decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
ssize_t v4; // rbp
__int64 v5; // r13
__int64 v6; // r12
int result; // eax
const unsigned __int16 *v8; // rax
unsigned __int16 v9; // cx
bool v10; // zf
unsigned __int16 v11; // ax
const unsigned __int16 *v12; // rax
unsigned __int16 v13; // cx
unsigned __int16 v14; // ax
__int64 v15; // rax
unsigned __int16 v16; // bx
int v17; // eax
ssize_t v18; // rax
unsigned __int16 v19; // r15
unsigned __int16 v20; // cx
__int64 v21; // rbx
const char *v22; // rax
__int16 v23; // [rsp+Ch] [rbp-4Ch]
unsigned __int16 v24; // [rsp+Eh] [rbp-4Ah]
_WORD buf[29]; // [rsp+1Eh] [rbp-3Ah] BYREF

v3 = fileno(_bss_start);
v4 = read(v3, buf, 2uLL);
if ( v4 == 2 )
{
v5 = -10LL;
v23 = 0;
v24 = 0;
v6 = 0LL;
do
{
v16 = buf[0];
v17 = fileno(_bss_start);
v18 = read(v17, buf, 2uLL);
v4 = v18;
if ( !v18 )
{
printf(" %17s\n", "---Bytecode Check---");
printf(
"%04zx %02x %02x: %17s 0x%04x (%d) %s\n",
v6 - 10,
HIBYTE(v16),
(unsigned __int8)v16,
"last word",
v16,
v16,
"(crc-16 check sum only of bytecode)");
return 0;
}
if ( v18 > 0 )
{
if ( v6 == 10 )
{
printf(" %17s\n", "---Event Table------");
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
0LL,
HIBYTE(v16),
(unsigned __int8)v16,
"event block size",
v16,
v16);
v24 = v16;
}
else
{
v15 = v24 + 10LL;
if ( v15 <= v6 )
{
if ( v15 == v6 )
printf(" %17s\n", "---Bytecode Data----");
v19 = v16 >> 12;
if ( v23 )
{
printf(
"%04zx %02x %02x: %17s 0x%04x (%d/%d)\n",
v5,
HIBYTE(v16),
(unsigned __int8)v16,
"argument",
v16,
v16,
(unsigned int)(__int16)v16);
if ( !--v23 )
goto LABEL_42;
}
else
{
v20 = v16 & 0xFFF;
if ( v19 == 12 )
{
if ( v20 > 0x2Au )
printf("%04zx %01x %03x: %17s %s (%d)\n", v5, 12LL, v20, off_405260[0], "(undefined)", v20);
else
printf("%04zx %01x %03x: %17s %s (%d)\n", v5, 12LL, v20, off_405260[0], native[v16 & 0xFFF], v20);
}
else
{
if ( (v19 & 0xFFFD) == 8 )
{
if ( (unsigned __int8)v16 > 0x11u )
printf(
"%04zx %01x %03x: %17s %s (%d)\n",
v5,
v19,
v20,
bytecode_name[3 * (v19 & 0xF)],
"unknown",
(unsigned __int8)v16);
else
printf(
"%04zx %01x %03x: %17s %s (%d)\n",
v5,
v19,
v20,
bytecode_name[3 * (v19 & 0xF)],
bin_op_name[(unsigned __int8)v16],
(unsigned __int8)v16);
LABEL_42:
if ( v19 == 10 )
{
v23 = 1;
}
else if ( v19 <= 0xAu )
{
v23 = 1;
if ( v19 != 2 )
v23 = (unsigned __int16)(v19 - 5) <= 1u;
}
else
{
v23 = 2 * (v19 == 11);
}
goto LABEL_29;
}
if ( v19 == 7 )
{
if ( (v16 & 0xFC) != 0 )
printf(
"%04zx %01x %03x: %17s %s (%d)\n",
v5,
7LL,
v20,
off_4051E8[0],
"unknown",
(unsigned __int8)v16);
else
printf(
"%04zx %01x %03x: %17s %s (%d)\n",
v5,
7LL,
v20,
off_4051E8[0],
unary_op_name[(unsigned __int8)v16],
(unsigned __int8)v16);
}
else
{
if ( (unsigned __int16)(v19 - 3) > 1u )
{
printf(
"%04zx %01x %03x: %17s %d (%d)\n",
v5,
v19,
v20,
bytecode_name[3 * (v19 & 0xF)],
v20,
(unsigned int)((__int16)(16 * v16) >> 4));
goto LABEL_42;
}
v21 = v20;
v22 = variable_name_of_index(v20);
printf(
"%04zx %01x %03x: %17s %s (%d)\n",
v5,
v19,
(unsigned int)v21,
bytecode_name[3 * (v19 & 0xF)],
v22,
v21);
}
}
}
}
else if ( (((_BYTE)v5 - (_BYTE)v24) & 1) != 0 )
{
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
v5,
HIBYTE(v16),
(unsigned __int8)v16,
"event address",
v16,
v16);
}
else if ( v16 <= 0xFFEEu )
{
printf(
"%04zx %02x %02x: %17s 0x%04x (%d/%d/~%d) %s\n",
v5,
HIBYTE(v16),
(unsigned __int8)v16,
"event type",
v16,
v16,
(unsigned int)(__int16)v16,
(unsigned __int16)~v16,
"unknown");
}
else
{
printf(
"%04zx %02x %02x: %17s 0x%04x (%d/%d/~%d) %s\n",
v5,
255LL,
(unsigned __int8)v16,
"event type",
v16,
v16,
(unsigned int)(__int16)v16,
(unsigned __int16)~v16,
event_names[(unsigned __int16)~v16]);
}
}
}
else
{
switch ( v6 )
{
case 0LL:
printf(" %17s\n", "---Header-----------");
v8 = *__ctype_b_loc();
v9 = 32;
if ( (v8[(unsigned __int8)v16] & 0x4000) != 0 )
v9 = (unsigned __int8)v16;
v10 = (v8[HIBYTE(v16)] & 0x4000) == 0;
v11 = 32;
if ( !v10 )
v11 = HIBYTE(v16);
printf(
"%04zx %02x %02x: %17s 0x%04x '%c''%c'\n",
0LL,
HIBYTE(v16),
(unsigned __int8)v16,
"magic 1",
v16,
v11,
v9);
break;
case 1LL:
v12 = *__ctype_b_loc();
v13 = 32;
if ( (v12[(unsigned __int8)v16] & 0x4000) != 0 )
v13 = (unsigned __int8)v16;
v10 = (v12[HIBYTE(v16)] & 0x4000) == 0;
v14 = 32;
if ( !v10 )
v14 = HIBYTE(v16);
printf(
"%04zx %02x %02x: %17s 0x%04x '%c''%c'\n",
1uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"magic 2",
v16,
v14,
v13);
break;
case 2LL:
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
2uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"binary format ver",
v16,
v16);
break;
case 3LL:
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
3uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"protocol ver",
v16,
v16);
break;
case 4LL:
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
4uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"prod identifier",
v16,
v16);
break;
case 5LL:
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
5uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"firmware version",
v16,
v16);
break;
case 6LL:
printf("%04zx %02x %02x: %17s 0x%04x (%d)\n", 6uLL, HIBYTE(v16), (unsigned __int8)v16, "id", v16, v16);
break;
case 7LL:
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
7uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"crc of nodeName",
v16,
v16);
break;
case 8LL:
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
8uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"crc of descr",
v16,
v16);
break;
case 9LL:
printf(" %17s\n", "---Bytecode Size----");
printf(
"%04zx %02x %02x: %17s 0x%04x (%d) ; in words\n",
9uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"bytcode size",
v16,
v16);
break;
default:
break;
}
}
LABEL_29:
++v6;
++v5;
}
while ( v4 == 2 );
}
result = 0;
if ( v4 == -1 )
{
perror("reading in bytecode");
result = *__errno_location();
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
ssize_t v4; // rbp
__int64 v5; // r13
__int64 v6; // r12
int result; // eax
const unsigned __int16 *v8; // rax
unsigned __int16 v9; // cx
bool v10; // zf
unsigned __int16 v11; // ax
const unsigned __int16 *v12; // rax
unsigned __int16 v13; // cx
unsigned __int16 v14; // ax
__int64 v15; // rax
unsigned __int16 v16; // bx
int v17; // eax
ssize_t v18; // rax
unsigned __int16 v19; // r15
unsigned __int16 v20; // cx
__int64 v21; // rbx
const char *v22; // rax
__int16 v23; // [rsp+Ch] [rbp-4Ch]
unsigned __int16 v24; // [rsp+Eh] [rbp-4Ah]
_WORD buf[29]; // [rsp+1Eh] [rbp-3Ah] BYREF

v3 = fileno(_bss_start);
v4 = read(v3, buf, 2uLL);
if ( v4 == 2 )
{
v5 = -10LL;
v23 = 0;
v24 = 0;
v6 = 0LL;
do
{
v16 = buf[0];
v17 = fileno(_bss_start);
v18 = read(v17, buf, 2uLL);
v4 = v18;
if ( !v18 )
{
printf(" %17s\n", "---Bytecode Check---");
printf(
"%04zx %02x %02x: %17s 0x%04x (%d) %s\n",
v6 - 10,
HIBYTE(v16),
(unsigned __int8)v16,
"last word",
v16,
v16,
"(crc-16 check sum only of bytecode)");
return 0;
}
if ( v18 > 0 )
{
if ( v6 == 10 )
{
printf(" %17s\n", "---Event Table------");
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
0LL,
HIBYTE(v16),
(unsigned __int8)v16,
"event block size",
v16,
v16);
v24 = v16;
}
else
{
v15 = v24 + 10LL;
if ( v15 <= v6 )
{
if ( v15 == v6 )
printf(" %17s\n", "---Bytecode Data----");
v19 = v16 >> 12;
if ( v23 )
{
printf(
"%04zx %02x %02x: %17s 0x%04x (%d/%d)\n",
v5,
HIBYTE(v16),
(unsigned __int8)v16,
"argument",
v16,
v16,
(unsigned int)(__int16)v16);
if ( !--v23 )
goto LABEL_42;
}
else
{
v20 = v16 & 0xFFF;
if ( v19 == 12 )
{
if ( v20 > 0x2Au )
printf("%04zx %01x %03x: %17s %s (%d)\n", v5, 12LL, v20, off_405260[0], "(undefined)", v20);
else
printf("%04zx %01x %03x: %17s %s (%d)\n", v5, 12LL, v20, off_405260[0], native[v16 & 0xFFF], v20);
}
else
{
if ( (v19 & 0xFFFD) == 8 )
{
if ( (unsigned __int8)v16 > 0x11u )
printf(
"%04zx %01x %03x: %17s %s (%d)\n",
v5,
v19,
v20,
bytecode_name[3 * (v19 & 0xF)],
"unknown",
(unsigned __int8)v16);
else
printf(
"%04zx %01x %03x: %17s %s (%d)\n",
v5,
v19,
v20,
bytecode_name[3 * (v19 & 0xF)],
bin_op_name[(unsigned __int8)v16],
(unsigned __int8)v16);
LABEL_42:
if ( v19 == 10 )
{
v23 = 1;
}
else if ( v19 <= 0xAu )
{
v23 = 1;
if ( v19 != 2 )
v23 = (unsigned __int16)(v19 - 5) <= 1u;
}
else
{
v23 = 2 * (v19 == 11);
}
goto LABEL_29;
}
if ( v19 == 7 )
{
if ( (v16 & 0xFC) != 0 )
printf(
"%04zx %01x %03x: %17s %s (%d)\n",
v5,
7LL,
v20,
off_4051E8[0],
"unknown",
(unsigned __int8)v16);
else
printf(
"%04zx %01x %03x: %17s %s (%d)\n",
v5,
7LL,
v20,
off_4051E8[0],
unary_op_name[(unsigned __int8)v16],
(unsigned __int8)v16);
}
else
{
if ( (unsigned __int16)(v19 - 3) > 1u )
{
printf(
"%04zx %01x %03x: %17s %d (%d)\n",
v5,
v19,
v20,
bytecode_name[3 * (v19 & 0xF)],
v20,
(unsigned int)((__int16)(16 * v16) >> 4));
goto LABEL_42;
}
v21 = v20;
v22 = func7(v20);
printf(
"%04zx %01x %03x: %17s %s (%d)\n",
v5,
v19,
(unsigned int)v21,
bytecode_name[3 * (v19 & 0xF)],
v22,
v21);
}
}
}
}
else if ( (((_BYTE)v5 - (_BYTE)v24) & 1) != 0 )
{
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
v5,
HIBYTE(v16),
(unsigned __int8)v16,
"event address",
v16,
v16);
}
else if ( v16 <= 0xFFEEu )
{
printf(
"%04zx %02x %02x: %17s 0x%04x (%d/%d/~%d) %s\n",
v5,
HIBYTE(v16),
(unsigned __int8)v16,
"event type",
v16,
v16,
(unsigned int)(__int16)v16,
(unsigned __int16)~v16,
"unknown");
}
else
{
printf(
"%04zx %02x %02x: %17s 0x%04x (%d/%d/~%d) %s\n",
v5,
255LL,
(unsigned __int8)v16,
"event type",
v16,
v16,
(unsigned int)(__int16)v16,
(unsigned __int16)~v16,
event_names[(unsigned __int16)~v16]);
}
}
}
else
{
switch ( v6 )
{
case 0LL:
printf(" %17s\n", "---Header-----------");
v8 = *__ctype_b_loc();
v9 = 32;
if ( (v8[(unsigned __int8)v16] & 0x4000) != 0 )
v9 = (unsigned __int8)v16;
v10 = (v8[HIBYTE(v16)] & 0x4000) == 0;
v11 = 32;
if ( !v10 )
v11 = HIBYTE(v16);
printf(
"%04zx %02x %02x: %17s 0x%04x '%c''%c'\n",
0LL,
HIBYTE(v16),
(unsigned __int8)v16,
"magic 1",
v16,
v11,
v9);
break;
case 1LL:
v12 = *__ctype_b_loc();
v13 = 32;
if ( (v12[(unsigned __int8)v16] & 0x4000) != 0 )
v13 = (unsigned __int8)v16;
v10 = (v12[HIBYTE(v16)] & 0x4000) == 0;
v14 = 32;
if ( !v10 )
v14 = HIBYTE(v16);
printf(
"%04zx %02x %02x: %17s 0x%04x '%c''%c'\n",
1uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"magic 2",
v16,
v14,
v13);
break;
case 2LL:
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
2uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"binary format ver",
v16,
v16);
break;
case 3LL:
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
3uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"protocol ver",
v16,
v16);
break;
case 4LL:
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
4uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"prod identifier",
v16,
v16);
break;
case 5LL:
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
5uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"firmware version",
v16,
v16);
break;
case 6LL:
printf("%04zx %02x %02x: %17s 0x%04x (%d)\n", 6uLL, HIBYTE(v16), (unsigned __int8)v16, "id", v16, v16);
break;
case 7LL:
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
7uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"crc of nodeName",
v16,
v16);
break;
case 8LL:
printf(
"%04zx %02x %02x: %17s 0x%04x (%d)\n",
8uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"crc of descr",
v16,
v16);
break;
case 9LL:
printf(" %17s\n", "---Bytecode Size----");
printf(
"%04zx %02x %02x: %17s 0x%04x (%d) ; in words\n",
9uLL,
HIBYTE(v16),
(unsigned __int8)v16,
"bytcode size",
v16,
v16);
break;
default:
break;
}
}
LABEL_29:
++v6;
++v5;
}
while ( v4 == 2 );
}
result = 0;
if ( v4 == -1 )
{
perror("reading in bytecode");
result = *__errno_location();
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 uint16_t code;
 uint16_t nextcode;
 ssize_t next;
 ssize_t counter=0;
 ssize_t numnative = sizeof(native) / sizeof(const char*);
 uint16_t events = 0;
 uint16_t succeeding = 0;
 next=read(fileno(stdin),&nextcode,2);
 while(2==next)
 {
  code = nextcode;
  next = read(fileno(stdin),&nextcode,2);
  if (next==0)
  {
   printf("                 %17s\n","---Bytecode Check---");
   printf("%04zx %02x %02x: %17s 0x%04x (%d) %s\n",counter-0x00a,(code>>8)&0xff,code&0xff,"last word",code,code,"(crc-16 check sum only of bytecode)");
   break;
  }
  uint16_t opcode = (code>>12);
  uint16_t argument = code & 0x0fff;
  int16_t sargument = ((int16_t)(code << 4)) >> 4;
  if (counter<0x00a)
  {
   switch(counter)
   {
    case 0x00:
     printf("                 %17s\n","---Header-----------");
     printf("%04zx %02x %02x: %17s 0x%04x '%c''%c'\n",counter,(code>>8)&0xff,code&0xff,"magic 1",code,((*__ctype_b_loc ())[(int) (((code>>8)&0xff))] & (unsigned short int) _ISprint)?(code>>8)&0xff:' ',((*__ctype_b_loc ())[(int) ((code&0xff))] & (unsigned short int) _ISprint)?code&0xff:' ');
     break;
    case 0x01:
     printf("%04zx %02x %02x: %17s 0x%04x '%c''%c'\n",counter,(code>>8)&0xff,code&0xff,"magic 2",code,((*__ctype_b_loc ())[(int) (((code>>8)&0xff))] & (unsigned short int) _ISprint)?(code>>8)&0xff:' ',((*__ctype_b_loc ())[(int) ((code&0xff))] & (unsigned short int) _ISprint)?code&0xff:' ');
     break;
    case 0x02:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"binary format ver",code,code);
     break;
    case 0x03:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"protocol ver",code,code);
     break;
    case 0x04:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"prod identifier",code,code);
     break;
    case 0x05:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"firmware version",code,code);
     break;
    case 0x06:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"id",code,code);
     break;
    case 0x07:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"crc of nodeName",code,code);
     break;
    case 0x08:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"crc of descr",code,code);
     break;
    case 0x09:
     printf("                 %17s\n","---Bytecode Size----");
     printf("%04zx %02x %02x: %17s 0x%04x (%d) ; in words\n",counter,(code>>8)&0xff,code&0xff,"bytcode size",code,code);
     break;
   }
  }
  else if (counter==0x00a)
  {
   printf("                 %17s\n","---Event Table------");
   printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter-0x00a,(code>>8)&0xff,code&0xff,"event block size",code,code);
   events = code;
  }
  else if (counter<0x00a+events)
  {
   if ((counter-0x00a-events)%2==0)
   {
    if ((sizeof(event_names)/sizeof(const char*))>((uint16_t)(~code)))
    {
     printf("%04zx %02x %02x: %17s 0x%04x (%d/%d/~%d) %s\n",counter-0x00a,(code>>8)&0xff,code&0xff,"event type",code,code,(int16_t)code,(uint16_t)(~code),event_names[(uint16_t)(~code)]);
    }
    else
    {
     printf("%04zx %02x %02x: %17s 0x%04x (%d/%d/~%d) %s\n",counter-0x00a,(code>>8)&0xff,code&0xff,"event type",code,code,(int16_t)code,(uint16_t)(~code),"unknown");
    }
   }
   else
   {
    printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter-0x00a,(code>>8)&0xff,code&0xff,"event address",code,code);
   }
  }
  else
  {
   if (counter==0x00a+events)
   {
    printf("                 %17s\n","---Bytecode Data----");
   }
   if (succeeding)
   {
    printf("%04zx %02x %02x: %17s 0x%04x (%d/%d)\n",counter-0x00a,(code>>8)&0xff,code&0xff,"argument",code,code,(int16_t)code);
    succeeding--;
   }
   else if (opcode==ASEBA_BYTECODE_NATIVE_CALL)
   {
    if (numnative>argument)
    {
     printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,native[argument],argument);
    }
    else
    {
     printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,"(undefined)",argument);
    }
   }
   else if (opcode== ASEBA_BYTECODE_BINARY_ARITHMETIC || opcode== ASEBA_BYTECODE_CONDITIONAL_BRANCH )
   {
    if ((sizeof(bin_op_name)/sizeof(const char*))>(argument&0xff))
    {
     printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,bin_op_name[argument&0xff],argument&0xff);
    }
    else
    {
     printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,"unknown",argument&0xff);
    }
   }
   else if (opcode== ASEBA_BYTECODE_UNARY_ARITHMETIC)
   {
    if ((sizeof(unary_op_name)/sizeof(const char*))>(argument&0xff))
    {
     printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,unary_op_name[argument&0xff],argument&0xff);
    }
    else
    {
     printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,"unknown",argument&0xff);
    }
   }
   else if (opcode==ASEBA_BYTECODE_STORE || opcode==ASEBA_BYTECODE_LOAD)
   {
    const char* name = variable_name_of_index(argument);
    printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,name,argument);
   }
   else
   {
    printf("%04zx %01x %03x: %17s %d (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,argument,sargument);
   }
   if (!succeeding)
   {
    switch (opcode)
    {
     case ASEBA_BYTECODE_LARGE_IMMEDIATE:
     case ASEBA_BYTECODE_LOAD_INDIRECT:
     case ASEBA_BYTECODE_STORE_INDIRECT:
     case ASEBA_BYTECODE_CONDITIONAL_BRANCH:
      succeeding = 1;
     break;
     case ASEBA_BYTECODE_EMIT:
      succeeding = 2;
     break;
    }
   }
  };
  counter++;
 };
 if (next==-1)
 {
  perror("reading in bytecode");
  return (*__errno_location ());
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned short code;
 unsigned short nextcode;
 long next;
 long counter = 0;
 long numnative = sizeof(native) / sizeof(const char*);
 unsigned short events = 0;
 unsigned short succeeding = 0;
 next=read(fileno(stdin),&nextcode,2);
 while(2==next)
 {
  code = nextcode;
  next = read(fileno(stdin),&nextcode,2);
  if (next==0)
  {
   printf("                 %17s\n","---Bytecode Check---");
   printf("%04zx %02x %02x: %17s 0x%04x (%d) %s\n",counter-0x00a,(code>>8)&0xff,code&0xff,"last word",code,code,"(crc-16 check sum only of bytecode)");
   break;
  }
  unsigned short opcode = (code>>12);
  unsigned short argument = code & 0x0fff;
  short sargument = ((int16_t)(code << 4)) >> 4;
  if (counter<0x00a)
  {
   switch(counter)
   {
    case 0x00:
     printf("                 %17s\n","---Header-----------");
     printf("%04zx %02x %02x: %17s 0x%04x '%c''%c'\n",counter,(code>>8)&0xff,code&0xff,"magic 1",code,((*__ctype_b_loc ())[(int) (((code>>8)&0xff))] & (unsigned short) _ISprint)?(code>>8)&0xff:' ',((*__ctype_b_loc ())[(int) ((code&0xff))] & (unsigned short) _ISprint)?code&0xff:' ');
     break;
    case 0x01:
     printf("%04zx %02x %02x: %17s 0x%04x '%c''%c'\n",counter,(code>>8)&0xff,code&0xff,"magic 2",code,((*__ctype_b_loc ())[(int) (((code>>8)&0xff))] & (unsigned short) _ISprint)?(code>>8)&0xff:' ',((*__ctype_b_loc ())[(int) ((code&0xff))] & (unsigned short) _ISprint)?code&0xff:' ');
     break;
    case 0x02:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"binary format ver",code,code);
     break;
    case 0x03:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"protocol ver",code,code);
     break;
    case 0x04:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"prod identifier",code,code);
     break;
    case 0x05:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"firmware version",code,code);
     break;
    case 0x06:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"id",code,code);
     break;
    case 0x07:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"crc of nodeName",code,code);
     break;
    case 0x08:
     printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter,(code>>8)&0xff,code&0xff,"crc of descr",code,code);
     break;
    case 0x09:
     printf("                 %17s\n","---Bytecode Size----");
     printf("%04zx %02x %02x: %17s 0x%04x (%d) ; in words\n",counter,(code>>8)&0xff,code&0xff,"bytcode size",code,code);
     break;
   }
  }
  else if (counter==0x00a)
  {
   printf("                 %17s\n","---Event Table------");
   printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter-0x00a,(code>>8)&0xff,code&0xff,"event block size",code,code);
   events = code;
  }
  else if (counter<0x00a+events)
  {
   if ((counter-0x00a-events)%2==0)
   {
    if ((sizeof(event_names)/sizeof(char *))>((unsigned short)(~code)))
    {
     printf("%04zx %02x %02x: %17s 0x%04x (%d/%d/~%d) %s\n",counter-0x00a,(code>>8)&0xff,code&0xff,"event type",code,code,(short)code,(unsigned short)(~code),event_names[(unsigned short)(~code)]);
    }
    else
    {
     printf("%04zx %02x %02x: %17s 0x%04x (%d/%d/~%d) %s\n",counter-0x00a,(code>>8)&0xff,code&0xff,"event type",code,code,(short)code,(unsigned short)(~code),"unknown");
    }
   }
   else
   {
    printf("%04zx %02x %02x: %17s 0x%04x (%d)\n",counter-0x00a,(code>>8)&0xff,code&0xff,"event address",code,code);
   }
  }
  else
  {
   if (counter==0x00a+events)
   {
    printf("                 %17s\n","---Bytecode Data----");
   }
   if (succeeding)
   {
    printf("%04zx %02x %02x: %17s 0x%04x (%d/%d)\n",counter-0x00a,(code>>8)&0xff,code&0xff,"argument",code,code,(short)code);
    succeeding--;
   }
   else if (opcode==ASEBA_BYTECODE_NATIVE_CALL)
   {
    if (numnative>argument)
    {
     printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,native[argument],argument);
    }
    else
    {
     printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,"(undefined)",argument);
    }
   }
   else if (opcode== ASEBA_BYTECODE_BINARY_ARITHMETIC || opcode== ASEBA_BYTECODE_CONDITIONAL_BRANCH )
   {
    if ((sizeof(bin_op_name)/sizeof(char *))>(argument&0xff))
    {
     printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,bin_op_name[argument&0xff],argument&0xff);
    }
    else
    {
     printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,"unknown",argument&0xff);
    }
   }
   else if (opcode== ASEBA_BYTECODE_UNARY_ARITHMETIC)
   {
    if ((sizeof(unary_op_name)/sizeof(char *))>(argument&0xff))
    {
     printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,unary_op_name[argument&0xff],argument&0xff);
    }
    else
    {
     printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,"unknown",argument&0xff);
    }
   }
   else if (opcode==ASEBA_BYTECODE_STORE || opcode==ASEBA_BYTECODE_LOAD)
   {
    char *name = variable_name_of_index(argument);
    printf("%04zx %01x %03x: %17s %s (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,name,argument);
   }
   else
   {
    printf("%04zx %01x %03x: %17s %d (%d)\n",counter-0x00a,opcode,argument,bytecode_name[opcode].name,argument,sargument);
   }
   if (!succeeding)
   {
    switch (opcode)
    {
     case ASEBA_BYTECODE_LARGE_IMMEDIATE:
     case ASEBA_BYTECODE_LOAD_INDIRECT:
     case ASEBA_BYTECODE_STORE_INDIRECT:
     case ASEBA_BYTECODE_CONDITIONAL_BRANCH:
      succeeding = 1;
     break;
     case ASEBA_BYTECODE_EMIT:
      succeeding = 2;
     break;
    }
   }
  };
  counter++;
 };
 if (next==-1)
 {
  perror("reading in bytecode");
  return (*__errno_location ());
 }
 return 0;
}

variable_types:
argv
char *[]

variable_types:
code
unsigned short

variable_types:
nextcode
unsigned short

variable_types: next long

variable_types: counter long

variable_types: numnative long

variable_types:
events
unsigned short

variable_types:
succeeding
unsigned short

variable_types:
opcode
unsigned short

variable_types:
argument
unsigned short

variable_types: sargument short

variable_types:
name
char *


repo: KAMEDAkyosuke/simple-apns-client

decompiled_code:
void __fastcall socketlist_free(void *ptr)
{
_QWORD *v1; // rbx
void *v2; // rdi

v1 = ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
_QWORD *v1; // rbx
void *v2; // rdi

v1 = ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
}
}

original_code:
void socketlist_free(socketlist_t* list)
{
    socketlist_t *current = list;
    while(current != ((void *)0)){
        socketlist_t* tmp = current;
        current = current->next;
        free(tmp);
        tmp = ((void *)0);
    }
}

canonical_original_code:
void socketlist_free(struct socketlist *list)
{
    struct socketlist *current = list;
    while(current != ((void *)0)){
        struct socketlist *tmp = current;
        current = current->next;
        free(tmp);
        tmp = ((void *)0);
    }
}

variable_types: struct socketlist { struct socketlist *next; int socket; _Bool is_closed; } *

return_type: void


decompiled_code:
_DWORD *tcp_server_new()
{
_DWORD *result; // rax

result = calloc(1uLL, 0x18uLL);
result[2] = 5;
*((_QWORD *)result + 2) = 0LL;
return result;
}

canonical_decompiled_code:
_DWORD *func1()
{
_DWORD *result; // rax

result = calloc(1uLL, 0x18uLL);
result[2] = 5;
*((_QWORD *)result + 2) = 0LL;
return result;
}

original_code:
tcp_server_ctx_t* tcp_server_new()
{
    tcp_server_ctx_t* ctx = (tcp_server_ctx_t*) calloc(1, sizeof(tcp_server_ctx_t));
    ctx->port = 0;
    ctx->listen_socket = 0;
    ctx->backlog = 5;
    ctx->client_sockets = ((void *)0);
    return ctx;
}

canonical_original_code:
struct tcp_server_ctx_t *tcp_server_new()
{
    struct tcp_server_ctx_t *ctx = (tcp_server_ctx_t*) calloc(1, sizeof(tcp_server_ctx_t));
    ctx->port = 0;
    ctx->listen_socket = 0;
    ctx->backlog = 5;
    ctx->client_sockets = ((void *)0);
    return ctx;
}

variable_types: struct tcp_server_ctx_t { int port; int listen_socket; int backlog; struct socketlist { struct socketlist *next; int socket; _Bool is_closed; } *client_sockets; } *

user_defined_types: struct tcp_server_ctx_t { int port; int listen_socket; int backlog; struct socketlist *client_sockets; }


decompiled_code:
__int64 __fastcall tcp_server_free(__int64 a1)
{
__int64 *i; // rbx

close(*(_DWORD *)(a1 + 4));
for ( i = *(__int64 **)(a1 + 16); i; i = (__int64 *)*i )
close(*((_DWORD *)i + 2));
return socketlist_free(*(_QWORD *)(a1 + 16));
}

original_code:
void tcp_server_free(const tcp_server_ctx_t* ctx)
{
    close(ctx->listen_socket);
    socketlist_t* tmp = ctx->client_sockets;
    while(tmp != ((void *)0)){
        close(tmp->socket);
        tmp = tmp->next;
    }
    socketlist_free(ctx->client_sockets);
}

canonical_original_code:
void tcp_server_free(struct tcp_server_ctx_t *ctx)
{
    close(ctx->listen_socket);
    struct socketlist *tmp = ctx->client_sockets;
    while(tmp != ((void *)0)){
        close(tmp->socket);
        tmp = tmp->next;
    }
    socketlist_free(ctx->client_sockets);
}

user_defined_types: struct socketlist { struct socketlist *next; int socket; _Bool is_closed; }


decompiled_code:
void __fastcall tcp_server_prepare_listen(__int64 a1)
{
int v1; // eax
struct sockaddr v2; // [rsp+0h] [rbp-28h] BYREF
int optval[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v1 = socket(2, 1, 0);
*(_DWORD *)(a1 + 4) = v1;
if ( v1 == -1 )
{
perror("socket error");
exit(1);
}
optval[0] = 1;
if ( setsockopt(v1, 1, 2, optval, 4u) == -1 )
{
perror("setsockopt error");
exit(1);
}
*(_QWORD *)&v2.sa_family = 2LL;
*(_QWORD *)&v2.sa_data[6] = 0LL;
*(_WORD *)v2.sa_data = _bswap_16(*(_WORD *)a1);
if ( bind(*(_DWORD *)(a1 + 4), &v2, 0x10u) == -1 )
{
perror("bind error");
exit(1);
}
if ( listen(*(_DWORD *)(a1 + 4), *(_DWORD *)(a1 + 8)) )
perror("listen error");
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
int v1; // eax
struct sockaddr v2; // [rsp+0h] [rbp-28h] BYREF
int optval[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v1 = socket(2, 1, 0);
*(_DWORD *)(a1 + 4) = v1;
if ( v1 == -1 )
{
perror("socket error");
exit(1);
}
optval[0] = 1;
if ( setsockopt(v1, 1, 2, optval, 4u) == -1 )
{
perror("setsockopt error");
exit(1);
}
*(_QWORD *)&v2.sa_family = 2LL;
*(_QWORD *)&v2.sa_data[6] = 0LL;
*(_WORD *)v2.sa_data = func0(*(_WORD *)a1);
if ( bind(*(_DWORD *)(a1 + 4), &v2, 0x10u) == -1 )
{
perror("bind error");
exit(1);
}
if ( listen(*(_DWORD *)(a1 + 4), *(_DWORD *)(a1 + 8)) )
perror("listen error");
}

original_code:
void tcp_server_prepare_listen(tcp_server_ctx_t* ctx)
{
    if((ctx->listen_socket = socket(2, SOCK_STREAM, 0)) == -1){
        perror("socket error");
        exit(1);
    }
    int on = 1;
    if(setsockopt(ctx->listen_socket, 1, 2, &on, sizeof(on)) == -1){
        perror("setsockopt error");
        exit(1);
    }
    struct sockaddr_in addr;
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = 2;
    addr.sin_port = htons(ctx->port);
    addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    if(bind(ctx->listen_socket, (struct sockaddr*) &addr, sizeof(addr)) == -1){
        perror("bind error");
        exit(1);
    }
    if(listen(ctx->listen_socket, ctx->backlog) != 0){
        perror("listen error");
    }
}

canonical_original_code:
void tcp_server_prepare_listen(struct tcp_server_ctx_t *ctx)
{
    if((ctx->listen_socket = socket(2, SOCK_STREAM, 0)) == -1){
        perror("socket error");
        exit(1);
    }
    int on = 1;
    if(setsockopt(ctx->listen_socket, 1, 2, &on, sizeof(on)) == -1){
        perror("setsockopt error");
        exit(1);
    }
    struct sockaddr_in addr;
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = 2;
    addr.sin_port = htons(ctx->port);
    addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
    if(bind(ctx->listen_socket, (struct sockaddr *) &addr, sizeof(addr)) == -1){
        perror("bind error");
        exit(1);
    }
    if(listen(ctx->listen_socket, ctx->backlog) != 0){
        perror("listen error");
    }
}

variable_types: on int

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

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

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


decompiled_code:
__int64 __fastcall accept_socket(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebx
int v3; // eax
__int64 result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
v1 = accept(*(_DWORD *)(a1 + 4), &addr, &addr_len);
if ( v1 < 0 )
{
perror("accept error");
exit(1);
}
v2 = v1;
v3 = fcntl(v1, 3, 0LL);
if ( v3 < 0 )
{
perror("fcntl(F_GETFL) failed");
exit(1);
}
BYTE1(v3) |= 8u;
if ( fcntl(v2, 4, (unsigned int)v3) < 0 )
{
perror("fcntl(F_SETFL) failed");
exit(1);
}
result = socketlist_append(*(_QWORD *)(a1 + 16), v2);
*(_QWORD *)(a1 + 16) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebx
int v3; // eax
__int64 result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
v1 = accept(*(_DWORD *)(a1 + 4), &addr, &addr_len);
if ( v1 < 0 )
{
perror("accept error");
exit(1);
}
v2 = v1;
v3 = fcntl(v1, 3, 0LL);
if ( v3 < 0 )
{
perror("fcntl(F_GETFL) failed");
exit(1);
}
BYTE1(v3) |= 8u;
if ( fcntl(v2, 4, (unsigned int)v3) < 0 )
{
perror("fcntl(F_SETFL) failed");
exit(1);
}
result = socketlist_append(*(_QWORD *)(a1 + 16), v2);
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void accept_socket(tcp_server_ctx_t* ctx)
{
    struct sockaddr_in client_addr;
    socklen_t client_len = sizeof(client_addr);
    int client_sd = accept(ctx->listen_socket, (struct sockaddr *)&client_addr, &client_len);
    if(client_sd < 0){
        perror("accept error");
        exit(1);
    }
    int flags;
    flags = fcntl(client_sd, 3, 0);
    if (flags < 0) {
        perror("fcntl(F_GETFL) failed");
        exit(1);
    }
    if (fcntl(client_sd, 4, flags | 04000) < 0) {
        perror("fcntl(F_SETFL) failed");
        exit(1);
    }
    ctx->client_sockets = socketlist_append(ctx->client_sockets, client_sd);
}

canonical_original_code:
void accept_socket(struct tcp_server_ctx_t *ctx)
{
    struct sockaddr_in client_addr;
    unsigned int client_len = sizeof(client_addr);
    int client_sd = accept(ctx->listen_socket, (struct sockaddr *)&client_addr, &client_len);
    if(client_sd < 0){
        perror("accept error");
        exit(1);
    }
    int flags;
    flags = fcntl(client_sd, 3, 0);
    if (flags < 0) {
        perror("fcntl(F_GETFL) failed");
        exit(1);
    }
    if (fcntl(client_sd, 4, flags | 04000) < 0) {
        perror("fcntl(F_SETFL) failed");
        exit(1);
    }
    ctx->client_sockets = socketlist_append(ctx->client_sockets, client_sd);
}

variable_types: flags int


repo: KGardevoir/StructureLib

decompiled_code:
__int64 __fastcall slist_length(_QWORD *a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = 0LL;
do
{
a1 = (_QWORD *)*a1;
++result;
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
do
{
a1 = (_QWORD *)*a1;
++result;
}
while ( a1 );
return result;
}

original_code:
size_t
slist_length(slist *head){
 if(head == ((void *)0)) return 0;
 slist *run = head;
 size_t i = 0;
 for(; run; run = run->next, i++);
 return i;
}

canonical_original_code:
unsigned long slist_length(struct slist *head){
 if(head == ((void *)0)) return 0;
 struct slist *run = head;
 unsigned long i = 0;
 for(; run; run = run->next, i++);
 return i;
}

variable_types: struct slist { struct slist *next; struct Object { struct Object_vtable { unsigned long (*hash)(struct Object *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } *method; } *data; } *

variable_types:
i
unsigned long

return_type: unsigned long

user_defined_types: struct slist { struct slist *next; struct Object *data; }

user_defined_types: struct Object { struct Object_vtable *method; }

user_defined_types: struct Object_vtable { unsigned long (*hash)(struct Object *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN (*equals)(struct Object *self, void *oth); unsigned long size; }


original_code:
slist*
slist_popback(slist *head, Object** data, BOOLEAN destroy_data){
 if(!head) return ((void *)0);
 slist *run = head;
 if(!run->next){
  if(data) *data = run->next->data;
  if(destroy_data) do{ if((run->data && run->data->method && run->data->method->destroy)) run->data->method->destroy ((void*)run->data); } while(0);
  free(run);
  return ((void *)0);
 }
 for(; run->next && run->next->next; run = run->next);
 if(data) *data = run->next->data;
 if(destroy_data) do{ if((run->next->data && run->next->data->method && run->next->data->method->destroy)) run->next->data->method->destroy ((void*)run->next->data); } while(0);
 free(run->next);
 run->next = ((void *)0);
 return head;
}

canonical_original_code:
struct slist *slist_popback(struct slist *head, struct Object **data, enum BOOLEAN destroy_data){
 if(!head) return ((void *)0);
 struct slist *run = head;
 if(!run->next){
  if(data) *data = run->next->data;
  if(destroy_data) do{ if((run->data && run->data->method && run->data->method->destroy)) run->data->method->destroy ((void *)run->data); } while(0);
  free(run);
  return ((void *)0);
 }
 for(; run->next && run->next->next; run = run->next);
 if(data) *data = run->next->data;
 if(destroy_data) do{ if((run->next->data && run->next->data->method && run->next->data->method->destroy)) run->next->data->method->destroy ((void *)run->next->data); } while(0);
 free(run->next);
 run->next = ((void *)0);
 return head;
}

variable_types:
head
struct slist *

variable_types:
data
struct Object **

return_type: struct slist { struct slist *next; struct Object { struct Object_vtable { unsigned long (*hash)(struct Object *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } *method; } *data; } *


decompiled_code:
__int64 __fastcall slist_popfront(void *ptr, _QWORD *a2, int a3)
{
__int64 v4; // rbp
__int64 v5; // rdi
void (*v6)(void); // rax

if ( !ptr )
return 0LL;
v4 = *(_QWORD *)ptr;
if ( a2 )
*a2 = *((_QWORD *)ptr + 1);
if ( a3 )
{
v5 = *((_QWORD *)ptr + 1);
if ( v5 )
{
if ( *(_QWORD *)v5 )
{
v6 = *(void (**)(void))(*(_QWORD *)v5 + 16LL);
if ( v6 )
v6();
}
}
}
free(ptr);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr, _QWORD *a2, int a3)
{
__int64 v4; // rbp
__int64 v5; // rdi
void (*v6)(void); // rax

if ( !ptr )
return 0LL;
v4 = *(_QWORD *)ptr;
if ( a2 )
*a2 = *((_QWORD *)ptr + 1);
if ( a3 )
{
v5 = *((_QWORD *)ptr + 1);
if ( v5 )
{
if ( *(_QWORD *)v5 )
{
v6 = *(void (**)(void))(*(_QWORD *)v5 + 16LL);
if ( v6 )
v6();
}
}
}
free(ptr);
return v4;
}

original_code:
slist*
slist_popfront(slist *head, Object** data, BOOLEAN destroy_data){
 slist *run = head;
 if(!head) return head;
 run = head;
 head = head->next;
 if(data) *data = run->data;
 if(destroy_data) do{ if((run->data && run->data->method && run->data->method->destroy)) run->data->method->destroy ((void*)run->data); } while(0);
 free(run);
 return head;
}

canonical_original_code:
struct slist *slist_popfront(struct slist *head, struct Object **data, enum BOOLEAN destroy_data){
 struct slist *run = head;
 if(!head) return head;
 run = head;
 head = head->next;
 if(data) *data = run->data;
 if(destroy_data) do{ if((run->data && run->data->method && run->data->method->destroy)) run->data->method->destroy ((void *)run->data); } while(0);
 free(run);
 return head;
}

variable_types: enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 }


decompiled_code:
__int64 __fastcall slist_has(_QWORD *a1, _QWORD *a2)
{
if ( !a1 )
return 0LL;
if ( a1 == a2 )
return 0xFFFFFFFFLL;
while ( 1 )
{
a1 = (_QWORD *)*a1;
if ( !a1 )
break;
if ( a2 == a1 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, _QWORD *a2)
{
if ( !a1 )
return 0LL;
if ( a1 == a2 )
return 0xFFFFFFFFLL;
while ( 1 )
{
a1 = (_QWORD *)*a1;
if ( !a1 )
break;
if ( a2 == a1 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
BOOLEAN
slist_has(slist *head, slist* node){
 slist *run;
 for((run) = (head); run; (run)=(run)->next)
  if(run == node) return TRUE;
 return FALSE;
}

canonical_original_code:
enum BOOLEAN slist_has(struct slist *head, struct slist *node){
 struct slist *run;
 for((run) = (head); run; (run)=(run)->next)
  if(run == node) return TRUE;
 return FALSE;
}

variable_types:
node
struct slist *

return_type: enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 }


decompiled_code:
__int64 __fastcall slist_head(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return a1;
}

original_code:
slist *
slist_head(slist *head){
 return head;
}

canonical_original_code:
struct slist *slist_head(struct slist *head){
 return head;
}

user_defined_types: enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 }


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

if ( !a1 )
return -1LL;
if ( a1 == a2 )
return 0LL;
result = 0LL;
while ( 1 )
{
++result;
a1 = (_QWORD *)*a1;
if ( !a1 )
break;
if ( a2 == a1 )
return result;
}
return -1LL;
}

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

if ( !a1 )
return -1LL;
if ( a1 == a2 )
return 0LL;
result = 0LL;
while ( 1 )
{
++result;
a1 = (_QWORD *)*a1;
if ( !a1 )
break;
if ( a2 == a1 )
return result;
}
return -1LL;
}

original_code:
size_t
slist_loc(slist *head, slist *node){
 slist *run;
 size_t i = 0;
 for((run) = (head); run; (run)=(run)->next){
  if(run == node) return i;
  i++;
 }
 return -1;
}

canonical_original_code:
unsigned long slist_loc(struct slist *head, struct slist *node){
 struct slist *run;
 unsigned long i = 0;
 for((run) = (head); run; (run)=(run)->next){
  if(run == node) return i;
  i++;
 }
 return -1;
}


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

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

original_code:
void
splaytree_destroy(splaytree *root){
 free(root);
}

canonical_original_code:
void splaytree_destroy(struct splaytree *root){
 free(root);
}

variable_types: struct splaytree { unsigned long size; struct Comparable_vtable { long (*compare)(void *self, void *oth); } *data_method; struct btree { struct btree *right; struct Object { struct Object_vtable { unsigned long (*hash)(struct Object *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } *method; } *data; struct btree *left; } *root; } *

user_defined_types: struct splaytree { unsigned long size; struct Comparable_vtable *data_method; struct btree *root; }

user_defined_types: struct btree { struct btree *right; struct Object *data; struct btree *left; }


original_code:
BOOLEAN
splay_insert(splaytree* root, Object* data, BOOLEAN copy){
 btree* n;
 long c;
 if(!root) return FALSE;
 if(!root->root){
  root->root = new_splaynode(data, copy);
  root->size++;
  return TRUE;
 } else {
  root->root = splay(root->root, data, root->data_method);
 }
 if((c = root->data_method->compare(data, (Object*)root->root->data)) == 0) return FALSE;
 n = new_splaynode(data, copy);
 if(c < 0){
  n->left = root->root->left;
  n->right = root->root;
  root->root->left = ((void *)0);
 } else {
  n->right = root->root->right;
  n->left = root->root;
  root->root->right = ((void *)0);
 }
 root->size++;
 root->root = n;
 return TRUE;
}

canonical_original_code:
enum BOOLEAN splay_insert(struct splaytree *root, struct Object *data, enum BOOLEAN copy){
 struct btree *n;
 long c;
 if(!root) return FALSE;
 if(!root->root){
  root->root = new_splaynode(data, copy);
  root->size++;
  return TRUE;
 } else {
  root->root = splay(root->root, data, root->data_method);
 }
 if((c = root->data_method->compare(data, (struct Object *)root->root->data)) == 0) return FALSE;
 n = new_splaynode(data, copy);
 if(c < 0){
  n->left = root->root->left;
  n->right = root->root;
  root->root->left = ((void *)0);
 } else {
  n->right = root->root->right;
  n->left = root->root;
  root->root->right = ((void *)0);
 }
 root->size++;
 root->root = n;
 return TRUE;
}

variable_types:
data
struct Object *

variable_types: struct btree { struct btree *right; struct Object { struct Object_vtable { unsigned long (*hash)(struct Object *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } *method; } *data; struct btree *left; } *

variable_types: c long

user_defined_types: struct Comparable_vtable { long (*compare)(void *self, void *oth); }


original_code:
Object*
splay_remove(splaytree* root, Object *key, const Comparable_vtable *key_method, BOOLEAN destroy_data){
 if(!root || !root->root) return ((void *)0);
 root->root = splay(root->root, key, key_method);
 Object *rtn = ((void *)0);
 if(key_method->compare(key, (Object*)root->root->data) == 0){
  btree *del = root->root;
  rtn = del->data;
  if(destroy_data){
   do{ if((rtn && rtn->method && rtn->method->destroy)) rtn->method->destroy ((void*)rtn); } while(0);
  }
  if(!del->left){
   root->root = del->right;
  } else {
   btree* x = del->right;
   root->root = splay(del->left, key, key_method);
   root->root->right = x;
  }
  free(del);
  root->size--;
 }
 return rtn;
}

canonical_original_code:
struct Object *splay_remove(struct splaytree *root, struct Object *key, struct Comparable_vtable *key_method, enum BOOLEAN destroy_data){
 if(!root || !root->root) return ((void *)0);
 root->root = splay(root->root, key, key_method);
 struct Object *rtn = ((void *)0);
 if(key_method->compare(key, (struct Object *)root->root->data) == 0){
  struct btree *del = root->root;
  rtn = del->data;
  if(destroy_data){
   do{ if((rtn && rtn->method && rtn->method->destroy)) rtn->method->destroy ((void *)rtn); } while(0);
  }
  if(!del->left){
   root->root = del->right;
  } else {
   struct btree *x = del->right;
   root->root = splay(del->left, key, key_method);
   root->root->right = x;
  }
  free(del);
  root->size--;
 }
 return rtn;
}

variable_types: struct splaytree { unsigned long size; struct Comparable_vtable { long (*compare)(void *self, void *oth); } *data_method; struct btree { struct btree *right; struct Object *data; struct btree *left; } *root; } *

variable_types:
key
struct Object *

variable_types: struct Object { struct Object_vtable { unsigned long (*hash)(struct Object *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } *method; } *


decompiled_code:
__int64 __fastcall splay_find(__int64 a1, __int64 a2, __int64 (__fastcall **a3)(__int64, _QWORD))
{
__int64 result; // rax
_QWORD *v5; // rax
__int64 v6; // rdx

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 16);
if ( result )
{
v5 = splay(*(_QWORD **)(a1 + 16), a2, a3);
*(_QWORD *)(a1 + 16) = v5;
v6 = (*a3)(a2, v5[1]);
result = 0LL;
if ( !v6 )
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 (__fastcall **a3)(__int64, _QWORD))
{
__int64 result; // rax
_QWORD *v5; // rax
__int64 v6; // rdx

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 16);
if ( result )
{
v5 = splay(*(_QWORD **)(a1 + 16), a2, a3);
*(_QWORD *)(a1 + 16) = v5;
v6 = (*a3)(a2, v5[1]);
result = 0LL;
if ( !v6 )
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL);
}
return result;
}

original_code:
Object*
splay_find(splaytree* root, Object* key, const Comparable_vtable *key_method){
 if(!root || !root->root) return ((void *)0);
 root->root = splay(root->root, key, key_method);
 if(key_method->compare(key, (Object*)root->root->data) == 0) return root->root->data;
 return ((void *)0);
}

canonical_original_code:
struct Object *splay_find(struct splaytree *root, struct Object *key, struct Comparable_vtable *key_method){
 if(!root || !root->root) return ((void *)0);
 root->root = splay(root->root, key, key_method);
 if(key_method->compare(key, (struct Object *)root->root->data) == 0) return root->root->data;
 return ((void *)0);
}

return_type: struct Object { struct Object_vtable { unsigned long (*hash)(struct Object *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } *method; } *


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

if ( !a2 )
return 0LL;
result = *(_QWORD *)(a2 + 16);
if ( result == a1 )
result = 0LL;
return result;
}

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

if ( !a2 )
return 0LL;
result = *(_QWORD *)(a2 + 16);
if ( result == a1 )
result = 0LL;
return result;
}

original_code: static inline dlist* dlist_prev(dlist *head, dlist *run){ if(!run || run->prev == head) return ((void *)0); return run->prev; }

canonical_original_code: static inline struct dlist *dlist_prev(struct dlist *head, struct dlist *run){ if(!run || run->prev == head) return ((void *)0); return run->prev; }

variable_types:
head
struct dlist *

variable_types:
run
struct dlist *

return_type: struct dlist { struct dlist *next; struct Object { struct Object_vtable { unsigned long (*hash)(struct Object *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } *method; } *data; struct dlist *prev; } *

user_defined_types: struct dlist { struct dlist *next; struct Object *data; struct dlist *prev; }


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

result = a1;
if ( a1 )
result = *(_QWORD *)(a1 + 16);
return result;
}

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

result = a1;
if ( a1 )
result = *(_QWORD *)(a1 + 16);
return result;
}

original_code: static inline dlist* dlist_tail(dlist *head){ if(head) return head->prev; return head; }

canonical_original_code: static inline struct dlist *dlist_tail(struct dlist *head){ if(head) return head->prev; return head; }


isABalanced

decompiled_code:
_BOOL8 __fastcall isABalanced(__int64 a1, __int64 a2, __int64 *a3, __int64 *a4)
{
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // rax
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // xmm1_8
_BOOL8 result; // rax
double v13; // xmm1_8
__int64 v14[5]; // [rsp+8h] [rbp-28h] BYREF

v14[0] = 0LL;
v5 = *a4;
v6 = btree_sibling(a3, a2);
btree_info(v6, 0LL, 0LL, 0LL, 0LL, v14, 0LL, 0LL);
v7 = v14[0];
v8 = v14[0] + v5 + 1;
*a4 = v8;
if ( v8 < 0 )
v9 = (double)(int)(v8 & 1 | ((unsigned __int64)v8 >> 1)) + (double)(int)(v8 & 1 | ((unsigned __int64)v8 >> 1));
else
v9 = (double)(int)v8;
v10 = v9 * *(double *)(a1 + 16);
if ( v5 < 0 )
v11 = (double)(int)(v5 & 1 | ((unsigned __int64)v5 >> 1)) + (double)(int)(v5 & 1 | ((unsigned __int64)v5 >> 1));
else
v11 = (double)(int)v5;
result = 0LL;
if ( v10 >= v11 )
{
if ( v7 < 0 )
v13 = (double)(int)(v7 & 1 | ((unsigned __int64)v7 >> 1)) + (double)(int)(v7 & 1 | ((unsigned __int64)v7 >> 1));
else
v13 = (double)(int)v7;
result = v10 >= v13;
}
return result;
}

original_code:
static inline BOOLEAN
isABalanced(scapegoat *goat, btree* run, btree* parent, size_t *size){
 size_t a = 0, b = 0;
 a = *size;
 btree_info(btree_sibling(parent, run), ((void *)0), ((void *)0), ((void *)0), ((void *)0), &b, ((void *)0), ((void *)0));
 *size = a+1+b;
 return (a <= (goat->a*(a+1+b))) && (b <= (goat->a*(a+1+b)));
}

canonical_original_code:
static inline enum BOOLEAN isABalanced(struct scapegoat *goat, struct btree *run, struct btree *parent, unsigned long *size){
 unsigned long a = 0; unsigned long b = 0;
 a = *size;
 btree_info(btree_sibling(parent, run), ((void *)0), ((void *)0), ((void *)0), ((void *)0), &b, ((void *)0), ((void *)0));
 *size = a+1+b;
 return (a <= (goat->a*(a+1+b))) && (b <= (goat->a*(a+1+b)));
}

variable_types: struct scapegoat { unsigned long size; unsigned long max_size; double a; double inv_log_a_inv; struct Comparable_vtable { long (*compare)(void *self, void *oth); } *data_method; struct btree { struct btree *right; struct Object { struct Object_vtable { unsigned long (*hash)(struct Object *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } *method; } *data; struct btree *left; } *root; } *

variable_types:
run
struct btree *

variable_types:
parent
struct btree *

variable_types:
size
unsigned long *

variable_types:
a
unsigned long

variable_types:
b
unsigned long

user_defined_types: struct scapegoat { unsigned long size; unsigned long max_size; double a; double inv_log_a_inv; struct Comparable_vtable *data_method; struct btree *root; }


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

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

original_code:
void
scapegoat_destroy(scapegoat* goat){
 free(goat);
}

canonical_original_code:
void scapegoat_destroy(struct scapegoat *goat){
 free(goat);
}


original_code:
Object *
scapegoat_remove(scapegoat* goat, Object* key, const Comparable_vtable *key_method, BOOLEAN destroy_data){
 Object *data = ((void *)0);
 BOOLEAN success = FALSE;
 btree *tr = btree_remove(goat->root, key, key_method, &data, destroy_data, &success);
 if(success){
  goat->size--;
  goat->root = tr;
  if(goat->size < goat->a*goat->max_size){
   goat->root = btree_balance(goat->root);
   goat->max_size = goat->size;
  }
 }
 return data;
}

canonical_original_code:
struct Object *scapegoat_remove(struct scapegoat *goat, struct Object *key, struct Comparable_vtable *key_method, enum BOOLEAN destroy_data){
 struct Object *data = ((void *)0);
 enum BOOLEAN success = FALSE;
 struct btree *tr = btree_remove(goat->root, key, key_method, &data, destroy_data, &success);
 if(success){
  goat->size--;
  goat->root = tr;
  if(goat->size < goat->a*goat->max_size){
   goat->root = btree_balance(goat->root);
   goat->max_size = goat->size;
  }
 }
 return data;
}

variable_types: struct scapegoat { unsigned long size; unsigned long max_size; double a; double inv_log_a_inv; struct Comparable_vtable { long (*compare)(void *self, void *oth); } *data_method; struct btree { struct btree *right; struct Object *data; struct btree *left; } *root; } *

variable_types: enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 }


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

result = btree_find(*(_QWORD *)(a1 + 40));
if ( result )
result = *(_QWORD *)(result + 8);
return result;
}

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

result = btree_find(*(_QWORD *)(a1 + 40));
if ( result )
result = *(_QWORD *)(result + 8);
return result;
}

original_code:
Object*
scapegoat_find(scapegoat* goat, Object* data, const Comparable_vtable *data_method){
 btree *found = btree_find(goat->root, data, data_method);
 return found?found->data:((void *)0);
}

canonical_original_code:
struct Object *scapegoat_find(struct scapegoat *goat, struct Object *data, struct Comparable_vtable *data_method){
 struct btree *found = btree_find(goat->root, data, data_method);
 return found?found->data:((void *)0);
}


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

if ( !a2 )
return 0LL;
result = *a2;
if ( *a2 == a1 )
result = 0LL;
return result;
}

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

if ( !a2 )
return 0LL;
result = *a2;
if ( *a2 == a1 )
result = 0LL;
return result;
}

original_code: static inline dlist* dlist_next(dlist *head, dlist *run){ if(!run || run->next == head) return ((void *)0); return run->next; }

canonical_original_code: static inline struct dlist *dlist_next(struct dlist *head, struct dlist *run){ if(!run || run->next == head) return ((void *)0); return run->next; }


decompiled_code:
__int64 __fastcall graph_tree_iterator_post_next(_QWORD *a1)
{
__int64 result; // rax
_QWORD *v3; // rdi
void (*v4)(void); // rax
_QWORD *v5; // [rsp+8h] [rbp-10h] BYREF

result = a1[1];
if ( result )
{
a1[1] = dlist_popback(a1[1], &v5, 0LL);
v3 = v5;
a1[3] = v5[1];
a1[2] = v3[2];
if ( *v3 )
{
v4 = *(void (**)(void))(*v3 + 16LL);
if ( v4 )
v4();
}
result = a1[2];
}
else
{
a1[2] = 0LL;
a1[3] = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 result; // rax
_QWORD *v3; // rdi
void (*v4)(void); // rax
_QWORD *v5; // [rsp+8h] [rbp-10h] BYREF

result = a1[1];
if ( result )
{
a1[1] = dlist_popback(a1[1], &v5, 0LL);
v3 = v5;
a1[3] = v5[1];
a1[2] = v3[2];
if ( *v3 )
{
v4 = *(void (**)(void))(*v3 + 16LL);
if ( v4 )
v4();
}
result = a1[2];
}
else
{
a1[2] = 0LL;
a1[3] = 0LL;
}
return result;
}

original_code:
graph*
graph_tree_iterator_post_next(graph_tree_iterator_post* self){
 if(!self->i_stk){
  self->r_current = ((void *)0);
  self->r_depth = 0;
  return ((void *)0);
 }
 node_info *g;
 self->i_stk = dlist_popback(self->i_stk, (Object**)&g, FALSE);
 self->r_depth = g->depth;
 self->r_current = (graph*)g->node;
 do{ if((g && g->method && g->method->destroy)) g->method->destroy ((void*)g); } while(0);
 return self->r_current;
}

canonical_original_code:
struct graph *graph_tree_iterator_post_next(struct graph_tree_iterator_post *self){
 if(!self->i_stk){
  self->r_current = ((void *)0);
  self->r_depth = 0;
  return ((void *)0);
 }
 struct node_info *g;
 self->i_stk = dlist_popback(self->i_stk, (struct Object **)&g, FALSE);
 self->r_depth = g->depth;
 self->r_current = (struct graph *)g->node;
 do{ if((g && g->method && g->method->destroy)) g->method->destroy ((void *)g); } while(0);
 return self->r_current;
}

variable_types: struct graph_tree_iterator_post { struct graph *i_root; struct dlist *i_stk; struct graph *r_current; unsigned long r_depth; } *

variable_types: struct node_info { struct Object_vtable { unsigned long (*hash)(struct Object { struct Object_vtable *method; } *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } *method; unsigned long depth; struct graph { struct graph_vtable { struct Object_vtable parent; struct Comparable_vtable { long (*compare)(void *self, void *oth); } comparable; } *method; struct Object *data; struct dlist { struct dlist *next; struct Object *data; struct dlist *prev; } *edges; } *node; } *

return_type: struct graph { struct graph_vtable { struct Object_vtable { unsigned long (*hash)(struct Object { struct Object_vtable *method; } *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } parent; struct Comparable_vtable { long (*compare)(void *self, void *oth); } comparable; } *method; struct Object *data; struct dlist { struct dlist *next; struct Object *data; struct dlist *prev; } *edges; } *

user_defined_types: struct node_info { struct Object_vtable *method; unsigned long depth; struct graph *node; }

user_defined_types: struct graph { struct graph_vtable *method; struct Object *data; struct dlist *edges; }

user_defined_types: struct graph_vtable { struct Object_vtable parent; struct Comparable_vtable comparable; }


original_code:
graph*
graph_tree_iterator_pre_next(graph_tree_iterator_pre* self){
 if(self->i_children){
  if(self->p_add_children){
   self->i_stk = dlist_concat(self->i_children, self->i_stk);
  } else {
   dlist_clear(self->i_children, TRUE);
  }
  self->i_children = ((void *)0);
 }
 if(!self->i_stk){
  self->r_current = ((void *)0);
  self->r_depth = 0;
  self->p_add_children = TRUE;
  return ((void *)0);
 }
 node_info *g;
 self->i_stk = dlist_popfront(self->i_stk, (Object**)&g, FALSE);
 dlist *new_list = dlist_copy(g->node->edges, FALSE);
 dlist *run;
 for((run) = (new_list); (run) != ((void *)0); (run) = dlist_next(new_list, run)){
  run->data = (void*)node_info_new((graph*)run->data, g->depth+1);
 }
 self->i_children = new_list;
 self->r_depth = g->depth;
 self->r_current = (graph*)g->node;
 self->p_add_children = TRUE;
 do{ if((g && g->method && g->method->destroy)) g->method->destroy ((void*)g); } while(0);
 return self->r_current;
}

canonical_original_code:
struct graph *graph_tree_iterator_pre_next(struct graph_tree_iterator_pre *self){
 if(self->i_children){
  if(self->p_add_children){
   self->i_stk = dlist_concat(self->i_children, self->i_stk);
  } else {
   dlist_clear(self->i_children, TRUE);
  }
  self->i_children = ((void *)0);
 }
 if(!self->i_stk){
  self->r_current = ((void *)0);
  self->r_depth = 0;
  self->p_add_children = TRUE;
  return ((void *)0);
 }
 struct node_info *g;
 self->i_stk = dlist_popfront(self->i_stk, (struct Object **)&g, FALSE);
 struct dlist *new_list = dlist_copy(g->node->edges, FALSE);
 struct dlist *run;
 for((run) = (new_list); (run) != ((void *)0); (run) = dlist_next(new_list, run)){
  run->data = (void *)node_info_new((struct graph *)run->data, g->depth+1);
 }
 self->i_children = new_list;
 self->r_depth = g->depth;
 self->r_current = (struct graph *)g->node;
 self->p_add_children = TRUE;
 do{ if((g && g->method && g->method->destroy)) g->method->destroy ((void *)g); } while(0);
 return self->r_current;
}

variable_types: struct graph_tree_iterator_pre { struct graph *i_root; struct dlist *i_stk; struct graph *r_current; unsigned long r_depth; enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } p_add_children; } *

variable_types: struct dlist { struct dlist *next; struct Object { struct Object_vtable { unsigned long (*hash)(struct Object *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } *method; } *data; struct dlist *prev; } *

user_defined_types: struct graph_tree_iterator_pre { struct graph *i_root; struct dlist *i_stk; struct graph *r_current; unsigned long r_depth; enum BOOLEAN p_add_children; }


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

dlist_clear(*(_QWORD *)(a1 + 8), 0xFFFFFFFFLL);
result = dlist_clear(*(_QWORD *)(a1 + 16), 0xFFFFFFFFLL);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 40) = -1;
return result;
}

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

dlist_clear(*(_QWORD *)(a1 + 8), 0xFFFFFFFFLL);
result = dlist_clear(*(_QWORD *)(a1 + 16), 0xFFFFFFFFLL);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 40) = -1;
return result;
}

original_code:
void
graph_tree_iterator_pre_destroy(graph_tree_iterator_pre* self){
 dlist_clear(self->i_stk, TRUE);
 dlist_clear(self->i_children, TRUE);
 self->i_root = ((void *)0);
 self->i_stk = ((void *)0);
 self->r_depth = 0;
 self->r_current = ((void *)0);
 self->p_add_children = TRUE;
}

canonical_original_code:
void graph_tree_iterator_pre_destroy(struct graph_tree_iterator_pre *self){
 dlist_clear(self->i_stk, TRUE);
 dlist_clear(self->i_children, TRUE);
 self->i_root = ((void *)0);
 self->i_stk = ((void *)0);
 self->r_depth = 0;
 self->r_current = ((void *)0);
 self->p_add_children = TRUE;
}

variable_types: struct graph_tree_iterator_pre { struct graph { struct graph_vtable { struct Object_vtable { unsigned long (*hash)(struct Object { struct Object_vtable *method; } *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } parent; struct Comparable_vtable { long (*compare)(void *self, void *oth); } comparable; } *method; struct Object *data; struct dlist { struct dlist *next; struct Object *data; struct dlist *prev; } *edges; } *i_root; struct dlist *i_stk; struct graph *r_current; unsigned long r_depth; enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } p_add_children; } *


original_code:
graph*
graph_tree_iterator_breadth_next(graph_tree_iterator_breadth* self){
 if(self->i_children){
  if(self->p_add_children){
   self->i_stk = dlist_concat(self->i_stk, self->i_children);
  } else {
   dlist_clear(self->i_children, TRUE);
  }
 }
 if(!self->i_stk){
  self->r_current = ((void *)0);
  self->r_depth = 0;
  self->p_add_children = TRUE;
  return ((void *)0);
 }
 node_info *g;
 self->i_stk = dlist_popfront(self->i_stk, (Object**)&g, FALSE);
 dlist *new_list = dlist_copy(g->node->edges, FALSE);
 dlist *run;
 for((run) = (new_list); (run) != ((void *)0); (run) = dlist_next(new_list, run)){
  run->data = (void*)node_info_new((graph*)run->data, self->r_depth+1);
 }
 self->i_children = new_list;
 self->r_current = (graph*)g->node;
 self->r_depth = g->depth;
 self->p_add_children = TRUE;
 do{ if((g && g->method && g->method->destroy)) g->method->destroy ((void*)g); } while(0);
 return self->r_current;
}

canonical_original_code:
struct graph *graph_tree_iterator_breadth_next(struct graph_tree_iterator_breadth *self){
 if(self->i_children){
  if(self->p_add_children){
   self->i_stk = dlist_concat(self->i_stk, self->i_children);
  } else {
   dlist_clear(self->i_children, TRUE);
  }
 }
 if(!self->i_stk){
  self->r_current = ((void *)0);
  self->r_depth = 0;
  self->p_add_children = TRUE;
  return ((void *)0);
 }
 struct node_info *g;
 self->i_stk = dlist_popfront(self->i_stk, (struct Object **)&g, FALSE);
 struct dlist *new_list = dlist_copy(g->node->edges, FALSE);
 struct dlist *run;
 for((run) = (new_list); (run) != ((void *)0); (run) = dlist_next(new_list, run)){
  run->data = (void *)node_info_new((struct graph *)run->data, self->r_depth+1);
 }
 self->i_children = new_list;
 self->r_current = (struct graph *)g->node;
 self->r_depth = g->depth;
 self->p_add_children = TRUE;
 do{ if((g && g->method && g->method->destroy)) g->method->destroy ((void *)g); } while(0);
 return self->r_current;
}

variable_types: struct graph_tree_iterator_breadth { struct graph *i_root; struct dlist *i_stk; struct graph *r_current; unsigned long r_depth; enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } p_add_children; } *

user_defined_types: struct graph_tree_iterator_breadth { struct graph *i_root; struct dlist *i_stk; struct graph *r_current; unsigned long r_depth; enum BOOLEAN p_add_children; }


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

dlist_clear(*(_QWORD *)(a1 + 8), 0xFFFFFFFFLL);
result = dlist_clear(*(_QWORD *)(a1 + 16), 0xFFFFFFFFLL);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 40) = -1;
return result;
}

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

dlist_clear(*(_QWORD *)(a1 + 8), 0xFFFFFFFFLL);
result = dlist_clear(*(_QWORD *)(a1 + 16), 0xFFFFFFFFLL);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 40) = -1;
return result;
}

original_code:
void
graph_tree_iterator_breadth_destroy(graph_tree_iterator_breadth* self){
 dlist_clear(self->i_stk, TRUE);
 dlist_clear(self->i_children, TRUE);
 self->i_root = ((void *)0);
 self->i_stk = ((void *)0);
 self->i_children = ((void *)0);
 self->r_depth = 0;
 self->r_current = ((void *)0);
 self->p_add_children = TRUE;
}

canonical_original_code:
void graph_tree_iterator_breadth_destroy(struct graph_tree_iterator_breadth *self){
 dlist_clear(self->i_stk, TRUE);
 dlist_clear(self->i_children, TRUE);
 self->i_root = ((void *)0);
 self->i_stk = ((void *)0);
 self->i_children = ((void *)0);
 self->r_depth = 0;
 self->r_current = ((void *)0);
 self->p_add_children = TRUE;
}

variable_types: struct graph_tree_iterator_breadth { struct graph { struct graph_vtable { struct Object_vtable { unsigned long (*hash)(struct Object { struct Object_vtable *method; } *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } parent; struct Comparable_vtable { long (*compare)(void *self, void *oth); } comparable; } *method; struct Object *data; struct dlist { struct dlist *next; struct Object *data; struct dlist *prev; } *edges; } *i_root; struct dlist *i_stk; struct graph *r_current; unsigned long r_depth; enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } p_add_children; } *


decompiled_code:
__int64 __fastcall graph_tree_link(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r12
__int64 v4; // rax
unsigned __int64 v5; // rbx
__int64 v6[9]; // [rsp+0h] [rbp-48h] BYREF

if ( !a2 )
return a1;
result = a2;
if ( a1 )
{
*(_QWORD *)(a1 + 16) = dlist_pushback(*(_QWORD *)(a1 + 16), a2, 0LL);
v6[0] = 0LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
v3 = graph_tree_iterator_pre_new(a1, (__int64)v6);
v4 = graph_tree_iterator_pre_next(v3);
if ( v4 )
{
v5 = 0LL;
while ( 1 )
{
v5 += a1 == v4;
if ( v5 > 1 )
break;
v4 = graph_tree_iterator_pre_next(v3);
if ( !v4 )
goto LABEL_7;
}
graph_tree_iterator_pre_destroy(v3);
*(_QWORD *)(a1 + 16) = dlist_popback(*(_QWORD *)(a1 + 16), 0LL, 0LL);
result = a1;
}
else
{
LABEL_7:
graph_tree_iterator_pre_destroy(v3);
result = a1;
}
}
return result;
}

original_code:
graph*
graph_tree_link(graph* root, graph* child){
 if(child == ((void *)0)) return root;
 if(root == ((void *)0)) return child;
 root->edges = dlist_pushback(root->edges, (Object*)child, FALSE);
 size_t root_visited = 0;
 graph_tree_iterator_pre *iter =
  graph_tree_iterator_pre_new(root, &(graph_tree_iterator_pre){});
 graph *g;
 for(g = graph_tree_iterator_pre_next(iter); g; g = graph_tree_iterator_pre_next(iter)){
  if(g == root){
   root_visited++;
  }
  if(root_visited > 1){
   break;
  }
 }
 graph_tree_iterator_pre_destroy(iter);
 if(root_visited > 1){
  root->edges = dlist_popback(root->edges, ((void *)0), FALSE);
 }
 return root;
}

canonical_original_code:
struct graph *graph_tree_link(struct graph *root, struct graph *child){
 if(child == ((void *)0)) return root;
 if(root == ((void *)0)) return child;
 root->edges = dlist_pushback(root->edges, (struct Object *)child, FALSE);
 unsigned long root_visited = 0;
 struct graph_tree_iterator_pre *iter = graph_tree_iterator_pre_new(root, &(graph_tree_iterator_pre){});
 struct graph *g;
 for(g = graph_tree_iterator_pre_next(iter); g; g = graph_tree_iterator_pre_next(iter)){
  if(g == root){
   root_visited++;
  }
  if(root_visited > 1){
   break;
  }
 }
 graph_tree_iterator_pre_destroy(iter);
 if(root_visited > 1){
  root->edges = dlist_popback(root->edges, ((void *)0), FALSE);
 }
 return root;
}

variable_types:
root
struct graph *

variable_types:
child
struct graph *

variable_types: struct graph { struct graph_vtable { struct Object_vtable { unsigned long (*hash)(struct Object { struct Object_vtable *method; } *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } parent; struct Comparable_vtable { long (*compare)(void *self, void *oth); } comparable; } *method; struct Object *data; struct dlist { struct dlist *next; struct Object *data; struct dlist *prev; } *edges; } *


decompiled_code:
__int64 __fastcall graph_tree_insert(__int64 a1)
{
__int64 v1; // rax

v1 = graph_insert(0LL);
return graph_tree_link(a1, v1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // rax

v1 = graph_insert(0LL);
return func8(a1, v1);
}

original_code:
graph*
graph_tree_insert(graph* root, Object* data, BOOLEAN copy){
 return graph_tree_link(root, graph_insert(((void *)0), data, copy));
}

canonical_original_code:
struct graph *graph_tree_insert(struct graph *root, struct Object *data, enum BOOLEAN copy){
 return graph_tree_link(root, graph_insert(((void *)0), data, copy));
}

variable_types:
data
struct Object *


decompiled_code:
__int64 __fastcall graph_tree_find(__int64 a1, int a2, __int64 a3, __int64 (__fastcall **a4)(__int64, _QWORD))
{
_QWORD *v6; // rbp
__int64 (__fastcall *v7)(_QWORD *); // r14
void (__fastcall *v8)(_QWORD *); // r15
__int64 v9; // rax
__int64 i; // rbx
__int64 v12[13]; // [rsp+0h] [rbp-68h] BYREF

v12[0] = 0LL;
v12[1] = 0LL;
v12[2] = 0LL;
v12[3] = 0LL;
v12[4] = 0LL;
v12[5] = 0LL;
if ( a2 == 1 )
{
v6 = (_QWORD *)graph_tree_iterator_pre_new(a1, (__int64)v12);
v7 = (__int64 (__fastcall *)(_QWORD *))graph_tree_iterator_pre_next;
v8 = (void (__fastcall *)(_QWORD *))graph_tree_iterator_pre_destroy;
v9 = graph_tree_iterator_pre_next((__int64)v6);
}
else if ( a2 == 3 )
{
v6 = graph_tree_iterator_post_new(a1, v12);
v7 = graph_tree_iterator_post_next;
v8 = (void (__fastcall *)(_QWORD *))graph_tree_iterator_post_destroy;
v9 = graph_tree_iterator_post_next(v6);
}
else
{
v6 = (_QWORD *)graph_tree_iterator_breadth_new(a1, (__int64)v12);
v7 = (__int64 (__fastcall *)(_QWORD *))graph_tree_iterator_breadth_next;
v8 = (void (__fastcall *)(_QWORD *))graph_tree_iterator_breadth_destroy;
v9 = graph_tree_iterator_breadth_next((__int64)v6);
}
for ( i = v9; i; i = v7(v6) )
{
if ( !(*a4)(a3, *(_QWORD *)(i + 8)) )
break;
}
v8(v6);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2, __int64 a3, __int64 (__fastcall **a4)(__int64, _QWORD))
{
_QWORD *v6; // rbp
__int64 (__fastcall *v7)(_QWORD *); // r14
void (__fastcall *v8)(_QWORD *); // r15
__int64 v9; // rax
__int64 i; // rbx
__int64 v12[13]; // [rsp+0h] [rbp-68h] BYREF

v12[0] = 0LL;
v12[1] = 0LL;
v12[2] = 0LL;
v12[3] = 0LL;
v12[4] = 0LL;
v12[5] = 0LL;
if ( a2 == 1 )
{
v6 = (_QWORD *)func7(a1, (__int64)v12);
v7 = (__int64 (__fastcall *)(_QWORD *))graph_tree_iterator_pre_next;
v8 = (void (__fastcall *)(_QWORD *))graph_tree_iterator_pre_destroy;
v9 = func3((__int64)v6);
}
else if ( a2 == 3 )
{
v6 = graph_tree_iterator_post_new(a1, v12);
v7 = graph_tree_iterator_post_next;
v8 = (void (__fastcall *)(_QWORD *))graph_tree_iterator_post_destroy;
v9 = func1(v6);
}
else
{
v6 = (_QWORD *)func10(a1, (__int64)v12);
v7 = (__int64 (__fastcall *)(_QWORD *))graph_tree_iterator_breadth_next;
v8 = (void (__fastcall *)(_QWORD *))graph_tree_iterator_breadth_destroy;
v9 = func5((__int64)v6);
}
for ( i = v9; i; i = v7(v6) )
{
if ( !(*a4)(a3, *(_QWORD *)(i + 8)) )
break;
}
v8(v6);
return i;
}

original_code:
graph*
graph_tree_find(graph *root, TRAVERSAL_STRATEGY strat, void* key, const Comparable_vtable* key_method){
 void *iter = (void*)&(char[( (sizeof(graph_tree_iterator_breadth))>(( (sizeof(graph_tree_iterator_pre))>(sizeof(graph_tree_iterator_post))?sizeof(graph_tree_iterator_pre):sizeof(graph_tree_iterator_post) ))?sizeof(graph_tree_iterator_breadth):( (sizeof(graph_tree_iterator_pre))>(sizeof(graph_tree_iterator_post))?sizeof(graph_tree_iterator_pre):sizeof(graph_tree_iterator_post) ) )]){0};
 void (*destroy)(void*);
 graph* (*next)(void*);
 switch(strat){
  case DEPTH_FIRST_POST:
   iter = graph_tree_iterator_post_new(root, iter);
   destroy = graph_tree_iterator_post_destroy;
   next = graph_tree_iterator_post_next;
   break;
  case DEPTH_FIRST_PRE:
   iter = graph_tree_iterator_pre_new(root, iter);
   destroy = graph_tree_iterator_pre_destroy;
   next = graph_tree_iterator_pre_next;
   break;
  default:
  case BREADTH_FIRST:
   iter = graph_tree_iterator_breadth_new(root, iter);
   destroy = graph_tree_iterator_breadth_destroy;
   next = graph_tree_iterator_breadth_next;
   break;
 }
 graph *rtn = ((void *)0);
 graph *g;
 for(g = next(iter); g; g = next(iter)){
  if(key_method->compare(key, g->data) == 0){
   rtn = g;
   break;
  }
 }
 destroy(iter);
 return rtn;
}

canonical_original_code:
struct graph *graph_tree_find(struct graph *root, enum TRAVERSAL_STRATEGY strat, void *key, struct Comparable_vtable *key_method){
 void *iter = (void*)&(char[( (sizeof(graph_tree_iterator_breadth))>(( (sizeof(graph_tree_iterator_pre))>(sizeof(graph_tree_iterator_post))?sizeof(graph_tree_iterator_pre):sizeof(graph_tree_iterator_post) ))?sizeof(graph_tree_iterator_breadth):( (sizeof(graph_tree_iterator_pre))>(sizeof(graph_tree_iterator_post))?sizeof(graph_tree_iterator_pre):sizeof(graph_tree_iterator_post) ) )]){0};
 void (*destroy)(void *);
 struct graph *(*next)(void *);
 switch(strat){
  case DEPTH_FIRST_POST:
   iter = graph_tree_iterator_post_new(root, iter);
   destroy = graph_tree_iterator_post_destroy;
   next = graph_tree_iterator_post_next;
   break;
  case DEPTH_FIRST_PRE:
   iter = graph_tree_iterator_pre_new(root, iter);
   destroy = graph_tree_iterator_pre_destroy;
   next = graph_tree_iterator_pre_next;
   break;
  default:
  case BREADTH_FIRST:
   iter = graph_tree_iterator_breadth_new(root, iter);
   destroy = graph_tree_iterator_breadth_destroy;
   next = graph_tree_iterator_breadth_next;
   break;
 }
 struct graph *rtn = ((void *)0);
 struct graph *g;
 for(g = next(iter); g; g = next(iter)){
  if(key_method->compare(key, g->data) == 0){
   rtn = g;
   break;
  }
 }
 destroy(iter);
 return rtn;
}

variable_types: enum TRAVERSAL_STRATEGY { BREADTH_FIRST=0, DEPTH_FIRST_PRE=1, DEPTH_FIRST=2, DEPTH_FIRST_IN=2, DEPTH_FIRST_POST=3 }

variable_types:
key
void *

variable_types:
iter
void *

variable_types:
destroy
void (*)(void *)

variable_types: struct graph { struct graph_vtable { struct Object_vtable { unsigned long (*hash)(struct Object { struct Object_vtable *method; } *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } parent; struct Comparable_vtable { long (*compare)(void *self, void *oth); } comparable; } *method; struct Object *data; struct dlist { struct dlist *next; struct Object *data; struct dlist *prev; } *edges; } *(*)(void *)


decompiled_code:
__int64 __fastcall graph_tree_size(__int64 a1, _QWORD *a2, _QWORD *a3)
{
__int64 v4; // r12
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7; // rbp
__int64 result; // rax
__int64 v9[11]; // [rsp+0h] [rbp-58h] BYREF

v9[0] = 0LL;
v9[1] = 0LL;
v9[2] = 0LL;
v9[3] = 0LL;
v9[4] = 0LL;
v9[5] = 0LL;
v4 = graph_tree_iterator_pre_new(a1, (__int64)v9);
v5 = graph_tree_iterator_pre_next(v4);
if ( v5 )
{
v6 = 0LL;
v7 = 0LL;
do
{
++v7;
v6 += dlist_length(*(_QWORD *)(v5 + 16));
v5 = graph_tree_iterator_pre_next(v4);
}
while ( v5 );
}
else
{
v6 = 0LL;
v7 = 0LL;
}
result = graph_tree_iterator_pre_destroy(v4);
if ( a2 )
*a2 = v7;
if ( a3 )
*a3 = v6;
return result;
}

original_code:
void
graph_tree_size(graph* root, size_t *nodes, size_t *edges){
 size_t i_nodes = 0;
 size_t i_edges = 0;
 graph_tree_iterator_pre *iter =
  graph_tree_iterator_pre_new(root, &(graph_tree_iterator_pre){});
 graph *g;
 for(g = graph_tree_iterator_pre_next(iter); g; g = graph_tree_iterator_pre_next(iter)){
  i_nodes++;
  i_edges += dlist_length(g->edges);
 }
 graph_tree_iterator_pre_destroy(iter);
 if(nodes) *nodes = i_nodes;
 if(edges) *edges = i_edges;
}

canonical_original_code:
void graph_tree_size(struct graph *root, unsigned long *nodes, unsigned long *edges){
 unsigned long i_nodes = 0;
 unsigned long i_edges = 0;
 struct graph_tree_iterator_pre *iter = graph_tree_iterator_pre_new(root, &(graph_tree_iterator_pre){});
 struct graph *g;
 for(g = graph_tree_iterator_pre_next(iter); g; g = graph_tree_iterator_pre_next(iter)){
  i_nodes++;
  i_edges += dlist_length(g->edges);
 }
 graph_tree_iterator_pre_destroy(iter);
 if(nodes) *nodes = i_nodes;
 if(edges) *edges = i_edges;
}

variable_types:
nodes
unsigned long *

variable_types:
edges
unsigned long *


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

if ( !a2 )
return 0LL;
result = *(_QWORD *)(a2 + 16);
if ( result == a1 )
result = 0LL;
return result;
}

variable_types:
head
struct dlist *

variable_types:
run
struct dlist *


decompiled_code:
__int64 __fastcall dlist_toSlist(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 v3; // rbx

v2 = a1;
if ( a1 )
{
v3 = a1;
a1 = 0LL;
do
{
a1 = slist_pushfront(a1, *(_QWORD *)(v3 + 8), a2);
v3 = *(_QWORD *)(v3 + 16);
}
while ( v2 != v3 );
}
return a1;
}

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

v2 = a1;
if ( a1 )
{
v3 = a1;
a1 = 0LL;
do
{
a1 = slist_pushfront(a1, *(_QWORD *)(v3 + 8), a2);
v3 = *(_QWORD *)(v3 + 16);
}
while ( v2 != v3 );
}
return a1;
}

original_code:
slist*
dlist_toSlist(dlist *head, BOOLEAN deep_copy){
 slist* p = ((void *)0);
 dlist* d = head;
 if(!d) return ((void *)0);
 do{ p = slist_pushfront(p, d->data, deep_copy); d = d->prev; } while(d != head);
 return p;
}

canonical_original_code:
struct slist *dlist_toSlist(struct dlist *head, enum BOOLEAN deep_copy){
 struct slist *p = ((void *)0);
 struct dlist *d = head;
 if(!d) return ((void *)0);
 do{ p = slist_pushfront(p, d->data, deep_copy); d = d->prev; } while(d != head);
 return p;
}

variable_types: struct dlist { struct dlist *next; struct Object *data; struct dlist *prev; } *

variable_types: struct slist { struct slist *next; struct Object { struct Object_vtable { unsigned long (*hash)(struct Object *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } *method; } *data; } *

variable_types: struct dlist { struct dlist *next; struct Object { struct Object_vtable { unsigned long (*hash)(struct Object *self); char *(*hashable)(struct Object *self, unsigned long *size); void (*destroy)(struct Object *self); struct Object *(*copy)(struct Object *self, void *buffer); enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 } (*equals)(struct Object *self, void *oth); unsigned long size; } *method; } *data; struct dlist *prev; } *


decompiled_code:
__int64 __fastcall array_toDlist(__int64 a1, unsigned __int64 a2, unsigned int a3)
{
unsigned __int64 v5; // rbx
__int64 v6; // rdi

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v5 = 0LL;
v6 = 0LL;
do
v6 = dlist_pushback(v6, *(_QWORD *)(a1 + 8 * v5++), a3);
while ( a2 > v5 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int64 a2, unsigned int a3)
{
unsigned __int64 v5; // rbx
__int64 v6; // rdi

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v5 = 0LL;
v6 = 0LL;
do
v6 = dlist_pushback(v6, *(_QWORD *)(a1 + 8 * v5++), a3);
while ( a2 > v5 );
return v6;
}

original_code:
dlist*
array_toDlist(Object** array, size_t size, BOOLEAN deep_copy){
 dlist *p = ((void *)0);
 if(!array) return ((void *)0);
 if(size == 0) return ((void *)0);
 size_t i = 0;
 for(; i < size; i++){
  p = dlist_pushback(p, array[i], deep_copy);
 }
 return p;
}

canonical_original_code:
struct dlist *array_toDlist(struct Object **array, unsigned long size, enum BOOLEAN deep_copy){
 struct dlist *p = ((void *)0);
 if(!array) return ((void *)0);
 if(size == 0) return ((void *)0);
 unsigned long i = 0;
 for(; i < size; i++){
  p = dlist_pushback(p, array[i], deep_copy);
 }
 return p;
}

variable_types:
array
struct Object **

variable_types:
size
unsigned long

variable_types: enum BOOLEAN { FALSE=0, TRUE=-1, MAYBE=-2 }

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall array_toSlist(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v5; // rbx
__int64 v6; // rdi

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v5 = a2 - 1;
if ( a2 == 1 )
return 0LL;
v6 = 0LL;
do
v6 = slist_pushfront(v6, *(_QWORD *)(a1 + 8 * v5--), a3);
while ( v5 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v5; // rbx
__int64 v6; // rdi

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v5 = a2 - 1;
if ( a2 == 1 )
return 0LL;
v6 = 0LL;
do
v6 = slist_pushfront(v6, *(_QWORD *)(a1 + 8 * v5--), a3);
while ( v5 );
return v6;
}

original_code:
slist*
array_toSlist(Object** arr, size_t size, BOOLEAN deep){
 if(arr == ((void *)0)) return ((void *)0);
 if(size == 0) return ((void *)0);
 size_t i = size;
 slist *head = ((void *)0);
 for(; --i; ){
  head = slist_pushfront(head, arr[i], deep);
 }
 return head;
}

canonical_original_code:
struct slist *array_toSlist(struct Object **arr, unsigned long size, enum BOOLEAN deep){
 if(arr == ((void *)0)) return ((void *)0);
 if(size == 0) return ((void *)0);
 unsigned long i = size;
 struct slist *head = ((void *)0);
 for(; --i; ){
  head = slist_pushfront(head, arr[i], deep);
 }
 return head;
}

variable_types:
arr
struct Object **


decompiled_code:
__int64 __fastcall slist_toDlist(__int64 a1, unsigned int a2)
{
_QWORD *v2; // rbx

v2 = (_QWORD *)a1;
if ( a1 )
{
a1 = 0LL;
do
{
a1 = dlist_pushback(a1, v2[1], a2);
v2 = (_QWORD *)*v2;
}
while ( v2 );
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
_QWORD *v2; // rbx

v2 = (_QWORD *)a1;
if ( a1 )
{
a1 = 0LL;
do
{
a1 = dlist_pushback(a1, v2[1], a2);
v2 = (_QWORD *)*v2;
}
while ( v2 );
}
return a1;
}

original_code:
dlist*
slist_toDlist(slist *head, BOOLEAN deep){
 slist* p = head;
 dlist* d = ((void *)0);
 for(; p; p = p->next){
  d = dlist_pushback(d, p->data, deep);
 }
 return d;
}

canonical_original_code:
struct dlist *slist_toDlist(struct slist *head, enum BOOLEAN deep){
 struct slist *p = head;
 struct dlist *d = ((void *)0);
 for(; p; p = p->next){
  d = dlist_pushback(d, p->data, deep);
 }
 return d;
}

variable_types: struct slist { struct slist *next; struct Object *data; } *


msleep

repo: KaTaLyzer/KaTaLyzer

decompiled_code:
__int64 __fastcall msleep(unsigned __int64 a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
struct timespec v3; // [rsp+10h] [rbp-18h] BYREF

v2.tv_sec = 0LL;
v2.tv_nsec = 0LL;
v3.tv_sec = (int)(a1 / 0x3E8);
v3.tv_nsec = 1000000 * (a1 - 1000 * v3.tv_sec);
_nsleep(&v3, &v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
struct timespec v3; // [rsp+10h] [rbp-18h] BYREF

v2.tv_sec = 0LL;
v2.tv_nsec = 0LL;
v3.tv_sec = (int)(a1 / 0x3E8);
v3.tv_nsec = 1000000 * (a1 - 1000 * v3.tv_sec);
func0(&v3, &v2);
return 1LL;
}

original_code:
int msleep(unsigned long milisec)
{
    struct timespec req={0},rem={0};
    time_t sec=(int)(milisec/1000);
    milisec=milisec-(sec*1000);
    req.tv_sec=sec;
    req.tv_nsec=milisec*1000000L;
    __nsleep(&req,&rem);
    return 1;
}

canonical_original_code:
int msleep(unsigned long milisec)
{
    struct timespec req = {0}; struct timespec rem = {0};
    long sec = (int)(milisec/1000);
    milisec=milisec-(sec*1000);
    req.tv_sec=sec;
    req.tv_nsec=milisec*1000000L;
    __nsleep(&req,&rem);
    return 1;
}

variable_types:
milisec
unsigned long

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types: sec long

return_type: int


waiting

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

puts("Waiting...");
while ( 1 )
{
time(&timer);
result = localtime(&timer);
if ( !result->tm_sec )
break;
msleep(0x14uLL);
fflush(stdout);
}
return result;
}

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

puts("Waiting...");
while ( 1 )
{
time(&timer);
result = localtime(&timer);
if ( !result->tm_sec )
break;
func1(0x14uLL);
fflush(stdout);
}
return result;
}

original_code:
void waiting()
{
    printf("Waiting...\n");
 struct tm *timetm;
 time_t timenow;
 for(;;){
                time( &timenow );
                timetm = localtime( &timenow );
                if(timetm->tm_sec != 0)
                {
                        msleep(20);
                        fflush(stdout);
                }
                else break;
    }
}

canonical_original_code:
void waiting()
{
    printf("Waiting...\n");
 struct tm *timetm;
 long timenow;
 for(;;){
                time( &timenow );
                timetm = localtime( &timenow );
                if(timetm->tm_sec != 0)
                {
                        msleep(20);
                        fflush(stdout);
                }
                else break;
    }
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: timenow long