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

result = 0LL;
if ( *a3 <= *(_DWORD *)(a2 + 36) )
{
if ( *(_DWORD *)a2 )
str_copy(a1, a2 + 8);
else
str_printf(a1, *(_QWORD *)(a2 + 8));
*a3 += *(_DWORD *)(a2 + 40);
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( *a3 <= *(_DWORD *)(a2 + 36) )
{
if ( *(_DWORD *)a2 )
str_copy(a1, a2 + 8);
else
str_printf(a1, *(_QWORD *)(a2 + 8));
*a3 += *(_DWORD *)(a2 + 40);
result = 1LL;
}
return result;
}

original_code:
int
get_batch_filename(str_t sname, struct spectra_lst *batch, int *iter)
{
    if(*iter > batch->stop) {
        return 0;
    }
    if(batch->single_file) {
        str_copy(sname, batch->name);
    } else {
        str_printf(sname, ((const char *) (batch->name)->heap), *iter);
    }
    *iter += batch->stride;
    return 1;
}

canonical_original_code:
int get_batch_filename(struct _str sname[1], struct spectra_lst *batch, int *iter)
{
    if(*iter > batch->stop) {
        return 0;
    }
    if(batch->single_file) {
        str_copy(sname, batch->name);
    } else {
        str_printf(sname, ((char *) (batch->name)->heap), *iter);
    }
    *iter += batch->stride;
    return 1;
}

variable_types: struct spectra_lst { int single_file; struct _str name[1]; int start; int stride; int length; } *

variable_types:
iter
int *


repo: franko/regress-pro

decompiled_code:
char *__fastcall remove_filename_extension(const char **a1)
{
const char *v1; // rbx
char *result; // rax

v1 = *a1;
result = strrchr(*a1, 46);
if ( result )
result = (char *)str_trunc(a1, (unsigned int)((_DWORD)result - (_DWORD)v1));
return result;
}

canonical_decompiled_code:
char *__fastcall func0(const char **a1)
{
const char *v1; // rbx
char *result; // rax

v1 = *a1;
result = strrchr(*a1, 46);
if ( result )
result = (char *)str_trunc(a1, (unsigned int)((_DWORD)result - (_DWORD)v1));
return result;
}

original_code:
static void
remove_filename_extension(str_t name)
{
    const char *base = ((const char *) (name)->heap);
    const char *p = strrchr(base, '.');
    if (p) {
        int len = p - base;
        str_trunc(name, len);
    }
}

canonical_original_code:
static void remove_filename_extension(struct _str name[1])
{
    char *base = ((const char *) (name)->heap);
    char *p = strrchr(base, '.');
    if (p) {
        int len = p - base;
        str_trunc(name, len);
    }
}

variable_types: struct _str { char *heap; unsigned long size; unsigned long length; } [1]

variable_types:
base
char *

variable_types:
p
char *

variable_types: len int

return_type: void


decompiled_code:
__int64 __fastcall write_library_id(__int64 a1, const char *a2)
{
writer_printf(a1, "library \"%s\"", a2);
writer_newline(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
writer_printf(a1, "library \"%s\"", a2);
writer_newline(a1);
return 0LL;
}

original_code:
static int
write_library_id(writer_t *w, const char *id)
{
    writer_printf(w, "library \"%s\"", id);
    writer_newline(w);
    return 0;
}

canonical_original_code:
static int write_library_id(struct _writer *w, char *id)
{
    writer_printf(w, "library \"%s\"", id);
    writer_newline(w);
    return 0;
}

variable_types: struct _writer { struct _str { char *heap; unsigned long size; unsigned long length; } text[1]; int indent; int single_line; int new_line; } *

variable_types:
id
char *

return_type: int

user_defined_types: struct _writer { struct _str text[1]; int indent; int single_line; int new_line; }


decompiled_code:
__int64 __fastcall set_range(float *a1, double a2, double a3)
{
int v3; // eax
float v4; // xmm2_4
float v5; // xmm2_4
__int64 result; // rax
float v7; // xmm1_4

v3 = *(_DWORD *)a1;
v4 = a2;
a1[1] = v4;
v5 = a3;
result = (unsigned int)(v3 - 1);
a1[2] = v5;
v7 = (a3 - a2) / (double)(int)result;
a1[3] = v7;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(float *a1, double a2, double a3)
{
int v3; // eax
float v4; // xmm2_4
float v5; // xmm2_4
__int64 result; // rax
float v7; // xmm1_4

v3 = *(_DWORD *)a1;
v4 = a2;
a1[1] = v4;
v5 = a3;
result = (unsigned int)(v3 - 1);
a1[2] = v5;
v7 = (a3 - a2) / (double)(int)result;
a1[3] = v7;
return result;
}

original_code:
static void
set_range(struct disp_table dt[], double lmin, double lmax)
{
    dt->lambda_min = lmin;
    dt->lambda_max = lmax;
    dt->lambda_stride = (lmax - lmin) / (dt->points_number - 1);
}

variable_types: struct disp_table { int points_number; float lambda_min; float lambda_stride; struct data_table { int rows; int columns; int ref_count; float heap[1]; } *table_ref; } []

variable_types: lmin double

variable_types: lmax double

user_defined_types: struct disp_table { int points_number; float lambda_min; float lambda_stride; struct data_table *table_ref; }


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

*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 4) = 0LL;
result = data_table_new(a2, 2LL);
*(_QWORD *)(a1 + 16) = result;
return result;
}

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

*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 4) = 0LL;
result = data_table_new(a2, 2LL);
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void
disp_table_init(struct disp_table dt[], int points)
{
    dt->points_number = points;
    dt->lambda_min = 0.0;
    dt->lambda_max = 0.0;
    dt->table_ref = data_table_new(points, 2 );
}

variable_types: points int

user_defined_types: struct data_table { int rows; int columns; int ref_count; float heap[1]; }


decompiled_code:
__int64 __fastcall cauchy_encode_param(__int64 a1, __int64 a2)
{
int v2; // eax
void *v3; // rdx

v2 = *(_DWORD *)(a2 + 12);
v3 = &unk_451;
if ( v2 >= 3 )
v3 = &unk_453;
return str_printf(a1, "%s%i", v3, (unsigned int)(v2 % 3));
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
int v2; // eax
void *v3; // rdx

v2 = *(_DWORD *)(a2 + 12);
v3 = &unk_451;
if ( v2 >= 3 )
v3 = &unk_453;
return str_printf(a1, "%s%i", v3, (unsigned int)(v2 % 3));
}

original_code:
void
cauchy_encode_param(str_t param, const fit_param_t *fp)
{
    int nb = fp->param_nb;
    str_printf(param, "%s%i", (nb < 3 ? "N" : "K"), nb % 3);
}

canonical_original_code:
void cauchy_encode_param(struct _str param[1], struct fit_param_t *fp)
{
    int nb = fp->param_nb;
    str_printf(param, "%s%i", (nb < 3 ? "N" : "K"), nb % 3);
}

variable_types: struct fit_param_t { enum params_id { PID_THICKNESS=1, PID_LAYER_N=2, PID_LAYER_INDIPENDENT=3, PID_FIRSTMUL=expr, PID_INVALID=expr } id; int layer_nb; enum disp_type { DISP_UNSET=0, DISP_TABLE=1, DISP_SAMPLE_TABLE=2, DISP_CAUCHY=3, DISP_HO=4, DISP_LOOKUP=5, DISP_BRUGGEMAN=6, DISP_FB=7, DISP_TAUC_LORENTZ=8, DISP_END_OF_TABLE=9 } model_id; int param_nb; } *

variable_types: nb int

user_defined_types: struct _str { char *heap; unsigned long size; unsigned long length; }

user_defined_types: struct fit_param_t { enum params_id id; int layer_nb; enum disp_type model_id; int param_nb; }


original_code:
int *
minsampling_stepper(struct step_data *info, int idx, int idx_red)
{
    int *map = ((void *)0);
    int j;
    for(j = idx + 2; j < info->idx_max; j++) {
        float pa = ((info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[j]) + (1) : (info->table)->table->columns * ((info->table)->idx_start + (j)) + (1))] - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (1) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (1))]) / ((info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[j]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (j)) + (0))] - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (0))]);
        float pb = ((info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[j]) + (2) : (info->table)->table->columns * ((info->table)->idx_start + (j)) + (2))] - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (2) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (2))]) / ((info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[j]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (j)) + (0))] - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (0))]);
        int k;
        for(k = idx+1; k < j; k++) {
            float yint;
            float dela, delb;
            yint = (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (1) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (1))] + ((info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[k]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (k)) + (0))] - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (0))]) * pa;
            dela = yint - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[k]) + (1) : (info->table)->table->columns * ((info->table)->idx_start + (k)) + (1))];
            yint = (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (2) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (2))] + ((info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[k]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (k)) + (0))] - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (0))]) * pb;
            delb = yint - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[k]) + (2) : (info->table)->table->columns * ((info->table)->idx_start + (k)) + (2))];
            if(dela > info->epsilon || dela < - info->epsilon) {
                break;
            }
            if(delb > info->epsilon || delb < - info->epsilon) {
                break;
            }
        }
        if(k == j) {
            continue;
        }
        map = minsampling_stepper(info, j - 1, idx_red + 1);
        map[idx_red] = j - 1;
        return map;
    }
    info->size = idx_red + 1;
    map = emalloc((idx_red + 1) * sizeof(int));
    map[idx_red] = info->idx_max - 1;
    return map;
}

canonical_original_code:
int *minsampling_stepper(struct step_data *info, int idx, int idx_red)
{
    int *map = ((void *)0);
    int j;
    for(j = idx + 2; j < info->idx_max; j++) {
        float pa = ((info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[j]) + (1) : (info->table)->table->columns * ((info->table)->idx_start + (j)) + (1))] - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (1) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (1))]) / ((info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[j]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (j)) + (0))] - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (0))]);
        float pb = ((info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[j]) + (2) : (info->table)->table->columns * ((info->table)->idx_start + (j)) + (2))] - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (2) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (2))]) / ((info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[j]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (j)) + (0))] - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (0))]);
        int k;
        for(k = idx+1; k < j; k++) {
            float yint;
            float dela; float delb;
            yint = (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (1) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (1))] + ((info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[k]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (k)) + (0))] - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (0))]) * pa;
            dela = yint - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[k]) + (1) : (info->table)->table->columns * ((info->table)->idx_start + (k)) + (1))];
            yint = (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (2) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (2))] + ((info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[k]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (k)) + (0))] - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[idx]) + (0) : (info->table)->table->columns * ((info->table)->idx_start + (idx)) + (0))]) * pb;
            delb = yint - (info->table)->table->heap[(info->table->map ? (info->table)->table->columns * ((info->table)->idx_start + (info->table)->map[k]) + (2) : (info->table)->table->columns * ((info->table)->idx_start + (k)) + (2))];
            if(dela > info->epsilon || dela < - info->epsilon) {
                break;
            }
            if(delb > info->epsilon || delb < - info->epsilon) {
                break;
            }
        }
        if(k == j) {
            continue;
        }
        map = minsampling_stepper(info, j - 1, idx_red + 1);
        map[idx_red] = j - 1;
        return map;
    }
    info->size = idx_red + 1;
    map = emalloc((idx_red + 1) * sizeof(int));
    map[idx_red] = info->idx_max - 1;
    return map;
}

variable_types: struct step_data { struct data_view { int rows; int columns; int idx_start; int idx_end; int *map; struct data_table { int rows; int columns; int ref_count; float heap[1]; } *table; } *table; float epsilon; int size; int idx_max; } *

variable_types: idx int

variable_types:
map
int *

variable_types: j int

variable_types: pa float

variable_types: pb float

variable_types: k int

variable_types: yint float

variable_types: dela float

variable_types: delb float

return_type: int *

user_defined_types: struct step_data { struct data_view *table; float epsilon; int size; int idx_max; }

user_defined_types: struct data_view { int rows; int columns; int idx_start; int idx_end; int *map; struct data_table *table; }


decompiled_code:
__int64 __fastcall elliss_sample_minimize(__int64 a1, double a2, double a3, double a4)
{
int v4; // eax
int v5; // esi
_DWORD *v6; // rax
__int64 v8; // [rsp+0h] [rbp-28h] BYREF
int v9; // [rsp+8h] [rbp-20h]
unsigned int v10; // [rsp+Ch] [rbp-1Ch]
int v11; // [rsp+10h] [rbp-18h]

v4 = *(_DWORD *)(a1 + 32);
v5 = *(_DWORD *)(a1 + 40);
v8 = a1 + 32;
v9 = LODWORD(a2);
v11 = v4;
v6 = (_DWORD *)minsampling_stepper((unsigned int *)&v8, v5, 1, a2, a3, a4);
*v6 = 0;
return data_view_set_map(a1 + 32, v10, v6);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, double a2, double a3, double a4)
{
int v4; // eax
int v5; // esi
_DWORD *v6; // rax
__int64 v8; // [rsp+0h] [rbp-28h] BYREF
int v9; // [rsp+8h] [rbp-20h]
unsigned int v10; // [rsp+Ch] [rbp-1Ch]
int v11; // [rsp+10h] [rbp-18h]

v4 = *(_DWORD *)(a1 + 32);
v5 = *(_DWORD *)(a1 + 40);
v8 = a1 + 32;
v9 = LODWORD(a2);
v11 = v4;
v6 = (_DWORD *)func0((unsigned int *)&v8, v5, 1, a2, a3, a4);
*v6 = 0;
return data_view_set_map(a1 + 32, v10, v6);
}

original_code:
void
elliss_sample_minimize(struct spectrum *s, float dlmt)
{
    struct step_data info[1];
    int *map;
    info->idx_max = s->table->rows;
    info->table = s->table;
    info->epsilon = dlmt;
    map = minsampling_stepper(info, s->table->idx_start, 1);
    map[0] = 0;
    data_view_set_map(s->table, info->size, map);
}

variable_types: struct spectrum { struct system_config { enum system_kind { SYSTEM_UNDEFINED=0, SYSTEM_REFLECTOMETER=1, SYSTEM_ELLISS_AB=2, SYSTEM_ELLISS_PSIDEL=3, SYSTEM_EXCEED_VALUE=4 } system; double aoi; double analyzer; double numap; } config; struct data_view { int rows; int columns; int idx_start; int idx_end; int *map; struct data_table { int rows; int columns; int ref_count; float heap[1]; } *table; } table[1]; } *

variable_types: dlmt float

variable_types: struct step_data { struct data_view { int rows; int columns; int idx_start; int idx_end; int *map; struct data_table { int rows; int columns; int ref_count; float heap[1]; } *table; } *table; float epsilon; int size; int idx_max; } [1]

user_defined_types: struct spectrum { struct system_config config; struct data_view table[1]; }

user_defined_types: struct system_config { enum system_kind system; double aoi; double analyzer; double numap; }


decompiled_code:
void __fastcall rc_matrix_ref(__int64 a1)
{
++*(_DWORD *)(a1 + 48);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
++*(_DWORD *)(a1 + 48);
}

original_code:
void rc_matrix_ref(rc_matrix *m)
{
    m->ref_count++;
}

canonical_original_code:
void rc_matrix_ref(struct _rc_matrix *m)
{
    m->ref_count++;
}

variable_types: struct _rc_matrix { struct _gsl_matrix_view { struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } matrix; } view; int ref_count; double data[1]; } *

user_defined_types: struct _rc_matrix { struct _gsl_matrix_view view; int ref_count; double data[1]; }

user_defined_types: struct _gsl_matrix_view { struct gsl_matrix matrix; }

user_defined_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; }


decompiled_code:
void __fastcall rc_matrix_unref(_DWORD *a1)
{
if ( a1[12] - 1 <= 0 )
free(a1);
else
--a1[12];
}

canonical_decompiled_code:
void __fastcall func2(_DWORD *a1)
{
if ( a1[12] - 1 <= 0 )
free(a1);
else
--a1[12];
}

original_code:
void rc_matrix_unref(rc_matrix *m)
{
    m->ref_count--;
    if (m->ref_count <= 0) {
        free(m);
    }
}

canonical_original_code:
void rc_matrix_unref(struct _rc_matrix *m)
{
    m->ref_count--;
    if (m->ref_count <= 0) {
        free(m);
    }
}

user_defined_types: struct gsl_block_struct { unsigned long size; double *data; }


decompiled_code:
__int64 __fastcall rc_matrix_write(__int64 a1, _QWORD *a2, int a3, double a4)
{
__int64 v5; // rbx
int v6; // er15
__int64 v7; // r12
__int64 v8; // rbx
__int64 v10; // [rsp+8h] [rbp-40h]

v5 = a2[1];
v6 = v5;
if ( !a3 )
LODWORD(v5) = *a2;
if ( a3 )
v6 = *a2;
writer_printf(a1, "%d %d", (unsigned int)v5, (unsigned int)v6);
writer_newline(a1);
if ( (int)v5 > 0 )
{
v7 = 0LL;
v10 = (int)v5;
while ( 1 )
{
if ( v6 > 0 )
{
v8 = 0LL;
while ( 1 )
{
if ( a3 )
gsl_matrix_get(a2, v8, v7);
else
gsl_matrix_get(a2, v7, v8);
++v8;
writer_printf(a1, "%g", a4);
if ( v6 == v8 )
break;
writer_printf(a1, " ");
}
}
if ( v10 == ++v7 )
break;
writer_newline(a1);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2, int a3, double a4)
{
__int64 v5; // rbx
int v6; // er15
__int64 v7; // r12
__int64 v8; // rbx
__int64 v10; // [rsp+8h] [rbp-40h]

v5 = a2[1];
v6 = v5;
if ( !a3 )
LODWORD(v5) = *a2;
if ( a3 )
v6 = *a2;
writer_printf(a1, "%d %d", (unsigned int)v5, (unsigned int)v6);
writer_newline(a1);
if ( (int)v5 > 0 )
{
v7 = 0LL;
v10 = (int)v5;
while ( 1 )
{
if ( v6 > 0 )
{
v8 = 0LL;
while ( 1 )
{
if ( a3 )
gsl_matrix_get(a2, v8, v7);
else
gsl_matrix_get(a2, v7, v8);
++v8;
writer_printf(a1, "%g", a4);
if ( v6 == v8 )
break;
writer_printf(a1, " ");
}
}
if ( v10 == ++v7 )
break;
writer_newline(a1);
}
}
return 0LL;
}

original_code:
int rc_matrix_write(writer_t *w, const rc_matrix *m, enum rc_matrix_mode mode)
{
    const gsl_matrix *mat = &m->view.matrix;
    int rows = (mode == RC_MATRIX_NORMAL ? mat->size1 : mat->size2);
    int cols = (mode == RC_MATRIX_NORMAL ? mat->size2 : mat->size1);
    writer_printf(w, "%d %d", rows, cols);
    writer_newline(w);
    int i, j;
    for (i = 0; i < rows; i++) {
        if (i > 0) {
            writer_newline(w);
        }
        for (j = 0; j < cols; j++) {
            if (j > 0) {
                writer_printf(w, " ");
            }
            double x = mode == RC_MATRIX_NORMAL ? gsl_matrix_get(mat, i, j) : gsl_matrix_get(mat, j, i);
            writer_printf(w, "%g", x);
        }
    }
    return 0;
}

canonical_original_code:
int rc_matrix_write(struct _writer *w, struct _rc_matrix *m, enum rc_matrix_mode mode)
{
    struct gsl_matrix *mat = &m->view.matrix;
    int rows = (mode == RC_MATRIX_NORMAL ? mat->size1 : mat->size2);
    int cols = (mode == RC_MATRIX_NORMAL ? mat->size2 : mat->size1);
    writer_printf(w, "%d %d", rows, cols);
    writer_newline(w);
    int i; int j;
    for (i = 0; i < rows; i++) {
        if (i > 0) {
            writer_newline(w);
        }
        for (j = 0; j < cols; j++) {
            if (j > 0) {
                writer_printf(w, " ");
            }
            double x = mode == RC_MATRIX_NORMAL ? gsl_matrix_get(mat, i, j) : gsl_matrix_get(mat, j, i);
            writer_printf(w, "%g", x);
        }
    }
    return 0;
}

variable_types: struct _writer { struct _str { char *heap; unsigned long size; unsigned long length; } text[1]; int indent; int single_line; int new_line; } *

variable_types: enum rc_matrix_mode { RC_MATRIX_NORMAL=0, RC_MATRIX_TRANSPOSED=1 }

variable_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: rows int

variable_types: cols int

variable_types: i int

variable_types: x double


decompiled_code:
__int64 __fastcall elliss_multifit_f(__int64 a1, __int64 a2, __int64 a3)
{
return elliss_multifit_fdf(a1, a2, a3, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
return func0(a1, a2, a3, 0LL);
}

original_code:
int
elliss_multifit_f(const gsl_vector *x, void *params, gsl_vector * f)
{
    return elliss_multifit_fdf(x, params, f, ((void *)0));
}

canonical_original_code:
int elliss_multifit_f(struct gsl_vector *x, void *params, struct gsl_vector *f)
{
    return elliss_multifit_fdf(x, params, f, ((void *)0));
}

variable_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types:
params
void *

variable_types:
f
struct gsl_vector *

user_defined_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; }


decompiled_code:
__int64 __fastcall elliss_multifit_df(__int64 a1, __int64 a2, __int64 a3)
{
return elliss_multifit_fdf(a1, a2, 0LL, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
return func0(a1, a2, 0LL, a3);
}

original_code:
int
elliss_multifit_df(const gsl_vector *x, void *params, gsl_matrix *jacob)
{
    return elliss_multifit_fdf(x, params, ((void *)0), jacob);
}

canonical_original_code:
int elliss_multifit_df(struct gsl_vector *x, void *params, struct gsl_matrix *jacob)
{
    return elliss_multifit_fdf(x, params, ((void *)0), jacob);
}

variable_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; } *


decompiled_code:
__int64 __fastcall ho_encode_param(__int64 a1, __int64 a2)
{
return str_printf(a1, "%s:%i", ho_param_names[*(_DWORD *)(a2 + 12) % 5]);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
return str_printf(a1, "%s:%i", ho_param_names[*(_DWORD *)(a2 + 12) % 5]);
}

original_code:
void
ho_encode_param(str_t param, const fit_param_t *fp)
{
    int onb = fp->param_nb / 5;
    int pnb = fp->param_nb % 5;
    str_printf(param, "%s:%i", ho_param_names[pnb], onb);
}

canonical_original_code:
void ho_encode_param(struct _str param[1], struct fit_param_t *fp)
{
    int onb = fp->param_nb / 5;
    int pnb = fp->param_nb % 5;
    str_printf(param, "%s:%i", ho_param_names[pnb], onb);
}

variable_types: struct _str { char *heap; unsigned long size; unsigned long length; } [1]

variable_types: struct fit_param_t { enum params_id { PID_THICKNESS=1, PID_LAYER_N=2, PID_LAYER_INDIPENDENT=3, PID_FIRSTMUL=expr, PID_INVALID=expr } id; int layer_nb; enum disp_type { DISP_UNSET=0, DISP_TABLE=1, DISP_SAMPLE_TABLE=2, DISP_CAUCHY=3, DISP_HO=4, DISP_LOOKUP=5, DISP_BRUGGEMAN=6, DISP_FB=7, DISP_TAUC_LORENTZ=8, DISP_END_OF_TABLE=9 } model_id; int param_nb; } *

variable_types: onb int

variable_types: pnb int


decompiled_code:
__int64 __fastcall fit_result_free(__int64 a1)
{
return gsl_vector_free(*(_QWORD *)(a1 + 16));
}

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

original_code:
void
fit_result_free(struct fit_result *r)
{
    gsl_vector_free(r->gsearch_x);
}

variable_types: struct fit_result { double gsearch_chisq; double chisq_threshold; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *gsearch_x; int status; int iter; int interrupted; double chisq; } *

user_defined_types: struct fit_result { double gsearch_chisq; double chisq_threshold; struct gsl_vector *gsearch_x; int status; int iter; int interrupted; double chisq; }


decompiled_code:
__int64 __fastcall fit_result_report(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // edi
const char *v7; // rax

if ( *(double *)a1 >= 0.0 )
{
str_copy_c(a2, "Grid search best point: ");
print_vector(a2, "%.5g", 0.0);
str_printf_add(a2, "With Chi Square: %g. Required threshold was: %g.\n\n", *(double *)a1, *(double *)(a1 + 8));
}
if ( *(_DWORD *)(a1 + 32) )
return str_copy_c(a2, "** Fit interrupted by the user.\n");
v5 = *(_DWORD *)(a1 + 24);
if ( v5 == -2 )
{
str_copy_c(a3, "Error: more iterations needed.");
}
else if ( v5 )
{
v7 = (const char *)gsl_strerror();
str_printf(a3, "Error: %s", v7);
}
else
{
str_trunc(a3, 0LL);
}
return str_printf_add(a2, "Nb of iterations to converge: %i\n", *(unsigned int *)(a1 + 28));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // edi
const char *v7; // rax

if ( *(double *)a1 >= 0.0 )
{
str_copy_c(a2, "Grid search best point: ");
print_vector(a2, "%.5g", 0.0);
str_printf_add(a2, "With Chi Square: %g. Required threshold was: %g.\n\n", *(double *)a1, *(double *)(a1 + 8));
}
if ( *(_DWORD *)(a1 + 32) )
return str_copy_c(a2, "** Fit interrupted by the user.\n");
v5 = *(_DWORD *)(a1 + 24);
if ( v5 == -2 )
{
str_copy_c(a3, "Error: more iterations needed.");
}
else if ( v5 )
{
v7 = (const char *)gsl_strerror();
str_printf(a3, "Error: %s", v7);
}
else
{
str_trunc(a3, 0LL);
}
return str_printf_add(a2, "Nb of iterations to converge: %i\n", *(unsigned int *)(a1 + 28));
}

original_code:
void
fit_result_report(struct fit_result *r, str_ptr analysis, str_ptr error)
{
    if (r->gsearch_chisq >= 0.0) {
        str_copy_c(analysis, "Grid search best point: ");
        print_vector(analysis, "%.5g", r->gsearch_x);
        str_printf_add(analysis, "With Chi Square: %g. Required threshold was: %g.\n\n", r->gsearch_chisq, r->chisq_threshold);
    }
    if (r->interrupted) {
        str_copy_c(analysis, "** Fit interrupted by the user.\n");
        return;
    }
    switch(r->status) {
    case GSL_SUCCESS:
        str_trunc(error, 0);
        break;
    case GSL_CONTINUE:
        str_copy_c(error, "Error: more iterations needed.");
        break;
    default:
        str_printf(error, "Error: %s", gsl_strerror(r->status));
    }
    str_printf_add(analysis, "Nb of iterations to converge: %i\n", r->iter);
}

canonical_original_code:
void fit_result_report(struct fit_result *r, struct _str *analysis, struct _str *error)
{
    if (r->gsearch_chisq >= 0.0) {
        str_copy_c(analysis, "Grid search best point: ");
        print_vector(analysis, "%.5g", r->gsearch_x);
        str_printf_add(analysis, "With Chi Square: %g. Required threshold was: %g.\n\n", r->gsearch_chisq, r->chisq_threshold);
    }
    if (r->interrupted) {
        str_copy_c(analysis, "** Fit interrupted by the user.\n");
        return;
    }
    switch(r->status) {
    case GSL_SUCCESS:
        str_trunc(error, 0);
        break;
    case GSL_CONTINUE:
        str_copy_c(error, "Error: more iterations needed.");
        break;
    default:
        str_printf(error, "Error: %s", gsl_strerror(r->status));
    }
    str_printf_add(analysis, "Nb of iterations to converge: %i\n", r->iter);
}

variable_types: struct _str { char *heap; unsigned long size; unsigned long length; } *

variable_types:
error
struct _str *


decompiled_code:
__int64 __fastcall bruggeman_encode_param(__int64 a1, __int64 a2)
{
return str_printf(a1, "f:%i", *(unsigned int *)(a2 + 12));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return str_printf(a1, "f:%i", *(unsigned int *)(a2 + 12));
}

original_code:
void
bruggeman_encode_param(str_t param, const fit_param_t *fp)
{
    str_printf(param, "f:%i", fp->param_nb);
}

canonical_original_code:
void bruggeman_encode_param(struct _str param[1], struct fit_param_t *fp)
{
    str_printf(param, "f:%i", fp->param_nb);
}

user_defined_types: enum params_id { PID_THICKNESS=1, PID_LAYER_N=2, PID_LAYER_INDIPENDENT=3, PID_FIRSTMUL=expr, PID_INVALID=expr }

user_defined_types: enum disp_type { DISP_UNSET=0, DISP_TABLE=1, DISP_SAMPLE_TABLE=2, DISP_CAUCHY=3, DISP_HO=4, DISP_LOOKUP=5, DISP_BRUGGEMAN=6, DISP_FB=7, DISP_TAUC_LORENTZ=8, DISP_END_OF_TABLE=9 }


interactionEnergy

repo: frankwillmore/ftw-codebase

original_code:
double interactionEnergy(int i,int j)
{
  double dx, dy, dz;
  double r_sq, r6, r12;
  double cutoff_sq = 2.5 * 2.5;
  double energy = 0;
  dx = x[j] - box_x - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  energy *=4;
  return energy;
}

canonical_original_code:
double interactionEnergy(int i, int j)
{
  double dx; double dy; double dz;
  double r_sq; double r6; double r12;
  double cutoff_sq = 2.5 * 2.5;
  double energy = 0;
  dx = x[j] - box_x - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - box_x - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] - box_y - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] - box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  dx = x[j] + box_x - x[i];
  dy = y[j] + box_y - y[i];
  dz = z[j] + box_z - z[i];
  r_sq = dx*dx + dy*dy + dz*dz;
  if (r_sq < cutoff_sq)
  {
    r6 = r_sq * r_sq * r_sq;
    r12 = r6 * r6;
    energy += (1/r12 - 1/r6 + psi_shift);
  }
  energy *=4;
  return energy;
}

variable_types: j int

variable_types: dx double

variable_types: dy double

variable_types: dz double

variable_types: energy double

return_type: double


calculateSystemEnergy

decompiled_code:
double calculateSystemEnergy()
{
int v0; // ecx
int v1; // edx
int v2; // er8
bool v3; // zf
int v4; // eax
double v6; // [rsp+0h] [rbp-8h]

v0 = number_of_molecules;
if ( number_of_molecules <= 0 )
return 0.0;
v1 = 0;
v2 = 1;
v6 = 0.0;
v3 = number_of_molecules == 1;
if ( number_of_molecules <= 1 )
goto LABEL_6;
LABEL_3:
v4 = v2;
do
v6 = interactionEnergy(v1, v4) + v6;
while ( v4 != v0 );
do
{
v1 = v2++;
v3 = v2 == v0;
if ( v2 < v0 )
goto LABEL_3;
LABEL_6:
;
}
while ( !v3 );
return v6;
}

canonical_decompiled_code:
double func1()
{
int v0; // ecx
int v1; // edx
int v2; // er8
bool v3; // zf
int v4; // eax
double v6; // [rsp+0h] [rbp-8h]

v0 = number_of_molecules;
if ( number_of_molecules <= 0 )
return 0.0;
v1 = 0;
v2 = 1;
v6 = 0.0;
v3 = number_of_molecules == 1;
if ( number_of_molecules <= 1 )
goto LABEL_6;
LABEL_3:
v4 = v2;
do
v6 = func0(v1, v4) + v6;
while ( v4 != v0 );
do
{
v1 = v2++;
v3 = v2 == v0;
if ( v2 < v0 )
goto LABEL_3;
LABEL_6:
;
}
while ( !v3 );
return v6;
}

original_code:
double calculateSystemEnergy()
{
  int i, j;
  double total_energy = 0;
  for (i=0; i<number_of_molecules; i++)
    for (j=i+1; j<number_of_molecules; j++)
    {
      total_energy = total_energy + interactionEnergy(i,j);
    }
  return (total_energy);
}

canonical_original_code:
double calculateSystemEnergy()
{
  int i; int j;
  double total_energy = 0;
  for (i=0; i<number_of_molecules; i++)
    for (j=i+1; j<number_of_molecules; j++)
    {
      total_energy = total_energy + interactionEnergy(i,j);
    }
  return (total_energy);
}

variable_types: i int


checkForWindowEvent

decompiled_code:
int checkForWindowEvent()
{
int result; // eax

result = XCheckMaskEvent(dpy, 32772LL, &event);
if ( result )
{
if ( event.type == 4 )
{
XFreeGC(dpy, context);
XCloseDisplay(dpy);
exit(0);
}
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

result = XCheckMaskEvent(dpy, 32772LL, &event);
if ( result )
{
if ( event.type == 4 )
{
XFreeGC(dpy, context);
XCloseDisplay(dpy);
exit(0);
}
}
return result;
}

original_code:
void checkForWindowEvent()
{
  int rstat;
  rstat = XCheckMaskEvent(dpy, (1L<<15) | (1L<<2), &event);
  if (rstat&&(event.type == 4))
  {
    XFreeGC(dpy, context);
    XCloseDisplay(dpy);
    exit(0);
  }
}

variable_types: rstat int


initializeDisplay

decompiled_code:
int initializeDisplay()
{
Display *v0; // rdi
int result; // eax

wsize_x = (int)(box_x * (double)particle_scale);
wsize_y = (int)(box_y * (double)particle_scale);
wsize_z = (int)((double)particle_scale * box_z);
z_rank = (__int64)malloc(4LL * number_of_molecules);
x_rank = (__int64)malloc(4LL * number_of_molecules);
dpy = XOpenDisplay(display);
v0 = dpy;
if ( !dpy )
{
puts("Can't open the display.");
v0 = dpy;
}
window = XCreateSimpleWindow(v0, v0->screens[(__int64)v0->default_screen].root, 0, 0, wsize_x, wsize_y, 0, 0LL, 0LL);
XSelectInput(dpy, window, 163852LL);
XMapWindow(dpy, window);
context = XCreateGC(dpy, window, 0xCuLL, &gcvalues);
XStoreName(dpy, window, display_name_1);
XSetIconName(dpy, window, display_name_2);
if ( side_view )
{
window2 = XCreateSimpleWindow(
dpy,
dpy->screens[(__int64)dpy->default_screen].root,
wsize_x,
0,
wsize_z,
wsize_y,
0,
0LL,
0LL);
XSelectInput(dpy, window2, 163852LL);
XMapWindow(dpy, window2);
context2 = XCreateGC(dpy, window2, 0xCuLL, &gcvalues);
XStoreName(dpy, window2, display_name_2);
XSetIconName(dpy, window2, display_name_2);
}
result = checkForWindowEvent();
color_shift = 0LL;
*(&color_shift + 1) = 1LL;
*(&color_shift + 2) = 256LL;
*(&color_shift + 3) = 0x10000LL;
return result;
}

canonical_decompiled_code:
int func1()
{
Display *v0; // rdi
int result; // eax

wsize_x = (int)(box_x * (double)particle_scale);
wsize_y = (int)(box_y * (double)particle_scale);
wsize_z = (int)((double)particle_scale * box_z);
z_rank = (__int64)malloc(4LL * number_of_molecules);
x_rank = (__int64)malloc(4LL * number_of_molecules);
dpy = XOpenDisplay(display);
v0 = dpy;
if ( !dpy )
{
puts("Can't open the display.");
v0 = dpy;
}
window = XCreateSimpleWindow(v0, v0->screens[(__int64)v0->default_screen].root, 0, 0, wsize_x, wsize_y, 0, 0LL, 0LL);
XSelectInput(dpy, window, 163852LL);
XMapWindow(dpy, window);
context = XCreateGC(dpy, window, 0xCuLL, &gcvalues);
XStoreName(dpy, window, display_name_1);
XSetIconName(dpy, window, display_name_2);
if ( side_view )
{
window2 = XCreateSimpleWindow(
dpy,
dpy->screens[(__int64)dpy->default_screen].root,
wsize_x,
0,
wsize_z,
wsize_y,
0,
0LL,
0LL);
XSelectInput(dpy, window2, 163852LL);
XMapWindow(dpy, window2);
context2 = XCreateGC(dpy, window2, 0xCuLL, &gcvalues);
XStoreName(dpy, window2, display_name_2);
XSetIconName(dpy, window2, display_name_2);
}
result = func0();
color_shift = 0LL;
*(&color_shift + 1) = 1LL;
*(&color_shift + 2) = 256LL;
*(&color_shift + 3) = 0x10000LL;
return result;
}

original_code:
void initializeDisplay()
{
  wsize_x = (int)(particle_scale * box_x);
  wsize_y = (int)(particle_scale * box_y);
  wsize_z = (int)(particle_scale * box_z);
  z_rank = (int*)malloc(sizeof(int) * number_of_molecules);
  x_rank = (int*)malloc(sizeof(int) * number_of_molecules);
  dpy = XOpenDisplay(display);
  if (dpy == ((void *)0)) printf("Can't open the display.\n");
  window = XCreateSimpleWindow(dpy, ((&((_XPrivDisplay)(dpy))->screens[(((_XPrivDisplay)(dpy))->default_screen)])->root), 0, 0, wsize_x, wsize_y, 0,0,0);
  XSelectInput(dpy, window, ((1L<<17)|(1L<<15)|(1L<<2)|(1L<<3)));
  XMapWindow(dpy, window);
  context = XCreateGC(dpy, window, (1L<<2) | (1L<<3), &gcvalues);
  XStoreName(dpy, window, display_name_1);
  XSetIconName(dpy, window, display_name_2);
  if (side_view)
  {
    window2 = XCreateSimpleWindow(dpy, ((&((_XPrivDisplay)(dpy))->screens[(((_XPrivDisplay)(dpy))->default_screen)])->root), wsize_x, 0, wsize_z, wsize_y, 0,0,0);
    XSelectInput(dpy, window2, ((1L<<17)|(1L<<15)|(1L<<2)|(1L<<3)));
    XMapWindow(dpy, window2);
    context2 = XCreateGC(dpy, window2, (1L<<2) | (1L<<3), &gcvalues);
    XStoreName(dpy, window2, display_name_2);
    XSetIconName(dpy, window2, display_name_2);
  }
  checkForWindowEvent();
  color_shift[0] = 0;
  color_shift[1] = 1;
  color_shift[2] = 256;
  color_shift[3] = 65536;
}

canonical_original_code:
void initializeDisplay()
{
  wsize_x = (int)(particle_scale * box_x);
  wsize_y = (int)(particle_scale * box_y);
  wsize_z = (int)(particle_scale * box_z);
  z_rank = (int *)malloc(sizeof(int) * number_of_molecules);
  x_rank = (int *)malloc(sizeof(int) * number_of_molecules);
  dpy = XOpenDisplay(display);
  if (dpy == ((void *)0)) printf("Can't open the display.\n");
  window = XCreateSimpleWindow(dpy, ((&((_XPrivDisplay)(dpy))->screens[(((_XPrivDisplay)(dpy))->default_screen)])->root), 0, 0, wsize_x, wsize_y, 0,0,0);
  XSelectInput(dpy, window, ((1L<<17)|(1L<<15)|(1L<<2)|(1L<<3)));
  XMapWindow(dpy, window);
  context = XCreateGC(dpy, window, (1L<<2) | (1L<<3), &gcvalues);
  XStoreName(dpy, window, display_name_1);
  XSetIconName(dpy, window, display_name_2);
  if (side_view)
  {
    window2 = XCreateSimpleWindow(dpy, ((&((_XPrivDisplay)(dpy))->screens[(((_XPrivDisplay)(dpy))->default_screen)])->root), wsize_x, 0, wsize_z, wsize_y, 0,0,0);
    XSelectInput(dpy, window2, ((1L<<17)|(1L<<15)|(1L<<2)|(1L<<3)));
    XMapWindow(dpy, window2);
    context2 = XCreateGC(dpy, window2, (1L<<2) | (1L<<3), &gcvalues);
    XStoreName(dpy, window2, display_name_2);
    XSetIconName(dpy, window2, display_name_2);
  }
  checkForWindowEvent();
  color_shift[0] = 0;
  color_shift[1] = 1;
  color_shift[2] = 256;
  color_shift[3] = 65536;
}


drawGraphicalRepresentation

decompiled_code:
int drawGraphicalRepresentation()
{
__int64 v0; // rax
__int64 i; // rdx
_XGC *v2; // rsi
Display *v3; // rdi
__int64 v4; // r10
unsigned int v5; // er9
__int64 v6; // r11
int *v7; // rax
__int64 v8; // rsi
__int64 v9; // rdi
double v10; // xmm4_8
__int64 v11; // r13
__int64 j; // xmm2_8
__int64 v13; // rax
double v14; // xmm0_8
double v15; // xmm3_8
unsigned int v16; // ebx
__m128d v17; // xmm1
__m128d v18; // xmm0
int v19; // ebp
__m128d v20; // xmm0
__m128d v21; // xmm3
int v22; // er12
__m128d v23; // xmm3
_XGC *v24; // rsi
Display *v25; // rdi
__int64 v26; // rdx
__int64 v27; // rax
_XGC *v28; // rsi
Display *v29; // rdi
__int64 v30; // r10
unsigned int v31; // er9
__int64 v32; // r11
int *v33; // rax
__int64 v34; // rdi
__int64 v35; // rsi
double v36; // xmm4_8
__int64 v37; // r13
__int64 k; // xmm2_8
__int64 v39; // rax
double v40; // xmm0_8
double v41; // xmm3_8
unsigned int v42; // ebx
__m128d v43; // xmm1
__m128d v44; // xmm0
int v45; // er12
__m128d v46; // xmm0
__m128d v47; // xmm3
int v48; // ebp
__m128d v49; // xmm3
_XGC *v50; // rsi
Display *v51; // rdi
double v53; // [rsp+0h] [rbp-38h]
double v54; // [rsp+0h] [rbp-38h]

v0 = 0LL;
for ( i = z_rank; number_of_molecules > (int)v0; ++v0 )
*(_DWORD *)(i + 4 * v0) = v0;
v2 = context;
v3 = dpy;
gcvalues.foreground = bg_color;
XChangeGC(v3, v2, 4uLL, &gcvalues);
XFillRectangle(dpy, window, context, (int)wsize_x / -2, (int)wsize_y / -2, 2 * wsize_x, 2 * wsize_y);
v4 = z_rank;
v5 = number_of_molecules - 2;
v6 = z_rank + 4;
if ( number_of_molecules <= 0 )
goto LABEL_42;
if ( number_of_molecules != 1 )
{
do
{
v7 = (int *)v4;
do
{
v8 = *v7;
v9 = v7[1];
if ( *((double *)&z + v9) > *((double *)&z + v8) )
{
*v7 = v9;
v7[1] = v8;
}
++v7;
}
while ( (int *)(v6 + 4LL * v5) != v7 );
--v5;
}
while ( v5 != -1 );
}
if ( number_of_molecules <= 0 )
{
LABEL_42:
if ( !side_view )
goto LABEL_41;
goto LABEL_24;
}
v10 = *(double *)&LC2;
v11 = 0LL;
for ( j = LC3; ; j = LC5 )
{
v13 = *(int *)(v4 + 4 * v11);
v14 = *((double *)&d + v13);
v15 = v14 * 0.5;
v16 = (int)(v14 * (double)particle_scale * *(double *)&sfactor);
v17.m128d_f64[0] = (*((double *)&x + v13) - v14 * 0.5) * (double)particle_scale;
if ( v10 > COERCE_DOUBLE(*(_QWORD *)&v17.m128d_f64[0] & j) )
{
v18.m128d_f64[0] = (double)(int)v17.m128d_f64[0];
*(_QWORD *)&v17.m128d_f64[0] = COERCE_UNSIGNED_INT64(v18.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v18, v17) & LC4)) | ~j & *(_QWORD *)&v17.m128d_f64[0];
}
v19 = (int)v17.m128d_f64[0];
v20.m128d_f64[0] = (*((double *)&y + v13) - v15) * (double)particle_scale;
if ( v10 > COERCE_DOUBLE(*(_QWORD *)&v20.m128d_f64[0] & j) )
{
v21.m128d_f64[0] = (double)(int)v20.m128d_f64[0];
*(_QWORD *)&v20.m128d_f64[0] = COERCE_UNSIGNED_INT64(v21.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v21, v20) & LC4)) | ~j & *(_QWORD *)&v20.m128d_f64[0];
}
v22 = (int)v20.m128d_f64[0];
v20.m128d_f64[0] = (double)(fg_color - min_color) * *((double *)&z + v13) / box_z;
if ( v10 > COERCE_DOUBLE(*(_QWORD *)&v20.m128d_f64[0] & j) )
{
v23.m128d_f64[0] = (double)(int)v20.m128d_f64[0];
*(_QWORD *)&v20.m128d_f64[0] = COERCE_UNSIGNED_INT64(v23.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v23, v20) & LC4)) | ~j & *(_QWORD *)&v20.m128d_f64[0];
}
v24 = context;
v25 = dpy;
v53 = v10;
++v11;
gcvalues.foreground = (int)((double)(int)color_shift[*((int *)&c + v13)] * ((double)fg_color - v20.m128d_f64[0]));
XChangeGC(v25, v24, 4uLL, &gcvalues);
XFillArc(dpy, window, context, v19, v22, v16, v16, 0, 23040);
XFillArc(dpy, window, context, v19, v22 + wsize_y, v16, v16, 0, 23040);
XFillArc(dpy, window, context, v19 + wsize_x, v22, v16, v16, 0, 23040);
XFillArc(dpy, window, context, v19 + wsize_x, v22 + wsize_y, v16, v16, 0, 23040);
if ( number_of_molecules <= (int)v11 )
break;
v4 = z_rank;
v10 = v53;
}
if ( side_view )
{
if ( number_of_molecules > 0 )
{
v26 = x_rank;
v27 = 0LL;
do
{
*(_DWORD *)(v26 + 4 * v27) = v27;
++v27;
}
while ( number_of_molecules > (int)v27 );
}
LABEL_24:
v28 = context2;
v29 = dpy;
gcvalues.foreground = bg_color;
XChangeGC(v29, v28, 4uLL, &gcvalues);
XFillRectangle(dpy, window2, context2, (int)wsize_z / -2, (int)wsize_y / -2, 2 * wsize_z, 2 * wsize_y);
v30 = x_rank;
v31 = number_of_molecules - 2;
v32 = x_rank + 4;
if ( number_of_molecules > 0 )
{
if ( number_of_molecules != 1 )
{
do
{
v33 = (int *)v30;
do
{
v34 = *v33;
v35 = v33[1];
if ( *((double *)&x + v34) > *((double *)&x + v35) )
{
*v33 = v35;
v33[1] = v34;
}
++v33;
}
while ( (int *)(v32 + 4LL * v31) != v33 );
--v31;
}
while ( v31 != -1 );
}
if ( number_of_molecules > 0 )
{
v36 = *(double *)&LC2;
v37 = 0LL;
for ( k = LC3; ; k = LC5 )
{
v39 = *(int *)(v30 + 4 * v37);
v40 = *((double *)&d + v39);
v41 = v40 * 0.5;
v42 = (int)(v40 * (double)particle_scale * *(double *)&sfactor);
v43.m128d_f64[0] = (*((double *)&y + v39) - v40 * 0.5) * (double)particle_scale;
if ( v36 > COERCE_DOUBLE(*(_QWORD *)&v43.m128d_f64[0] & k) )
{
v44.m128d_f64[0] = (double)(int)v43.m128d_f64[0];
*(_QWORD *)&v43.m128d_f64[0] = COERCE_UNSIGNED_INT64(v44.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v44, v43) & LC4)) | ~k & *(_QWORD *)&v43.m128d_f64[0];
}
v45 = (int)v43.m128d_f64[0];
v46.m128d_f64[0] = (*((double *)&z + v39) - v41) * (double)particle_scale;
if ( v36 > COERCE_DOUBLE(*(_QWORD *)&v46.m128d_f64[0] & k) )
{
v47.m128d_f64[0] = (double)(int)v46.m128d_f64[0];
*(_QWORD *)&v46.m128d_f64[0] = COERCE_UNSIGNED_INT64(v47.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v47, v46) & LC4)) | ~k & *(_QWORD *)&v46.m128d_f64[0];
}
v48 = (int)v46.m128d_f64[0];
v46.m128d_f64[0] = (double)(fg_color - min_color) * *((double *)&x + v39) / box_x;
if ( v36 > COERCE_DOUBLE(*(_QWORD *)&v46.m128d_f64[0] & k) )
{
v49.m128d_f64[0] = (double)(int)v46.m128d_f64[0];
*(_QWORD *)&v46.m128d_f64[0] = COERCE_UNSIGNED_INT64(v49.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v49, v46) & LC4)) | ~k & *(_QWORD *)&v46.m128d_f64[0];
}
v50 = context2;
v51 = dpy;
v54 = v36;
++v37;
gcvalues.foreground = (int)((double)(int)color_shift[*((int *)&c + v39)]
* (v46.m128d_f64[0] + (double)min_color));
XChangeGC(v51, v50, 4uLL, &gcvalues);
XFillArc(dpy, window2, context2, v48, v45, v42, v42, 0, 23040);
XFillArc(dpy, window2, context2, v48, v45 + wsize_y, v42, v42, 0, 23040);
XFillArc(dpy, window2, context2, v48 + wsize_z, v45, v42, v42, 0, 23040);
XFillArc(dpy, window2, context2, v48 + wsize_z, v45 + wsize_y, v42, v42, 0, 23040);
if ( number_of_molecules <= (int)v37 )
break;
v30 = x_rank;
v36 = v54;
}
}
}
}
LABEL_41:
XFlush(dpy);
return checkForWindowEvent();
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rax
__int64 i; // rdx
_XGC *v2; // rsi
Display *v3; // rdi
__int64 v4; // r10
unsigned int v5; // er9
__int64 v6; // r11
int *v7; // rax
__int64 v8; // rsi
__int64 v9; // rdi
double v10; // xmm4_8
__int64 v11; // r13
__int64 j; // xmm2_8
__int64 v13; // rax
double v14; // xmm0_8
double v15; // xmm3_8
unsigned int v16; // ebx
__m128d v17; // xmm1
__m128d v18; // xmm0
int v19; // ebp
__m128d v20; // xmm0
__m128d v21; // xmm3
int v22; // er12
__m128d v23; // xmm3
_XGC *v24; // rsi
Display *v25; // rdi
__int64 v26; // rdx
__int64 v27; // rax
_XGC *v28; // rsi
Display *v29; // rdi
__int64 v30; // r10
unsigned int v31; // er9
__int64 v32; // r11
int *v33; // rax
__int64 v34; // rdi
__int64 v35; // rsi
double v36; // xmm4_8
__int64 v37; // r13
__int64 k; // xmm2_8
__int64 v39; // rax
double v40; // xmm0_8
double v41; // xmm3_8
unsigned int v42; // ebx
__m128d v43; // xmm1
__m128d v44; // xmm0
int v45; // er12
__m128d v46; // xmm0
__m128d v47; // xmm3
int v48; // ebp
__m128d v49; // xmm3
_XGC *v50; // rsi
Display *v51; // rdi
double v53; // [rsp+0h] [rbp-38h]
double v54; // [rsp+0h] [rbp-38h]

v0 = 0LL;
for ( i = z_rank; number_of_molecules > (int)v0; ++v0 )
*(_DWORD *)(i + 4 * v0) = v0;
v2 = context;
v3 = dpy;
gcvalues.foreground = bg_color;
XChangeGC(v3, v2, 4uLL, &gcvalues);
XFillRectangle(dpy, window, context, (int)wsize_x / -2, (int)wsize_y / -2, 2 * wsize_x, 2 * wsize_y);
v4 = z_rank;
v5 = number_of_molecules - 2;
v6 = z_rank + 4;
if ( number_of_molecules <= 0 )
goto LABEL_42;
if ( number_of_molecules != 1 )
{
do
{
v7 = (int *)v4;
do
{
v8 = *v7;
v9 = v7[1];
if ( *((double *)&z + v9) > *((double *)&z + v8) )
{
*v7 = v9;
v7[1] = v8;
}
++v7;
}
while ( (int *)(v6 + 4LL * v5) != v7 );
--v5;
}
while ( v5 != -1 );
}
if ( number_of_molecules <= 0 )
{
LABEL_42:
if ( !side_view )
goto LABEL_41;
goto LABEL_24;
}
v10 = *(double *)&LC2;
v11 = 0LL;
for ( j = LC3; ; j = LC5 )
{
v13 = *(int *)(v4 + 4 * v11);
v14 = *((double *)&d + v13);
v15 = v14 * 0.5;
v16 = (int)(v14 * (double)particle_scale * *(double *)&sfactor);
v17.m128d_f64[0] = (*((double *)&x + v13) - v14 * 0.5) * (double)particle_scale;
if ( v10 > COERCE_DOUBLE(*(_QWORD *)&v17.m128d_f64[0] & j) )
{
v18.m128d_f64[0] = (double)(int)v17.m128d_f64[0];
*(_QWORD *)&v17.m128d_f64[0] = COERCE_UNSIGNED_INT64(v18.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v18, v17) & LC4)) | ~j & *(_QWORD *)&v17.m128d_f64[0];
}
v19 = (int)v17.m128d_f64[0];
v20.m128d_f64[0] = (*((double *)&y + v13) - v15) * (double)particle_scale;
if ( v10 > COERCE_DOUBLE(*(_QWORD *)&v20.m128d_f64[0] & j) )
{
v21.m128d_f64[0] = (double)(int)v20.m128d_f64[0];
*(_QWORD *)&v20.m128d_f64[0] = COERCE_UNSIGNED_INT64(v21.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v21, v20) & LC4)) | ~j & *(_QWORD *)&v20.m128d_f64[0];
}
v22 = (int)v20.m128d_f64[0];
v20.m128d_f64[0] = (double)(fg_color - min_color) * *((double *)&z + v13) / box_z;
if ( v10 > COERCE_DOUBLE(*(_QWORD *)&v20.m128d_f64[0] & j) )
{
v23.m128d_f64[0] = (double)(int)v20.m128d_f64[0];
*(_QWORD *)&v20.m128d_f64[0] = COERCE_UNSIGNED_INT64(v23.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v23, v20) & LC4)) | ~j & *(_QWORD *)&v20.m128d_f64[0];
}
v24 = context;
v25 = dpy;
v53 = v10;
++v11;
gcvalues.foreground = (int)((double)(int)color_shift[*((int *)&c + v13)] * ((double)fg_color - v20.m128d_f64[0]));
XChangeGC(v25, v24, 4uLL, &gcvalues);
XFillArc(dpy, window, context, v19, v22, v16, v16, 0, 23040);
XFillArc(dpy, window, context, v19, v22 + wsize_y, v16, v16, 0, 23040);
XFillArc(dpy, window, context, v19 + wsize_x, v22, v16, v16, 0, 23040);
XFillArc(dpy, window, context, v19 + wsize_x, v22 + wsize_y, v16, v16, 0, 23040);
if ( number_of_molecules <= (int)v11 )
break;
v4 = z_rank;
v10 = v53;
}
if ( side_view )
{
if ( number_of_molecules > 0 )
{
v26 = x_rank;
v27 = 0LL;
do
{
*(_DWORD *)(v26 + 4 * v27) = v27;
++v27;
}
while ( number_of_molecules > (int)v27 );
}
LABEL_24:
v28 = context2;
v29 = dpy;
gcvalues.foreground = bg_color;
XChangeGC(v29, v28, 4uLL, &gcvalues);
XFillRectangle(dpy, window2, context2, (int)wsize_z / -2, (int)wsize_y / -2, 2 * wsize_z, 2 * wsize_y);
v30 = x_rank;
v31 = number_of_molecules - 2;
v32 = x_rank + 4;
if ( number_of_molecules > 0 )
{
if ( number_of_molecules != 1 )
{
do
{
v33 = (int *)v30;
do
{
v34 = *v33;
v35 = v33[1];
if ( *((double *)&x + v34) > *((double *)&x + v35) )
{
*v33 = v35;
v33[1] = v34;
}
++v33;
}
while ( (int *)(v32 + 4LL * v31) != v33 );
--v31;
}
while ( v31 != -1 );
}
if ( number_of_molecules > 0 )
{
v36 = *(double *)&LC2;
v37 = 0LL;
for ( k = LC3; ; k = LC5 )
{
v39 = *(int *)(v30 + 4 * v37);
v40 = *((double *)&d + v39);
v41 = v40 * 0.5;
v42 = (int)(v40 * (double)particle_scale * *(double *)&sfactor);
v43.m128d_f64[0] = (*((double *)&y + v39) - v40 * 0.5) * (double)particle_scale;
if ( v36 > COERCE_DOUBLE(*(_QWORD *)&v43.m128d_f64[0] & k) )
{
v44.m128d_f64[0] = (double)(int)v43.m128d_f64[0];
*(_QWORD *)&v43.m128d_f64[0] = COERCE_UNSIGNED_INT64(v44.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v44, v43) & LC4)) | ~k & *(_QWORD *)&v43.m128d_f64[0];
}
v45 = (int)v43.m128d_f64[0];
v46.m128d_f64[0] = (*((double *)&z + v39) - v41) * (double)particle_scale;
if ( v36 > COERCE_DOUBLE(*(_QWORD *)&v46.m128d_f64[0] & k) )
{
v47.m128d_f64[0] = (double)(int)v46.m128d_f64[0];
*(_QWORD *)&v46.m128d_f64[0] = COERCE_UNSIGNED_INT64(v47.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v47, v46) & LC4)) | ~k & *(_QWORD *)&v46.m128d_f64[0];
}
v48 = (int)v46.m128d_f64[0];
v46.m128d_f64[0] = (double)(fg_color - min_color) * *((double *)&x + v39) / box_x;
if ( v36 > COERCE_DOUBLE(*(_QWORD *)&v46.m128d_f64[0] & k) )
{
v49.m128d_f64[0] = (double)(int)v46.m128d_f64[0];
*(_QWORD *)&v46.m128d_f64[0] = COERCE_UNSIGNED_INT64(v49.m128d_f64[0] - COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v49, v46) & LC4)) | ~k & *(_QWORD *)&v46.m128d_f64[0];
}
v50 = context2;
v51 = dpy;
v54 = v36;
++v37;
gcvalues.foreground = (int)((double)(int)color_shift[*((int *)&c + v39)]
* (v46.m128d_f64[0] + (double)min_color));
XChangeGC(v51, v50, 4uLL, &gcvalues);
XFillArc(dpy, window2, context2, v48, v45, v42, v42, 0, 23040);
XFillArc(dpy, window2, context2, v48, v45 + wsize_y, v42, v42, 0, 23040);
XFillArc(dpy, window2, context2, v48 + wsize_z, v45, v42, v42, 0, 23040);
XFillArc(dpy, window2, context2, v48 + wsize_z, v45 + wsize_y, v42, v42, 0, 23040);
if ( number_of_molecules <= (int)v37 )
break;
v30 = x_rank;
v36 = v54;
}
}
}
}
LABEL_41:
XFlush(dpy);
return func0();
}

original_code:
void drawGraphicalRepresentation()
{
  int xx, yy, zz;
  int i, j;
  int z_shade, x_shade;
  int temporary;
  int g_diameter;
  for (i=0; i<number_of_molecules; i++) z_rank[i] = i;
  gcvalues.foreground = bg_color;
  XChangeGC(dpy, context, (1L<<2), &gcvalues);
  XFillRectangle(dpy, window, context, -wsize_x/2, -wsize_y/2, wsize_x*2, wsize_y*2);
  for (i=number_of_molecules; i>0; i--)
    for (j=0; j<i-1; j++)
      if (z[z_rank[j]] < z[z_rank[j+1]])
      {
        temporary = z_rank[j];
        z_rank[j] = z_rank[j+1];
        z_rank[j+1] = temporary;
      }
  for(i=0;i<number_of_molecules;i++)
  {
    g_diameter = d[z_rank[i]] * particle_scale * sfactor;
    xx=floor(particle_scale * (x[z_rank[i]] - .5 * d[z_rank[i]]));
    yy=floor(particle_scale * (y[z_rank[i]] - .5 * d[z_rank[i]]));
    z_shade = color_shift[c[z_rank[i]]] * (fg_color - floor((fg_color - min_color) * z[z_rank[i]] / box_z));
    gcvalues.foreground = z_shade;
    XChangeGC(dpy, context, (1L<<2), &gcvalues);
    XFillArc(dpy, window, context, xx, yy, g_diameter, g_diameter, 0, 360*64);
    XFillArc(dpy, window, context, xx, yy + wsize_y, g_diameter, g_diameter, 0, 360*64);
    XFillArc(dpy, window, context, xx + wsize_x, yy, g_diameter, g_diameter, 0, 360*64);
    XFillArc(dpy, window, context, xx + wsize_x, yy + wsize_y, g_diameter, g_diameter, 0, 360*64);
  }
  if (side_view)
  {
    for (i=0; i<number_of_molecules; i++) x_rank[i] = i;
    gcvalues.foreground = bg_color;
    XChangeGC(dpy, context2, (1L<<2), &gcvalues);
    XFillRectangle(dpy, window2, context2, -wsize_z/2, -wsize_y/2, wsize_z*2, wsize_y*2);
    for (i=number_of_molecules; i>0; i--)
      for (j=0; j<i-1; j++)
        if (x[x_rank[j]] > x[x_rank[j+1]])
        {
          temporary = x_rank[j];
          x_rank[j] = x_rank[j+1];
          x_rank[j+1] = temporary;
        }
    for(i=0; i<number_of_molecules;i++)
    {
      g_diameter = d[x_rank[i]] * particle_scale * sfactor;
      yy=floor(particle_scale * (y[x_rank[i]] - .5 * d[x_rank[i]]));
      zz=floor(particle_scale * (z[x_rank[i]] - .5 * d[x_rank[i]]));
      x_shade = color_shift[c[x_rank[i]]] * (min_color + floor((fg_color - min_color) * x[x_rank[i]] / box_x));
      gcvalues.foreground = x_shade;
      XChangeGC(dpy, context2, (1L<<2), &gcvalues);
      XFillArc(dpy, window2, context2, zz, yy, g_diameter, g_diameter, 0, 360*64);
      XFillArc(dpy, window2, context2, zz, yy + wsize_y, g_diameter, g_diameter, 0, 360*64);
      XFillArc(dpy, window2, context2, zz + wsize_z, yy, g_diameter, g_diameter, 0, 360*64);
      XFillArc(dpy, window2, context2, zz + wsize_z, yy + wsize_y, g_diameter, g_diameter, 0, 360*64);
    }
  }
  XFlush(dpy);
  checkForWindowEvent();
}

canonical_original_code:
void drawGraphicalRepresentation()
{
  int xx; int yy; int zz;
  int i; int j;
  int z_shade; int x_shade;
  int temporary;
  int g_diameter;
  for (i=0; i<number_of_molecules; i++) z_rank[i] = i;
  gcvalues.foreground = bg_color;
  XChangeGC(dpy, context, (1L<<2), &gcvalues);
  XFillRectangle(dpy, window, context, -wsize_x/2, -wsize_y/2, wsize_x*2, wsize_y*2);
  for (i=number_of_molecules; i>0; i--)
    for (j=0; j<i-1; j++)
      if (z[z_rank[j]] < z[z_rank[j+1]])
      {
        temporary = z_rank[j];
        z_rank[j] = z_rank[j+1];
        z_rank[j+1] = temporary;
      }
  for(i=0;i<number_of_molecules;i++)
  {
    g_diameter = d[z_rank[i]] * particle_scale * sfactor;
    xx=floor(particle_scale * (x[z_rank[i]] - .5 * d[z_rank[i]]));
    yy=floor(particle_scale * (y[z_rank[i]] - .5 * d[z_rank[i]]));
    z_shade = color_shift[c[z_rank[i]]] * (fg_color - floor((fg_color - min_color) * z[z_rank[i]] / box_z));
    gcvalues.foreground = z_shade;
    XChangeGC(dpy, context, (1L<<2), &gcvalues);
    XFillArc(dpy, window, context, xx, yy, g_diameter, g_diameter, 0, 360*64);
    XFillArc(dpy, window, context, xx, yy + wsize_y, g_diameter, g_diameter, 0, 360*64);
    XFillArc(dpy, window, context, xx + wsize_x, yy, g_diameter, g_diameter, 0, 360*64);
    XFillArc(dpy, window, context, xx + wsize_x, yy + wsize_y, g_diameter, g_diameter, 0, 360*64);
  }
  if (side_view)
  {
    for (i=0; i<number_of_molecules; i++) x_rank[i] = i;
    gcvalues.foreground = bg_color;
    XChangeGC(dpy, context2, (1L<<2), &gcvalues);
    XFillRectangle(dpy, window2, context2, -wsize_z/2, -wsize_y/2, wsize_z*2, wsize_y*2);
    for (i=number_of_molecules; i>0; i--)
      for (j=0; j<i-1; j++)
        if (x[x_rank[j]] > x[x_rank[j+1]])
        {
          temporary = x_rank[j];
          x_rank[j] = x_rank[j+1];
          x_rank[j+1] = temporary;
        }
    for(i=0; i<number_of_molecules;i++)
    {
      g_diameter = d[x_rank[i]] * particle_scale * sfactor;
      yy=floor(particle_scale * (y[x_rank[i]] - .5 * d[x_rank[i]]));
      zz=floor(particle_scale * (z[x_rank[i]] - .5 * d[x_rank[i]]));
      x_shade = color_shift[c[x_rank[i]]] * (min_color + floor((fg_color - min_color) * x[x_rank[i]] / box_x));
      gcvalues.foreground = x_shade;
      XChangeGC(dpy, context2, (1L<<2), &gcvalues);
      XFillArc(dpy, window2, context2, zz, yy, g_diameter, g_diameter, 0, 360*64);
      XFillArc(dpy, window2, context2, zz, yy + wsize_y, g_diameter, g_diameter, 0, 360*64);
      XFillArc(dpy, window2, context2, zz + wsize_z, yy, g_diameter, g_diameter, 0, 360*64);
      XFillArc(dpy, window2, context2, zz + wsize_z, yy + wsize_y, g_diameter, g_diameter, 0, 360*64);
    }
  }
  XFlush(dpy);
  checkForWindowEvent();
}

variable_types: xx int

variable_types: yy int

variable_types: zz int

variable_types: temporary int


repo: franshub/networking

decompiled_code:
__int64 __fastcall prepare_for_server(int *a1, unsigned __int16 a2)
{
int v2; // eax
__int64 v3; // rcx
socklen_t v4; // edx
int v5; // er8
__int64 result; // rax
struct sockaddr v7[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 2, 0);
*a1 = v2;
if ( v2 < 0 )
{
puts("failed to create socket");
result = 0xFFFFFFFFLL;
}
else
{
v7[0].sa_family = 2;
*(_QWORD *)&v7[0].sa_data[6] = 0LL;
*(_QWORD *)&v7[0].sa_data[2] = (unsigned int)_bswap_32_constprop_0(a2, v7, 16LL, v3, (unsigned int)v2);
*(_WORD *)v7[0].sa_data = _bswap_16(a2);
if ( bind(v5, v7, v4) )
{
printf("failed to bind socket to port %d\n", a2);
close(*a1);
result = 0xFFFFFFFFLL;
}
else
{
a1[12] = 0;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1, unsigned __int16 a2)
{
int v2; // eax
__int64 v3; // rcx
socklen_t v4; // edx
int v5; // er8
__int64 result; // rax
struct sockaddr v7[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 2, 0);
*a1 = v2;
if ( v2 < 0 )
{
puts("failed to create socket");
result = 0xFFFFFFFFLL;
}
else
{
v7[0].sa_family = 2;
*(_QWORD *)&v7[0].sa_data[6] = 0LL;
*(_QWORD *)&v7[0].sa_data[2] = (unsigned int)func9(a2, v7, 16LL, v3, (unsigned int)v2);
*(_WORD *)v7[0].sa_data = func7(a2);
if ( bind(v5, v7, v4) )
{
printf("failed to bind socket to port %d\n", a2);
close(*a1);
result = 0xFFFFFFFFLL;
}
else
{
a1[12] = 0;
result = 1LL;
}
}
return result;
}

original_code:
int prepare_for_server(struct control_s *cs,
                       uint16_t port) {
    cs->sock = socket(2, SOCK_DGRAM, 0);
    if (cs->sock < 0) {
        printf("failed to create socket\n");
        return -1;
    }
    struct sockaddr_in addr;
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = 2;
    addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    addr.sin_port = htons(port);
    socklen_t addr_len = sizeof(addr);
    if (bind(cs->sock, (struct sockaddr *) &addr, addr_len) != 0) {
        printf("failed to bind socket to port %d\n", port);
        close(cs->sock);
        return -1;
    }
    cs->has_addr = 0;
    return 1;
}

canonical_original_code:
int prepare_for_server(struct control_s *cs, unsigned short port) {
    cs->sock = socket(2, SOCK_DGRAM, 0);
    if (cs->sock < 0) {
        printf("failed to create socket\n");
        return -1;
    }
    struct sockaddr_in addr;
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = 2;
    addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    addr.sin_port = htons(port);
    unsigned int addr_len = sizeof(addr);
    if (bind(cs->sock, (struct sockaddr *) &addr, addr_len) != 0) {
        printf("failed to bind socket to port %d\n", port);
        close(cs->sock);
        return -1;
    }
    cs->has_addr = 0;
    return 1;
}

variable_types: struct control_s { int sock; int stop_recv; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; int has_addr; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; } *

variable_types:
port
unsigned short

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct control_s { int sock; int stop_recv; union pthread_mutex_t mutex; int has_addr; struct sockaddr_in addr; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // ax
int v4; // eax
unsigned __int16 v6; // ax
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
int arg; // [rsp+10h] [rbp-68h] BYREF
int v9; // [rsp+14h] [rbp-64h]
pthread_mutex_t mutex; // [rsp+18h] [rbp-60h] BYREF

if ( argc > 2 )
{
v6 = atoi(argv[2]);
v4 = prepare_for_client(&arg, argv[1], v6);
}
else
{
if ( argc != 2 )
{
puts("expected a port number (for server operation),");
puts("or an ip address and a port number (for client operation)");
return 0;
}
v3 = atoi(argv[1]);
v4 = prepare_for_server(&arg, v3);
}
if ( !v4 )
return -1;
pthread_mutex_init(&mutex, 0LL);
v9 = 0;
pthread_create(&newthread, 0LL, do_receive, &arg);
do_send(&arg);
v9 = 1;
close(arg);
pthread_join(newthread, 0LL);
pthread_mutex_destroy(&mutex);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // ax
int v4; // eax
unsigned __int16 v6; // ax
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
int arg; // [rsp+10h] [rbp-68h] BYREF
int v9; // [rsp+14h] [rbp-64h]
pthread_mutex_t mutex; // [rsp+18h] [rbp-60h] BYREF

if ( argc > 2 )
{
v6 = atoi(argv[2]);
v4 = func10(&arg, argv[1], v6);
}
else
{
if ( argc != 2 )
{
puts("expected a port number (for server operation),");
puts("or an ip address and a port number (for client operation)");
return 0;
}
v3 = atoi(argv[1]);
v4 = func11(&arg, v3);
}
if ( !v4 )
return -1;
pthread_mutex_init(&mutex, 0LL);
v9 = 0;
pthread_create(&newthread, 0LL, do_receive, &arg);
func12(&arg);
v9 = 1;
close(arg);
pthread_join(newthread, 0LL);
pthread_mutex_destroy(&mutex);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    struct control_s cs;
    int ok = 1;
    int is_server = 0;
    char *ipaddress;
    uint16_t port;
    if (argc >= 3) {
        ipaddress = argv[1];
        port = (uint16_t) atoi(argv[2]);
        ok = prepare_for_client(&cs, ipaddress, port);
    } else if (argc >= 2) {
        port = (uint16_t) atoi(argv[1]);
        ok = prepare_for_server(&cs, port);
    } else {
        printf("expected a port number (for server operation),\n");
        printf("or an ip address and a port number (for client operation)\n");
        return 0;
    }
    if (!ok) {
        return -1;
    }
    pthread_mutex_init(&cs.mutex, ((void *)0));
    pthread_t recv_thread;
    cs.stop_recv = 0;
    pthread_create(&recv_thread, 0, do_receive, (void *) &cs);
    do_send(&cs);
    cs.stop_recv = 1;
    close(cs.sock);
    pthread_join(recv_thread, 0);
    pthread_mutex_destroy(&cs.mutex);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    struct control_s cs;
    int ok = 1;
    int is_server = 0;
    char *ipaddress;
    unsigned short port;
    if (argc >= 3) {
        ipaddress = argv[1];
        port = (unsigned short) atoi(argv[2]);
        ok = prepare_for_client(&cs, ipaddress, port);
    } else if (argc >= 2) {
        port = (unsigned short) atoi(argv[1]);
        ok = prepare_for_server(&cs, port);
    } else {
        printf("expected a port number (for server operation),\n");
        printf("or an ip address and a port number (for client operation)\n");
        return 0;
    }
    if (!ok) {
        return -1;
    }
    pthread_mutex_init(&cs.mutex, ((void *)0));
    unsigned long recv_thread;
    cs.stop_recv = 0;
    pthread_create(&recv_thread, 0, do_receive, (void *) &cs);
    do_send(&cs);
    cs.stop_recv = 1;
    close(cs.sock);
    pthread_join(recv_thread, 0);
    pthread_mutex_destroy(&cs.mutex);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct control_s { int sock; int stop_recv; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; int has_addr; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; }

variable_types: ok int

variable_types:
ipaddress
char *


decompiled_code:
void *__fastcall do_receive(void *a1)
{
pthread_mutex_t *v1; // r13
int v3; // edi
int v4; // ebx
int v5; // ebp
__m128i v6; // xmm0
__int64 v7; // rbx
__int64 v8; // rsi
socklen_t addr_len; // [rsp+Ch] [rbp-13Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-138h] BYREF
char buf[296]; // [rsp+20h] [rbp-128h] BYREF

v1 = (pthread_mutex_t *)((char *)a1 + 8);
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 8));
printf("receiving from socket %d\n", *(unsigned int *)a1);
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 8));
if ( *((_DWORD *)a1 + 1) )
return 0LL;
while ( 1 )
{
v3 = *(_DWORD *)a1;
addr_len = 16;
v4 = recvfrom(v3, buf, 0x100uLL, 0, &addr, &addr_len);
v5 = v4;
if ( v4 < 0 )
break;
pthread_mutex_lock(v1);
v6 = _mm_loadu_si128((const __m128i *)&addr);
*((_DWORD *)a1 + 12) = 1;
*(__m128i *)((char *)a1 + 52) = v6;
if ( v4 == 1 )
{
printf("received %d %s: ", 1LL, "byte");
LABEL_5:
v7 = 0LL;
do
{
if ( v7 )
putchar(32);
v8 = (unsigned __int8)buf[v7++];
printf("%02.2x", v8);
}
while ( v5 > (int)v7 );
goto LABEL_9;
}
printf("received %d %s: ", (unsigned int)v4, "bytes");
if ( v4 )
goto LABEL_5;
LABEL_9:
putchar(10);
pthread_mutex_unlock(v1);
if ( *((_DWORD *)a1 + 1) )
return 0LL;
}
if ( *((_DWORD *)a1 + 1) )
return 0LL;
pthread_mutex_lock(v1);
puts("recvfrom() failed");
pthread_mutex_unlock(v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
pthread_mutex_t *v1; // r13
int v3; // edi
int v4; // ebx
int v5; // ebp
__m128i v6; // xmm0
__int64 v7; // rbx
__int64 v8; // rsi
socklen_t addr_len; // [rsp+Ch] [rbp-13Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-138h] BYREF
char buf[296]; // [rsp+20h] [rbp-128h] BYREF

v1 = (pthread_mutex_t *)((char *)a1 + 8);
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 8));
printf("receiving from socket %d\n", *(unsigned int *)a1);
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 8));
if ( *((_DWORD *)a1 + 1) )
return 0LL;
while ( 1 )
{
v3 = *(_DWORD *)a1;
addr_len = 16;
v4 = recvfrom(v3, buf, 0x100uLL, 0, &addr, &addr_len);
v5 = v4;
if ( v4 < 0 )
break;
pthread_mutex_lock(v1);
v6 = _mm_loadu_si128((const __m128i *)&addr);
*((_DWORD *)a1 + 12) = 1;
*(__m128i *)((char *)a1 + 52) = v6;
if ( v4 == 1 )
{
printf("received %d %s: ", 1LL, "byte");
LABEL_5:
v7 = 0LL;
do
{
if ( v7 )
putchar(32);
v8 = (unsigned __int8)buf[v7++];
printf("%02.2x", v8);
}
while ( v5 > (int)v7 );
goto LABEL_9;
}
printf("received %d %s: ", (unsigned int)v4, "bytes");
if ( v4 )
goto LABEL_5;
LABEL_9:
putchar(10);
pthread_mutex_unlock(v1);
if ( *((_DWORD *)a1 + 1) )
return 0LL;
}
if ( *((_DWORD *)a1 + 1) )
return 0LL;
pthread_mutex_lock(v1);
puts("recvfrom() failed");
pthread_mutex_unlock(v1);
return 0LL;
}

original_code:
void *do_receive(void *arg) {
    struct control_s *cs = (struct control_s *) arg;
    pthread_mutex_lock(&cs->mutex);
    printf("receiving from socket %d\n", cs->sock);
    pthread_mutex_unlock(&cs->mutex);
    unsigned char buf[256];
    struct sockaddr_in remote_addr;
    while (!cs->stop_recv) {
        socklen_t remote_size = (socklen_t) sizeof(remote_addr);
        int nr_recv = recvfrom(cs->sock, buf, sizeof(buf), 0,
                               (struct sockaddr *) &remote_addr,
                               &remote_size);
        if (nr_recv < 0) {
            if (!cs->stop_recv) {
                pthread_mutex_lock(&cs->mutex);
                printf("recvfrom() failed\n");
                pthread_mutex_unlock(&cs->mutex);
            }
            return ((void *)0);
        }
        pthread_mutex_lock(&cs->mutex);
        memcpy(&cs->addr, &remote_addr, sizeof(remote_addr));
        cs->has_addr = 1;
        printf("received %d %s: ", nr_recv, (nr_recv == 1 ? "byte" : "bytes"));
        int i;
        for (i = 0; i < nr_recv; i++) {
            if (i > 0) {
                putchar(' ');
            }
            printf("%02.2x", buf[i]);
        }
        putchar('\n');
        pthread_mutex_unlock(&cs->mutex);
    }
    return ((void *)0);
}

canonical_original_code:
void *do_receive(void *arg) {
    struct control_s *cs = (struct control_s *) arg;
    pthread_mutex_lock(&cs->mutex);
    printf("receiving from socket %d\n", cs->sock);
    pthread_mutex_unlock(&cs->mutex);
    unsigned char buf[256];
    struct sockaddr_in remote_addr;
    while (!cs->stop_recv) {
        unsigned int remote_size = (socklen_t) sizeof(remote_addr);
        int nr_recv = recvfrom(cs->sock, buf, sizeof(buf), 0,
                               (struct sockaddr *) &remote_addr,
                               &remote_size);
        if (nr_recv < 0) {
            if (!cs->stop_recv) {
                pthread_mutex_lock(&cs->mutex);
                printf("recvfrom() failed\n");
                pthread_mutex_unlock(&cs->mutex);
            }
            return ((void *)0);
        }
        pthread_mutex_lock(&cs->mutex);
        memcpy(&cs->addr, &remote_addr, sizeof(remote_addr));
        cs->has_addr = 1;
        printf("received %d %s: ", nr_recv, (nr_recv == 1 ? "byte" : "bytes"));
        int i;
        for (i = 0; i < nr_recv; i++) {
            if (i > 0) {
                putchar(' ');
            }
            printf("%02.2x", buf[i]);
        }
        putchar('\n');
        pthread_mutex_unlock(&cs->mutex);
    }
    return ((void *)0);
}

variable_types:
arg
void *

variable_types:
buf
unsigned char [256]

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

return_type: void *

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall prepare_for_client(__int64 a1, const char *a2, __int16 a3)
{
int v4; // eax
__int16 v5; // ax
int v6; // ecx
__int64 result; // rax

v4 = socket(2, 2, 0);
*(_DWORD *)a1 = v4;
if ( v4 < 0 )
{
puts("failed to create socket");
result = 0LL;
}
else if ( inet_addr(a2) == -1 )
{
printf("failed to parse ip address '%s'\n", a2);
result = 0LL;
}
else
{
*(_QWORD *)(a1 + 60) = 0LL;
*(_WORD *)(a1 + 52) = 2;
v5 = _bswap_16(a3);
*(_DWORD *)(a1 + 56) = v6;
*(_WORD *)(a1 + 54) = v5;
result = 1LL;
*(_DWORD *)(a1 + 48) = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2, __int16 a3)
{
int v4; // eax
__int16 v5; // ax
int v6; // ecx
__int64 result; // rax

v4 = socket(2, 2, 0);
*(_DWORD *)a1 = v4;
if ( v4 < 0 )
{
puts("failed to create socket");
result = 0LL;
}
else if ( inet_addr(a2) == -1 )
{
printf("failed to parse ip address '%s'\n", a2);
result = 0LL;
}
else
{
*(_QWORD *)(a1 + 60) = 0LL;
*(_WORD *)(a1 + 52) = 2;
v5 = func7(a3);
*(_DWORD *)(a1 + 56) = v6;
*(_WORD *)(a1 + 54) = v5;
result = 1LL;
*(_DWORD *)(a1 + 48) = 1;
}
return result;
}

original_code:
int prepare_for_client(struct control_s *cs,
                       char *ipaddress,
                       uint16_t port) {
    cs->sock = socket(2, SOCK_DGRAM, 0);
    if (cs->sock < 0) {
        printf("failed to create socket\n");
        return 0;
    }
    in_addr_t in_addr = inet_addr(ipaddress);
    if (in_addr == (in_addr_t) -1) {
        printf("failed to parse ip address '%s'\n", ipaddress);
        return 0;
    }
    memset(&cs->addr, 0, sizeof(cs->addr));
    cs->addr.sin_family = 2;
    cs->addr.sin_port = htons(port);
    cs->addr.sin_addr.s_addr = in_addr;
    cs->has_addr = 1;
    return 1;
}

canonical_original_code:
int prepare_for_client(struct control_s *cs, char *ipaddress, unsigned short port) {
    cs->sock = socket(2, SOCK_DGRAM, 0);
    if (cs->sock < 0) {
        printf("failed to create socket\n");
        return 0;
    }
    unsigned int in_addr = inet_addr(ipaddress);
    if (in_addr == (in_addr_t) -1) {
        printf("failed to parse ip address '%s'\n", ipaddress);
        return 0;
    }
    memset(&cs->addr, 0, sizeof(cs->addr));
    cs->addr.sin_family = 2;
    cs->addr.sin_port = htons(port);
    cs->addr.sin_addr.s_addr = in_addr;
    cs->has_addr = 1;
    return 1;
}


decompiled_code:
char *__fastcall do_send(__int64 a1)
{
char *result; // rax
int v2; // ebx
const unsigned __int16 **v3; // rax
__int64 v4; // rdx
int v5; // er15
char *v6; // rbp
const unsigned __int16 *v7; // r14
int v8; // er13
unsigned __int16 v9; // ax
__int64 v10; // rax
ssize_t v11; // rbp
const char *v12; // rdx
pthread_mutex_t *mutex; // [rsp+18h] [rbp-140h]
char s[4]; // [rsp+20h] [rbp-138h] BYREF

mutex = (pthread_mutex_t *)(a1 + 8);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
puts("Type bytes as one or two character hexadecimal values.");
puts("Separate bytes by a space.");
puts("Press <enter> to send.");
puts("Type stop<enter> to quit.");
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
while ( 1 )
{
result = fgets(s, 256, _bss_start);
if ( !result || *(_DWORD *)s == 1886352499 )
return result;
v2 = (unsigned __int8)s[0];
if ( s[0] )
{
v3 = __ctype_b_loc();
v4 = (char)v2;
v5 = 0;
v6 = s;
v7 = *v3;
v8 = 0;
v9 = (*v3)[(char)v2];
if ( (v9 & 0x800) != 0 )
goto LABEL_13;
LABEL_6:
if ( (v9 & 0x400) != 0 )
{
v5 = ((*__ctype_tolower_loc())[v4] - 87) | (16 * v5);
goto LABEL_11;
}
if ( (v9 & 0x2000) != 0 )
{
if ( v6 <= s )
{
if ( *v6 != 10 )
goto LABEL_11;
if ( v8 )
goto LABEL_17;
}
else
{
v10 = v8++;
s[v10] = v5;
if ( *v6 != 10 )
{
v5 = 0;
goto LABEL_11;
}
LABEL_17:
if ( *(_DWORD *)(a1 + 48) )
{
v11 = sendto(*(_DWORD *)a1, s, v8, 0, (const struct sockaddr *)(a1 + 52), 0x10u);
pthread_mutex_lock(mutex);
v12 = "byte";
if ( v11 != 1 )
v12 = "bytes";
printf("sent %ld %s\n", v11, v12);
pthread_mutex_unlock(mutex);
}
else
{
pthread_mutex_lock(mutex);
puts("Cannot send: peer address is not yet known.");
pthread_mutex_unlock(mutex);
}
}
}
else
{
LABEL_11:
while ( 1 )
{
v2 = (unsigned __int8)*++v6;
if ( !(_BYTE)v2 )
break;
v4 = (char)v2;
v9 = v7[(char)v2];
if ( (v9 & 0x800) == 0 )
goto LABEL_6;
LABEL_13:
v5 = (v2 - 48) | (16 * v5);
}
}
}
}
}

canonical_decompiled_code:
char *__fastcall func12(__int64 a1)
{
char *result; // rax
int v2; // ebx
const unsigned __int16 **v3; // rax
__int64 v4; // rdx
int v5; // er15
char *v6; // rbp
const unsigned __int16 *v7; // r14
int v8; // er13
unsigned __int16 v9; // ax
__int64 v10; // rax
ssize_t v11; // rbp
const char *v12; // rdx
pthread_mutex_t *mutex; // [rsp+18h] [rbp-140h]
char s[4]; // [rsp+20h] [rbp-138h] BYREF

mutex = (pthread_mutex_t *)(a1 + 8);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
puts("Type bytes as one or two character hexadecimal values.");
puts("Separate bytes by a space.");
puts("Press <enter> to send.");
puts("Type stop<enter> to quit.");
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
while ( 1 )
{
result = fgets(s, 256, _bss_start);
if ( !result || *(_DWORD *)s == 1886352499 )
return result;
v2 = (unsigned __int8)s[0];
if ( s[0] )
{
v3 = __ctype_b_loc();
v4 = (char)v2;
v5 = 0;
v6 = s;
v7 = *v3;
v8 = 0;
v9 = (*v3)[(char)v2];
if ( (v9 & 0x800) != 0 )
goto LABEL_13;
LABEL_6:
if ( (v9 & 0x400) != 0 )
{
v5 = ((*__ctype_tolower_loc())[v4] - 87) | (16 * v5);
goto LABEL_11;
}
if ( (v9 & 0x2000) != 0 )
{
if ( v6 <= s )
{
if ( *v6 != 10 )
goto LABEL_11;
if ( v8 )
goto LABEL_17;
}
else
{
v10 = v8++;
s[v10] = v5;
if ( *v6 != 10 )
{
v5 = 0;
goto LABEL_11;
}
LABEL_17:
if ( *(_DWORD *)(a1 + 48) )
{
v11 = sendto(*(_DWORD *)a1, s, v8, 0, (const struct sockaddr *)(a1 + 52), 0x10u);
pthread_mutex_lock(mutex);
v12 = "byte";
if ( v11 != 1 )
v12 = "bytes";
printf("sent %ld %s\n", v11, v12);
pthread_mutex_unlock(mutex);
}
else
{
pthread_mutex_lock(mutex);
puts("Cannot send: peer address is not yet known.");
pthread_mutex_unlock(mutex);
}
}
}
else
{
LABEL_11:
while ( 1 )
{
v2 = (unsigned __int8)*++v6;
if ( !(_BYTE)v2 )
break;
v4 = (char)v2;
v9 = v7[(char)v2];
if ( (v9 & 0x800) == 0 )
goto LABEL_6;
LABEL_13:
v5 = (v2 - 48) | (16 * v5);
}
}
}
}
}

original_code:
void do_send(struct control_s *cs) {
    pthread_mutex_lock(&cs->mutex);
    printf("Type bytes as one or two character hexadecimal values.\n");
    printf("Separate bytes by a space.\n");
    printf("Press <enter> to send.\n");
    printf("Type stop<enter> to quit.\n");
    pthread_mutex_unlock(&cs->mutex);
    char buf[256];
    while (fgets(buf, sizeof(buf), stdin) != ((void *)0)) {
        if (memcmp(buf, "stop", 4) == 0) {
            break;
        }
        int nr_bytes = 0;
        char *cp;
        unsigned char value = 0;
        for (cp = buf; *cp != '\0'; cp++) {
            if (((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short int) _ISdigit)) {
                value <<= 4;
                value |= *cp - '0';
                continue;
            }
            if (((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short int) _ISalpha)) {
                value <<= 4;
                value |= tolower(*cp) - 'a' + 10;
                continue;
            }
            if (!((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short int) _ISspace)) {
                continue;
            }
            if (cp > buf) {
                buf[nr_bytes] = ((int) value) & 0xff;
                value = 0;
                nr_bytes++;
            }
            if (*cp != '\n') {
                continue;
            }
            if (nr_bytes <= 0) {
                break;
            }
            if (!cs->has_addr) {
                pthread_mutex_lock(&cs->mutex);
                printf("Cannot send: peer address is not yet known.\n");
                pthread_mutex_unlock(&cs->mutex);
            } else {
                ssize_t nr_sent = sendto(cs->sock, buf, nr_bytes, 0,
                                         (struct sockaddr *) &cs->addr,
                                         sizeof(cs->addr));
                pthread_mutex_lock(&cs->mutex);
                printf("sent %ld %s\n", (long) nr_sent, (nr_sent == 1 ? "byte" : "bytes"));
                pthread_mutex_unlock(&cs->mutex);
            }
            break;
        }
    }
}

canonical_original_code:
void do_send(struct control_s *cs) {
    pthread_mutex_lock(&cs->mutex);
    printf("Type bytes as one or two character hexadecimal values.\n");
    printf("Separate bytes by a space.\n");
    printf("Press <enter> to send.\n");
    printf("Type stop<enter> to quit.\n");
    pthread_mutex_unlock(&cs->mutex);
    char buf[256];
    while (fgets(buf, sizeof(buf), stdin) != ((void *)0)) {
        if (memcmp(buf, "stop", 4) == 0) {
            break;
        }
        int nr_bytes = 0;
        char *cp;
        unsigned char value = 0;
        for (cp = buf; *cp != '\0'; cp++) {
            if (((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short) _ISdigit)) {
                value <<= 4;
                value |= *cp - '0';
                continue;
            }
            if (((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short) _ISalpha)) {
                value <<= 4;
                value |= tolower(*cp) - 'a' + 10;
                continue;
            }
            if (!((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short) _ISspace)) {
                continue;
            }
            if (cp > buf) {
                buf[nr_bytes] = ((int) value) & 0xff;
                value = 0;
                nr_bytes++;
            }
            if (*cp != '\n') {
                continue;
            }
            if (nr_bytes <= 0) {
                break;
            }
            if (!cs->has_addr) {
                pthread_mutex_lock(&cs->mutex);
                printf("Cannot send: peer address is not yet known.\n");
                pthread_mutex_unlock(&cs->mutex);
            } else {
                long nr_sent = sendto(cs->sock, buf, nr_bytes, 0,
                                         (struct sockaddr *) &cs->addr,
                                         sizeof(cs->addr));
                pthread_mutex_lock(&cs->mutex);
                printf("sent %ld %s\n", (long) nr_sent, (nr_sent == 1 ? "byte" : "bytes"));
                pthread_mutex_unlock(&cs->mutex);
            }
            break;
        }
    }
}

variable_types:
buf
char [256]

variable_types:
cp
char *

variable_types:
value
unsigned char


decompiled_code:
void __fastcall release_lines(void *ptr)
{
void *v2; // rdi
_QWORD *v3; // rbx

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
v3 = ptr;
do
{
free(v2);
v2 = (void *)v3[1];
++v3;
}
while ( v2 );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi
_QWORD *v3; // rbx

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
v3 = ptr;
do
{
free(v2);
v2 = (void *)v3[1];
++v3;
}
while ( v2 );
}
free(ptr);
}
}

original_code:
static void release_lines(char **lines) {
    if (lines == ((void *)0)) {
        return;
    }
    for (char **p = lines; *p != ((void *)0); p++) {
        free(*p);
    }
    free(lines);
}

variable_types:
lines
char **

variable_types:
p
char **