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

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

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

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

original_code:
void xyz_event2_destroy(struct xyz_event2_t *ev2)
{
    if(ev2) {
        close(ev2->evfd);
        if(ev2->nodes) {
            free(ev2->nodes);
        }
        free(ev2);
    }
    return;
}

user_defined_types: struct xyz_event2_node_t { int (*rdfunc)(int fd, void *arg); int (*wtfunc)(int fd, void *arg); void *rdarg; void *wtarg; }


repo: alannice/learn

original_code:
int xyz_event2_add(struct xyz_event2_t *ev2, int fd, int type, xyz_ev2_func func, void *arg)
{
    if(ev2 == ((void *)0) || fd < 0 || func == ((void *)0) || fd >= 65535 -1) {
        return -1;
    }
    if(type == 1) {
        ev2->nodes[fd].rdfunc = func;
        ev2->nodes[fd].rdarg = arg;
    } else if(type == 2) {
        ev2->nodes[fd].wtfunc = func;
        ev2->nodes[fd].wtarg = arg;
    } else {
        return -1;
    }
    __xyz_event2_add(ev2, fd, type);
    return 0;
}

canonical_original_code:
int xyz_event2_add(struct xyz_event2_t *ev2, int fd, int type, int (*func)(int fd, void *arg), void *arg)
{
    if(ev2 == ((void *)0) || fd < 0 || func == ((void *)0) || fd >= 65535 -1) {
        return -1;
    }
    if(type == 1) {
        ev2->nodes[fd].rdfunc = func;
        ev2->nodes[fd].rdarg = arg;
    } else if(type == 2) {
        ev2->nodes[fd].wtfunc = func;
        ev2->nodes[fd].wtarg = arg;
    } else {
        return -1;
    }
    __xyz_event2_add(ev2, fd, type);
    return 0;
}

variable_types: struct xyz_event2_t { int evfd; struct xyz_event2_node_t { int (*rdfunc)(int fd, void *arg); int (*wtfunc)(int fd, void *arg); void *rdarg; void *wtarg; } *nodes; int isstop; int (*call)(); } *

variable_types: fd int

variable_types: type int

variable_types:
func
int (*)(int fd, void *arg)

variable_types:
arg
void *

return_type: int

user_defined_types: struct xyz_event2_t { int evfd; struct xyz_event2_node_t *nodes; int isstop; int (*call)(); }


decompiled_code:
__int64 __fastcall xyz_event2_del(__int64 a1, int a2, int a3)
{
__int64 v3; // rax
_QWORD *v5; // rax

if ( a1 && (unsigned int)a2 <= 0xFFFE )
{
if ( a3 == 1 )
{
v5 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 32LL * a2);
*v5 = 0LL;
v5[2] = 0LL;
_xyz_event2_del(a1, a2, 1);
return 0LL;
}
if ( a3 == 2 )
{
v3 = *(_QWORD *)(a1 + 8) + 32LL * a2;
*(_QWORD *)(v3 + 8) = 0LL;
*(_QWORD *)(v3 + 24) = 0LL;
_xyz_event2_del(a1, a2, 2);
return 0LL;
}
}
return 0xFFFFFFFFLL;
}

original_code:
int xyz_event2_del(struct xyz_event2_t *ev2, int fd, int type)
{
    if(ev2 == ((void *)0) || fd < 0 || fd >= 65535) {
        return -1;
    }
    if(type == 1) {
        ev2->nodes[fd].rdfunc = ((void *)0);
        ev2->nodes[fd].rdarg = ((void *)0);
    } else if(type == 2) {
        ev2->nodes[fd].wtfunc = ((void *)0);
        ev2->nodes[fd].wtarg = ((void *)0);
    } else {
        return -1;
    }
    __xyz_event2_del(ev2, fd, type);
    return 0;
}


decompiled_code:
__int64 __fastcall xyz_event2_call(__int64 a1, __int64 a2)
{
if ( a1 )
*(_QWORD *)(a1 + 24) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
if ( a1 )
*(_QWORD *)(a1 + 24) = a2;
return 0LL;
}

original_code:
int xyz_event2_call(struct xyz_event2_t *ev2, xyz_ev2_call call)
{
    if(ev2) {
        ev2->call = call;
    }
    return 0;
}

canonical_original_code:
int xyz_event2_call(struct xyz_event2_t *ev2, int (*call)())
{
    if(ev2) {
        ev2->call = call;
    }
    return 0;
}

variable_types:
call
int (*)()


original_code:
void xyz_event2_loop(struct xyz_event2_t *ev2)
{
    if(ev2 == ((void *)0)) {
        return;
    }
    ev2->isstop = 0;
    while(ev2->isstop == 0) {
        __xyz_event2_run(ev2);
        if(ev2->call) {
            ev2->call();
        }
    }
    return;
}

return_type: void


decompiled_code:
void __fastcall xyz_event2_stop(__int64 a1)
{
if ( a1 )
*(_DWORD *)(a1 + 16) = 1;
}

original_code:
void xyz_event2_stop(struct xyz_event2_t *ev2)
{
    if(ev2) {
        ev2->isstop = 1;
    }
    return;
}


decompiled_code:
void __fastcall xyz_event2_stat(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
const void *v4; // rdx

if ( a1 )
{
v1 = 0LL;
puts("------ event2 stat ------");
printf("isstop : %d\n", *(unsigned int *)(a1 + 16));
printf("call : %p\n", *(const void **)(a1 + 24));
do
{
v2 = 32 * v1;
v3 = 32 * v1 + *(_QWORD *)(a1 + 8);
if ( *(_QWORD *)v3 )
{
printf("\t[%d] rdfunc : %p\n", (unsigned int)v1, *(const void **)v3);
printf("\t[%d] rdarg : %p\n", (unsigned int)v1, *(const void **)(*(_QWORD *)(a1 + 8) + v2 + 16));
v3 = v2 + *(_QWORD *)(a1 + 8);
}
v4 = *(const void **)(v3 + 8);
if ( v4 )
{
printf("\t[%d] wtfunc : %p\n", (unsigned int)v1, v4);
printf("\t[%d] wtarg : %p\n", (unsigned int)v1, *(const void **)(*(_QWORD *)(a1 + 8) + v2 + 24));
}
++v1;
}
while ( v1 != 0xFFFF );
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
const void *v4; // rdx

if ( a1 )
{
v1 = 0LL;
puts("------ event2 stat ------");
printf("isstop : %d\n", *(unsigned int *)(a1 + 16));
printf("call : %p\n", *(const void **)(a1 + 24));
do
{
v2 = 32 * v1;
v3 = 32 * v1 + *(_QWORD *)(a1 + 8);
if ( *(_QWORD *)v3 )
{
printf("\t[%d] rdfunc : %p\n", (unsigned int)v1, *(const void **)v3);
printf("\t[%d] rdarg : %p\n", (unsigned int)v1, *(const void **)(*(_QWORD *)(a1 + 8) + v2 + 16));
v3 = v2 + *(_QWORD *)(a1 + 8);
}
v4 = *(const void **)(v3 + 8);
if ( v4 )
{
printf("\t[%d] wtfunc : %p\n", (unsigned int)v1, v4);
printf("\t[%d] wtarg : %p\n", (unsigned int)v1, *(const void **)(*(_QWORD *)(a1 + 8) + v2 + 24));
}
++v1;
}
while ( v1 != 0xFFFF );
}
}

original_code:
void xyz_event2_stat(struct xyz_event2_t *ev2)
{
    int idx;
    if(ev2) {
        printf("------ event2 stat ------\n");
        printf("isstop : %d\n", ev2->isstop);
        printf("call : %p\n", ev2->call);
        for(idx=0; idx<65535; idx++) {
            if(ev2->nodes[idx].rdfunc != ((void *)0)) {
                printf("\t[%d] rdfunc : %p\n", idx, ev2->nodes[idx].rdfunc);
                printf("\t[%d] rdarg : %p\n", idx, ev2->nodes[idx].rdarg);
            }
            if(ev2->nodes[idx].wtfunc != ((void *)0)) {
                printf("\t[%d] wtfunc : %p\n", idx, ev2->nodes[idx].wtfunc);
                printf("\t[%d] wtarg : %p\n", idx, ev2->nodes[idx].wtarg);
            }
        }
    }
    return;
}

variable_types: idx int


decompiled_code:
__int64 __fastcall bkdr_hash(_BYTE *a1)
{
int v1; // eax
int v2; // edx

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 131 * v2;
v1 = (char)*a1;
}
while ( *a1 );
return v2 & 0x7FFFFFFF;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
int v1; // eax
int v2; // edx

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 131 * v2;
v1 = (char)*a1;
}
while ( *a1 );
return v2 & 0x7FFFFFFF;
}

original_code:
signed int bkdr_hash(char *str)
{
    unsigned int seed = 131;
    unsigned int hash = 0;
    while (*str)
    {
        hash = hash * seed + (*str++);
    }
    return (hash & 0x7FFFFFFF);
}

variable_types:
str
char *

variable_types:
seed
unsigned int

variable_types:
hash
unsigned int


decompiled_code:
void __fastcall xyz_hash_destroy(void *ptr)
{
__int64 v2; // rdi
void *v3; // rdi

if ( ptr )
{
v2 = *(_QWORD *)ptr;
if ( v2 )
xyz_mpool_destroy(v2);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
free(ptr);
}
}

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

if ( ptr )
{
v2 = *(_QWORD *)ptr;
if ( v2 )
xyz_mpool_destroy(v2);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
free(ptr);
}
}

original_code:
void xyz_hash_destroy(struct xyz_hash_t *hash)
{
    if(hash) {
        if(hash->mp) {
            xyz_mpool_destroy(hash->mp);
        }
        if(hash->list) {
            free(hash->list);
        }
        free(hash);
    }
    return;
}

variable_types: struct xyz_hash_t { struct xyz_mpool_t { char label[32]; int data_size; char *free_list; int free_count; char *block_list; int block_count; } *mp; int count; int size; struct xyz_hash_list_t { char key[32]; void *data; struct xyz_hash_list_t *next; } **list; } *

user_defined_types: struct xyz_hash_t { struct xyz_mpool_t *mp; int count; int size; struct xyz_hash_list_t **list; }


decompiled_code:
__int64 __fastcall xyz_hash_get(__int64 a1, char *a2)
{
__int64 v2; // r12

v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * ((int)bkdr_hash(a2) % *(_DWORD *)(a1 + 12)));
if ( !v2 )
return v2;
while ( strcmp(a2, (const char *)v2) )
{
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return v2;
}
return *(_QWORD *)(v2 + 32);
}

original_code:
void *xyz_hash_get(struct xyz_hash_t *hash, char *key)
{
    int nkey = bkdr_hash(key)%hash->size;
    struct xyz_hash_list_t *list = hash->list[nkey];
    if(list == ((void *)0)) {
        return ((void *)0);
    }
    while(list) {
        if(strcmp(key, list->key) == 0) {
            return list->data;
        }
        list = list->next;
    }
    return ((void *)0);
}

variable_types:
key
char *

variable_types: nkey int

variable_types: struct xyz_hash_list_t { char key[32]; void *data; struct xyz_hash_list_t *next; } *

return_type: void *

user_defined_types: struct xyz_mpool_t { char label[32]; int data_size; char *free_list; int free_count; char *block_list; int block_count; }


decompiled_code:
__int64 __fastcall xyz_hash_add(__int64 a1, char *a2, __int64 a3)
{
__int64 v5; // r14
__int64 v6; // rbx
__int64 v7; // r13
__int64 v8; // rdi
__int64 result; // rax

v5 = (int)bkdr_hash(a2) % *(_DWORD *)(a1 + 12);
v6 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v5);
v7 = xyz_mpool_malloc(*(_QWORD *)a1);
strncpy((char *)v7, a2, 0x1FuLL);
*(_QWORD *)(v7 + 32) = a3;
*(_QWORD *)(v7 + 40) = 0LL;
if ( v6 )
{
do
{
v8 = v6;
v6 = *(_QWORD *)(v6 + 40);
if ( !v6 )
{
*(_QWORD *)(v8 + 40) = v7;
result = 0LL;
++*(_DWORD *)(a1 + 8);
return result;
}
}
while ( strcmp((const char *)v8, a2) );
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v5) = v7;
result = 0LL;
++*(_DWORD *)(a1 + 8);
}
return result;
}

original_code:
int xyz_hash_add(struct xyz_hash_t *hash, char *key, void *data)
{
    int nkey = bkdr_hash(key)%hash->size;
    struct xyz_hash_list_t *list = hash->list[nkey];
    struct xyz_hash_list_t *tmp;
    tmp = xyz_mpool_malloc(hash->mp);
    strncpy(tmp->key, key, sizeof(tmp->key)-1);
    tmp->data = data;
    tmp->next = ((void *)0);
    if(list == ((void *)0)) {
        hash->list[nkey] = tmp;
        hash->count++;
        return 0;
    }
    while(list->next) {
        if(strcmp(list->key, key) == 0) {
            return -1;
        }
        list = list->next;
    }
    list->next = tmp;
    hash->count++;
 return 0;
}

variable_types:
data
void *

user_defined_types: struct xyz_hash_list_t { char key[32]; void *data; struct xyz_hash_list_t *next; }


original_code:
int xyz_hash_del(struct xyz_hash_t *hash, char *key)
{
    int nkey = bkdr_hash(key)%hash->size;
    struct xyz_hash_list_t *list = hash->list[nkey];
    struct xyz_hash_list_t *prov = ((void *)0);
    if(list == ((void *)0)) {
        return 0;
    }
    while(list) {
        if(strcmp(list->key, key) == 0) {
            if(prov) {
                prov->next = list->next;
            } else {
                hash->list[nkey] = ((void *)0);
            }
            xyz_mpool_free(hash->mp, list);
            hash->count--;
            return 0;
        }
        prov = list;
        list = list->next;
    }
 return 0;
}


decompiled_code:
__int64 __fastcall xyz_hash_state(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rbx

if ( !a1 )
return 0xFFFFFFFFLL;
puts("---xyz_hash_state---");
printf("hash size : %d\n", *(unsigned int *)(a1 + 12));
printf("hash count : %d\n", *(unsigned int *)(a1 + 8));
printf("hash node :");
if ( *(int *)(a1 + 12) > 0 )
{
v1 = 0LL;
do
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v1);
if ( v2 )
{
printf("\n <%d>", (unsigned int)v1);
do
{
printf(" [%s]", (const char *)v2);
v2 = *(_QWORD *)(v2 + 40);
}
while ( v2 );
}
++v1;
}
while ( *(_DWORD *)(a1 + 12) > (int)v1 );
}
puts("\n---the end---");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rbx

if ( !a1 )
return 0xFFFFFFFFLL;
puts("---xyz_hash_state---");
printf("hash size : %d\n", *(unsigned int *)(a1 + 12));
printf("hash count : %d\n", *(unsigned int *)(a1 + 8));
printf("hash node :");
if ( *(int *)(a1 + 12) > 0 )
{
v1 = 0LL;
do
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v1);
if ( v2 )
{
printf("\n <%d>", (unsigned int)v1);
do
{
printf(" [%s]", (const char *)v2);
v2 = *(_QWORD *)(v2 + 40);
}
while ( v2 );
}
++v1;
}
while ( *(_DWORD *)(a1 + 12) > (int)v1 );
}
puts("\n---the end---");
return 0LL;
}

original_code:
int xyz_hash_state(struct xyz_hash_t *hash)
{
    struct xyz_hash_list_t *list;
    int i;
    if(hash == ((void *)0)) {
        return -1;
    }
    printf("---xyz_hash_state---\n");
    printf("hash size : %d\n", hash->size);
    printf("hash count : %d\n", hash->count);
    printf("hash node :");
    for(i=0; i<hash->size; i++) {
        list = hash->list[i];
        if(list) {
            printf("\n <%d>", i);
        }
        while(list) {
            printf(" [%s]", list->key);
            list = list->next;
        }
    }
    printf("\n---the end---\n");
 return 0;
}

variable_types: i int


decompiled_code:
char *__fastcall xyz_mpool_create(char *src, int a2)
{
unsigned int v2; // ebx
char *v3; // rax
char *v4; // r8
char *result; // rax

if ( a2 <= 2 )
return 0LL;
v2 = a2;
v3 = (char *)malloc(0x48uLL);
v4 = v3;
if ( !v3 )
return 0LL;
if ( src && *src )
v4 = strncpy(v3, src, 0x1FuLL);
*((_QWORD *)v4 + 5) = 0LL;
result = v4;
*((_DWORD *)v4 + 12) = 0;
*((_QWORD *)v4 + 7) = 0LL;
if ( (a2 & 7) != 0 )
v2 = (a2 & 0xFFFFFFF8) + 8;
*((_DWORD *)v4 + 16) = 0;
*((_DWORD *)v4 + 8) = v2;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *src, int a2)
{
unsigned int v2; // ebx
char *v3; // rax
char *v4; // r8
char *result; // rax

if ( a2 <= 2 )
return 0LL;
v2 = a2;
v3 = (char *)malloc(0x48uLL);
v4 = v3;
if ( !v3 )
return 0LL;
if ( src && *src )
v4 = strncpy(v3, src, 0x1FuLL);
*((_QWORD *)v4 + 5) = 0LL;
result = v4;
*((_DWORD *)v4 + 12) = 0;
*((_QWORD *)v4 + 7) = 0LL;
if ( (a2 & 7) != 0 )
v2 = (a2 & 0xFFFFFFF8) + 8;
*((_DWORD *)v4 + 16) = 0;
*((_DWORD *)v4 + 8) = v2;
return result;
}

original_code:
struct xyz_mpool_t *xyz_mpool_create(char *label, int size)
{
 if(size <= 2) {
  return ((void *)0);
 }
 struct xyz_mpool_t *mp = malloc(sizeof(struct xyz_mpool_t));
 if(mp==((void *)0)) {
  return ((void *)0);
 }
 if(label != ((void *)0) && strlen(label) > 0) {
  strncpy(mp->label, label, sizeof(mp->label)-1);
 }
 mp->data_size = size;
 if(size & 0x7) {
  mp->data_size = ((size>>3)<<3)+8;
 }
 mp->free_list = ((void *)0);
 mp->free_count = 0;
 mp->block_list = ((void *)0);
 mp->block_count = 0;
 return mp;
}

variable_types:
label
char *

variable_types: size int

variable_types: struct xyz_mpool_t { char label[32]; int data_size; char *free_list; int free_count; char *block_list; int block_count; } *


decompiled_code:
void __fastcall xyz_mpool_destroy(void *ptr)
{
_QWORD *i; // rdi

if ( ptr )
{
for ( i = (_QWORD *)*((_QWORD *)ptr + 7); i; i = (_QWORD *)*((_QWORD *)ptr + 7) )
{
*((_QWORD *)ptr + 7) = *i;
free(i);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
_QWORD *i; // rdi

if ( ptr )
{
for ( i = (_QWORD *)*((_QWORD *)ptr + 7); i; i = (_QWORD *)*((_QWORD *)ptr + 7) )
{
*((_QWORD *)ptr + 7) = *i;
free(i);
}
free(ptr);
}
}

original_code:
void xyz_mpool_destroy(struct xyz_mpool_t *mp)
{
 char *p;
 if(mp == ((void *)0)) {
  return;
 }
 while(mp->block_list) {
  p = mp->block_list;
  mp->block_list = *(char **)p;
  free(p);
 }
 free(mp);
 return;
}

variable_types:
p
char *


decompiled_code:
__int64 __fastcall xyz_mpool_free(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

if ( a1 )
{
if ( a2 )
{
result = *(_QWORD *)(a1 + 40);
*a2 = result;
++*(_DWORD *)(a1 + 48);
*(_QWORD *)(a1 + 40) = a2;
}
}
return result;
}

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

if ( a1 )
{
if ( a2 )
{
result = *(_QWORD *)(a1 + 40);
*a2 = result;
++*(_DWORD *)(a1 + 48);
*(_QWORD *)(a1 + 40) = a2;
}
}
return result;
}

original_code:
void xyz_mpool_free(struct xyz_mpool_t *mp, void *p)
{
 if(mp == ((void *)0) || p == ((void *)0)) {
  return;
 }
 *(char **)p = mp->free_list;
 mp->free_list = p;
 mp->free_count++;
 return;
}

variable_types:
p
void *


decompiled_code:
int __fastcall xyz_mpool_stat(__int64 a1, int a2)
{
int result; // eax
_QWORD *i; // rbx
_QWORD *j; // rbx

puts("------ mpool stat ------");
printf("*** %s ***\n", (const char *)a1);
printf("data_size:%d\n", *(unsigned int *)(a1 + 32));
printf("free_count:%d\n", *(unsigned int *)(a1 + 48));
printf("block_size:%d\n", 32 * *(_DWORD *)(a1 + 32) + 8LL);
result = printf("block_count:%d\n", *(unsigned int *)(a1 + 64));
if ( a2 )
{
puts("free_list display:");
for ( i = *(_QWORD **)(a1 + 40); i; i = (_QWORD *)*i )
printf(" %p ", i);
putchar(10);
puts("block_list display:");
for ( j = *(_QWORD **)(a1 + 56); j; j = (_QWORD *)*j )
printf(" %p ", j);
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, int a2)
{
int result; // eax
_QWORD *i; // rbx
_QWORD *j; // rbx

puts("------ mpool stat ------");
printf("*** %s ***\n", (const char *)a1);
printf("data_size:%d\n", *(unsigned int *)(a1 + 32));
printf("free_count:%d\n", *(unsigned int *)(a1 + 48));
printf("block_size:%d\n", 32 * *(_DWORD *)(a1 + 32) + 8LL);
result = printf("block_count:%d\n", *(unsigned int *)(a1 + 64));
if ( a2 )
{
puts("free_list display:");
for ( i = *(_QWORD **)(a1 + 40); i; i = (_QWORD *)*i )
printf(" %p ", i);
putchar(10);
puts("block_list display:");
for ( j = *(_QWORD **)(a1 + 56); j; j = (_QWORD *)*j )
printf(" %p ", j);
result = putchar(10);
}
return result;
}

original_code:
void xyz_mpool_stat(struct xyz_mpool_t *mp, int v)
{
 char *p;
 printf("------ mpool stat ------\n");
 printf("*** %s ***\n", mp->label);
 printf("data_size:%d\n", mp->data_size);
 printf("free_count:%d\n", mp->free_count);
 printf("block_size:%d\n", mp->data_size*32 +sizeof(char *));
 printf("block_count:%d\n", mp->block_count);
 if(v) {
  printf("free_list display:\n");
  p = mp->free_list;
  while(p) {
   printf(" %p ", p);
   p = *(char **)p;
  }
  printf("\n");
  printf("block_list display:\n");
  p = mp->block_list;
  while(p) {
   printf(" %p ", p);
   p = *(char **)p;
  }
  printf("\n");
 }
 return;
}

variable_types: v int


decompiled_code:
_DWORD *xyz_event_create()
{
_DWORD *result; // rax

result = malloc(0x110uLL);
if ( result )
{
result[2] = -1;
*(_QWORD *)result = 0x30D4000000000LL;
result[10] = -1;
result[18] = -1;
result[26] = -1;
result[34] = -1;
result[42] = -1;
result[50] = -1;
result[58] = -1;
*((_QWORD *)result + 33) = 0LL;
}
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *result; // rax

result = malloc(0x110uLL);
if ( result )
{
result[2] = -1;
*(_QWORD *)result = 0x30D4000000000LL;
result[10] = -1;
result[18] = -1;
result[26] = -1;
result[34] = -1;
result[42] = -1;
result[50] = -1;
result[58] = -1;
*((_QWORD *)result + 33) = 0LL;
}
return result;
}

original_code:
struct xyz_event_t *xyz_event_create()
{
 int i;
 struct xyz_event_t *ev = malloc(sizeof(struct xyz_event_t));
 if(ev == ((void *)0)) {
  return ((void *)0);
 }
 ev->stop = 0;
 ev->usec = 200*1000;
 for(i=0; i<8; i++) {
  ev->array[i].fd = -1;
 }
 ev->call = ((void *)0);
 return ev;
}

variable_types: struct xyz_event_t { int stop; int usec; struct xyz_event_node_t { int fd; int (*rdfunc)(int fd, void *arg); int (*wtfunc)(int fd, void *arg); void *arg; } array[8]; int (*call)(); } *

user_defined_types: struct xyz_event_t { int stop; int usec; struct xyz_event_node_t array[8]; int (*call)(); }


decompiled_code:
__int64 __fastcall xyz_event_call(__int64 a1, __int64 a2)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 264) = a2;
return 0LL;
}

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

original_code:
int xyz_event_call(struct xyz_event_t *ev, xyz_ev_call call)
{
    if(ev == ((void *)0)) {
        return -1;
    }
 ev->call = call;
 return 0;
}

canonical_original_code:
int xyz_event_call(struct xyz_event_t *ev, int (*call)())
{
    if(ev == ((void *)0)) {
        return -1;
    }
 ev->call = call;
 return 0;
}

variable_types:
call
int (*)()

user_defined_types: struct xyz_event_node_t { int fd; int (*rdfunc)(int fd, void *arg); int (*wtfunc)(int fd, void *arg); void *arg; }


original_code:
int xyz_event_add(struct xyz_event_t *ev, int fd, int type, xyz_ev_func func, void *arg)
{
 int i;
 if(ev == ((void *)0) || fd < 0 || func == ((void *)0) || fd >= 1024) {
  return -1;
 }
    if(type != 1 && type != 2) {
        return -1;
    }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd == fd) {
   if(type == 1) {
    ev->array[i].rdfunc = func;
   } else if(type == 2) {
    ev->array[i].wtfunc = func;
   } else {
    return -1;
   }
   ev->array[i].arg = arg;
   return 0;
  }
 }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   if(type == 1) {
    ev->array[i].rdfunc = func;
   } else if(type == 2) {
    ev->array[i].wtfunc = func;
   } else {
    return -1;
   }
   ev->array[i].fd = fd;
   ev->array[i].arg = arg;
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
int xyz_event_add(struct xyz_event_t *ev, int fd, int type, int (*func)(int fd, void *arg), void *arg)
{
 int i;
 if(ev == ((void *)0) || fd < 0 || func == ((void *)0) || fd >= 1024) {
  return -1;
 }
    if(type != 1 && type != 2) {
        return -1;
    }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd == fd) {
   if(type == 1) {
    ev->array[i].rdfunc = func;
   } else if(type == 2) {
    ev->array[i].wtfunc = func;
   } else {
    return -1;
   }
   ev->array[i].arg = arg;
   return 0;
  }
 }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   if(type == 1) {
    ev->array[i].rdfunc = func;
   } else if(type == 2) {
    ev->array[i].wtfunc = func;
   } else {
    return -1;
   }
   ev->array[i].fd = fd;
   ev->array[i].arg = arg;
   return 0;
  }
 }
 return -1;
}

variable_types: fd int

variable_types: type int

variable_types:
func
int (*)(int fd, void *arg)

variable_types:
arg
void *


decompiled_code:
__int64 __fastcall xyz_event_del(__int64 a1, unsigned int a2, int a3)
{
_DWORD *v4; // rdx
int v5; // eax
__int64 v7; // rdx
bool v8; // zf

if ( !a1 || a2 > 0x3FF || (unsigned int)(a3 - 1) > 1 )
return 0xFFFFFFFFLL;
v4 = (_DWORD *)(a1 + 8);
v5 = 0;
while ( *v4 != a2 )
{
++v5;
v4 += 8;
if ( v5 == 8 )
return 0xFFFFFFFFLL;
}
v7 = a1 + 32LL * v5;
if ( a3 == 1 )
{
v8 = *(_QWORD *)(v7 + 24) == 0LL;
*(_QWORD *)(v7 + 16) = 0LL;
if ( !v8 )
return 0LL;
LABEL_12:
*(_DWORD *)(a1 + 32LL * v5 + 8) = -1;
return 0LL;
}
v8 = *(_QWORD *)(v7 + 16) == 0LL;
*(_QWORD *)(v7 + 24) = 0LL;
if ( v8 )
goto LABEL_12;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2, int a3)
{
_DWORD *v4; // rdx
int v5; // eax
__int64 v7; // rdx
bool v8; // zf

if ( !a1 || a2 > 0x3FF || (unsigned int)(a3 - 1) > 1 )
return 0xFFFFFFFFLL;
v4 = (_DWORD *)(a1 + 8);
v5 = 0;
while ( *v4 != a2 )
{
++v5;
v4 += 8;
if ( v5 == 8 )
return 0xFFFFFFFFLL;
}
v7 = a1 + 32LL * v5;
if ( a3 == 1 )
{
v8 = *(_QWORD *)(v7 + 24) == 0LL;
*(_QWORD *)(v7 + 16) = 0LL;
if ( !v8 )
return 0LL;
LABEL_12:
*(_DWORD *)(a1 + 32LL * v5 + 8) = -1;
return 0LL;
}
v8 = *(_QWORD *)(v7 + 16) == 0LL;
*(_QWORD *)(v7 + 24) = 0LL;
if ( v8 )
goto LABEL_12;
return 0LL;
}

original_code:
int xyz_event_del(struct xyz_event_t *ev, int fd, int type)
{
 int i;
    if(ev == ((void *)0) || fd < 0 || fd >= 1024) {
        return -1;
    }
    if(type != 1 && type != 2) {
        return -1;
    }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd == fd) {
   if(type == 1) {
    ev->array[i].rdfunc = ((void *)0);
   } else if(type == 2) {
    ev->array[i].wtfunc = ((void *)0);
   } else {
    return -1;
   }
   if(ev->array[i].rdfunc == ((void *)0) && ev->array[i].wtfunc == ((void *)0)) {
    ev->array[i].fd = -1;
   }
   return 0;
  }
 }
 return -1;
}


decompiled_code:
__int64 __fastcall xyz_event_run(__int64 a1)
{
__suseconds_t v1; // rax
int *v3; // rbx
int v4; // edi
unsigned int *v5; // rbp
int *v6; // rax
int v7; // ecx
int v8; // eax
unsigned int v9; // er12
int v10; // ecx
void (__fastcall *v11)(_QWORD, _QWORD); // r8
void (__fastcall *v12)(_QWORD, _QWORD); // rdx
struct timeval v14; // [rsp+0h] [rbp-138h] BYREF
fd_set readfds; // [rsp+10h] [rbp-128h] BYREF
fd_set writefds; // [rsp+90h] [rbp-A8h] BYREF

if ( !a1 )
return (unsigned int)-1;
v1 = *(int *)(a1 + 4);
v14.tv_sec = 0LL;
v14.tv_usec = v1;
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
v3 = (int *)(a1 + 8);
v4 = 0;
v5 = (unsigned int *)(a1 + 264);
v6 = v3;
do
{
v7 = *v6;
if ( *v6 >= 0 )
{
if ( *((_QWORD *)v6 + 1) )
readfds.fds_bits[v7 >> 6] |= 1LL << v7;
if ( *((_QWORD *)v6 + 2) )
writefds.fds_bits[v7 >> 6] |= 1LL << v7;
if ( v4 < v7 )
v4 = v7;
}
v6 += 8;
}
while ( v6 != (int *)v5 );
v8 = select(v4 + 1, &readfds, &writefds, 0LL, &v14);
v9 = v8;
if ( v8 )
{
if ( v8 == -1 )
{
v9 = -(*_errno_location() != 4);
}
else
{
do
{
v10 = *v3;
if ( *v3 >= 0 )
{
v11 = (void (__fastcall *)(_QWORD, _QWORD))*((_QWORD *)v3 + 1);
if ( v11 && (readfds.fds_bits[v10 >> 6] & (1LL << v10)) != 0 )
v11((unsigned int)v10, *((_QWORD *)v3 + 3));
v12 = (void (__fastcall *)(_QWORD, _QWORD))*((_QWORD *)v3 + 2);
if ( v12 && (writefds.fds_bits[*v3 / 64] & (1LL << (*v3 % 64))) != 0 )
v12((unsigned int)*v3, *((_QWORD *)v3 + 3));
}
v3 += 8;
}
while ( v3 != (int *)v5 );
}
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__suseconds_t v1; // rax
int *v3; // rbx
int v4; // edi
unsigned int *v5; // rbp
int *v6; // rax
int v7; // ecx
int v8; // eax
unsigned int v9; // er12
int v10; // ecx
void (__fastcall *v11)(_QWORD, _QWORD); // r8
void (__fastcall *v12)(_QWORD, _QWORD); // rdx
struct timeval v14; // [rsp+0h] [rbp-138h] BYREF
fd_set readfds; // [rsp+10h] [rbp-128h] BYREF
fd_set writefds; // [rsp+90h] [rbp-A8h] BYREF

if ( !a1 )
return (unsigned int)-1;
v1 = *(int *)(a1 + 4);
v14.tv_sec = 0LL;
v14.tv_usec = v1;
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
v3 = (int *)(a1 + 8);
v4 = 0;
v5 = (unsigned int *)(a1 + 264);
v6 = v3;
do
{
v7 = *v6;
if ( *v6 >= 0 )
{
if ( *((_QWORD *)v6 + 1) )
readfds.fds_bits[v7 >> 6] |= 1LL << v7;
if ( *((_QWORD *)v6 + 2) )
writefds.fds_bits[v7 >> 6] |= 1LL << v7;
if ( v4 < v7 )
v4 = v7;
}
v6 += 8;
}
while ( v6 != (int *)v5 );
v8 = select(v4 + 1, &readfds, &writefds, 0LL, &v14);
v9 = v8;
if ( v8 )
{
if ( v8 == -1 )
{
v9 = -(*_errno_location() != 4);
}
else
{
do
{
v10 = *v3;
if ( *v3 >= 0 )
{
v11 = (void (__fastcall *)(_QWORD, _QWORD))*((_QWORD *)v3 + 1);
if ( v11 && (readfds.fds_bits[v10 >> 6] & (1LL << v10)) != 0 )
v11((unsigned int)v10, *((_QWORD *)v3 + 3));
v12 = (void (__fastcall *)(_QWORD, _QWORD))*((_QWORD *)v3 + 2);
if ( v12 && (writefds.fds_bits[*v3 / 64] & (1LL << (*v3 % 64))) != 0 )
v12((unsigned int)*v3, *((_QWORD *)v3 + 3));
}
v3 += 8;
}
while ( v3 != (int *)v5 );
}
}
return v9;
}

original_code:
int xyz_event_run(struct xyz_event_t *ev)
{
 int num, i;
 struct timeval tv;
    fd_set rdset, wtset;
    int maxfd = 0;
    if(ev == ((void *)0)) {
        return -1;
    }
 tv.tv_sec = 0;
 tv.tv_usec = ev->usec;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rdset)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wtset)->__fds_bits)[0]) : "memory"); } while (0);
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   continue;
  }
  if(ev->array[i].rdfunc != ((void *)0)) {
   ((void) (((&rdset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))));
  }
  if(ev->array[i].wtfunc != ((void *)0)) {
   ((void) (((&wtset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))));
  }
  if(ev->array[i].fd > maxfd) {
   maxfd = ev->array[i].fd;
  }
 }
 num = select(maxfd+1, &rdset, &wtset, ((void *)0), &tv);
 if(num == 0) {
  return 0;
 } else if(num == -1) {
  if((*__errno_location ()) == 4) {
   return 0;
  } else {
   return -1;
  }
 }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   continue;
  }
  if(ev->array[i].rdfunc != ((void *)0) && ((((&rdset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            ev->array[i].rdfunc(ev->array[i].fd, ev->array[i].arg);
  }
  if(ev->array[i].wtfunc != ((void *)0) && ((((&wtset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            ev->array[i].wtfunc(ev->array[i].fd, ev->array[i].arg);
  }
 }
 return num;
}

canonical_original_code:
int xyz_event_run(struct xyz_event_t *ev)
{
 int num; int i;
 struct timeval tv;
    struct fd_set rdset; struct fd_set wtset;
    int maxfd = 0;
    if(ev == ((void *)0)) {
        return -1;
    }
 tv.tv_sec = 0;
 tv.tv_usec = ev->usec;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rdset)->__fds_bits)[0]) : "memory"); } while (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" (&((&wtset)->__fds_bits)[0]) : "memory"); } while (0);
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   continue;
  }
  if(ev->array[i].rdfunc != ((void *)0)) {
   ((void) (((&rdset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))));
  }
  if(ev->array[i].wtfunc != ((void *)0)) {
   ((void) (((&wtset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))));
  }
  if(ev->array[i].fd > maxfd) {
   maxfd = ev->array[i].fd;
  }
 }
 num = select(maxfd+1, &rdset, &wtset, ((void *)0), &tv);
 if(num == 0) {
  return 0;
 } else if(num == -1) {
  if((*__errno_location ()) == 4) {
   return 0;
  } else {
   return -1;
  }
 }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   continue;
  }
  if(ev->array[i].rdfunc != ((void *)0) && ((((&rdset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            ev->array[i].rdfunc(ev->array[i].fd, ev->array[i].arg);
  }
  if(ev->array[i].wtfunc != ((void *)0) && ((((&wtset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            ev->array[i].wtfunc(ev->array[i].fd, ev->array[i].arg);
  }
 }
 return num;
}

variable_types: num int

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

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

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

variable_types: maxfd int


decompiled_code:
void __fastcall xyz_event_destroy(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func6(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void xyz_event_destroy(struct xyz_event_t *ev)
{
 if(ev) {
  free(ev);
 }
 return;
}


decompiled_code:
void __fastcall xyz_event_loop(__int64 a1)
{
void (*v1)(void); // rax

if ( a1 )
{
*(_DWORD *)a1 = 0;
do
{
xyz_event_run(a1);
v1 = *(void (**)(void))(a1 + 264);
if ( v1 )
v1();
}
while ( !*(_DWORD *)a1 );
}
}

original_code:
void xyz_event_loop(struct xyz_event_t *ev)
{
    if(ev == ((void *)0)) {
        return;
    }
 ev->stop = 0;
 do {
  xyz_event_run(ev);
  if(ev->call) {
   ev->call();
  }
 } while(! ev->stop);
 return;
}


decompiled_code:
int __fastcall xyz_event_stat(__int64 a1)
{
unsigned int *v1; // rbx
int result; // eax
__int64 v3; // rsi
const void *v4; // rsi
const void *v5; // rsi

if ( a1 )
{
v1 = (unsigned int *)(a1 + 8);
result = puts("------ event stat ------");
do
{
v3 = *v1;
if ( (int)v3 >= 0 )
{
printf("fd:%d ", v3);
v4 = (const void *)*((_QWORD *)v1 + 1);
if ( v4 )
printf("read func : %p ", v4);
v5 = (const void *)*((_QWORD *)v1 + 2);
if ( v5 )
printf("write func : %p", v5);
result = putchar(10);
}
v1 += 8;
}
while ( v1 != (unsigned int *)(a1 + 264) );
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
unsigned int *v1; // rbx
int result; // eax
__int64 v3; // rsi
const void *v4; // rsi
const void *v5; // rsi

if ( a1 )
{
v1 = (unsigned int *)(a1 + 8);
result = puts("------ event stat ------");
do
{
v3 = *v1;
if ( (int)v3 >= 0 )
{
printf("fd:%d ", v3);
v4 = (const void *)*((_QWORD *)v1 + 1);
if ( v4 )
printf("read func : %p ", v4);
v5 = (const void *)*((_QWORD *)v1 + 2);
if ( v5 )
printf("write func : %p", v5);
result = putchar(10);
}
v1 += 8;
}
while ( v1 != (unsigned int *)(a1 + 264) );
}
return result;
}

original_code:
void xyz_event_stat(struct xyz_event_t *ev)
{
 int i;
    if(ev == ((void *)0)) {
        return;
    }
 printf("------ event stat ------\n");
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   continue;
  }
  printf("fd:%d    ", ev->array[i].fd);
  if(ev->array[i].rdfunc) {
   printf("read func : %p    ", ev->array[i].rdfunc);
  }
  if(ev->array[i].wtfunc) {
   printf("write func : %p", ev->array[i].wtfunc);
  }
  printf("\n");
 }
}

variable_types: i int


decompiled_code:
int __fastcall xyz_log_tag(const char *a1)
{
int result; // eax

if ( a1 )
result = snprintf(g_xyz_log_tag, 0x40uLL, "[%s]", a1);
return result;
}

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

if ( a1 )
result = snprintf(g_xyz_log_tag, 0x40uLL, "[%s]", a1);
return result;
}

original_code:
void xyz_log_tag(char *tag)
{
    if(tag) {
        snprintf(g_xyz_log_tag, sizeof(g_xyz_log_tag), "[%s]", tag);
    }
    return;
}

variable_types:
tag
char *


decompiled_code:
void __fastcall xyz_log_open(const char *a1, int a2, int a3)
{
g_xyz_log_level = a3;
openlog(a1, 1, a2);
}

canonical_decompiled_code:
void __fastcall func1(const char *a1, int a2, int a3)
{
g_xyz_log_level = a3;
openlog(a1, 1, a2);
}

original_code:
void xyz_log_open(const char* ident, int facility, int level)
{
 g_xyz_log_level = level;
 openlog(ident, 0x01, facility);
 return;
}

canonical_original_code:
void xyz_log_open(char *ident, int facility, int level)
{
 g_xyz_log_level = level;
 openlog(ident, 0x01, facility);
 return;
}

variable_types:
ident
char *

variable_types: facility int

variable_types: level int


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

if ( g_xyz_log_level >= a1 )
{
va_start(ap, a2);
vsyslog(a1, a2, ap);
}
}

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

if ( g_xyz_log_level >= a1 )
{
va_start(ap, a2);
vsyslog(a1, a2, ap);
}
}

original_code:
void xyz_log_write(int level, const char* format, ...)
{
 if(level > g_xyz_log_level) {
  return;
 }
 va_list args;
 __builtin_va_start(args,format);
 vsyslog(level, format, args);
 __builtin_va_end(args);
 return;
}

canonical_original_code:
void xyz_log_write(int level, char *format, ...)
{
 if(level > g_xyz_log_level) {
  return;
 }
 __builtin_va_list args;
 __builtin_va_start(args,format);
 vsyslog(level, format, args);
 __builtin_va_end(args);
 return;
}

variable_types:
format
char *


decompiled_code:
// attributes: thunk
void xyz_log_close(void)
{
closelog();
}

canonical_decompiled_code:
void func3(void)
{
closelog();
}

original_code:
void xyz_log_close(void)
{
 closelog();
 return;
}

canonical_original_code:
void xyz_log_close()
{
 closelog();
 return;
}


getprime

repo: albinoBandicoot/nsieve

decompiled_code:
__int64 __fastcall getprime(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx

v3 = a3;
__gmpz_urandomb();
while ( v3 != __gmpz_sizeinbase() )
__gmpz_urandomb();
return __gmpz_nextprime();
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx

v3 = a3;
__gmpz_urandomb();
while ( v3 != __gmpz_sizeinbase() )
__gmpz_urandomb();
return __gmpz_nextprime();
}

original_code:
void getprime (mpz_t res, gmp_randstate_t rand, int bits){
 __gmpz_urandomb (res, rand, bits);
 while (__gmpz_sizeinbase (res, 2) != bits){
  __gmpz_urandomb (res, rand, bits);
 }
 __gmpz_nextprime (res, res);
}

canonical_original_code:
void getprime(struct __mpz_struct res[1], struct __gmp_randstate_struct rand[1], int bits){
 __gmpz_urandomb (res, rand, bits);
 while (__gmpz_sizeinbase (res, 2) != bits){
  __gmpz_urandomb (res, rand, bits);
 }
 __gmpz_nextprime (res, res);
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types: struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } [1]

variable_types: bits int

user_defined_types: struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t _mp_alg; union { void *_mp_lc; } _mp_algdata; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char **v4; // rbp
const char *v5; // rdi
unsigned int v6; // eax
int result; // eax
char v8[16]; // [rsp+10h] [rbp-48h] BYREF
char v9[56]; // [rsp+20h] [rbp-38h] BYREF

if ( argc == 1 )
{
puts(
"! Error: expecting command line options (list of integers representing bit lengths of the primes to multiply together)");
result = 1;
}
else
{
__gmpz_inits();
__gmpz_set_ui();
__gmp_randinit_default();
if ( argc > 1 )
{
v3 = argv + 1;
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v5 = *v3++;
v6 = atoi(v5);
getprime(v8, v9, v6);
__gmpz_mul();
}
while ( v3 != v4 );
}
__gmpz_out_str();
putchar(10);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char **v4; // rbp
const char *v5; // rdi
unsigned int v6; // eax
int result; // eax
char v8[16]; // [rsp+10h] [rbp-48h] BYREF
char v9[56]; // [rsp+20h] [rbp-38h] BYREF

if ( argc == 1 )
{
puts(
"! Error: expecting command line options (list of integers representing bit lengths of the primes to multiply together)");
result = 1;
}
else
{
__gmpz_inits();
__gmpz_set_ui();
__gmp_randinit_default();
if ( argc > 1 )
{
v3 = argv + 1;
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v5 = *v3++;
v6 = atoi(v5);
func7(v8, v9, v6);
__gmpz_mul();
}
while ( v3 != v4 );
}
__gmpz_out_str();
putchar(10);
result = 0;
}
return result;
}

original_code:
int main (int argc, const char *argv[]){
 if (argc == 1){
  printf("! Error: expecting command line options (list of integers representing bit lengths of the primes to multiply together)\n");
  return 1;
 }
 mpz_t res, temp;
 __gmpz_inits (res, temp, ((void *)0));
 __gmpz_set_ui (res, 1);
 gmp_randstate_t rand;
 __gmp_randinit_default (rand);
 int arg =1;
 while (arg < argc){
  getprime (temp, rand, atoi(argv[arg]));
  __gmpz_mul (res, res, temp);
  arg++;
 }
 __gmpz_out_str (stdout, 10, res);
 printf("\n");
}

canonical_original_code:
int main(int argc, char *argv[]){
 if (argc == 1){
  printf("! Error: expecting command line options (list of integers representing bit lengths of the primes to multiply together)\n");
  return 1;
 }
 struct __mpz_struct res[1]; struct __mpz_struct temp[1];
 __gmpz_inits (res, temp, ((void *)0));
 __gmpz_set_ui (res, 1);
 struct __gmp_randstate_struct rand[1];
 __gmp_randinit_default (rand);
 int arg = 1;
 while (arg < argc){
  getprime (temp, rand, atoi(argv[arg]));
  __gmpz_mul (res, res, temp);
  arg++;
 }
 __gmpz_out_str (stdout, 10, res);
 printf("\n");
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct __gmp_randstate_struct { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } [1]

variable_types: arg int


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

for ( result = *(unsigned int **)(a2 + 16); result; ++*(_WORD *)(a1 + 2 * v3) )
{
v3 = *result;
result = (unsigned int *)*((_QWORD *)result + 1);
}
return result;
}

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

for ( result = *(unsigned int **)(a2 + 16); result; ++*(_WORD *)(a1 + 2 * v3) )
{
v3 = *result;
result = (unsigned int *)*((_QWORD *)result + 1);
}
return result;
}

original_code:
void add_factors_to_table (uint16_t *table, rel_t *rel){
 fl_entry_t *factor = rel->factors;
 while (factor != ((void *)0)){
  table[factor->fac] ++;
  factor = factor->next;
 }
}

canonical_original_code:
void add_factors_to_table(unsigned short *table, struct relation *rel){
 struct flentry *factor = rel->factors;
 while (factor != ((void *)0)){
  table[factor->fac] ++;
  factor = factor->next;
 }
}

variable_types:
table
unsigned short *

variable_types: struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *

user_defined_types: struct relation { struct poly_t *poly; int x; unsigned int cofactor; struct flentry *factors; }

user_defined_types: struct poly_t { struct poly_group_t *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; }

user_defined_types: struct poly_group_t { struct __mpz_struct a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; }


decompiled_code:
__int64 __fastcall construct_rhs(unsigned __int16 *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rdx
int v6; // ecx
__int64 v7; // rbx
__int64 v8; // rdx
__int64 v9; // rsi
__int64 result; // rax
_BYTE v11[56]; // [rsp+0h] [rbp-38h] BYREF

v4 = *a1;
if ( (v4 & 1) != 0 )
{
printf("Error: table[%d] is not even (=%d)\n", 0LL, v4);
result = 0LL;
}
else
{
if ( (v4 & 2) != 0 )
_gmpz_neg(a2);
_gmpz_init(v11);
v6 = *(_DWORD *)(a3 + 32);
if ( (unsigned int)(v6 + 1) <= 1 )
{
LABEL_10:
_gmpz_clear(v11);
result = 1LL;
}
else
{
v7 = 1LL;
while ( 1 )
{
v8 = a1[v7];
if ( (v8 & 1) != 0 )
break;
if ( (_WORD)v8 )
{
v9 = *(unsigned int *)(*(_QWORD *)(a3 + 48) + 4 * v7++ - 4);
_gmpz_ui_pow_ui(v11, v9, (unsigned __int16)v8 >> 1);
_gmpz_mul(a2, a2, v11);
_gmpz_mod(a2, a2, a3);
v6 = *(_DWORD *)(a3 + 32);
if ( v6 + 1 <= (unsigned int)v7 )
goto LABEL_10;
}
else if ( v6 + 1 <= (unsigned int)++v7 )
{
goto LABEL_10;
}
}
printf("Error: table[%d] is not even (=%d)\n", (unsigned int)v7, v8);
_gmpz_clear(v11);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rdx
int v6; // ecx
__int64 v7; // rbx
__int64 v8; // rdx
__int64 v9; // rsi
__int64 result; // rax
_BYTE v11[56]; // [rsp+0h] [rbp-38h] BYREF

v4 = *a1;
if ( (v4 & 1) != 0 )
{
printf("Error: table[%d] is not even (=%d)\n", 0LL, v4);
result = 0LL;
}
else
{
if ( (v4 & 2) != 0 )
_gmpz_neg(a2);
_gmpz_init(v11);
v6 = *(_DWORD *)(a3 + 32);
if ( (unsigned int)(v6 + 1) <= 1 )
{
LABEL_10:
_gmpz_clear(v11);
result = 1LL;
}
else
{
v7 = 1LL;
while ( 1 )
{
v8 = a1[v7];
if ( (v8 & 1) != 0 )
break;
if ( (_WORD)v8 )
{
v9 = *(unsigned int *)(*(_QWORD *)(a3 + 48) + 4 * v7++ - 4);
_gmpz_ui_pow_ui(v11, v9, (unsigned __int16)v8 >> 1);
_gmpz_mul(a2, a2, v11);
_gmpz_mod(a2, a2, a3);
v6 = *(_DWORD *)(a3 + 32);
if ( v6 + 1 <= (unsigned int)v7 )
goto LABEL_10;
}
else if ( v6 + 1 <= (unsigned int)++v7 )
{
goto LABEL_10;
}
}
printf("Error: table[%d] is not even (=%d)\n", (unsigned int)v7, v8);
_gmpz_clear(v11);
result = 0LL;
}
}
return result;
}

original_code:
int construct_rhs (uint16_t *table, mpz_t rhs, nsieve_t *ns){
 if (table[0] % 2 != 0){
  printf("Error: table[%d] is not even (=%d)\n", 0, table[0]);
  return 0;
 }
 if ((table[0]/2) % 2 == 1){
  __gmpz_neg (rhs, rhs);
 }
 mpz_t temp;
 __gmpz_init (temp);
 for (int i=1; i < ns->fb_len + 1; i++){
  if (table[i] % 2 != 0){
   printf("Error: table[%d] is not even (=%d)\n", i, table[i]);
   __gmpz_clear (temp);
   return 0;
  }
  if (table[i] > 0){
   __gmpz_ui_pow_ui (temp, ns->fb[i-1], table[i]/2);
   __gmpz_mul (rhs, rhs, temp);
   __gmpz_mod (rhs, rhs, ns->N);
  }
 }
 __gmpz_clear(temp);
 return 1;
}

canonical_original_code:
int construct_rhs(unsigned short *table, struct __mpz_struct rhs[1], struct nsieve_t *ns){
 if (table[0] % 2 != 0){
  printf("Error: table[%d] is not even (=%d)\n", 0, table[0]);
  return 0;
 }
 if ((table[0]/2) % 2 == 1){
  __gmpz_neg (rhs, rhs);
 }
 struct __mpz_struct temp[1];
 __gmpz_init (temp);
 for (int i = 1; i < ns->fb_len + 1; i++){
  if (table[i] % 2 != 0){
   printf("Error: table[%d] is not even (=%d)\n", i, table[i]);
   __gmpz_clear (temp);
   return 0;
  }
  if (table[i] > 0){
   __gmpz_ui_pow_ui (temp, ns->fb[i-1], table[i]/2);
   __gmpz_mul (rhs, rhs, temp);
   __gmpz_mod (rhs, rhs, ns->N);
  }
 }
 __gmpz_clear(temp);
 return 1;
}

variable_types: struct nsieve_t { struct __mpz_struct N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t { struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *r1; struct relation *r2; unsigned long *row; } *relns; unsigned int lp_bound; struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry { struct relation *rel; struct htentry *next; } **buckets; } partials; int nthreads; unsigned long *threads; 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; } lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t { long init_time; long sieve_time; long filter_time; long matsolve_time; long facdeduct_time; long total_time; } timing; } *

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }

user_defined_types: struct nsieve_t { struct __mpz_struct N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t *relns; unsigned int lp_bound; struct hashtable_t partials; int nthreads; unsigned long *threads; union pthread_mutex_t lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t timing; }

user_defined_types: struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry **buckets; }

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

user_defined_types: struct matrel_t { struct relation *r1; struct relation *r2; unsigned long *row; }

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:
__int64 __fastcall multiply_in_lhs(__int64 a1, int *a2, __int64 a3)
{
__int64 v5; // r13
_BYTE v7[56]; // [rsp+0h] [rbp-38h] BYREF

_gmpz_init(v7);
v5 = *(_QWORD *)(**(_QWORD **)a2 + 80LL);
_gmpz_set_si(v7, *(int *)(v5 + 8));
_gmpz_mul(v7, v7, *(_QWORD *)v5 + 8LL);
_gmpz_add(v7, v7, *(_QWORD *)v5 + 24LL);
_gmpz_mul(a1, a1, v7);
_gmpz_set_si(v7, a2[2]);
_gmpz_mul(v7, v7, *(_QWORD *)a2 + 8LL);
_gmpz_add(v7, v7, *(_QWORD *)a2 + 24LL);
_gmpz_mul(a1, a1, v7);
_gmpz_invert(v7, *(_QWORD *)v5 + 8LL, a3);
_gmpz_mul(a1, a1, v7);
_gmpz_mod(a1, a1, a3);
return _gmpz_clear(v7);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int *a2, __int64 a3)
{
__int64 v5; // r13
_BYTE v7[56]; // [rsp+0h] [rbp-38h] BYREF

_gmpz_init(v7);
v5 = *(_QWORD *)(**(_QWORD **)a2 + 80LL);
_gmpz_set_si(v7, *(int *)(v5 + 8));
_gmpz_mul(v7, v7, *(_QWORD *)v5 + 8LL);
_gmpz_add(v7, v7, *(_QWORD *)v5 + 24LL);
_gmpz_mul(a1, a1, v7);
_gmpz_set_si(v7, a2[2]);
_gmpz_mul(v7, v7, *(_QWORD *)a2 + 8LL);
_gmpz_add(v7, v7, *(_QWORD *)a2 + 24LL);
_gmpz_mul(a1, a1, v7);
_gmpz_invert(v7, *(_QWORD *)v5 + 8LL, a3);
_gmpz_mul(a1, a1, v7);
_gmpz_mod(a1, a1, a3);
return _gmpz_clear(v7);
}

original_code:
void multiply_in_lhs (mpz_t lhs, rel_t *rel, nsieve_t *ns) {
 mpz_t temp;
 __gmpz_init (temp);
 rel_t *victim = rel->poly->group->victim;
 __gmpz_set_si (temp, victim->x);
 __gmpz_mul (temp, temp, victim->poly->a);
 __gmpz_add (temp, temp, victim->poly->b);
 __gmpz_mul (lhs, lhs, temp);
 __gmpz_set_si (temp, rel->x);
 __gmpz_mul (temp, temp, rel->poly->a);
 __gmpz_add (temp, temp, rel->poly->b);
 __gmpz_mul (lhs, lhs, temp);
 __gmpz_invert (temp, victim->poly->a, ns->N);
 __gmpz_mul (lhs, lhs, temp);
 __gmpz_mod (lhs, lhs, ns->N);
 __gmpz_clear (temp);
}

canonical_original_code:
void multiply_in_lhs(struct __mpz_struct lhs[1], struct relation *rel, struct nsieve_t *ns) {
 struct __mpz_struct temp[1];
 __gmpz_init (temp);
 struct relation *victim = rel->poly->group->victim;
 __gmpz_set_si (temp, victim->x);
 __gmpz_mul (temp, temp, victim->poly->a);
 __gmpz_add (temp, temp, victim->poly->b);
 __gmpz_mul (lhs, lhs, temp);
 __gmpz_set_si (temp, rel->x);
 __gmpz_mul (temp, temp, rel->poly->a);
 __gmpz_add (temp, temp, rel->poly->b);
 __gmpz_mul (lhs, lhs, temp);
 __gmpz_invert (temp, victim->poly->a, ns->N);
 __gmpz_mul (lhs, lhs, temp);
 __gmpz_mod (lhs, lhs, ns->N);
 __gmpz_clear (temp);
}

variable_types: struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *

variable_types: struct nsieve_t { struct __mpz_struct N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t { struct relation *r1; struct relation *r2; unsigned long *row; } *relns; unsigned int lp_bound; struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry { struct relation *rel; struct htentry *next; } **buckets; } partials; int nthreads; unsigned long *threads; 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; } lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t { long init_time; long sieve_time; long filter_time; long matsolve_time; long facdeduct_time; long total_time; } timing; } *


original_code:
void solve_matrix (nsieve_t *ns){
 printf ("\nStarting gaussian elimination... \n");
 long start = clock();
 const int hmlen = (ns->rels_needed -1)/64 + 1;
 const int hmsize = ns->rels_needed;
 uint64_t *history[hmsize];
 uint32_t rmos[hmsize];
 for (int i=0; i < hmsize; i++){
  history[i] = (uint64_t *) calloc (hmlen, sizeof(uint64_t));
  flip_bit (history[i], i);
  rmos[i] = rightmost_1 (ns->relns[i].row, ns->fb_len);
 }
 uint64_t *expm[ns->rels_needed];
 for (int i=0; i < hmsize; i++){
  expm[i] = (uint64_t *) malloc (ns->row_len * sizeof(uint64_t));
  for (int j=0; j<ns->row_len; j++){
   expm[i][j] = ns->relns[i].row[j];
  }
 }
 const int expm_rows = ns->rels_needed;
 const int expm_cols = ns->fb_len + 1;
 for (int col = expm_cols-1; col >= 0; col --){
  if ((expm_cols - col) % 50 == 0){
   printf("Column %d of %d\r", expm_cols - col, expm_cols);
   fflush(stdout);
  }
  int pivot = 0;
  while (pivot < expm_rows && rmos[pivot] != col){
   pivot ++;
  }
  for (int yolanda = pivot + 1; yolanda < expm_rows; yolanda++){
   if (rmos[yolanda] == col){
    xor_row (ns->relns[yolanda].row, ns->relns[pivot].row, ns->row_len);
    xor_row (history[yolanda], history[pivot], hmlen);
    rmos[yolanda] = rightmost_1 (ns->relns[yolanda].row, col);
   }
  }
 }
 printf("\nMatrix solved; deducing factors...\n");
 ns->timing.matsolve_time = clock() - start;
 start = clock();
 __gmpz_divexact_ui (ns->N, ns->N, ns->multiplier);
 mpz_t ncopy, temp;
 __gmpz_init_set (ncopy, ns->N);
 __gmpz_inits (temp, ((void *)0));
 uint16_t factor_counts[ns->fb_len+1];
 for (int row = 0; row < expm_rows; row ++){
  if (is_zero_vec (ns->relns[row].row, ns->row_len)){
   memset (factor_counts, 0, 2 * (ns->fb_len + 1));
   int relct = 0;
   int partialct = 0;
   uint64_t check [ns->row_len];
   clear_row (check, ns);
   for (int i=0; i < hmsize; i++){
    if (get_bit (history[row], i) == 1){
     xor_row (check, expm[i], ns->row_len);
    }
   }
   if (is_zero_vec (check, ns->row_len)){
   } else {
    printf("Check FAILED for row = %d\n", row);
   }
   mpz_t lhs, rhs;
   __gmpz_inits (lhs, rhs, ((void *)0));
   __gmpz_set_ui(lhs, 1);
   __gmpz_set_ui(rhs, 1);
   for (int relnum = 0; relnum < hmsize; relnum ++){
    if (get_bit (history[row], relnum) == 1){
     matrel_t *m = &ns->relns[relnum];
     if (!rel_check (m->r1, ns)){
      printf ("relation failed check. [%s]\n", m->r2==((void *)0)?"full":"partial, r1");
     } else {
     }
     multiply_in_lhs (lhs, m->r1, ns);
     add_factors_to_table (factor_counts, m->r1);
     relct ++;
     if (m->r2 != ((void *)0)){
      partialct ++;
      if (m->r1->cofactor != m->r2->cofactor){
       printf("AAAH - cofactors disagree! (%d and %d)\n", m->r1->cofactor, m->r2->cofactor);
      }
      if (!rel_check (m->r2, ns)){
       printf ("relation failed check. [partial, r2]\n");
      }
      multiply_in_lhs (lhs, m->r2, ns);
      add_factors_to_table (factor_counts, m->r2);
      __gmpz_mul_ui (rhs, rhs, m->r1->cofactor);
     }
    }
   }
   int is_good = construct_rhs (factor_counts, rhs, ns);
   if ( ! is_good ) {
    printf ("construct_rhs check failed.\n");
    continue;
   }
   __gmpz_mod (lhs, lhs, ns->N);
   __gmpz_mod (rhs, rhs, ns->N);
   __gmpz_sub (temp, rhs, lhs);
   __gmpz_gcd (temp, temp, ncopy);
   __gmpz_abs (temp, temp);
   if ((__builtin_constant_p (1) && (1) == 0 ? ((temp)->_mp_size < 0 ? -1 : (temp)->_mp_size > 0) : __gmpz_cmp_ui (temp,1)) > 0){
    if (__gmpz_cmp (temp, ns->N) != 0){
     if (__gmpz_divisible_p(ncopy, temp)){
      if (__gmpz_probab_prime_p (temp, 10)){
       __gmpz_out_str (stdout, 10, temp);
       printf (" (prp)\n");
       __gmpz_divexact(ncopy, ncopy, temp);
       if (__gmpz_probab_prime_p (ncopy, 10)){
        __gmpz_out_str(stdout, 10, ncopy);
        printf (" (prp)\n");
        __gmpz_set_ui(ncopy, 1);
       }
       if ((__builtin_constant_p (1) && (1) == 0 ? ((ncopy)->_mp_size < 0 ? -1 : (ncopy)->_mp_size > 0) : __gmpz_cmp_ui (ncopy,1)) == 0){
        __gmpz_clears(lhs, rhs, temp, ncopy, ((void *)0));
        ns->timing.facdeduct_time = clock() - start;
        return;
       }
      }
     }
    }
   }
   __gmpz_clears(lhs, rhs, ((void *)0));
  }
 }
 if ((__builtin_constant_p (1) && (1) == 0 ? ((ncopy)->_mp_size < 0 ? -1 : (ncopy)->_mp_size > 0) : __gmpz_cmp_ui (ncopy,1)) != 0){
  __gmpz_out_str (stdout, 10, ncopy);
  if (__gmpz_probab_prime_p (ncopy, 10)){
   printf (" (prp)\n");
  } else {
   printf (" (c)\n");
  }
 }
 ns->timing.facdeduct_time = clock() - start;
}

canonical_original_code:
void solve_matrix(struct nsieve_t *ns){
 printf ("\nStarting gaussian elimination... \n");
 long start = clock();
 int hmlen = (ns->rels_needed -1)/64 + 1;
 int hmsize = ns->rels_needed;
 unsigned long *history[-1];
 unsigned int rmos[-1];
 for (int i = 0; i < hmsize; i++){
  history[i] = (unsigned long *) calloc (hmlen, sizeof(unsigned long));
  flip_bit (history[i], i);
  rmos[i] = rightmost_1 (ns->relns[i].row, ns->fb_len);
 }
 unsigned long *expm[-1];
 for (int i = 0; i < hmsize; i++){
  expm[i] = (unsigned long *) malloc (ns->row_len * sizeof(unsigned long));
  for (int j = 0; j<ns->row_len; j++){
   expm[i][j] = ns->relns[i].row[j];
  }
 }
 int expm_rows = ns->rels_needed;
 int expm_cols = ns->fb_len + 1;
 for (int col = expm_cols-1; col >= 0; col --){
  if ((expm_cols - col) % 50 == 0){
   printf("Column %d of %d\r", expm_cols - col, expm_cols);
   fflush(stdout);
  }
  int pivot = 0;
  while (pivot < expm_rows && rmos[pivot] != col){
   pivot ++;
  }
  for (int yolanda = pivot + 1; yolanda < expm_rows; yolanda++){
   if (rmos[yolanda] == col){
    xor_row (ns->relns[yolanda].row, ns->relns[pivot].row, ns->row_len);
    xor_row (history[yolanda], history[pivot], hmlen);
    rmos[yolanda] = rightmost_1 (ns->relns[yolanda].row, col);
   }
  }
 }
 printf("\nMatrix solved; deducing factors...\n");
 ns->timing.matsolve_time = clock() - start;
 start = clock();
 __gmpz_divexact_ui (ns->N, ns->N, ns->multiplier);
 struct __mpz_struct ncopy[1]; struct __mpz_struct temp[1];
 __gmpz_init_set (ncopy, ns->N);
 __gmpz_inits (temp, ((void *)0));
 unsigned short factor_counts[-1];
 for (int row = 0; row < expm_rows; row ++){
  if (is_zero_vec (ns->relns[row].row, ns->row_len)){
   memset (factor_counts, 0, 2 * (ns->fb_len + 1));
   int relct = 0;
   int partialct = 0;
   unsigned long check[-1];
   clear_row (check, ns);
   for (int i = 0; i < hmsize; i++){
    if (get_bit (history[row], i) == 1){
     xor_row (check, expm[i], ns->row_len);
    }
   }
   if (is_zero_vec (check, ns->row_len)){
   } else {
    printf("Check FAILED for row = %d\n", row);
   }
   struct __mpz_struct lhs[1]; struct __mpz_struct rhs[1];
   __gmpz_inits (lhs, rhs, ((void *)0));
   __gmpz_set_ui(lhs, 1);
   __gmpz_set_ui(rhs, 1);
   for (int relnum = 0; relnum < hmsize; relnum ++){
    if (get_bit (history[row], relnum) == 1){
     struct matrel_t *m = &ns->relns[relnum];
     if (!rel_check (m->r1, ns)){
      printf ("relation failed check. [%s]\n", m->r2==((void *)0)?"full":"partial, r1");
     } else {
     }
     multiply_in_lhs (lhs, m->r1, ns);
     add_factors_to_table (factor_counts, m->r1);
     relct ++;
     if (m->r2 != ((void *)0)){
      partialct ++;
      if (m->r1->cofactor != m->r2->cofactor){
       printf("AAAH - cofactors disagree! (%d and %d)\n", m->r1->cofactor, m->r2->cofactor);
      }
      if (!rel_check (m->r2, ns)){
       printf ("relation failed check. [partial, r2]\n");
      }
      multiply_in_lhs (lhs, m->r2, ns);
      add_factors_to_table (factor_counts, m->r2);
      __gmpz_mul_ui (rhs, rhs, m->r1->cofactor);
     }
    }
   }
   int is_good = construct_rhs (factor_counts, rhs, ns);
   if ( ! is_good ) {
    printf ("construct_rhs check failed.\n");
    continue;
   }
   __gmpz_mod (lhs, lhs, ns->N);
   __gmpz_mod (rhs, rhs, ns->N);
   __gmpz_sub (temp, rhs, lhs);
   __gmpz_gcd (temp, temp, ncopy);
   __gmpz_abs (temp, temp);
   if ((__builtin_constant_p (1) && (1) == 0 ? ((temp)->_mp_size < 0 ? -1 : (temp)->_mp_size > 0) : __gmpz_cmp_ui (temp,1)) > 0){
    if (__gmpz_cmp (temp, ns->N) != 0){
     if (__gmpz_divisible_p(ncopy, temp)){
      if (__gmpz_probab_prime_p (temp, 10)){
       __gmpz_out_str (stdout, 10, temp);
       printf (" (prp)\n");
       __gmpz_divexact(ncopy, ncopy, temp);
       if (__gmpz_probab_prime_p (ncopy, 10)){
        __gmpz_out_str(stdout, 10, ncopy);
        printf (" (prp)\n");
        __gmpz_set_ui(ncopy, 1);
       }
       if ((__builtin_constant_p (1) && (1) == 0 ? ((ncopy)->_mp_size < 0 ? -1 : (ncopy)->_mp_size > 0) : __gmpz_cmp_ui (ncopy,1)) == 0){
        __gmpz_clears(lhs, rhs, temp, ncopy, ((void *)0));
        ns->timing.facdeduct_time = clock() - start;
        return;
       }
      }
     }
    }
   }
   __gmpz_clears(lhs, rhs, ((void *)0));
  }
 }
 if ((__builtin_constant_p (1) && (1) == 0 ? ((ncopy)->_mp_size < 0 ? -1 : (ncopy)->_mp_size > 0) : __gmpz_cmp_ui (ncopy,1)) != 0){
  __gmpz_out_str (stdout, 10, ncopy);
  if (__gmpz_probab_prime_p (ncopy, 10)){
   printf (" (prp)\n");
  } else {
   printf (" (c)\n");
  }
 }
 ns->timing.facdeduct_time = clock() - start;
}

variable_types: struct nsieve_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t { struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *r1; struct relation *r2; unsigned long *row; } *relns; unsigned int lp_bound; struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry { struct relation *rel; struct htentry *next; } **buckets; } partials; int nthreads; unsigned long *threads; 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; } lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t { long init_time; long sieve_time; long filter_time; long matsolve_time; long facdeduct_time; long total_time; } timing; } *

variable_types: start long

variable_types: hmlen int

variable_types: hmsize int

variable_types:
history
unsigned long *[-1]

variable_types:
rmos
unsigned int [-1]

variable_types: i int

variable_types:
expm
unsigned long *[-1]

variable_types: j int

variable_types: col int

variable_types: pivot int

variable_types: yolanda int

variable_types: row int

variable_types: relct int

variable_types: partialct int

variable_types:
check
unsigned long [-1]

variable_types: relnum int

variable_types: struct matrel_t { struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *r1; struct relation *r2; unsigned long *row; } *


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

v2 = *(unsigned int *)(a2 + 84);
if ( (_DWORD)v2 )
result = memset(a1, 0, 8 * v2);
return result;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1, __int64 a2)
{
__int64 v2; // rdx
void *result; // rax

v2 = *(unsigned int *)(a2 + 84);
if ( (_DWORD)v2 )
result = memset(a1, 0, 8 * v2);
return result;
}

original_code:
void clear_row (uint64_t *m, nsieve_t *ns){
 for (int i=0; i < ns->row_len; i++){
  m[i] = 0;
 }
}

canonical_original_code:
void clear_row(unsigned long *m, struct nsieve_t *ns){
 for (int i = 0; i < ns->row_len; i++){
  m[i] = 0;
 }
}

variable_types:
m
unsigned long *

variable_types: struct nsieve_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t { struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *r1; struct relation *r2; unsigned long *row; } *relns; unsigned int lp_bound; struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry { struct relation *rel; struct htentry *next; } **buckets; } partials; int nthreads; unsigned long *threads; 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; } lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t { long init_time; long sieve_time; long filter_time; long matsolve_time; long facdeduct_time; long total_time; } timing; } *


original_code:
int get_bit (uint64_t *m, int pos){
 int block = pos/64;
 uint64_t mask = 1ull << (pos % 64);
 return (m[block] & mask) > 0 ? 1 : 0;
}

canonical_original_code:
int get_bit(unsigned long *m, int pos){
 int block = pos/64;
 unsigned long mask = 1ull << (pos % 64);
 return (m[block] & mask) > 0 ? 1 : 0;
}

variable_types: pos int

variable_types: block int

variable_types:
mask
unsigned long


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

result = a2 / 64;
*(_QWORD *)(a1 + 8 * result) ^= 1LL << (a2 % 64);
return result;
}

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

result = a2 / 64;
*(_QWORD *)(a1 + 8 * result) ^= 1LL << (a2 % 64);
return result;
}

original_code:
void flip_bit (uint64_t *m, int pos){
 int block = pos/64;
 uint64_t mask = 1ull << (pos % 64);
 m[block] = m[block] ^ mask;
}

canonical_original_code:
void flip_bit(unsigned long *m, int pos){
 int block = pos/64;
 unsigned long mask = 1ull << (pos % 64);
 m[block] = m[block] ^ mask;
}


original_code:
void xor_row (uint64_t *res, uint64_t *op, int len){
 for (int i=0; i<len; i++){
  res[i] = res[i] ^ op[i];
 }
}

canonical_original_code:
void xor_row(unsigned long *res, unsigned long *op, int len){
 for (int i = 0; i<len; i++){
  res[i] = res[i] ^ op[i];
 }
}

variable_types:
res
unsigned long *

variable_types:
op
unsigned long *

variable_types: len int

variable_types: i int


original_code:
int rightmost_1 (uint64_t *m, int max_i){
 int block = max_i / 64;
 while (block > 0 && m[block] == 0) block--;
 if (m[block] == 0) return -1;
 uint64_t x = m[block];
 int pos = 0;
 while ((x & (1ull << 63)) == 0){
  pos++;
  x = x << 1;
 }
 int res = (63 - pos) + 64 * block;
 return res;
}

canonical_original_code:
int rightmost_1(unsigned long *m, int max_i){
 int block = max_i / 64;
 while (block > 0 && m[block] == 0) block--;
 if (m[block] == 0) return -1;
 unsigned long x = m[block];
 int pos = 0;
 while ((x & (1ull << 63)) == 0){
  pos++;
  x = x << 1;
 }
 int res = (63 - pos) + 64 * block;
 return res;
}

variable_types:
x
unsigned long

variable_types: res int


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

if ( a2 <= 0 )
return 1LL;
v2 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
while ( !*a1 )
{
if ( ++a1 == (_QWORD *)v2 )
return 1LL;
}
return 0LL;
}

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

if ( a2 <= 0 )
return 1LL;
v2 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
while ( !*a1 )
{
if ( ++a1 == (_QWORD *)v2 )
return 1LL;
}
return 0LL;
}

original_code:
int is_zero_vec (uint64_t *m, int len){
 for (int i=0; i<len; i++){
  if (m[i] != 0) return 0;
 }
 return 1;
}

canonical_original_code:
int is_zero_vec(unsigned long *m, int len){
 for (int i = 0; i<len; i++){
  if (m[i] != 0) return 0;
 }
 return 1;
}


decompiled_code:
int __fastcall print_row(__int64 a1, int a2)
{
int v2; // ebx

v2 = 0;
if ( a2 > 0 )
{
do
{
while ( !get_bit(a1, v2) )
{
++v2;
fputc(48, stderr);
if ( a2 == v2 )
return fputc(10, stderr);
}
++v2;
fputc(49, stderr);
}
while ( a2 != v2 );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, int a2)
{
int v2; // ebx

v2 = 0;
if ( a2 > 0 )
{
do
{
while ( !func1(a1, v2) )
{
++v2;
fputc(48, stderr);
if ( a2 == v2 )
return fputc(10, stderr);
}
++v2;
fputc(49, stderr);
}
while ( a2 != v2 );
}
return fputc(10, stderr);
}

original_code:
void print_row (uint64_t *m, int max_i){
 for (int i=0; i<max_i; i++){
  if (get_bit(m, i) == 1){
   fprintf(stderr, "1");
  } else {
   fprintf(stderr, "0");
  }
 }
 fprintf(stderr, "\n");
}

canonical_original_code:
void print_row(unsigned long *m, int max_i){
 for (int i = 0; i<max_i; i++){
  if (get_bit(m, i) == 1){
   fprintf(stderr, "1");
  } else {
   fprintf(stderr, "0");
  }
 }
 fprintf(stderr, "\n");
}


decompiled_code:
void *__fastcall ht_init(__int64 a1)
{
void *result; // rax

result = calloc(0x156BuLL, 8uLL);
*(_QWORD *)(a1 + 104) = 5483LL;
*(_QWORD *)(a1 + 112) = result;
return result;
}

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

result = calloc(0x156BuLL, 8uLL);
*(_QWORD *)(a1 + 104) = 5483LL;
*(_QWORD *)(a1 + 112) = result;
return result;
}

original_code:
void ht_init (nsieve_t *ns){
 ns->partials.nbuckets = 5483;
 ns->partials.buckets = (ht_entry_t **)(calloc(5483, sizeof(ht_entry_t*)));
 ns->partials.nentries = 0;
}

canonical_original_code:
void ht_init(struct nsieve_t *ns){
 ns->partials.nbuckets = 5483;
 ns->partials.buckets = (struct htentry **)(calloc(5483, sizeof(struct htentry *)));
 ns->partials.nentries = 0;
}

user_defined_types: struct htentry { struct relation *rel; struct htentry *next; }

user_defined_types: struct time_data_t { long init_time; long sieve_time; long filter_time; long matsolve_time; long facdeduct_time; long total_time; }

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

user_defined_types: struct flentry { unsigned int fac; struct flentry *next; }


decompiled_code:
__int64 __fastcall hash_partial(int a1)
{
return (unsigned int)(263633281 * a1 + 135666227);
}

original_code:
uint32_t hash_partial (uint32_t cofactor){
 return (cofactor * 263633281) + 135666227;
}

canonical_original_code:
unsigned int hash_partial(unsigned int cofactor){
 return (cofactor * 263633281) + 135666227;
}

variable_types:
cofactor
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall ht_count_bucket(_QWORD *a1)
{
__int64 result; // rax
int v2; // ecx
int v3; // edx
int v4; // eax
int v5; // esi

result = 0LL;
if ( a1 )
{
v2 = 0;
v3 = *(_DWORD *)(*a1 + 12LL);
v4 = 0;
v5 = v3;
while ( 1 )
{
while ( v3 != v5 )
{
v2 = v2 + v4 - 1;
v5 = v3;
v4 = 0;
}
a1 = (_QWORD *)a1[1];
++v4;
if ( !a1 )
break;
v3 = *(_DWORD *)(*a1 + 12LL);
}
result = (unsigned int)(v2 + v4 - 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
__int64 result; // rax
int v2; // ecx
int v3; // edx
int v4; // eax
int v5; // esi

result = 0LL;
if ( a1 )
{
v2 = 0;
v3 = *(_DWORD *)(*a1 + 12LL);
v4 = 0;
v5 = v3;
while ( 1 )
{
while ( v3 != v5 )
{
v2 = v2 + v4 - 1;
v5 = v3;
v4 = 0;
}
a1 = (_QWORD *)a1[1];
++v4;
if ( !a1 )
break;
v3 = *(_DWORD *)(*a1 + 12LL);
}
result = (unsigned int)(v2 + v4 - 1);
}
return result;
}

original_code:
uint32_t ht_count_bucket (ht_entry_t *h){
 if (h == ((void *)0)) return 0;
 uint32_t res = 0;
 uint32_t ct = 0;
 uint32_t curr_cofactor = h->rel->cofactor;
 while (1){
  while (h != ((void *)0) && h->rel->cofactor == curr_cofactor){
   ct ++;
   h = h->next;
  }
  res += ct - 1;
  if (h == ((void *)0)){
   return res;
  }
  curr_cofactor = h->rel->cofactor;
  ct = 0;
 }
 return 0;
}

canonical_original_code:
unsigned int ht_count_bucket(struct htentry *h){
 if (h == ((void *)0)) return 0;
 unsigned int res = 0;
 unsigned int ct = 0;
 unsigned int curr_cofactor = h->rel->cofactor;
 while (1){
  while (h != ((void *)0) && h->rel->cofactor == curr_cofactor){
   ct ++;
   h = h->next;
  }
  res += ct - 1;
  if (h == ((void *)0)){
   return res;
  }
  curr_cofactor = h->rel->cofactor;
  ct = 0;
 }
 return 0;
}

variable_types: struct htentry { struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *rel; struct htentry *next; } *

variable_types:
res
unsigned int

variable_types:
ct
unsigned int


decompiled_code:
__int64 __fastcall ht_count(unsigned int *a1)
{
unsigned int v1; // er9
_QWORD **v2; // rax
int v3; // eax
int v4; // er9
_QWORD **v5; // r8
_QWORD **v6; // r10

v1 = *a1;
if ( *a1 )
{
v2 = (_QWORD **)*((_QWORD *)a1 + 1);
do
{
v3 = ht_count_bucket(*v2);
v1 = v3 + v4;
v2 = v5;
}
while ( v5 != v6 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1)
{
unsigned int v1; // er9
_QWORD **v2; // rax
int v3; // eax
int v4; // er9
_QWORD **v5; // r8
_QWORD **v6; // r10

v1 = *a1;
if ( *a1 )
{
v2 = (_QWORD **)*((_QWORD *)a1 + 1);
do
{
v3 = func9(*v2);
v1 = v3 + v4;
v2 = v5;
}
while ( v5 != v6 );
}
return v1;
}

original_code:
uint32_t ht_count (hashtable_t *ht){
 uint32_t res = 0;
 for (int i=0; i < ht->nbuckets; i++){
  res += ht_count_bucket (ht->buckets[i]);
 }
 return res;
}

canonical_original_code:
unsigned int ht_count(struct hashtable_t *ht){
 unsigned int res = 0;
 for (int i = 0; i < ht->nbuckets; i++){
  res += ht_count_bucket (ht->buckets[i]);
 }
 return res;
}

variable_types: struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry { struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *rel; struct htentry *next; } **buckets; } *


decompiled_code:
__int64 __fastcall find_root(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned __int64 v3; // r13
unsigned int v4; // er15
unsigned int v5; // er12
unsigned int v6; // er13
unsigned int v7; // ebx
int v8; // ebp
int v9; // ebx
int v10; // edx
__int64 v12; // r12
char v13[16]; // [rsp+0h] [rbp-98h] BYREF
char v14[16]; // [rsp+10h] [rbp-88h] BYREF
char v15[16]; // [rsp+20h] [rbp-78h] BYREF
char v16[16]; // [rsp+30h] [rbp-68h] BYREF
char v17[16]; // [rsp+40h] [rbp-58h] BYREF
char v18[72]; // [rsp+50h] [rbp-48h] BYREF

_gmpz_inits(v13, v14, v15, 0LL);
_gmpz_fdiv_r_ui(v14, a1, a2);
v2 = _gmpz_get_ui(v14);
LODWORD(v3) = v2;
if ( a2 != 2 )
{
v4 = v2;
v5 = a2;
if ( (a2 & 3) == 3 )
{
_gmpz_set_ui(v13, a2);
_gmpz_powm_ui(v14, v14, (a2 >> 2) + 1, v13);
LODWORD(v3) = _gmpz_get_ui(v14);
}
else if ( (a2 & 7) == 5 )
{
_gmpz_set_ui(v13, a2);
v12 = (a2 >> 3) + 1;
_gmpz_powm_ui(v15, v14, 2 * (a2 >> 3) + 1, v13);
if ( (unsigned int)_gmpz_cmp_ui(v15, 1LL) )
{
_gmpz_mul_ui(v14, v14, 4LL);
_gmpz_powm_ui(v15, v14, v12, v13);
if ( (unsigned int)_gmpz_divisible_ui_p(v15, 2LL) )
LODWORD(v3) = (unsigned __int64)_gmpz_get_ui(v15) >> 1;
else
v3 = ((unsigned __int64)a2 + _gmpz_get_ui(v15)) >> 1;
}
else
{
_gmpz_powm_ui(v15, v14, v12, v13);
LODWORD(v3) = _gmpz_get_ui(v15);
}
_gmpz_clears(v13, v14, v15, 0LL);
}
else
{
v6 = a2 - 1;
v7 = a2 - 1;
v8 = ((_BYTE)a2 - 1) & 1;
if ( (((_BYTE)a2 - 1) & 1) != 0 )
{
v8 = 0;
}
else
{
do
{
v7 >>= 1;
++v8;
}
while ( (v7 & 1) == 0 );
v5 = v7 + 1;
}
_gmpz_set_ui(v13, a2);
_gmpz_set_ui(v15, 2LL);
_gmpz_powm_ui(v14, v15, v6 >> 1, v13);
while ( (unsigned int)_gmpz_cmp_ui(v14, v6) )
{
_gmpz_add_ui(v15, v15, 1LL);
_gmpz_powm_ui(v14, v15, v6 >> 1, v13);
}
_gmpz_inits(v16, v17, v18, 0LL);
_gmpz_set_ui(v14, v4);
_gmpz_powm_ui(v16, v14, v5 >> 1, v13);
_gmpz_powm_ui(v17, v14, v7, v13);
_gmpz_powm_ui(v18, v15, v7, v13);
while ( 1 )
{
v9 = 0;
_gmpz_set(v14, v17);
while ( (unsigned int)_gmpz_cmp_ui(v14, 1LL) )
{
++v9;
_gmpz_mul(v14, v14);
_gmpz_mod(v14, v14, v13);
}
if ( !v9 )
break;
v10 = v8 - 1;
v8 = v9;
_gmpz_ui_pow_ui(v14, 2LL, (unsigned int)(v10 - v9));
_gmpz_powm(v14, v18, v14, v13);
_gmpz_mul(v16, v16);
_gmpz_mod(v16, v16, v13);
_gmpz_mul(v14, v14);
_gmpz_mod(v14, v14, v13);
_gmpz_mul(v17, v17);
_gmpz_mod(v17, v17, v13);
_gmpz_set(v18, v14);
}
LODWORD(v3) = _gmpz_get_ui(v16);
_gmpz_clears(v16, v17, v18, v13);
}
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned __int64 v3; // r13
unsigned int v4; // er15
unsigned int v5; // er12
unsigned int v6; // er13
unsigned int v7; // ebx
int v8; // ebp
int v9; // ebx
int v10; // edx
__int64 v12; // r12
char v13[16]; // [rsp+0h] [rbp-98h] BYREF
char v14[16]; // [rsp+10h] [rbp-88h] BYREF
char v15[16]; // [rsp+20h] [rbp-78h] BYREF
char v16[16]; // [rsp+30h] [rbp-68h] BYREF
char v17[16]; // [rsp+40h] [rbp-58h] BYREF
char v18[72]; // [rsp+50h] [rbp-48h] BYREF

_gmpz_inits(v13, v14, v15, 0LL);
_gmpz_fdiv_r_ui(v14, a1, a2);
v2 = _gmpz_get_ui(v14);
LODWORD(v3) = v2;
if ( a2 != 2 )
{
v4 = v2;
v5 = a2;
if ( (a2 & 3) == 3 )
{
_gmpz_set_ui(v13, a2);
_gmpz_powm_ui(v14, v14, (a2 >> 2) + 1, v13);
LODWORD(v3) = _gmpz_get_ui(v14);
}
else if ( (a2 & 7) == 5 )
{
_gmpz_set_ui(v13, a2);
v12 = (a2 >> 3) + 1;
_gmpz_powm_ui(v15, v14, 2 * (a2 >> 3) + 1, v13);
if ( (unsigned int)_gmpz_cmp_ui(v15, 1LL) )
{
_gmpz_mul_ui(v14, v14, 4LL);
_gmpz_powm_ui(v15, v14, v12, v13);
if ( (unsigned int)_gmpz_divisible_ui_p(v15, 2LL) )
LODWORD(v3) = (unsigned __int64)_gmpz_get_ui(v15) >> 1;
else
v3 = ((unsigned __int64)a2 + _gmpz_get_ui(v15)) >> 1;
}
else
{
_gmpz_powm_ui(v15, v14, v12, v13);
LODWORD(v3) = _gmpz_get_ui(v15);
}
_gmpz_clears(v13, v14, v15, 0LL);
}
else
{
v6 = a2 - 1;
v7 = a2 - 1;
v8 = ((_BYTE)a2 - 1) & 1;
if ( (((_BYTE)a2 - 1) & 1) != 0 )
{
v8 = 0;
}
else
{
do
{
v7 >>= 1;
++v8;
}
while ( (v7 & 1) == 0 );
v5 = v7 + 1;
}
_gmpz_set_ui(v13, a2);
_gmpz_set_ui(v15, 2LL);
_gmpz_powm_ui(v14, v15, v6 >> 1, v13);
while ( (unsigned int)_gmpz_cmp_ui(v14, v6) )
{
_gmpz_add_ui(v15, v15, 1LL);
_gmpz_powm_ui(v14, v15, v6 >> 1, v13);
}
_gmpz_inits(v16, v17, v18, 0LL);
_gmpz_set_ui(v14, v4);
_gmpz_powm_ui(v16, v14, v5 >> 1, v13);
_gmpz_powm_ui(v17, v14, v7, v13);
_gmpz_powm_ui(v18, v15, v7, v13);
while ( 1 )
{
v9 = 0;
_gmpz_set(v14, v17);
while ( (unsigned int)_gmpz_cmp_ui(v14, 1LL) )
{
++v9;
_gmpz_mul(v14, v14);
_gmpz_mod(v14, v14, v13);
}
if ( !v9 )
break;
v10 = v8 - 1;
v8 = v9;
_gmpz_ui_pow_ui(v14, 2LL, (unsigned int)(v10 - v9));
_gmpz_powm(v14, v18, v14, v13);
_gmpz_mul(v16, v16);
_gmpz_mod(v16, v16, v13);
_gmpz_mul(v14, v14);
_gmpz_mod(v14, v14, v13);
_gmpz_mul(v17, v17);
_gmpz_mod(v17, v17, v13);
_gmpz_set(v18, v14);
}
LODWORD(v3) = _gmpz_get_ui(v16);
_gmpz_clears(v16, v17, v18, v13);
}
}
return (unsigned int)v3;
}

original_code:
uint32_t find_root (mpz_t k, uint32_t p){
 mpz_t pol, temp, temp2;
 __gmpz_inits (pol, temp, temp2, ((void *)0));
 __gmpz_fdiv_r_ui (temp, k, p);
 uint32_t a = __gmpz_get_ui (temp);
 if (p == 2){
  return a;
 }
 uint32_t res = 0;
 if (p % 4 == 3){
  uint32_t m = p/4;
  __gmpz_set_ui(pol, p);
  __gmpz_powm_ui (temp, temp, m+1, pol);
  return __gmpz_get_ui (temp);
 } else if (p % 8 == 5){
  uint32_t m = p/8;
  __gmpz_set_ui (pol, p);
  __gmpz_powm_ui (temp2, temp, 2*m+1, pol);
  if ((__builtin_constant_p (1) && (1) == 0 ? ((temp2)->_mp_size < 0 ? -1 : (temp2)->_mp_size > 0) : __gmpz_cmp_ui (temp2,1)) == 0){
   __gmpz_powm_ui(temp2, temp, m+1, pol);
   res = __gmpz_get_ui (temp2);
   __gmpz_clears (pol, temp, temp2, ((void *)0));
   return res;
  } else {
   __gmpz_mul_ui(temp, temp, 4);
   __gmpz_powm_ui(temp2, temp, m+1, pol);
   if (__gmpz_divisible_ui_p(temp2, 2)){
    res = __gmpz_get_ui(temp2)/2;
    __gmpz_clears (pol, temp, temp2, ((void *)0));
    return res;
   } else {
    res = (__gmpz_get_ui(temp2)+p)/2;
    __gmpz_clears (pol, temp, temp2, ((void *)0));
    return res;
   }
  }
 }
 uint32_t s = p-1;
 uint32_t e = 0;
 while (s % 2 == 0){
  s /= 2;
  e ++;
 }
 __gmpz_set_ui (pol, p);
 __gmpz_set_ui(temp2, 2);
 __gmpz_powm_ui (temp, temp2, (p-1)/2, pol);
 while ((__builtin_constant_p (p-1) && (p-1) == 0 ? ((temp)->_mp_size < 0 ? -1 : (temp)->_mp_size > 0) : __gmpz_cmp_ui (temp,p-1)) != 0){
  __gmpz_add_ui (temp2, temp2, 1);
  __gmpz_powm_ui (temp, temp2, (p-1)/2, pol);
 }
 mpz_t x, b, g;
 __gmpz_inits (x, b, g, ((void *)0));
 __gmpz_set_ui (temp, a);
 __gmpz_powm_ui (x, temp, (s+1)/2, pol);
 __gmpz_powm_ui (b, temp, s, pol);
 __gmpz_powm_ui (g, temp2, s, pol);
 uint32_t r = e;
 uint32_t m;
tshanks_mainloop:
 m = 0;
 __gmpz_set (temp, b);
 while ((__builtin_constant_p (1) && (1) == 0 ? ((temp)->_mp_size < 0 ? -1 : (temp)->_mp_size > 0) : __gmpz_cmp_ui (temp,1)) != 0){
  __gmpz_mul (temp, temp, temp);
  __gmpz_mod (temp, temp, pol);
  m++;
 }
 if (m == 0){
  uint32_t res = __gmpz_get_ui (x);
  __gmpz_clears (x, b, g, pol, temp, temp2, ((void *)0));
  return res;
 } else {
  __gmpz_ui_pow_ui (temp, 2, r-m-1);
  __gmpz_powm (temp, g, temp, pol);
  __gmpz_mul (x, x, temp);
  __gmpz_mod (x, x, pol);
  __gmpz_mul (temp, temp, temp);
  __gmpz_mod (temp, temp, pol);
  __gmpz_mul (b, b, temp);
  __gmpz_mod (b, b, pol);
  __gmpz_set (g, temp);
  r = m;
 }
 goto tshanks_mainloop;
 __gmpz_clears (pol, temp, temp2, ((void *)0));
 uint32_t t = 0;
 while ( t*t % p != a && t < p/2 + 1 ){
  t ++;
 }
 if (t*t%p == a) return t;
 return -1;
}

canonical_original_code:
unsigned int find_root(struct __mpz_struct k[1], unsigned int p){
 struct __mpz_struct pol[1]; struct __mpz_struct temp[1]; struct __mpz_struct temp2[1];
 __gmpz_inits (pol, temp, temp2, ((void *)0));
 __gmpz_fdiv_r_ui (temp, k, p);
 unsigned int a = __gmpz_get_ui (temp);
 if (p == 2){
  return a;
 }
 unsigned int res = 0;
 if (p % 4 == 3){
  unsigned int m = p/4;
  __gmpz_set_ui(pol, p);
  __gmpz_powm_ui (temp, temp, m+1, pol);
  return __gmpz_get_ui (temp);
 } else if (p % 8 == 5){
  unsigned int m = p/8;
  __gmpz_set_ui (pol, p);
  __gmpz_powm_ui (temp2, temp, 2*m+1, pol);
  if ((__builtin_constant_p (1) && (1) == 0 ? ((temp2)->_mp_size < 0 ? -1 : (temp2)->_mp_size > 0) : __gmpz_cmp_ui (temp2,1)) == 0){
   __gmpz_powm_ui(temp2, temp, m+1, pol);
   res = __gmpz_get_ui (temp2);
   __gmpz_clears (pol, temp, temp2, ((void *)0));
   return res;
  } else {
   __gmpz_mul_ui(temp, temp, 4);
   __gmpz_powm_ui(temp2, temp, m+1, pol);
   if (__gmpz_divisible_ui_p(temp2, 2)){
    res = __gmpz_get_ui(temp2)/2;
    __gmpz_clears (pol, temp, temp2, ((void *)0));
    return res;
   } else {
    res = (__gmpz_get_ui(temp2)+p)/2;
    __gmpz_clears (pol, temp, temp2, ((void *)0));
    return res;
   }
  }
 }
 unsigned int s = p-1;
 unsigned int e = 0;
 while (s % 2 == 0){
  s /= 2;
  e ++;
 }
 __gmpz_set_ui (pol, p);
 __gmpz_set_ui(temp2, 2);
 __gmpz_powm_ui (temp, temp2, (p-1)/2, pol);
 while ((__builtin_constant_p (p-1) && (p-1) == 0 ? ((temp)->_mp_size < 0 ? -1 : (temp)->_mp_size > 0) : __gmpz_cmp_ui (temp,p-1)) != 0){
  __gmpz_add_ui (temp2, temp2, 1);
  __gmpz_powm_ui (temp, temp2, (p-1)/2, pol);
 }
 struct __mpz_struct x[1]; struct __mpz_struct b[1]; struct __mpz_struct g[1];
 __gmpz_inits (x, b, g, ((void *)0));
 __gmpz_set_ui (temp, a);
 __gmpz_powm_ui (x, temp, (s+1)/2, pol);
 __gmpz_powm_ui (b, temp, s, pol);
 __gmpz_powm_ui (g, temp2, s, pol);
 unsigned int r = e;
 unsigned int m;
tshanks_mainloop:
 m = 0;
 __gmpz_set (temp, b);
 while ((__builtin_constant_p (1) && (1) == 0 ? ((temp)->_mp_size < 0 ? -1 : (temp)->_mp_size > 0) : __gmpz_cmp_ui (temp,1)) != 0){
  __gmpz_mul (temp, temp, temp);
  __gmpz_mod (temp, temp, pol);
  m++;
 }
 if (m == 0){
  unsigned int res = __gmpz_get_ui (x);
  __gmpz_clears (x, b, g, pol, temp, temp2, ((void *)0));
  return res;
 } else {
  __gmpz_ui_pow_ui (temp, 2, r-m-1);
  __gmpz_powm (temp, g, temp, pol);
  __gmpz_mul (x, x, temp);
  __gmpz_mod (x, x, pol);
  __gmpz_mul (temp, temp, temp);
  __gmpz_mod (temp, temp, pol);
  __gmpz_mul (b, b, temp);
  __gmpz_mod (b, b, pol);
  __gmpz_set (g, temp);
  r = m;
 }
 goto tshanks_mainloop;
 __gmpz_clears (pol, temp, temp2, ((void *)0));
 unsigned int t = 0;
 while ( t*t % p != a && t < p/2 + 1 ){
  t ++;
 }
 if (t*t%p == a) return t;
 return -1;
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
p
unsigned int

variable_types:
a
unsigned int

variable_types:
m
unsigned int

variable_types:
s
unsigned int

variable_types:
e
unsigned int

variable_types:
r
unsigned int

variable_types:
t
unsigned int


mod

decompiled_code:
__int64 __fastcall mod(int a1, unsigned int a2)
{
unsigned int v2; // edx

v2 = a1 % a2;
if ( a1 <= 0 )
{
v2 += a2;
if ( a2 == v2 )
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, unsigned int a2)
{
unsigned int v2; // edx

v2 = a1 % a2;
if ( a1 <= 0 )
{
v2 += a2;
if ( a2 == v2 )
v2 = 0;
}
return v2;
}

original_code:
inline uint32_t mod (int32_t x, uint32_t p){
 if (x > 0){
  return x % p;
 } else {
  uint32_t z = p + (x % p);
  if (z == p) return 0;
  return z;
 }
}

canonical_original_code:
inline unsigned int mod(int x, unsigned int p){
 if (x > 0){
  return x % p;
 } else {
  unsigned int z = p + (x % p);
  if (z == p) return 0;
  return z;
 }
}

variable_types: x int

variable_types:
z
unsigned int


decompiled_code:
_BOOL8 __fastcall mpz_fits_64(__int64 a1)
{
return (unsigned __int64)_gmpz_sizeinbase(a1, 2LL) <= 0x3E;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(__int64 a1)
{
return (unsigned __int64)_gmpz_sizeinbase(a1, 2LL) <= 0x3E;
}

original_code:
int mpz_fits_64 (mpz_t a){
 return __gmpz_sizeinbase (a, 2) < 63;
}

canonical_original_code:
int mpz_fits_64(struct __mpz_struct a[1]){
 return __gmpz_sizeinbase (a, 2) < 63;
}


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

if ( (unsigned int)_gmpz_fits_ulong_p() )
result = _gmpz_get_ui(a1);
else
result = _gmpz_getlimbn(a1, 0LL);
return result;
}

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

if ( (unsigned int)_gmpz_fits_ulong_p() )
result = _gmpz_get_ui(a1);
else
result = _gmpz_getlimbn(a1, 0LL);
return result;
}

original_code:
uint64_t mpz_get_64 (mpz_t a){
 if (__gmpz_fits_ulong_p (a)){
  return (uint64_t) __gmpz_get_ui(a);
 }
 uint64_t res = 0;
 if (sizeof(mp_limb_t) == 4){
  res = __gmpz_getlimbn (a, 1);
  res = (res << 32) | __gmpz_getlimbn(a, 0);
 } else {
  res = __gmpz_getlimbn (a, 0);
 }
 return res;
}

canonical_original_code:
unsigned long mpz_get_64(struct __mpz_struct a[1]){
 if (__gmpz_fits_ulong_p (a)){
  return (unsigned long) __gmpz_get_ui(a);
 }
 unsigned long res = 0;
 if (sizeof(mp_limb_t) == 4){
  res = __gmpz_getlimbn (a, 1);
  res = (res << 32) | __gmpz_getlimbn(a, 0);
 } else {
  res = __gmpz_getlimbn (a, 0);
 }
 return res;
}

variable_types:
res
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall fl_check(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = *(_QWORD *)(a1 + 16);
if ( !v2 )
return 1LL;
while ( *(_DWORD *)v2 <= *(_DWORD *)(a2 + 32) )
{
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 1LL;
}
return 0LL;
}

original_code:
int fl_check (rel_t *rel, nsieve_t *ns){
 fl_entry_t *entry = rel->factors;
 while (entry != ((void *)0)){
  if (entry->fac > ns->fb_len){
   return 0;
  }
  entry = entry->next;
 }
 return 1;
}

canonical_original_code:
int fl_check(struct relation *rel, struct nsieve_t *ns){
 struct flentry *entry = rel->factors;
 while (entry != ((void *)0)){
  if (entry->fac > ns->fb_len){
   return 0;
  }
  entry = entry->next;
 }
 return 1;
}

variable_types: struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *

variable_types: struct nsieve_t { struct __mpz_struct N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t { struct relation *r1; struct relation *r2; unsigned long *row; } *relns; unsigned int lp_bound; struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry { struct relation *rel; struct htentry *next; } **buckets; } partials; int nthreads; unsigned long *threads; 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; } lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t { long init_time; long sieve_time; long filter_time; long matsolve_time; long facdeduct_time; long total_time; } timing; } *


decompiled_code:
__int64 __fastcall fl_fillrow(__int64 a1, void *a2, __int64 a3)
{
__int64 result; // rax
unsigned int *i; // rbx
__int64 v7; // rsi

result = (__int64)clear_row(a2, a3);
for ( i = *(unsigned int **)(a1 + 16); i; i = (unsigned int *)*((_QWORD *)i + 1) )
{
v7 = *i;
if ( (unsigned int)v7 > *(_DWORD *)(a3 + 32) + 1 )
{
printf("WARNING - bad factor: %d\n", v7);
LODWORD(v7) = *i;
}
result = flip_bit((__int64)a2, v7);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, void *a2, __int64 a3)
{
__int64 result; // rax
unsigned int *i; // rbx
__int64 v7; // rsi

result = (__int64)func0(a2, a3);
for ( i = *(unsigned int **)(a1 + 16); i; i = (unsigned int *)*((_QWORD *)i + 1) )
{
v7 = *i;
if ( (unsigned int)v7 > *(_DWORD *)(a3 + 32) + 1 )
{
printf("WARNING - bad factor: %d\n", v7);
LODWORD(v7) = *i;
}
result = func2((__int64)a2, v7);
}
return result;
}

original_code:
void fl_fillrow (rel_t *rel, uint64_t *row, nsieve_t *ns){
 clear_row (row, ns);
 fl_entry_t *entry = rel->factors;
 while (entry != ((void *)0)){
  if (entry->fac > ns->fb_len+1){
   printf ("WARNING - bad factor: %d\n", entry->fac);
  }
  flip_bit (row, entry->fac);
  entry = entry->next;
 }
}

canonical_original_code:
void fl_fillrow(struct relation *rel, unsigned long *row, struct nsieve_t *ns){
 clear_row (row, ns);
 struct flentry *entry = rel->factors;
 while (entry != ((void *)0)){
  if (entry->fac > ns->fb_len+1){
   printf ("WARNING - bad factor: %d\n", entry->fac);
  }
  flip_bit (row, entry->fac);
  entry = entry->next;
 }
}

variable_types:
row
unsigned long *

variable_types: struct flentry { unsigned int fac; struct flentry *next; } *


decompiled_code:
__int64 __fastcall fl_concat(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rcx
__int64 v4; // rdx

result = *(_QWORD *)(a1 + 16);
v3 = *(_QWORD *)(a2 + 16);
if ( result )
{
do
{
v4 = result;
result = *(_QWORD *)(result + 8);
}
while ( result );
*(_QWORD *)(v4 + 8) = v3;
}
else
{
*(_QWORD *)(a1 + 16) = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rcx
__int64 v4; // rdx

result = *(_QWORD *)(a1 + 16);
v3 = *(_QWORD *)(a2 + 16);
if ( result )
{
do
{
v4 = result;
result = *(_QWORD *)(result + 8);
}
while ( result );
*(_QWORD *)(v4 + 8) = v3;
}
else
{
*(_QWORD *)(a1 + 16) = v3;
}
return result;
}

original_code:
void fl_concat (rel_t *res, rel_t *victim){
 fl_entry_t *entry = res->factors;
 if (entry == ((void *)0)){
  res->factors = victim->factors;
 } else {
  while (entry->next != ((void *)0)){
   entry = entry->next;
  }
  entry->next = victim->factors;
 }
}

canonical_original_code:
void fl_concat(struct relation *res, struct relation *victim){
 struct flentry *entry = res->factors;
 if (entry == ((void *)0)){
  res->factors = victim->factors;
 } else {
  while (entry->next != ((void *)0)){
   entry = entry->next;
  }
  entry->next = victim->factors;
 }
}

variable_types:
victim
struct relation *


decompiled_code:
void __fastcall rel_free(void *ptr)
{
fl_free((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func19(void *ptr)
{
func15((__int64)ptr);
free(ptr);
}

original_code:
void rel_free (rel_t *rel){
 fl_free (rel);
 free (rel);
}

canonical_original_code:
void rel_free(struct relation *rel){
 fl_free (rel);
 free (rel);
}