original_code:
int reverse_traceroute(int pbr, TRACE_t * trace, const TRACE_t * cmptrace)
{
    unsigned char ttl;
    unsigned char type;
    int timeout = 0;
    IP_t from;
    trace->rst = 0;
    trace->end = ((trace->end > 30) ? 30 : trace->end);
    if (trace->end == 0) {
        do{if (_opt_debug) {fprintf(stdout, "[D]" "trace->end == 0"); fflush(stdout);} } while(0);
        return -1;
    }
    for (ttl = trace->end; ttl != 0; ttl--) {
        type = hopping(pbr, trace->dst, ttl, &from);
        if (type == 0) {
            return -1;
        }
        if (type == 6) {
            trace->hop[ttl - 1] = 0;
            continue;
        }
        timeout = 0;
        trace->hop[ttl - 1] = from;
        if (type != 11) {
            if ((type>=12&&type<=(12 + 15)?1:0)) {
                unsigned char code = (type-12);
                if (code != 2 && code != 3) {
                    trace->rst = 2;
                } else {
                    trace->rst = 1;
                }
            } else {
                trace->rst = 1;
            }
            trace->end = ttl;
            continue;
        }
        if (from == trace->dst) {
            trace->end = ttl;
            trace->rst = 6;
            continue;
        }
        if (cmptrace != ((void *)0) && cmptrace->start <= ttl
            && cmptrace->end >= ttl
            && cmptrace->hop[ttl - 1] == trace->hop[ttl - 1]) {
            trace->start = ttl;
            trace->rst = (trace->rst == 0 ? 7 : trace->rst);
            return 1;
        }
    }
    trace->start = 1;
    trace->rst = (trace->rst == 0 ? 7 : trace->rst);
    return 1;
}

canonical_original_code:
int reverse_traceroute(int pbr, struct TRACE_t *trace, struct TRACE_t *cmptrace)
{
    unsigned char ttl;
    unsigned char type;
    int timeout = 0;
    unsigned int from;
    trace->rst = 0;
    trace->end = ((trace->end > 30) ? 30 : trace->end);
    if (trace->end == 0) {
        do{if (_opt_debug) {fprintf(stdout, "[D]" "trace->end == 0"); fflush(stdout);} } while(0);
        return -1;
    }
    for (ttl = trace->end; ttl != 0; ttl--) {
        type = hopping(pbr, trace->dst, ttl, &from);
        if (type == 0) {
            return -1;
        }
        if (type == 6) {
            trace->hop[ttl - 1] = 0;
            continue;
        }
        timeout = 0;
        trace->hop[ttl - 1] = from;
        if (type != 11) {
            if ((type>=12&&type<=(12 + 15)?1:0)) {
                unsigned char code = (type-12);
                if (code != 2 && code != 3) {
                    trace->rst = 2;
                } else {
                    trace->rst = 1;
                }
            } else {
                trace->rst = 1;
            }
            trace->end = ttl;
            continue;
        }
        if (from == trace->dst) {
            trace->end = ttl;
            trace->rst = 6;
            continue;
        }
        if (cmptrace != ((void *)0) && cmptrace->start <= ttl
            && cmptrace->end >= ttl
            && cmptrace->hop[ttl - 1] == trace->hop[ttl - 1]) {
            trace->start = ttl;
            trace->rst = (trace->rst == 0 ? 7 : trace->rst);
            return 1;
        }
    }
    trace->start = 1;
    trace->rst = (trace->rst == 0 ? 7 : trace->rst);
    return 1;
}


repo: YuZhang/fastrace

decompiled_code:
__int64 __fastcall forward_reverse(unsigned int a1, unsigned int *a2, _BYTE *a3, __int64 a4)
{
char v5; // al
__int64 v6; // rbx
char v7; // r14
__int64 result; // rax
char v9; // bl

if ( (unsigned int)forward_traceroute(a1, a2, a3) == -1 )
return 0xFFFFFFFFLL;
v5 = *((_BYTE *)a2 + 4);
if ( v5 == 1 )
return 1LL;
v6 = *((unsigned __int8 *)a2 + 5);
*((_BYTE *)a2 + 5) = v5 - 1;
v7 = *((_BYTE *)a2 + 7);
if ( (unsigned int)reverse_traceroute(a1, a2, a4) == -1 )
return 0xFFFFFFFFLL;
if ( *((_BYTE *)a2 + 7) != 7 )
return 1LL;
if ( v7 != 3 )
{
*((_BYTE *)a2 + 7) = v7;
*((_BYTE *)a2 + 5) = v6;
if ( (unsigned __int8)(v7 - 4) <= 1u )
search_loop((unsigned __int8 *)a2);
return 1LL;
}
while ( 1 )
{
if ( !v6 )
{
v9 = 1;
goto LABEL_13;
}
if ( a2[v6 + 1] )
break;
--v6;
}
v9 = v6 + 1;
LABEL_13:
*((_BYTE *)a2 + 7) = 3;
result = 1LL;
*((_BYTE *)a2 + 5) = v9;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, unsigned int *a2, _BYTE *a3, __int64 a4)
{
char v5; // al
__int64 v6; // rbx
char v7; // r14
__int64 result; // rax
char v9; // bl

if ( (unsigned int)func3(a1, a2, a3) == -1 )
return 0xFFFFFFFFLL;
v5 = *((_BYTE *)a2 + 4);
if ( v5 == 1 )
return 1LL;
v6 = *((unsigned __int8 *)a2 + 5);
*((_BYTE *)a2 + 5) = v5 - 1;
v7 = *((_BYTE *)a2 + 7);
if ( (unsigned int)func4(a1, a2, a4) == -1 )
return 0xFFFFFFFFLL;
if ( *((_BYTE *)a2 + 7) != 7 )
return 1LL;
if ( v7 != 3 )
{
*((_BYTE *)a2 + 7) = v7;
*((_BYTE *)a2 + 5) = v6;
if ( (unsigned __int8)(v7 - 4) <= 1u )
func2((unsigned __int8 *)a2);
return 1LL;
}
while ( 1 )
{
if ( !v6 )
{
v9 = 1;
goto LABEL_13;
}
if ( a2[v6 + 1] )
break;
--v6;
}
v9 = v6 + 1;
LABEL_13:
*((_BYTE *)a2 + 7) = 3;
result = 1LL;
*((_BYTE *)a2 + 5) = v9;
return result;
}

original_code:
int forward_reverse(int pbr, TRACE_t * trace, const TRACE_t * fcmptrace,
                    const TRACE_t * rcmptrace)
{
    unsigned char result;
    unsigned char end;
    if (forward_traceroute(pbr, trace, fcmptrace) == -1) {
        return -1;
    }
    if (trace->start == 1) {
        return 1;
    }
    result = trace->rst;
    end = trace->end;
    trace->end = trace->start - 1;
    if (reverse_traceroute(pbr, trace, rcmptrace) == -1) {
        return -1;
    }
    if (trace->rst != 7) {
        return 1;
    }
    if (result == 3) {
        int i = end;
        while (i > 0 && trace->hop[i - 1] == 0) {
            i--;
        }
        end = i + 1;
    }
    trace->rst = result;
    trace->end = end;
    if (result == 5 || result == 4) {
        search_loop(trace);
    }
    return 1;
}

canonical_original_code:
int forward_reverse(int pbr, struct TRACE_t *trace, struct TRACE_t *fcmptrace, struct TRACE_t *rcmptrace)
{
    unsigned char result;
    unsigned char end;
    if (forward_traceroute(pbr, trace, fcmptrace) == -1) {
        return -1;
    }
    if (trace->start == 1) {
        return 1;
    }
    result = trace->rst;
    end = trace->end;
    trace->end = trace->start - 1;
    if (reverse_traceroute(pbr, trace, rcmptrace) == -1) {
        return -1;
    }
    if (trace->rst != 7) {
        return 1;
    }
    if (result == 3) {
        int i = end;
        while (i > 0 && trace->hop[i - 1] == 0) {
            i--;
        }
        end = i + 1;
    }
    trace->rst = result;
    trace->end = end;
    if (result == 5 || result == 4) {
        search_loop(trace);
    }
    return 1;
}

variable_types: pbr int

variable_types: struct TRACE_t { unsigned int dst; unsigned char start; unsigned char end; unsigned char ept; unsigned char rst; unsigned int hop[30]; } *

variable_types:
fcmptrace
struct TRACE_t *

variable_types:
rcmptrace
struct TRACE_t *

variable_types:
result
unsigned char

variable_types:
end
unsigned char

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall trace_to_tab(unsigned int a1, unsigned __int8 *a2, _DWORD *a3)
{
unsigned int v3; // er15
__int64 v4; // rdx
int v5; // eax
unsigned __int8 v6; // cl
unsigned __int8 *v7; // rbx
unsigned int v8; // er13
__int64 v9; // r14
unsigned int v10; // ebp
const char *v12; // rax
const char *v13; // rax
const char *v14; // rax
char s[168]; // [rsp+10h] [rbp-A8h] BYREF

v3 = 0;
*a3 = 0;
v4 = a2[4];
if ( (_BYTE)v4 )
{
v5 = a2[5];
if ( (_BYTE)v5 )
{
v6 = a2[7];
if ( (unsigned __int8)(v6 - 4) > 1u )
v5 -= v6 != 7;
if ( v5 >= (unsigned __int8)v4 )
{
v7 = &a2[4 * v4];
v3 = 0;
v8 = 0;
v9 = (__int64)&a2[4 * v4 + 4 + 4 * (v5 - (unsigned int)(unsigned __int8)v4)];
while ( 1 )
{
while ( 1 )
{
v10 = *((_DWORD *)v7 + 1);
if ( v10 )
break;
v7 += 4;
v8 = 0;
if ( v7 == (unsigned __int8 *)v9 )
return v3;
}
if ( !find_ip_in_tab(a1, v10) )
{
insert_ip_to_tab(a1, v10);
++*a3;
if ( opt_debug )
{
v12 = (const char *)ip2str(v10);
fprintf(stdout, "[D]New IP is %s\n", v12);
fflush(stdout);
}
}
if ( !v8 )
goto LABEL_11;
if ( v10 != v8 )
break;
LABEL_12:
v7 += 4;
if ( v7 == (unsigned __int8 *)v9 )
return v3;
}
if ( !(unsigned int)search_link_in_tab(a1, v8, v10) )
{
++v3;
insert_link_to_tab(a1, v8, v10);
v13 = (const char *)ip2str(v8);
sprintf(s, "New link is %s ", v13);
if ( opt_debug )
{
v14 = (const char *)ip2str(v10);
fprintf(stdout, "[D]%s- %s\n", s, v14);
fflush(stdout);
}
}
LABEL_11:
v8 = v10;
goto LABEL_12;
}
v3 = 0;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned __int8 *a2, _DWORD *a3)
{
unsigned int v3; // er15
__int64 v4; // rdx
int v5; // eax
unsigned __int8 v6; // cl
unsigned __int8 *v7; // rbx
unsigned int v8; // er13
__int64 v9; // r14
unsigned int v10; // ebp
const char *v12; // rax
const char *v13; // rax
const char *v14; // rax
char s[168]; // [rsp+10h] [rbp-A8h] BYREF

v3 = 0;
*a3 = 0;
v4 = a2[4];
if ( (_BYTE)v4 )
{
v5 = a2[5];
if ( (_BYTE)v5 )
{
v6 = a2[7];
if ( (unsigned __int8)(v6 - 4) > 1u )
v5 -= v6 != 7;
if ( v5 >= (unsigned __int8)v4 )
{
v7 = &a2[4 * v4];
v3 = 0;
v8 = 0;
v9 = (__int64)&a2[4 * v4 + 4 + 4 * (v5 - (unsigned int)(unsigned __int8)v4)];
while ( 1 )
{
while ( 1 )
{
v10 = *((_DWORD *)v7 + 1);
if ( v10 )
break;
v7 += 4;
v8 = 0;
if ( v7 == (unsigned __int8 *)v9 )
return v3;
}
if ( !find_ip_in_tab(a1, v10) )
{
insert_ip_to_tab(a1, v10);
++*a3;
if ( opt_debug )
{
v12 = (const char *)ip2str(v10);
fprintf(stdout, "[D]New IP is %s\n", v12);
fflush(stdout);
}
}
if ( !v8 )
goto LABEL_11;
if ( v10 != v8 )
break;
LABEL_12:
v7 += 4;
if ( v7 == (unsigned __int8 *)v9 )
return v3;
}
if ( !(unsigned int)search_link_in_tab(a1, v8, v10) )
{
++v3;
insert_link_to_tab(a1, v8, v10);
v13 = (const char *)ip2str(v8);
sprintf(s, "New link is %s ", v13);
if ( opt_debug )
{
v14 = (const char *)ip2str(v10);
fprintf(stdout, "[D]%s- %s\n", s, v14);
fflush(stdout);
}
}
LABEL_11:
v8 = v10;
goto LABEL_12;
}
v3 = 0;
}
}
return v3;
}

original_code:
int trace_to_tab(int tab, TRACE_t * tr, int *nr_new_ip)
{
    int i, end;
    IP_t ip, last;
    int nr_new_link = 0;
    struct ipnode *in, *ln;
    *nr_new_ip = 0;
    if (tr->start <= 0 || tr->end <= 0) {
        return 0;
    }
    if (tr->rst == 5 || tr->rst == 7
        || tr->rst == 4)
        end = tr->end;
    else
        end = tr->end - 1;
    last = 0;
    for (i = tr->start; i <= end; i++) {
        ip = tr->hop[i - 1];
        if (ip == 0) {
            last = 0;
            continue;
        }
        if ((in = find_ip_in_tab(tab, ip)) == ((void *)0)) {
            in = insert_ip_to_tab(tab, ip);
            (*nr_new_ip)++;
            do{if (_opt_debug) {fprintf(stdout, "[D]" "New IP is %s\n", ip2str(ip)); fflush(stdout);} } while(0);
        }
        if (last) {
            if (last == ip)
                continue;
            if (!search_link_in_tab(tab, last, ip)) {
                char string[100];
                nr_new_link++;
                insert_link_to_tab(tab, last, ip);
                sprintf(string, "New link is %s ", ip2str(last));
                do{if (_opt_debug) {fprintf(stdout, "[D]" "%s- %s\n", string, ip2str(ip)); fflush(stdout);} } while(0);
            }
        }
        last = ip;
        ln = in;
    }
    return nr_new_link;
}

canonical_original_code:
int trace_to_tab(int tab, struct TRACE_t *tr, int *nr_new_ip)
{
    int i; int end;
    unsigned int ip; unsigned int last;
    int nr_new_link = 0;
    struct ipnode *in; struct ipnode *ln;
    *nr_new_ip = 0;
    if (tr->start <= 0 || tr->end <= 0) {
        return 0;
    }
    if (tr->rst == 5 || tr->rst == 7
        || tr->rst == 4)
        end = tr->end;
    else
        end = tr->end - 1;
    last = 0;
    for (i = tr->start; i <= end; i++) {
        ip = tr->hop[i - 1];
        if (ip == 0) {
            last = 0;
            continue;
        }
        if ((in = find_ip_in_tab(tab, ip)) == ((void *)0)) {
            in = insert_ip_to_tab(tab, ip);
            (*nr_new_ip)++;
            do{if (_opt_debug) {fprintf(stdout, "[D]" "New IP is %s\n", ip2str(ip)); fflush(stdout);} } while(0);
        }
        if (last) {
            if (last == ip)
                continue;
            if (!search_link_in_tab(tab, last, ip)) {
                char string[100];
                nr_new_link++;
                insert_link_to_tab(tab, last, ip);
                sprintf(string, "New link is %s ", ip2str(last));
                do{if (_opt_debug) {fprintf(stdout, "[D]" "%s- %s\n", string, ip2str(ip)); fflush(stdout);} } while(0);
            }
        }
        last = ip;
        ln = in;
    }
    return nr_new_link;
}

variable_types: tab int

variable_types: end int

variable_types:
ip
unsigned int

variable_types:
last
unsigned int

variable_types: struct ipnode { unsigned int ip; unsigned char min_hop; struct iplist { unsigned int ip; struct iplist *next; } *up; struct iplist *down; } *

variable_types:
string
char [100]

user_defined_types: struct TRACE_t { unsigned int dst; unsigned char start; unsigned char end; unsigned char ept; unsigned char rst; unsigned int hop[30]; }

user_defined_types: struct ipnode { unsigned int ip; unsigned char min_hop; struct iplist *up; struct iplist *down; }


decompiled_code:
char *__fastcall trr2str(unsigned __int8 a1)
{
char *result; // rax

if ( a1 > 7u )
result = 0LL;
else
result = &TRR2STRING[24 * a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func5(unsigned __int8 a1)
{
char *result; // rax

if ( a1 > 7u )
result = 0LL;
else
result = &TRR2STRING[24 * a1];
return result;
}

original_code:
const char *trr2str(unsigned char trr)
{
    if (trr > 7)
        return ((void *)0);
    return TRR2STRING[trr];
}

variable_types:
trr
unsigned char

return_type: char *


decompiled_code:
int __fastcall print_tr(__int64 a1)
{
char *v1; // rax
unsigned int v2; // er13
unsigned int v3; // er12
const char *v4; // rbx
char *v5; // rax
int result; // eax
__int64 v7; // rbx
char *v8; // rax
__int64 v9; // rsi

if ( !a1 )
_assert_fail("tr", "inout.c", 0x6Bu, "print_tr");
v1 = trr2str(*(_BYTE *)(a1 + 7));
v2 = *(unsigned __int8 *)(a1 + 5);
v3 = *(unsigned __int8 *)(a1 + 4);
v4 = v1;
v5 = ip2str(*(_DWORD *)a1);
result = printf("Target %s , hop %u - %u , %s.\n", v5, v3, v2, v4);
v7 = *(unsigned __int8 *)(a1 + 4);
if ( (_BYTE)v7 )
{
result = *(unsigned __int8 *)(a1 + 5);
if ( (_BYTE)result )
{
if ( (unsigned __int8)v7 <= (unsigned __int8)result )
{
do
{
v8 = ip2str(*(_DWORD *)(a1 + 4 * v7 + 4));
v9 = (unsigned int)v7++;
printf("~ %d %s\n", v9, v8);
result = *(unsigned __int8 *)(a1 + 5);
}
while ( result >= (int)v7 );
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
char *v1; // rax
unsigned int v2; // er13
unsigned int v3; // er12
const char *v4; // rbx
char *v5; // rax
int result; // eax
__int64 v7; // rbx
char *v8; // rax
__int64 v9; // rsi

if ( !a1 )
_assert_fail("tr", "inout.c", 0x6Bu, "print_tr");
v1 = func5(*(_BYTE *)(a1 + 7));
v2 = *(unsigned __int8 *)(a1 + 5);
v3 = *(unsigned __int8 *)(a1 + 4);
v4 = v1;
v5 = func2(*(_DWORD *)a1);
result = printf("Target %s , hop %u - %u , %s.\n", v5, v3, v2, v4);
v7 = *(unsigned __int8 *)(a1 + 4);
if ( (_BYTE)v7 )
{
result = *(unsigned __int8 *)(a1 + 5);
if ( (_BYTE)result )
{
if ( (unsigned __int8)v7 <= (unsigned __int8)result )
{
do
{
v8 = func2(*(_DWORD *)(a1 + 4 * v7 + 4));
v9 = (unsigned int)v7++;
printf("~ %d %s\n", v9, v8);
result = *(unsigned __int8 *)(a1 + 5);
}
while ( result >= (int)v7 );
}
}
}
return result;
}

original_code:
void print_tr(const TRACE_t * tr)
{
    int i;
    ((void) sizeof ((tr) ? 1 : 0), __extension__ ({ if (tr) ; else __assert_fail ("tr", "inout.c", 107, __extension__ __PRETTY_FUNCTION__); }));
    printf("Target %s , hop %u - %u , %s.\n", ip2str(tr->dst), tr->start,
           tr->end, trr2str(tr->rst));
    if (tr->start <= 0 || tr->end <= 0) {
        return;
    }
    for (i = tr->start; i <= tr->end; i++) {
        printf("~ %d %s\n", i, ip2str(tr->hop[i - 1]));
    }
}

canonical_original_code:
void print_tr(struct TRACE_t *tr)
{
    int i;
    ((void) sizeof ((tr) ? 1 : 0), __extension__ ({ if (tr) ; else __assert_fail ("tr", "inout.c", 107, __extension__ __PRETTY_FUNCTION__); }));
    printf("Target %s , hop %u - %u , %s.\n", ip2str(tr->dst), tr->start,
           tr->end, trr2str(tr->rst));
    if (tr->start <= 0 || tr->end <= 0) {
        return;
    }
    for (i = tr->start; i <= tr->end; i++) {
        printf("~ %d %s\n", i, ip2str(tr->hop[i - 1]));
    }
}

return_type: void


decompiled_code:
char *__fastcall cidr2str(__int64 a1)
{
unsigned int v1; // er12
char *v2; // rax

if ( !a1 )
_assert_fail("cidr", "inout.c", 0x7Eu, "cidr2str");
v1 = *(char *)(a1 + 4);
v2 = ip2str(*(_DWORD *)a1);
sprintf(str_5, "%s/%u", v2, v1);
return str_5;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 a1)
{
unsigned int v1; // er12
char *v2; // rax

if ( !a1 )
_assert_fail("cidr", "inout.c", 0x7Eu, "cidr2str");
v1 = *(char *)(a1 + 4);
v2 = func2(*(_DWORD *)a1);
sprintf(str_5, "%s/%u", v2, v1);
return str_5;
}

original_code:
const char *cidr2str(CIDR_t * cidr)
{
    static char str[20];
    ((void) sizeof ((cidr) ? 1 : 0), __extension__ ({ if (cidr) ; else __assert_fail ("cidr", "inout.c", 126, __extension__ __PRETTY_FUNCTION__); }));
    sprintf(str, "%s/%u", ip2str(cidr->net), cidr->pfx);
    return str;
}

canonical_original_code:
char *cidr2str(struct CIDR_t *cidr)
{
    static char str[20];
    ((void) sizeof ((cidr) ? 1 : 0), __extension__ ({ if (cidr) ; else __assert_fail ("cidr", "inout.c", 126, __extension__ __PRETTY_FUNCTION__); }));
    sprintf(str, "%s/%u", ip2str(cidr->net), cidr->pfx);
    return str;
}

variable_types: struct CIDR_t { unsigned int net; char pfx; } *

variable_types:
str
char [20]


decompiled_code:
int __fastcall str2cidr(void *src, __int64 a2)
{
size_t v2; // rax
char *v3; // rax
char *v4; // rbp
int result; // eax
char v6[56]; // [rsp+0h] [rbp-38h] BYREF

if ( !src || !a2 )
_assert_fail("str && cidr", "inout.c", 0x8Bu, "str2cidr");
v2 = strlen((const char *)src);
if ( (int)v2 > 19 )
{
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "str2cidr", "inout.c", 142LL);
fwrite("str2cidr() arguments `str' lenth is too long", 1uLL, 0x2CuLL, stderr);
LABEL_8:
result = fputc(10, stderr);
*(_DWORD *)a2 = 0;
*(_BYTE *)(a2 + 4) = 0;
return result;
}
memcpy(v6, src, v2 + 1);
v3 = strchr(v6, 47);
v4 = v3;
if ( !v3 )
{
result = resolve(v6);
*(_BYTE *)(a2 + 4) = 32;
*(_DWORD *)a2 = result;
return result;
}
*v3 = 0;
*(_DWORD *)a2 = resolve(v6);
result = atoi(v4 + 1);
*(_BYTE *)(a2 + 4) = result;
if ( (unsigned __int8)result > 0x20u )
{
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "str2cidr", "inout.c", 157LL);
fprintf(stderr, "Netmask prefix (%d) is illegal , must be /0 - /32.", (unsigned int)*(char *)(a2 + 4));
goto LABEL_8;
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(void *src, __int64 a2)
{
size_t v2; // rax
char *v3; // rax
char *v4; // rbp
int result; // eax
char v6[56]; // [rsp+0h] [rbp-38h] BYREF

if ( !src || !a2 )
_assert_fail("str && cidr", "inout.c", 0x8Bu, "str2cidr");
v2 = strlen((const char *)src);
if ( (int)v2 > 19 )
{
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "str2cidr", "inout.c", 142LL);
fwrite("str2cidr() arguments `str' lenth is too long", 1uLL, 0x2CuLL, stderr);
LABEL_8:
result = fputc(10, stderr);
*(_DWORD *)a2 = 0;
*(_BYTE *)(a2 + 4) = 0;
return result;
}
memcpy(v6, src, v2 + 1);
v3 = strchr(v6, 47);
v4 = v3;
if ( !v3 )
{
result = resolve(v6);
*(_BYTE *)(a2 + 4) = 32;
*(_DWORD *)a2 = result;
return result;
}
*v3 = 0;
*(_DWORD *)a2 = resolve(v6);
result = atoi(v4 + 1);
*(_BYTE *)(a2 + 4) = result;
if ( (unsigned __int8)result > 0x20u )
{
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "str2cidr", "inout.c", 157LL);
fprintf(stderr, "Netmask prefix (%d) is illegal , must be /0 - /32.", (unsigned int)*(char *)(a2 + 4));
goto LABEL_8;
}
return result;
}

original_code:
void str2cidr(const char *str, CIDR_t * cidr)
{
    int len;
    char copy[20];
    char *c = ((void *)0);
    ((void) sizeof ((str && cidr) ? 1 : 0), __extension__ ({ if (str && cidr) ; else __assert_fail ("str && cidr", "inout.c", 139, __extension__ __PRETTY_FUNCTION__); }));
    if ((len = strlen(str)) >= 20) {
        do{fprintf(stderr, "[!]"); fprintf(stderr, "%s:%s:%d: ", __func__, "inout.c", 142); fprintf(stderr, "str2cidr() arguments `str' lenth is too long"); fprintf(stderr, "\n");} while(0);
        cidr->net = 0;
        cidr->pfx = 0;
        return;
    }
    strcpy(copy, str);
    if ((c = strchr(copy, '/')) == ((void *)0)) {
        cidr->net = resolve(copy);
        cidr->pfx = 32;
    } else {
        *c = '\0';
        cidr->net = resolve(copy);
        c++;
        cidr->pfx = atoi(c);
        if (cidr->pfx < 0 || cidr->pfx > 32) {
            do{fprintf(stderr, "[!]"); fprintf(stderr, "%s:%s:%d: ", __func__, "inout.c", 157); fprintf(stderr, "Netmask prefix (%d) is illegal , must be /0 - /32.", cidr->pfx); fprintf(stderr, "\n");} while(0);
            cidr->net = 0;
            cidr->pfx = 0;
            return;
        }
    }
}

canonical_original_code:
void str2cidr(char *str, struct CIDR_t *cidr)
{
    int len;
    char copy[20];
    char *c = ((void *)0);
    ((void) sizeof ((str && cidr) ? 1 : 0), __extension__ ({ if (str && cidr) ; else __assert_fail ("str && cidr", "inout.c", 139, __extension__ __PRETTY_FUNCTION__); }));
    if ((len = strlen(str)) >= 20) {
        do{fprintf(stderr, "[!]"); fprintf(stderr, "%s:%s:%d: ", __func__, "inout.c", 142); fprintf(stderr, "str2cidr() arguments `str' lenth is too long"); fprintf(stderr, "\n");} while(0);
        cidr->net = 0;
        cidr->pfx = 0;
        return;
    }
    strcpy(copy, str);
    if ((c = strchr(copy, '/')) == ((void *)0)) {
        cidr->net = resolve(copy);
        cidr->pfx = 32;
    } else {
        *c = '\0';
        cidr->net = resolve(copy);
        c++;
        cidr->pfx = atoi(c);
        if (cidr->pfx < 0 || cidr->pfx > 32) {
            do{fprintf(stderr, "[!]"); fprintf(stderr, "%s:%s:%d: ", __func__, "inout.c", 157); fprintf(stderr, "Netmask prefix (%d) is illegal , must be /0 - /32.", cidr->pfx); fprintf(stderr, "\n");} while(0);
            cidr->net = 0;
            cidr->pfx = 0;
            return;
        }
    }
}

variable_types:
str
char *

variable_types: len int

variable_types:
copy
char [20]

variable_types:
c
char *

user_defined_types: struct CIDR_t { unsigned int net; char pfx; }


decompiled_code:
int __fastcall str2ipport(void *src, unsigned int *a2, _WORD *a3)
{
size_t v4; // rax
char *v5; // rax
char *v6; // r13
int result; // eax
unsigned int v8; // ebp
char *v9; // rax
char v10[72]; // [rsp+0h] [rbp-48h] BYREF

if ( a3 == 0LL || a2 == 0LL || !src )
_assert_fail("str && ip && port", "inout.c", 0xAEu, "str2ipport");
v4 = strlen((const char *)src);
if ( (int)v4 > 23 )
{
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "str2ipport", "inout.c", 177LL);
fwrite("str2ipport arguments str lenth is too long", 1uLL, 0x2AuLL, stderr);
result = fputc(10, stderr);
*a2 = 0;
*a3 = 0;
}
else
{
memcpy(v10, src, v4 + 1);
v5 = strchr(v10, 58);
v6 = v5;
if ( v5 )
{
*v5 = 0;
*a2 = resolve(v10);
*a3 = atoi(v6 + 1);
}
else
{
*a2 = resolve(v10);
*a3 = 0;
}
result = opt_debug;
if ( opt_debug )
{
v8 = (unsigned __int16)*a3;
v9 = ip2str(*a2);
fprintf(stdout, "[D]str2ipport (%s) -> (%s:%u)\n", (const char *)src, v9, v8);
result = fflush(stdout);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(void *src, unsigned int *a2, _WORD *a3)
{
size_t v4; // rax
char *v5; // rax
char *v6; // r13
int result; // eax
unsigned int v8; // ebp
char *v9; // rax
char v10[72]; // [rsp+0h] [rbp-48h] BYREF

if ( a3 == 0LL || a2 == 0LL || !src )
_assert_fail("str && ip && port", "inout.c", 0xAEu, "str2ipport");
v4 = strlen((const char *)src);
if ( (int)v4 > 23 )
{
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "str2ipport", "inout.c", 177LL);
fwrite("str2ipport arguments str lenth is too long", 1uLL, 0x2AuLL, stderr);
result = fputc(10, stderr);
*a2 = 0;
*a3 = 0;
}
else
{
memcpy(v10, src, v4 + 1);
v5 = strchr(v10, 58);
v6 = v5;
if ( v5 )
{
*v5 = 0;
*a2 = resolve(v10);
*a3 = atoi(v6 + 1);
}
else
{
*a2 = resolve(v10);
*a3 = 0;
}
result = opt_debug;
if ( opt_debug )
{
v8 = (unsigned __int16)*a3;
v9 = func2(*a2);
fprintf(stdout, "[D]str2ipport (%s) -> (%s:%u)\n", (const char *)src, v9, v8);
result = fflush(stdout);
}
}
return result;
}

original_code:
void str2ipport(const char *str, IP_t * ip, unsigned short *port)
{
    int len;
    char copy[24];
    char *c = ((void *)0);
    ((void) sizeof ((str && ip && port) ? 1 : 0), __extension__ ({ if (str && ip && port) ; else __assert_fail ("str && ip && port", "inout.c", 174, __extension__ __PRETTY_FUNCTION__); }));
    if ((len = strlen(str)) >= 24) {
        do{fprintf(stderr, "[!]"); fprintf(stderr, "%s:%s:%d: ", __func__, "inout.c", 177); fprintf(stderr, "str2ipport arguments str lenth is too long"); fprintf(stderr, "\n");} while(0);
        *ip = 0;
        *port = 0;
        return;
    }
    strcpy(copy, str);
    if ((c = strchr(copy, ':')) == ((void *)0)) {
        *ip = resolve(copy);
        *port = 0;
    } else {
        *c = '\0';
        *ip = resolve(copy);
        c++;
        *port = atoi(c);
    }
    do{if (_opt_debug) {fprintf(stdout, "[D]" "str2ipport (%s) -> (%s:%u)\n", str, ip2str(*ip), *port); fflush(stdout);} } while(0);
}

canonical_original_code:
void str2ipport(char *str, unsigned int *ip, unsigned short *port)
{
    int len;
    char copy[24];
    char *c = ((void *)0);
    ((void) sizeof ((str && ip && port) ? 1 : 0), __extension__ ({ if (str && ip && port) ; else __assert_fail ("str && ip && port", "inout.c", 174, __extension__ __PRETTY_FUNCTION__); }));
    if ((len = strlen(str)) >= 24) {
        do{fprintf(stderr, "[!]"); fprintf(stderr, "%s:%s:%d: ", __func__, "inout.c", 177); fprintf(stderr, "str2ipport arguments str lenth is too long"); fprintf(stderr, "\n");} while(0);
        *ip = 0;
        *port = 0;
        return;
    }
    strcpy(copy, str);
    if ((c = strchr(copy, ':')) == ((void *)0)) {
        *ip = resolve(copy);
        *port = 0;
    } else {
        *c = '\0';
        *ip = resolve(copy);
        c++;
        *port = atoi(c);
    }
    do{if (_opt_debug) {fprintf(stdout, "[D]" "str2ipport (%s) -> (%s:%u)\n", str, ip2str(*ip), *port); fflush(stdout);} } while(0);
}

variable_types:
ip
unsigned int *

variable_types:
port
unsigned short *

variable_types:
copy
char [24]


decompiled_code:
int fclose_dump_fp()
{
if ( !dump_fp )
_assert_fail("_dump_fp", "inout.c", 0xC6u, "fclose_dump_fp");
return fclose(dump_fp);
}

canonical_decompiled_code:
int func10()
{
if ( !dump_fp )
_assert_fail("_dump_fp", "inout.c", 0xC6u, "fclose_dump_fp");
return fclose(dump_fp);
}

original_code:
void fclose_dump_fp(void)
{
    ((void) sizeof ((_dump_fp) ? 1 : 0), __extension__ ({ if (_dump_fp) ; else __assert_fail ("_dump_fp", "inout.c", 198, __extension__ __PRETTY_FUNCTION__); }));
    fclose(_dump_fp);
}

canonical_original_code:
void fclose_dump_fp()
{
    ((void) sizeof ((_dump_fp) ? 1 : 0), __extension__ ({ if (_dump_fp) ; else __assert_fail ("_dump_fp", "inout.c", 198, __extension__ __PRETTY_FUNCTION__); }));
    fclose(_dump_fp);
}


decompiled_code:
char *__fastcall ptype2str(char a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 27 )
{
result = aIUn;
if ( (unsigned __int8)(a1 - 12) > 0xFu )
result = &PTYPE2STRING[5 * a1];
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 27 )
{
result = aIUn;
if ( (unsigned __int8)(a1 - 12) > 0xFu )
result = &PTYPE2STRING[5 * a1];
}
return result;
}

original_code:
const char *ptype2str(char type)
{
    if (type > (12 + 15))
        return ((void *)0);
    else
        return (type>=12&&type<=(12 + 15)?1:0) ?
            PTYPE2STRING[12] : PTYPE2STRING[(int) (type)];
}

variable_types: type char


decompiled_code:
char *__fastcall ip2str(unsigned int a1)
{
struct in_addr v2; // [rsp+Ch] [rbp-Ch]

v2.s_addr = _bswap_32(a1);
return inet_ntoa(v2);
}

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1)
{
struct in_addr v2; // [rsp+Ch] [rbp-Ch]

v2.s_addr = func0(a1);
return inet_ntoa(v2);
}

original_code:
const char *ip2str(IP_t ip)
{
    IP_t i = htonl(ip);
    return inet_ntoa(*(struct in_addr *) &(i));
}

canonical_original_code:
char *ip2str(unsigned int ip)
{
    unsigned int i = htonl(ip);
    return inet_ntoa(*(struct in_addr *) &(i));
}

variable_types:
i
unsigned int


decompiled_code:
void __fastcall print_pi(__int64 a1)
{
char v2; // di
char *v3; // rax
unsigned int v4; // er12
const char *v5; // rbp
char *v6; // rax

if ( !a1 )
_assert_fail("i", "inout.c", 0x34u, "print_pi");
v2 = *(_BYTE *)(a1 + 2);
if ( v2 )
{
if ( opt_verbose )
{
v3 = ptype2str(v2);
v4 = *(unsigned __int16 *)(a1 + 18);
v5 = v3;
v6 = ip2str(*(_DWORD *)(a1 + 12));
fprintf(stdout, "> %u %s:%u %s", *(unsigned __int8 *)(a1 + 4), v6, v4, v5);
fflush(stdout);
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
char v2; // di
char *v3; // rax
unsigned int v4; // er12
const char *v5; // rbp
char *v6; // rax

if ( !a1 )
_assert_fail("i", "inout.c", 0x34u, "print_pi");
v2 = *(_BYTE *)(a1 + 2);
if ( v2 )
{
if ( opt_verbose )
{
v3 = func1(v2);
v4 = *(unsigned __int16 *)(a1 + 18);
v5 = v3;
v6 = func2(*(_DWORD *)(a1 + 12));
fprintf(stdout, "> %u %s:%u %s", *(unsigned __int8 *)(a1 + 4), v6, v4, v5);
fflush(stdout);
}
}
}

original_code:
void print_pi(const struct probing_info *i)
{
    ((void) sizeof ((i) ? 1 : 0), __extension__ ({ if (i) ; else __assert_fail ("i", "inout.c", 52, __extension__ __PRETTY_FUNCTION__); }));
    if (i->type == 0)
        return;
    do{if (_opt_verbose) {fprintf(stdout, "> %u %s:%u %s", i->ttl, ip2str(i->dst), i->dport, ptype2str(i->type)); fflush(stdout);} } while(0);
}

canonical_original_code:
void print_pi(struct probing_info *i)
{
    ((void) sizeof ((i) ? 1 : 0), __extension__ ({ if (i) ; else __assert_fail ("i", "inout.c", 52, __extension__ __PRETTY_FUNCTION__); }));
    if (i->type == 0)
        return;
    do{if (_opt_verbose) {fprintf(stdout, "> %u %s:%u %s", i->ttl, ip2str(i->dst), i->dport, ptype2str(i->type)); fflush(stdout);} } while(0);
}

variable_types: struct probing_info { unsigned short seq; unsigned char type; unsigned char option; unsigned char ttl; unsigned char wt; unsigned short zero; unsigned int src; unsigned int dst; unsigned short sport; unsigned short dport; } *


decompiled_code:
int __fastcall print_ri(__int64 a1)
{
char v2; // di
int result; // eax
char *v4; // r12
char *v5; // rax
int v6; // edx

if ( !a1 )
_assert_fail("i", "inout.c", 0x41u, "print_ri");
v2 = *(_BYTE *)(a1 + 2);
result = opt_verbose;
if ( v2 )
{
if ( v2 == 6 )
{
if ( opt_verbose )
{
fwrite(" - *\n", 1uLL, 5uLL, stdout);
return fflush(stdout);
}
}
else
{
if ( !opt_verbose )
return result;
v4 = ptype2str(v2);
v5 = ip2str(*(_DWORD *)(a1 + 4));
fprintf(stdout, " - %s %s", v5, v4);
fflush(stdout);
v6 = *(unsigned __int8 *)(a1 + 2);
result = opt_verbose;
if ( (unsigned __int8)(v6 - 12) <= 0xFu )
{
if ( !opt_verbose )
return result;
fprintf(stdout, ":%d", (unsigned int)(v6 - 12));
fflush(stdout);
result = opt_verbose;
}
if ( result )
{
fprintf(
stdout,
" %u %u %.3fms\n",
*(unsigned __int8 *)(a1 + 10),
*(unsigned __int16 *)(a1 + 8),
(float)((float)*(int *)(a1 + 12) / 1000.0));
return fflush(stdout);
}
}
}
else if ( opt_verbose )
{
fwrite(" - error\n", 1uLL, 9uLL, stdout);
return fflush(stdout);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
char v2; // di
int result; // eax
char *v4; // r12
char *v5; // rax
int v6; // edx

if ( !a1 )
_assert_fail("i", "inout.c", 0x41u, "print_ri");
v2 = *(_BYTE *)(a1 + 2);
result = opt_verbose;
if ( v2 )
{
if ( v2 == 6 )
{
if ( opt_verbose )
{
fwrite(" - *\n", 1uLL, 5uLL, stdout);
return fflush(stdout);
}
}
else
{
if ( !opt_verbose )
return result;
v4 = func1(v2);
v5 = func2(*(_DWORD *)(a1 + 4));
fprintf(stdout, " - %s %s", v5, v4);
fflush(stdout);
v6 = *(unsigned __int8 *)(a1 + 2);
result = opt_verbose;
if ( (unsigned __int8)(v6 - 12) <= 0xFu )
{
if ( !opt_verbose )
return result;
fprintf(stdout, ":%d", (unsigned int)(v6 - 12));
fflush(stdout);
result = opt_verbose;
}
if ( result )
{
fprintf(
stdout,
" %u %u %.3fms\n",
*(unsigned __int8 *)(a1 + 10),
*(unsigned __int16 *)(a1 + 8),
(float)((float)*(int *)(a1 + 12) / 1000.0));
return fflush(stdout);
}
}
}
else if ( opt_verbose )
{
fwrite(" - error\n", 1uLL, 9uLL, stdout);
return fflush(stdout);
}
return result;
}

original_code:
void print_ri(const struct return_info *i)
{
    static int old = 0;
    ((void) sizeof ((i) ? 1 : 0), __extension__ ({ if (i) ; else __assert_fail ("i", "inout.c", 65, __extension__ __PRETTY_FUNCTION__); }));
    if (i->type == 0) {
        do{if (_opt_verbose) {fprintf(stdout, " - error\n"); fflush(stdout);} } while(0);
        return;
    }
    if (i->type == 6) {
        do{if (_opt_verbose) {fprintf(stdout, " - *\n"); fflush(stdout);} } while(0);
        return;
    }
    do{if (_opt_verbose) {fprintf(stdout, " - %s %s", ip2str(i->from), ptype2str(i->type)); fflush(stdout);} } while(0);
    if ((i->type>=12&&i->type<=(12 + 15)?1:0))
        do{if (_opt_verbose) {fprintf(stdout, ":%d", (i->type-12)); fflush(stdout);} } while(0);
    do{if (_opt_verbose) {fprintf(stdout, " %u %u %.3fms\n", i->ttl, i->id, (float) (i->rtt) / (float) 1000); fflush(stdout);} } while(0);
    old = i->seq;
}

canonical_original_code:
void print_ri(struct return_info *i)
{
    static int old = 0;
    ((void) sizeof ((i) ? 1 : 0), __extension__ ({ if (i) ; else __assert_fail ("i", "inout.c", 65, __extension__ __PRETTY_FUNCTION__); }));
    if (i->type == 0) {
        do{if (_opt_verbose) {fprintf(stdout, " - error\n"); fflush(stdout);} } while(0);
        return;
    }
    if (i->type == 6) {
        do{if (_opt_verbose) {fprintf(stdout, " - *\n"); fflush(stdout);} } while(0);
        return;
    }
    do{if (_opt_verbose) {fprintf(stdout, " - %s %s", ip2str(i->from), ptype2str(i->type)); fflush(stdout);} } while(0);
    if ((i->type>=12&&i->type<=(12 + 15)?1:0))
        do{if (_opt_verbose) {fprintf(stdout, ":%d", (i->type-12)); fflush(stdout);} } while(0);
    do{if (_opt_verbose) {fprintf(stdout, " %u %u %.3fms\n", i->ttl, i->id, (float) (i->rtt) / (float) 1000); fflush(stdout);} } while(0);
    old = i->seq;
}

variable_types: struct return_info { unsigned short seq; unsigned char type; unsigned char zero1; unsigned int from; unsigned short id; unsigned char ttl; unsigned char zero2; unsigned int rtt; } *

variable_types: old int


getipname

decompiled_code:
struct hostent *__fastcall getipname(unsigned int a1)
{
int v1; // eax
struct hostent *result; // rax

v1 = _bswap_32(a1);
if ( v1 == lastreq_3 )
return (struct hostent *)last_answerp_2;
lastreq_3 = v1;
result = gethostbyaddr(&lastreq_3, 4u, 2);
if ( result )
{
strncpy(answer_1, result->h_name, 0x400uLL);
result = (struct hostent *)answer_1;
last_answerp_2 = (__int64)answer_1;
}
else
{
last_answerp_2 = 0LL;
}
return result;
}

canonical_decompiled_code:
struct hostent *__fastcall func3(unsigned int a1)
{
int v1; // eax
struct hostent *result; // rax

v1 = func0(a1);
if ( v1 == lastreq_3 )
return (struct hostent *)last_answerp_2;
lastreq_3 = v1;
result = gethostbyaddr(&lastreq_3, 4u, 2);
if ( result )
{
strncpy(answer_1, result->h_name, 0x400uLL);
result = (struct hostent *)answer_1;
last_answerp_2 = (__int64)answer_1;
}
else
{
last_answerp_2 = 0LL;
}
return result;
}

original_code:
char *getipname(IP_t addr)
{
    static char answer[1024];
    static IP_t lastreq = 0;
    struct hostent *he;
    static char *last_answerp = ((void *)0);
    if (htonl(addr) == lastreq)
        return last_answerp;
    lastreq = htonl(addr);
    he = gethostbyaddr((char *) &lastreq, 4, 2);
    if (he == ((void *)0)) {
        last_answerp = ((void *)0);
        return ((void *)0);
    }
    strncpy(answer, he->h_name, 1024);
    last_answerp = answer;
    return answer;
}

canonical_original_code:
char *getipname(unsigned int addr)
{
    static char answer[1024];
    static unsigned int lastreq = 0;
    struct hostent *he;
    static char *last_answerp = ((void *)0);
    if (htonl(addr) == lastreq)
        return last_answerp;
    lastreq = htonl(addr);
    he = gethostbyaddr((char *) &lastreq, 4, 2);
    if (he == ((void *)0)) {
        last_answerp = ((void *)0);
        return ((void *)0);
    }
    strncpy(answer, he->h_name, 1024);
    last_answerp = answer;
    return answer;
}

variable_types:
addr
unsigned int

variable_types:
answer
char [1024]

variable_types:
lastreq
unsigned int

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


usage

decompiled_code:
void __fastcall __noreturn usage(int status)
{
if ( status )
fprintf(stderr, "Try `%s -h' for more information.\n", (const char *)program_name);
else
printf(
"Usage: %s [OPTION] [DESTINATION]...\n"
" OPTION is:\n"
" -a . . . . . . . 'ally' two IP addresses\n"
" -d . . . . . . . debug output\n"
" -f IP_list . . . destination IP address list file\n"
" -h . . . . . . . help\n"
" -i . . . . . . . 'iffinder' one IP address\n"
" -M max_pfx_len . max prefix lenth, def: 30\n"
" -m min_pfx_len . min prefix lenth, def: 20\n"
" -n min_no_new . min no-new-found prefix lenth, def: 24\n"
" -p probing_type . probing packet types (Mix/TCP/UDP/ICMP), def: Mix\n"
" -s server:port . proberd server address with port, def: 11661\n"
" -t test_pfx_len . last-hop criterion test prefix length, def: off\n"
" -u server_path . proberd server Unix path, def: /tmp/pbr_usock\n"
" -v . . . . . . . verbose output\n"
" -V . . . . . . . version about\n"
"\n"
" DESTINATION is: IP_address[/prefixlen]\n"
" If neither destiantions nor option -f is here, \n"
" read destinations from stdin.\n",
(const char *)program_name);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int status)
{
if ( status )
fprintf(stderr, "Try `%s -h' for more information.\n", (const char *)program_name);
else
printf(
"Usage: %s [OPTION] [DESTINATION]...\n"
" OPTION is:\n"
" -a . . . . . . . 'ally' two IP addresses\n"
" -d . . . . . . . debug output\n"
" -f IP_list . . . destination IP address list file\n"
" -h . . . . . . . help\n"
" -i . . . . . . . 'iffinder' one IP address\n"
" -M max_pfx_len . max prefix lenth, def: 30\n"
" -m min_pfx_len . min prefix lenth, def: 20\n"
" -n min_no_new . min no-new-found prefix lenth, def: 24\n"
" -p probing_type . probing packet types (Mix/TCP/UDP/ICMP), def: Mix\n"
" -s server:port . proberd server address with port, def: 11661\n"
" -t test_pfx_len . last-hop criterion test prefix length, def: off\n"
" -u server_path . proberd server Unix path, def: /tmp/pbr_usock\n"
" -v . . . . . . . verbose output\n"
" -V . . . . . . . version about\n"
"\n"
" DESTINATION is: IP_address[/prefixlen]\n"
" If neither destiantions nor option -f is here, \n"
" read destinations from stdin.\n",
(const char *)program_name);
exit(status);
}

original_code:
static void usage(int status)
{
    if (status != 0) {
        fprintf(stderr, "Try `%s -h' for more information.\n", _program_name);
    } else {
        printf("Usage: %s [OPTION] [DESTINATION]...\n""  OPTION is:\n""    -a   . . . . . . . 'ally' two IP addresses\n""    -d   . . . . . . . debug output\n""    -f IP_list   . . . destination IP address list file\n""    -h   . . . . . . . help\n""    -i   . . . . . . . 'iffinder' one IP address\n""    -M max_pfx_len   . max prefix lenth, def: 30\n""    -m min_pfx_len   . min prefix lenth, def: 20\n""    -n min_no_new    . min no-new-found prefix lenth, def: 24\n""    -p probing_type  . probing packet types (Mix/TCP/UDP/ICMP), def: Mix\n""    -s server:port   . proberd server address with port, def: 11661\n""    -t test_pfx_len  . last-hop criterion test prefix length, def: off\n""    -u server_path   . proberd server Unix path, def: /tmp/pbr_usock\n""    -v   . . . . . . . verbose output\n""    -V   . . . . . . . version about\n""\n""  DESTINATION is: IP_address[/prefixlen]\n""    If neither destiantions nor option -f is here, \n""    read destinations from stdin.\n", _program_name);
    }
    exit(status);
}

variable_types: status int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rsi
unsigned int v5; // eax
__int64 v6; // rdx
unsigned int v7; // er14
int v8; // eax
int v9; // ebx
const char **v10; // rbp
const char *v11; // rdx
__int64 v12; // rbp
FILE *v13; // r12
__int64 v14; // r8
int *v15; // rax
char *v16; // rdx
unsigned int v17; // [rsp+0h] [rbp-A8h] BYREF
char v18; // [rsp+4h] [rbp-A4h]
int v19; // [rsp+8h] [rbp-A0h] BYREF
int v20[38]; // [rsp+10h] [rbp-98h] BYREF

parse_opt(argc, (char **)argv);
probing_ini();
if ( opt_svripport )
{
str2ipport(opt_svripport, v20, &v19);
if ( !v20[0] )
{
fwrite("[X]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", 250LL);
fprintf(stderr, "Cann't parse (%s)", opt_svripport);
goto LABEL_49;
}
v4 = (unsigned __int16)v19;
if ( !(_WORD)v19 )
v4 = 11661LL;
LOWORD(v19) = v4;
v5 = new_prober((unsigned int)v20[0], v4, 0LL);
v6 = opt_svrpath;
v7 = v5;
if ( !opt_svrpath )
goto LABEL_6;
}
else
{
v6 = opt_svrpath;
if ( !opt_svrpath )
{
v7 = new_prober(opt_svripport, 0LL, "/tmp/pbr_usock");
LABEL_6:
v8 = new_iptab();
v9 = optind;
global_map = v8;
if ( argc <= optind )
{
LABEL_18:
if ( !opt_iplist )
{
if ( !opt_fstdin )
goto LABEL_42;
goto LABEL_46;
}
v13 = fopen(opt_iplist, "r");
if ( v13 )
{
if ( !opt_fstdin )
goto LABEL_21;
LABEL_46:
v13 = stdin;
while ( 1 )
{
while ( 1 )
{
LABEL_21:
if ( (unsigned int)_isoc99_fscanf(v13, "%80s", v20) != 1 )
goto LABEL_40;
str2cidr(v20, &v17);
if ( v17 )
break;
fwrite("[!]", 1uLL, 3uLL, stderr);
v14 = 318LL;
LABEL_33:
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", v14);
fprintf(stderr, "Cann't resolve (%s)", (const char *)v20);
fputc(10, stderr);
}
if ( opt_ally )
{
if ( (unsigned int)_isoc99_fscanf(v13, "%80s", v20) != 1 )
{
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", 324LL);
fwrite("Option -a, need a pair of IP addresses each time", 1uLL, 0x30uLL, stderr);
fputc(10, stderr);
LABEL_40:
if ( stdin != v13 )
fclose(v13);
LABEL_42:
del_prober(v7);
del_iptab(global_map);
exit(0);
}
str2cidr(v20, &v19);
if ( !v19 )
{
fwrite("[!]", 1uLL, 3uLL, stderr);
v14 = 329LL;
goto LABEL_33;
}
ally(v7, v17);
}
else if ( opt_iffinder )
{
iffinder(v7, v17, &v19);
}
else if ( v18 == 32 )
{
normal_traceroute(v7);
}
else
{
tree_traceroute(v7, &v17);
}
}
}
fwrite("[X]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", 308LL);
fprintf(stderr, "fopen read-only file (%s)", opt_iplist);
v15 = _errno_location();
v16 = strerror(*v15);
fprintf(stderr, " %s.", v16);
LABEL_49:
fputc(10, stderr);
exit(1);
}
while ( 1 )
{
v12 = v9;
str2cidr(argv[v12], &v17);
if ( !v17 )
break;
if ( opt_ally )
{
if ( ++v9 >= argc )
{
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", 276LL);
fwrite("Option -a, need a pair of IP addresses each time", 1uLL, 0x30uLL, stderr);
fputc(10, stderr);
goto LABEL_18;
}
v10 = &argv[v12 + 1];
str2cidr(*v10, v20);
if ( v20[0] )
{
ally(v7, v17);
goto LABEL_12;
}
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", 281LL);
v11 = *v10;
LABEL_11:
fprintf(stderr, "Cann't resolve (%s)", v11);
fputc(10, stderr);
LABEL_12:
if ( argc <= ++v9 )
goto LABEL_18;
}
else
{
if ( opt_iffinder )
{
iffinder(v7, v17, v20);
goto LABEL_12;
}
if ( v18 == 32 )
{
normal_traceroute(v7);
goto LABEL_12;
}
++v9;
tree_traceroute(v7, &v17);
if ( argc <= v9 )
goto LABEL_18;
}
}
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", 269LL);
v11 = argv[v9];
goto LABEL_11;
}
}
v7 = new_prober(0LL, 0LL, v6);
goto LABEL_6;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v4; // rsi
unsigned int v5; // eax
__int64 v6; // rdx
unsigned int v7; // er14
int v8; // eax
int v9; // ebx
const char **v10; // rbp
const char *v11; // rdx
__int64 v12; // rbp
FILE *v13; // r12
__int64 v14; // r8
int *v15; // rax
char *v16; // rdx
unsigned int v17; // [rsp+0h] [rbp-A8h] BYREF
char v18; // [rsp+4h] [rbp-A4h]
int v19; // [rsp+8h] [rbp-A0h] BYREF
int v20[38]; // [rsp+10h] [rbp-98h] BYREF

func1(argc, (char **)argv);
probing_ini();
if ( opt_svripport )
{
str2ipport(opt_svripport, v20, &v19);
if ( !v20[0] )
{
fwrite("[X]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", 250LL);
fprintf(stderr, "Cann't parse (%s)", opt_svripport);
goto LABEL_49;
}
v4 = (unsigned __int16)v19;
if ( !(_WORD)v19 )
v4 = 11661LL;
LOWORD(v19) = v4;
v5 = new_prober((unsigned int)v20[0], v4, 0LL);
v6 = opt_svrpath;
v7 = v5;
if ( !opt_svrpath )
goto LABEL_6;
}
else
{
v6 = opt_svrpath;
if ( !opt_svrpath )
{
v7 = new_prober(opt_svripport, 0LL, "/tmp/pbr_usock");
LABEL_6:
v8 = new_iptab();
v9 = optind;
global_map = v8;
if ( argc <= optind )
{
LABEL_18:
if ( !opt_iplist )
{
if ( !opt_fstdin )
goto LABEL_42;
goto LABEL_46;
}
v13 = fopen(opt_iplist, "r");
if ( v13 )
{
if ( !opt_fstdin )
goto LABEL_21;
LABEL_46:
v13 = stdin;
while ( 1 )
{
while ( 1 )
{
LABEL_21:
if ( (unsigned int)_isoc99_fscanf(v13, "%80s", v20) != 1 )
goto LABEL_40;
str2cidr(v20, &v17);
if ( v17 )
break;
fwrite("[!]", 1uLL, 3uLL, stderr);
v14 = 318LL;
LABEL_33:
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", v14);
fprintf(stderr, "Cann't resolve (%s)", (const char *)v20);
fputc(10, stderr);
}
if ( opt_ally )
{
if ( (unsigned int)_isoc99_fscanf(v13, "%80s", v20) != 1 )
{
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", 324LL);
fwrite("Option -a, need a pair of IP addresses each time", 1uLL, 0x30uLL, stderr);
fputc(10, stderr);
LABEL_40:
if ( stdin != v13 )
fclose(v13);
LABEL_42:
del_prober(v7);
del_iptab(global_map);
exit(0);
}
str2cidr(v20, &v19);
if ( !v19 )
{
fwrite("[!]", 1uLL, 3uLL, stderr);
v14 = 329LL;
goto LABEL_33;
}
ally(v7, v17);
}
else if ( opt_iffinder )
{
iffinder(v7, v17, &v19);
}
else if ( v18 == 32 )
{
normal_traceroute(v7);
}
else
{
tree_traceroute(v7, &v17);
}
}
}
fwrite("[X]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", 308LL);
fprintf(stderr, "fopen read-only file (%s)", opt_iplist);
v15 = _errno_location();
v16 = strerror(*v15);
fprintf(stderr, " %s.", v16);
LABEL_49:
fputc(10, stderr);
exit(1);
}
while ( 1 )
{
v12 = v9;
str2cidr(argv[v12], &v17);
if ( !v17 )
break;
if ( opt_ally )
{
if ( ++v9 >= argc )
{
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", 276LL);
fwrite("Option -a, need a pair of IP addresses each time", 1uLL, 0x30uLL, stderr);
fputc(10, stderr);
goto LABEL_18;
}
v10 = &argv[v12 + 1];
str2cidr(*v10, v20);
if ( v20[0] )
{
ally(v7, v17);
goto LABEL_12;
}
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", 281LL);
v11 = *v10;
LABEL_11:
fprintf(stderr, "Cann't resolve (%s)", v11);
fputc(10, stderr);
LABEL_12:
if ( argc <= ++v9 )
goto LABEL_18;
}
else
{
if ( opt_iffinder )
{
iffinder(v7, v17, v20);
goto LABEL_12;
}
if ( v18 == 32 )
{
normal_traceroute(v7);
goto LABEL_12;
}
++v9;
tree_traceroute(v7, &v17);
if ( argc <= v9 )
goto LABEL_18;
}
}
fwrite("[!]", 1uLL, 3uLL, stderr);
fprintf(stderr, "%s:%s:%d: ", "main", "fastrace.c", 269LL);
v11 = argv[v9];
goto LABEL_11;
}
}
v7 = new_prober(0LL, 0LL, v6);
goto LABEL_6;
}

original_code:
int main(int argc, char **argv)
{
    parse_opt(argc, argv);
    if (_opt_isd) {
        if (daemon(0, 0) == -1) {
            perror("daemon() error");
            exit(1);
        };
    }
    pbr_start();
    pbr_loop();
    pbr_stop();
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


repo: YustasSwamp/blutechheli

decompiled_code:
void turnoff_heli()
{
cmd_control = 8355818LL;
}

canonical_decompiled_code:
void func1()
{
cmd_control = 8355818LL;
}

original_code:
void turnoff_heli(void)
{
 cmd_control = 0x007f7f0a | (7 << 5);
}

canonical_original_code:
void turnoff_heli()
{
 cmd_control = 0x007f7f0a | (7 << 5);
}


finalize

decompiled_code:
void __noreturn finalize()
{
puts("\nTurn helicopter off.");
turnoff_heli();
usleep(0x30D40u);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
puts("\nTurn helicopter off.");
func1();
usleep(0x30D40u);
exit(1);
}

original_code:
void finalize(int s){
 printf("\nTurn helicopter off.\n");
 turnoff_heli();
 usleep(200000);
 exit(1);
}

variable_types: s int


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

if ( a1 > 128 )
{
v2 = 0xFFFFFFFF80000000LL;
}
else
{
result = (unsigned __int8)cmd_control | 0x7F7F0ALL;
if ( a1 <= 0 )
{
cmd_control = (unsigned __int8)cmd_control | 0x7F7F0ALL;
return result;
}
v2 = a1 << 24;
}
result = cmd_control & 0xFFFFFF | v2;
cmd_control = result;
return result;
}

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

if ( a1 > 128 )
{
v2 = 0xFFFFFFFF80000000LL;
}
else
{
result = (unsigned __int8)cmd_control | 0x7F7F0ALL;
if ( a1 <= 0 )
{
cmd_control = (unsigned __int8)cmd_control | 0x7F7F0ALL;
return result;
}
v2 = a1 << 24;
}
result = cmd_control & 0xFFFFFF | v2;
cmd_control = result;
return result;
}

original_code:
void set_throttle(int val)
{
 if ( val > 128 )
  val = 128;
 if ( val < 0 )
  val = 0;
 if (val == 0)
  cmd_control = (cmd_control & ~0xffffff00) | 0x007f7f0a;
 else
  cmd_control = (cmd_control & ~0xff000000) | (val << 24);
}

variable_types: val int


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

if ( a1 < 0 )
a1 = 0;
result = cmd_control & 0xFFFFFFFFFF00FFFFLL;
if ( a1 > 255 )
a1 = 255;
cmd_control = result | (a1 << 16);
return result;
}

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

if ( a1 < 0 )
a1 = 0;
result = cmd_control & 0xFFFFFFFFFF00FFFFLL;
if ( a1 > 255 )
a1 = 255;
cmd_control = result | (a1 << 16);
return result;
}

original_code:
void set_pitch(int val)
{
 if ( val > 255 )
  val = 255;
 if ( val < 0 )
  val = 0;
 cmd_control = (cmd_control & ~0xff0000) | (val << 16);
}


decompiled_code:
__int16 __fastcall set_yaw(int a1)
{
__int64 v1; // rax

if ( a1 < 0 )
a1 = 0;
v1 = cmd_control;
BYTE1(v1) = 0;
if ( a1 > 255 )
a1 = 255;
cmd_control = v1 | (a1 << 8);
return v1;
}

canonical_decompiled_code:
__int16 __fastcall func5(int a1)
{
__int64 v1; // rax

if ( a1 < 0 )
a1 = 0;
v1 = cmd_control;
BYTE1(v1) = 0;
if ( a1 > 255 )
a1 = 255;
cmd_control = v1 | (a1 << 8);
return v1;
}

original_code:
void set_yaw(int val)
{
 if ( val > 255 )
  val = 255;
 if ( val < 0 )
  val = 0;
 cmd_control = (cmd_control & ~0xff00) | (val << 8);
}


decompiled_code:
void get_trimmer()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
int get_trimmer(void)
{
 int val = (cmd_control & 0x1f) >> 0;
}

canonical_original_code:
int get_trimmer()
{
 int val = (cmd_control & 0x1f) >> 0;
}


decompiled_code:
unsigned __int64 dec_trimmer()
{
int v0; // eax
int v1; // eax
unsigned __int64 result; // rax

get_trimmer();
v1 = v0 - 1;
if ( v1 < 0 )
v1 = 0;
result = cmd_control & 0xFFFFFFFFFFFFFFE0LL | v1;
cmd_control = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 func7()
{
int v0; // eax
int v1; // eax
unsigned __int64 result; // rax

func6();
v1 = v0 - 1;
if ( v1 < 0 )
v1 = 0;
result = cmd_control & 0xFFFFFFFFFFFFFFE0LL | v1;
cmd_control = result;
return result;
}

original_code:
void dec_trimmer(void)
{
 int val = get_trimmer() - 1;
 if ( val < 0 )
  val = 0;
 cmd_control = (cmd_control & ~0x1f) | (val << 0);
}

canonical_original_code:
void dec_trimmer()
{
 int val = get_trimmer() - 1;
 if ( val < 0 )
  val = 0;
 cmd_control = (cmd_control & ~0x1f) | (val << 0);
}


decompiled_code:
unsigned __int64 inc_trimmer()
{
int v0; // eax
int v1; // eax
unsigned __int64 result; // rax

get_trimmer();
v1 = v0 + 1;
if ( v1 > 20 )
v1 = 20;
result = cmd_control & 0xFFFFFFFFFFFFFFE0LL | v1;
cmd_control = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 func8()
{
int v0; // eax
int v1; // eax
unsigned __int64 result; // rax

func6();
v1 = v0 + 1;
if ( v1 > 20 )
v1 = 20;
result = cmd_control & 0xFFFFFFFFFFFFFFE0LL | v1;
cmd_control = result;
return result;
}

original_code:
void inc_trimmer(void)
{
 int val = get_trimmer() + 1;
 if ( val > 20 )
  val = 20;
 cmd_control = (cmd_control & ~0x1f) | (val << 0);
}

canonical_original_code:
void inc_trimmer()
{
 int val = get_trimmer() + 1;
 if ( val > 20 )
  val = 20;
 cmd_control = (cmd_control & ~0x1f) | (val << 0);
}


decompiled_code:
ssize_t __fastcall send_cmd_packet(int fd)
{
unsigned __int64 v2; // rax
char v3; // dl
char v4; // cl

if ( cmd_packet[5]++ == -1 )
++cmd_packet[4];
sprintf((char *)(unsigned int)((_DWORD)cmd_packet + 11), "%08x", cmd_control);
v2 = (unsigned int)((_DWORD)cmd_packet + 1);
v3 = 0;
do
{
v4 = *(_BYTE *)v2++;
v3 += v4;
}
while ( (char *)v2 != &cmd_packet[18] );
cmd_packet[19] = -v3;
return write(fd, cmd_packet, 0x14uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func9(int fd)
{
unsigned __int64 v2; // rax
char v3; // dl
char v4; // cl

if ( cmd_packet[5]++ == -1 )
++cmd_packet[4];
sprintf((char *)(unsigned int)((_DWORD)cmd_packet + 11), "%08x", cmd_control);
v2 = (unsigned int)((_DWORD)cmd_packet + 1);
v3 = 0;
do
{
v4 = *(_BYTE *)v2++;
v3 += v4;
}
while ( (char *)v2 != &cmd_packet[18] );
cmd_packet[19] = -v3;
return write(fd, cmd_packet, 0x14uLL);
}

original_code:
int send_cmd_packet(int socket)
{
 int i;
 int csum;
 cmd_packet[5]++;
 if (!cmd_packet[5]) cmd_packet[4]++;
 sprintf(&cmd_packet[11], "%08x", cmd_control);
 csum = 0;
 for (i = 1; i < 20 - 2; i++)
  csum += cmd_packet[i];
 cmd_packet[20 - 1] = (0x100 - csum) & 0xff;
 return write(socket, cmd_packet, 20);
}

variable_types: socket int

variable_types: i int

variable_types: csum int


decompiled_code:
int set_sigint_handler()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)finalize;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
return sigaction(2, &v1, 0LL);
}

canonical_decompiled_code:
int func10()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)finalize;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
return sigaction(2, &v1, 0LL);
}

original_code:
void set_sigint_handler(void)
{
 struct sigaction sigIntHandler;
 sigIntHandler.__sigaction_handler.sa_handler = finalize;
 sigemptyset(&sigIntHandler.sa_mask);
 sigIntHandler.sa_flags = 0;
 sigaction(2, &sigIntHandler, ((void *)0));
}

canonical_original_code:
void set_sigint_handler()
{
 struct sigaction sigIntHandler;
 sigIntHandler.__sigaction_handler.sa_handler = finalize;
 sigemptyset(&sigIntHandler.sa_mask);
 sigIntHandler.sa_flags = 0;
 sigaction(2, &sigIntHandler, ((void *)0));
}

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

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

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


decompiled_code:
__int64 heli_connect()
{
int v0; // eax
unsigned int v1; // er12
char addr[26]; // [rsp+6h] [rbp-32h] BYREF
__int16 v4; // [rsp+20h] [rbp-18h]

*(_WORD *)&addr[8] = 0;
*(_QWORD *)addr = 0LL;
v4 = 101;
*(__m128i *)&addr[10] = _mm_load_si128((const __m128i *)&LC5);
v0 = socket(31, 1, 3);
if ( v0 < 0 )
{
perror("Opening RFCOMM socket");
exit(1);
}
v1 = v0;
addr[8] = 3;
*(_WORD *)addr = 31;
str2ba(&addr[10], &addr[2]);
if ( connect(v1, (const struct sockaddr *)addr, 0xAu) < 0 )
{
perror("Connect failed");
close(v1);
exit(1);
}
puts("Connect success!");
if ( (int)heli_init_aap(v1) < 0 )
{
close(v1);
exit(1);
}
return v1;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // eax
unsigned int v1; // er12
char addr[26]; // [rsp+6h] [rbp-32h] BYREF
__int16 v4; // [rsp+20h] [rbp-18h]

*(_WORD *)&addr[8] = 0;
*(_QWORD *)addr = 0LL;
v4 = 101;
*(__m128i *)&addr[10] = _mm_load_si128((const __m128i *)&LC5);
v0 = socket(31, 1, 3);
if ( v0 < 0 )
{
perror("Opening RFCOMM socket");
exit(1);
}
v1 = v0;
addr[8] = 3;
*(_WORD *)addr = 31;
str2ba(&addr[10], &addr[2]);
if ( connect(v1, (const struct sockaddr *)addr, 0xAu) < 0 )
{
perror("Connect failed");
close(v1);
exit(1);
}
puts("Connect success!");
if ( (int)heli_init_aap(v1) < 0 )
{
close(v1);
exit(1);
}
return v1;
}

original_code:
int heli_connect(void)
{
 struct sockaddr_rc addr = { 0 };
 int status;
 char dest[18] = "00:11:67:e5:b9:3e";
 char buf[1024] = {0};
 int bytes_read;
 unsigned char i = 0;
 int heli_socket;
 heli_socket = socket(31, SOCK_STREAM, 3);
 if (heli_socket < 0) {
  perror("Opening RFCOMM socket");
  exit (1);
 }
 addr.rc_family = 31;
 addr.rc_channel = (uint8_t) 3;
 str2ba( dest, &addr.rc_bdaddr );
 status = connect(heli_socket, (struct sockaddr *)&addr, sizeof(addr));
 if (status < 0) {
  perror("Connect failed");
  close(heli_socket);
  exit (1);
 }
 printf("Connect success!\n");
 status = heli_init_aap(heli_socket);
 if (status < 0) {
  close(heli_socket);
  exit (1);
 }
 return heli_socket;
}

canonical_original_code:
int heli_connect()
{
 struct sockaddr_rc addr = { 0 };
 int status;
 char dest[18] = "00:11:67:e5:b9:3e";
 char buf[1024] = {0};
 int bytes_read;
 unsigned char i = 0;
 int heli_socket;
 heli_socket = socket(31, SOCK_STREAM, 3);
 if (heli_socket < 0) {
  perror("Opening RFCOMM socket");
  exit (1);
 }
 addr.rc_family = 31;
 addr.rc_channel = (unsigned char) 3;
 str2ba( dest, &addr.rc_bdaddr );
 status = connect(heli_socket, (struct sockaddr *)&addr, sizeof(addr));
 if (status < 0) {
  perror("Connect failed");
  close(heli_socket);
  exit (1);
 }
 printf("Connect success!\n");
 status = heli_init_aap(heli_socket);
 if (status < 0) {
  close(heli_socket);
  exit (1);
 }
 return heli_socket;
}

variable_types: struct sockaddr_rc { unsigned short rc_family; struct bdaddr_t { unsigned char b[6]; } rc_bdaddr; unsigned char rc_channel; }

variable_types:
dest
char [18]

variable_types:
buf
char [1024]

variable_types:
i
unsigned char

user_defined_types: struct sockaddr_rc { unsigned short rc_family; struct bdaddr_t rc_bdaddr; unsigned char rc_channel; }

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


threadfunc

decompiled_code:
void __fastcall __noreturn threadfunc(void *a1)
{
int v1; // ebx

v1 = (int)a1;
while ( 1 )
{
if ( (int)send_cmd_packet(v1) < 0 )
{
perror("Send");
puts("Trying to reconnect...");
cmd_control = 8355594LL;
*(_WORD *)&cmd_packet[4] = 0;
v1 = heli_connect();
}
usleep(0x186A0u);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func12(void *a1)
{
int v1; // ebx

v1 = (int)a1;
while ( 1 )
{
if ( (int)func9(v1) < 0 )
{
perror("Send");
puts("Trying to reconnect...");
cmd_control = 8355594LL;
*(_WORD *)&cmd_packet[4] = 0;
v1 = func11();
}
usleep(0x186A0u);
}
}

original_code:
void *threadfunc(void *parm)
{
 int socket = (int)parm;
 int status;
 char buf[1024];
 while (1) {
  status = send_cmd_packet(socket);
  if (status < 0) {
   perror("Send");
   printf("Trying to reconnect...\n");
   cmd_packet[5] = 0;
   cmd_packet[4] = 0;
   cmd_control = 0x007f7f0a;
   socket = heli_connect();
  }
  usleep(100000);
 }
}

variable_types:
parm
void *

return_type: void *


decompiled_code:
__int64 start_heli_control_thread()
{
int v0; // eax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v0 = heli_connect();
pthread_create(newthread, 0LL, (void *(*)(void *))threadfunc, (void *)v0);
set_sigint_handler();
return 0LL;
}

canonical_decompiled_code:
__int64 func13()
{
int v0; // eax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v0 = func11();
pthread_create(newthread, 0LL, (void *(*)(void *))threadfunc, (void *)v0);
func10();
return 0LL;
}

original_code:
int start_heli_control_thread(void)
{
 int heli_socket;
 pthread_t thread;
 heli_socket = heli_connect();
 pthread_create(&thread, ((void *)0), threadfunc, (void *)heli_socket);
 set_sigint_handler();
 return 0;
}

canonical_original_code:
int start_heli_control_thread()
{
 int heli_socket;
 unsigned long thread;
 heli_socket = heli_connect();
 pthread_create(&thread, ((void *)0), threadfunc, (void *)heli_socket);
 set_sigint_handler();
 return 0;
}

variable_types:
thread
unsigned long


decompiled_code:
int __fastcall dump_packet(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rbx
int v5; // er14
int result; // eax

putchar(123);
if ( a2 <= 0 )
goto LABEL_11;
v4 = 0LL;
v5 = 0;
while ( 1 )
{
printf(" 0x%02x", *(unsigned __int8 *)(a1 + v4));
if ( a3 )
{
if ( *(_BYTE *)(a3 + v4) != *(_BYTE *)(a1 + v4) )
v5 = 1;
}
if ( a2 == ++v4 )
break;
putchar(44);
}
if ( v5 )
result = puts(" }},\n\n (DIFFER!!!!!!!!!!!!!)\n");
else
LABEL_11:
result = puts(" }},");
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rbx
int v5; // er14
int result; // eax

putchar(123);
if ( a2 <= 0 )
goto LABEL_11;
v4 = 0LL;
v5 = 0;
while ( 1 )
{
printf(" 0x%02x", *(unsigned __int8 *)(a1 + v4));
if ( a3 )
{
if ( *(_BYTE *)(a3 + v4) != *(_BYTE *)(a1 + v4) )
v5 = 1;
}
if ( a2 == ++v4 )
break;
putchar(44);
}
if ( v5 )
result = puts(" }},\n\n (DIFFER!!!!!!!!!!!!!)\n");
else
LABEL_11:
result = puts(" }},");
return result;
}

original_code:
void dump_packet(char *data, int len, char *compare)
{
 int i;
 int differ = 0;
 printf("{");
 for (i = 0; i < len; i++) {
  if (i) printf(",");
  printf(" 0x%02x", ((int)data[i]) & 0xff);
  if (compare && compare[i] != data[i])
   differ = 1;
 }
 if (differ)
  printf(" }},\n\n               (DIFFER!!!!!!!!!!!!!)\n\n");
 else
  printf(" }},\n");
}

variable_types:
data
char *

variable_types: len int

variable_types:
compare
char *

variable_types: differ int


decompiled_code:
__int64 __fastcall heli_init_aap(int fd)
{
const void **v1; // rbx
__int64 v3; // [rsp+0h] [rbp-418h] BYREF

v1 = (const void **)&cmds;
while ( 1 )
{
if ( *(_DWORD *)v1 )
{
if ( (int)read(fd, &v3, 0x400uLL) < 0 )
{
perror("Receive");
return 0xFFFFFFFFLL;
}
goto LABEL_3;
}
if ( (int)write(fd, v1[1], *((int *)v1 + 1)) < 0 )
break;
LABEL_3:
v1 += 2;
if ( v1 == (const void **)((char *)&cmds + 576) )
return 0LL;
}
perror("Send");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd)
{
const void **v1; // rbx
__int64 v3; // [rsp+0h] [rbp-418h] BYREF

v1 = (const void **)&cmds;
while ( 1 )
{
if ( *(_DWORD *)v1 )
{
if ( (int)read(fd, &v3, 0x400uLL) < 0 )
{
perror("Receive");
return 0xFFFFFFFFLL;
}
goto LABEL_3;
}
if ( (int)write(fd, v1[1], *((int *)v1 + 1)) < 0 )
break;
LABEL_3:
v1 += 2;
if ( v1 == (const void **)((char *)&cmds + 576) )
return 0LL;
}
perror("Send");
return 0xFFFFFFFFLL;
}

original_code:
int heli_init_aap(int socket)
{
 int i;
 struct cmd_t *cmd;
 int status;
 char buf[1024];
 for (i = 0; i < sizeof(cmds)/sizeof(struct cmd_t); i++)
 {
  cmd = &cmds[i];
  if (cmd->dir == PHONE_TO_HELI) {
   status = write(socket, cmd->data, cmd->len);
   if (status < 0) {
    perror("Send");
    return -1;
   }
  } else {
   status = read(socket, buf, sizeof(buf));
   if (status < 0)
   {
    perror("Receive");
    return -1;
   }
  }
 }
 return 0;
}

variable_types: struct cmd_t { enum direction { PHONE_TO_HELI=0, HELI_TO_PHONE=1 } dir; int len; char *data; } *

variable_types: status int

user_defined_types: struct cmd_t { enum direction dir; int len; char *data; }


main

repo: YuuKohaku/diffie-hellman

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
clock_t v3; // r12
clock_t v4; // rbp
double v5; // xmm0_8
FILE *v6; // rdi

init_numbers(argc, argv, envp);
urand = fopen("/dev/urandom", "r");
if ( !urand )
{
fwrite("Failed to init randomization\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
v3 = clock();
init_prime(0x40uLL);
generate_key(64LL, &private_key_1);
generate_key(64LL, &private_key_2);
__gmpz_powm();
__gmpz_powm();
v4 = clock();
__gmp_printf();
v5 = difftime(v4, v3);
printf("Done in %.2f seconds\n", v5 / 1000000.0);
v6 = urand;
fclose(urand);
clear_numbers(v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
clock_t v3; // r12
clock_t v4; // rbp
double v5; // xmm0_8
FILE *v6; // rdi

func10(argc, argv, envp);
urand = fopen("/dev/urandom", "r");
if ( !urand )
{
fwrite("Failed to init randomization\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
v3 = clock();
func9(0x40uLL);
func8(64LL, &private_key_1);
func8(64LL, &private_key_2);
__gmpz_powm();
__gmpz_powm();
v4 = clock();
__gmp_printf();
v5 = difftime(v4, v3);
printf("Done in %.2f seconds\n", v5 / 1000000.0);
v6 = urand;
fclose(urand);
func11(v6);
return 0;
}

original_code:
int main(void)
{
    clock_t start, end;
    init_numbers();
    urand = fopen("/dev/urandom","r");
    if(((void *)0) == urand)
    {
        fprintf(stderr, "Failed to init randomization\n");
        exit(1);
    }
    start = clock();
    init_prime(64);
    generate_key(64, private_key_1);
    generate_key(64, private_key_2);
    __gmpz_powm(public_key, base, private_key_1, prime);
    __gmpz_powm(key, public_key, private_key_2, prime);
    end = clock();
    __gmp_printf ("Prime: %Zd\nBase: %Zd\nPrivate key a: %Zd\nPrivate key b: %Zd\nPublic key A: %Zd\nSecret key: %Zd\n", prime,base,private_key_1, private_key_2, public_key, key);
    printf("Done in %.2f seconds\n", difftime(end, start)/((__clock_t) 1000000));
    fclose(urand);
    clear_numbers();
    return 0;
}

canonical_original_code:
int main()
{
    long start; long end;
    init_numbers();
    urand = fopen("/dev/urandom","r");
    if(((void *)0) == urand)
    {
        fprintf(stderr, "Failed to init randomization\n");
        exit(1);
    }
    start = clock();
    init_prime(64);
    generate_key(64, private_key_1);
    generate_key(64, private_key_2);
    __gmpz_powm(public_key, base, private_key_1, prime);
    __gmpz_powm(key, public_key, private_key_2, prime);
    end = clock();
    __gmp_printf ("Prime: %Zd\nBase: %Zd\nPrivate key a: %Zd\nPrivate key b: %Zd\nPublic key A: %Zd\nSecret key: %Zd\n", prime,base,private_key_1, private_key_2, public_key, key);
    printf("Done in %.2f seconds\n", difftime(end, start)/((long) 1000000));
    fclose(urand);
    clear_numbers();
    return 0;
}

variable_types: start long

variable_types: end long


decompiled_code:
int __fastcall generate_random(unsigned __int64 a1, __int64 a2)
{
int v3; // ebx
int v4; // eax
int v5; // edi
unsigned __int64 v6; // rbx
int result; // eax

if ( !a1 || !a2 )
{
fwrite("Wrong params for generate_random()\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
v3 = fgetc(urand);
v4 = fgetc(urand);
v5 = v3 << 8;
v6 = 0LL;
srand(v4 | v5);
do
{
result = rand();
*(_BYTE *)(a2 + v6++) = result;
}
while ( a1 > v6 );
return result;
}

canonical_decompiled_code:
int __fastcall func7(unsigned __int64 a1, __int64 a2)
{
int v3; // ebx
int v4; // eax
int v5; // edi
unsigned __int64 v6; // rbx
int result; // eax

if ( !a1 || !a2 )
{
fwrite("Wrong params for generate_random()\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
v3 = fgetc(urand);
v4 = fgetc(urand);
v5 = v3 << 8;
v6 = 0LL;
srand(v4 | v5);
do
{
result = rand();
*(_BYTE *)(a2 + v6++) = result;
}
while ( a1 > v6 );
return result;
}

original_code:
void generate_random(size_t sz, unsigned char* random_bytes)
{
    unsigned int init_random = 0;
    size_t i = 0;
    if(0 == sz || ((void *)0) == random_bytes)
    {
        fprintf(stderr, "Wrong params for generate_random()\n");
        exit(1);
    }
    init_random ^= ((unsigned int)fgetc(urand) << 8)|fgetc(urand);
    srand(init_random);
    for(i = 0; i < sz; i++)
    {
        random_bytes[i] = rand();
    }
}

canonical_original_code:
void generate_random(unsigned long sz, unsigned char *random_bytes)
{
    unsigned int init_random = 0;
    unsigned long i = 0;
    if(0 == sz || ((void *)0) == random_bytes)
    {
        fprintf(stderr, "Wrong params for generate_random()\n");
        exit(1);
    }
    init_random ^= ((unsigned int)fgetc(urand) << 8)|fgetc(urand);
    srand(init_random);
    for(i = 0; i < sz; i++)
    {
        random_bytes[i] = rand();
    }
}

variable_types:
sz
unsigned long

variable_types:
i
unsigned long


decompiled_code:
void __fastcall generate_key(size_t a1, __int64 a2)
{
void *v2; // rax
void *v3; // rbp

if ( !a1 || !a2 )
{
fwrite("Wrong params for generate_key()\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
v2 = malloc(a1);
v3 = v2;
if ( !v2 )
{
fwrite("Failed to allocate random bytes array for the private key\n", 1uLL, 0x3AuLL, stderr);
exit(1);
}
generate_random(a1, (__int64)v2);
__gmpz_import();
free(v3);
}

canonical_decompiled_code:
void __fastcall func8(size_t a1, __int64 a2)
{
void *v2; // rax
void *v3; // rbp

if ( !a1 || !a2 )
{
fwrite("Wrong params for generate_key()\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
v2 = malloc(a1);
v3 = v2;
if ( !v2 )
{
fwrite("Failed to allocate random bytes array for the private key\n", 1uLL, 0x3AuLL, stderr);
exit(1);
}
func7(a1, (__int64)v2);
__gmpz_import();
free(v3);
}

original_code:
void generate_key(size_t sz, mpz_t result)
{
    unsigned char* random_bytes = ((void *)0);
    if(0 == sz || ((void *)0) == result)
    {
        fprintf(stderr, "Wrong params for generate_key()\n");
        exit(1);
    }
    random_bytes = (unsigned char *)malloc(sz*sizeof(unsigned char));
    if(((void *)0) == random_bytes)
    {
        fprintf(stderr, "Failed to allocate random bytes array for the private key\n");
        exit(1);
    }
    generate_random(sz, random_bytes);
    __gmpz_import(result, 1, -1, sz, -1, 0, (const void*)random_bytes);
    free(random_bytes);
}

canonical_original_code:
void generate_key(unsigned long sz, struct __mpz_struct result[1])
{
    unsigned char *random_bytes = ((void *)0);
    if(0 == sz || ((void *)0) == result)
    {
        fprintf(stderr, "Wrong params for generate_key()\n");
        exit(1);
    }
    random_bytes = (unsigned char *)malloc(sz*sizeof(unsigned char));
    if(((void *)0) == random_bytes)
    {
        fprintf(stderr, "Failed to allocate random bytes array for the private key\n");
        exit(1);
    }
    generate_random(sz, random_bytes);
    __gmpz_import(result, 1, -1, sz, -1, 0, (void *)random_bytes);
    free(random_bytes);
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]


decompiled_code:
__int64 __fastcall init_prime(size_t size)
{
_BYTE *v1; // rax
_BYTE *v2; // rbp
_BYTE *v3; // r12

if ( !size )
{
fwrite("Wrong params for init_prime()\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
__gmpz_init();
__gmpz_init();
v1 = malloc(size);
v2 = v1;
if ( !v1 )
{
fwrite("Failed to allocate random bytes array for the prime number\n", 1uLL, 0x3BuLL, stderr);
exit(1);
}
v3 = &v1[size - 1];
do
{
generate_random(size, (__int64)v2);
*v3 |= 0x40u;
*v2 |= 1u;
__gmpz_import();
while ( !(unsigned int)__gmpz_probab_prime_p() )
__gmpz_add_ui();
__gmpz_mul_ui();
__gmpz_add_ui();
}
while ( !(unsigned int)__gmpz_probab_prime_p() );
free(v2);
__gmpz_set_ui();
__gmpz_clear();
return __gmpz_clear();
}

canonical_decompiled_code:
__int64 __fastcall func9(size_t size)
{
_BYTE *v1; // rax
_BYTE *v2; // rbp
_BYTE *v3; // r12

if ( !size )
{
fwrite("Wrong params for init_prime()\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
__gmpz_init();
__gmpz_init();
v1 = malloc(size);
v2 = v1;
if ( !v1 )
{
fwrite("Failed to allocate random bytes array for the prime number\n", 1uLL, 0x3BuLL, stderr);
exit(1);
}
v3 = &v1[size - 1];
do
{
func7(size, (__int64)v2);
*v3 |= 0x40u;
*v2 |= 1u;
__gmpz_import();
while ( !(unsigned int)__gmpz_probab_prime_p() )
__gmpz_add_ui();
__gmpz_mul_ui();
__gmpz_add_ui();
}
while ( !(unsigned int)__gmpz_probab_prime_p() );
free(v2);
__gmpz_set_ui();
__gmpz_clear();
return __gmpz_clear();
}

original_code:
void init_prime(size_t sz)
{
    mpz_t tmp;
    mpz_t x;
    unsigned char* random_bytes = ((void *)0);
    if(0 == sz)
    {
        fprintf(stderr, "Wrong params for init_prime()\n");
        exit(1);
    }
    __gmpz_init(tmp);
    __gmpz_init(x);
    random_bytes = (unsigned char *)malloc(sz*sizeof(unsigned char));
    if(((void *)0) == random_bytes)
    {
        fprintf(stderr, "Failed to allocate random bytes array for the prime number\n");
        exit(1);
    }
    while (1)
    {
        generate_random(sz, random_bytes);
        random_bytes[sz-1] |= (unsigned char)0x40;
        random_bytes[0] |= (unsigned char)1;
        __gmpz_import(tmp, 1, -1, sz, -1, 0, (const void*)random_bytes);
        while (0 == __gmpz_probab_prime_p(tmp, 10))
        {
            __gmpz_add_ui(tmp, tmp, 2);
        }
        __gmpz_mul_ui(prime, tmp, 2);
        __gmpz_add_ui(prime, prime, 1);
        if (0 != __gmpz_probab_prime_p(prime, 10))
        {
            break;
        }
    }
    free(random_bytes);
    __gmpz_set_ui(base, (unsigned long)2);
    __gmpz_clear(tmp);
    __gmpz_clear(x);
}

canonical_original_code:
void init_prime(unsigned long sz)
{
    struct __mpz_struct tmp[1];
    struct __mpz_struct x[1];
    unsigned char *random_bytes = ((void *)0);
    if(0 == sz)
    {
        fprintf(stderr, "Wrong params for init_prime()\n");
        exit(1);
    }
    __gmpz_init(tmp);
    __gmpz_init(x);
    random_bytes = (unsigned char *)malloc(sz*sizeof(unsigned char));
    if(((void *)0) == random_bytes)
    {
        fprintf(stderr, "Failed to allocate random bytes array for the prime number\n");
        exit(1);
    }
    while (1)
    {
        generate_random(sz, random_bytes);
        random_bytes[sz-1] |= (unsigned char)0x40;
        random_bytes[0] |= (unsigned char)1;
        __gmpz_import(tmp, 1, -1, sz, -1, 0, (void *)random_bytes);
        while (0 == __gmpz_probab_prime_p(tmp, 10))
        {
            __gmpz_add_ui(tmp, tmp, 2);
        }
        __gmpz_mul_ui(prime, tmp, 2);
        __gmpz_add_ui(prime, prime, 1);
        if (0 != __gmpz_probab_prime_p(prime, 10))
        {
            break;
        }
    }
    free(random_bytes);
    __gmpz_set_ui(base, (unsigned long)2);
    __gmpz_clear(tmp);
    __gmpz_clear(x);
}

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }


decompiled_code:
__int64 init_numbers()
{
__gmpz_init();
__gmpz_init();
__gmpz_init();
__gmpz_init();
__gmpz_init();
return __gmpz_init();
}

canonical_decompiled_code:
__int64 func10()
{
__gmpz_init();
__gmpz_init();
__gmpz_init();
__gmpz_init();
__gmpz_init();
return __gmpz_init();
}

original_code:
void init_numbers(void)
{
    __gmpz_init(key);
    __gmpz_init(prime);
    __gmpz_init(base);
    __gmpz_init(private_key_1);
    __gmpz_init(private_key_2);
    __gmpz_init(public_key);
}

canonical_original_code:
void init_numbers()
{
    __gmpz_init(key);
    __gmpz_init(prime);
    __gmpz_init(base);
    __gmpz_init(private_key_1);
    __gmpz_init(private_key_2);
    __gmpz_init(public_key);
}


decompiled_code:
__int64 clear_numbers()
{
__gmpz_clear();
__gmpz_clear();
__gmpz_clear();
__gmpz_clear();
__gmpz_clear();
return __gmpz_init();
}

canonical_decompiled_code:
__int64 func11()
{
__gmpz_clear();
__gmpz_clear();
__gmpz_clear();
__gmpz_clear();
__gmpz_clear();
return __gmpz_init();
}

original_code:
void clear_numbers(void)
{
    __gmpz_clear(key);
    __gmpz_clear(prime);
    __gmpz_clear(base);
    __gmpz_clear(private_key_1);
    __gmpz_clear(private_key_2);
    __gmpz_init(public_key);
}

canonical_original_code:
void clear_numbers()
{
    __gmpz_clear(key);
    __gmpz_clear(prime);
    __gmpz_clear(base);
    __gmpz_clear(private_key_1);
    __gmpz_clear(private_key_2);
    __gmpz_init(public_key);
}


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

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_usec + 1000000000 * v1.tv_sec;
}

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

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_usec + 1000000000 * v1.tv_sec;
}

original_code:
uinteger64 prp_time(void)
{
    uinteger64 time;
    struct timeval temp_time;
    gettimeofday(&temp_time, ((void *)0));
    time = ((uinteger64)temp_time.tv_sec * 1000000000) +
            ((uinteger64)temp_time.tv_usec * 1000);
    return(time);
}

canonical_original_code:
unsigned long long prp_time()
{
    unsigned long long time;
    struct timeval temp_time;
    gettimeofday(&temp_time, ((void *)0));
    time = ((unsigned long long)temp_time.tv_sec * 1000000000) +
            ((unsigned long long)temp_time.tv_usec * 1000);
    return(time);
}

variable_types:
time
unsigned long long

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

return_type: unsigned long long


decompiled_code:
int prp_printf(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(buffer_0, 0x100uLL, format, arg);
return printf("%s", buffer_0);
}

canonical_decompiled_code:
int func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(buffer_0, 0x100uLL, format, arg);
return printf("%s", buffer_0);
}

original_code:
int prp_printf(const char *format, ...)
{
    static char buffer[256];
    va_list args;
    __builtin_va_start(args,format);
    vsnprintf(buffer, sizeof(buffer), (const char*)format, args);
    __builtin_va_end(args);
    return printf("%s",buffer);
}

canonical_original_code:
int prp_printf(char *format, ...)
{
    static char buffer[256];
    __builtin_va_list args;
    __builtin_va_start(args,format);
    vsnprintf(buffer, sizeof(buffer), (char *)format, args);
    __builtin_va_end(args);
    return printf("%s",buffer);
}

variable_types:
format
char *

variable_types:
buffer
char [256]


decompiled_code:
void *__fastcall prp_malloc(size_t size)
{
return malloc((unsigned int)size);
}

canonical_decompiled_code:
void *__fastcall func2(size_t size)
{
return malloc((unsigned int)size);
}

original_code:
void* prp_malloc(uinteger32 size)
{
    return malloc(size);
}

canonical_original_code:
void *prp_malloc(unsigned int size)
{
    return malloc(size);
}

variable_types:
size
unsigned int


decompiled_code:
// attributes: thunk
void prp_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func3(void *ptr)
{
free(ptr);
}

original_code:
void prp_free(void* ptr)
{
    free(ptr);
}

canonical_original_code:
void prp_free(void *ptr)
{
    free(ptr);
}

variable_types:
ptr
void *


decompiled_code:
void *__fastcall prp_memcpy(void *a1, const void *a2, unsigned int a3)
{
return memcpy(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func4(void *a1, const void *a2, unsigned int a3)
{
return memcpy(a1, a2, a3);
}

original_code:
void prp_memcpy(void *dest_ptr, const void *src_ptr, uinteger32 size)
{
    memcpy(dest_ptr, src_ptr, size);
}

canonical_original_code:
void prp_memcpy(void *dest_ptr, void *src_ptr, unsigned int size)
{
    memcpy(dest_ptr, src_ptr, size);
}


decompiled_code:
int __fastcall prp_memcmp(const void *a1, const void *a2, unsigned int a3)
{
return memcmp(a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func5(const void *a1, const void *a2, unsigned int a3)
{
return memcmp(a1, a2, a3);
}

original_code:
integer32 prp_memcmp( const void *left_ptr, const void *right_ptr, uinteger32 size)
{
    return memcmp(left_ptr, right_ptr, size);
}

canonical_original_code:
int prp_memcmp(void *left_ptr, void *right_ptr, unsigned int size)
{
    return memcmp(left_ptr, right_ptr, size);
}


decompiled_code:
void *__fastcall prp_memset(void *a1, unsigned __int8 a2, unsigned int a3)
{
return memset(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func6(void *a1, unsigned __int8 a2, unsigned int a3)
{
return memset(a1, a2, a3);
}

original_code:
void prp_memset(void *ptr, octet set, uinteger32 size)
{
    memset(ptr, set, size);
}

canonical_original_code:
void prp_memset(void *ptr, unsigned char set, unsigned int size)
{
    memset(ptr, set, size);
}

variable_types:
set
unsigned char


decompiled_code:
__int64 create_lock()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 1LL;
}

original_code: void* create_lock(void) { return (void *) 1; }

canonical_original_code: void *create_lock() { return (void *) 1; }


decompiled_code:
void destroy_lock()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code: void destroy_lock(void* lock) { }

canonical_original_code: void destroy_lock(void *lock) { }

variable_types:
lock
void *


decompiled_code:
void lock_down()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code: void lock_down(void* lock) { }

canonical_original_code: void lock_down(void *lock) { }


decompiled_code:
void lock_up()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code: void lock_up(void* lock) { }

canonical_original_code: void lock_up(void *lock) { }


repo: ZackMason/rougelike

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
_QWORD *v4; // rax
_QWORD *v5; // rbx
_QWORD *v6; // rax
_QWORD *v7; // rbp
void *v8; // rax
void *v9; // rax
_QWORD *v10; // rax
_QWORD *v11; // rbp
void *v12; // rax

v3 = time(0LL);
srand(v3);
v4 = calloc(0x20uLL, 1uLL);
if ( !v4 )
{
fwrite("could not alloc game\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
v5 = v4;
v6 = malloc(0x10uLL);
v5[2] = v6;
v7 = v6;
if ( !v6 )
{
fwrite("could not alloc map\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
*v6 = 0x3200000096LL;
v8 = calloc(0x1D4CuLL, 1uLL);
v7[1] = v8;
if ( !v8 )
{
fwrite("could not alloc map data\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v9 = calloc(0xCuLL, 1uLL);
v5[1] = v9;
if ( !v9 )
{
fwrite("could not alloc player\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v10 = malloc(0x10uLL);
v5[3] = v10;
v11 = v10;
if ( !v10 )
{
fwrite("could not alloc old map\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
*v10 = 0x3200000096LL;
v12 = calloc(0x1D4CuLL, 1uLL);
v11[1] = v12;
if ( !v12 )
{
fwrite("could not alloc old map data\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
startup(v5);
while ( *(_DWORD *)v5 == 1 )
{
updateScreen(v5);
processInput(v5);
}
endwin();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
_QWORD *v4; // rax
_QWORD *v5; // rbx
_QWORD *v6; // rax
_QWORD *v7; // rbp
void *v8; // rax
void *v9; // rax
_QWORD *v10; // rax
_QWORD *v11; // rbp
void *v12; // rax

v3 = time(0LL);
srand(v3);
v4 = calloc(0x20uLL, 1uLL);
if ( !v4 )
{
fwrite("could not alloc game\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
v5 = v4;
v6 = malloc(0x10uLL);
v5[2] = v6;
v7 = v6;
if ( !v6 )
{
fwrite("could not alloc map\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
*v6 = 0x3200000096LL;
v8 = calloc(0x1D4CuLL, 1uLL);
v7[1] = v8;
if ( !v8 )
{
fwrite("could not alloc map data\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v9 = calloc(0xCuLL, 1uLL);
v5[1] = v9;
if ( !v9 )
{
fwrite("could not alloc player\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
v10 = malloc(0x10uLL);
v5[3] = v10;
v11 = v10;
if ( !v10 )
{
fwrite("could not alloc old map\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
*v10 = 0x3200000096LL;
v12 = calloc(0x1D4CuLL, 1uLL);
v11[1] = v12;
if ( !v12 )
{
fwrite("could not alloc old map data\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
func17(v5);
while ( *(_DWORD *)v5 == 1 )
{
func15(v5);
func16(v5);
}
endwin();
return 0;
}

original_code:
int main()
{
    int ch;
    game_t *game;
    srand(time(((void *)0)));
    game = malloc(sizeof(game_t));
    if (!game) {
 fprintf(stderr, "could not alloc game\n");
 exit(1);
    }
    memset(game, 0, sizeof(game_t));
    game->map = malloc(sizeof(map_t));
    if (!game->map) {
 fprintf(stderr, "could not alloc map\n");
 exit(1);
    }
    memset(game->map, 0, sizeof(map_t));
    game->map->width = 150;
    game->map->height = 50;
    game->map->data = malloc(game->map->width * game->map->height);
    if (!game->map->data) {
 fprintf(stderr, "could not alloc map data\n");
 exit(1);
    }
    memset(game->map->data, 0, game->map->width * game->map->height);
    game->player = malloc(sizeof(player_t));
    if (!game->player) {
 fprintf(stderr, "could not alloc player\n");
 exit(1);
    }
    memset(game->player, 0, sizeof(player_t));
    game->oldMap = malloc(sizeof(map_t));
    if (!game->oldMap) {
 fprintf(stderr, "could not alloc old map\n");
 exit(1);
    }
    memset(game->oldMap, 0, sizeof(map_t));
    game->oldMap->width = game->map->width;
    game->oldMap->height = game->map->height;
    game->oldMap->data = malloc(game->oldMap->width * game->oldMap->height);
    if (!game->oldMap->data) {
 fprintf(stderr, "could not alloc old map data\n");
 exit(1);
    }
    memset(game->oldMap->data, 0, game->oldMap->width * game->oldMap->height);
    startup(game);
    while (game->running == 1)
    {
 updateScreen(game);
 processInput(game);
    }
    endwin();
    return(0);
}

canonical_original_code:
int main()
{
    int ch;
    struct game_s *game;
    srand(time(((void *)0)));
    game = malloc(sizeof(game_t));
    if (!game) {
 fprintf(stderr, "could not alloc game\n");
 exit(1);
    }
    memset(game, 0, sizeof(game_t));
    game->map = malloc(sizeof(map_t));
    if (!game->map) {
 fprintf(stderr, "could not alloc map\n");
 exit(1);
    }
    memset(game->map, 0, sizeof(map_t));
    game->map->width = 150;
    game->map->height = 50;
    game->map->data = malloc(game->map->width * game->map->height);
    if (!game->map->data) {
 fprintf(stderr, "could not alloc map data\n");
 exit(1);
    }
    memset(game->map->data, 0, game->map->width * game->map->height);
    game->player = malloc(sizeof(player_t));
    if (!game->player) {
 fprintf(stderr, "could not alloc player\n");
 exit(1);
    }
    memset(game->player, 0, sizeof(player_t));
    game->oldMap = malloc(sizeof(map_t));
    if (!game->oldMap) {
 fprintf(stderr, "could not alloc old map\n");
 exit(1);
    }
    memset(game->oldMap, 0, sizeof(map_t));
    game->oldMap->width = game->map->width;
    game->oldMap->height = game->map->height;
    game->oldMap->data = malloc(game->oldMap->width * game->oldMap->height);
    if (!game->oldMap->data) {
 fprintf(stderr, "could not alloc old map data\n");
 exit(1);
    }
    memset(game->oldMap->data, 0, game->oldMap->width * game->oldMap->height);
    startup(game);
    while (game->running == 1)
    {
 updateScreen(game);
 processInput(game);
    }
    endwin();
    return(0);
}

variable_types: ch int

variable_types: struct game_s { int running; struct player_s { char ch; int y; int x; } *player; struct map_s { int width; char *data; } *map; struct map_s *oldMap; } *

user_defined_types: struct game_s { int running; struct player_s *player; struct map_s *map; struct map_s *oldMap; }


setMapTile

decompiled_code:
__int64 __fastcall setMapTile(__int64 a1, int a2, int a3, char a4)
{
__int64 result; // rax

if ( a3 < 0 || *(_DWORD *)a1 <= a3 )
__assert_fail("(x >= 0) && (x < map->width)", "main.c", 0x27u, "setMapTile");
result = *(_QWORD *)(a1 + 8);
*(_BYTE *)(result + a3 + a2 * *(_DWORD *)a1) = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, int a3, char a4)
{
__int64 result; // rax

if ( a3 < 0 || *(_DWORD *)a1 <= a3 )
__assert_fail("(x >= 0) && (x < map->width)", "main.c", 0x27u, "setMapTile");
result = *(_QWORD *)(a1 + 8);
*(_BYTE *)(result + a3 + a2 * *(_DWORD *)a1) = a4;
return result;
}

original_code:
void setMapTile(map_t *map, int y, int x, char ch)
{
    ((void) sizeof (((x >= 0) && (x < map->width)) ? 1 : 0), __extension__ ({ if ((x >= 0) && (x < map->width)) ; else __assert_fail ("(x >= 0) && (x < map->width)", "main.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    map->data[y * map->width + x] = ch;
}

canonical_original_code:
void setMapTile(struct map_s *map, int y, int x, char ch)
{
    ((void) sizeof (((x >= 0) && (x < map->width)) ? 1 : 0), __extension__ ({ if ((x >= 0) && (x < map->width)) ; else __assert_fail ("(x >= 0) && (x < map->width)", "main.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    map->data[y * map->width + x] = ch;
}

variable_types: struct map_s { int width; char *data; } *

variable_types: y int

variable_types: x int

variable_types: ch char


getMapTile

decompiled_code:
__int64 __fastcall getMapTile(__int64 a1, int a2, int a3)
{
return *(unsigned __int8 *)(*(_QWORD *)(a1 + 8) + a3 + *(_DWORD *)a1 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, int a3)
{
return *(unsigned __int8 *)(*(_QWORD *)(a1 + 8) + a3 + *(_DWORD *)a1 * a2);
}

original_code:
char getMapTile(map_t *map, int y, int x)
{
    return map->data[y * map->width + x];
}

canonical_original_code:
char getMapTile(struct map_s *map, int y, int x)
{
    return map->data[y * map->width + x];
}

return_type: char


isWall

decompiled_code:
_BOOL8 __fastcall isWall(__int64 a1, int a2, int a3)
{
return (unsigned __int8)getMapTile(a1, a2, a3) == 35;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1, int a2, int a3)
{
return (unsigned __int8)func8(a1, a2, a3) == 35;
}

original_code:
int isWall(map_t *map, int y, int x)
{
    return getMapTile(map, y, x) == '#';
}

canonical_original_code:
int isWall(struct map_s *map, int y, int x)
{
    return getMapTile(map, y, x) == '#';
}


isDoor

decompiled_code:
_BOOL8 __fastcall isDoor(__int64 a1, int a2, int a3)
{
return (unsigned __int8)getMapTile(a1, a2, a3) == 43;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1, int a2, int a3)
{
return (unsigned __int8)func8(a1, a2, a3) == 43;
}

original_code:
int isDoor(map_t *map, int y, int x)
{
    return getMapTile(map, y, x) == '+';
}

canonical_original_code:
int isDoor(struct map_s *map, int y, int x)
{
    return getMapTile(map, y, x) == '+';
}


caveMap

original_code:
void caveMap(game_t *game) {
    int y, x, n, m;
    int count;
    int i = 100;
    for (y = 0; y < game->map->height; ++y) {
 for (x = 0; x < game->map->width; ++x) {
     char ch = '#';
     int r = rand() % 2;
     if (r == 0) {
  setMapTile(game->oldMap, y, x, ch);
     } else {
  setMapTile(game->oldMap, y, x, '.');
     }
 }
    }
    while(i > 0) {
 for (y = 0; y < game->oldMap->height; ++y) {
     for (x = 0; x < game->oldMap->width; ++x) {
  count = 0;
  for (n = y - 1; n != y + 2; ++n) {
      for (m = x - 1; m != x + 2; ++m) {
   if (getMapTile(game->oldMap, n, m) == '#') {
       ++count;
   }
      }
  }
  if (count > 4) {
      setMapTile(game->map, y, x, '#');
  } else {
      setMapTile(game->map, y, x, '.');
  }
     }
 }
 memcpy(game->oldMap->data, game->map->data,
        game->map->width * game->map->height);
 --i;
    }
}

canonical_original_code:
void caveMap(struct game_s *game) {
    int y; int x; int n; int m;
    int count;
    int i = 100;
    for (y = 0; y < game->map->height; ++y) {
 for (x = 0; x < game->map->width; ++x) {
     char ch = '#';
     int r = rand() % 2;
     if (r == 0) {
  setMapTile(game->oldMap, y, x, ch);
     } else {
  setMapTile(game->oldMap, y, x, '.');
     }
 }
    }
    while(i > 0) {
 for (y = 0; y < game->oldMap->height; ++y) {
     for (x = 0; x < game->oldMap->width; ++x) {
  count = 0;
  for (n = y - 1; n != y + 2; ++n) {
      for (m = x - 1; m != x + 2; ++m) {
   if (getMapTile(game->oldMap, n, m) == '#') {
       ++count;
   }
      }
  }
  if (count > 4) {
      setMapTile(game->map, y, x, '#');
  } else {
      setMapTile(game->map, y, x, '.');
  }
     }
 }
 memcpy(game->oldMap->data, game->map->data,
        game->map->width * game->map->height);
 --i;
    }
}

variable_types: n int

variable_types: m int

variable_types: count int

variable_types: i int

variable_types: r int

user_defined_types: struct player_s { char ch; int y; int x; }


fillMap

original_code:
void fillMap(map_t *map)
{
    int x, y;
    for (y = 0; y < map->height; ++y) {
 for (x = 0; x < map->width; ++x) {
     char ch = '.';
     if ((x == 0) || (x == (map->width - 1))
  || (y == 0) || (y == (map->height - 1))) {
  ch = '#';
     }
     setMapTile(map, y, x, ch);
 }
    }
}

canonical_original_code:
void fillMap(struct map_s *map)
{
    int x; int y;
    for (y = 0; y < map->height; ++y) {
 for (x = 0; x < map->width; ++x) {
     char ch = '.';
     if ((x == 0) || (x == (map->width - 1))
  || (y == 0) || (y == (map->height - 1))) {
  ch = '#';
     }
     setMapTile(map, y, x, ch);
 }
    }
}


splitMap

decompiled_code:
__int64 __fastcall splitMap(int *a1, int a2)
{
int v2; // er13
int v3; // er14
__int64 result; // rax
int v5; // ebp
int v6; // er15
int v7; // er13
int v8; // ebx
int v9; // er15
int v10; // edx
int v11; // ebx
int v12; // [rsp+0h] [rbp-48h]
int v13; // [rsp+4h] [rbp-44h]
int v14; // [rsp+8h] [rbp-40h]
int v15; // [rsp+Ch] [rbp-3Ch]

result = (unsigned int)a1[1];
v5 = *a1;
v15 = a2;
v12 = a1[1];
if ( a2 > 0 )
{
do
{
if ( (v15 & 1) != 0 )
{
if ( v12 > 0 )
{
LODWORD(result) = 0;
v9 = v12 - 1;
v10 = v5 >> 1;
do
{
v11 = 0;
if ( v5 > 0 )
{
do
{
while ( v10 == v11 )
{
v14 = v10;
v13 = result;
setMapTile((__int64)a1, result, v10, 35);
LODWORD(result) = v13;
v10 = v14;
if ( v9 == v13 )
v3 = v11;
if ( ++v11 == v5 )
goto LABEL_25;
}
if ( v9 == (_DWORD)result )
v3 = v11;
++v11;
}
while ( v11 != v5 );
}
LABEL_25:
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v12 );
}
v5 = v3;
}
else
{
result = (unsigned int)v12;
if ( v12 <= 0 )
{
v12 = v2;
}
else
{
v6 = 0;
v7 = v12 >> 1;
do
{
v8 = 0;
if ( v5 > 0 )
{
do
{
while ( v7 != v6 )
{
if ( ++v8 == v5 )
goto LABEL_10;
}
setMapTile((__int64)a1, v7, v8++, 35);
}
while ( v8 != v5 );
}
LABEL_10:
++v6;
}
while ( v6 != v12 );
result = (unsigned int)--v12;
v2 = v12;
}
}
--v15;
}
while ( v15 );
}
return result;
}

original_code:
void splitMap(map_t *map, int iterations)
{
    int x, y, splitX, splitY, lastY, lastX, i;
    char ch = '#';
    i = iterations;
    splitX = map->width;
    splitY = map->height;
    while(i > 0) {
 if (i % 2 == 1) {
     for (y = 0; y < splitY; ++y) {
  for (x = 0; x < splitX; ++x) {
      if(x == splitX/2) {
   setMapTile(map, y, x, ch);
      }
      if (y == splitY - 1) {
   lastX = x;
      }
  }
     }
     splitX = lastX;
 } else {
     for (y = 0; y < splitY; ++y) {
  for (x = 0; x < splitX; ++x) {
      if(y == splitY/2) {
   setMapTile(map, y, x, ch);
      }
  }
  lastY = y;
     }
     splitY = lastY;
 }
 --i;
    }
 }

canonical_original_code:
void splitMap(struct map_s *map, int iterations)
{
    int x; int y; int splitX; int splitY; int lastY; int lastX; int i;
    char ch = '#';
    i = iterations;
    splitX = map->width;
    splitY = map->height;
    while(i > 0) {
 if (i % 2 == 1) {
     for (y = 0; y < splitY; ++y) {
  for (x = 0; x < splitX; ++x) {
      if(x == splitX/2) {
   setMapTile(map, y, x, ch);
      }
      if (y == splitY - 1) {
   lastX = x;
      }
  }
     }
     splitX = lastX;
 } else {
     for (y = 0; y < splitY; ++y) {
  for (x = 0; x < splitX; ++x) {
      if(y == splitY/2) {
   setMapTile(map, y, x, ch);
      }
  }
  lastY = y;
     }
     splitY = lastY;
 }
 --i;
    }
 }

variable_types: iterations int

variable_types: splitX int

variable_types: splitY int

variable_types: lastY int

variable_types: lastX int


drawMap

original_code:
void drawMap(game_t *game)
{
    fillMap(game->map);
    caveMap(game);
    int placed = 0;
    game->player->ch = '@';
    while (placed == 0) {
 int RX = rand() % game->map->width;
 int RY = rand() % game->map->height;
 if (getMapTile(game->map, RY, RX) == '.') {
     setMapTile(game->map, RY, RX, '<');
     game->player->x = RX;
     game->player->y = RY;
     placed = 1;
 }
    }
    placed = 0;
    while (placed == 0) {
 int RX = rand() % game->map->width;
 int RY = rand() % game->map->height;
 if (getMapTile(game->map, RY, RX) == '.') {
     setMapTile(game->map, RY, RX, '>');
     placed = 1;
 }
    }
}

canonical_original_code:
void drawMap(struct game_s *game)
{
    fillMap(game->map);
    caveMap(game);
    int placed = 0;
    game->player->ch = '@';
    while (placed == 0) {
 int RX = rand() % game->map->width;
 int RY = rand() % game->map->height;
 if (getMapTile(game->map, RY, RX) == '.') {
     setMapTile(game->map, RY, RX, '<');
     game->player->x = RX;
     game->player->y = RY;
     placed = 1;
 }
    }
    placed = 0;
    while (placed == 0) {
 int RX = rand() % game->map->width;
 int RY = rand() % game->map->height;
 if (getMapTile(game->map, RY, RX) == '.') {
     setMapTile(game->map, RY, RX, '>');
     placed = 1;
 }
    }
}

variable_types: placed int

variable_types: RX int

variable_types: RY int