decompiled_code:
__int64 __fastcall lookup_encode_param(__int64 a1)
{
return str_copy_c(a1, &unk_651);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return str_copy_c(a1, &unk_651);
}

original_code:
void
lookup_encode_param(str_t param, const fit_param_t *fp)
{
    str_copy_c(param, "P");
}

canonical_original_code:
void lookup_encode_param(struct _str param[1], struct fit_param_t *fp)
{
    str_copy_c(param, "P");
}

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

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


emalloc

repo: franko/regress-pro

decompiled_code:
void *__fastcall emalloc(int a1)
{
void *result; // rax

if ( a1 < 0 )
_assert_fail("n >= 0", "common.c", 0xEu, "emalloc");
result = malloc(a1);
if ( !result )
{
fwrite("Couldn't allocate memory\n", 1uLL, 0x19uLL, stderr);
fflush(stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
void *result; // rax

if ( a1 < 0 )
_assert_fail("n >= 0", "common.c", 0xEu, "emalloc");
result = malloc(a1);
if ( !result )
{
fwrite("Couldn't allocate memory\n", 1uLL, 0x19uLL, stderr);
fflush(stderr);
exit(1);
}
return result;
}

original_code:
void *
emalloc(int n)
{
    void *p;
    ((void) sizeof ((n >= 0) ? 1 : 0), __extension__ ({ if (n >= 0) ; else __assert_fail ("n >= 0", "common.c", 14, __extension__ __PRETTY_FUNCTION__); }));
    p = malloc(n);
    if(p == ((void *)0)) {
        fprintf(stderr, "Couldn't allocate memory\n");
        fflush(stderr);
        exit(1);
    }
    return p;
}

canonical_original_code:
void *emalloc(int n)
{
    void *p;
    ((void) sizeof ((n >= 0) ? 1 : 0), __extension__ ({ if (n >= 0) ; else __assert_fail ("n >= 0", "common.c", 14, __extension__ __PRETTY_FUNCTION__); }));
    p = malloc(n);
    if(p == ((void *)0)) {
        fprintf(stderr, "Couldn't allocate memory\n");
        fflush(stderr);
        exit(1);
    }
    return p;
}

variable_types: n int

variable_types:
p
void *

return_type: void *


erealloc

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

if ( a2 < 0 )
_assert_fail("n >= 0", "common.c", 0x20u, "erealloc");
result = realloc(a1, a2);
if ( !result )
{
fwrite("Couldn't allocate memory\n", 1uLL, 0x19uLL, stderr);
fflush(stderr);
exit(1);
}
return result;
}

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

if ( a2 < 0 )
_assert_fail("n >= 0", "common.c", 0x20u, "erealloc");
result = realloc(a1, a2);
if ( !result )
{
fwrite("Couldn't allocate memory\n", 1uLL, 0x19uLL, stderr);
fflush(stderr);
exit(1);
}
return result;
}

original_code:
void *
erealloc(void *p, int n)
{
    void *newp;
    ((void) sizeof ((n >= 0) ? 1 : 0), __extension__ ({ if (n >= 0) ; else __assert_fail ("n >= 0", "common.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    newp = realloc(p, n);
    if(newp == ((void *)0)) {
        fprintf(stderr, "Couldn't allocate memory\n");
        fflush(stderr);
        exit(1);
    }
    return newp;
}

canonical_original_code:
void *erealloc(void *p, int n)
{
    void *newp;
    ((void) sizeof ((n >= 0) ? 1 : 0), __extension__ ({ if (n >= 0) ; else __assert_fail ("n >= 0", "common.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    newp = realloc(p, n);
    if(newp == ((void *)0)) {
        fprintf(stderr, "Couldn't allocate memory\n");
        fflush(stderr);
        exit(1);
    }
    return newp;
}

variable_types:
newp
void *


decompiled_code:
void __fastcall generic_array_check_alloc(_QWORD *a1, int a2, __int64 a3)
{
unsigned __int64 v5; // rdi
void *v6; // r12
void *v7; // rax

if ( a2 < 0 )
_assert_fail("idx >= 0", "common.c", 0x33u, "generic_array_check_alloc");
v5 = a1[1];
if ( a2 >= v5 )
{
v6 = (void *)a1[2];
do
v5 *= 2LL;
while ( a2 >= v5 );
a1[1] = v5;
v7 = emalloc((int)a3 * (int)v5);
a1[2] = v7;
memcpy(v7, v6, *a1 * a3);
free(v6);
}
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1, int a2, __int64 a3)
{
unsigned __int64 v5; // rdi
void *v6; // r12
void *v7; // rax

if ( a2 < 0 )
_assert_fail("idx >= 0", "common.c", 0x33u, "generic_array_check_alloc");
v5 = a1[1];
if ( a2 >= v5 )
{
v6 = (void *)a1[2];
do
v5 *= 2LL;
while ( a2 >= v5 );
a1[1] = v5;
v7 = func0((int)a3 * (int)v5);
a1[2] = v7;
memcpy(v7, v6, *a1 * a3);
free(v6);
}
}

original_code:
void
generic_array_check_alloc(struct generic_array *s, int idx,
                          size_t data_size)
{
    void *oldptr;
    ((void) sizeof ((idx >= 0) ? 1 : 0), __extension__ ({ if (idx >= 0) ; else __assert_fail ("idx >= 0", "common.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    if((size_t)idx < s->alloc) {
        return;
    }
    oldptr = s->heap;
    do {
        s->alloc *= 2;
    } while((size_t)idx >= s->alloc);
    s->heap = emalloc(s->alloc * data_size);
    memcpy(s->heap, oldptr, s->number * data_size);
    free(oldptr);
}

canonical_original_code:
void generic_array_check_alloc(struct generic_array *s, int idx, unsigned long data_size)
{
    void *oldptr;
    ((void) sizeof ((idx >= 0) ? 1 : 0), __extension__ ({ if (idx >= 0) ; else __assert_fail ("idx >= 0", "common.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    if((unsigned long)idx < s->alloc) {
        return;
    }
    oldptr = s->heap;
    do {
        s->alloc *= 2;
    } while((unsigned long)idx >= s->alloc);
    s->heap = emalloc(s->alloc * data_size);
    memcpy(s->heap, oldptr, s->number * data_size);
    free(oldptr);
}

variable_types: struct generic_array { unsigned long number; unsigned long alloc; void *heap; } *

variable_types: idx int

variable_types:
oldptr
void *

return_type: void


decompiled_code:
void __fastcall generic_array_free(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void
generic_array_free(struct generic_array *r)
{
    free(r->heap);
    free(r);
}

user_defined_types: struct generic_array { unsigned long number; unsigned long alloc; void *heap; }


decompiled_code:
double __fastcall get_lambda(double *a1, int a2)
{
return (double)(a2 * a2) * a1[2] + (double)a2 * a1[1] + (double)(a2 * a2 * a2) * a1[3] + *a1;
}

canonical_decompiled_code:
double __fastcall func0(double *a1, int a2)
{
return (double)(a2 * a2) * a1[2] + (double)a2 * a1[1] + (double)(a2 * a2 * a2) * a1[3] + *a1;
}

original_code:
static double
get_lambda(double w[], int k)
{
    return w[0] + k * w[1] + k*k * w[2] + k*k*k * w[3];
}

variable_types:
w
double []

variable_types: k int

return_type: double


original_code:
static int filmetrics_parse_line(const char *s, unsigned int flags, float x[])
{
    int n;
    const char list_sep = (flags & PARSE_FLOAT_FRENCH_LOCALE ? ';' : ',');
    if (parse_float(s, flags, &x[0], &n)) return 1;
    s = skip_spaces(s + n);
    if (*s != list_sep && *s != '\t') return 1;
    s = skip_spaces(s + 1);
    if (parse_float(s, flags, &x[1], &n)) return 1;
    s = skip_spaces(s + n);
    while (*s == '\r' || *s == '\n') {
        s ++;
    }
    return (*s == '\0' ? 0 : 1);
}

canonical_original_code:
static int filmetrics_parse_line(char *s, unsigned int flags, float x[])
{
    int n;
    char list_sep = (flags & PARSE_FLOAT_FRENCH_LOCALE ? ';' : ',');
    if (parse_float(s, flags, &x[0], &n)) return 1;
    s = skip_spaces(s + n);
    if (*s != list_sep && *s != '\t') return 1;
    s = skip_spaces(s + 1);
    if (parse_float(s, flags, &x[1], &n)) return 1;
    s = skip_spaces(s + n);
    while (*s == '\r' || *s == '\n') {
        s ++;
    }
    return (*s == '\0' ? 0 : 1);
}

variable_types:
s
char *

variable_types:
flags
unsigned int

variable_types:
x
float []

return_type: int


decompiled_code:
__int64 __fastcall filmetrics_test_line_format(__int64 a1)
{
int v1; // edx
__int64 result; // rax
char v3[16]; // [rsp+8h] [rbp-10h] BYREF

v1 = filmetrics_parse_line(a1, 1LL, (__int64)v3);
result = 1LL;
if ( v1 )
result = (unsigned int)filmetrics_parse_line(a1, 3LL, (__int64)v3) == 0 ? 3 : -1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // edx
__int64 result; // rax
char v3[16]; // [rsp+8h] [rbp-10h] BYREF

v1 = func1(a1, 1LL, (__int64)v3);
result = 1LL;
if ( v1 )
result = (unsigned int)func1(a1, 3LL, (__int64)v3) == 0 ? 3 : -1;
return result;
}

original_code:
static int filmetrics_test_line_format(const char *s)
{
    float x[2];
    unsigned int test_flags = PARSE_FLOAT_SKIP_SPACES;
    if (filmetrics_parse_line(s, test_flags, x) == 0) {
        return test_flags;
    }
    test_flags |= PARSE_FLOAT_FRENCH_LOCALE;
    if (filmetrics_parse_line(s, test_flags, x) == 0) {
        return test_flags;
    }
    return -1;
}

canonical_original_code:
static int filmetrics_test_line_format(char *s)
{
    float x[2];
    unsigned int test_flags = PARSE_FLOAT_SKIP_SPACES;
    if (filmetrics_parse_line(s, test_flags, x) == 0) {
        return test_flags;
    }
    test_flags |= PARSE_FLOAT_FRENCH_LOCALE;
    if (filmetrics_parse_line(s, test_flags, x) == 0) {
        return test_flags;
    }
    return -1;
}

variable_types:
x
float [2]


decompiled_code:
__int64 __fastcall refl_multifit_f(__int64 a1, __int64 a2, __int64 a3)
{
return refl_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
refl_multifit_f(const gsl_vector *x, void *params, gsl_vector * f)
{
    return refl_multifit_fdf(x, params, f, ((void *)0));
}

canonical_original_code:
int refl_multifit_f(struct gsl_vector *x, void *params, struct gsl_vector *f)
{
    return refl_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 refl_multifit_df(__int64 a1, __int64 a2, __int64 a3)
{
return refl_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
refl_multifit_df(const gsl_vector *x, void *params, gsl_matrix *jacob)
{
    return refl_multifit_fdf(x, params, ((void *)0), jacob);
}

canonical_original_code:
int refl_multifit_df(struct gsl_vector *x, void *params, struct gsl_matrix *jacob)
{
    return refl_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; } *

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


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

*(_DWORD *)a1 = *a2;
*(_DWORD *)(a1 + 4) = a2[1];
*(_DWORD *)(a1 + 8) = 0;
result = *a2;
*(_DWORD *)(a1 + 12) = result;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = a2;
return result;
}

original_code:
void
data_view_init(struct data_view *d, struct data_table *table)
{
    d->rows = table->rows;
    d->columns = table->columns;
    d->idx_start = 0;
    d->idx_end = table->rows;
    d->map = ((void *)0);
    d->table = table;
}

variable_types: 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; } *

variable_types:
table
struct data_table *

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


decompiled_code:
__int64 __fastcall data_view_copy(__int64 a1, int *a2)
{
void *v2; // rax
__int64 v3; // rdx
__int64 result; // rax

*(_DWORD *)a1 = *a2;
*(_DWORD *)(a1 + 4) = a2[1];
*(_DWORD *)(a1 + 8) = a2[2];
*(_DWORD *)(a1 + 12) = a2[3];
if ( *((_QWORD *)a2 + 2) )
{
v2 = (void *)emalloc((unsigned int)(4 * *a2));
*(_QWORD *)(a1 + 16) = v2;
memcpy(v2, *((const void **)a2 + 2), 4LL * *a2);
}
else
{
*(_QWORD *)(a1 + 16) = 0LL;
}
v3 = *((_QWORD *)a2 + 3);
*(_QWORD *)(a1 + 24) = v3;
result = *(unsigned int *)(v3 + 8);
if ( (int)result >= 0 )
{
result = (unsigned int)(result + 1);
*(_DWORD *)(v3 + 8) = result;
}
return result;
}

original_code:
void
data_view_copy(struct data_view *dest, const struct data_view *src)
{
    dest->rows = src->rows;
    dest->columns = src->columns;
    dest->idx_start = src->idx_start;
    dest->idx_end = src->idx_end;
    if(src->map) {
        dest->map = emalloc(src->rows * sizeof(int));
        memcpy(dest->map, src->map, src->rows * sizeof(int));
    } else {
        dest->map = ((void *)0);
    }
    dest->table = src->table;
    if ((src->table)->ref_count >= 0) { (src->table)->ref_count++; };
}

canonical_original_code:
void data_view_copy(struct data_view *dest, struct data_view *src)
{
    dest->rows = src->rows;
    dest->columns = src->columns;
    dest->idx_start = src->idx_start;
    dest->idx_end = src->idx_end;
    if(src->map) {
        dest->map = emalloc(src->rows * sizeof(int));
        memcpy(dest->map, src->map, src->rows * sizeof(int));
    } else {
        dest->map = ((void *)0);
    }
    dest->table = src->table;
    if ((src->table)->ref_count >= 0) { (src->table)->ref_count++; };
}

variable_types:
src
struct data_view *

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


decompiled_code:
__int64 __fastcall data_view_dealloc(__int64 a1)
{
void *v2; // rdi
__int64 result; // rax

v2 = *(void **)(a1 + 16);
if ( v2 )
free(v2);
result = data_table_unref(*(_QWORD *)(a1 + 24));
*(_QWORD *)(a1 + 24) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
void *v2; // rdi
__int64 result; // rax

v2 = *(void **)(a1 + 16);
if ( v2 )
free(v2);
result = data_table_unref(*(_QWORD *)(a1 + 24));
*(_QWORD *)(a1 + 24) = 0LL;
return result;
}

original_code:
void
data_view_dealloc(struct data_view *d)
{
    if(d->map != ((void *)0)) {
        free(d->map);
    }
    data_table_unref(d->table);
    d->table = ((void *)0);
}


original_code:
void
data_view_init_empty(struct data_view *d)
{
    d->rows = 0;
    d->columns = 0;
    d->idx_start = 0;
    d->idx_end = 0;
    d->map = ((void *)0);
    d->table = empty_data_table;
}


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

if ( *(_QWORD *)(a1 + 16) )
_assert_fail("d->map == NULL", "data-view.c", 0x44u, "data_view_set_mask_offset");
result = *(int **)(a1 + 24);
if ( *result < a3 || a2 < 0 || a3 <= a2 )
_assert_fail(
"end <= d->table->rows && start >= 0 && start < end",
"data-view.c",
0x46u,
"data_view_set_mask_offset");
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
*(_DWORD *)a1 = a3 - a2;
return result;
}

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

if ( *(_QWORD *)(a1 + 16) )
_assert_fail("d->map == NULL", "data-view.c", 0x44u, "data_view_set_mask_offset");
result = *(int **)(a1 + 24);
if ( *result < a3 || a2 < 0 || a3 <= a2 )
_assert_fail(
"end <= d->table->rows && start >= 0 && start < end",
"data-view.c",
0x46u,
"data_view_set_mask_offset");
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
*(_DWORD *)a1 = a3 - a2;
return result;
}

original_code:
void
data_view_set_mask_offset(struct data_view *d, int start, int end)
{
    ((void) sizeof ((d->map == ((void *)0)) ? 1 : 0), __extension__ ({ if (d->map == ((void *)0)) ; else __assert_fail ("d->map == NULL", "data-view.c", 68, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((end <= d->table->rows && start >= 0 && start < end) ? 1 : 0), __extension__ ({ if (end <= d->table->rows && start >= 0 && start < end) ; else __assert_fail ("end <= d->table->rows && start >= 0 && start < end", "data-view.c", 70, __extension__ __PRETTY_FUNCTION__); }));
    d->idx_start = start;
    d->idx_end = end;
    d->rows = end - start;
}

variable_types: start int

variable_types: end int


decompiled_code:
void __fastcall data_view_set_map(__int64 a1, int a2, _DWORD *a3)
{
_DWORD *v4; // r12
_DWORD *v5; // rax
void *v6; // rdi

v4 = a3;
if ( a2 > 0 )
{
v5 = a3;
do
{
if ( *v5 >= *(_DWORD *)a1 )
_assert_fail("map[k] < d->rows", "data-view.c", 0x55u, "data_view_set_map");
++v5;
}
while ( v5 != &a3[a2 - 1 + 1] );
}
v6 = *(void **)(a1 + 16);
if ( v6 )
free(v6);
*(_QWORD *)(a1 + 16) = v4;
*(_DWORD *)a1 = a2;
}

original_code:
void
data_view_set_map(struct data_view *d, int size, int *map)
{
    int k;
    for(k = 0; k < size; k++) {
        ((void) sizeof ((map[k] < d->rows) ? 1 : 0), __extension__ ({ if (map[k] < d->rows) ; else __assert_fail ("map[k] < d->rows", "data-view.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    }
    if(d->map != ((void *)0)) {
        free(d->map);
    }
    d->map = map;
    d->rows = size;
}

variable_types: size int

variable_types:
map
int *


decompiled_code:
__int64 __fastcall data_view_reset(__int64 a1)
{
void *v2; // rdi
__int64 result; // rax

v2 = *(void **)(a1 + 16);
if ( v2 )
{
free(v2);
*(_QWORD *)(a1 + 16) = 0LL;
}
*(_DWORD *)(a1 + 8) = 0;
result = **(unsigned int **)(a1 + 24);
*(_DWORD *)(a1 + 12) = result;
*(_DWORD *)a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
void *v2; // rdi
__int64 result; // rax

v2 = *(void **)(a1 + 16);
if ( v2 )
{
free(v2);
*(_QWORD *)(a1 + 16) = 0LL;
}
*(_DWORD *)(a1 + 8) = 0;
result = **(unsigned int **)(a1 + 24);
*(_DWORD *)(a1 + 12) = result;
*(_DWORD *)a1 = result;
return result;
}

original_code:
void
data_view_reset(struct data_view *d)
{
    if(d->map != ((void *)0)) {
        free(d->map);
        d->map = ((void *)0);
    }
    d->idx_start = 0;
    d->idx_end = d->table->rows;
    d->rows = d->table->rows;
}


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

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

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

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


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

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

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

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

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 lexer_free(void *ptr)
{
str_free((char *)ptr + 24);
str_free((char *)ptr + 48);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
str_free((char *)ptr + 24);
str_free((char *)ptr + 48);
free(ptr);
}

original_code:
void
lexer_free(lexer_t *l)
{
    str_free(l->buffer);
    str_free(l->store);
    free(l);
}

canonical_original_code:
void lexer_free(struct lexer_t *l)
{
    str_free(l->buffer);
    str_free(l->store);
    free(l);
}

variable_types: struct lexer_t { char *text; struct token_t { enum token_e { TK_UNDEF=0, TK_IDENT=1, TK_STRING=2, TK_EOF=3, TK_NUMBER=256, TK_INTEGER=257 } tk; union { double num; long integer; char *str; } value; } current; struct _str { char *heap; unsigned long size; unsigned long length; } buffer[1]; struct _str store[1]; } *

user_defined_types: struct lexer_t { char *text; struct token_t current; struct _str buffer[1]; struct _str store[1]; }

user_defined_types: struct token_t { enum token_e tk; union { double num; long integer; char *str; } value; }


original_code:
void
lexer_next(lexer_t *l)
{
    while (*l->text == ' ' || *l->text == '\t' || *l->text == '\r' || *l->text == '\n') {
        l->text ++;
    }
    char c = l->text[0];
    if (c == 0) {
        l->current.tk = TK_EOF;
    } else if ((c >= '0' && c <= '9') || c == '.' || c == '-') {
        char *ftail, *ltail;
        double fval = strtod(l->text, &ftail);
        long lval = strtol(l->text, &ltail, 10);
        if (ltail == ftail) {
            l->current.tk = TK_INTEGER;
            l->current.value.integer = lval;
            l->text = ltail;
        } else {
            l->current.tk = TK_NUMBER;
            l->current.value.num = fval;
            l->text = ftail;
        }
    } else if (c == '"') {
        const char *tail;
        str_trunc(l->buffer, 0);
        read_string(l->text + 1, l->buffer, &tail);
        l->current.tk = TK_STRING;
        l->current.value.str = ((const char *) (l->buffer)->heap);
        l->text = tail;
    } else {
        const char *tail;
        str_trunc(l->buffer, 0);
        read_ident(l->text, l->buffer, &tail);
        if (tail == l->text) {
            l->current.tk = TK_UNDEF;
        } else {
            l->current.tk = TK_IDENT;
            l->current.value.str = ((const char *) (l->buffer)->heap);
            l->text = tail;
        }
    }
}

canonical_original_code:
void lexer_next(struct lexer_t *l)
{
    while (*l->text == ' ' || *l->text == '\t' || *l->text == '\r' || *l->text == '\n') {
        l->text ++;
    }
    char c = l->text[0];
    if (c == 0) {
        l->current.tk = TK_EOF;
    } else if ((c >= '0' && c <= '9') || c == '.' || c == '-') {
        char *ftail; char *ltail;
        double fval = strtod(l->text, &ftail);
        long lval = strtol(l->text, &ltail, 10);
        if (ltail == ftail) {
            l->current.tk = TK_INTEGER;
            l->current.value.integer = lval;
            l->text = ltail;
        } else {
            l->current.tk = TK_NUMBER;
            l->current.value.num = fval;
            l->text = ftail;
        }
    } else if (c == '"') {
        char *tail;
        str_trunc(l->buffer, 0);
        read_string(l->text + 1, l->buffer, &tail);
        l->current.tk = TK_STRING;
        l->current.value.str = ((char *) (l->buffer)->heap);
        l->text = tail;
    } else {
        char *tail;
        str_trunc(l->buffer, 0);
        read_ident(l->text, l->buffer, &tail);
        if (tail == l->text) {
            l->current.tk = TK_UNDEF;
        } else {
            l->current.tk = TK_IDENT;
            l->current.value.str = ((char *) (l->buffer)->heap);
            l->text = tail;
        }
    }
}

variable_types: c char

variable_types:
ftail
char *

variable_types:
ltail
char *

variable_types: fval double

variable_types: lval long

variable_types:
tail
char *

user_defined_types: enum token_e { TK_UNDEF=0, TK_IDENT=1, TK_STRING=2, TK_EOF=3, TK_NUMBER=256, TK_INTEGER=257 }

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


decompiled_code:
__int64 __fastcall lexer_string_store(__int64 a1, int a2)
{
if ( *(_DWORD *)(a1 + 8) != (a2 == 0) + 1 )
return 1LL;
str_copy_c(a1 + 48, *(_QWORD *)(a1 + 16), 1LL);
lexer_next(a1);
return 0LL;
}

original_code:
int
lexer_string_store(lexer_t *l, int tk_ident)
{
    const int req = (tk_ident ? TK_IDENT : TK_STRING);
    if (l->current.tk == req) {
        str_copy_c(l->store, l->current.value.str);
        lexer_next(l);
        return 0;
    }
    return 1;
}

canonical_original_code:
int lexer_string_store(struct lexer_t *l, int tk_ident)
{
    int req = (tk_ident ? TK_IDENT : TK_STRING);
    if (l->current.tk == req) {
        str_copy_c(l->store, l->current.value.str);
        lexer_next(l);
        return 0;
    }
    return 1;
}

variable_types: req int


decompiled_code:
__int64 __fastcall lexer_check_ident(__int64 a1, const char *a2)
{
unsigned int v2; // ebp

v2 = 1;
if ( *(_DWORD *)(a1 + 8) == 1 )
{
v2 = strcmp(*(const char **)(a1 + 16), a2);
if ( v2 )
v2 = 1;
else
lexer_next(a1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2)
{
unsigned int v2; // ebp

v2 = 1;
if ( *(_DWORD *)(a1 + 8) == 1 )
{
v2 = strcmp(*(const char **)(a1 + 16), a2);
if ( v2 )
v2 = 1;
else
func3(a1);
}
return v2;
}

original_code:
int
lexer_check_ident(lexer_t *l, const char *id)
{
    if (l->current.tk == TK_IDENT && strcmp(l->current.value.str, id) == 0) {
        lexer_next(l);
        return 0;
    }
    return 1;
}

canonical_original_code:
int lexer_check_ident(struct lexer_t *l, char *id)
{
    if (l->current.tk == TK_IDENT && strcmp(l->current.value.str, id) == 0) {
        lexer_next(l);
        return 0;
    }
    return 1;
}

variable_types:
id
char *


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

result = 1LL;
if ( *(_DWORD *)(a1 + 8) == 257 )
{
*a2 = *(_QWORD *)(a1 + 16);
lexer_next(a1);
result = 0LL;
}
return result;
}

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

result = 1LL;
if ( *(_DWORD *)(a1 + 8) == 257 )
{
*a2 = *(_QWORD *)(a1 + 16);
func3(a1);
result = 0LL;
}
return result;
}

original_code:
int
lexer_integer(lexer_t *l, int *value)
{
    if (l->current.tk == TK_INTEGER) {
        *value = l->current.value.integer;
        lexer_next(l);
        return 0;
    }
    return 1;
}

canonical_original_code:
int lexer_integer(struct lexer_t *l, int *value)
{
    if (l->current.tk == TK_INTEGER) {
        *value = l->current.value.integer;
        lexer_next(l);
        return 0;
    }
    return 1;
}

variable_types:
value
int *


decompiled_code:
__int64 __fastcall lexer_number(__int64 a1, double *a2)
{
int v2; // eax
unsigned int v3; // edx

v2 = *(_DWORD *)(a1 + 8);
if ( v2 == 257 )
{
*a2 = (double)(int)*(_QWORD *)(a1 + 16);
lexer_next(a1);
v3 = 0;
}
else
{
v3 = 1;
if ( v2 == 256 )
{
*a2 = *(double *)(a1 + 16);
lexer_next(a1);
v3 = 0;
}
}
return v3;
}

original_code:
int
lexer_number(lexer_t *l, double *value)
{
    if (l->current.tk == TK_INTEGER) {
        *value = (double) (l->current.value.integer);
        lexer_next(l);
        return 0;
    } else if (l->current.tk == TK_NUMBER) {
        *value = l->current.value.num;
        lexer_next(l);
        return 0;
    }
    return 1;
}

canonical_original_code:
int lexer_number(struct lexer_t *l, double *value)
{
    if (l->current.tk == TK_INTEGER) {
        *value = (double) (l->current.value.integer);
        lexer_next(l);
        return 0;
    } else if (l->current.tk == TK_NUMBER) {
        *value = l->current.value.num;
        lexer_next(l);
        return 0;
    }
    return 1;
}

variable_types:
value
double *


decompiled_code:
__int64 __fastcall init_interp(_QWORD *a1)
{
__int64 result; // rax

a1[2] = gsl_interp_alloc(gsl_interp_cspline, *(int *)a1);
a1[3] = gsl_interp_alloc(gsl_interp_cspline, *(int *)a1);
result = gsl_interp_accel_alloc();
a1[4] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
__int64 result; // rax

a1[2] = gsl_interp_alloc(gsl_interp_cspline, *(int *)a1);
a1[3] = gsl_interp_alloc(gsl_interp_cspline, *(int *)a1);
result = gsl_interp_accel_alloc();
a1[4] = result;
return result;
}

original_code:
static void
init_interp(struct disp_sample_table *dt)
{
    dt->interp_n = gsl_interp_alloc(gsl_interp_cspline, dt->len);
    dt->interp_k = gsl_interp_alloc(gsl_interp_cspline, dt->len);
    dt->accel = gsl_interp_accel_alloc();
}

variable_types: struct disp_sample_table { int len; 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]; } *table; struct gsl_interp { struct gsl_interp_type { char *name; unsigned int min_size; void *(*alloc)(unsigned long size); int (*init)(void *, double xa[], double ya[], unsigned long size); int (*eval)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel { unsigned long cache; unsigned long miss_count; unsigned long hit_count; } *, double *y); int (*eval_deriv)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_p); int (*eval_deriv2)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_pp); int (*eval_integ)(void *, double xa[], double ya[], unsigned long size, struct gsl_interp_accel *, double a, double b, double *result); void (*free)(void *); } *type; double xmin; double xmax; unsigned long size; void *state; } *interp_n; struct gsl_interp_accel *accel; } *

user_defined_types: struct disp_sample_table { int len; struct _rc_matrix *table; struct gsl_interp *interp_n; struct gsl_interp_accel *accel; }

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

user_defined_types: struct gsl_interp { struct gsl_interp_type *type; double xmin; double xmax; unsigned long size; void *state; }

user_defined_types: struct _gsl_matrix_view { struct gsl_matrix matrix; }

user_defined_types: struct gsl_interp_type { char *name; unsigned int min_size; void *(*alloc)(unsigned long size); int (*init)(void *, double xa[], double ya[], unsigned long size); int (*eval)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y); int (*eval_deriv)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_p); int (*eval_deriv2)(void *, double xa[], double ya[], unsigned long size, double x, struct gsl_interp_accel *, double *y_pp); int (*eval_integ)(void *, double xa[], double ya[], unsigned long size, struct gsl_interp_accel *, double a, double b, double *result); void (*free)(void *); }


decompiled_code:
__int64 __fastcall prepare_interp(int *a1)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rax

v2 = n_array((__int64)a1);
v3 = wavelength_array((__int64)a1);
gsl_interp_init(*((_QWORD *)a1 + 2), v3, v2, *a1);
v4 = k_array((__int64)a1);
v5 = wavelength_array((__int64)a1);
return gsl_interp_init(*((_QWORD *)a1 + 3), v5, v4, *a1);
}

original_code:
static void
prepare_interp(struct disp_sample_table *dt)
{
    gsl_interp_init(dt->interp_n, wavelength_array(dt), n_array(dt), dt->len);
    gsl_interp_init(dt->interp_k, wavelength_array(dt), k_array(dt), dt->len);
}

user_defined_types: struct gsl_interp_accel { unsigned long cache; unsigned long miss_count; unsigned long hit_count; }


init

decompiled_code:
__int64 __fastcall init(_QWORD *a1, int a2)
{
*(_DWORD *)a1 = a2;
a1[1] = rc_matrix_alloc(3LL, a2);
return init_interp(a1);
}

canonical_decompiled_code:
__int64 __fastcall func17(_QWORD *a1, int a2)
{
*(_DWORD *)a1 = a2;
a1[1] = rc_matrix_alloc(3LL, a2);
return func10(a1);
}

original_code:
static void
init(struct disp_sample_table *dt, int len)
{
    dt->len = len;
    dt->table = rc_matrix_alloc(3, len);
    init_interp(dt);
}

variable_types: len int


decompiled_code:
void __fastcall disp_sample_table_get_sample(__int64 a1, int a2, double *a3, double *a4, double *a5)
{
*a3 = get_wavelength(a1, a2);
*a4 = get_n(a1, a2);
*a5 = get_k(a1, a2);
}

canonical_decompiled_code:
void __fastcall func18(__int64 a1, int a2, double *a3, double *a4, double *a5)
{
*a3 = func0(a1, a2);
*a4 = func1(a1, a2);
*a5 = func2(a1, a2);
}

original_code:
void disp_sample_table_get_sample(const struct disp_sample_table *dt, int index, double *w, double *n, double *k)
{
    *w = get_wavelength(dt, index);
    *n = get_n(dt, index);
    *k = get_k(dt, index);
}

canonical_original_code:
void disp_sample_table_get_sample(struct disp_sample_table *dt, int index, double *w, double *n, double *k)
{
    *w = get_wavelength(dt, index);
    *n = get_n(dt, index);
    *k = get_k(dt, index);
}

variable_types: index int

variable_types:
w
double *

variable_types:
n
double *

variable_types:
k
double *


original_code:
float
get_lambda_by_index(struct spectrum *s, int idx)
{
    ((void) sizeof ((idx >= 0 && idx < s->table->rows) ? 1 : 0), __extension__ ({ if (idx >= 0 && idx < s->table->rows) ; else __assert_fail ("idx >= 0 && idx < s->table->rows", "spectra.c", 195, __extension__ __PRETTY_FUNCTION__); }));
    return (s->table)->table->heap[(s->table->map ? (s->table)->table->columns * ((s->table)->idx_start + (s->table)->map[idx]) + (0) : (s->table)->table->columns * ((s->table)->idx_start + (idx)) + (0))];
}

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: idx int

return_type: float

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 spectra_free(void *ptr)
{
data_view_dealloc((char *)ptr + 32);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
data_view_dealloc((char *)ptr + 32);
free(ptr);
}

original_code:
void
spectra_free(struct spectrum *s)
{
    data_view_dealloc(s->table);
    free(s);
}

user_defined_types: enum system_kind { SYSTEM_UNDEFINED=0, SYSTEM_REFLECTOMETER=1, SYSTEM_ELLISS_AB=2, SYSTEM_ELLISS_PSIDEL=3, SYSTEM_EXCEED_VALUE=4 }


decompiled_code:
__int64 __fastcall spectr_cut_range(__int64 a1, float a2, float a3)
{
int v3; // er15
int v4; // er12
int v5; // ebp
int i; // ebx
float v7; // xmm0_4

data_view_reset(a1 + 32);
v3 = *(_DWORD *)(a1 + 32);
if ( v3 <= 0 )
{
v4 = 0;
v5 = -1;
}
else
{
v4 = 0;
v5 = -1;
for ( i = 0; i != v3; ++i )
{
v7 = get_lambda_by_index(a1, i);
if ( a2 <= v7 && v7 <= a3 )
{
if ( v5 < 0 )
v5 = i;
++v4;
}
}
}
return data_view_set_mask_offset(a1 + 32, (unsigned int)v5, (unsigned int)(v5 + v4));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, float a2, float a3)
{
int v3; // er15
int v4; // er12
int v5; // ebp
int i; // ebx
float v7; // xmm0_4

data_view_reset(a1 + 32);
v3 = *(_DWORD *)(a1 + 32);
if ( v3 <= 0 )
{
v4 = 0;
v5 = -1;
}
else
{
v4 = 0;
v5 = -1;
for ( i = 0; i != v3; ++i )
{
v7 = func2(a1, i);
if ( a2 <= v7 && v7 <= a3 )
{
if ( v5 < 0 )
v5 = i;
++v4;
}
}
}
return data_view_set_mask_offset(a1 + 32, (unsigned int)v5, (unsigned int)(v5 + v4));
}

original_code:
void
spectr_cut_range(struct spectrum *s, float inf, float sup)
{
    int j, jmin = -1, npt = 0;
    data_view_reset(s->table);
    for(j = 0; j < ((s)->table->rows); j++) {
        float lam = get_lambda_by_index(s, j);
        if(lam < inf || lam > sup) {
            continue;
        }
        if(jmin < 0) {
            jmin = j;
        }
        npt++;
    }
    data_view_set_mask_offset(s->table, jmin, jmin + npt);
}

canonical_original_code:
void spectr_cut_range(struct spectrum *s, float inf, float sup)
{
    int j; int jmin = -1; int npt = 0;
    data_view_reset(s->table);
    for(j = 0; j < ((s)->table->rows); j++) {
        float lam = get_lambda_by_index(s, j);
        if(lam < inf || lam > sup) {
            continue;
        }
        if(jmin < 0) {
            jmin = j;
        }
        npt++;
    }
    data_view_set_mask_offset(s->table, jmin, jmin + npt);
}

variable_types: inf float

variable_types: sup float

variable_types: j int

variable_types: jmin int

variable_types: npt int

variable_types: lam float


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

v2 = a1 + 32;
data_view_reset(a1 + 32);
if ( **(_DWORD **)(a1 + 56) >= (signed int)a2 )
return data_view_set_mask_offset(v2, 0LL, a2);
data_view_dealloc(v2);
*(_DWORD *)(a1 + 32) = a2;
result = data_table_new(a2, *(unsigned int *)(a1 + 36));
*(_QWORD *)(a1 + 56) = result;
return result;
}

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

v2 = a1 + 32;
data_view_reset(a1 + 32);
if ( **(_DWORD **)(a1 + 56) >= (signed int)a2 )
return data_view_set_mask_offset(v2, 0LL, a2);
data_view_dealloc(v2);
*(_DWORD *)(a1 + 32) = a2;
result = data_table_new(a2, *(unsigned int *)(a1 + 36));
*(_QWORD *)(a1 + 56) = result;
return result;
}

original_code:
void
spectra_resize(struct spectrum *s, int nr)
{
    struct data_view *dv = s->table;
    data_view_reset(dv);
    if(nr <= dv->table->rows) {
        data_view_set_mask_offset(dv, 0, nr);
    } else {
        data_view_dealloc(dv);
        dv->rows = nr;
        dv->table = data_table_new(nr, dv->columns);
    }
}

variable_types: nr int

variable_types: 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; } *


original_code:
float const *
spectra_get_values(struct spectrum const *s, int idx)
{
    return ((s->table)->table->heap + (s->table->map ? (s->table)->table->columns * ((s->table)->idx_start + (s->table)->map[idx]) + (0) : (s->table)->table->columns * ((s->table)->idx_start + (idx)) + (0)));
}

canonical_original_code:
float *spectra_get_values(struct spectrum *s, int idx)
{
    return ((s->table)->table->heap + (s->table->map ? (s->table)->table->columns * ((s->table)->idx_start + (s->table)->map[idx]) + (0) : (s->table)->table->columns * ((s->table)->idx_start + (idx)) + (0)));
}

return_type: float *


decompiled_code:
__int64 new_error_message(int a1, __int64 a2, ...)
{
__int64 v2; // rbx
gcc_va_list va; // [rsp+8h] [rbp-100h] BYREF
char v5[32]; // [rsp+20h] [rbp-E8h] BYREF

va_start(va, a2);
v2 = str_new();
str_init_from_c(v2, error_type_id[a1]);
str_init(v5, 64LL);
str_vprintf(v5, a2, 0LL, va);
str_append(v2, v5, 32LL);
str_free(v5);
return v2;
}

canonical_decompiled_code:
__int64 func0(int a1, __int64 a2, ...)
{
__int64 v2; // rbx
gcc_va_list va; // [rsp+8h] [rbp-100h] BYREF
char v5[32]; // [rsp+20h] [rbp-E8h] BYREF

va_start(va, a2);
v2 = str_new();
str_init_from_c(v2, error_type_id[a1]);
str_init(v5, 64LL);
str_vprintf(v5, a2, 0LL, va);
str_append(v2, v5, 32LL);
str_free(v5);
return v2;
}

original_code:
str_ptr
new_error_message(enum error_type_e etype, const char * msg, ...)
{
    str_ptr error_msg = str_new();
    str_t tail;
    va_list ap;
    str_init_from_c(error_msg, error_type_id[etype]);
    __builtin_va_start(ap,msg);
    str_init(tail, 64);
    str_vprintf(tail, msg, 0, ap);
    str_append(error_msg, tail, ' ');
    str_free(tail);
    __builtin_va_end(ap);
    return error_msg;
}

canonical_original_code:
struct _str *new_error_message(enum error_type_e etype, char *msg, ...)
{
    struct _str *error_msg = str_new();
    struct _str tail[1];
    __builtin_va_list ap;
    str_init_from_c(error_msg, error_type_id[etype]);
    __builtin_va_start(ap,msg);
    str_init(tail, 64);
    str_vprintf(tail, msg, 0, ap);
    str_append(error_msg, tail, ' ');
    str_free(tail);
    __builtin_va_end(ap);
    return error_msg;
}

variable_types: enum error_type_e { LOADING_FILE_ERROR=0, RECIPE_CHECK=1, FIT_ERROR=2 }

variable_types:
msg
char *

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

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


decompiled_code:
void __fastcall free_error_message(void *ptr)
{
str_free(ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
str_free(ptr);
free(ptr);
}

original_code:
void
free_error_message(str_ptr error_msg)
{
    str_free(error_msg);
    free(error_msg);
}

canonical_original_code:
void free_error_message(struct _str *error_msg)
{
    str_free(error_msg);
    free(error_msg);
}


decompiled_code:
__int64 __fastcall str_init_raw(__int64 *a1, __int64 a2)
{
unsigned __int64 v3; // rdi
__int64 result; // rax

v3 = (a2 + 8) & 0xFFFFFFFFFFFFFFF8LL;
if ( v3 < 8 )
v3 = 8LL;
a1[1] = v3;
result = emalloc();
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, __int64 a2)
{
unsigned __int64 v3; // rdi
__int64 result; // rax

v3 = (a2 + 8) & 0xFFFFFFFFFFFFFFF8LL;
if ( v3 < 8 )
v3 = 8LL;
a1[1] = v3;
result = emalloc();
*a1 = result;
return result;
}

original_code:
void
str_init_raw(str_ptr s, size_t len)
{
    const size_t alloc_size = (((len+1) + ((1 << 3) - 1)) & ~((1 << 3) - 1));
    s->size = (alloc_size >= 8 ? alloc_size : 8);
    s->heap = emalloc(s->size);
}

canonical_original_code:
void str_init_raw(struct _str *s, unsigned long len)
{
    unsigned long alloc_size = (((len+1) + ((1 << 3) - 1)) & ~((1 << 3) - 1));
    s->size = (alloc_size >= 8 ? alloc_size : 8);
    s->heap = emalloc(s->size);
}

variable_types:
len
unsigned long


decompiled_code:
size_t __fastcall str_init_view(const char **a1, const char *a2)
{
size_t result; // rax

*a1 = a2;
result = strlen(a2);
a1[2] = (const char *)result;
a1[1] = 0LL;
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(const char **a1, const char *a2)
{
size_t result; // rax

*a1 = a2;
result = strlen(a2);
a1[2] = (const char *)result;
a1[1] = 0LL;
return result;
}

original_code:
void
str_init_view(str_ptr s, const char *data)
{
    s->heap = (char *) data;
    s->length = strlen(data);
    s->size = 0;
}

canonical_original_code:
void str_init_view(struct _str *s, char *data)
{
    s->heap = (char *) data;
    s->length = strlen(data);
    s->size = 0;
}

variable_types:
data
char *


original_code:
str_ptr
str_new(void)
{
    str_ptr s = emalloc(sizeof(str_t));
    str_init_raw(s, 15);
    s->heap[0] = 0;
    s->length = 0;
    return s;
}

canonical_original_code:
struct _str *str_new()
{
    struct _str *s = emalloc(sizeof(str_t));
    str_init_raw(s, 15);
    s->heap[0] = 0;
    s->length = 0;
    return s;
}

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


decompiled_code:
void __fastcall str_free(__int64 a1)
{
if ( *(_QWORD *)(a1 + 8) )
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
if ( *(_QWORD *)(a1 + 8) )
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
}

original_code:
void
str_free(str_ptr s)
{
    if(s->size > 0) {
        free(s->heap);
    }
    s->heap = 0;
}

canonical_original_code:
void str_free(struct _str *s)
{
    if(s->size > 0) {
        free(s->heap);
    }
    s->heap = 0;
}


decompiled_code:
void __fastcall str_resize(__int64 *a1, __int64 a2)
{
void *v2; // rbp

if ( a1[1] )
{
v2 = (void *)*a1;
str_init_raw(a1, (unsigned __int64)(3 * a2) >> 1);
if ( v2 )
{
memcpy((void *)*a1, v2, a1[2] + 1);
free(v2);
}
}
else
{
str_init_raw(a1, (unsigned __int64)(3 * a2) >> 1);
}
}

original_code:
void
str_resize(str_t s, size_t len)
{
    char *old_heap = (s->size > 0 ? s->heap : ((void *)0));
    str_init_raw(s, (((len) * 3) / 2));
    if(old_heap) {
        memcpy(s->heap, old_heap, s->length+1);
        free(old_heap);
    }
}

canonical_original_code:
void str_resize(struct _str s[1], unsigned long len)
{
    char *old_heap = (s->size > 0 ? s->heap : ((void *)0));
    str_init_raw(s, (((len) * 3) / 2));
    if(old_heap) {
        memcpy(s->heap, old_heap, s->length+1);
        free(old_heap);
    }
}


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

if ( a2 >= 0 && a2 < (unsigned __int64)a1[2] )
{
result = *a1;
*(_BYTE *)(*a1 + a2) = 0;
a1[2] = a2;
}
return result;
}

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

if ( a2 >= 0 && a2 < (unsigned __int64)a1[2] )
{
result = *a1;
*(_BYTE *)(*a1 + a2) = 0;
a1[2] = a2;
}
return result;
}

original_code:
void
str_trunc(str_t s, int len)
{
    if(len < 0 || (size_t)len >= ((s)->length)) {
        return;
    }
    s->heap[len] = 0;
    s->length = len;
}

canonical_original_code:
void str_trunc(struct _str s[1], int len)
{
    if(len < 0 || (unsigned long)len >= ((s)->length)) {
        return;
    }
    s->heap[len] = 0;
    s->length = len;
}

variable_types: len int


decompiled_code:
void __fastcall str_vprintf(__int64 *a1, const char *a2, int a3, void *a4)
{
int v6; // eax
int v7; // ebx
int v8; // er15
char *ptr; // [rsp+8h] [rbp-80h]
char s[120]; // [rsp+10h] [rbp-78h] BYREF

v6 = vsnprintf(s, 0x40uLL, a2, a4);
v7 = v6;
if ( v6 > 63 )
{
v8 = v6 + 1;
ptr = (char *)emalloc((unsigned int)(v6 + 1));
vsnprintf(ptr, v8, a2, a4);
if ( a3 )
{
str_append_c(a1, ptr, 0);
free(ptr);
}
else
{
free((void *)*a1);
*a1 = (__int64)ptr;
a1[1] = v8;
a1[2] = v7;
}
}
else if ( a3 )
{
str_append_c(a1, s, 0);
}
else
{
str_copy_c_substr(a1, s, v6);
}
}

canonical_decompiled_code:
void __fastcall func18(__int64 *a1, const char *a2, int a3, void *a4)
{
int v6; // eax
int v7; // ebx
int v8; // er15
char *ptr; // [rsp+8h] [rbp-80h]
char s[120]; // [rsp+10h] [rbp-78h] BYREF

v6 = vsnprintf(s, 0x40uLL, a2, a4);
v7 = v6;
if ( v6 > 63 )
{
v8 = v6 + 1;
ptr = (char *)emalloc((unsigned int)(v6 + 1));
vsnprintf(ptr, v8, a2, a4);
if ( a3 )
{
func12(a1, ptr, 0);
free(ptr);
}
else
{
free((void *)*a1);
*a1 = (__int64)ptr;
a1[1] = v8;
a1[2] = v7;
}
}
else if ( a3 )
{
func12(a1, s, 0);
}
else
{
func11(a1, s, v6);
}
}

original_code:
void
str_vprintf(str_t d, const char *fmt, int append, va_list ap)
{
    char buffer[64];
    char *xbuf;
    int xbuf_size;
    int ns;
    ns = vsnprintf(buffer, 64, fmt, ap);
    if(ns >= 64) {
        xbuf_size = ns+1;
        xbuf = emalloc(xbuf_size);
        vsnprintf(xbuf, xbuf_size, fmt, ap);
    } else {
        xbuf = buffer;
        xbuf_size = 0;
    }
    if(append) {
        str_append_c(d, xbuf, 0);
        if(xbuf_size > 0) {
            free(xbuf);
        }
    } else {
        if(xbuf_size > 0) {
            free(d->heap);
            d->heap = xbuf;
            d->size = xbuf_size;
            d->length = ns;
        } else {
            str_copy_c_substr(d, xbuf, ns);
        }
    }
}

canonical_original_code:
void str_vprintf(struct _str d[1], char *fmt, int append, __builtin_va_list ap)
{
    char buffer[64];
    char *xbuf;
    int xbuf_size;
    int ns;
    ns = vsnprintf(buffer, 64, fmt, ap);
    if(ns >= 64) {
        xbuf_size = ns+1;
        xbuf = emalloc(xbuf_size);
        vsnprintf(xbuf, xbuf_size, fmt, ap);
    } else {
        xbuf = buffer;
        xbuf_size = 0;
    }
    if(append) {
        str_append_c(d, xbuf, 0);
        if(xbuf_size > 0) {
            free(xbuf);
        }
    } else {
        if(xbuf_size > 0) {
            free(d->heap);
            d->heap = xbuf;
            d->size = xbuf_size;
            d->length = ns;
        } else {
            str_copy_c_substr(d, xbuf, ns);
        }
    }
}

variable_types:
fmt
char *

variable_types: append int

variable_types:
buffer
char [64]

variable_types:
xbuf
char *

variable_types: ns int


decompiled_code:
void str_printf(__int64 *a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
str_vprintf(a1, a2, 0, va);
}

canonical_decompiled_code:
void func19(__int64 *a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
func18(a1, a2, 0, va);
}

original_code:
void
str_printf(str_t d, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    str_vprintf(d, fmt, 0, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void str_printf(struct _str d[1], char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    str_vprintf(d, fmt, 0, ap);
    __builtin_va_end(ap);
}


decompiled_code:
void str_printf_add(__int64 *a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
str_vprintf(a1, a2, 1, va);
}

canonical_decompiled_code:
void func20(__int64 *a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
func18(a1, a2, 1, va);
}

original_code:
void
str_printf_add(str_t d, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    str_vprintf(d, fmt, 1, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void str_printf_add(struct _str d[1], char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    str_vprintf(d, fmt, 1, ap);
    __builtin_va_end(ap);
}


decompiled_code:
__int64 __fastcall begin_write(__int64 a1)
{
int v1; // ebp
__int64 result; // rax

if ( *(_DWORD *)(a1 + 32) )
{
if ( *(int *)(a1 + 24) > 0 )
{
v1 = 0;
do
{
result = str_append_c(a1, &unk_1D9, 0LL);
++v1;
}
while ( *(_DWORD *)(a1 + 24) > v1 );
}
*(_DWORD *)(a1 + 32) = 0;
}
return result;
}

original_code:
static void
begin_write(writer_t *w)
{
    if (w->new_line) {
        int i;
        for (i = 0; i < w->indent; i++) {
            str_append_c(w->text, "  ", 0);
        }
        w->new_line = 0;
    }
}

canonical_original_code:
static void begin_write(struct _writer *w)
{
    if (w->new_line) {
        int i;
        for (i = 0; i < w->indent; i++) {
            str_append_c(w->text, "  ", 0);
        }
        w->new_line = 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: i int

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


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

v0 = (_DWORD *)emalloc(40LL);
str_init(v0, 1024LL);
v0[6] = 0;
v0[7] = 0;
v0[8] = 1;
return v0;
}

original_code:
writer_t *writer_new()
{
    writer_t *w = emalloc(sizeof(writer_t));
    str_init(w->text, 1024);
    w->indent = 0;
    w->single_line = 0;
    w->new_line = 1;
    return w;
}

canonical_original_code:
struct _writer *writer_new()
{
    struct _writer *w = emalloc(sizeof(writer_t));
    str_init(w->text, 1024);
    w->indent = 0;
    w->single_line = 0;
    w->new_line = 1;
    return w;
}

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


decompiled_code:
void __fastcall writer_free(void *ptr)
{
str_free();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
str_free();
free(ptr);
}

original_code:
void
writer_free(writer_t *w)
{
    str_free(w->text);
    free(w);
}

canonical_original_code:
void writer_free(struct _writer *w)
{
    str_free(w->text);
    free(w);
}


decompiled_code:
__int64 writer_printf(__int64 a1, __int64 a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a2);
begin_write(a1);
return str_vprintf(a1, a2, 1LL, va);
}

canonical_decompiled_code:
__int64 func3(__int64 a1, __int64 a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a2);
func0(a1);
return str_vprintf(a1, a2, 1LL, va);
}

original_code:
void
writer_printf(writer_t *w, const char *fmt, ...)
{
    va_list ap;
    begin_write(w);
    __builtin_va_start(ap,fmt);
    str_vprintf(w->text, fmt, 1, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void writer_printf(struct _writer *w, char *fmt, ...)
{
    __builtin_va_list ap;
    begin_write(w);
    __builtin_va_start(ap,fmt);
    str_vprintf(w->text, fmt, 1, ap);
    __builtin_va_end(ap);
}


decompiled_code:
__int64 __fastcall writer_newline(__int64 a1)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 28) )
return str_append_c(a1, &unk_1DC, 0LL);
result = str_append_c(a1, &unk_1DE, 0LL);
*(_DWORD *)(a1 + 32) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 28) )
return str_append_c(a1, &unk_1DC, 0LL);
result = str_append_c(a1, &unk_1DE, 0LL);
*(_DWORD *)(a1 + 32) = 1;
return result;
}

original_code:
void
writer_newline(writer_t *w)
{
    if (w->single_line) {
        str_append_c(w->text, " ", 0);
    } else {
        str_append_c(w->text, "\n", 0);
        w->new_line = 1;
    }
}

canonical_original_code:
void writer_newline(struct _writer *w)
{
    if (w->single_line) {
        str_append_c(w->text, " ", 0);
    } else {
        str_append_c(w->text, "\n", 0);
        w->new_line = 1;
    }
}


decompiled_code:
__int64 __fastcall writer_newline_enter(__int64 a1)
{
++*(_DWORD *)(a1 + 24);
return writer_newline(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
++*(_DWORD *)(a1 + 24);
return func4(a1);
}

original_code:
void
writer_newline_enter(writer_t *w)
{
    w->indent ++;
    writer_newline(w);
}

canonical_original_code:
void writer_newline_enter(struct _writer *w)
{
    w->indent ++;
    writer_newline(w);
}


decompiled_code:
__int64 __fastcall writer_newline_exit(__int64 a1)
{
--*(_DWORD *)(a1 + 24);
return writer_newline(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
--*(_DWORD *)(a1 + 24);
return func4(a1);
}

original_code:
void
writer_newline_exit(writer_t *w)
{
    w->indent --;
    writer_newline(w);
}

canonical_original_code:
void writer_newline_exit(struct _writer *w)
{
    w->indent --;
    writer_newline(w);
}


decompiled_code:
void __fastcall writer_indent(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 24) += a2;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 24) += a2;
}

original_code:
void
writer_indent(writer_t *w, int n)
{
    w->indent += n;
}

canonical_original_code:
void writer_indent(struct _writer *w, int n)
{
    w->indent += n;
}

variable_types: n int


decompiled_code:
__int64 __fastcall disp_fit_df(__int64 a1, _QWORD *a2, __int64 a3, double a4, double a5)
{
return disp_fit_fdf(a1, a2, 0LL, a3, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2, __int64 a3, double a4, double a5)
{
return func1(a1, a2, 0LL, a3, a4, a5);
}

original_code:
static int
disp_fit_df(const gsl_vector *x, void *_fit, gsl_matrix *j)
{
    return disp_fit_fdf(x, _fit, ((void *)0), j);
}

canonical_original_code:
static int disp_fit_df(struct gsl_vector *x, void *_fit, struct gsl_matrix *j)
{
    return disp_fit_fdf(x, _fit, ((void *)0), j);
}

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: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; } *

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 disp_fit_f(__int64 a1, _QWORD *a2, __int64 a3, double a4, double a5)
{
return disp_fit_fdf(a1, a2, a3, 0LL, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2, __int64 a3, double a4, double a5)
{
return func1(a1, a2, a3, 0LL, a4, a5);
}

original_code:
static int
disp_fit_f(const gsl_vector *x, void *_fit, gsl_vector *f)
{
    return disp_fit_fdf(x, _fit, f, ((void *)0));
}

canonical_original_code:
static int disp_fit_f(struct gsl_vector *x, void *_fit, struct gsl_vector *f)
{
    return disp_fit_fdf(x, _fit, f, ((void *)0));
}

variable_types:
f
struct gsl_vector *

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


decompiled_code:
__int64 __fastcall disp_fit_config_init(__int64 a1)
{
__int64 result; // rax

*(_DWORD *)a1 = 20;
result = LC0;
*(_QWORD *)(a1 + 8) = LC0;
*(_QWORD *)(a1 + 16) = LC1;
*(_QWORD *)(a1 + 24) = LC1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax

*(_DWORD *)a1 = 20;
result = LC0;
*(_QWORD *)(a1 + 8) = LC0;
*(_QWORD *)(a1 + 16) = LC1;
*(_QWORD *)(a1 + 24) = LC1;
return result;
}

original_code:
void
disp_fit_config_init(struct disp_fit_config *cfg)
{
    cfg->nb_max_iters = 20;
    cfg->chisq_norm_factor = 1.0;
    cfg->epsabs = 1e-6;
    cfg->epsrel = 1e-6;
}

variable_types: struct disp_fit_config { int nb_max_iters; double chisq_norm_factor; double epsabs; double epsrel; } *


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

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

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

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

variable_types:
params
void *


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

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

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

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

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:
int *__fastcall data_table_new(int a1, int a2)
{
int *result; // rax

if ( a1 <= 0 || a2 <= 0 )
_assert_fail("rows > 0 && columns > 0", "data-table.c", 0x36u, "data_table_new");
result = (int *)emalloc((unsigned int)(4 * a2 * a1 + 12));
*result = a1;
result[1] = a2;
result[2] = 1;
return result;
}

canonical_decompiled_code:
int *__fastcall func0(int a1, int a2)
{
int *result; // rax

if ( a1 <= 0 || a2 <= 0 )
_assert_fail("rows > 0 && columns > 0", "data-table.c", 0x36u, "data_table_new");
result = (int *)emalloc((unsigned int)(4 * a2 * a1 + 12));
*result = a1;
result[1] = a2;
result[2] = 1;
return result;
}

original_code:
struct data_table *
data_table_new(int rows, int columns) {
    struct data_table *r;
    int excess_size = rows * columns - 1;
    ((void) sizeof ((rows > 0 && columns > 0) ? 1 : 0), __extension__ ({ if (rows > 0 && columns > 0) ; else __assert_fail ("rows > 0 && columns > 0", "data-table.c", 54, __extension__ __PRETTY_FUNCTION__); }));
    r = emalloc(sizeof(struct data_table) + excess_size * sizeof(float));
    r->rows = rows;
    r->columns = columns;
    r->ref_count = 1;
    return r;
}

canonical_original_code:
struct data_table *data_table_new(int rows, int columns) {
    struct data_table *r;
    int excess_size = rows * columns - 1;
    ((void) sizeof ((rows > 0 && columns > 0) ? 1 : 0), __extension__ ({ if (rows > 0 && columns > 0) ; else __assert_fail ("rows > 0 && columns > 0", "data-table.c", 54, __extension__ __PRETTY_FUNCTION__); }));
    r = emalloc(sizeof(struct data_table) + excess_size * sizeof(float));
    r->rows = rows;
    r->columns = columns;
    r->ref_count = 1;
    return r;
}

variable_types: rows int

variable_types: columns int

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


decompiled_code:
void __fastcall data_table_unref(_DWORD *a1)
{
int v1; // eax
int v2; // eax

v1 = a1[2];
if ( v1 >= 0 )
{
v2 = v1 - 1;
a1[2] = v2;
if ( v2 < 0 )
_assert_fail("table->ref_count >= 0", "data-table.c", 0x4Bu, "data_table_unref");
if ( !v2 )
free(a1);
}
}

canonical_decompiled_code:
void __fastcall func2(_DWORD *a1)
{
int v1; // eax
int v2; // eax

v1 = a1[2];
if ( v1 >= 0 )
{
v2 = v1 - 1;
a1[2] = v2;
if ( v2 < 0 )
_assert_fail("table->ref_count >= 0", "data-table.c", 0x4Bu, "data_table_unref");
if ( !v2 )
free(a1);
}
}

original_code:
void
data_table_unref(struct data_table *table)
{
    if(table->ref_count < 0) {
        return;
    }
    table->ref_count --;
    ((void) sizeof ((table->ref_count >= 0) ? 1 : 0), __extension__ ({ if (table->ref_count >= 0) ; else __assert_fail ("table->ref_count >= 0", "data-table.c", 75, __extension__ __PRETTY_FUNCTION__); }));
    if(table->ref_count == 0) {
        free(table);
    }
}

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


decompiled_code:
__int64 __fastcall data_table_write(__int64 a1, unsigned int *a2)
{
int v2; // er13
int v4; // ebx

writer_printf(a1, "%d %d", *a2, a2[1]);
writer_newline(a1);
v2 = 0;
if ( (int)*a2 > 0 )
{
while ( 1 )
{
v4 = 0;
if ( (int)a2[1] > 0 )
{
while ( 1 )
{
writer_printf(a1, "%g", *(float *)&a2[v4 + a2[1] * v2 + 3]);
if ( (int)a2[1] <= ++v4 )
break;
if ( v4 > 0 )
writer_printf(a1, " ");
}
}
if ( (int)*a2 <= ++v2 )
break;
if ( v2 > 0 )
writer_newline(a1);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int *a2)
{
int v2; // er13
int v4; // ebx

writer_printf(a1, "%d %d", *a2, a2[1]);
writer_newline(a1);
v2 = 0;
if ( (int)*a2 > 0 )
{
while ( 1 )
{
v4 = 0;
if ( (int)a2[1] > 0 )
{
while ( 1 )
{
writer_printf(a1, "%g", *(float *)&a2[v4 + a2[1] * v2 + 3]);
if ( (int)a2[1] <= ++v4 )
break;
if ( v4 > 0 )
writer_printf(a1, " ");
}
}
if ( (int)*a2 <= ++v2 )
break;
if ( v2 > 0 )
writer_newline(a1);
}
}
return 0LL;
}

original_code:
int
data_table_write(writer_t *w, const struct data_table *dt)
{
    writer_printf(w, "%d %d", dt->rows, dt->columns);
    writer_newline(w);
    int i, j;
    for (i = 0; i < dt->rows; i++) {
        if (i > 0) {
            writer_newline(w);
        }
        for (j = 0; j < dt->columns; j++) {
            if (j > 0) {
                writer_printf(w, " ");
            }
            writer_printf(w, "%g", ((dt)->heap[(dt)->columns * (i) + (j)]));
        }
    }
    return 0;
}

canonical_original_code:
int data_table_write(struct _writer *w, struct data_table *dt)
{
    writer_printf(w, "%d %d", dt->rows, dt->columns);
    writer_newline(w);
    int i; int j;
    for (i = 0; i < dt->rows; i++) {
        if (i > 0) {
            writer_newline(w);
        }
        for (j = 0; j < dt->columns; j++) {
            if (j > 0) {
                writer_printf(w, " ");
            }
            writer_printf(w, "%g", ((dt)->heap[(dt)->columns * (i) + (j)]));
        }
    }
    return 0;
}

variable_types: j int


decompiled_code:
int *__fastcall data_table_read(__int64 a1)
{
int *v1; // r13
int v2; // er14
float *v3; // rbp
int v4; // er15
int v5; // ebx
float v6; // xmm0_4
double v8; // [rsp+0h] [rbp-48h] BYREF
int v9; // [rsp+8h] [rbp-40h] BYREF
int v10[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v1 = 0LL;
if ( !(unsigned int)lexer_integer(a1, v10) )
{
v2 = lexer_integer(a1, &v9);
if ( !v2 )
{
v1 = data_table_new(v10[0], v9);
v3 = (float *)(v1 + 3);
v4 = 0;
if ( v10[0] > 0 )
{
while ( 1 )
{
v5 = v2;
if ( v9 > 0 )
break;
LABEL_7:
if ( v10[0] <= ++v4 )
return v1;
}
while ( !(unsigned int)lexer_number(a1, &v8) )
{
v6 = v8;
*v3 = v6;
++v5;
++v3;
if ( v9 <= v5 )
goto LABEL_7;
}
data_table_unref(v1);
v1 = 0LL;
}
}
}
return v1;
}

canonical_decompiled_code:
int *__fastcall func4(__int64 a1)
{
int *v1; // r13
int v2; // er14
float *v3; // rbp
int v4; // er15
int v5; // ebx
float v6; // xmm0_4
double v8; // [rsp+0h] [rbp-48h] BYREF
int v9; // [rsp+8h] [rbp-40h] BYREF
int v10[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v1 = 0LL;
if ( !(unsigned int)lexer_integer(a1, v10) )
{
v2 = lexer_integer(a1, &v9);
if ( !v2 )
{
v1 = func0(v10[0], v9);
v3 = (float *)(v1 + 3);
v4 = 0;
if ( v10[0] > 0 )
{
while ( 1 )
{
v5 = v2;
if ( v9 > 0 )
break;
LABEL_7:
if ( v10[0] <= ++v4 )
return v1;
}
while ( !(unsigned int)lexer_number(a1, &v8) )
{
v6 = v8;
*v3 = v6;
++v5;
++v3;
if ( v9 <= v5 )
goto LABEL_7;
}
func2(v1);
v1 = 0LL;
}
}
}
return v1;
}

original_code:
struct data_table *
data_table_read(lexer_t *l)
{
    int rows, columns;
    if (lexer_integer(l, &rows)) return ((void *)0);
    if (lexer_integer(l, &columns)) return ((void *)0);
    int i, j;
    struct data_table *dt = data_table_new(rows, columns);
    float *p = dt->heap;
    for (i = 0; i < rows; i++) {
        for (j = 0; j < columns; j++, p++) {
            double x;
            if (lexer_number(l, &x)) goto table_exit;
            *p = x;
        }
    }
    return dt;
table_exit:
    data_table_unref(dt);
    return ((void *)0);
}

canonical_original_code:
struct data_table *data_table_read(struct lexer_t *l)
{
    int rows; int columns;
    if (lexer_integer(l, &rows)) return ((void *)0);
    if (lexer_integer(l, &columns)) return ((void *)0);
    int i; int j;
    struct data_table *dt = data_table_new(rows, columns);
    float *p = dt->heap;
    for (i = 0; i < rows; i++) {
        for (j = 0; j < columns; j++, p++) {
            double x;
            if (lexer_number(l, &x)) goto table_exit;
            *p = x;
        }
    }
    return dt;
table_exit:
    data_table_unref(dt);
    return ((void *)0);
}

variable_types: struct lexer_t { char *text; struct token_t { enum token_e { TK_UNDEF=0, TK_IDENT=1, TK_STRING=2, TK_EOF=3, TK_NUMBER=256, TK_INTEGER=257 } tk; union { double num; long integer; char *str; } value; } current; struct _str { char *heap; unsigned long size; unsigned long length; } buffer[1]; struct _str store[1]; } *

variable_types:
p
float *

variable_types: x double

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

user_defined_types: struct lexer_t { char *text; struct token_t current; struct _str buffer[1]; struct _str store[1]; }

user_defined_types: struct token_t { enum token_e tk; union { double num; long integer; char *str; } value; }


decompiled_code:
__m128 __fastcall egap_k(double a1, double a2, __m128 a3)
{
if ( a1 <= a2 )
a3 = 0LL;
return a3;
}

canonical_decompiled_code:
__m128 __fastcall func0(double a1, double a2, __m128 a3)
{
if ( a1 <= a2 )
a3 = 0LL;
return a3;
}

original_code:
static double egap_k(const double E, const double Eg, const double k)
{
    return (E > Eg ? k : 0.0);
}

canonical_original_code:
static double egap_k(double E, double Eg, double k)
{
    return (E > Eg ? k : 0.0);
}

variable_types: E double

variable_types: Eg double

variable_types: k double


decompiled_code:
double __fastcall pow2(double a1)
{
return a1 * a1;
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
return a1 * a1;
}

original_code: static inline double pow2(double x) { return x * x; }


decompiled_code:
double __fastcall pow4(double a1)
{
return a1 * a1 * (a1 * a1);
}

canonical_decompiled_code:
double __fastcall func2(double a1)
{
return a1 * a1 * (a1 * a1);
}

original_code:
static inline double pow4(double x)
{
    const double s = x * x;
    return s * s;
}

canonical_original_code:
static inline double pow4(double x)
{
    double s = x * x;
    return s * s;
}

variable_types: s double


decompiled_code:
__int64 __fastcall tauc_lorentz_encode_param(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = *(_DWORD *)(a2 + 12);
if ( !v2 )
return str_copy_c(a1, "EpsInf");
if ( v2 == 1 )
return str_copy_c(a1, "Eg");
return str_printf(a1, "%s:%i", tauc_lorentz_param_names[(v2 - 2) % 3]);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = *(_DWORD *)(a2 + 12);
if ( !v2 )
return str_copy_c(a1, "EpsInf");
if ( v2 == 1 )
return str_copy_c(a1, "Eg");
return str_printf(a1, "%s:%i", tauc_lorentz_param_names[(v2 - 2) % 3]);
}

original_code:
void
tauc_lorentz_encode_param(str_t param, const fit_param_t *fp)
{
    if (fp->param_nb == 0) {
        str_copy_c(param, "EpsInf");
    } else if (fp->param_nb == 1) {
        str_copy_c(param, "Eg");
    } else {
        int onb = (fp->param_nb - 2) / 3;
        int pnb = (fp->param_nb - 2) % 3;
        str_printf(param, "%s:%i", tauc_lorentz_param_names[pnb], onb);
    }
}

canonical_original_code:
void tauc_lorentz_encode_param(struct _str param[1], struct fit_param_t *fp)
{
    if (fp->param_nb == 0) {
        str_copy_c(param, "EpsInf");
    } else if (fp->param_nb == 1) {
        str_copy_c(param, "Eg");
    } else {
        int onb = (fp->param_nb - 2) / 3;
        int pnb = (fp->param_nb - 2) % 3;
        str_printf(param, "%s:%i", tauc_lorentz_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; }


original_code:
void tauc_lorentz_change_form(struct disp_fb *fb, int new_coeff_form)
{
    if (new_coeff_form == TAUC_LORENTZ_STANDARD) {
        int i;
        for (i = 0; i < fb->n; i++) {
            struct fb_osc *osc = &fb->osc[i];
            const double ALp = osc->a, Ep = osc->b, G = osc->c;
            const double Gqq = pow4(G);
            const double E0 = pow(pow4(Ep) + Gqq / 4, 0.25);
            const double C = sqrt(2 * ((E0) * (E0)) - 2 * ((Ep) * (Ep)));
            const double AL = ALp * Gqq / (4 * E0 * C);
            osc->a = AL;
            osc->b = E0;
            osc->c = C;
        }
    } else {
        int i;
        for (i = 0; i < fb->n; i++) {
            struct fb_osc *osc = &fb->osc[i];
            const double AL = osc->a, E0 = osc->b, C = osc->c;
            const double Cq = ((C) * (C));
            const double Gqq = (4 * ((E0) * (E0)) - Cq) * Cq;
            const double G = pow(Gqq, 0.25);
            const double Ep = sqrt(((E0) * (E0)) - Cq / 2);
            const double ALp = (4 * AL * E0 * C) / Gqq;
            osc->a = ALp;
            osc->b = Ep;
            osc->c = G;
        }
    }
}

canonical_original_code:
void tauc_lorentz_change_form(struct disp_fb *fb, int new_coeff_form)
{
    if (new_coeff_form == TAUC_LORENTZ_STANDARD) {
        int i;
        for (i = 0; i < fb->n; i++) {
            struct fb_osc *osc = &fb->osc[i];
            double ALp = osc->a; double Ep = osc->b; double G = osc->c;
            double Gqq = pow4(G);
            double E0 = pow(pow4(Ep) + Gqq / 4, 0.25);
            double C = sqrt(2 * ((E0) * (E0)) - 2 * ((Ep) * (Ep)));
            double AL = ALp * Gqq / (4 * E0 * C);
            osc->a = AL;
            osc->b = E0;
            osc->c = C;
        }
    } else {
        int i;
        for (i = 0; i < fb->n; i++) {
            struct fb_osc *osc = &fb->osc[i];
            double AL = osc->a; double E0 = osc->b; double C = osc->c;
            double Cq = ((C) * (C));
            double Gqq = (4 * ((E0) * (E0)) - Cq) * Cq;
            double G = pow(Gqq, 0.25);
            double Ep = sqrt(((E0) * (E0)) - Cq / 2);
            double ALp = (4 * AL * E0 * C) / Gqq;
            osc->a = ALp;
            osc->b = Ep;
            osc->c = G;
        }
    }
}

variable_types: struct disp_fb { short n; short form; double n_inf; double eg; struct fb_osc { double a; double b; double c; } *osc; } *

variable_types: i int

variable_types: ALp double

variable_types: Ep double

variable_types: G double

variable_types: Gqq double

variable_types: C double

variable_types: AL double

variable_types: Cq double

user_defined_types: struct disp_fb { short n; short form; double n_inf; double eg; struct fb_osc *osc; }


decompiled_code:
__int64 __fastcall lmfit_iter(__int64 a1, __int64 a2, __int64 a3, int a4, int *a5, __int64 (__fastcall *a6)(__int64, const char *, double), double a7, double a8, __int64 a9, unsigned int *a10)
{
unsigned int v13; // ebx
int v14; // er12
int v15; // er13
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // ebp
unsigned int v19; // er12
float v21; // [rsp+14h] [rbp-54h]

gsl_multifit_fdfsolver_set(a3, a2, a1);
v13 = 0;
if ( a6 )
v13 = a6(a9, "Running Levenberg-Marquardt search...", 0.0);
v14 = a4;
v21 = 1.0 / (float)a4;
v15 = 0;
while ( 1 )
{
v18 = v13;
if ( a6 )
v18 = a6(a9, 0LL, (float)((float)v15 * v21));
++v15;
v16 = gsl_multifit_fdfsolver_iterate(a3);
v13 = v16;
if ( v16 )
{
v19 = v16;
goto LABEL_11;
}
v17 = gsl_multifit_test_delta(*(_QWORD *)(a3 + 32), *(_QWORD *)(a3 + 16), a7, a8);
if ( v18 != 0 || v14 <= v15 )
break;
if ( v17 != -2 )
{
v19 = v17;
goto LABEL_11;
}
}
v19 = v17;
LABEL_11:
memcpy(*(void **)(a1 + 16), *(const void **)(*(_QWORD *)(a3 + 16) + 16LL), 8LL * *(_QWORD *)(a2 + 32));
*a5 = v15;
if ( a10 )
*a10 = v18;
return v19;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, int a4, int *a5, __int64 (__fastcall *a6)(__int64, const char *, double), double a7, double a8, __int64 a9, unsigned int *a10)
{
unsigned int v13; // ebx
int v14; // er12
int v15; // er13
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // ebp
unsigned int v19; // er12
float v21; // [rsp+14h] [rbp-54h]

gsl_multifit_fdfsolver_set(a3, a2, a1);
v13 = 0;
if ( a6 )
v13 = a6(a9, "Running Levenberg-Marquardt search...", 0.0);
v14 = a4;
v21 = 1.0 / (float)a4;
v15 = 0;
while ( 1 )
{
v18 = v13;
if ( a6 )
v18 = a6(a9, 0LL, (float)((float)v15 * v21));
++v15;
v16 = gsl_multifit_fdfsolver_iterate(a3);
v13 = v16;
if ( v16 )
{
v19 = v16;
goto LABEL_11;
}
v17 = gsl_multifit_test_delta(*(_QWORD *)(a3 + 32), *(_QWORD *)(a3 + 16), a7, a8);
if ( v18 != 0 || v14 <= v15 )
break;
if ( v17 != -2 )
{
v19 = v17;
goto LABEL_11;
}
}
v19 = v17;
LABEL_11:
memcpy(*(void **)(a1 + 16), *(const void **)(*(_QWORD *)(a3 + 16) + 16LL), 8LL * *(_QWORD *)(a2 + 32));
*a5 = v15;
if ( a10 )
*a10 = v18;
return v19;
}

original_code:
int
lmfit_iter(gsl_vector *x, gsl_multifit_function_fdf *f,
           gsl_multifit_fdfsolver *s, const int max_iter,
           double epsabs, double epsrel, int *nb_iter,
           gui_hook_func_t hfun, void *hdata, int *user_stop)
{
    int iter = 0, status;
    int stop_request = 0;
    gsl_multifit_fdfsolver_set(s, f, x);
    if(hfun) {
        stop_request = (*hfun)(hdata, 0.0, "Running Levenberg-Marquardt search...");
    }
    do {
        if(hfun) {
            stop_request = (*hfun)(hdata, iter / (float)max_iter, ((void *)0));
        }
        iter++;
        status = gsl_multifit_fdfsolver_iterate(s);
        if(status) {
            break;
        }
        status = gsl_multifit_test_delta(s->dx, s->x, epsabs, epsrel);
    } while(status == GSL_CONTINUE && iter < max_iter && !stop_request);
    memcpy(x->data, s->x->data, f->p * sizeof(double));
    *nb_iter = iter;
    if(user_stop) {
        *user_stop = stop_request;
    }
    return status;
}

canonical_original_code:
int lmfit_iter(struct gsl_vector *x, struct gsl_multifit_function_fdf_struct *f, struct gsl_multifit_fdfsolver *s, int max_iter, double epsabs, double epsrel, int *nb_iter, int (*hfun)(void *, float, char *), void *hdata, int *user_stop)
{
    int iter = 0; int status;
    int stop_request = 0;
    gsl_multifit_fdfsolver_set(s, f, x);
    if(hfun) {
        stop_request = (*hfun)(hdata, 0.0, "Running Levenberg-Marquardt search...");
    }
    do {
        if(hfun) {
            stop_request = (*hfun)(hdata, iter / (float)max_iter, ((void *)0));
        }
        iter++;
        status = gsl_multifit_fdfsolver_iterate(s);
        if(status) {
            break;
        }
        status = gsl_multifit_test_delta(s->dx, s->x, epsabs, epsrel);
    } while(status == GSL_CONTINUE && iter < max_iter && !stop_request);
    memcpy(x->data, s->x->data, f->p * sizeof(double));
    *nb_iter = iter;
    if(user_stop) {
        *user_stop = stop_request;
    }
    return status;
}

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: struct gsl_multifit_function_fdf_struct { int (*f)(struct gsl_vector *x, void *params, struct gsl_vector *f); int (*df)(struct gsl_vector *x, void *params, struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; } *df); int (*fdf)(struct gsl_vector *x, void *params, struct gsl_vector *f, struct gsl_matrix *df); unsigned long n; unsigned long p; void *params; unsigned long nevalf; unsigned long nevaldf; } *

variable_types: struct gsl_multifit_fdfsolver { struct gsl_multifit_fdfsolver_type { char *name; unsigned long size; int (*alloc)(void *state, unsigned long n, unsigned long p); int (*set)(void *state, struct gsl_vector *wts, struct gsl_multifit_function_fdf_struct *fdf, struct gsl_vector *x, struct gsl_vector *f, struct gsl_vector *dx); int (*iterate)(void *state, struct gsl_vector *wts, struct gsl_multifit_function_fdf_struct *fdf, struct gsl_vector *x, struct gsl_vector *f, struct gsl_vector *dx); int (*gradient)(void *state, struct gsl_vector *g); int (*jac)(void *state, struct gsl_matrix *J); void (*free)(void *state); } *type; struct gsl_multifit_function_fdf_struct *fdf; struct gsl_vector *x; struct gsl_vector *f; struct gsl_vector *dx; struct gsl_vector *g; struct gsl_vector *sqrt_wts; unsigned long niter; void *state; } *

variable_types: epsabs double

variable_types: epsrel double

variable_types:
hfun
int (*)(void *, float, char *)

variable_types:
hdata
void *

variable_types: iter int

variable_types: status int

user_defined_types: struct gsl_multifit_function_fdf_struct { int (*f)(struct gsl_vector *x, void *params, struct gsl_vector *f); int (*df)(struct gsl_vector *x, void *params, struct gsl_matrix *df); int (*fdf)(struct gsl_vector *x, void *params, struct gsl_vector *f, struct gsl_matrix *df); unsigned long n; unsigned long p; void *params; unsigned long nevalf; unsigned long nevaldf; }

user_defined_types: struct gsl_multifit_fdfsolver { struct gsl_multifit_fdfsolver_type *type; struct gsl_multifit_function_fdf_struct *fdf; struct gsl_vector *x; struct gsl_vector *f; struct gsl_vector *dx; struct gsl_vector *g; struct gsl_vector *sqrt_wts; unsigned long niter; void *state; }


decompiled_code:
__int64 __fastcall parse_int(_BYTE *a1, _DWORD *a2)
{
char v2; // al
_BYTE *v3; // rdx
unsigned int v4; // ecx

v2 = *a1;
if ( (unsigned __int8)(*a1 - 48) > 9u )
{
LODWORD(v3) = (_DWORD)a1;
v4 = 0;
}
else
{
v3 = a1;
v4 = 0;
do
{
v4 = v2 + 10 * v4 - 48;
v2 = *++v3;
}
while ( (unsigned __int8)(*v3 - 48) <= 9u );
}
*a2 = (_DWORD)v3 - (_DWORD)a1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, _DWORD *a2)
{
char v2; // al
_BYTE *v3; // rdx
unsigned int v4; // ecx

v2 = *a1;
if ( (unsigned __int8)(*a1 - 48) > 9u )
{
LODWORD(v3) = (_DWORD)a1;
v4 = 0;
}
else
{
v3 = a1;
v4 = 0;
do
{
v4 = v2 + 10 * v4 - 48;
v2 = *++v3;
}
while ( (unsigned __int8)(*v3 - 48) <= 9u );
}
*a2 = (_DWORD)v3 - (_DWORD)a1;
return v4;
}

original_code:
static int parse_int(const char *text, int *nread)
{
    int n = 0;
    const char *s = text;
    while ((int) *s >= (int) '0' && (int) *s <= (int) '9') {
        int d = (int) *s - (int) '0';
        n = 10 * n + d;
        s ++;
    }
    *nread = s - text;
    return n;
}

canonical_original_code:
static int parse_int(char *text, int *nread)
{
    int n = 0;
    char *s = text;
    while ((int) *s >= (int) '0' && (int) *s <= (int) '9') {
        int d = (int) *s - (int) '0';
        n = 10 * n + d;
        s ++;
    }
    *nread = s - text;
    return n;
}

variable_types:
text
char *

variable_types:
nread
int *

variable_types: n int

variable_types:
s
char *

variable_types: d int


original_code:
int parse_float(const char *text, unsigned int flags, float *value, int *n_parsed)
{
    const char *s = text;
    if (flags & PARSE_FLOAT_SKIP_SPACES) {
        s = skip_spaces(s);
    }
    int dec_pending = 1;
    int sign = 1;
    if (*s == '+' || *s == '-') {
        sign = (*s == '+' ? 1 : -1);
        s ++;
    }
    int nread;
    int int_part = parse_int(s, &nread);
    if (nread > 0) {
        dec_pending = 0;
    }
    s += nread;
    const char decimal_sym = (flags & PARSE_FLOAT_FRENCH_LOCALE ? ',' : '.');
    int dec_part = 0, dec_power = 0;
    if (*s == decimal_sym) {
        dec_part = parse_int(s + 1, &nread);
        if (nread > 0) {
            dec_pending = 0;
        }
        s += nread + 1;
        dec_power = nread;
    }
    if (dec_pending) return 1;
    int exp_int = 0;
    if (*s == 'e' || *s == 'E') {
        s ++;
        int esign = 1;
        if (*s == '+' || *s == '-') {
            esign = (*s == '+' ? 1 : -1);
            s ++;
        }
        exp_int = esign * parse_int(s, &nread);
        if (nread == 0) return 1;
        s += nread;
    }
    float x = sign * int_part + dec_part / ipowf(10.0, dec_power);
    if (exp_int >= 0) {
        *value = x * ipowf(10.0, exp_int);
    } else if (exp_int < 0) {
        *value = x / ipowf(10.0, - exp_int);
    }
    *n_parsed = s - text;
    return 0;
}

canonical_original_code:
int parse_float(char *text, unsigned int flags, float *value, int *n_parsed)
{
    char *s = text;
    if (flags & PARSE_FLOAT_SKIP_SPACES) {
        s = skip_spaces(s);
    }
    int dec_pending = 1;
    int sign = 1;
    if (*s == '+' || *s == '-') {
        sign = (*s == '+' ? 1 : -1);
        s ++;
    }
    int nread;
    int int_part = parse_int(s, &nread);
    if (nread > 0) {
        dec_pending = 0;
    }
    s += nread;
    char decimal_sym = (flags & PARSE_FLOAT_FRENCH_LOCALE ? ',' : '.');
    int dec_part = 0; int dec_power = 0;
    if (*s == decimal_sym) {
        dec_part = parse_int(s + 1, &nread);
        if (nread > 0) {
            dec_pending = 0;
        }
        s += nread + 1;
        dec_power = nread;
    }
    if (dec_pending) return 1;
    int exp_int = 0;
    if (*s == 'e' || *s == 'E') {
        s ++;
        int esign = 1;
        if (*s == '+' || *s == '-') {
            esign = (*s == '+' ? 1 : -1);
            s ++;
        }
        exp_int = esign * parse_int(s, &nread);
        if (nread == 0) return 1;
        s += nread;
    }
    float x = sign * int_part + dec_part / ipowf(10.0, dec_power);
    if (exp_int >= 0) {
        *value = x * ipowf(10.0, exp_int);
    } else if (exp_int < 0) {
        *value = x / ipowf(10.0, - exp_int);
    }
    *n_parsed = s - text;
    return 0;
}

variable_types:
flags
unsigned int

variable_types:
value
float *

variable_types: sign int

variable_types: nread int

variable_types: esign int

variable_types: x float


original_code:
int dispers_library_init()
{
    int status;
    status = load_library_from_data(app_lib, dispersions_data);
    if (status != 0) return status;
    status = load_library_from_data(preset_lib, preset_library_data);
    return status;
}


decompiled_code:
__int64 __fastcall print_vector(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 v4; // rbx

v4 = 0LL;
if ( *a3 )
{
while ( 1 )
{
gsl_vector_get(a3, v4);
str_printf_add(a1, a2);
if ( *a3 <= (unsigned __int64)++v4 )
break;
if ( v4 )
str_append_c(a1, &unk_1E5, 0LL);
}
}
return str_append_c(a1, &unk_1E7, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 v4; // rbx

v4 = 0LL;
if ( *a3 )
{
while ( 1 )
{
gsl_vector_get(a3, v4);
str_printf_add(a1, a2);
if ( *a3 <= (unsigned __int64)++v4 )
break;
if ( v4 )
str_append_c(a1, &unk_1E5, 0LL);
}
}
return str_append_c(a1, &unk_1E7, 0LL);
}

original_code:
void
print_vector(str_t s, const char *fmt, const gsl_vector *v)
{
    size_t j;
    for(j = 0; j < v->size; j++) {
        if(j > 0) {
            str_append_c(s, " ", 0);
        }
        str_printf_add(s, fmt, gsl_vector_get(v, j));
    }
    str_append_c(s, "\n", 0);
}

canonical_original_code:
void print_vector(struct _str s[1], char *fmt, struct gsl_vector *v)
{
    unsigned long j;
    for(j = 0; j < v->size; j++) {
        if(j > 0) {
            str_append_c(s, " ", 0);
        }
        str_printf_add(s, fmt, gsl_vector_get(v, j));
    }
    str_append_c(s, "\n", 0);
}

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

variable_types:
fmt
char *

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:
j
unsigned long


original_code:
void
print_matrix(str_t s, const char *fmt, const gsl_matrix *m)
{
    int field_size = 0;
    size_t i, j;
    size_t n1 = m->size1, n2 = m->size2;
    str_t number;
    str_init(number, 64);
    for(i = 0; i < n1; i++) {
        for(j = 0; j < n2; j++) {
            str_printf(number, fmt, gsl_matrix_get(m, i, j));
            if(((number)->length) > field_size) {
                field_size = ((number)->length);
            }
        }
    }
    for(i = 0; i < n1; i++) {
        str_append_c(s, "|", 0);
        for(j = 0; j < n2; j++) {
            if(j > 0) {
                str_append_c(s, " ", 0);
            }
            str_printf(number, fmt, gsl_matrix_get(m, i, j));
            str_pad(number, field_size, ' ');
            str_append(s, number, 0);
        }
        str_append_c(s, "|\n", 0);
    }
    str_free(number);
}

canonical_original_code:
void print_matrix(struct _str s[1], char *fmt, struct gsl_matrix *m)
{
    int field_size = 0;
    unsigned long i; unsigned long j;
    unsigned long n1 = m->size1; unsigned long n2 = m->size2;
    struct _str number[1];
    str_init(number, 64);
    for(i = 0; i < n1; i++) {
        for(j = 0; j < n2; j++) {
            str_printf(number, fmt, gsl_matrix_get(m, i, j));
            if(((number)->length) > field_size) {
                field_size = ((number)->length);
            }
        }
    }
    for(i = 0; i < n1; i++) {
        str_append_c(s, "|", 0);
        for(j = 0; j < n2; j++) {
            if(j > 0) {
                str_append_c(s, " ", 0);
            }
            str_printf(number, fmt, gsl_matrix_get(m, i, j));
            str_pad(number, field_size, ' ');
            str_append(s, number, 0);
        }
        str_append_c(s, "|\n", 0);
    }
    str_free(number);
}

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:
i
unsigned long

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


original_code:
int
batch_descr_parse(const char *descr, struct spectra_lst *bspec,
                  int extended)
{
    const char *ptr = descr;
    char ifmt[5];
    char *next;
    int digits, slen;
    if(strchr(descr, (int) '%')) {
        return 1;
    }
    str_copy_c(bspec->name, ptr);
    next = strchr(ptr, (int) '#');
    if(! next) {
        return 1;
    }
    str_trunc(bspec->name, next - ptr);
    ptr = next;
    while(*next == '#') {
        next++;
    }
    digits = next - ptr;
    if(digits <= 0 || digits > 9) {
        return 1;
    }
    sprintf(ifmt, "%%0%ii", digits);
    str_append_c(bspec->name, ifmt, 0);
    slen = ((bspec->name)->length);
    str_append_c(bspec->name, next, 0);
    if(extended) {
        ptr = next;
        next = strchr(ptr, (int) '[');
        if(! next) {
            return 1;
        }
        slen += next - ptr;
        str_trunc(bspec->name, slen);
        bspec->length = next - descr;
        ptr = next + 1;
        bspec->start = strtol(ptr, &next, 10);
        if(*next != '-') {
            return 1;
        }
        ptr = next + 1;
        bspec->stop = strtol(ptr, &next, 10);
        if(*next == ',') {
            ptr = next + 1;
            bspec->stride = strtol(ptr, &next, 10);
            if(! next) {
                return 1;
            }
        } else {
            bspec->stride = 1;
        }
        if(*next == ']') {
            return 0;
        }
        return 1;
    } else {
        bspec->start = bspec->stop = 0;
        bspec->stride = 1;
    }
    return 0;
}

canonical_original_code:
int batch_descr_parse(char *descr, struct spectra_lst *bspec, int extended)
{
    char *ptr = descr;
    char ifmt[5];
    char *next;
    int digits; int slen;
    if(strchr(descr, (int) '%')) {
        return 1;
    }
    str_copy_c(bspec->name, ptr);
    next = strchr(ptr, (int) '#');
    if(! next) {
        return 1;
    }
    str_trunc(bspec->name, next - ptr);
    ptr = next;
    while(*next == '#') {
        next++;
    }
    digits = next - ptr;
    if(digits <= 0 || digits > 9) {
        return 1;
    }
    sprintf(ifmt, "%%0%ii", digits);
    str_append_c(bspec->name, ifmt, 0);
    slen = ((bspec->name)->length);
    str_append_c(bspec->name, next, 0);
    if(extended) {
        ptr = next;
        next = strchr(ptr, (int) '[');
        if(! next) {
            return 1;
        }
        slen += next - ptr;
        str_trunc(bspec->name, slen);
        bspec->length = next - descr;
        ptr = next + 1;
        bspec->start = strtol(ptr, &next, 10);
        if(*next != '-') {
            return 1;
        }
        ptr = next + 1;
        bspec->stop = strtol(ptr, &next, 10);
        if(*next == ',') {
            ptr = next + 1;
            bspec->stride = strtol(ptr, &next, 10);
            if(! next) {
                return 1;
            }
        } else {
            bspec->stride = 1;
        }
        if(*next == ']') {
            return 0;
        }
        return 1;
    } else {
        bspec->start = bspec->stop = 0;
        bspec->stride = 1;
    }
    return 0;
}

variable_types:
descr
char *

variable_types: struct spectra_lst { int single_file; struct _str { char *heap; unsigned long size; unsigned long length; } name[1]; int start; int stride; int length; } *

variable_types: extended int

variable_types:
ptr
char *

variable_types:
ifmt
char [5]

variable_types:
next
char *

variable_types: digits int

variable_types: slen int

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


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

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

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

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

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

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

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

variable_types:
iter
int *


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

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

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

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

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

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

variable_types:
base
char *

variable_types:
p
char *

variable_types: len int


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

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

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

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

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

variable_types:
id
char *


decompiled_code:
__int64 __fastcall set_range(__int64 a1, double a2, double a3)
{
float v3; // xmm2_4
float v4; // xmm2_4
__int64 result; // rax
float v6; // xmm1_4

v3 = a2;
*(float *)(a1 + 4) = v3;
v4 = a3;
*(float *)(a1 + 8) = v4;
result = (unsigned int)(*(_DWORD *)a1 - 1);
v6 = (a3 - a2) / (double)(int)result;
*(float *)(a1 + 12) = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, double a2, double a3)
{
float v3; // xmm2_4
float v4; // xmm2_4
__int64 result; // rax
float v6; // xmm1_4

v3 = a2;
*(float *)(a1 + 4) = v3;
v4 = a3;
*(float *)(a1 + 8) = v4;
result = (unsigned int)(*(_DWORD *)a1 - 1);
v6 = (a3 - a2) / (double)(int)result;
*(float *)(a1 + 12) = v6;
return result;
}

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

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

variable_types: lmin double

variable_types: lmax double

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


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

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

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

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

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

variable_types: points int


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

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

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

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

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

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

variable_types: struct _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: nb int