initICMPFilter

decompiled_code:
void __fastcall initICMPFilter(_OWORD *a1)
{
*a1 = -1LL;
a1[1] = -1LL;
}

canonical_decompiled_code:
void __fastcall func8(_OWORD *a1)
{
*a1 = -1LL;
a1[1] = -1LL;
}

original_code:
void initICMPFilter(struct icmp6_filter * filter)
{
 memset (filter, 0xFF, sizeof (struct icmp6_filter));;
}

canonical_original_code:
void initICMPFilter(struct icmp6_filter *filter)
{
 memset (filter, 0xFF, sizeof (struct icmp6_filter));;
}

variable_types: struct icmp6_filter { unsigned int icmp6_filt[8]; } *


allowTypeICMPfilter

repo: tcheneau/RplIcmp

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

result = (unsigned int)~(1 << a2);
*(_DWORD *)(a1 + 4LL * (a2 >> 5)) &= result;
return result;
}

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

result = (unsigned int)~(1 << a2);
*(_DWORD *)(a1 + 4LL * (a2 >> 5)) &= result;
return result;
}

original_code:
void allowTypeICMPfilter(struct icmp6_filter * filter, int type)
{
 ((((filter)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))));
}

canonical_original_code:
void allowTypeICMPfilter(struct icmp6_filter *filter, int type)
{
 ((((filter)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))));
}

variable_types: type int

return_type: void

user_defined_types: struct icmp6_filter { unsigned int icmp6_filt[8]; }


enableICMPfilter

decompiled_code:
int __fastcall enableICMPfilter(int fd, void *s2)
{
int v2; // eax
int v3; // eax
int result; // eax
int v5; // [rsp+Ch] [rbp-4Ch]
int v6; // [rsp+Ch] [rbp-4Ch]
socklen_t optlen; // [rsp+1Ch] [rbp-3Ch] BYREF
char optval[56]; // [rsp+20h] [rbp-38h] BYREF

optlen = 32;
v2 = setsockopt(fd, 58, 1, s2, 0x20u);
if ( v2 < 0 )
{
v5 = v2;
perror("setsockopt(ICMP6_FILTER)");
result = v5;
}
else
{
v3 = getsockopt(fd, 58, 1, optval, &optlen);
if ( v3 < 0 )
{
v6 = v3;
perror("getsockopt(ICMP6_FILTER)");
result = v6;
}
else
{
result = memcmp(optval, s2, 0x20uLL);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(int fd, void *s2)
{
int v2; // eax
int v3; // eax
int result; // eax
int v5; // [rsp+Ch] [rbp-4Ch]
int v6; // [rsp+Ch] [rbp-4Ch]
socklen_t optlen; // [rsp+1Ch] [rbp-3Ch] BYREF
char optval[56]; // [rsp+20h] [rbp-38h] BYREF

optlen = 32;
v2 = setsockopt(fd, 58, 1, s2, 0x20u);
if ( v2 < 0 )
{
v5 = v2;
perror("setsockopt(ICMP6_FILTER)");
result = v5;
}
else
{
v3 = getsockopt(fd, 58, 1, optval, &optlen);
if ( v3 < 0 )
{
v6 = v3;
perror("getsockopt(ICMP6_FILTER)");
result = v6;
}
else
{
result = memcmp(optval, s2, 0x20uLL);
}
}
return result;
}

original_code:
int enableICMPfilter(int icmp_sock, struct icmp6_filter * filter)
{
 int err;
 struct icmp6_filter applied_filter;
 socklen_t applied_filter_len = sizeof(struct icmp6_filter);
 err = setsockopt(icmp_sock, IPPROTO_ICMPV6, 1, filter,
    sizeof(struct icmp6_filter));
 if (err < 0) {
  perror("setsockopt(ICMP6_FILTER)");
  return err;
 }
 err = getsockopt(icmp_sock, IPPROTO_ICMPV6, 1, &applied_filter,
   &applied_filter_len);
 if (err <0)
 {
  perror("getsockopt(ICMP6_FILTER)");
  return err;
 }
 return memcmp(&applied_filter, filter, sizeof(struct icmp6_filter));
}

canonical_original_code:
int enableICMPfilter(int icmp_sock, struct icmp6_filter *filter)
{
 int err;
 struct icmp6_filter applied_filter;
 unsigned int applied_filter_len = sizeof(struct icmp6_filter);
 err = setsockopt(icmp_sock, IPPROTO_ICMPV6, 1, filter,
    sizeof(struct icmp6_filter));
 if (err < 0) {
  perror("setsockopt(ICMP6_FILTER)");
  return err;
 }
 err = getsockopt(icmp_sock, IPPROTO_ICMPV6, 1, &applied_filter,
   &applied_filter_len);
 if (err <0)
 {
  perror("getsockopt(ICMP6_FILTER)");
  return err;
 }
 return memcmp(&applied_filter, filter, sizeof(struct icmp6_filter));
}

variable_types: err int

variable_types: struct icmp6_filter { unsigned int icmp6_filt[8]; }

return_type: int


repo: tchetch/XComp

decompiled_code:
_BOOL8 __fastcall sys_check_file(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

original_code:
int sys_check_file(const char * path)
{
    int ret = 0;
    struct stat buffer;
    if(stat(path, &buffer) == 0) {
        if(((((buffer.st_mode)) & 0170000) == (0100000))) {
            ret = 1;
        }
    }
    return ret;
}

canonical_original_code:
int sys_check_file(char *path)
{
    int ret = 0;
    struct stat buffer;
    if(stat(path, &buffer) == 0) {
        if(((((buffer.st_mode)) & 0170000) == (0100000))) {
            ret = 1;
        }
    }
    return ret;
}

variable_types:
path
char *

variable_types: ret int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall sys_mutex_init(pthread_mutex_t **a1)
{
pthread_mutex_t *v1; // rax

if ( !a1 )
return 0LL;
v1 = (pthread_mutex_t *)malloc(0x28uLL);
*a1 = v1;
if ( !v1 )
return 0LL;
pthread_mutex_init(v1, 0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(pthread_mutex_t **a1)
{
pthread_mutex_t *v1; // rax

if ( !a1 )
return 0LL;
v1 = (pthread_mutex_t *)malloc(0x28uLL);
*a1 = v1;
if ( !v1 )
return 0LL;
pthread_mutex_init(v1, 0LL);
return 1LL;
}

original_code:
int sys_mutex_init(pthread_mutex_t ** mtx)
{
    int ret = 0;
    if(mtx != ((void *)0)) {
        *mtx = malloc(sizeof(**mtx));
        if(*mtx != ((void *)0)) {
            pthread_mutex_init(*mtx, ((void *)0));
            ret = 1;
        }
    }
    return ret;
}

canonical_original_code:
int sys_mutex_init(union pthread_mutex_t **mtx)
{
    int ret = 0;
    if(mtx != ((void *)0)) {
        *mtx = malloc(sizeof(**mtx));
        if(*mtx != ((void *)0)) {
            pthread_mutex_init(*mtx, ((void *)0));
            ret = 1;
        }
    }
    return ret;
}

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } **

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

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


decompiled_code:
// attributes: thunk
int sys_mutex_lock(pthread_mutex_t *mutex)
{
return pthread_mutex_lock(mutex);
}

canonical_decompiled_code:
int func3(pthread_mutex_t *mutex)
{
return pthread_mutex_lock(mutex);
}

original_code:
int sys_mutex_lock(pthread_mutex_t * mtx)
{
    return pthread_mutex_lock(mtx);
}

canonical_original_code:
int sys_mutex_lock(union pthread_mutex_t *mtx)
{
    return pthread_mutex_lock(mtx);
}

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *


decompiled_code:
// attributes: thunk
int sys_mutex_unlock(pthread_mutex_t *mutex)
{
return pthread_mutex_unlock(mutex);
}

canonical_decompiled_code:
int func4(pthread_mutex_t *mutex)
{
return pthread_mutex_unlock(mutex);
}

original_code:
int sys_mutex_unlock(pthread_mutex_t * mtx)
{
    return pthread_mutex_unlock(mtx);
}

canonical_original_code:
int sys_mutex_unlock(union pthread_mutex_t *mtx)
{
    return pthread_mutex_unlock(mtx);
}

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


decompiled_code:
void __fastcall sys_mutex_destroy(void *ptr)
{
if ( ptr )
{
pthread_mutex_destroy((pthread_mutex_t *)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
if ( ptr )
{
pthread_mutex_destroy((pthread_mutex_t *)ptr);
free(ptr);
}
}

original_code:
void sys_mutex_destroy(pthread_mutex_t * mtx)
{
    if(mtx != ((void *)0)) {
        pthread_mutex_destroy(mtx);
        free(mtx);
    }
}

canonical_original_code:
void sys_mutex_destroy(union pthread_mutex_t *mtx)
{
    if(mtx != ((void *)0)) {
        pthread_mutex_destroy(mtx);
        free(mtx);
    }
}


decompiled_code:
int __fastcall sys_create_thread(pthread_t *a1, void *(*a2)(void *), void *a3)
{
return pthread_create(a1, 0LL, a2, a3);
}

canonical_decompiled_code:
int __fastcall func6(pthread_t *a1, void *(*a2)(void *), void *a3)
{
return pthread_create(a1, 0LL, a2, a3);
}

original_code:
int sys_create_thread(pthread_t * id, void *(*func)(void *), void * args)
{
    return pthread_create(id, ((void *)0), func, args);
}

canonical_original_code:
int sys_create_thread(unsigned long *id, void *(*func)(void *), void *args)
{
    return pthread_create(id, ((void *)0), func, args);
}

variable_types:
id
unsigned long *

variable_types:
func
void *(*)(void *)

variable_types:
args
void *


decompiled_code:
int __fastcall sys_wait_thread(pthread_t *a1)
{
return pthread_join(*a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func7(pthread_t *a1)
{
return pthread_join(*a1, 0LL);
}

original_code:
int sys_wait_thread(pthread_t * id)
{
    return pthread_join(*id, ((void *)0));
}

canonical_original_code:
int sys_wait_thread(unsigned long *id)
{
    return pthread_join(*id, ((void *)0));
}


decompiled_code:
__int64 __fastcall sstack_init(_QWORD *a1, int a2)
{
__int64 result; // rax
_QWORD *v3; // rax
_QWORD *v4; // r12
void *v5; // rax

if ( a2 > 0 )
{
if ( a1 )
{
v3 = malloc(0x10uLL);
*a1 = v3;
v4 = v3;
if ( v3 )
{
v5 = malloc(8LL * a2);
v4[1] = v5;
if ( v5 )
{
*(_DWORD *)v4 = a2;
result = 1LL;
*((_DWORD *)v4 + 1) = 0;
return result;
}
free(v4);
}
}
return 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, int a2)
{
__int64 result; // rax
_QWORD *v3; // rax
_QWORD *v4; // r12
void *v5; // rax

if ( a2 > 0 )
{
if ( a1 )
{
v3 = malloc(0x10uLL);
*a1 = v3;
v4 = v3;
if ( v3 )
{
v5 = malloc(8LL * a2);
v4[1] = v5;
if ( v5 )
{
*(_DWORD *)v4 = a2;
result = 1LL;
*((_DWORD *)v4 + 1) = 0;
return result;
}
free(v4);
}
}
return 0LL;
}
return 0LL;
}

original_code:
int sstack_init(struct SStack ** s, int size)
{
    int ret = 0;
    if(s != ((void *)0)) {
        if(size > 0) {
            *s = malloc(sizeof(**s));
            if(*s != ((void *)0)) {
                (*s)->data = malloc(size * sizeof(*((*s)->data)));
                if((*s)->data == ((void *)0)) {
                    free(*s);
                } else {
                    (*s)->size = size;
                    (*s)->current = 0;
                    ret = 1;
                }
            }
        }
    }
    return ret;
}

canonical_original_code:
int sstack_init(struct SStack **s, int size)
{
    int ret = 0;
    if(s != ((void *)0)) {
        if(size > 0) {
            *s = malloc(sizeof(**s));
            if(*s != ((void *)0)) {
                (*s)->data = malloc(size * sizeof(*((*s)->data)));
                if((*s)->data == ((void *)0)) {
                    free(*s);
                } else {
                    (*s)->size = size;
                    (*s)->current = 0;
                    ret = 1;
                }
            }
        }
    }
    return ret;
}

variable_types: struct SStack { int size; int current; char **data; } **

variable_types: size int


decompiled_code:
__int64 __fastcall sstack_push(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax

if ( !a1 || !a2 )
return 0LL;
v2 = *(_DWORD *)(a1 + 4);
result = 0LL;
if ( v2 < *(_DWORD *)a1 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v2) = a2;
result = 1LL;
*(_DWORD *)(a1 + 4) = v2 + 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax

if ( !a1 || !a2 )
return 0LL;
v2 = *(_DWORD *)(a1 + 4);
result = 0LL;
if ( v2 < *(_DWORD *)a1 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v2) = a2;
result = 1LL;
*(_DWORD *)(a1 + 4) = v2 + 1;
}
return result;
}

original_code:
int sstack_push(struct SStack * s, void * p)
{
    int ret = 0;
    if(s != ((void *)0) && p != ((void *)0)) {
        if(s->current < s->size) {
            s->data[s->current] = (char *)p;
            s->current++;
            ret = 1;
        }
    }
    return ret;
}

canonical_original_code:
int sstack_push(struct SStack *s, void *p)
{
    int ret = 0;
    if(s != ((void *)0) && p != ((void *)0)) {
        if(s->current < s->size) {
            s->data[s->current] = (char *)p;
            s->current++;
            ret = 1;
        }
    }
    return ret;
}

variable_types: struct SStack { int size; int current; char **data; } *

variable_types:
p
void *


decompiled_code:
__int64 __fastcall sstack_pop(int *a1, _QWORD *a2)
{
int v2; // edx
__int64 result; // rax
_QWORD *v4; // rax

if ( !a1 || !a2 )
return 0LL;
v2 = a1[1];
result = 0LL;
if ( v2 > 0 )
{
v4 = (_QWORD *)*((_QWORD *)a1 + 1);
a1[1] = v2 - 1;
*a2 = *v4;
memmove(*((void **)a1 + 1), (const void *)(*((_QWORD *)a1 + 1) + 8LL), 8LL * (*a1 - 1));
*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1 - 8) = 0LL;
result = 1LL;
}
return result;
}

original_code:
int sstack_pop(struct SStack * s, void ** p)
{
    int ret = 0;
    if(s != ((void *)0) && p != ((void *)0)) {
        if(s->current > 0) {
            s->current--;
            *p = (void *)s->data[0];
            memmove(&(s->data[0]), &(s->data[1]), (s->size - 1) * sizeof(char *));
            s->data[s->size - 1] = ((void *)0);
            ret = 1;
        }
    }
    return ret;
}

canonical_original_code:
int sstack_pop(struct SStack *s, void **p)
{
    int ret = 0;
    if(s != ((void *)0) && p != ((void *)0)) {
        if(s->current > 0) {
            s->current--;
            *p = (void *)s->data[0];
            memmove(&(s->data[0]), &(s->data[1]), (s->size - 1) * sizeof(char *));
            s->data[s->size - 1] = ((void *)0);
            ret = 1;
        }
    }
    return ret;
}

variable_types:
p
void **

user_defined_types: struct SStack { int size; int current; char **data; }


decompiled_code:
void __fastcall sstack_free(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void sstack_free(struct SStack * s)
{
    if(s != ((void *)0)) {
        if(s->data != ((void *)0)) free(s->data);
        free(s);
    }
}

canonical_original_code:
void sstack_free(struct SStack *s)
{
    if(s != ((void *)0)) {
        if(s->data != ((void *)0)) free(s->data);
        free(s);
    }
}


decompiled_code:
__int64 __fastcall bytetok_size(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

if ( !*a1 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

if ( !*a1 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int bytetok_size(Tokk b)
{
    int i = 0;
    for(i = 0; b[i] != ((void *)0); i++);
    return i;
}

canonical_original_code:
int bytetok_size(char **b)
{
    int i = 0;
    for(i = 0; b[i] != ((void *)0); i++);
    return i;
}

variable_types:
b
char **

variable_types: i int


decompiled_code:
_QWORD *group_init()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_DWORD *)result = 0;
result[1] = 0LL;
}
return result;
}

canonical_decompiled_code:
_QWORD *func6()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_DWORD *)result = 0;
result[1] = 0LL;
}
return result;
}

original_code:
Group group_init(void)
{
    Group g = ((void *)0);
    g = malloc(sizeof(*g));
    if (g != ((void *)0)) {
        g->size = 0;
        g->data = ((void *)0);
    }
    return g;
}

canonical_original_code:
struct s_Group *group_init()
{
    struct s_Group *g = ((void *)0);
    g = malloc(sizeof(*g));
    if (g != ((void *)0)) {
        g->size = 0;
        g->data = ((void *)0);
    }
    return g;
}

variable_types: struct s_Group { int size; char **data; } *


decompiled_code:
__int64 __fastcall group_append(int *a1, __int64 a2)
{
__int64 v2; // rax
_QWORD *v3; // rax

if ( a1 )
{
if ( a2 )
{
v2 = *a1;
if ( (int)v2 > 0 )
{
LABEL_4:
v3 = (_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v2 - 8);
if ( !*v3 )
{
LABEL_7:
*v3 = a2;
return 1LL;
}
if ( (unsigned int)grow_group(a1, 1) )
{
v3 = (_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1 - 8);
goto LABEL_7;
}
return 0LL;
}
if ( (unsigned int)grow_group(a1, 1) )
{
v2 = *a1;
goto LABEL_4;
}
}
return 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1, __int64 a2)
{
__int64 v2; // rax
_QWORD *v3; // rax

if ( a1 )
{
if ( a2 )
{
v2 = *a1;
if ( (int)v2 > 0 )
{
LABEL_4:
v3 = (_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v2 - 8);
if ( !*v3 )
{
LABEL_7:
*v3 = a2;
return 1LL;
}
if ( (unsigned int)func7(a1, 1) )
{
v3 = (_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *a1 - 8);
goto LABEL_7;
}
return 0LL;
}
if ( (unsigned int)func7(a1, 1) )
{
v2 = *a1;
goto LABEL_4;
}
}
return 0LL;
}
return 0LL;
}

original_code:
int group_append(Group g, void * p)
{
    int ret = 0;
    if(g != ((void *)0) && p != ((void *)0)) {
        if(g->size <= 0) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        if(g->data[g->size - 1] != ((void *)0)) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        g->data[g->size - 1] = p;
        ret = 1;
    }
quick_return:
    return ret;
}

canonical_original_code:
int group_append(struct s_Group *g, void *p)
{
    int ret = 0;
    if(g != ((void *)0) && p != ((void *)0)) {
        if(g->size <= 0) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        if(g->data[g->size - 1] != ((void *)0)) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        g->data[g->size - 1] = p;
        ret = 1;
    }
quick_return:
    return ret;
}

user_defined_types: struct s_Group { int size; char **data; }


decompiled_code:
__int64 __fastcall group_prepend(__int64 a1, __int64 a2)
{
int v3; // eax
_QWORD *v4; // rsi

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v3 = *(_DWORD *)a1;
if ( *(int *)a1 <= 0 )
{
if ( !(unsigned int)grow_group((int *)a1, 1) )
return 0LL;
v3 = *(_DWORD *)a1;
}
v4 = *(_QWORD **)(a1 + 8);
if ( v4[v3 - 1] )
{
if ( (unsigned int)grow_group((int *)a1, 1) )
{
v3 = *(_DWORD *)a1;
v4 = *(_QWORD **)(a1 + 8);
goto LABEL_7;
}
return 0LL;
}
LABEL_7:
if ( v3 > 1 )
{
memmove(v4 + 1, v4, 8LL * (v3 - 1));
**(_QWORD **)(a1 + 8) = a2;
}
else
{
*v4 = a2;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
int v3; // eax
_QWORD *v4; // rsi

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v3 = *(_DWORD *)a1;
if ( *(int *)a1 <= 0 )
{
if ( !(unsigned int)func7((int *)a1, 1) )
return 0LL;
v3 = *(_DWORD *)a1;
}
v4 = *(_QWORD **)(a1 + 8);
if ( v4[v3 - 1] )
{
if ( (unsigned int)func7((int *)a1, 1) )
{
v3 = *(_DWORD *)a1;
v4 = *(_QWORD **)(a1 + 8);
goto LABEL_7;
}
return 0LL;
}
LABEL_7:
if ( v3 > 1 )
{
memmove(v4 + 1, v4, 8LL * (v3 - 1));
**(_QWORD **)(a1 + 8) = a2;
}
else
{
*v4 = a2;
}
return 1LL;
}

original_code:
int group_prepend(Group g, void * p)
{
    int ret = 0;
    if(g != ((void *)0) && p != ((void *)0)) {
        if(g->size <= 0) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        if(g->data[g->size -1] != ((void *)0)) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        if(g->size > 1) {
            memmove(&(g->data[1]), &(g->data[0]), sizeof(*(g->data)) * (g->size -1));
            g->data[0] = p;
        } else {
            g->data[0] = p;
        }
        ret = 1;
    }
quick_return:
    return ret;
}

canonical_original_code:
int group_prepend(struct s_Group *g, void *p)
{
    int ret = 0;
    if(g != ((void *)0) && p != ((void *)0)) {
        if(g->size <= 0) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        if(g->data[g->size -1] != ((void *)0)) {
            if( ! _grow_group(g, 1)) {
                goto quick_return;
            }
        }
        if(g->size > 1) {
            memmove(&(g->data[1]), &(g->data[0]), sizeof(*(g->data)) * (g->size -1));
            g->data[0] = p;
        } else {
            g->data[0] = p;
        }
        ret = 1;
    }
quick_return:
    return ret;
}


original_code:
int group_delete(Group g, int index)
{
    int ret = 0;
    void * bck = ((void *)0);
    if(g != ((void *)0) && index < g->size && g->size > 0) {
        bck = g->data[index];
        do { memmove(&((g)->data[(index)]), &((g)->data[(index) + (1)]), ((g)->size - ((index) + (1))) * sizeof(*((g)->data))); } while(0);
        g->data[g->size - 1] = ((void *)0);
        if( ! _shrink_group(g, 1)) {
            do { memmove(&((g)->data[(index) + (1)]), &((g)->data[(index)]), ((g)->size - ((index) + (1))) * sizeof(*((g)->data))); } while(0);
            g->data[index]=bck;
        } else {
            ret = 1;
        }
    }
    return ret;
}

canonical_original_code:
int group_delete(struct s_Group *g, int index)
{
    int ret = 0;
    void *bck = ((void *)0);
    if(g != ((void *)0) && index < g->size && g->size > 0) {
        bck = g->data[index];
        do { memmove(&((g)->data[(index)]), &((g)->data[(index) + (1)]), ((g)->size - ((index) + (1))) * sizeof(*((g)->data))); } while(0);
        g->data[g->size - 1] = ((void *)0);
        if( ! _shrink_group(g, 1)) {
            do { memmove(&((g)->data[(index) + (1)]), &((g)->data[(index)]), ((g)->size - ((index) + (1))) * sizeof(*((g)->data))); } while(0);
            g->data[index]=bck;
        } else {
            ret = 1;
        }
    }
    return ret;
}

variable_types: index int

variable_types:
bck
void *


decompiled_code:
__int64 __fastcall group_add(__int64 a1, __int64 a2, int a3)
{
if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
if ( *(int *)a1 <= 0 || *(_DWORD *)a1 - 1 <= a3 )
return group_append((int *)a1, a2);
if ( a3 <= 0 )
return group_prepend(a1, a2);
if ( !(unsigned int)grow_group((int *)a1, 1) )
return 0LL;
memmove(
(void *)(*(_QWORD *)(a1 + 8) + 8LL * a3 + 8),
(const void *)(*(_QWORD *)(a1 + 8) + 8LL * a3),
8LL * (*(_DWORD *)a1 + ~a3));
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a3) = a2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, int a3)
{
if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
if ( *(int *)a1 <= 0 || *(_DWORD *)a1 - 1 <= a3 )
return func9((int *)a1, a2);
if ( a3 <= 0 )
return func10(a1, a2);
if ( !(unsigned int)func7((int *)a1, 1) )
return 0LL;
memmove(
(void *)(*(_QWORD *)(a1 + 8) + 8LL * a3 + 8),
(const void *)(*(_QWORD *)(a1 + 8) + 8LL * a3),
8LL * (*(_DWORD *)a1 + ~a3));
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a3) = a2;
return 1LL;
}

original_code:
int group_add(Group g, void * p, int index)
{
    int ret = 0;
    if(g != ((void *)0) && p != ((void *)0)) {
        if(g->size <= 0) {
            ret = group_append(g, p);
        } else if(index >= g->size - 1) {
            ret = group_append(g, p);
        } else if(index <= 0) {
            ret = group_prepend(g, p);
        } else {
            if( _grow_group(g, 1)) {
                do { memmove(&((g)->data[(index) + (1)]), &((g)->data[(index)]), ((g)->size - ((index) + (1))) * sizeof(*((g)->data))); } while(0);
                g->data[index] = p;
                ret = 1;
            }
        }
    }
    return ret;
}

canonical_original_code:
int group_add(struct s_Group *g, void *p, int index)
{
    int ret = 0;
    if(g != ((void *)0) && p != ((void *)0)) {
        if(g->size <= 0) {
            ret = group_append(g, p);
        } else if(index >= g->size - 1) {
            ret = group_append(g, p);
        } else if(index <= 0) {
            ret = group_prepend(g, p);
        } else {
            if( _grow_group(g, 1)) {
                do { memmove(&((g)->data[(index) + (1)]), &((g)->data[(index)]), ((g)->size - ((index) + (1))) * sizeof(*((g)->data))); } while(0);
                g->data[index] = p;
                ret = 1;
            }
        }
    }
    return ret;
}

variable_types: ret int


rxc

repo: tcoram/uforth

decompiled_code:
int rxc()
{
return getchar();
}

canonical_decompiled_code:
int func0()
{
return getchar();
}

original_code:
uint8_t rxc(void) {
  return getchar();
}

canonical_original_code:
unsigned char rxc() {
  return getchar();
}

return_type: unsigned char


decompiled_code:
_BYTE *rl_gets()
{
_BYTE *result; // rax

if ( line_read )
{
free(line_read);
line_read = 0LL;
}
result = (_BYTE *)readline(&unk_AB0);
line_read = result;
if ( result )
{
if ( *result )
{
add_history(result);
result = line_read;
}
}
return result;
}

canonical_decompiled_code:
_BYTE *func1()
{
_BYTE *result; // rax

if ( line_read )
{
free(line_read);
line_read = 0LL;
}
result = (_BYTE *)readline(&unk_AB0);
line_read = result;
if ( result )
{
if ( *result )
{
add_history(result);
result = line_read;
}
}
return result;
}

original_code:
char *
rl_gets ()
{
  if (line_read)
    {
      free (line_read);
      line_read = (char *)((void *)0);
    }
  line_read = readline ("");
  if (line_read && *line_read)
    add_history (line_read);
  return (line_read);
}

canonical_original_code:
char *rl_gets()
{
  if (line_read)
    {
      free (line_read);
      line_read = (char *)((void *)0);
    }
  line_read = readline ("");
  if (line_read && *line_read)
    add_history (line_read);
  return (line_read);
}

return_type: char *


rxgetline

decompiled_code:
char *__fastcall rxgetline(char *a1)
{
return fgets(a1, 128, stdin);
}

canonical_decompiled_code:
char *__fastcall func2(char *a1)
{
return fgets(a1, 128, stdin);
}

original_code:
void rxgetline(char* str) {
  fgets(str,128,stdin);
}

canonical_original_code:
void rxgetline(char *str) {
  fgets(str,128,stdin);
}

variable_types:
str
char *


txc

decompiled_code:
int __fastcall txc(unsigned __int8 a1)
{
fputc(a1, OUTFP);
return fflush(OUTFP);
}

canonical_decompiled_code:
int __fastcall func3(unsigned __int8 a1)
{
fputc(a1, OUTFP);
return fflush(OUTFP);
}

original_code:
void txc(uint8_t c) {
  fputc(c, OUTFP);
  fflush(OUTFP);
}

canonical_original_code:
void txc(unsigned char c) {
  fputc(c, OUTFP);
  fflush(OUTFP);
}

variable_types:
c
unsigned char


txs

decompiled_code:
int __fastcall txs(const void *a1, int a2)
{
fwrite(a1, a2, 1uLL, OUTFP);
return fflush(OUTFP);
}

canonical_decompiled_code:
int __fastcall func4(const void *a1, int a2)
{
fwrite(a1, a2, 1uLL, OUTFP);
return fflush(OUTFP);
}

original_code:
void txs(char* s, int cnt) {
  fwrite(s,cnt,1,OUTFP);
  fflush(OUTFP);
}

canonical_original_code:
void txs(char *s, int cnt) {
  fwrite(s,cnt,1,OUTFP);
  fflush(OUTFP);
}

variable_types:
s
char *

variable_types: cnt int


decompiled_code:
bool __fastcall config_open_w(const char *a1)
{
cfp = fopen(a1, "w+");
return cfp != 0LL;
}

canonical_decompiled_code:
bool __fastcall func5(const char *a1)
{
cfp = fopen(a1, "w+");
return cfp != 0LL;
}

original_code:
bool config_open_w(char* f) {
  cfp = fopen(f, "w+");
  return (cfp != ((void *)0));
}

canonical_original_code:
char config_open_w(char *f) {
  cfp = fopen(f, "w+");
  return (cfp != ((void *)0));
}

variable_types:
f
char *

return_type: char


decompiled_code:
bool __fastcall config_open_r(const char *a1)
{
cfp = fopen(a1, "r");
return cfp != 0LL;
}

canonical_decompiled_code:
bool __fastcall func6(const char *a1)
{
cfp = fopen(a1, "r");
return cfp != 0LL;
}

original_code:
bool config_open_r(char* f) {
  cfp = fopen(f, "r");
  return (cfp != ((void *)0));
}

canonical_original_code:
char config_open_r(char *f) {
  cfp = fopen(f, "r");
  return (cfp != ((void *)0));
}


decompiled_code:
__int64 __fastcall config_write(const void *a1, unsigned __int16 a2)
{
fwrite(a1, a2, 1uLL, cfp);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, unsigned __int16 a2)
{
fwrite(a1, a2, 1uLL, cfp);
return 1LL;
}

original_code:
bool config_write(char *src, uint16_t size) {
  fwrite((char*)src, size, 1, cfp);
  return 1;
}

canonical_original_code:
char config_write(char *src, unsigned short size) {
  fwrite((char *)src, size, 1, cfp);
  return 1;
}

variable_types:
src
char *

variable_types:
size
unsigned short


decompiled_code:
__int64 __fastcall config_read(void *ptr)
{
unsigned __int16 v2; // [rsp+Eh] [rbp-Ah] BYREF

_isoc99_fscanf(cfp, "%d\n", &v2);
fread(ptr, v2, 1uLL, cfp);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *ptr)
{
unsigned __int16 v2; // [rsp+Eh] [rbp-Ah] BYREF

_isoc99_fscanf(cfp, "%d\n", &v2);
fread(ptr, v2, 1uLL, cfp);
return 1LL;
}

original_code:
bool config_read(void *dest) {
  uint16_t size;
  fscanf(cfp,"%d\n",(int*)&size);
  fread((char*)dest, size, 1, cfp);
  return 1;
}

canonical_original_code:
char config_read(void *dest) {
  unsigned short size;
  fscanf(cfp,"%d\n",(int *)&size);
  fread((char *)dest, size, 1, cfp);
  return 1;
}

variable_types:
dest
void *


decompiled_code:
__int64 config_close()
{
fclose(cfp);
return 1LL;
}

canonical_decompiled_code:
__int64 func9()
{
fclose(cfp);
return 1LL;
}

original_code:
bool config_close(void) {
  fclose(cfp);
  return 1;
}

canonical_original_code:
char config_close() {
  fclose(cfp);
  return 1;
}


decompiled_code:
void c_ext_init()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void c_ext_init(void) {
}

canonical_original_code:
void c_ext_init() {
}


decompiled_code:
void c_ext_create_cmds()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void c_ext_create_cmds(void) {
}

canonical_original_code:
void c_ext_create_cmds() {
}


original_code:
uforth_stat c_ext_handle_cmds(CELL n) {
  CELL r1, r2,r3;
  char *str1;
  switch (n) {
  case 5:
    r1 = dpop();
    str1 = uforth_count_str(r1,&r1);
    str1[r1] = '\0';
    dpush(uforth_interpret(str1));
    break;
  case 6:
    r1 = dpop();
    r2 = dpop();
    r3 = dpop();
    str1 = uforth_count_str(r1,&r1);
    if (r1 < r2) r2 = r1;
    uforth_ram[(uforth_iram->total_ram - 160)] = r2;
    memcpy((char*)&uforth_ram[(uforth_iram->total_ram - 160)+1], str1 + r3, r2);
    dpush((uforth_iram->total_ram - 160));
    break;
  case 3:
    {
      char num[12];
      i32toa(dpop32(),num,uforth_uram->base);
      uforth_ram[(uforth_iram->total_ram - 160)]=strlen(num);
      memcpy((char*)&uforth_ram[(uforth_iram->total_ram - 160)+1], num, 160);
      dpush((uforth_iram->total_ram - 160));
    }
    break;
  default:
    return E_ABORT;
  }
  return OK;
}

canonical_original_code:
enum uforth_stat c_ext_handle_cmds(unsigned short n) {
  unsigned short r1; unsigned short r2; unsigned short r3;
  char *str1;
  switch (n) {
  case 5:
    r1 = dpop();
    str1 = uforth_count_str(r1,&r1);
    str1[r1] = '\0';
    dpush(uforth_interpret(str1));
    break;
  case 6:
    r1 = dpop();
    r2 = dpop();
    r3 = dpop();
    str1 = uforth_count_str(r1,&r1);
    if (r1 < r2) r2 = r1;
    uforth_ram[(uforth_iram->total_ram - 160)] = r2;
    memcpy((char *)&uforth_ram[(uforth_iram->total_ram - 160)+1], str1 + r3, r2);
    dpush((uforth_iram->total_ram - 160));
    break;
  case 3:
    {
      char num[12];
      i32toa(dpop32(),num,uforth_uram->base);
      uforth_ram[(uforth_iram->total_ram - 160)]=strlen(num);
      memcpy((char *)&uforth_ram[(uforth_iram->total_ram - 160)+1], num, 160);
      dpush((uforth_iram->total_ram - 160));
    }
    break;
  default:
    return E_ABORT;
  }
  return OK;
}

variable_types:
n
unsigned short

variable_types:
num
char [12]

return_type: enum uforth_stat { OK=0, E_NOT_A_WORD=1, E_STACK_UNDERFLOW=2, E_RSTACK_OVERFLOW=3, E_DSTACK_OVERFLOW=4, E_ABORT=5, E_EXIT=6 }


main

canonical_name: main

repo: tcreech/nqueens-pthreads

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
char *v4; // rax
unsigned __int64 v5; // r12
pthread_t *v6; // rax
pthread_t *v7; // r13
pthread_t *v8; // rbx
pthread_t *v9; // r15
char *i; // rbp
pthread_t v11; // rdi
__int64 v12; // r12
__int64 v13; // rax
__int64 v14; // rdx
__int64 v15; // rax

n = set_problem_size(argc, argv, envp);
jobs = get_sub_problem_num((unsigned int)n, &prob);
v3 = get_time();
v4 = getenv("OMP_NUM_THREADS");
v5 = (unsigned int)atoi(v4);
printf("Starting %d worker threads.\n", v5);
v6 = (pthread_t *)malloc(8 * v5);
v7 = v6;
if ( (_DWORD)v5 )
{
v8 = v6;
v9 = v6;
for ( i = 0LL; i != (char *)v5; ++i )
pthread_create(v9++, 0LL, worker_body, i);
do
{
v11 = *v8++;
pthread_join(v11, 0LL);
}
while ( v8 != &v7[(unsigned int)(v5 - 1) + 1] );
}
free(v7);
puts("All work finished.");
if ( jobs <= 0 )
{
v12 = 0LL;
}
else
{
v12 = 0LL;
v13 = 1LL;
do
{
v14 = rets[v13++];
v12 += v14;
}
while ( jobs + 1 != v13 );
}
v15 = get_time();
print_result((unsigned int)n, v15 - v3, v12);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
char *v4; // rax
unsigned __int64 v5; // r12
pthread_t *v6; // rax
pthread_t *v7; // r13
pthread_t *v8; // rbx
pthread_t *v9; // r15
char *i; // rbp
pthread_t v11; // rdi
__int64 v12; // r12
__int64 v13; // rax
__int64 v14; // rdx
__int64 v15; // rax

n = func11(argc, argv, envp);
jobs = func13((unsigned int)n, &prob);
v3 = func9();
v4 = getenv("OMP_NUM_THREADS");
v5 = (unsigned int)atoi(v4);
printf("Starting %d worker threads.\n", v5);
v6 = (pthread_t *)malloc(8 * v5);
v7 = v6;
if ( (_DWORD)v5 )
{
v8 = v6;
v9 = v6;
for ( i = 0LL; i != (char *)v5; ++i )
pthread_create(v9++, 0LL, worker_body, i);
do
{
v11 = *v8++;
pthread_join(v11, 0LL);
}
while ( v8 != &v7[(unsigned int)(v5 - 1) + 1] );
}
free(v7);
puts("All work finished.");
if ( jobs <= 0 )
{
v12 = 0LL;
}
else
{
v12 = 0LL;
v13 = 1LL;
do
{
v14 = rets[v13++];
v12 += v14;
}
while ( jobs + 1 != v13 );
}
v15 = func9();
func10((unsigned int)n, v15 - v3, v12);
return 0;
}

original_code:
int main(int argc, char *argv[]){
   int i;
   n = set_problem_size(argc, argv);
   jobs = get_sub_problem_num(n, prob);
   long long usec = get_time();
   long long answers = 0;
   char *nthreads_s = getenv("OMP_NUM_THREADS");
   unsigned int nthreads = 1;
   if(nthreads)
      nthreads = atoi(nthreads_s);
   printf("Starting %d worker threads.\n", nthreads);
   pthread_t *workers = malloc(sizeof(pthread_t) * nthreads);
   for(int thread=0; thread < nthreads; thread++){
      pthread_create(workers+thread, ((void *)0), &worker_body, (void*)thread);
   }
   for(int thread=0; thread < nthreads; thread++){
      pthread_join(workers[thread], ((void *)0));
   }
   free(workers);
   printf("All work finished.\n");
   for(i=1; i<=jobs; i++) answers += rets[i];
   print_result(n, get_time()-usec, answers);
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
   int i;
   n = set_problem_size(argc, argv);
   jobs = get_sub_problem_num(n, prob);
   long long usec = get_time();
   long long answers = 0;
   char *nthreads_s = getenv("OMP_NUM_THREADS");
   unsigned int nthreads = 1;
   if(nthreads)
      nthreads = atoi(nthreads_s);
   printf("Starting %d worker threads.\n", nthreads);
   unsigned long *workers = malloc(sizeof(pthread_t) * nthreads);
   for(int thread = 0; thread < nthreads; thread++){
      pthread_create(workers+thread, ((void *)0), &worker_body, (void *)thread);
   }
   for(int thread = 0; thread < nthreads; thread++){
      pthread_join(workers[thread], ((void *)0));
   }
   free(workers);
   printf("All work finished.\n");
   for(i=1; i<=jobs; i++) answers += rets[i];
   print_result(n, get_time()-usec, answers);
   return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
usec
long long

variable_types:
answers
long long

variable_types:
nthreads
unsigned int

variable_types:
workers
unsigned long *

variable_types: thread int


decompiled_code:
__int64 atomic_grab_next()
{
__int64 result; // rax

result = (unsigned int)_InterlockedIncrement(&grabbed);
if ( jobs < (unsigned int)result )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax

result = (unsigned int)_InterlockedIncrement(&grabbed);
if ( jobs < (unsigned int)result )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int atomic_grab_next(void){
   int retval = -1;
   unsigned local_grabbed = __sync_add_and_fetch(&grabbed, 1);
   if(local_grabbed <= jobs)
      retval = local_grabbed;
   return retval;
}

canonical_original_code:
int atomic_grab_next(){
   int retval = -1;
   unsigned int local_grabbed = __sync_add_and_fetch(&grabbed, 1);
   if(local_grabbed <= jobs)
      retval = local_grabbed;
   return retval;
}

variable_types: retval int


qn

original_code:
long long qn(int n, int h, int r, array *a){
   long long answers = 0;
   for(;;){
      if(r){
         int lsb = (-r) & r;
         a[h+1].cdt = ( r & ~lsb);
         a[h+1].col = (a[h].col & ~lsb);
         a[h+1].pos = (a[h].pos | lsb) << 1;
         a[h+1].neg = (a[h].neg | lsb) >> 1;
         r = a[h+1].col & ~(a[h+1].pos | a[h+1].neg);
         h++;
      }
      else{
         r = a[h].cdt;
         h--;
         if(h==0) break;
         if(h==n) answers++;
      }
   }
   return answers;
}

canonical_original_code:
long long qn(int n, int h, int r, struct array_t *a){
   long long answers = 0;
   for(;;){
      if(r){
         int lsb = (-r) & r;
         a[h+1].cdt = ( r & ~lsb);
         a[h+1].col = (a[h].col & ~lsb);
         a[h+1].pos = (a[h].pos | lsb) << 1;
         a[h+1].neg = (a[h].neg | lsb) >> 1;
         r = a[h+1].col & ~(a[h+1].pos | a[h+1].neg);
         h++;
      }
      else{
         r = a[h].cdt;
         h--;
         if(h==0) break;
         if(h==n) answers++;
      }
   }
   return answers;
}

variable_types: n int

variable_types: h int

variable_types: r int

variable_types: struct array_t { unsigned int cdt; unsigned int col; unsigned int pos; unsigned int neg; } *

variable_types: lsb int

return_type: long long


decompiled_code:
__suseconds_t get_time()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func9()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
long long get_time(){
   struct timeval tp;
   gettimeofday(&tp, ((void *)0));
   return tp.tv_sec * 1000000ull + tp.tv_usec;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
int __fastcall print_result(unsigned int a1, int a2, __int64 a3)
{
int v4; // ebx
__int64 v5; // rbx
int v6; // ebx

v4 = 45;
do
{
putchar(61);
--v4;
}
while ( v4 );
putchar(10);
printf("%s %s\n", "qn24b pthreads", "version 1.0.0.1 2013-03-13");
printf("problem size n : %d\n", a1);
printf("total solutions : %lld\n", a3);
v5 = answer_0[a1];
printf("correct solutions : %lld\n", v5);
printf("million solutions/sec : %.3f\n", (double)(int)a3 / (double)a2);
printf("elapsed time (sec) : %.3f\n", (double)a2 / 1000000.0);
if ( v5 != a3 )
puts(" ### Wrong answer");
v6 = 45;
do
{
putchar(61);
--v6;
}
while ( v6 );
putchar(10);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1, int a2, __int64 a3)
{
int v4; // ebx
__int64 v5; // rbx
int v6; // ebx

v4 = 45;
do
{
putchar(61);
--v4;
}
while ( v4 );
putchar(10);
printf("%s %s\n", "qn24b pthreads", "version 1.0.0.1 2013-03-13");
printf("problem size n : %d\n", a1);
printf("total solutions : %lld\n", a3);
v5 = answer_0[a1];
printf("correct solutions : %lld\n", v5);
printf("million solutions/sec : %.3f\n", (double)(int)a3 / (double)a2);
printf("elapsed time (sec) : %.3f\n", (double)a2 / 1000000.0);
if ( v5 != a3 )
puts(" ### Wrong answer");
v6 = 45;
do
{
putchar(61);
--v6;
}
while ( v6 );
putchar(10);
return fflush(stdout);
}

original_code:
void print_result(int n, long long usec,
      long long solution){
   int i;
   static long long answer[30] = {
      0, 1, 0, 0, 2, 10, 4, 40, 92, 352, 724,
      2680, 14200, 73712, 365596, 2279184,
      14772512, 95815104, 666090624ull,
      4968057848ull, 39029188884ull,
      314666222712ull, 2691008701644ull,
      24233937684440ull,
      0,0,0,0,0,0
   };
   for(i=0;i<45;i++) printf("="); printf("\n");
   printf("%s %s\n", "qn24b pthreads", "version 1.0.0.1 2013-03-13");
   printf("problem size n        : %d\n", n);
   printf("total   solutions     : %lld\n",
         solution);
   printf("correct solutions     : %lld\n",
         answer[n]);
   printf("million solutions/sec : %.3f\n",
         (double)solution/usec);
   printf("elapsed time (sec)    : %.3f\n",
         usec/1000000.0);
   if(solution!=answer[n])
      printf(" ### Wrong answer\n");
   for(i=0;i<45;i++) printf("="); printf("\n");
   fflush(stdout);
}

variable_types:
solution
long long

variable_types: i int

variable_types:
answer
long long [30]


decompiled_code:
int __fastcall set_problem_size(int a1, const char **a2)
{
int result; // eax

printf("%s %s\n", "qn24b pthreads", "version 1.0.0.1 2013-03-13");
if ( a1 != 2 )
{
printf("Usage: %s n\n", *a2);
exit(0);
}
result = atoi(a2[1]);
if ( (unsigned int)(result - 2) > 0x1B )
{
printf("board size range: %d-%d\n", 2LL, 29LL);
exit(0);
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(int a1, const char **a2)
{
int result; // eax

printf("%s %s\n", "qn24b pthreads", "version 1.0.0.1 2013-03-13");
if ( a1 != 2 )
{
printf("Usage: %s n\n", *a2);
exit(0);
}
result = atoi(a2[1]);
if ( (unsigned int)(result - 2) > 0x1B )
{
printf("board size range: %d-%d\n", 2LL, 29LL);
exit(0);
}
return result;
}

original_code:
int set_problem_size(int argc, char** argv){
   int n;
   printf("%s %s\n", "qn24b pthreads", "version 1.0.0.1 2013-03-13");
   if(argc!=2){
      printf("Usage: %s n\n", argv[0]);
      exit(0);
   }
   n = atoi(argv[1]);
   if(2>n || 29<n){
      printf("board size range: %d-%d\n",2, 29);
      exit(0);
   }
   return n;
}

canonical_original_code:
int set_problem_size(int argc, char **argv){
   int n;
   printf("%s %s\n", "qn24b pthreads", "version 1.0.0.1 2013-03-13");
   if(argc!=2){
      printf("Usage: %s n\n", argv[0]);
      exit(0);
   }
   n = atoi(argv[1]);
   if(2>n || 29<n){
      printf("board size range: %d-%d\n",2, 29);
      exit(0);
   }
   return n;
}

variable_types: argc int

variable_types:
argv
char **


original_code:
long long queen_sub(int n, int *in, int mode){
   int i;
   long long solution=0;
   unsigned int row;
   unsigned int h;
   array a[29];
   for(i=0; i<29; i++){
      a[i].cdt = a[i].col = a[i].pos = a[i].neg = 0;
   }
   row = (1<<n)-1;
   a[1].col = (1<<n)-1;
   a[1].pos = 0;
   a[1].neg = 0;
   a[1].cdt = 1;
   a[2].cdt = 0;
   for(h=1; h<=4; h++){
      int lsb = (1<<in[h]);
      if((a[h].col & lsb)==0) return 0;
      if((a[h].pos & lsb)!=0) return 0;
      if((a[h].neg & lsb)!=0) return 0;
      a[h+1].col = (a[h].col & ~lsb);
      a[h+1].pos = (a[h].pos | lsb) << 1;
      a[h+1].neg = (a[h].neg | lsb) >> 1;
      row = a[h+1].col & ~(a[h+1].pos | a[h+1].neg);
   }
   if(mode==0) return 1;
   solution = qn(n, h, row, a);
   return solution;
}

canonical_original_code:
long long queen_sub(int n, int *in, int mode){
   int i;
   long long solution = 0;
   unsigned int row;
   unsigned int h;
   struct array_t a[29];
   for(i=0; i<29; i++){
      a[i].cdt = a[i].col = a[i].pos = a[i].neg = 0;
   }
   row = (1<<n)-1;
   a[1].col = (1<<n)-1;
   a[1].pos = 0;
   a[1].neg = 0;
   a[1].cdt = 1;
   a[2].cdt = 0;
   for(h=1; h<=4; h++){
      int lsb = (1<<in[h]);
      if((a[h].col & lsb)==0) return 0;
      if((a[h].pos & lsb)!=0) return 0;
      if((a[h].neg & lsb)!=0) return 0;
      a[h+1].col = (a[h].col & ~lsb);
      a[h+1].pos = (a[h].pos | lsb) << 1;
      a[h+1].neg = (a[h].neg | lsb) >> 1;
      row = a[h+1].col & ~(a[h+1].pos | a[h+1].neg);
   }
   if(mode==0) return 1;
   solution = qn(n, h, row, a);
   return solution;
}

variable_types:
in
int *

variable_types: mode int

variable_types:
row
unsigned int

variable_types:
h
unsigned int

variable_types: struct array_t { unsigned int cdt; unsigned int col; unsigned int pos; unsigned int neg; } [29]


decompiled_code:
__int64 __fastcall get_sub_problem_num(int a1, __int64 a2)
{
int v2; // ebx
int v3; // er12
int i; // er13
_DWORD v6[42]; // [rsp+0h] [rbp-A8h] BYREF

v2 = a1 * a1 * a1 * ((a1 & 1) + (a1 >> 1));
if ( v2 < 0 )
{
v3 = 0;
printf("There are %d tasks\n", 0LL);
}
else
{
v3 = 0;
for ( i = 0; i <= v2; ++i )
{
v6[4] = (i - 1) % a1;
v6[3] = (i - 1) / a1 % a1;
v6[2] = (i - 1) / a1 / a1 % a1;
v6[1] = (i - 1) / a1 / a1 / a1;
if ( queen_sub(a1, (__int64)v6, 0) )
*(_DWORD *)(a2 + 4LL * ++v3) = i;
}
printf("There are %d tasks\n", (unsigned int)v3);
if ( v3 > 100000 )
{
puts("The number of tasks is too large.");
exit(1);
}
}
return (unsigned int)v3;
}

original_code:
int get_sub_problem_num(int n, int *prob){
   int i;
   int problem=0;
   int max = ((n>>1) + (n&1)) * n * n * n;
   for(i=0; i<=max; i++){
      int in[29];
      in[1] = (i-1) / n / n / n;
      in[2] = (i-1) / n / n % n;
      in[3] = (i-1) / n % n;
      in[4] = (i-1) % n;
      if(queen_sub(n, in, 0)){
         problem++;
         prob[problem] = i;
      }
   }
   printf("There are %d tasks\n", problem);
   if(problem > 100000){
      printf("The number of tasks is too large.\n");
      exit(1);
   }
   return problem;
}

canonical_original_code:
int get_sub_problem_num(int n, int *prob){
   int i;
   int problem = 0;
   int max = ((n>>1) + (n&1)) * n * n * n;
   for(i=0; i<=max; i++){
      int in[29];
      in[1] = (i-1) / n / n / n;
      in[2] = (i-1) / n / n % n;
      in[3] = (i-1) / n % n;
      in[4] = (i-1) % n;
      if(queen_sub(n, in, 0)){
         problem++;
         prob[problem] = i;
      }
   }
   printf("There are %d tasks\n", problem);
   if(problem > 100000){
      printf("The number of tasks is too large.\n");
      exit(1);
   }
   return problem;
}

variable_types:
prob
int *

variable_types: problem int

variable_types: max int

variable_types:
in
int [29]


solver

decompiled_code:
__int64 __fastcall solver(int a1, __int64 a2, int a3, __int64 a4)
{
int v4; // eax
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-88h] BYREF
int v7; // [rsp+8h] [rbp-80h]
int v8; // [rsp+Ch] [rbp-7Ch]
int v9; // [rsp+10h] [rbp-78h]

if ( (int)a2 <= 0 || (int)a2 > a3 )
{
printf("The id %d is out of range.\n", a2);
result = 0LL;
}
else
{
v4 = (*(_DWORD *)(a4 + 4LL * (int)a2) - 1) / a1;
v9 = (*(_DWORD *)(a4 + 4LL * (int)a2) - 1) % a1;
v8 = v4 % a1;
v7 = v4 / a1 % a1;
HIDWORD(v6) = v4 / a1 / a1;
result = queen_sub(a1, (__int64)&v6, 1);
if ( SHIDWORD(v6) < a1 >> 1 )
result *= 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, __int64 a2, int a3, __int64 a4)
{
int v4; // eax
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-88h] BYREF
int v7; // [rsp+8h] [rbp-80h]
int v8; // [rsp+Ch] [rbp-7Ch]
int v9; // [rsp+10h] [rbp-78h]

if ( (int)a2 <= 0 || (int)a2 > a3 )
{
printf("The id %d is out of range.\n", a2);
result = 0LL;
}
else
{
v4 = (*(_DWORD *)(a4 + 4LL * (int)a2) - 1) / a1;
v9 = (*(_DWORD *)(a4 + 4LL * (int)a2) - 1) % a1;
v8 = v4 % a1;
v7 = v4 / a1 % a1;
HIDWORD(v6) = v4 / a1 / a1;
result = func12(a1, (__int64)&v6, 1);
if ( SHIDWORD(v6) < a1 >> 1 )
result *= 2LL;
}
return result;
}

original_code:
long long solver(int n, int id,
      int problem, int *prob){
   long long ret;
   int p_no = prob[id];
   int in[29];
   if(id<1 || id>problem){
      printf("The id %d is out of range.\n", id);
      return 0;
   }
   in[1] = (p_no-1) / n / n / n;
   in[2] = (p_no-1) / n / n % n;
   in[3] = (p_no-1) / n % n;
   in[4] = (p_no-1) % n;
   ret = queen_sub(n, in, 1);
   if(in[1]<(n>>1)) ret = ret * 2;
   return ret;
}

variable_types: n int

variable_types: id int

variable_types:
ret
long long


decompiled_code:
void *__fastcall worker_body(void *a1)
{
unsigned int v1; // eax

while ( 1 )
{
v1 = atomic_grab_next(a1);
if ( v1 == -1 )
break;
a1 = (void *)(unsigned int)n;
rets[v1] = solver(n, v1, jobs, (__int64)&prob);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func15(void *a1)
{
unsigned int v1; // eax

while ( 1 )
{
v1 = func7(a1);
if ( v1 == -1 )
break;
a1 = (void *)(unsigned int)n;
rets[v1] = func14(n, v1, jobs, (__int64)&prob);
}
return 0LL;
}

original_code:
void* worker_body(void* thread_v){
   int i;
   int thread = (int)thread_v;
   while((i = atomic_grab_next()) != -1){
      rets[i] = solver(n, i, jobs, prob);
   }
   return ((void *)0);
}

canonical_original_code:
void *worker_body(void *thread_v){
   int i;
   int thread = (int)thread_v;
   while((i = atomic_grab_next()) != -1){
      rets[i] = solver(n, i, jobs, prob);
   }
   return ((void *)0);
}

variable_types: thread int

return_type: void *


main

repo: tcreech/stdbuf-osx

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
const char *v4; // r13
const char *v5; // r12
int v6; // eax
const char **v7; // rbp
char *v8; // rdx
int v9; // eax
char *ptr[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "e:i:o:");
if ( v6 == -1 )
break;
if ( v6 == 105 )
{
v3 = (const char *)optarg;
}
else if ( v6 == 111 )
{
v4 = (const char *)optarg;
}
else
{
if ( v6 != 101 )
usage_constprop_0();
v5 = (const char *)optarg;
}
}
v7 = &argv[optind];
if ( optind != argc )
{
if ( v3 && setenv("_STDBUF_I", v3, 1) == -1 )
warn("Failed to set environment variable: %s=%s", "_STDBUF_I", v3);
if ( v4 && setenv("_STDBUF_O", v4, 1) == -1 )
warn("Failed to set environment variable: %s=%s", "_STDBUF_O", v4);
if ( v5 && setenv("_STDBUF_E", v5, 1) == -1 )
warn("Failed to set environment variable: %s=%s", "_STDBUF_E", v5);
v8 = getenv("DYLD_INSERT_LIBRARIES");
if ( v8 )
v9 = asprintf(ptr, "DYLD_INSERT_LIBRARIES=%s:%s", v8, "/usr/local/lib/libstdbuf.dylib");
else
v9 = asprintf(ptr, "DYLD_INSERT_LIBRARIES=/usr/local/lib/libstdbuf.dylib");
if ( v9 < 0 || putenv(ptr[0]) == -1 )
warn("Failed to set environment variable: DYLD_INSERT_LIBRARIES");
execvp(*v7, (char *const *)v7);
err(2, "%s", *v7);
}
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
const char *v4; // r13
const char *v5; // r12
int v6; // eax
const char **v7; // rbp
char *v8; // rdx
int v9; // eax
char *ptr[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "e:i:o:");
if ( v6 == -1 )
break;
if ( v6 == 105 )
{
v3 = (const char *)optarg;
}
else if ( v6 == 111 )
{
v4 = (const char *)optarg;
}
else
{
if ( v6 != 101 )
func7();
v5 = (const char *)optarg;
}
}
v7 = &argv[optind];
if ( optind != argc )
{
if ( v3 && setenv("_STDBUF_I", v3, 1) == -1 )
warn("Failed to set environment variable: %s=%s", "_STDBUF_I", v3);
if ( v4 && setenv("_STDBUF_O", v4, 1) == -1 )
warn("Failed to set environment variable: %s=%s", "_STDBUF_O", v4);
if ( v5 && setenv("_STDBUF_E", v5, 1) == -1 )
warn("Failed to set environment variable: %s=%s", "_STDBUF_E", v5);
v8 = getenv("DYLD_INSERT_LIBRARIES");
if ( v8 )
v9 = asprintf(ptr, "DYLD_INSERT_LIBRARIES=%s:%s", v8, "/usr/local/lib/libstdbuf.dylib");
else
v9 = asprintf(ptr, "DYLD_INSERT_LIBRARIES=/usr/local/lib/libstdbuf.dylib");
if ( v9 < 0 || putenv(ptr[0]) == -1 )
warn("Failed to set environment variable: DYLD_INSERT_LIBRARIES");
execvp(*v7, (char *const *)v7);
err(2, "%s", *v7);
}
exit(0);
}

original_code:
int
main(int argc, char *argv[])
{
 char *ibuf, *obuf, *ebuf;
 char *preload0, *preload1;
 int i;
 ibuf = obuf = ebuf = ((void *)0);
 while ((i = getopt(argc, argv, "e:i:o:")) != -1) {
  switch (i) {
  case 'e':
   ebuf = optarg;
   break;
  case 'i':
   ibuf = optarg;
   break;
  case 'o':
   obuf = optarg;
   break;
  case '?':
  default:
   usage(1);
   break;
  }
 }
 argc -= optind;
 argv += optind;
 if (argc == 0)
  exit(0);
 if (ibuf != ((void *)0) && setenv("_STDBUF_I", ibuf, 1) == -1)
  warn("Failed to set environment variable: %s=%s",
      "_STDBUF_I", ibuf);
 if (obuf != ((void *)0) && setenv("_STDBUF_O", obuf, 1) == -1)
  warn("Failed to set environment variable: %s=%s",
      "_STDBUF_O", obuf);
 if (ebuf != ((void *)0) && setenv("_STDBUF_E", ebuf, 1) == -1)
  warn("Failed to set environment variable: %s=%s",
      "_STDBUF_E", ebuf);
 preload0 = getenv("DYLD_INSERT_LIBRARIES");
 if (preload0 == ((void *)0))
  i = asprintf(&preload1, "DYLD_INSERT_LIBRARIES=" "/usr/local" "/lib/" "libstdbuf.dylib");
 else
  i = asprintf(&preload1, "DYLD_INSERT_LIBRARIES=%s:%s", preload0,
      "/usr/local" "/lib/" "libstdbuf.dylib");
 if (i < 0 || putenv(preload1) == -1)
  warn("Failed to set environment variable: DYLD_INSERT_LIBRARIES");
 execvp(argv[0], argv);
 err(2, "%s", argv[0]);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *ibuf; char *obuf; char *ebuf;
 char *preload0; char *preload1;
 int i;
 ibuf = obuf = ebuf = ((void *)0);
 while ((i = getopt(argc, argv, "e:i:o:")) != -1) {
  switch (i) {
  case 'e':
   ebuf = optarg;
   break;
  case 'i':
   ibuf = optarg;
   break;
  case 'o':
   obuf = optarg;
   break;
  case '?':
  default:
   usage(1);
   break;
  }
 }
 argc -= optind;
 argv += optind;
 if (argc == 0)
  exit(0);
 if (ibuf != ((void *)0) && setenv("_STDBUF_I", ibuf, 1) == -1)
  warn("Failed to set environment variable: %s=%s",
      "_STDBUF_I", ibuf);
 if (obuf != ((void *)0) && setenv("_STDBUF_O", obuf, 1) == -1)
  warn("Failed to set environment variable: %s=%s",
      "_STDBUF_O", obuf);
 if (ebuf != ((void *)0) && setenv("_STDBUF_E", ebuf, 1) == -1)
  warn("Failed to set environment variable: %s=%s",
      "_STDBUF_E", ebuf);
 preload0 = getenv("DYLD_INSERT_LIBRARIES");
 if (preload0 == ((void *)0))
  i = asprintf(&preload1, "DYLD_INSERT_LIBRARIES=" "/usr/local" "/lib/" "libstdbuf.dylib");
 else
  i = asprintf(&preload1, "DYLD_INSERT_LIBRARIES=%s:%s", preload0,
      "/usr/local" "/lib/" "libstdbuf.dylib");
 if (i < 0 || putenv(preload1) == -1)
  warn("Failed to set environment variable: DYLD_INSERT_LIBRARIES");
 execvp(argv[0], argv);
 err(2, "%s", argv[0]);
}

variable_types:
argv
char *[]

variable_types:
ibuf
char *

variable_types:
obuf
char *

variable_types:
ebuf
char *

variable_types: i int


repo: tdierks/tageventor

decompiled_code:
__int64 __fastcall jcop_read(int a1)
{
int v1; // eax
unsigned int v2; // er8
int v3; // ebp
int v4; // eax

v1 = read(JCOP_socket, JCOP_buffer, 0x400uLL);
if ( v1 <= 3 || JCOP_buffer[0] != a1 || JCOP_buffer[1] )
goto LABEL_10;
v2 = v1;
v3 = (unsigned __int8)JCOP_buffer[3] | JCOP_buffer[2] & 0xFF00;
if ( v3 + 4 != v1 )
{
if ( v1 == 4 )
{
v4 = read(JCOP_socket, &JCOP_buffer[4], 0x3FCuLL);
if ( v4 >= 0 && v3 == v4 )
return (unsigned int)(v3 + 4);
}
LABEL_10:
jcop_close_isra_0();
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int v1; // eax
unsigned int v2; // er8
int v3; // ebp
int v4; // eax

v1 = read(JCOP_socket, JCOP_buffer, 0x400uLL);
if ( v1 <= 3 || JCOP_buffer[0] != a1 || JCOP_buffer[1] )
goto LABEL_10;
v2 = v1;
v3 = (unsigned __int8)JCOP_buffer[3] | JCOP_buffer[2] & 0xFF00;
if ( v3 + 4 != v1 )
{
if ( v1 == 4 )
{
v4 = read(JCOP_socket, &JCOP_buffer[4], 0x3FCuLL);
if ( v4 >= 0 && v3 == v4 )
return (unsigned int)(v3 + 4);
}
LABEL_10:
func7();
v2 = -1;
}
return v2;
}

original_code:
static int jcop_read(int tag){
    int ret, len;
    ;;
    ret = read(JCOP_socket, JCOP_buffer, 1024);
    ;
    ;;
    if (ret < 4){
 ;;
 jcop_close();
 return -1;
    }
    if ((JCOP_buffer[0] != tag) || (JCOP_buffer[1] != 0)){
 ;;
 jcop_close();
 return -1;
    }
    len = (JCOP_buffer[2]&0xff << 8) + (JCOP_buffer[3]&0xff);
    if (ret == len + 4){
 ;;
 return ret;
    }
    ;;
    if (ret != 4){
 ;;
 jcop_close();
 return -1;
    }
    ret = read(JCOP_socket, JCOP_buffer+4, 1024 -4);
    ;
    ;;
    if (ret < 0){
 ;;
 jcop_close();
 return -1;
    }
    if (ret != len){
 ;;
 jcop_close();
 return -1;
    }
    return 4+ret;
}

canonical_original_code:
static int jcop_read(int tag){
    int ret; int len;
    ;;
    ret = read(JCOP_socket, JCOP_buffer, 1024);
    ;
    ;;
    if (ret < 4){
 ;;
 jcop_close();
 return -1;
    }
    if ((JCOP_buffer[0] != tag) || (JCOP_buffer[1] != 0)){
 ;;
 jcop_close();
 return -1;
    }
    len = (JCOP_buffer[2]&0xff << 8) + (JCOP_buffer[3]&0xff);
    if (ret == len + 4){
 ;;
 return ret;
    }
    ;;
    if (ret != 4){
 ;;
 jcop_close();
 return -1;
    }
    ret = read(JCOP_socket, JCOP_buffer+4, 1024 -4);
    ;
    ;;
    if (ret < 0){
 ;;
 jcop_close();
 return -1;
    }
    if (ret != len){
 ;;
 jcop_close();
 return -1;
    }
    return 4+ret;
}

variable_types: tag int

variable_types: ret int

variable_types: len int


decompiled_code:
__int64 jcop_power_up()
{
struct hostent *v0; // rax
int v1; // eax
__int64 result; // rax
struct sockaddr v3; // [rsp+0h] [rbp-28h] BYREF

if ( JCOP_socket >= 0 )
jcop_close_isra_0();
JCOP_socket = socket(2, 1, 0);
if ( JCOP_socket < 0 )
return 612LL;
v3.sa_family = 2;
*(_WORD *)v3.sa_data = _bswap_16_constprop_0("localhost");
v0 = gethostbyname("localhost");
if ( !v0 )
{
jcop_close_isra_0();
fprintf(stderr, "invalid jcop host %s\n", "localhost");
fflush(stderr);
exit(-1);
}
*(_DWORD *)&v3.sa_data[2] = **(_DWORD **)v0->h_addr_list;
if ( connect(JCOP_socket, &v3, 0x10u) < 0
|| (*(_QWORD *)JCOP_buffer = 67117312LL, (int)write(JCOP_socket, JCOP_buffer, 8uLL) < 0) )
{
jcop_close_isra_0();
result = 612LL;
}
else
{
v1 = jcop_read(0);
if ( v1 <= 3 )
{
result = 0xFFFFFFFFLL;
}
else
{
JCOP_atrl = v1 - 4;
memcpy(&JCOP_atr, &JCOP_buffer[4], v1 - 4);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
struct hostent *v0; // rax
int v1; // eax
__int64 result; // rax
struct sockaddr v3; // [rsp+0h] [rbp-28h] BYREF

if ( JCOP_socket >= 0 )
func7();
JCOP_socket = socket(2, 1, 0);
if ( JCOP_socket < 0 )
return 612LL;
v3.sa_family = 2;
*(_WORD *)v3.sa_data = func6("localhost");
v0 = gethostbyname("localhost");
if ( !v0 )
{
func7();
fprintf(stderr, "invalid jcop host %s\n", "localhost");
fflush(stderr);
exit(-1);
}
*(_DWORD *)&v3.sa_data[2] = **(_DWORD **)v0->h_addr_list;
if ( connect(JCOP_socket, &v3, 0x10u) < 0
|| (*(_QWORD *)JCOP_buffer = 67117312LL, (int)write(JCOP_socket, JCOP_buffer, 8uLL) < 0) )
{
func7();
result = 612LL;
}
else
{
v1 = func8(0);
if ( v1 <= 3 )
{
result = 0xFFFFFFFFLL;
}
else
{
JCOP_atrl = v1 - 4;
memcpy(&JCOP_atr, &JCOP_buffer[4], v1 - 4);
result = 0LL;
}
}
return result;
}

original_code:
static int jcop_power_up(){
    struct sockaddr_in servername;
    struct hostent *hostinfo;
    int ret;
    if (JCOP_socket >= 0)
 jcop_close();
    ;;
    JCOP_socket = socket(2, SOCK_STREAM, 0);
    if (JCOP_socket < 0) {
 ;;
 return 612;
    }
    servername.sin_family = 2;
    servername.sin_port = htons(8050);
    hostinfo = gethostbyname("localhost");
    if (hostinfo == ((void *)0)){
 jcop_close();
 fprintf(stderr, "invalid jcop host %s\n", "localhost");
 fflush(stderr);
 exit(-1);
    }
    servername.sin_addr = *(struct in_addr *) hostinfo->h_addr_list[0];
    if (connect (JCOP_socket, (struct sockaddr *) &servername, sizeof (servername)) < 0){
 jcop_close();
 ;;
 return 612;
    }
    JCOP_buffer[0] = 0x0;
    JCOP_buffer[1] = 0x21;
    JCOP_buffer[2] = 0;
    JCOP_buffer[3] = 4;
    JCOP_buffer[4] = 0;
    JCOP_buffer[5] = 0;
    JCOP_buffer[6] = 0;
    JCOP_buffer[7] = 0;
    ret = write(JCOP_socket, JCOP_buffer, 8);
    if (ret < 0){
 ;;
 jcop_close();
 return 612;
    }
    ret = jcop_read(0x0);
    if (ret < 4){
 ;;
 return -1;
    }
    JCOP_atrl = ret - 4;
    memcpy(JCOP_atr, JCOP_buffer+4, JCOP_atrl);
    ;
    ;;
    return 0;
}

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

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

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

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


IFDHCreateChannel

decompiled_code:
__int64 IFDHCreateChannel()
{
jcop_power_up();
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
func9();
return 0LL;
}

original_code:
RESPONSECODE IFDHCreateChannel ( DWORD Lun, DWORD Channel ) {
    ;;
    jcop_power_up();
    return 0;
}

canonical_original_code:
long IFDHCreateChannel(unsigned long Lun, unsigned long Channel) {
    ;;
    jcop_power_up();
    return 0;
}

variable_types:
Lun
unsigned long

variable_types:
Channel
unsigned long

return_type: long


IFDHCloseChannel

decompiled_code:
__int64 IFDHCloseChannel()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
return 0LL;
}

original_code:
RESPONSECODE IFDHCloseChannel ( DWORD Lun ) {
    ;;
    return 0;
}

canonical_original_code:
long IFDHCloseChannel(unsigned long Lun) {
    ;;
    return 0;
}


IFDHGetCapabilities

decompiled_code:
__int64 __fastcall IFDHGetCapabilities(__int64 a1, __int64 a2, __int64 a3, _BYTE *a4)
{
if ( a2 == 4014 )
*a4 = 1;
return 0LL;
}

original_code:
RESPONSECODE IFDHGetCapabilities ( DWORD Lun, DWORD Tag,
       PDWORD Length, PUCHAR Value ) {
    ;;
    switch(Tag){
    case 0x0FAE:
 *Value = 1;
 break;
    default:
 ;;
    }
    return 0;
}

canonical_original_code:
long IFDHGetCapabilities(unsigned long Lun, unsigned long Tag, unsigned long *Length, unsigned char *Value) {
    ;;
    switch(Tag){
    case 0x0FAE:
 *Value = 1;
 break;
    default:
 ;;
    }
    return 0;
}

variable_types:
Tag
unsigned long

variable_types:
Length
unsigned long *

variable_types:
Value
unsigned char *


IFDHSetCapabilities

decompiled_code:
__int64 IFDHSetCapabilities()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func13()
{
return 0LL;
}

original_code:
RESPONSECODE IFDHSetCapabilities ( DWORD Lun, DWORD Tag,
          DWORD Length, PUCHAR Value ) {
    return 0;
}

canonical_original_code:
long IFDHSetCapabilities(unsigned long Lun, unsigned long Tag, unsigned long Length, unsigned char *Value) {
    return 0;
}

variable_types:
Length
unsigned long


IFDHSetProtocolParameters

decompiled_code:
__int64 IFDHSetProtocolParameters()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
return 0LL;
}

original_code:
RESPONSECODE IFDHSetProtocolParameters ( DWORD Lun, DWORD Protocol,
       UCHAR Flags, UCHAR PTS1,
       UCHAR PTS2, UCHAR PTS3) {
    ;;
    return 0;
}

canonical_original_code:
long IFDHSetProtocolParameters(unsigned long Lun, unsigned long Protocol, unsigned char Flags, unsigned char PTS1, unsigned char PTS2, unsigned char PTS3) {
    ;;
    return 0;
}

variable_types:
Protocol
unsigned long

variable_types:
Flags
unsigned char


IFDHPowerICC

decompiled_code:
__int64 __fastcall IFDHPowerICC(__int64 a1, __int64 a2, void *a3, _QWORD *a4)
{
if ( a2 != 500 )
return 0LL;
if ( !(unsigned int)jcop_power_up() )
{
memcpy(a3, &JCOP_atr, JCOP_atrl);
*a4 = JCOP_atrl;
return 0LL;
}
*a4 = 0LL;
return 612LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, void *a3, _QWORD *a4)
{
if ( a2 != 500 )
return 0LL;
if ( !(unsigned int)func9() )
{
memcpy(a3, &JCOP_atr, JCOP_atrl);
*a4 = JCOP_atrl;
return 0LL;
}
*a4 = 0LL;
return 612LL;
}

original_code:
RESPONSECODE IFDHPowerICC ( DWORD Lun, DWORD Action,
       PUCHAR Atr, PDWORD AtrLength ) {
    ;;
    if (Action == 500){
 int ret = jcop_power_up();
 if (ret == 0){
     memcpy(Atr, JCOP_atr, JCOP_atrl);
     *AtrLength = JCOP_atrl;
     ;;
     return 0;
 }
 ;;
 *AtrLength = 0;
 return 612;
    }
    return 0;
}

canonical_original_code:
long IFDHPowerICC(unsigned long Lun, unsigned long Action, unsigned char *Atr, unsigned long *AtrLength) {
    ;;
    if (Action == 500){
 int ret = jcop_power_up();
 if (ret == 0){
     memcpy(Atr, JCOP_atr, JCOP_atrl);
     *AtrLength = JCOP_atrl;
     ;;
     return 0;
 }
 ;;
 *AtrLength = 0;
 return 612;
    }
    return 0;
}

variable_types:
Action
unsigned long

variable_types:
Atr
unsigned char *

variable_types:
AtrLength
unsigned long *


IFDHControl

decompiled_code:
__int64 IFDHControl()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func17()
{
return 0LL;
}

original_code:
RESPONSECODE IFDHControl ( DWORD Lun, PUCHAR TxBuffer,
    DWORD TxLength, PUCHAR RxBuffer,
    PDWORD RxLength ) {
    ;;
    return 0;
}

canonical_original_code:
long IFDHControl(unsigned long Lun, unsigned char *TxBuffer, unsigned long TxLength, unsigned char *RxBuffer, unsigned long *RxLength) {
    ;;
    return 0;
}

variable_types:
TxBuffer
unsigned char *

variable_types:
TxLength
unsigned long

variable_types:
RxBuffer
unsigned char *

variable_types:
RxLength
unsigned long *


IFDHICCPresence

decompiled_code:
__int64 IFDHICCPresence()
{
__int64 result; // rax
int v1; // edi
int v2; // eax
struct timeval v3; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

if ( JCOP_socket < 0 )
{
jcop_power_up();
v1 = JCOP_socket;
if ( JCOP_socket <= 0 )
goto LABEL_7;
}
else if ( !JCOP_socket )
{
return 615LL;
}
memset(&readfds, 0, sizeof(readfds));
v3.tv_sec = 0LL;
v3.tv_usec = 0LL;
readfds.fds_bits[JCOP_socket / 64] |= 1LL << (JCOP_socket % 64);
v2 = select(1024, &readfds, 0LL, 0LL, &v3);
if ( v2 < 0 )
goto LABEL_9;
v1 = JCOP_socket;
if ( v2 != 1 )
goto LABEL_7;
if ( (int)read(JCOP_socket, JCOP_buffer, 0x400uLL) <= 0 )
{
LABEL_9:
jcop_close_isra_0();
return 616LL;
}
v1 = JCOP_socket;
LABEL_7:
result = 616LL;
if ( v1 >= 0 )
return 615LL;
return result;
}

canonical_decompiled_code:
__int64 func18()
{
__int64 result; // rax
int v1; // edi
int v2; // eax
struct timeval v3; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

if ( JCOP_socket < 0 )
{
func9();
v1 = JCOP_socket;
if ( JCOP_socket <= 0 )
goto LABEL_7;
}
else if ( !JCOP_socket )
{
return 615LL;
}
memset(&readfds, 0, sizeof(readfds));
v3.tv_sec = 0LL;
v3.tv_usec = 0LL;
readfds.fds_bits[JCOP_socket / 64] |= 1LL << (JCOP_socket % 64);
v2 = select(1024, &readfds, 0LL, 0LL, &v3);
if ( v2 < 0 )
goto LABEL_9;
v1 = JCOP_socket;
if ( v2 != 1 )
goto LABEL_7;
if ( (int)read(JCOP_socket, JCOP_buffer, 0x400uLL) <= 0 )
{
LABEL_9:
func7();
return 616LL;
}
v1 = JCOP_socket;
LABEL_7:
result = 616LL;
if ( v1 >= 0 )
return 615LL;
return result;
}

original_code:
RESPONSECODE IFDHICCPresence( DWORD Lun ) {
    fd_set set;
    struct timeval timeout;
    int ret;
    if (JCOP_socket < 0){
 ;;
 (void) jcop_power_up();
    }
    if (JCOP_socket > 0){
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&set)->__fds_bits)[((JCOP_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((JCOP_socket) % (8 * (int) sizeof (__fd_mask)))))));
 timeout.tv_sec = 0;
 timeout.tv_usec = 0;
 ret = select (1024, &set, ((void *)0), ((void *)0), &timeout);
 if (ret < 0){
     ;;
     jcop_close();
     return 616;
 }
 if (ret == 1){
     ;;
     ret = read(JCOP_socket, JCOP_buffer, 1024);
     if (ret <= 0){
  ;;
  jcop_close();
  return 616;
     }else{
  ;
     }
 }
    }
    return (JCOP_socket < 0) ? 616 : 615;
}

canonical_original_code:
long IFDHICCPresence(unsigned long Lun) {
    struct fd_set set;
    struct timeval timeout;
    int ret;
    if (JCOP_socket < 0){
 ;;
 (void) jcop_power_up();
    }
    if (JCOP_socket > 0){
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&set)->__fds_bits)[((JCOP_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((JCOP_socket) % (8 * (int) sizeof (__fd_mask)))))));
 timeout.tv_sec = 0;
 timeout.tv_usec = 0;
 ret = select (1024, &set, ((void *)0), ((void *)0), &timeout);
 if (ret < 0){
     ;;
     jcop_close();
     return 616;
 }
 if (ret == 1){
     ;;
     ret = read(JCOP_socket, JCOP_buffer, 1024);
     if (ret <= 0){
  ;;
  jcop_close();
  return 616;
     }else{
  ;
     }
 }
    }
    return (JCOP_socket < 0) ? 616 : 615;
}

variable_types:
set
struct fd_set { long __fds_bits[-1]; }

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: ret int


repo: tdubourg/TPThread

decompiled_code:
int exercice1()
{
puts("\n ------------ Exercice 1 ------------ ");
if ( !(unsigned int)testIsPrime(50LL) )
return puts("isPrime() went wrong.");
testPrintPrimeFactors();
putchar(10);
return readMyFile("numbers.txt");
}

canonical_decompiled_code:
int func0()
{
puts("\n ------------ Exercice 1 ------------ ");
if ( !(unsigned int)testIsPrime(50LL) )
return puts("isPrime() went wrong.");
testPrintPrimeFactors();
putchar(10);
return readMyFile("numbers.txt");
}

original_code:
void exercice1() {
 printf("\n ------------ Exercice 1 ------------ \n");
 if (!testIsPrime(50)) {
  printf("isPrime() went wrong.\n");
  return;
 }
 testPrintPrimeFactors();
 printf("\n");
 readMyFile("numbers.txt");
}


decompiled_code:
__int64 exercice2()
{
puts("\n ------------ Exercice 2 ------------ ");
return readMyFileThreaded1("numbers.txt");
}

canonical_decompiled_code:
__int64 func1()
{
puts("\n ------------ Exercice 2 ------------ ");
return readMyFileThreaded1("numbers.txt");
}

original_code:
void exercice2() {
 printf("\n ------------ Exercice 2 ------------ \n");
 readMyFileThreaded1("numbers.txt");
}


decompiled_code:
__int64 exercice3()
{
puts("\n ------------ Exercice 3 ------------ ");
return readMyFileThreaded2("numbers.txt");
}

canonical_decompiled_code:
__int64 func2()
{
puts("\n ------------ Exercice 3 ------------ ");
return readMyFileThreaded2("numbers.txt");
}

original_code:
void exercice3() {
 printf("\n ------------ Exercice 3 ------------ \n");
 readMyFileThreaded2("numbers.txt");
}


decompiled_code:
__int64 exercice4()
{
puts("\n ------------ Exercice 4 ------------ ");
return readMyFileThreadedN_And_Memoized("numbers.txt", 2LL);
}

canonical_decompiled_code:
__int64 func3()
{
puts("\n ------------ Exercice 4 ------------ ");
return readMyFileThreadedN_And_Memoized("numbers.txt", 2LL);
}

original_code:
void exercice4() {
 printf("\n ------------ Exercice 4 ------------ \n");
 readMyFileThreadedN_And_Memoized("numbers.txt", 2);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
exercice1();
exercice2(argc, argv);
exercice3();
exercice4();
pthread_exit(0LL);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func0();
func1(argc, argv);
func2();
func3();
pthread_exit(0LL);
}

original_code:
int main(int argc, char** argv) {
 exercice1();
 exercice2();
 exercice3();
 exercice4();
 pthread_exit(((void *)0));
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 exercice1();
 exercice2();
 exercice3();
 exercice4();
 pthread_exit(((void *)0));
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall detruire_noeud_arbre(void *ptr)
{
unsigned int v1; // er12

v1 = *(_DWORD *)ptr;
free(*((void **)ptr + 1));
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
unsigned int v1; // er12

v1 = *(_DWORD *)ptr;
free(*((void **)ptr + 1));
free(ptr);
return v1;
}

original_code:
t_element detruire_noeud_arbre(t_arbre *noeud) {
 t_element el = noeud->cle;
 free(noeud->valeur);
 noeud->valeur = ((void *)0);
 free(noeud);
 return el;
}

canonical_original_code:
unsigned int detruire_noeud_arbre(struct t_noeud *noeud) {
 unsigned int el = noeud->cle;
 free(noeud->valeur);
 noeud->valeur = ((void *)0);
 free(noeud);
 return el;
}

variable_types: struct t_noeud { unsigned int cle; unsigned int *valeur; unsigned int val_size; unsigned int hauteur; struct t_noeud *gauche; struct t_noeud *droit; } *

variable_types:
el
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall detruire_arbre(_QWORD *a1)
{
if ( a1[3] )
detruire_arbre();
if ( a1[4] )
detruire_arbre();
return detruire_noeud_arbre(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
if ( a1[3] )
func1();
if ( a1[4] )
func1();
return func0(a1);
}

original_code:
void detruire_arbre(t_arbre *a) {
 if (a->gauche != ((void *)0)) {
  detruire_arbre(a->gauche);
 }
 if (a->droit != ((void *)0)) {
  detruire_arbre(a->droit);
 }
 detruire_noeud_arbre(a);
}

canonical_original_code:
void detruire_arbre(struct t_noeud *a) {
 if (a->gauche != ((void *)0)) {
  detruire_arbre(a->gauche);
 }
 if (a->droit != ((void *)0)) {
  detruire_arbre(a->droit);
 }
 detruire_noeud_arbre(a);
}

user_defined_types: struct t_noeud { unsigned int cle; unsigned int *valeur; unsigned int val_size; unsigned int hauteur; struct t_noeud *gauche; struct t_noeud *droit; }


decompiled_code:
__int64 __fastcall inserer_arbre(__int64 a1, unsigned int a2, void *a3, int a4)
{
__int64 i; // rbx
__int64 v6; // rax
int v7; // ebp
_QWORD *v8; // rax

if ( !a1 )
inserer_arbre_cold(a2, a3);
for ( i = a1; a2 < *(_DWORD *)i; i = v6 )
{
v6 = *(_QWORD *)(i + 24);
v7 = 1;
if ( !v6 )
goto LABEL_8;
LABEL_4:
;
}
if ( a2 <= *(_DWORD *)i )
{
free(a3);
return a1;
}
v6 = *(_QWORD *)(i + 32);
v7 = 0;
if ( v6 )
goto LABEL_4;
LABEL_8:
v8 = creer_arbre(a2, (__int64)a3, 0LL, 0LL);
*((_DWORD *)v8 + 4) = a4;
if ( v7 )
*(_QWORD *)(i + 24) = v8;
else
*(_QWORD *)(i + 32) = v8;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, void *a3, int a4)
{
__int64 i; // rbx
__int64 v6; // rax
int v7; // ebp
_QWORD *v8; // rax

if ( !a1 )
func11(a2, a3);
for ( i = a1; a2 < *(_DWORD *)i; i = v6 )
{
v6 = *(_QWORD *)(i + 24);
v7 = 1;
if ( !v6 )
goto LABEL_8;
LABEL_4:
;
}
if ( a2 <= *(_DWORD *)i )
{
free(a3);
return a1;
}
v6 = *(_QWORD *)(i + 32);
v7 = 0;
if ( v6 )
goto LABEL_4;
LABEL_8:
v8 = creer_arbre(a2, (__int64)a3, 0LL, 0LL);
*((_DWORD *)v8 + 4) = a4;
if ( v7 )
*(_QWORD *)(i + 24) = v8;
else
*(_QWORD *)(i + 32) = v8;
return a1;
}

original_code:
t_arbre *inserer_arbre(t_arbre *a, t_element v, t_element* factors, unsigned v_size) {
 t_arbre* curr = a;
 t_arbre *prec = ((void *)0);
 int left = 0;
 while (curr != ((void *)0)) {
  t_element e = curr->cle;
  if (e > v) {
   prec = curr;
   curr = curr->gauche;
   left = 1;
  } else if (e < v) {
   prec = curr;
   curr = curr->droit;
   left = 0;
  } else {
   free(factors);
   return a;
  }
 }
 t_arbre *n = creer_arbre(v, factors, ((void *)0), ((void *)0));
 n->val_size = v_size;
 if (left) {
  prec->gauche = n;
 } else {
  prec->droit = n;
 }
 return a;
}

canonical_original_code:
struct t_noeud *inserer_arbre(struct t_noeud *a, unsigned int v, unsigned int *factors, unsigned int v_size) {
 struct t_noeud *curr = a;
 struct t_noeud *prec = ((void *)0);
 int left = 0;
 while (curr != ((void *)0)) {
  unsigned int e = curr->cle;
  if (e > v) {
   prec = curr;
   curr = curr->gauche;
   left = 1;
  } else if (e < v) {
   prec = curr;
   curr = curr->droit;
   left = 0;
  } else {
   free(factors);
   return a;
  }
 }
 struct t_noeud *n = creer_arbre(v, factors, ((void *)0), ((void *)0));
 n->val_size = v_size;
 if (left) {
  prec->gauche = n;
 } else {
  prec->droit = n;
 }
 return a;
}

variable_types:
a
struct t_noeud *

variable_types:
v
unsigned int

variable_types:
factors
unsigned int *

variable_types: left int

variable_types:
e
unsigned int

return_type: struct t_noeud { unsigned int cle; unsigned int *valeur; unsigned int val_size; unsigned int hauteur; struct t_noeud *gauche; struct t_noeud *droit; } *


decompiled_code:
__int64 __fastcall supprimer_min(void *ptr)
{
unsigned int *v1; // r8
unsigned int v2; // er12

do
{
v1 = (unsigned int *)ptr;
ptr = (void *)*((_QWORD *)ptr + 3);
}
while ( ptr );
v2 = *v1;
detruire_noeud_arbre(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
unsigned int *v1; // r8
unsigned int v2; // er12

do
{
v1 = (unsigned int *)ptr;
ptr = (void *)*((_QWORD *)ptr + 3);
}
while ( ptr );
v2 = *v1;
func0(v1);
return v2;
}

original_code:
t_element supprimer_min(t_arbre *a) {
 t_arbre *c;
 t_element tmp;
 if (a->gauche == ((void *)0)) {
  tmp = (a->cle);
  c = a;
  a = a->droit;
  detruire_noeud_arbre(c);
  return tmp;
 } else {
  return supprimer_min(a->gauche);
 }
}

canonical_original_code:
unsigned int supprimer_min(struct t_noeud *a) {
 struct t_noeud *c;
 unsigned int tmp;
 if (a->gauche == ((void *)0)) {
  tmp = (a->cle);
  c = a;
  a = a->droit;
  detruire_noeud_arbre(c);
  return tmp;
 } else {
  return supprimer_min(a->gauche);
 }
}

variable_types:
tmp
unsigned int


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

for ( result = a1; result; result = *(_QWORD *)(result + 32) )
{
while ( *(_DWORD *)result > a2 )
{
result = *(_QWORD *)(result + 24);
if ( !result )
return result;
}
if ( *(_DWORD *)result >= a2 )
break;
}
return result;
}

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

for ( result = a1; result; result = *(_QWORD *)(result + 32) )
{
while ( *(_DWORD *)result > a2 )
{
result = *(_QWORD *)(result + 24);
if ( !result )
return result;
}
if ( *(_DWORD *)result >= a2 )
break;
}
return result;
}

original_code:
t_arbre *rechercher_arbre(t_arbre *a, t_element v) {
 t_arbre* curr = a;
 while (curr != ((void *)0)) {
  t_element e = curr->cle;
  if (e > v) {
   curr = curr->gauche;
  } else if (e < v) {
   curr = curr->droit;
  } else {
   return curr;
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct t_noeud *rechercher_arbre(struct t_noeud *a, unsigned int v) {
 struct t_noeud *curr = a;
 while (curr != ((void *)0)) {
  unsigned int e = curr->cle;
  if (e > v) {
   curr = curr->gauche;
  } else if (e < v) {
   curr = curr->droit;
  } else {
   return curr;
  }
 }
 return ((void *)0);
}


decompiled_code:
__int64 __fastcall calculer_hauteur(__int64 a1)
{
int v2; // eax
__int64 v3; // rdi
__int64 result; // rax
int v5; // eax
unsigned int v6; // edx

if ( *(_QWORD *)(a1 + 24) )
{
v2 = calculer_hauteur();
v3 = *(_QWORD *)(a1 + 32);
result = (unsigned int)(v2 + 1);
*(_DWORD *)(a1 + 20) = result;
if ( !v3 )
return result;
}
else if ( !*(_QWORD *)(a1 + 32) )
{
*(_DWORD *)(a1 + 20) = 0;
return 0LL;
}
v5 = calculer_hauteur();
v6 = *(_DWORD *)(a1 + 20);
result = (unsigned int)(v5 + 1);
if ( v6 >= (unsigned int)result )
return v6;
*(_DWORD *)(a1 + 20) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v2; // eax
__int64 v3; // rdi
__int64 result; // rax
int v5; // eax
unsigned int v6; // edx

if ( *(_QWORD *)(a1 + 24) )
{
v2 = func5();
v3 = *(_QWORD *)(a1 + 32);
result = (unsigned int)(v2 + 1);
*(_DWORD *)(a1 + 20) = result;
if ( !v3 )
return result;
}
else if ( !*(_QWORD *)(a1 + 32) )
{
*(_DWORD *)(a1 + 20) = 0;
return 0LL;
}
v5 = func5();
v6 = *(_DWORD *)(a1 + 20);
result = (unsigned int)(v5 + 1);
if ( v6 >= (unsigned int)result )
return v6;
*(_DWORD *)(a1 + 20) = result;
return result;
}

original_code:
int calculer_hauteur(t_arbre *a) {
 if (a->gauche == ((void *)0) && a->droit == ((void *)0)) {
  a->hauteur = 0;
 } else {
  if (a->gauche != ((void *)0)) {
   a->hauteur = 1 + calculer_hauteur(a->gauche);
  }
  if (a->droit != ((void *)0)) {
   int curr;
   curr = 1 + calculer_hauteur(a->droit);
   if (curr > a->hauteur) {
    a->hauteur = curr;
   }
  }
 }
 return a->hauteur;
}

canonical_original_code:
int calculer_hauteur(struct t_noeud *a) {
 if (a->gauche == ((void *)0) && a->droit == ((void *)0)) {
  a->hauteur = 0;
 } else {
  if (a->gauche != ((void *)0)) {
   a->hauteur = 1 + calculer_hauteur(a->gauche);
  }
  if (a->droit != ((void *)0)) {
   int curr;
   curr = 1 + calculer_hauteur(a->droit);
   if (curr > a->hauteur) {
    a->hauteur = curr;
   }
  }
 }
 return a->hauteur;
}

variable_types: curr int


decompiled_code:
int __fastcall afficher_arbre(unsigned int *a1)
{
int v1; // ebx
int result; // eax
int v3; // ebx
int v4; // ebx

v1 = 1;
if ( ++hauteur_courante_0 > 0 )
{
do
{
++v1;
putchar(9);
}
while ( hauteur_courante_0 >= v1 );
}
result = printf("(Noeud) Cle : %u ; hauteur : %u\n", *a1, a1[5]);
if ( *((_QWORD *)a1 + 3) )
{
v3 = 1;
if ( hauteur_courante_0 > 0 )
{
do
{
++v3;
putchar(9);
}
while ( hauteur_courante_0 >= v3 );
}
puts("SAG : ");
result = afficher_arbre(*((_QWORD *)a1 + 3));
}
if ( *((_QWORD *)a1 + 4) )
{
v4 = 1;
if ( hauteur_courante_0 > 0 )
{
do
{
++v4;
putchar(9);
}
while ( hauteur_courante_0 >= v4 );
}
puts("SAD : ");
result = afficher_arbre(*((_QWORD *)a1 + 4));
}
--hauteur_courante_0;
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1)
{
int v1; // ebx
int result; // eax
int v3; // ebx
int v4; // ebx

v1 = 1;
if ( ++hauteur_courante_0 > 0 )
{
do
{
++v1;
putchar(9);
}
while ( hauteur_courante_0 >= v1 );
}
result = printf("(Noeud) Cle : %u ; hauteur : %u\n", *a1, a1[5]);
if ( *((_QWORD *)a1 + 3) )
{
v3 = 1;
if ( hauteur_courante_0 > 0 )
{
do
{
++v3;
putchar(9);
}
while ( hauteur_courante_0 >= v3 );
}
puts("SAG : ");
result = func6(*((_QWORD *)a1 + 3));
}
if ( *((_QWORD *)a1 + 4) )
{
v4 = 1;
if ( hauteur_courante_0 > 0 )
{
do
{
++v4;
putchar(9);
}
while ( hauteur_courante_0 >= v4 );
}
puts("SAD : ");
result = func6(*((_QWORD *)a1 + 4));
}
--hauteur_courante_0;
return result;
}

original_code:
void afficher_arbre(t_arbre *a) {
 static int hauteur_courante = 0;
 hauteur_courante++;
 int i;
 for (i = 1; i <= hauteur_courante; i++) {
  printf("\t");
 }
 printf("(Noeud) Cle : %u ; hauteur : %u\n", a->cle, a->hauteur);
 if (a->gauche != ((void *)0)) {
  for (i = 1; i <= hauteur_courante; i++) {
   printf("\t");
  }
  printf("SAG : \n");
  afficher_arbre(a->gauche);
 }
 if (a->droit != ((void *)0)) {
  for (i = 1; i <= hauteur_courante; i++) {
   printf("\t");
  }
  printf("SAD : \n");
  afficher_arbre(a->droit);
 }
 hauteur_courante--;
}

canonical_original_code:
void afficher_arbre(struct t_noeud *a) {
 static int hauteur_courante = 0;
 hauteur_courante++;
 int i;
 for (i = 1; i <= hauteur_courante; i++) {
  printf("\t");
 }
 printf("(Noeud) Cle : %u ; hauteur : %u\n", a->cle, a->hauteur);
 if (a->gauche != ((void *)0)) {
  for (i = 1; i <= hauteur_courante; i++) {
   printf("\t");
  }
  printf("SAG : \n");
  afficher_arbre(a->gauche);
 }
 if (a->droit != ((void *)0)) {
  for (i = 1; i <= hauteur_courante; i++) {
   printf("\t");
  }
  printf("SAD : \n");
  afficher_arbre(a->droit);
 }
 hauteur_courante--;
}

variable_types: i int


decompiled_code:
__int64 __fastcall maj_hauteur_depuis_enfants(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rsi
__int64 result; // rax
int v4; // edx
int v5; // ecx
int v6; // edx

v1 = *(_QWORD *)(a1 + 24);
v2 = *(_QWORD *)(a1 + 32);
result = a1;
if ( !v1 )
{
v4 = -1;
if ( !v2 )
{
v6 = 0;
goto LABEL_7;
}
goto LABEL_3;
}
v4 = *(_DWORD *)(v1 + 20);
v5 = -1;
if ( v2 )
LABEL_3:
v5 = *(_DWORD *)(v2 + 20);
if ( v4 < v5 )
v4 = v5;
v6 = v4 + 1;
LABEL_7:
*(_DWORD *)(a1 + 20) = v6;
return result;
}

original_code:
t_arbre *maj_hauteur_depuis_enfants(t_arbre *x) {
 int hauteur_gauche = (x->gauche != ((void *)0)) ? x->gauche->hauteur : -1;
 int hauteur_droit = (x->droit != ((void *)0)) ? x->droit->hauteur : -1;
 if (x->gauche == ((void *)0) && x->droit == ((void *)0)) {
  x->hauteur = 0;
 } else {
  x->hauteur = 1
   + ((hauteur_gauche > hauteur_droit) ?
   hauteur_gauche : hauteur_droit);
 }
 return x;
}

canonical_original_code:
struct t_noeud *maj_hauteur_depuis_enfants(struct t_noeud *x) {
 int hauteur_gauche = (x->gauche != ((void *)0)) ? x->gauche->hauteur : -1;
 int hauteur_droit = (x->droit != ((void *)0)) ? x->droit->hauteur : -1;
 if (x->gauche == ((void *)0) && x->droit == ((void *)0)) {
  x->hauteur = 0;
 } else {
  x->hauteur = 1
   + ((hauteur_gauche > hauteur_droit) ?
   hauteur_gauche : hauteur_droit);
 }
 return x;
}

variable_types:
x
struct t_noeud *


original_code:
t_arbre *rotation_droite(t_arbre *y) {
 t_arbre *b = y->gauche->droit;
 t_arbre *x = y->gauche;
 x->droit = y;
 y->gauche = b;
 y = maj_hauteur_depuis_enfants(y);
 int hauteur_droit = (x->droit != ((void *)0)) ? x->droit->hauteur : -1;
 x->hauteur = 1
  + ((hauteur_droit > x->hauteur) ? hauteur_droit : x->hauteur);
 return x;
}

canonical_original_code:
struct t_noeud *rotation_droite(struct t_noeud *y) {
 struct t_noeud *b = y->gauche->droit;
 struct t_noeud *x = y->gauche;
 x->droit = y;
 y->gauche = b;
 y = maj_hauteur_depuis_enfants(y);
 int hauteur_droit = (x->droit != ((void *)0)) ? x->droit->hauteur : -1;
 x->hauteur = 1
  + ((hauteur_droit > x->hauteur) ? hauteur_droit : x->hauteur);
 return x;
}

variable_types:
y
struct t_noeud *


original_code:
t_arbre *rotation_gauche(t_arbre *x) {
 t_arbre *b = x->droit->gauche;
 t_arbre *y = x->droit;
 x->droit = b;
 y->gauche = x;
 x = maj_hauteur_depuis_enfants(x);
 int hauteur_droit = (y->droit != ((void *)0)) ? y->droit->hauteur : -1;
 y->hauteur = 1
  + ((hauteur_droit > x->hauteur) ? hauteur_droit : x->hauteur);
 return y;
}

canonical_original_code:
struct t_noeud *rotation_gauche(struct t_noeud *x) {
 struct t_noeud *b = x->droit->gauche;
 struct t_noeud *y = x->droit;
 x->droit = b;
 y->gauche = x;
 x = maj_hauteur_depuis_enfants(x);
 int hauteur_droit = (y->droit != ((void *)0)) ? y->droit->hauteur : -1;
 y->hauteur = 1
  + ((hauteur_droit > x->hauteur) ? hauteur_droit : x->hauteur);
 return y;
}


original_code:
t_arbre *equilibrer_arbre(t_arbre *a) {
 if (a->gauche != ((void *)0) && a->gauche->gauche != ((void *)0)) {
  int hauteur_B =
   (a->gauche->droit != ((void *)0)) ?
   a->gauche->droit->hauteur : -1;
  int hauteur_C = (a->droit != ((void *)0)) ? a->droit->hauteur : -1;
  int hauteur_A = a->gauche->gauche->hauteur;
  int max = (hauteur_B > hauteur_C) ? hauteur_B : hauteur_C;
  while (hauteur_A >= max) {
   a = rotation_droite(a);
   if (a->gauche != ((void *)0) && a->gauche->gauche != ((void *)0)) {
    hauteur_B =
     (a->gauche->droit != ((void *)0)) ?
     a->gauche->droit->hauteur : -1;
    hauteur_C =
     (a->droit != ((void *)0)) ? a->droit->hauteur : -1;
    hauteur_A = a->gauche->gauche->hauteur;
    max = (hauteur_B > hauteur_C) ? hauteur_B : hauteur_C;
   } else {
    break;
   }
  }
 }
 if (a->droit != ((void *)0) && a->droit->droit != ((void *)0)) {
  int hauteur_B =
   (a->droit->gauche != ((void *)0)) ?
   a->droit->gauche->hauteur : -1;
  int hauteur_A = (a->gauche != ((void *)0)) ? a->gauche->hauteur : -1;
  int hauteur_C = a->droit->droit->hauteur;
  int max = (hauteur_B > hauteur_A) ? hauteur_B : hauteur_A;
  while (hauteur_C >= max) {
   a = rotation_gauche(a);
   if (a->droit != ((void *)0) && a->droit->droit != ((void *)0)) {
    hauteur_B =
     (a->droit->gauche != ((void *)0)) ?
     a->droit->gauche->hauteur : -1;
    hauteur_A =
     (a->gauche != ((void *)0)) ? a->gauche->hauteur : -1;
    hauteur_C = a->droit->droit->hauteur;
    max = (hauteur_B > hauteur_A) ? hauteur_B : hauteur_A;
   } else {
    break;
   }
  }
 }
 if (a->droit != ((void *)0)) {
  a->droit = equilibrer_arbre(a->droit);
  a->droit = maj_hauteur_depuis_enfants(a->droit);
 }
 if (a->gauche != ((void *)0)) {
  a->gauche = equilibrer_arbre(a->gauche);
  a->gauche = maj_hauteur_depuis_enfants(a->gauche);
 }
 a = maj_hauteur_depuis_enfants(a);
 return a;
}

canonical_original_code:
struct t_noeud *equilibrer_arbre(struct t_noeud *a) {
 if (a->gauche != ((void *)0) && a->gauche->gauche != ((void *)0)) {
  int hauteur_B = (a->gauche->droit != ((void *)0)) ?
   a->gauche->droit->hauteur : -1;
  int hauteur_C = (a->droit != ((void *)0)) ? a->droit->hauteur : -1;
  int hauteur_A = a->gauche->gauche->hauteur;
  int max = (hauteur_B > hauteur_C) ? hauteur_B : hauteur_C;
  while (hauteur_A >= max) {
   a = rotation_droite(a);
   if (a->gauche != ((void *)0) && a->gauche->gauche != ((void *)0)) {
    hauteur_B =
     (a->gauche->droit != ((void *)0)) ?
     a->gauche->droit->hauteur : -1;
    hauteur_C =
     (a->droit != ((void *)0)) ? a->droit->hauteur : -1;
    hauteur_A = a->gauche->gauche->hauteur;
    max = (hauteur_B > hauteur_C) ? hauteur_B : hauteur_C;
   } else {
    break;
   }
  }
 }
 if (a->droit != ((void *)0) && a->droit->droit != ((void *)0)) {
  int hauteur_B = (a->droit->gauche != ((void *)0)) ?
   a->droit->gauche->hauteur : -1;
  int hauteur_A = (a->gauche != ((void *)0)) ? a->gauche->hauteur : -1;
  int hauteur_C = a->droit->droit->hauteur;
  int max = (hauteur_B > hauteur_A) ? hauteur_B : hauteur_A;
  while (hauteur_C >= max) {
   a = rotation_gauche(a);
   if (a->droit != ((void *)0) && a->droit->droit != ((void *)0)) {
    hauteur_B =
     (a->droit->gauche != ((void *)0)) ?
     a->droit->gauche->hauteur : -1;
    hauteur_A =
     (a->gauche != ((void *)0)) ? a->gauche->hauteur : -1;
    hauteur_C = a->droit->droit->hauteur;
    max = (hauteur_B > hauteur_A) ? hauteur_B : hauteur_A;
   } else {
    break;
   }
  }
 }
 if (a->droit != ((void *)0)) {
  a->droit = equilibrer_arbre(a->droit);
  a->droit = maj_hauteur_depuis_enfants(a->droit);
 }
 if (a->gauche != ((void *)0)) {
  a->gauche = equilibrer_arbre(a->gauche);
  a->gauche = maj_hauteur_depuis_enfants(a->gauche);
 }
 a = maj_hauteur_depuis_enfants(a);
 return a;
}

variable_types: max int


decompiled_code:
void *init_table()
{
return memset(&MEM_TABLE, 0, (size_t)&unk_7D000);
}

canonical_decompiled_code:
void *func0()
{
return memset(&MEM_TABLE, 0, (size_t)&unk_7D000);
}

original_code:
static void init_table() {
 int i = 0;
 for(; i < 64000; i++) {
  MEM_TABLE[i] = ((void *)0);
 }
}


rechercher

decompiled_code:
__int64 __fastcall rechercher(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0xF9FF )
result = 0LL;
else
result = MEM_TABLE[a1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0xF9FF )
result = 0LL;
else
result = MEM_TABLE[a1];
return result;
}

original_code:
static t_el* rechercher(unsigned n) {
 if(n >= 64000) {
  return ((void *)0);
 }
 return MEM_TABLE[n % 64000];
}

canonical_original_code:
static struct t_table_el *rechercher(unsigned int n) {
 if(n >= 64000) {
  return ((void *)0);
 }
 return MEM_TABLE[n % 64000];
}

variable_types:
n
unsigned int

return_type: struct t_table_el { int cle; unsigned int *valeur; unsigned int val_size; } *


original_code:
static void print_prime_factors_nodisp(unsigned n, int startresearch) {
 if (!(n % 2)) {
  printf(" %u", 2);
  return print_prime_factors_nodisp(n / 2, 2);
 }
 if (!(n % 3)) {
  printf(" %u", 3);
  return print_prime_factors_nodisp(n / 3, 3);
 }
 if (!(n % 5)) {
  printf(" %u", 5);
  return print_prime_factors_nodisp(n / 5, 5);
 }
 int pas_i = 4;
 int i;
 startresearch = (startresearch >= 7) ? startresearch : 7;
 int max = sqrt(n) + 1;
 for (i = startresearch; i < max; i += pas_i, pas_i = 6 - pas_i) {
  if (!(n % i)) {
   printf(" %u", i);
   if (i < n) {
    return print_prime_factors_nodisp(n / i, i);
   }
  }
 }
 printf(" %u", n);
}

canonical_original_code:
static void print_prime_factors_nodisp(unsigned int n, int startresearch) {
 if (!(n % 2)) {
  printf(" %u", 2);
  return print_prime_factors_nodisp(n / 2, 2);
 }
 if (!(n % 3)) {
  printf(" %u", 3);
  return print_prime_factors_nodisp(n / 3, 3);
 }
 if (!(n % 5)) {
  printf(" %u", 5);
  return print_prime_factors_nodisp(n / 5, 5);
 }
 int pas_i = 4;
 int i;
 startresearch = (startresearch >= 7) ? startresearch : 7;
 int max = sqrt(n) + 1;
 for (i = startresearch; i < max; i += pas_i, pas_i = 6 - pas_i) {
  if (!(n % i)) {
   printf(" %u", i);
   if (i < n) {
    return print_prime_factors_nodisp(n / i, i);
   }
  }
 }
 printf(" %u", n);
}

variable_types: startresearch int


inserer

decompiled_code:
void __fastcall inserer(unsigned int a1, void *a2, int a3)
{
_QWORD *v4; // rax

if ( a1 <= 0xF9FF )
{
if ( MEM_TABLE[a1] )
{
free(a2);
}
else
{
v4 = malloc(0x18uLL);
*(_DWORD *)v4 = a1;
v4[1] = a2;
*((_DWORD *)v4 + 4) = a3;
MEM_TABLE[a1] = (__int64)v4;
}
}
}

canonical_decompiled_code:
void __fastcall func3(unsigned int a1, void *a2, int a3)
{
_QWORD *v4; // rax

if ( a1 <= 0xF9FF )
{
if ( MEM_TABLE[a1] )
{
free(a2);
}
else
{
v4 = malloc(0x18uLL);
*(_DWORD *)v4 = a1;
v4[1] = a2;
*((_DWORD *)v4 + 4) = a3;
MEM_TABLE[a1] = (__int64)v4;
}
}
}

original_code:
static void inserer(unsigned n, t_element* val, unsigned size) {
 if(n >= 64000) {
  return;
 }
 if(MEM_TABLE[n % 64000] != ((void *)0)) {
  free(val);
  return;
 }
 t_el* t = (t_el*) malloc(sizeof(t_el));
 t->cle = n;
 t->valeur = val;
 t->val_size = size;
 MEM_TABLE[t->cle % 64000] = t;
}

canonical_original_code:
static void inserer(unsigned int n, unsigned int *val, unsigned int size) {
 if(n >= 64000) {
  return;
 }
 if(MEM_TABLE[n % 64000] != ((void *)0)) {
  free(val);
  return;
 }
 struct t_table_el *t = (t_el*) malloc(sizeof(t_el));
 t->cle = n;
 t->valeur = val;
 t->val_size = size;
 MEM_TABLE[t->cle % 64000] = t;
}

variable_types:
val
unsigned int *

variable_types:
size
unsigned int

variable_types: struct t_table_el { int cle; unsigned int *valeur; unsigned int val_size; } *


decompiled_code:
void detruire_table()
{
void **v0; // rbx

v0 = (void **)MEM_TABLE;
do
{
if ( *v0 )
{
free(*((void **)*v0 + 1));
free(*v0);
}
++v0;
}
while ( v0 != (void **)&unk_7DE80 );
}

original_code:
static void detruire_table() {
 int i = 0;
 for(; i < 64000; i++) {
  if(MEM_TABLE[i] != ((void *)0)) {
   free(MEM_TABLE[i]->valeur);
   MEM_TABLE[i]->valeur = ((void *)0);
   free(MEM_TABLE[i]);
  }
 }
}


decompiled_code:
__int64 __fastcall is_prime(unsigned int a1)
{
__int64 result; // rax
double v2; // xmm1_8
double v3; // xmm1_8
double v4; // xmm1_8
unsigned int v5; // ecx
double v6; // xmm0_8

result = 1LL;
if ( a1 > 3 )
{
if ( a1 <= 7 )
return (a1 & 0xFFFFFFFD) - 4;
v2 = (double)(int)a1;
if ( (double)(int)a1 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
v4 = v3 + 1.0;
if ( (a1 & 1) == 0 )
{
v6 = *(double *)&LC3;
return v6 >= v4;
}
v5 = 2;
if ( v4 < 2.0 )
{
v6 = *(double *)&LC3;
return v6 >= v4;
}
while ( 1 )
{
v6 = (double)(int)++v5;
if ( !(a1 % v5) )
break;
if ( v4 < v6 )
return v6 >= v4;
}
result = v6 >= v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
__int64 result; // rax
double v2; // xmm1_8
double v3; // xmm1_8
double v4; // xmm1_8
unsigned int v5; // ecx
double v6; // xmm0_8

result = 1LL;
if ( a1 > 3 )
{
if ( a1 <= 7 )
return (a1 & 0xFFFFFFFD) - 4;
v2 = (double)(int)a1;
if ( (double)(int)a1 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
v4 = v3 + 1.0;
if ( (a1 & 1) == 0 )
{
v6 = *(double *)&LC3;
return v6 >= v4;
}
v5 = 2;
if ( v4 < 2.0 )
{
v6 = *(double *)&LC3;
return v6 >= v4;
}
while ( 1 )
{
v6 = (double)(int)++v5;
if ( !(a1 % v5) )
break;
if ( v4 < v6 )
return v6 >= v4;
}
result = v6 >= v4;
}
return result;
}

original_code:
int is_prime(unsigned p) {
 if (p <= 3) {
  return 1;
 } else if (!p) {
  return 0;
 } else if (p <= 7) {
  switch (p) {
   case 5:
   case 7:
    return 1;
    break;
   default:
    return 0;
    break;
  }
 }
 double max = sqrt(p) + 1;
 int j;
 for (j = 2; p % j && j <= max; j++);
 return (j >= max) ? 1 : 0;
}

canonical_original_code:
int is_prime(unsigned int p) {
 if (p <= 3) {
  return 1;
 } else if (!p) {
  return 0;
 } else if (p <= 7) {
  switch (p) {
   case 5:
   case 7:
    return 1;
    break;
   default:
    return 0;
    break;
  }
 }
 double max = sqrt(p) + 1;
 int j;
 for (j = 2; p % j && j <= max; j++);
 return (j >= max) ? 1 : 0;
}

variable_types:
p
unsigned int

variable_types: max double

variable_types: j int


decompiled_code:
int __fastcall print_prime_factors(unsigned int a1)
{
unsigned int v1; // ebp
int v2; // ecx
unsigned int v3; // ebx
int result; // eax

printf("%u:", a1);
if ( (unsigned int)is_prime(a1) )
return printf(" %u\n", a1);
if ( (a1 & 1) != 0 )
{
if ( -1431655765 * a1 <= 0x55555555 )
{
printf(" %u", 3LL);
print_prime_factors_nodisp(a1 / 3, 3u);
result = putchar(10);
}
else if ( -858993459 * a1 <= 0x33333333 )
{
printf(" %u", 5LL);
print_prime_factors_nodisp(a1 / 5, 5u);
result = putchar(10);
}
else
{
if ( a1 <= 7 )
return putchar(10);
v1 = 7;
if ( -1227133513 * a1 > 0x24924924 )
{
v2 = 4;
while ( 1 )
{
v1 += v2;
v3 = v1;
v2 = 6 - v2;
if ( v1 >= a1 )
return putchar(10);
if ( !(a1 % v1) )
goto LABEL_16;
}
}
v3 = 7;
LABEL_16:
printf(" %u", v1);
print_prime_factors_nodisp(a1 / v3, v1);
result = putchar(10);
}
}
else
{
printf(" %u", 2LL);
print_prime_factors_nodisp(a1 >> 1, 2u);
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1)
{
unsigned int v1; // ebp
int v2; // ecx
unsigned int v3; // ebx
int result; // eax

printf("%u:", a1);
if ( (unsigned int)func5(a1) )
return printf(" %u\n", a1);
if ( (a1 & 1) != 0 )
{
if ( -1431655765 * a1 <= 0x55555555 )
{
printf(" %u", 3LL);
func2(a1 / 3, 3u);
result = putchar(10);
}
else if ( -858993459 * a1 <= 0x33333333 )
{
printf(" %u", 5LL);
func2(a1 / 5, 5u);
result = putchar(10);
}
else
{
if ( a1 <= 7 )
return putchar(10);
v1 = 7;
if ( -1227133513 * a1 > 0x24924924 )
{
v2 = 4;
while ( 1 )
{
v1 += v2;
v3 = v1;
v2 = 6 - v2;
if ( v1 >= a1 )
return putchar(10);
if ( !(a1 % v1) )
goto LABEL_16;
}
}
v3 = 7;
LABEL_16:
printf(" %u", v1);
func2(a1 / v3, v1);
result = putchar(10);
}
}
else
{
printf(" %u", 2LL);
func2(a1 >> 1, 2u);
result = putchar(10);
}
return result;
}

original_code:
void print_prime_factors(unsigned n) {
 printf("%u:", n);
 if (is_prime(n)) {
  printf(" %u\n", n);
  return;
 } else if (!(n % 2)) {
  printf(" %u", 2);
  print_prime_factors_nodisp(n / 2, 2);
 } else if (!(n % 3)) {
  printf(" %u", 3);
  print_prime_factors_nodisp(n / 3, 3);
 } else if (!(n % 5)) {
  printf(" %u", 5);
  print_prime_factors_nodisp(n / 5, 5);
 } else {
  int pas_j = 4;
  int i;
  for (i = 7; i < n; i += pas_j, pas_j = 6 - pas_j) {
   if (!(n % i)) {
    printf(" %u", i);
    print_prime_factors_nodisp(n / i, i);
    break;
   }
  }
 }
 printf("\n");
}

canonical_original_code:
void print_prime_factors(unsigned int n) {
 printf("%u:", n);
 if (is_prime(n)) {
  printf(" %u\n", n);
  return;
 } else if (!(n % 2)) {
  printf(" %u", 2);
  print_prime_factors_nodisp(n / 2, 2);
 } else if (!(n % 3)) {
  printf(" %u", 3);
  print_prime_factors_nodisp(n / 3, 3);
 } else if (!(n % 5)) {
  printf(" %u", 5);
  print_prime_factors_nodisp(n / 5, 5);
 } else {
  int pas_j = 4;
  int i;
  for (i = 7; i < n; i += pas_j, pas_j = 6 - pas_j) {
   if (!(n % i)) {
    printf(" %u", i);
    print_prime_factors_nodisp(n / i, i);
    break;
   }
  }
 }
 printf("\n");
}