decompiled_code:
__int64 __fastcall hash_pjw(char *a1)
{
char v1; // dl
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(v1 + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = ((((unsigned int)result & 0xF0000000) >> 24) ^ (unsigned int)result) & 0xFFFFFFF;
v1 = *++a1;
}
while ( *a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1)
{
char v1; // dl
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(v1 + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = ((((unsigned int)result & 0xF0000000) >> 24) ^ (unsigned int)result) & 0xFFFFFFF;
v1 = *++a1;
}
while ( *a1 );
return result;
}

original_code:
unsigned int
hash_pjw(char const * str)
{
    unsigned int hash_value, i;
    for (hash_value = 0; *str; ++str) {
        hash_value = ( hash_value << ((int) (( sizeof(int) * 8 ) / 8)) ) + *str;
        if (( i = hash_value & ( ~((unsigned int)(~0) >> ((int) (( sizeof(int) * 8 ) / 8)) )) ) != 0 ) {
            hash_value =
                ( hash_value ^ ( i >> ((int) ((( sizeof(int) * 8 ) * 3) / 4)) )) &
  ~( ~((unsigned int)(~0) >> ((int) (( sizeof(int) * 8 ) / 8)) ));
 }
    }
    return hash_value;
}

canonical_original_code:
unsigned int hash_pjw(char *str)
{
    unsigned int hash_value; unsigned int i;
    for (hash_value = 0; *str; ++str) {
        hash_value = ( hash_value << ((int) (( sizeof(int) * 8 ) / 8)) ) + *str;
        if (( i = hash_value & ( ~((unsigned int)(~0) >> ((int) (( sizeof(int) * 8 ) / 8)) )) ) != 0 ) {
            hash_value =
                ( hash_value ^ ( i >> ((int) ((( sizeof(int) * 8 ) * 3) / 4)) )) &
  ~( ~((unsigned int)(~0) >> ((int) (( sizeof(int) * 8 ) / 8)) ));
 }
    }
    return hash_value;
}

variable_types:
str
char *


decompiled_code:
int __fastcall handle_accept(const void *a1, unsigned int a2, unsigned int a3, __int64 (__fastcall *a4)(const void *, _QWORD))
{
int result; // eax

Event_DebugMsg("tcp_handle_accept(es=%p, fd=%d, flags=%u, data=%p)\n", a1, a2, a3, a4);
result = accept(a2, 0LL, 0LL);
if ( result >= 0 )
result = a4(a1, (unsigned int)result);
return result;
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, unsigned int a2, unsigned int a3, __int64 (__fastcall *a4)(const void *, _QWORD))
{
int result; // eax

Event_DebugMsg("tcp_handle_accept(es=%p, fd=%d, flags=%u, data=%p)\n", a1, a2, a3, a4);
result = accept(a2, 0LL, 0LL);
if ( result >= 0 )
result = a4(a1, (unsigned int)result);
return result;
}

original_code:
static void
handle_accept(EventSelector *es,
       int fd,
       unsigned int flags,
       void *data)
{
    int conn;
    EventTcpAcceptFunc f;
    Event_DebugMsg ("tcp_handle_accept(es=%p, fd=%d, flags=%u, data=%p)\n", es, fd, flags, data);
    conn = accept(fd, ((void *)0), ((void *)0));
    if (conn < 0) return;
    f = (EventTcpAcceptFunc) data;
    f(es, conn);
}

canonical_original_code:
static void handle_accept(struct EventSelector_t *es, int fd, unsigned int flags, void *data)
{
    int conn;
    void (*f)(struct EventSelector_t *es, int fd);
    Event_DebugMsg ("tcp_handle_accept(es=%p, fd=%d, flags=%u, data=%p)\n", es, fd, flags, data);
    conn = accept(fd, ((void *)0), ((void *)0));
    if (conn < 0) return;
    f = (void (*)(struct EventSelector_t *es, int fd)) data;
    f(es, conn);
}

variable_types: fd int

variable_types:
flags
unsigned int

variable_types:
data
void *

variable_types: conn int

variable_types: void (*)(struct EventSelector_t { struct EventHandler_t { struct EventHandler_t *next; int fd; unsigned int flags; struct timeval { long tv_sec; long tv_usec; } tmout; void (*fn)(struct EventSelector_t *es, int fd, unsigned int flags, void *data); void *data; } *handlers; int nestLevel; int opsPending; int destroyPending; } *es, int fd)

return_type: void

user_defined_types: struct EventSelector_t { struct EventHandler_t *handlers; int nestLevel; int opsPending; int destroyPending; }

user_defined_types: struct EventHandler_t { struct EventHandler_t *next; int fd; unsigned int flags; struct timeval tmout; void (*fn)(struct EventSelector_t *es, int fd, unsigned int flags, void *data); void *data; }


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

if ( ptr )
{
Event_DebugMsg("tcp_free_state(state=%p)\n", ptr);
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
if ( *((_QWORD *)ptr + 6) )
Event_DelHandler(*((_QWORD *)ptr + 5));
free(ptr);
}
}

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

if ( ptr )
{
Event_DebugMsg("tcp_free_state(state=%p)\n", ptr);
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
if ( *((_QWORD *)ptr + 6) )
Event_DelHandler(*((_QWORD *)ptr + 5));
free(ptr);
}
}

original_code:
static void
free_state(EventTcpState *state)
{
    if (!state) return;
    Event_DebugMsg ("tcp_free_state(state=%p)\n", state);
    if (state->buf) free(state->buf);
    if (state->eh) Event_DelHandler(state->es, state->eh);
    free(state);
}

canonical_original_code:
static void free_state(struct EventTcpState_t *state)
{
    if (!state) return;
    Event_DebugMsg ("tcp_free_state(state=%p)\n", state);
    if (state->buf) free(state->buf);
    if (state->eh) Event_DelHandler(state->es, state->eh);
    free(state);
}

variable_types: struct EventTcpState_t { int socket; char *buf; char *cur; int len; int delim; void (*f)(struct EventSelector_t { struct EventHandler_t { struct EventHandler_t *next; int fd; unsigned int flags; struct timeval { long tv_sec; long tv_usec; } tmout; void (*fn)(struct EventSelector_t *es, int fd, unsigned int flags, void *data); void *data; } *handlers; int nestLevel; int opsPending; int destroyPending; } *es, int fd, char *buf, int len, int flag, void *data); struct EventSelector_t *es; struct EventHandler_t *eh; void *data; } *

user_defined_types: struct EventTcpState_t { int socket; char *buf; char *cur; int len; int delim; void (*f)(struct EventSelector_t *es, int fd, char *buf, int len, int flag, void *data); struct EventSelector_t *es; struct EventHandler_t *eh; void *data; }


original_code:
static void
handle_readable(EventSelector *es,
  int fd,
  unsigned int flags,
  void *data)
{
    EventTcpState *state = (EventTcpState *) data;
    int done = state->cur - state->buf;
    int togo = state->len - done;
    int nread = 0;
    int flag;
    Event_DebugMsg ("tcp_handle_readable(es=%p, fd=%d, flags=%u, data=%p)\n", es, fd, flags, data);
    if (flags & 8) {
 (*__errno_location ()) = 110;
 (state->f)(es, state->socket, state->buf, done, 3,
     state->data);
 free_state(state);
 return;
    }
    if (state->delim < 0) {
 nread = read(fd, state->cur, togo);
 if (nread <= 0) {
     if (nread < 0 && (*__errno_location ()) == 104 && done > 0) {
  nread = 0;
     }
     flag = (nread) ? 1 : 2;
     (state->f)(es, state->socket, state->buf, done, flag, state->data);
     free_state(state);
     return;
 }
 state->cur += nread;
 done += nread;
 if (done >= state->len) {
     (state->f)(es, state->socket, state->buf, done,
         0, state->data);
     free_state(state);
     return;
 }
    } else {
 while ( (togo > 0) && (nread = read(fd, state->cur, 1)) == 1) {
     togo--;
     done++;
     state->cur++;
     if (*(state->cur - 1) == state->delim) break;
 }
 if (nread <= 0) {
     if (nread < 0 && (*__errno_location ()) == 11) return;
 }
 if (nread < 0) {
     flag = 1;
 } else if (nread == 0) {
     flag = 2;
 } else {
     flag = 0;
 }
 (state->f)(es, state->socket, state->buf, done, flag, state->data);
 free_state(state);
 return;
    }
}

canonical_original_code:
static void handle_readable(struct EventSelector_t *es, int fd, unsigned int flags, void *data)
{
    struct EventTcpState_t *state = (EventTcpState *) data;
    int done = state->cur - state->buf;
    int togo = state->len - done;
    int nread = 0;
    int flag;
    Event_DebugMsg ("tcp_handle_readable(es=%p, fd=%d, flags=%u, data=%p)\n", es, fd, flags, data);
    if (flags & 8) {
 (*__errno_location ()) = 110;
 (state->f)(es, state->socket, state->buf, done, 3,
     state->data);
 free_state(state);
 return;
    }
    if (state->delim < 0) {
 nread = read(fd, state->cur, togo);
 if (nread <= 0) {
     if (nread < 0 && (*__errno_location ()) == 104 && done > 0) {
  nread = 0;
     }
     flag = (nread) ? 1 : 2;
     (state->f)(es, state->socket, state->buf, done, flag, state->data);
     free_state(state);
     return;
 }
 state->cur += nread;
 done += nread;
 if (done >= state->len) {
     (state->f)(es, state->socket, state->buf, done,
         0, state->data);
     free_state(state);
     return;
 }
    } else {
 while ( (togo > 0) && (nread = read(fd, state->cur, 1)) == 1) {
     togo--;
     done++;
     state->cur++;
     if (*(state->cur - 1) == state->delim) break;
 }
 if (nread <= 0) {
     if (nread < 0 && (*__errno_location ()) == 11) return;
 }
 if (nread < 0) {
     flag = 1;
 } else if (nread == 0) {
     flag = 2;
 } else {
     flag = 0;
 }
 (state->f)(es, state->socket, state->buf, done, flag, state->data);
 free_state(state);
 return;
    }
}

variable_types: struct EventSelector_t { struct EventHandler_t { struct EventHandler_t *next; int fd; unsigned int flags; struct timeval { long tv_sec; long tv_usec; } tmout; void (*fn)(struct EventSelector_t *es, int fd, unsigned int flags, void *data); void *data; } *handlers; int nestLevel; int opsPending; int destroyPending; } *

variable_types: done int

variable_types: togo int

variable_types: nread int

variable_types: flag int


decompiled_code:
void __fastcall handle_writeable(const void *a1, unsigned int a2, unsigned int a3, unsigned int *a4)
{
__int64 v5; // r15
int v7; // er14
__int64 v8; // rcx
void (__fastcall *v9)(const void *, _QWORD, _QWORD, __int64, _QWORD, _QWORD); // rax
void (__fastcall *v10)(const void *, _QWORD, _QWORD, _QWORD, __int64, _QWORD); // rax

v5 = *((_QWORD *)a4 + 2) - *((_QWORD *)a4 + 1);
if ( (a3 & 8) != 0 )
{
*_errno_location() = 110;
(*((void (__fastcall **)(const void *, _QWORD, _QWORD, _QWORD, __int64, _QWORD))a4 + 4))(
a1,
*a4,
*((_QWORD *)a4 + 1),
(unsigned int)v5,
3LL,
*((_QWORD *)a4 + 7));
free_state(a4);
return;
}
v7 = write(a2, *((const void **)a4 + 2), (int)(a4[6] - v5));
Event_DebugMsg("tcp_handle_writeable(es=%p, fd=%d, flags=%u, data=%p)\n", a1, a2, a3, a4);
if ( v7 <= 0 )
{
v10 = (void (__fastcall *)(const void *, _QWORD, _QWORD, _QWORD, __int64, _QWORD))*((_QWORD *)a4 + 4);
if ( v10 )
{
v10(a1, *a4, *((_QWORD *)a4 + 1), (unsigned int)v5, 1LL, *((_QWORD *)a4 + 7));
goto LABEL_8;
}
LABEL_11:
close(a2);
goto LABEL_8;
}
*((_QWORD *)a4 + 2) += v7;
v8 = (unsigned int)(v7 + v5);
if ( (int)a4[6] <= (int)v8 )
{
v9 = (void (__fastcall *)(const void *, _QWORD, _QWORD, __int64, _QWORD, _QWORD))*((_QWORD *)a4 + 4);
if ( v9 )
{
v9(a1, *a4, *((_QWORD *)a4 + 1), v8, 0LL, *((_QWORD *)a4 + 7));
LABEL_8:
free_state(a4);
return;
}
goto LABEL_11;
}
}

canonical_decompiled_code:
void __fastcall func3(const void *a1, unsigned int a2, unsigned int a3, unsigned int *a4)
{
__int64 v5; // r15
int v7; // er14
__int64 v8; // rcx
void (__fastcall *v9)(const void *, _QWORD, _QWORD, __int64, _QWORD, _QWORD); // rax
void (__fastcall *v10)(const void *, _QWORD, _QWORD, _QWORD, __int64, _QWORD); // rax

v5 = *((_QWORD *)a4 + 2) - *((_QWORD *)a4 + 1);
if ( (a3 & 8) != 0 )
{
*_errno_location() = 110;
(*((void (__fastcall **)(const void *, _QWORD, _QWORD, _QWORD, __int64, _QWORD))a4 + 4))(
a1,
*a4,
*((_QWORD *)a4 + 1),
(unsigned int)v5,
3LL,
*((_QWORD *)a4 + 7));
func1(a4);
return;
}
v7 = write(a2, *((const void **)a4 + 2), (int)(a4[6] - v5));
Event_DebugMsg("tcp_handle_writeable(es=%p, fd=%d, flags=%u, data=%p)\n", a1, a2, a3, a4);
if ( v7 <= 0 )
{
v10 = (void (__fastcall *)(const void *, _QWORD, _QWORD, _QWORD, __int64, _QWORD))*((_QWORD *)a4 + 4);
if ( v10 )
{
v10(a1, *a4, *((_QWORD *)a4 + 1), (unsigned int)v5, 1LL, *((_QWORD *)a4 + 7));
goto LABEL_8;
}
LABEL_11:
close(a2);
goto LABEL_8;
}
*((_QWORD *)a4 + 2) += v7;
v8 = (unsigned int)(v7 + v5);
if ( (int)a4[6] <= (int)v8 )
{
v9 = (void (__fastcall *)(const void *, _QWORD, _QWORD, __int64, _QWORD, _QWORD))*((_QWORD *)a4 + 4);
if ( v9 )
{
v9(a1, *a4, *((_QWORD *)a4 + 1), v8, 0LL, *((_QWORD *)a4 + 7));
LABEL_8:
func1(a4);
return;
}
goto LABEL_11;
}
}

original_code:
static void
handle_writeable(EventSelector *es,
  int fd,
  unsigned int flags,
  void *data)
{
    EventTcpState *state = (EventTcpState *) data;
    int done = state->cur - state->buf;
    int togo = state->len - done;
    int n;
    if (flags & 8) {
 (*__errno_location ()) = 110;
 (state->f)(es, state->socket, state->buf, done, 3,
     state->data);
 free_state(state);
 return;
    }
    n = write(fd, state->cur, togo);
    Event_DebugMsg ("tcp_handle_writeable(es=%p, fd=%d, flags=%u, data=%p)\n", es, fd, flags, data);
    if (n <= 0) {
 if (state->f) {
     (state->f)(es, state->socket, state->buf, done,
         1,
         state->data);
 } else {
     close(fd);
 }
 free_state(state);
 return;
    }
    state->cur += n;
    done += n;
    if (done >= state->len) {
 if (state->f) {
     (state->f)(es, state->socket, state->buf, done,
         0, state->data);
 } else {
     close(fd);
 }
 free_state(state);
 return;
    }
}

canonical_original_code:
static void handle_writeable(struct EventSelector_t *es, int fd, unsigned int flags, void *data)
{
    struct EventTcpState_t *state = (EventTcpState *) data;
    int done = state->cur - state->buf;
    int togo = state->len - done;
    int n;
    if (flags & 8) {
 (*__errno_location ()) = 110;
 (state->f)(es, state->socket, state->buf, done, 3,
     state->data);
 free_state(state);
 return;
    }
    n = write(fd, state->cur, togo);
    Event_DebugMsg ("tcp_handle_writeable(es=%p, fd=%d, flags=%u, data=%p)\n", es, fd, flags, data);
    if (n <= 0) {
 if (state->f) {
     (state->f)(es, state->socket, state->buf, done,
         1,
         state->data);
 } else {
     close(fd);
 }
 free_state(state);
 return;
    }
    state->cur += n;
    done += n;
    if (done >= state->len) {
 if (state->f) {
     (state->f)(es, state->socket, state->buf, done,
         0, state->data);
 } else {
     close(fd);
 }
 free_state(state);
 return;
    }
}

variable_types: n int

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


decompiled_code:
void __fastcall handle_connect(const void *a1, unsigned int a2, unsigned int a3, __int64 a4)
{
char v4; // bp
int v6; // ebp
socklen_t optlen; // [rsp+8h] [rbp-30h] BYREF
int optval[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = a3;
optval[0] = 0;
optlen = 4;
Event_DebugMsg("tcp_handle_connect(es=%p, fd=%d, flags=%u, data=%p)\n", a1, a2, a3, (const void *)a4);
Event_DelHandler(a1);
*(_QWORD *)(a4 + 8) = 0LL;
if ( (v4 & 8) != 0 )
{
*_errno_location() = 110;
(*(void (__fastcall **)(const void *, _QWORD, __int64, _QWORD))(a4 + 16))(a1, a2, 3LL, *(_QWORD *)(a4 + 24));
free((void *)a4);
}
else if ( getsockopt(a2, 1, 4, optval, &optlen) < 0 )
{
(*(void (__fastcall **)(const void *, _QWORD, __int64, _QWORD))(a4 + 16))(a1, a2, 1LL, *(_QWORD *)(a4 + 24));
free((void *)a4);
}
else
{
v6 = optval[0];
if ( optval[0] )
{
*_errno_location() = v6;
(*(void (__fastcall **)(const void *, _QWORD, __int64, _QWORD))(a4 + 16))(a1, a2, 1LL, *(_QWORD *)(a4 + 24));
}
else
{
(*(void (__fastcall **)(const void *, _QWORD, _QWORD, _QWORD))(a4 + 16))(a1, a2, 0LL, *(_QWORD *)(a4 + 24));
}
free((void *)a4);
}
}

canonical_decompiled_code:
void __fastcall func4(const void *a1, unsigned int a2, unsigned int a3, __int64 a4)
{
char v4; // bp
int v6; // ebp
socklen_t optlen; // [rsp+8h] [rbp-30h] BYREF
int optval[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = a3;
optval[0] = 0;
optlen = 4;
Event_DebugMsg("tcp_handle_connect(es=%p, fd=%d, flags=%u, data=%p)\n", a1, a2, a3, (const void *)a4);
Event_DelHandler(a1);
*(_QWORD *)(a4 + 8) = 0LL;
if ( (v4 & 8) != 0 )
{
*_errno_location() = 110;
(*(void (__fastcall **)(const void *, _QWORD, __int64, _QWORD))(a4 + 16))(a1, a2, 3LL, *(_QWORD *)(a4 + 24));
free((void *)a4);
}
else if ( getsockopt(a2, 1, 4, optval, &optlen) < 0 )
{
(*(void (__fastcall **)(const void *, _QWORD, __int64, _QWORD))(a4 + 16))(a1, a2, 1LL, *(_QWORD *)(a4 + 24));
free((void *)a4);
}
else
{
v6 = optval[0];
if ( optval[0] )
{
*_errno_location() = v6;
(*(void (__fastcall **)(const void *, _QWORD, __int64, _QWORD))(a4 + 16))(a1, a2, 1LL, *(_QWORD *)(a4 + 24));
}
else
{
(*(void (__fastcall **)(const void *, _QWORD, _QWORD, _QWORD))(a4 + 16))(a1, a2, 0LL, *(_QWORD *)(a4 + 24));
}
free((void *)a4);
}
}

original_code:
static void
handle_connect(EventSelector *es,
       int fd,
       unsigned int flags,
       void *data)
{
    int error = 0;
    socklen_t len = sizeof(error);
    EventTcpConnectState *state = (EventTcpConnectState *) data;
    Event_DebugMsg ("tcp_handle_connect(es=%p, fd=%d, flags=%u, data=%p)\n", es, fd, flags, data);
    Event_DelHandler(es, state->conn);
    state->conn = ((void *)0);
    if (flags & 8) {
 (*__errno_location ()) = 110;
 state->f(es, fd, 3, state->data);
 free(state);
 return;
    }
    if (getsockopt(fd, 1, 4, &error, &len) < 0) {
 state->f(es, fd, 1, state->data);
 free(state);
 return;
    }
    if (error) {
 (*__errno_location ()) = error;
 state->f(es, fd, 1, state->data);
 free(state);
 return;
    }
    state->f(es, fd, 0, state->data);
    free(state);
}

canonical_original_code:
static void handle_connect(struct EventSelector_t *es, int fd, unsigned int flags, void *data)
{
    int error = 0;
    unsigned int len = sizeof(error);
    struct EventTcpConnectState_t *state = (EventTcpConnectState *) data;
    Event_DebugMsg ("tcp_handle_connect(es=%p, fd=%d, flags=%u, data=%p)\n", es, fd, flags, data);
    Event_DelHandler(es, state->conn);
    state->conn = ((void *)0);
    if (flags & 8) {
 (*__errno_location ()) = 110;
 state->f(es, fd, 3, state->data);
 free(state);
 return;
    }
    if (getsockopt(fd, 1, 4, &error, &len) < 0) {
 state->f(es, fd, 1, state->data);
 free(state);
 return;
    }
    if (error) {
 (*__errno_location ()) = error;
 state->f(es, fd, 1, state->data);
 free(state);
 return;
    }
    state->f(es, fd, 0, state->data);
    free(state);
}

variable_types: error int

variable_types:
len
unsigned int

variable_types: struct EventTcpConnectState_t { int fd; struct EventHandler_t { struct EventHandler_t *next; int fd; unsigned int flags; struct timeval { long tv_sec; long tv_usec; } tmout; void (*fn)(struct EventSelector_t { struct EventHandler_t *handlers; int nestLevel; int opsPending; int destroyPending; } *es, int fd, unsigned int flags, void *data); void *data; } *conn; void (*f)(struct EventSelector_t *es, int fd, int flag, void *data); void *data; } *

user_defined_types: struct EventTcpConnectState_t { int fd; struct EventHandler_t *conn; void (*f)(struct EventSelector_t *es, int fd, int flag, void *data); void *data; }


decompiled_code:
__int64 __fastcall EventTcp_CreateAcceptor(const void *a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // eax
__int64 result; // rax

Event_DebugMsg("EventTcp_CreateAcceptor(es=%p, socket=%d)\n", a1, a2);
v4 = fcntl(a2, 3, 0LL);
if ( v4 == -1 )
return 0LL;
BYTE1(v4) |= 8u;
if ( fcntl(a2, 4, v4) == -1 )
result = 0LL;
else
result = Event_AddHandler(a1, a2, 1LL, handle_accept, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const void *a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // eax
__int64 result; // rax

Event_DebugMsg("EventTcp_CreateAcceptor(es=%p, socket=%d)\n", a1, a2);
v4 = fcntl(a2, 3, 0LL);
if ( v4 == -1 )
return 0LL;
BYTE1(v4) |= 8u;
if ( fcntl(a2, 4, v4) == -1 )
result = 0LL;
else
result = Event_AddHandler(a1, a2, 1LL, handle_accept, a3);
return result;
}

original_code:
EventHandler *
EventTcp_CreateAcceptor(EventSelector *es,
   int socket,
   EventTcpAcceptFunc f)
{
    int flags;
    Event_DebugMsg ("EventTcp_CreateAcceptor(es=%p, socket=%d)\n", es, socket);
    flags = fcntl(socket, 3, 0);
    if (flags == -1) {
 return ((void *)0);
    }
    if (fcntl(socket, 4, flags | 04000) == -1) {
 return ((void *)0);
    }
    return Event_AddHandler(es, socket, 1,
       handle_accept, (void *) f);
}

canonical_original_code:
struct EventHandler_t *EventTcp_CreateAcceptor(struct EventSelector_t *es, int socket, void (*f)(struct EventSelector_t *es, int fd))
{
    int flags;
    Event_DebugMsg ("EventTcp_CreateAcceptor(es=%p, socket=%d)\n", es, socket);
    flags = fcntl(socket, 3, 0);
    if (flags == -1) {
 return ((void *)0);
    }
    if (fcntl(socket, 4, flags | 04000) == -1) {
 return ((void *)0);
    }
    return Event_AddHandler(es, socket, 1,
       handle_accept, (void *) f);
}

variable_types:
es
struct EventSelector_t *

variable_types: socket int

variable_types: void (*)(struct EventSelector_t *es, int fd)

variable_types: flags int

return_type: struct EventHandler_t { struct EventHandler_t *next; int fd; unsigned int flags; struct timeval { long tv_sec; long tv_usec; } tmout; void (*fn)(struct EventSelector_t { struct EventHandler_t *handlers; int nestLevel; int opsPending; int destroyPending; } *es, int fd, unsigned int flags, void *data); void *data; } *


decompiled_code:
__int64 __fastcall EventTcp_Connect(__int64 a1, unsigned int a2, const struct sockaddr *a3, socklen_t a4, __int64 (__fastcall *a5)(__int64, _QWORD, __int64, __int64), int a6, __int64 a7)
{
unsigned int v11; // eax
int v12; // eax
__int64 result; // rax
_QWORD *v14; // rax
_QWORD *v15; // r14
__int64 v16; // rcx
__int64 v17; // r8

v11 = fcntl(a2, 3, 0LL);
if ( v11 == -1 )
return a5(a1, a2, 1LL, a7);
BYTE1(v11) |= 8u;
if ( fcntl(a2, 4, v11) == -1 )
return a5(a1, a2, 1LL, a7);
v12 = connect(a2, a3, a4);
if ( v12 < 0 )
{
if ( *_errno_location() != 115 )
return a5(a1, a2, 1LL, a7);
}
else if ( !v12 )
{
return a5(a1, a2, 0LL, a7);
}
v14 = malloc(0x20uLL);
v15 = v14;
if ( !v14 )
return a5(a1, a2, 1LL, a7);
v14[2] = a5;
*(_DWORD *)v14 = a2;
v14[3] = a7;
v16 = a6;
v17 = 0LL;
if ( a6 <= 0 )
v16 = -1LL;
if ( a6 <= 0 )
v17 = -1LL;
result = Event_AddHandlerWithTimeout(a1, a2, 2LL, v16, v17, handle_connect, v14);
v15[1] = result;
if ( !result )
{
free(v15);
result = a5(a1, a2, 1LL, a7);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, const struct sockaddr *a3, socklen_t a4, __int64 (__fastcall *a5)(__int64, _QWORD, __int64, __int64), int a6, __int64 a7)
{
unsigned int v11; // eax
int v12; // eax
__int64 result; // rax
_QWORD *v14; // rax
_QWORD *v15; // r14
__int64 v16; // rcx
__int64 v17; // r8

v11 = fcntl(a2, 3, 0LL);
if ( v11 == -1 )
return a5(a1, a2, 1LL, a7);
BYTE1(v11) |= 8u;
if ( fcntl(a2, 4, v11) == -1 )
return a5(a1, a2, 1LL, a7);
v12 = connect(a2, a3, a4);
if ( v12 < 0 )
{
if ( *_errno_location() != 115 )
return a5(a1, a2, 1LL, a7);
}
else if ( !v12 )
{
return a5(a1, a2, 0LL, a7);
}
v14 = malloc(0x20uLL);
v15 = v14;
if ( !v14 )
return a5(a1, a2, 1LL, a7);
v14[2] = a5;
*(_DWORD *)v14 = a2;
v14[3] = a7;
v16 = a6;
v17 = 0LL;
if ( a6 <= 0 )
v16 = -1LL;
if ( a6 <= 0 )
v17 = -1LL;
result = Event_AddHandlerWithTimeout(a1, a2, 2LL, v16, v17, handle_connect, v14);
v15[1] = result;
if ( !result )
{
free(v15);
result = a5(a1, a2, 1LL, a7);
}
return result;
}

original_code:
void
EventTcp_Connect(EventSelector *es,
   int fd,
   struct sockaddr const *addr,
   socklen_t addrlen,
   EventTcpConnectFunc f,
   int timeout,
   void *data)
{
    int flags;
    int n;
    EventTcpConnectState *state;
    struct timeval t;
    flags = fcntl(fd, 3, 0);
    if (flags == -1 || fcntl(fd, 4, flags | 04000) == -1) {
 f(es, fd, 1, data);
 return;
    }
    n = connect(fd, addr, addrlen);
    if (n < 0) {
 if ((*__errno_location ()) != 115) {
     f(es, fd, 1, data);
     return;
 }
    }
    if (n == 0) {
 f(es, fd, 0, data);
 return;
    }
    state = malloc(sizeof(*state));
    if (!state) {
 f(es, fd, 1, data);
 return;
    }
    state->f = f;
    state->fd = fd;
    state->data = data;
    if (timeout <= 0) {
 t.tv_sec = -1;
 t.tv_usec = -1;
    } else {
 t.tv_sec = timeout;
 t.tv_usec = 0;
    }
    state->conn = Event_AddHandlerWithTimeout(es, fd, 2,
           t, handle_connect,
           (void *) state);
    if (!state->conn) {
 free(state);
 f(es, fd, 1, data);
 return;
    }
}

canonical_original_code:
void EventTcp_Connect(struct EventSelector_t *es, int fd, struct sockaddr *addr, unsigned int addrlen, void (*f)(struct EventSelector_t *es, int fd, int flag, void *data), int timeout, void *data)
{
    int flags;
    int n;
    struct EventTcpConnectState_t *state;
    struct timeval t;
    flags = fcntl(fd, 3, 0);
    if (flags == -1 || fcntl(fd, 4, flags | 04000) == -1) {
 f(es, fd, 1, data);
 return;
    }
    n = connect(fd, addr, addrlen);
    if (n < 0) {
 if ((*__errno_location ()) != 115) {
     f(es, fd, 1, data);
     return;
 }
    }
    if (n == 0) {
 f(es, fd, 0, data);
 return;
    }
    state = malloc(sizeof(*state));
    if (!state) {
 f(es, fd, 1, data);
 return;
    }
    state->f = f;
    state->fd = fd;
    state->data = data;
    if (timeout <= 0) {
 t.tv_sec = -1;
 t.tv_usec = -1;
    } else {
 t.tv_sec = timeout;
 t.tv_usec = 0;
    }
    state->conn = Event_AddHandlerWithTimeout(es, fd, 2,
           t, handle_connect,
           (void *) state);
    if (!state->conn) {
 free(state);
 f(es, fd, 1, data);
 return;
    }
}

variable_types: fd int

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

variable_types:
addrlen
unsigned int

variable_types: void (*)(struct EventSelector_t *es, int fd, int flag, void *data)

variable_types: timeout int

variable_types:
data
void *

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


decompiled_code:
void __fastcall EventTcp_CancelPending(void *a1)
{
free_state(a1);
}

canonical_decompiled_code:
void __fastcall func7(void *a1)
{
func1(a1);
}

original_code:
void
EventTcp_CancelPending(EventTcpState *s)
{
    free_state(s);
}

canonical_original_code:
void EventTcp_CancelPending(struct EventTcpState_t *s)
{
    free_state(s);
}

variable_types: struct EventTcpState_t { int socket; char *buf; char *cur; int len; int delim; void (*f)(struct EventSelector_t { struct EventHandler_t { struct EventHandler_t *next; int fd; unsigned int flags; struct timeval { long tv_sec; long tv_usec; } tmout; void (*fn)(struct EventSelector_t *es, int fd, unsigned int flags, void *data); void *data; } *handlers; int nestLevel; int opsPending; int destroyPending; } *es, int fd, char *buf, int len, int flag, void *data); struct EventSelector_t *es; struct EventHandler_t *eh; void *data; } *


repo: VentrueSoftware/vnes

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

if ( (a1 & 1) == 0 )
{
Get_Render_Buffer();
Open_Display(&disp__, 512LL, 480LL);
result = Display_Loop(disp__, &Handle_Debug_Input);
}
return result;
}

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

if ( (a1 & 1) == 0 )
{
Get_Render_Buffer();
Open_Display(&disp__, 512LL, 480LL);
result = Display_Loop(disp__, &Handle_Debug_Input);
}
return result;
}

original_code:
void Start_Debug(u32 flags) {
    if (((flags) & (0x00000001))) {
    } else {
        u32 *render_buffer = Get_Render_Buffer();
        Open_Display(&disp__, 256 * 2, 240 * 2);
        Display_Loop(disp__, Handle_Debug_Input);
    }
}

canonical_original_code:
void Start_Debug(unsigned int flags) {
    if (((flags) & (0x00000001))) {
    } else {
        unsigned int *render_buffer = Get_Render_Buffer();
        Open_Display(&disp__, 256 * 2, 240 * 2);
        Display_Loop(disp__, Handle_Debug_Input);
    }
}

variable_types:
flags
unsigned int


decompiled_code:
__int64 End_Debug()
{
return Close_Display(disp__);
}

canonical_decompiled_code:
__int64 func1()
{
return Close_Display(disp__);
}

original_code:
void End_Debug(int sig) {
    Close_Display(disp__);
}

variable_types: sig int


decompiled_code:
void Log_Line()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code: void Log_Line(const char *format, ...) {}

canonical_original_code: void Log_Line(char *format, ...) {}

variable_types:
format
char *


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

cpu[8] = 1;
do
result = Cpu_Step();
while ( (_DWORD)result && cpu[8] );
return result;
}

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

cpu[8] = 1;
do
result = Cpu_Step();
while ( (_DWORD)result && cpu[8] );
return result;
}

original_code:
void Cpu_Run(void) {
    cpu.state = 1;
    while (cpu.state) {
        if (!Cpu_Step()) {
   ;
   break;
  }
    }
}

canonical_original_code:
void Cpu_Run() {
    cpu.state = 1;
    while (cpu.state) {
        if (!Cpu_Step()) {
   ;
   break;
  }
    }
}


decompiled_code:
void Cpu_Dump()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}


decompiled_code:
__int64 VNES_Init()
{
Cpu_Init();
Ppu_Init();
return Mem_Init();
}

canonical_decompiled_code:
__int64 func0()
{
Cpu_Init();
Ppu_Init();
return Mem_Init();
}

original_code:
void VNES_Init(void) {
    ;
    Cpu_Init();
    Ppu_Init();
    Mem_Init();
}

canonical_original_code:
void VNES_Init() {
    ;
    Cpu_Init();
    Ppu_Init();
    Mem_Init();
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Load_Cartridge(argv[1]);
VNES_Init();
Start_Debug(0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Load_Cartridge(argv[1]);
func0();
Start_Debug(0LL);
return 0;
}

original_code:
int main(int argc, char **argv) {
    Load_Cartridge(argv[1]);
    VNES_Init();
    Start_Debug(0);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


decompiled_code:
__int64 __fastcall Read_Cartridge_Prg(unsigned __int16 a1)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( g_cart )
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(g_cart + 8))(g_cart, a1);
return result;
}

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

result = 0xFFFFFFFFLL;
if ( g_cart )
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(g_cart + 8))(g_cart, a1);
return result;
}

original_code:
u8 Read_Cartridge_Prg(u16 address) {
    if (g_cart) {
        return g_cart->Read_Prg(g_cart, address);
    }
    return 0xFF;
}

canonical_original_code:
unsigned char Read_Cartridge_Prg(unsigned short address) {
    if (g_cart) {
        return g_cart->Read_Prg(g_cart, address);
    }
    return 0xFF;
}

variable_types:
address
unsigned short

return_type: unsigned char


decompiled_code:
__int64 __fastcall Read_Cartridge_Chr(unsigned __int16 a1)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( g_cart )
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(g_cart + 16))(g_cart, a1);
return result;
}

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

result = 0xFFFFFFFFLL;
if ( g_cart )
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(g_cart + 16))(g_cart, a1);
return result;
}

original_code:
u8 Read_Cartridge_Chr(u16 address) {
 if (g_cart) {
  return g_cart->Read_Chr(g_cart, address);
 }
 return 0xFF;
}

canonical_original_code:
unsigned char Read_Cartridge_Chr(unsigned short address) {
 if (g_cart) {
  return g_cart->Read_Chr(g_cart, address);
 }
 return 0xFF;
}


original_code:
static inline u8 Read_Ppu_Status(void) {
    register u8 status = ppu.status;
    status |= ppu.last_write & 0x1F;
    ((ppu.status) &= ~(0x80));
    ppu.latch = 0;
    return status | 0x40;
}

canonical_original_code:
static inline unsigned char Read_Ppu_Status() {
    register unsigned char status = ppu.status;
    status |= ppu.last_write & 0x1F;
    ((ppu.status) &= ~(0x80));
    ppu.latch = 0;
    return status | 0x40;
}

variable_types:
status
unsigned char


decompiled_code:
__int64 Read_Oam_Data()
{
return *((unsigned __int8 *)&ppu + *((unsigned __int8 *)&ppu + 17) + 8288);
}

canonical_decompiled_code:
__int64 func1()
{
return *((unsigned __int8 *)&ppu + *((unsigned __int8 *)&ppu + 17) + 8288);
}

original_code:
static inline u8 Read_Oam_Data(void) {
    return ppu.oam[ppu.oamaddr];
}

canonical_original_code:
static inline unsigned char Read_Oam_Data() {
    return ppu.oam[ppu.oamaddr];
}


decompiled_code:
void __fastcall Write_Ppu_Mask(char a1)
{
*((_BYTE *)&ppu + 15) = a1;
}

canonical_decompiled_code:
void __fastcall func2(char a1)
{
*((_BYTE *)&ppu + 15) = a1;
}

original_code:
static inline void Write_Ppu_Mask(u8 value) {
    ppu.mask = value;
}

canonical_original_code:
static inline void Write_Ppu_Mask(unsigned char value) {
    ppu.mask = value;
}

variable_types:
value
unsigned char


decompiled_code:
void __fastcall Write_Ppu_Oam_Addr(char a1)
{
*((_BYTE *)&ppu + 17) = a1;
}

canonical_decompiled_code:
void __fastcall func3(char a1)
{
*((_BYTE *)&ppu + 17) = a1;
}

original_code:
static inline void Write_Ppu_Oam_Addr(u8 value) {
    ppu.oamaddr = value;
}

canonical_original_code:
static inline void Write_Ppu_Oam_Addr(unsigned char value) {
    ppu.oamaddr = value;
}


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

LOBYTE(result) = *((_BYTE *)&ppu + 17);
*((_BYTE *)&ppu + 17) = result + 1;
result = (unsigned __int8)result;
*((_BYTE *)&ppu + (unsigned __int8)result + 8288) = a1;
return result;
}

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

LOBYTE(result) = *((_BYTE *)&ppu + 17);
*((_BYTE *)&ppu + 17) = result + 1;
result = (unsigned __int8)result;
*((_BYTE *)&ppu + (unsigned __int8)result + 8288) = a1;
return result;
}

original_code:
static inline void Write_Ppu_Oam_Data(u8 value) {
    ppu.oam[ppu.oamaddr++] = value;
}

canonical_original_code:
static inline void Write_Ppu_Oam_Data(unsigned char value) {
    ppu.oam[ppu.oamaddr++] = value;
}


decompiled_code:
__int64 __fastcall Write_Ppu_Scroll(unsigned __int8 a1)
{
int v1; // edx
__int64 result; // rax
unsigned int v3; // eax

if ( *((_BYTE *)&ppu + 18) )
{
v3 = *((unsigned __int16 *)&ppu + 14);
LOWORD(v3) = v3 & 0xFC1F;
result = (a1 >> 3) | v3;
*((_WORD *)&ppu + 14) = result;
*((_WORD *)&ppu + 11) = a1 & 7;
*((_BYTE *)&ppu + 18) = 0;
}
else
{
v1 = a1 >> 3;
result = v1 | *((_WORD *)&ppu + 14) & 0xFFE0u;
*((_WORD *)&ppu + 14) = v1 | *((_WORD *)&ppu + 14) & 0xFFE0;
*((_WORD *)&ppu + 10) = a1 & 7;
*((_BYTE *)&ppu + 18) = 1;
}
return result;
}

original_code:
static inline void Write_Ppu_Scroll(u8 value) {
    if (0 == ppu.latch) {
        ppu.t_addr = (ppu.t_addr & 0xFFE0) | ((value & 0xF8) >> 3);
        ppu.scrollx = value & 0x07;
        ppu.latch = 1;
    } else {
        ppu.t_addr = (ppu.t_addr & 0xFC1F) | ((value & 0xF8) >> 3);
        ppu.scrolly = value & 0x07;
        ppu.latch = 0;
    }
}

canonical_original_code:
static inline void Write_Ppu_Scroll(unsigned char value) {
    if (0 == ppu.latch) {
        ppu.t_addr = (ppu.t_addr & 0xFFE0) | ((value & 0xF8) >> 3);
        ppu.scrollx = value & 0x07;
        ppu.latch = 1;
    } else {
        ppu.t_addr = (ppu.t_addr & 0xFC1F) | ((value & 0xF8) >> 3);
        ppu.scrolly = value & 0x07;
        ppu.latch = 0;
    }
}


original_code:
static inline void Write_Ppu_Addr(u8 value) {
    if (0 == ppu.latch) {
        ppu.t_addr = (((u16)(value) & 0x3F) << 8) | (ppu.t_addr & 0x00FF);
        ppu.t_addr = ppu.t_addr & 0x3FFF;
        ppu.latch = 1;
    } else {
        ppu.t_addr = (ppu.t_addr & 0xFF00) | (u16)(value);
        ppu.v_addr = ppu.t_addr;
        ppu.latch = 0;
    }
}

canonical_original_code:
static inline void Write_Ppu_Addr(unsigned char value) {
    if (0 == ppu.latch) {
        ppu.t_addr = (((u16)(value) & 0x3F) << 8) | (ppu.t_addr & 0x00FF);
        ppu.t_addr = ppu.t_addr & 0x3FFF;
        ppu.latch = 1;
    } else {
        ppu.t_addr = (ppu.t_addr & 0xFF00) | (u16)(value);
        ppu.v_addr = ppu.t_addr;
        ppu.latch = 0;
    }
}


original_code:
static void Write_Vram(u16 addr, u8 value) {
    addr &= 0x3FFF;
    if (addr < 0x2000) {
    }
    else if (addr < 0x3F00) {
        register u8 index = (addr >> 10) & 0x03;
        register u16 offset = addr & 0x3FF;
        ppu.nt_map[index][offset] = value;
    } else {
        if (4 == (addr & 0x7) || 0 == (addr & 0xF))
            ppu.bg_pal[addr & 0x0F] = ppu.spr_pal[addr & 0x0F] = value;
        else if (addr & 0x10) ppu.spr_pal[addr & 0x0F] = value;
        else ppu.bg_pal[addr & 0x0F] = value;
    }
}

canonical_original_code:
static void Write_Vram(unsigned short addr, unsigned char value) {
    addr &= 0x3FFF;
    if (addr < 0x2000) {
    }
    else if (addr < 0x3F00) {
        register unsigned char index = (addr >> 10) & 0x03;
        register unsigned short offset = addr & 0x3FF;
        ppu.nt_map[index][offset] = value;
    } else {
        if (4 == (addr & 0x7) || 0 == (addr & 0xF))
            ppu.bg_pal[addr & 0x0F] = ppu.spr_pal[addr & 0x0F] = value;
        else if (addr & 0x10) ppu.spr_pal[addr & 0x0F] = value;
        else ppu.bg_pal[addr & 0x0F] = value;
    }
}

variable_types:
addr
unsigned short

variable_types:
index
unsigned char

variable_types:
offset
unsigned short


original_code:
inline void Write_Ppu_Data(u8 value) {
    Write_Vram(ppu.v_addr, value);
    ppu.v_addr += (ppu.ctrl & 0x04) ? 32 : 1;
}

canonical_original_code:
inline void Write_Ppu_Data(unsigned char value) {
    Write_Vram(ppu.v_addr, value);
    ppu.v_addr += (ppu.ctrl & 0x04) ? 32 : 1;
}


original_code:
static u8 Read_Vram(u16 addr) {
    register u8 value = 0;
    addr &= 0x3FFF;
    if (addr < 0x2000) return Read_Cartridge_Chr(addr);
    else if (addr < 0x3F00) {
        register u8 index = (addr >> 10) & 0x03;
        register u16 offset = addr & 0x3FF;
        value = ppu.vram_value;
        ppu.vram_value = ppu.nt_map[index][offset];
        return value;
    } else {
        if (4 == (addr & 0x7) || 0 == (addr & 0xF)) return ppu.bg_pal[addr & 0x0F];
        if (addr & 0x10) return ppu.spr_pal[addr & 0x0F];
        return ppu.bg_pal[addr & 0x0F];
    }
    return 0xFF;
}

canonical_original_code:
static unsigned char Read_Vram(unsigned short addr) {
    register unsigned char value = 0;
    addr &= 0x3FFF;
    if (addr < 0x2000) return Read_Cartridge_Chr(addr);
    else if (addr < 0x3F00) {
        register unsigned char index = (addr >> 10) & 0x03;
        register unsigned short offset = addr & 0x3FF;
        value = ppu.vram_value;
        ppu.vram_value = ppu.nt_map[index][offset];
        return value;
    } else {
        if (4 == (addr & 0x7) || 0 == (addr & 0xF)) return ppu.bg_pal[addr & 0x0F];
        if (addr & 0x10) return ppu.spr_pal[addr & 0x0F];
        return ppu.bg_pal[addr & 0x0F];
    }
    return 0xFF;
}


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

LODWORD(result) = Read_Vram(WORD1(ppu[3]));
WORD1(ppu[3]) += (ppu[2] & 4) == 0 ? 1 : 32;
return (unsigned int)result;
}

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

LODWORD(result) = func9(WORD1(ppu[3]));
WORD1(ppu[3]) += (ppu[2] & 4) == 0 ? 1 : 32;
return (unsigned int)result;
}

original_code:
static inline u8 Read_Ppu_Data(void) {
    register u8 value = 0;
    value = Read_Vram(ppu.v_addr);
    ppu.v_addr += (ppu.status & 0x04) ? 32 : 1;
    return value;
}

canonical_original_code:
static inline unsigned char Read_Ppu_Data() {
    register unsigned char value = 0;
    value = Read_Vram(ppu.v_addr);
    ppu.v_addr += (ppu.status & 0x04) ? 32 : 1;
    return value;
}


decompiled_code:
__int16 __fastcall Write_Ppu_Ctrl(unsigned __int8 a1)
{
__int16 result; // ax

Log_Line("Writing to PPUCTRL, value: %02X", a1);
BYTE6(ppu[1]) = a1;
result = WORD2(ppu[3]);
HIBYTE(result) &= 0xF3u;
WORD2(ppu[3]) = result | (a1 << 10) & 0xC00;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func11(unsigned __int8 a1)
{
__int16 result; // ax

Log_Line("Writing to PPUCTRL, value: %02X", a1);
BYTE6(ppu[1]) = a1;
result = WORD2(ppu[3]);
HIBYTE(result) &= 0xF3u;
WORD2(ppu[3]) = result | (a1 << 10) & 0xC00;
return result;
}

original_code:
static inline void Write_Ppu_Ctrl(u8 value) {
    Log_Line("Writing to PPUCTRL, value: %02X", value);
    ppu.ctrl = value;
    ppu.t_addr = (ppu.t_addr & 0xF3FF) | (((u16)(value & 0x03)) << 10);
}

canonical_original_code:
static inline void Write_Ppu_Ctrl(unsigned char value) {
    Log_Line("Writing to PPUCTRL, value: %02X", value);
    ppu.ctrl = value;
    ppu.t_addr = (ppu.t_addr & 0xF3FF) | (((u16)(value & 0x03)) << 10);
}


decompiled_code:
__int64 __fastcall Read_Ppu(unsigned __int16 a1)
{
switch ( a1 )
{
case 0x2004u:
return Read_Oam_Data();
case 0x2007u:
return Read_Ppu_Data();
case 0x2002u:
return Read_Ppu_Status();
}
printf("Unrecognized PPU Register read address (0x%04X)!\n", a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int16 a1)
{
switch ( a1 )
{
case 0x2004u:
return func1();
case 0x2007u:
return func10();
case 0x2002u:
return func0();
}
printf("Unrecognized PPU Register read address (0x%04X)!\n", a1);
return 0xFFFFFFFFLL;
}

original_code:
u8 Read_Ppu(u16 addr) {
    switch (addr) {
        case 0x2002: return Read_Ppu_Status();
        case 0x2004: return Read_Oam_Data();
        case 0x2007: return Read_Ppu_Data();
        default:
            printf("Unrecognized PPU Register read address (0x%04X)!\n", addr);
    }
    return 0xFF;
}

canonical_original_code:
unsigned char Read_Ppu(unsigned short addr) {
    switch (addr) {
        case 0x2002: return Read_Ppu_Status();
        case 0x2004: return Read_Oam_Data();
        case 0x2007: return Read_Ppu_Data();
        default:
            printf("Unrecognized PPU Register read address (0x%04X)!\n", addr);
    }
    return 0xFF;
}


decompiled_code:
void __fastcall Write_Ppu(__int64 a1, __int64 a2)
{
BYTE5(ppu[1]) = a2;
switch ( (__int16)a1 )
{
case 8192:
if ( (unsigned int)Cpu_Get_Cycles(a1, a2, (unsigned int)a1) > 0x73DA )
Write_Ppu_Ctrl(a2);
break;
case 8193:
if ( (unsigned int)Cpu_Get_Cycles(a1, a2, (unsigned int)a1) > 0x73DA )
Write_Ppu_Mask(a2);
break;
case 8195:
Write_Ppu_Oam_Addr(a2);
break;
case 8196:
Write_Ppu_Oam_Data(a2);
break;
case 8197:
if ( (unsigned int)Cpu_Get_Cycles(a1, a2, (unsigned int)a1) > 0x73DA )
Write_Ppu_Scroll(a2);
break;
case 8198:
if ( (unsigned int)Cpu_Get_Cycles(a1, a2, (unsigned int)a1) > 0x73DA )
Write_Ppu_Addr(a2);
break;
case 8199:
Write_Ppu_Data(a2);
break;
default:
printf("Unrecognized PPU Register address (0x%04X)!\n", (unsigned __int16)a1);
break;
}
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, __int64 a2)
{
BYTE5(ppu[1]) = a2;
switch ( (__int16)a1 )
{
case 8192:
if ( (unsigned int)Cpu_Get_Cycles(a1, a2, (unsigned int)a1) > 0x73DA )
func11(a2);
break;
case 8193:
if ( (unsigned int)Cpu_Get_Cycles(a1, a2, (unsigned int)a1) > 0x73DA )
func2(a2);
break;
case 8195:
func3(a2);
break;
case 8196:
func4(a2);
break;
case 8197:
if ( (unsigned int)Cpu_Get_Cycles(a1, a2, (unsigned int)a1) > 0x73DA )
func5(a2);
break;
case 8198:
if ( (unsigned int)Cpu_Get_Cycles(a1, a2, (unsigned int)a1) > 0x73DA )
func6(a2);
break;
case 8199:
func8(a2);
break;
default:
printf("Unrecognized PPU Register address (0x%04X)!\n", (unsigned __int16)a1);
break;
}
}

original_code:
void Write_Ppu(u16 addr, u8 value) {
    ppu.last_write = value;
    switch (addr) {
        case 0x2000:
            if (Cpu_Get_Cycles() > 29658) Write_Ppu_Ctrl(value);
        break;
        case 0x2001:
            if (Cpu_Get_Cycles() > 29658) Write_Ppu_Mask(value);
        break;
        case 0x2003: Write_Ppu_Oam_Addr(value); break;
        case 0x2004: Write_Ppu_Oam_Data(value); break;
        case 0x2005:
            if (Cpu_Get_Cycles() > 29658) Write_Ppu_Scroll(value);
        break;
        case 0x2006:
            if (Cpu_Get_Cycles() > 29658) Write_Ppu_Addr(value);
        break;
        case 0x2007: Write_Ppu_Data(value); break;
        default:
            printf("Unrecognized PPU Register address (0x%04X)!\n", addr);
    }
}

canonical_original_code:
void Write_Ppu(unsigned short addr, unsigned char value) {
    ppu.last_write = value;
    switch (addr) {
        case 0x2000:
            if (Cpu_Get_Cycles() > 29658) Write_Ppu_Ctrl(value);
        break;
        case 0x2001:
            if (Cpu_Get_Cycles() > 29658) Write_Ppu_Mask(value);
        break;
        case 0x2003: Write_Ppu_Oam_Addr(value); break;
        case 0x2004: Write_Ppu_Oam_Data(value); break;
        case 0x2005:
            if (Cpu_Get_Cycles() > 29658) Write_Ppu_Scroll(value);
        break;
        case 0x2006:
            if (Cpu_Get_Cycles() > 29658) Write_Ppu_Addr(value);
        break;
        case 0x2007: Write_Ppu_Data(value); break;
        default:
            printf("Unrecognized PPU Register address (0x%04X)!\n", addr);
    }
}


original_code:
static u8 Read_iNES0_Prg(icart *cart, u16 address) {
    ines_cart *c = (ines_cart *)cart;
    u16 index = ((address - 0x8000) / (16 * 1024)) % c->prg_pages;
    return c->prg_rom[index][(address - 0x8000) % (16 * 1024)];
}

canonical_original_code:
static unsigned char Read_iNES0_Prg(struct icart *cart, unsigned short address) {
    struct ines_cart *c = (ines_cart *)cart;
    unsigned short index = ((address - 0x8000) / (16 * 1024)) % c->prg_pages;
    return c->prg_rom[index][(address - 0x8000) % (16 * 1024)];
}

variable_types: struct ines_cart { unsigned char type; unsigned char (*Read_Prg)(struct icart { unsigned char type; unsigned char (*Read_Prg)(struct icart *, unsigned short); unsigned char (*Read_Chr)(struct icart *, unsigned short); unsigned char (*Write_Prg)(struct icart *, unsigned short, unsigned char); unsigned char (*Write_Chr)(struct icart *, unsigned short, unsigned char); void (*Unload)(struct icart *); } *, unsigned short); unsigned char (*Read_Chr)(struct icart *, unsigned short); unsigned char (*Write_Prg)(struct icart *, unsigned short, unsigned char); unsigned char (*Write_Chr)(struct icart *, unsigned short, unsigned char); void (*Unload)(struct icart *); unsigned char mapper_id; unsigned char prg_pages; unsigned char chr_pages; unsigned char **prg_rom; unsigned char **chr_rom; unsigned char flags; unsigned char *trainer; } *

variable_types:
index
unsigned short

user_defined_types: struct ines_cart { unsigned char type; unsigned char (*Read_Prg)(struct icart *, unsigned short); unsigned char (*Read_Chr)(struct icart *, unsigned short); unsigned char (*Write_Prg)(struct icart *, unsigned short, unsigned char); unsigned char (*Write_Chr)(struct icart *, unsigned short, unsigned char); void (*Unload)(struct icart *); unsigned char mapper_id; unsigned char prg_pages; unsigned char chr_pages; unsigned char **prg_rom; unsigned char **chr_rom; unsigned char flags; unsigned char *trainer; }


decompiled_code:
__int64 __fastcall Read_iNES0_Chr(__int64 a1, unsigned __int16 a2)
{
return *(unsigned __int8 *)(*(_QWORD *)(*(_QWORD *)(a1 + 64) + 8LL * (a2 >> 13)) + (a2 & 0x3FFF));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int16 a2)
{
return *(unsigned __int8 *)(*(_QWORD *)(*(_QWORD *)(a1 + 64) + 8LL * (a2 >> 13)) + (a2 & 0x3FFF));
}

original_code:
static u8 Read_iNES0_Chr(icart *cart, u16 address) {
    ines_cart *c = (ines_cart *)cart;
    u16 index = (address / (8 * 1024));
    return c->chr_rom[index][address % (16 * 1024)];
}

canonical_original_code:
static unsigned char Read_iNES0_Chr(struct icart *cart, unsigned short address) {
    struct ines_cart *c = (ines_cart *)cart;
    unsigned short index = (address / (8 * 1024));
    return c->chr_rom[index][address % (16 * 1024)];
}

variable_types: struct icart { unsigned char type; unsigned char (*Read_Prg)(struct icart *, unsigned short); unsigned char (*Read_Chr)(struct icart *, unsigned short); unsigned char (*Write_Prg)(struct icart *, unsigned short, unsigned char); unsigned char (*Write_Chr)(struct icart *, unsigned short, unsigned char); void (*Unload)(struct icart *); } *


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

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

original_code:
static u8 Write_iNES0_Prg(icart *cart, u16 address, u8 value) {
    return 0;
}

canonical_original_code:
static unsigned char Write_iNES0_Prg(struct icart *cart, unsigned short address, unsigned char value) {
    return 0;
}

user_defined_types: struct icart { unsigned char type; unsigned char (*Read_Prg)(struct icart *, unsigned short); unsigned char (*Read_Chr)(struct icart *, unsigned short); unsigned char (*Write_Prg)(struct icart *, unsigned short, unsigned char); unsigned char (*Write_Chr)(struct icart *, unsigned short, unsigned char); void (*Unload)(struct icart *); }


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

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

original_code:
static u8 Write_iNES0_Chr(icart *cart, u16 address, u8 value) {
    return 0;
}

canonical_original_code:
static unsigned char Write_iNES0_Chr(struct icart *cart, unsigned short address, unsigned char value) {
    return 0;
}


original_code:
static void Free_iNES_Pages(ines_cart *cart) {
    u8 i;
    if (cart) {
        if (cart->prg_rom) {
            for (i = 0; i < cart->prg_pages; i++) {
                free(cart->prg_rom[i]);
            }
            free(cart->prg_rom);
        }
        if (cart->chr_rom) {
            for (i = 0; i < cart->chr_pages; i++) {
                free(cart->chr_rom[i]);
            }
            free(cart->chr_rom);
        }
    }
}

canonical_original_code:
static void Free_iNES_Pages(struct ines_cart *cart) {
    unsigned char i;
    if (cart) {
        if (cart->prg_rom) {
            for (i = 0; i < cart->prg_pages; i++) {
                free(cart->prg_rom[i]);
            }
            free(cart->prg_rom);
        }
        if (cart->chr_rom) {
            for (i = 0; i < cart->chr_pages; i++) {
                free(cart->chr_rom[i]);
            }
            free(cart->chr_rom);
        }
    }
}

variable_types:
i
unsigned char


decompiled_code:
void __fastcall Unload_iNES0(void *ptr)
{
Free_iNES_Pages((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
func4((__int64)ptr);
free(ptr);
}

original_code:
static void Unload_iNES0(icart *cart) {
    ines_cart *c = (ines_cart *)cart;
    Free_iNES_Pages(c);
    free(c);
}

canonical_original_code:
static void Unload_iNES0(struct icart *cart) {
    struct ines_cart *c = (ines_cart *)cart;
    Free_iNES_Pages(c);
    free(c);
}


decompiled_code:
__int64 Init_GL_2D()
{
glClearColor(0.0, 0.0, 0.0);
glShadeModel(7424LL);
return glPixelStorei(3317LL, 1LL);
}

canonical_decompiled_code:
__int64 func1()
{
glClearColor(0.0, 0.0, 0.0);
glShadeModel(7424LL);
return glPixelStorei(3317LL, 1LL);
}

original_code:
void Init_GL_2D(void) {
    glClearColor(.0, .0, .0, .0);
    glShadeModel(0x1D00);
    glPixelStorei(0x0CF5, 1);
}

canonical_original_code:
void Init_GL_2D() {
    glClearColor(.0, .0, .0, .0);
    glShadeModel(0x1D00);
    glPixelStorei(0x0CF5, 1);
}


decompiled_code:
__int64 __fastcall Test_GL_Render(unsigned int a1)
{
glClear(16640LL);
glEnable(3553LL);
glTexEnvf(8960LL, 8704LL, 7681.0);
if ( a1 )
{
glBindTexture(3553LL, a1);
glBegin(7LL);
glTexCoord2f(0.0);
glVertex3f(-1.0, 1.0, 0.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC2));
glVertex3f(1.0, 1.0, 0.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC2));
glVertex3f(1.0, -1.0, 0.0);
glTexCoord2f(0.0);
glVertex3f(-1.0, -1.0, 0.0);
glEnd();
}
return glDisable(3553LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
glClear(16640LL);
glEnable(3553LL);
glTexEnvf(8960LL, 8704LL, 7681.0);
if ( a1 )
{
glBindTexture(3553LL, a1);
glBegin(7LL);
glTexCoord2f(0.0);
glVertex3f(-1.0, 1.0, 0.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC2));
glVertex3f(1.0, 1.0, 0.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC2));
glVertex3f(1.0, -1.0, 0.0);
glTexCoord2f(0.0);
glVertex3f(-1.0, -1.0, 0.0);
glEnd();
}
return glDisable(3553LL);
}

original_code:
void Test_GL_Render(GLuint tex) {
    glClear(0x00004000 | 0x00000100);
    glEnable(0x0DE1);
    glTexEnvf(0x2300, 0x2200, 0x1E01);
    if (0 != tex) {
        glBindTexture(0x0DE1, tex);
        glBegin(0x0007);
            glTexCoord2f(0., 0.); glVertex3f(-1.0, 1.0, 0.);
            glTexCoord2f(1., 0.); glVertex3f( 1.0, 1.0, 0.);
            glTexCoord2f(1., 1.); glVertex3f( 1.0, -1.0, 0.);
            glTexCoord2f(0., 1.); glVertex3f(-1.0, -1.0, 0.);
        glEnd();
    }
    glDisable(0x0DE1);
}

canonical_original_code:
void Test_GL_Render(unsigned int tex) {
    glClear(0x00004000 | 0x00000100);
    glEnable(0x0DE1);
    glTexEnvf(0x2300, 0x2200, 0x1E01);
    if (0 != tex) {
        glBindTexture(0x0DE1, tex);
        glBegin(0x0007);
            glTexCoord2f(0., 0.); glVertex3f(-1.0, 1.0, 0.);
            glTexCoord2f(1., 0.); glVertex3f( 1.0, 1.0, 0.);
            glTexCoord2f(1., 1.); glVertex3f( 1.0, -1.0, 0.);
            glTexCoord2f(0., 1.); glVertex3f(-1.0, -1.0, 0.);
        glEnd();
    }
    glDisable(0x0DE1);
}

variable_types:
tex
unsigned int


variable_types:
line
unsigned short


original_code:
static void Render_Background(u16 *background) {
    u16 clip_amount;
    u16 i;
    u16 tile_no;
    u16 pattern_base;
    u16 pattern_offset;
    u8 nt_index,
       current_pixel,
       current_attr;
    pattern_base = ((ppu.ctrl) & (0x10)) ? 0x1000 : 0x0000;
    clip_amount = ((ppu.mask) & (0x02)) ? 0 : 8;
    for (i = 0; i < 264; i++) {
        if (i < clip_amount) goto update;
        nt_index = (ppu.v_addr >> 10) & 0x0003;
        tile_no = ppu.nt_map[nt_index][ppu.v_addr & 0x03FF];
        pattern_offset = pattern_base + (tile_no << 4) + ppu.scrolly;
        current_attr = ppu.nt_map[nt_index][0x03C0 + ((ppu.v_addr & 0x0380) >> 4) + ((ppu.v_addr & 0x001F) >> 2)];
        current_attr >>= ((ppu.v_addr & 0x0040) >> 4) | (ppu.v_addr & 0x0002);
        current_attr &= 0x03;
        current_pixel = ((Read_Cartridge_Chr(pattern_offset) >> (7 - ppu.scrollx)) & 1)
                       | (((Read_Cartridge_Chr(pattern_offset + 8) >> (7 - ppu.scrollx)) & 1) << 1)
                       | (current_attr << 2);
        if (current_pixel & 0x03) {
            background[i] = current_pixel | 0x3F00;
        }
update:
        ppu.scrollx++;
        if (8 == ppu.scrollx) {
            ppu.scrollx = 0;
            if ((ppu.v_addr & 0x001F) == 0x001F) {
                ppu.v_addr &= ~0x001F;
                ppu.v_addr ^= 0x0400;
            } else {
                ppu.v_addr++;
            }
        }
    }
     ppu.scrolly++;
    if (8 == ppu.scrolly) {
        register u16 y = (ppu.v_addr & 0x03E0) >> 5;
        ppu.scrolly = 0;
        if (y == 29) {
            y = 0;
            ppu.v_addr ^= 0x0800;
        } else if (y == 31) {
            y = 0;
        } else {
            y++;
        }
        ppu.v_addr = (ppu.v_addr & 0xFC1F) | (y << 5);
    }
    ppu.v_addr = (ppu.v_addr & 0x3BE0) | (ppu.t_addr & 0x041F);
}

canonical_original_code:
static void Render_Background(unsigned short *background) {
    unsigned short clip_amount;
    unsigned short i;
    unsigned short tile_no;
    unsigned short pattern_base;
    unsigned short pattern_offset;
    unsigned char nt_index; unsigned char current_pixel; unsigned char current_attr;
    pattern_base = ((ppu.ctrl) & (0x10)) ? 0x1000 : 0x0000;
    clip_amount = ((ppu.mask) & (0x02)) ? 0 : 8;
    for (i = 0; i < 264; i++) {
        if (i < clip_amount) goto update;
        nt_index = (ppu.v_addr >> 10) & 0x0003;
        tile_no = ppu.nt_map[nt_index][ppu.v_addr & 0x03FF];
        pattern_offset = pattern_base + (tile_no << 4) + ppu.scrolly;
        current_attr = ppu.nt_map[nt_index][0x03C0 + ((ppu.v_addr & 0x0380) >> 4) + ((ppu.v_addr & 0x001F) >> 2)];
        current_attr >>= ((ppu.v_addr & 0x0040) >> 4) | (ppu.v_addr & 0x0002);
        current_attr &= 0x03;
        current_pixel = ((Read_Cartridge_Chr(pattern_offset) >> (7 - ppu.scrollx)) & 1)
                       | (((Read_Cartridge_Chr(pattern_offset + 8) >> (7 - ppu.scrollx)) & 1) << 1)
                       | (current_attr << 2);
        if (current_pixel & 0x03) {
            background[i] = current_pixel | 0x3F00;
        }
update:
        ppu.scrollx++;
        if (8 == ppu.scrollx) {
            ppu.scrollx = 0;
            if ((ppu.v_addr & 0x001F) == 0x001F) {
                ppu.v_addr &= ~0x001F;
                ppu.v_addr ^= 0x0400;
            } else {
                ppu.v_addr++;
            }
        }
    }
     ppu.scrolly++;
    if (8 == ppu.scrolly) {
        register unsigned short y = (ppu.v_addr & 0x03E0) >> 5;
        ppu.scrolly = 0;
        if (y == 29) {
            y = 0;
            ppu.v_addr ^= 0x0800;
        } else if (y == 31) {
            y = 0;
        } else {
            y++;
        }
        ppu.v_addr = (ppu.v_addr & 0xFC1F) | (y << 5);
    }
    ppu.v_addr = (ppu.v_addr & 0x3BE0) | (ppu.t_addr & 0x041F);
}

variable_types:
background
unsigned short *

variable_types:
i
unsigned short

variable_types:
y
unsigned short


decompiled_code:
__int64 __fastcall Render_Scanline(__int16 a1)
{
__int64 result; // rax
unsigned int v2; // eax
_BYTE v3[1544]; // [rsp+0h] [rbp-608h] BYREF

result = 0LL;
memset(v3, 0, 0x400uLL);
if ( (*((_BYTE *)&ppu + 15) & 8) != 0 )
result = Render_Background((__int64)v3);
if ( a1 == -1 )
{
v2 = *((unsigned __int16 *)&ppu + 13);
LOWORD(v2) = v2 & 0x41F;
result = *((_WORD *)&ppu + 14) & 0xFBE0 | v2;
*((_WORD *)&ppu + 13) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1)
{
__int64 result; // rax
unsigned int v2; // eax
_BYTE v3[1544]; // [rsp+0h] [rbp-608h] BYREF

result = 0LL;
memset(v3, 0, 0x400uLL);
if ( (*((_BYTE *)&ppu + 15) & 8) != 0 )
result = func1((__int64)v3);
if ( a1 == -1 )
{
v2 = *((unsigned __int16 *)&ppu + 13);
LOWORD(v2) = v2 & 0x41F;
result = *((_WORD *)&ppu + 14) & 0xFBE0 | v2;
*((_WORD *)&ppu + 13) = result;
}
return result;
}

original_code:
void Render_Scanline(i16 scanline) {
    u16 render_buffer[256 * 3];
    u16 *background = render_buffer,
        *spr_back = render_buffer + 256,
        *spr_front = render_buffer + (2 * 256);
    bzero(render_buffer, 256 * 4);
    if (ppu.mask & 0x08) Render_Background(background);
    if (scanline > -1 && scanline < 240) {
        Composite_Scanline(scanline, background, spr_front, spr_back);
    } else if (scanline == -1) {
        ppu.v_addr = (ppu.v_addr & 0x041F) | (ppu.t_addr & ~0x041F);
    }
}

canonical_original_code:
void Render_Scanline(short scanline) {
    unsigned short render_buffer[-1];
    unsigned short *background = render_buffer; unsigned short *spr_back = render_buffer + 256; unsigned short *spr_front = render_buffer + (2 * 256);
    bzero(render_buffer, 256 * 4);
    if (ppu.mask & 0x08) Render_Background(background);
    if (scanline > -1 && scanline < 240) {
        Composite_Scanline(scanline, background, spr_front, spr_back);
    } else if (scanline == -1) {
        ppu.v_addr = (ppu.v_addr & 0x041F) | (ppu.t_addr & ~0x041F);
    }
}

variable_types: scanline short


decompiled_code:
__int64 Dump_Pattern_Tables()
{
unsigned __int16 v0; // r13
unsigned __int8 v1; // r12
int v2; // ebx
int v3; // ebp
__int16 v4; // r14
__int64 result; // rax
unsigned int v6; // [rsp+4h] [rbp-44h]
int i; // [rsp+8h] [rbp-40h]
unsigned int v8; // [rsp+Ch] [rbp-3Ch]

for ( i = 0; i != 32; i += 16 )
{
v6 = 16 * i;
v8 = v6 + 256;
do
{
v4 = 16 * v6 + 256;
do
{
v0 = v4 - 256;
do
{
v1 = Read_Cartridge_Chr(v0);
v2 = 7;
v3 = (unsigned __int8)Read_Cartridge_Chr((unsigned __int16)(v0 + 8));
do
{
fwrite(
(char *)&pt_palette + 4 * (((int)v1 >> v2) & 1 | (2 * (unsigned __int8)(v3 >> v2)) & 2u),
4uLL,
1uLL,
stdout);
--v2;
}
while ( v2 != -1 );
v0 += 16;
}
while ( v0 != v4 );
++v4;
}
while ( v4 != 16 * (_WORD)v6 + 264 );
v6 += 16;
result = v6;
}
while ( v6 != v8 );
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned __int16 v0; // r13
unsigned __int8 v1; // r12
int v2; // ebx
int v3; // ebp
__int16 v4; // r14
__int64 result; // rax
unsigned int v6; // [rsp+4h] [rbp-44h]
int i; // [rsp+8h] [rbp-40h]
unsigned int v8; // [rsp+Ch] [rbp-3Ch]

for ( i = 0; i != 32; i += 16 )
{
v6 = 16 * i;
v8 = v6 + 256;
do
{
v4 = 16 * v6 + 256;
do
{
v0 = v4 - 256;
do
{
v1 = Read_Cartridge_Chr(v0);
v2 = 7;
v3 = (unsigned __int8)Read_Cartridge_Chr((unsigned __int16)(v0 + 8));
do
{
fwrite(
(char *)&pt_palette + 4 * (((int)v1 >> v2) & 1 | (2 * (unsigned __int8)(v3 >> v2)) & 2u),
4uLL,
1uLL,
stdout);
--v2;
}
while ( v2 != -1 );
v0 += 16;
}
while ( v0 != v4 );
++v4;
}
while ( v4 != 16 * (_WORD)v6 + 264 );
v6 += 16;
result = v6;
}
while ( v6 != v8 );
}
return result;
}

canonical_original_code:
void Dump_Pattern_Tables() {
    unsigned short base = 0; unsigned short i; unsigned short j;
    short x; short y;
    for (base = 0; base < 2; base++) {
        for (i = 0; i < 16; i++) {
            for (y = 0; y < 8; y++) {
                for (j = 0; j < 16; j++) {
                    unsigned char t1 = Read_Cartridge_Chr((base * 0x1000) + (i * 0x100) + (j * 0x10) + y);
                    unsigned char t2 = Read_Cartridge_Chr((base * 0x1000) + (i * 0x100) + (j * 0x10) + 8 + y);
                    for (x = 7; x > -1; x--) {
                        unsigned char index = (t1 >> (x) & 1) | (((t2 >> x) & 1) << 1);
                        fwrite(pt_palette + index, sizeof(u32), 1, stdout);
                    }
                }
            }
        }
    }
}

variable_types:
base
unsigned short

variable_types:
j
unsigned short

variable_types: x short

variable_types: y short


sqr

repo: VerebLaszlo/waveform

decompiled_code:
double __fastcall sqr(double a1)
{
return a1 * a1;
}

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

original_code:
double sqr(double a) {
 return a * a;
}

canonical_original_code:
double sqr(double a) {
 return a * a;
}

variable_types: a double

return_type: double


original_code:
long round_pow2(double num) {
 register double temp = log(num) / 0.69314718055994530942;
 return (long) exp2(ceil(temp));
 return (long) exp(ceil(temp) * 0.69314718055994530942);
}

variable_types: num double

variable_types: temp double

return_type: long


decompiled_code:
unsigned __int64 __fastcall multi_Min(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
unsigned __int64 *v3; // rax
unsigned __int64 *v4; // rsi

v2 = *a1;
if ( a2 > 1 )
{
v3 = a1 + 1;
v4 = &a1[a2];
do
{
if ( v2 > *v3 )
v2 = *v3;
++v3;
}
while ( v3 != v4 );
}
return v2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
unsigned __int64 *v3; // rax
unsigned __int64 *v4; // rsi

v2 = *a1;
if ( a2 > 1 )
{
v3 = a1 + 1;
v4 = &a1[a2];
do
{
if ( v2 > *v3 )
v2 = *v3;
++v3;
}
while ( v3 != v4 );
}
return v2;
}

original_code:
size_t multi_Min(size_t array[], size_t length) {
 size_t i, min = array[0];
 for (i = 1; i < length; i++) {
  min = min < array[i] ? min : array[i];
 }
 return min;
}

canonical_original_code:
unsigned long multi_Min(unsigned long array[], unsigned long length) {
 unsigned long i; unsigned long min = array[0];
 for (i = 1; i < length; i++) {
  min = min < array[i] ? min : array[i];
 }
 return min;
}

variable_types:
array
unsigned long []

variable_types:
length
unsigned long

variable_types:
i
unsigned long

variable_types:
min
unsigned long

return_type: unsigned long


decompiled_code:
unsigned __int64 __fastcall multi_Max(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
unsigned __int64 *v3; // rax
unsigned __int64 *v4; // rsi

v2 = *a1;
if ( a2 > 1 )
{
v3 = a1 + 1;
v4 = &a1[a2];
do
{
if ( v2 < *v3 )
v2 = *v3;
++v3;
}
while ( v3 != v4 );
}
return v2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
unsigned __int64 *v3; // rax
unsigned __int64 *v4; // rsi

v2 = *a1;
if ( a2 > 1 )
{
v3 = a1 + 1;
v4 = &a1[a2];
do
{
if ( v2 < *v3 )
v2 = *v3;
++v3;
}
while ( v3 != v4 );
}
return v2;
}

original_code:
size_t multi_Max(size_t array[], size_t length) {
 size_t i, max = array[0];
 for (i = 1; i < length; i++) {
  max = max > array[i] ? max : array[i];
 }
 return max;
}

canonical_original_code:
unsigned long multi_Max(unsigned long array[], unsigned long length) {
 unsigned long i; unsigned long max = array[0];
 for (i = 1; i < length; i++) {
  max = max > array[i] ? max : array[i];
 }
 return max;
}

variable_types:
max
unsigned long


decompiled_code:
double __fastcall scalar_Product3(double *a1, double *a2)
{
return *a1 * *a2 + a1[1] * a2[1] + a1[2] * a2[2];
}

canonical_decompiled_code:
double __fastcall func4(double *a1, double *a2)
{
return *a1 * *a2 + a1[1] * a2[1] + a1[2] * a2[2];
}

original_code:
double scalar_Product3(const double a1[3], const double a2[3]) {
 return a1[0] * a2[0] + a1[1] * a2[1] + a1[2] * a2[2];
}

canonical_original_code:
double scalar_Product3(double a1[3], double a2[3]) {
 return a1[0] * a2[0] + a1[1] * a2[1] + a1[2] * a2[2];
}


original_code:
void vector_product3(const double left[3], const double right[3],
  double weight, double product[3]) {
 product[0] = weight * (left[1] * right[2] - left[2] * right[1]);
 product[1] = weight * (left[2] * right[0] - left[0] * right[2]);
 product[2] = weight * (left[0] * right[1] - left[1] * right[0]);
}

canonical_original_code:
void vector_product3(double left[3], double right[3], double weight, double product[3]) {
 product[0] = weight * (left[1] * right[2] - left[2] * right[1]);
 product[1] = weight * (left[2] * right[0] - left[0] * right[2]);
 product[2] = weight * (left[0] * right[1] - left[1] * right[0]);
}

variable_types:
left
double [3]

variable_types:
right
double [3]

variable_types: weight double

variable_types:
product
double [3]


setup

repo: VjiaoBlack/terminvaders

decompiled_code:
__int64 setup()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
xt_par0("\x1B[2J");
return load_rc();
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
xt_par0("\x1B[2J");
return load_rc();
}

original_code:
static void setup(void) {
    srand(time(((void *)0)));
    xt_par0("\033[2J");
    load_rc();
}

canonical_original_code:
static void setup() {
    srand(time(((void *)0)));
    xt_par0("\033[2J");
    load_rc();
}


drawmenu

decompiled_code:
__int64 __fastcall drawmenu(int a1)
{
int v1; // ebx
unsigned int i; // ebp
unsigned int v3; // eax
unsigned int j; // ebp
unsigned int v5; // eax
int v6; // ebx
int v7; // eax
int v8; // ebx
int v9; // eax
int v10; // ebp
int v11; // ebx
int v12; // eax
int v13; // ebp
int v14; // ebx
int v15; // eax
int v16; // ebp
int v17; // ebx
int v18; // eax
int v19; // ebp
int v20; // ebx
int v21; // eax
unsigned int v22; // ebx
unsigned int v23; // eax
int v24; // ebp
int v25; // ebx
int v26; // eax
unsigned int v27; // ebx
unsigned int v28; // eax
int v29; // ebx
int v30; // eax
unsigned int v31; // ebx
unsigned int v32; // eax
int v34; // ebp
int v35; // ebx
int v36; // eax
unsigned int v37; // ebx
unsigned int v38; // eax

xt_par2("\x1B[%d;%dH", 1LL, 1LL);
v1 = 0;
for ( i = 1; (int)get_cols() >= (int)i; ++i )
{
xt_par2("\x1B[%d;%dH", 1LL, i);
putchar(126);
v3 = get_rows();
xt_par2("\x1B[%d;%dH", v3, i);
putchar(126);
if ( v1 == 3 )
v1 = 0;
++v1;
}
for ( j = 2; (int)get_rows() > (int)j; ++j )
{
xt_par2("\x1B[%d;%dH", j, 1LL);
putchar(35);
v5 = get_cols();
xt_par2("\x1B[%d;%dH", j, v5);
putchar(35);
if ( v1 == 3 )
v1 = 0;
++v1;
}
xt_par0("\x1B[1m");
xt_par0("\x1B[33m");
v6 = get_cols();
v7 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v7 / 4), (unsigned int)(v6 / 2 - 11));
printf("-~<[ terminvaders ]>~-");
xt_par0("\x1B[39m");
v8 = get_cols();
v9 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v9 / 2), (unsigned int)(v8 / 2 - 6));
xt_par0("\x1B[32m");
printf("Single Player");
v10 = get_cols();
v11 = get_rows();
v12 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v11 / 2 + 2 * (v12 / 10)), (unsigned int)(v10 / 2 - 4));
xt_par0("\x1B[37m");
printf("Settings");
v13 = get_cols();
v14 = get_rows();
v15 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v14 / 2 + 3 * (v15 / 10)), (unsigned int)(v13 / 2 - 2));
xt_par0("\x1B[31m");
printf("Quit");
v16 = get_cols();
v17 = get_rows();
v18 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v17 / 2 + v18 / 10), (unsigned int)(v16 / 2 - 5));
xt_par0("\x1B[31m");
xt_par0("\x1B[1m");
putchar(77);
xt_par0("\x1B[33m");
putchar(117);
xt_par0("\x1B[32m");
putchar(76);
xt_par0("\x1B[36m");
putchar(116);
xt_par0("\x1B[34m");
putchar(73);
xt_par0("\x1B[35m");
putchar(112);
xt_par0("\x1B[31m");
putchar(76);
xt_par0("\x1B[33m");
putchar(97);
xt_par0("\x1B[32m");
putchar(89);
xt_par0("\x1B[36m");
putchar(101);
xt_par0("\x1B[34m");
putchar(82);
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
if ( a1 == 2 )
{
v34 = get_cols();
v35 = get_rows();
v36 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v35 / 2 + 2 * (v36 / 10)), (unsigned int)(v34 / 2 - 4));
xt_par0("\x1B[37m");
xt_par0("\x1B[1m");
printf("Settings");
v37 = get_cols();
v38 = get_rows();
xt_par2("\x1B[%d;%dH", v38, v37);
}
else if ( a1 > 2 )
{
if ( a1 == 3 )
{
v24 = get_cols();
v25 = get_rows();
v26 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v25 / 2 + 3 * (v26 / 10)), (unsigned int)(v24 / 2 - 2));
xt_par0("\x1B[31m");
printf("Quit");
v27 = get_cols();
v28 = get_rows();
xt_par2("\x1B[%d;%dH", v28, v27);
}
}
else if ( a1 )
{
if ( a1 == 1 )
{
v19 = get_cols();
v20 = get_rows();
v21 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v20 / 2 + v21 / 10), (unsigned int)(v19 / 2 - 5));
xt_par0("\x1B[31m");
xt_par0("\x1B[1m");
putchar(77);
xt_par0("\x1B[33m");
putchar(117);
xt_par0("\x1B[32m");
putchar(76);
xt_par0("\x1B[36m");
putchar(116);
xt_par0("\x1B[34m");
putchar(73);
xt_par0("\x1B[35m");
putchar(112);
xt_par0("\x1B[31m");
putchar(76);
xt_par0("\x1B[33m");
putchar(97);
xt_par0("\x1B[32m");
putchar(89);
xt_par0("\x1B[36m");
putchar(101);
xt_par0("\x1B[34m");
putchar(82);
v22 = get_cols();
v23 = get_rows();
xt_par2("\x1B[%d;%dH", v23, v22);
}
}
else
{
v29 = get_cols();
v30 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v30 / 2), (unsigned int)(v29 / 2 - 6));
xt_par0("\x1B[32m");
printf("Single Player");
v31 = get_cols();
v32 = get_rows();
xt_par2("\x1B[%d;%dH", v32, v31);
}
return xt_par0("\x1B[0m");
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // ebx
unsigned int i; // ebp
unsigned int v3; // eax
unsigned int j; // ebp
unsigned int v5; // eax
int v6; // ebx
int v7; // eax
int v8; // ebx
int v9; // eax
int v10; // ebp
int v11; // ebx
int v12; // eax
int v13; // ebp
int v14; // ebx
int v15; // eax
int v16; // ebp
int v17; // ebx
int v18; // eax
int v19; // ebp
int v20; // ebx
int v21; // eax
unsigned int v22; // ebx
unsigned int v23; // eax
int v24; // ebp
int v25; // ebx
int v26; // eax
unsigned int v27; // ebx
unsigned int v28; // eax
int v29; // ebx
int v30; // eax
unsigned int v31; // ebx
unsigned int v32; // eax
int v34; // ebp
int v35; // ebx
int v36; // eax
unsigned int v37; // ebx
unsigned int v38; // eax

xt_par2("\x1B[%d;%dH", 1LL, 1LL);
v1 = 0;
for ( i = 1; (int)get_cols() >= (int)i; ++i )
{
xt_par2("\x1B[%d;%dH", 1LL, i);
putchar(126);
v3 = get_rows();
xt_par2("\x1B[%d;%dH", v3, i);
putchar(126);
if ( v1 == 3 )
v1 = 0;
++v1;
}
for ( j = 2; (int)get_rows() > (int)j; ++j )
{
xt_par2("\x1B[%d;%dH", j, 1LL);
putchar(35);
v5 = get_cols();
xt_par2("\x1B[%d;%dH", j, v5);
putchar(35);
if ( v1 == 3 )
v1 = 0;
++v1;
}
xt_par0("\x1B[1m");
xt_par0("\x1B[33m");
v6 = get_cols();
v7 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v7 / 4), (unsigned int)(v6 / 2 - 11));
printf("-~<[ terminvaders ]>~-");
xt_par0("\x1B[39m");
v8 = get_cols();
v9 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v9 / 2), (unsigned int)(v8 / 2 - 6));
xt_par0("\x1B[32m");
printf("Single Player");
v10 = get_cols();
v11 = get_rows();
v12 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v11 / 2 + 2 * (v12 / 10)), (unsigned int)(v10 / 2 - 4));
xt_par0("\x1B[37m");
printf("Settings");
v13 = get_cols();
v14 = get_rows();
v15 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v14 / 2 + 3 * (v15 / 10)), (unsigned int)(v13 / 2 - 2));
xt_par0("\x1B[31m");
printf("Quit");
v16 = get_cols();
v17 = get_rows();
v18 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v17 / 2 + v18 / 10), (unsigned int)(v16 / 2 - 5));
xt_par0("\x1B[31m");
xt_par0("\x1B[1m");
putchar(77);
xt_par0("\x1B[33m");
putchar(117);
xt_par0("\x1B[32m");
putchar(76);
xt_par0("\x1B[36m");
putchar(116);
xt_par0("\x1B[34m");
putchar(73);
xt_par0("\x1B[35m");
putchar(112);
xt_par0("\x1B[31m");
putchar(76);
xt_par0("\x1B[33m");
putchar(97);
xt_par0("\x1B[32m");
putchar(89);
xt_par0("\x1B[36m");
putchar(101);
xt_par0("\x1B[34m");
putchar(82);
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
if ( a1 == 2 )
{
v34 = get_cols();
v35 = get_rows();
v36 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v35 / 2 + 2 * (v36 / 10)), (unsigned int)(v34 / 2 - 4));
xt_par0("\x1B[37m");
xt_par0("\x1B[1m");
printf("Settings");
v37 = get_cols();
v38 = get_rows();
xt_par2("\x1B[%d;%dH", v38, v37);
}
else if ( a1 > 2 )
{
if ( a1 == 3 )
{
v24 = get_cols();
v25 = get_rows();
v26 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v25 / 2 + 3 * (v26 / 10)), (unsigned int)(v24 / 2 - 2));
xt_par0("\x1B[31m");
printf("Quit");
v27 = get_cols();
v28 = get_rows();
xt_par2("\x1B[%d;%dH", v28, v27);
}
}
else if ( a1 )
{
if ( a1 == 1 )
{
v19 = get_cols();
v20 = get_rows();
v21 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v20 / 2 + v21 / 10), (unsigned int)(v19 / 2 - 5));
xt_par0("\x1B[31m");
xt_par0("\x1B[1m");
putchar(77);
xt_par0("\x1B[33m");
putchar(117);
xt_par0("\x1B[32m");
putchar(76);
xt_par0("\x1B[36m");
putchar(116);
xt_par0("\x1B[34m");
putchar(73);
xt_par0("\x1B[35m");
putchar(112);
xt_par0("\x1B[31m");
putchar(76);
xt_par0("\x1B[33m");
putchar(97);
xt_par0("\x1B[32m");
putchar(89);
xt_par0("\x1B[36m");
putchar(101);
xt_par0("\x1B[34m");
putchar(82);
v22 = get_cols();
v23 = get_rows();
xt_par2("\x1B[%d;%dH", v23, v22);
}
}
else
{
v29 = get_cols();
v30 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v30 / 2), (unsigned int)(v29 / 2 - 6));
xt_par0("\x1B[32m");
printf("Single Player");
v31 = get_cols();
v32 = get_rows();
xt_par2("\x1B[%d;%dH", v32, v31);
}
return xt_par0("\x1B[0m");
}

variable_types: choice int

variable_types: test int

variable_types: lim int


clear

decompiled_code:
__int64 clear()
{
int i; // ebp
int j; // ebx
__int64 result; // rax

for ( i = 1; ; ++i )
{
result = get_rows();
if ( (int)result < i )
break;
xt_par2("\x1B[%d;%dH", (unsigned int)i, 1LL);
for ( j = 1; (int)get_cols() >= j; ++j )
putchar(32);
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int i; // ebp
int j; // ebx
__int64 result; // rax

for ( i = 1; ; ++i )
{
result = get_rows();
if ( (int)result < i )
break;
xt_par2("\x1B[%d;%dH", (unsigned int)i, 1LL);
for ( j = 1; (int)get_cols() >= j; ++j )
putchar(32);
}
return result;
}

original_code:
static void clear(void) {
    int r, c;
    for (r = 1; r <= get_rows(); r++) {
        xt_par2("\033[%d;%dH", (r), (1));
        for (c = 1; c <= get_cols(); c++)
            putchar(' ');
    }
}

canonical_original_code:
static void clear() {
    int r; int c;
    for (r = 1; r <= get_rows(); r++) {
        xt_par2("\033[%d;%dH", (r), (1));
        for (c = 1; c <= get_cols(); c++)
            putchar(' ');
    }
}

variable_types: r int

variable_types: c int


menu

decompiled_code:
__int64 menu()
{
void *v0; // rbp
unsigned int v1; // ebx
unsigned int v2; // eax
int v3; // er12
int v4; // er12
int v5; // ebx
int v6; // eax
int v7; // ebx
int v8; // eax
int v9; // er12
int v10; // ebx
int v11; // eax
int v12; // er12
int v13; // ebx
int v14; // eax
int v15; // ebx
int v16; // eax
unsigned int v17; // ebx
unsigned int v18; // eax
int v19; // er12
int v20; // ebx
int v21; // eax
unsigned int v22; // ebx
unsigned int v23; // eax
int v24; // ebx
int v25; // eax
int v26; // er12
int v27; // ebx
int v28; // eax
int v29; // er12
int v30; // ebx
int v31; // eax
int v32; // er12
int v33; // ebx
int v34; // eax
int v35; // ebx
int v36; // eax
unsigned int v37; // ebx
unsigned int v38; // eax
int v39; // ebx
int v40; // eax
int v41; // er13
int v42; // ebx
int v43; // eax
int v44; // er12
int v45; // ebx
int v46; // eax
unsigned int v47; // ebx
unsigned int v48; // eax

clear();
drawmenu(0);
v0 = malloc(0xE10uLL);
init(v0);
v1 = get_cols();
v2 = get_rows();
xt_par2("\x1B[%d;%dH", v2, v1);
v3 = 0;
while ( 1 )
{
v24 = 12;
do
{
update(v0);
--v24;
}
while ( v24 );
display(v0);
drawmenu(v3);
v25 = getkey();
if ( v25 == 113 )
break;
if ( v25 > 113 )
{
if ( v25 == 115 )
goto LABEL_26;
if ( v25 == 119 )
{
LABEL_21:
xt_par0("\x1B[39m");
if ( v3 != 2 )
{
if ( v3 <= 2 )
{
if ( v3 )
{
if ( v3 == 1 )
{
v26 = get_cols();
v27 = get_rows();
v28 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v28 / 10 + v27 / 2), (unsigned int)(v26 / 2 - 5));
xt_par0("\x1B[31m");
xt_par0("\x1B[1m");
putchar(77);
xt_par0("\x1B[33m");
putchar(117);
xt_par0("\x1B[32m");
putchar(76);
xt_par0("\x1B[36m");
putchar(116);
xt_par0("\x1B[34m");
putchar(73);
xt_par0("\x1B[35m");
putchar(112);
xt_par0("\x1B[31m");
putchar(76);
xt_par0("\x1B[33m");
putchar(97);
xt_par0("\x1B[32m");
putchar(89);
xt_par0("\x1B[36m");
putchar(101);
xt_par0("\x1B[34m");
putchar(82);
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
v15 = get_cols();
v16 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v16 / 2), (unsigned int)(v15 / 2 - 6));
xt_par0("\x1B[32m");
printf("Single Player");
v17 = get_cols();
v18 = get_rows();
xt_par2("\x1B[%d;%dH", v18, v17);
v3 = 0;
goto LABEL_11;
}
}
else
{
v7 = get_cols();
v8 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v8 / 2), (unsigned int)(v7 / 2 - 6));
xt_par0("\x1B[32m");
printf("Single Player");
}
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
LABEL_39:
v44 = get_cols();
v45 = get_rows();
v46 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v45 / 2 + 3 * (v46 / 10)), (unsigned int)(v44 / 2 - 2));
xt_par0("\x1B[31m");
printf("Quit");
v47 = get_cols();
v48 = get_rows();
xt_par2("\x1B[%d;%dH", v48, v47);
v3 = 3;
goto LABEL_11;
}
v4 = get_cols();
v5 = get_rows();
v6 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v5 / 2 + 3 * (v6 / 10)), (unsigned int)(v4 / 2 - 2));
xt_par0("\x1B[31m");
printf("Quit");
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
LABEL_10:
v19 = get_cols();
v20 = get_rows();
v21 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v20 / 2 + 2 * (v21 / 10)), (unsigned int)(v19 / 2 - 4));
xt_par0("\x1B[37m");
xt_par0("\x1B[1m");
printf("Settings");
v22 = get_cols();
v23 = get_rows();
xt_par2("\x1B[%d;%dH", v23, v22);
v3 = 2;
LABEL_11:
xt_par0("\x1B[0m");
goto LABEL_12;
}
v9 = get_cols();
v10 = get_rows();
v11 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v10 / 2 + 2 * (v11 / 10)), (unsigned int)(v9 / 2 - 4));
xt_par0("\x1B[37m");
printf("Settings");
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
LABEL_9:
v12 = get_cols();
v13 = get_rows();
v14 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v14 / 10 + v13 / 2), (unsigned int)(v12 / 2 - 5));
xt_par0("\x1B[31m");
xt_par0("\x1B[1m");
putchar(77);
xt_par0("\x1B[33m");
putchar(117);
xt_par0("\x1B[32m");
putchar(76);
xt_par0("\x1B[36m");
putchar(116);
xt_par0("\x1B[34m");
putchar(73);
xt_par0("\x1B[35m");
putchar(112);
xt_par0("\x1B[31m");
putchar(76);
xt_par0("\x1B[33m");
putchar(97);
xt_par0("\x1B[32m");
putchar(89);
xt_par0("\x1B[36m");
putchar(101);
xt_par0("\x1B[34m");
putchar(82);
v3 = 1;
goto LABEL_11;
}
}
else
{
if ( v25 == 10 )
return (unsigned int)v3;
if ( v25 <= 10 )
{
if ( v25 == -11 )
{
LABEL_26:
xt_par0("\x1B[39m");
if ( v3 != 2 )
{
if ( v3 > 2 )
{
v32 = get_cols();
v33 = get_rows();
v34 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v33 / 2 + 3 * (v34 / 10)), (unsigned int)(v32 / 2 - 2));
xt_par0("\x1B[31m");
printf("Quit");
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
}
else
{
if ( !v3 )
{
v39 = get_cols();
v40 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v40 / 2), (unsigned int)(v39 / 2 - 6));
xt_par0("\x1B[32m");
printf("Single Player");
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
goto LABEL_9;
}
if ( v3 == 1 )
{
v29 = get_cols();
v30 = get_rows();
v31 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v31 / 10 + v30 / 2), (unsigned int)(v29 / 2 - 5));
xt_par0("\x1B[31m");
xt_par0("\x1B[1m");
putchar(77);
xt_par0("\x1B[33m");
putchar(117);
xt_par0("\x1B[32m");
putchar(76);
xt_par0("\x1B[36m");
putchar(116);
xt_par0("\x1B[34m");
putchar(73);
xt_par0("\x1B[35m");
putchar(112);
xt_par0("\x1B[31m");
putchar(76);
xt_par0("\x1B[33m");
putchar(97);
xt_par0("\x1B[32m");
putchar(89);
xt_par0("\x1B[36m");
putchar(101);
xt_par0("\x1B[34m");
putchar(82);
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
goto LABEL_10;
}
LABEL_37:
++v3;
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
if ( v3 == 2 )
goto LABEL_10;
if ( v3 > 2 )
goto LABEL_39;
if ( v3 )
{
if ( v3 != 1 )
goto LABEL_11;
goto LABEL_9;
}
}
v35 = get_cols();
v36 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v36 / 2), (unsigned int)(v35 / 2 - 6));
xt_par0("\x1B[32m");
printf("Single Player");
v37 = get_cols();
v38 = get_rows();
xt_par2("\x1B[%d;%dH", v38, v37);
v3 = 0;
goto LABEL_11;
}
v41 = get_cols();
v42 = get_rows();
v43 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v42 / 2 + 2 * (v43 / 10)), (unsigned int)(v41 / 2 - 4));
xt_par0("\x1B[37m");
printf("Settings");
goto LABEL_37;
}
if ( v25 == -10 )
goto LABEL_21;
}
}
LABEL_12:
fflush(stdout);
usleep(0xC350u);
}
return 3;
}

canonical_decompiled_code:
__int64 func3()
{
void *v0; // rbp
unsigned int v1; // ebx
unsigned int v2; // eax
int v3; // er12
int v4; // er12
int v5; // ebx
int v6; // eax
int v7; // ebx
int v8; // eax
int v9; // er12
int v10; // ebx
int v11; // eax
int v12; // er12
int v13; // ebx
int v14; // eax
int v15; // ebx
int v16; // eax
unsigned int v17; // ebx
unsigned int v18; // eax
int v19; // er12
int v20; // ebx
int v21; // eax
unsigned int v22; // ebx
unsigned int v23; // eax
int v24; // ebx
int v25; // eax
int v26; // er12
int v27; // ebx
int v28; // eax
int v29; // er12
int v30; // ebx
int v31; // eax
int v32; // er12
int v33; // ebx
int v34; // eax
int v35; // ebx
int v36; // eax
unsigned int v37; // ebx
unsigned int v38; // eax
int v39; // ebx
int v40; // eax
int v41; // er13
int v42; // ebx
int v43; // eax
int v44; // er12
int v45; // ebx
int v46; // eax
unsigned int v47; // ebx
unsigned int v48; // eax

func2();
func1(0);
v0 = malloc(0xE10uLL);
init(v0);
v1 = get_cols();
v2 = get_rows();
xt_par2("\x1B[%d;%dH", v2, v1);
v3 = 0;
while ( 1 )
{
v24 = 12;
do
{
update(v0);
--v24;
}
while ( v24 );
display(v0);
func1(v3);
v25 = getkey();
if ( v25 == 113 )
break;
if ( v25 > 113 )
{
if ( v25 == 115 )
goto LABEL_26;
if ( v25 == 119 )
{
LABEL_21:
xt_par0("\x1B[39m");
if ( v3 != 2 )
{
if ( v3 <= 2 )
{
if ( v3 )
{
if ( v3 == 1 )
{
v26 = get_cols();
v27 = get_rows();
v28 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v28 / 10 + v27 / 2), (unsigned int)(v26 / 2 - 5));
xt_par0("\x1B[31m");
xt_par0("\x1B[1m");
putchar(77);
xt_par0("\x1B[33m");
putchar(117);
xt_par0("\x1B[32m");
putchar(76);
xt_par0("\x1B[36m");
putchar(116);
xt_par0("\x1B[34m");
putchar(73);
xt_par0("\x1B[35m");
putchar(112);
xt_par0("\x1B[31m");
putchar(76);
xt_par0("\x1B[33m");
putchar(97);
xt_par0("\x1B[32m");
putchar(89);
xt_par0("\x1B[36m");
putchar(101);
xt_par0("\x1B[34m");
putchar(82);
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
v15 = get_cols();
v16 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v16 / 2), (unsigned int)(v15 / 2 - 6));
xt_par0("\x1B[32m");
printf("Single Player");
v17 = get_cols();
v18 = get_rows();
xt_par2("\x1B[%d;%dH", v18, v17);
v3 = 0;
goto LABEL_11;
}
}
else
{
v7 = get_cols();
v8 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v8 / 2), (unsigned int)(v7 / 2 - 6));
xt_par0("\x1B[32m");
printf("Single Player");
}
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
LABEL_39:
v44 = get_cols();
v45 = get_rows();
v46 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v45 / 2 + 3 * (v46 / 10)), (unsigned int)(v44 / 2 - 2));
xt_par0("\x1B[31m");
printf("Quit");
v47 = get_cols();
v48 = get_rows();
xt_par2("\x1B[%d;%dH", v48, v47);
v3 = 3;
goto LABEL_11;
}
v4 = get_cols();
v5 = get_rows();
v6 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v5 / 2 + 3 * (v6 / 10)), (unsigned int)(v4 / 2 - 2));
xt_par0("\x1B[31m");
printf("Quit");
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
LABEL_10:
v19 = get_cols();
v20 = get_rows();
v21 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v20 / 2 + 2 * (v21 / 10)), (unsigned int)(v19 / 2 - 4));
xt_par0("\x1B[37m");
xt_par0("\x1B[1m");
printf("Settings");
v22 = get_cols();
v23 = get_rows();
xt_par2("\x1B[%d;%dH", v23, v22);
v3 = 2;
LABEL_11:
xt_par0("\x1B[0m");
goto LABEL_12;
}
v9 = get_cols();
v10 = get_rows();
v11 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v10 / 2 + 2 * (v11 / 10)), (unsigned int)(v9 / 2 - 4));
xt_par0("\x1B[37m");
printf("Settings");
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
LABEL_9:
v12 = get_cols();
v13 = get_rows();
v14 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v14 / 10 + v13 / 2), (unsigned int)(v12 / 2 - 5));
xt_par0("\x1B[31m");
xt_par0("\x1B[1m");
putchar(77);
xt_par0("\x1B[33m");
putchar(117);
xt_par0("\x1B[32m");
putchar(76);
xt_par0("\x1B[36m");
putchar(116);
xt_par0("\x1B[34m");
putchar(73);
xt_par0("\x1B[35m");
putchar(112);
xt_par0("\x1B[31m");
putchar(76);
xt_par0("\x1B[33m");
putchar(97);
xt_par0("\x1B[32m");
putchar(89);
xt_par0("\x1B[36m");
putchar(101);
xt_par0("\x1B[34m");
putchar(82);
v3 = 1;
goto LABEL_11;
}
}
else
{
if ( v25 == 10 )
return (unsigned int)v3;
if ( v25 <= 10 )
{
if ( v25 == -11 )
{
LABEL_26:
xt_par0("\x1B[39m");
if ( v3 != 2 )
{
if ( v3 > 2 )
{
v32 = get_cols();
v33 = get_rows();
v34 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v33 / 2 + 3 * (v34 / 10)), (unsigned int)(v32 / 2 - 2));
xt_par0("\x1B[31m");
printf("Quit");
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
}
else
{
if ( !v3 )
{
v39 = get_cols();
v40 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v40 / 2), (unsigned int)(v39 / 2 - 6));
xt_par0("\x1B[32m");
printf("Single Player");
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
goto LABEL_9;
}
if ( v3 == 1 )
{
v29 = get_cols();
v30 = get_rows();
v31 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v31 / 10 + v30 / 2), (unsigned int)(v29 / 2 - 5));
xt_par0("\x1B[31m");
xt_par0("\x1B[1m");
putchar(77);
xt_par0("\x1B[33m");
putchar(117);
xt_par0("\x1B[32m");
putchar(76);
xt_par0("\x1B[36m");
putchar(116);
xt_par0("\x1B[34m");
putchar(73);
xt_par0("\x1B[35m");
putchar(112);
xt_par0("\x1B[31m");
putchar(76);
xt_par0("\x1B[33m");
putchar(97);
xt_par0("\x1B[32m");
putchar(89);
xt_par0("\x1B[36m");
putchar(101);
xt_par0("\x1B[34m");
putchar(82);
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
goto LABEL_10;
}
LABEL_37:
++v3;
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
if ( v3 == 2 )
goto LABEL_10;
if ( v3 > 2 )
goto LABEL_39;
if ( v3 )
{
if ( v3 != 1 )
goto LABEL_11;
goto LABEL_9;
}
}
v35 = get_cols();
v36 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v36 / 2), (unsigned int)(v35 / 2 - 6));
xt_par0("\x1B[32m");
printf("Single Player");
v37 = get_cols();
v38 = get_rows();
xt_par2("\x1B[%d;%dH", v38, v37);
v3 = 0;
goto LABEL_11;
}
v41 = get_cols();
v42 = get_rows();
v43 = get_rows();
xt_par2("\x1B[%d;%dH", (unsigned int)(v42 / 2 + 2 * (v43 / 10)), (unsigned int)(v41 / 2 - 4));
xt_par0("\x1B[37m");
printf("Settings");
goto LABEL_37;
}
if ( v25 == -10 )
goto LABEL_21;
}
}
LABEL_12:
fflush(stdout);
usleep(0xC350u);
}
return 3;
}

canonical_original_code:
static int menu() {
    clear();
    drawmenu(0);
    struct star_t *stars = malloc(sizeof(star_t) * 100);
    init(stars);
    int frame;
    int key; int choice = 0;
    xt_par2("\033[%d;%dH", (get_rows()), (get_cols()));
    while (1) {
        for (frame = 0; frame < 240 / 20; frame++)
            update(stars);
        display(stars);
        drawmenu(choice);
        switch ((key = getkey())) {
        case -10:
        case 'w':
            xt_par0("\033[39m");
            switch (choice) {
                case 0:
                    xt_par2("\033[%d;%dH", (get_rows() / 2), (get_cols() / 2 - 6));
                    xt_par0("\033[32m");
                    printf("Single Player");
                    break;
                case 2:
                    xt_par2("\033[%d;%dH", (get_rows() / 2 + 2 * (get_rows() / 10)), (get_cols() / 2 - 4));
                    xt_par0("\033[37m");
                    printf("Settings");
                    break;
                case 3:
                    xt_par2("\033[%d;%dH", (get_rows() / 2 + 3 * (get_rows() / 10)), (get_cols() / 2 - 2));
                    xt_par0("\033[31m");
                    printf("Quit");
                    break;
                case 1:
                    xt_par2("\033[%d;%dH", (get_rows() / 2 + 1 * (get_rows() / 10)), (get_cols() / 2 - 5));
                    xt_par0("\033[31m");
                    xt_par0("\033[1m");
                    printf("M");
                    xt_par0("\033[33m");
                    printf("u");
                    xt_par0("\033[32m");
                    printf("L");
                    xt_par0("\033[36m");
                    printf("t");
                    xt_par0("\033[34m");
                    printf("I");
                    xt_par0("\033[35m");
                    printf("p");
                    xt_par0("\033[31m");
                    printf("L");
                    xt_par0("\033[33m");
                    printf("a");
                    xt_par0("\033[32m");
                    printf("Y");
                    xt_par0("\033[36m");
                    printf("e");
                    xt_par0("\033[34m");
                    printf("R");
                    break;
            }
            if (choice > 0)
                choice--;
            else
                choice = 3;
            xt_par0("\033[1m");
            xt_par0("\033[7m");
            switch (choice) {
                case 0:
                    xt_par2("\033[%d;%dH", (get_rows() / 2), (get_cols() / 2 - 6));
                    xt_par0("\033[32m");
                    printf("Single Player");
                    xt_par2("\033[%d;%dH", (get_rows()), (get_cols()));
                    break;
                case 2:
                    xt_par2("\033[%d;%dH", (get_rows() / 2 + 2 * (get_rows() / 10)), (get_cols() / 2 - 4));
                    xt_par0("\033[37m");
                    xt_par0("\033[1m");
                    printf("Settings");
                    xt_par2("\033[%d;%dH", (get_rows()), (get_cols()));
                    break;
                case 3:
                    xt_par2("\033[%d;%dH", (get_rows() / 2 + 3 * (get_rows() / 10)), (get_cols() / 2 - 2));
                    xt_par0("\033[31m");
                    printf("Quit");
                    xt_par2("\033[%d;%dH", (get_rows()), (get_cols()));
                    break;
                case 1:
                    xt_par2("\033[%d;%dH", (get_rows() / 2 + 1 * (get_rows() / 10)), (get_cols() / 2 - 5));
                    xt_par0("\033[31m");
                    xt_par0("\033[1m");
                    printf("M");
                    xt_par0("\033[33m");
                    printf("u");
                    xt_par0("\033[32m");
                    printf("L");
                    xt_par0("\033[36m");
                    printf("t");
                    xt_par0("\033[34m");
                    printf("I");
                    xt_par0("\033[35m");
                    printf("p");
                    xt_par0("\033[31m");
                    printf("L");
                    xt_par0("\033[33m");
                    printf("a");
                    xt_par0("\033[32m");
                    printf("Y");
                    xt_par0("\033[36m");
                    printf("e");
                    xt_par0("\033[34m");
                    printf("R");
                    break;
            }
            xt_par0("\033[0m");
            break;
        case -11:
        case 's':
            xt_par0("\033[39m");
            switch (choice) {
                case 0:
                    xt_par2("\033[%d;%dH", (get_rows() / 2), (get_cols() / 2 - 6));
                    xt_par0("\033[32m");
                    printf("Single Player");
                    break;
                case 2:
                    xt_par2("\033[%d;%dH", (get_rows() / 2 + 2 * (get_rows() / 10)), (get_cols() / 2 - 4));
                    xt_par0("\033[37m");
                    printf("Settings");
                    break;
                case 3:
                    xt_par2("\033[%d;%dH", (get_rows() / 2 + 3 * (get_rows() / 10)), (get_cols() / 2 - 2));
                    xt_par0("\033[31m");
                    printf("Quit");
                    break;
                case 1:
                    xt_par2("\033[%d;%dH", (get_rows() / 2 + 1 * (get_rows() / 10)), (get_cols() / 2 - 5));
                    xt_par0("\033[31m");
                    xt_par0("\033[1m");
                    printf("M");
                    xt_par0("\033[33m");
                    printf("u");
                    xt_par0("\033[32m");
                    printf("L");
                    xt_par0("\033[36m");
                    printf("t");
                    xt_par0("\033[34m");
                    printf("I");
                    xt_par0("\033[35m");
                    printf("p");
                    xt_par0("\033[31m");
                    printf("L");
                    xt_par0("\033[33m");
                    printf("a");
                    xt_par0("\033[32m");
                    printf("Y");
                    xt_par0("\033[36m");
                    printf("e");
                    xt_par0("\033[34m");
                    printf("R");
                    break;
            }
            if (choice < 3)
                choice++;
            else
                choice = 0;
            xt_par0("\033[1m");
            xt_par0("\033[7m");
            switch (choice) {
                case 0:
                    xt_par2("\033[%d;%dH", (get_rows() / 2), (get_cols() / 2 - 6));
                    xt_par0("\033[32m");
                    printf("Single Player");
                    xt_par2("\033[%d;%dH", (get_rows()), (get_cols()));
                    break;
                case 2:
                    xt_par2("\033[%d;%dH", (get_rows() / 2 + 2 * (get_rows() / 10)), (get_cols() / 2 - 4));
                    xt_par0("\033[37m");
                    xt_par0("\033[1m");
                    printf("Settings");
                    xt_par2("\033[%d;%dH", (get_rows()), (get_cols()));
                    break;
                case 3:
                    xt_par2("\033[%d;%dH", (get_rows() / 2 + 3 * (get_rows() / 10)), (get_cols() / 2 - 2));
                    xt_par0("\033[31m");
                    printf("Quit");
                    xt_par2("\033[%d;%dH", (get_rows()), (get_cols()));
                    break;
                case 1:
                    xt_par2("\033[%d;%dH", (get_rows() / 2 + (get_rows() / 10)), (get_cols() / 2 - 5));
                    xt_par0("\033[31m");
                    xt_par0("\033[1m");
                    printf("M");
                    xt_par0("\033[33m");
                    printf("u");
                    xt_par0("\033[32m");
                    printf("L");
                    xt_par0("\033[36m");
                    printf("t");
                    xt_par0("\033[34m");
                    printf("I");
                    xt_par0("\033[35m");
                    printf("p");
                    xt_par0("\033[31m");
                    printf("L");
                    xt_par0("\033[33m");
                    printf("a");
                    xt_par0("\033[32m");
                    printf("Y");
                    xt_par0("\033[36m");
                    printf("e");
                    xt_par0("\033[34m");
                    printf("R");
                    break;
                }
                xt_par0("\033[0m");
                break;
            case 10:
                return choice;
            case 'q':
                return 3;
        }
        fflush(stdout);
        usleep(1000000/20);
    }
}

variable_types: struct star_t { int x; int y; int xwait; int ywait; int xwaited; int ywaited; int roy; int rox; int d; } *

variable_types: frame int

variable_types: key int


loop

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

do
{
while ( 1 )
{
while ( 1 )
{
result = menu();
if ( (_DWORD)result != 2 )
break;
configloop();
}
if ( (int)result > 2 )
break;
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
serverlogin();
}
else
{
play();
}
}
}
while ( (_DWORD)result != 3 );
return result;
}

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

do
{
while ( 1 )
{
while ( 1 )
{
result = func3();
if ( (_DWORD)result != 2 )
break;
configloop();
}
if ( (int)result > 2 )
break;
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
serverlogin();
}
else
{
play();
}
}
}
while ( (_DWORD)result != 3 );
return result;
}

original_code:
static void loop(void) {
    int option;
    while (1) {
        switch ((option = menu())) {
            case 0:
                play();
                break;
            case 2:
                configloop();
                break;
            case 1:
                serverlogin();
                break;
            case 3:
                return;
        }
    }
}

canonical_original_code:
static void loop() {
    int option;
    while (1) {
        switch ((option = menu())) {
            case 0:
                play();
                break;
            case 2:
                configloop();
                break;
            case 1:
                serverlogin();
                break;
            case 3:
                return;
        }
    }
}

variable_types: option int


finish

decompiled_code:
__int64 finish()
{
getkey_terminate();
xt_par0("\x1B[2J");
xt_par0("\x1B[0m");
return xt_par2("\x1B[%d;%dH", 1LL, 1LL);
}

canonical_decompiled_code:
__int64 func5()
{
getkey_terminate();
xt_par0("\x1B[2J");
xt_par0("\x1B[0m");
return xt_par2("\x1B[%d;%dH", 1LL, 1LL);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
setup(argc, argv, envp);
loop();
finish();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0(argc, argv, envp);
func4();
func5();
return 0;
}

original_code:
int main(int argc, char* argv[]) {
    setup();
    loop();
    finish();
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    setup();
    loop();
    finish();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


isBeginningOf

decompiled_code:
__int64 __fastcall isBeginningOf(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // dl
char v4; // cl

v2 = 0LL;
while ( 1 )
{
v3 = *(_BYTE *)(a2 + v2);
if ( !v3 )
break;
v4 = *(_BYTE *)(a1 + v2++);
if ( v4 != v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // dl
char v4; // cl

v2 = 0LL;
while ( 1 )
{
v3 = *(_BYTE *)(a2 + v2);
if ( !v3 )
break;
v4 = *(_BYTE *)(a1 + v2++);
if ( v4 != v3 )
return 0LL;
}
return 1LL;
}

original_code:
static int isBeginningOf(char *s, char *scode) {
 while (*scode) {
  if (*s++ != *scode++)
   return 0;
 }
 return 1;
}

variable_types:
s
char *

variable_types:
scode
char *