decompiled_code:
__int64 __fastcall next_pow2(unsigned __int64 a1)
{
__int64 result; // rax
char v2; // cl

result = 1LL;
if ( a1 )
{
result = a1;
if ( (a1 & (a1 - 1)) != 0 )
{
v2 = 0;
do
{
++v2;
a1 >>= 1;
}
while ( a1 );
result = 1LL << v2;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1)
{
__int64 result; // rax
char v2; // cl

result = 1LL;
if ( a1 )
{
result = a1;
if ( (a1 & (a1 - 1)) != 0 )
{
v2 = 0;
do
{
++v2;
a1 >>= 1;
}
while ( a1 );
result = 1LL << v2;
}
}
return result;
}

original_code:
static size_t
next_pow2(size_t n)
{
    size_t bit_count = 0;
    if (n == 0)
        return 1;
    if ((n & (n - 1)) == 0)
        return n;
    while (n != 0) {
        n >>= 1;
        bit_count += 1;
    }
    return (size_t)1 << (size_t)bit_count;
}

canonical_original_code:
static unsigned long next_pow2(unsigned long n)
{
    unsigned long bit_count = 0;
    if (n == 0)
        return 1;
    if ((n & (n - 1)) == 0)
        return n;
    while (n != 0) {
        n >>= 1;
        bit_count += 1;
    }
    return (unsigned long)1 << (unsigned long)bit_count;
}

variable_types:
n
unsigned long

return_type: unsigned long


repo: robertdavidgraham/masscan

decompiled_code:
void __fastcall rstfilter_destroy(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 4));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 4));
free(ptr);
}
}

original_code:
void
rstfilter_destroy(struct ResetFilter *rf)
{
    if (rf == ((void *)0))
        return;
    free(rf->buckets);
    free(rf);
}

variable_types: struct ResetFilter { unsigned long long seed; unsigned long bucket_count; unsigned long bucket_mask; unsigned int counter; unsigned char *buckets; } *

return_type: void


original_code:
int
rstfilter_is_filter(struct ResetFilter *rf,
                    ipaddress src_ip, unsigned src_port,
                    ipaddress dst_ip, unsigned dst_port)
{
    uint64_t hash;
    uint64_t input[5];
    uint64_t key[2];
    size_t index;
    unsigned char *p;
    int result = 0;
    switch (src_ip.version) {
    case 4:
        input[0] = src_ip.ipv4;
        input[1] = src_port;
        input[2] = dst_ip.ipv4;
        input[3] = dst_port;
        break;
    case 6:
        input[0] = src_ip.ipv6.hi;
        input[1] = src_ip.ipv6.lo;
        input[2] = dst_ip.ipv6.hi;
        input[3] = dst_ip.ipv6.lo;
        input[4] = src_port<<16 | dst_port;
        break;
    }
    key[0] = rf->seed;
    key[1] = rf->seed;
    hash = siphash24(input, sizeof(input), key);
    index = hash & rf->bucket_mask;
    p = &rf->buckets[index/2];
    if (index & 1) {
        if ((*p & 0x0F) == 0x0F)
            result = 1;
        else
            *p = (*p) + 0x01;
    } else {
        if ((*p & 0xF0) == 0xF0)
            result = 1;
        else
            *p = (*p) + 0x10;
    }
    input[0] = (unsigned)hash;
    input[1] = rf->counter++;
    hash = siphash24(input, sizeof(input), key);
    index = hash & rf->bucket_mask;
    p = &rf->buckets[index/2];
    if (index & 1) {
        if ((*p & 0x0F))
            *p = (*p) - 0x01;
    } else {
        if ((*p & 0xF0))
            *p = (*p) - 0x10;
    }
    return result;
}

canonical_original_code:
int rstfilter_is_filter(struct ResetFilter *rf, struct ipaddress src_ip, unsigned int src_port, struct ipaddress dst_ip, unsigned int dst_port)
{
    unsigned long hash;
    unsigned long input[5];
    unsigned long key[2];
    unsigned long index;
    unsigned char *p;
    int result = 0;
    switch (src_ip.version) {
    case 4:
        input[0] = src_ip.ipv4;
        input[1] = src_port;
        input[2] = dst_ip.ipv4;
        input[3] = dst_port;
        break;
    case 6:
        input[0] = src_ip.ipv6.hi;
        input[1] = src_ip.ipv6.lo;
        input[2] = dst_ip.ipv6.hi;
        input[3] = dst_ip.ipv6.lo;
        input[4] = src_port<<16 | dst_port;
        break;
    }
    key[0] = rf->seed;
    key[1] = rf->seed;
    hash = siphash24(input, sizeof(input), key);
    index = hash & rf->bucket_mask;
    p = &rf->buckets[index/2];
    if (index & 1) {
        if ((*p & 0x0F) == 0x0F)
            result = 1;
        else
            *p = (*p) + 0x01;
    } else {
        if ((*p & 0xF0) == 0xF0)
            result = 1;
        else
            *p = (*p) + 0x10;
    }
    input[0] = (unsigned int)hash;
    input[1] = rf->counter++;
    hash = siphash24(input, sizeof(input), key);
    index = hash & rf->bucket_mask;
    p = &rf->buckets[index/2];
    if (index & 1) {
        if ((*p & 0x0F))
            *p = (*p) - 0x01;
    } else {
        if ((*p & 0xF0))
            *p = (*p) - 0x10;
    }
    return result;
}

variable_types: struct ipaddress { union { unsigned int ipv4; struct ipv6address { unsigned long hi; unsigned long lo; } ipv6; }; unsigned char version; }

variable_types:
hash
unsigned long

variable_types:
input
unsigned long [5]

variable_types:
key
unsigned long [2]

variable_types:
index
unsigned long

variable_types:
p
unsigned char *

variable_types: result int

return_type: int

user_defined_types: struct ipaddress { union { unsigned int ipv4; struct ipv6address ipv6; }; unsigned char version; }

user_defined_types: struct ResetFilter { unsigned long long seed; unsigned long bucket_count; unsigned long bucket_mask; unsigned int counter; unsigned char *buckets; }


original_code:
int
rstfilter_selftest(void)
{
    struct ResetFilter *rf;
    size_t i;
    unsigned count_filtered = 0;
    unsigned count_passed = 0;
    ipaddress src;
    ipaddress dst;
    src.version = 4;
    src.ipv4 = 1;
    dst.version = 4;
    dst.ipv4 = 3;
    rf = rstfilter_create(time(0), 64);
    for (i=0; i<15; i++) {
        int x;
        x = rstfilter_is_filter(rf, src, 2, dst, 4);
        if (x) {
            fprintf(stderr, "[-] rstfilter failed, line=%u\n", 161);
            return 1;
        }
    }
    for (i=0; i<1000; i++) {
        int x;
        x = rstfilter_is_filter(rf, src, 2, dst, 4);
        count_filtered += x;
        count_passed += !x;
    }
    if (count_passed == 0) {
        fprintf(stderr, "[-] rstfilter failed, line=%u\n", 176);
        return 1;
    }
    if (count_passed > count_filtered/10) {
        fprintf(stderr, "[-] rstfilter failed, line=%u\n", 182);
        return 1;
    }
    return 0;
}

canonical_original_code:
int rstfilter_selftest()
{
    struct ResetFilter *rf;
    unsigned long i;
    unsigned int count_filtered = 0;
    unsigned int count_passed = 0;
    struct ipaddress src;
    struct ipaddress dst;
    src.version = 4;
    src.ipv4 = 1;
    dst.version = 4;
    dst.ipv4 = 3;
    rf = rstfilter_create(time(0), 64);
    for (i=0; i<15; i++) {
        int x;
        x = rstfilter_is_filter(rf, src, 2, dst, 4);
        if (x) {
            fprintf(stderr, "[-] rstfilter failed, line=%u\n", 161);
            return 1;
        }
    }
    for (i=0; i<1000; i++) {
        int x;
        x = rstfilter_is_filter(rf, src, 2, dst, 4);
        count_filtered += x;
        count_passed += !x;
    }
    if (count_passed == 0) {
        fprintf(stderr, "[-] rstfilter failed, line=%u\n", 176);
        return 1;
    }
    if (count_passed > count_filtered/10) {
        fprintf(stderr, "[-] rstfilter failed, line=%u\n", 182);
        return 1;
    }
    return 0;
}

variable_types:
i
unsigned long

variable_types: x int

user_defined_types: struct ipv6address { unsigned long hi; unsigned long lo; }


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

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

original_code:
static int
ssh_selftest(void)
{
    return 0;
}

canonical_original_code:
static int ssh_selftest()
{
    return 0;
}


vLOG

decompiled_code:
int __fastcall vLOG(int a1, const char *a2, void *a3)
{
int result; // eax

if ( global_debug_level >= a1 )
{
vfprintf(stderr, a2, a3);
result = fflush(stderr);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, const char *a2, void *a3)
{
int result; // eax

if ( global_debug_level >= a1 )
{
vfprintf(stderr, a2, a3);
result = fflush(stderr);
}
return result;
}

original_code:
static void
vLOG(int level, const char *fmt, va_list marker)
{
    if (level <= global_debug_level) {
        vfprintf(stderr, fmt, marker);
        fflush(stderr);
    }
}

canonical_original_code:
static void vLOG(int level, char *fmt, __builtin_va_list marker)
{
    if (level <= global_debug_level) {
        vfprintf(stderr, fmt, marker);
        fflush(stderr);
    }
}

variable_types: level int

variable_types:
fmt
char *


vLOGip

decompiled_code:
int __fastcall vLOGip(int a1, unsigned int a2, const char *a3, void *a4)
{
int result; // eax
char v7[48]; // [rsp+0h] [rbp-88h] BYREF
char s[88]; // [rsp+30h] [rbp-58h] BYREF

if ( global_debug_level >= a1 )
{
ipaddress_fmt(v7);
snprintf(s, 0x40uLL, "%s", v7);
fprintf(stderr, "%-15s:%5u: ", s, a2);
vfprintf(stderr, a3, a4);
result = fflush(stderr);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1, unsigned int a2, const char *a3, void *a4)
{
int result; // eax
char v7[48]; // [rsp+0h] [rbp-88h] BYREF
char s[88]; // [rsp+30h] [rbp-58h] BYREF

if ( global_debug_level >= a1 )
{
ipaddress_fmt(v7);
snprintf(s, 0x40uLL, "%s", v7);
fprintf(stderr, "%-15s:%5u: ", s, a2);
vfprintf(stderr, a3, a4);
result = fflush(stderr);
}
return result;
}

original_code:
static void
vLOGip(int level, ipaddress ip, unsigned port, const char *fmt, va_list marker)
{
    if (level <= global_debug_level) {
        char sz_ip[64];
        ipaddress_formatted_t fmt1 = ipaddress_fmt(ip);
        snprintf(sz_ip, sizeof(sz_ip), "%s", fmt1.string);
        fprintf(stderr, "%-15s:%5u: ", sz_ip, port);
        vfprintf(stderr, fmt, marker);
        fflush(stderr);
    }
}

canonical_original_code:
static void vLOGip(int level, struct ipaddress ip, unsigned int port, char *fmt, __builtin_va_list marker)
{
    if (level <= global_debug_level) {
        char sz_ip[64];
        struct ipaddress_formatted fmt1 = ipaddress_fmt(ip);
        snprintf(sz_ip, sizeof(sz_ip), "%s", fmt1.string);
        fprintf(stderr, "%-15s:%5u: ", sz_ip, port);
        vfprintf(stderr, fmt, marker);
        fflush(stderr);
    }
}

variable_types:
port
unsigned int

variable_types: struct ipaddress_formatted { char string[48]; }


decompiled_code:
void __fastcall LOG_add_level(int a1)
{
global_debug_level += a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
global_debug_level += a1;
}

original_code:
void LOG_add_level(int x)
{
    global_debug_level += x;
}


LOG

decompiled_code:
int LOG(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return vLOG(a1, a2, va);
}

canonical_decompiled_code:
int func3(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return func0(a1, a2, va);
}

original_code:
void
LOG(int level, const char *fmt, ...)
{
    va_list marker;
    __builtin_va_start(marker,fmt);
    vLOG(level, fmt, marker);
    __builtin_va_end(marker);
}

canonical_original_code:
void LOG(int level, char *fmt, ...)
{
    __builtin_va_list marker;
    __builtin_va_start(marker,fmt);
    vLOG(level, fmt, marker);
    __builtin_va_end(marker);
}


LOGip

decompiled_code:
int LOGip(int a1, unsigned int a2, const char *a3, __int64 a4, __int64 a5, __int64 a6, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a6);
return vLOGip(a1, a2, a3, va);
}

canonical_decompiled_code:
int func4(int a1, unsigned int a2, const char *a3, __int64 a4, __int64 a5, __int64 a6, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a6);
return func1(a1, a2, a3, va);
}

original_code:
void
LOGip(int level, ipaddress ip, unsigned port, const char *fmt, ...)
{
    va_list marker;
    __builtin_va_start(marker,fmt);
    vLOGip(level, ip, port, fmt, marker);
    __builtin_va_end(marker);
}

canonical_original_code:
void LOGip(int level, struct ipaddress ip, unsigned int port, char *fmt, ...)
{
    __builtin_va_list marker;
    __builtin_va_start(marker,fmt);
    vLOGip(level, ip, port, fmt, marker);
    __builtin_va_end(marker);
}


decompiled_code:
__int64 __fastcall rawsock_get_default_interface(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // ebp
int v4; // eax
int v5; // eax
int v6; // er15
int v7; // er13
__int64 *v8; // r14
__int64 v9; // rax
__int64 result; // rax
int *v11; // rbx
int *v12; // rbx
int *v13; // rbx
__int128 v14; // [rsp+0h] [rbp-4058h] BYREF
__int128 v15; // [rsp+10h] [rbp-4048h] BYREF
__int64 s[2055]; // [rsp+20h] [rbp-4038h] BYREF

v2 = socket(16, 2, 0);
if ( v2 < 0 )
{
v11 = _errno_location();
fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n", "src/rawsock-getif.c", 315LL, (unsigned int)*v11);
result = (unsigned int)*v11;
}
else
{
v3 = v2;
memset(s, 0, 0x4000uLL);
s[0] = 0x301001A0000001CLL;
HIDWORD(s[1]) = getpid();
if ( send(v3, s, LODWORD(s[0]), 0) < 0 )
{
v13 = _errno_location();
fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n", "src/rawsock-getif.c", 336LL, (unsigned int)*v13);
result = (unsigned int)*v13;
}
else
{
v4 = getpid();
v5 = read_netlink_constprop_0(v3, s, v4);
v6 = v5;
if ( v5 <= 0 )
{
v12 = _errno_location();
fprintf(stderr, "%s:%d: read_netlink: %d\n", "src/rawsock-getif.c", 346LL, (unsigned int)*v12);
result = (unsigned int)*v12;
}
else
{
v7 = 0x7FFFFF;
v8 = s;
if ( v5 > 15 )
{
do
{
if ( *(_DWORD *)v8 <= 0xFu || *(_DWORD *)v8 > (unsigned int)v6 )
break;
v14 = 0LL;
v15 = 0LL;
if ( !(unsigned int)parseRoutes((__int64)v8, (__int64)&v14) )
{
LOG(
3LL,
"if: route: '%12s' dst=%u.%u.%u.%u src=%u.%u.%u.%u gw=%u.%u.%u.%u priority=%d\n",
(const char *)&v15,
BYTE4(v14),
BYTE5(v14),
BYTE6(v14),
HIBYTE(DWORD1(v14)),
BYTE8(v14),
BYTE9(v14),
BYTE10(v14),
HIBYTE(DWORD2(v14)),
BYTE12(v14),
BYTE13(v14),
BYTE14(v14),
HIBYTE(HIDWORD(v14)),
(unsigned int)v14);
if ( !DWORD1(v14) && (int)v14 < v7 )
{
v7 = v14;
if ( (unsigned int)_bswap_32(HIDWORD(v14)) )
strcpy_s(a1, a2, &v15);
}
}
v9 = (*(_DWORD *)v8 + 3) & 0xFFFFFFFC;
v6 -= v9;
v8 = (__int64 *)((char *)v8 + v9);
}
while ( v6 > 15 );
}
close(v3);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // ebp
int v4; // eax
int v5; // eax
int v6; // er15
int v7; // er13
__int64 *v8; // r14
__int64 v9; // rax
__int64 result; // rax
int *v11; // rbx
int *v12; // rbx
int *v13; // rbx
__int128 v14; // [rsp+0h] [rbp-4058h] BYREF
__int128 v15; // [rsp+10h] [rbp-4048h] BYREF
__int64 s[2055]; // [rsp+20h] [rbp-4038h] BYREF

v2 = socket(16, 2, 0);
if ( v2 < 0 )
{
v11 = _errno_location();
fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n", "src/rawsock-getif.c", 315LL, (unsigned int)*v11);
result = (unsigned int)*v11;
}
else
{
v3 = v2;
memset(s, 0, 0x4000uLL);
s[0] = 0x301001A0000001CLL;
HIDWORD(s[1]) = getpid();
if ( send(v3, s, LODWORD(s[0]), 0) < 0 )
{
v13 = _errno_location();
fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n", "src/rawsock-getif.c", 336LL, (unsigned int)*v13);
result = (unsigned int)*v13;
}
else
{
v4 = getpid();
v5 = func2(v3, s, v4);
v6 = v5;
if ( v5 <= 0 )
{
v12 = _errno_location();
fprintf(stderr, "%s:%d: read_netlink: %d\n", "src/rawsock-getif.c", 346LL, (unsigned int)*v12);
result = (unsigned int)*v12;
}
else
{
v7 = 0x7FFFFF;
v8 = s;
if ( v5 > 15 )
{
do
{
if ( *(_DWORD *)v8 <= 0xFu || *(_DWORD *)v8 > (unsigned int)v6 )
break;
v14 = 0LL;
v15 = 0LL;
if ( !(unsigned int)func0((__int64)v8, (__int64)&v14) )
{
LOG(
3LL,
"if: route: '%12s' dst=%u.%u.%u.%u src=%u.%u.%u.%u gw=%u.%u.%u.%u priority=%d\n",
(const char *)&v15,
BYTE4(v14),
BYTE5(v14),
BYTE6(v14),
HIBYTE(DWORD1(v14)),
BYTE8(v14),
BYTE9(v14),
BYTE10(v14),
HIBYTE(DWORD2(v14)),
BYTE12(v14),
BYTE13(v14),
BYTE14(v14),
HIBYTE(HIDWORD(v14)),
(unsigned int)v14);
if ( !DWORD1(v14) && (int)v14 < v7 )
{
v7 = v14;
if ( (unsigned int)func1(HIDWORD(v14)) )
strcpy_s(a1, a2, &v15);
}
}
v9 = (*(_DWORD *)v8 + 3) & 0xFFFFFFFC;
v6 -= v9;
v8 = (__int64 *)((char *)v8 + v9);
}
while ( v6 > 15 );
}
close(v3);
result = 0LL;
}
}
}
return result;
}

original_code:
int rawsock_get_default_interface(char *ifname, size_t sizeof_ifname)
{
    int fd;
    struct nlmsghdr *nlMsg;
    char msgBuf[16384];
    int len;
    int msgSeq = 0;
    unsigned ipv4 = 0;
    int priority = 0x7FFFFF;
    fd = socket(16, SOCK_DGRAM, 0);
    if (fd < 0) {
        fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n",
            "src/rawsock-getif.c", 315, (*__errno_location ()));
        return (*__errno_location ());
    }
    memset(msgBuf, 0, sizeof(msgBuf));
    nlMsg = (struct nlmsghdr *)msgBuf;
    nlMsg->nlmsg_len = ((sizeof(struct rtmsg)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )));
    nlMsg->nlmsg_type = RTM_GETROUTE;
    nlMsg->nlmsg_flags = (0x100|0x200) | 0x01;
    nlMsg->nlmsg_seq = msgSeq++;
    nlMsg->nlmsg_pid = getpid();
    if (send(fd, nlMsg, nlMsg->nlmsg_len, 0) < 0) {
        fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n",
            "src/rawsock-getif.c", 336, (*__errno_location ()));
        return (*__errno_location ());
    }
    len = read_netlink(fd, msgBuf, sizeof(msgBuf), msgSeq, getpid());
    if (len <= 0) {
        fprintf(stderr, "%s:%d: read_netlink: %d\n",
            "src/rawsock-getif.c", 346, (*__errno_location ()));
        return (*__errno_location ());
    }
    for (; ((len) >= (int)sizeof(struct nlmsghdr) && (nlMsg)->nlmsg_len >= sizeof(struct nlmsghdr) && (nlMsg)->nlmsg_len <= (len)); nlMsg = ((len) -= ( (((nlMsg)->nlmsg_len)+4U -1) & ~(4U -1) ), (struct nlmsghdr*)(((char*)(nlMsg)) + ( (((nlMsg)->nlmsg_len)+4U -1) & ~(4U -1) )))) {
        struct route_info rtInfo[1];
        int err;
        memset(rtInfo, 0, sizeof(struct route_info));
        err = parseRoutes(nlMsg, rtInfo);
        if (err != 0)
            continue;
        LOG(3, "if: route: '%12s' dst=%u.%u.%u.%u src=%u.%u.%u.%u gw=%u.%u.%u.%u priority=%d\n",
                rtInfo->ifName,
                ((rtInfo->dstAddr.s_addr)&0xFF), ((rtInfo->dstAddr.s_addr>>8)&0xFF), ((rtInfo->dstAddr.s_addr>>16)&0xFF), ((rtInfo->dstAddr.s_addr>>24)&0xFF),
                ((rtInfo->srcAddr.s_addr)&0xFF), ((rtInfo->srcAddr.s_addr>>8)&0xFF), ((rtInfo->srcAddr.s_addr>>16)&0xFF), ((rtInfo->srcAddr.s_addr>>24)&0xFF),
                ((rtInfo->gateWay.s_addr)&0xFF), ((rtInfo->gateWay.s_addr>>8)&0xFF), ((rtInfo->gateWay.s_addr>>16)&0xFF), ((rtInfo->gateWay.s_addr>>24)&0xFF),
                rtInfo->priority
            );
        if (rtInfo->dstAddr.s_addr != 0)
            continue;
        if (rtInfo->priority < priority) {
            priority = rtInfo->priority;
            ipv4 = ntohl(rtInfo->gateWay.s_addr);
            if (ipv4 == 0)
                continue;
            strcpy_s(ifname, sizeof_ifname, rtInfo->ifName);
        }
    }
    close(fd);
    return 0;
}

canonical_original_code:
int rawsock_get_default_interface(char *ifname, unsigned long sizeof_ifname)
{
    int fd;
    struct nlmsghdr *nlMsg;
    char msgBuf[16384];
    int len;
    int msgSeq = 0;
    unsigned int ipv4 = 0;
    int priority = 0x7FFFFF;
    fd = socket(16, SOCK_DGRAM, 0);
    if (fd < 0) {
        fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n",
            "src/rawsock-getif.c", 315, (*__errno_location ()));
        return (*__errno_location ());
    }
    memset(msgBuf, 0, sizeof(msgBuf));
    nlMsg = (struct nlmsghdr *)msgBuf;
    nlMsg->nlmsg_len = ((sizeof(struct rtmsg)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )));
    nlMsg->nlmsg_type = RTM_GETROUTE;
    nlMsg->nlmsg_flags = (0x100|0x200) | 0x01;
    nlMsg->nlmsg_seq = msgSeq++;
    nlMsg->nlmsg_pid = getpid();
    if (send(fd, nlMsg, nlMsg->nlmsg_len, 0) < 0) {
        fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n",
            "src/rawsock-getif.c", 336, (*__errno_location ()));
        return (*__errno_location ());
    }
    len = read_netlink(fd, msgBuf, sizeof(msgBuf), msgSeq, getpid());
    if (len <= 0) {
        fprintf(stderr, "%s:%d: read_netlink: %d\n",
            "src/rawsock-getif.c", 346, (*__errno_location ()));
        return (*__errno_location ());
    }
    for (; ((len) >= (int)sizeof(struct nlmsghdr) && (nlMsg)->nlmsg_len >= sizeof(struct nlmsghdr) && (nlMsg)->nlmsg_len <= (len)); nlMsg = ((len) -= ( (((nlMsg)->nlmsg_len)+4U -1) & ~(4U -1) ), (struct nlmsghdr *)(((char *)(nlMsg)) + ( (((nlMsg)->nlmsg_len)+4U -1) & ~(4U -1) )))) {
        struct route_info rtInfo[1];
        int err;
        memset(rtInfo, 0, sizeof(struct route_info));
        err = parseRoutes(nlMsg, rtInfo);
        if (err != 0)
            continue;
        LOG(3, "if: route: '%12s' dst=%u.%u.%u.%u src=%u.%u.%u.%u gw=%u.%u.%u.%u priority=%d\n",
                rtInfo->ifName,
                ((rtInfo->dstAddr.s_addr)&0xFF), ((rtInfo->dstAddr.s_addr>>8)&0xFF), ((rtInfo->dstAddr.s_addr>>16)&0xFF), ((rtInfo->dstAddr.s_addr>>24)&0xFF),
                ((rtInfo->srcAddr.s_addr)&0xFF), ((rtInfo->srcAddr.s_addr>>8)&0xFF), ((rtInfo->srcAddr.s_addr>>16)&0xFF), ((rtInfo->srcAddr.s_addr>>24)&0xFF),
                ((rtInfo->gateWay.s_addr)&0xFF), ((rtInfo->gateWay.s_addr>>8)&0xFF), ((rtInfo->gateWay.s_addr>>16)&0xFF), ((rtInfo->gateWay.s_addr>>24)&0xFF),
                rtInfo->priority
            );
        if (rtInfo->dstAddr.s_addr != 0)
            continue;
        if (rtInfo->priority < priority) {
            priority = rtInfo->priority;
            ipv4 = ntohl(rtInfo->gateWay.s_addr);
            if (ipv4 == 0)
                continue;
            strcpy_s(ifname, sizeof_ifname, rtInfo->ifName);
        }
    }
    close(fd);
    return 0;
}

variable_types:
ifname
char *

variable_types: fd int

variable_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } *

variable_types:
msgBuf
char [16384]

variable_types: len int

variable_types: msgSeq int

variable_types: priority int

variable_types: struct route_info { int priority; struct in_addr { unsigned int s_addr; } dstAddr; struct in_addr srcAddr; struct in_addr gateWay; char ifName[16]; } [1]

variable_types: err int

user_defined_types: struct rtmsg { unsigned char rtm_family; unsigned char rtm_dst_len; unsigned char rtm_src_len; unsigned char rtm_tos; unsigned char rtm_table; unsigned char rtm_protocol; unsigned char rtm_scope; unsigned char rtm_type; unsigned int rtm_flags; }

user_defined_types: struct route_info { int priority; struct in_addr dstAddr; struct in_addr srcAddr; struct in_addr gateWay; char ifName[16]; }


parseRoutes

decompiled_code:
__int64 __fastcall parseRoutes(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int16 *v3; // rbx
int v4; // ebp
int v5; // eax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax

result = 1LL;
if ( *(_BYTE *)(a1 + 16) == 2 && *(_BYTE *)(a1 + 20) == 0xFE )
{
v3 = (unsigned __int16 *)(a1 + 28);
v4 = *(_DWORD *)a1 - 28;
if ( v4 > 3 )
{
while ( 2 )
{
v5 = *v3;
if ( (unsigned __int16)v5 > 3u && v5 <= v4 )
{
switch ( v3[1] )
{
case 1u:
v10 = (v5 + 3) & 0xFFFFFFFC;
v4 -= v10;
*(_DWORD *)(a2 + 4) = *((_DWORD *)v3 + 1);
v3 = (unsigned __int16 *)((char *)v3 + v10);
if ( v4 > 3 )
continue;
goto LABEL_10;
case 4u:
if_indextoname(*((_DWORD *)v3 + 1), (char *)(a2 + 16));
v9 = (*v3 + 3) & 0xFFFFFFFC;
v4 -= v9;
v3 = (unsigned __int16 *)((char *)v3 + v9);
if ( v4 > 3 )
continue;
goto LABEL_10;
case 5u:
v8 = (v5 + 3) & 0xFFFFFFFC;
v4 -= v8;
*(_DWORD *)(a2 + 12) = *((_DWORD *)v3 + 1);
v3 = (unsigned __int16 *)((char *)v3 + v8);
if ( v4 > 3 )
continue;
goto LABEL_10;
case 6u:
*(_DWORD *)a2 = *((_DWORD *)v3 + 1);
goto LABEL_9;
case 7u:
v7 = (v5 + 3) & 0xFFFFFFFC;
v4 -= v7;
*(_DWORD *)(a2 + 8) = *((_DWORD *)v3 + 1);
v3 = (unsigned __int16 *)((char *)v3 + v7);
if ( v4 > 3 )
continue;
goto LABEL_10;
default:
LABEL_9:
v6 = (v5 + 3) & 0xFFFFFFFC;
v4 -= v6;
v3 = (unsigned __int16 *)((char *)v3 + v6);
if ( v4 <= 3 )
goto LABEL_10;
continue;
}
}
break;
}
}
LABEL_10:
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int16 *v3; // rbx
int v4; // ebp
int v5; // eax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax

result = 1LL;
if ( *(_BYTE *)(a1 + 16) == 2 && *(_BYTE *)(a1 + 20) == 0xFE )
{
v3 = (unsigned __int16 *)(a1 + 28);
v4 = *(_DWORD *)a1 - 28;
if ( v4 > 3 )
{
while ( 2 )
{
v5 = *v3;
if ( (unsigned __int16)v5 > 3u && v5 <= v4 )
{
switch ( v3[1] )
{
case 1u:
v10 = (v5 + 3) & 0xFFFFFFFC;
v4 -= v10;
*(_DWORD *)(a2 + 4) = *((_DWORD *)v3 + 1);
v3 = (unsigned __int16 *)((char *)v3 + v10);
if ( v4 > 3 )
continue;
goto LABEL_10;
case 4u:
if_indextoname(*((_DWORD *)v3 + 1), (char *)(a2 + 16));
v9 = (*v3 + 3) & 0xFFFFFFFC;
v4 -= v9;
v3 = (unsigned __int16 *)((char *)v3 + v9);
if ( v4 > 3 )
continue;
goto LABEL_10;
case 5u:
v8 = (v5 + 3) & 0xFFFFFFFC;
v4 -= v8;
*(_DWORD *)(a2 + 12) = *((_DWORD *)v3 + 1);
v3 = (unsigned __int16 *)((char *)v3 + v8);
if ( v4 > 3 )
continue;
goto LABEL_10;
case 6u:
*(_DWORD *)a2 = *((_DWORD *)v3 + 1);
goto LABEL_9;
case 7u:
v7 = (v5 + 3) & 0xFFFFFFFC;
v4 -= v7;
*(_DWORD *)(a2 + 8) = *((_DWORD *)v3 + 1);
v3 = (unsigned __int16 *)((char *)v3 + v7);
if ( v4 > 3 )
continue;
goto LABEL_10;
default:
LABEL_9:
v6 = (v5 + 3) & 0xFFFFFFFC;
v4 -= v6;
v3 = (unsigned __int16 *)((char *)v3 + v6);
if ( v4 <= 3 )
goto LABEL_10;
continue;
}
}
break;
}
}
LABEL_10:
result = 0LL;
}
return result;
}

original_code:
static int parseRoutes(struct nlmsghdr *nlHdr, struct route_info *rtInfo)
{
    struct rtmsg *rtMsg;
    struct rtattr *rtAttr;
    int rtLen = 0;
    rtMsg = (struct rtmsg *) ((void*)(((char*)nlHdr) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
    if (rtMsg->rtm_family != 2)
        return 1;
    if (rtMsg->rtm_table != RT_TABLE_MAIN)
        return 1;
    rtAttr = (struct rtattr *)((struct rtattr*)(((char*)(rtMsg)) + ( ((sizeof(struct rtmsg))+4U -1) & ~(4U -1) )));
    rtLen = ((nlHdr)->nlmsg_len - ( (((((sizeof(struct rtmsg))) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
    for (; ((rtLen) >= (int)sizeof(struct rtattr) && (rtAttr)->rta_len >= sizeof(struct rtattr) && (rtAttr)->rta_len <= (rtLen)); rtAttr = ((rtLen) -= ( (((rtAttr)->rta_len)+4U -1) & ~(4U -1) ), (struct rtattr*)(((char*)(rtAttr)) + ( (((rtAttr)->rta_len)+4U -1) & ~(4U -1) )))) {
        switch (rtAttr->rta_type) {
        case RTA_OIF:
            if_indextoname(*(int *) ((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))), rtInfo->ifName);
            break;
        case RTA_GATEWAY:
            rtInfo->gateWay.s_addr = *(u_int *)((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_PREFSRC:
            rtInfo->srcAddr.s_addr = *(u_int *)((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_DST:
            rtInfo->dstAddr .s_addr = *(u_int *)((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_PRIORITY:
            rtInfo->priority = *(int*)((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        default:
            ;
        }
    }
    return 0;
}

canonical_original_code:
static int parseRoutes(struct nlmsghdr *nlHdr, struct route_info *rtInfo)
{
    struct rtmsg *rtMsg;
    struct rtattr *rtAttr;
    int rtLen = 0;
    rtMsg = (struct rtmsg *) ((void *)(((char *)nlHdr) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
    if (rtMsg->rtm_family != 2)
        return 1;
    if (rtMsg->rtm_table != RT_TABLE_MAIN)
        return 1;
    rtAttr = (struct rtattr *)((struct rtattr *)(((char *)(rtMsg)) + ( ((sizeof(struct rtmsg))+4U -1) & ~(4U -1) )));
    rtLen = ((nlHdr)->nlmsg_len - ( (((((sizeof(struct rtmsg))) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
    for (; ((rtLen) >= (int)sizeof(struct rtattr) && (rtAttr)->rta_len >= sizeof(struct rtattr) && (rtAttr)->rta_len <= (rtLen)); rtAttr = ((rtLen) -= ( (((rtAttr)->rta_len)+4U -1) & ~(4U -1) ), (struct rtattr *)(((char *)(rtAttr)) + ( (((rtAttr)->rta_len)+4U -1) & ~(4U -1) )))) {
        switch (rtAttr->rta_type) {
        case RTA_OIF:
            if_indextoname(*(int *) ((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))), rtInfo->ifName);
            break;
        case RTA_GATEWAY:
            rtInfo->gateWay.s_addr = *(unsigned int *)((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_PREFSRC:
            rtInfo->srcAddr.s_addr = *(unsigned int *)((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_DST:
            rtInfo->dstAddr .s_addr = *(unsigned int *)((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_PRIORITY:
            rtInfo->priority = *(int *)((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        default:
            ;
        }
    }
    return 0;
}

variable_types: struct route_info { int priority; struct in_addr { unsigned int s_addr; } dstAddr; struct in_addr srcAddr; struct in_addr gateWay; char ifName[16]; } *

variable_types: struct rtmsg { unsigned char rtm_family; unsigned char rtm_dst_len; unsigned char rtm_src_len; unsigned char rtm_tos; unsigned char rtm_table; unsigned char rtm_protocol; unsigned char rtm_scope; unsigned char rtm_type; unsigned int rtm_flags; } *

variable_types: struct rtattr { unsigned short rta_len; unsigned short rta_type; } *

variable_types: rtLen int

user_defined_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; }


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

original_code:
static int
scripting_banner_selftest(void)
{
    return 0;
}

canonical_original_code:
static int scripting_banner_selftest()
{
    return 0;
}


decompiled_code:
__int64 __fastcall rawsock_get_adapter_ip(const char *a1)
{
int v1; // ebp
__int64 result; // rax
int *v3; // rax
char *v4; // rax
_WORD v5[10]; // [rsp+0h] [rbp-48h] BYREF
unsigned int v6; // [rsp+14h] [rbp-34h]

v1 = socket(2, 2, 0);
v5[8] = 2;
strcpy_s(v5, 16LL, a1);
if ( ioctl(v1, 0x8915uLL, v5) < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR:'%s': %s\n", a1, v4);
close(v1);
result = 0LL;
}
else
{
close(v1);
result = _bswap_32(v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v1; // ebp
__int64 result; // rax
int *v3; // rax
char *v4; // rax
_WORD v5[10]; // [rsp+0h] [rbp-48h] BYREF
unsigned int v6; // [rsp+14h] [rbp-34h]

v1 = socket(2, 2, 0);
v5[8] = 2;
strcpy_s(v5, 16LL, a1);
if ( ioctl(v1, 0x8915uLL, v5) < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR:'%s': %s\n", a1, v4);
close(v1);
result = 0LL;
}
else
{
close(v1);
result = func0(v6);
}
return result;
}

original_code:
unsigned
rawsock_get_adapter_ip(const char *ifname)
{
    int fd;
    struct ifreq ifr;
    struct sockaddr_in *sin;
    struct sockaddr *sa;
    int x;
    fd = socket(2, SOCK_DGRAM, 0);
    ifr.ifr_ifru.ifru_addr.sa_family = 2;
    strcpy_s(ifr.ifr_ifrn.ifrn_name, 16, ifname);
    x = ioctl(fd, 0x8915, &ifr);
    if (x < 0) {
        fprintf(stderr, "ERROR:'%s': %s\n", ifname, strerror((*__errno_location ())));
        close(fd);
        return 0;
    }
    close(fd);
    sa = &ifr.ifr_ifru.ifru_addr;
    sin = (struct sockaddr_in *)sa;
    return ntohl(sin->sin_addr.s_addr);
}

canonical_original_code:
unsigned int rawsock_get_adapter_ip(char *ifname)
{
    int fd;
    struct ifreq ifr;
    struct sockaddr_in *sin;
    struct sockaddr *sa;
    int x;
    fd = socket(2, SOCK_DGRAM, 0);
    ifr.ifr_ifru.ifru_addr.sa_family = 2;
    strcpy_s(ifr.ifr_ifrn.ifrn_name, 16, ifname);
    x = ioctl(fd, 0x8915, &ifr);
    if (x < 0) {
        fprintf(stderr, "ERROR:'%s': %s\n", ifname, strerror((*__errno_location ())));
        close(fd);
        return 0;
    }
    close(fd);
    sa = &ifr.ifr_ifru.ifru_addr;
    sin = (struct sockaddr_in *)sa;
    return ntohl(sin->sin_addr.s_addr);
}

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

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

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

variable_types: x int

return_type: unsigned int

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

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


decompiled_code:
char *__fastcall masscan_app_to_string(unsigned int a1)
{
if ( a1 <= 0x1E )
return CSWTCH_1[a1];
snprintf(tmp_1, 0x40uLL, "(%u)", a1);
return tmp_1;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1)
{
if ( a1 <= 0x1E )
return CSWTCH_1[a1];
snprintf(tmp_1, 0x40uLL, "(%u)", a1);
return tmp_1;
}

original_code:
const char *
masscan_app_to_string(enum ApplicationProtocol proto)
{
    static char tmp[64];
    switch (proto) {
    case PROTO_NONE: return "unknown";
    case PROTO_HEUR: return "unknown";
    case PROTO_SSH1: return "ssh";
    case PROTO_SSH2: return "ssh";
    case PROTO_HTTP: return "http";
    case PROTO_FTP: return "ftp";
    case PROTO_DNS_VERSIONBIND: return "dns-ver";
    case PROTO_SNMP: return "snmp";
    case PROTO_NBTSTAT: return "nbtstat";
    case PROTO_SSL3: return "ssl";
    case PROTO_SMB: return "smb";
    case PROTO_SMTP: return "smtp";
    case PROTO_POP3: return "pop";
    case PROTO_IMAP4: return "imap";
    case PROTO_UDP_ZEROACCESS: return "zeroaccess";
    case PROTO_X509_CERT: return "X509";
    case PROTO_HTML_TITLE: return "title";
    case PROTO_HTML_FULL: return "html";
    case PROTO_NTP: return "ntp";
    case PROTO_VULN: return "vuln";
    case PROTO_HEARTBLEED: return "heartbleed";
    case PROTO_TICKETBLEED: return "ticketbleed";
    case PROTO_VNC_RFB: return "vnc";
    case PROTO_SAFE: return "safe";
    case PROTO_MEMCACHED: return "memcached";
    case PROTO_SCRIPTING: return "scripting";
    case PROTO_VERSIONING: return "versioning";
    case PROTO_COAP: return "coap";
    case PROTO_TELNET: return "telnet";
    case PROTO_RDP: return "rdp";
    case PROTO_HTTP_SERVER: return "http.server";
    default:
        snprintf(tmp, sizeof(tmp), "(%u)", proto);
        return tmp;
    }
}

canonical_original_code:
char *masscan_app_to_string(enum ApplicationProtocol proto)
{
    static char tmp[64];
    switch (proto) {
    case PROTO_NONE: return "unknown";
    case PROTO_HEUR: return "unknown";
    case PROTO_SSH1: return "ssh";
    case PROTO_SSH2: return "ssh";
    case PROTO_HTTP: return "http";
    case PROTO_FTP: return "ftp";
    case PROTO_DNS_VERSIONBIND: return "dns-ver";
    case PROTO_SNMP: return "snmp";
    case PROTO_NBTSTAT: return "nbtstat";
    case PROTO_SSL3: return "ssl";
    case PROTO_SMB: return "smb";
    case PROTO_SMTP: return "smtp";
    case PROTO_POP3: return "pop";
    case PROTO_IMAP4: return "imap";
    case PROTO_UDP_ZEROACCESS: return "zeroaccess";
    case PROTO_X509_CERT: return "X509";
    case PROTO_HTML_TITLE: return "title";
    case PROTO_HTML_FULL: return "html";
    case PROTO_NTP: return "ntp";
    case PROTO_VULN: return "vuln";
    case PROTO_HEARTBLEED: return "heartbleed";
    case PROTO_TICKETBLEED: return "ticketbleed";
    case PROTO_VNC_RFB: return "vnc";
    case PROTO_SAFE: return "safe";
    case PROTO_MEMCACHED: return "memcached";
    case PROTO_SCRIPTING: return "scripting";
    case PROTO_VERSIONING: return "versioning";
    case PROTO_COAP: return "coap";
    case PROTO_TELNET: return "telnet";
    case PROTO_RDP: return "rdp";
    case PROTO_HTTP_SERVER: return "http.server";
    default:
        snprintf(tmp, sizeof(tmp), "(%u)", proto);
        return tmp;
    }
}

variable_types: enum ApplicationProtocol { PROTO_NONE=0, PROTO_HEUR=1, PROTO_SSH1=2, PROTO_SSH2=3, PROTO_HTTP=4, PROTO_FTP=5, PROTO_DNS_VERSIONBIND=6, PROTO_SNMP=7, PROTO_NBTSTAT=8, PROTO_SSL3=9, PROTO_SMB=10, PROTO_SMTP=11, PROTO_POP3=12, PROTO_IMAP4=13, PROTO_UDP_ZEROACCESS=14, PROTO_X509_CERT=15, PROTO_HTML_TITLE=16, PROTO_HTML_FULL=17, PROTO_NTP=18, PROTO_VULN=19, PROTO_HEARTBLEED=20, PROTO_TICKETBLEED=21, PROTO_VNC_RFB=22, PROTO_SAFE=23, PROTO_MEMCACHED=24, PROTO_SCRIPTING=25, PROTO_VERSIONING=26, PROTO_COAP=27, PROTO_TELNET=28, PROTO_RDP=29, PROTO_HTTP_SERVER=30, PROTO_end_of_list=31 }

variable_types:
tmp
char [64]

return_type: char *


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

original_code:
static int
imap4_selftest(void)
{
    return 0;
}

canonical_original_code:
static int imap4_selftest()
{
    return 0;
}


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

original_code:
static int
ftp_selftest(void)
{
    return 0;
}

canonical_original_code:
static int ftp_selftest()
{
    return 0;
}


decompiled_code:
_BOOL8 __fastcall readscan_filter_pass(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4)
{
_BOOL8 result; // rax

if ( !a3 )
goto LABEL_4;
if ( *(_QWORD *)(a3 + 120) && !(unsigned int)massip_has_ip(a3) )
return 0LL;
if ( *(_QWORD *)(a3 + 112) && !(unsigned int)massip_has_port(a3, a1) )
return 0LL;
LABEL_4:
result = 1LL;
if ( a4 )
{
if ( *(_DWORD *)(a4 + 8) )
result = (unsigned int)rangelist_is_contains(a4, a2) != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4)
{
_BOOL8 result; // rax

if ( !a3 )
goto LABEL_4;
if ( *(_QWORD *)(a3 + 120) && !(unsigned int)massip_has_ip(a3) )
return 0LL;
if ( *(_QWORD *)(a3 + 112) && !(unsigned int)massip_has_port(a3, a1) )
return 0LL;
LABEL_4:
result = 1LL;
if ( a4 )
{
if ( *(_DWORD *)(a4 + 8) )
result = (unsigned int)rangelist_is_contains(a4, a2) != 0;
}
return result;
}

original_code:
int
readscan_filter_pass(ipaddress ip, unsigned port, unsigned type,
              const struct MassIP *filter,
              const struct RangeList *btypes)
{
    if (filter && filter->count_ipv4s) {
        if (!massip_has_ip(filter, ip))
            return 0;
    }
    if (filter && filter->count_ports) {
        if (!massip_has_port(filter, port))
            return 0;
    }
    if (btypes && btypes->count) {
        if (!rangelist_is_contains(btypes, type))
            return 0;
    }
    return 1;
}

canonical_original_code:
int readscan_filter_pass(struct ipaddress ip, unsigned int port, unsigned int type, struct MassIP *filter, struct RangeList *btypes)
{
    if (filter && filter->count_ipv4s) {
        if (!massip_has_ip(filter, ip))
            return 0;
    }
    if (filter && filter->count_ports) {
        if (!massip_has_port(filter, port))
            return 0;
    }
    if (btypes && btypes->count) {
        if (!rangelist_is_contains(btypes, type))
            return 0;
    }
    return 1;
}

variable_types: struct ipaddress { union { unsigned int ipv4; struct ipv6address { unsigned long hi; unsigned long lo; } ipv6; }; unsigned char version; }

variable_types:
port
unsigned int

variable_types:
type
unsigned int

variable_types: struct MassIP { struct RangeList { struct Range { unsigned int begin; unsigned int end; } *list; unsigned int count; unsigned int max; unsigned int *picker; unsigned int is_sorted; } ipv4; struct Range6List { struct Range6 { struct ipv6address begin; struct ipv6address end; } *list; unsigned long count; unsigned long max; unsigned long *picker; unsigned int is_sorted; } ipv6; struct RangeList ports; unsigned long ipv4_index_threshold; unsigned long count_ports; unsigned long count_ipv4s; unsigned long count_ipv6s; } *

variable_types:
btypes
struct RangeList *

user_defined_types: struct MassIP { struct RangeList ipv4; struct Range6List ipv6; struct RangeList ports; unsigned long ipv4_index_threshold; unsigned long count_ports; unsigned long count_ipv4s; unsigned long count_ipv6s; }

user_defined_types: struct RangeList { struct Range *list; unsigned int count; unsigned int max; unsigned int *picker; unsigned int is_sorted; }

user_defined_types: struct Range6List { struct Range6 *list; unsigned long count; unsigned long max; unsigned long *picker; unsigned int is_sorted; }


decompiled_code:
// attributes: thunk
__int64 __fastcall rte_ring_sc_dequeue(_DWORD *a1, _QWORD *a2)
{
return rte_ring_sc_dequeue_bulk_constprop_0(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _QWORD *a2)
{
return func1(a1, a2);
}

original_code:
static inline int
rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
{
    return rte_ring_sc_dequeue_bulk(r, obj_p, 1);
}

variable_types: struct rte_ring { int flags; struct prod { unsigned int watermark; unsigned int sp_enqueue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } prod; struct cons { unsigned int sc_dequeue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } cons; void *ring[1]; } *

user_defined_types: struct rte_ring { int flags; struct prod prod; struct cons cons; void *ring[1]; }


decompiled_code:
__int64 __fastcall rte_ring_sp_enqueue(_DWORD *a1, __int64 a2)
{
__int64 v3; // [rsp+0h] [rbp-8h] BYREF

v3 = a2;
return rte_ring_sp_enqueue_bulk_constprop_0(a1, &v3);
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, __int64 a2)
{
__int64 v3; // [rsp+0h] [rbp-8h] BYREF

v3 = a2;
return func4(a1, &v3);
}

original_code:
static inline int
rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
{
    return rte_ring_sp_enqueue_bulk(r, &obj, 1);
}

variable_types:
obj
void *

user_defined_types: struct prod { unsigned int watermark; unsigned int sp_enqueue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; }

user_defined_types: struct cons { unsigned int sc_dequeue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; }


repo: robertovela/sisop

decompiled_code:
int __fastcall leggi_valore(int a1, int a2)
{
return semctl(a1, a2, 12);
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2)
{
return semctl(a1, a2, 12);
}

original_code:
int leggi_valore(int id_sem, int semaforo) {
  return semctl(id_sem,semaforo,12);
}

variable_types: semaforo int


RichiestaC

decompiled_code:
__int64 __fastcall RichiestaC(_DWORD *a1, int a2, int a3)
{
unsigned int v3; // er12
_DWORD *v5; // rax

v3 = 0;
Wait_Sem(a2, 1u);
Wait_Sem(a3, 1u);
v5 = a1;
while ( *v5 != 3 )
{
++v3;
++v5;
if ( v3 == 6 )
{
v5 = a1 + 6;
break;
}
}
*v5 = 4;
Signal_Sem(a3, 1u);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1, int a2, int a3)
{
unsigned int v3; // er12
_DWORD *v5; // rax

v3 = 0;
func8(a2, 1u);
func8(a3, 1u);
v5 = a1;
while ( *v5 != 3 )
{
++v3;
++v5;
if ( v3 == 6 )
{
v5 = a1 + 6;
break;
}
}
*v5 = 4;
func9(a3, 1u);
return v3;
}

original_code:
int RichiestaC (int*stato,int sem, int mutex){
 int indice=0;
 Wait_Sem(sem,1);
 Wait_Sem(mutex,1);
 while ((indice<=5)&&(stato[indice]!=3))
  indice++;
 stato[indice]=4;
 Signal_Sem(mutex,1);
 return indice;
}

canonical_original_code:
int RichiestaC(int *stato, int sem, int mutex){
 int indice = 0;
 Wait_Sem(sem,1);
 Wait_Sem(mutex,1);
 while ((indice<=5)&&(stato[indice]!=3))
  indice++;
 stato[indice]=4;
 Signal_Sem(mutex,1);
 return indice;
}

variable_types:
stato
int *

variable_types: sem int

variable_types: mutex int

variable_types: indice int


Consumo

decompiled_code:
__int64 __fastcall Consumo(int a1, __int64 a2)
{
__int64 v2; // r12

v2 = *(_QWORD *)(a2 + 8LL * a1);
sleep(2u);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, __int64 a2)
{
__int64 v2; // r12

v2 = *(_QWORD *)(a2 + 8LL * a1);
sleep(2u);
return v2;
}

original_code:
msg Consumo(int indice,msg * buffer){
 msg messaggio;
 messaggio=buffer[indice];
 sleep(2);
 return messaggio;
}

canonical_original_code:
long Consumo(int indice, long *buffer){
 long messaggio;
 messaggio=buffer[indice];
 sleep(2);
 return messaggio;
}

variable_types:
buffer
long *

variable_types: messaggio long

return_type: long


RilascioC

decompiled_code:
int __fastcall RilascioC(int a1, __int64 a2, int a3)
{
*(_DWORD *)(a2 + 4LL * a1) = 2;
return Signal_Sem(a3, 0);
}

canonical_decompiled_code:
int __fastcall func12(int a1, __int64 a2, int a3)
{
*(_DWORD *)(a2 + 4LL * a1) = 2;
return func9(a3, 0);
}

original_code:
void RilascioC(int indice,int*stato,int sem){
 stato[indice]=2;
 Signal_Sem(sem,0);
}

canonical_original_code:
void RilascioC(int indice, int *stato, int sem){
 stato[indice]=2;
 Signal_Sem(sem,0);
}


RichiestaP

decompiled_code:
__int64 __fastcall RichiestaP(_DWORD *a1, int a2, int a3)
{
unsigned int v3; // er12
_DWORD *v5; // rax

v3 = 0;
Wait_Sem(a2, 0);
Wait_Sem(a3, 0);
v5 = a1;
while ( *v5 != 2 )
{
++v3;
++v5;
if ( v3 == 6 )
{
v5 = a1 + 6;
break;
}
}
*v5 = 4;
Signal_Sem(a3, 0);
return v3;
}

original_code:
int RichiestaP (int*stato,int sem, int mutex){
 int indice=0;
 Wait_Sem(sem, 0);
 Wait_Sem(mutex,0);
 while ((indice<=5)&&(stato[indice]!=2))
  indice++;
 stato[indice]=4;
 Signal_Sem(mutex,0);
 return indice;
}

canonical_original_code:
int RichiestaP(int *stato, int sem, int mutex){
 int indice = 0;
 Wait_Sem(sem, 0);
 Wait_Sem(mutex,0);
 while ((indice<=5)&&(stato[indice]!=2))
  indice++;
 stato[indice]=4;
 Signal_Sem(mutex,0);
 return indice;
}


Produzione

decompiled_code:
void __fastcall Produzione(int a1, __int64 a2, __int64 a3)
{
*(_QWORD *)(a3 + 8LL * a1) = a2;
}

canonical_decompiled_code:
void __fastcall func15(int a1, __int64 a2, __int64 a3)
{
*(_QWORD *)(a3 + 8LL * a1) = a2;
}

original_code:
void Produzione(int indice,msg messaggio,msg *buffer){
 buffer[indice]=messaggio;
}

canonical_original_code:
void Produzione(int indice, long messaggio, long *buffer){
 buffer[indice]=messaggio;
}


RilascioP

decompiled_code:
int __fastcall RilascioP(int a1, __int64 a2, int a3)
{
*(_DWORD *)(a2 + 4LL * a1) = 3;
return Signal_Sem(a3, 1u);
}

canonical_decompiled_code:
int __fastcall func16(int a1, __int64 a2, int a3)
{
*(_DWORD *)(a2 + 4LL * a1) = 3;
return func9(a3, 1u);
}

original_code:
void RilascioP (int indice,int*stato,int sem){
 stato[indice]=3;
 Signal_Sem(sem,1);
}

canonical_original_code:
void RilascioP(int indice, int *stato, int sem){
 stato[indice]=3;
 Signal_Sem(sem,1);
}


Fornitore

decompiled_code:
__int64 __fastcall Fornitore(__int64 a1, _DWORD *a2, __int64 a3)
{
int v4; // er12
__int64 v5; // rax
__int64 v6; // rcx
__pid_t *v7; // r14
unsigned int v8; // eax
__int64 result; // rax

v4 = 15;
do
{
enter_monitor(a1);
if ( *a2 == 100 )
wait_condition(a1, 0LL);
v5 = 0LL;
while ( 1 )
{
v6 = (int)v5;
if ( (unsigned int)(*(_DWORD *)(a3 + 8 * v5 + 4) - 1) > 1 )
break;
if ( ++v5 == 100 )
{
v6 = 100LL;
break;
}
}
v7 = (__pid_t *)(a3 + 8 * v6);
v7[1] = 2;
leave_monitor(a1);
sleep(2u);
v8 = getpid();
printf("Fornitura effettuata dal Fornitore %d\n", v8);
*v7 = getpid();
enter_monitor(a1);
v7[1] = 1;
++*a2;
result = signal_condition(a1, 1LL);
--v4;
}
while ( v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _DWORD *a2, __int64 a3)
{
int v4; // er12
__int64 v5; // rax
__int64 v6; // rcx
__pid_t *v7; // r14
unsigned int v8; // eax
__int64 result; // rax

v4 = 15;
do
{
enter_monitor(a1);
if ( *a2 == 100 )
wait_condition(a1, 0LL);
v5 = 0LL;
while ( 1 )
{
v6 = (int)v5;
if ( (unsigned int)(*(_DWORD *)(a3 + 8 * v5 + 4) - 1) > 1 )
break;
if ( ++v5 == 100 )
{
v6 = 100LL;
break;
}
}
v7 = (__pid_t *)(a3 + 8 * v6);
v7[1] = 2;
leave_monitor(a1);
sleep(2u);
v8 = getpid();
printf("Fornitura effettuata dal Fornitore %d\n", v8);
*v7 = getpid();
enter_monitor(a1);
v7[1] = 1;
++*a2;
result = signal_condition(a1, 1LL);
--v4;
}
while ( v4 );
return result;
}

original_code:
void Fornitore(Monitor* M ,int* livello_scorte ,Magazzino* magazzino)
{
 int i,k;
 for(k=0;k<15;k++)
 {
  i=0;
  enter_monitor(M);
  if((*livello_scorte)==100)
   wait_condition(M,0);
  while(i<100 && ((*magazzino)[i].stato==1 || (*magazzino)[i].stato==2))
  {
   i++;
  }
  (*magazzino)[i].stato=2;
  leave_monitor(M);
  sleep(2);
  printf("Fornitura effettuata dal Fornitore %d\n",getpid());
  (*magazzino)[i].id_fornitore=getpid();
  enter_monitor(M);
  (*magazzino)[i].stato=1;
  (*livello_scorte)++;
  signal_condition(M,1);
 }
}

canonical_original_code:
void Fornitore(struct Monitor *M, int *livello_scorte, struct Scaffale (*magazzino)[100])
{
 int i; int k;
 for(k=0;k<15;k++)
 {
  i=0;
  enter_monitor(M);
  if((*livello_scorte)==100)
   wait_condition(M,0);
  while(i<100 && ((*magazzino)[i].stato==1 || (*magazzino)[i].stato==2))
  {
   i++;
  }
  (*magazzino)[i].stato=2;
  leave_monitor(M);
  sleep(2);
  printf("Fornitura effettuata dal Fornitore %d\n",getpid());
  (*magazzino)[i].id_fornitore=getpid();
  enter_monitor(M);
  (*magazzino)[i].stato=1;
  (*livello_scorte)++;
  signal_condition(M,1);
 }
}

variable_types: struct Monitor { int mutex; int num_var_cond; int id_conds; int *cond_counts; int id_shared; } *

variable_types: struct Scaffale { unsigned int id_fornitore; unsigned int stato; } (*)[100]

variable_types: i int

variable_types: k int


Cliente

decompiled_code:
__int64 __fastcall Cliente(__int64 a1, _DWORD *a2, __int64 a3)
{
int v3; // er14
__int64 v5; // rax
int v6; // ebp
unsigned int *v7; // r15
__int64 result; // rax

v3 = 15;
do
{
enter_monitor(a1);
if ( !*a2 )
wait_condition(a1, 1LL);
v5 = 0LL;
while ( 1 )
{
v6 = v5;
if ( (*(_DWORD *)(a3 + 8 * v5 + 4) & 0xFFFFFFFD) != 0 )
break;
if ( ++v5 == 100 )
{
v6 = 100;
break;
}
}
v7 = (unsigned int *)(a3 + 8LL * v6);
v7[1] = 2;
leave_monitor(a1);
sleep(2u);
printf("Acquisto effettuato, merce venduta dal Fornitore %d \n", *v7);
printf("magazzino[%d].stato=%d\n", (unsigned int)v6, v7[1]);
enter_monitor(a1);
v7[1] = 0;
--*a2;
result = signal_condition(a1, 0LL);
--v3;
}
while ( v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _DWORD *a2, __int64 a3)
{
int v3; // er14
__int64 v5; // rax
int v6; // ebp
unsigned int *v7; // r15
__int64 result; // rax

v3 = 15;
do
{
enter_monitor(a1);
if ( !*a2 )
wait_condition(a1, 1LL);
v5 = 0LL;
while ( 1 )
{
v6 = v5;
if ( (*(_DWORD *)(a3 + 8 * v5 + 4) & 0xFFFFFFFD) != 0 )
break;
if ( ++v5 == 100 )
{
v6 = 100;
break;
}
}
v7 = (unsigned int *)(a3 + 8LL * v6);
v7[1] = 2;
leave_monitor(a1);
sleep(2u);
printf("Acquisto effettuato, merce venduta dal Fornitore %d \n", *v7);
printf("magazzino[%d].stato=%d\n", (unsigned int)v6, v7[1]);
enter_monitor(a1);
v7[1] = 0;
--*a2;
result = signal_condition(a1, 0LL);
--v3;
}
while ( v3 );
return result;
}

original_code:
void Cliente(Monitor* M ,int* livello_scorte ,Magazzino* magazzino)
{
 int i,k;
 for(k=0;k<15;k++)
 {
  i=0;
  enter_monitor(M);
  if((*livello_scorte)==0)
   wait_condition(M,1);
  while(i<100 && ((*magazzino)[i].stato==0 || (*magazzino)[i].stato==2))
  {
   i++;
  }
  (*magazzino)[i].stato=2;
  leave_monitor(M);
  sleep(2);
  printf("Acquisto effettuato, merce venduta dal Fornitore %d \n",(*magazzino)[i].id_fornitore);
  printf("magazzino[%d].stato=%d\n",i,(*magazzino)[i].stato);
  enter_monitor(M);
  (*magazzino)[i].stato=0;
  (*livello_scorte)--;
  signal_condition(M,0);
 }
}

canonical_original_code:
void Cliente(struct Monitor *M, int *livello_scorte, struct Scaffale (*magazzino)[100])
{
 int i; int k;
 for(k=0;k<15;k++)
 {
  i=0;
  enter_monitor(M);
  if((*livello_scorte)==0)
   wait_condition(M,1);
  while(i<100 && ((*magazzino)[i].stato==0 || (*magazzino)[i].stato==2))
  {
   i++;
  }
  (*magazzino)[i].stato=2;
  leave_monitor(M);
  sleep(2);
  printf("Acquisto effettuato, merce venduta dal Fornitore %d \n",(*magazzino)[i].id_fornitore);
  printf("magazzino[%d].stato=%d\n",i,(*magazzino)[i].stato);
  enter_monitor(M);
  (*magazzino)[i].stato=0;
  (*livello_scorte)--;
  signal_condition(M,0);
 }
}

user_defined_types: struct Monitor { int mutex; int num_var_cond; int id_conds; int *cond_counts; int id_shared; }

user_defined_types: struct Scaffale { unsigned int id_fornitore; unsigned int stato; }


Servizio

decompiled_code:
unsigned int __fastcall Servizio(__int64 a1, __int64 a2)
{
int v2; // ebp
unsigned int v3; // eax
void *v4; // r14
int v5; // eax
unsigned int v6; // er13
unsigned int v7; // er15
unsigned int v8; // eax
unsigned int result; // eax

v2 = 20;
v3 = time(0LL);
srand(v3);
do
{
v4 = &unk_314;
InizioScrittura(a1, a2);
*(_DWORD *)a2 = rand() % 101 - 50;
*(_DWORD *)(a2 + 4) = rand() % 101;
v5 = rand();
v6 = *(_DWORD *)(a2 + 4);
v7 = *(_DWORD *)a2;
LOWORD(v5) = v5 % 2;
*(_WORD *)(a2 + 8) = v5;
if ( (_WORD)v5 )
v4 = &unk_311;
v8 = getpid();
printf(format, v8, v7, v6, v4);
FineScrittura(a1, a2);
result = sleep(2u);
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func4(__int64 a1, __int64 a2)
{
int v2; // ebp
unsigned int v3; // eax
void *v4; // r14
int v5; // eax
unsigned int v6; // er13
unsigned int v7; // er15
unsigned int v8; // eax
unsigned int result; // eax

v2 = 20;
v3 = time(0LL);
srand(v3);
do
{
v4 = &unk_314;
func2(a1, a2);
*(_DWORD *)a2 = rand() % 101 - 50;
*(_DWORD *)(a2 + 4) = rand() % 101;
v5 = rand();
v6 = *(_DWORD *)(a2 + 4);
v7 = *(_DWORD *)a2;
LOWORD(v5) = v5 % 2;
*(_WORD *)(a2 + 8) = v5;
if ( (_WORD)v5 )
v4 = &unk_311;
v8 = getpid();
printf(format, v8, v7, v6, v4);
func3(a1, a2);
result = sleep(2u);
--v2;
}
while ( v2 );
return result;
}

original_code:
void Servizio(Monitor* m, Buffer * buf){
 srand(time(0));
 int i;
 for(i=0; i<20; i++) {
  InizioScrittura(m,buf);
  buf->meteo.temperatura = (rand()%101)-50;
  buf->meteo.umidita = rand()%101;
  buf->meteo.pioggia = rand()%2;
  printf("<%d> scrittura: Temperatura=%d, Umidità=%d, Pioggia=%s\n", getpid(), buf->meteo.temperatura, buf->meteo.umidita, (buf->meteo.pioggia ? "si" : "no") );
  FineScrittura(m,buf);
  sleep(2);
 }
}

canonical_original_code:
void Servizio(struct Monitor *m, struct Buffer *buf){
 srand(time(0));
 int i;
 for(i=0; i<20; i++) {
  InizioScrittura(m,buf);
  buf->meteo.temperatura = (rand()%101)-50;
  buf->meteo.umidita = rand()%101;
  buf->meteo.pioggia = rand()%2;
  printf("<%d> scrittura: Temperatura=%d, Umidità=%d, Pioggia=%s\n", getpid(), buf->meteo.temperatura, buf->meteo.umidita, (buf->meteo.pioggia ? "si" : "no") );
  FineScrittura(m,buf);
  sleep(2);
 }
}

variable_types: struct Monitor { int mutex; int urgent_sem; int num_var_cond; int id_conds; int id_shared; int *cond_counts; int *urgent_count; } *

variable_types: struct Buffer { struct meteo { int temperatura; unsigned int umidita; unsigned short pioggia; } meteo; unsigned short occupato; unsigned int numlettori; } *

user_defined_types: struct Buffer { struct meteo meteo; unsigned short occupato; unsigned int numlettori; }


Utente

decompiled_code:
unsigned int __fastcall Utente(__int64 a1, __int64 a2)
{
int v2; // ebp
void *v3; // r14
unsigned int v4; // er15
unsigned int v5; // er13
unsigned int v6; // eax
unsigned int result; // eax

v2 = 10;
do
{
v3 = &unk_314;
InizioLettura(a1, a2);
v4 = *(_DWORD *)a2;
if ( *(_WORD *)(a2 + 8) )
v3 = &unk_311;
v5 = *(_DWORD *)(a2 + 4);
v6 = getpid();
printf(aDLetturaTemper, v6, v4, v5, v3);
FineLettura(a1, a2);
result = sleep(1u);
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func5(__int64 a1, __int64 a2)
{
int v2; // ebp
void *v3; // r14
unsigned int v4; // er15
unsigned int v5; // er13
unsigned int v6; // eax
unsigned int result; // eax

v2 = 10;
do
{
v3 = &unk_314;
func0(a1, a2);
v4 = *(_DWORD *)a2;
if ( *(_WORD *)(a2 + 8) )
v3 = &unk_311;
v5 = *(_DWORD *)(a2 + 4);
v6 = getpid();
printf(aDLetturaTemper, v6, v4, v5, v3);
func1(a1, a2);
result = sleep(1u);
--v2;
}
while ( v2 );
return result;
}

original_code:
void Utente(Monitor* m, Buffer * buf) {
 int i;
 for(i=0; i<10; i++) {
  InizioLettura(m,buf);
  printf("<%d> lettura: Temperatura=%d, Umidità=%d, Pioggia=%s\n", getpid(), buf->meteo.temperatura, buf->meteo.umidita, (buf->meteo.pioggia ? "si" : "no") );
  FineLettura(m,buf);
  sleep(1);
 }
}

canonical_original_code:
void Utente(struct Monitor *m, struct Buffer *buf) {
 int i;
 for(i=0; i<10; i++) {
  InizioLettura(m,buf);
  printf("<%d> lettura: Temperatura=%d, Umidità=%d, Pioggia=%s\n", getpid(), buf->meteo.temperatura, buf->meteo.umidita, (buf->meteo.pioggia ? "si" : "no") );
  FineLettura(m,buf);
  sleep(1);
 }
}

user_defined_types: struct Monitor { int mutex; int urgent_sem; int num_var_cond; int id_conds; int id_shared; int *cond_counts; int *urgent_count; }

user_defined_types: struct meteo { int temperatura; unsigned int umidita; unsigned short pioggia; }


InizioLettura

decompiled_code:
__int64 __fastcall InizioLettura(__int64 a1, __int64 a2)
{
int v2; // eax

enter_monitor();
v2 = *(_DWORD *)(a2 + 16);
if ( *(_WORD *)(a2 + 12) && !v2 )
{
wait_condition(a1, 0LL);
v2 = *(_DWORD *)(a2 + 16);
}
*(_WORD *)(a2 + 12) = 1;
*(_DWORD *)(a2 + 16) = v2 + 1;
signal_condition(a1, 0LL);
return leave_monitor(a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
int v2; // eax

enter_monitor();
v2 = *(_DWORD *)(a2 + 16);
if ( *(_WORD *)(a2 + 12) && !v2 )
{
wait_condition(a1, 0LL);
v2 = *(_DWORD *)(a2 + 16);
}
*(_WORD *)(a2 + 12) = 1;
*(_DWORD *)(a2 + 16) = v2 + 1;
signal_condition(a1, 0LL);
return leave_monitor(a1);
}

original_code:
void InizioLettura(Monitor* m, Buffer * buf){
 enter_monitor(m);
 if (buf->occupato && buf->numlettori==0)
  wait_condition(m,0);
 buf->occupato = 1;
 buf->numlettori=buf->numlettori+1;
 signal_condition(m,0);
 leave_monitor(m);
}

canonical_original_code:
void InizioLettura(struct Monitor *m, struct Buffer *buf){
 enter_monitor(m);
 if (buf->occupato && buf->numlettori==0)
  wait_condition(m,0);
 buf->occupato = 1;
 buf->numlettori=buf->numlettori+1;
 signal_condition(m,0);
 leave_monitor(m);
}


FineLettura

decompiled_code:
__int64 __fastcall FineLettura(__int64 a1, __int64 a2)
{
enter_monitor();
if ( (*(_DWORD *)(a2 + 16))-- == 1 )
{
*(_WORD *)(a2 + 12) = 0;
signal_condition(a1, 1LL);
}
return leave_monitor(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
enter_monitor();
if ( (*(_DWORD *)(a2 + 16))-- == 1 )
{
*(_WORD *)(a2 + 12) = 0;
signal_condition(a1, 1LL);
}
return leave_monitor(a1);
}

original_code:
void FineLettura(Monitor* m, Buffer * buf) {
 enter_monitor(m);
 buf->numlettori=buf->numlettori-1;
 if (buf->numlettori==0) {
       buf->occupato=0;
  signal_condition(m,1);
 }
 leave_monitor(m);
}

canonical_original_code:
void FineLettura(struct Monitor *m, struct Buffer *buf) {
 enter_monitor(m);
 buf->numlettori=buf->numlettori-1;
 if (buf->numlettori==0) {
       buf->occupato=0;
  signal_condition(m,1);
 }
 leave_monitor(m);
}


InizioScrittura

decompiled_code:
__int64 __fastcall InizioScrittura(__int64 a1, __int64 a2)
{
enter_monitor();
if ( *(_WORD *)(a2 + 12) )
wait_condition(a1, 1LL);
*(_WORD *)(a2 + 12) = 1;
return leave_monitor(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
enter_monitor();
if ( *(_WORD *)(a2 + 12) )
wait_condition(a1, 1LL);
*(_WORD *)(a2 + 12) = 1;
return leave_monitor(a1);
}

original_code:
void InizioScrittura(Monitor* m,Buffer*buf){
 enter_monitor(m);
 if (buf->occupato)
  wait_condition(m,1);
 buf->occupato = 1;
 leave_monitor(m);
}

canonical_original_code:
void InizioScrittura(struct Monitor *m, struct Buffer *buf){
 enter_monitor(m);
 if (buf->occupato)
  wait_condition(m,1);
 buf->occupato = 1;
 leave_monitor(m);
}


FineScrittura

decompiled_code:
__int64 __fastcall FineScrittura(__int64 a1, __int64 a2)
{
__int64 result; // rax

enter_monitor();
if ( (int)queue_condition(a1, 1LL) <= 0 )
{
if ( (int)queue_condition(a1, 0LL) > 0 )
signal_condition(a1, 0LL);
else
*(_WORD *)(a2 + 12) = 0;
result = leave_monitor(a1);
}
else
{
signal_condition(a1, 1LL);
result = leave_monitor(a1);
}
return result;
}

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

enter_monitor();
if ( (int)queue_condition(a1, 1LL) <= 0 )
{
if ( (int)queue_condition(a1, 0LL) > 0 )
signal_condition(a1, 0LL);
else
*(_WORD *)(a2 + 12) = 0;
result = leave_monitor(a1);
}
else
{
signal_condition(a1, 1LL);
result = leave_monitor(a1);
}
return result;
}

original_code:
void FineScrittura(Monitor* m, Buffer*buf){
 enter_monitor(m);
 if (queue_condition(m,1)>0) {
  signal_condition(m,1);
        } else if (queue_condition(m,0)>0) {
  signal_condition(m,0);
 } else {
  buf->occupato = 0;
 }
 leave_monitor(m);
}

canonical_original_code:
void FineScrittura(struct Monitor *m, struct Buffer *buf){
 enter_monitor(m);
 if (queue_condition(m,1)>0) {
  signal_condition(m,1);
        } else if (queue_condition(m,0)>0) {
  signal_condition(m,0);
 } else {
  buf->occupato = 0;
 }
 leave_monitor(m);
}


InizioConsumo

decompiled_code:
int InizioConsumo()
{
int result; // eax

for ( result = pthread_mutex_lock(&mutex); !ok_consumo; result = ok_consumo )
pthread_cond_wait(&ok_cons_cv, &mutex);
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

for ( result = pthread_mutex_lock(&mutex); !ok_consumo; result = ok_consumo )
pthread_cond_wait(&ok_cons_cv, &mutex);
return result;
}

original_code:
void InizioConsumo(){
 pthread_mutex_lock(&mutex);
 while (ok_consumo==0)
  pthread_cond_wait(&ok_cons_cv,&mutex);
}


FineConsumo

decompiled_code:
int FineConsumo()
{
ok_produzione = 1;
ok_consumo = 0;
pthread_cond_signal(&ok_prod_cv);
return pthread_mutex_unlock(&mutex);
}

canonical_decompiled_code:
int func1()
{
ok_produzione = 1;
ok_consumo = 0;
pthread_cond_signal(&ok_prod_cv);
return pthread_mutex_unlock(&mutex);
}

original_code:
void FineConsumo(){
        ok_produzione = 1;
 ok_consumo = 0;
 pthread_cond_signal(&ok_prod_cv);
 pthread_mutex_unlock(&mutex);
}


InizioProduzione

decompiled_code:
int InizioProduzione()
{
int result; // eax

for ( result = pthread_mutex_lock(&mutex); !ok_produzione; result = ok_produzione )
pthread_cond_wait(&ok_prod_cv, &mutex);
return result;
}

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

for ( result = pthread_mutex_lock(&mutex); !ok_produzione; result = ok_produzione )
pthread_cond_wait(&ok_prod_cv, &mutex);
return result;
}

original_code:
void InizioProduzione(){
 pthread_mutex_lock(&mutex);
 while (ok_produzione==0)
  pthread_cond_wait(&ok_prod_cv,&mutex);
}


FineProduzione

decompiled_code:
int FineProduzione()
{
ok_consumo = 1;
ok_produzione = 0;
pthread_cond_signal(&ok_cons_cv);
return pthread_mutex_unlock(&mutex);
}

canonical_decompiled_code:
int func3()
{
ok_consumo = 1;
ok_produzione = 0;
pthread_cond_signal(&ok_cons_cv);
return pthread_mutex_unlock(&mutex);
}

original_code:
void FineProduzione (){
 ok_consumo = 1;
 ok_produzione = 0;
 pthread_cond_signal(&ok_cons_cv);
 pthread_mutex_unlock(&mutex);
}

canonical_original_code:
void FineProduzione(){
 ok_consumo = 1;
 ok_produzione = 0;
 pthread_cond_signal(&ok_cons_cv);
 pthread_mutex_unlock(&mutex);
}


Produttore

decompiled_code:
void __fastcall __noreturn Produttore(unsigned int a1)
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

InizioProduzione();
gettimeofday(&tv, &tz);
mess = tv.tv_usec;
printf("Thread#%d Valore PRODOTTO = <%d> \n", a1, tv.tv_usec);
FineProduzione();
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(unsigned int a1)
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

func2();
gettimeofday(&tv, &tz);
mess = tv.tv_usec;
printf("Thread#%d Valore PRODOTTO = <%d> \n", a1, tv.tv_usec);
func3();
pthread_exit(0LL);
}

original_code:
void *Produttore(void* id) {
  InizioProduzione();
                struct timeval t1;
                struct timezone t2;
                gettimeofday(&t1,&t2);
                msg val =t1.tv_usec;
         int my_id = (int) id;
                mess = val;
         printf("Thread#%d Valore PRODOTTO = <%d> \n", my_id, mess);
  FineProduzione();
  pthread_exit(((void *)0));
}

canonical_original_code:
void *Produttore(void *id) {
  InizioProduzione();
                struct timeval t1;
                struct timezone t2;
                gettimeofday(&t1,&t2);
                long val = t1.tv_usec;
         int my_id = (int) id;
                mess = val;
         printf("Thread#%d Valore PRODOTTO = <%d> \n", my_id, mess);
  FineProduzione();
  pthread_exit(((void *)0));
}

variable_types:
id
void *

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

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }

variable_types: val long

return_type: void *


Consumatore

decompiled_code:
void __fastcall __noreturn Consumatore(unsigned int a1)
{
InizioConsumo();
printf("Thread #%d, valore CONSUMATO = <%d> \n", a1, mess);
FineConsumo();
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(unsigned int a1)
{
func0();
printf("Thread #%d, valore CONSUMATO = <%d> \n", a1, mess);
func1();
pthread_exit(0LL);
}

original_code:
void * Consumatore (void * id) {
  InizioConsumo();
  int my_id = (int) id;
         printf("Thread #%d, valore CONSUMATO = <%d> \n", my_id, mess);
  FineConsumo();
  pthread_exit(((void *)0));
}

canonical_original_code:
void *Consumatore(void *id) {
  InizioConsumo();
  int my_id = (int) id;
         printf("Thread #%d, valore CONSUMATO = <%d> \n", my_id, mess);
  FineConsumo();
  pthread_exit(((void *)0));
}


Prodotto

decompiled_code:
void __fastcall __noreturn Prodotto(void *a1)
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
unsigned int v2; // [rsp+8h] [rbp-10h]

v1 = *(_QWORD *)a1;
v2 = *((_DWORD *)a1 + 3) * *((_DWORD *)a1 + 2);
pthread_mutex_lock(&mutex);
printf("\nSono Prodotto di Server. Invio del calcolo: %d\n\n", v2);
if ( msgsnd(id_s, &v1, 8uLL, 0) >= 0 )
{
pthread_mutex_unlock(&mutex);
free(a1);
pthread_exit(0LL);
}
perror("Errore invio risposta server");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
unsigned int v2; // [rsp+8h] [rbp-10h]

v1 = *(_QWORD *)a1;
v2 = *((_DWORD *)a1 + 3) * *((_DWORD *)a1 + 2);
pthread_mutex_lock(&mutex);
printf("\nSono Prodotto di Server. Invio del calcolo: %d\n\n", v2);
if ( msgsnd(id_s, &v1, 8uLL, 0) >= 0 )
{
pthread_mutex_unlock(&mutex);
free(a1);
pthread_exit(0LL);
}
perror("Errore invio risposta server");
exit(1);
}

original_code:
void* Prodotto(void* v){
 int ret;
 Buffer_C* BC=(Buffer_C*) v;
 Buffer_S BS;
 BS.pid=BC->pid;
 BS.v3=BC->v1*BC->v2;
 pthread_mutex_lock(&mutex);
  printf("\nSono Prodotto di Server. Invio del calcolo: %d\n\n",BS.v3);
  ret = msgsnd(id_s, &BS, sizeof(Buffer_S)-sizeof(long), 0);
  if(ret < 0) {
   perror("Errore invio risposta server");
   exit(1);
  }
 pthread_mutex_unlock(&mutex);
 free(BC);
 pthread_exit(((void *)0));
}

canonical_original_code:
void *Prodotto(void *v){
 int ret;
 struct Buffer_C *BC = (Buffer_C*) v;
 struct Buffer_S BS;
 BS.pid=BC->pid;
 BS.v3=BC->v1*BC->v2;
 pthread_mutex_lock(&mutex);
  printf("\nSono Prodotto di Server. Invio del calcolo: %d\n\n",BS.v3);
  ret = msgsnd(id_s, &BS, sizeof(Buffer_S)-sizeof(long), 0);
  if(ret < 0) {
   perror("Errore invio risposta server");
   exit(1);
  }
 pthread_mutex_unlock(&mutex);
 free(BC);
 pthread_exit(((void *)0));
}

variable_types:
v
void *

variable_types: ret int

variable_types: struct Buffer_C { long pid; int v1; int v2; } *

variable_types:
BS
struct Buffer_S { long pid; int v3; }


client

decompiled_code:
int client()
{
unsigned int v0; // ebx
unsigned int v1; // eax
__int64 i; // rcx
unsigned int v3; // eax
__int64 v4; // rsi
int result; // eax
_DWORD v6[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 msgp; // [rsp+10h] [rbp-18h] BYREF
unsigned int v8; // [rsp+18h] [rbp-10h]
unsigned int v9; // [rsp+1Ch] [rbp-Ch]

v0 = 0;
v1 = getpid();
srand(v1);
msgp = getpid();
v8 = rand() % 101;
v9 = rand() % 101;
for ( i = v9; ; i = v9 )
{
printf("Richiesta %d Inviata (%d, %d) [PID=%ld]\n\n", v0, v8, i, msgp);
if ( msgsnd(id_c, &msgp, 8uLL, 0) < 0 )
{
perror("Errore invio richiesta client");
exit(1);
}
v3 = getpid();
if ( (int)msgrcv(id_s, v6, 8uLL, v3, 0) < 0 )
{
perror("Errore ricezione risposta client");
exit(1);
}
v4 = v0++;
result = printf("Risposta %d Ricevuta (%d) [PID=%ld]\n\n", v4, v6[2], msgp);
if ( v0 == 5 )
break;
}
return result;
}

canonical_decompiled_code:
int func8()
{
unsigned int v0; // ebx
unsigned int v1; // eax
__int64 i; // rcx
unsigned int v3; // eax
__int64 v4; // rsi
int result; // eax
_DWORD v6[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 msgp; // [rsp+10h] [rbp-18h] BYREF
unsigned int v8; // [rsp+18h] [rbp-10h]
unsigned int v9; // [rsp+1Ch] [rbp-Ch]

v0 = 0;
v1 = getpid();
srand(v1);
msgp = getpid();
v8 = rand() % 101;
v9 = rand() % 101;
for ( i = v9; ; i = v9 )
{
printf("Richiesta %d Inviata (%d, %d) [PID=%ld]\n\n", v0, v8, i, msgp);
if ( msgsnd(id_c, &msgp, 8uLL, 0) < 0 )
{
perror("Errore invio richiesta client");
exit(1);
}
v3 = getpid();
if ( (int)msgrcv(id_s, v6, 8uLL, v3, 0) < 0 )
{
perror("Errore ricezione risposta client");
exit(1);
}
v4 = v0++;
result = printf("Risposta %d Ricevuta (%d) [PID=%ld]\n\n", v4, v6[2], msgp);
if ( v0 == 5 )
break;
}
return result;
}

original_code:
void client(){
 int k;
 int ret;
 srand(getpid());
 Buffer_S BS;
 Buffer_C BC;
 BC.pid=getpid();
 BC.v1=rand()%101;
 BC.v2=rand()%101;
 for(k=0;k<5;k++){
  printf("Richiesta %d Inviata (%d, %d) [PID=%ld]\n\n", k, BC.v1, BC.v2, BC.pid);
  ret = msgsnd(id_c, &BC, sizeof(Buffer_C)-sizeof(long), 0);
  if(ret < 0) {
   perror("Errore invio richiesta client");
   exit(1);
  }
  ret = msgrcv(id_s, &BS, sizeof(Buffer_S)-sizeof(long), getpid(), 0);
  if(ret < 0) {
   perror("Errore ricezione risposta client");
   exit(1);
  }
  printf("Risposta %d Ricevuta (%d) [PID=%ld]\n\n", k, BS.v3, BC.pid);
 }
}

canonical_original_code:
void client(){
 int k;
 int ret;
 srand(getpid());
 struct Buffer_S BS;
 struct Buffer_C BC;
 BC.pid=getpid();
 BC.v1=rand()%101;
 BC.v2=rand()%101;
 for(k=0;k<5;k++){
  printf("Richiesta %d Inviata (%d, %d) [PID=%ld]\n\n", k, BC.v1, BC.v2, BC.pid);
  ret = msgsnd(id_c, &BC, sizeof(Buffer_C)-sizeof(long), 0);
  if(ret < 0) {
   perror("Errore invio richiesta client");
   exit(1);
  }
  ret = msgrcv(id_s, &BS, sizeof(Buffer_S)-sizeof(long), getpid(), 0);
  if(ret < 0) {
   perror("Errore ricezione risposta client");
   exit(1);
  }
  printf("Risposta %d Ricevuta (%d) [PID=%ld]\n\n", k, BS.v3, BC.pid);
 }
}

variable_types: struct Buffer_C { long pid; int v1; int v2; }


server

decompiled_code:
void __noreturn server()
{
_QWORD *v0; // rax
int v1; // edi
_QWORD *v2; // r12
pthread_t newthread; // [rsp+8h] [rbp-50h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-48h] BYREF

pthread_attr_init(&attr);
pthread_mutex_init(&mutex, 0LL);
while ( 1 )
{
v0 = malloc(0x10uLL);
v1 = id_c;
*v0 = 0LL;
v2 = v0;
v0[1] = 0LL;
if ( (int)msgrcv(v1, v0, 8uLL, 0LL, 0) < 0 )
break;
if ( v2[1] == -1LL )
exit(0);
pthread_create(&newthread, &attr, (void *(*)(void *))Prodotto, v2);
}
perror("Errore ricezione richiesta server");
exit(1);
}

canonical_decompiled_code:
void __noreturn func9()
{
_QWORD *v0; // rax
int v1; // edi
_QWORD *v2; // r12
pthread_t newthread; // [rsp+8h] [rbp-50h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-48h] BYREF

pthread_attr_init(&attr);
pthread_mutex_init(&mutex, 0LL);
while ( 1 )
{
v0 = malloc(0x10uLL);
v1 = id_c;
*v0 = 0LL;
v2 = v0;
v0[1] = 0LL;
if ( (int)msgrcv(v1, v0, 8uLL, 0LL, 0) < 0 )
break;
if ( v2[1] == -1LL )
exit(0);
pthread_create(&newthread, &attr, (void *(*)(void *))Prodotto, v2);
}
perror("Errore ricezione richiesta server");
exit(1);
}

original_code:
void server(){
 int k;
 int ret;
 pthread_attr_t attr;
 pthread_attr_init(&attr);
 pthread_mutex_init(&mutex,((void *)0));
 while(1){
  Buffer_C * BC = (Buffer_C*) malloc(sizeof(Buffer_C));
  BC->v1=0;
  BC->v2=0;
  BC->pid=0;
  ret = msgrcv(id_c, BC, sizeof(Buffer_C)-sizeof(long), 0, 0);
  if(ret < 0) {
   perror("Errore ricezione richiesta server");
   exit(1);
  }
  if(BC->v1==-1 && BC->v2==-1){
   exit(0);
  }
  pthread_t t;
  pthread_create(&t, &attr, Prodotto, (void*) BC);
 }
}

canonical_original_code:
void server(){
 int k;
 int ret;
 union pthread_attr_t attr;
 pthread_attr_init(&attr);
 pthread_mutex_init(&mutex,((void *)0));
 while(1){
  struct Buffer_C *BC = (Buffer_C*) malloc(sizeof(Buffer_C));
  BC->v1=0;
  BC->v2=0;
  BC->pid=0;
  ret = msgrcv(id_c, BC, sizeof(Buffer_C)-sizeof(long), 0, 0);
  if(ret < 0) {
   perror("Errore ricezione richiesta server");
   exit(1);
  }
  if(BC->v1==-1 && BC->v2==-1){
   exit(0);
  }
  unsigned long t;
  pthread_create(&t, &attr, Prodotto, (void *) BC);
 }
}

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types:
t
unsigned long

user_defined_types: struct Buffer_C { long pid; int v1; int v2; }


prenota

decompiled_code:
__int64 __fastcall prenota(unsigned int a1, __int64 a2)
{
accedi_prenotati();
++*(_DWORD *)(a2 + 20);
return lascia_prenotati(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, __int64 a2)
{
func16();
++*(_DWORD *)(a2 + 20);
return func17(a1);
}

original_code:
void prenota(int semid,esame_t* esame){
 accedi_prenotati(semid);
 esame->numero_prenotati += 1;
 lascia_prenotati(semid);
}

canonical_original_code:
void prenota(int semid, struct tipo_esame *esame){
 accedi_prenotati(semid);
 esame->numero_prenotati += 1;
 lascia_prenotati(semid);
}

variable_types: semid int

variable_types: struct tipo_esame { char prossimo_appello[20]; int numero_prenotati; int numero_lettori; } *


decompiled_code:
__int64 __fastcall stampa_appello(unsigned int a1, const char *a2)
{
unsigned int v2; // eax

inizio_lettura();
v2 = getpid();
printf("Processo studente %d - Data di appello: %s\n", v2, a2);
return fine_lettura(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, const char *a2)
{
unsigned int v2; // eax

func12();
v2 = getpid();
printf("Processo studente %d - Data di appello: %s\n", v2, a2);
return func13(a1, a2);
}

original_code:
void stampa_appello(int semid,esame_t* esame){
 inizio_lettura(semid,esame);
 printf("Processo studente %d - Data di appello: %s\n",getpid(),esame->prossimo_appello);
 fine_lettura(semid,esame);
}

canonical_original_code:
void stampa_appello(int semid, struct tipo_esame *esame){
 inizio_lettura(semid,esame);
 printf("Processo studente %d - Data di appello: %s\n",getpid(),esame->prossimo_appello);
 fine_lettura(semid,esame);
}

user_defined_types: struct tipo_esame { char prossimo_appello[20]; int numero_prenotati; int numero_lettori; }


decompiled_code:
int __fastcall wait_sem(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
*(_DWORD *)&sops.sem_op = 0xFFFF;
return semop(a1, &sops, 1uLL);
}

canonical_decompiled_code:
int __fastcall func10(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
*(_DWORD *)&sops.sem_op = 0xFFFF;
return semop(a1, &sops, 1uLL);
}

original_code:
void wait_sem(int idsem,int numsem){
 struct sembuf sem_buf;
 sem_buf.sem_num = numsem;
 sem_buf.sem_flg=0;
 sem_buf.sem_op=-1;
 semop(idsem,&sem_buf,1);
}

canonical_original_code:
void wait_sem(int idsem, int numsem){
 struct sembuf sem_buf;
 sem_buf.sem_num = numsem;
 sem_buf.sem_flg=0;
 sem_buf.sem_op=-1;
 semop(idsem,&sem_buf,1);
}

variable_types: idsem int

variable_types: numsem int

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


decompiled_code:
int __fastcall signal_sem(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
*(_DWORD *)&sops.sem_op = 1;
return semop(a1, &sops, 1uLL);
}

canonical_decompiled_code:
int __fastcall func11(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
*(_DWORD *)&sops.sem_op = 1;
return semop(a1, &sops, 1uLL);
}

original_code:
void signal_sem(int idsem,int numsem){
 struct sembuf sem_buf;
 sem_buf.sem_num = numsem;
 sem_buf.sem_flg=0;
 sem_buf.sem_op=1;
 semop(idsem,&sem_buf,1);
}

canonical_original_code:
void signal_sem(int idsem, int numsem){
 struct sembuf sem_buf;
 sem_buf.sem_num = numsem;
 sem_buf.sem_flg=0;
 sem_buf.sem_op=1;
 semop(idsem,&sem_buf,1);
}

user_defined_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


decompiled_code:
int __fastcall inizio_lettura(int a1, __int64 a2)
{
__int64 v3; // rsi

wait_sem(a1, 0);
v3 = (unsigned int)(*(_DWORD *)(a2 + 24) + 1);
*(_DWORD *)(a2 + 24) = v3;
printf("DEBUG: Numero lettori %d\n", v3);
if ( *(_DWORD *)(a2 + 24) == 1 )
wait_sem(a1, 1u);
return signal_sem(a1, 0);
}

canonical_decompiled_code:
int __fastcall func12(int a1, __int64 a2)
{
__int64 v3; // rsi

func10(a1, 0);
v3 = (unsigned int)(*(_DWORD *)(a2 + 24) + 1);
*(_DWORD *)(a2 + 24) = v3;
printf("DEBUG: Numero lettori %d\n", v3);
if ( *(_DWORD *)(a2 + 24) == 1 )
func10(a1, 1u);
return func11(a1, 0);
}

original_code:
void inizio_lettura(int sem,esame_t* esame){
 wait_sem(sem,0);
 esame->numero_lettori = esame->numero_lettori+1;
 printf("DEBUG: Numero lettori %d\n",esame->numero_lettori);
 if(esame->numero_lettori == 1)
  wait_sem(sem,1);
 signal_sem(sem,0);
}

canonical_original_code:
void inizio_lettura(int sem, struct tipo_esame *esame){
 wait_sem(sem,0);
 esame->numero_lettori = esame->numero_lettori+1;
 printf("DEBUG: Numero lettori %d\n",esame->numero_lettori);
 if(esame->numero_lettori == 1)
  wait_sem(sem,1);
 signal_sem(sem,0);
}

variable_types: sem int


decompiled_code:
int __fastcall fine_lettura(int a1, __int64 a2)
{
__int64 v3; // rsi

wait_sem(a1, 0);
v3 = (unsigned int)(*(_DWORD *)(a2 + 24) - 1);
*(_DWORD *)(a2 + 24) = v3;
printf("DEBUG: Numero lettori %d\n", v3);
if ( !*(_DWORD *)(a2 + 24) )
signal_sem(a1, 1u);
return signal_sem(a1, 0);
}

canonical_decompiled_code:
int __fastcall func13(int a1, __int64 a2)
{
__int64 v3; // rsi

func10(a1, 0);
v3 = (unsigned int)(*(_DWORD *)(a2 + 24) - 1);
*(_DWORD *)(a2 + 24) = v3;
printf("DEBUG: Numero lettori %d\n", v3);
if ( !*(_DWORD *)(a2 + 24) )
func11(a1, 1u);
return func11(a1, 0);
}

original_code:
void fine_lettura(int sem,esame_t* esame){
 wait_sem(sem,0);
 esame->numero_lettori = esame->numero_lettori - 1;
 printf("DEBUG: Numero lettori %d\n",esame->numero_lettori);
 if(esame->numero_lettori == 0)
  signal_sem(sem,1);
 signal_sem(sem,0);
}

canonical_original_code:
void fine_lettura(int sem, struct tipo_esame *esame){
 wait_sem(sem,0);
 esame->numero_lettori = esame->numero_lettori - 1;
 printf("DEBUG: Numero lettori %d\n",esame->numero_lettori);
 if(esame->numero_lettori == 0)
  signal_sem(sem,1);
 signal_sem(sem,0);
}


decompiled_code:
int __fastcall inizio_scrittura(int a1)
{
wait_sem(a1, 1u);
return puts("DEBUG: Inizio scrittura");
}

canonical_decompiled_code:
int __fastcall func14(int a1)
{
func10(a1, 1u);
return puts("DEBUG: Inizio scrittura");
}

original_code:
void inizio_scrittura(int sem){
 wait_sem(sem,1);
 printf("DEBUG: Inizio scrittura\n");
}


decompiled_code:
int __fastcall fine_scrittura(int a1)
{
signal_sem(a1, 1u);
return puts("DEBUG: Fine scrittura");
}

canonical_decompiled_code:
int __fastcall func15(int a1)
{
func11(a1, 1u);
return puts("DEBUG: Fine scrittura");
}

original_code:
void fine_scrittura(int sem){
 signal_sem(sem,1);
 printf("DEBUG: Fine scrittura\n");
}


decompiled_code:
int __fastcall accedi_prenotati(int a1)
{
wait_sem(a1, 2u);
return puts("DEBUG: Inizio scrittura prenotati");
}

canonical_decompiled_code:
int __fastcall func16(int a1)
{
func10(a1, 2u);
return puts("DEBUG: Inizio scrittura prenotati");
}

original_code:
void accedi_prenotati(int sem){
 wait_sem(sem,2);
 printf("DEBUG: Inizio scrittura prenotati\n");
}


decompiled_code:
int __fastcall lascia_prenotati(int a1)
{
signal_sem(a1, 2u);
return puts("DEBUG: Fine scrittura prenotati");
}

canonical_decompiled_code:
int __fastcall func17(int a1)
{
func11(a1, 2u);
return puts("DEBUG: Fine scrittura prenotati");
}

original_code:
void lascia_prenotati(int sem){
 signal_sem(sem,2);
 printf("DEBUG: Fine scrittura prenotati\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
key_t v3; // er12
key_t v4; // ebp
unsigned int v5; // er12
void *v6; // r13
__int64 v7; // rbp
struct timeval v9; // [rsp+0h] [rbp-28h] BYREF

v3 = ftok(".", 83);
v4 = ftok(".", 80);
gettimeofday(&v9, 0LL);
srand(LODWORD(v9.tv_usec) * LODWORD(v9.tv_sec));
v5 = shmget(v3, 0x1CuLL, 948);
v6 = shmat(v5, 0LL, 0);
v7 = (unsigned int)semget(v4, 0, 0);
printf("Debug [PS] - idshm %d idsem %d\n", v5, v7);
esegui((unsigned int)v7, v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
key_t v3; // er12
key_t v4; // ebp
unsigned int v5; // er12
void *v6; // r13
__int64 v7; // rbp
struct timeval v9; // [rsp+0h] [rbp-28h] BYREF

v3 = ftok(".", 83);
v4 = ftok(".", 80);
gettimeofday(&v9, 0LL);
srand(LODWORD(v9.tv_usec) * LODWORD(v9.tv_sec));
v5 = shmget(v3, 0x1CuLL, 948);
v6 = shmat(v5, 0LL, 0);
v7 = (unsigned int)semget(v4, 0, 0);
printf("Debug [PS] - idshm %d idsem %d\n", v5, v7);
func9((unsigned int)v7, v6);
return 0;
}

original_code:
int main(int argc,char* argv[]){
 key_t key_shm,key_sem;
 int shmid,semid;
 key_shm = ftok(".",'S');
 key_sem = ftok(".",'P');
 esame_t* esame = ((void *)0);
 struct timeval t1;
 gettimeofday(&t1, ((void *)0));
 srand(t1.tv_usec * t1.tv_sec);
 shmid = shmget(key_shm,sizeof(esame_t),01000|0664);
 esame = (esame_t*) shmat(shmid,0,0);
 semid = semget(key_sem,0,0);
 printf("Debug [PS] - idshm %d idsem %d\n",shmid,semid);
 esegui(semid,esame);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 int key_shm; int key_sem;
 int shmid; int semid;
 key_shm = ftok(".",'S');
 key_sem = ftok(".",'P');
 struct tipo_esame *esame = ((void *)0);
 struct timeval t1;
 gettimeofday(&t1, ((void *)0));
 srand(t1.tv_usec * t1.tv_sec);
 shmid = shmget(key_shm,sizeof(esame_t),01000|0664);
 esame = (struct tipo_esame *) shmat(shmid,0,0);
 semid = semget(key_sem,0,0);
 printf("Debug [PS] - idshm %d idsem %d\n",shmid,semid);
 esegui(semid,esame);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: shmid int

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


esegui

decompiled_code:
__int64 __fastcall esegui(unsigned int a1, const char *a2)
{
unsigned int v2; // ebp

v2 = rand() % 8 + 1;
printf("Sono studente e aspetto tempo %d secondi\n", v2);
sleep(v2);
stampa_appello(a1, a2);
return prenota(a1, (__int64)a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, const char *a2)
{
unsigned int v2; // ebp

v2 = rand() % 8 + 1;
printf("Sono studente e aspetto tempo %d secondi\n", v2);
sleep(v2);
func8(a1, a2);
return func7(a1, (__int64)a2);
}

original_code:
void esegui(int semid,esame_t* esame){
 int i;
 int t;
 t = 1 + (rand() % 8);
 printf("Sono studente e aspetto tempo %d secondi\n",t);
 sleep(t);
 stampa_appello(semid,esame);
 prenota(semid,esame);
}

canonical_original_code:
void esegui(int semid, struct tipo_esame *esame){
 int i;
 int t;
 t = 1 + (rand() % 8);
 printf("Sono studente e aspetto tempo %d secondi\n",t);
 sleep(t);
 stampa_appello(semid,esame);
 prenota(semid,esame);
}

variable_types: i int

variable_types: t int


decompiled_code:
__int64 __fastcall azzera_prenotati(unsigned int a1, __int64 a2)
{
inizio_lettura();
accedi_prenotati(a1);
putchar(10);
puts("-------Stampa stato esame------");
printf("Data di esame: %s\n", (const char *)a2);
printf("Numero prenotati: %d\n", *(unsigned int *)(a2 + 20));
puts("-------------------------------");
putchar(10);
*(_DWORD *)(a2 + 20) = 0;
lascia_prenotati(a1);
return fine_lettura(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, __int64 a2)
{
func12();
func16(a1);
putchar(10);
puts("-------Stampa stato esame------");
printf("Data di esame: %s\n", (const char *)a2);
printf("Numero prenotati: %d\n", *(unsigned int *)(a2 + 20));
puts("-------------------------------");
putchar(10);
*(_DWORD *)(a2 + 20) = 0;
func17(a1);
return func13(a1, a2);
}

original_code:
void azzera_prenotati(int semid,esame_t* esame){
 inizio_lettura(semid,esame);
 accedi_prenotati(semid);
 printf("\n");
 printf("-------Stampa stato esame------\n");
 printf("Data di esame: %s\n",esame->prossimo_appello);
 printf("Numero prenotati: %d\n",esame->numero_prenotati);
 printf("-------------------------------\n");
 printf("\n");
 esame->numero_prenotati = 0;
 lascia_prenotati(semid);
 fine_lettura(semid,esame);
}

canonical_original_code:
void azzera_prenotati(int semid, struct tipo_esame *esame){
 inizio_lettura(semid,esame);
 accedi_prenotati(semid);
 printf("\n");
 printf("-------Stampa stato esame------\n");
 printf("Data di esame: %s\n",esame->prossimo_appello);
 printf("Numero prenotati: %d\n",esame->numero_prenotati);
 printf("-------------------------------\n");
 printf("\n");
 esame->numero_prenotati = 0;
 lascia_prenotati(semid);
 fine_lettura(semid,esame);
}


decompiled_code:
__int64 __fastcall aggiorna_data(unsigned int a1, char *a2, const char *a3)
{
printf("DEBUG: Aggiorna data %s\n", a3);
inizio_scrittura(a1);
strcpy(a2, a3);
printf("DEBUG: Prossimo appello %s\n", a2);
return fine_scrittura(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, char *a2, const char *a3)
{
printf("DEBUG: Aggiorna data %s\n", a3);
func14(a1);
strcpy(a2, a3);
printf("DEBUG: Prossimo appello %s\n", a2);
return func15(a1);
}

original_code:
void aggiorna_data(int semid,esame_t* esame,char* data){
 printf("DEBUG: Aggiorna data %s\n",data);
 inizio_scrittura(semid);
 strcpy(&esame->prossimo_appello,data);
 printf("DEBUG: Prossimo appello %s\n",esame->prossimo_appello);
 fine_scrittura(semid);
}

canonical_original_code:
void aggiorna_data(int semid, struct tipo_esame *esame, char *data){
 printf("DEBUG: Aggiorna data %s\n",data);
 inizio_scrittura(semid);
 strcpy(&esame->prossimo_appello,data);
 printf("DEBUG: Prossimo appello %s\n",esame->prossimo_appello);
 fine_scrittura(semid);
}

variable_types:
data
char *


canonical_original_code:
void inizio_scrittura(int sem){
 wait_sem(sem,1);
 printf("DEBUG: Inizio scrittura\n");
}


canonical_original_code:
void fine_scrittura(int sem){
 signal_sem(sem,1);
 printf("DEBUG: Fine scrittura\n");
}


canonical_original_code:
void accedi_prenotati(int sem){
 wait_sem(sem,2);
 printf("DEBUG: Inizio scrittura prenotati\n");
}


canonical_original_code:
void lascia_prenotati(int sem){
 signal_sem(sem,2);
 printf("DEBUG: Fine scrittura prenotati\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
key_t v3; // er12
key_t v4; // ebp
unsigned int v5; // er12
void *v6; // r13
__int64 v7; // rbp

v3 = ftok(".", 83);
v4 = ftok(".", 80);
v5 = shmget(v3, 0LL, 0);
v6 = shmat(v5, 0LL, 0);
v7 = (unsigned int)semget(v4, 0, 0);
printf("Debug [PD] : idshm %d idsem %d\n", v5, v7);
esegui((unsigned int)v7, v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
key_t v3; // er12
key_t v4; // ebp
unsigned int v5; // er12
void *v6; // r13
__int64 v7; // rbp

v3 = ftok(".", 83);
v4 = ftok(".", 80);
v5 = shmget(v3, 0LL, 0);
v6 = shmat(v5, 0LL, 0);
v7 = (unsigned int)semget(v4, 0, 0);
printf("Debug [PD] : idshm %d idsem %d\n", v5, v7);
func9((unsigned int)v7, v6);
return 0;
}

original_code:
int main(int argc,char* argv[]){
 key_t key_shm,key_sem;
 int shmid,semid;
 key_shm = ftok(".",'S');
 key_sem = ftok(".",'P');
 esame_t* esame = ((void *)0);
 shmid = shmget(key_shm,0,0);
 esame = (esame_t*) (shmat(shmid,0,0));
 semid = semget(key_sem,0,0);
 printf("Debug [PD] : idshm %d idsem %d\n",shmid,semid);
 esegui(semid,esame);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 int key_shm; int key_sem;
 int shmid; int semid;
 key_shm = ftok(".",'S');
 key_sem = ftok(".",'P');
 struct tipo_esame *esame = ((void *)0);
 shmid = shmget(key_shm,0,0);
 esame = (struct tipo_esame *) (shmat(shmid,0,0));
 semid = semget(key_sem,0,0);
 printf("Debug [PD] : idshm %d idsem %d\n",shmid,semid);
 esegui(semid,esame);
 return 0;
}


esegui

decompiled_code:
__int64 __fastcall esegui(unsigned int a1, char *a2)
{
puts("Docente in esecuzione");
aggiorna_data(a1, a2, "14/02/2013");
sleep(3u);
azzera_prenotati(a1, (__int64)a2);
aggiorna_data(a1, a2, "05/03/2013");
sleep(3u);
azzera_prenotati(a1, (__int64)a2);
aggiorna_data(a1, a2, "02/04/2013");
sleep(3u);
return azzera_prenotati(a1, (__int64)a2);
}

original_code:
void esegui(int semid,esame_t* esame){
 printf("Docente in esecuzione\n");
 int i;
 char* data;
 for(i=0; i < 3;i++){
  switch(i){
   case 0:
   data = "14/02/2013";
   break;
   case 1:
   data = "05/03/2013";
   break;
   case 2:
   data = "02/04/2013";
   break;
   default:
   data = "default";
   break;
  }
   aggiorna_data(semid,esame,data);
  sleep(3);
  azzera_prenotati(semid,esame);
 }
}

canonical_original_code:
void esegui(int semid, struct tipo_esame *esame){
 printf("Docente in esecuzione\n");
 int i;
 char *data;
 for(i=0; i < 3;i++){
  switch(i){
   case 0:
   data = "14/02/2013";
   break;
   case 1:
   data = "05/03/2013";
   break;
   case 2:
   data = "02/04/2013";
   break;
   default:
   data = "default";
   break;
  }
   aggiorna_data(semid,esame,data);
  sleep(3);
  azzera_prenotati(semid,esame);
 }
}


StackInit

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

pthread_mutex_init((pthread_mutex_t *)(a1 + 16), 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 56), 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 104), 0LL);
result = malloc(4LL * a2);
*(_DWORD *)(a1 + 8) = a2;
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 12) = 0;
return result;
}

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

pthread_mutex_init((pthread_mutex_t *)(a1 + 16), 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 56), 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 104), 0LL);
result = malloc(4LL * a2);
*(_DWORD *)(a1 + 8) = a2;
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 12) = 0;
return result;
}

original_code:
void StackInit(Stack * s, int dim) {
 pthread_mutex_init( &(s->m), ((void *)0) );
 pthread_cond_init( &(s->ok_push), ((void *)0) );
 pthread_cond_init( &(s->ok_pop), ((void *)0) );
 s->dati = (Elem *) malloc(sizeof(Elem)*dim);
 s->dim = dim;
 s->testa = 0;
}

canonical_original_code:
void StackInit(struct Stack *s, int dim) {
 pthread_mutex_init( &(s->m), ((void *)0) );
 pthread_cond_init( &(s->ok_push), ((void *)0) );
 pthread_cond_init( &(s->ok_pop), ((void *)0) );
 s->dati = (int *) malloc(sizeof(Elem)*dim);
 s->dim = dim;
 s->testa = 0;
}

variable_types: struct Stack { int *dati; int dim; int testa; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } m; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } ok_push; union pthread_cond_t ok_pop; } *

variable_types: dim int

user_defined_types: struct Stack { int *dati; int dim; int testa; union pthread_mutex_t m; union pthread_cond_t ok_push; union pthread_cond_t ok_pop; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


StackRemove

decompiled_code:
void __fastcall StackRemove(__int64 a1)
{
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 16));
pthread_cond_destroy((pthread_cond_t *)(a1 + 56));
pthread_cond_destroy((pthread_cond_t *)(a1 + 104));
free(*(void **)a1);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 16));
pthread_cond_destroy((pthread_cond_t *)(a1 + 56));
pthread_cond_destroy((pthread_cond_t *)(a1 + 104));
free(*(void **)a1);
}

original_code:
void StackRemove(Stack * s) {
 pthread_mutex_destroy( &(s->m) );
 pthread_cond_destroy( &(s->ok_push) );
 pthread_cond_destroy( &(s->ok_pop) );
 free(s->dati);
}

canonical_original_code:
void StackRemove(struct Stack *s) {
 pthread_mutex_destroy( &(s->m) );
 pthread_cond_destroy( &(s->ok_push) );
 pthread_cond_destroy( &(s->ok_pop) );
 free(s->dati);
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

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


StackPush

decompiled_code:
int __fastcall StackPush(__int64 a1, int a2)
{
pthread_mutex_t *v2; // rbp
__int64 i; // rax

v2 = (pthread_mutex_t *)(a1 + 16);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
for ( i = *(int *)(a1 + 12); *(_DWORD *)(a1 + 8) == (_DWORD)i; i = *(int *)(a1 + 12) )
pthread_cond_wait((pthread_cond_t *)(a1 + 56), v2);
*(_DWORD *)(*(_QWORD *)a1 + 4 * i) = a2;
++*(_DWORD *)(a1 + 12);
pthread_cond_signal((pthread_cond_t *)(a1 + 104));
return pthread_mutex_unlock(v2);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, int a2)
{
pthread_mutex_t *v2; // rbp
__int64 i; // rax

v2 = (pthread_mutex_t *)(a1 + 16);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
for ( i = *(int *)(a1 + 12); *(_DWORD *)(a1 + 8) == (_DWORD)i; i = *(int *)(a1 + 12) )
pthread_cond_wait((pthread_cond_t *)(a1 + 56), v2);
*(_DWORD *)(*(_QWORD *)a1 + 4 * i) = a2;
++*(_DWORD *)(a1 + 12);
pthread_cond_signal((pthread_cond_t *)(a1 + 104));
return pthread_mutex_unlock(v2);
}

original_code:
void StackPush(Stack * s, Elem e) {
 pthread_mutex_lock( &(s->m) );
 while( s->dim==s->testa )
  pthread_cond_wait( &(s->ok_push), &(s->m) );
 s->dati[s->testa] = e;
 s->testa++;
 pthread_cond_signal( &(s->ok_pop) );
 pthread_mutex_unlock( &(s->m) );
}

canonical_original_code:
void StackPush(struct Stack *s, int e) {
 pthread_mutex_lock( &(s->m) );
 while( s->dim==s->testa )
  pthread_cond_wait( &(s->ok_push), &(s->m) );
 s->dati[s->testa] = e;
 s->testa++;
 pthread_cond_signal( &(s->ok_pop) );
 pthread_mutex_unlock( &(s->m) );
}

variable_types: e int


StackPop

decompiled_code:
__int64 __fastcall StackPop(__int64 *a1)
{
pthread_mutex_t *v1; // rbp
int i; // eax
int v3; // eax
__int64 v4; // rdx
unsigned int v5; // er12

v1 = (pthread_mutex_t *)(a1 + 2);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 2));
for ( i = *((_DWORD *)a1 + 3); !i; i = *((_DWORD *)a1 + 3) )
pthread_cond_wait((pthread_cond_t *)(a1 + 13), v1);
v3 = i - 1;
v4 = *a1;
*((_DWORD *)a1 + 3) = v3;
v5 = *(_DWORD *)(v4 + 4LL * v3);
pthread_cond_signal((pthread_cond_t *)(a1 + 7));
pthread_mutex_unlock(v1);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1)
{
pthread_mutex_t *v1; // rbp
int i; // eax
int v3; // eax
__int64 v4; // rdx
unsigned int v5; // er12

v1 = (pthread_mutex_t *)(a1 + 2);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 2));
for ( i = *((_DWORD *)a1 + 3); !i; i = *((_DWORD *)a1 + 3) )
pthread_cond_wait((pthread_cond_t *)(a1 + 13), v1);
v3 = i - 1;
v4 = *a1;
*((_DWORD *)a1 + 3) = v3;
v5 = *(_DWORD *)(v4 + 4LL * v3);
pthread_cond_signal((pthread_cond_t *)(a1 + 7));
pthread_mutex_unlock(v1);
return v5;
}

original_code:
Elem StackPop(Stack * s) {
 int elemento;
 pthread_mutex_lock( &(s->m) );
 while( s->testa==0 )
  pthread_cond_wait( &(s->ok_pop), &(s->m) );
 s->testa--;
 elemento=s->dati[s->testa];
 pthread_cond_signal( &(s->ok_push) );
 pthread_mutex_unlock( &(s->m) );
 return elemento;
}

canonical_original_code:
int StackPop(struct Stack *s) {
 int elemento;
 pthread_mutex_lock( &(s->m) );
 while( s->testa==0 )
  pthread_cond_wait( &(s->ok_pop), &(s->m) );
 s->testa--;
 elemento=s->dati[s->testa];
 pthread_cond_signal( &(s->ok_push) );
 pthread_mutex_unlock( &(s->m) );
 return elemento;
}

variable_types: elemento int


StackSize

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

pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
v1 = *(_DWORD *)(a1 + 12);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 16));
return v1;
}

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

pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
v1 = *(_DWORD *)(a1 + 12);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 16));
return v1;
}

original_code:
int StackSize(Stack * s) {
 int size;
 pthread_mutex_lock( &(s->m) );
 size = s->testa;
 pthread_mutex_unlock( &(s->m) );
 return size;
}

canonical_original_code:
int StackSize(struct Stack *s) {
 int size;
 pthread_mutex_lock( &(s->m) );
 size = s->testa;
 pthread_mutex_unlock( &(s->m) );
 return size;
}

variable_types: size int