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

result = *a1;
if ( *a1 )
{
if ( result == a1[1] )
{
*a1 = 0LL;
a1[1] = 0LL;
}
else
{
*a1 = *(_QWORD *)(result + 8);
}
--*((_DWORD *)a1 + 4);
}
return result;
}

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

result = *a1;
if ( *a1 )
{
if ( result == a1[1] )
{
*a1 = 0LL;
a1[1] = 0LL;
}
else
{
*a1 = *(_QWORD *)(result + 8);
}
--*((_DWORD *)a1 + 4);
}
return result;
}

original_code:
static NODE *del_from_list_head(QUEUE *lst)
{
    NODE *node = ((void *)0);
    if(((void *)0) == lst->head)
        return ((void *)0);
    if(lst->head == lst->tail)
    {
        node = lst->head;
        lst->head = ((void *)0);
        lst->tail = ((void *)0);
    }
    else
    {
        node = lst->head;
        lst->head = node->next;
    }
    lst->elems --;
    return node;
}

canonical_original_code:
static struct node *del_from_list_head(struct list *lst)
{
    struct node *node = ((void *)0);
    if(((void *)0) == lst->head)
        return ((void *)0);
    if(lst->head == lst->tail)
    {
        node = lst->head;
        lst->head = ((void *)0);
        lst->tail = ((void *)0);
    }
    else
    {
        node = lst->head;
        lst->head = node->next;
    }
    lst->elems --;
    return node;
}

variable_types: struct list { struct node *head; struct node *tail; int elems; unsigned char need_lock; unsigned char waiting; 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; } lmutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } lcond; } *

variable_types: struct node { void *value; struct node *next; } *


repo: terry-chelsea/shlowRun

decompiled_code:
__int64 __fastcall get_remove_node_lock(__int64 a1, int a2)
{
pthread_mutex_t *v2; // rbp
__int64 v3; // r12

v2 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v3 = del_from_list_head((__int64 *)a1);
if ( !v3 && a2 )
{
do
{
++*(_BYTE *)(a1 + 21);
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v2);
v3 = del_from_list_head((__int64 *)a1);
}
while ( !v3 );
}
pthread_mutex_unlock(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
pthread_mutex_t *v2; // rbp
__int64 v3; // r12

v2 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v3 = func1((__int64 *)a1);
if ( !v3 && a2 )
{
do
{
++*(_BYTE *)(a1 + 21);
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v2);
v3 = func1((__int64 *)a1);
}
while ( !v3 );
}
pthread_mutex_unlock(v2);
return v3;
}

original_code:
static NODE *get_remove_node_lock(QUEUE *lst , int flag)
{
    pthread_mutex_lock(&(lst->lmutex));
    NODE *node = del_from_list_head(lst);
    while(((void *)0) == node)
    {
        if(!flag)
        {
            pthread_mutex_unlock(&(lst->lmutex));
            return ((void *)0);
        }
        lst->waiting ++ ;
        pthread_cond_wait(&(lst->lcond) , &(lst->lmutex));
        node = del_from_list_head(lst);
    }
    pthread_mutex_unlock(&(lst->lmutex));
    return node;
}

canonical_original_code:
static struct node *get_remove_node_lock(struct list *lst, int flag)
{
    pthread_mutex_lock(&(lst->lmutex));
    struct node *node = del_from_list_head(lst);
    while(((void *)0) == node)
    {
        if(!flag)
        {
            pthread_mutex_unlock(&(lst->lmutex));
            return ((void *)0);
        }
        lst->waiting ++ ;
        pthread_cond_wait(&(lst->lcond) , &(lst->lmutex));
        node = del_from_list_head(lst);
    }
    pthread_mutex_unlock(&(lst->lmutex));
    return node;
}

variable_types: flag int

return_type: struct node { void *value; struct node *next; } *

user_defined_types: struct list { struct node *head; struct node *tail; int elems; unsigned char need_lock; unsigned char waiting; union pthread_mutex_t lmutex; union pthread_cond_t lcond; }

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

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

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

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


decompiled_code:
__int64 __fastcall queue_get_inside(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v3; // rdi
__int64 result; // rax

if ( *(_BYTE *)(a1 + 20) )
{
v3 = (_QWORD *)get_remove_node_lock(a1, a3);
if ( v3 )
{
LABEL_3:
*a2 = *v3;
free(v3);
return 0LL;
}
fwrite("ERROR:CAN not happen when remove a node return NULL with blocking...\n", 1uLL, 0x45uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v3 = (_QWORD *)del_from_list_head((__int64 *)a1);
if ( v3 )
goto LABEL_3;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v3; // rdi
__int64 result; // rax

if ( *(_BYTE *)(a1 + 20) )
{
v3 = (_QWORD *)func2(a1, a3);
if ( v3 )
{
LABEL_3:
*a2 = *v3;
free(v3);
return 0LL;
}
fwrite("ERROR:CAN not happen when remove a node return NULL with blocking...\n", 1uLL, 0x45uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v3 = (_QWORD *)func1((__int64 *)a1);
if ( v3 )
goto LABEL_3;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int queue_get_inside(QUEUE *queue , ElemType *val , int flag)
{
    NODE *node = ((void *)0);
    if(queue->need_lock)
    {
        node = get_remove_node_lock(queue , flag);
        if(node == ((void *)0))
        {
            fprintf(stderr , "ERROR:CAN not happen when remove a node return NULL with blocking...\n");
            return -1;
        }
    }
    else
    {
        node = del_from_list_head(queue);
        if(((void *)0) == node)
            return -1;
    }
    *val = node->value;
    free(node);
    return 0;
}

canonical_original_code:
static int queue_get_inside(struct list *queue, void **val, int flag)
{
    struct node *node = ((void *)0);
    if(queue->need_lock)
    {
        node = get_remove_node_lock(queue , flag);
        if(node == ((void *)0))
        {
            fprintf(stderr , "ERROR:CAN not happen when remove a node return NULL with blocking...\n");
            return -1;
        }
    }
    else
    {
        node = del_from_list_head(queue);
        if(((void *)0) == node)
            return -1;
    }
    *val = node->value;
    free(node);
    return 0;
}

variable_types: struct list { struct node { void *value; struct node *next; } *head; struct node *tail; int elems; unsigned char need_lock; unsigned char waiting; 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; } lmutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } lcond; } *

variable_types:
val
void **

return_type: int


decompiled_code:
__int64 __fastcall queue_put(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // r12
bool v4; // zf
char v5; // al
__int64 result; // rax

if ( a1 )
{
v2 = malloc(0x10uLL);
v3 = (__int64)v2;
if ( v2 )
{
v4 = *(_BYTE *)(a1 + 20) == 0;
*v2 = a2;
v2[1] = 0LL;
if ( v4 )
{
add_to_list_tail(a1, (__int64)v2);
result = 0LL;
}
else
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
add_to_list_tail(a1, v3);
v5 = *(_BYTE *)(a1 + 21);
if ( v5 )
{
*(_BYTE *)(a1 + 21) = v5 - 1;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
}
else
{
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
result = 0LL;
}
}
else
{
fprintf(stderr, "Allocate memory size %lu failed when put to queue...\n", 16LL);
result = 0xFFFFFFFFLL;
}
}
else
{
fwrite("WARNING : Put a value to NULL queue ...\n", 1uLL, 0x28uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // r12
bool v4; // zf
char v5; // al
__int64 result; // rax

if ( a1 )
{
v2 = malloc(0x10uLL);
v3 = (__int64)v2;
if ( v2 )
{
v4 = *(_BYTE *)(a1 + 20) == 0;
*v2 = a2;
v2[1] = 0LL;
if ( v4 )
{
func0(a1, (__int64)v2);
result = 0LL;
}
else
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
func0(a1, v3);
v5 = *(_BYTE *)(a1 + 21);
if ( v5 )
{
*(_BYTE *)(a1 + 21) = v5 - 1;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
}
else
{
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
result = 0LL;
}
}
else
{
fprintf(stderr, "Allocate memory size %lu failed when put to queue...\n", 16LL);
result = 0xFFFFFFFFLL;
}
}
else
{
fwrite("WARNING : Put a value to NULL queue ...\n", 1uLL, 0x28uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int queue_put(QUEUE *queue , ElemType value)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : Put a value to NULL queue ...\n");
        return -1;
    }
    NODE *node = (NODE *)malloc(sizeof(NODE));
    if(((void *)0) == node)
    {
        fprintf(stderr , "Allocate memory size %lu failed when put to queue...\n" , sizeof(NODE));
        return -1;
    }
    node->value = value;
    node->next = ((void *)0);
    if(queue->need_lock)
    {
        pthread_mutex_lock(&(queue->lmutex));
        add_to_list_tail(queue , node);
        int flag = 0;
        if(queue->waiting > 0)
        {
            flag = 1;
            queue->waiting --;
        }
        pthread_mutex_unlock(&(queue->lmutex));
        if(flag)
            pthread_cond_signal(&(queue->lcond));
    }
    else
    {
        add_to_list_tail(queue , node);
    }
    return 0;
}

canonical_original_code:
int queue_put(struct list *queue, void *value)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : Put a value to NULL queue ...\n");
        return -1;
    }
    struct node *node = (NODE *)malloc(sizeof(NODE));
    if(((void *)0) == node)
    {
        fprintf(stderr , "Allocate memory size %lu failed when put to queue...\n" , sizeof(NODE));
        return -1;
    }
    node->value = value;
    node->next = ((void *)0);
    if(queue->need_lock)
    {
        pthread_mutex_lock(&(queue->lmutex));
        add_to_list_tail(queue , node);
        int flag = 0;
        if(queue->waiting > 0)
        {
            flag = 1;
            queue->waiting --;
        }
        pthread_mutex_unlock(&(queue->lmutex));
        if(flag)
            pthread_cond_signal(&(queue->lcond));
    }
    else
    {
        add_to_list_tail(queue , node);
    }
    return 0;
}

variable_types:
value
void *

user_defined_types: struct node { void *value; struct node *next; }


decompiled_code:
__int64 __fastcall queue_get(__int64 a1, _QWORD *a2)
{
if ( a1 )
return queue_get_inside(a1, a2, 1);
fwrite("WARNING : get value from a NULL queue ...\n", 1uLL, 0x2AuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _QWORD *a2)
{
if ( a1 )
return func3(a1, a2, 1);
fwrite("WARNING : get value from a NULL queue ...\n", 1uLL, 0x2AuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int queue_get(QUEUE *queue , ElemType *val)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : get value from a NULL queue ...\n");
        return -1;
    }
    return queue_get_inside(queue , val , 1);
}

canonical_original_code:
int queue_get(struct list *queue, void **val)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : get value from a NULL queue ...\n");
        return -1;
    }
    return queue_get_inside(queue , val , 1);
}


decompiled_code:
__int64 __fastcall queue_get_nonblocking(__int64 a1, _QWORD *a2)
{
if ( a1 )
return queue_get_inside(a1, a2, 0);
fwrite("WARNING : nonblocking get value from a NULL queue ...\n", 1uLL, 0x36uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, _QWORD *a2)
{
if ( a1 )
return func3(a1, a2, 0);
fwrite("WARNING : nonblocking get value from a NULL queue ...\n", 1uLL, 0x36uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int queue_get_nonblocking(QUEUE *queue , ElemType *val)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : nonblocking get value from a NULL queue ...\n");
        return -1;
    }
    return queue_get_inside(queue , val , 0);
}

canonical_original_code:
int queue_get_nonblocking(struct list *queue, void **val)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : nonblocking get value from a NULL queue ...\n");
        return -1;
    }
    return queue_get_inside(queue , val , 0);
}


decompiled_code:
__int64 __fastcall queue_size(__int64 a1)
{
unsigned int v2; // er12

if ( a1 )
{
if ( !*(_BYTE *)(a1 + 20) )
return list_size_inside_isra_0(*(_QWORD *)a1);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v2 = list_size_inside_isra_0(*(_QWORD *)a1);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
else
{
v2 = -1;
fwrite("WARNING : get size from a NULL queue ...\n", 1uLL, 0x29uLL, stderr);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
unsigned int v2; // er12

if ( a1 )
{
if ( !*(_BYTE *)(a1 + 20) )
return func4(*(_QWORD *)a1);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v2 = func4(*(_QWORD *)a1);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
else
{
v2 = -1;
fwrite("WARNING : get size from a NULL queue ...\n", 1uLL, 0x29uLL, stderr);
}
return v2;
}

original_code:
int queue_size(QUEUE *queue)
{
    if(((void *)0) == queue)
    {
        fprintf(stderr , "WARNING : get size from a NULL queue ...\n");
        return -1;
    }
    int size = 0;
    if(queue->need_lock)
    {
        pthread_mutex_lock(&(queue->lmutex));
        size = list_size_inside(queue);
        pthread_mutex_unlock(&(queue->lmutex));
    }
    else
        size = list_size_inside(queue);
    return size;
}

canonical_original_code:
int queue_size(struct list *queue)
{
    if(((void *)0) == queue)
    {
        fprintf(stderr , "WARNING : get size from a NULL queue ...\n");
        return -1;
    }
    int size = 0;
    if(queue->need_lock)
    {
        pthread_mutex_lock(&(queue->lmutex));
        size = list_size_inside(queue);
        pthread_mutex_unlock(&(queue->lmutex));
    }
    else
        size = list_size_inside(queue);
    return size;
}

variable_types: size int


decompiled_code:
int __fastcall queue_info(__int64 a1)
{
const char *v1; // rsi
unsigned int v2; // eax

if ( !a1 )
return fwrite("WARNING : get queue info with a NULL queue ...\n", 1uLL, 0x2FuLL, stderr);
if ( *(_BYTE *)(a1 + 20) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
puts("Statics : ");
printf("sum elements counter : %d\n", *(unsigned int *)(a1 + 16));
v1 = "Yes";
if ( !*(_BYTE *)(a1 + 20) )
v1 = "No";
printf("With lock : %s and current waiting threads : %d\n", v1, *(unsigned __int8 *)(a1 + 21));
if ( *(_BYTE *)(a1 + 20) )
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
v2 = queue_size(a1);
return printf("Elements in the list : %d\n", v2);
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
const char *v1; // rsi
unsigned int v2; // eax

if ( !a1 )
return fwrite("WARNING : get queue info with a NULL queue ...\n", 1uLL, 0x2FuLL, stderr);
if ( *(_BYTE *)(a1 + 20) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
puts("Statics : ");
printf("sum elements counter : %d\n", *(unsigned int *)(a1 + 16));
v1 = "Yes";
if ( !*(_BYTE *)(a1 + 20) )
v1 = "No";
printf("With lock : %s and current waiting threads : %d\n", v1, *(unsigned __int8 *)(a1 + 21));
if ( *(_BYTE *)(a1 + 20) )
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
v2 = func9(a1);
return printf("Elements in the list : %d\n", v2);
}

original_code:
void queue_info(QUEUE *queue)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : get queue info with a NULL queue ...\n");
        return ;
    }
    if(queue->need_lock)
        pthread_mutex_lock(&(queue->lmutex));
    printf("Statics : \n");
    printf("sum elements counter : %d\n" , queue->elems);
    printf("With lock : %s and current waiting threads : %d\n" ,
            queue->need_lock ? "Yes" : "No" , queue->waiting);
    if(queue->need_lock)
        pthread_mutex_unlock(&(queue->lmutex));
    printf("Elements in the list : %d\n" , queue_size(queue));
}

canonical_original_code:
void queue_info(struct list *queue)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : get queue info with a NULL queue ...\n");
        return ;
    }
    if(queue->need_lock)
        pthread_mutex_lock(&(queue->lmutex));
    printf("Statics : \n");
    printf("sum elements counter : %d\n" , queue->elems);
    printf("With lock : %s and current waiting threads : %d\n" ,
            queue->need_lock ? "Yes" : "No" , queue->waiting);
    if(queue->need_lock)
        pthread_mutex_unlock(&(queue->lmutex));
    printf("Elements in the list : %d\n" , queue_size(queue));
}

return_type: void


decompiled_code:
__int64 __fastcall queue_get_tail(__int64 a1)
{
__int64 v1; // r12
__int64 v3; // r12

if ( !a1 )
{
v1 = 0LL;
fwrite("get tail from NULL queue ...\n", 1uLL, 0x1DuLL, stderr);
return v1;
}
if ( !*(_BYTE *)(a1 + 20) )
return *(_QWORD *)(a1 + 8);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v3 = *(_QWORD *)(a1 + 8);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // r12
__int64 v3; // r12

if ( !a1 )
{
v1 = 0LL;
fwrite("get tail from NULL queue ...\n", 1uLL, 0x1DuLL, stderr);
return v1;
}
if ( !*(_BYTE *)(a1 + 20) )
return *(_QWORD *)(a1 + 8);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v3 = *(_QWORD *)(a1 + 8);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
return v3;
}

original_code:
NODE *queue_get_tail(QUEUE *lst)
{
    if(((void *)0) == lst)
    {
        fprintf(stderr , "get tail from NULL queue ...\n");
        return ((void *)0);
    }
    NODE *node = ((void *)0);
    if(lst->need_lock)
    {
        pthread_mutex_lock(&(lst->lmutex));
        node = lst->tail;
        pthread_mutex_unlock(&(lst->lmutex));
    }
    else
        node = lst->tail;
    return node;
}

canonical_original_code:
struct node *queue_get_tail(struct list *lst)
{
    if(((void *)0) == lst)
    {
        fprintf(stderr , "get tail from NULL queue ...\n");
        return ((void *)0);
    }
    struct node *node = ((void *)0);
    if(lst->need_lock)
    {
        pthread_mutex_lock(&(lst->lmutex));
        node = lst->tail;
        pthread_mutex_unlock(&(lst->lmutex));
    }
    else
        node = lst->tail;
    return node;
}


decompiled_code:
int screen_savePic()
{
puts("save_savePic");
pthread_create(&talk_savePic_threadId, 0LL, savePic_thread, 0LL);
return pthread_join(talk_savePic_threadId, 0LL);
}

canonical_decompiled_code:
int func0()
{
puts("save_savePic");
pthread_create(&talk_savePic_threadId, 0LL, savePic_thread, 0LL);
return pthread_join(talk_savePic_threadId, 0LL);
}

original_code:
void screen_savePic()
{
printf("save_savePic\n");
    pthread_create(&talk_savePic_threadId, ((void *)0), (void *)savePic_thread, ((void *)0));
   pthread_join(talk_savePic_threadId,((void *)0));
}


decompiled_code:
__int64 fb_init()
{
unsigned int v0; // er13
size_t v1; // r12
__int64 v3; // [rsp+0h] [rbp-108h] BYREF
int v4; // [rsp+50h] [rbp-B8h] BYREF
int v5; // [rsp+54h] [rbp-B4h]
unsigned int v6; // [rsp+68h] [rbp-A0h]

fb_dev_fd = open("/dev/fb0", 2);
printf("fb %d", (unsigned int)fb_dev_fd);
if ( !fb_dev_fd )
{
puts("Fail!");
exit(1);
}
v0 = ioctl(fb_dev_fd, 0x4600uLL, &v4);
if ( v0 )
{
v0 = -1;
printf("%s : Can't ioctl FBIOGET_VSCREENINFO\n", "fb_init");
}
else
{
ioctl(fb_dev_fd, 0x4602uLL, &v3);
fb_Width = v4;
fb_Height = v5;
fb_Depth = v6 >> 3;
v1 = (int)((v6 >> 3) * v5 * v4);
framebuffer_data = malloc(v1);
read(fb_dev_fd, framebuffer_data, v1);
puts("\nclose fb");
close(fb_dev_fd);
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er13
size_t v1; // r12
__int64 v3; // [rsp+0h] [rbp-108h] BYREF
int v4; // [rsp+50h] [rbp-B8h] BYREF
int v5; // [rsp+54h] [rbp-B4h]
unsigned int v6; // [rsp+68h] [rbp-A0h]

fb_dev_fd = open("/dev/fb0", 2);
printf("fb %d", (unsigned int)fb_dev_fd);
if ( !fb_dev_fd )
{
puts("Fail!");
exit(1);
}
v0 = ioctl(fb_dev_fd, 0x4600uLL, &v4);
if ( v0 )
{
v0 = -1;
printf("%s : Can't ioctl FBIOGET_VSCREENINFO\n", "fb_init");
}
else
{
ioctl(fb_dev_fd, 0x4602uLL, &v3);
fb_Width = v4;
fb_Height = v5;
fb_Depth = v6 >> 3;
v1 = (int)((v6 >> 3) * v5 * v4);
framebuffer_data = malloc(v1);
read(fb_dev_fd, framebuffer_data, v1);
puts("\nclose fb");
close(fb_dev_fd);
}
return v0;
}

original_code:
int fb_init(void){
 struct fb_fix_screeninfo fb_fix_info;
    struct fb_var_screeninfo fb_var_info;
    fb_dev_fd = open("/dev/fb0", 02);
printf("fb %d",fb_dev_fd);
 if(!fb_dev_fd){
 printf("Fail!\n");
 exit(1);
 }
    if (ioctl(fb_dev_fd, 0x4600, &fb_var_info) ) {
        printf("%s : Can't ioctl FBIOGET_VSCREENINFO\n", __FUNCTION__);
        return -1;
    }
    ioctl(fb_dev_fd,0x4602,&fb_fix_info);
    fb_Depth = fb_var_info.bits_per_pixel / 8;
    fb_Width = fb_var_info.xres;
    fb_Height = fb_var_info.yres;
    int data_size = fb_Width * fb_Height * fb_Depth;
    int len, i;
    framebuffer_data = (char *)malloc(data_size);
    len=read(fb_dev_fd, framebuffer_data, data_size);
printf("\nclose fb\n");
 close(fb_dev_fd);
 return 0;
}

canonical_original_code:
int fb_init(){
 struct fb_fix_screeninfo fb_fix_info;
    struct fb_var_screeninfo fb_var_info;
    fb_dev_fd = open("/dev/fb0", 02);
printf("fb %d",fb_dev_fd);
 if(!fb_dev_fd){
 printf("Fail!\n");
 exit(1);
 }
    if (ioctl(fb_dev_fd, 0x4600, &fb_var_info) ) {
        printf("%s : Can't ioctl FBIOGET_VSCREENINFO\n", __FUNCTION__);
        return -1;
    }
    ioctl(fb_dev_fd,0x4602,&fb_fix_info);
    fb_Depth = fb_var_info.bits_per_pixel / 8;
    fb_Width = fb_var_info.xres;
    fb_Height = fb_var_info.yres;
    int data_size = fb_Width * fb_Height * fb_Depth;
    int len; int i;
    framebuffer_data = (char *)malloc(data_size);
    len=read(fb_dev_fd, framebuffer_data, data_size);
printf("\nclose fb\n");
 close(fb_dev_fd);
 return 0;
}

variable_types: struct fb_fix_screeninfo { char id[16]; unsigned long smem_start; unsigned int smem_len; unsigned int type; unsigned int type_aux; unsigned int visual; unsigned short xpanstep; unsigned short ypanstep; unsigned short ywrapstep; unsigned int line_length; unsigned long mmio_start; unsigned int mmio_len; unsigned int accel; unsigned short capabilities; unsigned short reserved[2]; }

variable_types: struct fb_var_screeninfo { unsigned int xres; unsigned int yres; unsigned int xres_virtual; unsigned int yres_virtual; unsigned int xoffset; unsigned int yoffset; unsigned int bits_per_pixel; unsigned int grayscale; struct fb_bitfield { unsigned int offset; unsigned int length; unsigned int msb_right; } red; struct fb_bitfield green; struct fb_bitfield blue; struct fb_bitfield transp; unsigned int nonstd; unsigned int activate; unsigned int height; unsigned int width; unsigned int accel_flags; unsigned int pixclock; unsigned int left_margin; unsigned int right_margin; unsigned int upper_margin; unsigned int lower_margin; unsigned int hsync_len; unsigned int vsync_len; unsigned int sync; unsigned int vmode; unsigned int rotate; unsigned int colorspace; unsigned int reserved[4]; }

variable_types: len int

variable_types: i int

user_defined_types: struct fb_var_screeninfo { unsigned int xres; unsigned int yres; unsigned int xres_virtual; unsigned int yres_virtual; unsigned int xoffset; unsigned int yoffset; unsigned int bits_per_pixel; unsigned int grayscale; struct fb_bitfield red; struct fb_bitfield green; struct fb_bitfield blue; struct fb_bitfield transp; unsigned int nonstd; unsigned int activate; unsigned int height; unsigned int width; unsigned int accel_flags; unsigned int pixclock; unsigned int left_margin; unsigned int right_margin; unsigned int upper_margin; unsigned int lower_margin; unsigned int hsync_len; unsigned int vsync_len; unsigned int sync; unsigned int vmode; unsigned int rotate; unsigned int colorspace; unsigned int reserved[4]; }


freePic

decompiled_code:
void freePic()
{
if ( framebuffer_data )
{
free(framebuffer_data);
framebuffer_data = 0LL;
}
}

canonical_decompiled_code:
void func2()
{
if ( framebuffer_data )
{
free(framebuffer_data);
framebuffer_data = 0LL;
}
}

original_code:
void freePic()
{
    if(((void *)0) != framebuffer_data) {
        free(framebuffer_data);
        framebuffer_data = ((void *)0);
    }
}


decompiled_code:
void *__fastcall savePic_thread(void *a1)
{
puts("savePic_thread");
if ( !framebuffer_data
|| (unsigned int)rawData2Jpg((__int64)framebuffer_data, work_dir, fb_Width, fb_Height, fb_Depth) )
{
return 0LL;
}
freePic();
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func4(void *a1)
{
puts("savePic_thread");
if ( !framebuffer_data
|| (unsigned int)func3((__int64)framebuffer_data, work_dir, fb_Width, fb_Height, fb_Depth) )
{
return 0LL;
}
func2();
return 0LL;
}

original_code:
void* savePic_thread (void* unused)
{
  printf("savePic_thread\n");
    if (((void *)0) != framebuffer_data) {
        if (0 == rawData2Jpg(framebuffer_data, work_dir, fb_Width, fb_Height, fb_Depth)) {
            freePic();
        }
    }
    return ((void *)0);
}

canonical_original_code:
void *savePic_thread(void *unused)
{
  printf("savePic_thread\n");
    if (((void *)0) != framebuffer_data) {
        if (0 == rawData2Jpg(framebuffer_data, work_dir, fb_Width, fb_Height, fb_Depth)) {
            freePic();
        }
    }
    return ((void *)0);
}

variable_types:
unused
void *

return_type: void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)fb_init(argc, argv, envp) )
{
puts("framebuffer init fail!");
goto LABEL_8;
}
puts("Capture the screen..");
if ( argc != 1 )
{
if ( argc == 2 )
return 0;
LABEL_8:
exit(1);
}
if ( !getcwd(work_dir, 0x64uLL) )
{
puts("can't get present work directory");
exit(1);
}
*(_QWORD *)work_dir = 0x6E6565726373LL;
screen_savePic();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func1(argc, argv, envp) )
{
puts("framebuffer init fail!");
goto LABEL_8;
}
puts("Capture the screen..");
if ( argc != 1 )
{
if ( argc == 2 )
return 0;
LABEL_8:
exit(1);
}
if ( !getcwd(work_dir, 0x64uLL) )
{
puts("can't get present work directory");
exit(1);
}
*(_QWORD *)work_dir = 0x6E6565726373LL;
func0();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
if( fb_init() == 0){
    printf("Capture the screen..\n");
 if(argc == 1){
  if ( getcwd(work_dir, sizeof(work_dir)) != ((void *)0))
  {
   char* tmp = "screen";
   strncpy(work_dir,tmp,sizeof(tmp));
   screen_savePic();
  }else{
   printf("can't get present work directory\n");
   exit(1);
  }
 }else if( argc == 2){
 }else{
 exit(1);
 }
return 0;
}else{
 printf("framebuffer init fail!\n");
 exit(1);
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
if( fb_init() == 0){
    printf("Capture the screen..\n");
 if(argc == 1){
  if ( getcwd(work_dir, sizeof(work_dir)) != ((void *)0))
  {
   char *tmp = "screen";
   strncpy(work_dir,tmp,sizeof(tmp));
   screen_savePic();
  }else{
   printf("can't get present work directory\n");
   exit(1);
  }
 }else if( argc == 2){
 }else{
 exit(1);
 }
return 0;
}else{
 printf("framebuffer init fail!\n");
 exit(1);
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
tmp
char *


fred

decompiled_code:
int __fastcall fred(unsigned int a1)
{
return printf("frex: we passed %d\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
return printf("frex: we passed %d\n", a1);
}

original_code:
void fred( int arg){
 printf("frex: we passed %d\n", arg);
}

canonical_original_code:
void fred(int arg){
 printf("frex: we passed %d\n", arg);
}

variable_types: arg int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
bill("Hello World\n", argv, envp);
exit(0);
}

original_code:
int main(){
 bill("Hello World\n");
 exit(0);
}


bill

decompiled_code:
int __fastcall bill(const char *a1)
{
return printf("Bill: we passed!%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("Bill: we passed!%s\n", a1);
}

original_code:
void bill( char *arg){
 printf("Bill: we passed!%s\n",arg);
}

canonical_original_code:
void bill(char *arg){
 printf("Bill: we passed!%s\n",arg);
}

variable_types:
arg
char *


main

repo: tetsuok/conllx-to-tikz-dep

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
int v4; // er12

if ( argc == 1 )
{
v3 = (char *)&delim[2];
}
else
{
if ( argc != 2 )
{
v4 = -1;
fprintf(stderr, "Usage: %s filename\n", *argv);
return v4;
}
v3 = (char *)argv[1];
}
latex_print_header(argc, argv, envp);
v4 = open_conllx(v3);
if ( v4 )
{
v4 = -1;
fprintf(stderr, "ERROR: failed to open %s\n", argv[1]);
}
else
{
latex_print_footer();
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
int v4; // er12

if ( argc == 1 )
{
v3 = (char *)&delim[2];
}
else
{
if ( argc != 2 )
{
v4 = -1;
fprintf(stderr, "Usage: %s filename\n", *argv);
return v4;
}
v3 = (char *)argv[1];
}
func11(argc, argv, envp);
v4 = func8(v3);
if ( v4 )
{
v4 = -1;
fprintf(stderr, "ERROR: failed to open %s\n", argv[1]);
}
else
{
func12();
}
return v4;
}

original_code:
int main(int argc, char** argv)
{
    const char* filename = ((void *)0);
    if (argc == 1) {
        filename = "-";
    } else if (argc == 2) {
        filename = argv[1];
    } else {
        fprintf(stderr, "Usage: %s filename\n", argv[0]);
        return -1;
    }
    latex_print_header();
    if (open_conllx(filename) != 0) {
        fprintf(stderr, "ERROR: failed to open %s\n", argv[1]);
        return -1;
    }
    latex_print_footer();
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    char *filename = ((void *)0);
    if (argc == 1) {
        filename = "-";
    } else if (argc == 2) {
        filename = argv[1];
    } else {
        fprintf(stderr, "Usage: %s filename\n", argv[0]);
        return -1;
    }
    latex_print_header();
    if (open_conllx(filename) != 0) {
        fprintf(stderr, "ERROR: failed to open %s\n", argv[1]);
        return -1;
    }
    latex_print_footer();
    return 0;
}

variable_types:
argv
char **

variable_types:
filename
char *


decompiled_code:
int __fastcall latex_print_deptext(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax

v1 = 0LL;
puts("\\begin{deptext}[column sep=1em]");
if ( *(int *)a1 > 0 )
{
while ( 1 )
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v1++);
printf("%s", *(const char **)(v2 + 8));
if ( *(_DWORD *)a1 <= (int)v1 )
break;
printf(" \\& ");
}
}
puts(" \\\\");
return puts("\\end{deptext}");
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax

v1 = 0LL;
puts("\\begin{deptext}[column sep=1em]");
if ( *(int *)a1 > 0 )
{
while ( 1 )
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v1++);
printf("%s", *(const char **)(v2 + 8));
if ( *(_DWORD *)a1 <= (int)v1 )
break;
printf(" \\& ");
}
}
puts(" \\\\");
return puts("\\end{deptext}");
}

original_code:
void latex_print_deptext(const struct sentence* s)
{
    int i;
    printf("\\begin{deptext}[column sep=1em]\n");
    for (i = 0; i < s->length; i++) {
        if (i > 0) printf(" \\& ");
        printf("%s", s->tokens[i]->form);
    }
    puts(" \\\\");
    puts("\\end{deptext}");
}

canonical_original_code:
void latex_print_deptext(struct sentence *s)
{
    int i;
    printf("\\begin{deptext}[column sep=1em]\n");
    for (i = 0; i < s->length; i++) {
        if (i > 0) printf(" \\& ");
        printf("%s", s->tokens[i]->form);
    }
    puts(" \\\\");
    puts("\\end{deptext}");
}

variable_types: struct sentence { int length; int cap; struct token { int id; int head; char *form; char *lemma; char *cpos; char *pos; char *feat; char *deprel; char *phead; char *pdeprel; } **tokens; } *

user_defined_types: struct sentence { int length; int cap; struct token **tokens; }


decompiled_code:
int __fastcall latex_print_depedge(unsigned int a1, unsigned int a2)
{
return printf("\\depedge{%d}{%d}{}\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1, unsigned int a2)
{
return printf("\\depedge{%d}{%d}{}\n", a1, a2);
}

original_code:
void latex_print_depedge(int h, int m)
{
    printf("\\depedge{%d}{%d}{}\n", h, m);
}

variable_types: h int

variable_types: m int


decompiled_code:
int latex_print_header()
{
puts("\\documentclass{standalone}");
puts("\\usepackage{tikz-dependency}");
puts("\\begin{document}");
return puts("\\begin{dependency}[theme = simple, edge style={<-}]");
}

canonical_decompiled_code:
int func11()
{
puts("\\documentclass{standalone}");
puts("\\usepackage{tikz-dependency}");
puts("\\begin{document}");
return puts("\\begin{dependency}[theme = simple, edge style={<-}]");
}

original_code:
void latex_print_header(void)
{
    puts("\\documentclass{standalone}");
    puts("\\usepackage{tikz-dependency}");
    puts("\\begin{document}");
    puts("\\begin{dependency}[theme = simple, edge style={<-}]");
}

canonical_original_code:
void latex_print_header()
{
    puts("\\documentclass{standalone}");
    puts("\\usepackage{tikz-dependency}");
    puts("\\begin{document}");
    puts("\\begin{dependency}[theme = simple, edge style={<-}]");
}


decompiled_code:
int latex_print_footer()
{
puts("\\end{dependency}");
return puts("\\end{document}");
}

canonical_decompiled_code:
int func12()
{
puts("\\end{dependency}");
return puts("\\end{document}");
}

original_code:
void latex_print_footer(void)
{
    puts("\\end{dependency}");
    puts("\\end{document}");
}

canonical_original_code:
void latex_print_footer()
{
    puts("\\end{dependency}");
    puts("\\end{document}");
}


decompiled_code:
int __fastcall latex_print_dep_tree(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
unsigned int *v3; // rax

latex_print_deptext(a1);
result = *(_DWORD *)a1;
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
result = is_root(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2));
if ( !result )
{
v3 = *(unsigned int **)(*(_QWORD *)(a1 + 8) + 8 * v2);
result = latex_print_depedge(v3[1], *v3);
}
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
unsigned int *v3; // rax

func9(a1);
result = *(_DWORD *)a1;
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
result = func16(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2));
if ( !result )
{
v3 = *(unsigned int **)(*(_QWORD *)(a1 + 8) + 8 * v2);
result = func10(v3[1], *v3);
}
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
}
return result;
}

original_code:
void latex_print_dep_tree(const struct sentence* s)
{
    int i;
    latex_print_deptext(s);
    for (i = 0; i < s->length; i++) {
        if (is_root(s->tokens[i])) continue;
        latex_print_depedge(s->tokens[i]->head, s->tokens[i]->id);
    }
}

canonical_original_code:
void latex_print_dep_tree(struct sentence *s)
{
    int i;
    latex_print_deptext(s);
    for (i = 0; i < s->length; i++) {
        if (is_root(s->tokens[i])) continue;
        latex_print_depedge(s->tokens[i]->head, s->tokens[i]->id);
    }
}

user_defined_types: struct token { int id; int head; char *form; char *lemma; char *cpos; char *pos; char *feat; char *deprel; char *phead; char *pdeprel; }


decompiled_code:
__int64 __fastcall token_new(__int64 a1, unsigned int a2)
{
__int64 v2; // r12
int v3; // eax
int v4; // er13
int v5; // eax
__int64 v6; // rdx

if ( !a1 )
{
v2 = 0LL;
fwrite("Warning: the pointer seq is NULL.\n", 1uLL, 0x22uLL, stderr);
return v2;
}
v2 = xmalloc(72LL);
if ( a2 == 10 )
{
v3 = atoi(*(const char **)a1);
*(_DWORD *)v2 = v3;
v4 = v3;
*(_QWORD *)(v2 + 8) = *(_QWORD *)(a1 + 8);
*(_QWORD *)(v2 + 16) = *(_QWORD *)(a1 + 16);
*(_QWORD *)(v2 + 24) = *(_QWORD *)(a1 + 24);
*(_QWORD *)(v2 + 32) = *(_QWORD *)(a1 + 32);
*(_QWORD *)(v2 + 40) = *(_QWORD *)(a1 + 40);
v5 = atoi(*(const char **)(a1 + 48));
v6 = *(_QWORD *)(a1 + 56);
*(_DWORD *)(v2 + 4) = v5;
*(_QWORD *)(v2 + 48) = v6;
*(_QWORD *)(v2 + 56) = *(_QWORD *)(a1 + 64);
*(_QWORD *)(v2 + 64) = *(_QWORD *)(a1 + 72);
if ( v4 < 0 )
{
v2 = 0LL;
fprintf(stderr, "invalid id = %d\n", (unsigned int)v4);
}
else if ( v5 < 0 )
{
v2 = 0LL;
fprintf(stderr, "invalid head = %d\n", (unsigned int)v5);
}
return v2;
}
fprintf(stderr, "invalid data format: n = %d\n", a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned int a2)
{
__int64 v2; // r12
int v3; // eax
int v4; // er13
int v5; // eax
__int64 v6; // rdx

if ( !a1 )
{
v2 = 0LL;
fwrite("Warning: the pointer seq is NULL.\n", 1uLL, 0x22uLL, stderr);
return v2;
}
v2 = func24(72LL);
if ( a2 == 10 )
{
v3 = atoi(*(const char **)a1);
*(_DWORD *)v2 = v3;
v4 = v3;
*(_QWORD *)(v2 + 8) = *(_QWORD *)(a1 + 8);
*(_QWORD *)(v2 + 16) = *(_QWORD *)(a1 + 16);
*(_QWORD *)(v2 + 24) = *(_QWORD *)(a1 + 24);
*(_QWORD *)(v2 + 32) = *(_QWORD *)(a1 + 32);
*(_QWORD *)(v2 + 40) = *(_QWORD *)(a1 + 40);
v5 = atoi(*(const char **)(a1 + 48));
v6 = *(_QWORD *)(a1 + 56);
*(_DWORD *)(v2 + 4) = v5;
*(_QWORD *)(v2 + 48) = v6;
*(_QWORD *)(v2 + 56) = *(_QWORD *)(a1 + 64);
*(_QWORD *)(v2 + 64) = *(_QWORD *)(a1 + 72);
if ( v4 < 0 )
{
v2 = 0LL;
fprintf(stderr, "invalid id = %d\n", (unsigned int)v4);
}
else if ( v5 < 0 )
{
v2 = 0LL;
fprintf(stderr, "invalid head = %d\n", (unsigned int)v5);
}
return v2;
}
fprintf(stderr, "invalid data format: n = %d\n", a2);
return 0LL;
}

original_code:
struct token* token_new(const char** seq, int n)
{
    struct token* t;
    if (seq == ((void *)0)) {
        fprintf(stderr, "Warning: the pointer seq is NULL.\n");
        return ((void *)0);
    }
    t = xmalloc(sizeof(struct token));
    if (n != 10) {
        fprintf(stderr, "invalid data format: n = %d\n", n);
        return ((void *)0);
    }
    t->id = atoi(seq[0]);
    t->form = seq[1];
    t->lemma = seq[2];
    t->cpos = seq[3];
    t->pos = seq[4];
    t->feat = seq[5];
    t->head = atoi(seq[6]);
    t->deprel = seq[7];
    t->phead = seq[8];
    t->pdeprel = seq[9];
    if (t->id < 0) {
        fprintf(stderr, "invalid id = %d\n", t->id);
        return ((void *)0);
    }
    if (t->head < 0) {
        fprintf(stderr, "invalid head = %d\n", t->head);
        return ((void *)0);
    }
    return t;
}

canonical_original_code:
struct token *token_new(char **seq, int n)
{
    struct token *t;
    if (seq == ((void *)0)) {
        fprintf(stderr, "Warning: the pointer seq is NULL.\n");
        return ((void *)0);
    }
    t = xmalloc(sizeof(struct token));
    if (n != 10) {
        fprintf(stderr, "invalid data format: n = %d\n", n);
        return ((void *)0);
    }
    t->id = atoi(seq[0]);
    t->form = seq[1];
    t->lemma = seq[2];
    t->cpos = seq[3];
    t->pos = seq[4];
    t->feat = seq[5];
    t->head = atoi(seq[6]);
    t->deprel = seq[7];
    t->phead = seq[8];
    t->pdeprel = seq[9];
    if (t->id < 0) {
        fprintf(stderr, "invalid id = %d\n", t->id);
        return ((void *)0);
    }
    if (t->head < 0) {
        fprintf(stderr, "invalid head = %d\n", t->head);
        return ((void *)0);
    }
    return t;
}

variable_types:
seq
char **

variable_types: n int

variable_types: struct token { int id; int head; char *form; char *lemma; char *cpos; char *pos; char *feat; char *deprel; char *phead; char *pdeprel; } *


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

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

original_code:
void token_destroy(struct token* t)
{
    if (t == ((void *)0)) return;
    free(t);
}

canonical_original_code:
void token_destroy(struct token *t)
{
    if (t == ((void *)0)) return;
    free(t);
}


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

result = 0xFFFFFFFFLL;
if ( a1 )
result = *(_DWORD *)(a1 + 4) == 0;
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a1 )
result = *(_DWORD *)(a1 + 4) == 0;
return result;
}

original_code:
int is_root(const struct token* t)
{
    return (t != ((void *)0)) ? t->head == 0 : -1;
}

canonical_original_code:
int is_root(struct token *t)
{
    return (t != ((void *)0)) ? t->head == 0 : -1;
}


decompiled_code:
_QWORD *sentence_new()
{
_QWORD *v0; // r12

v0 = (_QWORD *)xmalloc(16LL);
*v0 = 0x10000000000LL;
v0[1] = xmalloc(2048LL);
return v0;
}

original_code:
struct sentence* sentence_new(void)
{
    struct sentence* s = xmalloc(sizeof(struct sentence));
    s->length = 0;
    s->cap = kBufSize;
    s->tokens = xmalloc(sizeof(struct token *) * kBufSize);
    return s;
}

canonical_original_code:
struct sentence *sentence_new()
{
    struct sentence *s = xmalloc(sizeof(struct sentence));
    s->length = 0;
    s->cap = kBufSize;
    s->tokens = xmalloc(sizeof(struct token *) * kBufSize);
    return s;
}

return_type: struct sentence { int length; int cap; struct token { int id; int head; char *form; char *lemma; char *cpos; char *pos; char *feat; char *deprel; char *phead; char *pdeprel; } **tokens; } *


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

if ( ptr )
{
if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
token_destroy(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
}
}

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

if ( ptr )
{
if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
func15(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void sentence_destroy(struct sentence* s)
{
    if (s == ((void *)0)) return;
    int i;
    for (i = 0; i < s->length; i++) {
        token_destroy(s->tokens[i]);
    }
    free(s->tokens);
    free(s);
}

canonical_original_code:
void sentence_destroy(struct sentence *s)
{
    if (s == ((void *)0)) return;
    int i;
    for (i = 0; i < s->length; i++) {
        token_destroy(s->tokens[i]);
    }
    free(s->tokens);
    free(s);
}


original_code:
void sentence_add_token(struct sentence* s, struct token* t)
{
    if (s == ((void *)0) || t == ((void *)0)) return;
    if (s->length >= s->cap) {
        struct token* new_tokens = xmalloc(sizeof(struct token *) * (unsigned long)s->cap * 2);
        memcpy(new_tokens, s->tokens, s->cap);
        s->cap *= 2;
    }
    s->tokens[s->length] = t;
    s->length++;
}

canonical_original_code:
void sentence_add_token(struct sentence *s, struct token *t)
{
    if (s == ((void *)0) || t == ((void *)0)) return;
    if (s->length >= s->cap) {
        struct token *new_tokens = xmalloc(sizeof(struct token *) * (unsigned long)s->cap * 2);
        memcpy(new_tokens, s->tokens, s->cap);
        s->cap *= 2;
    }
    s->tokens[s->length] = t;
    s->length++;
}

variable_types:
t
struct token *


decompiled_code:
int __fastcall print_form(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax

if ( *(int *)a1 > 0 )
{
v1 = 0LL;
while ( 1 )
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v1++);
printf("%s", *(const char **)(v2 + 8));
if ( *(_DWORD *)a1 <= (int)v1 )
break;
putchar(32);
}
}
return putchar(10);
}

original_code:
void print_form(const struct sentence* s)
{
    int i;
    for (i = 0; i < s->length; i++) {
        if (i > 0) printf(" ");
        printf("%s", s->tokens[i]->form);
    }
    printf("\n");
}

canonical_original_code:
void print_form(struct sentence *s)
{
    int i;
    for (i = 0; i < s->length; i++) {
        if (i > 0) printf(" ");
        printf("%s", s->tokens[i]->form);
    }
    printf("\n");
}


decompiled_code:
__int64 __fastcall new_blocks(int a1)
{
size_t v1; // r13
__int64 v2; // r12
void *v3; // rax
__int64 result; // rax

v1 = 8LL * a1;
v2 = xmalloc(16LL);
v3 = (void *)xmalloc(v1);
*(_QWORD *)v2 = v3;
if ( a1 > 0 )
memset(v3, 0, v1);
*(_DWORD *)(v2 + 8) = a1;
result = v2;
*(_DWORD *)(v2 + 12) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(int a1)
{
size_t v1; // r13
__int64 v2; // r12
void *v3; // rax
__int64 result; // rax

v1 = 8LL * a1;
v2 = func24(16LL);
v3 = (void *)func24(v1);
*(_QWORD *)v2 = v3;
if ( a1 > 0 )
memset(v3, 0, v1);
*(_DWORD *)(v2 + 8) = a1;
result = v2;
*(_DWORD *)(v2 + 12) = 0;
return result;
}

original_code:
struct blocks* new_blocks(int size)
{
    int i;
    struct blocks* b = xmalloc(sizeof(struct blocks));
    b->bufs = xmalloc(sizeof(char *) * (unsigned long)size);
    for (i = 0; i < size; i++) {
        b->bufs[i] = ((void *)0);
    }
    b->size = size;
    b->ptr = 0;
    return b;
}

canonical_original_code:
struct blocks *new_blocks(int size)
{
    int i;
    struct blocks *b = xmalloc(sizeof(struct blocks));
    b->bufs = xmalloc(sizeof(char *) * (unsigned long)size);
    for (i = 0; i < size; i++) {
        b->bufs[i] = ((void *)0);
    }
    b->size = size;
    b->ptr = 0;
    return b;
}

variable_types: size int

variable_types: struct blocks { char **bufs; int size; int ptr; } *


decompiled_code:
void __fastcall destroy_blocks(void *ptr)
{
_QWORD *v2; // r8
__int64 v3; // rbx
void *v4; // rdi

v2 = *(_QWORD **)ptr;
if ( *((int *)ptr + 3) > 0 )
{
v3 = 0LL;
do
{
v4 = (void *)v2[v3];
if ( v4 )
{
free(v4);
v2 = *(_QWORD **)ptr;
}
++v3;
}
while ( *((_DWORD *)ptr + 3) > (int)v3 );
}
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func22(void *ptr)
{
_QWORD *v2; // r8
__int64 v3; // rbx
void *v4; // rdi

v2 = *(_QWORD **)ptr;
if ( *((int *)ptr + 3) > 0 )
{
v3 = 0LL;
do
{
v4 = (void *)v2[v3];
if ( v4 )
{
free(v4);
v2 = *(_QWORD **)ptr;
}
++v3;
}
while ( *((_DWORD *)ptr + 3) > (int)v3 );
}
free(v2);
free(ptr);
}

original_code:
void destroy_blocks(struct blocks* b)
{
    int i;
    for (i = 0; i < b->ptr; i++) {
        if (b->bufs[i] != ((void *)0))
            free(b->bufs[i]);
    }
    free(b->bufs);
    free(b);
}

canonical_original_code:
void destroy_blocks(struct blocks *b)
{
    int i;
    for (i = 0; i < b->ptr; i++) {
        if (b->bufs[i] != ((void *)0))
            free(b->bufs[i]);
    }
    free(b->bufs);
    free(b);
}

variable_types: i int

user_defined_types: struct blocks { char **bufs; int size; int ptr; }


decompiled_code:
__int64 __fastcall blocks_add_elem(__int64 a1, __int64 a2)
{
int v3; // eax
__int64 v4; // rdi
_QWORD *v5; // rcx
__int64 v6; // rdx
__int64 result; // rax
void *v8; // rax
_QWORD *v9; // rax

v3 = *(_DWORD *)(a1 + 12);
v4 = *(int *)(a1 + 8);
if ( v3 >= (int)v4 )
{
v8 = (void *)xmalloc(16 * v4);
v9 = memcpy(v8, *(const void **)a1, *(int *)(a1 + 8));
*(_DWORD *)(a1 + 8) *= 2;
*(_QWORD *)a1 = v9;
v5 = v9;
v3 = *(_DWORD *)(a1 + 12);
}
else
{
v5 = *(_QWORD **)a1;
}
v6 = v3;
result = (unsigned int)(v3 + 1);
v5[v6] = a2;
*(_DWORD *)(a1 + 12) = result;
return result;
}

original_code:
void blocks_add_elem(struct blocks* b, char* s)
{
    if (b->ptr >= b->size) {
        char** new_bufs = xmalloc(sizeof(char *) * (unsigned long)b->size * 2);
        memcpy(new_bufs, b->bufs, b->size);
        b->bufs = new_bufs;
        b->size *= 2;
    }
    b->bufs[b->ptr] = s;
    b->ptr++;
}

canonical_original_code:
void blocks_add_elem(struct blocks *b, char *s)
{
    if (b->ptr >= b->size) {
        char **new_bufs = xmalloc(sizeof(char *) * (unsigned long)b->size * 2);
        memcpy(new_bufs, b->bufs, b->size);
        b->bufs = new_bufs;
        b->size *= 2;
    }
    b->bufs[b->ptr] = s;
    b->ptr++;
}

variable_types:
s
char *


xmalloc

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

result = malloc(a1);
if ( !result )
{
fwrite("memory exhausted!\n", 1uLL, 0x12uLL, stderr);
exit(-1);
}
return result;
}

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

result = malloc(a1);
if ( !result )
{
fwrite("memory exhausted!\n", 1uLL, 0x12uLL, stderr);
exit(-1);
}
return result;
}

original_code:
void* xmalloc(size_t n) {
    void *p = (void *)malloc(n);
    if (p == ((void *)0)) {
        fprintf(stderr, "memory exhausted!\n");
        exit(-1);
    }
    return p;
}

canonical_original_code:
void *xmalloc(unsigned long n) {
    void *p = (void *)malloc(n);
    if (p == ((void *)0)) {
        fprintf(stderr, "memory exhausted!\n");
        exit(-1);
    }
    return p;
}

variable_types:
n
unsigned long

variable_types:
p
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rdx
int v5; // er12
__int64 v7; // rax
__int64 v8; // rdx
std::ostream *v9; // rax
__int64 v10; // rax
__int64 v11; // rdx
__int64 v12; // rax
__int64 v13; // rdx
std::ostream *v14; // rax
__int64 v15[5]; // [rsp+0h] [rbp-28h] BYREF

if ( argc == 1 )
{
v3 = (const char *)&unk_55F;
}
else
{
if ( argc != 2 )
{
v5 = -1;
v10 = std::operator<<<std::char_traits<char>>(&std::cerr, "Usage: ", envp);
v12 = std::operator<<<std::char_traits<char>>(v10, *argv, v11);
v14 = (std::ostream *)std::operator<<<std::char_traits<char>>(v12, "filename", v13);
std::endl<char,std::char_traits<char>>(v14);
return v5;
}
v3 = argv[1];
}
v15[0] = 0LL;
v15[1] = sentence_new(argc, argv, envp);
latex_print_header();
if ( (unsigned __int8)conll::Reader::Open((conll::Reader *)v15, v3) )
{
latex_print_footer();
v5 = 0;
}
else
{
v7 = std::operator<<<std::char_traits<char>>(&std::cerr, "ERROR: failed to open ", v4);
v9 = (std::ostream *)std::operator<<<std::char_traits<char>>(v7, v3, v8);
std::endl<char,std::char_traits<char>>(v9);
v5 = -1;
}
conll::Reader::~Reader((conll::Reader *)v15);
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rdx
int v5; // er12
__int64 v7; // rax
__int64 v8; // rdx
std::ostream *v9; // rax
__int64 v10; // rax
__int64 v11; // rdx
__int64 v12; // rax
__int64 v13; // rdx
std::ostream *v14; // rax
__int64 v15[5]; // [rsp+0h] [rbp-28h] BYREF

if ( argc == 1 )
{
v3 = (const char *)&unk_55F;
}
else
{
if ( argc != 2 )
{
v5 = -1;
v10 = std::operator<<<std::char_traits<char>>(&std::cerr, "Usage: ", envp);
v12 = std::operator<<<std::char_traits<char>>(v10, *argv, v11);
v14 = (std::ostream *)std::operator<<<std::char_traits<char>>(v12, "filename", v13);
std::endl<char,std::char_traits<char>>(v14);
return v5;
}
v3 = argv[1];
}
v15[0] = 0LL;
v15[1] = sentence_new(argc, argv, envp);
latex_print_header();
if ( (unsigned __int8)conll::Reader::func0((conll::Reader *)v15, v3) )
{
latex_print_footer();
v5 = 0;
}
else
{
v7 = std::operator<<<std::char_traits<char>>(&std::cerr, "ERROR: failed to open ", v4);
v9 = (std::ostream *)std::operator<<<std::char_traits<char>>(v7, v3, v8);
std::endl<char,std::char_traits<char>>(v9);
v5 = -1;
}
conll::Reader::~func2((conll::Reader *)v15);
return v5;
}

original_code:
int main(int argc, char** argv)
{
    const char* filename = ((void *)0);
    if (argc == 1) {
        filename = "-";
    } else if (argc == 2) {
        filename = argv[1];
    } else {
        fprintf(stderr, "Usage: %s filename\n", argv[0]);
        return -1;
    }
    latex_print_header();
    if (open_conllx(filename) != 0) {
        fprintf(stderr, "ERROR: failed to open %s\n", argv[1]);
        return -1;
    }
    latex_print_footer();
    return 0;
}

variable_types: argc int


original_code:
static int calc_samples(int freq)
{
 int x, samples;
 samples = 8000;
 for (x=0;x<6;x++)
  if (!(freq % 2)) {
   freq /= 2;
   samples /= 2;
  }
 for (x=0;x<3;x++)
  if (!(freq % 5)) {
   freq /= 5;
   samples /=5;
  }
 return samples;
}

canonical_original_code:
static int calc_samples(int freq)
{
 int x; int samples;
 samples = 8000;
 for (x=0;x<6;x++)
  if (!(freq % 2)) {
   freq /= 2;
   samples /= 2;
  }
 for (x=0;x<3;x++)
  if (!(freq % 5)) {
   freq /= 5;
   samples /=5;
  }
 return samples;
}

variable_types: freq int

variable_types: x int

variable_types: samples int


repo: tgreaves/ilona

decompiled_code:
__int64 __fastcall set_systemlog(__int64 a1)
{
return _isoc99_sscanf(a1, &unk_B11, sc);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return _isoc99_sscanf(a1, &unk_B11, sc);
}

original_code:
void set_systemlog (char *f)
{
    sscanf (f, "%s ", sc->systemlog);
}

canonical_original_code:
void set_systemlog(char *f)
{
    sscanf (f, "%s ", sc->systemlog);
}

variable_types:
f
char *


decompiled_code:
int set_newbot()
{
int result; // eax

if ( edit_bot == 1 )
{
result = printf(
"Error parsing configuration (line %d) - Can't define a bot inside another bot!\n",
(unsigned int)line);
cfg_error = 1;
}
else
{
result = insert_bot(thebots);
edit_bot = 1;
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax

if ( edit_bot == 1 )
{
result = printf(
"Error parsing configuration (line %d) - Can't define a bot inside another bot!\n",
(unsigned int)line);
cfg_error = 1;
}
else
{
result = insert_bot(thebots);
edit_bot = 1;
}
return result;
}

original_code:
void set_newbot (char *f)
{
    if (edit_bot != 1)
    {
        insert_bot (thebots);
        edit_bot=1;
    }
    else
    {
        printf("Error parsing configuration (line %d) - Can't define a bot inside another bot!\n", line);
        cfg_error=1;
    }
}

canonical_original_code:
void set_newbot(char *f)
{
    if (edit_bot != 1)
    {
        insert_bot (thebots);
        edit_bot=1;
    }
    else
    {
        printf("Error parsing configuration (line %d) - Can't define a bot inside another bot!\n", line);
        cfg_error=1;
    }
}


decompiled_code:
int set_endchannel()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rbx
bool v3; // zf

if ( edit_channel == 1 )
{
v1 = get_bot(thebots, 1LL);
v0 = get_channel(v1, 1LL);
v2 = v0;
if ( *(_BYTE *)(v0 + 16) )
{
if ( *(_BYTE *)(v0 + 66) )
goto LABEL_5;
}
else
{
LODWORD(v0) = printf(
"Error parsing configuration file (line %d) - Channel name not defined!\n",
(unsigned int)line);
v3 = *(_BYTE *)(v2 + 66) == 0;
cfg_error = 1;
if ( !v3 )
{
LABEL_5:
if ( *(_BYTE *)(v2 + 166) )
{
LABEL_6:
edit_channel = 0;
return v0;
}
LABEL_9:
LODWORD(v0) = printf(
"Error parsing configuration file (line %d) - Channel_Log not defined!\n",
(unsigned int)line);
cfg_error = 1;
goto LABEL_6;
}
}
LODWORD(v0) = printf("Error parsing configuration file (line %d) - Userfile not defined!\n", (unsigned int)line);
v3 = *(_BYTE *)(v2 + 166) == 0;
cfg_error = 1;
if ( !v3 )
goto LABEL_6;
goto LABEL_9;
}
LODWORD(v0) = printf(
"Error parsing configuration file (line %d) - Found EndChannel before NewChannel.\n",
(unsigned int)line);
cfg_error = 1;
return v0;
}

canonical_decompiled_code:
int func3()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rbx
bool v3; // zf

if ( edit_channel == 1 )
{
v1 = get_bot(thebots, 1LL);
v0 = get_channel(v1, 1LL);
v2 = v0;
if ( *(_BYTE *)(v0 + 16) )
{
if ( *(_BYTE *)(v0 + 66) )
goto LABEL_5;
}
else
{
LODWORD(v0) = printf(
"Error parsing configuration file (line %d) - Channel name not defined!\n",
(unsigned int)line);
v3 = *(_BYTE *)(v2 + 66) == 0;
cfg_error = 1;
if ( !v3 )
{
LABEL_5:
if ( *(_BYTE *)(v2 + 166) )
{
LABEL_6:
edit_channel = 0;
return v0;
}
LABEL_9:
LODWORD(v0) = printf(
"Error parsing configuration file (line %d) - Channel_Log not defined!\n",
(unsigned int)line);
cfg_error = 1;
goto LABEL_6;
}
}
LODWORD(v0) = printf("Error parsing configuration file (line %d) - Userfile not defined!\n", (unsigned int)line);
v3 = *(_BYTE *)(v2 + 166) == 0;
cfg_error = 1;
if ( !v3 )
goto LABEL_6;
goto LABEL_9;
}
LODWORD(v0) = printf(
"Error parsing configuration file (line %d) - Found EndChannel before NewChannel.\n",
(unsigned int)line);
cfg_error = 1;
return v0;
}

original_code:
void set_endchannel (char *f)
{
    struct Channel *mychan;
    if (edit_channel==1)
    {
        mychan= get_channel ( get_bot(thebots,1), 1);
        if ( mychan->channel[0]=='\0')
        {
            printf("Error parsing configuration file (line %d) - Channel name not defined!\n", line);
            cfg_error=1;
        }
        if ( mychan->userfile[0]=='\0')
        {
            printf("Error parsing configuration file (line %d) - Userfile not defined!\n", line);
            cfg_error=1;
        }
        if ( mychan->logfile[0]=='\0')
        {
            printf("Error parsing configuration file (line %d) - Channel_Log not defined!\n", line);
            cfg_error=1;
        }
        edit_channel=0;
    }
    else
    {
        printf("Error parsing configuration file (line %d) - Found EndChannel before NewChannel.\n", line);
        cfg_error=1;
    }
}

canonical_original_code:
void set_endchannel(char *f)
{
    struct Channel *mychan;
    if (edit_channel==1)
    {
        mychan= get_channel ( get_bot(thebots,1), 1);
        if ( mychan->channel[0]=='\0')
        {
            printf("Error parsing configuration file (line %d) - Channel name not defined!\n", line);
            cfg_error=1;
        }
        if ( mychan->userfile[0]=='\0')
        {
            printf("Error parsing configuration file (line %d) - Userfile not defined!\n", line);
            cfg_error=1;
        }
        if ( mychan->logfile[0]=='\0')
        {
            printf("Error parsing configuration file (line %d) - Channel_Log not defined!\n", line);
            cfg_error=1;
        }
        edit_channel=0;
    }
    else
    {
        printf("Error parsing configuration file (line %d) - Found EndChannel before NewChannel.\n", line);
        cfg_error=1;
    }
}

variable_types: struct Channel { struct ChanUser { char nick[12]; char NUH[30]; struct ChanUser *next; } *cusers; struct User { struct User *next; char nick[12]; char NUH[30]; int level; int op; int autoop; } *users; char channel[50]; char userfile[100]; char logfile[100]; struct Channel *next; int no_users; int no_cusers; int anonops; } *

user_defined_types: struct Channel { struct ChanUser *cusers; struct User *users; char channel[50]; char userfile[100]; char logfile[100]; struct Channel *next; int no_users; int no_cusers; int anonops; }


decompiled_code:
int __fastcall set_channel(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rax

if ( edit_channel != 1 )
return printf(
"Error parsing configuration file (line %d) - Can't define Channel ouuside a NewChannel/EndChannel eefinition.\n",
(unsigned int)line);
_isoc99_sscanf(a1, &unk_B11, temp_line);
v2 = get_bot(thebots, 1LL);
v3 = get_channel(v2, 1LL);
return (unsigned int)strcpy((char *)(v3 + 16), temp_line);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rax

if ( edit_channel != 1 )
return printf(
"Error parsing configuration file (line %d) - Can't define Channel ouuside a NewChannel/EndChannel eefinition.\n",
(unsigned int)line);
_isoc99_sscanf(a1, &unk_B11, temp_line);
v2 = get_bot(thebots, 1LL);
v3 = get_channel(v2, 1LL);
return (unsigned int)strcpy((char *)(v3 + 16), temp_line);
}

original_code:
void set_channel (char *f)
{
    if (edit_channel==1)
    {
        sscanf (f, "%s ", temp_line);
        strcpy ( get_channel(get_bot (thebots, 1), 1)->channel, temp_line);
    }
    else
    {
        printf("Error parsing configuration file (line %d) - Can't define Channel ouuside a NewChannel/EndChannel eefinition.\n", line);
    }
}

canonical_original_code:
void set_channel(char *f)
{
    if (edit_channel==1)
    {
        sscanf (f, "%s ", temp_line);
        strcpy ( get_channel(get_bot (thebots, 1), 1)->channel, temp_line);
    }
    else
    {
        printf("Error parsing configuration file (line %d) - Can't define Channel ouuside a NewChannel/EndChannel eefinition.\n", line);
    }
}


decompiled_code:
int __fastcall set_userfile(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rax

if ( edit_channel != 1 )
return printf(
"Error parsing configuration file (line %d) - Can't define Userfile outside a NewChannel/EndChannel definition.\n",
(unsigned int)line);
_isoc99_sscanf(a1, &unk_B11, temp_line);
v2 = get_bot(thebots, 1LL);
v3 = get_channel(v2, 1LL);
return (unsigned int)strcpy((char *)(v3 + 66), temp_line);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rax

if ( edit_channel != 1 )
return printf(
"Error parsing configuration file (line %d) - Can't define Userfile outside a NewChannel/EndChannel definition.\n",
(unsigned int)line);
_isoc99_sscanf(a1, &unk_B11, temp_line);
v2 = get_bot(thebots, 1LL);
v3 = get_channel(v2, 1LL);
return (unsigned int)strcpy((char *)(v3 + 66), temp_line);
}

original_code:
void set_userfile (char *f)
{
    if (edit_channel==1)
    {
        sscanf (f, "%s ", temp_line);
        strcpy ( get_channel(get_bot (thebots,1), 1)->userfile, temp_line);
    }
    else
    {
        printf("Error parsing configuration file (line %d) - Can't define Userfile outside a NewChannel/EndChannel definition.\n", line);
    }
}

canonical_original_code:
void set_userfile(char *f)
{
    if (edit_channel==1)
    {
        sscanf (f, "%s ", temp_line);
        strcpy ( get_channel(get_bot (thebots,1), 1)->userfile, temp_line);
    }
    else
    {
        printf("Error parsing configuration file (line %d) - Can't define Userfile outside a NewChannel/EndChannel definition.\n", line);
    }
}


decompiled_code:
int __fastcall set_chanlog(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rax

if ( edit_channel != 1 )
return printf(
"Error parsing configuration file (line %d) - Can't define Channel_Log ouuside a NewChannel/EndChannel definition.\n",
(unsigned int)line);
_isoc99_sscanf(a1, &unk_B11, temp_line);
v2 = get_bot(thebots, 1LL);
v3 = get_channel(v2, 1LL);
return (unsigned int)strcpy((char *)(v3 + 166), temp_line);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rax

if ( edit_channel != 1 )
return printf(
"Error parsing configuration file (line %d) - Can't define Channel_Log ouuside a NewChannel/EndChannel definition.\n",
(unsigned int)line);
_isoc99_sscanf(a1, &unk_B11, temp_line);
v2 = get_bot(thebots, 1LL);
v3 = get_channel(v2, 1LL);
return (unsigned int)strcpy((char *)(v3 + 166), temp_line);
}

original_code:
void set_chanlog (char *f)
{
    if (edit_channel==1)
    {
        sscanf (f, "%s ", temp_line);
        strcpy ( get_channel(get_bot (thebots,1), 1)->logfile, temp_line);
    }
    else
    {
        printf("Error parsing configuration file (line %d) - Can't define Channel_Log ouuside a NewChannel/EndChannel definition.\n", line);
    }
}

canonical_original_code:
void set_chanlog(char *f)
{
    if (edit_channel==1)
    {
        sscanf (f, "%s ", temp_line);
        strcpy ( get_channel(get_bot (thebots,1), 1)->logfile, temp_line);
    }
    else
    {
        printf("Error parsing configuration file (line %d) - Can't define Channel_Log ouuside a NewChannel/EndChannel definition.\n", line);
    }
}


decompiled_code:
int set_anonops()
{
__int64 v0; // rax
__int64 v1; // rax

if ( edit_channel == 1 )
{
v1 = get_bot(thebots, 1LL);
v0 = get_channel(v1, 1LL);
*(_DWORD *)(v0 + 288) = 1;
}
else
{
LODWORD(v0) = printf(
"Error parsing configuration file (line %d) - Can't define AnonOps ouuside a NewChannel/EndChannel definition.\n",
(unsigned int)line);
}
return v0;
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // rax
__int64 v1; // rax

if ( edit_channel == 1 )
{
v1 = get_bot(thebots, 1LL);
v0 = get_channel(v1, 1LL);
*(_DWORD *)(v0 + 288) = 1;
}
else
{
LODWORD(v0) = printf(
"Error parsing configuration file (line %d) - Can't define AnonOps ouuside a NewChannel/EndChannel definition.\n",
(unsigned int)line);
}
return v0;
}

original_code:
void set_anonops (char *f)
{
    if (edit_channel==1)
    {
        get_channel(get_bot(thebots,1), 1)->anonops = 1 ;
    }
    else
    {
        printf("Error parsing configuration file (line %d) - Can't define AnonOps ouuside a NewChannel/EndChannel definition.\n", line);
    }
}

canonical_original_code:
void set_anonops(char *f)
{
    if (edit_channel==1)
    {
        get_channel(get_bot(thebots,1), 1)->anonops = 1 ;
    }
    else
    {
        printf("Error parsing configuration file (line %d) - Can't define AnonOps ouuside a NewChannel/EndChannel definition.\n", line);
    }
}


decompiled_code:
int __fastcall err_notinbot(const char *a1)
{
return printf(
"Error parsing configuration (line %d) - Can't define %s outside a bot definition.\n",
(unsigned int)line,
a1);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
return printf(
"Error parsing configuration (line %d) - Can't define %s outside a bot definition.\n",
(unsigned int)line,
a1);
}

original_code:
void err_notinbot (char *f)
{
    printf("Error parsing configuration (line %d) - Can't define %s outside a bot definition.\n", line, f);
}

canonical_original_code:
void err_notinbot(char *f)
{
    printf("Error parsing configuration (line %d) - Can't define %s outside a bot definition.\n", line, f);
}


decompiled_code:
int __fastcall set_description(char *src)
{
__int64 v2; // rax

if ( edit_bot != 1 )
return err_notinbot("Description");
v2 = get_bot(thebots, 1LL);
return (unsigned int)strcpy((char *)(v2 + 44), src);
}

canonical_decompiled_code:
int __fastcall func11(char *src)
{
__int64 v2; // rax

if ( edit_bot != 1 )
return func8("Description");
v2 = get_bot(thebots, 1LL);
return (unsigned int)strcpy((char *)(v2 + 44), src);
}

original_code:
void set_description (char *f)
{
    if (edit_bot == 1)
    {
        strcpy ( get_bot (thebots,1)->description, f);
    }
    else
    {
        err_notinbot ("Description");
    }
}

canonical_original_code:
void set_description(char *f)
{
    if (edit_bot == 1)
    {
        strcpy ( get_bot (thebots,1)->description, f);
    }
    else
    {
        err_notinbot ("Description");
    }
}


decompiled_code:
int __fastcall set_server(__int64 a1)
{
unsigned int v2; // ebx
__int64 v3; // rax
char v4; // [rsp-78h] [rbp-78h] BYREF

if ( edit_bot != 1 )
return err_notinbot("Server");
_isoc99_sscanf(a1, "%s %s ", temp_line);
v2 = strtol(&v4, 0LL, 0);
v3 = get_bot(thebots, 1LL);
return insert_IRCServer(v3, temp_line, v2);
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1)
{
unsigned int v2; // ebx
__int64 v3; // rax
char v4; // [rsp-78h] [rbp-78h] BYREF

if ( edit_bot != 1 )
return func8("Server");
_isoc99_sscanf(a1, "%s %s ", temp_line);
v2 = strtol(&v4, 0LL, 0);
v3 = get_bot(thebots, 1LL);
return insert_IRCServer(v3, temp_line, v2);
}

original_code:
void set_server (char *f)
{
    int port;
    char temp[100];
    if (edit_bot == 1)
    {
        sscanf (f, "%s %s ", temp_line, temp);
        port = strtol (temp, ((void *)0), 0);
        insert_IRCServer ( get_bot (thebots, 1), temp_line, port ) ;
    }
    else
    {
        err_notinbot ("Server");
    }
}

canonical_original_code:
void set_server(char *f)
{
    int port;
    char temp[100];
    if (edit_bot == 1)
    {
        sscanf (f, "%s %s ", temp_line, temp);
        port = strtol (temp, ((void *)0), 0);
        insert_IRCServer ( get_bot (thebots, 1), temp_line, port ) ;
    }
    else
    {
        err_notinbot ("Server");
    }
}

variable_types: port int

variable_types:
temp
char [100]


decompiled_code:
int __fastcall set_nickname(__int64 a1)
{
__int64 v2; // rax

if ( edit_bot != 1 )
return err_notinbot("Nickname");
_isoc99_sscanf(a1, &unk_B11, temp_line);
v2 = get_bot(thebots, 1LL);
return insert_nick(v2, temp_line);
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
__int64 v2; // rax

if ( edit_bot != 1 )
return func8("Nickname");
_isoc99_sscanf(a1, &unk_B11, temp_line);
v2 = get_bot(thebots, 1LL);
return insert_nick(v2, temp_line);
}

original_code:
void set_nickname (char *f)
{
    if (edit_bot == 1)
    {
        sscanf (f, "%s ", temp_line);
        insert_nick ( get_bot (thebots, 1), temp_line);
    }
    else
    {
        err_notinbot ("Nickname");
    }
}

canonical_original_code:
void set_nickname(char *f)
{
    if (edit_bot == 1)
    {
        sscanf (f, "%s ", temp_line);
        insert_nick ( get_bot (thebots, 1), temp_line);
    }
    else
    {
        err_notinbot ("Nickname");
    }
}


decompiled_code:
int __fastcall set_maxconnects(const char *a1)
{
__int64 v1; // rax
int v2; // ebx
char *endptr; // [rsp+0h] [rbp-10h] BYREF

if ( edit_bot == 1 )
{
v2 = strtol(a1, &endptr, 0);
v1 = get_bot(thebots, 1LL);
*(_DWORD *)(v1 + 156) = v2;
}
else
{
LODWORD(v1) = err_notinbot("Max_Connects");
}
return v1;
}

canonical_decompiled_code:
int __fastcall func14(const char *a1)
{
__int64 v1; // rax
int v2; // ebx
char *endptr; // [rsp+0h] [rbp-10h] BYREF

if ( edit_bot == 1 )
{
v2 = strtol(a1, &endptr, 0);
v1 = get_bot(thebots, 1LL);
*(_DWORD *)(v1 + 156) = v2;
}
else
{
LODWORD(v1) = func8("Max_Connects");
}
return v1;
}

original_code:
void set_maxconnects (char *f)
{
    int no;
    char *tail;
    if (edit_bot == 1)
    {
        no = strtol (f, &tail, 0);
        get_bot(thebots, 1)->max_connects = no;
    }
    else
    {
        err_notinbot ("Max_Connects");
    }
}

canonical_original_code:
void set_maxconnects(char *f)
{
    int no;
    char *tail;
    if (edit_bot == 1)
    {
        no = strtol (f, &tail, 0);
        get_bot(thebots, 1)->max_connects = no;
    }
    else
    {
        err_notinbot ("Max_Connects");
    }
}

variable_types: no int

variable_types:
tail
char *


decompiled_code:
int set_motd()
{
__int64 v0; // rax

if ( edit_bot == 1 )
{
v0 = get_bot(thebots, 1LL);
*(_DWORD *)(v0 + 912) = 1;
}
else
{
LODWORD(v0) = err_notinbot("Log_MOTD");
}
return v0;
}

canonical_decompiled_code:
int func15()
{
__int64 v0; // rax

if ( edit_bot == 1 )
{
v0 = get_bot(thebots, 1LL);
*(_DWORD *)(v0 + 912) = 1;
}
else
{
LODWORD(v0) = func8("Log_MOTD");
}
return v0;
}

original_code:
void set_motd (char *f)
{
    if (edit_bot == 1)
    {
        get_bot(thebots,1)->log_motd=1;
    }
    else
    {
        err_notinbot ("Log_MOTD");
    }
}

canonical_original_code:
void set_motd(char *f)
{
    if (edit_bot == 1)
    {
        get_bot(thebots,1)->log_motd=1;
    }
    else
    {
        err_notinbot ("Log_MOTD");
    }
}


decompiled_code:
int set_newchannel()
{
int result; // eax
__int64 v1; // rax

if ( edit_bot != 1 )
return err_notinbot("NewChannel");
if ( edit_channel )
{
result = printf(
"Error parsing configuration (line %d) - Can't define a channel inside another one!\n",
(unsigned int)line);
cfg_error = 1;
}
else
{
v1 = get_bot(thebots, 1LL);
result = insert_channel(v1);
edit_channel = 1;
}
return result;
}

canonical_decompiled_code:
int func16()
{
int result; // eax
__int64 v1; // rax

if ( edit_bot != 1 )
return func8("NewChannel");
if ( edit_channel )
{
result = printf(
"Error parsing configuration (line %d) - Can't define a channel inside another one!\n",
(unsigned int)line);
cfg_error = 1;
}
else
{
v1 = get_bot(thebots, 1LL);
result = insert_channel(v1);
edit_channel = 1;
}
return result;
}

original_code:
void set_newchannel (char *f)
{
    if (edit_bot == 1)
    {
        if (edit_channel ==0)
        {
            insert_channel ( get_bot(thebots, 1));
            edit_channel=1;
        }
        else
        {
            printf("Error parsing configuration (line %d) - Can't define a channel inside another one!\n", line);
            cfg_error=1;
        }
    }
    else
    {
        err_notinbot ("NewChannel");
    }
}

canonical_original_code:
void set_newchannel(char *f)
{
    if (edit_bot == 1)
    {
        if (edit_channel ==0)
        {
            insert_channel ( get_bot(thebots, 1));
            edit_channel=1;
        }
        else
        {
            printf("Error parsing configuration (line %d) - Can't define a channel inside another one!\n", line);
            cfg_error=1;
        }
    }
    else
    {
        err_notinbot ("NewChannel");
    }
}


decompiled_code:
int __fastcall set_newuser(__int64 a1)
{
int result; // eax

if ( edit_user == 1 )
{
result = printf(
"Error parsing %s (line %d) - Can't define a user inside another user!\n",
(const char *)(a1 + 66),
(unsigned int)line);
cfg_error = 1;
}
else
{
result = (unsigned int)insert_user(a1);
edit_user = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
int result; // eax

if ( edit_user == 1 )
{
result = printf(
"Error parsing %s (line %d) - Can't define a user inside another user!\n",
(const char *)(a1 + 66),
(unsigned int)line);
cfg_error = 1;
}
else
{
result = (unsigned int)insert_user(a1);
edit_user = 1;
}
return result;
}

original_code:
void set_newuser (struct Channel *chan, char *f)
{
    if (edit_user != 1)
    {
        insert_user (chan);
        edit_user=1;
    }
    else
    {
        printf("Error parsing %s (line %d) - Can't define a user inside another user!\n", chan->userfile, line);
        cfg_error=1;
    }
}

canonical_original_code:
void set_newuser(struct Channel *chan, char *f)
{
    if (edit_user != 1)
    {
        insert_user (chan);
        edit_user=1;
    }
    else
    {
        printf("Error parsing %s (line %d) - Can't define a user inside another user!\n", chan->userfile, line);
        cfg_error=1;
    }
}

user_defined_types: struct ChanUser { char nick[12]; char NUH[30]; struct ChanUser *next; }

user_defined_types: struct User { struct User *next; char nick[12]; char NUH[30]; int level; int op; int autoop; }


decompiled_code:
int __fastcall set_enduser(__int64 a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rbp
int result; // eax
bool v4; // zf

if ( edit_user == 1 )
{
v1 = get_user(a1, 1);
v2 = v1;
if ( *((_BYTE *)v1 + 8) )
{
if ( *((_BYTE *)v1 + 20) )
goto LABEL_4;
}
else
{
printf("Error parsing %s (line %d) - User nickname not defined!\n", (const char *)(a1 + 66), (unsigned int)line);
v4 = *((_BYTE *)v2 + 20) == 0;
cfg_error = 1;
if ( !v4 )
{
LABEL_4:
result = *((_DWORD *)v2 + 13);
if ( result )
{
LABEL_5:
edit_user = 0;
return result;
}
LABEL_7:
result = printf(
"Error parsing %s (line %d) - User's level not defined!\n",
(const char *)(a1 + 66),
(unsigned int)line);
cfg_error = 1;
goto LABEL_5;
}
}
printf(
"Error parsing %s (line %d) - User's nick!user@host not defined!\n",
(const char *)(a1 + 66),
(unsigned int)line);
result = *((_DWORD *)v2 + 13);
cfg_error = 1;
if ( result )
goto LABEL_5;
goto LABEL_7;
}
result = printf(
"Error parsing %s (line %d) - Found EndUser before NewUser!.\n",
(const char *)(a1 + 66),
(unsigned int)line);
cfg_error = 1;
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rbp
int result; // eax
bool v4; // zf

if ( edit_user == 1 )
{
v1 = get_user(a1, 1);
v2 = v1;
if ( *((_BYTE *)v1 + 8) )
{
if ( *((_BYTE *)v1 + 20) )
goto LABEL_4;
}
else
{
printf("Error parsing %s (line %d) - User nickname not defined!\n", (const char *)(a1 + 66), (unsigned int)line);
v4 = *((_BYTE *)v2 + 20) == 0;
cfg_error = 1;
if ( !v4 )
{
LABEL_4:
result = *((_DWORD *)v2 + 13);
if ( result )
{
LABEL_5:
edit_user = 0;
return result;
}
LABEL_7:
result = printf(
"Error parsing %s (line %d) - User's level not defined!\n",
(const char *)(a1 + 66),
(unsigned int)line);
cfg_error = 1;
goto LABEL_5;
}
}
printf(
"Error parsing %s (line %d) - User's nick!user@host not defined!\n",
(const char *)(a1 + 66),
(unsigned int)line);
result = *((_DWORD *)v2 + 13);
cfg_error = 1;
if ( result )
goto LABEL_5;
goto LABEL_7;
}
result = printf(
"Error parsing %s (line %d) - Found EndUser before NewUser!.\n",
(const char *)(a1 + 66),
(unsigned int)line);
cfg_error = 1;
return result;
}

original_code:
void set_enduser (struct Channel *chan, char *f)
{
    struct User *myuser;
    if (edit_user==1)
    {
        myuser= get_user ( chan, 1);
        if ( myuser->nick[0]=='\0')
        {
            printf("Error parsing %s (line %d) - User nickname not defined!\n", chan->userfile, line);
            cfg_error=1;
        }
        if ( myuser->NUH[0]=='\0')
        {
            printf("Error parsing %s (line %d) - User's nick!user@host not defined!\n", chan->userfile, line);
            cfg_error=1;
        }
        if ( myuser->level==0)
        {
            printf("Error parsing %s (line %d) - User's level not defined!\n", chan->userfile, line);
            cfg_error=1;
        }
        edit_user=0;
    }
    else
    {
        printf("Error parsing %s (line %d) - Found EndUser before NewUser!.\n", chan->userfile, line);
        cfg_error=1;
    }
}

canonical_original_code:
void set_enduser(struct Channel *chan, char *f)
{
    struct User *myuser;
    if (edit_user==1)
    {
        myuser= get_user ( chan, 1);
        if ( myuser->nick[0]=='\0')
        {
            printf("Error parsing %s (line %d) - User nickname not defined!\n", chan->userfile, line);
            cfg_error=1;
        }
        if ( myuser->NUH[0]=='\0')
        {
            printf("Error parsing %s (line %d) - User's nick!user@host not defined!\n", chan->userfile, line);
            cfg_error=1;
        }
        if ( myuser->level==0)
        {
            printf("Error parsing %s (line %d) - User's level not defined!\n", chan->userfile, line);
            cfg_error=1;
        }
        edit_user=0;
    }
    else
    {
        printf("Error parsing %s (line %d) - Found EndUser before NewUser!.\n", chan->userfile, line);
        cfg_error=1;
    }
}

variable_types: struct User { struct User *next; char nick[12]; char NUH[30]; int level; int op; int autoop; } *


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

result = *a1;
if ( *a1 && a2 != 1 )
{
for ( i = 1; i != a2; ++i )
{
result = *(_QWORD *)(result + 48);
if ( !result )
break;
}
}
return result;
}

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

result = *a1;
if ( *a1 && a2 != 1 )
{
for ( i = 1; i != a2; ++i )
{
result = *(_QWORD *)(result + 48);
if ( !result )
break;
}
}
return result;
}

original_code:
struct ChanUser * get_chanuser (struct Channel *b, int no)
{
    struct ChanUser *temp;
    int count=0;
    for (temp=b->cusers; temp; temp=temp->next)
    {
        count++;
        if (count == no)
        {
            break;
        }
    }
    return temp;
}

canonical_original_code:
struct ChanUser *get_chanuser(struct Channel *b, int no)
{
    struct ChanUser *temp;
    int count = 0;
    for (temp=b->cusers; temp; temp=temp->next)
    {
        count++;
        if (count == no)
        {
            break;
        }
    }
    return temp;
}

variable_types: struct Channel { struct ChanUser *cusers; struct User { struct User *next; char nick[12]; char NUH[30]; int level; int op; int autoop; } *users; char channel[50]; char userfile[100]; char logfile[100]; struct Channel *next; int no_users; int no_cusers; int anonops; } *

variable_types: struct ChanUser { char nick[12]; char NUH[30]; struct ChanUser *next; } *

variable_types: count int


decompiled_code:
int __fastcall err_notinuser(__int64 a1, const char *a2)
{
return printf(
"Error parsing %s (line %d) - Can't define %s outside a user definition.\n",
(const char *)(a1 + 66),
(unsigned int)line,
a2);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, const char *a2)
{
return printf(
"Error parsing %s (line %d) - Can't define %s outside a user definition.\n",
(const char *)(a1 + 66),
(unsigned int)line,
a2);
}

original_code:
void err_notinuser (struct Channel *chan, char *f)
{
    printf("Error parsing %s (line %d) - Can't define %s outside a user definition.\n", chan->userfile, line, f);
}

canonical_original_code:
void err_notinuser(struct Channel *chan, char *f)
{
    printf("Error parsing %s (line %d) - Can't define %s outside a user definition.\n", chan->userfile, line, f);
}


decompiled_code:
int __fastcall set_nick(__int64 a1, __int64 a2)
{
char *v3; // rax

if ( edit_user != 1 )
return err_notinuser(a1, "Nick");
_isoc99_sscanf(a2, "%s ", temp_line);
v3 = (char *)get_user(a1, 1);
return (unsigned int)strcpy(v3 + 8, temp_line);
}

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

if ( edit_user != 1 )
return func3(a1, "Nick");
_isoc99_sscanf(a2, "%s ", temp_line);
v3 = (char *)get_user(a1, 1);
return (unsigned int)strcpy(v3 + 8, temp_line);
}

original_code:
void set_nick (struct Channel *chan, char *f)
{
    if (edit_user == 1)
    {
        sscanf (f, "%s ", temp_line);
        strcpy ( get_user (chan, 1)->nick, temp_line);
    }
    else
    {
        err_notinuser (chan, "Nick");
    }
}

canonical_original_code:
void set_nick(struct Channel *chan, char *f)
{
    if (edit_user == 1)
    {
        sscanf (f, "%s ", temp_line);
        strcpy ( get_user (chan, 1)->nick, temp_line);
    }
    else
    {
        err_notinuser (chan, "Nick");
    }
}


decompiled_code:
int __fastcall set_NUH(__int64 a1, __int64 a2)
{
char *v3; // rax

if ( edit_user != 1 )
return err_notinuser(a1, "NUH");
_isoc99_sscanf(a2, "%s ", temp_line);
v3 = (char *)get_user(a1, 1);
return (unsigned int)strcpy(v3 + 20, temp_line);
}

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

if ( edit_user != 1 )
return func3(a1, "NUH");
_isoc99_sscanf(a2, "%s ", temp_line);
v3 = (char *)get_user(a1, 1);
return (unsigned int)strcpy(v3 + 20, temp_line);
}

original_code:
void set_NUH (struct Channel *chan, char *f)
{
    if (edit_user == 1)
    {
        sscanf (f, "%s ", temp_line);
        strcpy ( get_user (chan, 1)->NUH, temp_line);
    }
    else
    {
        err_notinuser (chan, "NUH");
    }
}

canonical_original_code:
void set_NUH(struct Channel *chan, char *f)
{
    if (edit_user == 1)
    {
        sscanf (f, "%s ", temp_line);
        strcpy ( get_user (chan, 1)->NUH, temp_line);
    }
    else
    {
        err_notinuser (chan, "NUH");
    }
}


decompiled_code:
int __fastcall set_level(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
int v3; // ecx
char *endptr; // [rsp+8h] [rbp-10h] BYREF

if ( edit_user == 1 )
{
_isoc99_sscanf(a2, "%s ", temp_line);
strtol(temp_line, &endptr, 0);
v2 = get_user(a1, 1);
*((_DWORD *)v2 + 13) = v3;
}
else
{
LODWORD(v2) = err_notinuser(a1, "Level");
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
int v3; // ecx
char *endptr; // [rsp+8h] [rbp-10h] BYREF

if ( edit_user == 1 )
{
_isoc99_sscanf(a2, "%s ", temp_line);
strtol(temp_line, &endptr, 0);
v2 = get_user(a1, 1);
*((_DWORD *)v2 + 13) = v3;
}
else
{
LODWORD(v2) = func3(a1, "Level");
}
return (int)v2;
}

original_code:
void set_level (struct Channel *chan, char *f)
{
    char *tail;
    if (edit_user == 1)
    {
        sscanf (f, "%s ", temp_line);
        get_user (chan, 1)->level = strtol (temp_line, &tail, 0);
    }
    else
    {
        err_notinuser (chan, "Level");
    }
}

canonical_original_code:
void set_level(struct Channel *chan, char *f)
{
    char *tail;
    if (edit_user == 1)
    {
        sscanf (f, "%s ", temp_line);
        get_user (chan, 1)->level = strtol (temp_line, &tail, 0);
    }
    else
    {
        err_notinuser (chan, "Level");
    }
}


decompiled_code:
int __fastcall set_op(__int64 a1)
{
_QWORD *v1; // rax

if ( edit_user == 1 )
{
v1 = get_user(a1, 1);
*((_DWORD *)v1 + 14) = 1;
}
else
{
LODWORD(v1) = err_notinuser(a1, "Op");
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
_QWORD *v1; // rax

if ( edit_user == 1 )
{
v1 = get_user(a1, 1);
*((_DWORD *)v1 + 14) = 1;
}
else
{
LODWORD(v1) = func3(a1, "Op");
}
return (int)v1;
}

original_code:
void set_op (struct Channel *chan, char *f)
{
    if (edit_user == 1)
    {
        get_user (chan,1)->op = 1;
    }
    else
    {
        err_notinuser (chan, "Op");
    }
}

canonical_original_code:
void set_op(struct Channel *chan, char *f)
{
    if (edit_user == 1)
    {
        get_user (chan,1)->op = 1;
    }
    else
    {
        err_notinuser (chan, "Op");
    }
}


decompiled_code:
int __fastcall set_autoop(__int64 a1)
{
_QWORD *v1; // rax

if ( edit_user == 1 )
{
v1 = get_user(a1, 1);
*((_DWORD *)v1 + 15) = 1;
}
else
{
LODWORD(v1) = err_notinuser(a1, "AutoOp");
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
_QWORD *v1; // rax

if ( edit_user == 1 )
{
v1 = get_user(a1, 1);
*((_DWORD *)v1 + 15) = 1;
}
else
{
LODWORD(v1) = func3(a1, "AutoOp");
}
return (int)v1;
}

original_code:
void set_autoop (struct Channel *chan, char *f)
{
    if (edit_user ==1)
    {
        get_user (chan,1)->autoop = 1;
    }
    else
    {
        err_notinuser (chan, "AutoOp");
    }
}

canonical_original_code:
void set_autoop(struct Channel *chan, char *f)
{
    if (edit_user ==1)
    {
        get_user (chan,1)->autoop = 1;
    }
    else
    {
        err_notinuser (chan, "AutoOp");
    }
}


decompiled_code:
void __fastcall __noreturn exit_nicely(int status)
{
int i; // ebx
__int64 v2; // rsi

do_sys_log(sc, "Ilona %s closed.\n", "v2.0");
if ( sc )
free(sc);
for ( i = 1; (int)no_bots(thebots) >= i; ++i )
{
v2 = (unsigned int)i;
mybot = get_bot(thebots, v2);
do_bot_log(mybot, "Ilona %s closed.\n", "v2.0");
}
kill_bots(thebots);
if ( thebots )
free(thebots);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int status)
{
int i; // ebx
__int64 v2; // rsi

do_sys_log(sc, "Ilona %s closed.\n", "v2.0");
if ( sc )
free(sc);
for ( i = 1; (int)no_bots(thebots) >= i; ++i )
{
v2 = (unsigned int)i;
mybot = get_bot(thebots, v2);
do_bot_log(mybot, "Ilona %s closed.\n", "v2.0");
}
kill_bots(thebots);
if ( thebots )
free(thebots);
exit(status);
}

original_code:
void exit_nicely (int nice)
{
    int i;
    do_sys_log (sc, "Ilona %s closed.\n", "v2.0");
    if (sc)
    {
        free(sc);
    }
    for (i=1; i<=no_bots(thebots); i++)
    {
        mybot=get_bot (thebots, i);
        do_bot_log (mybot, "Ilona %s closed.\n", "v2.0");
    }
    kill_bots(thebots);
    if (thebots)
    {
        free (thebots);
    }
    exit(nice) ;
}

canonical_original_code:
void exit_nicely(int nice)
{
    int i;
    do_sys_log (sc, "Ilona %s closed.\n", "v2.0");
    if (sc)
    {
        free(sc);
    }
    for (i=1; i<=no_bots(thebots); i++)
    {
        mybot=get_bot (thebots, i);
        do_bot_log (mybot, "Ilona %s closed.\n", "v2.0");
    }
    kill_bots(thebots);
    if (thebots)
    {
        free (thebots);
    }
    exit(nice) ;
}

variable_types: nice int

variable_types: i int


SigInt

decompiled_code:
void __noreturn SigInt()
{
do_sys_log(sc, "User break detected.");
exit_nicely(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
do_sys_log(sc, "User break detected.");
func0(0);
}

original_code:
void SigInt (int sig)
{
    do_sys_log(sc, "User break detected.") ;
    exit_nicely(0);
}

canonical_original_code:
void SigInt(int sig)
{
    do_sys_log(sc, "User break detected.") ;
    exit_nicely(0);
}

variable_types: sig int


titles

decompiled_code:
int titles()
{
return printf("Ilona %s - (c) Copyright 1996-2012 Tristan Greaves.\n\n", "v2.0");
}

canonical_decompiled_code:
int func2()
{
return printf("Ilona %s - (c) Copyright 1996-2012 Tristan Greaves.\n\n", "v2.0");
}

original_code:
void titles (void)
{
    printf("Ilona %s - (c) Copyright 1996-2012 Tristan Greaves.\n\n", "v2.0");
}

canonical_original_code:
void titles()
{
    printf("Ilona %s - (c) Copyright 1996-2012 Tristan Greaves.\n\n", "v2.0");
}


DateToString

decompiled_code:
char *__fastcall DateToString(const time_t *a1)
{
struct tm *v1; // rax

v1 = localtime(a1);
strftime(datebuffer_1, 0xAuLL, "%d-%b-%y", v1);
return datebuffer_1;
}

canonical_decompiled_code:
char *__fastcall func0(const time_t *a1)
{
struct tm *v1; // rax

v1 = localtime(a1);
strftime(datebuffer_1, 0xAuLL, "%d-%b-%y", v1);
return datebuffer_1;
}

original_code:
char *DateToString (time_t *dat)
{
    static char datebuffer[10] ;
    struct tm *btime ;
    btime = localtime ( dat ) ;
    strftime (datebuffer, 10, "%d-%b-%y", btime) ;
    return (datebuffer) ;
}

canonical_original_code:
char *DateToString(long *dat)
{
    static char datebuffer[10];
    struct tm *btime;
    btime = localtime ( dat ) ;
    strftime (datebuffer, 10, "%d-%b-%y", btime) ;
    return (datebuffer) ;
}

variable_types:
dat
long *

variable_types:
datebuffer
char [10]

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

return_type: char *


TimeToString

decompiled_code:
char *__fastcall TimeToString(const time_t *a1)
{
struct tm *v1; // rax

v1 = localtime(a1);
strftime(timebuffer_0, 9uLL, "%H:%M:%S", v1);
return timebuffer_0;
}

canonical_decompiled_code:
char *__fastcall func1(const time_t *a1)
{
struct tm *v1; // rax

v1 = localtime(a1);
strftime(timebuffer_0, 9uLL, "%H:%M:%S", v1);
return timebuffer_0;
}

original_code:
char *TimeToString (time_t *dat)
{
    static char timebuffer[9] ;
    struct tm *btime ;
    btime = localtime ( dat ) ;
    strftime (timebuffer, 9, "%H:%M:%S", btime) ;
    return (timebuffer) ;
}

canonical_original_code:
char *TimeToString(long *dat)
{
    static char timebuffer[9];
    struct tm *btime;
    btime = localtime ( dat ) ;
    strftime (timebuffer, 9, "%H:%M:%S", btime) ;
    return (timebuffer) ;
}

variable_types:
timebuffer
char [9]

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


insertInstrucInTable

repo: thaliacampolina/sb

decompiled_code:
char *__fastcall insertInstrucInTable(__int64 a1, const char *a2, const char *a3)
{
int v4; // ebp
char *v5; // r13
char *v6; // r12
char *result; // rax

v4 = *(_DWORD *)(a1 + 1616);
v5 = (char *)calloc(0x64uLL, 1uLL);
*(_QWORD *)(a1 + 8LL * v4 + 8) = v5;
v6 = (char *)calloc(0x64uLL, 1uLL);
*(_QWORD *)(a1 + 8LL * v4 + 808) = v6;
strcpy(v5, a2);
result = strcpy(v6, a3);
*(_DWORD *)(a1 + 1616) = v4 + 1;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, const char *a2, const char *a3)
{
int v4; // ebp
char *v5; // r13
char *v6; // r12
char *result; // rax

v4 = *(_DWORD *)(a1 + 1616);
v5 = (char *)calloc(0x64uLL, 1uLL);
*(_QWORD *)(a1 + 8LL * v4 + 8) = v5;
v6 = (char *)calloc(0x64uLL, 1uLL);
*(_QWORD *)(a1 + 8LL * v4 + 808) = v6;
strcpy(v5, a2);
result = strcpy(v6, a3);
*(_DWORD *)(a1 + 1616) = v4 + 1;
return result;
}

original_code:
void insertInstrucInTable(MacroSymbols* macro, char* instruc,char* oper){
    macro->instruc_[macro->last_]=(char*) calloc(100,sizeof(char));
    macro->oper_[macro->last_]=(char*) calloc(100,sizeof(char));
    strcpy(macro->instruc_[macro->last_],instruc);
    strcpy(macro->oper_[macro->last_],oper);
    macro->last_++;
}

canonical_original_code:
void insertInstrucInTable(struct macroSymbols *macro, char *instruc, char *oper){
    macro->instruc_[macro->last_]=(char *) calloc(100,sizeof(char));
    macro->oper_[macro->last_]=(char *) calloc(100,sizeof(char));
    strcpy(macro->instruc_[macro->last_],instruc);
    strcpy(macro->oper_[macro->last_],oper);
    macro->last_++;
}

variable_types: struct macroSymbols { char *name_; char *instruc_[100]; char *oper_[100]; char *parameter_; int last_; int has_parameter_; } *

variable_types:
instruc
char *

variable_types:
oper
char *


createMacroTable

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

result = malloc(0x328uLL);
result[200] = 0;
return result;
}

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

result = malloc(0x328uLL);
result[200] = 0;
return result;
}

original_code:
MacroTable* createMacroTable(){
    MacroTable* macroTable = (MacroTable*) malloc(sizeof(MacroTable));
    macroTable->last_=0;
    return macroTable;
}

canonical_original_code:
struct macroTable *createMacroTable(){
    struct macroTable *macroTable = (MacroTable*) malloc(sizeof(MacroTable));
    macroTable->last_=0;
    return macroTable;
}

variable_types: struct macroTable { struct macroSymbols { char *name_; char *instruc_[100]; char *oper_[100]; char *parameter_; int last_; int has_parameter_; } *macros_[100]; int last_; } *

user_defined_types: struct macroTable { struct macroSymbols *macros_[100]; int last_; }


insertInMacroTable

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

v2 = *(_DWORD *)(a1 + 800);
*(_QWORD *)(a1 + 8LL * v2) = a2;
result = (unsigned int)(v2 + 1);
*(_DWORD *)(a1 + 800) = result;
return result;
}

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

v2 = *(_DWORD *)(a1 + 800);
*(_QWORD *)(a1 + 8LL * v2) = a2;
result = (unsigned int)(v2 + 1);
*(_DWORD *)(a1 + 800) = result;
return result;
}

original_code:
void insertInMacroTable(MacroTable* macroTable, MacroSymbols* macroSymbol){
    macroTable->macros_[macroTable->last_] = macroSymbol;
    macroTable->last_ ++;
}

canonical_original_code:
void insertInMacroTable(struct macroTable *macroTable, struct macroSymbols *macroSymbol){
    macroTable->macros_[macroTable->last_] = macroSymbol;
    macroTable->last_ ++;
}

variable_types:
macroSymbol
struct macroSymbols *

user_defined_types: struct macroSymbols { char *name_; char *instruc_[100]; char *oper_[100]; char *parameter_; int last_; int has_parameter_; }


decompiled_code:
__int64 __fastcall remove2P(_BYTE *a1)
{
__int64 result; // rax

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 58 )
*a1 = 0;
++a1;
}
return result;
}

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

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 58 )
*a1 = 0;
++a1;
}
return result;
}

original_code:
void remove2P(char *str)
{
     int i=0;
     while(str[i]){
 if(str[i]==':'){
     str[i]='\0';
 }
 i++;
     }
}

canonical_original_code:
void remove2P(char *str)
{
     int i = 0;
     while(str[i]){
 if(str[i]==':'){
     str[i]='\0';
 }
 i++;
     }
}

variable_types:
str
char *


findLabelName

decompiled_code:
__int64 __fastcall findLabelName(__int64 a1, const char *a2)
{
__int64 v2; // rbp
__int64 v3; // rbx

v2 = *(int *)(a1 + 800);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( strcmp(**(const char ***)(a1 + 8 * v3), a2) )
{
if ( ++v3 == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
__int64 v2; // rbp
__int64 v3; // rbx

v2 = *(int *)(a1 + 800);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( strcmp(**(const char ***)(a1 + 8 * v3), a2) )
{
if ( ++v3 == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v3;
}

original_code:
int findLabelName(MacroTable* macro, char* name){
    int i = 0;
    for(i=0;i<macro->last_;i++){
       if(strcmp(macro->macros_[i]->name_, name)==0){
           return i;
       }
    }
    return -1;
}

canonical_original_code:
int findLabelName(struct macroTable *macro, char *name){
    int i = 0;
    for(i=0;i<macro->last_;i++){
       if(strcmp(macro->macros_[i]->name_, name)==0){
           return i;
       }
    }
    return -1;
}

variable_types:
name
char *


hasParameter

decompiled_code:
_BOOL8 __fastcall hasParameter(__int64 a1, const char *a2)
{
return *(_DWORD *)(*(_QWORD *)(a1 + 8LL * (int)findLabelName(a1, a2)) + 1620LL) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1, const char *a2)
{
return *(_DWORD *)(*(_QWORD *)(a1 + 8LL * (int)func6(a1, a2)) + 1620LL) == 1;
}

original_code:
int hasParameter(MacroTable* macroTable,char* name){
    if(macroTable->macros_[findLabelName(macroTable,name)]->has_parameter_==1)
 return 1;
    else
 return 0;
}

canonical_original_code:
int hasParameter(struct macroTable *macroTable, char *name){
    if(macroTable->macros_[findLabelName(macroTable,name)]->has_parameter_==1)
 return 1;
    else
 return 0;
}


isMacro

decompiled_code:
__int64 __fastcall isMacro(__int64 a1, const char *a2)
{
int v2; // ebx
int v3; // er8
int v4; // eax

v2 = *(_DWORD *)(a1 + 800);
if ( v2 <= 0 )
return 0LL;
v3 = findLabelName(a1, a2);
v4 = 0;
if ( v3 == -1 )
{
do
++v4;
while ( v4 != v2 );
return 0LL;
}
return (unsigned int)hasParameter(a1, a2) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2)
{
int v2; // ebx
int v3; // er8
int v4; // eax

v2 = *(_DWORD *)(a1 + 800);
if ( v2 <= 0 )
return 0LL;
v3 = func6(a1, a2);
v4 = 0;
if ( v3 == -1 )
{
do
++v4;
while ( v4 != v2 );
return 0LL;
}
return (unsigned int)func9(a1, a2) + 1;
}

original_code:
int isMacro(MacroTable* macroTable, char* name){
    int i;
    for(i=0;i<macroTable->last_; i++){
        if(findLabelName(macroTable,name) != -1){
            if(hasParameter(macroTable,name)==1)
  return 2;
     else
  return 1;
        }
    }
    return 0;
}

canonical_original_code:
int isMacro(struct macroTable *macroTable, char *name){
    int i;
    for(i=0;i<macroTable->last_; i++){
        if(findLabelName(macroTable,name) != -1){
            if(hasParameter(macroTable,name)==1)
  return 2;
     else
  return 1;
        }
    }
    return 0;
}