decompiled_code:
__int64 __fastcall ft_strmapi(_BYTE *a1, __int64 (__fastcall *a2)(_QWORD))
{
__int64 v2; // rax
__int64 v3; // r12
unsigned int v4; // er14
__int64 v5; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = ft_strlen();
v3 = ft_strnew(v2 + 1);
if ( !v3 )
return 0LL;
if ( *a1 )
{
v4 = 0;
v5 = 0LL;
do
{
*(_BYTE *)(v3 + v5) = a2(v4++);
v5 = v4;
}
while ( a1[v4] );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 (__fastcall *a2)(_QWORD))
{
__int64 v2; // rax
__int64 v3; // r12
unsigned int v4; // er14
__int64 v5; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = ft_strlen();
v3 = ft_strnew(v2 + 1);
if ( !v3 )
return 0LL;
if ( *a1 )
{
v4 = 0;
v5 = 0LL;
do
{
*(_BYTE *)(v3 + v5) = a2(v4++);
v5 = v4;
}
while ( a1[v4] );
}
return v3;
}

original_code:
char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
{
 unsigned int i;
 char *new;
 i = 0;
 if (!(s && f))
  return (((void *)0));
 new = ft_strnew(ft_strlen(s) + 1);
 if (new == ((void *)0))
  return (((void *)0));
 while (s[i])
 {
  new[i] = f(i, s[i]);
  i++;
 }
 return (new);
}

canonical_original_code:
char *ft_strmapi(char *s, char (*f)(unsigned int, char))
{
 unsigned int i;
 char *new;
 i = 0;
 if (!(s && f))
  return (((void *)0));
 new = ft_strnew(ft_strlen(s) + 1);
 if (new == ((void *)0))
  return (((void *)0));
 while (s[i])
 {
  new[i] = f(i, s[i]);
  i++;
 }
 return (new);
}

variable_types:
s
char *

variable_types:
f
char (*)(unsigned int, char)

variable_types:
i
unsigned int

variable_types:
new
char *


decompiled_code:
__int64 __fastcall ft_select(__int64 a1, unsigned int a2)
{
char *v3; // rsi
int v4; // eax

v3 = getenv("TERM");
if ( !v3 )
{
ft_putendl("Specify a terminal type with setenv.");
v3 = 0LL;
}
v4 = tgetent(0LL, v3);
if ( v4 < 0 )
return ft_putendl("Soz, couldn't access da termcap data base.");
if ( v4 )
return ft_term(a1, a2);
return ft_putendl("wtf, define a valid teminal pliss.");
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
char *v3; // rsi
int v4; // eax

v3 = getenv("TERM");
if ( !v3 )
{
ft_putendl("Specify a terminal type with setenv.");
v3 = 0LL;
}
v4 = tgetent(0LL, v3);
if ( v4 < 0 )
return ft_putendl("Soz, couldn't access da termcap data base.");
if ( v4 )
return ft_term(a1, a2);
return ft_putendl("wtf, define a valid teminal pliss.");
}

original_code:
void ft_select(t_alst *data, int width)
{
 char *term_buff;
 char *term_type;
 int ret;
 ret = 0;
 term_buff = ((void *)0);
 term_type = getenv("TERM");
 if (term_type == ((void *)0))
  ft_putendl("Specify a terminal type with setenv.");
 ret = tgetent(term_buff, term_type);
 if (ret < 0)
  ft_putendl("Soz, couldn't access da termcap data base.");
 else if (ret == 0)
  ft_putendl("wtf, define a valid teminal pliss.");
 else
  ft_term(data, width);
}

canonical_original_code:
void ft_select(struct s_alst *data, int width)
{
 char *term_buff;
 char *term_type;
 int ret;
 ret = 0;
 term_buff = ((void *)0);
 term_type = getenv("TERM");
 if (term_type == ((void *)0))
  ft_putendl("Specify a terminal type with setenv.");
 ret = tgetent(term_buff, term_type);
 if (ret < 0)
  ft_putendl("Soz, couldn't access da termcap data base.");
 else if (ret == 0)
  ft_putendl("wtf, define a valid teminal pliss.");
 else
  ft_term(data, width);
}

variable_types: struct s_alst { char *param; int size; int select; int i; struct s_alst *next; struct s_alst *prev; } *

variable_types: width int

variable_types: ret int

return_type: void


decompiled_code:
__int64 __fastcall ft_lstdel(__int64 *a1, __int64 a2)
{
__int64 v3; // rdi
__int64 result; // rax

if ( a1 && a2 )
{
v3 = *a1;
if ( *(_QWORD *)(v3 + 16) )
ft_lstdel(v3 + 16);
result = ft_lstdelone(a1, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, __int64 a2)
{
__int64 v3; // rdi
__int64 result; // rax

if ( a1 && a2 )
{
v3 = *a1;
if ( *(_QWORD *)(v3 + 16) )
func0(v3 + 16);
result = ft_lstdelone(a1, a2);
}
return result;
}

original_code:
void ft_lstdel(t_list **alst, void (*del)(void *, size_t))
{
 if (alst && del)
 {
  if ((*alst)->next)
   ft_lstdel(&((*alst)->next), del);
  ft_lstdelone(alst, del);
 }
}

canonical_original_code:
void ft_lstdel(struct s_list **alst, void (*del)(void *, unsigned long))
{
 if (alst && del)
 {
  if ((*alst)->next)
   ft_lstdel(&((*alst)->next), del);
  ft_lstdelone(alst, del);
 }
}

variable_types: struct s_list { void *content; unsigned long content_size; struct s_list *next; } **

variable_types:
del
void (*)(void *, unsigned long)


decompiled_code:
__int64 __fastcall ft_isspace(char a1)
{
return (a1 == 32) | (unsigned __int8)((unsigned __int8)(a1 - 9) <= 1u);
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return (a1 == 32) | (unsigned __int8)((unsigned __int8)(a1 - 9) <= 1u);
}

original_code:
static int ft_isspace(char c)
{
 if (c == ' ' || c == '\n' || c == '\t')
  return (1);
 return (0);
}

variable_types: c char

return_type: int


decompiled_code:
__int64 __fastcall ft_strtrim(char *a1)
{
char *v1; // rbx
__int64 v2; // rcx
int v3; // eax
__int64 v4; // rcx
bool v5; // dl
char v6; // di
char *v7; // rbp
int v8; // er8
int v9; // er9
int v10; // er9
int v11; // ebx
__int64 v12; // rdi
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = a1;
v2 = (int)ft_strlen();
do
{
v3 = ft_isspace(a1[v2 - 1]);
v5 = (int)v4 > 0;
v2 = v4 - 1;
}
while ( v3 != 0 && v5 );
do
{
v6 = *v1;
v7 = v1++;
}
while ( (unsigned int)ft_isspace(v6) && v6 );
v10 = v9 - v8;
v11 = 0;
if ( v10 >= 0 )
v11 = v10;
v12 = ft_strnew(v11 + 1);
if ( v12 )
result = ft_strncpy(v12, v7, v11);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char *v1; // rbx
__int64 v2; // rcx
int v3; // eax
__int64 v4; // rcx
bool v5; // dl
char v6; // di
char *v7; // rbp
int v8; // er8
int v9; // er9
int v10; // er9
int v11; // ebx
__int64 v12; // rdi
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = a1;
v2 = (int)ft_strlen();
do
{
v3 = func0(a1[v2 - 1]);
v5 = (int)v4 > 0;
v2 = v4 - 1;
}
while ( v3 != 0 && v5 );
do
{
v6 = *v1;
v7 = v1++;
}
while ( (unsigned int)func0(v6) && v6 );
v10 = v9 - v8;
v11 = 0;
if ( v10 >= 0 )
v11 = v10;
v12 = ft_strnew(v11 + 1);
if ( v12 )
result = ft_strncpy(v12, v7, v11);
else
result = 0LL;
return result;
}

original_code:
char *ft_strtrim(const char *src)
{
 int i;
 int l;
 char *new;
 if (!src)
  return (((void *)0));
 i = 0;
 l = ft_strlen(src);
 while (ft_isspace(src[l - 1]) && l > 0)
  l--;
 while (ft_isspace(src[i]) && src[i])
  i++;
 l -= i;
 if (l < 0)
  l = 0;
 new = ft_strnew(l + 1);
 if (!new)
  return (((void *)0));
 new = ft_strncpy(new, &src[i], l);
 return (new);
}

canonical_original_code:
char *ft_strtrim(char *src)
{
 int i;
 int l;
 char *new;
 if (!src)
  return (((void *)0));
 i = 0;
 l = ft_strlen(src);
 while (ft_isspace(src[l - 1]) && l > 0)
  l--;
 while (ft_isspace(src[i]) && src[i])
  i++;
 l -= i;
 if (l < 0)
  l = 0;
 new = ft_strnew(l + 1);
 if (!new)
  return (((void *)0));
 new = ft_strncpy(new, &src[i], l);
 return (new);
}

variable_types:
src
char *

variable_types: i int

variable_types: l int

return_type: char *


decompiled_code:
__int64 __fastcall ft_memcpy(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rax

if ( a3 == 0 || a2 == 0 || !a1 )
return a1;
v4 = 0LL;
do
{
*(_BYTE *)(a1 + v4) = *(_BYTE *)(a2 + v4);
++v4;
}
while ( a3 > v4 );
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rax

if ( a3 == 0 || a2 == 0 || !a1 )
return a1;
v4 = 0LL;
do
{
*(_BYTE *)(a1 + v4) = *(_BYTE *)(a2 + v4);
++v4;
}
while ( a3 > v4 );
return a1;
}

original_code:
void *ft_memcpy(void *s1, const void *s2, size_t n)
{
 unsigned char *dest;
 const unsigned char *src;
 size_t index;
 dest = s1;
 src = s2;
 if (s1 && s2 && n)
 {
  index = 0;
  while (index < n)
  {
   dest[index] = src[index];
   index++;
  }
 }
 return (s1);
}

canonical_original_code:
void *ft_memcpy(void *s1, void *s2, unsigned long n)
{
 unsigned char *dest;
 unsigned char *src;
 unsigned long index;
 dest = s1;
 src = s2;
 if (s1 && s2 && n)
 {
  index = 0;
  while (index < n)
  {
   dest[index] = src[index];
   index++;
  }
 }
 return (s1);
}

variable_types:
n
unsigned long

variable_types:
dest
unsigned char *

variable_types:
src
unsigned char *

variable_types:
index
unsigned long

return_type: void *


decompiled_code:
void __fastcall __noreturn ft_quit(__int64 a1, const struct termios *a2, int a3)
{
char *v4; // rax
char *v5; // rax

v4 = tgetstr("ve", 0LL);
tputs(v4, 1, (int (*)(int))&ft_printchar);
v5 = tgetstr("te", 0LL);
tputs(v5, 1, (int (*)(int))&ft_printchar);
a2->c_lflag |= 0xAu;
tcsetattr(0, 0, a2);
if ( a3 )
ft_return_lst(a1, 0LL, *(unsigned int *)(a1 + 16));
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(__int64 a1, const struct termios *a2, int a3)
{
char *v4; // rax
char *v5; // rax

v4 = tgetstr("ve", 0LL);
tputs(v4, 1, (int (*)(int))&ft_printchar);
v5 = tgetstr("te", 0LL);
tputs(v5, 1, (int (*)(int))&ft_printchar);
a2->c_lflag |= 0xAu;
tcsetattr(0, 0, a2);
if ( a3 )
ft_return_lst(a1, 0LL, *(unsigned int *)(a1 + 16));
exit(1);
}

original_code:
void ft_quit(t_alst *data, struct termios *term, int ret)
{
 tputs(tgetstr("ve", ((void *)0)), 1, ft_printchar);
 tputs(tgetstr("te", ((void *)0)), 1, ft_printchar);
 term->c_lflag |= 0000002;
 term->c_lflag |= 0000010;
 tcsetattr(0, 0, term);
 if (ret)
  ft_return_lst(data, 0, data->i);
 exit(1);
}

canonical_original_code:
void ft_quit(struct s_alst *data, struct termios *term, int ret)
{
 tputs(tgetstr("ve", ((void *)0)), 1, ft_printchar);
 tputs(tgetstr("te", ((void *)0)), 1, ft_printchar);
 term->c_lflag |= 0000002;
 term->c_lflag |= 0000010;
 tcsetattr(0, 0, term);
 if (ret)
  ft_return_lst(data, 0, data->i);
 exit(1);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } *

user_defined_types: struct s_alst { char *param; int size; int select; int i; struct s_alst *next; struct s_alst *prev; }


decompiled_code:
__int64 __fastcall ft_strjoin(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // r12

if ( !a1 || !a2 )
return 0LL;
v2 = (int)((__int64 (*)(void))ft_strlen)();
v3 = ft_strlen(a2);
v4 = ft_strnew(v2 + v3 + 1);
v5 = v4;
if ( v4 )
{
ft_strcpy(v4, a1);
ft_strcpy(v5 + v2, a2);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // r12

if ( !a1 || !a2 )
return 0LL;
v2 = (int)((__int64 (*)(void))ft_strlen)();
v3 = ft_strlen(a2);
v4 = ft_strnew(v2 + v3 + 1);
v5 = v4;
if ( v4 )
{
ft_strcpy(v4, a1);
ft_strcpy(v5 + v2, a2);
}
return v5;
}

original_code:
char *ft_strjoin(const char *s1, const char *s2)
{
 char *new;
 int len;
 if (!(s1 && s2))
  return (((void *)0));
 len = ft_strlen(s1);
 new = ft_strnew(len + ft_strlen(s2) + 1);
 if (!new)
  return (((void *)0));
 ft_strcpy(new, s1);
 ft_strcpy(&new[len], s2);
 return (new);
}

canonical_original_code:
char *ft_strjoin(char *s1, char *s2)
{
 char *new;
 int len;
 if (!(s1 && s2))
  return (((void *)0));
 len = ft_strlen(s1);
 new = ft_strnew(len + ft_strlen(s2) + 1);
 if (!new)
  return (((void *)0));
 ft_strcpy(new, s1);
 ft_strcpy(&new[len], s2);
 return (new);
}

variable_types: len int


decompiled_code:
__int64 __fastcall ft_printchar(int a1)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 1LL;
}

original_code:
int ft_printchar(int c)
{
 write(1, &c, 1);
 return (1);
}

variable_types: c int


decompiled_code:
void __fastcall __noreturn ft_travel_lst(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // ebp
__int64 v6; // rax

while ( 1 )
{
ft_aff_elem(a1, a2, 1LL);
v5 = key_hook(a1, a3);
ft_aff_elem(a1, a2, 0LL);
v6 = *(_QWORD *)(a1 + 32);
if ( v5 != -1 )
v6 = *(_QWORD *)(a1 + 24);
a1 = v6;
}
}

original_code:
int ft_travel_lst(t_alst *data, t_term *e, struct termios *term)
{
 int ret;
 ft_aff_elem(data, e, 1);
 ret = key_hook(data, term);
 ft_aff_elem(data, e, 0);
 if (ret == -1)
  return (ft_travel_lst(data->prev, e, term));
 else
  return (ft_travel_lst(data->next, e, term));
}

canonical_original_code:
int ft_travel_lst(struct s_alst *data, struct s_term *e, struct termios *term)
{
 int ret;
 ft_aff_elem(data, e, 1);
 ret = key_hook(data, term);
 ft_aff_elem(data, e, 0);
 if (ret == -1)
  return (ft_travel_lst(data->prev, e, term));
 else
  return (ft_travel_lst(data->next, e, term));
}

variable_types: struct s_term { int h; int w; int max_c; } *

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
ssize_t __fastcall ft_putchar_fd(char a1, int a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(a2, buf, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func0(char a1, int a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(a2, buf, 1uLL);
}

original_code:
void ft_putchar_fd(char c, int fd)
{
 write(fd, &c, 1);
}

variable_types: fd int


decompiled_code:
ssize_t __fastcall ft_putchar(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func0(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

original_code:
void ft_putchar(char c)
{
 write(1, &c, 1);
}


decompiled_code:
__int64 __fastcall ft_isspace(char a1)
{
return (a1 == 32) | (unsigned __int8)((unsigned __int8)(a1 - 9) <= 4u);
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return (a1 == 32) | (unsigned __int8)((unsigned __int8)(a1 - 9) <= 4u);
}

canonical_original_code:
static int ft_isspace(char c)
{
 if (c == ' ' || c == '\n' || c == '\t')
  return (1);
 return (0);
}


repo: Shardcached/libshardcache

decompiled_code:
__int64 __fastcall string2sockaddr(char *src, int a2, __int64 a3)
{
int v4; // er12
int *v5; // rax
int *v6; // r14
char *v7; // rax
const char *v8; // r13
int v9; // er15
struct addrinfo *v10; // rdi
__int16 v11; // bp
int v13; // ebp
struct addrinfo *pai; // [rsp+8h] [rbp-270h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-268h] BYREF
char dest[2]; // [rsp+40h] [rbp-238h] BYREF

v4 = _bswap_32_constprop_0();
v5 = _errno_location();
*v5 = 22;
if ( !src )
{
if ( !a2 )
return 0xFFFFFFFFLL;
LABEL_12:
*(_QWORD *)(a3 + 8) = 0LL;
*(_WORD *)a3 = 2;
*(_DWORD *)(a3 + 4) = v4;
v11 = _bswap_16(a2);
goto LABEL_10;
}
v6 = v5;
strncpy(dest, src, 0x1FFuLL);
v7 = strchr(dest, 58);
v8 = v7;
if ( v7 )
{
*v7 = 0;
*(_OWORD *)&req.ai_flags = 0LL;
v8 = v7 + 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
pai = 0LL;
*(_QWORD *)&req.ai_family = 0x100000002LL;
req.ai_addrlen = 16;
*(_OWORD *)&req.ai_canonname = 0LL;
pthread_mutex_lock(&lock_0);
if ( *(_WORD *)dest == 42 )
{
v13 = getaddrinfo(0LL, v8, &req, &pai);
pthread_mutex_unlock(&lock_0);
if ( !v13 )
{
v10 = pai;
v4 = 0;
goto LABEL_8;
}
LABEL_15:
*v6 = 2;
return 0xFFFFFFFFLL;
}
}
else
{
pai = 0LL;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_QWORD *)&req.ai_family = 0x100000002LL;
req.ai_addrlen = 16;
*(_OWORD *)&req.ai_canonname = 0LL;
pthread_mutex_lock(&lock_0);
if ( *(_WORD *)dest == 42 )
{
pthread_mutex_unlock(&lock_0);
goto LABEL_15;
}
}
v9 = getaddrinfo(dest, v8, &req, &pai);
pthread_mutex_unlock(&lock_0);
if ( v9 )
goto LABEL_15;
v10 = pai;
if ( v4 )
v4 = *(_DWORD *)&pai->ai_addr->sa_data[2];
if ( !v8 )
{
freeaddrinfo(pai);
if ( !a2 )
return 0xFFFFFFFFLL;
goto LABEL_12;
}
LABEL_8:
v11 = *(_WORD *)v10->ai_addr->sa_data;
freeaddrinfo(v10);
if ( v11 )
{
*(_QWORD *)(a3 + 8) = 0LL;
*(_WORD *)a3 = 2;
*(_DWORD *)(a3 + 4) = v4;
LABEL_10:
*(_WORD *)(a3 + 2) = v11;
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, int a2, __int64 a3)
{
int v4; // er12
int *v5; // rax
int *v6; // r14
char *v7; // rax
const char *v8; // r13
int v9; // er15
struct addrinfo *v10; // rdi
__int16 v11; // bp
int v13; // ebp
struct addrinfo *pai; // [rsp+8h] [rbp-270h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-268h] BYREF
char dest[2]; // [rsp+40h] [rbp-238h] BYREF

v4 = func1();
v5 = _errno_location();
*v5 = 22;
if ( !src )
{
if ( !a2 )
return 0xFFFFFFFFLL;
LABEL_12:
*(_QWORD *)(a3 + 8) = 0LL;
*(_WORD *)a3 = 2;
*(_DWORD *)(a3 + 4) = v4;
v11 = func0(a2);
goto LABEL_10;
}
v6 = v5;
strncpy(dest, src, 0x1FFuLL);
v7 = strchr(dest, 58);
v8 = v7;
if ( v7 )
{
*v7 = 0;
*(_OWORD *)&req.ai_flags = 0LL;
v8 = v7 + 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
pai = 0LL;
*(_QWORD *)&req.ai_family = 0x100000002LL;
req.ai_addrlen = 16;
*(_OWORD *)&req.ai_canonname = 0LL;
pthread_mutex_lock(&lock_0);
if ( *(_WORD *)dest == 42 )
{
v13 = getaddrinfo(0LL, v8, &req, &pai);
pthread_mutex_unlock(&lock_0);
if ( !v13 )
{
v10 = pai;
v4 = 0;
goto LABEL_8;
}
LABEL_15:
*v6 = 2;
return 0xFFFFFFFFLL;
}
}
else
{
pai = 0LL;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_QWORD *)&req.ai_family = 0x100000002LL;
req.ai_addrlen = 16;
*(_OWORD *)&req.ai_canonname = 0LL;
pthread_mutex_lock(&lock_0);
if ( *(_WORD *)dest == 42 )
{
pthread_mutex_unlock(&lock_0);
goto LABEL_15;
}
}
v9 = getaddrinfo(dest, v8, &req, &pai);
pthread_mutex_unlock(&lock_0);
if ( v9 )
goto LABEL_15;
v10 = pai;
if ( v4 )
v4 = *(_DWORD *)&pai->ai_addr->sa_data[2];
if ( !v8 )
{
freeaddrinfo(pai);
if ( !a2 )
return 0xFFFFFFFFLL;
goto LABEL_12;
}
LABEL_8:
v11 = *(_WORD *)v10->ai_addr->sa_data;
freeaddrinfo(v10);
if ( v11 )
{
*(_QWORD *)(a3 + 8) = 0LL;
*(_WORD *)a3 = 2;
*(_DWORD *)(a3 + 4) = v4;
LABEL_10:
*(_WORD *)(a3 + 2) = v11;
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int
string2sockaddr(const char *host, int port, struct sockaddr_in *sockaddr)
{
    u_int32_t ip = htonl(((in_addr_t) 0x7f000001));
    (*__errno_location ()) = 22;
    int is_nbo = 0;
    if (host) {
        char host2[512];
        char *p;
        strncpy(host2, host, sizeof(host2)-1);
        p = strchr(host2, ':');
        if (p) {
            *p = 0;
            p++;
        }
        struct addrinfo *info = ((void *)0);
        struct addrinfo hints = {
            .ai_family = 2,
            .ai_socktype = SOCK_STREAM,
            .ai_addrlen = sizeof(struct sockaddr_in),
        };
        int rc = -1;
        static pthread_mutex_t lock = { { 0, 0, 0, 0, 0, 0, 0, { 0, 0 } } };
        pthread_mutex_lock(&lock);
        if (strcmp(host2, "*") == 0) {
            ip = ((in_addr_t) 0x00000000);
            if (p)
                rc = getaddrinfo(((void *)0), p, &hints, &info);
        } else {
            rc = getaddrinfo(host2, p, &hints, &info);
        }
        pthread_mutex_unlock(&lock);
        if (rc == 0) {
            if (ip != ((in_addr_t) 0x00000000))
                ip = ((struct sockaddr_in *)info->ai_addr)->sin_addr.s_addr;
            if (p) {
                port = ((struct sockaddr_in *)info->ai_addr)->sin_port;
                is_nbo = 1;
            }
            freeaddrinfo(info);
        } else {
            (*__errno_location ()) = 2;
            return -1;
        }
    }
    if (port == 0)
        return -1;
    bzero(sockaddr, sizeof(struct sockaddr_in));
    sockaddr->sin_family = 2;
    sockaddr->sin_addr.s_addr = ip;
    sockaddr->sin_port = is_nbo ? port : htons(port);
    return 0;
}

canonical_original_code:
int string2sockaddr(char *host, int port, struct sockaddr_in *sockaddr)
{
    unsigned int ip = htonl(((in_addr_t) 0x7f000001));
    (*__errno_location ()) = 22;
    int is_nbo = 0;
    if (host) {
        char host2[512];
        char *p;
        strncpy(host2, host, sizeof(host2)-1);
        p = strchr(host2, ':');
        if (p) {
            *p = 0;
            p++;
        }
        struct addrinfo *info = ((void *)0);
        struct addrinfo hints = {
            .ai_family = 2,
            .ai_socktype = SOCK_STREAM,
            .ai_addrlen = sizeof(struct sockaddr_in),
        };
        int rc = -1;
        static union pthread_mutex_t lock = { { 0, 0, 0, 0, 0, 0, 0, { 0, 0 } } };
        pthread_mutex_lock(&lock);
        if (strcmp(host2, "*") == 0) {
            ip = ((unsigned int) 0x00000000);
            if (p)
                rc = getaddrinfo(((void *)0), p, &hints, &info);
        } else {
            rc = getaddrinfo(host2, p, &hints, &info);
        }
        pthread_mutex_unlock(&lock);
        if (rc == 0) {
            if (ip != ((unsigned int) 0x00000000))
                ip = ((struct sockaddr_in *)info->ai_addr)->sin_addr.s_addr;
            if (p) {
                port = ((struct sockaddr_in *)info->ai_addr)->sin_port;
                is_nbo = 1;
            }
            freeaddrinfo(info);
        } else {
            (*__errno_location ()) = 2;
            return -1;
        }
    }
    if (port == 0)
        return -1;
    bzero(sockaddr, sizeof(struct sockaddr_in));
    sockaddr->sin_family = 2;
    sockaddr->sin_addr.s_addr = ip;
    sockaddr->sin_port = is_nbo ? port : htons(port);
    return 0;
}

variable_types:
host
char *

variable_types: port int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types:
ip
unsigned int

variable_types:
p
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: rc int

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; }

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall open_socket(char *src, int a2)
{
int v2; // eax
unsigned int v3; // er12
int optval; // [rsp+4h] [rbp-44h] BYREF
__int64 v6; // [rsp+8h] [rbp-40h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

optval = 1;
v6 = 0LL;
*_errno_location() = 22;
if ( (!src || !*src) && !a2 )
return (unsigned int)-1;
v2 = socket(2, 1, 6);
v3 = v2;
if ( v2 == -1 )
return (unsigned int)-1;
setsockopt(v2, 1, 2, &optval, 4u);
setsockopt(v3, 6, 1, &optval, 4u);
setsockopt(v3, 1, 13, &v6, 8u);
if ( (unsigned int)string2sockaddr(src, a2, (__int64)&addr) == -1 || bind(v3, &addr, 0x10u) == -1 )
{
shutdown(v3, 2);
close(v3);
return (unsigned int)-1;
}
listen(v3, -1);
fcntl(v3, 2, 1LL);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, int a2)
{
int v2; // eax
unsigned int v3; // er12
int optval; // [rsp+4h] [rbp-44h] BYREF
__int64 v6; // [rsp+8h] [rbp-40h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

optval = 1;
v6 = 0LL;
*_errno_location() = 22;
if ( (!src || !*src) && !a2 )
return (unsigned int)-1;
v2 = socket(2, 1, 6);
v3 = v2;
if ( v2 == -1 )
return (unsigned int)-1;
setsockopt(v2, 1, 2, &optval, 4u);
setsockopt(v3, 6, 1, &optval, 4u);
setsockopt(v3, 1, 13, &v6, 8u);
if ( (unsigned int)func2(src, a2, (__int64)&addr) == -1 || bind(v3, &addr, 0x10u) == -1 )
{
shutdown(v3, 2);
close(v3);
return (unsigned int)-1;
}
listen(v3, -1);
fcntl(v3, 2, 1LL);
return v3;
}

original_code:
int
open_socket(const char *host, int port)
{
    int val = 1;
    struct sockaddr_in sockaddr;
    int sock;
    struct linger ling = {0, 0};
    (*__errno_location ()) = 22;
    if ((host == ((void *)0) || !*host) && port == 0)
        return -1;
    sock = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (sock == -1)
        return -1;
    setsockopt(sock, 1, 2, &val, sizeof(val));
    setsockopt(sock, IPPROTO_TCP, 1, &val, sizeof(val));
    setsockopt(sock, 1, 13, (void *)&ling, sizeof(ling));
    if (string2sockaddr(host, port, &sockaddr) == -1
        || bind(sock, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) == -1)
    {
        shutdown(sock, SHUT_RDWR);
        close(sock);
        return -1;
    }
    listen(sock, -1);
    fcntl(sock, 2, 1);
    return sock;
}

canonical_original_code:
int open_socket(char *host, int port)
{
    int val = 1;
    struct sockaddr_in sockaddr;
    int sock;
    struct linger ling = {0, 0};
    (*__errno_location ()) = 22;
    if ((host == ((void *)0) || !*host) && port == 0)
        return -1;
    sock = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (sock == -1)
        return -1;
    setsockopt(sock, 1, 2, &val, sizeof(val));
    setsockopt(sock, IPPROTO_TCP, 1, &val, sizeof(val));
    setsockopt(sock, 1, 13, (void *)&ling, sizeof(ling));
    if (string2sockaddr(host, port, &sockaddr) == -1
        || bind(sock, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) == -1)
    {
        shutdown(sock, SHUT_RDWR);
        close(sock);
        return -1;
    }
    listen(sock, -1);
    fcntl(sock, 2, 1);
    return sock;
}

variable_types: val int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: sock int

variable_types: struct linger { int l_onoff; int l_linger; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall write_socket(int fd, __int64 a2, int a3)
{
unsigned int v5; // er12
int v6; // ebx
unsigned int v7; // eax
int v8; // edi
char *v10; // rax

v5 = 0;
v6 = 0;
while ( 1 )
{
while ( 1 )
{
v6 += v5;
a3 -= v5;
v7 = write(fd, (const void *)(a2 + v6), a3);
v5 = v7;
if ( v7 == -1 )
break;
if ( !v7 || v7 == a3 )
return v5;
}
v8 = *_errno_location();
if ( v8 != 4 && v8 != 11 )
break;
v5 = 0;
if ( !a3 )
return v5;
}
v10 = strerror(v8);
fprintf(stderr, "write on fd %d failed: %s", (unsigned int)fd, v10);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __int64 a2, int a3)
{
unsigned int v5; // er12
int v6; // ebx
unsigned int v7; // eax
int v8; // edi
char *v10; // rax

v5 = 0;
v6 = 0;
while ( 1 )
{
while ( 1 )
{
v6 += v5;
a3 -= v5;
v7 = write(fd, (const void *)(a2 + v6), a3);
v5 = v7;
if ( v7 == -1 )
break;
if ( !v7 || v7 == a3 )
return v5;
}
v8 = *_errno_location();
if ( v8 != 4 && v8 != 11 )
break;
v5 = 0;
if ( !a3 )
return v5;
}
v10 = strerror(v8);
fprintf(stderr, "write on fd %d failed: %s", (unsigned int)fd, v10);
return v5;
}

original_code:
int write_socket(int fd, char *buf, int len) {
    int wb = 0;
    int ofx = 0;
    do {
        len -= wb;
        ofx += wb;
        wb = write(fd, buf+ofx, len);
        if (wb == -1) {
            if ((*__errno_location ()) != 4 && (*__errno_location ()) != 11) {
                fprintf(stderr, "write on fd %d failed: %s", fd, strerror((*__errno_location ())));
                return -1;
            }
            wb = 0;
        } else if (wb == 0) {
            break;
        }
    } while (wb != len);
    return wb;
}

variable_types:
buf
char *

variable_types: wb int

variable_types: ofx int


decompiled_code:
__int64 __fastcall read_socket(int fd, void *buf, int a3, int a4)
{
size_t v5; // rbp
unsigned int v6; // eax
unsigned __int8 v7; // bl
int v8; // er14
int v9; // eax

v5 = a3;
v6 = fcntl(fd, 3, 0LL);
if ( v6 == -1 )
{
v8 = -1;
}
else
{
v7 = ((v6 >> 11) ^ 1) & 1;
do
{
v8 = read(fd, buf, v5);
if ( v8 >= 0 )
break;
v9 = *_errno_location();
}
while ( v9 == 4 || ((a4 != 0) & v7) != 0 && v9 == 11 );
}
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, void *buf, int a3, int a4)
{
size_t v5; // rbp
unsigned int v6; // eax
unsigned __int8 v7; // bl
int v8; // er14
int v9; // eax

v5 = a3;
v6 = fcntl(fd, 3, 0LL);
if ( v6 == -1 )
{
v8 = -1;
}
else
{
v7 = ((v6 >> 11) ^ 1) & 1;
do
{
v8 = read(fd, buf, v5);
if ( v8 >= 0 )
break;
v9 = *_errno_location();
}
while ( v9 == 4 || ((a4 != 0) & v7) != 0 && v9 == 11 );
}
return (unsigned int)v8;
}

original_code:
int read_socket(int fd, char *buf, int len, int ignore_timeout) {
    int rb = 0;
    int flags = fcntl(fd, 3, 0);
    if (flags == -1)
        return -1;
    do {
        rb = read(fd, buf, len);
    } while(rb < 0 && ((*__errno_location ()) == 4 || (!(flags&04000) && ignore_timeout && (*__errno_location ()) == 11)));
    return rb;
}

variable_types: len int

variable_types: rb int

variable_types: flags int


decompiled_code:
__int64 __fastcall open_lsocket(char *name)
{
unsigned int v1; // er12
struct sockaddr v3[8]; // [rsp+0h] [rbp-88h] BYREF

*_errno_location() = 22;
if ( !name )
return (unsigned int)-1;
if ( !*name )
return (unsigned int)-1;
v1 = socket(1, 1, 0);
if ( v1 == -1 )
return (unsigned int)-1;
unlink(name);
v3[0].sa_family = 1;
strncpy(v3[0].sa_data, name, 0x6CuLL);
if ( bind(v1, v3, 0x6Eu) == -1 || listen(v1, -1) == -1 )
{
shutdown(v1, 2);
close(v1);
return (unsigned int)-1;
}
fcntl(v1, 2, 1LL);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *name)
{
unsigned int v1; // er12
struct sockaddr v3[8]; // [rsp+0h] [rbp-88h] BYREF

*_errno_location() = 22;
if ( !name )
return (unsigned int)-1;
if ( !*name )
return (unsigned int)-1;
v1 = socket(1, 1, 0);
if ( v1 == -1 )
return (unsigned int)-1;
unlink(name);
v3[0].sa_family = 1;
strncpy(v3[0].sa_data, name, 0x6CuLL);
if ( bind(v1, v3, 0x6Eu) == -1 || listen(v1, -1) == -1 )
{
shutdown(v1, 2);
close(v1);
return (unsigned int)-1;
}
fcntl(v1, 2, 1LL);
return v1;
}

original_code:
int
open_lsocket(const char *filename)
{
    struct sockaddr_un sockaddr;
    int sock;
    (*__errno_location ()) = 22;
    if (filename == ((void *)0) || !*filename)
        return -1;
    sock = socket(1, SOCK_STREAM, 0);
    if (sock == -1)
        return -1;
    unlink(filename);
    sockaddr.sun_family = 1;
    strncpy(sockaddr.sun_path, filename, sizeof(sockaddr.sun_path));
    if (bind(sock, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) == -1 || listen(sock, -1) == -1)
    {
        shutdown(sock, SHUT_RDWR);
        close(sock);
        return -1;
    }
    fcntl(sock, 2, 1);
    return sock;
}

canonical_original_code:
int open_lsocket(char *filename)
{
    struct sockaddr_un sockaddr;
    int sock;
    (*__errno_location ()) = 22;
    if (filename == ((void *)0) || !*filename)
        return -1;
    sock = socket(1, SOCK_STREAM, 0);
    if (sock == -1)
        return -1;
    unlink(filename);
    sockaddr.sun_family = 1;
    strncpy(sockaddr.sun_path, filename, sizeof(sockaddr.sun_path));
    if (bind(sock, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) == -1 || listen(sock, -1) == -1)
    {
        shutdown(sock, SHUT_RDWR);
        close(sock);
        return -1;
    }
    fcntl(sock, 2, 1);
    return sock;
}

variable_types:
filename
char *

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
__int64 __fastcall open_fifo(char *file)
{
int *v1; // rbx
unsigned int v2; // er12
int v3; // eax
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

if ( !mkfifo(file, 0x1180u) )
goto LABEL_5;
v1 = _errno_location();
if ( *v1 != 17 )
return (unsigned int)-1;
v2 = stat(file, &v5);
if ( v2 == -1 )
{
*v1 = 17;
return v2;
}
if ( (v5.st_mode & 0xF000) != 4096 )
return (unsigned int)-1;
LABEL_5:
v3 = open(file, 2178);
v2 = v3;
if ( v3 != -1 )
fcntl(v3, 2, 1LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *file)
{
int *v1; // rbx
unsigned int v2; // er12
int v3; // eax
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

if ( !mkfifo(file, 0x1180u) )
goto LABEL_5;
v1 = _errno_location();
if ( *v1 != 17 )
return (unsigned int)-1;
v2 = stat(file, &v5);
if ( v2 == -1 )
{
*v1 = 17;
return v2;
}
if ( (v5.st_mode & 0xF000) != 4096 )
return (unsigned int)-1;
LABEL_5:
v3 = open(file, 2178);
v2 = v3;
if ( v3 != -1 )
fcntl(v3, 2, 1LL);
return v2;
}

original_code:
int
open_fifo(const char *filename)
{
    struct stat sb;
    int fd;
    if (mkfifo(filename, 0010000 | 0600) != 0) {
    if ((*__errno_location ()) == 17) {
        if (stat(filename, &sb) == -1) {
        (*__errno_location ()) = 17;
        return -1;
        } else if (!((((sb.st_mode)) & 0170000) == (0010000))) {
        return -1;
        }
    } else {
        return -1;
    }
    }
    fd = open(filename, 02|0200|04000);
    if (fd == -1)
    return -1;
    fcntl(fd, 2, 1);
    return fd;
}

canonical_original_code:
int open_fifo(char *filename)
{
    struct stat sb;
    int fd;
    if (mkfifo(filename, 0010000 | 0600) != 0) {
    if ((*__errno_location ()) == 17) {
        if (stat(filename, &sb) == -1) {
        (*__errno_location ()) = 17;
        return -1;
        } else if (!((((sb.st_mode)) & 0170000) == (0010000))) {
        return -1;
        }
    } else {
        return -1;
    }
    }
    fd = open(filename, 02|0200|04000);
    if (fd == -1)
    return -1;
    fcntl(fd, 2, 1);
    return fd;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: fd int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


original_code:
unsigned long shardcache_byte_escape(char ch,
                             char esc,
                             char *buffer,
                             unsigned long len,
                             char **dest,
                             unsigned long *newlen)
{
    char *newbuf;
    unsigned long buflen;
    unsigned long i;
    unsigned long cnt;
    int escape;
    char *p;
    unsigned long off;
    if(len == 0)
        return 0;
    newbuf = (char *)malloc(len);
    if(!newbuf)
        return 0;
    buflen = len;
    p = buffer;
    off = 0;
    cnt = 0;
    for(i=0;i<len;i++)
    {
        escape = 0;
        if(*p == ch)
            cnt ++;
        if(*p == ch || *p == esc)
            escape = 1;
        if(escape)
        {
            buflen++;
            newbuf = (char *)realloc(newbuf, buflen+1);
            memcpy(newbuf+off, &esc, 1);
            off++;
        }
        memcpy(newbuf+off, p, 1);
        p++;
        off++;
    }
    *dest = newbuf;
    *newlen = buflen;
    return cnt;
}

variable_types: ch char

variable_types: esc char

variable_types:
buffer
char *

variable_types:
len
unsigned long

variable_types:
dest
char **

variable_types:
newlen
unsigned long *

variable_types:
newbuf
char *

variable_types:
buflen
unsigned long

variable_types:
i
unsigned long

variable_types:
cnt
unsigned long

variable_types: escape int

variable_types:
p
char *

variable_types:
off
unsigned long

return_type: unsigned long


decompiled_code:
char *__fastcall shardcache_hex_escape(__int64 a1, int a2, int a3, int a4)
{
int v5; // er12
char *v6; // rbp
__int64 v7; // rbx
__int64 v8; // rdx
char *v9; // rdi
__int64 v11; // rax
const char *v12; // rbx

if ( a3 <= 0 || a3 >= a2 )
{
v5 = 0x8000;
if ( a2 <= 0x8000 )
v5 = a2;
if ( !a4 )
{
v6 = (char *)shardcache_byte_escape + _tls_get_addr(&str_0_tlsind);
goto LABEL_11;
}
LABEL_17:
v11 = _tls_get_addr(&str_0_tlsind);
*(_WORD *)((char *)shardcache_byte_escape + v11) = 30768;
v6 = &byte_63C[v11 - 1594];
*v6 = 0;
LABEL_11:
if ( v5 <= 0 )
goto LABEL_14;
goto LABEL_12;
}
v5 = 0x8000;
if ( a3 <= 0x8000 )
v5 = a3;
if ( a4 )
goto LABEL_17;
v6 = (char *)shardcache_byte_escape + _tls_get_addr(&str_0_tlsind);
LABEL_12:
v7 = 0LL;
do
{
v8 = *(unsigned __int8 *)(a1 + v7);
v9 = v6;
++v7;
v6 += 2;
sprintf(v9, "%02x", v8);
}
while ( v5 > (int)v7 );
LABEL_14:
if ( a2 > v5 )
{
v12 = (char *)shardcache_byte_escape + _tls_get_addr(&str_0_tlsind);
*(_DWORD *)&v12[strlen(v12)] = 3026478;
}
return (char *)shardcache_byte_escape + _tls_get_addr(&str_0_tlsind);
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, int a2, int a3, int a4)
{
int v5; // er12
char *v6; // rbp
__int64 v7; // rbx
__int64 v8; // rdx
char *v9; // rdi
__int64 v11; // rax
const char *v12; // rbx

if ( a3 <= 0 || a3 >= a2 )
{
v5 = 0x8000;
if ( a2 <= 0x8000 )
v5 = a2;
if ( !a4 )
{
v6 = (char *)shardcache_byte_escape + _tls_get_addr(&str_0_tlsind);
goto LABEL_11;
}
LABEL_17:
v11 = _tls_get_addr(&str_0_tlsind);
*(_WORD *)((char *)shardcache_byte_escape + v11) = 30768;
v6 = &byte_63C[v11 - 1594];
*v6 = 0;
LABEL_11:
if ( v5 <= 0 )
goto LABEL_14;
goto LABEL_12;
}
v5 = 0x8000;
if ( a3 <= 0x8000 )
v5 = a3;
if ( a4 )
goto LABEL_17;
v6 = (char *)shardcache_byte_escape + _tls_get_addr(&str_0_tlsind);
LABEL_12:
v7 = 0LL;
do
{
v8 = *(unsigned __int8 *)(a1 + v7);
v9 = v6;
++v7;
v6 += 2;
sprintf(v9, "%02x", v8);
}
while ( v5 > (int)v7 );
LABEL_14:
if ( a2 > v5 )
{
v12 = (char *)shardcache_byte_escape + _tls_get_addr(&str_0_tlsind);
*(_DWORD *)&v12[strlen(v12)] = 3026478;
}
return (char *)shardcache_byte_escape + _tls_get_addr(&str_0_tlsind);
}

original_code:
char *shardcache_hex_escape(char *buf, int len, int limit, int include_prefix)
{
    int i;
    static __thread char str[(1<<16)+6];
    int olen = (limit > 0 && limit < len) ? limit : len;
    if (olen > (1<<16)/2)
        olen = (1<<16)/2;
    char *p = str;
    if (include_prefix) {
        strcpy(str, "0x");
        p += 2;
    }
    for (i = 0; i < olen; i++) {
        sprintf(p, "%02x", (unsigned char)buf[i]);
        p+=2;
    }
    if (olen < len)
        strcat(str, "...");
    return str;
}

canonical_original_code:
char *shardcache_hex_escape(char *buf, int len, int limit, int include_prefix)
{
    int i;
    static __thread char str[-1];
    int olen = (limit > 0 && limit < len) ? limit : len;
    if (olen > (1<<16)/2)
        olen = (1<<16)/2;
    char *p = str;
    if (include_prefix) {
        strcpy(str, "0x");
        p += 2;
    }
    for (i = 0; i < olen; i++) {
        sprintf(p, "%02x", (unsigned char)buf[i]);
        p+=2;
    }
    if (olen < len)
        strcat(str, "...");
    return str;
}

variable_types:
buf
char *

variable_types: len int

variable_types: limit int

variable_types: i int

variable_types:
str
char [-1]

variable_types: olen int


decompiled_code:
__int64 shardcache_log_level()
{
return shardcache_loglevel;
}

canonical_decompiled_code:
__int64 func2()
{
return shardcache_loglevel;
}

original_code:
unsigned int shardcache_log_level()
{
    return shardcache_loglevel;
}

return_type: unsigned int


decompiled_code:
void shardcache_log_message(int pri, int a2, const char *a3, ...)
{
const char *v4; // r14
size_t v5; // r13
size_t v6; // rax
char *v7; // rax
char *v8; // r13
gcc_va_list ap; // [rsp+8h] [rbp-F0h] BYREF

switch ( pri )
{
case 3:
v4 = "[ERROR]: ";
if ( a3 )
goto LABEL_6;
return;
case 4:
v4 = "[WARNING]: ";
goto LABEL_3;
case 5:
v4 = "[NOTICE]: ";
goto LABEL_3;
case 6:
v4 = "[INFO]: ";
goto LABEL_3;
case 7:
switch ( a2 )
{
case 1:
v4 = "[DBG]: ";
break;
case 2:
v4 = "[DBG2]: ";
break;
case 3:
v4 = "[DBG3]: ";
break;
case 4:
v4 = "[DBG4]: ";
break;
case 5:
v4 = "[DBG5]: ";
break;
default:
v4 = "[DBGX]: ";
break;
}
goto LABEL_3;
default:
v4 = "[UNKNOWN]: ";
LABEL_3:
if ( a3 )
{
LABEL_6:
v5 = strlen(a3);
v6 = strlen(v4);
v7 = (char *)calloc(1uLL, v5 + v6 + 1);
v8 = v7;
if ( v7 )
{
sprintf(v7, "%s%s", v4, a3);
va_start(ap, a3);
vsyslog(pri, v8, ap);
free(v8);
}
}
return;
}
}

canonical_decompiled_code:
void func3(int pri, int a2, const char *a3, ...)
{
const char *v4; // r14
size_t v5; // r13
size_t v6; // rax
char *v7; // rax
char *v8; // r13
gcc_va_list ap; // [rsp+8h] [rbp-F0h] BYREF

switch ( pri )
{
case 3:
v4 = "[ERROR]: ";
if ( a3 )
goto LABEL_6;
return;
case 4:
v4 = "[WARNING]: ";
goto LABEL_3;
case 5:
v4 = "[NOTICE]: ";
goto LABEL_3;
case 6:
v4 = "[INFO]: ";
goto LABEL_3;
case 7:
switch ( a2 )
{
case 1:
v4 = "[DBG]: ";
break;
case 2:
v4 = "[DBG2]: ";
break;
case 3:
v4 = "[DBG3]: ";
break;
case 4:
v4 = "[DBG4]: ";
break;
case 5:
v4 = "[DBG5]: ";
break;
default:
v4 = "[DBGX]: ";
break;
}
goto LABEL_3;
default:
v4 = "[UNKNOWN]: ";
LABEL_3:
if ( a3 )
{
LABEL_6:
v5 = strlen(a3);
v6 = strlen(v4);
v7 = (char *)calloc(1uLL, v5 + v6 + 1);
v8 = v7;
if ( v7 )
{
sprintf(v7, "%s%s", v4, a3);
va_start(ap, a3);
vsyslog(pri, v8, ap);
free(v8);
}
}
return;
}
}

original_code:
void shardcache_log_message(int prio, int dbglevel, const char *fmt, ...)
{
    char *newfmt = ((void *)0);
    const char *prefix = ((void *)0);
    switch (prio) {
        case 3:
            prefix = "[ERROR]: ";
            break;
        case 4:
            prefix = "[WARNING]: ";
            break;
        case 5:
            prefix = "[NOTICE]: ";
            break;
        case 6:
            prefix = "[INFO]: ";
            break;
        case 7:
            switch (dbglevel) {
                case 1:
                    prefix = "[DBG]: ";
                    break;
                case 2:
                    prefix = "[DBG2]: ";
                    break;
                case 3:
                    prefix = "[DBG3]: ";
                    break;
                case 4:
                    prefix = "[DBG4]: ";
                    break;
                case 5:
                    prefix = "[DBG5]: ";
                    break;
                default:
                    prefix = "[DBGX]: ";
                    break;
            }
            break;
        default:
            prefix = "[UNKNOWN]: ";
            break;
    }
    if (prefix && fmt) {
        newfmt = (char *)calloc(1, strlen(fmt)+strlen(prefix)+1);
        if (newfmt) {
            sprintf(newfmt, "%s%s", prefix, fmt);
            va_list arg;
            __builtin_va_start(arg,fmt);
            vsyslog(prio, newfmt, arg);
            __builtin_va_end(arg);
            free(newfmt);
        }
    }
}

canonical_original_code:
void shardcache_log_message(int prio, int dbglevel, char *fmt, ...)
{
    char *newfmt = ((void *)0);
    char *prefix = ((void *)0);
    switch (prio) {
        case 3:
            prefix = "[ERROR]: ";
            break;
        case 4:
            prefix = "[WARNING]: ";
            break;
        case 5:
            prefix = "[NOTICE]: ";
            break;
        case 6:
            prefix = "[INFO]: ";
            break;
        case 7:
            switch (dbglevel) {
                case 1:
                    prefix = "[DBG]: ";
                    break;
                case 2:
                    prefix = "[DBG2]: ";
                    break;
                case 3:
                    prefix = "[DBG3]: ";
                    break;
                case 4:
                    prefix = "[DBG4]: ";
                    break;
                case 5:
                    prefix = "[DBG5]: ";
                    break;
                default:
                    prefix = "[DBGX]: ";
                    break;
            }
            break;
        default:
            prefix = "[UNKNOWN]: ";
            break;
    }
    if (prefix && fmt) {
        newfmt = (char *)calloc(1, strlen(fmt)+strlen(prefix)+1);
        if (newfmt) {
            sprintf(newfmt, "%s%s", prefix, fmt);
            __builtin_va_list arg;
            __builtin_va_start(arg,fmt);
            vsyslog(prio, newfmt, arg);
            __builtin_va_end(arg);
            free(newfmt);
        }
    }
}

variable_types: prio int

variable_types: dbglevel int

variable_types:
fmt
char *

variable_types:
newfmt
char *

variable_types:
prefix
char *


main

canonical_name: main

repo: Sharli/libsubsonic

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
freopen(0LL, "rb", stdin);
unpack_resource(stdin);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
freopen(0LL, "rb", stdin);
func10(stdin);
return 0;
}

original_code:
int main(int argc, char **argv) {
  freopen(((void *)0), "rb", stdin);
  unpack_resource(stdin);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
int ex1()
{
printf("sizeof(arr)= %ld\n", 28LL);
printf("sizeof(arr[0])= %ld\n", 4LL);
printf("%lld\n", 0LL);
return printf("%lld\n", -24LL);
}

canonical_decompiled_code:
int func7()
{
printf("sizeof(arr)= %ld\n", 28LL);
printf("sizeof(arr[0])= %ld\n", 4LL);
printf("%lld\n", 0LL);
return printf("%lld\n", -24LL);
}

original_code:
void ex1(void) {
  int arr[7] = {1, 2, 3, 4, 5, 6, 7};
  int *p0 = (&arr[0] + 1) ;
  int *p1 = (arr + 1) ;
  int *p2 = (&arr + 1);
  printf("sizeof(arr)= %ld\n", sizeof(arr));
  printf("sizeof(arr[0])= %ld\n", sizeof(arr[0]));
  long long x = (((long long) p1) - ((long long) p0));
  printf("%lld\n", x);
  x = (((long long) p1) - ((long long) p2));
  printf("%lld\n", x);
}

canonical_original_code:
void ex1() {
  int arr[7] = {1, 2, 3, 4, 5, 6, 7};
  int *p0 = (&arr[0] + 1);
  int *p1 = (arr + 1);
  int *p2 = (&arr + 1);
  printf("sizeof(arr)= %ld\n", sizeof(arr));
  printf("sizeof(arr[0])= %ld\n", sizeof(arr[0]));
  long long x = (((long long) p1) - ((long long) p0));
  printf("%lld\n", x);
  x = (((long long) p1) - ((long long) p2));
  printf("%lld\n", x);
}

variable_types:
arr
int [7]

variable_types:
x
long long


decompiled_code:
int ex3()
{
return printf("%d\n", 6LL);
}

canonical_decompiled_code:
int func9()
{
return printf("%d\n", 6LL);
}

original_code:
void ex3(void) {
  int arr[3];
  2[arr] = 6;
  printf("%d\n", arr[2]);
}

canonical_original_code:
void ex3() {
  int arr[3];
  2[arr] = 6;
  printf("%d\n", arr[2]);
}

variable_types:
arr
int [3]


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
ex1(argc, argv, envp);
ex2();
ex3();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7(argc, argv, envp);
func8();
func9();
return 0;
}

original_code:
int main(void) {
  ex1();
  ex2();
  ex3();
  return 0;
}

canonical_original_code:
int main() {
  ex1();
  ex2();
  ex3();
  return 0;
}


decompiled_code:
__int64 __fastcall gray_to_binary(unsigned int a1, const char *a2)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, const char *a2)
{
return a1;
}

original_code:
uint16_t gray_to_binary(uint16_t gray)
{
   return gray;
}

canonical_original_code:
unsigned short gray_to_binary(unsigned short gray)
{
   return gray;
}

variable_types:
gray
unsigned short

return_type: unsigned short


decompiled_code:
// attributes: thunk
__int64 __fastcall binary_to_gray(unsigned int a1, const char *a2)
{
return gray_to_binary(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, const char *a2)
{
return func7(a1, a2);
}

original_code:
uint16_t binary_to_gray(uint16_t binary)
{
   return binary;
}

canonical_original_code:
unsigned short binary_to_gray(unsigned short binary)
{
   return binary;
}

variable_types:
binary
unsigned short


repo: ShiHong-Zhang/lmts-gtk

decompiled_code:
__int64 keyboard_run()
{
printPrompt(&unk_1213);
gdk_threads_enter();
draw_kbd();
gdk_threads_leave();
if ( kbd_result )
printNG(&unk_122A);
else
printOK(&unk_123E);
return (unsigned int)kbd_result;
}

canonical_decompiled_code:
__int64 func3()
{
printPrompt(&unk_1213);
gdk_threads_enter();
func2();
gdk_threads_leave();
if ( kbd_result )
printNG(&unk_122A);
else
printOK(&unk_123E);
return (unsigned int)kbd_result;
}

original_code:
int keyboard_run(char *arg)
{
 printPrompt("进入键盘测试。\n");
 gdk_threads_enter();
 draw_kbd();
 gdk_threads_leave();
 if (kbd_result) {
  printNG("键盘测试失败\n");
 } else {
  printOK("键盘测试通过\n");
 }
 return kbd_result;
}

variable_types:
arg
char *


decompiled_code:
__int64 F_keyboard_register()
{
RegisterTestFunc("keyboard", keyboard_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
RegisterTestFunc("keyboard", keyboard_run);
return 0LL;
}

original_code:
int F_keyboard_register()
{
 F_Test_Run run = keyboard_run;
 RegisterTestFunc("keyboard", run);
 return 0;
}

canonical_original_code:
int F_keyboard_register()
{
 int (*run)(char *arg) = keyboard_run;
 RegisterTestFunc("keyboard", run);
 return 0;
}

variable_types:
run
int (*)(char *arg)


decompiled_code:
__int64 F_sdcard_register()
{
RegisterTestFunc("sdcard", sdcard_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("sdcard", sdcard_run);
return 0LL;
}

original_code:
int F_sdcard_register()
{
 F_Test_Run run = sdcard_run;
 RegisterTestFunc("sdcard", run);
 return 0;
}

canonical_original_code:
int F_sdcard_register()
{
 int (*run)(char *arg) = sdcard_run;
 RegisterTestFunc("sdcard", run);
 return 0;
}


decompiled_code:
__int64 battery_run()
{
printPrompt(&unk_645);
printPrompt(&unk_778);
return bat_test();
}

canonical_decompiled_code:
__int64 func1()
{
printPrompt(&unk_645);
printPrompt(&unk_778);
return func0();
}

original_code:
int battery_run(char *arg)
{
 int ret = 0;
 printPrompt("开始进行电池测试\n");
 printPrompt("请将电池电量保持在95%以下\n");
 ret = bat_test();
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 F_battery_register()
{
RegisterTestFunc("battery", battery_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
RegisterTestFunc("battery", battery_run);
return 0LL;
}

original_code:
int F_battery_register()
{
 F_Test_Run run = battery_run;
 RegisterTestFunc("battery", run);
 return 0;
}

canonical_original_code:
int F_battery_register()
{
 int (*run)(char *arg) = battery_run;
 RegisterTestFunc("battery", run);
 return 0;
}


decompiled_code:
__int64 F_fanstem_register()
{
RegisterTestFunc("fanstem", fanstem_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("fanstem", fanstem_run);
return 0LL;
}

original_code:
int F_fanstem_register()
{
 F_Test_Run run = fanstem_run;
 RegisterTestFunc("fanstem", run);
 return 0;
}

canonical_original_code:
int F_fanstem_register()
{
 int (*run)(char *arg) = fanstem_run;
 RegisterTestFunc("fanstem", run);
 return 0;
}


decompiled_code:
__int64 F_ckec_register()
{
RegisterTestFunc("ckec", ckec_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("ckec", ckec_run);
return 0LL;
}

original_code:
int F_ckec_register()
{
 F_Test_Run run = ckec_run;
 RegisterTestFunc("ckec", run);
 return 0;
}

canonical_original_code:
int F_ckec_register()
{
 int (*run)(char *arg) = ckec_run;
 RegisterTestFunc("ckec", run);
 return 0;
}


decompiled_code:
__int64 F_ckntp_register()
{
RegisterTestFunc("ckntp", ckntp_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("ckntp", ckntp_run);
return 0LL;
}

original_code:
int F_ckntp_register()
{
 F_Test_Run run = ckntp_run;
 RegisterTestFunc("ckntp", run);
 return 0;
}

canonical_original_code:
int F_ckntp_register()
{
 int (*run)(char *arg) = ckntp_run;
 RegisterTestFunc("ckntp", run);
 return 0;
}


decompiled_code:
__int64 F_lan_register()
{
RegisterTestFunc(&unk_96F, lan_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc(&unk_96F, lan_run);
return 0LL;
}

original_code:
int F_lan_register()
{
 F_Test_Run run = lan_run;
 RegisterTestFunc("lan", run);
 return 0;
}

canonical_original_code:
int F_lan_register()
{
 int (*run)(char *arg) = lan_run;
 RegisterTestFunc("lan", run);
 return 0;
}


decompiled_code:
__int64 lcdwave_run()
{
__int64 result; // rax

printPrompt(&unk_590);
printPrompt(&unk_5D8);
printPrompt(&unk_5A1);
g_usleep(1500000LL);
gdk_threads_enter();
draw_lcd();
gdk_threads_leave();
result = (unsigned int)lcd_result;
if ( lcd_result )
{
printNG(&unk_5B8);
result = (unsigned int)lcd_result;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax

printPrompt(&unk_590);
printPrompt(&unk_5D8);
printPrompt(&unk_5A1);
g_usleep(1500000LL);
gdk_threads_enter();
func1();
gdk_threads_leave();
result = (unsigned int)lcd_result;
if ( lcd_result )
{
printNG(&unk_5B8);
result = (unsigned int)lcd_result;
}
return result;
}

original_code:
int lcdwave_run(char *arg)
{
 printPrompt("LCD屏幕测试\n");
 printPrompt("LCD屏无亮点、坏点：请按'Y'键\n");
 printPrompt("否则：请按'N'键\n");
 g_usleep(1500000);
 gdk_threads_enter();
 draw_lcd();
 gdk_threads_leave();
 if (lcd_result) {
  printNG("LCD测试失败\n");
 }
 return lcd_result;
}


decompiled_code:
__int64 F_lcdwave_register()
{
RegisterTestFunc("lcdwave", lcdwave_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
RegisterTestFunc("lcdwave", lcdwave_run);
return 0LL;
}

original_code:
int F_lcdwave_register()
{
 F_Test_Run run = lcdwave_run;
 RegisterTestFunc("lcdwave", run);
 return 0;
}

canonical_original_code:
int F_lcdwave_register()
{
 int (*run)(char *arg) = lcdwave_run;
 RegisterTestFunc("lcdwave", run);
 return 0;
}


decompiled_code:
__int64 F_cpu_memcap_register()
{
RegisterTestFunc("cpu_memcap", cpu_memcap_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("cpu_memcap", cpu_memcap_run);
return 0LL;
}

original_code:
int F_cpu_memcap_register()
{
 F_Test_Run run = cpu_memcap_run;
 RegisterTestFunc("cpu_memcap", run);
 return 0;
}

canonical_original_code:
int F_cpu_memcap_register()
{
 int (*run)(char *arg) = cpu_memcap_run;
 RegisterTestFunc("cpu_memcap", run);
 return 0;
}


decompiled_code:
__int64 vgaout_run()
{
__int64 result; // rax

printPrompt(&unk_5F8);
g_usleep(1500000LL);
gdk_threads_enter();
draw_vga();
gdk_threads_leave();
result = (unsigned int)vga_result;
if ( vga_result )
{
printNG(&unk_5DE);
result = (unsigned int)vga_result;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax

printPrompt(&unk_5F8);
g_usleep(1500000LL);
gdk_threads_enter();
func1();
gdk_threads_leave();
result = (unsigned int)vga_result;
if ( vga_result )
{
printNG(&unk_5DE);
result = (unsigned int)vga_result;
}
return result;
}

original_code:
int vgaout_run(char *arg)
{
 printPrompt("VGAOUT 测试\n请外接VGA显示器\n");
 g_usleep(1500000);
 gdk_threads_enter();
 draw_vga();
 gdk_threads_leave();
 if (vga_result) {
  printNG("VGA测试失败\n");
 }
 return vga_result;
}


decompiled_code:
__int64 F_vgaout_register()
{
RegisterTestFunc("vgaout", vgaout_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
RegisterTestFunc("vgaout", vgaout_run);
return 0LL;
}

original_code:
int F_vgaout_register()
{
 F_Test_Run run = vgaout_run;
 RegisterTestFunc("vgaout", run);
 return 0;
}

canonical_original_code:
int F_vgaout_register()
{
 int (*run)(char *arg) = vgaout_run;
 RegisterTestFunc("vgaout", run);
 return 0;
}


decompiled_code:
__int64 F_scanpsn_register()
{
RegisterTestFunc("scanpsn", scanpsn_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("scanpsn", scanpsn_run);
return 0LL;
}

original_code:
int F_scanpsn_register()
{
 F_Test_Run run = scanpsn_run;
 RegisterTestFunc("scanpsn", run);
 return 0;
}

canonical_original_code:
int F_scanpsn_register()
{
 int (*run)(char *arg) = scanpsn_run;
 RegisterTestFunc("scanpsn", run);
 return 0;
}


decompiled_code:
__int64 check_result()
{
fprintf(stderr, "result: %d\n", (unsigned int)tp_result);
if ( tp_result > 4 )
{
if ( source_id )
g_source_remove();
gtk_widget_destroy(tp_win);
gtk_main_quit();
}
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
fprintf(stderr, "result: %d\n", (unsigned int)tp_result);
if ( tp_result > 4 )
{
if ( source_id )
g_source_remove();
gtk_widget_destroy(tp_win);
gtk_main_quit();
}
return 1LL;
}

original_code:
gboolean check_result(gpointer arg)
{
 fprintf(stderr, "result: %d\n", tp_result);
 if (tp_result >= 5) {
  if (source_id) {
   g_source_remove(source_id);
  }
  gtk_widget_destroy(tp_win);
  gtk_main_quit();
 }
 return (!(0));
}

canonical_original_code:
int check_result(void *arg)
{
 fprintf(stderr, "result: %d\n", tp_result);
 if (tp_result >= 5) {
  if (source_id) {
   g_source_remove(source_id);
  }
  gtk_widget_destroy(tp_win);
  gtk_main_quit();
 }
 return (!(0));
}

variable_types:
arg
void *


decompiled_code:
__int64 F_touchpad_register()
{
RegisterTestFunc("touchpad", touchpad_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
RegisterTestFunc("touchpad", touchpad_run);
return 0LL;
}

original_code:
int F_touchpad_register()
{
 F_Test_Run run = touchpad_run;
 RegisterTestFunc("touchpad", run);
 return 0;
}

canonical_original_code:
int F_touchpad_register()
{
 int (*run)(char *arg) = touchpad_run;
 RegisterTestFunc("touchpad", run);
 return 0;
}


decompiled_code:
__int64 F_scanmbsn_register()
{
RegisterTestFunc("scanmbsn", scanmbsn_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("scanmbsn", scanmbsn_run);
return 0LL;
}

original_code:
int F_scanmbsn_register()
{
 F_Test_Run run = scanmbsn_run;
 RegisterTestFunc("scanmbsn", run);
 return 0;
}

canonical_original_code:
int F_scanmbsn_register()
{
 int (*run)(char *arg) = scanmbsn_run;
 RegisterTestFunc("scanmbsn", run);
 return 0;
}


decompiled_code:
__int64 F_burnmac_register()
{
RegisterTestFunc("burnmac", burnmac_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("burnmac", burnmac_run);
return 0LL;
}

original_code:
int F_burnmac_register()
{
 F_Test_Run run = burnmac_run;
 RegisterTestFunc("burnmac", run);
 return 0;
}

canonical_original_code:
int F_burnmac_register()
{
 int (*run)(char *arg) = burnmac_run;
 RegisterTestFunc("burnmac", run);
 return 0;
}


decompiled_code:
__int64 cmos_run()
{
__int64 result; // rax
char *v1; // rdi
int v2; // ebp
__int64 v3; // [rsp+0h] [rbp-88h] BYREF
__int16 v4; // [rsp+8h] [rbp-80h]
char name[22]; // [rsp+Ah] [rbp-7Eh] BYREF
_BYTE v6[48]; // [rsp+20h] [rbp-68h] BYREF
unsigned int v7; // [rsp+50h] [rbp-38h] BYREF
__int64 v8; // [rsp+54h] [rbp-34h]
__int64 v9; // [rsp+5Ch] [rbp-2Ch]
int v10; // [rsp+64h] [rbp-24h]

v3 = 0x6374722F7665642FLL;
v4 = 0;
strcpy(name, "/dev/rtc0");
if ( access((const char *)&v3, 0) )
{
if ( access(name, 0) )
{
fwrite("dev file error.\n", 1uLL, 0x10uLL, stderr);
printNG(&unk_591);
return 1LL;
}
v1 = name;
}
else
{
v1 = (char *)&v3;
}
v2 = open(v1, 2);
if ( v2 == -1 )
{
perror((const char *)&v3);
exit(1);
}
if ( ioctl(v2, 0x80247009uLL, v6) == -1 )
goto LABEL_16;
printf(
"%d-%d-%d, %02d:%02d: %02d.\n",
*(unsigned int *)&v6[12],
(unsigned int)(*(_DWORD *)&v6[16] + 1),
(unsigned int)(*(_DWORD *)&v6[20] + 1900),
*(unsigned int *)&v6[8],
*(unsigned int *)&v6[4],
*(unsigned int *)v6);
printPrompt(&unk_5C5);
*(_QWORD *)&v6[8] = 0x100000000LL;
*(_QWORD *)&v6[16] = 0x6C0000000BLL;
*(_QWORD *)v6 = 0LL;
if ( ioctl(v2, 0x4024700AuLL, v6) == -1
|| (printf(
"%d-%d-%d, %02d:%02d: %02d.\n",
*(unsigned int *)&v6[12],
(unsigned int)(*(_DWORD *)&v6[16] + 1),
(unsigned int)(*(_DWORD *)&v6[20] + 1900),
*(unsigned int *)&v6[8],
*(unsigned int *)&v6[4],
*(unsigned int *)v6),
printPrompt(&unk_5E0),
sleep(3u),
ioctl(v2, 0x80247009uLL, &v7) == -1) )
{
LABEL_16:
perror("ioctl");
exit(1);
}
if ( v9 == *(_QWORD *)&v6[12] && v10 == *(_DWORD *)&v6[20] && v8 == *(_QWORD *)&v6[4] && v7 - *(_DWORD *)v6 == 3 )
{
puts("Check OK!");
((void (__fastcall *)(void *))printOK)(&unk_5FC);
close(v2);
system("hwclock -w");
result = 0LL;
}
else
{
fwrite("Check Error!\n", 1uLL, 0xDuLL, stderr);
printNG(&unk_627);
fprintf(
stderr,
"%d-%d-%d, %02d:%02d: %02d.\n",
(unsigned int)v9,
(unsigned int)(HIDWORD(v9) + 1),
(unsigned int)(v10 + 1900),
HIDWORD(v8),
(unsigned int)v8,
v7);
close(v2);
system("hwclock -w");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
char *v1; // rdi
int v2; // ebp
__int64 v3; // [rsp+0h] [rbp-88h] BYREF
__int16 v4; // [rsp+8h] [rbp-80h]
char name[22]; // [rsp+Ah] [rbp-7Eh] BYREF
_BYTE v6[48]; // [rsp+20h] [rbp-68h] BYREF
unsigned int v7; // [rsp+50h] [rbp-38h] BYREF
__int64 v8; // [rsp+54h] [rbp-34h]
__int64 v9; // [rsp+5Ch] [rbp-2Ch]
int v10; // [rsp+64h] [rbp-24h]

v3 = 0x6374722F7665642FLL;
v4 = 0;
strcpy(name, "/dev/rtc0");
if ( access((const char *)&v3, 0) )
{
if ( access(name, 0) )
{
fwrite("dev file error.\n", 1uLL, 0x10uLL, stderr);
printNG(&unk_591);
return 1LL;
}
v1 = name;
}
else
{
v1 = (char *)&v3;
}
v2 = open(v1, 2);
if ( v2 == -1 )
{
perror((const char *)&v3);
exit(1);
}
if ( ioctl(v2, 0x80247009uLL, v6) == -1 )
goto LABEL_16;
printf(
"%d-%d-%d, %02d:%02d: %02d.\n",
*(unsigned int *)&v6[12],
(unsigned int)(*(_DWORD *)&v6[16] + 1),
(unsigned int)(*(_DWORD *)&v6[20] + 1900),
*(unsigned int *)&v6[8],
*(unsigned int *)&v6[4],
*(unsigned int *)v6);
printPrompt(&unk_5C5);
*(_QWORD *)&v6[8] = 0x100000000LL;
*(_QWORD *)&v6[16] = 0x6C0000000BLL;
*(_QWORD *)v6 = 0LL;
if ( ioctl(v2, 0x4024700AuLL, v6) == -1
|| (printf(
"%d-%d-%d, %02d:%02d: %02d.\n",
*(unsigned int *)&v6[12],
(unsigned int)(*(_DWORD *)&v6[16] + 1),
(unsigned int)(*(_DWORD *)&v6[20] + 1900),
*(unsigned int *)&v6[8],
*(unsigned int *)&v6[4],
*(unsigned int *)v6),
printPrompt(&unk_5E0),
sleep(3u),
ioctl(v2, 0x80247009uLL, &v7) == -1) )
{
LABEL_16:
perror("ioctl");
exit(1);
}
if ( v9 == *(_QWORD *)&v6[12] && v10 == *(_DWORD *)&v6[20] && v8 == *(_QWORD *)&v6[4] && v7 - *(_DWORD *)v6 == 3 )
{
puts("Check OK!");
((void (__fastcall *)(void *))printOK)(&unk_5FC);
close(v2);
system("hwclock -w");
result = 0LL;
}
else
{
fwrite("Check Error!\n", 1uLL, 0xDuLL, stderr);
printNG(&unk_627);
fprintf(
stderr,
"%d-%d-%d, %02d:%02d: %02d.\n",
(unsigned int)v9,
(unsigned int)(HIDWORD(v9) + 1),
(unsigned int)(v10 + 1900),
HIDWORD(v8),
(unsigned int)v8,
v7);
close(v2);
system("hwclock -w");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int cmos_run(char *arg)
{
 char devfile[2][10] = {
  "/dev/rtc",
  "/dev/rtc0",
 };
 int i, fd, retval;
 struct rtc_time rtc_tm, rtc_tm2;
 char *file = ((void *)0);
 for (i = 0; i < 2; ++i) {
  if (access(devfile[i], 0) == 0) {
   file = devfile[i];
   break;
  }
 }
 if (!file) {
  fprintf(stderr, "dev file error.\n");
  printNG("读取rtc失败\n");
  return 1;
 }
 fd = open (file, 02);
 if (fd == -1) {
  perror((const char *)devfile);
  exit(1);
 }
 retval = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('p')) << (0 +8)) | (((0x09)) << 0) | ((((sizeof(struct rtc_time)))) << ((0 +8)+8))), &rtc_tm);
 if (retval == -1) {
  perror("ioctl");
  exit(1);
 }
 printf("%d-%d-%d, %02d:%02d:  %02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
 printPrompt("开始重置CMOS时间：\n");
 rtc_tm.tm_mday = 1;
 rtc_tm.tm_mon = 12 - 1;
 rtc_tm.tm_year = 2008 - 1900;
 rtc_tm.tm_hour = 0;
 rtc_tm.tm_min = 0;
 rtc_tm.tm_sec = 0;
 retval = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('p')) << (0 +8)) | (((0x0a)) << 0) | ((((sizeof(struct rtc_time)))) << ((0 +8)+8))), &rtc_tm);
 if (retval == -1) {
  perror("ioctl");
  exit(1);
 }
 printf("%d-%d-%d, %02d:%02d:  %02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
 printPrompt("请等待3秒...\n");
 sleep(3);
 retval = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('p')) << (0 +8)) | (((0x09)) << 0) | ((((sizeof(struct rtc_time)))) << ((0 +8)+8))), &rtc_tm2);
 if (retval == -1) {
  perror("ioctl");
  exit(1);
 }
 if (rtc_tm2.tm_mday == rtc_tm.tm_mday
   && rtc_tm2.tm_mon == rtc_tm.tm_mon
   && rtc_tm2.tm_year == rtc_tm.tm_year
   && rtc_tm2.tm_hour == rtc_tm.tm_hour
   && rtc_tm2.tm_min == rtc_tm.tm_min
   && rtc_tm2.tm_sec - rtc_tm.tm_sec == 3)
 {
  printf("Check OK!\n");
  printOK("CMOS走时准确\n");
  close(fd);
  system("hwclock -w");
  return 0;
 } else {
  fprintf(stderr, "Check Error!\n");
  printNG("CMOS走时不准确\n");
  fprintf( stderr, "%d-%d-%d, %02d:%02d:  %02d.\n",
   rtc_tm2.tm_mday, rtc_tm2.tm_mon + 1, rtc_tm2.tm_year + 1900,
   rtc_tm2.tm_hour, rtc_tm2.tm_min, rtc_tm2.tm_sec);
  close(fd);
  system("hwclock -w");
  return -1;
 }
}

canonical_original_code:
int cmos_run(char *arg)
{
 char devfile[2][10] = {
  "/dev/rtc",
  "/dev/rtc0",
 };
 int i; int fd; int retval;
 struct rtc_time rtc_tm; struct rtc_time rtc_tm2;
 char *file = ((void *)0);
 for (i = 0; i < 2; ++i) {
  if (access(devfile[i], 0) == 0) {
   file = devfile[i];
   break;
  }
 }
 if (!file) {
  fprintf(stderr, "dev file error.\n");
  printNG("读取rtc失败\n");
  return 1;
 }
 fd = open (file, 02);
 if (fd == -1) {
  perror((char *)devfile);
  exit(1);
 }
 retval = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('p')) << (0 +8)) | (((0x09)) << 0) | ((((sizeof(struct rtc_time)))) << ((0 +8)+8))), &rtc_tm);
 if (retval == -1) {
  perror("ioctl");
  exit(1);
 }
 printf("%d-%d-%d, %02d:%02d:  %02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
 printPrompt("开始重置CMOS时间：\n");
 rtc_tm.tm_mday = 1;
 rtc_tm.tm_mon = 12 - 1;
 rtc_tm.tm_year = 2008 - 1900;
 rtc_tm.tm_hour = 0;
 rtc_tm.tm_min = 0;
 rtc_tm.tm_sec = 0;
 retval = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('p')) << (0 +8)) | (((0x0a)) << 0) | ((((sizeof(struct rtc_time)))) << ((0 +8)+8))), &rtc_tm);
 if (retval == -1) {
  perror("ioctl");
  exit(1);
 }
 printf("%d-%d-%d, %02d:%02d:  %02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
 printPrompt("请等待3秒...\n");
 sleep(3);
 retval = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('p')) << (0 +8)) | (((0x09)) << 0) | ((((sizeof(struct rtc_time)))) << ((0 +8)+8))), &rtc_tm2);
 if (retval == -1) {
  perror("ioctl");
  exit(1);
 }
 if (rtc_tm2.tm_mday == rtc_tm.tm_mday
   && rtc_tm2.tm_mon == rtc_tm.tm_mon
   && rtc_tm2.tm_year == rtc_tm.tm_year
   && rtc_tm2.tm_hour == rtc_tm.tm_hour
   && rtc_tm2.tm_min == rtc_tm.tm_min
   && rtc_tm2.tm_sec - rtc_tm.tm_sec == 3)
 {
  printf("Check OK!\n");
  printOK("CMOS走时准确\n");
  close(fd);
  system("hwclock -w");
  return 0;
 } else {
  fprintf(stderr, "Check Error!\n");
  printNG("CMOS走时不准确\n");
  fprintf( stderr, "%d-%d-%d, %02d:%02d:  %02d.\n",
   rtc_tm2.tm_mday, rtc_tm2.tm_mon + 1, rtc_tm2.tm_year + 1900,
   rtc_tm2.tm_hour, rtc_tm2.tm_min, rtc_tm2.tm_sec);
  close(fd);
  system("hwclock -w");
  return -1;
 }
}

variable_types:
devfile
char [2][10]

variable_types: i int

variable_types: fd int

variable_types: retval int

variable_types: struct rtc_time { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; }

variable_types:
file
char *


decompiled_code:
__int64 F_cmos_register()
{
RegisterTestFunc("cmos", cmos_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("cmos", cmos_run);
return 0LL;
}

original_code:
int F_cmos_register()
{
 F_Test_Run run = cmos_run;
 RegisterTestFunc("cmos", run);
 return 0;
}

canonical_original_code:
int F_cmos_register()
{
 int (*run)(char *arg) = cmos_run;
 RegisterTestFunc("cmos", run);
 return 0;
}


decompiled_code:
__int64 F_wifi_register()
{
RegisterTestFunc("wifi", wifi_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("wifi", wifi_run);
return 0LL;
}

original_code:
int F_wifi_register()
{
 F_Test_Run run = wifi_run;
 RegisterTestFunc("wifi", run);
 return 0;
}

canonical_original_code:
int F_wifi_register()
{
 int (*run)(char *arg) = wifi_run;
 RegisterTestFunc("wifi", run);
 return 0;
}


decompiled_code:
__int64 F_ckpmon_register()
{
RegisterTestFunc("ckpmon", ckpmon_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("ckpmon", ckpmon_run);
return 0LL;
}

original_code:
int F_ckpmon_register()
{
 F_Test_Run run = ckpmon_run;
 RegisterTestFunc("ckpmon", run);
 return 0;
}

canonical_original_code:
int F_ckpmon_register()
{
 int (*run)(char *arg) = ckpmon_run;
 RegisterTestFunc("ckpmon", run);
 return 0;
}


decompiled_code:
__int64 F_usb_register()
{
RegisterTestFunc("usb", usb_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("usb", usb_run);
return 0LL;
}

original_code:
int F_usb_register()
{
 F_Test_Run run = usb_run;
 RegisterTestFunc("usb", run);
 return 0;
}

canonical_original_code:
int F_usb_register()
{
 int (*run)(char *arg) = usb_run;
 RegisterTestFunc("usb", run);
 return 0;
}


decompiled_code:
__int64 F_ntp_register()
{
RegisterTestFunc(&unk_798, ntp_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc(&unk_798, ntp_run);
return 0LL;
}

original_code:
int F_ntp_register()
{
 F_Test_Run run = ntp_run;
 RegisterTestFunc("ntp", run);
 return 0;
}

canonical_original_code:
int F_ntp_register()
{
 int (*run)(char *arg) = ntp_run;
 RegisterTestFunc("ntp", run);
 return 0;
}


decompiled_code:
__int64 F_upload_register()
{
RegisterTestFunc("upload", upload_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("upload", upload_run);
return 0LL;
}

original_code:
int F_upload_register()
{
 F_Test_Run run = upload_run;
 RegisterTestFunc("upload", run);
 return 0;
}

canonical_original_code:
int F_upload_register()
{
 int (*run)(char *arg) = upload_run;
 RegisterTestFunc("upload", run);
 return 0;
}


decompiled_code:
__int64 F_ckrom_register()
{
RegisterTestFunc("ckrom", ckrom_run);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
RegisterTestFunc("ckrom", ckrom_run);
return 0LL;
}

original_code:
int F_ckrom_register()
{
 F_Test_Run run = ckrom_run;
 RegisterTestFunc("ckrom", run);
 return 0;
}

canonical_original_code:
int F_ckrom_register()
{
 int (*run)(char *arg) = ckrom_run;
 RegisterTestFunc("ckrom", run);
 return 0;
}


repo: Sidnicious/noeol

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
size_t v4; // rdx

while ( 1 )
{
n = read(0, &buf, 0x200uLL);
v4 = n;
if ( !n )
break;
if ( haveeol )
{
putchar(10);
v4 = n;
}
v3 = v4 - 1;
if ( byte_40407F[v4] == 10 )
{
haveeol = 1;
--v4;
n = v3;
}
write(1, &buf, v4);
}
return 0;
}

original_code:
int main() {
    while((n = read(0, buf, sizeof(buf)))) {
        if (haveeol) { putchar('\n'); }
        if (buf[n-1] == '\n') {
            haveeol = 1;
            n -= 1;
        }
        write(1, buf, n);
    }
}


repo: SigmaG/nmud

decompiled_code:
__int64 __fastcall connect_to_mud(const char **a1)
{
const char *v1; // rsi
const char *v2; // rdi
int v3; // eax
struct addrinfo *v4; // rbx
int v5; // eax
unsigned int v6; // ebp
const char *v8; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

v1 = a1[1];
v2 = *a1;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
req.ai_flags = 32;
*(_OWORD *)&req.ai_canonname = 0LL;
v3 = getaddrinfo(v2, v1, &req, &pai);
if ( v3 )
{
v8 = gai_strerror(v3);
display_error("getaddrinfo : %s\n", v8);
return 0xFFFFFFFFLL;
}
v4 = pai;
if ( !pai )
{
LABEL_7:
display_error("Could not connect\n");
return 0xFFFFFFFFLL;
}
while ( 1 )
{
v5 = socket(v4->ai_family, v4->ai_socktype, v4->ai_protocol);
v6 = v5;
if ( v5 != -1 )
break;
LABEL_6:
v4 = v4->ai_next;
if ( !v4 )
goto LABEL_7;
}
if ( connect(v5, v4->ai_addr, v4->ai_addrlen) == -1 )
{
close(v6);
goto LABEL_6;
}
freeaddrinfo(pai);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1)
{
const char *v1; // rsi
const char *v2; // rdi
int v3; // eax
struct addrinfo *v4; // rbx
int v5; // eax
unsigned int v6; // ebp
const char *v8; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

v1 = a1[1];
v2 = *a1;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
req.ai_flags = 32;
*(_OWORD *)&req.ai_canonname = 0LL;
v3 = getaddrinfo(v2, v1, &req, &pai);
if ( v3 )
{
v8 = gai_strerror(v3);
display_error("getaddrinfo : %s\n", v8);
return 0xFFFFFFFFLL;
}
v4 = pai;
if ( !pai )
{
LABEL_7:
display_error("Could not connect\n");
return 0xFFFFFFFFLL;
}
while ( 1 )
{
v5 = socket(v4->ai_family, v4->ai_socktype, v4->ai_protocol);
v6 = v5;
if ( v5 != -1 )
break;
LABEL_6:
v4 = v4->ai_next;
if ( !v4 )
goto LABEL_7;
}
if ( connect(v5, v4->ai_addr, v4->ai_addrlen) == -1 )
{
close(v6);
goto LABEL_6;
}
freeaddrinfo(pai);
return v6;
}

original_code:
int connect_to_mud(struct conf* cnf) {
struct addrinfo hints;
struct addrinfo *result, *rp;
int mudsock;
memset(&hints,0,sizeof(struct addrinfo));
hints.ai_family = 0;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = 0x0020;
hints.ai_protocol = 0;
int s = getaddrinfo(cnf->address,cnf->port,&hints,&result);
if (s != 0) {
 display_error("getaddrinfo : %s\n", gai_strerror(s));
 return -1;
}
for (rp = result; rp != ((void *)0); rp = rp->ai_next) {
 mudsock = socket(rp->ai_family,rp->ai_socktype,rp->ai_protocol);
 if (mudsock == -1) continue;
 if (connect(mudsock, rp->ai_addr, rp->ai_addrlen) != -1) break;
 close(mudsock);
}
if (rp == ((void *)0)) {
 display_error("Could not connect\n");
 return -1;
}
freeaddrinfo(result);
return mudsock;
}

canonical_original_code:
int connect_to_mud(struct conf *cnf) {
struct addrinfo hints;
struct addrinfo *result; struct addrinfo *rp;
int mudsock;
memset(&hints,0,sizeof(struct addrinfo));
hints.ai_family = 0;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = 0x0020;
hints.ai_protocol = 0;
int s = getaddrinfo(cnf->address,cnf->port,&hints,&result);
if (s != 0) {
 display_error("getaddrinfo : %s\n", gai_strerror(s));
 return -1;
}
for (rp = result; rp != ((void *)0); rp = rp->ai_next) {
 mudsock = socket(rp->ai_family,rp->ai_socktype,rp->ai_protocol);
 if (mudsock == -1) continue;
 if (connect(mudsock, rp->ai_addr, rp->ai_addrlen) != -1) break;
 close(mudsock);
}
if (rp == ((void *)0)) {
 display_error("Could not connect\n");
 return -1;
}
freeaddrinfo(result);
return mudsock;
}

variable_types: struct conf { char *address; char *port; int r_size; int t_size; int buffer; } *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: mudsock int

variable_types: s int


decompiled_code:
ssize_t __fastcall write_network_line(void *buf, int fd)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
return write(fd, buf, v2);
}

canonical_decompiled_code:
ssize_t __fastcall func3(void *buf, int fd)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
return write(fd, buf, v2);
}

original_code:
int write_network_line(char* r, int sock) {
 write(sock, r, strlen(r));
}

canonical_original_code:
int write_network_line(char *r, int sock) {
 write(sock, r, strlen(r));
}

variable_types:
r
char *

variable_types: sock int


decompiled_code:
int __fastcall close_connection(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int __fastcall func4(int fd)
{
return close(fd);
}

original_code:
int close_connection(int sock) {
 close(sock);
}


decompiled_code:
__int64 n_main()
{
const char **v0; // rax
int v1; // ebp
__int64 result; // rax
const char *v3; // rax

v0 = (const char **)read_config();
v1 = connect_to_mud(v0);
result = 1LL;
if ( v1 != -1 )
{
write_network_line("tolsuatoheushtaso,euht\naoeu\n", v1);
v3 = (const char *)read_network_line(v1);
printf("%s", v3);
close(v1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
const char **v0; // rax
int v1; // ebp
__int64 result; // rax
const char *v3; // rax

v0 = (const char **)read_config();
v1 = func0(v0);
result = 1LL;
if ( v1 != -1 )
{
func3("tolsuatoheushtaso,euht\naoeu\n", v1);
v3 = (const char *)func2(v1);
printf("%s", v3);
close(v1);
result = 0LL;
}
return result;
}

original_code:
int n_main() {
struct conf* cnf = read_config();
int mudsock = connect_to_mud(cnf);
if (mudsock == -1) return 1;
write_network_line("tolsuatoheushtaso,euht\naoeu\n",mudsock);
char* test = read_network_line(mudsock);
printf("%s",test);
close(mudsock);
return 0;
}

canonical_original_code:
int n_main() {
struct conf *cnf = read_config();
int mudsock = connect_to_mud(cnf);
if (mudsock == -1) return 1;
write_network_line("tolsuatoheushtaso,euht\naoeu\n",mudsock);
char *test = read_network_line(mudsock);
printf("%s",test);
close(mudsock);
return 0;
}

variable_types:
test
char *

user_defined_types: struct conf { char *address; char *port; int r_size; int t_size; int buffer; }


decompiled_code:
__int64 initialize_windows()
{
int v0; // ebp
int i; // ebx

v0 = 0;
initscr();
start_color();
raw();
noecho();
nonl();
intrflush(stdscr, 0);
keypad(stdscr, 1);
do
{
for ( i = 0; i != 8; ++i )
{
if ( v0 + i )
init_pair(8 * v0 + i, i, v0);
}
++v0;
}
while ( v0 != 8 );
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // ebp
int i; // ebx

v0 = 0;
initscr();
start_color();
raw();
noecho();
nonl();
intrflush(stdscr, 0);
keypad(stdscr, 1);
do
{
for ( i = 0; i != 8; ++i )
{
if ( v0 + i )
init_pair(8 * v0 + i, i, v0);
}
++v0;
}
while ( v0 != 8 );
return 0LL;
}

original_code:
int initialize_windows() {
 initscr();
 start_color();
 raw();
 noecho();
 nonl();
 intrflush(stdscr,0);
 keypad(stdscr,1);
 int bg;
 int fg;
 for (bg = 0; bg < 8; bg++) {
 for (fg = 0; fg < 8; fg++) {
  if (bg+fg > 0) {
   init_pair(fg+8*bg,fg,bg);
  }
 }
 }
 return 0;
}

variable_types: bg int

variable_types: fg int


decompiled_code:
__int64 close_windows()
{
endwin();
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
endwin();
return 0LL;
}

original_code:
int close_windows() {
 endwin();
 return 0;
}


decompiled_code:
_BOOL8 __fastcall is_letter(char a1)
{
return (unsigned __int8)((a1 & 0xDF) - 65) <= 0x19u;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char a1)
{
return (unsigned __int8)((a1 & 0xDF) - 65) <= 0x19u;
}

variable_types: s char


decompiled_code:
__int64 __fastcall get_number(char a1)
{
unsigned int v1; // eax
unsigned int v2; // edi
bool v3; // cf
__int64 result; // rax

v1 = a1 - 49;
v2 = a1 - 48;
v3 = v1 < 9;
result = 0LL;
if ( v3 )
result = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
unsigned int v1; // eax
unsigned int v2; // edi
bool v3; // cf
__int64 result; // rax

v1 = a1 - 49;
v2 = a1 - 48;
v3 = v1 < 9;
result = 0LL;
if ( v3 )
result = v2;
return result;
}

original_code:
int get_number(char s) {
 int r = (int) s - 48;
 if ((r > 0) && (r < 10)) {
  return r;
 } else {
  return 0;
 }
}

variable_types: r int


decompiled_code:
__int64 c_main()
{
const char **v0; // rbx

v0 = (const char **)read_config();
printf("ADDRESS: %s\n", *v0);
printf("PORT: %s\n", v0[1]);
printf("RIGHT WINDOW SIZE: %d\n", *((unsigned int *)v0 + 4));
printf("TOP WINDOW SIZE: %d\n", *((unsigned int *)v0 + 5));
printf("BUFFER SIZE: %d\n", *((unsigned int *)v0 + 6));
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
const char **v0; // rbx

v0 = (const char **)read_config();
printf("ADDRESS: %s\n", *v0);
printf("PORT: %s\n", v0[1]);
printf("RIGHT WINDOW SIZE: %d\n", *((unsigned int *)v0 + 4));
printf("TOP WINDOW SIZE: %d\n", *((unsigned int *)v0 + 5));
printf("BUFFER SIZE: %d\n", *((unsigned int *)v0 + 6));
return 0LL;
}

original_code:
int c_main() {
struct conf* c = read_config();
 printf("ADDRESS: %s\n",c->address);
 printf("PORT: %s\n",c->port);
 printf("RIGHT WINDOW SIZE: %d\n",c->r_size);
 printf("TOP WINDOW SIZE: %d\n",c->t_size);
 printf("BUFFER SIZE: %d\n",c->buffer);
return 0;
}

canonical_original_code:
int c_main() {
struct conf *c = read_config();
 printf("ADDRESS: %s\n",c->address);
 printf("PORT: %s\n",c->port);
 printf("RIGHT WINDOW SIZE: %d\n",c->r_size);
 printf("TOP WINDOW SIZE: %d\n",c->t_size);
 printf("BUFFER SIZE: %d\n",c->buffer);
return 0;
}


decompiled_code:
int display_error(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

canonical_decompiled_code:
int func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

original_code:
int display_error(char* err,...) {
 va_list ap;
 __builtin_va_start(ap,err);
 vfprintf(stderr,err,ap);
}

canonical_original_code:
int display_error(char *err, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,err);
 vfprintf(stderr,err,ap);
}

variable_types:
err
char *


repo: Silberbogen/algorithmns

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v4; // rsi
__int64 v5; // rdx
__int64 v6; // rsi
__int64 v7; // rdx
unsigned int v8; // eax
unsigned int v9; // eax
__int64 v10; // rax
int v12; // [rsp+0h] [rbp-48h] BYREF
__int64 v13; // [rsp+4h] [rbp-44h] BYREF
int v14; // [rsp+Ch] [rbp-3Ch]
__int64 v15[2]; // [rsp+10h] [rbp-38h] BYREF
__int64 v16[2]; // [rsp+20h] [rbp-28h] BYREF
int v17; // [rsp+30h] [rbp-18h]

v3 = 200;
v16[0] = 0x600000003LL;
v16[1] = 0x180000000CLL;
v17 = 9;
v4 = (unsigned int)gcd_array(v16, argv, envp);
printf("gcd of 3, 6, 12, 24, 9 = %d\n", v4);
v15[0] = 0x2300000019LL;
v15[1] = 0x7D00000032LL;
v6 = (unsigned int)gcd_array(v15, v4, v5);
printf("gcd of 25, 35, 50, 125 = %d\n", v6);
v12 = 1;
v8 = gcd_array(&v12, v6, v7);
printf("gcd of 1 = %d\n", v8);
v14 = 72;
v13 = 0x240000000CLL;
v9 = lcm_array(&v13);
printf("lcm of 12, 36, 72 = %d\n", v9);
printf("Primzahl: ");
do
{
v10 = primeNumberGenerator();
printf("%lld, ", v10);
--v3;
}
while ( v3 );
puts("");
resetPrimeNumberGenerator();
return 0;
}

original_code:
int main() {
    printf("gcd of 3, 6, 12, 24, 9 = %d\n", gcd_array( (int[]){3, 6, 12, 24, 9} ));
    printf("gcd of 25, 35, 50, 125 = %d\n", gcd_array( (int[]){25, 35, 50, 125} ));
    printf("gcd of 1 = %d\n", gcd_array( (int[]){1} ));
    printf("lcm of 12, 36, 72 = %d\n", lcm_array( (int[]){12, 36, 72} ));
    printf("Primzahl: ");
    for (int i = 0; i < 200; i++) printf("%lld, ", primeNumberGenerator());
    puts("");
    resetPrimeNumberGenerator();
}

canonical_original_code:
int main() {
    printf("gcd of 3, 6, 12, 24, 9 = %d\n", gcd_array( (int []){3, 6, 12, 24, 9} ));
    printf("gcd of 25, 35, 50, 125 = %d\n", gcd_array( (int []){25, 35, 50, 125} ));
    printf("gcd of 1 = %d\n", gcd_array( (int []){1} ));
    printf("lcm of 12, 36, 72 = %d\n", lcm_array( (int []){12, 36, 72} ));
    printf("Primzahl: ");
    for (int i = 0; i < 200; i++) printf("%lld, ", primeNumberGenerator());
    puts("");
    resetPrimeNumberGenerator();
}

variable_types: i int


resetPrimeNumberGenerator

decompiled_code:
void resetPrimeNumberGenerator()
{
new_number = 2LL;
n_sieb = 1LL;
if ( sieb )
free(sieb);
sieb = 0LL;
}

canonical_decompiled_code:
void func7()
{
new_number = 2LL;
n_sieb = 1LL;
if ( sieb )
free(sieb);
sieb = 0LL;
}

original_code:
void resetPrimeNumberGenerator(void) {
    old_number = 0;
    new_number = 2;
    n_sieb = 1;
    if (sieb) free(sieb);
    sieb = 0;
}

canonical_original_code:
void resetPrimeNumberGenerator() {
    old_number = 0;
    new_number = 2;
    n_sieb = 1;
    if (sieb) free(sieb);
    sieb = 0;
}


decompiled_code:
__int64 __fastcall gcd_single(int a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // edx

for ( result = a2; a1 > 0; a1 -= result )
{
if ( a1 < (int)result )
{
v3 = a1;
a1 = result;
result = v3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // edx

for ( result = a2; a1 > 0; a1 -= result )
{
if ( a1 < (int)result )
{
v3 = a1;
a1 = result;
result = v3;
}
}
return result;
}

original_code:
int gcd_single(int u, int v) {
    while (u > 0) {
        if ( u < v) {
            int temp = u;
            u = v;
            v = temp;
        }
        u = u - v;
    }
    return v;
}

variable_types: u int

variable_types: v int

variable_types: temp int


decompiled_code:
__int64 __fastcall gcd_array(__int64 a1)
{
return gcd_single(*(_DWORD *)(a1 + 4), *(_DWORD *)a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return func8(*(_DWORD *)(a1 + 4), *(_DWORD *)a1);
}

original_code:
int gcd_array(int in[]) {
    int len = sizeof in / sizeof in[0];
    int v = in[0];
    for(int i = 1; i < len; i++) v = gcd_single(in[i], v);
    return v;
}

variable_types:
in
int []

variable_types: len int


decompiled_code:
__int64 __fastcall lcm_single(int a1, int a2)
{
int v3; // eax
int v4; // ecx
int v5[2]; // [rsp+0h] [rbp-8h] BYREF

if ( !a1 || !a2 )
return 0LL;
v5[0] = a1;
v5[1] = a2;
v3 = gcd_array((__int64)v5);
return (unsigned int)(v4 / v3);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
int v3; // eax
int v4; // ecx
int v5[2]; // [rsp+0h] [rbp-8h] BYREF

if ( !a1 || !a2 )
return 0LL;
v5[0] = a1;
v5[1] = a2;
v3 = func9((__int64)v5);
return (unsigned int)(v4 / v3);
}

original_code:
int lcm_single(int a, int b) {
    if (a && b) return a * b / gcd_array( (int[]){a, b} );
    return 0;
}

canonical_original_code:
int lcm_single(int a, int b) {
    if (a && b) return a * b / gcd_array( (int []){a, b} );
    return 0;
}

variable_types: a int

variable_types: b int


decompiled_code:
__int64 __fastcall lcm_array(int *a1)
{
return lcm_single(a1[1], *a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1)
{
return func10(a1[1], *a1);
}

original_code:
int lcm_array(int in[]) {
    int len = sizeof in / sizeof in[0];
    int j = in[0];
    for(int i = 1; i < len; i++) j = lcm_single(in[i], j);
    return j;
}

variable_types: j int


primeNumberGenerator

decompiled_code:
__int64 primeNumberGenerator()
{
__int64 v0; // r12
size_t v1; // rbx
__int64 v2; // rsi
char i; // r8
__int64 v4; // rcx
size_t v5; // rbx
char *v6; // rax
__int64 result; // rax
_QWORD *v8; // rax

if ( !freeOnExit_0 )
{
atexit(resetPrimeNumberGenerator);
freeOnExit_0 = 1;
}
v0 = new_number;
v1 = n_sieb;
if ( new_number == 2 )
{
v8 = calloc(n_sieb, 8uLL);
new_number = 3LL;
v8[v1 - 1] = 2LL;
sieb = v8;
result = 2LL;
}
else
{
v2 = new_number;
for ( i = 0; (__int64)n_sieb > 0; i = 1 )
{
v4 = 0LL;
while ( v2 % *((_QWORD *)sieb + v4) )
{
if ( ++v4 == n_sieb )
goto LABEL_9;
}
v2 += 2LL;
}
LABEL_9:
if ( i )
v0 = v2;
++n_sieb;
v5 = 8 * (v1 + 1);
v6 = (char *)realloc(sieb, v5);
*(_QWORD *)&v6[v5 - 8] = v0;
sieb = v6;
new_number = v0 + 2;
result = v0;
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // r12
size_t v1; // rbx
__int64 v2; // rsi
char i; // r8
__int64 v4; // rcx
size_t v5; // rbx
char *v6; // rax
__int64 result; // rax
_QWORD *v8; // rax

if ( !freeOnExit_0 )
{
func15(resetPrimeNumberGenerator);
freeOnExit_0 = 1;
}
v0 = new_number;
v1 = n_sieb;
if ( new_number == 2 )
{
v8 = calloc(n_sieb, 8uLL);
new_number = 3LL;
v8[v1 - 1] = 2LL;
sieb = v8;
result = 2LL;
}
else
{
v2 = new_number;
for ( i = 0; (__int64)n_sieb > 0; i = 1 )
{
v4 = 0LL;
while ( v2 % *((_QWORD *)sieb + v4) )
{
if ( ++v4 == n_sieb )
goto LABEL_9;
}
v2 += 2LL;
}
LABEL_9:
if ( i )
v0 = v2;
++n_sieb;
v5 = 8 * (v1 + 1);
v6 = (char *)realloc(sieb, v5);
*(_QWORD *)&v6[v5 - 8] = v0;
sieb = v6;
new_number = v0 + 2;
result = v0;
}
return result;
}

original_code:
long long primeNumberGenerator(void) {
    static _Bool freeOnExit = 0;
    if (!freeOnExit) {
        atexit(resetPrimeNumberGenerator);
        freeOnExit = 1;
    }
    if (new_number == 2) {
        sieb = calloc(n_sieb, sizeof(long long));
        sieb[n_sieb - 1] = 2;
        old_number = 2;
        new_number = 3;
        return old_number;
    }
    for (;;) {
        _Bool istPrimzahl = 1;
        for (int i = 0; i < n_sieb; i++) {
            if (new_number % sieb[i] == 0) {
                istPrimzahl = 0;
                break;
            }
        }
        if (istPrimzahl) {
            n_sieb += 1;
            sieb = realloc(sieb, n_sieb * sizeof(long long));
            sieb[n_sieb - 1] = new_number;
            old_number = new_number;
            new_number += 2;
            return old_number;
        }
        new_number += 2;
    }
    return 0;
}

canonical_original_code:
long long primeNumberGenerator() {
    static _Bool freeOnExit = 0;
    if (!freeOnExit) {
        atexit(resetPrimeNumberGenerator);
        freeOnExit = 1;
    }
    if (new_number == 2) {
        sieb = calloc(n_sieb, sizeof(long long));
        sieb[n_sieb - 1] = 2;
        old_number = 2;
        new_number = 3;
        return old_number;
    }
    for (;;) {
        _Bool istPrimzahl = 1;
        for (int i = 0; i < n_sieb; i++) {
            if (new_number % sieb[i] == 0) {
                istPrimzahl = 0;
                break;
            }
        }
        if (istPrimzahl) {
            n_sieb += 1;
            sieb = realloc(sieb, n_sieb * sizeof(long long));
            sieb[n_sieb - 1] = new_number;
            old_number = new_number;
            new_number += 2;
            return old_number;
        }
        new_number += 2;
    }
    return 0;
}

return_type: long long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
_BYTE v4[280]; // [rsp+0h] [rbp-118h] BYREF

if ( argc <= 2 )
{
fprintf(stderr, "Usage:%s string path\n", *argv);
result = -1;
}
else
{
init_worker_crew(v4, 4LL, envp);
crew_start(v4, argv[2], argv[1]);
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[]){
 crew_t point;
 char line[128],*next;
 if(argc<3){
  fprintf(stderr,"Usage:%s string path\n",argv[0]);
  return -1;
 }
 int status=init_worker_crew(&point,4);
 crew_start(&point,argv[2],argv[1]);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 struct crew_tag point;
 char line[128]; char *next;
 if(argc<3){
  fprintf(stderr,"Usage:%s string path\n",argv[0]);
  return -1;
 }
 int status = init_worker_crew(&point,4);
 crew_start(&point,argv[2],argv[1]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct crew_tag { int count_crew_size; struct worker_tag { unsigned long trhead_id; int thread_index; struct crew_tag *crew; } crew_member[4]; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } start; union pthread_cond_t done; struct work_tag { char *path; char *string; struct work_tag *next; } *first; int work_count; }

variable_types:
line
char [128]

variable_types:
next
char *

variable_types: status int

user_defined_types: struct crew_tag { int count_crew_size; struct worker_tag crew_member[4]; union pthread_mutex_t mutex; union pthread_cond_t start; union pthread_cond_t done; struct work_tag *first; int work_count; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }


decompiled_code:
int __fastcall init_worker_crew(pthread_cond_t *a1, int a2)
{
int result; // eax
pthread_mutex_t *v4; // rdi
unsigned __int64 *v5; // rbx
int i; // ebp

if ( a2 <= 3 )
{
a1->__lock = a2;
v4 = (pthread_mutex_t *)(&a1[2].__align + 1);
*((_DWORD *)&v4[3].__align + 8) = 0;
*(&v4[3].__align + 2) = 0LL;
v4[3].__list.__prev = 0LL;
if ( !pthread_mutex_init(v4, 0LL) && !pthread_cond_init(a1 + 3, 0LL) )
pthread_cond_init(a1 + 4, 0LL);
v5 = &a1->__total_seq;
for ( i = 0; i != 4; ++i )
{
*((_DWORD *)v5 + 2) = i;
v5[2] = (unsigned __int64)a1;
result = pthread_create(v5, 0LL, thread_routine, v5);
if ( result )
_assert_fail("status==0", "filter_string_crew.c", 0x2Au, "init_worker_crew");
v5 += 3;
}
}
else
{
*_errno_location() = 22;
result = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(pthread_cond_t *a1, int a2)
{
int result; // eax
pthread_mutex_t *v4; // rdi
unsigned __int64 *v5; // rbx
int i; // ebp

if ( a2 <= 3 )
{
a1->__lock = a2;
v4 = (pthread_mutex_t *)(&a1[2].__align + 1);
*((_DWORD *)&v4[3].__align + 8) = 0;
*(&v4[3].__align + 2) = 0LL;
v4[3].__list.__prev = 0LL;
if ( !pthread_mutex_init(v4, 0LL) && !pthread_cond_init(a1 + 3, 0LL) )
pthread_cond_init(a1 + 4, 0LL);
v5 = &a1->__total_seq;
for ( i = 0; i != 4; ++i )
{
*((_DWORD *)v5 + 2) = i;
v5[2] = (unsigned __int64)a1;
result = pthread_create(v5, 0LL, thread_routine, v5);
if ( result )
_assert_fail("status==0", "filter_string_crew.c", 0x2Au, "init_worker_crew");
v5 += 3;
}
}
else
{
*_errno_location() = 22;
result = 1;
}
return result;
}

original_code:
int init_worker_crew(crew_t *crew,int crew_size){
 int status;
 if(crew_size>=4){
  (*__errno_location ())=22;
  return 1;
 }
 crew->count_crew_size=crew_size;
 crew->work_count=0;
 crew->first=((void *)0);
 crew->end=((void *)0);
 do{
  if(pthread_mutex_init(&crew->mutex,((void *)0))!=0) break;
  if(pthread_cond_init(&crew->start,((void *)0))!=0) break;
  if(pthread_cond_init(&crew->done,((void *)0))!=0) break;
 }while(0);
 for(int index=0;index<4;index++){
  crew->crew_member[index].thread_index=index;
  crew->crew_member[index].crew=crew;
  status=pthread_create(&crew->crew_member[index].trhead_id, ((void *)0),thread_routine,(void*)&crew->crew_member[index]);
  ((status==0) ? (void) (0) : __assert_fail ("status==0", "filter_string_crew.c", 42, __extension__ __PRETTY_FUNCTION__));
 }
 return 0;
}

canonical_original_code:
int init_worker_crew(struct crew_tag *crew, int crew_size){
 int status;
 if(crew_size>=4){
  (*__errno_location ())=22;
  return 1;
 }
 crew->count_crew_size=crew_size;
 crew->work_count=0;
 crew->first=((void *)0);
 crew->end=((void *)0);
 do{
  if(pthread_mutex_init(&crew->mutex,((void *)0))!=0) break;
  if(pthread_cond_init(&crew->start,((void *)0))!=0) break;
  if(pthread_cond_init(&crew->done,((void *)0))!=0) break;
 }while(0);
 for(int index = 0;index<4;index++){
  crew->crew_member[index].thread_index=index;
  crew->crew_member[index].crew=crew;
  status=pthread_create(&crew->crew_member[index].trhead_id, ((void *)0),thread_routine,(void *)&crew->crew_member[index]);
  ((status==0) ? (void) (0) : __assert_fail ("status==0", "filter_string_crew.c", 42, __extension__ __PRETTY_FUNCTION__));
 }
 return 0;
}

variable_types: struct crew_tag { int count_crew_size; struct worker_tag { unsigned long trhead_id; int thread_index; struct crew_tag *crew; } crew_member[4]; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } start; union pthread_cond_t done; struct work_tag { char *path; char *string; struct work_tag *next; } *first; int work_count; } *

variable_types: index int


initDoor

decompiled_code:
__int64 initDoor()
{
__int64 v0; // rax
int v1; // edx
__int64 v2; // rdi
int v3; // edx
__int64 v4; // rdx

theDoor = 5832780;
*((_QWORD *)&theDoor + 4) = screen;
*((_WORD *)&theDoor + 2) = 1191;
*((_WORD *)&theDoor + 3) = rand() % 631 + 10;
v0 = IMG_Load("./res/img/door.png");
v1 = *((__int16 *)&theDoor + 2);
v2 = v0;
*((_QWORD *)&theDoor + 3) = v0;
LODWORD(v0) = v1 + (HIWORD(theDoor) >> 1);
v3 = *((__int16 *)&theDoor + 3);
*(&theDoor + 3) = v0;
LODWORD(v0) = v3 + ((unsigned __int16)theDoor >> 1);
v4 = screen;
*(&theDoor + 4) = v0;
SDL_UpperBlit(v2, 0LL, v4, (unsigned int)((_DWORD)&theDoor + 4));
return SDL_Flip(screen);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
int v1; // edx
__int64 v2; // rdi
int v3; // edx
__int64 v4; // rdx

theDoor = 5832780;
*((_QWORD *)&theDoor + 4) = screen;
*((_WORD *)&theDoor + 2) = 1191;
*((_WORD *)&theDoor + 3) = rand() % 631 + 10;
v0 = IMG_Load("./res/img/door.png");
v1 = *((__int16 *)&theDoor + 2);
v2 = v0;
*((_QWORD *)&theDoor + 3) = v0;
LODWORD(v0) = v1 + (HIWORD(theDoor) >> 1);
v3 = *((__int16 *)&theDoor + 3);
*(&theDoor + 3) = v0;
LODWORD(v0) = v3 + ((unsigned __int16)theDoor >> 1);
v4 = screen;
*(&theDoor + 4) = v0;
SDL_UpperBlit(v2, 0LL, v4, (unsigned int)((_DWORD)&theDoor + 4));
return SDL_Flip(screen);
}

original_code:
void initDoor()
{
  theDoor.doorHeight = 76;
  theDoor.doorWidth = 89;
  theDoor.screen = screen;
  theDoor.doorSource.x = 1280 - theDoor.doorWidth;
  theDoor.doorSource.y = (10+(rand () % ( (720 -80) -10 + 1)));
  theDoor.doorSurface = IMG_Load("./res/img/door.png");
  theDoor.doorCenter.x = theDoor.doorSource.x + theDoor.doorWidth/2;
  theDoor.doorCenter.y = theDoor.doorSource.y + theDoor.doorHeight/2;
  SDL_UpperBlit(theDoor.doorSurface, ((void *)0), screen, &(theDoor.doorSource));
  SDL_Flip(screen);
}