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; }


repo: franko/regress-pro

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

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

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

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

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]

return_type: void

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 func0(__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 func1(_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, int *a2, int a3, double a4)
{
int v5; // ebx
__int64 i; // r12
__int64 j; // rbx
__int64 v9; // [rsp+0h] [rbp-48h]
int v10; // [rsp+8h] [rbp-40h]

if ( a3 )
{
v5 = a2[2];
v10 = *a2;
}
else
{
v5 = *a2;
v10 = a2[2];
}
writer_printf(a1, "%d %d", (unsigned int)v5, (unsigned int)v10);
writer_newline(a1);
if ( v5 > 0 )
{
v9 = (unsigned int)(v5 - 1);
for ( i = 0LL; ; ++i )
{
if ( v10 > 0 )
{
for ( j = 0LL; ; ++j )
{
if ( a3 )
gsl_matrix_get(a2, j, i);
else
gsl_matrix_get(a2, i, j);
writer_printf(a1, "%g", a4);
if ( j == v10 - 1 )
break;
if ( (int)j + 1 > 0 )
writer_printf(a1, " ");
}
}
if ( i == v9 )
break;
if ( (int)i + 1 > 0 )
writer_newline(a1);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int *a2, int a3, double a4)
{
int v5; // ebx
__int64 i; // r12
__int64 j; // rbx
__int64 v9; // [rsp+0h] [rbp-48h]
int v10; // [rsp+8h] [rbp-40h]

if ( a3 )
{
v5 = a2[2];
v10 = *a2;
}
else
{
v5 = *a2;
v10 = a2[2];
}
writer_printf(a1, "%d %d", (unsigned int)v5, (unsigned int)v10);
writer_newline(a1);
if ( v5 > 0 )
{
v9 = (unsigned int)(v5 - 1);
for ( i = 0LL; ; ++i )
{
if ( v10 > 0 )
{
for ( j = 0LL; ; ++j )
{
if ( a3 )
gsl_matrix_get(a2, j, i);
else
gsl_matrix_get(a2, i, j);
writer_printf(a1, "%g", a4);
if ( j == v10 - 1 )
break;
if ( (int)j + 1 > 0 )
writer_printf(a1, " ");
}
}
if ( i == v9 )
break;
if ( (int)i + 1 > 0 )
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

return_type: int

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


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

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


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: struct _str { char *heap; unsigned long size; unsigned long length; }

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; // er12
int i; // ebp
int v2; // ebx
double v4; // [rsp+0h] [rbp-28h]

v0 = number_of_molecules;
if ( number_of_molecules > 0 )
{
v4 = 0.0;
for ( i = 0; ; ++i )
{
if ( i + 1 >= v0 )
{
if ( i + 1 == v0 )
return v4;
}
else
{
v2 = i + 1;
do
v4 = interactionEnergy(i, v2++) + v4;
while ( v2 != v0 );
}
}
}
return 0.0;
}

canonical_decompiled_code:
double func1()
{
int v0; // er12
int i; // ebp
int v2; // ebx
double v4; // [rsp+0h] [rbp-28h]

v0 = number_of_molecules;
if ( number_of_molecules > 0 )
{
v4 = 0.0;
for ( i = 0; ; ++i )
{
if ( i + 1 >= v0 )
{
if ( i + 1 == v0 )
return v4;
}
else
{
v2 = i + 1;
do
v4 = func0(i, v2++) + v4;
while ( v2 != v0 );
}
}
}
return 0.0;
}

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()
{
int result; // eax

wsize_x = (int)((double)particle_scale * box_x);
wsize_y = (int)((double)particle_scale * box_y);
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);
if ( !dpy )
puts("Can't open the display.");
window = XCreateSimpleWindow(
dpy,
dpy->screens[(__int64)dpy->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()
{
int result; // eax

wsize_x = (int)((double)particle_scale * box_x);
wsize_y = (int)((double)particle_scale * box_y);
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);
if ( !dpy )
puts("Can't open the display.");
window = XCreateSimpleWindow(
dpy,
dpy->screens[(__int64)dpy->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
unsigned int i; // er10
_DWORD *v2; // rsi
int v3; // ecx
__int64 v4; // rax
int v5; // edx
__int64 v6; // r13
int v7; // eax
unsigned int v8; // ebx
double v9; // xmm2_8
__m128d v10; // xmm1
double v11; // xmm0_8
__m128d v12; // xmm0
int v13; // ebp
__m128d v14; // xmm0
double v15; // xmm2_8
__m128d v16; // xmm2
int v17; // er12
__m128d v18; // xmm0
double v19; // xmm3_8
__m128d v20; // xmm2
__int64 v21; // rax
unsigned int j; // er10
_DWORD *v23; // rsi
int v24; // ecx
__int64 v25; // rax
int v26; // edx
__int64 v27; // r13
int v28; // eax
unsigned int v29; // ebx
double v30; // xmm2_8
__m128d v31; // xmm1
double v32; // xmm0_8
__m128d v33; // xmm0
int v34; // er12
__m128d v35; // xmm0
double v36; // xmm2_8
__m128d v37; // xmm2
int v38; // ebp
__m128d v39; // xmm0
double v40; // xmm3_8
__m128d v41; // xmm2

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

canonical_decompiled_code:
int func2()
{
__int64 v0; // rax
unsigned int i; // er10
_DWORD *v2; // rsi
int v3; // ecx
__int64 v4; // rax
int v5; // edx
__int64 v6; // r13
int v7; // eax
unsigned int v8; // ebx
double v9; // xmm2_8
__m128d v10; // xmm1
double v11; // xmm0_8
__m128d v12; // xmm0
int v13; // ebp
__m128d v14; // xmm0
double v15; // xmm2_8
__m128d v16; // xmm2
int v17; // er12
__m128d v18; // xmm0
double v19; // xmm3_8
__m128d v20; // xmm2
__int64 v21; // rax
unsigned int j; // er10
_DWORD *v23; // rsi
int v24; // ecx
__int64 v25; // rax
int v26; // edx
__int64 v27; // r13
int v28; // eax
unsigned int v29; // ebx
double v30; // xmm2_8
__m128d v31; // xmm1
double v32; // xmm0_8
__m128d v33; // xmm0
int v34; // er12
__m128d v35; // xmm0
double v36; // xmm2_8
__m128d v37; // xmm2
int v38; // ebp
__m128d v39; // xmm0
double v40; // xmm3_8
__m128d v41; // xmm2

if ( number_of_molecules > 0 )
{
v0 = 0LL;
do
{
*(_DWORD *)(z_rank + 4 * v0) = v0;
++v0;
}
while ( number_of_molecules > (int)v0 );
}
gcvalues.foreground = bg_color;
XChangeGC(dpy, context, 4uLL, &gcvalues);
XFillRectangle(dpy, window, context, (int)wsize_x / -2, (int)wsize_y / -2, 2 * wsize_x, 2 * wsize_y);
if ( number_of_molecules <= 0 )
goto LABEL_40;
for ( i = number_of_molecules - 2; i != -1; --i )
{
v4 = 0LL;
do
{
v2 = (_DWORD *)(z_rank + v4);
v3 = *(_DWORD *)(z_rank + v4);
v4 += 4LL;
v5 = *(_DWORD *)(z_rank + v4);
if ( *((double *)&z + v5) > *((double *)&z + v3) )
{
*v2 = v5;
*(_DWORD *)(z_rank + v4) = v3;
}
}
while ( v4 != 4LL * i + 4 );
}
if ( number_of_molecules <= 0 )
{
LABEL_40:
if ( !side_view )
goto LABEL_41;
goto LABEL_23;
}
v6 = 0LL;
do
{
v7 = *(_DWORD *)(z_rank + 4 * v6);
v8 = (int)(*((double *)&d + v7) * (double)particle_scale * *(double *)&sfactor);
v9 = *((double *)&d + v7) * 0.5;
v10.m128d_f64[0] = (*((double *)&x + v7) - v9) * (double)particle_scale;
v11 = v10.m128d_f64[0];
if ( COERCE_DOUBLE(LC3 & *(_QWORD *)&v10.m128d_f64[0]) < 4.503599627370496e15 )
{
v12.m128d_f64[0] = (double)(int)v10.m128d_f64[0];
*(_QWORD *)&v11 = ~LC3 & *(_QWORD *)&v10.m128d_f64[0] | COERCE_UNSIGNED_INT64(
v12.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v12, v10) & LC4));
}
v13 = (int)v11;
v15 = (*((double *)&y + v7) - v9) * (double)particle_scale;
v14.m128d_f64[0] = v15;
if ( COERCE_DOUBLE(LC3 & *(_QWORD *)&v15) < 4.503599627370496e15 )
{
v16.m128d_f64[0] = (double)(int)v15;
*(_QWORD *)&v15 = ~LC3 & *(_QWORD *)&v14.m128d_f64[0] | COERCE_UNSIGNED_INT64(
(double)(int)v14.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v16, v14) & LC4));
}
v17 = (int)v15;
v18.m128d_f64[0] = (double)(fg_color - min_color) * *((double *)&z + v7) / box_z;
v19 = v18.m128d_f64[0];
if ( COERCE_DOUBLE(LC5 & *(_QWORD *)&v18.m128d_f64[0]) < 4.503599627370496e15 )
{
v20.m128d_f64[0] = (double)(int)v18.m128d_f64[0];
*(_QWORD *)&v19 = ~LC5 & *(_QWORD *)&v18.m128d_f64[0] | COERCE_UNSIGNED_INT64(
v20.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v20, v18) & LC4));
}
gcvalues.foreground = (int)(((double)fg_color - v19) * (double)(int)color_shift[*((int *)&c + v7)]);
XChangeGC(dpy, context, 4uLL, &gcvalues);
XFillArc(dpy, window, context, v13, v17, v8, v8, 0, 23040);
XFillArc(dpy, window, context, v13, wsize_y + v17, v8, v8, 0, 23040);
XFillArc(dpy, window, context, wsize_x + v13, v17, v8, v8, 0, 23040);
XFillArc(dpy, window, context, wsize_x + v13, wsize_y + v17, v8, v8, 0, 23040);
++v6;
}
while ( number_of_molecules > (int)v6 );
if ( side_view )
{
if ( number_of_molecules > 0 )
{
v21 = 0LL;
do
{
*(_DWORD *)(x_rank + 4 * v21) = v21;
++v21;
}
while ( number_of_molecules > (int)v21 );
}
LABEL_23:
gcvalues.foreground = bg_color;
XChangeGC(dpy, context2, 4uLL, &gcvalues);
XFillRectangle(dpy, window2, context2, (int)wsize_z / -2, (int)wsize_y / -2, 2 * wsize_z, 2 * wsize_y);
if ( number_of_molecules > 0 )
{
for ( j = number_of_molecules - 2; j != -1; --j )
{
v25 = 0LL;
do
{
v23 = (_DWORD *)(x_rank + v25);
v24 = *(_DWORD *)(x_rank + v25);
v25 += 4LL;
v26 = *(_DWORD *)(x_rank + v25);
if ( *((double *)&x + v24) > *((double *)&x + v26) )
{
*v23 = v26;
*(_DWORD *)(x_rank + v25) = v24;
}
}
while ( 4LL * j + 4 != v25 );
}
if ( number_of_molecules > 0 )
{
v27 = 0LL;
do
{
v28 = *(_DWORD *)(x_rank + 4 * v27);
v29 = (int)(*((double *)&d + v28) * (double)particle_scale * *(double *)&sfactor);
v30 = *((double *)&d + v28) * 0.5;
v31.m128d_f64[0] = (*((double *)&y + v28) - v30) * (double)particle_scale;
v32 = v31.m128d_f64[0];
if ( COERCE_DOUBLE(LC3 & *(_QWORD *)&v31.m128d_f64[0]) < 4.503599627370496e15 )
{
v33.m128d_f64[0] = (double)(int)v31.m128d_f64[0];
*(_QWORD *)&v32 = ~LC3 & *(_QWORD *)&v31.m128d_f64[0] | COERCE_UNSIGNED_INT64(
v33.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v33, v31) & LC4));
}
v34 = (int)v32;
v36 = (*((double *)&z + v28) - v30) * (double)particle_scale;
v35.m128d_f64[0] = v36;
if ( COERCE_DOUBLE(LC3 & *(_QWORD *)&v36) < 4.503599627370496e15 )
{
v37.m128d_f64[0] = (double)(int)v36;
*(_QWORD *)&v36 = ~LC3 & *(_QWORD *)&v35.m128d_f64[0] | COERCE_UNSIGNED_INT64(
(double)(int)v35.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v37, v35) & LC4));
}
v38 = (int)v36;
v39.m128d_f64[0] = (double)(fg_color - min_color) * *((double *)&x + v28) / box_x;
v40 = v39.m128d_f64[0];
if ( COERCE_DOUBLE(LC5 & *(_QWORD *)&v39.m128d_f64[0]) < 4.503599627370496e15 )
{
v41.m128d_f64[0] = (double)(int)v39.m128d_f64[0];
*(_QWORD *)&v40 = ~LC5 & *(_QWORD *)&v39.m128d_f64[0] | COERCE_UNSIGNED_INT64(
v41.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v41, v39) & LC4));
}
gcvalues.foreground = (int)(((double)min_color + v40) * (double)(int)color_shift[*((int *)&c + v28)]);
XChangeGC(dpy, context2, 4uLL, &gcvalues);
XFillArc(dpy, window2, context2, v38, v34, v29, v29, 0, 23040);
XFillArc(dpy, window2, context2, v38, wsize_y + v34, v29, v29, 0, 23040);
XFillArc(dpy, window2, context2, wsize_z + v38, v34, v29, v29, 0, 23040);
XFillArc(dpy, window2, context2, wsize_z + v38, wsize_y + v34, v29, v29, 0, 23040);
++v27;
}
while ( number_of_molecules > (int)v27 );
}
}
}
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
int v3; // ebx
__int64 result; // rax
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 2, 0);
*a1 = v2;
if ( v2 < 0 )
{
puts("failed to create socket");
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
*(_DWORD *)&v5.sa_data[10] = 0;
v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)v5.sa_data = _bswap_16(a2);
if ( bind(v3, &v5, 0x10u) )
{
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
int v3; // ebx
__int64 result; // rax
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 2, 0);
*a1 = v2;
if ( v2 < 0 )
{
puts("failed to create socket");
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
*(_DWORD *)&v5.sa_data[10] = 0;
v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[2] = (unsigned int)func8(0);
*(_WORD *)v5.sa_data = func7(a2);
if ( bind(v3, &v5, 0x10u) )
{
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; }


decompiled_code:
void *__fastcall do_receive(void *a1)
{
pthread_mutex_t *v1; // r13
__int64 v3; // rbx
int v4; // ebx
int v5; // ebp
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 )
{
addr_len = 16;
v4 = recvfrom(*(_DWORD *)a1, buf, 0x100uLL, 0, &addr, &addr_len);
v5 = v4;
if ( v4 < 0 )
break;
pthread_mutex_lock(v1);
*(__m128i *)((char *)a1 + 52) = _mm_loadu_si128((const __m128i *)&addr);
*((_DWORD *)a1 + 12) = 1;
if ( v4 == 1 )
{
printf("received %d %s: ", 1LL, "byte");
LABEL_13:
v3 = 0LL;
do
{
if ( (int)v3 > 0 )
putchar(32);
printf("%02.2x", (unsigned __int8)buf[v3++]);
}
while ( v5 > (int)v3 );
goto LABEL_9;
}
printf("received %d %s: ", (unsigned int)v4, "bytes");
if ( v4 > 0 )
goto LABEL_13;
LABEL_9:
putchar(10);
pthread_mutex_unlock(v1);
if ( *((_DWORD *)a1 + 1) )
return 0LL;
}
if ( !*((_DWORD *)a1 + 1) )
{
pthread_mutex_lock(v1);
puts("recvfrom() failed");
pthread_mutex_unlock(v1);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func9(void *a1)
{
pthread_mutex_t *v1; // r13
__int64 v3; // rbx
int v4; // ebx
int v5; // ebp
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 )
{
addr_len = 16;
v4 = recvfrom(*(_DWORD *)a1, buf, 0x100uLL, 0, &addr, &addr_len);
v5 = v4;
if ( v4 < 0 )
break;
pthread_mutex_lock(v1);
*(__m128i *)((char *)a1 + 52) = _mm_loadu_si128((const __m128i *)&addr);
*((_DWORD *)a1 + 12) = 1;
if ( v4 == 1 )
{
printf("received %d %s: ", 1LL, "byte");
LABEL_13:
v3 = 0LL;
do
{
if ( (int)v3 > 0 )
putchar(32);
printf("%02.2x", (unsigned __int8)buf[v3++]);
}
while ( v5 > (int)v3 );
goto LABEL_9;
}
printf("received %d %s: ", (unsigned int)v4, "bytes");
if ( v4 > 0 )
goto LABEL_13;
LABEL_9:
putchar(10);
pthread_mutex_unlock(v1);
if ( *((_DWORD *)a1 + 1) )
return 0LL;
}
if ( !*((_DWORD *)a1 + 1) )
{
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
in_addr_t v5; // er13
__int64 result; // rax

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

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

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

variable_types:
ipaddress
char *


decompiled_code:
int __fastcall do_send(__int64 a1)
{
int v1; // er12
char *v2; // rbp
int v3; // ebx
unsigned __int16 v4; // ax
char *v5; // rax
const unsigned __int16 *v6; // r14
ssize_t v7; // rbx
const char *v8; // rdx
int v10; // [rsp+4h] [rbp-154h]
pthread_mutex_t *mutex; // [rsp+10h] [rbp-148h]
char s[312]; // [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));
LABEL_11:
while ( 1 )
{
v5 = fgets(s, 256, stdin);
if ( !v5 )
break;
LODWORD(v5) = memcmp(s, "stop", 4uLL);
if ( !(_DWORD)v5 )
break;
v3 = (unsigned __int8)s[0];
if ( !s[0] )
continue;
v6 = *__ctype_b_loc();
v1 = 0;
v2 = s;
v10 = 0;
while ( 1 )
{
v4 = v6[(char)v3];
if ( (v4 & 0x800) == 0 )
break;
v1 = (v3 - 48) | (16 * v1);
LABEL_3:
v3 = (unsigned __int8)*++v2;
if ( !(_BYTE)v3 )
goto LABEL_11;
}
if ( (v4 & 0x400) != 0 )
{
v1 = ((*__ctype_tolower_loc())[(char)v3] - 87) | (16 * v1);
goto LABEL_3;
}
if ( (v4 & 0x2000) == 0 )
goto LABEL_3;
if ( v2 > s )
{
s[v10++] = v1;
v1 = 0;
}
if ( *v2 != 10 )
goto LABEL_3;
if ( v10 > 0 )
{
if ( *(_DWORD *)(a1 + 48) )
{
v7 = sendto(*(_DWORD *)a1, s, v10, 0, (const struct sockaddr *)(a1 + 52), 0x10u);
pthread_mutex_lock(mutex);
v8 = "byte";
if ( v7 != 1 )
v8 = "bytes";
printf("sent %ld %s\n", v7, v8);
pthread_mutex_unlock(mutex);
}
else
{
pthread_mutex_lock(mutex);
puts("Cannot send: peer address is not yet known.");
pthread_mutex_unlock(mutex);
}
}
}
return (int)v5;
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1)
{
int v1; // er12
char *v2; // rbp
int v3; // ebx
unsigned __int16 v4; // ax
char *v5; // rax
const unsigned __int16 *v6; // r14
ssize_t v7; // rbx
const char *v8; // rdx
int v10; // [rsp+4h] [rbp-154h]
pthread_mutex_t *mutex; // [rsp+10h] [rbp-148h]
char s[312]; // [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));
LABEL_11:
while ( 1 )
{
v5 = fgets(s, 256, stdin);
if ( !v5 )
break;
LODWORD(v5) = memcmp(s, "stop", 4uLL);
if ( !(_DWORD)v5 )
break;
v3 = (unsigned __int8)s[0];
if ( !s[0] )
continue;
v6 = *__ctype_b_loc();
v1 = 0;
v2 = s;
v10 = 0;
while ( 1 )
{
v4 = v6[(char)v3];
if ( (v4 & 0x800) == 0 )
break;
v1 = (v3 - 48) | (16 * v1);
LABEL_3:
v3 = (unsigned __int8)*++v2;
if ( !(_BYTE)v3 )
goto LABEL_11;
}
if ( (v4 & 0x400) != 0 )
{
v1 = ((*__ctype_tolower_loc())[(char)v3] - 87) | (16 * v1);
goto LABEL_3;
}
if ( (v4 & 0x2000) == 0 )
goto LABEL_3;
if ( v2 > s )
{
s[v10++] = v1;
v1 = 0;
}
if ( *v2 != 10 )
goto LABEL_3;
if ( v10 > 0 )
{
if ( *(_DWORD *)(a1 + 48) )
{
v7 = sendto(*(_DWORD *)a1, s, v10, 0, (const struct sockaddr *)(a1 + 52), 0x10u);
pthread_mutex_lock(mutex);
v8 = "byte";
if ( v7 != 1 )
v8 = "bytes";
printf("sent %ld %s\n", v7, v8);
pthread_mutex_unlock(mutex);
}
else
{
pthread_mutex_lock(mutex);
puts("Cannot send: peer address is not yet known.");
pthread_mutex_unlock(mutex);
}
}
}
return (int)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


main

canonical_name: main

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

if ( argc > 2 )
{
v6 = atoi(argv[2]);
v4 = prepare_for_client((__int64)&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((__int64)&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
__int16 v6; // ax
pthread_t newthread; // [rsp+8h] [rbp-60h] BYREF
int arg; // [rsp+10h] [rbp-58h] BYREF
int v9; // [rsp+14h] [rbp-54h]
pthread_mutex_t mutex; // [rsp+18h] [rbp-50h] BYREF

if ( argc > 2 )
{
v6 = atoi(argv[2]);
v4 = func10((__int64)&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((__int64)&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


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

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

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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
v3 = (void **)ptr;
do
{
free(v2);
v2 = *++v3;
}
while ( *v3 );
}
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 **


decompiled_code:
void *__fastcall read_request(int a1)
{
int v1; // ebx
void *v2; // r13
const char *v3; // rdi
char *v5; // r14
const char *v6; // r15
char *v7; // rbx
int v8; // eax
void *v9; // rax
ssize_t v10; // rax
char *v11; // r12
char *v12; // r12
int v13; // [rsp+Ch] [rbp-44Ch]
int v14; // [rsp+18h] [rbp-440h]
int fd; // [rsp+1Ch] [rbp-43Ch] BYREF
char dest[2]; // [rsp+20h] [rbp-438h] BYREF
char v17; // [rsp+22h] [rbp-436h] BYREF

fd = a1;
puts("waiting for request...");
v1 = 0;
v2 = 0LL;
v13 = 0;
while ( 1 )
{
v10 = recv(fd, &dest[v1], 1024LL - v1, 0);
if ( v10 <= 0 )
break;
v14 = v1 + v10;
v11 = (char *)&fd + v1 + (int)v10 + 3;
if ( v11 > dest )
{
v7 = &v17;
v12 = v11 + 2;
v6 = dest;
while ( 1 )
{
if ( *(v7 - 2) == 13 && *(v7 - 1) == 10 )
{
*(v7 - 2) = 0;
if ( v2 )
{
v8 = v13++;
v9 = realloc(v2, 8LL * (v8 + 2));
if ( !v9 )
{
puts("out of memory (2)");
release_lines(v2);
return 0LL;
}
v2 = v9;
}
else
{
v2 = malloc(0x10uLL);
if ( !v2 )
{
puts("out of memory (1)");
return v2;
}
v13 = 1;
}
*((_QWORD *)v2 + v13) = 0LL;
v5 = strdup(v6);
*((_QWORD *)v2 + v13 - 1) = v5;
if ( !v5 )
{
puts("out of memory (3)");
release_lines(v2);
return 0LL;
}
if ( !*v6 )
return v2;
v6 = v7;
}
if ( ++v7 == v12 )
goto LABEL_21;
}
}
v6 = dest;
LABEL_21:
v1 = v14 - (v6 - dest);
if ( v1 > 0 )
memmove(dest, v6, v1);
}
v3 = "connection closed unexpectedly\n";
if ( v10 )
v3 = "connection lost\n";
printf(v3);
release_lines(v2);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func5(int a1)
{
int v1; // ebx
void *v2; // r13
const char *v3; // rdi
char *v5; // r14
const char *v6; // r15
char *v7; // rbx
int v8; // eax
void *v9; // rax
ssize_t v10; // rax
char *v11; // r12
char *v12; // r12
int v13; // [rsp+Ch] [rbp-44Ch]
int v14; // [rsp+18h] [rbp-440h]
int fd; // [rsp+1Ch] [rbp-43Ch] BYREF
char dest[2]; // [rsp+20h] [rbp-438h] BYREF
char v17; // [rsp+22h] [rbp-436h] BYREF

fd = a1;
puts("waiting for request...");
v1 = 0;
v2 = 0LL;
v13 = 0;
while ( 1 )
{
v10 = recv(fd, &dest[v1], 1024LL - v1, 0);
if ( v10 <= 0 )
break;
v14 = v1 + v10;
v11 = (char *)&fd + v1 + (int)v10 + 3;
if ( v11 > dest )
{
v7 = &v17;
v12 = v11 + 2;
v6 = dest;
while ( 1 )
{
if ( *(v7 - 2) == 13 && *(v7 - 1) == 10 )
{
*(v7 - 2) = 0;
if ( v2 )
{
v8 = v13++;
v9 = realloc(v2, 8LL * (v8 + 2));
if ( !v9 )
{
puts("out of memory (2)");
func4(v2);
return 0LL;
}
v2 = v9;
}
else
{
v2 = malloc(0x10uLL);
if ( !v2 )
{
puts("out of memory (1)");
return v2;
}
v13 = 1;
}
*((_QWORD *)v2 + v13) = 0LL;
v5 = strdup(v6);
*((_QWORD *)v2 + v13 - 1) = v5;
if ( !v5 )
{
puts("out of memory (3)");
func4(v2);
return 0LL;
}
if ( !*v6 )
return v2;
v6 = v7;
}
if ( ++v7 == v12 )
goto LABEL_21;
}
}
v6 = dest;
LABEL_21:
v1 = v14 - (v6 - dest);
if ( v1 > 0 )
memmove(dest, v6, v1);
}
v3 = "connection closed unexpectedly\n";
if ( v10 )
v3 = "connection lost\n";
printf(v3);
func4(v2);
return 0LL;
}

original_code:
static char **read_request(int sock) {
    printf("waiting for request...\n");
    int line_count = 0;
    char **lines = ((void *)0);
    char buffer[1024];
    int offset = 0;
    while (1) {
        ssize_t nr_recv = recv(sock, buffer + offset, sizeof(buffer) - offset, 0);
        if (nr_recv <= 0) {
            printf(nr_recv == 0 ? "connection closed unexpectedly\n" : "connection lost\n");
            release_lines(lines);
            return ((void *)0);
        }
        int nr_in_buf = offset + nr_recv;
        char *start_of_line = buffer;
        for (char *p = buffer; p < buffer + nr_in_buf - 1; p++) {
            if (*p == 0x0d && *(p + 1) == 0x0a) {
                *p = '\0';
                if (lines == ((void *)0)) {
                    line_count = 1;
                    lines = (char **) malloc((line_count + 1) * sizeof(char **));
                    if (lines == ((void *)0)) {
                        printf("out of memory (1)\n");
                        return ((void *)0);
                    }
                } else {
                    line_count++;
                    char **new_lines = (char **) realloc(lines, (line_count + 1) * sizeof(char **));
                    if (new_lines == ((void *)0)) {
                        printf("out of memory (2)\n");
                        release_lines(lines);
                        return ((void *)0);
                    }
                    lines = new_lines;
                }
                lines[line_count] = ((void *)0);
                lines[line_count - 1] = strdup(start_of_line);
                if (lines[line_count - 1] == ((void *)0)) {
                    printf("out of memory (3)\n");
                    release_lines(lines);
                    return ((void *)0);
                }
                if (strlen(start_of_line) == 0) {
                    return lines;
                }
                start_of_line = p + 2;
            }
        }
        int remaining = nr_in_buf - (start_of_line - buffer);
        if (remaining > 0) {
            memmove(buffer, start_of_line, remaining);
        }
        offset = remaining;
    }
}

canonical_original_code:
static char **read_request(int sock) {
    printf("waiting for request...\n");
    int line_count = 0;
    char **lines = ((void *)0);
    char buffer[1024];
    int offset = 0;
    while (1) {
        long nr_recv = recv(sock, buffer + offset, sizeof(buffer) - offset, 0);
        if (nr_recv <= 0) {
            printf(nr_recv == 0 ? "connection closed unexpectedly\n" : "connection lost\n");
            release_lines(lines);
            return ((void *)0);
        }
        int nr_in_buf = offset + nr_recv;
        char *start_of_line = buffer;
        for (char *p = buffer; p < buffer + nr_in_buf - 1; p++) {
            if (*p == 0x0d && *(p + 1) == 0x0a) {
                *p = '\0';
                if (lines == ((void *)0)) {
                    line_count = 1;
                    lines = (char **) malloc((line_count + 1) * sizeof(char **));
                    if (lines == ((void *)0)) {
                        printf("out of memory (1)\n");
                        return ((void *)0);
                    }
                } else {
                    line_count++;
                    char **new_lines = (char **) realloc(lines, (line_count + 1) * sizeof(char **));
                    if (new_lines == ((void *)0)) {
                        printf("out of memory (2)\n");
                        release_lines(lines);
                        return ((void *)0);
                    }
                    lines = new_lines;
                }
                lines[line_count] = ((void *)0);
                lines[line_count - 1] = strdup(start_of_line);
                if (lines[line_count - 1] == ((void *)0)) {
                    printf("out of memory (3)\n");
                    release_lines(lines);
                    return ((void *)0);
                }
                if (strlen(start_of_line) == 0) {
                    return lines;
                }
                start_of_line = p + 2;
            }
        }
        int remaining = nr_in_buf - (start_of_line - buffer);
        if (remaining > 0) {
            memmove(buffer, start_of_line, remaining);
        }
        offset = remaining;
    }
}

variable_types: sock int

variable_types:
buffer
char [1024]

variable_types: offset int

variable_types:
p
char *

variable_types: remaining int

return_type: char **