decompiled_code:
__int64 __fastcall cfg_read_bool(__int64 a1, const char *a2, const char *a3, _BYTE *a4, char a5)
{
int v7; // eax
unsigned int v8; // er12
_BYTE *v9; // rbp
char v10; // bl
const __int32_t **v11; // rcx
__int64 v12; // rax
char *v13; // rdx
void *ptr; // [rsp+8h] [rbp-30h] BYREF

ptr = 0LL;
v7 = cfg_read_str(a1, a2, a3, (char **)&ptr, 0LL);
v8 = v7;
if ( v7 )
{
if ( v7 > 0 )
*a4 = a5;
}
else
{
v9 = ptr;
v10 = *(_BYTE *)ptr;
if ( *(_BYTE *)ptr )
{
v11 = _ctype_tolower_loc();
v12 = 1LL;
do
{
*v9 = (*v11)[v10];
v13 = (char *)ptr;
v9 = (char *)ptr + v12;
v10 = *((_BYTE *)ptr + v12++);
}
while ( v10 );
}
else
{
v13 = (char *)ptr;
}
if ( !strcmp(v13, "true") )
{
*a4 = 1;
}
else
{
if ( !strcmp(v13, "false") )
a5 = 0;
*a4 = a5;
}
free(v13);
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, const char *a2, const char *a3, _BYTE *a4, char a5)
{
int v7; // eax
unsigned int v8; // er12
_BYTE *v9; // rbp
char v10; // bl
const __int32_t **v11; // rcx
__int64 v12; // rax
char *v13; // rdx
void *ptr; // [rsp+8h] [rbp-30h] BYREF

ptr = 0LL;
v7 = func8(a1, a2, a3, (char **)&ptr, 0LL);
v8 = v7;
if ( v7 )
{
if ( v7 > 0 )
*a4 = a5;
}
else
{
v9 = ptr;
v10 = *(_BYTE *)ptr;
if ( *(_BYTE *)ptr )
{
v11 = _ctype_tolower_loc();
v12 = 1LL;
do
{
*v9 = (*v11)[v10];
v13 = (char *)ptr;
v9 = (char *)ptr + v12;
v10 = *((_BYTE *)ptr + v12++);
}
while ( v10 );
}
else
{
v13 = (char *)ptr;
}
if ( !strcmp(v13, "true") )
{
*a4 = 1;
}
else
{
if ( !strcmp(v13, "false") )
a5 = 0;
*a4 = a5;
}
free(v13);
}
return v8;
}

original_code:
int cfg_read_bool(cfg_st *handler,
        char *section, char *name, _Bool *value, _Bool default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, ((void *)0));
    if (ret == 0)
    {
        int i;
        for (i = 0; s[i]; ++i)
            s[i] = tolower(s[i]);
        if (strcmp(s, "true") == 0)
            *value = 1;
        else if (strcmp(s, "false") == 0)
            *value = 0;
        else
            *value = default_value;
        free(s);
    }
    else if (ret > 0)
    {
        *value = default_value;
    }
    return ret;
}

canonical_original_code:
int cfg_read_bool(struct cfg_section *handler, char *section, char *name, _Bool *value, _Bool default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, ((void *)0));
    if (ret == 0)
    {
        int i;
        for (i = 0; s[i]; ++i)
            s[i] = tolower(s[i]);
        if (strcmp(s, "true") == 0)
            *value = 1;
        else if (strcmp(s, "false") == 0)
            *value = 0;
        else
            *value = default_value;
        free(s);
    }
    else if (ret > 0)
    {
        *value = default_value;
    }
    return ret;
}

variable_types:
value
_Bool *

variable_types: i int


repo: leevon/rhizel

decompiled_code:
void __fastcall __noreturn thread_routine(void *a1)
{
pthread_mutex_t *v1; // r12
__int64 v2; // rax
void *v3; // rbx

v1 = (pthread_mutex_t *)((char *)a1 + 32);
while ( 1 )
{
pthread_mutex_lock(v1);
v3 = (void *)*((_QWORD *)a1 + 3);
if ( !v3 )
break;
LABEL_2:
if ( *(_DWORD *)a1 )
goto LABEL_10;
v2 = *((_QWORD *)v3 + 2);
*((_QWORD *)a1 + 3) = v2;
if ( !v2 )
pthread_cond_signal((pthread_cond_t *)((char *)a1 + 120));
pthread_mutex_unlock(v1);
(*(void (__fastcall **)(_QWORD))v3)(*((_QWORD *)v3 + 1));
free(*((void **)v3 + 1));
free(v3);
}
while ( !*(_DWORD *)a1 )
{
pthread_cond_wait((pthread_cond_t *)((char *)a1 + 72), v1);
v3 = (void *)*((_QWORD *)a1 + 3);
if ( v3 )
goto LABEL_2;
}
LABEL_10:
pthread_mutex_unlock(v1);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
pthread_mutex_t *v1; // r12
__int64 v2; // rax
void *v3; // rbx

v1 = (pthread_mutex_t *)((char *)a1 + 32);
while ( 1 )
{
pthread_mutex_lock(v1);
v3 = (void *)*((_QWORD *)a1 + 3);
if ( !v3 )
break;
LABEL_2:
if ( *(_DWORD *)a1 )
goto LABEL_10;
v2 = *((_QWORD *)v3 + 2);
*((_QWORD *)a1 + 3) = v2;
if ( !v2 )
pthread_cond_signal((pthread_cond_t *)((char *)a1 + 120));
pthread_mutex_unlock(v1);
(*(void (__fastcall **)(_QWORD))v3)(*((_QWORD *)v3 + 1));
free(*((void **)v3 + 1));
free(v3);
}
while ( !*(_DWORD *)a1 )
{
pthread_cond_wait((pthread_cond_t *)((char *)a1 + 72), v1);
v3 = (void *)*((_QWORD *)a1 + 3);
if ( v3 )
goto LABEL_2;
}
LABEL_10:
pthread_mutex_unlock(v1);
pthread_exit(0LL);
}

original_code:
static void*
thread_routine(void *arg)
{
    tpool_t *tpool = (tpool_t *)arg;
    tpool_work_t *work;
    while(1) {
        pthread_mutex_lock(&tpool->queue_lock);
        while(!tpool->queue_head && !tpool->shutdown)
        {
            pthread_cond_wait(&tpool->queue_ready, &tpool->queue_lock);
        }
        if (tpool->shutdown) {
            pthread_mutex_unlock(&tpool->queue_lock);
            pthread_exit(((void *)0));
        }
        work = tpool->queue_head;
        tpool->queue_head = tpool->queue_head->next;
        if (!tpool->queue_head)
        {
          pthread_cond_signal(&tpool->queue_empty);
        }
        pthread_mutex_unlock(&tpool->queue_lock);
        work->routine(work->arg);
        free(work->arg);
        free(work);
    }
    return ((void *)0);
}

canonical_original_code:
static void *thread_routine(void *arg)
{
    struct tpool *tpool = (tpool_t *)arg;
    struct tpool_work *work;
    while(1) {
        pthread_mutex_lock(&tpool->queue_lock);
        while(!tpool->queue_head && !tpool->shutdown)
        {
            pthread_cond_wait(&tpool->queue_ready, &tpool->queue_lock);
        }
        if (tpool->shutdown) {
            pthread_mutex_unlock(&tpool->queue_lock);
            pthread_exit(((void *)0));
        }
        work = tpool->queue_head;
        tpool->queue_head = tpool->queue_head->next;
        if (!tpool->queue_head)
        {
          pthread_cond_signal(&tpool->queue_empty);
        }
        pthread_mutex_unlock(&tpool->queue_lock);
        work->routine(work->arg);
        free(work->arg);
        free(work);
    }
    return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct tpool { int shutdown; int list_close; int max_thr_num; unsigned long *thr_id; struct tpool_work { void *(*routine)(void *); void *arg; struct tpool_work *next; } *queue_head; 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; } queue_lock; 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; } queue_ready; union pthread_cond_t queue_empty; } *

return_type: void *

user_defined_types: struct tpool { int shutdown; int list_close; int max_thr_num; unsigned long *thr_id; struct tpool_work *queue_head; union pthread_mutex_t queue_lock; union pthread_cond_t queue_ready; union pthread_cond_t queue_empty; }

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


decompiled_code:
__int64 __fastcall tpool_create(_QWORD *a1, int a2)
{
char *v2; // rax
char *v3; // rbp
void *v4; // rax
__int64 v5; // rbx
int *v7; // rbx
char *v8; // rax
int *v9; // rbx
char *v10; // rax
int *v11; // rbx
char *v12; // rax
int *v13; // rbx
char *v14; // rax

v2 = (char *)calloc(1uLL, 0xA8uLL);
if ( !v2 )
{
printf("%s: calloc failed\n", "tpool_create");
exit(1);
}
v3 = v2;
*((_DWORD *)v2 + 2) = a2;
*(_DWORD *)v2 = 0;
*((_DWORD *)v2 + 1) = 0;
*((_QWORD *)v2 + 3) = 0LL;
if ( pthread_mutex_init((pthread_mutex_t *)(v2 + 32), 0LL) )
{
v7 = _errno_location();
v8 = strerror(*v7);
printf("%s: pthread_mutex_init failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v7, v8);
exit(1);
}
if ( pthread_cond_init((pthread_cond_t *)(v3 + 72), 0LL) )
{
v9 = _errno_location();
v10 = strerror(*v9);
printf("%s: pthread_cond_init failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v9, v10);
exit(1);
}
if ( pthread_cond_init((pthread_cond_t *)(v3 + 120), 0LL) )
{
v11 = _errno_location();
v12 = strerror(*v11);
printf("%s: pthread_cond_init2 failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v11, v12);
exit(1);
}
v4 = calloc(a2, 8uLL);
*((_QWORD *)v3 + 2) = v4;
if ( !v4 )
{
printf("%s: calloc failed\n", "tpool_create");
exit(1);
}
v5 = 0LL;
if ( a2 > 0 )
{
do
{
if ( pthread_create((pthread_t *)(*((_QWORD *)v3 + 2) + v5), 0LL, (void *(*)(void *))thread_routine, v3) )
{
v13 = _errno_location();
v14 = strerror(*v13);
printf("%s:pthread_create failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v13, v14);
exit(1);
}
v5 += 8LL;
}
while ( v5 != 8LL * (unsigned int)a2 );
}
*a1 = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, int a2)
{
char *v2; // rax
char *v3; // rbp
void *v4; // rax
__int64 v5; // rbx
int *v7; // rbx
char *v8; // rax
int *v9; // rbx
char *v10; // rax
int *v11; // rbx
char *v12; // rax
int *v13; // rbx
char *v14; // rax

v2 = (char *)calloc(1uLL, 0xA8uLL);
if ( !v2 )
{
printf("%s: calloc failed\n", "tpool_create");
exit(1);
}
v3 = v2;
*((_DWORD *)v2 + 2) = a2;
*(_DWORD *)v2 = 0;
*((_DWORD *)v2 + 1) = 0;
*((_QWORD *)v2 + 3) = 0LL;
if ( pthread_mutex_init((pthread_mutex_t *)(v2 + 32), 0LL) )
{
v7 = _errno_location();
v8 = strerror(*v7);
printf("%s: pthread_mutex_init failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v7, v8);
exit(1);
}
if ( pthread_cond_init((pthread_cond_t *)(v3 + 72), 0LL) )
{
v9 = _errno_location();
v10 = strerror(*v9);
printf("%s: pthread_cond_init failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v9, v10);
exit(1);
}
if ( pthread_cond_init((pthread_cond_t *)(v3 + 120), 0LL) )
{
v11 = _errno_location();
v12 = strerror(*v11);
printf("%s: pthread_cond_init2 failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v11, v12);
exit(1);
}
v4 = calloc(a2, 8uLL);
*((_QWORD *)v3 + 2) = v4;
if ( !v4 )
{
printf("%s: calloc failed\n", "tpool_create");
exit(1);
}
v5 = 0LL;
if ( a2 > 0 )
{
do
{
if ( pthread_create((pthread_t *)(*((_QWORD *)v3 + 2) + v5), 0LL, (void *(*)(void *))thread_routine, v3) )
{
v13 = _errno_location();
v14 = strerror(*v13);
printf("%s:pthread_create failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v13, v14);
exit(1);
}
v5 += 8LL;
}
while ( v5 != 8LL * (unsigned int)a2 );
}
*a1 = v3;
return 0LL;
}

original_code:
int
tpool_create(tpool_t **ppTpool, int max_thr_num)
{
    int i;
    tpool_t *tpool = ((void *)0);
    tpool = calloc(1, sizeof(tpool_t));
    if (!tpool) {
        printf("%s: calloc failed\n", __FUNCTION__);
        exit(1);
    }
    tpool->max_thr_num = max_thr_num;
    tpool->shutdown = 0;
    tpool->list_close = 0;
    tpool->queue_head = ((void *)0);
    if (pthread_mutex_init(&tpool->queue_lock, ((void *)0)) !=0) {
        printf("%s: pthread_mutex_init failed, errno:%d, error:%s\n",
            __FUNCTION__, (*__errno_location ()), strerror((*__errno_location ())));
        exit(1);
    }
    if (pthread_cond_init(&tpool->queue_ready, ((void *)0)) !=0 ) {
        printf("%s: pthread_cond_init failed, errno:%d, error:%s\n",
            __FUNCTION__, (*__errno_location ()), strerror((*__errno_location ())));
        exit(1);
    }
    if (pthread_cond_init(&tpool->queue_empty, ((void *)0)) !=0 ) {
        printf("%s: pthread_cond_init2 failed, errno:%d, error:%s\n",
            __FUNCTION__, (*__errno_location ()), strerror((*__errno_location ())));
        exit(1);
    }
    tpool->thr_id = calloc(max_thr_num, sizeof(pthread_t));
    if (!tpool->thr_id) {
        printf("%s: calloc failed\n", __FUNCTION__);
        exit(1);
    }
    for (i = 0; i < max_thr_num; ++i) {
        if (pthread_create(&tpool->thr_id[i], ((void *)0), thread_routine, (void*)tpool) != 0){
            printf("%s:pthread_create failed, errno:%d, error:%s\n", __FUNCTION__,
                (*__errno_location ()), strerror((*__errno_location ())));
            exit(1);
        }
    }
    *ppTpool = tpool;
    return 0;
}

canonical_original_code:
int tpool_create(struct tpool **ppTpool, int max_thr_num)
{
    int i;
    struct tpool *tpool = ((void *)0);
    tpool = calloc(1, sizeof(tpool_t));
    if (!tpool) {
        printf("%s: calloc failed\n", __FUNCTION__);
        exit(1);
    }
    tpool->max_thr_num = max_thr_num;
    tpool->shutdown = 0;
    tpool->list_close = 0;
    tpool->queue_head = ((void *)0);
    if (pthread_mutex_init(&tpool->queue_lock, ((void *)0)) !=0) {
        printf("%s: pthread_mutex_init failed, errno:%d, error:%s\n",
            __FUNCTION__, (*__errno_location ()), strerror((*__errno_location ())));
        exit(1);
    }
    if (pthread_cond_init(&tpool->queue_ready, ((void *)0)) !=0 ) {
        printf("%s: pthread_cond_init failed, errno:%d, error:%s\n",
            __FUNCTION__, (*__errno_location ()), strerror((*__errno_location ())));
        exit(1);
    }
    if (pthread_cond_init(&tpool->queue_empty, ((void *)0)) !=0 ) {
        printf("%s: pthread_cond_init2 failed, errno:%d, error:%s\n",
            __FUNCTION__, (*__errno_location ()), strerror((*__errno_location ())));
        exit(1);
    }
    tpool->thr_id = calloc(max_thr_num, sizeof(pthread_t));
    if (!tpool->thr_id) {
        printf("%s: calloc failed\n", __FUNCTION__);
        exit(1);
    }
    for (i = 0; i < max_thr_num; ++i) {
        if (pthread_create(&tpool->thr_id[i], ((void *)0), thread_routine, (void *)tpool) != 0){
            printf("%s:pthread_create failed, errno:%d, error:%s\n", __FUNCTION__,
                (*__errno_location ()), strerror((*__errno_location ())));
            exit(1);
        }
    }
    *ppTpool = tpool;
    return 0;
}

variable_types: struct tpool { int shutdown; int list_close; int max_thr_num; unsigned long *thr_id; struct tpool_work { void *(*routine)(void *); void *arg; struct tpool_work *next; } *queue_head; 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; } queue_lock; 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; } queue_ready; union pthread_cond_t queue_empty; } **

return_type: int


decompiled_code:
void __fastcall tpool_destroy(void *ptr, int a2)
{
pthread_mutex_t *v2; // r12
__int64 v3; // rbp
__int64 i; // rbp

if ( !*((_DWORD *)ptr + 1) )
{
v2 = (pthread_mutex_t *)((char *)ptr + 32);
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 32));
*((_DWORD *)ptr + 1) = 1;
if ( a2 && *((_QWORD *)ptr + 3) )
pthread_cond_wait((pthread_cond_t *)((char *)ptr + 120), v2);
*(_DWORD *)ptr = 1;
pthread_cond_broadcast((pthread_cond_t *)((char *)ptr + 72));
pthread_mutex_unlock(v2);
if ( *((int *)ptr + 2) > 0 )
{
v3 = 0LL;
do
pthread_join(*(_QWORD *)(*((_QWORD *)ptr + 2) + 8 * v3++), 0LL);
while ( *((_DWORD *)ptr + 2) > (int)v3 );
}
free(*((void **)ptr + 2));
for ( i = *((_QWORD *)ptr + 3); i; i = *((_QWORD *)ptr + 3) )
{
*((_QWORD *)ptr + 3) = *(_QWORD *)(i + 16);
free(*(void **)(i + 8));
free((void *)i);
}
pthread_mutex_destroy(v2);
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 72));
free(ptr);
}
}

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

if ( !*((_DWORD *)ptr + 1) )
{
v2 = (pthread_mutex_t *)((char *)ptr + 32);
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 32));
*((_DWORD *)ptr + 1) = 1;
if ( a2 && *((_QWORD *)ptr + 3) )
pthread_cond_wait((pthread_cond_t *)((char *)ptr + 120), v2);
*(_DWORD *)ptr = 1;
pthread_cond_broadcast((pthread_cond_t *)((char *)ptr + 72));
pthread_mutex_unlock(v2);
if ( *((int *)ptr + 2) > 0 )
{
v3 = 0LL;
do
pthread_join(*(_QWORD *)(*((_QWORD *)ptr + 2) + 8 * v3++), 0LL);
while ( *((_DWORD *)ptr + 2) > (int)v3 );
}
free(*((void **)ptr + 2));
for ( i = *((_QWORD *)ptr + 3); i; i = *((_QWORD *)ptr + 3) )
{
*((_QWORD *)ptr + 3) = *(_QWORD *)(i + 16);
free(*(void **)(i + 8));
free((void *)i);
}
pthread_mutex_destroy(v2);
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 72));
free(ptr);
}
}

original_code:
void
tpool_destroy(tpool_t *tpool,int flag)
{
    int i;
    tpool_work_t *member;
    if (tpool->list_close) {
        return;
    }
    pthread_mutex_lock(&tpool->queue_lock);
    tpool->list_close =1;
    if (flag)
    {
      if (tpool->queue_head)
      {
        pthread_cond_wait(&tpool->queue_empty, &tpool->queue_lock);
      }
    }
    tpool->shutdown = 1;
    pthread_cond_broadcast(&tpool->queue_ready);
    pthread_mutex_unlock(&tpool->queue_lock);
    for (i = 0; i < tpool->max_thr_num; ++i) {
        pthread_join(tpool->thr_id[i], ((void *)0));
    }
    free(tpool->thr_id);
    while(tpool->queue_head) {
        member = tpool->queue_head;
        tpool->queue_head = tpool->queue_head->next;
        free(member->arg);
        free(member);
    }
    pthread_mutex_destroy(&tpool->queue_lock);
    pthread_cond_destroy(&tpool->queue_ready);
    free(tpool);
}

canonical_original_code:
void tpool_destroy(struct tpool *tpool, int flag)
{
    int i;
    struct tpool_work *member;
    if (tpool->list_close) {
        return;
    }
    pthread_mutex_lock(&tpool->queue_lock);
    tpool->list_close =1;
    if (flag)
    {
      if (tpool->queue_head)
      {
        pthread_cond_wait(&tpool->queue_empty, &tpool->queue_lock);
      }
    }
    tpool->shutdown = 1;
    pthread_cond_broadcast(&tpool->queue_ready);
    pthread_mutex_unlock(&tpool->queue_lock);
    for (i = 0; i < tpool->max_thr_num; ++i) {
        pthread_join(tpool->thr_id[i], ((void *)0));
    }
    free(tpool->thr_id);
    while(tpool->queue_head) {
        member = tpool->queue_head;
        tpool->queue_head = tpool->queue_head->next;
        free(member->arg);
        free(member);
    }
    pthread_mutex_destroy(&tpool->queue_lock);
    pthread_cond_destroy(&tpool->queue_ready);
    free(tpool);
}

variable_types: flag int

variable_types: struct tpool_work { void *(*routine)(void *); void *arg; struct tpool_work *next; } *

return_type: void

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 tpool_add_work(__int64 a1, __int64 a2, const void *a3, int a4)
{
_QWORD *v7; // rax
_QWORD *v8; // rbp
void *v9; // rdi
unsigned int v10; // er12
__int64 v11; // rax
__int64 v12; // rdx

if ( a2 )
{
v7 = malloc(0x18uLL);
v8 = v7;
if ( v7 )
{
*v7 = a2;
v9 = malloc(a4);
v8[1] = v9;
if ( v9 )
{
memcpy(v9, a3, a4);
v8[2] = 0LL;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v10 = *(_DWORD *)(a1 + 4);
if ( v10 )
{
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
v10 = 0;
}
else
{
v11 = *(_QWORD *)(a1 + 24);
if ( v11 )
{
do
{
v12 = v11;
v11 = *(_QWORD *)(v11 + 16);
}
while ( v11 );
*(_QWORD *)(v12 + 16) = v8;
}
else
{
*(_QWORD *)(a1 + 24) = v8;
}
pthread_cond_signal((pthread_cond_t *)(a1 + 72));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
}
}
else
{
v10 = 0;
}
}
else
{
printf("%s:malloc failed\n", "tpool_add_work");
v10 = -1;
}
}
else
{
printf("%s:Invalid argument\n", "tpool_add_work");
v10 = -1;
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, const void *a3, int a4)
{
_QWORD *v7; // rax
_QWORD *v8; // rbp
void *v9; // rdi
unsigned int v10; // er12
__int64 v11; // rax
__int64 v12; // rdx

if ( a2 )
{
v7 = malloc(0x18uLL);
v8 = v7;
if ( v7 )
{
*v7 = a2;
v9 = malloc(a4);
v8[1] = v9;
if ( v9 )
{
memcpy(v9, a3, a4);
v8[2] = 0LL;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v10 = *(_DWORD *)(a1 + 4);
if ( v10 )
{
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
v10 = 0;
}
else
{
v11 = *(_QWORD *)(a1 + 24);
if ( v11 )
{
do
{
v12 = v11;
v11 = *(_QWORD *)(v11 + 16);
}
while ( v11 );
*(_QWORD *)(v12 + 16) = v8;
}
else
{
*(_QWORD *)(a1 + 24) = v8;
}
pthread_cond_signal((pthread_cond_t *)(a1 + 72));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
}
}
else
{
v10 = 0;
}
}
else
{
printf("%s:malloc failed\n", "tpool_add_work");
v10 = -1;
}
}
else
{
printf("%s:Invalid argument\n", "tpool_add_work");
v10 = -1;
}
return v10;
}

original_code:
int
tpool_add_work(tpool_t *tpool, void*(*routine)(void*), void *arg, int len)
{
    tpool_work_t *work, *member;
    if (!routine){
        printf("%s:Invalid argument\n", __FUNCTION__);
        return -1;
    }
    work = malloc(sizeof(tpool_work_t));
    if (!work) {
        printf("%s:malloc failed\n", __FUNCTION__);
        return -1;
    }
    work->routine = routine;
    work->arg = (void*)malloc(len);
    if (!work->arg) return 0;
    memcpy(work->arg, arg, len);
    work->next = ((void *)0);
    pthread_mutex_lock(&tpool->queue_lock);
    if (tpool->list_close)
    {
      pthread_mutex_unlock(&tpool->queue_lock);
      return 0;
    }
    member = tpool->queue_head;
    if (!member) {
        tpool->queue_head = work;
    } else {
        while(member->next) {
            member = member->next;
        }
        member->next = work;
    }
    pthread_cond_signal(&tpool->queue_ready);
    pthread_mutex_unlock(&tpool->queue_lock);
    return 0;
}

canonical_original_code:
int tpool_add_work(struct tpool *tpool, void *(*routine)(void *), void *arg, int len)
{
    struct tpool_work *work; struct tpool_work *member;
    if (!routine){
        printf("%s:Invalid argument\n", __FUNCTION__);
        return -1;
    }
    work = malloc(sizeof(tpool_work_t));
    if (!work) {
        printf("%s:malloc failed\n", __FUNCTION__);
        return -1;
    }
    work->routine = routine;
    work->arg = (void *)malloc(len);
    if (!work->arg) return 0;
    memcpy(work->arg, arg, len);
    work->next = ((void *)0);
    pthread_mutex_lock(&tpool->queue_lock);
    if (tpool->list_close)
    {
      pthread_mutex_unlock(&tpool->queue_lock);
      return 0;
    }
    member = tpool->queue_head;
    if (!member) {
        tpool->queue_head = work;
    } else {
        while(member->next) {
            member = member->next;
        }
        member->next = work;
    }
    pthread_cond_signal(&tpool->queue_ready);
    pthread_mutex_unlock(&tpool->queue_lock);
    return 0;
}

variable_types:
routine
void *(*)(void *)

variable_types: len int

user_defined_types: struct tpool_work { void *(*routine)(void *); void *arg; struct tpool_work *next; }


getTcpConSoc

decompiled_code:
__int64 __fastcall getTcpConSoc(char *cp, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[6] = 0LL;
*(_WORD *)v5.sa_data = _bswap_16(a2);
*(_DWORD *)&v5.sa_data[2] = inet_addr(cp);
v2 = socket(2, 1, 0);
v3 = v2;
if ( v2 < 0 )
{
perror("create\n");
}
else if ( connect(v2, &v5, 0x10u) < 0 )
{
perror("connect\n");
close(v3);
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *cp, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[6] = 0LL;
*(_WORD *)v5.sa_data = func0(a2);
*(_DWORD *)&v5.sa_data[2] = inet_addr(cp);
v2 = socket(2, 1, 0);
v3 = v2;
if ( v2 < 0 )
{
perror("create\n");
}
else if ( connect(v2, &v5, 0x10u) < 0 )
{
perror("connect\n");
close(v3);
v3 = -1;
}
return v3;
}

original_code:
int getTcpConSoc(char *serverIp, int port)
{
  struct sockaddr_in client_addr;
  bzero(&client_addr, sizeof(client_addr));
  client_addr.sin_family = 2;
  client_addr.sin_port = htons(port);
  client_addr.sin_addr.s_addr = inet_addr(serverIp);
  int soc = -1;
  if((soc = socket(2,SOCK_STREAM,0)) < 0)
  {
    perror("create\n");
    return soc;
  }
  if(connect(soc,(struct sockaddr *)&client_addr,sizeof(client_addr)) < 0)
  {
    perror("connect\n");
    close(soc);
    return -1;
  }
  return soc;
}

variable_types:
serverIp
char *

variable_types: port int

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

variable_types: soc int

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

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


clsSoc

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

if ( a1 > 0 )
result = close(a1);
return result;
}

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

if ( a1 > 0 )
result = close(a1);
return result;
}

original_code:
void clsSoc(int soc)
{
  if (soc > 0)
  {
    close(soc);
  }
}


sendCmdStr

decompiled_code:
__int64 __fastcall sendCmdStr(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
if ( send(fd, buf, v2 + 1, 0) >= 0 )
return 0LL;
perror("send");
return 4294967197LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
if ( send(fd, buf, v2 + 1, 0) >= 0 )
return 0LL;
perror("send");
return 4294967197LL;
}

original_code:
int sendCmdStr(int soc, char *sdCmd)
{
  if(send(soc,sdCmd,strlen(sdCmd)+1,0) < 0)
  {
    perror("send");
    return -99;
  }
  return 0;
}

variable_types:
sdCmd
char *


recvInfoStr

decompiled_code:
__int64 __fastcall recvInfoStr(int fd, __int64 a2, int a3)
{
int v4; // ebp
int v5; // er13
__int64 v6; // r14
unsigned int v7; // er15
int v9; // eax
int v10; // eax
int v11; // ebx
__int64 buf[2]; // [rsp+10h] [rbp-8C8h] BYREF
char v14[1008]; // [rsp+20h] [rbp-8B8h] BYREF
char src[8]; // [rsp+410h] [rbp-4C8h] BYREF
__int64 v16; // [rsp+418h] [rbp-4C0h]
char v17[1008]; // [rsp+420h] [rbp-4B8h] BYREF
fd_set readfds; // [rsp+810h] [rbp-C8h] BYREF
struct timeval timeout; // [rsp+890h] [rbp-48h] BYREF

v4 = a3;
timeout.tv_sec = 80LL;
timeout.tv_usec = 50LL;
memset(&readfds, 0, sizeof(readfds));
v5 = fd / 64;
v6 = 1LL << (fd % 64);
readfds.fds_bits[fd / 64] |= v6;
if ( !a3 )
return 0;
v7 = 0;
while ( 1 )
{
v9 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( v9 == -1 )
{
perror("select.");
return (unsigned int)-1;
}
if ( v9 )
break;
LABEL_5:
sendCmdStr(fd, "LT");
LABEL_6:
if ( !--v4 )
return v7;
}
if ( (readfds.fds_bits[v5] & v6) == 0 )
goto LABEL_6;
buf[0] = 0LL;
buf[1] = 0LL;
memset(v14, 0, sizeof(v14));
v10 = recv(fd, buf, 0x400uLL, 0);
if ( v10 < 0 )
{
perror("recv.");
return (unsigned int)-1;
}
if ( v10 )
{
*(_QWORD *)src = 0LL;
v16 = 0LL;
memset(v17, 0, sizeof(v17));
if ( memcmp("LT", src, 2uLL) )
{
v11 = v10 - 6;
strncpy((char *)(a2 + (int)v7), src, v10 - 6);
v7 += v11;
timeout.tv_sec /= 2LL;
goto LABEL_6;
}
goto LABEL_5;
}
perror("recv connect err");
return (unsigned int)-99;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __int64 a2, int a3)
{
int v4; // ebp
int v5; // er13
__int64 v6; // r14
unsigned int v7; // er15
int v9; // eax
int v10; // eax
int v11; // ebx
__int64 buf[2]; // [rsp+10h] [rbp-8C8h] BYREF
char v14[1008]; // [rsp+20h] [rbp-8B8h] BYREF
char src[8]; // [rsp+410h] [rbp-4C8h] BYREF
__int64 v16; // [rsp+418h] [rbp-4C0h]
char v17[1008]; // [rsp+420h] [rbp-4B8h] BYREF
fd_set readfds; // [rsp+810h] [rbp-C8h] BYREF
struct timeval timeout; // [rsp+890h] [rbp-48h] BYREF

v4 = a3;
timeout.tv_sec = 80LL;
timeout.tv_usec = 50LL;
memset(&readfds, 0, sizeof(readfds));
v5 = fd / 64;
v6 = 1LL << (fd % 64);
readfds.fds_bits[fd / 64] |= v6;
if ( !a3 )
return 0;
v7 = 0;
while ( 1 )
{
v9 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( v9 == -1 )
{
perror("select.");
return (unsigned int)-1;
}
if ( v9 )
break;
LABEL_5:
func3(fd, "LT");
LABEL_6:
if ( !--v4 )
return v7;
}
if ( (readfds.fds_bits[v5] & v6) == 0 )
goto LABEL_6;
buf[0] = 0LL;
buf[1] = 0LL;
memset(v14, 0, sizeof(v14));
v10 = recv(fd, buf, 0x400uLL, 0);
if ( v10 < 0 )
{
perror("recv.");
return (unsigned int)-1;
}
if ( v10 )
{
*(_QWORD *)src = 0LL;
v16 = 0LL;
memset(v17, 0, sizeof(v17));
if ( memcmp("LT", src, 2uLL) )
{
v11 = v10 - 6;
strncpy((char *)(a2 + (int)v7), src, v10 - 6);
v7 += v11;
timeout.tv_sec /= 2LL;
goto LABEL_6;
}
goto LABEL_5;
}
perror("recv connect err");
return (unsigned int)-99;
}

original_code:
int recvInfoStr(int soc, char *recBuf, int iDftRdCt)
{
  struct timeval timeout;
  timeout.tv_sec = 80;
  timeout.tv_usec = 50;
  fd_set read_fds;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&read_fds)->__fds_bits)[((soc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((soc) % (8 * (int) sizeof (__fd_mask)))))));
  int iLen = 0;
  while(iDftRdCt--)
  {
    int iSelRet = select(soc+1,&read_fds,((void *)0),((void *)0),&timeout);
    if (-1 == iSelRet)
    {
      perror("select.");
      return -1;
    }
    else if (0 == iSelRet)
    {
      sendCmdStr(soc, "LT");
      continue;
    }
    else
    {
      if (((((&read_fds)->__fds_bits)[((soc) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((soc) % (8 * (int) sizeof (__fd_mask)))))) != 0))
      {
        char strRecvInfo[1024] = {0};
        int iRecRet = recv(soc,strRecvInfo,sizeof(strRecvInfo),0);
        if(iRecRet < 0)
        {
          perror("recv.");
          return -1;
        }
        if (iRecRet == 0)
        {
          perror("recv connect err");
          return -99;
        }
        char strJmInfo[1024] = {0};
        iRecRet -= 6;
        if (0 == strncmp("LT",strJmInfo, 2))
        {
          sendCmdStr(soc, "LT");
          continue;
        }
        strncpy(recBuf+iLen, strJmInfo, iRecRet);
        iLen += iRecRet;
        timeout.tv_sec /= 2;
      }
    }
  }
  return iLen;
}

canonical_original_code:
int recvInfoStr(int soc, char *recBuf, int iDftRdCt)
{
  struct timeval timeout;
  timeout.tv_sec = 80;
  timeout.tv_usec = 50;
  struct fd_set read_fds;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&read_fds)->__fds_bits)[((soc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((soc) % (8 * (int) sizeof (__fd_mask)))))));
  int iLen = 0;
  while(iDftRdCt--)
  {
    int iSelRet = select(soc+1,&read_fds,((void *)0),((void *)0),&timeout);
    if (-1 == iSelRet)
    {
      perror("select.");
      return -1;
    }
    else if (0 == iSelRet)
    {
      sendCmdStr(soc, "LT");
      continue;
    }
    else
    {
      if (((((&read_fds)->__fds_bits)[((soc) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((soc) % (8 * (int) sizeof (__fd_mask)))))) != 0))
      {
        char strRecvInfo[1024] = {0};
        int iRecRet = recv(soc,strRecvInfo,sizeof(strRecvInfo),0);
        if(iRecRet < 0)
        {
          perror("recv.");
          return -1;
        }
        if (iRecRet == 0)
        {
          perror("recv connect err");
          return -99;
        }
        char strJmInfo[1024] = {0};
        iRecRet -= 6;
        if (0 == strncmp("LT",strJmInfo, 2))
        {
          sendCmdStr(soc, "LT");
          continue;
        }
        strncpy(recBuf+iLen, strJmInfo, iRecRet);
        iLen += iRecRet;
        timeout.tv_sec /= 2;
      }
    }
  }
  return iLen;
}

variable_types:
recBuf
char *

variable_types: iDftRdCt int

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

variable_types: iLen int

variable_types: iSelRet int

variable_types:
strRecvInfo
char [1024]

variable_types: iRecRet int

variable_types:
strJmInfo
char [1024]


pstrchr

decompiled_code:
void __fastcall pstrchr(const char *a1, char a2, int a3, char *a4)
{
char *v6; // rax
int v7; // ebx

if ( a1 )
{
v6 = strchr(a1, a2);
if ( v6 )
{
if ( a3 <= 1 )
{
LABEL_7:
strcpy(a4, v6);
}
else
{
v7 = 1;
while ( 1 )
{
v6 = strchr(v6 + 1, a2);
if ( !v6 )
break;
if ( a3 == ++v7 )
goto LABEL_7;
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func0(const char *a1, char a2, int a3, char *a4)
{
char *v6; // rax
int v7; // ebx

if ( a1 )
{
v6 = strchr(a1, a2);
if ( v6 )
{
if ( a3 <= 1 )
{
LABEL_7:
strcpy(a4, v6);
}
else
{
v7 = 1;
while ( 1 )
{
v6 = strchr(v6 + 1, a2);
if ( !v6 )
break;
if ( a3 == ++v7 )
goto LABEL_7;
}
}
}
}
}

original_code:
static void pstrchr( char * str, char ch, int n, char * p )
{
  char * tmp = ((void *)0);
  int i = 0;
  int k = 0;
  if(!str) return;
  tmp = strchr(str, ch);
  if( !tmp ) return;
  i++;
  for(k=i; k<n; k++)
  {
    tmp = strchr(tmp+1, ch);
    if(!tmp)
    {
      return;
    }
  }
  strcpy(p, tmp);
}

canonical_original_code:
static void pstrchr(char *str, char ch, int n, char *p)
{
  char *tmp = ((void *)0);
  int i = 0;
  int k = 0;
  if(!str) return;
  tmp = strchr(str, ch);
  if( !tmp ) return;
  i++;
  for(k=i; k<n; k++)
  {
    tmp = strchr(tmp+1, ch);
    if(!tmp)
    {
      return;
    }
  }
  strcpy(p, tmp);
}

variable_types:
str
char *

variable_types: ch char

variable_types: n int

variable_types:
p
char *

variable_types:
tmp
char *

variable_types: i int

variable_types: k int


daemonInit

decompiled_code:
int daemonInit()
{
if ( fork() > 0 )
exit(0);
sleep(1u);
setsid();
signal(1, (__sighandler_t)((char *)pstrchr + 1));
if ( fork() > 0 )
exit(0);
sleep(1u);
close(0);
close(1);
return close(2);
}

canonical_decompiled_code:
int func1()
{
if ( fork() > 0 )
exit(0);
sleep(1u);
setsid();
signal(1, (__sighandler_t)((char *)pstrchr + 1));
if ( fork() > 0 )
exit(0);
sleep(1u);
close(0);
close(1);
return close(2);
}

original_code:
void daemonInit(void)
{
  int i;
  if(fork() > 0) exit(0);
  sleep(1);
  setsid();
  signal(1,((__sighandler_t) 1));
  if(fork() > 0) exit(0);
  sleep(1);
  for(i = 0; i < 3; i++)
  {
    close(i);
  }
}

canonical_original_code:
void daemonInit()
{
  int i;
  if(fork() > 0) exit(0);
  sleep(1);
  setsid();
  signal(1,((void (*)(int)) 1));
  if(fork() > 0) exit(0);
  sleep(1);
  for(i = 0; i < 3; i++)
  {
    close(i);
  }
}


isNumber

decompiled_code:
__int64 __fastcall isNumber(const char *a1)
{
const char *v1; // rbx
char *v2; // rbp
const unsigned __int16 **v3; // rax
__int64 v4; // rdx

if ( !a1 )
return 0LL;
v1 = a1;
v2 = (char *)&a1[strlen(a1)];
while ( v1 != v2 )
{
v3 = _ctype_b_loc();
v4 = *v1++;
if ( ((*v3)[v4] & 0x800) == 0 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
const char *v1; // rbx
char *v2; // rbp
const unsigned __int16 **v3; // rax
__int64 v4; // rdx

if ( !a1 )
return 0LL;
v1 = a1;
v2 = (char *)&a1[strlen(a1)];
while ( v1 != v2 )
{
v3 = _ctype_b_loc();
v4 = *v1++;
if ( ((*v3)[v4] & 0x800) == 0 )
return 0LL;
}
return 1LL;
}

original_code:
int isNumber(char * sNumber)
{
  if (!sNumber) return 0;
  int i;
  for(i=0; i<strlen(sNumber); ++i)
  {
    if(0 == ((*__ctype_b_loc ())[(int) ((sNumber[i]))] & (unsigned short int) _ISdigit))
    {
      return 0;
    }
  }
  return 1;
}

canonical_original_code:
int isNumber(char *sNumber)
{
  if (!sNumber) return 0;
  int i;
  for(i=0; i<strlen(sNumber); ++i)
  {
    if(0 == ((*__ctype_b_loc ())[(int) ((sNumber[i]))] & (unsigned short) _ISdigit))
    {
      return 0;
    }
  }
  return 1;
}

variable_types:
sNumber
char *


ltrim

decompiled_code:
void *__fastcall ltrim(void *src)
{
int v1; // er12
const unsigned __int16 *v2; // rdx
const char *i; // rbx
size_t v4; // rax

if ( src )
{
v1 = strlen((const char *)src);
v2 = *_ctype_b_loc();
for ( i = (const char *)src; (v2[*i] & 0x2000) != 0; ++i )
;
v4 = strlen(i);
if ( v1 > v4 )
memcpy(src, i, v4 + 1);
}
return src;
}

canonical_decompiled_code:
void *__fastcall func3(void *src)
{
int v1; // er12
const unsigned __int16 *v2; // rdx
const char *i; // rbx
size_t v4; // rax

if ( src )
{
v1 = strlen((const char *)src);
v2 = *_ctype_b_loc();
for ( i = (const char *)src; (v2[*i] & 0x2000) != 0; ++i )
;
v4 = strlen(i);
if ( v1 > v4 )
memcpy(src, i, v4 + 1);
}
return src;
}

original_code:
char* ltrim(char *s)
{
  if (!s) return ((void *)0);
  char *ptmp = s;
  int tmpLen = strlen(s);
  while(((*__ctype_b_loc ())[(int) ((*ptmp))] & (unsigned short int) _ISspace))
  {
    ++ptmp;
  }
  if (tmpLen > strlen(ptmp))
  {
    memcpy(s, ptmp, strlen(ptmp)+1);
  }
  return s;
}

canonical_original_code:
char *ltrim(char *s)
{
  if (!s) return ((void *)0);
  char *ptmp = s;
  int tmpLen = strlen(s);
  while(((*__ctype_b_loc ())[(int) ((*ptmp))] & (unsigned short) _ISspace))
  {
    ++ptmp;
  }
  if (tmpLen > strlen(ptmp))
  {
    memcpy(s, ptmp, strlen(ptmp)+1);
  }
  return s;
}

variable_types:
s
char *

variable_types:
ptmp
char *

variable_types: tmpLen int

return_type: char *


rtrim

decompiled_code:
const char *__fastcall rtrim(const char *a1)
{
int v2; // ebp
const unsigned __int16 **v3; // rsi
char *v4; // rax
__int64 v5; // rdi

if ( a1 )
{
v2 = strlen(a1);
if ( v2 )
{
v3 = _ctype_b_loc();
v4 = (char *)&a1[v2 - 1];
v5 = (__int64)&a1[v2 - 2 - (v2 - 1)];
do
{
if ( ((*v3)[*v4] & 0x2000) == 0 )
break;
*v4-- = 0;
}
while ( v4 != (char *)v5 );
}
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func4(const char *a1)
{
int v2; // ebp
const unsigned __int16 **v3; // rsi
char *v4; // rax
__int64 v5; // rdi

if ( a1 )
{
v2 = strlen(a1);
if ( v2 )
{
v3 = _ctype_b_loc();
v4 = (char *)&a1[v2 - 1];
v5 = (__int64)&a1[v2 - 2 - (v2 - 1)];
do
{
if ( ((*v3)[*v4] & 0x2000) == 0 )
break;
*v4-- = 0;
}
while ( v4 != (char *)v5 );
}
}
return a1;
}

original_code:
char* rtrim(char *s)
{
  if (!s) return ((void *)0);
  char *ptmp = s;
  int len = strlen(s);
  while (len)
  {
    if (((*__ctype_b_loc ())[(int) ((*(ptmp+len-1)))] & (unsigned short int) _ISspace))
    {
      *(ptmp+len-1) = '\0';
      --len;
    }
    else
    {
      break;
    }
  }
  return s;
}

canonical_original_code:
char *rtrim(char *s)
{
  if (!s) return ((void *)0);
  char *ptmp = s;
  int len = strlen(s);
  while (len)
  {
    if (((*__ctype_b_loc ())[(int) ((*(ptmp+len-1)))] & (unsigned short) _ISspace))
    {
      *(ptmp+len-1) = '\0';
      --len;
    }
    else
    {
      break;
    }
  }
  return s;
}

variable_types: len int


getSysDate

decompiled_code:
char *__fastcall getSysDate(char *s)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

if ( s )
{
timer = time(0LL);
v1 = localtime(&timer);
sprintf(
s,
"%04d%02d%02d%02d%02d%02d",
(unsigned int)(v1->tm_year + 1900),
(unsigned int)(v1->tm_mon + 1),
(unsigned int)v1->tm_mday,
(unsigned int)v1->tm_hour,
(unsigned int)v1->tm_min,
(unsigned int)v1->tm_sec);
s[14] = 0;
}
return s;
}

canonical_decompiled_code:
char *__fastcall func6(char *s)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

if ( s )
{
timer = time(0LL);
v1 = localtime(&timer);
sprintf(
s,
"%04d%02d%02d%02d%02d%02d",
(unsigned int)(v1->tm_year + 1900),
(unsigned int)(v1->tm_mon + 1),
(unsigned int)v1->tm_mday,
(unsigned int)v1->tm_hour,
(unsigned int)v1->tm_min,
(unsigned int)v1->tm_sec);
s[14] = 0;
}
return s;
}

original_code:
char* getSysDate(char * sysDate)
{
  if (!sysDate) return ((void *)0);
  time_t sec;
  struct tm *t;
  sec = time(((void *)0));
  t = localtime(&sec);
  sprintf(sysDate,"%04d%02d%02d%02d%02d%02d", t->tm_year+1900,t->tm_mon+1, t->tm_mday, t->tm_hour,t->tm_min,t->tm_sec);
  sysDate[14]='\0';
  return sysDate;
}

canonical_original_code:
char *getSysDate(char *sysDate)
{
  if (!sysDate) return ((void *)0);
  long sec;
  struct tm *t;
  sec = time(((void *)0));
  t = localtime(&sec);
  sprintf(sysDate,"%04d%02d%02d%02d%02d%02d", t->tm_year+1900,t->tm_mon+1, t->tm_mday, t->tm_hour,t->tm_min,t->tm_sec);
  sysDate[14]='\0';
  return sysDate;
}

variable_types:
sysDate
char *

variable_types: sec long

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


isDate

decompiled_code:
__int64 __fastcall isDate(__int64 a1)
{
size_t v1; // rdx
__int64 result; // rax
int v3; // er12
int v4; // ebp
int v5; // eax
int v6; // edx
char nptr[4]; // [rsp+1h] [rbp-1Dh] BYREF
char v8; // [rsp+5h] [rbp-19h]

if ( !a1 )
return 0LL;
v1 = strlen((const char *)a1);
result = 0LL;
if ( v1 == 8 )
{
result = isNumber((const char *)a1);
if ( (_DWORD)result )
{
*(_DWORD *)nptr = *(_DWORD *)a1;
v8 = 0;
v3 = atoi(nptr);
*(_WORD *)nptr = *(_WORD *)(a1 + 4);
nptr[2] = 0;
v4 = atoi(nptr);
*(_WORD *)nptr = *(_WORD *)(a1 + 6);
result = 0LL;
if ( v3 > 1990 )
{
v5 = atoi(nptr);
v6 = v5;
if ( v4 > 12 || v5 > 31 )
{
result = 0LL;
}
else if ( v4 && v5 )
{
if ( (v4 & 0xFFFFFFFD) != 4 && (v4 & 0xFFFFFFFD) != 9 || (result = 0LL, v6 != 31) )
{
result = 1LL;
if ( v4 == 2 )
{
if ( v3 == 100 * (v3 / 100) && v3 != 400 * (v3 / 400) || (v3 & 3) != 0 )
result = v6 <= 28;
else
result = v6 <= 29;
}
}
}
else
{
result = 0LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
size_t v1; // rdx
__int64 result; // rax
int v3; // er12
int v4; // ebp
int v5; // eax
int v6; // edx
char nptr[4]; // [rsp+1h] [rbp-1Dh] BYREF
char v8; // [rsp+5h] [rbp-19h]

if ( !a1 )
return 0LL;
v1 = strlen((const char *)a1);
result = 0LL;
if ( v1 == 8 )
{
result = func2((const char *)a1);
if ( (_DWORD)result )
{
*(_DWORD *)nptr = *(_DWORD *)a1;
v8 = 0;
v3 = atoi(nptr);
*(_WORD *)nptr = *(_WORD *)(a1 + 4);
nptr[2] = 0;
v4 = atoi(nptr);
*(_WORD *)nptr = *(_WORD *)(a1 + 6);
result = 0LL;
if ( v3 > 1990 )
{
v5 = atoi(nptr);
v6 = v5;
if ( v4 > 12 || v5 > 31 )
{
result = 0LL;
}
else if ( v4 && v5 )
{
if ( (v4 & 0xFFFFFFFD) != 4 && (v4 & 0xFFFFFFFD) != 9 || (result = 0LL, v6 != 31) )
{
result = 1LL;
if ( v4 == 2 )
{
if ( v3 == 100 * (v3 / 100) && v3 != 400 * (v3 / 400) || (v3 & 3) != 0 )
result = v6 <= 28;
else
result = v6 <= 29;
}
}
}
else
{
result = 0LL;
}
}
}
}
return result;
}

original_code:
int isDate(char * sDate)
{
  if (!sDate || strlen(sDate)!=8) return 0;
  int iYear,iMonth,iDay;
  char sBuffer[5];
  if (!isNumber(sDate)) return 0;
  memcpy(sBuffer,sDate,4);
  sBuffer[4] = 0;
  iYear = atoi(sBuffer);
  memcpy(sBuffer,sDate+4,2);
  sBuffer[2] = 0;
  iMonth = atoi(sBuffer);
  memcpy(sBuffer,sDate+6,2);
  sBuffer[2] = 0;
  iDay = atoi(sBuffer);
  if (iYear <= 1990)
  {
    return 0;
  }
  if (iMonth>12 || iDay>31 || iMonth==0 || iDay==0)
  {
    return 0;
  }
  if ((iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11) && iDay>30)
  {
    return 0;
  }
  if (iMonth==2)
  {
    if ((iYear%100!=0 && iYear%4==0) || (iYear%400==0 && iYear%4==0))
    {
      if (iDay > 29) return 0;
    }
    else
    {
      if (iDay > 28) return 0;
    }
  }
  return 1;
}

canonical_original_code:
int isDate(char *sDate)
{
  if (!sDate || strlen(sDate)!=8) return 0;
  int iYear; int iMonth; int iDay;
  char sBuffer[5];
  if (!isNumber(sDate)) return 0;
  memcpy(sBuffer,sDate,4);
  sBuffer[4] = 0;
  iYear = atoi(sBuffer);
  memcpy(sBuffer,sDate+4,2);
  sBuffer[2] = 0;
  iMonth = atoi(sBuffer);
  memcpy(sBuffer,sDate+6,2);
  sBuffer[2] = 0;
  iDay = atoi(sBuffer);
  if (iYear <= 1990)
  {
    return 0;
  }
  if (iMonth>12 || iDay>31 || iMonth==0 || iDay==0)
  {
    return 0;
  }
  if ((iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11) && iDay>30)
  {
    return 0;
  }
  if (iMonth==2)
  {
    if ((iYear%100!=0 && iYear%4==0) || (iYear%400==0 && iYear%4==0))
    {
      if (iDay > 29) return 0;
    }
    else
    {
      if (iDay > 28) return 0;
    }
  }
  return 1;
}

variable_types:
sDate
char *

variable_types: iYear int

variable_types: iMonth int

variable_types: iDay int

variable_types:
sBuffer
char [5]


isTime

decompiled_code:
__int64 __fastcall isTime(__int64 a1)
{
size_t v1; // rdx
__int64 result; // rax
unsigned int v3; // edx
unsigned int v4; // edx
char nptr[2]; // [rsp+1h] [rbp-Dh] BYREF
char v6; // [rsp+3h] [rbp-Bh]

if ( !a1 )
return 0LL;
v1 = strlen((const char *)a1);
result = 0LL;
if ( v1 == 6 )
{
result = isNumber((const char *)a1);
if ( (_DWORD)result )
{
*(_WORD *)nptr = *(_WORD *)a1;
v6 = 0;
v3 = atoi(nptr);
result = 0LL;
if ( v3 <= 0x17 )
{
*(_WORD *)nptr = *(_WORD *)(a1 + 2);
v4 = atoi(nptr);
result = 0LL;
if ( v4 <= 0x3B )
{
*(_WORD *)nptr = *(_WORD *)(a1 + 4);
result = (unsigned int)atoi(nptr) <= 0x3B;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
size_t v1; // rdx
__int64 result; // rax
unsigned int v3; // edx
unsigned int v4; // edx
char nptr[2]; // [rsp+1h] [rbp-Dh] BYREF
char v6; // [rsp+3h] [rbp-Bh]

if ( !a1 )
return 0LL;
v1 = strlen((const char *)a1);
result = 0LL;
if ( v1 == 6 )
{
result = func2((const char *)a1);
if ( (_DWORD)result )
{
*(_WORD *)nptr = *(_WORD *)a1;
v6 = 0;
v3 = atoi(nptr);
result = 0LL;
if ( v3 <= 0x17 )
{
*(_WORD *)nptr = *(_WORD *)(a1 + 2);
v4 = atoi(nptr);
result = 0LL;
if ( v4 <= 0x3B )
{
*(_WORD *)nptr = *(_WORD *)(a1 + 4);
result = (unsigned int)atoi(nptr) <= 0x3B;
}
}
}
}
return result;
}

original_code:
int isTime(char * sTime)
{
  if (!sTime || strlen(sTime)!=6) return 0;
  char sBuffer[5];
  int iValue;
  if (!isNumber(sTime)) return 0;
  memcpy(sBuffer,sTime,2);
  sBuffer[2] = 0;
  iValue = atoi(sBuffer);
  if (!(iValue>=0 && iValue <=23)) return 0;
  memcpy(sBuffer,&sTime[2],2);
  sBuffer[2] = 0;
  iValue = atoi(sBuffer);
  if (!(iValue>=0 && iValue <=59)) return 0;
  memcpy(sBuffer,&sTime[4],2);
  sBuffer[2] = 0;
  iValue = atoi(sBuffer);
  if (!(iValue>=0 && iValue <=59)) return 0;
  return 1;
}

canonical_original_code:
int isTime(char *sTime)
{
  if (!sTime || strlen(sTime)!=6) return 0;
  char sBuffer[5];
  int iValue;
  if (!isNumber(sTime)) return 0;
  memcpy(sBuffer,sTime,2);
  sBuffer[2] = 0;
  iValue = atoi(sBuffer);
  if (!(iValue>=0 && iValue <=23)) return 0;
  memcpy(sBuffer,&sTime[2],2);
  sBuffer[2] = 0;
  iValue = atoi(sBuffer);
  if (!(iValue>=0 && iValue <=59)) return 0;
  memcpy(sBuffer,&sTime[4],2);
  sBuffer[2] = 0;
  iValue = atoi(sBuffer);
  if (!(iValue>=0 && iValue <=59)) return 0;
  return 1;
}

variable_types:
sTime
char *

variable_types: iValue int


isDatetime

decompiled_code:
__int64 __fastcall isDatetime(__int64 a1)
{
size_t v1; // rdx
__int64 result; // rax
int v3; // [rsp+0h] [rbp-18h] BYREF
__int16 v4; // [rsp+4h] [rbp-14h]
char v5; // [rsp+6h] [rbp-12h]
__int64 v6; // [rsp+7h] [rbp-11h] BYREF
char v7; // [rsp+Fh] [rbp-9h]

if ( !a1 )
return 0LL;
v1 = strlen((const char *)a1);
result = 0LL;
if ( v1 == 14 )
{
v6 = *(_QWORD *)a1;
v7 = 0;
result = isDate((__int64)&v6);
if ( (_DWORD)result )
{
v3 = *(_DWORD *)(a1 + 8);
v4 = *(_WORD *)(a1 + 12);
v5 = 0;
result = (unsigned int)isTime((__int64)&v3) != 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
size_t v1; // rdx
__int64 result; // rax
int v3; // [rsp+0h] [rbp-18h] BYREF
__int16 v4; // [rsp+4h] [rbp-14h]
char v5; // [rsp+6h] [rbp-12h]
__int64 v6; // [rsp+7h] [rbp-11h] BYREF
char v7; // [rsp+Fh] [rbp-9h]

if ( !a1 )
return 0LL;
v1 = strlen((const char *)a1);
result = 0LL;
if ( v1 == 14 )
{
v6 = *(_QWORD *)a1;
v7 = 0;
result = func7((__int64)&v6);
if ( (_DWORD)result )
{
v3 = *(_DWORD *)(a1 + 8);
v4 = *(_WORD *)(a1 + 12);
v5 = 0;
result = (unsigned int)func8((__int64)&v3) != 0;
}
}
return result;
}

original_code:
int isDatetime(const char * sDatetime)
{
  if (!sDatetime || strlen(sDatetime)!=14) return 0;
  char sDate[8+1];
  char sTime[6+1];
  if( strlen(sDatetime) != 14 ) return 0;
  memcpy(sDate,sDatetime,8);
  sDate[8] = 0;
  if (!isDate(sDate)) return 0;
  memcpy(sTime,&sDatetime[8],6);
  sTime[6] = 0;
  if (!isTime(sTime)) return 0;
  return 1;
}

canonical_original_code:
int isDatetime(char *sDatetime)
{
  if (!sDatetime || strlen(sDatetime)!=14) return 0;
  char sDate[-1];
  char sTime[-1];
  if( strlen(sDatetime) != 14 ) return 0;
  memcpy(sDate,sDatetime,8);
  sDate[8] = 0;
  if (!isDate(sDate)) return 0;
  memcpy(sTime,&sDatetime[8],6);
  sTime[6] = 0;
  if (!isTime(sTime)) return 0;
  return 1;
}

variable_types:
sDatetime
char *

variable_types:
sDate
char [-1]

variable_types:
sTime
char [-1]


decompiled_code:
time_t __fastcall time2sec(__int64 a1)
{
time_t result; // rax
int v2; // edx
struct tm tp; // [rsp+0h] [rbp-48h] BYREF

result = 0LL;
if ( a1 )
{
v2 = isDatetime(a1);
result = 0LL;
if ( v2 )
{
*(_QWORD *)&tp.tm_sec = 0LL;
*(_QWORD *)&tp.tm_hour = 0LL;
*(_QWORD *)&tp.tm_mon = 0LL;
*(_QWORD *)&tp.tm_wday = 0LL;
*(_QWORD *)&tp.tm_isdst = 0LL;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 0LL;
_isoc99_sscanf(a1, "%4d%2d%2d%2d%2d%2d", &tp.tm_year, &tp.tm_mon, &tp.tm_mday, &tp.tm_hour, &tp.tm_min, &tp);
tp.tm_year -= 1900;
--tp.tm_mon;
result = mktime(&tp);
}
}
return result;
}

canonical_decompiled_code:
time_t __fastcall func10(__int64 a1)
{
time_t result; // rax
int v2; // edx
struct tm tp; // [rsp+0h] [rbp-48h] BYREF

result = 0LL;
if ( a1 )
{
v2 = func9(a1);
result = 0LL;
if ( v2 )
{
*(_QWORD *)&tp.tm_sec = 0LL;
*(_QWORD *)&tp.tm_hour = 0LL;
*(_QWORD *)&tp.tm_mon = 0LL;
*(_QWORD *)&tp.tm_wday = 0LL;
*(_QWORD *)&tp.tm_isdst = 0LL;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 0LL;
_isoc99_sscanf(a1, "%4d%2d%2d%2d%2d%2d", &tp.tm_year, &tp.tm_mon, &tp.tm_mday, &tp.tm_hour, &tp.tm_min, &tp);
tp.tm_year -= 1900;
--tp.tm_mon;
result = mktime(&tp);
}
}
return result;
}

original_code:
long time2sec(const char *src)
{
  if (!src || !isDatetime(src)) return 0L;
  struct tm tmpTm;
  memset(&tmpTm,0x00,sizeof(struct tm));
  sscanf(src,"%4d%2d%2d%2d%2d%2d",&tmpTm.tm_year, &tmpTm.tm_mon, &tmpTm.tm_mday, &tmpTm.tm_hour, &tmpTm.tm_min, &tmpTm.tm_sec);
  tmpTm.tm_year -= 1900;
  tmpTm.tm_mon -= 1;
  return mktime(&tmpTm);
}

canonical_original_code:
long time2sec(char *src)
{
  if (!src || !isDatetime(src)) return 0L;
  struct tm tmpTm;
  memset(&tmpTm,0x00,sizeof(struct tm));
  sscanf(src,"%4d%2d%2d%2d%2d%2d",&tmpTm.tm_year, &tmpTm.tm_mon, &tmpTm.tm_mday, &tmpTm.tm_hour, &tmpTm.tm_min, &tmpTm.tm_sec);
  tmpTm.tm_year -= 1900;
  tmpTm.tm_mon -= 1;
  return mktime(&tmpTm);
}

variable_types:
src
char *

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


diffsec

decompiled_code:
time_t __fastcall diffsec(__int64 a1, __int64 a2)
{
time_t v2; // rbx

v2 = time2sec(a1);
return v2 - time2sec(a2);
}

canonical_decompiled_code:
time_t __fastcall func11(__int64 a1, __int64 a2)
{
time_t v2; // rbx

v2 = func10(a1);
return v2 - func10(a2);
}

original_code:
long diffsec(const char *src1, const char *src2)
{
  return time2sec(src1) - time2sec(src2);
}

canonical_original_code:
long diffsec(char *src1, char *src2)
{
  return time2sec(src1) - time2sec(src2);
}


cryptStr

original_code:
char* cryptStr(char * oStr,char * sStr)
{
  char key[5 +1]="\001\002\003\004\005";
  int p = (int)5;
  int k;
  for (k=0; k<strlen(sStr); ++k)
  {
   oStr[k]=sStr[k]^key[k%p--];
   if (!p) p = (int)5;
  }
  oStr[strlen(sStr)] = '\0';
  return oStr;
}

canonical_original_code:
char *cryptStr(char *oStr, char *sStr)
{
  char key[-1] = "\001\002\003\004\005";
  int p = (int)5;
  int k;
  for (k=0; k<strlen(sStr); ++k)
  {
   oStr[k]=sStr[k]^key[k%p--];
   if (!p) p = (int)5;
  }
  oStr[strlen(sStr)] = '\0';
  return oStr;
}

variable_types:
oStr
char *

variable_types:
sStr
char *

variable_types:
key
char [-1]

variable_types: p int

variable_types: k int


getExePathAndName

decompiled_code:
__int64 __fastcall getExePathAndName(char *src, char *dest, char *a3)
{
char *v4; // rax
const char *v5; // r13
const char *v6; // r14
size_t v7; // rax
size_t v8; // rbp
size_t v9; // rax
__int64 result; // rax
size_t v11; // rax

if ( src )
{
v4 = strrchr(src, 47);
v5 = v4;
if ( v4 )
{
v6 = v4 + 1;
v7 = strlen(v4 + 1);
strncpy(dest, v6, v7);
v8 = strlen(src);
v9 = strlen(v5);
strncpy(a3, src, v8 + 1 - v9);
}
else
{
v11 = strlen(src);
strncpy(dest, src, v11);
*(_WORD *)a3 = 12078;
}
result = 0LL;
}
else
{
puts("SearchExeFileNameAndPath_<Input_Parameter_Error");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *src, char *dest, char *a3)
{
char *v4; // rax
const char *v5; // r13
const char *v6; // r14
size_t v7; // rax
size_t v8; // rbp
size_t v9; // rax
__int64 result; // rax
size_t v11; // rax

if ( src )
{
v4 = strrchr(src, 47);
v5 = v4;
if ( v4 )
{
v6 = v4 + 1;
v7 = strlen(v4 + 1);
strncpy(dest, v6, v7);
v8 = strlen(src);
v9 = strlen(v5);
strncpy(a3, src, v8 + 1 - v9);
}
else
{
v11 = strlen(src);
strncpy(dest, src, v11);
*(_WORD *)a3 = 12078;
}
result = 0LL;
}
else
{
puts("SearchExeFileNameAndPath_<Input_Parameter_Error");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int getExePathAndName( const char *in_ptrArgv0,char *out_exename, char *out_exepath)
{
  const char *ptrChar;
  if( in_ptrArgv0 == ((void *)0) )
  {
    printf( "SearchExeFileNameAndPath_<Input_Parameter_Error\n" );
    return -1;
  }
  ptrChar = strrchr( in_ptrArgv0, '/' );
  if( ptrChar != ((void *)0) )
  {
    strncpy(out_exename, ptrChar+1, strlen(ptrChar+1));
    strncpy(out_exepath, in_ptrArgv0, strlen(in_ptrArgv0)-strlen(ptrChar)+1);
  }
  else
  {
    strncpy( out_exename, in_ptrArgv0, strlen( in_ptrArgv0 ) );
    strncpy( out_exepath, "./", 2);
  }
  return 0;
}

canonical_original_code:
int getExePathAndName(char *in_ptrArgv0, char *out_exename, char *out_exepath)
{
  char *ptrChar;
  if( in_ptrArgv0 == ((void *)0) )
  {
    printf( "SearchExeFileNameAndPath_<Input_Parameter_Error\n" );
    return -1;
  }
  ptrChar = strrchr( in_ptrArgv0, '/' );
  if( ptrChar != ((void *)0) )
  {
    strncpy(out_exename, ptrChar+1, strlen(ptrChar+1));
    strncpy(out_exepath, in_ptrArgv0, strlen(in_ptrArgv0)-strlen(ptrChar)+1);
  }
  else
  {
    strncpy( out_exename, in_ptrArgv0, strlen( in_ptrArgv0 ) );
    strncpy( out_exepath, "./", 2);
  }
  return 0;
}

variable_types:
ptrChar
char *


getsubstr

decompiled_code:
char *__fastcall getsubstr(char *src, char a2, int a3, char *a4)
{
char *result; // rax
size_t v7; // rbx
size_t v8; // rax
size_t v9; // rbx
size_t v10; // rax
char v11[1024]; // [rsp+0h] [rbp-828h] BYREF
char dest[1064]; // [rsp+400h] [rbp-428h] BYREF

result = 0LL;
memset(dest, 0, 0x400uLL);
memset(v11, 0, sizeof(v11));
if ( src && a3 > 0 )
{
if ( a3 == 1 )
{
strcpy(dest, src);
pstrchr(src, a2, 1, v11);
v9 = strlen(dest);
v10 = strlen(v11);
result = strncpy(a4, dest, v9 - v10);
}
else
{
pstrchr(src, a2, a3 - 1, dest);
pstrchr(src, a2, a3, v11);
v7 = strlen(&dest[1]);
v8 = strlen(v11);
result = strncpy(a4, &dest[1], v7 - v8);
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func14(char *src, char a2, int a3, char *a4)
{
char *result; // rax
size_t v7; // rbx
size_t v8; // rax
size_t v9; // rbx
size_t v10; // rax
char v11[1024]; // [rsp+0h] [rbp-828h] BYREF
char dest[1064]; // [rsp+400h] [rbp-428h] BYREF

result = 0LL;
memset(dest, 0, 0x400uLL);
memset(v11, 0, sizeof(v11));
if ( src && a3 > 0 )
{
if ( a3 == 1 )
{
strcpy(dest, src);
func0(src, a2, 1, v11);
v9 = strlen(dest);
v10 = strlen(v11);
result = strncpy(a4, dest, v9 - v10);
}
else
{
func0(src, a2, a3 - 1, dest);
func0(src, a2, a3, v11);
v7 = strlen(&dest[1]);
v8 = strlen(v11);
result = strncpy(a4, &dest[1], v7 - v8);
}
}
return result;
}

original_code:
void getsubstr(char *str, char sp, int n, char *substr)
{
  char p0[1024];
  char p1[1024];
  memset(p0, 0, sizeof(p0));
  memset(p1, 0, sizeof(p1));
  if(!str || n<=0) return;
  if(n == 1)
  {
    strcpy(p0, str);
  }
  else
  {
    pstrchr( str, sp, n-1, p0 );
  }
  pstrchr( str, sp, n, p1 );
    if( n == 1 )
    {
      strncpy( substr, p0, strlen( p0 ) - strlen( p1 ) );
    }
    else
    {
      strncpy( substr, p0+1, strlen( p0+1 ) - strlen( p1 ) );
    }
}

variable_types:
str
char *

variable_types: sp char

variable_types: n int

variable_types:
substr
char *


getstrnum

decompiled_code:
__int64 __fastcall getstrnum(const char *a1, const char *a2)
{
char *v2; // rax
char *v3; // rbx
size_t v4; // r13
unsigned int v5; // ebp

v2 = strstr(a1, a2);
if ( !v2 )
return 0;
v3 = v2;
v4 = strlen(a2);
v5 = 0;
do
{
++v5;
v3 = strstr(&v3[v4], a2);
}
while ( v3 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func15(const char *a1, const char *a2)
{
char *v2; // rax
char *v3; // rbx
size_t v4; // r13
unsigned int v5; // ebp

v2 = strstr(a1, a2);
if ( !v2 )
return 0;
v3 = v2;
v4 = strlen(a2);
v5 = 0;
do
{
++v5;
v3 = strstr(&v3[v4], a2);
}
while ( v3 );
return v5;
}

original_code:
int getstrnum(char *dest ,char *searchstr)
{
  char *strtmp,*strtmp2;
  int i=0;
  if (strstr(dest,searchstr)==((void *)0))
  {
    return 0;
  }
  strtmp=dest;
  while ((strtmp2=strstr((char *)strtmp,searchstr))!=((void *)0))
  {
    strtmp=strtmp2+strlen(searchstr);
    i++;
  }
  return i;
}

canonical_original_code:
int getstrnum(char *dest, char *searchstr)
{
  char *strtmp; char *strtmp2;
  int i = 0;
  if (strstr(dest,searchstr)==((void *)0))
  {
    return 0;
  }
  strtmp=dest;
  while ((strtmp2=strstr((char *)strtmp,searchstr))!=((void *)0))
  {
    strtmp=strtmp2+strlen(searchstr);
    i++;
  }
  return i;
}

variable_types:
dest
char *

variable_types:
searchstr
char *

variable_types:
strtmp
char *

variable_types: i int


strreplace

decompiled_code:
__int64 __fastcall strreplace(char *haystack, char *needle, char *src)
{
char *v4; // rdx
__int64 result; // rax
int v6; // er13
int v7; // er15
int v8; // ebx
size_t v9; // rbx
void *v10; // rax
void *v11; // r13
unsigned int v12; // eax
size_t v13; // rax
unsigned int v14; // ebx
int i; // ebx
size_t v16; // rax
unsigned int v17; // ebx
const char *v18; // rbx
char *v19; // rax
size_t v20; // rax

v4 = strstr(haystack, needle);
result = 0LL;
if ( v4 )
{
v6 = getstrnum(haystack, needle);
v7 = strlen(needle);
v8 = strlen(src);
v9 = (int)(v6 * (v8 - v7) + strlen(haystack) + 1);
v10 = malloc(v9);
v11 = v10;
if ( v10 )
{
memset(v10, 0, v9);
v12 = (unsigned int)strstr(haystack, needle);
memcpy(v11, haystack, (int)(v12 - (_DWORD)haystack));
v13 = strlen(src);
strncat((char *)v11, src, v13);
v14 = (unsigned int)strstr(haystack, needle);
for ( i = strlen(needle) + v14 - (_DWORD)haystack; ; i = strlen(needle) + v17 - (_DWORD)haystack )
{
v18 = &haystack[i];
v19 = strstr(v18, needle);
if ( !v19 )
break;
strncat((char *)v11, v18, v19 - v18);
v16 = strlen(src);
strncat((char *)v11, src, v16);
v17 = (unsigned int)strstr(v18, needle);
}
v20 = strlen(v18);
strncat((char *)v11, v18, v20);
strcpy(haystack, (const char *)v11);
free(v11);
result = 0LL;
}
else
{
perror("replace malloc error");
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *haystack, char *needle, char *src)
{
char *v4; // rdx
__int64 result; // rax
int v6; // er13
int v7; // er15
int v8; // ebx
size_t v9; // rbx
void *v10; // rax
void *v11; // r13
unsigned int v12; // eax
size_t v13; // rax
unsigned int v14; // ebx
int i; // ebx
size_t v16; // rax
unsigned int v17; // ebx
const char *v18; // rbx
char *v19; // rax
size_t v20; // rax

v4 = strstr(haystack, needle);
result = 0LL;
if ( v4 )
{
v6 = func15(haystack, needle);
v7 = strlen(needle);
v8 = strlen(src);
v9 = (int)(v6 * (v8 - v7) + strlen(haystack) + 1);
v10 = malloc(v9);
v11 = v10;
if ( v10 )
{
memset(v10, 0, v9);
v12 = (unsigned int)strstr(haystack, needle);
memcpy(v11, haystack, (int)(v12 - (_DWORD)haystack));
v13 = strlen(src);
strncat((char *)v11, src, v13);
v14 = (unsigned int)strstr(haystack, needle);
for ( i = strlen(needle) + v14 - (_DWORD)haystack; ; i = strlen(needle) + v17 - (_DWORD)haystack )
{
v18 = &haystack[i];
v19 = strstr(v18, needle);
if ( !v19 )
break;
strncat((char *)v11, v18, v19 - v18);
v16 = strlen(src);
strncat((char *)v11, src, v16);
v17 = (unsigned int)strstr(v18, needle);
}
v20 = strlen(v18);
strncat((char *)v11, v18, v20);
strcpy(haystack, (const char *)v11);
free(v11);
result = 0LL;
}
else
{
perror("replace malloc error");
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int strreplace(char *dest,char *searchstr,char *replacestr)
{
  char *sTmphead, *sTmptail;
  int ilen = 0, ipos = 0;
  int iserlen, ireplen, inum;
  if (strstr(dest,searchstr) == ((void *)0))
  {
    return 0;
  }
  inum = getstrnum(dest,searchstr);
  iserlen = strlen(searchstr);
  ireplen = strlen(replacestr);
  ilen = strlen(dest) + (ireplen-iserlen)*inum + 1;
  if ((sTmphead=(char *)malloc(ilen)) == ((void *)0))
  {
    perror("replace malloc error");
    return -1;
  }
  memset(sTmphead, 0, ilen);
  ilen = strstr(dest, searchstr) - dest;
  memcpy(sTmphead,dest,ilen);
  strncat(sTmphead,replacestr,strlen(replacestr));
  ipos=strstr(dest,searchstr)-dest+strlen(searchstr);
  while ((sTmptail=strstr(dest+ipos,searchstr)) != ((void *)0))
  {
    strncat(sTmphead,dest+ipos,sTmptail-(dest+ipos));
    strncat(sTmphead,replacestr,strlen(replacestr));
    ipos=strstr(dest+ipos,searchstr)-dest+strlen(searchstr);
  }
  strncat(sTmphead,dest+ipos,strlen(dest+ipos));
  strcpy(dest,sTmphead);
  free(sTmphead);
  return 0;
}

canonical_original_code:
int strreplace(char *dest, char *searchstr, char *replacestr)
{
  char *sTmphead; char *sTmptail;
  int ilen = 0; int ipos = 0;
  int iserlen; int ireplen; int inum;
  if (strstr(dest,searchstr) == ((void *)0))
  {
    return 0;
  }
  inum = getstrnum(dest,searchstr);
  iserlen = strlen(searchstr);
  ireplen = strlen(replacestr);
  ilen = strlen(dest) + (ireplen-iserlen)*inum + 1;
  if ((sTmphead=(char *)malloc(ilen)) == ((void *)0))
  {
    perror("replace malloc error");
    return -1;
  }
  memset(sTmphead, 0, ilen);
  ilen = strstr(dest, searchstr) - dest;
  memcpy(sTmphead,dest,ilen);
  strncat(sTmphead,replacestr,strlen(replacestr));
  ipos=strstr(dest,searchstr)-dest+strlen(searchstr);
  while ((sTmptail=strstr(dest+ipos,searchstr)) != ((void *)0))
  {
    strncat(sTmphead,dest+ipos,sTmptail-(dest+ipos));
    strncat(sTmphead,replacestr,strlen(replacestr));
    ipos=strstr(dest+ipos,searchstr)-dest+strlen(searchstr);
  }
  strncat(sTmphead,dest+ipos,strlen(dest+ipos));
  strcpy(dest,sTmphead);
  free(sTmphead);
  return 0;
}

variable_types:
replacestr
char *

variable_types:
sTmphead
char *

variable_types:
sTmptail
char *

variable_types: ilen int

variable_types: ipos int

variable_types: iserlen int

variable_types: ireplen int

variable_types: inum int


trim

decompiled_code:
void *__fastcall trim(void *src)
{
int v2; // er12
const unsigned __int16 **v3; // rsi
char *v4; // rax
char *v5; // rdi
const unsigned __int16 *v6; // rdx
const char *i; // rbx
size_t v8; // rax

if ( src )
{
v2 = strlen((const char *)src);
if ( v2 )
{
v3 = _ctype_b_loc();
v4 = (char *)src + v2 - 1;
v5 = (char *)src + v2 - (unsigned int)(v2 - 1) - 2;
do
{
if ( ((*v3)[*v4] & 0x2000) == 0 )
break;
*v4-- = 0;
}
while ( v4 != v5 );
}
v6 = *_ctype_b_loc();
for ( i = (const char *)src; (v6[*i] & 0x2000) != 0; ++i )
;
v8 = strlen(i);
if ( v2 > v8 )
memcpy(src, i, v8 + 1);
}
return src;
}

canonical_decompiled_code:
void *__fastcall func5(void *src)
{
int v2; // er12
const unsigned __int16 **v3; // rsi
char *v4; // rax
char *v5; // rdi
const unsigned __int16 *v6; // rdx
const char *i; // rbx
size_t v8; // rax

if ( src )
{
v2 = strlen((const char *)src);
if ( v2 )
{
v3 = _ctype_b_loc();
v4 = (char *)src + v2 - 1;
v5 = (char *)src + v2 - (unsigned int)(v2 - 1) - 2;
do
{
if ( ((*v3)[*v4] & 0x2000) == 0 )
break;
*v4-- = 0;
}
while ( v4 != v5 );
}
v6 = *_ctype_b_loc();
for ( i = (const char *)src; (v6[*i] & 0x2000) != 0; ++i )
;
v8 = strlen(i);
if ( v2 > v8 )
memcpy(src, i, v8 + 1);
}
return src;
}

original_code:
char* trim(char *s)
{
  if (!s) return ((void *)0);
  char *ptmp = s;
  int len = strlen(s);
  int tmpLen = len;
  while (len)
  {
    if (((*__ctype_b_loc ())[(int) ((*(ptmp+len-1)))] & (unsigned short int) _ISspace))
    {
      *(ptmp+len-1) = '\0';
      --len;
    }
    else
    {
      break;
    }
  }
  while(((*__ctype_b_loc ())[(int) ((*ptmp))] & (unsigned short int) _ISspace))
  {
    ++ptmp;
  }
  if (tmpLen > strlen(ptmp))
  {
    memcpy(s, ptmp, strlen(ptmp)+1);
  }
  return s;
}

canonical_original_code:
char *trim(char *s)
{
  if (!s) return ((void *)0);
  char *ptmp = s;
  int len = strlen(s);
  int tmpLen = len;
  while (len)
  {
    if (((*__ctype_b_loc ())[(int) ((*(ptmp+len-1)))] & (unsigned short) _ISspace))
    {
      *(ptmp+len-1) = '\0';
      --len;
    }
    else
    {
      break;
    }
  }
  while(((*__ctype_b_loc ())[(int) ((*ptmp))] & (unsigned short) _ISspace))
  {
    ++ptmp;
  }
  if (tmpLen > strlen(ptmp))
  {
    memcpy(s, ptmp, strlen(ptmp)+1);
  }
  return s;
}

variable_types:
s
char *

variable_types:
ptmp
char *

variable_types: len int

variable_types: tmpLen int


mkFlNm

decompiled_code:
char *__fastcall mkFlNm(char *a1, const char *a2, const char *a3)
{
int v4; // eax

strcpy(a1, a2);
v4 = strlen(a2);
if ( a2[v4 - 1] == 47 )
{
strcpy(&a1[v4], a3);
}
else
{
a2[v4] = 47;
strcpy(&a1[v4 + 1], a3);
}
return a1;
}

canonical_decompiled_code:
char *__fastcall func0(char *a1, const char *a2, const char *a3)
{
int v4; // eax

strcpy(a1, a2);
v4 = strlen(a2);
if ( a2[v4 - 1] == 47 )
{
strcpy(&a1[v4], a3);
}
else
{
a2[v4] = 47;
strcpy(&a1[v4 + 1], a3);
}
return a1;
}

original_code:
char *mkFlNm(char *fullFileName, char *dirName, char *fileName)
{
  int dirLen;
  strcpy(fullFileName, dirName);
  dirLen = strlen(dirName);
  if(dirName[dirLen-1]=='/')
  {
    strcpy(fullFileName+dirLen, fileName);
  }
  else
  {
    dirName[dirLen]='/';
    strcpy(fullFileName+dirLen+1, fileName);
  }
  return fullFileName;
}

variable_types:
fullFileName
char *

variable_types:
dirName
char *

variable_types:
fileName
char *

variable_types: dirLen int


getFlLth

decompiled_code:
__off_t __fastcall getFlLth(const char *a1, const char *a2)
{
struct stat v3; // [rsp+0h] [rbp-498h] BYREF
char file[8]; // [rsp+90h] [rbp-408h] BYREF
__int64 v5; // [rsp+98h] [rbp-400h]
char v6[1008]; // [rsp+A0h] [rbp-3F8h] BYREF

*(_QWORD *)file = 0LL;
v5 = 0LL;
memset(v6, 0, sizeof(v6));
mkFlNm(file, a1, a2);
stat(file, &v3);
return v3.st_size;
}

canonical_decompiled_code:
__off_t __fastcall func8(const char *a1, const char *a2)
{
struct stat v3; // [rsp+0h] [rbp-498h] BYREF
char file[8]; // [rsp+90h] [rbp-408h] BYREF
__int64 v5; // [rsp+98h] [rbp-400h]
char v6[1008]; // [rsp+A0h] [rbp-3F8h] BYREF

*(_QWORD *)file = 0LL;
v5 = 0LL;
memset(v6, 0, sizeof(v6));
func0(file, a1, a2);
stat(file, &v3);
return v3.st_size;
}

original_code:
long getFlLth(char *dirName, char *fileName)
{
  char fullName[1024] = {0};
  mkFlNm(fullName, dirName, fileName);
  struct stat buf;
  stat(fullName, &buf);
  return buf.st_size;
}

variable_types:
fullName
char [1024]

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


reNm

decompiled_code:
int __fastcall reNm(const char *a1, const char *a2, const char *a3)
{
char v5[1024]; // [rsp+0h] [rbp-818h] BYREF
char old[1048]; // [rsp+400h] [rbp-418h] BYREF

mkFlNm(old, a3, a1);
mkFlNm(v5, a3, a2);
return rename(old, v5);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1, const char *a2, const char *a3)
{
char v5[1024]; // [rsp+0h] [rbp-818h] BYREF
char old[1048]; // [rsp+400h] [rbp-418h] BYREF

func0(old, a3, a1);
func0(v5, a3, a2);
return rename(old, v5);
}

original_code:
int reNm(char *oldFileName, char *newFileName, char *dirName)
{
  char oldFullFile[1024];
  char newFullFile[1024];
  mkFlNm(oldFullFile, dirName, oldFileName);
  mkFlNm(newFullFile, dirName, newFileName);
  return rename(oldFullFile, newFullFile);
}

variable_types:
oldFileName
char *

variable_types:
newFileName
char *

variable_types:
oldFullFile
char [1024]

variable_types:
newFullFile
char [1024]


isHaveFile

decompiled_code:
_BOOL8 __fastcall isHaveFile(const char *a1)
{
return access(a1, 0) >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(const char *a1)
{
return access(a1, 0) >= 0;
}

original_code:
int isHaveFile(char *file)
{
  if (access(file, 0) < 0)
  {
    return 0;
  }
  else
  {
    return 1;
  }
}

variable_types:
file
char *


getLogLevel

decompiled_code:
__int64 __fastcall getLogLevel(char *a1, int a2)
{
if ( a2 == 3 )
{
strcpy(a1, "WARN");
return 0LL;
}
if ( a2 > 3 )
{
if ( a2 == 4 )
{
strcpy(a1, "ERROR");
return 0LL;
}
}
else
{
if ( a2 == 1 )
{
strcpy(a1, "DEBUG");
return 0LL;
}
if ( a2 == 2 )
{
strcpy(a1, "INFO");
return 0LL;
}
}
perror("error log level!");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, int a2)
{
if ( a2 == 3 )
{
strcpy(a1, "WARN");
return 0LL;
}
if ( a2 > 3 )
{
if ( a2 == 4 )
{
strcpy(a1, "ERROR");
return 0LL;
}
}
else
{
if ( a2 == 1 )
{
strcpy(a1, "DEBUG");
return 0LL;
}
if ( a2 == 2 )
{
strcpy(a1, "INFO");
return 0LL;
}
}
perror("error log level!");
return 0LL;
}

original_code:
static int getLogLevel(char *levelInfo, int logLevel)
{
  switch(logLevel)
  {
    case 1:
      strcpy(levelInfo, "DEBUG");
      break;
    case 2:
      strcpy(levelInfo, "INFO");
      break;
    case 3:
      strcpy(levelInfo, "WARN");
      break;
    case 4:
      strcpy(levelInfo, "ERROR");
      break;
    default:
      perror("error log level!");
  }
  return 0;
}

variable_types:
levelInfo
char *

variable_types: logLevel int


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

result = 1LL;
if ( a1 >= 0 )
result = (unsigned int)((a1 & 0x40) != 0) + 2;
return result;
}

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

result = 1LL;
if ( a1 >= 0 )
result = (unsigned int)((a1 & 0x40) != 0) + 2;
return result;
}

original_code:
int adc_chunk_type(char _byte)
{
 if (_byte & 0x80)
  return 0x01;
 if (_byte & 0x40)
  return 0x03;
 return 0x02;
}


decompiled_code:
__int64 __fastcall adc_chunk_size(char a1)
{
int v1; // eax
bool v2; // zf
__int64 result; // rax

v1 = adc_chunk_type(a1);
if ( v1 == 2 )
return ((a1 >> 2) & 0xFu) + 3;
if ( v1 == 3 )
return (a1 & 0x3Fu) + 4;
v2 = v1 == 1;
result = 0xFFFFFFFFLL;
if ( v2 )
result = (a1 & 0x7Fu) + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
int v1; // eax
bool v2; // zf
__int64 result; // rax

v1 = func0(a1);
if ( v1 == 2 )
return ((a1 >> 2) & 0xFu) + 3;
if ( v1 == 3 )
return (a1 & 0x3Fu) + 4;
v2 = v1 == 1;
result = 0xFFFFFFFFLL;
if ( v2 )
result = (a1 & 0x7Fu) + 1;
return result;
}

original_code:
int adc_chunk_size(char _byte)
{
 switch (adc_chunk_type(_byte)) {
  case 0x01:
  return (_byte & 0x7F) + 1;
 case 0x02:
  return ((_byte & 0x3F) >> 2) + 3;
 case 0x03:
  return (_byte & 0x3F) + 4;
 }
 return -1;
}


decompiled_code:
__int64 __fastcall adc_chunk_offset(unsigned __int8 *a1)
{
__int16 v1; // bx
int v2; // eax

v1 = *a1;
v2 = adc_chunk_type(v1);
if ( v2 == 2 )
return ((v1 << 8) & 0x300) + (unsigned int)a1[1];
if ( v2 == 3 )
return a1[2] + (a1[1] << 8);
return (unsigned int)-(v2 != 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1)
{
__int16 v1; // bx
int v2; // eax

v1 = *a1;
v2 = func0(v1);
if ( v2 == 2 )
return ((v1 << 8) & 0x300) + (unsigned int)a1[1];
if ( v2 == 3 )
return a1[2] + (a1[1] << 8);
return (unsigned int)-(v2 != 1);
}

original_code:
int adc_chunk_offset(unsigned char *chunk_start)
{
 unsigned char *c = chunk_start;
 switch (adc_chunk_type(*c)) {
 case 0x01:
  return 0;
 case 0x02:
  return ((((unsigned char)*c & 0x03)) << 8) + (unsigned char)*(c + 1);
 case 0x03:
  return (((unsigned char)*(c + 1)) << 8) + (unsigned char)*(c + 2);
 }
 return -1;
}

variable_types:
c
unsigned char *


decompiled_code:
__int64 __fastcall adc_decompress(unsigned int a1, char *a2, int a3, char *a4, _DWORD *a5)
{
__int64 result; // rax
char *v7; // r12
char *v8; // rbx
char v9; // r14
int v10; // eax
size_t v11; // r14
int v12; // eax
__int64 v13; // rdx
char *v14; // rax
int v15; // eax
__int64 v16; // rdx
char *v17; // rax
char *v18; // [rsp+10h] [rbp-58h]
int v19; // [rsp+18h] [rbp-50h]
int v20; // [rsp+18h] [rbp-50h]

v18 = a4;
result = a1;
if ( a1 )
{
v7 = a4;
v8 = a2;
while ( v8 - a2 < (int)a1 )
{
v9 = *v8;
v10 = adc_chunk_type(*v8);
switch ( v10 )
{
case 2:
v19 = adc_chunk_size(v9);
if ( &v7[v19] - v18 > a3 )
goto LABEL_9;
v12 = adc_chunk_offset((unsigned __int8 *)v8);
if ( v12 )
{
if ( v19 > 0 )
{
v13 = v12;
v14 = &v7[~(__int64)v12];
do
{
v14[v13 + 1] = *v14;
++v14;
}
while ( v14 != &v7[(unsigned int)(v19 - 1) - v13] );
v7 += (unsigned int)v19;
}
v8 += 2;
}
else
{
memset(v7, (unsigned __int8)*(v7 - 1), v19);
v8 += 2;
v7 += v19;
}
break;
case 3:
v20 = adc_chunk_size(v9);
if ( &v7[v20] - v18 > a3 )
goto LABEL_9;
v15 = adc_chunk_offset((unsigned __int8 *)v8);
if ( v15 )
{
if ( v20 > 0 )
{
v16 = v15;
v17 = &v7[~(__int64)v15];
do
{
v17[v16 + 1] = *v17;
++v17;
}
while ( v17 != &v7[(unsigned int)(v20 - 1) - v16] );
v7 += (unsigned int)v20;
}
v8 += 3;
}
else
{
memset(v7, (unsigned __int8)*(v7 - 1), v20);
v8 += 3;
v7 += v20;
}
break;
case 1:
v11 = (int)adc_chunk_size(v9);
if ( &v7[v11] - v18 > a3 )
goto LABEL_9;
memcpy(v7, v8 + 1, v11);
v8 += v11 + 1;
v7 += v11;
break;
}
}
LABEL_9:
*a5 = (_DWORD)v7 - (_DWORD)v18;
result = (unsigned int)((_DWORD)v8 - (_DWORD)a2);
}
return result;
}

original_code:
int adc_decompress(int in_size, unsigned char *input, int avail_size, unsigned char *output, int *bytes_written)
{
 if (in_size == 0)
  return 0;
 short output_full = 0;
 unsigned char *inp = input;
 unsigned char *outp = output;
 int chunk_type;
 int chunk_size;
 int offset;
 int i;
 while (inp - input < in_size) {
  chunk_type = adc_chunk_type(*inp);
  switch (chunk_type) {
  case 0x01:
   chunk_size = adc_chunk_size(*inp);
   if (outp + chunk_size - output > avail_size) {
    output_full = 1;
    break;
   }
   memcpy(outp, inp + 1, chunk_size);
   inp += chunk_size + 1;
   outp += chunk_size;
   break;
  case 0x02:
   chunk_size = adc_chunk_size(*inp);
   offset = adc_chunk_offset(inp);
   if (outp + chunk_size - output > avail_size) {
    output_full = 1;
    break;
   }
   if (offset == 0) {
    memset(outp, *(outp - offset - 1), chunk_size);
    outp += chunk_size;
    inp += 2;
   } else {
    for (i = 0; i < chunk_size; i++) {
     memcpy(outp, outp - offset - 1, 1);
     outp++;
    }
    inp += 2;
   }
   break;
  case 0x03:
   chunk_size = adc_chunk_size(*inp);
   offset = adc_chunk_offset(inp);
   if (outp + chunk_size - output > avail_size) {
    output_full = 1;
    break;
   }
   if (offset == 0) {
    memset(outp, *(outp - offset - 1), chunk_size);
    outp += chunk_size;
    inp += 3;
   } else {
    for (i = 0; i < chunk_size; i++) {
     memcpy(outp, outp - offset - 1, 1);
     outp++;
    }
    inp += 3;
   }
   break;
  }
  if (output_full)
   break;
 }
 *bytes_written = outp - output;
 return inp - input;
}

variable_types:
input
unsigned char *

variable_types:
output
unsigned char *

variable_types:
inp
unsigned char *

variable_types:
outp
unsigned char *

variable_types: offset int

variable_types: i int


decompiled_code:
__int64 __fastcall is_base64(unsigned __int8 a1)
{
unsigned __int64 v1; // rdx

LODWORD(v1) = 1;
if ( (unsigned __int8)((a1 & 0xDF) - 65) > 0x19u )
{
LODWORD(v1) = 0;
if ( a1 <= 0x3Du )
v1 = (0x23FF880000000000uLL >> a1) & 1;
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
unsigned __int64 v1; // rdx

LODWORD(v1) = 1;
if ( (unsigned __int8)((a1 & 0xDF) - 65) > 0x19u )
{
LODWORD(v1) = 0;
if ( a1 <= 0x3Du )
v1 = (0x23FF880000000000uLL >> a1) & 1;
}
return (unsigned int)v1;
}

variable_types: c char

return_type: short


decompiled_code:
unsigned __int8 *__fastcall cleanup_base64(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbp
_BYTE *v3; // rbx
unsigned __int8 v4; // r12
unsigned __int8 *result; // rax

v2 = a1;
if ( a2 )
{
v3 = a1 + 1;
while ( 1 )
{
v4 = *(v3 - 1);
result = &v2[-((unsigned __int16)is_base64(v4) == 0) + 1];
*v2 = v4;
if ( ++v3 == &a1[a2 - 1 + 2] )
break;
v2 = result;
}
}
else
{
result = a1;
}
*result = 0;
return result;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func1(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbp
_BYTE *v3; // rbx
unsigned __int8 v4; // r12
unsigned __int8 *result; // rax

v2 = a1;
if ( a2 )
{
v3 = a1 + 1;
while ( 1 )
{
v4 = *(v3 - 1);
result = &v2[-((unsigned __int16)func0(v4) == 0) + 1];
*v2 = v4;
if ( ++v3 == &a1[a2 - 1 + 2] )
break;
v2 = result;
}
}
else
{
result = a1;
}
*result = 0;
return result;
}

original_code:
void cleanup_base64(char *inp, const unsigned int size)
{
 char *tinp1, *tinp2;
 unsigned int i;
 tinp1 = inp;
 tinp2 = inp;
 for (i = 0; i < size; i++) {
  if (is_base64(*tinp2)) {
   *tinp1++ = *tinp2++;
  } else {
   *tinp1 = *tinp2++;
  }
 }
 *(tinp1) = 0;
}

canonical_original_code:
void cleanup_base64(char *inp, unsigned int size)
{
 char *tinp1; char *tinp2;
 unsigned int i;
 tinp1 = inp;
 tinp2 = inp;
 for (i = 0; i < size; i++) {
  if (is_base64(*tinp2)) {
   *tinp1++ = *tinp2++;
  } else {
   *tinp1 = *tinp2++;
  }
 }
 *(tinp1) = 0;
}

variable_types:
inp
char *

variable_types:
size
unsigned int

variable_types:
i
unsigned int


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

result = (unsigned int)(a1 - 65);
if ( (unsigned __int8)(a1 - 65) > 0x19u )
{
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
{
result = (unsigned int)(a1 - 71);
}
else if ( (unsigned __int8)(a1 - 48) <= 9u )
{
result = (unsigned int)(a1 + 4);
}
else if ( (_BYTE)a1 == 43 )
{
result = 62LL;
}
else
{
result = 63LL;
if ( (_BYTE)a1 == 61 )
result = 0LL;
}
}
return result;
}

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

result = (unsigned int)(a1 - 65);
if ( (unsigned __int8)(a1 - 65) > 0x19u )
{
if ( (unsigned __int8)(a1 - 97) <= 0x19u )
{
result = (unsigned int)(a1 - 71);
}
else if ( (unsigned __int8)(a1 - 48) <= 9u )
{
result = (unsigned int)(a1 + 4);
}
else if ( (_BYTE)a1 == 43 )
{
result = 62LL;
}
else
{
result = 63LL;
if ( (_BYTE)a1 == 61 )
result = 0LL;
}
}
return result;
}

original_code:
unsigned char decode_base64_char(const char c)
{
 if (c >= 'A' && c <= 'Z')
  return c - 'A';
 if (c >= 'a' && c <= 'z')
  return c - 'a' + 26;
 if (c >= '0' && c <= '9')
  return c - '0' + 52;
 if (c == '+')
  return 62;
 if (c == '=')
  return 0;
 return 63;
}

canonical_original_code:
unsigned char decode_base64_char(char c)
{
 if (c >= 'A' && c <= 'Z')
  return c - 'A';
 if (c >= 'a' && c <= 'z')
  return c - 'a' + 26;
 if (c >= '0' && c <= '9')
  return c - '0' + 52;
 if (c == '+')
  return 62;
 if (c == '=')
  return 0;
 return 63;
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall decode_base64(char *a1, unsigned int a2, char *a3, _DWORD *a4)
{
char *v4; // rbx
_BYTE *v5; // rbp
__int64 result; // rax
char v8; // r12
char v9; // r12
char v10; // r12

v4 = a1;
v5 = a3;
result = a2 >> 2;
*a4 = 3 * result;
if ( a1 != a3 )
{
result = (__int64)malloc((unsigned int)(3 * result));
v5 = (_BYTE *)result;
}
if ( a2 >> 2 )
{
do
{
v8 = 4 * decode_base64_char(*v4);
*v5 = v8;
*v5 = ((unsigned __int8)decode_base64_char(v4[1]) >> 4) | v8;
v9 = 16 * decode_base64_char(v4[1]);
v5[1] = v9;
v5[1] = ((unsigned __int8)decode_base64_char(v4[2]) >> 2) | v9;
v10 = (unsigned __int8)decode_base64_char(v4[2]) << 6;
v5[2] = v10;
v4 += 4;
result = decode_base64_char(*(v4 - 1));
v5 += 3;
*(v5 - 1) = result | v10;
}
while ( &a1[4 * (a2 >> 2)] != v4 );
}
if ( *(v4 - 1) == 61 )
--*a4;
if ( *(v4 - 2) == 61 )
--*a4;
return result;
}

original_code:
void decode_base64(const char *inp, unsigned int isize,
          char *out, unsigned int *osize)
{
 char *tinp = (char *)inp;
 char *tout;
 unsigned int i;
 *osize = isize / 4 * 3;
 if (inp != out) {
  tout = (char *)malloc(*osize);
  out = tout;
 } else {
  tout = tinp;
 }
 for (i = 0; i < (isize >> 2); i++) {
  *tout = decode_base64_char(*tinp++) << 2;
  *tout++ |= decode_base64_char(*tinp) >> 4;
  *tout = decode_base64_char(*tinp++) << 4;
  *tout++ |= decode_base64_char(*tinp) >> 2;
  *tout = decode_base64_char(*tinp++) << 6;
  *tout++ |= decode_base64_char(*tinp++);
 }
 if (*(tinp - 1) == '=')
  (*osize)--;
 if (*(tinp - 2) == '=')
  (*osize)--;
}

canonical_original_code:
void decode_base64(char *inp, unsigned int isize, char *out, unsigned int *osize)
{
 char *tinp = (char *)inp;
 char *tout;
 unsigned int i;
 *osize = isize / 4 * 3;
 if (inp != out) {
  tout = (char *)malloc(*osize);
  out = tout;
 } else {
  tout = tinp;
 }
 for (i = 0; i < (isize >> 2); i++) {
  *tout = decode_base64_char(*tinp++) << 2;
  *tout++ |= decode_base64_char(*tinp) >> 4;
  *tout = decode_base64_char(*tinp++) << 4;
  *tout++ |= decode_base64_char(*tinp) >> 2;
  *tout = decode_base64_char(*tinp++) << 6;
  *tout++ |= decode_base64_char(*tinp++);
 }
 if (*(tinp - 1) == '=')
  (*osize)--;
 if (*(tinp - 2) == '=')
  (*osize)--;
}

variable_types:
isize
unsigned int

variable_types:
out
char *

variable_types:
osize
unsigned int *

variable_types:
tinp
char *

variable_types:
tout
char *


repo: lemenkov/grubby

decompiled_code:
__int64 open_log()
{
unsigned int v0; // ebx
int v2; // eax
FILE *v3; // rdi
int *v4; // rbp
int v5; // er12

v0 = 0;
if ( log_fd < 0 )
{
v2 = open("/var/log/grubby", 525378, 384LL);
v0 = v2;
log_fd = v2;
if ( v2 >= 0 )
{
v3 = fdopen(v2, "a+");
f = (__int64)v3;
if ( v3 )
{
setbuf(v3, 0LL);
v0 = 0;
}
else
{
v4 = _errno_location();
v5 = *v4;
close(v0);
log_fd = -1;
*v4 = v5;
v0 = -1;
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx
int v2; // eax
FILE *v3; // rdi
int *v4; // rbp
int v5; // er12

v0 = 0;
if ( log_fd < 0 )
{
v2 = open("/var/log/grubby", 525378, 384LL);
v0 = v2;
log_fd = v2;
if ( v2 >= 0 )
{
v3 = fdopen(v2, "a+");
f = (__int64)v3;
if ( v3 )
{
setbuf(v3, 0LL);
v0 = 0;
}
else
{
v4 = _errno_location();
v5 = *v4;
close(v0);
log_fd = -1;
*v4 = v5;
v0 = -1;
}
}
}
return v0;
}

original_code:
static int
open_log(void)
{
 if (log_fd > -1)
  return 0;
 log_fd = open("/var/log/grubby", 02|02000|0100|02000000, 0600);
 if (log_fd < 0)
  return log_fd;
 f = fdopen(log_fd, "a+");
 if (f == ((void *)0)) {
  typeof((*__errno_location ())) saved_errno = (*__errno_location ());
  close(log_fd);
  log_fd = -1;
  (*__errno_location ()) = saved_errno;
  return -1;
 }
 setbuf(f, ((void *)0));
 return 0;
}

canonical_original_code:
static int open_log()
{
 if (log_fd > -1)
  return 0;
 log_fd = open("/var/log/grubby", 02|02000|0100|02000000, 0600);
 if (log_fd < 0)
  return log_fd;
 f = fdopen(log_fd, "a+");
 if (f == ((void *)0)) {
  typeof((*__errno_location ())) saved_errno = (*__errno_location ());
  close(log_fd);
  log_fd = -1;
  (*__errno_location ()) = saved_errno;
  return -1;
 }
 setbuf(f, ((void *)0));
 return 0;
}


check

repo: lennartblanco/zdc

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

result = printf("%s [ok]\n", a1);
++passed;
return result;
}

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

result = printf("%s [ok]\n", a1);
++passed;
return result;
}

original_code:
void check(char *function_called)
{
    printf("%s [ok]\n", function_called);
    passed += 1;
}


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

printf("%s ", a1);
if ( a2 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

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

printf("%s ", a1);
if ( a2 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void check_cond(char *function_called, _Bool cond)
{
    printf("%s ", function_called);
    if (cond)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}


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

printf("%s = %d", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

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

printf("%s = %d", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_int(char *function_called, int res, int expected_res)
{
    printf("%s = %d", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types: res int


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

printf("%s = %u", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

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

printf("%s = %u", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_uint(char *function_called, unsigned res, unsigned expected_res)
{
    printf("%s = %u", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

canonical_original_code:
void check_uint(char *function_called, unsigned int res, unsigned int expected_res)
{
    printf("%s = %u", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types:
res
unsigned int


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

printf("%s = %d", a1, (unsigned int)a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

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

printf("%s = %d", a1, (unsigned int)a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_short(char *function_called, short res, short expected_res)
{
    printf("%s = %d", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types: res short


decompiled_code:
int __fastcall check_ushort(const char *a1, unsigned __int16 a2, __int16 a3)
{
int result; // eax

printf("%s = %u", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, unsigned __int16 a2, __int16 a3)
{
int result; // eax

printf("%s = %u", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_ushort(char *function_called,
             unsigned short res,
             unsigned short expected_res)
{
    printf("%s = %u", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types:
res
unsigned short


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

printf("%s = %d", a1, (unsigned int)a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

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

printf("%s = %d", a1, (unsigned int)a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_byte(char *function_called, char res, char expected_res)
{
    printf("%s = %d", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types: res char


decompiled_code:
int __fastcall check_ubyte(const char *a1, unsigned __int8 a2, char a3)
{
int result; // eax

printf("%s = %u", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, unsigned __int8 a2, char a3)
{
int result; // eax

printf("%s = %u", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_ubyte(char *function_called,
            unsigned char res,
            unsigned char expected_res)
{
    printf("%s = %u", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types:
res
unsigned char


decompiled_code:
int __fastcall check_bool(const char *a1, char a2, char a3)
{
const char *v4; // rdx
int result; // eax

v4 = "true";
if ( !a2 )
v4 = "false";
printf("%s = %s", a1, v4);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, char a2, char a3)
{
const char *v4; // rdx
int result; // eax

v4 = "true";
if ( !a2 )
v4 = "false";
printf("%s = %s", a1, v4);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_bool(char *function_called, _Bool res, _Bool expected_res)
{
    printf("%s = %s", function_called, res ? "true" : "false");
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}


decompiled_code:
int __fastcall check_char(const char *a1, unsigned __int8 a2, char a3)
{
int result; // eax

printf("%s = ", a1);
if ( (a2 & 0x80u) != 0 || iscntrl(a2) )
printf("%u", a2);
else
printf("'%c'", a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(const char *a1, unsigned __int8 a2, char a3)
{
int result; // eax

printf("%s = ", a1);
if ( (a2 & 0x80u) != 0 || iscntrl(a2) )
printf("%u", a2);
else
printf("'%c'", a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_char(char *function_called,
           unsigned char res,
           unsigned char expected_res)
{
    printf("%s = ", function_called);
    if (isascii(res) != 0 && iscntrl(res) == 0)
    {
      printf("'%c'", res);
    }
    else
    {
      printf("%u", res);
    }
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}


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

printf("%s = %p", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

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

printf("%s = %p", a1, a2);
if ( a2 == a3 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_pointer(char *function_called, void *res, void *expected_res)
{
    printf("%s = %p", function_called, res);
    if (res == expected_res)
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}

variable_types:
res
void *


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

printf("%s = %p", a1, a2);
if ( a2 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

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

printf("%s = %p", a1, a2);
if ( a2 )
{
result = puts(" [ok]");
++passed;
}
else
{
result = puts(" unexpected result!");
++failed;
}
return result;
}

original_code:
void
check_non_null_ptr(char *function_called, void *res)
{
    printf("%s = %p", function_called, res);
    if (res != ((void *)0))
    {
        printf(" [ok]\n");
        passed += 1;
    }
    else
    {
        printf(" unexpected result!\n");
        failed += 1;
    }
}


decompiled_code:
void __noreturn check_exit()
{
printf("passed: %d failed: %d\n", (unsigned int)passed, (unsigned int)failed);
if ( failed )
exit(-1);
exit(0);
}

canonical_decompiled_code:
void __noreturn func12()
{
printf("passed: %d failed: %d\n", (unsigned int)passed, (unsigned int)failed);
if ( failed )
exit(-1);
exit(0);
}

original_code:
void
check_exit()
{
    printf("passed: %d failed: %d\n", passed, failed);
    if (failed != 0)
    {
        exit(-1);
    }
    exit(0);
}


decompiled_code:
bool __fastcall ir_is_struct_literal(_QWORD *a1)
{
__int64 v1; // rsi
int v2; // eax

v1 = ir_struct_literal_get_type();
v2 = 0;
if ( a1 )
{
if ( !*a1 || (v2 = 1, *(_QWORD *)*a1 != v1) )
v2 = g_type_check_instance_is_a(a1, v1);
}
return v2 != 0;
}

canonical_decompiled_code:
bool __fastcall func3(_QWORD *a1)
{
__int64 v1; // rsi
int v2; // eax

v1 = func2();
v2 = 0;
if ( a1 )
{
if ( !*a1 || (v2 = 1, *(_QWORD *)*a1 != v1) )
v2 = g_type_check_instance_is_a(a1, v1);
}
return v2 != 0;
}

original_code:
_Bool
ir_is_struct_literal(void *obj)
{
    return ((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (obj); GType __t = (ir_struct_literal_get_type()); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}

canonical_original_code:
_Bool ir_is_struct_literal(void *obj)
{
    return ((__extension__ ({ struct _GTypeInstance *__inst = (GTypeInstance*) (obj); unsigned long __t = (ir_struct_literal_get_type()); int __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })));
}

variable_types:
obj
void *

variable_types: struct _GTypeInstance { struct _GTypeClass { unsigned long g_type; } *g_class; } *

user_defined_types: struct _GTypeInstance { struct _GTypeClass *g_class; }


decompiled_code:
__int64 __fastcall g_type_from_instance(__int64 a1)
{
return **(_QWORD **)a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return **(_QWORD **)a1;
}

original_code:
GType
g_type_from_instance(void *obj)
{
    return ((((GTypeClass*) (((GTypeInstance*) (obj))->g_class))->g_type));
}

canonical_original_code:
unsigned long g_type_from_instance(void *obj)
{
    return ((((struct _GTypeClass *) (((struct _GTypeInstance *) (obj))->g_class))->g_type));
}

return_type: unsigned long

user_defined_types: struct _GTypeClass { unsigned long g_type; }


decompiled_code:
bool __fastcall g_is_object(__int64 a1)
{
return (unsigned int)g_type_check_instance_is_fundamentally_a(a1, 80LL) != 0;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
return (unsigned int)g_type_check_instance_is_fundamentally_a(a1, 80LL) != 0;
}

original_code:
_Bool
g_is_object(void *obj)
{
    return (((g_type_check_instance_is_fundamentally_a ((GTypeInstance*) ((obj)), (((GType) ((20) << (2))))))));
}

canonical_original_code:
_Bool g_is_object(void *obj)
{
    return (((g_type_check_instance_is_fundamentally_a ((struct _GTypeInstance *) ((obj)), (((GType) ((20) << (2))))))));
}


decompiled_code:
__int64 sym_table_error_quark()
{
return g_quark_from_static_string("zdc-sym-table-error-quark");
}

canonical_decompiled_code:
__int64 func0()
{
return g_quark_from_static_string("zdc-sym-table-error-quark");
}

original_code:
static GQuark
sym_table_error_quark(void)
{
    return g_quark_from_static_string ("zdc-sym-table-error-quark");
}

canonical_original_code:
static unsigned int sym_table_error_quark()
{
    return g_quark_from_static_string ("zdc-sym-table-error-quark");
}

return_type: unsigned int