decompiled_code:
__int64 __fastcall setup_dft(__int64 a1)
{
unsigned int v1; // er12
unsigned __int64 v3; // rbx
int v4; // ebp
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // r12

if ( (unsigned int)h5_get_attr(a1, "DFT", "enable_DFT", &flag_dft) )
{
if ( *(double *)&flag_dft != 0.0 )
{
v1 = h5_get_attr(a1, "DFT", "number_of_frequencies", &total_frequencies);
if ( !v1 )
{
notice("dft.c", 40LL, "setup_dft", "fail to get h5 attributes");
return v1;
}
v3 = (unsigned int)((_DWORD)&output_ports + 64);
v4 = 1;
if ( total_output_ports > 0 )
{
while ( 1 )
{
v7 = *(int *)v3;
frequencies = h5_load1(a1, "/DFT/frequencies", total_frequencies, 0.0);
if ( !frequencies )
{
v1 = 0;
notice("dft.c", 47LL, "setup_dft", "fail to load hdf5 dataset");
return v1;
}
v5 = mem2(2LL, total_frequencies, v7);
*(_QWORD *)(v3 + 16) = v5;
if ( !v5 )
{
v1 = 0;
notice("dft.c", 49LL, "setup_dft", "fail to allocate memory");
return v1;
}
v6 = mem2(2LL, total_frequencies, v7);
*(_QWORD *)(v3 + 24) = v6;
if ( !v6 )
break;
++v4;
v3 += 48LL;
if ( total_output_ports < v4 )
return 1;
}
v1 = 0;
notice("dft.c", 51LL, "setup_dft", "fail to allocate memory");
return v1;
}
}
return 1;
}
notice("dft.c", 36LL, "setup_dft", "fail to get h5 attributes");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // er12
unsigned __int64 v3; // rbx
int v4; // ebp
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // r12

if ( (unsigned int)h5_get_attr(a1, "DFT", "enable_DFT", &flag_dft) )
{
if ( *(double *)&flag_dft != 0.0 )
{
v1 = h5_get_attr(a1, "DFT", "number_of_frequencies", &total_frequencies);
if ( !v1 )
{
notice("dft.c", 40LL, "setup_dft", "fail to get h5 attributes");
return v1;
}
v3 = (unsigned int)((_DWORD)&output_ports + 64);
v4 = 1;
if ( total_output_ports > 0 )
{
while ( 1 )
{
v7 = *(int *)v3;
frequencies = h5_load1(a1, "/DFT/frequencies", total_frequencies, 0.0);
if ( !frequencies )
{
v1 = 0;
notice("dft.c", 47LL, "setup_dft", "fail to load hdf5 dataset");
return v1;
}
v5 = mem2(2LL, total_frequencies, v7);
*(_QWORD *)(v3 + 16) = v5;
if ( !v5 )
{
v1 = 0;
notice("dft.c", 49LL, "setup_dft", "fail to allocate memory");
return v1;
}
v6 = mem2(2LL, total_frequencies, v7);
*(_QWORD *)(v3 + 24) = v6;
if ( !v6 )
break;
++v4;
v3 += 48LL;
if ( total_output_ports < v4 )
return 1;
}
v1 = 0;
notice("dft.c", 51LL, "setup_dft", "fail to allocate memory");
return v1;
}
}
return 1;
}
notice("dft.c", 36LL, "setup_dft", "fail to get h5 attributes");
return 0LL;
}

original_code:
int setup_dft(char* file_name)
{
    int port_index;
    int total_points;
    int status;
    status = h5_get_attr(file_name, "DFT", "enable_DFT", &flag_dft);
    if (!(status)) {notice("dft.c",36,__func__,"fail to get h5 attributes"); return(0);};
    if (flag_dft == 0) return 1;
    status = h5_get_attr(file_name, "DFT", "number_of_frequencies", &total_frequencies);
    if (!(status)) {notice("dft.c",40,__func__,"fail to get h5 attributes"); return(0);};
    for (port_index = 1; port_index <= total_output_ports; port_index++)
    {
        total_points = output_ports[port_index].total_points;
        frequencies = (double *)h5_load1(file_name, "/DFT/frequencies", total_frequencies);
        if (!(frequencies)) {notice("dft.c",47,__func__,"fail to load hdf5 dataset"); return(0);};
        output_ports[port_index].dft_real = (double **)mem2(type_double, total_frequencies, total_points);
        if (!(output_ports[port_index].dft_real)) {notice("dft.c",49,__func__,"fail to allocate memory"); return(0);};
        output_ports[port_index].dft_imag = (double **)mem2(type_double, total_frequencies, total_points);
        if (!(output_ports[port_index].dft_imag)) {notice("dft.c",51,__func__,"fail to allocate memory"); return(0);};
    }
    return 1;
}

canonical_original_code:
int setup_dft(char *file_name)
{
    int port_index;
    int total_points;
    int status;
    status = h5_get_attr(file_name, "DFT", "enable_DFT", &flag_dft);
    if (!(status)) {notice("dft.c",36,__func__,"fail to get h5 attributes"); return(0);};
    if (flag_dft == 0) return 1;
    status = h5_get_attr(file_name, "DFT", "number_of_frequencies", &total_frequencies);
    if (!(status)) {notice("dft.c",40,__func__,"fail to get h5 attributes"); return(0);};
    for (port_index = 1; port_index <= total_output_ports; port_index++)
    {
        total_points = output_ports[port_index].total_points;
        frequencies = (double *)h5_load1(file_name, "/DFT/frequencies", total_frequencies);
        if (!(frequencies)) {notice("dft.c",47,__func__,"fail to load hdf5 dataset"); return(0);};
        output_ports[port_index].dft_real = (double **)mem2(type_double, total_frequencies, total_points);
        if (!(output_ports[port_index].dft_real)) {notice("dft.c",49,__func__,"fail to allocate memory"); return(0);};
        output_ports[port_index].dft_imag = (double **)mem2(type_double, total_frequencies, total_points);
        if (!(output_ports[port_index].dft_imag)) {notice("dft.c",51,__func__,"fail to allocate memory"); return(0);};
    }
    return 1;
}

variable_types: status int


repo: emguy/ezfdtd

original_code:
int update_dft(int time_index)
{
    int port_index;
    int probe_index;
    int total_points;
    int frequency_index;
    double value;
    if (flag_dft == 0) return 1;
    for (port_index = 1; port_index <= total_output_ports; port_index++)
    {
        total_points = output_ports[port_index].total_points;
        for (probe_index = 0; probe_index < total_points; probe_index++)
        {
            value = output_ports[port_index].fields[time_index][probe_index];
            for (frequency_index = 0; frequency_index < total_frequencies; frequency_index ++)
            {
                output_ports[port_index].dft_real[frequency_index][probe_index]
                    = output_ports[port_index].dft_real[frequency_index][probe_index]
                    + value * cos(2.0 * 3.1415926535897932384626434 * frequencies[frequency_index] * time_index * d_t);
                output_ports[port_index].dft_imag[frequency_index][probe_index]
                    = output_ports[port_index].dft_imag[frequency_index][probe_index]
                    - value * sin(2.0 * 3.1415926535897932384626434 * frequencies[frequency_index] * time_index * d_t);
            }
        }
    }
    return 1;
}

variable_types: value double

return_type: int


decompiled_code:
__int64 __fastcall write_dft(__int64 a1)
{
unsigned __int64 v1; // rbx
unsigned int v2; // ebp
char v4[72]; // [rsp-40h] [rbp-48h] BYREF

if ( *(double *)&flag_dft == 0.0 || total_output_ports <= 0 )
return 1LL;
v1 = (unsigned int)((_DWORD)&output_ports + 64);
v2 = 1;
while ( 1 )
{
sprintf(v4, "port_%02d_spectrum_real", v2);
if ( !(unsigned int)h5_write2(a1, v4, 2LL, *(_QWORD *)(v1 + 16), total_frequencies, *(int *)v1) )
{
notice("dft.c", 96LL, "write_dft", "fail to write h5 dset");
return 0LL;
}
sprintf(v4, "port_%02d_spectrum_imag", v2);
if ( !(unsigned int)h5_write2(a1, v4, 2LL, *(_QWORD *)(v1 + 24), total_frequencies, *(int *)v1) )
break;
++v2;
v1 += 48LL;
if ( total_output_ports < (int)v2 )
return 1LL;
}
notice("dft.c", 99LL, "write_dft", "fail to write h5 dset");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned __int64 v1; // rbx
unsigned int v2; // ebp
char v4[72]; // [rsp-40h] [rbp-48h] BYREF

if ( *(double *)&flag_dft == 0.0 || total_output_ports <= 0 )
return 1LL;
v1 = (unsigned int)((_DWORD)&output_ports + 64);
v2 = 1;
while ( 1 )
{
sprintf(v4, "port_%02d_spectrum_real", v2);
if ( !(unsigned int)h5_write2(a1, v4, 2LL, *(_QWORD *)(v1 + 16), total_frequencies, *(int *)v1) )
{
notice("dft.c", 96LL, "write_dft", "fail to write h5 dset");
return 0LL;
}
sprintf(v4, "port_%02d_spectrum_imag", v2);
if ( !(unsigned int)h5_write2(a1, v4, 2LL, *(_QWORD *)(v1 + 24), total_frequencies, *(int *)v1) )
break;
++v2;
v1 += 48LL;
if ( total_output_ports < (int)v2 )
return 1LL;
}
notice("dft.c", 99LL, "write_dft", "fail to write h5 dset");
return 0LL;
}

original_code:
int write_dft(char* file_name)
{
    int port_index;
    char attr_name[30];
    int status;
    if (flag_dft == 0) return 1;
    for (port_index = 1; port_index <= total_output_ports; port_index++)
    {
        sprintf(attr_name, "port_%02d_spectrum_real", port_index);
        status = h5_write2(file_name, attr_name, type_double, (void **)output_ports[port_index].dft_real, total_frequencies, output_ports[port_index].total_points);
        if (!(status)) {notice("dft.c",96,__func__,"fail to write h5 dset"); return(0);};
        sprintf(attr_name, "port_%02d_spectrum_imag", port_index);
        status = h5_write2(file_name, attr_name, type_double, (void **)output_ports[port_index].dft_imag, total_frequencies, output_ports[port_index].total_points);
        if (!(status)) {notice("dft.c",99,__func__,"fail to write h5 dset"); return(0);};
    }
    return 1;
}

canonical_original_code:
int write_dft(char *file_name)
{
    int port_index;
    char attr_name[30];
    int status;
    if (flag_dft == 0) return 1;
    for (port_index = 1; port_index <= total_output_ports; port_index++)
    {
        sprintf(attr_name, "port_%02d_spectrum_real", port_index);
        status = h5_write2(file_name, attr_name, type_double, (void **)output_ports[port_index].dft_real, total_frequencies, output_ports[port_index].total_points);
        if (!(status)) {notice("dft.c",96,__func__,"fail to write h5 dset"); return(0);};
        sprintf(attr_name, "port_%02d_spectrum_imag", port_index);
        status = h5_write2(file_name, attr_name, type_double, (void **)output_ports[port_index].dft_imag, total_frequencies, output_ports[port_index].total_points);
        if (!(status)) {notice("dft.c",99,__func__,"fail to write h5 dset"); return(0);};
    }
    return 1;
}


compute

decompiled_code:
__int64 __fastcall compute(unsigned int a1)
{
get_h();
apply_hhards(a1);
get_e();
update_mur();
apply_ehards(a1);
return apply_pmc();
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
get_h();
apply_hhards(a1);
get_e();
update_mur();
apply_ehards(a1);
return apply_pmc();
}

original_code:
static void compute (int time_index)
{
    get_h();
    apply_hhards(time_index);
    get_e();
    update_mur();
    apply_ehards(time_index);
    apply_pmc();
}

canonical_original_code:
static void compute(int time_index)
{
    get_h();
    apply_hhards(time_index);
    get_e();
    update_mur();
    apply_ehards(time_index);
    apply_pmc();
}

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
const char *v4; // r12
const char *v5; // rcx
__int64 v6; // rsi
unsigned int i; // er12
__int64 v8; // rsi
int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc <= 1 )
{
v5 = "less than two arguments; exit !";
v6 = 99LL;
}
else
{
v3 = argv[2];
v4 = argv[1];
if ( !(unsigned int)h5_set_file(v3, argv, envp) )
{
notice("ezfdtd.c", 104LL, "main", "fail to create h5 output files");
exit(1);
}
if ( !(unsigned int)h5_get_attr(v4, "settings", "number_of_timesteps", &total_timesteps) )
{
notice("ezfdtd.c", 107LL, "main", "fail to get h5 attributes");
exit(1);
}
if ( (unsigned int)h5_get_attr(v4, "settings", "verbosity", v9) && v9[0] >= 0 )
{
if ( !(unsigned int)h5_get_attr(v4, "boundaries", "pml_type", &pml_type) )
{
notice("ezfdtd.c", 111LL, "main", "fail to get h5 attributes");
exit(1);
}
if ( !(unsigned int)setup_domain(v4) )
{
notice("ezfdtd.c", 114LL, "main", "fail to setup domain");
exit(1);
}
if ( !(unsigned int)setup_fields(v4) )
{
notice("ezfdtd.c", 118LL, "main", "fail to setup fields");
exit(1);
}
if ( !(unsigned int)setup_mur() )
{
notice("ezfdtd.c", 121LL, "main", "fail to setup abc_mur");
exit(1);
}
if ( (unsigned int)setup_classical(v4) )
{
if ( v9[0] > 0 )
puts("setup classical ... DONE");
if ( classical == 1 || (unsigned int)setup_ade(v4) )
{
if ( pml_type )
{
if ( !(unsigned int)setup_cpml(v4) )
{
notice("ezfdtd.c", 136LL, "main", "fail to setup cpml");
exit(1);
}
if ( v9[0] > 0 )
puts("setup cpml ... DONE");
}
else
{
if ( !(unsigned int)setup_pml(v4) )
{
notice("ezfdtd.c", 143LL, "main", "fail to setup pml");
exit(1);
}
if ( v9[0] > 0 )
puts("setup pml ... DONE");
}
if ( (unsigned int)setup_input_ports(v4) )
{
if ( v9[0] > 0 )
puts("setup excitation ... DONE");
if ( (unsigned int)setup_point_sources(v4) )
{
if ( v9[0] > 0 )
puts("setup point sources ... DONE");
if ( (unsigned int)setup_hards(v4) )
{
if ( v9[0] > 0 )
puts("setup hard sources ... DONE ");
if ( (unsigned int)setup_output_ports(v4) )
{
if ( v9[0] > 0 )
puts("setup probes ... DONE");
if ( (unsigned int)setup_planes(v4, v3) )
{
if ( v9[0] > 0 )
puts("setup animations ... DONE");
if ( (unsigned int)setup_dft(v4) )
{
if ( v9[0] > 0 )
puts("setup DFT ... DONE");
for ( i = 0; total_timesteps > i; ++i )
{
if ( v9[0] > 0 && !((int)i % v9[0]) )
printf("Time Index %06d:\n", i);
excite(i);
compute(i);
update_ports(i);
update_dft(i);
v8 = i;
update_planes(v3, v8);
}
write_ports(v3);
write_dft(v3);
exit(0);
}
notice("ezfdtd.c", 169LL, "main", "fail to setup dft");
exit(1);
}
notice("ezfdtd.c", 165LL, "main", "fail to setup planes");
exit(1);
}
notice("ezfdtd.c", 160LL, "main", "fail to setup output ports");
exit(1);
}
notice("ezfdtd.c", 156LL, "main", "fail to setup hards");
exit(1);
}
notice("ezfdtd.c", 152LL, "main", "fail to setup point sources");
exit(1);
}
notice("ezfdtd.c", 148LL, "main", "fail to setup input ports");
exit(1);
}
notice("ezfdtd.c", 130LL, "main", "fail to setup ade");
exit(1);
}
notice("ezfdtd.c", 124LL, "main", "fail to setup classical mode");
exit(1);
}
v5 = "fail to get h5 attributes";
v6 = 109LL;
}
notice("ezfdtd.c", v6, "main", v5);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
const char *v4; // r12
const char *v5; // rcx
__int64 v6; // rsi
unsigned int i; // er12
__int64 v8; // rsi
int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc <= 1 )
{
v5 = "less than two arguments; exit !";
v6 = 99LL;
}
else
{
v3 = argv[2];
v4 = argv[1];
if ( !(unsigned int)h5_set_file(v3, argv, envp) )
{
notice("ezfdtd.c", 104LL, "main", "fail to create h5 output files");
exit(1);
}
if ( !(unsigned int)h5_get_attr(v4, "settings", "number_of_timesteps", &total_timesteps) )
{
notice("ezfdtd.c", 107LL, "main", "fail to get h5 attributes");
exit(1);
}
if ( (unsigned int)h5_get_attr(v4, "settings", "verbosity", v9) && v9[0] >= 0 )
{
if ( !(unsigned int)h5_get_attr(v4, "boundaries", "pml_type", &pml_type) )
{
notice("ezfdtd.c", 111LL, "main", "fail to get h5 attributes");
exit(1);
}
if ( !(unsigned int)setup_domain(v4) )
{
notice("ezfdtd.c", 114LL, "main", "fail to setup domain");
exit(1);
}
if ( !(unsigned int)setup_fields(v4) )
{
notice("ezfdtd.c", 118LL, "main", "fail to setup fields");
exit(1);
}
if ( !(unsigned int)setup_mur() )
{
notice("ezfdtd.c", 121LL, "main", "fail to setup abc_mur");
exit(1);
}
if ( (unsigned int)setup_classical(v4) )
{
if ( v9[0] > 0 )
puts("setup classical ... DONE");
if ( classical == 1 || (unsigned int)setup_ade(v4) )
{
if ( pml_type )
{
if ( !(unsigned int)setup_cpml(v4) )
{
notice("ezfdtd.c", 136LL, "main", "fail to setup cpml");
exit(1);
}
if ( v9[0] > 0 )
puts("setup cpml ... DONE");
}
else
{
if ( !(unsigned int)setup_pml(v4) )
{
notice("ezfdtd.c", 143LL, "main", "fail to setup pml");
exit(1);
}
if ( v9[0] > 0 )
puts("setup pml ... DONE");
}
if ( (unsigned int)setup_input_ports(v4) )
{
if ( v9[0] > 0 )
puts("setup excitation ... DONE");
if ( (unsigned int)setup_point_sources(v4) )
{
if ( v9[0] > 0 )
puts("setup point sources ... DONE");
if ( (unsigned int)setup_hards(v4) )
{
if ( v9[0] > 0 )
puts("setup hard sources ... DONE ");
if ( (unsigned int)setup_output_ports(v4) )
{
if ( v9[0] > 0 )
puts("setup probes ... DONE");
if ( (unsigned int)setup_planes(v4, v3) )
{
if ( v9[0] > 0 )
puts("setup animations ... DONE");
if ( (unsigned int)setup_dft(v4) )
{
if ( v9[0] > 0 )
puts("setup DFT ... DONE");
for ( i = 0; total_timesteps > i; ++i )
{
if ( v9[0] > 0 && !((int)i % v9[0]) )
printf("Time Index %06d:\n", i);
excite(i);
func0(i);
update_ports(i);
update_dft(i);
v8 = i;
update_planes(v3, v8);
}
write_ports(v3);
write_dft(v3);
exit(0);
}
notice("ezfdtd.c", 169LL, "main", "fail to setup dft");
exit(1);
}
notice("ezfdtd.c", 165LL, "main", "fail to setup planes");
exit(1);
}
notice("ezfdtd.c", 160LL, "main", "fail to setup output ports");
exit(1);
}
notice("ezfdtd.c", 156LL, "main", "fail to setup hards");
exit(1);
}
notice("ezfdtd.c", 152LL, "main", "fail to setup point sources");
exit(1);
}
notice("ezfdtd.c", 148LL, "main", "fail to setup input ports");
exit(1);
}
notice("ezfdtd.c", 130LL, "main", "fail to setup ade");
exit(1);
}
notice("ezfdtd.c", 124LL, "main", "fail to setup classical mode");
exit(1);
}
v5 = "fail to get h5 attributes";
v6 = 109LL;
}
notice("ezfdtd.c", v6, "main", v5);
exit(1);
}

original_code:
int main (int argc, char** argv)
{
    char *input_file_name;
    char *output_file_name;
    int time_index;
    int status;
    int verbosity;
    if (!(argc > 1)) {notice("ezfdtd.c",99,__func__,"less than two arguments; exit !"); exit(1);};
    input_file_name = argv[1];
    output_file_name = argv[2];
    status = h5_set_file(output_file_name);
    if (!(status)) {notice("ezfdtd.c",104,__func__,"fail to create h5 output files"); exit(1);};
    status = h5_get_attr(input_file_name, "settings", "number_of_timesteps", &total_timesteps);
    if (!(status)) {notice("ezfdtd.c",107,__func__,"fail to get h5 attributes"); exit(1);};
    status = h5_get_attr(input_file_name, "settings", "verbosity", &verbosity);
    if (!(status && verbosity >= 0)) {notice("ezfdtd.c",109,__func__,"fail to get h5 attributes"); exit(1);};
    status = h5_get_attr(input_file_name, "boundaries", "pml_type", &pml_type);
    if (!(status)) {notice("ezfdtd.c",111,__func__,"fail to get h5 attributes"); exit(1);};
    status = setup_domain(input_file_name);
    if (!(status)) {notice("ezfdtd.c",114,__func__,"fail to setup domain"); exit(1);};
    status = setup_fields(input_file_name);
    if (!(status)) {notice("ezfdtd.c",118,__func__,"fail to setup fields"); exit(1);};
    status = setup_mur();
    if (!(status)) {notice("ezfdtd.c",121,__func__,"fail to setup abc_mur"); exit(1);};
    status = setup_classical(input_file_name);
    if (!(status)) {notice("ezfdtd.c",124,__func__,"fail to setup classical mode"); exit(1);};
    if (verbosity > 0) printf("setup classical ... DONE\n");
    if (classical != 1)
    {
        status = setup_ade(input_file_name);
        if (!(status)) {notice("ezfdtd.c",130,__func__,"fail to setup ade"); exit(1);};
    }
    if (pml_type != 0)
    {
        status = setup_cpml(input_file_name);
        if (!(status)) {notice("ezfdtd.c",136,__func__,"fail to setup cpml"); exit(1);};
        if (verbosity > 0) printf("setup cpml ... DONE\n");
    }
    else
    {
        status = setup_pml(input_file_name);
        if (!(status)) {notice("ezfdtd.c",143,__func__,"fail to setup pml"); exit(1);};
        if (verbosity > 0) printf("setup pml ... DONE\n");
    }
    status = setup_input_ports(input_file_name);
    if (!(status)) {notice("ezfdtd.c",148,__func__,"fail to setup input ports"); exit(1);};
    if (verbosity > 0) printf("setup excitation ... DONE\n");
    status = setup_point_sources(input_file_name);
    if (!(status)) {notice("ezfdtd.c",152,__func__,"fail to setup point sources"); exit(1);};
    if (verbosity > 0) printf("setup point sources ... DONE\n");
    status = setup_hards(input_file_name);
    if (!(status)) {notice("ezfdtd.c",156,__func__,"fail to setup hards"); exit(1);};
    if (verbosity > 0) printf("setup hard sources ... DONE \n");
    status = setup_output_ports(input_file_name);
    if (!(status)) {notice("ezfdtd.c",160,__func__,"fail to setup output ports"); exit(1);};
    if (verbosity > 0) printf("setup probes ... DONE\n");
    status = setup_planes(input_file_name, output_file_name);
    if (!(status)) {notice("ezfdtd.c",165,__func__,"fail to setup planes"); exit(1);};
    if (verbosity > 0) printf("setup animations ... DONE\n");
    status = setup_dft(input_file_name);
    if (!(status)) {notice("ezfdtd.c",169,__func__,"fail to setup dft"); exit(1);};
    if (verbosity > 0) printf("setup DFT ... DONE\n");
    for (time_index = 0; time_index < total_timesteps; time_index++)
    {
        if (verbosity > 0 && time_index%verbosity == 0) printf("Time Index %06d:\n", time_index);
        excite(time_index);
        compute(time_index);
        update_ports(time_index);
        update_dft(time_index);
        update_planes(output_file_name, time_index);
    }
    write_ports(output_file_name);
    write_dft(output_file_name);
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    char *input_file_name;
    char *output_file_name;
    int time_index;
    int status;
    int verbosity;
    if (!(argc > 1)) {notice("ezfdtd.c",99,__func__,"less than two arguments; exit !"); exit(1);};
    input_file_name = argv[1];
    output_file_name = argv[2];
    status = h5_set_file(output_file_name);
    if (!(status)) {notice("ezfdtd.c",104,__func__,"fail to create h5 output files"); exit(1);};
    status = h5_get_attr(input_file_name, "settings", "number_of_timesteps", &total_timesteps);
    if (!(status)) {notice("ezfdtd.c",107,__func__,"fail to get h5 attributes"); exit(1);};
    status = h5_get_attr(input_file_name, "settings", "verbosity", &verbosity);
    if (!(status && verbosity >= 0)) {notice("ezfdtd.c",109,__func__,"fail to get h5 attributes"); exit(1);};
    status = h5_get_attr(input_file_name, "boundaries", "pml_type", &pml_type);
    if (!(status)) {notice("ezfdtd.c",111,__func__,"fail to get h5 attributes"); exit(1);};
    status = setup_domain(input_file_name);
    if (!(status)) {notice("ezfdtd.c",114,__func__,"fail to setup domain"); exit(1);};
    status = setup_fields(input_file_name);
    if (!(status)) {notice("ezfdtd.c",118,__func__,"fail to setup fields"); exit(1);};
    status = setup_mur();
    if (!(status)) {notice("ezfdtd.c",121,__func__,"fail to setup abc_mur"); exit(1);};
    status = setup_classical(input_file_name);
    if (!(status)) {notice("ezfdtd.c",124,__func__,"fail to setup classical mode"); exit(1);};
    if (verbosity > 0) printf("setup classical ... DONE\n");
    if (classical != 1)
    {
        status = setup_ade(input_file_name);
        if (!(status)) {notice("ezfdtd.c",130,__func__,"fail to setup ade"); exit(1);};
    }
    if (pml_type != 0)
    {
        status = setup_cpml(input_file_name);
        if (!(status)) {notice("ezfdtd.c",136,__func__,"fail to setup cpml"); exit(1);};
        if (verbosity > 0) printf("setup cpml ... DONE\n");
    }
    else
    {
        status = setup_pml(input_file_name);
        if (!(status)) {notice("ezfdtd.c",143,__func__,"fail to setup pml"); exit(1);};
        if (verbosity > 0) printf("setup pml ... DONE\n");
    }
    status = setup_input_ports(input_file_name);
    if (!(status)) {notice("ezfdtd.c",148,__func__,"fail to setup input ports"); exit(1);};
    if (verbosity > 0) printf("setup excitation ... DONE\n");
    status = setup_point_sources(input_file_name);
    if (!(status)) {notice("ezfdtd.c",152,__func__,"fail to setup point sources"); exit(1);};
    if (verbosity > 0) printf("setup point sources ... DONE\n");
    status = setup_hards(input_file_name);
    if (!(status)) {notice("ezfdtd.c",156,__func__,"fail to setup hards"); exit(1);};
    if (verbosity > 0) printf("setup hard sources ... DONE \n");
    status = setup_output_ports(input_file_name);
    if (!(status)) {notice("ezfdtd.c",160,__func__,"fail to setup output ports"); exit(1);};
    if (verbosity > 0) printf("setup probes ... DONE\n");
    status = setup_planes(input_file_name, output_file_name);
    if (!(status)) {notice("ezfdtd.c",165,__func__,"fail to setup planes"); exit(1);};
    if (verbosity > 0) printf("setup animations ... DONE\n");
    status = setup_dft(input_file_name);
    if (!(status)) {notice("ezfdtd.c",169,__func__,"fail to setup dft"); exit(1);};
    if (verbosity > 0) printf("setup DFT ... DONE\n");
    for (time_index = 0; time_index < total_timesteps; time_index++)
    {
        if (verbosity > 0 && time_index%verbosity == 0) printf("Time Index %06d:\n", time_index);
        excite(time_index);
        compute(time_index);
        update_ports(time_index);
        update_dft(time_index);
        update_planes(output_file_name, time_index);
    }
    write_ports(output_file_name);
    write_dft(output_file_name);
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: verbosity int


decompiled_code:
__int64 __fastcall setup_classical(__int64 a1)
{
unsigned int v1; // er12
__int64 v3; // rbp
int v4; // eax
unsigned int v5; // er14
__int64 v6; // r13
__int64 v7; // rbx
__int64 v8; // r10
__int64 v9; // r9
__int64 v10; // r8
__int64 v11; // rcx
int v12; // eax
__int64 v13; // r15
int v14; // er12
char v15; // dl
__int64 v16; // rdx
__int64 i; // rax
double *v18; // rdi
double v19; // xmm0_8
double v20; // xmm1_8
int v21; // esi
__int64 v22; // [rsp+8h] [rbp-50h]
int v23; // [rsp+14h] [rbp-44h]
unsigned int v24; // [rsp+18h] [rbp-40h]
unsigned int v25; // [rsp+1Ch] [rbp-3Ch]

if ( (unsigned int)h5_get_attr(a1, "materials", "classical_mode", &classical) )
{
v1 = classical;
if ( classical == 1 )
{
v3 = h5_load3(a1, "/materials/sigma", total_x, total_y, total_z);
if ( v3 )
{
ca = mem3(2LL, total_x, total_y, total_z);
v4 = mode;
if ( mode != 4 && mode != 1 )
{
cb_x = mem3(2LL, total_x, total_y, total_z);
if ( !cb_x )
{
v1 = 0;
notice("classical.c", 47LL, "setup_classical", "fail to allocate memory for cb_x");
return v1;
}
v4 = mode;
}
if ( v4 != 5 && v4 != 2 )
{
cb_y = mem3(2LL, total_x, total_y, total_z);
if ( !cb_y )
{
v1 = 0;
notice("classical.c", 52LL, "setup_classical", "fail to allocate memory for cb_y");
return v1;
}
v4 = mode;
}
if ( v4 == 6 || v4 == 3 || (cb_z = mem3(2LL, total_x, total_y, total_z)) != 0 )
{
z = 0;
v5 = total_x;
v23 = total_z;
v24 = total_y;
if ( total_z )
{
v6 = epsilon;
v7 = ca;
v8 = cb_x;
v9 = cb_y;
v10 = cb_z;
v22 = 8LL * total_z;
v11 = 0LL;
v12 = x;
v25 = v1;
v13 = 8LL * (unsigned int)(total_y - 1) + 8;
v14 = total_y;
v15 = 0;
do
{
if ( v14 )
{
v16 = 0LL;
do
{
if ( v5 )
{
for ( i = 0LL; i != v5; ++i )
{
v18 = (double *)(v11 + *(_QWORD *)(*(_QWORD *)(v6 + 8 * i) + v16));
v19 = *(double *)(*(_QWORD *)(*(_QWORD *)(v3 + 8 * i) + v16) + v11) * d_t / (*v18 + *v18);
v20 = v19 + 1.0;
*(double *)(*(_QWORD *)(*(_QWORD *)(v7 + 8 * i) + v16) + v11) = (1.0 - v19) / (v19 + 1.0);
if ( v8 )
*(double *)(*(_QWORD *)(*(_QWORD *)(v8 + 8 * i) + v16) + v11) = d_tx / *v18 / v20;
if ( v9 )
*(double *)(*(_QWORD *)(*(_QWORD *)(v9 + 8 * i) + v16) + v11) = d_ty / *v18 / v20;
if ( v10 )
*(double *)(*(_QWORD *)(*(_QWORD *)(v10 + 8 * i) + v16) + v11) = d_tz / *v18 / v20;
}
}
v16 += 8LL;
}
while ( v13 != v16 );
v12 = v5;
v21 = v14;
v15 = 1;
}
else
{
v21 = 0;
}
v11 += 8LL;
}
while ( v22 != v11 );
y = v21;
v1 = v25;
if ( v15 )
x = v12;
z = v23;
}
free_mem3(v3, v5, v24);
}
else
{
v1 = 0;
notice("classical.c", 57LL, "setup_classical", "fail to allocate memory for cb_z");
}
}
else
{
v1 = 0;
notice("classical.c", 41LL, "setup_classical", "fail to load hdf5 dataset");
}
}
else
{
v1 = 1;
}
}
else
{
v1 = 0;
notice("classical.c", 37LL, "setup_classical", "fail to get h5 attributes");
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // er12
__int64 v3; // rbp
int v4; // eax
unsigned int v5; // er14
__int64 v6; // r13
__int64 v7; // rbx
__int64 v8; // r10
__int64 v9; // r9
__int64 v10; // r8
__int64 v11; // rcx
int v12; // eax
__int64 v13; // r15
int v14; // er12
char v15; // dl
__int64 v16; // rdx
__int64 i; // rax
double *v18; // rdi
double v19; // xmm0_8
double v20; // xmm1_8
int v21; // esi
__int64 v22; // [rsp+8h] [rbp-50h]
int v23; // [rsp+14h] [rbp-44h]
unsigned int v24; // [rsp+18h] [rbp-40h]
unsigned int v25; // [rsp+1Ch] [rbp-3Ch]

if ( (unsigned int)h5_get_attr(a1, "materials", "classical_mode", &classical) )
{
v1 = classical;
if ( classical == 1 )
{
v3 = h5_load3(a1, "/materials/sigma", total_x, total_y, total_z);
if ( v3 )
{
ca = mem3(2LL, total_x, total_y, total_z);
v4 = mode;
if ( mode != 4 && mode != 1 )
{
cb_x = mem3(2LL, total_x, total_y, total_z);
if ( !cb_x )
{
v1 = 0;
notice("classical.c", 47LL, "setup_classical", "fail to allocate memory for cb_x");
return v1;
}
v4 = mode;
}
if ( v4 != 5 && v4 != 2 )
{
cb_y = mem3(2LL, total_x, total_y, total_z);
if ( !cb_y )
{
v1 = 0;
notice("classical.c", 52LL, "setup_classical", "fail to allocate memory for cb_y");
return v1;
}
v4 = mode;
}
if ( v4 == 6 || v4 == 3 || (cb_z = mem3(2LL, total_x, total_y, total_z)) != 0 )
{
z = 0;
v5 = total_x;
v23 = total_z;
v24 = total_y;
if ( total_z )
{
v6 = epsilon;
v7 = ca;
v8 = cb_x;
v9 = cb_y;
v10 = cb_z;
v22 = 8LL * total_z;
v11 = 0LL;
v12 = x;
v25 = v1;
v13 = 8LL * (unsigned int)(total_y - 1) + 8;
v14 = total_y;
v15 = 0;
do
{
if ( v14 )
{
v16 = 0LL;
do
{
if ( v5 )
{
for ( i = 0LL; i != v5; ++i )
{
v18 = (double *)(v11 + *(_QWORD *)(*(_QWORD *)(v6 + 8 * i) + v16));
v19 = *(double *)(*(_QWORD *)(*(_QWORD *)(v3 + 8 * i) + v16) + v11) * d_t / (*v18 + *v18);
v20 = v19 + 1.0;
*(double *)(*(_QWORD *)(*(_QWORD *)(v7 + 8 * i) + v16) + v11) = (1.0 - v19) / (v19 + 1.0);
if ( v8 )
*(double *)(*(_QWORD *)(*(_QWORD *)(v8 + 8 * i) + v16) + v11) = d_tx / *v18 / v20;
if ( v9 )
*(double *)(*(_QWORD *)(*(_QWORD *)(v9 + 8 * i) + v16) + v11) = d_ty / *v18 / v20;
if ( v10 )
*(double *)(*(_QWORD *)(*(_QWORD *)(v10 + 8 * i) + v16) + v11) = d_tz / *v18 / v20;
}
}
v16 += 8LL;
}
while ( v13 != v16 );
v12 = v5;
v21 = v14;
v15 = 1;
}
else
{
v21 = 0;
}
v11 += 8LL;
}
while ( v22 != v11 );
y = v21;
v1 = v25;
if ( v15 )
x = v12;
z = v23;
}
free_mem3(v3, v5, v24);
}
else
{
v1 = 0;
notice("classical.c", 57LL, "setup_classical", "fail to allocate memory for cb_z");
}
}
else
{
v1 = 0;
notice("classical.c", 41LL, "setup_classical", "fail to load hdf5 dataset");
}
}
else
{
v1 = 1;
}
}
else
{
v1 = 0;
notice("classical.c", 37LL, "setup_classical", "fail to get h5 attributes");
}
return v1;
}

original_code:
int setup_classical (char *file_name)
{
    double tmp;
    double*** sigma;
    int status;
    status = h5_get_attr(file_name, "materials", "classical_mode", &classical);
    if (!(status)) {notice("classical.c",37,__func__,"fail to get h5 attributes"); return(0);};
    if (classical != 1) return 1;
    sigma = (double ***)h5_load3(file_name, "/materials/sigma", total_x, total_y, total_z);
    if (!(sigma)) {notice("classical.c",41,__func__,"fail to load hdf5 dataset"); return(0);};
    ca = (double ***)mem3(type_double, total_x, total_y, total_z);
    if (mode != mode_tex && mode != mode_tmx)
    {
        cb_x = (double ***)mem3(type_double, total_x, total_y, total_z);
        if (!(cb_x)) {notice("classical.c",47,__func__,"fail to allocate memory for cb_x"); return(0);};
    }
    if (mode != mode_tey && mode != mode_tmy)
    {
        cb_y = (double ***)mem3(type_double, total_x, total_y, total_z);
        if (!(cb_y)) {notice("classical.c",52,__func__,"fail to allocate memory for cb_y"); return(0);};
    }
    if (mode != mode_tez && mode != mode_tmz)
    {
        cb_z = (double ***)mem3(type_double, total_x, total_y, total_z);
        if (!(cb_z)) {notice("classical.c",57,__func__,"fail to allocate memory for cb_z"); return(0);};
    }
    for (z = 0; z < total_z; z++)
        for (y = 0; y < total_y; y++)
            for (x = 0; x < total_x; x++)
            {
                tmp = sigma[x][y][z] * d_t / (2 * epsilon[x][y][z]);
                ca[x][y][z] = (1 - tmp) / (1 + tmp);
                if (cb_x)
                    cb_x[x][y][z] = d_tx / epsilon[x][y][z] / (1 + tmp);
                if (cb_y)
                    cb_y[x][y][z] = d_ty / epsilon[x][y][z] / (1 + tmp);
                if (cb_z)
                    cb_z[x][y][z] = d_tz / epsilon[x][y][z] / (1 + tmp);
            }
    free_mem3((void ***)sigma, total_x, total_y);
    return 1;
}

canonical_original_code:
int setup_classical(char *file_name)
{
    double tmp;
    double ***sigma;
    int status;
    status = h5_get_attr(file_name, "materials", "classical_mode", &classical);
    if (!(status)) {notice("classical.c",37,__func__,"fail to get h5 attributes"); return(0);};
    if (classical != 1) return 1;
    sigma = (double ***)h5_load3(file_name, "/materials/sigma", total_x, total_y, total_z);
    if (!(sigma)) {notice("classical.c",41,__func__,"fail to load hdf5 dataset"); return(0);};
    ca = (double ***)mem3(type_double, total_x, total_y, total_z);
    if (mode != mode_tex && mode != mode_tmx)
    {
        cb_x = (double ***)mem3(type_double, total_x, total_y, total_z);
        if (!(cb_x)) {notice("classical.c",47,__func__,"fail to allocate memory for cb_x"); return(0);};
    }
    if (mode != mode_tey && mode != mode_tmy)
    {
        cb_y = (double ***)mem3(type_double, total_x, total_y, total_z);
        if (!(cb_y)) {notice("classical.c",52,__func__,"fail to allocate memory for cb_y"); return(0);};
    }
    if (mode != mode_tez && mode != mode_tmz)
    {
        cb_z = (double ***)mem3(type_double, total_x, total_y, total_z);
        if (!(cb_z)) {notice("classical.c",57,__func__,"fail to allocate memory for cb_z"); return(0);};
    }
    for (z = 0; z < total_z; z++)
        for (y = 0; y < total_y; y++)
            for (x = 0; x < total_x; x++)
            {
                tmp = sigma[x][y][z] * d_t / (2 * epsilon[x][y][z]);
                ca[x][y][z] = (1 - tmp) / (1 + tmp);
                if (cb_x)
                    cb_x[x][y][z] = d_tx / epsilon[x][y][z] / (1 + tmp);
                if (cb_y)
                    cb_y[x][y][z] = d_ty / epsilon[x][y][z] / (1 + tmp);
                if (cb_z)
                    cb_z[x][y][z] = d_tz / epsilon[x][y][z] / (1 + tmp);
            }
    free_mem3((void ***)sigma, total_x, total_y);
    return 1;
}

variable_types: tmp double

variable_types:
sigma
double ***


decompiled_code:
__int64 __fastcall setup_input_ports(__int64 a1)
{
unsigned int v1; // er12
unsigned __int64 v3; // rbx
unsigned int v4; // er13
__int64 v5; // rax
__int64 v6; // rsi
int v7; // ecx
__int64 i; // rdx
_DWORD *v9; // rax
__int64 v10; // rax
__int64 v11; // rax
char v12[88]; // [rsp+0h] [rbp-58h] BYREF

if ( (unsigned int)h5_get_attr(a1, "excitations", "number_of_ports", &total_input_ports) )
{
if ( total_input_ports )
{
v1 = h5_get_attr(a1, "settings", "starting_index", &starting_index);
if ( !v1 )
{
notice("excitation.c", 49LL, "setup_input_ports", "fail to get h5 attributes");
return v1;
}
if ( total_input_ports > 0 )
{
v3 = (unsigned int)((_DWORD)&input_ports + 40);
v4 = 1;
while ( 1 )
{
sprintf(v12, "port_%02d_number_of_points", v4);
v1 = h5_get_attr(a1, "excitations", v12, v3);
if ( !v1 )
{
notice("excitation.c", 55LL, "setup_input_ports", "fail to get h5 attributes");
return v1;
}
sprintf(v12, "port_%02d_polarization", v4);
v1 = h5_get_attr(a1, "excitations", v12, v3 + 16);
if ( !v1 )
{
notice("excitation.c", 58LL, "setup_input_ports", "fail to get h5 attributes");
return v1;
}
if ( mode && mode != *(_DWORD *)(v3 + 16) )
break;
sprintf(v12, "/excitations/port_%02d_points", v4);
v5 = h5_load2(a1, v12, *(int *)v3, 3LL);
*(_QWORD *)(v3 + 8) = v5;
v6 = v5;
if ( !v5 )
{
v1 = 0;
notice("excitation.c", 63LL, "setup_input_ports", "fail to load hdf5 dataset");
return v1;
}
v7 = starting_index;
for ( i = 0LL; *(_DWORD *)v3 > (int)i; v9[2] -= v7 )
{
v9 = *(_DWORD **)(v6 + 8 * i++);
*v9 -= v7;
v7 = starting_index;
v9[1] -= starting_index;
}
sprintf(v12, "/excitations/port_%02d_signal", v4);
v10 = h5_load1(a1, v12, total_timesteps);
*(_QWORD *)(v3 + 32) = v10;
if ( !v10 )
{
v1 = 0;
notice("excitation.c", 74LL, "setup_input_ports", "fail to load hdf5 dataset");
return v1;
}
sprintf(v12, "/excitations/port_%02d_distribution", v4);
v11 = h5_load1(a1, v12, *(int *)v3);
*(_QWORD *)(v3 + 24) = v11;
if ( !v11 )
{
v1 = 0;
notice("excitation.c", 77LL, "setup_input_ports", "fail to load hdf5 dataset");
return v1;
}
++v4;
v3 += 40LL;
if ( total_input_ports < (int)v4 )
return 1;
}
v1 = 0;
notice("excitation.c", 59LL, "setup_input_ports", "polarization does not match with current simulation mode");
return v1;
}
}
return 1;
}
notice("excitation.c", 46LL, "setup_input_ports", "fail to get h5 attributes");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // er12
unsigned __int64 v3; // rbx
unsigned int v4; // er13
__int64 v5; // rax
__int64 v6; // rsi
int v7; // ecx
__int64 i; // rdx
_DWORD *v9; // rax
__int64 v10; // rax
__int64 v11; // rax
char v12[88]; // [rsp+0h] [rbp-58h] BYREF

if ( (unsigned int)h5_get_attr(a1, "excitations", "number_of_ports", &total_input_ports) )
{
if ( total_input_ports )
{
v1 = h5_get_attr(a1, "settings", "starting_index", &starting_index);
if ( !v1 )
{
notice("excitation.c", 49LL, "setup_input_ports", "fail to get h5 attributes");
return v1;
}
if ( total_input_ports > 0 )
{
v3 = (unsigned int)((_DWORD)&input_ports + 40);
v4 = 1;
while ( 1 )
{
sprintf(v12, "port_%02d_number_of_points", v4);
v1 = h5_get_attr(a1, "excitations", v12, v3);
if ( !v1 )
{
notice("excitation.c", 55LL, "setup_input_ports", "fail to get h5 attributes");
return v1;
}
sprintf(v12, "port_%02d_polarization", v4);
v1 = h5_get_attr(a1, "excitations", v12, v3 + 16);
if ( !v1 )
{
notice("excitation.c", 58LL, "setup_input_ports", "fail to get h5 attributes");
return v1;
}
if ( mode && mode != *(_DWORD *)(v3 + 16) )
break;
sprintf(v12, "/excitations/port_%02d_points", v4);
v5 = h5_load2(a1, v12, *(int *)v3, 3LL);
*(_QWORD *)(v3 + 8) = v5;
v6 = v5;
if ( !v5 )
{
v1 = 0;
notice("excitation.c", 63LL, "setup_input_ports", "fail to load hdf5 dataset");
return v1;
}
v7 = starting_index;
for ( i = 0LL; *(_DWORD *)v3 > (int)i; v9[2] -= v7 )
{
v9 = *(_DWORD **)(v6 + 8 * i++);
*v9 -= v7;
v7 = starting_index;
v9[1] -= starting_index;
}
sprintf(v12, "/excitations/port_%02d_signal", v4);
v10 = h5_load1(a1, v12, total_timesteps);
*(_QWORD *)(v3 + 32) = v10;
if ( !v10 )
{
v1 = 0;
notice("excitation.c", 74LL, "setup_input_ports", "fail to load hdf5 dataset");
return v1;
}
sprintf(v12, "/excitations/port_%02d_distribution", v4);
v11 = h5_load1(a1, v12, *(int *)v3);
*(_QWORD *)(v3 + 24) = v11;
if ( !v11 )
{
v1 = 0;
notice("excitation.c", 77LL, "setup_input_ports", "fail to load hdf5 dataset");
return v1;
}
++v4;
v3 += 40LL;
if ( total_input_ports < (int)v4 )
return 1;
}
v1 = 0;
notice("excitation.c", 59LL, "setup_input_ports", "polarization does not match with current simulation mode");
return v1;
}
}
return 1;
}
notice("excitation.c", 46LL, "setup_input_ports", "fail to get h5 attributes");
return 0LL;
}

original_code:
int setup_input_ports(char* file_name)
{
    int port_index;
    char attr_name[45];
    int status;
    int point_index;
    status = h5_get_attr(file_name, "excitations", "number_of_ports", &total_input_ports);
    if (!(status)) {notice("excitation.c",46,__func__,"fail to get h5 attributes"); return(0);};
    if (total_input_ports == 0) return 1;
    status = h5_get_attr(file_name, "settings", "starting_index", &starting_index);
    if (!(status)) {notice("excitation.c",49,__func__,"fail to get h5 attributes"); return(0);};
    for (port_index = 1; port_index <= total_input_ports; port_index++)
    {
        sprintf(attr_name, "port_%02d_number_of_points", port_index);
        status = h5_get_attr(file_name, "excitations", attr_name, &(input_ports[port_index].total_points));
        if (!(status)) {notice("excitation.c",55,__func__,"fail to get h5 attributes"); return(0);};
        sprintf(attr_name, "port_%02d_polarization", port_index);
        status = h5_get_attr(file_name, "excitations", attr_name, &(input_ports[port_index].polarization));
        if (!(status)) {notice("excitation.c",58,__func__,"fail to get h5 attributes"); return(0);};
        if (!(mode == 0 || input_ports[port_index].polarization == mode)) {notice("excitation.c",59,__func__,"polarization does not match with current simulation mode"); return(0);};
        sprintf(attr_name, "/excitations/port_%02d_points", port_index);
        input_ports[port_index].source_points = (int **)h5_load2(file_name, attr_name, input_ports[port_index].total_points, 3);
        if (!(input_ports[port_index].source_points)) {notice("excitation.c",63,__func__,"fail to load hdf5 dataset"); return(0);};
        for (point_index = 0; point_index < input_ports[port_index].total_points; point_index ++)
        {
            input_ports[port_index].source_points[point_index][0] = input_ports[port_index].source_points[point_index][0] - starting_index;
            input_ports[port_index].source_points[point_index][1] = input_ports[port_index].source_points[point_index][1] - starting_index;
            input_ports[port_index].source_points[point_index][2] = input_ports[port_index].source_points[point_index][2] - starting_index;
        }
        sprintf(attr_name, "/excitations/port_%02d_signal", port_index);
        input_ports[port_index].source_signal = (double *)h5_load1(file_name, attr_name, total_timesteps);
        if (!(input_ports[port_index].source_signal)) {notice("excitation.c",74,__func__,"fail to load hdf5 dataset"); return(0);};
        sprintf(attr_name, "/excitations/port_%02d_distribution", port_index);
        input_ports[port_index].source_distribution = (double *)h5_load1(file_name, attr_name, input_ports[port_index].total_points);
        if (!(input_ports[port_index].source_distribution)) {notice("excitation.c",77,__func__,"fail to load hdf5 dataset"); return(0);};
    }
    return 1;
}

canonical_original_code:
int setup_input_ports(char *file_name)
{
    int port_index;
    char attr_name[45];
    int status;
    int point_index;
    status = h5_get_attr(file_name, "excitations", "number_of_ports", &total_input_ports);
    if (!(status)) {notice("excitation.c",46,__func__,"fail to get h5 attributes"); return(0);};
    if (total_input_ports == 0) return 1;
    status = h5_get_attr(file_name, "settings", "starting_index", &starting_index);
    if (!(status)) {notice("excitation.c",49,__func__,"fail to get h5 attributes"); return(0);};
    for (port_index = 1; port_index <= total_input_ports; port_index++)
    {
        sprintf(attr_name, "port_%02d_number_of_points", port_index);
        status = h5_get_attr(file_name, "excitations", attr_name, &(input_ports[port_index].total_points));
        if (!(status)) {notice("excitation.c",55,__func__,"fail to get h5 attributes"); return(0);};
        sprintf(attr_name, "port_%02d_polarization", port_index);
        status = h5_get_attr(file_name, "excitations", attr_name, &(input_ports[port_index].polarization));
        if (!(status)) {notice("excitation.c",58,__func__,"fail to get h5 attributes"); return(0);};
        if (!(mode == 0 || input_ports[port_index].polarization == mode)) {notice("excitation.c",59,__func__,"polarization does not match with current simulation mode"); return(0);};
        sprintf(attr_name, "/excitations/port_%02d_points", port_index);
        input_ports[port_index].source_points = (int **)h5_load2(file_name, attr_name, input_ports[port_index].total_points, 3);
        if (!(input_ports[port_index].source_points)) {notice("excitation.c",63,__func__,"fail to load hdf5 dataset"); return(0);};
        for (point_index = 0; point_index < input_ports[port_index].total_points; point_index ++)
        {
            input_ports[port_index].source_points[point_index][0] = input_ports[port_index].source_points[point_index][0] - starting_index;
            input_ports[port_index].source_points[point_index][1] = input_ports[port_index].source_points[point_index][1] - starting_index;
            input_ports[port_index].source_points[point_index][2] = input_ports[port_index].source_points[point_index][2] - starting_index;
        }
        sprintf(attr_name, "/excitations/port_%02d_signal", port_index);
        input_ports[port_index].source_signal = (double *)h5_load1(file_name, attr_name, total_timesteps);
        if (!(input_ports[port_index].source_signal)) {notice("excitation.c",74,__func__,"fail to load hdf5 dataset"); return(0);};
        sprintf(attr_name, "/excitations/port_%02d_distribution", port_index);
        input_ports[port_index].source_distribution = (double *)h5_load1(file_name, attr_name, input_ports[port_index].total_points);
        if (!(input_ports[port_index].source_distribution)) {notice("excitation.c",77,__func__,"fail to load hdf5 dataset"); return(0);};
    }
    return 1;
}


decompiled_code:
__int64 __fastcall setup_point_sources(__int64 a1)
{
unsigned int v1; // er12
__int64 result; // rax
__int64 v3; // rsi
int v4; // eax
int v5; // ecx
__int64 i; // rdx
_DWORD *v7; // rax

if ( (unsigned int)h5_get_attr(a1, "excitations", "number_of_point_sources", &total_point_sources) )
{
if ( !total_point_sources )
return 1;
if ( (unsigned int)h5_get_attr(a1, "settings", "starting_index", &starting_index) )
{
source_points = h5_load2(a1, "/excitations/source_points", total_point_sources, 3LL);
v3 = source_points;
if ( !source_points )
{
v1 = 0;
notice("excitation.c", 95LL, "setup_point_sources", "fail to load hdf5 dataset");
return v1;
}
v4 = total_point_sources;
v5 = starting_index;
for ( i = 0LL; total_point_sources > (int)i; v4 = total_point_sources )
{
v7 = *(_DWORD **)(v3 + 8 * i++);
*v7 -= v5;
v5 = starting_index;
v7[1] -= starting_index;
v7[2] -= v5;
}
source_polarizations = h5_load1(a1, "/excitations/source_polarizations", v4);
if ( !source_polarizations )
{
v1 = 0;
notice("excitation.c", 104LL, "setup_point_sources", "fail to load hdf5 dataset");
return v1;
}
source_signals = h5_load2(a1, "/excitations/source_signals", total_timesteps, total_point_sources);
if ( !source_signals )
{
v1 = 0;
notice("excitation.c", 106LL, "setup_point_sources", "fail to load hdf5 dataset");
return v1;
}
return 1;
}
notice("excitation.c", 92LL, "setup_point_sources", "fail to get h5 attributes");
result = 0LL;
}
else
{
notice("excitation.c", 88LL, "setup_point_sources", "fail to load hdf5 dataset");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // er12
__int64 result; // rax
__int64 v3; // rsi
int v4; // eax
int v5; // ecx
__int64 i; // rdx
_DWORD *v7; // rax

if ( (unsigned int)h5_get_attr(a1, "excitations", "number_of_point_sources", &total_point_sources) )
{
if ( !total_point_sources )
return 1;
if ( (unsigned int)h5_get_attr(a1, "settings", "starting_index", &starting_index) )
{
source_points = h5_load2(a1, "/excitations/source_points", total_point_sources, 3LL);
v3 = source_points;
if ( !source_points )
{
v1 = 0;
notice("excitation.c", 95LL, "setup_point_sources", "fail to load hdf5 dataset");
return v1;
}
v4 = total_point_sources;
v5 = starting_index;
for ( i = 0LL; total_point_sources > (int)i; v4 = total_point_sources )
{
v7 = *(_DWORD **)(v3 + 8 * i++);
*v7 -= v5;
v5 = starting_index;
v7[1] -= starting_index;
v7[2] -= v5;
}
source_polarizations = h5_load1(a1, "/excitations/source_polarizations", v4);
if ( !source_polarizations )
{
v1 = 0;
notice("excitation.c", 104LL, "setup_point_sources", "fail to load hdf5 dataset");
return v1;
}
source_signals = h5_load2(a1, "/excitations/source_signals", total_timesteps, total_point_sources);
if ( !source_signals )
{
v1 = 0;
notice("excitation.c", 106LL, "setup_point_sources", "fail to load hdf5 dataset");
return v1;
}
return 1;
}
notice("excitation.c", 92LL, "setup_point_sources", "fail to get h5 attributes");
result = 0LL;
}
else
{
notice("excitation.c", 88LL, "setup_point_sources", "fail to load hdf5 dataset");
result = 0LL;
}
return result;
}

original_code:
int setup_point_sources(char* file_name)
{
    int status;
    int point_index;
    status = h5_get_attr(file_name, "excitations", "number_of_point_sources", &total_point_sources);
    if (!(status)) {notice("excitation.c",88,__func__,"fail to load hdf5 dataset"); return(0);};
    if (total_point_sources == 0) return 1;
    status = h5_get_attr(file_name, "settings", "starting_index", &starting_index);
    if (!(status)) {notice("excitation.c",92,__func__,"fail to get h5 attributes"); return(0);};
    source_points = (int **)h5_load2(file_name, "/excitations/source_points", total_point_sources, 3);
    if (!(source_points)) {notice("excitation.c",95,__func__,"fail to load hdf5 dataset"); return(0);};
    for (point_index = 0; point_index < total_point_sources; point_index ++)
    {
        source_points[point_index][0] = source_points[point_index][0] - starting_index;
        source_points[point_index][1] = source_points[point_index][1] - starting_index;
        source_points[point_index][2] = source_points[point_index][2] - starting_index;
    }
    source_polarizations = (int *)h5_load1(file_name, "/excitations/source_polarizations", total_point_sources);
    if (!(source_polarizations)) {notice("excitation.c",104,__func__,"fail to load hdf5 dataset"); return(0);};
    source_signals = (double **)h5_load2(file_name, "/excitations/source_signals", total_timesteps, total_point_sources);
    if (!(source_signals)) {notice("excitation.c",106,__func__,"fail to load hdf5 dataset"); return(0);};
    return 1;
}

canonical_original_code:
int setup_point_sources(char *file_name)
{
    int status;
    int point_index;
    status = h5_get_attr(file_name, "excitations", "number_of_point_sources", &total_point_sources);
    if (!(status)) {notice("excitation.c",88,__func__,"fail to load hdf5 dataset"); return(0);};
    if (total_point_sources == 0) return 1;
    status = h5_get_attr(file_name, "settings", "starting_index", &starting_index);
    if (!(status)) {notice("excitation.c",92,__func__,"fail to get h5 attributes"); return(0);};
    source_points = (int **)h5_load2(file_name, "/excitations/source_points", total_point_sources, 3);
    if (!(source_points)) {notice("excitation.c",95,__func__,"fail to load hdf5 dataset"); return(0);};
    for (point_index = 0; point_index < total_point_sources; point_index ++)
    {
        source_points[point_index][0] = source_points[point_index][0] - starting_index;
        source_points[point_index][1] = source_points[point_index][1] - starting_index;
        source_points[point_index][2] = source_points[point_index][2] - starting_index;
    }
    source_polarizations = (int *)h5_load1(file_name, "/excitations/source_polarizations", total_point_sources);
    if (!(source_polarizations)) {notice("excitation.c",104,__func__,"fail to load hdf5 dataset"); return(0);};
    source_signals = (double **)h5_load2(file_name, "/excitations/source_signals", total_timesteps, total_point_sources);
    if (!(source_signals)) {notice("excitation.c",106,__func__,"fail to load hdf5 dataset"); return(0);};
    return 1;
}


decompiled_code:
__int64 __fastcall setup_hards(__int64 a1)
{
unsigned int v1; // er12
__int64 result; // rax
__int64 v3; // rsi
int v4; // eax
int v5; // ecx
__int64 i; // rdx
_DWORD *v7; // rax

if ( (unsigned int)h5_get_attr(a1, "excitations", "number_of_hards", &total_hards) )
{
if ( !total_hards )
return 1;
if ( (unsigned int)h5_get_attr(a1, "settings", "starting_index", &starting_index) )
{
hard_points = h5_load2(a1, "/excitations/hard_points", total_hards, 3LL);
v3 = hard_points;
if ( !hard_points )
{
v1 = 0;
notice("excitation.c", 123LL, "setup_hards", "fail to load hdf5 dataset");
return v1;
}
v4 = total_hards;
v5 = starting_index;
for ( i = 0LL; total_hards > (int)i; v4 = total_hards )
{
v7 = *(_DWORD **)(v3 + 8 * i++);
*v7 -= v5;
v5 = starting_index;
v7[1] -= starting_index;
v7[2] -= v5;
}
hard_polarizations = h5_load1(a1, "/excitations/hard_polarizations", v4);
if ( !hard_polarizations )
{
v1 = 0;
notice("excitation.c", 131LL, "setup_hards", "fail to load hdf5 dataset");
return v1;
}
hard_signals = h5_load2(a1, "/excitations/hard_signals", total_timesteps, total_hards);
if ( !hard_signals )
{
v1 = 0;
notice("excitation.c", 133LL, "setup_hards", "fail to load hdf5 dataset");
return v1;
}
return 1;
}
notice("excitation.c", 120LL, "setup_hards", "fail to get h5 attributes");
result = 0LL;
}
else
{
notice("excitation.c", 117LL, "setup_hards", "fail to load hdf5 dataset");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // er12
__int64 result; // rax
__int64 v3; // rsi
int v4; // eax
int v5; // ecx
__int64 i; // rdx
_DWORD *v7; // rax

if ( (unsigned int)h5_get_attr(a1, "excitations", "number_of_hards", &total_hards) )
{
if ( !total_hards )
return 1;
if ( (unsigned int)h5_get_attr(a1, "settings", "starting_index", &starting_index) )
{
hard_points = h5_load2(a1, "/excitations/hard_points", total_hards, 3LL);
v3 = hard_points;
if ( !hard_points )
{
v1 = 0;
notice("excitation.c", 123LL, "setup_hards", "fail to load hdf5 dataset");
return v1;
}
v4 = total_hards;
v5 = starting_index;
for ( i = 0LL; total_hards > (int)i; v4 = total_hards )
{
v7 = *(_DWORD **)(v3 + 8 * i++);
*v7 -= v5;
v5 = starting_index;
v7[1] -= starting_index;
v7[2] -= v5;
}
hard_polarizations = h5_load1(a1, "/excitations/hard_polarizations", v4);
if ( !hard_polarizations )
{
v1 = 0;
notice("excitation.c", 131LL, "setup_hards", "fail to load hdf5 dataset");
return v1;
}
hard_signals = h5_load2(a1, "/excitations/hard_signals", total_timesteps, total_hards);
if ( !hard_signals )
{
v1 = 0;
notice("excitation.c", 133LL, "setup_hards", "fail to load hdf5 dataset");
return v1;
}
return 1;
}
notice("excitation.c", 120LL, "setup_hards", "fail to get h5 attributes");
result = 0LL;
}
else
{
notice("excitation.c", 117LL, "setup_hards", "fail to load hdf5 dataset");
result = 0LL;
}
return result;
}

original_code:
int setup_hards(char* file_name)
{
    int status;
    int point_index;
    status = h5_get_attr(file_name, "excitations", "number_of_hards", &total_hards);
    if (!(status)) {notice("excitation.c",117,__func__,"fail to load hdf5 dataset"); return(0);};
    if (total_hards == 0) return 1;
    status = h5_get_attr(file_name, "settings", "starting_index", &starting_index);
    if (!(status)) {notice("excitation.c",120,__func__,"fail to get h5 attributes"); return(0);};
    hard_points = (int **)h5_load2(file_name, "/excitations/hard_points", total_hards, 3);
    if (!(hard_points)) {notice("excitation.c",123,__func__,"fail to load hdf5 dataset"); return(0);};
    for (point_index = 0; point_index < total_hards; point_index ++)
    {
        hard_points[point_index][0] = hard_points[point_index][0] - starting_index;
        hard_points[point_index][1] = hard_points[point_index][1] - starting_index;
        hard_points[point_index][2] = hard_points[point_index][2] - starting_index;
    }
    hard_polarizations = (int *)h5_load1(file_name, "/excitations/hard_polarizations", total_hards);
    if (!(hard_polarizations)) {notice("excitation.c",131,__func__,"fail to load hdf5 dataset"); return(0);};
    hard_signals = (double **)h5_load2(file_name, "/excitations/hard_signals", total_timesteps, total_hards);
    if (!(hard_signals)) {notice("excitation.c",133,__func__,"fail to load hdf5 dataset"); return(0);};
    return 1;
}

canonical_original_code:
int setup_hards(char *file_name)
{
    int status;
    int point_index;
    status = h5_get_attr(file_name, "excitations", "number_of_hards", &total_hards);
    if (!(status)) {notice("excitation.c",117,__func__,"fail to load hdf5 dataset"); return(0);};
    if (total_hards == 0) return 1;
    status = h5_get_attr(file_name, "settings", "starting_index", &starting_index);
    if (!(status)) {notice("excitation.c",120,__func__,"fail to get h5 attributes"); return(0);};
    hard_points = (int **)h5_load2(file_name, "/excitations/hard_points", total_hards, 3);
    if (!(hard_points)) {notice("excitation.c",123,__func__,"fail to load hdf5 dataset"); return(0);};
    for (point_index = 0; point_index < total_hards; point_index ++)
    {
        hard_points[point_index][0] = hard_points[point_index][0] - starting_index;
        hard_points[point_index][1] = hard_points[point_index][1] - starting_index;
        hard_points[point_index][2] = hard_points[point_index][2] - starting_index;
    }
    hard_polarizations = (int *)h5_load1(file_name, "/excitations/hard_polarizations", total_hards);
    if (!(hard_polarizations)) {notice("excitation.c",131,__func__,"fail to load hdf5 dataset"); return(0);};
    hard_signals = (double **)h5_load2(file_name, "/excitations/hard_signals", total_timesteps, total_hards);
    if (!(hard_signals)) {notice("excitation.c",133,__func__,"fail to load hdf5 dataset"); return(0);};
    return 1;
}


excite

original_code:
int excite(int time_index)
{
    int source_index;
    int port_index;
    for (port_index = 1; port_index <= total_input_ports; port_index++)
    {
        for (source_index = 0; source_index < input_ports[port_index].total_points; source_index++)
        {
            x = input_ports[port_index].source_points[source_index][0];
            y = input_ports[port_index].source_points[source_index][1];
            z = input_ports[port_index].source_points[source_index][2];
            if (input_ports[port_index].polarization == p_ex)
                dipole_ex[x][y][z] = input_ports[port_index].source_signal[time_index]
                    * input_ports[port_index].source_distribution[source_index];
            else if (input_ports[port_index].polarization == p_ey)
                dipole_ey[x][y][z] = input_ports[port_index].source_signal[time_index]
                    * input_ports[port_index].source_distribution[source_index];
            else if (input_ports[port_index].polarization == p_ez)
                dipole_ez[x][y][z] = input_ports[port_index].source_signal[time_index]
                    * input_ports[port_index].source_distribution[source_index];
            else if (input_ports[port_index].polarization == p_hx)
                dipole_hx[x][y][z] = input_ports[port_index].source_signal[time_index]
                    * input_ports[port_index].source_distribution[source_index];
            else if (input_ports[port_index].polarization == p_hy)
                dipole_hy[x][y][z] = input_ports[port_index].source_signal[time_index]
                    * input_ports[port_index].source_distribution[source_index];
            else if (input_ports[port_index].polarization == p_hz)
                dipole_hz[x][y][z] = input_ports[port_index].source_signal[time_index]
                    * input_ports[port_index].source_distribution[source_index];
        }
    }
    for (source_index = 0; source_index < total_point_sources; source_index++)
    {
        x = source_points[source_index][0];
        y = source_points[source_index][1];
        z = source_points[source_index][2];
        switch (source_polarizations[source_index])
        {
            case (p_ex):
                dipole_ex[x][y][z] = source_signals[time_index][source_index];
                break;
            case (p_ey):
                dipole_ey[x][y][z] = source_signals[time_index][source_index];
                break;
            case (p_ez):
                dipole_ez[x][y][z] = source_signals[time_index][source_index];
                break;
            case (p_hx):
                dipole_hx[x][y][z] = source_signals[time_index][source_index];
                break;
            case (p_hy):
                dipole_hy[x][y][z] = source_signals[time_index][source_index];
                break;
            case (p_hz):
                dipole_hz[x][y][z] = source_signals[time_index][source_index];
                break;
        }
    }
    return 1;
}


original_code:
int apply_ehards(int time_index)
{
    int hard_index;
    for (hard_index = 0; hard_index < total_hards; hard_index++)
    {
        x = hard_points[hard_index][0];
        y = hard_points[hard_index][1];
        z = hard_points[hard_index][2];
        if (hard_polarizations[hard_index] == p_ex)
            ex[x][y][z] = hard_signals[time_index][hard_index];
        else if (hard_polarizations[hard_index] == p_ey)
            ey[x][y][z] = hard_signals[time_index][hard_index];
        else if (hard_polarizations[hard_index] == p_ez)
            ez[x][y][z] = hard_signals[time_index][hard_index];
    }
    return 1;
}


original_code:
int apply_hhards(int time_index)
{
    int hard_index;
    for (hard_index = 0; hard_index < total_hards; hard_index++)
    {
        x = hard_points[hard_index][0];
        y = hard_points[hard_index][1];
        z = hard_points[hard_index][2];
        if (hard_polarizations[hard_index] == p_hx)
            hx[x][y][z] = hard_signals[time_index][hard_index];
        else if (hard_polarizations[hard_index] == p_hy)
            hy[x][y][z] = hard_signals[time_index][hard_index];
        else if (hard_polarizations[hard_index] == p_hz)
            hz[x][y][z] = hard_signals[time_index][hard_index];
    }
    return 1;
}


original_code:
void clist_init(
                CList *list,
                void (*destroy)(void *))
{
    list->size = 0;
    list->destroy = destroy;
    list->head = ((void *)0);
}

canonical_original_code:
void clist_init(struct CList_ *list, void (*destroy)(void *))
{
    list->size = 0;
    list->destroy = destroy;
    list->head = ((void *)0);
}

variable_types: struct CList_ { int size; int (*cmp)(void *, void *); void (*destroy)(void *); struct CListElmt_ { void *data; struct CListElmt_ *next; } *head; } *

variable_types:
destroy
void (*)(void *)

user_defined_types: struct CList_ { int size; int (*cmp)(void *, void *); void (*destroy)(void *); struct CListElmt_ *head; }


decompiled_code:
__int64 __fastcall clist_ins_next(int *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax
int v5; // edx
__int64 v6; // rcx
__int64 result; // rax

v4 = malloc(0x10uLL);
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = *a1;
*v4 = a3;
if ( v5 )
{
v6 = *(_QWORD *)(a2 + 8);
*(_QWORD *)(a2 + 8) = v4;
v4[1] = v6;
}
else
{
v4[1] = v4;
*((_QWORD *)a1 + 3) = v4;
}
result = 0LL;
*a1 = v5 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax
int v5; // edx
__int64 v6; // rcx
__int64 result; // rax

v4 = malloc(0x10uLL);
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = *a1;
*v4 = a3;
if ( v5 )
{
v6 = *(_QWORD *)(a2 + 8);
*(_QWORD *)(a2 + 8) = v4;
v4[1] = v6;
}
else
{
v4[1] = v4;
*((_QWORD *)a1 + 3) = v4;
}
result = 0LL;
*a1 = v5 + 1;
return result;
}

original_code:
int clist_ins_next(
                CList *list,
                CListElmt *iter,
                const void *data)
{
    CListElmt *new_element ;
    if((new_element = (CListElmt*)malloc(sizeof(CListElmt))) == ((void *)0))
        return -1;
    new_element->data = (void *)data;
    if(((list)->size) == 0)
    {
        new_element->next = new_element;
        list->head = new_element;
    } else {
        new_element->next = iter->next;
        iter->next = new_element;
    }
    list->size++;
    return 0;
}

canonical_original_code:
int clist_ins_next(struct CList_ *list, struct CListElmt_ *iter, void *data)
{
    struct CListElmt_ *new_element;
    if((new_element = (struct CListElmt_ *)malloc(sizeof(CListElmt))) == ((void *)0))
        return -1;
    new_element->data = (void *)data;
    if(((list)->size) == 0)
    {
        new_element->next = new_element;
        list->head = new_element;
    } else {
        new_element->next = iter->next;
        iter->next = new_element;
    }
    list->size++;
    return 0;
}

variable_types:
iter
struct CListElmt_ *

variable_types:
data
void *

variable_types: struct CListElmt_ { void *data; struct CListElmt_ *next; } *


original_code:
int clist_rem_next(
                CList *list,
                CListElmt * iter,
                void **data)
{
    CListElmt *old_element;
    if(((list)->size) == 0)
        return -1;
    *data = iter->next->data;
    if(iter == iter->next){
        old_element = iter;
        list->head = ((void *)0);
    } else {
        old_element = iter->next;
        iter->next = old_element->next;
        if (old_element == ((list)->head))
            list->head = old_element->next;
    }
    free(old_element);
    list->size--;
    return 0;
}

canonical_original_code:
int clist_rem_next(struct CList_ *list, struct CListElmt_ *iter, void **data)
{
    struct CListElmt_ *old_element;
    if(((list)->size) == 0)
        return -1;
    *data = iter->next->data;
    if(iter == iter->next){
        old_element = iter;
        list->head = ((void *)0);
    } else {
        old_element = iter->next;
        iter->next = old_element->next;
        if (old_element == ((list)->head))
            list->head = old_element->next;
    }
    free(old_element);
    list->size--;
    return 0;
}

variable_types:
data
void **

user_defined_types: struct CListElmt_ { void *data; struct CListElmt_ *next; }


decompiled_code:
int __fastcall print_email_list(unsigned int *a1)
{
int result; // eax
int v2; // er12
const char **v3; // rbp
int v4; // er13
int v5; // ebx
int v6; // eax
__int64 v7; // rdx

result = fprintf(_bss_start, "Email_list size is %d (circling twice)\n\n", *a1);
v2 = *a1;
v3 = (const char **)*((_QWORD *)a1 + 3);
v4 = 2 * *a1;
if ( v4 > 0 )
{
v5 = 0;
do
{
v6 = v5++;
v7 = (unsigned int)(v6 >> 31);
LODWORD(v7) = v6 % v2;
result = fprintf(
_bss_start,
"email_list[%03d] =\nEmail {\nsubjet: %s,\nfrom: %s,\ntime_date: %d }\n\n",
v7,
*v3,
*v3 + 1032,
*((unsigned int *)*v3 + 256));
v3 = (const char **)v3[1];
}
while ( v5 != v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(unsigned int *a1)
{
int result; // eax
int v2; // er12
const char **v3; // rbp
int v4; // er13
int v5; // ebx
int v6; // eax
__int64 v7; // rdx

result = fprintf(_bss_start, "Email_list size is %d (circling twice)\n\n", *a1);
v2 = *a1;
v3 = (const char **)*((_QWORD *)a1 + 3);
v4 = 2 * *a1;
if ( v4 > 0 )
{
v5 = 0;
do
{
v6 = v5++;
v7 = (unsigned int)(v6 >> 31);
LODWORD(v7) = v6 % v2;
result = fprintf(
_bss_start,
"email_list[%03d] =\nEmail {\nsubjet: %s,\nfrom: %s,\ntime_date: %d }\n\n",
v7,
*v3,
*v3 + 1032,
*((unsigned int *)*v3 + 256));
v3 = (const char **)v3[1];
}
while ( v5 != v4 );
}
return result;
}

original_code:
void print_email_list(const CList *list) {
    CListElmt *iter;
    int size,
                        i;
    fprintf(stdout, "Email_list size is %d (circling twice)\n\n", ((list)->size));
    size = ((list)->size);
    iter = ((list)->head);
    i = 0;
    Email *email;
    while (i < size * 2) {
        email = ((iter)->data);
        fprintf(stdout, "email_list[%03d] =\nEmail {\nsubjet: %s,\nfrom: %s,\ntime_date: %d }\n\n", (i % size), email->subject, email->from, (int) email->time_date);
        iter = ((iter)->next);
        i++;
    }
    return;
}

canonical_original_code:
void print_email_list(struct CList_ *list) {
    struct CListElmt_ *iter;
    int size; int i;
    fprintf(stdout, "Email_list size is %d (circling twice)\n\n", ((list)->size));
    size = ((list)->size);
    iter = ((list)->head);
    i = 0;
    struct Email_ *email;
    while (i < size * 2) {
        email = ((iter)->data);
        fprintf(stdout, "email_list[%03d] =\nEmail {\nsubjet: %s,\nfrom: %s,\ntime_date: %d }\n\n", (i % size), email->subject, email->from, (int) email->time_date);
        iter = ((iter)->next);
        i++;
    }
    return;
}

variable_types: size int

variable_types: i int

variable_types: struct Email_ { char subject[1024]; long time_date; char from[64]; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
char **v4; // rbp
char *v5; // rdi
int v6; // eax
__int64 v7; // r8
const char *v8; // rcx
int v9; // er12
char *dest; // [rsp+8h] [rbp-4A0h] BYREF
char v12[24]; // [rsp+10h] [rbp-498h] BYREF
__int64 v13; // [rsp+28h] [rbp-480h]
char src[1144]; // [rsp+30h] [rbp-478h] BYREF

v3 = 0;
memset(src, 0, 0x448uLL);
*(__m128i *)src = _mm_load_si128((const __m128i *)&xmmword_402120);
*(_QWORD *)&src[1056] = 0LL;
*(_QWORD *)&src[1048] = 0x3E6E69616D6F6440LL;
*(__m128i *)&src[1032] = _mm_load_si128((const __m128i *)&xmmword_402130);
*(_QWORD *)&src[16] = 7302501LL;
*(_QWORD *)&src[24] = 0LL;
clist_init(v12, free);
v4 = (char **)v13;
fwrite("...Insert ten emial objects\n", 1uLL, 0x1CuLL, _bss_start);
do
{
while ( 1 )
{
dest = (char *)malloc(0x448uLL);
if ( !dest )
return 1;
v5 = dest;
*((_QWORD *)dest + 128) = time(0LL);
strncpy(v5, src, 0x3FFuLL);
strncpy(dest + 1032, &src[1032], 0x3FuLL);
fprintf(_bss_start, "insert [%03d] item...\n", v3);
if ( (unsigned int)clist_ins_next(v12, v4, dest) )
return 1;
if ( !v4 )
break;
++v3;
v4 = (char **)v4[1];
if ( v3 == 10 )
goto LABEL_7;
}
++v3;
v4 = *(char ***)(v13 + 8);
}
while ( v3 != 10 );
LABEL_7:
print_email_list(v12);
v6 = 15;
do
{
v4 = (char **)v4[1];
--v6;
}
while ( v6 );
v7 = *((unsigned int *)*v4 + 256);
v8 = *v4 + 1032;
dest = *v4;
fprintf(_bss_start, "remove after Email {\nsubjet: %s,\nfrom: %s,\ntime_date: %d }\n\n", dest, v8, v7);
v9 = clist_rem_next(v12, v4, &dest);
if ( v9 )
return 1;
free(dest);
print_email_list(v12);
fwrite("Destory Email circular list\n", 1uLL, 0x1CuLL, _bss_start);
clist_dealloc(v12);
return v9;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
char **v4; // rbp
char *v5; // rdi
int v6; // eax
__int64 v7; // r8
const char *v8; // rcx
int v9; // er12
char *dest; // [rsp+8h] [rbp-4A0h] BYREF
char v12[24]; // [rsp+10h] [rbp-498h] BYREF
__int64 v13; // [rsp+28h] [rbp-480h]
char src[1144]; // [rsp+30h] [rbp-478h] BYREF

v3 = 0;
memset(src, 0, 0x448uLL);
*(__m128i *)src = _mm_load_si128((const __m128i *)&xmmword_402120);
*(_QWORD *)&src[1056] = 0LL;
*(_QWORD *)&src[1048] = 0x3E6E69616D6F6440LL;
*(__m128i *)&src[1032] = _mm_load_si128((const __m128i *)&xmmword_402130);
*(_QWORD *)&src[16] = 7302501LL;
*(_QWORD *)&src[24] = 0LL;
func7(v12, free);
v4 = (char **)v13;
fwrite("...Insert ten emial objects\n", 1uLL, 0x1CuLL, _bss_start);
do
{
while ( 1 )
{
dest = (char *)malloc(0x448uLL);
if ( !dest )
return 1;
v5 = dest;
*((_QWORD *)dest + 128) = time(0LL);
strncpy(v5, src, 0x3FFuLL);
strncpy(dest + 1032, &src[1032], 0x3FuLL);
fprintf(_bss_start, "insert [%03d] item...\n", v3);
if ( (unsigned int)func8(v12, v4, dest) )
return 1;
if ( !v4 )
break;
++v3;
v4 = (char **)v4[1];
if ( v3 == 10 )
goto LABEL_7;
}
++v3;
v4 = *(char ***)(v13 + 8);
}
while ( v3 != 10 );
LABEL_7:
func11(v12);
v6 = 15;
do
{
v4 = (char **)v4[1];
--v6;
}
while ( v6 );
v7 = *((unsigned int *)*v4 + 256);
v8 = *v4 + 1032;
dest = *v4;
fprintf(_bss_start, "remove after Email {\nsubjet: %s,\nfrom: %s,\ntime_date: %d }\n\n", dest, v8, v7);
v9 = func9(v12, v4, &dest);
if ( v9 )
return 1;
free(dest);
func11(v12);
fwrite("Destory Email circular list\n", 1uLL, 0x1CuLL, _bss_start);
func10(v12);
return v9;
}

original_code:
int main()
{
    Email eemail = {.subject = "this is a test demo", .from = "Thomas<youremail@domain>"};
    Email *email;
    CList email_list;
    clist_init(&email_list, free);
    CListElmt *iter;
    iter = ((&email_list)->head);
    int i = 0;
    fprintf(stdout, "...Insert ten emial objects\n");
    while(i < 10){
        if((email = (Email*)malloc(sizeof(Email))) == ((void *)0) )
            return 1;
        email->time_date = time(((void *)0));
        strncpy(email->subject, eemail.subject, 1023);
        strncpy(email->from, eemail.from, 63);
        fprintf(stdout, "insert [%03d] item...\n", i);
        if(clist_ins_next(&email_list, iter, (void *)email ) != 0)
            return 1;
        if (iter == ((void *)0))
            iter = ((((&email_list)->head))->next);
        else
            iter = ((iter)->next);
        i++;
    }
    print_email_list(&email_list);
    for (i = 0; i < 15; i++)
      iter = ((iter)->next);
    email = ((iter)->data);
     fprintf(stdout, "remove after Email {\nsubjet: %s,\nfrom: %s,\ntime_date: %d }\n\n", email->subject, email->from, (int)email->time_date);
    if (clist_rem_next(&email_list, iter, (void **)&email) != 0)
        return 1;
    free(email);
    print_email_list(&email_list);
    fprintf(stdout, "Destory Email circular list\n");
    clist_dealloc(&email_list);
    return 0;
}

canonical_original_code:
int main()
{
    struct Email_ eemail = {.subject = "this is a test demo", .from = "Thomas<youremail@domain>"};
    struct Email_ *email;
    struct CList_ email_list;
    clist_init(&email_list, free);
    struct CListElmt_ *iter;
    iter = ((&email_list)->head);
    int i = 0;
    fprintf(stdout, "...Insert ten emial objects\n");
    while(i < 10){
        if((email = (struct Email_ *)malloc(sizeof(Email))) == ((void *)0) )
            return 1;
        email->time_date = time(((void *)0));
        strncpy(email->subject, eemail.subject, 1023);
        strncpy(email->from, eemail.from, 63);
        fprintf(stdout, "insert [%03d] item...\n", i);
        if(clist_ins_next(&email_list, iter, (void *)email ) != 0)
            return 1;
        if (iter == ((void *)0))
            iter = ((((&email_list)->head))->next);
        else
            iter = ((iter)->next);
        i++;
    }
    print_email_list(&email_list);
    for (i = 0; i < 15; i++)
      iter = ((iter)->next);
    email = ((iter)->data);
     fprintf(stdout, "remove after Email {\nsubjet: %s,\nfrom: %s,\ntime_date: %d }\n\n", email->subject, email->from, (int)email->time_date);
    if (clist_rem_next(&email_list, iter, (void **)&email) != 0)
        return 1;
    free(email);
    print_email_list(&email_list);
    fprintf(stdout, "Destory Email circular list\n");
    clist_dealloc(&email_list);
    return 0;
}

variable_types: struct Email_ { char subject[1024]; long time_date; char from[64]; }

variable_types: struct CList_ { int size; int (*cmp)(void *, void *); void (*destroy)(void *); struct CListElmt_ { void *data; struct CListElmt_ *next; } *head; }


decompiled_code:
unsigned __int64 COUNTING_SORT()
{
int v0; // esi
__int64 v1; // rax
__int64 v2; // rdx
unsigned __int64 result; // rax
__int64 v4; // rdx
__int64 v5; // rcx
int v6; // eax

v0 = lenth;
memset(count, 0, 0x320uLL);
count[200] = 0;
if ( v0 > 0 )
{
v1 = 1LL;
do
{
v2 = num[v1++];
++count[v2];
}
while ( v0 + 1 != v1 );
}
result = (unsigned __int64)&unk_404084;
do
{
*(_DWORD *)result += *(_DWORD *)(result - 4);
result += 4LL;
}
while ( &unk_4043A4 != (_UNKNOWN *)result );
if ( v0 > 0 )
{
v4 = v0;
do
{
v5 = num[v4--];
v6 = count[v5];
::result[v6] = v5;
result = (unsigned int)(v6 - 1);
count[v5] = result;
}
while ( (int)v4 > 0 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 func7()
{
int v0; // esi
__int64 v1; // rax
__int64 v2; // rdx
unsigned __int64 result; // rax
__int64 v4; // rdx
__int64 v5; // rcx
int v6; // eax

v0 = lenth;
memset(count, 0, 0x320uLL);
count[200] = 0;
if ( v0 > 0 )
{
v1 = 1LL;
do
{
v2 = num[v1++];
++count[v2];
}
while ( v0 + 1 != v1 );
}
result = (unsigned __int64)&unk_404084;
do
{
*(_DWORD *)result += *(_DWORD *)(result - 4);
result += 4LL;
}
while ( &unk_4043A4 != (_UNKNOWN *)result );
if ( v0 > 0 )
{
v4 = v0;
do
{
v5 = num[v4--];
v6 = count[v5];
::result[v6] = v5;
result = (unsigned int)(v6 - 1);
count[v5] = result;
}
while ( (int)v4 > 0 );
}
return result;
}

original_code:
void COUNTING_SORT()
{
    int i;
    for(i=0;i<=200;i++)
        count[i]=0;
    for(i=1;i<=lenth;i++)
        count[num[i]]=count[num[i]]+1;
    for(i=1;i<=200;i++)
        count[i]=count[i]+count[i-1];
    for(i=lenth;i>=1;i--)
    {
        result[count[num[i]]]=num[i];
        count[num[i]]=count[num[i]]-1;
    }
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rsi
int *v4; // rbp
int v5; // ebx
__int64 v6; // rbx
__int64 v7; // rsi

freopen("in.txt", "r", _bss_start);
v3 = &lenth;
__isoc99_scanf();
if ( lenth > 0 )
{
v4 = (int *)&unk_4043C4;
v5 = 1;
do
{
v3 = v4;
++v5;
__isoc99_scanf();
++v4;
}
while ( lenth >= v5 );
}
COUNTING_SORT("%d", v3);
if ( lenth > 0 )
{
v6 = 1LL;
do
{
v7 = (unsigned int)result[v6++];
printf(" %d", v7);
}
while ( lenth >= (int)v6 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rsi
int *v4; // rbp
int v5; // ebx
__int64 v6; // rbx
__int64 v7; // rsi

freopen("in.txt", "r", _bss_start);
v3 = &lenth;
__isoc99_scanf();
if ( lenth > 0 )
{
v4 = (int *)&unk_4043C4;
v5 = 1;
do
{
v3 = v4;
++v5;
__isoc99_scanf();
++v4;
}
while ( lenth >= v5 );
}
func7("%d", v3);
if ( lenth > 0 )
{
v6 = 1LL;
do
{
v7 = (unsigned int)result[v6++];
printf(" %d", v7);
}
while ( lenth >= (int)v6 );
}
return 0;
}

original_code:
int main()
{
    int i;
    freopen("in.txt","r",stdin);
    scanf("%d",&lenth);
    for(i=1;i<=lenth;i++)
    {
        scanf("%d",&num[i]);
    }
    COUNTING_SORT();
    for(i=1;i<=lenth;i++)
        printf(" %d",result[i]);
    return 0;
}


delete

original_code:
statusEnum delete(keyType key) {
    int i;
    nodeType *update[15 +1], *x;
    x = list.hdr;
    for (i = list.listLevel; i >= 0; i--) {
        while (x->forward[i] != list.hdr
          && (x->forward[i]->key < key))
            x = x->forward[i];
        update[i] = x;
    }
    x = x->forward[0];
    if (x == list.hdr || !(x->key == key))
        return STATUS_KEY_NOT_FOUND;
    for (i = 0; i <= list.listLevel; i++) {
        if (update[i]->forward[i] != x)
            break;
        update[i]->forward[i] = x->forward[i];
    }
    free (x);
    while ((list.listLevel > 0)
    && (list.hdr->forward[list.listLevel] == list.hdr))
        list.listLevel--;
    return STATUS_OK;
}

canonical_original_code:
enum statusEnum delete(int key) {
    int i;
    struct nodeTag *update[-1]; struct nodeTag *x;
    x = list.hdr;
    for (i = list.listLevel; i >= 0; i--) {
        while (x->forward[i] != list.hdr
          && (x->forward[i]->key < key))
            x = x->forward[i];
        update[i] = x;
    }
    x = x->forward[0];
    if (x == list.hdr || !(x->key == key))
        return STATUS_KEY_NOT_FOUND;
    for (i = 0; i <= list.listLevel; i++) {
        if (update[i]->forward[i] != x)
            break;
        update[i]->forward[i] = x->forward[i];
    }
    free (x);
    while ((list.listLevel > 0)
    && (list.hdr->forward[list.listLevel] == list.hdr))
        list.listLevel--;
    return STATUS_OK;
}

variable_types: key int

variable_types: struct nodeTag { int key; struct recType { int stuff; } rec; struct nodeTag *forward[1]; } *[-1]

return_type: enum statusEnum { STATUS_OK=0, STATUS_MEM_EXHAUSTED=1, STATUS_DUPLICATE_KEY=2, STATUS_KEY_NOT_FOUND=3 }

user_defined_types: struct nodeTag { int key; struct recType rec; struct nodeTag *forward[1]; }


find

original_code:
statusEnum find(keyType key, recType *rec) {
    int i;
    nodeType *x = list.hdr;
    for (i = list.listLevel; i >= 0; i--) {
        while (x->forward[i] != list.hdr && (x->forward[i]->key < key))
            x = x->forward[i];
    }
    x = x->forward[0];
    if (x != list.hdr && (x->key == key)) {
        *rec = x->rec;
        return STATUS_OK;
    }
    return STATUS_KEY_NOT_FOUND;
}

canonical_original_code:
enum statusEnum find(int key, struct recType *rec) {
    int i;
    struct nodeTag *x = list.hdr;
    for (i = list.listLevel; i >= 0; i--) {
        while (x->forward[i] != list.hdr && (x->forward[i]->key < key))
            x = x->forward[i];
    }
    x = x->forward[0];
    if (x != list.hdr && (x->key == key)) {
        *rec = x->rec;
        return STATUS_OK;
    }
    return STATUS_KEY_NOT_FOUND;
}

variable_types:
rec
struct recType { int stuff; } *

variable_types: struct nodeTag { int key; struct recType { int stuff; } rec; struct nodeTag *forward[1]; } *

user_defined_types: enum statusEnum { STATUS_OK=0, STATUS_MEM_EXHAUSTED=1, STATUS_DUPLICATE_KEY=2, STATUS_KEY_NOT_FOUND=3 }


initList

decompiled_code:
char *initList()
{
char *v0; // rax
char *v1; // rdx
char *result; // rax

v0 = (char *)malloc(0x88uLL);
list = (__int64)v0;
if ( !v0 )
{
puts("insufficient memory (initList)");
exit(1);
}
v1 = v0;
result = v0 + 8;
do
{
*(_QWORD *)result = v1;
result += 8;
}
while ( result != v1 + 136 );
dword_404098 = 0;
return result;
}

canonical_decompiled_code:
char *func11()
{
char *v0; // rax
char *v1; // rdx
char *result; // rax

v0 = (char *)malloc(0x88uLL);
list = (__int64)v0;
if ( !v0 )
{
puts("insufficient memory (initList)");
exit(1);
}
v1 = v0;
result = v0 + 8;
do
{
*(_QWORD *)result = v1;
result += 8;
}
while ( result != v1 + 136 );
dword_404098 = 0;
return result;
}

original_code:
void initList() {
    int i;
    if ((list.hdr = malloc(sizeof(nodeType) + 15*sizeof(nodeType *))) == 0) {
        printf ("insufficient memory (initList)\n");
        exit(1);
    }
    for (i = 0; i <= 15; i++)
        list.hdr->forward[i] = list.hdr;
    list.listLevel = 0;
}

canonical_original_code:
void initList() {
    int i;
    if ((list.hdr = malloc(sizeof(nodeType) + 15*sizeof(struct nodeTag *))) == 0) {
        printf ("insufficient memory (initList)\n");
        exit(1);
    }
    for (i = 0; i <= 15; i++)
        list.hdr->forward[i] = list.hdr;
    list.listLevel = 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // r12
char *v5; // rax
unsigned int *v6; // rbp
char *v7; // rbx
char *v8; // r13
__int64 j; // rbx
unsigned int v10; // eax
__int64 v11; // rbx
unsigned int v12; // eax
unsigned int *k; // rbx
unsigned int *v14; // rax
unsigned int v15; // eax
__int64 i; // rax

initList(argc, argv, envp);
v3 = (char *)malloc(0x50uLL);
if ( !v3 )
{
fwrite("insufficient memory (rec)\n", 1uLL, 0x1AuLL, stderr);
exit(1);
}
v4 = v3;
v5 = (char *)malloc(0x50uLL);
v6 = (unsigned int *)v5;
if ( !v5 )
{
fwrite("insufficient memory (key)\n", 1uLL, 0x1AuLL, stderr);
exit(1);
}
if ( argc <= 2 )
{
for ( i = 0LL; i != 20; ++i )
v6[i] = i;
printf("seq, %d items\n", 20LL);
}
else
{
v7 = v5;
v8 = v5 + 80;
do
{
v7 += 4;
*((_DWORD *)v7 - 1) = rand();
}
while ( v7 != v8 );
printf("ran, %d items\n", 20LL);
}
for ( j = 0LL; j != 20; ++j )
{
while ( 1 )
{
v10 = insert(v6[j], &v4[j * 4]);
if ( v10 )
break;
if ( ++j == 20 )
goto LABEL_11;
}
printf("pt1: error = %d\n", v10);
}
LABEL_11:
v11 = 19LL;
printf("the number of insert node is %d!\n", (unsigned int)count);
print_skip_list();
do
{
while ( 1 )
{
v12 = find(v6[v11], &v4[v11 * 4]);
if ( v12 )
break;
if ( --v11 == -1 )
goto LABEL_15;
}
--v11;
printf("pt2: error = %d\n", v12);
}
while ( v11 != -1 );
LABEL_15:
for ( k = v6 + 19; ; k = v14 )
{
v15 = delete(*k);
if ( v15 )
break;
v14 = k - 1;
if ( k == v6 )
return 0;
LABEL_17:
;
}
printf("pt3: error = %d\n", v15);
v14 = k - 1;
if ( k != v6 )
goto LABEL_17;
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // r12
char *v5; // rax
unsigned int *v6; // rbp
char *v7; // rbx
char *v8; // r13
__int64 j; // rbx
unsigned int v10; // eax
__int64 v11; // rbx
unsigned int v12; // eax
unsigned int *k; // rbx
unsigned int *v14; // rax
unsigned int v15; // eax
__int64 i; // rax

func11(argc, argv, envp);
v3 = (char *)malloc(0x50uLL);
if ( !v3 )
{
fwrite("insufficient memory (rec)\n", 1uLL, 0x1AuLL, stderr);
exit(1);
}
v4 = v3;
v5 = (char *)malloc(0x50uLL);
v6 = (unsigned int *)v5;
if ( !v5 )
{
fwrite("insufficient memory (key)\n", 1uLL, 0x1AuLL, stderr);
exit(1);
}
if ( argc <= 2 )
{
for ( i = 0LL; i != 20; ++i )
v6[i] = i;
printf("seq, %d items\n", 20LL);
}
else
{
v7 = v5;
v8 = v5 + 80;
do
{
v7 += 4;
*((_DWORD *)v7 - 1) = rand();
}
while ( v7 != v8 );
printf("ran, %d items\n", 20LL);
}
for ( j = 0LL; j != 20; ++j )
{
while ( 1 )
{
v10 = func8(v6[j], &v4[j * 4]);
if ( v10 )
break;
if ( ++j == 20 )
goto LABEL_11;
}
printf("pt1: error = %d\n", v10);
}
LABEL_11:
v11 = 19LL;
printf("the number of insert node is %d!\n", (unsigned int)count);
func7();
do
{
while ( 1 )
{
v12 = func10(v6[v11], &v4[v11 * 4]);
if ( v12 )
break;
if ( --v11 == -1 )
goto LABEL_15;
}
--v11;
printf("pt2: error = %d\n", v12);
}
while ( v11 != -1 );
LABEL_15:
for ( k = v6 + 19; ; k = v14 )
{
v15 = func9(*k);
if ( v15 )
break;
v14 = k - 1;
if ( k == v6 )
return 0;
LABEL_17:
;
}
printf("pt3: error = %d\n", v15);
v14 = k - 1;
if ( k != v6 )
goto LABEL_17;
return 0;
}

original_code:
int main(int argc, char **argv) {
    int i, maxnum, random;
    recType *rec;
    keyType *key;
    statusEnum status;
    maxnum = 20;
    random = argc > 2;
    initList();
    if ((rec = malloc(maxnum * sizeof(recType))) == 0) {
        fprintf (stderr, "insufficient memory (rec)\n");
        exit(1);
    }
    if ((key = malloc(maxnum * sizeof(keyType))) == 0) {
        fprintf (stderr, "insufficient memory (key)\n");
        exit(1);
    }
    if (random) {
        for (i = 0; i < maxnum; i++) key[i] = rand();
        printf ("ran, %d items\n", maxnum);
    } else {
        for (i = 0; i < maxnum; i++) key[i] = i;
        printf ("seq, %d items\n", maxnum);
    }
    for (i = 0; i < maxnum; i++) {
        status = insert(key[i], &rec[i]);
        if (status)
            printf("pt1: error = %d\n", status);
    }
    printf("the number of insert node is %d!\n",count);
    print_skip_list();
    for (i = maxnum-1; i >= 0; i--) {
        status = find(key[i], &rec[i]);
        if (status) printf("pt2: error = %d\n", status);
    }
    for (i = maxnum-1; i >= 0; i--) {
        status = delete(key[i]);
        if (status) printf("pt3: error = %d\n", status);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    int i; int maxnum; int random;
    struct recType *rec;
    int *key;
    enum statusEnum status;
    maxnum = 20;
    random = argc > 2;
    initList();
    if ((rec = malloc(maxnum * sizeof(recType))) == 0) {
        fprintf (stderr, "insufficient memory (rec)\n");
        exit(1);
    }
    if ((key = malloc(maxnum * sizeof(keyType))) == 0) {
        fprintf (stderr, "insufficient memory (key)\n");
        exit(1);
    }
    if (random) {
        for (i = 0; i < maxnum; i++) key[i] = rand();
        printf ("ran, %d items\n", maxnum);
    } else {
        for (i = 0; i < maxnum; i++) key[i] = i;
        printf ("seq, %d items\n", maxnum);
    }
    for (i = 0; i < maxnum; i++) {
        status = insert(key[i], &rec[i]);
        if (status)
            printf("pt1: error = %d\n", status);
    }
    printf("the number of insert node is %d!\n",count);
    print_skip_list();
    for (i = maxnum-1; i >= 0; i--) {
        status = find(key[i], &rec[i]);
        if (status) printf("pt2: error = %d\n", status);
    }
    for (i = maxnum-1; i >= 0; i--) {
        status = delete(key[i]);
        if (status) printf("pt3: error = %d\n", status);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: maxnum int

variable_types: random int

variable_types:
key
int *

variable_types: enum statusEnum { STATUS_OK=0, STATUS_MEM_EXHAUSTED=1, STATUS_DUPLICATE_KEY=2, STATUS_KEY_NOT_FOUND=3 }


decompiled_code:
int print_skip_list()
{
int v0; // er12
unsigned int *v1; // rbx

if ( dword_404098 >= 0 )
{
v0 = 0;
do
{
v1 = *(unsigned int **)(list + 8LL * v0 + 8);
printf("\nlevel[%d]", (unsigned int)v0);
for ( ; *(_QWORD *)&v1[2 * v0 + 2] != list; v1 = *(unsigned int **)&v1[2 * v0 + 2] )
printf("-->%d", *v1);
++v0;
printf("-->%d", *v1);
}
while ( dword_404098 >= v0 );
}
return putchar(10);
}

canonical_decompiled_code:
int func7()
{
int v0; // er12
unsigned int *v1; // rbx

if ( dword_404098 >= 0 )
{
v0 = 0;
do
{
v1 = *(unsigned int **)(list + 8LL * v0 + 8);
printf("\nlevel[%d]", (unsigned int)v0);
for ( ; *(_QWORD *)&v1[2 * v0 + 2] != list; v1 = *(unsigned int **)&v1[2 * v0 + 2] )
printf("-->%d", *v1);
++v0;
printf("-->%d", *v1);
}
while ( dword_404098 >= v0 );
}
return putchar(10);
}

original_code:
void print_skip_list()
{
    int i;
    nodeType *x;
    for (i = 0; i <= list.listLevel; i++) {
        x = list.hdr->forward[i];
        printf("\nlevel[%d]",i);
        while (x->forward[i] != list.hdr){
            printf("-->%d",x->key);
            x = x->forward[i];
        }
        printf("-->%d",x->key);
    }
    printf("\n");
}

canonical_original_code:
void print_skip_list()
{
    int i;
    struct nodeTag *x;
    for (i = 0; i <= list.listLevel; i++) {
        x = list.hdr->forward[i];
        printf("\nlevel[%d]",i);
        while (x->forward[i] != list.hdr){
            printf("-->%d",x->key);
            x = x->forward[i];
        }
        printf("-->%d",x->key);
    }
    printf("\n");
}


insert

original_code:
statusEnum insert(keyType key, recType *rec) {
    int i, newLevel;
    nodeType *update[15 +1];
    nodeType *x;
    count++;
    printf("-insert-%d-\n",key);
    x = list.hdr;
    for (i = list.listLevel; i >= 0; i--) {
        while (x->forward[i] != list.hdr && (x->forward[i]->key < key))
            x = x->forward[i];
        update[i] = x;
    }
    x = x->forward[0];
    if (x != list.hdr && (x->key == key))
        return STATUS_DUPLICATE_KEY;
    for (newLevel = 0;rand() < 2147483647/2 && newLevel < 15;newLevel++);
        if (newLevel > list.listLevel) {
            for (i = list.listLevel + 1; i <= newLevel; i++)
                update[i] = list.hdr;
            list.listLevel = newLevel;
        }
    if ((x = malloc(sizeof(nodeType) + newLevel*sizeof(nodeType *))) == 0)
        return STATUS_MEM_EXHAUSTED;
    x->key = key;
    x->rec = *rec;
    for (i = 0; i <= newLevel; i++) {
        x->forward[i] = update[i]->forward[i];
        update[i]->forward[i] = x;
    }
    return STATUS_OK;
}

canonical_original_code:
enum statusEnum insert(int key, struct recType *rec) {
    int i; int newLevel;
    struct nodeTag *update[-1];
    struct nodeTag *x;
    count++;
    printf("-insert-%d-\n",key);
    x = list.hdr;
    for (i = list.listLevel; i >= 0; i--) {
        while (x->forward[i] != list.hdr && (x->forward[i]->key < key))
            x = x->forward[i];
        update[i] = x;
    }
    x = x->forward[0];
    if (x != list.hdr && (x->key == key))
        return STATUS_DUPLICATE_KEY;
    for (newLevel = 0;rand() < 2147483647/2 && newLevel < 15;newLevel++);
        if (newLevel > list.listLevel) {
            for (i = list.listLevel + 1; i <= newLevel; i++)
                update[i] = list.hdr;
            list.listLevel = newLevel;
        }
    if ((x = malloc(sizeof(nodeType) + newLevel*sizeof(struct nodeTag *))) == 0)
        return STATUS_MEM_EXHAUSTED;
    x->key = key;
    x->rec = *rec;
    for (i = 0; i <= newLevel; i++) {
        x->forward[i] = update[i]->forward[i];
        update[i]->forward[i] = x;
    }
    return STATUS_OK;
}

variable_types: newLevel int


invert

original_code:
char *invert(char *start, char *end)
{
    char tmp, *ptmp = start;
    while (start != ((void *)0) && end != ((void *)0) && start < end)
    {
        tmp = *start;
        *start = *end;
        *end = tmp;
        start ++;
        end --;
    }
    return ptmp;
}

canonical_original_code:
char *invert(char *start, char *end)
{
    char tmp; char *ptmp = start;
    while (start != ((void *)0) && end != ((void *)0) && start < end)
    {
        tmp = *start;
        *start = *end;
        *end = tmp;
        start ++;
        end --;
    }
    return ptmp;
}

variable_types:
start
char *

variable_types:
end
char *

variable_types: tmp char

variable_types:
ptmp
char *

return_type: char *


left

decompiled_code:
char *__fastcall left(char *a1, int a2)
{
int v2; // er10
char *v3; // r10

strlen(a1);
invert(a1, &a1[a2 - 1]);
invert(&a1[a2], &a1[v2 - 1]);
invert(a1, v3);
return a1;
}

canonical_decompiled_code:
char *__fastcall func8(char *a1, int a2)
{
int v2; // er10
char *v3; // r10

strlen(a1);
func7(a1, &a1[a2 - 1]);
func7(&a1[a2], &a1[v2 - 1]);
func7(a1, v3);
return a1;
}

original_code:
char *left(char *s, int pos)
{
    int len = strlen(s);
    invert(s, s + (pos - 1));
    invert(s + pos, s + (len - 1));
    invert(s, s + (len - 1));
    return s;
}

variable_types:
s
char *

variable_types: pos int

variable_types: len int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
char v5[19]; // [rsp+5h] [rbp-13h] BYREF

strcpy(v5, "abcdefghij");
v3 = (const char *)left(v5, 3LL, envp);
puts(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
char v5[19]; // [rsp+5h] [rbp-13h] BYREF

strcpy(v5, "abcdefghij");
v3 = (const char *)func8(v5, 3LL, envp);
puts(v3);
return 0;
}

original_code:
int main()
{
    char s[] = "abcdefghij";
    puts(left(s, 3));
    return 0;
}

variable_types:
s
char []


Exchange

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

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

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

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void Exchange(int *a,int *b)
{
    int temp=*a;
        *a=*b;
        *b=temp;
}

canonical_original_code:
void Exchange(int *a, int *b)
{
    int temp = *a;
        *a=*b;
        *b=temp;
}

variable_types:
a
int *

variable_types:
b
int *

variable_types: temp int


decompiled_code:
__int64 __fastcall Max_HEAPIFY(__int64 a1, int a2)
{
__int64 v3; // rdi
int v4; // er9
int v5; // ecx
int v6; // ecx
__int64 result; // rax

while ( 1 )
{
result = (unsigned int)(2 * a2);
v5 = result + 1;
if ( lenth < (int)result )
break;
v3 = a2;
v4 = *(_DWORD *)(a1 + 4LL * (int)result);
if ( v4 <= *(_DWORD *)(a1 + 4LL * a2) )
break;
if ( lenth >= v5 )
{
if ( v4 >= *(_DWORD *)(a1 + 4LL * v5) )
v5 = 2 * a2;
}
else
{
v5 = 2 * a2;
}
LABEL_5:
if ( v5 == a2 )
return result;
Exchange((_DWORD *)(a1 + 4 * v3), (_DWORD *)(a1 + 4LL * v5));
a2 = v6;
}
if ( lenth >= v5 )
{
v3 = a2;
result = *(unsigned int *)(a1 + 4LL * v5);
if ( *(_DWORD *)(a1 + 4LL * a2) < (int)result )
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
__int64 v3; // rdi
int v4; // er9
int v5; // ecx
int v6; // ecx
__int64 result; // rax

while ( 1 )
{
result = (unsigned int)(2 * a2);
v5 = result + 1;
if ( lenth < (int)result )
break;
v3 = a2;
v4 = *(_DWORD *)(a1 + 4LL * (int)result);
if ( v4 <= *(_DWORD *)(a1 + 4LL * a2) )
break;
if ( lenth >= v5 )
{
if ( v4 >= *(_DWORD *)(a1 + 4LL * v5) )
v5 = 2 * a2;
}
else
{
v5 = 2 * a2;
}
LABEL_5:
if ( v5 == a2 )
return result;
func7((_DWORD *)(a1 + 4 * v3), (_DWORD *)(a1 + 4LL * v5));
a2 = v6;
}
if ( lenth >= v5 )
{
v3 = a2;
result = *(unsigned int *)(a1 + 4LL * v5);
if ( *(_DWORD *)(a1 + 4LL * a2) < (int)result )
goto LABEL_5;
}
return result;
}

original_code:
void Max_HEAPIFY(int *a,int i)
{
    int l=i*2,r=i*2+1,large;
    if(l<=lenth&&a[l]>a[i])
        large=l;
    else
        large=i;
    if(r<=lenth&&a[large]<a[r])
    {
        large=r;
    }
    if(large!=i)
    {
        Exchange(&a[i],&a[large]);
        Max_HEAPIFY(a,large);
    }
}

canonical_original_code:
void Max_HEAPIFY(int *a, int i)
{
    int l = i*2; int r = i*2+1; int large;
    if(l<=lenth&&a[l]>a[i])
        large=l;
    else
        large=i;
    if(r<=lenth&&a[large]<a[r])
    {
        large=r;
    }
    if(large!=i)
    {
        Exchange(&a[i],&a[large]);
        Max_HEAPIFY(a,large);
    }
}

variable_types: i int

variable_types: l int

variable_types: r int

variable_types: large int


decompiled_code:
__int64 __fastcall BUILD_MAX_HEAP(__int64 a1)
{
__int64 result; // rax
int v3; // er10
int v4; // er10

result = (unsigned int)lenth;
v3 = lenth / 2;
if ( lenth > 1 )
{
do
{
result = Max_HEAPIFY(a1, v3);
v3 = v4 - 1;
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
int v3; // er10
int v4; // er10

result = (unsigned int)lenth;
v3 = lenth / 2;
if ( lenth > 1 )
{
do
{
result = func8(a1, v3);
v3 = v4 - 1;
}
while ( v3 );
}
return result;
}

original_code:
void BUILD_MAX_HEAP(int *a)
{
  int i;
  for(i=lenth/2;i>=1;i--)
  {
      Max_HEAPIFY(a,i);
  }
}


HEAPSORT

decompiled_code:
__int64 __fastcall HEAPSORT(__int64 a1)
{
_DWORD *v1; // r11
__int64 result; // rax
int v3; // er10

BUILD_MAX_HEAP(a1);
v1 = (_DWORD *)(a1 + 4);
do
{
Exchange(v1, (_DWORD *)(a1 + 4LL * lenth));
--lenth;
result = Max_HEAPIFY(a1, 1);
}
while ( v3 != 1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
_DWORD *v1; // r11
__int64 result; // rax
int v3; // er10

func9(a1);
v1 = (_DWORD *)(a1 + 4);
do
{
func7(v1, (_DWORD *)(a1 + 4LL * lenth));
--lenth;
result = func8(a1, 1);
}
while ( v3 != 1 );
return result;
}

original_code:
void HEAPSORT(int *a)
{
   int i;
   BUILD_MAX_HEAP(a);
   for(i=10;i>=2;i--)
   {
       Exchange(&a[1],&a[lenth]);
       lenth=lenth-1;
       Max_HEAPIFY(a,1);
   }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v3; // rbx
char *v4; // rbp
char *v5; // rsi
__int64 v6; // rsi

v3 = (unsigned int *)&unk_4040A4;
v4 = (char *)&unk_4040A4;
freopen("in.txt", "r", _bss_start);
do
{
v5 = v4;
v4 += 4;
__isoc99_scanf();
}
while ( v4 != (char *)&unk_4040CC );
lenth = 10;
HEAPSORT(&num, v5);
do
{
v6 = *v3++;
printf("%d ", v6);
}
while ( v3 != (unsigned int *)&unk_4040CC );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v3; // rbx
char *v4; // rbp
char *v5; // rsi
__int64 v6; // rsi

v3 = (unsigned int *)&unk_4040A4;
v4 = (char *)&unk_4040A4;
freopen("in.txt", "r", _bss_start);
do
{
v5 = v4;
v4 += 4;
__isoc99_scanf();
}
while ( v4 != (char *)&unk_4040CC );
lenth = 10;
func10(&num, v5);
do
{
v6 = *v3++;
printf("%d ", v6);
}
while ( v3 != (unsigned int *)&unk_4040CC );
return 0;
}

original_code:
int main()
{
    int i,j;
    freopen("in.txt","r",stdin);
    for(i=1;i<=10;i++)
    {
        scanf("%d",&num[i]);
    }
    lenth=10;
    HEAPSORT(num);
    for(i=1;i<=10;i++)
        printf("%d ",num[i]);
    return 0;
}

canonical_original_code:
int main()
{
    int i; int j;
    freopen("in.txt","r",stdin);
    for(i=1;i<=10;i++)
    {
        scanf("%d",&num[i]);
    }
    lenth=10;
    HEAPSORT(num);
    for(i=1;i<=10;i++)
        printf("%d ",num[i]);
    return 0;
}

variable_types: j int