decompiled_code:
void __fastcall ct_valgrind_for_loop(int a1, void (__fastcall *a2)(_QWORD, __int64), __int64 a3)
{
__int64 v4; // rax
unsigned int *v5; // rbp
unsigned int *v6; // r15
unsigned int v7; // ebx
void *ptr; // [rsp+8h] [rbp-40h]

ct_valgrind_int(8, 0);
ct_valgrind_cmd("setactiv");
v4 = ct_rand_perm((unsigned int)a1);
ptr = (void *)v4;
if ( a1 > 0 )
{
v5 = (unsigned int *)v4;
v6 = (unsigned int *)(v4 + 4LL * (unsigned int)a1);
do
{
v7 = *v5;
ct_valgrind_int(4, (int)*v5 % 254);
ct_valgrind_cmd("thrd");
ct_valgrind_int(4, v7);
ct_valgrind_cmd("iter");
a2(v7, a3);
ct_valgrind_int(4, v7);
ct_valgrind_cmd("done");
++v5;
}
while ( v5 != v6 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(int a1, void (__fastcall *a2)(_QWORD, __int64), __int64 a3)
{
__int64 v4; // rax
unsigned int *v5; // rbp
unsigned int *v6; // r15
unsigned int v7; // ebx
void *ptr; // [rsp+8h] [rbp-40h]

ct_valgrind_int(8, 0);
func3("setactiv");
v4 = ct_rand_perm((unsigned int)a1);
ptr = (void *)v4;
if ( a1 > 0 )
{
v5 = (unsigned int *)v4;
v6 = (unsigned int *)(v4 + 4LL * (unsigned int)a1);
do
{
v7 = *v5;
ct_valgrind_int(4, (int)*v5 % 254);
func3("thrd");
ct_valgrind_int(4, v7);
func3("iter");
a2(v7, a3);
ct_valgrind_int(4, v7);
func3("done");
++v5;
}
while ( v5 != v6 );
}
free(ptr);
}

original_code:
void ct_valgrind_for_loop(int n, ct_ind_func f, void* context, ct_canceller* c) {
    int i;
    int* perm;
    ct_valgrind_int(8, 0);
    ct_valgrind_cmd("setactiv");
    perm = ct_rand_perm(n);
    for(i=0; i<n; ++i) {
        int ind = perm[i];
        ct_valgrind_int(4, ind%254);
        ct_valgrind_cmd("thrd");
        ct_valgrind_int(4, ind);
        ct_valgrind_cmd("iter");
        f(ind, context);
        ct_valgrind_int(4, ind);
        ct_valgrind_cmd("done");
    }
    free(perm);
}

canonical_original_code:
void ct_valgrind_for_loop(int n, void (*f)(int ind, void *context), void *context, struct ct_canceller *c) {
    int i;
    int *perm;
    ct_valgrind_int(8, 0);
    ct_valgrind_cmd("setactiv");
    perm = ct_rand_perm(n);
    for(i=0; i<n; ++i) {
        int ind = perm[i];
        ct_valgrind_int(4, ind%254);
        ct_valgrind_cmd("thrd");
        ct_valgrind_int(4, ind);
        ct_valgrind_cmd("iter");
        f(ind, context);
        ct_valgrind_int(4, ind);
        ct_valgrind_cmd("done");
    }
    free(perm);
}

variable_types: n int

variable_types:
f
void (*)(int ind, void *context)

variable_types:
context
void *

variable_types: struct ct_canceller { int cancelled; void *sched_data; } *

variable_types:
perm
int *

variable_types: ind int


repo: yosefk/checkedthreads

decompiled_code:
void *__fastcall ct_valgrind_for(unsigned int a1, __int64 a2, __int64 a3, __int64 a4)
{
int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v7[0] = 0;
ct_valgrind_cmd("begin_for");
ct_valgrind_ptr(8, (__int64)v7);
ct_valgrind_cmd("stackbot");
g_ct_valgrind_for(a1, a2, a3, a4);
return ct_valgrind_cmd("end_for");
}

canonical_decompiled_code:
void *__fastcall func5(unsigned int a1, __int64 a2, __int64 a3, __int64 a4)
{
int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v7[0] = 0;
func3("begin_for");
func2(8, (__int64)v7);
func3("stackbot");
g_ct_valgrind_for(a1, a2, a3, a4);
return func3("end_for");
}

original_code:
void ct_valgrind_for(int n, ct_ind_func f, void* context, ct_canceller* c) {
    volatile int local=0;
    ct_valgrind_cmd("begin_for");
    ct_valgrind_ptr(8, &local);
    ct_valgrind_cmd("stackbot");
    (*g_ct_valgrind_for)(n,f,context,c);
    ct_valgrind_cmd("end_for");
}

canonical_original_code:
void ct_valgrind_for(int n, void (*f)(int ind, void *context), void *context, struct ct_canceller *c) {
    int local = 0;
    ct_valgrind_cmd("begin_for");
    ct_valgrind_ptr(8, &local);
    ct_valgrind_cmd("stackbot");
    (*g_ct_valgrind_for)(n,f,context,c);
    ct_valgrind_cmd("end_for");
}

variable_types: local int

return_type: void

user_defined_types: struct ct_canceller { int cancelled; void *sched_data; }


decompiled_code:
__int64 __fastcall ct_debug_get_owner(__int64 a1)
{
__int64 result; // rax
int i; // [rsp+Ch] [rbp-Ch]

ct_valgrind_ptr(8, a1);
ct_valgrind_cmd("getowner");
for ( i = 0; i <= 4; ++i )
;
if ( g_ct_valgrind_cmd[0] == 305419896 )
result = 4294967294LL;
else
result = g_ct_valgrind_cmd[0];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 result; // rax
int i; // [rsp+Ch] [rbp-Ch]

func2(8, a1);
func3("getowner");
for ( i = 0; i <= 4; ++i )
;
if ( g_ct_valgrind_cmd[0] == 305419896 )
result = 4294967294LL;
else
result = g_ct_valgrind_cmd[0];
return result;
}

original_code:
int ct_debug_get_owner(const void* addr) {
    volatile int i,m;
    ct_valgrind_ptr(8, addr);
    ct_valgrind_cmd("getowner");
    for(i=0; i<5; ++i) {
        m = g_ct_valgrind_cmd.stored_magic;
    }
    return g_ct_valgrind_cmd.stored_magic == 0x12345678 ? (-2) : g_ct_valgrind_cmd.stored_magic;
}

canonical_original_code:
int ct_debug_get_owner(void *addr) {
    int i; int m;
    ct_valgrind_ptr(8, addr);
    ct_valgrind_cmd("getowner");
    for(i=0; i<5; ++i) {
        m = g_ct_valgrind_cmd.stored_magic;
    }
    return g_ct_valgrind_cmd.stored_magic == 0x12345678 ? (-2) : g_ct_valgrind_cmd.stored_magic;
}

variable_types:
addr
void *

variable_types: i int

variable_types: m int

return_type: int


decompiled_code:
void ct_serial_init()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void ct_serial_init(const ct_env_var* env) {
    (void)env;
}

canonical_original_code:
void ct_serial_init(struct ct_env_var *env) {
    (void)env;
}

variable_types: struct ct_env_var { char *name; char *value; } *


decompiled_code:
void ct_serial_fini()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void ct_serial_fini(void) {
}

canonical_original_code:
void ct_serial_fini() {
}


decompiled_code:
__int64 __fastcall ct_serial_for(int a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, unsigned int *a4)
{
unsigned int i; // ebx
__int64 result; // rax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
result = *a4;
if ( (_DWORD)result )
break;
result = a2(i, a3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, unsigned int *a4)
{
unsigned int i; // ebx
__int64 result; // rax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
result = *a4;
if ( (_DWORD)result )
break;
result = a2(i, a3);
}
}
return result;
}

original_code:
void ct_serial_for(int n, ct_ind_func f, void* context, ct_canceller* c) {
    int i;
    for(i=0; i<n; ++i) {
        if(c->cancelled) {
            break;
        }
        f(i, context);
    }
}

canonical_original_code:
void ct_serial_for(int n, void (*f)(int ind, void *context), void *context, struct ct_canceller *c) {
    int i;
    for(i=0; i<n; ++i) {
        if(c->cancelled) {
            break;
        }
        f(i, context);
    }
}


decompiled_code:
void *__fastcall child_fn(void *a1)
{
set_by_child = 1;
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
set_by_child = 1;
return 0LL;
}

original_code:
void* child_fn(void* arg) {
    set_by_child = 1;
    return 0;
}

canonical_original_code:
void *child_fn(void *arg) {
    set_by_child = 1;
    return 0;
}

variable_types:
arg
void *

return_type: void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_attr_t v4; // [rsp+0h] [rbp-48h] BYREF
pthread_t newthread[2]; // [rsp+38h] [rbp-10h] BYREF

pthread_attr_init(&v4);
pthread_attr_setdetachstate(&v4, 0);
pthread_create(newthread, &v4, child_fn, 0LL);
pthread_join(newthread[0], 0LL);
if ( set_by_child == 1 )
puts("pthreads test passed");
else
puts("set_by_child not set by child!");
return 0;
}

original_code:
int main() {
    pthread_t child;
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    pthread_create(&child, &attr, child_fn, 0);
    pthread_join(child, 0);
    if(set_by_child == 1) {
        printf("pthreads test passed\n");
    }
    else {
        printf("set_by_child not set by child!\n");
    }
}

canonical_original_code:
int main() {
    unsigned long child;
    union pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    pthread_create(&child, &attr, child_fn, 0);
    pthread_join(child, 0);
    if(set_by_child == 1) {
        printf("pthreads test passed\n");
    }
    else {
        printf("set_by_child not set by child!\n");
    }
}

variable_types:
child
unsigned long

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


decompiled_code:
__int64 run_omp_for()
{
return GOMP_parallel();
}

canonical_decompiled_code:
__int64 func8()
{
return GOMP_parallel();
}

original_code:
void run_omp_for(void) {
    int i;

#pragma omp parallel for
    for(i=0; i<100; ++i) {
        data_arr[i]=i;
        int tn = omp_get_thread_num();
        if(tn >= 0 && tn < 100) {
            thread_hist[tn]++;
        }
    }
}

canonical_original_code:
void run_omp_for() {
    int i;

#pragma omp parallel for
    for(i=0; i<100; ++i) {
        data_arr[i]=i;
        int tn = omp_get_thread_num();
        if(tn >= 0 && tn < 100) {
            thread_hist[tn]++;
        }
    }
}

variable_types: tn int


decompiled_code:
int test_omp_results()
{
__int64 i; // rax
__int64 j; // rbx
__int64 v2; // rdx

for ( i = 0LL; i != 100; ++i )
{
if ( data_arr[i] != (_DWORD)i )
{
printf("wrong result at %d\n", (unsigned int)i);
exit(1);
}
}
for ( j = 0LL; j != 100; ++j )
{
v2 = (unsigned int)thread_hist[j];
if ( (_DWORD)v2 )
printf("OpenMP thread %d used %d times\n", (unsigned int)j, v2);
}
return puts("OpenMP test passed");
}

canonical_decompiled_code:
int func9()
{
__int64 i; // rax
__int64 j; // rbx
__int64 v2; // rdx

for ( i = 0LL; i != 100; ++i )
{
if ( data_arr[i] != (_DWORD)i )
{
printf("wrong result at %d\n", (unsigned int)i);
exit(1);
}
}
for ( j = 0LL; j != 100; ++j )
{
v2 = (unsigned int)thread_hist[j];
if ( (_DWORD)v2 )
printf("OpenMP thread %d used %d times\n", (unsigned int)j, v2);
}
return puts("OpenMP test passed");
}

original_code:
void test_omp_results() {
    int i;
    for(i=0; i<100; ++i) {
        if(data_arr[i] != i) {
            printf("wrong result at %d\n", i);
            exit(1);
        }
    }
    for(i=0; i<100; ++i) {
        if(thread_hist[i] != 0) {
            printf("OpenMP thread %d used %d times\n", i, thread_hist[i]);
        }
    }
    printf("OpenMP test passed\n");
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
run_omp_for(argc, argv, envp);
test_omp_results();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8(argc, argv, envp);
func9();
return 0;
}

original_code:
int main() {
    run_omp_for();
    test_omp_results();
}


decompiled_code:
void ct_shuffle_fini()
{
;
}

original_code:
void ct_shuffle_fini(void) {
}

canonical_original_code:
void ct_shuffle_fini() {
}


decompiled_code:
int __fastcall ct_shuffle_init(__int64 a1)
{
const char *v1; // rax
int v2; // eax
const char *v3; // rax
int result; // eax

v1 = (const char *)ct_getenv(a1, "CT_RAND_SEED", "12345");
v2 = atoi(v1);
srand(v2);
v3 = (const char *)ct_getenv(a1, "CT_RAND_REV", "0");
result = atoi(v3);
g_ct_random_reverse = result;
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
const char *v1; // rax
int v2; // eax
const char *v3; // rax
int result; // eax

v1 = (const char *)ct_getenv(a1, "CT_RAND_SEED", "12345");
v2 = atoi(v1);
srand(v2);
v3 = (const char *)ct_getenv(a1, "CT_RAND_REV", "0");
result = atoi(v3);
g_ct_random_reverse = result;
return result;
}

original_code:
void ct_shuffle_init(const ct_env_var* env) {
    srand(atoi(ct_getenv(env, "CT_RAND_SEED", "12345")));
    g_ct_random_reverse = atoi(ct_getenv(env, "CT_RAND_REV", "0"));
}

canonical_original_code:
void ct_shuffle_init(struct ct_env_var *env) {
    srand(atoi(ct_getenv(env, "CT_RAND_SEED", "12345")));
    g_ct_random_reverse = atoi(ct_getenv(env, "CT_RAND_REV", "0"));
}

user_defined_types: struct ct_env_var { char *name; char *value; }


original_code:
void ct_random_shuffle(int* p, int n) {
    int i;
    for(i=1; i<n; ++i) {
        int j = rand() % (i+1);
        int tmp = p[j];
        p[j] = p[i];
        p[i] = tmp;
    }
}

canonical_original_code:
void ct_random_shuffle(int *p, int n) {
    int i;
    for(i=1; i<n; ++i) {
        int j = rand() % (i+1);
        int tmp = p[j];
        p[j] = p[i];
        p[i] = tmp;
    }
}

variable_types:
p
int *

variable_types: j int

variable_types: tmp int


decompiled_code:
void __fastcall ct_shuffle_for(int a1, void (__fastcall *a2)(_QWORD, __int64), __int64 a3, _DWORD *a4)
{
_DWORD *v6; // rax
void *v7; // r15
unsigned int *v8; // rbx
unsigned int *v9; // r14

v6 = ct_rand_perm(a1);
v7 = v6;
if ( a1 > 0 )
{
v8 = v6;
v9 = &v6[a1];
do
{
if ( *a4 )
break;
a2(*v8++, a3);
}
while ( v8 != v9 );
}
free(v7);
}

canonical_decompiled_code:
void __fastcall func3(int a1, void (__fastcall *a2)(_QWORD, __int64), __int64 a3, _DWORD *a4)
{
_DWORD *v6; // rax
void *v7; // r15
unsigned int *v8; // rbx
unsigned int *v9; // r14

v6 = ct_rand_perm(a1);
v7 = v6;
if ( a1 > 0 )
{
v8 = v6;
v9 = &v6[a1];
do
{
if ( *a4 )
break;
a2(*v8++, a3);
}
while ( v8 != v9 );
}
free(v7);
}

original_code:
void ct_shuffle_for(int n, ct_ind_func f, void* context, ct_canceller* c) {
    int* perm = ct_rand_perm(n);
    int i;
    for(i=0; i<n; ++i) {
        if(c->cancelled) {
            break;
        }
        f(perm[i], context);
    }
    free(perm);
}

canonical_original_code:
void ct_shuffle_for(int n, void (*f)(int ind, void *context), void *context, struct ct_canceller *c) {
    int *perm = ct_rand_perm(n);
    int i;
    for(i=0; i<n; ++i) {
        if(c->cancelled) {
            break;
        }
        f(perm[i], context);
    }
    free(perm);
}

variable_types: n int

variable_types:
f
void (*)(int ind, void *context)


decompiled_code:
__int64 ct_nprocs()
{
return sysconf(84);
}

canonical_decompiled_code:
__int64 func0()
{
return sysconf(84);
}

original_code:
int ct_nprocs() {
    return sysconf( _SC_NPROCESSORS_ONLN );
}


decompiled_code:
__int64 __fastcall ct_work(int *a1)
{
int v2; // ebp
void (__fastcall *v3)(__int64, __int64); // r13
__int64 v4; // r12
__int64 result; // rax
__int64 v6; // rdi
unsigned int *v7; // rax

v2 = a1[2];
v3 = (void (__fastcall *)(__int64, __int64))*((_QWORD *)a1 + 2);
v4 = *((_QWORD *)a1 + 3);
while ( 1 )
{
result = (unsigned int)*a1;
if ( (int)result >= v2 )
break;
v6 = (unsigned int)_InterlockedExchangeAdd(a1, 1u);
if ( v2 > (int)v6 )
{
v7 = (unsigned int *)*((_QWORD *)a1 + 4);
if ( v7 )
{
result = *v7;
if ( (_DWORD)result )
{
a1[1] = 0;
*a1 = v2;
return result;
}
}
v3(v6, v4);
_InterlockedSub(a1 + 1, 1u);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
int v2; // ebp
void (__fastcall *v3)(__int64, __int64); // r13
__int64 v4; // r12
__int64 result; // rax
__int64 v6; // rdi
unsigned int *v7; // rax

v2 = a1[2];
v3 = (void (__fastcall *)(__int64, __int64))*((_QWORD *)a1 + 2);
v4 = *((_QWORD *)a1 + 3);
while ( 1 )
{
result = (unsigned int)*a1;
if ( (int)result >= v2 )
break;
v6 = (unsigned int)_InterlockedExchangeAdd(a1, 1u);
if ( v2 > (int)v6 )
{
v7 = (unsigned int *)*((_QWORD *)a1 + 4);
if ( v7 )
{
result = *v7;
if ( (_DWORD)result )
{
a1[1] = 0;
*a1 = v2;
return result;
}
}
v3(v6, v4);
_InterlockedSub(a1 + 1, 1u);
}
}
return result;
}

original_code:
void ct_work(ct_work_item* item) {
    int n = item->n;
    ct_ind_func f = item->f;
    void* context = item->context;
    while(item->next_ind < n) {
        int next_ind = __sync_fetch_and_add(&item->next_ind,1);
        if(next_ind < n) {
            ct_canceller* canceller = item->canceller;
            if(canceller && canceller->cancelled) {
                item->to_do = 0;
                item->next_ind = n;
                break;
            }
            f(next_ind, context);
            __sync_fetch_and_sub(&item->to_do,1);
        }
    }
}

canonical_original_code:
void ct_work(struct ct_work_item *item) {
    int n = item->n;
    void (*f)(int ind, void *context) = item->f;
    void *context = item->context;
    while(item->next_ind < n) {
        int next_ind = __sync_fetch_and_add(&item->next_ind,1);
        if(next_ind < n) {
            struct ct_canceller *canceller = item->canceller;
            if(canceller && canceller->cancelled) {
                item->to_do = 0;
                item->next_ind = n;
                break;
            }
            f(next_ind, context);
            __sync_fetch_and_sub(&item->to_do,1);
        }
    }
}

variable_types: struct ct_work_item { int next_ind; int to_do; int n; int ref_cnt; void (*f)(int ind, void *context); void *context; struct ct_canceller { int cancelled; void *sched_data; } *canceller; } *

variable_types:
context
void *

user_defined_types: struct ct_work_item { int next_ind; int to_do; int n; int ref_cnt; void (*f)(int ind, void *context); void *context; struct ct_canceller *canceller; }


decompiled_code:
char *__fastcall get_message(int a1)
{
char *result; // rax

if ( a1 > 80 )
return 0LL;
if ( !loaded_language || !*(_QWORD *)loaded_language )
return en_messages[a1];
result = *(char **)(*(_QWORD *)loaded_language + 8LL * a1);
if ( !result )
result = en_messages[a1];
return result;
}

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

if ( a1 > 80 )
return 0LL;
if ( !loaded_language || !*(_QWORD *)loaded_language )
return en_messages[a1];
result = *(char **)(*(_QWORD *)loaded_language + 8LL * a1);
if ( !result )
result = en_messages[a1];
return result;
}

original_code:
const char* get_message(int mesg_number) {
 if(mesg_number >= mesg_end) return ((void *)0);
 return ((loaded_language&&loaded_language->messages)?
  (loaded_language->messages[mesg_number]?
   loaded_language->messages[mesg_number]:en_messages[mesg_number]):
  en_messages[mesg_number]);
}

canonical_original_code:
char *get_message(int mesg_number) {
 if(mesg_number >= mesg_end) return ((void *)0);
 return ((loaded_language&&loaded_language->messages)?
  (loaded_language->messages[mesg_number]?
   loaded_language->messages[mesg_number]:en_messages[mesg_number]):
  en_messages[mesg_number]);
}

return_type: char *


decompiled_code:
void unload_language()
{
void **v0; // rbp
__int64 i; // rbx
void *v2; // rdi
_QWORD *v3; // rax
void *v4; // rdi
void *v5; // rdi

if ( loaded_language_name )
{
free(loaded_language_name);
loaded_language_name = 0LL;
}
v0 = (void **)loaded_language;
if ( loaded_language )
{
if ( *(_QWORD *)loaded_language )
{
for ( i = 0LL; i != 648; i += 8LL )
{
v2 = *(void **)((char *)*v0 + i);
if ( v2 )
free(v2);
}
free(*v0);
}
v3 = v0[1];
if ( v3 )
{
v4 = (void *)v3[1];
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)v0[1] + 2);
if ( v5 )
free(v5);
free(v0[1]);
}
free(v0);
loaded_language = 0LL;
}
}

canonical_decompiled_code:
void func1()
{
void **v0; // rbp
__int64 i; // rbx
void *v2; // rdi
_QWORD *v3; // rax
void *v4; // rdi
void *v5; // rdi

if ( loaded_language_name )
{
free(loaded_language_name);
loaded_language_name = 0LL;
}
v0 = (void **)loaded_language;
if ( loaded_language )
{
if ( *(_QWORD *)loaded_language )
{
for ( i = 0LL; i != 648; i += 8LL )
{
v2 = *(void **)((char *)*v0 + i);
if ( v2 )
free(v2);
}
free(*v0);
}
v3 = v0[1];
if ( v3 )
{
v4 = (void *)v3[1];
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)v0[1] + 2);
if ( v5 )
free(v5);
free(v0[1]);
}
free(v0);
loaded_language = 0LL;
}
}

original_code:
void unload_language() {
 if(loaded_language_name) {
  free(loaded_language_name);
  loaded_language_name = ((void *)0);
 }
 if(!loaded_language) return;
 if(loaded_language->messages) {
  unsigned i;
  for(i = 0; i < mesg_end; ++i) {
   if(loaded_language->messages[i]) free(loaded_language->messages[i]);
  }
  free(loaded_language->messages);
 }
 if(loaded_language->ranges) {
  if(loaded_language->ranges->range_begins) free(loaded_language->ranges->range_begins);
  if(loaded_language->ranges->range_ends) free(loaded_language->ranges->range_ends);
  free(loaded_language->ranges);
 }
 free(loaded_language);
 loaded_language = ((void *)0);
}

canonical_original_code:
void unload_language() {
 if(loaded_language_name) {
  free(loaded_language_name);
  loaded_language_name = ((void *)0);
 }
 if(!loaded_language) return;
 if(loaded_language->messages) {
  unsigned int i;
  for(i = 0; i < mesg_end; ++i) {
   if(loaded_language->messages[i]) free(loaded_language->messages[i]);
  }
  free(loaded_language->messages);
 }
 if(loaded_language->ranges) {
  if(loaded_language->ranges->range_begins) free(loaded_language->ranges->range_begins);
  if(loaded_language->ranges->range_ends) free(loaded_language->ranges->range_ends);
  free(loaded_language->ranges);
 }
 free(loaded_language);
 loaded_language = ((void *)0);
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall load_language(const char *a1)
{
unsigned int v1; // ebp
void **v3; // r12
unsigned int v4; // er13
char *v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
__int64 *v10; // rax
__int64 *v11; // rbp
__int64 v12; // rax
char *v13; // rax
char *v14; // rax
char *v15; // rax
__int64 v16; // [rsp+0h] [rbp-48h] BYREF

if ( !a1 )
return 0;
if ( !strcmp(a1, "builtin") )
{
v1 = 1;
if ( loaded_language )
unload_language();
}
else
{
v3 = (void **)malloc(0x18uLL);
v4 = get_language_ranges(a1, v3);
if ( (_BYTE)v4 )
{
if ( v3 )
free(v3);
v5 = get_message(9);
error_message(v5);
v1 = 0;
}
else
{
get_font_ranges(&v16);
v1 = ranges_compatible(&v16, v3, v6, v7, v8, v9);
if ( (_BYTE)v1 )
{
v10 = (__int64 *)malloc(0x10uLL);
v11 = v10;
if ( v10 )
{
v10[1] = (__int64)v3;
v12 = get_language_messages(a1);
*v11 = v12;
if ( v12 )
{
if ( loaded_language )
unload_language();
loaded_language = v11;
loaded_language_name = (void *)make_string(a1);
v1 = 1;
}
else
{
free(v3[1]);
free(v3[2]);
free(v3);
free(v11);
v15 = get_message(9);
error_message(v15);
v1 = v4;
}
}
else
{
free(v3[1]);
free(v3[2]);
free(v3);
v14 = get_message(9);
error_message(v14);
v1 = v4;
}
}
else
{
free(v3[1]);
free(v3[2]);
free(v3);
v13 = get_message(11);
error_message(v13);
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
unsigned int v1; // ebp
void **v3; // r12
unsigned int v4; // er13
char *v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
__int64 *v10; // rax
__int64 *v11; // rbp
__int64 v12; // rax
char *v13; // rax
char *v14; // rax
char *v15; // rax
__int64 v16; // [rsp+0h] [rbp-48h] BYREF

if ( !a1 )
return 0;
if ( !strcmp(a1, "builtin") )
{
v1 = 1;
if ( loaded_language )
func1();
}
else
{
v3 = (void **)malloc(0x18uLL);
v4 = get_language_ranges(a1, v3);
if ( (_BYTE)v4 )
{
if ( v3 )
free(v3);
v5 = func0(9);
error_message(v5);
v1 = 0;
}
else
{
get_font_ranges(&v16);
v1 = ranges_compatible(&v16, v3, v6, v7, v8, v9);
if ( (_BYTE)v1 )
{
v10 = (__int64 *)malloc(0x10uLL);
v11 = v10;
if ( v10 )
{
v10[1] = (__int64)v3;
v12 = get_language_messages(a1);
*v11 = v12;
if ( v12 )
{
if ( loaded_language )
func1();
loaded_language = v11;
loaded_language_name = (void *)make_string(a1);
v1 = 1;
}
else
{
free(v3[1]);
free(v3[2]);
free(v3);
free(v11);
v15 = func0(9);
error_message(v15);
v1 = v4;
}
}
else
{
free(v3[1]);
free(v3[2]);
free(v3);
v14 = func0(9);
error_message(v14);
v1 = v4;
}
}
else
{
free(v3[1]);
free(v3[2]);
free(v3);
v13 = func0(11);
error_message(v13);
}
}
}
return v1;
}

original_code:
char load_language(const char *lang) {
 if(!lang) return 0;
 if(strcmp(lang,"builtin") == 0) {
  if(loaded_language) unload_language();
  return 1;
 }
 char_ranges *ranges = malloc(sizeof(char_ranges));
 if(get_language_ranges(lang,ranges) != 0) {
  if(ranges) free(ranges);
  error_message(get_message(mesg_load_language_error));
  return 0;
 }
 if(!ranges_compatible(get_font_ranges(),*ranges)) {
  free(ranges->range_begins);
  free(ranges->range_ends);
  free(ranges);
  error_message(get_message(mesg_theme_too_short_error));
  return 0;
 }
 language *new_language = malloc(sizeof(language));
 if(!new_language) {
  free(ranges->range_begins);
  free(ranges->range_ends);
  free(ranges);
  error_message(get_message(mesg_load_language_error));
  return 0;
 }
 new_language->ranges = ranges;
 new_language->messages = get_language_messages(lang);
 if(!new_language->messages) {
  free(ranges->range_begins);
  free(ranges->range_ends);
  free(ranges);
  free(new_language);
  error_message(get_message(mesg_load_language_error));
  return 0;
 }
 if(loaded_language) unload_language();
 loaded_language = new_language;
 loaded_language_name = make_string(lang);
 return 1;
}

canonical_original_code:
char load_language(char *lang) {
 if(!lang) return 0;
 if(strcmp(lang,"builtin") == 0) {
  if(loaded_language) unload_language();
  return 1;
 }
 struct char_ranges *ranges = malloc(sizeof(char_ranges));
 if(get_language_ranges(lang,ranges) != 0) {
  if(ranges) free(ranges);
  error_message(get_message(mesg_load_language_error));
  return 0;
 }
 if(!ranges_compatible(get_font_ranges(),*ranges)) {
  free(ranges->range_begins);
  free(ranges->range_ends);
  free(ranges);
  error_message(get_message(mesg_theme_too_short_error));
  return 0;
 }
 struct language *new_language = malloc(sizeof(language));
 if(!new_language) {
  free(ranges->range_begins);
  free(ranges->range_ends);
  free(ranges);
  error_message(get_message(mesg_load_language_error));
  return 0;
 }
 new_language->ranges = ranges;
 new_language->messages = get_language_messages(lang);
 if(!new_language->messages) {
  free(ranges->range_begins);
  free(ranges->range_ends);
  free(ranges);
  free(new_language);
  error_message(get_message(mesg_load_language_error));
  return 0;
 }
 if(loaded_language) unload_language();
 loaded_language = new_language;
 loaded_language_name = make_string(lang);
 return 1;
}

variable_types:
lang
char *

variable_types: struct language { char **messages; struct char_ranges { unsigned int num_ranges; unsigned int *range_begins; unsigned int *range_ends; } *ranges; } *

return_type: char

user_defined_types: struct language { char **messages; struct char_ranges *ranges; }


decompiled_code:
const char *get_loaded_language_name()
{
const char *result; // rax

result = (const char *)loaded_language_name;
if ( !loaded_language_name )
result = "builtin";
return result;
}

canonical_decompiled_code:
const char *func3()
{
const char *result; // rax

result = (const char *)loaded_language_name;
if ( !loaded_language_name )
result = "builtin";
return result;
}

original_code:
const char* get_loaded_language_name() {
 if(loaded_language_name) return loaded_language_name;
 return "builtin";
}

canonical_original_code:
char *get_loaded_language_name() {
 if(loaded_language_name) return loaded_language_name;
 return "builtin";
}


hash

repo: yoshiomori/neighborhoods

decompiled_code:
__int64 __fastcall hash(char *a1)
{
unsigned int v1; // esi
char v2; // cl
int v3; // edx

v1 = length_vector;
if ( length_vector )
{
v2 = *a1;
if ( *a1 )
{
v3 = 0;
do
{
v3 = (254 * v3 + v2) % length_vector;
v2 = *++a1;
}
while ( *a1 );
v1 = v3;
}
else
{
v1 = 0;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
unsigned int v1; // esi
char v2; // cl
int v3; // edx

v1 = length_vector;
if ( length_vector )
{
v2 = *a1;
if ( *a1 )
{
v3 = 0;
do
{
v3 = (254 * v3 + v2) % length_vector;
v2 = *++a1;
}
while ( *a1 );
v1 = v3;
}
else
{
v1 = 0;
}
}
return v1;
}

original_code:
static int hash(char *s){
  int h = 0;
  if(length_vector)
    for(h = 0; *s; s++)
      h = (254 * h + *s) % length_vector;
  return h;
}

variable_types:
s
char *

variable_types: h int


decompiled_code:
void __noreturn format_error()
{
puts(s);
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
puts(s);
exit(0);
}

original_code:
void format_error(){
  printf("Arquivo não está no formato correto, veja arquivo_padrão\n");
  exit(0);
}


decompiled_code:
void __noreturn memory_error()
{
puts(aMem);
exit(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
puts(aMem);
exit(0);
}

original_code:
void memory_error(){
  printf("Memória insuficiente!\n");
  exit(0);
}


decompiled_code:
void alloc_alphabet()
{
int v0; // ebp
char **v1; // r12
int v2; // eax
char **v3; // rbx
__int64 v4; // rbp

v0 = length_vector;
if ( length_vector / 2 >= vector_free_space )
{
v1 = (char **)data;
v2 = iprime++;
length_vector = prime[v2];
vector_free_space = length_vector;
data = calloc(length_vector, 8uLL);
if ( !data )
memory_error();
if ( v0 > 0 )
{
v3 = v1;
v4 = (__int64)&v1[(unsigned int)(v0 - 1) + 1];
do
{
if ( *v3 )
insert_alphabet(*v3);
++v3;
}
while ( v3 != (char **)v4 );
}
if ( v1 )
free(v1);
}
}

canonical_decompiled_code:
void func4()
{
int v0; // ebp
char **v1; // r12
int v2; // eax
char **v3; // rbx
__int64 v4; // rbp

v0 = length_vector;
if ( length_vector / 2 >= vector_free_space )
{
v1 = (char **)data;
v2 = iprime++;
length_vector = prime[v2];
vector_free_space = length_vector;
data = calloc(length_vector, 8uLL);
if ( !data )
func2();
if ( v0 > 0 )
{
v3 = v1;
v4 = (__int64)&v1[(unsigned int)(v0 - 1) + 1];
do
{
if ( *v3 )
func3(*v3);
++v3;
}
while ( v3 != (char **)v4 );
}
if ( v1 )
free(v1);
}
}

original_code:
void alloc_alphabet(){
  char **aux_alphabet = data.alphabet;
  int aux_length_vector = length_vector;
  int i = 0;
  if(vector_free_space <= length_vector / 2){
    vector_free_space = length_vector = prime[iprime++];
    if(!(data.alphabet = calloc(length_vector, sizeof(*data.alphabet))))
      memory_error();
    for(i = 0; i < aux_length_vector; i++)
      if(aux_alphabet[i])
 insert_alphabet(aux_alphabet[i]);
    if(aux_alphabet){
      free(aux_alphabet);
      aux_alphabet = ((void *)0);
    }
  }
}

variable_types: i int


decompiled_code:
const char *__fastcall search_alphabet(char *s1)
{
int v1; // eax
_QWORD *v2; // r12
int v3; // er13
const char *v4; // r14
int v5; // ebx

v1 = hash(s1);
v2 = data;
if ( !data )
return (const char *)data;
v3 = v1;
v4 = (const char *)*((_QWORD *)data + v1);
if ( v4 )
{
v5 = length_vector;
do
{
if ( !strcmp(s1, v4) )
break;
v3 = (v3 + 1) % v5;
v4 = (const char *)v2[v3];
}
while ( v4 );
}
return v4;
}

canonical_decompiled_code:
const char *__fastcall func5(char *s1)
{
int v1; // eax
_QWORD *v2; // r12
int v3; // er13
const char *v4; // r14
int v5; // ebx

v1 = func0(s1);
v2 = data;
if ( !data )
return (const char *)data;
v3 = v1;
v4 = (const char *)*((_QWORD *)data + v1);
if ( v4 )
{
v5 = length_vector;
do
{
if ( !strcmp(s1, v4) )
break;
v3 = (v3 + 1) % v5;
v4 = (const char *)v2[v3];
}
while ( v4 );
}
return v4;
}

original_code:
char *search_alphabet(char *symbol){
  int i = hash(symbol);
  if(data.alphabet)
    while(data.alphabet[i] != ((void *)0)){
      if(!strcmp(symbol, data.alphabet[i]))
 return data.alphabet[i];
      else
 i = (i + 1) % length_vector;
    }
  return ((void *)0);
}

variable_types:
symbol
char *


decompiled_code:
int __fastcall read_alphabet(__int64 a1)
{
void **v1; // rbx
char *v2; // rax
char *i; // rbp

data = 0LL;
*((_DWORD *)&data + 4) = 0;
if ( !a1 )
format_error();
v1 = (void **)chop();
symbol = v1;
v2 = (char *)*v1;
*(&data + 1) = *v1;
for ( i = (char *)*v1; *v1; i = (char *)*v1 )
{
if ( search_alphabet(i) )
{
LODWORD(v2) = printf("Letra %s repetiu no alfabeto.\n", i);
}
else
{
alloc_alphabet();
LODWORD(v2) = insert_alphabet((char *)*v1);
}
++v1;
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
void **v1; // rbx
char *v2; // rax
char *i; // rbp

data = 0LL;
*((_DWORD *)&data + 4) = 0;
if ( !a1 )
func1();
v1 = (void **)chop();
symbol = v1;
v2 = (char *)*v1;
*(&data + 1) = *v1;
for ( i = (char *)*v1; *v1; i = (char *)*v1 )
{
if ( func5(i) )
{
LODWORD(v2) = printf("Letra %s repetiu no alfabeto.\n", i);
}
else
{
func4();
LODWORD(v2) = func3((char *)*v1);
}
++v1;
}
return (int)v2;
}

original_code:
void read_alphabet(char *line){
  char **aux = ((void *)0);
  data.alphabet = ((void *)0);
  data.size_alphabet = 0;
  if(!line)
    format_error();
  symbol = chop(line);
  data.first_char = *symbol;
  for(aux = symbol; *aux; aux++){
    if(!search_alphabet(*aux)){
      alloc_alphabet();
      insert_alphabet(*aux);
    }
    else
      printf("Letra %s repetiu no alfabeto.\n", *aux);
  }
}

variable_types:
line
char *

variable_types:
aux
char **


decompiled_code:
void delete_alphabet()
{
if ( data )
{
free(data);
data = 0LL;
}
if ( symbol )
{
free(symbol);
symbol = 0LL;
}
}

canonical_decompiled_code:
void func7()
{
if ( data )
{
free(data);
data = 0LL;
}
if ( symbol )
{
free(symbol);
symbol = 0LL;
}
}

original_code:
void delete_alphabet(){
  if(data.alphabet){
    free(data.alphabet);
    data.alphabet = ((void *)0);
  }
  if(symbol){
    free(symbol);
    symbol = ((void *)0);
  }
}


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

result = calloc(a1, 0xCuLL);
if ( !result )
{
puts(s);
exit(0);
}
return result;
}

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

result = calloc(a1, 0xCuLL);
if ( !result )
{
puts(s);
exit(0);
}
return result;
}

original_code:
node node_init(int size){
  node aux;
  if(!(aux = calloc(size, sizeof *aux))){
    printf("Memória insuficiente\n");
    exit(0);
  }
  return aux;
}

canonical_original_code:
struct NODE *node_init(int size){
  struct NODE *aux;
  if(!(aux = calloc(size, sizeof *aux))){
    printf("Memória insuficiente\n");
    exit(0);
  }
  return aux;
}

variable_types: size int

variable_types: struct NODE { int not_null; int pos_word; int num_occur; } *


original_code:
long vert_neig_hash(int pos, word_table table){
  unsigned int h = 0;
  Vertice *c;
  for(c = table->set; *c; c++)
    h = (h * data.size_alphabet + ((*c)->info[pos] - data.first_char)) % table->length_vert_neig;
  return h;
}

canonical_original_code:
long vert_neig_hash(int pos, struct WORD_TABLE *table){
  unsigned int h = 0;
  struct VERTICE **c;
  for(c = table->set; *c; c++)
    h = (h * data.size_alphabet + ((*c)->info[pos] - data.first_char)) % table->length_vert_neig;
  return h;
}

variable_types: pos int

variable_types: struct WORD_TABLE { struct VERTICE { int line; char **info; unsigned long size_info; struct NEIGHBORHOOD { struct VERTICE **vertice; int size; struct WORD_TABLE *table; } neighborhood; } **set; struct NODE { int not_null; int pos_word; int num_occur; } *word_vert_neig; int length_vert_neig; int free_vert_neig; struct NODE *word_neig; int length_neig; int free_neig; double f; } *

variable_types:
h
unsigned int

variable_types: struct VERTICE { int line; char **info; unsigned long size_info; struct NEIGHBORHOOD { struct VERTICE **vertice; int size; struct WORD_TABLE { struct VERTICE **set; struct NODE { int not_null; int pos_word; int num_occur; } *word_vert_neig; int length_vert_neig; int free_vert_neig; struct NODE *word_neig; int length_neig; int free_neig; double f; } *table; } neighborhood; } **

return_type: long

user_defined_types: struct WORD_TABLE { struct VERTICE **set; struct NODE *word_vert_neig; int length_vert_neig; int free_vert_neig; struct NODE *word_neig; int length_neig; int free_neig; double f; }

user_defined_types: struct VERTICE { int line; char **info; unsigned long size_info; struct NEIGHBORHOOD neighborhood; }


original_code:
void expand_vert_neig(word_table table){
  node aux = table->word_vert_neig;
  int aux_length = table->length_vert_neig;
  int i, h;
  table->word_vert_neig = node_init(table->length_vert_neig = prime[vert_neig++]);
  table->free_vert_neig = table->length_vert_neig;
  for(i = 0; i < aux_length; i++)
    if(aux[i].not_null){
      h = vert_neig_hash(aux[i].pos_word, table);
      while(table->word_vert_neig[h].not_null)
 h = (h + 1) % table->length_vert_neig;
      table->word_vert_neig[h].not_null = 1;
      table->word_vert_neig[h].pos_word = aux[i].pos_word;
      table->word_vert_neig[h].num_occur = aux[i].num_occur;
      table->free_vert_neig--;
    }
  if(aux){
    free(aux);
    aux = ((void *)0);
  }
}

canonical_original_code:
void expand_vert_neig(struct WORD_TABLE *table){
  struct NODE *aux = table->word_vert_neig;
  int aux_length = table->length_vert_neig;
  int i; int h;
  table->word_vert_neig = node_init(table->length_vert_neig = prime[vert_neig++]);
  table->free_vert_neig = table->length_vert_neig;
  for(i = 0; i < aux_length; i++)
    if(aux[i].not_null){
      h = vert_neig_hash(aux[i].pos_word, table);
      while(table->word_vert_neig[h].not_null)
 h = (h + 1) % table->length_vert_neig;
      table->word_vert_neig[h].not_null = 1;
      table->word_vert_neig[h].pos_word = aux[i].pos_word;
      table->word_vert_neig[h].num_occur = aux[i].num_occur;
      table->free_vert_neig--;
    }
  if(aux){
    free(aux);
    aux = ((void *)0);
  }
}

user_defined_types: struct NODE { int not_null; int pos_word; int num_occur; }

user_defined_types: struct NEIGHBORHOOD { struct VERTICE **vertice; int size; struct WORD_TABLE *table; }


original_code:
void vert_neig_insert(int pos, word_table table){
  long h = vert_neig_hash(pos, table);
  node aux;
  if(!(aux = vert_neig_search(pos, table))){
    while(table->word_vert_neig[h].not_null)
      h = (h + 1) % table->length_vert_neig;
    table->word_vert_neig[h].not_null = 1;
    table->word_vert_neig[h].pos_word = pos;
    table->word_vert_neig[h].num_occur++;
    if(--table->free_vert_neig <= table->length_vert_neig / 2)
      expand_vert_neig(table);
  }
  else
    aux->num_occur++;
}

canonical_original_code:
void vert_neig_insert(int pos, struct WORD_TABLE *table){
  long h = vert_neig_hash(pos, table);
  struct NODE *aux;
  if(!(aux = vert_neig_search(pos, table))){
    while(table->word_vert_neig[h].not_null)
      h = (h + 1) % table->length_vert_neig;
    table->word_vert_neig[h].not_null = 1;
    table->word_vert_neig[h].pos_word = pos;
    table->word_vert_neig[h].num_occur++;
    if(--table->free_vert_neig <= table->length_vert_neig / 2)
      expand_vert_neig(table);
  }
  else
    aux->num_occur++;
}

variable_types: h long


original_code:
long neig_hash(int pos,word_table table){
  long h = 0;
  Vertice *c;
  for(c = table->set + 1; *c; c++)
    h = (h * data.size_alphabet + ((*c)->info[pos] - data.first_char)) % table->length_neig;
  return h;
}

canonical_original_code:
long neig_hash(int pos, struct WORD_TABLE *table){
  long h = 0;
  struct VERTICE **c;
  for(c = table->set + 1; *c; c++)
    h = (h * data.size_alphabet + ((*c)->info[pos] - data.first_char)) % table->length_neig;
  return h;
}


original_code:
void expand_neig(word_table table){
  node aux = table->word_neig;
  int aux_length = table->length_neig;
  int i, h;
  table->word_neig = node_init(table->length_neig = prime[neig++]);
  table->free_neig = table->length_neig;
  for(i = 0; i < aux_length; i++)
    if(aux[i].not_null){
      h = neig_hash(aux[i].pos_word, table);
      while(table->word_neig[h].not_null)
 h = (h + 1) % table->length_neig;
      table->word_neig[h].not_null = 1;
      table->word_neig[h].pos_word = aux[i].pos_word;
      table->word_neig[h].num_occur = aux[i].num_occur;
      table->free_neig--;
    }
  if(aux){
    free(aux);
    aux = ((void *)0);
  }
}

canonical_original_code:
void expand_neig(struct WORD_TABLE *table){
  struct NODE *aux = table->word_neig;
  int aux_length = table->length_neig;
  int i; int h;
  table->word_neig = node_init(table->length_neig = prime[neig++]);
  table->free_neig = table->length_neig;
  for(i = 0; i < aux_length; i++)
    if(aux[i].not_null){
      h = neig_hash(aux[i].pos_word, table);
      while(table->word_neig[h].not_null)
 h = (h + 1) % table->length_neig;
      table->word_neig[h].not_null = 1;
      table->word_neig[h].pos_word = aux[i].pos_word;
      table->word_neig[h].num_occur = aux[i].num_occur;
      table->free_neig--;
    }
  if(aux){
    free(aux);
    aux = ((void *)0);
  }
}


original_code:
void neig_insert(int pos, word_table table){
  long h = neig_hash(pos, table);
  node aux;
  if(!(aux = neig_search(pos, table))){
    while(table->word_neig[h].not_null)
      h = (h + 1) % table->length_neig;
    table->word_neig[h].not_null = 1;
    table->word_neig[h].pos_word = pos;
    table->word_neig[h].num_occur++;
    if(--table->free_neig <= table->length_neig / 2)
      expand_neig(table);
  }
  else
    aux->num_occur++;
}

canonical_original_code:
void neig_insert(int pos, struct WORD_TABLE *table){
  long h = neig_hash(pos, table);
  struct NODE *aux;
  if(!(aux = neig_search(pos, table))){
    while(table->word_neig[h].not_null)
      h = (h + 1) % table->length_neig;
    table->word_neig[h].not_null = 1;
    table->word_neig[h].pos_word = pos;
    table->word_neig[h].num_occur++;
    if(--table->free_neig <= table->length_neig / 2)
      expand_neig(table);
  }
  else
    aux->num_occur++;
}


processing

original_code:
void processing(){
  int i = 0, j = 0, k, l, m;
  int stop;
  int pos;
  int size;
  word_table cur, prev, aux_table;
  node aux, aux_stop;
  for(i = 0; i < data.vertice_head.first_free_pos; i++){
    size = 0;
    cur = word_table_init(data.vertice_head.vertice[i].neighborhood.size + 2);
    prev = word_table_init(data.vertice_head.vertice[i].neighborhood.size + 2);
    prev->set[0] = &data.vertice_head.vertice[i];
    prev->set[1] = ((void *)0);
    for(pos = 0; prev->set[0]->info[pos]; pos++)
      vert_neig_insert(pos, prev);
    for(k = 0; k < prev->length_vert_neig; k++)
      if(prev->word_vert_neig[k].not_null)
 prev->f += (double)prev->word_vert_neig[k].num_occur * log((double)prev->word_vert_neig[k].num_occur / (double)data.vertice_head.vertice[i].size_info);
    prev->f -= data.constant * log((double)data.vertice_head.vertice[i].size_info) / log((double)data.size_alphabet);
    for(j = 0, stop = 1; j < data.vertice_head.vertice[i].neighborhood.size; j++)
      stop <<= 1;
    for(k = 1; k != stop; k++){
      cur->f = 0;
      cur->free_neig = cur->length_neig;
      cur->free_vert_neig = cur->length_vert_neig;
      for(aux = cur->word_vert_neig, aux_stop = aux + cur->length_vert_neig; aux < aux_stop; aux++){
 if(aux->not_null){
   aux->not_null = 0;
   aux->num_occur = 0;
 }
      }
      for(aux = cur->word_neig, aux_stop = aux + cur->length_neig; aux < aux_stop; aux++){
 if(aux->not_null){
   aux->not_null = 0;
   aux->num_occur = 0;
 }
      }
      cur->set[0] = &data.vertice_head.vertice[i];
      for(l = 0, m = 1; k >> l; l++)
       if(k >> l & 1)
         cur->set[m++] = cur->set[0]->neighborhood.vertice[l];
      cur->set[m] = ((void *)0);
      for(pos = 0; cur->set[0]->info[pos]; pos++){
 neig_insert(pos, cur);
 vert_neig_insert(pos, cur);
      }
      for(l = 0; l < cur->length_vert_neig; l++)
       if(cur->word_vert_neig[l].not_null){
         aux = neig_search(cur->word_vert_neig[l].pos_word, cur);
         cur->f += (double)cur->word_vert_neig[l].num_occur * log((double)cur->word_vert_neig[l].num_occur / (double)aux->num_occur);
       }
      cur->f -= data.constant * pow((double)data.size_alphabet, (double)(m-1)) * log((double)data.vertice_head.vertice[i].size_info) / log((double)data.size_alphabet);
      if(prev->f <= cur->f){
       aux_table = cur;
       cur = prev;
       prev = aux_table;
       size = m - 1;
      }
    }
    if(cur){
      free(cur);
      cur = ((void *)0);
    }
    data.vertice_head.vertice[i].neighborhood.table = prev;
    if(data.vertice_head.vertice[i].neighborhood.vertice){
      free(data.vertice_head.vertice[i].neighborhood.vertice);
      data.vertice_head.vertice[i].neighborhood.vertice = ((void *)0);
    }
    data.vertice_head.vertice[i].neighborhood.vertice = (prev->set) + 1;
    data.vertice_head.vertice[i].neighborhood.size = size;
  }
}

canonical_original_code:
void processing(){
  int i = 0; int j = 0; int k; int l; int m;
  int stop;
  int pos;
  int size;
  struct WORD_TABLE *cur; struct WORD_TABLE *prev; struct WORD_TABLE *aux_table;
  struct NODE *aux; struct NODE *aux_stop;
  for(i = 0; i < data.vertice_head.first_free_pos; i++){
    size = 0;
    cur = word_table_init(data.vertice_head.vertice[i].neighborhood.size + 2);
    prev = word_table_init(data.vertice_head.vertice[i].neighborhood.size + 2);
    prev->set[0] = &data.vertice_head.vertice[i];
    prev->set[1] = ((void *)0);
    for(pos = 0; prev->set[0]->info[pos]; pos++)
      vert_neig_insert(pos, prev);
    for(k = 0; k < prev->length_vert_neig; k++)
      if(prev->word_vert_neig[k].not_null)
 prev->f += (double)prev->word_vert_neig[k].num_occur * log((double)prev->word_vert_neig[k].num_occur / (double)data.vertice_head.vertice[i].size_info);
    prev->f -= data.constant * log((double)data.vertice_head.vertice[i].size_info) / log((double)data.size_alphabet);
    for(j = 0, stop = 1; j < data.vertice_head.vertice[i].neighborhood.size; j++)
      stop <<= 1;
    for(k = 1; k != stop; k++){
      cur->f = 0;
      cur->free_neig = cur->length_neig;
      cur->free_vert_neig = cur->length_vert_neig;
      for(aux = cur->word_vert_neig, aux_stop = aux + cur->length_vert_neig; aux < aux_stop; aux++){
 if(aux->not_null){
   aux->not_null = 0;
   aux->num_occur = 0;
 }
      }
      for(aux = cur->word_neig, aux_stop = aux + cur->length_neig; aux < aux_stop; aux++){
 if(aux->not_null){
   aux->not_null = 0;
   aux->num_occur = 0;
 }
      }
      cur->set[0] = &data.vertice_head.vertice[i];
      for(l = 0, m = 1; k >> l; l++)
       if(k >> l & 1)
         cur->set[m++] = cur->set[0]->neighborhood.vertice[l];
      cur->set[m] = ((void *)0);
      for(pos = 0; cur->set[0]->info[pos]; pos++){
 neig_insert(pos, cur);
 vert_neig_insert(pos, cur);
      }
      for(l = 0; l < cur->length_vert_neig; l++)
       if(cur->word_vert_neig[l].not_null){
         aux = neig_search(cur->word_vert_neig[l].pos_word, cur);
         cur->f += (double)cur->word_vert_neig[l].num_occur * log((double)cur->word_vert_neig[l].num_occur / (double)aux->num_occur);
       }
      cur->f -= data.constant * pow((double)data.size_alphabet, (double)(m-1)) * log((double)data.vertice_head.vertice[i].size_info) / log((double)data.size_alphabet);
      if(prev->f <= cur->f){
       aux_table = cur;
       cur = prev;
       prev = aux_table;
       size = m - 1;
      }
    }
    if(cur){
      free(cur);
      cur = ((void *)0);
    }
    data.vertice_head.vertice[i].neighborhood.table = prev;
    if(data.vertice_head.vertice[i].neighborhood.vertice){
      free(data.vertice_head.vertice[i].neighborhood.vertice);
      data.vertice_head.vertice[i].neighborhood.vertice = ((void *)0);
    }
    data.vertice_head.vertice[i].neighborhood.vertice = (prev->set) + 1;
    data.vertice_head.vertice[i].neighborhood.size = size;
  }
}

variable_types: j int

variable_types: k int

variable_types: l int

variable_types: m int

variable_types: stop int


decompiled_code:
void __fastcall __noreturn format_error_vertice(__int64 a1)
{
printf(format, a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(__int64 a1)
{
printf(format, a1);
exit(0);
}

original_code:
void format_error_vertice(char *symbol){
  printf("A letra %s não está presente no alfabeto!\n", symbol);
  exit(0);
}


decompiled_code:
__int64 read_vertice()
{
_QWORD *v0; // rbp
__int64 v1; // rbx
__int64 v2; // rax
__int64 v3; // r12
int v4; // eax
int v5; // edx
int v6; // eax
__int64 result; // rax
void *v8; // rax
int v9; // eax
void *v10; // rax

v0 = (_QWORD *)chop();
if ( *v0 )
{
v1 = 0LL;
do
{
v2 = search_alphabet();
v0[v1] = v2;
if ( !v2 )
format_error_vertice(0LL);
if ( first_time_3 )
++size_info_vertice_2;
++v1;
}
while ( v0[v1] );
}
else
{
v1 = 0LL;
}
v3 = size_info_vertice_2;
if ( size_info_vertice_2 != v1 )
{
puts(s);
exit(0);
}
if ( first_time_3 )
{
v8 = malloc(0x1E0uLL);
*((_QWORD *)&data + 4) = v8;
if ( !v8 )
{
puts(aMem);
exit(0);
}
*((_DWORD *)&data + 10) = 10;
*((_DWORD *)&data + 11) = 0;
}
else
{
v4 = *((_DWORD *)&data + 10);
if ( *((_DWORD *)&data + 11) == v4 )
{
v9 = 2 * v4;
*((_DWORD *)&data + 10) = v9;
v10 = realloc(*((void **)&data + 4), 48LL * v9);
*((_QWORD *)&data + 4) = v10;
if ( !v10 )
{
puts(aMem_0);
exit(0);
}
}
}
v5 = count_1++;
*(_DWORD *)(*((_QWORD *)&data + 4) + 48LL * *((int *)&data + 11)) = v5;
*(_QWORD *)(*((_QWORD *)&data + 4) + 48LL * *((int *)&data + 11) + 8) = v0;
v6 = *((_DWORD *)&data + 11);
*((_DWORD *)&data + 11) = v6 + 1;
result = *((_QWORD *)&data + 4) + 48LL * v6;
*(_QWORD *)(result + 16) = v3;
first_time_3 = 0;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
_QWORD *v0; // rbp
__int64 v1; // rbx
__int64 v2; // rax
__int64 v3; // r12
int v4; // eax
int v5; // edx
int v6; // eax
__int64 result; // rax
void *v8; // rax
int v9; // eax
void *v10; // rax

v0 = (_QWORD *)chop();
if ( *v0 )
{
v1 = 0LL;
do
{
v2 = search_alphabet();
v0[v1] = v2;
if ( !v2 )
func0(0LL);
if ( first_time_3 )
++size_info_vertice_2;
++v1;
}
while ( v0[v1] );
}
else
{
v1 = 0LL;
}
v3 = size_info_vertice_2;
if ( size_info_vertice_2 != v1 )
{
puts(s);
exit(0);
}
if ( first_time_3 )
{
v8 = malloc(0x1E0uLL);
*((_QWORD *)&data + 4) = v8;
if ( !v8 )
{
puts(aMem);
exit(0);
}
*((_DWORD *)&data + 10) = 10;
*((_DWORD *)&data + 11) = 0;
}
else
{
v4 = *((_DWORD *)&data + 10);
if ( *((_DWORD *)&data + 11) == v4 )
{
v9 = 2 * v4;
*((_DWORD *)&data + 10) = v9;
v10 = realloc(*((void **)&data + 4), 48LL * v9);
*((_QWORD *)&data + 4) = v10;
if ( !v10 )
{
puts(aMem_0);
exit(0);
}
}
}
v5 = count_1++;
*(_DWORD *)(*((_QWORD *)&data + 4) + 48LL * *((int *)&data + 11)) = v5;
*(_QWORD *)(*((_QWORD *)&data + 4) + 48LL * *((int *)&data + 11) + 8) = v0;
v6 = *((_DWORD *)&data + 11);
*((_DWORD *)&data + 11) = v6 + 1;
result = *((_QWORD *)&data + 4) + 48LL * v6;
*(_QWORD *)(result + 16) = v3;
first_time_3 = 0;
return result;
}

original_code:
void read_vertice(char *line){
  char **info_vertice = ((void *)0);
  char **aux = ((void *)0);
  unsigned long int size = 0;
  static int first_time = 1;
  static unsigned long int size_info_vertice = 0;
  static int count = 0;
  info_vertice = chop(line);
  for(aux = info_vertice; *aux; aux++){
    if(!(*aux = search_alphabet(*aux)))
      format_error_vertice(*aux);
    if(first_time)
      size_info_vertice++;
    size++;
  }
  if(size_info_vertice != size){
    printf("Vertice com mais informação que outras!\n");
    exit(0);
  }
  if(first_time){
    if(!(data.vertice_head.vertice = malloc(10 * sizeof *data.vertice_head.vertice))){
      printf("Memória insuficiente!\n");
      exit(0);
    }
    data.vertice_head.length = 10;
    data.vertice_head.first_free_pos = 0;
  }
  else if(data.vertice_head.first_free_pos == data.vertice_head.length){
    data.vertice_head.length += data.vertice_head.length;
    if(!(data.vertice_head.vertice = realloc(data.vertice_head.vertice, data.vertice_head.length * sizeof *data.vertice_head.vertice))){
      printf("Memória insuficiente\n");
      exit(0);
    }
  }
  data.vertice_head.vertice[data.vertice_head.first_free_pos].line = count++;
  data.vertice_head.vertice[data.vertice_head.first_free_pos].info = info_vertice;
  data.vertice_head.vertice[data.vertice_head.first_free_pos++].size_info = size_info_vertice;
  first_time = 0;
}

canonical_original_code:
void read_vertice(char *line){
  char **info_vertice = ((void *)0);
  char **aux = ((void *)0);
  unsigned long size = 0;
  static int first_time = 1;
  static unsigned long size_info_vertice = 0;
  static int count = 0;
  info_vertice = chop(line);
  for(aux = info_vertice; *aux; aux++){
    if(!(*aux = search_alphabet(*aux)))
      format_error_vertice(*aux);
    if(first_time)
      size_info_vertice++;
    size++;
  }
  if(size_info_vertice != size){
    printf("Vertice com mais informação que outras!\n");
    exit(0);
  }
  if(first_time){
    if(!(data.vertice_head.vertice = malloc(10 * sizeof *data.vertice_head.vertice))){
      printf("Memória insuficiente!\n");
      exit(0);
    }
    data.vertice_head.length = 10;
    data.vertice_head.first_free_pos = 0;
  }
  else if(data.vertice_head.first_free_pos == data.vertice_head.length){
    data.vertice_head.length += data.vertice_head.length;
    if(!(data.vertice_head.vertice = realloc(data.vertice_head.vertice, data.vertice_head.length * sizeof *data.vertice_head.vertice))){
      printf("Memória insuficiente\n");
      exit(0);
    }
  }
  data.vertice_head.vertice[data.vertice_head.first_free_pos].line = count++;
  data.vertice_head.vertice[data.vertice_head.first_free_pos].info = info_vertice;
  data.vertice_head.vertice[data.vertice_head.first_free_pos++].size_info = size_info_vertice;
  first_time = 0;
}

variable_types:
size
unsigned long

variable_types: count int


decompiled_code:
_BYTE *read_neighborhood()
{
_BYTE **v0; // rax
_BYTE **v1; // r14
_BYTE *v2; // r13
const char **v3; // rbp
const char *v4; // rbx
int v5; // er12
_BYTE **v6; // rax
int v7; // ebx
_QWORD *v8; // rcx
int v9; // edi
__int64 v10; // rax
_BYTE *result; // rax
__int64 v12; // rsi
_BYTE **v13; // rdx

v0 = (_BYTE **)chop();
v1 = v0;
v2 = *v0;
if ( !*v0 )
{
v7 = *((_DWORD *)&data + 11);
if ( !v7 )
goto LABEL_14;
LABEL_23:
puts(aErroDeSintaxeN);
puts(aIndica);
exit(0);
}
v3 = (const char **)v0;
v4 = *v0;
v5 = 0;
do
{
if ( (unsigned int)strlen(v4) != 1 || (unsigned __int8)(*v4 - 48) > 1u )
{
puts(aErroDeSintaxeN);
puts("Permitido apenas 0 ou 1 na matriz.");
exit(0);
}
++v3;
++v5;
v4 = *v3;
}
while ( *v3 );
if ( *((_DWORD *)&data + 11) != v5 )
goto LABEL_23;
v6 = v1;
v7 = 0;
do
{
if ( *v2 != 48 )
{
if ( current_vertice_0 == (unsigned int)(v6 - v1) )
{
puts(aErroDeSintaxeN);
puts("Diagonal deve ser zerada.");
exit(0);
}
++v7;
}
v2 = *++v6;
}
while ( *v6 );
LABEL_14:
v8 = malloc(8LL * v7);
if ( !v8 )
{
puts(aMem);
exit(0);
}
v9 = current_vertice_0;
v10 = 48LL * current_vertice_0;
*(_QWORD *)(*((_QWORD *)&data + 4) + v10 + 24) = v8;
*(_DWORD *)(*((_QWORD *)&data + 4) + v10 + 32) = v7;
result = *v1;
if ( *v1 )
{
v12 = *((_QWORD *)&data + 4);
v13 = v1;
do
{
if ( *result != 48 )
*v8++ = v12 + 48LL * (int)(v13 - v1);
result = *++v13;
}
while ( *v13 );
}
current_vertice_0 = v9 + 1;
return result;
}

canonical_decompiled_code:
_BYTE *func2()
{
_BYTE **v0; // rax
_BYTE **v1; // r14
_BYTE *v2; // r13
const char **v3; // rbp
const char *v4; // rbx
int v5; // er12
_BYTE **v6; // rax
int v7; // ebx
_QWORD *v8; // rcx
int v9; // edi
__int64 v10; // rax
_BYTE *result; // rax
__int64 v12; // rsi
_BYTE **v13; // rdx

v0 = (_BYTE **)chop();
v1 = v0;
v2 = *v0;
if ( !*v0 )
{
v7 = *((_DWORD *)&data + 11);
if ( !v7 )
goto LABEL_14;
LABEL_23:
puts(aErroDeSintaxeN);
puts(aIndica);
exit(0);
}
v3 = (const char **)v0;
v4 = *v0;
v5 = 0;
do
{
if ( (unsigned int)strlen(v4) != 1 || (unsigned __int8)(*v4 - 48) > 1u )
{
puts(aErroDeSintaxeN);
puts("Permitido apenas 0 ou 1 na matriz.");
exit(0);
}
++v3;
++v5;
v4 = *v3;
}
while ( *v3 );
if ( *((_DWORD *)&data + 11) != v5 )
goto LABEL_23;
v6 = v1;
v7 = 0;
do
{
if ( *v2 != 48 )
{
if ( current_vertice_0 == (unsigned int)(v6 - v1) )
{
puts(aErroDeSintaxeN);
puts("Diagonal deve ser zerada.");
exit(0);
}
++v7;
}
v2 = *++v6;
}
while ( *v6 );
LABEL_14:
v8 = malloc(8LL * v7);
if ( !v8 )
{
puts(aMem);
exit(0);
}
v9 = current_vertice_0;
v10 = 48LL * current_vertice_0;
*(_QWORD *)(*((_QWORD *)&data + 4) + v10 + 24) = v8;
*(_DWORD *)(*((_QWORD *)&data + 4) + v10 + 32) = v7;
result = *v1;
if ( *v1 )
{
v12 = *((_QWORD *)&data + 4);
v13 = v1;
do
{
if ( *result != 48 )
*v8++ = v12 + 48LL * (int)(v13 - v1);
result = *++v13;
}
while ( *v13 );
}
current_vertice_0 = v9 + 1;
return result;
}

original_code:
void read_neighborhood(char *line){
  char **neighborhood = ((void *)0);
  char **aux = ((void *)0);
  int size = 0;
  static int current_vertice = 0;
  Vertice *current_neighborhood = ((void *)0);
  neighborhood = chop(line);
  for(aux = neighborhood, size = 0; *aux; aux++, size++)
    if((int)strlen(*aux) != 1 || (**aux != '0' && **aux != '1')){
      printf("Erro de sintaxe na matriz de vizinhança!\n");
      printf("Permitido apenas 0 ou 1 na matriz.\n");
      exit(0);
    }
  if(size != data.vertice_head.first_free_pos){
    printf("Erro de sintaxe na matriz de vizinhança!\n");
    printf("Indicação de vizinhaça a mais.\n");
    exit(0);
  }
  for(aux = neighborhood, size = 0; *aux; aux++)
    if(**aux - '0'){
      if(current_vertice == (int)(aux - neighborhood)){
 printf("Erro de sintaxe na matriz de vizinhança!\n");
 printf("Diagonal deve ser zerada.\n");
 exit(0);
      }
      size++;
    }
  if(!(current_neighborhood = malloc(size * sizeof *current_neighborhood))){
    printf("Memória insuficiente!\n");
    exit(0);
  }
  data.vertice_head.vertice[current_vertice].neighborhood.vertice = current_neighborhood;
  data.vertice_head.vertice[current_vertice].neighborhood.size = size;
  for(aux = neighborhood; *aux; aux++)
    if(**aux - '0')
      *(current_neighborhood++) = &data.vertice_head.vertice[(int)(aux - neighborhood)];
  current_vertice++;
}

canonical_original_code:
void read_neighborhood(char *line){
  char **neighborhood = ((void *)0);
  char **aux = ((void *)0);
  int size = 0;
  static int current_vertice = 0;
  struct VERTICE **current_neighborhood = ((void *)0);
  neighborhood = chop(line);
  for(aux = neighborhood, size = 0; *aux; aux++, size++)
    if((int)strlen(*aux) != 1 || (**aux != '0' && **aux != '1')){
      printf("Erro de sintaxe na matriz de vizinhança!\n");
      printf("Permitido apenas 0 ou 1 na matriz.\n");
      exit(0);
    }
  if(size != data.vertice_head.first_free_pos){
    printf("Erro de sintaxe na matriz de vizinhança!\n");
    printf("Indicação de vizinhaça a mais.\n");
    exit(0);
  }
  for(aux = neighborhood, size = 0; *aux; aux++)
    if(**aux - '0'){
      if(current_vertice == (int)(aux - neighborhood)){
 printf("Erro de sintaxe na matriz de vizinhança!\n");
 printf("Diagonal deve ser zerada.\n");
 exit(0);
      }
      size++;
    }
  if(!(current_neighborhood = malloc(size * sizeof *current_neighborhood))){
    printf("Memória insuficiente!\n");
    exit(0);
  }
  data.vertice_head.vertice[current_vertice].neighborhood.vertice = current_neighborhood;
  data.vertice_head.vertice[current_vertice].neighborhood.size = size;
  for(aux = neighborhood; *aux; aux++)
    if(**aux - '0')
      *(current_neighborhood++) = &data.vertice_head.vertice[(int)(aux - neighborhood)];
  current_vertice++;
}

variable_types:
neighborhood
char **


decompiled_code:
__int64 __fastcall binary_search(unsigned __int64 a1, __int64 a2, int a3)
{
__int64 v4; // rdx
unsigned __int64 v5; // r8
__int64 v6; // r9
__int64 v7; // rcx
__int64 v8; // rcx

v4 = (unsigned int)(a3 / 2);
v5 = *(_QWORD *)(a2 + 8LL * (int)v4);
if ( v5 == a1 )
return a1;
v6 = 8LL * (int)v4;
v7 = 0LL;
if ( !(_DWORD)v4 )
return v7;
if ( v5 > a1 )
return binary_search(a1, a2, v4, 0LL, v5, v6);
v8 = 0LL;
if ( v5 < a1 )
v8 = binary_search(a1, a2 + v6 + 8, (unsigned int)(a3 - v4 - 1), 0LL, v5, v6);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 a1, __int64 a2, int a3)
{
__int64 v4; // rdx
unsigned __int64 v5; // r8
__int64 v6; // r9
__int64 v7; // rcx
__int64 v8; // rcx

v4 = (unsigned int)(a3 / 2);
v5 = *(_QWORD *)(a2 + 8LL * (int)v4);
if ( v5 == a1 )
return a1;
v6 = 8LL * (int)v4;
v7 = 0LL;
if ( !(_DWORD)v4 )
return v7;
if ( v5 > a1 )
return func3(a1, a2, v4, 0LL, v5, v6);
v8 = 0LL;
if ( v5 < a1 )
v8 = func3(a1, a2 + v6 + 8, (unsigned int)(a3 - v4 - 1), 0LL, v5, v6);
return v8;
}

original_code:
Vertice binary_search(Vertice v, Vertice *n, int size){
  int p = size / 2;
  if(v == n[p])
    return v;
  else if(p){
    if(v < n[p])
      return binary_search(v, n, p);
    if(v > n[p])
      return binary_search(v, &n[p + 1], size - p - 1);
  }
  return ((void *)0);
}

canonical_original_code:
struct VERTICE *binary_search(struct VERTICE *v, struct VERTICE **n, int size){
  int p = size / 2;
  if(v == n[p])
    return v;
  else if(p){
    if(v < n[p])
      return binary_search(v, n, p);
    if(v > n[p])
      return binary_search(v, &n[p + 1], size - p - 1);
  }
  return ((void *)0);
}

variable_types:
v
struct VERTICE *

variable_types:
n
struct VERTICE **

variable_types: p int

return_type: struct VERTICE { int line; char **info; unsigned long size_info; struct NEIGHBORHOOD { struct VERTICE **vertice; int size; struct WORD_TABLE { struct VERTICE **set; struct NODE { int not_null; int pos_word; int num_occur; } *word_vert_neig; int length_vert_neig; int free_vert_neig; struct NODE *word_neig; int length_neig; int free_neig; double f; } *table; } neighborhood; } *


decompiled_code:
__int64 __fastcall neighborhood_search(unsigned __int64 a1, __int64 a2)
{
return binary_search(a1, *(_QWORD *)a2, *(_DWORD *)(a2 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 a1, __int64 a2)
{
return func3(a1, *(_QWORD *)a2, *(_DWORD *)(a2 + 8));
}

original_code:
Vertice neighborhood_search(Vertice v, Neighborhood *n){
  return binary_search(v, n->vertice, n->size);
}

canonical_original_code:
struct VERTICE *neighborhood_search(struct VERTICE *v, struct NEIGHBORHOOD *n){
  return binary_search(v, n->vertice, n->size);
}

variable_types:
n
struct NEIGHBORHOOD *


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
perror(a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
perror(a1);
exit(0);
}

original_code:
void error(char *str){
  perror(str);
  exit(0);
}

variable_types:
str
char *


decompiled_code:
void *__fastcall safe_malloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
error("malloc");
return result;
}

canonical_decompiled_code:
void *__fastcall func8(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
func7("malloc");
return result;
}

original_code:
void *safe_malloc(size_t size){
  void *aux = malloc(size);
  if(!aux)
    error("malloc");
  return aux;
}

canonical_original_code:
void *safe_malloc(unsigned long size){
  void *aux = malloc(size);
  if(!aux)
    error("malloc");
  return aux;
}

variable_types:
aux
void *


decompiled_code:
void *__fastcall safe_realloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
error("realloc");
return result;
}

canonical_decompiled_code:
void *__fastcall func9(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
func7("realloc");
return result;
}

original_code:
void *safe_realloc(void *array, size_t size){
  if(!(array = realloc(array, size)))
    error("realloc");
  return array;
}

canonical_original_code:
void *safe_realloc(void *array, unsigned long size){
  if(!(array = realloc(array, size)))
    error("realloc");
  return array;
}

variable_types:
array
void *


decompiled_code:
_BOOL8 __fastcall end_read_block(char *a1)
{
_BOOL8 result; // rax
char i; // al

result = 1LL;
if ( a1 )
{
for ( i = *a1; *a1 == 32; i = *a1 )
++a1;
result = i == 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char *a1)
{
_BOOL8 result; // rax
char i; // al

result = 1LL;
if ( a1 )
{
for ( i = *a1; *a1 == 32; i = *a1 )
++a1;
result = i == 0;
}
return result;
}

original_code:
int end_read_block(char *line){
  if(line){
    while(*line == ' ')
      line++;
    if(*line)
      return 0;
  }
  return 1;
}

variable_types:
line
char *


info

decompiled_code:
void __noreturn info()
{
puts(s);
exit(0);
}

original_code:
void info(){
  printf("USO:\n\t./neighborhood NOME_DO_ARQUIVO_DE_DADOS [nome_do_arquivo_de_saída_prob] [nome_do_arquivo_de_saída_neig]\n\n");
  exit(0);
}


decompiled_code:
void __noreturn format_error_constant()
{
puts("Erro no formato da constante no arquivo!");
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("Erro no formato da constante no arquivo!");
exit(0);
}

original_code:
void format_error_constant(){
  printf("Erro no formato da constante no arquivo!\n");
  exit(0);
}


decompiled_code:
__int64 __fastcall read_constant(char *a1, __int64 a2, double a3, double a4, double a5)
{
__int64 result; // rax
double v6; // xmm1_8
__int64 v7; // rdx

data[3] = 0.0;
result = (unsigned __int8)*a1;
if ( (_BYTE)result )
{
*(_QWORD *)&v6 = (unsigned int)LC1;
v7 = 0LL;
do
{
if ( (_DWORD)v7 == 1 )
{
a2 = (unsigned int)(result - 48);
if ( (unsigned __int8)(result - 48) > 9u )
{
if ( (_BYTE)result != 32 && (_BYTE)result != 10 )
format_error_constant(a1, a2, v7, data, 1LL, 2LL, a3, v6, a5, 10.0, 0.1);
v7 = 2LL;
}
else
{
v6 = *(float *)&v6 * 0.1;
*(float *)&v6 = v6;
a3 = (float)((float)((char)result - 48) * *(float *)&v6) + data[3];
data[3] = a3;
}
}
else if ( (_DWORD)v7 == 2 )
{
if ( (_BYTE)result != 32 && (_BYTE)result != 10 )
format_error_constant(a1, a2, v7, data, 1LL, 2LL, a3, v6, a5, 10.0, 0.1);
}
else
{
a2 = (unsigned int)(result - 48);
if ( (unsigned __int8)(result - 48) > 9u )
{
if ( (result & 0xFD) != 44 )
format_error_constant(a1, a2, v7, data, 1LL, 2LL, a3, v6, a5, 10.0, 0.1);
v7 = 1LL;
}
else
{
a5 = 10.0 * data[3];
data[3] = a5;
a3 = (double)(*a1 - 48) + a5;
data[3] = a3;
}
}
result = (unsigned __int8)*++a1;
}
while ( (_BYTE)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, __int64 a2, double a3, double a4, double a5)
{
__int64 result; // rax
double v6; // xmm1_8
__int64 v7; // rdx

data[3] = 0.0;
result = (unsigned __int8)*a1;
if ( (_BYTE)result )
{
*(_QWORD *)&v6 = (unsigned int)LC1;
v7 = 0LL;
do
{
if ( (_DWORD)v7 == 1 )
{
a2 = (unsigned int)(result - 48);
if ( (unsigned __int8)(result - 48) > 9u )
{
if ( (_BYTE)result != 32 && (_BYTE)result != 10 )
func0(a1, a2, v7, data, 1LL, 2LL, a3, v6, a5, 10.0, 0.1);
v7 = 2LL;
}
else
{
v6 = *(float *)&v6 * 0.1;
*(float *)&v6 = v6;
a3 = (float)((float)((char)result - 48) * *(float *)&v6) + data[3];
data[3] = a3;
}
}
else if ( (_DWORD)v7 == 2 )
{
if ( (_BYTE)result != 32 && (_BYTE)result != 10 )
func0(a1, a2, v7, data, 1LL, 2LL, a3, v6, a5, 10.0, 0.1);
}
else
{
a2 = (unsigned int)(result - 48);
if ( (unsigned __int8)(result - 48) > 9u )
{
if ( (result & 0xFD) != 44 )
func0(a1, a2, v7, data, 1LL, 2LL, a3, v6, a5, 10.0, 0.1);
v7 = 1LL;
}
else
{
a5 = 10.0 * data[3];
data[3] = a5;
a3 = (double)(*a1 - 48) + a5;
data[3] = a3;
}
}
result = (unsigned __int8)*++a1;
}
while ( (_BYTE)result );
}
return result;
}

original_code:
void read_constant(char *line){
  int state = 0;
  float decimal = 1;
  data.constant = 0;
  for(; *line; line++){
    switch(state){
    case 0:
      if('0' <= *line && *line <= '9')
 data.constant = (data.constant *= 10) + (float)(*line - '0');
      else if(*line == '.' || *line == ',')
 state = 1;
      else
 format_error_constant();
      break;
    case 1:
      if('0' <= *line && *line <= '9')
 data.constant += (float)(*line - '0') * (decimal *= 0.1);
      else if(*line == ' ' || *line == '\n')
 state = 2;
      else
 format_error_constant();
      break;
    case 2:
      if(*line != ' ' && *line != '\n')
 format_error_constant();
      break;
    }
  }
}

variable_types: state int

variable_types: decimal float


CharToDigit

decompiled_code:
__int64 __fastcall CharToDigit(char a1)
{
return (unsigned int)(a1 - 48);
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
return (unsigned int)(a1 - 48);
}

original_code:
static int CharToDigit(char ch)
{
    return (ch - '0');
}

variable_types: ch char


decompiled_code:
__int64 __fastcall mt_get_addr_info(_QWORD *a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( !__memory_trace_info_head_ )
return 0xFFFFFFFFLL;
*a1 = __memory_trace_info_head_;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( !__memory_trace_info_head_ )
return 0xFFFFFFFFLL;
*a1 = __memory_trace_info_head_;
return 0LL;
}

original_code:
int mt_get_addr_info(mti **mt)
{
 if(!mt || !___memory_trace_info_head___){
  return -1;
 }
 *mt = ___memory_trace_info_head___;
 return 0;
}

canonical_original_code:
int mt_get_addr_info(struct malloc_trace_info **mt)
{
 if(!mt || !___memory_trace_info_head___){
  return -1;
 }
 *mt = ___memory_trace_info_head___;
 return 0;
}

variable_types: struct malloc_trace_info { char *head; struct malloc_trace_info *prev; struct malloc_trace_info *next; unsigned long size; char *callfunc; char *file; int line; } **


decompiled_code:
__int64 __fastcall mt_get_addr_next_info(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( !*(_QWORD *)a1 )
return 0xFFFFFFFFLL;
*(_QWORD *)a1 = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( !*(_QWORD *)a1 )
return 0xFFFFFFFFLL;
*(_QWORD *)a1 = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
return 0LL;
}

original_code:
int mt_get_addr_next_info(mti **mt)
{
 if(!mt || !*mt){
  return -1;
 }
 *mt = (*mt)->next;
 return 0;
}

canonical_original_code:
int mt_get_addr_next_info(struct malloc_trace_info **mt)
{
 if(!mt || !*mt){
  return -1;
 }
 *mt = (*mt)->next;
 return 0;
}

user_defined_types: struct malloc_trace_info { char *head; struct malloc_trace_info *prev; struct malloc_trace_info *next; unsigned long size; char *callfunc; char *file; int line; }


decompiled_code:
__int64 __fastcall mt_get_addr(__int64 a1, _QWORD *a2, _QWORD *a3, _QWORD *a4, _QWORD *a5, _DWORD *a6)
{
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 )
*a2 = a1 + 56;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 24);
if ( a4 )
*a4 = *(_QWORD *)(a1 + 32);
if ( a5 )
*a5 = *(_QWORD *)(a1 + 40);
result = 0LL;
if ( a6 )
{
*a6 = *(_DWORD *)(a1 + 48);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2, _QWORD *a3, _QWORD *a4, _QWORD *a5, _DWORD *a6)
{
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 )
*a2 = a1 + 56;
if ( a3 )
*a3 = *(_QWORD *)(a1 + 24);
if ( a4 )
*a4 = *(_QWORD *)(a1 + 32);
if ( a5 )
*a5 = *(_QWORD *)(a1 + 40);
result = 0LL;
if ( a6 )
{
*a6 = *(_DWORD *)(a1 + 48);
result = 0LL;
}
return result;
}

original_code:
int mt_get_addr(mti *mt, void **addr, size_t *size, char **callfunc, char **file, int *line)
{
 if(!mt){
  return -1;
 }
 if(addr){
  *addr = (void *)(((char*)mt) + sizeof(mti));
 }
 if(size)*size = mt->size;
 if(callfunc)*callfunc = mt->callfunc;
 if(file)*file = mt->file;
 if(line)*line = mt->line;
 return 0;
}

canonical_original_code:
int mt_get_addr(struct malloc_trace_info *mt, void **addr, unsigned long *size, char **callfunc, char **file, int *line)
{
 if(!mt){
  return -1;
 }
 if(addr){
  *addr = (void *)(((char *)mt) + sizeof(mti));
 }
 if(size)*size = mt->size;
 if(callfunc)*callfunc = mt->callfunc;
 if(file)*file = mt->file;
 if(line)*line = mt->line;
 return 0;
}

variable_types: struct malloc_trace_info { char *head; struct malloc_trace_info *prev; struct malloc_trace_info *next; unsigned long size; char *callfunc; char *file; int line; } *

variable_types:
addr
void **

variable_types:
size
unsigned long *

variable_types:
callfunc
char **

variable_types:
file
char **

variable_types:
line
int *


decompiled_code:
__int64 mt_get_count()
{
unsigned int i; // ebx
__int64 v2[2]; // [rsp+8h] [rbp-10h] BYREF

i = 0;
if ( !(unsigned int)mt_get_addr_info(v2) )
{
for ( i = 1; ; ++i )
{
mt_get_addr_next_info((__int64)v2);
if ( !v2[0] )
break;
}
}
return i;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int i; // ebx
__int64 v2[2]; // [rsp+8h] [rbp-10h] BYREF

i = 0;
if ( !(unsigned int)func1(v2) )
{
for ( i = 1; ; ++i )
{
func2((__int64)v2);
if ( !v2[0] )
break;
}
}
return i;
}

original_code:
int mt_get_count(void)
{
 mti *mt;
 int i = 0;
 if(mt_get_addr_info(&mt) != 0){
  return 0;
 }
 i++;
 while(1){
  mt_get_addr_next_info(&mt);
  if(!mt){
   break;
  }
  i++;
 }
 return i;
}

canonical_original_code:
int mt_get_count()
{
 struct malloc_trace_info *mt;
 int i = 0;
 if(mt_get_addr_info(&mt) != 0){
  return 0;
 }
 i++;
 while(1){
  mt_get_addr_next_info(&mt);
  if(!mt){
   break;
  }
  i++;
 }
 return i;
}

variable_types: i int


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

result = 0LL;
if ( !strcmp(*(const char **)(a1 - 56), "MTI") )
result = a1 - 56;
return result;
}

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

result = 0LL;
if ( !strcmp(*(const char **)(a1 - 56), "MTI") )
result = a1 - 56;
return result;
}

original_code:
mti* mt_get_addr_by_mti(void *addr)
{
 mti *mt;
 int i;
 mt = (mti*)(((char*)addr) - sizeof(mti));
 if(!mt){
  return ((void *)0);
 }
 i = memcmp(mt->head, ___mti_check_header___, strlen(___mti_check_header___) + 1);
 return (i == 0 ? mt : ((void *)0));
}

canonical_original_code:
struct malloc_trace_info *mt_get_addr_by_mti(void *addr)
{
 struct malloc_trace_info *mt;
 int i;
 mt = (struct malloc_trace_info *)(((char *)addr) - sizeof(mti));
 if(!mt){
  return ((void *)0);
 }
 i = memcmp(mt->head, ___mti_check_header___, strlen(___mti_check_header___) + 1);
 return (i == 0 ? mt : ((void *)0));
}

variable_types:
addr
void *

return_type: struct malloc_trace_info { char *head; struct malloc_trace_info *prev; struct malloc_trace_info *next; unsigned long size; char *callfunc; char *file; int line; } *


decompiled_code:
__int64 __fastcall mt_unregister(void *ptr)
{
__int64 v1; // rax
_QWORD *v2; // rbx
__int64 v3; // r8
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // rax

if ( ptr )
{
v1 = mt_get_addr_by_mti((__int64)ptr);
v2 = (_QWORD *)v1;
if ( v1 )
{
v3 = *(_QWORD *)(v1 + 24);
if ( *(_BYTE *)(v1 + v3 + 56) != 0xCC )
fprintf(
stderr,
"%s : allocator %s : size %ld : %s(%d)\n",
"Warrning: buffer over run",
*(const char **)(v1 + 32),
v3,
*(const char **)(v1 + 40),
*(unsigned int *)(v1 + 48));
v4 = v2[1];
if ( v4 )
*(_QWORD *)(v4 + 16) = v2[2];
v5 = v2[2];
if ( v5 )
*(_QWORD *)(v5 + 8) = v2[1];
if ( (_QWORD *)__memory_trace_info_head_ == v2 )
__memory_trace_info_head_ = v2[2];
if ( (_QWORD *)__memory_trace_info_tail_ == v2 )
__memory_trace_info_tail_ = v2[1];
free(v2);
result = 0LL;
}
else
{
fprintf(
stderr,
"%s\n%s\n",
"Warrning: buffer addr in non mti header",
"if destroy memory table ? or mti register no use allocate buffer");
free(ptr);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s\n", "Warrning: buffer addr is NULL");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *ptr)
{
__int64 v1; // rax
_QWORD *v2; // rbx
__int64 v3; // r8
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // rax

if ( ptr )
{
v1 = func5((__int64)ptr);
v2 = (_QWORD *)v1;
if ( v1 )
{
v3 = *(_QWORD *)(v1 + 24);
if ( *(_BYTE *)(v1 + v3 + 56) != 0xCC )
fprintf(
stderr,
"%s : allocator %s : size %ld : %s(%d)\n",
"Warrning: buffer over run",
*(const char **)(v1 + 32),
v3,
*(const char **)(v1 + 40),
*(unsigned int *)(v1 + 48));
v4 = v2[1];
if ( v4 )
*(_QWORD *)(v4 + 16) = v2[2];
v5 = v2[2];
if ( v5 )
*(_QWORD *)(v5 + 8) = v2[1];
if ( (_QWORD *)__memory_trace_info_head_ == v2 )
__memory_trace_info_head_ = v2[2];
if ( (_QWORD *)__memory_trace_info_tail_ == v2 )
__memory_trace_info_tail_ = v2[1];
free(v2);
result = 0LL;
}
else
{
fprintf(
stderr,
"%s\n%s\n",
"Warrning: buffer addr in non mti header",
"if destroy memory table ? or mti register no use allocate buffer");
free(ptr);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s\n", "Warrning: buffer addr is NULL");
result = 0LL;
}
return result;
}

original_code:
int mt_unregister(void *addr)
{
 mti *n;
 if(!addr){
  fprintf(stderr, "%s\n", "Warrning: buffer addr is NULL");
  return 0;
 }
 n = mt_get_addr_by_mti(addr);
 if(n == ((void *)0)){
  fprintf(stderr, "%s\n%s\n",
   "Warrning: buffer addr in non mti header",
   "if destroy memory table ? or mti register no use allocate buffer"
  );
  free(addr);
  return -1;
 }
 if((*((unsigned char*)n + sizeof(mti) + n->size) != 0xcc)){
  fprintf(stderr, "%s : allocator %s : size %ld : %s(%d)\n",
   "Warrning: buffer over run",
   n->callfunc, n->size, n->file, n->line
  );
 }
 if(n->prev)n->prev->next = n->next;
 if(n->next)n->next->prev = n->prev;
 if(___memory_trace_info_head___ == n){
  ___memory_trace_info_head___ = ___memory_trace_info_head___->next;
 }
 if(___memory_trace_info_tail___ == n){
  ___memory_trace_info_tail___ = ___memory_trace_info_tail___->prev;
 }
 memset(n, 0xdd, sizeof(mti) + n->size);
 free(n);
 return 0;
}

canonical_original_code:
int mt_unregister(void *addr)
{
 struct malloc_trace_info *n;
 if(!addr){
  fprintf(stderr, "%s\n", "Warrning: buffer addr is NULL");
  return 0;
 }
 n = mt_get_addr_by_mti(addr);
 if(n == ((void *)0)){
  fprintf(stderr, "%s\n%s\n",
   "Warrning: buffer addr in non mti header",
   "if destroy memory table ? or mti register no use allocate buffer"
  );
  free(addr);
  return -1;
 }
 if((*((unsigned char *)n + sizeof(mti) + n->size) != 0xcc)){
  fprintf(stderr, "%s : allocator %s : size %ld : %s(%d)\n",
   "Warrning: buffer over run",
   n->callfunc, n->size, n->file, n->line
  );
 }
 if(n->prev)n->prev->next = n->next;
 if(n->next)n->next->prev = n->prev;
 if(___memory_trace_info_head___ == n){
  ___memory_trace_info_head___ = ___memory_trace_info_head___->next;
 }
 if(___memory_trace_info_tail___ == n){
  ___memory_trace_info_tail___ = ___memory_trace_info_tail___->prev;
 }
 memset(n, 0xdd, sizeof(mti) + n->size);
 free(n);
 return 0;
}


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

v1 = mt_get_addr_by_mti(a1);
if ( v1 )
result = *(_QWORD *)(v1 + 24);
else
result = 0LL;
return result;
}

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

v1 = func5(a1);
if ( v1 )
result = *(_QWORD *)(v1 + 24);
else
result = 0LL;
return result;
}

original_code:
size_t mt_get_buf_size(void *addr)
{
 mti *mt;
 mt = mt_get_addr_by_mti(addr);
 if(!mt){
  return 0;
 }
 return mt->size;
}

canonical_original_code:
unsigned long mt_get_buf_size(void *addr)
{
 struct malloc_trace_info *mt;
 mt = mt_get_addr_by_mti(addr);
 if(!mt){
  return 0;
 }
 return mt->size;
}

return_type: unsigned long


decompiled_code:
__int64 mt_malloc()
{
return mt_register();
}

canonical_decompiled_code:
__int64 func0()
{
return mt_register();
}

original_code:
void *mt_malloc(size_t size, char *callfunc, char *file, int line)
{
 return mt_register(size, callfunc, file, line);
}

canonical_original_code:
void *mt_malloc(unsigned long size, char *callfunc, char *file, int line)
{
 return mt_register(size, callfunc, file, line);
}

variable_types:
size
unsigned long

variable_types:
callfunc
char *

variable_types:
file
char *

variable_types: line int


decompiled_code:
__int64 mt_free()
{
return mt_unregister();
}

canonical_decompiled_code:
__int64 func1()
{
return mt_unregister();
}

original_code:
int mt_free(void *addr)
{
 return mt_unregister(addr);
}


decompiled_code:
void *__fastcall mt_realloc(void *src, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
void *v5; // rbx
size_t v6; // rax

v5 = (void *)mt_malloc(a2, a3, a4, a5);
if ( v5 )
{
v6 = mt_get_buf_size(src);
memmove(v5, src, v6);
mt_free(src);
}
return v5;
}

canonical_decompiled_code:
void *__fastcall func2(void *src, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
void *v5; // rbx
size_t v6; // rax

v5 = (void *)func0(a2, a3, a4, a5);
if ( v5 )
{
v6 = mt_get_buf_size(src);
memmove(v5, src, v6);
func1(src);
}
return v5;
}

original_code:
void *mt_realloc(void *addr, size_t size, char *callfunc, char *file, int line)
{
 void *buf;
 buf = mt_malloc(size, callfunc, file, line);
 if(buf){
  memmove(buf, addr, mt_get_buf_size(addr));
  mt_free(addr);
 }
 return buf;
}

canonical_original_code:
void *mt_realloc(void *addr, unsigned long size, char *callfunc, char *file, int line)
{
 void *buf;
 buf = mt_malloc(size, callfunc, file, line);
 if(buf){
  memmove(buf, addr, mt_get_buf_size(addr));
  mt_free(addr);
 }
 return buf;
}

variable_types:
buf
void *


decompiled_code:
void *__fastcall mt_calloc(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
void *v5; // rax
void *v6; // rbx

v5 = (void *)mt_malloc(a1 * a2, a3, a4, a5);
v6 = v5;
if ( v5 )
memset(v5, 0, a1 * a2);
return v6;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
void *v5; // rax
void *v6; // rbx

v5 = (void *)func0(a1 * a2, a3, a4, a5);
v6 = v5;
if ( v5 )
memset(v5, 0, a1 * a2);
return v6;
}

original_code:
void *mt_calloc(size_t size1, size_t size2, char *callfunc, char *file, int line)
{
 void *buf;
 buf = mt_malloc(size1 * size2, callfunc, file, line);
 if(buf){
  memset(buf, 0x00, size1 * size2);
 }
 return buf;
}

canonical_original_code:
void *mt_calloc(unsigned long size1, unsigned long size2, char *callfunc, char *file, int line)
{
 void *buf;
 buf = mt_malloc(size1 * size2, callfunc, file, line);
 if(buf){
  memset(buf, 0x00, size1 * size2);
 }
 return buf;
}


decompiled_code:
char *__fastcall mt_strdup(char *src, __int64 a2, __int64 a3, unsigned int a4)
{
size_t v6; // rax
char *v7; // rax
char *v8; // rbx

v6 = strlen(src);
v7 = (char *)mt_malloc(v6 + 1, a2, a3, a4);
v8 = v7;
if ( v7 )
strcpy(v7, src);
return v8;
}

canonical_decompiled_code:
char *__fastcall func4(char *src, __int64 a2, __int64 a3, unsigned int a4)
{
size_t v6; // rax
char *v7; // rax
char *v8; // rbx

v6 = strlen(src);
v7 = (char *)func0(v6 + 1, a2, a3, a4);
v8 = v7;
if ( v7 )
strcpy(v7, src);
return v8;
}

original_code:
char *mt_strdup(char *str, char *callfunc, char *file, int line)
{
 char *buf;
 buf = (char*)mt_malloc(sizeof(char) * (strlen(str) + 1), callfunc, file, line);
 if(buf){
  strcpy(buf, str);
 }
 return buf;
}

canonical_original_code:
char *mt_strdup(char *str, char *callfunc, char *file, int line)
{
 char *buf;
 buf = (char *)mt_malloc(sizeof(char) * (strlen(str) + 1), callfunc, file, line);
 if(buf){
  strcpy(buf, str);
 }
 return buf;
}

variable_types:
str
char *

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall msl_alloc(_QWORD *a1, __int64 a2)
{
*a1 = mt_register(a2, "msl_alloc", "./msl.c", 21LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2)
{
*a1 = mt_register(a2, "msl_alloc", "./msl.c", 21LL);
return 0LL;
}

original_code:
int msl_alloc(void **buf, size_t size)
{
 *buf = mt_register(size, "msl_alloc", "./msl.c", 21);
 if(!buf){
  return -1;
 }
 return 0;
}

canonical_original_code:
int msl_alloc(void **buf, unsigned long size)
{
 *buf = mt_register(size, "msl_alloc", "./msl.c", 21);
 if(!buf){
  return -1;
 }
 return 0;
}

variable_types:
buf
void **


decompiled_code:
__int64 __fastcall msl_free(_QWORD *a1)
{
if ( !a1 )
return 0LL;
if ( *a1 )
{
mt_unregister();
*a1 = 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
if ( !a1 )
return 0LL;
if ( *a1 )
{
mt_unregister();
*a1 = 0LL;
}
return 0LL;
}

original_code:
int msl_free(void **buf)
{
 if(!buf || !*buf){
  return 0;
 }
 mt_unregister(*buf);
 *buf = ((void *)0);
 return 0;
}


EsLoadShader

repo: yougukepp/Qe

decompiled_code:
__int64 __fastcall EsLoadShader(__int64 a1, const char *a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx
unsigned int v5; // ebp
char *v6; // r12
const char *v7; // [rsp+8h] [rbp-30h] BYREF
int v8; // [rsp+18h] [rbp-20h] BYREF
int v9[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v7 = a2;
v2 = glCreateShader();
v3 = v2;
if ( v2 )
{
glShaderSource(v2, 1LL, &v7, 0LL);
glCompileShader(v3);
glGetShaderiv(v3, 35713LL, v9);
if ( !v9[0] )
{
v8 = 0;
glGetShaderiv(v3, 35716LL, &v8);
v5 = v8;
if ( v8 > 1 )
{
v6 = (char *)malloc(v8);
glGetShaderInfoLog(v3, v5, 0LL, v6);
printf("Error compiling shader:%s\n", v6);
printf("shader content:\n%s", v7);
free(v6);
}
glDeleteShader(v3);
v3 = 0;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx
unsigned int v5; // ebp
char *v6; // r12
const char *v7; // [rsp+8h] [rbp-30h] BYREF
int v8; // [rsp+18h] [rbp-20h] BYREF
int v9[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v7 = a2;
v2 = glCreateShader();
v3 = v2;
if ( v2 )
{
glShaderSource(v2, 1LL, &v7, 0LL);
glCompileShader(v3);
glGetShaderiv(v3, 35713LL, v9);
if ( !v9[0] )
{
v8 = 0;
glGetShaderiv(v3, 35716LL, &v8);
v5 = v8;
if ( v8 > 1 )
{
v6 = (char *)malloc(v8);
glGetShaderInfoLog(v3, v5, 0LL, v6);
printf("Error compiling shader:%s\n", v6);
printf("shader content:\n%s", v7);
free(v6);
}
glDeleteShader(v3);
v3 = 0;
}
}
return v3;
}

original_code:
static GLuint EsLoadShader(GLenum type, const GLchar* shaderSrc)
{
   GLuint shader;
   GLint compiled;
   shader = glCreateShader(type);
   if(0 == shader)
   {
       return 0;
   }
   glShaderSource(shader, 1, &shaderSrc, ((void *)0));
   glCompileShader(shader);
   glGetShaderiv(shader, 0x8B81, &compiled);
   if(!compiled)
   {
      GLint infoLen = 0;
      glGetShaderiv(shader, 0x8B84, &infoLen);
      if(infoLen > 1)
      {
         GLchar* infoLog = malloc(sizeof(GLchar) * infoLen);
         glGetShaderInfoLog (shader, infoLen, ((void *)0), infoLog);
         printf("Error compiling shader:%s\n", infoLog);
         printf("shader content:\n%s", shaderSrc);
         free(infoLog);
      }
      glDeleteShader ( shader );
      return 0;
   }
   return shader;
}

canonical_original_code:
static unsigned int EsLoadShader(unsigned int type, char *shaderSrc)
{
   unsigned int shader;
   int compiled;
   shader = glCreateShader(type);
   if(0 == shader)
   {
       return 0;
   }
   glShaderSource(shader, 1, &shaderSrc, ((void *)0));
   glCompileShader(shader);
   glGetShaderiv(shader, 0x8B81, &compiled);
   if(!compiled)
   {
      int infoLen = 0;
      glGetShaderiv(shader, 0x8B84, &infoLen);
      if(infoLen > 1)
      {
         char *infoLog = malloc(sizeof(GLchar) * infoLen);
         glGetShaderInfoLog (shader, infoLen, ((void *)0), infoLog);
         printf("Error compiling shader:%s\n", infoLog);
         printf("shader content:\n%s", shaderSrc);
         free(infoLog);
      }
      glDeleteShader ( shader );
      return 0;
   }
   return shader;
}

variable_types:
type
unsigned int

variable_types:
shaderSrc
char *

variable_types:
shader
unsigned int

variable_types: compiled int

variable_types: infoLen int

variable_types:
infoLog
char *

return_type: unsigned int


EsLoaderProgram

decompiled_code:
__int64 __fastcall EsLoaderProgram(const char *a1, const char *a2)
{
unsigned int v2; // ebx
unsigned int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // er12

v2 = EsLoadShader(35633LL, a1);
if ( v2 )
{
v4 = EsLoadShader(35632LL, a2);
if ( v4 )
{
v5 = glCreateProgram();
v6 = v5;
if ( v5 )
{
glAttachShader(v5, v2);
glAttachShader(v6, v4);
v2 = v6;
}
else
{
v2 = 0;
}
}
else
{
glDeleteShader(v2);
v2 = 0;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
unsigned int v2; // ebx
unsigned int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // er12

v2 = func0(35633LL, a1);
if ( v2 )
{
v4 = func0(35632LL, a2);
if ( v4 )
{
v5 = glCreateProgram();
v6 = v5;
if ( v5 )
{
glAttachShader(v5, v2);
glAttachShader(v6, v4);
v2 = v6;
}
else
{
v2 = 0;
}
}
else
{
glDeleteShader(v2);
v2 = 0;
}
}
return v2;
}

original_code:
GLuint EsLoaderProgram(const GLchar* vertexShaderSrc, const GLchar* fragmentShaderSrc)
{
    GLuint vertexShader;
    GLuint fragmentShader;
    GLuint programObject;
    vertexShader = EsLoadShader(0x8B31, vertexShaderSrc);
    if (0 == vertexShader)
    {
        return 0;
    }
    fragmentShader = EsLoadShader(0x8B30, fragmentShaderSrc);
    if(0 == fragmentShader)
    {
        glDeleteShader(vertexShader);
        return 0;
    }
    programObject = glCreateProgram();
    if(0 == programObject)
    {
        return 0;
    }
    glAttachShader(programObject, vertexShader);
    glAttachShader(programObject, fragmentShader);
    return programObject;
}

canonical_original_code:
unsigned int EsLoaderProgram(char *vertexShaderSrc, char *fragmentShaderSrc)
{
    unsigned int vertexShader;
    unsigned int fragmentShader;
    unsigned int programObject;
    vertexShader = EsLoadShader(0x8B31, vertexShaderSrc);
    if (0 == vertexShader)
    {
        return 0;
    }
    fragmentShader = EsLoadShader(0x8B30, fragmentShaderSrc);
    if(0 == fragmentShader)
    {
        glDeleteShader(vertexShader);
        return 0;
    }
    programObject = glCreateProgram();
    if(0 == programObject)
    {
        return 0;
    }
    glAttachShader(programObject, vertexShader);
    glAttachShader(programObject, fragmentShader);
    return programObject;
}

variable_types:
vertexShaderSrc
char *

variable_types:
fragmentShaderSrc
char *

variable_types:
vertexShader
unsigned int

variable_types:
fragmentShader
unsigned int

variable_types:
programObject
unsigned int


EsBindAttribLocation

decompiled_code:
__int64 __fastcall EsBindAttribLocation(unsigned int a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 i; // rbx
__int64 result; // rax

if ( a3 > 0 )
{
v3 = (unsigned int)a3;
for ( i = 0LL; i != v3; ++i )
result = glBindAttribLocation(a1, (unsigned int)i, *(_QWORD *)(a2 + 8 * i));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 i; // rbx
__int64 result; // rax

if ( a3 > 0 )
{
v3 = (unsigned int)a3;
for ( i = 0LL; i != v3; ++i )
result = glBindAttribLocation(a1, (unsigned int)i, *(_QWORD *)(a2 + 8 * i));
}
return result;
}

original_code:
GLvoid EsBindAttribLocation(GLint programId, GLchar *pAttr[], GLint size)
{
    GLint i = 0;
    for(i=0; i<size; i++)
    {
        glBindAttribLocation(programId, i, *pAttr);
        pAttr++;
    }
}

canonical_original_code:
void EsBindAttribLocation(int programId, char *pAttr[], int size)
{
    int i = 0;
    for(i=0; i<size; i++)
    {
        glBindAttribLocation(programId, i, *pAttr);
        pAttr++;
    }
}

variable_types: programId int

variable_types:
pAttr
char *[]

variable_types: size int

variable_types: i int


EsLinkProgram

decompiled_code:
__int64 __fastcall EsLinkProgram(unsigned int a1)
{
__int64 result; // rax
unsigned int v2; // ebp
char *v3; // r12
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

glLinkProgram();
result = glGetProgramiv(a1, 35714LL, v5);
if ( !v5[0] )
{
v4 = 0;
glGetProgramiv(a1, 35716LL, &v4);
v2 = v4;
if ( v4 > 1 )
{
v3 = (char *)malloc(v4);
glGetProgramInfoLog(a1, v2, 0LL, v3);
printf("Error linking program:%s\n", v3);
free(v3);
}
result = glDeleteProgram(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 result; // rax
unsigned int v2; // ebp
char *v3; // r12
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

glLinkProgram();
result = glGetProgramiv(a1, 35714LL, v5);
if ( !v5[0] )
{
v4 = 0;
glGetProgramiv(a1, 35716LL, &v4);
v2 = v4;
if ( v4 > 1 )
{
v3 = (char *)malloc(v4);
glGetProgramInfoLog(a1, v2, 0LL, v3);
printf("Error linking program:%s\n", v3);
free(v3);
}
result = glDeleteProgram(a1);
}
return result;
}

original_code:
GLvoid EsLinkProgram(GLint programId)
{
    GLint linked;
    glLinkProgram(programId);
    glGetProgramiv(programId, 0x8B82, &linked);
    if(!linked)
    {
        GLint infoLen = 0;
        glGetProgramiv(programId, 0x8B84, &infoLen);
        if(infoLen > 1)
        {
            GLchar* infoLog = malloc(sizeof(GLchar) * infoLen);
            glGetProgramInfoLog(programId, infoLen, ((void *)0), infoLog);
            printf("Error linking program:%s\n", infoLog);
            free(infoLog);
        }
        glDeleteProgram(programId);
        return;
    }
}

canonical_original_code:
void EsLinkProgram(int programId)
{
    int linked;
    glLinkProgram(programId);
    glGetProgramiv(programId, 0x8B82, &linked);
    if(!linked)
    {
        int infoLen = 0;
        glGetProgramiv(programId, 0x8B84, &infoLen);
        if(infoLen > 1)
        {
            char *infoLog = malloc(sizeof(GLchar) * infoLen);
            glGetProgramInfoLog(programId, infoLen, ((void *)0), infoLog);
            printf("Error linking program:%s\n", infoLog);
            free(infoLog);
        }
        glDeleteProgram(programId);
        return;
    }
}

variable_types: linked int


repo: younix/crypt

decompiled_code:
__int64 __fastcall gen_table(__int64 a1, __int64 a2)
{
__int64 v4; // rdi
__int64 v5; // rbx
__int64 v6; // r8
__int64 result; // rax
__int64 v8; // rcx
__int64 v9; // rdx

v4 = 0LL;
v5 = 0LL;
v6 = 26LL;
do
{
result = v5;
do
{
v8 = (int)v4 - 26 + (int)result;
if ( (int)v4 + (int)result <= 25 )
v8 = result + v4;
*(_BYTE *)(a1 + result) = byte_402004[v8];
v9 = (int)result + 26;
if ( (int)result >= 0 )
v9 = result;
*(_BYTE *)(a2 + result++) = byte_402004[v9];
}
while ( result != v6 );
a2 += 27LL;
--v5;
a1 += 27LL;
v4 += 2LL;
--v6;
}
while ( v6 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 v4; // rdi
__int64 v5; // rbx
__int64 v6; // r8
__int64 result; // rax
__int64 v8; // rcx
__int64 v9; // rdx

v4 = 0LL;
v5 = 0LL;
v6 = 26LL;
do
{
result = v5;
do
{
v8 = (int)v4 - 26 + (int)result;
if ( (int)v4 + (int)result <= 25 )
v8 = result + v4;
*(_BYTE *)(a1 + result) = byte_402004[v8];
v9 = (int)result + 26;
if ( (int)result >= 0 )
v9 = result;
*(_BYTE *)(a2 + result++) = byte_402004[v9];
}
while ( result != v6 );
a2 += 27LL;
--v5;
a1 += 27LL;
v4 += 2LL;
--v6;
}
while ( v6 );
return result;
}

original_code:
void
gen_table(char table[26][26], char rtable[26][26])
{
 char *abc = "abcdefghijklmnopqrstuvwxyz";
 for (int y = 0; y < 26; y++) {
  for (int x = 0; x < 26; x++) {
   table[y][x] = abc[x + y < 26 ? x + y: x + y - 26];
   rtable[y][x] = abc[x - y >= 0 ? x - y: x - y + 26];
  }
 }
}

variable_types:
table
char [26][26]

variable_types:
rtable
char [26][26]

variable_types:
abc
char *

variable_types: y int

variable_types: x int


usage

decompiled_code:
void __noreturn usage()
{
fwrite(
"usage: polybios [-dh] {-p PASSWORD | -t}\n"
"\n"
"OPTIONS\n"
"\t-d\tdecode\n"
"\t-p\tpassword\n"
"\t-t\tprint lookup table\n"
"\t-h\tshow this help message\n",
1uLL,
0x7CuLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func8()
{
fwrite(
"usage: polybios [-dh] {-p PASSWORD | -t}\n"
"\n"
"OPTIONS\n"
"\t-d\tdecode\n"
"\t-p\tpassword\n"
"\t-t\tprint lookup table\n"
"\t-h\tshow this help message\n",
1uLL,
0x7CuLL,
stderr);
exit(1);
}

original_code:
void
usage(void)
{
 fprintf(stderr, "usage: polybios [-dh] {-p PASSWORD | -t}\n"
   "\n"
   "OPTIONS\n"
   "\t-d\tdecode\n"
   "\t-p\tpassword\n"
   "\t-t\tprint lookup table\n"
   "\t-h\tshow this help message\n");
 exit(1);
}

canonical_original_code:
void usage()
{
 fprintf(stderr, "usage: polybios [-dh] {-p PASSWORD | -t}\n"
   "\n"
   "OPTIONS\n"
   "\t-d\tdecode\n"
   "\t-p\tpassword\n"
   "\t-t\tprint lookup table\n"
   "\t-h\tshow this help message\n");
 exit(1);
}