server

decompiled_code:
int __fastcall server(__int16 a1, int a2)
{
int v2; // er15
unsigned int v3; // er13
char *v4; // rax
pthread_mutex_t *v5; // rbx
__int64 v6; // rbp
int v7; // ebx
int *v8; // rax
__int64 v9; // rbx
char *v10; // rax
int *v11; // rax
__int64 v12; // rbx
char *v13; // rax
int v14; // eax
char *v15; // rbp
int v16; // eax
int *v17; // rax
__int64 v18; // rbx
char *v19; // rax
unsigned int *v20; // rbx
int result; // eax
int *v22; // rax
__int64 v23; // rbx
char *v24; // rax
char *v25; // [rsp+10h] [rbp-70h]
socklen_t addr_len; // [rsp+24h] [rbp-5Ch] BYREF
struct sockaddr fds; // [rsp+28h] [rbp-58h] BYREF
struct sockaddr addr; // [rsp+38h] [rbp-48h] BYREF

v2 = socket(2, 1, 0);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = _bswap_32(0);
*(_WORD *)addr.sa_data = _bswap_16(a1);
if ( bind(v2, &addr, 0x10u) )
{
v8 = __errno_location();
v9 = (unsigned int)*v8;
v10 = strerror(*v8);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 63LL, "server", "Bind", v10, v9);
exit(2);
}
puts("Bind is ok");
v3 = listen(v2, 5);
if ( v3 )
{
v11 = __errno_location();
v12 = (unsigned int)*v11;
v13 = strerror(*v11);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 70LL, "server", "Listen", v13, v12);
exit(3);
}
puts("Listen is ok");
v4 = (char *)malloc(72LL * a2);
v25 = v4;
if ( a2 > 0 )
{
v5 = (pthread_mutex_t *)(v4 + 24);
v6 = (__int64)&v4[72 * (a2 - 1) + 96];
do
{
v5[1].__lock = -1;
pthread_mutex_init(v5, 0LL);
v5 = (pthread_mutex_t *)((char *)v5 + 72);
}
while ( v5 != (pthread_mutex_t *)v6 );
v7 = v3;
while ( 1 )
{
if ( !server_run )
{
LABEL_22:
v20 = (unsigned int *)(v25 + 8);
do
{
pthread_join(*((_QWORD *)v20 + 1), 0LL);
printf("Thread #%d returns: %d\n", v3++, *v20);
v20 += 18;
}
while ( a2 != v3 );
goto LABEL_24;
}
v15 = &v25[72 * v7];
pthread_mutex_lock((pthread_mutex_t *)(v15 + 24));
v16 = *((_DWORD *)v15 + 16);
if ( !v16 )
break;
if ( v16 <= 0 )
{
pthread_mutex_unlock((pthread_mutex_t *)(v15 + 24));
goto LABEL_11;
}
pthread_mutex_unlock((pthread_mutex_t *)(v15 + 24));
LABEL_16:
v7 = (v7 + 1) % a2;
if ( a2 <= v7 )
goto LABEL_22;
}
pthread_join(*((_QWORD *)v15 + 2), 0LL);
printf("Thread #%d returns: %d\n", (unsigned int)v7, *((unsigned int *)v15 + 2));
pthread_mutex_unlock((pthread_mutex_t *)(v15 + 24));
LABEL_11:
puts("server waiting for connection");
if ( !server_run )
goto LABEL_22;
while ( 1 )
{
*(_DWORD *)&fds.sa_family = v2;
*(_WORD *)&fds.sa_data[2] = 1;
v14 = poll((struct pollfd *)&fds, 1uLL, 3500);
if ( v14 == -1 )
{
v17 = __errno_location();
v18 = (unsigned int)*v17;
v19 = strerror(*v17);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 106LL, "server", "Poll", v19, v18);
goto LABEL_22;
}
if ( v14 )
break;
if ( !server_run )
goto LABEL_22;
}
if ( !server_run )
goto LABEL_22;
addr_len = 16;
*((_DWORD *)v15 + 1) = accept(v2, &fds, &addr_len);
printf("server crating thread #%d\n", (unsigned int)v7);
*((_DWORD *)v15 + 16) = 1;
*((_DWORD *)v15 + 2) = pthread_create((pthread_t *)v15 + 2, 0LL, (void *(*)(void *))client_thread, v15);
goto LABEL_16;
}
LABEL_24:
result = close(v2);
if ( result )
{
v22 = __errno_location();
v23 = (unsigned int)*v22;
v24 = strerror(*v22);
result = fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 133LL, "server", "Close server socket", v24, v23);
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int16 a1, int a2)
{
int v2; // er15
unsigned int v3; // er13
char *v4; // rax
pthread_mutex_t *v5; // rbx
__int64 v6; // rbp
int v7; // ebx
int *v8; // rax
__int64 v9; // rbx
char *v10; // rax
int *v11; // rax
__int64 v12; // rbx
char *v13; // rax
int v14; // eax
char *v15; // rbp
int v16; // eax
int *v17; // rax
__int64 v18; // rbx
char *v19; // rax
unsigned int *v20; // rbx
int result; // eax
int *v22; // rax
__int64 v23; // rbx
char *v24; // rax
char *v25; // [rsp+10h] [rbp-70h]
socklen_t addr_len; // [rsp+24h] [rbp-5Ch] BYREF
struct sockaddr fds; // [rsp+28h] [rbp-58h] BYREF
struct sockaddr addr; // [rsp+38h] [rbp-48h] BYREF

v2 = socket(2, 1, 0);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = func8(0);
*(_WORD *)addr.sa_data = func9(a1);
if ( bind(v2, &addr, 0x10u) )
{
v8 = __errno_location();
v9 = (unsigned int)*v8;
v10 = strerror(*v8);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 63LL, "server", "Bind", v10, v9);
exit(2);
}
puts("Bind is ok");
v3 = listen(v2, 5);
if ( v3 )
{
v11 = __errno_location();
v12 = (unsigned int)*v11;
v13 = strerror(*v11);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 70LL, "server", "Listen", v13, v12);
exit(3);
}
puts("Listen is ok");
v4 = (char *)malloc(72LL * a2);
v25 = v4;
if ( a2 > 0 )
{
v5 = (pthread_mutex_t *)(v4 + 24);
v6 = (__int64)&v4[72 * (a2 - 1) + 96];
do
{
v5[1].__lock = -1;
pthread_mutex_init(v5, 0LL);
v5 = (pthread_mutex_t *)((char *)v5 + 72);
}
while ( v5 != (pthread_mutex_t *)v6 );
v7 = v3;
while ( 1 )
{
if ( !server_run )
{
LABEL_22:
v20 = (unsigned int *)(v25 + 8);
do
{
pthread_join(*((_QWORD *)v20 + 1), 0LL);
printf("Thread #%d returns: %d\n", v3++, *v20);
v20 += 18;
}
while ( a2 != v3 );
goto LABEL_24;
}
v15 = &v25[72 * v7];
pthread_mutex_lock((pthread_mutex_t *)(v15 + 24));
v16 = *((_DWORD *)v15 + 16);
if ( !v16 )
break;
if ( v16 <= 0 )
{
pthread_mutex_unlock((pthread_mutex_t *)(v15 + 24));
goto LABEL_11;
}
pthread_mutex_unlock((pthread_mutex_t *)(v15 + 24));
LABEL_16:
v7 = (v7 + 1) % a2;
if ( a2 <= v7 )
goto LABEL_22;
}
pthread_join(*((_QWORD *)v15 + 2), 0LL);
printf("Thread #%d returns: %d\n", (unsigned int)v7, *((unsigned int *)v15 + 2));
pthread_mutex_unlock((pthread_mutex_t *)(v15 + 24));
LABEL_11:
puts("server waiting for connection");
if ( !server_run )
goto LABEL_22;
while ( 1 )
{
*(_DWORD *)&fds.sa_family = v2;
*(_WORD *)&fds.sa_data[2] = 1;
v14 = poll((struct pollfd *)&fds, 1uLL, 3500);
if ( v14 == -1 )
{
v17 = __errno_location();
v18 = (unsigned int)*v17;
v19 = strerror(*v17);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 106LL, "server", "Poll", v19, v18);
goto LABEL_22;
}
if ( v14 )
break;
if ( !server_run )
goto LABEL_22;
}
if ( !server_run )
goto LABEL_22;
addr_len = 16;
*((_DWORD *)v15 + 1) = accept(v2, &fds, &addr_len);
printf("server crating thread #%d\n", (unsigned int)v7);
*((_DWORD *)v15 + 16) = 1;
*((_DWORD *)v15 + 2) = pthread_create((pthread_t *)v15 + 2, 0LL, (void *(*)(void *))client_thread, v15);
goto LABEL_16;
}
LABEL_24:
result = close(v2);
if ( result )
{
v22 = __errno_location();
v23 = (unsigned int)*v22;
v24 = strerror(*v22);
result = fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 133LL, "server", "Close server socket", v24, v23);
}
return result;
}

original_code:
void server(int port, int tcnt) {
    int sockfd = socket(2, SOCK_STREAM, 0);
    struct sockaddr_in server_address;
    server_address.sin_family = 2;
    server_address.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    server_address.sin_port = htons(port);
    if (bind(sockfd, (struct sockaddr *) &server_address, sizeof(server_address))) {
        if (1) { int myerr = (*__errno_location ()); fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 63, __FUNCTION__, "Bind", strerror(myerr), myerr); };
        exit(2);
    } else {
        printf("Bind is ok\n");
    }
    if (listen(sockfd, 5)) {
        if (1) { int myerr = (*__errno_location ()); fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 70, __FUNCTION__, "Listen", strerror(myerr), myerr); };
        exit(3);
    } else {
        printf("Listen is ok\n");
    }
    struct thread_conf *threads = (struct thread_conf *) malloc(tcnt * sizeof(struct thread_conf));
    int i = 0;
    for(i = 0; i < tcnt; ++i) {
        threads[i].status = -1;
        pthread_mutex_init(&(threads[i].lock), ((void *)0));
    }
    for(i = 0; (i < tcnt) && server_run; i = (i + 1) % tcnt) {
        pthread_mutex_lock(&(threads[i].lock));
        if (!threads[i].status) {
            pthread_join(threads[i].thread, ((void *)0));
            printf("Thread #%d returns: %d\n", i, threads[i].iret);
            pthread_mutex_unlock(&(threads[i].lock));
        } else if (threads[i].status > 0) {
            pthread_mutex_unlock(&(threads[i].lock));
            continue;
        } else {
            pthread_mutex_unlock(&(threads[i].lock));
        }
        printf("server waiting for connection\n");
        int pret = 0;
        while(server_run) {
            struct pollfd serv;
            serv.fd = sockfd;
            serv.events = 0x001;
            pret = poll(&serv, 1, 3500);
            if (-1 == pret) {
                if (1) { int myerr = (*__errno_location ()); fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 106, __FUNCTION__, "Poll", strerror(myerr), myerr); };
                break;
            } else if(0 == pret) {
                continue;
            } else {
                break;
            }
        }
        if ((-1 == pret) || !server_run) {
            break;
        }
        struct sockaddr_in client_address;
        int client_len = sizeof(client_address);
        threads[i].sockfd = accept(sockfd, (struct sockaddr *) &client_address, &client_len);
        printf("server crating thread #%d\n", i);
        threads[i].status = 1;
        threads[i].iret = pthread_create(&(threads[i].thread), ((void *)0), client_thread, (void*) &(threads[i]));
    }
    for(i = 0; i < tcnt; ++i) {
        pthread_join(threads[i].thread, ((void *)0));
        printf("Thread #%d returns: %d\n", i, threads[i].iret);
    }
    if (close(sockfd)) {
        if (1) { int myerr = (*__errno_location ()); fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 133, __FUNCTION__, "Close server socket", strerror(myerr), myerr); };
    }
}

canonical_original_code:
void server(int port, int tcnt) {
    int sockfd = socket(2, SOCK_STREAM, 0);
    struct sockaddr_in server_address;
    server_address.sin_family = 2;
    server_address.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    server_address.sin_port = htons(port);
    if (bind(sockfd, (struct sockaddr *) &server_address, sizeof(server_address))) {
        if (1) { int myerr = (*__errno_location ()); fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 63, __FUNCTION__, "Bind", strerror(myerr), myerr); };
        exit(2);
    } else {
        printf("Bind is ok\n");
    }
    if (listen(sockfd, 5)) {
        if (1) { int myerr = (*__errno_location ()); fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 70, __FUNCTION__, "Listen", strerror(myerr), myerr); };
        exit(3);
    } else {
        printf("Listen is ok\n");
    }
    struct thread_conf *threads = (struct thread_conf *) malloc(tcnt * sizeof(struct thread_conf));
    int i = 0;
    for(i = 0; i < tcnt; ++i) {
        threads[i].status = -1;
        pthread_mutex_init(&(threads[i].lock), ((void *)0));
    }
    for(i = 0; (i < tcnt) && server_run; i = (i + 1) % tcnt) {
        pthread_mutex_lock(&(threads[i].lock));
        if (!threads[i].status) {
            pthread_join(threads[i].thread, ((void *)0));
            printf("Thread #%d returns: %d\n", i, threads[i].iret);
            pthread_mutex_unlock(&(threads[i].lock));
        } else if (threads[i].status > 0) {
            pthread_mutex_unlock(&(threads[i].lock));
            continue;
        } else {
            pthread_mutex_unlock(&(threads[i].lock));
        }
        printf("server waiting for connection\n");
        int pret = 0;
        while(server_run) {
            struct pollfd serv;
            serv.fd = sockfd;
            serv.events = 0x001;
            pret = poll(&serv, 1, 3500);
            if (-1 == pret) {
                if (1) { int myerr = (*__errno_location ()); fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 106, __FUNCTION__, "Poll", strerror(myerr), myerr); };
                break;
            } else if(0 == pret) {
                continue;
            } else {
                break;
            }
        }
        if ((-1 == pret) || !server_run) {
            break;
        }
        struct sockaddr_in client_address;
        int client_len = sizeof(client_address);
        threads[i].sockfd = accept(sockfd, (struct sockaddr *) &client_address, &client_len);
        printf("server crating thread #%d\n", i);
        threads[i].status = 1;
        threads[i].iret = pthread_create(&(threads[i].thread), ((void *)0), client_thread, (void *) &(threads[i]));
    }
    for(i = 0; i < tcnt; ++i) {
        pthread_join(threads[i].thread, ((void *)0));
        printf("Thread #%d returns: %d\n", i, threads[i].iret);
    }
    if (close(sockfd)) {
        if (1) { int myerr = (*__errno_location ()); fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 133, __FUNCTION__, "Close server socket", strerror(myerr), myerr); };
    }
}

variable_types: port int

variable_types: tcnt int

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

variable_types: i int

variable_types: pret int

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

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


client

decompiled_code:
int __fastcall client(char *cp, __int16 a2)
{
int v2; // ebp
int v3; // ebx
int result; // eax
unsigned int v5; // ebx
char *v6; // rax
int *v7; // rax
__int64 v8; // rbx
char *v9; // rax
unsigned int v10; // ebx
char *v11; // rax
_BYTE v12[32]; // [rsp+0h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
*(_WORD *)addr.sa_data = _bswap_16(a2);
if ( connect(v2, &addr, 0x10u) )
{
v5 = *__errno_location();
v6 = strerror(v5);
printf("Client: Connect: %s [%d]\n", v6, v5);
exit(2);
}
v3 = 10;
while ( 1 )
{
pack_heart_comm((__int64)v12);
if ( (unsigned int)send(v2, v12, 0x14uLL, 0) != 20 )
break;
sleep(3u);
if ( !--v3 )
goto LABEL_5;
}
v7 = __errno_location();
v8 = (unsigned int)*v7;
v9 = strerror(*v7);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "client.c", 53LL, "client", "Can't send command", v9, v8);
LABEL_5:
result = close(v2);
if ( result )
{
v10 = *__errno_location();
v11 = strerror(v10);
result = printf("Client: close server socket: %s [%d]\n", v11, v10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(char *cp, __int16 a2)
{
int v2; // ebp
int v3; // ebx
int result; // eax
unsigned int v5; // ebx
char *v6; // rax
int *v7; // rax
__int64 v8; // rbx
char *v9; // rax
unsigned int v10; // ebx
char *v11; // rax
_BYTE v12[32]; // [rsp+0h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
*(_WORD *)addr.sa_data = func7(a2);
if ( connect(v2, &addr, 0x10u) )
{
v5 = *__errno_location();
v6 = strerror(v5);
printf("Client: Connect: %s [%d]\n", v6, v5);
exit(2);
}
v3 = 10;
while ( 1 )
{
func8((__int64)v12);
if ( (unsigned int)send(v2, v12, 0x14uLL, 0) != 20 )
break;
sleep(3u);
if ( !--v3 )
goto LABEL_5;
}
v7 = __errno_location();
v8 = (unsigned int)*v7;
v9 = strerror(*v7);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "client.c", 53LL, "client", "Can't send command", v9, v8);
LABEL_5:
result = close(v2);
if ( result )
{
v10 = *__errno_location();
v11 = strerror(v10);
result = printf("Client: close server socket: %s [%d]\n", v11, v10);
}
return result;
}

original_code:
void client(char *ip, int port) {
    int sockfd = socket (2, SOCK_STREAM, 0);
    struct sockaddr_in address;
    address.sin_family = 2;
    address.sin_addr.s_addr= inet_addr(ip);
    address.sin_port = htons(port);
    if (connect(sockfd, (struct sockaddr *) &address, sizeof(address))) {
        int myerr = (*__errno_location ());
        printf("Client: Connect: %s [%d]\n", strerror(myerr), myerr);
        exit(2);
    }
    char com[20];
    int i = 0;
    for(i = 0; i < 10; ++i) {
        pack_heart_comm(com);
        int rsnd = send(sockfd, (void*) com, 20, 0);
        if (20 != rsnd) {
            if (1) { int myerr = (*__errno_location ()); fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "client.c", 53, __FUNCTION__, "Can't send command", strerror(myerr), myerr); };
            break;
        }
        sleep(3);
    }
    if (close(sockfd)) {
        int myerr = (*__errno_location ());
        printf("Client: close server socket: %s [%d]\n", strerror(myerr), myerr);
    }
}

variable_types:
ip
char *

variable_types: sockfd int

variable_types: myerr int

variable_types:
com
char [20]

variable_types: rsnd int

return_type: void

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

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


repo: whatsbcn/hexin

decompiled_code:
void __noreturn sig_die()
{
tcsetattr(0, 2, &oldterm);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
tcsetattr(0, 2, &oldterm);
exit(1);
}

original_code:
void sig_die(int n) {
 tcsetattr(0, 2, &oldterm);
 exit(1);
}

variable_types: n int


filter

decompiled_code:
__int64 __fastcall filter(_QWORD *a1, int a2)
{
_QWORD *v2; // r13
unsigned int v3; // er12
int i; // ebx
char v5; // cl
char v6; // al
char nptr[2]; // [rsp+6h] [rbp-32h] BYREF
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v2 = malloc(0x400uLL);
if ( a2 <= 0 )
{
v3 = 0;
}
else
{
v3 = 0;
for ( i = 0; i < a2; ++i )
{
v6 = *((_BYTE *)a1 + i);
if ( v6 == 92 )
{
v5 = *((_BYTE *)a1 + i + 1);
switch ( v5 )
{
case '\\':
*((_BYTE *)v2 + (int)v3) = 92;
break;
case 'n':
*((_BYTE *)v2 + (int)v3) = 10;
break;
case 'r':
*((_BYTE *)v2 + (int)v3) = 13;
break;
case 't':
*((_BYTE *)v2 + (int)v3) = 9;
break;
case 'x':
nptr[0] = *((_BYTE *)a1 + i + 2);
nptr[1] = *((_BYTE *)a1 + i + 3);
*((_BYTE *)v2 + (int)v3) = strtol(nptr, &endptr, 16);
i += 2;
break;
default:
*((_BYTE *)v2 + (int)v3++) = 92;
*((_BYTE *)v2 + (int)v3) = v5;
break;
}
++i;
}
else
{
*((_BYTE *)v2 + (int)v3) = v6;
}
++v3;
}
}
*((_BYTE *)v2 + (int)v3) = 10;
*a1 = *v2;
a1[127] = v2[127];
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)v2 - ((char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 1024) >> 3));
free(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, int a2)
{
_QWORD *v2; // r13
unsigned int v3; // er12
int i; // ebx
char v5; // cl
char v6; // al
char nptr[2]; // [rsp+6h] [rbp-32h] BYREF
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v2 = malloc(0x400uLL);
if ( a2 <= 0 )
{
v3 = 0;
}
else
{
v3 = 0;
for ( i = 0; i < a2; ++i )
{
v6 = *((_BYTE *)a1 + i);
if ( v6 == 92 )
{
v5 = *((_BYTE *)a1 + i + 1);
switch ( v5 )
{
case '\\':
*((_BYTE *)v2 + (int)v3) = 92;
break;
case 'n':
*((_BYTE *)v2 + (int)v3) = 10;
break;
case 'r':
*((_BYTE *)v2 + (int)v3) = 13;
break;
case 't':
*((_BYTE *)v2 + (int)v3) = 9;
break;
case 'x':
nptr[0] = *((_BYTE *)a1 + i + 2);
nptr[1] = *((_BYTE *)a1 + i + 3);
*((_BYTE *)v2 + (int)v3) = strtol(nptr, &endptr, 16);
i += 2;
break;
default:
*((_BYTE *)v2 + (int)v3++) = 92;
*((_BYTE *)v2 + (int)v3) = v5;
break;
}
++i;
}
else
{
*((_BYTE *)v2 + (int)v3) = v6;
}
++v3;
}
}
*((_BYTE *)v2 + (int)v3) = 10;
*a1 = *v2;
a1[127] = v2[127];
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)v2 - ((char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 1024) >> 3));
free(v2);
return v3;
}

original_code:
int filter(char *buf, int size){
 int i;
 int offset;
 char *buf2;
 char *ptr;
 char ch;
 char hex[2];
 buf2=malloc(1024);
 for(i=0,offset=0;i<size;i++,offset++){
  if(buf[i]=='\\'){
   switch(buf[i+1]){
    case '\\':
     buf2[offset]='\\';
     break;
    case 'n':
     buf2[offset]='\n';
     break;
    case 'r':
     buf2[offset]='\r';
     break;
    case 't':
     buf2[offset]='\t';
     break;
    case 'x':
     hex[0]=buf[i+2];
     hex[1]=buf[i+3];
     buf2[offset]=strtol(hex,&ptr,16);
     i+=2;
     break;
    default:
     buf2[offset]='\\';
     buf2[++offset]=buf[i+1];
     break;
   }
   i++;
  }
  else{
   buf2[offset]=buf[i];
  }
 }
 buf2[offset] = '\n';
 memset(buf,0,1024);
 memcpy(buf, buf2, 1024);
 free(buf2);
 return offset;
}

variable_types:
buf
char *

variable_types: size int

variable_types: offset int

variable_types:
ptr
char *

variable_types: ch char

variable_types:
hex
char [2]

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbp
int v4; // ebx
char *v5; // rax
int v6; // er12
int i; // ebx
struct termios *v8; // rdi
struct termios *v9; // rsi
__int64 j; // rcx
int v11; // er14
__int64 v12; // r13
int v13; // er15
struct termios *v14; // rdi
struct termios *v15; // rsi
__int64 k; // rcx
int v17; // [rsp+8h] [rbp-C0h]
int v18; // [rsp+8h] [rbp-C0h]
int v19; // [rsp+8h] [rbp-C0h]
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF

puts("Hexin Terminal v0.2 - z0nKT1g3r & whats");
v3 = malloc(0x400uLL);
v4 = open("/dev/ptmx", 2);
grantpt(v4);
unlockpt(v4);
v5 = ptsname(v4);
v6 = open(v5, 2);
if ( !fork() )
{
setsid();
ioctl(v6, 0x540EuLL, 0LL);
dup2(v6, 0);
dup2(v6, 1);
dup2(v6, 2);
close(v6);
for ( i = 1; i != 64; ++i )
signal(i, 0LL);
putenv("PS1=\\[\\033[1;30m\\][\\[\\033[0;32m\\]\\u\\[\\033[1;32m\\]@\\[\\033[0;32m\\]\\h \\[\\033[1;37m\\]\\W\\[\\033"
"[1;30m\\]]\\[\\033[0m\\]# ");
execl("/bin/bash", "bash", "--norc", "-i", 0LL);
puts("despres");
exit(1);
}
tcgetattr(0, &oldterm);
sleep(1u);
v8 = &newterm;
v9 = &oldterm;
for ( j = 15LL; j; --j )
{
v8->c_iflag = v9->c_iflag;
v9 = (struct termios *)((char *)v9 + 4);
v8 = (struct termios *)((char *)v8 + 4);
}
newterm.c_lflag &= 0xFFFFFFF4;
newterm.c_iflag &= 0xFFFFEBFF;
tcsetattr(0, 2, &newterm);
signal(17, (__sighandler_t)sig_die);
signal(2, (__sighandler_t)sig_die);
signal(3, (__sighandler_t)sig_die);
signal(4, (__sighandler_t)sig_die);
signal(6, (__sighandler_t)sig_die);
signal(11, (__sighandler_t)sig_die);
signal(15, (__sighandler_t)sig_die);
v11 = v4 / 64;
v12 = 1LL << (v4 % 64);
v13 = 0;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[0] |= 1uLL;
readfds.fds_bits[v11] |= v12;
if ( select(v4 + 1, &readfds, 0LL, 0LL, 0LL) >= 0 )
break;
if ( *__errno_location() != 4 )
goto LABEL_18;
}
if ( (readfds.fds_bits[0] & 1) == 0 )
break;
if ( v13 )
{
*(_BYTE *)v3 = 92;
v18 = read(0, (char *)v3 + 1, 0x400uLL);
if ( v18 <= 0 && *__errno_location() != 4
|| (filter(v3, v18), write(v4, v3, v18) < 0) && *__errno_location() != 4 )
{
LABEL_18:
tcsetattr(0, 2, &oldterm);
exit(0);
}
tcsetattr(0, 2, &newterm);
memset(v3, 0, 0x400uLL);
}
else
{
v17 = read(0, v3, 1uLL);
if ( v17 <= 0 && *__errno_location() != 4 )
goto LABEL_18;
if ( *(_BYTE *)v3 == 92 )
{
putchar(92);
fflush(stdout);
v14 = &tmpterm;
v15 = &oldterm;
for ( k = 15LL; k; --k )
{
v14->c_iflag = v15->c_iflag;
v15 = (struct termios *)((char *)v15 + 4);
v14 = (struct termios *)((char *)v14 + 4);
}
tmpterm.c_iflag &= 0xFFFFEBFF;
tcsetattr(0, 2, &tmpterm);
v13 = 1;
}
else if ( write(v4, v3, v17) < 0 && *__errno_location() != 4 )
{
goto LABEL_18;
}
}
}
if ( (readfds.fds_bits[v11] & v12) != 0 )
{
v19 = read(v4, v3, 0x400uLL);
if ( v19 <= 0 && *__errno_location() != 4 )
goto LABEL_18;
if ( v13 )
v13 = 0;
else
write(1, v3, v19);
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbp
int v4; // ebx
char *v5; // rax
int v6; // er12
int i; // ebx
struct termios *v8; // rdi
struct termios *v9; // rsi
__int64 j; // rcx
int v11; // er14
__int64 v12; // r13
int v13; // er15
struct termios *v14; // rdi
struct termios *v15; // rsi
__int64 k; // rcx
int v17; // [rsp+8h] [rbp-C0h]
int v18; // [rsp+8h] [rbp-C0h]
int v19; // [rsp+8h] [rbp-C0h]
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF

puts("Hexin Terminal v0.2 - z0nKT1g3r & whats");
v3 = malloc(0x400uLL);
v4 = open("/dev/ptmx", 2);
grantpt(v4);
unlockpt(v4);
v5 = ptsname(v4);
v6 = open(v5, 2);
if ( !fork() )
{
setsid();
ioctl(v6, 0x540EuLL, 0LL);
dup2(v6, 0);
dup2(v6, 1);
dup2(v6, 2);
close(v6);
for ( i = 1; i != 64; ++i )
signal(i, 0LL);
putenv("PS1=\\[\\033[1;30m\\][\\[\\033[0;32m\\]\\u\\[\\033[1;32m\\]@\\[\\033[0;32m\\]\\h \\[\\033[1;37m\\]\\W\\[\\033"
"[1;30m\\]]\\[\\033[0m\\]# ");
execl("/bin/bash", "bash", "--norc", "-i", 0LL);
puts("despres");
exit(1);
}
tcgetattr(0, &oldterm);
sleep(1u);
v8 = &newterm;
v9 = &oldterm;
for ( j = 15LL; j; --j )
{
v8->c_iflag = v9->c_iflag;
v9 = (struct termios *)((char *)v9 + 4);
v8 = (struct termios *)((char *)v8 + 4);
}
newterm.c_lflag &= 0xFFFFFFF4;
newterm.c_iflag &= 0xFFFFEBFF;
tcsetattr(0, 2, &newterm);
signal(17, (__sighandler_t)sig_die);
signal(2, (__sighandler_t)sig_die);
signal(3, (__sighandler_t)sig_die);
signal(4, (__sighandler_t)sig_die);
signal(6, (__sighandler_t)sig_die);
signal(11, (__sighandler_t)sig_die);
signal(15, (__sighandler_t)sig_die);
v11 = v4 / 64;
v12 = 1LL << (v4 % 64);
v13 = 0;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[0] |= 1uLL;
readfds.fds_bits[v11] |= v12;
if ( select(v4 + 1, &readfds, 0LL, 0LL, 0LL) >= 0 )
break;
if ( *__errno_location() != 4 )
goto LABEL_18;
}
if ( (readfds.fds_bits[0] & 1) == 0 )
break;
if ( v13 )
{
*(_BYTE *)v3 = 92;
v18 = read(0, (char *)v3 + 1, 0x400uLL);
if ( v18 <= 0 && *__errno_location() != 4
|| (func8(v3, v18), write(v4, v3, v18) < 0) && *__errno_location() != 4 )
{
LABEL_18:
tcsetattr(0, 2, &oldterm);
exit(0);
}
tcsetattr(0, 2, &newterm);
memset(v3, 0, 0x400uLL);
}
else
{
v17 = read(0, v3, 1uLL);
if ( v17 <= 0 && *__errno_location() != 4 )
goto LABEL_18;
if ( *(_BYTE *)v3 == 92 )
{
putchar(92);
fflush(stdout);
v14 = &tmpterm;
v15 = &oldterm;
for ( k = 15LL; k; --k )
{
v14->c_iflag = v15->c_iflag;
v15 = (struct termios *)((char *)v15 + 4);
v14 = (struct termios *)((char *)v14 + 4);
}
tmpterm.c_iflag &= 0xFFFFEBFF;
tcsetattr(0, 2, &tmpterm);
v13 = 1;
}
else if ( write(v4, v3, v17) < 0 && *__errno_location() != 4 )
{
goto LABEL_18;
}
}
}
if ( (readfds.fds_bits[v11] & v12) != 0 )
{
v19 = read(v4, v3, 0x400uLL);
if ( v19 <= 0 && *__errno_location() != 4 )
goto LABEL_18;
if ( v13 )
v13 = 0;
else
write(1, v3, v19);
}
}
}

original_code:
int main(int argc, char **argv){
 printf("Hexin Terminal v0.2 - z0nKT1g3r & whats\n");
 char *buf = malloc(1024);
 int tty, pty;
 extern char *ptsname();
 pty = open("/dev/ptmx", 02);
 grantpt(pty);
 unlockpt(pty);
 tty = open(ptsname(pty), 02);
 if(!fork()) {
  setsid();
  ioctl(tty, 0x540E, ((void *)0));
  dup2(tty, 0);
  dup2(tty, 1);
  dup2(tty, 2);
  close(tty);
  int i;
  for (i = 1; i < 64; i++)
   signal(i, ((__sighandler_t) 0));
  putenv("PS1=\\[\\033[1;30m\\][\\[\\033[0;32m\\]\\u\\[\\033[1;32m\\]@\\[\\033[0;32m\\]\\h \\[\\033[1;37m\\]\\W\\[\\033[1;30m\\]]\\[\\033[0m\\]# ");
  execl("/bin/bash", "bash", "--norc", "-i", ((void *)0));
  printf("despres\n");
  exit(1);
 }
 else{
  tcgetattr(0, &oldterm);
  sleep(1);
  newterm = oldterm;
  newterm.c_lflag &= ~(0000002 | 0000010 | 0000001);
  newterm.c_iflag &= ~(0002000 | 0010000);
  tcsetattr(0, 2, &newterm);
  signal(17, sig_die);
  signal(2, sig_die);
  signal(3, sig_die);
  signal(4, sig_die);
  signal(6, sig_die);
  signal(11, sig_die);
  signal(15, sig_die);
  int state = 0;
  char hex[2];
  while (1) {
    fd_set fds;
    int count;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
    ((void) (((&fds)->__fds_bits)[((pty) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((pty) % (8 * (int) sizeof (__fd_mask)))))));
    if (select(pty + 1, &fds, ((void *)0), ((void *)0), ((void *)0)) < 0) {
      if ((*__errno_location ()) == 4)
        continue;
      break;
    }
    if (((((&fds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
     if (state == 0) {
      count = read(0, buf, 1);
      if ((count <= 0) && ((*__errno_location ()) != 4))
        break;
      if (buf[0] == '\\') {
       printf("\\");fflush(stdout);
       state = 1;
          tmpterm = oldterm;
             tmpterm.c_lflag &= ~0000001 | ~0000010 | 0000002;
             tmpterm.c_iflag &= ~(0002000 | 0010000);
       tcsetattr(0, 2, &tmpterm);
      } else {
       if ((write(pty, buf, count) < 0) && ((*__errno_location ()) != 4))
        break;
      }
     } else {
      buf[0] = '\\';
      count = read(0, buf+1, 1024);
      if ((count <= 0) && ((*__errno_location ()) != 4))
        break;
      filter(buf, count);
      if ((write(pty, buf, count) < 0) && ((*__errno_location ()) != 4))
        break;
      tcsetattr(0, 2, &newterm);
      memset(buf, 0, 1024);
     }
    } else if (((((&fds)->__fds_bits)[((pty) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((pty) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
      count = read(pty, buf, 1024);
      if ((count <= 0) && ((*__errno_location ()) != 4))
        break;
      if (state == 0) write(1, buf, count);
      else state = 0;
    }
  }
  tcsetattr(0, 2, &oldterm);
 }
 exit(0);
}

canonical_original_code:
int main(int argc, char **argv){
 printf("Hexin Terminal v0.2 - z0nKT1g3r & whats\n");
 char *buf = malloc(1024);
 int tty; int pty;
 extern char *ptsname();
 pty = open("/dev/ptmx", 02);
 grantpt(pty);
 unlockpt(pty);
 tty = open(ptsname(pty), 02);
 if(!fork()) {
  setsid();
  ioctl(tty, 0x540E, ((void *)0));
  dup2(tty, 0);
  dup2(tty, 1);
  dup2(tty, 2);
  close(tty);
  int i;
  for (i = 1; i < 64; i++)
   signal(i, ((void (*)(int)) 0));
  putenv("PS1=\\[\\033[1;30m\\][\\[\\033[0;32m\\]\\u\\[\\033[1;32m\\]@\\[\\033[0;32m\\]\\h \\[\\033[1;37m\\]\\W\\[\\033[1;30m\\]]\\[\\033[0m\\]# ");
  execl("/bin/bash", "bash", "--norc", "-i", ((void *)0));
  printf("despres\n");
  exit(1);
 }
 else{
  tcgetattr(0, &oldterm);
  sleep(1);
  newterm = oldterm;
  newterm.c_lflag &= ~(0000002 | 0000010 | 0000001);
  newterm.c_iflag &= ~(0002000 | 0010000);
  tcsetattr(0, 2, &newterm);
  signal(17, sig_die);
  signal(2, sig_die);
  signal(3, sig_die);
  signal(4, sig_die);
  signal(6, sig_die);
  signal(11, sig_die);
  signal(15, sig_die);
  int state = 0;
  char hex[2];
  while (1) {
    struct fd_set fds;
    int count;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
    ((void) (((&fds)->__fds_bits)[((pty) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((pty) % (8 * (int) sizeof (__fd_mask)))))));
    if (select(pty + 1, &fds, ((void *)0), ((void *)0), ((void *)0)) < 0) {
      if ((*__errno_location ()) == 4)
        continue;
      break;
    }
    if (((((&fds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
     if (state == 0) {
      count = read(0, buf, 1);
      if ((count <= 0) && ((*__errno_location ()) != 4))
        break;
      if (buf[0] == '\\') {
       printf("\\");fflush(stdout);
       state = 1;
          tmpterm = oldterm;
             tmpterm.c_lflag &= ~0000001 | ~0000010 | 0000002;
             tmpterm.c_iflag &= ~(0002000 | 0010000);
       tcsetattr(0, 2, &tmpterm);
      } else {
       if ((write(pty, buf, count) < 0) && ((*__errno_location ()) != 4))
        break;
      }
     } else {
      buf[0] = '\\';
      count = read(0, buf+1, 1024);
      if ((count <= 0) && ((*__errno_location ()) != 4))
        break;
      filter(buf, count);
      if ((write(pty, buf, count) < 0) && ((*__errno_location ()) != 4))
        break;
      tcsetattr(0, 2, &newterm);
      memset(buf, 0, 1024);
     }
    } else if (((((&fds)->__fds_bits)[((pty) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((pty) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
      count = read(pty, buf, 1024);
      if ((count <= 0) && ((*__errno_location ()) != 4))
        break;
      if (state == 0) write(1, buf, count);
      else state = 0;
    }
  }
  tcsetattr(0, 2, &oldterm);
 }
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: tty int

variable_types: pty int

variable_types:
ptsname
char *()

variable_types: state int

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

variable_types: count int


repo: white-pony/planet-lander

decompiled_code:
size_t __fastcall draw_vector_text(char *s, int a2, int a3, float a4)
{
unsigned __int64 i; // r12
size_t result; // rax
__int64 v7; // rbx
__int64 v8; // rbp
char v9; // al
float *v10; // rbx
__int64 v11; // rbp
float v12; // [rsp+8h] [rbp-40h]
float v13; // [rsp+Ch] [rbp-3Ch]

for ( i = 0LL; ; ++i )
{
result = strlen(s);
if ( result <= i )
break;
v12 = (float)((float)(a4 * 1.4) * (float)(int)i) + (float)a2;
v13 = (float)a3;
result = (unsigned __int8)s[i];
if ( (char)result <= 31 )
break;
v7 = (char)result - 32;
v8 = chars_coords[v7];
glBegin(1LL);
v9 = char_lines[v7];
if ( v9 > 0 )
{
v10 = (float *)v8;
v11 = v8 + 16LL * (unsigned int)(v9 - 1) + 16;
do
{
glVertex2f((float)(a4 * *v10) + v12, (float)((float)(1.5 * v10[1]) * a4) + v13);
glVertex2f((float)(a4 * v10[2]) + v12, (float)((float)(1.5 * v10[3]) * a4) + v13);
v10 += 4;
}
while ( v10 != (float *)v11 );
}
glEnd();
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(char *s, int a2, int a3, float a4)
{
unsigned __int64 i; // r12
size_t result; // rax
__int64 v7; // rbx
__int64 v8; // rbp
char v9; // al
float *v10; // rbx
__int64 v11; // rbp
float v12; // [rsp+8h] [rbp-40h]
float v13; // [rsp+Ch] [rbp-3Ch]

for ( i = 0LL; ; ++i )
{
result = strlen(s);
if ( result <= i )
break;
v12 = (float)((float)(a4 * 1.4) * (float)(int)i) + (float)a2;
v13 = (float)a3;
result = (unsigned __int8)s[i];
if ( (char)result <= 31 )
break;
v7 = (char)result - 32;
v8 = chars_coords[v7];
glBegin(1LL);
v9 = char_lines[v7];
if ( v9 > 0 )
{
v10 = (float *)v8;
v11 = v8 + 16LL * (unsigned int)(v9 - 1) + 16;
do
{
glVertex2f((float)(a4 * *v10) + v12, (float)((float)(1.5 * v10[1]) * a4) + v13);
glVertex2f((float)(a4 * v10[2]) + v12, (float)((float)(1.5 * v10[3]) * a4) + v13);
v10 += 4;
}
while ( v10 != (float *)v11 );
}
glEnd();
}
return result;
}

original_code:
void draw_vector_text(const char* text, int x, int y, float font_scale)
{
 for (int i=0; i<strlen(text); i++)
 {
  float char_x = x + SPASING * font_scale * i;
  float char_y = y;
  char current_char = text[i];
  if (current_char < 32)
   return;
  const float* current_char_coords = chars_coords[current_char-32];
  glBegin(0x0001);
  for (int l = 0; l < char_lines[current_char-32]; l++) {
   glVertex2f(char_x + current_char_coords[4*l] * font_scale, char_y + current_char_coords[4*l+1] * HEIGHT_WIDTH_RATIO * font_scale);
   glVertex2f(char_x + current_char_coords[4*l+2] * font_scale, char_y + current_char_coords[4*l+3] * HEIGHT_WIDTH_RATIO * font_scale);
  }
  glEnd();
 }
}

canonical_original_code:
void draw_vector_text(char *text, int x, int y, float font_scale)
{
 for (int i = 0; i<strlen(text); i++)
 {
  float char_x = x + SPASING * font_scale * i;
  float char_y = y;
  char current_char = text[i];
  if (current_char < 32)
   return;
  float *current_char_coords = chars_coords[current_char-32];
  glBegin(0x0001);
  for (int l = 0; l < char_lines[current_char-32]; l++) {
   glVertex2f(char_x + current_char_coords[4*l] * font_scale, char_y + current_char_coords[4*l+1] * HEIGHT_WIDTH_RATIO * font_scale);
   glVertex2f(char_x + current_char_coords[4*l+2] * font_scale, char_y + current_char_coords[4*l+3] * HEIGHT_WIDTH_RATIO * font_scale);
  }
  glEnd();
 }
}

variable_types:
text
char *

variable_types: x int

variable_types: y int

variable_types: i int

variable_types: l int


Glpk

decompiled_code:
__int64 Glpk()
{
int v0; // ebx
unsigned int v1; // ebp

if ( NZERO <= 0 )
return 0;
v0 = 0;
v1 = 0;
do
{
v0 -= ((unsigned int)Lp_main() == 0) - 1;
printf("SNR is %f, failure number is %d, total number is %d\n", *(float *)&SNR, (unsigned int)v0, ++v1);
}
while ( NZERO > v0 );
return v1;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // ebx
unsigned int v1; // ebp

if ( NZERO <= 0 )
return 0;
v0 = 0;
v1 = 0;
do
{
v0 -= ((unsigned int)Lp_main() == 0) - 1;
printf("SNR is %f, failure number is %d, total number is %d\n", *(float *)&SNR, (unsigned int)v0, ++v1);
}
while ( NZERO > v0 );
return v1;
}

original_code:
int Glpk()
{
 int num_total = 0;
 int num_nzero = 0;
 while(num_nzero < NZERO)
 {
  if(Lp_main())
   num_nzero ++;
  num_total ++;
  printf("SNR is %f, failure number is %d, total number is %d\n", SNR, num_nzero, num_total);
 }
 return num_total;
}


Gunplot

decompiled_code:
void Gunplot()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void Gunplot()
{
}

canonical_original_code:
void Gunplot()
{
}


updatePC

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

regPC = a1;
result = (unsigned int)(a1 >> 7);
dword_404144 = a1 >> 7;
dword_404148 = a1 & 0x7F;
return result;
}

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

regPC = a1;
result = (unsigned int)(a1 >> 7);
dword_404144 = a1 >> 7;
dword_404148 = a1 & 0x7F;
return result;
}

original_code:
int updatePC(int i)
{
  regPC.addr = i;
  regPC.page = i >> 7;
  regPC.offset = i & 0x7f;
}


original_code:
int group1If(int i, int opcode, int groupbit)
{
   group1.opcode = opcode;
   group1.bit3 = groupbit;
   group1.cla = (i >> 7) & 1;
   group1.cll = (i >> 6) & 1;
   group1.cma = (i >> 5) & 1;
   group1.cml = (i >> 4) & 1;
   group1.rar = (i >> 3) & 1;
   group1.ral = (i >> 2) & 1;
   group1.rotate = (i >> 1) & 1;
   group1.iac = i & 1;
   if (group1.cla == 1)
      regAC.addr = 0;
   if (group1.cll == 1)
      regAC.link = 0;
   if (group1.cma == 1)
      regAC.addr = ~regAC.addr;
   if (group1.cml == 1)
      regAC.link = ~regAC.link;
   if (group1.iac == 1)
      regAC.addr = regAC.addr + 1;
   if (group1.rar == 1 && group1.rotate == 0)
      regAC.addr = (0xfff & (regAC.addr >> 1)) || (regAC.addr << 11);
   if (group1.rar == 1 && group1.rotate == 1)
      regAC.addr = (0xfff & (regAC.addr >> 2)) || (regAC.addr << 10);
   if (group1.ral == 1 && group1.rotate == 0)
      regAC.addr = (0xfff & (regAC.addr << 1)) || (regAC.addr >> 11);
   if (group1.ral == 1 && group1.rotate == 1)
      regAC.addr = (0xfff & (regAC.addr << 2)) || (regAC.addr >> 10);
   else
      countClock--;
   updatePC(regPC.addr + 1);
   return 0;
}

variable_types: opcode int

variable_types: groupbit int


decompiled_code:
__int64 __fastcall group2If(int a1, int a2, int a3, int a4)
{
group2 = a2;
dword_4040A4 = a3;
dword_4040A8 = (a1 >> 7) & 1;
dword_4040AC = (a1 >> 6) & 1;
dword_4040B8 = (a1 >> 5) & 1;
dword_4040C0 = (a1 >> 4) & 1;
dword_4040C4 = (a1 >> 3) & 1;
dword_4040CC = (a1 >> 2) & 1;
dword_4040D0 = (a1 >> 1) & 1;
dword_4040D4 = a4;
if ( dword_4040AC && dword_40413C < 0 )
updatePC(regPC + 1);
if ( dword_4040B8 == 1 && !dword_40413C )
updatePC(regPC + 1);
if ( dword_4040C0 == 1 && regAC )
updatePC(regPC + 1);
if ( dword_4040B0 == 1 && dword_40413C > 0 )
updatePC(regPC + 1);
if ( dword_4040B4 == 1 && dword_40413C )
updatePC(regPC + 1);
if ( dword_4040BC == 1 && !regAC )
updatePC(regPC + 1);
if ( dword_4040C8 == 1 )
updatePC(regPC + 1);
if ( dword_4040A8 == 1 )
updatePC(regPC + 1);
if ( dword_4040CC == 1 )
printf("Warning: Group 2 instruction ORs the SR with the AC; nop.");
updatePC(regPC + 1);
return 0LL;
}

original_code:
int group2If(int i, int opcode, int groupbit, int bit11)
{
   group2.opcode = opcode;
   group2.bit3 = groupbit;
   group2.cla = (i >> 7) & 1;
   group2.sma = (i >> 6) & 1;
   group2.sza = (i >> 5) & 1;
   group2.snl = (i >> 4) & 1;
   group2.rev = (i >> 3) & 1;
   group2.osr = (i >> 2) & 1;
   group2.hlt = (i >> 1) & 1;
   group2.bit11 = bit11;
   if (group2.sma == 1)
   {
      if (regAC.addr < 0)
         updatePC(regPC.addr + 1);
   }
   if (group2.sza == 1)
   {
      if (regAC.addr == 0)
         updatePC(regPC.addr + 1);
   }
   if (group2.snl == 1)
  {
      if (regAC.link != 0)
         updatePC(regPC.addr + 1);
   }
   if (group2.spa == 1)
   {
      if (regAC.addr > 0)
         updatePC(regPC.addr + 1);
   }
   if (group2.sna == 1)
   {
      if (regAC.addr != 0)
         updatePC(regPC.addr + 1);
   }
   if (group2.szl == 1)
   {
      if (regAC.link == 0)
          updatePC(regPC.addr + 1);
   }
   if (group2.skp == 1)
      updatePC(regPC.addr + 1);
   if (group2.cla == 1)
      updatePC(regPC.addr + 1);
   if (group2.osr == 1)
   {
      printf("Warning: Group 2 instruction ORs the SR with the AC; nop.");
   }
   updatePC(regPC.addr + 1);
   return 0;
}


updateCPMA

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

regCPMA = a1;
result = (unsigned int)(a1 >> 7);
dword_40410C = a1 >> 7;
dword_404110 = a1 & 0x7F;
return result;
}

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

regCPMA = a1;
result = (unsigned int)(a1 >> 7);
dword_40410C = a1 >> 7;
dword_404110 = a1 & 0x7F;
return result;
}

original_code:
int updateCPMA(int i)
{
  regCPMA.addr = i;
  regCPMA.page = i >> 7;
  regCPMA.offset = i & 0x7f;
}


handleIR

original_code:
int handleIR(int i)
{
  regIR.addr = i;
  regIR.page = i >> 7;
  regIR.indirectBit = (i >> 8) & 1;
  regIR.pageBit = (i >> 7) & 1;
  regIR.offset = i & 0x7f;
  regIR.opcode = i >> 9;
}


getHex

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

result = (unsigned int)(a1 - 48);
if ( (unsigned int)result > 9 )
{
if ( (unsigned int)(a1 - 97) <= 5 )
{
result = (unsigned int)(a1 - 87);
}
else if ( (unsigned int)(a1 - 65) > 5 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)(a1 - 55);
}
}
return result;
}

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

result = (unsigned int)(a1 - 48);
if ( (unsigned int)result > 9 )
{
if ( (unsigned int)(a1 - 97) <= 5 )
{
result = (unsigned int)(a1 - 87);
}
else if ( (unsigned int)(a1 - 65) > 5 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)(a1 - 55);
}
}
return result;
}

original_code:
int getHex(int num)
{
  if (48 <= num && num <= 57)
     return num - 48;
  else if (97 <= num && num <= 102)
     return num - 87;
  else if (65 <= num && num <= 70)
     return num - 55;
  else
     return -1;
}

variable_types: num int


loadAllTheThings

decompiled_code:
__int64 loadAllTheThings()
{
int v0; // ebp
int v1; // er12
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // er12
char v7; // [rsp+Bh] [rbp-1Dh]
char v8; // [rsp+Ch] [rbp-1Ch]
char v9; // [rsp+Dh] [rbp-1Bh]
char v10; // [rsp+Eh] [rbp-1Ah]

ifp = fopen("test.mem", "r");
v0 = 0;
while ( (unsigned int)__isoc99_fscanf() != -1 )
{
if ( v7 == 64 )
{
++v0;
v1 = getHex(v8);
v2 = getHex(v9);
v3 = getHex(v10) + 16 * (16 * v1 + v2);
updatePC(v3);
if ( v0 == 1 )
{
handleIR(v3);
}
else if ( v0 > 2 )
{
puts("Warning: Input file lines after the third @ were ignored;\n the program will now execute.\n");
break;
}
}
else
{
if ( !v0 )
{
puts("Warning: The first line of the input file did not contain an @. Halting program.");
break;
}
v4 = getHex(v7);
v5 = getHex(v8);
memory[128 * (__int64)dword_404144 + dword_404148] = getHex(v9) + 16 * (v5 + 16 * v4);
updatePC(regPC + 1);
}
}
fclose(ifp);
return 0LL;
}

canonical_decompiled_code:
__int64 func13()
{
int v0; // ebp
int v1; // er12
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // er12
char v7; // [rsp+Bh] [rbp-1Dh]
char v8; // [rsp+Ch] [rbp-1Ch]
char v9; // [rsp+Dh] [rbp-1Bh]
char v10; // [rsp+Eh] [rbp-1Ah]

ifp = fopen("test.mem", "r");
v0 = 0;
while ( (unsigned int)__isoc99_fscanf() != -1 )
{
if ( v7 == 64 )
{
++v0;
v1 = func12(v8);
v2 = func12(v9);
v3 = func12(v10) + 16 * (16 * v1 + v2);
func7(v3);
if ( v0 == 1 )
{
func11(v3);
}
else if ( v0 > 2 )
{
puts("Warning: Input file lines after the third @ were ignored;\n the program will now execute.\n");
break;
}
}
else
{
if ( !v0 )
{
puts("Warning: The first line of the input file did not contain an @. Halting program.");
break;
}
v4 = func12(v7);
v5 = func12(v8);
memory[128 * (__int64)dword_404144 + dword_404148] = func12(v9) + 16 * (v5 + 16 * v4);
func7(regPC + 1);
}
}
fclose(ifp);
return 0LL;
}

original_code:
int loadAllTheThings()
{
  int count;
  int input1;
  int input2;
  int input3;
  int i;
  char input[5];
  count = 0;
  ifp = fopen("test.mem", "r");
  while (fscanf(ifp, "%s\n", &input) != (-1))
  {
    if (input[0] == '@')
    {
      count++;
      input1 = getHex(input[1]);
      input2 = getHex(input[2]);
      input3 = getHex(input[3]);
      i = input1*256 + input2*16 + input3;
      updatePC(i);
      if (count == 1)
      {
        handleIR(i);
      }
      else if (count > 2)
      {
         printf("Warning: Input file lines after the third @ were ignored;\n "
                          "    the program will now execute.\n\n");
         break;
      }
    }
    else
    {
         if (count == 0)
         {
            printf("Warning: The first line of the input file did not "
                             "contain an @. Halting program.\n");
     break;
         }
         input1 = getHex(input[0]);
         input2 = getHex(input[1]);
         input3 = getHex(input[2]);
         i = input1*256 + input2*16 + input3;
         memory[regPC.page][regPC.offset] = i;
         updatePC(regPC.addr + 1);
    }
  }
  fclose(ifp);
  return 0;
}

variable_types:
input
char [5]


getEffAddr

decompiled_code:
__int64 getEffAddr()
{
int v0; // eax

if ( dword_40412C )
{
if ( dword_40412C == 1 )
{
if ( dword_404128 == 1 )
{
regCPMA = memory[128 * (__int64)dword_404130 + dword_404134];
++countClock;
return 0LL;
}
if ( !dword_404128 )
{
regCPMA = dword_404130 + dword_404134;
return 0LL;
}
}
else if ( dword_40412C > 1 )
{
goto LABEL_9;
}
}
else
{
if ( dword_404128 == 1 )
{
regCPMA = memory[dword_404134];
++countClock;
return 0LL;
}
if ( !dword_404128 )
{
v0 = memory[dword_404134];
memory[dword_404134] = v0 + 1;
regCPMA = v0;
countClock += 2;
return 0LL;
}
}
if ( dword_404128 <= 1 )
return 0LL;
LABEL_9:
printf("Something's gone badly wrong.");
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
int v0; // eax

if ( dword_40412C )
{
if ( dword_40412C == 1 )
{
if ( dword_404128 == 1 )
{
regCPMA = memory[128 * (__int64)dword_404130 + dword_404134];
++countClock;
return 0LL;
}
if ( !dword_404128 )
{
regCPMA = dword_404130 + dword_404134;
return 0LL;
}
}
else if ( dword_40412C > 1 )
{
goto LABEL_9;
}
}
else
{
if ( dword_404128 == 1 )
{
regCPMA = memory[dword_404134];
++countClock;
return 0LL;
}
if ( !dword_404128 )
{
v0 = memory[dword_404134];
memory[dword_404134] = v0 + 1;
regCPMA = v0;
countClock += 2;
return 0LL;
}
}
if ( dword_404128 <= 1 )
return 0LL;
LABEL_9:
printf("Something's gone badly wrong.");
return 0LL;
}

original_code:
int getEffAddr()
{
        if (regIR.pageBit == 0 && regIR.indirectBit == 1)
        {
          regCPMA.addr = memory[0][regIR.offset];
          countClock++;
        }
        else if (regIR.pageBit == 1 && regIR.indirectBit == 1)
        {
          regCPMA.addr = memory[regIR.page][regIR.offset];
          countClock++;
        }
        else if (regIR.pageBit == 1 && regIR.indirectBit == 0)
        {
          regCPMA.addr = regIR.page + regIR.offset;
        }
        else if (regIR.pageBit == 0 && regIR.indirectBit == 0)
        {
          if (0x8 < regIR.offset < 0xf)
          {
            regCPMA.addr = memory[0][regIR.offset]++;
            countClock = countClock + 2;
          }
          else
          {
            regCPMA.addr = memory[0][regIR.offset];
            countClock++;
          }
        }
        else if (regIR.pageBit > 1 || regIR.indirectBit > 1)
        {
          printf("Something's gone badly wrong.");
        }
 return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
int v4; // ecx
int v5; // edi
int v6; // eax

memory[0] = 0;
loadAllTheThings(argc, argv, envp);
updatePC(regIR);
while ( *(&group2 + 12) != 1 )
{
ofp = fopen("tracefile.din", "a");
++countInstr;
v5 = memory[128 * (__int64)dword_404144 + dword_404148];
v6 = v5 >> 9;
if ( v5 <= 3071 )
{
handleIR(v5);
getEffAddr();
switch ( dword_404124 )
{
case 0:
++countAND;
countClock += 2;
dword_40413C &= memory[128 * (__int64)dword_40410C + dword_404110];
updatePC(regPC + 1);
trace = 0;
dword_404094 = regCPMA;
break;
case 1:
++countTAD;
countClock += 2;
dword_40413C -= memory[128 * (__int64)dword_40410C + dword_404110];
updatePC(regPC + 1);
trace = 0;
dword_404094 = regCPMA;
break;
case 2:
countClock += 2;
++countISZ;
v3 = dword_404110 + ((__int64)dword_40410C << 7);
v4 = memory[v3];
memory[v3] = v4 + 1;
if ( v4 == -1 )
updatePC(++regPC);
trace = 1;
dword_404094 = regCPMA;
break;
case 3:
countClock += 2;
++countDCA;
memory[128 * (__int64)dword_40410C + dword_404110] = dword_40413C;
dword_40413C = 0;
regAC = 0;
updatePC(regPC + 1);
trace = 1;
dword_404094 = regCPMA;
break;
case 4:
countClock += 2;
++countJMS;
updateCPMA(regPC);
regPC = regCPMA + 1;
updatePC(regCPMA + 1);
trace = 1;
dword_404094 = regCPMA;
break;
case 5:
++countJMP;
++countClock;
regPC = regCPMA;
updatePC(regCPMA);
trace = 2;
dword_404094 = regCPMA;
break;
default:
break;
}
}
else if ( v6 == 6 )
{
++countIO;
puts("Warning: an I/O instruction was not simulated.");
}
else if ( v6 == 7 )
{
++count7;
++countClock;
if ( (v5 & 0x100) != 0 )
{
if ( (v5 & 1) != 0 )
puts("Warning: Group 3 instructions not supported");
else
group2If(v5, 7, 1, 0);
}
else
{
group1If(v5, 7, 0);
}
}
else
{
printf("Warning: Opcode %d is greater than 7\n", (unsigned int)dword_404124);
}
if ( *(&group2 + 12) != 1 )
{
fprintf(ofp, "%d %o\n", (unsigned int)trace, (unsigned int)dword_404094);
fflush(ofp);
}
}
fclose(ofp);
puts("\n_______________ OUTPUT ____________________");
printf("\nTotal clock cycles: %d\n", (unsigned int)countClock);
printf("Total instructions: %d\n", (unsigned int)countInstr);
printf(
"Counts: AND, TAD, ISZ, DCA, JMS, JMP, IO, Micro\n\n %-4d %-4d %-4d %-4d %-4d %-4d %-3d %-6d\n\n",
(unsigned int)countAND,
(unsigned int)countTAD,
(unsigned int)countISZ,
(unsigned int)countDCA,
(unsigned int)countJMS,
(unsigned int)countJMP,
(unsigned int)countIO,
(unsigned int)count7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
int v4; // ecx
int v5; // edi
int v6; // eax

memory[0] = 0;
func13(argc, argv, envp);
func7(regIR);
while ( *(&group2 + 12) != 1 )
{
ofp = fopen("tracefile.din", "a");
++countInstr;
v5 = memory[128 * (__int64)dword_404144 + dword_404148];
v6 = v5 >> 9;
if ( v5 <= 3071 )
{
func11(v5);
func14();
switch ( dword_404124 )
{
case 0:
++countAND;
countClock += 2;
dword_40413C &= memory[128 * (__int64)dword_40410C + dword_404110];
func7(regPC + 1);
trace = 0;
dword_404094 = regCPMA;
break;
case 1:
++countTAD;
countClock += 2;
dword_40413C -= memory[128 * (__int64)dword_40410C + dword_404110];
func7(regPC + 1);
trace = 0;
dword_404094 = regCPMA;
break;
case 2:
countClock += 2;
++countISZ;
v3 = dword_404110 + ((__int64)dword_40410C << 7);
v4 = memory[v3];
memory[v3] = v4 + 1;
if ( v4 == -1 )
func7(++regPC);
trace = 1;
dword_404094 = regCPMA;
break;
case 3:
countClock += 2;
++countDCA;
memory[128 * (__int64)dword_40410C + dword_404110] = dword_40413C;
dword_40413C = 0;
regAC = 0;
func7(regPC + 1);
trace = 1;
dword_404094 = regCPMA;
break;
case 4:
countClock += 2;
++countJMS;
func10(regPC);
regPC = regCPMA + 1;
func7(regCPMA + 1);
trace = 1;
dword_404094 = regCPMA;
break;
case 5:
++countJMP;
++countClock;
regPC = regCPMA;
func7(regCPMA);
trace = 2;
dword_404094 = regCPMA;
break;
default:
break;
}
}
else if ( v6 == 6 )
{
++countIO;
puts("Warning: an I/O instruction was not simulated.");
}
else if ( v6 == 7 )
{
++count7;
++countClock;
if ( (v5 & 0x100) != 0 )
{
if ( (v5 & 1) != 0 )
puts("Warning: Group 3 instructions not supported");
else
func9(v5, 7, 1, 0);
}
else
{
func8(v5, 7, 0);
}
}
else
{
printf("Warning: Opcode %d is greater than 7\n", (unsigned int)dword_404124);
}
if ( *(&group2 + 12) != 1 )
{
fprintf(ofp, "%d %o\n", (unsigned int)trace, (unsigned int)dword_404094);
fflush(ofp);
}
}
fclose(ofp);
puts("\n_______________ OUTPUT ____________________");
printf("\nTotal clock cycles: %d\n", (unsigned int)countClock);
printf("Total instructions: %d\n", (unsigned int)countInstr);
printf(
"Counts: AND, TAD, ISZ, DCA, JMS, JMP, IO, Micro\n\n %-4d %-4d %-4d %-4d %-4d %-4d %-3d %-6d\n\n",
(unsigned int)countAND,
(unsigned int)countTAD,
(unsigned int)countISZ,
(unsigned int)countDCA,
(unsigned int)countJMS,
(unsigned int)countJMP,
(unsigned int)countIO,
(unsigned int)count7);
return 0;
}

original_code:
int main()
{
  memset(memory, 0, sizeof(int));
  loadAllTheThings();
  int i;
  updatePC(regIR.addr);
  int carryout;
  int c;
  int opcode;
  while (group2.hlt != 1)
  {
      ofp = fopen("tracefile.din", "a");
      countInstr++;
      i = memory[regPC.page][regPC.offset];
      opcode = i >> 9;
      if (opcode < 6)
      {
        handleIR(i);
        getEffAddr();
        switch (regIR.opcode)
        {
          case 0:
            countAND++;
            countClock = countClock + 2;
            regAC.addr = regAC.addr & memory[regCPMA.page][regCPMA.offset];
            updatePC(regPC.addr + 1);
            trace.n = 0;
            trace.addr = regCPMA.addr;
            break;
          case 1:
            countTAD++;
            countClock = countClock + 2;
            regAC.addr = regAC.addr + -memory[regCPMA.page][regCPMA.offset];
            if (carryout)
               regAC.link = -regAC.link;
            updatePC(regPC.addr + 1);
            trace.n = 0;
            trace.addr = regCPMA.addr;
            break;
          case 2:
            countClock = countClock + 2;
            countISZ++;
            memory[regCPMA.page][regCPMA.offset] = memory[regCPMA.page][regCPMA.offset] + 1;
            if (memory[regCPMA.page][regCPMA.offset] == 0)
            {
               regPC.addr = regPC.addr + 1;
               updatePC(regPC.addr);
            }
            regPC.addr = regPC.addr;
            trace.n = 1;
            trace.addr = regCPMA.addr;
            break;
          case 3:
            countClock = countClock + 2;
            countDCA++;
            memory[regCPMA.page][regCPMA.offset] = regAC.addr;
            regAC.addr = 0;
            regAC.link = 0;
            updatePC(regPC.addr + 1);
            trace.n = 1;
            trace.addr = regCPMA.addr;
            break;
          case 4:
            countClock = countClock + 2;
            countJMS++;
            updateCPMA(regPC.addr);
            regPC.addr = regCPMA.addr + 1;
            updatePC(regPC.addr);
            trace.n = 1;
            trace.addr = regCPMA.addr;
            break;
          case 5:
            countJMP++;
            countClock++;
            regPC.addr = regCPMA.addr;
            updatePC(regPC.addr);
            trace.n = 2;
            trace.addr = regCPMA.addr;
            break;
        }
      }
      else if (opcode == 6)
      {
         countIO++;
         printf("Warning: an I/O instruction was not simulated.\n");
      }
      else if (opcode == 7)
      {
         count7++;
         countClock++;
         int bit11;
         int groupbit;
         groupbit = (i >> 8) & 1;
         bit11 = i & 1;
         if (groupbit == 0)
            group1If(i, opcode, groupbit);
         else if (groupbit == 1 && bit11 == 0)
            group2If(i, opcode, groupbit, bit11);
         else
           printf("Warning: Group 3 instructions not supported\n");
      }
      else if (opcode > 7)
         printf("Warning: Opcode %d is greater than 7\n",regIR.opcode);
      if (group2.hlt != 1)
      {
         fprintf(ofp,"%d %o\n",trace.n,trace.addr);
         fflush(ofp);
      }
  }
  fclose(ofp);
  printf("\n_______________ OUTPUT ____________________\n");
  printf("\nTotal clock cycles: %d\n",countClock);
  printf("Total instructions: %d\n",countInstr);
  printf("Counts: AND, TAD, ISZ, DCA, JMS, JMP, IO, Micro\n\n"
         "        %-4d %-4d %-4d %-4d %-4d %-4d %-3d %-6d\n\n",
         countAND,countTAD,countISZ,countDCA,countJMS,countJMP,countIO,count7);
  return 0;
}

variable_types: carryout int

variable_types: c int


displayMemory

decompiled_code:
int displayMemory()
{
unsigned int *v0; // rbp
unsigned int *v1; // rbx
int result; // eax

puts("Contents of the first pages of memory:");
v0 = (unsigned int *)&unk_404340;
do
{
v1 = v0 - 120;
do
printf("%x ", *v1++);
while ( v1 != v0 );
result = puts("\n");
v0 += 128;
}
while ( v0 != (unsigned int *)&unk_404940 );
return result;
}

canonical_decompiled_code:
int func15()
{
unsigned int *v0; // rbp
unsigned int *v1; // rbx
int result; // eax

puts("Contents of the first pages of memory:");
v0 = (unsigned int *)&unk_404340;
do
{
v1 = v0 - 120;
do
printf("%x ", *v1++);
while ( v1 != v0 );
result = puts("\n");
v0 += 128;
}
while ( v0 != (unsigned int *)&unk_404940 );
return result;
}

original_code:
void displayMemory()
{
  printf("Contents of the first pages of memory:\n");
  int p;
  int y;
  for (p = 0; p < 3; p++)
  {
    for (y = 0; y < 120; y++)
    {
      printf("%x ",memory[p][y]);
    }
    printf("\n\n");
  }
}

variable_types: p int


decompiled_code:
int displayGroup1()
{
return printf(
"grp1: op bit3 cla cll cma cml rar ral rot iac\n %-3d %-4d %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d\n",
(unsigned int)group1,
(unsigned int)dword_4040E4,
(unsigned int)dword_4040E8,
(unsigned int)dword_4040EC,
(unsigned int)dword_4040F0,
(unsigned int)dword_4040F4,
(unsigned int)dword_4040F8,
(unsigned int)dword_4040FC,
(unsigned int)dword_404100,
(unsigned int)dword_404104);
}

canonical_decompiled_code:
int func16()
{
return printf(
"grp1: op bit3 cla cll cma cml rar ral rot iac\n %-3d %-4d %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d\n",
(unsigned int)group1,
(unsigned int)dword_4040E4,
(unsigned int)dword_4040E8,
(unsigned int)dword_4040EC,
(unsigned int)dword_4040F0,
(unsigned int)dword_4040F4,
(unsigned int)dword_4040F8,
(unsigned int)dword_4040FC,
(unsigned int)dword_404100,
(unsigned int)dword_404104);
}

original_code:
void displayGroup1()
{
  printf("grp1: op bit3 cla cll cma cml rar ral rot iac\n"
         "      %-3d %-4d %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d\n",
         group1.opcode, group1.bit3, group1.cla, group1.cll,
         group1.cma, group1.cml, group1.rar, group1.ral,
         group1.rotate, group1.iac);
}


decompiled_code:
int displayGroup2()
{
return printf(
"grp2: op bit3 cla sma sza snl rev osr hlt bit11\n %-3d %-4d %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-5d\n",
(unsigned int)group2,
(unsigned int)dword_4040A4,
(unsigned int)dword_4040A8,
(unsigned int)dword_4040AC,
(unsigned int)dword_4040B8,
(unsigned int)dword_4040C0,
(unsigned int)dword_4040C4,
(unsigned int)dword_4040CC,
(unsigned int)dword_4040D0,
(unsigned int)dword_4040D4);
}

canonical_decompiled_code:
int func17()
{
return printf(
"grp2: op bit3 cla sma sza snl rev osr hlt bit11\n %-3d %-4d %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-5d\n",
(unsigned int)group2,
(unsigned int)dword_4040A4,
(unsigned int)dword_4040A8,
(unsigned int)dword_4040AC,
(unsigned int)dword_4040B8,
(unsigned int)dword_4040C0,
(unsigned int)dword_4040C4,
(unsigned int)dword_4040CC,
(unsigned int)dword_4040D0,
(unsigned int)dword_4040D4);
}

original_code:
void displayGroup2()
{
  printf("grp2: op bit3 cla sma sza snl rev osr hlt bit11\n"
         "      %-3d %-4d %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-5d\n",
         group2.opcode, group2.bit3, group2.cla, group2.sma,
         group2.sza, group2.snl, group2.rev, group2.osr,
         group2.hlt, group2.bit11);
}


checkTag

decompiled_code:
__int64 __fastcall checkTag(int a1, int a2)
{
__int64 *v2; // rax
unsigned int v3; // edx

v2 = &L2cache[32 * (__int64)a1];
v3 = 0;
while ( *((_DWORD *)v2 + 2) != a2 )
{
++v3;
v2 += 2;
if ( v3 == 6 )
return 16;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
__int64 *v2; // rax
unsigned int v3; // edx

v2 = &L2cache[32 * (__int64)a1];
v3 = 0;
while ( *((_DWORD *)v2 + 2) != a2 )
{
++v3;
v2 += 2;
if ( v3 == 6 )
return 16;
}
return v3;
}

original_code:
int checkTag(int index, int tag)
{
  int way;
  for (way = 0; way <= 5; way++)
  {
    if (L2cache[index][way].tag == tag)
       return way;
  }
  return 16;
}

variable_types: index int

variable_types: tag int

variable_types: way int


checkLRU

original_code:
int checkLRU(int index)
{
  int way;
  for (way = 0; way <= 5; way++)
  {
    if (L2cache[index][way].LRUbits == 0)
       return way;
  }
  return 16;
}


updateLRU

decompiled_code:
__int64 __fastcall updateLRU(int a1, int a2)
{
__int64 result; // rax
int i; // ecx
__int64 v4; // rdx
int v5; // eax

result = a2;
if ( HIDWORD(L2cache[32 * a1 + 2 * a2]) != 5 )
{
for ( i = 0; i != 6; ++i )
{
v4 = ((__int64)a1 << 8) + 4210848;
v5 = 0;
while ( *(_DWORD *)(v4 + 4) != i )
{
++v5;
v4 += 16LL;
if ( v5 == 6 )
goto LABEL_4;
}
HIDWORD(L2cache[32 * a1 + 2 * v5]) = i - 1;
LABEL_4:
;
}
result = 16 * (a2 + 16LL * a1);
*(_DWORD *)((char *)L2cache + result + 4) = 5;
}
return result;
}

original_code:
void updateLRU(int index, int ourway)
{
  if (L2cache[index][ourway].LRUbits == 5)
     return;
  else
  {
     int ourbits = L2cache[index][ourway].LRUbits;
     int testbits = ourbits++;
     int testway;
     for (testbits = 0; testbits <= 5; testbits++)
     {
         testway = 0;
         while (testway <= 5)
         {
            if (testbits == L2cache[index][testway].LRUbits)
               {
                  L2cache[index][testway].LRUbits--;
                  break;
               }
            else
               testway++;
  }
     }
     L2cache[index][ourway].LRUbits = 5;
  }
}

variable_types: ourway int

variable_types: ourbits int

variable_types: testbits int

variable_types: testway int


testIndex

decompiled_code:
__int64 __fastcall testIndex(int a1)
{
__int64 v1; // rdx
_DWORD *v2; // rax
_DWORD *v3; // rdx

v1 = (__int64)a1 << 8;
v2 = (_DWORD *)((char *)L2cache + v1);
v3 = (_DWORD *)(v1 + 4210944);
while ( *v2 == 3 )
{
v2 += 4;
if ( v2 == v3 )
return 1LL;
}
return 0LL;
}

original_code:
int testIndex(int index, int way)
{
   for (way = 0; way <= 5; way++)
   {
       if (L2cache[index][way].MESIbits != 3)
       {
          return 0;
       }
   }
   return 1;
}


cacheDisplay

original_code:
void cacheDisplay()
{
   int index;
   int way;
   ofp = fopen("display.txt", "a");
   for (index = 0; index <= 16482; index++)
   {
      if (testIndex(index,way) == 0)
       {
           fprintf(ofp,"INDEX: 0x%-8x\n",index);
           fflush(ofp);
           for (way = 0; way <= 5; way++)
          {
             fprintf(ofp,"WAY %-8d LRU: %-4d MESI: %-10d TAG: %-8d"
                          " ADDR: 0x%-8x\n",
                          way,
                          L2cache[index][way].LRUbits,
                          L2cache[index][way].MESIbits,
                          L2cache[index][way].tag,
                          L2cache[index][way].address);
             fflush(ofp);
          }
      }
   }
   fprintf(ofp,"---------------------------------------------------------------------\n");
   fflush(ofp);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er15
unsigned int v4; // er14
unsigned int v5; // er12
int v6; // eax
int v7; // ebp
int v8; // er13
int v9; // ebx
__int64 v10; // rax
int v11; // eax
int v12; // ebp
__int64 v13; // rbp
int v14; // eax
__int64 v15; // rcx
__int64 v16; // rdx
int v17; // eax
__int64 v18; // rdx
int v19; // eax
__int64 *v20; // rbp
unsigned int v22; // [rsp+8h] [rbp-50h]
int v23; // [rsp+Ch] [rbp-4Ch]
int v24; // [rsp+18h] [rbp-40h]
int v25; // [rsp+1Ch] [rbp-3Ch]

L2cache[0] = 0LL;
qword_4040A8[0] = 0LL;
setLRUbitsToWay();
ifp = (__int64)fopen("testfile.din", "r");
ofp = fopen("display.txt", "w");
v3 = 0;
v23 = 0;
v22 = 0;
v4 = 0;
v5 = 0;
LABEL_6:
while ( (unsigned int)__isoc99_fscanf() != -1 )
{
v8 = v24 >> 20;
v9 = (v24 >> 6) & 0x3FFF;
++v5;
switch ( v25 )
{
case 0:
case 2:
++v4;
v6 = checkTag(v9, v8);
v7 = v6;
if ( v6 > 5 )
{
++v3;
v7 = checkLRU(v9);
updateLRU(v9, v7);
v10 = 2 * (v7 + 16LL * v9);
LODWORD(qword_4040A8[v10]) = v8;
LODWORD(L2cache[v10]) = 1;
}
else if ( LODWORD(L2cache[32 * v9 + 2 * v6]) > 2 )
{
++v3;
updateLRU(v9, v6);
LODWORD(L2cache[32 * v9 + 2 * v7]) = 1;
}
else
{
++v23;
updateLRU(v9, v6);
}
HIDWORD(qword_4040A8[32 * v9 + 2 * v7]) = v24;
break;
case 1:
++v22;
v11 = checkTag(v9, v8);
v12 = v11;
if ( v11 > 5 )
{
++v3;
v12 = checkLRU(v9);
LODWORD(qword_4040A8[32 * v9 + 2 * v12]) = v8;
}
else if ( LODWORD(L2cache[32 * v9 + 2 * v11]) > 2 )
{
++v3;
}
else
{
++v23;
}
updateLRU(v9, v12);
v13 = 2 * (16LL * v9 + v12);
LODWORD(L2cache[v13]) = 0;
*(_DWORD *)(v13 * 8 + 4210860) = v24;
break;
case 3:
case 5:
v22 += v25 == 5;
v17 = checkTag(v9, v8);
if ( v17 > 5 )
{
++v3;
}
else if ( LODWORD(L2cache[32 * v9 + 2 * v17]) <= 2 )
{
++v23;
v18 = 2 * (v17 + 16LL * v9);
LODWORD(L2cache[v18]) = 3;
*(_DWORD *)(v18 * 8 + 4210860) = v24;
updateLRU(v9, v17);
}
else
{
++v3;
}
break;
case 4:
++v4;
v14 = checkTag(v9, v8);
if ( v14 <= 5 )
{
v15 = 16LL * v9;
v16 = 2 * (v15 + v14);
if ( LODWORD(L2cache[v16]) > 2 )
{
++v3;
}
else
{
++v23;
LODWORD(L2cache[v16]) = 2;
HIDWORD(qword_4040A8[2 * v15 + 2 * v14]) = v24;
}
}
break;
case 6:
++v4;
v19 = checkTag(v9, v8);
if ( v19 <= 5 )
{
if ( LODWORD(L2cache[32 * v9 + 2 * v19]) <= 2 )
{
++v23;
v20 = &L2cache[32 * v9 + 2 * v19];
*(_DWORD *)v20 = 3;
updateLRU(v9, v19);
*((_DWORD *)v20 + 3) = v24;
}
else
{
++v3;
}
}
break;
case 8:
fprintf(
ofp,
"Reference %d called for the cache to be reset. No ways are valid.\n"
"---------------------------------------------------------------------\n",
v5);
fflush(ofp);
setLRUbitsToWay();
break;
case 9:
fprintf(ofp, "Reference %d displayed only indices containing valid ways.\n", v5);
fflush(ofp);
cacheDisplay();
break;
default:
goto LABEL_6;
}
}
printf(
" Total References: %d\n"
" Reads: %d\n"
" Writes: %d\n"
" Hits: %d\n"
" Misses %d\n"
" Hit ratio: %f\n"
"---------------------------------------------------------------------\n",
v5,
v4,
v22,
(unsigned int)v23,
v3,
(float)((float)v23 / (float)(int)v5));
fflush(ofp);
return 0;
}

original_code:
int main()
{
  memset(L2cache, 0, sizeof (cacheLine));
  int refCount = 0;
  int readCount = 0;
  int writeCount = 0;
  int hitCount = 0;
  int missCount = 0;
  int hitM = 0;
  int hit = 0;
  int way;
  int n;
  int addr;
  setLRUbitsToWay();
  ifp = fopen("testfile.din", "r");
  ofp = fopen("display.txt", "w");
  while (fscanf(ifp, "%d %x\n", &n, &addr) != (-1))
  {
    int tag = addr >> 20;
    int index = (addr >> 6) & 16383;
    refCount++;
    switch (n)
    {
      case 0:
      case 2:
 readCount++;
        way = checkTag(index, tag);
 if (way <= 5)
 {
    int MESI = L2cache[index][way].MESIbits;
    if (MESI == 0 || MESI == 1 || MESI == 2)
    {
       hitCount++;
       updateLRU(index, way);
      }
    else
           {
       missCount++;
              updateLRU(index, way);
       L2cache[index][way].MESIbits = 1;
    }
 }
        else
   {
    missCount++;
    way = checkLRU(index);
           updateLRU(index, way);
           L2cache[index][way].tag = tag;
    L2cache[index][way].MESIbits = 1;
        }
        L2cache[index][way].address = addr;
 break;
      case 1:
 writeCount++;
        way = checkTag(index, tag);
 if (way <= 5)
 {
    int MESI = L2cache[index][way].MESIbits;
    if (MESI == 0 || MESI == 1 || MESI == 2)
       hitCount++;
           else
              missCount++;
        }
        else
   {
    missCount++;
    way = checkLRU(index);
           L2cache[index][way].tag = tag;
        }
        updateLRU(index, way);
        L2cache[index][way].MESIbits = 0;
        L2cache[index][way].address = addr;
      break;
      case 4:
 readCount++;
        way = checkTag(index, tag);
 if (way <= 5)
 {
    int MESI = L2cache[index][way].MESIbits;
    if (MESI == 0 || MESI == 1 || MESI == 2)
    {
       hitCount++;
              if (MESI == 0)
                 hitM++;
              else
                 hit++;
       L2cache[index][way].MESIbits = 2;
              L2cache[index][way].address = addr;
           }
           else
              missCount++;
        }
      break;
      case 3:
      case 5:
        if (n == 5)
           writeCount++;
        way = checkTag(index, tag);
 if (way <= 5)
 {
    int MESI = L2cache[index][way].MESIbits;
    if (MESI == 0 || MESI == 1 || MESI == 2)
              {
                 hitCount++;
          L2cache[index][way].MESIbits = 3;
                 L2cache[index][way].address = addr;
                 updateLRU(index, way);
              }
    else
              missCount++;
        }
        else
           missCount++;
      break;
      case 6:
 readCount++;
        way = checkTag(index, tag);
 if (way <= 5)
 {
    int MESI = L2cache[index][way].MESIbits;
    if (MESI == 0 || MESI == 1 || MESI == 2)
           {
              hitCount++;
              if (MESI == 0)
                 hitM++;
              L2cache[index][way].MESIbits = 3;
              updateLRU(index, way);
              L2cache[index][way].address = addr;
           }
           else
              missCount++;
       }
      break;
      case 8:
        fprintf(ofp,"Reference %d called for the cache to be reset. No ways are valid.\n"
                    "---------------------------------------------------------------------\n",
                    refCount);
        fflush(ofp);
        setLRUbitsToWay();
      break;
      case 9:
        fprintf(ofp,"Reference %d displayed only indices containing valid ways.\n",refCount);
        fflush(ofp);
        cacheDisplay();
        break;
    }
  }
  float hitRatio = (float) hitCount / refCount;
  printf(" Total References: %d\n Reads: %d\n Writes: %d\n Hits: %d\n"
         " Misses %d\n Hit ratio: %f\n"
         "---------------------------------------------------------------------\n",
         refCount,readCount,writeCount,hitCount,missCount,hitRatio);
  fflush(ofp);
  return 0;
}

variable_types: refCount int

variable_types: readCount int

variable_types: writeCount int

variable_types: hitCount int

variable_types: missCount int

variable_types: hitM int

variable_types: hit int

variable_types: n int

variable_types: addr int

variable_types: MESI int

variable_types: hitRatio float


help

decompiled_code:
void __noreturn help()
{
puts("Usage:udp_scan\tdest\t[-s start_port]");
puts("\t\t\t[-e end_port]");
puts("\t\t\t[-i interval]");
puts("\t\t\t[-a attempts]");
puts("\t\t\t[-p payload]");
puts("\t\t\t[-w time_to_exit]");
puts("\t\t\t[-h help]");
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("Usage:udp_scan\tdest\t[-s start_port]");
puts("\t\t\t[-e end_port]");
puts("\t\t\t[-i interval]");
puts("\t\t\t[-a attempts]");
puts("\t\t\t[-p payload]");
puts("\t\t\t[-w time_to_exit]");
puts("\t\t\t[-h help]");
exit(0);
}

original_code:
static void help(void)
{
 printf("Usage:udp_scan\tdest\t[-s start_port]\n");
 printf("\t\t\t[-e end_port]\n");
 printf("\t\t\t[-i interval]\n");
 printf("\t\t\t[-a attempts]\n");
 printf("\t\t\t[-p payload]\n");
 printf("\t\t\t[-w time_to_exit]\n");
 printf("\t\t\t[-h help]\n");
 exit(0);
}

canonical_original_code:
static void help()
{
 printf("Usage:udp_scan\tdest\t[-s start_port]\n");
 printf("\t\t\t[-e end_port]\n");
 printf("\t\t\t[-i interval]\n");
 printf("\t\t\t[-a attempts]\n");
 printf("\t\t\t[-p payload]\n");
 printf("\t\t\t[-w time_to_exit]\n");
 printf("\t\t\t[-h help]\n");
 exit(0);
}


alarmHanlder

decompiled_code:
unsigned int alarmHanlder()
{
return alarm(1u);
}

canonical_decompiled_code:
unsigned int func1()
{
return alarm(1u);
}

original_code:
static void alarmHanlder(int signo)
{
 alarm(1);
}

variable_types: signo int


sender

decompiled_code:
void __fastcall sender(unsigned __int16 *a1)
{
unsigned __int16 v1; // r13
int v2; // er12
int v3; // er14
unsigned __int16 v4; // bx
__int16 v5; // bx
unsigned int v6; // [rsp+0h] [rbp-510h]
unsigned __int16 v7; // [rsp+6h] [rbp-50Ah]
socklen_t addr_len; // [rsp+14h] [rbp-4FCh] BYREF
struct sockaddr v9; // [rsp+18h] [rbp-4F8h] BYREF
char buf[1024]; // [rsp+28h] [rbp-4E8h] BYREF
struct sigaction v11; // [rsp+428h] [rbp-E8h] BYREF
struct sockaddr addr; // [rsp+4C8h] [rbp-48h] BYREF

if ( a1 )
{
v7 = *a1;
v1 = a1[1];
v2 = socket(2, 2, 17);
if ( v2 < 0 )
{
perror("socket(AF_INET,SOCK_DGRAM,0) error");
exit(-1);
}
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_QWORD *)&addr.sa_data[2] = *((unsigned int *)a1 + 65);
v3 = strlen((const char *)a1 + 264);
setbuf(stdout, 0LL);
if ( *((_DWORD *)a1 + 99) )
{
v6 = 1;
do
{
printf("sending UDP packets(%d)", v6);
if ( v7 <= v1 )
{
v4 = v7;
do
{
*(_WORD *)addr.sa_data = _bswap_16(v4);
if ( sendto(v2, a1 + 132, v3, 0, &addr, 0x10u) < 0 )
{
perror("sendto error");
exit(-1);
}
usleep(*((_DWORD *)a1 + 98));
putchar(46);
++v4;
}
while ( v1 >= v4 );
}
printf("\ncomplete sending(%d)\n", v6);
if ( *((_DWORD *)a1 + 99) == v6 )
break;
v5 = 20;
do
{
putchar(46);
usleep(0x186A0u);
--v5;
}
while ( v5 );
putchar(10);
++v6;
}
while ( *((_DWORD *)a1 + 99) >= v6 );
}
puts("+++++++++++++++++++++++++++++\nall packets are sent!");
printf("wait %d seconds to exit!\n", *((unsigned int *)a1 + 102));
v11.sa_handler = (__sighandler_t)alarmHanlder;
sigemptyset(&v11.sa_mask);
v11.sa_flags = 0x20000000;
sigaction(14, &v11, 0LL);
alarm(*((_DWORD *)a1 + 102));
while ( recvfrom(v2, buf, 0x400uLL, 0, &v9, &addr_len) > 0 )
{
if ( *(_DWORD *)&v9.sa_data[2] == *(_DWORD *)&addr.sa_data[2] )
*(_BYTE *)(*((_QWORD *)a1 + 50) + (unsigned __int16)_bswap_16(*(__int16 *)v9.sa_data) - *a1) = 2;
}
close(v2);
}
}

canonical_decompiled_code:
void __fastcall func3(unsigned __int16 *a1)
{
unsigned __int16 v1; // r13
int v2; // er12
int v3; // er14
unsigned __int16 v4; // bx
__int16 v5; // bx
unsigned int v6; // [rsp+0h] [rbp-510h]
unsigned __int16 v7; // [rsp+6h] [rbp-50Ah]
socklen_t addr_len; // [rsp+14h] [rbp-4FCh] BYREF
struct sockaddr v9; // [rsp+18h] [rbp-4F8h] BYREF
char buf[1024]; // [rsp+28h] [rbp-4E8h] BYREF
struct sigaction v11; // [rsp+428h] [rbp-E8h] BYREF
struct sockaddr addr; // [rsp+4C8h] [rbp-48h] BYREF

if ( a1 )
{
v7 = *a1;
v1 = a1[1];
v2 = socket(2, 2, 17);
if ( v2 < 0 )
{
perror("socket(AF_INET,SOCK_DGRAM,0) error");
exit(-1);
}
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_QWORD *)&addr.sa_data[2] = *((unsigned int *)a1 + 65);
v3 = strlen((const char *)a1 + 264);
setbuf(stdout, 0LL);
if ( *((_DWORD *)a1 + 99) )
{
v6 = 1;
do
{
printf("sending UDP packets(%d)", v6);
if ( v7 <= v1 )
{
v4 = v7;
do
{
*(_WORD *)addr.sa_data = func2(v4);
if ( sendto(v2, a1 + 132, v3, 0, &addr, 0x10u) < 0 )
{
perror("sendto error");
exit(-1);
}
usleep(*((_DWORD *)a1 + 98));
putchar(46);
++v4;
}
while ( v1 >= v4 );
}
printf("\ncomplete sending(%d)\n", v6);
if ( *((_DWORD *)a1 + 99) == v6 )
break;
v5 = 20;
do
{
putchar(46);
usleep(0x186A0u);
--v5;
}
while ( v5 );
putchar(10);
++v6;
}
while ( *((_DWORD *)a1 + 99) >= v6 );
}
puts("+++++++++++++++++++++++++++++\nall packets are sent!");
printf("wait %d seconds to exit!\n", *((unsigned int *)a1 + 102));
v11.sa_handler = (__sighandler_t)alarmHanlder;
sigemptyset(&v11.sa_mask);
v11.sa_flags = 0x20000000;
sigaction(14, &v11, 0LL);
alarm(*((_DWORD *)a1 + 102));
while ( recvfrom(v2, buf, 0x400uLL, 0, &v9, &addr_len) > 0 )
{
if ( *(_DWORD *)&v9.sa_data[2] == *(_DWORD *)&addr.sa_data[2] )
*(_BYTE *)(*((_QWORD *)a1 + 50) + (unsigned __int16)func2(*(__int16 *)v9.sa_data) - *a1) = 2;
}
close(v2);
}
}

original_code:
void sender(struct scaninfo *arg)
{
 if (arg == ((void *)0))
  return;
 int sockfd;
 unsigned short i, start, end;
 int len, total;
 struct sockaddr_in servaddr;
 struct scaninfo *info = (struct scaninfo *) arg;
 start = info->start;
 end = info->end;
 if ((sockfd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
  perror("socket(AF_INET,SOCK_DGRAM,0) error");
  exit(-1);
 }
 memset(&servaddr, 0, sizeof(servaddr));
 servaddr.sin_family = 2;
 memcpy(&servaddr.sin_addr, &info->addr, sizeof(servaddr.sin_addr));
 len = strlen(info->data);
 setbuf(stdout, ((void *)0));
 for (total = 1; total <= info->attempts; total++) {
  printf("sending UDP packets(%d)", total);
  for (i = start; i <= end; i++) {
   servaddr.sin_port = htons(i);
   if (sendto(sockfd, info->data, len, 0,
        (struct sockaddr *) &servaddr,
        sizeof(servaddr)) < 0) {
    perror("sendto error");
    exit(-1);
   }
   usleep(info->interval);
   printf(".");
  }
  printf("\ncomplete sending(%d)\n", total);
  if (total == info->attempts)
   break;
  for (i = 1; i <= 20; i++) {
   printf(".");
   usleep(100000);
  }
  printf("\n");
 }
 printf("+++++++++++++++++++++++++++++\nall packets are sent!\n");
 printf("wait %d seconds to exit!\n", info->wait);
 struct sigaction act;
 act.__sigaction_handler.sa_handler = alarmHanlder;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0x20000000;
 sigaction(14, &act, ((void *)0));
 alarm(info->wait);
 char buf[1024];
 struct sockaddr_in recvaddr;
 socklen_t recvlen;
 ssize_t n;
 while ((n = recvfrom(sockfd, buf, 1024, 0,
       (struct sockaddr *) &recvaddr, &recvlen)) > 0) {
  if (recvaddr.sin_addr.s_addr == servaddr.sin_addr.s_addr) {
   unsigned short port = ntohs(recvaddr.sin_port);
   info->status[port - info->start] = 2;
  }
 }
 close(sockfd);
 return;
}

canonical_original_code:
void sender(struct scaninfo *arg)
{
 if (arg == ((void *)0))
  return;
 int sockfd;
 unsigned short i; unsigned short start; unsigned short end;
 int len; int total;
 struct sockaddr_in servaddr;
 struct scaninfo *info = (struct scaninfo *) arg;
 start = info->start;
 end = info->end;
 if ((sockfd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
  perror("socket(AF_INET,SOCK_DGRAM,0) error");
  exit(-1);
 }
 memset(&servaddr, 0, sizeof(servaddr));
 servaddr.sin_family = 2;
 memcpy(&servaddr.sin_addr, &info->addr, sizeof(servaddr.sin_addr));
 len = strlen(info->data);
 setbuf(stdout, ((void *)0));
 for (total = 1; total <= info->attempts; total++) {
  printf("sending UDP packets(%d)", total);
  for (i = start; i <= end; i++) {
   servaddr.sin_port = htons(i);
   if (sendto(sockfd, info->data, len, 0,
        (struct sockaddr *) &servaddr,
        sizeof(servaddr)) < 0) {
    perror("sendto error");
    exit(-1);
   }
   usleep(info->interval);
   printf(".");
  }
  printf("\ncomplete sending(%d)\n", total);
  if (total == info->attempts)
   break;
  for (i = 1; i <= 20; i++) {
   printf(".");
   usleep(100000);
  }
  printf("\n");
 }
 printf("+++++++++++++++++++++++++++++\nall packets are sent!\n");
 printf("wait %d seconds to exit!\n", info->wait);
 struct sigaction act;
 act.__sigaction_handler.sa_handler = alarmHanlder;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0x20000000;
 sigaction(14, &act, ((void *)0));
 alarm(info->wait);
 char buf[1024];
 struct sockaddr_in recvaddr;
 unsigned int recvlen;
 long n;
 while ((n = recvfrom(sockfd, buf, 1024, 0,
       (struct sockaddr *) &recvaddr, &recvlen)) > 0) {
  if (recvaddr.sin_addr.s_addr == servaddr.sin_addr.s_addr) {
   unsigned short port = ntohs(recvaddr.sin_port);
   info->status[port - info->start] = 2;
  }
 }
 close(sockfd);
 return;
}

variable_types: struct scaninfo { unsigned short start; unsigned short end; char hostname[256]; struct in_addr { unsigned int s_addr; } addr; char data[128]; unsigned int interval; unsigned int attempts; unsigned char *status; unsigned int wait; } *

variable_types: sockfd int

variable_types:
i
unsigned short

variable_types:
start
unsigned short

variable_types:
end
unsigned short

variable_types: len int

variable_types: total int

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

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types:
buf
char [1024]

variable_types:
recvlen
unsigned int

variable_types: n long

variable_types:
port
unsigned short

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct scaninfo { unsigned short start; unsigned short end; char hostname[256]; struct in_addr addr; char data[128]; unsigned int interval; unsigned int attempts; unsigned char *status; unsigned int wait; }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


receiver

original_code:
void *receiver(void *arg)
{
 int sockfd;
 struct scaninfo *sip;
 struct sockaddr_in raddr;
 socklen_t len;
 char buf[4096];
 struct iphdr *ip;
 unsigned int iplen;
 struct icmphdr *icmp;
 struct udphdr *udp;
 char straddr[256];
 unsigned short start, end, total;
 unsigned short port;
 sip = (struct scaninfo *) arg;
 if (sip == ((void *)0))
  return ((void *)0);
 start = sip->start;
 end = sip->end;
 total = end - start + 1;
 if ((sockfd = socket(2, SOCK_RAW, IPPROTO_ICMP)) < 0) {
  perror("socket(AF_INET,SOCK_RAW,IPPROTO_ICMP) error");
  exit(-1);
 }
 setuid(getuid());
 memset(&raddr, 0, sizeof(raddr));
 len = sizeof(raddr);
 raddr.sin_family = 2;
 memcpy(&raddr.sin_addr, &sip->addr, sizeof(raddr.sin_addr));
 if (connect(sockfd, (struct sockaddr *) &raddr, len) < 0) {
  perror("connect error");
  exit(-1);
 }
 while (recv(sockfd, buf, 4096, 0) > 0) {
  ip = (struct iphdr *) buf;
  if (inet_ntop(2, &ip->saddr, straddr, 256) != 1)
   strncpy(straddr, "unknown", 256);
  if (ip->protocol == IPPROTO_ICMP) {
   iplen = ip->ihl << 2;
   icmp = (struct icmphdr *) (buf + iplen);
   if (icmp->type != 3 || icmp->code != 3) {
    printf
     ("an unexpected packet from %s, type = %d, code = %d\n",
      straddr, icmp->type, icmp->code);
    continue;
   }
   ip = (struct iphdr *) (buf + iplen + 8);
   iplen = ip->ihl << 2;
   udp = (struct udphdr *) ((char *) ip + iplen);
   port = ntohs(udp->dest);
   if (port < start || port > end) {
    printf("an unexpected packet from %s, udp port = %d\n",
        straddr, port);
    continue;
   }
   sip->status[port - start] = 1;
  }
 }
 close(sockfd);
 return ((void *)0);
}

canonical_original_code:
void *receiver(void *arg)
{
 int sockfd;
 struct scaninfo *sip;
 struct sockaddr_in raddr;
 unsigned int len;
 char buf[4096];
 struct iphdr *ip;
 unsigned int iplen;
 struct icmphdr *icmp;
 struct udphdr *udp;
 char straddr[256];
 unsigned short start; unsigned short end; unsigned short total;
 unsigned short port;
 sip = (struct scaninfo *) arg;
 if (sip == ((void *)0))
  return ((void *)0);
 start = sip->start;
 end = sip->end;
 total = end - start + 1;
 if ((sockfd = socket(2, SOCK_RAW, IPPROTO_ICMP)) < 0) {
  perror("socket(AF_INET,SOCK_RAW,IPPROTO_ICMP) error");
  exit(-1);
 }
 setuid(getuid());
 memset(&raddr, 0, sizeof(raddr));
 len = sizeof(raddr);
 raddr.sin_family = 2;
 memcpy(&raddr.sin_addr, &sip->addr, sizeof(raddr.sin_addr));
 if (connect(sockfd, (struct sockaddr *) &raddr, len) < 0) {
  perror("connect error");
  exit(-1);
 }
 while (recv(sockfd, buf, 4096, 0) > 0) {
  ip = (struct iphdr *) buf;
  if (inet_ntop(2, &ip->saddr, straddr, 256) != 1)
   strncpy(straddr, "unknown", 256);
  if (ip->protocol == IPPROTO_ICMP) {
   iplen = ip->ihl << 2;
   icmp = (struct icmphdr *) (buf + iplen);
   if (icmp->type != 3 || icmp->code != 3) {
    printf
     ("an unexpected packet from %s, type = %d, code = %d\n",
      straddr, icmp->type, icmp->code);
    continue;
   }
   ip = (struct iphdr *) (buf + iplen + 8);
   iplen = ip->ihl << 2;
   udp = (struct udphdr *) ((char *) ip + iplen);
   port = ntohs(udp->dest);
   if (port < start || port > end) {
    printf("an unexpected packet from %s, udp port = %d\n",
        straddr, port);
    continue;
   }
   sip->status[port - start] = 1;
  }
 }
 close(sockfd);
 return ((void *)0);
}

variable_types:
arg
void *

variable_types:
len
unsigned int

variable_types:
buf
char [4096]

variable_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *

variable_types:
iplen
unsigned int

variable_types: struct icmphdr { unsigned char type; unsigned char code; unsigned short checksum; union { struct { unsigned short id; unsigned short sequence; } echo; unsigned int gateway; struct { unsigned short __glibc_reserved; unsigned short mtu; } frag; } un; } *

variable_types: struct udphdr { union { struct { unsigned short uh_sport; unsigned short uh_dport; unsigned short uh_ulen; unsigned short uh_sum; }; struct { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; }; }; } *

variable_types:
straddr
char [256]

variable_types:
total
unsigned short

return_type: void *


original_code:
void parse_scanpara(int argc, char *argv[], struct scaninfo *info)
{
 if (info == ((void *)0))
  return;
 memset(info, 0, sizeof(struct scaninfo));
 info->attempts = 1;
 info->interval = 500000;
 strncpy(info->data, "hello world!", 128);
 int opt;
 struct option longopts[] = {
  {"help", 0, ((void *)0), 'h'},
  {"start-port", 1, ((void *)0), 's'},
  {"end-port", 1, ((void *)0), 'e'},
  {"interval", 1, ((void *)0), 'i'},
  {"attempts", 1, ((void *)0), 'a'},
  {"payload", 1, ((void *)0), 'p'},
  {"wait", 1, ((void *)0), 'w'},
  {0, 0, 0, 0}
 };
 while ((opt =
   getopt_long(argc, argv, "hs:e:i:a:p:w:", longopts,
      ((void *)0))) != -1) {
  switch (opt) {
  case 'h':
   help();
   break;
  case 's':
   info->start = atoi(optarg);
   break;
  case 'e':
   info->end = atoi(optarg);
   break;
  case 'i':
   info->interval = atoi(optarg) * 1000;
   break;
  case 'a':
   info->attempts = atoi(optarg);
   break;
  case 'p':
   strncpy(info->data, optarg, 128);
   break;
  case 'w':
   info->wait = atoi(optarg);
   break;
  default:
   help();
   break;
  }
 }
 if (optind != argc - 1)
  help();
 if (info->start == 0 || info->end == 0 || info->end < info->start
  || info->attempts <= 0) {
  fprintf(stderr, "Invalid port number or attempts\n");
  exit(-1);
 }
 if (info->wait == 0) {
  info->wait =
   info->interval / 1000000.0 * (info->end - info->start + 1);
  if (info->wait == 0) {
   info->wait = 1;
  }
 }
 info->status =
  (unsigned char *) malloc((info->end - info->start + 1) *
         sizeof(unsigned char));
 if (info->status == ((void *)0)) {
  perror("malloc error");
  exit(-1);
 }
 memset(info->status, 0, info->end - info->start + 1);
 if (inet_pton(2, argv[optind], &info->addr) != 1) {
  struct hostent *hp;
  if ((hp = gethostbyname(argv[optind])) == ((void *)0)) {
   fprintf(stderr, "Invalid destination - %s\n", argv[optind]);
   exit(-1);
  }
  strncpy(info->hostname, argv[optind], 256);
  memcpy(&info->addr, hp->h_addr_list[0], sizeof(info->addr));
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct scaninfo { unsigned short start; unsigned short end; char hostname[256]; struct in_addr { unsigned int s_addr; } addr; char data[128]; unsigned int interval; unsigned int attempts; unsigned char *status; unsigned int wait; } *

variable_types: opt int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


decompiled_code:
void *__fastcall listen_in_port(void *a1)
{
int v1; // eax
int v2; // ebp
unsigned __int16 v3; // bx
char *v4; // rax
signed __int64 v5; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-10ACh] BYREF
struct sockaddr v8; // [rsp+10h] [rbp-10A8h] BYREF
char buf[4096]; // [rsp+90h] [rbp-1028h] BYREF
struct sockaddr addr; // [rsp+1090h] [rbp-28h] BYREF

v1 = socket(2, 2, 17);
if ( v1 < 0 )
{
perror("socket error");
exit(-1);
}
v2 = v1;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)addr.sa_data = _bswap_16((__int16)a1);
if ( bind(v2, &addr, 0x10u) < 0 )
{
perror("bind error");
exit(-1);
}
while ( 1 )
{
v5 = recvfrom(v2, buf, 0x1000uLL, 0, &v8, &addr_len);
if ( v5 <= 0 )
break;
buf[v5] = 0;
sendto(v2, buf, v5, 0, &v8, addr_len);
v3 = _bswap_16(*(__int16 *)v8.sa_data);
v4 = inet_ntoa(*(struct in_addr *)&v8.sa_data[2]);
printf("Receive from %s:%u\t%s\n", v4, v3, buf);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func9(void *a1)
{
int v1; // eax
int v2; // ebp
unsigned __int16 v3; // bx
char *v4; // rax
signed __int64 v5; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-10ACh] BYREF
struct sockaddr v8; // [rsp+10h] [rbp-10A8h] BYREF
char buf[4096]; // [rsp+90h] [rbp-1028h] BYREF
struct sockaddr addr; // [rsp+1090h] [rbp-28h] BYREF

v1 = socket(2, 2, 17);
if ( v1 < 0 )
{
perror("socket error");
exit(-1);
}
v2 = v1;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func7(0);
*(_WORD *)addr.sa_data = func8((__int16)a1);
if ( bind(v2, &addr, 0x10u) < 0 )
{
perror("bind error");
exit(-1);
}
while ( 1 )
{
v5 = recvfrom(v2, buf, 0x1000uLL, 0, &v8, &addr_len);
if ( v5 <= 0 )
break;
buf[v5] = 0;
sendto(v2, buf, v5, 0, &v8, addr_len);
v3 = func8(*(__int16 *)v8.sa_data);
v4 = inet_ntoa(*(struct in_addr *)&v8.sa_data[2]);
printf("Receive from %s:%u\t%s\n", v4, v3, buf);
}
return 0LL;
}

original_code:
static void *listen_in_port(void *arg)
{
 unsigned int port = (unsigned int) (long) arg;
 int sockfd;
 struct sockaddr_in servaddr;
 if ((sockfd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
  perror("socket error");
  exit(-1);
 }
 memset(&servaddr, 0, sizeof(servaddr));
 servaddr.sin_family = 2;
 servaddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 servaddr.sin_port = htons(port);
 if (bind(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
  perror("bind error");
  exit(-1);
 }
 char buf[4096];
 struct sockaddr_storage recvaddr;
 socklen_t addrlen;
 ssize_t n;
 while ((n =
   recvfrom(sockfd, buf, 4096, 0, (struct sockaddr *) &recvaddr,
      &addrlen)) > 0) {
  buf[n] = '\0';
  sendto(sockfd, buf, n, 0, (struct sockaddr *) &recvaddr, addrlen);
  printf("Receive from %s:%u\t%s\n",
      inet_ntoa(((struct sockaddr_in *) &recvaddr)->sin_addr),
      ntohs(((struct sockaddr_in *) &recvaddr)->sin_port), buf);
 }
 return ((void *)0);
}

canonical_original_code:
static void *listen_in_port(void *arg)
{
 unsigned int port = (unsigned int) (long) arg;
 int sockfd;
 struct sockaddr_in servaddr;
 if ((sockfd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
  perror("socket error");
  exit(-1);
 }
 memset(&servaddr, 0, sizeof(servaddr));
 servaddr.sin_family = 2;
 servaddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 servaddr.sin_port = htons(port);
 if (bind(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
  perror("bind error");
  exit(-1);
 }
 char buf[4096];
 struct sockaddr_storage recvaddr;
 unsigned int addrlen;
 long n;
 while ((n =
   recvfrom(sockfd, buf, 4096, 0, (struct sockaddr *) &recvaddr,
      &addrlen)) > 0) {
  buf[n] = '\0';
  sendto(sockfd, buf, n, 0, (struct sockaddr *) &recvaddr, addrlen);
  printf("Receive from %s:%u\t%s\n",
      inet_ntoa(((struct sockaddr_in *) &recvaddr)->sin_addr),
      ntohs(((struct sockaddr_in *) &recvaddr)->sin_port), buf);
 }
 return ((void *)0);
}

variable_types:
port
unsigned int

variable_types: sockfd int

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

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
addrlen
unsigned int

variable_types: n long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t v3; // rbx
pthread_t v4; // rbp
const char **v5; // rbx
unsigned int v6; // eax
pthread_t newthread[4]; // [rsp+0h] [rbp-20h] BYREF

if ( argc > 1 )
{
newthread[3] = v4;
newthread[2] = v3;
v5 = argv + 1;
while ( 1 )
{
v6 = atoi(*v5);
if ( v6 )
{
if ( pthread_create(newthread, 0LL, listen_in_port, (void *)v6) < 0 )
{
perror("pthread_create error");
exit(0);
}
if ( pthread_detach(newthread[0]) < 0 )
{
perror("pthread_detach error");
exit(0);
}
}
if ( ++v5 == &argv[(unsigned int)(argc - 2) + 2] )
{
while ( 1 )
;
}
}
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 unsigned int port = 0;
 int i;
 pthread_t tid;
 if (argc <= 1)
  return;
 for (i = 1; i < argc; i++) {
  port = atoi(argv[i]);
  if (port > 0) {
   if (pthread_create
    (&tid, ((void *)0), listen_in_port, (void *) (long) port) < 0) {
    perror("pthread_create error");
    exit(0);
   }
   if (pthread_detach(tid) < 0) {
    perror("pthread_detach error");
    exit(0);
   }
  }
 }
 while (1);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned int port = 0;
 int i;
 unsigned long tid;
 if (argc <= 1)
  return;
 for (i = 1; i < argc; i++) {
  port = atoi(argv[i]);
  if (port > 0) {
   if (pthread_create
    (&tid, ((void *)0), listen_in_port, (void *) (long) port) < 0) {
    perror("pthread_create error");
    exit(0);
   }
   if (pthread_detach(tid) < 0) {
    perror("pthread_detach error");
    exit(0);
   }
  }
 }
 while (1);
 return 0;
}

variable_types: i int

variable_types:
tid
unsigned long


decompiled_code:
int show_result()
{
unsigned __int16 v0; // bp
__int64 v1; // rbx
int v2; // er12
__int64 v3; // rbx
int v4; // er12
__int64 v5; // rbx
int v6; // er12

v0 = word_242 + 1 - info;
printf("\nopen port:\t");
if ( v0 )
{
v1 = 0LL;
v2 = 0;
do
{
if ( *(_BYTE *)(qword_3D0 + v1) == 2 )
{
++v2;
printf("%d ", (unsigned int)v1 + (unsigned __int16)info);
if ( (_WORD)v2 == 10 )
{
printf("\n\t\t");
v2 = 0;
}
}
++v1;
}
while ( v0 > (unsigned __int16)v1 );
printf("\nclosed port:\t");
v3 = 0LL;
v4 = 0;
do
{
if ( *(_BYTE *)(qword_3D0 + v3) == 1 )
{
++v4;
printf("%d ", (unsigned int)v3 + (unsigned __int16)info);
if ( (_WORD)v4 == 10 )
{
printf("\n\t\t");
v4 = 0;
}
}
++v3;
}
while ( v0 > (unsigned __int16)v3 );
printf("\nunknown port:\t");
v5 = 0LL;
v6 = 0;
do
{
if ( !*(_BYTE *)(qword_3D0 + v5) )
{
++v6;
printf("%d ", (unsigned int)v5 + (unsigned __int16)info);
if ( (_WORD)v6 == 10 )
{
printf("\n\t\t");
v6 = 0;
}
}
++v5;
}
while ( v0 > (unsigned __int16)v5 );
}
else
{
printf("\nclosed port:\t");
printf("\nunknown port:\t");
}
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
unsigned __int16 v0; // bp
__int64 v1; // rbx
int v2; // er12
__int64 v3; // rbx
int v4; // er12
__int64 v5; // rbx
int v6; // er12

v0 = word_242 + 1 - info;
printf("\nopen port:\t");
if ( v0 )
{
v1 = 0LL;
v2 = 0;
do
{
if ( *(_BYTE *)(qword_3D0 + v1) == 2 )
{
++v2;
printf("%d ", (unsigned int)v1 + (unsigned __int16)info);
if ( (_WORD)v2 == 10 )
{
printf("\n\t\t");
v2 = 0;
}
}
++v1;
}
while ( v0 > (unsigned __int16)v1 );
printf("\nclosed port:\t");
v3 = 0LL;
v4 = 0;
do
{
if ( *(_BYTE *)(qword_3D0 + v3) == 1 )
{
++v4;
printf("%d ", (unsigned int)v3 + (unsigned __int16)info);
if ( (_WORD)v4 == 10 )
{
printf("\n\t\t");
v4 = 0;
}
}
++v3;
}
while ( v0 > (unsigned __int16)v3 );
printf("\nunknown port:\t");
v5 = 0LL;
v6 = 0;
do
{
if ( !*(_BYTE *)(qword_3D0 + v5) )
{
++v6;
printf("%d ", (unsigned int)v5 + (unsigned __int16)info);
if ( (_WORD)v6 == 10 )
{
printf("\n\t\t");
v6 = 0;
}
}
++v5;
}
while ( v0 > (unsigned __int16)v5 );
}
else
{
printf("\nclosed port:\t");
printf("\nunknown port:\t");
}
return putchar(10);
}

original_code:
static void show_result(void)
{
 unsigned short total;
 unsigned short i, j;
 total = info.end - info.start + 1;
 printf("\nopen port:\t");
 for (i = 0, j = 0; i < total; i++) {
  if (info.status[i] == 2) {
   j++;
   printf("%d ", i + info.start);
   if (j == 10) {
    printf("\n\t\t");
    j = 0;
   }
  }
 }
 printf("\nclosed port:\t");
 for (i = 0, j = 0; i < total; i++) {
  if (info.status[i] == 1) {
   j++;
   printf("%d ", i + info.start);
   if (j == 10) {
    printf("\n\t\t");
    j = 0;
   }
  }
 }
 printf("\nunknown port:\t");
 for (i = 0, j = 0; i < total; i++) {
  if (info.status[i] == 0) {
   j++;
   printf("%d ", i + info.start);
   if (j == 10) {
    printf("\n\t\t");
    j = 0;
   }
  }
 }
 printf("\n");
}

canonical_original_code:
static void show_result()
{
 unsigned short total;
 unsigned short i; unsigned short j;
 total = info.end - info.start + 1;
 printf("\nopen port:\t");
 for (i = 0, j = 0; i < total; i++) {
  if (info.status[i] == 2) {
   j++;
   printf("%d ", i + info.start);
   if (j == 10) {
    printf("\n\t\t");
    j = 0;
   }
  }
 }
 printf("\nclosed port:\t");
 for (i = 0, j = 0; i < total; i++) {
  if (info.status[i] == 1) {
   j++;
   printf("%d ", i + info.start);
   if (j == 10) {
    printf("\n\t\t");
    j = 0;
   }
  }
 }
 printf("\nunknown port:\t");
 for (i = 0, j = 0; i < total; i++) {
  if (info.status[i] == 0) {
   j++;
   printf("%d ", i + info.start);
   if (j == 10) {
    printf("\n\t\t");
    j = 0;
   }
  }
 }
 printf("\n");
}

variable_types:
i
unsigned short

variable_types:
j
unsigned short


decompiled_code:
void __noreturn sig_int()
{
show_result();
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
func0();
exit(0);
}

original_code:
static void sig_int(int signo)
{
 show_result();
 exit(0);
}

variable_types: signo int