main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebp
unsigned int v6; // ebx
int v7; // eax
socklen_t len; // [rsp+Ch] [rbp-18Ch] BYREF
struct sockaddr cp; // [rsp+10h] [rbp-188h] BYREF
char buf[16]; // [rsp+20h] [rbp-178h] BYREF
struct sigaction v11; // [rsp+30h] [rbp-168h] BYREF
struct sigaction v12; // [rsp+D0h] [rbp-C8h] BYREF
struct rlimit rlimits; // [rsp+170h] [rbp-28h] BYREF

v3 = time(0LL);
srand(v3);
if ( getrlimit(RLIMIT_NOFILE, &rlimits) )
{
perror("Failed to get limit");
}
else
{
rlimits.rlim_cur = rlimits.rlim_max;
if ( setrlimit(RLIMIT_NOFILE, &rlimits) )
{
perror("Failed to set limit");
}
else
{
v4 = createListenFD(4912LL);
if ( v4 != -1 )
{
sigfillset(&v12.sa_mask);
v12.sa_handler = (__sighandler_t)main;
v12.sa_flags = 0;
if ( !sigaction(13, &v12, &v11) && v11.sa_handler != (__sighandler_t)main )
{
v12.sa_handler = (__sighandler_t)ignore;
sigaction(13, &v12, 0LL);
}
while ( 1 )
{
while ( 1 )
{
len = 16;
v6 = accept(v4, &cp, &len);
if ( v6 == -1 )
break;
inet_ntop(2, &cp, buf, len);
printf("Recieved connection from %s\n", buf);
beginSlavery(v6);
close(v6);
}
v7 = *_errno_location();
if ( v7 != 11 && v7 != 4 )
perror("Accept failed");
}
}
}
}
return -1;
}

original_code:
int main(int argc, char** argv)
{
    srand((int)time(((void *)0)));
    struct rlimit limit;
    if(getrlimit(RLIMIT_NOFILE, &limit))
    {
        perror("Failed to get limit");
        return -1;
    }
    limit.rlim_cur = limit.rlim_max;
    if(setrlimit(RLIMIT_NOFILE, &limit))
    {
        perror("Failed to set limit");
        return -1;
    }
    int listenFD = createListenFD(4912);
    if(listenFD == -1)
    {
        return -1;
    }
    struct sigaction new_sa;
    struct sigaction old_sa;
    sigfillset(&new_sa.sa_mask);
    new_sa.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
    new_sa.sa_flags = 0;
    if(sigaction(13, &new_sa, &old_sa) == 0 && old_sa.__sigaction_handler.sa_handler != ((__sighandler_t) 1))
    {
        new_sa.__sigaction_handler.sa_handler = ignore;
        sigaction(13, &new_sa, 0);
    }
    while(1)
    {
        struct sockaddr_in peerAddr;
        socklen_t len = sizeof(peerAddr);
        int newFD = accept(listenFD, (struct sockaddr*)&peerAddr, &len);
        if(newFD == -1)
        {
            if((*__errno_location ()) != 11 && (*__errno_location ()) != 11 && (*__errno_location ()) != 4)
            {
                perror("Accept failed");
            }
            continue;
        }
        char buf[16];
        inet_ntop(2, &peerAddr, buf, len);
        printf("Recieved connection from %s\n", buf);
        beginSlavery(newFD);
        close(newFD);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    srand((int)time(((void *)0)));
    struct rlimit limit;
    if(getrlimit(RLIMIT_NOFILE, &limit))
    {
        perror("Failed to get limit");
        return -1;
    }
    limit.rlim_cur = limit.rlim_max;
    if(setrlimit(RLIMIT_NOFILE, &limit))
    {
        perror("Failed to set limit");
        return -1;
    }
    int listenFD = createListenFD(4912);
    if(listenFD == -1)
    {
        return -1;
    }
    struct sigaction new_sa;
    struct sigaction old_sa;
    sigfillset(&new_sa.sa_mask);
    new_sa.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
    new_sa.sa_flags = 0;
    if(sigaction(13, &new_sa, &old_sa) == 0 && old_sa.__sigaction_handler.sa_handler != ((void (*)(int)) 1))
    {
        new_sa.__sigaction_handler.sa_handler = ignore;
        sigaction(13, &new_sa, 0);
    }
    while(1)
    {
        struct sockaddr_in peerAddr;
        unsigned int len = sizeof(peerAddr);
        int newFD = accept(listenFD, (struct sockaddr*)&peerAddr, &len);
        if(newFD == -1)
        {
            if((*__errno_location ()) != 11 && (*__errno_location ()) != 11 && (*__errno_location ()) != 4)
            {
                perror("Accept failed");
            }
            continue;
        }
        char buf[16];
        inet_ntop(2, &peerAddr, buf, len);
        printf("Recieved connection from %s\n", buf);
        beginSlavery(newFD);
        close(newFD);
    }
    return 0;
}

variable_types:
argv
char **

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }

variable_types: listenFD int

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: 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:
len
unsigned int

variable_types: newFD int

variable_types:
buf
char [16]

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 sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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; }


getIP

decompiled_code:
__int64 __fastcall getIP(char *buf, socklen_t len)
{
unsigned int v2; // ebx
socklen_t lena; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr cp; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF

v2 = socket(2, 2, 0);
if ( v2 == -1 )
{
perror("Socket failed");
}
else
{
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = inet_addr("8.8.8.8");
*(_WORD *)addr.sa_data = _bswap_16(53);
if ( connect(v2, &addr, 0x10u) == -1 )
{
perror("Connect failed");
v2 = -1;
}
else
{
lena = 16;
getsockname(v2, &cp, &lena);
if ( inet_ntop(2, &cp.sa_data[2], buf, len) )
{
close(v2);
v2 = 0;
}
else
{
fwrite("inet_ntop failed\n", 1uLL, 0x11uLL, stderr);
v2 = -1;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *buf, socklen_t len)
{
unsigned int v2; // ebx
socklen_t lena; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr cp; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF

v2 = socket(2, 2, 0);
if ( v2 == -1 )
{
perror("Socket failed");
}
else
{
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = inet_addr("8.8.8.8");
*(_WORD *)addr.sa_data = func0(53);
if ( connect(v2, &addr, 0x10u) == -1 )
{
perror("Connect failed");
v2 = -1;
}
else
{
lena = 16;
getsockname(v2, &cp, &lena);
if ( inet_ntop(2, &cp.sa_data[2], buf, len) )
{
close(v2);
v2 = 0;
}
else
{
fwrite("inet_ntop failed\n", 1uLL, 0x11uLL, stderr);
v2 = -1;
}
}
}
return v2;
}

original_code:
int getIP(char* buffer, size_t buflen)
{
    int sock = socket(2, SOCK_DGRAM, 0);
    if(sock == -1)
    {
        perror("Socket failed");
        return -1;
    }
    const char* kGoogleDnsIp = "8.8.8.8";
    uint16_t kDnsPort = 53;
    struct sockaddr_in serv;
    memset(&serv, 0, sizeof(serv));
    serv.sin_family = 2;
    serv.sin_addr.s_addr = inet_addr(kGoogleDnsIp);
    serv.sin_port = htons(kDnsPort);
    int err = connect(sock, (const struct sockaddr*) &serv, sizeof(serv));
    if(err == -1)
    {
        perror("Connect failed");
        return -1;
    }
    struct sockaddr_in name;
    socklen_t namelen = sizeof(name);
    err = getsockname(sock, (struct sockaddr*) &name, &namelen);
    if(!inet_ntop(2, &name.sin_addr, buffer, (int)buflen))
    {
        fprintf(stderr, "inet_ntop failed\n");
        return -1;
    }
    close(sock);
    return 0;
}

canonical_original_code:
int getIP(char *buffer, unsigned long buflen)
{
    int sock = socket(2, SOCK_DGRAM, 0);
    if(sock == -1)
    {
        perror("Socket failed");
        return -1;
    }
    char *kGoogleDnsIp = "8.8.8.8";
    unsigned short kDnsPort = 53;
    struct sockaddr_in serv;
    memset(&serv, 0, sizeof(serv));
    serv.sin_family = 2;
    serv.sin_addr.s_addr = inet_addr(kGoogleDnsIp);
    serv.sin_port = htons(kDnsPort);
    int err = connect(sock, (const struct sockaddr*) &serv, sizeof(serv));
    if(err == -1)
    {
        perror("Connect failed");
        return -1;
    }
    struct sockaddr_in name;
    unsigned int namelen = sizeof(name);
    err = getsockname(sock, (struct sockaddr *) &name, &namelen);
    if(!inet_ntop(2, &name.sin_addr, buffer, (int)buflen))
    {
        fprintf(stderr, "inet_ntop failed\n");
        return -1;
    }
    close(sock);
    return 0;
}

variable_types:
buffer
char *

variable_types:
buflen
unsigned long

variable_types: sock int

variable_types:
kGoogleDnsIp
char *

variable_types:
kDnsPort
unsigned short

variable_types: err int

variable_types:
namelen
unsigned int

return_type: int

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


createListenFD

decompiled_code:
__int64 __fastcall createListenFD(unsigned int a1)
{
struct addrinfo *v1; // rbx
unsigned int v2; // ebp
int v3; // edi
int optval; // [rsp+Ch] [rbp-14Ch] BYREF
char buf[48]; // [rsp+10h] [rbp-148h] BYREF
char name[128]; // [rsp+40h] [rbp-118h] BYREF
char s[72]; // [rsp+C0h] [rbp-98h] BYREF
struct addrinfo *pai; // [rsp+108h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+110h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
sprintf(s, "%d", a1);
if ( (unsigned int)getIP(name, 0x80u) )
return (unsigned int)-1;
if ( getaddrinfo(name, s, &req, &pai) )
{
fwrite("Error getting address info", 1uLL, 0x1AuLL, stderr);
return (unsigned int)-1;
}
v1 = pai;
if ( pai )
{
while ( 1 )
{
if ( v1->ai_family == 2 )
{
v2 = socket(2, v1->ai_socktype, v1->ai_protocol);
if ( v2 != -1 )
{
v3 = v1->ai_family;
if ( v3 == 2 )
inet_ntop(2, &v1->ai_addr->sa_data[2], buf, 0x2Eu);
else
inet_ntop(v3, &v1->ai_addr->sa_data[6], buf, 0x2Eu);
optval = 1;
if ( setsockopt(v2, 1, 2, &optval, 4u) == -1 )
{
perror("Error setting socket options");
}
else
{
if ( bind(v2, v1->ai_addr, v1->ai_addrlen) != -1 )
{
freeaddrinfo(pai);
if ( listen(v2, 20) == -1 )
{
perror("Listen failed");
v2 = -1;
}
else
{
fprintf(stdout, "Listening on: %s\n", buf);
}
return v2;
}
perror("Binding Server Failed");
}
return (unsigned int)-1;
}
perror("Error opening socket");
}
v1 = v1->ai_next;
if ( !v1 )
{
freeaddrinfo(pai);
goto LABEL_7;
}
}
}
freeaddrinfo(0LL);
LABEL_7:
fwrite("Failed to create any listening sockets\n", 1uLL, 0x27uLL, stderr);
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
struct addrinfo *v1; // rbx
unsigned int v2; // ebp
int v3; // edi
int optval; // [rsp+Ch] [rbp-14Ch] BYREF
char buf[48]; // [rsp+10h] [rbp-148h] BYREF
char name[128]; // [rsp+40h] [rbp-118h] BYREF
char s[72]; // [rsp+C0h] [rbp-98h] BYREF
struct addrinfo *pai; // [rsp+108h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+110h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
sprintf(s, "%d", a1);
if ( (unsigned int)func1(name, 0x80u) )
return (unsigned int)-1;
if ( getaddrinfo(name, s, &req, &pai) )
{
fwrite("Error getting address info", 1uLL, 0x1AuLL, stderr);
return (unsigned int)-1;
}
v1 = pai;
if ( pai )
{
while ( 1 )
{
if ( v1->ai_family == 2 )
{
v2 = socket(2, v1->ai_socktype, v1->ai_protocol);
if ( v2 != -1 )
{
v3 = v1->ai_family;
if ( v3 == 2 )
inet_ntop(2, &v1->ai_addr->sa_data[2], buf, 0x2Eu);
else
inet_ntop(v3, &v1->ai_addr->sa_data[6], buf, 0x2Eu);
optval = 1;
if ( setsockopt(v2, 1, 2, &optval, 4u) == -1 )
{
perror("Error setting socket options");
}
else
{
if ( bind(v2, v1->ai_addr, v1->ai_addrlen) != -1 )
{
freeaddrinfo(pai);
if ( listen(v2, 20) == -1 )
{
perror("Listen failed");
v2 = -1;
}
else
{
fprintf(stdout, "Listening on: %s\n", buf);
}
return v2;
}
perror("Binding Server Failed");
}
return (unsigned int)-1;
}
perror("Error opening socket");
}
v1 = v1->ai_next;
if ( !v1 )
{
freeaddrinfo(pai);
goto LABEL_7;
}
}
}
freeaddrinfo(0LL);
LABEL_7:
fwrite("Failed to create any listening sockets\n", 1uLL, 0x27uLL, stderr);
return (unsigned int)-1;
}

original_code:
int createListenFD(int port)
{
    struct addrinfo hints;
    memset(&hints, 0, sizeof(struct addrinfo));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0001;
    struct addrinfo* serverList;
    char buf[64];
    sprintf(buf, "%d", port);
    char addrBuf[128];
    if(getIP(addrBuf, sizeof(addrBuf)))
    {
        return -1;
    }
    int result = getaddrinfo(addrBuf, buf, &hints, &serverList);
    if(result)
    {
        fprintf(stderr, "Error getting address info");
        return -1;
    }
 char addressString[46];
    struct addrinfo* try;
    int socketFD = -1;
    for(try = serverList; try; try = try->ai_next)
    {
        if(try->ai_family == 2)
        {
            socketFD = socket(try->ai_family, try->ai_socktype, try->ai_protocol);
            if(socketFD == -1)
            {
                perror("Error opening socket");
                continue;
            }
            if(try->ai_family == 2)
            {
                inet_ntop(try->ai_family, &((struct sockaddr_in*)try->ai_addr)->sin_addr, addressString, sizeof(addressString));
            }
            else
            {
                inet_ntop(try->ai_family, &((struct sockaddr_in6*)try->ai_addr)->sin6_addr, addressString, sizeof(addressString));
            }
            int yes = 1;
            if(setsockopt(socketFD, 1, 2, &yes, sizeof(yes)) == -1)
            {
                perror("Error setting socket options");
                return -1;
            }
            if(bind(socketFD, try->ai_addr, try->ai_addrlen) == -1)
            {
                perror("Binding Server Failed");
                return -1;
            }
            break;
        }
    }
    freeaddrinfo(serverList);
    if(socketFD == -1)
    {
        fprintf(stderr, "Failed to create any listening sockets\n");
        return -1;
    }
    if(listen(socketFD, 20) == -1)
    {
        perror("Listen failed");
        return -1;
    }
    else
    {
        fprintf(stdout, "Listening on: %s\n", addressString);
    }
    return socketFD;
}

canonical_original_code:
int createListenFD(int port)
{
    struct addrinfo hints;
    memset(&hints, 0, sizeof(struct addrinfo));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0001;
    struct addrinfo *serverList;
    char buf[64];
    sprintf(buf, "%d", port);
    char addrBuf[128];
    if(getIP(addrBuf, sizeof(addrBuf)))
    {
        return -1;
    }
    int result = getaddrinfo(addrBuf, buf, &hints, &serverList);
    if(result)
    {
        fprintf(stderr, "Error getting address info");
        return -1;
    }
 char addressString[46];
    struct addrinfo *try;
    int socketFD = -1;
    for(try = serverList; try; try = try->ai_next)
    {
        if(try->ai_family == 2)
        {
            socketFD = socket(try->ai_family, try->ai_socktype, try->ai_protocol);
            if(socketFD == -1)
            {
                perror("Error opening socket");
                continue;
            }
            if(try->ai_family == 2)
            {
                inet_ntop(try->ai_family, &((struct sockaddr_in *)try->ai_addr)->sin_addr, addressString, sizeof(addressString));
            }
            else
            {
                inet_ntop(try->ai_family, &((struct sockaddr_in6 *)try->ai_addr)->sin6_addr, addressString, sizeof(addressString));
            }
            int yes = 1;
            if(setsockopt(socketFD, 1, 2, &yes, sizeof(yes)) == -1)
            {
                perror("Error setting socket options");
                return -1;
            }
            if(bind(socketFD, try->ai_addr, try->ai_addrlen) == -1)
            {
                perror("Binding Server Failed");
                return -1;
            }
            break;
        }
    }
    freeaddrinfo(serverList);
    if(socketFD == -1)
    {
        fprintf(stderr, "Failed to create any listening sockets\n");
        return -1;
    }
    if(listen(socketFD, 20) == -1)
    {
        perror("Listen failed");
        return -1;
    }
    else
    {
        fprintf(stdout, "Listening on: %s\n", addressString);
    }
    return socketFD;
}

variable_types: port int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
buf
char [64]

variable_types:
addrBuf
char [128]

variable_types: result int

variable_types:
addressString
char [46]

variable_types: socketFD int

variable_types: yes int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


sendAll

decompiled_code:
__int64 __fastcall sendAll(int fd, void *buf, size_t n)
{
size_t v3; // rbx
ssize_t v4; // rax

v3 = n;
if ( !n )
return 0LL;
while ( 1 )
{
v4 = send(fd, buf, v3, 0);
if ( v4 == -1 )
break;
v3 -= v4;
if ( !v3 )
return 0LL;
}
perror("Failed to send data");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, void *buf, size_t n)
{
size_t v3; // rbx
ssize_t v4; // rax

v3 = n;
if ( !n )
return 0LL;
while ( 1 )
{
v4 = send(fd, buf, v3, 0);
if ( v4 == -1 )
break;
v3 -= v4;
if ( !v3 )
return 0LL;
}
perror("Failed to send data");
return 0xFFFFFFFFLL;
}

original_code:
int sendAll(int socket, const char* buf, size_t num)
{
    while(num)
    {
        ssize_t result = send(socket, buf, num, 0);
        if(result == -1)
        {
            perror("Failed to send data");
            return -1;
        }
        num -= result;
    }
    return 0;
}

canonical_original_code:
int sendAll(int socket, char *buf, unsigned long num)
{
    while(num)
    {
        long result = send(socket, buf, num, 0);
        if(result == -1)
        {
            perror("Failed to send data");
            return -1;
        }
        num -= result;
    }
    return 0;
}

variable_types: socket int

variable_types:
buf
char *

variable_types:
num
unsigned long

variable_types: result long


uSElapsed

decompiled_code:
__suseconds_t __fastcall uSElapsed(_QWORD *a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v2, 0LL);
return v2.tv_usec + 1000000 * (v2.tv_sec - *a1) - a1[1];
}

canonical_decompiled_code:
__suseconds_t __fastcall func2(_QWORD *a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v2, 0LL);
return v2.tv_usec + 1000000 * (v2.tv_sec - *a1) - a1[1];
}

original_code:
int64_t uSElapsed(struct timeval* start)
{
    struct timeval end;
    gettimeofday(&end, ((void *)0));
    return (end.tv_sec - start->tv_sec) * 1000000 + (end.tv_usec - start->tv_usec);
}

canonical_original_code:
long uSElapsed(struct timeval *start)
{
    struct timeval end;
    gettimeofday(&end, ((void *)0));
    return (end.tv_sec - start->tv_sec) * 1000000 + (end.tv_usec - start->tv_usec);
}

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

return_type: long


timeElapsed

decompiled_code:
__suseconds_t __fastcall timeElapsed(_QWORD *a1)
{
return uSElapsed(a1) / 10;
}

canonical_decompiled_code:
__suseconds_t __fastcall func3(_QWORD *a1)
{
return func2(a1) / 10;
}

original_code:
uint64_t timeElapsed(struct timeval* start)
{
    return uSElapsed(start)/10;
}

canonical_original_code:
unsigned long timeElapsed(struct timeval *start)
{
    return uSElapsed(start)/10;
}

return_type: unsigned long

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


original_code:
void hmac_sha256(const unsigned char *text, size_t text_len, const unsigned char *key, size_t key_len, void *digest)
{
    unsigned char k_ipad[65];
    unsigned char k_opad[65];
    unsigned char tk[32];
    unsigned char tk2[32];
    unsigned char bufferIn[1024];
    unsigned char bufferOut[1024];
    int i;
    if (key_len > 64) {
        SHA256(key, key_len, tk);
        key = tk;
        key_len = 32;
    }
    memset(k_ipad, 0, sizeof k_ipad);
    memset(k_opad, 0, sizeof k_opad);
    memcpy(k_ipad, key, key_len);
    memcpy(k_opad, key, key_len);
    for (i = 0; i < 64; i++) {
        k_ipad[i] ^= 0x36;
        k_opad[i] ^= 0x5c;
    }
    memset(bufferIn, 0x00, 1024);
    memcpy(bufferIn, k_ipad, 64);
    memcpy(bufferIn + 64, text, text_len);
    SHA256(bufferIn, 64 + text_len, tk2);
    memset(bufferOut, 0x00, 1024);
    memcpy(bufferOut, k_opad, 64);
    memcpy(bufferOut + 64, tk2, 32);
    SHA256(bufferOut, 64 + 32, digest);
}

canonical_original_code:
void hmac_sha256(unsigned char *text, unsigned long text_len, unsigned char *key, unsigned long key_len, void *digest)
{
    unsigned char k_ipad[65];
    unsigned char k_opad[65];
    unsigned char tk[32];
    unsigned char tk2[32];
    unsigned char bufferIn[1024];
    unsigned char bufferOut[1024];
    int i;
    if (key_len > 64) {
        SHA256(key, key_len, tk);
        key = tk;
        key_len = 32;
    }
    memset(k_ipad, 0, sizeof k_ipad);
    memset(k_opad, 0, sizeof k_opad);
    memcpy(k_ipad, key, key_len);
    memcpy(k_opad, key, key_len);
    for (i = 0; i < 64; i++) {
        k_ipad[i] ^= 0x36;
        k_opad[i] ^= 0x5c;
    }
    memset(bufferIn, 0x00, 1024);
    memcpy(bufferIn, k_ipad, 64);
    memcpy(bufferIn + 64, text, text_len);
    SHA256(bufferIn, 64 + text_len, tk2);
    memset(bufferOut, 0x00, 1024);
    memcpy(bufferOut, k_opad, 64);
    memcpy(bufferOut + 64, tk2, 32);
    SHA256(bufferOut, 64 + 32, digest);
}

variable_types:
text
unsigned char *

variable_types:
key
unsigned char *

variable_types:
digest
void *

variable_types:
tk
unsigned char [32]

variable_types:
bufferIn
unsigned char [1024]

variable_types:
bufferOut
unsigned char [1024]

variable_types: i int

return_type: void


decompiled_code:
const char *__fastcall ece297strerror(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 1:
result = "Invalid parameters";
break;
case 2:
result = "Failed to connect to server";
break;
case 3:
result = "Not authenticated";
break;
case 4:
result = "Invalid username or password";
break;
case 5:
result = "Table not found";
break;
case 6:
result = "Key not found";
break;
default:
result = "Unknown error";
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func6(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 1:
result = "Invalid parameters";
break;
case 2:
result = "Failed to connect to server";
break;
case 3:
result = "Not authenticated";
break;
case 4:
result = "Invalid username or password";
break;
case 5:
result = "Table not found";
break;
case 6:
result = "Key not found";
break;
default:
result = "Unknown error";
break;
}
return result;
}

original_code:
const char* ece297strerror(int error)
{
    switch (error)
    {
        case 1:
        {
            return "Invalid parameters";
        }
        case 2:
        {
            return "Failed to connect to server";
        }
        case 3:
        {
            return "Not authenticated";
        }
        case 4:
        {
            return "Invalid username or password";
        }
        case 5:
        {
            return "Table not found";
        }
        case 6:
        {
            return "Key not found";
        }
        default:
        {
            return "Unknown error";
        }
    }
}

canonical_original_code:
char *ece297strerror(int error)
{
    switch (error)
    {
        case 1:
        {
            return "Invalid parameters";
        }
        case 2:
        {
            return "Failed to connect to server";
        }
        case 3:
        {
            return "Not authenticated";
        }
        case 4:
        {
            return "Invalid username or password";
        }
        case 5:
        {
            return "Table not found";
        }
        case 6:
        {
            return "Key not found";
        }
        default:
        {
            return "Unknown error";
        }
    }
}

variable_types: error int

return_type: char *


recordLatency

decompiled_code:
void __fastcall recordLatency(unsigned __int64 a1, __int64 a2)
{
if ( a1 <= 0x7FFFF )
_InterlockedAdd64((volatile signed __int64 *)(a2 + 8 * a1), 1uLL);
}

canonical_decompiled_code:
void __fastcall func0(unsigned __int64 a1, __int64 a2)
{
if ( a1 <= 0x7FFFF )
_InterlockedAdd64((volatile signed __int64 *)(a2 + 8 * a1), 1uLL);
}

original_code:
static void recordLatency(uint64_t dataPoint, uint64_t* stats)
{
    if(dataPoint < 524288)
    {
        __sync_fetch_and_add(&stats[dataPoint], 1);
    }
}

canonical_original_code:
static void recordLatency(unsigned long dataPoint, unsigned long *stats)
{
    if(dataPoint < 524288)
    {
        __sync_fetch_and_add(&stats[dataPoint], 1);
    }
}

variable_types:
dataPoint
unsigned long

variable_types:
stats
unsigned long *


tulostaOhjeet

repo: charn/WordCount

decompiled_code:
int __fastcall tulostaOhjeet(__int64 a1)
{
printf("Sanalaskuri versio %s\n", "1.1");
printf(aOhjelmanK, a1);
puts("\nOhjelman mahdolliset parametrit:");
printf("%-30s%s", "-h / --help", aTulostaaT);
printf("%-30s%s", "-s / --source <tiedosto>", "Tiedosto, josta sanoja luetaan.\n");
printf("%-30s%s", "-o / --out <tiedosto>", "Tiedosto, johon tulokset tallennetaan.\n");
puts(aJosParametrej);
return puts(aJosSy);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
printf("Sanalaskuri versio %s\n", "1.1");
printf(aOhjelmanK, a1);
puts("\nOhjelman mahdolliset parametrit:");
printf("%-30s%s", "-h / --help", aTulostaaT);
printf("%-30s%s", "-s / --source <tiedosto>", "Tiedosto, josta sanoja luetaan.\n");
printf("%-30s%s", "-o / --out <tiedosto>", "Tiedosto, johon tulokset tallennetaan.\n");
puts(aJosParametrej);
return puts(aJosSy);
}

original_code:
void tulostaOhjeet( const char *komento ) {
 printf("Sanalaskuri versio %s\n", "1.1");
 printf("Ohjelman käyttö: %s [-s tiedosto] [-o tulostiedosto] \n", komento);
 printf("\nOhjelman mahdolliset parametrit:\n");
 printf("%-30s%s","-h / --help","Tulostaa tämän ohjeen.\n");
 printf("%-30s%s","-s / --source <tiedosto>","Tiedosto, josta sanoja luetaan.\n");
 printf("%-30s%s","-o / --out <tiedosto>","Tiedosto, johon tulokset tallennetaan.\n");
 printf("\nJos parametrejä -s tai -o ei anneta, olettaa ohjelma syötteen tulevan standarista syöttövirrasta\ntai tulostuksen menevän standardiin tulostusvirtaan.\n");
 printf("Jos syötettä annetaan näppäimistöllä, voidaan sanojen antaminen lopettaa painamalla CTRL-D\n");
}

canonical_original_code:
void tulostaOhjeet(char *komento) {
 printf("Sanalaskuri versio %s\n", "1.1");
 printf("Ohjelman käyttö: %s [-s tiedosto] [-o tulostiedosto] \n", komento);
 printf("\nOhjelman mahdolliset parametrit:\n");
 printf("%-30s%s","-h / --help","Tulostaa tämän ohjeen.\n");
 printf("%-30s%s","-s / --source <tiedosto>","Tiedosto, josta sanoja luetaan.\n");
 printf("%-30s%s","-o / --out <tiedosto>","Tiedosto, johon tulokset tallennetaan.\n");
 printf("\nJos parametrejä -s tai -o ei anneta, olettaa ohjelma syötteen tulevan standarista syöttövirrasta\ntai tulostuksen menevän standardiin tulostusvirtaan.\n");
 printf("Jos syötettä annetaan näppäimistöllä, voidaan sanojen antaminen lopettaa painamalla CTRL-D\n");
}

variable_types:
komento
char *


buildTree

decompiled_code:
_DWORD *buildTree()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = malloc(0x10uLL);
v1 = v0;
if ( v0 )
{
v0[2] = 0;
*(_QWORD *)v0 = 0LL;
}
else
{
fwrite(&unk_402338, 1uLL, 0x23uLL, stderr);
}
return v1;
}

canonical_decompiled_code:
_DWORD *func10()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = malloc(0x10uLL);
v1 = v0;
if ( v0 )
{
v0[2] = 0;
*(_QWORD *)v0 = 0LL;
}
else
{
fwrite(&unk_402338, 1uLL, 0x23uLL, stderr);
}
return v1;
}

original_code:
BinTree* buildTree( void ) {
 BinTree *puu = ((void *)0);
 if((puu=malloc(sizeof(BinTree))) != ((void *)0)) {
  puu->items = 0;
  puu->root = ((void *)0);
 }
 else
  fprintf(stderr,"Muistinvaraus puulle epäonnistui.\n");
 return puu;
}

canonical_original_code:
struct BinTree *buildTree() {
 struct BinTree *puu = ((void *)0);
 if((puu=malloc(sizeof(BinTree))) != ((void *)0)) {
  puu->items = 0;
  puu->root = ((void *)0);
 }
 else
  fprintf(stderr,"Muistinvaraus puulle epäonnistui.\n");
 return puu;
}

variable_types: struct BinTree { struct BinSilmu { struct BinSilmu *left; struct BinSilmu *right; struct BinSilmu *parent; char *string; int count; } *root; int items; } *

user_defined_types: struct BinTree { struct BinSilmu *root; int items; }


addSilmu

decompiled_code:
__int64 __fastcall addSilmu(__int64 *a1, void *a2)
{
_QWORD *v2; // rax
_QWORD *v3; // r13
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // rax

v2 = buildSilmu(a2);
if ( v2 )
{
v3 = v2;
if ( a1 )
{
v4 = *a1;
if ( *a1 )
{
while ( 1 )
{
v6 = strcmp((const char *)a2, *(const char **)(v4 + 24)) >= 0 ? *(_QWORD *)(v4 + 8) : *(_QWORD *)v4;
if ( !v6 )
break;
v4 = v6;
}
v3[2] = v4;
if ( strcmp((const char *)a2, *(const char **)(v4 + 24)) < 0 )
*(_QWORD *)v4 = v3;
else
*(_QWORD *)(v4 + 8) = v3;
}
else
{
*a1 = (__int64)v2;
}
++*((_DWORD *)a1 + 2);
result = 0LL;
}
else
{
fwrite("Ei voida laittaa silmua puuhun, jota ei ole olemassa.\n", 1uLL, 0x36uLL, stderr);
result = 1LL;
}
}
else
{
fwrite("Silmua ei onnistuttu luomaan.\n", 1uLL, 0x1EuLL, stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1, void *a2)
{
_QWORD *v2; // rax
_QWORD *v3; // r13
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // rax

v2 = buildSilmu(a2);
if ( v2 )
{
v3 = v2;
if ( a1 )
{
v4 = *a1;
if ( *a1 )
{
while ( 1 )
{
v6 = strcmp((const char *)a2, *(const char **)(v4 + 24)) >= 0 ? *(_QWORD *)(v4 + 8) : *(_QWORD *)v4;
if ( !v6 )
break;
v4 = v6;
}
v3[2] = v4;
if ( strcmp((const char *)a2, *(const char **)(v4 + 24)) < 0 )
*(_QWORD *)v4 = v3;
else
*(_QWORD *)(v4 + 8) = v3;
}
else
{
*a1 = (__int64)v2;
}
++*((_DWORD *)a1 + 2);
result = 0LL;
}
else
{
fwrite("Ei voida laittaa silmua puuhun, jota ei ole olemassa.\n", 1uLL, 0x36uLL, stderr);
result = 1LL;
}
}
else
{
fwrite("Silmua ei onnistuttu luomaan.\n", 1uLL, 0x1EuLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int addSilmu(BinTree *puu, const char *string) {
 BinSilmu *silmu, *apusilmu, *vanhempi;
 silmu = buildSilmu(string);
 if(silmu==((void *)0)) {
  fprintf(stderr,"Silmua ei onnistuttu luomaan.\n");
  return 1;
 }
 if(puu == ((void *)0)) {
  fprintf(stderr,"Ei voida laittaa silmua puuhun, jota ei ole olemassa.\n");
  return 1;
 }
 if(puu->root == ((void *)0))
  puu->root = silmu;
 else {
  apusilmu = puu->root;
  while(apusilmu != ((void *)0)) {
   vanhempi = apusilmu;
   if((strcmp(string, apusilmu->string)) < 0)
    apusilmu = apusilmu->left;
   else
    apusilmu = apusilmu->right;
  }
  silmu->parent = vanhempi;
  if((strcmp(string, vanhempi->string)) < 0)
   vanhempi->left = silmu;
  else
   vanhempi->right = silmu;
 }
 (puu->items)++;
 return 0;
}

canonical_original_code:
int addSilmu(struct BinTree *puu, char *string) {
 struct BinSilmu *silmu; struct BinSilmu *apusilmu; struct BinSilmu *vanhempi;
 silmu = buildSilmu(string);
 if(silmu==((void *)0)) {
  fprintf(stderr,"Silmua ei onnistuttu luomaan.\n");
  return 1;
 }
 if(puu == ((void *)0)) {
  fprintf(stderr,"Ei voida laittaa silmua puuhun, jota ei ole olemassa.\n");
  return 1;
 }
 if(puu->root == ((void *)0))
  puu->root = silmu;
 else {
  apusilmu = puu->root;
  while(apusilmu != ((void *)0)) {
   vanhempi = apusilmu;
   if((strcmp(string, apusilmu->string)) < 0)
    apusilmu = apusilmu->left;
   else
    apusilmu = apusilmu->right;
  }
  silmu->parent = vanhempi;
  if((strcmp(string, vanhempi->string)) < 0)
   vanhempi->left = silmu;
  else
   vanhempi->right = silmu;
 }
 (puu->items)++;
 return 0;
}

variable_types:
string
char *

variable_types: struct BinSilmu { struct BinSilmu *left; struct BinSilmu *right; struct BinSilmu *parent; char *string; int count; } *


extendChar

decompiled_code:
void *__fastcall extendChar(void *ptr, int a2, int a3)
{
void *v3; // rax
void *v4; // r12

if ( a3 < 0 || a2 < 0 || !ptr )
return 0LL;
v3 = calloc(a2 + a3, 1uLL);
v4 = v3;
if ( v3 )
{
memcpy(v3, ptr, a2);
free(ptr);
}
else
{
fwrite(&unk_402440, 1uLL, 0x3DuLL, stderr);
}
return v4;
}

canonical_decompiled_code:
void *__fastcall func13(void *ptr, int a2, int a3)
{
void *v3; // rax
void *v4; // r12

if ( a3 < 0 || a2 < 0 || !ptr )
return 0LL;
v3 = calloc(a2 + a3, 1uLL);
v4 = v3;
if ( v3 )
{
memcpy(v3, ptr, a2);
free(ptr);
}
else
{
fwrite(&unk_402440, 1uLL, 0x3DuLL, stderr);
}
return v4;
}

original_code:
char* extendChar(char *sana, int pituus, int kasvatuspituus) {
 char *pidempisana;
 if (sana == ((void *)0) || pituus < 0 || kasvatuspituus < 0)
  return ((void *)0);
 if((pidempisana=calloc((pituus + kasvatuspituus),sizeof(char))) == ((void *)0) ) {
  fprintf(stderr,"Muistinvaraus pidemmälle merkkijonotaulukolle epäonnistui.\n");
  return ((void *)0);
 }
 memcpy(pidempisana, sana,(pituus*sizeof(char)));
 free(sana);
 return pidempisana;
}

canonical_original_code:
char *extendChar(char *sana, int pituus, int kasvatuspituus) {
 char *pidempisana;
 if (sana == ((void *)0) || pituus < 0 || kasvatuspituus < 0)
  return ((void *)0);
 if((pidempisana=calloc((pituus + kasvatuspituus),sizeof(char))) == ((void *)0) ) {
  fprintf(stderr,"Muistinvaraus pidemmälle merkkijonotaulukolle epäonnistui.\n");
  return ((void *)0);
 }
 memcpy(pidempisana, sana,(pituus*sizeof(char)));
 free(sana);
 return pidempisana;
}

variable_types:
sana
char *

variable_types: pituus int

variable_types: kasvatuspituus int

variable_types:
pidempisana
char *


repo: charsyam/tutorial

decompiled_code:
__int64 __fastcall parse_command(char *a1, char *a2, char *a3, char *a4)
{
char *v7; // rsi
__int64 result; // rax
char *v9; // rsi
char *v10; // rsi
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v7 = strtok_r(a1, " ", save_ptr);
result = 0LL;
if ( v7 )
{
strcpy(a2, v7);
v9 = strtok_r(0LL, " ", save_ptr);
result = 0LL;
if ( v9 )
{
strcpy(a3, v9);
v10 = strtok_r(0LL, " ", save_ptr);
result = 0LL;
if ( v10 )
{
strcpy(a4, v10);
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, char *a2, char *a3, char *a4)
{
char *v7; // rsi
__int64 result; // rax
char *v9; // rsi
char *v10; // rsi
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v7 = strtok_r(a1, " ", save_ptr);
result = 0LL;
if ( v7 )
{
strcpy(a2, v7);
v9 = strtok_r(0LL, " ", save_ptr);
result = 0LL;
if ( v9 )
{
strcpy(a3, v9);
v10 = strtok_r(0LL, " ", save_ptr);
result = 0LL;
if ( v10 )
{
strcpy(a4, v10);
result = 1LL;
}
}
}
return result;
}

original_code:
int parse_command(char *cmdline, char *cmd, char *uri, char *protocol) {
    char *token = ((void *)0);
    char *next;
    token = strtok_r(cmdline, " ", &next);
    if (token == ((void *)0))
        return 0;
    strcpy(cmd, token);
    token = strtok_r(((void *)0), " ", &next);
    if (token == ((void *)0))
        return 0;
    strcpy(uri, token);
    token = strtok_r(((void *)0), " ", &next);
    if (token == ((void *)0))
        return 0;
    strcpy(protocol, token);
    return 1;
}

variable_types:
cmdline
char *

variable_types:
cmd
char *

variable_types:
uri
char *

variable_types:
protocol
char *

variable_types:
token
char *

variable_types:
next
char *


decompiled_code:
__int64 __fastcall parse_options(char *a1, char *a2, char *a3)
{
char *v5; // rsi
__int64 result; // rax
char *v7; // rsi
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v5 = strtok_r(a1, ": ", save_ptr);
result = 0LL;
if ( v5 )
{
strcpy(a2, v5);
v7 = strtok_r(0LL, ": ", save_ptr);
result = 0LL;
if ( v7 )
{
strcpy(a3, v7);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, char *a2, char *a3)
{
char *v5; // rsi
__int64 result; // rax
char *v7; // rsi
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v5 = strtok_r(a1, ": ", save_ptr);
result = 0LL;
if ( v5 )
{
strcpy(a2, v5);
v7 = strtok_r(0LL, ": ", save_ptr);
result = 0LL;
if ( v7 )
{
strcpy(a3, v7);
result = 1LL;
}
}
return result;
}

original_code:
int parse_options(char *line, char *name, char *value) {
    char *token = ((void *)0);
    char *next;
    token = strtok_r(line, ": ", &next);
    if (token == ((void *)0))
        return 0;
    strcpy(name, token);
    token = strtok_r(((void *)0), ": ", &next);
    if (token == ((void *)0))
        return 0;
    strcpy(value, token);
    return 1;
}

variable_types:
line
char *

variable_types:
name
char *

variable_types:
value
char *


decompiled_code:
__int64 __fastcall http_parser(char *a1)
{
char *i; // rbx
char v3[1024]; // [rsp+0h] [rbp-C18h] BYREF
char v4[1024]; // [rsp+400h] [rbp-818h] BYREF
char v5[1032]; // [rsp+800h] [rbp-418h] BYREF
char *save_ptr[2]; // [rsp+C08h] [rbp-10h] BYREF

for ( i = strtok_r(a1, "\r\n", save_ptr); i; i = strtok_r(0LL, "\r\n", save_ptr) )
{
puts(i);
parse_command(i, v5, v4, v3);
printf("cmd: %s, uri: %s, protocol: %s\n", v5, v4, v3);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1)
{
char *i; // rbx
char v3[1024]; // [rsp+0h] [rbp-C18h] BYREF
char v4[1024]; // [rsp+400h] [rbp-818h] BYREF
char v5[1032]; // [rsp+800h] [rbp-418h] BYREF
char *save_ptr[2]; // [rsp+C08h] [rbp-10h] BYREF

for ( i = strtok_r(a1, "\r\n", save_ptr); i; i = strtok_r(0LL, "\r\n", save_ptr) )
{
puts(i);
func7(i, v5, v4, v3);
printf("cmd: %s, uri: %s, protocol: %s\n", v5, v4, v3);
}
return 0LL;
}

original_code:
int http_parser(char *header) {
    char *token = ((void *)0);
    char *next;
    char cmd[1024];
    char uri[1024];
    char protocol[1024];
    char name[1024];
    char value[1024];
    token = strtok_r(header, "\r\n", &next);
    int line = 0;
    while(token) {
        printf("%s\n", token);
        if (line == 0) {
            parse_command(token, cmd, uri, protocol);
            printf("cmd: %s, uri: %s, protocol: %s\n", cmd, uri, protocol);
        } else {
            parse_options(token, name, value);
            printf("name: %s, value: %s\n", name, value);
        }
        token = strtok_r(((void *)0), "\r\n", &next);
    }
    return 0;
}

variable_types:
header
char *

variable_types:
cmd
char [1024]

variable_types:
uri
char [1024]

variable_types:
protocol
char [1024]

variable_types:
name
char [1024]

variable_types:
value
char [1024]

variable_types: line int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

strcpy(v4, "GET / HTTP/1.1\r\nHost: www.naver.com\r\nconnection: close\r\n\r\n");
http_parser(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

strcpy(v4, "GET / HTTP/1.1\r\nHost: www.naver.com\r\nconnection: close\r\n\r\n");
func9(v4);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    char header[] = "GET / HTTP/1.1\r\nHost: www.naver.com\r\nconnection: close\r\n\r\n";
    http_parser(header);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
header
char []


createTcpServerSocket

decompiled_code:
__int64 __fastcall createTcpServerSocket(struct sockaddr *addr)
{
int v1; // eax
unsigned int v2; // ebx

v1 = socket(2, 1, 0);
v2 = v1;
if ( v1 != -1 )
{
if ( bind(v1, addr, 0x10u) == -1 )
{
v2 = -1;
}
else if ( listen(v2, 100) == -1 )
{
v2 = -1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(struct sockaddr *addr)
{
int v1; // eax
unsigned int v2; // ebx

v1 = socket(2, 1, 0);
v2 = v1;
if ( v1 != -1 )
{
if ( bind(v1, addr, 0x10u) == -1 )
{
v2 = -1;
}
else if ( listen(v2, 100) == -1 )
{
v2 = -1;
}
}
return v2;
}

original_code:
int createTcpServerSocket(struct sockaddr_in *addr) {
    int sock = socket(2, SOCK_STREAM, 0);
    if (sock == -1) {
        return -1;
    }
    if (bind(sock, (struct sockaddr *)addr, sizeof(struct sockaddr_in)) == -1) {
        return -1;
    }
    if (listen(sock, 100) == -1)
        return -1;
    return sock;
}

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: sock int


createUdpServerSocket

decompiled_code:
__int64 __fastcall createUdpServerSocket(struct sockaddr *addr)
{
int v1; // eax
unsigned int v2; // ebx

v1 = socket(2, 2, 0);
v2 = v1;
if ( v1 != -1 && bind(v1, addr, 0x10u) == -1 )
v2 = -1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(struct sockaddr *addr)
{
int v1; // eax
unsigned int v2; // ebx

v1 = socket(2, 2, 0);
v2 = v1;
if ( v1 != -1 && bind(v1, addr, 0x10u) == -1 )
v2 = -1;
return v2;
}

original_code:
int createUdpServerSocket(struct sockaddr_in *addr) {
    int sock = socket(2, SOCK_DGRAM, 0);
    if (sock == -1) {
        return -1;
    }
    if (bind(sock, (struct sockaddr *)addr, sizeof(struct sockaddr_in)) == -1) {
        return -1;
    }
    return sock;
}


parseXml

decompiled_code:
__int64 __fastcall parseXml(const char *a1)
{
xmlCheckVersion(20904LL);
parseXmlReal(a1);
xmlCleanupParser();
xmlMemoryDump();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
xmlCheckVersion(20904LL);
func7(a1);
xmlCleanupParser();
xmlMemoryDump();
return 0LL;
}

original_code:
int parseXml(char *filename) {
    xmlCheckVersion(20904);
    parseXmlReal(filename);
    xmlCleanupParser();
    xmlMemoryDump();
    return 0;
}

variable_types:
filename
char *


OnCharacters

decompiled_code:
char __fastcall OnCharacters(const char **a1, const char *a2, int a3)
{
const char *v4; // rdx
bool v5; // zf
__int64 v6; // rax
__int64 v7; // rbp
size_t v8; // rbp
char *v9; // rbx
int v10; // edx
__int64 v11; // rbp
char v13[1048]; // [rsp+0h] [rbp-418h] BYREF

v4 = *a1;
if ( !strcmp(*a1, "name") )
{
v8 = a3;
v9 = (char *)(388LL * fileindex + 4210912);
LOBYTE(v6) = (unsigned __int8)strncpy(v9, a2, v8);
v9[v8] = 0;
}
else if ( !strcmp(v4, "size") )
{
strncpy(v13, a2, a3);
v13[a3] = 0;
v10 = atoi(v13);
v6 = 388LL * fileindex;
*(int *)((char *)&dword_404160 + v6) = v10;
}
else if ( !strcmp(v4, "time") )
{
v11 = 388LL * fileindex;
LOBYTE(v6) = (unsigned __int8)strncpy(&byte_404164[v11], a2, a3);
xmlfile[a3 + v11] = 0;
}
else
{
v5 = strcmp(v4, "owner") == 0;
LOBYTE(v6) = !v5;
if ( v5 )
{
v7 = 388LL * fileindex;
LOBYTE(v6) = (unsigned __int8)strncpy(&byte_4041E4[v7], a2, a3);
xmlfile[a3 + v7] = 0;
}
}
return v6;
}

canonical_decompiled_code:
char __fastcall func8(const char **a1, const char *a2, int a3)
{
const char *v4; // rdx
bool v5; // zf
__int64 v6; // rax
__int64 v7; // rbp
size_t v8; // rbp
char *v9; // rbx
int v10; // edx
__int64 v11; // rbp
char v13[1048]; // [rsp+0h] [rbp-418h] BYREF

v4 = *a1;
if ( !strcmp(*a1, "name") )
{
v8 = a3;
v9 = (char *)(388LL * fileindex + 4210912);
LOBYTE(v6) = (unsigned __int8)strncpy(v9, a2, v8);
v9[v8] = 0;
}
else if ( !strcmp(v4, "size") )
{
strncpy(v13, a2, a3);
v13[a3] = 0;
v10 = atoi(v13);
v6 = 388LL * fileindex;
*(int *)((char *)&dword_404160 + v6) = v10;
}
else if ( !strcmp(v4, "time") )
{
v11 = 388LL * fileindex;
LOBYTE(v6) = (unsigned __int8)strncpy(&byte_404164[v11], a2, a3);
xmlfile[a3 + v11] = 0;
}
else
{
v5 = strcmp(v4, "owner") == 0;
LOBYTE(v6) = !v5;
if ( v5 )
{
v7 = 388LL * fileindex;
LOBYTE(v6) = (unsigned __int8)strncpy(&byte_4041E4[v7], a2, a3);
xmlfile[a3 + v7] = 0;
}
}
return v6;
}

original_code:
static void OnCharacters(void *ctx, const xmlChar *ch, int len) {
    struct state *parseState = (struct state *)ctx;
    if (!strcmp(parseState->tag, "name")) {
        strncpy(xmlfile[fileindex].name, (const char *)ch, len);
        xmlfile[fileindex].name[len] = 0;
    }
    else if (!strcmp(parseState->tag, "size")) {
        char buf[1024];
        strncpy(buf, (const char *)ch, len);
        buf[len] = 0;
        xmlfile[fileindex].size = atoi(buf);
    }
    else if (!strcmp(parseState->tag, "time")) {
        strncpy(xmlfile[fileindex].time, (const char *)ch, len);
        xmlfile[fileindex].name[len] = 0;
    }
    else if (!strcmp(parseState->tag, "owner")) {
        strncpy(xmlfile[fileindex].owner, (const char *)ch, len);
        xmlfile[fileindex].name[len] = 0;
    }
}

canonical_original_code:
static void OnCharacters(void *ctx, unsigned char *ch, int len) {
    struct state *parseState = (struct state *)ctx;
    if (!strcmp(parseState->tag, "name")) {
        strncpy(xmlfile[fileindex].name, (char *)ch, len);
        xmlfile[fileindex].name[len] = 0;
    }
    else if (!strcmp(parseState->tag, "size")) {
        char buf[1024];
        strncpy(buf, (char *)ch, len);
        buf[len] = 0;
        xmlfile[fileindex].size = atoi(buf);
    }
    else if (!strcmp(parseState->tag, "time")) {
        strncpy(xmlfile[fileindex].time, (char *)ch, len);
        xmlfile[fileindex].name[len] = 0;
    }
    else if (!strcmp(parseState->tag, "owner")) {
        strncpy(xmlfile[fileindex].owner, (char *)ch, len);
        xmlfile[fileindex].name[len] = 0;
    }
}

variable_types:
ctx
void *

variable_types:
ch
unsigned char *

variable_types: len int

variable_types:
parseState
struct state { char *tag; } *

variable_types:
buf
char [1024]


createTcpServerSocket

canonical_decompiled_code:
__int64 __fastcall func9(struct sockaddr *addr)
{
int v1; // eax
unsigned int v2; // ebx

v1 = socket(2, 1, 0);
v2 = v1;
if ( v1 != -1 )
{
if ( bind(v1, addr, 0x10u) == -1 )
{
v2 = -1;
}
else if ( listen(v2, 100) == -1 )
{
v2 = -1;
}
}
return v2;
}

canonical_original_code:
int createTcpServerSocket(struct sockaddr_in *addr) {
    int sock = socket(2, SOCK_STREAM, 0);
    if (sock == -1) {
        return -1;
    }
    if (bind(sock, (struct sockaddr *)addr, sizeof(struct sockaddr_in)) == -1) {
        return -1;
    }
    if (listen(sock, 100) == -1)
        return -1;
    return sock;
}


createUdpServerSocket

canonical_decompiled_code:
__int64 __fastcall func10(struct sockaddr *addr)
{
int v1; // eax
unsigned int v2; // ebx

v1 = socket(2, 2, 0);
v2 = v1;
if ( v1 != -1 && bind(v1, addr, 0x10u) == -1 )
v2 = -1;
return v2;
}

canonical_original_code:
int createUdpServerSocket(struct sockaddr_in *addr) {
    int sock = socket(2, SOCK_DGRAM, 0);
    if (sock == -1) {
        return -1;
    }
    if (bind(sock, (struct sockaddr *)addr, sizeof(struct sockaddr_in)) == -1) {
        return -1;
    }
    return sock;
}


multicast

decompiled_code:
int multicast()
{
int result; // eax
int v1; // ebx
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr inp; // [rsp+10h] [rbp-18h] BYREF

*(_QWORD *)&inp.sa_family = 0LL;
*(_QWORD *)&inp.sa_data[6] = 0LL;
result = socket(2, 2, 0);
if ( result != -1 )
{
v1 = result;
inp.sa_family = 2;
*(_WORD *)inp.sa_data = _bswap_16(2001);
inet_aton("226.0.0.1", (struct in_addr *)&inp.sa_data[2]);
optval = 1000;
setsockopt(v1, 0, 33, &optval, 4u);
result = sendto(v1, "notification", 0xCuLL, 0, &inp, 0x10u);
if ( result == -1 )
result = fwrite("ERROR: multicast\n", 1uLL, 0x11uLL, stderr);
}
return result;
}

canonical_decompiled_code:
int func13()
{
int result; // eax
int v1; // ebx
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr inp; // [rsp+10h] [rbp-18h] BYREF

*(_QWORD *)&inp.sa_family = 0LL;
*(_QWORD *)&inp.sa_data[6] = 0LL;
result = socket(2, 2, 0);
if ( result != -1 )
{
v1 = result;
inp.sa_family = 2;
*(_WORD *)inp.sa_data = func7(2001);
inet_aton("226.0.0.1", (struct in_addr *)&inp.sa_data[2]);
optval = 1000;
setsockopt(v1, 0, 33, &optval, 4u);
result = sendto(v1, "notification", 0xCuLL, 0, &inp, 0x10u);
if ( result == -1 )
result = fwrite("ERROR: multicast\n", 1uLL, 0x11uLL, stderr);
}
return result;
}

original_code:
void multicast() {
    struct sockaddr_in addr;
    socklen_t len = sizeof(addr);
    memset(&addr, 0, sizeof(addr));
    int ufd = socket(2, SOCK_DGRAM, 0);
    if (ufd == -1) {
        return;
    }
    addr.sin_family = 2;
    addr.sin_port = htons(2001);
    inet_aton("226.0.0.1", &addr.sin_addr);
    int ttl=1000;
    setsockopt(ufd, IPPROTO_IP, 33, (void *)&ttl, sizeof(ttl));
    char *msg = "notification";
    int numbytes = sendto(ufd, msg, strlen(msg), 0, (struct sockaddr *)&addr, len);
    if (numbytes == -1) {
        fprintf(stderr, "ERROR: multicast\n");
    }
}

canonical_original_code:
void multicast() {
    struct sockaddr_in addr;
    unsigned int len = sizeof(addr);
    memset(&addr, 0, sizeof(addr));
    int ufd = socket(2, SOCK_DGRAM, 0);
    if (ufd == -1) {
        return;
    }
    addr.sin_family = 2;
    addr.sin_port = htons(2001);
    inet_aton("226.0.0.1", &addr.sin_addr);
    int ttl = 1000;
    setsockopt(ufd, IPPROTO_IP, 33, (void *)&ttl, sizeof(ttl));
    char *msg = "notification";
    int numbytes = sendto(ufd, msg, strlen(msg), 0, (struct sockaddr *)&addr, len);
    if (numbytes == -1) {
        fprintf(stderr, "ERROR: multicast\n");
    }
}

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:
len
unsigned int

variable_types: ufd int

variable_types: ttl int

variable_types:
msg
char *

variable_types: numbytes int


broadcast

decompiled_code:
int broadcast()
{
int result; // eax
int v1; // ebx
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr inp; // [rsp+10h] [rbp-18h] BYREF

*(_QWORD *)&inp.sa_family = 0LL;
*(_QWORD *)&inp.sa_data[6] = 0LL;
result = socket(2, 2, 0);
if ( result != -1 )
{
v1 = result;
inp.sa_family = 2;
*(_WORD *)inp.sa_data = _bswap_16(2001);
inet_aton("255.255.255.255", (struct in_addr *)&inp.sa_data[2]);
optval = 1;
setsockopt(v1, 1, 6, &optval, 4u);
result = sendto(v1, "notification", 0xCuLL, 0, &inp, 0x10u);
if ( result == -1 )
result = fwrite("ERROR: broadcast\n", 1uLL, 0x11uLL, stderr);
}
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax
int v1; // ebx
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr inp; // [rsp+10h] [rbp-18h] BYREF

*(_QWORD *)&inp.sa_family = 0LL;
*(_QWORD *)&inp.sa_data[6] = 0LL;
result = socket(2, 2, 0);
if ( result != -1 )
{
v1 = result;
inp.sa_family = 2;
*(_WORD *)inp.sa_data = func0(2001);
inet_aton("255.255.255.255", (struct in_addr *)&inp.sa_data[2]);
optval = 1;
setsockopt(v1, 1, 6, &optval, 4u);
result = sendto(v1, "notification", 0xCuLL, 0, &inp, 0x10u);
if ( result == -1 )
result = fwrite("ERROR: broadcast\n", 1uLL, 0x11uLL, stderr);
}
return result;
}

original_code:
void broadcast() {
    struct sockaddr_in addr;
    socklen_t len = sizeof(addr);
    memset(&addr, 0, sizeof(addr));
    int ufd = socket(2, SOCK_DGRAM, 0);
    if (ufd == -1) {
        return;
    }
    addr.sin_family = 2;
    addr.sin_port = htons(2001);
    inet_aton("255.255.255.255", &addr.sin_addr);
    int opt = 1;
    setsockopt(ufd, 1, 6, &opt, sizeof(opt));
    char *msg = "notification";
    int numbytes = sendto(ufd, msg, strlen(msg), 0, (struct sockaddr *)&addr, len);
    if (numbytes == -1) {
        fprintf(stderr, "ERROR: broadcast\n");
    }
}

canonical_original_code:
void broadcast() {
    struct sockaddr_in addr;
    unsigned int len = sizeof(addr);
    memset(&addr, 0, sizeof(addr));
    int ufd = socket(2, SOCK_DGRAM, 0);
    if (ufd == -1) {
        return;
    }
    addr.sin_family = 2;
    addr.sin_port = htons(2001);
    inet_aton("255.255.255.255", &addr.sin_addr);
    int opt = 1;
    setsockopt(ufd, 1, 6, &opt, sizeof(opt));
    char *msg = "notification";
    int numbytes = sendto(ufd, msg, strlen(msg), 0, (struct sockaddr *)&addr, len);
    if (numbytes == -1) {
        fprintf(stderr, "ERROR: broadcast\n");
    }
}

variable_types: opt int


repo: chartbeat/tcpkill

decompiled_code:
char *__fastcall copy_argv(const char **a1)
{
const char *v1; // rbx
const char **v2; // rbp
const char **v3; // r12
const char *v4; // rdi
unsigned int v5; // er13
char *v6; // rax
char *v7; // rdi
const char **v8; // rsi
char *v9; // rcx
char v10; // dl

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1;
v3 = a1;
v4 = *a1;
v5 = 0;
do
{
++v3;
v5 += strlen(v4) + 1;
v4 = *v3;
}
while ( *v3 );
v6 = (char *)malloc(v5);
v7 = v6;
if ( !v6 )
err(1, "copy_argv: malloc");
v8 = v2 + 1;
do
{
do
{
++v1;
v9 = v6++;
v10 = *(v1 - 1);
*(v6 - 1) = v10;
}
while ( v10 );
*v9 = 32;
v1 = *v8++;
}
while ( v1 );
*(v6 - 1) = 0;
return v7;
}

canonical_decompiled_code:
char *__fastcall func9(const char **a1)
{
const char *v1; // rbx
const char **v2; // rbp
const char **v3; // r12
const char *v4; // rdi
unsigned int v5; // er13
char *v6; // rax
char *v7; // rdi
const char **v8; // rsi
char *v9; // rcx
char v10; // dl

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1;
v3 = a1;
v4 = *a1;
v5 = 0;
do
{
++v3;
v5 += strlen(v4) + 1;
v4 = *v3;
}
while ( *v3 );
v6 = (char *)malloc(v5);
v7 = v6;
if ( !v6 )
err(1, "copy_argv: malloc");
v8 = v2 + 1;
do
{
do
{
++v1;
v9 = v6++;
v10 = *(v1 - 1);
*(v6 - 1) = v10;
}
while ( v10 );
*v9 = 32;
v1 = *v8++;
}
while ( v1 );
*(v6 - 1) = 0;
return v7;
}

original_code:
char *
copy_argv(char **argv)
{
 char **p, *buf, *src, *dst;
 u_int len = 0;
 p = argv;
 if (*p == 0)
  return (0);
 while (*p)
  len += strlen(*p++) + 1;
 if ((buf = (char *)malloc(len)) == ((void *)0))
  err(1, "copy_argv: malloc");
 p = argv;
 dst = buf;
 while ((src = *p++) != ((void *)0)) {
  while ((*dst++ = *src++) != '\0')
   ;
  dst[-1] = ' ';
 }
 dst[-1] = '\0';
 return (buf);
}

canonical_original_code:
char *copy_argv(char **argv)
{
 char **p; char *buf; char *src; char *dst;
 unsigned int len = 0;
 p = argv;
 if (*p == 0)
  return (0);
 while (*p)
  len += strlen(*p++) + 1;
 if ((buf = (char *)malloc(len)) == ((void *)0))
  err(1, "copy_argv: malloc");
 p = argv;
 dst = buf;
 while ((src = *p++) != ((void *)0)) {
  while ((*dst++ = *src++) != '\0')
   ;
  dst[-1] = ' ';
 }
 dst[-1] = '\0';
 return (buf);
}

variable_types:
argv
char **

variable_types:
p
char **

variable_types:
buf
char *

variable_types:
src
char *

variable_types:
dst
char *


decompiled_code:
__int64 __fastcall tcp_kill_cb(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
_BYTE *v4; // rbp
_BYTE *v5; // r12
unsigned int v6; // er13
unsigned __int16 v7; // r14
unsigned __int16 v8; // r15
const char *v9; // rax
int v10; // er14
const char *v11; // [rsp+0h] [rbp-88h]
int v12; // [rsp+0h] [rbp-88h]
int v13; // [rsp+Ch] [rbp-7Ch]
char s[120]; // [rsp+10h] [rbp-78h] BYREF

result = pcap_off;
v4 = (_BYTE *)(a3 + pcap_off);
if ( v4[9] == 6 )
{
v5 = &v4[(4 * *v4) & 0x3C];
if ( (v5[13] & 7) == 0 )
{
v6 = _bswap_32(*((_DWORD *)v5 + 2));
v13 = (unsigned __int16)_bswap_16(*((_WORD *)v5 + 7));
v7 = _bswap_16(*((_WORD *)v5 + 1));
v11 = (const char *)libnet_addr2name4();
v8 = _bswap_16(*(_WORD *)v5);
v9 = (const char *)libnet_addr2name4();
snprintf(s, 0x40uLL, "%s:%d > %s:%d:", v9, v8, v11, v7);
if ( Opt_severity > 0 )
{
v12 = 0;
v10 = 0;
do
{
v6 += v12;
libnet_clear_packet();
_bswap_16(*(_WORD *)v5);
_bswap_16(*((_WORD *)v5 + 1));
libnet_build_tcp();
libnet_get_prand();
libnet_build_ipv4();
if ( (int)libnet_write() < 0 )
warn("write", 0LL);
fprintf(stderr, "%s R %lu:%lu(0) win 0\n", s, v6, v6);
++v10;
v12 += v13;
}
while ( Opt_severity > v10 );
}
result = (unsigned int)(kill_counter + 1);
kill_counter = result;
if ( (int)result >= Opt_max_kill )
{
if ( Opt_max_kill )
result = pcap_breakloop();
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
_BYTE *v4; // rbp
_BYTE *v5; // r12
unsigned int v6; // er13
unsigned __int16 v7; // r14
unsigned __int16 v8; // r15
const char *v9; // rax
int v10; // er14
const char *v11; // [rsp+0h] [rbp-88h]
int v12; // [rsp+0h] [rbp-88h]
int v13; // [rsp+Ch] [rbp-7Ch]
char s[120]; // [rsp+10h] [rbp-78h] BYREF

result = pcap_off;
v4 = (_BYTE *)(a3 + pcap_off);
if ( v4[9] == 6 )
{
v5 = &v4[(4 * *v4) & 0x3C];
if ( (v5[13] & 7) == 0 )
{
v6 = func10(*((_DWORD *)v5 + 2));
v13 = (unsigned __int16)func11(*((_WORD *)v5 + 7));
v7 = func11(*((_WORD *)v5 + 1));
v11 = (const char *)libnet_addr2name4();
v8 = func11(*(_WORD *)v5);
v9 = (const char *)libnet_addr2name4();
snprintf(s, 0x40uLL, "%s:%d > %s:%d:", v9, v8, v11, v7);
if ( Opt_severity > 0 )
{
v12 = 0;
v10 = 0;
do
{
v6 += v12;
libnet_clear_packet();
func11(*(_WORD *)v5);
func11(*((_WORD *)v5 + 1));
libnet_build_tcp();
libnet_get_prand();
libnet_build_ipv4();
if ( (int)libnet_write() < 0 )
warn("write", 0LL);
fprintf(stderr, "%s R %lu:%lu(0) win 0\n", s, v6, v6);
++v10;
v12 += v13;
}
while ( Opt_severity > v10 );
}
result = (unsigned int)(kill_counter + 1);
kill_counter = result;
if ( (int)result >= Opt_max_kill )
{
if ( Opt_max_kill )
result = pcap_breakloop();
}
}
}
return result;
}

original_code:
static void
tcp_kill_cb(u_char *user, const struct pcap_pkthdr *pcap, const u_char *pkt)
{
 struct libnet_ipv4_hdr *ip;
 struct libnet_tcp_hdr *tcp;
 char ctext[64];
 u_int32_t seq, win;
 int i, len;
 libnet_t *l;
 l = (libnet_t *)user;
 pkt += pcap_off;
 len = pcap->caplen - pcap_off;
 ip = (struct libnet_ipv4_hdr *)pkt;
 if (ip->ip_p != IPPROTO_TCP)
  return;
 tcp = (struct libnet_tcp_hdr *)(pkt + (ip->ip_hl << 2));
 if (tcp->th_flags & (0x02|0x01|0x04))
  return;
 seq = ntohl(tcp->th_ack);
 win = ntohs(tcp->th_win);
 snprintf(ctext, sizeof(ctext), "%s:%d > %s:%d:",
   libnet_addr2name4(ip->ip_src.s_addr, 0),
   ntohs(tcp->th_sport),
   libnet_addr2name4(ip->ip_dst.s_addr, 0),
   ntohs(tcp->th_dport));
 for (i = 0; i < Opt_severity; i++) {
  seq += (i * win);
  libnet_clear_packet(l);
  libnet_build_tcp(ntohs(tcp->th_dport), ntohs(tcp->th_sport),
     seq, 0, 0x04, 0, 0, 0, 0x14,
     ((void *)0), 0, l, 0);
  libnet_build_ipv4(0x14 + 0x14, 0,
      libnet_get_prand(3), 0, 64,
      IPPROTO_TCP, 0, ip->ip_dst.s_addr,
      ip->ip_src.s_addr, ((void *)0), 0, l, 0);
  if (libnet_write(l) < 0)
   warn("write");
  fprintf(stderr, "%s R %lu:%lu(0) win 0\n",
                        ctext,
                        (unsigned long) seq,
                        (unsigned long) seq);
 }
        ++kill_counter;
        if (Opt_max_kill && kill_counter >= Opt_max_kill) {
          pcap_breakloop(pd);
        }
}

canonical_original_code:
static void tcp_kill_cb(unsigned char *user, struct pcap_pkthdr *pcap, unsigned char *pkt)
{
 struct libnet_ipv4_hdr *ip;
 struct libnet_tcp_hdr *tcp;
 char ctext[64];
 unsigned int seq; unsigned int win;
 int i; int len;
 struct libnet_context *l;
 l = (struct libnet_context *)user;
 pkt += pcap_off;
 len = pcap->caplen - pcap_off;
 ip = (struct libnet_ipv4_hdr *)pkt;
 if (ip->ip_p != IPPROTO_TCP)
  return;
 tcp = (struct libnet_tcp_hdr *)(pkt + (ip->ip_hl << 2));
 if (tcp->th_flags & (0x02|0x01|0x04))
  return;
 seq = ntohl(tcp->th_ack);
 win = ntohs(tcp->th_win);
 snprintf(ctext, sizeof(ctext), "%s:%d > %s:%d:",
   libnet_addr2name4(ip->ip_src.s_addr, 0),
   ntohs(tcp->th_sport),
   libnet_addr2name4(ip->ip_dst.s_addr, 0),
   ntohs(tcp->th_dport));
 for (i = 0; i < Opt_severity; i++) {
  seq += (i * win);
  libnet_clear_packet(l);
  libnet_build_tcp(ntohs(tcp->th_dport), ntohs(tcp->th_sport),
     seq, 0, 0x04, 0, 0, 0, 0x14,
     ((void *)0), 0, l, 0);
  libnet_build_ipv4(0x14 + 0x14, 0,
      libnet_get_prand(3), 0, 64,
      IPPROTO_TCP, 0, ip->ip_dst.s_addr,
      ip->ip_src.s_addr, ((void *)0), 0, l, 0);
  if (libnet_write(l) < 0)
   warn("write");
  fprintf(stderr, "%s R %lu:%lu(0) win 0\n",
                        ctext,
                        (unsigned long) seq,
                        (unsigned long) seq);
 }
        ++kill_counter;
        if (Opt_max_kill && kill_counter >= Opt_max_kill) {
          pcap_breakloop(pd);
        }
}

variable_types:
user
unsigned char *

variable_types: struct pcap_pkthdr { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int caplen; unsigned int len; } *

variable_types:
pkt
unsigned char *

variable_types: struct libnet_ipv4_hdr { unsigned char ip_hl; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr { unsigned int s_addr; } ip_src; } *

variable_types: struct libnet_tcp_hdr { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; } *

variable_types:
ctext
char [64]

variable_types:
seq
unsigned int

variable_types:
win
unsigned int

variable_types: i int

variable_types: struct libnet_context { int fd; int injection_type; struct libnet_protocol_block { unsigned char *buf; unsigned int b_len; unsigned short h_len; unsigned int copied; unsigned char type; unsigned char flags; int ptag; struct libnet_protocol_block *next; struct libnet_protocol_block *prev; } *protocol_blocks; struct libnet_protocol_block *pblock_end; unsigned int n_pblocks; int link_type; int link_offset; int aligner; char *device; struct libnet_stats { unsigned long packets_sent; unsigned long packet_errors; unsigned long bytes_written; } stats; int ptag_state; char label[64]; char err_buf[256]; unsigned int total_size; } *

user_defined_types: struct pcap_pkthdr { struct timeval ts; unsigned int caplen; unsigned int len; }

user_defined_types: struct libnet_ipv4_hdr { unsigned char ip_hl; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; }

user_defined_types: struct libnet_context { int fd; int injection_type; struct libnet_protocol_block *protocol_blocks; struct libnet_protocol_block *pblock_end; unsigned int n_pblocks; int link_type; int link_offset; int aligner; char *device; struct libnet_stats stats; int ptag_state; char label[64]; char err_buf[256]; unsigned int total_size; }


usage

decompiled_code:
void __noreturn usage()
{
fwrite("Version: 2.4\nUsage: tcpkill [-i interface] [-m max kills] [-1..9] expression\n", 1uLL, 0x4DuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func13()
{
fwrite("Version: 2.4\nUsage: tcpkill [-i interface] [-m max kills] [-1..9] expression\n", 1uLL, 0x4DuLL, stderr);
exit(1);
}

original_code:
static void
usage(void)
{
 fprintf(stderr, "Version: " "2.4" "\n"
  "Usage: tcpkill [-i interface] [-m max kills] [-1..9] expression\n");
 exit(1);
}

canonical_original_code:
static void usage()
{
 fprintf(stderr, "Version: " "2.4" "\n"
  "Usage: tcpkill [-i interface] [-m max kills] [-1..9] expression\n");
 exit(1);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v4; // eax
const char *v5; // rcx
char *v6; // rbx
__int64 v7; // rdi
char v8[280]; // [rsp+100h] [rbp-118h] BYREF

v3 = 0LL;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "i:m:123456789h?V");
if ( v4 == -1 )
{
if ( !v3 )
{
v3 = (const char *)pcap_lookupdev();
if ( !v3 )
errx(1, "%s", v8);
}
if ( optind != argc )
{
v6 = copy_argv(&argv[optind]);
v7 = pcap_init((__int64)v3);
pd = v7;
if ( v7 )
{
pcap_off = pcap_dloff(v7, (__int64)v6);
if ( pcap_off >= 0 )
{
if ( libnet_init() )
{
libnet_seed_prand();
warnx("listening on %s [%s]", v3, v6);
pcap_loop();
exit(0);
}
errx(1, "couldn't initialize sending");
}
errx(1, "couldn't determine link layer offset");
}
errx(1, "couldn't initialize sniffing");
}
usage();
}
if ( v4 != 105 )
break;
v3 = optarg;
}
if ( v4 > 105 )
break;
if ( (unsigned int)(v4 - 48) > 9 )
goto LABEL_14;
v5 = argv[optind - 1];
if ( *v5 == 45 && v5[1] == v4 && !v5[2] )
Opt_severity = atoi(v5 + 1);
else
Opt_severity = atoi(argv[optind] + 1);
}
if ( v4 != 109 )
LABEL_14:
usage();
Opt_max_kill = atoi(optarg);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v4; // eax
const char *v5; // rcx
char *v6; // rbx
__int64 v7; // rdi
char v8[280]; // [rsp+100h] [rbp-118h] BYREF

v3 = 0LL;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "i:m:123456789h?V");
if ( v4 == -1 )
{
if ( !v3 )
{
v3 = (const char *)pcap_lookupdev();
if ( !v3 )
errx(1, "%s", v8);
}
if ( optind != argc )
{
v6 = func9(&argv[optind]);
v7 = func8((__int64)v3);
pd = v7;
if ( v7 )
{
pcap_off = func7(v7, (__int64)v6);
if ( pcap_off >= 0 )
{
if ( libnet_init() )
{
libnet_seed_prand();
warnx("listening on %s [%s]", v3, v6);
pcap_loop();
exit(0);
}
errx(1, "couldn't initialize sending");
}
errx(1, "couldn't determine link layer offset");
}
errx(1, "couldn't initialize sniffing");
}
func13();
}
if ( v4 != 105 )
break;
v3 = optarg;
}
if ( v4 > 105 )
break;
if ( (unsigned int)(v4 - 48) > 9 )
goto LABEL_14;
v5 = argv[optind - 1];
if ( *v5 == 45 && v5[1] == v4 && !v5[2] )
Opt_severity = atoi(v5 + 1);
else
Opt_severity = atoi(argv[optind] + 1);
}
if ( v4 != 109 )
LABEL_14:
func13();
Opt_max_kill = atoi(optarg);
}
}

original_code:
int
main(int argc, char *argv[])
{
 extern char *optarg;
 extern int optind;
 int c;
 char *p, *intf, *filter, ebuf[256];
 char libnet_ebuf[0x100];
 libnet_t *l;
 intf = ((void *)0);
 while ((c = getopt(argc, argv, "i:m:123456789h?V")) != -1) {
  switch (c) {
  case 'i':
   intf = optarg;
   break;
  case 'm':
   Opt_max_kill = atoi(optarg);
   break;
  case '0': case '1': case '2': case '3': case '4':
  case '5': case '6': case '7': case '8': case '9':
   p = argv[optind - 1];
   if (p[0] == '-' && p[1] == c && p[2] == '\0')
    Opt_severity = atoi(++p);
   else
    Opt_severity = atoi(argv[optind] + 1);
   break;
  default:
   usage();
   break;
  }
 }
 if (intf == ((void *)0) && (intf = pcap_lookupdev(ebuf)) == ((void *)0))
  errx(1, "%s", ebuf);
 argc -= optind;
 argv += optind;
 if (argc == 0)
  usage();
 filter = copy_argv(argv);
 if ((pd = pcap_init(intf, filter, 64)) == ((void *)0))
  errx(1, "couldn't initialize sniffing");
 if ((pcap_off = pcap_dloff(pd)) < 0)
  errx(1, "couldn't determine link layer offset");
 if ((l = libnet_init(0x01, intf, libnet_ebuf)) == ((void *)0))
  errx(1, "couldn't initialize sending");
 libnet_seed_prand(l);
 warnx("listening on %s [%s]", intf, filter);
 pcap_loop(pd, -1, tcp_kill_cb, (u_char *)l);
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 extern char *optarg;
 extern int optind;
 int c;
 char *p; char *intf; char *filter; char ebuf[256];
 char libnet_ebuf[256];
 struct libnet_context *l;
 intf = ((void *)0);
 while ((c = getopt(argc, argv, "i:m:123456789h?V")) != -1) {
  switch (c) {
  case 'i':
   intf = optarg;
   break;
  case 'm':
   Opt_max_kill = atoi(optarg);
   break;
  case '0': case '1': case '2': case '3': case '4':
  case '5': case '6': case '7': case '8': case '9':
   p = argv[optind - 1];
   if (p[0] == '-' && p[1] == c && p[2] == '\0')
    Opt_severity = atoi(++p);
   else
    Opt_severity = atoi(argv[optind] + 1);
   break;
  default:
   usage();
   break;
  }
 }
 if (intf == ((void *)0) && (intf = pcap_lookupdev(ebuf)) == ((void *)0))
  errx(1, "%s", ebuf);
 argc -= optind;
 argv += optind;
 if (argc == 0)
  usage();
 filter = copy_argv(argv);
 if ((pd = pcap_init(intf, filter, 64)) == ((void *)0))
  errx(1, "couldn't initialize sniffing");
 if ((pcap_off = pcap_dloff(pd)) < 0)
  errx(1, "couldn't determine link layer offset");
 if ((l = libnet_init(0x01, intf, libnet_ebuf)) == ((void *)0))
  errx(1, "couldn't initialize sending");
 libnet_seed_prand(l);
 warnx("listening on %s [%s]", intf, filter);
 pcap_loop(pd, -1, tcp_kill_cb, (unsigned char *)l);
 exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
optarg
char *

variable_types: optind int

variable_types: c int

variable_types:
p
char *

variable_types:
intf
char *

variable_types:
filter
char *

variable_types:
ebuf
char [256]

user_defined_types: struct libnet_stats { unsigned long packets_sent; unsigned long packet_errors; unsigned long bytes_written; }

user_defined_types: struct libnet_protocol_block { unsigned char *buf; unsigned int b_len; unsigned short h_len; unsigned int copied; unsigned char type; unsigned char flags; int ptag; struct libnet_protocol_block *next; struct libnet_protocol_block *prev; }


decompiled_code:
int f74()
{
return puts("f4");
}

canonical_decompiled_code:
int func0()
{
return puts("f4");
}

original_code:
void f74(void* arg){
    printf("f4\n");
}

canonical_original_code:
void f74(void *arg){
    printf("f4\n");
}

variable_types:
arg
void *


decompiled_code:
int __fastcall f63(unsigned int *a1)
{
unsigned int i; // ebx

printf("Entered thread 3, arg: %d\n", *a1);
for ( i = 0; i != 12; printf("thread3 return from yield, local = %d \n", i) )
{
i += 3;
thread_yield();
}
return puts("thread 3 exiting");
}

canonical_decompiled_code:
int __fastcall func4(unsigned int *a1)
{
unsigned int i; // ebx

printf("Entered thread 3, arg: %d\n", *a1);
for ( i = 0; i != 12; printf("thread3 return from yield, local = %d \n", i) )
{
i += 3;
thread_yield();
}
return puts("thread 3 exiting");
}

original_code:
void f63(int *arg) {
 int local=0;
 printf("Entered thread 3, arg: %d\n",*arg);
 while(1) {
   local=local+3;
      thread_yield();
      printf("thread3 return from yield, local = %d \n",local);
      if (local>10) {
       printf("thread 3 exiting\n");
       break;
      }
 }
}

canonical_original_code:
void f63(int *arg) {
 int local = 0;
 printf("Entered thread 3, arg: %d\n",*arg);
 while(1) {
   local=local+3;
      thread_yield();
      printf("thread3 return from yield, local = %d \n",local);
      if (local>10) {
       printf("thread 3 exiting\n");
       break;
      }
 }
}

variable_types:
arg
int *

variable_types: local int


decompiled_code:
int __fastcall f61(unsigned int *a1)
{
unsigned int i; // ebx

printf("Entered thread 1, arg: %d\n", *a1);
for ( i = 0; i != 11; printf("thread1 return from yield, local = %d \n", i) )
{
++i;
thread_yield();
}
return puts("thread 1 exiting");
}

canonical_decompiled_code:
int __fastcall func5(unsigned int *a1)
{
unsigned int i; // ebx

printf("Entered thread 1, arg: %d\n", *a1);
for ( i = 0; i != 11; printf("thread1 return from yield, local = %d \n", i) )
{
++i;
thread_yield();
}
return puts("thread 1 exiting");
}

original_code:
void f61(int *arg) {
    printf("Entered thread 1, arg: %d\n",*arg);
    int local=0;
    while(1) {
     local++;
     thread_yield();
     printf("thread1 return from yield, local = %d \n",local);
     if (local>10) {
        printf("thread 1 exiting\n");
        break;
     }
    }
}

canonical_original_code:
void f61(int *arg) {
    printf("Entered thread 1, arg: %d\n",*arg);
    int local = 0;
    while(1) {
     local++;
     thread_yield();
     printf("thread1 return from yield, local = %d \n",local);
     if (local>10) {
        printf("thread 1 exiting\n");
        break;
     }
    }
}


decompiled_code:
int __fastcall f53(unsigned int *a1)
{
printf("Entered thread 3, arg: %d\n", *a1);
return puts("thread 3 exiting");
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1)
{
printf("Entered thread 3, arg: %d\n", *a1);
return puts("thread 3 exiting");
}

original_code:
void f53(int *arg) {
 printf("Entered thread 3, arg: %d\n",*arg);
 printf("thread 3 exiting\n");
}


decompiled_code:
int __fastcall f52(unsigned int *a1)
{
printf("Entered thread 2, arg: %d\n", *a1);
return puts("thread 2 exiting");
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1)
{
printf("Entered thread 2, arg: %d\n", *a1);
return puts("thread 2 exiting");
}

original_code:
void f52(int *arg) {
 printf("Entered thread 2, arg: %d\n",*arg);
 printf("thread 2 exiting\n");
}


decompiled_code:
int __fastcall f51(unsigned int *a1)
{
printf("Entered thread 1, arg: %d\n", *a1);
return puts("thread 1 exiting");
}

canonical_decompiled_code:
int __fastcall func8(unsigned int *a1)
{
printf("Entered thread 1, arg: %d\n", *a1);
return puts("thread 1 exiting");
}

original_code:
void f51(int *arg) {
    printf("Entered thread 1, arg: %d\n",*arg);
    printf("thread 1 exiting\n");
}


decompiled_code:
void __noreturn f31()
{
unsigned int i; // ebx

printf("thread 1: %d\n", 100LL);
for ( i = 101; ; i = 100 )
{
do
{
thread_yield();
printf("thread 1: %d\n", i++);
}
while ( i != 110 );
}
}

canonical_decompiled_code:
void __noreturn func9()
{
unsigned int i; // ebx

printf("thread 1: %d\n", 100LL);
for ( i = 101; ; i = 100 )
{
do
{
thread_yield();
printf("thread 1: %d\n", i++);
}
while ( i != 110 );
}
}

original_code:
void f31(void *arg)
{
    int i = 100;
    while(1) {
        printf("thread 1: %d\n", i++);
        if (i == 110) {
            i = 100;
        }
        thread_yield();
    }
}


decompiled_code:
int __fastcall f23(unsigned int *a1)
{
unsigned int i; // ebx

printf("Entered thread 3, arg: %d\n", *a1);
for ( i = 0; i != 51; printf("thread3 return from yield, local = %d \n", i) )
{
i += 3;
thread_yield();
}
return puts("thread 3 exiting");
}

canonical_decompiled_code:
int __fastcall func10(unsigned int *a1)
{
unsigned int i; // ebx

printf("Entered thread 3, arg: %d\n", *a1);
for ( i = 0; i != 51; printf("thread3 return from yield, local = %d \n", i) )
{
i += 3;
thread_yield();
}
return puts("thread 3 exiting");
}

original_code:
void f23(int *arg) {
 int local=0;
 printf("Entered thread 3, arg: %d\n",*arg);
 while(1) {
   local=local+3;
      thread_yield();
      printf("thread3 return from yield, local = %d \n",local);
      if (local>50) {
       printf("thread 3 exiting\n");
       break;
      }
 }
}

canonical_original_code:
void f23(int *arg) {
 int local = 0;
 printf("Entered thread 3, arg: %d\n",*arg);
 while(1) {
   local=local+3;
      thread_yield();
      printf("thread3 return from yield, local = %d \n",local);
      if (local>50) {
       printf("thread 3 exiting\n");
       break;
      }
 }
}


decompiled_code:
int __fastcall f22(unsigned int *a1)
{
printf("Entered thread 2, arg: %d\n", *a1);
thread_yield();
printf("thread2 return from yield, local = %d \n", 2LL);
thread_yield();
printf("thread2 return from yield, local = %d \n", 4LL);
return puts("thread 2 exiting");
}

canonical_decompiled_code:
int __fastcall func11(unsigned int *a1)
{
printf("Entered thread 2, arg: %d\n", *a1);
thread_yield();
printf("thread2 return from yield, local = %d \n", 2LL);
thread_yield();
printf("thread2 return from yield, local = %d \n", 4LL);
return puts("thread 2 exiting");
}

original_code:
void f22(int *arg) {
 int local=0;
 printf("Entered thread 2, arg: %d\n",*arg);
 while(1) {
   local=local+2;
      thread_yield();
      printf("thread2 return from yield, local = %d \n",local);
      if (local>3) {
       printf("thread 2 exiting\n");
       break;
      }
 }
}

canonical_original_code:
void f22(int *arg) {
 int local = 0;
 printf("Entered thread 2, arg: %d\n",*arg);
 while(1) {
   local=local+2;
      thread_yield();
      printf("thread2 return from yield, local = %d \n",local);
      if (local>3) {
       printf("thread 2 exiting\n");
       break;
      }
 }
}


decompiled_code:
int __fastcall f21(unsigned int *a1)
{
printf("Entered thread 1, arg: %d\n", *a1);
return puts("thread 1 exiting");
}

canonical_decompiled_code:
int __fastcall func12(unsigned int *a1)
{
printf("Entered thread 1, arg: %d\n", *a1);
return puts("thread 1 exiting");
}

original_code:
void f21(int *arg) {
    printf("Entered thread 1, arg: %d\n",*arg);
    printf("thread 1 exiting\n");
}


decompiled_code:
void __noreturn f13()
{
__int64 i; // rsi

for ( i = 0LL; ; i = (unsigned int)(i + 1) )
{
printf("thread 3: %d\n", i);
thread_yield();
}
}

canonical_decompiled_code:
void __noreturn func13()
{
__int64 i; // rsi

for ( i = 0LL; ; i = (unsigned int)(i + 1) )
{
printf("thread 3: %d\n", i);
thread_yield();
}
}

original_code:
void f13(void *arg)
{
    int i=0;
    while (1) {
        printf("thread 3: %d\n", i++);
        thread_yield();
    }
}

canonical_original_code:
void f13(void *arg)
{
    int i = 0;
    while (1) {
        printf("thread 3: %d\n", i++);
        thread_yield();
    }
}


decompiled_code:
void __noreturn f12()
{
unsigned int i; // ebx

printf("thread 2: %d\n", 0LL);
for ( i = 1; ; i = 0 )
{
do
{
thread_yield();
printf("thread 2: %d\n", i++);
}
while ( i != 10 );
}
}

canonical_decompiled_code:
void __noreturn func14()
{
unsigned int i; // ebx

printf("thread 2: %d\n", 0LL);
for ( i = 1; ; i = 0 )
{
do
{
thread_yield();
printf("thread 2: %d\n", i++);
}
while ( i != 10 );
}
}

original_code:
void f12(void *arg)
{
    int i = 0;
    while(1) {
        printf("thread 2: %d\n",i++);
        if (i == 10) {
            i = 0;
        }
        thread_yield();
    }
}


decompiled_code:
int __fastcall f62(unsigned int *a1)
{
printf("Entered thread 2, arg: %d\n", *a1);
thread_yield();
printf("thread2 return from yield, local = %d \n", 2LL);
puts("thread 2 exiting through thread_exit");
thread_exit();
return puts("don't want to come here after thread_exit");
}

canonical_decompiled_code:
int __fastcall func16(unsigned int *a1)
{
printf("Entered thread 2, arg: %d\n", *a1);
thread_yield();
printf("thread2 return from yield, local = %d \n", 2LL);
puts("thread 2 exiting through thread_exit");
thread_exit();
return puts("don't want to come here after thread_exit");
}

original_code:
void f62(int *arg) {
 int local=0;
 printf("Entered thread 2, arg: %d\n",*arg);
 while(1) {
   local=local+2;
      thread_yield();
      printf("thread2 return from yield, local = %d \n",local);
      if (local>1) {
       printf("thread 2 exiting through thread_exit\n");
       thread_exit();
       printf("don't want to come here after thread_exit\n");
       break;
      }
 }
}

canonical_original_code:
void f62(int *arg) {
 int local = 0;
 printf("Entered thread 2, arg: %d\n",*arg);
 while(1) {
   local=local+2;
      thread_yield();
      printf("thread2 return from yield, local = %d \n",local);
      if (local>1) {
       printf("thread 2 exiting through thread_exit\n");
       thread_exit();
       printf("don't want to come here after thread_exit\n");
       break;
      }
 }
}


decompiled_code:
int test4()
{
puts("no threads added, but start threading");
thread_start_threading();
return puts("exited");
}

canonical_decompiled_code:
int func20()
{
puts("no threads added, but start threading");
thread_start_threading();
return puts("exited");
}

original_code:
void test4() {
 printf("no threads added, but start threading\n");
 thread_start_threading();
 printf("exited\n");
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 2;
while ( 1 )
{
puts("type test number");
_isoc99_scanf("%d", v4);
switch ( v4[0] )
{
case 1:
test1();
break;
case 2:
test2();
break;
case 3:
test3();
break;
case 4:
test4();
break;
case 5:
test5();
break;
case 6:
test6();
break;
case 7:
test7();
break;
default:
puts("exiting program");
break;
}
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 2;
while ( 1 )
{
puts("type test number");
_isoc99_scanf("%d", v4);
switch ( v4[0] )
{
case 1:
func23();
break;
case 2:
func22();
break;
case 3:
func21();
break;
case 4:
func20();
break;
case 5:
func19();
break;
case 6:
func18();
break;
case 7:
func17();
break;
default:
puts("exiting program");
break;
}
}
}

original_code:
int main(int argc, char **argv)
{
 int test_number;
 test_number=2;
 while (1) {
  printf("type test number\n");
  scanf("%d", &test_number);
  switch(test_number) {
      case 1 :
       test1();
       break;
      case 2 :
       test2();
       break;
      case 3 :
       test3();
       break;
      case 4 :
       test4();
       break;
      case 5 :
       test5();
       break;
      case 6 :
       test6();
       break;
      case 7 :
       test7();
       break;
      default :
       printf("exiting program\n");
       break;
  }
 }
}

variable_types:
argv
char **


decompiled_code:
void __fastcall thread_add_runqueue(_QWORD *a1)
{
_QWORD *v1; // rax
__int64 v2; // rax

if ( first_thread )
{
v1 = current_thread;
if ( (void *)first_thread == current_thread )
{
v2 = last_thread;
a1[32] = last_thread;
*(_QWORD *)(v2 + 264) = a1;
last_thread = (__int64)a1;
}
else
{
*(_QWORD *)(*((_QWORD *)current_thread + 32) + 264LL) = a1;
a1[32] = v1[32];
v1[32] = a1;
a1[33] = v1;
}
}
else
{
current_thread = a1;
first_thread = (__int64)a1;
last_thread = (__int64)a1;
}
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1)
{
_QWORD *v1; // rax
__int64 v2; // rax

if ( first_thread )
{
v1 = current_thread;
if ( (void *)first_thread == current_thread )
{
v2 = last_thread;
a1[32] = last_thread;
*(_QWORD *)(v2 + 264) = a1;
last_thread = (__int64)a1;
}
else
{
*(_QWORD *)(*((_QWORD *)current_thread + 32) + 264LL) = a1;
a1[32] = v1[32];
v1[32] = a1;
a1[33] = v1;
}
}
else
{
current_thread = a1;
first_thread = (__int64)a1;
last_thread = (__int64)a1;
}
}

original_code:
void thread_add_runqueue(struct thread *t)
{
 if (first_thread==((void *)0)){
  current_thread=t;
  first_thread=t;
  last_thread=t;
  return;
 }
 if (current_thread==first_thread){
  t->prev=last_thread;
  last_thread->next=t;
  last_thread=t;
  return;
 }
 current_thread->prev->next=t;
 t->prev=current_thread->prev;
 current_thread->prev=t;
 t->next=current_thread;
}

variable_types: struct thread { int threadid; void *arg; void (*f)(void *arg); int first_time; unsigned char *esp; unsigned char *ebp; struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } buf[1]; unsigned char *stack; struct thread *prev; struct thread *next; } *

user_defined_types: struct thread { int threadid; void *arg; void (*f)(void *arg); int first_time; unsigned char *esp; unsigned char *ebp; struct __jmp_buf_tag buf[1]; unsigned char *stack; struct thread *prev; struct thread *next; }

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


schedule

decompiled_code:
void schedule()
{
void *v0; // rax

if ( first_thread )
{
v0 = (void *)*((_QWORD *)current_thread + 33);
if ( !v0 )
v0 = (void *)first_thread;
current_thread = v0;
}
else
{
current_thread = 0LL;
}
}

canonical_decompiled_code:
void func2()
{
void *v0; // rax

if ( first_thread )
{
v0 = (void *)*((_QWORD *)current_thread + 33);
if ( !v0 )
v0 = (void *)first_thread;
current_thread = v0;
}
else
{
current_thread = 0LL;
}
}

original_code:
void schedule(void)
{
 if (first_thread==((void *)0)){
  current_thread=((void *)0);
  return;
 }
 if (current_thread->next==((void *)0)){
  current_thread=first_thread;
  return;
 }
 current_thread=current_thread->next;
}

canonical_original_code:
void schedule()
{
 if (first_thread==((void *)0)){
  current_thread=((void *)0);
  return;
 }
 if (current_thread->next==((void *)0)){
  current_thread=first_thread;
  return;
 }
 current_thread=current_thread->next;
}


decompiled_code:
void __noreturn thread_exit()
{
longjmp(main_buf, 1);
}

canonical_decompiled_code:
void __noreturn func4()
{
longjmp(main_buf, 1);
}

original_code:
void thread_exit (void){
 longjmp(main_buf,1);
}

canonical_original_code:
void thread_exit(){
 longjmp(main_buf,1);
}


decompiled_code:
void thread_terminate()
{
void *v0; // rbx
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax

v0 = current_thread;
v1 = *((_QWORD *)current_thread + 32);
if ( v1 )
{
*(_QWORD *)(v1 + 264) = *((_QWORD *)current_thread + 33);
v2 = *((_QWORD *)v0 + 33);
if ( v2 )
goto LABEL_3;
v3 = *((_QWORD *)v0 + 32);
if ( v3 )
goto LABEL_7;
}
else
{
v2 = *((_QWORD *)current_thread + 33);
if ( v2 )
{
LABEL_3:
*(_QWORD *)(v2 + 256) = *((_QWORD *)v0 + 32);
v3 = *((_QWORD *)v0 + 32);
if ( v3 )
goto LABEL_4;
goto LABEL_9;
}
}
LABEL_9:
first_thread = *((_QWORD *)v0 + 33);
v3 = 0LL;
LABEL_4:
if ( !*((_QWORD *)v0 + 33) )
LABEL_7:
last_thread = v3;
schedule();
free(*((void **)v0 + 31));
free(v0);
}

canonical_decompiled_code:
void func5()
{
void *v0; // rbx
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax

v0 = current_thread;
v1 = *((_QWORD *)current_thread + 32);
if ( v1 )
{
*(_QWORD *)(v1 + 264) = *((_QWORD *)current_thread + 33);
v2 = *((_QWORD *)v0 + 33);
if ( v2 )
goto LABEL_3;
v3 = *((_QWORD *)v0 + 32);
if ( v3 )
goto LABEL_7;
}
else
{
v2 = *((_QWORD *)current_thread + 33);
if ( v2 )
{
LABEL_3:
*(_QWORD *)(v2 + 256) = *((_QWORD *)v0 + 32);
v3 = *((_QWORD *)v0 + 32);
if ( v3 )
goto LABEL_4;
goto LABEL_9;
}
}
LABEL_9:
first_thread = *((_QWORD *)v0 + 33);
v3 = 0LL;
LABEL_4:
if ( !*((_QWORD *)v0 + 33) )
LABEL_7:
last_thread = v3;
func2();
free(*((void **)v0 + 31));
free(v0);
}

original_code:
void thread_terminate(void)
{
 if (current_thread->prev!=((void *)0))
  (current_thread->prev)->next=current_thread->next;
 if (current_thread->next!=((void *)0))
  (current_thread->next)->prev=current_thread->prev;
 if (current_thread->prev==((void *)0))
  first_thread=current_thread->next;
 if (current_thread->next==((void *)0))
  last_thread=current_thread->prev;
 struct thread* saved_thread=current_thread;
 schedule();
 free(saved_thread->stack);
 free(saved_thread);
}

canonical_original_code:
void thread_terminate()
{
 if (current_thread->prev!=((void *)0))
  (current_thread->prev)->next=current_thread->next;
 if (current_thread->next!=((void *)0))
  (current_thread->next)->prev=current_thread->prev;
 if (current_thread->prev==((void *)0))
  first_thread=current_thread->next;
 if (current_thread->next==((void *)0))
  last_thread=current_thread->prev;
 struct thread *saved_thread = current_thread;
 schedule();
 free(saved_thread->stack);
 free(saved_thread);
}

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }


checkSupplies

decompiled_code:
int checkSupplies()
{
char *v0; // rax
int v1; // ebx
char *v2; // rax
int v3; // ebp
char *v4; // rax
int result; // eax

v0 = getenv("PAPER");
v1 = atoi(v0);
v2 = getenv("TOBACCO");
v3 = atoi(v2);
v4 = getenv("MATCHES");
if ( v1 <= 0 )
{
puts("NO PAPER!\n");
fflush(_bss_start);
exit(0);
}
if ( v3 <= 0 )
{
puts("NO TOBACCO!\n");
fflush(_bss_start);
exit(0);
}
result = atoi(v4);
if ( result <= 0 )
{
puts("NO MATCHES!\n");
fflush(_bss_start);
exit(0);
}
return result;
}

canonical_decompiled_code:
int func7()
{
char *v0; // rax
int v1; // ebx
char *v2; // rax
int v3; // ebp
char *v4; // rax
int result; // eax

v0 = getenv("PAPER");
v1 = atoi(v0);
v2 = getenv("TOBACCO");
v3 = atoi(v2);
v4 = getenv("MATCHES");
if ( v1 <= 0 )
{
puts("NO PAPER!\n");
fflush(_bss_start);
exit(0);
}
if ( v3 <= 0 )
{
puts("NO TOBACCO!\n");
fflush(_bss_start);
exit(0);
}
result = atoi(v4);
if ( result <= 0 )
{
puts("NO MATCHES!\n");
fflush(_bss_start);
exit(0);
}
return result;
}

original_code:
void checkSupplies()
{
 char * paperStr = getenv("PAPER");
 int paper = atoi(paperStr);
 char * tobaccoStr = getenv("TOBACCO");
 int tobacco = atoi(tobaccoStr);
 char * matchesStr = getenv("MATCHES");
 int matches = atoi(matchesStr);
 if (paper <= 0) {
  printf("NO PAPER!\n\n");
  fflush(stdout);
  exit(0);
 } else if (tobacco <= 0) {
  printf("NO TOBACCO!\n\n");
  fflush(stdout);
  exit(0);
 } else if (matches <= 0) {
  printf("NO MATCHES!\n\n");
  fflush(stdout);
  exit(0);
 }
}

canonical_original_code:
void checkSupplies()
{
 char *paperStr = getenv("PAPER");
 int paper = atoi(paperStr);
 char *tobaccoStr = getenv("TOBACCO");
 int tobacco = atoi(tobaccoStr);
 char *matchesStr = getenv("MATCHES");
 int matches = atoi(matchesStr);
 if (paper <= 0) {
  printf("NO PAPER!\n\n");
  fflush(stdout);
  exit(0);
 } else if (tobacco <= 0) {
  printf("NO TOBACCO!\n\n");
  fflush(stdout);
  exit(0);
 } else if (matches <= 0) {
  printf("NO MATCHES!\n\n");
  fflush(stdout);
  exit(0);
 }
}

variable_types:
paperStr
char *

variable_types: paper int

variable_types:
tobaccoStr
char *

variable_types: tobacco int

variable_types:
matchesStr
char *

variable_types: matches int


listAvaliable

decompiled_code:
int listAvaliable()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax

v0 = getenv("PAPER");
printf("PAPER IS AVAILABLE! P:%s\n", v0);
v1 = getenv("TOBACCO");
printf("TOBACCO IS AVAILABLE! T:%s\n", v1);
v2 = getenv("MATCHES");
return printf("MATCHES ARE AVAILABLE! M:%s\n", v2);
}

canonical_decompiled_code:
int func8()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax

v0 = getenv("PAPER");
printf("PAPER IS AVAILABLE! P:%s\n", v0);
v1 = getenv("TOBACCO");
printf("TOBACCO IS AVAILABLE! T:%s\n", v1);
v2 = getenv("MATCHES");
return printf("MATCHES ARE AVAILABLE! M:%s\n", v2);
}

original_code:
void listAvaliable()
{
 printf("PAPER IS AVAILABLE! P:%s\n", getenv("PAPER"));
 printf("TOBACCO IS AVAILABLE! T:%s\n", getenv("TOBACCO"));
 printf("MATCHES ARE AVAILABLE! M:%s\n", getenv("MATCHES"));
}


printInfo

decompiled_code:
int printInfo()
{
unsigned int v0; // eax
__uid_t v1; // eax
char *v2; // rax
char *v3; // rbp
char *v4; // rbx
char *v5; // rax
time_t timer; // [rsp+8h] [rbp-120h] BYREF
char name[280]; // [rsp+10h] [rbp-118h] BYREF

puts("AGENT INFO:");
gethostname(name, 0x100uLL);
printf("HOSTNAME:%s\n", name);
v0 = getpid();
printf("PID:%d\n", v0);
v1 = getuid();
printf("UID:%d\n", v1);
time(&timer);
v2 = ctime(&timer);
printf("TIME:%s\n", v2);
v3 = getenv("MATCHES");
v4 = getenv("TOBACCO");
v5 = getenv("PAPER");
return printf("PAPER:%s, TOBACCO:%s, MATCHES:%s\n", v5, v4, v3);
}

canonical_decompiled_code:
int func9()
{
unsigned int v0; // eax
__uid_t v1; // eax
char *v2; // rax
char *v3; // rbp
char *v4; // rbx
char *v5; // rax
time_t timer; // [rsp+8h] [rbp-120h] BYREF
char name[280]; // [rsp+10h] [rbp-118h] BYREF

puts("AGENT INFO:");
gethostname(name, 0x100uLL);
printf("HOSTNAME:%s\n", name);
v0 = getpid();
printf("PID:%d\n", v0);
v1 = getuid();
printf("UID:%d\n", v1);
time(&timer);
v2 = ctime(&timer);
printf("TIME:%s\n", v2);
v3 = getenv("MATCHES");
v4 = getenv("TOBACCO");
v5 = getenv("PAPER");
return printf("PAPER:%s, TOBACCO:%s, MATCHES:%s\n", v5, v4, v3);
}

original_code:
void printInfo()
{
 printf("AGENT INFO:\n");
 char hostName[256];
 gethostname(hostName, sizeof(hostName));
 printf("HOSTNAME:%s\n", hostName);
 printf("PID:%d\n", getpid());
 printf("UID:%d\n", getuid());
 time_t now;
 time(&now);
 printf("TIME:%s\n", ctime(&now));
 printf("PAPER:%s, TOBACCO:%s, MATCHES:%s\n", getenv("PAPER"), getenv("TOBACCO"), getenv("MATCHES"));
}

canonical_original_code:
void printInfo()
{
 printf("AGENT INFO:\n");
 char hostName[256];
 gethostname(hostName, sizeof(hostName));
 printf("HOSTNAME:%s\n", hostName);
 printf("PID:%d\n", getpid());
 printf("UID:%d\n", getuid());
 long now;
 time(&now);
 printf("TIME:%s\n", ctime(&now));
 printf("PAPER:%s, TOBACCO:%s, MATCHES:%s\n", getenv("PAPER"), getenv("TOBACCO"), getenv("MATCHES"));
}

variable_types:
hostName
char [256]

variable_types: now long


initializeSuplies

decompiled_code:
int __fastcall initializeSuplies(unsigned int a1, unsigned int a2, unsigned int a3)
{
char v5[10]; // [rsp+2h] [rbp-36h] BYREF
char value[10]; // [rsp+Ch] [rbp-2Ch] BYREF
char s[34]; // [rsp+16h] [rbp-22h] BYREF

snprintf(s, 0xAuLL, "%d", a1);
setenv("PAPER", s, 1);
snprintf(value, 0xAuLL, "%d", a2);
setenv("TOBACCO", value, 1);
snprintf(v5, 0xAuLL, "%d", a3);
return setenv("MATCHES", v5, 1);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1, unsigned int a2, unsigned int a3)
{
char v5[10]; // [rsp+2h] [rbp-36h] BYREF
char value[10]; // [rsp+Ch] [rbp-2Ch] BYREF
char s[34]; // [rsp+16h] [rbp-22h] BYREF

snprintf(s, 0xAuLL, "%d", a1);
setenv("PAPER", s, 1);
snprintf(value, 0xAuLL, "%d", a2);
setenv("TOBACCO", value, 1);
snprintf(v5, 0xAuLL, "%d", a3);
return setenv("MATCHES", v5, 1);
}

original_code:
void initializeSuplies(int paper, int tobacco, int matches)
{
 char paperBuffer[10];
 snprintf(paperBuffer, 10, "%d", paper);
 setenv("PAPER", paperBuffer, 1);
 char tobaccoBuffer[10];
 snprintf(tobaccoBuffer, 10, "%d", tobacco);
 setenv("TOBACCO", tobaccoBuffer, 1);
 char matchesBuffer[10];
 snprintf(matchesBuffer, 10, "%d", matches);
 setenv("MATCHES", matchesBuffer, 1);
}

variable_types:
paperBuffer
char [10]

variable_types:
tobaccoBuffer
char [10]

variable_types:
matchesBuffer
char [10]


consume

decompiled_code:
int consume()
{
char *v0; // rax
int v1; // eax
char *v2; // rax
int v3; // eax
char *v4; // rax
int v5; // eax
char v7[10]; // [rsp+2h] [rbp-26h] BYREF
char value[10]; // [rsp+Ch] [rbp-1Ch] BYREF
char s[18]; // [rsp+16h] [rbp-12h] BYREF

v0 = getenv("PAPER");
v1 = atoi(v0);
snprintf(s, 0xAuLL, "%d", (unsigned int)(v1 - 1));
setenv("PAPER", s, 1);
v2 = getenv("TOBACCO");
v3 = atoi(v2);
snprintf(value, 0xAuLL, "%d", (unsigned int)(v3 - 1));
setenv("TOBACCO", value, 1);
v4 = getenv("MATCHES");
v5 = atoi(v4);
snprintf(v7, 0xAuLL, "%d", (unsigned int)(v5 - 1));
return setenv("MATCHES", v7, 1);
}

canonical_decompiled_code:
int func11()
{
char *v0; // rax
int v1; // eax
char *v2; // rax
int v3; // eax
char *v4; // rax
int v5; // eax
char v7[10]; // [rsp+2h] [rbp-26h] BYREF
char value[10]; // [rsp+Ch] [rbp-1Ch] BYREF
char s[18]; // [rsp+16h] [rbp-12h] BYREF

v0 = getenv("PAPER");
v1 = atoi(v0);
snprintf(s, 0xAuLL, "%d", (unsigned int)(v1 - 1));
setenv("PAPER", s, 1);
v2 = getenv("TOBACCO");
v3 = atoi(v2);
snprintf(value, 0xAuLL, "%d", (unsigned int)(v3 - 1));
setenv("TOBACCO", value, 1);
v4 = getenv("MATCHES");
v5 = atoi(v4);
snprintf(v7, 0xAuLL, "%d", (unsigned int)(v5 - 1));
return setenv("MATCHES", v7, 1);
}

original_code:
void consume()
{
 char *paperStr = getenv("PAPER");
 int paper = atoi(paperStr) - 1;
 char paperBuffer[10];
 snprintf(paperBuffer, 10, "%d", paper);
 setenv("PAPER", paperBuffer, 1);
 char *tobaccoStr = getenv("TOBACCO");
 int tobacco = atoi(tobaccoStr) - 1;
 char tobaccoBuffer[10];
 snprintf(tobaccoBuffer, 10, "%d", tobacco);
 setenv("TOBACCO", tobaccoBuffer, 1);
 char *matchesStr = getenv("MATCHES");
 int matches = atoi(matchesStr) - 1;
 char matchesBuffer[10];
 snprintf(matchesBuffer, 10, "%d", matches);
 setenv("MATCHES", matchesBuffer, 1);
}


wait

decompiled_code:
unsigned int wait()
{
return sleep(2u);
}

canonical_decompiled_code:
unsigned int func12()
{
return sleep(2u);
}

original_code:
void wait()
{
 sleep(2);
}

canonical_original_code:
void wait()
{
 sleep(2);
}


smoke

decompiled_code:
int smoke()
{
checkSupplies();
listAvaliable();
return puts("SMOKING!\n");
}

canonical_decompiled_code:
int func13()
{
func7();
func8();
return puts("SMOKING!\n");
}

original_code:
void smoke()
{
 checkSupplies();
 listAvaliable();
 printf("SMOKING!\n\n");
}


forkSmokers

decompiled_code:
void forkSmokers()
{
__pid_t v0; // eax
__pid_t v1; // eax
__pid_t v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax

puts("FORKING THREE SMOKERS!\n");
v0 = fork();
if ( !v0 )
{
v3 = getpid();
printf("SMOKER S1:%d\n", v3);
smoke();
fflush(_bss_start);
exit(0);
}
if ( v0 < 0 )
{
perror("Failed to fork");
}
else
{
wait();
consume();
v1 = fork();
if ( !v1 )
{
v4 = getpid();
printf("SMOKER S2:%d\n", v4);
smoke();
fflush(_bss_start);
exit(0);
}
if ( v1 < 0 )
goto LABEL_7;
wait();
consume();
v2 = fork();
if ( !v2 )
{
v5 = getpid();
printf("SMOKER S3:%d\n", v5);
smoke();
fflush(_bss_start);
exit(0);
}
if ( v2 < 0 )
LABEL_7:
perror("Failed to fork");
}
}

canonical_decompiled_code:
void func14()
{
__pid_t v0; // eax
__pid_t v1; // eax
__pid_t v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax

puts("FORKING THREE SMOKERS!\n");
v0 = fork();
if ( !v0 )
{
v3 = getpid();
printf("SMOKER S1:%d\n", v3);
func13();
fflush(_bss_start);
exit(0);
}
if ( v0 < 0 )
{
perror("Failed to fork");
}
else
{
func12();
func11();
v1 = fork();
if ( !v1 )
{
v4 = getpid();
printf("SMOKER S2:%d\n", v4);
func13();
fflush(_bss_start);
exit(0);
}
if ( v1 < 0 )
goto LABEL_7;
func12();
func11();
v2 = fork();
if ( !v2 )
{
v5 = getpid();
printf("SMOKER S3:%d\n", v5);
func13();
fflush(_bss_start);
exit(0);
}
if ( v2 < 0 )
LABEL_7:
perror("Failed to fork");
}
}

original_code:
void forkSmokers()
{
 printf("FORKING THREE SMOKERS!\n\n");
 pid_t S1 = fork();
 if (S1 == 0) {
  printf("SMOKER S1:%d\n", getpid());
  smoke();
  fflush(stdout);
  exit(0);
 } else if (S1 < 0) {
  perror("Failed to fork");
 } else {
  wait();
  consume();
  pid_t S2 = fork();
  if (S2 == 0) {
   printf("SMOKER S2:%d\n", getpid());
   smoke();
   fflush(stdout);
   exit(0);
  } else if (S2 < 0) {
   perror("Failed to fork");
  } else {
   wait();
   consume();
   pid_t S3 = fork();
   if (S3 == 0) {
    printf("SMOKER S3:%d\n", getpid());
    smoke();
    fflush(stdout);
    exit(0);
   } else if (S3 < 0) {
    perror("Failed to fork");
   }
  }
 }
}

canonical_original_code:
void forkSmokers()
{
 printf("FORKING THREE SMOKERS!\n\n");
 int S1 = fork();
 if (S1 == 0) {
  printf("SMOKER S1:%d\n", getpid());
  smoke();
  fflush(stdout);
  exit(0);
 } else if (S1 < 0) {
  perror("Failed to fork");
 } else {
  wait();
  consume();
  int S2 = fork();
  if (S2 == 0) {
   printf("SMOKER S2:%d\n", getpid());
   smoke();
   fflush(stdout);
   exit(0);
  } else if (S2 < 0) {
   perror("Failed to fork");
  } else {
   wait();
   consume();
   int S3 = fork();
   if (S3 == 0) {
    printf("SMOKER S3:%d\n", getpid());
    smoke();
    fflush(stdout);
    exit(0);
   } else if (S3 < 0) {
    perror("Failed to fork");
   }
  }
 }
}


smokeScenario

decompiled_code:
int __fastcall smokeScenario(unsigned int a1, unsigned int a2, unsigned int a3)
{
initializeSuplies(a1, a2, a3);
printInfo();
forkSmokers();
wait();
return puts("AGENT IS DONE!\n-----");
}

canonical_decompiled_code:
int __fastcall func15(unsigned int a1, unsigned int a2, unsigned int a3)
{
func10(a1, a2, a3);
func9();
func14();
func12();
return puts("AGENT IS DONE!\n-----");
}

original_code:
void smokeScenario(int paper, int tobacco, int matches)
{
 initializeSuplies(paper, tobacco, matches);
 printInfo();
 forkSmokers();
 wait();
 printf("AGENT IS DONE!\n-----\n");
}