executaOperacoes

decompiled_code:
void __fastcall __noreturn executaOperacoes(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
unsigned int v7; // er14
unsigned int v8; // ebx
unsigned int v9; // er13
int v10; // ebp
_BYTE v11[4012]; // [rsp-FB0h] [rbp-1F98h] BYREF
_BYTE v12[4008]; // [rsp+0h] [rbp-FE8h] BYREF
unsigned int v13; // [rsp+FA8h] [rbp-40h]

v7 = STACK[0x1F94];
v8 = STACK[0x1F98];
v9 = LODWORD(STACK[0x1F90]) - 1;
while ( 1 )
{
v10 = *((_DWORD *)&a7 + (int)++v9);
switch ( v10 )
{
case 1:
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
LOAD(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o LOAD \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_44:
if ( v10 != 4 )
goto LABEL_45;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
POP(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o POP \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_47:
if ( v10 != 7 )
goto LABEL_48;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JPGE(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JPGE \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_50:
if ( v10 != 10 )
goto LABEL_51;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JPE(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JPE \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_53:
if ( v10 != 13 )
goto LABEL_54;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
AND(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o AND \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_56:
if ( v10 != 16 )
goto LABEL_57;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
ADD(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o ADD \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_59:
if ( v10 != 19 )
goto LABEL_60;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
WRITE(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o WRITE \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_40:
if ( v10 == 22 )
{
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
HALT(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o HALT \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
}
break;
case 2:
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
STORE(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o STORE \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_45:
if ( v10 != 5 )
goto LABEL_46;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JMP(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JMP \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_48:
if ( v10 != 8 )
goto LABEL_49;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JPL(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JPL \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_51:
if ( v10 != 11 )
goto LABEL_52;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JPNE(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JPNE \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_54:
if ( v10 != 14 )
goto LABEL_55;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
OR(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o OR \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_57:
if ( v10 != 17 )
goto LABEL_58;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
SUB(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o SUB \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_60:
if ( v10 != 20 )
goto LABEL_61;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
CALL(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o CALL \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
break;
case 3:
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
PUSH(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o PUSH \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_46:
if ( v10 != 6 )
goto LABEL_47;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JPG(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JPG \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_49:
if ( v10 != 9 )
goto LABEL_50;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JPLE(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JPLE \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_52:
if ( v10 != 12 )
goto LABEL_53;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
XOR(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o XOR \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_55:
if ( v10 != 15 )
goto LABEL_56;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
NOT(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o NOT \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_58:
if ( v10 != 18 )
goto LABEL_59;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
READ(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o READ \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_61:
if ( v10 != 21 )
goto LABEL_40;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
RET(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o RET \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
break;
default:
goto LABEL_44;
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
unsigned int v7; // er14
unsigned int v8; // ebx
unsigned int v9; // er13
int v10; // ebp
_BYTE v11[4012]; // [rsp-FB0h] [rbp-1F98h] BYREF
_BYTE v12[4008]; // [rsp+0h] [rbp-FE8h] BYREF
unsigned int v13; // [rsp+FA8h] [rbp-40h]

v7 = STACK[0x1F94];
v8 = STACK[0x1F98];
v9 = LODWORD(STACK[0x1F90]) - 1;
while ( 1 )
{
v10 = *((_DWORD *)&a7 + (int)++v9);
switch ( v10 )
{
case 1:
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
LOAD(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o LOAD \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_44:
if ( v10 != 4 )
goto LABEL_45;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
POP(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o POP \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_47:
if ( v10 != 7 )
goto LABEL_48;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JPGE(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JPGE \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_50:
if ( v10 != 10 )
goto LABEL_51;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JPE(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JPE \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_53:
if ( v10 != 13 )
goto LABEL_54;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
AND(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o AND \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_56:
if ( v10 != 16 )
goto LABEL_57;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
ADD(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o ADD \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_59:
if ( v10 != 19 )
goto LABEL_60;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
WRITE(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o WRITE \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_40:
if ( v10 == 22 )
{
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
HALT(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o HALT \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
}
break;
case 2:
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
STORE(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o STORE \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_45:
if ( v10 != 5 )
goto LABEL_46;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JMP(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JMP \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_48:
if ( v10 != 8 )
goto LABEL_49;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JPL(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JPL \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_51:
if ( v10 != 11 )
goto LABEL_52;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JPNE(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JPNE \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_54:
if ( v10 != 14 )
goto LABEL_55;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
OR(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o OR \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_57:
if ( v10 != 17 )
goto LABEL_58;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
SUB(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o SUB \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_60:
if ( v10 != 20 )
goto LABEL_61;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
CALL(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o CALL \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
break;
case 3:
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
PUSH(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o PUSH \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_46:
if ( v10 != 6 )
goto LABEL_47;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JPG(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JPG \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_49:
if ( v10 != 9 )
goto LABEL_50;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
JPLE(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o JPLE \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_52:
if ( v10 != 12 )
goto LABEL_53;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
XOR(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o XOR \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_55:
if ( v10 != 15 )
goto LABEL_56;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
NOT(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o NOT \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_58:
if ( v10 != 18 )
goto LABEL_59;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
READ(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o READ \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
LABEL_61:
if ( v10 != 21 )
goto LABEL_40;
LODWORD(STACK[0x1F90]) = v9;
LODWORD(STACK[0x1F94]) = v7;
LODWORD(STACK[0x1F98]) = v8;
qmemcpy(v11, &a7, sizeof(v11));
RET(v12);
qmemcpy(&a7, v12, 0xFA8uLL);
v8 = v13;
LODWORD(STACK[0x1F98]) = v13;
v9 = STACK[0x1F90];
v7 = STACK[0x1F94];
if ( a1 == 1 )
{
printf("Executando o RET \n ");
printf("PC_=%d, SP_=%d, AC_=%d\n", v9, v8, v7);
printf("\n ");
}
break;
default:
goto LABEL_44;
}
}
}

original_code:
void executaOperacoes(MaquinaVirtual MV, int verbose){
    MV.PC_--;
    int instrucao;
    while(1) {
        MV.PC_++;
 instrucao=MV.RAM_[MV.PC_];
    if(instrucao==1){
        MV=LOAD(MV);
        if(verbose==1){
            printf("Executando o LOAD \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==2){
        MV=STORE(MV);
        if(verbose==1){
            printf("Executando o STORE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==3){
        MV=PUSH(MV);
        if(verbose==1){
            printf("Executando o PUSH \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==4){
        MV=POP(MV);
        if(verbose==1){
            printf("Executando o POP \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==5){
        MV=JMP(MV);
        if(verbose==1){
            printf("Executando o JMP \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==6){
        MV=JPG(MV);
        if(verbose==1){
            printf("Executando o JPG \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==7){
        MV=JPGE(MV);
        if(verbose==1){
            printf("Executando o JPGE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==8){
        MV=JPL(MV);
        if(verbose==1){
            printf("Executando o JPL \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==9){
        MV=JPLE(MV);
        if(verbose==1){
            printf("Executando o JPLE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==10){
        MV=JPE(MV);
        if(verbose==1){
            printf("Executando o JPE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==11){
        MV=JPNE(MV);
        if(verbose==1){
            printf("Executando o JPNE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==12){
        MV=XOR(MV);
        if(verbose==1){
            printf("Executando o XOR \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==13){
        MV=AND(MV);
        if(verbose==1){
            printf("Executando o AND \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==14){
        MV=OR(MV);
        if(verbose==1){
            printf("Executando o OR \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==15){
        MV=NOT(MV);
        if(verbose==1){
            printf("Executando o NOT \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==16){
        MV=ADD(MV);
        if(verbose==1){
            printf("Executando o ADD \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==17){
        MV=SUB(MV);
        if(verbose==1){
            printf("Executando o SUB \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==18){
        MV=READ(MV);
        if(verbose==1){
            printf("Executando o READ \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==19){
        MV=WRITE(MV);
        if(verbose==1){
            printf("Executando o WRITE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==20){
        MV=CALL(MV);
        if(verbose==1){
            printf("Executando o CALL \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==21){
        MV=RET(MV);
        if(verbose==1){
            printf("Executando o RET \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==22){
        MV=HALT(MV);
        if(verbose==1){
            printf("Executando o HALT \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    }
}

canonical_original_code:
void executaOperacoes(struct maquinavirtual MV, int verbose){
    MV.PC_--;
    int instrucao;
    while(1) {
        MV.PC_++;
 instrucao=MV.RAM_[MV.PC_];
    if(instrucao==1){
        MV=LOAD(MV);
        if(verbose==1){
            printf("Executando o LOAD \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==2){
        MV=STORE(MV);
        if(verbose==1){
            printf("Executando o STORE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==3){
        MV=PUSH(MV);
        if(verbose==1){
            printf("Executando o PUSH \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==4){
        MV=POP(MV);
        if(verbose==1){
            printf("Executando o POP \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==5){
        MV=JMP(MV);
        if(verbose==1){
            printf("Executando o JMP \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==6){
        MV=JPG(MV);
        if(verbose==1){
            printf("Executando o JPG \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==7){
        MV=JPGE(MV);
        if(verbose==1){
            printf("Executando o JPGE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==8){
        MV=JPL(MV);
        if(verbose==1){
            printf("Executando o JPL \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==9){
        MV=JPLE(MV);
        if(verbose==1){
            printf("Executando o JPLE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==10){
        MV=JPE(MV);
        if(verbose==1){
            printf("Executando o JPE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==11){
        MV=JPNE(MV);
        if(verbose==1){
            printf("Executando o JPNE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==12){
        MV=XOR(MV);
        if(verbose==1){
            printf("Executando o XOR \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==13){
        MV=AND(MV);
        if(verbose==1){
            printf("Executando o AND \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==14){
        MV=OR(MV);
        if(verbose==1){
            printf("Executando o OR \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==15){
        MV=NOT(MV);
        if(verbose==1){
            printf("Executando o NOT \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==16){
        MV=ADD(MV);
        if(verbose==1){
            printf("Executando o ADD \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==17){
        MV=SUB(MV);
        if(verbose==1){
            printf("Executando o SUB \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==18){
        MV=READ(MV);
        if(verbose==1){
            printf("Executando o READ \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==19){
        MV=WRITE(MV);
        if(verbose==1){
            printf("Executando o WRITE \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==20){
        MV=CALL(MV);
        if(verbose==1){
            printf("Executando o CALL \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==21){
        MV=RET(MV);
        if(verbose==1){
            printf("Executando o RET \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    if(instrucao==22){
        MV=HALT(MV);
        if(verbose==1){
            printf("Executando o HALT \n ");
            printf("PC_=%d, SP_=%d, AC_=%d\n",MV.PC_,MV.SP_,MV.AC_);
            printf("\n ");
        }
    }
    }
}

variable_types: struct maquinavirtual { int RAM_[1000]; int PC_; int AC_; int SP_; }

variable_types: verbose int

variable_types: instrucao int


repo: thammi/epa

decompiled_code:
__int64 __fastcall list_add_edge(_QWORD *a1, int a2, int a3)
{
_QWORD *v4; // rax
_QWORD *v5; // rdx

v4 = malloc(0x10uLL);
*(_DWORD *)v4 = a3;
v5 = (_QWORD *)(*a1 + 8LL * a2);
v4[1] = *v5;
*v5 = v4;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, int a2, int a3)
{
_QWORD *v4; // rax
_QWORD *v5; // rdx

v4 = malloc(0x10uLL);
*(_DWORD *)v4 = a3;
v5 = (_QWORD *)(*a1 + 8LL * a2);
v4[1] = *v5;
*v5 = v4;
return 1LL;
}

original_code:
int list_add_edge(adj_list *lists, int from, int to) {
 adj_node *new_node = malloc(sizeof(adj_node));
 new_node->neighbour = to;
 new_node->next = lists->nodes[from];
 lists->nodes[from] = new_node;
 return 1;
}

canonical_original_code:
int list_add_edge(struct adj_list *lists, int from, int to) {
 struct adj_node *new_node = malloc(sizeof(adj_node));
 new_node->neighbour = to;
 new_node->next = lists->nodes[from];
 lists->nodes[from] = new_node;
 return 1;
}

variable_types: struct adj_list { struct adj_node { int neighbour; struct adj_node *next; } **nodes; unsigned long size; } *

variable_types: from int

variable_types: to int

return_type: int

user_defined_types: struct adj_list { struct adj_node **nodes; unsigned long size; }


decompiled_code:
__int64 __fastcall list_remove_edge(_QWORD *a1, int a2, int a3)
{
void **v3; // rax
char *v4; // rdi

v3 = (void **)(*a1 + 8LL * a2);
v4 = (char *)*v3;
if ( !*v3 )
return 0LL;
while ( *(_DWORD *)v4 != a3 )
{
v3 = (void **)(v4 + 8);
v4 = (char *)*((_QWORD *)v4 + 1);
if ( !v4 )
return 0LL;
}
*v3 = (void *)*((_QWORD *)v4 + 1);
free(v4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, int a2, int a3)
{
void **v3; // rax
char *v4; // rdi

v3 = (void **)(*a1 + 8LL * a2);
v4 = (char *)*v3;
if ( !*v3 )
return 0LL;
while ( *(_DWORD *)v4 != a3 )
{
v3 = (void **)(v4 + 8);
v4 = (char *)*((_QWORD *)v4 + 1);
if ( !v4 )
return 0LL;
}
*v3 = (void *)*((_QWORD *)v4 + 1);
free(v4);
return 1LL;
}

original_code:
int list_remove_edge(adj_list *lists, int from, int to) {
 adj_node **cur_ptr = &lists->nodes[from];
 while(*cur_ptr) {
  adj_node *cur = *cur_ptr;
  if(cur->neighbour == to) {
   *cur_ptr = cur->next;
   free(cur);
   return 1;
  }
  cur_ptr = &cur->next;
 }
 return 0;
}

canonical_original_code:
int list_remove_edge(struct adj_list *lists, int from, int to) {
 struct adj_node **cur_ptr = &lists->nodes[from];
 while(*cur_ptr) {
  struct adj_node *cur = *cur_ptr;
  if(cur->neighbour == to) {
   *cur_ptr = cur->next;
   free(cur);
   return 1;
  }
  cur_ptr = &cur->next;
 }
 return 0;
}

variable_types: struct adj_node { int neighbour; struct adj_node *next; } **


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

result = *(_QWORD *)(*a1 + 8LL * a2);
if ( !result )
return 0LL;
while ( *(_DWORD *)result != a3 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return 1LL;
}

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

result = *(_QWORD *)(*a1 + 8LL * a2);
if ( !result )
return 0LL;
while ( *(_DWORD *)result != a3 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return 1LL;
}

original_code:
int list_test_edge(adj_list *lists, int from, int to) {
 adj_node *cur = lists->nodes[from];
 while(cur) {
  if(cur->neighbour == to) {
   return 1;
  }
  cur = cur->next;
 }
 return 0;
}

canonical_original_code:
int list_test_edge(struct adj_list *lists, int from, int to) {
 struct adj_node *cur = lists->nodes[from];
 while(cur) {
  if(cur->neighbour == to) {
   return 1;
  }
  cur = cur->next;
 }
 return 0;
}

variable_types: struct adj_node { int neighbour; struct adj_node *next; } *


decompiled_code:
void __fastcall free_adj_list(void *ptr)
{
unsigned __int64 v2; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

if ( *((_QWORD *)ptr + 1) )
{
v2 = 0LL;
do
{
v3 = *(_QWORD **)(*(_QWORD *)ptr + 8 * v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[1];
free(v4);
}
++v2;
}
while ( *((_QWORD *)ptr + 1) > v2 );
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
unsigned __int64 v2; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

if ( *((_QWORD *)ptr + 1) )
{
v2 = 0LL;
do
{
v3 = *(_QWORD **)(*(_QWORD *)ptr + 8 * v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[1];
free(v4);
}
++v2;
}
while ( *((_QWORD *)ptr + 1) > v2 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_adj_list(adj_list *list) {
 for(int i = 0; i < list->size; ++i) {
  adj_node *cur = list->nodes[i];
  while(cur) {
   adj_node *next = cur->next;
   free(cur);
   cur = next;
  }
 }
 free(list->nodes);
 free(list);
}

canonical_original_code:
void free_adj_list(struct adj_list *list) {
 for(int i = 0; i < list->size; ++i) {
  struct adj_node *cur = list->nodes[i];
  while(cur) {
   struct adj_node *next = cur->next;
   free(cur);
   cur = next;
  }
 }
 free(list->nodes);
 free(list);
}

variable_types: i int

return_type: void

user_defined_types: struct adj_node { int neighbour; struct adj_node *next; }


original_code:
size_t list_mem(adj_list *list) {
 int count = 0;
 for(int x = 0; x < list->size; ++x) {
  for(int y = 0; y < list->size; ++y) {
   if(list_test_edge(list, x, y)) {
    ++count;
   }
  }
 }
 return sizeof(*list) + list->size * sizeof(list->nodes) + count * sizeof(**list->nodes);
}

canonical_original_code:
unsigned long list_mem(struct adj_list *list) {
 int count = 0;
 for(int x = 0; x < list->size; ++x) {
  for(int y = 0; y < list->size; ++y) {
   if(list_test_edge(list, x, y)) {
    ++count;
   }
  }
 }
 return sizeof(*list) + list->size * sizeof(list->nodes) + count * sizeof(**list->nodes);
}

variable_types: count int

variable_types: x int

variable_types: y int

return_type: unsigned long


benchmark

decompiled_code:
int __fastcall benchmark(unsigned int a1)
{
int v1; // er14
void **v2; // rbx
char *v3; // rbp
double v4; // r15
int v5; // er14
void **v6; // rbx
char *v7; // rbp
double v8; // rbp
_BYTE v10[400]; // [rsp+0h] [rbp-358h] BYREF
char v11[400]; // [rsp+190h] [rbp-1C8h] BYREF
char v12[56]; // [rsp+320h] [rbp-38h] BYREF

v1 = clock();
v2 = (void **)v11;
v3 = v11;
do
{
*(_QWORD *)v3 = create_adj_matrix(1000LL, a1);
v3 += 8;
}
while ( v3 != v12 );
v4 = (double)(int)(clock() - v1) / 1000000.0 / 50.0;
do
free_adj_matrix(*v2++);
while ( v2 != (void **)v12 );
v5 = clock();
v6 = (void **)v10;
v7 = v10;
do
{
*(_QWORD *)v7 = create_adj_list(1000LL, a1);
v7 += 8;
}
while ( v11 != v7 );
v8 = (double)(int)(clock() - v5) / 1000000.0 / 50.0;
do
free_adj_list(*v6++);
while ( v11 != (char *)v6 );
return printf("%d;%.4f;%.4f\n", a1, v4, v8);
}

original_code:
void benchmark(int n) {
 clock_t matrix_start = clock();
 adj_matrix *matrix[50];
 for(int i = 0; i < 50; ++i) {
  matrix[i] = create_adj_matrix(1000, n);
 }
 double matrix_time = (clock() - matrix_start) / (double) ((__clock_t) 1000000) / 50;
 for(int i = 0; i < 50; ++i) {
  free_adj_matrix(matrix[i]);
 }
 clock_t list_start = clock();
 adj_list *list[50];
 for(int i = 0; i < 50; ++i) {
  list[i] = create_adj_list(1000, n);
 }
 double list_time = (clock() - list_start) / (double) ((__clock_t) 1000000) / 50;
 for(int i = 0; i < 50; ++i) {
  free_adj_list(list[i]);
 }
 printf("%d;%.4f;%.4f\n", n, matrix_time, list_time);
}

canonical_original_code:
void benchmark(int n) {
 long matrix_start = clock();
 struct adj_matrix *matrix[50];
 for(int i = 0; i < 50; ++i) {
  matrix[i] = create_adj_matrix(1000, n);
 }
 double matrix_time = (clock() - matrix_start) / (double) ((__clock_t) 1000000) / 50;
 for(int i = 0; i < 50; ++i) {
  free_adj_matrix(matrix[i]);
 }
 long list_start = clock();
 struct adj_list *list[50];
 for(int i = 0; i < 50; ++i) {
  list[i] = create_adj_list(1000, n);
 }
 double list_time = (clock() - list_start) / (double) ((__clock_t) 1000000) / 50;
 for(int i = 0; i < 50; ++i) {
  free_adj_list(list[i]);
 }
 printf("%d;%.4f;%.4f\n", n, matrix_time, list_time);
}

variable_types: n int

variable_types: struct adj_matrix { char *data; unsigned long size; } *[50]

variable_types: struct adj_list { struct adj_node { int neighbour; struct adj_node *next; } **nodes; unsigned long size; } *[50]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx

puts("n;matrix;list");
benchmark(1u);
for ( i = 49; i != 2049; i += 50 )
benchmark(i);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx

puts("n;matrix;list");
func12(1u);
for ( i = 49; i != 2049; i += 50 )
func12(i);
return 0;
}

original_code:
int main(int argc, char *args[]) {
 printf("n;matrix;list\n");
 benchmark(1);
 for(int i = 49; i < 2000; i += 50) {
  benchmark(i);
 }
 return 0;
}

variable_types: argc int

variable_types:
args
char *[]


original_code:
int matrix_add_edge(adj_matrix *matrix, int from, int to) {
 const size_t i = from * matrix->size + to;
 matrix->data[i/8] |= 1 << i % 8;
 return 1;
}

canonical_original_code:
int matrix_add_edge(struct adj_matrix *matrix, int from, int to) {
 unsigned long i = from * matrix->size + to;
 matrix->data[i/8] |= 1 << i % 8;
 return 1;
}

variable_types: struct adj_matrix { char *data; unsigned long size; } *

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall matrix_remove_edge(_QWORD *a1, int a2, int a3)
{
__int64 v3; // rsi
char v4; // cl
_BYTE *v5; // rdx

v3 = a1[1] * a2;
v4 = v3 + a3;
v5 = (_BYTE *)(*a1 + ((unsigned __int64)(v3 + a3) >> 3));
*v5 &= ~(unsigned __int8)(1 << (v4 & 7));
return 1LL;
}

original_code:
int matrix_remove_edge(adj_matrix *matrix, int from, int to) {
 const size_t i = from * matrix->size + to;
 matrix->data[i/8] &= ~(1 << i % 8);
 return 1;
}

canonical_original_code:
int matrix_remove_edge(struct adj_matrix *matrix, int from, int to) {
 unsigned long i = from * matrix->size + to;
 matrix->data[i/8] &= ~(1 << i % 8);
 return 1;
}

user_defined_types: struct adj_matrix { char *data; unsigned long size; }


decompiled_code:
__int64 __fastcall matrix_test_edge(__int64 a1, int a2, int a3)
{
return (1 << ((*(_BYTE *)(a1 + 8) * a2 + a3) & 7)) & (unsigned int)*(char *)(*(_QWORD *)a1
+ ((unsigned __int64)(*(_QWORD *)(a1 + 8)
* a2
+ a3) >> 3));
}

original_code:
int matrix_test_edge(adj_matrix *matrix, int from, int to) {
 const size_t i = from * matrix->size + to;
 return matrix->data[i/8] & (1 << i % 8);
}

canonical_original_code:
int matrix_test_edge(struct adj_matrix *matrix, int from, int to) {
 unsigned long i = from * matrix->size + to;
 return matrix->data[i/8] & (1 << i % 8);
}


decompiled_code:
void __fastcall free_adj_matrix(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func16(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_adj_matrix(adj_matrix *matrix) {
 free(matrix->data);
 free(matrix);
}

canonical_original_code:
void free_adj_matrix(struct adj_matrix *matrix) {
 free(matrix->data);
 free(matrix);
}


repo: tharvey/gst-httpd

original_code:
unsigned long
avg_add_samples(struct avg* pavg, unsigned long val)
{
 int i;
 time_t now = time(((void *)0));
 if (pavg->lastupdate > now
  || now - pavg->lastupdate > 0
  || pavg->_idx == 0)
 {
  pavg->idx++;
  pavg->lastupdate = now;
  if (pavg->_idx < 1 +1)
   pavg->_idx++;
  if (pavg->idx >= 1 +1)
   pavg->idx = 0;
  pavg->window[pavg->idx] = 0;
 }
 pavg->window[pavg->idx] += val;
 pavg->total += val;
 pavg->avg = 0;
 if (pavg->_idx > 1) {
  for (i = 0; i < 1 +1; i++) {
   if (i != pavg->idx)
    pavg->avg += pavg->window[i];
  }
  if (pavg->_idx > 2)
   pavg->avg /= (pavg->_idx - 1);
 }
 return pavg->avg;
}

canonical_original_code:
unsigned long avg_add_samples(struct avg *pavg, unsigned long val)
{
 int i;
 long now = time(((void *)0));
 if (pavg->lastupdate > now
  || now - pavg->lastupdate > 0
  || pavg->_idx == 0)
 {
  pavg->idx++;
  pavg->lastupdate = now;
  if (pavg->_idx < 1 +1)
   pavg->_idx++;
  if (pavg->idx >= 1 +1)
   pavg->idx = 0;
  pavg->window[pavg->idx] = 0;
 }
 pavg->window[pavg->idx] += val;
 pavg->total += val;
 pavg->avg = 0;
 if (pavg->_idx > 1) {
  for (i = 0; i < 1 +1; i++) {
   if (i != pavg->idx)
    pavg->avg += pavg->window[i];
  }
  if (pavg->_idx > 2)
   pavg->avg /= (pavg->_idx - 1);
 }
 return pavg->avg;
}

variable_types: struct avg { unsigned long total; unsigned long avg; unsigned int idx; unsigned int _idx; unsigned long window[-1]; long lastupdate; } *

variable_types:
val
unsigned long

variable_types: now long


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

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

original_code:
unsigned long
avg_get_avg(struct avg *pavg)
{
 return pavg->avg;
}

user_defined_types: struct avg { unsigned long total; unsigned long avg; unsigned int idx; unsigned int _idx; unsigned long window[-1]; long lastupdate; }


repo: thasmin/apocscientist

decompiled_code:
_BOOL8 __fastcall point_is_valid(float *a1)
{
_BOOL8 result; // rax

if ( -1.0 == *a1 )
result = 0LL;
else
result = -1.0 != a1[1];
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(float *a1)
{
_BOOL8 result; // rax

if ( -1.0 == *a1 )
result = 0LL;
else
result = -1.0 != a1[1];
return result;
}

original_code:
int point_is_valid(point *p)
{
 return p->x != -1 && p->y != -1;
}

canonical_original_code:
int point_is_valid(struct _point *p)
{
 return p->x != -1 && p->y != -1;
}

variable_types:
p
struct _point { float x; float y; } *


decompiled_code:
double __fastcall point_dist(float *a1, float *a2)
{
double v2; // xmm0_8
int v3; // eax
double result; // xmm0_8

if ( a1 == a2 )
return 0.0;
if ( !a1 || !a2 )
return 0.0;
v2 = (double)((int)*a1 - (int)*a2);
v3 = (int)a1[1] - (int)a2[1];
result = v2 * v2 + (double)v3 * (double)v3;
*(float *)&result = result;
return result;
}

canonical_decompiled_code:
double __fastcall func2(float *a1, float *a2)
{
double v2; // xmm0_8
int v3; // eax
double result; // xmm0_8

if ( a1 == a2 )
return 0.0;
if ( !a1 || !a2 )
return 0.0;
v2 = (double)((int)*a1 - (int)*a2);
v3 = (int)a1[1] - (int)a2[1];
result = v2 * v2 + (double)v3 * (double)v3;
*(float *)&result = result;
return result;
}

original_code:
float point_dist(point *p1, point *p2)
{
 if (p1 == p2)
  return 0;
 if (p1 == ((void *)0) || p2 == ((void *)0))
  return 0;
 return pow((int)p1->x - (int)p2->x, 2) + pow((int)p1->y - (int)p2->y, 2);
}

canonical_original_code:
float point_dist(struct _point *p1, struct _point *p2)
{
 if (p1 == p2)
  return 0;
 if (p1 == ((void *)0) || p2 == ((void *)0))
  return 0;
 return pow((int)p1->x - (int)p2->x, 2) + pow((int)p1->y - (int)p2->y, 2);
}

return_type: float


decompiled_code:
_BOOL8 __fastcall point_equals(float *a1, float *a2)
{
if ( a1 == a2 )
return 1LL;
if ( !a1 || !a2 )
return 0LL;
if ( *a1 == *a2 )
return a1[1] == a2[1];
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(float *a1, float *a2)
{
if ( a1 == a2 )
return 1LL;
if ( !a1 || !a2 )
return 0LL;
if ( *a1 == *a2 )
return a1[1] == a2[1];
return 0LL;
}

original_code:
int point_equals(point *p1, point *p2)
{
 if (p1 == p2)
  return 1;
 if (p1 == ((void *)0) || p2 == ((void *)0))
  return 0;
 return p1->x == p2->x && p1->y == p2->y;
}

canonical_original_code:
int point_equals(struct _point *p1, struct _point *p2)
{
 if (p1 == p2)
  return 1;
 if (p1 == ((void *)0) || p2 == ((void *)0))
  return 0;
 return p1->x == p2->x && p1->y == p2->y;
}


original_code:
void point_moveto(point *mover, point *target, float dist)
{
 if (point_equals(mover, target))
  return;
 float movex = (int)target->x - (int)mover->x;
 float movey = (int)target->y - (int)mover->y;
 float angle = atan2(movey, movex) * 180 / 3.14159265;
 if (angle < 0)
  angle += 360;
 float step = 360.0f / 16;
 if (angle > 360 - step || angle < 0 + step)
  mover->x += dist;
 else if (angle > 45 - step && angle < 45 + step)
  mover->x += dist, mover->y += dist;
 else if (angle > 90 - step && angle < 90 + step)
  mover->y += dist;
 else if (angle > 135 - step && angle < 135 + step)
  mover->x -= dist, mover->y += dist;
 else if (angle > 180 - step && angle < 180 + step)
  mover->x -= dist;
 else if (angle > 225 - step && angle < 225 + step)
  mover->x -= dist, mover->y -= dist;
 else if (angle > 270 - step && angle < 270 + step)
  mover->y -= dist;
 else if (angle > 315 - step && angle < 315 + step)
  mover->x += dist, mover->y -= dist;
 else
  printf("bad angle: %f\n", angle);
}

canonical_original_code:
void point_moveto(struct _point *mover, struct _point *target, float dist)
{
 if (point_equals(mover, target))
  return;
 float movex = (int)target->x - (int)mover->x;
 float movey = (int)target->y - (int)mover->y;
 float angle = atan2(movey, movex) * 180 / 3.14159265;
 if (angle < 0)
  angle += 360;
 float step = 360.0f / 16;
 if (angle > 360 - step || angle < 0 + step)
  mover->x += dist;
 else if (angle > 45 - step && angle < 45 + step)
  mover->x += dist, mover->y += dist;
 else if (angle > 90 - step && angle < 90 + step)
  mover->y += dist;
 else if (angle > 135 - step && angle < 135 + step)
  mover->x -= dist, mover->y += dist;
 else if (angle > 180 - step && angle < 180 + step)
  mover->x -= dist;
 else if (angle > 225 - step && angle < 225 + step)
  mover->x -= dist, mover->y -= dist;
 else if (angle > 270 - step && angle < 270 + step)
  mover->y -= dist;
 else if (angle > 315 - step && angle < 315 + step)
  mover->x += dist, mover->y -= dist;
 else
  printf("bad angle: %f\n", angle);
}

variable_types:
mover
struct _point { float x; float y; } *

variable_types:
target
struct _point *

variable_types: dist float

variable_types: movex float

variable_types: movey float

variable_types: angle float

variable_types: step float


decompiled_code:
int __fastcall debug_print_point(float *a1)
{
return printf("%f, %f\n", *a1, a1[1]);
}

canonical_decompiled_code:
int __fastcall func5(float *a1)
{
return printf("%f, %f\n", *a1, a1[1]);
}

original_code:
void debug_print_point(point *p)
{
 printf("%f, %f\n", p->x, p->y);
}

canonical_original_code:
void debug_print_point(struct _point *p)
{
 printf("%f, %f\n", p->x, p->y);
}


decompiled_code:
int __fastcall debug_print_point_node_list(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
int result; // eax

if ( a1 )
{
v1 = a1;
v2 = 0;
do
{
result = printf("%d: %f, %f\n", v2++, *(float *)v1, *(float *)(v1 + 4));
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
int result; // eax

if ( a1 )
{
v1 = a1;
v2 = 0;
do
{
result = printf("%d: %f, %f\n", v2++, *(float *)v1, *(float *)(v1 + 4));
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return result;
}

original_code:
void debug_print_point_node_list(point_node *node)
{
 int i = 0;
 while (node) {
  printf("%d: %f, %f\n", i, node->p.x, node->p.y);
  ++i;
  node = node->next;
 }
}

canonical_original_code:
void debug_print_point_node_list(struct _point_node *node)
{
 int i = 0;
 while (node) {
  printf("%d: %f, %f\n", i, node->p.x, node->p.y);
  ++i;
  node = node->next;
 }
}

variable_types: struct _point_node { struct _point { float x; float y; } p; struct _point_node *next; } *

variable_types: i int

user_defined_types: struct _point_node { struct _point p; struct _point_node *next; }


decompiled_code:
void orders_init()
{
pending = 0LL;
}

canonical_decompiled_code:
void func0()
{
pending = 0LL;
}

original_code:
void orders_init()
{
 pending = ((void *)0);
}


repo: thayton/ptrie

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
test_1(argc, argv, envp);
test_2();
test_3();
test_4();
test_5();
test_6();
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func0(argc, argv, envp);
func1();
func2();
func3();
func4();
func5();
exit(0);
}

original_code:
int main(int argc, char **argv)
{
    test_1();
    test_2();
    test_3();
    test_4();
    test_5();
    test_6();
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **


getbit

decompiled_code:
__int64 __fastcall getbit(__int64 a1, unsigned __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned __int64 v4; // rdx

result = a3;
if ( a3 )
{
v4 = (int)(a3 - 1) >> 3;
if ( v4 > a2 )
result = 0LL;
else
result = ((int)*(unsigned __int8 *)(a1 + v4) >> (-(char)result & 7)) & 1;
}
return result;
}

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

result = a3;
if ( a3 )
{
v4 = (int)(a3 - 1) >> 3;
if ( v4 > a2 )
result = 0LL;
else
result = ((int)*(unsigned __int8 *)(a1 + v4) >> (-(char)result & 7)) & 1;
}
return result;
}

original_code:
static inline int getbit(void *key, size_t keysz, int bit)
{
    uint8_t *ptr = (uint8_t *)key;
    if (bit) {
        bit--;
        if ((bit >> 3) > keysz)
            return 0;
        return ptr[bit >> 3] & 1<<(7 - (bit & 7)) ? 1 : 0;
    }
    return 0;
}

canonical_original_code:
static inline int getbit(void *key, unsigned long keysz, int bit)
{
    unsigned char *ptr = (uint8_t *)key;
    if (bit) {
        bit--;
        if ((bit >> 3) > keysz)
            return 0;
        return ptr[bit >> 3] & 1<<(7 - (bit & 7)) ? 1 : 0;
    }
    return 0;
}

variable_types:
key
void *

variable_types:
keysz
unsigned long

variable_types: bit int

variable_types:
ptr
unsigned char *


keycmp

original_code:
static inline int keycmp(void *key1, size_t key1sz, void *key2, size_t key2sz)
{
    int i;
    int j;
    uint8_t *ptr1 = (uint8_t *)key1;
    uint8_t *ptr2 = (uint8_t *)key2;
    for (i = 0; *ptr1 == *ptr2; ptr1++, ptr2++, i++) {
        if (key1sz == key2sz) {
            if (i+1 == key1sz)
                return 0;
        }
    }
    i = i*8 + 1;
    for (j = 1<<7; (*ptr1 & j) == (*ptr2 & j); i++, j >>= 1)
            ;
    return (*ptr1 & j) ? i : -i;
}

canonical_original_code:
static inline int keycmp(void *key1, unsigned long key1sz, void *key2, unsigned long key2sz)
{
    int i;
    int j;
    unsigned char *ptr1 = (uint8_t *)key1;
    unsigned char *ptr2 = (uint8_t *)key2;
    for (i = 0; *ptr1 == *ptr2; ptr1++, ptr2++, i++) {
        if (key1sz == key2sz) {
            if (i+1 == key1sz)
                return 0;
        }
    }
    i = i*8 + 1;
    for (j = 1<<7; (*ptr1 & j) == (*ptr2 & j); i++, j >>= 1)
            ;
    return (*ptr1 & j) ? i : -i;
}

variable_types: j int


original_code:
static pnode_t *
pnode_new(ptrie_t *pt, pn_type_t type)
{
    pnode_t *pn;
    if (pt->pt_list == ((void *)0)) {
        int i;
        for (i = 0; i < 1024; i++) {
            pn = pt->pt_malloc_func(sizeof(*pn));
            pn->pn_u.pn_node.pn_Cld[0] = pt->pt_list;
            pt->pt_list = pn;
        }
    }
    pn = pt->pt_list;
    pt->pt_list = pn->pn_u.pn_node.pn_Cld[0];
    pn->pn_type = type;
    return pn;
}

canonical_original_code:
static struct pnode *pnode_new(struct ptrie *pt, enum pn_type_t type)
{
    struct pnode *pn;
    if (pt->pt_list == ((void *)0)) {
        int i;
        for (i = 0; i < 1024; i++) {
            pn = pt->pt_malloc_func(sizeof(*pn));
            pn->pn_u.pn_node.pn_Cld[0] = pt->pt_list;
            pt->pt_list = pn;
        }
    }
    pn = pt->pt_list;
    pt->pt_list = pn->pn_u.pn_node.pn_Cld[0];
    pn->pn_type = type;
    return pn;
}

variable_types: struct ptrie { struct pnode *pt_root; struct pnode *pt_list; unsigned long pt_size; unsigned int pt_parms; struct ptrie_iter { void *pn; void *root; } pt_iter; void *(*pt_malloc_func)(unsigned long); void (*pt_free_func)(void *); unsigned long pt_keysz; unsigned long (*pt_keysz_func)(void *key); } *

variable_types:
type
enum pn_type_t { PN_LEAF=0, PN_NODE=1 }

variable_types: struct pnode { enum pn_type_t { PN_LEAF=0, PN_NODE=1 } pn_type; struct pnode *pn_up; union { struct { void *pn_Key; unsigned long pn_Keysz; void *pn_Val; unsigned long pn_Valsz; } pn_leaf; struct { int pn_Bit; struct pnode *pn_Cld[2]; } pn_node; } pn_u; } *

user_defined_types: struct ptrie { struct pnode *pt_root; struct pnode *pt_list; unsigned long pt_size; unsigned int pt_parms; struct ptrie_iter pt_iter; void *(*pt_malloc_func)(unsigned long); void (*pt_free_func)(void *); unsigned long pt_keysz; unsigned long (*pt_keysz_func)(void *key); }

user_defined_types: struct pnode { enum pn_type_t pn_type; struct pnode *pn_up; union { struct { void *pn_Key; unsigned long pn_Keysz; void *pn_Val; unsigned long pn_Valsz; } pn_leaf; struct { int pn_Bit; struct pnode *pn_Cld[2]; } pn_node; } pn_u; }


newpar

decompiled_code:
__int64 __fastcall newpar(__int64 a1, int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = pnode_new(a1, 1);
*(_DWORD *)(result + 16) = a2 ^ (a2 >> 31);
*(_DWORD *)(result + 16) -= a2 >> 31;
if ( a2 < 0 )
{
*(_QWORD *)(result + 24) = a3;
*(_QWORD *)(result + 32) = a4;
}
else
{
*(_QWORD *)(result + 24) = a4;
*(_QWORD *)(result + 32) = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = func2(a1, 1);
*(_DWORD *)(result + 16) = a2 ^ (a2 >> 31);
*(_DWORD *)(result + 16) -= a2 >> 31;
if ( a2 < 0 )
{
*(_QWORD *)(result + 24) = a3;
*(_QWORD *)(result + 32) = a4;
}
else
{
*(_QWORD *)(result + 24) = a4;
*(_QWORD *)(result + 32) = a3;
}
return result;
}

original_code:
static pnode_t *
newpar(ptrie_t *pt, int diffbit, pnode_t *cld1, pnode_t *cld2)
{
    pnode_t *pn = pnode_new(pt, PN_NODE);
    pn->pn_u.pn_node.pn_Bit = ((diffbit) < 0 ? -(diffbit) : (diffbit));
    if (diffbit < 0) {
        pn->pn_u.pn_node.pn_Cld[0] = cld1;
        pn->pn_u.pn_node.pn_Cld[1] = cld2;
    } else {
        pn->pn_u.pn_node.pn_Cld[0] = cld2;
        pn->pn_u.pn_node.pn_Cld[1] = cld1;
    }
    return pn;
}

canonical_original_code:
static struct pnode *newpar(struct ptrie *pt, int diffbit, struct pnode *cld1, struct pnode *cld2)
{
    struct pnode *pn = pnode_new(pt, PN_NODE);
    pn->pn_u.pn_node.pn_Bit = ((diffbit) < 0 ? -(diffbit) : (diffbit));
    if (diffbit < 0) {
        pn->pn_u.pn_node.pn_Cld[0] = cld1;
        pn->pn_u.pn_node.pn_Cld[1] = cld2;
    } else {
        pn->pn_u.pn_node.pn_Cld[0] = cld2;
        pn->pn_u.pn_node.pn_Cld[1] = cld1;
    }
    return pn;
}

variable_types: diffbit int

return_type: struct pnode { enum pn_type_t { PN_LEAF=0, PN_NODE=1 } pn_type; struct pnode *pn_up; union { struct { void *pn_Key; unsigned long pn_Keysz; void *pn_Val; unsigned long pn_Valsz; } pn_leaf; struct { int pn_Bit; struct pnode *pn_Cld[2]; } pn_node; } pn_u; } *

user_defined_types: struct ptrie_iter { void *pn; void *root; }


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

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

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

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

original_code:
static void
pnode_free(ptrie_t *pt, pnode_t *pn)
{
    pn->pn_u.pn_node.pn_Cld[0] = pt->pt_list;
    pt->pt_list = pn;
}

canonical_original_code:
static void pnode_free(struct ptrie *pt, struct pnode *pn)
{
    pn->pn_u.pn_node.pn_Cld[0] = pt->pt_list;
    pt->pt_list = pn;
}

variable_types: struct ptrie { struct pnode { enum pn_type_t { PN_LEAF=0, PN_NODE=1 } pn_type; struct pnode *pn_up; union { struct { void *pn_Key; unsigned long pn_Keysz; void *pn_Val; unsigned long pn_Valsz; } pn_leaf; struct { int pn_Bit; struct pnode *pn_Cld[2]; } pn_node; } pn_u; } *pt_root; struct pnode *pt_list; unsigned long pt_size; unsigned int pt_parms; struct ptrie_iter { void *pn; void *root; } pt_iter; void *(*pt_malloc_func)(unsigned long); void (*pt_free_func)(void *); unsigned long pt_keysz; unsigned long (*pt_keysz_func)(void *key); } *

variable_types:
pn
struct pnode *


fmalloc

decompiled_code:
void *__fastcall fmalloc(size_t a1)
{
void *result; // rax
int *v2; // rax
char *v3; // rax

result = malloc(a1);
if ( !result )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "fmalloc - malloc failed: %s\n", v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func5(size_t a1)
{
void *result; // rax
int *v2; // rax
char *v3; // rax

result = malloc(a1);
if ( !result )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "fmalloc - malloc failed: %s\n", v3);
exit(1);
}
return result;
}

original_code:
static void *
fmalloc(size_t size)
{
    void *data = malloc(size);
    if (data == ((void *)0)) {
        fprintf(stderr, "fmalloc - malloc failed: %s\n", strerror((*__errno_location ())));
        exit(1);
    }
    return data;
}

canonical_original_code:
static void *fmalloc(unsigned long size)
{
    void *data = malloc(size);
    if (data == ((void *)0)) {
        fprintf(stderr, "fmalloc - malloc failed: %s\n", strerror((*__errno_location ())));
        exit(1);
    }
    return data;
}

variable_types:
size
unsigned long

variable_types:
data
void *

return_type: void *


keysize

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

result = *(_QWORD *)(a1 + 64);
if ( !result )
{
v3 = *(__int64 (__fastcall **)(__int64))(a1 + 72);
if ( !v3 )
{
fwrite("Error: unable to determine key size\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
result = v3(a2);
}
return result;
}

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

result = *(_QWORD *)(a1 + 64);
if ( !result )
{
v3 = *(__int64 (__fastcall **)(__int64))(a1 + 72);
if ( !v3 )
{
fwrite("Error: unable to determine key size\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
result = v3(a2);
}
return result;
}

original_code:
static size_t
keysize(ptrie_t *pt, void *key)
{
    if (pt->pt_keysz)
        return pt->pt_keysz;
    else if (pt->pt_keysz_func)
        return (*pt->pt_keysz_func)(key);
    else {
        fprintf(stderr, "Error: unable to determine key size\n");
        exit(1);
    }
}

canonical_original_code:
static unsigned long keysize(struct ptrie *pt, void *key)
{
    if (pt->pt_keysz)
        return pt->pt_keysz;
    else if (pt->pt_keysz_func)
        return (*pt->pt_keysz_func)(key);
    else {
        fprintf(stderr, "Error: unable to determine key size\n");
        exit(1);
    }
}


keyseq

decompiled_code:
_BOOL8 __fastcall keyseq(const void *a1, size_t a2, const void *a3, __int64 a4)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 == a4 )
result = memcmp(a1, a3, a2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(const void *a1, size_t a2, const void *a3, __int64 a4)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 == a4 )
result = memcmp(a1, a3, a2) == 0;
return result;
}

original_code:
static inline int keyseq(void *key1, size_t key1sz, void *key2, size_t key2sz)
{
    return key1sz == key2sz && memcmp(key1, key2, key1sz) == 0;
}

canonical_original_code:
static inline int keyseq(void *key1, unsigned long key1sz, void *key2, unsigned long key2sz)
{
    return key1sz == key2sz && memcmp(key1, key2, key1sz) == 0;
}


original_code:
static pnode_t *
ptrie_del0(ptrie_t *pt, void *key, size_t keysz, pnode_t *pn)
{
    int i;
    if (pn->pn_type == PN_NODE) {
        i = getbit(key, keysz, pn->pn_u.pn_node.pn_Bit);
        pn->pn_u.pn_node.pn_Cld[i] = ptrie_del0(pt, key, keysz, pn->pn_u.pn_node.pn_Cld[i]);
        if (pn->pn_u.pn_node.pn_Cld[i] == ((void *)0)) {
            pnode_t *fn;
            pn->pn_u.pn_node.pn_Cld[((i) ^ 1)]->pn_up = pn->pn_up;
            fn = pn;
            pn = pn->pn_u.pn_node.pn_Cld[((i) ^ 1)];
            pnode_free(pt, fn);
        }
    } else if (keyseq(key, keysz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz)) {
        pnode_free(pt, pn);
        pn = ((void *)0);
        pt->pt_size--;
    }
    return pn;
}

canonical_original_code:
static struct pnode *ptrie_del0(struct ptrie *pt, void *key, unsigned long keysz, struct pnode *pn)
{
    int i;
    if (pn->pn_type == PN_NODE) {
        i = getbit(key, keysz, pn->pn_u.pn_node.pn_Bit);
        pn->pn_u.pn_node.pn_Cld[i] = ptrie_del0(pt, key, keysz, pn->pn_u.pn_node.pn_Cld[i]);
        if (pn->pn_u.pn_node.pn_Cld[i] == ((void *)0)) {
            struct pnode *fn;
            pn->pn_u.pn_node.pn_Cld[((i) ^ 1)]->pn_up = pn->pn_up;
            fn = pn;
            pn = pn->pn_u.pn_node.pn_Cld[((i) ^ 1)];
            pnode_free(pt, fn);
        }
    } else if (keyseq(key, keysz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz)) {
        pnode_free(pt, pn);
        pn = ((void *)0);
        pt->pt_size--;
    }
    return pn;
}


original_code:
ptrie_t *
ptrie_new(void)
{
    int i;
    ptrie_t *pt;
    pnode_t *pn;
    pt = fmalloc(sizeof(*pt));
    pt->pt_root = ((void *)0);
    pt->pt_list = ((void *)0);
    pt->pt_size = 0;
    pt->pt_keysz = 0;
    pt->pt_keysz_func = (size_t (*)(void *))strlen;
    pt->pt_malloc_func = fmalloc;
    pt->pt_free_func = free;
    for (i = 0; i < 1024; i++) {
        pn = pt->pt_malloc_func(sizeof(*pn));
        pn->pn_u.pn_node.pn_Cld[0] = pt->pt_list;
        pt->pt_list = pn;
    }
    return pt;
}

canonical_original_code:
struct ptrie *ptrie_new()
{
    int i;
    struct ptrie *pt;
    struct pnode *pn;
    pt = fmalloc(sizeof(*pt));
    pt->pt_root = ((void *)0);
    pt->pt_list = ((void *)0);
    pt->pt_size = 0;
    pt->pt_keysz = 0;
    pt->pt_keysz_func = (unsigned long (*)(void *))strlen;
    pt->pt_malloc_func = fmalloc;
    pt->pt_free_func = free;
    for (i = 0; i < 1024; i++) {
        pn = pt->pt_malloc_func(sizeof(*pn));
        pn->pn_u.pn_node.pn_Cld[0] = pt->pt_list;
        pt->pt_list = pn;
    }
    return pt;
}

return_type: struct ptrie { struct pnode { enum pn_type_t { PN_LEAF=0, PN_NODE=1 } pn_type; struct pnode *pn_up; union { struct { void *pn_Key; unsigned long pn_Keysz; void *pn_Val; unsigned long pn_Valsz; } pn_leaf; struct { int pn_Bit; struct pnode *pn_Cld[2]; } pn_node; } pn_u; } *pt_root; struct pnode *pt_list; unsigned long pt_size; unsigned int pt_parms; struct ptrie_iter { void *pn; void *root; } pt_iter; void *(*pt_malloc_func)(unsigned long); void (*pt_free_func)(void *); unsigned long pt_keysz; unsigned long (*pt_keysz_func)(void *key); } *


decompiled_code:
void ptrie_free()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void
ptrie_free(ptrie_t *ptrie)
{
    return;
}

canonical_original_code:
void ptrie_free(struct ptrie *ptrie)
{
    return;
}


original_code:
void
ptrie_add2(ptrie_t *pt, void *key, void *val, void **pnode)
{
    pnode_t *pn;
    pnode_t **lk;
    pnode_t *nnode;
    pnode_t *nleaf;
    size_t keysz;
    int diffbit;
    keysz = keysize(pt, key);
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        pt->pt_root = newcld(pt, key, keysz, val);
        pt->pt_root->pn_up = ((void *)0);
        pt->pt_size++;
        if (pnode)
            *pnode = pt->pt_root;
        return;
    }
    for (pn = pt->pt_root; pn->pn_type == PN_NODE; )
        pn = pn->pn_u.pn_node.pn_Cld[getbit(key, keysz, pn->pn_u.pn_node.pn_Bit)];
    diffbit = keycmp(key, keysz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz);
    if (diffbit == 0) {
        return;
    }
    lk = &pt->pt_root;
    pn = pt->pt_root;
    while (pn->pn_type == PN_NODE) {
        if (pn->pn_u.pn_node.pn_Bit > ((diffbit) < 0 ? -(diffbit) : (diffbit))) {
            break;
        } else {
            lk = &pn->pn_u.pn_node.pn_Cld[getbit(key, keysz, pn->pn_u.pn_node.pn_Bit)];
            pn = *lk;
        }
    }
    nleaf = newcld(pt, key, keysz, val);
    nnode = newpar(pt, diffbit, nleaf, pn);
    nleaf->pn_up = nnode;
    nnode->pn_up = pn->pn_up;
    pn->pn_up = nnode;
    *lk = nnode;
    pt->pt_size++;
    if (pnode)
        *pnode = nleaf;
    return;
}

canonical_original_code:
void ptrie_add2(struct ptrie *pt, void *key, void *val, void **pnode)
{
    struct pnode *pn;
    struct pnode **lk;
    struct pnode *nnode;
    struct pnode *nleaf;
    unsigned long keysz;
    int diffbit;
    keysz = keysize(pt, key);
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        pt->pt_root = newcld(pt, key, keysz, val);
        pt->pt_root->pn_up = ((void *)0);
        pt->pt_size++;
        if (pnode)
            *pnode = pt->pt_root;
        return;
    }
    for (pn = pt->pt_root; pn->pn_type == PN_NODE; )
        pn = pn->pn_u.pn_node.pn_Cld[getbit(key, keysz, pn->pn_u.pn_node.pn_Bit)];
    diffbit = keycmp(key, keysz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz);
    if (diffbit == 0) {
        return;
    }
    lk = &pt->pt_root;
    pn = pt->pt_root;
    while (pn->pn_type == PN_NODE) {
        if (pn->pn_u.pn_node.pn_Bit > ((diffbit) < 0 ? -(diffbit) : (diffbit))) {
            break;
        } else {
            lk = &pn->pn_u.pn_node.pn_Cld[getbit(key, keysz, pn->pn_u.pn_node.pn_Bit)];
            pn = *lk;
        }
    }
    nleaf = newcld(pt, key, keysz, val);
    nnode = newpar(pt, diffbit, nleaf, pn);
    nleaf->pn_up = nnode;
    nnode->pn_up = pn->pn_up;
    pn->pn_up = nnode;
    *lk = nnode;
    pt->pt_size++;
    if (pnode)
        *pnode = nleaf;
    return;
}

variable_types:
val
void *

variable_types:
pnode
void **

variable_types: struct pnode { enum pn_type_t { PN_LEAF=0, PN_NODE=1 } pn_type; struct pnode *pn_up; union { struct { void *pn_Key; unsigned long pn_Keysz; void *pn_Val; unsigned long pn_Valsz; } pn_leaf; struct { int pn_Bit; struct pnode *pn_Cld[2]; } pn_node; } pn_u; } **


decompiled_code:
__int64 __fastcall ptrie_add(__int64 *a1, unsigned __int8 *a2, __int64 a3)
{
return ptrie_add2(a1, a2, a3, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1, unsigned __int8 *a2, __int64 a3)
{
return func11(a1, a2, a3, 0LL);
}

original_code:
void
ptrie_add(ptrie_t *pt, void *key, void *val)
{
    ptrie_add2(pt, key, val, ((void *)0));
}

canonical_original_code:
void ptrie_add(struct ptrie *pt, void *key, void *val)
{
    ptrie_add2(pt, key, val, ((void *)0));
}


decompiled_code:
__int64 __fastcall ptrie_get(__int64 *a1, const void *a2)
{
__int64 result; // rax
__int64 v3; // r12
__int64 i; // rbx
_BOOL4 v5; // edx

if ( !a1[2] )
return 0LL;
result = *a1;
if ( *a1 )
{
v3 = keysize((__int64)a1, (__int64)a2);
for ( i = *a1; *(_DWORD *)i == 1; i = *(_QWORD *)(i + 8LL * (int)getbit((__int64)a2, v3, *(_DWORD *)(i + 16)) + 24) )
;
v5 = keyseq(a2, v3, *(const void **)(i + 16), *(_QWORD *)(i + 24));
result = 0LL;
if ( v5 )
result = *(_QWORD *)(i + 32);
}
return result;
}

original_code:
void *
ptrie_get(ptrie_t *pt, void *key)
{
    pnode_t *pn;
    size_t keysz;
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        return ((void *)0);
    }
    keysz = keysize(pt, key);
    for (pn = pt->pt_root; pn->pn_type == PN_NODE; )
        pn = pn->pn_u.pn_node.pn_Cld[getbit(key, keysz, pn->pn_u.pn_node.pn_Bit)];
    if (keyseq(key, keysz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz)) {
        return pn->pn_u.pn_leaf.pn_Val;
    }
    return ((void *)0);
}

canonical_original_code:
void *ptrie_get(struct ptrie *pt, void *key)
{
    struct pnode *pn;
    unsigned long keysz;
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        return ((void *)0);
    }
    keysz = keysize(pt, key);
    for (pn = pt->pt_root; pn->pn_type == PN_NODE; )
        pn = pn->pn_u.pn_node.pn_Cld[getbit(key, keysz, pn->pn_u.pn_node.pn_Bit)];
    if (keyseq(key, keysz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz)) {
        return pn->pn_u.pn_leaf.pn_Val;
    }
    return ((void *)0);
}


decompiled_code:
_BOOL8 __fastcall ptrie_haskey(__int64 *a1, const void *a2)
{
return ptrie_get(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(__int64 *a1, const void *a2)
{
return func13(a1, a2) != 0;
}

original_code:
int
ptrie_haskey(ptrie_t *pt, void *key)
{
    return ptrie_get(pt, key) != ((void *)0);
}

canonical_original_code:
int ptrie_haskey(struct ptrie *pt, void *key)
{
    return ptrie_get(pt, key) != ((void *)0);
}


original_code:
void *
ptrie_get_prefix(ptrie_t *pt, void *prefix, size_t nbits)
{
    pnode_t *pn;
    pnode_t *in;
    size_t pfxsz;
    int diffbit;
    pfxsz = keysize(pt, prefix);
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        return ((void *)0);
    }
    for (pn = pt->pt_root; pn->pn_type == PN_NODE; )
        pn = pn->pn_u.pn_node.pn_Cld[getbit(prefix, pfxsz, pn->pn_u.pn_node.pn_Bit)];
    diffbit = keycmp(prefix, pfxsz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz);
    if (diffbit == 0 || nbits < diffbit) {
        for (in = pn->pn_up; in && nbits < in->pn_u.pn_node.pn_Bit; in = pn->pn_up)
            pn = in;
    }
    return pn;
}

canonical_original_code:
void *ptrie_get_prefix(struct ptrie *pt, void *prefix, unsigned long nbits)
{
    struct pnode *pn;
    struct pnode *in;
    unsigned long pfxsz;
    int diffbit;
    pfxsz = keysize(pt, prefix);
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        return ((void *)0);
    }
    for (pn = pt->pt_root; pn->pn_type == PN_NODE; )
        pn = pn->pn_u.pn_node.pn_Cld[getbit(prefix, pfxsz, pn->pn_u.pn_node.pn_Bit)];
    diffbit = keycmp(prefix, pfxsz, pn->pn_u.pn_leaf.pn_Key, pn->pn_u.pn_leaf.pn_Keysz);
    if (diffbit == 0 || nbits < diffbit) {
        for (in = pn->pn_up; in && nbits < in->pn_u.pn_node.pn_Bit; in = pn->pn_up)
            pn = in;
    }
    return pn;
}

variable_types:
prefix
void *

variable_types:
nbits
unsigned long

variable_types:
pfxsz
unsigned long


original_code:
void
ptrie_del(ptrie_t *pt, void *key)
{
    size_t keysz;
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        return;
    }
    keysz = keysize(pt, key);
    pt->pt_root = ptrie_del0(pt, key, keysz, pt->pt_root);
}

canonical_original_code:
void ptrie_del(struct ptrie *pt, void *key)
{
    unsigned long keysz;
    if (pt->pt_size == 0 ||
        pt->pt_root == ((void *)0)) {
        return;
    }
    keysz = keysize(pt, key);
    pt->pt_root = ptrie_del0(pt, key, keysz, pt->pt_root);
}

variable_types:
key
void *

variable_types:
keysz
unsigned long


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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 16);
return result;
}

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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 16);
return result;
}

original_code:
int
ptrie_size(ptrie_t *pt)
{
    return pt ? pt->pt_size : 0;
}

canonical_original_code:
int ptrie_size(struct ptrie *pt)
{
    return pt ? pt->pt_size : 0;
}


original_code:
int
ptrie_iter_next(ptrie_t *pt, ptrie_iter_t *ptit, void **key, void **val)
{
    pnode_t *pn;
    if (! ptit)
        ptit = &pt->pt_iter;
    if (! ptit->pn)
        return 0;
    pn = ptit->pn;
    if (key) *key = pn->pn_u.pn_leaf.pn_Key;
    if (val) *val = pn->pn_u.pn_leaf.pn_Val;
    if (pn != ptit->root && ((pn) == (pn)->pn_up->pn_u.pn_node.pn_Cld[1])) {
        for (pn = pn->pn_up; pn != ptit->root; pn = pn->pn_up)
            if (((pn) == (pn)->pn_up->pn_u.pn_node.pn_Cld[0]))
                break;
    }
    if (pn == ptit->root) {
        ptit->pn = ((void *)0);
        return 1;
    }
    pn = pn->pn_up->pn_u.pn_node.pn_Cld[1];
    while (pn->pn_type == PN_NODE)
        pn = pn->pn_u.pn_node.pn_Cld[0];
    ptit->pn = pn;
    return 1;
}

canonical_original_code:
int ptrie_iter_next(struct ptrie *pt, struct ptrie_iter *ptit, void **key, void **val)
{
    struct pnode *pn;
    if (! ptit)
        ptit = &pt->pt_iter;
    if (! ptit->pn)
        return 0;
    pn = ptit->pn;
    if (key) *key = pn->pn_u.pn_leaf.pn_Key;
    if (val) *val = pn->pn_u.pn_leaf.pn_Val;
    if (pn != ptit->root && ((pn) == (pn)->pn_up->pn_u.pn_node.pn_Cld[1])) {
        for (pn = pn->pn_up; pn != ptit->root; pn = pn->pn_up)
            if (((pn) == (pn)->pn_up->pn_u.pn_node.pn_Cld[0]))
                break;
    }
    if (pn == ptit->root) {
        ptit->pn = ((void *)0);
        return 1;
    }
    pn = pn->pn_up->pn_u.pn_node.pn_Cld[1];
    while (pn->pn_type == PN_NODE)
        pn = pn->pn_u.pn_node.pn_Cld[0];
    ptit->pn = pn;
    return 1;
}

variable_types:
ptit
struct ptrie_iter *

variable_types:
key
void **

variable_types:
val
void **


main

repo: thborges/datecmd

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int16 v4; // r12
__int16 v5; // r14
__int16 v6; // r13
const char *v7; // r15
int v8; // er9
int v9; // er10
int result; // eax
struct tm *v11; // rcx
char v12[88]; // [rsp+0h] [rbp-98h] BYREF
time_t timer; // [rsp+58h] [rbp-40h] BYREF

if ( argc == 2 )
{
if ( !strcmp(argv[1], "/?") )
{
LABEL_14:
printf(usage);
return 1;
}
}
else if ( argc <= 1 )
{
time(&timer);
v11 = localtime(&timer);
v4 = 0;
v7 = "%Y.%m.%d %H:%M:%S";
goto LABEL_25;
}
v3 = 1;
v4 = 0;
v5 = 0;
v6 = 0;
v7 = "%Y.%m.%d %H:%M:%S";
v8 = 1;
v9 = 0;
do
{
if ( !strcmp(argv[(__int16)v3], "/e") )
{
v4 = 1;
}
else if ( !strcmp(argv[(__int16)v3], "/d") )
{
v6 = 1;
}
else if ( !strcmp(argv[(__int16)v3], "/t") )
{
v5 = 1;
}
else if ( !strcmp(argv[(__int16)v3], "/f") )
{
if ( v8 + 1 >= argc )
goto LABEL_14;
v3 = v9 + 2;
v7 = argv[(__int16)(v9 + 2)];
}
v9 = v3++;
v8 = (__int16)v3;
}
while ( (__int16)v3 < argc );
time(&timer);
v11 = localtime(&timer);
if ( v6 )
{
strftime(v12, 0x50uLL, "%Y%m%d", v11);
goto LABEL_21;
}
if ( v5 )
{
strftime(v12, 0x50uLL, "%H%M%S", v11);
goto LABEL_21;
}
LABEL_25:
strftime(v12, 0x50uLL, v7, v11);
LABEL_21:
printf(v12);
result = 0;
if ( v4 )
{
puts("\r");
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
 char *format = "%Y.%m.%d %H:%M:%S";
 short date_only = 0;
 short time_only = 0;
 short crlf = 0;
    short i = 0;
 time_t rawtime;
 struct tm *ct;
 char buffer[80];
 if ((argc == 2) && (strcmp(argv[1], "/?") == 0)) {
  goto usage;
 }
 i=0;
 while (++i < argc) {
  if (strcmp(argv[i], "/e") == 0) {
   crlf = 1;
   continue;
  }
  if (strcmp(argv[i], "/d") == 0) {
   date_only = 1;
   continue;
  }
  if (strcmp(argv[i], "/t") == 0) {
   time_only = 1;
   continue;
  }
  if (strcmp(argv[i], "/f") == 0) {
   if (argc <= i+1)
    goto usage;
   format = argv[++i];
   continue;
  }
 };
 time(&rawtime);
 ct = localtime(&rawtime);
 if (date_only)
  strftime(buffer, 80, "%Y%m%d", ct);
 else if (time_only)
  strftime(buffer, 80, "%H%M%S", ct);
 else
  strftime(buffer, 80, format, ct);
 printf(buffer);
 if (crlf)
  printf("\r\n");
 return 0;
usage:
 printf(usage);
 return 1;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 char *format = "%Y.%m.%d %H:%M:%S";
 short date_only = 0;
 short time_only = 0;
 short crlf = 0;
    short i = 0;
 long rawtime;
 struct tm *ct;
 char buffer[80];
 if ((argc == 2) && (strcmp(argv[1], "/?") == 0)) {
  goto usage;
 }
 i=0;
 while (++i < argc) {
  if (strcmp(argv[i], "/e") == 0) {
   crlf = 1;
   continue;
  }
  if (strcmp(argv[i], "/d") == 0) {
   date_only = 1;
   continue;
  }
  if (strcmp(argv[i], "/t") == 0) {
   time_only = 1;
   continue;
  }
  if (strcmp(argv[i], "/f") == 0) {
   if (argc <= i+1)
    goto usage;
   format = argv[++i];
   continue;
  }
 };
 time(&rawtime);
 ct = localtime(&rawtime);
 if (date_only)
  strftime(buffer, 80, "%Y%m%d", ct);
 else if (time_only)
  strftime(buffer, 80, "%H%M%S", ct);
 else
  strftime(buffer, 80, format, ct);
 printf(buffer);
 if (crlf)
  printf("\r\n");
 return 0;
usage:
 printf(usage);
 return 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
format
char *

variable_types: crlf short

variable_types: i short

variable_types: rawtime long

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

variable_types:
buffer
char [80]


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !a1 )
_assert_fail("size != 0", "common.h", 0x11u, "xmalloc");
if ( !result )
{
fwrite("malloc call failed - this is pretty bad\n", 1uLL, 0x28uLL, stderr);
exit(-2);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !a1 )
_assert_fail("size != 0", "common.h", 0x11u, "xmalloc");
if ( !result )
{
fwrite("malloc call failed - this is pretty bad\n", 1uLL, 0x28uLL, stderr);
exit(-2);
}
return result;
}

original_code:
inline static void *xmalloc(size_t size) {
    void *ptr = malloc(size);
    ((void) sizeof ((size != 0) ? 1 : 0), __extension__ ({ if (size != 0) ; else __assert_fail ("size != 0", "common.h", 17, __extension__ __PRETTY_FUNCTION__); }));
    if(!ptr) {
        fprintf(stderr, "malloc call failed - this is pretty bad\n");
        exit(-2);
    }
    return ptr;
}

canonical_original_code:
inline static void *xmalloc(unsigned long size) {
    void *ptr = malloc(size);
    ((void) sizeof ((size != 0) ? 1 : 0), __extension__ ({ if (size != 0) ; else __assert_fail ("size != 0", "common.h", 17, __extension__ __PRETTY_FUNCTION__); }));
    if(!ptr) {
        fprintf(stderr, "malloc call failed - this is pretty bad\n");
        exit(-2);
    }
    return ptr;
}

variable_types:
size
unsigned long

variable_types:
ptr
void *


decompiled_code:
void __fastcall aio_buffer_free(void *ptr)
{
int v2; // edi

v2 = *((_DWORD *)ptr + 10);
if ( v2 != -1 )
close(v2);
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
int v2; // edi

v2 = *((_DWORD *)ptr + 10);
if ( v2 != -1 )
close(v2);
free(*(void **)ptr);
free(ptr);
}

original_code:
void aio_buffer_free(aio_buffer *buffer) {
  if(buffer->fd != -1)
    close(buffer->fd);
  free(buffer->data);
  free(buffer);
}

canonical_original_code:
void aio_buffer_free(struct aio_buffer *buffer) {
  if(buffer->fd != -1)
    close(buffer->fd);
  free(buffer->data);
  free(buffer);
}

variable_types: struct aio_buffer { char *data; unsigned long size; char *start; char *end; unsigned long limit; int fd; char *linestart; char *linelimit; } *


decompiled_code:
int __fastcall aio_buffer_close(__int64 a1)
{
int v2; // edi
int result; // eax

v2 = *(_DWORD *)(a1 + 40);
if ( v2 != -1 )
result = close(v2);
*(_DWORD *)(a1 + 40) = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
int v2; // edi
int result; // eax

v2 = *(_DWORD *)(a1 + 40);
if ( v2 != -1 )
result = close(v2);
*(_DWORD *)(a1 + 40) = -1;
return result;
}

original_code:
void aio_buffer_close(aio_buffer *buffer) {
  if(buffer->fd != -1)
    close(buffer->fd);
  buffer->fd = -1;
}

canonical_original_code:
void aio_buffer_close(struct aio_buffer *buffer) {
  if(buffer->fd != -1)
    close(buffer->fd);
  buffer->fd = -1;
}

user_defined_types: struct aio_buffer { char *data; unsigned long size; char *start; char *end; unsigned long limit; int fd; char *linestart; char *linelimit; }


decompiled_code:
__int64 __fastcall aio_buffer_fill(__int64 a1, size_t a2, _QWORD *a3)
{
size_t v3; // r12
__int64 v4; // rax
char *v5; // r13
const void *v6; // rcx
ssize_t v7; // rax
ssize_t v8; // rbp

v3 = *(_QWORD *)(a1 + 32) - a2;
if ( !v3 )
_assert_fail("readsize > 0", "input.c", 0x50u, "aio_buffer_fill");
v4 = *(_QWORD *)(a1 + 16);
v5 = (char *)(v4 + a2);
v6 = (const void *)(*(_QWORD *)(a1 + 24) - a2);
*a3 = v4 - (_QWORD)v6;
if ( a2 )
memmove(*(void **)(a1 + 16), v6, a2);
while ( 1 )
{
v7 = read(*(_DWORD *)(a1 + 40), v5, v3);
v8 = v7;
if ( v7 >= 0 )
break;
if ( *_errno_location() != 4 )
goto LABEL_6;
}
if ( v7 )
{
LABEL_6:
*(_QWORD *)(a1 + 24) = &v5[v8];
return 0LL;
}
return 4294959996LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, size_t a2, _QWORD *a3)
{
size_t v3; // r12
__int64 v4; // rax
char *v5; // r13
const void *v6; // rcx
ssize_t v7; // rax
ssize_t v8; // rbp

v3 = *(_QWORD *)(a1 + 32) - a2;
if ( !v3 )
_assert_fail("readsize > 0", "input.c", 0x50u, "aio_buffer_fill");
v4 = *(_QWORD *)(a1 + 16);
v5 = (char *)(v4 + a2);
v6 = (const void *)(*(_QWORD *)(a1 + 24) - a2);
*a3 = v4 - (_QWORD)v6;
if ( a2 )
memmove(*(void **)(a1 + 16), v6, a2);
while ( 1 )
{
v7 = read(*(_DWORD *)(a1 + 40), v5, v3);
v8 = v7;
if ( v7 >= 0 )
break;
if ( *_errno_location() != 4 )
goto LABEL_6;
}
if ( v7 )
{
LABEL_6:
*(_QWORD *)(a1 + 24) = &v5[v8];
return 0LL;
}
return 4294959996LL;
}

original_code:
int aio_buffer_fill(aio_buffer *buffer, size_t keep, off_t *adjust) {
  size_t readsize = buffer->limit - keep;
  ((void) sizeof ((readsize > 0) ? 1 : 0), __extension__ ({ if (readsize > 0) ; else __assert_fail ("readsize > 0", "input.c", 80, __extension__ __PRETTY_FUNCTION__); }));
  char *readstart = buffer->start + keep;
  char *keepstart = buffer->end - keep;
  *adjust = buffer->start - keepstart;
  if(keep) {
    memmove(buffer->start, keepstart, keep);
  }
  ssize_t bytesread;
  while((bytesread = read(buffer->fd, readstart, readsize)) < 0 && (*__errno_location ()) == 4)
    continue;
  if(bytesread == 0)
    return (-7300);
  buffer->end = readstart + bytesread;
  return 0;
}

canonical_original_code:
int aio_buffer_fill(struct aio_buffer *buffer, unsigned long keep, long *adjust) {
  unsigned long readsize = buffer->limit - keep;
  ((void) sizeof ((readsize > 0) ? 1 : 0), __extension__ ({ if (readsize > 0) ; else __assert_fail ("readsize > 0", "input.c", 80, __extension__ __PRETTY_FUNCTION__); }));
  char *readstart = buffer->start + keep;
  char *keepstart = buffer->end - keep;
  *adjust = buffer->start - keepstart;
  if(keep) {
    memmove(buffer->start, keepstart, keep);
  }
  long bytesread;
  while((bytesread = read(buffer->fd, readstart, readsize)) < 0 && (*__errno_location ()) == 4)
    continue;
  if(bytesread == 0)
    return (-7300);
  buffer->end = readstart + bytesread;
  return 0;
}

variable_types:
keep
unsigned long

variable_types:
adjust
long *

variable_types:
readsize
unsigned long

variable_types:
readstart
char *

variable_types:
keepstart
char *

variable_types: bytesread long


decompiled_code:
__int64 __fastcall aio_buffer_open(__int64 a1, const char *a2)
{
int v2; // eax
__int64 result; // rax

v2 = open(a2, 0);
if ( v2 == -1 )
result = 4294960195LL;
else
result = aio_buffer_init(a1, v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
int v2; // eax
__int64 result; // rax

v2 = open(a2, 0);
if ( v2 == -1 )
result = 4294960195LL;
else
result = func5(a1, v2);
return result;
}

original_code:
int aio_buffer_open(aio_buffer *buffer, const char *path) {
  int fd = open(path, 00);
  if(fd == -1)
    return (-7101);
  return aio_buffer_init(buffer, fd);
}

canonical_original_code:
int aio_buffer_open(struct aio_buffer *buffer, char *path) {
  int fd = open(path, 00);
  if(fd == -1)
    return (-7101);
  return aio_buffer_init(buffer, fd);
}

variable_types:
path
char *

variable_types: fd int


decompiled_code:
__int64 __fastcall aio_buffer_loadline(_QWORD *a1)
{
char *v1; // r12
char *v2; // rbx
char *v3; // rax
unsigned int v4; // edx
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = (char *)(a1[7] + 1LL);
v6[0] = 0LL;
if ( *v1 == (unsigned __int8)aio_eol )
{
v2 = v1;
v4 = 0;
}
else
{
v2 = v1;
do
{
v3 = v2;
if ( a1[3] <= (unsigned __int64)v2 )
{
v4 = aio_buffer_fill((__int64)a1, v2 - v1, v6);
v1 += v6[0];
v3 = &v2[v6[0]];
if ( v4 )
{
v2 += v6[0];
goto LABEL_8;
}
}
v2 = v3 + 1;
}
while ( v3[1] != (unsigned __int8)aio_eol );
v4 = 0;
}
LABEL_8:
a1[6] = v1;
a1[7] = v2;
return v4;
}

original_code:
int aio_buffer_loadline(aio_buffer *buffer) {
  char *linestart = buffer->linestart;
  char *linelimit = buffer->linelimit;
  linestart = linelimit + 1;
  linelimit = linestart;
  off_t adjust = 0;
  int res = 0;
  for(; *linelimit != aio_eol; ++linelimit) {
    if(linelimit >= buffer->end) {
      res = aio_buffer_fill(buffer, linelimit - linestart, &adjust);
      linestart += adjust;
      linelimit += adjust;
      if(res != 0)
        break;
    }
  }
  buffer->linestart = linestart;
  buffer->linelimit = linelimit;
  if(res != 0)
    return res;
  return 0;
}

canonical_original_code:
int aio_buffer_loadline(struct aio_buffer *buffer) {
  char *linestart = buffer->linestart;
  char *linelimit = buffer->linelimit;
  linestart = linelimit + 1;
  linelimit = linestart;
  long adjust = 0;
  int res = 0;
  for(; *linelimit != aio_eol; ++linelimit) {
    if(linelimit >= buffer->end) {
      res = aio_buffer_fill(buffer, linelimit - linestart, &adjust);
      linestart += adjust;
      linelimit += adjust;
      if(res != 0)
        break;
    }
  }
  buffer->linestart = linestart;
  buffer->linelimit = linelimit;
  if(res != 0)
    return res;
  return 0;
}

variable_types:
linestart
char *

variable_types:
linelimit
char *

variable_types: adjust long

variable_types: res int


decompiled_code:
ssize_t __fastcall aio_buffer_writeline(__int64 a1, int a2)
{
write(a2, *(const void **)(a1 + 48), *(_QWORD *)(a1 + 56) - *(_QWORD *)(a1 + 48));
return write(a2, "\n", 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func8(__int64 a1, int a2)
{
write(a2, *(const void **)(a1 + 48), *(_QWORD *)(a1 + 56) - *(_QWORD *)(a1 + 48));
return write(a2, "\n", 1uLL);
}

original_code:
void aio_buffer_writeline(aio_buffer *buffer, int fdout) {
  write(fdout, buffer->linestart, (size_t) (buffer->linelimit - buffer->linestart));
  write(fdout, "\n", 1);
}

canonical_original_code:
void aio_buffer_writeline(struct aio_buffer *buffer, int fdout) {
  write(fdout, buffer->linestart, (unsigned long) (buffer->linelimit - buffer->linestart));
  write(fdout, "\n", 1);
}

variable_types: fdout int


decompiled_code:
__int64 __fastcall aio_buffer_setlinelimit(_QWORD *a1)
{
char *v1; // rbx
__int64 v2; // rax
char *v3; // rax
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v5[0] = 0LL;
v1 = (char *)(a1[6] + 1LL);
if ( *v1 != (unsigned __int8)aio_eol )
{
do
{
v3 = v1;
if ( (char *)a1[3] == v1 )
{
if ( (unsigned int)aio_buffer_fill((__int64)a1, (size_t)&v1[-a1[6]], v5) )
break;
v2 = v5[0];
a1[6] += v5[0];
v3 = &v1[v2];
}
v1 = v3 + 1;
}
while ( v3[1] != (unsigned __int8)aio_eol );
}
a1[7] = v1;
return 0LL;
}

original_code:
int aio_buffer_setlinelimit(aio_buffer *buffer) {
  char *limit;
  off_t adj = 0;
  for(limit = buffer->linestart + 1; *limit != aio_eol; ++limit) {
    if(limit == buffer->end) {
      if(aio_buffer_fill(buffer, limit - buffer->linestart, &adj) != 0)
        break;
      buffer->linestart += adj;
      limit += adj;
    }
  }
  buffer->linelimit = limit;
  return 0;
}

canonical_original_code:
int aio_buffer_setlinelimit(struct aio_buffer *buffer) {
  char *limit;
  long adj = 0;
  for(limit = buffer->linestart + 1; *limit != aio_eol; ++limit) {
    if(limit == buffer->end) {
      if(aio_buffer_fill(buffer, limit - buffer->linestart, &adj) != 0)
        break;
      buffer->linestart += adj;
      limit += adj;
    }
  }
  buffer->linelimit = limit;
  return 0;
}

variable_types:
limit
char *

variable_types: adj long


loadip

decompiled_code:
int __fastcall loadip(const char *a1)
{
int v1; // eax
int result; // eax

v1 = strlen(a1);
result = addip_str(iptree, a1, &a1[v1]);
if ( verbose )
{
switch ( result )
{
case -1002:
result = fprintf(stderr, "Warning: The IP %s is invalid.\n", a1);
break;
case -1001:
result = fprintf(stderr, "Warning: The CIDR block %s is invalid.\n", a1);
break;
case -1100:
result = fprintf(stderr, "Warning: No IP found in \"%s\".\n", a1);
break;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
int v1; // eax
int result; // eax

v1 = strlen(a1);
result = addip_str(iptree, a1, &a1[v1]);
if ( verbose )
{
switch ( result )
{
case -1002:
result = fprintf(stderr, "Warning: The IP %s is invalid.\n", a1);
break;
case -1001:
result = fprintf(stderr, "Warning: The CIDR block %s is invalid.\n", a1);
break;
case -1100:
result = fprintf(stderr, "Warning: No IP found in \"%s\".\n", a1);
break;
}
}
return result;
}

original_code:
static void loadip(void *arg) {
  char *ip = (char *)arg;
  unsigned int len = strlen(ip);
  int res = addip_str(iptree, ip, (ip + len));
  if(verbose) {
    switch(res) {
      case -1002:
      fprintf(stderr, "Warning: The IP %s is invalid.\n", ip);
      break;
      case -1001:
      fprintf(stderr, "Warning: The CIDR block %s is invalid.\n", ip);
      break;
      case -1100:
      fprintf(stderr, "Warning: No IP found in \"%s\".\n", ip);
      break;
    }
  }
}

variable_types:
arg
void *

variable_types:
ip
char *

variable_types:
len
unsigned int


loadlist

decompiled_code:
unsigned int __fastcall loadlist(const char *a1)
{
unsigned int result; // eax
int v2; // ebx
int v3; // eax

result = aio_buffer_open(buffer, a1);
if ( result )
{
if ( verbose )
result = fprintf(stderr, "Warning: could not open file %s, error code: %d.\n", a1, result);
}
else
{
while ( 1 )
{
result = aio_buffer_loadline(buffer);
v2 = result;
if ( result )
break;
v3 = addip_str(iptree, *(_QWORD *)(buffer + 48), *(_QWORD *)(buffer + 56));
if ( verbose )
{
switch ( v3 )
{
case -1002:
fprintf(
stderr,
"Warning: The IP address on the line below is invalid.\n%.*s\n",
*(_QWORD *)(buffer + 56) - *(_QWORD *)(buffer + 48),
*(const char **)(buffer + 48));
break;
case -1001:
fprintf(
stderr,
"Warning: The CIDR block on the line below is invalid.\n%.*s\n",
*(_QWORD *)(buffer + 56) - *(_QWORD *)(buffer + 48),
*(const char **)(buffer + 48));
break;
case -1100:
fprintf(
stderr,
"Warning: The line below does not contain an IP address.\n%.*s\n",
*(_QWORD *)(buffer + 56) - *(_QWORD *)(buffer + 48),
*(const char **)(buffer + 48));
break;
}
}
}
if ( result != -7300 )
{
fprintf(stderr, "IO Error code %d.\n", result);
exit(v2);
}
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func2(const char *a1)
{
unsigned int result; // eax
int v2; // ebx
int v3; // eax

result = aio_buffer_open(buffer, a1);
if ( result )
{
if ( verbose )
result = fprintf(stderr, "Warning: could not open file %s, error code: %d.\n", a1, result);
}
else
{
while ( 1 )
{
result = aio_buffer_loadline(buffer);
v2 = result;
if ( result )
break;
v3 = addip_str(iptree, *(_QWORD *)(buffer + 48), *(_QWORD *)(buffer + 56));
if ( verbose )
{
switch ( v3 )
{
case -1002:
fprintf(
stderr,
"Warning: The IP address on the line below is invalid.\n%.*s\n",
*(_QWORD *)(buffer + 56) - *(_QWORD *)(buffer + 48),
*(const char **)(buffer + 48));
break;
case -1001:
fprintf(
stderr,
"Warning: The CIDR block on the line below is invalid.\n%.*s\n",
*(_QWORD *)(buffer + 56) - *(_QWORD *)(buffer + 48),
*(const char **)(buffer + 48));
break;
case -1100:
fprintf(
stderr,
"Warning: The line below does not contain an IP address.\n%.*s\n",
*(_QWORD *)(buffer + 56) - *(_QWORD *)(buffer + 48),
*(const char **)(buffer + 48));
break;
}
}
}
if ( result != -7300 )
{
fprintf(stderr, "IO Error code %d.\n", result);
exit(v2);
}
}
return result;
}

original_code:
static void loadlist(void *arg) {
  char *path = (char *)arg;
  int res = 0;
  if((res = aio_buffer_open(buffer, path)) != 0) {
    if(verbose)
      fprintf(stderr, "Warning: could not open file %s, error code: %d.\n", path, res);
    return;
  }
  while((res = aio_buffer_loadline(buffer)) == 0) {
    res = addip_str(iptree, buffer->linestart, buffer->linelimit);
    if(verbose) {
      switch(res) {
        case -1002:
        fprintf(stderr, "Warning: The IP address on the line below is invalid.\n%.*s\n", (int) (buffer->linelimit - buffer->linestart), buffer->linestart);
        break;
        case -1001:
        fprintf(stderr, "Warning: The CIDR block on the line below is invalid.\n%.*s\n", (int) (buffer->linelimit - buffer->linestart), buffer->linestart);
        break;
        case -1100:
        fprintf(stderr, "Warning: The line below does not contain an IP address.\n%.*s\n", (int) (buffer->linelimit - buffer->linestart), buffer->linestart);
        break;
      }
    }
  }
  if(res != (-7300)) {
    fprintf(stderr, "IO Error code %d.\n", res);
    exit(res);
  } else {
    return;
  }
}


decompiled_code:
void __noreturn print_usage()
{
puts(
"Usage: ipscan [OPTION]...\n"
"Search for IP addresses or CIDR blocks in STDIN and print out matched lines.\n"
"\n"
"Loading IP lists:\n"
" -i, --ip-list FILE\t\tload newline-separated list of IP addresses (CIDR notation supported)\n"
" -I, --ip-search IP\t\tadd the IP to the list of IP addresses searched for (CIDR notation is supported)\n"
"\n"
"Search options:\n"
" -v, --invert-match\t\tinstead of printing lines that match the IP list, print ones that don't\n"
" -p, --match-position IDX\tinstead of checking against the first IP on the line, check against the IDXth\n"
"\t\t\t\tSupports negative IDX, counting from right instead from left.\n"
"\t\t\t\t(-1 = last IP, 1 = first IP, 0 = any position; default: 0)\n"
"\n"
"Output control:\n"
" --dump-ips\t\t\tinstead of running the search dump the computed CIDR blocks to STDOUT\n"
" --verbose\t\t\tprint additional messages to STDERR (default)\n"
" --quiet\t\t\tdon't print messages to STDERR\n"
"\n"
"Miscellaneous:\n"
" -V, --version\t\t\tprint version information and exit\n"
" -h, --help\t\t\tprint this message and exit\n"
"\n"
"Examples:\n"
"# Find all communication where neither source nor destination are in a private range:\n"
"> cat /var/syslog/* | ipscan -v -I 10.0.0.0/8 -I 192.168.0.0/16 -I 172.16.0.0/12 -p 0\n"
"# Find all communication originating from China:\n"
"> cat /var/syslog/* | ipscan -i chinese_ranges.txt -p 0\n"
"\n"
"# Simplify a list of IP ranges:\n"
"> ipscan -I 10.0.0.0/24 -I 10.0.1.0/24 --dump-ips\n"
"\t# outputs: 10.0.0.0/23");
exit(0);
}

canonical_decompiled_code:
void __noreturn func3()
{
puts(
"Usage: ipscan [OPTION]...\n"
"Search for IP addresses or CIDR blocks in STDIN and print out matched lines.\n"
"\n"
"Loading IP lists:\n"
" -i, --ip-list FILE\t\tload newline-separated list of IP addresses (CIDR notation supported)\n"
" -I, --ip-search IP\t\tadd the IP to the list of IP addresses searched for (CIDR notation is supported)\n"
"\n"
"Search options:\n"
" -v, --invert-match\t\tinstead of printing lines that match the IP list, print ones that don't\n"
" -p, --match-position IDX\tinstead of checking against the first IP on the line, check against the IDXth\n"
"\t\t\t\tSupports negative IDX, counting from right instead from left.\n"
"\t\t\t\t(-1 = last IP, 1 = first IP, 0 = any position; default: 0)\n"
"\n"
"Output control:\n"
" --dump-ips\t\t\tinstead of running the search dump the computed CIDR blocks to STDOUT\n"
" --verbose\t\t\tprint additional messages to STDERR (default)\n"
" --quiet\t\t\tdon't print messages to STDERR\n"
"\n"
"Miscellaneous:\n"
" -V, --version\t\t\tprint version information and exit\n"
" -h, --help\t\t\tprint this message and exit\n"
"\n"
"Examples:\n"
"# Find all communication where neither source nor destination are in a private range:\n"
"> cat /var/syslog/* | ipscan -v -I 10.0.0.0/8 -I 192.168.0.0/16 -I 172.16.0.0/12 -p 0\n"
"# Find all communication originating from China:\n"
"> cat /var/syslog/* | ipscan -i chinese_ranges.txt -p 0\n"
"\n"
"# Simplify a list of IP ranges:\n"
"> ipscan -I 10.0.0.0/24 -I 10.0.1.0/24 --dump-ips\n"
"\t# outputs: 10.0.0.0/23");
exit(0);
}

original_code:
static void print_usage() {
  printf(
    "Usage: ipscan [OPTION]...\n"
    "Search for IP addresses or CIDR blocks in STDIN and print out matched lines.\n"
    "\nLoading IP lists:\n"
    "  -i, --ip-list FILE\t\tload newline-separated list of IP addresses (CIDR notation supported)\n"
    "  -I, --ip-search IP\t\tadd the IP to the list of IP addresses searched for (CIDR notation is supported)\n"
    "\nSearch options:\n"
    "  -v, --invert-match\t\tinstead of printing lines that match the IP list, print ones that don't\n"
    "  -p, --match-position IDX\tinstead of checking against the first IP on the line, check against the IDXth\n"
    "\t\t\t\tSupports negative IDX, counting from right instead from left.\n"
    "\t\t\t\t(-1 = last IP, 1 = first IP, 0 = any position; default: 0)\n"
    "\nOutput control:\n"
    "  --dump-ips\t\t\tinstead of running the search dump the computed CIDR blocks to STDOUT\n"
    "  --verbose\t\t\tprint additional messages to STDERR (default)\n"
    "  --quiet\t\t\tdon't print messages to STDERR\n"
    "\nMiscellaneous:\n"
    "  -V, --version\t\t\tprint version information and exit\n"
    "  -h, --help\t\t\tprint this message and exit\n"
    "\nExamples:\n"
    "# Find all communication where neither source nor destination are in a private range:\n"
    "> cat /var/syslog/* | ipscan -v -I 10.0.0.0/8 -I 192.168.0.0/16 -I 172.16.0.0/12 -p 0\n"
    "# Find all communication originating from China:\n"
    "> cat /var/syslog/* | ipscan -i chinese_ranges.txt -p 0\n\n"
    "# Simplify a list of IP ranges:\n"
    "> ipscan -I 10.0.0.0/24 -I 10.0.1.0/24 --dump-ips\n"
    "\t# outputs: 10.0.0.0/23\n"
    );
  exit(0);
}


decompiled_code:
void __noreturn print_version()
{
printf("ipscan %d.%d.%d\n\n", 0LL, 9LL, 0LL);
exit(0);
}

canonical_decompiled_code:
void __noreturn func4()
{
printf("ipscan %d.%d.%d\n\n", 0LL, 9LL, 0LL);
exit(0);
}

original_code:
static void print_version() {
  printf(
    "ipscan %d.%d.%d\n\n",
    0, 9, 0
  );
  exit(0);
}


xmalloc

canonical_decompiled_code:
void *__fastcall func5(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !a1 )
_assert_fail("size != 0", "common.h", 0x11u, "xmalloc");
if ( !result )
{
fwrite("malloc call failed - this is pretty bad\n", 1uLL, 0x28uLL, stderr);
exit(-2);
}
return result;
}

variable_types:
size
unsigned long

variable_types:
ptr
void *