decompiled_code:
__int64 __fastcall bin2gray_ui8matrix(__int64 a1, int a2, int a3, int a4, int a5, __int64 a6)
{
_BYTE *v10; // rbx

v10 = (_BYTE *)alloc_ui8lut();
init_ui8lut(v10, 1LL, 255);
apply_ui8lut(a1, a2, a3, a4, a5, (__int64)v10, a6);
return free_ui8lut((__int64)v10);
}

original_code:
void bin2gray_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 **Y)
{
    uint8 *L;
    L = alloc_ui8lut();
    init_ui8lut(L, 1, 255);
    apply_ui8lut(X, i0, i1, j0, j1, L, Y);
    free_ui8lut(L);
}

canonical_original_code:
void bin2gray_ui8matrix(unsigned char **X, int i0, int i1, int j0, int j1, unsigned char **Y)
{
    unsigned char *L;
    L = alloc_ui8lut();
    init_ui8lut(L, 1, 255);
    apply_ui8lut(X, i0, i1, j0, j1, L, Y);
    free_ui8lut(L);
}


repo: rvion/school-mega-repo

decompiled_code:
__int64 __fastcall routine_basic_morpho(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12
__int64 v5; // rbx
__int64 v7; // [rsp+10h] [rbp-448h] BYREF
__int64 v8; // [rsp+18h] [rbp-440h] BYREF
__int64 v9; // [rsp+20h] [rbp-438h] BYREF
__int64 v10; // [rsp+28h] [rbp-430h] BYREF
char s[1064]; // [rsp+30h] [rbp-428h] BYREF

generate_path_filename_extension(a1, a2, &unk_B11, s);
puts(s);
v4 = LoadPGM_ui8matrix(s, &v10, &v9, &v8, &v7);
v5 = ui8matrix(v10, v9, v8, v7);
erosion_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B15, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
erosion_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 2LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B15, 2LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 2LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 2LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 3LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 3LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
opening_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B1D, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
closing_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B21, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
free_ui8matrix(v4, v10, v9, v8, v7);
return free_ui8matrix(v5, v10, v9, v8, v7);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12
__int64 v5; // rbx
__int64 v7; // [rsp+10h] [rbp-448h] BYREF
__int64 v8; // [rsp+18h] [rbp-440h] BYREF
__int64 v9; // [rsp+20h] [rbp-438h] BYREF
__int64 v10; // [rsp+28h] [rbp-430h] BYREF
char s[1064]; // [rsp+30h] [rbp-428h] BYREF

generate_path_filename_extension(a1, a2, &unk_B11, s);
puts(s);
v4 = LoadPGM_ui8matrix(s, &v10, &v9, &v8, &v7);
v5 = ui8matrix(v10, v9, v8, v7);
erosion_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B15, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
erosion_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 2LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B15, 2LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 2LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 2LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 3LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 3LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
opening_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B1D, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
closing_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B21, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
free_ui8matrix(v4, v10, v9, v8, v7);
return free_ui8matrix(v5, v10, v9, v8, v7);
}

original_code:
void routine_basic_morpho(char *src_path, char *filename, char *dst_path)
{
    char complete_filename[1024];
    char *sep;
    int k;
    int radius;
    int ndigit = 1;
    long i0, i1, j0, j1;
    uint8 **X, **Y;
    generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename);
    X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1);
    Y = ui8matrix(i0, i1, j0, j1);
    radius = 1; sep = "_E_";
    k = radius;
    erosion_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 2; sep = "_E_";
    k = radius;
    erosion_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 1; sep = "_D_";
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 2; sep = "_D_";
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 3; sep = "_D_";
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 1; sep = "_O_";
    k = radius;
    opening_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 1; sep = "_C_";
    k = radius;
    closing_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    free_ui8matrix(X, i0, i1, j0, j1);
    free_ui8matrix(Y, i0, i1, j0, j1);
}

canonical_original_code:
void routine_basic_morpho(char *src_path, char *filename, char *dst_path)
{
    char complete_filename[1024];
    char *sep;
    int k;
    int radius;
    int ndigit = 1;
    long i0; long i1; long j0; long j1;
    unsigned char **X; unsigned char **Y;
    generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename);
    X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1);
    Y = ui8matrix(i0, i1, j0, j1);
    radius = 1; sep = "_E_";
    k = radius;
    erosion_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 2; sep = "_E_";
    k = radius;
    erosion_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 1; sep = "_D_";
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 2; sep = "_D_";
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 3; sep = "_D_";
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 1; sep = "_O_";
    k = radius;
    opening_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 1; sep = "_C_";
    k = radius;
    closing_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    free_ui8matrix(X, i0, i1, j0, j1);
    free_ui8matrix(Y, i0, i1, j0, j1);
}

variable_types:
filename
char *

variable_types:
sep
char *

variable_types: k int

variable_types: radius int

variable_types: ndigit int

variable_types:
X
unsigned char **

variable_types:
Y
unsigned char **

return_type: void


decompiled_code:
__int64 test_basic_morpho()
{
puts("-------------------------");
puts("--- test_basic_morpho ---");
puts("-------------------------");
return routine_basic_morpho(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/",
(__int64)"carre8_IN_005",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/");
}

canonical_decompiled_code:
__int64 func1()
{
puts("-------------------------");
puts("--- test_basic_morpho ---");
puts("-------------------------");
return func0(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/",
(__int64)"carre8_IN_005",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/");
}

original_code:
void test_basic_morpho(void)
{
    char *noise_path;
    char *morpho_path;
    puts("-------------------------");
    puts("--- test_basic_morpho ---");
    puts("-------------------------");
    noise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/";
    morpho_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/";
    routine_basic_morpho(noise_path, "carre8_IN_005", morpho_path);
}

canonical_original_code:
void test_basic_morpho()
{
    char *noise_path;
    char *morpho_path;
    puts("-------------------------");
    puts("--- test_basic_morpho ---");
    puts("-------------------------");
    noise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/";
    morpho_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/";
    routine_basic_morpho(noise_path, "carre8_IN_005", morpho_path);
}


decompiled_code:
__int64 __fastcall routine_binary_morpho(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12
__int64 v5; // rbx
__int64 v7; // [rsp+10h] [rbp-448h] BYREF
__int64 v8; // [rsp+18h] [rbp-440h] BYREF
__int64 v9; // [rsp+20h] [rbp-438h] BYREF
__int64 v10; // [rsp+28h] [rbp-430h] BYREF
char s[1064]; // [rsp+30h] [rbp-428h] BYREF

generate_path_filename_extension(a1, a2, &unk_B11, s);
puts(s);
v4 = LoadPGM_ui8matrix(s, &v10, &v9, &v8, &v7);
v5 = ui8matrix(v10, v9, v8, v7);
erosion_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B15, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 3LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 3LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
opening_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B1D, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
closing_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B21, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
free_ui8matrix(v4, v10, v9, v8, v7);
return free_ui8matrix(v5, v10, v9, v8, v7);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12
__int64 v5; // rbx
__int64 v7; // [rsp+10h] [rbp-448h] BYREF
__int64 v8; // [rsp+18h] [rbp-440h] BYREF
__int64 v9; // [rsp+20h] [rbp-438h] BYREF
__int64 v10; // [rsp+28h] [rbp-430h] BYREF
char s[1064]; // [rsp+30h] [rbp-428h] BYREF

generate_path_filename_extension(a1, a2, &unk_B11, s);
puts(s);
v4 = LoadPGM_ui8matrix(s, &v10, &v9, &v8, &v7);
v5 = ui8matrix(v10, v9, v8, v7);
erosion_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B15, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 3LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 3LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
opening_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B1D, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
closing_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B21, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
free_ui8matrix(v4, v10, v9, v8, v7);
return free_ui8matrix(v5, v10, v9, v8, v7);
}

original_code:
void routine_binary_morpho(char *src_path, char *filename, char *dst_path)
{
    char complete_filename[1024];
    char *sep;
    int k;
    int radius;
    int ndigit = 1;
    long i0, i1, j0, j1;
    uint8 **X, **Y;
    generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename);
    X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1);
    Y = ui8matrix(i0, i1, j0, j1);
    sep = "_E_";
    radius = 1;
    k = radius;
    erosion_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_D_";
    radius = 1;
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 3;
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_O_";
    radius = 1;
    k = radius;
    opening_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_C_";
    radius = 1;
    k = radius;
    closing_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    free_ui8matrix(X, i0, i1, j0, j1);
    free_ui8matrix(Y, i0, i1, j0, j1);
}

canonical_original_code:
void routine_binary_morpho(char *src_path, char *filename, char *dst_path)
{
    char complete_filename[1024];
    char *sep;
    int k;
    int radius;
    int ndigit = 1;
    long i0; long i1; long j0; long j1;
    unsigned char **X; unsigned char **Y;
    generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename);
    X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1);
    Y = ui8matrix(i0, i1, j0, j1);
    sep = "_E_";
    radius = 1;
    k = radius;
    erosion_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_D_";
    radius = 1;
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 3;
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_O_";
    radius = 1;
    k = radius;
    opening_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_C_";
    radius = 1;
    k = radius;
    closing_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    free_ui8matrix(X, i0, i1, j0, j1);
    free_ui8matrix(Y, i0, i1, j0, j1);
}


decompiled_code:
int test_binary_morpho()
{
puts("--------------------------");
puts("--- test_binary_morpho ---");
puts("--------------------------");
routine_binary_morpho(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/",
(__int64)"carre64_GN_01_S_T_064",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/");
return puts(&byte_BB3);
}

canonical_decompiled_code:
int func3()
{
puts("--------------------------");
puts("--- test_binary_morpho ---");
puts("--------------------------");
func2(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/",
(__int64)"carre64_GN_01_S_T_064",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/");
return puts(&byte_BB3);
}

original_code:
void test_binary_morpho(void)
{
    char *contour_path;
    char *morpho_path;
    puts("--------------------------");
    puts("--- test_binary_morpho ---");
    puts("--------------------------");
    contour_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/";
    morpho_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/";
    routine_binary_morpho(contour_path, "carre64_GN_01_S_T_064", morpho_path); puts("");
}

canonical_original_code:
void test_binary_morpho()
{
    char *contour_path;
    char *morpho_path;
    puts("--------------------------");
    puts("--- test_binary_morpho ---");
    puts("--------------------------");
    contour_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/";
    morpho_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/";
    routine_binary_morpho(contour_path, "carre64_GN_01_S_T_064", morpho_path); puts("");
}


decompiled_code:
__int64 __fastcall routine_morpho(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12
__int64 v5; // rbx
__int64 v7; // [rsp+10h] [rbp-448h] BYREF
__int64 v8; // [rsp+18h] [rbp-440h] BYREF
__int64 v9; // [rsp+20h] [rbp-438h] BYREF
__int64 v10; // [rsp+28h] [rbp-430h] BYREF
char s[1064]; // [rsp+30h] [rbp-428h] BYREF

generate_path_filename_extension(a1, a2, &unk_B11, s);
puts(s);
v4 = LoadPGM_ui8matrix(s, &v10, &v9, &v8, &v7);
v5 = ui8matrix(v10, v9, v8, v7);
erosion_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B15, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 3LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 3LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
opening_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B1D, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
closing_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B21, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
alternate_sequential_filter_opening_ui8matrix(
v4,
(unsigned int)v10,
(unsigned int)v9,
(unsigned int)v8,
(unsigned int)v7,
1LL,
v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, "_ASFO_", 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
alternate_sequential_filter_closing_ui8matrix(
v4,
(unsigned int)v10,
(unsigned int)v9,
(unsigned int)v8,
(unsigned int)v7,
1LL,
v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, "_ASFC_", 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
free_ui8matrix(v4, v10, v9, v8, v7);
return free_ui8matrix(v5, v10, v9, v8, v7);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12
__int64 v5; // rbx
__int64 v7; // [rsp+10h] [rbp-448h] BYREF
__int64 v8; // [rsp+18h] [rbp-440h] BYREF
__int64 v9; // [rsp+20h] [rbp-438h] BYREF
__int64 v10; // [rsp+28h] [rbp-430h] BYREF
char s[1064]; // [rsp+30h] [rbp-428h] BYREF

generate_path_filename_extension(a1, a2, &unk_B11, s);
puts(s);
v4 = LoadPGM_ui8matrix(s, &v10, &v9, &v8, &v7);
v5 = ui8matrix(v10, v9, v8, v7);
erosion_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B15, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
dilation_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 3LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B19, 3LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
opening_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B1D, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
closing_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, 1LL, v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, &unk_B21, 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
alternate_sequential_filter_opening_ui8matrix(
v4,
(unsigned int)v10,
(unsigned int)v9,
(unsigned int)v8,
(unsigned int)v7,
1LL,
v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, "_ASFO_", 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
alternate_sequential_filter_closing_ui8matrix(
v4,
(unsigned int)v10,
(unsigned int)v9,
(unsigned int)v8,
(unsigned int)v7,
1LL,
v5);
generate_path_filename_sep_k_ndigit_extension(a3, a2, "_ASFC_", 1LL, 1LL, &unk_B11, s);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
free_ui8matrix(v4, v10, v9, v8, v7);
return free_ui8matrix(v5, v10, v9, v8, v7);
}

original_code:
void routine_morpho(char *src_path, char *filename, char *dst_path)
{
    char complete_filename[1024];
    char *sep;
    int k;
    int radius;
    int ndigit = 1;
    long i0, i1, j0, j1;
    uint8 **X, **Y;
    generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename);
    X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1);
    Y = ui8matrix(i0, i1, j0, j1);
    sep = "_E_";
    radius = 1;
    k = radius;
    erosion_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_D_";
    radius = 1;
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 3;
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_O_";
    radius = 1;
    k = radius;
    opening_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_C_";
    radius = 1;
    k = radius;
    closing_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_ASFO_";
    radius = 1;
    k = radius;
    alternate_sequential_filter_opening_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_ASFC_";
    radius = 1;
    k = radius;
    alternate_sequential_filter_closing_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    free_ui8matrix(X, i0, i1, j0, j1);
    free_ui8matrix(Y, i0, i1, j0, j1);
}

canonical_original_code:
void routine_morpho(char *src_path, char *filename, char *dst_path)
{
    char complete_filename[1024];
    char *sep;
    int k;
    int radius;
    int ndigit = 1;
    long i0; long i1; long j0; long j1;
    unsigned char **X; unsigned char **Y;
    generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename);
    X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1);
    Y = ui8matrix(i0, i1, j0, j1);
    sep = "_E_";
    radius = 1;
    k = radius;
    erosion_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_D_";
    radius = 1;
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    radius = 3;
    k = radius;
    dilation_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_O_";
    radius = 1;
    k = radius;
    opening_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_C_";
    radius = 1;
    k = radius;
    closing_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_ASFO_";
    radius = 1;
    k = radius;
    alternate_sequential_filter_opening_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    sep = "_ASFC_";
    radius = 1;
    k = radius;
    alternate_sequential_filter_closing_ui8matrix(X, i0, i1, j0, j1, radius, Y);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    free_ui8matrix(X, i0, i1, j0, j1);
    free_ui8matrix(Y, i0, i1, j0, j1);
}


decompiled_code:
int test_morpho()
{
puts("-------------------");
puts("--- test_morpho ---");
puts("-------------------");
routine_morpho(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/",
(__int64)"lena",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/");
puts(&byte_BB3);
routine_morpho(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/",
(__int64)"bureau",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/");
puts(&byte_BB3);
routine_morpho(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/",
(__int64)"IceteaG",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/");
puts(&byte_BB3);
routine_morpho(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/",
(__int64)"IceteaB",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/");
return puts(&byte_BB3);
}

canonical_decompiled_code:
int func5()
{
puts("-------------------");
puts("--- test_morpho ---");
puts("-------------------");
func4(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/",
(__int64)"lena",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/");
puts(&byte_BB3);
func4(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/",
(__int64)"bureau",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/");
puts(&byte_BB3);
func4(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/",
(__int64)"IceteaG",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/");
puts(&byte_BB3);
func4(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/",
(__int64)"IceteaB",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/");
return puts(&byte_BB3);
}

original_code:
void test_morpho(void)
{
    char *src_path;
    char *noise_path;
    char *morpho_path;
    puts("-------------------");
    puts("--- test_morpho ---");
    puts("-------------------");
    src_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/";
    noise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/";
    morpho_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/";
    routine_morpho(src_path, "lena", morpho_path); puts("");
    routine_morpho(src_path, "bureau", morpho_path); puts("");
    routine_morpho(src_path, "IceteaG", morpho_path); puts("");
    routine_morpho(src_path, "IceteaB", morpho_path); puts("");
}

canonical_original_code:
void test_morpho()
{
    char *src_path;
    char *noise_path;
    char *morpho_path;
    puts("-------------------");
    puts("--- test_morpho ---");
    puts("-------------------");
    src_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/";
    noise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/";
    morpho_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/morpho/";
    routine_morpho(src_path, "lena", morpho_path); puts("");
    routine_morpho(src_path, "bureau", morpho_path); puts("");
    routine_morpho(src_path, "IceteaG", morpho_path); puts("");
    routine_morpho(src_path, "IceteaB", morpho_path); puts("");
}


original_code:
int test_morphoNR(int argc, const char * argv[])
{
    puts("=====================");
    puts("=== test_morphoNR ===");
    puts("=====================");
    test_basic_morpho();
    test_binary_morpho();
    test_morpho();
    return 0;
}

canonical_original_code:
int test_morphoNR(int argc, char *argv[])
{
    puts("=====================");
    puts("=== test_morphoNR ===");
    puts("=====================");
    test_basic_morpho();
    test_binary_morpho();
    test_morpho();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rax
__int64 v5; // rax

if ( (int)SDL_Init() < 0 )
{
v4 = (const char *)SDL_GetError();
printf("Impossible d'initialiser SDL: %s\n", v4);
exit(1);
}
atexit(SDL_Quit, argv);
if ( !SDL_SetVideoMode() )
{
v5 = SDL_GetError();
printf(aImpossibleDIni, v5);
exit(1);
}
SDL_Delay();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rax
__int64 v5; // rax

if ( (int)SDL_Init() < 0 )
{
v4 = (const char *)SDL_GetError();
printf("Impossible d'initialiser SDL: %s\n", v4);
exit(1);
}
func11(SDL_Quit, argv);
if ( !SDL_SetVideoMode() )
{
v5 = SDL_GetError();
printf(aImpossibleDIni, v5);
exit(1);
}
SDL_Delay();
return 0;
}

original_code:
int main (int argc, const char * argv[]) {
    printf("Hello, dWorld!\n");
    test(argc, argv);
    puts("bye ...");
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    printf("Hello, dWorld!\n");
    test(argc, argv);
    puts("bye ...");
    return 0;
}


decompiled_code:
__int64 __fastcall routine_sobel(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r13
__int64 v5; // rbx
__int64 v7; // [rsp+0h] [rbp-448h] BYREF
__int64 v8; // [rsp+8h] [rbp-440h] BYREF
__int64 v9; // [rsp+10h] [rbp-438h] BYREF
__int64 v10; // [rsp+18h] [rbp-430h] BYREF
char s[1064]; // [rsp+20h] [rbp-428h] BYREF

generate_path_filename_extension(a1, a2, &unk_714, s);
puts(s);
v4 = LoadPGM_ui8matrix(s, &v10, &v9, &v8, &v7);
v5 = ui8matrix(v10, v9, v8, v7);
sobel_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, v5);
generate_path_filename_sep_extension(a3, a2, &unk_718, &unk_714, s);
puts(s);
double_intensity_ui8matrix(v5, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, v5);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
return free_ui8matrix(v5, v10, v9, v8, v7);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r13
__int64 v5; // rbx
__int64 v7; // [rsp+0h] [rbp-448h] BYREF
__int64 v8; // [rsp+8h] [rbp-440h] BYREF
__int64 v9; // [rsp+10h] [rbp-438h] BYREF
__int64 v10; // [rsp+18h] [rbp-430h] BYREF
char s[1064]; // [rsp+20h] [rbp-428h] BYREF

generate_path_filename_extension(a1, a2, &unk_714, s);
puts(s);
v4 = LoadPGM_ui8matrix(s, &v10, &v9, &v8, &v7);
v5 = ui8matrix(v10, v9, v8, v7);
sobel_ui8matrix(v4, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, v5);
generate_path_filename_sep_extension(a3, a2, &unk_718, &unk_714, s);
puts(s);
double_intensity_ui8matrix(v5, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, (unsigned int)v7, v5);
SavePGM_ui8matrix(v5, v10, v9, v8, v7, s);
return free_ui8matrix(v5, v10, v9, v8, v7);
}

original_code:
void routine_sobel(char *src_path, char *filename, char *dst_path)
{
    char complete_filename[1024];
    char *sep = "_S";
    uint8 **X, **Y;
    long i0, i1, j0, j1;
    generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename);
    X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1);
    Y = ui8matrix(i0, i1, j0, j1);
    sobel_ui8matrix(X, i0, i1, j0, j1, Y);
    generate_path_filename_sep_extension(dst_path, filename, sep, "pgm", complete_filename); puts(complete_filename);
    double_intensity_ui8matrix(Y, i0, i1, j0, j1, Y);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    free_ui8matrix(Y, i0, i1, j0, j1);
}

canonical_original_code:
void routine_sobel(char *src_path, char *filename, char *dst_path)
{
    char complete_filename[1024];
    char *sep = "_S";
    unsigned char **X; unsigned char **Y;
    long i0; long i1; long j0; long j1;
    generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename);
    X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1);
    Y = ui8matrix(i0, i1, j0, j1);
    sobel_ui8matrix(X, i0, i1, j0, j1, Y);
    generate_path_filename_sep_extension(dst_path, filename, sep, "pgm", complete_filename); puts(complete_filename);
    double_intensity_ui8matrix(Y, i0, i1, j0, j1, Y);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    free_ui8matrix(Y, i0, i1, j0, j1);
}


canonical_decompiled_code:
__int64 func1()
{
puts("------------------------");
puts("--- test_sobel part1 ---");
puts("------------------------");
func0(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/",
(__int64)"carre64_GN_01",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/");
func0(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/",
(__int64)"carre16_GN_02",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/");
func0(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/denoise/",
(__int64)"carre16_IN_005_M_1",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/");
func0(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/",
(__int64)"carre16_GN_05",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/");
return func0(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/",
(__int64)"carre16_GN_10",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/");
}

original_code:
void test_sobel(void)
{
    char *noise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/";
    char *denoise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/denoise/";
    char *contour_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/";
    puts("------------------------");
    puts("--- test_sobel part1 ---");
    puts("------------------------");
    routine_sobel(noise_path, "carre64_GN_01", contour_path);
    routine_sobel(noise_path, "carre16_GN_02", contour_path);
    routine_sobel(denoise_path, "carre16_IN_005_M_1", contour_path);
    routine_sobel(noise_path, "carre16_GN_05", contour_path);
    routine_sobel(noise_path, "carre16_GN_10", contour_path);
}

canonical_original_code:
void test_sobel()
{
    char *noise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/";
    char *denoise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/denoise/";
    char *contour_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/";
    puts("------------------------");
    puts("--- test_sobel part1 ---");
    puts("------------------------");
    routine_sobel(noise_path, "carre64_GN_01", contour_path);
    routine_sobel(noise_path, "carre16_GN_02", contour_path);
    routine_sobel(denoise_path, "carre16_IN_005_M_1", contour_path);
    routine_sobel(noise_path, "carre16_GN_05", contour_path);
    routine_sobel(noise_path, "carre16_GN_10", contour_path);
}


decompiled_code:
__int64 __fastcall routine_fgl(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r14
__int64 v5; // rbp
__int64 v6; // rbx
__int64 v8; // [rsp+0h] [rbp-448h] BYREF
__int64 v9; // [rsp+8h] [rbp-440h] BYREF
__int64 v10; // [rsp+10h] [rbp-438h] BYREF
__int64 v11; // [rsp+18h] [rbp-430h] BYREF
char s[1064]; // [rsp+20h] [rbp-428h] BYREF

generate_path_filename_extension(a1, a2, &unk_714, s);
puts(s);
v4 = LoadPGM_ui8matrix(s, &v11, &v10, &v9, &v8);
v5 = ui8matrix(v11, v10, v9, v8);
v6 = ui8matrix(v11, v10, v9, v8);
fgl_ui8matrix(v4, (unsigned int)v11, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, v5, 0.80000001);
roberts_ui8matrix(v5, (unsigned int)v11, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, v6);
generate_path_filename_sep_k_ndigit_extension(a3, a2, "_FGL_", 8LL, 2LL, &unk_714, s);
puts(s);
SavePGM_ui8matrix(v5, v11, v10, v9, v8, s);
generate_path_filename_sep_k_ndigit_extension(a3, a2, "_FGLG_", 8LL, 2LL, &unk_714, s);
puts(s);
SavePGM_ui8matrix(v6, v11, v10, v9, v8, s);
double_intensity_ui8matrix(v6, (unsigned int)v11, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, v6);
double_intensity_ui8matrix(v6, (unsigned int)v11, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, v6);
generate_path_filename_sep_k_ndigit_extension(a3, a2, "VISU", 8LL, 2LL, &unk_714, s);
puts(s);
SavePGM_ui8matrix(v6, v11, v10, v9, v8, s);
free_ui8matrix(v4, v11, v10, v9, v8);
return free_ui8matrix(v5, v11, v10, v9, v8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r14
__int64 v5; // rbp
__int64 v6; // rbx
__int64 v8; // [rsp+0h] [rbp-448h] BYREF
__int64 v9; // [rsp+8h] [rbp-440h] BYREF
__int64 v10; // [rsp+10h] [rbp-438h] BYREF
__int64 v11; // [rsp+18h] [rbp-430h] BYREF
char s[1064]; // [rsp+20h] [rbp-428h] BYREF

generate_path_filename_extension(a1, a2, &unk_714, s);
puts(s);
v4 = LoadPGM_ui8matrix(s, &v11, &v10, &v9, &v8);
v5 = ui8matrix(v11, v10, v9, v8);
v6 = ui8matrix(v11, v10, v9, v8);
fgl_ui8matrix(v4, (unsigned int)v11, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, v5, 0.80000001);
roberts_ui8matrix(v5, (unsigned int)v11, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, v6);
generate_path_filename_sep_k_ndigit_extension(a3, a2, "_FGL_", 8LL, 2LL, &unk_714, s);
puts(s);
SavePGM_ui8matrix(v5, v11, v10, v9, v8, s);
generate_path_filename_sep_k_ndigit_extension(a3, a2, "_FGLG_", 8LL, 2LL, &unk_714, s);
puts(s);
SavePGM_ui8matrix(v6, v11, v10, v9, v8, s);
double_intensity_ui8matrix(v6, (unsigned int)v11, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, v6);
double_intensity_ui8matrix(v6, (unsigned int)v11, (unsigned int)v10, (unsigned int)v9, (unsigned int)v8, v6);
generate_path_filename_sep_k_ndigit_extension(a3, a2, "VISU", 8LL, 2LL, &unk_714, s);
puts(s);
SavePGM_ui8matrix(v6, v11, v10, v9, v8, s);
free_ui8matrix(v4, v11, v10, v9, v8);
return free_ui8matrix(v5, v11, v10, v9, v8);
}

original_code:
void routine_fgl(char *src_path, char *filename, char *dst_path)
{
    char complete_filename[1024];
    char *sep1 = "_FGL_";
    char *sep2 = "_FGLG_";
    int k;
    int ndigit = 2;
    uint8 **X, **Y, **Z;
    long i0, i1, j0, j1;
    float32 alpha;
    generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename);
    X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1);
    Y = ui8matrix(i0, i1, j0, j1);
    Z = ui8matrix(i0, i1, j0, j1);
    alpha = 0.8;
    k = (int) (10*alpha);
    fgl_ui8matrix(X, i0, i1, j0, j1, alpha, Y);
    roberts_ui8matrix(Y, i0, i1, j0, j1, Z);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep1, k, ndigit, "pgm", complete_filename); puts(complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep2, k, ndigit, "pgm", complete_filename); puts(complete_filename);
    SavePGM_ui8matrix(Z, i0, i1, j0, j1, complete_filename);
    double_intensity_ui8matrix(Z, i0, i1, j0, j1, Z);
    double_intensity_ui8matrix(Z, i0, i1, j0, j1, Z);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, "VISU", k, ndigit, "pgm", complete_filename); puts(complete_filename);
    SavePGM_ui8matrix(Z, i0, i1, j0, j1, complete_filename);
    free_ui8matrix(X, i0, i1, j0, j1);
    free_ui8matrix(Y, i0, i1, j0, j1);
}

canonical_original_code:
void routine_fgl(char *src_path, char *filename, char *dst_path)
{
    char complete_filename[1024];
    char *sep1 = "_FGL_";
    char *sep2 = "_FGLG_";
    int k;
    int ndigit = 2;
    unsigned char **X; unsigned char **Y; unsigned char **Z;
    long i0; long i1; long j0; long j1;
    float alpha;
    generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename);
    X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1);
    Y = ui8matrix(i0, i1, j0, j1);
    Z = ui8matrix(i0, i1, j0, j1);
    alpha = 0.8;
    k = (int) (10*alpha);
    fgl_ui8matrix(X, i0, i1, j0, j1, alpha, Y);
    roberts_ui8matrix(Y, i0, i1, j0, j1, Z);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep1, k, ndigit, "pgm", complete_filename); puts(complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep2, k, ndigit, "pgm", complete_filename); puts(complete_filename);
    SavePGM_ui8matrix(Z, i0, i1, j0, j1, complete_filename);
    double_intensity_ui8matrix(Z, i0, i1, j0, j1, Z);
    double_intensity_ui8matrix(Z, i0, i1, j0, j1, Z);
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, "VISU", k, ndigit, "pgm", complete_filename); puts(complete_filename);
    SavePGM_ui8matrix(Z, i0, i1, j0, j1, complete_filename);
    free_ui8matrix(X, i0, i1, j0, j1);
    free_ui8matrix(Y, i0, i1, j0, j1);
}

variable_types:
Z
unsigned char **

variable_types: alpha float


decompiled_code:
__int64 test_fgl()
{
puts("------------------------");
puts("--- test_fgl part1 ---");
puts("------------------------");
routine_fgl(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/",
(__int64)"carre64",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/");
routine_fgl(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/",
(__int64)"carre64_GN_01",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/");
return routine_fgl(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/denoise/",
(__int64)"carre64_IN_005_M_1",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/");
}

canonical_decompiled_code:
__int64 func3()
{
puts("------------------------");
puts("--- test_fgl part1 ---");
puts("------------------------");
func2(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/",
(__int64)"carre64",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/");
func2(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/",
(__int64)"carre64_GN_01",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/");
return func2(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/denoise/",
(__int64)"carre64_IN_005_M_1",
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/");
}

original_code:
void test_fgl(void)
{
    char *src_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/";
    char *noise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/";
    char *denoise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/denoise/";
    char *contour_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/";
    puts("------------------------");
    puts("--- test_fgl part1 ---");
    puts("------------------------");
    routine_fgl(src_path, "carre64", contour_path);
    routine_fgl(noise_path, "carre64_GN_01", contour_path);
    routine_fgl(denoise_path, "carre64_IN_005_M_1", contour_path);
  }

canonical_original_code:
void test_fgl()
{
    char *src_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/";
    char *noise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/noise/";
    char *denoise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/denoise/";
    char *contour_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/";
    puts("------------------------");
    puts("--- test_fgl part1 ---");
    puts("------------------------");
    routine_fgl(src_path, "carre64", contour_path);
    routine_fgl(noise_path, "carre64_GN_01", contour_path);
    routine_fgl(denoise_path, "carre64_IN_005_M_1", contour_path);
  }


decompiled_code:
__int64 __fastcall routine_contour_threshold(__int64 a1, const char *a2, unsigned __int8 a3, __int64 a4)
{
__int64 v6; // r12
__int64 v7; // rbx
unsigned int v8; // er13
__int64 v10; // [rsp+0h] [rbp-448h] BYREF
__int64 v11; // [rsp+8h] [rbp-440h] BYREF
__int64 v12; // [rsp+10h] [rbp-438h] BYREF
__int64 v13; // [rsp+18h] [rbp-430h] BYREF
char s[1064]; // [rsp+20h] [rbp-428h] BYREF

puts("=================================");
printf(" === %s ===\n", a2);
puts("=================================");
generate_path_filename_extension(a1, a2, &unk_714, s);
puts(s);
v6 = LoadPGM_ui8matrix(s, &v13, &v12, &v11, &v10);
v7 = ui8matrix(v13, v12, v11, v10);
display_ui8matrix(v6, v13, v12, v11, v10, "%4d", a2);
puts("\n=============================================\n");
threshold_ui8matrix(v6, (unsigned int)v13, (unsigned int)v12, (unsigned int)v11, (unsigned int)v10, a3, 255LL, v7);
display_ui8matrix(v7, v13, v12, v11, v10, "%4d", "Thresold");
generate_path_filename_sep_k_ndigit_extension(a4, a2, "_T_", a3, 3LL, &unk_714, s);
puts(s);
SavePGM_ui8matrix(v7, v13, v12, v11, v10, s);
puts("\n=============================================\n");
v8 = calc_otsu_threshold_ui8matrix(v6, (unsigned int)v13, (unsigned int)v12, (unsigned int)v11, (unsigned int)v10);
threshold_ui8matrix(
v6,
(unsigned int)v13,
(unsigned int)v12,
(unsigned int)v11,
(unsigned int)v10,
(unsigned __int8)v8,
255LL,
v7);
display_ui8matrix(v7, v13, v12, v11, v10, "%4d", "Otsu threshold");
generate_path_filename_sep_k_ndigit_extension(a4, a2, "_OTSU_", v8, 3LL, &unk_714, s);
puts(s);
SavePGM_ui8matrix(v7, v13, v12, v11, v10, s);
return free_ui8matrix(v7, v13, v12, v11, v10);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, unsigned __int8 a3, __int64 a4)
{
__int64 v6; // r12
__int64 v7; // rbx
unsigned int v8; // er13
__int64 v10; // [rsp+0h] [rbp-448h] BYREF
__int64 v11; // [rsp+8h] [rbp-440h] BYREF
__int64 v12; // [rsp+10h] [rbp-438h] BYREF
__int64 v13; // [rsp+18h] [rbp-430h] BYREF
char s[1064]; // [rsp+20h] [rbp-428h] BYREF

puts("=================================");
printf(" === %s ===\n", a2);
puts("=================================");
generate_path_filename_extension(a1, a2, &unk_714, s);
puts(s);
v6 = LoadPGM_ui8matrix(s, &v13, &v12, &v11, &v10);
v7 = ui8matrix(v13, v12, v11, v10);
display_ui8matrix(v6, v13, v12, v11, v10, "%4d", a2);
puts("\n=============================================\n");
threshold_ui8matrix(v6, (unsigned int)v13, (unsigned int)v12, (unsigned int)v11, (unsigned int)v10, a3, 255LL, v7);
display_ui8matrix(v7, v13, v12, v11, v10, "%4d", "Thresold");
generate_path_filename_sep_k_ndigit_extension(a4, a2, "_T_", a3, 3LL, &unk_714, s);
puts(s);
SavePGM_ui8matrix(v7, v13, v12, v11, v10, s);
puts("\n=============================================\n");
v8 = calc_otsu_threshold_ui8matrix(v6, (unsigned int)v13, (unsigned int)v12, (unsigned int)v11, (unsigned int)v10);
threshold_ui8matrix(
v6,
(unsigned int)v13,
(unsigned int)v12,
(unsigned int)v11,
(unsigned int)v10,
(unsigned __int8)v8,
255LL,
v7);
display_ui8matrix(v7, v13, v12, v11, v10, "%4d", "Otsu threshold");
generate_path_filename_sep_k_ndigit_extension(a4, a2, "_OTSU_", v8, 3LL, &unk_714, s);
puts(s);
SavePGM_ui8matrix(v7, v13, v12, v11, v10, s);
return free_ui8matrix(v7, v13, v12, v11, v10);
}

original_code:
void routine_contour_threshold(char *src_path, char *filename, uint8 threshold, char *dst_path)
{
    char complete_filename[1024];
    char *sep;
    int k;
    int optimal_threhsold;
    int ndigit = 3;
    uint8 value = 255;
    uint8 **X, **Y;
    long i0, i1, j0, j1;
    puts("=================================");
    printf(" === %s ===\n", filename);
    puts("=================================");
    k = threshold;
    generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename);
    X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1);
    Y = ui8matrix(i0, i1, j0, j1);
    display_ui8matrix(X, i0, i1, j0, j1, "%4d", filename);
    puts("\n=============================================\n");
    sep = "_T_";
    threshold_ui8matrix(X, i0, i1, j0, j1, threshold, value, Y);
    display_ui8matrix(Y, i0, i1, j0, j1, "%4d", "Thresold");
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename); puts(complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    puts("\n=============================================\n");
    sep = "_OTSU_";
    optimal_threhsold = calc_otsu_threshold_ui8matrix(X, i0, i1, j0, j1);
    k = optimal_threhsold;
    threshold_ui8matrix(X, i0, i1, j0, j1, optimal_threhsold, value, Y);
    display_ui8matrix(Y, i0, i1, j0, j1, "%4d", "Otsu threshold");
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename); puts(complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    free_ui8matrix(Y, i0, i1, j0, j1);
}

canonical_original_code:
void routine_contour_threshold(char *src_path, char *filename, unsigned char threshold, char *dst_path)
{
    char complete_filename[1024];
    char *sep;
    int k;
    int optimal_threhsold;
    int ndigit = 3;
    unsigned char value = 255;
    unsigned char **X; unsigned char **Y;
    long i0; long i1; long j0; long j1;
    puts("=================================");
    printf(" === %s ===\n", filename);
    puts("=================================");
    k = threshold;
    generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename);
    X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1);
    Y = ui8matrix(i0, i1, j0, j1);
    display_ui8matrix(X, i0, i1, j0, j1, "%4d", filename);
    puts("\n=============================================\n");
    sep = "_T_";
    threshold_ui8matrix(X, i0, i1, j0, j1, threshold, value, Y);
    display_ui8matrix(Y, i0, i1, j0, j1, "%4d", "Thresold");
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename); puts(complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    puts("\n=============================================\n");
    sep = "_OTSU_";
    optimal_threhsold = calc_otsu_threshold_ui8matrix(X, i0, i1, j0, j1);
    k = optimal_threhsold;
    threshold_ui8matrix(X, i0, i1, j0, j1, optimal_threhsold, value, Y);
    display_ui8matrix(Y, i0, i1, j0, j1, "%4d", "Otsu threshold");
    generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename); puts(complete_filename);
    SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename);
    free_ui8matrix(Y, i0, i1, j0, j1);
}

variable_types:
threshold
unsigned char

variable_types:
value
unsigned char


decompiled_code:
__int64 test_contour_threshold()
{
puts("----------------------------");
puts("--- test_threshold part1 ---");
puts("----------------------------");
return routine_contour_threshold(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/",
"carre64_GN_01_S",
0x40u,
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/");
}

canonical_decompiled_code:
__int64 func5()
{
puts("----------------------------");
puts("--- test_threshold part1 ---");
puts("----------------------------");
return func4(
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/",
"carre64_GN_01_S",
0x40u,
(__int64)"/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/");
}

original_code:
void test_contour_threshold(void)
{
    char *noise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/";
    char *src_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/";
    char *threshold_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/";
    puts("----------------------------");
    puts("--- test_threshold part1 ---");
    puts("----------------------------");
    routine_contour_threshold(noise_path, "carre64_GN_01_S", 64, threshold_path);
}

canonical_original_code:
void test_contour_threshold()
{
    char *noise_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/";
    char *src_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/src/";
    char *threshold_path = "/home/vinneur/Documents/Traitement_image/tp1_filtrage/VION/images/contour/";
    puts("----------------------------");
    puts("--- test_threshold part1 ---");
    puts("----------------------------");
    routine_contour_threshold(noise_path, "carre64_GN_01_S", 64, threshold_path);
}


original_code:
int test_contourNR(int argc, const char * argv[])
{
    puts("======================");
    puts("=== test_contourNR ===");
    puts("======================");
    test_sobel();
    test_contour_threshold();
    return 0;
}

canonical_original_code:
int test_contourNR(int argc, char *argv[])
{
    puts("======================");
    puts("=== test_contourNR ===");
    puts("======================");
    test_sobel();
    test_contour_threshold();
    return 0;
}


decompiled_code:
__int64 __fastcall alloc_kernel(int a1)
{
return f32matrix(-a1, a1, -a1, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return f32matrix(-a1, a1, -a1, a1);
}

original_code:
float32** alloc_kernel(int radius)
{
    float32 **K;
    K = f32matrix(-radius, radius, -radius, radius);
    return K;
}

canonical_original_code:
float **alloc_kernel(int radius)
{
    float **K;
    K = f32matrix(-radius, radius, -radius, radius);
    return K;
}

variable_types:
K
float **

return_type: float **


decompiled_code:
__int64 __fastcall free_kernel(__int64 a1, int a2)
{
return free_f32matrix(a1, -a2, a2, -a2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
return free_f32matrix(a1, -a2, a2, -a2, a2);
}

original_code:
void free_kernel(float32 **K, int radius)
{
    free_f32matrix(K, -radius, radius, -radius, radius);
}

canonical_original_code:
void free_kernel(float **K, int radius)
{
    free_f32matrix(K, -radius, radius, -radius, radius);
}


decompiled_code:
__int64 __fastcall display_kernel(__int64 a1, int a2, __int64 a3, __int64 a4)
{
return display_f32matrix(a1, -a2, a2, -a2, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, __int64 a3, __int64 a4)
{
return display_f32matrix(a1, -a2, a2, -a2, a2, a3, a4);
}

original_code:
void display_kernel(float32 **K, int radius, char *format, char *name)
{
    display_f32matrix(K, -radius, +radius, -radius, +radius, format, name);
}

canonical_original_code:
void display_kernel(float **K, int radius, char *format, char *name)
{
    display_f32matrix(K, -radius, +radius, -radius, +radius, format, name);
}

variable_types:
format
char *

variable_types:
name
char *


decompiled_code:
__int64 __fastcall init_average_kernel(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // edx
float v4; // xmm0_4
_QWORD *v5; // rcx
__int64 v6; // rax
__int64 v7; // r8
__int64 v8; // rsi

result = (unsigned int)((2 * a2 + 1) * (2 * a2 + 1));
v3 = -a2;
if ( ((a2 & 0x40000000) != 0) == __OFSUB__(a2, -a2) )
{
v4 = 1.0 / (float)(int)result;
v5 = (_QWORD *)(a1 + 8LL * v3);
v6 = (unsigned int)(2 * a2);
v7 = a1 + 8 * (v3 + v6) + 8;
v8 = 4 * (v3 + v6 + 1);
do
{
result = 4LL * v3;
do
{
*(float *)(*v5 + result) = v4;
result += 4LL;
}
while ( result != v8 );
++v5;
}
while ( v5 != (_QWORD *)v7 );
}
return result;
}

original_code:
void init_average_kernel(float32 **K, int radius)
{
    int i, j;
    float32 x, sx = (2*radius+1)*(2*radius+1);
    for(i=-radius; i<=radius; i++) {
        for(j=-radius; j<=radius; j++) {
            x = 1.0f / sx;
            K[i][j] = x;
        }
    }
}

canonical_original_code:
void init_average_kernel(float **K, int radius)
{
    int i; int j;
    float x; float sx = (2*radius+1)*(2*radius+1);
    for(i=-radius; i<=radius; i++) {
        for(j=-radius; j<=radius; j++) {
            x = 1.0f / sx;
            K[i][j] = x;
        }
    }
}

variable_types: i int

variable_types: j int

variable_types: x float

variable_types: sx float


original_code:
void convolve_kernel_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, float32 **K, int radius, uint8 **Y)
{
    int i, j;
    int ii, jj;
    uint8 **T;
    float32 y;
    T = ui8matrix(i0-radius, i1+radius, j0-radius, j1+radius);
    zero_ui8matrix(T, i0-radius, i1+radius, j0-radius, j1+radius);
    dup_ui8matrix(X, i0, i1, j0, j1, T);
    extend_ui8matrix(T, i0, i1, j0, j1, radius);
    for(i=i0; i<=i1; i++) {
        for(j=j0; j<=j1; j++) {
            y = 0.0f;
            for(ii=-radius; ii<=radius; ii++) {
                for(jj=-radius; jj<=radius; jj++) {
                    y += T[i+ii][j+jj] * K[ii][jj];
                }
            }
            if(y<0.0f) y = 0.0f;
            if(y>255.0f) y = 255.0f;
            Y[i][j] = (uint8) y;
        }
    }
    free_ui8matrix(T, i0-radius, i1+radius, j0-radius, j1+radius);
}

canonical_original_code:
void convolve_kernel_ui8matrix(unsigned char **X, int i0, int i1, int j0, int j1, float **K, int radius, unsigned char **Y)
{
    int i; int j;
    int ii; int jj;
    unsigned char **T;
    float y;
    T = ui8matrix(i0-radius, i1+radius, j0-radius, j1+radius);
    zero_ui8matrix(T, i0-radius, i1+radius, j0-radius, j1+radius);
    dup_ui8matrix(X, i0, i1, j0, j1, T);
    extend_ui8matrix(T, i0, i1, j0, j1, radius);
    for(i=i0; i<=i1; i++) {
        for(j=j0; j<=j1; j++) {
            y = 0.0f;
            for(ii=-radius; ii<=radius; ii++) {
                for(jj=-radius; jj<=radius; jj++) {
                    y += T[i+ii][j+jj] * K[ii][jj];
                }
            }
            if(y<0.0f) y = 0.0f;
            if(y>255.0f) y = 255.0f;
            Y[i][j] = (unsigned char) y;
        }
    }
    free_ui8matrix(T, i0-radius, i1+radius, j0-radius, j1+radius);
}

variable_types: radius int

variable_types: ii int

variable_types: jj int

variable_types:
T
unsigned char **

variable_types: y float


decompiled_code:
void __fastcall sort_selection_ui8vector(__int64 a1, int a2, int a3)
{
int v4; // edi
unsigned __int8 *v5; // rax
unsigned __int8 v6; // dl
unsigned __int8 v7; // cl

if ( a2 < a3 )
{
v4 = a3 - a2;
do
{
if ( a2 < v4 )
{
v5 = (unsigned __int8 *)(a1 + a2);
do
{
v6 = *v5;
v7 = v5[1];
if ( *v5 > v7 )
{
*v5 = v7;
v5[1] = v6;
}
++v5;
}
while ( v5 != (unsigned __int8 *)(a1 + a2 + 1 + (unsigned int)(~a2 + v4)) );
}
--v4;
}
while ( v4 );
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2, int a3)
{
int v4; // edi
unsigned __int8 *v5; // rax
unsigned __int8 v6; // dl
unsigned __int8 v7; // cl

if ( a2 < a3 )
{
v4 = a3 - a2;
do
{
if ( a2 < v4 )
{
v5 = (unsigned __int8 *)(a1 + a2);
do
{
v6 = *v5;
v7 = v5[1];
if ( *v5 > v7 )
{
*v5 = v7;
v5[1] = v6;
}
++v5;
}
while ( v5 != (unsigned __int8 *)(a1 + a2 + 1 + (unsigned int)(~a2 + v4)) );
}
--v4;
}
while ( v4 );
}
}

original_code:
void sort_selection_ui8vector(uint8 *X, int i0, int i1)
{
    int c,d;
    uint8 swap;
    for (c = i0; c < i1; c++) {
        for (d = i0 ; d < i1 - c; d++) {
            if (X[d] > X[d+1]){
                swap = X[d];
                X[d] = X[d+1];
                X[d+1] = swap;
            }
        }
    }
}

canonical_original_code:
void sort_selection_ui8vector(unsigned char *X, int i0, int i1)
{
    int c; int d;
    unsigned char swap;
    for (c = i0; c < i1; c++) {
        for (d = i0 ; d < i1 - c; d++) {
            if (X[d] > X[d+1]){
                swap = X[d];
                X[d] = X[d+1];
                X[d+1] = swap;
            }
        }
    }
}

variable_types:
X
unsigned char *

variable_types: c int

variable_types: d int

variable_types:
swap
unsigned char


original_code:
void median_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, int radius, uint8 **Y)
{
    int i, j;
    int ii, jj;
    int k;
    uint8 **T;
    float32 y;
    uint8 *vec;
    vec = ui8vector(0,(2*radius+1)*(2*radius+1));
    T = ui8matrix(i0-radius, i1+radius, j0-radius, j1+radius);
    zero_ui8matrix(T, i0-radius, i1+radius, j0-radius, j1+radius);
    dup_ui8matrix(X, i0, i1, j0, j1, T);
    extend_ui8matrix(T, i0, i1, j0, j1, radius);
    for(i=i0; i<=i1; i++) {
        for(j=j0; j<=j1; j++) {
            k = 0;
            for(ii=-radius; ii<=radius; ii++) {
                for(jj=-radius; jj<=radius; jj++) {
                    vec[k]= T[i+ii][j+jj];
                    k ++;
                }
            }
            if(y<0.0f) y = 0.0f;
            if(y>255.0f) y = 255.0f;
            sort_selection_ui8vector(vec,0,k);
            Y[i][j] = (uint8) vec[radius*radius];
        }
    }
    free_ui8matrix(T, i0-radius, i1+radius, j0-radius, j1+radius);
}

canonical_original_code:
void median_ui8matrix(unsigned char **X, int i0, int i1, int j0, int j1, int radius, unsigned char **Y)
{
    int i; int j;
    int ii; int jj;
    int k;
    unsigned char **T;
    float y;
    unsigned char *vec;
    vec = ui8vector(0,(2*radius+1)*(2*radius+1));
    T = ui8matrix(i0-radius, i1+radius, j0-radius, j1+radius);
    zero_ui8matrix(T, i0-radius, i1+radius, j0-radius, j1+radius);
    dup_ui8matrix(X, i0, i1, j0, j1, T);
    extend_ui8matrix(T, i0, i1, j0, j1, radius);
    for(i=i0; i<=i1; i++) {
        for(j=j0; j<=j1; j++) {
            k = 0;
            for(ii=-radius; ii<=radius; ii++) {
                for(jj=-radius; jj<=radius; jj++) {
                    vec[k]= T[i+ii][j+jj];
                    k ++;
                }
            }
            if(y<0.0f) y = 0.0f;
            if(y>255.0f) y = 255.0f;
            sort_selection_ui8vector(vec,0,k);
            Y[i][j] = (unsigned char) vec[radius*radius];
        }
    }
    free_ui8matrix(T, i0-radius, i1+radius, j0-radius, j1+radius);
}

variable_types:
X
unsigned char **

variable_types:
Y
unsigned char **

variable_types: k int

variable_types:
vec
unsigned char *


decompiled_code:
void roberts_ui8matrix()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void roberts_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 **Y)
{
}

canonical_original_code:
void roberts_ui8matrix(unsigned char **X, int i0, int i1, int j0, int j1, unsigned char **Y)
{
}


decompiled_code:
void fgl_ui8matrix()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void fgl_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, float32 alpha, uint8 **Y)
{
}

canonical_original_code:
void fgl_ui8matrix(unsigned char **X, int i0, int i1, int j0, int j1, float alpha, unsigned char **Y)
{
}

variable_types: alpha float


decompiled_code:
void max_dir_ui8matrix()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void max_dir_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 **Y)
{
}

canonical_original_code:
void max_dir_ui8matrix(unsigned char **X, int i0, int i1, int j0, int j1, unsigned char **Y)
{
}


decompiled_code:
void max_dir_ext_ui8matrix()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void max_dir_ext_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 **Y)
{
}

canonical_original_code:
void max_dir_ext_ui8matrix(unsigned char **X, int i0, int i1, int j0, int j1, unsigned char **Y)
{
}


variable_types: i int

variable_types: j int

variable_types:
Kx
char **

variable_types:
Ky
char **


decompiled_code:
float __fastcall gaussian_noise(float a1, float a2)
{
return (float)(gasdev(&seed_1) * a2) + a1;
}

canonical_decompiled_code:
float __fastcall func0(float a1, float a2)
{
return (float)(gasdev(&seed_1) * a2) + a1;
}

original_code:
float32 gaussian_noise(float32 average, float32 sigma)
{
    static long seed = 0x101;
    float g, r;
    g = gasdev(&seed);
    r = average + sigma * g;
    return r;
}

canonical_original_code:
float gaussian_noise(float average, float sigma)
{
    static long seed = 0x101;
    float g; float r;
    g = gasdev(&seed);
    r = average + sigma * g;
    return r;
}

variable_types: average float

variable_types: sigma float

variable_types: seed long

variable_types: g float

variable_types: r float

return_type: float


original_code:
void gaussian_noise_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, float32 sigma, uint8 **Y)
{
    int i, j;
    float32 x, y, g;
    for(i=i0; i<=i1; i++) {
        for(j=j0; j<=j1; j++) {
            x = X[i][j];
            g = gaussian_noise(0.0f, sigma);
            y = x + g;
            if(y<0.0f) y = 0.0f;
            if(y>255.0f) y = 255.0f;
            Y[i][j] = (uint8) y;
        }
    }
}

canonical_original_code:
void gaussian_noise_ui8matrix(unsigned char **X, int i0, int i1, int j0, int j1, float sigma, unsigned char **Y)
{
    int i; int j;
    float x; float y; float g;
    for(i=i0; i<=i1; i++) {
        for(j=j0; j<=j1; j++) {
            x = X[i][j];
            g = gaussian_noise(0.0f, sigma);
            y = x + g;
            if(y<0.0f) y = 0.0f;
            if(y>255.0f) y = 255.0f;
            Y[i][j] = (unsigned char) y;
        }
    }
}

variable_types: x float

variable_types: y float


decompiled_code:
__int64 __fastcall impulse_noise_ui8matrix(__int64 a1, int a2, int a3, int a4, int a5, __int64 a6, float a7)
{
__int64 v8; // r14
_QWORD *v9; // rbp
__int64 v10; // rbx
__int64 result; // rax
__int64 v15; // [rsp+18h] [rbp-40h]

if ( a2 <= a3 )
{
v8 = a2;
v9 = (_QWORD *)(a6 + 8LL * a2);
v15 = a4;
do
{
v10 = v15;
result = (unsigned int)a4;
if ( a4 <= a5 )
{
do
{
if ( ran1(&seed_0) <= a7 )
*(_BYTE *)(*v9 + v10) = -1;
else
*(_BYTE *)(*v9 + v10) = *(_BYTE *)(*(_QWORD *)(a1 + 8 * v8) + v10);
result = (unsigned int)(a4 - v15 + ++v10);
}
while ( (int)result <= a5 );
}
++v8;
++v9;
}
while ( a3 >= (int)v8 );
}
return result;
}

original_code:
void impulse_noise_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, float32 percent, uint8 **Y)
{
    int i, j;
    float32 r;
    static long seed = 0x101;
    for(i=i0; i<=i1; i++) {
        for(j=j0; j<=j1; j++) {
            r = ran1(&seed);
            if(r>percent) {
                Y[i][j] = X[i][j];
            } else {
                Y[i][j] = 255;
            }
        }
    }
}

canonical_original_code:
void impulse_noise_ui8matrix(unsigned char **X, int i0, int i1, int j0, int j1, float percent, unsigned char **Y)
{
    int i; int j;
    float r;
    static long seed = 0x101;
    for(i=i0; i<=i1; i++) {
        for(j=j0; j<=j1; j++) {
            r = ran1(&seed);
            if(r>percent) {
                Y[i][j] = X[i][j];
            } else {
                Y[i][j] = 255;
            }
        }
    }
}

variable_types: percent float


psnr

decompiled_code:
float __fastcall psnr(__int64 a1, int a2, int a3, int a4, int a5, __int64 a6)
{
float v6; // xmm0_4
float result; // xmm0_4

v6 = COERCE_FLOAT(mean_square_error(a1, a2, a3, a4, a5, a6));
if ( v6 == 0.0 )
result = 0.0;
else
result = 4.81308036086791 / log10(v6) * 10.0;
return result;
}

canonical_decompiled_code:
float __fastcall func3(__int64 a1, int a2, int a3, int a4, int a5, __int64 a6)
{
float v6; // xmm0_4
float result; // xmm0_4

v6 = COERCE_FLOAT(mean_square_error(a1, a2, a3, a4, a5, a6));
if ( v6 == 0.0 )
result = 0.0;
else
result = 4.81308036086791 / log10(v6) * 10.0;
return result;
}

original_code:
float32 psnr(uint8 **X, int i0, int i1, int j0, int j1, uint8 **Y)
{
    float32 mse;
    float32 psnr;
    mse = mean_square_error(X, i0, i1, j0, j1, Y);
    if(mse != 0.0f) {
        psnr = 10 * (log10(255*255) / log10(mse));
    } else {
        psnr = 0.0;
    }
    return psnr;
}

canonical_original_code:
float psnr(unsigned char **X, int i0, int i1, int j0, int j1, unsigned char **Y)
{
    float mse;
    float psnr;
    mse = mean_square_error(X, i0, i1, j0, j1, Y);
    if(mse != 0.0f) {
        psnr = 10 * (log10(255*255) / log10(mse));
    } else {
        psnr = 0.0;
    }
    return psnr;
}

variable_types:
X
unsigned char **

variable_types: mse float

variable_types: psnr float


decompiled_code:
float __fastcall gauss1D(float a1, float a2)
{
return 1.0
/ (a1
* 2.506628309507644)
* exp((float)(COERCE_FLOAT(COERCE_UNSIGNED_INT(a2 * a2) ^ LC0) / (float)((float)(a1 + a1) * a1)));
}

canonical_decompiled_code:
float __fastcall func0(float a1, float a2)
{
return 1.0
/ (a1
* 2.506628309507644)
* exp((float)(COERCE_FLOAT(COERCE_UNSIGNED_INT(a2 * a2) ^ LC0) / (float)((float)(a1 + a1) * a1)));
}

original_code:
float32 gauss1D(float32 sigma, float32 x)
{
    float32 pi = 3.1415927;
    float32 r;
    r = 1.0f / (sqrt(2*pi)*sigma) * exp(-(x*x)/(2*sigma*sigma));
    return r;
}

canonical_original_code:
float gauss1D(float sigma, float x)
{
    float pi = 3.1415927;
    float r;
    r = 1.0f / (sqrt(2*pi)*sigma) * exp(-(x*x)/(2*sigma*sigma));
    return r;
}

variable_types: pi float


decompiled_code:
float __fastcall gauss2D(float a1, float a2, float a3)
{
return 1.0
/ (a1
* 2.506628309507644)
* exp((float)(COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(a2 * a2) + (float)(a3 * a3)) ^ LC0)
/ (float)((float)(a1 + a1) * a1)));
}

canonical_decompiled_code:
float __fastcall func1(float a1, float a2, float a3)
{
return 1.0
/ (a1
* 2.506628309507644)
* exp((float)(COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(a2 * a2) + (float)(a3 * a3)) ^ LC0)
/ (float)((float)(a1 + a1) * a1)));
}

original_code:
float32 gauss2D(float32 sigma, float32 x, float32 y)
{
    float32 pi = 3.1415927;
    float32 r;
    r = 1.0f / (sqrt(2*pi)*sigma) * exp(-(x*x+y*y)/(2*sigma*sigma));
    return r;
}

canonical_original_code:
float gauss2D(float sigma, float x, float y)
{
    float pi = 3.1415927;
    float r;
    r = 1.0f / (sqrt(2*pi)*sigma) * exp(-(x*x+y*y)/(2*sigma*sigma));
    return r;
}


test

decompiled_code:
__int64 __fastcall test(unsigned int a1, __int64 a2)
{
puts("test");
test_filterNR(a1, a2);
test_contourNR(a1, a2);
test_morphoNR(a1, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
puts("test");
test_filterNR(a1, a2);
test_contourNR(a1, a2);
test_morphoNR(a1, a2);
return 0LL;
}

original_code:
int test (int argc, const char * argv[])
{
    puts("test");
    test_filterNR(argc, argv);
    test_contourNR(argc, argv);
    test_morphoNR(argc, argv);
    return 0;
}

canonical_original_code:
int test(int argc, char *argv[])
{
    puts("test");
    test_filterNR(argc, argv);
    test_contourNR(argc, argv);
    test_morphoNR(argc, argv);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: rvsjoen/game-of-life

decompiled_code:
int __fastcall set_color(__int64 a1, int *a2)
{
int v3; // esi
int v4; // eax

if ( a2[1] || (v3 = 4, *a2 != 3) )
{
v4 = *a2;
v3 = 1;
if ( v4 > 1 )
v3 = ((unsigned int)(v4 - 2) > 1) + 2;
}
return wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, (unsigned int)(v3 << 8), 0LL);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, int *a2)
{
int v3; // esi
int v4; // eax

if ( a2[1] || (v3 = 4, *a2 != 3) )
{
v4 = *a2;
v3 = 1;
if ( v4 > 1 )
v3 = ((unsigned int)(v4 - 2) > 1) + 2;
}
return wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, (unsigned int)(v3 << 8), 0LL);
}

original_code:
void set_color(int** cworld, CellState* state) {
  int pair;
  if ((state->status == 0)
   && (state->neighbors == 3))
    pair = 4;
  else {
    if (state->neighbors < 2)
      pair = 1;
    else if ((state->neighbors >= 2)
          && (state->neighbors <= 3))
      pair = 2;
    else if (state->neighbors > 3)
      pair = 3;
  }
  wattr_on(stdscr, (attr_t)(((((chtype)(((pair))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
}

canonical_original_code:
void set_color(int **cworld, struct cell_state *state) {
  int pair;
  if ((state->status == 0)
   && (state->neighbors == 3))
    pair = 4;
  else {
    if (state->neighbors < 2)
      pair = 1;
    else if ((state->neighbors >= 2)
          && (state->neighbors <= 3))
      pair = 2;
    else if (state->neighbors > 3)
      pair = 3;
  }
  wattr_on(stdscr, (attr_t)(((((chtype)(((pair))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
}

variable_types:
cworld
int **

variable_types: struct cell_state { int neighbors; int status; } *

variable_types: pair int


decompiled_code:
char init_colors()
{
char result; // al

result = has_colors();
if ( result )
{
start_color();
init_pair(1, 1, 0);
init_pair(2, 4, 0);
init_pair(4, 2, 0);
result = init_pair(3, 6, 0);
}
return result;
}

canonical_decompiled_code:
char func8()
{
char result; // al

result = has_colors();
if ( result )
{
start_color();
init_pair(1, 1, 0);
init_pair(2, 4, 0);
init_pair(4, 2, 0);
result = init_pair(3, 6, 0);
}
return result;
}

original_code:
void init_colors() {
  if (has_colors()) {
    start_color();
    init_pair(1, 1, 0);
    init_pair(2, 4, 0);
    init_pair(4, 2, 0);
    init_pair(3, 6, 0);
  }
}


decompiled_code:
int exit_gracefully()
{
return endwin();
}

canonical_decompiled_code:
int func9()
{
return endwin();
}

original_code:
void exit_gracefully(){
 endwin();
}

canonical_original_code:
void exit_gracefully(){
 endwin();
}


readfile

original_code:
void readfile(char* name, int scr_w, int scr_h){
 int fd;
 if((fd = open(name, 00)) == -1 )
  exit_gracefully(), exit(1);
 int istate_w = 0;
 int istate_h = 0;
 char buf;
 while(read(fd, &buf, 1)){
  if(buf == '\n')
   istate_h++, istate_w = 0;
  else
   istate_w++;
 }
 lseek(fd, 0, 0);
 int x = 0, y = 0;
 while(read(fd, &buf, 1)){
  if(buf == '\n'){
   y++;
   x=0;
  } else {
   x++;
   if(buf == '1')
    world[0][y+scr_h/2-istate_h/2][x+scr_w/2-istate_w/2] = 1;
  }
 }
 close(fd);
}

canonical_original_code:
void readfile(char *name, int scr_w, int scr_h){
 int fd;
 if((fd = open(name, 00)) == -1 )
  exit_gracefully(), exit(1);
 int istate_w = 0;
 int istate_h = 0;
 char buf;
 while(read(fd, &buf, 1)){
  if(buf == '\n')
   istate_h++, istate_w = 0;
  else
   istate_w++;
 }
 lseek(fd, 0, 0);
 int x = 0; int y = 0;
 while(read(fd, &buf, 1)){
  if(buf == '\n'){
   y++;
   x=0;
  } else {
   x++;
   if(buf == '1')
    world[0][y+scr_h/2-istate_h/2][x+scr_w/2-istate_w/2] = 1;
  }
 }
 close(fd);
}

variable_types:
name
char *

variable_types: fd int

variable_types: buf char

variable_types: x int

variable_types: y int


zero

decompiled_code:
void *__fastcall zero(void **a1, int a2, int a3)
{
void **v3; // rbx
__int64 v4; // r12
void *result; // rax

if ( a3 > 0 )
{
v3 = a1;
v4 = (__int64)&a1[(unsigned int)(a3 - 1) + 1];
do
result = memset(*v3++, 0, 4LL * a2);
while ( v3 != (void **)v4 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func11(void **a1, int a2, int a3)
{
void **v3; // rbx
__int64 v4; // r12
void *result; // rax

if ( a3 > 0 )
{
v3 = a1;
v4 = (__int64)&a1[(unsigned int)(a3 - 1) + 1];
do
result = memset(*v3++, 0, 4LL * a2);
while ( v3 != (void **)v4 );
}
return result;
}

original_code:
void zero(int** cworld, int x, int y){
  int i;
  for(i=0;i<y;i++)
   memset(cworld[i], 0, sizeof(int)*x);
}

canonical_original_code:
void zero(int **cworld, int x, int y){
  int i;
  for(i=0;i<y;i++)
   memset(cworld[i], 0, sizeof(int)*x);
}

variable_types: i int


init

decompiled_code:
void *__fastcall init(int a1, int a2)
{
void ***v2; // r15
unsigned __int64 v3; // rbx
void **v4; // rbp
void *result; // rax

v2 = (void ***)&world;
do
{
*v2 = (void **)malloc(8LL * a2);
if ( a2 > 0 )
{
v3 = 0LL;
do
{
v4 = &(*v2)[v3 / 8];
*v4 = malloc(4LL * a1);
v3 += 8LL;
}
while ( v3 != 8LL * (unsigned int)(a2 - 1) + 8 );
}
result = zero(*v2++, a1, a2);
}
while ( v2 != (void ***)&end );
return result;
}

canonical_decompiled_code:
void *__fastcall func12(int a1, int a2)
{
void ***v2; // r15
unsigned __int64 v3; // rbx
void **v4; // rbp
void *result; // rax

v2 = (void ***)&world;
do
{
*v2 = (void **)malloc(8LL * a2);
if ( a2 > 0 )
{
v3 = 0LL;
do
{
v4 = &(*v2)[v3 / 8];
*v4 = malloc(4LL * a1);
v3 += 8LL;
}
while ( v3 != 8LL * (unsigned int)(a2 - 1) + 8 );
}
result = func11(*v2++, a1, a2);
}
while ( v2 != (void ***)&end );
return result;
}

original_code:
void init(int x, int y){
 int i;
 for(i=0;i<2;i++){
  world[i] = malloc(sizeof(int*)*y);
  int j;
  for(j=0;j<y;j++){
   world[i][j] = malloc(sizeof(int)*x);
  }
  zero(world[i], x, y);
 }
}

canonical_original_code:
void init(int x, int y){
 int i;
 for(i=0;i<2;i++){
  world[i] = malloc(sizeof(int *)*y);
  int j;
  for(j=0;j<y;j++){
   world[i][j] = malloc(sizeof(int)*x);
  }
  zero(world[i], x, y);
 }
}

variable_types: j int


freeMem

decompiled_code:
void freeMem()
{
free(world);
free(ptr);
}

canonical_decompiled_code:
void func13()
{
free(world);
free(ptr);
}

original_code:
void freeMem(int x, int y) {
 int i;
 for(i=0;i<2;i++){
      free(world[i]);
 }
}


tick

original_code:
int** tick(int width, int height){
 int** cworld = world[current];
 current = ( current + 1 ) % 2;
 int** nworld = world[current];
 int x, y;
 for(x=0; x<width; x++){
  for(y=0; y<height; y++){
   CellState* state = get_cell_state(cworld, x, y, width, height);
      int cnt = state->neighbors;
   switch(cnt){
    case 0: case 1:
     nworld[y][x] = 0; break;
    case 2: case 3:
     if(cworld[y][x] == 0 && cnt == 3)
      nworld[y][x] = 1;
     else
      nworld[y][x] = cworld[y][x];
     break;
    case 4: case 5: case 6: case 7: case 8:
     nworld[y][x] = 0; break;
   }
      free(state);
  }
 }
 return nworld;
}

canonical_original_code:
int **tick(int width, int height){
 int **cworld = world[current];
 current = ( current + 1 ) % 2;
 int **nworld = world[current];
 int x; int y;
 for(x=0; x<width; x++){
  for(y=0; y<height; y++){
   struct cell_state *state = get_cell_state(cworld, x, y, width, height);
      int cnt = state->neighbors;
   switch(cnt){
    case 0: case 1:
     nworld[y][x] = 0; break;
    case 2: case 3:
     if(cworld[y][x] == 0 && cnt == 3)
      nworld[y][x] = 1;
     else
      nworld[y][x] = cworld[y][x];
     break;
    case 4: case 5: case 6: case 7: case 8:
     nworld[y][x] = 0; break;
   }
      free(state);
  }
 }
 return nworld;
}

variable_types: width int

variable_types: height int

variable_types:
nworld
int **

variable_types: cnt int

return_type: int **

user_defined_types: struct cell_state { int neighbors; int status; }


threadworker

decompiled_code:
void __fastcall __noreturn threadworker(void *a1)
{
void *v1; // rbx
pthread_t v2; // r12
size_t v3; // rax

v1 = malloc(0x100uLL);
memset(v1, 0, 0x100uLL);
if ( (int)read((int)a1, v1, 0x100uLL) >= 0 )
{
printf("New message received: %s", (const char *)v1);
memset(v1, 0, 0x100uLL);
v2 = pthread_self();
sprintf((char *)v1, "Acknowledgement from TID:0x%x", v2);
v3 = strlen((const char *)v1);
if ( (int)write((int)a1, v1, v3) >= 0 )
{
puts("Requesting mutex lock...");
pthread_mutex_lock(&lock);
printf("Current counter value: %d, upping by 1...\n", (unsigned int)counter);
++counter;
pthread_mutex_unlock(&lock);
printf("Done! Mutex unlocked again, new counter value: %d\n", (unsigned int)counter);
close((int)a1);
printf("TID:0x%x served request, exiting thread\n", v2);
pthread_exit(0LL);
}
perror("Error writing to socket, exiting thread");
pthread_exit(0LL);
}
perror("Error reading form socket, exiting thread");
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
void *v1; // rbx
pthread_t v2; // r12
size_t v3; // rax

v1 = malloc(0x100uLL);
memset(v1, 0, 0x100uLL);
if ( (int)read((int)a1, v1, 0x100uLL) >= 0 )
{
printf("New message received: %s", (const char *)v1);
memset(v1, 0, 0x100uLL);
v2 = pthread_self();
sprintf((char *)v1, "Acknowledgement from TID:0x%x", v2);
v3 = strlen((const char *)v1);
if ( (int)write((int)a1, v1, v3) >= 0 )
{
puts("Requesting mutex lock...");
pthread_mutex_lock(&lock);
printf("Current counter value: %d, upping by 1...\n", (unsigned int)counter);
++counter;
pthread_mutex_unlock(&lock);
printf("Done! Mutex unlocked again, new counter value: %d\n", (unsigned int)counter);
close((int)a1);
printf("TID:0x%x served request, exiting thread\n", v2);
pthread_exit(0LL);
}
perror("Error writing to socket, exiting thread");
pthread_exit(0LL);
}
perror("Error reading form socket, exiting thread");
pthread_exit(0LL);
}

original_code:
void *threadworker(void *arg)
{
  int sockfd, rw;
  char *buffer;
  sockfd = (int) arg;
  buffer = malloc(256);
  bzero(buffer, 256);
  rw = read(sockfd, buffer, 256);
  if (rw < 0)
  {
    perror("Error reading form socket, exiting thread");
    pthread_exit(0);
  }
  printf("New message received: %s", buffer);
  bzero(buffer, 256);
  sprintf(buffer, "Acknowledgement from TID:0x%x", pthread_self());
  rw = write(sockfd, buffer, strlen(buffer));
  if (rw < 0)
  {
    perror("Error writing to socket, exiting thread");
    pthread_exit(0);
  }
  printf("Requesting mutex lock...\n");
  pthread_mutex_lock (&lock);
  printf("Current counter value: %d, upping by 1...\n", counter);
  counter++;
  pthread_mutex_unlock (&lock);
  printf("Done! Mutex unlocked again, new counter value: %d\n", counter);
  close(sockfd);
  printf("TID:0x%x served request, exiting thread\n", pthread_self());
  pthread_exit(0);
}

canonical_original_code:
void *threadworker(void *arg)
{
  int sockfd; int rw;
  char *buffer;
  sockfd = (int) arg;
  buffer = malloc(256);
  bzero(buffer, 256);
  rw = read(sockfd, buffer, 256);
  if (rw < 0)
  {
    perror("Error reading form socket, exiting thread");
    pthread_exit(0);
  }
  printf("New message received: %s", buffer);
  bzero(buffer, 256);
  sprintf(buffer, "Acknowledgement from TID:0x%x", pthread_self());
  rw = write(sockfd, buffer, strlen(buffer));
  if (rw < 0)
  {
    perror("Error writing to socket, exiting thread");
    pthread_exit(0);
  }
  printf("Requesting mutex lock...\n");
  pthread_mutex_lock (&lock);
  printf("Current counter value: %d, upping by 1...\n", counter);
  counter++;
  pthread_mutex_unlock (&lock);
  printf("Done! Mutex unlocked again, new counter value: %d\n", counter);
  close(sockfd);
  printf("TID:0x%x served request, exiting thread\n", pthread_self());
  pthread_exit(0);
}

variable_types:
arg
void *

variable_types: sockfd int

variable_types: rw int

variable_types:
buffer
char *

return_type: void *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
struct addrinfo *v4; // rdi
int v5; // ebp
int v6; // ebx
int v7; // er12
int v8; // eax
pthread_attr_t v9; // [rsp+0h] [rbp-118h] BYREF
struct sockaddr addr; // [rsp+40h] [rbp-D8h] BYREF
socklen_t addr_len; // [rsp+C4h] [rbp-54h] BYREF
struct addrinfo *pai; // [rsp+C8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+D0h] [rbp-48h] BYREF

if ( argc > 1 )
{
v3 = 12LL;
v4 = &req;
while ( v3 )
{
v4->ai_flags = 0;
v4 = (struct addrinfo *)((char *)v4 + 4);
--v3;
}
req.ai_socktype = 1;
req.ai_flags = 1;
if ( getaddrinfo(0LL, argv[1], &req, &pai) >= 0 )
{
v5 = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
if ( v5 >= 0 )
{
if ( bind(v5, pai->ai_addr, pai->ai_addrlen) >= 0 )
{
freeaddrinfo(pai);
pthread_attr_init(&v9);
pthread_attr_setschedpolicy(&v9, 1);
pthread_attr_setdetachstate(&v9, 1);
listen(v5, 5);
addr_len = 128;
v6 = 0;
while ( 1 )
{
v8 = accept(v5, &addr, &addr_len);
if ( v8 < 0 )
break;
v7 = v6 + 1;
pthread_create(&threadid[v6], &v9, (void *(*)(void *))threadworker, (void *)v8);
sleep(0);
v6 = 0;
if ( v7 != 50 )
v6 = v7;
}
perror("Error on accept");
exit(-1);
}
perror("Error on binding");
exit(-1);
}
perror("Error opening socket");
exit(-1);
}
perror("Couldn't read host info for socket start");
exit(-1);
}
fwrite("Error: no port provided\n", 1uLL, 0x18uLL, stderr);
exit(-1);
}

original_code:
int main(int argc, char *argv[])
{
  int serv_sockfd, new_sockfd;
  struct addrinfo flags;
  struct addrinfo *host_info;
  socklen_t addr_size;
  struct sockaddr_storage client;
  pthread_attr_t attr;
  int i;
  if (argc < 2) {
    fprintf(stderr,"Error: no port provided\n");
    exit(-1);
  }
  memset(&flags, 0, sizeof(flags));
  flags.ai_family = 0;
  flags.ai_socktype = SOCK_STREAM;
  flags.ai_flags = 0x0001;
  if (getaddrinfo(((void *)0), argv[1], &flags, &host_info) < 0)
  {
    perror("Couldn't read host info for socket start");
    exit(-1);
  }
  serv_sockfd = socket(host_info->ai_family, host_info->ai_socktype, host_info->ai_protocol);
  if (serv_sockfd < 0)
  {
    perror("Error opening socket");
    exit(-1);
  }
  if (bind(serv_sockfd, host_info->ai_addr, host_info->ai_addrlen) < 0)
  {
    perror("Error on binding");
    exit(-1);
  }
  freeaddrinfo(host_info);
  pthread_attr_init(&attr);
  pthread_attr_setschedpolicy(&attr, 1);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  listen(serv_sockfd, 5);
  addr_size = sizeof(client);
  i = 0;
  while (1)
  {
    if (i == 50)
    {
      i = 0;
    }
    new_sockfd = accept(serv_sockfd, (struct sockaddr *) &client, &addr_size);
    if (new_sockfd < 0)
    {
      perror("Error on accept");
      exit(-1);
    }
    pthread_create(&threadid[i++], &attr, &threadworker, (void *) new_sockfd);
    sleep(0);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int serv_sockfd; int new_sockfd;
  struct addrinfo flags;
  struct addrinfo *host_info;
  unsigned int addr_size;
  struct sockaddr_storage client;
  union pthread_attr_t attr;
  int i;
  if (argc < 2) {
    fprintf(stderr,"Error: no port provided\n");
    exit(-1);
  }
  memset(&flags, 0, sizeof(flags));
  flags.ai_family = 0;
  flags.ai_socktype = SOCK_STREAM;
  flags.ai_flags = 0x0001;
  if (getaddrinfo(((void *)0), argv[1], &flags, &host_info) < 0)
  {
    perror("Couldn't read host info for socket start");
    exit(-1);
  }
  serv_sockfd = socket(host_info->ai_family, host_info->ai_socktype, host_info->ai_protocol);
  if (serv_sockfd < 0)
  {
    perror("Error opening socket");
    exit(-1);
  }
  if (bind(serv_sockfd, host_info->ai_addr, host_info->ai_addrlen) < 0)
  {
    perror("Error on binding");
    exit(-1);
  }
  freeaddrinfo(host_info);
  pthread_attr_init(&attr);
  pthread_attr_setschedpolicy(&attr, 1);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  listen(serv_sockfd, 5);
  addr_size = sizeof(client);
  i = 0;
  while (1)
  {
    if (i == 50)
    {
      i = 0;
    }
    new_sockfd = accept(serv_sockfd, (struct sockaddr *) &client, &addr_size);
    if (new_sockfd < 0)
    {
      perror("Error on accept");
      exit(-1);
    }
    pthread_create(&threadid[i++], &attr, &threadworker, (void *) new_sockfd);
    sleep(0);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types: union pthread_attr_t { char __size[56]; long __align; }

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


repo: ryanashcraft/libprototype

original_code:
int ht_hash(void *key, size_t key_size, size_t max_size) {
 short *ptr = (short *)key;
    int hash = 0;
    size_t i;
    for (i = 0; i < (key_size / 2); i++) {
        hash ^= (i << 4 ^ *ptr << 8 ^ *ptr);
        ptr++;
    }
    hash = hash % max_size;
    return hash;
}

canonical_original_code:
int ht_hash(void *key, unsigned long key_size, unsigned long max_size) {
 short *ptr = (short *)key;
    int hash = 0;
    unsigned long i;
    for (i = 0; i < (key_size / 2); i++) {
        hash ^= (i << 4 ^ *ptr << 8 ^ *ptr);
        ptr++;
    }
    hash = hash % max_size;
    return hash;
}

variable_types:
key
void *

variable_types:
ptr
short *

variable_types: hash int

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall ht_linear_probe_if_needed(__int64 *a1, int a2, const void *a3, size_t a4)
{
__int64 v6; // r14
__int64 v7; // rbx
const void **v8; // rax

v6 = *a1;
LABEL_2:
v7 = a2;
while ( 1 )
{
v8 = *(const void ***)(v6 + 8 * v7);
if ( !v8 || !memcmp(*v8, a3, a4) )
return (unsigned int)v7;
++v7;
a2 = 0;
if ( a1[1] == v7 )
goto LABEL_2;
}
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, int a2, const void *a3, size_t a4)
{
__int64 v6; // r14
__int64 v7; // rbx
const void **v8; // rax

v6 = *a1;
LABEL_2:
v7 = a2;
while ( 1 )
{
v8 = *(const void ***)(v6 + 8 * v7);
if ( !v8 || !memcmp(*v8, a3, a4) )
return (unsigned int)v7;
++v7;
a2 = 0;
if ( a1[1] == v7 )
goto LABEL_2;
}
}

original_code:
int ht_linear_probe_if_needed(hashtable *table, int hash, void *key, size_t key_size) {
 while (table->entries[hash] != ((void *)0) && memcmp(table->entries[hash]->key, key, key_size) != 0) {
  hash += 1;
  if (hash == table->max_size) {
   hash = 0;
  }
 }
 return hash;
}

canonical_original_code:
int ht_linear_probe_if_needed(struct _htable *table, int hash, void *key, unsigned long key_size) {
 while (table->entries[hash] != ((void *)0) && memcmp(table->entries[hash]->key, key, key_size) != 0) {
  hash += 1;
  if (hash == table->max_size) {
   hash = 0;
  }
 }
 return hash;
}

variable_types: struct _htable { struct _htable_entry { void *key; unsigned long key_size; void *value; unsigned long value_size; } **entries; unsigned long max_size; unsigned long entry_count; unsigned long resize_ratio; } *

user_defined_types: struct _htable { struct _htable_entry **entries; unsigned long max_size; unsigned long entry_count; unsigned long resize_ratio; }


decompiled_code:
__int64 __fastcall ht_correct_index_if_needed(__int64 *a1, int a2, const void *a3, size_t a4)
{
__int64 v6; // r13
__int64 v7; // rbx
__int64 v8; // rax
unsigned int v10; // [rsp+Ch] [rbp-3Ch]

v6 = *a1;
LABEL_2:
v7 = a2;
while ( 1 )
{
v10 = v7;
v8 = *(_QWORD *)(v6 + 8 * v7);
if ( !v8 )
return (unsigned int)-1;
if ( *(_QWORD *)(v8 + 8) == a4 && !memcmp(*(const void **)v8, a3, a4) )
return v10;
++v7;
a2 = 0;
if ( a1[1] == v7 )
goto LABEL_2;
}
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, int a2, const void *a3, size_t a4)
{
__int64 v6; // r13
__int64 v7; // rbx
__int64 v8; // rax
unsigned int v10; // [rsp+Ch] [rbp-3Ch]

v6 = *a1;
LABEL_2:
v7 = a2;
while ( 1 )
{
v10 = v7;
v8 = *(_QWORD *)(v6 + 8 * v7);
if ( !v8 )
return (unsigned int)-1;
if ( *(_QWORD *)(v8 + 8) == a4 && !memcmp(*(const void **)v8, a3, a4) )
return v10;
++v7;
a2 = 0;
if ( a1[1] == v7 )
goto LABEL_2;
}
}

original_code:
int ht_correct_index_if_needed(hashtable *table, int index, void *key, size_t key_size) {
 while (1) {
  if (table->entries[index] == ((void *)0)) {
   return -1;
  } else if (table->entries[index]->key_size == key_size && memcmp(table->entries[index]->key, key, key_size) == 0) {
   return index;
  } else {
   index += 1;
   if (index == table->max_size) {
    index = 0;
   }
  }
 }
 return -1;
}

canonical_original_code:
int ht_correct_index_if_needed(struct _htable *table, int index, void *key, unsigned long key_size) {
 while (1) {
  if (table->entries[index] == ((void *)0)) {
   return -1;
  } else if (table->entries[index]->key_size == key_size && memcmp(table->entries[index]->key, key, key_size) == 0) {
   return index;
  } else {
   index += 1;
   if (index == table->max_size) {
    index = 0;
   }
  }
 }
 return -1;
}

variable_types: index int

user_defined_types: struct _htable_entry { void *key; unsigned long key_size; void *value; unsigned long value_size; }


decompiled_code:
void __fastcall ht_destroy(void *ptr)
{
unsigned __int64 v1; // rbx
void **v2; // rbp

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

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
unsigned __int64 v1; // rbx
void **v2; // rbp

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

original_code:
void ht_destroy(hashtable *table) {
 for (int i = 0; i < table->max_size; i++) {
  struct _htable_entry *entry = table->entries[i];
  if (entry != ((void *)0)) {
   free(entry->key);
   free(entry->value);
   free(entry);
  }
 }
 free(table->entries);
 free(table);
}

canonical_original_code:
void ht_destroy(struct _htable *table) {
 for (int i = 0; i < table->max_size; i++) {
  struct _htable_entry *entry = table->entries[i];
  if (entry != ((void *)0)) {
   free(entry->key);
   free(entry->value);
   free(entry);
  }
 }
 free(table->entries);
 free(table);
}

variable_types: i int

variable_types: struct _htable_entry { void *key; unsigned long key_size; void *value; unsigned long value_size; } *