decompiled_code:
__int64 ht_attr_get(_QWORD *a1, unsigned int a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return ht_attr_ctrl(0, a1, a2, (__int64)va);
}

canonical_decompiled_code:
__int64 func4(_QWORD *a1, unsigned int a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return func3(0, a1, a2, (__int64)va);
}

original_code:
int
ht_attr_get(ht_attr_t a, int op, ...)
{
    va_list ap;
    int rc;
    __builtin_va_start(ap,op);
    rc = ht_attr_ctrl(HT_ATTR_GET, a, op, ap);
    __builtin_va_end(ap);
    return rc;
}

canonical_original_code:
int ht_attr_get(struct ht_attr_st *a, int op, ...)
{
    __builtin_va_list ap;
    int rc;
    __builtin_va_start(ap,op);
    rc = ht_attr_ctrl(HT_ATTR_GET, a, op, ap);
    __builtin_va_end(ap);
    return rc;
}

variable_types: op int

user_defined_types: enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 }

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

user_defined_types: struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; }

user_defined_types: struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; }

user_defined_types: struct _libc_xmmreg { unsigned int element[4]; }


repo: watsonjiang/hybirdthread

decompiled_code:
__int64 ht_attr_set(_QWORD *a1, unsigned int a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return ht_attr_ctrl(1, a1, a2, (__int64)va);
}

canonical_decompiled_code:
__int64 func5(_QWORD *a1, unsigned int a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return func3(1, a1, a2, (__int64)va);
}

original_code:
int
ht_attr_set(ht_attr_t a, int op, ...)
{
    va_list ap;
    int rc;
    __builtin_va_start(ap,op);
    rc = ht_attr_ctrl(HT_ATTR_SET, a, op, ap);
    __builtin_va_end(ap);
    return rc;
}

canonical_original_code:
int ht_attr_set(struct ht_attr_st *a, int op, ...)
{
    __builtin_va_list ap;
    int rc;
    __builtin_va_start(ap,op);
    rc = ht_attr_ctrl(HT_ATTR_SET, a, op, ap);
    __builtin_va_end(ap);
    return rc;
}

variable_types: struct ht_attr_st { struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; } *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } *a_tid; int a_prio; int a_dispatches; char a_name[40]; int a_joinable; unsigned int a_cancelstate; unsigned int a_stacksize; char *a_stackaddr; } *

variable_types: rc int

return_type: int

user_defined_types: struct ht_attr_st { struct ht_st *a_tid; int a_prio; int a_dispatches; char a_name[40]; int a_joinable; unsigned int a_cancelstate; unsigned int a_stacksize; char *a_stackaddr; }

user_defined_types: struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en state; struct timeval spawned; struct timeval lastran; struct timeval running; struct ht_event_st *events; struct ht_mctx_st mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st *cleanups; struct ht_ring_st mutexring; }

user_defined_types: struct ht_mctx_st { struct ucontext_t uc; int restored; int error; }

user_defined_types: struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st *mp; } MSG; struct { struct ht_mutex_st *mutex; } MUTEX; struct { struct ht_cond_st *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }

user_defined_types: struct ht_msgport_st { struct ht_ringnode_st mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st mp_queue; }


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

if ( !ptr )
return;
v2 = (void *)*((_QWORD *)ptr + 138);
if ( v2 && !*((_DWORD *)ptr + 282) )
{
free(v2);
v3 = (void *)*((_QWORD *)ptr + 146);
if ( !v3 )
goto LABEL_6;
goto LABEL_5;
}
v3 = (void *)*((_QWORD *)ptr + 146);
if ( v3 )
LABEL_5:
free(v3);
LABEL_6:
if ( *((_QWORD *)ptr + 149) )
ht_cleanup_popall(ptr, 0LL);
free(ptr);
}

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

if ( !ptr )
return;
v2 = (void *)*((_QWORD *)ptr + 138);
if ( v2 && !*((_DWORD *)ptr + 282) )
{
free(v2);
v3 = (void *)*((_QWORD *)ptr + 146);
if ( !v3 )
goto LABEL_6;
goto LABEL_5;
}
v3 = (void *)*((_QWORD *)ptr + 146);
if ( v3 )
LABEL_5:
free(v3);
LABEL_6:
if ( *((_QWORD *)ptr + 149) )
ht_cleanup_popall(ptr, 0LL);
free(ptr);
}

original_code:
void
ht_tcb_free(ht_t t)
{
    if (t == ((void *)0))
        return;
    if (t->stack != ((void *)0) && !t->stackloan)
        free(t->stack);
    if (t->data_value != ((void *)0))
        free(t->data_value);
    if (t->cleanups != ((void *)0))
        ht_cleanup_popall(t, (0));
    free(t);
    return;
}

canonical_original_code:
void ht_tcb_free(struct ht_st *t)
{
    if (t == ((void *)0))
        return;
    if (t->stack != ((void *)0) && !t->stackloan)
        free(t->stack);
    if (t->data_value != ((void *)0))
        free(t->data_value);
    if (t->cleanups != ((void *)0))
        ht_cleanup_popall(t, (0));
    free(t);
    return;
}

variable_types: struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; } *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } *

return_type: void


decompiled_code:
__int64 ht_debug(const char *a1, unsigned int a2, int a3, __int64 a4, ...)
{
int *v5; // rbx
int v6; // eax
unsigned int v7; // eax
size_t v8; // rax
char *v9; // rdi
size_t v10; // rax
__int64 result; // rax
gcc_va_list va; // [rsp+18h] [rbp-100h] BYREF

va_start(va, a4);
v5 = _errno_location();
v6 = *v5;
ht_errno_flag = 1;
ht_errno_storage = v6;
if ( a1 )
{
v7 = getpid();
ht_snprintf(str_0, 1024LL, "%d:%s:%04d: ", v7, a1, a2);
}
else
{
str_0[0] = 0;
}
v8 = strlen(str_0);
v9 = &str_0[v8];
if ( a3 == 1 )
ht_util_cpystrn(v9, a4, 1024 - v8);
else
ht_vsnprintf(v9, 1024 - v8, a4, va);
v10 = strlen(str_0);
str_0[v10] = 10;
write(2, str_0, v10 + 1);
result = ht_errno_storage;
*v5 = ht_errno_storage;
ht_errno_flag = 0;
return result;
}

canonical_decompiled_code:
__int64 func0(const char *a1, unsigned int a2, int a3, __int64 a4, ...)
{
int *v5; // rbx
int v6; // eax
unsigned int v7; // eax
size_t v8; // rax
char *v9; // rdi
size_t v10; // rax
__int64 result; // rax
gcc_va_list va; // [rsp+18h] [rbp-100h] BYREF

va_start(va, a4);
v5 = _errno_location();
v6 = *v5;
ht_errno_flag = 1;
ht_errno_storage = v6;
if ( a1 )
{
v7 = getpid();
ht_snprintf(str_0, 1024LL, "%d:%s:%04d: ", v7, a1, a2);
}
else
{
str_0[0] = 0;
}
v8 = strlen(str_0);
v9 = &str_0[v8];
if ( a3 == 1 )
ht_util_cpystrn(v9, a4, 1024 - v8);
else
ht_vsnprintf(v9, 1024 - v8, a4, va);
v10 = strlen(str_0);
str_0[v10] = 10;
write(2, str_0, v10 + 1);
result = ht_errno_storage;
*v5 = ht_errno_storage;
ht_errno_flag = 0;
return result;
}

original_code:
void
ht_debug(const char *file, int line, int argc, const char *fmt, ...)
{
    va_list ap;
    static char str[1024];
    size_t n;
    for ( ht_errno_storage = (*__errno_location ()), ht_errno_flag = (!(0)); ht_errno_flag; (*__errno_location ()) = ht_errno_storage, ht_errno_flag = (0) ) {
        __builtin_va_start(ap,fmt);
        if (file != ((void *)0))
            ht_snprintf(str, sizeof(str), "%d:%s:%04d: ", (int)getpid(), file, line);
        else
            str[0] = '\0';
        n = strlen(str);
        if (argc == 1)
            ht_util_cpystrn(str+n, fmt, sizeof(str)-n);
        else
            ht_vsnprintf(str+n, sizeof(str)-n, fmt, ap);
        __builtin_va_end(ap);
        n = strlen(str);
        str[n++] = '\n';
        write(2, str, n);
    }
    return;
}

canonical_original_code:
void ht_debug(char *file, int line, int argc, char *fmt, ...)
{
    __builtin_va_list ap;
    static char str[1024];
    unsigned long n;
    for ( ht_errno_storage = (*__errno_location ()), ht_errno_flag = (!(0)); ht_errno_flag; (*__errno_location ()) = ht_errno_storage, ht_errno_flag = (0) ) {
        __builtin_va_start(ap,fmt);
        if (file != ((void *)0))
            ht_snprintf(str, sizeof(str), "%d:%s:%04d: ", (int)getpid(), file, line);
        else
            str[0] = '\0';
        n = strlen(str);
        if (argc == 1)
            ht_util_cpystrn(str+n, fmt, sizeof(str)-n);
        else
            ht_vsnprintf(str+n, sizeof(str)-n, fmt, ap);
        __builtin_va_end(ap);
        n = strlen(str);
        str[n++] = '\n';
        write(2, str, n);
    }
    return;
}

variable_types:
file
char *

variable_types: line int

variable_types: argc int

variable_types:
fmt
char *

variable_types:
str
char [1024]

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall ht_mctx_set(ucontext_t *a1, void (*a2)(void), void *a3, __int64 a4)
{
int v4; // er8
__int64 result; // rax

v4 = getcontext(a1);
result = 0LL;
if ( !v4 )
{
a1->uc_stack.ss_sp = a3;
a1->uc_stack.ss_size = a4 - (_QWORD)a3;
a1->uc_link = 0LL;
a1->uc_stack.ss_flags = 0;
makecontext(a1, a2, 1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(ucontext_t *a1, void (*a2)(void), void *a3, __int64 a4)
{
int v4; // er8
__int64 result; // rax

v4 = getcontext(a1);
result = 0LL;
if ( !v4 )
{
a1->uc_stack.ss_sp = a3;
a1->uc_stack.ss_size = a4 - (_QWORD)a3;
a1->uc_link = 0LL;
a1->uc_stack.ss_flags = 0;
makecontext(a1, a2, 1);
result = 1LL;
}
return result;
}

original_code:
int
ht_mctx_set(
    ht_mctx_t *mctx, void (*func)(void), char *sk_addr_lo, char *sk_addr_hi)
{
    if (getcontext(&(mctx->uc)) != 0)
        return (0);
    mctx->uc.uc_link = ((void *)0);
    mctx->uc.uc_stack.ss_sp = sk_addr_lo;
    mctx->uc.uc_stack.ss_size = sk_addr_hi-sk_addr_lo;
    mctx->uc.uc_stack.ss_flags = 0;
    makecontext(&(mctx->uc), func, 0+1);
    return (!(0));
}

canonical_original_code:
int ht_mctx_set(struct ht_mctx_st *mctx, void (*func)(), char *sk_addr_lo, char *sk_addr_hi)
{
    if (getcontext(&(mctx->uc)) != 0)
        return (0);
    mctx->uc.uc_link = ((void *)0);
    mctx->uc.uc_stack.ss_sp = sk_addr_lo;
    mctx->uc.uc_stack.ss_size = sk_addr_hi-sk_addr_lo;
    mctx->uc.uc_stack.ss_flags = 0;
    makecontext(&(mctx->uc), func, 0+1);
    return (!(0));
}

variable_types: struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } *

variable_types:
func
void (*)()


disconnectClient

repo: waywardgeek/comserial

decompiled_code:
void __fastcall disconnectClient(void *ptr)
{
__int64 v1; // rdx

if ( coEndSession )
coEndSession(*((_QWORD *)ptr + 4));
if ( coCurrentClient == ptr )
coCurrentClient = 0LL;
v1 = *(int *)ptr;
*((_QWORD *)coClientTable + v1) = 0LL;
close(v1);
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
__int64 v1; // rdx

if ( coEndSession )
coEndSession(*((_QWORD *)ptr + 4));
if ( coCurrentClient == ptr )
coCurrentClient = 0LL;
v1 = *(int *)ptr;
*((_QWORD *)coClientTable + v1) = 0LL;
close(v1);
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
static void disconnectClient(
    coClient client)
{
    if(coEndSession != ((void *)0)) {
 coEndSession(client->sessionID);
    }
    if(client == coCurrentClient) {
 coCurrentClient = ((void *)0);
    }
    coClientTable[client->sockfd] = ((void *)0);
    close(client->sockfd);
    free(client->message);
    free(client);
}

canonical_original_code:
static void disconnectClient(struct coClientStruct *client)
{
    if(coEndSession != ((void *)0)) {
 coEndSession(client->sessionID);
    }
    if(client == coCurrentClient) {
 coCurrentClient = ((void *)0);
    }
    coClientTable[client->sockfd] = ((void *)0);
    close(client->sockfd);
    free(client->message);
    free(client);
}

variable_types: struct coClientStruct { int sockfd; char *message; unsigned int messageSize; unsigned int messagePos; char *sessionID; struct coClientStruct *nextReadyClient; } *


acceptConnection

decompiled_code:
int acceptConnection()
{
int result; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-7Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-78h] BYREF

addr_len = 110;
result = accept(coServerSockfd, &addr, &addr_len);
if ( result < 0 )
{
perror("Failed to accept socket");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-7Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-78h] BYREF

addr_len = 110;
result = accept(coServerSockfd, &addr, &addr_len);
if ( result < 0 )
{
perror("Failed to accept socket");
exit(1);
}
return result;
}

original_code:
static int acceptConnection(void)
{
    struct sockaddr_un clientAddress;
    socklen_t length = sizeof(clientAddress);
    int clientSockfd = accept(coServerSockfd, (struct sockaddr*)&clientAddress, &length);
    if(clientSockfd < 0) {
        perror("Failed to accept socket");
        exit(1);
    }
    return clientSockfd;
}

canonical_original_code:
static int acceptConnection()
{
    struct sockaddr_un clientAddress;
    unsigned int length = sizeof(clientAddress);
    int clientSockfd = accept(coServerSockfd, (struct sockaddr*)&clientAddress, &length);
    if(clientSockfd < 0) {
        perror("Failed to accept socket");
        exit(1);
    }
    return clientSockfd;
}

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

variable_types:
length
unsigned int

variable_types: clientSockfd int


acceptNewClient

decompiled_code:
_QWORD *acceptNewClient()
{
__int64 v0; // rbx
_DWORD *v1; // rax
_DWORD *v2; // rbp
void *v3; // rax
bool v4; // cf
_QWORD *result; // rax

v0 = acceptConnection();
v1 = calloc(1uLL, 0x30uLL);
*v1 = v0;
v2 = v1;
v1[4] = 42;
v3 = calloc(0x2AuLL, 1uLL);
v4 = (unsigned int)v0 < (unsigned int)coClientTableSize;
*((_QWORD *)v2 + 1) = v3;
result = coClientTable;
if ( v4 )
{
*((_QWORD *)coClientTable + v0) = v2;
}
else
{
LODWORD(coClientTableSize) = v0 + ((int)v0 >> 1);
result = realloc(coClientTable, 8LL * (unsigned int)(v0 + ((int)v0 >> 1)));
result[v0] = v2;
coClientTable = result;
}
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
__int64 v0; // rbx
_DWORD *v1; // rax
_DWORD *v2; // rbp
void *v3; // rax
bool v4; // cf
_QWORD *result; // rax

v0 = func1();
v1 = calloc(1uLL, 0x30uLL);
*v1 = v0;
v2 = v1;
v1[4] = 42;
v3 = calloc(0x2AuLL, 1uLL);
v4 = (unsigned int)v0 < (unsigned int)coClientTableSize;
*((_QWORD *)v2 + 1) = v3;
result = coClientTable;
if ( v4 )
{
*((_QWORD *)coClientTable + v0) = v2;
}
else
{
LODWORD(coClientTableSize) = v0 + ((int)v0 >> 1);
result = realloc(coClientTable, 8LL * (unsigned int)(v0 + ((int)v0 >> 1)));
result[v0] = v2;
coClientTable = result;
}
return result;
}

original_code:
static void acceptNewClient(void)
{
    int sockfd = acceptConnection();
    coClient client = (coClient)calloc(1, sizeof(struct coClientStruct));
    client->sockfd = sockfd;
    client->messageSize = 42;
    client->message = (char *)calloc(client->messageSize, sizeof(char));
    if(sockfd >= coClientTableSize) {
        coClientTableSize = sockfd + (sockfd >> 1);
        coClientTable = (coClient *)realloc(coClientTable, coClientTableSize*sizeof(coClient));
    }
    coClientTable[sockfd] = client;
}

canonical_original_code:
static void acceptNewClient()
{
    int sockfd = acceptConnection();
    struct coClientStruct *client = (coClient)calloc(1, sizeof(struct coClientStruct));
    client->sockfd = sockfd;
    client->messageSize = 42;
    client->message = (char *)calloc(client->messageSize, sizeof(char));
    if(sockfd >= coClientTableSize) {
        coClientTableSize = sockfd + (sockfd >> 1);
        coClientTable = (struct coClientStruct **)realloc(coClientTable, coClientTableSize*sizeof(coClient));
    }
    coClientTable[sockfd] = client;
}

variable_types: sockfd int

user_defined_types: struct coClientStruct { int sockfd; char *message; unsigned int messageSize; unsigned int messagePos; char *sessionID; struct coClientStruct *nextReadyClient; }


readMessage

decompiled_code:
void __fastcall readMessage(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 v7; // rbx
__int64 v8; // rbp
signed __int64 v9; // rax
size_t v10; // r13
__int64 v11; // rdx
__int64 v12; // rcx
void *v13; // rdi
int v14; // er13
__int64 v15; // rdx
__int64 v16; // rax
bool v17; // cc
size_t v18; // rsi
void *v19; // rax
char *v20; // rax
__int64 v21; // rax
char v22[4136]; // [rsp-1028h] [rbp-1028h] BYREF

if ( (_DWORD)coClientTableSize )
{
v7 = 0LL;
while ( 1 )
{
v8 = *((_QWORD *)coClientTable + v7);
if ( !v8 || (*(&a7 + ((int)v7 >> 6)) & (1LL << v7)) == 0 )
goto LABEL_3;
v9 = read(v7, v22, 0x1000uLL);
v10 = v9;
if ( v9 <= 0 )
{
if ( *_errno_location() != 11 )
disconnectClient((void *)v8);
goto LABEL_3;
}
if ( *(_QWORD *)(v8 + 32) )
{
v11 = *(unsigned int *)(v8 + 20);
v12 = *(unsigned int *)(v8 + 16);
v13 = *(void **)(v8 + 8);
if ( v11 + v9 >= v12 )
{
v18 = (unsigned int)v9 + ((unsigned int)v12 >> 1) + *(_DWORD *)(v8 + 20);
*(_DWORD *)(v8 + 16) = v18;
v19 = realloc(v13, v18);
v11 = *(unsigned int *)(v8 + 20);
*(_QWORD *)(v8 + 8) = v19;
v13 = v19;
}
strncpy((char *)v13 + v11, v22, v10);
v14 = *(_DWORD *)(v8 + 20) + v10;
v15 = *(_QWORD *)(v8 + 8);
*(_DWORD *)(v8 + 20) = v14;
if ( *(_BYTE *)(v15 + (unsigned int)(v14 - 1)) )
goto LABEL_3;
v16 = firstReadyClient;
v17 = (unsigned int)coClientTableSize <= (unsigned int)++v7;
firstReadyClient = v8;
*(_DWORD *)(v8 + 24) = 0;
*(_QWORD *)(v8 + 40) = v16;
if ( v17 )
return;
}
else
{
v20 = (char *)calloc(v9, 1uLL);
*(_QWORD *)(v8 + 32) = v20;
strcpy(v20, v22);
v21 = firstReadyClient;
firstReadyClient = v8;
*(_QWORD *)(v8 + 40) = v21;
LABEL_3:
if ( (unsigned int)coClientTableSize <= (unsigned int)++v7 )
return;
}
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 v7; // rbx
__int64 v8; // rbp
signed __int64 v9; // rax
size_t v10; // r13
__int64 v11; // rdx
__int64 v12; // rcx
void *v13; // rdi
int v14; // er13
__int64 v15; // rdx
__int64 v16; // rax
bool v17; // cc
size_t v18; // rsi
void *v19; // rax
char *v20; // rax
__int64 v21; // rax
char v22[4136]; // [rsp-1028h] [rbp-1028h] BYREF

if ( (_DWORD)coClientTableSize )
{
v7 = 0LL;
while ( 1 )
{
v8 = *((_QWORD *)coClientTable + v7);
if ( !v8 || (*(&a7 + ((int)v7 >> 6)) & (1LL << v7)) == 0 )
goto LABEL_3;
v9 = read(v7, v22, 0x1000uLL);
v10 = v9;
if ( v9 <= 0 )
{
if ( *_errno_location() != 11 )
func0((void *)v8);
goto LABEL_3;
}
if ( *(_QWORD *)(v8 + 32) )
{
v11 = *(unsigned int *)(v8 + 20);
v12 = *(unsigned int *)(v8 + 16);
v13 = *(void **)(v8 + 8);
if ( v11 + v9 >= v12 )
{
v18 = (unsigned int)v9 + ((unsigned int)v12 >> 1) + *(_DWORD *)(v8 + 20);
*(_DWORD *)(v8 + 16) = v18;
v19 = realloc(v13, v18);
v11 = *(unsigned int *)(v8 + 20);
*(_QWORD *)(v8 + 8) = v19;
v13 = v19;
}
strncpy((char *)v13 + v11, v22, v10);
v14 = *(_DWORD *)(v8 + 20) + v10;
v15 = *(_QWORD *)(v8 + 8);
*(_DWORD *)(v8 + 20) = v14;
if ( *(_BYTE *)(v15 + (unsigned int)(v14 - 1)) )
goto LABEL_3;
v16 = firstReadyClient;
v17 = (unsigned int)coClientTableSize <= (unsigned int)++v7;
firstReadyClient = v8;
*(_DWORD *)(v8 + 24) = 0;
*(_QWORD *)(v8 + 40) = v16;
if ( v17 )
return;
}
else
{
v20 = (char *)calloc(v9, 1uLL);
*(_QWORD *)(v8 + 32) = v20;
strcpy(v20, v22);
v21 = firstReadyClient;
firstReadyClient = v8;
*(_QWORD *)(v8 + 40) = v21;
LABEL_3:
if ( (unsigned int)coClientTableSize <= (unsigned int)++v7 )
return;
}
}
}
}

original_code:
static void readMessage(
    fd_set readSockets)
{
    coClient client;
    int xClient;
    char buf[4096];
    ssize_t length;
    for(xClient = 0; xClient < coClientTableSize; xClient++) {
        client = coClientTable[xClient];
        if(client != ((void *)0)) {
            if(((((&readSockets)->__fds_bits)[((xClient) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((xClient) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                length = read(xClient, buf, 4096);
                if(length <= 0) {
                    if(length <= 0 && (*__errno_location ()) != 11) {
                        disconnectClient(client);
                    }
                } else if(client->sessionID == ((void *)0)) {
                    client->sessionID = (char *)calloc(length, sizeof(char));
                    strcpy(client->sessionID, buf);
                    client->nextReadyClient = firstReadyClient;
                    firstReadyClient = client;
                } else {
                    if(length + client->messageLength >= client->messageSize) {
                        client->messageSize = length + client->messageLength + (client->messageSize >> 1);
                        client->message = (char *)realloc(client->message, client->messageSize*sizeof(char));
                    }
                    strncpy(client->message + client->messageLength, buf, length);
                    client->messageLength += length;
                    if(client->message[client->messageLength - 1] == '\0') {
                        client->nextReadyClient = firstReadyClient;
                        firstReadyClient = client;
                        client->messagePos = 0;
                    }
                }
            }
        }
    }
}

canonical_original_code:
static void readMessage(struct fd_set readSockets)
{
    struct coClientStruct *client;
    int xClient;
    char buf[4096];
    long length;
    for(xClient = 0; xClient < coClientTableSize; xClient++) {
        client = coClientTable[xClient];
        if(client != ((void *)0)) {
            if(((((&readSockets)->__fds_bits)[((xClient) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((xClient) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                length = read(xClient, buf, 4096);
                if(length <= 0) {
                    if(length <= 0 && (*__errno_location ()) != 11) {
                        disconnectClient(client);
                    }
                } else if(client->sessionID == ((void *)0)) {
                    client->sessionID = (char *)calloc(length, sizeof(char));
                    strcpy(client->sessionID, buf);
                    client->nextReadyClient = firstReadyClient;
                    firstReadyClient = client;
                } else {
                    if(length + client->messageLength >= client->messageSize) {
                        client->messageSize = length + client->messageLength + (client->messageSize >> 1);
                        client->message = (char *)realloc(client->message, client->messageSize*sizeof(char));
                    }
                    strncpy(client->message + client->messageLength, buf, length);
                    client->messageLength += length;
                    if(client->message[client->messageLength - 1] == '\0') {
                        client->nextReadyClient = firstReadyClient;
                        firstReadyClient = client;
                        client->messagePos = 0;
                    }
                }
            }
        }
    }
}

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

variable_types: xClient int

variable_types:
buf
char [4096]

variable_types: length long


flushBuffer

decompiled_code:
void flushBuffer()
{
if ( coCurrentClient )
{
if ( coBufferPosition != (unsigned int)write(*(_DWORD *)coCurrentClient, &coBuffer, coBufferPosition) )
disconnectClient(coCurrentClient);
coBufferPosition = 0;
}
}

canonical_decompiled_code:
void func4()
{
if ( coCurrentClient )
{
if ( coBufferPosition != (unsigned int)write(*(_DWORD *)coCurrentClient, &coBuffer, coBufferPosition) )
func0(coCurrentClient);
coBufferPosition = 0;
}
}

original_code:
static void flushBuffer(void)
{
    int bytesWritten;
    if(coCurrentClient == ((void *)0)) {
 return;
    }
    bytesWritten = write(coCurrentClient->sockfd, coBuffer, coBufferPosition);
    if(bytesWritten != coBufferPosition) {
        disconnectClient(coCurrentClient);
    }
    coBufferPosition = 0;
}

canonical_original_code:
static void flushBuffer()
{
    int bytesWritten;
    if(coCurrentClient == ((void *)0)) {
 return;
    }
    bytesWritten = write(coCurrentClient->sockfd, coBuffer, coBufferPosition);
    if(bytesWritten != coBufferPosition) {
        disconnectClient(coCurrentClient);
    }
    coBufferPosition = 0;
}

variable_types: bytesWritten int


writeBufferedBytes

decompiled_code:
__int64 __fastcall writeBufferedBytes(__int64 *a1, int a2)
{
__int64 result; // rax
int v3; // er8
char *v4; // rdx

if ( a2 > 4096 )
{
perror("Write size too large.");
exit(1);
}
result = coBufferPosition;
v3 = coBufferPosition + a2;
if ( coBufferPosition + a2 > 4095 )
{
flushBuffer();
result = coBufferPosition;
v3 = a2 + coBufferPosition;
}
v4 = (char *)&coBuffer + result;
if ( (unsigned __int64)a2 >= 8 )
{
*(__int64 *)((char *)&coBuffer + result) = *a1;
result = *(__int64 *)((char *)a1 + a2 - 8);
*(_QWORD *)&v4[a2 - 8] = result;
qmemcpy(
(void *)((unsigned __int64)(v4 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)a1 - &v4[-((unsigned __int64)(v4 + 8) & 0xFFFFFFFFFFFFFFF8LL)]),
8 * ((unsigned __int64)&v4[a2 - ((unsigned __int64)(v4 + 8) & 0xFFFFFFFFFFFFFFF8LL)] >> 3));
coBufferPosition = v3;
}
else
{
if ( (a2 & 4) != 0 )
{
*(_DWORD *)((char *)&coBuffer + result) = *(_DWORD *)a1;
result = *(unsigned int *)((char *)a1 + a2 - 4);
*(_DWORD *)&v4[a2 - 4] = result;
}
else if ( a2 )
{
*((_BYTE *)&coBuffer + result) = *(_BYTE *)a1;
if ( (a2 & 2) != 0 )
{
result = *(unsigned __int16 *)((char *)a1 + a2 - 2);
*(_WORD *)&v4[a2 - 2] = result;
}
}
coBufferPosition = v3;
}
return result;
}

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

if ( a2 > 4096 )
{
perror("Write size too large.");
exit(1);
}
result = coBufferPosition;
v3 = coBufferPosition + a2;
if ( coBufferPosition + a2 > 4095 )
{
func4();
result = coBufferPosition;
v3 = a2 + coBufferPosition;
}
v4 = (char *)&coBuffer + result;
if ( (unsigned __int64)a2 >= 8 )
{
*(__int64 *)((char *)&coBuffer + result) = *a1;
result = *(__int64 *)((char *)a1 + a2 - 8);
*(_QWORD *)&v4[a2 - 8] = result;
qmemcpy(
(void *)((unsigned __int64)(v4 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)a1 - &v4[-((unsigned __int64)(v4 + 8) & 0xFFFFFFFFFFFFFFF8LL)]),
8 * ((unsigned __int64)&v4[a2 - ((unsigned __int64)(v4 + 8) & 0xFFFFFFFFFFFFFFF8LL)] >> 3));
coBufferPosition = v3;
}
else
{
if ( (a2 & 4) != 0 )
{
*(_DWORD *)((char *)&coBuffer + result) = *(_DWORD *)a1;
result = *(unsigned int *)((char *)a1 + a2 - 4);
*(_DWORD *)&v4[a2 - 4] = result;
}
else if ( a2 )
{
*((_BYTE *)&coBuffer + result) = *(_BYTE *)a1;
if ( (a2 & 2) != 0 )
{
result = *(unsigned __int16 *)((char *)a1 + a2 - 2);
*(_WORD *)&v4[a2 - 2] = result;
}
}
coBufferPosition = v3;
}
return result;
}

original_code:
static void writeBufferedBytes(
    char *buffer,
    int length)
{
    if(length > 4096) {
        perror("Write size too large.");
        exit(1);
    }
    if(coBufferPosition + length >= 4096) {
 flushBuffer();
    }
    memcpy(coBuffer + coBufferPosition, buffer, length);
    coBufferPosition += length;
}

canonical_original_code:
static void writeBufferedBytes(char *buffer, int length)
{
    if(length > 4096) {
        perror("Write size too large.");
        exit(1);
    }
    if(coBufferPosition + length >= 4096) {
 flushBuffer();
    }
    memcpy(coBuffer + coBufferPosition, buffer, length);
    coBufferPosition += length;
}

variable_types:
buffer
char *

variable_types: length int


coStartServer

decompiled_code:
void *__fastcall coStartServer(void *src)
{
int v1; // er12
int v2; // eax
size_t v3; // r12
void *result; // rax
struct sockaddr v5[6]; // [rsp+0h] [rbp-88h] BYREF
char v6; // [rsp+6Dh] [rbp-1Bh]

unlink((const char *)src);
coServerSockfd = socket(1, 1, 0);
v1 = coServerSockfd;
v5[0].sa_family = 1;
strncpy(v5[0].sa_data, (const char *)src, 0x6BuLL);
v6 = 0;
v2 = strlen(v5[0].sa_data);
if ( bind(v1, v5, v2 + 2) )
{
perror("failed to bind socket");
exit(1);
}
listen(v1, 5);
v3 = strlen((const char *)src) + 1;
coSocketPath = (char *)calloc(v3, 1uLL);
memcpy(coSocketPath, src, v3);
result = calloc((unsigned int)coClientTableSize, 8uLL);
coServerStarted = 1;
coClientTable = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func6(void *src)
{
int v1; // er12
int v2; // eax
size_t v3; // r12
void *result; // rax
struct sockaddr v5[6]; // [rsp+0h] [rbp-88h] BYREF
char v6; // [rsp+6Dh] [rbp-1Bh]

unlink((const char *)src);
coServerSockfd = socket(1, 1, 0);
v1 = coServerSockfd;
v5[0].sa_family = 1;
strncpy(v5[0].sa_data, (const char *)src, 0x6BuLL);
v6 = 0;
v2 = strlen(v5[0].sa_data);
if ( bind(v1, v5, v2 + 2) )
{
perror("failed to bind socket");
exit(1);
}
listen(v1, 5);
v3 = strlen((const char *)src) + 1;
coSocketPath = (char *)calloc(v3, 1uLL);
memcpy(coSocketPath, src, v3);
result = calloc((unsigned int)coClientTableSize, 8uLL);
coServerStarted = 1;
coClientTable = result;
return result;
}

original_code:
void coStartServer(
    char *fileSocketPath)
{
    int serverLen;
    struct sockaddr_un serverAddress;
    unlink(fileSocketPath);
    coServerSockfd = socket(1, SOCK_STREAM, 0);
    serverAddress.sun_family = 1;
    strncpy(serverAddress.sun_path, fileSocketPath, 108);
    serverAddress.sun_path[108 - 1] = '\0';
    serverLen = strlen(serverAddress.sun_path) + 2;
    if(bind(coServerSockfd, (struct sockaddr*)&serverAddress, serverLen)) {
        perror("failed to bind socket");
        exit(1);
    }
    listen(coServerSockfd, 5);
    coSocketPath = calloc(strlen(fileSocketPath) + 1, sizeof(char));
    strcpy(coSocketPath, fileSocketPath);
    coClientTable = (coClient *)calloc(coClientTableSize, sizeof(coClient));
    coServerStarted = 1;
}

canonical_original_code:
void coStartServer(char *fileSocketPath)
{
    int serverLen;
    struct sockaddr_un serverAddress;
    unlink(fileSocketPath);
    coServerSockfd = socket(1, SOCK_STREAM, 0);
    serverAddress.sun_family = 1;
    strncpy(serverAddress.sun_path, fileSocketPath, 108);
    serverAddress.sun_path[108 - 1] = '\0';
    serverLen = strlen(serverAddress.sun_path) + 2;
    if(bind(coServerSockfd, (struct sockaddr *)&serverAddress, serverLen)) {
        perror("failed to bind socket");
        exit(1);
    }
    listen(coServerSockfd, 5);
    coSocketPath = calloc(strlen(fileSocketPath) + 1, sizeof(char));
    strcpy(coSocketPath, fileSocketPath);
    coClientTable = (struct coClientStruct **)calloc(coClientTableSize, sizeof(coClient));
    coServerStarted = 1;
}

variable_types:
fileSocketPath
char *

variable_types: serverLen int

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

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


coStopServer

decompiled_code:
int coStopServer()
{
char *v0; // rbp

v0 = coSocketPath;
unlink(coSocketPath);
free(v0);
free(coClientTable);
return close(coServerSockfd);
}

canonical_decompiled_code:
int func7()
{
char *v0; // rbp

v0 = coSocketPath;
unlink(coSocketPath);
free(v0);
free(coClientTable);
return close(coServerSockfd);
}

original_code:
void coStopServer(void)
{
    unlink(coSocketPath);
    free(coSocketPath);
    free(coClientTable);
    close(coServerSockfd);
}

canonical_original_code:
void coStopServer()
{
    unlink(coSocketPath);
    free(coSocketPath);
    free(coClientTable);
    close(coServerSockfd);
}


coStartResponse

decompiled_code:
const char *coStartResponse()
{
_QWORD *i; // rax
int v1; // esi
int **v2; // rax
int **v3; // rdx
int **v4; // r8
int *v5; // rax
int v6; // ecx
int v7; // eax
__int64 v8; // rdi
__int64 v9; // r8
__int64 v10; // r9
__int64 v11; // rsi
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // rdx
const char *result; // rax
struct timeval v16; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

if ( !coServerStarted )
return "sessionID";
for ( i = (_QWORD *)firstReadyClient; !firstReadyClient; i = (_QWORD *)firstReadyClient )
{
v1 = coServerSockfd;
memset(&readfds, 0, sizeof(readfds));
if ( (_DWORD)coClientTableSize )
{
v2 = (int **)coClientTable;
v3 = (int **)((char *)coClientTable + 8);
v4 = (int **)((char *)coClientTable + 8 * (unsigned int)(coClientTableSize - 1) + 8);
while ( 1 )
{
v5 = *v2;
if ( v5 )
{
v6 = *v5;
v7 = *v5 + 63;
if ( v1 < v6 )
v1 = v6;
if ( v6 >= 0 )
v7 = v6;
readfds.fds_bits[v7 >> 6] |= 1LL << (v6 % 64);
}
v2 = v3;
if ( v3 == v4 )
break;
++v3;
}
}
v16.tv_sec = 2LL;
v16.tv_usec = 0LL;
v8 = (unsigned int)(v1 + 1);
readfds.fds_bits[coServerSockfd / 64] |= 1LL << (coServerSockfd % 64);
if ( select(v8, &readfds, 0LL, 0LL, &v16) < 0 )
{
perror("Select error");
exit(1);
}
v11 = (unsigned int)(coServerSockfd >> 31) >> 26;
v12 = coServerSockfd / 64;
v13 = (unsigned int)(coServerSockfd % 64);
if ( (readfds.fds_bits[v12] & (1LL << (coServerSockfd % 64))) != 0 )
acceptNewClient();
readMessage(v8, v11, v12, v13, v9, v10, readfds.fds_bits[0]);
}
v14 = i[5];
coCurrentClient = i;
result = (const char *)i[4];
firstReadyClient = v14;
return result;
}

canonical_decompiled_code:
const char *func8()
{
_QWORD *i; // rax
int v1; // esi
int **v2; // rax
int **v3; // rdx
int **v4; // r8
int *v5; // rax
int v6; // ecx
int v7; // eax
__int64 v8; // rdi
__int64 v9; // r8
__int64 v10; // r9
__int64 v11; // rsi
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // rdx
const char *result; // rax
struct timeval v16; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

if ( !coServerStarted )
return "sessionID";
for ( i = (_QWORD *)firstReadyClient; !firstReadyClient; i = (_QWORD *)firstReadyClient )
{
v1 = coServerSockfd;
memset(&readfds, 0, sizeof(readfds));
if ( (_DWORD)coClientTableSize )
{
v2 = (int **)coClientTable;
v3 = (int **)((char *)coClientTable + 8);
v4 = (int **)((char *)coClientTable + 8 * (unsigned int)(coClientTableSize - 1) + 8);
while ( 1 )
{
v5 = *v2;
if ( v5 )
{
v6 = *v5;
v7 = *v5 + 63;
if ( v1 < v6 )
v1 = v6;
if ( v6 >= 0 )
v7 = v6;
readfds.fds_bits[v7 >> 6] |= 1LL << (v6 % 64);
}
v2 = v3;
if ( v3 == v4 )
break;
++v3;
}
}
v16.tv_sec = 2LL;
v16.tv_usec = 0LL;
v8 = (unsigned int)(v1 + 1);
readfds.fds_bits[coServerSockfd / 64] |= 1LL << (coServerSockfd % 64);
if ( select(v8, &readfds, 0LL, 0LL, &v16) < 0 )
{
perror("Select error");
exit(1);
}
v11 = (unsigned int)(coServerSockfd >> 31) >> 26;
v12 = coServerSockfd / 64;
v13 = (unsigned int)(coServerSockfd % 64);
if ( (readfds.fds_bits[v12] & (1LL << (coServerSockfd % 64))) != 0 )
func2();
func3(v8, v11, v12, v13, v9, v10, readfds.fds_bits[0]);
}
v14 = i[5];
coCurrentClient = i;
result = (const char *)i[4];
firstReadyClient = v14;
return result;
}

original_code:
char *coStartResponse(void)
{
    coClient client;
    fd_set readSockets;
    struct timeval tv;
    int maxSocket;
    int numActiveSockets;
    int xClient;
    if(!coServerStarted) {
        return "sessionID";
    }
    while(firstReadyClient == ((void *)0)) {
        maxSocket = coServerSockfd;
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readSockets)->__fds_bits)[0]) : "memory"); } while (0);
        for(xClient = 0; xClient < coClientTableSize; xClient++) {
            client = coClientTable[xClient];
            if(client != ((void *)0)) {
                if(client->sockfd > maxSocket) {
                    maxSocket = client->sockfd;
                }
                ((void) (((&readSockets)->__fds_bits)[((client->sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((client->sockfd) % (8 * (int) sizeof (__fd_mask)))))));
            }
        }
        ((void) (((&readSockets)->__fds_bits)[((coServerSockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((coServerSockfd) % (8 * (int) sizeof (__fd_mask)))))));
        tv.tv_sec = 2;
        tv.tv_usec = 0;
        numActiveSockets = select(maxSocket + 1, &readSockets, ((void *)0), ((void *)0), &tv);
        if(numActiveSockets < 0) {
            perror("Select error");
            exit(1);
        }
        if(((((&readSockets)->__fds_bits)[((coServerSockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((coServerSockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            acceptNewClient();
        }
        readMessage(readSockets);
    }
    coCurrentClient = firstReadyClient;
    firstReadyClient = firstReadyClient->nextReadyClient;
    return coCurrentClient->sessionID;
}

canonical_original_code:
char *coStartResponse()
{
    struct coClientStruct *client;
    struct fd_set readSockets;
    struct timeval tv;
    int maxSocket;
    int numActiveSockets;
    int xClient;
    if(!coServerStarted) {
        return "sessionID";
    }
    while(firstReadyClient == ((void *)0)) {
        maxSocket = coServerSockfd;
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readSockets)->__fds_bits)[0]) : "memory"); } while (0);
        for(xClient = 0; xClient < coClientTableSize; xClient++) {
            client = coClientTable[xClient];
            if(client != ((void *)0)) {
                if(client->sockfd > maxSocket) {
                    maxSocket = client->sockfd;
                }
                ((void) (((&readSockets)->__fds_bits)[((client->sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((client->sockfd) % (8 * (int) sizeof (__fd_mask)))))));
            }
        }
        ((void) (((&readSockets)->__fds_bits)[((coServerSockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((coServerSockfd) % (8 * (int) sizeof (__fd_mask)))))));
        tv.tv_sec = 2;
        tv.tv_usec = 0;
        numActiveSockets = select(maxSocket + 1, &readSockets, ((void *)0), ((void *)0), &tv);
        if(numActiveSockets < 0) {
            perror("Select error");
            exit(1);
        }
        if(((((&readSockets)->__fds_bits)[((coServerSockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((coServerSockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            acceptNewClient();
        }
        readMessage(readSockets);
    }
    coCurrentClient = firstReadyClient;
    firstReadyClient = firstReadyClient->nextReadyClient;
    return coCurrentClient->sessionID;
}

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

variable_types: maxSocket int

variable_types: numActiveSockets int

return_type: char *


coGetc

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

if ( !coServerStarted )
return getchar();
v0 = *((unsigned int *)coCurrentClient + 6);
if ( (_DWORD)v0 == *((_DWORD *)coCurrentClient + 5) )
return -1;
v1 = *((_QWORD *)coCurrentClient + 1);
*((_DWORD *)coCurrentClient + 6) = v0 + 1;
return *(char *)(v1 + v0);
}

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

if ( !coServerStarted )
return getchar();
v0 = *((unsigned int *)coCurrentClient + 6);
if ( (_DWORD)v0 == *((_DWORD *)coCurrentClient + 5) )
return -1;
v1 = *((_QWORD *)coCurrentClient + 1);
*((_DWORD *)coCurrentClient + 6) = v0 + 1;
return *(char *)(v1 + v0);
}

original_code:
int coGetc(void)
{
    if(!coServerStarted) {
        return getchar();
    }
    if(coCurrentClient->messagePos == coCurrentClient->messageLength) {
        return (-1);
    }
    return coCurrentClient->message[(coCurrentClient->messagePos)++];
}

canonical_original_code:
int coGetc()
{
    if(!coServerStarted) {
        return getchar();
    }
    if(coCurrentClient->messagePos == coCurrentClient->messageLength) {
        return (-1);
    }
    return coCurrentClient->message[(coCurrentClient->messagePos)++];
}


coPrintf

decompiled_code:
__int64 coPrintf(char *format, ...)
{
unsigned int v1; // er12
gcc_va_list arg; // [rsp+8h] [rbp-10D0h] BYREF
__int64 s[512]; // [rsp+20h] [rbp-10B8h] BYREF

va_start(arg, format);
v1 = vsnprintf((char *)s, 0x1000uLL, format, arg);
if ( coServerStarted )
writeBufferedBytes(s, v1);
else
printf("%s", (const char *)s);
return v1;
}

canonical_decompiled_code:
__int64 func10(char *format, ...)
{
unsigned int v1; // er12
gcc_va_list arg; // [rsp+8h] [rbp-10D0h] BYREF
__int64 s[512]; // [rsp+20h] [rbp-10B8h] BYREF

va_start(arg, format);
v1 = vsnprintf((char *)s, 0x1000uLL, format, arg);
if ( coServerStarted )
func5(s, v1);
else
printf("%s", (const char *)s);
return v1;
}

original_code:
int coPrintf(
    char *format,
    ...)
{
    va_list ap;
    char buffer[4096];
    int length;
    __builtin_va_start(ap,format);
    length = vsnprintf(buffer, 4096, format, ap);
    __builtin_va_end(ap);
    if(coServerStarted) {
 writeBufferedBytes(buffer, length);
    } else {
        printf("%s", buffer);
    }
    return length;
}

canonical_original_code:
int coPrintf(char *format, ...)
{
    __builtin_va_list ap;
    char buffer[4096];
    int length;
    __builtin_va_start(ap,format);
    length = vsnprintf(buffer, 4096, format, ap);
    __builtin_va_end(ap);
    if(coServerStarted) {
 writeBufferedBytes(buffer, length);
    } else {
        printf("%s", buffer);
    }
    return length;
}

variable_types:
format
char *

variable_types:
buffer
char [4096]


coCompleteResponse

decompiled_code:
unsigned __int64 coCompleteResponse()
{
unsigned __int64 result; // rax

result = (unsigned int)coServerStarted;
if ( coServerStarted )
{
writeBufferedBytes((__int64 *)&unk_19D6, 1);
flushBuffer();
fsync(*(_DWORD *)coCurrentClient);
result = (unsigned __int64)coCurrentClient;
coCurrentClient = 0LL;
*(_QWORD *)(result + 20) = 0LL;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 func11()
{
unsigned __int64 result; // rax

result = (unsigned int)coServerStarted;
if ( coServerStarted )
{
func5((__int64 *)&unk_19D6, 1);
func4();
fsync(*(_DWORD *)coCurrentClient);
result = (unsigned __int64)coCurrentClient;
coCurrentClient = 0LL;
*(_QWORD *)(result + 20) = 0LL;
}
return result;
}

original_code:
void coCompleteResponse(void)
{
    if(coServerStarted) {
        writeBufferedBytes("", 1);
 flushBuffer();
        fsync(coCurrentClient->sockfd);
        coCurrentClient->messageLength = 0;
        coCurrentClient->messagePos = 0;
        coCurrentClient = ((void *)0);
    }
}

canonical_original_code:
void coCompleteResponse()
{
    if(coServerStarted) {
        writeBufferedBytes("", 1);
 flushBuffer();
        fsync(coCurrentClient->sockfd);
        coCurrentClient->messageLength = 0;
        coCurrentClient->messagePos = 0;
        coCurrentClient = ((void *)0);
    }
}


readChar

decompiled_code:
__int64 readChar()
{
__int64 v0; // rax
int v1; // edx
__int64 result; // rax
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

*(_DWORD *)&fds.events = 1;
fds.fd = coSockfd;
v0 = coBufferNextCharPos;
if ( coBufferNextCharPos >= coBufferLength )
{
poll(&fds, 1uLL, -1);
coBufferNextCharPos = 0;
coBufferLength = read(coSockfd, coBuffer, 0x1000uLL);
if ( coBufferLength <= 0 )
{
perror("Cannot read from server");
exit(1);
}
v0 = coBufferNextCharPos;
}
v1 = v0 + 1;
result = (unsigned __int8)coBuffer[v0];
coBufferNextCharPos = v1;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
int v1; // edx
__int64 result; // rax
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

*(_DWORD *)&fds.events = 1;
fds.fd = coSockfd;
v0 = coBufferNextCharPos;
if ( coBufferNextCharPos >= coBufferLength )
{
poll(&fds, 1uLL, -1);
coBufferNextCharPos = 0;
coBufferLength = read(coSockfd, coBuffer, 0x1000uLL);
if ( coBufferLength <= 0 )
{
perror("Cannot read from server");
exit(1);
}
v0 = coBufferNextCharPos;
}
v1 = v0 + 1;
result = (unsigned __int8)coBuffer[v0];
coBufferNextCharPos = v1;
return result;
}

original_code:
static char readChar(void)
{
    struct pollfd pstruct = {coSockfd, 0x001, 0};
    if(coBufferNextCharPos < coBufferLength) {
 return coBuffer[coBufferNextCharPos++];
    }
    poll(&pstruct, 1, -1);
    coBufferNextCharPos = 0;
    coBufferLength = read(coSockfd, coBuffer, 4096);
    if(coBufferLength <= 0) {
 perror("Cannot read from server");
 exit(1);
    }
    return coBuffer[coBufferNextCharPos++];
}

canonical_original_code:
static char readChar()
{
    struct pollfd pstruct = {coSockfd, 0x001, 0};
    if(coBufferNextCharPos < coBufferLength) {
 return coBuffer[coBufferNextCharPos++];
    }
    poll(&pstruct, 1, -1);
    coBufferNextCharPos = 0;
    coBufferLength = read(coSockfd, coBuffer, 4096);
    if(coBufferLength <= 0) {
 perror("Cannot read from server");
 exit(1);
    }
    return coBuffer[coBufferNextCharPos++];
}

variable_types: struct pollfd { int fd; short events; short revents; }

return_type: char


coStopClient

decompiled_code:
int coStopClient()
{
return close(coSockfd);
}

canonical_decompiled_code:
int func1()
{
return close(coSockfd);
}

original_code:
void coStopClient(void)
{
    close(coSockfd);
}

canonical_original_code:
void coStopClient()
{
    close(coSockfd);
}


coSendMessage

decompiled_code:
int coSendMessage(char *format, ...)
{
int v1; // eax
gcc_va_list arg; // [rsp+8h] [rbp-10D0h] BYREF
char s[4096]; // [rsp+20h] [rbp-10B8h] BYREF

va_start(arg, format);
v1 = vsnprintf(s, 0x1000uLL, format, arg);
write(coSockfd, s, v1 + 1);
return fsync(coSockfd);
}

canonical_decompiled_code:
int func2(char *format, ...)
{
int v1; // eax
gcc_va_list arg; // [rsp+8h] [rbp-10D0h] BYREF
char s[4096]; // [rsp+20h] [rbp-10B8h] BYREF

va_start(arg, format);
v1 = vsnprintf(s, 0x1000uLL, format, arg);
write(coSockfd, s, v1 + 1);
return fsync(coSockfd);
}

original_code:
void coSendMessage(
    char *format,
    ...)
{
    va_list ap;
    char buffer[4096];
    int length;
    __builtin_va_start(ap,format);
    length = vsnprintf(buffer, 4096, format, ap);
    __builtin_va_end(ap);
    length = write(coSockfd, buffer, length + 1);
    fsync(coSockfd);
}

canonical_original_code:
void coSendMessage(char *format, ...)
{
    __builtin_va_list ap;
    char buffer[4096];
    int length;
    __builtin_va_start(ap,format);
    length = vsnprintf(buffer, 4096, format, ap);
    __builtin_va_end(ap);
    length = write(coSockfd, buffer, length + 1);
    fsync(coSockfd);
}


coReadMessage

decompiled_code:
_BYTE *coReadMessage()
{
__int64 v0; // rbp
_BYTE *result; // rax
char v2; // al
int v3; // esi
char v4; // bl

v0 = 0LL;
do
{
while ( 1 )
{
v2 = readChar();
v3 = coMessageSize;
v4 = v2;
if ( coMessageSize == (_DWORD)v0 + 1 )
break;
result = coMessage;
*((_BYTE *)coMessage + v0++) = v4;
if ( !v4 )
return result;
}
coMessageSize *= 2;
result = realloc(coMessage, 2 * v3);
result[v0++] = v4;
coMessage = result;
}
while ( v4 );
return result;
}

canonical_decompiled_code:
_BYTE *func3()
{
__int64 v0; // rbp
_BYTE *result; // rax
char v2; // al
int v3; // esi
char v4; // bl

v0 = 0LL;
do
{
while ( 1 )
{
v2 = func0();
v3 = coMessageSize;
v4 = v2;
if ( coMessageSize == (_DWORD)v0 + 1 )
break;
result = coMessage;
*((_BYTE *)coMessage + v0++) = v4;
if ( !v4 )
return result;
}
coMessageSize *= 2;
result = realloc(coMessage, 2 * v3);
result[v0++] = v4;
coMessage = result;
}
while ( v4 );
return result;
}

original_code:
char *coReadMessage(void)
{
    char c;
    int messagePos = 0;
    do {
 c = readChar();
        if(messagePos + 1 == coMessageSize) {
            coMessageSize <<= 1;
            coMessage = (char *)realloc(coMessage, coMessageSize*sizeof(char));
        }
        coMessage[messagePos++] = c;
    } while(c != '\0');
    return coMessage;
}

canonical_original_code:
char *coReadMessage()
{
    char c;
    int messagePos = 0;
    do {
 c = readChar();
        if(messagePos + 1 == coMessageSize) {
            coMessageSize <<= 1;
            coMessage = (char *)realloc(coMessage, coMessageSize*sizeof(char));
        }
        coMessage[messagePos++] = c;
    } while(c != '\0');
    return coMessage;
}

variable_types: c char

variable_types: messagePos int


usage

repo: waywardgeek/sonic

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"Usage: sonic [OPTION]... infile outfile\n"
" -c -- Modify pitch by emulating vocal chords vibrating\n"
" faster or slower.\n"
" -o -- Override the sample rate of the output. -o 44200\n"
" on an input file at 22100 KHz will play twice as fast\n"
" and have twice the pitch.\n"
" -p pitch -- Set pitch scaling factor. 1.3 means 30%% higher.\n"
" -q -- Disable speed-up heuristics. May increase quality.\n"
" -r rate -- Set playback rate. 2.0 means 2X faster, and 2X pitch.\n"
" -s speed -- Set speed up factor. 2.0 means 2X faster.\n"
" -v volume -- Scale volume by a constant factor.\n");
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fprintf(
stderr,
"Usage: sonic [OPTION]... infile outfile\n"
" -c -- Modify pitch by emulating vocal chords vibrating\n"
" faster or slower.\n"
" -o -- Override the sample rate of the output. -o 44200\n"
" on an input file at 22100 KHz will play twice as fast\n"
" and have twice the pitch.\n"
" -p pitch -- Set pitch scaling factor. 1.3 means 30%% higher.\n"
" -q -- Disable speed-up heuristics. May increase quality.\n"
" -r rate -- Set playback rate. 2.0 means 2X faster, and 2X pitch.\n"
" -s speed -- Set speed up factor. 2.0 means 2X faster.\n"
" -v volume -- Scale volume by a constant factor.\n");
exit(1);
}

original_code:
static void usage(void) {
  fprintf(
      stderr,
      "Usage: sonic [OPTION]... infile outfile\n"
      "    -c         -- Modify pitch by emulating vocal chords vibrating\n"
      "                  faster or slower.\n"
      "    -o         -- Override the sample rate of the output.  -o 44200\n"
      "                  on an input file at 22100 KHz will play twice as fast\n"
      "                  and have twice the pitch.\n"
      "    -p pitch   -- Set pitch scaling factor.  1.3 means 30%% higher.\n"
      "    -q         -- Disable speed-up heuristics.  May increase quality.\n"
      "    -r rate    -- Set playback rate.  2.0 means 2X faster, and 2X "
      "pitch.\n"
      "    -s speed   -- Set speed up factor.  2.0 means 2X faster.\n"
      "    -v volume  -- Scale volume by a constant factor.\n");
  exit(1);
}

canonical_original_code:
static void usage() {
  fprintf(
      stderr,
      "Usage: sonic [OPTION]... infile outfile\n"
      "    -c         -- Modify pitch by emulating vocal chords vibrating\n"
      "                  faster or slower.\n"
      "    -o         -- Override the sample rate of the output.  -o 44200\n"
      "                  on an input file at 22100 KHz will play twice as fast\n"
      "                  and have twice the pitch.\n"
      "    -p pitch   -- Set pitch scaling factor.  1.3 means 30%% higher.\n"
      "    -q         -- Disable speed-up heuristics.  May increase quality.\n"
      "    -r rate    -- Set playback rate.  2.0 means 2X faster, and 2X "
      "pitch.\n"
      "    -s speed   -- Set speed up factor.  2.0 means 2X faster.\n"
      "    -v volume  -- Scale volume by a constant factor.\n");
  exit(1);
}


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r15
int v4; // er14
unsigned int v5; // er13
unsigned int v6; // er12
int v7; // ebp
int v8; // ebx
int v9; // eax
float v10; // xmm1_4
float v11; // xmm7_4
float v13; // xmm5_4
float v14; // xmm6_4
float v15; // [rsp+4h] [rbp-54h]
float v16; // [rsp+8h] [rbp-50h]
unsigned int v17; // [rsp+Ch] [rbp-4Ch]
float v18; // [rsp+10h] [rbp-48h]
float v19; // [rsp+14h] [rbp-44h]

v3 = argv;
v4 = argc;
v5 = 0;
v6 = 0;
v7 = 1;
v17 = 0;
if ( argc > 1 )
{
v19 = *(float *)&LC3;
v15 = *(float *)&LC3;
v16 = *(float *)&LC3;
v18 = *(float *)&LC3;
while ( 1 )
{
*(_QWORD *)&argc = v3[v7];
envp = (const char **)(8LL * v7);
if ( **(_BYTE **)&argc != 45 )
goto LABEL_23;
v9 = *(unsigned __int8 *)(*(_QWORD *)&argc + 1LL);
if ( v9 == 99 && !*(_BYTE *)(*(_QWORD *)&argc + 2LL) )
break;
argv = (const char **)(unsigned __int8)**(_BYTE **)&argc;
v8 = v7 + 1;
if ( (_DWORD)argv != 45 )
goto LABEL_9;
if ( v9 != 111 || *(_BYTE *)(*(_QWORD *)&argc + 2LL) )
{
if ( v9 == 112 && !*(_BYTE *)(*(_QWORD *)&argc + 2LL) )
{
if ( v8 < v4 )
{
*(_QWORD *)&argc = "Setting pitch to %0.2fX\n";
v13 = atof(*(const char **)((char *)envp + (_QWORD)v3 + 8));
v16 = v13;
printf("Setting pitch to %0.2fX\n", v13);
}
goto LABEL_5;
}
if ( v9 != 113 || *(_BYTE *)(*(_QWORD *)&argc + 2LL) )
{
if ( v9 != 114 || *(_BYTE *)(*(_QWORD *)&argc + 2LL) )
{
if ( v9 == 115 && !*(_BYTE *)(*(_QWORD *)&argc + 2LL) )
{
if ( v8 < v4 )
{
*(_QWORD *)&argc = "Setting speed to %0.2fX\n";
v11 = atof(*(const char **)((char *)envp + (_QWORD)v3 + 8));
v18 = v11;
printf("Setting speed to %0.2fX\n", v11);
}
goto LABEL_5;
}
LABEL_9:
argv = (const char **)"-v";
if ( !strcmp(*(const char **)&argc, "-v") )
{
envp = (const char **)(8LL * v7);
if ( v8 < v4 )
{
*(_QWORD *)&argc = "Setting volume to %0.2f\n";
v10 = atof(v3[v7 + 1]);
v19 = v10;
printf("Setting volume to %0.2f\n", v10);
}
}
else
{
v8 = v7;
}
goto LABEL_5;
}
if ( v8 < v4 )
{
*(_QWORD *)&argc = *(const char **)((char *)envp + (_QWORD)v3 + 8);
v14 = atof(*(const char **)&argc);
v15 = v14;
if ( v14 == 0.0 )
goto LABEL_37;
*(_QWORD *)&argc = "Setting rate to %0.2fX\n";
printf("Setting rate to %0.2fX\n", v14);
}
}
else
{
*(_QWORD *)&argc = "Disabling speed-up heuristics";
v8 = v7;
puts("Disabling speed-up heuristics");
v17 = 1;
}
LABEL_5:
v7 = v8 + 1;
if ( v4 <= v8 + 1 )
goto LABEL_23;
}
else
{
if ( v8 >= v4 )
goto LABEL_5;
v7 += 2;
*(_QWORD *)&argc = "Setting output sample rate to %d\n";
argv = (const char **)(unsigned int)atoi(*(const char **)((char *)envp + (_QWORD)v3 + 8));
v6 = (unsigned int)argv;
printf("Setting output sample rate to %d\n", argv);
if ( v4 <= v7 )
goto LABEL_23;
}
}
*(_QWORD *)&argc = "Scaling pitch linearly.";
v8 = v7;
v5 = 1;
puts("Scaling pitch linearly.");
goto LABEL_5;
}
v19 = *(float *)&LC3;
v15 = *(float *)&LC3;
v16 = *(float *)&LC3;
v18 = *(float *)&LC3;
LABEL_23:
if ( v4 - v7 != 2 )
LABEL_37:
usage(*(_QWORD *)&argc, argv, envp);
runSonic_constprop_0((__int64)v3[v7], (__int64)v3[v7 + 1], v6, v5, v17, v18, v16, v15, v19);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r15
int v4; // er14
unsigned int v5; // er13
unsigned int v6; // er12
int v7; // ebp
int v8; // ebx
int v9; // eax
float v10; // xmm1_4
float v11; // xmm7_4
float v13; // xmm5_4
float v14; // xmm6_4
float v15; // [rsp+4h] [rbp-54h]
float v16; // [rsp+8h] [rbp-50h]
unsigned int v17; // [rsp+Ch] [rbp-4Ch]
float v18; // [rsp+10h] [rbp-48h]
float v19; // [rsp+14h] [rbp-44h]

v3 = argv;
v4 = argc;
v5 = 0;
v6 = 0;
v7 = 1;
v17 = 0;
if ( argc > 1 )
{
v19 = *(float *)&LC3;
v15 = *(float *)&LC3;
v16 = *(float *)&LC3;
v18 = *(float *)&LC3;
while ( 1 )
{
*(_QWORD *)&argc = v3[v7];
envp = (const char **)(8LL * v7);
if ( **(_BYTE **)&argc != 45 )
goto LABEL_23;
v9 = *(unsigned __int8 *)(*(_QWORD *)&argc + 1LL);
if ( v9 == 99 && !*(_BYTE *)(*(_QWORD *)&argc + 2LL) )
break;
argv = (const char **)(unsigned __int8)**(_BYTE **)&argc;
v8 = v7 + 1;
if ( (_DWORD)argv != 45 )
goto LABEL_9;
if ( v9 != 111 || *(_BYTE *)(*(_QWORD *)&argc + 2LL) )
{
if ( v9 == 112 && !*(_BYTE *)(*(_QWORD *)&argc + 2LL) )
{
if ( v8 < v4 )
{
*(_QWORD *)&argc = "Setting pitch to %0.2fX\n";
v13 = atof(*(const char **)((char *)envp + (_QWORD)v3 + 8));
v16 = v13;
printf("Setting pitch to %0.2fX\n", v13);
}
goto LABEL_5;
}
if ( v9 != 113 || *(_BYTE *)(*(_QWORD *)&argc + 2LL) )
{
if ( v9 != 114 || *(_BYTE *)(*(_QWORD *)&argc + 2LL) )
{
if ( v9 == 115 && !*(_BYTE *)(*(_QWORD *)&argc + 2LL) )
{
if ( v8 < v4 )
{
*(_QWORD *)&argc = "Setting speed to %0.2fX\n";
v11 = atof(*(const char **)((char *)envp + (_QWORD)v3 + 8));
v18 = v11;
printf("Setting speed to %0.2fX\n", v11);
}
goto LABEL_5;
}
LABEL_9:
argv = (const char **)"-v";
if ( !strcmp(*(const char **)&argc, "-v") )
{
envp = (const char **)(8LL * v7);
if ( v8 < v4 )
{
*(_QWORD *)&argc = "Setting volume to %0.2f\n";
v10 = atof(v3[v7 + 1]);
v19 = v10;
printf("Setting volume to %0.2f\n", v10);
}
}
else
{
v8 = v7;
}
goto LABEL_5;
}
if ( v8 < v4 )
{
*(_QWORD *)&argc = *(const char **)((char *)envp + (_QWORD)v3 + 8);
v14 = atof(*(const char **)&argc);
v15 = v14;
if ( v14 == 0.0 )
goto LABEL_37;
*(_QWORD *)&argc = "Setting rate to %0.2fX\n";
printf("Setting rate to %0.2fX\n", v14);
}
}
else
{
*(_QWORD *)&argc = "Disabling speed-up heuristics";
v8 = v7;
puts("Disabling speed-up heuristics");
v17 = 1;
}
LABEL_5:
v7 = v8 + 1;
if ( v4 <= v8 + 1 )
goto LABEL_23;
}
else
{
if ( v8 >= v4 )
goto LABEL_5;
v7 += 2;
*(_QWORD *)&argc = "Setting output sample rate to %d\n";
argv = (const char **)(unsigned int)atoi(*(const char **)((char *)envp + (_QWORD)v3 + 8));
v6 = (unsigned int)argv;
printf("Setting output sample rate to %d\n", argv);
if ( v4 <= v7 )
goto LABEL_23;
}
}
*(_QWORD *)&argc = "Scaling pitch linearly.";
v8 = v7;
v5 = 1;
puts("Scaling pitch linearly.");
goto LABEL_5;
}
v19 = *(float *)&LC3;
v15 = *(float *)&LC3;
v16 = *(float *)&LC3;
v18 = *(float *)&LC3;
LABEL_23:
if ( v4 - v7 != 2 )
LABEL_37:
func0(*(_QWORD *)&argc, argv, envp);
func1((__int64)v3[v7], (__int64)v3[v7 + 1], v6, v5, v17, v18, v16, v15, v19);
return 0;
}

original_code:
int main(int argc, char** argv) {
  char* inFileName;
  char* outFileName;
  float speed = 1.0f;
  float pitch = 1.0f;
  float rate = 1.0f;
  float volume = 1.0f;
  int outputSampleRate = 0;
  int emulateChordPitch = 0;
  int quality = 0;
  int xArg = 1;
  int computeSpectrogram = 0;
  int numRows = 0, numCols = 0;
  while (xArg < argc && *(argv[xArg]) == '-') {
    if (!strcmp(argv[xArg], "-c")) {
      emulateChordPitch = 1;
      printf("Scaling pitch linearly.\n");
    } else if (!strcmp(argv[xArg], "-o")) {
      xArg++;
      if (xArg < argc) {
        outputSampleRate = atoi(argv[xArg]);
        printf("Setting output sample rate to %d\n", outputSampleRate);
      }
    } else if (!strcmp(argv[xArg], "-p")) {
      xArg++;
      if (xArg < argc) {
        pitch = atof(argv[xArg]);
        printf("Setting pitch to %0.2fX\n", pitch);
      }
    } else if (!strcmp(argv[xArg], "-q")) {
      quality = 1;
      printf("Disabling speed-up heuristics\n");
    } else if (!strcmp(argv[xArg], "-r")) {
      xArg++;
      if (xArg < argc) {
        rate = atof(argv[xArg]);
        if (rate == 0.0f) {
          usage();
        }
        printf("Setting rate to %0.2fX\n", rate);
      }
    } else if (!strcmp(argv[xArg], "-s")) {
      xArg++;
      if (xArg < argc) {
        speed = atof(argv[xArg]);
        printf("Setting speed to %0.2fX\n", speed);
      }
    } else if (!strcmp(argv[xArg], "-v")) {
      xArg++;
      if (xArg < argc) {
        volume = atof(argv[xArg]);
        printf("Setting volume to %0.2f\n", volume);
      }
    }
    xArg++;
  }
  if (argc - xArg != 2) {
    usage();
  }
  inFileName = argv[xArg];
  outFileName = argv[xArg + 1];
  runSonic(inFileName, outFileName, speed, pitch, rate, volume,
           outputSampleRate, emulateChordPitch, quality,
           computeSpectrogram, numRows, numCols);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  char *inFileName;
  char *outFileName;
  float speed = 1.0f;
  float pitch = 1.0f;
  float rate = 1.0f;
  float volume = 1.0f;
  int outputSampleRate = 0;
  int emulateChordPitch = 0;
  int quality = 0;
  int xArg = 1;
  int computeSpectrogram = 0;
  int numRows = 0; int numCols = 0;
  while (xArg < argc && *(argv[xArg]) == '-') {
    if (!strcmp(argv[xArg], "-c")) {
      emulateChordPitch = 1;
      printf("Scaling pitch linearly.\n");
    } else if (!strcmp(argv[xArg], "-o")) {
      xArg++;
      if (xArg < argc) {
        outputSampleRate = atoi(argv[xArg]);
        printf("Setting output sample rate to %d\n", outputSampleRate);
      }
    } else if (!strcmp(argv[xArg], "-p")) {
      xArg++;
      if (xArg < argc) {
        pitch = atof(argv[xArg]);
        printf("Setting pitch to %0.2fX\n", pitch);
      }
    } else if (!strcmp(argv[xArg], "-q")) {
      quality = 1;
      printf("Disabling speed-up heuristics\n");
    } else if (!strcmp(argv[xArg], "-r")) {
      xArg++;
      if (xArg < argc) {
        rate = atof(argv[xArg]);
        if (rate == 0.0f) {
          usage();
        }
        printf("Setting rate to %0.2fX\n", rate);
      }
    } else if (!strcmp(argv[xArg], "-s")) {
      xArg++;
      if (xArg < argc) {
        speed = atof(argv[xArg]);
        printf("Setting speed to %0.2fX\n", speed);
      }
    } else if (!strcmp(argv[xArg], "-v")) {
      xArg++;
      if (xArg < argc) {
        volume = atof(argv[xArg]);
        printf("Setting volume to %0.2f\n", volume);
      }
    }
    xArg++;
  }
  if (argc - xArg != 2) {
    usage();
  }
  inFileName = argv[xArg];
  outFileName = argv[xArg + 1];
  runSonic(inFileName, outFileName, speed, pitch, rate, volume,
           outputSampleRate, emulateChordPitch, quality,
           computeSpectrogram, numRows, numCols);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
inFileName
char *

variable_types:
outFileName
char *

variable_types: speed float

variable_types: pitch float

variable_types: rate float

variable_types: volume float

variable_types: outputSampleRate int

variable_types: emulateChordPitch int

variable_types: quality int

variable_types: xArg int

variable_types: computeSpectrogram int

variable_types: numRows int

variable_types: numCols int


cmp

repo: wazedix/algorithms

decompiled_code:
__int64 __fastcall cmp(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a1 + 2) - *((_DWORD *)a2 + 2));
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a1 + 2) - *((_DWORD *)a2 + 2));
}

original_code:
int cmp(const void *x, const void *y)
{
    return (*(Edge *)x).value - (*(Edge *)y).value;
}

canonical_original_code:
int cmp(void *x, void *y)
{
    return (*(struct Edge *)x).value - (*(struct Edge *)y).value;
}

variable_types:
x
void *

variable_types:
y
void *

user_defined_types: struct Edge { int x; int y; int value; }


decompiled_code:
__int64 __fastcall get_father(int a1)
{
__int64 v1; // rbx
__int64 v2; // rdi
__int64 result; // rax

v1 = a1;
v2 = (unsigned int)father[a1];
result = v1;
if ( (_DWORD)v2 != (_DWORD)v1 )
{
result = get_father(v2);
father[v1] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 v1; // rbx
__int64 v2; // rdi
__int64 result; // rax

v1 = a1;
v2 = (unsigned int)father[a1];
result = v1;
if ( (_DWORD)v2 != (_DWORD)v1 )
{
result = func8(v2);
father[v1] = result;
}
return result;
}

original_code:
int get_father(int x)
{
    if (father[x] != x)
        father[x] = get_father(father[x]);
    return father[x];
}

variable_types: x int


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

get_father(a1);
result = get_father(a2);
if ( (_DWORD)v3 != (_DWORD)result )
father[v3] = result;
return result;
}

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

func8(a1);
result = func8(a2);
if ( (_DWORD)v3 != (_DWORD)result )
father[v3] = result;
return result;
}

original_code:
void set_union(int x, int y)
{
    x = get_father(x);
    y = get_father(y);
    if (x != y)
        father[x] = y;
}

variable_types: y int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
int i; // er12
int v5; // ebx
int *v6; // rbp
int v7; // edx
__int64 v8; // rcx
__int64 v9; // rcx
int v10; // eax
__int64 v11; // rdx
__int64 v12; // rcx
int v13; // er8
__int64 v14; // r9
int v16; // [rsp+8h] [rbp-30h]
int v17; // [rsp+Ch] [rbp-2Ch]

__isoc99_scanf();
if ( v16 <= 0 )
{
qsort(edge, 0LL, 0xCuLL, cmp);
}
else
{
v3 = 1LL;
for ( i = 0; ; i = v7 )
{
father[v3] = v3;
v5 = 1;
v6 = &edge[3 * i];
do
{
v6 += 3;
__isoc99_scanf();
*(v6 - 2) = v5;
v7 = i + v5++;
*(v6 - 3) = v3;
*(v6 - 1) = v17;
}
while ( v16 >= v5 );
if ( v16 < (int)++v3 )
break;
}
qsort(edge, v7, 0xCuLL, cmp);
v8 = 0LL;
do
{
get_father(*(unsigned int *)((char *)edge + v8));
v10 = get_father(*(unsigned int *)((char *)&dword_4049C4 + v9));
if ( (_DWORD)v11 != v10 )
set_union(
*(unsigned int *)((char *)edge + v12),
*(unsigned int *)((char *)&dword_4049C4 + v12),
v11,
v12,
(unsigned int)(v13 + 1));
if ( v16 - 1 <= v13 )
break;
v8 = v12 + 12;
}
while ( v14 != v8 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
int i; // er12
int v5; // ebx
int *v6; // rbp
int v7; // edx
__int64 v8; // rcx
__int64 v9; // rcx
int v10; // eax
__int64 v11; // rdx
__int64 v12; // rcx
int v13; // er8
__int64 v14; // r9
int v16; // [rsp+8h] [rbp-30h]
int v17; // [rsp+Ch] [rbp-2Ch]

__isoc99_scanf();
if ( v16 <= 0 )
{
qsort(edge, 0LL, 0xCuLL, cmp);
}
else
{
v3 = 1LL;
for ( i = 0; ; i = v7 )
{
father[v3] = v3;
v5 = 1;
v6 = &edge[3 * i];
do
{
v6 += 3;
__isoc99_scanf();
*(v6 - 2) = v5;
v7 = i + v5++;
*(v6 - 3) = v3;
*(v6 - 1) = v17;
}
while ( v16 >= v5 );
if ( v16 < (int)++v3 )
break;
}
qsort(edge, v7, 0xCuLL, cmp);
v8 = 0LL;
do
{
func8(*(unsigned int *)((char *)edge + v8));
v10 = func8(*(unsigned int *)((char *)&dword_4049C4 + v9));
if ( (_DWORD)v11 != v10 )
func9(
*(unsigned int *)((char *)edge + v12),
*(unsigned int *)((char *)&dword_4049C4 + v12),
v11,
v12,
(unsigned int)(v13 + 1));
if ( v16 - 1 <= v13 )
break;
v8 = v12 + 12;
}
while ( v14 != v8 );
}
return 0;
}

original_code:
int main(void)
{
    int n, i, j, value;
    int length = 0;
    int max = 0;
    int num_E = 0;
    scanf("%d", &n);
    for (i = 1; i <= n; i ++)
    {
        father[i] = i;
        for (j = 1; j <=n; j ++)
        {
            scanf("%d", &value);
            edge[length].x = i;
            edge[length].y = j;
            edge[length].value = value;
            length ++;
        }
    }
    qsort(edge, length, sizeof(Edge), cmp);
    for (i = 0; i < length; i ++)
    {
        if (get_father(edge[i].x) != get_father(edge[i].y))
        {
            set_union(edge[i].x, edge[i].y);
            num_E ++;
        }
        if (num_E >= n-1)
            break;
    }
    return 0;
}

canonical_original_code:
int main()
{
    int n; int i; int j; int value;
    int length = 0;
    int max = 0;
    int num_E = 0;
    scanf("%d", &n);
    for (i = 1; i <= n; i ++)
    {
        father[i] = i;
        for (j = 1; j <=n; j ++)
        {
            scanf("%d", &value);
            edge[length].x = i;
            edge[length].y = j;
            edge[length].value = value;
            length ++;
        }
    }
    qsort(edge, length, sizeof(Edge), cmp);
    for (i = 0; i < length; i ++)
    {
        if (get_father(edge[i].x) != get_father(edge[i].y))
        {
            set_union(edge[i].x, edge[i].y);
            num_E ++;
        }
        if (num_E >= n-1)
            break;
    }
    return 0;
}

variable_types: n int

variable_types: i int

variable_types: j int

variable_types: value int

variable_types: length int

variable_types: max int


sort

original_code:
void sort(int *begin, int *end, int n)
{
    int i, j, temp;
    for (i = 0; i < n; i ++)
        for (j = i+1; j < n; j ++)
            if (end[j] < end[i])
            {
                temp = end[j];
                end[j] = end[i];
                end[i] = temp;
                temp = begin[j];
                begin[j] = begin[i];
                begin[i] = temp;
            }
}

canonical_original_code:
void sort(int *begin, int *end, int n)
{
    int i; int j; int temp;
    for (i = 0; i < n; i ++)
        for (j = i+1; j < n; j ++)
            if (end[j] < end[i])
            {
                temp = end[j];
                end[j] = end[i];
                end[i] = temp;
                temp = begin[j];
                begin[j] = begin[i];
                begin[i] = temp;
            }
}

variable_types:
begin
int *

variable_types:
end
int *

variable_types: temp int


select

original_code:
void select(int *begin, int *end, int n)
{
    int index = 0;
    int ans[MAXN], length = 0;
    int last_time = 0;
    while (index < n)
    {
        if (begin[index] > last_time)
        {
            ans[length ++] = index;
            last_time = end[index];
        }
        index ++;
    }
    for (index = 0; index < length; index ++)
        printf("%d ", ans[index] + 1);
    printf("\n");
}

canonical_original_code:
void select(int *begin, int *end, int n)
{
    int index = 0;
    int ans[-1]; int length = 0;
    int last_time = 0;
    while (index < n)
    {
        if (begin[index] > last_time)
        {
            ans[length ++] = index;
            last_time = end[index];
        }
        index ++;
    }
    for (index = 0; index < length; index ++)
        printf("%d ", ans[index] + 1);
    printf("\n");
}

variable_types: index int

variable_types:
ans
int [-1]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
__int64 v4; // rbx
int v6; // [rsp+Ch] [rbp-8Ch]
char v7[48]; // [rsp+10h] [rbp-88h] BYREF
char v8[88]; // [rsp+40h] [rbp-58h] BYREF

__isoc99_scanf();
if ( v6 > 0 )
{
v3 = v7;
v4 = 0LL;
do
{
__isoc99_scanf();
++v4;
v3 += 4;
}
while ( v6 > (int)v4 );
}
sort(v7, v8);
select(v7, v8, (unsigned int)v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
__int64 v4; // rbx
int v6; // [rsp+Ch] [rbp-8Ch]
char v7[48]; // [rsp+10h] [rbp-88h] BYREF
char v8[88]; // [rsp+40h] [rbp-58h] BYREF

__isoc99_scanf();
if ( v6 > 0 )
{
v3 = v7;
v4 = 0LL;
do
{
__isoc99_scanf();
++v4;
v3 += 4;
}
while ( v6 > (int)v4 );
}
func7(v7, v8);
func8(v7, v8, (unsigned int)v6);
return 0;
}

original_code:
int main(void)
{
    int begin[MAXN], end[MAXN];
    int n, i;
    scanf("%d\n", &n);
    for (i = 0; i < n; i ++)
        scanf("%d %d\n", &begin[i], &end[i]);
    sort(begin, end, n);
    select(begin, end, n);
    return 0;
}

canonical_original_code:
int main()
{
    int begin[-1]; int end[-1];
    int n; int i;
    scanf("%d\n", &n);
    for (i = 0; i < n; i ++)
        scanf("%d %d\n", &begin[i], &end[i]);
    sort(begin, end, n);
    select(begin, end, n);
    return 0;
}

variable_types:
begin
int [-1]

variable_types:
end
int [-1]


output

decompiled_code:
int __fastcall output(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rbx

if ( (_DWORD)a2 == a3 )
return printf("A%d", a2);
putchar(40);
v4 = a1 + 28LL * (int)a2;
output(a1, (unsigned int)a2, *(unsigned int *)(v4 + 4LL * (int)a3));
output(a1, (unsigned int)(*(_DWORD *)(v4 + 4LL * (int)a3) + 1), a3);
return putchar(41);
}

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

if ( (_DWORD)a2 == a3 )
return printf("A%d", a2);
putchar(40);
v4 = a1 + 28LL * (int)a2;
func7(a1, (unsigned int)a2, *(unsigned int *)(v4 + 4LL * (int)a3));
func7(a1, (unsigned int)(*(_DWORD *)(v4 + 4LL * (int)a3) + 1), a3);
return putchar(41);
}

original_code:
void output(int s[][MAXN], int i, int j)
{
    if( i == j)
        printf("A%d", i);
    else
    {
        printf("(");
        output(s, i, s[i][j]);
        output(s, s[i][j] + 1, j);
        printf(")");
    }
}

canonical_original_code:
void output(int s[][-1], int i, int j)
{
    if( i == j)
        printf("A%d", i);
    else
    {
        printf("(");
        output(s, i, s[i][j]);
        output(s, s[i][j] + 1, j);
        printf(")");
    }
}


matrix

original_code:
int matrix(int *list)
{
    int result[MAXN][MAXN], record[MAXN][MAXN];
    memset(result, 0, MAXN * MAXN * sizeof(int));
    memset(record, 0, MAXN * MAXN * sizeof(int));
    int i, j, k, q, temp;
    for (q = 2; q <= n; q ++)
        for (i = 1; i <= n - q + 1; i ++)
        {
            j = i + q - 1;
            result[i][j] = 0x7fffffff;
            for (k = i; k <= j - 1; k ++)
            {
                temp = result[i][k] + result[k+1][j] +
                    list[i-1] * list[k] * list[j];
                if (temp < result[i][j])
                {
                    result[i][j] = temp;
                    record[i][j] = k;
                }
            }
        }
    output(record, 1, n);
    return result[1][n];
}

canonical_original_code:
int matrix(int *list)
{
    int result[-1][-1]; int record[-1][-1];
    memset(result, 0, MAXN * MAXN * sizeof(int));
    memset(record, 0, MAXN * MAXN * sizeof(int));
    int i; int j; int k; int q; int temp;
    for (q = 2; q <= n; q ++)
        for (i = 1; i <= n - q + 1; i ++)
        {
            j = i + q - 1;
            result[i][j] = 0x7fffffff;
            for (k = i; k <= j - 1; k ++)
            {
                temp = result[i][k] + result[k+1][j] +
                    list[i-1] * list[k] * list[j];
                if (temp < result[i][j])
                {
                    result[i][j] = temp;
                    record[i][j] = k;
                }
            }
        }
    output(record, 1, n);
    return result[1][n];
}

variable_types:
list
int *

variable_types:
result
int [-1][-1]

variable_types:
record
int [-1][-1]

variable_types: k int

variable_types: q int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rsi
int v4; // ebx
int *v5; // rbp
unsigned int v6; // eax
_BYTE v8[56]; // [rsp+0h] [rbp-38h] BYREF

v3 = &n;
v4 = 0;
__isoc99_scanf();
v5 = (int *)v8;
if ( n >= 0 )
{
do
{
v3 = v5;
++v4;
__isoc99_scanf();
++v5;
}
while ( n >= v4 );
}
v6 = matrix(v8, v3);
printf("\nans:%d\n", v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rsi
int v4; // ebx
int *v5; // rbp
unsigned int v6; // eax
_BYTE v8[56]; // [rsp+0h] [rbp-38h] BYREF

v3 = &n;
v4 = 0;
__isoc99_scanf();
v5 = (int *)v8;
if ( n >= 0 )
{
do
{
v3 = v5;
++v4;
__isoc99_scanf();
++v5;
}
while ( n >= v4 );
}
v6 = func8(v8, v3);
printf("\nans:%d\n", v6);
return 0;
}

original_code:
int main(void)
{
    int list[MAXN];
    int i;
    scanf("%d", &n);
    for (i = 0; i <= n; i ++)
        scanf("%d", &list[i]);
    int ans = matrix(list);
    printf("\nans:%d\n", ans);
    return 0;
}

canonical_original_code:
int main()
{
    int list[-1];
    int i;
    scanf("%d", &n);
    for (i = 0; i <= n; i ++)
        scanf("%d", &list[i]);
    int ans = matrix(list);
    printf("\nans:%d\n", ans);
    return 0;
}

variable_types:
list
int [-1]

variable_types: i int

variable_types: ans int


output

decompiled_code:
int __fastcall output(unsigned int *a1, int a2)
{
__int64 v2; // rbp
unsigned int *v3; // rbx
__int64 v4; // rsi

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
printf("%d ", v4);
}
while ( v3 != (unsigned int *)v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func15(unsigned int *a1, int a2)
{
__int64 v2; // rbp
unsigned int *v3; // rbx
__int64 v4; // rsi

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
printf("%d ", v4);
}
while ( v3 != (unsigned int *)v2 );
}
return putchar(10);
}

variable_types: j int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax
__int64 v5; // rbx
__int64 v6; // rdi
int *v7; // rbx
__int64 v8; // rdi

v3 = 0LL;
v4 = time(0LL);
srand(v4);
do
LIST[v3++] = rand() % 100;
while ( v3 != 5 );
v5 = 0LL;
output(LIST, 5LL);
do
{
v6 = (unsigned int)LIST[v5++];
tree_insert(v6);
}
while ( v5 != 5 );
v7 = LIST;
tree_walk(ROOT);
putchar(10);
do
{
v8 = tree_search((unsigned int)*v7);
if ( v8 )
tree_delete(v8);
++v7;
tree_walk(ROOT);
putchar(10);
}
while ( v7 != (int *)&unk_4040CC );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax
__int64 v5; // rbx
__int64 v6; // rdi
int *v7; // rbx
__int64 v8; // rdi

v3 = 0LL;
v4 = time(0LL);
srand(v4);
do
LIST[v3++] = rand() % 100;
while ( v3 != 5 );
v5 = 0LL;
func15(LIST, 5LL);
do
{
v6 = (unsigned int)LIST[v5++];
func12(v6);
}
while ( v5 != 5 );
v7 = LIST;
func7(ROOT);
putchar(10);
do
{
v8 = func10((unsigned int)*v7);
if ( v8 )
func14(v8);
++v7;
func7(ROOT);
putchar(10);
}
while ( v7 != (int *)&unk_4040CC );
return 0;
}


repo: wcharczuk/urlencode

decompiled_code:
__int64 __fastcall is_non_symbol(int a1, __int64 a2, int a3)
{
__int64 result; // rax
unsigned int v4; // eax

result = 1LL;
if ( (_BYTE)a1 )
{
v4 = (a1 & 0xFFFFFFDF) - 65;
LOBYTE(v4) = (unsigned __int8)v4 <= 0x19u;
LOBYTE(a3) = (unsigned int)((char)a1 - 48) <= 9;
result = a3 | v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, __int64 a2, int a3)
{
__int64 result; // rax
unsigned int v4; // eax

result = 1LL;
if ( (_BYTE)a1 )
{
v4 = (a1 & 0xFFFFFFDF) - 65;
LOBYTE(v4) = (unsigned __int8)v4 <= 0x19u;
LOBYTE(a3) = (unsigned int)((char)a1 - 48) <= 9;
result = a3 | v4;
}
return result;
}

original_code:
_Bool is_non_symbol(char c)
{
    if(c == '\0') return 1;
    int c_int = (int)c;
    return (c_int >= 48 && c_int <= 57) || (c_int >= 65 && c_int <= 90) || (c_int >= 97 && c_int <= 122);
}

variable_types: c char


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
char *v5; // rbp
char *v6; // [rsp+0h] [rbp-18h] BYREF
size_t n[2]; // [rsp+8h] [rbp-10h] BYREF

if ( argc > 1 )
{
v5 = (char *)url_encode(argv[1]);
printf("%s", v5);
free(v5);
}
else
{
v6 = 0LL;
while ( getline(&v6, n, stdin) != -1 )
{
v3 = (char *)url_encode(v6);
printf("%s", v3);
free(v3);
}
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
    if(argc > 1)
    {
        char *input = argv[1];
        char *encoded = url_encode(input);
        printf("%s", encoded);
        free(encoded);
    }
    else
    {
        char *line = ((void *)0);
        size_t size;
        while(getline(&line, &size, stdin) != -1)
        {
            char *encoded = url_encode(line);
            printf("%s", encoded);
            free(encoded);
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    if(argc > 1)
    {
        char *input = argv[1];
        char *encoded = url_encode(input);
        printf("%s", encoded);
        free(encoded);
    }
    else
    {
        char *line = ((void *)0);
        unsigned long size;
        while(getline(&line, &size, stdin) != -1)
        {
            char *encoded = url_encode(line);
            printf("%s", encoded);
            free(encoded);
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
input
char *

variable_types:
encoded
char *

variable_types:
line
char *

variable_types:
size
unsigned long


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
char *v5; // rbp
char *v6; // [rsp+0h] [rbp-18h] BYREF
size_t n[2]; // [rsp+8h] [rbp-10h] BYREF

if ( argc > 1 )
{
v5 = (char *)url_decode(argv[1]);
printf("%s", v5);
free(v5);
}
else
{
v6 = 0LL;
while ( getline(&v6, n, stdin) != -1 )
{
v3 = (char *)url_decode(v6);
printf("%s", v3);
free(v3);
}
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
    if(argc > 1)
    {
        char *input = argv[1];
        char *decoded = url_decode(input);
        printf("%s",decoded);
     free(decoded);
    }
    else
    {
        char *line = ((void *)0);
        size_t size;
        while(getline(&line, &size, stdin) != -1)
        {
         char *decoded = url_decode(line);
            printf("%s", decoded);
            free(decoded);
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    if(argc > 1)
    {
        char *input = argv[1];
        char *decoded = url_decode(input);
        printf("%s",decoded);
     free(decoded);
    }
    else
    {
        char *line = ((void *)0);
        unsigned long size;
        while(getline(&line, &size, stdin) != -1)
        {
         char *decoded = url_decode(line);
            printf("%s", decoded);
            free(decoded);
        }
    }
    return 0;
}

variable_types:
decoded
char *


repo: wconrad/brazzle

decompiled_code:
__int64 __fastcall memcpy_forward(__int64 a1, __int64 a2, int a3)
{
__int64 i; // rax

if ( a3 )
{
for ( i = 0LL; i != a3; ++i )
*(_BYTE *)(a1 + i) = *(_BYTE *)(a2 + i);
}
return a1;
}

original_code:
static void *
memcpy_forward(void * dst, const void * src, unsigned size) {
  for(unsigned i = 0; i < size; i++)
    ((char *)dst)[i] = ((const char *)src)[i];
  return dst;
}

canonical_original_code:
static void *memcpy_forward(void *dst, void *src, unsigned int size) {
  for(unsigned int i = 0; i < size; i++)
    ((char *)dst)[i] = ((char *)src)[i];
  return dst;
}

variable_types:
dst
void *

variable_types:
src
void *

variable_types:
size
unsigned int

variable_types:
i
unsigned int

return_type: void *


decompiled_code:
__int64 __fastcall memcpy_backward(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // eax

v3 = a3 - 1;
if ( a3 )
{
do
*(_BYTE *)(a1 + v3) = *(_BYTE *)(a2 + v3);
while ( v3-- != 0 );
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // eax

v3 = a3 - 1;
if ( a3 )
{
do
*(_BYTE *)(a1 + v3) = *(_BYTE *)(a2 + v3);
while ( v3-- != 0 );
}
return a1;
}

original_code:
static void *
memcpy_backward(void * dst, const void * src, unsigned size) {
  for(unsigned i = 0; i < size; i++)
    ((char *)dst)[(size - 1) - i] = ((const char *)src)[(size - 1) - i];
  return dst;
}

canonical_original_code:
static void *memcpy_backward(void *dst, void *src, unsigned int size) {
  for(unsigned int i = 0; i < size; i++)
    ((char *)dst)[(size - 1) - i] = ((char *)src)[(size - 1) - i];
  return dst;
}


memcpy

decompiled_code:
// attributes: thunk
__int64 __fastcall memcpy(__int64 a1, __int64 a2, int a3)
{
return memcpy_forward(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3)
{
return func0(a1, a2, a3);
}

original_code:
void *
memcpy(void * dst, const void * src, unsigned size) {
  return memcpy_forward(dst, src, size);
}

canonical_original_code:
void *memcpy(void *dst, void *src, unsigned int size) {
  return memcpy_forward(dst, src, size);
}


memmove

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

if ( a2 < (unsigned __int64)a1 )
result = memcpy_backward(a1, a2, a3);
else
result = memcpy_forward(a1, a2, a3);
return result;
}

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

if ( a2 < (unsigned __int64)a1 )
result = func1(a1, a2, a3);
else
result = func0(a1, a2, a3);
return result;
}

original_code:
void *
memmove(void * dst, const void * src, unsigned size) {
  if(src >= dst)
    return memcpy_forward(dst, src, size);
  else
    return memcpy_backward(dst, src, size);
}

canonical_original_code:
void *memmove(void *dst, void *src, unsigned int size) {
  if(src >= dst)
    return memcpy_forward(dst, src, size);
  else
    return memcpy_backward(dst, src, size);
}


strrev

decompiled_code:
char *__fastcall strrev(char *a1)
{
char v1; // cl
char *v2; // rdx
char *v3; // rax
char *i; // rdx
char v5; // si

v1 = *a1;
if ( *a1 )
{
v2 = a1;
do
v3 = v2++;
while ( *v2 );
}
else
{
v3 = a1 - 1;
}
if ( v3 > a1 )
{
for ( i = a1; ; v1 = *i )
{
v5 = *v3;
++i;
--v3;
*(i - 1) = v5;
v3[1] = v1;
if ( i >= v3 )
break;
}
}
return a1;
}

original_code:
char *
strrev(char * s) {
  char * a = s;
  char * b = s;
  while(*b != '\0')
    b++;
  b--;
  while (a < b) {
    char temp = *a;
    *a++ = *b;
    *b-- = temp;
  }
  return s;
}

canonical_original_code:
char *strrev(char *s) {
  char *a = s;
  char *b = s;
  while(*b != '\0')
    b++;
  b--;
  while (a < b) {
    char temp = *a;
    *a++ = *b;
    *b-- = temp;
  }
  return s;
}

variable_types:
s
char *

variable_types:
a
char *

variable_types:
b
char *

variable_types: temp char


strlen

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

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

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

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

original_code:
unsigned strlen(const char * s) {
  unsigned length = 0;
  while (*s++ != '\0')
    length++;
  return length;
}

canonical_original_code:
unsigned int strlen(char *s) {
  unsigned int length = 0;
  while (*s++ != '\0')
    length++;
  return length;
}

variable_types:
length
unsigned int

return_type: unsigned int


decompiled_code:
void __fastcall apply_bios_map_if(unsigned __int8 a1)
{
unsigned int v1; // ebx
unsigned int *v2; // rax

if ( loader_data[0] )
{
v1 = 0;
do
{
v2 = &loader_data[6 * v1 + 1];
if ( (v2[4] == 1) == a1 && !v2[1] && !v2[3] )
pmmap_mark_region(loader_data[6 * v1 + 1], v2[2], a1 ^ 1u);
++v1;
}
while ( loader_data[0] > v1 );
}
}

canonical_decompiled_code:
void __fastcall func0(unsigned __int8 a1)
{
unsigned int v1; // ebx
unsigned int *v2; // rax

if ( loader_data[0] )
{
v1 = 0;
do
{
v2 = &loader_data[6 * v1 + 1];
if ( (v2[4] == 1) == a1 && !v2[1] && !v2[3] )
pmmap_mark_region(loader_data[6 * v1 + 1], v2[2], a1 ^ 1u);
++v1;
}
while ( loader_data[0] > v1 );
}
}

original_code:
static void apply_bios_map_if(_Bool avail) {
  for(unsigned i = 0; i < loader_data.bios_memory_map.count; i++) {
    BiosMemoryMapEntry * entry = loader_data.bios_memory_map.entries + i;
    if(avail != (entry->type == 1))
      continue;
    if(entry->base_addr_high != 0 || entry->length_high != 0)
      continue;
    pmmap_mark_region((PhysicalAddress) entry->base_addr_low,
                      entry->length_low,
                      avail ? BLOCK_AVAIL : BLOCK_UNAVAIL);
  }
}

canonical_original_code:
static void apply_bios_map_if(_Bool avail) {
  for(unsigned int i = 0; i < loader_data.bios_memory_map.count; i++) {
    struct BiosMemoryMapEntry *entry = loader_data.bios_memory_map.entries + i;
    if(avail != (entry->type == 1))
      continue;
    if(entry->base_addr_high != 0 || entry->length_high != 0)
      continue;
    pmmap_mark_region((void *) entry->base_addr_low,
                      entry->length_low,
                      avail ? BLOCK_AVAIL : BLOCK_UNAVAIL);
  }
}

variable_types: struct BiosMemoryMapEntry { unsigned int base_addr_low; unsigned int base_addr_high; unsigned int length_low; unsigned int length_high; unsigned int type; unsigned int reserved; } *


decompiled_code:
void apply_bios_map()
{
pmmap_mark_all_used();
apply_bios_map_if(1u);
apply_bios_map_if(0);
}

canonical_decompiled_code:
void func1()
{
pmmap_mark_all_used();
func0(1u);
func0(0);
}

original_code:
static void apply_bios_map() {
  pmmap_mark_all_used();
  apply_bios_map_if(1);
  apply_bios_map_if(0);
}


decompiled_code:
__int64 mark_kernel_memory_used()
{
return pmmap_mark_region(kernel_phys_addr_var, kernel_max_bytes_var, 1LL);
}

canonical_decompiled_code:
__int64 func2()
{
return pmmap_mark_region(kernel_phys_addr_var, kernel_max_bytes_var, 1LL);
}

original_code:
static void mark_kernel_memory_used() {
  pmmap_mark_region((PhysicalAddress) kernel_phys_addr_var,
                    kernel_max_bytes_var,
                    BLOCK_UNAVAIL);
}

canonical_original_code:
static void mark_kernel_memory_used() {
  pmmap_mark_region((void *) kernel_phys_addr_var,
                    kernel_max_bytes_var,
                    BLOCK_UNAVAIL);
}


decompiled_code:
__int64 mark_page_tables_used()
{
unsigned int i; // ebx
__int64 result; // rax

for ( i = 0; i != 1024; ++i )
{
result = page_table_phys_addr(i);
if ( result )
result = pmmap_mark_region(result, 4096LL, 1LL);
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int i; // ebx
__int64 result; // rax

for ( i = 0; i != 1024; ++i )
{
result = page_table_phys_addr(i);
if ( result )
result = pmmap_mark_region(result, 4096LL, 1LL);
}
return result;
}

original_code:
static void mark_page_tables_used() {
  for(int i = 0; i < 0x400; i++) {
    PhysicalAddress phys_addr = page_table_phys_addr(i);
    if(phys_addr != 0)
      pmmap_mark_region(phys_addr, (0x400 * sizeof(uint32_t)), BLOCK_UNAVAIL);
  }
}

canonical_original_code:
static void mark_page_tables_used() {
  for(int i = 0; i < 0x400; i++) {
    void *phys_addr = page_table_phys_addr(i);
    if(phys_addr != 0)
      pmmap_mark_region(phys_addr, (0x400 * sizeof(unsigned int)), BLOCK_UNAVAIL);
  }
}

variable_types: i int


decompiled_code:
__int64 mem_init()
{
pmmap_init();
apply_bios_map();
mark_kernel_memory_used();
return mark_page_tables_used();
}

canonical_decompiled_code:
__int64 func4()
{
pmmap_init();
func1();
func2();
return func3();
}

original_code:
void mem_init() {
  pmmap_init();
  apply_bios_map();
  mark_kernel_memory_used();
  mark_page_tables_used();
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
init(argc, argv, envp);
vty_puts("Hello, world...\n");
bmmap_print();
pmmap_print();
return halt();
}

original_code:
void main() {
  init();
  vty_puts("Hello, world...\n");
  bmmap_print();
  pmmap_print();
  halt();
}


decompiled_code:
void *loader_data_init()
{
void *result; // rax

result = memmove(&loader_data, loader_data_p, 0x244uLL);
loader_data_p = 0LL;
return result;
}

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

result = memmove(&loader_data, loader_data_p, 0x244uLL);
loader_data_p = 0LL;
return result;
}

original_code:
void loader_data_init() {
  memmove(&loader_data, loader_data_p, sizeof(loader_data));
  loader_data_p = ((void *)0);
}