createServerChannel

decompiled_code:
__int64 __fastcall createServerChannel(void *src)
{
size_t v1; // rax
size_t v2; // rbx
int v3; // eax
unsigned int v4; // er12

v1 = strlen((const char *)src);
if ( v1 > 0x6C )
return (unsigned int)-11;
v2 = v1;
memcpy(sockadr.sa_data, src, v1);
*(_DWORD *)&sockadr.sa_data[v2] = 1668248420;
*(_WORD *)&sockadr.sa_data[v2 + 4] = 107;
sockadr.sa_family = 1;
unlink(sockadr.sa_data);
v3 = socket(1, 1, 0);
v4 = v3;
if ( v3 < 0 || bind(v3, &sockadr, 0x6Eu) < 0 || listen(v4, 128) < 0 )
v4 = -1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *src)
{
size_t v1; // rax
size_t v2; // rbx
int v3; // eax
unsigned int v4; // er12

v1 = strlen((const char *)src);
if ( v1 > 0x6C )
return (unsigned int)-11;
v2 = v1;
memcpy(sockadr.sa_data, src, v1);
*(_DWORD *)&sockadr.sa_data[v2] = 1668248420;
*(_WORD *)&sockadr.sa_data[v2 + 4] = 107;
sockadr.sa_family = 1;
unlink(sockadr.sa_data);
v3 = socket(1, 1, 0);
v4 = v3;
if ( v3 < 0 || bind(v3, &sockadr, 0x6Eu) < 0 || listen(v4, 128) < 0 )
v4 = -1;
return v4;
}

original_code:
serverChannel_t createServerChannel(const char *path)
{
    serverChannel_t fd_sock;
    if (strlen(path) > 108)
 return -11;
    strcpy(sockadr.sun_path, path);
    strncat(sockadr.sun_path, "dsock", strlen("dsock"));
    sockadr.sun_family = 1;
    (void) unlink(sockadr.sun_path);
    fd_sock = socket(1, SOCK_STREAM, 0);
    if (fd_sock < 0)
 return -1;
    if (bind(fd_sock, (struct sockaddr *) &sockadr, sizeof(sockadr)) < 0)
 return -1;
    if (listen(fd_sock, 128) < 0)
 return -1;
    return fd_sock;
}

canonical_original_code:
int createServerChannel(char *path)
{
    int fd_sock;
    if (strlen(path) > 108)
 return -11;
    strcpy(sockadr.sun_path, path);
    strncat(sockadr.sun_path, "dsock", strlen("dsock"));
    sockadr.sun_family = 1;
    (void) unlink(sockadr.sun_path);
    fd_sock = socket(1, SOCK_STREAM, 0);
    if (fd_sock < 0)
 return -1;
    if (bind(fd_sock, (struct sockaddr *) &sockadr, sizeof(sockadr)) < 0)
 return -1;
    if (listen(fd_sock, 128) < 0)
 return -1;
    return fd_sock;
}

variable_types:
path
char *

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


closeSocket

repo: dbacarel/Dplan

decompiled_code:
__int64 __fastcall closeSocket(int a1)
{
unsigned int v1; // er12

v1 = close(a1);
unlink(sockadr.sa_data);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned int v1; // er12

v1 = close(a1);
unlink(sockadr.sa_data);
return v1;
}

original_code:
int closeSocket(serverChannel_t s)
{
    int i;
    i = close(s);
    (void) unlink(sockadr.sun_path);
    return i;
}

canonical_original_code:
int closeSocket(int s)
{
    int i;
    i = close(s);
    (void) unlink(sockadr.sun_path);
    return i;
}

variable_types: s int

variable_types: i int

return_type: int


acceptConnection

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

if ( a1 < 0 )
{
*_errno_location() = 22;
result = -1;
}
else
{
result = accept(a1, 0LL, 0LL);
if ( result < 0 )
result = -1;
}
return result;
}

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

if ( a1 < 0 )
{
*_errno_location() = 22;
result = -1;
}
else
{
result = accept(a1, 0LL, 0LL);
if ( result < 0 )
result = -1;
}
return result;
}

original_code:
channel_t acceptConnection(serverChannel_t s)
{
    channel_t fd_client;
    if (s < 0) {
 (*__errno_location ()) = 22;
 return -1;
    }
    fd_client = accept(s, ((void *)0), 0);
    if (fd_client < 0)
 return -1;
    return fd_client;
}

canonical_original_code:
int acceptConnection(int s)
{
    int fd_client;
    if (s < 0) {
 (*__errno_location ()) = 22;
 return -1;
    }
    fd_client = accept(s, ((void *)0), 0);
    if (fd_client < 0)
 return -1;
    return fd_client;
}


receiveMessage

decompiled_code:
__int64 __fastcall receiveMessage(int fd, _QWORD *a2)
{
int v2; // eax
int v3; // eax
size_t v4; // r12
void *v5; // rax
int v6; // eax

if ( a2 )
{
v2 = read(fd, a2, 8uLL);
if ( v2 >= 0 )
{
if ( !v2 )
return 4294967294LL;
v3 = read(fd, (char *)a2 + 4, 8uLL);
if ( v3 >= 0 )
{
if ( v3 )
{
v4 = *((unsigned int *)a2 + 1);
v5 = malloc(v4);
a2[1] = v5;
if ( v5 )
{
v6 = read(fd, v5, v4);
if ( v6 >= 0 )
{
if ( v6 )
return *((unsigned int *)a2 + 1);
return 4294967294LL;
}
}
else
{
*_errno_location() = 12;
perror("LCSCOM: Allocating memory for message's buffer ");
}
return 0xFFFFFFFFLL;
}
return 4294967294LL;
}
}
return 0xFFFFFFFFLL;
}
*_errno_location() = 22;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, _QWORD *a2)
{
int v2; // eax
int v3; // eax
size_t v4; // r12
void *v5; // rax
int v6; // eax

if ( a2 )
{
v2 = read(fd, a2, 8uLL);
if ( v2 >= 0 )
{
if ( !v2 )
return 4294967294LL;
v3 = read(fd, (char *)a2 + 4, 8uLL);
if ( v3 >= 0 )
{
if ( v3 )
{
v4 = *((unsigned int *)a2 + 1);
v5 = malloc(v4);
a2[1] = v5;
if ( v5 )
{
v6 = read(fd, v5, v4);
if ( v6 >= 0 )
{
if ( v6 )
return *((unsigned int *)a2 + 1);
return 4294967294LL;
}
}
else
{
*_errno_location() = 12;
perror("LCSCOM: Allocating memory for message's buffer ");
}
return 0xFFFFFFFFLL;
}
return 4294967294LL;
}
}
return 0xFFFFFFFFLL;
}
*_errno_location() = 22;
return 0xFFFFFFFFLL;
}

original_code:
int receiveMessage(channel_t sc, message_t * msg)
{
    int c;
    if (msg == ((void *)0)) {
 (*__errno_location ()) = 22;
 return -1;
    }
    c = read(sc, &(msg->type), sizeof(&(msg->type)));
    if(c < 0 ) {return -1;};
    if(c == 0 ) {return -2;};
    c = read(sc, &(msg->length), sizeof(&(msg->length)));
    if(c < 0 ) {return -1;};
    if(c == 0 ) {return -2;};
    msg->buffer = (char *) malloc(sizeof(char) * msg->length);
    if (msg->buffer == ((void *)0)) {
 (*__errno_location ()) = 12;
 perror("LCSCOM: Allocating memory for message's buffer ");
 return -1;
    }
    c = read(sc, msg->buffer, msg->length);
    if(c < 0 ) {return -1;};
    if(c == 0 ) {return -2;};
    return msg->length;
}

canonical_original_code:
int receiveMessage(int sc, struct message_t *msg)
{
    int c;
    if (msg == ((void *)0)) {
 (*__errno_location ()) = 22;
 return -1;
    }
    c = read(sc, &(msg->type), sizeof(&(msg->type)));
    if(c < 0 ) {return -1;};
    if(c == 0 ) {return -2;};
    c = read(sc, &(msg->length), sizeof(&(msg->length)));
    if(c < 0 ) {return -1;};
    if(c == 0 ) {return -2;};
    msg->buffer = (char *) malloc(sizeof(char) * msg->length);
    if (msg->buffer == ((void *)0)) {
 (*__errno_location ()) = 12;
 perror("LCSCOM: Allocating memory for message's buffer ");
 return -1;
    }
    c = read(sc, msg->buffer, msg->length);
    if(c < 0 ) {return -1;};
    if(c == 0 ) {return -2;};
    return msg->length;
}

variable_types: sc int

variable_types: struct message_t { char type; unsigned int length; char *buffer; } *

variable_types: c int


sendMessage

decompiled_code:
ssize_t __fastcall sendMessage(int fd, const void **a2)
{
ssize_t result; // rax

if ( !a2 )
BUG();
if ( (int)write(fd, a2, 8uLL) < 0 || (int)write(fd, (char *)a2 + 4, 8uLL) < 0 )
return 0xFFFFFFFFLL;
result = write(fd, a2[1], *((unsigned int *)a2 + 1));
if ( (int)result < 0 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func4(int fd, const void **a2)
{
ssize_t result; // rax

if ( !a2 )
BUG();
if ( (int)write(fd, a2, 8uLL) < 0 || (int)write(fd, (char *)a2 + 4, 8uLL) < 0 )
return 0xFFFFFFFFLL;
result = write(fd, a2[1], *((unsigned int *)a2 + 1));
if ( (int)result < 0 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int sendMessage(channel_t sc, message_t * msg)
{
    int c;
    if (msg == ((void *)0) && msg->buffer == ((void *)0)) {
 (*__errno_location ()) = 22;
 return -1;
    }
    c = write(sc, &(msg->type), sizeof(&(msg->type)));
    if(c < 0 ) {return -1;};
    c = write(sc, &(msg->length), sizeof(&(msg->length)));
    if(c < 0 ) {return -1;};
    c = write(sc, msg->buffer, msg->length);
    if(c < 0 ) {return -1;};
    return c;
}

canonical_original_code:
int sendMessage(int sc, struct message_t *msg)
{
    int c;
    if (msg == ((void *)0) && msg->buffer == ((void *)0)) {
 (*__errno_location ()) = 22;
 return -1;
    }
    c = write(sc, &(msg->type), sizeof(&(msg->type)));
    if(c < 0 ) {return -1;};
    c = write(sc, &(msg->length), sizeof(&(msg->length)));
    if(c < 0 ) {return -1;};
    c = write(sc, msg->buffer, msg->length);
    if(c < 0 ) {return -1;};
    return c;
}

user_defined_types: struct message_t { char type; unsigned int length; char *buffer; }


closeConnection

decompiled_code:
// attributes: thunk
int closeConnection(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int func5(int fd)
{
return close(fd);
}

original_code:
int closeConnection(channel_t sc)
{
    return close(sc);
}

canonical_original_code:
int closeConnection(int sc)
{
    return close(sc);
}


openConnection

decompiled_code:
__int64 __fastcall openConnection(const char *a1)
{
int v1; // eax
unsigned int v2; // er12
struct sockaddr v4[7]; // [rsp+0h] [rbp-78h] BYREF

if ( strlen(a1) > 0x6C )
{
v2 = -11;
*_errno_location() = 36;
}
else
{
strcpy(v4[0].sa_data, "./tmp/dsock");
v4[0].sa_family = 1;
v1 = socket(1, 1, 0);
v2 = v1;
if ( v1 < 0 || connect(v1, v4, 0x6Eu) < 0 )
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
int v1; // eax
unsigned int v2; // er12
struct sockaddr v4[7]; // [rsp+0h] [rbp-78h] BYREF

if ( strlen(a1) > 0x6C )
{
v2 = -11;
*_errno_location() = 36;
}
else
{
strcpy(v4[0].sa_data, "./tmp/dsock");
v4[0].sa_family = 1;
v1 = socket(1, 1, 0);
v2 = v1;
if ( v1 < 0 || connect(v1, v4, 0x6Eu) < 0 )
v2 = -1;
}
return v2;
}

original_code:
channel_t openConnection(const char *path)
{
    struct sockaddr_un sock;
    channel_t fd_sock;
    if (strlen(path) > 108) {
 (*__errno_location ()) = 36;
 return -11;
    }
    strcpy(sock.sun_path, "./tmp/");
    strncat(sock.sun_path, "dsock", strlen("dsock"));
    sock.sun_family = 1;
    fd_sock = socket(1, SOCK_STREAM, 0);
    if(fd_sock < 0 ) {return -1;};
    if(connect(fd_sock, (struct sockaddr *) &sock, sizeof(sockadr)) < 0 ) {return -1;};
    return fd_sock;
}

canonical_original_code:
int openConnection(char *path)
{
    struct sockaddr_un sock;
    int fd_sock;
    if (strlen(path) > 108) {
 (*__errno_location ()) = 36;
 return -11;
    }
    strcpy(sock.sun_path, "./tmp/");
    strncat(sock.sun_path, "dsock", strlen("dsock"));
    sock.sun_family = 1;
    fd_sock = socket(1, SOCK_STREAM, 0);
    if(fd_sock < 0 ) {return -1;};
    if(connect(fd_sock, (struct sockaddr *) &sock, sizeof(sockadr)) < 0 ) {return -1;};
    return fd_sock;
}

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


printHelp

decompiled_code:
int printHelp()
{
puts(
"Usage: dplan [ agenda [ -d gg-mm-aaaa -u utente#descrizione] [ -g gg-mm-aaaa ] [ -m mm-aaaa ] [ -r pattern ] ] [-cq aname]");
puts(aCCreaUnaNuovaA);
puts(aQRimuoveUnaAge);
puts("\t-d\tspecifica la data");
puts(aUSpecificaL);
puts(aGRichiedeGliEv);
puts(aMRichiedeGliEv);
return puts(aREliminaTuttiG);
}

canonical_decompiled_code:
int func0()
{
puts(
"Usage: dplan [ agenda [ -d gg-mm-aaaa -u utente#descrizione] [ -g gg-mm-aaaa ] [ -m mm-aaaa ] [ -r pattern ] ] [-cq aname]");
puts(aCCreaUnaNuovaA);
puts(aQRimuoveUnaAge);
puts("\t-d\tspecifica la data");
puts(aUSpecificaL);
puts(aGRichiedeGliEv);
puts(aMRichiedeGliEv);
return puts(aREliminaTuttiG);
}

original_code:
void printHelp(void)
{
    printf
 ("Usage:  dplan [ agenda [ -d gg-mm-aaaa -u utente#descrizione] [ -g gg-mm-aaaa ] [ -m mm-aaaa ] [ -r pattern ]  ] [-cq aname]\n");
    printf("\t-c\tcrea una nuova agenda di nome ‘‘aname’’\n");
    printf
 ("\t-q\trimuove una agenda di nome ‘‘aname’’ (solo se vuota)\n");
    printf("\t-d\tspecifica la data\n");
    printf
 ("\t-u\tspecifica l’utente che sta effettuando la registrazione e la descrizione dell’evento\n");
    printf
 ("\t-g\trichiede gli eventi registrati per un certo giorno su ‘‘agenda’’ e li stampa sullo stdout\n");
    printf
 ("\t-m\trichiede gli eventi registrati su ‘‘agenda’’ per un certo mese e li stampa sullo stdout\n");
    printf
 ("\t-r\telimina tutti gli eventi di ‘‘agenda’’ che contengono ‘‘pattern’’ come sottostringa in un qualsiasi campo\n");
}

canonical_original_code:
void printHelp()
{
    printf
 ("Usage:  dplan [ agenda [ -d gg-mm-aaaa -u utente#descrizione] [ -g gg-mm-aaaa ] [ -m mm-aaaa ] [ -r pattern ]  ] [-cq aname]\n");
    printf("\t-c\tcrea una nuova agenda di nome ‘‘aname’’\n");
    printf
 ("\t-q\trimuove una agenda di nome ‘‘aname’’ (solo se vuota)\n");
    printf("\t-d\tspecifica la data\n");
    printf
 ("\t-u\tspecifica l’utente che sta effettuando la registrazione e la descrizione dell’evento\n");
    printf
 ("\t-g\trichiede gli eventi registrati per un certo giorno su ‘‘agenda’’ e li stampa sullo stdout\n");
    printf
 ("\t-m\trichiede gli eventi registrati su ‘‘agenda’’ per un certo mese e li stampa sullo stdout\n");
    printf
 ("\t-r\telimina tutti gli eventi di ‘‘agenda’’ che contengono ‘‘pattern’’ come sottostringa in un qualsiasi campo\n");
}

return_type: void


getBufferString

decompiled_code:
char *__fastcall getBufferString(int a1, const char *a2, __int64 a3, _DWORD *a4)
{
char *v6; // r12
size_t v7; // rax
size_t v8; // rax
const char *v9; // r13
int v10; // ebx
char *v11; // r14
size_t v12; // rax
size_t v14; // rax
int v15; // ebx
size_t v16; // rax
size_t v17; // rax
const char *v18; // r14
char *v19; // rbx
size_t v20; // rax
size_t v21; // rax
char *v22; // r15
char *v23; // r13
size_t v24; // rax
size_t v25; // rax
char *v26; // r15
char *v27; // r13
size_t v28; // rax
size_t v29; // rax
size_t v30; // rax
size_t v31; // rax
size_t v32; // rax
int v33; // [rsp+8h] [rbp-40h]

v6 = (char *)malloc(0x7AuLL);
switch ( a1 )
{
case 'C':
case 'Q':
v14 = strlen(a2);
v15 = v14;
strncpy(v6, a2, v14 + 1);
*a4 = v15 + 1;
return v6;
case 'D':
v16 = strlen(a2);
strncpy(v6, a2, v16 + 1);
v17 = strlen(v6);
v18 = *(const char **)a3;
v19 = &v6[v17 + 1];
v33 = v17;
v20 = strlen(*(const char **)a3);
strncpy(v19, v18, v20 + 1);
v21 = strlen(v19);
v22 = &v19[v21 + 1];
LODWORD(v18) = v21;
v23 = strtok(*(char **)(a3 + 8), "#");
v24 = strlen(v23);
strncpy(v22, v23, v24 + 1);
v25 = strlen(v22);
v26 = &v22[v25 + 1];
LODWORD(v19) = v25;
v27 = strtok(0LL, "#");
v28 = strlen(v27);
strncpy(v26, v27, v28 + 1);
*a4 = strlen(v26) + (_DWORD)v19 + v33 + (_DWORD)v18 + 4;
return v6;
case 'G':
v29 = strlen(a2);
strncpy(v6, a2, v29 + 1);
v30 = strlen(v6);
v9 = *(const char **)(a3 + 40);
v10 = v30;
v11 = &v6[v30 + 1];
goto LABEL_3;
case 'M':
v31 = strlen(a2);
strncpy(v6, a2, v31 + 1);
v32 = strlen(v6);
v9 = *(const char **)(a3 + 48);
v10 = v32;
v11 = &v6[v32 + 1];
goto LABEL_3;
case 'R':
v7 = strlen(a2);
strncpy(v6, a2, v7 + 1);
v8 = strlen(v6);
v9 = *(const char **)(a3 + 32);
v10 = v8;
v11 = &v6[v8 + 1];
LABEL_3:
v12 = strlen(v9);
strncpy(v11, v9, v12 + 1);
*a4 = v10 + strlen(v11) + 2;
break;
default:
return v6;
}
return v6;
}

canonical_decompiled_code:
char *__fastcall func1(int a1, const char *a2, __int64 a3, _DWORD *a4)
{
char *v6; // r12
size_t v7; // rax
size_t v8; // rax
const char *v9; // r13
int v10; // ebx
char *v11; // r14
size_t v12; // rax
size_t v14; // rax
int v15; // ebx
size_t v16; // rax
size_t v17; // rax
const char *v18; // r14
char *v19; // rbx
size_t v20; // rax
size_t v21; // rax
char *v22; // r15
char *v23; // r13
size_t v24; // rax
size_t v25; // rax
char *v26; // r15
char *v27; // r13
size_t v28; // rax
size_t v29; // rax
size_t v30; // rax
size_t v31; // rax
size_t v32; // rax
int v33; // [rsp+8h] [rbp-40h]

v6 = (char *)malloc(0x7AuLL);
switch ( a1 )
{
case 'C':
case 'Q':
v14 = strlen(a2);
v15 = v14;
strncpy(v6, a2, v14 + 1);
*a4 = v15 + 1;
return v6;
case 'D':
v16 = strlen(a2);
strncpy(v6, a2, v16 + 1);
v17 = strlen(v6);
v18 = *(const char **)a3;
v19 = &v6[v17 + 1];
v33 = v17;
v20 = strlen(*(const char **)a3);
strncpy(v19, v18, v20 + 1);
v21 = strlen(v19);
v22 = &v19[v21 + 1];
LODWORD(v18) = v21;
v23 = strtok(*(char **)(a3 + 8), "#");
v24 = strlen(v23);
strncpy(v22, v23, v24 + 1);
v25 = strlen(v22);
v26 = &v22[v25 + 1];
LODWORD(v19) = v25;
v27 = strtok(0LL, "#");
v28 = strlen(v27);
strncpy(v26, v27, v28 + 1);
*a4 = strlen(v26) + (_DWORD)v19 + v33 + (_DWORD)v18 + 4;
return v6;
case 'G':
v29 = strlen(a2);
strncpy(v6, a2, v29 + 1);
v30 = strlen(v6);
v9 = *(const char **)(a3 + 40);
v10 = v30;
v11 = &v6[v30 + 1];
goto LABEL_3;
case 'M':
v31 = strlen(a2);
strncpy(v6, a2, v31 + 1);
v32 = strlen(v6);
v9 = *(const char **)(a3 + 48);
v10 = v32;
v11 = &v6[v32 + 1];
goto LABEL_3;
case 'R':
v7 = strlen(a2);
strncpy(v6, a2, v7 + 1);
v8 = strlen(v6);
v9 = *(const char **)(a3 + 32);
v10 = v8;
v11 = &v6[v8 + 1];
LABEL_3:
v12 = strlen(v9);
strncpy(v11, v9, v12 + 1);
*a4 = v10 + strlen(v11) + 2;
break;
default:
return v6;
}
return v6;
}

original_code:
char *getBufferString(int tipo, char *agenda, char **args,
        unsigned int *length)
{
    char *stringa, *tmp, *g;
    int i;
    i = 0;
    stringa = (char *) malloc(sizeof(char) * (20 + 100 + 2));
    switch (tipo) {
    case 'C':
 strncpy(stringa, agenda, strlen(agenda) + 1);
 *length = strlen(agenda) + 1;
 break;
    case 'Q':
 strncpy(stringa, agenda, strlen(agenda) + 1);
 *length = strlen(agenda) + 1;
 break;
    case 'R':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[4], strlen(args[4]) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 break;
    case 'D':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[0], strlen(args[0]) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 g = strtok(args[1], "#");
 strncpy(tmp, g, strlen(g) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 g = strtok(((void *)0), "#");
 strncpy(tmp, g, strlen(g) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 return stringa;
 break;
    case 'G':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[5], strlen(args[5]) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 break;
    case 'M':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[6], strlen(args[6]) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 break;
    }
    return stringa;
}

canonical_original_code:
char *getBufferString(int tipo, char *agenda, char **args, unsigned int *length)
{
    char *stringa; char *tmp; char *g;
    int i;
    i = 0;
    stringa = (char *) malloc(sizeof(char) * (20 + 100 + 2));
    switch (tipo) {
    case 'C':
 strncpy(stringa, agenda, strlen(agenda) + 1);
 *length = strlen(agenda) + 1;
 break;
    case 'Q':
 strncpy(stringa, agenda, strlen(agenda) + 1);
 *length = strlen(agenda) + 1;
 break;
    case 'R':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[4], strlen(args[4]) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 break;
    case 'D':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[0], strlen(args[0]) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 g = strtok(args[1], "#");
 strncpy(tmp, g, strlen(g) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 g = strtok(((void *)0), "#");
 strncpy(tmp, g, strlen(g) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 return stringa;
 break;
    case 'G':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[5], strlen(args[5]) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 break;
    case 'M':
 tmp = stringa;
 strncpy(tmp, agenda, strlen(agenda) + 1);
 i += strlen(tmp) + 1;
 tmp = &(tmp[strlen(tmp) + 1]);
 strncpy(tmp, args[6], strlen(args[6]) + 1);
 i += strlen(tmp) + 1;
 *length = i;
 break;
    }
    return stringa;
}

variable_types: tipo int

variable_types:
agenda
char *

variable_types:
args
char **

variable_types:
length
unsigned int *

variable_types:
stringa
char *

variable_types:
tmp
char *

variable_types:
g
char *

return_type: char *


checkOpts

decompiled_code:
_BOOL8 __fastcall checkOpts(_WORD *a1, unsigned int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( !a1[a2] )
{
result = 1LL;
if ( (a2 <= 1 || !*a1 && !a1[1]) && !a1[2] && !a1[3] && !a1[4] )
{
result = 1LL;
if ( !a1[5] )
result = a1[6] != 0;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_WORD *a1, unsigned int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( !a1[a2] )
{
result = 1LL;
if ( (a2 <= 1 || !*a1 && !a1[1]) && !a1[2] && !a1[3] && !a1[4] )
{
result = 1LL;
if ( !a1[5] )
result = a1[6] != 0;
}
}
return result;
}

original_code:
int checkOpts(short int *flags, int indice)
{
    if (flags[indice])
 return 0;
    if (indice == 0 || indice == 1)
 return (flags[2] || flags[3] || flags[4] || flags[5] || flags[6]);
    else
 return (flags[0] || flags[1] || flags[2] || flags[3] || flags[4]
  || flags[5] || flags[6]);
}

canonical_original_code:
int checkOpts(short *flags, int indice)
{
    if (flags[indice])
 return 0;
    if (indice == 0 || indice == 1)
 return (flags[2] || flags[3] || flags[4] || flags[5] || flags[6]);
    else
 return (flags[0] || flags[1] || flags[2] || flags[3] || flags[4]
  || flags[5] || flags[6]);
}

variable_types:
flags
short *

variable_types: indice int


checkDate

decompiled_code:
__int64 __fastcall checkDate(int a1, const char *a2)
{
__int64 result; // rax
char nptr[2]; // [rsp+6h] [rbp-12h] BYREF
char v4; // [rsp+8h] [rbp-10h]
char v5[3]; // [rsp+9h] [rbp-Fh] BYREF
int v6; // [rsp+Ch] [rbp-Ch] BYREF

v4 = 0;
LOBYTE(v6) = 0;
if ( a1 )
{
if ( (unsigned int)_isoc99_sscanf(a2, "%2c-%2c-%d", nptr, v5, &v6) != 3
|| (unsigned int)(atoi(nptr) - 1) > 0x1E && (nptr[0] != 42 || nptr[1] != 42 || v4)
|| (unsigned int)(atoi(v5) - 1) > 0xB )
{
goto LABEL_6;
}
}
else if ( (unsigned int)_isoc99_sscanf(a2, "%2c-%d", nptr, &v6) != 2 || (unsigned int)(atoi(nptr) - 1) > 0xB )
{
goto LABEL_6;
}
result = 0LL;
if ( v6 <= 1999 )
{
LABEL_6:
printf("dplan: %s: Data non corretta\n", a2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, const char *a2)
{
__int64 result; // rax
char nptr[2]; // [rsp+6h] [rbp-12h] BYREF
char v4; // [rsp+8h] [rbp-10h]
char v5[3]; // [rsp+9h] [rbp-Fh] BYREF
int v6; // [rsp+Ch] [rbp-Ch] BYREF

v4 = 0;
LOBYTE(v6) = 0;
if ( a1 )
{
if ( (unsigned int)_isoc99_sscanf(a2, "%2c-%2c-%d", nptr, v5, &v6) != 3
|| (unsigned int)(atoi(nptr) - 1) > 0x1E && (nptr[0] != 42 || nptr[1] != 42 || v4)
|| (unsigned int)(atoi(v5) - 1) > 0xB )
{
goto LABEL_6;
}
}
else if ( (unsigned int)_isoc99_sscanf(a2, "%2c-%d", nptr, &v6) != 2 || (unsigned int)(atoi(nptr) - 1) > 0xB )
{
goto LABEL_6;
}
result = 0LL;
if ( v6 <= 1999 )
{
LABEL_6:
printf("dplan: %s: Data non corretta\n", a2);
result = 1LL;
}
return result;
}

original_code:
int checkDate(int type, char *date)
{
    int a, tmp;
    char g[3], m[3];
    g[2] = '\0';
    m[3] = '\0';
    if (type) {
 if ((tmp = sscanf(date, "%2c-%2c-%d", g, m, &a)) == 3) {
     if (((atoi(g) > 0 && atoi(g) < 32) || strcmp(g, "**") == 0)
  && (atoi(m)
      > 0 && atoi(m) < 13) && (a >= 2000))
  return 0;
     else
  printf("dplan: %s: Data non corretta\n", date);
 } else
     printf("dplan: %s: Data non corretta\n", date);
    } else {
 if ((tmp = sscanf(date, "%2c-%d", g, &a)) == 2) {
     if ((atoi(g) > 0 && atoi(g) < 13) && (a >= 2000))
  return 0;
     else
  printf("dplan: %s: Data non corretta\n", date);
 } else
     printf("dplan: %s: Data non corretta\n", date);
    }
    return 1;
}

canonical_original_code:
int checkDate(int type, char *date)
{
    int a; int tmp;
    char g[3]; char m[3];
    g[2] = '\0';
    m[3] = '\0';
    if (type) {
 if ((tmp = sscanf(date, "%2c-%2c-%d", g, m, &a)) == 3) {
     if (((atoi(g) > 0 && atoi(g) < 32) || strcmp(g, "**") == 0)
  && (atoi(m)
      > 0 && atoi(m) < 13) && (a >= 2000))
  return 0;
     else
  printf("dplan: %s: Data non corretta\n", date);
 } else
     printf("dplan: %s: Data non corretta\n", date);
    } else {
 if ((tmp = sscanf(date, "%2c-%d", g, &a)) == 2) {
     if ((atoi(g) > 0 && atoi(g) < 13) && (a >= 2000))
  return 0;
     else
  printf("dplan: %s: Data non corretta\n", date);
 } else
     printf("dplan: %s: Data non corretta\n", date);
    }
    return 1;
}

variable_types: type int

variable_types:
date
char *

variable_types: a int

variable_types: tmp int

variable_types:
g
char [3]

variable_types:
m
char [3]


checkArgs

decompiled_code:
__int64 __fastcall checkArgs(_WORD *a1, int a2, __int64 a3, const char **a4, const char **a5)
{
_WORD *v5; // rbp
int v8; // ebx
const char **v9; // r15
const char *v10; // r12
int v11; // ebx
char *v13; // r12
char *v14; // rdi
char v16; // [rsp+1Fh] [rbp-A9h] BYREF
char dest[168]; // [rsp+20h] [rbp-A8h] BYREF

*a5 = 0LL;
if ( a2 <= 1 )
goto LABEL_26;
v5 = a1;
v8 = 1;
while ( 1 )
{
v9 = (const char **)(a3 + 8LL * v8);
if ( !(unsigned int)_isoc99_sscanf(*v9, "-%c", &v16) )
break;
if ( !a1[2] )
v8 += a1[3] == 0;
if ( a2 <= ++v8 )
{
if ( *a5 )
goto LABEL_10;
LABEL_26:
puts("dplan: Formato scorretto del comando");
exit(1);
}
}
v10 = *v9;
if ( strlen(*v9) > 0x14 )
{
printf("dplan: %s: Agenda max 20 caratteri\n", v10);
return 0xFFFFFFFFLL;
}
*a5 = v10;
LABEL_10:
v11 = 1;
while ( 2 )
{
if ( !*v5 )
{
LABEL_14:
if ( v11 == 7 )
return 0LL;
goto LABEL_15;
}
switch ( v11 )
{
case 1:
if ( !(unsigned int)checkDate(1, *a4) )
goto LABEL_15;
return 0xFFFFFFFFLL;
case 2:
strncpy(dest, a4[1], 0x6EuLL);
v13 = strtok(dest, "#");
if ( strlen(v13) <= 8 )
{
v14 = strtok(0LL, "#");
if ( !v14 )
{
printf("dplan: %s: Formato evento non corretto (manca #)\n", a4[1]);
return 0xFFFFFFFFLL;
}
if ( strlen(v14) > 0x50 )
{
printf("dplan: %s: Formato evento non corretto (Descrizione max 80 caratteri)\n", a4[1]);
return 0xFFFFFFFFLL;
}
if ( strtok(0LL, "#") )
return 0xFFFFFFFFLL;
LABEL_15:
++v5;
++v11;
continue;
}
printf("dplan: %s: Formato evento non corretto (Utente max 8 caratteri)\n", v13);
return 0xFFFFFFFFLL;
case 3:
case 4:
return 0LL;
case 6:
if ( !(unsigned int)checkDate(1, a4[5]) )
goto LABEL_15;
return 0xFFFFFFFFLL;
case 7:
return (unsigned int)-((unsigned int)checkDate(0, a4[6]) != 0);
default:
goto LABEL_14;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func4(_WORD *a1, int a2, __int64 a3, const char **a4, const char **a5)
{
_WORD *v5; // rbp
int v8; // ebx
const char **v9; // r15
const char *v10; // r12
int v11; // ebx
char *v13; // r12
char *v14; // rdi
char v16; // [rsp+1Fh] [rbp-A9h] BYREF
char dest[168]; // [rsp+20h] [rbp-A8h] BYREF

*a5 = 0LL;
if ( a2 <= 1 )
goto LABEL_26;
v5 = a1;
v8 = 1;
while ( 1 )
{
v9 = (const char **)(a3 + 8LL * v8);
if ( !(unsigned int)_isoc99_sscanf(*v9, "-%c", &v16) )
break;
if ( !a1[2] )
v8 += a1[3] == 0;
if ( a2 <= ++v8 )
{
if ( *a5 )
goto LABEL_10;
LABEL_26:
puts("dplan: Formato scorretto del comando");
exit(1);
}
}
v10 = *v9;
if ( strlen(*v9) > 0x14 )
{
printf("dplan: %s: Agenda max 20 caratteri\n", v10);
return 0xFFFFFFFFLL;
}
*a5 = v10;
LABEL_10:
v11 = 1;
while ( 2 )
{
if ( !*v5 )
{
LABEL_14:
if ( v11 == 7 )
return 0LL;
goto LABEL_15;
}
switch ( v11 )
{
case 1:
if ( !(unsigned int)func3(1, *a4) )
goto LABEL_15;
return 0xFFFFFFFFLL;
case 2:
strncpy(dest, a4[1], 0x6EuLL);
v13 = strtok(dest, "#");
if ( strlen(v13) <= 8 )
{
v14 = strtok(0LL, "#");
if ( !v14 )
{
printf("dplan: %s: Formato evento non corretto (manca #)\n", a4[1]);
return 0xFFFFFFFFLL;
}
if ( strlen(v14) > 0x50 )
{
printf("dplan: %s: Formato evento non corretto (Descrizione max 80 caratteri)\n", a4[1]);
return 0xFFFFFFFFLL;
}
if ( strtok(0LL, "#") )
return 0xFFFFFFFFLL;
LABEL_15:
++v5;
++v11;
continue;
}
printf("dplan: %s: Formato evento non corretto (Utente max 8 caratteri)\n", v13);
return 0xFFFFFFFFLL;
case 3:
case 4:
return 0LL;
case 6:
if ( !(unsigned int)func3(1, a4[5]) )
goto LABEL_15;
return 0xFFFFFFFFLL;
case 7:
return (unsigned int)-((unsigned int)func3(0, a4[6]) != 0);
default:
goto LABEL_14;
}
}
}

original_code:
int checkArgs(short int *flags, int argc, char **argv, char **args,
       char **agenda)
{
    int i;
    char *buf;
    char tmp;
    char tmp2[110];
    *agenda = ((void *)0);
    buf = ((void *)0);
    for (i = 1; i < argc; i++) {
 if (sscanf(argv[i], "-%c", &tmp)) {
     if (flags[2] || flags[3]);
     else
  i += 1;
 } else {
     if (strlen(argv[i]) > 20) {
  printf("dplan: %s: Agenda max 20 caratteri\n", argv[i]);
  return -1;
     } else {
  *agenda = argv[i];
  break;
     }
 }
    }
    if (*agenda == ((void *)0)) {
 { printf("dplan: Formato scorretto del comando\n"); exit(1);};
    }
    for (i = 0; i < 7; i++) {
 if (flags[i]) {
     switch (i) {
     case 2:
  return 0;
  break;
     case 0:
  if (checkDate(1, args[i]))
      return -1;
  break;
     case 3:
  return 0;
  break;
     case 4:
  break;
     case 5:
  if (checkDate(1, args[i]))
      return -1;
  break;
     case 6:
  if (checkDate(0, args[i]))
      return -1;
  break;
     case 1:
  strncpy(tmp2, args[i], 110);
  buf = strtok(tmp2, "#");
  if (strlen(buf) <= 8) {
      buf = strtok(((void *)0), "#");
      if (!buf) {
   printf
       ("dplan: %s: Formato evento non corretto (manca #)\n",
        args[i]);
   return -1;
      }
      if (!(strlen(buf) <= 80)) {
   printf
       ("dplan: %s: Formato evento non corretto (Descrizione max 80 caratteri)\n",
        args[i]);
   return -1;
      }
      if (strtok(((void *)0), "#"))
   return -1;
  } else {
      printf
   ("dplan: %s: Formato evento non corretto (Utente max 8 caratteri)\n",
    buf);
      return -1;
  }
  break;
     }
 }
    }
    return 0;
}

canonical_original_code:
int checkArgs(short *flags, int argc, char **argv, char **args, char **agenda)
{
    int i;
    char *buf;
    char tmp;
    char tmp2[110];
    *agenda = ((void *)0);
    buf = ((void *)0);
    for (i = 1; i < argc; i++) {
 if (sscanf(argv[i], "-%c", &tmp)) {
     if (flags[2] || flags[3]);
     else
  i += 1;
 } else {
     if (strlen(argv[i]) > 20) {
  printf("dplan: %s: Agenda max 20 caratteri\n", argv[i]);
  return -1;
     } else {
  *agenda = argv[i];
  break;
     }
 }
    }
    if (*agenda == ((void *)0)) {
 { printf("dplan: Formato scorretto del comando\n"); exit(1);};
    }
    for (i = 0; i < 7; i++) {
 if (flags[i]) {
     switch (i) {
     case 2:
  return 0;
  break;
     case 0:
  if (checkDate(1, args[i]))
      return -1;
  break;
     case 3:
  return 0;
  break;
     case 4:
  break;
     case 5:
  if (checkDate(1, args[i]))
      return -1;
  break;
     case 6:
  if (checkDate(0, args[i]))
      return -1;
  break;
     case 1:
  strncpy(tmp2, args[i], 110);
  buf = strtok(tmp2, "#");
  if (strlen(buf) <= 8) {
      buf = strtok(((void *)0), "#");
      if (!buf) {
   printf
       ("dplan: %s: Formato evento non corretto (manca #)\n",
        args[i]);
   return -1;
      }
      if (!(strlen(buf) <= 80)) {
   printf
       ("dplan: %s: Formato evento non corretto (Descrizione max 80 caratteri)\n",
        args[i]);
   return -1;
      }
      if (strtok(((void *)0), "#"))
   return -1;
  } else {
      printf
   ("dplan: %s: Formato evento non corretto (Utente max 8 caratteri)\n",
    buf);
      return -1;
  }
  break;
     }
 }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
agenda
char **

variable_types: i int

variable_types:
buf
char *

variable_types: tmp char


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

result = 0LL;
if ( (unsigned __int8)(a1 - 69) <= 0x12u )
result = (0x44201uLL >> (a1 - 69)) & 1;
return result;
}

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

result = 0LL;
if ( (unsigned __int8)(a1 - 69) <= 0x12u )
result = (0x44201uLL >> (a1 - 69)) & 1;
return result;
}

original_code:
static inline int is_cardinal(char a) {
 return a == 'N' || a == 'S' || a == 'E' || a == 'W';
}

variable_types: a char


decompiled_code:
_BOOL8 __fastcall compare_delim(char *a1, char *a2)
{
char v4; // dl
char v5; // si
char v6; // al

if ( !a1 || !a2 )
return 0LL;
v4 = *a1;
v5 = *a2;
if ( *a1 )
{
while ( v5 )
{
if ( v4 != v5 && (!(unsigned int)is_cardinal(v4) || !(unsigned int)is_cardinal(v5)) )
return 0LL;
v6 = v4;
do
++v6;
while ( v6 == 32 );
*a1 = v6;
v5 = *a2;
do
++v5;
while ( v5 == 32 );
*a2 = v5;
v4 = *a1;
if ( !*a1 )
return v4 == v5;
}
}
return v4 == v5;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(char *a1, char *a2)
{
char v4; // dl
char v5; // si
char v6; // al

if ( !a1 || !a2 )
return 0LL;
v4 = *a1;
v5 = *a2;
if ( *a1 )
{
while ( v5 )
{
if ( v4 != v5 && (!(unsigned int)func7(v4) || !(unsigned int)func7(v5)) )
return 0LL;
v6 = v4;
do
++v6;
while ( v6 == 32 );
*a1 = v6;
v5 = *a2;
do
++v5;
while ( v5 == 32 );
*a2 = v5;
v4 = *a1;
if ( !*a1 )
return v4 == v5;
}
}
return v4 == v5;
}

original_code:
static int compare_delim(char* a, char* b) {
 if (a == ((void *)0) || b == ((void *)0)) {
  return 0;
 }
 while (*a != '\0' && *b != '\0') {
  if (*a == *b || (is_cardinal(*a) && is_cardinal(*b))) {
   while( ++*a == ' ') {};
   while( ++*b == ' ') {};
  } else {
   return 0;
  }
 }
 return *a == *b;
}

canonical_original_code:
static int compare_delim(char *a, char *b) {
 if (a == ((void *)0) || b == ((void *)0)) {
  return 0;
 }
 while (*a != '\0' && *b != '\0') {
  if (*a == *b || (is_cardinal(*a) && is_cardinal(*b))) {
   while( ++*a == ' ') {};
   while( ++*b == ' ') {};
  } else {
   return 0;
  }
 }
 return *a == *b;
}

variable_types:
a
char *

variable_types:
b
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
int v5; // er15
unsigned int v6; // eax
int v7; // er14
unsigned int v8; // eax
int *v9; // r12
int *v10; // rbp
int *v11; // rbx
int *v12; // r13
unsigned int v13; // eax
__int64 v14; // rax
int v15; // ecx
__int64 v16; // rdx
double v17; // xmm0_8
double v18; // xmm1_8
double v19; // xmm0_8
int v20; // eax
double v21; // xmm1_8
double v22; // xmm0_8
double v23; // xmm1_8
double v24; // xmm0_8
int v25; // eax
double v26; // xmm1_8
FILE *v27; // r15
unsigned int *v28; // r14
__int64 v29; // rdx
int result; // eax
unsigned __int64 v31; // rdx
unsigned __int64 v32; // rdx
unsigned int *ptr; // [rsp+0h] [rbp-2FB8h]
int fd; // [rsp+8h] [rbp-2FB0h]
double fda; // [rsp+8h] [rbp-2FB0h]
double v36; // [rsp+10h] [rbp-2FA8h]
double v37; // [rsp+18h] [rbp-2FA0h]
double v38; // [rsp+20h] [rbp-2F98h]
double v39; // [rsp+28h] [rbp-2F90h]
double v40; // [rsp+30h] [rbp-2F88h]
int v41; // [rsp+38h] [rbp-2F80h]
int v42; // [rsp+3Ch] [rbp-2F7Ch]
__int64 buf; // [rsp+40h] [rbp-2F78h] BYREF
unsigned __int64 v44; // [rsp+48h] [rbp-2F70h] BYREF
__int64 v45; // [rsp+50h] [rbp-2F68h] BYREF
unsigned __int64 v46; // [rsp+58h] [rbp-2F60h] BYREF
__int64 v47; // [rsp+60h] [rbp-2F58h] BYREF
unsigned __int64 v48; // [rsp+68h] [rbp-2F50h] BYREF
__int64 v49; // [rsp+70h] [rbp-2F48h] BYREF
unsigned __int64 v50; // [rsp+78h] [rbp-2F40h] BYREF
char v51[3008]; // [rsp+80h] [rbp-2F38h] BYREF
char v52[3008]; // [rsp+C40h] [rbp-2378h] BYREF
char v53[3008]; // [rsp+1800h] [rbp-17B8h] BYREF
char v54[3064]; // [rsp+23C0h] [rbp-BF8h] BYREF

byte_404128 &= 0xFEu;
attr = 0;
qword_404108 = 0LL;
v3 = getpid();
fd = perf_event_open(&attr, v3, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL);
if ( fd < 0 )
perror("Opening performance counter");
byte_404198 &= 0xFEu;
dword_404170 = 0;
qword_404178 = 5LL;
v4 = getpid();
v5 = perf_event_open(&dword_404170, v4, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL);
if ( v5 < 0 )
perror("Opening performance counter");
byte_404208 &= 0xFEu;
dword_4041E0 = 0;
qword_4041E8 = 4LL;
v6 = getpid();
v7 = perf_event_open(&dword_4041E0, v6, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL);
if ( v7 < 0 )
perror("Opening performance counter");
byte_404278 &= 0xFEu;
dword_404250 = 0;
qword_404258 = 1LL;
v8 = getpid();
v41 = perf_event_open(&dword_404250, v8, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL);
if ( v41 < 0 )
perror("Opening performance counter");
if ( argc == 5 )
{
v36 = atof(argv[1]);
v37 = atof(argv[2]);
v38 = atof(argv[3]);
v39 = atof(argv[4]);
v9 = (int *)malloc(0x17D78400uLL);
v10 = (int *)malloc(0x17D78400uLL);
v11 = (int *)malloc(0x17D78400uLL);
v12 = (int *)malloc(0x17D78400uLL);
ptr = (unsigned int *)malloc(0x17D78400uLL);
v13 = time(0LL);
srand(v13);
createData(v51, v36);
createData(v52, v37);
createData(v53, v38);
createData(v54, v39);
createOffsets(v9);
createOffsets(v10);
createOffsets(v11);
createOffsets(v12);
puts("Loop start!");
fflush(stdout);
v40 = get_timestamp(0.0);
if ( !(unsigned int)read(fd, &buf, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Au, "main");
if ( !(unsigned int)read(v5, &v44, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Bu, "main");
if ( !(unsigned int)read(v7, &v45, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Cu, "main");
if ( !(unsigned int)read(v41, &v46, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Du, "main");
v14 = 0LL;
v15 = 0;
do
{
if ( v54[v12[v14]] && v53[v11[v14]] && v52[v10[v14]] && v51[v9[v14]] )
{
v16 = v15++;
ptr[v16] = v14;
}
++v14;
}
while ( v14 != 100000000 );
v42 = v15;
if ( !(unsigned int)read(fd, &v47, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x9Du, "main");
if ( !(unsigned int)read(v5, &v48, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x9Eu, "main");
if ( !(unsigned int)read(v7, &v49, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x9Fu, "main");
if ( !(unsigned int)read(v41, &v50, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0xA0u, "main");
close(fd);
close(v5);
close(v7);
close(v41);
fda = get_timestamp(v40);
puts("Loop stop!");
printf("Elapsed time: %.9lf seconds\n", fda);
printf("CPU Cycles: %lu \n", v47 - buf);
printf("Instructions: %lu \n", v50 - v46);
if ( (v50 & 0x8000000000000000LL) != 0LL )
v17 = (double)(int)(v50 & 1 | (v50 >> 1)) + (double)(int)(v50 & 1 | (v50 >> 1));
else
v17 = (double)(int)v50;
if ( (v46 & 0x8000000000000000LL) != 0LL )
v18 = (double)(int)(v46 & 1 | (v46 >> 1)) + (double)(int)(v46 & 1 | (v46 >> 1));
else
v18 = (double)(int)v46;
v19 = v17 - v18;
v20 = v47 - buf;
if ( v47 - buf < 0 )
{
v32 = v20 & 1 | ((unsigned __int64)(v47 - buf) >> 1);
v21 = (double)(int)v32 + (double)(int)v32;
}
else
{
v21 = (double)v20;
}
printf("IPC: %lf\n", v19 / v21);
printf("Branch misses: %lu \n", v48 - v44);
printf("Branch instructions: %lu \n", v49 - v45);
if ( (v48 & 0x8000000000000000LL) != 0LL )
v22 = (double)(int)(v48 & 1 | (v48 >> 1)) + (double)(int)(v48 & 1 | (v48 >> 1));
else
v22 = (double)(int)v48;
if ( (v44 & 0x8000000000000000LL) != 0LL )
v23 = (double)(int)(v44 & 1 | (v44 >> 1)) + (double)(int)(v44 & 1 | (v44 >> 1));
else
v23 = (double)(int)v44;
v24 = (v22 - v23) * 100.0;
v25 = v49 - v45;
if ( v49 - v45 < 0 )
{
v31 = v25 & 1 | ((unsigned __int64)(v49 - v45) >> 1);
v26 = (double)(int)v31 + (double)(int)v31;
}
else
{
v26 = (double)v25;
}
printf("Branch mispred. rate: %lf%%\n", v24 / v26);
putchar(10);
printf("overall selectivity = %10.9f\n", (double)v42 / 100000000.0);
printf("theoretical selectivity = %10.9f\n", v36 * v37 * v38 * v39);
v27 = fopen("/dev/null", "w");
if ( v42 )
{
v28 = ptr;
do
{
v29 = *v28++;
fprintf(v27, "%d ", v29);
}
while ( &ptr[v42 - 1 + 1] != v28 );
}
fclose(v27);
free(v9);
free(v10);
free(v11);
free(v12);
free(ptr);
result = 0;
}
else
{
puts("argument error!");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
int v5; // er15
unsigned int v6; // eax
int v7; // er14
unsigned int v8; // eax
int *v9; // r12
int *v10; // rbp
int *v11; // rbx
int *v12; // r13
unsigned int v13; // eax
__int64 v14; // rax
int v15; // ecx
__int64 v16; // rdx
double v17; // xmm0_8
double v18; // xmm1_8
double v19; // xmm0_8
int v20; // eax
double v21; // xmm1_8
double v22; // xmm0_8
double v23; // xmm1_8
double v24; // xmm0_8
int v25; // eax
double v26; // xmm1_8
FILE *v27; // r15
unsigned int *v28; // r14
__int64 v29; // rdx
int result; // eax
unsigned __int64 v31; // rdx
unsigned __int64 v32; // rdx
unsigned int *ptr; // [rsp+0h] [rbp-2FB8h]
int fd; // [rsp+8h] [rbp-2FB0h]
double fda; // [rsp+8h] [rbp-2FB0h]
double v36; // [rsp+10h] [rbp-2FA8h]
double v37; // [rsp+18h] [rbp-2FA0h]
double v38; // [rsp+20h] [rbp-2F98h]
double v39; // [rsp+28h] [rbp-2F90h]
double v40; // [rsp+30h] [rbp-2F88h]
int v41; // [rsp+38h] [rbp-2F80h]
int v42; // [rsp+3Ch] [rbp-2F7Ch]
__int64 buf; // [rsp+40h] [rbp-2F78h] BYREF
unsigned __int64 v44; // [rsp+48h] [rbp-2F70h] BYREF
__int64 v45; // [rsp+50h] [rbp-2F68h] BYREF
unsigned __int64 v46; // [rsp+58h] [rbp-2F60h] BYREF
__int64 v47; // [rsp+60h] [rbp-2F58h] BYREF
unsigned __int64 v48; // [rsp+68h] [rbp-2F50h] BYREF
__int64 v49; // [rsp+70h] [rbp-2F48h] BYREF
unsigned __int64 v50; // [rsp+78h] [rbp-2F40h] BYREF
char v51[3008]; // [rsp+80h] [rbp-2F38h] BYREF
char v52[3008]; // [rsp+C40h] [rbp-2378h] BYREF
char v53[3008]; // [rsp+1800h] [rbp-17B8h] BYREF
char v54[3064]; // [rsp+23C0h] [rbp-BF8h] BYREF

byte_404128 &= 0xFEu;
attr = 0;
qword_404108 = 0LL;
v3 = getpid();
fd = func7(&attr, v3, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL);
if ( fd < 0 )
perror("Opening performance counter");
byte_404198 &= 0xFEu;
dword_404170 = 0;
qword_404178 = 5LL;
v4 = getpid();
v5 = func7(&dword_404170, v4, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL);
if ( v5 < 0 )
perror("Opening performance counter");
byte_404208 &= 0xFEu;
dword_4041E0 = 0;
qword_4041E8 = 4LL;
v6 = getpid();
v7 = func7(&dword_4041E0, v6, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL);
if ( v7 < 0 )
perror("Opening performance counter");
byte_404278 &= 0xFEu;
dword_404250 = 0;
qword_404258 = 1LL;
v8 = getpid();
v41 = func7(&dword_404250, v8, 0xFFFFFFFFLL, 0xFFFFFFFFLL, 0LL);
if ( v41 < 0 )
perror("Opening performance counter");
if ( argc == 5 )
{
v36 = atof(argv[1]);
v37 = atof(argv[2]);
v38 = atof(argv[3]);
v39 = atof(argv[4]);
v9 = (int *)malloc(0x17D78400uLL);
v10 = (int *)malloc(0x17D78400uLL);
v11 = (int *)malloc(0x17D78400uLL);
v12 = (int *)malloc(0x17D78400uLL);
ptr = (unsigned int *)malloc(0x17D78400uLL);
v13 = time(0LL);
srand(v13);
func9(v51, v36);
func9(v52, v37);
func9(v53, v38);
func9(v54, v39);
func10(v9);
func10(v10);
func10(v11);
func10(v12);
puts("Loop start!");
fflush(stdout);
v40 = func8(0.0);
if ( !(unsigned int)read(fd, &buf, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Au, "main");
if ( !(unsigned int)read(v5, &v44, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Bu, "main");
if ( !(unsigned int)read(v7, &v45, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Cu, "main");
if ( !(unsigned int)read(v41, &v46, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x8Du, "main");
v14 = 0LL;
v15 = 0;
do
{
if ( v54[v12[v14]] && v53[v11[v14]] && v52[v10[v14]] && v51[v9[v14]] )
{
v16 = v15++;
ptr[v16] = v14;
}
++v14;
}
while ( v14 != 100000000 );
v42 = v15;
if ( !(unsigned int)read(fd, &v47, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x9Du, "main");
if ( !(unsigned int)read(v5, &v48, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x9Eu, "main");
if ( !(unsigned int)read(v7, &v49, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0x9Fu, "main");
if ( !(unsigned int)read(v41, &v50, 8uLL) )
__assert_fail("rc", "branch_mispred.c", 0xA0u, "main");
close(fd);
close(v5);
close(v7);
close(v41);
fda = func8(v40);
puts("Loop stop!");
printf("Elapsed time: %.9lf seconds\n", fda);
printf("CPU Cycles: %lu \n", v47 - buf);
printf("Instructions: %lu \n", v50 - v46);
if ( (v50 & 0x8000000000000000LL) != 0LL )
v17 = (double)(int)(v50 & 1 | (v50 >> 1)) + (double)(int)(v50 & 1 | (v50 >> 1));
else
v17 = (double)(int)v50;
if ( (v46 & 0x8000000000000000LL) != 0LL )
v18 = (double)(int)(v46 & 1 | (v46 >> 1)) + (double)(int)(v46 & 1 | (v46 >> 1));
else
v18 = (double)(int)v46;
v19 = v17 - v18;
v20 = v47 - buf;
if ( v47 - buf < 0 )
{
v32 = v20 & 1 | ((unsigned __int64)(v47 - buf) >> 1);
v21 = (double)(int)v32 + (double)(int)v32;
}
else
{
v21 = (double)v20;
}
printf("IPC: %lf\n", v19 / v21);
printf("Branch misses: %lu \n", v48 - v44);
printf("Branch instructions: %lu \n", v49 - v45);
if ( (v48 & 0x8000000000000000LL) != 0LL )
v22 = (double)(int)(v48 & 1 | (v48 >> 1)) + (double)(int)(v48 & 1 | (v48 >> 1));
else
v22 = (double)(int)v48;
if ( (v44 & 0x8000000000000000LL) != 0LL )
v23 = (double)(int)(v44 & 1 | (v44 >> 1)) + (double)(int)(v44 & 1 | (v44 >> 1));
else
v23 = (double)(int)v44;
v24 = (v22 - v23) * 100.0;
v25 = v49 - v45;
if ( v49 - v45 < 0 )
{
v31 = v25 & 1 | ((unsigned __int64)(v49 - v45) >> 1);
v26 = (double)(int)v31 + (double)(int)v31;
}
else
{
v26 = (double)v25;
}
printf("Branch mispred. rate: %lf%%\n", v24 / v26);
putchar(10);
printf("overall selectivity = %10.9f\n", (double)v42 / 100000000.0);
printf("theoretical selectivity = %10.9f\n", v36 * v37 * v38 * v39);
v27 = fopen("/dev/null", "w");
if ( v42 )
{
v28 = ptr;
do
{
v29 = *v28++;
fprintf(v27, "%d ", v29);
}
while ( &ptr[v42 - 1 + 1] != v28 );
}
fclose(v27);
free(v9);
free(v10);
free(v11);
free(v12);
free(ptr);
result = 0;
}
else
{
puts("argument error!");
result = -1;
}
return result;
}

original_code:
int main(int argc, char * argv[])
{
  int num_runs = 0;
  int num_filters[1000] = {-99.0};
  float selectivities[1000][15];
  init_array(selectivities);
  struct sel_conf sc;
  if (argc != 3) {
    printf("usage: ./selconds <query_file> <config_file>\n");
    exit(1);
  }
  num_runs = parse_query_file(argv[1], num_filters, selectivities);
  parse_config_file(argv[2], &sc);
  int run_idx;
  printf("==========================================================================================\n");
  for (run_idx = 0; run_idx < num_runs; run_idx++) {
    compute_best_plan(num_filters[run_idx], &sc, selectivities[run_idx]);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int num_runs = 0;
  int num_filters[1000] = {-99.0};
  float selectivities[1000][15];
  init_array(selectivities);
  struct sel_conf sc;
  if (argc != 3) {
    printf("usage: ./selconds <query_file> <config_file>\n");
    exit(1);
  }
  num_runs = parse_query_file(argv[1], num_filters, selectivities);
  parse_config_file(argv[2], &sc);
  int run_idx;
  printf("==========================================================================================\n");
  for (run_idx = 0; run_idx < num_runs; run_idx++) {
    compute_best_plan(num_filters[run_idx], &sc, selectivities[run_idx]);
  }
  return 0;
}

variable_types:
argv
char *[]

variable_types:
selectivities
float [1000][15]

variable_types: struct sel_conf { int r; int t; int l; int m; int a; int f; }


decompiled_code:
double __fastcall get_timestamp(double a1)
{
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

if ( !gettimeofday(&tv, 0LL) )
return (double)SLODWORD(tv.tv_usec) * 0.000001 + (double)SLODWORD(tv.tv_sec) - a1;
printf("Failed to get time stamp");
return -1.0;
}

canonical_decompiled_code:
double __fastcall func8(double a1)
{
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

if ( !gettimeofday(&tv, 0LL) )
return (double)SLODWORD(tv.tv_usec) * 0.000001 + (double)SLODWORD(tv.tv_sec) - a1;
printf("Failed to get time stamp");
return -1.0;
}

original_code:
double get_timestamp(double start_time) {
  struct timeval tp;
  if (gettimeofday(&tp, ((void *)0)) == 0) {
    return (double)tp.tv_sec + (double)tp.tv_usec * 1e-6 - start_time;
  } else {
    printf("Failed to get time stamp");
    return -1.0f;
  }
}

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

return_type: double


createData

original_code:
char * createData(double selectivity, char * data) {
  int i;
  double r;
  for(i = 0; i < 3000; i++) {
    r = ((double)rand() / ((double)(2147483647) + (double)(1)));
    if(r < selectivity) {
      *data = 1;
    } else {
      *data = 0;
    }
    data++;
  }
  *data = '\0';
  return data;
}

canonical_original_code:
char *createData(double selectivity, char *data) {
  int i;
  double r;
  for(i = 0; i < 3000; i++) {
    r = ((double)rand() / ((double)(2147483647) + (double)(1)));
    if(r < selectivity) {
      *data = 1;
    } else {
      *data = 0;
    }
    data++;
  }
  *data = '\0';
  return data;
}

variable_types: selectivity double

variable_types:
data
char *

variable_types: r double


createOffsets

original_code:
int createOffsets(int * off) {
  int i;
  for(i = 0; i < 100000000; i++) {
    double r = ((double)rand() / ((double)(2147483647) + (double)(1)));
    off[i] = (int)(r * (double)3000);
  }
  return 0;
}

canonical_original_code:
int createOffsets(int *off) {
  int i;
  for(i = 0; i < 100000000; i++) {
    double r = ((double)rand() / ((double)(2147483647) + (double)(1)));
    off[i] = (int)(r * (double)3000);
  }
  return 0;
}

variable_types:
off
int *


main

repo: dbittman/basil

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *v4; // r12
FILE *v5; // rbp
void *v6; // rax
_BYTE *v7; // rdx
int v8; // eax
unsigned __int8 *v9; // rax
__int64 v10; // rsi
__int64 v11; // rdx
unsigned int v12; // ebp
struct stat v14; // [rsp+0h] [rbp-A8h] BYREF

opterr = 0;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "vVbh");
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'b':
little_endian = 0;
break;
case 'v':
verbose = 1;
break;
case 'V':
very_verbose = 1;
break;
default:
goto LABEL_7;
}
}
v4 = (char *)argv[optind];
if ( !v4 )
LABEL_7:
usage();
if ( argc <= 1 || (setbuf(stdout, 0LL), signal(2, sigint), (v5 = fopen(v4, "r")) == 0LL) )
exit(1);
if ( (unsigned int)stat(v4, &v14) == -1 )
{
perror("stat");
exit(3);
}
v6 = malloc(v14.st_size);
program = (__int64)v6;
if ( !v6 || (pc_8 = (__int64)v6, stack = (__int64)malloc(0x1000uLL), (qword_404258 = stack) == 0) )
{
perror("malloc");
exit(3);
}
while ( 1 )
{
v8 = fgetc(v5);
if ( v8 == -1 )
break;
v7 = (_BYTE *)pc_8++;
*v7 = v8;
}
max = pc_8;
fclose(v5);
v9 = (unsigned __int8 *)program;
pc_4 = 0;
v10 = (unsigned int)counter;
pc_8 = program;
if ( program < (unsigned __int64)max )
{
v11 = 0LL;
do
{
if ( little_endian )
{
if ( !(_DWORD)v11 )
goto LABEL_22;
}
else if ( (_DWORD)v11 )
{
LABEL_22:
v12 = *v9 >> 4;
if ( very_verbose )
goto LABEL_27;
goto LABEL_23;
}
v12 = *v9 & 0xF;
if ( very_verbose )
{
LABEL_27:
printf("%d: %d %d: %x: %x\n", v10, v11, &v9[-program], v12, *v9);
LODWORD(v10) = counter;
}
LABEL_23:
counter = v10 + 1;
execute(v12);
v10 = (unsigned int)counter;
v11 = (unsigned int)(counter % 2);
v9 = (unsigned __int8 *)(program + counter / 2);
pc_8 = (__int64)v9;
pc_4 = counter % 2;
}
while ( (unsigned __int64)v9 < max );
}
fprintf(stderr, "executing code outside of program space: pc = %d\n", (unsigned int)v10);
return 2;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *v4; // r12
FILE *v5; // rbp
void *v6; // rax
_BYTE *v7; // rdx
int v8; // eax
unsigned __int8 *v9; // rax
__int64 v10; // rsi
__int64 v11; // rdx
unsigned int v12; // ebp
struct stat v14; // [rsp+0h] [rbp-A8h] BYREF

opterr = 0;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "vVbh");
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'b':
little_endian = 0;
break;
case 'v':
verbose = 1;
break;
case 'V':
very_verbose = 1;
break;
default:
goto LABEL_7;
}
}
v4 = (char *)argv[optind];
if ( !v4 )
LABEL_7:
func20();
if ( argc <= 1 || (setbuf(stdout, 0LL), signal(2, sigint), (v5 = fopen(v4, "r")) == 0LL) )
exit(1);
if ( (unsigned int)func23(v4, &v14) == -1 )
{
perror("stat");
exit(3);
}
v6 = malloc(v14.st_size);
program = (__int64)v6;
if ( !v6 || (pc_8 = (__int64)v6, stack = (__int64)malloc(0x1000uLL), (qword_404258 = stack) == 0) )
{
perror("malloc");
exit(3);
}
while ( 1 )
{
v8 = fgetc(v5);
if ( v8 == -1 )
break;
v7 = (_BYTE *)pc_8++;
*v7 = v8;
}
max = pc_8;
fclose(v5);
v9 = (unsigned __int8 *)program;
pc_4 = 0;
v10 = (unsigned int)counter;
pc_8 = program;
if ( program < (unsigned __int64)max )
{
v11 = 0LL;
do
{
if ( little_endian )
{
if ( !(_DWORD)v11 )
goto LABEL_22;
}
else if ( (_DWORD)v11 )
{
LABEL_22:
v12 = *v9 >> 4;
if ( very_verbose )
goto LABEL_27;
goto LABEL_23;
}
v12 = *v9 & 0xF;
if ( very_verbose )
{
LABEL_27:
printf("%d: %d %d: %x: %x\n", v10, v11, &v9[-program], v12, *v9);
LODWORD(v10) = counter;
}
LABEL_23:
counter = v10 + 1;
func18(v12);
v10 = (unsigned int)counter;
v11 = (unsigned int)(counter % 2);
v9 = (unsigned __int8 *)(program + counter / 2);
pc_8 = (__int64)v9;
pc_4 = counter % 2;
}
while ( (unsigned __int64)v9 < max );
}
fprintf(stderr, "executing code outside of program space: pc = %d\n", (unsigned int)v10);
return 2;
}

original_code:
int main(int argc, char **argv)
{
 opterr=0;
 int c;
 int keep=0;
 while((c = getopt(argc, argv, "khb")) != (-1)) {
  switch(c) {
   case 'k':
    keep=1;
    break;
   case 'b':
    byte_instructions = 1;
    break;
   case 'h':case '?':
   default:
    usage();
  }
 }
 char *infile = argv[optind];
 char *outfile = argv[optind+1];
 if(!infile || !outfile) usage();
 char out1[strlen(outfile) + 2];
 strcpy(out1, outfile);
 strcat(out1, ".1");
 char out2[strlen(outfile) + 2];
 strcpy(out2,outfile);
 strcat(out2, ".2");
 char out3[strlen(outfile) + 2];
 strcpy(out3, outfile);
 strcat(out3, ".3");
 char outs[strlen(outfile) + 4];
 strcpy(outs, outfile);
 strcat(outs, ".sym");
 if(pass1(infile, out1)) return 1;
 if(pass2(out1, out2, outs)) return 1;
 if(pass3(out2, out3)) return 1;
 if(pass4(out3, outfile, 1)) return 1;
 if(!keep) {
  unlink(out1);
  unlink(out2);
  unlink(out3);
  unlink(outs);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 opterr=0;
 int c;
 int keep = 0;
 while((c = getopt(argc, argv, "khb")) != (-1)) {
  switch(c) {
   case 'k':
    keep=1;
    break;
   case 'b':
    byte_instructions = 1;
    break;
   case 'h':case '?':
   default:
    usage();
  }
 }
 char *infile = argv[optind];
 char *outfile = argv[optind+1];
 if(!infile || !outfile) usage();
 char out1[-1];
 strcpy(out1, outfile);
 strcat(out1, ".1");
 char out2[-1];
 strcpy(out2,outfile);
 strcat(out2, ".2");
 char out3[-1];
 strcpy(out3, outfile);
 strcat(out3, ".3");
 char outs[-1];
 strcpy(outs, outfile);
 strcat(outs, ".sym");
 if(pass1(infile, out1)) return 1;
 if(pass2(out1, out2, outs)) return 1;
 if(pass3(out2, out3)) return 1;
 if(pass4(out3, outfile, 1)) return 1;
 if(!keep) {
  unlink(out1);
  unlink(out2);
  unlink(out3);
  unlink(outs);
 }
 return 0;
}

variable_types: argc int

variable_types: c int

variable_types: keep int

variable_types:
infile
char *

variable_types:
outfile
char *

variable_types:
outs
char [-1]


sigint

decompiled_code:
void __noreturn sigint()
{
fprintf(stderr, "\n\ninterrupted (SIGINT): pc = %d\n", (unsigned int)counter);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
fprintf(stderr, "\n\ninterrupted (SIGINT): pc = %d\n", (unsigned int)counter);
exit(0);
}

original_code:
void sigint(int s)
{
 fprintf(stderr, "\n\ninterrupted (SIGINT): pc = %d\n", counter);
 exit(0);
}

variable_types: s int


decompiled_code:
void __noreturn op_und()
{
fprintf(stderr, "undefined opcode: pc = %d\n", (unsigned int)counter);
exit(2);
}

canonical_decompiled_code:
void __noreturn func8()
{
fprintf(stderr, "undefined opcode: pc = %d\n", (unsigned int)counter);
exit(2);
}

original_code:
void op_und(uint8_t p)
{
 fprintf(stderr, "undefined opcode: pc = %d\n", counter);
 exit(2);
}

canonical_original_code:
void op_und(unsigned char p)
{
 fprintf(stderr, "undefined opcode: pc = %d\n", counter);
 exit(2);
}

variable_types:
p
unsigned char


underflow

decompiled_code:
void __noreturn underflow()
{
fprintf(stderr, "underflow: pc = %d\n", (unsigned int)counter);
exit(2);
}

canonical_decompiled_code:
void __noreturn func9()
{
fprintf(stderr, "underflow: pc = %d\n", (unsigned int)counter);
exit(2);
}

original_code:
void underflow()
{
 fprintf(stderr, "underflow: pc = %d\n", counter);
 exit(2);
}


overflow

decompiled_code:
void __noreturn overflow()
{
fprintf(stderr, "overflow: pc = %d\n", (unsigned int)counter);
exit(2);
}

canonical_decompiled_code:
void __noreturn func10()
{
fprintf(stderr, "overflow: pc = %d\n", (unsigned int)counter);
exit(2);
}

original_code:
void overflow()
{
 fprintf(stderr, "overflow: pc = %d\n", counter);
 exit(2);
}


pop

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

if ( qword_404258 == stack )
underflow(a1);
result = *(unsigned int *)(qword_404258 - 4);
qword_404258 -= 4LL;
return result;
}

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

if ( qword_404258 == stack )
func9(a1);
result = *(unsigned int *)(qword_404258 - 4);
qword_404258 -= 4LL;
return result;
}

original_code:
uint32_t pop()
{
 if(sp == stack) underflow();
 uint32_t x = *(--sp);
 return x;
}

canonical_original_code:
unsigned int pop()
{
 if(sp == stack) underflow();
 unsigned int x = *(--sp);
 return x;
}

variable_types:
x
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall op_pop(__int64 a1)
{
return pop(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return func11(a1);
}

original_code:
void op_pop(uint8_t p)
{
 pop();
}

canonical_original_code:
void op_pop(unsigned char p)
{
 pop();
}


decompiled_code:
int __fastcall op_put(__int64 a1)
{
int v1; // eax

v1 = pop(a1);
return putc(v1, stdout);
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
int v1; // eax

v1 = func11(a1);
return putc(v1, stdout);
}

original_code:
void op_put(uint8_t p)
{
 int x = pop();
 putc(x, stdout);
}

canonical_original_code:
void op_put(unsigned char p)
{
 int x = pop();
 putc(x, stdout);
}

variable_types: x int


decompiled_code:
__int64 __fastcall op_br(__int64 a1)
{
int v1; // ebx
__int64 result; // rax

v1 = pop(a1);
result = pop(a1);
if ( v1 )
counter = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
int v1; // ebx
__int64 result; // rax

v1 = func11(a1);
result = func11(a1);
if ( v1 )
counter = result;
return result;
}

original_code:
void op_br(uint8_t p)
{
 uint32_t test = pop();
 uint32_t x = pop();
 if(test)
  counter = x;
}

canonical_original_code:
void op_br(unsigned char p)
{
 unsigned int test = pop();
 unsigned int x = pop();
 if(test)
  counter = x;
}

variable_types:
test
unsigned int


decompiled_code:
_DWORD *op_ppc()
{
return push((unsigned int)counter);
}

canonical_decompiled_code:
_DWORD *func15()
{
return push((unsigned int)counter);
}

original_code:
void op_ppc(uint8_t p)
{
 push(counter);
}

canonical_original_code:
void op_ppc(unsigned char p)
{
 push(counter);
}


decompiled_code:
_DWORD *op_get()
{
unsigned int v0; // eax

v0 = getc(stdin);
if ( v0 == -1 )
{
fwrite("recieved EOF\n", 1uLL, 0xDuLL, stderr);
while ( 1 )
;
}
return push(v0);
}

canonical_decompiled_code:
_DWORD *func16()
{
unsigned int v0; // eax

v0 = getc(stdin);
if ( v0 == -1 )
{
fwrite("recieved EOF\n", 1uLL, 0xDuLL, stderr);
while ( 1 )
;
}
return push(v0);
}

original_code:
void op_get(uint8_t p)
{
 int in = getc(stdin);
 if(in != (-1)) {
  push((uint32_t)in);
 }
 else {
  fprintf(stderr, "recieved EOF\n");
  for(;;);
 }
}

canonical_original_code:
void op_get(unsigned char p)
{
 int in = getc(stdin);
 if(in != (-1)) {
  push((unsigned int)in);
 }
 else {
  fprintf(stderr, "recieved EOF\n");
  for(;;);
 }
}

variable_types: in int


peek

decompiled_code:
__int64 __fastcall peek(__int64 a1)
{
if ( qword_404258 == stack )
underflow(a1);
return *(unsigned int *)(qword_404258 - 4);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
if ( qword_404258 == stack )
func9(a1);
return *(unsigned int *)(qword_404258 - 4);
}

original_code:
uint32_t peek()
{
 if(sp == stack) underflow();
 return *(sp-1);
}

canonical_original_code:
unsigned int peek()
{
 if(sp == stack) underflow();
 return *(sp-1);
}


execute

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

if ( waiting_for_push_operand_0 )
{
waiting_for_push_operand_0 = 0;
if ( verbose )
fprintf(stderr, "push %d\n", a1);
result = off_4040C8((unsigned __int8)a1);
}
else if ( a1 )
{
if ( verbose )
fprintf(stderr, "%s\n", (&optable)[2 * (int)a1]);
result = (*(&off_4040C8 + 2 * (int)a1))(0LL);
}
else
{
waiting_for_push_operand_0 = 1;
}
return result;
}

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

if ( waiting_for_push_operand_0 )
{
waiting_for_push_operand_0 = 0;
if ( verbose )
fprintf(stderr, "push %d\n", a1);
result = off_4040C8((unsigned __int8)a1);
}
else if ( a1 )
{
if ( verbose )
fprintf(stderr, "%s\n", (&optable)[2 * (int)a1]);
result = (*(&off_4040C8 + 2 * (int)a1))(0LL);
}
else
{
waiting_for_push_operand_0 = 1;
}
return result;
}

original_code:
void execute(int code)
{
 static int waiting_for_push_operand = 0;
 if(waiting_for_push_operand)
 {
  waiting_for_push_operand = 0;
  if(verbose)
   fprintf(stderr, "push %d\n", code);
  optable[0].fn(code);
 } else {
  if(!code)
   waiting_for_push_operand = 1;
  else {
   if(verbose)
    fprintf(stderr, "%s\n", optable[code].name);
   optable[code].fn(0);
  }
 }
}

variable_types: code int


decompiled_code:
__int64 __fastcall op_swap(__int64 a1)
{
int v1; // ebx
__int64 result; // rax
_DWORD *v3; // rcx
char v4; // al

v1 = pop(a1);
result = peek(a1);
if ( v1 )
{
v3 = (_DWORD *)(qword_404258 - 4LL * (unsigned int)(v1 + 1));
if ( (unsigned __int64)v3 < stack )
underflow(a1);
*(_DWORD *)(qword_404258 - 4) = *v3;
*v3 = result;
}
else
{
v4 = pop(a1);
result = execute(v4 & 0xF);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
int v1; // ebx
__int64 result; // rax
_DWORD *v3; // rcx
char v4; // al

v1 = func11(a1);
result = func17(a1);
if ( v1 )
{
v3 = (_DWORD *)(qword_404258 - 4LL * (unsigned int)(v1 + 1));
if ( (unsigned __int64)v3 < stack )
func9(a1);
*(_DWORD *)(qword_404258 - 4) = *v3;
*v3 = result;
}
else
{
v4 = func11(a1);
result = func18(v4 & 0xF);
}
return result;
}

original_code:
void op_swap(uint8_t p)
{
 uint32_t param = pop();
 uint32_t elem = peek();
 if(param > 0) {
  if((sp - (param + 1)) < stack)
   underflow();
  *(sp-1) = *(sp - (param + 1));
  *(sp - (param + 1)) = elem;
 } else {
  elem = pop();
  execute(elem & 0xF);
 }
}

canonical_original_code:
void op_swap(unsigned char p)
{
 unsigned int param = pop();
 unsigned int elem = peek();
 if(param > 0) {
  if((sp - (param + 1)) < stack)
   underflow();
  *(sp-1) = *(sp - (param + 1));
  *(sp - (param + 1)) = elem;
 } else {
  elem = pop();
  execute(elem & 0xF);
 }
}

variable_types:
param
unsigned int

variable_types:
elem
unsigned int


decompiled_code:
__int64 __fastcall get_opcode(char *s1)
{
unsigned int v1; // er12

v1 = strcasecmp(s1, "push");
if ( v1 )
{
v1 = strcasecmp(s1, "psh");
if ( v1 )
{
v1 = 8;
if ( strcasecmp(s1, "pop") )
{
v1 = 10;
if ( strcasecmp(s1, "dup") )
{
v1 = 14;
if ( strcasecmp(s1, "br") )
{
if ( strcasecmp(s1, "branch") )
{
v1 = 1;
if ( strcasecmp(s1, "and") )
{
v1 = 6;
if ( strcasecmp(s1, "add") )
{
v1 = 7;
if ( strcasecmp(s1, "cmp") )
{
v1 = 9;
if ( strcasecmp(s1, "swap") )
{
if ( strcasecmp(s1, "swp") )
{
v1 = 2;
if ( strcasecmp(s1, "not") )
{
v1 = 3;
if ( strcasecmp(s1, "or") )
{
v1 = 11;
if ( strcasecmp(s1, "ppc") )
{
v1 = 4;
if ( strcasecmp(s1, "mul") )
{
v1 = 5;
if ( strcasecmp(s1, "div") )
{
v1 = 12;
if ( strcasecmp(s1, "get") )
v1 = strcasecmp(s1, "put") == 0 ? 13 : -1;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
unsigned int v1; // er12

v1 = strcasecmp(s1, "push");
if ( v1 )
{
v1 = strcasecmp(s1, "psh");
if ( v1 )
{
v1 = 8;
if ( strcasecmp(s1, "pop") )
{
v1 = 10;
if ( strcasecmp(s1, "dup") )
{
v1 = 14;
if ( strcasecmp(s1, "br") )
{
if ( strcasecmp(s1, "branch") )
{
v1 = 1;
if ( strcasecmp(s1, "and") )
{
v1 = 6;
if ( strcasecmp(s1, "add") )
{
v1 = 7;
if ( strcasecmp(s1, "cmp") )
{
v1 = 9;
if ( strcasecmp(s1, "swap") )
{
if ( strcasecmp(s1, "swp") )
{
v1 = 2;
if ( strcasecmp(s1, "not") )
{
v1 = 3;
if ( strcasecmp(s1, "or") )
{
v1 = 11;
if ( strcasecmp(s1, "ppc") )
{
v1 = 4;
if ( strcasecmp(s1, "mul") )
{
v1 = 5;
if ( strcasecmp(s1, "div") )
{
v1 = 12;
if ( strcasecmp(s1, "get") )
v1 = strcasecmp(s1, "put") == 0 ? 13 : -1;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return v1;
}

original_code:
int get_opcode(char *code)
{
 if(!strcasecmp(code, "push") || !strcasecmp(code, "psh")) {
  return 0;
 } else if(!strcasecmp(code, "pop")) {
  return 8;
 } else if(!strcasecmp(code, "dup")) {
  return 10;
 } else if(!strcasecmp(code, "br") || !strcasecmp(code, "branch")) {
  return 14;
 } else if(!strcasecmp(code, "and")) {
  return 1;
 } else if(!strcasecmp(code, "add")) {
  return 6;
 } else if(!strcasecmp(code, "cmp")) {
  return 7;
 } else if(!strcasecmp(code, "swap") || !strcasecmp(code, "swp")) {
  return 9;
 } else if(!strcasecmp(code, "not")) {
  return 2;
 } else if(!strcasecmp(code, "or")) {
  return 3;
 } else if(!strcasecmp(code, "ppc")) {
  return 11;
 } else if(!strcasecmp(code, "mul")) {
  return 4;
 } else if(!strcasecmp(code, "div")) {
  return 5;
 } else if(!strcasecmp(code, "get")) {
  return 12;
 } else if(!strcasecmp(code, "put")) {
  return 13;
 } else
  return -1;
}

variable_types:
code
char *


convert

decompiled_code:
__int64 __fastcall convert(const char *a1, unsigned int a2, char *a3)
{
int v4; // ebp
int v5; // eax
unsigned int v6; // er14
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

*_errno_location() = 0;
endptr = 0LL;
v4 = strtol(a3, &endptr, 0);
v5 = strlen(a3);
if ( endptr - a3 == v5 )
{
v6 = v4;
if ( v4 <= 15 )
return v6;
fprintf(stderr, "warning: %s:%d: immediate value truncated to 4 bits: %d\n", a1, a2, (unsigned int)v4);
result = (unsigned int)v4;
}
else
{
v6 = get_opcode(a3);
if ( v6 != -1 )
return v6;
fprintf(stderr, "warning: %s:%d: invalid opcode: %s\n", a1, a2, a3);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, unsigned int a2, char *a3)
{
int v4; // ebp
int v5; // eax
unsigned int v6; // er14
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

*_errno_location() = 0;
endptr = 0LL;
v4 = strtol(a3, &endptr, 0);
v5 = strlen(a3);
if ( endptr - a3 == v5 )
{
v6 = v4;
if ( v4 <= 15 )
return v6;
fprintf(stderr, "warning: %s:%d: immediate value truncated to 4 bits: %d\n", a1, a2, (unsigned int)v4);
result = (unsigned int)v4;
}
else
{
v6 = func0(a3);
if ( v6 != -1 )
return v6;
fprintf(stderr, "warning: %s:%d: invalid opcode: %s\n", a1, a2, a3);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
uint8_t convert(char *outname, int line, char *tok)
{
 (*__errno_location ())=0;
 char *end=0;
 int conv = strtol(tok, &end, 0);
 if((end - tok) != (int)strlen(tok)) {
  conv = get_opcode(tok);
  if(conv == -1)
   fprintf(stderr, "warning: %s:%d: invalid opcode: %s\n", outname, line, tok);
 } else {
  if(conv > 15)
   fprintf(stderr, "warning: %s:%d: immediate value truncated to 4 bits: %d\n", outname, line, conv);
 }
 return (uint8_t)conv;
}

canonical_original_code:
unsigned char convert(char *outname, int line, char *tok)
{
 (*__errno_location ())=0;
 char *end = 0;
 int conv = strtol(tok, &end, 0);
 if((end - tok) != (int)strlen(tok)) {
  conv = get_opcode(tok);
  if(conv == -1)
   fprintf(stderr, "warning: %s:%d: invalid opcode: %s\n", outname, line, tok);
 } else {
  if(conv > 15)
   fprintf(stderr, "warning: %s:%d: immediate value truncated to 4 bits: %d\n", outname, line, conv);
 }
 return (unsigned char)conv;
}

variable_types:
outname
char *

variable_types: line int

variable_types:
tok
char *

variable_types:
end
char *

variable_types: conv int

return_type: unsigned char


decompiled_code:
__int64 __fastcall get_label(char *s2)
{
char *v1; // rbx

v1 = syms;
if ( !syms )
return 0xFFFFFFFFLL;
while ( strcmp(v1, s2) )
{
v1 = (char *)*((_QWORD *)v1 + 17);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)v1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s2)
{
char *v1; // rbx

v1 = syms;
if ( !syms )
return 0xFFFFFFFFLL;
while ( strcmp(v1, s2) )
{
v1 = (char *)*((_QWORD *)v1 + 17);
if ( !v1 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)v1 + 32);
}

original_code:
int get_label(char *name)
{
 struct symbol *s = syms;
 while(s)
 {
  if(!strcmp(s->name, name))
   return s->pc;
  s=s->next;
 }
 return -1;
}

variable_types:
name
char *

variable_types: struct symbol { char name[128]; int pc; struct symbol *next; } *


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

v1 = *a1;
if ( !(_BYTE)v1 )
return 1LL;
v2 = a1;
v3 = *_ctype_b_loc();
while ( (v3[v1] & 0x2000) != 0 )
{
v1 = *++v2;
if ( !(_BYTE)v1 )
return 1LL;
}
return 0LL;
}

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

v1 = *a1;
if ( !(_BYTE)v1 )
return 1LL;
v2 = a1;
v3 = *_ctype_b_loc();
while ( (v3[v1] & 0x2000) != 0 )
{
v1 = *++v2;
if ( !(_BYTE)v1 )
return 1LL;
}
return 0LL;
}

original_code:
int is_empty(const char *s) {
  while (*s != '\0') {
    if (!((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace))
      return 0;
    s++;
  }
  return 1;
}

canonical_original_code:
int is_empty(char *s) {
  while (*s != '\0') {
    if (!((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace))
      return 0;
    s++;
  }
  return 1;
}

variable_types:
s
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // eax
const char *v5; // r12
const char *v6; // rdi
size_t v7; // rbx
void *v8; // rsp
size_t v9; // rbx
void *v10; // rsp
size_t v11; // rbx
void *v12; // rsp
size_t v13; // rbx
void *v14; // rsp
const char *v15; // r8
int v16; // er12
char *v18; // rbx
char *name; // [rsp+0h] [rbp-40h] BYREF
const char *v20; // [rsp+8h] [rbp-38h]

v3 = 0;
opterr = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "khb");
if ( v4 == -1 )
break;
if ( v4 == 98 )
{
byte_instructions = 1;
}
else
{
v3 = 1;
if ( v4 != 107 )
goto LABEL_6;
}
}
v5 = argv[optind + 1];
if ( !argv[optind] || !v5 )
LABEL_6:
usage();
v6 = argv[optind + 1];
v20 = argv[optind];
v7 = strlen(v6);
v8 = alloca(v7 + 2);
memcpy(&name, v5, v7);
*((_BYTE *)&name + v7 + 2) = 0;
*(_WORD *)((char *)&name + v7) = 12590;
v9 = strlen(v5);
v10 = alloca(v9 + 2);
memcpy(&name, v5, v9);
*((_BYTE *)&name + v9 + 2) = 0;
*(_WORD *)((char *)&name + v9) = 12846;
v11 = strlen(v5);
v12 = alloca(v11 + 2);
name = (char *)&name;
memcpy(&name, v5, v11);
*((_BYTE *)&name + v11 + 2) = 0;
*(_WORD *)((char *)&name + v11) = 13102;
v13 = strlen(v5);
v14 = alloca(v13 + 4);
memcpy(&name, v5, v13);
v15 = v20;
*(_DWORD *)((char *)&name + v13) = 1836675886;
*((_BYTE *)&name + v13 + 4) = 0;
if ( (unsigned int)pass1(v15, (const char *)&name) )
return 1;
if ( (unsigned int)pass2((const char *)&name, (const char *)&name, (const char *)&name) )
return 1;
v18 = name;
if ( (unsigned int)pass3((const char *)&name, name) )
return 1;
v16 = pass4(v18, v5, 1);
if ( v16 )
return 1;
if ( !v3 )
{
unlink((const char *)&name);
unlink((const char *)&name);
unlink(name);
unlink((const char *)&name);
}
return v16;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // eax
const char *v5; // r12
const char *v6; // rdi
size_t v7; // rbx
void *v8; // rsp
size_t v9; // rbx
void *v10; // rsp
size_t v11; // rbx
void *v12; // rsp
size_t v13; // rbx
void *v14; // rsp
const char *v15; // r8
int v16; // er12
char *v18; // rbx
char *name; // [rsp+0h] [rbp-40h] BYREF
const char *v20; // [rsp+8h] [rbp-38h]

v3 = 0;
opterr = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "khb");
if ( v4 == -1 )
break;
if ( v4 == 98 )
{
byte_instructions = 1;
}
else
{
v3 = 1;
if ( v4 != 107 )
goto LABEL_6;
}
}
v5 = argv[optind + 1];
if ( !argv[optind] || !v5 )
LABEL_6:
func12();
v6 = argv[optind + 1];
v20 = argv[optind];
v7 = strlen(v6);
v8 = alloca(v7 + 2);
memcpy(&name, v5, v7);
*((_BYTE *)&name + v7 + 2) = 0;
*(_WORD *)((char *)&name + v7) = 12590;
v9 = strlen(v5);
v10 = alloca(v9 + 2);
memcpy(&name, v5, v9);
*((_BYTE *)&name + v9 + 2) = 0;
*(_WORD *)((char *)&name + v9) = 12846;
v11 = strlen(v5);
v12 = alloca(v11 + 2);
name = (char *)&name;
memcpy(&name, v5, v11);
*((_BYTE *)&name + v11 + 2) = 0;
*(_WORD *)((char *)&name + v11) = 13102;
v13 = strlen(v5);
v14 = alloca(v13 + 4);
memcpy(&name, v5, v13);
v15 = v20;
*(_DWORD *)((char *)&name + v13) = 1836675886;
*((_BYTE *)&name + v13 + 4) = 0;
if ( (unsigned int)func11(v15, (const char *)&name) )
return 1;
if ( (unsigned int)func6((const char *)&name, (const char *)&name, (const char *)&name) )
return 1;
v18 = name;
if ( (unsigned int)func5((const char *)&name, name) )
return 1;
v16 = func2(v18, v5, 1);
if ( v16 )
return 1;
if ( !v3 )
{
unlink((const char *)&name);
unlink((const char *)&name);
unlink(name);
unlink((const char *)&name);
}
return v16;
}

original_code:
int main(int argc, char **argv)
{
 opterr=0;
 int c;
 int keep=0;
 while((c = getopt(argc, argv, "khb")) != (-1)) {
  switch(c) {
   case 'k':
    keep=1;
    break;
   case 'b':
    byte_instructions = 1;
    break;
   case 'h':case '?':
   default:
    usage();
  }
 }
 char *infile = argv[optind];
 char *outfile = argv[optind+1];
 if(!infile || !outfile) usage();
 char out1[strlen(outfile) + 2];
 strcpy(out1, outfile);
 strcat(out1, ".1");
 char out2[strlen(outfile) + 2];
 strcpy(out2,outfile);
 strcat(out2, ".2");
 char out3[strlen(outfile) + 2];
 strcpy(out3, outfile);
 strcat(out3, ".3");
 char outs[strlen(outfile) + 4];
 strcpy(outs, outfile);
 strcat(outs, ".sym");
 if(pass1(infile, out1)) return 1;
 if(pass2(out1, out2, outs)) return 1;
 if(pass3(out2, out3)) return 1;
 if(pass4(out3, outfile, 1)) return 1;
 if(!keep) {
  unlink(out1);
  unlink(out2);
  unlink(out3);
  unlink(outs);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: keep int

variable_types:
infile
char *

variable_types:
outfile
char *

variable_types:
outs
char [-1]


usage

decompiled_code:
void __noreturn usage()
{
fwrite("bas: usage: bas [-k] <source-file> <binary-file>\n", 1uLL, 0x31uLL, stderr);
fwrite("assembles an assembly language program directly into a binary file for BASIL\n", 1uLL, 0x4DuLL, stderr);
fwrite(" -k: keep intermediate files\n", 1uLL, 0x1EuLL, stderr);
fwrite(" -b: make each instruction 8 bites long\n", 1uLL, 0x29uLL, stderr);
exit(0);
}

canonical_decompiled_code:
void __noreturn func12()
{
fwrite("bas: usage: bas [-k] <source-file> <binary-file>\n", 1uLL, 0x31uLL, stderr);
fwrite("assembles an assembly language program directly into a binary file for BASIL\n", 1uLL, 0x4DuLL, stderr);
fwrite(" -k: keep intermediate files\n", 1uLL, 0x1EuLL, stderr);
fwrite(" -b: make each instruction 8 bites long\n", 1uLL, 0x29uLL, stderr);
exit(0);
}

original_code:
void usage()
{
 fprintf(stderr, "bas: usage: bas [-k] <source-file> <binary-file>\n");
 fprintf(stderr, "assembles an assembly language program directly into a binary file for BASIL\n");
 fprintf(stderr, "  -k: keep intermediate files\n");
 fprintf(stderr, "  -b: make each instruction 8 bites long\n");
 exit(0);
}


oneline

repo: dbondin/testdnsd

decompiled_code:
int oneline()
{
int v0; // ebp
int v1; // er12
int v2; // er13
int v3; // ebx
int v4; // eax
int v5; // ebx
int v6; // eax
int v7; // eax

v0 = 0;
v1 = rand() % 3 + 2;
while ( 1 )
{
v2 = 0;
v3 = rand() % 5 + 2;
if ( v3 > 0 )
{
do
{
v4 = rand();
++v2;
putchar(v4 % 26 + 97);
}
while ( v3 != v2 );
}
if ( v1 < ++v0 )
break;
putchar(46);
}
v5 = 0;
putchar(32);
do
{
if ( ++v5 == 1 )
{
do
{
v6 = rand();
++v5;
printf("%d", (unsigned int)(v6 % 255 + 1));
}
while ( v5 == 1 );
}
putchar(46);
v7 = rand();
printf("%d", (unsigned int)(v7 % 255 + 1));
}
while ( v5 != 4 );
return putchar(10);
}

original_code:
void oneline() {
    int i;
    int num = 2 + rand() % 3;
    int j;
    int size;
    for(i=0; i <= num; i++) {
 if(i != 0) {
     putchar('.');
 }
 size = 2 + rand() % 5;
 for(j=0; j<size; j++) {
     putchar('a' + rand() % ('z' - 'a' + 1));
 }
    }
    putchar(' ');
    for(i=0; i<4; i++) {
 if(i != 0) {
     putchar('.');
 }
 printf("%d", 1 + rand() % 255);
    }
    putchar('\n');
}

variable_types: i int

variable_types: num int

variable_types: j int

variable_types: size int


main

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

if ( argc <= 1 )
{
fwrite("Number of lines required\n", 1uLL, 0x19uLL, _bss_start);
result = 1;
}
else
{
v3 = time(0LL);
srand(v3);
v4 = 0LL;
v5 = atol(argv[1]);
if ( v5 <= 0 )
{
fwrite("Bad number of lines specified\n", 1uLL, 0x1EuLL, _bss_start);
result = 1;
}
else
{
do
{
++v4;
oneline();
}
while ( v5 != v4 );
result = 0;
}
}
return result;
}

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

if ( argc <= 1 )
{
fwrite("Number of lines required\n", 1uLL, 0x19uLL, _bss_start);
result = 1;
}
else
{
v3 = time(0LL);
srand(v3);
v4 = 0LL;
v5 = atol(argv[1]);
if ( v5 <= 0 )
{
fwrite("Bad number of lines specified\n", 1uLL, 0x1EuLL, _bss_start);
result = 1;
}
else
{
do
{
++v4;
func7();
}
while ( v5 != v4 );
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char ** argv) {
    long i;
    long num;
    if(argc < 2) {
 fprintf(stderr, "Number of lines required\n");
 return 1;
    }
    srand(time(((void *)0)));
    num = atol(argv[1]);
    if(num <=0) {
 fprintf(stderr, "Bad number of lines specified\n");
 return 1;
    }
    for(i=0; i<num; i++) {
 oneline();
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    long i;
    long num;
    if(argc < 2) {
 fprintf(stderr, "Number of lines required\n");
 return 1;
    }
    srand(time(((void *)0)));
    num = atol(argv[1]);
    if(num <=0) {
 fprintf(stderr, "Bad number of lines specified\n");
 return 1;
    }
    for(i=0; i<num; i++) {
 oneline();
    }
    return 0;
}

variable_types: i long

variable_types: num long


original_code:
void prepare_response_found(data_queue_element * dqe, lookupdb_addr * ldb_addr) {
    int ancount = 0;
    int off = dqe->data_len;
    dns_header * ph = (dns_header *) dqe->data;
    struct in_addr * addr;
    ph->flags = htons(0x8100);
    while(ldb_addr != ((void *)0) &&
   off <= 512 - 12 - sizeof(struct in_addr)) {
 dqe->data[off++] = 0xc0;
 dqe->data[off++] = 0x0c;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x01;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x01;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x04;
 addr = (struct in_addr *) &(dqe->data[off]);
 *addr = ldb_addr->addr;
 off += sizeof(struct in_addr);
 ldb_addr = ldb_addr->next;
 ancount ++;
    }
    ph->ancount = htons(ancount);
    dqe->data_len = off;
}

canonical_original_code:
void prepare_response_found(struct _data_queue_element *dqe, struct _lookupdb_addr *ldb_addr) {
    int ancount = 0;
    int off = dqe->data_len;
    struct _dns_header *ph = (dns_header *) dqe->data;
    struct in_addr *addr;
    ph->flags = htons(0x8100);
    while(ldb_addr != ((void *)0) &&
   off <= 512 - 12 - sizeof(struct in_addr)) {
 dqe->data[off++] = 0xc0;
 dqe->data[off++] = 0x0c;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x01;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x01;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x00;
 dqe->data[off++] = 0x04;
 addr = (struct in_addr *) &(dqe->data[off]);
 *addr = ldb_addr->addr;
 off += sizeof(struct in_addr);
 ldb_addr = ldb_addr->next;
 ancount ++;
    }
    ph->ancount = htons(ancount);
    dqe->data_len = off;
}

variable_types: struct _data_queue_element { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; char data[512]; int data_len; } *

variable_types: struct _lookupdb_addr { struct in_addr addr; struct _lookupdb_addr *next; } *

variable_types: ancount int

variable_types: off int

variable_types: struct _dns_header { unsigned short id; unsigned short flags; unsigned short qdcount; unsigned short ancount; unsigned short nscount; unsigned short arcount; } *

variable_types: struct in_addr { unsigned int s_addr; } *

user_defined_types: struct _data_queue_element { struct sockaddr_in addr; char data[512]; int data_len; }

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


decompiled_code:
__int16 prepare_response_not_found()
{
__int16 result; // ax
__int64 v1; // rdx

result = _bswap_16(33027);
*(_WORD *)(v1 + 18) = result;
return result;
}

canonical_decompiled_code:
__int16 func3()
{
__int16 result; // ax
__int64 v1; // rdx

result = func1(33027);
*(_WORD *)(v1 + 18) = result;
return result;
}

original_code:
static void prepare_response_not_found(data_queue_element * dqe) {
    dns_header * ph = (dns_header *) dqe->data;
    ph->flags = htons(0x8103);
}

canonical_original_code:
static void prepare_response_not_found(struct _data_queue_element *dqe) {
    struct _dns_header *ph = (dns_header *) dqe->data;
    ph->flags = htons(0x8103);
}

user_defined_types: struct _dns_header { unsigned short id; unsigned short flags; unsigned short qdcount; unsigned short ancount; unsigned short nscount; unsigned short arcount; }


decompiled_code:
void __fastcall __noreturn processor_thread_fn(unsigned int *a1)
{
__int16 v1; // cx
__int16 v2; // bx
__int16 v3; // r8
__int16 v4; // r13
__int16 v5; // ax
__int16 v6; // r9
__int16 v7; // bp
__int16 v8; // r14
unsigned __int16 v9; // r15
__int64 v10; // rax
__int64 v11; // rsi
int *v12; // rbp
char *v13; // [rsp+0h] [rbp-468h] BYREF
int v14; // [rsp+8h] [rbp-460h]
char v15[512]; // [rsp+10h] [rbp-458h] BYREF
char v16[16]; // [rsp+210h] [rbp-258h] BYREF
__int16 v17[6]; // [rsp+220h] [rbp-248h] BYREF
char v18[500]; // [rsp+22Ch] [rbp-23Ch] BYREF
unsigned int v19; // [rsp+420h] [rbp-48h]

XXLOG("PRC[%d]: Started", *a1);
while ( 1 )
{
while ( (unsigned int)data_queue_get_data(&INQ, v16) )
XXLOG_DEBUG("PRC[%d]: Error getting data from input queue. Ignoring", *a1);
if ( v19 > 0xB )
{
_bswap_16(v17[0]);
_bswap_16(v17[1]);
_bswap_16(v17[2]);
v2 = v1;
_bswap_16(v17[3]);
v4 = v3;
v5 = _bswap_16(v17[4]);
v7 = v6;
v8 = v5;
v9 = _bswap_16(v17[5]);
XXLOG_DEBUG("PRC[%d]: got id=0x%.4x, flags=0x%.4x, qdcount=%u ancount=%u nscount=%u arcount=%u", *a1);
XXLOG_DEBUG("PRC[%d]: %d %d %d", *a1);
if ( v2 >= 0
&& !(v2 & 0x7A00 | (unsigned __int16)(v9 | v8 | v7))
&& v4 == 1
&& !(unsigned int)dns_question_load(v18, &v13, v9) )
{
qname2str(v13, (__int64)v15);
XXLOG_DEBUG("PRC[%d]: qname='%s' qtype=0x%x qclass=0x%x", *a1);
if ( v14 == 65537 )
{
v10 = lookupdb_search(&DB, v15);
v11 = *a1;
v12 = (int *)v10;
if ( v10 )
{
XXLOG_DEBUG("PRC[%d]: FOUND", v11);
prepare_response_found((__int64)v16, v12);
goto LABEL_9;
}
XXLOG_DEBUG("PRC[%d]: NOT FOUND", v11);
}
}
}
prepare_response_not_found();
LABEL_9:
XXLOG_DEBUG("PRC[%d]: Put the response in output queue", *a1);
if ( (unsigned int)data_queue_put_data(&OUTQ, v16, v17, v19) )
XXLOG("PRC[%d]: Error putting data to output queue", *a1);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func4(unsigned int *a1)
{
__int16 v1; // cx
__int16 v2; // bx
__int16 v3; // r8
__int16 v4; // r13
__int16 v5; // ax
__int16 v6; // r9
__int16 v7; // bp
__int16 v8; // r14
unsigned __int16 v9; // r15
__int64 v10; // rax
__int64 v11; // rsi
int *v12; // rbp
char *v13; // [rsp+0h] [rbp-468h] BYREF
int v14; // [rsp+8h] [rbp-460h]
char v15[512]; // [rsp+10h] [rbp-458h] BYREF
char v16[16]; // [rsp+210h] [rbp-258h] BYREF
__int16 v17[6]; // [rsp+220h] [rbp-248h] BYREF
char v18[500]; // [rsp+22Ch] [rbp-23Ch] BYREF
unsigned int v19; // [rsp+420h] [rbp-48h]

XXLOG("PRC[%d]: Started", *a1);
while ( 1 )
{
while ( (unsigned int)data_queue_get_data(&INQ, v16) )
XXLOG_DEBUG("PRC[%d]: Error getting data from input queue. Ignoring", *a1);
if ( v19 > 0xB )
{
func1(v17[0]);
func1(v17[1]);
func1(v17[2]);
v2 = v1;
func1(v17[3]);
v4 = v3;
v5 = func1(v17[4]);
v7 = v6;
v8 = v5;
v9 = func1(v17[5]);
XXLOG_DEBUG("PRC[%d]: got id=0x%.4x, flags=0x%.4x, qdcount=%u ancount=%u nscount=%u arcount=%u", *a1);
XXLOG_DEBUG("PRC[%d]: %d %d %d", *a1);
if ( v2 >= 0
&& !(v2 & 0x7A00 | (unsigned __int16)(v9 | v8 | v7))
&& v4 == 1
&& !(unsigned int)dns_question_load(v18, &v13, v9) )
{
func0(v13, (__int64)v15);
XXLOG_DEBUG("PRC[%d]: qname='%s' qtype=0x%x qclass=0x%x", *a1);
if ( v14 == 65537 )
{
v10 = lookupdb_search(&DB, v15);
v11 = *a1;
v12 = (int *)v10;
if ( v10 )
{
XXLOG_DEBUG("PRC[%d]: FOUND", v11);
func2((__int64)v16, v12);
goto LABEL_9;
}
XXLOG_DEBUG("PRC[%d]: NOT FOUND", v11);
}
}
}
func3();
LABEL_9:
XXLOG_DEBUG("PRC[%d]: Put the response in output queue", *a1);
if ( (unsigned int)data_queue_put_data(&OUTQ, v16, v17, v19) )
XXLOG("PRC[%d]: Error putting data to output queue", *a1);
}
}

original_code:
void * processor_thread_fn(void * args) {
    processor_thread_fn_arg_t * prc_arg = (processor_thread_fn_arg_t *) args;
    dns_header h;
    data_queue_element dqe;
    dns_question dnsq;
    char name[512];
    lookupdb_addr * ldb_addr;
    int found;
    XXLOG("PRC[%d]: Started", prc_arg->prc_id);
    while(1) {
 if(data_queue_get_data(&INQ, &dqe)) {
     XXLOG_DEBUG("PRC[%d]: Error getting data from input queue. Ignoring", prc_arg->prc_id);
     continue;
 }
 found = 0;
 if(dqe.data_len >= sizeof(dns_header)) {
     h.id = ntohs(((dns_header *) dqe.data)->id);
     h.flags = ntohs(((dns_header *) dqe.data)->flags);
     h.qdcount = ntohs(((dns_header *) dqe.data)->qdcount);
     h.ancount = ntohs(((dns_header *) dqe.data)->ancount);
     h.nscount = ntohs(((dns_header *) dqe.data)->nscount);
     h.arcount = ntohs(((dns_header *) dqe.data)->arcount);
     XXLOG_DEBUG("PRC[%d]: got id=0x%.4x, flags=0x%.4x, qdcount=%u ancount=%u nscount=%u arcount=%u",
   prc_arg->prc_id,
   h.id,
   h.flags,
   h.qdcount,
   h.ancount,
   h.nscount,
   h.arcount);
     XXLOG_DEBUG("PRC[%d]: %d %d %d", prc_arg->prc_id, (h.flags & 0x8000), (h.flags & 0x7800), (h.flags & 0x0200));
     if((h.flags & 0x8000) == 0
        && (h.flags & 0x7800) == 0
        && (h.flags & 0x0200) == 0
        && h.qdcount == 1
        && h.ancount == 0
        && h.nscount == 0
        && h.arcount == 0
        )
     {
  if(!dns_question_load((void *)(dqe.data + sizeof(dns_header)), &dnsq)) {
      qname2str(dnsq.qname, name);
      XXLOG_DEBUG("PRC[%d]: qname='%s' qtype=0x%x qclass=0x%x",
    prc_arg->prc_id,
    name,
    dnsq.qtype,
    dnsq.qclass);
      if(dnsq.qtype == 1
         && dnsq.qclass == 1 ) {
   ldb_addr = lookupdb_search(&DB, name);
   if(ldb_addr != ((void *)0)) {
       XXLOG_DEBUG("PRC[%d]: FOUND", prc_arg->prc_id);
       found = 1;
   }
   else {
       XXLOG_DEBUG("PRC[%d]: NOT FOUND", prc_arg->prc_id);
   }
      }
  }
     }
 }
 if(found) {
     prepare_response_found(&dqe, ldb_addr);
 }
 else {
     prepare_response_not_found(&dqe);
 }
 XXLOG_DEBUG("PRC[%d]: Put the response in output queue", prc_arg->prc_id);
 if(data_queue_put_data(&OUTQ, &(dqe.addr), (void *) dqe.data, dqe.data_len)) {
     XXLOG("PRC[%d]: Error putting data to output queue", prc_arg->prc_id);
 }
    }
    return ((void *)0);
}

canonical_original_code:
void *processor_thread_fn(void *args) {
    struct _processor_thread_fn_arg_t *prc_arg = (processor_thread_fn_arg_t *) args;
    struct _dns_header h;
    struct _data_queue_element dqe;
    struct _dns_question dnsq;
    char name[512];
    struct _lookupdb_addr *ldb_addr;
    int found;
    XXLOG("PRC[%d]: Started", prc_arg->prc_id);
    while(1) {
 if(data_queue_get_data(&INQ, &dqe)) {
     XXLOG_DEBUG("PRC[%d]: Error getting data from input queue. Ignoring", prc_arg->prc_id);
     continue;
 }
 found = 0;
 if(dqe.data_len >= sizeof(dns_header)) {
     h.id = ntohs(((struct _dns_header *) dqe.data)->id);
     h.flags = ntohs(((struct _dns_header *) dqe.data)->flags);
     h.qdcount = ntohs(((struct _dns_header *) dqe.data)->qdcount);
     h.ancount = ntohs(((struct _dns_header *) dqe.data)->ancount);
     h.nscount = ntohs(((struct _dns_header *) dqe.data)->nscount);
     h.arcount = ntohs(((struct _dns_header *) dqe.data)->arcount);
     XXLOG_DEBUG("PRC[%d]: got id=0x%.4x, flags=0x%.4x, qdcount=%u ancount=%u nscount=%u arcount=%u",
   prc_arg->prc_id,
   h.id,
   h.flags,
   h.qdcount,
   h.ancount,
   h.nscount,
   h.arcount);
     XXLOG_DEBUG("PRC[%d]: %d %d %d", prc_arg->prc_id, (h.flags & 0x8000), (h.flags & 0x7800), (h.flags & 0x0200));
     if((h.flags & 0x8000) == 0
        && (h.flags & 0x7800) == 0
        && (h.flags & 0x0200) == 0
        && h.qdcount == 1
        && h.ancount == 0
        && h.nscount == 0
        && h.arcount == 0
        )
     {
  if(!dns_question_load((void *)(dqe.data + sizeof(dns_header)), &dnsq)) {
      qname2str(dnsq.qname, name);
      XXLOG_DEBUG("PRC[%d]: qname='%s' qtype=0x%x qclass=0x%x",
    prc_arg->prc_id,
    name,
    dnsq.qtype,
    dnsq.qclass);
      if(dnsq.qtype == 1
         && dnsq.qclass == 1 ) {
   ldb_addr = lookupdb_search(&DB, name);
   if(ldb_addr != ((void *)0)) {
       XXLOG_DEBUG("PRC[%d]: FOUND", prc_arg->prc_id);
       found = 1;
   }
   else {
       XXLOG_DEBUG("PRC[%d]: NOT FOUND", prc_arg->prc_id);
   }
      }
  }
     }
 }
 if(found) {
     prepare_response_found(&dqe, ldb_addr);
 }
 else {
     prepare_response_not_found(&dqe);
 }
 XXLOG_DEBUG("PRC[%d]: Put the response in output queue", prc_arg->prc_id);
 if(data_queue_put_data(&OUTQ, &(dqe.addr), (void *) dqe.data, dqe.data_len)) {
     XXLOG("PRC[%d]: Error putting data to output queue", prc_arg->prc_id);
 }
    }
    return ((void *)0);
}

variable_types:
args
void *

variable_types: struct _processor_thread_fn_arg_t { int prc_id; } *

variable_types: struct _dns_header { unsigned short id; unsigned short flags; unsigned short qdcount; unsigned short ancount; unsigned short nscount; unsigned short arcount; }

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

variable_types: struct _dns_question { char *qname; unsigned short qtype; unsigned short qclass; }

variable_types:
name
char [512]

variable_types: struct _lookupdb_addr { struct in_addr { unsigned int s_addr; } addr; struct _lookupdb_addr *next; } *

variable_types: found int

return_type: void *

user_defined_types: struct _lookupdb_addr { struct in_addr addr; struct _lookupdb_addr *next; }


receiver

decompiled_code:
__int64 receiver()
{
int *v0; // rbp
ssize_t v1; // rax
__int64 v2; // rbx
char *v3; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-42Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-428h] BYREF
char buf[1048]; // [rsp+20h] [rbp-418h] BYREF

XXLOG("Starting receiver");
v0 = _errno_location();
do
{
while ( 1 )
{
XXLOG_DEBUG("Waiting for data");
v1 = recvfrom(SOCKET, buf, 0x400uLL, 0, &addr, &addr_len);
v2 = v1;
if ( v1 == -1 )
break;
XXLOG_DEBUG("Receiver receives %d bytes", v1);
if ( v2 > 0 )
{
XXLOG_DEBUG("Putting data to the queue");
if ( (unsigned int)data_queue_put_data(&INQ, &addr, buf, (unsigned int)v2) )
XXLOG("Receiver error: input queue operation failure");
else
XXLOG_DEBUG("Putting data to the queue success");
}
}
}
while ( *v0 == 4 );
v3 = strerror(*v0);
return XXLOG("Receiver failed (%s)", v3);
}

canonical_decompiled_code:
__int64 func0()
{
int *v0; // rbp
ssize_t v1; // rax
__int64 v2; // rbx
char *v3; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-42Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-428h] BYREF
char buf[1048]; // [rsp+20h] [rbp-418h] BYREF

XXLOG("Starting receiver");
v0 = _errno_location();
do
{
while ( 1 )
{
XXLOG_DEBUG("Waiting for data");
v1 = recvfrom(SOCKET, buf, 0x400uLL, 0, &addr, &addr_len);
v2 = v1;
if ( v1 == -1 )
break;
XXLOG_DEBUG("Receiver receives %d bytes", v1);
if ( v2 > 0 )
{
XXLOG_DEBUG("Putting data to the queue");
if ( (unsigned int)data_queue_put_data(&INQ, &addr, buf, (unsigned int)v2) )
XXLOG("Receiver error: input queue operation failure");
else
XXLOG_DEBUG("Putting data to the queue success");
}
}
}
while ( *v0 == 4 );
v3 = strerror(*v0);
return XXLOG("Receiver failed (%s)", v3);
}

original_code:
void receiver() {
    ssize_t bytes_read;
    char read_buffer[1024];
    struct sockaddr_in src_addr;
    socklen_t src_len;
    XXLOG("Starting receiver");
    while(1) {
 XXLOG_DEBUG("Waiting for data");
 bytes_read = recvfrom(SOCKET,
         (void *) read_buffer,
         1024,
         0,
         (struct sockaddr *) &src_addr,
         &src_len);
 if(bytes_read == -1) {
     if((*__errno_location ()) == 4) {
  continue;
     }
     else {
  XXLOG("Receiver failed (%s)", strerror((*__errno_location ())));
  return;
     }
 }
 XXLOG_DEBUG("Receiver receives %d bytes", bytes_read);
 if(bytes_read > 0) {
     XXLOG_DEBUG("Putting data to the queue");
     if(data_queue_put_data(&INQ, &src_addr, (void *) read_buffer, bytes_read)) {
  XXLOG("Receiver error: input queue operation failure");
     }
     else {
  XXLOG_DEBUG("Putting data to the queue success");
     }
 }
    }
    XXLOG("Receiver finished");
    return;
}

canonical_original_code:
void receiver() {
    long bytes_read;
    char read_buffer[1024];
    struct sockaddr_in src_addr;
    unsigned int src_len;
    XXLOG("Starting receiver");
    while(1) {
 XXLOG_DEBUG("Waiting for data");
 bytes_read = recvfrom(SOCKET,
         (void *) read_buffer,
         1024,
         0,
         (struct sockaddr *) &src_addr,
         &src_len);
 if(bytes_read == -1) {
     if((*__errno_location ()) == 4) {
  continue;
     }
     else {
  XXLOG("Receiver failed (%s)", strerror((*__errno_location ())));
  return;
     }
 }
 XXLOG_DEBUG("Receiver receives %d bytes", bytes_read);
 if(bytes_read > 0) {
     XXLOG_DEBUG("Putting data to the queue");
     if(data_queue_put_data(&INQ, &src_addr, (void *) read_buffer, bytes_read)) {
  XXLOG("Receiver error: input queue operation failure");
     }
     else {
  XXLOG_DEBUG("Putting data to the queue success");
     }
 }
    }
    XXLOG("Receiver finished");
    return;
}

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


decompiled_code:
void __noreturn sender_thread_fn()
{
int *v0; // rax
char *v1; // rax
struct sockaddr v2; // [rsp+0h] [rbp-228h] BYREF
char buf[512]; // [rsp+10h] [rbp-218h] BYREF
int v4; // [rsp+210h] [rbp-18h]

XXLOG("SND: Started");
while ( 1 )
{
while ( (unsigned int)data_queue_get_data(&OUTQ, &v2) )
;
if ( (unsigned int)sendto(SOCKET, buf, v4, 0, &v2, 0x10u) == -1 )
{
v0 = _errno_location();
v1 = strerror(*v0);
XXLOG("SND: error sending reply (%s)", v1);
}
else
{
XXLOG_DEBUG("SND: reply sent");
}
}
}

canonical_decompiled_code:
void __noreturn func0()
{
int *v0; // rax
char *v1; // rax
struct sockaddr v2; // [rsp+0h] [rbp-228h] BYREF
char buf[512]; // [rsp+10h] [rbp-218h] BYREF
int v4; // [rsp+210h] [rbp-18h]

XXLOG("SND: Started");
while ( 1 )
{
while ( (unsigned int)data_queue_get_data(&OUTQ, &v2) )
;
if ( (unsigned int)sendto(SOCKET, buf, v4, 0, &v2, 0x10u) == -1 )
{
v0 = _errno_location();
v1 = strerror(*v0);
XXLOG("SND: error sending reply (%s)", v1);
}
else
{
XXLOG_DEBUG("SND: reply sent");
}
}
}

original_code:
void * sender_thread_fn(void * args) {
    int status;
    data_queue_element dqe;
    XXLOG("SND: Started");
    while(1) {
 if(data_queue_get_data(&OUTQ, &dqe) == 0) {
     status = sendto(SOCKET,
       (void *) dqe.data,
       dqe.data_len,
       0,
       (struct sockaddr *) &(dqe.addr),
       sizeof(struct sockaddr));
     if(status != -1) {
  XXLOG_DEBUG("SND: reply sent");
     }
     else {
  XXLOG("SND: error sending reply (%s)", strerror((*__errno_location ())));
     }
 }
    }
    return ((void *)0);
}

canonical_original_code:
void *sender_thread_fn(void *args) {
    int status;
    struct _data_queue_element dqe;
    XXLOG("SND: Started");
    while(1) {
 if(data_queue_get_data(&OUTQ, &dqe) == 0) {
     status = sendto(SOCKET,
       (void *) dqe.data,
       dqe.data_len,
       0,
       (struct sockaddr *) &(dqe.addr),
       sizeof(struct sockaddr));
     if(status != -1) {
  XXLOG_DEBUG("SND: reply sent");
     }
     else {
  XXLOG("SND: error sending reply (%s)", strerror((*__errno_location ())));
     }
 }
    }
    return ((void *)0);
}

variable_types: status int