calc

decompiled_code:
__int64 __fastcall calc(__int64 a1, char *a2, int a3)
{
int v5; // eax
size_t v7; // rsi
const char *v8; // rcx

v5 = request_option_code();
if ( v5 > 28 )
{
if ( v5 == 1000 )
return (unsigned int)(printf("Server shutdown NOW\n") + 3);
}
else if ( v5 >= -1 )
{
switch ( v5 )
{
case -1:
v7 = a3;
v8 = "Request parsing failed";
break;
case 16:
v7 = a3;
v8 = "Unkown request type";
break;
case 17:
v7 = a3;
v8 = (const char *)info_by_ip_and_hosts(a1);
break;
case 18:
v7 = a3;
v8 = (const char *)info_by_ip_and_hosts_per_subnet(a1);
break;
case 19:
v7 = a3;
v8 = (const char *)info_by_ip_and_subnets(a1);
break;
case 20:
v7 = a3;
v8 = (const char *)info_by_hosts(a1);
break;
case 21:
v7 = a3;
v8 = (const char *)info_by_hosts_per_subnet(a1);
break;
case 22:
v7 = a3;
v8 = (const char *)info_by_subnets(a1);
break;
case 23:
v7 = a3;
v8 = (const char *)subnetting_by_ip_and_hosts(a1);
break;
case 24:
v7 = a3;
v8 = (const char *)subnetting_by_ip_and_hosts_per_subnet(a1);
break;
case 25:
v7 = a3;
v8 = (const char *)subnetting_by_ip_and_subnets(a1);
break;
case 26:
v7 = a3;
v8 = (const char *)subnetting_by_hosts(a1);
break;
case 27:
v7 = a3;
v8 = (const char *)subnetting_by_hosts_per_subnet(a1);
break;
case 28:
v7 = a3;
v8 = (const char *)subnetting_by_subnets(a1);
break;
default:
goto LABEL_6;
}
goto LABEL_7;
}
LABEL_6:
v7 = a3;
v8 = "This shouldn't happen at all!";
LABEL_7:
snprintf(a2, v7, "%s", v8);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2, int a3)
{
int v5; // eax
size_t v7; // rsi
const char *v8; // rcx

v5 = request_option_code();
if ( v5 > 28 )
{
if ( v5 == 1000 )
return (unsigned int)(printf("Server shutdown NOW\n") + 3);
}
else if ( v5 >= -1 )
{
switch ( v5 )
{
case -1:
v7 = a3;
v8 = "Request parsing failed";
break;
case 16:
v7 = a3;
v8 = "Unkown request type";
break;
case 17:
v7 = a3;
v8 = (const char *)info_by_ip_and_hosts(a1);
break;
case 18:
v7 = a3;
v8 = (const char *)info_by_ip_and_hosts_per_subnet(a1);
break;
case 19:
v7 = a3;
v8 = (const char *)info_by_ip_and_subnets(a1);
break;
case 20:
v7 = a3;
v8 = (const char *)info_by_hosts(a1);
break;
case 21:
v7 = a3;
v8 = (const char *)info_by_hosts_per_subnet(a1);
break;
case 22:
v7 = a3;
v8 = (const char *)info_by_subnets(a1);
break;
case 23:
v7 = a3;
v8 = (const char *)subnetting_by_ip_and_hosts(a1);
break;
case 24:
v7 = a3;
v8 = (const char *)subnetting_by_ip_and_hosts_per_subnet(a1);
break;
case 25:
v7 = a3;
v8 = (const char *)subnetting_by_ip_and_subnets(a1);
break;
case 26:
v7 = a3;
v8 = (const char *)subnetting_by_hosts(a1);
break;
case 27:
v7 = a3;
v8 = (const char *)subnetting_by_hosts_per_subnet(a1);
break;
case 28:
v7 = a3;
v8 = (const char *)subnetting_by_subnets(a1);
break;
default:
goto LABEL_6;
}
goto LABEL_7;
}
LABEL_6:
v7 = a3;
v8 = "This shouldn't happen at all!";
LABEL_7:
snprintf(a2, v7, "%s", v8);
return 0LL;
}

original_code:
extern int calc(const char* request, char* response, int size) {
 switch(request_option_code(request)) {
 case 17:
  snprintf(response, size, "%s", info_by_ip_and_hosts(request)); break;
 case 18:
  snprintf(response, size, "%s", info_by_ip_and_hosts_per_subnet(request)); break;
 case 19:
  snprintf(response, size, "%s", info_by_ip_and_subnets(request)); break;
 case 20:
  snprintf(response, size, "%s", info_by_hosts(request)); break;
 case 21:
  snprintf(response, size, "%s", info_by_hosts_per_subnet(request)); break;
 case 22:
  snprintf(response, size, "%s", info_by_subnets(request)); break;
 case 23:
  snprintf(response, size, "%s", subnetting_by_ip_and_hosts(request)); break;
 case 24:
  snprintf(response, size, "%s", subnetting_by_ip_and_hosts_per_subnet(request)); break;
 case 25:
  snprintf(response, size, "%s", subnetting_by_ip_and_subnets(request)); break;
 case 26:
  snprintf(response, size, "%s", subnetting_by_hosts(request)); break;
 case 27:
  snprintf(response, size, "%s", subnetting_by_hosts_per_subnet(request)); break;
 case 28:
  snprintf(response, size, "%s", subnetting_by_subnets(request)); break;
 case -1:
  snprintf(response, size, "%s", "Request parsing failed"); break;
 case 16:
  snprintf(response, size, "%s", "Unkown request type"); break;
 case 1000:
  return 3 + 1*printf("Server shutdown NOW\n");
 default:
  snprintf(response, size, "%s", "This shouldn't happen at all!"); break;
 }
 return 0;
}

canonical_original_code:
extern int calc(char *request, char *response, int size) {
 switch(request_option_code(request)) {
 case 17:
  snprintf(response, size, "%s", info_by_ip_and_hosts(request)); break;
 case 18:
  snprintf(response, size, "%s", info_by_ip_and_hosts_per_subnet(request)); break;
 case 19:
  snprintf(response, size, "%s", info_by_ip_and_subnets(request)); break;
 case 20:
  snprintf(response, size, "%s", info_by_hosts(request)); break;
 case 21:
  snprintf(response, size, "%s", info_by_hosts_per_subnet(request)); break;
 case 22:
  snprintf(response, size, "%s", info_by_subnets(request)); break;
 case 23:
  snprintf(response, size, "%s", subnetting_by_ip_and_hosts(request)); break;
 case 24:
  snprintf(response, size, "%s", subnetting_by_ip_and_hosts_per_subnet(request)); break;
 case 25:
  snprintf(response, size, "%s", subnetting_by_ip_and_subnets(request)); break;
 case 26:
  snprintf(response, size, "%s", subnetting_by_hosts(request)); break;
 case 27:
  snprintf(response, size, "%s", subnetting_by_hosts_per_subnet(request)); break;
 case 28:
  snprintf(response, size, "%s", subnetting_by_subnets(request)); break;
 case -1:
  snprintf(response, size, "%s", "Request parsing failed"); break;
 case 16:
  snprintf(response, size, "%s", "Unkown request type"); break;
 case 1000:
  return 3 + 1*printf("Server shutdown NOW\n");
 default:
  snprintf(response, size, "%s", "This shouldn't happen at all!"); break;
 }
 return 0;
}

variable_types:
response
char *

variable_types: size int


repo: urbo-escom/c-ip-subnetting

decompiled_code:
char *get_time()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = localtime(&timer);
strftime(buffer, 0x1BuLL, "[%Y:%m:%d %H:%M:%S]", v0);
return buffer;
}

canonical_decompiled_code:
char *func0()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = localtime(&timer);
strftime(buffer, 0x1BuLL, "[%Y:%m:%d %H:%M:%S]", v0);
return buffer;
}

original_code:
static char* get_time() {
 time_t timer;
 struct tm* tm_info;
 time(&timer);
 tm_info = localtime(&timer);
 strftime(buffer, 27, "[%Y:%m:%d %H:%M:%S]", tm_info);
 return buffer;
}

canonical_original_code:
static char *get_time() {
 long timer;
 struct tm *tm_info;
 time(&timer);
 tm_info = localtime(&timer);
 strftime(buffer, 27, "[%Y:%m:%d %H:%M:%S]", tm_info);
 return buffer;
}

variable_types: timer long

variable_types: struct tm { 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; long tm_gmtoff; char *tm_zone; } *

return_type: char *


decompiled_code:
__int64 __fastcall Socket_receive(int *a1, _BYTE *a2, int a3)
{
unsigned int v3; // ebp
char *v4; // rax
char *v5; // rax
char *v7; // r12
const char *v8; // rbx
int v9; // edi
char *v10; // rax

*a2 = 0;
v3 = recv(*a1, a2, a3, 0);
if ( v3 == -1 )
{
v7 = "None";
Socket_set_errno(4294967284LL);
v8 = (const char *)Socket_strerror();
v9 = *_errno_location();
if ( v9 )
v7 = strerror(v9);
v10 = get_time();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Receive failed: %s\n",
v10,
"src/network/bsd-win-sock-receive.c",
14LL,
v7,
v8);
}
else
{
v4 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) NULL terminating message\n", v4, "src/network/bsd-win-sock-receive.c", 18LL);
a2[v3] = 0;
v5 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Message: '%s'\n", v5, "src/network/bsd-win-sock-receive.c", 21LL, a2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, _BYTE *a2, int a3)
{
unsigned int v3; // ebp
char *v4; // rax
char *v5; // rax
char *v7; // r12
const char *v8; // rbx
int v9; // edi
char *v10; // rax

*a2 = 0;
v3 = recv(*a1, a2, a3, 0);
if ( v3 == -1 )
{
v7 = "None";
Socket_set_errno(4294967284LL);
v8 = (const char *)Socket_strerror();
v9 = *_errno_location();
if ( v9 )
v7 = strerror(v9);
v10 = func0();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Receive failed: %s\n",
v10,
"src/network/bsd-win-sock-receive.c",
14LL,
v7,
v8);
}
else
{
v4 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) NULL terminating message\n", v4, "src/network/bsd-win-sock-receive.c", 18LL);
a2[v3] = 0;
v5 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Message: '%s'\n", v5, "src/network/bsd-win-sock-receive.c", 21LL, a2);
}
return v3;
}

original_code:
extern int Socket_receive(Socket_T* sock, char* msg, int msg_len) {
 msg[0] = '\0';
 int n = recv(sock->sockfd_dest, msg, msg_len, 0);
 if (n == -1) {
  Socket_set_errno(-12);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Receive failed: %s" "\n", get_time(), "src/network/bsd-win-sock-receive.c", 14, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "NULL terminating message" "\n", get_time(), "src/network/bsd-win-sock-receive.c", 18);
 msg[n] = '\0';
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Message: '%s'" "\n", get_time(), "src/network/bsd-win-sock-receive.c", 21, msg);
 return n;
}

canonical_original_code:
extern int Socket_receive(struct Socket_T *sock, char *msg, int msg_len) {
 msg[0] = '\0';
 int n = recv(sock->sockfd_dest, msg, msg_len, 0);
 if (n == -1) {
  Socket_set_errno(-12);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Receive failed: %s" "\n", get_time(), "src/network/bsd-win-sock-receive.c", 14, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "NULL terminating message" "\n", get_time(), "src/network/bsd-win-sock-receive.c", 18);
 msg[n] = '\0';
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Message: '%s'" "\n", get_time(), "src/network/bsd-win-sock-receive.c", 21, msg);
 return n;
}

variable_types: struct Socket_T { int sockfd_dest; int sockfd_src; 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; } hints; struct addrinfo *result; char peer_ip[20]; char peer_port[20]; char *address; char *portnum; } *

variable_types:
msg
char *

variable_types: n int

return_type: int

user_defined_types: struct Socket_T { int sockfd_dest; int sockfd_src; struct addrinfo hints; struct addrinfo *result; char peer_ip[20]; char peer_port[20]; char *address; char *portnum; }

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: struct tm { 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; long tm_gmtoff; char *tm_zone; }


repo: urezki/sftpd

decompiled_code:
void __fastcall str_contac(char *a1)
{
char v1; // al

if ( a1 )
{
while ( 1 )
{
v1 = *a1;
if ( !*a1 )
break;
if ( (unsigned __int8)(v1 - 97) <= 0x19u )
*a1 = v1 - 32;
++a1;
}
}
}

canonical_decompiled_code:
void __fastcall func0(char *a1)
{
char v1; // al

if ( a1 )
{
while ( 1 )
{
v1 = *a1;
if ( !*a1 )
break;
if ( (unsigned __int8)(v1 - 97) <= 0x19u )
*a1 = v1 - 32;
++a1;
}
}
}

variable_types:
s
char *

return_type: void


decompiled_code:
__int64 __fastcall str_strlen(_BYTE *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 && *a1 )
{
do
++result;
while ( a1[result] );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 && *a1 )
{
do
++result;
while ( a1[result] );
}
return result;
}

original_code:
size_t
str_strlen(const char *s)
{
 size_t i = 0;
 if (s) {
  while (*(s++) != '\0')
   i++;
 }
 return i;
}

canonical_original_code:
unsigned long str_strlen(char *s)
{
 unsigned long i = 0;
 if (s) {
  while (*(s++) != '\0')
   i++;
 }
 return i;
}

variable_types:
i
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall str_strcspn(_BYTE *a1, _BYTE *a2)
{
__int64 v2; // rax
__int64 v3; // rcx
__int64 v4; // r8
unsigned __int64 v5; // r9
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rax

str_strlen(a1);
v2 = str_strlen(a2);
v6 = v2;
if ( v5 && v2 )
{
while ( 2 )
{
v7 = 0LL;
do
{
if ( *(_BYTE *)(v3 + v4) == a2[v7] )
return (int)v4;
++v7;
}
while ( v7 < v6 );
if ( v5 > ++v4 )
continue;
break;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, _BYTE *a2)
{
__int64 v2; // rax
__int64 v3; // rcx
__int64 v4; // r8
unsigned __int64 v5; // r9
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rax

func1(a1);
v2 = func1(a2);
v6 = v2;
if ( v5 && v2 )
{
while ( 2 )
{
v7 = 0LL;
do
{
if ( *(_BYTE *)(v3 + v4) == a2[v7] )
return (int)v4;
++v7;
}
while ( v7 < v6 );
if ( v5 > ++v4 )
continue;
break;
}
}
return v4;
}

original_code:
size_t
str_strcspn(const char *a, const char *b)
{
 size_t a_len;
 size_t b_len;
 int i, j = 0;
 a_len = str_strlen(a);
 b_len = str_strlen(b);
 if (!a_len || !b_len)
  goto out;
 for (i = 0; i < a_len; i++) {
  for (j = 0; j < b_len; j++) {
   if (a[i] != b[j])
    continue;
   goto out;
  }
 }
out:
 return i;
}

canonical_original_code:
unsigned long str_strcspn(char *a, char *b)
{
 unsigned long a_len;
 unsigned long b_len;
 int i; int j = 0;
 a_len = str_strlen(a);
 b_len = str_strlen(b);
 if (!a_len || !b_len)
  goto out;
 for (i = 0; i < a_len; i++) {
  for (j = 0; j < b_len; j++) {
   if (a[i] != b[j])
    continue;
   goto out;
  }
 }
out:
 return i;
}

variable_types:
a
char *

variable_types:
b
char *

variable_types: i int

variable_types: j int


original_code:
size_t
str_findss(const char *a, const char *b)
{
 size_t a_len;
 size_t b_len;
 size_t index;
 int i, j;
 a_len = str_strlen(a);
 b_len = str_strlen(b);
 if (!a_len || !b_len)
  goto not_found;
 for (i = 0; i < a_len; i++) {
  if (a[i] == b[0]) {
   index = i;
   for (j = 0; i < a_len; i++) {
    if (a[i] == b[j]) {
     if (++j == b_len)
      return index;
    } else {
     i--;
     break;
    }
   }
  }
 }
not_found:
 return 0;
}

canonical_original_code:
unsigned long str_findss(char *a, char *b)
{
 unsigned long a_len;
 unsigned long b_len;
 unsigned long index;
 int i; int j;
 a_len = str_strlen(a);
 b_len = str_strlen(b);
 if (!a_len || !b_len)
  goto not_found;
 for (i = 0; i < a_len; i++) {
  if (a[i] == b[0]) {
   index = i;
   for (j = 0; i < a_len; i++) {
    if (a[i] == b[j]) {
     if (++j == b_len)
      return index;
    } else {
     i--;
     break;
    }
   }
  }
 }
not_found:
 return 0;
}

variable_types:
index
unsigned long


decompiled_code:
__int64 __fastcall str_removesfs(_BYTE *a1, char *a2)
{
__int64 result; // rax

result = str_findss(a1, a2);
if ( result )
a1[result] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1, char *a2)
{
__int64 result; // rax

result = func3(a1, a2);
if ( result )
a1[result] = 0;
return result;
}

original_code:
size_t
str_removesfs(char *a, const char *b)
{
 size_t i;
 i = str_findss(a, b);
 if (i)
  a[i] = '\0';
 return i;
}

canonical_original_code:
unsigned long str_removesfs(char *a, char *b)
{
 unsigned long i;
 i = str_findss(a, b);
 if (i)
  a[i] = '\0';
 return i;
}


original_code:
size_t
str_remove_from_to_symbols(char *str, char a, char b)
{
 size_t str_new_len = 0;
 size_t str_len;
 int i, j;
 str_len = str_strlen(str);
again:
 for (i = 0; i < str_len; i++) {
  if (str[i] == a) {
   for (j = i; j < str_len; j++) {
    if (str[j] == b) {
     do {
      str[i++] = str[++j];
     } while (str[j] != '\0');
     str_new_len = str_len =
      (str_len - (j - i)) - 1;
     goto again;
    }
   }
  }
 }
 return str_new_len;
}

canonical_original_code:
unsigned long str_remove_from_to_symbols(char *str, char a, char b)
{
 unsigned long str_new_len = 0;
 unsigned long str_len;
 int i; int j;
 str_len = str_strlen(str);
again:
 for (i = 0; i < str_len; i++) {
  if (str[i] == a) {
   for (j = i; j < str_len; j++) {
    if (str[j] == b) {
     do {
      str[i++] = str[++j];
     } while (str[j] != '\0');
     str_new_len = str_len =
      (str_len - (j - i)) - 1;
     goto again;
    }
   }
  }
 }
 return str_new_len;
}

variable_types:
str
char *

variable_types: a char

variable_types: b char


decompiled_code:
__int64 __fastcall hash_function(_BYTE *a1, unsigned int a2)
{
int v2; // edx
unsigned int v3; // eax
int v4; // eax
unsigned int v5; // edx

v2 = (char)*a1;
if ( !*a1 )
return 0LL;
v3 = 0;
do
{
++a1;
v4 = v2 + 16 * v3;
v5 = ~(v4 & 0xF0000000);
if ( (v4 & 0xF0000000) != 0 )
v4 ^= (v4 & 0xF0000000) >> 24;
v3 = v5 & v4;
v2 = (char)*a1;
}
while ( *a1 );
return v3 % a2;
}

original_code:
static inline unsigned int
hash_function(const char *key, int table_size)
{
 unsigned int h = 0;
 unsigned int g = 0;
 while (*key) {
  h = (h << 4U) + *key++;
  if ((g = h & 0xf0000000))
   h ^= g >> 24U;
  h &= ~g;
 }
 return h % table_size;
}

canonical_original_code:
static inline unsigned int hash_function(char *key, int table_size)
{
 unsigned int h = 0;
 unsigned int g = 0;
 while (*key) {
  h = (h << 4U) + *key++;
  if ((g = h & 0xf0000000))
   h ^= g >> 24U;
  h &= ~g;
 }
 return h % table_size;
}

variable_types:
key
char *

variable_types:
h
unsigned int

variable_types:
g
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall hash_del_entry(__int64 a1, __int64 *a2)
{
_QWORD *v2; // rcx
__int64 v3; // rdx

if ( a1 && a2 )
{
v2 = (_QWORD *)a2[1];
v3 = *a2;
if ( v2 )
{
*v2 = v3;
if ( !v3 )
{
LABEL_6:
free(a2);
return 1LL;
}
}
else if ( !v3 )
{
goto LABEL_9;
}
*(_QWORD *)(v3 + 8) = v2;
if ( a2[1] )
goto LABEL_6;
LABEL_9:
*(_QWORD *)(a1 + 8LL * *((unsigned int *)a2 + 6) + 8) = v3;
goto LABEL_6;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 *a2)
{
_QWORD *v2; // rcx
__int64 v3; // rdx

if ( a1 && a2 )
{
v2 = (_QWORD *)a2[1];
v3 = *a2;
if ( v2 )
{
*v2 = v3;
if ( !v3 )
{
LABEL_6:
free(a2);
return 1LL;
}
}
else if ( !v3 )
{
goto LABEL_9;
}
*(_QWORD *)(v3 + 8) = v2;
if ( a2[1] )
goto LABEL_6;
LABEL_9:
*(_QWORD *)(a1 + 8LL * *((unsigned int *)a2 + 6) + 8) = v3;
goto LABEL_6;
}
return 0LL;
}

original_code:
int
hash_del_entry(struct hash *h, struct hash_entry *entry)
{
 if (h && entry) {
  if (entry->prev)
   entry->prev->next = entry->next;
  if (entry->next)
   entry->next->prev = entry->prev;
  if (entry->prev == ((void *)0))
   h->hash_table[entry->index] = entry->next;
  free(entry);
  return 1;
 }
 return 0;
}

variable_types: struct hash { unsigned int hash_size; void *hash_table[]; } *

variable_types: struct hash_entry { struct hash_entry *next; struct hash_entry *prev; long born_time; unsigned int index; char key[4096]; void *data; } *


decompiled_code:
_BOOL8 __fastcall hash_del(unsigned int *a1, char *a2)
{
__int64 v3; // rbp

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v3 = *(_QWORD *)&a1[2 * (unsigned int)hash_function(a2, *a1) + 2];
if ( !v3 )
return 0LL;
if ( strcmp((const char *)(v3 + 28), a2) )
{
while ( 1 )
{
v3 = *(_QWORD *)v3;
if ( !v3 )
break;
if ( !strcmp((const char *)(v3 + 28), a2) )
return (unsigned int)hash_del_entry((__int64)a1, (__int64 *)v3) != 0;
}
return 0LL;
}
return (unsigned int)hash_del_entry((__int64)a1, (__int64 *)v3) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(unsigned int *a1, char *a2)
{
__int64 v3; // rbp

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v3 = *(_QWORD *)&a1[2 * (unsigned int)func0(a2, *a1) + 2];
if ( !v3 )
return 0LL;
if ( strcmp((const char *)(v3 + 28), a2) )
{
while ( 1 )
{
v3 = *(_QWORD *)v3;
if ( !v3 )
break;
if ( !strcmp((const char *)(v3 + 28), a2) )
return (unsigned int)func1((__int64)a1, (__int64 *)v3) != 0;
}
return 0LL;
}
return (unsigned int)func1((__int64)a1, (__int64 *)v3) != 0;
}

original_code:
int
hash_del(struct hash *h, const char *key)
{
 struct hash_entry *tmp;
 unsigned int index;
 if (h && key) {
  index = hash_function(key, h->hash_size);
  tmp = h->hash_table[index];
  if (tmp == ((void *)0))
   goto out;
  for (; tmp; tmp = tmp->next) {
   if (!strcmp(tmp->key, key)) {
    int ret = hash_del_entry(h, tmp);
    if (ret)
     return 1;
    else
     goto out;
   }
  }
 }
out:
 return 0;
}

canonical_original_code:
int hash_del(struct hash *h, char *key)
{
 struct hash_entry *tmp;
 unsigned int index;
 if (h && key) {
  index = hash_function(key, h->hash_size);
  tmp = h->hash_table[index];
  if (tmp == ((void *)0))
   goto out;
  for (; tmp; tmp = tmp->next) {
   if (!strcmp(tmp->key, key)) {
    int ret = hash_del_entry(h, tmp);
    if (ret)
     return 1;
    else
     goto out;
   }
  }
 }
out:
 return 0;
}

variable_types:
index
unsigned int

variable_types: ret int

user_defined_types: struct hash { unsigned int hash_size; void *hash_table[]; }

user_defined_types: struct hash_entry { struct hash_entry *next; struct hash_entry *prev; long born_time; unsigned int index; char key[4096]; void *data; }


original_code:
void
hash_destroy(struct hash *h)
{
 struct hash_entry *tmp;
 int i;
 if (h) {
  for (i = 0; h->hash_table[i] != ((void *) 0x00100100); i++) {
   tmp = h->hash_table[i];
   while (tmp) {
    (void) hash_del(h, tmp->key);
    tmp = h->hash_table[i];
   }
   h->hash_table[i] = ((void *)0);
  }
  free(h);
 }
}


decompiled_code:
__int64 __fastcall hash_add(unsigned int *a1, char *a2, __int64 a3)
{
__int64 result; // rax
unsigned int v5; // ebx
char *v6; // rax
char *v7; // r12
time_t v8; // rax
__int64 v9; // rax
char *v10; // rbx

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
v5 = hash_function(a2, *a1);
v6 = (char *)calloc(1uLL, 0x1028uLL);
v7 = v6;
if ( v6 )
{
strncpy(v6 + 28, a2, 0x1000uLL);
v8 = time(0LL);
*((_DWORD *)v7 + 6) = v5;
*((_QWORD *)v7 + 2) = v8;
v9 = v5;
v10 = *(char **)&a1[2 * v5 + 2];
*((_QWORD *)v7 + 516) = a3;
*(_QWORD *)v7 = 0LL;
*((_QWORD *)v7 + 1) = 0LL;
if ( !v10 )
{
*(_QWORD *)&a1[2 * v9 + 2] = v7;
return 1LL;
}
while ( strcmp(v10 + 28, a2) )
{
if ( !*(_QWORD *)v10 )
{
*(_QWORD *)v10 = v7;
result = 1LL;
*((_QWORD *)v7 + 1) = v10;
*(_QWORD *)v7 = 0LL;
return result;
}
v10 = *(char **)v10;
}
}
free(v7);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, char *a2, __int64 a3)
{
__int64 result; // rax
unsigned int v5; // ebx
char *v6; // rax
char *v7; // r12
time_t v8; // rax
__int64 v9; // rax
char *v10; // rbx

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
v5 = func0(a2, *a1);
v6 = (char *)calloc(1uLL, 0x1028uLL);
v7 = v6;
if ( v6 )
{
strncpy(v6 + 28, a2, 0x1000uLL);
v8 = time(0LL);
*((_DWORD *)v7 + 6) = v5;
*((_QWORD *)v7 + 2) = v8;
v9 = v5;
v10 = *(char **)&a1[2 * v5 + 2];
*((_QWORD *)v7 + 516) = a3;
*(_QWORD *)v7 = 0LL;
*((_QWORD *)v7 + 1) = 0LL;
if ( !v10 )
{
*(_QWORD *)&a1[2 * v9 + 2] = v7;
return 1LL;
}
while ( strcmp(v10 + 28, a2) )
{
if ( !*(_QWORD *)v10 )
{
*(_QWORD *)v10 = v7;
result = 1LL;
*((_QWORD *)v7 + 1) = v10;
*(_QWORD *)v7 = 0LL;
return result;
}
v10 = *(char **)v10;
}
}
free(v7);
result = 0LL;
}
return result;
}

original_code:
int
hash_add(struct hash *h, const char *key, void *data)
{
 struct hash_entry *node;
 struct hash_entry *tmp;
 unsigned int index;
 if (h == ((void *)0) || key == ((void *)0))
  goto out;
 index = hash_function(key, h->hash_size);
 node = (hash_entry *) calloc(1, sizeof(hash_entry));
 if (node) {
  (void) strncpy(node->key, key, sizeof(node->key));
  node->born_time = time(((void *)0));
  node->index = index;
  node->data = data;
  node->next = ((void *)0);
  node->prev = ((void *)0);
  if (h->hash_table[index] == ((void *)0)) {
   h->hash_table[index] = node;
  } else {
   tmp = h->hash_table[index];
   while (1) {
    if (!strcmp(tmp->key, key))
     goto out_and_free;
    if (tmp->next)
     tmp = tmp->next;
    else
     break;
   }
   tmp->next = node;
   node->next = ((void *)0);
   node->prev = tmp;
  }
  return 1;
 }
out_and_free:
 free(node);
out:
 return 0;
}

canonical_original_code:
int hash_add(struct hash *h, char *key, void *data)
{
 struct hash_entry *node;
 struct hash_entry *tmp;
 unsigned int index;
 if (h == ((void *)0) || key == ((void *)0))
  goto out;
 index = hash_function(key, h->hash_size);
 node = (struct hash_entry *) calloc(1, sizeof(hash_entry));
 if (node) {
  (void) strncpy(node->key, key, sizeof(node->key));
  node->born_time = time(((void *)0));
  node->index = index;
  node->data = data;
  node->next = ((void *)0);
  node->prev = ((void *)0);
  if (h->hash_table[index] == ((void *)0)) {
   h->hash_table[index] = node;
  } else {
   tmp = h->hash_table[index];
   while (1) {
    if (!strcmp(tmp->key, key))
     goto out_and_free;
    if (tmp->next)
     tmp = tmp->next;
    else
     break;
   }
   tmp->next = node;
   node->next = ((void *)0);
   node->prev = tmp;
  }
  return 1;
 }
out_and_free:
 free(node);
out:
 return 0;
}

variable_types:
data
void *


decompiled_code:
const char *__fastcall hash_lookup(unsigned int *a1, char *a2)
{
unsigned int v2; // eax
__int64 v3; // r9
const char *v4; // r12

if ( !a1 || !a2 )
return 0LL;
v2 = hash_function(a2, *a1);
v4 = *(const char **)(v3 + 8LL * v2 + 8);
if ( v4 && *(_QWORD *)v4 )
{
do
{
if ( !strcmp(v4 + 28, a2) )
break;
v4 = *(const char **)v4;
}
while ( v4 );
}
return v4;
}

canonical_decompiled_code:
const char *__fastcall func5(unsigned int *a1, char *a2)
{
unsigned int v2; // eax
__int64 v3; // r9
const char *v4; // r12

if ( !a1 || !a2 )
return 0LL;
v2 = func0(a2, *a1);
v4 = *(const char **)(v3 + 8LL * v2 + 8);
if ( v4 && *(_QWORD *)v4 )
{
do
{
if ( !strcmp(v4 + 28, a2) )
break;
v4 = *(const char **)v4;
}
while ( v4 );
}
return v4;
}

original_code:
struct hash_entry *
hash_lookup(struct hash *h, const char *key)
{
 struct hash_entry *entry = ((void *)0);
 unsigned int index;
 if (h && key) {
  index = hash_function(key, h->hash_size);
  entry = h->hash_table[index];
  if (entry) {
   if (!entry->next)
    goto no_collisions;
   do {
    if (!strcmp(entry->key, key))
     break;
   } while ((entry = entry->next));
  }
 }
no_collisions:
 return entry;
}

canonical_original_code:
struct hash_entry *hash_lookup(struct hash *h, char *key)
{
 struct hash_entry *entry = ((void *)0);
 unsigned int index;
 if (h && key) {
  index = hash_function(key, h->hash_size);
  entry = h->hash_table[index];
  if (entry) {
   if (!entry->next)
    goto no_collisions;
   do {
    if (!strcmp(entry->key, key))
     break;
   } while ((entry = entry->next));
  }
 }
no_collisions:
 return entry;
}

return_type: struct hash_entry { struct hash_entry *next; struct hash_entry *prev; long born_time; unsigned int index; char key[4096]; void *data; } *


decompiled_code:
__int64 hash_resize()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 0LL;
}

original_code:
int
hash_resize(struct hash *h, int size)
{
 return 0;
}

variable_types: size int


original_code:
int
hash_rehash(struct hash *h)
{
 if (h) {
  for (int i = 0; h->hash_table[i] != (hash_entry *) ((void *) 0x00100100) && h->hash_table[i]; i++) {
   struct hash_entry *tmp = h->hash_table[i];
   unsigned int index = hash_function(tmp->key, h->hash_size);
   do {
    if (tmp->index != index) {
     int ret;
     ret = hash_add(h, tmp->key, tmp->data);
     if (ret) {
      ret = hash_del_entry(h, tmp);
     }
    }
   } while (tmp->next);
  }
 }
 return 0;
}

canonical_original_code:
int hash_rehash(struct hash *h)
{
 if (h) {
  for (int i = 0; h->hash_table[i] != (struct hash_entry *) ((void *) 0x00100100) && h->hash_table[i]; i++) {
   struct hash_entry *tmp = h->hash_table[i];
   unsigned int index = hash_function(tmp->key, h->hash_size);
   do {
    if (tmp->index != index) {
     int ret;
     ret = hash_add(h, tmp->key, tmp->data);
     if (ret) {
      ret = hash_del_entry(h, tmp);
     }
    }
   } while (tmp->next);
  }
 }
 return 0;
}


decompiled_code:
int __fastcall hash_dump(__int64 a1)
{
_QWORD *v1; // rbx
__int64 v2; // rbp
int result; // eax

if ( a1 )
{
v1 = *(_QWORD **)(a1 + 8);
if ( v1 != (_QWORD *)1048832 )
{
v2 = 0LL;
do
{
if ( v1 )
{
fprintf(stdout, "%d ", (unsigned int)v2);
do
{
fputc(43, stdout);
v1 = (_QWORD *)*v1;
}
while ( v1 );
result = fputc(10, stdout);
}
else
{
result = fprintf(stdout, "%d -\n", (unsigned int)v2);
}
++v2;
v1 = *(_QWORD **)(a1 + 8 * v2 + 8);
}
while ( v1 != (_QWORD *)1048832 );
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
_QWORD *v1; // rbx
__int64 v2; // rbp
int result; // eax

if ( a1 )
{
v1 = *(_QWORD **)(a1 + 8);
if ( v1 != (_QWORD *)1048832 )
{
v2 = 0LL;
do
{
if ( v1 )
{
fprintf(stdout, "%d ", (unsigned int)v2);
do
{
fputc(43, stdout);
v1 = (_QWORD *)*v1;
}
while ( v1 );
result = fputc(10, stdout);
}
else
{
result = fprintf(stdout, "%d -\n", (unsigned int)v2);
}
++v2;
v1 = *(_QWORD **)(a1 + 8 * v2 + 8);
}
while ( v1 != (_QWORD *)1048832 );
}
}
return result;
}

original_code:
void
hash_dump(struct hash *h)
{
 struct hash_entry *n;
 int i;
 if (h) {
  for (i = 0; h->hash_table[i] != (hash_entry *) ((void *) 0x00100100); i++) {
   n = h->hash_table[i];
   if (n) {
    fprintf(stdout, "%d ", i);
    do {
     fprintf(stdout, "+");
    } while ((n = n->next));
    fprintf(stdout, "\n");
   } else {
    fprintf(stdout, "%d -\n", i);
   }
  }
 }
}

canonical_original_code:
void hash_dump(struct hash *h)
{
 struct hash_entry *n;
 int i;
 if (h) {
  for (i = 0; h->hash_table[i] != (struct hash_entry *) ((void *) 0x00100100); i++) {
   n = h->hash_table[i];
   if (n) {
    fprintf(stdout, "%d ", i);
    do {
     fprintf(stdout, "+");
    } while ((n = n->next));
    fprintf(stdout, "\n");
   } else {
    fprintf(stdout, "%d -\n", i);
   }
  }
 }
}


decompiled_code:
int __fastcall signal_handle(int a1)
{
return _set_signal_handler(a1, _signal_handler);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
return func1(a1, _signal_handler);
}

original_code:
void
signal_handle(int sig)
{
 __set_signal_handler(sig, __signal_handler);
}

variable_types: sig int


decompiled_code:
void __fastcall signal_clear(int a1)
{
_caught_signals[a1] = 0;
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
_caught_signals[a1] = 0;
}

original_code:
void
signal_clear(int sig)
{
 __caught_signals[sig] = 0;
}


decompiled_code:
int __fastcall signal_unhandle(int a1)
{
int v1; // er8

signal_clear(a1);
return _set_signal_handler(v1, 0LL);
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
int v1; // er8

func3(a1);
return func1(v1, 0LL);
}

original_code:
void
signal_unhandle(int sig)
{
 signal_clear(sig);
 __set_signal_handler(sig, ((__sighandler_t) 0));
}

canonical_original_code:
void signal_unhandle(int sig)
{
 signal_clear(sig);
 __set_signal_handler(sig, ((void (*)(int)) 0));
}


decompiled_code:
int __fastcall signal_ignore(int a1)
{
int v1; // er8

signal_clear(a1);
return _set_signal_handler(v1, (void (__fastcall *)(int))((char *)_signal_handler + 1));
}

canonical_decompiled_code:
int __fastcall func5(int a1)
{
int v1; // er8

func3(a1);
return func1(v1, (void (__fastcall *)(int))((char *)_signal_handler + 1));
}

original_code:
void
signal_ignore(int sig)
{
 signal_clear(sig);
 __set_signal_handler(sig, ((__sighandler_t) 1));
}

canonical_original_code:
void signal_ignore(int sig)
{
 signal_clear(sig);
 __set_signal_handler(sig, ((void (*)(int)) 1));
}


decompiled_code:
__int64 __fastcall signal_is_pending(int a1)
{
return (unsigned int)_caught_signals[a1];
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
return (unsigned int)_caught_signals[a1];
}

original_code:
int
signal_is_pending(int sig)
{
 return __caught_signals[sig];
}


decompiled_code:
int __fastcall build_list_line(const char *a1, __int64 a2, char *a3, int a4)
{
size_t v5; // rbp
__int64 v7; // [rsp+1h] [rbp-53h] BYREF
__int16 v8; // [rsp+9h] [rbp-4Bh]
char v9; // [rsp+Bh] [rbp-49h]
__int128 v10; // [rsp+Ch] [rbp-48h] BYREF
int v11; // [rsp+1Ch] [rbp-38h]

v5 = a4 - 1;
v11 = 0;
v7 = 0LL;
v8 = 0;
v9 = 0;
v10 = 0LL;
if ( !a2 )
return snprintf(a3, v5, "%s\r\n", a1);
get_perm_isra_0(*(_DWORD *)(a2 + 24), (__int64)&v7);
get_mtime_constprop_0_isra_0(*(_QWORD *)(a2 + 88), (char *)&v10);
return snprintf(
a3,
v5,
"%s%4u %-*u %-*u %*ld %s %s\r\n",
(const char *)&v7,
*(unsigned int *)(a2 + 16),
5,
*(unsigned int *)(a2 + 28),
5,
*(unsigned int *)(a2 + 32),
10,
*(_QWORD *)(a2 + 48),
(const char *)&v10,
a1);
}

original_code:
int
build_list_line(const char *name, struct stat *st, char *line, int l_size)
{
 char mtime[20] = {'\0'};
 char perm[11] = {'\0'};
 int ret = -1;
 if (st) {
  (void) get_perm(st->st_mode, perm);
  (void) get_mtime(st->st_mtim.tv_sec, mtime, sizeof(mtime));
  ret = snprintf(line, l_size - 1, "%s%4u %-*u  %-*u %*ld %s %s\r\n",
        perm, (unsigned int) st->st_nlink, 5, st->st_uid,
        5, st->st_gid, 10, st->st_size, mtime, name);
 } else {
  ret = snprintf(line, l_size - 1, "%s\r\n", name);
 }
 return ret;
}

canonical_original_code:
int build_list_line(char *name, struct stat *st, char *line, int l_size)
{
 char mtime[20] = {'\0'};
 char perm[11] = {'\0'};
 int ret = -1;
 if (st) {
  (void) get_perm(st->st_mode, perm);
  (void) get_mtime(st->st_mtim.tv_sec, mtime, sizeof(mtime));
  ret = snprintf(line, l_size - 1, "%s%4u %-*u  %-*u %*ld %s %s\r\n",
        perm, (unsigned int) st->st_nlink, 5, st->st_uid,
        5, st->st_gid, 10, st->st_size, mtime, name);
 } else {
  ret = snprintf(line, l_size - 1, "%s\r\n", name);
 }
 return ret;
}

variable_types:
name
char *

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:
line
char *

variable_types:
mtime
char [20]

variable_types:
perm
char [11]

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:
static int
do_queue_work(struct workqueue_struct *wq, struct work_struct *work)
{
 int rv = 0;
 if (work->flags != WORK_STRUCT_PENDING) {
  work->flags = WORK_STRUCT_PENDING;
  do { (((work))->entries.tqe_next) = ((void *)0); (work)->entries.tqe_prev = (&wq->list)->tqh_last; *(&wq->list)->tqh_last = (work); (&wq->list)->tqh_last = &(((work))->entries.tqe_next); } while (0);
  rv = 1;
 }
 return rv;
}

variable_types: struct workqueue_struct { unsigned long thread; char *name; 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; } cond; struct work_list { struct work_struct { void (*func)(struct work_struct *work); void *data; int flags; struct { struct work_struct *tqe_next; struct work_struct **tqe_prev; } entries; } *tqh_first; struct work_struct **tqh_last; } list; } *

variable_types:
work
struct work_struct *

variable_types: rv int

user_defined_types: struct workqueue_struct { unsigned long thread; char *name; union pthread_mutex_t mutex; union pthread_cond_t cond; struct work_list list; }

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

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

user_defined_types: struct work_list { struct work_struct *tqh_first; struct work_struct **tqh_last; }

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:
void __fastcall __noreturn worker_thread(void *a1)
{
__int64 v1; // rbx
__int64 v2; // rdx
_QWORD *v3; // rax

if ( !pthread_detach(*(_QWORD *)a1) )
{
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 16));
v1 = *((_QWORD *)a1 + 13);
if ( v1 )
break;
pthread_cond_wait((pthread_cond_t *)((char *)a1 + 56), (pthread_mutex_t *)((char *)a1 + 16));
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 16));
}
v2 = *(_QWORD *)(v1 + 24);
v3 = *(_QWORD **)(v1 + 32);
*(_DWORD *)(v1 + 16) = 2;
if ( v2 )
{
*(_QWORD *)(v2 + 32) = v3;
v3 = *(_QWORD **)(v1 + 32);
}
else
{
*((_QWORD *)a1 + 14) = v3;
}
*v3 = v2;
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 16));
(*(void (__fastcall **)(_QWORD))v1)(*(_QWORD *)(v1 + 8));
}
}
perror("pthread_detach error\n");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
__int64 v1; // rbx
__int64 v2; // rdx
_QWORD *v3; // rax

if ( !pthread_detach(*(_QWORD *)a1) )
{
while ( 1 )
{
while ( 1 )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 16));
v1 = *((_QWORD *)a1 + 13);
if ( v1 )
break;
pthread_cond_wait((pthread_cond_t *)((char *)a1 + 56), (pthread_mutex_t *)((char *)a1 + 16));
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 16));
}
v2 = *(_QWORD *)(v1 + 24);
v3 = *(_QWORD **)(v1 + 32);
*(_DWORD *)(v1 + 16) = 2;
if ( v2 )
{
*(_QWORD *)(v2 + 32) = v3;
v3 = *(_QWORD **)(v1 + 32);
}
else
{
*((_QWORD *)a1 + 14) = v3;
}
*v3 = v2;
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 16));
(*(void (__fastcall **)(_QWORD))v1)(*(_QWORD *)(v1 + 8));
}
}
perror("pthread_detach error\n");
exit(1);
}

original_code:
static void *
worker_thread(void *arg)
{
 struct workqueue_struct *wq;
 struct work_struct *work;
 int rv;
 wq = (struct workqueue_struct *) arg;
 rv = pthread_detach(wq->thread);
 if (rv)
  do { perror("pthread_detach error\n"); exit(1); } while (0);
 while (1) {
  pthread_mutex_lock(&wq->mutex);
  if (!((&wq->list)->tqh_first == ((void *)0))) {
   work = ((&wq->list)->tqh_first);
   work->flags = WORK_STRUCT_RUNNING;
   do { if (((((work))->entries.tqe_next)) != ((void *)0)) (((work))->entries.tqe_next)->entries.tqe_prev = (work)->entries.tqe_prev; else (&wq->list)->tqh_last = (work)->entries.tqe_prev; *(work)->entries.tqe_prev = (((work))->entries.tqe_next); } while (0);
  } else {
   pthread_cond_wait(&wq->cond, &wq->mutex);
  }
  pthread_mutex_unlock(&wq->mutex);
  if (work) {
   work->func(work->data);
   work = ((void *)0);
  }
 }
 return ((void *)0);
}

canonical_original_code:
static void *worker_thread(void *arg)
{
 struct workqueue_struct *wq;
 struct work_struct *work;
 int rv;
 wq = (struct workqueue_struct *) arg;
 rv = pthread_detach(wq->thread);
 if (rv)
  do { perror("pthread_detach error\n"); exit(1); } while (0);
 while (1) {
  pthread_mutex_lock(&wq->mutex);
  if (!((&wq->list)->tqh_first == ((void *)0))) {
   work = ((&wq->list)->tqh_first);
   work->flags = WORK_STRUCT_RUNNING;
   do { if (((((work))->entries.tqe_next)) != ((void *)0)) (((work))->entries.tqe_next)->entries.tqe_prev = (work)->entries.tqe_prev; else (&wq->list)->tqh_last = (work)->entries.tqe_prev; *(work)->entries.tqe_prev = (((work))->entries.tqe_next); } while (0);
  } else {
   pthread_cond_wait(&wq->cond, &wq->mutex);
  }
  pthread_mutex_unlock(&wq->mutex);
  if (work) {
   work->func(work->data);
   work = ((void *)0);
  }
 }
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct work_struct { void (*func)(struct work_struct *work); void *data; int flags; struct { struct work_struct *tqe_next; struct work_struct **tqe_prev; } entries; } *

return_type: void *

user_defined_types: 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]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall queue_work(__int64 a1, __int64 a2)
{
unsigned int v3; // er12

if ( !a1 || !a2 )
return 0LL;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
v3 = do_queue_work(a1, a2);
if ( v3 )
pthread_cond_signal((pthread_cond_t *)(a1 + 56));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 16));
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v3; // er12

if ( !a1 || !a2 )
return 0LL;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
v3 = func0(a1, a2);
if ( v3 )
pthread_cond_signal((pthread_cond_t *)(a1 + 56));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 16));
return v3;
}

original_code:
int queue_work(struct workqueue_struct *wq, struct work_struct *work)
{
 int ret = 0;
 if (wq && work) {
  pthread_mutex_lock(&wq->mutex);
  ret = do_queue_work(wq, work);
  if (ret)
   pthread_cond_signal(&wq->cond);
  pthread_mutex_unlock(&wq->mutex);
 }
 return ret;
}

user_defined_types: struct work_struct { void (*func)(struct work_struct *work); void *data; int flags; struct { struct work_struct *tqe_next; struct work_struct **tqe_prev; } entries; }


decompiled_code:
int __fastcall set_euid(__uid_t a1)
{
int result; // eax
int *v2; // rbp
char *v3; // rax

result = seteuid(a1);
if ( result < 0 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stdout, "%s:%d: seteuid [%d] failed with errno %u: %s\n", "src/utils.c", 22LL, a1, (unsigned int)*v2, v3);
result = fflush(stdout);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__uid_t a1)
{
int result; // eax
int *v2; // rbp
char *v3; // rax

result = seteuid(a1);
if ( result < 0 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stdout, "%s:%d: seteuid [%d] failed with errno %u: %s\n", "src/utils.c", 22LL, a1, (unsigned int)*v2, v3);
result = fflush(stdout);
}
return result;
}

original_code:
void
set_euid(uid_t euid)
{
 do { } while(0);
 if (seteuid(euid) < 0)
  do { fprintf(stdout, "%s:%d: " "seteuid [%d] failed with errno %u: %s\n", "src/utils.c", 22, euid, (*__errno_location ()), strerror((*__errno_location ()))); fflush(stdout); } while (0);
 do { } while(0);
}

canonical_original_code:
void set_euid(unsigned int euid)
{
 do { } while(0);
 if (seteuid(euid) < 0)
  do { fprintf(stdout, "%s:%d: " "seteuid [%d] failed with errno %u: %s\n", "src/utils.c", 22, euid, (*__errno_location ()), strerror((*__errno_location ()))); fflush(stdout); } while (0);
 do { } while(0);
}

variable_types:
euid
unsigned int


decompiled_code:
int reset_euid()
{
int result; // eax
int *v1; // rbx
char *v2; // rax

result = seteuid(0);
if ( result < 0 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stdout, "%s:%d: seteuid failed with errno %d: %s\n", "src/utils.c", 34LL, (unsigned int)*v1, v2);
result = fflush(stdout);
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
int *v1; // rbx
char *v2; // rax

result = seteuid(0);
if ( result < 0 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stdout, "%s:%d: seteuid failed with errno %d: %s\n", "src/utils.c", 34LL, (unsigned int)*v1, v2);
result = fflush(stdout);
}
return result;
}

original_code:
void
reset_euid(void)
{
 do { } while(0);
 if (seteuid(0) < 0)
  do { fprintf(stdout, "%s:%d: " "seteuid failed with errno %d: %s\n", "src/utils.c", 34, (*__errno_location ()), strerror((*__errno_location ()))); fflush(stdout); } while (0);
 do { } while(0);
}

canonical_original_code:
void reset_euid()
{
 do { } while(0);
 if (seteuid(0) < 0)
  do { fprintf(stdout, "%s:%d: " "seteuid failed with errno %d: %s\n", "src/utils.c", 34, (*__errno_location ()), strerror((*__errno_location ()))); fflush(stdout); } while (0);
 do { } while(0);
}


decompiled_code:
int __fastcall set_egid(__gid_t a1)
{
int result; // eax
int *v2; // rbp
char *v3; // rax

result = setegid(a1);
if ( result < 0 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stdout, "%s:%d: setegid [%d] failed with errno %u: %s\n", "src/utils.c", 46LL, a1, (unsigned int)*v2, v3);
result = fflush(stdout);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__gid_t a1)
{
int result; // eax
int *v2; // rbp
char *v3; // rax

result = setegid(a1);
if ( result < 0 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stdout, "%s:%d: setegid [%d] failed with errno %u: %s\n", "src/utils.c", 46LL, a1, (unsigned int)*v2, v3);
result = fflush(stdout);
}
return result;
}

original_code:
void
set_egid(gid_t egid)
{
 do { } while(0);
 if (setegid(egid) < 0)
  do { fprintf(stdout, "%s:%d: " "setegid [%d] failed with errno %u: %s\n", "src/utils.c", 46, egid, (*__errno_location ()), strerror((*__errno_location ()))); fflush(stdout); } while (0);
 do { } while(0);
}

canonical_original_code:
void set_egid(unsigned int egid)
{
 do { } while(0);
 if (setegid(egid) < 0)
  do { fprintf(stdout, "%s:%d: " "setegid [%d] failed with errno %u: %s\n", "src/utils.c", 46, egid, (*__errno_location ()), strerror((*__errno_location ()))); fflush(stdout); } while (0);
 do { } while(0);
}

variable_types:
egid
unsigned int


decompiled_code:
int reset_egid()
{
int result; // eax
int *v1; // rbx
char *v2; // rax

result = setegid(0);
if ( result < 0 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stdout, "%s:%d: setegid failed with errno %d: %s\n", "src/utils.c", 58LL, (unsigned int)*v1, v2);
result = fflush(stdout);
}
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax
int *v1; // rbx
char *v2; // rax

result = setegid(0);
if ( result < 0 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stdout, "%s:%d: setegid failed with errno %d: %s\n", "src/utils.c", 58LL, (unsigned int)*v1, v2);
result = fflush(stdout);
}
return result;
}

original_code:
void
reset_egid(void)
{
 do { } while(0);
 if (setegid(0) < 0)
  do { fprintf(stdout, "%s:%d: " "setegid failed with errno %d: %s\n", "src/utils.c", 58, (*__errno_location ()), strerror((*__errno_location ()))); fflush(stdout); } while (0);
 do { } while(0);
}

canonical_original_code:
void reset_egid()
{
 do { } while(0);
 if (setegid(0) < 0)
  do { fprintf(stdout, "%s:%d: " "setegid failed with errno %d: %s\n", "src/utils.c", 58, (*__errno_location ()), strerror((*__errno_location ()))); fflush(stdout); } while (0);
 do { } while(0);
}


repo: usaco/Pandemoonium

decompiled_code:
void socket_setup()
{
struct addrinfo *v0; // rbx
struct addrinfo *pai; // [rsp+0h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-38h] BYREF

if ( !socket_ready )
{
socket_ready = 1;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
req.ai_flags = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(0LL, "1337", &req, &pai) )
{
fwrite("getaddrinfo failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
v0 = pai;
if ( !pai )
LABEL_8:
exit(1);
while ( 1 )
{
sockfd = socket(v0->ai_family, v0->ai_socktype, v0->ai_protocol);
if ( sockfd != -1 )
{
if ( !bind(sockfd, v0->ai_addr, v0->ai_addrlen) )
{
freeaddrinfo(pai);
listen(sockfd, 8);
return;
}
close(sockfd);
}
v0 = v0->ai_next;
if ( !v0 )
goto LABEL_8;
}
}
}

canonical_decompiled_code:
void func0()
{
struct addrinfo *v0; // rbx
struct addrinfo *pai; // [rsp+0h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-38h] BYREF

if ( !socket_ready )
{
socket_ready = 1;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
req.ai_flags = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(0LL, "1337", &req, &pai) )
{
fwrite("getaddrinfo failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
v0 = pai;
if ( !pai )
LABEL_8:
exit(1);
while ( 1 )
{
sockfd = socket(v0->ai_family, v0->ai_socktype, v0->ai_protocol);
if ( sockfd != -1 )
{
if ( !bind(sockfd, v0->ai_addr, v0->ai_addrlen) )
{
freeaddrinfo(pai);
listen(sockfd, 8);
return;
}
close(sockfd);
}
v0 = v0->ai_next;
if ( !v0 )
goto LABEL_8;
}
}
}

original_code:
void socket_setup()
{
 if (socket_ready) return;
 socket_ready = 1u;
 struct addrinfo hints;
 struct addrinfo *result, *rp;
 memset(&hints, 0, sizeof hints);
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_flags = 0x0001;
 hints.ai_protocol = 0;
 hints.ai_addr = ((void *)0);
 hints.ai_next = ((void *)0);
 if (getaddrinfo(((void *)0), "1337", &hints, &result))
 { fprintf(stderr, "getaddrinfo failed\n"); exit(1); }
 for (rp = result; rp; rp = rp->ai_next)
 {
  sockfd = socket(rp->ai_family,
   rp->ai_socktype, rp->ai_protocol);
  if (sockfd == -1) continue;
  if (bind(sockfd, rp->ai_addr,
   rp->ai_addrlen) == 0) break;
  close(sockfd);
 }
 if (!rp) exit(1);
 freeaddrinfo(result);
 listen(sockfd, 8);
}

canonical_original_code:
void socket_setup()
{
 if (socket_ready) return;
 socket_ready = 1u;
 struct addrinfo hints;
 struct addrinfo *result; struct addrinfo *rp;
 memset(&hints, 0, sizeof hints);
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_flags = 0x0001;
 hints.ai_protocol = 0;
 hints.ai_addr = ((void *)0);
 hints.ai_next = ((void *)0);
 if (getaddrinfo(((void *)0), "1337", &hints, &result))
 { fprintf(stderr, "getaddrinfo failed\n"); exit(1); }
 for (rp = result; rp; rp = rp->ai_next)
 {
  sockfd = socket(rp->ai_family,
   rp->ai_socktype, rp->ai_protocol);
  if (sockfd == -1) continue;
  if (bind(sockfd, rp->ai_addr,
   rp->ai_addrlen) == 0) break;
  close(sockfd);
 }
 if (!rp) exit(1);
 freeaddrinfo(result);
 listen(sockfd, 8);
}

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; } *


decompiled_code:
int __fastcall setup_agent(unsigned int a1, _DWORD *a2, char *a3)
{
int v4; // edi
int result; // eax
char *v7; // rdi
__int64 v8; // rbx
__int64 v9; // r12
__pid_t v10; // eax
const char *v11; // rdi
int *v12; // rbx
char *v13; // rax
FILE *v14; // rdi
int v15; // [rsp+0h] [rbp-358h] BYREF
int fd; // [rsp+4h] [rbp-354h]
socklen_t addr_len[2]; // [rsp+8h] [rbp-350h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-348h] BYREF

if ( !strcmp(a3, "HUMAN") )
{
socket_setup();
v4 = sockfd;
a2[66] = -1;
addr_len[0] = 16;
result = accept(v4, &addr, addr_len);
if ( result >= 0 )
{
a2[66] = 0;
a2[68] = result;
a2[67] = result;
a2[70] = 30000;
}
}
else
{
a2[70] = 500;
v7 = strtok(a3, " ");
if ( v7 )
{
v8 = 1LL;
do
{
v9 = (int)v8;
*(_QWORD *)&addr_len[2 * v8++] = strdup(v7);
v7 = strtok(0LL, " ");
}
while ( v7 );
}
else
{
v9 = 0LL;
}
*((_QWORD *)&addr.sa_family + v9) = 0LL;
if ( pipe(&v15) || pipe((int *)addr_len) )
{
fprintf(stderr, "Couldn't set up communication for bot%d\n", a1 + 1);
exit(1);
}
v10 = fork();
if ( v10 == -1 )
{
v14 = stderr;
a2[66] = -1;
fprintf(v14, "Could not fork process to run bot%d: '%s'\n", a1 + 1, a3);
exit(1);
}
if ( !v10 )
{
close(addr_len[1]);
close(v15);
if ( dup2(addr_len[0], 0) )
fprintf(stderr, "Could not replace stdin on bot%d\n", a1 + 1);
if ( dup2(fd, 1) != 1 )
fprintf(stderr, "Could not replace stdout on bot%d\n", a1 + 1);
close(addr_len[0]);
close(fd);
v11 = *(const char **)&addr.sa_family;
a2[66] = 0;
execvp(v11, (char *const *)&addr);
a2[66] = -1;
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(stderr, "Could not exec bot%d: [%d] %s\n", a1, (unsigned int)*v12, v13);
exit(1);
}
a2[69] = v10;
close(addr_len[0]);
close(fd);
a2[67] = v15;
result = addr_len[1];
a2[68] = addr_len[1];
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, _DWORD *a2, char *a3)
{
int v4; // edi
int result; // eax
char *v7; // rdi
__int64 v8; // rbx
__int64 v9; // r12
__pid_t v10; // eax
const char *v11; // rdi
int *v12; // rbx
char *v13; // rax
FILE *v14; // rdi
int v15; // [rsp+0h] [rbp-358h] BYREF
int fd; // [rsp+4h] [rbp-354h]
socklen_t addr_len[2]; // [rsp+8h] [rbp-350h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-348h] BYREF

if ( !strcmp(a3, "HUMAN") )
{
func0();
v4 = sockfd;
a2[66] = -1;
addr_len[0] = 16;
result = accept(v4, &addr, addr_len);
if ( result >= 0 )
{
a2[66] = 0;
a2[68] = result;
a2[67] = result;
a2[70] = 30000;
}
}
else
{
a2[70] = 500;
v7 = strtok(a3, " ");
if ( v7 )
{
v8 = 1LL;
do
{
v9 = (int)v8;
*(_QWORD *)&addr_len[2 * v8++] = strdup(v7);
v7 = strtok(0LL, " ");
}
while ( v7 );
}
else
{
v9 = 0LL;
}
*((_QWORD *)&addr.sa_family + v9) = 0LL;
if ( pipe(&v15) || pipe((int *)addr_len) )
{
fprintf(stderr, "Couldn't set up communication for bot%d\n", a1 + 1);
exit(1);
}
v10 = fork();
if ( v10 == -1 )
{
v14 = stderr;
a2[66] = -1;
fprintf(v14, "Could not fork process to run bot%d: '%s'\n", a1 + 1, a3);
exit(1);
}
if ( !v10 )
{
close(addr_len[1]);
close(v15);
if ( dup2(addr_len[0], 0) )
fprintf(stderr, "Could not replace stdin on bot%d\n", a1 + 1);
if ( dup2(fd, 1) != 1 )
fprintf(stderr, "Could not replace stdout on bot%d\n", a1 + 1);
close(addr_len[0]);
close(fd);
v11 = *(const char **)&addr.sa_family;
a2[66] = 0;
execvp(v11, (char *const *)&addr);
a2[66] = -1;
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(stderr, "Could not exec bot%d: [%d] %s\n", a1, (unsigned int)*v12, v13);
exit(1);
}
a2[69] = v10;
close(addr_len[0]);
close(fd);
a2[67] = v15;
result = addr_len[1];
a2[68] = addr_len[1];
}
return result;
}

original_code:
void setup_agent(int bot, struct agent_t* agent, char* filename)
{
 if (!strcmp(filename, "HUMAN"))
 {
  socket_setup();
  socklen_t clen;
  struct sockaddr_in cli_addr;
  int nsockfd;
  agent->status = -1;
  clen = sizeof cli_addr;
  if (0) fprintf(stderr, "Accepting connections"
    " for bot #%d\n", bot+1);
  nsockfd = accept(sockfd,
    (struct sockaddr *) &cli_addr, &clen);
  if (nsockfd < 0) return;
  if (0) fprintf(stderr, "...bot #%d connected"
    " successfully!\n", bot+1);
  agent->status = 0;
  agent->fds[0] = agent->fds[1] = nsockfd;
  agent->timeout = 30000;
  return;
 }
 else
 {
  int i, pid, c2p[2], p2c[2];
  agent->timeout = 500;
  char *p, *arglist[100];
  for (i = 0, p = strtok(filename, " "); p;
   ++i, p = strtok(((void *)0), " ")) arglist[i] = strdup(p);
  arglist[i] = ((void *)0);
  if (pipe(c2p) || pipe(p2c))
  {
   fprintf(stderr, "Couldn't set up communication for bot%d\n", bot+1);
   exit(1);
  }
  switch (pid = fork())
  {
  case -1:
   agent->status = -1;
   fprintf(stderr, "Could not fork process to run bot%d: '%s'\n", bot+1, filename);
   exit(1);
  case 0:
   close(p2c[1]); close(c2p[0]);
   if (0 != dup2(p2c[0], 0))
    fprintf(stderr, "Could not replace stdin on bot%d\n", bot+1);
   if (1 != dup2(c2p[1], 1))
    fprintf(stderr, "Could not replace stdout on bot%d\n", bot+1);
   close(p2c[0]); close(c2p[1]);
   agent->status = 0;
   execvp(arglist[0], arglist);
   agent->status = -1;
   fprintf(stderr, "Could not exec bot%d: [%d] %s\n",
    bot, (*__errno_location ()), strerror((*__errno_location ())));
   exit(1);
   break;
  default:
   agent->pid = pid;
   close(p2c[0]); close(c2p[1]);
   agent->fds[0 ] = c2p[0 ];
   agent->fds[1] = p2c[1];
   return;
  }
 }
}

canonical_original_code:
void setup_agent(int bot, struct agent_t *agent, char *filename)
{
 if (!strcmp(filename, "HUMAN"))
 {
  socket_setup();
  unsigned int clen;
  struct sockaddr_in cli_addr;
  int nsockfd;
  agent->status = -1;
  clen = sizeof cli_addr;
  if (0) fprintf(stderr, "Accepting connections"
    " for bot #%d\n", bot+1);
  nsockfd = accept(sockfd,
    (struct sockaddr *) &cli_addr, &clen);
  if (nsockfd < 0) return;
  if (0) fprintf(stderr, "...bot #%d connected"
    " successfully!\n", bot+1);
  agent->status = 0;
  agent->fds[0] = agent->fds[1] = nsockfd;
  agent->timeout = 30000;
  return;
 }
 else
 {
  int i; int pid; int c2p[2]; int p2c[2];
  agent->timeout = 500;
  char *p; char *arglist[100];
  for (i = 0, p = strtok(filename, " "); p;
   ++i, p = strtok(((void *)0), " ")) arglist[i] = strdup(p);
  arglist[i] = ((void *)0);
  if (pipe(c2p) || pipe(p2c))
  {
   fprintf(stderr, "Couldn't set up communication for bot%d\n", bot+1);
   exit(1);
  }
  switch (pid = fork())
  {
  case -1:
   agent->status = -1;
   fprintf(stderr, "Could not fork process to run bot%d: '%s'\n", bot+1, filename);
   exit(1);
  case 0:
   close(p2c[1]); close(c2p[0]);
   if (0 != dup2(p2c[0], 0))
    fprintf(stderr, "Could not replace stdin on bot%d\n", bot+1);
   if (1 != dup2(c2p[1], 1))
    fprintf(stderr, "Could not replace stdout on bot%d\n", bot+1);
   close(p2c[0]); close(c2p[1]);
   agent->status = 0;
   execvp(arglist[0], arglist);
   agent->status = -1;
   fprintf(stderr, "Could not exec bot%d: [%d] %s\n",
    bot, (*__errno_location ()), strerror((*__errno_location ())));
   exit(1);
   break;
  default:
   agent->pid = pid;
   close(p2c[0]); close(c2p[1]);
   agent->fds[0 ] = c2p[0 ];
   agent->fds[1] = p2c[1];
   return;
  }
 }
}

variable_types: bot int

variable_types: struct agent_t { char name[256]; unsigned int milk; unsigned int loc; int status; int fds[2]; int pid; int timeout; void *vis; } *

variable_types:
filename
char *

variable_types:
clen
unsigned 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: nsockfd int

variable_types: i int

variable_types: pid int

variable_types:
p
char *

variable_types:
arglist
char *[100]

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 sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall listen_bot(void *buf, int a2)
{
char *v2; // rbx
unsigned __int64 v3; // rdi
char *v4; // r12
__int64 result; // rax
int v6; // ebp

v2 = (char *)buf;
v3 = (unsigned __int64)buf + 8;
*(_QWORD *)(v3 - 8) = 0LL;
*(_QWORD *)(v3 + 112) = 0LL;
memset((void *)(v3 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)v2 - (v3 & 0xFFFFFFF8) + 128) >> 3));
v4 = &agents[296 * a2];
result = *((unsigned int *)v4 + 66);
if ( !(_DWORD)result )
{
v6 = 128;
do
{
LODWORD(result) = read(*((_DWORD *)v4 + 67), v2, v6);
v6 -= result;
result = (int)result;
v2 += (int)result;
}
while ( v6 > 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *buf, int a2)
{
char *v2; // rbx
unsigned __int64 v3; // rdi
char *v4; // r12
__int64 result; // rax
int v6; // ebp

v2 = (char *)buf;
v3 = (unsigned __int64)buf + 8;
*(_QWORD *)(v3 - 8) = 0LL;
*(_QWORD *)(v3 + 112) = 0LL;
memset((void *)(v3 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)v2 - (v3 & 0xFFFFFFF8) + 128) >> 3));
v4 = &agents[296 * a2];
result = *((unsigned int *)v4 + 66);
if ( !(_DWORD)result )
{
v6 = 128;
do
{
LODWORD(result) = read(*((_DWORD *)v4 + 67), v2, v6);
v6 -= result;
result = (int)result;
v2 += (int)result;
}
while ( v6 > 0 );
}
return result;
}

original_code:
void listen_bot(char* msg, int bot)
{
 bzero(msg, 128);
 if (agents[bot].status != 0) return;
 int br, bl; char* m = msg;
 for (bl = 128; bl > 0; bl -= br, m += br)
  br = read(agents[bot].fds[0], m, bl);
 if (0) fprintf(stderr, "==> RECV [%d]: (%d) %s\n", bot, br, msg);
}

canonical_original_code:
void listen_bot(char *msg, int bot)
{
 bzero(msg, 128);
 if (agents[bot].status != 0) return;
 int br; int bl; char *m = msg;
 for (bl = 128; bl > 0; bl -= br, m += br)
  br = read(agents[bot].fds[0], m, bl);
 if (0) fprintf(stderr, "==> RECV [%d]: (%d) %s\n", bot, br, msg);
}

variable_types:
msg
char *

variable_types: br int

variable_types: bl int

variable_types:
m
char *


decompiled_code:
__int64 __fastcall listen_bot_timeout(void *buf, int a2, int a3)
{
char *v3; // rbx
__int64 result; // rax
int v6; // edi
struct timeval v7; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

v3 = &agents[296 * a2];
result = *((unsigned int *)v3 + 66);
if ( !(_DWORD)result )
{
memset(&readfds, 0, sizeof(readfds));
v6 = *((_DWORD *)v3 + 67);
v7.tv_sec = 0LL;
readfds.fds_bits[v6 / 64] |= 1LL << (v6 % 64);
v7.tv_usec = (unsigned int)(1000 * a3);
if ( select(v6 + 1, &readfds, 0LL, 0LL, &v7) <= 0 )
*((_DWORD *)v3 + 66) = -1;
result = listen_bot(buf, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *buf, int a2, int a3)
{
char *v3; // rbx
__int64 result; // rax
int v6; // edi
struct timeval v7; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

v3 = &agents[296 * a2];
result = *((unsigned int *)v3 + 66);
if ( !(_DWORD)result )
{
memset(&readfds, 0, sizeof(readfds));
v6 = *((_DWORD *)v3 + 67);
v7.tv_sec = 0LL;
readfds.fds_bits[v6 / 64] |= 1LL << (v6 % 64);
v7.tv_usec = (unsigned int)(1000 * a3);
if ( select(v6 + 1, &readfds, 0LL, 0LL, &v7) <= 0 )
*((_DWORD *)v3 + 66) = -1;
result = func2(buf, a2);
}
return result;
}

original_code:
void listen_bot_timeout(char* msg, int bot, int milliseconds)
{
 fd_set rfds;
 struct timeval tv;
 int retval;
 if (agents[bot].status != 0) return;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rfds)->__fds_bits)[((agents[bot].fds[0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((agents[bot].fds[0]) % (8 * (int) sizeof (__fd_mask)))))));
 tv.tv_sec = 0;
 tv.tv_usec = milliseconds * 1000u;
 retval = select(1+agents[bot].fds[0],
  &rfds, ((void *)0), ((void *)0), &tv);
 if (retval < 1) agents[bot].status = -1;
 listen_bot(msg, bot);
}

canonical_original_code:
void listen_bot_timeout(char *msg, int bot, int milliseconds)
{
 struct fd_set rfds;
 struct timeval tv;
 int retval;
 if (agents[bot].status != 0) return;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rfds)->__fds_bits)[((agents[bot].fds[0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((agents[bot].fds[0]) % (8 * (int) sizeof (__fd_mask)))))));
 tv.tv_sec = 0;
 tv.tv_usec = milliseconds * 1000u;
 retval = select(1+agents[bot].fds[0],
  &rfds, ((void *)0), ((void *)0), &tv);
 if (retval < 1) agents[bot].status = -1;
 listen_bot(msg, bot);
}

variable_types: milliseconds int

variable_types:
rfds
struct fd_set { long __fds_bits[-1]; }

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: retval int


decompiled_code:
__int64 __fastcall tell_bot(void *buf, int a2)
{
int v3; // ebx
__int64 result; // rax

v3 = 128;
do
{
LODWORD(result) = write(*(_DWORD *)&agents[296 * a2 + 272], buf, v3);
v3 -= result;
result = (int)result;
buf = (char *)buf + (int)result;
}
while ( v3 > 0 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *buf, int a2)
{
int v3; // ebx
__int64 result; // rax

v3 = 128;
do
{
LODWORD(result) = write(*(_DWORD *)&agents[296 * a2 + 272], buf, v3);
v3 -= result;
result = (int)result;
buf = (char *)buf + (int)result;
}
while ( v3 > 0 );
return result;
}

original_code:
void tell_bot(char* msg, int bot)
{
 int br, bl; char* m = msg;
 for (bl = 128; bl > 0; bl -= br, m += br)
  br = write(agents[bot].fds[1], m, bl);
 if (0) fprintf(stderr, "<-- SEND [%d]: (%d) %s\n", bot, br, msg);
}

canonical_original_code:
void tell_bot(char *msg, int bot)
{
 int br; int bl; char *m = msg;
 for (bl = 128; bl > 0; bl -= br, m += br)
  br = write(agents[bot].fds[1], m, bl);
 if (0) fprintf(stderr, "<-- SEND [%d]: (%d) %s\n", bot, br, msg);
}

variable_types: bot int


decompiled_code:
__int64 __fastcall tell_all(void *buf, int a2)
{
__int64 result; // rax
unsigned int v3; // ebx

result = (unsigned int)NUMAGENTS;
if ( NUMAGENTS )
{
v3 = 0;
do
{
if ( a2 != v3 )
result = tell_bot(buf, v3);
++v3;
}
while ( NUMAGENTS > v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *buf, int a2)
{
__int64 result; // rax
unsigned int v3; // ebx

result = (unsigned int)NUMAGENTS;
if ( NUMAGENTS )
{
v3 = 0;
do
{
if ( a2 != v3 )
result = func4(buf, v3);
++v3;
}
while ( NUMAGENTS > v3 );
}
return result;
}

original_code:
void tell_all(char* msg, int exclude)
{
 unsigned int i;
 for (i = 0; i < NUMAGENTS; ++i)
  if (i != exclude) tell_bot(msg, i);
}

canonical_original_code:
void tell_all(char *msg, int exclude)
{
 unsigned int i;
 for (i = 0; i < NUMAGENTS; ++i)
  if (i != exclude) tell_bot(msg, i);
}

variable_types: exclude int

variable_types:
i
unsigned int


decompiled_code:
__int64 setup_game()
{
unsigned int v0; // ebp
char *v1; // rax
__int64 v2; // rbx
const unsigned __int16 **v3; // rax
char *v4; // rdx
const unsigned __int16 *v5; // rax
__int64 v6; // rax
unsigned int v7; // edi
char *v8; // rbp
unsigned int v9; // ebx
int v10; // esi
__int64 v11; // rdx
__int64 v12; // rbx
__int64 v13; // rcx
__int64 v14; // rdx
char v16[5]; // [rsp+0h] [rbp-98h] BYREF
char src[147]; // [rsp+5h] [rbp-93h] BYREF

v0 = 0;
fgets(v16, 128, gamedata);
if ( !NUMAGENTS )
goto LABEL_16;
do
{
fgets(v16, 128, gamedata);
v1 = strchr(v16, 10);
if ( v1 )
*v1 = 0;
v2 = v16[0];
if ( v16[0] )
{
v3 = _ctype_b_loc();
v4 = v16;
v5 = *v3;
do
{
if ( (v5[v2] & 0x2000) == 0 )
break;
v2 = *++v4;
}
while ( (_BYTE)v2 );
}
else
{
v4 = v16;
}
v6 = v0;
v7 = v0++;
setup_agent(v7, &agents[296 * v6], v4);
}
while ( NUMAGENTS > v0 );
if ( NUMAGENTS )
{
v8 = agents;
v9 = 0;
do
{
sprintf(v16, "INIT %u", v9);
tell_bot(v16, v9);
v10 = v9++;
listen_bot_timeout(v16, v10, *((_DWORD *)v8 + 70));
strncpy(v8, src, 0xFFuLL);
v11 = (unsigned int)NUMAGENTS;
v8[255] = 0;
v8 += 296;
}
while ( (unsigned int)v11 > v9 );
}
else
{
LABEL_16:
v11 = 0LL;
}
v12 = 0LL;
sprintf(v16, "PLAYERS %u", v11);
tell_all(v16, -1);
sprintf(v16, "COWS %u", (unsigned int)NUMCOWS);
tell_all(v16, -1);
if ( NUMCOWS )
{
do
{
v13 = (unsigned int)MILKVALUES[v12];
v14 = (unsigned int)v12++;
sprintf(v16, "COW %d %d", v14, v13);
tell_all(v16, -1);
}
while ( NUMCOWS > (unsigned int)v12 );
}
sprintf(v16, "ROUNDS %u", (unsigned int)NUMROUNDS);
return tell_all(v16, -1);
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // ebp
char *v1; // rax
__int64 v2; // rbx
const unsigned __int16 **v3; // rax
char *v4; // rdx
const unsigned __int16 *v5; // rax
__int64 v6; // rax
unsigned int v7; // edi
char *v8; // rbp
unsigned int v9; // ebx
int v10; // esi
__int64 v11; // rdx
__int64 v12; // rbx
__int64 v13; // rcx
__int64 v14; // rdx
char v16[5]; // [rsp+0h] [rbp-98h] BYREF
char src[147]; // [rsp+5h] [rbp-93h] BYREF

v0 = 0;
fgets(v16, 128, gamedata);
if ( !NUMAGENTS )
goto LABEL_16;
do
{
fgets(v16, 128, gamedata);
v1 = strchr(v16, 10);
if ( v1 )
*v1 = 0;
v2 = v16[0];
if ( v16[0] )
{
v3 = _ctype_b_loc();
v4 = v16;
v5 = *v3;
do
{
if ( (v5[v2] & 0x2000) == 0 )
break;
v2 = *++v4;
}
while ( (_BYTE)v2 );
}
else
{
v4 = v16;
}
v6 = v0;
v7 = v0++;
func1(v7, &agents[296 * v6], v4);
}
while ( NUMAGENTS > v0 );
if ( NUMAGENTS )
{
v8 = agents;
v9 = 0;
do
{
sprintf(v16, "INIT %u", v9);
func4(v16, v9);
v10 = v9++;
func3(v16, v10, *((_DWORD *)v8 + 70));
strncpy(v8, src, 0xFFuLL);
v11 = (unsigned int)NUMAGENTS;
v8[255] = 0;
v8 += 296;
}
while ( (unsigned int)v11 > v9 );
}
else
{
LABEL_16:
v11 = 0LL;
}
v12 = 0LL;
sprintf(v16, "PLAYERS %u", v11);
func5(v16, -1);
sprintf(v16, "COWS %u", (unsigned int)NUMCOWS);
func5(v16, -1);
if ( NUMCOWS )
{
do
{
v13 = (unsigned int)MILKVALUES[v12];
v14 = (unsigned int)v12++;
sprintf(v16, "COW %d %d", v14, v13);
func5(v16, -1);
}
while ( NUMCOWS > (unsigned int)v12 );
}
sprintf(v16, "ROUNDS %u", (unsigned int)NUMROUNDS);
return func5(v16, -1);
}

original_code:
void setup_game()
{
 unsigned int i; char msg[128];
 fgets(msg, 128, gamedata);
 for (i = 0; i < NUMAGENTS; ++i)
 {
  fgets(msg, 128, gamedata);
  char *p = strchr(msg, '\n');
  if (p) *p = 0;
  for (p = msg; *p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISspace); ++p);
  setup_agent(i, &agents[i], p);
 }
 for (i = 0; i < NUMAGENTS; ++i)
 {
  sprintf(msg, "INIT %u", i); tell_bot(msg, i);
  listen_bot_timeout(msg, i, agents[i].timeout);
  strncpy(agents[i].name, msg + 5, 255);
  agents[i].name[255] = 0;
 }
 sprintf(msg, "PLAYERS %u", NUMAGENTS);
 tell_all(msg, -1);
 sprintf(msg, "COWS %u", NUMCOWS);
 tell_all(msg, -1);
 for (i = 0; i < NUMCOWS; ++i)
 {
  sprintf(msg, "COW %d %d", i, MILKVALUES[i]);
  tell_all(msg, -1);
 }
 sprintf(msg, "ROUNDS %u", NUMROUNDS);
 tell_all(msg, -1);
}

canonical_original_code:
void setup_game()
{
 unsigned int i; char msg[128];
 fgets(msg, 128, gamedata);
 for (i = 0; i < NUMAGENTS; ++i)
 {
  fgets(msg, 128, gamedata);
  char *p = strchr(msg, '\n');
  if (p) *p = 0;
  for (p = msg; *p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISspace); ++p);
  setup_agent(i, &agents[i], p);
 }
 for (i = 0; i < NUMAGENTS; ++i)
 {
  sprintf(msg, "INIT %u", i); tell_bot(msg, i);
  listen_bot_timeout(msg, i, agents[i].timeout);
  strncpy(agents[i].name, msg + 5, 255);
  agents[i].name[255] = 0;
 }
 sprintf(msg, "PLAYERS %u", NUMAGENTS);
 tell_all(msg, -1);
 sprintf(msg, "COWS %u", NUMCOWS);
 tell_all(msg, -1);
 for (i = 0; i < NUMCOWS; ++i)
 {
  sprintf(msg, "COW %d %d", i, MILKVALUES[i]);
  tell_all(msg, -1);
 }
 sprintf(msg, "ROUNDS %u", NUMROUNDS);
 tell_all(msg, -1);
}

variable_types:
msg
char [128]


decompiled_code:
__int64 play_game()
{
unsigned int i; // er12
unsigned int v1; // ebp
unsigned int *v2; // rbx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // rdx
unsigned int *v6; // rbx
unsigned int v7; // ebp
__int64 v8; // rdi
unsigned int v9; // edx
char *v10; // rcx
__int64 v11; // rdx
char v13[128]; // [rsp+0h] [rbp-168h] BYREF
__int16 s[116]; // [rsp+80h] [rbp-E8h] BYREF

for ( i = 0; NUMROUNDS > i; ++i )
{
sprintf(v13, "ROUND %u", i);
v1 = 0;
tell_all(v13, -1);
v2 = (unsigned int *)agents;
if ( NUMAGENTS )
{
do
{
if ( v2[66] )
{
v2[65] = -1;
v3 = 0xFFFFFFFFLL;
}
else
{
v3 = v2[65];
}
v4 = v2[64];
v5 = v1;
v2 += 74;
++v1;
sprintf(v13, "PLAYER %u %u %u", v5, v3, v4);
tell_all(v13, -1);
}
while ( NUMAGENTS > v1 );
}
tell_all("GO", -1);
if ( NUMCOWS )
memset(s, 0, 2LL * (unsigned int)NUMCOWS);
v6 = (unsigned int *)(unsigned int)((_DWORD)agents + 260);
v7 = 0;
v8 = 0LL;
if ( NUMAGENTS )
{
do
{
listen_bot_timeout(v13, v7, v6[5]);
if ( !v6[1] )
{
_isoc99_sscanf(v13, "%*s %u", v6);
v9 = *v6 % NUMCOWS;
*v6 = v9;
++s[v9];
}
v8 = (unsigned int)NUMAGENTS;
++v7;
v6 += 74;
}
while ( NUMAGENTS > v7 );
if ( NUMAGENTS )
{
v10 = agents;
do
{
if ( *((_DWORD *)v10 + 66) != -1 )
*((_DWORD *)v10 + 64) += MILKVALUES[*((unsigned int *)v10 + 65)]
/ (unsigned int)(unsigned __int16)s[*((unsigned int *)v10 + 65)];
v10 += 296;
}
while ( v10 != &agents[296 * (unsigned int)v8] );
}
}
v11 = i;
update_bcb_vis(v8, agents, v11);
}
return tell_all("ENDGAME", -1);
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int i; // er12
unsigned int v1; // ebp
unsigned int *v2; // rbx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // rdx
unsigned int *v6; // rbx
unsigned int v7; // ebp
__int64 v8; // rdi
unsigned int v9; // edx
char *v10; // rcx
__int64 v11; // rdx
char v13[128]; // [rsp+0h] [rbp-168h] BYREF
__int16 s[116]; // [rsp+80h] [rbp-E8h] BYREF

for ( i = 0; NUMROUNDS > i; ++i )
{
sprintf(v13, "ROUND %u", i);
v1 = 0;
func5(v13, -1);
v2 = (unsigned int *)agents;
if ( NUMAGENTS )
{
do
{
if ( v2[66] )
{
v2[65] = -1;
v3 = 0xFFFFFFFFLL;
}
else
{
v3 = v2[65];
}
v4 = v2[64];
v5 = v1;
v2 += 74;
++v1;
sprintf(v13, "PLAYER %u %u %u", v5, v3, v4);
func5(v13, -1);
}
while ( NUMAGENTS > v1 );
}
func5("GO", -1);
if ( NUMCOWS )
memset(s, 0, 2LL * (unsigned int)NUMCOWS);
v6 = (unsigned int *)(unsigned int)((_DWORD)agents + 260);
v7 = 0;
v8 = 0LL;
if ( NUMAGENTS )
{
do
{
func3(v13, v7, v6[5]);
if ( !v6[1] )
{
_isoc99_sscanf(v13, "%*s %u", v6);
v9 = *v6 % NUMCOWS;
*v6 = v9;
++s[v9];
}
v8 = (unsigned int)NUMAGENTS;
++v7;
v6 += 74;
}
while ( NUMAGENTS > v7 );
if ( NUMAGENTS )
{
v10 = agents;
do
{
if ( *((_DWORD *)v10 + 66) != -1 )
*((_DWORD *)v10 + 64) += MILKVALUES[*((unsigned int *)v10 + 65)]
/ (unsigned int)(unsigned __int16)s[*((unsigned int *)v10 + 65)];
v10 += 296;
}
while ( v10 != &agents[296 * (unsigned int)v8] );
}
}
v11 = i;
update_bcb_vis(v8, agents, v11);
}
return func5("ENDGAME", -1);
}

original_code:
void play_game()
{
 char msg[128];
 struct agent_t *a;
 unsigned int i, rnum;
 unsigned short cowcount[100];
 for (rnum = 0; rnum < NUMROUNDS; ++rnum)
 {
  sprintf(msg, "ROUND %u", rnum);
  tell_all(msg, -1);
  for (i = 0, a = agents; i < NUMAGENTS; ++a, ++i)
  {
   if (a->status != 0) a->loc = -1;
   sprintf(msg, "PLAYER %u %u %u", i, a->loc, a->milk);
   tell_all(msg, -1);
  }
  tell_all("GO", -1);
  for (i = 0; i < NUMCOWS; ++i) cowcount[i] = 0;
  for (i = 0, a = agents; i < NUMAGENTS; ++a, ++i)
  {
   listen_bot_timeout(msg, i, a->timeout);
   if (a->status != 0) continue;
   sscanf(msg, "%*s %u", &a->loc);
   a->loc %= NUMCOWS;
   ++cowcount[a->loc];
  }
  for (i = 0, a = agents; i < NUMAGENTS; ++a, ++i)
   if (a->status != -1) a->milk += MILKVALUES[a->loc] / cowcount[a->loc];
  update_bcb_vis(NUMAGENTS, agents, rnum);
 }
 tell_all("ENDGAME", -1);
}

canonical_original_code:
void play_game()
{
 char msg[128];
 struct agent_t *a;
 unsigned int i; unsigned int rnum;
 unsigned short cowcount[100];
 for (rnum = 0; rnum < NUMROUNDS; ++rnum)
 {
  sprintf(msg, "ROUND %u", rnum);
  tell_all(msg, -1);
  for (i = 0, a = agents; i < NUMAGENTS; ++a, ++i)
  {
   if (a->status != 0) a->loc = -1;
   sprintf(msg, "PLAYER %u %u %u", i, a->loc, a->milk);
   tell_all(msg, -1);
  }
  tell_all("GO", -1);
  for (i = 0; i < NUMCOWS; ++i) cowcount[i] = 0;
  for (i = 0, a = agents; i < NUMAGENTS; ++a, ++i)
  {
   listen_bot_timeout(msg, i, a->timeout);
   if (a->status != 0) continue;
   sscanf(msg, "%*s %u", &a->loc);
   a->loc %= NUMCOWS;
   ++cowcount[a->loc];
  }
  for (i = 0, a = agents; i < NUMAGENTS; ++a, ++i)
   if (a->status != -1) a->milk += MILKVALUES[a->loc] / cowcount[a->loc];
  update_bcb_vis(NUMAGENTS, agents, rnum);
 }
 tell_all("ENDGAME", -1);
}

variable_types: struct agent_t { char name[256]; unsigned int milk; unsigned int loc; int status; int fds[2]; int pid; int timeout; void *vis; } *

variable_types:
rnum
unsigned int

variable_types:
cowcount
unsigned short [100]


decompiled_code:
int cleanup_bots()
{
int result; // eax
unsigned int v1; // ebp
int *v2; // rbx
int v3; // edi

result = NUMAGENTS;
if ( NUMAGENTS )
{
v1 = 0;
v2 = (int *)(unsigned int)((_DWORD)agents + 268);
do
{
v3 = *v2;
++v1;
v2 += 74;
close(v3);
result = kill(*(v2 - 72), 15);
}
while ( NUMAGENTS > v1 );
}
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax
unsigned int v1; // ebp
int *v2; // rbx
int v3; // edi

result = NUMAGENTS;
if ( NUMAGENTS )
{
v1 = 0;
v2 = (int *)(unsigned int)((_DWORD)agents + 268);
do
{
v3 = *v2;
++v1;
v2 += 74;
close(v3);
result = kill(*(v2 - 72), 15);
}
while ( NUMAGENTS > v1 );
}
return result;
}

original_code:
void cleanup_bots()
{
 int i; for (i = 0; i < NUMAGENTS; ++i)
 {
  close(agents[i].fds[0]);
  kill(agents[i].pid, 15);
 }
}

variable_types: i int


sighandler

decompiled_code:
void __fastcall __noreturn sighandler(unsigned int a1)
{
fprintf(stderr, "!!! Signal %d\n", a1);
close_bcb_vis();
cleanup_bots();
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(unsigned int a1)
{
fprintf(stderr, "!!! Signal %d\n", a1);
close_bcb_vis();
func8();
exit(1);
}

original_code:
void sighandler(int signum)
{
 fprintf(stderr, "!!! Signal %d\n", signum);
 close_bcb_vis();
 cleanup_bots();
 exit(1);
}

variable_types: signum int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4; // rax
unsigned int v6; // edx
char *v7; // rax
unsigned int v8; // er12
char *v9; // rbx
unsigned int v10; // ebp
const char **v11; // [rsp+0h] [rbp-38h] BYREF
int v12; // [rsp+Ch] [rbp-2Ch] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

v12 = argc;
v11 = argv;
setbuf(stdout, 0LL);
setbuf(stderr, 0LL);
signal(13, (__sighandler_t)sighandler);
signal(15, (__sighandler_t)sighandler);
gettimeofday(&tv, 0LL);
srand(tv.tv_usec);
if ( argc <= 1 )
{
fprintf(stderr, "USAGE: %s <datafile>\n", *v11);
exit(0);
}
v3 = 0;
gamedata = fopen(v11[1], "r");
_isoc99_fscanf(gamedata, "%u %u", &NUMCOWS, &NUMROUNDS);
if ( NUMCOWS )
{
do
{
v4 = v3++;
_isoc99_fscanf(gamedata, "%u", &MILKVALUES[v4]);
}
while ( NUMCOWS > v3 );
}
_isoc99_fscanf(gamedata, "%u", &NUMAGENTS);
setup_game();
fclose(gamedata);
if ( (unsigned int)setup_bcb_vis((unsigned int)NUMAGENTS, agents, &v12, &v11) )
{
tell_all("READY", -1);
play_game();
close_bcb_vis();
if ( NUMAGENTS )
{
v6 = 0;
v7 = agents;
do
{
v8 = v6;
if ( *((_DWORD *)v7 + 64) > v6 && !*((_DWORD *)v7 + 66) )
{
v6 = *((_DWORD *)v7 + 64);
v8 = v6;
}
v7 += 296;
}
while ( v7 != &agents[296 * NUMAGENTS] );
v9 = agents;
v10 = 0;
do
{
if ( *((_DWORD *)v9 + 64) == v8 && !*((_DWORD *)v9 + 66) )
printf("Player #%u (%s) wins!\n", v10, v9);
++v10;
v9 += 296;
}
while ( NUMAGENTS > v10 );
}
}
cleanup_bots();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4; // rax
unsigned int v6; // edx
char *v7; // rax
unsigned int v8; // er12
char *v9; // rbx
unsigned int v10; // ebp
const char **v11; // [rsp+0h] [rbp-38h] BYREF
int v12; // [rsp+Ch] [rbp-2Ch] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

v12 = argc;
v11 = argv;
setbuf(stdout, 0LL);
setbuf(stderr, 0LL);
signal(13, (__sighandler_t)sighandler);
signal(15, (__sighandler_t)sighandler);
gettimeofday(&tv, 0LL);
srand(tv.tv_usec);
if ( argc <= 1 )
{
fprintf(stderr, "USAGE: %s <datafile>\n", *v11);
exit(0);
}
v3 = 0;
gamedata = fopen(v11[1], "r");
_isoc99_fscanf(gamedata, "%u %u", &NUMCOWS, &NUMROUNDS);
if ( NUMCOWS )
{
do
{
v4 = v3++;
_isoc99_fscanf(gamedata, "%u", &MILKVALUES[v4]);
}
while ( NUMCOWS > v3 );
}
_isoc99_fscanf(gamedata, "%u", &NUMAGENTS);
func6();
fclose(gamedata);
if ( (unsigned int)setup_bcb_vis((unsigned int)NUMAGENTS, agents, &v12, &v11) )
{
func5("READY", -1);
func7();
close_bcb_vis();
if ( NUMAGENTS )
{
v6 = 0;
v7 = agents;
do
{
v8 = v6;
if ( *((_DWORD *)v7 + 64) > v6 && !*((_DWORD *)v7 + 66) )
{
v6 = *((_DWORD *)v7 + 64);
v8 = v6;
}
v7 += 296;
}
while ( v7 != &agents[296 * NUMAGENTS] );
v9 = agents;
v10 = 0;
do
{
if ( *((_DWORD *)v9 + 64) == v8 && !*((_DWORD *)v9 + 66) )
printf("Player #%u (%s) wins!\n", v10, v9);
++v10;
v9 += 296;
}
while ( NUMAGENTS > v10 );
}
}
func8();
return 0;
}

original_code:
int main(int argc, char** argv)
{
 setbuf(stdout, ((void *)0));
 setbuf(stderr, ((void *)0));
 unsigned int i;
 signal(13, sighandler);
 signal(15, sighandler);
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 srand(tv.tv_usec);
 if (argc < 2)
 {
  fprintf(stderr, "USAGE: %s <datafile>\n", argv[0]);
  exit(0);
 }
 gamedata = fopen(argv[1], "r");
 fscanf(gamedata, "%u %u", &NUMCOWS, &NUMROUNDS);
 for (i = 0; i < NUMCOWS; ++i)
  fscanf(gamedata, "%u", &MILKVALUES[i]);
 fscanf(gamedata, "%u", &NUMAGENTS);
 setup_game();
 fclose(gamedata);
 if (setup_bcb_vis(NUMAGENTS, agents, &argc, &argv))
 {
  tell_all("READY", -1);
  play_game();
  close_bcb_vis();
  int maxmilk = 0;
  struct agent_t *a;
  for (i = 0, a = agents; i < NUMAGENTS; ++i, ++a)
   if (a->milk > maxmilk && a->status == 0)
    maxmilk = a->milk;
  for (i = 0, a = agents; i < NUMAGENTS; ++i, ++a)
   if (a->milk == maxmilk && a->status == 0)
    printf("Player #%u (%s) wins!\n", i, a->name);
 }
 cleanup_bots();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 setbuf(stdout, ((void *)0));
 setbuf(stderr, ((void *)0));
 unsigned int i;
 signal(13, sighandler);
 signal(15, sighandler);
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 srand(tv.tv_usec);
 if (argc < 2)
 {
  fprintf(stderr, "USAGE: %s <datafile>\n", argv[0]);
  exit(0);
 }
 gamedata = fopen(argv[1], "r");
 fscanf(gamedata, "%u %u", &NUMCOWS, &NUMROUNDS);
 for (i = 0; i < NUMCOWS; ++i)
  fscanf(gamedata, "%u", &MILKVALUES[i]);
 fscanf(gamedata, "%u", &NUMAGENTS);
 setup_game();
 fclose(gamedata);
 if (setup_bcb_vis(NUMAGENTS, agents, &argc, &argv))
 {
  tell_all("READY", -1);
  play_game();
  close_bcb_vis();
  int maxmilk = 0;
  struct agent_t *a;
  for (i = 0, a = agents; i < NUMAGENTS; ++i, ++a)
   if (a->milk > maxmilk && a->status == 0)
    maxmilk = a->milk;
  for (i = 0, a = agents; i < NUMAGENTS; ++i, ++a)
   if (a->milk == maxmilk && a->status == 0)
    printf("Player #%u (%s) wins!\n", i, a->name);
 }
 cleanup_bots();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: maxmilk int

user_defined_types: struct timeval { long tv_sec; long tv_usec; }

user_defined_types: struct agent_t { char name[256]; unsigned int milk; unsigned int loc; int status; int fds[2]; int pid; int timeout; void *vis; }


repo: useche/btstats

decompiled_code:
__int64 __fastcall comp_int64(_QWORD *a1, _QWORD *a2)
{
__int64 result; // rax

result = 0LL;
if ( *a1 != *a2 )
result = *a2 < *a1 ? 1 : -1;
return result;
}

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

result = 0LL;
if ( *a1 != *a2 )
result = *a2 < *a1 ? 1 : -1;
return result;
}

original_code:
inline static int comp_int64(gconstpointer a,gconstpointer b)
{
 __u64 x = *((__u64 *)a);
 __u64 y = *((__u64 *)b);
 if(x==y)
  return 0;
 else
  return x>y?1:-1;
}

canonical_original_code:
inline static int comp_int64(void *a, void *b)
{
 unsigned long long x = *((__u64 *)a);
 unsigned long long y = *((__u64 *)b);
 if(x==y)
  return 0;
 else
  return x>y?1:-1;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
x
unsigned long long

variable_types:
y
unsigned long long


decompiled_code:
void __fastcall add_histogram(unsigned __int64 *a1, unsigned __int64 *a2)
{
unsigned __int64 v2; // r9
unsigned __int64 v3; // r10
unsigned int v4; // edx
unsigned __int64 v5; // rax
double *v6; // rcx
double v7; // xmm0_8

v2 = *a1;
if ( *a1 )
{
v3 = *a2;
v4 = 0;
v5 = 0LL;
do
{
if ( v3 <= v5 )
break;
v6 = (double *)(a1[2] + 8 * v5);
v7 = *v6 + *(double *)(a2[2] + 8 * v5);
v5 = ++v4;
*v6 = v7;
}
while ( v4 < v2 );
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned __int64 *a1, unsigned __int64 *a2)
{
unsigned __int64 v2; // r9
unsigned __int64 v3; // r10
unsigned int v4; // edx
unsigned __int64 v5; // rax
double *v6; // rcx
double v7; // xmm0_8

v2 = *a1;
if ( *a1 )
{
v3 = *a2;
v4 = 0;
v5 = 0LL;
do
{
if ( v3 <= v5 )
break;
v6 = (double *)(a1[2] + 8 * v5);
v7 = *v6 + *(double *)(a2[2] + 8 * v5);
v5 = ++v4;
*v6 = v7;
}
while ( v4 < v2 );
}
}

original_code:
static void add_histogram(gsl_histogram *h1, gsl_histogram *h2)
{
 unsigned int i;
 for (i = 0; i < h1->n && i < h2->n; i++) {
  h1->bin[i] += h2->bin[i];
 }
}

canonical_original_code:
static void add_histogram(struct gsl_histogram *h1, struct gsl_histogram *h2)
{
 unsigned int i;
 for (i = 0; i < h1->n && i < h2->n; i++) {
  h1->bin[i] += h2->bin[i];
 }
}

variable_types: struct gsl_histogram { unsigned long n; double *range; double *bin; } *


decompiled_code:
_QWORD *new_hist()
{
_QWORD *v0; // r12

v0 = (_QWORD *)gsl_histogram_alloc(21LL);
gsl_histogram_set_ranges_uniform(v0, 0.0, 168.0);
*(_QWORD *)(v0[1] + 8LL * *v0) = LC2;
return v0;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *v0; // r12

v0 = (_QWORD *)gsl_histogram_alloc(21LL);
gsl_histogram_set_ranges_uniform(v0, 0.0, 168.0);
*(_QWORD *)(v0[1] + 8LL * *v0) = LC2;
return v0;
}

original_code:
static gsl_histogram *new_hist()
{
 gsl_histogram *h;
 h = gsl_histogram_alloc((21));
 gsl_histogram_set_ranges_uniform(h,0,(21)*(8));
 h->range[h->n] = ((double)1.79769313486231570814527423731704357e+308L);
 return h;
}

canonical_original_code:
static struct gsl_histogram *new_hist()
{
 struct gsl_histogram *h;
 h = gsl_histogram_alloc((21));
 gsl_histogram_set_ranges_uniform(h,0,(21)*(8));
 h->range[h->n] = ((double)1.79769313486231570814527423731704357e+308L);
 return h;
}

return_type: struct gsl_histogram { unsigned long n; double *range; double *bin; } *


original_code:
static void init_oio_data(struct oio_data *oio, int n)
{
 int i;
 for (i = 0; i < n; i++) {
  oio[i].time = 0;
  oio[i].op[0] = new_hist();
  oio[i].op[1] = new_hist();
 }
}

variable_types: struct oio_data { struct gsl_histogram { unsigned long n; double *range; double *bin; } *op[2]; unsigned long long time; } *

variable_types: n int

user_defined_types: struct oio_data { struct gsl_histogram *op[2]; unsigned long long time; }


decompiled_code:
__int64 __fastcall get_filename(__int64 a1, const char *a2, const char *a3, __int64 a4)
{
double v4; // xmm0_8

if ( a4 == -1 )
return _sprintf_chk(a1, 1LL, -1LL, "%s_%s", a2, a3);
if ( a4 < 0 )
v4 = (double)(int)(a4 & 1 | ((unsigned __int64)a4 >> 1)) + (double)(int)(a4 & 1 | ((unsigned __int64)a4 >> 1));
else
v4 = (double)(int)a4;
return _sprintf_chk(a1, 1LL, -1LL, "%s_%s_%.4f", a2, a3, v4 / 1000000000.0);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2, const char *a3, __int64 a4)
{
double v4; // xmm0_8

if ( a4 == -1 )
return _sprintf_chk(a1, 1LL, -1LL, "%s_%s", a2, a3);
if ( a4 < 0 )
v4 = (double)(int)(a4 & 1 | ((unsigned __int64)a4 >> 1)) + (double)(int)(a4 & 1 | ((unsigned __int64)a4 >> 1));
else
v4 = (double)(int)a4;
return _sprintf_chk(a1, 1LL, -1LL, "%s_%s_%.4f", a2, a3, v4 / 1000000000.0);
}

original_code:
inline static void get_filename(char *filename, char *suffix, char *param, __u64 end_range)
{
  if(end_range==(0xffffffffffffffffUL))
   sprintf(filename, "%s_%s",
     suffix,
     param);
  else
   sprintf(filename, "%s_%s_%.4f",
     suffix,
     param,
     (((double)(end_range))/1000000000));
}

canonical_original_code:
inline static void get_filename(char *filename, char *suffix, char *param, unsigned long long end_range)
{
  if(end_range==(0xffffffffffffffffUL))
   sprintf(filename, "%s_%s",
     suffix,
     param);
  else
   sprintf(filename, "%s_%s_%.4f",
     suffix,
     param,
     (((double)(end_range))/1000000000));
}

variable_types:
filename
char *

variable_types:
suffix
char *

variable_types:
param
char *


I

original_code:
static void I(struct blk_io_trace *t, void *data)
{
 struct merge_data *m = (struct merge_data *)data;
 m->ins++;
}

variable_types: struct blk_io_trace { unsigned int magic; unsigned int sequence; unsigned long long time; unsigned long long sector; unsigned int bytes; unsigned int action; unsigned int pid; unsigned int device; unsigned int cpu; unsigned short error; unsigned short pdu_len; } *

variable_types:
data
void *

variable_types: struct merge_data { unsigned long long ms; unsigned long long fs; unsigned long long ins; } *


C

decompiled_code:
void __fastcall C(__int64 a1, _QWORD *a2)
{
if ( g_tree_lookup(*a2, a1 + 16) )
{
g_tree_remove(*a2, a1 + 16);
oio_change((__int64)a2, a1, 0);
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, _QWORD *a2)
{
if ( g_tree_lookup(*a2, a1 + 16) )
{
g_tree_remove(*a2, a1 + 16);
func8((__int64)a2, a1, 0);
}
}

original_code:
static void C(struct blk_io_trace *t, void *data)
{
 struct reqsize_data *rsd = (struct reqsize_data *)data;
 __u64 blks = ((t)->bytes >> 9);
 if(blks) {
  rsd->min = (((rsd->min) < (blks)) ? (rsd->min) : (blks));
  rsd->max = (((rsd->max) > (blks)) ? (rsd->max) : (blks));
  rsd->total_size += blks;
  rsd->reqs++;
  if(!((t->action & ((BLK_TC_WRITE) << (16))) != 0)) {
   rsd->reads++;
  }
 }
}

canonical_original_code:
static void C(struct blk_io_trace *t, void *data)
{
 struct reqsize_data *rsd = (struct reqsize_data *)data;
 unsigned long long blks = ((t)->bytes >> 9);
 if(blks) {
  rsd->min = (((rsd->min) < (blks)) ? (rsd->min) : (blks));
  rsd->max = (((rsd->max) > (blks)) ? (rsd->max) : (blks));
  rsd->total_size += blks;
  rsd->reqs++;
  if(!((t->action & ((BLK_TC_WRITE) << (16))) != 0)) {
   rsd->reads++;
  }
 }
}

variable_types: struct reqsize_data { unsigned long long min; unsigned long long max; unsigned long long total_size; unsigned long long reqs; unsigned long long reads; } *

variable_types:
blks
unsigned long long

user_defined_types: struct blk_io_trace { unsigned int magic; unsigned int sequence; unsigned long long time; unsigned long long sector; unsigned int bytes; unsigned int action; unsigned int pid; unsigned int device; unsigned int cpu; unsigned short error; unsigned short pdu_len; }


decompiled_code:
unsigned __int64 __fastcall min_time(unsigned __int64 a1, unsigned __int64 *a2)
{
unsigned __int64 result; // rax

result = *(unsigned int *)(a1 + 52);
if ( !(_DWORD)result )
{
result = *a2;
if ( !*a2 || (result = *(_QWORD *)(result + 8), *(_QWORD *)(a1 + 8) < result) )
*a2 = a1;
}
return result;
}

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

result = *(unsigned int *)(a1 + 52);
if ( !(_DWORD)result )
{
result = *a2;
if ( !*a2 || (result = *(_QWORD *)(result + 8), *(_QWORD *)(a1 + 8) < result) )
*a2 = a1;
}
return result;
}

original_code:
void min_time(gpointer data, gpointer min)
{
 struct trace_file *tf = (struct trace_file *)data;
 struct trace_file **mintf = (struct trace_file **)min;
 if(!tf->eof) {
  if(!(*mintf)) {
   *mintf = tf;
  } else {
   if(tf->t.time<(*mintf)->t.time)
    *mintf = tf;
  }
 }
}

canonical_original_code:
void min_time(void *data, void *min)
{
 struct trace_file *tf = (struct trace_file *)data;
 struct trace_file **mintf = (struct trace_file **)min;
 if(!tf->eof) {
  if(!(*mintf)) {
   *mintf = tf;
  } else {
   if(tf->t.time<(*mintf)->t.time)
    *mintf = tf;
  }
 }
}

variable_types:
min
void *

variable_types: struct trace_file { struct blk_io_trace { unsigned int magic; unsigned int sequence; unsigned long long time; unsigned long long sector; unsigned int bytes; unsigned int action; unsigned int pid; unsigned int device; unsigned int cpu; unsigned short error; unsigned short pdu_len; } t; int fd; int eof; } **

user_defined_types: struct trace_file { struct blk_io_trace t; int fd; int eof; }


decompiled_code:
__int64 __fastcall correct_time(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(_QWORD *)(a2 + 8);
*(_QWORD *)(a1 + 8) -= result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(_QWORD *)(a2 + 8);
*(_QWORD *)(a1 + 8) -= result;
return result;
}

original_code:
void correct_time(gpointer data, gpointer dt_arg)
{
 struct trace_file *tf = (struct trace_file *)data;
 struct trace *dt = (struct trace *)dt_arg;
 tf->t.time -= dt->genesis;
}

canonical_original_code:
void correct_time(void *data, void *dt_arg)
{
 struct trace_file *tf = (struct trace_file *)data;
 struct trace *dt = (struct trace *)dt_arg;
 tf->t.time -= dt->genesis;
}

variable_types: struct trace_file { struct blk_io_trace { unsigned int magic; unsigned int sequence; unsigned long long time; unsigned long long sector; unsigned int bytes; unsigned int action; unsigned int pid; unsigned int device; unsigned int cpu; unsigned short error; unsigned short pdu_len; } t; int fd; int eof; } *

variable_types: struct trace { struct _GSList { void *data; struct _GSList *next; } *files; unsigned long long genesis; } *

user_defined_types: struct trace { struct _GSList *files; unsigned long long genesis; }


decompiled_code:
__int64 __fastcall check_data_endianness(unsigned int a1)
{
unsigned int v1; // edx
__int64 result; // rax
__int64 v3; // rax

v1 = a1;
result = 1LL;
LOBYTE(v1) = 0;
if ( v1 != 1700885504 )
{
v3 = _bswap_32(a1);
LOBYTE(v3) = 0;
result = (unsigned int)-((_DWORD)v3 != 1700885504);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
unsigned int v1; // edx
__int64 result; // rax
__int64 v3; // rax

v1 = a1;
result = 1LL;
LOBYTE(v1) = 0;
if ( v1 != 1700885504 )
{
v3 = func3(a1);
LOBYTE(v3) = 0;
result = (unsigned int)-((_DWORD)v3 != 1700885504);
}
return result;
}

original_code:
static inline int check_data_endianness(__u32 magic)
{
 if ((magic & 0xffffff00) == 0x65617400) {
  return 1;
 }
 magic = __bswap_32(magic);
 if ((magic & 0xffffff00) == 0x65617400) {
  return 0;
 }
 return -1;
}

canonical_original_code:
static inline int check_data_endianness(unsigned int magic)
{
 if ((magic & 0xffffff00) == 0x65617400) {
  return 1;
 }
 magic = __bswap_32(magic);
 if ((magic & 0xffffff00) == 0x65617400) {
  return 0;
 }
 return -1;
}

variable_types:
magic
unsigned int


decompiled_code:
__int64 __fastcall free_data(__int64 a1)
{
close(*(_DWORD *)(a1 + 48));
return g_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
close(*(_DWORD *)(a1 + 48));
return g_free(a1);
}

original_code:
void free_data(gpointer data, gpointer __unused)
{
 struct trace_file *tf = (struct trace_file *)data;
 close(tf->fd);
 g_free(tf);
}

canonical_original_code:
void free_data(void *data, void *__unused)
{
 struct trace_file *tf = (struct trace_file *)data;
 close(tf->fd);
 g_free(tf);
}


original_code:
gboolean not_real_event(struct blk_io_trace *t)
{
 return (t->action & ((BLK_TC_NOTIFY) << (16))) ||
  (t->action & ((BLK_TC_DISCARD) << (16)))||
  (t->action & ((BLK_TC_DRV_DATA) << (16)));
}

canonical_original_code:
int not_real_event(struct blk_io_trace *t)
{
 return (t->action & ((BLK_TC_NOTIFY) << (16))) ||
  (t->action & ((BLK_TC_DISCARD) << (16)))||
  (t->action & ((BLK_TC_DRV_DATA) << (16)));
}