decompiled_code:
__int64 __fastcall direction_pos(__int64 a1, unsigned int a2)
{
int v2; // edx
unsigned int v3; // eax
__int64 v4; // rdi
__int64 v5; // rcx
unsigned int v6; // edi
unsigned int v7; // edx
unsigned int v9; // edi

v2 = a1;
v3 = a1;
v4 = a1 >> 32;
v5 = (unsigned int)v4;
if ( a2 == 2 )
{
v5 = (unsigned int)(v4 - 1);
}
else if ( a2 > 2 )
{
v9 = v4 + 1;
if ( a2 == 3 )
v5 = v9;
}
else
{
v6 = v2 + 1;
v7 = v2 - 1;
v3 = v6;
if ( !a2 )
v3 = v7;
}
return (v5 << 32) | v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
int v2; // edx
unsigned int v3; // eax
__int64 v4; // rdi
__int64 v5; // rcx
unsigned int v6; // edi
unsigned int v7; // edx
unsigned int v9; // edi

v2 = a1;
v3 = a1;
v4 = a1 >> 32;
v5 = (unsigned int)v4;
if ( a2 == 2 )
{
v5 = (unsigned int)(v4 - 1);
}
else if ( a2 > 2 )
{
v9 = v4 + 1;
if ( a2 == 3 )
v5 = v9;
}
else
{
v6 = v2 + 1;
v7 = v2 - 1;
v3 = v6;
if ( !a2 )
v3 = v7;
}
return (v5 << 32) | v3;
}

original_code:
pos_t direction_pos(pos_t pos, dir_t direction)
{
    switch (direction)
    {
        case UP:
            pos.y--;
            break;
        case DOWN:
            pos.y++;
            break;
        case LEFT:
            pos.x--;
            break;
        case RIGHT:
            pos.x++;
            break;
    }
    return (pos);
}

canonical_original_code:
struct pos_t direction_pos(struct pos_t pos, enum direction_e direction)
{
    switch (direction)
    {
        case UP:
            pos.y--;
            break;
        case DOWN:
            pos.y++;
            break;
        case LEFT:
            pos.x--;
            break;
        case RIGHT:
            pos.x++;
            break;
    }
    return (pos);
}

variable_types:
pos
struct pos_t

variable_types: enum direction_e { LEFT=0, RIGHT=1, UP=2, DOWN=3 }

return_type: struct pos_t { int x; int y; }


repo: Sevauk/libsquare

decompiled_code:
int __fastcall print_grid(__int64 (__fastcall *a1)(_QWORD), __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
int result; // eax
int v9; // er14
int v10; // er13
__int64 v11; // rbx
char v12; // al

result = HIDWORD(a8);
if ( SHIDWORD(a8) > 0 )
{
v9 = 0;
v10 = 0;
do
{
if ( (int)a8 > 0 )
{
v11 = 8LL * v9;
do
{
v12 = a1(*(_QWORD *)(a7 + v11));
putchar(v12);
v11 += 8LL;
}
while ( v11 != 8 * ((unsigned int)a8 + (__int64)v9) );
}
result = putchar(10);
++v10;
v9 += a8;
}
while ( v10 != HIDWORD(a8) );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 (__fastcall *a1)(_QWORD), __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
int result; // eax
int v9; // er14
int v10; // er13
__int64 v11; // rbx
char v12; // al

result = HIDWORD(a8);
if ( SHIDWORD(a8) > 0 )
{
v9 = 0;
v10 = 0;
do
{
if ( (int)a8 > 0 )
{
v11 = 8LL * v9;
do
{
v12 = a1(*(_QWORD *)(a7 + v11));
putchar(v12);
v11 += 8LL;
}
while ( v11 != 8 * ((unsigned int)a8 + (__int64)v9) );
}
result = putchar(10);
++v10;
v9 += a8;
}
while ( v10 != HIDWORD(a8) );
}
return result;
}

original_code:
void print_grid(grid_t grid, char (*skin)(cell_t cell))
{
    int i, j;
    for (i = 0; i < grid.sizeY; i++)
    {
 for (j = 0; j < grid.sizeX; j++)
 {
     printf("%c", skin(grid.data[((i) * (grid.sizeX) + (j))]));
 }
 printf("\n");
    }
}

canonical_original_code:
void print_grid(struct grid_s grid, char (*skin)(union cell_t cell))
{
    int i; int j;
    for (i = 0; i < grid.sizeY; i++)
    {
 for (j = 0; j < grid.sizeX; j++)
 {
     printf("%c", skin(grid.data[((i) * (grid.sizeX) + (j))]));
 }
 printf("\n");
    }
}

variable_types: struct grid_s { union cell_t { char ccell; int icell; long lcell; } *data; int sizeX; int sizeY; int bytesize; enum type_e { CHAR=expr, INT=expr, LONG=expr } type; }

variable_types:
skin
char (*)(union cell_t cell)

variable_types: i int

variable_types: j int

return_type: void

user_defined_types: struct grid_s { union cell_t *data; int sizeX; int sizeY; int bytesize; enum type_e type; }


decompiled_code:
__int64 __fastcall grid_cpy(__int64 a1, int a2, int a3, int a4, int a5, int a6, void *src, int a8, int a9)
{
if ( *(_DWORD *)(a1 + 16) < a9 )
return 0xFFFFFFFFLL;
memcpy(*(void **)a1, src, a9);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, int a3, int a4, int a5, int a6, void *src, int a8, int a9)
{
if ( *(_DWORD *)(a1 + 16) < a9 )
return 0xFFFFFFFFLL;
memcpy(*(void **)a1, src, a9);
return 0LL;
}

original_code:
int grid_cpy(grid_t *dest, grid_t src)
{
    if (dest->bytesize < src.bytesize)
 return -1;
    memcpy(dest->data, src.data, src.bytesize);
    return 0;
}

canonical_original_code:
int grid_cpy(struct grid_s *dest, struct grid_s src)
{
    if (dest->bytesize < src.bytesize)
 return -1;
    memcpy(dest->data, src.data, src.bytesize);
    return 0;
}

variable_types: struct grid_s { union cell_t { char ccell; int icell; long lcell; } *data; int sizeX; int sizeY; int bytesize; enum type_e { CHAR=expr, INT=expr, LONG=expr } type; } *

variable_types:
src
struct grid_s

return_type: int


decompiled_code:
char __fastcall read_cell(__int64 a1, __int64 (__fastcall *a2)(_QWORD), __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
char result; // al

result = (int)a8 <= (int)a1 || (int)a1 < 0 || a1 < 0;
if ( result )
return 0;
if ( SHIDWORD(a8) > SHIDWORD(a1) )
result = a2(*(_QWORD *)(a7 + 8LL * (HIDWORD(a1) * (int)a8 + (int)a1)));
return result;
}

canonical_decompiled_code:
char __fastcall func8(__int64 a1, __int64 (__fastcall *a2)(_QWORD), __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
char result; // al

result = (int)a8 <= (int)a1 || (int)a1 < 0 || a1 < 0;
if ( result )
return 0;
if ( SHIDWORD(a8) > SHIDWORD(a1) )
result = a2(*(_QWORD *)(a7 + 8LL * (HIDWORD(a1) * (int)a8 + (int)a1)));
return result;
}

original_code:
_Bool read_cell(grid_t grid, pos_t pos, _Bool (*cell_status)(cell_t cell))
{
    if (!(pos.x >= 0 && pos.y >= 0 && pos.x < grid.sizeX && pos.y < grid.sizeY))
 return (0);
    return (cell_status(grid.data[((pos.y) * (grid.sizeX) + (pos.x))]));
}

canonical_original_code:
_Bool read_cell(struct grid_s grid, struct pos_t pos, _Bool (*cell_status)(union cell_t cell))
{
    if (!(pos.x >= 0 && pos.y >= 0 && pos.x < grid.sizeX && pos.y < grid.sizeY))
 return (0);
    return (cell_status(grid.data[((pos.y) * (grid.sizeX) + (pos.x))]));
}

variable_types:
pos
struct pos_t { int x; int y; }

user_defined_types: enum type_e { CHAR=expr, INT=expr, LONG=expr }

user_defined_types: union cell_t { char ccell; int icell; long lcell; }


decompiled_code:
__int64 __fastcall write_cell(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
if ( !read_cell(a2, (__int64 (__fastcall *)(_QWORD))always_true, a3, a4, a5, a6, a7, a8) )
return 0xFFFFFFFFLL;
*(_QWORD *)(a7 + 8LL * ((int)a2 + (int)a8 * HIDWORD(a2))) = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
if ( !func8(a2, (__int64 (__fastcall *)(_QWORD))always_true, a3, a4, a5, a6, a7, a8) )
return 0xFFFFFFFFLL;
*(_QWORD *)(a7 + 8LL * ((int)a2 + (int)a8 * HIDWORD(a2))) = a1;
return 0LL;
}

original_code:
int write_cell(grid_t grid, cell_t cell, pos_t pos)
{
    if (read_cell(grid, pos, always_true) == 0)
 return (-1);
    grid.data[((pos.y) * (grid.sizeX) + (pos.x))] = cell;
    return (0);
}

canonical_original_code:
int write_cell(struct grid_s grid, union cell_t cell, struct pos_t pos)
{
    if (read_cell(grid, pos, always_true) == 0)
 return (-1);
    grid.data[((pos.y) * (grid.sizeX) + (pos.x))] = cell;
    return (0);
}

variable_types:
cell
union cell_t


decompiled_code:
char __fastcall read_cell_direc(__int64 a1, __int64 (__fastcall *a2)(_QWORD), unsigned int a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
__int64 v8; // rax
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9

v8 = direction_pos(a1, a3);
return read_cell(v8, a2, v9, v10, v11, v12, a7, a8);
}

original_code:
_Bool read_cell_direc(grid_t grid, pos_t position, _Bool (*cell_status)(cell_t cell), dir_t direction)
{
    position = direction_pos(position, direction);
    return (read_cell(grid, position, cell_status));
}

canonical_original_code:
_Bool read_cell_direc(struct grid_s grid, struct pos_t position, _Bool (*cell_status)(union cell_t cell), enum direction_e direction)
{
    position = direction_pos(position, direction);
    return (read_cell(grid, position, cell_status));
}

variable_types:
position
struct pos_t { int x; int y; }

user_defined_types: enum direction_e { LEFT=0, RIGHT=1, UP=2, DOWN=3 }


decompiled_code:
__int64 __fastcall read_cell_around(__int64 a1, __int64 (__fastcall *a2)(_QWORD), __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
unsigned int v8; // ebx

v8 = 0;
while ( !read_cell_direc(a1, a2, v8, a4, a5, a6, a7, a8) )
{
if ( ++v8 > 3 )
return -1LL;
}
return direction_pos(a1, v8);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 (__fastcall *a2)(_QWORD), __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
unsigned int v8; // ebx

v8 = 0;
while ( !func10(a1, a2, v8, a4, a5, a6, a7, a8) )
{
if ( ++v8 > 3 )
return -1LL;
}
return func3(a1, v8);
}

original_code:
pos_t read_cell_around(grid_t grid, pos_t position, _Bool (*cell_status)(cell_t cell))
{
    dir_t curr_direction = LEFT;
    while (curr_direction <= DOWN)
    {
        if (read_cell_direc(grid, position, cell_status, curr_direction))
            return (direction_pos(position, curr_direction));
        curr_direction++;
    }
    return ((pos_t){ -1, -1});
}

canonical_original_code:
struct pos_t read_cell_around(struct grid_s grid, struct pos_t position, _Bool (*cell_status)(union cell_t cell))
{
    enum direction_e curr_direction = LEFT;
    while (curr_direction <= DOWN)
    {
        if (read_cell_direc(grid, position, cell_status, curr_direction))
            return (direction_pos(position, curr_direction));
        curr_direction++;
    }
    return ((struct pos_t){ -1, -1});
}

variable_types:
position
struct pos_t


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
size_t v4; // rax
int v5; // eax
int v6; // er14
DIR *v7; // r12
int v8; // ebp
char *v9; // r15
__int64 v10; // rbx
unsigned int v11; // er15
__int64 v12; // r12
__int64 v13; // r13
float v14; // xmm0_4
double v15; // xmm0_8
float v16; // xmm1_4
float v17; // xmm0_4
float v18; // xmm0_4
double v19; // xmm1_8
double v20; // xmm2_8
double v21; // xmm3_8
size_t v22; // rax
char *v23; // r14
FILE *v24; // rbp
double v25; // xmm0_8
double v26; // xmm0_8
double v27; // r13
double v28; // xmm0_8
float v30; // [rsp+8h] [rbp-C0h]
double v31; // [rsp+8h] [rbp-C0h]
double v32; // [rsp+10h] [rbp-B8h]
double v33; // [rsp+18h] [rbp-B0h]
float v34; // [rsp+20h] [rbp-A8h]
double v35; // [rsp+28h] [rbp-A0h]
double v36; // [rsp+30h] [rbp-98h]
double v37; // [rsp+38h] [rbp-90h]
double v38; // [rsp+40h] [rbp-88h]
double v39; // [rsp+48h] [rbp-80h]
double v40; // [rsp+50h] [rbp-78h]
double v41; // [rsp+58h] [rbp-70h]
double v42; // [rsp+60h] [rbp-68h]
char *name; // [rsp+68h] [rbp-60h]
float v44; // [rsp+70h] [rbp-58h]
unsigned int v45; // [rsp+74h] [rbp-54h]
int v46; // [rsp+78h] [rbp-50h]
char ptr[58]; // [rsp+8Eh] [rbp-3Ah] BYREF

name = 0LL;
v45 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "i:r:");
if ( v5 == -1 )
break;
if ( v5 == 105 )
{
v3 = _bss_start;
v4 = strlen(_bss_start);
name = (char *)malloc(v4 + 1);
strcpy(name, v3);
}
else if ( v5 == 114 )
{
v45 = atoi(_bss_start);
}
}
v6 = -1;
if ( v45 && name )
{
v7 = opendir(name);
v8 = 0;
while ( 1 )
{
v10 = (__int64)readdir(v7);
if ( !v10 )
break;
v9 = (char *)malloc(0x10uLL);
sprintf(v9, "RAW_DATA_%06d", v45);
v8 += strncmp((const char *)(v10 + 19), v9, 0xFuLL) == 0;
free(v9);
}
v46 = v8;
closedir(v7);
if ( v8 <= 0 )
{
v36 = 0.0;
v38 = 0.0;
v12 = 0LL;
v13 = 0LL;
v10 = 0LL;
v33 = 0.0;
v42 = 2.225073858507201e-308;
v41 = 2.225073858507201e-308;
v32 = 0.0;
v34 = 3.4028235e38;
v30 = 1.1754944e-38;
LABEL_30:
printf("Max amplitude: %f\n", v30);
printf("Min amplitude: %f\n", v34);
if ( v10 < 0 )
v31 = (double)(int)(v10 & 1 | ((unsigned __int64)v10 >> 1))
+ (double)(int)(v10 & 1 | ((unsigned __int64)v10 >> 1));
else
v31 = (double)(int)v10;
printf("Average amplitude: %f\n", v32 / v31);
v25 = sqrt((v33 - v32 * v32 / v31) / v31);
printf("Stddev amplitude: %f\n", v25);
if ( v13 < 0 )
v26 = (double)(int)(v13 & 1 | ((unsigned __int64)v13 >> 1))
+ (double)(int)(v13 & 1 | ((unsigned __int64)v13 >> 1));
else
v26 = (double)(int)v13;
v27 = v38 / v26;
if ( v12 < 0 )
v28 = (double)(int)(v12 & 1 | ((unsigned __int64)v12 >> 1))
+ (double)(int)(v12 & 1 | ((unsigned __int64)v12 >> 1));
else
v28 = (double)(int)v12;
cabs();
cabs();
__divdc3();
clog();
cabs();
if ( v36 / v28 <= v27 )
printf("SNR: %f\n", v41 * 10.0);
else
printf("SNR: %f\n", v42 * 10.0);
free(name);
v6 = 0;
}
else
{
v35 = 0.0;
v36 = 0.0;
v37 = 0.0;
v38 = 0.0;
v11 = 1;
v12 = 0LL;
v13 = 0LL;
v33 = 0.0;
v42 = 2.225073858507201e-308;
v40 = 2.225073858507201e-308;
v41 = 2.225073858507201e-308;
v39 = 2.225073858507201e-308;
v32 = 0.0;
v34 = 3.4028235e38;
v30 = 1.1754944e-38;
while ( 1 )
{
v22 = strlen(name);
v23 = (char *)malloc(v22 + 24);
sprintf(v23, "%s/RAW_DATA_%06d_%06d", name, v45, v11);
v24 = fopen(v23, "rb");
if ( !v24 )
break;
while ( fread(ptr, 2uLL, 1uLL, v24) )
{
v16 = (double)(unsigned __int8)ptr[0] * 0.0078125 - 1.0;
v17 = (double)(unsigned __int8)ptr[1] * 0.0078125 - 1.0;
v44 = v17 * v17;
v18 = (float)(v16 * v16) + (float)(v17 * v17);
if ( v18 < 0.0 )
v14 = sqrtf(v18);
else
v14 = fsqrt(v18);
v19 = (float)((float)(v44 * 0.0) + (float)(v16 * v16));
v20 = v44;
v30 = fmaxf(v14, v30);
v34 = fminf(v14, v34);
v21 = v14;
v32 = v32 + v14;
v33 = (float)(v14 * v14) + v33;
if ( ++v10 < 0 )
v15 = (double)(int)(v10 & 1 | ((unsigned __int64)v10 >> 1))
+ (double)(int)(v10 & 1 | ((unsigned __int64)v10 >> 1));
else
v15 = (double)(int)v10;
if ( (((unsigned __int8)(int)(v15 / 1638400.0) + ((int)(v15 / 1638400.0) < 0)) & 2) != 0 )
{
v36 = v36 + v19;
v35 = v20 + v35;
++v12;
if ( v21 > v40 )
{
v40 = v30;
v42 = v19;
}
}
else
{
v38 = v38 + v19;
v37 = v20 + v37;
++v13;
if ( v21 > v39 )
{
v39 = v30;
v41 = v19;
}
}
}
fclose(v24);
free(v23);
if ( v46 < (int)++v11 )
goto LABEL_30;
}
v6 = -1;
puts("Error!");
}
}
return v6;
}

original_code:
int main(int argc, char *argv[]) {
 printf("Memmory Allocation...\n");
 fftw_init_threads();
 fftw_plan_with_nthreads(4);
 load_files();
 init_buffers();
 printf("Analysis Process Started...\n");
 analysis();
 printf("Process Finished.\n");
 clean_up_memmory();
 fftw_cleanup_threads();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rax
int v5; // ebx
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // rax
char v10[32]; // [rsp+10h] [rbp-80h] BYREF
char v11[44]; // [rsp+30h] [rbp-60h] BYREF
unsigned int v12; // [rsp+5Ch] [rbp-34h]
_DWORD *v13; // [rsp+60h] [rbp-30h]
int v14; // [rsp+68h] [rbp-28h]
char v15; // [rsp+6Fh] [rbp-21h]
int v16; // [rsp+70h] [rbp-20h]
int i; // [rsp+74h] [rbp-1Ch]
char v18; // [rsp+79h] [rbp-17h]
char v19; // [rsp+7Ah] [rbp-16h]
char v20; // [rsp+7Bh] [rbp-15h]
unsigned int v21; // [rsp+7Ch] [rbp-14h]

std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(v11, argv, envp);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(v10, argv, v3);
v16 = 0;
v21 = 0;
v20 = 0;
v19 = 0;
v15 = 0;
v18 = 0;
while ( 1 )
{
v14 = getopt(argc, (char *const *)argv, "o:i:f:r:");
if ( v14 == -1 )
break;
if ( v14 == 114 )
{
v21 = atoi(optarg);
v18 = 1;
}
else if ( v14 <= 114 )
{
if ( v14 == 105 )
{
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator=(v11, optarg);
v19 = 1;
}
else if ( v14 == 111 )
{
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator=(v10, optarg);
v20 = 1;
}
}
}
if ( argc == optind )
{
v4 = std::operator<<<std::char_traits<char>>(&std::cerr, "No frequencies found!");
std::ostream::operator<<(v4, &std::endl<char,std::char_traits<char>>);
v5 = -1;
}
else
{
v15 = 1;
if ( v20 != 1 || v19 != 1 || v15 != 1 || v18 != 1 )
{
v6 = std::operator<<<std::char_traits<char>>(&std::cerr, "Not enough args!");
std::ostream::operator<<(v6, &std::endl<char,std::char_traits<char>>);
v5 = -1;
}
else
{
v13 = malloc(4LL * (argc - optind));
v12 = argc - optind;
for ( i = optind; i < argc; ++i )
{
v16 = atoi(argv[i]);
v13[i - optind] = (int)(float)(0.0020000001 * (float)v16);
if ( (int)v13[i - optind] < 0 && (int)v13[i - optind] >= -2047 )
v13[i - optind] += 4096;
if ( (int)v13[i - optind] < 0 || (int)v13[i - optind] > 4096 )
{
v5 = -1;
goto LABEL_28;
}
printf("Using %d bin\n", (unsigned int)v13[i - optind]);
}
v7 = std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str(v10);
v8 = std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str(v11);
v5 = process(v8, v7, v12, v13, v21);
}
}
LABEL_28:
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string(v10);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string(v11);
return v5;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 printf("Memmory Allocation...\n");
 fftw_init_threads();
 fftw_plan_with_nthreads(4);
 load_files();
 init_buffers();
 printf("Analysis Process Started...\n");
 analysis();
 printf("Process Finished.\n");
 clean_up_memmory();
 fftw_cleanup_threads();
 return 0;
}


decompiled_code:
void __fastcall __noreturn fatal_error(const char *a1, int a2)
{
puts(a1);
exit(a2);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1, int a2)
{
puts(a1);
exit(a2);
}

original_code:
void fatal_error( const char *message, int code ) {
  printf("%s\n", message );
  exit( code );
}

canonical_original_code:
void fatal_error(char *message, int code) {
  printf("%s\n", message );
  exit( code );
}

variable_types:
message
char *

variable_types: code int


compare

decompiled_code:
int __fastcall compare(const char *a1, const char *a2)
{
int v2; // ebx
int v3; // er14
size_t v4; // rax
int v5; // er15
bool v6; // cf
const char *v7; // rax
__int64 v8; // rbx
char v9; // dl
char v10; // cl
int v11; // ebx
const char *v12; // rbx
size_t v13; // rax
const char *v15; // [rsp+8h] [rbp-40h]

v2 = strlen(a1);
v3 = v2;
v4 = strlen(a2);
v5 = v4;
v6 = v4 < v2;
if ( v4 < v2 )
v3 = v4;
if ( v4 < v2 )
v5 = v2;
v7 = a2;
if ( v6 )
v7 = a1;
v15 = v7;
if ( v3 <= 0 )
{
v11 = 0;
}
else
{
v8 = 1LL;
do
{
v9 = a1[v8 - 1];
v10 = a2[v8 - 1];
if ( v9 != v10 )
LODWORD(v7) = printf(
"Character %d differs: String 1: %c, String2 %c",
(unsigned int)v8,
(unsigned int)v9,
(unsigned int)v10);
++v8;
}
while ( v8 != v3 + 1 );
v11 = v3;
}
if ( v3 != v5 )
{
v12 = &v15[v11];
v13 = strlen(v12);
LODWORD(v7) = printf(
"The strings are of different length\nThe longer string is %d characters longer, and ends with %s\n",
v13,
v12);
}
return (int)v7;
}

canonical_decompiled_code:
int __fastcall func9(const char *a1, const char *a2)
{
int v2; // ebx
int v3; // er14
size_t v4; // rax
int v5; // er15
bool v6; // cf
const char *v7; // rax
__int64 v8; // rbx
char v9; // dl
char v10; // cl
int v11; // ebx
const char *v12; // rbx
size_t v13; // rax
const char *v15; // [rsp+8h] [rbp-40h]

v2 = strlen(a1);
v3 = v2;
v4 = strlen(a2);
v5 = v4;
v6 = v4 < v2;
if ( v4 < v2 )
v3 = v4;
if ( v4 < v2 )
v5 = v2;
v7 = a2;
if ( v6 )
v7 = a1;
v15 = v7;
if ( v3 <= 0 )
{
v11 = 0;
}
else
{
v8 = 1LL;
do
{
v9 = a1[v8 - 1];
v10 = a2[v8 - 1];
if ( v9 != v10 )
LODWORD(v7) = printf(
"Character %d differs: String 1: %c, String2 %c",
(unsigned int)v8,
(unsigned int)v9,
(unsigned int)v10);
++v8;
}
while ( v8 != v3 + 1 );
v11 = v3;
}
if ( v3 != v5 )
{
v12 = &v15[v11];
v13 = strlen(v12);
LODWORD(v7) = printf(
"The strings are of different length\nThe longer string is %d characters longer, and ends with %s\n",
v13,
v12);
}
return (int)v7;
}

original_code:
void compare( char *a, char *b ) {
  int i;
  char *longer = b;
  int short_length = strlen( a );
  int long_length = strlen( b );
  if( strlen( b ) < short_length ) {
    short_length = strlen( b );
    long_length = strlen( a );
    longer = a;
  }
  for( i = 0; i < short_length; i++ ) {
    if( a[i] != b[i] )
      printf("Character %d differs:  String 1: %c, String2 %c", i+1, a[i], b[i]);
  }
  if( short_length != long_length ) {
    printf( "The strings are of different length\n"
            "The longer string is %d characters longer, and ends with %s\n",
            strlen( longer + i ), longer + i );
  }
}

canonical_original_code:
void compare(char *a, char *b) {
  int i;
  char *longer = b;
  int short_length = strlen( a );
  int long_length = strlen( b );
  if( strlen( b ) < short_length ) {
    short_length = strlen( b );
    long_length = strlen( a );
    longer = a;
  }
  for( i = 0; i < short_length; i++ ) {
    if( a[i] != b[i] )
      printf("Character %d differs:  String 1: %c, String2 %c", i+1, a[i], b[i]);
  }
  if( short_length != long_length ) {
    printf( "The strings are of different length\n"
            "The longer string is %d characters longer, and ends with %s\n",
            strlen( longer + i ), longer + i );
  }
}

variable_types:
a
char *

variable_types:
b
char *

variable_types:
longer
char *


decompiled_code:
void __fastcall __noreturn process_three(int *a1, int *a2)
{
size_t v2; // rax
size_t v3; // rax
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

close(a1[1]);
close(*a2);
if ( read(*a1, v4, 0x400uLL) != -1 )
{
close(*a1);
upper(v4);
v2 = strlen(v4);
write(1, v4, v2);
write(1, "\n", 1uLL);
v3 = strlen(v4);
write(a2[1], v4, v3 + 1);
close(a2[1]);
puts("Terminating process 3");
exit(0);
}
fatal_error("Failed to read from pipe!", 1);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(int *a1, int *a2)
{
size_t v2; // rax
size_t v3; // rax
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

close(a1[1]);
close(*a2);
if ( read(*a1, v4, 0x400uLL) != -1 )
{
close(*a1);
func8(v4);
v2 = strlen(v4);
write(1, v4, v2);
write(1, "\n", 1uLL);
v3 = strlen(v4);
write(a2[1], v4, v3 + 1);
close(a2[1]);
puts("Terminating process 3");
exit(0);
}
func7("Failed to read from pipe!", 1);
}

original_code:
void process_three( int fd1[], int fd2[] ) {
  char buf3[1024];
  close( fd1[1] );
  close( fd2[0] );
  if( read( fd1[0], buf3, 1024 ) == -1 )
    fatal_error( "Failed to read from pipe!", 1 );
  close( fd1[0] );
  upper( buf3 );
  write( 1, buf3, strlen( buf3 ) );
  write( 1, "\n", 1 );
  write( fd2[1], buf3, strlen( buf3 ) + 1 );
  close( fd2[1] );
  printf("Terminating process 3\n");
  exit( 0 );
}

canonical_original_code:
void process_three(int fd1[], int fd2[]) {
  char buf3[1024];
  close( fd1[1] );
  close( fd2[0] );
  if( read( fd1[0], buf3, 1024 ) == -1 )
    fatal_error( "Failed to read from pipe!", 1 );
  close( fd1[0] );
  upper( buf3 );
  write( 1, buf3, strlen( buf3 ) );
  write( 1, "\n", 1 );
  write( fd2[1], buf3, strlen( buf3 ) + 1 );
  close( fd2[1] );
  printf("Terminating process 3\n");
  exit( 0 );
}


decompiled_code:
void __fastcall __noreturn process_two(int *a1, int *a2)
{
int v2; // eax
__int64 v3; // rbx
size_t v4; // rax
size_t v5; // rax
__pid_t v6; // eax
size_t v7; // rax
char v8[1024]; // [rsp+0h] [rbp-1028h] BYREF
char s[1024]; // [rsp+400h] [rbp-C28h] BYREF
char buf[2048]; // [rsp+800h] [rbp-828h] BYREF
int v11[2]; // [rsp+1000h] [rbp-28h] BYREF
int pipedes[2]; // [rsp+1008h] [rbp-20h] BYREF

close(*a2);
close(a1[1]);
if ( read(*a1, buf, 0x400uLL) != -1 )
{
close(*a1);
v2 = strlen(buf) - 1;
if ( v2 >= 0 )
{
v3 = v2;
do
{
s[strlen(buf) - 1 - v3] = buf[v3];
--v3;
}
while ( (int)v3 >= 0 );
}
v4 = strlen(s);
write(1, s, v4);
write(1, "\n", 1uLL);
if ( pipe(pipedes) != -1 )
{
if ( pipe(v11) != -1 )
{
v5 = strlen(s);
if ( write(pipedes[1], s, v5 + 1) != -1 )
{
close(pipedes[1]);
v6 = fork();
if ( v6 != -1 )
{
if ( !v6 )
process_three(pipedes, v11);
close(pipedes[0]);
close(v11[1]);
wait(0LL);
read(v11[0], v8, 0x400uLL);
close(v11[0]);
strncat(buf, v8, 0x400uLL);
puts(buf);
v7 = strlen(buf);
if ( write(a2[1], buf, v7 + 1) != -1 )
{
close(a2[1]);
puts("Terminating process 2");
exit(0);
}
fatal_error("Failed to write to pipe!", 1);
}
fatal_error("The process failed to fork!", 2);
}
fatal_error("Failed to write to pipe!", 1);
}
fatal_error("There was an error creating the pipe!", 1);
}
fatal_error("There was an error creating the pipe!", 1);
}
fatal_error("Read from pipe failed!", 1);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(int *a1, int *a2)
{
int v2; // eax
__int64 v3; // rbx
size_t v4; // rax
size_t v5; // rax
__pid_t v6; // eax
size_t v7; // rax
char v8[1024]; // [rsp+0h] [rbp-1028h] BYREF
char s[1024]; // [rsp+400h] [rbp-C28h] BYREF
char buf[2048]; // [rsp+800h] [rbp-828h] BYREF
int v11[2]; // [rsp+1000h] [rbp-28h] BYREF
int pipedes[2]; // [rsp+1008h] [rbp-20h] BYREF

close(*a2);
close(a1[1]);
if ( read(*a1, buf, 0x400uLL) != -1 )
{
close(*a1);
v2 = strlen(buf) - 1;
if ( v2 >= 0 )
{
v3 = v2;
do
{
s[strlen(buf) - 1 - v3] = buf[v3];
--v3;
}
while ( (int)v3 >= 0 );
}
v4 = strlen(s);
write(1, s, v4);
write(1, "\n", 1uLL);
if ( pipe(pipedes) != -1 )
{
if ( pipe(v11) != -1 )
{
v5 = strlen(s);
if ( write(pipedes[1], s, v5 + 1) != -1 )
{
close(pipedes[1]);
v6 = fork();
if ( v6 != -1 )
{
if ( !v6 )
func10(pipedes, v11);
close(pipedes[0]);
close(v11[1]);
wait(0LL);
read(v11[0], v8, 0x400uLL);
close(v11[0]);
strncat(buf, v8, 0x400uLL);
puts(buf);
v7 = strlen(buf);
if ( write(a2[1], buf, v7 + 1) != -1 )
{
close(a2[1]);
puts("Terminating process 2");
exit(0);
}
func7("Failed to write to pipe!", 1);
}
func7("The process failed to fork!", 2);
}
func7("Failed to write to pipe!", 1);
}
func7("There was an error creating the pipe!", 1);
}
func7("There was an error creating the pipe!", 1);
}
func7("Read from pipe failed!", 1);
}

original_code:
void process_two( int fd1[], int fd2[] ) {
  int i, pfd1[2], pfd2[2];
  char buf2[2048], rev_str[1024], tmp;
  pid_t child2_pid;
  close( fd2[0] );
  close( fd1[1] );
  if( read( fd1[0], buf2, 1024 ) == -1 )
    fatal_error( "Read from pipe failed!", 1 );
  close( fd1[0] );
  for( i = strlen( buf2 ) - 1; i >= 0; i-- ) {
    rev_str[ strlen( buf2 ) - i - 1 ] = buf2[ i ];
  }
  write( 1, rev_str, strlen( rev_str ) );
  write( 1, "\n", 1 );
  if( pipe( pfd1 ) == -1 )
    fatal_error( "There was an error creating the pipe!", 1 );
  if( pipe( pfd2 ) == -1 )
    fatal_error( "There was an error creating the pipe!", 1 );
  if( write( pfd1[1], rev_str, strlen( rev_str ) + 1 ) == -1 )
    fatal_error( "Failed to write to pipe!", 1 );
  close( pfd1[1] );
  child2_pid = fork();
  if( child2_pid == -1 )
    fatal_error( "The process failed to fork!", 2 );
  else if( child2_pid == 0 ) {
    process_three( pfd1, pfd2 );
  }
  else {
    char buf4[1024];
    close( pfd1[0] );
    close( pfd2[1] );
    wait( ((void *)0) );
    read( pfd2[0], buf4, 1024 );
    close( pfd2[0] );
    strncat( buf2, buf4, 1024 );
    printf("%s\n", buf2);
    if( write( fd2[1], buf2, strlen( buf2 ) + 1 ) == -1 )
      fatal_error("Failed to write to pipe!", 1);
    close( fd2[1] );
    printf( "Terminating process 2\n" );
    exit( 0 );
  }
}

canonical_original_code:
void process_two(int fd1[], int fd2[]) {
  int i; int pfd1[2]; int pfd2[2];
  char buf2[2048]; char rev_str[1024]; char tmp;
  int child2_pid;
  close( fd2[0] );
  close( fd1[1] );
  if( read( fd1[0], buf2, 1024 ) == -1 )
    fatal_error( "Read from pipe failed!", 1 );
  close( fd1[0] );
  for( i = strlen( buf2 ) - 1; i >= 0; i-- ) {
    rev_str[ strlen( buf2 ) - i - 1 ] = buf2[ i ];
  }
  write( 1, rev_str, strlen( rev_str ) );
  write( 1, "\n", 1 );
  if( pipe( pfd1 ) == -1 )
    fatal_error( "There was an error creating the pipe!", 1 );
  if( pipe( pfd2 ) == -1 )
    fatal_error( "There was an error creating the pipe!", 1 );
  if( write( pfd1[1], rev_str, strlen( rev_str ) + 1 ) == -1 )
    fatal_error( "Failed to write to pipe!", 1 );
  close( pfd1[1] );
  child2_pid = fork();
  if( child2_pid == -1 )
    fatal_error( "The process failed to fork!", 2 );
  else if( child2_pid == 0 ) {
    process_three( pfd1, pfd2 );
  }
  else {
    char buf4[1024];
    close( pfd1[0] );
    close( pfd2[1] );
    wait( ((void *)0) );
    read( pfd2[0], buf4, 1024 );
    close( pfd2[0] );
    strncat( buf2, buf4, 1024 );
    printf("%s\n", buf2);
    if( write( fd2[1], buf2, strlen( buf2 ) + 1 ) == -1 )
      fatal_error("Failed to write to pipe!", 1);
    close( fd2[1] );
    printf( "Terminating process 2\n" );
    exit( 0 );
  }
}

variable_types: tmp char


upper

decompiled_code:
size_t __fastcall upper(char *s)
{
unsigned __int64 i; // rbx
size_t result; // rax
char v3; // al

for ( i = 0LL; ; ++i )
{
result = strlen(s);
if ( result <= i )
break;
v3 = s[i];
if ( (unsigned __int8)(v3 - 97) <= 0x19u )
s[i] = v3 - 32;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func8(char *s)
{
unsigned __int64 i; // rbx
size_t result; // rax
char v3; // al

for ( i = 0LL; ; ++i )
{
result = strlen(s);
if ( result <= i )
break;
v3 = s[i];
if ( (unsigned __int8)(v3 - 97) <= 0x19u )
s[i] = v3 - 32;
}
return result;
}

original_code:
void upper( char *mystring ) {
  int i, diff = 'a' - 'A';
  for( i = 0; i < strlen( mystring ); i++ ) {
    if( mystring[i] >= 'a' && mystring[i] <= 'z' )
      mystring[i] -= diff;
  }
}

canonical_original_code:
void upper(char *mystring) {
  int i; int diff = 'a' - 'A';
  for( i = 0; i < strlen( mystring ); i++ ) {
    if( mystring[i] >= 'a' && mystring[i] <= 'z' )
      mystring[i] -= diff;
  }
}

variable_types:
mystring
char *

variable_types: diff int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbx
size_t v5; // rax
__pid_t v6; // eax
char v7[2048]; // [rsp+0h] [rbp-828h] BYREF
char *lineptr; // [rsp+800h] [rbp-28h] BYREF
size_t n; // [rsp+808h] [rbp-20h] BYREF
int v10[2]; // [rsp+810h] [rbp-18h] BYREF
int pipedes[2]; // [rsp+818h] [rbp-10h] BYREF

n = 1024LL;
lineptr = (char *)malloc(0x400uLL);
printf("Enter a string: ");
getline(&lineptr, &n, stdin);
v3 = strchr(lineptr, 10);
if ( v3 )
*v3 = 0;
puts(lineptr);
if ( pipe(pipedes) != -1 )
{
if ( pipe(v10) != -1 )
{
v4 = lineptr;
v5 = strlen(lineptr);
if ( write(pipedes[1], v4, v5 + 1) != -1 )
{
close(pipedes[1]);
v6 = fork();
if ( v6 != -1 )
{
if ( !v6 )
process_two(pipedes, v10);
wait(0LL);
if ( read(v10[0], v7, 0x800uLL) != -1 )
{
compare(lineptr, v7);
puts("Terminating process 1");
exit(0);
}
fatal_error("Failed to read from pipe!", 1);
}
fatal_error("The process failed to fork!", 2);
}
fatal_error("Failure to write to pipe!", 1);
}
fatal_error("There was an error creating the pipe!", 1);
}
fatal_error("There was an error creating the pipe!", 1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbx
size_t v5; // rax
__pid_t v6; // eax
char v7[2048]; // [rsp+0h] [rbp-828h] BYREF
char *lineptr; // [rsp+800h] [rbp-28h] BYREF
size_t n; // [rsp+808h] [rbp-20h] BYREF
int v10[2]; // [rsp+810h] [rbp-18h] BYREF
int pipedes[2]; // [rsp+818h] [rbp-10h] BYREF

n = 1024LL;
lineptr = (char *)malloc(0x400uLL);
printf("Enter a string: ");
getline(&lineptr, &n, stdin);
v3 = strchr(lineptr, 10);
if ( v3 )
*v3 = 0;
puts(lineptr);
if ( pipe(pipedes) != -1 )
{
if ( pipe(v10) != -1 )
{
v4 = lineptr;
v5 = strlen(lineptr);
if ( write(pipedes[1], v4, v5 + 1) != -1 )
{
close(pipedes[1]);
v6 = fork();
if ( v6 != -1 )
{
if ( !v6 )
func11(pipedes, v10);
wait(0LL);
if ( read(v10[0], v7, 0x800uLL) != -1 )
{
func9(lineptr, v7);
puts("Terminating process 1");
exit(0);
}
func7("Failed to read from pipe!", 1);
}
func7("The process failed to fork!", 2);
}
func7("Failure to write to pipe!", 1);
}
func7("There was an error creating the pipe!", 1);
}
func7("There was an error creating the pipe!", 1);
}

original_code:
int main( int argc, char *argv[] ) {
  int pfd1[2];
  int pfd2[2];
  pid_t child1_pid;
  size_t size = 1024;
  char *buf = (char*) malloc( size );
  char final_buf[2048];
  printf( "Enter a string: " );
  getline( &buf, &size, stdin );
  char *c = strchr( buf, '\n' );
  if( c != ((void *)0) )
    *c = '\0';
  printf( "%s\n", buf );
  if( pipe( pfd1 ) == -1 )
    fatal_error( "There was an error creating the pipe!", 1 );
  if( pipe( pfd2 ) == -1 )
    fatal_error( "There was an error creating the pipe!", 1 );
  if( write( pfd1[1], buf, strlen( buf ) + 1 ) == -1 )
    fatal_error( "Failure to write to pipe!", 1 );
  close( pfd1[1] );
  child1_pid = fork();
  if( child1_pid == -1 )
    fatal_error( "The process failed to fork!", 2 );
  else if( child1_pid == 0 ) {
    process_two( pfd1, pfd2 );
  }
  else {
    wait( ((void *)0) );
    if( read( pfd2[0], final_buf, 2048 ) == -1 )
      fatal_error("Failed to read from pipe!", 1 );
    compare( buf, final_buf );
    printf("Terminating process 1\n");
    exit( 0 );
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int pfd1[2];
  int pfd2[2];
  int child1_pid;
  unsigned long size = 1024;
  char *buf = (char*) malloc( size );
  char final_buf[2048];
  printf( "Enter a string: " );
  getline( &buf, &size, stdin );
  char *c = strchr( buf, '\n' );
  if( c != ((void *)0) )
    *c = '\0';
  printf( "%s\n", buf );
  if( pipe( pfd1 ) == -1 )
    fatal_error( "There was an error creating the pipe!", 1 );
  if( pipe( pfd2 ) == -1 )
    fatal_error( "There was an error creating the pipe!", 1 );
  if( write( pfd1[1], buf, strlen( buf ) + 1 ) == -1 )
    fatal_error( "Failure to write to pipe!", 1 );
  close( pfd1[1] );
  child1_pid = fork();
  if( child1_pid == -1 )
    fatal_error( "The process failed to fork!", 2 );
  else if( child1_pid == 0 ) {
    process_two( pfd1, pfd2 );
  }
  else {
    wait( ((void *)0) );
    if( read( pfd2[0], final_buf, 2048 ) == -1 )
      fatal_error("Failed to read from pipe!", 1 );
    compare( buf, final_buf );
    printf("Terminating process 1\n");
    exit( 0 );
  }
  return 0;
}

variable_types:
size
unsigned long

variable_types:
buf
char *

variable_types:
c
char *


min

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

original_code:
int min( int one, int two ) {
  if( one > two )
    return two;
  else
    return one;
}

canonical_original_code:
int min(int one, int two) {
  if( one > two )
    return two;
  else
    return one;
}

variable_types: one int

variable_types: two int


compare

decompiled_code:
int __fastcall compare(int a1, int a2, int a3, const char *a4, const char *a5)
{
int v6; // er15
signed int v7; // ebp
int v8; // eax
unsigned int v9; // er12
int v10; // er14
int v11; // er13
__int64 i; // rbx
char v13; // dl
char v14; // cl
int v15; // eax
int fd; // [rsp+10h] [rbp-848h]
char v19[1024]; // [rsp+20h] [rbp-838h] BYREF
char buf[1080]; // [rsp+420h] [rbp-438h] BYREF

fd = open(a4, 0);
v6 = open(a5, 0);
v7 = read(fd, buf, 0x400uLL);
v8 = read(v6, v19, 0x400uLL);
if ( v7 > 0 )
{
v9 = v8;
if ( v8 > 0 )
{
v10 = 0;
do
{
if ( a3 )
upper((__int64)buf, (__int64)v19);
if ( a1 )
{
v11 = min(v7, v9);
for ( i = 0LL; v11 > (int)i; ++i )
{
v13 = buf[i];
v14 = v19[i];
if ( v13 != v14 )
printf(
"Byte %d File1:%c\tFile2:%c\n",
(unsigned int)(v10 + 1 + i),
(unsigned int)v13,
(unsigned int)v14);
}
}
if ( v7 != v9 && a2 )
{
puts("The files are of different length");
exit(0);
}
v10 += min(v7, v9);
v7 = read(fd, buf, 0x400uLL);
v15 = read(v6, v19, 0x400uLL);
v9 = v15;
}
while ( v7 > 0 && v15 > 0 );
}
}
close(fd);
return close(v6);
}

canonical_decompiled_code:
int __fastcall func10(int a1, int a2, int a3, const char *a4, const char *a5)
{
int v6; // er15
signed int v7; // ebp
int v8; // eax
unsigned int v9; // er12
int v10; // er14
int v11; // er13
__int64 i; // rbx
char v13; // dl
char v14; // cl
int v15; // eax
int fd; // [rsp+10h] [rbp-848h]
char v19[1024]; // [rsp+20h] [rbp-838h] BYREF
char buf[1080]; // [rsp+420h] [rbp-438h] BYREF

fd = open(a4, 0);
v6 = open(a5, 0);
v7 = read(fd, buf, 0x400uLL);
v8 = read(v6, v19, 0x400uLL);
if ( v7 > 0 )
{
v9 = v8;
if ( v8 > 0 )
{
v10 = 0;
do
{
if ( a3 )
func9((__int64)buf, (__int64)v19);
if ( a1 )
{
v11 = func8(v7, v9);
for ( i = 0LL; v11 > (int)i; ++i )
{
v13 = buf[i];
v14 = v19[i];
if ( v13 != v14 )
printf(
"Byte %d File1:%c\tFile2:%c\n",
(unsigned int)(v10 + 1 + i),
(unsigned int)v13,
(unsigned int)v14);
}
}
if ( v7 != v9 && a2 )
{
puts("The files are of different length");
exit(0);
}
v10 += func8(v7, v9);
v7 = read(fd, buf, 0x400uLL);
v15 = read(v6, v19, 0x400uLL);
v9 = v15;
}
while ( v7 > 0 && v15 > 0 );
}
}
close(fd);
return close(v6);
}

variable_types: i int


decompiled_code:
void __noreturn print_usage()
{
puts(
"Usage: compare [-s] [-d] [-u] file1 file2\n"
" -s Compare only until end of shorter file\n"
" -d Indicate files are of different length\n"
" -u Ignore case");
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
puts(
"Usage: compare [-s] [-d] [-u] file1 file2\n"
" -s Compare only until end of shorter file\n"
" -d Indicate files are of different length\n"
" -u Ignore case");
exit(0);
}

original_code:
void print_usage( ) {
  printf("Usage: compare [-s] [-d] [-u] file1 file2\n"
      "  -s   Compare only until end of shorter file\n"
      "  -d   Indicate files are of different length\n"
      "  -u   Ignore case\n");
  exit( 0 );
}

canonical_original_code:
void print_usage() {
  printf("Usage: compare [-s] [-d] [-u] file1 file2\n"
      "  -s   Compare only until end of shorter file\n"
      "  -d   Indicate files are of different length\n"
      "  -u   Ignore case\n");
  exit( 0 );
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er14
int v5; // er15
int v7; // eax
int v8; // [rsp+Ch] [rbp-3Ch]

v3 = 2;
v4 = 0;
v8 = 0;
v5 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "sdu");
if ( v7 == 100 )
{
v8 = 1;
goto LABEL_9;
}
if ( v7 <= 100 )
break;
if ( v7 == 115 )
{
v5 = 1;
}
else
{
if ( v7 != 117 )
goto LABEL_14;
v4 = 1;
}
LABEL_9:
++v3;
}
if ( v7 != -1 )
{
if ( v7 == 63 )
print_usage();
LABEL_14:
abort();
}
if ( v3 + 1 < argc )
print_usage();
compare(v5, v8, v4, argv[_bss_start], argv[_bss_start + 1]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er14
int v5; // er15
int v7; // eax
int v8; // [rsp+Ch] [rbp-3Ch]

v3 = 2;
v4 = 0;
v8 = 0;
v5 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "sdu");
if ( v7 == 100 )
{
v8 = 1;
goto LABEL_9;
}
if ( v7 <= 100 )
break;
if ( v7 == 115 )
{
v5 = 1;
}
else
{
if ( v7 != 117 )
goto LABEL_14;
v4 = 1;
}
LABEL_9:
++v3;
}
if ( v7 != -1 )
{
if ( v7 == 63 )
func7();
LABEL_14:
abort();
}
if ( v3 + 1 < argc )
func7();
func10(v5, v8, v4, argv[_bss_start], argv[_bss_start + 1]);
return 0;
}


decompiled_code:
void __noreturn alarm_handler()
{
kill(cpid, 9);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
kill(cpid, 9);
exit(0);
}

original_code:
void alarm_handler( int parameter ) {
  kill( cpid, 9 );
  exit( 0 );
}

canonical_original_code:
void alarm_handler(int parameter) {
  kill( cpid, 9 );
  exit( 0 );
}

variable_types: parameter int


decompiled_code:
void __fastcall __noreturn print_usage(int status)
{
puts("Usage: kill_it <program to run> <time to run program>");
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(int status)
{
puts("Usage: kill_it <program to run> <time to run program>");
exit(status);
}

original_code:
void print_usage( int code ) {
  printf("Usage: kill_it <program to run> <time to run program>\n");
  exit( code );
}

canonical_original_code:
void print_usage(int code) {
  printf("Usage: kill_it <program to run> <time to run program>\n");
  exit( code );
}


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

if ( argc != 3 )
print_usage(1);
signal(14, (__sighandler_t)alarm_handler);
v3 = atoi(argv[2]);
alarm(v3);
v4 = fork();
cpid = v4;
if ( v4 == -1 )
{
puts("Failed to create child");
exit(1);
}
if ( v4 )
pause();
else
execl(argv[1], 0LL);
return 0;
}

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

if ( argc != 3 )
func8(1);
signal(14, (__sighandler_t)alarm_handler);
v3 = atoi(argv[2]);
alarm(v3);
v4 = fork();
cpid = v4;
if ( v4 == -1 )
{
puts("Failed to create child");
exit(1);
}
if ( v4 )
pause();
else
execl(argv[1], 0LL);
return 0;
}

original_code:
int main( int argc, char* argv[] ) {
  if( argc != 3 )
    print_usage( 1 );
  signal( 14, alarm_handler );
  alarm( atoi( argv[2] ) );
  cpid = fork();
  if( cpid == -1 ) {
    printf("Failed to create child\n");
    exit( 1 );
  }
  else if( cpid == 0 ) {
    execl( argv[1], ((void *)0) );
  }
  else {
    pause();
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  if( argc != 3 )
    print_usage( 1 );
  signal( 14, alarm_handler );
  alarm( atoi( argv[2] ) );
  cpid = fork();
  if( cpid == -1 ) {
    printf("Failed to create child\n");
    exit( 1 );
  }
  else if( cpid == 0 ) {
    execl( argv[1], ((void *)0) );
  }
  else {
    pause();
  }
  return 0;
}

variable_types: argc int


decompiled_code:
int __fastcall print_page_header(const char *a1, const char *a2)
{
int result; // eax

result = printf("Page %3d %*s\t %s\t \n", (unsigned int)page_number_0, 26, a1, a2);
++page_number_0;
return result;
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, const char *a2)
{
int result; // eax

result = printf("Page %3d %*s\t %s\t \n", (unsigned int)page_number_0, 26, a1, a2);
++page_number_0;
return result;
}

original_code:
static void print_page_header(char source_name[], char date[])
{
 static int page_number = 0;
 printf("Page %3d %*s\t %s\t \n", page_number, 80/3, source_name, date);
 page_number++;
}

variable_types:
date
char []


decompiled_code:
int __fastcall print_line(const char *a1, const char *a2, const char *a3)
{
if ( ++line_count_1 > 50 )
{
print_page_header(a2, a3);
line_count_1 = 0;
}
return printf("%.*s", 80, a1);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1, const char *a2, const char *a3)
{
if ( ++line_count_1 > 50 )
{
func8(a2, a3);
line_count_1 = 0;
}
return printf("%.*s", 80, a1);
}

original_code:
void print_line(char line[], char source_name_to_print[], char date_to_print[])
{
    static int line_count = 50;
    if (++line_count > 50)
    {
        print_page_header(source_name_to_print, date_to_print);
 line_count = 0;
    }
    printf("%.*s", 80, line);
}

variable_types:
line
char []


CuStrAlloc

repo: bcg/bitpack

decompiled_code:
void *__fastcall CuStrAlloc(int a1)
{
return malloc(a1);
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
return malloc(a1);
}

original_code:
char* CuStrAlloc(int size)
{
 char* newStr = (char*) malloc( sizeof(char) * (size) );
 return newStr;
}

canonical_original_code:
char *CuStrAlloc(int size)
{
 char *newStr = (char*) malloc( sizeof(char) * (size) );
 return newStr;
}

variable_types: size int

variable_types:
newStr
char *

return_type: char *


CuStrCopy

decompiled_code:
char *__fastcall CuStrCopy(char *src)
{
int v1; // eax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)CuStrAlloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
int v1; // eax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)func0(v1 + 1);
return strcpy(v2, src);
}

original_code:
char* CuStrCopy(const char* old)
{
 int len = strlen(old);
 char* newStr = CuStrAlloc(len + 1);
 strcpy(newStr, old);
 return newStr;
}

canonical_original_code:
char *CuStrCopy(char *old)
{
 int len = strlen(old);
 char *newStr = CuStrAlloc(len + 1);
 strcpy(newStr, old);
 return newStr;
}

variable_types:
old
char *

variable_types: len int


CuStringNew

decompiled_code:
_DWORD *CuStringNew()
{
_DWORD *v0; // rbx
_BYTE *v1; // rax

v0 = malloc(0x10uLL);
*v0 = 0;
v0[1] = 256;
v1 = malloc(0x100uLL);
*((_QWORD *)v0 + 1) = v1;
*v1 = 0;
return v0;
}

original_code:
CuString* CuStringNew(void)
{
 CuString* str = (CuString*) malloc(sizeof(CuString));
 str->length = 0;
 str->size = 256;
 str->buffer = (char*) malloc(sizeof(char) * str->size);
 str->buffer[0] = '\0';
 return str;
}

canonical_original_code:
struct CuString *CuStringNew()
{
 struct CuString *str = (CuString*) malloc(sizeof(CuString));
 str->length = 0;
 str->size = 256;
 str->buffer = (char *) malloc(sizeof(char) * str->size);
 str->buffer[0] = '\0';
 return str;
}

variable_types: struct CuString { int length; int size; char *buffer; } *


CuStringResize

decompiled_code:
void *__fastcall CuStringResize(__int64 a1, int a2)
{
void *result; // rax

result = realloc(*(void **)(a1 + 8), a2);
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 4) = a2;
return result;
}

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

result = realloc(*(void **)(a1 + 8), a2);
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 4) = a2;
return result;
}

original_code:
void CuStringResize(CuString* str, int newSize)
{
 str->buffer = (char*) realloc(str->buffer, sizeof(char) * newSize);
 str->size = newSize;
}

canonical_original_code:
void CuStringResize(struct CuString *str, int newSize)
{
 str->buffer = (char *) realloc(str->buffer, sizeof(char) * newSize);
 str->size = newSize;
}

variable_types: newSize int

user_defined_types: struct CuString { int length; int size; char *buffer; }


CuStringAppend

decompiled_code:
char *__fastcall CuStringAppend(__int64 a1, const char *a2)
{
const char *v2; // rbp
int v3; // er12
int v4; // esi

v2 = a2;
if ( !a2 )
v2 = "NULL";
v3 = strlen(v2);
v4 = *(_DWORD *)a1 + v3;
if ( v4 + 1 >= *(_DWORD *)(a1 + 4) )
CuStringResize(a1, v4 + 257);
*(_DWORD *)a1 += v3;
return strcat(*(char **)(a1 + 8), v2);
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1, const char *a2)
{
const char *v2; // rbp
int v3; // er12
int v4; // esi

v2 = a2;
if ( !a2 )
v2 = "NULL";
v3 = strlen(v2);
v4 = *(_DWORD *)a1 + v3;
if ( v4 + 1 >= *(_DWORD *)(a1 + 4) )
func3(a1, v4 + 257);
*(_DWORD *)a1 += v3;
return strcat(*(char **)(a1 + 8), v2);
}

original_code:
void CuStringAppend(CuString* str, const char* text)
{
 int length;
 if (text == ((void *)0)) {
  text = "NULL";
 }
 length = strlen(text);
 if (str->length + length + 1 >= str->size)
  CuStringResize(str, str->length + length + 1 + 256);
 str->length += length;
 strcat(str->buffer, text);
}

canonical_original_code:
void CuStringAppend(struct CuString *str, char *text)
{
 int length;
 if (text == ((void *)0)) {
  text = "NULL";
 }
 length = strlen(text);
 if (str->length + length + 1 >= str->size)
  CuStringResize(str, str->length + length + 1 + 256);
 str->length += length;
 strcat(str->buffer, text);
}

variable_types:
text
char *

variable_types: length int


CuStringAppendChar

decompiled_code:
char *__fastcall CuStringAppendChar(__int64 a1, char a2)
{
char v3[10]; // [rsp+Eh] [rbp-Ah] BYREF

v3[0] = a2;
v3[1] = 0;
return CuStringAppend(a1, v3);
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1, char a2)
{
char v3[10]; // [rsp+Eh] [rbp-Ah] BYREF

v3[0] = a2;
v3[1] = 0;
return func4(a1, v3);
}

original_code:
void CuStringAppendChar(CuString* str, char ch)
{
 char text[2];
 text[0] = ch;
 text[1] = '\0';
 CuStringAppend(str, text);
}

canonical_original_code:
void CuStringAppendChar(struct CuString *str, char ch)
{
 char text[2];
 text[0] = ch;
 text[1] = '\0';
 CuStringAppend(str, text);
}

variable_types: ch char

variable_types:
text
char [2]


CuStringAppendFormat

decompiled_code:
char *CuStringAppendFormat(__int64 a1, const char *a2, ...)
{
char v3[8200]; // [rsp+0h] [rbp-20D8h] BYREF
gcc_va_list arg; // [rsp+2008h] [rbp-D0h] BYREF

va_start(arg, a2);
vsprintf(v3, a2, arg);
return CuStringAppend(a1, v3);
}

canonical_decompiled_code:
char *func6(__int64 a1, const char *a2, ...)
{
char v3[8200]; // [rsp+0h] [rbp-20D8h] BYREF
gcc_va_list arg; // [rsp+2008h] [rbp-D0h] BYREF

va_start(arg, a2);
vsprintf(v3, a2, arg);
return func4(a1, v3);
}

original_code:
void CuStringAppendFormat(CuString* str, const char* format, ...)
{
 va_list argp;
 char buf[8192];
 __builtin_va_start(argp,format);
 vsprintf(buf, format, argp);
 __builtin_va_end(argp);
 CuStringAppend(str, buf);
}

canonical_original_code:
void CuStringAppendFormat(struct CuString *str, char *format, ...)
{
 __builtin_va_list argp;
 char buf[8192];
 __builtin_va_start(argp,format);
 vsprintf(buf, format, argp);
 __builtin_va_end(argp);
 CuStringAppend(str, buf);
}

variable_types:
format
char *

variable_types:
buf
char [8192]


CuStringInsert

decompiled_code:
void *__fastcall CuStringInsert(__int64 a1, const char *a2, int a3)
{
int v5; // eax
int v6; // er12
int v7; // esi

v5 = strlen(a2);
v6 = v5;
if ( *(_DWORD *)a1 <= a3 )
a3 = *(_DWORD *)a1;
v7 = v5 + *(_DWORD *)a1;
if ( v7 + 1 >= *(_DWORD *)(a1 + 4) )
CuStringResize(a1, v7 + 257);
memmove(
(void *)(*(_QWORD *)(a1 + 8) + a3 + (__int64)v6),
(const void *)(*(_QWORD *)(a1 + 8) + a3),
*(_DWORD *)a1 - a3 + 1);
*(_DWORD *)a1 += v6;
return memcpy((void *)(*(_QWORD *)(a1 + 8) + a3), a2, v6);
}

original_code:
void CuStringInsert(CuString* str, const char* text, int pos)
{
 int length = strlen(text);
 if (pos > str->length)
  pos = str->length;
 if (str->length + length + 1 >= str->size)
  CuStringResize(str, str->length + length + 1 + 256);
 memmove(str->buffer + pos + length, str->buffer + pos, (str->length - pos) + 1);
 str->length += length;
 memcpy(str->buffer + pos, text, length);
}

canonical_original_code:
void CuStringInsert(struct CuString *str, char *text, int pos)
{
 int length = strlen(text);
 if (pos > str->length)
  pos = str->length;
 if (str->length + length + 1 >= str->size)
  CuStringResize(str, str->length + length + 1 + 256);
 memmove(str->buffer + pos + length, str->buffer + pos, (str->length - pos) + 1);
 str->length += length;
 memcpy(str->buffer + pos, text, length);
}

variable_types: pos int


CuFailInternal

decompiled_code:
__int64 __fastcall CuFailInternal(__int64 a1, const char *a2, unsigned int a3, __int64 a4)
{
__int64 result; // rax
struct __jmp_buf_tag *v6; // rdi
char v7[8216]; // [rsp+0h] [rbp-2018h] BYREF

sprintf(v7, "%s:%d: ", a2, a3);
CuStringInsert(a4, v7, 0);
*(_DWORD *)(a1 + 16) = 1;
result = *(_QWORD *)(a4 + 8);
*(_QWORD *)(a1 + 24) = result;
v6 = *(struct __jmp_buf_tag **)(a1 + 32);
if ( v6 )
longjmp(v6, 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2, unsigned int a3, __int64 a4)
{
__int64 result; // rax
struct __jmp_buf_tag *v6; // rdi
char v7[8216]; // [rsp+0h] [rbp-2018h] BYREF

sprintf(v7, "%s:%d: ", a2, a3);
func7(a4, v7, 0);
*(_DWORD *)(a1 + 16) = 1;
result = *(_QWORD *)(a4 + 8);
*(_QWORD *)(a1 + 24) = result;
v6 = *(struct __jmp_buf_tag **)(a1 + 32);
if ( v6 )
longjmp(v6, 0);
return result;
}

original_code:
static void CuFailInternal(CuTest* tc, const char* file, int line, CuString* string)
{
 char buf[8192];
 sprintf(buf, "%s:%d: ", file, line);
 CuStringInsert(string, buf, 0);
 tc->failed = 1;
 tc->message = string->buffer;
 if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0);
}

canonical_original_code:
static void CuFailInternal(struct CuTest *tc, char *file, int line, struct CuString *string)
{
 char buf[8192];
 sprintf(buf, "%s:%d: ", file, line);
 CuStringInsert(string, buf, 0);
 tc->failed = 1;
 tc->message = string->buffer;
 if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0);
}

variable_types: struct CuTest { char *name; void (*function)(struct CuTest *); int failed; int ran; char *message; struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } (*jumpBuf)[1]; } *

variable_types:
file
char *

variable_types: line int

user_defined_types: struct CuTest { char *name; void (*function)(struct CuTest *); int failed; int ran; char *message; struct __jmp_buf_tag (*jumpBuf)[1]; }

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


CuTestInit

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

result = CuStrCopy(a2);
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)(a1 + 20) = 0;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 8) = a3;
*(_QWORD *)(a1 + 32) = 0LL;
return result;
}

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

result = func1(a2);
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)(a1 + 20) = 0;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 8) = a3;
*(_QWORD *)(a1 + 32) = 0LL;
return result;
}

original_code:
void CuTestInit(CuTest* t, const char* name, TestFunction function)
{
 t->name = CuStrCopy(name);
 t->failed = 0;
 t->ran = 0;
 t->message = ((void *)0);
 t->function = function;
 t->jumpBuf = ((void *)0);
}

canonical_original_code:
void CuTestInit(struct CuTest *t, char *name, void (*function)(struct CuTest *))
{
 t->name = CuStrCopy(name);
 t->failed = 0;
 t->ran = 0;
 t->message = ((void *)0);
 t->function = function;
 t->jumpBuf = ((void *)0);
}

variable_types:
name
char *

variable_types:
function
void (*)(struct CuTest *)

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }


CuTestNew

decompiled_code:
void *__fastcall CuTestNew(char *a1, __int64 a2)
{
void *v2; // rbx

v2 = malloc(0x28uLL);
CuTestInit((__int64)v2, a1, a2);
return v2;
}

canonical_decompiled_code:
void *__fastcall func10(char *a1, __int64 a2)
{
void *v2; // rbx

v2 = malloc(0x28uLL);
func9((__int64)v2, a1, a2);
return v2;
}

original_code:
CuTest* CuTestNew(const char* name, TestFunction function)
{
 CuTest* tc = ((CuTest*) malloc(sizeof(CuTest)));
 CuTestInit(tc, name, function);
 return tc;
}

canonical_original_code:
struct CuTest *CuTestNew(char *name, void (*function)(struct CuTest *))
{
 struct CuTest *tc = ((CuTest*) malloc(sizeof(CuTest)));
 CuTestInit(tc, name, function);
 return tc;
}

return_type: struct CuTest { char *name; void (*function)(struct CuTest *); int failed; int ran; char *message; struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } (*jumpBuf)[1]; } *


CuTestRun

decompiled_code:
__int64 __fastcall CuTestRun(__int64 a1)
{
__int64 result; // rax
jmp_buf env; // [rsp+10h] [rbp-D8h] BYREF

*(_QWORD *)(a1 + 32) = env;
if ( !setjmp(env) )
{
*(_DWORD *)(a1 + 20) = 1;
(*(void (__fastcall **)(__int64))(a1 + 8))(a1);
}
result = a1;
*(_QWORD *)(a1 + 32) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 result; // rax
jmp_buf env; // [rsp+10h] [rbp-D8h] BYREF

*(_QWORD *)(a1 + 32) = env;
if ( !setjmp(env) )
{
*(_DWORD *)(a1 + 20) = 1;
(*(void (__fastcall **)(__int64))(a1 + 8))(a1);
}
result = a1;
*(_QWORD *)(a1 + 32) = 0LL;
return result;
}

original_code:
void CuTestRun(CuTest* tc)
{
 jmp_buf buf;
 tc->jumpBuf = &buf;
 if (_setjmp (buf) == 0)
 {
  tc->ran = 1;
  (tc->function)(tc);
 }
 tc->jumpBuf = 0;
}

canonical_original_code:
void CuTestRun(struct CuTest *tc)
{
 struct __jmp_buf_tag buf[1];
 tc->jumpBuf = &buf;
 if (_setjmp (buf) == 0)
 {
  tc->ran = 1;
  (tc->function)(tc);
 }
 tc->jumpBuf = 0;
}

variable_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } [1]


decompiled_code:
__int64 __fastcall CuFail_Line(__int64 a1, const char *a2, unsigned int a3, const char *a4, const char *a5)
{
_BYTE v9[56]; // [rsp+0h] [rbp-38h] BYREF

CuStringInit((__int64)v9);
if ( a4 )
{
CuStringAppend((__int64)v9, a4);
CuStringAppend((__int64)v9, ": ");
}
CuStringAppend((__int64)v9, a5);
return CuFailInternal(a1, a2, a3, (__int64)v9);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const char *a2, unsigned int a3, const char *a4, const char *a5)
{
_BYTE v9[56]; // [rsp+0h] [rbp-38h] BYREF

CuStringInit((__int64)v9);
if ( a4 )
{
func4((__int64)v9, a4);
func4((__int64)v9, ": ");
}
func4((__int64)v9, a5);
return func8(a1, a2, a3, (__int64)v9);
}

original_code:
void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message)
{
 CuString string;
 CuStringInit(&string);
 if (message2 != ((void *)0))
 {
  CuStringAppend(&string, message2);
  CuStringAppend(&string, ": ");
 }
 CuStringAppend(&string, message);
 CuFailInternal(tc, file, line, &string);
}

canonical_original_code:
void CuFail_Line(struct CuTest *tc, char *file, int line, char *message2, char *message)
{
 struct CuString string;
 CuStringInit(&string);
 if (message2 != ((void *)0))
 {
  CuStringAppend(&string, message2);
  CuStringAppend(&string, ": ");
 }
 CuStringAppend(&string, message);
 CuFailInternal(tc, file, line, &string);
}

variable_types:
message
char *

variable_types: struct CuString { int length; int size; char *buffer; }


decompiled_code:
__int64 __fastcall CuAssert_Line(__int64 a1, const char *a2, unsigned int a3, const char *a4, int a5)
{
__int64 result; // rax

if ( !a5 )
result = CuFail_Line(a1, a2, a3, 0LL, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, const char *a2, unsigned int a3, const char *a4, int a5)
{
__int64 result; // rax

if ( !a5 )
result = func12(a1, a2, a3, 0LL, a4);
return result;
}

original_code:
void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message, int condition)
{
 if (condition) return;
 CuFail_Line(tc, file, line, ((void *)0), message);
}

canonical_original_code:
void CuAssert_Line(struct CuTest *tc, char *file, int line, char *message, int condition)
{
 if (condition) return;
 CuFail_Line(tc, file, line, ((void *)0), message);
}

variable_types: condition int


decompiled_code:
int __fastcall CuAssertStrEquals_LineMsg(__int64 a1, const char *a2, unsigned int a3, const char *a4, const char *a5, const char *a6)
{
int result; // eax
_BYTE v11[72]; // [rsp-48h] [rbp-48h] BYREF

result = (unsigned int)a6 | (unsigned int)a5;
if ( (unsigned __int64)a6 | (unsigned __int64)a5 )
{
if ( !a5 || !a6 || (result = strcmp(a5, a6)) != 0 )
{
CuStringInit((__int64)v11);
if ( a4 )
{
CuStringAppend((__int64)v11, a4);
CuStringAppend((__int64)v11, ": ");
}
CuStringAppend((__int64)v11, "expected <");
CuStringAppend((__int64)v11, a5);
CuStringAppend((__int64)v11, "> but was <");
CuStringAppend((__int64)v11, a6);
CuStringAppend((__int64)v11, ">");
result = CuFailInternal(a1, a2, a3, (__int64)v11);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, const char *a2, unsigned int a3, const char *a4, const char *a5, const char *a6)
{
int result; // eax
_BYTE v11[72]; // [rsp-48h] [rbp-48h] BYREF

result = (unsigned int)a6 | (unsigned int)a5;
if ( (unsigned __int64)a6 | (unsigned __int64)a5 )
{
if ( !a5 || !a6 || (result = strcmp(a5, a6)) != 0 )
{
CuStringInit((__int64)v11);
if ( a4 )
{
func4((__int64)v11, a4);
func4((__int64)v11, ": ");
}
func4((__int64)v11, "expected <");
func4((__int64)v11, a5);
func4((__int64)v11, "> but was <");
func4((__int64)v11, a6);
func4((__int64)v11, ">");
result = func8(a1, a2, a3, (__int64)v11);
}
}
return result;
}

original_code:
void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
 const char* expected, const char* actual)
{
 CuString string;
 if ((expected == ((void *)0) && actual == ((void *)0)) ||
     (expected != ((void *)0) && actual != ((void *)0) &&
      strcmp(expected, actual) == 0))
 {
  return;
 }
 CuStringInit(&string);
 if (message != ((void *)0))
 {
  CuStringAppend(&string, message);
  CuStringAppend(&string, ": ");
 }
 CuStringAppend(&string, "expected <");
 CuStringAppend(&string, expected);
 CuStringAppend(&string, "> but was <");
 CuStringAppend(&string, actual);
 CuStringAppend(&string, ">");
 CuFailInternal(tc, file, line, &string);
}

canonical_original_code:
void CuAssertStrEquals_LineMsg(struct CuTest *tc, char *file, int line, char *message, char *expected, char *actual)
{
 struct CuString string;
 if ((expected == ((void *)0) && actual == ((void *)0)) ||
     (expected != ((void *)0) && actual != ((void *)0) &&
      strcmp(expected, actual) == 0))
 {
  return;
 }
 CuStringInit(&string);
 if (message != ((void *)0))
 {
  CuStringAppend(&string, message);
  CuStringAppend(&string, ": ");
 }
 CuStringAppend(&string, "expected <");
 CuStringAppend(&string, expected);
 CuStringAppend(&string, "> but was <");
 CuStringAppend(&string, actual);
 CuStringAppend(&string, ">");
 CuFailInternal(tc, file, line, &string);
}

variable_types:
expected
char *

variable_types:
actual
char *


decompiled_code:
__int64 __fastcall CuAssertIntEquals_LineMsg(__int64 a1, const char *a2, unsigned int a3, const char *a4, unsigned int a5, unsigned int a6)
{
__int64 result; // rax
char v9[296]; // [rsp-128h] [rbp-128h] BYREF

if ( a5 != a6 )
{
sprintf(v9, "expected <%d> but was <%d>", a5, a6);
result = CuFail_Line(a1, a2, a3, a4, v9);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, const char *a2, unsigned int a3, const char *a4, unsigned int a5, unsigned int a6)
{
__int64 result; // rax
char v9[296]; // [rsp-128h] [rbp-128h] BYREF

if ( a5 != a6 )
{
sprintf(v9, "expected <%d> but was <%d>", a5, a6);
result = func12(a1, a2, a3, a4, v9);
}
return result;
}

original_code:
void CuAssertIntEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
 int expected, int actual)
{
 char buf[256];
 if (expected == actual) return;
 sprintf(buf, "expected <%d> but was <%d>", expected, actual);
 CuFail_Line(tc, file, line, message, buf);
}

canonical_original_code:
void CuAssertIntEquals_LineMsg(struct CuTest *tc, char *file, int line, char *message, int expected, int actual)
{
 char buf[256];
 if (expected == actual) return;
 sprintf(buf, "expected <%d> but was <%d>", expected, actual);
 CuFail_Line(tc, file, line, message, buf);
}

variable_types: expected int

variable_types: actual int

variable_types:
buf
char [256]


decompiled_code:
__int64 __fastcall CuAssertDblEquals_LineMsg(__int64 a1, const char *a2, unsigned int a3, const char *a4, double a5, double a6, double a7)
{
__int64 result; // rax
char v10[296]; // [rsp-128h] [rbp-128h] BYREF

if ( a7 < COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a5 - a6) & LC7) )
{
sprintf(v10, "expected <%lf> but was <%lf>", a5, a6);
result = CuFail_Line(a1, a2, a3, a4, v10);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, const char *a2, unsigned int a3, const char *a4, double a5, double a6, double a7)
{
__int64 result; // rax
char v10[296]; // [rsp-128h] [rbp-128h] BYREF

if ( a7 < COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a5 - a6) & LC7) )
{
sprintf(v10, "expected <%lf> but was <%lf>", a5, a6);
result = func12(a1, a2, a3, a4, v10);
}
return result;
}

original_code:
void CuAssertDblEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
 double expected, double actual, double delta)
{
 char buf[256];
 if (fabs(expected - actual) <= delta) return;
 sprintf(buf, "expected <%lf> but was <%lf>", expected, actual);
 CuFail_Line(tc, file, line, message, buf);
}

canonical_original_code:
void CuAssertDblEquals_LineMsg(struct CuTest *tc, char *file, int line, char *message, double expected, double actual, double delta)
{
 char buf[256];
 if (fabs(expected - actual) <= delta) return;
 sprintf(buf, "expected <%lf> but was <%lf>", expected, actual);
 CuFail_Line(tc, file, line, message, buf);
}

variable_types: expected double

variable_types: actual double

variable_types: delta double


decompiled_code:
__int64 __fastcall CuAssertPtrEquals_LineMsg(__int64 a1, const char *a2, unsigned int a3, const char *a4, const void *a5, const void *a6)
{
__int64 result; // rax
char v9[296]; // [rsp-128h] [rbp-128h] BYREF

if ( a5 != a6 )
{
sprintf(v9, "expected pointer <0x%p> but was <0x%p>", a5, a6);
result = CuFail_Line(a1, a2, a3, a4, v9);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, const char *a2, unsigned int a3, const char *a4, const void *a5, const void *a6)
{
__int64 result; // rax
char v9[296]; // [rsp-128h] [rbp-128h] BYREF

if ( a5 != a6 )
{
sprintf(v9, "expected pointer <0x%p> but was <0x%p>", a5, a6);
result = func12(a1, a2, a3, a4, v9);
}
return result;
}

original_code:
void CuAssertPtrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
 void* expected, void* actual)
{
 char buf[256];
 if (expected == actual) return;
 sprintf(buf, "expected pointer <0x%p> but was <0x%p>", expected, actual);
 CuFail_Line(tc, file, line, message, buf);
}

canonical_original_code:
void CuAssertPtrEquals_LineMsg(struct CuTest *tc, char *file, int line, char *message, void *expected, void *actual)
{
 char buf[256];
 if (expected == actual) return;
 sprintf(buf, "expected pointer <0x%p> but was <0x%p>", expected, actual);
 CuFail_Line(tc, file, line, message, buf);
}

variable_types: struct CuTest { char *name; void (*function)(struct CuTest *); int failed; int ran; char *message; struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } (*jumpBuf)[1]; } *

variable_types:
expected
void *

variable_types:
actual
void *


CuSuiteNew

decompiled_code:
_DWORD *CuSuiteNew()
{
_DWORD *v0; // rbx

v0 = malloc(0x2010uLL);
CuSuiteInit(v0);
return v0;
}

canonical_decompiled_code:
_DWORD *func19()
{
_DWORD *v0; // rbx

v0 = malloc(0x2010uLL);
func18(v0);
return v0;
}

original_code:
CuSuite* CuSuiteNew(void)
{
 CuSuite* testSuite = ((CuSuite*) malloc(sizeof(CuSuite)));
 CuSuiteInit(testSuite);
 return testSuite;
}

canonical_original_code:
struct CuSuite *CuSuiteNew()
{
 struct CuSuite *testSuite = ((CuSuite*) malloc(sizeof(CuSuite)));
 CuSuiteInit(testSuite);
 return testSuite;
}

variable_types: struct CuSuite { int count; struct CuTest { char *name; void (*function)(struct CuTest *); int failed; int ran; char *message; struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } (*jumpBuf)[1]; } *list[1024]; int failCount; } *

user_defined_types: struct CuSuite { int count; struct CuTest *list[1024]; int failCount; }


CuSuiteAdd

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

v2 = *a1;
if ( *a1 > 1023 )
_assert_fail("testSuite->count < MAX_TEST_CASES", "CuTest.c", 0xEEu, "CuSuiteAdd");
*(_QWORD *)&a1[2 * v2 + 2] = a2;
result = (unsigned int)(v2 + 1);
*a1 = result;
return result;
}

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

v2 = *a1;
if ( *a1 > 1023 )
_assert_fail("testSuite->count < MAX_TEST_CASES", "CuTest.c", 0xEEu, "CuSuiteAdd");
*(_QWORD *)&a1[2 * v2 + 2] = a2;
result = (unsigned int)(v2 + 1);
*a1 = result;
return result;
}

original_code:
void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase)
{
 ((void) sizeof ((testSuite->count < 1024) ? 1 : 0), __extension__ ({ if (testSuite->count < 1024) ; else __assert_fail ("testSuite->count < MAX_TEST_CASES", "CuTest.c", 238, __extension__ __PRETTY_FUNCTION__); }));
 testSuite->list[testSuite->count] = testCase;
 testSuite->count++;
}

canonical_original_code:
void CuSuiteAdd(struct CuSuite *testSuite, struct CuTest *testCase)
{
 ((void) sizeof ((testSuite->count < 1024) ? 1 : 0), __extension__ ({ if (testSuite->count < 1024) ; else __assert_fail ("testSuite->count < MAX_TEST_CASES", "CuTest.c", 238, __extension__ __PRETTY_FUNCTION__); }));
 testSuite->list[testSuite->count] = testCase;
 testSuite->count++;
}

variable_types:
testCase
struct CuTest *


CuSuiteAddSuite

decompiled_code:
__int64 __fastcall CuSuiteAddSuite(int *a1, int *a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( *a2 > 0 )
{
v2 = 0LL;
do
result = CuSuiteAdd(a1, *(_QWORD *)&a2[2 * v2++ + 2]);
while ( *a2 > (int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(int *a1, int *a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( *a2 > 0 )
{
v2 = 0LL;
do
result = func20(a1, *(_QWORD *)&a2[2 * v2++ + 2]);
while ( *a2 > (int)v2 );
}
return result;
}

original_code:
void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2)
{
 int i;
 for (i = 0 ; i < testSuite2->count ; ++i)
 {
  CuTest* testCase = testSuite2->list[i];
  CuSuiteAdd(testSuite, testCase);
 }
}

canonical_original_code:
void CuSuiteAddSuite(struct CuSuite *testSuite, struct CuSuite *testSuite2)
{
 int i;
 for (i = 0 ; i < testSuite2->count ; ++i)
 {
  struct CuTest *testCase = testSuite2->list[i];
  CuSuiteAdd(testSuite, testCase);
 }
}

variable_types: i int


CuSuiteRun

decompiled_code:
__int64 __fastcall CuSuiteRun(int *a1)
{
__int64 v1; // rbx
__int64 v2; // r12
__int64 result; // rax

if ( *a1 > 0 )
{
v1 = 0LL;
do
{
v2 = *(_QWORD *)&a1[2 * v1 + 2];
result = CuTestRun(v2);
if ( *(_DWORD *)(v2 + 16) )
++a1[2050];
++v1;
}
while ( *a1 > (int)v1 );
}
return result;
}

original_code:
void CuSuiteRun(CuSuite* testSuite)
{
 int i;
 for (i = 0 ; i < testSuite->count ; ++i)
 {
  CuTest* testCase = testSuite->list[i];
  CuTestRun(testCase);
  if (testCase->failed) { testSuite->failCount += 1; }
 }
}

canonical_original_code:
void CuSuiteRun(struct CuSuite *testSuite)
{
 int i;
 for (i = 0 ; i < testSuite->count ; ++i)
 {
  struct CuTest *testCase = testSuite->list[i];
  CuTestRun(testCase);
  if (testCase->failed) { testSuite->failCount += 1; }
 }
}


CuSuiteSummary

decompiled_code:
char *__fastcall CuSuiteSummary(int *a1, __int64 a2)
{
__int64 v3; // rbx
const char *v4; // rsi

if ( *a1 > 0 )
{
v3 = 0LL;
do
{
v4 = ".";
if ( *(_DWORD *)(*(_QWORD *)&a1[2 * v3 + 2] + 16LL) )
v4 = "F";
CuStringAppend(a2, v4);
++v3;
}
while ( *a1 > (int)v3 );
}
return CuStringAppend(a2, "\n\n");
}

original_code:
void CuSuiteSummary(CuSuite* testSuite, CuString* summary)
{
 int i;
 for (i = 0 ; i < testSuite->count ; ++i)
 {
  CuTest* testCase = testSuite->list[i];
  CuStringAppend(summary, testCase->failed ? "F" : ".");
 }
 CuStringAppend(summary, "\n\n");
}

canonical_original_code:
void CuSuiteSummary(struct CuSuite *testSuite, struct CuString *summary)
{
 int i;
 for (i = 0 ; i < testSuite->count ; ++i)
 {
  struct CuTest *testCase = testSuite->list[i];
  CuStringAppend(summary, testCase->failed ? "F" : ".");
 }
 CuStringAppend(summary, "\n\n");
}

variable_types: struct CuString { int length; int size; char *buffer; } *


CuSuiteDetails

decompiled_code:
char *__fastcall CuSuiteDetails(unsigned int *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rdx
const char *v4; // rcx
char *result; // rax
__int64 v6; // rbx
int i; // er13
__int64 v8; // rax

v2 = a1[2050];
if ( (_DWORD)v2 )
{
if ( (_DWORD)v2 == 1 )
CuStringAppend(a2, "There was 1 failure:\n");
else
CuStringAppendFormat(a2, "There were %d failures:\n", v2);
v6 = 0LL;
for ( i = 0; (int)*a1 > (int)v6; ++v6 )
{
v8 = *(_QWORD *)&a1[2 * v6 + 2];
if ( *(_DWORD *)(v8 + 16) )
CuStringAppendFormat(a2, "%d) %s: %s\n", (unsigned int)++i, *(const char **)v8, *(const char **)(v8 + 24));
}
CuStringAppend(a2, "\n!!!FAILURES!!!\n");
CuStringAppendFormat(a2, "Runs: %d ", *a1);
CuStringAppendFormat(a2, "Passes: %d ", *a1 - a1[2050]);
result = CuStringAppendFormat(a2, "Fails: %d\n", a1[2050]);
}
else
{
v3 = *a1;
v4 = "test";
if ( (_DWORD)v3 != 1 )
v4 = "tests";
result = CuStringAppendFormat(a2, "OK (%d %s)\n", v3, v4);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func24(unsigned int *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rdx
const char *v4; // rcx
char *result; // rax
__int64 v6; // rbx
int i; // er13
__int64 v8; // rax

v2 = a1[2050];
if ( (_DWORD)v2 )
{
if ( (_DWORD)v2 == 1 )
func4(a2, "There was 1 failure:\n");
else
func6(a2, "There were %d failures:\n", v2);
v6 = 0LL;
for ( i = 0; (int)*a1 > (int)v6; ++v6 )
{
v8 = *(_QWORD *)&a1[2 * v6 + 2];
if ( *(_DWORD *)(v8 + 16) )
func6(a2, "%d) %s: %s\n", (unsigned int)++i, *(const char **)v8, *(const char **)(v8 + 24));
}
func4(a2, "\n!!!FAILURES!!!\n");
func6(a2, "Runs: %d ", *a1);
func6(a2, "Passes: %d ", *a1 - a1[2050]);
result = func6(a2, "Fails: %d\n", a1[2050]);
}
else
{
v3 = *a1;
v4 = "test";
if ( (_DWORD)v3 != 1 )
v4 = "tests";
result = func6(a2, "OK (%d %s)\n", v3, v4);
}
return result;
}

original_code:
void CuSuiteDetails(CuSuite* testSuite, CuString* details)
{
 int i;
 int failCount = 0;
 if (testSuite->failCount == 0)
 {
  int passCount = testSuite->count - testSuite->failCount;
  const char* testWord = passCount == 1 ? "test" : "tests";
  CuStringAppendFormat(details, "OK (%d %s)\n", passCount, testWord);
 }
 else
 {
  if (testSuite->failCount == 1)
   CuStringAppend(details, "There was 1 failure:\n");
  else
   CuStringAppendFormat(details, "There were %d failures:\n", testSuite->failCount);
  for (i = 0 ; i < testSuite->count ; ++i)
  {
   CuTest* testCase = testSuite->list[i];
   if (testCase->failed)
   {
    failCount++;
    CuStringAppendFormat(details, "%d) %s: %s\n",
     failCount, testCase->name, testCase->message);
   }
  }
  CuStringAppend(details, "\n!!!FAILURES!!!\n");
  CuStringAppendFormat(details, "Runs: %d ", testSuite->count);
  CuStringAppendFormat(details, "Passes: %d ", testSuite->count - testSuite->failCount);
  CuStringAppendFormat(details, "Fails: %d\n", testSuite->failCount);
 }
}

canonical_original_code:
void CuSuiteDetails(struct CuSuite *testSuite, struct CuString *details)
{
 int i;
 int failCount = 0;
 if (testSuite->failCount == 0)
 {
  int passCount = testSuite->count - testSuite->failCount;
  char *testWord = passCount == 1 ? "test" : "tests";
  CuStringAppendFormat(details, "OK (%d %s)\n", passCount, testWord);
 }
 else
 {
  if (testSuite->failCount == 1)
   CuStringAppend(details, "There was 1 failure:\n");
  else
   CuStringAppendFormat(details, "There were %d failures:\n", testSuite->failCount);
  for (i = 0 ; i < testSuite->count ; ++i)
  {
   struct CuTest *testCase = testSuite->list[i];
   if (testCase->failed)
   {
    failCount++;
    CuStringAppendFormat(details, "%d) %s: %s\n",
     failCount, testCase->name, testCase->message);
   }
  }
  CuStringAppend(details, "\n!!!FAILURES!!!\n");
  CuStringAppendFormat(details, "Runs: %d ", testSuite->count);
  CuStringAppendFormat(details, "Passes: %d ", testSuite->count - testSuite->failCount);
  CuStringAppendFormat(details, "Fails: %d\n", testSuite->failCount);
 }
}

variable_types: failCount int

variable_types: passCount int

variable_types:
testWord
char *


decompiled_code:
void __fastcall __noreturn nids_no_mem(const char *a1)
{
fprintf(stderr, "Out of memory in %s.\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "Out of memory in %s.\n", a1);
exit(1);
}

original_code:
void
nids_no_mem(char *func)
{
  fprintf(stderr, "Out of memory in %s.\n", func);
  exit(1);
}

variable_types:
func
char *


decompiled_code:
void *__fastcall test_malloc(int a1)
{
void *v1; // rbx

v1 = malloc(a1);
if ( !v1 )
nids_params[7]("test_malloc");
return v1;
}

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
void *v1; // rbx

v1 = malloc(a1);
if ( !v1 )
nids_params[7]("test_malloc");
return v1;
}

original_code:
char *
test_malloc(int x)
{
  char *ret = malloc(x);
  if (!ret)
    nids_params.no_mem("test_malloc");
  return ret;
}

canonical_original_code:
char *test_malloc(int x)
{
  char *ret = malloc(x);
  if (!ret)
    nids_params.no_mem("test_malloc");
  return ret;
}

variable_types: x int

variable_types:
ret
char *


decompiled_code:
void __fastcall unregister_callback(_QWORD **a1, __int64 a2)
{
_QWORD *v3; // rdi
_QWORD *v4; // rdx

v3 = *a1;
if ( v3 )
{
v4 = 0LL;
while ( *v3 != a2 )
{
v4 = v3;
if ( !v3[1] )
return;
v3 = (_QWORD *)v3[1];
}
if ( v4 )
v4[1] = v3[1];
else
*a1 = (_QWORD *)v3[1];
free(v3);
}
}

original_code:
void
unregister_callback(struct proc_node **procs, void (*x))
{
  struct proc_node *ipp;
  struct proc_node *ipp_prev = 0;
  for (ipp = *procs; ipp; ipp = ipp->next) {
    if (x == ipp->item) {
      if (ipp_prev)
 ipp_prev->next = ipp->next;
      else
 *procs = ipp->next;
      free(ipp);
      return;
    }
    ipp_prev = ipp;
  }
}

canonical_original_code:
void unregister_callback(struct proc_node **procs, void *x)
{
  struct proc_node *ipp;
  struct proc_node *ipp_prev = 0;
  for (ipp = *procs; ipp; ipp = ipp->next) {
    if (x == ipp->item) {
      if (ipp_prev)
 ipp_prev->next = ipp->next;
      else
 *procs = ipp->next;
      free(ipp);
      return;
    }
    ipp_prev = ipp;
  }
}

variable_types: struct proc_node { void (*item)(); struct proc_node *next; } **

variable_types:
x
void *


dontchksum

decompiled_code:
__int64 __fastcall dontchksum(int a1)
{
_DWORD *v1; // rax

if ( nrnochksum <= 0 )
return 0LL;
v1 = (_DWORD *)nchk;
while ( (v1[1] & a1) != *v1 )
{
v1 += 4;
if ( v1 == (_DWORD *)(nchk + 16LL * (unsigned int)(nrnochksum - 1) + 16) )
return 0LL;
}
return (unsigned int)v1[2];
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
_DWORD *v1; // rax

if ( nrnochksum <= 0 )
return 0LL;
v1 = (_DWORD *)nchk;
while ( (v1[1] & a1) != *v1 )
{
v1 += 4;
if ( v1 == (_DWORD *)(nchk + 16LL * (unsigned int)(nrnochksum - 1) + 16) )
return 0LL;
}
return (unsigned int)v1[2];
}

original_code:
static int dontchksum(unsigned int ip)
{
 int i;
  for (i=0;i<nrnochksum;i++)
   if ((ip & nchk[i].mask)==nchk[i].netaddr)
    return nchk[i].action;
 return 0;
}

variable_types:
ip
unsigned int


decompiled_code:
void __fastcall nids_register_chksum_ctl(__int64 a1, int a2)
{
nchk = a1;
nrnochksum = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
nchk = a1;
nrnochksum = a2;
}

original_code:
void nids_register_chksum_ctl(struct nids_chksum_ctl * ptr, int nr)
{
 nchk=ptr;
 nrnochksum=nr;
}

canonical_original_code:
void nids_register_chksum_ctl(struct nids_chksum_ctl *ptr, int nr)
{
 nchk=ptr;
 nrnochksum=nr;
}

variable_types: struct nids_chksum_ctl { unsigned int netaddr; unsigned int mask; unsigned int action; unsigned int reserved; } *

variable_types: nr int


original_code:
u_short
ip_check_ext(register u_short *addr, register int len, int addon)
{
  register int nleft = len;
  register u_short *w = addr;
  register int sum = addon;
  u_short answer = 0;
  while (nleft > 1) {
    sum += *w++;
    nleft -= 2;
  }
  if (nleft == 1) {
    *(u_char *)(&answer) = *(u_char *)w;
    sum += answer;
  }
  sum = (sum >> 16) + (sum & 0xffff);
  sum += (sum >> 16);
  answer = ~sum;
  return (answer);
}

canonical_original_code:
unsigned short ip_check_ext(unsigned short *addr, int len, int addon)
{
  register int nleft = len;
  register unsigned short *w = addr;
  register int sum = addon;
  unsigned short answer = 0;
  while (nleft > 1) {
    sum += *w++;
    nleft -= 2;
  }
  if (nleft == 1) {
    *(unsigned char *)(&answer) = *(unsigned char *)w;
    sum += answer;
  }
  sum = (sum >> 16) + (sum & 0xffff);
  sum += (sum >> 16);
  answer = ~sum;
  return (answer);
}

variable_types:
addr
unsigned short *

variable_types: len int

variable_types: addon int

variable_types: nleft int

variable_types:
w
unsigned short *

variable_types: sum int

variable_types:
answer
unsigned short

return_type: unsigned short


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

v2 = dontchksum(*(_DWORD *)(a1 + 12));
result = 0LL;
if ( !v2 )
result = ip_check_ext((_BYTE *)a1, 4 * a2, 0);
return result;
}

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

v2 = func0(*(_DWORD *)(a1 + 12));
result = 0LL;
if ( !v2 )
result = func3((_BYTE *)a1, 4 * a2, 0);
return result;
}

original_code:
u_short
ip_fast_csum(u_short *addr, int len)
{
  if (dontchksum(((struct ip*)addr)->ip_src.s_addr))
 return 0;
  return ip_check_ext(addr, len << 2, 0);
}

canonical_original_code:
unsigned short ip_fast_csum(unsigned short *addr, int len)
{
  if (dontchksum(((struct ip *)addr)->ip_src.s_addr))
 return 0;
  return ip_check_ext(addr, len << 2, 0);
}

user_defined_types: struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; }


decompiled_code:
__int64 __fastcall ip_compute_csum(_BYTE *a1, int a2)
{
return ip_check_ext(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1, int a2)
{
return func3(a1, a2, 0);
}

original_code:
u_short
ip_compute_csum(u_short *addr, int len)
{
  return ip_check_ext(addr, len, 0);
}

canonical_original_code:
unsigned short ip_compute_csum(unsigned short *addr, int len)
{
  return ip_check_ext(addr, len, 0);
}


decompiled_code:
__int64 __fastcall my_tcp_check(_BYTE *a1, __int16 a2, int a3, int a4)
{
int v6; // ebx
__int64 result; // rax
char *v8; // rax
int v9[2]; // [rsp+4h] [rbp-34h] BYREF
char v10; // [rsp+Ch] [rbp-2Ch]
char v11; // [rsp+Dh] [rbp-2Bh]
__int16 v12; // [rsp+Eh] [rbp-2Ah]
char v13; // [rsp+10h] [rbp-28h] BYREF

v6 = dontchksum(a3);
result = 0LL;
if ( !v6 )
{
v9[0] = a3;
v9[1] = a4;
v10 = 0;
v11 = 6;
v12 = _bswap_16(a2);
v8 = (char *)v9;
do
{
v6 += *(unsigned __int16 *)v8;
v8 += 2;
}
while ( v8 != &v13 );
result = ip_check_ext(a1, a2, v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1, __int16 a2, int a3, int a4)
{
int v6; // ebx
__int64 result; // rax
char *v8; // rax
int v9[2]; // [rsp+4h] [rbp-34h] BYREF
char v10; // [rsp+Ch] [rbp-2Ch]
char v11; // [rsp+Dh] [rbp-2Bh]
__int16 v12; // [rsp+Eh] [rbp-2Ah]
char v13; // [rsp+10h] [rbp-28h] BYREF

v6 = func0(a3);
result = 0LL;
if ( !v6 )
{
v9[0] = a3;
v9[1] = a4;
v10 = 0;
v11 = 6;
v12 = func1(a2);
v8 = (char *)v9;
do
{
v6 += *(unsigned __int16 *)v8;
v8 += 2;
}
while ( v8 != &v13 );
result = func3(a1, a2, v6);
}
return result;
}

original_code:
u_short
my_tcp_check(struct tcphdr *th, int len, u_int saddr, u_int daddr)
{
  unsigned int i;
  int sum = 0;
  struct psuedo_hdr hdr;
  if (dontchksum(saddr))
   return 0;
  hdr.saddr = saddr;
  hdr.daddr = daddr;
  hdr.zero = 0;
  hdr.protocol = IPPROTO_TCP;
  hdr.len = htons(len);
  for (i = 0; i < sizeof(hdr); i += 2)
    sum += *(u_short *)((char *)(&hdr) + i);
  return (ip_check_ext((u_short *)th, len, sum));
}

canonical_original_code:
unsigned short my_tcp_check(struct tcphdr *th, int len, unsigned int saddr, unsigned int daddr)
{
  unsigned int i;
  int sum = 0;
  struct psuedo_hdr hdr;
  if (dontchksum(saddr))
   return 0;
  hdr.saddr = saddr;
  hdr.daddr = daddr;
  hdr.zero = 0;
  hdr.protocol = IPPROTO_TCP;
  hdr.len = htons(len);
  for (i = 0; i < sizeof(hdr); i += 2)
    sum += *(unsigned short *)((char *)(&hdr) + i);
  return (ip_check_ext((unsigned short *)th, len, sum));
}

variable_types: struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; } *

variable_types:
saddr
unsigned int

variable_types:
daddr
unsigned int

variable_types:
i
unsigned int

variable_types: struct psuedo_hdr { unsigned int saddr; unsigned int daddr; unsigned char zero; unsigned char protocol; unsigned short len; }


decompiled_code:
__int64 __fastcall my_udp_check(_BYTE *a1, __int16 a2, int a3, int a4)
{
int v6; // ebx
__int64 result; // rax
char *v8; // rax
int v9[2]; // [rsp+4h] [rbp-34h] BYREF
char v10; // [rsp+Ch] [rbp-2Ch]
char v11; // [rsp+Dh] [rbp-2Bh]
__int16 v12; // [rsp+Eh] [rbp-2Ah]
char v13; // [rsp+10h] [rbp-28h] BYREF

v6 = dontchksum(a3);
result = 0LL;
if ( !v6 )
{
v9[0] = a3;
v9[1] = a4;
v10 = 0;
v11 = 17;
v12 = _bswap_16(a2);
v8 = (char *)v9;
do
{
v6 += *(unsigned __int16 *)v8;
v8 += 2;
}
while ( v8 != &v13 );
result = ip_check_ext(a1, a2, v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1, __int16 a2, int a3, int a4)
{
int v6; // ebx
__int64 result; // rax
char *v8; // rax
int v9[2]; // [rsp+4h] [rbp-34h] BYREF
char v10; // [rsp+Ch] [rbp-2Ch]
char v11; // [rsp+Dh] [rbp-2Bh]
__int16 v12; // [rsp+Eh] [rbp-2Ah]
char v13; // [rsp+10h] [rbp-28h] BYREF

v6 = func0(a3);
result = 0LL;
if ( !v6 )
{
v9[0] = a3;
v9[1] = a4;
v10 = 0;
v11 = 17;
v12 = func1(a2);
v8 = (char *)v9;
do
{
v6 += *(unsigned __int16 *)v8;
v8 += 2;
}
while ( v8 != &v13 );
result = func3(a1, a2, v6);
}
return result;
}

original_code:
u_short
my_udp_check(void *u, int len, u_int saddr, u_int daddr)
{
  unsigned int i;
  int sum = 0;
  struct psuedo_hdr hdr;
  if (dontchksum(saddr))
   return 0;
  hdr.saddr = saddr;
  hdr.daddr = daddr;
  hdr.zero = 0;
  hdr.protocol = IPPROTO_UDP;
  hdr.len = htons(len);
  for (i = 0; i < sizeof(hdr); i += 2)
    sum += *(u_short *)((char *)(&hdr) + i);
  return (ip_check_ext((u_short *)u, len, sum));
}

canonical_original_code:
unsigned short my_udp_check(void *u, int len, unsigned int saddr, unsigned int daddr)
{
  unsigned int i;
  int sum = 0;
  struct psuedo_hdr hdr;
  if (dontchksum(saddr))
   return 0;
  hdr.saddr = saddr;
  hdr.daddr = daddr;
  hdr.zero = 0;
  hdr.protocol = IPPROTO_UDP;
  hdr.len = htons(len);
  for (i = 0; i < sizeof(hdr); i += 2)
    sum += *(unsigned short *)((char *)(&hdr) + i);
  return (ip_check_ext((unsigned short *)u, len, sum));
}

variable_types:
u
void *

user_defined_types: struct psuedo_hdr { unsigned int saddr; unsigned int daddr; unsigned char zero; unsigned char protocol; unsigned short len; }


decompiled_code:
__int64 raw_init()
{
unsigned int v0; // edx
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

l = libnet_init(1LL, 0LL, v2);
v0 = 1;
if ( !l )
{
puts(v2);
v0 = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // edx
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

l = libnet_init(1LL, 0LL, v2);
v0 = 1;
if ( !l )
{
puts(v2);
v0 = 0;
}
return v0;
}

original_code:
int raw_init()
{
    char errbuf[1024];
    l = libnet_init(0x01,
      ((void *)0),
      errbuf);
    if (!l) {
 printf("%s\n", errbuf);
 return 0;
    } else
 return 1;
}

variable_types:
errbuf
char [1024]


decompiled_code:
void __fastcall nids_killtcp_seq(unsigned __int16 *a1, int a2)
{
int v2; // eax
int v3; // eax

if ( l )
{
v2 = 0;
if ( a2 )
v2 = a1[100] >> 1;
tcp_tag = libnet_build_tcp(
*a1,
a1[1],
(unsigned int)(v2 + *((_DWORD *)a1 + 21) + *((_DWORD *)a1 + 39) + *((_DWORD *)a1 + 43)),
0LL,
4LL,
32000LL,
0LL,
0LL,
20LL,
0LL,
0LL,
l,
(unsigned int)tcp_tag);
ip_tag = libnet_build_ipv4(
40LL,
0LL,
12345LL,
0LL,
64LL,
6LL,
0LL,
*((unsigned int *)a1 + 1),
*((unsigned int *)a1 + 2),
0LL,
0LL,
l,
(unsigned int)ip_tag);
libnet_write(l);
v3 = 0;
if ( a2 )
v3 = a1[48] >> 1;
tcp_tag = libnet_build_tcp(
a1[1],
*a1,
(unsigned int)(v3 + *((_DWORD *)a1 + 47) + *((_DWORD *)a1 + 13) + *((_DWORD *)a1 + 17)),
0LL,
4LL,
32000LL,
0LL,
0LL,
20LL,
0LL,
0LL,
l,
(unsigned int)tcp_tag);
ip_tag = libnet_build_ipv4(
40LL,
0LL,
12345LL,
0LL,
64LL,
6LL,
0LL,
*((unsigned int *)a1 + 2),
*((unsigned int *)a1 + 1),
0LL,
0LL,
l,
(unsigned int)ip_tag);
libnet_write(l);
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned __int16 *a1, int a2)
{
int v2; // eax
int v3; // eax

if ( l )
{
v2 = 0;
if ( a2 )
v2 = a1[100] >> 1;
tcp_tag = libnet_build_tcp(
*a1,
a1[1],
(unsigned int)(v2 + *((_DWORD *)a1 + 21) + *((_DWORD *)a1 + 39) + *((_DWORD *)a1 + 43)),
0LL,
4LL,
32000LL,
0LL,
0LL,
20LL,
0LL,
0LL,
l,
(unsigned int)tcp_tag);
ip_tag = libnet_build_ipv4(
40LL,
0LL,
12345LL,
0LL,
64LL,
6LL,
0LL,
*((unsigned int *)a1 + 1),
*((unsigned int *)a1 + 2),
0LL,
0LL,
l,
(unsigned int)ip_tag);
libnet_write(l);
v3 = 0;
if ( a2 )
v3 = a1[48] >> 1;
tcp_tag = libnet_build_tcp(
a1[1],
*a1,
(unsigned int)(v3 + *((_DWORD *)a1 + 47) + *((_DWORD *)a1 + 13) + *((_DWORD *)a1 + 17)),
0LL,
4LL,
32000LL,
0LL,
0LL,
20LL,
0LL,
0LL,
l,
(unsigned int)tcp_tag);
ip_tag = libnet_build_ipv4(
40LL,
0LL,
12345LL,
0LL,
64LL,
6LL,
0LL,
*((unsigned int *)a1 + 2),
*((unsigned int *)a1 + 1),
0LL,
0LL,
l,
(unsigned int)ip_tag);
libnet_write(l);
}
}

original_code:
void nids_killtcp_seq(struct tcp_stream *a_tcp, int seqoff)
{
    if (!l)
 return;
    tcp_tag = libnet_build_tcp(a_tcp->addr.source, a_tcp->addr.dest,
 a_tcp->client.first_data_seq +
  a_tcp->server.count + a_tcp->server.urg_count +
  (seqoff?(a_tcp->server.window/2):0),
 0, 0x4, 32000, 0, 0, 0x14, ((void *)0), 0, l, tcp_tag);
    ip_tag =
 libnet_build_ipv4(0x14 + 0x14, 0, 12345, 0, 64,
     IPPROTO_TCP, 0, a_tcp->addr.saddr,
     a_tcp->addr.daddr, 0, 0, l, ip_tag);
    libnet_write(l);
    tcp_tag = libnet_build_tcp(a_tcp->addr.dest, a_tcp->addr.source,
        a_tcp->server.first_data_seq +
                a_tcp->client.count + a_tcp->client.urg_count +
                (seqoff?(a_tcp->client.window/2):0),
0, 0x4, 32000, 0,
          0, 0x14, ((void *)0), 0, l, tcp_tag);
    ip_tag =
 libnet_build_ipv4(0x14 + 0x14, 0, 12345, 0, 64,
     IPPROTO_TCP, 0, a_tcp->addr.daddr,
     a_tcp->addr.saddr, 0, 0, l, ip_tag);
    libnet_write(l);
}

variable_types: struct tcp_stream { struct tuple4 { unsigned short source; unsigned short dest; unsigned int saddr; unsigned int daddr; } addr; char nids_state; struct lurker_node { void (*item)(); void *data; char whatto; struct lurker_node *next; } *listeners; struct half_stream { char state; char collect; char collect_urg; char *data; char *ip_tcp_header; int offset; int count; int count_new; int bufsize; int rmem_alloc; int urg_count; unsigned int acked; unsigned int seq; unsigned int ack_seq; unsigned int first_data_seq; unsigned char urgdata; unsigned char count_new_urg; unsigned char urg_seen; unsigned int urg_ptr; unsigned short window; unsigned char ts_on; unsigned char wscale_on; unsigned int curr_ts; unsigned int wscale; struct skbuff { struct skbuff *next; struct skbuff *prev; void *ip_tcp_header; void *data; unsigned int len; unsigned int truesize; unsigned int urg_ptr; char fin; char urg; unsigned int seq; unsigned int ack; } *list; struct skbuff *listtail; } client; struct half_stream server; struct tcp_stream *next_node; struct tcp_stream *prev_node; int hash_index; struct tcp_stream *next_time; struct tcp_stream *prev_time; int read; struct tcp_stream *next_free; void *user; } *

variable_types: seqoff int

user_defined_types: struct tcp_stream { struct tuple4 addr; char nids_state; struct lurker_node *listeners; struct half_stream client; struct half_stream server; struct tcp_stream *next_node; struct tcp_stream *prev_node; int hash_index; struct tcp_stream *next_time; struct tcp_stream *prev_time; int read; struct tcp_stream *next_free; void *user; }

user_defined_types: struct half_stream { char state; char collect; char collect_urg; char *data; char *ip_tcp_header; int offset; int count; int count_new; int bufsize; int rmem_alloc; int urg_count; unsigned int acked; unsigned int seq; unsigned int ack_seq; unsigned int first_data_seq; unsigned char urgdata; unsigned char count_new_urg; unsigned char urg_seen; unsigned int urg_ptr; unsigned short window; unsigned char ts_on; unsigned char wscale_on; unsigned int curr_ts; unsigned int wscale; struct skbuff *list; struct skbuff *listtail; }


decompiled_code:
void __fastcall nids_killtcp(unsigned __int16 *a1)
{
nids_killtcp_seq(a1, 0);
nids_killtcp_seq(a1, 1);
}

canonical_decompiled_code:
void __fastcall func2(unsigned __int16 *a1)
{
func1(a1, 0);
func1(a1, 1);
}

original_code:
void nids_killtcp(struct tcp_stream *a_tcp)
{
    nids_killtcp_seq(a_tcp, 0);
    nids_killtcp_seq(a_tcp, 1);
}

user_defined_types: struct tuple4 { unsigned short source; unsigned short dest; unsigned int saddr; unsigned int daddr; }

user_defined_types: struct lurker_node { void (*item)(); void *data; char whatto; struct lurker_node *next; }

user_defined_types: struct skbuff { struct skbuff *next; struct skbuff *prev; void *ip_tcp_header; void *data; unsigned int len; unsigned int truesize; unsigned int urg_ptr; char fin; char urg; unsigned int seq; unsigned int ack; }