decompiled_code:
__int64 __fastcall ndmp_connect_close(unsigned int *a1)
{
__int64 v2; // rbx
__int64 v3; // rdi

v2 = get_session_info(*a1);
enter_critical_section(*(_QWORD *)(v2 + 16));
*(_DWORD *)(v2 + 4) = 4;
*(_QWORD *)(v2 + 8) = 0x400000004LL;
v3 = *(_QWORD *)(a1 + 1);
a1[1033] = 0;
write_client_log(v3, *(_QWORD *)(a1 + 3), "Sent CONNECT_CLOSE to client");
return exit_critical_section(*(_QWORD *)(v2 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
__int64 v2; // rbx
__int64 v3; // rdi

v2 = get_session_info(*a1);
enter_critical_section(*(_QWORD *)(v2 + 16));
*(_DWORD *)(v2 + 4) = 4;
*(_QWORD *)(v2 + 8) = 0x400000004LL;
v3 = *(_QWORD *)(a1 + 1);
a1[1033] = 0;
write_client_log(v3, *(_QWORD *)(a1 + 3), "Sent CONNECT_CLOSE to client");
return exit_critical_section(*(_QWORD *)(v2 + 16));
}

original_code:
void ndmp_connect_close(struct client_txn *txn,
                        struct ndmp_header header,
                        XDR* request_stream)
{
        struct ndmp_session_info *session_info;
        session_info = get_session_info(txn->client_session.session_id);
        enter_critical_section(session_info->s_lock);
        session_info->connection_state = HALTED;
        session_info->data_state = HALTED;
        session_info->mover_state = HALTED;
        txn->reply.length = 0;
        write_client_log(txn->client_session.client_info.client, "Sent CONNECT_CLOSE to client");
        exit_critical_section(session_info->s_lock);
}

canonical_original_code:
void ndmp_connect_close(struct client_txn *txn, struct ndmp_header header, struct XDR *request_stream)
{
        struct ndmp_session_info *session_info;
        session_info = get_session_info(txn->client_session.session_id);
        enter_critical_section(session_info->s_lock);
        session_info->connection_state = HALTED;
        session_info->data_state = HALTED;
        session_info->mover_state = HALTED;
        txn->reply.length = 0;
        write_client_log(txn->client_session.client_info.client, "Sent CONNECT_CLOSE to client");
        exit_critical_section(session_info->s_lock);
}

user_defined_types: enum ndmp_header_message_type { NDMP_MESSAGE_REQUEST=0, NDMP_MESSAGE_REPLY=1 }

user_defined_types: enum ndmp_message { NDMP_CONNECT_OPEN=2304, NDMP_CONNECT_CLIENT_AUTH=2305, NDMP_CONNECT_CLOSE=2306, NDMP_CONNECT_SERVER_AUTH=2307, NDMP_CONFIG_GET_HOST_INFO=256, NDMP_CONFIG_GET_CONNECTION_TYPE=258, NDMP_CONFIG_GET_AUTH_ATTR=259, NDMP_CONFIG_GET_BUTYPE_INFO=260, NDMP_CONFIG_GET_FS_INFO=261, NDMP_CONFIG_GET_TAPE_INFO=262, NDMP_CONFIG_GET_SCSI_INFO=263, NDMP_CONFIG_GET_SERVER_INFO=264, NDMP_SCSI_OPEN=512, NDMP_SCSI_CLOSE=513, NDMP_SCSI_GET_STATE=514, NDMP_SCSI_SET_TARGET=515, NDMP_SCSI_RESET_DEVICE=516, NDMP_SCSI_RESET_BUS=517, NDMP_SCSI_EXECUTE_CDB=518, NDMP_TAPE_OPEN=768, NDMP_TAPE_CLOSE=769, NDMP_TAPE_GET_STATE=770, NDMP_TAPE_MTIO=771, NDMP_TAPE_WRITE=772, NDMP_TAPE_READ=773, NDMP_TAPE_EXECUTE_CDB=775, NDMP_DATA_GET_STATE=1024, NDMP_DATA_START_BACKUP=1025, NDMP_DATA_START_RECOVER=1026, NDMP_DATA_ABORT=1027, NDMP_DATA_GET_ENV=1028, NDMP_DATA_STOP=1031, NDMP_DATA_LISTEN=1033, NDMP_DATA_CONNECT=1034, NDMP_NOTIFY_DATA_HALTED=1281, NDMP_NOTIFY_CONNECTED=1282, NDMP_NOTIFY_MOVER_HALTED=1283, NDMP_NOTIFY_MOVER_PAUSED=1284, NDMP_NOTIFY_DATA_READ=1285, NDMP_LOG_FILE=1538, NDMP_LOG_MESSAGE=1539, NDMP_FH_ADD_FILE=1795, NDMP_FH_ADD_DIR=1796, NDMP_FH_ADD_NODE=1797, NDMP_MOVER_GET_STATE=2560, NDMP_MOVER_LISTEN=2561, NDMP_MOVER_CONTINUE=2562, NDMP_MOVER_ABORT=2563, NDMP_MOVER_STOP=2564, NDMP_MOVER_SET_WINDOW=2565, NDMP_MOVER_READ=2566, NDMP_MOVER_CLOSE=2567, NDMP_MOVER_SET_RECORD_SIZE=2568, NDMP_MOVER_CONNECT=2569, NDMP_VENDORS_BASE=61440, NDMP_RESERVED_BASE=65280 }

user_defined_types: enum ndmp_error { NDMP_NO_ERR=0, NDMP_NOT_SUPPORTED_ERR=1, NDMP_DEVICE_BUSY_ERR=2, NDMP_DEVICE_OPENED_ERR=3, NDMP_NOT_AUTHORIZED_ERR=4, NDMP_PERMISSION_ERR=5, NDMP_DEV_NOT_OPEN_ERR=6, NDMP_IO_ERR=7, NDMP_TIMEOUT_ERR=8, NDMP_ILLEGAL_ARGS_ERR=9, NDMP_NO_TAPE_LOADED_ERR=10, NDMP_WRITE_PROTECT_ERR=11, NDMP_EOF_ERR=12, NDMP_EOM_ERR=13, NDMP_FILE_NOT_FOUND_ERR=14, NDMP_BAD_FILE_ERR=15, NDMP_NO_DEVICE_ERR=16, NDMP_NO_BUS_ERR=17, NDMP_XDR_DECODE_ERR=18, NDMP_ILLEGAL_STATE_ERR=19, NDMP_UNDEFINED_ERR=20, NDMP_XDR_ENCODE_ERR=21, NDMP_NO_MEM_ERR=22, NDMP_CONNECT_ERR=23 }

user_defined_types: struct session { int session_id; struct client_endpoint client_info; }

user_defined_types: enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 }

user_defined_types: enum ndmp_state { IDLE=0, LISTEN=1, CONNECTED=2, ACTIVE=3, HALTED=4 }

user_defined_types: struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); }


usage

decompiled_code:
int usage()
{
return printf("./morse_client IP MORSE_MESSAGE");
}

canonical_decompiled_code:
int func0()
{
return printf("./morse_client IP MORSE_MESSAGE");
}

original_code:
void usage(){
    printf("./morse_client IP MORSE_MESSAGE");
}

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax

if ( argc == 3 )
{
connectToServer(argv[1], argv, envp);
sendMsgToServer(argv[2]);
result = 0;
}
else
{
usage();
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax

if ( argc == 3 )
{
connectToServer(argv[1], argv, envp);
sendMsgToServer(argv[2]);
result = 0;
}
else
{
func0();
result = 1;
}
return result;
}

original_code:
int main(int argc, char** argv)
{
    if(argc != 3){
        usage();
        return 1;
    }
    connectToServer(argv[1]);
    sendMsgToServer(argv[2]);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    if(argc != 3){
        usage();
        return 1;
    }
    connectToServer(argv[1]);
    sendMsgToServer(argv[2]);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


createSocket

decompiled_code:
__int64 createSocket()
{
int *v1; // rbx
char *v2; // rax

client_fd = socket(2, 1, 0);
if ( client_fd >= 0 )
return 0LL;
v1 = _errno_location();
v2 = strerror(*v1);
printf("Error while creating client socket: %d - %s\n!", (unsigned int)*v1, v2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
int *v1; // rbx
char *v2; // rax

client_fd = socket(2, 1, 0);
if ( client_fd >= 0 )
return 0LL;
v1 = _errno_location();
v2 = strerror(*v1);
printf("Error while creating client socket: %d - %s\n!", (unsigned int)*v1, v2);
return 0xFFFFFFFFLL;
}

original_code:
static int createSocket(void){
    client_fd = socket(2, SOCK_STREAM, 0);
    if(client_fd < 0){
        printf("Error while creating client socket: %d - %s\n!", (*__errno_location ()), strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

canonical_original_code:
static int createSocket(){
    client_fd = socket(2, SOCK_STREAM, 0);
    if(client_fd < 0){
        printf("Error while creating client socket: %d - %s\n!", (*__errno_location ()), strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}


connectSocket

decompiled_code:
__int64 connectSocket()
{
int *v1; // rbx
char *v2; // rax

if ( connect(client_fd, &client_socket, 0x10u) >= 0 )
return 0LL;
v1 = _errno_location();
v2 = strerror(*v1);
printf("Error while connecting client socket: %d - %s\n!", (unsigned int)*v1, v2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
int *v1; // rbx
char *v2; // rax

if ( connect(client_fd, &client_socket, 0x10u) >= 0 )
return 0LL;
v1 = _errno_location();
v2 = strerror(*v1);
printf("Error while connecting client socket: %d - %s\n!", (unsigned int)*v1, v2);
return 0xFFFFFFFFLL;
}

original_code:
static int connectSocket(void){
    int ret = connect(client_fd, (struct sockaddr*) &client_socket, sizeof(client_socket));
    if( ret < 0 ){
        printf("Error while connecting client socket: %d - %s\n!", (*__errno_location ()), strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

canonical_original_code:
static int connectSocket(){
    int ret = connect(client_fd, (struct sockaddr*) &client_socket, sizeof(client_socket));
    if( ret < 0 ){
        printf("Error while connecting client socket: %d - %s\n!", (*__errno_location ()), strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

variable_types: ret int


initSocket

decompiled_code:
in_addr_t __fastcall initSocket(const char *a1)
{
in_addr_t result; // eax

client_socket = 0LL;
client_socket.sa_family = 2;
*(_WORD *)client_socket.sa_data = _bswap_16_constprop_0();
if ( a1 )
result = inet_addr(a1);
else
result = inet_addr("10.116.1.17");
*(_DWORD *)&client_socket.sa_data[2] = result;
return result;
}

canonical_decompiled_code:
in_addr_t __fastcall func3(const char *a1)
{
in_addr_t result; // eax

client_socket = 0LL;
client_socket.sa_family = 2;
*(_WORD *)client_socket.sa_data = func2();
if ( a1 )
result = inet_addr(a1);
else
result = inet_addr("10.116.1.17");
*(_DWORD *)&client_socket.sa_data[2] = result;
return result;
}

original_code:
static void initSocket(char* pIP){
    memset(&client_socket, 0, sizeof(client_socket));
    client_socket.sin_family = 2;
    client_socket.sin_port = htons(6543);
    if(pIP == ((void *)0))
        client_socket.sin_addr.s_addr = inet_addr("10.116.1.17");
    else
        client_socket.sin_addr.s_addr = inet_addr(pIP);
}

canonical_original_code:
static void initSocket(char *pIP){
    memset(&client_socket, 0, sizeof(client_socket));
    client_socket.sin_family = 2;
    client_socket.sin_port = htons(6543);
    if(pIP == ((void *)0))
        client_socket.sin_addr.s_addr = inet_addr("10.116.1.17");
    else
        client_socket.sin_addr.s_addr = inet_addr(pIP);
}

variable_types:
pIP
char *


connectToServer

decompiled_code:
__int64 __fastcall connectToServer(const char *a1)
{
unsigned int v1; // er12

printf("Creating client socket...");
if ( (unsigned int)createSocket() )
return (unsigned int)-1;
v1 = 0;
puts("done!");
printf("Initializing client socket...");
initSocket(a1);
puts("done!");
printf("Connecting to server...");
if ( (unsigned int)connectSocket() == -1 )
return (unsigned int)-1;
puts("done!");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
unsigned int v1; // er12

printf("Creating client socket...");
if ( (unsigned int)func0() )
return (unsigned int)-1;
v1 = 0;
puts("done!");
printf("Initializing client socket...");
func3(a1);
puts("done!");
printf("Connecting to server...");
if ( (unsigned int)func1() == -1 )
return (unsigned int)-1;
puts("done!");
return v1;
}

original_code:
int connectToServer(char* pIP){
    printf("Creating client socket...");
    if(createSocket()){
        return -1;
    }
    printf("done!\n");
    printf("Initializing client socket...");
    initSocket(pIP);
    printf("done!\n");
    printf("Connecting to server...");
    if(connectSocket() == -1){
        return -1;
    }
    printf("done!\n");
    return 0;
}

canonical_original_code:
int connectToServer(char *pIP){
    printf("Creating client socket...");
    if(createSocket()){
        return -1;
    }
    printf("done!\n");
    printf("Initializing client socket...");
    initSocket(pIP);
    printf("done!\n");
    printf("Connecting to server...");
    if(connectSocket() == -1){
        return -1;
    }
    printf("done!\n");
    return 0;
}


sendMsgToServer

decompiled_code:
__int64 __fastcall sendMsgToServer(_BYTE *a1)
{
int *v3; // rbx
char *v4; // rax

do
{
if ( !*a1 )
{
close(client_fd);
return 0LL;
}
++a1;
}
while ( (int)write(client_fd, a1, 1uLL) >= 0 );
v3 = _errno_location();
v4 = strerror(*v3);
printf("Error while connecting client socket: %d - %s\n!", (unsigned int)*v3, v4);
close(client_fd);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1)
{
int *v3; // rbx
char *v4; // rax

do
{
if ( !*a1 )
{
close(client_fd);
return 0LL;
}
++a1;
}
while ( (int)write(client_fd, a1, 1uLL) >= 0 );
v3 = _errno_location();
v4 = strerror(*v3);
printf("Error while connecting client socket: %d - %s\n!", (unsigned int)*v3, v4);
close(client_fd);
return 0xFFFFFFFFLL;
}

original_code:
int sendMsgToServer(char* pMsg){
    int char_cnt = 0;
    int ret = 0;
    while(*pMsg != '\0'){
        ++char_cnt;
        ret = write(client_fd, &*(++pMsg), 1);
        if(ret < 0){
            printf("Error while connecting client socket: %d - %s\n!", (*__errno_location ()), strerror((*__errno_location ())));
            close(client_fd);
            return -1;
        }
    }
    close(client_fd);
    return 0;
}

canonical_original_code:
int sendMsgToServer(char *pMsg){
    int char_cnt = 0;
    int ret = 0;
    while(*pMsg != '\0'){
        ++char_cnt;
        ret = write(client_fd, &*(++pMsg), 1);
        if(ret < 0){
            printf("Error while connecting client socket: %d - %s\n!", (*__errno_location ()), strerror((*__errno_location ())));
            close(client_fd);
            return -1;
        }
    }
    close(client_fd);
    return 0;
}

variable_types:
pMsg
char *


bail

repo: shivanan/cmc

decompiled_code:
void __noreturn bail(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

original_code:
void bail(const char * text,...)
{
 va_list args;
 __builtin_va_start(args,text);
 vfprintf (stderr, text, args);
 __builtin_va_end(args);
 exit(1);
}

canonical_original_code:
void bail(char *text, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,text);
 vfprintf (stderr, text, args);
 __builtin_va_end(args);
 exit(1);
}

variable_types:
text
char *


xmalloc

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

if ( !a1 )
bail("Zero byte allocation requested\n");
result = malloc(a1);
if ( !result )
bail("Memory allocation failed\n");
return result;
}

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

if ( !a1 )
func0("Zero byte allocation requested\n");
result = malloc(a1);
if ( !result )
func0("Memory allocation failed\n");
return result;
}

original_code:
void * xmalloc (size_t size)
{
 void * result;
 if (!size)
  bail ("Zero byte allocation requested\n");
 result = malloc(size);
 if (!result)
  bail ("Memory allocation failed\n");
 return result;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
 void *result;
 if (!size)
  bail ("Zero byte allocation requested\n");
 result = malloc(size);
 if (!result)
  bail ("Memory allocation failed\n");
 return result;
}

variable_types:
size
unsigned long

variable_types:
result
void *

return_type: void *


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, size_t a2)
{
void *result; // rax

if ( !a2 )
bail("Zero byte realloction requested\n");
result = realloc(a1, a2);
if ( !result )
bail("Reallocation failed\n");
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
void *result; // rax

if ( !a2 )
func0("Zero byte realloction requested\n");
result = realloc(a1, a2);
if ( !result )
func0("Reallocation failed\n");
return result;
}

original_code:
void * xrealloc (void * ptr, size_t size)
{
 void * result;
 if (!size)
  bail ("Zero byte realloction requested\n");
 result = realloc (ptr, size);
 if (!result)
  bail ("Reallocation failed\n");
 return result;
}

canonical_original_code:
void *xrealloc(void *ptr, unsigned long size)
{
 void *result;
 if (!size)
  bail ("Zero byte realloction requested\n");
 result = realloc (ptr, size);
 if (!result)
  bail ("Reallocation failed\n");
 return result;
}

variable_types:
ptr
void *


xfree

decompiled_code:
void __fastcall xfree(void *a1)
{
if ( !a1 )
bail("Attempting to free NULL pointer");
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
if ( !a1 )
func0("Attempting to free NULL pointer");
free(a1);
}

original_code:
void xfree (void * ptr)
{
 if (!ptr)
  bail ("Attempting to free NULL pointer");
 free (ptr);
}

canonical_original_code:
void xfree(void *ptr)
{
 if (!ptr)
  bail ("Attempting to free NULL pointer");
 free (ptr);
}


decompiled_code:
__int64 __fastcall instrument_number(char *s1)
{
__int64 i; // rbx

for ( i = 0LL; i != 128; ++i )
{
if ( !strcasecmp(s1, (&instruments)[i]) )
return (unsigned int)i;
}
return 4294967168LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s1)
{
__int64 i; // rbx

for ( i = 0LL; i != 128; ++i )
{
if ( !strcasecmp(s1, (&instruments)[i]) )
return (unsigned int)i;
}
return 4294967168LL;
}

original_code:
unsigned char instrument_number (char * instrument)
{
 int i=0;
 while (i<0x80) {
  if (!strcasecmp (instrument, instruments[i]))
   return (unsigned char)i;
  i++;
 }
 return 0x80;
}

canonical_original_code:
unsigned char instrument_number(char *instrument)
{
 int i = 0;
 while (i<0x80) {
  if (!strcasecmp (instrument, instruments[i]))
   return (unsigned char)i;
  i++;
 }
 return 0x80;
}

variable_types:
instrument
char *

variable_types: i int

return_type: unsigned char


original_code:
STREAM * stream_create (size_t size)
{
 STREAM *result = (STREAM *)xmalloc(sizeof(STREAM));
 result->size = 0;
 result->capacity = size;
 result->offset = 0;
 result->buffer = (char *)xmalloc(size);
 result->r_offset = 0;
 if (!result->buffer)
  return ((void *)0);
 return result;
}

canonical_original_code:
struct _STREAM *stream_create(unsigned long size)
{
 struct _STREAM *result = (STREAM *)xmalloc(sizeof(STREAM));
 result->size = 0;
 result->capacity = size;
 result->offset = 0;
 result->buffer = (char *)xmalloc(size);
 result->r_offset = 0;
 if (!result->buffer)
  return ((void *)0);
 return result;
}

variable_types: struct _STREAM { unsigned long capacity; unsigned long size; int offset; char *buffer; int r_offset; } *


decompiled_code:
__int64 __fastcall stream_free(__int64 a1)
{
if ( *(_QWORD *)(a1 + 24) )
((void (*)(void))xfree)();
return xfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( *(_QWORD *)(a1 + 24) )
((void (*)(void))xfree)();
return xfree(a1);
}

original_code:
void stream_free(STREAM *stream)
{
 if (stream->buffer)
  xfree(stream->buffer);
 xfree(stream);
}

canonical_original_code:
void stream_free(struct _STREAM *stream)
{
 if (stream->buffer)
  xfree(stream->buffer);
 xfree(stream);
}

user_defined_types: struct _STREAM { unsigned long capacity; unsigned long size; int offset; char *buffer; int r_offset; }


decompiled_code:
void __fastcall stream_write_reset(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 0;
}

original_code:
void stream_write_reset (STREAM * stream)
{
 stream->size = 0;
 stream->offset = 0;
}

canonical_original_code:
void stream_write_reset(struct _STREAM *stream)
{
 stream->size = 0;
 stream->offset = 0;
}


decompiled_code:
size_t __fastcall stream_write(__int64 a1, const void *a2, size_t a3)
{
__int64 v6; // rdi
unsigned __int64 v7; // rbp
unsigned __int64 v8; // rsi

v6 = *(int *)(a1 + 16);
v7 = (int)v6 + (int)a3;
if ( v7 > *(_QWORD *)a1 )
{
v8 = 2LL * *(_QWORD *)a1;
if ( v7 <= v8 )
stream_expand_isra_0((_QWORD *)a1, v8);
else
stream_expand_isra_0((_QWORD *)a1, v7);
v6 = *(int *)(a1 + 16);
}
memcpy((void *)(*(_QWORD *)(a1 + 24) + v6), a2, a3);
*(_DWORD *)(a1 + 16) += a3;
if ( v7 > *(_QWORD *)(a1 + 8) )
*(_QWORD *)(a1 + 8) = v7;
return a3;
}

original_code:
size_t stream_write(STREAM *stream,const char *data,size_t len)
{
 int final_size;
 final_size = stream->offset+len;
 if (final_size > stream->capacity)
 {
  if (final_size > 2*stream->capacity)
   stream_expand(stream,final_size);
  else
   stream_expand(stream,2*stream->capacity);
 }
 memcpy(stream->buffer+stream->offset,data,len);
 stream->offset += len;
 if (final_size > stream->size)
  stream->size = final_size;
 return len;
}

canonical_original_code:
unsigned long stream_write(struct _STREAM *stream, char *data, unsigned long len)
{
 int final_size;
 final_size = stream->offset+len;
 if (final_size > stream->capacity)
 {
  if (final_size > 2*stream->capacity)
   stream_expand(stream,final_size);
  else
   stream_expand(stream,2*stream->capacity);
 }
 memcpy(stream->buffer+stream->offset,data,len);
 stream->offset += len;
 if (final_size > stream->size)
  stream->size = final_size;
 return len;
}

variable_types:
data
char *

variable_types:
len
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall stream_create_from_buffer(const void *a1, size_t a2)
{
__int64 v2; // r12

v2 = stream_create(a2);
stream_write(v2, a1, a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(const void *a1, size_t a2)
{
__int64 v2; // r12

v2 = func1(a2);
func4(v2, a1, a2);
return v2;
}

original_code:
STREAM * stream_create_from_buffer (const char * buffer, size_t buf_len)
{
 STREAM * result = stream_create (buf_len);
 stream_write (result, buffer, buf_len);
 return result;
}

canonical_original_code:
struct _STREAM *stream_create_from_buffer(char *buffer, unsigned long buf_len)
{
 struct _STREAM *result = stream_create (buf_len);
 stream_write (result, buffer, buf_len);
 return result;
}

variable_types:
buffer
char *

return_type: struct _STREAM { unsigned long capacity; unsigned long size; int offset; char *buffer; int r_offset; } *


decompiled_code:
__int64 __fastcall stream_current_position(__int64 a1)
{
return *(_QWORD *)(a1 + 24) + *(int *)(a1 + 32);
}

original_code:
char * stream_current_position (STREAM * stream)
{
 return stream->buffer + stream->r_offset;
}

canonical_original_code:
char *stream_current_position(struct _STREAM *stream)
{
 return stream->buffer + stream->r_offset;
}

return_type: char *


decompiled_code:
__int64 __fastcall stream_read(__int64 a1, void *a2, size_t a3)
{
unsigned int v5; // ebx
size_t v6; // rsi
size_t v7; // rax

v5 = a3;
v6 = *(int *)(a1 + 32);
v7 = *(_QWORD *)(a1 + 8);
if ( v6 + a3 >= v7 || v6 > v7 )
return 0LL;
memcpy(a2, (const void *)(*(_QWORD *)(a1 + 24) + v6), a3);
*(_DWORD *)(a1 + 32) += v5;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, void *a2, size_t a3)
{
unsigned int v5; // ebx
size_t v6; // rsi
size_t v7; // rax

v5 = a3;
v6 = *(int *)(a1 + 32);
v7 = *(_QWORD *)(a1 + 8);
if ( v6 + a3 >= v7 || v6 > v7 )
return 0LL;
memcpy(a2, (const void *)(*(_QWORD *)(a1 + 24) + v6), a3);
*(_DWORD *)(a1 + 32) += v5;
return v5;
}

original_code:
int stream_read (STREAM * stream, char * buffer, size_t len)
{
 int offset = stream->r_offset;
 if (len+offset >= stream->size) return 0;
 if (offset > stream->size)
  return 0;
 memcpy (buffer, stream->buffer + offset, len);
 stream->r_offset += len;
 return len;
}

canonical_original_code:
int stream_read(struct _STREAM *stream, char *buffer, unsigned long len)
{
 int offset = stream->r_offset;
 if (len+offset >= stream->size) return 0;
 if (offset > stream->size)
  return 0;
 memcpy (buffer, stream->buffer + offset, len);
 stream->r_offset += len;
 return len;
}

variable_types: offset int


decompiled_code:
__int64 __fastcall stream_read_char(__int64 a1, _BYTE *a2)
{
unsigned __int64 v2; // rdx
__int64 result; // rax

v2 = *(int *)(a1 + 32);
result = 0LL;
if ( v2 <= *(_QWORD *)(a1 + 8) )
{
*a2 = *(_BYTE *)(*(_QWORD *)(a1 + 24) + v2);
result = 1LL;
++*(_DWORD *)(a1 + 32);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, _BYTE *a2)
{
unsigned __int64 v2; // rdx
__int64 result; // rax

v2 = *(int *)(a1 + 32);
result = 0LL;
if ( v2 <= *(_QWORD *)(a1 + 8) )
{
*a2 = *(_BYTE *)(*(_QWORD *)(a1 + 24) + v2);
result = 1LL;
++*(_DWORD *)(a1 + 32);
}
return result;
}

original_code:
int stream_read_char (STREAM * stream, unsigned char * c)
{
 int offset = stream->r_offset;
 if (offset > stream->size)
  return 0;
 *c = stream->buffer[offset];
 stream->r_offset++;
 return 1;
}

canonical_original_code:
int stream_read_char(struct _STREAM *stream, unsigned char *c)
{
 int offset = stream->r_offset;
 if (offset > stream->size)
  return 0;
 *c = stream->buffer[offset];
 stream->r_offset++;
 return 1;
}

variable_types:
c
unsigned char *


original_code:
int stream_add_char(STREAM *stream,unsigned char ch)
{
 int final_size;
 final_size = stream->offset+1;
 if (final_size > stream->capacity)
 {
  if (final_size > 2*stream->capacity)
   stream_expand(stream,final_size);
  else
   stream_expand(stream,2*stream->capacity);
 }
 stream->buffer[stream->offset]=ch;
 stream->offset++;
 if (final_size > stream->size)
  stream->size = final_size;
 return 1;
}

canonical_original_code:
int stream_add_char(struct _STREAM *stream, unsigned char ch)
{
 int final_size;
 final_size = stream->offset+1;
 if (final_size > stream->capacity)
 {
  if (final_size > 2*stream->capacity)
   stream_expand(stream,final_size);
  else
   stream_expand(stream,2*stream->capacity);
 }
 stream->buffer[stream->offset]=ch;
 stream->offset++;
 if (final_size > stream->size)
  stream->size = final_size;
 return 1;
}

variable_types:
ch
unsigned char


decompiled_code:
__int64 __fastcall stream_write_int_reverse(__int64 a1, int a2, __int64 a3)
{
int v3; // er12
__int64 v5; // rax
char *v6; // rbp
char *v7; // rax
unsigned int v8; // ebx

v3 = a3;
v5 = xmalloc(a3);
v6 = (char *)v5;
if ( v3 > 0 )
{
v7 = (char *)(v5 + v3 - 1);
do
{
*v7-- = a2;
a2 >>= 8;
}
while ( v7 != &v6[v3 - 2LL - (unsigned int)(v3 - 1)] );
}
v8 = stream_write(a1, v6, 4uLL);
xfree(v6);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, __int64 a3)
{
int v3; // er12
__int64 v5; // rax
char *v6; // rbp
char *v7; // rax
unsigned int v8; // ebx

v3 = a3;
v5 = xmalloc(a3);
v6 = (char *)v5;
if ( v3 > 0 )
{
v7 = (char *)(v5 + v3 - 1);
do
{
*v7-- = a2;
a2 >>= 8;
}
while ( v7 != &v6[v3 - 2LL - (unsigned int)(v3 - 1)] );
}
v8 = func4(a1, v6, 4uLL);
xfree(v6);
return v8;
}

original_code:
int stream_write_int_reverse (STREAM * stream, int i, size_t int_size)
{
 int k,j=i, result=0;
 char * buffer = (char *)xmalloc (int_size);
 for (k=int_size;k>0;k--)
 {
  unsigned char b = j & 0xFF;
  buffer[k-1] = b;
  j>>=8;
 }
 result = stream_write (stream, buffer, 4);
 xfree (buffer);
 return result;
}

canonical_original_code:
int stream_write_int_reverse(struct _STREAM *stream, int i, unsigned long int_size)
{
 int k; int j = i; int result = 0;
 char *buffer = (char *)xmalloc (int_size);
 for (k=int_size;k>0;k--)
 {
  unsigned char b = j & 0xFF;
  buffer[k-1] = b;
  j>>=8;
 }
 result = stream_write (stream, buffer, 4);
 xfree (buffer);
 return result;
}

variable_types: k int

variable_types: j int

variable_types: result int

variable_types:
b
unsigned char


decompiled_code:
__int64 __fastcall stream_data(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
char * stream_data(STREAM *stream)
{
 return stream->buffer;
}

canonical_original_code:
char *stream_data(struct _STREAM *stream)
{
 return stream->buffer;
}


decompiled_code:
void *__fastcall stream_copy_buffer(__int64 a1)
{
__int64 v2; // rdi
void *v3; // r8
void *v4; // rax

v2 = *(_QWORD *)(a1 + 8);
v3 = 0LL;
if ( v2 )
{
v4 = (void *)xmalloc(v2);
v3 = memcpy(v4, *(const void **)(a1 + 24), *(_QWORD *)(a1 + 8));
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func12(__int64 a1)
{
__int64 v2; // rdi
void *v3; // r8
void *v4; // rax

v2 = *(_QWORD *)(a1 + 8);
v3 = 0LL;
if ( v2 )
{
v4 = (void *)xmalloc(v2);
v3 = memcpy(v4, *(const void **)(a1 + 24), *(_QWORD *)(a1 + 8));
}
return v3;
}

original_code:
char * stream_copy_buffer (STREAM * stream)
{
 char * r;
 if (stream->size < 1)
  return ((void *)0);
 r = (char *)xmalloc(stream->size);
 memcpy (r, stream->buffer, stream->size);
 return r;
}

canonical_original_code:
char *stream_copy_buffer(struct _STREAM *stream)
{
 char *r;
 if (stream->size < 1)
  return ((void *)0);
 r = (char *)xmalloc(stream->size);
 memcpy (r, stream->buffer, stream->size);
 return r;
}

variable_types:
r
char *


main

repo: shivdasgujare/code

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v4; // eax
int v5; // ebp
ssize_t v6; // rax
int *v8; // rbp
char *v9; // rax
char *v10; // rax
__int64 v11; // r8
__int64 v12; // rdx
const char *v13; // r9
int *v14; // rbp
char *v15; // rax
char *v16; // rax
char v17[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( argc <= 1 )
{
fprintf(stderr, "\nUsage:\t%s { sysfs file }\n", *argv);
exit(1);
}
v3 = argv[1];
v4 = open(v3, 0, envp);
v5 = v4;
if ( v4 < 0 )
{
v14 = __errno_location();
v15 = strerror(*v14);
fprintf(stderr, "open %s: %s\n", v3, v15);
v16 = strerror(*v14);
v11 = (unsigned int)*v14;
v12 = 31LL;
v13 = v16;
LABEL_7:
fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", v12, "sysfsread.c", v11, v13);
exit(1);
}
v6 = read(v4, v17, 0x3FFuLL);
if ( v6 < 0 )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(stderr, "read %s: %s", v3, v9);
v10 = strerror(*v8);
v11 = (unsigned int)*v8;
v12 = 37LL;
v13 = v10;
goto LABEL_7;
}
v17[v6] = 0;
printf("%s : %s\n", v3, v17);
close(v5);
return 0;
}

original_code:
int main(int argc, char **argv)
{
        char buf[1024];
        ssize_t len;
        int fd;
 char *filename;
 if(argc < 2) {
  fprintf(stderr, "\nUsage:\t%s { sysfs file }\n", argv[0]);
  exit(1);
 }
 filename = argv[1];
        fd = open(filename, 00);
        if (fd < 0) {
  fprintf(stderr, "open %s: %s\n", filename, strerror((*__errno_location ())));
  do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", 31, "sysfsread.c", (*__errno_location ()), strerror((*__errno_location ()))); exit(1); } while(0);
        }
        len = read(fd, buf, sizeof(buf)-1);
        if (len < 0) {
                fprintf(stderr, "read %s: %s", filename, strerror((*__errno_location ())));
  do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", 37, "sysfsread.c", (*__errno_location ()), strerror((*__errno_location ()))); exit(1); } while(0);
        }
        buf[len] = 0;
 printf("%s : %s\n", filename, buf);
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
        char buf[1024];
        long len;
        int fd;
 char *filename;
 if(argc < 2) {
  fprintf(stderr, "\nUsage:\t%s { sysfs file }\n", argv[0]);
  exit(1);
 }
 filename = argv[1];
        fd = open(filename, 00);
        if (fd < 0) {
  fprintf(stderr, "open %s: %s\n", filename, strerror((*__errno_location ())));
  do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", 31, "sysfsread.c", (*__errno_location ()), strerror((*__errno_location ()))); exit(1); } while(0);
        }
        len = read(fd, buf, sizeof(buf)-1);
        if (len < 0) {
                fprintf(stderr, "read %s: %s", filename, strerror((*__errno_location ())));
  do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", 37, "sysfsread.c", (*__errno_location ()), strerror((*__errno_location ()))); exit(1); } while(0);
        }
        buf[len] = 0;
 printf("%s : %s\n", filename, buf);
 close(fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
buf
char [1024]

variable_types: len long

variable_types: fd int

variable_types:
filename
char *


max

decompiled_code:
__int64 __fastcall max(__int64 a1, __int64 a2, __int64 a3, signed int a4, signed int a5, signed int a6)
{
__int64 v6; // rax
int v7; // edx
int v8; // edx
int v9; // edx
_DWORD *v10; // rdx
__int64 result; // rax

v6 = a3 + 12 * fx * a1;
v7 = a6;
if ( a4 >= a6 )
v7 = a4;
if ( a5 >= v7 )
*(_DWORD *)(v6 + 12 * a2 + 4) = 1;
v8 = a6;
if ( a5 >= a6 )
v8 = a5;
if ( a4 >= v8 )
*(_DWORD *)(v6 + 12 * a2) = 1;
v9 = a4;
if ( a5 >= a4 )
v9 = a5;
if ( a6 >= v9 )
*(_DWORD *)(v6 + 12 * a2 + 8) = 1;
v10 = (_DWORD *)(v6 + 12 * a2);
result = (unsigned int)a5;
if ( !v10[1] )
{
result = (unsigned int)a4;
if ( !*v10 )
{
result = (unsigned int)v10[2];
if ( (_DWORD)result )
result = (unsigned int)a6;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, signed int a4, signed int a5, signed int a6)
{
__int64 v6; // rax
int v7; // edx
int v8; // edx
int v9; // edx
_DWORD *v10; // rdx
__int64 result; // rax

v6 = a3 + 12 * fx * a1;
v7 = a6;
if ( a4 >= a6 )
v7 = a4;
if ( a5 >= v7 )
*(_DWORD *)(v6 + 12 * a2 + 4) = 1;
v8 = a6;
if ( a5 >= a6 )
v8 = a5;
if ( a4 >= v8 )
*(_DWORD *)(v6 + 12 * a2) = 1;
v9 = a4;
if ( a5 >= a4 )
v9 = a5;
if ( a6 >= v9 )
*(_DWORD *)(v6 + 12 * a2 + 8) = 1;
v10 = (_DWORD *)(v6 + 12 * a2);
result = (unsigned int)a5;
if ( !v10[1] )
{
result = (unsigned int)a4;
if ( !*v10 )
{
result = (unsigned int)v10[2];
if ( (_DWORD)result )
result = (unsigned int)a6;
}
}
return result;
}

original_code:
int
max(const unsigned long int i, const unsigned long int j, int paths[fy][fx][3],
 const int left, const int diag, const int up)
{
 if(diag >= left && diag >= up) paths[i][j][1] = 1;
 if(left >= diag && left >= up) paths[i][j][0] = 1;
 if(up >= left && up >= diag) paths[i][j][2] = 1;
 if(paths[i][j][1]) return diag;
 else if(paths[i][j][0]) return left;
 else if(paths[i][j][2]) return up;
 return 0;
}

canonical_original_code:
int max(unsigned long i, unsigned long j, int paths[-1][-1][3], int left, int diag, int up)
{
 if(diag >= left && diag >= up) paths[i][j][1] = 1;
 if(left >= diag && left >= up) paths[i][j][0] = 1;
 if(up >= left && up >= diag) paths[i][j][2] = 1;
 if(paths[i][j][1]) return diag;
 else if(paths[i][j][0]) return left;
 else if(paths[i][j][2]) return up;
 return 0;
}

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types: left int

variable_types: diag int

variable_types: up int


bumpRow

decompiled_code:
__int64 __fastcall bumpRow(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
__int64 v3; // rsi
__int64 v4; // rdx

v1 = 4 * fx;
result = print1dint(fx, a1);
v3 = fx;
v4 = a1 + v1;
if ( fx )
{
result = 0LL;
do
{
*(_DWORD *)(a1 + 4 * result) = *(_DWORD *)(v4 + 4 * result);
*(_DWORD *)(v4 + 4 * result++) = 0;
}
while ( result != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
__int64 v3; // rsi
__int64 v4; // rdx

v1 = 4 * fx;
result = print1dint(fx, a1);
v3 = fx;
v4 = a1 + v1;
if ( fx )
{
result = 0LL;
do
{
*(_DWORD *)(a1 + 4 * result) = *(_DWORD *)(v4 + 4 * result);
*(_DWORD *)(v4 + 4 * result++) = 0;
}
while ( result != v3 );
}
return result;
}

original_code:
void bumpRow(int f1d[2][fx])
{
 unsigned long int i;
 print1dint(fx,f1d[0]);
 for(i=0; i<fx; i++)
 {
  f1d[0][i] = f1d[1][i];
  f1d[1][i] = 0;
 }
}

canonical_original_code:
void bumpRow(int f1d[2][-1])
{
 unsigned long i;
 print1dint(fx,f1d[0]);
 for(i=0; i<fx; i++)
 {
  f1d[0][i] = f1d[1][i];
  f1d[1][i] = 0;
 }
}


original_code:
int
findSim1d(unsigned long int i, unsigned long int j, char s[], char t[], int f1d[2][fx], int pathsFrom1d[fy][fx][3])
{
 static int localOptimal=0;
 unsigned long int xSize = (strlen(s) +1), ySize = (strlen(t) +1);
 if(i==0 && j==0)
 {
  f1d[0][0] = 0;
  for(i=0; i<ySize; i++)
  {
   for(j=0; j<xSize; j++)
   {
    if(i==0 && j==0);
    else findSim1d(i,j,s,t,f1d,pathsFrom1d);
   }
   if(i!=0) bumpRow(f1d);
  }
  print1dint(fx,f1d[0]);
  optimal = f1d[1][j-1];
 }
 else if(i==0)
 {
  f1d[0][j] = algorithm?0:j*g;
  pathsFrom1d[i][j][0] = 1;
 }
 else if(j==0)
 {
  f1d[1][j] = algorithm?0:i*g;
  pathsFrom1d[i][j][2] = 1;
 }
 else
 {
  f1d[1][j] = max(i,j,pathsFrom1d, (f1d[1][j-1]+g), ( f1d[0][j-1]+( s[j-1]==t[i-1] ? m : mism ) ), (f1d[0][j]+g) );
  if(algorithm && f1d[1][j]<0)
   f1d[1][j] = 0;
 }
 return localOptimal;
}

canonical_original_code:
int findSim1d(unsigned long i, unsigned long j, char s[], char t[], int f1d[2][-1], int pathsFrom1d[-1][-1][3])
{
 static int localOptimal = 0;
 unsigned long xSize = (strlen(s) +1); unsigned long ySize = (strlen(t) +1);
 if(i==0 && j==0)
 {
  f1d[0][0] = 0;
  for(i=0; i<ySize; i++)
  {
   for(j=0; j<xSize; j++)
   {
    if(i==0 && j==0);
    else findSim1d(i,j,s,t,f1d,pathsFrom1d);
   }
   if(i!=0) bumpRow(f1d);
  }
  print1dint(fx,f1d[0]);
  optimal = f1d[1][j-1];
 }
 else if(i==0)
 {
  f1d[0][j] = algorithm?0:j*g;
  pathsFrom1d[i][j][0] = 1;
 }
 else if(j==0)
 {
  f1d[1][j] = algorithm?0:i*g;
  pathsFrom1d[i][j][2] = 1;
 }
 else
 {
  f1d[1][j] = max(i,j,pathsFrom1d, (f1d[1][j-1]+g), ( f1d[0][j-1]+( s[j-1]==t[i-1] ? m : mism ) ), (f1d[0][j]+g) );
  if(algorithm && f1d[1][j]<0)
   f1d[1][j] = 0;
 }
 return localOptimal;
}

variable_types:
s
char []

variable_types:
t
char []

variable_types: localOptimal int

variable_types:
xSize
unsigned long

variable_types:
ySize
unsigned long


insertGap

decompiled_code:
unsigned __int64 __fastcall insertGap(int a1, __int64 a2, __int64 a3)
{
unsigned __int64 result; // rax
unsigned __int64 v5; // rdx
char v6; // di
char v7; // r8

if ( a1 < 0 )
a1 = 0;
result = 0LL;
v5 = a1;
v6 = 0;
if ( a2 )
{
do
{
while ( v5 == result )
{
++result;
v6 = *(_BYTE *)(a3 + v5);
*(_BYTE *)(a3 + v5) = 45;
if ( a2 == result )
return result;
}
if ( v5 < result )
{
v7 = *(_BYTE *)(a3 + result);
*(_BYTE *)(a3 + result) = v6;
v6 = v7;
}
++result;
}
while ( a2 != result );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(int a1, __int64 a2, __int64 a3)
{
unsigned __int64 result; // rax
unsigned __int64 v5; // rdx
char v6; // di
char v7; // r8

if ( a1 < 0 )
a1 = 0;
result = 0LL;
v5 = a1;
v6 = 0;
if ( a2 )
{
do
{
while ( v5 == result )
{
++result;
v6 = *(_BYTE *)(a3 + v5);
*(_BYTE *)(a3 + v5) = 45;
if ( a2 == result )
return result;
}
if ( v5 < result )
{
v7 = *(_BYTE *)(a3 + result);
*(_BYTE *)(a3 + result) = v6;
v6 = v7;
}
++result;
}
while ( a2 != result );
}
return result;
}

original_code:
void
insertGap(int index, const unsigned long int n, char arr[n])
{
 unsigned long int i;
 char temp = '\0', temp1 = '\0';
 if(index<0) index=0;
 for(i=0; i<n; i++)
 {
  if(i==(unsigned long)index)
  {
   temp = arr[i];
   arr[i] = '-';
  }
  else if(i>(unsigned long)index)
  {
   temp1 = arr[i];
   arr[i] = temp;
   temp = temp1;
  }
 }
}

canonical_original_code:
void insertGap(int index, unsigned long n, char arr[-1])
{
 unsigned long i;
 char temp = '\0'; char temp1 = '\0';
 if(index<0) index=0;
 for(i=0; i<n; i++)
 {
  if(i==(unsigned long)index)
  {
   temp = arr[i];
   arr[i] = '-';
  }
  else if(i>(unsigned long)index)
  {
   temp1 = arr[i];
   arr[i] = temp;
   temp = temp1;
  }
 }
}

variable_types: index int

variable_types:
n
unsigned long

variable_types:
arr
char [-1]

variable_types: temp char


align

original_code:
void
align(char sAligned[], char tAligned[], int paths[fy][fx][3])
{
 long int i = (fy-1),j = (fx-1);
 while( i>=0 && j>=0 )
 {
  if(paths[i][j][1])
  {
   i--;
   j--;
  }
  else if(paths[i][j][0])
  {
   insertGap( i,a,tAligned);
   j--;
  }
  else if(paths[i][j][2])
  {
   insertGap( j,a,sAligned);
   i--;
  }
  else break;
 }
}

canonical_original_code:
void align(char sAligned[], char tAligned[], int paths[-1][-1][3])
{
 long i = (fy-1); long j = (fx-1);
 while( i>=0 && j>=0 )
 {
  if(paths[i][j][1])
  {
   i--;
   j--;
  }
  else if(paths[i][j][0])
  {
   insertGap( i,a,tAligned);
   j--;
  }
  else if(paths[i][j][2])
  {
   insertGap( j,a,sAligned);
   i--;
  }
  else break;
 }
}

variable_types:
sAligned
char []

variable_types:
tAligned
char []

variable_types: i long

variable_types: j long


score

decompiled_code:
__int64 __fastcall score(__int64 a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rax
char v5; // cl
char v6; // dl

if ( !a )
return 0LL;
v3 = 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v4);
if ( !v5 )
break;
v6 = *(_BYTE *)(a2 + v4);
if ( !v6 )
break;
if ( v5 == v6 )
{
++v4;
v3 += m;
if ( a == v4 )
return (unsigned int)v3;
}
else
{
if ( v6 == 45 || v5 == 45 )
v3 += g;
else
v3 += mism;
if ( a == ++v4 )
return (unsigned int)v3;
}
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rax
char v5; // cl
char v6; // dl

if ( !a )
return 0LL;
v3 = 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v4);
if ( !v5 )
break;
v6 = *(_BYTE *)(a2 + v4);
if ( !v6 )
break;
if ( v5 == v6 )
{
++v4;
v3 += m;
if ( a == v4 )
return (unsigned int)v3;
}
else
{
if ( v6 == 45 || v5 == 45 )
v3 += g;
else
v3 += mism;
if ( a == ++v4 )
return (unsigned int)v3;
}
}
return (unsigned int)v3;
}

original_code:
int
score(char sAligned[a], char tAligned[a])
{
 unsigned long int i, score=0;
 for(i=0; i<a; i++)
 {
  if(sAligned[i]=='\0' || tAligned[i]=='\0') break;
  else if(sAligned[i] == tAligned[i]) score += m;
  else if(sAligned[i]=='-' || tAligned[i]=='-') score += g;
  else score+=mism;
 }
 return score;
}

canonical_original_code:
int score(char sAligned[-1], char tAligned[-1])
{
 unsigned long i; unsigned long score = 0;
 for(i=0; i<a; i++)
 {
  if(sAligned[i]=='\0' || tAligned[i]=='\0') break;
  else if(sAligned[i] == tAligned[i]) score += m;
  else if(sAligned[i]=='-' || tAligned[i]=='-') score += g;
  else score+=mism;
 }
 return score;
}

variable_types:
sAligned
char [-1]

variable_types:
tAligned
char [-1]

variable_types:
i
unsigned long

variable_types:
score
unsigned long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v4; // rdi
int v5; // eax
const char *v6; // rdi
int v7; // eax
const char *v8; // rdi
const char *v9; // r14
char *v10; // rax
const char *v11; // r12
void *v12; // rsp
void *v13; // rsp
char *v14; // r14
__int64 v15; // rbx
void *v16; // rsp
signed __int64 v17; // r12
void *v18; // rsp
void *v19; // rsp
void *v20; // rsp
unsigned __int64 v21; // rcx
unsigned __int64 v22; // r8
time_t v23; // rsi
signed __int64 v24; // rax
void *v25; // rsp
void *v26; // rsp
unsigned __int64 v27; // rax
char v28; // dl
char v29; // dl
unsigned int v30; // eax
time_t v31; // rax
double v32; // xmm0_8
char *v34; // [rsp+0h] [rbp-50h] BYREF
time_t v35; // [rsp+8h] [rbp-48h]
time_t time0; // [rsp+10h] [rbp-40h]
char *s; // [rsp+18h] [rbp-38h]

if ( argc == 3 )
{
g = -1;
m = 2;
mism = -1;
algorithm = 0;
}
else
{
if ( argc != 7 )
{
printf(
"\n"
"Incorrect usage.\n"
"Syntax: %s Sequence1(s) Sequence2(t)\n"
"\n"
"OR\n"
"\n"
"%s Sequence1(s) Sequence2(t) gapPenalty(default=-1) matchBonus(default=2) mismatchPenalty(default=-1) whichAlgor"
"ithm(default NW=0;SW=1)\n"
"\n",
*argv,
*argv);
return -1;
}
v3 = atoi(argv[3]);
v4 = argv[4];
g = v3;
v5 = atoi(v4);
v6 = argv[5];
m = v5;
v7 = atoi(v6);
v8 = argv[6];
mism = v7;
algorithm = atoi(v8);
}
v9 = argv[1];
v10 = (char *)strlen(v9);
v11 = argv[2];
sx = (__int64)v10;
s = v10;
tx = strlen(v11);
v34 = s;
time0 = tx;
v12 = alloca((signed __int64)s);
v13 = alloca(tx);
s = (char *)&v34;
strcpy((char *)&v34, v9);
strcpy((char *)&v34, v11);
v14 = v34 + 1;
v35 = time0;
fy = time0 + 1;
v15 = (_QWORD)(v34 + 1) * (time0 + 1);
time0 = (time_t)v34;
fx = (__int64)(v34 + 1);
v16 = alloca(4 * v15);
v17 = 16 * ((unsigned __int64)(12 * v15 + 15) >> 4);
memset(&v34, 0, 4 * v15);
v18 = alloca(v17);
memset(&v34, 0, 12 * v15);
v19 = alloca(8LL * (_QWORD)v14);
memset(&v34, 0, 8LL * (_QWORD)v14);
v20 = alloca(v17);
memset(&v34, 0, 12 * v15);
v21 = time0;
v22 = v35;
v23 = time0 + v35;
a = time0 + v35;
v24 = 16 * ((unsigned __int64)(time0 + v35 + 15) >> 4);
v25 = alloca(v24);
v26 = alloca(v24);
if ( time0 + v35 )
{
v27 = 0LL;
do
{
v28 = 0;
if ( v21 > v27 )
v28 = *((_BYTE *)&v34 + v27);
*((_BYTE *)&v34 + v27) = v28;
v29 = 0;
if ( v22 > v27 )
v29 = s[v27];
*((_BYTE *)&v34 + v27++) = v29;
}
while ( v23 != v27 );
}
printf("\nSequence s:\n\t");
puts((const char *)&v34);
printf("Sequence t:\n\t");
puts(s);
printf("Gap Penalty:\t% d\n", (unsigned int)g);
printf("Match Bonus:\t% d\n", (unsigned int)m);
printf("Mismatch:\t% d\n", (unsigned int)mism);
printf("Algorithm:\t");
if ( algorithm )
puts("Smith-Waterman");
else
puts("Needleman-Wunsch");
putchar(10);
time0 = time(0LL);
puts("Similarity matrix using O(n) space optimization:");
optimal = findSim1d(0, (const char *)&v34, s, &v34, (__int64)&v34);
puts("\nSimilarity matrix computed.");
printf("The optimal score is % d.\n\n", (unsigned int)optimal);
puts("Possible paths:");
print3dint(fy, fx, 3LL, &v34);
puts("Computing optimal alignment...");
align((__int64)&v34, (__int64)&v34, (__int64)&v34);
puts("Optimal global alignment computed.\n");
printf("Aligned sequence s:\n\t");
puts((const char *)&v34);
printf("Aligned sequence t:\n\t");
puts((const char *)&v34);
v30 = score((__int64)&v34, (__int64)&v34);
printf("The alignment score is: % d\n\n", v30);
v31 = time(0LL);
v32 = difftime(v31, time0);
printf("Time taken for computation: %f sec\n\n", v32);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v4; // rdi
int v5; // eax
const char *v6; // rdi
int v7; // eax
const char *v8; // rdi
const char *v9; // r14
char *v10; // rax
const char *v11; // r12
void *v12; // rsp
void *v13; // rsp
char *v14; // r14
__int64 v15; // rbx
void *v16; // rsp
signed __int64 v17; // r12
void *v18; // rsp
void *v19; // rsp
void *v20; // rsp
unsigned __int64 v21; // rcx
unsigned __int64 v22; // r8
time_t v23; // rsi
signed __int64 v24; // rax
void *v25; // rsp
void *v26; // rsp
unsigned __int64 v27; // rax
char v28; // dl
char v29; // dl
unsigned int v30; // eax
time_t v31; // rax
double v32; // xmm0_8
char *v34; // [rsp+0h] [rbp-50h] BYREF
time_t v35; // [rsp+8h] [rbp-48h]
time_t time0; // [rsp+10h] [rbp-40h]
char *s; // [rsp+18h] [rbp-38h]

if ( argc == 3 )
{
g = -1;
m = 2;
mism = -1;
algorithm = 0;
}
else
{
if ( argc != 7 )
{
printf(
"\n"
"Incorrect usage.\n"
"Syntax: %s Sequence1(s) Sequence2(t)\n"
"\n"
"OR\n"
"\n"
"%s Sequence1(s) Sequence2(t) gapPenalty(default=-1) matchBonus(default=2) mismatchPenalty(default=-1) whichAlgor"
"ithm(default NW=0;SW=1)\n"
"\n",
*argv,
*argv);
return -1;
}
v3 = atoi(argv[3]);
v4 = argv[4];
g = v3;
v5 = atoi(v4);
v6 = argv[5];
m = v5;
v7 = atoi(v6);
v8 = argv[6];
mism = v7;
algorithm = atoi(v8);
}
v9 = argv[1];
v10 = (char *)strlen(v9);
v11 = argv[2];
sx = (__int64)v10;
s = v10;
tx = strlen(v11);
v34 = s;
time0 = tx;
v12 = alloca((signed __int64)s);
v13 = alloca(tx);
s = (char *)&v34;
strcpy((char *)&v34, v9);
strcpy((char *)&v34, v11);
v14 = v34 + 1;
v35 = time0;
fy = time0 + 1;
v15 = (_QWORD)(v34 + 1) * (time0 + 1);
time0 = (time_t)v34;
fx = (__int64)(v34 + 1);
v16 = alloca(4 * v15);
v17 = 16 * ((unsigned __int64)(12 * v15 + 15) >> 4);
memset(&v34, 0, 4 * v15);
v18 = alloca(v17);
memset(&v34, 0, 12 * v15);
v19 = alloca(8LL * (_QWORD)v14);
memset(&v34, 0, 8LL * (_QWORD)v14);
v20 = alloca(v17);
memset(&v34, 0, 12 * v15);
v21 = time0;
v22 = v35;
v23 = time0 + v35;
a = time0 + v35;
v24 = 16 * ((unsigned __int64)(time0 + v35 + 15) >> 4);
v25 = alloca(v24);
v26 = alloca(v24);
if ( time0 + v35 )
{
v27 = 0LL;
do
{
v28 = 0;
if ( v21 > v27 )
v28 = *((_BYTE *)&v34 + v27);
*((_BYTE *)&v34 + v27) = v28;
v29 = 0;
if ( v22 > v27 )
v29 = s[v27];
*((_BYTE *)&v34 + v27++) = v29;
}
while ( v23 != v27 );
}
printf("\nSequence s:\n\t");
puts((const char *)&v34);
printf("Sequence t:\n\t");
puts(s);
printf("Gap Penalty:\t% d\n", (unsigned int)g);
printf("Match Bonus:\t% d\n", (unsigned int)m);
printf("Mismatch:\t% d\n", (unsigned int)mism);
printf("Algorithm:\t");
if ( algorithm )
puts("Smith-Waterman");
else
puts("Needleman-Wunsch");
putchar(10);
time0 = time(0LL);
puts("Similarity matrix using O(n) space optimization:");
optimal = func2(0, (const char *)&v34, s, &v34, (__int64)&v34);
puts("\nSimilarity matrix computed.");
printf("The optimal score is % d.\n\n", (unsigned int)optimal);
puts("Possible paths:");
print3dint(fy, fx, 3LL, &v34);
puts("Computing optimal alignment...");
func4((__int64)&v34, (__int64)&v34, (__int64)&v34);
puts("Optimal global alignment computed.\n");
printf("Aligned sequence s:\n\t");
puts((const char *)&v34);
printf("Aligned sequence t:\n\t");
puts((const char *)&v34);
v30 = func5((__int64)&v34, (__int64)&v34);
printf("The alignment score is: % d\n\n", v30);
v31 = time(0LL);
v32 = difftime(v31, time0);
printf("Time taken for computation: %f sec\n\n", v32);
return 0;
}

original_code:
int
main(int argc, char* argv[])
{
 unsigned long int i;
 time_t start, end;
 if(argc==3)
 {
  g = -1;
  m = 2;
  mism = -1;
  algorithm = 0;
 }
 else if(argc==7)
 {
  g = atoi(argv[3]);
  m = atoi(argv[4]);
  mism = atoi(argv[5]);
  algorithm = atoi(argv[6]);
 }
 else
 {
  printf("\nIncorrect usage.\nSyntax: %s Sequence1(s) Sequence2(t)\n\nOR\n\n%s Sequence1(s) Sequence2(t) gapPenalty(default=-1) matchBonus(default=2) mismatchPenalty(default=-1) whichAlgorithm(default NW=0;SW=1)\n\n", argv[0], argv[0]);
  return -1;
 }
 sx = strlen(argv[1]);
 tx = strlen(argv[2]);
 char s[sx], t[tx];
 strcpy(s,argv[1]);
 strcpy(t,argv[2]);
 fy = tx+1;
 fx = sx+1;
 int f[fy][fx];
 memset(f,0,sizeof(f));
 int paths[fy][fx][3];
 memset(paths,0,sizeof(paths));
 int f1d[2][fx];
 memset(f1d,0,sizeof(f1d));
 int pathsFrom1d[fy][fx][3];
 memset(pathsFrom1d,0,sizeof(pathsFrom1d));
 a = sx + tx;
 char sAligned[a], tAligned[a];
 for(i=0; i<a; i++)
 {
  if(i<sx) sAligned[i] = s[i];
  else sAligned[i] = '\0';
  if(i<tx) tAligned[i] = t[i];
  else tAligned[i] = '\0';
 }
 printf("\nSequence s:\n\t");
 puts(s);
 printf("Sequence t:\n\t");
 puts(t);
 printf("Gap Penalty:\t% d\n",g);
 printf("Match Bonus:\t% d\n",m);
 printf("Mismatch:\t% d\n",mism);
 printf("Algorithm:\t");
 if(algorithm==0)
  puts("Needleman-Wunsch");
 else
  puts("Smith-Waterman");
 putchar('\n');
 start = time(((void *)0));
 printf("Similarity matrix using O(n) space optimization:\n");
 optimal = findSim1d(0,0,s,t,f1d,pathsFrom1d);
 printf("\nSimilarity matrix computed.\n");
 printf("The optimal score is % d.\n\n", optimal);
 printf("Possible paths:\n");
 print3dint(fy,fx,3,pathsFrom1d);
 printf("Computing optimal alignment...\n");
 align(sAligned,tAligned,pathsFrom1d);
 printf("Optimal global alignment computed.\n\n");
 printf("Aligned sequence s:\n\t");
 puts(sAligned);
 printf("Aligned sequence t:\n\t");
 puts(tAligned);
 printf("The alignment score is:  % d\n\n", score(sAligned, tAligned) );
 end = time(((void *)0));
 printf("Time taken for computation: %f sec\n\n", difftime(end,start));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long i;
 long start; long end;
 if(argc==3)
 {
  g = -1;
  m = 2;
  mism = -1;
  algorithm = 0;
 }
 else if(argc==7)
 {
  g = atoi(argv[3]);
  m = atoi(argv[4]);
  mism = atoi(argv[5]);
  algorithm = atoi(argv[6]);
 }
 else
 {
  printf("\nIncorrect usage.\nSyntax: %s Sequence1(s) Sequence2(t)\n\nOR\n\n%s Sequence1(s) Sequence2(t) gapPenalty(default=-1) matchBonus(default=2) mismatchPenalty(default=-1) whichAlgorithm(default NW=0;SW=1)\n\n", argv[0], argv[0]);
  return -1;
 }
 sx = strlen(argv[1]);
 tx = strlen(argv[2]);
 char s[-1]; char t[-1];
 strcpy(s,argv[1]);
 strcpy(t,argv[2]);
 fy = tx+1;
 fx = sx+1;
 int f[-1][-1];
 memset(f,0,sizeof(f));
 int paths[-1][-1][3];
 memset(paths,0,sizeof(paths));
 int f1d[2][-1];
 memset(f1d,0,sizeof(f1d));
 int pathsFrom1d[-1][-1][3];
 memset(pathsFrom1d,0,sizeof(pathsFrom1d));
 a = sx + tx;
 char sAligned[-1]; char tAligned[-1];
 for(i=0; i<a; i++)
 {
  if(i<sx) sAligned[i] = s[i];
  else sAligned[i] = '\0';
  if(i<tx) tAligned[i] = t[i];
  else tAligned[i] = '\0';
 }
 printf("\nSequence s:\n\t");
 puts(s);
 printf("Sequence t:\n\t");
 puts(t);
 printf("Gap Penalty:\t% d\n",g);
 printf("Match Bonus:\t% d\n",m);
 printf("Mismatch:\t% d\n",mism);
 printf("Algorithm:\t");
 if(algorithm==0)
  puts("Needleman-Wunsch");
 else
  puts("Smith-Waterman");
 putchar('\n');
 start = time(((void *)0));
 printf("Similarity matrix using O(n) space optimization:\n");
 optimal = findSim1d(0,0,s,t,f1d,pathsFrom1d);
 printf("\nSimilarity matrix computed.\n");
 printf("The optimal score is % d.\n\n", optimal);
 printf("Possible paths:\n");
 print3dint(fy,fx,3,pathsFrom1d);
 printf("Computing optimal alignment...\n");
 align(sAligned,tAligned,pathsFrom1d);
 printf("Optimal global alignment computed.\n\n");
 printf("Aligned sequence s:\n\t");
 puts(sAligned);
 printf("Aligned sequence t:\n\t");
 puts(tAligned);
 printf("The alignment score is:  % d\n\n", score(sAligned, tAligned) );
 end = time(((void *)0));
 printf("Time taken for computation: %f sec\n\n", difftime(end,start));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: start long

variable_types: end long

variable_types:
s
char [-1]

variable_types:
t
char [-1]


repo: shmily/linux

decompiled_code:
__int64 __fastcall Get_Next_xy(int a1, int a2, int *a3, int *a4, int a5)
{
__int64 result; // rax
bool v6; // cc
int v7; // edi
int v8; // edi
int v9; // esi

result = (unsigned int)(a5 - 258);
if ( (unsigned int)result > 3 )
{
a5 = dir_in_0;
v6 = dir_in_0 <= 260;
if ( dir_in_0 != 260 )
goto LABEL_3;
LABEL_14:
v8 = a1 - 1;
result = 0LL;
if ( v8 < 0 )
v8 = 0;
*a3 = v8;
*a4 = a2;
return result;
}
dir_in_0 = a5;
v6 = a5 <= 260;
if ( a5 == 260 )
goto LABEL_14;
LABEL_3:
if ( v6 )
{
if ( a5 != 258 )
{
if ( a5 == 259 )
{
--a2;
result = 0LL;
if ( a2 < 0 )
a2 = 0;
}
goto LABEL_8;
}
v9 = a2 + 1;
result = 15LL;
*a3 = a1;
if ( v9 > 15 )
v9 = 15;
*a4 = v9;
}
else
{
if ( a5 != 261 )
{
LABEL_8:
*a3 = a1;
*a4 = a2;
return result;
}
v7 = a1 + 1;
result = 23LL;
if ( v7 > 23 )
v7 = 23;
*a3 = v7;
*a4 = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, int *a3, int *a4, int a5)
{
__int64 result; // rax
bool v6; // cc
int v7; // edi
int v8; // edi
int v9; // esi

result = (unsigned int)(a5 - 258);
if ( (unsigned int)result > 3 )
{
a5 = dir_in_0;
v6 = dir_in_0 <= 260;
if ( dir_in_0 != 260 )
goto LABEL_3;
LABEL_14:
v8 = a1 - 1;
result = 0LL;
if ( v8 < 0 )
v8 = 0;
*a3 = v8;
*a4 = a2;
return result;
}
dir_in_0 = a5;
v6 = a5 <= 260;
if ( a5 == 260 )
goto LABEL_14;
LABEL_3:
if ( v6 )
{
if ( a5 != 258 )
{
if ( a5 == 259 )
{
--a2;
result = 0LL;
if ( a2 < 0 )
a2 = 0;
}
goto LABEL_8;
}
v9 = a2 + 1;
result = 15LL;
*a3 = a1;
if ( v9 > 15 )
v9 = 15;
*a4 = v9;
}
else
{
if ( a5 != 261 )
{
LABEL_8:
*a3 = a1;
*a4 = a2;
return result;
}
v7 = a1 + 1;
result = 23LL;
if ( v7 > 23 )
v7 = 23;
*a3 = v7;
*a4 = a2;
}
return result;
}

original_code:
static void Get_Next_xy(int cur_x, int cur_y, int *next_x, int *next_y, int direction)
{
 static int dir_in = 0405;
 if((direction==0403)||(direction==0402)||(direction==0404)||(direction==0405))
 {
  dir_in = direction;
 }
 switch(dir_in){
  case 0403 :
    cur_y = cur_y - 1;
    if(cur_y<0) cur_y = 0;
    break;
  case 0402 :
    cur_y = cur_y + 1;
    if(cur_y>=16) cur_y = 16 - 1;
    break;
  case 0404 :
    cur_x = cur_x - 1;
    if(cur_x<0) cur_x = 0;
    break;
  case 0405 :
    cur_x = cur_x + 1;
    if(cur_x>=(48/2)) cur_x = (48/2) - 1;
    break;
  default :
    break;
 }
 *next_x = cur_x;
 *next_y = cur_y;
}

variable_types: direction int


decompiled_code:
__int64 random_init()
{
fp = fopen("/dev/urandom", "r");
if ( fp )
return 0LL;
fwrite("Error! Could not open /dev/urandom for read\n", 1uLL, 0x2CuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func6()
{
fp = fopen("/dev/urandom", "r");
if ( fp )
return 0LL;
fwrite("Error! Could not open /dev/urandom for read\n", 1uLL, 0x2CuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int random_init(void)
{
 if ((fp = fopen("/dev/urandom", "r")) == ((void *)0)) {
  fprintf(stderr, "Error! Could not open /dev/urandom for read\n");
  return -1;
 }
 return 0;
}

canonical_original_code:
int random_init()
{
 if ((fp = fopen("/dev/urandom", "r")) == ((void *)0)) {
  fprintf(stderr, "Error! Could not open /dev/urandom for read\n");
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall GetFood_xy(int *a1)
{
int v1; // ebx
int v2; // eax
__int64 result; // rax

v1 = fgetc(fp);
v2 = fgetc(fp);
*a1 = v1 % 24;
result = (unsigned int)(v2 % 16);
a1[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1)
{
int v1; // ebx
int v2; // eax
__int64 result; // rax

v1 = fgetc(fp);
v2 = fgetc(fp);
*a1 = v1 % 24;
result = (unsigned int)(v2 % 16);
a1[1] = result;
return result;
}

original_code:
void GetFood_xy( struct Point *pfood)
{
 int rand_x;
 int rand_y;
 rand_x = fgetc(fp);
 rand_y = fgetc(fp);
 pfood->x = rand_x%(48/2);
 pfood->y = rand_y%16;
}

canonical_original_code:
void GetFood_xy(struct Point *pfood)
{
 int rand_x;
 int rand_y;
 rand_x = fgetc(fp);
 rand_y = fgetc(fp);
 pfood->x = rand_x%(48/2);
 pfood->y = rand_y%16;
}

variable_types:
pfood
struct Point { int x; int y; } *


DrawBody

decompiled_code:
__int64 __fastcall DrawBody(int a1, __int64 a2)
{
DrawPoint((unsigned int)(2 * a1), a2, 32LL);
return DrawPoint((unsigned int)(2 * a1 + 1), (unsigned int)a2, 32LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2)
{
DrawPoint((unsigned int)(2 * a1), a2, 32LL);
return DrawPoint((unsigned int)(2 * a1 + 1), (unsigned int)a2, 32LL);
}

original_code:
void DrawBody(int x, int y)
{
 DrawPoint(x*2, y, ' ');
 DrawPoint(x*2+1, y, ' ');
}

variable_types: x int

variable_types: y int


ClearBody

decompiled_code:
__int64 __fastcall ClearBody(int a1)
{
ClearPoint((unsigned int)(2 * a1));
return ClearPoint((unsigned int)(2 * a1 + 1));
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
ClearPoint((unsigned int)(2 * a1));
return ClearPoint((unsigned int)(2 * a1 + 1));
}

original_code:
void ClearBody(int x, int y)
{
 ClearPoint(x*2, y);
 ClearPoint(x*2+1, y);
}


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

result = 0LL;
memset(&snake_mask, 0, 0x100uLL);
return result;
}

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

result = 0LL;
memset(&snake_mask, 0, 0x100uLL);
return result;
}

original_code:
void init_snakeMask(void)
{
 memset(snake_mask, 0, sizeof(snake_mask)*sizeof(int));
}

canonical_original_code:
void init_snakeMask()
{
 memset(snake_mask, 0, sizeof(snake_mask)*sizeof(int));
}


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

result = (unsigned int)(1 << a1);
snake_mask[a2] |= result;
return result;
}

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

result = (unsigned int)(1 << a1);
snake_mask[a2] |= result;
return result;
}

original_code:
void set_snakeMask(int x, int y)
{
 int tmp = 0;
 tmp = (0x01<<x);
 snake_mask[y] = (snake_mask[y] | tmp);
}

variable_types: tmp int


CreatSnake

decompiled_code:
__int64 CreatSnake()
{
int v0; // ebx
_DWORD *v1; // rax
char v2; // di
__int64 *i; // rbx

v0 = 0;
init_snakeMask();
random_init();
INIT_LIST_HEAD_constprop_0();
do
{
v1 = malloc(0x18uLL);
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = v0;
v1[1] = 4;
list_add_constprop_0((_QWORD *)v1 + 1);
v2 = v0++;
set_snakeMask(v2, 4);
}
while ( v0 != 3 );
for ( i = (__int64 *)SnakeHead; i != &SnakeHead; i = (__int64 *)*i )
DrawBody(*((_DWORD *)i - 2), *((unsigned int *)i - 1));
GetFood_xy(&food);
DrawBody(food, (unsigned int)dword_4AC);
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // ebx
_DWORD *v1; // rax
char v2; // di
__int64 *i; // rbx

v0 = 0;
func10();
func6();
func5();
do
{
v1 = malloc(0x18uLL);
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = v0;
v1[1] = 4;
func4((_QWORD *)v1 + 1);
v2 = v0++;
func11(v2, 4);
}
while ( v0 != 3 );
for ( i = (__int64 *)SnakeHead; i != &SnakeHead; i = (__int64 *)*i )
func8(*((_DWORD *)i - 2), *((unsigned int *)i - 1));
func7(&food);
func8(food, (unsigned int)dword_4AC);
return 0LL;
}

original_code:
int CreatSnake(void)
{
 int i;
 char *p;
 struct list_head *pList;
 struct SnakeBody *pSnakeBody;
 init_snakeMask();
 random_init();
 INIT_LIST_HEAD(&SnakeHead);
 for(i=0; i<3; i++){
  p = malloc(sizeof(struct SnakeBody));
  if(p==((void *)0)){
   return -1;
  }
  pSnakeBody = (struct SnakeBody *)p;
  pSnakeBody->x = i;
  pSnakeBody->y = 4;
  list_add(&(pSnakeBody->list), &SnakeHead);
  set_snakeMask(i, 4);
 }
 for (pList = (&SnakeHead)->next; pList != (&SnakeHead); pList = pList->next){
  pSnakeBody = (struct SnakeBody *)((char *)pList -((size_t) &((struct SnakeBody *)0)->list));
  DrawBody(pSnakeBody->x, pSnakeBody->y);
 }
 GetFood_xy(&food);
 DrawBody(food.x, food.y);
 return 0;
}

canonical_original_code:
int CreatSnake()
{
 int i;
 char *p;
 struct list_head *pList;
 struct SnakeBody *pSnakeBody;
 init_snakeMask();
 random_init();
 INIT_LIST_HEAD(&SnakeHead);
 for(i=0; i<3; i++){
  p = malloc(sizeof(struct SnakeBody));
  if(p==((void *)0)){
   return -1;
  }
  pSnakeBody = (struct SnakeBody *)p;
  pSnakeBody->x = i;
  pSnakeBody->y = 4;
  list_add(&(pSnakeBody->list), &SnakeHead);
  set_snakeMask(i, 4);
 }
 for (pList = (&SnakeHead)->next; pList != (&SnakeHead); pList = pList->next){
  pSnakeBody = (struct SnakeBody *)((char *)pList -((unsigned long) &((struct SnakeBody *)0)->list));
  DrawBody(pSnakeBody->x, pSnakeBody->y);
 }
 GetFood_xy(&food);
 DrawBody(food.x, food.y);
 return 0;
}

variable_types: i int

variable_types:
p
char *

variable_types: struct list_head { struct list_head *next; } *

variable_types: struct SnakeBody { int x; int y; struct list_head { struct list_head *next; } list; } *

user_defined_types: struct SnakeBody { int x; int y; struct list_head list; }


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

result = (unsigned int)__ROL4__(-2, a1);
snake_mask[a2] &= result;
return result;
}

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

result = (unsigned int)__ROL4__(-2, a1);
snake_mask[a2] &= result;
return result;
}

original_code:
void clear_snakeMask(int x, int y)
{
 int tmp = 0;
 tmp = (0x01<<x);
 tmp = ~tmp;
 snake_mask[y] = (snake_mask[y] & tmp);
}


decompiled_code:
__int64 __fastcall is_OverSnakeBody(char a1, int a2)
{
return snake_mask[a2] & (unsigned int)(1 << a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(char a1, int a2)
{
return snake_mask[a2] & (unsigned int)(1 << a1);
}

original_code:
int is_OverSnakeBody(int x, int y)
{
 int tmp = 0;
 tmp = (0x01<<x);
 return (snake_mask[y] & tmp);
}


decompiled_code:
__int64 __fastcall snake_Move(int a1)
{
unsigned int *v1; // rax
unsigned int *v2; // rbx
__int64 v3; // rbx
__int64 result; // rax
int v5; // edi
unsigned int v6; // er8
unsigned int v7; // [rsp+18h] [rbp-20h] BYREF
unsigned int v8[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v1 = (unsigned int *)malloc(0x18uLL);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = v1;
Get_Next_xy(*(_DWORD *)(SnakeHead - 8), *(_DWORD *)(SnakeHead - 4), (int *)&v7, (int *)v8, a1);
*v2 = v7;
v2[1] = v8[0];
list_add_constprop_0((_QWORD *)v2 + 1);
DrawBody(*v2, v2[1]);
set_snakeMask(*v2, v2[1]);
if ( food == v7 && dword_4AC == v8[0] )
{
do
{
GetFood_xy(&food);
v5 = food;
}
while ( (unsigned int)is_OverSnakeBody(food, dword_4AC) );
DrawBody(v5, v6);
result = 0LL;
}
else
{
v3 = qword_4B8;
ClearBody(*(_DWORD *)(qword_4B8 - 8));
clear_snakeMask(*(_DWORD *)(v3 - 8), *(_DWORD *)(v3 - 4));
list_del(qword_4B8);
free((void *)(v3 - 8));
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
unsigned int *v1; // rax
unsigned int *v2; // rbx
__int64 v3; // rbx
__int64 result; // rax
int v5; // edi
unsigned int v6; // er8
unsigned int v7; // [rsp+18h] [rbp-20h] BYREF
unsigned int v8[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v1 = (unsigned int *)malloc(0x18uLL);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = v1;
func2(*(_DWORD *)(SnakeHead - 8), *(_DWORD *)(SnakeHead - 4), (int *)&v7, (int *)v8, a1);
*v2 = v7;
v2[1] = v8[0];
func4((_QWORD *)v2 + 1);
func8(*v2, v2[1]);
func11(*v2, v2[1]);
if ( food == v7 && dword_4AC == v8[0] )
{
do
{
func7(&food);
v5 = food;
}
while ( (unsigned int)func14(food, dword_4AC) );
func8(v5, v6);
result = 0LL;
}
else
{
v3 = qword_4B8;
func9(*(_DWORD *)(qword_4B8 - 8));
func13(*(_DWORD *)(v3 - 8), *(_DWORD *)(v3 - 4));
func1(qword_4B8);
free((void *)(v3 - 8));
result = 0LL;
}
return result;
}

original_code:
int snake_Move(int direction)
{
 int next_x, next_y;
 char *p;
 struct SnakeBody *pNew;
 struct SnakeBody *pHead;
 struct SnakeBody *pTail;
 int is_cover;
 p = malloc(sizeof(struct SnakeBody));
 if(p==((void *)0)){
  return -1;
 }
 pNew = (struct SnakeBody *)p;
 pHead = (struct SnakeBody *)((char *)SnakeHead.next -((size_t) &((struct SnakeBody *)0)->list));
 Get_Next_xy(pHead->x, pHead->y, &next_x, &next_y, direction);
 pNew->x = next_x;
 pNew->y = next_y;
 list_add(&(pNew->list), &SnakeHead);
 DrawBody(pNew->x, pNew->y);
 set_snakeMask(pNew->x, pNew->y);
 if((next_x == food.x)&&(next_y == food.y)){
  do{
   GetFood_xy(&food);
   is_cover = is_OverSnakeBody(food.x, food.y);
  }while(is_cover!=0);
  DrawBody(food.x, food.y);
  return 0;
 }
 pTail = (struct SnakeBody *)((char *)SnakeHead.prev -((size_t) &((struct SnakeBody *)0)->list));
 ClearBody(pTail->x, pTail->y);
 clear_snakeMask(pTail->x, pTail->y);
 list_del(SnakeHead.prev);
 free((char *)pTail);
 return 0;
}

canonical_original_code:
int snake_Move(int direction)
{
 int next_x; int next_y;
 char *p;
 struct SnakeBody *pNew;
 struct SnakeBody *pHead;
 struct SnakeBody *pTail;
 int is_cover;
 p = malloc(sizeof(struct SnakeBody));
 if(p==((void *)0)){
  return -1;
 }
 pNew = (struct SnakeBody *)p;
 pHead = (struct SnakeBody *)((char *)SnakeHead.next -((unsigned long) &((struct SnakeBody *)0)->list));
 Get_Next_xy(pHead->x, pHead->y, &next_x, &next_y, direction);
 pNew->x = next_x;
 pNew->y = next_y;
 list_add(&(pNew->list), &SnakeHead);
 DrawBody(pNew->x, pNew->y);
 set_snakeMask(pNew->x, pNew->y);
 if((next_x == food.x)&&(next_y == food.y)){
  do{
   GetFood_xy(&food);
   is_cover = is_OverSnakeBody(food.x, food.y);
  }while(is_cover!=0);
  DrawBody(food.x, food.y);
  return 0;
 }
 pTail = (struct SnakeBody *)((char *)SnakeHead.prev -((unsigned long) &((struct SnakeBody *)0)->list));
 ClearBody(pTail->x, pTail->y);
 clear_snakeMask(pTail->x, pTail->y);
 list_del(SnakeHead.prev);
 free((char *)pTail);
 return 0;
}

user_defined_types: struct list_head { struct list_head *next; }


decompiled_code:
_BOOL8 __fastcall ip_valid(int *a1)
{
int v1; // eax
int v2; // eax
int v3; // edx
int v4; // edx
int v5; // eax

v1 = *a1;
if ( v1 > 254 || v1 == 127 || !v1 )
return 0LL;
v2 = a1[1];
v3 = a1[2];
LOBYTE(v2) = 0;
LOBYTE(v3) = 0;
v4 = v2 + v3;
v5 = a1[3];
LOBYTE(v5) = 0;
return v4 + v5 <= 0;
}

variable_types:
ip
int *

variable_types: t int


decompiled_code:
_BOOL8 __fastcall mask_valid(_DWORD *a1)
{
_BOOL4 v1; // er8

v1 = 0;
if ( (unsigned int)(*a1 - 1) <= 0xFFFFFFFD )
v1 = (~*a1 & -*a1) == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_DWORD *a1)
{
_BOOL4 v1; // er8

v1 = 0;
if ( (unsigned int)(*a1 - 1) <= 0xFFFFFFFD )
v1 = (~*a1 & -*a1) == 0;
return v1;
}

original_code:
int mask_valid(int *mask)
{
 unsigned int b;
 b = (unsigned int)*mask;
 if((b==0xFFFFFFFF)||(b==0x00)) return 0;
 b = ~b + 1;
 b = b&(b-1);
 return (b==0)?1:0;
}

variable_types:
mask
int *

variable_types:
b
unsigned int


main

original_code:
int main(void)
{
 int ip[4];
 int mask[4];
 int i, count;
 int local, _mask, tmp;
 scanf("%d.%d.%d.%d", (ip), (ip+1), (ip+2), (ip+3));
 if(ip_valid(ip) == 0){
  printf("Invalid IP adress.\n");
  exit(0);
 }
 local = (ip[0]<<24) + (ip[1]<<16) + (ip[2]<<8) + ip[3];
 scanf("%d.%d.%d.%d", (mask), (mask+1), (mask+2), (mask+3));
 _mask = (mask[0]<<24) + (mask[1]<<16) + (mask[2]<<8) + mask[3];
 if(mask_valid(&_mask) == 0){
  printf("Invalid netmask adress.\n");
  exit(0);
 }
 local = local & _mask;
 scanf("%d", &count);
 for(i=0; i<count; i++){
  scanf("%d.%d.%d.%d", (ip), (ip+1), (ip+2), (ip+3));
  if(ip_valid(ip) == 0){
   printf("Invalid IP adress.\n");
   continue;
  }
  tmp = (ip[0]<<24) + (ip[1]<<16) + (ip[2]<<8) + ip[3];
  tmp = tmp & _mask;
  if(tmp == local){
   printf("let's rock\n");
  }else{
   printf("not you\n");
  }
 }
 exit(0);
}

canonical_original_code:
int main()
{
 int ip[4];
 int mask[4];
 int i; int count;
 int local; int _mask; int tmp;
 scanf("%d.%d.%d.%d", (ip), (ip+1), (ip+2), (ip+3));
 if(ip_valid(ip) == 0){
  printf("Invalid IP adress.\n");
  exit(0);
 }
 local = (ip[0]<<24) + (ip[1]<<16) + (ip[2]<<8) + ip[3];
 scanf("%d.%d.%d.%d", (mask), (mask+1), (mask+2), (mask+3));
 _mask = (mask[0]<<24) + (mask[1]<<16) + (mask[2]<<8) + mask[3];
 if(mask_valid(&_mask) == 0){
  printf("Invalid netmask adress.\n");
  exit(0);
 }
 local = local & _mask;
 scanf("%d", &count);
 for(i=0; i<count; i++){
  scanf("%d.%d.%d.%d", (ip), (ip+1), (ip+2), (ip+3));
  if(ip_valid(ip) == 0){
   printf("Invalid IP adress.\n");
   continue;
  }
  tmp = (ip[0]<<24) + (ip[1]<<16) + (ip[2]<<8) + ip[3];
  tmp = tmp & _mask;
  if(tmp == local){
   printf("let's rock\n");
  }else{
   printf("not you\n");
  }
 }
 exit(0);
}

variable_types:
ip
int [4]

variable_types:
mask
int [4]

variable_types: count int

variable_types: local int


original_code:
int infix_init(char *pstr, int *postfix, int *mask)
{
    int count;
    int sign = 1;
    int tmp;
    int *psave;
    while(*pstr==' '){
        pstr++;
    }
    if(*pstr=='-'){
        sign = -1;
        pstr++;
    }
    psave = postfix;
    count = 0;
    tmp = 0;
    while(*pstr!='\0'){
        if((*pstr>='0')&&(*pstr<='9')){
            tmp = tmp*10 + (*pstr - '0');
            pstr++;
        }else if((*pstr=='+')||(*pstr=='-')||(*pstr=='*')||(*pstr=='/')){
            *psave++ = tmp;
            *mask++ = 1;
            *psave++ = *pstr;
            *mask++ = 0;
            count += 2;
            tmp = 0;
            pstr++;
        }else{
            pstr++;
        }
    }
 *psave++ = tmp;
 *mask++ = 1;
 count += 1;
 pstr++;
    *postfix = *postfix * sign;
    return count;
}

variable_types:
pstr
char *

variable_types:
postfix
int *

variable_types: sign int

variable_types:
psave
int *


Init

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

if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 4) = a2 - 1;
*(_DWORD *)a1 = -1;
v2 = malloc(4LL * a2);
*(_QWORD *)(a1 + 8) = v2;
return (unsigned int)-(v2 == 0LL);
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 4) = a2 - 1;
*(_DWORD *)a1 = -1;
v2 = malloc(4LL * a2);
*(_QWORD *)(a1 + 8) = v2;
return (unsigned int)-(v2 == 0LL);
}

original_code:
int Init(STACK_STRU *pThis,int nMaxSize)
{
 if (((void *)0) == pThis){
  return -1;
 }
 pThis->nMaxStackTop = nMaxSize - 1;
 pThis->nStackTop = -1;
 pThis->pNStackBuf = (int *)malloc(sizeof(int) * nMaxSize);
 if (((void *)0) == pThis->pNStackBuf){
  return -1;
 }
 return 0;
}

canonical_original_code:
int Init(struct tag_STACK_STRU *pThis, int nMaxSize)
{
 if (((void *)0) == pThis){
  return -1;
 }
 pThis->nMaxStackTop = nMaxSize - 1;
 pThis->nStackTop = -1;
 pThis->pNStackBuf = (int *)malloc(sizeof(int) * nMaxSize);
 if (((void *)0) == pThis->pNStackBuf){
  return -1;
 }
 return 0;
}

variable_types: struct tag_STACK_STRU { int nStackTop; int nMaxStackTop; int *pNStackBuf; } *

variable_types: nMaxSize int


Push

original_code:
int Push(STACK_STRU *pThis,int nValue)
{
 pThis->pNStackBuf[++(pThis->nStackTop)] = nValue;
 return 0;
}

canonical_original_code:
int Push(struct tag_STACK_STRU *pThis, int nValue)
{
 pThis->pNStackBuf[++(pThis->nStackTop)] = nValue;
 return 0;
}

variable_types: nValue int

user_defined_types: struct tag_STACK_STRU { int nStackTop; int nMaxStackTop; int *pNStackBuf; }


Pop

original_code:
int Pop(STACK_STRU *pThis)
{
 return pThis->pNStackBuf[pThis->nStackTop--];
}

canonical_original_code:
int Pop(struct tag_STACK_STRU *pThis)
{
 return pThis->pNStackBuf[pThis->nStackTop--];
}


decompiled_code:
__int64 __fastcall postfix_calu(int *a1, _DWORD *a2, int a3)
{
int v6; // eax
int v7; // er8
int v8; // edx
int v9; // esi
_DWORD *v10; // r9
int v11; // esi
_DWORD *v12; // r9

Init((__int64)g_stOperand, 10);
if ( a3 > 0 )
{
do
{
while ( *a2 == 1 )
{
v11 = *a1;
++a2;
++a1;
Push((__int64)g_stOperand, v11);
if ( a2 == v12 )
return Pop(g_stOperand);
}
Pop(g_stOperand);
v6 = Pop(g_stOperand);
v8 = *a1;
if ( *a1 == 45 )
{
v9 = v6 - v7;
goto LABEL_8;
}
if ( v8 > 45 )
{
if ( v8 != 47 )
goto LABEL_14;
v9 = v6 / v7;
}
else
{
if ( v8 == 42 )
{
v9 = v6 * v7;
goto LABEL_8;
}
if ( v8 != 43 )
{
LABEL_14:
v9 = 0;
goto LABEL_8;
}
v9 = v7 + v6;
}
LABEL_8:
++a2;
++a1;
Push((__int64)g_stOperand, v9);
}
while ( a2 != v10 );
}
return Pop(g_stOperand);
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, _DWORD *a2, int a3)
{
int v6; // eax
int v7; // er8
int v8; // edx
int v9; // esi
_DWORD *v10; // r9
int v11; // esi
_DWORD *v12; // r9

func1((__int64)g_stOperand, 10);
if ( a3 > 0 )
{
do
{
while ( *a2 == 1 )
{
v11 = *a1;
++a2;
++a1;
func2((__int64)g_stOperand, v11);
if ( a2 == v12 )
return func3(g_stOperand);
}
func3(g_stOperand);
v6 = func3(g_stOperand);
v8 = *a1;
if ( *a1 == 45 )
{
v9 = v6 - v7;
goto LABEL_8;
}
if ( v8 > 45 )
{
if ( v8 != 47 )
goto LABEL_14;
v9 = v6 / v7;
}
else
{
if ( v8 == 42 )
{
v9 = v6 * v7;
goto LABEL_8;
}
if ( v8 != 43 )
{
LABEL_14:
v9 = 0;
goto LABEL_8;
}
v9 = v7 + v6;
}
LABEL_8:
++a2;
++a1;
func2((__int64)g_stOperand, v9);
}
while ( a2 != v10 );
}
return func3(g_stOperand);
}

original_code:
int postfix_calu(int *postfix, int *mask, int count)
{
    int a1, a2, tmp;
    int i;
    Init(&g_stOperand, 10);
    for(i=0; i<count; i++){
        if(*mask==1){
            Push(&g_stOperand, *postfix);
        }else{
            tmp = 0;
            a2 = Pop(&g_stOperand);
            a1 = Pop(&g_stOperand);
            switch(*postfix){
                case '+': tmp = a1 + a2;
                          break;
                case '-': tmp = a1 - a2;
                          break;
                case '*': tmp = a1 * a2;
                          break;
                case '/': tmp = a1 / a2;
                          break;
                default: break;
            }
            Push(&g_stOperand, tmp);
        }
        mask++;
        postfix++;
    }
    return Pop(&g_stOperand);
}

canonical_original_code:
int postfix_calu(int *postfix, int *mask, int count)
{
    int a1; int a2; int tmp;
    int i;
    Init(&g_stOperand, 10);
    for(i=0; i<count; i++){
        if(*mask==1){
            Push(&g_stOperand, *postfix);
        }else{
            tmp = 0;
            a2 = Pop(&g_stOperand);
            a1 = Pop(&g_stOperand);
            switch(*postfix){
                case '+': tmp = a1 + a2;
                          break;
                case '-': tmp = a1 - a2;
                          break;
                case '*': tmp = a1 * a2;
                          break;
                case '/': tmp = a1 / a2;
                          break;
                default: break;
            }
            Push(&g_stOperand, tmp);
        }
        mask++;
        postfix++;
    }
    return Pop(&g_stOperand);
}

variable_types: tmp int

variable_types: i int


IsFull

decompiled_code:
_BOOL8 __fastcall IsFull(_DWORD *a1)
{
return a1[1] == *a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_DWORD *a1)
{
return a1[1] == *a1;
}

original_code:
int IsFull(STACK_STRU *pThis)
{
 return (pThis->nMaxStackTop == pThis->nStackTop)?1:0;
}

canonical_original_code:
int IsFull(struct tag_STACK_STRU *pThis)
{
 return (pThis->nMaxStackTop == pThis->nStackTop)?1:0;
}


IsEmpty

decompiled_code:
_BOOL8 __fastcall IsEmpty(_DWORD *a1)
{
return *a1 == -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(_DWORD *a1)
{
return *a1 == -1;
}

original_code:
int IsEmpty(STACK_STRU *pThis)
{
 return (pThis->nStackTop == -1)?1:0;
}

canonical_original_code:
int IsEmpty(struct tag_STACK_STRU *pThis)
{
 return (pThis->nStackTop == -1)?1:0;
}


original_code:
void infix2posfix(int *postfix, int *mask, int count)
{
    int buff[32];
    int flag[32];
    int i, tmp;
    int *psave, *psource, *pmask;
    memset(buff, 0, sizeof(int)*32);
    memset(flag, 0, sizeof(int)*32);
    Init(&g_stOperator, 10);
    psave = buff;
    pmask = flag;
    psource = postfix;
    for(i=0; i<count; i++){
        if(mask[i]==1){
            *psave++ = *psource;
            *pmask++ = 1;
        }else{
            if((*psource=='+')||(*psource=='-')){
                while(IsEmpty(&g_stOperator)!=1){
                    *psave++ = Pop(&g_stOperator);
                    *pmask++ = 0;
                }
                Push(&g_stOperator, *psource);
            }else{
                while(IsEmpty(&g_stOperator)!=1){
                    tmp = Pop(&g_stOperator);
                    if((tmp=='+')||(tmp=='-')){
                        Push(&g_stOperator, tmp);
                        Push(&g_stOperator, *psource);
                        break;
                    }else{
                        *psave++ = tmp;
                        *pmask++ = 0;
                    }
                }
                if(IsEmpty(&g_stOperator)==1){
     Push(&g_stOperator, *psource);
    }
            }
        }
        psource++;
    }
    while(IsEmpty(&g_stOperator)!=1){
        *psave++ = Pop(&g_stOperator);
        *pmask++ = 0;
    }
    memcpy(postfix, buff, sizeof(int)*32);
    memcpy(mask, flag, sizeof(int)*32);
}

canonical_original_code:
void infix2posfix(int *postfix, int *mask, int count)
{
    int buff[32];
    int flag[32];
    int i; int tmp;
    int *psave; int *psource; int *pmask;
    memset(buff, 0, sizeof(int)*32);
    memset(flag, 0, sizeof(int)*32);
    Init(&g_stOperator, 10);
    psave = buff;
    pmask = flag;
    psource = postfix;
    for(i=0; i<count; i++){
        if(mask[i]==1){
            *psave++ = *psource;
            *pmask++ = 1;
        }else{
            if((*psource=='+')||(*psource=='-')){
                while(IsEmpty(&g_stOperator)!=1){
                    *psave++ = Pop(&g_stOperator);
                    *pmask++ = 0;
                }
                Push(&g_stOperator, *psource);
            }else{
                while(IsEmpty(&g_stOperator)!=1){
                    tmp = Pop(&g_stOperator);
                    if((tmp=='+')||(tmp=='-')){
                        Push(&g_stOperator, tmp);
                        Push(&g_stOperator, *psource);
                        break;
                    }else{
                        *psave++ = tmp;
                        *pmask++ = 0;
                    }
                }
                if(IsEmpty(&g_stOperator)==1){
     Push(&g_stOperator, *psource);
    }
            }
        }
        psource++;
    }
    while(IsEmpty(&g_stOperator)!=1){
        *psave++ = Pop(&g_stOperator);
        *pmask++ = 0;
    }
    memcpy(postfix, buff, sizeof(int)*32);
    memcpy(mask, flag, sizeof(int)*32);
}

variable_types:
buff
int [32]

variable_types:
flag
int [32]

variable_types:
psource
int *

variable_types:
pmask
int *


Destory

decompiled_code:
__int64 __fastcall Destory(__int64 a1)
{
free(*(void **)(a1 + 8));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
free(*(void **)(a1 + 8));
return 0LL;
}

original_code:
int Destory(STACK_STRU *pThis)
{
 free(pThis->pNStackBuf);
 return 0;
}

canonical_original_code:
int Destory(struct tag_STACK_STRU *pThis)
{
 free(pThis->pNStackBuf);
 return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned int v4; // eax
__m128i v6[8]; // [rsp+0h] [rbp-308h] BYREF
__m128i v7[8]; // [rsp+80h] [rbp-288h] BYREF
char v8[520]; // [rsp+100h] [rbp-208h] BYREF

gets(v8, argv, envp);
v3 = infix_init(v8, (int *)v6, v7);
infix2posfix(v6, v7, v3);
v4 = postfix_calu((int *)v6, v7, v3);
printf("%d\n", v4);
Destory((__int64)g_stOperand);
Destory((__int64)g_stOperator);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned int v4; // eax
__m128i v6[8]; // [rsp+0h] [rbp-308h] BYREF
__m128i v7[8]; // [rsp+80h] [rbp-288h] BYREF
char v8[520]; // [rsp+100h] [rbp-208h] BYREF

gets(v8, argv, envp);
v3 = func0(v8, (int *)v6, v7);
func7(v6, v7, v3);
v4 = func4((int *)v6, v7, v3);
printf("%d\n", v4);
func8((__int64)g_stOperand);
func8((__int64)g_stOperator);
return 0;
}

original_code:
int main()
{
 char str[512];
    int postfix[32];
    int mask[32];
    int count, i;
 gets(str);
    count = infix_init(str, postfix, mask);
    infix2posfix(postfix, mask, count);
 i = postfix_calu(postfix, mask, count);
 printf("%d\n", i);
 Destory(&g_stOperand);
 Destory(&g_stOperator);
 return 0;
}

canonical_original_code:
int main()
{
 char str[512];
    int postfix[32];
    int mask[32];
    int count; int i;
 gets(str);
    count = infix_init(str, postfix, mask);
    infix2posfix(postfix, mask, count);
 i = postfix_calu(postfix, mask, count);
 printf("%d\n", i);
 Destory(&g_stOperand);
 Destory(&g_stOperator);
 return 0;
}

variable_types:
str
char [512]

variable_types:
postfix
int [32]

variable_types:
mask
int [32]


scale

original_code:
static inline signed int scale(mad_fixed_t sample)
{
    sample += (1L << (28 - 16));
    if (sample >= ((mad_fixed_t) (0x10000000L)))
    sample = ((mad_fixed_t) (0x10000000L)) - 1;
    else if (sample < -((mad_fixed_t) (0x10000000L)))
    sample = -((mad_fixed_t) (0x10000000L));
    return sample >> (28 + 1 - 16);
}

canonical_original_code:
static inline int scale(int sample)
{
    sample += (1L << (28 - 16));
    if (sample >= ((mad_fixed_t) (0x10000000L)))
    sample = ((mad_fixed_t) (0x10000000L)) - 1;
    else if (sample < -((mad_fixed_t) (0x10000000L)))
    sample = -((mad_fixed_t) (0x10000000L));
    return sample >> (28 + 1 - 16);
}

variable_types: sample int


error

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

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

original_code:
static
enum mad_flow error(void *data,
            struct mad_stream *stream, struct mad_frame *frame)
{
    return MAD_FLOW_CONTINUE;
}

variable_types:
data
void *

variable_types: struct mad_stream { unsigned char *buffer; unsigned char *bufend; unsigned long skiplen; int sync; unsigned long freerate; unsigned char *this_frame; unsigned char *next_frame; struct mad_bitptr { unsigned char *byte; unsigned short cache; unsigned short left; } ptr; struct mad_bitptr anc_ptr; unsigned int anc_bitlen; unsigned char (*main_data)[-1]; unsigned int md_len; int options; enum mad_error { MAD_ERROR_NONE=0, MAD_ERROR_BUFLEN=1, MAD_ERROR_BUFPTR=2, MAD_ERROR_NOMEM=49, MAD_ERROR_LOSTSYNC=257, MAD_ERROR_BADLAYER=258, MAD_ERROR_BADBITRATE=259, MAD_ERROR_BADSAMPLERATE=260, MAD_ERROR_BADEMPHASIS=261, MAD_ERROR_BADCRC=513, MAD_ERROR_BADBITALLOC=529, MAD_ERROR_BADSCALEFACTOR=545, MAD_ERROR_BADMODE=546, MAD_ERROR_BADFRAMELEN=561, MAD_ERROR_BADBIGVALUES=562, MAD_ERROR_BADBLOCKTYPE=563, MAD_ERROR_BADSCFSI=564, MAD_ERROR_BADDATAPTR=565, MAD_ERROR_BADPART3LEN=566, MAD_ERROR_BADHUFFTABLE=567, MAD_ERROR_BADHUFFDATA=568, MAD_ERROR_BADSTEREO=569 } error; } *

variable_types: struct mad_frame { struct mad_header { enum mad_layer { MAD_LAYER_I=1, MAD_LAYER_II=2, MAD_LAYER_III=3 } layer; enum mad_mode { MAD_MODE_SINGLE_CHANNEL=0, MAD_MODE_DUAL_CHANNEL=1, MAD_MODE_JOINT_STEREO=2, MAD_MODE_STEREO=3 } mode; int mode_extension; enum mad_emphasis { MAD_EMPHASIS_NONE=0, MAD_EMPHASIS_50_15_US=1, MAD_EMPHASIS_CCITT_J_17=3, MAD_EMPHASIS_RESERVED=2 } emphasis; unsigned long bitrate; unsigned int samplerate; unsigned short crc_check; unsigned short crc_target; int flags; int private_bits; struct mad_timer_t { long seconds; unsigned long fraction; } duration; } header; int options; int sbsample[2][36][32]; int (*overlap)[2][32][18]; } *

return_type: enum mad_flow { MAD_FLOW_CONTINUE=0, MAD_FLOW_STOP=16, MAD_FLOW_BREAK=17, MAD_FLOW_IGNORE=32 }

user_defined_types: struct mad_stream { unsigned char *buffer; unsigned char *bufend; unsigned long skiplen; int sync; unsigned long freerate; unsigned char *this_frame; unsigned char *next_frame; struct mad_bitptr ptr; struct mad_bitptr anc_ptr; unsigned int anc_bitlen; unsigned char (*main_data)[-1]; unsigned int md_len; int options; enum mad_error error; }

user_defined_types: struct mad_frame { struct mad_header header; int options; int sbsample[2][36][32]; int (*overlap)[2][32][18]; }

user_defined_types: struct mad_header { enum mad_layer layer; enum mad_mode mode; int mode_extension; enum mad_emphasis emphasis; unsigned long bitrate; unsigned int samplerate; unsigned short crc_check; unsigned short crc_target; int flags; int private_bits; struct mad_timer_t duration; }


output

original_code:
static
enum mad_flow output(void *data,
             struct mad_header const *header, struct mad_pcm *pcm)
{
    unsigned int nchannels, nsamples, n;
    mad_fixed_t const *left_ch, *right_ch;
    unsigned char Output[6912], *OutputPtr;
    int fmt, wrote, speed;
    nchannels = pcm->channels;
    n = nsamples = pcm->length;
    left_ch = pcm->samples[0];
    right_ch = pcm->samples[1];
    fmt = 0x00000010;
    speed = pcm->samplerate * 2;
    ioctl(sfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((2)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &(speed));
    ioctl(sfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((5)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &fmt);
    ioctl(sfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((6)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &(pcm->channels));
    OutputPtr = Output;
    while (nsamples--) {
    signed int sample;
    sample = scale(*left_ch++);
    *(OutputPtr++) = sample >> 0;
    *(OutputPtr++) = sample >> 8;
    if (nchannels == 2) {
        sample = scale(*right_ch++);
        *(OutputPtr++) = sample >> 0;
        *(OutputPtr++) = sample >> 8;
    }
    }
    n *= 4;
    OutputPtr = Output;
    while (n) {
    wrote = write(sfd, OutputPtr, n);
    OutputPtr += wrote;
    n -= wrote;
    }
    OutputPtr = Output;
    return MAD_FLOW_CONTINUE;
}

canonical_original_code:
static enum mad_flow output(void *data, struct mad_header *header, struct mad_pcm *pcm)
{
    unsigned int nchannels; unsigned int nsamples; unsigned int n;
    int *left_ch; int *right_ch;
    unsigned char Output[6912]; unsigned char *OutputPtr;
    int fmt; int wrote; int speed;
    nchannels = pcm->channels;
    n = nsamples = pcm->length;
    left_ch = pcm->samples[0];
    right_ch = pcm->samples[1];
    fmt = 0x00000010;
    speed = pcm->samplerate * 2;
    ioctl(sfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((2)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &(speed));
    ioctl(sfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((5)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &fmt);
    ioctl(sfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((6)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &(pcm->channels));
    OutputPtr = Output;
    while (nsamples--) {
    int sample;
    sample = scale(*left_ch++);
    *(OutputPtr++) = sample >> 0;
    *(OutputPtr++) = sample >> 8;
    if (nchannels == 2) {
        sample = scale(*right_ch++);
        *(OutputPtr++) = sample >> 0;
        *(OutputPtr++) = sample >> 8;
    }
    }
    n *= 4;
    OutputPtr = Output;
    while (n) {
    wrote = write(sfd, OutputPtr, n);
    OutputPtr += wrote;
    n -= wrote;
    }
    OutputPtr = Output;
    return MAD_FLOW_CONTINUE;
}

variable_types: struct mad_header { enum mad_layer { MAD_LAYER_I=1, MAD_LAYER_II=2, MAD_LAYER_III=3 } layer; enum mad_mode { MAD_MODE_SINGLE_CHANNEL=0, MAD_MODE_DUAL_CHANNEL=1, MAD_MODE_JOINT_STEREO=2, MAD_MODE_STEREO=3 } mode; int mode_extension; enum mad_emphasis { MAD_EMPHASIS_NONE=0, MAD_EMPHASIS_50_15_US=1, MAD_EMPHASIS_CCITT_J_17=3, MAD_EMPHASIS_RESERVED=2 } emphasis; unsigned long bitrate; unsigned int samplerate; unsigned short crc_check; unsigned short crc_target; int flags; int private_bits; struct mad_timer_t { long seconds; unsigned long fraction; } duration; } *

variable_types: struct mad_pcm { unsigned int samplerate; unsigned short channels; unsigned short length; int samples[2][1152]; } *

variable_types:
nchannels
unsigned int

variable_types:
nsamples
unsigned int

variable_types:
n
unsigned int

variable_types:
Output
unsigned char [6912]

variable_types:
OutputPtr
unsigned char *

variable_types: fmt int

variable_types: wrote int

variable_types: speed int

user_defined_types: enum mad_flow { MAD_FLOW_CONTINUE=0, MAD_FLOW_STOP=16, MAD_FLOW_BREAK=17, MAD_FLOW_IGNORE=32 }


input

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

result = 16LL;
if ( a1[1] )
{
mad_stream_buffer(a2, *a1);
a1[1] = 0LL;
result = 0LL;
}
return result;
}

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

result = 16LL;
if ( a1[1] )
{
mad_stream_buffer(a2, *a1);
a1[1] = 0LL;
result = 0LL;
}
return result;
}

original_code:
static
enum mad_flow input(void *data, struct mad_stream *stream)
{
    struct buffer *buffer = data;
    if (!buffer->length)
    return MAD_FLOW_STOP;
    mad_stream_buffer(stream, buffer->start, buffer->length);
    buffer->length = 0;
    return MAD_FLOW_CONTINUE;
}

variable_types: struct buffer { unsigned char *start; unsigned long length; } *

user_defined_types: struct mad_bitptr { unsigned char *byte; unsigned short cache; unsigned short left; }

user_defined_types: enum mad_error { MAD_ERROR_NONE=0, MAD_ERROR_BUFLEN=1, MAD_ERROR_BUFPTR=2, MAD_ERROR_NOMEM=49, MAD_ERROR_LOSTSYNC=257, MAD_ERROR_BADLAYER=258, MAD_ERROR_BADBITRATE=259, MAD_ERROR_BADSAMPLERATE=260, MAD_ERROR_BADEMPHASIS=261, MAD_ERROR_BADCRC=513, MAD_ERROR_BADBITALLOC=529, MAD_ERROR_BADSCALEFACTOR=545, MAD_ERROR_BADMODE=546, MAD_ERROR_BADFRAMELEN=561, MAD_ERROR_BADBIGVALUES=562, MAD_ERROR_BADBLOCKTYPE=563, MAD_ERROR_BADSCFSI=564, MAD_ERROR_BADDATAPTR=565, MAD_ERROR_BADPART3LEN=566, MAD_ERROR_BADHUFFTABLE=567, MAD_ERROR_BADHUFFDATA=568, MAD_ERROR_BADSTEREO=569 }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
int result; // eax
void *v6; // rax
void *v7; // rbp
int v8; // ebp
struct stat v9; // [rsp+0h] [rbp-A8h] BYREF

v3 = open(argv[1], 0, envp);
v4 = open("/dev/dsp", 1);
sfd = v4;
if ( v4 < 0 )
{
printf("can not open device!!!/n");
result = 5;
}
else
{
ioctl(v4, 0x5001uLL, 0LL);
if ( fstat(v3, &v9) == -1 )
{
result = 2;
}
else
{
result = 2;
if ( v9.st_size )
{
v6 = mmap(0LL, v9.st_size, 1, 1, v3, 0LL);
v7 = v6;
if ( v6 == (void *)-1LL )
{
result = 3;
}
else
{
decode_isra_0((__int64)v6, v9.st_size);
if ( munmap(v7, v9.st_size) == -1 )
{
result = 4;
}
else
{
v8 = sfd;
ioctl(sfd, 0x5000uLL, 0LL);
close(v8);
result = 0;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // eax
int result; // eax
void *v6; // rax
void *v7; // rbp
int v8; // ebp
struct stat v9; // [rsp+0h] [rbp-A8h] BYREF

v3 = open(argv[1], 0, envp);
v4 = open("/dev/dsp", 1);
sfd = v4;
if ( v4 < 0 )
{
printf("can not open device!!!/n");
result = 5;
}
else
{
ioctl(v4, 0x5001uLL, 0LL);
if ( fstat(v3, &v9) == -1 )
{
result = 2;
}
else
{
result = 2;
if ( v9.st_size )
{
v6 = mmap(0LL, v9.st_size, 1, 1, v3, 0LL);
v7 = v6;
if ( v6 == (void *)-1LL )
{
result = 3;
}
else
{
func4((__int64)v6, v9.st_size);
if ( munmap(v7, v9.st_size) == -1 )
{
result = 4;
}
else
{
v8 = sfd;
ioctl(sfd, 0x5000uLL, 0LL);
close(v8);
result = 0;
}
}
}
}
}
return result;
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types:
fdm
void *

variable_types:
file
char *

variable_types: fd int

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


paserInput

decompiled_code:
__int64 __fastcall paserInput(char *a1)
{
char v1; // cl
int v2; // eax
int v3; // edx
__int64 v4; // rdx
__int64 result; // rax

while ( 1 )
{
result = (unsigned int)*a1;
if ( !*a1 )
break;
v1 = a1[1];
v2 = result - 48;
v3 = 0;
if ( v1 != 84 )
v3 = (v1 != 68) + 1;
a1 += 2;
v4 = 5LL * v3;
++mahjong[2 * v4];
++mahjong[2 * v4 + v2];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // cl
int v2; // eax
int v3; // edx
__int64 v4; // rdx
__int64 result; // rax

while ( 1 )
{
result = (unsigned int)*a1;
if ( !*a1 )
break;
v1 = a1[1];
v2 = result - 48;
v3 = 0;
if ( v1 != 84 )
v3 = (v1 != 68) + 1;
a1 += 2;
v4 = 5LL * v3;
++mahjong[2 * v4];
++mahjong[2 * v4 + v2];
}
return result;
}

original_code:
void paserInput(char *str)
{
 char *p;
 int num, type;
 p = str;
 while(*p!='\0'){
  num = (*p - '0');
  if(*(p+1)=='T') { type = 0; }
  else if(*(p+1)=='D') { type = 1; }
  else { type = 2; }
  mahjong[type][0]++;
  mahjong[type][num]++;
  p +=2;
 }
}

canonical_original_code:
void paserInput(char *str)
{
 char *p;
 int num; int type;
 p = str;
 while(*p!='\0'){
  num = (*p - '0');
  if(*(p+1)=='T') { type = 0; }
  else if(*(p+1)=='D') { type = 1; }
  else { type = 2; }
  mahjong[type][0]++;
  mahjong[type][num]++;
  p +=2;
 }
}

variable_types:
str
char *

variable_types:
p
char *

variable_types: num int

variable_types: type int


original_code:
int is7pair(void)
{
    int i,j;
    for(i=0; i<3; i++){
        if(mahjong[i][0]!=0){
            for(j=1; j<10; j++){
                if(mahjong[i][j]%2!=0){
                    return -2;
                }
            }
        }
    }
    return 0;
}

canonical_original_code:
int is7pair()
{
    int i; int j;
    for(i=0; i<3; i++){
        if(mahjong[i][0]!=0){
            for(j=1; j<10; j++){
                if(mahjong[i][j]%2!=0){
                    return -2;
                }
            }
        }
    }
    return 0;
}

variable_types: i int

variable_types: j int


analyze

original_code:
int analyze(int *arry)
{
 int i, ret;
 if(arry[0]==0){
  return 0;
 }
 for(i=1; i<10; i++){
  if(arry[i]!=0) break;
 }
 if(arry[i]>=3){
  arry[i] -= 3;
  arry[0] -= 3;
  ret = analyze(arry);
  arry[i] += 3;
  arry[0] += 3;
  return ret;
 }
 if((i<8)&&(arry[i+1]>0)&&(arry[i+2]>0)){
  arry[i] -= 1;
  arry[i+1] -= 1;
  arry[i+2] -= 1;
  arry[0] -= 3;
  ret = analyze(arry);
  arry[i] += 1;
  arry[i+1] += 1;
  arry[i+2] += 1;
  arry[0] += 3;
  return ret;
 }
 return -1;
}

canonical_original_code:
int analyze(int *arry)
{
 int i; int ret;
 if(arry[0]==0){
  return 0;
 }
 for(i=1; i<10; i++){
  if(arry[i]!=0) break;
 }
 if(arry[i]>=3){
  arry[i] -= 3;
  arry[0] -= 3;
  ret = analyze(arry);
  arry[i] += 3;
  arry[0] += 3;
  return ret;
 }
 if((i<8)&&(arry[i+1]>0)&&(arry[i+2]>0)){
  arry[i] -= 1;
  arry[i+1] -= 1;
  arry[i+2] -= 1;
  arry[0] -= 3;
  ret = analyze(arry);
  arry[i] += 1;
  arry[i+1] += 1;
  arry[i+2] += 1;
  arry[0] += 3;
  return ret;
 }
 return -1;
}

variable_types:
arry
int *

variable_types: ret int


isWin

original_code:
int isWin(void)
{
 int j, i, pair, nopair;
 int ret;
 if((mahjong[0][0]+mahjong[1][0]+mahjong[2][0])!=14) return -2;
 if((mahjong[0][0]!=0)&&(mahjong[1][0]!=0)&&(mahjong[2][0]!=0)){
        return -2;
 }
 for(j=0; j<3; j++){
  if(mahjong[j][0]>4){
   for(i=1; i<10; i++){
    if(mahjong[j][i]>4){
     return -2;
    }
   }
  }
 }
 pair = -1;
 nopair = -1;
 for(i=0; i<3; i++){
  if( mahjong[i][0]%3==1 ){
   return -2;
  }else if(mahjong[i][0]%3==2){
   if(pair==-1){
    pair = i;
   }else{
    return -2;
   }
  }else{
   nopair = i;
  }
 }
 if(nopair!=-1){
  ret = analyze(mahjong[nopair]);
  if(ret!=0) return -1;
 }
 if(pair!=-1){
  for(i=1; i<10; i++){
            if(mahjong[pair][i]>=2){
                mahjong[pair][i] -= 2;
                mahjong[pair][0] -= 2;
                ret = analyze(mahjong[pair]);
                mahjong[pair][i] += 2;
                mahjong[pair][0] += 2;
                if(ret==0) break;
            }
        }
 }
    return ret;
}

canonical_original_code:
int isWin()
{
 int j; int i; int pair; int nopair;
 int ret;
 if((mahjong[0][0]+mahjong[1][0]+mahjong[2][0])!=14) return -2;
 if((mahjong[0][0]!=0)&&(mahjong[1][0]!=0)&&(mahjong[2][0]!=0)){
        return -2;
 }
 for(j=0; j<3; j++){
  if(mahjong[j][0]>4){
   for(i=1; i<10; i++){
    if(mahjong[j][i]>4){
     return -2;
    }
   }
  }
 }
 pair = -1;
 nopair = -1;
 for(i=0; i<3; i++){
  if( mahjong[i][0]%3==1 ){
   return -2;
  }else if(mahjong[i][0]%3==2){
   if(pair==-1){
    pair = i;
   }else{
    return -2;
   }
  }else{
   nopair = i;
  }
 }
 if(nopair!=-1){
  ret = analyze(mahjong[nopair]);
  if(ret!=0) return -1;
 }
 if(pair!=-1){
  for(i=1; i<10; i++){
            if(mahjong[pair][i]>=2){
                mahjong[pair][i] -= 2;
                mahjong[pair][0] -= 2;
                ret = analyze(mahjong[pair]);
                mahjong[pair][i] += 2;
                mahjong[pair][0] += 2;
                if(ret==0) break;
            }
        }
 }
    return ret;
}

variable_types: pair int

variable_types: nopair int