decompiled_code:
__int64 __fastcall read_value(const char *a1, const char *a2)
{
char *v2; // rax
const char *v3; // rbp
const unsigned __int16 *v4; // rcx
__int64 v5; // rdx
__int64 result; // rax

v2 = strstr(a1, a2);
if ( !v2 )
goto LABEL_6;
v3 = &v2[strlen(a2)];
v4 = *_ctype_b_loc();
while ( 1 )
{
v5 = *v3;
if ( (v4[v5] & 0x2000) == 0 )
break;
++v3;
}
if ( (_BYTE)v5 )
result = (unsigned int)strtoul(v3, 0LL, 0);
else
LABEL_6:
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
char *v2; // rax
const char *v3; // rbp
const unsigned __int16 *v4; // rcx
__int64 v5; // rdx
__int64 result; // rax

v2 = strstr(a1, a2);
if ( !v2 )
goto LABEL_6;
v3 = &v2[strlen(a2)];
v4 = *_ctype_b_loc();
while ( 1 )
{
v5 = *v3;
if ( (v4[v5] & 0x2000) == 0 )
break;
++v3;
}
if ( (_BYTE)v5 )
result = (unsigned int)strtoul(v3, 0LL, 0);
else
LABEL_6:
result = 0LL;
return result;
}

original_code:
unsigned int read_value(const char *buffer, const char *prefix)
{
 buffer = strstr(buffer, prefix);
 if (buffer != ((void *)0)) {
  buffer += strlen(prefix);
  while (((*__ctype_b_loc ())[(int) ((*buffer))] & (unsigned short int) _ISspace)) {
   buffer++;
  }
  return (*buffer != '\0') ? strtoul(buffer, ((void *)0), 0) : 0;
 } else {
  return 0;
 }
}

canonical_original_code:
unsigned int read_value(char *buffer, char *prefix)
{
 buffer = strstr(buffer, prefix);
 if (buffer != ((void *)0)) {
  buffer += strlen(prefix);
  while (((*__ctype_b_loc ())[(int) ((*buffer))] & (unsigned short) _ISspace)) {
   buffer++;
  }
  return (*buffer != '\0') ? strtoul(buffer, ((void *)0), 0) : 0;
 } else {
  return 0;
 }
}

variable_types:
buffer
char *

variable_types:
prefix
char *


repo: javiplx/mini-snmpd

decompiled_code:
char *__fastcall read_values(const char *a1, const char *a2, _DWORD *a3, int a4)
{
char *v6; // rax
char *v7; // rbx
char *result; // rax
char *v9; // rbx
const unsigned __int16 **v10; // r13
__int64 v11; // r12
const unsigned __int16 *v12; // rsi
__int64 v13; // rcx
const char *v14; // rdi
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v6 = strstr(a1, a2);
endptr = v6;
if ( !v6 )
return (char *)memset(a3, 0, 4LL * a4);
v7 = v6;
result = (char *)strlen(a2);
v9 = &v7[(_QWORD)result];
endptr = v9;
if ( a4 > 0 )
{
v10 = _ctype_b_loc();
v11 = (__int64)&a3[a4 - 1 + 1];
while ( 1 )
{
v12 = *v10;
for ( result = v9; ; endptr = result )
{
v13 = *result;
v14 = result++;
if ( (v12[v13] & 0x2000) == 0 )
break;
}
if ( (_BYTE)v13 )
{
++a3;
result = (char *)strtoul(v14, &endptr, 0);
*(a3 - 1) = (_DWORD)result;
if ( (_DWORD *)v11 == a3 )
return result;
}
else
{
*a3++ = 0;
if ( (_DWORD *)v11 == a3 )
return result;
}
v9 = endptr;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1, const char *a2, _DWORD *a3, int a4)
{
char *v6; // rax
char *v7; // rbx
char *result; // rax
char *v9; // rbx
const unsigned __int16 **v10; // r13
__int64 v11; // r12
const unsigned __int16 *v12; // rsi
__int64 v13; // rcx
const char *v14; // rdi
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v6 = strstr(a1, a2);
endptr = v6;
if ( !v6 )
return (char *)memset(a3, 0, 4LL * a4);
v7 = v6;
result = (char *)strlen(a2);
v9 = &v7[(_QWORD)result];
endptr = v9;
if ( a4 > 0 )
{
v10 = _ctype_b_loc();
v11 = (__int64)&a3[a4 - 1 + 1];
while ( 1 )
{
v12 = *v10;
for ( result = v9; ; endptr = result )
{
v13 = *result;
v14 = result++;
if ( (v12[v13] & 0x2000) == 0 )
break;
}
if ( (_BYTE)v13 )
{
++a3;
result = (char *)strtoul(v14, &endptr, 0);
*(a3 - 1) = (_DWORD)result;
if ( (_DWORD *)v11 == a3 )
return result;
}
else
{
*a3++ = 0;
if ( (_DWORD *)v11 == a3 )
return result;
}
v9 = endptr;
}
}
return result;
}

original_code:
void read_values(const char *buffer, const char *prefix, unsigned int *values, int count)
{
 int i;
 buffer = strstr(buffer, prefix);
 if (buffer != ((void *)0)) {
  buffer += strlen(prefix);
  for (i = 0; i < count; i++) {
   while (((*__ctype_b_loc ())[(int) ((*buffer))] & (unsigned short int) _ISspace)) {
    buffer++;
   }
   if (*buffer != '\0') {
    values[i] = strtoul(buffer, (char **)&buffer, 0);
   } else {
    values[i] = 0;
   }
  }
 } else {
  memset(values, 0, count * sizeof (unsigned int));
 }
}

canonical_original_code:
void read_values(char *buffer, char *prefix, unsigned int *values, int count)
{
 int i;
 buffer = strstr(buffer, prefix);
 if (buffer != ((void *)0)) {
  buffer += strlen(prefix);
  for (i = 0; i < count; i++) {
   while (((*__ctype_b_loc ())[(int) ((*buffer))] & (unsigned short) _ISspace)) {
    buffer++;
   }
   if (*buffer != '\0') {
    values[i] = strtoul(buffer, (char **)&buffer, 0);
   } else {
    values[i] = 0;
   }
  }
 } else {
  memset(values, 0, count * sizeof (unsigned int));
 }
}

variable_types:
values
unsigned int *

variable_types: count int

variable_types: i int

return_type: void


decompiled_code:
__int64 __fastcall ticks_since(__time_t *a1, struct timeval *a2)
{
__time_t v3; // rax
__suseconds_t v4; // rcx
__suseconds_t v5; // rsi
float v6; // xmm1_4
unsigned int v7; // er12

if ( gettimeofday(a2, 0LL) == -1 )
{
v7 = -1;
fprintf(stderr, "could not get ticks: %m\n");
}
else
{
v3 = a2->tv_sec;
if ( a2->tv_sec < *a1 || (v4 = a2->tv_usec, v5 = a1[1], a2->tv_sec == *a1) && v5 > v4 )
{
v7 = -1;
fwrite("could not get ticks: time running backwards\n", 1uLL, 0x2CuLL, stderr);
}
else
{
v6 = (float)(int)(v3 - 1 - *a1) * 100.0 + (float)(int)((v4 + 1000000 - v5) / 10000);
if ( g_verbose )
fprintf(stderr, "seconds since last update: %.2f\n", (float)(v6 / 100.0));
if ( v6 < -2147483600.0 )
{
v7 = 0x80000000;
}
else
{
v7 = 0x7FFFFFFF;
if ( v6 <= 2147483600.0 )
v7 = (int)v6;
}
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(__time_t *a1, struct timeval *a2)
{
__time_t v3; // rax
__suseconds_t v4; // rcx
__suseconds_t v5; // rsi
float v6; // xmm1_4
unsigned int v7; // er12

if ( gettimeofday(a2, 0LL) == -1 )
{
v7 = -1;
fprintf(stderr, "could not get ticks: %m\n");
}
else
{
v3 = a2->tv_sec;
if ( a2->tv_sec < *a1 || (v4 = a2->tv_usec, v5 = a1[1], a2->tv_sec == *a1) && v5 > v4 )
{
v7 = -1;
fwrite("could not get ticks: time running backwards\n", 1uLL, 0x2CuLL, stderr);
}
else
{
v6 = (float)(int)(v3 - 1 - *a1) * 100.0 + (float)(int)((v4 + 1000000 - v5) / 10000);
if ( g_verbose )
fprintf(stderr, "seconds since last update: %.2f\n", (float)(v6 / 100.0));
if ( v6 < -2147483600.0 )
{
v7 = 0x80000000;
}
else
{
v7 = 0x7FFFFFFF;
if ( v6 <= 2147483600.0 )
v7 = (int)v6;
}
}
}
return v7;
}

original_code:
int ticks_since(const struct timeval *tv_last, struct timeval *tv_now)
{
 float ticks;
 if (gettimeofday(tv_now, ((void *)0)) == -1) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not get ticks: %m\n"); } } while (0);
  return -1;
 } else if (tv_now->tv_sec < tv_last->tv_sec
  || (tv_now->tv_sec == tv_last->tv_sec && tv_now->tv_usec < tv_last->tv_usec)) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not get ticks: time running backwards\n"); } } while (0);
  return -1;
 } else {
  ticks = (float)(tv_now->tv_sec - 1 - tv_last->tv_sec) * 100.0
   + (float)((tv_now->tv_usec + 1000000 - tv_last->tv_usec) / 10000);
  do { if (g_verbose || (7 != 7)) { fprintf(stderr, "seconds since last update: %.2f\n", ticks / 100); } } while (0);
  if (ticks < (-0x7fffffff - 1)) {
   return (-0x7fffffff - 1);
  } else if (ticks > 0x7fffffff) {
   return 0x7fffffff;
  } else {
   return ticks;
  }
 }
}

canonical_original_code:
int ticks_since(struct timeval *tv_last, struct timeval *tv_now)
{
 float ticks;
 if (gettimeofday(tv_now, ((void *)0)) == -1) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not get ticks: %m\n"); } } while (0);
  return -1;
 } else if (tv_now->tv_sec < tv_last->tv_sec
  || (tv_now->tv_sec == tv_last->tv_sec && tv_now->tv_usec < tv_last->tv_usec)) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not get ticks: time running backwards\n"); } } while (0);
  return -1;
 } else {
  ticks = (float)(tv_now->tv_sec - 1 - tv_last->tv_sec) * 100.0
   + (float)((tv_now->tv_usec + 1000000 - tv_last->tv_usec) / 10000);
  do { if (g_verbose || (7 != 7)) { fprintf(stderr, "seconds since last update: %.2f\n", ticks / 100); } } while (0);
  if (ticks < (-0x7fffffff - 1)) {
   return (-0x7fffffff - 1);
  } else if (ticks > 0x7fffffff) {
   return 0x7fffffff;
  } else {
   return ticks;
  }
 }
}

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

variable_types: ticks float

return_type: int


decompiled_code:
int __fastcall dump_packet(__int64 a1)
{
bool v1; // zf
__int64 v2; // rbp
unsigned int v3; // ebx
int i; // eax
int result; // eax
__int64 v6; // rax
const char *v7; // r8
const char *v8; // rdx
__m128i v9; // [rsp+0h] [rbp-2068h] BYREF
char buf[48]; // [rsp+10h] [rbp-2058h] BYREF
char v11[8232]; // [rsp+40h] [rbp-2028h] BYREF

v1 = *(_QWORD *)(a1 + 2080) == 0LL;
v9 = _mm_loadu_si128((const __m128i *)(a1 + 12));
if ( !v1 )
{
v2 = 0LL;
v3 = 0;
for ( i = snprintf(v11, 0x2000uLL, "%02X", *(unsigned __int8 *)(a1 + 30));
;
i = snprintf(&v11[v3], 0x2000LL - (int)v3, " %02X", *(unsigned __int8 *)(a1 + v2 + 30)) )
{
v3 += i;
if ( v3 > 0x1FFF )
break;
if ( *(_QWORD *)(a1 + 2080) <= (unsigned __int64)++v2 )
break;
}
}
result = (unsigned int)inet_ntop(10, &v9, buf, 0x2Eu);
if ( g_verbose )
{
v6 = (unsigned __int16)_bswap_16(*(_WORD *)(a1 + 28));
if ( *(_DWORD *)(a1 + 2088) )
v7 = "to";
v8 = "received";
if ( *(_DWORD *)(a1 + 2088) )
v8 = "transmitted";
result = fprintf(stderr, "%s %u bytes %s %s:%d (%s)\n", v8, *(_QWORD *)(a1 + 2080), v7, buf, v6, v11);
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
bool v1; // zf
__int64 v2; // rbp
unsigned int v3; // ebx
int i; // eax
int result; // eax
__int64 v6; // rax
const char *v7; // r8
const char *v8; // rdx
__m128i v9; // [rsp+0h] [rbp-2068h] BYREF
char buf[48]; // [rsp+10h] [rbp-2058h] BYREF
char v11[8232]; // [rsp+40h] [rbp-2028h] BYREF

v1 = *(_QWORD *)(a1 + 2080) == 0LL;
v9 = _mm_loadu_si128((const __m128i *)(a1 + 12));
if ( !v1 )
{
v2 = 0LL;
v3 = 0;
for ( i = snprintf(v11, 0x2000uLL, "%02X", *(unsigned __int8 *)(a1 + 30));
;
i = snprintf(&v11[v3], 0x2000LL - (int)v3, " %02X", *(unsigned __int8 *)(a1 + v2 + 30)) )
{
v3 += i;
if ( v3 > 0x1FFF )
break;
if ( *(_QWORD *)(a1 + 2080) <= (unsigned __int64)++v2 )
break;
}
}
result = (unsigned int)inet_ntop(10, &v9, buf, 0x2Eu);
if ( g_verbose )
{
v6 = (unsigned __int16)func0(*(_WORD *)(a1 + 28));
if ( *(_DWORD *)(a1 + 2088) )
v7 = "to";
v8 = "received";
if ( *(_DWORD *)(a1 + 2088) )
v8 = "transmitted";
result = fprintf(stderr, "%s %u bytes %s %s:%d (%s)\n", v8, *(_QWORD *)(a1 + 2080), v7, buf, v6, v11);
}
return result;
}

original_code:
void dump_packet(const client_t *client)
{
 struct in6_addr client_addr;
 char straddr[46];
 char buffer[8192];
 int len;
 int i;
 client_addr = client->addr;
 len = 0;
 for (i = 0; i < client->size; i++) {
  len += snprintf(buffer + len, sizeof (buffer) - len,
   i ? " %02X" : "%02X", client->packet[i]);
  if (len >= sizeof (buffer)) {
   break;
  }
 }
 inet_ntop(10, &client_addr, straddr, sizeof(straddr));
 do { if (g_verbose || (7 != 7)) { fprintf(stderr, "%s %u bytes %s %s:%d (%s)\n", client->outgoing ? "transmitted" : "received", (int) client->size, client->outgoing ? "to" : "from", straddr, ntohs(client->port), buffer); } } while (0);
}

canonical_original_code:
void dump_packet(struct client_s *client)
{
 struct in6_addr client_addr;
 char straddr[46];
 char buffer[8192];
 int len;
 int i;
 client_addr = client->addr;
 len = 0;
 for (i = 0; i < client->size; i++) {
  len += snprintf(buffer + len, sizeof (buffer) - len,
   i ? " %02X" : "%02X", client->packet[i]);
  if (len >= sizeof (buffer)) {
   break;
  }
 }
 inet_ntop(10, &client_addr, straddr, sizeof(straddr));
 do { if (g_verbose || (7 != 7)) { fprintf(stderr, "%s %u bytes %s %s:%d (%s)\n", client->outgoing ? "transmitted" : "received", (int) client->size, client->outgoing ? "to" : "from", straddr, ntohs(client->port), buffer); } } while (0);
}

variable_types: struct client_s { long timestamp; int sockfd; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } addr; unsigned short port; unsigned char packet[2048]; unsigned long size; int outgoing; } *

variable_types:
straddr
char [46]

variable_types:
buffer
char [8192]

variable_types: len int

user_defined_types: struct client_s { long timestamp; int sockfd; struct in6_addr addr; unsigned short port; unsigned char packet[2048]; unsigned long size; int outgoing; }


decompiled_code:
char *__fastcall oid_ntoa(__int64 a1)
{
bool v1; // cc
__int64 v2; // rbp
int v3; // ebx

v1 = *(_WORD *)(a1 + 64) <= 0;
buffer_2[0] = 0;
if ( v1 )
return buffer_2;
v2 = 0LL;
v3 = 0;
do
{
v3 += snprintf(&buffer_2[v3], 162LL - v3, ".%d", *(unsigned int *)(a1 + 4 * v2));
if ( v3 > 161 )
break;
++v2;
}
while ( *(__int16 *)(a1 + 64) > (int)v2 );
return buffer_2;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1)
{
bool v1; // cc
__int64 v2; // rbp
int v3; // ebx

v1 = *(_WORD *)(a1 + 64) <= 0;
buffer_2[0] = 0;
if ( v1 )
return buffer_2;
v2 = 0LL;
v3 = 0;
do
{
v3 += snprintf(&buffer_2[v3], 162LL - v3, ".%d", *(unsigned int *)(a1 + 4 * v2));
if ( v3 > 161 )
break;
++v2;
}
while ( *(__int16 *)(a1 + 64) > (int)v2 );
return buffer_2;
}

original_code:
char *oid_ntoa(const oid_t *oid)
{
 static char buffer[16 * 10 + 2];
 int len;
 int i;
 buffer[0] = '\0';
 len = 0;
 for (i = 0; i < oid->subid_list_length; i++) {
  len += snprintf(buffer + len, sizeof (buffer) - len, ".%d", oid->subid_list[i]);
  if (len >= sizeof (buffer)) {
   break;
  }
 }
 return buffer;
}

canonical_original_code:
char *oid_ntoa(struct oid_s *oid)
{
 static char buffer[-1];
 int len;
 int i;
 buffer[0] = '\0';
 len = 0;
 for (i = 0; i < oid->subid_list_length; i++) {
  len += snprintf(buffer + len, sizeof (buffer) - len, ".%d", oid->subid_list[i]);
  if (len >= sizeof (buffer)) {
   break;
  }
 }
 return buffer;
}

variable_types: struct oid_s { unsigned int subid_list[16]; short subid_list_length; short encoded_length; } *

variable_types:
buffer
char [-1]

return_type: char *


decompiled_code:
void __fastcall dump_mib(__int64 a1, int a2)
{
unsigned int v2; // ebp
__int64 v3; // rbx
unsigned int v4; // er13
__int64 v5; // rdi
char *v6; // rax
__int64 v7; // rdx
__int16 v8[4116]; // [rsp+0h] [rbp-2028h] BYREF

if ( a2 > 0 )
{
v2 = 0;
v3 = a1 + 72;
do
{
while ( 1 )
{
if ( (unsigned int)snmp_element_as_string(v3, v8, 0x2000LL) == -1 )
v8[0] = 63;
if ( g_verbose )
break;
++v2;
v3 += 88LL;
if ( a2 == v2 )
return;
}
v4 = *(__int16 *)(v3 + 8);
v5 = v3 - 72;
v3 += 88LL;
v6 = oid_ntoa(v5);
v7 = v2++;
fprintf(stderr, "mib entry[%d]: oid='%s', max_length=%d, data='%s'\n", v7, v6, v4, (const char *)v8);
}
while ( a2 != v2 );
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2)
{
unsigned int v2; // ebp
__int64 v3; // rbx
unsigned int v4; // er13
__int64 v5; // rdi
char *v6; // rax
__int64 v7; // rdx
__int16 v8[4116]; // [rsp+0h] [rbp-2028h] BYREF

if ( a2 > 0 )
{
v2 = 0;
v3 = a1 + 72;
do
{
while ( 1 )
{
if ( (unsigned int)snmp_element_as_string(v3, v8, 0x2000LL) == -1 )
v8[0] = 63;
if ( g_verbose )
break;
++v2;
v3 += 88LL;
if ( a2 == v2 )
return;
}
v4 = *(__int16 *)(v3 + 8);
v5 = v3 - 72;
v3 += 88LL;
v6 = func6(v5);
v7 = v2++;
fprintf(stderr, "mib entry[%d]: oid='%s', max_length=%d, data='%s'\n", v7, v6, v4, (const char *)v8);
}
while ( a2 != v2 );
}
}

original_code:
void dump_mib(const value_t *value, int size)
{
 char buffer[8192];
 int i;
 for (i = 0; i < size; i++) {
  if (snmp_element_as_string(&value[i].data, buffer, sizeof (buffer)) == -1) {
   strcpy(buffer, "?");
  }
  do { if (g_verbose || (7 != 7)) { fprintf(stderr, "mib entry[%d]: oid='%s', max_length=%d, data='%s'\n", i, oid_ntoa(&value[i].oid), value[i].data.max_length, buffer); } } while (0);
 }
}

canonical_original_code:
void dump_mib(struct value_s *value, int size)
{
 char buffer[8192];
 int i;
 for (i = 0; i < size; i++) {
  if (snmp_element_as_string(&value[i].data, buffer, sizeof (buffer)) == -1) {
   strcpy(buffer, "?");
  }
  do { if (g_verbose || (7 != 7)) { fprintf(stderr, "mib entry[%d]: oid='%s', max_length=%d, data='%s'\n", i, oid_ntoa(&value[i].oid), value[i].data.max_length, buffer); } } while (0);
 }
}

variable_types: struct value_s { struct oid_s { unsigned int subid_list[16]; short subid_list_length; short encoded_length; } oid; struct data_s { unsigned char *buffer; short max_length; short encoded_length; } data; } *

variable_types: size int

user_defined_types: struct value_s { struct oid_s oid; struct data_s data; }


decompiled_code:
void __fastcall dump_response(unsigned int *a1)
{
unsigned int *v1; // rbp
signed int i; // ebx
char *v3; // rax
__int16 v4[1036]; // [rsp+0h] [rbp-818h] BYREF

if ( g_verbose )
fprintf(stderr, "response: status=%d, index=%d, nr_entries=%d\n", *a1, a1[1], a1[2818]);
v1 = a1 + 20;
for ( i = 0; (int)a1[2818] > i; v1 += 22 )
{
if ( (unsigned int)snmp_element_as_string(v1, v4, 2048LL) == -1 )
v4[0] = 63;
if ( g_verbose )
{
v3 = oid_ntoa((__int64)(v1 - 18));
fprintf(stderr, "response: entry[%d]='%s','%s'\n", (unsigned int)i, v3, (const char *)v4);
}
++i;
}
}

canonical_decompiled_code:
void __fastcall func8(unsigned int *a1)
{
unsigned int *v1; // rbp
signed int i; // ebx
char *v3; // rax
__int16 v4[1036]; // [rsp+0h] [rbp-818h] BYREF

if ( g_verbose )
fprintf(stderr, "response: status=%d, index=%d, nr_entries=%d\n", *a1, a1[1], a1[2818]);
v1 = a1 + 20;
for ( i = 0; (int)a1[2818] > i; v1 += 22 )
{
if ( (unsigned int)snmp_element_as_string(v1, v4, 2048LL) == -1 )
v4[0] = 63;
if ( g_verbose )
{
v3 = func6((__int64)(v1 - 18));
fprintf(stderr, "response: entry[%d]='%s','%s'\n", (unsigned int)i, v3, (const char *)v4);
}
++i;
}
}

original_code:
void dump_response(const response_t *response)
{
 char buffer[2048];
 int i;
 do { if (g_verbose || (7 != 7)) { fprintf(stderr, "response: status=%d, index=%d, nr_entries=%d\n", response->error_status, response->error_index, response->value_list_length); } } while (0);
 for (i = 0; i < response->value_list_length; i++) {
  if (snmp_element_as_string(&response->value_list[i].data, buffer, sizeof (buffer)) == -1) {
   strcpy(buffer, "?");
  }
  do { if (g_verbose || (7 != 7)) { fprintf(stderr, "response: entry[%d]='%s','%s'\n", i, oid_ntoa(&response->value_list[i].oid), buffer); } } while (0);
 }
}

canonical_original_code:
void dump_response(struct response_s *response)
{
 char buffer[2048];
 int i;
 do { if (g_verbose || (7 != 7)) { fprintf(stderr, "response: status=%d, index=%d, nr_entries=%d\n", response->error_status, response->error_index, response->value_list_length); } } while (0);
 for (i = 0; i < response->value_list_length; i++) {
  if (snmp_element_as_string(&response->value_list[i].data, buffer, sizeof (buffer)) == -1) {
   strcpy(buffer, "?");
  }
  do { if (g_verbose || (7 != 7)) { fprintf(stderr, "response: entry[%d]='%s','%s'\n", i, oid_ntoa(&response->value_list[i].oid), buffer); } } while (0);
 }
}

variable_types: struct response_s { int error_status; int error_index; struct value_s { struct oid_s { unsigned int subid_list[16]; short subid_list_length; short encoded_length; } oid; struct data_s { unsigned char *buffer; short max_length; short encoded_length; } data; } value_list[128]; int value_list_length; } *

variable_types:
buffer
char [2048]

user_defined_types: struct response_s { int error_status; int error_index; struct value_s value_list[128]; int value_list_length; }


decompiled_code:
int *__fastcall oid_aton(char *a1)
{
__int16 v1; // dx
char v2; // al
int v3; // eax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = 0;
word_960 = 0;
v2 = *a1;
endptr = a1;
if ( v2 )
{
while ( v2 == 46 )
{
if ( v1 > 15 )
break;
endptr = a1 + 1;
if ( !a1[1] )
break;
v3 = strtoul(a1 + 1, &endptr, 0);
a1 = endptr;
v1 = word_960 + 1;
oid_1[word_960] = v3;
word_960 = v1;
v2 = *a1;
if ( !*a1 )
{
if ( v1 > 1 && (unsigned int)(dword_924 + 40 * oid_1[0]) <= 0xFF )
return oid_1;
return 0LL;
}
}
}
return 0LL;
}

canonical_decompiled_code:
int *__fastcall func9(char *a1)
{
__int16 v1; // dx
char v2; // al
int v3; // eax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = 0;
word_960 = 0;
v2 = *a1;
endptr = a1;
if ( v2 )
{
while ( v2 == 46 )
{
if ( v1 > 15 )
break;
endptr = a1 + 1;
if ( !a1[1] )
break;
v3 = strtoul(a1 + 1, &endptr, 0);
a1 = endptr;
v1 = word_960 + 1;
oid_1[word_960] = v3;
word_960 = v1;
v2 = *a1;
if ( !*a1 )
{
if ( v1 > 1 && (unsigned int)(dword_924 + 40 * oid_1[0]) <= 0xFF )
return oid_1;
return 0LL;
}
}
}
return 0LL;
}

original_code:
oid_t *oid_aton(const char *str)
{
 static oid_t oid;
 char *ptr;
 oid.subid_list_length = 0;
 ptr = (char *)str;
 while (*ptr != '\0') {
  if (oid.subid_list_length >= 16) {
   return ((void *)0);
  }
  if (*ptr != '.') {
   return ((void *)0);
  }
  ptr++;
  if (*ptr == '\0') {
   return ((void *)0);
  }
  oid.subid_list[oid.subid_list_length++] = strtoul(ptr, &ptr, 0);
 }
 if (oid.subid_list_length < 2
  || (oid.subid_list[0] * 40 + oid.subid_list[1]) > 0xFF) {
  return ((void *)0);
 }
 return &oid;
}

canonical_original_code:
struct oid_s *oid_aton(char *str)
{
 static struct oid_s oid;
 char *ptr;
 oid.subid_list_length = 0;
 ptr = (char *)str;
 while (*ptr != '\0') {
  if (oid.subid_list_length >= 16) {
   return ((void *)0);
  }
  if (*ptr != '.') {
   return ((void *)0);
  }
  ptr++;
  if (*ptr == '\0') {
   return ((void *)0);
  }
  oid.subid_list[oid.subid_list_length++] = strtoul(ptr, &ptr, 0);
 }
 if (oid.subid_list_length < 2
  || (oid.subid_list[0] * 40 + oid.subid_list[1]) > 0xFF) {
  return ((void *)0);
 }
 return &oid;
}

variable_types:
str
char *

variable_types:
ptr
char *

return_type: struct oid_s { unsigned int subid_list[16]; short subid_list_length; short encoded_length; } *


original_code:
int oid_cmp(const oid_t *oid1, const oid_t *oid2)
{
 int subid1;
 int subid2;
 int i;
 for (i = 0; i < 16; i++) {
  subid1 = (oid1->subid_list_length > i) ? oid1->subid_list[i] : -1;
  subid2 = (oid2->subid_list_length > i) ? oid2->subid_list[i] : -1;
  if (subid1 == -1 && subid2 == -1) {
   return 0;
  } else if (subid1 > subid2) {
   return 1;
  } else if (subid1 < subid2) {
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int oid_cmp(struct oid_s *oid1, struct oid_s *oid2)
{
 int subid1;
 int subid2;
 int i;
 for (i = 0; i < 16; i++) {
  subid1 = (oid1->subid_list_length > i) ? oid1->subid_list[i] : -1;
  subid2 = (oid2->subid_list_length > i) ? oid2->subid_list[i] : -1;
  if (subid1 == -1 && subid2 == -1) {
   return 0;
  } else if (subid1 > subid2) {
   return 1;
  } else if (subid1 < subid2) {
   return -1;
  }
 }
 return 0;
}

user_defined_types: struct oid_s { unsigned int subid_list[16]; short subid_list_length; short encoded_length; }


split

decompiled_code:
__int64 __fastcall split(const char *a1, const char *a2, __int64 a3, int a4)
{
char *v6; // rax
__int64 v7; // r13
char v9[8232]; // [rsp+0h] [rbp-2028h] BYREF

snprintf(v9, 0x2000uLL, "%s", a1);
v6 = strtok(v9, a2);
if ( v6 )
{
v7 = 0LL;
do
{
while ( a4 <= (int)v7 )
{
v6 = strtok(0LL, a2);
if ( !v6 )
return (unsigned int)v7;
}
*(_QWORD *)(a3 + 8 * v7) = strdup(v6);
v7 = (int)v7 + 1;
v6 = strtok(0LL, a2);
}
while ( v6 );
}
else
{
LODWORD(v7) = 0;
}
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1, const char *a2, __int64 a3, int a4)
{
char *v6; // rax
__int64 v7; // r13
char v9[8232]; // [rsp+0h] [rbp-2028h] BYREF

snprintf(v9, 0x2000uLL, "%s", a1);
v6 = strtok(v9, a2);
if ( v6 )
{
v7 = 0LL;
do
{
while ( a4 <= (int)v7 )
{
v6 = strtok(0LL, a2);
if ( !v6 )
return (unsigned int)v7;
}
*(_QWORD *)(a3 + 8 * v7) = strdup(v6);
v7 = (int)v7 + 1;
v6 = strtok(0LL, a2);
}
while ( v6 );
}
else
{
LODWORD(v7) = 0;
}
return (unsigned int)v7;
}

original_code:
int split(const char *str, char *delim, char **list, int max_list_length)
{
 char buffer[8192];
 int list_length;
 char *ptr;
 snprintf(buffer, sizeof (buffer), "%s", str);
 list_length = 0;
 for (ptr = strtok(buffer, delim); ptr != ((void *)0); ptr = strtok(((void *)0), delim)) {
  if (list_length < max_list_length) {
   list[list_length++] = strdup(ptr);
  }
 }
 return list_length;
}

canonical_original_code:
int split(char *str, char *delim, char **list, int max_list_length)
{
 char buffer[8192];
 int list_length;
 char *ptr;
 snprintf(buffer, sizeof (buffer), "%s", str);
 list_length = 0;
 for (ptr = strtok(buffer, delim); ptr != ((void *)0); ptr = strtok(((void *)0), delim)) {
  if (list_length < max_list_length) {
   list[list_length++] = strdup(ptr);
  }
 }
 return list_length;
}

variable_types:
delim
char *

variable_types:
list
char **


decompiled_code:
int __fastcall get_demoinfo(int *a1)
{
int result; // eax
unsigned int v2; // eax

if ( !did_init_0 )
{
v2 = time(0LL);
srand(v2);
did_init_0 = 1;
}
*a1 = rand();
result = rand();
a1[1] = result;
return result;
}

canonical_decompiled_code:
int __fastcall func12(int *a1)
{
int result; // eax
unsigned int v2; // eax

if ( !did_init_0 )
{
v2 = time(0LL);
srand(v2);
did_init_0 = 1;
}
*a1 = rand();
result = rand();
a1[1] = result;
return result;
}

original_code:
void get_demoinfo(demoinfo_t *demoinfo)
{
 static int did_init = 0;
 if (did_init == 0) {
  srand(time(((void *)0)));
  did_init = 1;
 }
 demoinfo->random_value_1 = rand();
 demoinfo->random_value_2 = rand();
}

canonical_original_code:
void get_demoinfo(struct demoinfo_s *demoinfo)
{
 static int did_init = 0;
 if (did_init == 0) {
  srand(time(((void *)0)));
  did_init = 1;
 }
 demoinfo->random_value_1 = rand();
 demoinfo->random_value_2 = rand();
}

variable_types: struct demoinfo_s { unsigned int random_value_1; unsigned int random_value_2; } *


decompiled_code:
__int64 get_system_uptime()
{
int v0; // er8
__int64 result; // rax
char v2[136]; // [rsp+0h] [rbp-88h] BYREF

v0 = read_file("/proc/uptime", v2, 128LL);
result = 0xFFFFFFFFLL;
if ( v0 != -1 )
result = (unsigned int)(int)(atof(v2) * 100.0);
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // er8
__int64 result; // rax
char v2[136]; // [rsp+0h] [rbp-88h] BYREF

v0 = read_file("/proc/uptime", v2, 128LL);
result = 0xFFFFFFFFLL;
if ( v0 != -1 )
result = (unsigned int)(int)(atof(v2) * 100.0);
return result;
}

original_code:
unsigned int get_system_uptime(void)
{
 char buffer[128];
 if (read_file("/proc/uptime", buffer, sizeof (buffer)) != -1) {
  return (unsigned int)(atof(buffer) * 100);
 } else {
  return -1;
 }
}

canonical_original_code:
unsigned int get_system_uptime()
{
 char buffer[128];
 if (read_file("/proc/uptime", buffer, sizeof (buffer)) != -1) {
  return (unsigned int)(atof(buffer) * 100);
 } else {
  return -1;
 }
}

variable_types:
buffer
char [128]

return_type: unsigned int


decompiled_code:
__int64 get_process_uptime()
{
int v0; // edx
__int64 result; // rax

v0 = get_system_uptime();
result = (unsigned int)uptime_start_0;
if ( uptime_start_0 )
return (unsigned int)(v0 - uptime_start_0);
uptime_start_0 = v0;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // edx
__int64 result; // rax

v0 = func0();
result = (unsigned int)uptime_start_0;
if ( uptime_start_0 )
return (unsigned int)(v0 - uptime_start_0);
uptime_start_0 = v0;
return result;
}

original_code:
unsigned int get_process_uptime(void)
{
 static unsigned int uptime_start = 0;
 unsigned int uptime_now;
 uptime_now = get_system_uptime();
 if (uptime_start == 0) {
  uptime_start = uptime_now;
 }
 return uptime_now - uptime_start;
}

canonical_original_code:
unsigned int get_process_uptime()
{
 static unsigned int uptime_start = 0;
 unsigned int uptime_now;
 uptime_now = get_system_uptime();
 if (uptime_start == 0) {
  uptime_start = uptime_now;
 }
 return uptime_now - uptime_start;
}


decompiled_code:
char *__fastcall get_loadinfo(_DWORD *a1)
{
_DWORD *v1; // rbx
char *result; // rax
_DWORD *v3; // r12
const unsigned __int16 **v4; // rbp
const unsigned __int16 *v5; // rsi
__int64 v6; // rcx
const char *v7; // rdi
char *endptr; // [rsp+8h] [rbp-A0h] BYREF
char nptr[152]; // [rsp+10h] [rbp-98h] BYREF

v1 = a1;
result = (char *)read_file("/proc/loadavg", nptr, 128LL);
if ( (_DWORD)result == -1 )
{
*(_QWORD *)a1 = 0LL;
a1[2] = 0;
}
else
{
v3 = a1 + 3;
endptr = nptr;
v4 = _ctype_b_loc();
for ( result = nptr; ; result = endptr )
{
v5 = *v4;
while ( 1 )
{
v6 = *result;
v7 = result++;
if ( (v5[v6] & 0x2000) == 0 )
break;
endptr = result;
}
if ( (_BYTE)v6 )
{
result = (char *)(unsigned int)(int)(strtod(v7, &endptr) * 100.0);
*v1 = (_DWORD)result;
}
if ( v3 == ++v1 )
break;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(_DWORD *a1)
{
_DWORD *v1; // rbx
char *result; // rax
_DWORD *v3; // r12
const unsigned __int16 **v4; // rbp
const unsigned __int16 *v5; // rsi
__int64 v6; // rcx
const char *v7; // rdi
char *endptr; // [rsp+8h] [rbp-A0h] BYREF
char nptr[152]; // [rsp+10h] [rbp-98h] BYREF

v1 = a1;
result = (char *)read_file("/proc/loadavg", nptr, 128LL);
if ( (_DWORD)result == -1 )
{
*(_QWORD *)a1 = 0LL;
a1[2] = 0;
}
else
{
v3 = a1 + 3;
endptr = nptr;
v4 = _ctype_b_loc();
for ( result = nptr; ; result = endptr )
{
v5 = *v4;
while ( 1 )
{
v6 = *result;
v7 = result++;
if ( (v5[v6] & 0x2000) == 0 )
break;
endptr = result;
}
if ( (_BYTE)v6 )
{
result = (char *)(unsigned int)(int)(strtod(v7, &endptr) * 100.0);
*v1 = (_DWORD)result;
}
if ( v3 == ++v1 )
break;
}
}
return result;
}

original_code:
void get_loadinfo(loadinfo_t *loadinfo)
{
 char buffer[128];
 char *ptr;
 int i;
 if (read_file("/proc/loadavg", buffer, sizeof (buffer)) != -1) {
  ptr = buffer;
  for (i = 0; i < 3; i++) {
   while (((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short int) _ISspace)) {
    ptr++;
   }
   if (*ptr != '\0') {
    loadinfo->avg[i] = strtod(ptr, &ptr) * 100;
   }
  }
 } else {
  memset(loadinfo, 0, sizeof (loadinfo_t));
 }
}

canonical_original_code:
void get_loadinfo(struct loadinfo_s *loadinfo)
{
 char buffer[128];
 char *ptr;
 int i;
 if (read_file("/proc/loadavg", buffer, sizeof (buffer)) != -1) {
  ptr = buffer;
  for (i = 0; i < 3; i++) {
   while (((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short) _ISspace)) {
    ptr++;
   }
   if (*ptr != '\0') {
    loadinfo->avg[i] = strtod(ptr, &ptr) * 100;
   }
  }
 } else {
  memset(loadinfo, 0, sizeof (loadinfo_t));
 }
}

variable_types: struct loadinfo_s { unsigned int avg[3]; } *

variable_types: i int


decompiled_code:
__int64 __fastcall get_meminfo(__int64 a1)
{
__int64 result; // rax
_BYTE v2[8200]; // [rsp+0h] [rbp-2008h] BYREF

result = read_file("/proc/meminfo", v2, 0x2000LL);
if ( (_DWORD)result == -1 )
{
*(_DWORD *)(a1 + 16) = 0;
*(_OWORD *)a1 = 0LL;
}
else
{
*(_DWORD *)a1 = read_value(v2, "MemTotal:");
*(_DWORD *)(a1 + 4) = read_value(v2, "MemFree:");
*(_DWORD *)(a1 + 8) = read_value(v2, "MemShared:");
*(_DWORD *)(a1 + 12) = read_value(v2, "Buffers:");
result = read_value(v2, "Cached:");
*(_DWORD *)(a1 + 16) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
_BYTE v2[8200]; // [rsp+0h] [rbp-2008h] BYREF

result = read_file("/proc/meminfo", v2, 0x2000LL);
if ( (_DWORD)result == -1 )
{
*(_DWORD *)(a1 + 16) = 0;
*(_OWORD *)a1 = 0LL;
}
else
{
*(_DWORD *)a1 = read_value(v2, "MemTotal:");
*(_DWORD *)(a1 + 4) = read_value(v2, "MemFree:");
*(_DWORD *)(a1 + 8) = read_value(v2, "MemShared:");
*(_DWORD *)(a1 + 12) = read_value(v2, "Buffers:");
result = read_value(v2, "Cached:");
*(_DWORD *)(a1 + 16) = result;
}
return result;
}

original_code:
void get_meminfo(meminfo_t *meminfo)
{
 char buffer[8192];
 if (read_file("/proc/meminfo", buffer, sizeof (buffer)) != -1) {
  meminfo->total = read_value(buffer, "MemTotal:");
  meminfo->free = read_value(buffer, "MemFree:");
  meminfo->shared = read_value(buffer, "MemShared:");
  meminfo->buffers = read_value(buffer, "Buffers:");
  meminfo->cached = read_value(buffer, "Cached:");
 } else {
  memset(meminfo, 0, sizeof (meminfo_t));
 }
}

canonical_original_code:
void get_meminfo(struct meminfo_s *meminfo)
{
 char buffer[8192];
 if (read_file("/proc/meminfo", buffer, sizeof (buffer)) != -1) {
  meminfo->total = read_value(buffer, "MemTotal:");
  meminfo->free = read_value(buffer, "MemFree:");
  meminfo->shared = read_value(buffer, "MemShared:");
  meminfo->buffers = read_value(buffer, "Buffers:");
  meminfo->cached = read_value(buffer, "Cached:");
 } else {
  memset(meminfo, 0, sizeof (meminfo_t));
 }
}

variable_types: struct meminfo_s { unsigned int total; unsigned int free; unsigned int shared; unsigned int buffers; unsigned int cached; } *


decompiled_code:
__int64 __fastcall get_cpuinfo(__int64 a1)
{
__int64 result; // rax
__int64 v2[2]; // [rsp+0h] [rbp-2018h] BYREF
char v3[8200]; // [rsp+10h] [rbp-2008h] BYREF

result = read_file("/proc/stat", v3, 0x2000LL);
if ( (_DWORD)result == -1 )
{
*(_QWORD *)(a1 + 16) = 0LL;
*(_OWORD *)a1 = 0LL;
}
else
{
read_values(v3, "cpu", v2, 4LL);
*(_QWORD *)a1 = v2[0];
*(_QWORD *)(a1 + 8) = v2[1];
*(_DWORD *)(a1 + 16) = read_value(v3, "intr");
result = read_value(v3, "ctxt");
*(_DWORD *)(a1 + 20) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax
__int64 v2[2]; // [rsp+0h] [rbp-2018h] BYREF
char v3[8200]; // [rsp+10h] [rbp-2008h] BYREF

result = read_file("/proc/stat", v3, 0x2000LL);
if ( (_DWORD)result == -1 )
{
*(_QWORD *)(a1 + 16) = 0LL;
*(_OWORD *)a1 = 0LL;
}
else
{
read_values(v3, "cpu", v2, 4LL);
*(_QWORD *)a1 = v2[0];
*(_QWORD *)(a1 + 8) = v2[1];
*(_DWORD *)(a1 + 16) = read_value(v3, "intr");
result = read_value(v3, "ctxt");
*(_DWORD *)(a1 + 20) = result;
}
return result;
}

original_code:
void get_cpuinfo(cpuinfo_t *cpuinfo)
{
 char buffer[8192];
 unsigned int values[4];
 if (read_file("/proc/stat", buffer, sizeof (buffer)) != -1) {
  read_values(buffer, "cpu", values, 4);
  cpuinfo->user = values[0];
  cpuinfo->nice = values[1];
  cpuinfo->system = values[2];
  cpuinfo->idle = values[3];
  cpuinfo->irqs = read_value(buffer, "intr");
  cpuinfo->cntxts = read_value(buffer, "ctxt");
 } else {
  memset(cpuinfo, 0, sizeof (cpuinfo_t));
 }
}

canonical_original_code:
void get_cpuinfo(struct cpuinfo_s *cpuinfo)
{
 char buffer[8192];
 unsigned int values[4];
 if (read_file("/proc/stat", buffer, sizeof (buffer)) != -1) {
  read_values(buffer, "cpu", values, 4);
  cpuinfo->user = values[0];
  cpuinfo->nice = values[1];
  cpuinfo->system = values[2];
  cpuinfo->idle = values[3];
  cpuinfo->irqs = read_value(buffer, "intr");
  cpuinfo->cntxts = read_value(buffer, "ctxt");
 } else {
  memset(cpuinfo, 0, sizeof (cpuinfo_t));
 }
}

variable_types: struct cpuinfo_s { unsigned int user; unsigned int nice; unsigned int system; unsigned int idle; unsigned int irqs; unsigned int cntxts; } *

variable_types:
buffer
char [8192]

variable_types:
values
unsigned int [4]


decompiled_code:
int __fastcall get_diskinfo(_DWORD *a1)
{
int result; // eax
__int64 i; // rbp
__fsblkcnt_t v4; // rax
float v5; // xmm2_4
float v6; // xmm1_4
__fsblkcnt_t v7; // rdx
float v8; // xmm0_4
__int64 v9; // rax
float v10; // xmm0_4
float v11; // xmm2_4
__fsfilcnt_t v12; // rax
float v13; // xmm0_4
struct statfs v14; // [rsp-8h] [rbp-98h] BYREF

result = g_disk_list_length;
if ( g_disk_list_length > 0 )
{
for ( i = 0LL; g_disk_list_length > (int)i; ++i )
{
result = statfs(*((const char **)&g_disk_list + i), &v14);
if ( result == -1 )
{
*a1 = 0;
a1[4] = 0;
a1[8] = 0;
a1[12] = 0;
}
else
{
v4 = v14.f_blocks;
if ( (v14.f_blocks & 0x8000000000000000LL) != 0LL )
v5 = (float)(int)(v14.f_blocks & 1 | (v14.f_blocks >> 1))
+ (float)(int)(v14.f_blocks & 1 | (v14.f_blocks >> 1));
else
v5 = (float)SLODWORD(v14.f_blocks);
v6 = (float)SLODWORD(v14.f_bsize);
*a1 = (int)(float)((float)(v5 * (float)SLODWORD(v14.f_bsize)) * 0.0009765625);
v7 = v14.f_bfree;
if ( (v14.f_bfree & 0x8000000000000000LL) != 0LL )
v8 = (float)(int)(v14.f_bfree & 1 | (v14.f_bfree >> 1)) + (float)(int)(v14.f_bfree & 1 | (v14.f_bfree >> 1));
else
v8 = (float)SLODWORD(v14.f_bfree);
a1[4] = (int)(float)((float)(v8 * v6) * 0.0009765625);
v9 = v4 - v7;
if ( v9 < 0 )
v10 = (float)(v9 & 1 | (unsigned int)((unsigned __int64)v9 >> 1))
+ (float)(v9 & 1 | (unsigned int)((unsigned __int64)v9 >> 1));
else
v10 = (float)(int)v9;
a1[8] = (int)(float)((float)(v6 * v10) * 0.0009765625);
a1[12] = (int)(float)((float)((float)((float)(v10 * 100.0) + v5) - 1.0) / v5);
result = v14.f_files;
if ( v14.f_files )
{
if ( (v14.f_files & 0x8000000000000000LL) != 0LL )
v11 = (float)(int)(v14.f_files & 1 | (v14.f_files >> 1))
+ (float)(int)(v14.f_files & 1 | (v14.f_files >> 1));
else
v11 = (float)SLODWORD(v14.f_files);
v12 = v14.f_files - v14.f_ffree;
if ( (__int64)(v14.f_files - v14.f_ffree) < 0 )
v13 = (float)(int)(v12 & 1 | (v12 >> 1)) + (float)(int)(v12 & 1 | (v12 >> 1));
else
v13 = (float)(int)v12;
result = (int)(float)((float)((float)((float)(v13 * 100.0) + v11) - 1.0) / v11);
a1[16] = result;
goto LABEL_16;
}
}
a1[16] = 0;
LABEL_16:
++a1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(_DWORD *a1)
{
int result; // eax
__int64 i; // rbp
__fsblkcnt_t v4; // rax
float v5; // xmm2_4
float v6; // xmm1_4
__fsblkcnt_t v7; // rdx
float v8; // xmm0_4
__int64 v9; // rax
float v10; // xmm0_4
float v11; // xmm2_4
__fsfilcnt_t v12; // rax
float v13; // xmm0_4
struct statfs v14; // [rsp-8h] [rbp-98h] BYREF

result = g_disk_list_length;
if ( g_disk_list_length > 0 )
{
for ( i = 0LL; g_disk_list_length > (int)i; ++i )
{
result = statfs(*((const char **)&g_disk_list + i), &v14);
if ( result == -1 )
{
*a1 = 0;
a1[4] = 0;
a1[8] = 0;
a1[12] = 0;
}
else
{
v4 = v14.f_blocks;
if ( (v14.f_blocks & 0x8000000000000000LL) != 0LL )
v5 = (float)(int)(v14.f_blocks & 1 | (v14.f_blocks >> 1))
+ (float)(int)(v14.f_blocks & 1 | (v14.f_blocks >> 1));
else
v5 = (float)SLODWORD(v14.f_blocks);
v6 = (float)SLODWORD(v14.f_bsize);
*a1 = (int)(float)((float)(v5 * (float)SLODWORD(v14.f_bsize)) * 0.0009765625);
v7 = v14.f_bfree;
if ( (v14.f_bfree & 0x8000000000000000LL) != 0LL )
v8 = (float)(int)(v14.f_bfree & 1 | (v14.f_bfree >> 1)) + (float)(int)(v14.f_bfree & 1 | (v14.f_bfree >> 1));
else
v8 = (float)SLODWORD(v14.f_bfree);
a1[4] = (int)(float)((float)(v8 * v6) * 0.0009765625);
v9 = v4 - v7;
if ( v9 < 0 )
v10 = (float)(v9 & 1 | (unsigned int)((unsigned __int64)v9 >> 1))
+ (float)(v9 & 1 | (unsigned int)((unsigned __int64)v9 >> 1));
else
v10 = (float)(int)v9;
a1[8] = (int)(float)((float)(v6 * v10) * 0.0009765625);
a1[12] = (int)(float)((float)((float)((float)(v10 * 100.0) + v5) - 1.0) / v5);
result = v14.f_files;
if ( v14.f_files )
{
if ( (v14.f_files & 0x8000000000000000LL) != 0LL )
v11 = (float)(int)(v14.f_files & 1 | (v14.f_files >> 1))
+ (float)(int)(v14.f_files & 1 | (v14.f_files >> 1));
else
v11 = (float)SLODWORD(v14.f_files);
v12 = v14.f_files - v14.f_ffree;
if ( (__int64)(v14.f_files - v14.f_ffree) < 0 )
v13 = (float)(int)(v12 & 1 | (v12 >> 1)) + (float)(int)(v12 & 1 | (v12 >> 1));
else
v13 = (float)(int)v12;
result = (int)(float)((float)((float)((float)(v13 * 100.0) + v11) - 1.0) / v11);
a1[16] = result;
goto LABEL_16;
}
}
a1[16] = 0;
LABEL_16:
++a1;
}
}
return result;
}

original_code:
void get_diskinfo(diskinfo_t *diskinfo)
{
 struct statfs fs;
 int i;
 for (i = 0; i < g_disk_list_length; i++) {
  if (statfs(g_disk_list[i], &fs) != -1) {
   diskinfo->total[i] = ((float)fs.f_blocks * fs.f_bsize) / 1024;
   diskinfo->free[i] = ((float)fs.f_bfree * fs.f_bsize) / 1024;
   diskinfo->used[i] = ((float)(fs.f_blocks - fs.f_bfree) * fs.f_bsize) / 1024;
   diskinfo->blocks_used_percent[i] = ((float)(fs.f_blocks - fs.f_bfree)
    * 100 + fs.f_blocks - 1) / fs.f_blocks;
   if (fs.f_files > 0) {
    diskinfo->inodes_used_percent[i] = ((float)(fs.f_files - fs.f_ffree)
     * 100 + fs.f_files - 1) / fs.f_files;
   } else {
    diskinfo->inodes_used_percent[i] = 0;
   }
  } else {
   diskinfo->total[i] = 0;
   diskinfo->free[i] = 0;
   diskinfo->used[i] = 0;
   diskinfo->blocks_used_percent[i] = 0;
   diskinfo->inodes_used_percent[i] = 0;
  }
 }
}

canonical_original_code:
void get_diskinfo(struct diskinfo_s *diskinfo)
{
 struct statfs fs;
 int i;
 for (i = 0; i < g_disk_list_length; i++) {
  if (statfs(g_disk_list[i], &fs) != -1) {
   diskinfo->total[i] = ((float)fs.f_blocks * fs.f_bsize) / 1024;
   diskinfo->free[i] = ((float)fs.f_bfree * fs.f_bsize) / 1024;
   diskinfo->used[i] = ((float)(fs.f_blocks - fs.f_bfree) * fs.f_bsize) / 1024;
   diskinfo->blocks_used_percent[i] = ((float)(fs.f_blocks - fs.f_bfree)
    * 100 + fs.f_blocks - 1) / fs.f_blocks;
   if (fs.f_files > 0) {
    diskinfo->inodes_used_percent[i] = ((float)(fs.f_files - fs.f_ffree)
     * 100 + fs.f_files - 1) / fs.f_files;
   } else {
    diskinfo->inodes_used_percent[i] = 0;
   }
  } else {
   diskinfo->total[i] = 0;
   diskinfo->free[i] = 0;
   diskinfo->used[i] = 0;
   diskinfo->blocks_used_percent[i] = 0;
   diskinfo->inodes_used_percent[i] = 0;
  }
 }
}

variable_types: struct diskinfo_s { unsigned int total[4]; unsigned int free[4]; unsigned int used[4]; unsigned int blocks_used_percent[4]; unsigned int inodes_used_percent[4]; } *

variable_types: struct statfs { long f_type; long f_bsize; unsigned long f_blocks; unsigned long f_bfree; unsigned long f_bavail; unsigned long f_files; unsigned long f_ffree; struct __fsid_t { int __val[2]; } f_fsid; long f_namelen; long f_frsize; long f_flags; long f_spare[4]; }

user_defined_types: struct statfs { long f_type; long f_bsize; unsigned long f_blocks; unsigned long f_bfree; unsigned long f_bavail; unsigned long f_files; unsigned long f_ffree; struct __fsid_t f_fsid; long f_namelen; long f_frsize; long f_flags; long f_spare[4]; }


original_code:
void get_netinfo(netinfo_t *netinfo)
{
 struct ifreq ifreq;
 char buffer[8192];
 char name[16];
 unsigned int values[16];
 int fd;
 int i;
 if (read_file("/proc/net/dev", buffer, sizeof (buffer)) == -1) {
  buffer[0] = '\0';
 }
 fd = socket(2, SOCK_DGRAM, 0);
 for (i = 0; i < g_interface_list_length; i++) {
  snprintf(ifreq.ifr_ifrn.ifrn_name, sizeof (ifreq.ifr_ifrn.ifrn_name), "%s", g_interface_list[i]);
  if (fd != -1 && ioctl(fd, 0x8913, &ifreq) != -1) {
   if (ifreq.ifr_ifru.ifru_flags & IFF_UP) {
    netinfo->status[i] = (ifreq.ifr_ifru.ifru_flags & IFF_RUNNING) ? 1 : 7;
   } else {
    netinfo->status[i] = 2;
   }
  } else {
   netinfo->status[i] = 4;
  }
  if (buffer[0] != '\0') {
   snprintf(name, sizeof (name), "%s:", g_interface_list[i]);
   read_values(buffer, name, values, 16);
  } else {
   memset(values, 0, sizeof (values));
  }
  netinfo->rx_bytes[i] = values[0];
  netinfo->rx_packets[i] = values[1];
  netinfo->rx_errors[i] = values[2];
  netinfo->rx_drops[i] = values[3];
  netinfo->tx_bytes[i] = values[8];
  netinfo->tx_packets[i] = values[9];
  netinfo->tx_errors[i] = values[10];
  netinfo->tx_drops[i] = values[11];
 }
 if (fd != -1) {
  close(fd);
 }
}

canonical_original_code:
void get_netinfo(struct netinfo_s *netinfo)
{
 struct ifreq ifreq;
 char buffer[8192];
 char name[16];
 unsigned int values[16];
 int fd;
 int i;
 if (read_file("/proc/net/dev", buffer, sizeof (buffer)) == -1) {
  buffer[0] = '\0';
 }
 fd = socket(2, SOCK_DGRAM, 0);
 for (i = 0; i < g_interface_list_length; i++) {
  snprintf(ifreq.ifr_ifrn.ifrn_name, sizeof (ifreq.ifr_ifrn.ifrn_name), "%s", g_interface_list[i]);
  if (fd != -1 && ioctl(fd, 0x8913, &ifreq) != -1) {
   if (ifreq.ifr_ifru.ifru_flags & IFF_UP) {
    netinfo->status[i] = (ifreq.ifr_ifru.ifru_flags & IFF_RUNNING) ? 1 : 7;
   } else {
    netinfo->status[i] = 2;
   }
  } else {
   netinfo->status[i] = 4;
  }
  if (buffer[0] != '\0') {
   snprintf(name, sizeof (name), "%s:", g_interface_list[i]);
   read_values(buffer, name, values, 16);
  } else {
   memset(values, 0, sizeof (values));
  }
  netinfo->rx_bytes[i] = values[0];
  netinfo->rx_packets[i] = values[1];
  netinfo->rx_errors[i] = values[2];
  netinfo->rx_drops[i] = values[3];
  netinfo->tx_bytes[i] = values[8];
  netinfo->tx_packets[i] = values[9];
  netinfo->tx_errors[i] = values[10];
  netinfo->tx_drops[i] = values[11];
 }
 if (fd != -1) {
  close(fd);
 }
}

variable_types: struct netinfo_s { unsigned int status[4]; unsigned int rx_bytes[4]; unsigned int rx_packets[4]; unsigned int rx_errors[4]; unsigned int rx_drops[4]; unsigned int tx_bytes[4]; unsigned int tx_packets[4]; unsigned int tx_errors[4]; unsigned int tx_drops[4]; } *

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

variable_types:
name
char [16]

variable_types:
values
unsigned int [16]

variable_types: fd int

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


decompiled_code:
const char *mem_init()
{
const char *result; // rax

mem_brk = (__int64)&heap;
result = "Invalid argument, incr=[%d] should > 0\n";
mem_max_addr = (__int64)"Invalid argument, incr=[%d] should > 0\n";
return result;
}

canonical_decompiled_code:
const char *func0()
{
const char *result; // rax

mem_brk = (__int64)&heap;
result = "Invalid argument, incr=[%d] should > 0\n";
mem_max_addr = (__int64)"Invalid argument, incr=[%d] should > 0\n";
return result;
}

original_code:
void mem_init()
{
    mem_brk = heap;
    mem_max_addr = heap + (20*(1<<20));
}


decompiled_code:
void mem_deinit()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void mem_deinit()
{
}

canonical_original_code:
void mem_deinit()
{
}


decompiled_code:
__int64 __fastcall mem_sbrk(int a1)
{
__int64 result; // rax
unsigned __int64 v2; // rdi

if ( a1 <= 0 )
{
fprintf(stderr, "Invalid argument, incr=[%d] should > 0\n", (unsigned int)a1);
result = 0LL;
}
else
{
result = mem_brk;
v2 = mem_brk + a1;
if ( v2 >= mem_max_addr )
result = 0LL;
else
mem_brk = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 result; // rax
unsigned __int64 v2; // rdi

if ( a1 <= 0 )
{
fprintf(stderr, "Invalid argument, incr=[%d] should > 0\n", (unsigned int)a1);
result = 0LL;
}
else
{
result = mem_brk;
v2 = mem_brk + a1;
if ( v2 >= mem_max_addr )
result = 0LL;
else
mem_brk = v2;
}
return result;
}

original_code:
void * mem_sbrk(int incr)
{
    if (incr <= 0) {
        fprintf (stderr, "Invalid argument, incr=[%d] should > 0\n",
                 incr);
        return ((void *)0);
    }
    char * old_brk = mem_brk;
    if (incr + mem_brk >= mem_max_addr) {
        return ((void *)0);
    }
    mem_brk += incr;
    return (void*)old_brk;
}

canonical_original_code:
void *mem_sbrk(int incr)
{
    if (incr <= 0) {
        fprintf (stderr, "Invalid argument, incr=[%d] should > 0\n",
                 incr);
        return ((void *)0);
    }
    char *old_brk = mem_brk;
    if (incr + mem_brk >= mem_max_addr) {
        return ((void *)0);
    }
    mem_brk += incr;
    return (void *)old_brk;
}

variable_types: incr int

return_type: void *


decompiled_code:
void mem_reset_brk()
{
mem_brk = (__int64)&heap;
}

canonical_decompiled_code:
void func3()
{
mem_brk = (__int64)&heap;
}

original_code:
void mem_reset_brk()
{
    mem_brk = heap;
}


decompiled_code:
void *mem_heap_low()
{
return &heap;
}

canonical_decompiled_code:
void *func4()
{
return &heap;
}

original_code:
void *mem_heap_low()
{
    return (void*)heap;
}

canonical_original_code:
void *mem_heap_low()
{
    return (void *)heap;
}


decompiled_code:
__int64 mem_heap_high()
{
return mem_brk - 1;
}

canonical_decompiled_code:
__int64 func5()
{
return mem_brk - 1;
}

original_code:
void *mem_heap_high()
{
    return (void*)(mem_brk - 1);
}

canonical_original_code:
void *mem_heap_high()
{
    return (void *)(mem_brk - 1);
}


decompiled_code:
__int64 mem_getheapsize()
{
return mem_brk - (_QWORD)&heap;
}

canonical_decompiled_code:
__int64 func6()
{
return mem_brk - (_QWORD)&heap;
}

original_code:
size_t mem_getheapsize()
{
    return (size_t)(mem_brk - heap);
}

canonical_original_code:
unsigned long mem_getheapsize()
{
    return (unsigned long)(mem_brk - heap);
}

return_type: unsigned long


decompiled_code:
__int64 mem_getpagesize()
{
return getpagesize();
}

canonical_decompiled_code:
__int64 func7()
{
return getpagesize();
}

original_code:
size_t mem_getpagesize()
{
    return getpagesize();
}

canonical_original_code:
unsigned long mem_getpagesize()
{
    return getpagesize();
}


main

canonical_name: main

original_code:
int main()
{
   int ret = mm_init();
   if (ret == -1) {
        printf("init error");
        return -1;
   }
   char * p = (char*)mm_malloc(100);
   memcpy(p, "helloworld", 100);
   printf("%s", p);
}

canonical_original_code:
int main()
{
   int ret = mm_init();
   if (ret == -1) {
        printf("init error");
        return -1;
   }
   char *p = (char*)mm_malloc(100);
   memcpy(p, "helloworld", 100);
   printf("%s", p);
}

variable_types: ret int

variable_types:
p
char *


coalesce

decompiled_code:
__int64 __fastcall coalesce(_QWORD *a1)
{
unsigned __int64 v2; // r8
__int64 v3; // rax
unsigned __int64 v4; // rdi
__int64 v5; // rdx
unsigned __int64 v6; // rsi
unsigned __int64 v7; // rsi
__int64 v8; // rcx
unsigned __int64 v10; // rsi
__int64 v11; // rcx
__int64 v12; // rcx
__int64 v13; // r9
__int64 v14; // rcx
unsigned __int64 v15; // rsi
__int64 v16; // r9

if ( !a1 )
return 0LL;
v2 = *(a1 - 1) & 0xFFFFFFFFFFFFFFF8LL;
v3 = *(_QWORD *)((char *)a1 - 4LL - v2);
v4 = *(_QWORD *)((char *)a1 - 4) & 0xFFFFFFFFFFFFFFF8LL;
v5 = *(_QWORD *)((char *)a1 + v4 - 4);
if ( ((unsigned __int8)v5 & (unsigned __int8)v3 & 1) != 0 )
{
LABEL_6:
insert_free_block(a1);
return v8;
}
if ( ((unsigned __int8)v5 & (unsigned __int8)~(_BYTE)v3 & 1) != 0 )
{
v15 = (v3 & 0xFFFFFFFFFFFFFFF8LL) + v4;
remove_free_block((_QWORD *)((char *)a1 - v2));
*(_QWORD *)(v12 + v16 - (*(_QWORD *)(v12 - 8) & 0xFFFFFFFFFFFFFFF8LL)) = v15;
*(_QWORD *)(v12 + (*(_QWORD *)(v12 - 4) & 0xFFFFFFFFFFFFFFF8LL) - 8) = v15;
}
else
{
v6 = v5 & 0xFFFFFFFFFFFFFFF8LL;
if ( ((unsigned __int8)v3 & (unsigned __int8)~(_BYTE)v5 & 1) != 0 )
{
v7 = v4 + v6;
remove_free_block((_QWORD *)((char *)a1 + v4));
*(_QWORD *)((char *)a1 - 4) = v7;
*(_QWORD *)((char *)a1 + v7 - 8) = v7;
goto LABEL_6;
}
v10 = v4 + (v3 & 0xFFFFFFFFFFFFFFF8LL) + v6;
remove_free_block((_QWORD *)((char *)a1 - v2));
remove_free_block((__int64 *)(v11 + (*(_QWORD *)(v11 - 4) & 0xFFFFFFFFFFFFFFF8LL)));
*(_QWORD *)(v12 + v13 - (*(_QWORD *)(v12 - 8) & 0xFFFFFFFFFFFFFFF8LL)) = v10;
*(_QWORD *)((*(_QWORD *)(v12 + (*(_QWORD *)(v12 - 4) & 0xFFFFFFFFFFFFFFF8LL) - 4) & 0xFFFFFFFFFFFFFFF8LL)
+ v12
+ (*(_QWORD *)(v12 - 4) & 0xFFFFFFFFFFFFFFF8LL)
- 8) = v10;
}
insert_free_block((_QWORD *)(v12 - (*(_QWORD *)(v12 - 8) & 0xFFFFFFFFFFFFFFF8LL)));
return v14 - (*(_QWORD *)(v14 - 8) & 0xFFFFFFFFFFFFFFF8LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
unsigned __int64 v2; // r8
__int64 v3; // rax
unsigned __int64 v4; // rdi
__int64 v5; // rdx
unsigned __int64 v6; // rsi
unsigned __int64 v7; // rsi
__int64 v8; // rcx
unsigned __int64 v10; // rsi
__int64 v11; // rcx
__int64 v12; // rcx
__int64 v13; // r9
__int64 v14; // rcx
unsigned __int64 v15; // rsi
__int64 v16; // r9

if ( !a1 )
return 0LL;
v2 = *(a1 - 1) & 0xFFFFFFFFFFFFFFF8LL;
v3 = *(_QWORD *)((char *)a1 - 4LL - v2);
v4 = *(_QWORD *)((char *)a1 - 4) & 0xFFFFFFFFFFFFFFF8LL;
v5 = *(_QWORD *)((char *)a1 + v4 - 4);
if ( ((unsigned __int8)v5 & (unsigned __int8)v3 & 1) != 0 )
{
LABEL_6:
func0(a1);
return v8;
}
if ( ((unsigned __int8)v5 & (unsigned __int8)~(_BYTE)v3 & 1) != 0 )
{
v15 = (v3 & 0xFFFFFFFFFFFFFFF8LL) + v4;
func1((_QWORD *)((char *)a1 - v2));
*(_QWORD *)(v12 + v16 - (*(_QWORD *)(v12 - 8) & 0xFFFFFFFFFFFFFFF8LL)) = v15;
*(_QWORD *)(v12 + (*(_QWORD *)(v12 - 4) & 0xFFFFFFFFFFFFFFF8LL) - 8) = v15;
}
else
{
v6 = v5 & 0xFFFFFFFFFFFFFFF8LL;
if ( ((unsigned __int8)v3 & (unsigned __int8)~(_BYTE)v5 & 1) != 0 )
{
v7 = v4 + v6;
func1((_QWORD *)((char *)a1 + v4));
*(_QWORD *)((char *)a1 - 4) = v7;
*(_QWORD *)((char *)a1 + v7 - 8) = v7;
goto LABEL_6;
}
v10 = v4 + (v3 & 0xFFFFFFFFFFFFFFF8LL) + v6;
func1((_QWORD *)((char *)a1 - v2));
func1((__int64 *)(v11 + (*(_QWORD *)(v11 - 4) & 0xFFFFFFFFFFFFFFF8LL)));
*(_QWORD *)(v12 + v13 - (*(_QWORD *)(v12 - 8) & 0xFFFFFFFFFFFFFFF8LL)) = v10;
*(_QWORD *)((*(_QWORD *)(v12 + (*(_QWORD *)(v12 - 4) & 0xFFFFFFFFFFFFFFF8LL) - 4) & 0xFFFFFFFFFFFFFFF8LL)
+ v12
+ (*(_QWORD *)(v12 - 4) & 0xFFFFFFFFFFFFFFF8LL)
- 8) = v10;
}
func0((_QWORD *)(v12 - (*(_QWORD *)(v12 - 8) & 0xFFFFFFFFFFFFFFF8LL)));
return v14 - (*(_QWORD *)(v14 - 8) & 0xFFFFFFFFFFFFFFF8LL);
}

canonical_original_code:
void *coalesce(void *bp)
{
    if (bp == ((void *)0)) {
        return ((void *)0);
    }
    unsigned long prev_alloc = ((*(size_t*)(((void*)((void*)bp - ((*(size_t*)((void*)bp - 8)) & ~0x7)) - 4))) & 0x1);
    unsigned long next_alloc = ((*(size_t*)(((void*)((void*)bp + ((*(size_t*)(((void*)bp - 4))) & ~0x7)) - 4))) & 0x1);
    unsigned long size = ((*(size_t*)(((void*)bp - 4))) & ~0x7);
    if (prev_alloc && next_alloc) {
        insert_free_block(bp);
        return bp;
    } else if (!prev_alloc && next_alloc) {
        size += ((*(unsigned long *)(((void *)((void *)bp - ((*(unsigned long *)((void *)bp - 8)) & ~0x7)) - 4))) & ~0x7);
        remove_free_block(((void *)bp - ((*(unsigned long *)((void *)bp - 8)) & ~0x7)));
        (*(unsigned long *)(((void *)((void *)bp - ((*(unsigned long *)((void *)bp - 8)) & ~0x7)) - 4)) = ((size) | (0)));
        (*(unsigned long *)(((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7) - 8)) = ((size) | (0)));
        insert_free_block(((void *)bp - ((*(unsigned long *)((void *)bp - 8)) & ~0x7)));
        return ((void *)bp - ((*(unsigned long *)((void *)bp - 8)) & ~0x7));
    } else if (prev_alloc && !next_alloc) {
        size += ((*(unsigned long *)(((void *)((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7)) - 4))) & ~0x7);
        remove_free_block(((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7)));
        (*(unsigned long *)(((void *)bp - 4)) = ((size) | (0)));
        (*(unsigned long *)(((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7) - 8)) = ((size) | (0)));
        insert_free_block(bp);
        return bp;
    } else {
        size += ((*(unsigned long *)(((void *)((void *)bp - ((*(unsigned long *)((void *)bp - 8)) & ~0x7)) - 4))) & ~0x7)
                + ((*(unsigned long *)(((void *)((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7)) - 4))) & ~0x7);
        remove_free_block(((void *)bp - ((*(unsigned long *)((void *)bp - 8)) & ~0x7)));
        remove_free_block(((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7)));
        (*(unsigned long *)(((void *)((void *)bp - ((*(unsigned long *)((void *)bp - 8)) & ~0x7)) - 4)) = ((size) | (0)));
        (*(unsigned long *)(((void *)((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7)) + ((*(unsigned long *)(((void *)((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7)) - 4))) & ~0x7) - 8)) = ((size) | (0)));
        insert_free_block(((void *)bp - ((*(unsigned long *)((void *)bp - 8)) & ~0x7)));
        return ((void *)bp - ((*(unsigned long *)((void *)bp - 8)) & ~0x7));
    }
}

variable_types:
bp
void *

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall mm_free(_QWORD *a1)
{
unsigned __int64 v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD *)((char *)a1 - 4) & 0xFFFFFFFFFFFFFFF8LL;
*(_QWORD *)((char *)a1 - 4) = v1;
*(_QWORD *)((char *)a1 + v1 - 8) = v1;
result = coalesce(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
unsigned __int64 v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD *)((char *)a1 - 4) & 0xFFFFFFFFFFFFFFF8LL;
*(_QWORD *)((char *)a1 - 4) = v1;
*(_QWORD *)((char *)a1 + v1 - 8) = v1;
result = func2(a1);
}
return result;
}

canonical_original_code:
void mm_free(void *bp)
{
    if (bp == ((void *)0)) {
        return;
    }
    unsigned long size = ((*(size_t*)(((void*)bp - 4))) & ~0x7);
    (*(unsigned long *)(((void *)bp - 4)) = ((size) | (0)));
    (*(unsigned long *)(((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7) - 8)) = ((size) | (0)));
    coalesce(bp);
}


decompiled_code:
__int64 __fastcall extend_heap(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax
_QWORD *v3; // rdi
unsigned __int64 v4; // rax

v1 = 4 * a1;
if ( (a1 & 1) != 0 )
v1 = 4 * a1 + 4;
v2 = mem_sbrk((unsigned int)v1);
if ( !v2 )
return 0LL;
*(_QWORD *)(v2 - 4) = v1;
v3 = (_QWORD *)v2;
v4 = v1 & 0xFFFFFFFFFFFFFFF8LL;
*(_QWORD *)((char *)v3 + v4 - 8) = v1;
*(_QWORD *)((char *)v3 + v4 - 4) = 1LL;
return coalesce(v3);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax
_QWORD *v3; // rdi
unsigned __int64 v4; // rax

v1 = 4 * a1;
if ( (a1 & 1) != 0 )
v1 = 4 * a1 + 4;
v2 = mem_sbrk((unsigned int)v1);
if ( !v2 )
return 0LL;
*(_QWORD *)(v2 - 4) = v1;
v3 = (_QWORD *)v2;
v4 = v1 & 0xFFFFFFFFFFFFFFF8LL;
*(_QWORD *)((char *)v3 + v4 - 8) = v1;
*(_QWORD *)((char *)v3 + v4 - 4) = 1LL;
return func2(v3);
}

canonical_original_code:
void *extend_heap(unsigned long words)
{
    unsigned long bytes = (words % 2) ? (words+1) * 4 : words * 4;
    void *ptr = mem_sbrk(bytes);
    if (((void *)0) == ptr) {
        return ((void *)0);
    }
    (*(unsigned long *)(((void *)ptr - 4)) = ((bytes) | (0)));
    (*(unsigned long *)(((void *)ptr + ((*(unsigned long *)(((void *)ptr - 4))) & ~0x7) - 8)) = ((bytes) | (0)));
    (*(unsigned long *)(((void *)ptr + ((*(unsigned long *)(((void *)ptr - 4))) & ~0x7) - 8) + 4) = ((0) | (1)));
    return coalesce(ptr);
}

variable_types:
words
unsigned long

variable_types:
bytes
unsigned long

variable_types:
ptr
void *


decompiled_code:
__int64 mm_init()
{
__int64 v0; // rax
__int64 v1; // rax
_QWORD *v2; // rdi
__int64 result; // rax

mem_init();
v0 = mem_sbrk(32LL);
heap_listp = v0;
if ( !v0 )
goto LABEL_4;
free_listp = v0;
v1 = v0 + 24;
*(_QWORD *)(v1 - 24) = 0LL;
*(_QWORD *)(v1 - 16) = 0LL;
*(_QWORD *)(v1 - 8) = 0x900000000LL;
*(_QWORD *)v1 = 0x100000009LL;
*(_DWORD *)(v1 + 8) = 0;
heap_listp = v1;
v2 = (_QWORD *)extend_heap(1024LL);
if ( v2 )
result = (unsigned int)-(coalesce(v2) == 0);
else
LABEL_4:
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rax
__int64 v1; // rax
_QWORD *v2; // rdi
__int64 result; // rax

mem_init();
v0 = mem_sbrk(32LL);
heap_listp = v0;
if ( !v0 )
goto LABEL_4;
free_listp = v0;
v1 = v0 + 24;
*(_QWORD *)(v1 - 24) = 0LL;
*(_QWORD *)(v1 - 16) = 0LL;
*(_QWORD *)(v1 - 8) = 0x900000000LL;
*(_QWORD *)v1 = 0x100000009LL;
*(_DWORD *)(v1 + 8) = 0;
heap_listp = v1;
v2 = (_QWORD *)func4(1024LL);
if ( v2 )
result = (unsigned int)-(func2(v2) == 0);
else
LABEL_4:
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int mm_init()
{
    mem_init();
    heap_listp = mem_sbrk(4*8);
    if (((void *)0) == heap_listp) {
        return -1;
    }
    free_listp = heap_listp;
    (*(unsigned long *)(heap_listp) = (unsigned long)(0));
    (*(unsigned long *)(heap_listp + 8) = (unsigned long)(0));
    heap_listp += 2 * 8;
    (*(size_t*)(heap_listp) = 0);
    (*(size_t*)(heap_listp + 4) = ((8) | (1)));
    (*(size_t*)(heap_listp + 8) = ((8) | (1)));
    (*(size_t*)(heap_listp + 4 + 8) = ((0) | (1)));
    heap_listp += 8;
    void * bp;
    if ((bp = extend_heap((1<<12)/4)) == ((void *)0)) {
        return -1;
    }
    if (coalesce(bp) == ((void *)0)) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int mm_init()
{
    mem_init();
    heap_listp = mem_sbrk(4*8);
    if (((void *)0) == heap_listp) {
        return -1;
    }
    free_listp = heap_listp;
    (*(unsigned long *)(heap_listp) = (unsigned long)(0));
    (*(unsigned long *)(heap_listp + 8) = (unsigned long)(0));
    heap_listp += 2 * 8;
    (*(unsigned long *)(heap_listp) = 0);
    (*(unsigned long *)(heap_listp + 4) = ((8) | (1)));
    (*(unsigned long *)(heap_listp + 8) = ((8) | (1)));
    (*(unsigned long *)(heap_listp + 4 + 8) = ((0) | (1)));
    heap_listp += 8;
    void *bp;
    if ((bp = extend_heap((1<<12)/4)) == ((void *)0)) {
        return -1;
    }
    if (coalesce(bp) == ((void *)0)) {
        return -1;
    }
    return 0;
}


place

canonical_original_code:
void place(void *bp, unsigned long asize)
{
    if (bp == ((void *)0)) {
        return;
    }
    remove_free_block(bp);
    unsigned long old_size = ((*(size_t*)(((void*)bp - 4))) & ~0x7);
    if (old_size - asize >= 2*8 + 8) {
        (*(unsigned long *)(((void *)bp - 4)) = ((asize) | (1)));
        (*(unsigned long *)(((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7) - 8)) = ((asize) | (1)));
        (*(unsigned long *)(((void *)((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7)) - 4)) = ((old_size - asize) | (0)));
        (*(unsigned long *)(((void *)((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7)) + ((*(unsigned long *)(((void *)((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7)) - 4))) & ~0x7) - 8)) = ((old_size - asize) | (0)));
        insert_free_block(((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7)));
    } else {
        (*(unsigned long *)(((void *)bp - 4)) = ((old_size) | (1)));
        (*(unsigned long *)(((void *)bp + ((*(unsigned long *)(((void *)bp - 4))) & ~0x7) - 8)) = ((old_size) | (1)));
    }
}

variable_types:
asize
unsigned long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int result; // eax

if ( argc <= 1 )
return puts("Usage: ss4200bright <number 0-255>");
v3 = (unsigned int)strtol(argv[1], 0LL, 10);
printf("level: %d\n", v3);
if ( (unsigned int)v3 > 0xFF )
{
perror("level must be <= 255");
}
else
{
ledPowerLevelSet((unsigned int)v3);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int result; // eax

if ( argc <= 1 )
return puts("Usage: ss4200bright <number 0-255>");
v3 = (unsigned int)strtol(argv[1], 0LL, 10);
printf("level: %d\n", v3);
if ( (unsigned int)v3 > 0xFF )
{
perror("level must be <= 255");
}
else
{
func7((unsigned int)v3);
result = 0;
}
return result;
}

original_code:
int main(int argc, char* argv[])
{
    if( argc < 2 )
    {
        printf("Usage: ss4200bright <number 0-255>\n");
        return;
    }
    unsigned int ulLevel = strtol(argv[1], ((void *)0), 10);
    printf("level: %d\n", ulLevel);
    if (ulLevel < 0)
    {
        perror("level must be >= 0");
        return;
    }
    if (ulLevel > 255)
    {
        perror("level must be <= 255");
        return;
    }
    ledPowerLevelSet(ulLevel);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    if( argc < 2 )
    {
        printf("Usage: ss4200bright <number 0-255>\n");
        return;
    }
    unsigned int ulLevel = strtol(argv[1], ((void *)0), 10);
    printf("level: %d\n", ulLevel);
    if (ulLevel < 0)
    {
        perror("level must be >= 0");
        return;
    }
    if (ulLevel > 255)
    {
        perror("level must be <= 255");
        return;
    }
    ledPowerLevelSet(ulLevel);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
ulLevel
unsigned int


ledPowerLevelSet

decompiled_code:
void __fastcall ledPowerLevelSet(unsigned int a1)
{
__int16 v1[2]; // [rsp+0h] [rbp-88h] BYREF
int v2; // [rsp+4h] [rbp-84h]
char *v3; // [rsp+8h] [rbp-80h]
__int16 v4[2]; // [rsp+10h] [rbp-78h] BYREF
int v5; // [rsp+14h] [rbp-74h]
char *v6; // [rsp+18h] [rbp-70h]
char v7; // [rsp+20h] [rbp-68h] BYREF
char v8; // [rsp+50h] [rbp-38h] BYREF

if ( a1 <= 0xFF )
{
smbusFd = open("/dev/i2c-6", 2);
if ( smbusFd == -1 )
{
perror("smbus failed to open, is i2c-dev module loaded?");
}
else if ( ioctl(smbusFd, 0x703uLL, 46LL) == -1 )
{
perror("Error setting smbus target slave address, is lm85 module loaded?");
}
else
{
v1[0] = -22784;
v3 = &v7;
v2 = 2;
v7 = 7;
if ( ioctl(smbusFd, 0x720uLL, v1) == -1 )
{
perror("Error on smbus write byte 1 (temp until set in BIOS)");
}
else
{
v4[0] = -23296;
v6 = &v8;
v5 = 2;
v8 = a1;
if ( ioctl(smbusFd, 0x720uLL, v4) == -1 )
{
perror("Error on smbus write byte 2 (power level)");
}
else
{
close(smbusFd);
smbusFd = -1;
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func7(unsigned int a1)
{
__int16 v1[2]; // [rsp+0h] [rbp-88h] BYREF
int v2; // [rsp+4h] [rbp-84h]
char *v3; // [rsp+8h] [rbp-80h]
__int16 v4[2]; // [rsp+10h] [rbp-78h] BYREF
int v5; // [rsp+14h] [rbp-74h]
char *v6; // [rsp+18h] [rbp-70h]
char v7; // [rsp+20h] [rbp-68h] BYREF
char v8; // [rsp+50h] [rbp-38h] BYREF

if ( a1 <= 0xFF )
{
smbusFd = open("/dev/i2c-6", 2);
if ( smbusFd == -1 )
{
perror("smbus failed to open, is i2c-dev module loaded?");
}
else if ( ioctl(smbusFd, 0x703uLL, 46LL) == -1 )
{
perror("Error setting smbus target slave address, is lm85 module loaded?");
}
else
{
v1[0] = -22784;
v3 = &v7;
v2 = 2;
v7 = 7;
if ( ioctl(smbusFd, 0x720uLL, v1) == -1 )
{
perror("Error on smbus write byte 1 (temp until set in BIOS)");
}
else
{
v4[0] = -23296;
v6 = &v8;
v5 = 2;
v8 = a1;
if ( ioctl(smbusFd, 0x720uLL, v4) == -1 )
{
perror("Error on smbus write byte 2 (power level)");
}
else
{
close(smbusFd);
smbusFd = -1;
}
}
}
}
}

original_code:
void ledPowerLevelSet( unsigned int ulPowerLevel )
{
    if( ulPowerLevel >= 0 && ulPowerLevel <= 255 )
    {
        smbusFd = open( "/dev/i2c-6", 02 );
        if( -1 == smbusFd )
        {
            perror( "smbus failed to open, is i2c-dev module loaded?" );
            return;
        }
        if( -1 == ioctl( smbusFd, 0x0703, ( 0x2e ) ) )
        {
            perror( "Error setting smbus target slave address, is lm85 module loaded?" );
            return;
        }
        struct i2c_smbus_ioctl_data cmd1;
        union i2c_smbus_data cmdData1;
        cmd1.read_write = 0;
        cmd1.command = ( 0xa7 );
        cmd1.size = 2;
        cmd1.data = &cmdData1;
        cmdData1.byte = 0x07;
        if( -1 == ioctl( smbusFd, 0x0720, &cmd1) )
        {
            perror( "Error on smbus write byte 1 (temp until set in BIOS)" );
            return;
        }
        struct i2c_smbus_ioctl_data cmd2;
        union i2c_smbus_data cmdData2;
        cmd2.read_write = 0;
        cmd2.command = ( 0xa5 );
        cmd2.size = 2;
        cmd2.data = &cmdData2;
        cmdData2.byte = ulPowerLevel;
        if( -1 == ioctl (smbusFd, 0x0720, &cmd2) )
        {
            perror( "Error on smbus write byte 2 (power level)" );
            return;
        }
        close( smbusFd );
        smbusFd = -1;
    }
}

canonical_original_code:
void ledPowerLevelSet(unsigned int ulPowerLevel)
{
    if( ulPowerLevel >= 0 && ulPowerLevel <= 255 )
    {
        smbusFd = open( "/dev/i2c-6", 02 );
        if( -1 == smbusFd )
        {
            perror( "smbus failed to open, is i2c-dev module loaded?" );
            return;
        }
        if( -1 == ioctl( smbusFd, 0x0703, ( 0x2e ) ) )
        {
            perror( "Error setting smbus target slave address, is lm85 module loaded?" );
            return;
        }
        struct i2c_smbus_ioctl_data cmd1;
        union i2c_smbus_data cmdData1;
        cmd1.read_write = 0;
        cmd1.command = ( 0xa7 );
        cmd1.size = 2;
        cmd1.data = &cmdData1;
        cmdData1.byte = 0x07;
        if( -1 == ioctl( smbusFd, 0x0720, &cmd1) )
        {
            perror( "Error on smbus write byte 1 (temp until set in BIOS)" );
            return;
        }
        struct i2c_smbus_ioctl_data cmd2;
        union i2c_smbus_data cmdData2;
        cmd2.read_write = 0;
        cmd2.command = ( 0xa5 );
        cmd2.size = 2;
        cmd2.data = &cmdData2;
        cmdData2.byte = ulPowerLevel;
        if( -1 == ioctl (smbusFd, 0x0720, &cmd2) )
        {
            perror( "Error on smbus write byte 2 (power level)" );
            return;
        }
        close( smbusFd );
        smbusFd = -1;
    }
}

variable_types:
ulPowerLevel
unsigned int

variable_types: struct i2c_smbus_ioctl_data { unsigned char read_write; unsigned char command; unsigned int size; union i2c_smbus_data { unsigned char byte; unsigned short word; unsigned char block[-1]; } *data; }

user_defined_types: struct i2c_smbus_ioctl_data { unsigned char read_write; unsigned char command; unsigned int size; union i2c_smbus_data *data; }


decompiled_code:
void __fastcall buf_destroy(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void buf_destroy(buf_t *buf) {
    if (buf) free(buf);
}

canonical_original_code:
void buf_destroy(struct buf_t *buf) {
    if (buf) free(buf);
}

variable_types: struct buf_t { long capacity; long read; long write; unsigned char data[]; } *


decompiled_code:
void __fastcall buf_reset(__int64 a1)
{
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void buf_reset(buf_t *buf) {
    buf->read = buf->write = 0;
}

canonical_original_code:
void buf_reset(struct buf_t *buf) {
    buf->read = buf->write = 0;
}

user_defined_types: struct buf_t { long capacity; long read; long write; unsigned char data[]; }


decompiled_code:
__int64 __fastcall buf_size(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
ssize_t buf_size(buf_t *buf) {
    return buf->write;
}

canonical_original_code:
long buf_size(struct buf_t *buf) {
    return buf->write;
}

return_type: long


decompiled_code:
__int64 __fastcall buf_read_pos(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
ssize_t buf_read_pos(buf_t *buf) {
    return buf->read;
}

canonical_original_code:
long buf_read_pos(struct buf_t *buf) {
    return buf->read;
}


decompiled_code:
__int64 __fastcall buf_write_remain(_QWORD *a1)
{
return *a1 - a1[2];
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
return *a1 - a1[2];
}

original_code:
ssize_t buf_write_remain(buf_t *buf) {
    return buf->capacity - buf->write;
}

canonical_original_code:
long buf_write_remain(struct buf_t *buf) {
    return buf->capacity - buf->write;
}


decompiled_code:
__int64 __fastcall buf_read_remain(__int64 a1)
{
return *(_QWORD *)(a1 + 16) - *(_QWORD *)(a1 + 8);
}

original_code:
ssize_t buf_read_remain(buf_t *buf) {
    return buf->write - buf->read;
}

canonical_original_code:
long buf_read_remain(struct buf_t *buf) {
    return buf->write - buf->read;
}


decompiled_code:
__int64 __fastcall buf_write_ptr(__int64 a1)
{
return *(_QWORD *)(a1 + 16) + a1 + 24;
}

original_code:
unsigned char* buf_write_ptr(buf_t *buf) {
    return buf->data + buf->write;
}

canonical_original_code:
unsigned char *buf_write_ptr(struct buf_t *buf) {
    return buf->data + buf->write;
}

return_type: unsigned char *


decompiled_code:
__int64 __fastcall bug_read_ptr(__int64 a1)
{
return *(_QWORD *)(a1 + 8) + a1 + 24;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(_QWORD *)(a1 + 8) + a1 + 24;
}

original_code:
unsigned char* bug_read_ptr(buf_t *buf) {
    return buf->data + buf->read;
}

canonical_original_code:
unsigned char *bug_read_ptr(struct buf_t *buf) {
    return buf->data + buf->read;
}


decompiled_code:
_BOOL8 __fastcall buf_is_empty(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

original_code:
int buf_is_empty(buf_t *buf) {
    return buf->write == 0;
}

canonical_original_code:
int buf_is_empty(struct buf_t *buf) {
    return buf->write == 0;
}


decompiled_code:
_BOOL8 __fastcall buf_is_full(_QWORD *a1)
{
return a1[2] == *a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(_QWORD *a1)
{
return a1[2] == *a1;
}

original_code:
int buf_is_full(buf_t *buf) {
    return buf->write == buf->capacity;
}

canonical_original_code:
int buf_is_full(struct buf_t *buf) {
    return buf->write == buf->capacity;
}


decompiled_code:
void __fastcall buf_advance(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 16) += a2;
}

original_code:
void buf_advance(buf_t *buf, ssize_t len) {
    buf->write += len;
}

canonical_original_code:
void buf_advance(struct buf_t *buf, long len) {
    buf->write += len;
}

variable_types: len long


original_code:
void buf_truncate(buf_t *buf, ssize_t len) {
    buf->write = len;
    if (buf->read > buf->write) {
        buf->read = buf->write;
    }
}

canonical_original_code:
void buf_truncate(struct buf_t *buf, long len) {
    buf->write = len;
    if (buf->read > buf->write) {
        buf->read = buf->write;
    }
}


decompiled_code:
__int64 __fastcall buf_write(_QWORD *a1, const void *a2, signed __int64 a3)
{
unsigned int v4; // er8
__int64 v5; // rdx

v4 = 0;
v5 = a1[2];
if ( *a1 - v5 >= a3 )
{
memcpy((char *)a1 + v5 + 24, a2, a3);
a1[2] += a3;
v4 = 1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1, const void *a2, signed __int64 a3)
{
unsigned int v4; // er8
__int64 v5; // rdx

v4 = 0;
v5 = a1[2];
if ( *a1 - v5 >= a3 )
{
memcpy((char *)a1 + v5 + 24, a2, a3);
a1[2] += a3;
v4 = 1;
}
return v4;
}

original_code:
int buf_write(buf_t *buf, unsigned char *bytes, ssize_t len) {
    if (!((buf->capacity - buf->write) >= len)) return 0;
    memcpy(buf->data + buf->write, bytes, len);
    buf->write += len;
    return 1;
}

canonical_original_code:
int buf_write(struct buf_t *buf, unsigned char *bytes, long len) {
    if (!((buf->capacity - buf->write) >= len)) return 0;
    memcpy(buf->data + buf->write, bytes, len);
    buf->write += len;
    return 1;
}

variable_types:
bytes
unsigned char *


decompiled_code:
__int64 __fastcall buf_write_uint64(_QWORD *a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return buf_write(a1, &v3, 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func14(_QWORD *a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return func13(a1, &v3, 8LL);
}

original_code: int buf_write_uint64(buf_t *buf, uint64_t v) { return buf_write(buf, (unsigned char*)&v, sizeof(uint64_t)); }

canonical_original_code: int buf_write_uint64(struct buf_t *buf, unsigned long v) { return buf_write(buf, (unsigned char *)&v, sizeof(unsigned long)); }

variable_types:
v
unsigned long


decompiled_code:
__int64 __fastcall buf_write_uint32(_QWORD *a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return buf_write(a1, v3, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func15(_QWORD *a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return func13(a1, v3, 4LL);
}

original_code: int buf_write_uint32(buf_t *buf, uint32_t v) { return buf_write(buf, (unsigned char*)&v, sizeof(uint32_t)); }

canonical_original_code: int buf_write_uint32(struct buf_t *buf, unsigned int v) { return buf_write(buf, (unsigned char *)&v, sizeof(unsigned int)); }

variable_types:
v
unsigned int


decompiled_code:
__int64 __fastcall buf_write_uint16(_QWORD *a1, __int16 a2)
{
__int16 v3[6]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return buf_write(a1, v3, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(_QWORD *a1, __int16 a2)
{
__int16 v3[6]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return func13(a1, v3, 2LL);
}

original_code: int buf_write_uint16(buf_t *buf, uint16_t v) { return buf_write(buf, (unsigned char*)&v, sizeof(uint16_t)); }

canonical_original_code: int buf_write_uint16(struct buf_t *buf, unsigned short v) { return buf_write(buf, (unsigned char *)&v, sizeof(unsigned short)); }

variable_types:
v
unsigned short


decompiled_code:
__int64 __fastcall buf_write_int64(_QWORD *a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return buf_write(a1, &v3, 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func17(_QWORD *a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return func13(a1, &v3, 8LL);
}

original_code: int buf_write_int64(buf_t *buf, int64_t v) { return buf_write(buf, (unsigned char*)&v, sizeof(int64_t)); }

canonical_original_code: int buf_write_int64(struct buf_t *buf, long v) { return buf_write(buf, (unsigned char *)&v, sizeof(long)); }

variable_types: v long


decompiled_code:
__int64 __fastcall buf_write_int32(_QWORD *a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return buf_write(a1, v3, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func18(_QWORD *a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return func13(a1, v3, 4LL);
}

original_code: int buf_write_int32(buf_t *buf, int32_t v) { return buf_write(buf, (unsigned char*)&v, sizeof(int32_t)); }

canonical_original_code: int buf_write_int32(struct buf_t *buf, int v) { return buf_write(buf, (unsigned char *)&v, sizeof(int)); }

variable_types: v int


decompiled_code:
__int64 __fastcall buf_write_int16(_QWORD *a1, __int16 a2)
{
__int16 v3[6]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return buf_write(a1, v3, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1, __int16 a2)
{
__int16 v3[6]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return func13(a1, v3, 2LL);
}

original_code: int buf_write_int16(buf_t *buf, int16_t v) { return buf_write(buf, (unsigned char*)&v, sizeof(int16_t)); }

canonical_original_code: int buf_write_int16(struct buf_t *buf, short v) { return buf_write(buf, (unsigned char *)&v, sizeof(short)); }

variable_types: v short


decompiled_code:
__int64 __fastcall buf_write_float(_QWORD *a1, float a2)
{
float v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return buf_write(a1, v3, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func20(_QWORD *a1, float a2)
{
float v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return func13(a1, v3, 4LL);
}

original_code: int buf_write_float(buf_t *buf, float v) { return buf_write(buf, (unsigned char*)&v, sizeof(float)); }

canonical_original_code: int buf_write_float(struct buf_t *buf, float v) { return buf_write(buf, (unsigned char *)&v, sizeof(float)); }

variable_types: v float


decompiled_code:
__int64 __fastcall buf_write_double(_QWORD *a1, double a2)
{
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a2;
return buf_write(a1, v3, 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func21(_QWORD *a1, double a2)
{
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a2;
return func13(a1, v3, 8LL);
}

original_code: int buf_write_double(buf_t *buf, double v) { return buf_write(buf, (unsigned char*)&v, sizeof(double)); }

canonical_original_code: int buf_write_double(struct buf_t *buf, double v) { return buf_write(buf, (unsigned char *)&v, sizeof(double)); }

variable_types: v double


original_code:
int buf_write_byte(buf_t *buf, unsigned char v) {
    if (!((buf->capacity - buf->write) >= 1)) return 0;
    buf->data[buf->write++] = v;
    return 1;
}

canonical_original_code:
int buf_write_byte(struct buf_t *buf, unsigned char v) {
    if (!((buf->capacity - buf->write) >= 1)) return 0;
    buf->data[buf->write++] = v;
    return 1;
}

variable_types:
v
unsigned char


original_code:
int buf_read(buf_t *buf, unsigned char *out, ssize_t len) {
    if (!((buf->write - buf->read) >= len)) return 0;
    memcpy(out, buf->data + buf->read, len);
    buf->read += len;
    return len;
}

canonical_original_code:
int buf_read(struct buf_t *buf, unsigned char *out, long len) {
    if (!((buf->write - buf->read) >= len)) return 0;
    memcpy(out, buf->data + buf->read, len);
    buf->read += len;
    return len;
}

variable_types:
out
unsigned char *


decompiled_code:
__int64 __fastcall buf_read_uint64(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

buf_read(a1, &v2, 8LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

func23(a1, &v2, 8LL);
return v2;
}

original_code: uint64_t buf_read_uint64(buf_t *buf) { uint64_t v; buf_read(buf, (unsigned char*)&v, sizeof(uint64_t)); return v; }

canonical_original_code: unsigned long buf_read_uint64(struct buf_t *buf) { unsigned long v; buf_read(buf, (unsigned char *)&v, sizeof(unsigned long)); return v; }


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

buf_read(a1, v2, 4LL);
return v2[0];
}

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

func23(a1, v2, 4LL);
return v2[0];
}

original_code: uint32_t buf_read_uint32(buf_t *buf) { uint32_t v; buf_read(buf, (unsigned char*)&v, sizeof(uint32_t)); return v; }

canonical_original_code: unsigned int buf_read_uint32(struct buf_t *buf) { unsigned int v; buf_read(buf, (unsigned char *)&v, sizeof(unsigned int)); return v; }


decompiled_code:
__int64 __fastcall buf_read_uint16(__int64 a1)
{
unsigned __int16 v2[5]; // [rsp+Eh] [rbp-Ah] BYREF

buf_read(a1, v2, 2LL);
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 a1)
{
unsigned __int16 v2[5]; // [rsp+Eh] [rbp-Ah] BYREF

func23(a1, v2, 2LL);
return v2[0];
}

original_code: uint16_t buf_read_uint16(buf_t *buf) { uint16_t v; buf_read(buf, (unsigned char*)&v, sizeof(uint16_t)); return v; }

canonical_original_code: unsigned short buf_read_uint16(struct buf_t *buf) { unsigned short v; buf_read(buf, (unsigned char *)&v, sizeof(unsigned short)); return v; }

return_type: unsigned short


decompiled_code:
__int64 __fastcall buf_read_int64(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

buf_read(a1, &v2, 8LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func27(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

func23(a1, &v2, 8LL);
return v2;
}

original_code: int64_t buf_read_int64(buf_t *buf) { int64_t v; buf_read(buf, (unsigned char*)&v, sizeof(int64_t)); return v; }

canonical_original_code: long buf_read_int64(struct buf_t *buf) { long v; buf_read(buf, (unsigned char *)&v, sizeof(long)); return v; }


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

buf_read(a1, v2, 4LL);
return v2[0];
}

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

func23(a1, v2, 4LL);
return v2[0];
}

original_code: int32_t buf_read_int32(buf_t *buf) { int32_t v; buf_read(buf, (unsigned char*)&v, sizeof(int32_t)); return v; }

canonical_original_code: int buf_read_int32(struct buf_t *buf) { int v; buf_read(buf, (unsigned char *)&v, sizeof(int)); return v; }


decompiled_code:
__int64 __fastcall buf_read_int16(__int64 a1)
{
unsigned __int16 v2[5]; // [rsp+Eh] [rbp-Ah] BYREF

buf_read(a1, v2, 2LL);
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func29(__int64 a1)
{
unsigned __int16 v2[5]; // [rsp+Eh] [rbp-Ah] BYREF

func23(a1, v2, 2LL);
return v2[0];
}

original_code: int16_t buf_read_int16(buf_t *buf) { int16_t v; buf_read(buf, (unsigned char*)&v, sizeof(int16_t)); return v; }

canonical_original_code: short buf_read_int16(struct buf_t *buf) { short v; buf_read(buf, (unsigned char *)&v, sizeof(short)); return v; }

return_type: short


decompiled_code:
float __fastcall buf_read_float(__int64 a1)
{
float v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf_read(a1, v2, 4LL);
return v2[0];
}

canonical_decompiled_code:
float __fastcall func30(__int64 a1)
{
float v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

func23(a1, v2, 4LL);
return v2[0];
}

original_code: float buf_read_float(buf_t *buf) { float v; buf_read(buf, (unsigned char*)&v, sizeof(float)); return v; }

canonical_original_code: float buf_read_float(struct buf_t *buf) { float v; buf_read(buf, (unsigned char *)&v, sizeof(float)); return v; }

return_type: float


decompiled_code:
double __fastcall buf_read_double(__int64 a1)
{
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

buf_read(a1, v2, 8LL);
return v2[0];
}

canonical_decompiled_code:
double __fastcall func31(__int64 a1)
{
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

func23(a1, v2, 8LL);
return v2[0];
}

original_code: double buf_read_double(buf_t *buf) { double v; buf_read(buf, (unsigned char*)&v, sizeof(double)); return v; }

canonical_original_code: double buf_read_double(struct buf_t *buf) { double v; buf_read(buf, (unsigned char *)&v, sizeof(double)); return v; }

return_type: double


original_code:
unsigned char buf_read_byte(buf_t *buf) {
    if (!((buf->write - buf->read) >= 1)) return 0;
    return buf->data[buf->read++];
}

canonical_original_code:
unsigned char buf_read_byte(struct buf_t *buf) {
    if (!((buf->write - buf->read) >= 1)) return 0;
    return buf->data[buf->read++];
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall mpool_init(unsigned __int64 *a1, __int64 a2)
{
unsigned __int64 v2; // rbx
char *v3; // rax
char *v4; // rbx
__int64 result; // rax

v2 = (a2 + 7) & 0xFFFFFFFFFFFFFFF8LL;
*a1 = v2;
v3 = (char *)malloc(v2);
a1[1] = (unsigned __int64)v3;
if ( !v3 )
return 0LL;
v4 = &v3[v2];
a1[3] = (unsigned __int64)v3;
result = 1LL;
a1[2] = (unsigned __int64)v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 *a1, __int64 a2)
{
unsigned __int64 v2; // rbx
char *v3; // rax
char *v4; // rbx
__int64 result; // rax

v2 = (a2 + 7) & 0xFFFFFFFFFFFFFFF8LL;
*a1 = v2;
v3 = (char *)malloc(v2);
a1[1] = (unsigned __int64)v3;
if ( !v3 )
return 0LL;
v4 = &v3[v2];
a1[3] = (unsigned __int64)v3;
result = 1LL;
a1[2] = (unsigned __int64)v4;
return result;
}

original_code:
int mpool_init(mpool_t *pool, ssize_t sz) {
    pool->size = (((sz) + (8 - 1)) & ~(8 - 1));
    pool->base = malloc(pool->size);
    if (pool->base) {
        pool->end = pool->base + pool->size;
        pool->next = pool->base;
        return 1;
    } else {
        return 0;
    }
}

canonical_original_code:
int mpool_init(struct mpool_t *pool, long sz) {
    pool->size = (((sz) + (8 - 1)) & ~(8 - 1));
    pool->base = malloc(pool->size);
    if (pool->base) {
        pool->end = pool->base + pool->size;
        pool->next = pool->base;
        return 1;
    } else {
        return 0;
    }
}

variable_types: struct mpool_t { long size; char *base; char *end; char *next; } *

variable_types: sz long


decompiled_code:
void __fastcall mpool_cleanup(__int64 a1)
{
free(*(void **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
free(*(void **)(a1 + 8));
}

original_code:
int mpool_cleanup(mpool_t *pool) {
    free(pool->base);
}

canonical_original_code:
int mpool_cleanup(struct mpool_t *pool) {
    free(pool->base);
}

user_defined_types: struct mpool_t { long size; char *base; char *end; char *next; }


decompiled_code:
__int64 __fastcall mpool_alloc(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int64 v3; // rsi

result = *(_QWORD *)(a1 + 24);
v3 = result + ((a2 + 7) & 0xFFFFFFFFFFFFFFF8LL);
if ( v3 > *(_QWORD *)(a1 + 16) )
return 0LL;
*(_QWORD *)(a1 + 24) = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int64 v3; // rsi

result = *(_QWORD *)(a1 + 24);
v3 = result + ((a2 + 7) & 0xFFFFFFFFFFFFFFF8LL);
if ( v3 > *(_QWORD *)(a1 + 16) )
return 0LL;
*(_QWORD *)(a1 + 24) = v3;
return result;
}

original_code:
void* mpool_alloc(mpool_t* pool, ssize_t sz) {
    sz = (((sz) + (8 - 1)) & ~(8 - 1));
    if (pool->next + sz > pool->end) {
        return 0;
    }
    char *ptr = pool->next;
    pool->next += sz;
    return ptr;
}

canonical_original_code:
void *mpool_alloc(struct mpool_t *pool, long sz) {
    sz = (((sz) + (8 - 1)) & ~(8 - 1));
    if (pool->next + sz > pool->end) {
        return 0;
    }
    char *ptr = pool->next;
    pool->next += sz;
    return ptr;
}

variable_types:
ptr
char *


decompiled_code:
__int64 __fastcall mpool_clear(__int64 a1)
{
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax

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

original_code:
void mpool_clear(mpool_t* pool) {
    pool->next = pool->base;
}

canonical_original_code:
void mpool_clear(struct mpool_t *pool) {
    pool->next = pool->base;
}


repo: jazzyb/libforchess

decompiled_code:
__int64 __fastcall fc_uint64(const char *a1)
{
char v2; // [rsp+Ch] [rbp-Ch] BYREF
char v3; // [rsp+Dh] [rbp-Bh] BYREF
char v4; // [rsp+Eh] [rbp-Ah] BYREF
char v5; // [rsp+Fh] [rbp-9h] BYREF

sscanf(a1, "%c%c-%c%c", &v2, &v4, &v3, &v5);
return (1LL << (v2 + 8 * v4 + 23)) | (1LL << (v3 + 8 * v5 + 23));
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
char v2; // [rsp+Ch] [rbp-Ch] BYREF
char v3; // [rsp+Dh] [rbp-Bh] BYREF
char v4; // [rsp+Eh] [rbp-Ah] BYREF
char v5; // [rsp+Fh] [rbp-9h] BYREF

sscanf(a1, "%c%c-%c%c", &v2, &v4, &v3, &v5);
return (1LL << (v2 + 8 * v4 + 23)) | (1LL << (v3 + 8 * v5 + 23));
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall fc_move_copy(__m128i *a1, const __m128i *a2)
{
__int64 result; // rax

*a1 = _mm_loadu_si128(a2);
a1[1] = _mm_loadu_si128(a2 + 1);
result = a2[2].m128i_i64[0];
a1[2].m128i_i64[0] = result;
return result;
}

original_code:
void fc_move_copy (fc_move_t *dst, fc_move_t *src)
{
 memcpy(dst, src, sizeof(*dst));
}

canonical_original_code:
void fc_move_copy(struct fc_move_t *dst, struct fc_move_t *src)
{
 memcpy(dst, src, sizeof(*dst));
}

variable_types: struct fc_move_t { enum fc_player_t { FC_FIRST=0, FC_SECOND=1, FC_THIRD=2, FC_FOURTH=3 } player; enum fc_piece_t { FC_PAWN=0, FC_BISHOP=1, FC_KNIGHT=2, FC_ROOK=3, FC_QUEEN=4, FC_KING=5 } piece; enum fc_player_t { FC_FIRST=0, FC_SECOND=1, FC_THIRD=2, FC_FOURTH=3 } opp_player; enum fc_piece_t { FC_PAWN=0, FC_BISHOP=1, FC_KNIGHT=2, FC_ROOK=3, FC_QUEEN=4, FC_KING=5 } opp_piece; enum fc_piece_t { FC_PAWN=0, FC_BISHOP=1, FC_KNIGHT=2, FC_ROOK=3, FC_QUEEN=4, FC_KING=5 } promote; unsigned long move; int value; } *

variable_types:
src
struct fc_move_t *

user_defined_types: struct fc_move_t { enum fc_player_t player; enum fc_piece_t piece; enum fc_player_t opp_player; enum fc_piece_t opp_piece; enum fc_piece_t promote; unsigned long move; int value; }


decompiled_code:
void __fastcall fc_move_set_promotion(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
}

original_code:
void fc_move_set_promotion (fc_move_t *move, fc_piece_t promote)
{
 move->promote = promote;
}

canonical_original_code:
void fc_move_set_promotion(struct fc_move_t *move, enum fc_piece_t promote)
{
 move->promote = promote;
}

variable_types: enum fc_piece_t { FC_PAWN=0, FC_BISHOP=1, FC_KNIGHT=2, FC_ROOK=3, FC_QUEEN=4, FC_KING=5 }

user_defined_types: enum fc_player_t { FC_FIRST=0, FC_SECOND=1, FC_THIRD=2, FC_FOURTH=3 }


decompiled_code:
_BOOL8 __fastcall fc_mlist_init(__int64 a1)
{
void *v1; // rax

*(_DWORD *)(a1 + 8) = 0;
v1 = calloc(0xFFuLL, 0x28uLL);
*(_QWORD *)a1 = v1;
return v1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
void *v1; // rax

*(_DWORD *)(a1 + 8) = 0;
v1 = calloc(0xFFuLL, 0x28uLL);
*(_QWORD *)a1 = v1;
return v1 != 0LL;
}

original_code:
int fc_mlist_init (fc_mlist_t *list)
{
 list->index = 0;
 list->moves = calloc(255, sizeof(*list->moves));
 if (!list->moves) {
  return 0;
 }
 return 1;
}

canonical_original_code:
int fc_mlist_init(struct fc_mlist_t *list)
{
 list->index = 0;
 list->moves = calloc(255, sizeof(*list->moves));
 if (!list->moves) {
  return 0;
 }
 return 1;
}

variable_types: struct fc_mlist_t { struct fc_move_t { enum fc_player_t { FC_FIRST=0, FC_SECOND=1, FC_THIRD=2, FC_FOURTH=3 } player; enum fc_piece_t { FC_PAWN=0, FC_BISHOP=1, FC_KNIGHT=2, FC_ROOK=3, FC_QUEEN=4, FC_KING=5 } piece; enum fc_player_t { FC_FIRST=0, FC_SECOND=1, FC_THIRD=2, FC_FOURTH=3 } opp_player; enum fc_piece_t { FC_PAWN=0, FC_BISHOP=1, FC_KNIGHT=2, FC_ROOK=3, FC_QUEEN=4, FC_KING=5 } opp_piece; enum fc_piece_t { FC_PAWN=0, FC_BISHOP=1, FC_KNIGHT=2, FC_ROOK=3, FC_QUEEN=4, FC_KING=5 } promote; unsigned long move; int value; } *moves; unsigned int index; } *

user_defined_types: struct fc_mlist_t { struct fc_move_t *moves; unsigned int index; }


decompiled_code:
__int64 __fastcall fc_mlist_copy(__int64 a1, __int64 a2)
{
unsigned int v4; // edx
unsigned int v5; // eax
__int64 result; // rax

if ( *(_DWORD *)(a2 + 8) )
{
v4 = 0;
do
{
fc_move_copy((__m128i *)(*(_QWORD *)a1 + 40LL * v4), (const __m128i *)(40LL * v4 + *(_QWORD *)a2));
v5 = *(_DWORD *)(a2 + 8);
}
while ( v5 > v4 );
*(_DWORD *)(a1 + 8) = v5;
result = 1LL;
}
else
{
*(_DWORD *)(a1 + 8) = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
unsigned int v4; // edx
unsigned int v5; // eax
__int64 result; // rax

if ( *(_DWORD *)(a2 + 8) )
{
v4 = 0;
do
{
func1((__m128i *)(*(_QWORD *)a1 + 40LL * v4), (const __m128i *)(40LL * v4 + *(_QWORD *)a2));
v5 = *(_DWORD *)(a2 + 8);
}
while ( v5 > v4 );
*(_DWORD *)(a1 + 8) = v5;
result = 1LL;
}
else
{
*(_DWORD *)(a1 + 8) = 0;
result = 1LL;
}
return result;
}

original_code:
int fc_mlist_copy (fc_mlist_t *dst, fc_mlist_t *src)
{
 uint32_t i;
 for (i = 0; i < src->index; i++) {
  fc_move_copy(dst->moves + i, src->moves + i);
 }
 dst->index = src->index;
 return 1;
}

canonical_original_code:
int fc_mlist_copy(struct fc_mlist_t *dst, struct fc_mlist_t *src)
{
 unsigned int i;
 for (i = 0; i < src->index; i++) {
  fc_move_copy(dst->moves + i, src->moves + i);
 }
 dst->index = src->index;
 return 1;
}

variable_types:
src
struct fc_mlist_t *

variable_types:
i
unsigned int

user_defined_types: enum fc_piece_t { FC_PAWN=0, FC_BISHOP=1, FC_KNIGHT=2, FC_ROOK=3, FC_QUEEN=4, FC_KING=5 }


original_code:
int fc_mlist_insert (fc_mlist_t *list, fc_move_t *move, int32_t value)
{
 uint32_t i;
 fc_move_t *old;
 ((void) (0));
 for (i = 0; i < list->index; i++) {
  old = list->moves + i;
  if (value > old->value) {
   break;
  }
 }
 (void)memmove(list->moves + i + 1, list->moves + i,
   (list->index - i) * sizeof(*list->moves));
 fc_move_copy(list->moves + i, move);
 list->moves[i].value = value;
 list->index += 1;
 return 1;
}

canonical_original_code:
int fc_mlist_insert(struct fc_mlist_t *list, struct fc_move_t *move, int value)
{
 unsigned int i;
 struct fc_move_t *old;
 ((void) (0));
 for (i = 0; i < list->index; i++) {
  old = list->moves + i;
  if (value > old->value) {
   break;
  }
 }
 (void)memmove(list->moves + i + 1, list->moves + i,
   (list->index - i) * sizeof(*list->moves));
 fc_move_copy(list->moves + i, move);
 list->moves[i].value = value;
 list->index += 1;
 return 1;
}

variable_types:
move
struct fc_move_t *

variable_types: value int


decompiled_code:
__int64 __fastcall fc_mlist_delete(__int64 a1, int a2)
{
unsigned int v2; // eax
__int64 v4; // rax
char *v5; // rsi

if ( a2 < 0 )
return 0LL;
v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= a2 )
return 0LL;
v4 = v2 - a2;
v5 = (char *)(*(_QWORD *)a1 + 8 * (5LL * a2 + 5));
memmove(v5 - 40, v5, 40 * v4);
--*(_DWORD *)(a1 + 8);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
unsigned int v2; // eax
__int64 v4; // rax
char *v5; // rsi

if ( a2 < 0 )
return 0LL;
v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= a2 )
return 0LL;
v4 = v2 - a2;
v5 = (char *)(*(_QWORD *)a1 + 8 * (5LL * a2 + 5));
memmove(v5 - 40, v5, 40 * v4);
--*(_DWORD *)(a1 + 8);
return 1LL;
}

original_code:
int fc_mlist_delete (fc_mlist_t *list, int index)
{
 if (index < 0 || index >= list->index) {
  return 0;
 }
 memmove(list->moves + index, list->moves + index + 1,
   (list->index - index) * sizeof(*list->moves));
 list->index -= 1;
 return 1;
}

canonical_original_code:
int fc_mlist_delete(struct fc_mlist_t *list, int index)
{
 if (index < 0 || index >= list->index) {
  return 0;
 }
 memmove(list->moves + index, list->moves + index + 1,
   (list->index - index) * sizeof(*list->moves));
 list->index -= 1;
 return 1;
}

variable_types: index int


decompiled_code:
void __fastcall fc_mlist_free(__int64 a1)
{
free(*(void **)a1);
*(_DWORD *)(a1 + 8) = 0;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
free(*(void **)a1);
*(_DWORD *)(a1 + 8) = 0;
}

original_code:
void fc_mlist_free (fc_mlist_t *list)
{
 free(list->moves);
 list->index = 0;
}

canonical_original_code:
void fc_mlist_free(struct fc_mlist_t *list)
{
 free(list->moves);
 list->index = 0;
}


decompiled_code:
__int64 __fastcall fc_mlist_length(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
int fc_mlist_length (fc_mlist_t *list)
{
 return list->index;
}

canonical_original_code:
int fc_mlist_length(struct fc_mlist_t *list)
{
 return list->index;
}


decompiled_code:
void __fastcall fc_mlist_clear(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 0;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 0;
}

original_code:
void fc_mlist_clear (fc_mlist_t *list)
{
 list->index = 0;
}

canonical_original_code:
void fc_mlist_clear(struct fc_mlist_t *list)
{
 list->index = 0;
}


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

if ( *(_DWORD *)(a1 + 8) <= a2 )
result = 0LL;
else
result = *(_QWORD *)a1 + 40LL * (int)a2;
return result;
}

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

if ( *(_DWORD *)(a1 + 8) <= a2 )
result = 0LL;
else
result = *(_QWORD *)a1 + 40LL * (int)a2;
return result;
}

original_code:
fc_move_t *fc_mlist_get (fc_mlist_t *list, int index)
{
 if (index >= list->index) {
  return ((void *)0);
 }
 return list->moves + index;
}

canonical_original_code:
struct fc_move_t *fc_mlist_get(struct fc_mlist_t *list, int index)
{
 if (index >= list->index) {
  return ((void *)0);
 }
 return list->moves + index;
}

variable_types: struct fc_mlist_t { struct fc_move_t *moves; unsigned int index; } *

return_type: struct fc_move_t { enum fc_player_t { FC_FIRST=0, FC_SECOND=1, FC_THIRD=2, FC_FOURTH=3 } player; enum fc_piece_t { FC_PAWN=0, FC_BISHOP=1, FC_KNIGHT=2, FC_ROOK=3, FC_QUEEN=4, FC_KING=5 } piece; enum fc_player_t { FC_FIRST=0, FC_SECOND=1, FC_THIRD=2, FC_FOURTH=3 } opp_player; enum fc_piece_t { FC_PAWN=0, FC_BISHOP=1, FC_KNIGHT=2, FC_ROOK=3, FC_QUEEN=4, FC_KING=5 } opp_piece; enum fc_piece_t { FC_PAWN=0, FC_BISHOP=1, FC_KNIGHT=2, FC_ROOK=3, FC_QUEEN=4, FC_KING=5 } promote; unsigned long move; int value; } *