chkzero

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

v1 = *((unsigned __int16 *)&reg + 2);
result = v1 & 0xFFFFFFFE;
v3 = v1 | 1;
if ( !a1 )
result = v3;
*((_WORD *)&reg + 2) = result;
return result;
}

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

v1 = *((unsigned __int16 *)&reg + 2);
result = v1 & 0xFFFFFFFE;
v3 = v1 | 1;
if ( !a1 )
result = v3;
*((_WORD *)&reg + 2) = result;
return result;
}

original_code:
void chkzero(int16_t value)
{
 if (value == 0)
 {
  reg[2] = reg[2]|1;
 }
 else
 {
  reg[2] = reg[2] & (~1);
 }
}

canonical_original_code:
void chkzero(short value)
{
 if (value == 0)
 {
  reg[2] = reg[2]|1;
 }
 else
 {
  reg[2] = reg[2] & (~1);
 }
}


chkcarry

repo: Darksecond/Landmine

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

v1 = *((unsigned __int16 *)&reg + 2);
result = v1 & 0xFFFFFFFD;
v3 = v1 | 2;
if ( a1 )
result = v3;
*((_WORD *)&reg + 2) = result;
return result;
}

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

v1 = *((unsigned __int16 *)&reg + 2);
result = v1 & 0xFFFFFFFD;
v3 = v1 | 2;
if ( a1 )
result = v3;
*((_WORD *)&reg + 2) = result;
return result;
}

original_code:
void chkcarry(int16_t value)
{
 if (value != 0)
 {
  reg[2] = reg[2]|2;
 }
 else
 {
  reg[2] = reg[2] & (~2);
 }
}

canonical_original_code:
void chkcarry(short value)
{
 if (value != 0)
 {
  reg[2] = reg[2]|2;
 }
 else
 {
  reg[2] = reg[2] & (~2);
 }
}

variable_types: value short

return_type: void


decompiled_code:
__int64 vm_running()
{
return ((unsigned __int8)(*((_WORD *)&reg + 2) >> 3) ^ 1) & 1;
}

original_code:
uint8_t vm_running()
{
 if((reg[2] & 8))
 {
  return 0;
 }
 else
 {
  return 1;
 }
}

canonical_original_code:
unsigned char vm_running()
{
 if((reg[2] & 8))
 {
  return 0;
 }
 else
 {
  return 1;
 }
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall vm_interrupt(unsigned __int8 a1)
{
__int64 result; // rax

if ( (*(_BYTE *)(&reg + 1) & 4) != 0 )
{
if ( *((_WORD *)&intr + a1) )
{
result = (unsigned int)(1 << a1);
reg_u32[127] |= result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1)
{
__int64 result; // rax

if ( (*(_BYTE *)(&reg + 1) & 4) != 0 )
{
if ( *((_WORD *)&intr + a1) )
{
result = (unsigned int)(1 << a1);
reg_u32[127] |= result;
}
}
return result;
}

original_code:
void vm_interrupt(uint8_t interrupt)
{
 if (reg[2] & 4)
 {
  if(intr[interrupt])
  {
   reg_u32[127] = reg_u32[127] | (1 << interrupt);
  }
 }
}

canonical_original_code:
void vm_interrupt(unsigned char interrupt)
{
 if (reg[2] & 4)
 {
  if(intr[interrupt])
  {
   reg_u32[127] = reg_u32[127] | (1 << interrupt);
  }
 }
}

variable_types:
interrupt
unsigned char


decompiled_code:
int __fastcall vm_step()
{
__int64 v0; // rbp
unsigned __int8 v1; // r12
unsigned __int16 v2; // r13
int v3; // edx
__int16 v4; // r8
__int16 v5; // di
unsigned __int8 v6; // bl
__int64 v7; // rax
__int16 v8; // ax
__int16 v9; // r13
__int16 v10; // r14
int v11; // ecx
__int64 v12; // rcx
__int16 v13; // ax
__int16 v14; // r13
__int16 v15; // bx
__int16 v16; // di
__int16 v17; // ax
__int16 v18; // ax
__int16 v19; // ax
__int16 v20; // ax
__int16 v21; // cx
__int16 v22; // ax
__int16 v23; // ax
__int16 v24; // r13
__int16 v25; // r13
__int16 v26; // ax

printf("PC=0x%04X ", (unsigned int)(__int16)reg);
v3 = reg_u32[127];
if ( v3 && (v4 = *((_WORD *)&reg + 2), (v4 & 4) != 0) )
{
v11 = 0;
while ( (v3 & (1 << v11)) == 0 )
{
if ( ++v11 == 32 )
goto LABEL_3;
}
reg_u32[127] = v3 & ~(1 << v11);
push(v4);
push(reg);
*((_WORD *)&reg + 2) &= 0xFFFBu;
v5 = *((_WORD *)&intr + v12);
}
else
{
LABEL_3:
v5 = reg;
}
LOWORD(reg) = v5 + 1;
v6 = ((__int64 (*)(void))vmext_getbyte)();
if ( v6 > 0x3Fu )
{
LOWORD(reg) = reg + 1;
LOBYTE(v0) = ((__int64 (*)(void))vmext_getbyte)();
LOWORD(reg) = reg + 1;
v8 = ((__int64 (*)(void))vmext_getbyte)();
v1 = v8;
LOWORD(reg) = reg + 1;
v9 = v8 << 8;
v10 = (unsigned __int8)((__int64 (*)(void))vmext_getbyte)();
printf("opcode=0x%02hhX", v6);
printf(" a1=0x%02hhi", (unsigned __int8)v0);
printf(" a2=0x%02hhi", v1);
printf(" a3=0x%02hhi", (unsigned __int8)v10);
v2 = v10 + v9;
LODWORD(v7) = putchar(10);
}
else if ( v6 > 0x1Fu )
{
LOWORD(reg) = reg + 1;
v13 = ((__int64 (*)(void))vmext_getbyte)();
LOBYTE(v0) = v13;
LOWORD(reg) = reg + 1;
v14 = v13 << 8;
v1 = ((__int64 (*)(void))vmext_getbyte)();
printf("opcode=0x%02hhX", v6);
printf(" a1=0x%02hhi", (unsigned __int8)v0);
printf(" a2=0x%02hhi", v1);
putchar(10);
LODWORD(v7) = v1;
v2 = v1 + v14;
}
else
{
if ( v6 > 0xFu )
{
LOWORD(reg) = reg + 1;
LOBYTE(v0) = ((__int64 (*)(void))vmext_getbyte)();
printf("opcode=0x%02hhX", v6);
printf(" a1=0x%02hhi", (unsigned __int8)v0);
}
else
{
printf("opcode=0x%02hhX", v6);
}
LODWORD(v7) = putchar(10);
}
switch ( v6 )
{
case 2u:
LODWORD(v7) = pop();
LOWORD(reg) = v7;
return v7;
case 3u:
LOWORD(reg) = pop();
LODWORD(v7) = pop();
*((_WORD *)&reg + 2) = v7;
return v7;
case 4u:
*((_WORD *)&reg + 2) &= 0xFFFBu;
return v7;
case 5u:
*((_WORD *)&reg + 2) |= 4u;
return v7;
case 6u:
*((_WORD *)&reg + 2) |= 8u;
return v7;
case 0x10u:
v19 = *((_WORD *)&reg + (unsigned __int8)v0) + 1;
*((_WORD *)&reg + (unsigned __int8)v0) = v19;
v16 = v19;
goto LABEL_24;
case 0x11u:
v18 = *((_WORD *)&reg + (unsigned __int8)v0) - 1;
*((_WORD *)&reg + (unsigned __int8)v0) = v18;
v16 = v18;
goto LABEL_24;
case 0x12u:
LODWORD(v7) = push(*((_WORD *)&reg + (unsigned __int8)v0));
return v7;
case 0x13u:
LODWORD(v7) = pop();
*((_WORD *)&reg + (unsigned __int8)v0) = v7;
return v7;
case 0x20u:
LODWORD(v7) = *((unsigned __int16 *)&reg + v1);
*((_WORD *)&reg + (unsigned __int8)v0) = v7;
return v7;
case 0x21u:
LODWORD(v7) = *((unsigned __int16 *)&reg + *((unsigned __int8 *)&reg + 2 * v1));
*((_WORD *)&reg + (unsigned __int8)v0) = v7;
return v7;
case 0x22u:
v7 = *((unsigned __int8 *)&reg + 2 * (unsigned __int8)v0);
*((_WORD *)&reg + v7) = *((_WORD *)&reg + v1);
return v7;
case 0x23u:
*((_WORD *)&reg + (unsigned __int8)v0) = (char)v1;
return v7;
case 0x24u:
v17 = *((_WORD *)&reg + v1) & *((_WORD *)&reg + (unsigned __int8)v0);
*((_WORD *)&reg + (unsigned __int8)v0) = v17;
LODWORD(v7) = chkzero(v17);
return v7;
case 0x25u:
v23 = *((_WORD *)&reg + v1) | *((_WORD *)&reg + (unsigned __int8)v0);
*((_WORD *)&reg + (unsigned __int8)v0) = v23;
LODWORD(v7) = chkzero(v23);
return v7;
case 0x26u:
v22 = *((_WORD *)&reg + v1) ^ *((_WORD *)&reg + (unsigned __int8)v0);
*((_WORD *)&reg + (unsigned __int8)v0) = v22;
LODWORD(v7) = chkzero(v22);
return v7;
case 0x27u:
*((_WORD *)&reg + (unsigned __int8)v0) *= *((_WORD *)&reg + v1);
chkcarry(0);
LODWORD(v7) = chkzero(v21);
return v7;
case 0x28u:
v20 = *((__int16 *)&reg + (unsigned __int8)v0) / *((__int16 *)&reg + v1);
*((_WORD *)&reg + (unsigned __int8)v0) = v20;
LODWORD(v7) = chkzero(v20);
return v7;
case 0x29u:
*((_WORD *)&reg + (unsigned __int8)v0) += *((_WORD *)&reg + v1);
goto LABEL_25;
case 0x2Au:
*((_WORD *)&reg + (unsigned __int8)v0) -= *((_WORD *)&reg + v1);
chkcarry(0);
LODWORD(v7) = chkzero(*((_WORD *)&reg + (unsigned __int8)v0));
return v7;
case 0x2Bu:
goto LABEL_11;
case 0x2Cu:
LODWORD(v7) = push(reg);
goto LABEL_11;
case 0x2Du:
if ( (*(_BYTE *)(&reg + 1) & 1) != 0 )
goto LABEL_11;
return v7;
case 0x2Eu:
if ( (*(_BYTE *)(&reg + 1) & 1) == 0 )
goto LABEL_11;
return v7;
case 0x2Fu:
if ( (*(_BYTE *)(&reg + 1) & 2) != 0 )
goto LABEL_11;
return v7;
case 0x30u:
if ( (*(_BYTE *)(&reg + 1) & 2) == 0 )
LABEL_11:
LOWORD(reg) = v2;
return v7;
case 0x31u:
v16 = *((_WORD *)&reg + (unsigned __int8)v0) - *((_WORD *)&reg + v1);
goto LABEL_24;
case 0x32u:
v16 = *((_WORD *)&reg + (unsigned __int8)v0) - v1;
goto LABEL_24;
case 0x40u:
v15 = vmext_getbyte(v2);
LODWORD(v7) = (unsigned __int8)vmext_getbyte((unsigned __int16)(v2 + 1));
*((_WORD *)&reg + (unsigned __int8)v0) = (unsigned __int8)v7 + (v15 << 8);
return v7;
case 0x41u:
v0 = (unsigned __int8)v0;
v24 = *((_WORD *)&reg + (unsigned __int8)v0) & v2;
goto LABEL_52;
case 0x42u:
v0 = (unsigned __int8)v0;
v24 = *((_WORD *)&reg + (unsigned __int8)v0) | v2;
goto LABEL_52;
case 0x43u:
v0 = (unsigned __int8)v0;
v24 = *((_WORD *)&reg + (unsigned __int8)v0) ^ v2;
LABEL_52:
*((_WORD *)&reg + v0) = v24;
LODWORD(v7) = chkzero(v24);
return v7;
case 0x44u:
v25 = *((_WORD *)&reg + (unsigned __int8)v0) + v2;
*((_WORD *)&reg + (unsigned __int8)v0) = v25;
v16 = v25;
goto LABEL_24;
case 0x45u:
v26 = *((_WORD *)&reg + (unsigned __int8)v0) - v2;
*((_WORD *)&reg + (unsigned __int8)v0) = v26;
v16 = v26;
goto LABEL_24;
case 0x46u:
v16 = *((_WORD *)&reg + (unsigned __int8)v0) - v2;
LABEL_24:
chkzero(v16);
LABEL_25:
LODWORD(v7) = chkcarry(0);
break;
case 0x47u:
if ( (unsigned __int8)v0 <= 0x20u )
*((_WORD *)&intr + (unsigned __int8)v0) = v2;
break;
case 0x48u:
*((_WORD *)&reg + (unsigned __int8)v0) = v2;
break;
default:
return v7;
}
return v7;
}

canonical_decompiled_code:
int __fastcall func7()
{
__int64 v0; // rbp
unsigned __int8 v1; // r12
unsigned __int16 v2; // r13
int v3; // edx
__int16 v4; // r8
__int16 v5; // di
unsigned __int8 v6; // bl
__int64 v7; // rax
__int16 v8; // ax
__int16 v9; // r13
__int16 v10; // r14
int v11; // ecx
__int64 v12; // rcx
__int16 v13; // ax
__int16 v14; // r13
__int16 v15; // bx
__int16 v16; // di
__int16 v17; // ax
__int16 v18; // ax
__int16 v19; // ax
__int16 v20; // ax
__int16 v21; // cx
__int16 v22; // ax
__int16 v23; // ax
__int16 v24; // r13
__int16 v25; // r13
__int16 v26; // ax

printf("PC=0x%04X ", (unsigned int)(__int16)reg);
v3 = reg_u32[127];
if ( v3 && (v4 = *((_WORD *)&reg + 2), (v4 & 4) != 0) )
{
v11 = 0;
while ( (v3 & (1 << v11)) == 0 )
{
if ( ++v11 == 32 )
goto LABEL_3;
}
reg_u32[127] = v3 & ~(1 << v11);
func1(v4);
func1(reg);
*((_WORD *)&reg + 2) &= 0xFFFBu;
v5 = *((_WORD *)&intr + v12);
}
else
{
LABEL_3:
v5 = reg;
}
LOWORD(reg) = v5 + 1;
v6 = ((__int64 (*)(void))vmext_getbyte)();
if ( v6 > 0x3Fu )
{
LOWORD(reg) = reg + 1;
LOBYTE(v0) = ((__int64 (*)(void))vmext_getbyte)();
LOWORD(reg) = reg + 1;
v8 = ((__int64 (*)(void))vmext_getbyte)();
v1 = v8;
LOWORD(reg) = reg + 1;
v9 = v8 << 8;
v10 = (unsigned __int8)((__int64 (*)(void))vmext_getbyte)();
printf("opcode=0x%02hhX", v6);
printf(" a1=0x%02hhi", (unsigned __int8)v0);
printf(" a2=0x%02hhi", v1);
printf(" a3=0x%02hhi", (unsigned __int8)v10);
v2 = v10 + v9;
LODWORD(v7) = putchar(10);
}
else if ( v6 > 0x1Fu )
{
LOWORD(reg) = reg + 1;
v13 = ((__int64 (*)(void))vmext_getbyte)();
LOBYTE(v0) = v13;
LOWORD(reg) = reg + 1;
v14 = v13 << 8;
v1 = ((__int64 (*)(void))vmext_getbyte)();
printf("opcode=0x%02hhX", v6);
printf(" a1=0x%02hhi", (unsigned __int8)v0);
printf(" a2=0x%02hhi", v1);
putchar(10);
LODWORD(v7) = v1;
v2 = v1 + v14;
}
else
{
if ( v6 > 0xFu )
{
LOWORD(reg) = reg + 1;
LOBYTE(v0) = ((__int64 (*)(void))vmext_getbyte)();
printf("opcode=0x%02hhX", v6);
printf(" a1=0x%02hhi", (unsigned __int8)v0);
}
else
{
printf("opcode=0x%02hhX", v6);
}
LODWORD(v7) = putchar(10);
}
switch ( v6 )
{
case 2u:
LODWORD(v7) = func0();
LOWORD(reg) = v7;
return v7;
case 3u:
LOWORD(reg) = func0();
LODWORD(v7) = func0();
*((_WORD *)&reg + 2) = v7;
return v7;
case 4u:
*((_WORD *)&reg + 2) &= 0xFFFBu;
return v7;
case 5u:
*((_WORD *)&reg + 2) |= 4u;
return v7;
case 6u:
*((_WORD *)&reg + 2) |= 8u;
return v7;
case 0x10u:
v19 = *((_WORD *)&reg + (unsigned __int8)v0) + 1;
*((_WORD *)&reg + (unsigned __int8)v0) = v19;
v16 = v19;
goto LABEL_24;
case 0x11u:
v18 = *((_WORD *)&reg + (unsigned __int8)v0) - 1;
*((_WORD *)&reg + (unsigned __int8)v0) = v18;
v16 = v18;
goto LABEL_24;
case 0x12u:
LODWORD(v7) = func1(*((_WORD *)&reg + (unsigned __int8)v0));
return v7;
case 0x13u:
LODWORD(v7) = func0();
*((_WORD *)&reg + (unsigned __int8)v0) = v7;
return v7;
case 0x20u:
LODWORD(v7) = *((unsigned __int16 *)&reg + v1);
*((_WORD *)&reg + (unsigned __int8)v0) = v7;
return v7;
case 0x21u:
LODWORD(v7) = *((unsigned __int16 *)&reg + *((unsigned __int8 *)&reg + 2 * v1));
*((_WORD *)&reg + (unsigned __int8)v0) = v7;
return v7;
case 0x22u:
v7 = *((unsigned __int8 *)&reg + 2 * (unsigned __int8)v0);
*((_WORD *)&reg + v7) = *((_WORD *)&reg + v1);
return v7;
case 0x23u:
*((_WORD *)&reg + (unsigned __int8)v0) = (char)v1;
return v7;
case 0x24u:
v17 = *((_WORD *)&reg + v1) & *((_WORD *)&reg + (unsigned __int8)v0);
*((_WORD *)&reg + (unsigned __int8)v0) = v17;
LODWORD(v7) = func2(v17);
return v7;
case 0x25u:
v23 = *((_WORD *)&reg + v1) | *((_WORD *)&reg + (unsigned __int8)v0);
*((_WORD *)&reg + (unsigned __int8)v0) = v23;
LODWORD(v7) = func2(v23);
return v7;
case 0x26u:
v22 = *((_WORD *)&reg + v1) ^ *((_WORD *)&reg + (unsigned __int8)v0);
*((_WORD *)&reg + (unsigned __int8)v0) = v22;
LODWORD(v7) = func2(v22);
return v7;
case 0x27u:
*((_WORD *)&reg + (unsigned __int8)v0) *= *((_WORD *)&reg + v1);
func3(0);
LODWORD(v7) = func2(v21);
return v7;
case 0x28u:
v20 = *((__int16 *)&reg + (unsigned __int8)v0) / *((__int16 *)&reg + v1);
*((_WORD *)&reg + (unsigned __int8)v0) = v20;
LODWORD(v7) = func2(v20);
return v7;
case 0x29u:
*((_WORD *)&reg + (unsigned __int8)v0) += *((_WORD *)&reg + v1);
goto LABEL_25;
case 0x2Au:
*((_WORD *)&reg + (unsigned __int8)v0) -= *((_WORD *)&reg + v1);
func3(0);
LODWORD(v7) = func2(*((_WORD *)&reg + (unsigned __int8)v0));
return v7;
case 0x2Bu:
goto LABEL_11;
case 0x2Cu:
LODWORD(v7) = func1(reg);
goto LABEL_11;
case 0x2Du:
if ( (*(_BYTE *)(&reg + 1) & 1) != 0 )
goto LABEL_11;
return v7;
case 0x2Eu:
if ( (*(_BYTE *)(&reg + 1) & 1) == 0 )
goto LABEL_11;
return v7;
case 0x2Fu:
if ( (*(_BYTE *)(&reg + 1) & 2) != 0 )
goto LABEL_11;
return v7;
case 0x30u:
if ( (*(_BYTE *)(&reg + 1) & 2) == 0 )
LABEL_11:
LOWORD(reg) = v2;
return v7;
case 0x31u:
v16 = *((_WORD *)&reg + (unsigned __int8)v0) - *((_WORD *)&reg + v1);
goto LABEL_24;
case 0x32u:
v16 = *((_WORD *)&reg + (unsigned __int8)v0) - v1;
goto LABEL_24;
case 0x40u:
v15 = vmext_getbyte(v2);
LODWORD(v7) = (unsigned __int8)vmext_getbyte((unsigned __int16)(v2 + 1));
*((_WORD *)&reg + (unsigned __int8)v0) = (unsigned __int8)v7 + (v15 << 8);
return v7;
case 0x41u:
v0 = (unsigned __int8)v0;
v24 = *((_WORD *)&reg + (unsigned __int8)v0) & v2;
goto LABEL_52;
case 0x42u:
v0 = (unsigned __int8)v0;
v24 = *((_WORD *)&reg + (unsigned __int8)v0) | v2;
goto LABEL_52;
case 0x43u:
v0 = (unsigned __int8)v0;
v24 = *((_WORD *)&reg + (unsigned __int8)v0) ^ v2;
LABEL_52:
*((_WORD *)&reg + v0) = v24;
LODWORD(v7) = func2(v24);
return v7;
case 0x44u:
v25 = *((_WORD *)&reg + (unsigned __int8)v0) + v2;
*((_WORD *)&reg + (unsigned __int8)v0) = v25;
v16 = v25;
goto LABEL_24;
case 0x45u:
v26 = *((_WORD *)&reg + (unsigned __int8)v0) - v2;
*((_WORD *)&reg + (unsigned __int8)v0) = v26;
v16 = v26;
goto LABEL_24;
case 0x46u:
v16 = *((_WORD *)&reg + (unsigned __int8)v0) - v2;
LABEL_24:
func2(v16);
LABEL_25:
LODWORD(v7) = func3(0);
break;
case 0x47u:
if ( (unsigned __int8)v0 <= 0x20u )
*((_WORD *)&intr + (unsigned __int8)v0) = v2;
break;
case 0x48u:
*((_WORD *)&reg + (unsigned __int8)v0) = v2;
break;
default:
return v7;
}
return v7;
}

original_code:
void vm_step()
{
 printf("PC=0x%04X ", reg[0]);
 if(reg_u32[127] && (reg[2] & 4))
 {
  int i;
  for(i = 0; i < 32; i++)
  {
   if(reg_u32[127] & (1 << i))
   {
    reg_u32[127] = (reg_u32[127] & (~(1 << i)));
    push(reg[2]);
    push(reg[0]);
    reg[0] = intr[i];
    reg[2] = reg[2] & ~(4);
    break;
   }
  }
 }
 uint8_t num_args;
 uint8_t a1, a2, a3, a4;
 uint8_t opcode = vmext_getbyte(reg[0]++);
 uint16_t pp;
 int32_t tmp32;
 if (opcode < 0x50) num_args = 3;
 if (opcode < 0x40) num_args = 2;
 if (opcode < 0x20) num_args = 1;
 if (opcode < 0x10) num_args = 0;
 if (num_args >= 1) a1 = vmext_getbyte(reg[0]++);
 if (num_args >= 2) a2 = vmext_getbyte(reg[0]++);
 if (num_args >= 3) a3 = vmext_getbyte(reg[0]++);
 if (num_args >= 4) a4 = vmext_getbyte(reg[0]++);
 printf("opcode=0x%02hhX", opcode);
 if (num_args >= 1) printf(" a1=0x%02hhi", a1);
 if (num_args >= 2) printf(" a2=0x%02hhi", a2);
 if (num_args >= 3) printf(" a3=0x%02hhi", a3);
 if (num_args >= 4) printf(" a4=0x%02hhi", a4);
 printf("\n");
 if (num_args == 2) pp = (a1 << 8) + a2;
 if (num_args == 3) pp = (a2 << 8) + a3;
 if (num_args == 4) pp = (a3 << 8) + a4;
 switch(opcode)
 {
  case 0x01:
   break;
  case 0x02:
   reg[0] = pop();
   break;
  case 0x03:
   reg[0] = pop();
   reg[2] = pop();
   break;
  case 0x04:
   reg[2] = reg[2] & (~4);
   break;
  case 0x05:
   reg[2] = reg[2]|4;
   break;
  case 0x06:
   reg[2] = reg[2]|8;
   break;
  case 0x10:
   tmp32 = reg[a1] + 1;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x11:
   tmp32 = reg[a1] - 1;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x12:
   push(reg[a1]);
   break;
  case 0x13:
   reg[a1] = pop();
   break;
  case 0x20:
   reg[a1] = reg[a2];
   break;
  case 0x21:
   reg[a1] = reg[(uint8_t)(reg[a2] & 255)];
   break;
  case 0x22:
   reg[(uint8_t)(reg[a1] & 255)] = reg[a2];
   break;
  case 0x23:
   reg[a1] = (int8_t)a2;
   break;
  case 0x24:
   reg[a1] = reg[a1] & reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x25:
   reg[a1] = reg[a1] | reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x26:
   reg[a1] = reg[a1] ^ reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x27:
   tmp32 = reg[a1] * reg[a2];
   reg[a1] = tmp32;
   chkcarry(tmp32 & 0xf0000);
   chkzero(tmp32);
   break;
  case 0x28:
   reg[a1] = reg[a1] / reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x29:
   tmp32 = reg[a1] + reg[a2];
   reg[a1] = tmp32 & 0xffff;
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x2A:
   tmp32 = reg[a1] - reg[a2];
   reg[a1] = tmp32 & 0xffff;
   chkcarry(tmp32 & 0xf0000);
   chkzero(reg[a1]);
   break;
  case 0x2B:
   reg[0] = pp;
   break;
  case 0x2C:
   push(reg[0]);
   reg[0] = pp;
   break;
  case 0x2D:
   if ((reg[2] & 1))
   {
    reg[0] = pp;
   }
   break;
  case 0x2E:
   if (!(reg[2] & 1))
   {
    reg[0] = pp;
   }
   break;
  case 0x2F:
   if((reg[2] & 2))
   {
    reg[0] = pp;
   }
   break;
  case 0x30:
   if(!(reg[2] & 2))
   {
    reg[0] = pp;
   }
   break;
  case 0x31:
   tmp32 = reg[a1] - reg[a2];
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x32:
   tmp32 = reg[a1] - (int16_t)a2;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x40:
   reg[a1] = (vmext_getbyte(pp) << 8) + vmext_getbyte(pp+1);
   break;
  case 0x41:
   reg[a1] = reg[a1] & (int16_t)pp;
   chkzero(reg[a1]);
   break;
  case 0x42:
   reg[a1] = reg[a1] | (int16_t)pp;
   chkzero(reg[a1]);
   break;
  case 0x43:
   reg[a1] = reg[a1] ^ (int16_t)pp;
   chkzero(reg[a1]);
   break;
  case 0x44:
   tmp32 = reg[a1] + (int16_t)pp;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x45:
   tmp32 = reg[a1] - (int16_t)pp;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x46:
   tmp32 = reg[a1] - (int16_t)pp;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x47:
   if (a1 <= 32)
   {
    intr[a1] = pp;
   }
   break;
  case 0x48:
   reg[a1] = (int16_t)pp;
   break;
 }
}

canonical_original_code:
void vm_step()
{
 printf("PC=0x%04X ", reg[0]);
 if(reg_u32[127] && (reg[2] & 4))
 {
  int i;
  for(i = 0; i < 32; i++)
  {
   if(reg_u32[127] & (1 << i))
   {
    reg_u32[127] = (reg_u32[127] & (~(1 << i)));
    push(reg[2]);
    push(reg[0]);
    reg[0] = intr[i];
    reg[2] = reg[2] & ~(4);
    break;
   }
  }
 }
 unsigned char num_args;
 unsigned char a1; unsigned char a2; unsigned char a3; unsigned char a4;
 unsigned char opcode = vmext_getbyte(reg[0]++);
 unsigned short pp;
 int tmp32;
 if (opcode < 0x50) num_args = 3;
 if (opcode < 0x40) num_args = 2;
 if (opcode < 0x20) num_args = 1;
 if (opcode < 0x10) num_args = 0;
 if (num_args >= 1) a1 = vmext_getbyte(reg[0]++);
 if (num_args >= 2) a2 = vmext_getbyte(reg[0]++);
 if (num_args >= 3) a3 = vmext_getbyte(reg[0]++);
 if (num_args >= 4) a4 = vmext_getbyte(reg[0]++);
 printf("opcode=0x%02hhX", opcode);
 if (num_args >= 1) printf(" a1=0x%02hhi", a1);
 if (num_args >= 2) printf(" a2=0x%02hhi", a2);
 if (num_args >= 3) printf(" a3=0x%02hhi", a3);
 if (num_args >= 4) printf(" a4=0x%02hhi", a4);
 printf("\n");
 if (num_args == 2) pp = (a1 << 8) + a2;
 if (num_args == 3) pp = (a2 << 8) + a3;
 if (num_args == 4) pp = (a3 << 8) + a4;
 switch(opcode)
 {
  case 0x01:
   break;
  case 0x02:
   reg[0] = pop();
   break;
  case 0x03:
   reg[0] = pop();
   reg[2] = pop();
   break;
  case 0x04:
   reg[2] = reg[2] & (~4);
   break;
  case 0x05:
   reg[2] = reg[2]|4;
   break;
  case 0x06:
   reg[2] = reg[2]|8;
   break;
  case 0x10:
   tmp32 = reg[a1] + 1;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x11:
   tmp32 = reg[a1] - 1;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x12:
   push(reg[a1]);
   break;
  case 0x13:
   reg[a1] = pop();
   break;
  case 0x20:
   reg[a1] = reg[a2];
   break;
  case 0x21:
   reg[a1] = reg[(unsigned char)(reg[a2] & 255)];
   break;
  case 0x22:
   reg[(unsigned char)(reg[a1] & 255)] = reg[a2];
   break;
  case 0x23:
   reg[a1] = (char)a2;
   break;
  case 0x24:
   reg[a1] = reg[a1] & reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x25:
   reg[a1] = reg[a1] | reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x26:
   reg[a1] = reg[a1] ^ reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x27:
   tmp32 = reg[a1] * reg[a2];
   reg[a1] = tmp32;
   chkcarry(tmp32 & 0xf0000);
   chkzero(tmp32);
   break;
  case 0x28:
   reg[a1] = reg[a1] / reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x29:
   tmp32 = reg[a1] + reg[a2];
   reg[a1] = tmp32 & 0xffff;
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x2A:
   tmp32 = reg[a1] - reg[a2];
   reg[a1] = tmp32 & 0xffff;
   chkcarry(tmp32 & 0xf0000);
   chkzero(reg[a1]);
   break;
  case 0x2B:
   reg[0] = pp;
   break;
  case 0x2C:
   push(reg[0]);
   reg[0] = pp;
   break;
  case 0x2D:
   if ((reg[2] & 1))
   {
    reg[0] = pp;
   }
   break;
  case 0x2E:
   if (!(reg[2] & 1))
   {
    reg[0] = pp;
   }
   break;
  case 0x2F:
   if((reg[2] & 2))
   {
    reg[0] = pp;
   }
   break;
  case 0x30:
   if(!(reg[2] & 2))
   {
    reg[0] = pp;
   }
   break;
  case 0x31:
   tmp32 = reg[a1] - reg[a2];
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x32:
   tmp32 = reg[a1] - (short)a2;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x40:
   reg[a1] = (vmext_getbyte(pp) << 8) + vmext_getbyte(pp+1);
   break;
  case 0x41:
   reg[a1] = reg[a1] & (short)pp;
   chkzero(reg[a1]);
   break;
  case 0x42:
   reg[a1] = reg[a1] | (short)pp;
   chkzero(reg[a1]);
   break;
  case 0x43:
   reg[a1] = reg[a1] ^ (short)pp;
   chkzero(reg[a1]);
   break;
  case 0x44:
   tmp32 = reg[a1] + (short)pp;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x45:
   tmp32 = reg[a1] - (short)pp;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x46:
   tmp32 = reg[a1] - (short)pp;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x47:
   if (a1 <= 32)
   {
    intr[a1] = pp;
   }
   break;
  case 0x48:
   reg[a1] = (short)pp;
   break;
 }
}

variable_types: i int

variable_types:
opcode
unsigned char

variable_types:
pp
unsigned short


decompiled_code:
__int64 __fastcall vmext_getbyte(unsigned __int16 a1)
{
return (unsigned __int8)firmware[a1];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1)
{
return (unsigned __int8)firmware[a1];
}

original_code:
uint8_t vmext_getbyte(uint16_t addr)
{
 return firmware[addr];
}

canonical_original_code:
unsigned char vmext_getbyte(unsigned short addr)
{
 return firmware[addr];
}

variable_types:
addr
unsigned short


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi
int v4; // eax

if ( argc == 1 )
{
printf("Usage: %s firmware.bin\n", *argv);
exit(0);
}
v3 = open(argv[1], 0, envp);
if ( v3 <= 0 )
{
perror("opening firmware file");
exit(1);
}
v4 = read(v3, firmware, (size_t)&unk_10000);
if ( v4 <= 0 )
{
perror("reading firmware file");
exit(1);
}
printf("Firmware: loaded %i bytes.\n", (unsigned int)v4);
vm_reset();
while ( (unsigned __int8)vm_running() == 1 )
vm_step();
return 0;
}

original_code:
int main(int argc, char** argv)
{
 if (argc == 1)
 {
  printf("Usage: %s firmware.bin\n", argv[0]);
  exit(0);
 }
 int i,f;
 f = open(argv[1],00);
 if ( f < 1)
 {
  perror("opening firmware file");
  exit(1);
 }
 i = read(f, firmware, 64*1024);
 if (i < 1)
 {
  perror("reading firmware file");
  exit(1);
 }
 printf("Firmware: loaded %i bytes.\n",i);
 vm_reset();
 while(vm_running() == 1)
 {
  vm_step();
 }
}

canonical_original_code:
int main(int argc, char **argv)
{
 if (argc == 1)
 {
  printf("Usage: %s firmware.bin\n", argv[0]);
  exit(0);
 }
 int i; int f;
 f = open(argv[1],00);
 if ( f < 1)
 {
  perror("opening firmware file");
  exit(1);
 }
 i = read(f, firmware, 64*1024);
 if (i < 1)
 {
  perror("reading firmware file");
  exit(1);
 }
 printf("Firmware: loaded %i bytes.\n",i);
 vm_reset();
 while(vm_running() == 1)
 {
  vm_step();
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: f int

return_type: int


freemakeargv

decompiled_code:
void __fastcall freemakeargv(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void freemakeargv(char **argv) {
 if (argv == ((void *)0))
  return;
 if (*argv != ((void *)0))
  free(*argv);
 free(argv);
}


makeargv

decompiled_code:
__int64 __fastcall makeargv(const char *a1, const char *a2, char ***a3)
{
const char *v4; // r13
size_t v5; // r15
char *v6; // rax
char *v7; // r14
int v8; // ebp
unsigned int v9; // er15
char **v10; // rax
char **v11; // rbp
__int64 v12; // r13
__int64 v13; // rbp
char **v14; // r14
char **v15; // r13
char **v17; // rax

if ( a3 == 0LL || a2 == 0LL || !a1 )
{
v9 = -1;
*__errno_location() = 22;
return v9;
}
*a3 = 0LL;
v4 = &a1[strspn(a1, a2)];
v5 = strlen(v4) + 1;
v6 = (char *)malloc(v5);
v7 = v6;
if ( !v6 )
return (unsigned int)-1;
memcpy(v6, v4, v5);
if ( strtok(v7, a2) )
{
v8 = 1;
do
v9 = v8++;
while ( strtok(0LL, a2) );
v10 = (char **)malloc(8LL * v8);
*a3 = v10;
v11 = v10;
if ( v10 )
{
strcpy(v7, v4);
v12 = 8LL * (int)v9;
*v11 = strtok(v7, a2);
if ( v9 != 1 )
{
v13 = 8LL;
do
{
v14 = &(*a3)[(unsigned __int64)v13 / 8];
v13 += 8LL;
*v14 = strtok(0LL, a2);
}
while ( v12 != v13 );
}
v15 = &(*a3)[(unsigned __int64)v12 / 8];
goto LABEL_12;
}
LABEL_16:
v9 = -1;
free(v7);
return v9;
}
v17 = (char **)malloc(8uLL);
*a3 = v17;
v15 = v17;
if ( !v17 )
goto LABEL_16;
v9 = 0;
free(v7);
LABEL_12:
*v15 = 0LL;
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, const char *a2, char ***a3)
{
const char *v4; // r13
size_t v5; // r15
char *v6; // rax
char *v7; // r14
int v8; // ebp
unsigned int v9; // er15
char **v10; // rax
char **v11; // rbp
__int64 v12; // r13
__int64 v13; // rbp
char **v14; // r14
char **v15; // r13
char **v17; // rax

if ( a3 == 0LL || a2 == 0LL || !a1 )
{
v9 = -1;
*__errno_location() = 22;
return v9;
}
*a3 = 0LL;
v4 = &a1[strspn(a1, a2)];
v5 = strlen(v4) + 1;
v6 = (char *)malloc(v5);
v7 = v6;
if ( !v6 )
return (unsigned int)-1;
memcpy(v6, v4, v5);
if ( strtok(v7, a2) )
{
v8 = 1;
do
v9 = v8++;
while ( strtok(0LL, a2) );
v10 = (char **)malloc(8LL * v8);
*a3 = v10;
v11 = v10;
if ( v10 )
{
strcpy(v7, v4);
v12 = 8LL * (int)v9;
*v11 = strtok(v7, a2);
if ( v9 != 1 )
{
v13 = 8LL;
do
{
v14 = &(*a3)[(unsigned __int64)v13 / 8];
v13 += 8LL;
*v14 = strtok(0LL, a2);
}
while ( v12 != v13 );
}
v15 = &(*a3)[(unsigned __int64)v12 / 8];
goto LABEL_12;
}
LABEL_16:
v9 = -1;
free(v7);
return v9;
}
v17 = (char **)malloc(8uLL);
*a3 = v17;
v15 = v17;
if ( !v17 )
goto LABEL_16;
v9 = 0;
free(v7);
LABEL_12:
*v15 = 0LL;
return v9;
}

original_code:
int makeargv(const char *s, const char *delimiters, char ***argvp) {
 int error;
 int i;
 int numtokens;
 const char *snew;
 char *t;
 if ((s == ((void *)0)) || (delimiters == ((void *)0)) || (argvp == ((void *)0))) {
  (*__errno_location ()) = 22;
  return -1;
 }
 *argvp = ((void *)0);
 snew = s + strspn(s, delimiters);
 if ((t = malloc(strlen(snew) + 1)) == ((void *)0))
  return -1;
 strcpy(t,snew);
 numtokens = 0;
 if (strtok(t, delimiters) != ((void *)0))
  for (numtokens = 1; strtok(((void *)0), delimiters) != ((void *)0); numtokens++) ;
 if ((*argvp = malloc((numtokens + 1)*sizeof(char *))) == ((void *)0)) {
  error = (*__errno_location ());
  free(t);
  (*__errno_location ()) = error;
  return -1;
 }
 if (numtokens == 0)
  free(t);
 else {
  strcpy(t,snew);
  **argvp = strtok(t,delimiters);
  for (i=1; i<numtokens; i++)
   *((*argvp) +i) = strtok(((void *)0),delimiters);
 }
 *((*argvp) + numtokens) = ((void *)0);
 return numtokens;
}

canonical_original_code:
int makeargv(char *s, char *delimiters, char ***argvp) {
 int error;
 int i;
 int numtokens;
 char *snew;
 char *t;
 if ((s == ((void *)0)) || (delimiters == ((void *)0)) || (argvp == ((void *)0))) {
  (*__errno_location ()) = 22;
  return -1;
 }
 *argvp = ((void *)0);
 snew = s + strspn(s, delimiters);
 if ((t = malloc(strlen(snew) + 1)) == ((void *)0))
  return -1;
 strcpy(t,snew);
 numtokens = 0;
 if (strtok(t, delimiters) != ((void *)0))
  for (numtokens = 1; strtok(((void *)0), delimiters) != ((void *)0); numtokens++) ;
 if ((*argvp = malloc((numtokens + 1)*sizeof(char *))) == ((void *)0)) {
  error = (*__errno_location ());
  free(t);
  (*__errno_location ()) = error;
  return -1;
 }
 if (numtokens == 0)
  free(t);
 else {
  strcpy(t,snew);
  **argvp = strtok(t,delimiters);
  for (i=1; i<numtokens; i++)
   *((*argvp) +i) = strtok(((void *)0),delimiters);
 }
 *((*argvp) + numtokens) = ((void *)0);
 return numtokens;
}

variable_types:
s
char *

variable_types:
delimiters
char *

variable_types:
argvp
char ***

variable_types: error int

variable_types: numtokens int

variable_types:
snew
char *

variable_types:
t
char *


original_code:
int parse_input_line(char *s, int id, node_t *node) {
 char **strings;
 char **child_list;
    char* line_location;
 int count = 0;
    int i;
    int tok_count = makeargv(s, ":", &strings);
 if (tok_count == -1) return 0;
 if(makeargv(strings[1], " ", &child_list) == -1) return 0;
    for (i = 0; i < tok_count; i++) {
  if((line_location = strpbrk(strings[i], "\n\r"))){
   *line_location = '\0';
        }
 }
 strcpy(node->prog,strings[0]);
 strcpy(node->input,strings[2]);
 strcpy(node->output,strings[3]);
 node->id = id;
 node->num_children = 0;
 while (child_list[count] != ((void *)0) && strcmp(child_list[count],"none")!=0) {
  node->children[count] = atoi(child_list[count]);
  node->num_children++;
  count++;
 }
    freemakeargv(strings);
 return 1;
}

canonical_original_code:
int parse_input_line(char *s, int id, struct node *node) {
 char **strings;
 char **child_list;
    char *line_location;
 int count = 0;
    int i;
    int tok_count = makeargv(s, ":", &strings);
 if (tok_count == -1) return 0;
 if(makeargv(strings[1], " ", &child_list) == -1) return 0;
    for (i = 0; i < tok_count; i++) {
  if((line_location = strpbrk(strings[i], "\n\r"))){
   *line_location = '\0';
        }
 }
 strcpy(node->prog,strings[0]);
 strcpy(node->input,strings[2]);
 strcpy(node->output,strings[3]);
 node->id = id;
 node->num_children = 0;
 while (child_list[count] != ((void *)0) && strcmp(child_list[count],"none")!=0) {
  node->children[count] = atoi(child_list[count]);
  node->num_children++;
  count++;
 }
    freemakeargv(strings);
 return 1;
}

variable_types: id int

variable_types: struct node { int id; char prog[1024]; char input[1024]; char output[1024]; int children[10]; int parents[50]; int num_children; int num_parents; int status; int pid; } *

variable_types:
strings
char **

variable_types: count int


decompiled_code:
void add_parent()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void add_parent(node_t * node, int parent_id) {
 int parent_count = node->num_parents;
    _Bool already_parent = 0;
    int i;
    for (i = 0; i < parent_count; i++)
        if(node->parents[i] == parent_id){
            already_parent = 1;
            break;
        }
    if (already_parent = 0){
        node->parents[node->num_parents++] = parent_id;
    }
}

canonical_original_code:
void add_parent(struct node *node, int parent_id) {
 int parent_count = node->num_parents;
    _Bool already_parent = 0;
    int i;
    for (i = 0; i < parent_count; i++)
        if(node->parents[i] == parent_id){
            already_parent = 1;
            break;
        }
    if (already_parent = 0){
        node->parents[node->num_parents++] = parent_id;
    }
}

variable_types: i int

user_defined_types: struct node { int id; char prog[1024]; char input[1024]; char output[1024]; int children[10]; int parents[50]; int num_children; int num_parents; int status; int pid; }


decompiled_code:
void link_nodes()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
void link_nodes(node_t * nodes[], int node_count) {
 int parent_id;
 int child_id;
 int child_index;
 int child_count;
 node_t * temp;
 for (parent_id = 0; parent_id < node_count; parent_id++) {
  temp = nodes[parent_id];
  child_count = temp->num_children;
  for (child_index = 0; child_index < child_count; child_index++) {
   child_id = temp->children[child_index];
   if (child_id < node_count) {
    add_parent(nodes[child_id], parent_id);
   }
  }
 }
}

canonical_original_code:
void link_nodes(struct node *nodes[], int node_count) {
 int parent_id;
 int child_id;
 int child_index;
 int child_count;
 struct node *temp;
 for (parent_id = 0; parent_id < node_count; parent_id++) {
  temp = nodes[parent_id];
  child_count = temp->num_children;
  for (child_index = 0; child_index < child_count; child_index++) {
   child_id = temp->children[child_index];
   if (child_id < node_count) {
    add_parent(nodes[child_id], parent_id);
   }
  }
 }
}

variable_types: struct node { int id; char prog[1024]; char input[1024]; char output[1024]; int children[10]; int parents[50]; int num_children; int num_parents; int status; int pid; } *[]


original_code:
void determine_eligible(node_t * nodes[], int count) {
 int i, j, parent_count;
    _Bool is_ready;
    node_t * node = (node_t*)malloc(sizeof(node_t));
 for (i = 0; i < count; i++) {
        node = nodes[i];
        parent_count = node->num_parents;
        is_ready = 1;
        if (node->status == 0) {
            while(j < parent_count && is_ready) {
                int parent_id = node->parents[j];
                if (nodes[parent_id]->status != 3) {
                    is_ready = 0;
                }
                j++;
            }
            if (is_ready) node->status = 1;
        }
 }
}

canonical_original_code:
void determine_eligible(struct node *nodes[], int count) {
 int i; int j; int parent_count;
    _Bool is_ready;
    struct node *node = (node_t*)malloc(sizeof(node_t));
 for (i = 0; i < count; i++) {
        node = nodes[i];
        parent_count = node->num_parents;
        is_ready = 1;
        if (node->status == 0) {
            while(j < parent_count && is_ready) {
                int parent_id = node->parents[j];
                if (nodes[parent_id]->status != 3) {
                    is_ready = 0;
                }
                j++;
            }
            if (is_ready) node->status = 1;
        }
 }
}

variable_types: j int


decompiled_code:
__int64 __fastcall run_node(__int64 a1)
{
unsigned int v2; // er12
int v3; // ebp
int v4; // er13
int v5; // er14
__pid_t v6; // eax
FILE *v7; // rdi
_DWORD stat_loc[13]; // [rsp+4h] [rbp-34h] BYREF

fflush(_bss_start);
v2 = dup(0);
if ( v2 == -1 )
{
perror("Failed to back-up stdin");
}
else
{
v3 = dup(1);
if ( v3 == -1 )
{
v2 = -1;
perror("Failed to back-up stdout");
}
else
{
v4 = open((const char *)(a1 + 1028), 64, 420LL);
if ( v4 == -1 )
{
v2 = -1;
perror("Failed to open input file");
}
else
{
v5 = open((const char *)(a1 + 2052), 65, 420LL);
if ( v5 == -1 )
{
v2 = -1;
perror("Failed to open output file");
}
else
{
fflush(_bss_start);
if ( dup2(v4, 0) == -1 )
{
v2 = -1;
perror("Failed to redirect stdin");
}
else if ( dup2(v5, 1) == -1 )
{
v2 = -1;
perror("Failed to redirect stdout");
}
else
{
makeargv((const char *)(a1 + 4), " ", (char ***)&stat_loc[1]);
*(_DWORD *)(a1 + 3324) = 2;
v6 = fork();
*(_DWORD *)(a1 + 3328) = v6;
if ( v6 )
wait((__WAIT_STATUS)stat_loc);
else
execvp(**(const char ***)&stat_loc[1], *(char *const *__attribute__((__org_arrdim(0,0))) *)&stat_loc[1]);
freemakeargv(*(void **)&stat_loc[1]);
v7 = _bss_start;
*(_DWORD *)(a1 + 3324) = 3;
fflush(v7);
if ( dup2(v3, 1) == -1 )
{
v2 = -1;
perror("Failed to redirect stdout to original stdout");
}
else if ( dup2(v2, 0) == -1 )
{
v2 = -1;
perror("Failed to redirect stdin to original stdin");
}
else
{
if ( close(v4) )
perror("Failed to close input_fd");
if ( close(v5) )
perror("Failed to close output_fd");
if ( close(v2) )
perror("Failed to close oldstdin");
if ( close(v3) )
perror("Failed to close oldstdout");
v2 = *(_DWORD *)(a1 + 3324);
}
}
}
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
unsigned int v2; // er12
int v3; // ebp
int v4; // er13
int v5; // er14
__pid_t v6; // eax
FILE *v7; // rdi
_DWORD stat_loc[13]; // [rsp+4h] [rbp-34h] BYREF

fflush(_bss_start);
v2 = dup(0);
if ( v2 == -1 )
{
perror("Failed to back-up stdin");
}
else
{
v3 = dup(1);
if ( v3 == -1 )
{
v2 = -1;
perror("Failed to back-up stdout");
}
else
{
v4 = open((const char *)(a1 + 1028), 64, 420LL);
if ( v4 == -1 )
{
v2 = -1;
perror("Failed to open input file");
}
else
{
v5 = open((const char *)(a1 + 2052), 65, 420LL);
if ( v5 == -1 )
{
v2 = -1;
perror("Failed to open output file");
}
else
{
fflush(_bss_start);
if ( dup2(v4, 0) == -1 )
{
v2 = -1;
perror("Failed to redirect stdin");
}
else if ( dup2(v5, 1) == -1 )
{
v2 = -1;
perror("Failed to redirect stdout");
}
else
{
func8((const char *)(a1 + 4), " ", (char ***)&stat_loc[1]);
*(_DWORD *)(a1 + 3324) = 2;
v6 = fork();
*(_DWORD *)(a1 + 3328) = v6;
if ( v6 )
wait((__WAIT_STATUS)stat_loc);
else
execvp(**(const char ***)&stat_loc[1], *(char *const *__attribute__((__org_arrdim(0,0))) *)&stat_loc[1]);
func7(*(void **)&stat_loc[1]);
v7 = _bss_start;
*(_DWORD *)(a1 + 3324) = 3;
fflush(v7);
if ( dup2(v3, 1) == -1 )
{
v2 = -1;
perror("Failed to redirect stdout to original stdout");
}
else if ( dup2(v2, 0) == -1 )
{
v2 = -1;
perror("Failed to redirect stdin to original stdin");
}
else
{
if ( close(v4) )
perror("Failed to close input_fd");
if ( close(v5) )
perror("Failed to close output_fd");
if ( close(v2) )
perror("Failed to close oldstdin");
if ( close(v3) )
perror("Failed to close oldstdout");
v2 = *(_DWORD *)(a1 + 3324);
}
}
}
}
}
}
return v2;
}

original_code:
int run_node(node_t * node) {
 char ** child_argv;
 int child_argc;
 int oldstdin, oldstdout;
 int input_fd, output_fd;
 int status;
 pid_t child_pid;
 fflush(stdout);
 if ((oldstdin = dup(0)) == -1) {
  perror("Failed to back-up stdin");
        return -1;
    }
 if ((oldstdout = dup(1)) == -1) {
  perror("Failed to back-up stdout");
  return -1;
 }
 if ((input_fd = open(node->input, 00 | 0100, 0644)) == -1) {
  perror("Failed to open input file");
        return -1;
    }
 if ((output_fd = open(node->output, 01 | 0100, 0644)) == -1) {
  perror("Failed to open output file");
        return -1;
    }
 fflush(stdout);
 if (dup2(input_fd, 0) == -1) {
  perror("Failed to redirect stdin");
        return -1;
    }
 if (dup2(output_fd, 1) == -1) {
  perror("Failed to redirect stdout");
        return -1;
    }
 child_argc = makeargv(node->prog, " ", &child_argv);
    node->status = 2;
 node->pid = child_pid = fork();
 if (child_pid) wait(&status);
 else execvp(child_argv[0], &child_argv[0]);
 freemakeargv(child_argv);
 node->status = 3;
 fflush(stdout);
 if (dup2(oldstdout, 1) == -1) {
  perror("Failed to redirect stdout to original stdout");
        return -1;
    }
 if (dup2(oldstdin, 0) == -1) {
  perror("Failed to redirect stdin to original stdin");
        return -1;
    }
 if (close(input_fd)) perror("Failed to close input_fd");
 if (close(output_fd)) perror("Failed to close output_fd");
 if (close(oldstdin)) perror("Failed to close oldstdin");
 if (close(oldstdout)) perror("Failed to close oldstdout");
 return node->status;
}

canonical_original_code:
int run_node(struct node *node) {
 char **child_argv;
 int child_argc;
 int oldstdin; int oldstdout;
 int input_fd; int output_fd;
 int status;
 int child_pid;
 fflush(stdout);
 if ((oldstdin = dup(0)) == -1) {
  perror("Failed to back-up stdin");
        return -1;
    }
 if ((oldstdout = dup(1)) == -1) {
  perror("Failed to back-up stdout");
  return -1;
 }
 if ((input_fd = open(node->input, 00 | 0100, 0644)) == -1) {
  perror("Failed to open input file");
        return -1;
    }
 if ((output_fd = open(node->output, 01 | 0100, 0644)) == -1) {
  perror("Failed to open output file");
        return -1;
    }
 fflush(stdout);
 if (dup2(input_fd, 0) == -1) {
  perror("Failed to redirect stdin");
        return -1;
    }
 if (dup2(output_fd, 1) == -1) {
  perror("Failed to redirect stdout");
        return -1;
    }
 child_argc = makeargv(node->prog, " ", &child_argv);
    node->status = 2;
 node->pid = child_pid = fork();
 if (child_pid) wait(&status);
 else execvp(child_argv[0], &child_argv[0]);
 freemakeargv(child_argv);
 node->status = 3;
 fflush(stdout);
 if (dup2(oldstdout, 1) == -1) {
  perror("Failed to redirect stdout to original stdout");
        return -1;
    }
 if (dup2(oldstdin, 0) == -1) {
  perror("Failed to redirect stdin to original stdin");
        return -1;
    }
 if (close(input_fd)) perror("Failed to close input_fd");
 if (close(output_fd)) perror("Failed to close output_fd");
 if (close(oldstdin)) perror("Failed to close oldstdin");
 if (close(oldstdout)) perror("Failed to close oldstdout");
 return node->status;
}

variable_types: oldstdin int

variable_types: oldstdout int

variable_types: status int


decompiled_code:
void __fastcall free_array(void **a1, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
{
if ( *v2 )
free(*v2);
++v2;
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

canonical_decompiled_code:
void __fastcall func15(void **a1, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
{
if ( *v2 )
free(*v2);
++v2;
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

original_code:
void free_array(node_t * nodes[], int count) {
 int i;
 for(i = 0; i < count; i++) {
  if (nodes[i]) free(nodes[i]);
 }
}

canonical_original_code:
void free_array(struct node *nodes[], int count) {
 int i;
 for(i = 0; i < count; i++) {
  if (nodes[i]) free(nodes[i]);
 }
}


main

repo: Datera/lio-utils

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
const char *v4; // r14
int v5; // eax
int v6; // er12
unsigned __int8 *v7; // rbx
int v8; // eax
int v9; // ebp
char *v10; // rax
char *v11; // rax
int result; // eax
int v13; // eax
__int64 v14; // [rsp+0h] [rbp-370h] BYREF
struct timeval tv; // [rsp+8h] [rbp-368h] BYREF
__int128 v16; // [rsp+18h] [rbp-358h] BYREF
char buf[16]; // [rsp+28h] [rbp-348h] BYREF
char s[16]; // [rsp+38h] [rbp-338h] BYREF
char v19[96]; // [rsp+48h] [rbp-328h] BYREF
char v20[256]; // [rsp+A8h] [rbp-2C8h] BYREF
char v21; // [rsp+1A8h] [rbp-1C8h]
struct utsname name; // [rsp+1B8h] [rbp-1B8h] BYREF

v16 = 0LL;
memset(v20, 0, sizeof(v20));
v21 = 0;
memset(v19, 0, 0x58uLL);
MD5Init(v19, argv, envp);
if ( argc > 1 && (v3 = argv[1]) != 0LL )
{
if ( !strcmp(argv[1], "-h") || !strcmp(v3, "--help") )
{
puts("\nDisplays the iSCSI initiator name");
exit(0);
}
if ( strcmp(v3, "-p") )
{
puts("\nUsage: iscsi-iname [-h | --help | -p <prefix>]");
exit(0);
}
v4 = argv[2];
}
else
{
v4 = "iqn.2003-01.org.linux-iscsi";
}
v5 = open("/dev/urandom", 0);
v6 = v5;
if ( v5 )
{
v13 = read(v5, buf, 0x10uLL);
if ( v13 > 0 )
MD5Update(v19, buf, (unsigned int)v13);
close(v6);
}
if ( gettimeofday(&tv, 0LL) < 0 )
{
perror("error: gettimeofday failed");
result = 1;
}
else
{
MD5Update(v19, &tv, 8LL);
MD5Update(v19, &tv.tv_usec, 8LL);
v14 = gethostid();
MD5Update(v19, &v14, 8LL);
if ( uname(&name) < 0 )
{
perror("error: uname failed");
result = 1;
}
else
{
v7 = (unsigned __int8 *)&v16;
MD5Update(v19, &name, 65LL);
MD5Update(v19, name.nodename, 65LL);
MD5Update(v19, name.release, 65LL);
MD5Update(v19, name.version, 65LL);
MD5Update(v19, name.machine, 65LL);
MD5Final(&v16, v19);
v8 = open("/dev/urandom", 0);
v9 = v8;
if ( v8 )
{
if ( read(v8, buf, 1uLL) == 1 )
v7 = (unsigned __int8 *)&v16 + buf[0] % 0xAu;
close(v9);
}
v10 = strchr(name.nodename, 46);
if ( v10 )
*v10 = 0;
snprintf(s, 0x10uLL, "%s", name.machine);
v11 = strchr(s, 95);
if ( v11 )
*v11 = 0;
sprintf(v20, "%s.%s.%s:sn.%x%x%x%x%x%x", v4, name.nodename, s, *v7, v7[1], v7[2], v7[3], v7[4], v7[5]);
v21 = 0;
puts(v20);
result = 0;
}
}
return result;
}

original_code:
int
main(int argc, char *argv[])
{
 char iname[256 + 1], *ptr;
 struct timeval time;
 struct utsname system_info;
 long hostid;
 struct MD5Context context;
 unsigned char digest[16];
 unsigned char *bytes = digest;
 unsigned char entropy[16], machine[16];
 int e;
 int fd;
 char *prefix;
 memset(iname, 0, sizeof (iname));
 memset(digest, 0, sizeof (digest));
 memset(&context, 0, sizeof (context));
 MD5Init(&context);
 if (argc > 1 && argv[1]) {
  prefix = argv[1];
  if (( strcmp(prefix, "-h") == 0 ) ||
      ( strcmp(prefix, "--help") == 0 )) {
   printf("\nDisplays the iSCSI initiator name\n");
   exit(0);
  } else if ( strcmp(prefix, "-p") == 0 ) {
   prefix = argv[2];
  } else {
   printf("\nUsage: iscsi-iname [-h | --help | "
          "-p <prefix>]\n");
   exit(0);
  }
 } else {
  prefix = "iqn.2003-01.org.linux-iscsi";
 }
 if ((fd = open("/dev/urandom", 00))) {
  e = read(fd, &entropy, 16);
  if (e >= 1)
   MD5Update(&context, (unsigned char *)entropy, e);
  close(fd);
 }
 if (gettimeofday(&time, ((void *)0)) < 0) {
  perror("error: gettimeofday failed");
  return 1;
 }
 MD5Update(&context, (unsigned char *) & time.tv_sec, sizeof (time.tv_sec));
 MD5Update(&context, (unsigned char *) & time.tv_usec, sizeof (time.tv_usec));
 hostid = gethostid();
 MD5Update(&context, (unsigned char *) & hostid, sizeof (hostid));
 if (uname(&system_info) < 0) {
  perror("error: uname failed");
  return 1;
 }
 MD5Update(&context, (unsigned char *) system_info.sysname,
    sizeof (system_info.sysname));
 MD5Update(&context, (unsigned char *) system_info.nodename,
    sizeof (system_info.nodename));
 MD5Update(&context, (unsigned char *) system_info.release,
    sizeof (system_info.release));
 MD5Update(&context, (unsigned char *) system_info.version,
    sizeof (system_info.version));
 MD5Update(&context, (unsigned char *) system_info.machine,
    sizeof (system_info.machine));
 MD5Final(digest, &context);
 if ((fd = open("/dev/urandom", 00))) {
  if (read(fd, entropy, 1) == 1)
   bytes = &digest[(entropy[0] % (sizeof(digest) - 6))];
  close(fd);
 }
 if ((ptr = strstr(system_info.nodename, ".")))
  (*ptr) = '\0';
 snprintf(machine, 16, "%s", system_info.machine);
 if ((ptr = strstr(machine, "_")))
  *ptr = '\0';
 sprintf(iname, "%s.%s.%s:sn.%x%x%x%x%x%x", prefix, system_info.nodename, machine,
  bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]);
 iname[sizeof (iname) - 1] = '\0';
 printf("%s\n", iname);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char iname[-1]; char *ptr;
 struct timeval time;
 struct utsname system_info;
 long hostid;
 struct MD5Context context;
 unsigned char digest[16];
 unsigned char *bytes = digest;
 unsigned char entropy[16]; unsigned char machine[16];
 int e;
 int fd;
 char *prefix;
 memset(iname, 0, sizeof (iname));
 memset(digest, 0, sizeof (digest));
 memset(&context, 0, sizeof (context));
 MD5Init(&context);
 if (argc > 1 && argv[1]) {
  prefix = argv[1];
  if (( strcmp(prefix, "-h") == 0 ) ||
      ( strcmp(prefix, "--help") == 0 )) {
   printf("\nDisplays the iSCSI initiator name\n");
   exit(0);
  } else if ( strcmp(prefix, "-p") == 0 ) {
   prefix = argv[2];
  } else {
   printf("\nUsage: iscsi-iname [-h | --help | "
          "-p <prefix>]\n");
   exit(0);
  }
 } else {
  prefix = "iqn.2003-01.org.linux-iscsi";
 }
 if ((fd = open("/dev/urandom", 00))) {
  e = read(fd, &entropy, 16);
  if (e >= 1)
   MD5Update(&context, (unsigned char *)entropy, e);
  close(fd);
 }
 if (gettimeofday(&time, ((void *)0)) < 0) {
  perror("error: gettimeofday failed");
  return 1;
 }
 MD5Update(&context, (unsigned char *) & time.tv_sec, sizeof (time.tv_sec));
 MD5Update(&context, (unsigned char *) & time.tv_usec, sizeof (time.tv_usec));
 hostid = gethostid();
 MD5Update(&context, (unsigned char *) & hostid, sizeof (hostid));
 if (uname(&system_info) < 0) {
  perror("error: uname failed");
  return 1;
 }
 MD5Update(&context, (unsigned char *) system_info.sysname,
    sizeof (system_info.sysname));
 MD5Update(&context, (unsigned char *) system_info.nodename,
    sizeof (system_info.nodename));
 MD5Update(&context, (unsigned char *) system_info.release,
    sizeof (system_info.release));
 MD5Update(&context, (unsigned char *) system_info.version,
    sizeof (system_info.version));
 MD5Update(&context, (unsigned char *) system_info.machine,
    sizeof (system_info.machine));
 MD5Final(digest, &context);
 if ((fd = open("/dev/urandom", 00))) {
  if (read(fd, entropy, 1) == 1)
   bytes = &digest[(entropy[0] % (sizeof(digest) - 6))];
  close(fd);
 }
 if ((ptr = strstr(system_info.nodename, ".")))
  (*ptr) = '\0';
 snprintf(machine, 16, "%s", system_info.machine);
 if ((ptr = strstr(machine, "_")))
  *ptr = '\0';
 sprintf(iname, "%s.%s.%s:sn.%x%x%x%x%x%x", prefix, system_info.nodename, machine,
  bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]);
 iname[sizeof (iname) - 1] = '\0';
 printf("%s\n", iname);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
iname
char [-1]

variable_types:
ptr
char *

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

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char __domainname[65]; }

variable_types: hostid long

variable_types: struct MD5Context { unsigned int buf[4]; unsigned int bytes[2]; unsigned int in[16]; }

variable_types:
digest
unsigned char [16]

variable_types:
bytes
unsigned char *

variable_types:
entropy
unsigned char [16]

variable_types:
machine
unsigned char [16]

variable_types: e int

variable_types: fd int

variable_types:
prefix
char *


power

repo: DePierre/big-int

decompiled_code:
__int64 __fastcall power(unsigned int a1, int a2)
{
unsigned int v2; // er8
int i; // eax

v2 = a1;
if ( a2 > 1 )
{
for ( i = 1; i != a2; ++i )
v2 *= a1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2)
{
unsigned int v2; // er8
int i; // eax

v2 = a1;
if ( a2 > 1 )
{
for ( i = 1; i != a2; ++i )
v2 *= a1;
}
return v2;
}

original_code:
int power(int n, int p)
{
    int i, current = n;
    for(i = 1; i < p; i = i + 1)
        current = current*n;
    return current;
}

canonical_original_code:
int power(int n, int p)
{
    int i; int current = n;
    for(i = 1; i < p; i = i + 1)
        current = current*n;
    return current;
}

variable_types: n int

variable_types: p int

variable_types: i int

variable_types: current int


decompiled_code:
int clean_stdin()
{
int result; // eax
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

do
{
result = scanf("%c", v1);
if ( result != 1 )
break;
result = (unsigned __int8)v1[0];
if ( v1[0] == 13 )
break;
}
while ( v1[0] != 10 );
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

do
{
result = scanf("%c", v1);
if ( result != 1 )
break;
result = (unsigned __int8)v1[0];
if ( v1[0] == 13 )
break;
}
while ( v1[0] != 10 );
return result;
}

original_code:
void clean_stdin()
{
    char c;
    while (scanf("%c",&c)==1 && c!=10 && c!=13);
}

variable_types: c char


decompiled_code:
__int64 display_menu()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = 0;
puts("Menu: ");
puts("1. Define the first big integer");
puts("2. Define the second big integer");
puts("3. Swap the two big integers");
puts("\n4. Sum big integers");
puts("5. Diff big integers");
puts("6. Mul big integers");
puts("\n7. Factorial");
puts("\n8. Print the big integers");
puts("\n9. Quit");
printf("\nChoice : ");
scanf("%d", v1);
putchar(10);
return v1[0];
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = 0;
puts("Menu: ");
puts("1. Define the first big integer");
puts("2. Define the second big integer");
puts("3. Swap the two big integers");
puts("\n4. Sum big integers");
puts("5. Diff big integers");
puts("6. Mul big integers");
puts("\n7. Factorial");
puts("\n8. Print the big integers");
puts("\n9. Quit");
printf("\nChoice : ");
scanf("%d", v1);
putchar(10);
return v1[0];
}

original_code:
int display_menu()
{
    int choice = 0;
    printf("Menu: \n");
    printf("1. Define the first big integer\n");
    printf("2. Define the second big integer\n");
    printf("3. Swap the two big integers\n");
    printf("\n4. Sum big integers\n");
    printf("5. Diff big integers\n");
    printf("6. Mul big integers\n");
    printf("\n7. Factorial\n");
    printf("\n8. Print the big integers\n");
    printf("\n9. Quit\n");
    printf("\nChoice : ");
    scanf("%d", &choice);
    printf("\n");
    return choice;
}

variable_types: choice int


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er15
__int64 v4; // r14
__int64 v5; // r13
const char **v6; // r12
__int64 v7; // rbp
int v8; // ebx
__int64 v9; // rax
_BYTE *v10; // rbx
_BYTE *v11; // rbx
const char **v13; // [rsp+8h] [rbp-40h] BYREF

v3 = 0;
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v13 = 0LL;
while ( 1 )
{
v8 = display_menu(*(_QWORD *)&argc, argv, envp);
switch ( v8 )
{
case 1:
clean_stdin();
v11 = new_str_of_big_int(1u);
v5 = newBigInteger(v11);
free(v11);
break;
case 2:
clean_stdin();
v10 = new_str_of_big_int(2u);
v6 = (const char **)newBigInteger(v10);
free(v10);
break;
case 3:
v4 = fromBigIntegerToBigInteger(v5);
v5 = fromBigIntegerToBigInteger(v6);
v6 = (const char **)fromBigIntegerToBigInteger(v4);
break;
case 4:
argv = v6;
v3 = 43;
v7 = sumBigInt(v5, v6);
break;
case 5:
argv = v6;
v3 = 45;
v7 = diffBigInt(v5, v6);
break;
case 6:
argv = v6;
v3 = 42;
v7 = mulBigInt(v5, v6);
break;
case 7:
printf("Enter the number :\t");
scanf("%lu", &v13);
v9 = factorial(v13);
argv = v13;
v7 = v9;
printf("(%ld)! = ", v13);
printBigInteger(v7);
break;
case 8:
printf("BigInteger 1 :\t");
printBigInteger(v5);
printf("BigInteger 2:\t");
printBigInteger(v6);
if ( v3 )
{
argv = (const char **)v3;
printf("\n(1) %c (2) = ", v3);
printBigInteger(v7);
}
break;
default:
*(_QWORD *)&argc = 10LL;
putchar(10);
if ( v8 != 9 )
continue;
delete_big_int(v5);
delete_big_int(v6);
delete_big_int(v7);
delete_big_int(v4);
return 0;
}
*(_QWORD *)&argc = 10LL;
putchar(10);
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er15
__int64 v4; // r14
__int64 v5; // r13
const char **v6; // r12
__int64 v7; // rbp
int v8; // ebx
__int64 v9; // rax
_BYTE *v10; // rbx
_BYTE *v11; // rbx
const char **v13; // [rsp+8h] [rbp-40h] BYREF

v3 = 0;
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v13 = 0LL;
while ( 1 )
{
v8 = func0(*(_QWORD *)&argc, argv, envp);
switch ( v8 )
{
case 1:
clean_stdin();
v11 = new_str_of_big_int(1u);
v5 = newBigInteger(v11);
free(v11);
break;
case 2:
clean_stdin();
v10 = new_str_of_big_int(2u);
v6 = (const char **)newBigInteger(v10);
free(v10);
break;
case 3:
v4 = fromBigIntegerToBigInteger(v5);
v5 = fromBigIntegerToBigInteger(v6);
v6 = (const char **)fromBigIntegerToBigInteger(v4);
break;
case 4:
argv = v6;
v3 = 43;
v7 = sumBigInt(v5, v6);
break;
case 5:
argv = v6;
v3 = 45;
v7 = diffBigInt(v5, v6);
break;
case 6:
argv = v6;
v3 = 42;
v7 = mulBigInt(v5, v6);
break;
case 7:
printf("Enter the number :\t");
scanf("%lu", &v13);
v9 = factorial(v13);
argv = v13;
v7 = v9;
printf("(%ld)! = ", v13);
printBigInteger(v7);
break;
case 8:
printf("BigInteger 1 :\t");
printBigInteger(v5);
printf("BigInteger 2:\t");
printBigInteger(v6);
if ( v3 )
{
argv = (const char **)v3;
printf("\n(1) %c (2) = ", v3);
printBigInteger(v7);
}
break;
default:
*(_QWORD *)&argc = 10LL;
putchar(10);
if ( v8 != 9 )
continue;
delete_big_int(v5);
delete_big_int(v6);
delete_big_int(v7);
delete_big_int(v4);
return 0;
}
*(_QWORD *)&argc = 10LL;
putchar(10);
}
}

original_code:
int main(void)
{
    int choice = 0, lastOpe = 0;
    unsigned long fact = 0;
    char *str = ((void *)0);
    BigInteger biOne = ((void *)0), biTwo = ((void *)0), res = ((void *)0), temp = ((void *)0);
    do
    {
        choice = display_menu();
        switch(choice)
        {
            case 1:
                clean_stdin();
                str = new_str_of_big_int(1);
                biOne = newBigInteger(str);
                free(str);
                str = ((void *)0);
                break;
            case 2:
                clean_stdin();
                str = new_str_of_big_int(2);
                biTwo = newBigInteger(str);
                free(str);
                str = ((void *)0);
                break;
            case 3:
                temp = fromBigIntegerToBigInteger(biOne);
                biOne = fromBigIntegerToBigInteger(biTwo);
                biTwo = fromBigIntegerToBigInteger(temp);
                break;
            case 4:
                lastOpe = '+';
                res = sumBigInt(biOne, biTwo);
                break;
            case 5:
                lastOpe = '-';
                res = diffBigInt(biOne, biTwo);
                break;
            case 6:
                lastOpe = '*';
                res = mulBigInt(biOne, biTwo);
                break;
            case 7:
                printf("Enter the number :\t");
                scanf("%lu", &fact);
                res = factorial(fact);
                printf("(%ld)! = ", fact);
                printBigInteger(res);
                break;
            case 8:
                printf("BigInteger 1 :\t");
                printBigInteger(biOne);
                printf("BigInteger 2:\t");
                printBigInteger(biTwo);
                if(lastOpe != 0)
                {
                    printf("\n(1) %c (2) = ", lastOpe);
                    printBigInteger(res);
                }
                break;
        }
        printf("\n");
    }while (choice != 9);
    delete_big_int(biOne);
    delete_big_int(biTwo);
    delete_big_int(res);
    delete_big_int(temp);
    return 0;
}

canonical_original_code:
int main()
{
    int choice = 0; int lastOpe = 0;
    unsigned long fact = 0;
    char *str = ((void *)0);
    struct Struct_big_integer *biOne = ((void *)0); struct Struct_big_integer *biTwo = ((void *)0); struct Struct_big_integer *res = ((void *)0); struct Struct_big_integer *temp = ((void *)0);
    do
    {
        choice = display_menu();
        switch(choice)
        {
            case 1:
                clean_stdin();
                str = new_str_of_big_int(1);
                biOne = newBigInteger(str);
                free(str);
                str = ((void *)0);
                break;
            case 2:
                clean_stdin();
                str = new_str_of_big_int(2);
                biTwo = newBigInteger(str);
                free(str);
                str = ((void *)0);
                break;
            case 3:
                temp = fromBigIntegerToBigInteger(biOne);
                biOne = fromBigIntegerToBigInteger(biTwo);
                biTwo = fromBigIntegerToBigInteger(temp);
                break;
            case 4:
                lastOpe = '+';
                res = sumBigInt(biOne, biTwo);
                break;
            case 5:
                lastOpe = '-';
                res = diffBigInt(biOne, biTwo);
                break;
            case 6:
                lastOpe = '*';
                res = mulBigInt(biOne, biTwo);
                break;
            case 7:
                printf("Enter the number :\t");
                scanf("%lu", &fact);
                res = factorial(fact);
                printf("(%ld)! = ", fact);
                printBigInteger(res);
                break;
            case 8:
                printf("BigInteger 1 :\t");
                printBigInteger(biOne);
                printf("BigInteger 2:\t");
                printBigInteger(biTwo);
                if(lastOpe != 0)
                {
                    printf("\n(1) %c (2) = ", lastOpe);
                    printBigInteger(res);
                }
                break;
        }
        printf("\n");
    }while (choice != 9);
    delete_big_int(biOne);
    delete_big_int(biTwo);
    delete_big_int(res);
    delete_big_int(temp);
    return 0;
}

variable_types: lastOpe int

variable_types:
fact
unsigned long

variable_types:
str
char *

variable_types: struct Struct_big_integer { int sign; struct struct_dlist { unsigned int length; struct element { int key; struct element *next; struct element *prev; } *head; struct element *tail; } *list; } *

user_defined_types: struct Struct_big_integer { int sign; struct struct_dlist *list; }

user_defined_types: struct struct_dlist { unsigned int length; struct element *head; struct element *tail; }


repo: Detegr/dtgconf

decompiled_code:
void __fastcall item_free(__int64 a1)
{
void *v1; // rdi

free(*(void **)a1);
v1 = *(void **)(a1 + 8);
if ( v1 )
free(v1);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
void *v1; // rdi

free(*(void **)a1);
v1 = *(void **)(a1 + 8);
if ( v1 )
free(v1);
}

original_code:
static void item_free(struct configitem *item)
{
 free(item->key);
 if(item->val) free(item->val);
}

variable_types: struct configitem { char *key; char *val; } *


original_code:
static void section_free(struct configsection *sect)
{
 free(sect->name);
 for(unsigned int i=0; i<sect->itemcount; ++i)
 {
  item_free(sect->items[i]);
  free(sect->items[i]);
 }
 free(sect->items);
}

canonical_original_code:
static void section_free(struct configsection *sect)
{
 free(sect->name);
 for(unsigned int i = 0; i<sect->itemcount; ++i)
 {
  item_free(sect->items[i]);
  free(sect->items[i]);
 }
 free(sect->items);
}

variable_types: struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem { char *key; char *val; } **items; } *

variable_types:
i
unsigned int

user_defined_types: struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem **items; }


decompiled_code:
void __fastcall item_add(__int64 a1, const char *a2, const char *a3)
{
unsigned int v6; // eax
size_t v7; // rsi
__int64 v8; // rax
void *v9; // rax
_QWORD *v10; // rbp
__int64 v11; // rax
_QWORD *v12; // rdi
size_t v13; // rsi

v6 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) >= v6 )
{
if ( v6 )
{
v8 = 2 * v6;
v7 = 8 * v8;
}
else
{
v7 = 64LL;
LODWORD(v8) = 8;
}
*(_DWORD *)(a1 + 12) = v8;
v9 = realloc(*(void **)(a1 + 16), v7);
if ( !v9 )
_assert_fail("newitems != NULL", "src/config.c", 0x58u, "item_add");
*(_QWORD *)(a1 + 16) = v9;
}
v10 = malloc(0x10uLL);
*v10 = strndup(a2, 0xFFuLL);
if ( a3 )
v10[1] = strndup(a3, 0xFFuLL);
else
v10[1] = 0LL;
v11 = *(unsigned int *)(a1 + 8);
v12 = *(_QWORD **)(a1 + 16);
v13 = (unsigned int)(v11 + 1);
*(_DWORD *)(a1 + 8) = v13;
v12[v11] = v10;
qsort(v12, v13, 8uLL, item_sort);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, const char *a2, const char *a3)
{
unsigned int v6; // eax
size_t v7; // rsi
__int64 v8; // rax
void *v9; // rax
_QWORD *v10; // rbp
__int64 v11; // rax
_QWORD *v12; // rdi
size_t v13; // rsi

v6 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) >= v6 )
{
if ( v6 )
{
v8 = 2 * v6;
v7 = 8 * v8;
}
else
{
v7 = 64LL;
LODWORD(v8) = 8;
}
*(_DWORD *)(a1 + 12) = v8;
v9 = realloc(*(void **)(a1 + 16), v7);
if ( !v9 )
_assert_fail("newitems != NULL", "src/config.c", 0x58u, "item_add");
*(_QWORD *)(a1 + 16) = v9;
}
v10 = malloc(0x10uLL);
*v10 = strndup(a2, 0xFFuLL);
if ( a3 )
v10[1] = strndup(a3, 0xFFuLL);
else
v10[1] = 0LL;
v11 = *(unsigned int *)(a1 + 8);
v12 = *(_QWORD **)(a1 + 16);
v13 = (unsigned int)(v11 + 1);
*(_DWORD *)(a1 + 8) = v13;
v12[v11] = v10;
qsort(v12, v13, 8uLL, item_sort);
}

original_code:
static void item_add(struct configsection *section, const char *key, const char *val)
{
 if(section->itemcount >= section->size)
 {
  section->size = section->size?section->size*2:8;
  struct configitem **newitems = (struct configitem**)realloc(section->items, section->size *sizeof(struct configitem*));
  ((newitems != ((void *)0)) ? (void) (0) : __assert_fail ("newitems != NULL", "src/config.c", 88, __extension__ __PRETTY_FUNCTION__));
  section->items=newitems;
 }
 struct configitem *newitem = (struct configitem*)malloc(sizeof(struct configitem));
 newitem->key = strndup(key, 255);
 if(val) newitem->val = strndup(val, 255);
 else newitem->val = ((void *)0);
 section->items[section->itemcount++] = newitem;
 qsort(section->items, section->itemcount, sizeof(struct configitem*), item_sort);
}

canonical_original_code:
static void item_add(struct configsection *section, char *key, char *val)
{
 if(section->itemcount >= section->size)
 {
  section->size = section->size?section->size*2:8;
  struct configitem **newitems = (struct configitem**)realloc(section->items, section->size *sizeof(struct configitem*));
  ((newitems != ((void *)0)) ? (void) (0) : __assert_fail ("newitems != NULL", "src/config.c", 88, __extension__ __PRETTY_FUNCTION__));
  section->items=newitems;
 }
 struct configitem *newitem = (struct configitem*)malloc(sizeof(struct configitem));
 newitem->key = strndup(key, 255);
 if(val) newitem->val = strndup(val, 255);
 else newitem->val = ((void *)0);
 section->items[section->itemcount++] = newitem;
 qsort(section->items, section->itemcount, sizeof(struct configitem *), item_sort);
}

variable_types:
key
char *

variable_types:
val
char *

variable_types: struct configitem { char *key; char *val; } **


decompiled_code:
int __fastcall item_sort(const void *a1, const void *a2)
{
return strncmp(**(const char ***)a1, **(const char ***)a2, 0xFFuLL);
}

canonical_decompiled_code:
int __fastcall func4(const void *a1, const void *a2)
{
return strncmp(**(const char ***)a1, **(const char ***)a2, 0xFFuLL);
}

original_code:
static int item_sort(const void *a, const void *b)
{
 return strncmp((*(struct configitem**)a)->key,(*(struct configitem**)b)->key,255);
}

canonical_original_code:
static int item_sort(void *a, void *b)
{
 return strncmp((*(struct configitem **)a)->key,(*(struct configitem **)b)->key,255);
}

variable_types:
a
void *

variable_types:
b
void *

user_defined_types: struct configitem { char *key; char *val; }


decompiled_code:
int __fastcall section_sort(const void *a1, const void *a2)
{
return strncmp(**(const char ***)a1, **(const char ***)a2, 0xFFuLL);
}

canonical_decompiled_code:
int __fastcall func5(const void *a1, const void *a2)
{
return strncmp(**(const char ***)a1, **(const char ***)a2, 0xFFuLL);
}

original_code:
static int section_sort(const void *a, const void *b)
{
 return strncmp((*(struct configsection**)a)->name,(*(struct configsection**)b)->name,255);
}

canonical_original_code:
static int section_sort(void *a, void *b)
{
 return strncmp((*(struct configsection **)a)->name,(*(struct configsection **)b)->name,255);
}


decompiled_code:
int __fastcall section_compare(const char *a1, const char ***a2)
{
return strncmp(a1, **a2, 0xFFuLL);
}

canonical_decompiled_code:
int __fastcall func6(const char *a1, const char ***a2)
{
return strncmp(a1, **a2, 0xFFuLL);
}

original_code:
static int section_compare(const void *a, const void *b)
{
 return strncmp((const char*)a,(*(struct configsection**)b)->name,255);
}

canonical_original_code:
static int section_compare(void *a, void *b)
{
 return strncmp((char *)a,(*(struct configsection **)b)->name,255);
}


decompiled_code:
int __fastcall item_compare(const char *a1, const char ***a2)
{
return strncmp(a1, **a2, 0xFFuLL);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, const char ***a2)
{
return strncmp(a1, **a2, 0xFFuLL);
}

original_code:
static int item_compare(const void *a, const void *b)
{
 return strncmp((const char*)a,(*(struct configitem**)b)->key,255);
}

canonical_original_code:
static int item_compare(void *a, void *b)
{
 return strncmp((char *)a,(*(struct configitem **)b)->key,255);
}


decompiled_code:
__int64 __fastcall item_find(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
if ( v2 )
result = binarysearch_constprop_0(
*(_QWORD *)(a1 + 16),
a2,
v2 - 1,
(int (__fastcall *)(__int64, __int64))item_compare);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
if ( v2 )
result = func8(
*(_QWORD *)(a1 + 16),
a2,
v2 - 1,
(int (__fastcall *)(__int64, __int64))item_compare);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int item_find(struct configsection *haystack, const char *needle)
{
 if(haystack->itemcount)
 {
  return binarysearch(haystack->items, needle, sizeof(struct configitem*), haystack->itemcount-1, item_compare);
 }
 return -1;
}

canonical_original_code:
static int item_find(struct configsection *haystack, char *needle)
{
 if(haystack->itemcount)
 {
  return binarysearch(haystack->items, needle, sizeof(struct configitem *), haystack->itemcount-1, item_compare);
 }
 return -1;
}

variable_types:
needle
char *


original_code:
void config_free(struct config *conf)
{
 for(unsigned int i=0; i<conf->sectioncount; ++i)
 {
  section_free(conf->sections[i]);
  free(conf->sections[i]);
 }
 free(conf->sections);
}

canonical_original_code:
void config_free(struct config *conf)
{
 for(unsigned int i = 0; i<conf->sectioncount; ++i)
 {
  section_free(conf->sections[i]);
  free(conf->sections[i]);
 }
 free(conf->sections);
}

variable_types: struct config { unsigned int sectioncount; unsigned int size; struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem { char *key; char *val; } **items; } **sections; } *

user_defined_types: struct config { unsigned int sectioncount; unsigned int size; struct configsection **sections; }


decompiled_code:
void __fastcall config_init(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func11(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

original_code:
void config_init(struct config *conf)
{
 conf->sectioncount = 0;
 conf->size = 0;
 conf->sections=((void *)0);
}


decompiled_code:
__int64 __fastcall config_find_section(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

if ( !*(_DWORD *)a1 )
return 0LL;
v2 = binarysearch_constprop_0(
*(_QWORD *)(a1 + 8),
a2,
*(_DWORD *)a1 - 1,
(int (__fastcall *)(__int64, __int64))section_compare);
if ( v2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

if ( !*(_DWORD *)a1 )
return 0LL;
v2 = func8(
*(_QWORD *)(a1 + 8),
a2,
*(_DWORD *)a1 - 1,
(int (__fastcall *)(__int64, __int64))section_compare);
if ( v2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v2);
return result;
}

original_code:
struct configsection *config_find_section(struct config *haystack, const char *needle)
{
 if(haystack->sectioncount)
 {
  int i = binarysearch(haystack->sections, needle, sizeof(struct configsection*), haystack->sectioncount-1, section_compare);
  if(i>=0) return haystack->sections[i];
 }
 return ((void *)0);
}

canonical_original_code:
struct configsection *config_find_section(struct config *haystack, char *needle)
{
 if(haystack->sectioncount)
 {
  int i = binarysearch(haystack->sections, needle, sizeof(struct configsection*), haystack->sectioncount-1, section_compare);
  if(i>=0) return haystack->sections[i];
 }
 return ((void *)0);
}

variable_types: struct config { unsigned int sectioncount; unsigned int size; struct configsection **sections; } *

variable_types: i int

return_type: struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem { char *key; char *val; } **items; } *


decompiled_code:
__int64 __fastcall config_find_item(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax
__int64 v4; // rbx
int v5; // eax
unsigned int v7; // ebx
int v8; // eax

if ( a3 )
{
v3 = config_find_section(a1, a3);
v4 = v3;
if ( v3 )
{
v5 = item_find(v3, a2);
if ( v5 != -1 )
return *(_QWORD *)(*(_QWORD *)(v4 + 16) + 8LL * v5);
}
return 0LL;
}
v7 = 0;
if ( !*(_DWORD *)a1 )
return 0LL;
while ( 1 )
{
v8 = item_find(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v7), a2);
if ( v8 != -1 )
break;
if ( *(_DWORD *)a1 <= ++v7 )
return 0LL;
}
return *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v7) + 16LL) + 8LL * v8);
}

original_code:
struct configitem *config_find_item(struct config *haystack, const char *needle, const char *section)
{
 if(section)
 {
  struct configsection *sect;
  if((sect=config_find_section(haystack, section)))
  {
   int item=item_find(sect, needle);
   if(item != -1) return sect->items[item];
  }
 }
 else
 {
  for(unsigned int i=0; i<haystack->sectioncount; ++i)
  {
   int item=item_find(haystack->sections[i], needle);
   if(item != -1) return haystack->sections[i]->items[item];
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct configitem *config_find_item(struct config *haystack, char *needle, char *section)
{
 if(section)
 {
  struct configsection *sect;
  if((sect=config_find_section(haystack, section)))
  {
   int item = item_find(sect, needle);
   if(item != -1) return sect->items[item];
  }
 }
 else
 {
  for(unsigned int i = 0; i<haystack->sectioncount; ++i)
  {
   int item = item_find(haystack->sections[i], needle);
   if(item != -1) return haystack->sections[i]->items[item];
  }
 }
 return ((void *)0);
}

variable_types: struct config { unsigned int sectioncount; unsigned int size; struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem **items; } **sections; } *

variable_types:
section
char *

variable_types: item int

return_type: struct configitem { char *key; char *val; } *


decompiled_code:
__int64 random_char()
{
return (unsigned int)(rand() % 58 + 64);
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)(rand() % 58 + 64);
}

original_code:
char random_char()
{
 int c = rand() % 58;
 if(c<64) c+=64;
 return (char)c;
}

variable_types: c int

return_type: char


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
__int64 v4; // r14
int v5; // ebx
const char **v6; // rax
__int64 v7; // rbx
void *v8; // rax
__int64 v9; // rdx
unsigned __int64 v10; // rsi
__int64 v11; // r12
__int64 v12; // r15
int v13; // ebx
_BYTE *v14; // r12
int v15; // ebx
size_t v16; // r14
size_t v17; // rdi
char *v18; // rax
__int64 v19; // rdx
char *v20; // r15
size_t v21; // r15
int v22; // er12
char *v23; // r14
__int64 v24; // rbx
char *v25; // rax
char *v26; // r14
__int64 i; // rbx
unsigned int j; // ebx
int v29; // er12
__int64 v30; // rdx
void *k; // rsp
char v32; // al
__int64 v33; // rdx
int v34; // eax
const char **v35; // r12
__int64 v36; // rbx
char *v37; // rbx
const char *v38; // rdi
int v39; // er15
int v40; // ebx
int v41; // eax
int v42; // ecx
__int64 v43; // rdx
unsigned __int64 v44; // rsi
int v45; // eax
int v46; // ebx
void *v47; // rsp
void *v48; // rsp
int v49; // er14
const char **v50; // rax
__int64 v51; // rcx
const char **v52; // r14
void *v53; // r15
const char *v54; // r12
__int64 v55; // rbx
const char *v56; // r14
size_t v57; // rax
__int64 v58; // r14
__int64 v59; // rbx
void *v60; // rdi
size_t v61; // rax
__int64 v62; // r12
size_t v63; // rax
__int64 v64; // r12
int v65; // eax
void *v66; // r15
void **v67; // rbx
__int64 v68; // r14
void *v69; // rdi
void *v70; // rdi
int v72; // ebx
char *v73; // r14
char *v74; // r15
char *v75; // r14
char *v76; // rbx
char v77[8]; // [rsp+0h] [rbp-50F0h] BYREF
__int64 v78; // [rsp+8h] [rbp-50E8h]
unsigned int v79; // [rsp+10h] [rbp-50E0h]
int v80; // [rsp+14h] [rbp-50DCh]
int *v81; // [rsp+18h] [rbp-50D8h]
char *v82; // [rsp+20h] [rbp-50D0h]
__int64 v83; // [rsp+28h] [rbp-50C8h]
__int64 v84; // [rsp+30h] [rbp-50C0h]
int v85; // [rsp+38h] [rbp-50B8h]
unsigned int seed; // [rsp+3Ch] [rbp-50B4h]
__int64 v87; // [rsp+40h] [rbp-50B0h]
void *s1; // [rsp+48h] [rbp-50A8h]
int *v89; // [rsp+50h] [rbp-50A0h]
unsigned __int64 v90; // [rsp+58h] [rbp-5098h]
int *v91; // [rsp+60h] [rbp-5090h]
char *s2; // [rsp+68h] [rbp-5088h]
char *v93; // [rsp+70h] [rbp-5080h]
char *v94; // [rsp+78h] [rbp-5078h]
char *v95; // [rsp+80h] [rbp-5070h]
__int64 v96; // [rsp+88h] [rbp-5068h]
const char **v97; // [rsp+90h] [rbp-5060h]
__int64 v98; // [rsp+98h] [rbp-5058h]
int v99[2]; // [rsp+A0h] [rbp-5050h] BYREF
const char **v100; // [rsp+A8h] [rbp-5048h]
int v101; // [rsp+B0h] [rbp-5040h] BYREF
unsigned int v102; // [rsp+B4h] [rbp-503Ch]
__int64 v103; // [rsp+B8h] [rbp-5038h]
char v104; // [rsp+C0h] [rbp-5030h] BYREF
char v105; // [rsp+10C0h] [rbp-4030h] BYREF
char v106; // [rsp+30C0h] [rbp-2030h] BYREF

v91 = v99;
v94 = &v105;
v93 = &v106;
seed = 6;
v95 = &v104;
do
{
v3 = 0LL;
config_init(v91, argv, envp);
srand(seed);
printf("Generating %d sections...\n", 1024LL);
memset(v94, 0, 0x2000uLL);
memset(v93, 0, 0x2000uLL);
do
{
LODWORD(v98) = (_DWORD)v3;
v4 = 0LL;
v5 = rand() % 16;
v97 = (const char **)malloc(v5 + 2);
if ( v5 >= 0 )
{
do
*((_BYTE *)v97 + v4++) = ((__int64 (*)(void))random_char)();
while ( v5 >= (int)v4 );
}
v6 = v97;
*(_QWORD *)&v94[8 * (_QWORD)v3] = v97;
*((_BYTE *)v6 + v5 + 1) = 0;
v7 = (unsigned int)(rand() % 32);
v8 = calloc(8LL * ((int)v7 + 1), 1uLL);
v9 = (unsigned int)v98;
v10 = (unsigned int)(v7 + 1);
v11 = (__int64)v8;
*(_QWORD *)&v93[8 * (_QWORD)v3] = v8;
printf("Adding %d keys to section %d\n", v10, v9);
*(_DWORD *)&v95[4 * (_QWORD)v3] = v7 + 1;
if ( (int)v7 + 1 > 0 )
{
v98 = v11;
v96 = v11 + 8 * v7 + 8;
s2 = v3;
do
{
v12 = 0LL;
v13 = rand() % 16;
v14 = malloc(v13 + 2);
*(_QWORD *)v98 = v14;
if ( v13 >= 0 )
{
do
v14[v12++] = ((__int64 (*)(void))random_char)();
while ( v13 >= (int)v12 );
}
v14[v13 + 1] = 0;
v15 = rand() % 16;
v16 = v15 + 2;
v17 = v16;
v18 = (char *)malloc(v16);
v19 = 0LL;
v20 = v18;
if ( v15 >= 0 )
{
v90 = (unsigned __int64)v14;
v21 = v15 + 2;
v22 = v15;
v23 = v18;
v24 = 0LL;
do
v23[v24++] = random_char(v17, v10, v19);
while ( v22 >= (int)v24 );
v25 = v23;
v14 = (_BYTE *)v90;
v16 = v21;
v20 = v25;
}
v20[v16 - 1] = 0;
v10 = (unsigned __int64)v97;
config_add(v91, v97, v14, v20);
free(v20);
v98 += 8LL;
}
while ( v98 != v96 );
v3 = s2;
}
++v3;
}
while ( v3 != "from nonexistent section, round %d, item %d\n" );
v26 = v94;
for ( i = 0LL; i != 1024; ++i )
{
printf("Searching section %d\n", (unsigned int)i);
if ( !config_find_section(v91, *(_QWORD *)&v26[8 * i]) )
_assert_fail("config_find_section(&c, sections[i]) != NULL", "test/configtest.c", 0x4Eu, "main");
}
for ( j = 0; j != 1024; ++j )
{
LABEL_20:
printf("Searching nonexistent section, round %d\n", j);
v29 = rand() % 16;
v30 = 0LL;
for ( k = alloca(v29 + 2); v29 >= (int)v30; v30 = v33 + 1 )
{
v98 = v30;
v32 = random_char("Searching nonexistent section, round %d\n", j, v30);
v33 = v98;
v77[v98] = v32;
}
v34 = v29 + 1;
v35 = (const char **)v94;
v77[v34] = 0;
do
{
if ( !strcmp(*v35, v77) )
goto LABEL_20;
++v35;
}
while ( v35 != (const char **)v93 );
if ( config_find_section(v91, v77) )
_assert_fail("config_find_section(&c, sect) == NULL", "test/configtest.c", 0x61u, "main");
}
s1 = 0LL;
do
{
LODWORD(v90) = (_DWORD)s1;
if ( *(int *)&v95[4 * (_QWORD)s1] > 0 )
{
v81 = (int *)*(int *)&v95[4 * (_QWORD)s1];
v89 = 0LL;
do
{
v36 = (__int64)v89;
LODWORD(v87) = (_DWORD)v89;
printf("Searching existing item from ALL sections, round %d, item %d\n", (unsigned int)v90, (unsigned int)v89);
v84 = *(_QWORD *)(*(_QWORD *)&v93[8 * (_QWORD)s1] + 8 * v36);
if ( !config_find_item(v91, v84, 0LL) )
_assert_fail("config_find_item(&c, keys[i][j], NULL)", "test/configtest.c", 0x6Au, "main");
printf(
"Searching existing item from correct section, round %d, item %d\n",
(unsigned int)v90,
(unsigned int)v89);
v83 = *(_QWORD *)&v94[8 * (_QWORD)s1];
if ( !config_find_item(v91, v84, v83) )
_assert_fail("config_find_item(&c, keys[i][j], sections[i])", "test/configtest.c", 0x6Cu, "main");
printf(
"Searching existing item from wrong section, round %d, item %d\n",
(unsigned int)v90,
(unsigned int)v89);
v37 = v94;
while ( 1 )
{
v38 = (const char *)v91;
if ( !config_find_item(v91, v84, *(_QWORD *)v37) )
break;
v37 += 8;
if ( v37 == v93 )
_assert_fail("nonexistent", "test/configtest.c", 0x74u, "main");
}
v39 = 1;
v40 = rand() % 16;
v80 = v40;
v41 = rand();
v82 = v77;
v42 = v40;
v43 = (unsigned int)(v41 >> 31) >> 28;
v44 = (unsigned int)(v41 % 16);
v85 = v41 % 16;
v45 = v40 + 6;
v46 = 1;
v47 = alloca(v45);
v48 = alloca((int)v44 + 6);
v79 = v42 + 5;
s2 = v77;
v78 = v42 + 5;
do
{
if ( v46 )
{
v43 = v79;
if ( (int)v79 > 0 )
{
v75 = v77;
v76 = &v77[v80 + 4 + 1];
do
*v75++ = random_char(v38, v44, v43);
while ( v76 != v75 );
}
v77[v78] = 0;
}
if ( v39 )
{
v72 = v85 + 5;
if ( v85 + 5 > 0 )
{
v73 = s2;
v74 = &s2[v85 + 4 + 1];
do
*v73++ = random_char(v38, v44, v43);
while ( v74 != v73 );
}
s2[v72] = 0;
}
v96 = 0LL;
v39 = 0;
v46 = 0;
do
{
v49 = *(_DWORD *)&v95[4 * v96];
if ( v49 > 0 )
{
LODWORD(v98) = strcmp(*(const char **)&v94[8 * v96], s2);
v50 = *(const char ***)&v93[8 * v96];
v51 = (unsigned int)(v49 - 1);
v52 = v50 + 1;
v97 = &v50[v51 + 1];
while ( 1 )
{
v38 = *v50;
v44 = (unsigned __int64)v77;
if ( !strcmp(*v50, v77) )
v46 = 1;
v50 = v52;
if ( !(_DWORD)v98 )
v39 = 1;
if ( v97 == v52 )
break;
++v52;
}
}
++v96;
}
while ( v96 != 1024 );
}
while ( v46 | v39 );
printf(
"Searching nonexistent item from ALL sections, round %d, item %d\n",
(unsigned int)v90,
(unsigned int)v87);
if ( config_find_item(v91, v77, 0LL) )
_assert_fail("config_find_item(&c, key, NULL) == NULL", "test/configtest.c", 0x9Au, "main");
printf(
"Searching nonexistent item from existing section, round %d, item %d\n",
(unsigned int)v90,
(unsigned int)v87);
if ( config_find_item(v91, v77, v83) )
_assert_fail("config_find_item(&c, key, sections[i]) == NULL", "test/configtest.c", 0x9Cu, "main");
printf(
"Searching nonexistent item from nonexistent section, round %d, item %d\n",
(unsigned int)v90,
(unsigned int)v87);
if ( config_find_item(v91, v77, s2) )
_assert_fail("config_find_item(&c, key, sec) == NULL", "test/configtest.c", 0x9Eu, "main");
printf(
"Searching existing item from nonexistent section, round %d, item %d\n",
(unsigned int)v90,
(unsigned int)v87);
if ( config_find_item(v91, v84, s2) )
_assert_fail("config_find_item(&c, keys[i][j], sec) == NULL", "test/configtest.c", 0xA0u, "main");
v89 = (int *)((char *)v89 + 1);
}
while ( v89 != v81 );
}
s1 = (char *)s1 + 1;
}
while ( s1 != "from nonexistent section, round %d, item %d\n" );
puts("Testing loading & saving...");
config_save(v91, "configtest.conf");
v89 = &v101;
config_load(&v101, "configtest.conf");
if ( v99[0] != v101 )
_assert_fail("c.sectioncount == loadedconf.sectioncount", "test/configtest.c", 0xA8u, "main");
argv = (const char **)v102;
if ( v99[1] != v102 )
_assert_fail("c.size == loadedconf.size", "test/configtest.c", 0xA9u, "main");
if ( v99[0] )
{
v90 = (unsigned int)v99[0];
v53 = 0LL;
v97 = v100;
v96 = v103;
do
{
v54 = v97[(_QWORD)v53];
v55 = *(_QWORD *)(v96 + 8LL * (_QWORD)v53);
if ( *((_DWORD *)v54 + 2) != *(_DWORD *)(v55 + 8) )
_assert_fail(
"c.sections[ii]->itemcount == loadedconf.sections[ii]->itemcount",
"test/configtest.c",
0xACu,
"main");
if ( *((_DWORD *)v54 + 3) != *(_DWORD *)(v55 + 12) )
_assert_fail("c.sections[ii]->size == loadedconf.sections[ii]->size", "test/configtest.c", 0xADu, "main");
v56 = *(const char **)v54;
LODWORD(v98) = *((_DWORD *)v54 + 2);
v57 = strlen(v56);
argv = *(const char ***)v55;
if ( memcmp(v56, *(const void **)v55, v57) )
_assert_fail(
"memcmp(c.sections[ii]->name, loadedconf.sections[ii]->name, strlen(c.sections[ii]->name)) == 0",
"test/configtest.c",
0xAEu,
"main");
if ( (_DWORD)v98 )
{
v58 = *(_QWORD *)(v55 + 16);
v59 = 0LL;
s2 = (char *)*((_QWORD *)v54 + 2);
v98 = (unsigned int)v98;
do
{
v60 = **(void ***)&s2[8 * v59];
v87 = *(_QWORD *)&s2[8 * v59];
s1 = v60;
v61 = strlen((const char *)v60);
v62 = *(_QWORD *)(v58 + 8 * v59);
if ( memcmp(s1, *(const void **)v62, v61) )
_assert_fail(
"memcmp(c.sections[ii]->items[jj]->key, loadedconf.sections[ii]->items[jj]->key, strlen(c.sections[ii]->i"
"tems[jj]->key)) == 0",
"test/configtest.c",
0xB1u,
"main");
s1 = *(void **)(v87 + 8);
v63 = strlen((const char *)s1);
argv = *(const char ***)(v62 + 8);
if ( memcmp(s1, argv, v63) )
_assert_fail(
"memcmp(c.sections[ii]->items[jj]->val, loadedconf.sections[ii]->items[jj]->val, strlen(c.sections[ii]->i"
"tems[jj]->val)) == 0",
"test/configtest.c",
0xB2u,
"main");
++v59;
}
while ( v98 != v59 );
}
v53 = (char *)v53 + 1;
}
while ( v53 != (void *)v90 );
}
v64 = 0LL;
config_free(v89);
do
{
v65 = *(_DWORD *)&v95[4 * v64];
v66 = *(void **)&v93[8 * v64];
if ( v65 > 0 )
{
v67 = *(void ***)&v93[8 * v64];
v68 = (__int64)v66 + 8 * (unsigned int)(v65 - 1) + 8;
do
{
v69 = *v67++;
free(v69);
}
while ( (void **)v68 != v67 );
}
free(v66);
v70 = *(void **)&v94[8 * v64++];
free(v70);
}
while ( v64 != 1024 );
config_free(v91);
++seed;
}
while ( seed != 10 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
__int64 v4; // r14
int v5; // ebx
const char **v6; // rax
__int64 v7; // rbx
void *v8; // rax
__int64 v9; // rdx
unsigned __int64 v10; // rsi
__int64 v11; // r12
__int64 v12; // r15
int v13; // ebx
_BYTE *v14; // r12
int v15; // ebx
size_t v16; // r14
size_t v17; // rdi
char *v18; // rax
__int64 v19; // rdx
char *v20; // r15
size_t v21; // r15
int v22; // er12
char *v23; // r14
__int64 v24; // rbx
char *v25; // rax
char *v26; // r14
__int64 i; // rbx
unsigned int j; // ebx
int v29; // er12
__int64 v30; // rdx
void *k; // rsp
char v32; // al
__int64 v33; // rdx
int v34; // eax
const char **v35; // r12
__int64 v36; // rbx
char *v37; // rbx
const char *v38; // rdi
int v39; // er15
int v40; // ebx
int v41; // eax
int v42; // ecx
__int64 v43; // rdx
unsigned __int64 v44; // rsi
int v45; // eax
int v46; // ebx
void *v47; // rsp
void *v48; // rsp
int v49; // er14
const char **v50; // rax
__int64 v51; // rcx
const char **v52; // r14
void *v53; // r15
const char *v54; // r12
__int64 v55; // rbx
const char *v56; // r14
size_t v57; // rax
__int64 v58; // r14
__int64 v59; // rbx
void *v60; // rdi
size_t v61; // rax
__int64 v62; // r12
size_t v63; // rax
__int64 v64; // r12
int v65; // eax
void *v66; // r15
void **v67; // rbx
__int64 v68; // r14
void *v69; // rdi
void *v70; // rdi
int v72; // ebx
char *v73; // r14
char *v74; // r15
char *v75; // r14
char *v76; // rbx
char v77[8]; // [rsp+0h] [rbp-50F0h] BYREF
__int64 v78; // [rsp+8h] [rbp-50E8h]
unsigned int v79; // [rsp+10h] [rbp-50E0h]
int v80; // [rsp+14h] [rbp-50DCh]
int *v81; // [rsp+18h] [rbp-50D8h]
char *v82; // [rsp+20h] [rbp-50D0h]
__int64 v83; // [rsp+28h] [rbp-50C8h]
__int64 v84; // [rsp+30h] [rbp-50C0h]
int v85; // [rsp+38h] [rbp-50B8h]
unsigned int seed; // [rsp+3Ch] [rbp-50B4h]
__int64 v87; // [rsp+40h] [rbp-50B0h]
void *s1; // [rsp+48h] [rbp-50A8h]
int *v89; // [rsp+50h] [rbp-50A0h]
unsigned __int64 v90; // [rsp+58h] [rbp-5098h]
int *v91; // [rsp+60h] [rbp-5090h]
char *s2; // [rsp+68h] [rbp-5088h]
char *v93; // [rsp+70h] [rbp-5080h]
char *v94; // [rsp+78h] [rbp-5078h]
char *v95; // [rsp+80h] [rbp-5070h]
__int64 v96; // [rsp+88h] [rbp-5068h]
const char **v97; // [rsp+90h] [rbp-5060h]
__int64 v98; // [rsp+98h] [rbp-5058h]
int v99[2]; // [rsp+A0h] [rbp-5050h] BYREF
const char **v100; // [rsp+A8h] [rbp-5048h]
int v101; // [rsp+B0h] [rbp-5040h] BYREF
unsigned int v102; // [rsp+B4h] [rbp-503Ch]
__int64 v103; // [rsp+B8h] [rbp-5038h]
char v104; // [rsp+C0h] [rbp-5030h] BYREF
char v105; // [rsp+10C0h] [rbp-4030h] BYREF
char v106; // [rsp+30C0h] [rbp-2030h] BYREF

v91 = v99;
v94 = &v105;
v93 = &v106;
seed = 6;
v95 = &v104;
do
{
v3 = 0LL;
config_init(v91, argv, envp);
srand(seed);
printf("Generating %d sections...\n", 1024LL);
memset(v94, 0, 0x2000uLL);
memset(v93, 0, 0x2000uLL);
do
{
LODWORD(v98) = (_DWORD)v3;
v4 = 0LL;
v5 = rand() % 16;
v97 = (const char **)malloc(v5 + 2);
if ( v5 >= 0 )
{
do
*((_BYTE *)v97 + v4++) = ((__int64 (*)(void))random_char)();
while ( v5 >= (int)v4 );
}
v6 = v97;
*(_QWORD *)&v94[8 * (_QWORD)v3] = v97;
*((_BYTE *)v6 + v5 + 1) = 0;
v7 = (unsigned int)(rand() % 32);
v8 = calloc(8LL * ((int)v7 + 1), 1uLL);
v9 = (unsigned int)v98;
v10 = (unsigned int)(v7 + 1);
v11 = (__int64)v8;
*(_QWORD *)&v93[8 * (_QWORD)v3] = v8;
printf("Adding %d keys to section %d\n", v10, v9);
*(_DWORD *)&v95[4 * (_QWORD)v3] = v7 + 1;
if ( (int)v7 + 1 > 0 )
{
v98 = v11;
v96 = v11 + 8 * v7 + 8;
s2 = v3;
do
{
v12 = 0LL;
v13 = rand() % 16;
v14 = malloc(v13 + 2);
*(_QWORD *)v98 = v14;
if ( v13 >= 0 )
{
do
v14[v12++] = ((__int64 (*)(void))random_char)();
while ( v13 >= (int)v12 );
}
v14[v13 + 1] = 0;
v15 = rand() % 16;
v16 = v15 + 2;
v17 = v16;
v18 = (char *)malloc(v16);
v19 = 0LL;
v20 = v18;
if ( v15 >= 0 )
{
v90 = (unsigned __int64)v14;
v21 = v15 + 2;
v22 = v15;
v23 = v18;
v24 = 0LL;
do
v23[v24++] = func0(v17, v10, v19);
while ( v22 >= (int)v24 );
v25 = v23;
v14 = (_BYTE *)v90;
v16 = v21;
v20 = v25;
}
v20[v16 - 1] = 0;
v10 = (unsigned __int64)v97;
config_add(v91, v97, v14, v20);
free(v20);
v98 += 8LL;
}
while ( v98 != v96 );
v3 = s2;
}
++v3;
}
while ( v3 != "from nonexistent section, round %d, item %d\n" );
v26 = v94;
for ( i = 0LL; i != 1024; ++i )
{
printf("Searching section %d\n", (unsigned int)i);
if ( !config_find_section(v91, *(_QWORD *)&v26[8 * i]) )
_assert_fail("config_find_section(&c, sections[i]) != NULL", "test/configtest.c", 0x4Eu, "main");
}
for ( j = 0; j != 1024; ++j )
{
LABEL_20:
printf("Searching nonexistent section, round %d\n", j);
v29 = rand() % 16;
v30 = 0LL;
for ( k = alloca(v29 + 2); v29 >= (int)v30; v30 = v33 + 1 )
{
v98 = v30;
v32 = func0("Searching nonexistent section, round %d\n", j, v30);
v33 = v98;
v77[v98] = v32;
}
v34 = v29 + 1;
v35 = (const char **)v94;
v77[v34] = 0;
do
{
if ( !strcmp(*v35, v77) )
goto LABEL_20;
++v35;
}
while ( v35 != (const char **)v93 );
if ( config_find_section(v91, v77) )
_assert_fail("config_find_section(&c, sect) == NULL", "test/configtest.c", 0x61u, "main");
}
s1 = 0LL;
do
{
LODWORD(v90) = (_DWORD)s1;
if ( *(int *)&v95[4 * (_QWORD)s1] > 0 )
{
v81 = (int *)*(int *)&v95[4 * (_QWORD)s1];
v89 = 0LL;
do
{
v36 = (__int64)v89;
LODWORD(v87) = (_DWORD)v89;
printf("Searching existing item from ALL sections, round %d, item %d\n", (unsigned int)v90, (unsigned int)v89);
v84 = *(_QWORD *)(*(_QWORD *)&v93[8 * (_QWORD)s1] + 8 * v36);
if ( !config_find_item(v91, v84, 0LL) )
_assert_fail("config_find_item(&c, keys[i][j], NULL)", "test/configtest.c", 0x6Au, "main");
printf(
"Searching existing item from correct section, round %d, item %d\n",
(unsigned int)v90,
(unsigned int)v89);
v83 = *(_QWORD *)&v94[8 * (_QWORD)s1];
if ( !config_find_item(v91, v84, v83) )
_assert_fail("config_find_item(&c, keys[i][j], sections[i])", "test/configtest.c", 0x6Cu, "main");
printf(
"Searching existing item from wrong section, round %d, item %d\n",
(unsigned int)v90,
(unsigned int)v89);
v37 = v94;
while ( 1 )
{
v38 = (const char *)v91;
if ( !config_find_item(v91, v84, *(_QWORD *)v37) )
break;
v37 += 8;
if ( v37 == v93 )
_assert_fail("nonexistent", "test/configtest.c", 0x74u, "main");
}
v39 = 1;
v40 = rand() % 16;
v80 = v40;
v41 = rand();
v82 = v77;
v42 = v40;
v43 = (unsigned int)(v41 >> 31) >> 28;
v44 = (unsigned int)(v41 % 16);
v85 = v41 % 16;
v45 = v40 + 6;
v46 = 1;
v47 = alloca(v45);
v48 = alloca((int)v44 + 6);
v79 = v42 + 5;
s2 = v77;
v78 = v42 + 5;
do
{
if ( v46 )
{
v43 = v79;
if ( (int)v79 > 0 )
{
v75 = v77;
v76 = &v77[v80 + 4 + 1];
do
*v75++ = func0(v38, v44, v43);
while ( v76 != v75 );
}
v77[v78] = 0;
}
if ( v39 )
{
v72 = v85 + 5;
if ( v85 + 5 > 0 )
{
v73 = s2;
v74 = &s2[v85 + 4 + 1];
do
*v73++ = func0(v38, v44, v43);
while ( v74 != v73 );
}
s2[v72] = 0;
}
v96 = 0LL;
v39 = 0;
v46 = 0;
do
{
v49 = *(_DWORD *)&v95[4 * v96];
if ( v49 > 0 )
{
LODWORD(v98) = strcmp(*(const char **)&v94[8 * v96], s2);
v50 = *(const char ***)&v93[8 * v96];
v51 = (unsigned int)(v49 - 1);
v52 = v50 + 1;
v97 = &v50[v51 + 1];
while ( 1 )
{
v38 = *v50;
v44 = (unsigned __int64)v77;
if ( !strcmp(*v50, v77) )
v46 = 1;
v50 = v52;
if ( !(_DWORD)v98 )
v39 = 1;
if ( v97 == v52 )
break;
++v52;
}
}
++v96;
}
while ( v96 != 1024 );
}
while ( v46 | v39 );
printf(
"Searching nonexistent item from ALL sections, round %d, item %d\n",
(unsigned int)v90,
(unsigned int)v87);
if ( config_find_item(v91, v77, 0LL) )
_assert_fail("config_find_item(&c, key, NULL) == NULL", "test/configtest.c", 0x9Au, "main");
printf(
"Searching nonexistent item from existing section, round %d, item %d\n",
(unsigned int)v90,
(unsigned int)v87);
if ( config_find_item(v91, v77, v83) )
_assert_fail("config_find_item(&c, key, sections[i]) == NULL", "test/configtest.c", 0x9Cu, "main");
printf(
"Searching nonexistent item from nonexistent section, round %d, item %d\n",
(unsigned int)v90,
(unsigned int)v87);
if ( config_find_item(v91, v77, s2) )
_assert_fail("config_find_item(&c, key, sec) == NULL", "test/configtest.c", 0x9Eu, "main");
printf(
"Searching existing item from nonexistent section, round %d, item %d\n",
(unsigned int)v90,
(unsigned int)v87);
if ( config_find_item(v91, v84, s2) )
_assert_fail("config_find_item(&c, keys[i][j], sec) == NULL", "test/configtest.c", 0xA0u, "main");
v89 = (int *)((char *)v89 + 1);
}
while ( v89 != v81 );
}
s1 = (char *)s1 + 1;
}
while ( s1 != "from nonexistent section, round %d, item %d\n" );
puts("Testing loading & saving...");
config_save(v91, "configtest.conf");
v89 = &v101;
config_load(&v101, "configtest.conf");
if ( v99[0] != v101 )
_assert_fail("c.sectioncount == loadedconf.sectioncount", "test/configtest.c", 0xA8u, "main");
argv = (const char **)v102;
if ( v99[1] != v102 )
_assert_fail("c.size == loadedconf.size", "test/configtest.c", 0xA9u, "main");
if ( v99[0] )
{
v90 = (unsigned int)v99[0];
v53 = 0LL;
v97 = v100;
v96 = v103;
do
{
v54 = v97[(_QWORD)v53];
v55 = *(_QWORD *)(v96 + 8LL * (_QWORD)v53);
if ( *((_DWORD *)v54 + 2) != *(_DWORD *)(v55 + 8) )
_assert_fail(
"c.sections[ii]->itemcount == loadedconf.sections[ii]->itemcount",
"test/configtest.c",
0xACu,
"main");
if ( *((_DWORD *)v54 + 3) != *(_DWORD *)(v55 + 12) )
_assert_fail("c.sections[ii]->size == loadedconf.sections[ii]->size", "test/configtest.c", 0xADu, "main");
v56 = *(const char **)v54;
LODWORD(v98) = *((_DWORD *)v54 + 2);
v57 = strlen(v56);
argv = *(const char ***)v55;
if ( memcmp(v56, *(const void **)v55, v57) )
_assert_fail(
"memcmp(c.sections[ii]->name, loadedconf.sections[ii]->name, strlen(c.sections[ii]->name)) == 0",
"test/configtest.c",
0xAEu,
"main");
if ( (_DWORD)v98 )
{
v58 = *(_QWORD *)(v55 + 16);
v59 = 0LL;
s2 = (char *)*((_QWORD *)v54 + 2);
v98 = (unsigned int)v98;
do
{
v60 = **(void ***)&s2[8 * v59];
v87 = *(_QWORD *)&s2[8 * v59];
s1 = v60;
v61 = strlen((const char *)v60);
v62 = *(_QWORD *)(v58 + 8 * v59);
if ( memcmp(s1, *(const void **)v62, v61) )
_assert_fail(
"memcmp(c.sections[ii]->items[jj]->key, loadedconf.sections[ii]->items[jj]->key, strlen(c.sections[ii]->i"
"tems[jj]->key)) == 0",
"test/configtest.c",
0xB1u,
"main");
s1 = *(void **)(v87 + 8);
v63 = strlen((const char *)s1);
argv = *(const char ***)(v62 + 8);
if ( memcmp(s1, argv, v63) )
_assert_fail(
"memcmp(c.sections[ii]->items[jj]->val, loadedconf.sections[ii]->items[jj]->val, strlen(c.sections[ii]->i"
"tems[jj]->val)) == 0",
"test/configtest.c",
0xB2u,
"main");
++v59;
}
while ( v98 != v59 );
}
v53 = (char *)v53 + 1;
}
while ( v53 != (void *)v90 );
}
v64 = 0LL;
config_free(v89);
do
{
v65 = *(_DWORD *)&v95[4 * v64];
v66 = *(void **)&v93[8 * v64];
if ( v65 > 0 )
{
v67 = *(void ***)&v93[8 * v64];
v68 = (__int64)v66 + 8 * (unsigned int)(v65 - 1) + 8;
do
{
v69 = *v67++;
free(v69);
}
while ( (void **)v68 != v67 );
}
free(v66);
v70 = *(void **)&v94[8 * v64++];
free(v70);
}
while ( v64 != 1024 );
config_free(v91);
++seed;
}
while ( seed != 10 );
return 0;
}

original_code:
int main()
{
 struct config conf;
 if(config_load(&conf, "../example.conf"))
 {
  error("Failed to load example.conf\n");
 }
 for(unsigned i=0; i<conf.sectioncount; ++i)
 {
  printf("[%s]\n", conf.sections[i]->name);
  for(unsigned j=0; j<conf.sections[i]->itemcount; ++j)
  {
   char* key=conf.sections[i]->items[j]->key;
   char* val=conf.sections[i]->items[j]->val;
   printf("\t%s=%s\n", key, val?val:"NO VALUE");
  }
 }
 struct configsection* sect=config_find_section(&conf, "Second section");
 if(!sect) error("Second section not found\n");
 else
 {
  printf("Keys from %s:\n", sect->name);
  for(unsigned i=0; i<sect->itemcount; ++i)
  {
   printf("\t%s\n", sect->items[i]->key);
  }
 }
 struct configitem* item=config_find_item(&conf, "Key2", ((void *)0));
 printf("Item:\n\t%s=%s\n", item->key, item->val);
 srand(time(((void *)0)));
 int rnd=rand();
 char rndstr[12];
 snprintf(rndstr, 12, "%d", rnd);
 config_add(&conf, "First section", "Random value from example", rndstr);
 config_save(&conf, "../example.conf");
}

canonical_original_code:
int main()
{
 struct config conf;
 if(config_load(&conf, "../example.conf"))
 {
  error("Failed to load example.conf\n");
 }
 for(unsigned int i = 0; i<conf.sectioncount; ++i)
 {
  printf("[%s]\n", conf.sections[i]->name);
  for(unsigned int j = 0; j<conf.sections[i]->itemcount; ++j)
  {
   char *key = conf.sections[i]->items[j]->key;
   char *val = conf.sections[i]->items[j]->val;
   printf("\t%s=%s\n", key, val?val:"NO VALUE");
  }
 }
 struct configsection *sect = config_find_section(&conf, "Second section");
 if(!sect) error("Second section not found\n");
 else
 {
  printf("Keys from %s:\n", sect->name);
  for(unsigned int i = 0; i<sect->itemcount; ++i)
  {
   printf("\t%s\n", sect->items[i]->key);
  }
 }
 struct configitem *item = config_find_item(&conf, "Key2", ((void *)0));
 printf("Item:\n\t%s=%s\n", item->key, item->val);
 srand(time(((void *)0)));
 int rnd = rand();
 char rndstr[12];
 snprintf(rndstr, 12, "%d", rnd);
 config_add(&conf, "First section", "Random value from example", rndstr);
 config_save(&conf, "../example.conf");
}

variable_types: struct config { unsigned int sectioncount; unsigned int size; struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem { char *key; char *val; } **items; } **sections; }

variable_types:
j
unsigned int

variable_types: rnd int

variable_types:
rndstr
char [12]


error

decompiled_code:
void __fastcall __noreturn error(char *format)
{
fprintf(stderr, format);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(char *format)
{
fprintf(stderr, format);
exit(1);
}

original_code:
void error(const char* msg)
{
 fprintf(stderr, msg);
 exit(1);
}

canonical_original_code:
void error(char *msg)
{
 fprintf(stderr, msg);
 exit(1);
}

variable_types:
msg
char *