decompiled_code:
_BOOL8 __fastcall match_source(__int64 a1, __int64 a2, unsigned __int16 a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_QWORD *)a1 == a2 )
result = *(_WORD *)(a1 + 8) == a3;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1, __int64 a2, unsigned __int16 a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_QWORD *)a1 == a2 )
result = *(_WORD *)(a1 + 8) == a3;
return result;
}

original_code:
int match_source(source_t* source, u_long ip, u_short port)
{
    if (source->ip == ip && source->port == port) {
        return 1;
    } else {
        return 0;
    }
}

canonical_original_code:
int match_source(struct source_s *source, unsigned long ip, unsigned short port)
{
    if (source->ip == ip && source->port == port) {
        return 1;
    } else {
        return 0;
    }
}

variable_types: struct source_s { unsigned long ip; unsigned short port; unsigned char mac[6]; unsigned long seq; struct packet_s { unsigned long seq; unsigned char *data; int len; struct packet_s *next; } *packets; } *

variable_types:
ip
unsigned long

variable_types:
port
unsigned short

user_defined_types: struct source_s { unsigned long ip; unsigned short port; unsigned char mac[6]; unsigned long seq; struct packet_s *packets; }


decompiled_code:
void __fastcall insert_packet(__int64 a1, unsigned __int64 *a2)
{
unsigned __int64 v2; // rdx
unsigned __int64 *v3; // rax
unsigned __int64 *v4; // rcx

v2 = *a2;
if ( *a2 >= *(_QWORD *)(a1 + 16) )
{
v3 = *(unsigned __int64 **)(a1 + 24);
if ( !v3 )
{
LABEL_5:
*(_QWORD *)(a1 + 24) = a2;
return;
}
if ( v2 < *v3 )
{
a2[3] = (unsigned __int64)v3;
goto LABEL_5;
}
if ( v2 > *v3 )
{
do
{
v4 = v3;
v3 = (unsigned __int64 *)v3[3];
if ( !v3 )
goto LABEL_10;
}
while ( v2 > *v3 );
if ( v2 < *v3 )
{
LABEL_10:
a2[3] = (unsigned __int64)v3;
v4[3] = (unsigned __int64)a2;
return;
}
}
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, unsigned __int64 *a2)
{
unsigned __int64 v2; // rdx
unsigned __int64 *v3; // rax
unsigned __int64 *v4; // rcx

v2 = *a2;
if ( *a2 >= *(_QWORD *)(a1 + 16) )
{
v3 = *(unsigned __int64 **)(a1 + 24);
if ( !v3 )
{
LABEL_5:
*(_QWORD *)(a1 + 24) = a2;
return;
}
if ( v2 < *v3 )
{
a2[3] = (unsigned __int64)v3;
goto LABEL_5;
}
if ( v2 > *v3 )
{
do
{
v4 = v3;
v3 = (unsigned __int64 *)v3[3];
if ( !v3 )
goto LABEL_10;
}
while ( v2 > *v3 );
if ( v2 < *v3 )
{
LABEL_10:
a2[3] = (unsigned __int64)v3;
v4[3] = (unsigned __int64)a2;
return;
}
}
}
}

original_code:
void insert_packet(source_t* source, packet_t* packet)
{
    if (packet->seq < source->seq) return;
    if (source->packets == ((void *)0)) {
        source->packets = packet;
    } else {
        if (packet->seq < source->packets->seq) {
            packet->next = source->packets;
            source->packets = packet;
        }
        else if (packet->seq > source->packets->seq) {
            packet_t* current = source->packets;
            while (current->next != ((void *)0) && current->next->seq < packet->seq) {
                current = current->next;
            }
            if (current->next == ((void *)0) || current->next->seq > packet->seq) {
                packet->next = current->next;
                current->next = packet;
            }
        }
    }
}

canonical_original_code:
void insert_packet(struct source_s *source, struct packet_s *packet)
{
    if (packet->seq < source->seq) return;
    if (source->packets == ((void *)0)) {
        source->packets = packet;
    } else {
        if (packet->seq < source->packets->seq) {
            packet->next = source->packets;
            source->packets = packet;
        }
        else if (packet->seq > source->packets->seq) {
            struct packet_s *current = source->packets;
            while (current->next != ((void *)0) && current->next->seq < packet->seq) {
                current = current->next;
            }
            if (current->next == ((void *)0) || current->next->seq > packet->seq) {
                packet->next = current->next;
                current->next = packet;
            }
        }
    }
}

variable_types:
packet
struct packet_s *

variable_types: struct packet_s { unsigned long seq; unsigned char *data; int len; struct packet_s *next; } *

return_type: void


decompiled_code:
void __fastcall free_packet(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void free_packet(packet_t* p)
{
    free(p->data);
    free(p);
}

canonical_original_code:
void free_packet(struct packet_s *p)
{
    free(p->data);
    free(p);
}

user_defined_types: struct packet_s { unsigned long seq; unsigned char *data; int len; struct packet_s *next; }


decompiled_code:
int __fastcall save_packet(__int64 a1)
{
fwrite((const void *)(*(_QWORD *)(a1 + 8) + 10LL), *(_DWORD *)(a1 + 16) - 10, 1uLL, file);
return fflush(file);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
fwrite((const void *)(*(_QWORD *)(a1 + 8) + 10LL), *(_DWORD *)(a1 + 16) - 10, 1uLL, file);
return fflush(file);
}

original_code:
void save_packet(packet_t* p)
{
    fwrite(p->data+10, p->len - 10, 1, file);
    fflush(file);
}

canonical_original_code:
void save_packet(struct packet_s *p)
{
    fwrite(p->data+10, p->len - 10, 1, file);
    fflush(file);
}


decompiled_code:
int __fastcall send_ack(__int64 a1)
{
_QWORD *v2; // rdi
__int64 v3; // rax
_QWORD *v4; // rdi
int result; // eax
const char *v6; // rax
const char *v7; // rax
const char *v8; // rax

v2 = *(_QWORD **)(a1 + 24);
if ( v2 )
{
v3 = *(_QWORD *)(a1 + 16);
do
{
if ( *v2 != v3 )
break;
save_packet((__int64)v2);
v4 = *(_QWORD **)(a1 + 24);
*(_QWORD *)(a1 + 24) = v4[3];
free_packet(v4);
v2 = *(_QWORD **)(a1 + 24);
v3 = *(_QWORD *)(a1 + 16) + 1LL;
*(_QWORD *)(a1 + 16) = v3;
}
while ( v2 );
}
udp_ptag = libnet_build_udp();
if ( udp_ptag == -1 )
{
v6 = (const char *)libnet_geterror();
result = fprintf(_bss_start, "Can't build UDP header: %s\n", v6);
}
else
{
ipv4_ptag = libnet_build_ipv4();
if ( ipv4_ptag == -1 )
{
v8 = (const char *)libnet_geterror();
result = fprintf(_bss_start, "Can't build IP header: %s\n", v8);
}
else
{
eth_ptag = libnet_build_ethernet();
if ( eth_ptag == -1 )
{
v7 = (const char *)libnet_geterror();
result = fprintf(_bss_start, "Can't build ethernet header: %s\n", v7);
}
else
{
result = libnet_write();
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1)
{
_QWORD *v2; // rdi
__int64 v3; // rax
_QWORD *v4; // rdi
int result; // eax
const char *v6; // rax
const char *v7; // rax
const char *v8; // rax

v2 = *(_QWORD **)(a1 + 24);
if ( v2 )
{
v3 = *(_QWORD *)(a1 + 16);
do
{
if ( *v2 != v3 )
break;
func11((__int64)v2);
v4 = *(_QWORD **)(a1 + 24);
*(_QWORD *)(a1 + 24) = v4[3];
func10(v4);
v2 = *(_QWORD **)(a1 + 24);
v3 = *(_QWORD *)(a1 + 16) + 1LL;
*(_QWORD *)(a1 + 16) = v3;
}
while ( v2 );
}
udp_ptag = libnet_build_udp();
if ( udp_ptag == -1 )
{
v6 = (const char *)libnet_geterror();
result = fprintf(_bss_start, "Can't build UDP header: %s\n", v6);
}
else
{
ipv4_ptag = libnet_build_ipv4();
if ( ipv4_ptag == -1 )
{
v8 = (const char *)libnet_geterror();
result = fprintf(_bss_start, "Can't build IP header: %s\n", v8);
}
else
{
eth_ptag = libnet_build_ethernet();
if ( eth_ptag == -1 )
{
v7 = (const char *)libnet_geterror();
result = fprintf(_bss_start, "Can't build ethernet header: %s\n", v7);
}
else
{
result = libnet_write();
}
}
}
return result;
}

original_code:
void send_ack(source_t* source)
{
    while (source->packets != ((void *)0) && source->seq == source->packets->seq) {
        save_packet(source->packets);
        packet_t* p = source->packets;
        source->packets = source->packets->next;
        free_packet(p);
        ++source->seq;
    }
    char payload[10];
    memset(payload, 0, sizeof(payload));
    memcpy(payload + 0, &source->seq, sizeof(u_long));
    udp_ptag = libnet_build_udp(
            local_port,
            source->port,
            0x08 + 10,
            0,
            payload,
            10,
            lnet,
            udp_ptag);
    if (udp_ptag == -1)
    {
        fprintf(stderr, "Can't build UDP header: %s\n", libnet_geterror(lnet));
        return;
    }
    ipv4_ptag = libnet_build_ipv4(
            0x14 + 0x08,
            0,
            242,
            0,
            64,
            IPPROTO_UDP,
            0,
            local_ip,
            source->ip,
            ((void *)0),
            0,
            lnet,
            ipv4_ptag);
    if (ipv4_ptag == -1)
    {
        fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(lnet));
        return;
    }
    eth_ptag = libnet_build_ethernet(
            source->mac,
            local_mac,
            0x0800,
            ((void *)0),
            0,
            lnet,
            eth_ptag);
    if (eth_ptag == -1)
    {
        fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(lnet));
        return;
    }
    libnet_write(lnet);
}

canonical_original_code:
void send_ack(struct source_s *source)
{
    while (source->packets != ((void *)0) && source->seq == source->packets->seq) {
        save_packet(source->packets);
        struct packet_s *p = source->packets;
        source->packets = source->packets->next;
        free_packet(p);
        ++source->seq;
    }
    char payload[10];
    memset(payload, 0, sizeof(payload));
    memcpy(payload + 0, &source->seq, sizeof(u_long));
    udp_ptag = libnet_build_udp(
            local_port,
            source->port,
            0x08 + 10,
            0,
            payload,
            10,
            lnet,
            udp_ptag);
    if (udp_ptag == -1)
    {
        fprintf(stderr, "Can't build UDP header: %s\n", libnet_geterror(lnet));
        return;
    }
    ipv4_ptag = libnet_build_ipv4(
            0x14 + 0x08,
            0,
            242,
            0,
            64,
            IPPROTO_UDP,
            0,
            local_ip,
            source->ip,
            ((void *)0),
            0,
            lnet,
            ipv4_ptag);
    if (ipv4_ptag == -1)
    {
        fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(lnet));
        return;
    }
    eth_ptag = libnet_build_ethernet(
            source->mac,
            local_mac,
            0x0800,
            ((void *)0),
            0,
            lnet,
            eth_ptag);
    if (eth_ptag == -1)
    {
        fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(lnet));
        return;
    }
    libnet_write(lnet);
}

variable_types:
payload
char [10]


original_code:
void parse_packet(u_char* args, const struct pcap_pkthdr* pkthdr, const u_char* packet)
{
    if (pkthdr->caplen < pkthdr->len) return;
    u_long src_ip;
    u_long seq;
    u_short src_port;
    u_char flags;
    u_char src_mac[6];
    memcpy(&src_mac, packet+6, 6);
    memcpy(&src_ip, packet+0x0e +12, 4);
    memcpy(&src_port, packet+0x0e +0x14 +0, 2);
    memcpy(&seq, packet+0x0e +0x14 +0x08 +0, 4);
    memcpy(&flags, packet+0x0e +0x14 +0x08 +8, sizeof(u_char));
    src_port = ntohs(src_port);
    packet_t* newp = malloc(sizeof(packet_t));
    int offset = 0x0e + 0x14 + 0x08;
    int len = pkthdr->len - offset;
    newp->seq = seq;
    newp->data = malloc(len);
    memcpy(newp->data, packet + offset, len);
    newp->len = len;
    newp->next = ((void *)0);
    int s = 0;
    while (s < src_num && !match_source(&sources[s], src_ip, src_port)) ++s;
    if (s >= src_num && (flags & 0x02)) {
        s = src_num++;
        sources[s].ip = src_ip;
        sources[s].port = src_port;
        sources[s].seq = seq;
        sources[s].packets = newp;
    } else {
        insert_packet(&sources[s], newp);
    }
    memcpy(sources[s].mac, src_mac, 6);
    send_ack(&sources[s]);
}

canonical_original_code:
void parse_packet(unsigned char *args, struct pcap_pkthdr *pkthdr, unsigned char *packet)
{
    if (pkthdr->caplen < pkthdr->len) return;
    unsigned long src_ip;
    unsigned long seq;
    unsigned short src_port;
    unsigned char flags;
    unsigned char src_mac[6];
    memcpy(&src_mac, packet+6, 6);
    memcpy(&src_ip, packet+0x0e +12, 4);
    memcpy(&src_port, packet+0x0e +0x14 +0, 2);
    memcpy(&seq, packet+0x0e +0x14 +0x08 +0, 4);
    memcpy(&flags, packet+0x0e +0x14 +0x08 +8, sizeof(u_char));
    src_port = ntohs(src_port);
    struct packet_s *newp = malloc(sizeof(packet_t));
    int offset = 0x0e + 0x14 + 0x08;
    int len = pkthdr->len - offset;
    newp->seq = seq;
    newp->data = malloc(len);
    memcpy(newp->data, packet + offset, len);
    newp->len = len;
    newp->next = ((void *)0);
    int s = 0;
    while (s < src_num && !match_source(&sources[s], src_ip, src_port)) ++s;
    if (s >= src_num && (flags & 0x02)) {
        s = src_num++;
        sources[s].ip = src_ip;
        sources[s].port = src_port;
        sources[s].seq = seq;
        sources[s].packets = newp;
    } else {
        insert_packet(&sources[s], newp);
    }
    memcpy(sources[s].mac, src_mac, 6);
    send_ack(&sources[s]);
}

variable_types:
args
unsigned char *

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

variable_types:
packet
unsigned char *

variable_types:
seq
unsigned long

variable_types:
flags
unsigned char

variable_types: offset int

variable_types: len int

variable_types: s int

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


decompiled_code:
__int64 set_local_fields()
{
__int64 v0; // rax
struct in_addr *v1; // rbp
__int64 result; // rax
const char *v3; // rax

v0 = libnet_get_hwaddr();
if ( v0 )
{
local_mac = *(_DWORD *)v0;
word_40C164 = *(_WORD *)(v0 + 4);
v1 = (struct in_addr *)malloc(4uLL);
if ( inet_aton("192.168.10.10", v1) )
{
local_ip = *(_QWORD *)&v1->s_addr;
free(v1);
result = 0LL;
local_port = 13579LL;
}
else
{
perror("Failed to set local ip");
result = 1LL;
}
}
else
{
v3 = (const char *)libnet_geterror();
perror(v3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 v0; // rax
struct in_addr *v1; // rbp
__int64 result; // rax
const char *v3; // rax

v0 = libnet_get_hwaddr();
if ( v0 )
{
local_mac = *(_DWORD *)v0;
word_40C164 = *(_WORD *)(v0 + 4);
v1 = (struct in_addr *)malloc(4uLL);
if ( inet_aton("192.168.10.10", v1) )
{
local_ip = *(_QWORD *)&v1->s_addr;
free(v1);
result = 0LL;
local_port = 13579LL;
}
else
{
perror("Failed to set local ip");
result = 1LL;
}
}
else
{
v3 = (const char *)libnet_geterror();
perror(v3);
result = 1LL;
}
return result;
}

original_code:
int set_local_fields() {
    struct libnet_ether_addr* src_hwaddr = libnet_get_hwaddr(lnet);
    if (src_hwaddr == ((void *)0)) {
        perror(libnet_geterror(lnet));
        return 1;
    }
    memcpy(local_mac, src_hwaddr->ether_addr_octet, 6);
    struct in_addr* inp = malloc(sizeof(struct in_addr));
    if (inet_aton("192.168.10.10", inp) == 0) {
        perror("Failed to set local ip");
        return 1;
    }
    memcpy(&local_ip, &(inp->s_addr), sizeof(u_long));
    free(inp);
    local_port = 13579;
    return 0;
}

canonical_original_code:
int set_local_fields() {
    struct libnet_ether_addr *src_hwaddr = libnet_get_hwaddr(lnet);
    if (src_hwaddr == ((void *)0)) {
        perror(libnet_geterror(lnet));
        return 1;
    }
    memcpy(local_mac, src_hwaddr->ether_addr_octet, 6);
    struct in_addr *inp = malloc(sizeof(struct in_addr));
    if (inet_aton("192.168.10.10", inp) == 0) {
        perror("Failed to set local ip");
        return 1;
    }
    memcpy(&local_ip, &(inp->s_addr), sizeof(u_long));
    free(inp);
    local_port = 13579;
    return 0;
}

variable_types: struct libnet_ether_addr { unsigned char ether_addr_octet[6]; } *

variable_types: struct in_addr { unsigned int s_addr; } *

return_type: int


list

decompiled_code:
__int64 __fastcall list(char *dir)
{
size_t v1; // rax
char *v2; // r14
__int64 v3; // r15
_QWORD *v4; // r13
__int64 i; // rbx
size_t v6; // rax
__int64 v7; // rbp
__int64 v8; // rbp
__int64 v9; // rax
struct dirent **namelist; // [rsp+8h] [rbp-40h] BYREF

puts("List operation");
v1 = strlen(dir);
v2 = (char *)malloc(v1 + 12);
v3 = scandir(
dir,
&namelist,
(int (*)(const struct dirent *))&filterFiles,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v4 = malloc(48 * v3);
if ( v3 )
{
for ( i = 0LL; ; ++i )
{
v6 = strlen(dir);
snprintf(v2, v6 + 12, "%s/%s", dir, namelist[i]->d_name);
v7 = getEntryFromFile(v2);
v4[i] = v7;
free(namelist[i]);
if ( v7 )
printEntry(v7);
if ( v3 == i + 1 )
break;
}
v8 = 0LL;
do
{
freeEntry(v4[v8]);
v9 = v8++;
}
while ( i != v9 );
}
free(v2);
free(v4);
free(namelist);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *dir)
{
size_t v1; // rax
char *v2; // r14
__int64 v3; // r15
_QWORD *v4; // r13
__int64 i; // rbx
size_t v6; // rax
__int64 v7; // rbp
__int64 v8; // rbp
__int64 v9; // rax
struct dirent **namelist; // [rsp+8h] [rbp-40h] BYREF

puts("List operation");
v1 = strlen(dir);
v2 = (char *)malloc(v1 + 12);
v3 = scandir(
dir,
&namelist,
(int (*)(const struct dirent *))&filterFiles,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v4 = malloc(48 * v3);
if ( v3 )
{
for ( i = 0LL; ; ++i )
{
v6 = strlen(dir);
snprintf(v2, v6 + 12, "%s/%s", dir, namelist[i]->d_name);
v7 = getEntryFromFile(v2);
v4[i] = v7;
free(namelist[i]);
if ( v7 )
printEntry(v7);
if ( v3 == i + 1 )
break;
}
v8 = 0LL;
do
{
freeEntry(v4[v8]);
v9 = v8++;
}
while ( i != v9 );
}
free(v2);
free(v4);
free(namelist);
return 0LL;
}

original_code:
int
list(const char* storageFolder)
{
    printf ("List operation\n");
    struct dirent **nameList;
    size_t numberFiles;
    struct LogEntry **entries;
    char* fileNameBuffer = malloc (strlen (storageFolder) + 12);
    int i = 0;
    numberFiles = scandir (storageFolder, &nameList, filterFiles, alphasort);
    entries = malloc (numberFiles * sizeof (struct LogEntry));
    for (i = 0; i < numberFiles; i++)
    {
        snprintf (fileNameBuffer, strlen (storageFolder) + 12, "%s/%s",
                    storageFolder, nameList[i]->d_name);
        entries[i] = getEntryFromFile (fileNameBuffer);
        free (nameList[i]);
        if (entries[i] != ((void *)0))
        {
            printEntry (entries[i]);
        }
    }
    for (i = 0; i < numberFiles; i++)
    {
        freeEntry (entries[i]);
    }
    free (fileNameBuffer);
    free (entries);
    free (nameList);
    return 0;
}

canonical_original_code:
int list(char *storageFolder)
{
    printf ("List operation\n");
    struct dirent **nameList;
    unsigned long numberFiles;
    struct LogEntry **entries;
    char *fileNameBuffer = malloc (strlen (storageFolder) + 12);
    int i = 0;
    numberFiles = scandir (storageFolder, &nameList, filterFiles, alphasort);
    entries = malloc (numberFiles * sizeof (struct LogEntry));
    for (i = 0; i < numberFiles; i++)
    {
        snprintf (fileNameBuffer, strlen (storageFolder) + 12, "%s/%s",
                    storageFolder, nameList[i]->d_name);
        entries[i] = getEntryFromFile (fileNameBuffer);
        free (nameList[i]);
        if (entries[i] != ((void *)0))
        {
            printEntry (entries[i]);
        }
    }
    for (i = 0; i < numberFiles; i++)
    {
        freeEntry (entries[i]);
    }
    free (fileNameBuffer);
    free (entries);
    free (nameList);
    return 0;
}

variable_types:
storageFolder
char *

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } **

variable_types:
numberFiles
unsigned long

variable_types: struct LogEntry { int id; long time; char *timezone; char *location; char *project; char *content; } **

variable_types:
fileNameBuffer
char *

variable_types: i int


usage

decompiled_code:
size_t usage()
{
return fwrite("usage: exlog [command] [-h]\n", 1uLL, 0x1CuLL, stderr);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite("usage: exlog [command] [-h]\n", 1uLL, 0x1CuLL, stderr);
}

original_code:
void
usage (void)
{
    fprintf (stderr, "usage: exlog [command] [-h]\n");
}

canonical_original_code:
void usage()
{
    fprintf (stderr, "usage: exlog [command] [-h]\n");
}


setup

decompiled_code:
void setup()
{
char *v0; // rax
const char *v1; // r13
size_t v2; // r12
char *v3; // rbp
size_t v4; // r12
int *v5; // rax
char *v6; // rax
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

v0 = getenv("HOME");
if ( !v0 )
{
fwrite("HOME not set", 1uLL, 0xCuLL, stderr);
exit(1);
}
v1 = v0;
v2 = snprintf(0LL, 0LL, "%s/.exlog", v0) + 1;
v3 = (char *)malloc(v2);
snprintf(v3, v2, "%s/.exlog", v1);
if ( stat(v3, &v7) == -1 || (v7.st_mode & 0xF000) != 0x4000 )
{
printf("Storage folder not found.\nCreating folder \"%s\" now...\n", v3);
if ( mkdir(v3, 0x1C0u) )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Failed to create storage folder.\nERROR: %s\n", v6);
}
}
v4 = strlen(v3) + 1;
gStorageFolder = malloc(v4);
strncpy((char *)gStorageFolder, v3, v4);
free(v3);
}

canonical_decompiled_code:
void func1()
{
char *v0; // rax
const char *v1; // r13
size_t v2; // r12
char *v3; // rbp
size_t v4; // r12
int *v5; // rax
char *v6; // rax
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

v0 = getenv("HOME");
if ( !v0 )
{
fwrite("HOME not set", 1uLL, 0xCuLL, stderr);
exit(1);
}
v1 = v0;
v2 = snprintf(0LL, 0LL, "%s/.exlog", v0) + 1;
v3 = (char *)malloc(v2);
snprintf(v3, v2, "%s/.exlog", v1);
if ( stat(v3, &v7) == -1 || (v7.st_mode & 0xF000) != 0x4000 )
{
printf("Storage folder not found.\nCreating folder \"%s\" now...\n", v3);
if ( mkdir(v3, 0x1C0u) )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Failed to create storage folder.\nERROR: %s\n", v6);
}
}
v4 = strlen(v3) + 1;
gStorageFolder = malloc(v4);
strncpy((char *)gStorageFolder, v3, v4);
free(v3);
}

original_code:
void
setup (void)
{
    struct stat sts;
    char *home = getenv ("HOME");
    if (home != ((void *)0))
    {
        size_t sizeNeeded = snprintf (((void *)0), 0, "%s/.exlog", home) + 1;
        char *path = malloc (sizeNeeded);
        snprintf (path, sizeNeeded, "%s/.exlog", home);
        size_t ret = stat(path, &sts);
        if ((ret == -1) || &sts != ((void *)0) && !((((sts.st_mode)) & 0170000) == (0040000)))
        {
            printf ("Storage folder not found.\n"
                    "Creating folder \"%s\" now...\n", path);
            if (mkdir (path, 0700) != 0)
            {
                fprintf (stderr, "Failed to create storage folder.\n"
                            "ERROR: %s\n", strerror((*__errno_location ())));
            }
        }
        gStorageFolder = malloc (strlen (path) + 1);
        strncpy (gStorageFolder, path, strlen (path) + 1);
        free (path);
    }else
    {
        fprintf (stderr, "HOME not set");
        exit (1);
    }
}

canonical_original_code:
void setup()
{
    struct stat sts;
    char *home = getenv ("HOME");
    if (home != ((void *)0))
    {
        unsigned long sizeNeeded = snprintf (((void *)0), 0, "%s/.exlog", home) + 1;
        char *path = malloc (sizeNeeded);
        snprintf (path, sizeNeeded, "%s/.exlog", home);
        unsigned long ret = stat(path, &sts);
        if ((ret == -1) || &sts != ((void *)0) && !((((sts.st_mode)) & 0170000) == (0040000)))
        {
            printf ("Storage folder not found.\n"
                    "Creating folder \"%s\" now...\n", path);
            if (mkdir (path, 0700) != 0)
            {
                fprintf (stderr, "Failed to create storage folder.\n"
                            "ERROR: %s\n", strerror((*__errno_location ())));
            }
        }
        gStorageFolder = malloc (strlen (path) + 1);
        strncpy (gStorageFolder, path, strlen (path) + 1);
        free (path);
    }else
    {
        fprintf (stderr, "HOME not set");
        exit (1);
    }
}

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

variable_types:
home
char *

variable_types:
sizeNeeded
unsigned long

variable_types:
path
char *

variable_types:
ret
unsigned long

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


teardown

decompiled_code:
void teardown()
{
free(gStorageFolder);
gStorageFolder = 0LL;
}

canonical_decompiled_code:
void func2()
{
free(gStorageFolder);
gStorageFolder = 0LL;
}

original_code:
void
teardown (void)
{
    free (gStorageFolder);
    gStorageFolder = ((void *)0);
}

canonical_original_code:
void teardown()
{
    free (gStorageFolder);
    gStorageFolder = ((void *)0);
}


callAdd

decompiled_code:
__int64 __fastcall callAdd(int argc, char **argv)
{
char *v2; // r13
char *v3; // r12
int v4; // eax
struct option v6; // [rsp+0h] [rbp-A8h] BYREF
const char *v7; // [rsp+20h] [rbp-88h]
int v8; // [rsp+28h] [rbp-80h]
__int64 v9; // [rsp+30h] [rbp-78h]
int v10; // [rsp+38h] [rbp-70h]
const char *v11; // [rsp+40h] [rbp-68h]
int v12; // [rsp+48h] [rbp-60h]
__int64 v13; // [rsp+50h] [rbp-58h]
int v14; // [rsp+58h] [rbp-50h]
__int64 v15; // [rsp+60h] [rbp-48h]
int v16; // [rsp+68h] [rbp-40h]
__int64 v17; // [rsp+70h] [rbp-38h]
int v18; // [rsp+78h] [rbp-30h]

v2 = 0LL;
v3 = 0LL;
v6.name = "help";
v6.has_arg = 0;
v6.flag = 0LL;
v6.val = 104;
v7 = "location";
v8 = 1;
v9 = 0LL;
v10 = 108;
v11 = "project";
v12 = 1;
v13 = 0LL;
v14 = 112;
v15 = 0LL;
v16 = 0;
v17 = 0LL;
v18 = 0;
while ( 1 )
{
v4 = getopt_long(argc, argv, "h", &v6, 0LL);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'l':
v3 = optarg;
break;
case 'p':
v2 = optarg;
break;
case 'h':
usage();
teardown();
exit(0);
default:
usage();
teardown();
exit(1);
}
}
return add(gStorageFolder, v3, v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(int argc, char **argv)
{
char *v2; // r13
char *v3; // r12
int v4; // eax
struct option v6; // [rsp+0h] [rbp-A8h] BYREF
const char *v7; // [rsp+20h] [rbp-88h]
int v8; // [rsp+28h] [rbp-80h]
__int64 v9; // [rsp+30h] [rbp-78h]
int v10; // [rsp+38h] [rbp-70h]
const char *v11; // [rsp+40h] [rbp-68h]
int v12; // [rsp+48h] [rbp-60h]
__int64 v13; // [rsp+50h] [rbp-58h]
int v14; // [rsp+58h] [rbp-50h]
__int64 v15; // [rsp+60h] [rbp-48h]
int v16; // [rsp+68h] [rbp-40h]
__int64 v17; // [rsp+70h] [rbp-38h]
int v18; // [rsp+78h] [rbp-30h]

v2 = 0LL;
v3 = 0LL;
v6.name = "help";
v6.has_arg = 0;
v6.flag = 0LL;
v6.val = 104;
v7 = "location";
v8 = 1;
v9 = 0LL;
v10 = 108;
v11 = "project";
v12 = 1;
v13 = 0LL;
v14 = 112;
v15 = 0LL;
v16 = 0;
v17 = 0LL;
v18 = 0;
while ( 1 )
{
v4 = getopt_long(argc, argv, "h", &v6, 0LL);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'l':
v3 = optarg;
break;
case 'p':
v2 = optarg;
break;
case 'h':
func0();
func2();
exit(0);
default:
func0();
func2();
exit(1);
}
}
return add(gStorageFolder, v3, v2);
}

original_code:
void
callAdd (int argc, char* argv[])
{
    const struct option long_options[] =
    {
        {"help", 0, ((void *)0), 'h'},
        {"location", 1, ((void *)0), 'l'},
        {"project", 1, ((void *)0), 'p'},
        {((void *)0), 0, ((void *)0), 0}
    };
    const char* location = ((void *)0);
    const char* project = ((void *)0);
    int next_option;
    while ((next_option = getopt_long (argc, argv, "h", long_options, ((void *)0)))
            != -1)
    {
        switch (next_option)
        {
            case 'h':
                usage ();
                teardown ();
                exit (0);
            case 'l':
                location = optarg;
                break;
            case 'p':
                project = optarg;
                break;
            default:
                usage ();
                teardown ();
                exit (1);
         }
    }
    add (gStorageFolder, location, project);
}

canonical_original_code:
void callAdd(int argc, char *argv[])
{
    struct option long_options[] = {
        {"help", 0, ((void *)0), 'h'},
        {"location", 1, ((void *)0), 'l'},
        {"project", 1, ((void *)0), 'p'},
        {((void *)0), 0, ((void *)0), 0}
    };
    char *location = ((void *)0);
    char *project = ((void *)0);
    int next_option;
    while ((next_option = getopt_long (argc, argv, "h", long_options, ((void *)0)))
            != -1)
    {
        switch (next_option)
        {
            case 'h':
                usage ();
                teardown ();
                exit (0);
            case 'l':
                location = optarg;
                break;
            case 'p':
                project = optarg;
                break;
            default:
                usage ();
                teardown ();
                exit (1);
         }
    }
    add (gStorageFolder, location, project);
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types:
location
char *

variable_types:
project
char *


callRm

decompiled_code:
int __fastcall callRm(int a1, __int64 a2)
{
int result; // eax
unsigned int v3; // [rsp+Ch] [rbp-Ch] BYREF

if ( a1 <= 1 )
{
puts("You need to specify what to delete.");
teardown();
exit(1);
}
result = sscanf(*(const char **)(a2 + 16), "%u", &v3);
if ( result == 1 )
result = rm(v3);
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, __int64 a2)
{
int result; // eax
unsigned int v3; // [rsp+Ch] [rbp-Ch] BYREF

if ( a1 <= 1 )
{
puts("You need to specify what to delete.");
func2();
exit(1);
}
result = sscanf(*(const char **)(a2 + 16), "%u", &v3);
if ( result == 1 )
result = rm(v3);
return result;
}

original_code:
void
callRm (int argc, char* argv[])
{
   uint id;
   if (argc < 2)
   {
       printf ("You need to specify what to delete.\n");
       teardown ();
       exit (1);
   }else
   {
       if (sscanf (argv[2], "%u", &id) == 1)
       {
           rm (id);
       }
   }
}

canonical_original_code:
void callRm(int argc, char *argv[])
{
   unsigned int id;
   if (argc < 2)
   {
       printf ("You need to specify what to delete.\n");
       teardown ();
       exit (1);
   }else
   {
       if (sscanf (argv[2], "%u", &id) == 1)
       {
           rm (id);
       }
   }
}

variable_types:
id
unsigned int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rbp
__int64 v5; // rbx
const char *v6; // rsi
char *s2[9]; // [rsp+0h] [rbp-48h]

s2[1] = "rm";
s2[2] = "list";
s2[3] = 0LL;
setup();
if ( argc <= 1 )
{
list(gStorageFolder);
teardown();
exit(0);
}
v4 = argv[1];
v5 = 0LL;
v6 = "add";
do
{
if ( !strcasecmp(v4, v6) )
break;
v6 = s2[++v5];
}
while ( v6 );
if ( v5 == 1 )
{
callRm(argc, (__int64)argv);
}
else if ( v5 == 2 )
{
list(gStorageFolder);
}
else
{
if ( v5 )
{
fwrite("Unknown command...\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
callAdd(argc, (char **)argv);
}
teardown();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rbp
__int64 v5; // rbx
const char *v6; // rsi
char *s2[9]; // [rsp+0h] [rbp-48h]

s2[1] = "rm";
s2[2] = "list";
s2[3] = 0LL;
func1();
if ( argc <= 1 )
{
list(gStorageFolder);
func2();
exit(0);
}
v4 = argv[1];
v5 = 0LL;
v6 = "add";
do
{
if ( !strcasecmp(v4, v6) )
break;
v6 = s2[++v5];
}
while ( v6 );
if ( v5 == 1 )
{
func4(argc, (__int64)argv);
}
else if ( v5 == 2 )
{
list(gStorageFolder);
}
else
{
if ( v5 )
{
fwrite("Unknown command...\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
func3(argc, (char **)argv);
}
func2();
return 0;
}

original_code:
int
main (int argc, char *argv[])
{
    size_t cmd;
    const char *commands[]={"add", "rm", "list", ((void *)0)};
    enum {ADD,RM,LIST};
    setup ();
    if (argc <= 1)
    {
        list (gStorageFolder);
        teardown ();
        exit (0);
    }
    for (cmd=0;commands[cmd] && strcasecmp(argv[1],commands[cmd]);cmd++);
    switch (cmd)
    {
        case ADD:
            callAdd (argc, argv);
            break;
        case RM:
            callRm (argc, argv);
            break;
        case LIST:
            list (gStorageFolder);
            break;
        default:
            fprintf (stderr, "Unknown command...\n");
            exit (1);
            break;
    }
    teardown ();
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned long cmd;
    char *commands[] = {"add", "rm", "list", ((void *)0)};
    enum {ADD,RM,LIST};
    setup ();
    if (argc <= 1)
    {
        list (gStorageFolder);
        teardown ();
        exit (0);
    }
    for (cmd=0;commands[cmd] && strcasecmp(argv[1],commands[cmd]);cmd++);
    switch (cmd)
    {
        case ADD:
            callAdd (argc, argv);
            break;
        case RM:
            callRm (argc, argv);
            break;
        case LIST:
            list (gStorageFolder);
            break;
        default:
            fprintf (stderr, "Unknown command...\n");
            exit (1);
            break;
    }
    teardown ();
    return 0;
}

variable_types:
cmd
unsigned long

variable_types:
commands
char *[]


freeEntry

decompiled_code:
void __fastcall freeEntry(void *ptr)
{
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(ptr);
}

original_code:
void
freeEntry (struct LogEntry* entry)
{
    free (entry->timezone);
    free (entry->location);
    free (entry->project);
    free (entry->content);
    free (entry);
}

canonical_original_code:
void freeEntry(struct LogEntry *entry)
{
    free (entry->timezone);
    free (entry->location);
    free (entry->project);
    free (entry->content);
    free (entry);
}

variable_types: struct LogEntry { int id; long time; char *timezone; char *location; char *project; char *content; } *


getTimeFromFile

decompiled_code:
__int64 __fastcall getTimeFromFile(const char *a1)
{
char *v1; // rax
__int64 result; // rax
int v3; // [rsp+Ch] [rbp-Ch] BYREF

v3 = -1;
v1 = strrchr(a1, 47);
sscanf(v1 + 1, "%d", &v3);
result = v3;
if ( v3 == -1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
char *v1; // rax
__int64 result; // rax
int v3; // [rsp+Ch] [rbp-Ch] BYREF

v3 = -1;
v1 = strrchr(a1, 47);
sscanf(v1 + 1, "%d", &v3);
result = v3;
if ( v3 == -1 )
result = 0LL;
return result;
}

original_code:
time_t
getTimeFromFile (const char* fileName)
{
    struct tm* cal;
    time_t timestamp = -1;
    int i = -1;
    sscanf (strrchr (fileName, '/') + 1, "%d", &i);
    if (i != -1)
    {
        timestamp = i;
        return timestamp;
    } else
    {
        return 0;
    }
}

canonical_original_code:
long getTimeFromFile(char *fileName)
{
    struct tm *cal;
    long timestamp = -1;
    int i = -1;
    sscanf (strrchr (fileName, '/') + 1, "%d", &i);
    if (i != -1)
    {
        timestamp = i;
        return timestamp;
    } else
    {
        return 0;
    }
}

variable_types:
fileName
char *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: timestamp long

return_type: long


getCorrectedTime

decompiled_code:
struct tm *__fastcall getCorrectedTime(__int64 a1)
{
char *v1; // rbp
struct tm *v2; // r12

v1 = getenv("TZ");
setenv("TZ", *(const char **)(a1 + 16), 1);
v2 = localtime((const time_t *)(a1 + 8));
setenv("TZ", v1, 1);
return v2;
}

canonical_decompiled_code:
struct tm *__fastcall func2(__int64 a1)
{
char *v1; // rbp
struct tm *v2; // r12

v1 = getenv("TZ");
setenv("TZ", *(const char **)(a1 + 16), 1);
v2 = localtime((const time_t *)(a1 + 8));
setenv("TZ", v1, 1);
return v2;
}

original_code:
struct tm*
getCorrectedTime (const struct LogEntry* entry)
{
    char* curTZ = getenv ("TZ");
    setenv ("TZ", entry->timezone, 1);
    struct tm* t = localtime (&entry->time);
    setenv ("TZ", curTZ, 1);
    return t;
}

canonical_original_code:
struct tm *getCorrectedTime(struct LogEntry *entry)
{
    char *curTZ = getenv ("TZ");
    setenv ("TZ", entry->timezone, 1);
    struct tm *t = localtime (&entry->time);
    setenv ("TZ", curTZ, 1);
    return t;
}

variable_types:
curTZ
char *

return_type: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

user_defined_types: struct LogEntry { int id; long time; char *timezone; char *location; char *project; char *content; }


printEntry

decompiled_code:
void __fastcall printEntry(unsigned int *a1)
{
struct tm *v1; // r12
char *v2; // rax
char *v3; // rbp
const char *v4; // rsi
const char *v5; // rsi

v1 = getCorrectedTime((__int64)a1);
v2 = (char *)malloc(0x1AuLL);
v3 = v2;
if ( v1 )
strftime(v2, 0x1AuLL, "%F %T %z", v1);
printf("Entry %d at %s\n", *a1, v3);
v4 = (const char *)*((_QWORD *)a1 + 4);
if ( v4 && !*v4 )
printf("Entry for project %s ", v4);
else
printf("Entry for project default ");
v5 = (const char *)*((_QWORD *)a1 + 3);
if ( v5 )
printf("at location %s\n", v5);
else
puts("at location default");
printf("Content: %s\n", *((const char **)a1 + 5));
free(v3);
}

canonical_decompiled_code:
void __fastcall func3(unsigned int *a1)
{
struct tm *v1; // r12
char *v2; // rax
char *v3; // rbp
const char *v4; // rsi
const char *v5; // rsi

v1 = func2((__int64)a1);
v2 = (char *)malloc(0x1AuLL);
v3 = v2;
if ( v1 )
strftime(v2, 0x1AuLL, "%F %T %z", v1);
printf("Entry %d at %s\n", *a1, v3);
v4 = (const char *)*((_QWORD *)a1 + 4);
if ( v4 && !*v4 )
printf("Entry for project %s ", v4);
else
printf("Entry for project default ");
v5 = (const char *)*((_QWORD *)a1 + 3);
if ( v5 )
printf("at location %s\n", v5);
else
puts("at location default");
printf("Content: %s\n", *((const char **)a1 + 5));
free(v3);
}

original_code:
void
printEntry (const struct LogEntry* entry)
{
    struct tm* t = getCorrectedTime (entry);
    char* date = malloc (26);
    if (t != ((void *)0))
    {
        strftime (date, 26, "%F %T %z\0", t);
    }
    printf ("Entry %d at %s\n",
            entry->id,
            date);
    if (entry->project == ((void *)0) || strcmp(entry->project, ""))
    {
        printf ("Entry for project default ");
    }else
    {
        printf ("Entry for project %s ", entry->project);
    }
    if (entry->location == ((void *)0))
    {
        printf ("at location default\n");
    }else
    {
        printf ("at location %s\n", entry->location);
    }
    printf ("Content: %s\n", entry->content);
    free (date);
}

canonical_original_code:
void printEntry(struct LogEntry *entry)
{
    struct tm *t = getCorrectedTime (entry);
    char *date = malloc (26);
    if (t != ((void *)0))
    {
        strftime (date, 26, "%F %T %z\0", t);
    }
    printf ("Entry %d at %s\n",
            entry->id,
            date);
    if (entry->project == ((void *)0) || strcmp(entry->project, ""))
    {
        printf ("Entry for project default ");
    }else
    {
        printf ("Entry for project %s ", entry->project);
    }
    if (entry->location == ((void *)0))
    {
        printf ("at location default\n");
    }else
    {
        printf ("at location %s\n", entry->location);
    }
    printf ("Content: %s\n", entry->content);
    free (date);
}

variable_types:
date
char *

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


getFileName

decompiled_code:
char *__fastcall getFileName(const char *a1, __int64 a2)
{
__int64 v2; // rbx
size_t v3; // rbp
char *v4; // r12

v2 = *(_QWORD *)(a2 + 8);
v3 = strlen(a1) + 12;
v4 = (char *)malloc(v3);
snprintf(v4, v3, "%s/%010d", a1, v2);
return v4;
}

canonical_decompiled_code:
char *__fastcall func4(const char *a1, __int64 a2)
{
__int64 v2; // rbx
size_t v3; // rbp
char *v4; // r12

v2 = *(_QWORD *)(a2 + 8);
v3 = strlen(a1) + 12;
v4 = (char *)malloc(v3);
snprintf(v4, v3, "%s/%010d", a1, v2);
return v4;
}

original_code:
char*
getFileName(const char* storageFolder, const struct LogEntry* entry)
{
    const char *fileNameFormat = "%s/%010d";
    const char* timeFormat = "%FT%T%z";
    time_t t = entry->time;
    size_t sizeNeeded = strlen (storageFolder) + 12;
    char* buf = malloc (sizeNeeded);
    snprintf (buf, sizeNeeded, fileNameFormat, storageFolder, t);
    return buf;
}

canonical_original_code:
char *getFileName(char *storageFolder, struct LogEntry *entry)
{
    char *fileNameFormat = "%s/%010d";
    char *timeFormat = "%FT%T%z";
    long t = entry->time;
    unsigned long sizeNeeded = strlen (storageFolder) + 12;
    char *buf = malloc (sizeNeeded);
    snprintf (buf, sizeNeeded, fileNameFormat, storageFolder, t);
    return buf;
}

variable_types:
storageFolder
char *

variable_types:
fileNameFormat
char *

variable_types:
timeFormat
char *

variable_types: t long

variable_types:
sizeNeeded
unsigned long

variable_types:
buf
char *

return_type: char *


getTimezone

decompiled_code:
_DWORD *getTimezone()
{
char *v0; // rax
const char *v1; // rbp
size_t v2; // r12
char *v3; // rax
_DWORD *result; // rax

v0 = getenv("TZ");
if ( v0 )
{
v1 = v0;
v2 = strlen(v0) + 1;
v3 = (char *)malloc(v2);
result = strncpy(v3, v1, v2);
}
else
{
result = malloc(4uLL);
*result = 4412501;
}
return result;
}

canonical_decompiled_code:
_DWORD *func1()
{
char *v0; // rax
const char *v1; // rbp
size_t v2; // r12
char *v3; // rax
_DWORD *result; // rax

v0 = getenv("TZ");
if ( v0 )
{
v1 = v0;
v2 = strlen(v0) + 1;
v3 = (char *)malloc(v2);
result = strncpy(v3, v1, v2);
}
else
{
result = malloc(4uLL);
*result = 4412501;
}
return result;
}

original_code:
char*
getTimezone ()
{
    char* env;
    char* tz;
    env = getenv ("TZ");
    if (env == ((void *)0))
    {
        tz = malloc (4);
        strncpy (tz, "UTC\0", 4);
    }else
    {
        tz = malloc (strlen (env) + 1);
        strncpy (tz, env, strlen (env) + 1);
    }
    return tz;
}

canonical_original_code:
char *getTimezone()
{
    char *env;
    char *tz;
    env = getenv ("TZ");
    if (env == ((void *)0))
    {
        tz = malloc (4);
        strncpy (tz, "UTC\0", 4);
    }else
    {
        tz = malloc (strlen (env) + 1);
        strncpy (tz, env, strlen (env) + 1);
    }
    return tz;
}

variable_types:
env
char *

variable_types:
tz
char *


getNextID

decompiled_code:
__int64 __fastcall getNextID(char *s)
{
unsigned int v1; // er13
int v2; // eax
unsigned __int64 v4; // rbp
size_t v5; // r13
char *v6; // rbx
size_t v7; // r13
char *v8; // r14
unsigned __int64 v9; // rbx
_DWORD *v10; // rax
struct dirent *v11; // rdi
struct dirent **namelist; // [rsp+8h] [rbp-30h] BYREF

v1 = 0;
v2 = scandir(
s,
&namelist,
(int (*)(const struct dirent *))&filterFiles,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
if ( v2 )
{
v4 = 8LL * v2;
v5 = strlen(s);
v6 = namelist[v4 / 8 - 1]->d_name;
v7 = v5 + strlen(v6) + 2;
v8 = (char *)malloc(v7);
snprintf(v8, v7, "%s/%s", s, v6);
v9 = 0LL;
v10 = (_DWORD *)getEntryFromFile(v8);
v1 = *v10 + 1;
freeEntry(v10);
free(v8);
do
{
v11 = namelist[v9 / 8];
v9 += 8LL;
free(v11);
}
while ( v4 != v9 );
}
free(namelist);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s)
{
unsigned int v1; // er13
int v2; // eax
unsigned __int64 v4; // rbp
size_t v5; // r13
char *v6; // rbx
size_t v7; // r13
char *v8; // r14
unsigned __int64 v9; // rbx
_DWORD *v10; // rax
struct dirent *v11; // rdi
struct dirent **namelist; // [rsp+8h] [rbp-30h] BYREF

v1 = 0;
v2 = scandir(
s,
&namelist,
(int (*)(const struct dirent *))&filterFiles,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
if ( v2 )
{
v4 = 8LL * v2;
v5 = strlen(s);
v6 = namelist[v4 / 8 - 1]->d_name;
v7 = v5 + strlen(v6) + 2;
v8 = (char *)malloc(v7);
snprintf(v8, v7, "%s/%s", s, v6);
v9 = 0LL;
v10 = (_DWORD *)getEntryFromFile(v8);
v1 = *v10 + 1;
freeEntry(v10);
free(v8);
do
{
v11 = namelist[v9 / 8];
v9 += 8LL;
free(v11);
}
while ( v4 != v9 );
}
free(namelist);
return v1;
}

original_code:
int
getNextID (const char* storageFolder)
{
    struct dirent **nameList;
    size_t numberFiles;
    int id = -1;
    int i = 0;
    numberFiles = scandir (storageFolder, &nameList, filterFiles, alphasort);
    if (numberFiles < 0)
    {
        fprintf (stderr, "Could not open storage folder: %s\n",
                strerror ((*__errno_location ())));
        exit(2);
    }else if (numberFiles == 0)
    {
        id = 0;
    }else
    {
        char* fileName = malloc ( strlen (storageFolder) + strlen (
                    nameList[numberFiles - 1]->d_name) + 2);
        snprintf (fileName, strlen (storageFolder) + strlen (
                    nameList[numberFiles - 1]->d_name) + 2,
                    "%s/%s", storageFolder, nameList[numberFiles - 1]->d_name);
        struct LogEntry* entry = getEntryFromFile (fileName);
        id = entry->id + 1;
        freeEntry (entry);
        free (fileName);
    }
    for (i = 0; i < numberFiles; i++)
    {
        free(nameList[i]);
    }
    free (nameList);
    return id;
}

canonical_original_code:
int getNextID(char *storageFolder)
{
    struct dirent **nameList;
    unsigned long numberFiles;
    int id = -1;
    int i = 0;
    numberFiles = scandir (storageFolder, &nameList, filterFiles, alphasort);
    if (numberFiles < 0)
    {
        fprintf (stderr, "Could not open storage folder: %s\n",
                strerror ((*__errno_location ())));
        exit(2);
    }else if (numberFiles == 0)
    {
        id = 0;
    }else
    {
        char *fileName = malloc ( strlen (storageFolder) + strlen (
                    nameList[numberFiles - 1]->d_name) + 2);
        snprintf (fileName, strlen (storageFolder) + strlen (
                    nameList[numberFiles - 1]->d_name) + 2,
                    "%s/%s", storageFolder, nameList[numberFiles - 1]->d_name);
        struct LogEntry *entry = getEntryFromFile (fileName);
        id = entry->id + 1;
        freeEntry (entry);
        free (fileName);
    }
    for (i = 0; i < numberFiles; i++)
    {
        free(nameList[i]);
    }
    free (nameList);
    return id;
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } **

variable_types:
numberFiles
unsigned long

variable_types: id int

variable_types: i int


rm

decompiled_code:
__int64 __fastcall rm(unsigned int a1)
{
printf("Rm operation, deleting log id %d\n", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
printf("Rm operation, deleting log id %d\n", a1);
return 0LL;
}

original_code:
int
rm (uint id)
{
    printf ("Rm operation, deleting log id %d\n", id);
    return 0;
}

canonical_original_code:
int rm(unsigned int id)
{
    printf ("Rm operation, deleting log id %d\n", id);
    return 0;
}

variable_types:
id
unsigned int


main

repo: Dorvaryn/ServerVideo

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int64 v4; // r12
int v5; // ebx
void *v6; // rax
void *v7; // rax
char *v8; // rcx
__int64 v9; // r12
int i; // ebx
void *(*v11)(void *); // rdx
char *v12; // rcx
char v13; // al
__int64 v14; // r13
_DWORD *v15; // rdi
__int64 v16; // rbx
__int64 v17; // r12
char *v18; // rdi
_DWORD *v19; // rdi
__int64 v20; // r13
__int64 v21; // rbx
__int64 v22; // r12
char *v23; // rdi
_DWORD *v24; // rdi
__int64 v25; // r13
__int64 v26; // rbx
__int64 v27; // r12
char *v28; // rdi
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
struct epoll_event event; // [rsp+14h] [rbp-64h] BYREF
int v32; // [rsp+20h] [rbp-58h] BYREF
void *ptr; // [rsp+28h] [rbp-50h]
int v34; // [rsp+30h] [rbp-48h] BYREF
void *v35; // [rsp+38h] [rbp-40h]
int v36; // [rsp+40h] [rbp-38h] BYREF
void *v37; // [rsp+48h] [rbp-30h]

*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
v3 = epoll_create(10);
if ( v3 == -1 )
perror("epollfd");
*(_QWORD *)&event.events = 1LL;
if ( epoll_ctl(v3, 1, 0, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev)");
v32 = 0;
v4 = 0LL;
v5 = 0;
v6 = malloc(0x600uLL);
v34 = 0;
ptr = v6;
v7 = malloc(0x600uLL);
v36 = 0;
v35 = v7;
v37 = malloc(0x600uLL);
catalogue = (void *)buildCatalogue(v3, &v32, &v34, &v36);
if ( v36 > 0 )
{
do
{
++v5;
v8 = (char *)v37 + v4;
v4 += 48LL;
pthread_create(&newthread, 0LL, (void *(*)(void *))&multiFlux, v8);
pthread_detach(newthread);
}
while ( v36 > v5 );
}
v9 = 0LL;
for ( i = 0; v34 > i; v9 += 48LL )
{
while ( 1 )
{
v11 = (void *(*)(void *))&udp_pull;
v12 = (char *)v35 + v9;
v13 = *((_BYTE *)v35 + v9 + 16);
if ( v13 != 2 )
break;
LABEL_12:
++i;
v9 += 48LL;
pthread_create(&newthread, 0LL, v11, v12);
pthread_detach(newthread);
if ( v34 <= i )
goto LABEL_13;
}
if ( v13 == 3 )
{
v11 = (void *(*)(void *))&udp_push;
goto LABEL_12;
}
++i;
}
LABEL_13:
v14 = 0LL;
central(v3, (__int64)&v32);
v15 = ptr;
if ( v32 > 0 )
{
do
{
v16 = 0LL;
v17 = 48 * v14;
close(v15[12 * v14]);
v18 = (char *)*((_QWORD *)ptr + 6 * v14 + 5);
do
{
free(*(void **)&v18[v16]);
v18 = *(char **)((char *)ptr + v17 + 40);
*(_QWORD *)&v18[v16] = 0LL;
v16 += 8LL;
}
while ( v16 != 0x2000 );
free(v18);
v15 = ptr;
++v14;
*(_QWORD *)((char *)ptr + v17 + 40) = 0LL;
}
while ( v32 > (int)v14 );
}
free(v15);
v19 = v35;
ptr = 0LL;
if ( v34 > 0 )
{
v20 = 0LL;
do
{
v21 = 0LL;
v22 = 48 * v20;
close(v19[12 * v20]);
v23 = (char *)*((_QWORD *)v35 + 6 * v20 + 5);
do
{
free(*(void **)&v23[v21]);
v23 = *(char **)((char *)v35 + v22 + 40);
*(_QWORD *)&v23[v21] = 0LL;
v21 += 8LL;
}
while ( v21 != 0x2000 );
free(v23);
v19 = v35;
++v20;
*(_QWORD *)((char *)v35 + v22 + 40) = 0LL;
}
while ( v34 > (int)v20 );
}
free(v19);
v24 = v37;
v35 = 0LL;
if ( v36 > 0 )
{
v25 = 0LL;
do
{
v26 = 0LL;
v27 = 48 * v25;
close(v24[12 * v25]);
v28 = (char *)*((_QWORD *)v37 + 6 * v25 + 5);
do
{
free(*(void **)&v28[v26]);
v28 = *(char **)((char *)v37 + v27 + 40);
*(_QWORD *)&v28[v26] = 0LL;
v26 += 8LL;
}
while ( v26 != 0x2000 );
free(v28);
v24 = v37;
++v25;
*(_QWORD *)((char *)v37 + v27 + 40) = 0LL;
}
while ( v36 > (int)v25 );
}
free(v24);
v37 = 0LL;
free(catalogue);
catalogue = 0LL;
close(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int64 v4; // r12
int v5; // ebx
void *v6; // rax
void *v7; // rax
char *v8; // rcx
__int64 v9; // r12
int i; // ebx
void *(*v11)(void *); // rdx
char *v12; // rcx
char v13; // al
__int64 v14; // r13
_DWORD *v15; // rdi
__int64 v16; // rbx
__int64 v17; // r12
char *v18; // rdi
_DWORD *v19; // rdi
__int64 v20; // r13
__int64 v21; // rbx
__int64 v22; // r12
char *v23; // rdi
_DWORD *v24; // rdi
__int64 v25; // r13
__int64 v26; // rbx
__int64 v27; // r12
char *v28; // rdi
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
struct epoll_event event; // [rsp+14h] [rbp-64h] BYREF
int v32; // [rsp+20h] [rbp-58h] BYREF
void *ptr; // [rsp+28h] [rbp-50h]
int v34; // [rsp+30h] [rbp-48h] BYREF
void *v35; // [rsp+38h] [rbp-40h]
int v36; // [rsp+40h] [rbp-38h] BYREF
void *v37; // [rsp+48h] [rbp-30h]

*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
v3 = epoll_create(10);
if ( v3 == -1 )
perror("epollfd");
*(_QWORD *)&event.events = 1LL;
if ( epoll_ctl(v3, 1, 0, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev)");
v32 = 0;
v4 = 0LL;
v5 = 0;
v6 = malloc(0x600uLL);
v34 = 0;
ptr = v6;
v7 = malloc(0x600uLL);
v36 = 0;
v35 = v7;
v37 = malloc(0x600uLL);
catalogue = (void *)buildCatalogue(v3, &v32, &v34, &v36);
if ( v36 > 0 )
{
do
{
++v5;
v8 = (char *)v37 + v4;
v4 += 48LL;
pthread_create(&newthread, 0LL, (void *(*)(void *))&multiFlux, v8);
pthread_detach(newthread);
}
while ( v36 > v5 );
}
v9 = 0LL;
for ( i = 0; v34 > i; v9 += 48LL )
{
while ( 1 )
{
v11 = (void *(*)(void *))&udp_pull;
v12 = (char *)v35 + v9;
v13 = *((_BYTE *)v35 + v9 + 16);
if ( v13 != 2 )
break;
LABEL_12:
++i;
v9 += 48LL;
pthread_create(&newthread, 0LL, v11, v12);
pthread_detach(newthread);
if ( v34 <= i )
goto LABEL_13;
}
if ( v13 == 3 )
{
v11 = (void *(*)(void *))&udp_push;
goto LABEL_12;
}
++i;
}
LABEL_13:
v14 = 0LL;
func0(v3, (__int64)&v32);
v15 = ptr;
if ( v32 > 0 )
{
do
{
v16 = 0LL;
v17 = 48 * v14;
close(v15[12 * v14]);
v18 = (char *)*((_QWORD *)ptr + 6 * v14 + 5);
do
{
free(*(void **)&v18[v16]);
v18 = *(char **)((char *)ptr + v17 + 40);
*(_QWORD *)&v18[v16] = 0LL;
v16 += 8LL;
}
while ( v16 != 0x2000 );
free(v18);
v15 = ptr;
++v14;
*(_QWORD *)((char *)ptr + v17 + 40) = 0LL;
}
while ( v32 > (int)v14 );
}
free(v15);
v19 = v35;
ptr = 0LL;
if ( v34 > 0 )
{
v20 = 0LL;
do
{
v21 = 0LL;
v22 = 48 * v20;
close(v19[12 * v20]);
v23 = (char *)*((_QWORD *)v35 + 6 * v20 + 5);
do
{
free(*(void **)&v23[v21]);
v23 = *(char **)((char *)v35 + v22 + 40);
*(_QWORD *)&v23[v21] = 0LL;
v21 += 8LL;
}
while ( v21 != 0x2000 );
free(v23);
v19 = v35;
++v20;
*(_QWORD *)((char *)v35 + v22 + 40) = 0LL;
}
while ( v34 > (int)v20 );
}
free(v19);
v24 = v37;
v35 = 0LL;
if ( v36 > 0 )
{
v25 = 0LL;
do
{
v26 = 0LL;
v27 = 48 * v25;
close(v24[12 * v25]);
v28 = (char *)*((_QWORD *)v37 + 6 * v25 + 5);
do
{
free(*(void **)&v28[v26]);
v28 = *(char **)((char *)v37 + v27 + 40);
*(_QWORD *)&v28[v26] = 0LL;
v26 += 8LL;
}
while ( v26 != 0x2000 );
free(v28);
v24 = v37;
++v25;
*(_QWORD *)((char *)v37 + v27 + 40) = 0LL;
}
while ( v36 > (int)v25 );
}
free(v24);
v37 = 0LL;
free(catalogue);
catalogue = 0LL;
close(v3);
return 0;
}

original_code:
int main(int argc, char ** argv)
{
  struct epoll_event ev;
  memset(&ev, 0, sizeof(struct epoll_event));
  int epollfd;
  epollfd = epoll_create(10);
  if(epollfd == -1) { perror("epollfd");};
  ev.events = EPOLLIN;
  ev.data.fd = 0;
  if(epoll_ctl(epollfd, 1, 0, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev)");};
  struct tabFlux tabFluxTCP;
  tabFluxTCP.nbFlux = 0;
  tabFluxTCP.flux = (struct flux *)malloc(32*sizeof(struct flux));
  struct tabFlux tabFluxUDP;
  tabFluxUDP.nbFlux = 0;
  tabFluxUDP.flux = (struct flux *)malloc(32*sizeof(struct flux));
  struct tabFlux tabFluxMCAST;
  tabFluxMCAST.nbFlux = 0;
  tabFluxMCAST.flux = (struct flux *)malloc(32*sizeof(struct flux));
  catalogue = buildCatalogue(epollfd, &tabFluxTCP, &tabFluxUDP, &tabFluxMCAST);
  int i;
  for(i = 0; i < tabFluxMCAST.nbFlux; i++) {
   pthread_t thread;
   pthread_create(&thread, ((void *)0), multiFlux, (void*)&tabFluxMCAST.flux[i]);
   pthread_detach(thread);
  }
  for(i = 0; i < tabFluxUDP.nbFlux; i++)
  {
   if(tabFluxUDP.flux[i].infosVideo.type == 2)
   {
    pthread_t thread;
    pthread_create(&thread, ((void *)0), udp_pull, (void*)&tabFluxUDP.flux[i]);
    pthread_detach(thread);
   }
   else if(tabFluxUDP.flux[i].infosVideo.type == 3)
   {
    pthread_t thread;
    pthread_create(&thread, ((void *)0), udp_push, (void*)&tabFluxUDP.flux[i]);
    pthread_detach(thread);
   }
  }
  central(epollfd, &tabFluxTCP, &tabFluxUDP);
  int j;
  for(i = 0; i < tabFluxTCP.nbFlux; i++) {
      close(tabFluxTCP.flux[i].sock);
   for(j = 0; j < 1024; j++) {
    free(tabFluxTCP.flux[i].infosVideo.images[j]);
    tabFluxTCP.flux[i].infosVideo.images[j] = ((void *)0);
   }
   free(tabFluxTCP.flux[i].infosVideo.images);
   tabFluxTCP.flux[i].infosVideo.images = ((void *)0);
  }
  free(tabFluxTCP.flux);
  tabFluxTCP.flux = ((void *)0);
  for(i = 0; i < tabFluxUDP.nbFlux; i++) {
      close(tabFluxUDP.flux[i].sock);
   for(j = 0; j < 1024; j++) {
    free(tabFluxUDP.flux[i].infosVideo.images[j]);
    tabFluxUDP.flux[i].infosVideo.images[j] = ((void *)0);
   }
   free(tabFluxUDP.flux[i].infosVideo.images);
   tabFluxUDP.flux[i].infosVideo.images = ((void *)0);
  }
  free(tabFluxUDP.flux);
  tabFluxUDP.flux = ((void *)0);
  for(i = 0; i < tabFluxMCAST.nbFlux; i++) {
      close(tabFluxMCAST.flux[i].sock);
   for(j = 0; j < 1024; j++) {
    free(tabFluxMCAST.flux[i].infosVideo.images[j]);
    tabFluxMCAST.flux[i].infosVideo.images[j] = ((void *)0);
   }
   free(tabFluxMCAST.flux[i].infosVideo.images);
   tabFluxMCAST.flux[i].infosVideo.images = ((void *)0);
  }
  free(tabFluxMCAST.flux);
  tabFluxMCAST.flux = ((void *)0);
  free(catalogue);
  catalogue = ((void *)0);
  close(epollfd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  struct epoll_event ev;
  memset(&ev, 0, sizeof(struct epoll_event));
  int epollfd;
  epollfd = epoll_create(10);
  if(epollfd == -1) { perror("epollfd");};
  ev.events = EPOLLIN;
  ev.data.fd = 0;
  if(epoll_ctl(epollfd, 1, 0, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev)");};
  struct tabFlux tabFluxTCP;
  tabFluxTCP.nbFlux = 0;
  tabFluxTCP.flux = (struct flux *)malloc(32*sizeof(struct flux));
  struct tabFlux tabFluxUDP;
  tabFluxUDP.nbFlux = 0;
  tabFluxUDP.flux = (struct flux *)malloc(32*sizeof(struct flux));
  struct tabFlux tabFluxMCAST;
  tabFluxMCAST.nbFlux = 0;
  tabFluxMCAST.flux = (struct flux *)malloc(32*sizeof(struct flux));
  catalogue = buildCatalogue(epollfd, &tabFluxTCP, &tabFluxUDP, &tabFluxMCAST);
  int i;
  for(i = 0; i < tabFluxMCAST.nbFlux; i++) {
   unsigned long thread;
   pthread_create(&thread, ((void *)0), multiFlux, (void *)&tabFluxMCAST.flux[i]);
   pthread_detach(thread);
  }
  for(i = 0; i < tabFluxUDP.nbFlux; i++)
  {
   if(tabFluxUDP.flux[i].infosVideo.type == 2)
   {
    unsigned long thread;
    pthread_create(&thread, ((void *)0), udp_pull, (void *)&tabFluxUDP.flux[i]);
    pthread_detach(thread);
   }
   else if(tabFluxUDP.flux[i].infosVideo.type == 3)
   {
    unsigned long thread;
    pthread_create(&thread, ((void *)0), udp_push, (void *)&tabFluxUDP.flux[i]);
    pthread_detach(thread);
   }
  }
  central(epollfd, &tabFluxTCP, &tabFluxUDP);
  int j;
  for(i = 0; i < tabFluxTCP.nbFlux; i++) {
      close(tabFluxTCP.flux[i].sock);
   for(j = 0; j < 1024; j++) {
    free(tabFluxTCP.flux[i].infosVideo.images[j]);
    tabFluxTCP.flux[i].infosVideo.images[j] = ((void *)0);
   }
   free(tabFluxTCP.flux[i].infosVideo.images);
   tabFluxTCP.flux[i].infosVideo.images = ((void *)0);
  }
  free(tabFluxTCP.flux);
  tabFluxTCP.flux = ((void *)0);
  for(i = 0; i < tabFluxUDP.nbFlux; i++) {
      close(tabFluxUDP.flux[i].sock);
   for(j = 0; j < 1024; j++) {
    free(tabFluxUDP.flux[i].infosVideo.images[j]);
    tabFluxUDP.flux[i].infosVideo.images[j] = ((void *)0);
   }
   free(tabFluxUDP.flux[i].infosVideo.images);
   tabFluxUDP.flux[i].infosVideo.images = ((void *)0);
  }
  free(tabFluxUDP.flux);
  tabFluxUDP.flux = ((void *)0);
  for(i = 0; i < tabFluxMCAST.nbFlux; i++) {
      close(tabFluxMCAST.flux[i].sock);
   for(j = 0; j < 1024; j++) {
    free(tabFluxMCAST.flux[i].infosVideo.images[j]);
    tabFluxMCAST.flux[i].infosVideo.images[j] = ((void *)0);
   }
   free(tabFluxMCAST.flux[i].infosVideo.images);
   tabFluxMCAST.flux[i].infosVideo.images = ((void *)0);
  }
  free(tabFluxMCAST.flux);
  tabFluxMCAST.flux = ((void *)0);
  free(catalogue);
  catalogue = ((void *)0);
  close(epollfd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; }

variable_types: epollfd int

variable_types: struct tabFlux { int nbFlux; struct flux { int sock; int port; char *adresse; struct infosVideo { char type; double fps; int nbImages; char **images; } infosVideo; } *flux; }

variable_types:
thread
unsigned long

variable_types: j int

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }

user_defined_types: struct tabFlux { int nbFlux; struct flux *flux; }

user_defined_types: struct flux { int sock; int port; char *adresse; struct infosVideo infosVideo; }


getTime

decompiled_code:
double getTime()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
double func2()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

original_code:
double getTime() {
 struct timeval timev;
 gettimeofday(&timev, ((void *)0));
 double micro = (double)timev.tv_usec;
 double sec = (double)timev.tv_sec;
 return sec + micro/1000000;
}

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

variable_types: micro double

variable_types: sec double

return_type: double


timeInterval

decompiled_code:
__m128 __fastcall timeInterval(double a1, __m128 a2)
{
if ( *(double *)a2.m128_u64 > a1 )
*(double *)a2.m128_u64 = *(double *)a2.m128_u64 - a1;
return a2;
}

original_code:
double timeInterval(double t1, double t2) {
    return (t1 < t2 ? t2-t1 : t2);
}


decompiled_code:
void __fastcall send_get_answer(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
if ( send(fd, buf, v2, 0) == -1 )
perror("send(fd, catalogue, strlen(catalogue), 0)");
}

canonical_decompiled_code:
void __fastcall func4(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
if ( send(fd, buf, v2, 0) == -1 )
perror("send(fd, catalogue, strlen(catalogue), 0)");
}

original_code:
void send_get_answer(int fd, char * catalogue)
{
 if(send(fd, catalogue, strlen(catalogue), 0) == -1) { perror("send(fd, catalogue, strlen(catalogue), 0)");};
}

canonical_original_code:
void send_get_answer(int fd, char *catalogue)
{
 if(send(fd, catalogue, strlen(catalogue), 0) == -1) { perror("send(fd, catalogue, strlen(catalogue), 0)");};
}

variable_types: fd int

variable_types:
catalogue
char *


createSockEventTCP

decompiled_code:
__int64 __fastcall createSockEventTCP(int epfd, unsigned __int16 a2)
{
unsigned int v2; // er12
unsigned int v3; // ebx
socklen_t v4; // edx
struct epoll_event event; // [rsp+4h] [rbp-44h] BYREF
struct sockaddr v7[3]; // [rsp+10h] [rbp-38h] BYREF

v2 = socket(2, 1, 0);
if ( v2 == -1 )
perror("sock");
v3 = fcntl(v2, 3, 2048LL);
if ( v3 == -1 )
perror("flags");
BYTE1(v3) |= 8u;
if ( fcntl(v2, 4, v3) == -1 )
perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");
*(_QWORD *)&v7[0].sa_data[6] = 0LL;
*(_QWORD *)&v7[0].sa_data[2] = (unsigned int)_bswap_32_constprop_0(a2, v7, 16LL);
v7[0].sa_family = 2;
*(_WORD *)v7[0].sa_data = _bswap_16(a2);
if ( bind(v2, v7, v4) == -1 )
perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");
if ( listen(v2, 10) == -1 )
perror("listen(sock, 10)");
event.events = -2147483647;
event.data.u64 = v2;
if ( epoll_ctl(epfd, 1, v2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(int epfd, unsigned __int16 a2)
{
unsigned int v2; // er12
unsigned int v3; // ebx
socklen_t v4; // edx
struct epoll_event event; // [rsp+4h] [rbp-44h] BYREF
struct sockaddr v7[3]; // [rsp+10h] [rbp-38h] BYREF

v2 = socket(2, 1, 0);
if ( v2 == -1 )
perror("sock");
v3 = fcntl(v2, 3, 2048LL);
if ( v3 == -1 )
perror("flags");
BYTE1(v3) |= 8u;
if ( fcntl(v2, 4, v3) == -1 )
perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");
*(_QWORD *)&v7[0].sa_data[6] = 0LL;
*(_QWORD *)&v7[0].sa_data[2] = (unsigned int)func1(a2, v7, 16LL);
v7[0].sa_family = 2;
*(_WORD *)v7[0].sa_data = func0(a2);
if ( bind(v2, v7, v4) == -1 )
perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");
if ( listen(v2, 10) == -1 )
perror("listen(sock, 10)");
event.events = -2147483647;
event.data.u64 = v2;
if ( epoll_ctl(epfd, 1, v2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");
return v2;
}

original_code:
int createSockEventTCP(int epollfd, int port)
{
 int sock = socket(2, SOCK_STREAM, 0);
 if(sock == -1) { perror("sock");};
 int flags = fcntl(sock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(sock,4,flags|04000) == -1) { perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");};
 struct sockaddr_in saddr;
 memset(&saddr, 0, sizeof(struct sockaddr_in));
 saddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 saddr.sin_family = 2;
 saddr.sin_port = htons(port);
 if(bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) { perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");};
 if(listen(sock, 10) == -1) { perror("listen(sock, 10)");};
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 ev.events = EPOLLIN | EPOLLET;
 ev.data.fd = sock;
 if(epoll_ctl(epollfd, 1, sock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");};
 return sock;
}

canonical_original_code:
int createSockEventTCP(int epollfd, int port)
{
 int sock = socket(2, SOCK_STREAM, 0);
 if(sock == -1) { perror("sock");};
 int flags = fcntl(sock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(sock,4,flags|04000) == -1) { perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");};
 struct sockaddr_in saddr;
 memset(&saddr, 0, sizeof(struct sockaddr_in));
 saddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 saddr.sin_family = 2;
 saddr.sin_port = htons(port);
 if(bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) { perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");};
 if(listen(sock, 10) == -1) { perror("listen(sock, 10)");};
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 ev.events = EPOLLIN | EPOLLET;
 ev.data.fd = sock;
 if(epoll_ctl(epollfd, 1, sock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");};
 return sock;
}

variable_types: port int

variable_types: sock int

variable_types: flags int

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

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: union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; }

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


createSockEventUDP

decompiled_code:
__int64 __fastcall createSockEventUDP(int epfd, unsigned __int16 a2)
{
unsigned int v2; // er12
unsigned int v3; // ebx
socklen_t v4; // edx
struct epoll_event event; // [rsp+4h] [rbp-44h] BYREF
struct sockaddr v7[3]; // [rsp+10h] [rbp-38h] BYREF

v2 = socket(2, 2, 0);
if ( v2 == -1 )
perror("sock");
v3 = fcntl(v2, 3, 2048LL);
if ( v3 == -1 )
perror("flags");
BYTE1(v3) |= 8u;
if ( fcntl(v2, 4, v3) == -1 )
perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");
*(_QWORD *)&v7[0].sa_data[6] = 0LL;
*(_QWORD *)&v7[0].sa_data[2] = (unsigned int)_bswap_32_constprop_0(a2, v7, 16LL);
v7[0].sa_family = 2;
*(_WORD *)v7[0].sa_data = _bswap_16(a2);
if ( bind(v2, v7, v4) == -1 )
perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");
event.events = -2147483647;
event.data.u64 = v2;
if ( epoll_ctl(epfd, 1, v2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(int epfd, unsigned __int16 a2)
{
unsigned int v2; // er12
unsigned int v3; // ebx
socklen_t v4; // edx
struct epoll_event event; // [rsp+4h] [rbp-44h] BYREF
struct sockaddr v7[3]; // [rsp+10h] [rbp-38h] BYREF

v2 = socket(2, 2, 0);
if ( v2 == -1 )
perror("sock");
v3 = fcntl(v2, 3, 2048LL);
if ( v3 == -1 )
perror("flags");
BYTE1(v3) |= 8u;
if ( fcntl(v2, 4, v3) == -1 )
perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");
*(_QWORD *)&v7[0].sa_data[6] = 0LL;
*(_QWORD *)&v7[0].sa_data[2] = (unsigned int)func1(a2, v7, 16LL);
v7[0].sa_family = 2;
*(_WORD *)v7[0].sa_data = func0(a2);
if ( bind(v2, v7, v4) == -1 )
perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");
event.events = -2147483647;
event.data.u64 = v2;
if ( epoll_ctl(epfd, 1, v2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");
return v2;
}

original_code:
int createSockEventUDP(int epollfd, int port)
{
 int sock = socket(2, SOCK_DGRAM, 0);
 if(sock == -1) { perror("sock");};
 int flags = fcntl(sock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(sock,4,flags|04000) == -1) { perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");};
 struct sockaddr_in saddr;
 memset(&saddr, 0, sizeof(struct sockaddr_in));
 saddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 saddr.sin_family = 2;
 saddr.sin_port = htons(port);
 if(bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) { perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");};
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 ev.events = EPOLLIN | EPOLLET;
 ev.data.fd = sock;
 if(epoll_ctl(epollfd, 1, sock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");};
 return sock;
}

canonical_original_code:
int createSockEventUDP(int epollfd, int port)
{
 int sock = socket(2, SOCK_DGRAM, 0);
 if(sock == -1) { perror("sock");};
 int flags = fcntl(sock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(sock,4,flags|04000) == -1) { perror("fcntl(sock,F_SETFL,flags|O_NONBLOCK)");};
 struct sockaddr_in saddr;
 memset(&saddr, 0, sizeof(struct sockaddr_in));
 saddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 saddr.sin_family = 2;
 saddr.sin_port = htons(port);
 if(bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) { perror("bind(sock, (struct sockaddr *)&saddr, sizeof(saddr))");};
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 ev.events = EPOLLIN | EPOLLET;
 ev.data.fd = sock;
 if(epoll_ctl(epollfd, 1, sock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev)");};
 return sock;
}


createSockClientEvent

decompiled_code:
__int64 __fastcall createSockClientEvent(int epfd, int fd)
{
unsigned int v2; // er12
unsigned int v3; // ebx
socklen_t v5; // [rsp+0h] [rbp-38h] BYREF
struct epoll_event event; // [rsp+4h] [rbp-34h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
v5 = 16;
addr = 0LL;
v2 = accept(fd, &addr, &v5);
if ( v2 == -1 )
perror("csock");
v3 = fcntl(v2, 3, 2048LL);
if ( v3 == -1 )
perror("flags");
BYTE1(v3) |= 8u;
if ( fcntl(v2, 4, v3) == -1 )
perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");
event.events = -2147483643;
event.data.fd = v2;
if ( epoll_ctl(epfd, 1, v2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int epfd, int fd)
{
unsigned int v2; // er12
unsigned int v3; // ebx
socklen_t v5; // [rsp+0h] [rbp-38h] BYREF
struct epoll_event event; // [rsp+4h] [rbp-34h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
v5 = 16;
addr = 0LL;
v2 = accept(fd, &addr, &v5);
if ( v2 == -1 )
perror("csock");
v3 = fcntl(v2, 3, 2048LL);
if ( v3 == -1 )
perror("flags");
BYTE1(v3) |= 8u;
if ( fcntl(v2, 4, v3) == -1 )
perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");
event.events = -2147483643;
event.data.fd = v2;
if ( epoll_ctl(epfd, 1, v2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");
return v2;
}

original_code:
int createSockClientEvent(int epollfd, int sock)
{
 int csock;
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 struct sockaddr_in saddr_client;
 memset(&saddr_client, 0, sizeof(struct sockaddr_in));
 socklen_t size_addr = sizeof(struct sockaddr_in);
 csock = accept(sock, (struct sockaddr *)&saddr_client, &size_addr);
 if(csock == -1) { perror("csock");}
 int flags = fcntl(csock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(csock,4,flags|04000) == -1) { perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");};
 ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
 ev.data.fd = csock;
 if(epoll_ctl(epollfd, 1, csock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");};
 return csock;
}

canonical_original_code:
int createSockClientEvent(int epollfd, int sock)
{
 int csock;
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 struct sockaddr_in saddr_client;
 memset(&saddr_client, 0, sizeof(struct sockaddr_in));
 unsigned int size_addr = sizeof(struct sockaddr_in);
 csock = accept(sock, (struct sockaddr *)&saddr_client, &size_addr);
 if(csock == -1) { perror("csock");}
 int flags = fcntl(csock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(csock,4,flags|04000) == -1) { perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");};
 ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
 ev.data.fd = csock;
 if(epoll_ctl(epollfd, 1, csock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");};
 return csock;
}

variable_types: csock int


createFichier

decompiled_code:
void *__fastcall createFichier(int epfd, int *a2, int a3, int *a4, unsigned int a5)
{
__int64 v8; // rbp
_DWORD *v9; // r13
char *v10; // r13
char *v11; // rax
char *v12; // rbx
char *v13; // r13
void *result; // rax
int v15; // eax
void *v16; // rdi
_DWORD *v17; // rax
int v18; // er8
__int64 v19; // rax

v8 = *a2;
v9 = (_DWORD *)*((_QWORD *)a2 + 1);
if ( (int)v8 < *a4 )
{
if ( a5 > 1 )
goto LABEL_3;
LABEL_8:
v18 = createSockEventTCP(epfd, a3);
v19 = 3 * v8;
LODWORD(v8) = *a2;
v9[4 * v19] = v18;
v9 = (_DWORD *)*((_QWORD *)a2 + 1);
goto LABEL_3;
}
v15 = 2 * *a4;
v16 = (void *)*((_QWORD *)a2 + 1);
*a4 = v15;
v17 = realloc(v16, 48LL * v15);
v9 = v17;
if ( !v17 )
{
free(*((void **)a2 + 1));
puts("Error (re)allocating memory");
exit(1);
}
*((_QWORD *)a2 + 1) = v17;
v8 = *a2;
if ( a5 <= 1 )
goto LABEL_8;
LABEL_3:
v10 = (char *)&v9[12 * (int)v8];
*((_DWORD *)v10 + 1) = a3;
*((_DWORD *)v10 + 8) = 0;
v11 = (char *)malloc(0x2000uLL);
*((_QWORD *)v10 + 5) = v11;
v12 = v11;
v13 = v11 + 0x2000;
do
{
v12 += 8;
result = malloc(0x200uLL);
*((_QWORD *)v12 - 1) = result;
}
while ( v13 != v12 );
*a2 = v8 + 1;
return result;
}

original_code:
void createFichier(int epollfd, struct tabFlux * tabFlux, int port, int * baseFichierCourante, int type)
{
 if (tabFlux->nbFlux >= *baseFichierCourante)
 {
  *baseFichierCourante *=2;
  struct flux * temp;
  temp = (struct flux *) realloc(tabFlux->flux,
    *baseFichierCourante*sizeof(struct flux));
  if (temp!=((void *)0))
  {
   tabFlux->flux = temp;
  }
  else
  {
   free (tabFlux->flux);
   puts ("Error (re)allocating memory");
   exit (1);
  }
 }
 if( type == 0 || type == 1 )
 {
  tabFlux->flux[tabFlux->nbFlux].sock = createSockEventTCP(epollfd,port);
 }
 tabFlux->flux[tabFlux->nbFlux].port = port;
 tabFlux->flux[tabFlux->nbFlux].infosVideo.nbImages = 0;
 tabFlux->flux[tabFlux->nbFlux].infosVideo.images = (char **)malloc(1024*sizeof(char*));
 int k;
 for (k = 0; k < 1024; k++)
 {
  tabFlux->flux[tabFlux->nbFlux].infosVideo.images[k] = (char *)malloc(512*sizeof(char));
 }
 tabFlux->nbFlux++;
}

canonical_original_code:
void createFichier(int epollfd, struct tabFlux *tabFlux, int port, int *baseFichierCourante, int type)
{
 if (tabFlux->nbFlux >= *baseFichierCourante)
 {
  *baseFichierCourante *=2;
  struct flux *temp;
  temp = (struct flux *) realloc(tabFlux->flux,
    *baseFichierCourante*sizeof(struct flux));
  if (temp!=((void *)0))
  {
   tabFlux->flux = temp;
  }
  else
  {
   free (tabFlux->flux);
   puts ("Error (re)allocating memory");
   exit (1);
  }
 }
 if( type == 0 || type == 1 )
 {
  tabFlux->flux[tabFlux->nbFlux].sock = createSockEventTCP(epollfd,port);
 }
 tabFlux->flux[tabFlux->nbFlux].port = port;
 tabFlux->flux[tabFlux->nbFlux].infosVideo.nbImages = 0;
 tabFlux->flux[tabFlux->nbFlux].infosVideo.images = (char **)malloc(1024*sizeof(char *));
 int k;
 for (k = 0; k < 1024; k++)
 {
  tabFlux->flux[tabFlux->nbFlux].infosVideo.images[k] = (char *)malloc(512*sizeof(char));
 }
 tabFlux->nbFlux++;
}

variable_types: struct tabFlux { int nbFlux; struct flux { int sock; int port; char *adresse; struct infosVideo { char type; double fps; int nbImages; char **images; } infosVideo; } *flux; } *

variable_types:
baseFichierCourante
int *

variable_types: type int

variable_types: k int


addImage

decompiled_code:
char *__fastcall addImage(char *src, __int64 a2)
{
char *result; // rax

result = strcpy(*(char **)(*(_QWORD *)(a2 + 24) + 8LL * *(int *)(a2 + 16)), src);
++*(_DWORD *)(a2 + 16);
return result;
}

canonical_decompiled_code:
char *__fastcall func9(char *src, __int64 a2)
{
char *result; // rax

result = strcpy(*(char **)(*(_QWORD *)(a2 + 24) + 8LL * *(int *)(a2 + 16)), src);
++*(_DWORD *)(a2 + 16);
return result;
}

original_code:
void addImage(char * uneImage, struct infosVideo * infos)
{
 strcpy(infos->images[infos->nbImages], uneImage);
 infos->nbImages++;
}

canonical_original_code:
void addImage(char *uneImage, struct infosVideo *infos)
{
 strcpy(infos->images[infos->nbImages], uneImage);
 infos->nbImages++;
}

variable_types:
uneImage
char *

variable_types: struct infosVideo { char type; double fps; int nbImages; char **images; } *


createEventPull

decompiled_code:
void __fastcall createEventPull(int a1, unsigned int a2)
{
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

event.data.u64 = a2;
event.events = -2147483644;
if ( epoll_ctl(a1, 1, a2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");
}

canonical_decompiled_code:
void __fastcall func11(int a1, unsigned int a2)
{
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

event.data.u64 = a2;
event.events = -2147483644;
if ( epoll_ctl(a1, 1, a2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");
}

original_code:
void createEventPull(int epollfd, int csock)
{
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 ev.events = EPOLLOUT | EPOLLET;
 ev.data.fd = csock;
 if(epoll_ctl(epollfd, 1, csock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");};
}

variable_types: epollfd int

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; }


createEventPush

decompiled_code:
void __fastcall createEventPush(int a1, unsigned int a2)
{
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

event.data.u64 = a2;
event.events = 4;
if ( epoll_ctl(a1, 1, a2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");
}

canonical_decompiled_code:
void __fastcall func12(int a1, unsigned int a2)
{
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

event.data.u64 = a2;
event.events = 4;
if ( epoll_ctl(a1, 1, a2, &event) == -1 )
perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");
}

original_code:
void createEventPush(int epollfd, int csock)
{
 struct epoll_event ev;
 memset(&ev, 0, sizeof(struct epoll_event));
 ev.events = EPOLLOUT;
 ev.data.fd = csock;
 if(epoll_ctl(epollfd, 1, csock, &ev) == -1) { perror("epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev)");};
}


connectDataTCP

decompiled_code:
__int64 __fastcall connectDataTCP(int a1, int a2, __int16 a3, int a4)
{
int v6; // edx
unsigned int v7; // er12
unsigned int v8; // ebx
__int64 result; // rax
socklen_t len; // [rsp+0h] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-38h] BYREF

addr = 0LL;
len = 16;
if ( getpeername(a2, &addr, &len) == -1 )
perror("getpeername(sock, (struct sockaddr*)&addr, &len)");
*(_WORD *)addr.sa_data = _bswap_16(a3);
v7 = socket(2, 1, v6);
v8 = fcntl(v7, 3, 2048LL);
if ( v8 == -1 )
perror("flags");
BYTE1(v8) |= 8u;
if ( fcntl(v7, 4, v8) == -1 )
perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");
if ( v7 == -1 )
perror("csock");
if ( connect(v7, &addr, len) == -1 )
perror("connect(csock, (struct sockaddr *)&addr, len)");
if ( a4 )
{
if ( a4 == 1 )
createEventPush(a1, v7);
result = v7;
}
else
{
createEventPull(a1, v7);
result = v7;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, int a2, __int16 a3, int a4)
{
int v6; // edx
unsigned int v7; // er12
unsigned int v8; // ebx
__int64 result; // rax
socklen_t len; // [rsp+0h] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-38h] BYREF

addr = 0LL;
len = 16;
if ( getpeername(a2, &addr, &len) == -1 )
perror("getpeername(sock, (struct sockaddr*)&addr, &len)");
*(_WORD *)addr.sa_data = func0(a3);
v7 = socket(2, 1, v6);
v8 = fcntl(v7, 3, 2048LL);
if ( v8 == -1 )
perror("flags");
BYTE1(v8) |= 8u;
if ( fcntl(v7, 4, v8) == -1 )
perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");
if ( v7 == -1 )
perror("csock");
if ( connect(v7, &addr, len) == -1 )
perror("connect(csock, (struct sockaddr *)&addr, len)");
if ( a4 )
{
if ( a4 == 1 )
func12(a1, v7);
result = v7;
}
else
{
func11(a1, v7);
result = v7;
}
return result;
}

original_code:
int connectDataTCP(int epollfd, int sock, int port, int type)
{
 struct sockaddr_in addr;
 memset(&addr, 0, sizeof(struct sockaddr_in));
 int csock;
 socklen_t len = sizeof(struct sockaddr_in);
 if(getpeername(sock, (struct sockaddr*)&addr, &len) == -1) { perror("getpeername(sock, (struct sockaddr*)&addr, &len)");};
 addr.sin_port = htons(port);
 csock = socket(2, SOCK_STREAM, 0);
 int flags = fcntl(csock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(csock,4,flags|04000) == -1) { perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");};
 if(csock == -1) { perror("csock");};
 if(connect(csock, (struct sockaddr *)&addr, len) == -1) { perror("connect(csock, (struct sockaddr *)&addr, len)");};
 if(type == 0)
 {
  createEventPull(epollfd, csock);
 }
 else if(type == 1)
 {
  createEventPush(epollfd, csock);
 }
    return csock;
}

canonical_original_code:
int connectDataTCP(int epollfd, int sock, int port, int type)
{
 struct sockaddr_in addr;
 memset(&addr, 0, sizeof(struct sockaddr_in));
 int csock;
 unsigned int len = sizeof(struct sockaddr_in);
 if(getpeername(sock, (struct sockaddr *)&addr, &len) == -1) { perror("getpeername(sock, (struct sockaddr*)&addr, &len)");};
 addr.sin_port = htons(port);
 csock = socket(2, SOCK_STREAM, 0);
 int flags = fcntl(csock,3,04000);
 if(flags == -1) { perror("flags");};
 if(fcntl(csock,4,flags|04000) == -1) { perror("fcntl(csock,F_SETFL,flags|O_NONBLOCK)");};
 if(csock == -1) { perror("csock");};
 if(connect(csock, (struct sockaddr *)&addr, len) == -1) { perror("connect(csock, (struct sockaddr *)&addr, len)");};
 if(type == 0)
 {
  createEventPull(epollfd, csock);
 }
 else if(type == 1)
 {
  createEventPush(epollfd, csock);
 }
    return csock;
}

variable_types:
len
unsigned int


multiCatalogue

decompiled_code:
void __fastcall __noreturn multiCatalogue(void *buf)
{
int v1; // ebx
char *v2; // r13
int v3; // er12
int v4; // eax
struct sockaddr v5; // [rsp+0h] [rbp-38h] BYREF

v1 = socket(2, 2, 0);
v5 = 0LL;
v5.sa_family = 2;
*(_DWORD *)&v5.sa_data[2] = inet_addr("225.6.7.8");
*(_WORD *)v5.sa_data = _bswap_16(4567);
while ( 1 )
{
v2 = (char *)buf;
v3 = strlen((const char *)buf);
do
{
v4 = sendto(v1, v2, v3, 0, &v5, 0x10u);
if ( v4 == -1 )
{
perror("nbSent");
}
else if ( v4 > 0 )
{
v3 -= v4;
v2 += v4;
}
}
while ( v3 > 0 );
sleep(1u);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *buf)
{
int v1; // ebx
char *v2; // r13
int v3; // er12
int v4; // eax
struct sockaddr v5; // [rsp+0h] [rbp-38h] BYREF

v1 = socket(2, 2, 0);
v5 = 0LL;
v5.sa_family = 2;
*(_DWORD *)&v5.sa_data[2] = inet_addr("225.6.7.8");
*(_WORD *)v5.sa_data = func0(4567);
while ( 1 )
{
v2 = (char *)buf;
v3 = strlen((const char *)buf);
do
{
v4 = sendto(v1, v2, v3, 0, &v5, 0x10u);
if ( v4 == -1 )
{
perror("nbSent");
}
else if ( v4 > 0 )
{
v3 -= v4;
v2 += v4;
}
}
while ( v3 > 0 );
sleep(1u);
}
}

original_code:
void* multiCatalogue(void* args) {
 char * origineBuffer = (char *)args;
 int clientSocket = socket(2, SOCK_DGRAM, 0);
 struct sockaddr_in dest_addr;
 memset(&dest_addr,0,sizeof(dest_addr));
 dest_addr.sin_family = 2;
 dest_addr.sin_addr.s_addr = inet_addr("225.6.7.8");
 dest_addr.sin_port = htons(4567);
 while(1)
 {
  char * buffer = origineBuffer;
  int bufLen = strlen(origineBuffer);
  int nbSent = 0;
  do
  {
   nbSent = sendto(clientSocket, buffer, bufLen, 0,
     (struct sockaddr*)&dest_addr, sizeof(struct sockaddr));
   if(nbSent == -1) { perror("nbSent");};
   if( nbSent > 0)
   {
    buffer += nbSent;
    bufLen -= nbSent;
   }
  } while (bufLen > 0);
  sleep(1);
 }
 return ((void *)0);
}

canonical_original_code:
void *multiCatalogue(void *args) {
 char *origineBuffer = (char *)args;
 int clientSocket = socket(2, SOCK_DGRAM, 0);
 struct sockaddr_in dest_addr;
 memset(&dest_addr,0,sizeof(dest_addr));
 dest_addr.sin_family = 2;
 dest_addr.sin_addr.s_addr = inet_addr("225.6.7.8");
 dest_addr.sin_port = htons(4567);
 while(1)
 {
  char *buffer = origineBuffer;
  int bufLen = strlen(origineBuffer);
  int nbSent = 0;
  do
  {
   nbSent = sendto(clientSocket, buffer, bufLen, 0,
     (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
   if(nbSent == -1) { perror("nbSent");};
   if( nbSent > 0)
   {
    buffer += nbSent;
    bufLen -= nbSent;
   }
  } while (bufLen > 0);
  sleep(1);
 }
 return ((void *)0);
}

variable_types:
args
void *

variable_types:
origineBuffer
char *

variable_types: clientSocket int

variable_types:
buffer
char *

variable_types: bufLen int

variable_types: nbSent int

return_type: void *


parseInt

decompiled_code:
__int64 __fastcall parseInt(char *a1)
{
int v1; // ebx
char *v2; // rdi
const unsigned __int16 *v3; // rcx
__int64 result; // rax

if ( *a1 == 45 && a1[1] == 49 && !a1[2] )
return 0xFFFFFFFFLL;
v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
v3 = *_ctype_b_loc();
LODWORD(result) = 0;
while ( (v3[(char)v1] & 0x800) != 0 )
{
++v2;
result = (unsigned int)(v1 + 10 * result - 48);
v1 = *(v2 - 1);
if ( !*(v2 - 1) )
return result;
}
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
int v1; // ebx
char *v2; // rdi
const unsigned __int16 *v3; // rcx
__int64 result; // rax

if ( *a1 == 45 && a1[1] == 49 && !a1[2] )
return 0xFFFFFFFFLL;
v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
v3 = *_ctype_b_loc();
LODWORD(result) = 0;
while ( (v3[(char)v1] & 0x800) != 0 )
{
++v2;
result = (unsigned int)(v1 + 10 * result - 48);
v1 = *(v2 - 1);
if ( !*(v2 - 1) )
return result;
}
return 4294967294LL;
}

original_code:
int parseInt(char* entier) {
 if(strcmp(entier, "-1") == 0) {
  return -1;
 }
 int res = 0;
 int i;
 for(i = 0; entier[i] != '\0'; i++) {
  char c = entier[i];
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit)) {
   res = res*10+(c-'0');
  } else {
   return -2;
  }
 }
 return res;
}

canonical_original_code:
int parseInt(char *entier) {
 if(strcmp(entier, "-1") == 0) {
  return -1;
 }
 int res = 0;
 int i;
 for(i = 0; entier[i] != '\0'; i++) {
  char c = entier[i];
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit)) {
   res = res*10+(c-'0');
  } else {
   return -2;
  }
 }
 return res;
}

variable_types:
entier
char *

variable_types: res int

variable_types: i int

variable_types: c char


initReq

decompiled_code:
__int64 __fastcall initReq(_QWORD *a1)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
a1[1] = -2LL;
*a1 = 0xFFFFFFFFLL;
a1[2] = 0xFFFFFFFFLL;
a1[3] = 0LL;
a1[4] = 0LL;
a1[5] = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
a1[1] = -2LL;
*a1 = 0xFFFFFFFFLL;
a1[2] = 0xFFFFFFFFLL;
a1[3] = 0LL;
a1[4] = 0LL;
a1[5] = 0LL;
return result;
}

original_code:
void initReq(struct requete* req) {
 req->type = (-1);
 req->isOver = 0;
 req->imgId = -2;
 req->listenPort = -1;
 req->fragmentSize = -1;
 req->inWord = 0;
 req->space = 0;
 req->crlfCounter = 0;
 req->mot = 0;
 req->motPosition = 0;
 req->reqPosition = 0;
}

canonical_original_code:
void initReq(struct requete *req) {
 req->type = (-1);
 req->isOver = 0;
 req->imgId = -2;
 req->listenPort = -1;
 req->fragmentSize = -1;
 req->inWord = 0;
 req->space = 0;
 req->crlfCounter = 0;
 req->mot = 0;
 req->motPosition = 0;
 req->reqPosition = 0;
}

variable_types: struct requete { int type; int isOver; int imgId; int listenPort; int fragmentSize; int inWord; int space; int crlfCounter; char *mot; int motPosition; int reqPosition; } *


decompiled_code:
const char *build_date()
{
return "00 / 00 / 00";
}

canonical_decompiled_code:
const char *func0()
{
return "00 / 00 / 00";
}

original_code:
char * build_date()
{
 return "00 / 00 / 00";
}


original_code:
char * build_http_header(char * type, int size)
{
 char * header = malloc(256 * sizeof(char));
 memset(header, '\0', 256);
 strcat(header, "HTTP/1.1 200 OK\r\nDate: ");
 strcat(header, build_date());
 strcat(header, "\r\nServer: ServLib (Unix) (Arch/Linux)\r\nAccept-Ranges: bytes\r\nContent-Length: ");
 char tmp[32] = {'\0'};
 sprintf(tmp, "%d", size);
 strcat(header, tmp);
 strcat(header, "\r\nConnection: close\r\nContent-Type: ");
 strcat(header, type);
 strcat(header, "; charset=UTF-8\r\n\r\n");
 return header;
}

canonical_original_code:
char *build_http_header(char *type, int size)
{
 char *header = malloc(256 * sizeof(char));
 memset(header, '\0', 256);
 strcat(header, "HTTP/1.1 200 OK\r\nDate: ");
 strcat(header, build_date());
 strcat(header, "\r\nServer: ServLib (Unix) (Arch/Linux)\r\nAccept-Ranges: bytes\r\nContent-Length: ");
 char tmp[32] = {'\0'};
 sprintf(tmp, "%d", size);
 strcat(header, tmp);
 strcat(header, "\r\nConnection: close\r\nContent-Type: ");
 strcat(header, type);
 strcat(header, "; charset=UTF-8\r\n\r\n");
 return header;
}

variable_types:
type
char *

variable_types: size int

variable_types:
header
char *

variable_types:
tmp
char [32]


isPaired

decompiled_code:
__int64 __fastcall isPaired(char a1, char a2)
{
unsigned int v2; // er12
__int64 result; // rax

LOBYTE(v2) = a2 == 93 && a1 != 91;
if ( (_BYTE)v2 )
{
puts("Closing square bracket not preceded by opening square bracket.");
result = 0LL;
}
else if ( a2 == 41 && a1 != 40 )
{
puts("Closing parentheses not preceded by opening parentheses.");
result = v2;
}
else if ( a1 != 123 && a2 == 125 )
{
puts("Closing bracket not preceded by opening bracket.");
result = v2;
}
else
{
LOBYTE(v2) = a2 == 93 && a1 == 91;
if ( (_BYTE)v2 )
{
puts("Found matching square brackets '[]'.");
result = v2;
}
else
{
LOBYTE(v2) = a2 == 41 && a1 == 40;
if ( (_BYTE)v2 )
{
puts("Found matching parentheses '()'.");
}
else
{
LOBYTE(v2) = a2 == 125 && a1 == 123;
if ( (_BYTE)v2 )
puts("Found matching brackets '{}'.");
}
result = v2;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, char a2)
{
unsigned int v2; // er12
__int64 result; // rax

LOBYTE(v2) = a2 == 93 && a1 != 91;
if ( (_BYTE)v2 )
{
puts("Closing square bracket not preceded by opening square bracket.");
result = 0LL;
}
else if ( a2 == 41 && a1 != 40 )
{
puts("Closing parentheses not preceded by opening parentheses.");
result = v2;
}
else if ( a1 != 123 && a2 == 125 )
{
puts("Closing bracket not preceded by opening bracket.");
result = v2;
}
else
{
LOBYTE(v2) = a2 == 93 && a1 == 91;
if ( (_BYTE)v2 )
{
puts("Found matching square brackets '[]'.");
result = v2;
}
else
{
LOBYTE(v2) = a2 == 41 && a1 == 40;
if ( (_BYTE)v2 )
{
puts("Found matching parentheses '()'.");
}
else
{
LOBYTE(v2) = a2 == 125 && a1 == 123;
if ( (_BYTE)v2 )
puts("Found matching brackets '{}'.");
}
result = v2;
}
}
return result;
}

original_code:
_Bool isPaired(char openBracket, char closeBracket) {
    if (closeBracket == ']' && openBracket != '[') {
        printf("Closing square bracket not preceded by opening square bracket.\n");
        return 0;
    }
    if (closeBracket == ')' && openBracket != '(') {
        printf("Closing parentheses not preceded by opening parentheses.\n");
        return 0;
    }
    if (closeBracket == '}' && openBracket != '{') {
        printf("Closing bracket not preceded by opening bracket.\n");
        return 0;
    }
    if (closeBracket == ']' && openBracket == '[') {
        printf("Found matching square brackets '[]'.\n");
        return 1;
    }
    if (closeBracket == ')' && openBracket == '(') {
        printf("Found matching parentheses '()'.\n");
        return 1;
    }
    if (closeBracket == '}' && openBracket == '{') {
        printf("Found matching brackets '{}'.\n");
        return 1;
    }
}

variable_types: openBracket char

variable_types: closeBracket char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // eax
int v5; // eax
double v7[2]; // [rsp+18h] [rbp-10h] BYREF

v3 = time(0LL);
srand(v3);
v7[0] = 0.0;
do
printf("Time Duration: ");
while ( (unsigned int)__isoc99_scanf() != 1 );
do
{
do
{
printf("Arrival Air Probobility: ");
v4 = __isoc99_scanf();
}
while ( 0.0 > 1.0 );
}
while ( v4 != 1 );
do
{
do
{
printf("Arrival Ground Probobility: ");
v5 = __isoc99_scanf();
}
while ( v7[0] > 1.0 );
}
while ( v5 != 1 );
puts("\n");
simulate(0LL, v7, 0.0, v7[0]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // eax
int v5; // eax
double v7[2]; // [rsp+18h] [rbp-10h] BYREF

v3 = time(0LL);
srand(v3);
v7[0] = 0.0;
do
printf("Time Duration: ");
while ( (unsigned int)__isoc99_scanf() != 1 );
do
{
do
{
printf("Arrival Air Probobility: ");
v4 = __isoc99_scanf();
}
while ( 0.0 > 1.0 );
}
while ( v4 != 1 );
do
{
do
{
printf("Arrival Ground Probobility: ");
v5 = __isoc99_scanf();
}
while ( v7[0] > 1.0 );
}
while ( v5 != 1 );
puts("\n");
func14(0LL, v7, 0.0, v7[0]);
return 0;
}

original_code:
int main(int argc, char** argv) {
   srand(time(((void *)0)));
   int result = 0;
   int timeDuration = 0;
   double arrivalAirProb = 0;
   double arrivalGroundProb = 0;
   while (result != 1) {
   printf("Time Duration: ");
   result = scanf("%d", &timeDuration);
   if (timeDuration > 100) {
   result = 0;
   }
   }
   result = 0;
   while (result != 1) {
   printf("Arrival Air Probobility: ");
   result = scanf("%lf", &arrivalAirProb);
   if (arrivalAirProb > 1) {
   result = 0;
   }
   }
   result = 0;
   while (result != 1) {
   printf("Arrival Ground Probobility: ");
   result = scanf("%lf", &arrivalGroundProb);
   if (arrivalGroundProb > 1) {
   result = 0;
   }
   }
   printf("\n\n");
   simulate(timeDuration, arrivalAirProb, arrivalGroundProb);
   return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
   srand(time(((void *)0)));
   int result = 0;
   int timeDuration = 0;
   double arrivalAirProb = 0;
   double arrivalGroundProb = 0;
   while (result != 1) {
   printf("Time Duration: ");
   result = scanf("%d", &timeDuration);
   if (timeDuration > 100) {
   result = 0;
   }
   }
   result = 0;
   while (result != 1) {
   printf("Arrival Air Probobility: ");
   result = scanf("%lf", &arrivalAirProb);
   if (arrivalAirProb > 1) {
   result = 0;
   }
   }
   result = 0;
   while (result != 1) {
   printf("Arrival Ground Probobility: ");
   result = scanf("%lf", &arrivalGroundProb);
   if (arrivalGroundProb > 1) {
   result = 0;
   }
   }
   printf("\n\n");
   simulate(timeDuration, arrivalAirProb, arrivalGroundProb);
   return (0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: result int

variable_types: timeDuration int

variable_types: arrivalAirProb double

variable_types: arrivalGroundProb double


addToAir

decompiled_code:
void addToAir()
{
;
}

canonical_decompiled_code:
void func15()
{
;
}

original_code:
_Bool addToAir(double arrivalAirProb) {
}


addToGroud

decompiled_code:
// attributes: thunk
void addToGroud()
{
addToAir();
}

canonical_decompiled_code:
void func16()
{
func15();
}

original_code:
_Bool addToGroud(double arrivalGroudProb) {
}

variable_types: arrivalGroudProb double


getData

decompiled_code:
__int64 getData()
{
int v0; // edx
int v1; // edx
bool v2; // zf
char *s; // [rsp+0h] [rbp-18h] BYREF
size_t n[2]; // [rsp+8h] [rbp-10h] BYREF

n[0] = 8LL;
for ( s = (char *)malloc(0x50uLL); ; *s = 0 )
{
printf("(y/n) -> ");
if ( (unsigned int)getline(&s, n, stdin) == -1 )
{
puts("INPUT ERROR.");
exit(1);
}
strtok(s, "\n");
v0 = (unsigned __int8)*s;
if ( v0 == 121 && !s[1] )
break;
v1 = v0 - 110;
if ( !v1 )
v1 = (unsigned __int8)s[1];
v2 = strcmp(s, "yes") == 0;
if ( !v1 )
{
if ( !v2 )
{
LABEL_13:
*s = 0;
return 0LL;
}
break;
}
if ( v2 )
break;
if ( *s == 110 && s[1] == 111 && !s[2] )
goto LABEL_13;
}
*s = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 func15()
{
int v0; // edx
int v1; // edx
bool v2; // zf
char *s; // [rsp+0h] [rbp-18h] BYREF
size_t n[2]; // [rsp+8h] [rbp-10h] BYREF

n[0] = 8LL;
for ( s = (char *)malloc(0x50uLL); ; *s = 0 )
{
printf("(y/n) -> ");
if ( (unsigned int)getline(&s, n, stdin) == -1 )
{
puts("INPUT ERROR.");
exit(1);
}
strtok(s, "\n");
v0 = (unsigned __int8)*s;
if ( v0 == 121 && !s[1] )
break;
v1 = v0 - 110;
if ( !v1 )
v1 = (unsigned __int8)s[1];
v2 = strcmp(s, "yes") == 0;
if ( !v1 )
{
if ( !v2 )
{
LABEL_13:
*s = 0;
return 0LL;
}
break;
}
if ( v2 )
break;
if ( *s == 110 && s[1] == 111 && !s[2] )
goto LABEL_13;
}
*s = 0;
return 1LL;
}

original_code:
int getData() {
        char *response = (char*) malloc(sizeof (char)*80);
        size_t responseSize = sizeof (response);
        int bytes_read = 1;
        while (1) {
            printf("(y/n) -> ");
            bytes_read = getline(&response, &responseSize, stdin);
            if (bytes_read == -1) {
                printf("INPUT ERROR.\n");
                exit(1);
            } else {
                strtok(response, "\n");
            }
            if (strcmp(response, "y") == 0 || strcmp(response, "n") == 0 || strcmp(response, "yes") == 0 || strcmp(response, "no") == 0) {
                break;
            } else {
                *response = 0;
                continue;
            }
        }
        if (strcmp(response, "y") == 0 || strcmp(response, "yes") == 0) {
            *response = 0;
            return 1;
        } else {
            *response = 0;
            return 0;
        }
    }

canonical_original_code:
int getData() {
        char *response = (char*) malloc(sizeof (char)*80);
        unsigned long responseSize = sizeof (response);
        int bytes_read = 1;
        while (1) {
            printf("(y/n) -> ");
            bytes_read = getline(&response, &responseSize, stdin);
            if (bytes_read == -1) {
                printf("INPUT ERROR.\n");
                exit(1);
            } else {
                strtok(response, "\n");
            }
            if (strcmp(response, "y") == 0 || strcmp(response, "n") == 0 || strcmp(response, "yes") == 0 || strcmp(response, "no") == 0) {
                break;
            } else {
                *response = 0;
                continue;
            }
        }
        if (strcmp(response, "y") == 0 || strcmp(response, "yes") == 0) {
            *response = 0;
            return 1;
        } else {
            *response = 0;
            return 0;
        }
    }

variable_types:
response
char *

variable_types:
responseSize
unsigned long


setprogname

decompiled_code:
char *__fastcall setprogname(char *a1)
{
char *v1; // rax

v1 = __xpg_basename(a1);
return strncpy(progname, v1, 0xFEuLL);
}

canonical_decompiled_code:
char *__fastcall func8(char *a1)
{
char *v1; // rax

v1 = __xpg_basename(a1);
return strncpy(progname, v1, 0xFEuLL);
}

original_code:
void setprogname(char* str) {
    strncpy(progname, __xpg_basename(str), 254);
}

canonical_original_code:
void setprogname(char *str) {
    strncpy(progname, __xpg_basename(str), 254);
}

variable_types:
str
char *