decompiled_code:
__int64 __fastcall current_http_date(char *a1, size_t a2)
{
const char *v2; // rdx
__int64 result; // rax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

if ( gettimeofday(&v4, 0LL) < 0 )
{
error((int)"Error getting time of day", 0, v2);
result = 0xFFFFFFFFLL;
}
else
{
format_http_date(&v4.tv_sec, a1, a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, size_t a2)
{
const char *v2; // rdx
__int64 result; // rax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

if ( gettimeofday(&v4, 0LL) < 0 )
{
error((int)"Error getting time of day", 0, v2);
result = 0xFFFFFFFFLL;
}
else
{
func0(&v4.tv_sec, a1, a2);
result = 0LL;
}
return result;
}

original_code:
int current_http_date(char *dst, size_t len) {
    struct timeval tv;
    int res;
    res = gettimeofday(&tv, ((void *)0));
    if (res < 0) {
        error("Error getting time of day");
        return -1;
    }
    format_http_date(&tv.tv_sec, dst, len);
    return 0;
}

canonical_original_code:
int current_http_date(char *dst, unsigned long len) {
    struct timeval tv;
    int res;
    res = gettimeofday(&tv, ((void *)0));
    if (res < 0) {
        error("Error getting time of day");
        return -1;
    }
    format_http_date(&tv.tv_sec, dst, len);
    return 0;
}

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

variable_types: res int


repo: moonranger/breeze

original_code:
int path_starts_with(const char* prefix, const char* path) {
    int match_count;
    if (path == ((void *)0) || prefix == ((void *)0))
        return 0;
    match_count = 0;
    while (*path != '\0' && *prefix != '\0' && *path == *prefix) {
        match_count++;
        path++;
        prefix++;
    }
    if (*prefix == '\0'
        && (*path == '\0' || *path == '/' || *(prefix-1) == '/'))
        return match_count;
    else
        return 0;
}

canonical_original_code:
int path_starts_with(char *prefix, char *path) {
    int match_count;
    if (path == ((void *)0) || prefix == ((void *)0))
        return 0;
    match_count = 0;
    while (*path != '\0' && *prefix != '\0' && *path == *prefix) {
        match_count++;
        path++;
        prefix++;
    }
    if (*prefix == '\0'
        && (*path == '\0' || *path == '/' || *(prefix-1) == '/'))
        return match_count;
    else
        return 0;
}

variable_types:
prefix
char *

variable_types:
path
char *

return_type: int


decompiled_code:
void __fastcall __noreturn stacktrace_handler(int a1)
{
int v1; // ebx
char *v2; // rax
void *v3[33]; // [rsp+0h] [rbp-108h] BYREF

v1 = backtrace(v3, 30);
v2 = strsignal(a1);
logging(3LL, "stacktrace.c", 18LL, "Error captured. Signal: %s", v2);
backtrace_symbols_fd(v3, v1, 2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1)
{
int v1; // ebx
char *v2; // rax
void *v3[33]; // [rsp+0h] [rbp-108h] BYREF

v1 = backtrace(v3, 30);
v2 = strsignal(a1);
logging(3LL, "stacktrace.c", 18LL, "Error captured. Signal: %s", v2);
backtrace_symbols_fd(v3, v1, 2);
exit(1);
}

original_code:
static void stacktrace_handler(int sig) {
    void *trace[30];
    size_t depth;
    depth = backtrace(trace, 30);
    logging(ERROR, "stacktrace.c", 18, "Error captured. Signal: %s", strsignal(sig));
    backtrace_symbols_fd(trace, depth, 2);
    exit(1);
}

canonical_original_code:
static void stacktrace_handler(int sig) {
    void *trace[30];
    unsigned long depth;
    depth = backtrace(trace, 30);
    logging(ERROR, "stacktrace.c", 18, "Error captured. Signal: %s", strsignal(sig));
    backtrace_symbols_fd(trace, depth, 2);
    exit(1);
}

variable_types: sig int

variable_types:
trace
void *[30]

variable_types:
depth
unsigned long

return_type: void


decompiled_code:
__sighandler_t print_stacktrace_on_error()
{
signal(11, (__sighandler_t)stacktrace_handler);
signal(8, (__sighandler_t)stacktrace_handler);
return signal(6, (__sighandler_t)stacktrace_handler);
}

canonical_decompiled_code:
__sighandler_t func1()
{
signal(11, (__sighandler_t)stacktrace_handler);
signal(8, (__sighandler_t)stacktrace_handler);
return signal(6, (__sighandler_t)stacktrace_handler);
}

original_code:
void print_stacktrace_on_error() {
    signal(11, stacktrace_handler);
    signal(8, stacktrace_handler);
    signal(6, stacktrace_handler);
}


vsay

repo: moonsdad/Troll-Raider

decompiled_code:
int vsay(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-120h] BYREF
char s[80]; // [rsp+20h] [rbp-108h] BYREF

va_start(arg, format);
vsnprintf(s, 0x50uLL, format, arg);
return wsay(display_btm, s);
}

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

va_start(arg, format);
vsnprintf(s, 0x50uLL, format, arg);
return func0(display_btm, s);
}

original_code:
void vsay( const char * fmt, ... )
{
    char buf[80];
    va_list valist;
    __builtin_va_start(valist,fmt);
    vsnprintf( buf, 80, fmt, valist );
    __builtin_va_end(valist);
    wsay( display_btm, buf );
}

canonical_original_code:
void vsay(char *fmt, ...)
{
    char buf[80];
    __builtin_va_list valist;
    __builtin_va_start(valist,fmt);
    vsnprintf( buf, 80, fmt, valist );
    __builtin_va_end(valist);
    wsay( display_btm, buf );
}

variable_types:
fmt
char *

variable_types:
buf
char [80]


stricpy

decompiled_code:
unsigned __int64 __fastcall stricpy(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 result; // rax
char v5; // dl

if ( !a2 || !a1 )
_assert_fail("src && dest", "src/rmhv_stdlib.c", 0x33u, "stricpy");
result = 0LL;
if ( !a3 )
return 0LL;
while ( 1 )
{
v5 = *(_BYTE *)(a2 + result);
if ( !v5 )
break;
*(_BYTE *)(a1 + result++) = v5;
if ( a3 == result )
return result;
}
if ( a3 > result )
*(_BYTE *)(a1 + result) = 0;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 result; // rax
char v5; // dl

if ( !a2 || !a1 )
_assert_fail("src && dest", "src/rmhv_stdlib.c", 0x33u, "stricpy");
result = 0LL;
if ( !a3 )
return 0LL;
while ( 1 )
{
v5 = *(_BYTE *)(a2 + result);
if ( !v5 )
break;
*(_BYTE *)(a1 + result++) = v5;
if ( a3 == result )
return result;
}
if ( a3 > result )
*(_BYTE *)(a1 + result) = 0;
return result;
}

original_code:
size_t stricpy( char * dest, const char * src, size_t n )
{
    size_t i;
    ((void) sizeof ((src && dest) ? 1 : 0), __extension__ ({ if (src && dest) ; else __assert_fail ("src && dest", "src/rmhv_stdlib.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    for( i = 0; ( i < n )&&( src[i] != '\0' ); i++ ) dest[i] = src[i];
    if( i < n ) dest[i] = '\0';
    return i;
}

canonical_original_code:
unsigned long stricpy(char *dest, char *src, unsigned long n)
{
    unsigned long i;
    ((void) sizeof ((src && dest) ? 1 : 0), __extension__ ({ if (src && dest) ; else __assert_fail ("src && dest", "src/rmhv_stdlib.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    for( i = 0; ( i < n )&&( src[i] != '\0' ); i++ ) dest[i] = src[i];
    if( i < n ) dest[i] = '\0';
    return i;
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types:
n
unsigned long

variable_types:
i
unsigned long

return_type: unsigned long


mypause

decompiled_code:
int __fastcall mypause(char a1)
{
if ( a1 )
printf("Press [Enter] to continue . . .");
fflush(stdout);
return getchar();
}

canonical_decompiled_code:
int __fastcall func2(char a1)
{
if ( a1 )
printf("Press [Enter] to continue . . .");
fflush(stdout);
return getchar();
}

original_code:
void mypause( _Bool display_prompt )
{
    if( display_prompt ) printf( "Press [Enter] to continue . . ." );
    fflush( stdout );
    getchar();
}

canonical_original_code:
void mypause(_Bool display_prompt)
{
    if( display_prompt ) printf( "Press [Enter] to continue . . ." );
    fflush( stdout );
    getchar();
}


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

if ( !a1 )
_assert_fail("ptr != NULL", "src/item.c", 0x66u, "slot_of");
switch ( *(_WORD *)(a1 + 26) )
{
case 0:
case 2:
case 4:
result = 0LL;
break;
case 1:
case 3:
result = 1LL;
break;
case 5:
result = 3LL;
break;
case 6:
result = 2LL;
break;
default:
result = 4LL;
break;
}
return result;
}

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

if ( !a1 )
_assert_fail("ptr != NULL", "src/item.c", 0x66u, "slot_of");
switch ( *(_WORD *)(a1 + 26) )
{
case 0:
case 2:
case 4:
result = 0LL;
break;
case 1:
case 3:
result = 1LL;
break;
case 5:
result = 3LL;
break;
case 6:
result = 2LL;
break;
default:
result = 4LL;
break;
}
return result;
}

original_code:
int slot_of( const ITEM * ptr )
{
    ((void) sizeof ((ptr != ((void *)0)) ? 1 : 0), __extension__ ({ if (ptr != ((void *)0)) ; else __assert_fail ("ptr != NULL", "src/item.c", 102, __extension__ __PRETTY_FUNCTION__); }));
    switch( ptr->type ) {
        case 0: case 4: case 2: return 0;
        case 1: case 3: return 1;
        case 6: return 2;
        case 5: return 3;
        default: return 4;
    }
}

canonical_original_code:
int slot_of(struct ITEM *ptr)
{
    ((void) sizeof ((ptr != ((void *)0)) ? 1 : 0), __extension__ ({ if (ptr != ((void *)0)) ; else __assert_fail ("ptr != NULL", "src/item.c", 102, __extension__ __PRETTY_FUNCTION__); }));
    switch( ptr->type ) {
        case 0: case 4: case 2: return 0;
        case 1: case 3: return 1;
        case 6: return 2;
        case 5: return 3;
        default: return 4;
    }
}

variable_types: struct ITEM { char name[-1]; int stats[2]; int worth; _Bool is_2handed; unsigned short type; } *


decompiled_code:
bool __fastcall is_equipable(__int64 a1)
{
if ( !a1 )
_assert_fail("itm != NULL", "src/item.c", 0x78u, "is_equipable");
return *(_WORD *)(a1 + 26) <= 6u;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
if ( !a1 )
_assert_fail("itm != NULL", "src/item.c", 0x78u, "is_equipable");
return *(_WORD *)(a1 + 26) <= 6u;
}

original_code:
_Bool is_equipable( ITEM * itm )
{
    ((void) sizeof ((itm != ((void *)0)) ? 1 : 0), __extension__ ({ if (itm != ((void *)0)) ; else __assert_fail ("itm != NULL", "src/item.c", 120, __extension__ __PRETTY_FUNCTION__); }));
    if( itm->type < 7 ) return 1;
    else return 0;
}

canonical_original_code:
_Bool is_equipable(struct ITEM *itm)
{
    ((void) sizeof ((itm != ((void *)0)) ? 1 : 0), __extension__ ({ if (itm != ((void *)0)) ; else __assert_fail ("itm != NULL", "src/item.c", 120, __extension__ __PRETTY_FUNCTION__); }));
    if( itm->type < 7 ) return 1;
    else return 0;
}

user_defined_types: struct ITEM { char name[-1]; int stats[2]; int worth; _Bool is_2handed; unsigned short type; }


roomgen

original_code:
static _Bool roomgen( RECT * room, COORD center )
{
    int dvert = 2 + ( rand() % (4) ),
        dhorz = 2 + ( rand() % (6) );
    room->a.rowy = center.rowy - dvert;
    room->a.colx = center.colx - dhorz;
    room->b.rowy = center.rowy + dvert;
    room->b.colx = center.colx + dhorz;
    if( ( room->a.rowy < 1 )||( room->a.colx < 1 ) ) return 0;
    if( room->b.rowy > ( 20 - 2 ) ) return 0;
    if( room->b.colx > ( 60 - 2 ) ) return 0;
    return 1;
}

canonical_original_code:
static _Bool roomgen(struct RECT *room, struct COORD center)
{
    int dvert = 2 + ( rand() % (4) ); int dhorz = 2 + ( rand() % (6) );
    room->a.rowy = center.rowy - dvert;
    room->a.colx = center.colx - dhorz;
    room->b.rowy = center.rowy + dvert;
    room->b.colx = center.colx + dhorz;
    if( ( room->a.rowy < 1 )||( room->a.colx < 1 ) ) return 0;
    if( room->b.rowy > ( 20 - 2 ) ) return 0;
    if( room->b.colx > ( 60 - 2 ) ) return 0;
    return 1;
}

variable_types: struct RECT { struct COORD { int rowy; int colx; } a; struct COORD b; } *

variable_types:
center
struct COORD

variable_types: dvert int

variable_types: dhorz int

user_defined_types: struct RECT { struct COORD a; struct COORD b; }


original_code:
void set_loc( LOC * spot, char type )
{
    spot->litter = ((void *)0);
    spot->mon = ((void *)0);
    spot->icon = type;
    spot->is_trap = 0;
}

canonical_original_code:
void set_loc(struct LOC *spot, char type)
{
    spot->litter = ((void *)0);
    spot->mon = ((void *)0);
    spot->icon = type;
    spot->is_trap = 0;
}

variable_types: struct LOC { struct ITEM { char name[-1]; int stats[2]; int worth; _Bool is_2handed; unsigned short type; } *litter; struct PLAYER { char name[-1]; int stats[6]; struct ITEM *inventory[10]; struct ITEM *equip[4]; int hp[2]; float explv; int money; int locr; unsigned int is_main; unsigned int is_alive; unsigned int is_human; unsigned int is_awake; } *mon; char icon; _Bool is_trap; } *

variable_types: type char

user_defined_types: struct LOC { struct ITEM *litter; struct PLAYER *mon; char icon; _Bool is_trap; }


towngen

original_code:
static void towngen( LEVEL * outside, LEVEL * inside, COORD * stair_spot )
{
    unsigned short hut_qt = 1 + ( rand() % (5) );
    unsigned short i, j, z;
    COORD hutspot[5];
    RECT room;
    for( i = 0; i < hut_qt; i++ ) {
        do {
            randspot( &hutspot[i] );
            if( i > 0 ) for( z = 0; z < i; z++ )
                if( dist( hutspot[z], hutspot[i] ) < 2.0 ) continue;
        } while( !roomgen( &room, hutspot[i]) );
        fill(outside,WALL,room);
        fill(inside,FLOOR,room);
        for( j = 0, z = ( rand() % (4) ) ; j < 4; j++ ) {
            if( ++z > 4 ) z = 1;
            switch( z ) {
                case 1:
                    hutspot[i].rowy = room.a.rowy;
                    ((void) sizeof ((hutspot[i].rowy-1 > -1) ? 1 : 0), __extension__ ({ if (hutspot[i].rowy-1 > -1) ; else __assert_fail ("hutspot[i].rowy-1 > -1", "src/map.c", 198, __extension__ __PRETTY_FUNCTION__); }));
                    if( outside->map[hutspot[i].rowy-1]
                                    [hutspot[i].colx].icon == WALL ) continue;
                    break;
                case 2:
                    hutspot[i].rowy = room.b.rowy - 1;
                    if( outside->map[room.b.rowy]
                                    [hutspot[i].colx].icon == WALL ) continue;
                    break;
                case 3:
                    hutspot[i].colx = room.b.colx - 1;
                    if( outside->map[hutspot[i].rowy]
                                    [room.b.colx].icon == WALL ) continue;
                    break;
                case 4:
                    hutspot[i].colx = room.a.colx;
                    ((void) sizeof ((hutspot[i].colx-1 > -1) ? 1 : 0), __extension__ ({ if (hutspot[i].colx-1 > -1) ; else __assert_fail ("hutspot[i].colx-1 > -1", "src/map.c", 214, __extension__ __PRETTY_FUNCTION__); }));
                    if( outside->map[hutspot[i].rowy]
                                    [hutspot[i].colx-1].icon == WALL ) continue;
                    break;
            }
            set_loc( &outside->map[hutspot[i].rowy][hutspot[i].colx], DOOR );
            if( inside->map[hutspot[i].rowy-1]
                           [hutspot[i].colx].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy-1][hutspot[i].colx], DOOR);
            else if( inside->map[hutspot[i].rowy+1]
                                [hutspot[i].colx].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy+1][hutspot[i].colx], DOOR);
            else if( inside->map[hutspot[i].rowy]
                                [hutspot[i].colx+1].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy][hutspot[i].colx+1], DOOR);
            else if( inside->map[hutspot[i].rowy]
                                [hutspot[i].colx-1].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy][hutspot[i].colx-1], DOOR);
            break;
        }
    }
    randspot( stair_spot );
    if( outside->map[stair_spot->rowy][stair_spot->colx].icon == WALL )
        set_loc( &inside->map[stair_spot->rowy][stair_spot->colx], DSTAIR );
    else set_loc( &outside->map[stair_spot->rowy][stair_spot->colx], DSTAIR );
}

canonical_original_code:
static void towngen(struct level_struct *outside, struct level_struct *inside, struct COORD *stair_spot)
{
    unsigned short hut_qt = 1 + ( rand() % (5) );
    unsigned short i; unsigned short j; unsigned short z;
    struct COORD hutspot[5];
    struct RECT room;
    for( i = 0; i < hut_qt; i++ ) {
        do {
            randspot( &hutspot[i] );
            if( i > 0 ) for( z = 0; z < i; z++ )
                if( dist( hutspot[z], hutspot[i] ) < 2.0 ) continue;
        } while( !roomgen( &room, hutspot[i]) );
        fill(outside,WALL,room);
        fill(inside,FLOOR,room);
        for( j = 0, z = ( rand() % (4) ) ; j < 4; j++ ) {
            if( ++z > 4 ) z = 1;
            switch( z ) {
                case 1:
                    hutspot[i].rowy = room.a.rowy;
                    ((void) sizeof ((hutspot[i].rowy-1 > -1) ? 1 : 0), __extension__ ({ if (hutspot[i].rowy-1 > -1) ; else __assert_fail ("hutspot[i].rowy-1 > -1", "src/map.c", 198, __extension__ __PRETTY_FUNCTION__); }));
                    if( outside->map[hutspot[i].rowy-1]
                                    [hutspot[i].colx].icon == WALL ) continue;
                    break;
                case 2:
                    hutspot[i].rowy = room.b.rowy - 1;
                    if( outside->map[room.b.rowy]
                                    [hutspot[i].colx].icon == WALL ) continue;
                    break;
                case 3:
                    hutspot[i].colx = room.b.colx - 1;
                    if( outside->map[hutspot[i].rowy]
                                    [room.b.colx].icon == WALL ) continue;
                    break;
                case 4:
                    hutspot[i].colx = room.a.colx;
                    ((void) sizeof ((hutspot[i].colx-1 > -1) ? 1 : 0), __extension__ ({ if (hutspot[i].colx-1 > -1) ; else __assert_fail ("hutspot[i].colx-1 > -1", "src/map.c", 214, __extension__ __PRETTY_FUNCTION__); }));
                    if( outside->map[hutspot[i].rowy]
                                    [hutspot[i].colx-1].icon == WALL ) continue;
                    break;
            }
            set_loc( &outside->map[hutspot[i].rowy][hutspot[i].colx], DOOR );
            if( inside->map[hutspot[i].rowy-1]
                           [hutspot[i].colx].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy-1][hutspot[i].colx], DOOR);
            else if( inside->map[hutspot[i].rowy+1]
                                [hutspot[i].colx].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy+1][hutspot[i].colx], DOOR);
            else if( inside->map[hutspot[i].rowy]
                                [hutspot[i].colx+1].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy][hutspot[i].colx+1], DOOR);
            else if( inside->map[hutspot[i].rowy]
                                [hutspot[i].colx-1].icon == WALL )
                set_loc(&inside->map[hutspot[i].rowy][hutspot[i].colx-1], DOOR);
            break;
        }
    }
    randspot( stair_spot );
    if( outside->map[stair_spot->rowy][stair_spot->colx].icon == WALL )
        set_loc( &inside->map[stair_spot->rowy][stair_spot->colx], DSTAIR );
    else set_loc( &outside->map[stair_spot->rowy][stair_spot->colx], DSTAIR );
}

variable_types: struct level_struct { struct LOC { struct ITEM { char name[-1]; int stats[2]; int worth; _Bool is_2handed; unsigned short type; } *litter; struct PLAYER { char name[-1]; int stats[6]; struct ITEM *inventory[10]; struct ITEM *equip[4]; int hp[2]; float explv; int money; int locr; unsigned int is_main; unsigned int is_alive; unsigned int is_human; unsigned int is_awake; } *mon; char icon; _Bool is_trap; } map[20][60]; int type; _Bool is_new; } *

variable_types:
inside
struct level_struct *

variable_types:
i
unsigned short

variable_types:
j
unsigned short

variable_types:
z
unsigned short

variable_types: struct COORD { int rowy; int colx; } [5]

variable_types: struct RECT { struct COORD { int rowy; int colx; } a; struct COORD b; }

user_defined_types: struct level_struct { struct LOC map[20][60]; int type; _Bool is_new; }


decompiled_code:
__int64 __fastcall get_map_icon(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, unsigned __int8 a9)
{
__int64 result; // rax

result = 38LL;
if ( !a7 )
{
result = 111LL;
if ( !a8 )
result = a9;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, unsigned __int8 a9)
{
__int64 result; // rax

result = 38LL;
if ( !a7 )
{
result = 111LL;
if ( !a8 )
result = a9;
}
return result;
}

original_code:
char get_map_icon( LOC here )
{
    if( here.litter != ((void *)0) ) return '&';
    if( here.mon != ((void *)0) ) return 'o';
                              return here.icon;
}

canonical_original_code:
char get_map_icon(struct LOC here)
{
    if( here.litter != ((void *)0) ) return '&';
    if( here.mon != ((void *)0) ) return 'o';
                              return here.icon;
}

variable_types: struct LOC { struct ITEM { char name[-1]; int stats[2]; int worth; _Bool is_2handed; unsigned short type; } *litter; struct PLAYER { char name[-1]; int stats[6]; struct ITEM *inventory[10]; struct ITEM *equip[4]; int hp[2]; float explv; int money; int locr; unsigned int is_main; unsigned int is_alive; unsigned int is_human; unsigned int is_awake; } *mon; char icon; _Bool is_trap; }

return_type: char


decompiled_code:
int __fastcall draw_map(__int64 a1)
{
int i; // ebp
int j; // ebx
WINDOW *v4; // rdi
int result; // eax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
char v10; // al

for ( i = 0; i != 20; ++i )
{
for ( j = 0; j != 60; ++j )
{
v4 = stdscr;
result = wmove(stdscr, i, j);
if ( result != -1 )
{
v10 = get_map_icon(
(__int64)v4,
(unsigned int)i,
v6,
v7,
v8,
v9,
*(_QWORD *)(a1 + 1440LL * i + 24LL * j),
*(_QWORD *)(a1 + 1440LL * i + 24LL * j + 8),
*(_QWORD *)(a1 + 1440LL * i + 24LL * j + 16));
result = waddch(stdscr, (unsigned int)v10);
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
int i; // ebp
int j; // ebx
WINDOW *v4; // rdi
int result; // eax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
char v10; // al

for ( i = 0; i != 20; ++i )
{
for ( j = 0; j != 60; ++j )
{
v4 = stdscr;
result = wmove(stdscr, i, j);
if ( result != -1 )
{
v10 = func6(
(__int64)v4,
(unsigned int)i,
v6,
v7,
v8,
v9,
*(_QWORD *)(a1 + 1440LL * i + 24LL * j),
*(_QWORD *)(a1 + 1440LL * i + 24LL * j + 8),
*(_QWORD *)(a1 + 1440LL * i + 24LL * j + 16));
result = waddch(stdscr, (unsigned int)v10);
}
}
}
return result;
}

original_code:
void draw_map( LEVEL * curlv )
{
    int r, c;
    for( r = 0; r < 20; r++ ) for( c = 0; c < 60; c++ )
        (wmove((stdscr),((r)),((c))) == (-1) ? (-1) : waddch((stdscr),((get_map_icon( curlv->map[r][c] )))));
}

canonical_original_code:
void draw_map(struct level_struct *curlv)
{
    int r; int c;
    for( r = 0; r < 20; r++ ) for( c = 0; c < 60; c++ )
        (wmove((stdscr),((r)),((c))) == (-1) ? (-1) : waddch((stdscr),((get_map_icon( curlv->map[r][c] )))));
}

variable_types: r int

variable_types: c int

user_defined_types: struct PLAYER { char name[-1]; int stats[6]; struct ITEM *inventory[10]; struct ITEM *equip[4]; int hp[2]; float explv; int money; int locr; unsigned int is_main; unsigned int is_alive; unsigned int is_human; unsigned int is_awake; }


dungen

original_code:
_Bool dungen( LEVEL * curlv, PLAYER * npc )
{
    int i;
    COORD prev_stair_spot;
    COORD top_left = { 0, 0 };
    COORD btm_right = { 20, 60 };
    RECT room = { top_left, btm_right };
    for( i = 0; i < 9; i++ ) {
        curlv[i].type = i;
        curlv[i].is_new = 1;
        if( i == 0 ) fill(&curlv[i],FLOOR,room);
        else fill(&curlv[i],WALL,room);
    }
    towngen( &curlv[0], &curlv[1], &prev_stair_spot );
    if( !roomgen( &room, prev_stair_spot ) ) {
        set_loc( &( curlv[6].map[prev_stair_spot.rowy]
                                       [prev_stair_spot.colx] ), FLOOR );
    } else fill(&curlv[6],FLOOR,room);
    return 1;
}

canonical_original_code:
_Bool dungen(struct level_struct *curlv, struct PLAYER *npc)
{
    int i;
    struct COORD prev_stair_spot;
    struct COORD top_left = { 0, 0 };
    struct COORD btm_right = { 20, 60 };
    struct RECT room = { top_left, btm_right };
    for( i = 0; i < 9; i++ ) {
        curlv[i].type = i;
        curlv[i].is_new = 1;
        if( i == 0 ) fill(&curlv[i],FLOOR,room);
        else fill(&curlv[i],WALL,room);
    }
    towngen( &curlv[0], &curlv[1], &prev_stair_spot );
    if( !roomgen( &room, prev_stair_spot ) ) {
        set_loc( &( curlv[6].map[prev_stair_spot.rowy]
                                       [prev_stair_spot.colx] ), FLOOR );
    } else fill(&curlv[6],FLOOR,room);
    return 1;
}

variable_types:
npc
struct PLAYER *

variable_types: i int


decompiled_code:
__int64 get_cmd()
{
int v0; // eax
unsigned int v1; // edx

v0 = wgetch(stdscr);
if ( v0 > 119 )
{
if ( v0 == 260 )
{
v1 = 4;
}
else if ( v0 <= 260 )
{
v1 = 2;
if ( v0 != 258 )
v1 = v0 == 259;
}
else
{
v1 = 3 * (v0 == 261);
}
}
else if ( v0 <= 26 )
{
v1 = 0;
}
else
{
switch ( v0 )
{
case 27:
case 81:
case 113:
v1 = 10;
break;
case 44:
case 103:
v1 = 16;
break;
case 49:
v1 = 8;
break;
case 50:
v1 = 2;
break;
case 51:
v1 = 7;
break;
case 52:
v1 = 4;
break;
case 53:
v1 = 9;
break;
case 54:
v1 = 3;
break;
case 55:
v1 = 6;
break;
case 56:
v1 = 1;
break;
case 57:
v1 = 5;
break;
case 73:
case 105:
v1 = 11;
break;
case 75:
v1 = 15;
break;
case 84:
case 117:
v1 = 14;
break;
case 100:
v1 = 13;
break;
case 101:
case 119:
v1 = 12;
break;
default:
v1 = 0;
break;
}
}
return v1;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
unsigned int v1; // edx

v0 = wgetch(stdscr);
if ( v0 > 119 )
{
if ( v0 == 260 )
{
v1 = 4;
}
else if ( v0 <= 260 )
{
v1 = 2;
if ( v0 != 258 )
v1 = v0 == 259;
}
else
{
v1 = 3 * (v0 == 261);
}
}
else if ( v0 <= 26 )
{
v1 = 0;
}
else
{
switch ( v0 )
{
case 27:
case 81:
case 113:
v1 = 10;
break;
case 44:
case 103:
v1 = 16;
break;
case 49:
v1 = 8;
break;
case 50:
v1 = 2;
break;
case 51:
v1 = 7;
break;
case 52:
v1 = 4;
break;
case 53:
v1 = 9;
break;
case 54:
v1 = 3;
break;
case 55:
v1 = 6;
break;
case 56:
v1 = 1;
break;
case 57:
v1 = 5;
break;
case 73:
case 105:
v1 = 11;
break;
case 75:
v1 = 15;
break;
case 84:
case 117:
v1 = 14;
break;
case 100:
v1 = 13;
break;
case 101:
case 119:
v1 = 12;
break;
default:
v1 = 0;
break;
}
}
return v1;
}

original_code:
static int get_cmd( void )
{
    switch( wgetch(stdscr) ) {
        case '8': case 0403: return 1;
        case '2': case 0402: return 2;
        case '6': case 0405: return 3;
        case '4': case 0404: return 4;
        case '9': return 5;
        case '7': return 6;
        case '3': return 7;
        case '1': return 8;
        case '5': return 9;
        case 'q':
        case 'Q': case 27: return 10;
        case 'g': case ',': return 16;
        case 'i': case 'I': return 11;
        case 'e': case 'w': return 12;
        case 'u': case 'T': return 14;
        case 'd': return 13;
        case 'K': return 15;
        default: return 0;
    }
}

canonical_original_code:
static int get_cmd()
{
    switch( wgetch(stdscr) ) {
        case '8': case 0403: return 1;
        case '2': case 0402: return 2;
        case '6': case 0405: return 3;
        case '4': case 0404: return 4;
        case '9': return 5;
        case '7': return 6;
        case '3': return 7;
        case '1': return 8;
        case '5': return 9;
        case 'q':
        case 'Q': case 27: return 10;
        case 'g': case ',': return 16;
        case 'i': case 'I': return 11;
        case 'e': case 'w': return 12;
        case 'u': case 'T': return 14;
        case 'd': return 13;
        case 'K': return 15;
        default: return 0;
    }
}


decompiled_code:
__int64 get_subi_cmd()
{
__int64 result; // rax

switch ( wgetch(stdscr) )
{
case 27:
case 32:
case 70:
case 81:
case 102:
case 113:
result = 10LL;
break;
case 68:
case 100:
result = 13LL;
break;
case 69:
case 87:
case 101:
case 114:
case 119:
result = 12LL;
break;
case 75:
case 88:
case 107:
case 120:
result = 15LL;
break;
case 82:
case 84:
case 85:
case 116:
case 117:
result = 14LL;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

switch ( wgetch(stdscr) )
{
case 27:
case 32:
case 70:
case 81:
case 102:
case 113:
result = 10LL;
break;
case 68:
case 100:
result = 13LL;
break;
case 69:
case 87:
case 101:
case 114:
case 119:
result = 12LL;
break;
case 75:
case 88:
case 107:
case 120:
result = 15LL;
break;
case 82:
case 84:
case 85:
case 116:
case 117:
result = 14LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
static int get_subi_cmd( void )
{
    switch( wgetch(stdscr) ) {
        case 'f': case 'F': case 27:
        case 'q': case 'Q': case ' ': return 10;
        case 'D': case 'd':
                                               return 13;
        case 'E': case 'e': case 'r':
        case 'w': case 'W': return 12;
        case 'u': case 'U': case 'R':
        case 't': case 'T': return 14;
        case 'K': case 'k':
        case 'x': case 'X': return 15;
        default: return 0;
    }
}

canonical_original_code:
static int get_subi_cmd()
{
    switch( wgetch(stdscr) ) {
        case 'f': case 'F': case 27:
        case 'q': case 'Q': case ' ': return 10;
        case 'D': case 'd':
                                               return 13;
        case 'E': case 'e': case 'r':
        case 'w': case 'W': return 12;
        case 'u': case 'U': case 'R':
        case 't': case 'T': return 14;
        case 'K': case 'k':
        case 'x': case 'X': return 15;
        default: return 0;
    }
}


decompiled_code:
__int64 __fastcall manage_inventory(__int64 a1, __int64 a2, int a3)
{
char v5; // dl

do
{
if ( (unsigned int)(a3 - 12) > 3 )
{
do
a3 = get_subi_cmd();
while ( !a3 );
}
if ( a3 == 14 )
{
v5 = unequip_me(a1, 0xFFFFFFFFLL, 1LL);
}
else if ( a3 > 14 )
{
if ( a3 != 15 )
return 1LL;
v5 = destroy_my_item(a1, 0xFFFFFFFFLL, 1LL);
}
else if ( a3 == 12 )
{
v5 = equip_me(a1, 0xFFFFFFFFLL, 1LL);
}
else
{
if ( a3 != 13 )
return 1LL;
v5 = drop_my_item(a1, a2, 0xFFFFFFFFLL, 1LL);
}
a3 = 0;
}
while ( !v5 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3)
{
char v5; // dl

do
{
if ( (unsigned int)(a3 - 12) > 3 )
{
do
a3 = func1();
while ( !a3 );
}
if ( a3 == 14 )
{
v5 = unequip_me(a1, 0xFFFFFFFFLL, 1LL);
}
else if ( a3 > 14 )
{
if ( a3 != 15 )
return 1LL;
v5 = destroy_my_item(a1, 0xFFFFFFFFLL, 1LL);
}
else if ( a3 == 12 )
{
v5 = equip_me(a1, 0xFFFFFFFFLL, 1LL);
}
else
{
if ( a3 != 13 )
return 1LL;
v5 = drop_my_item(a1, a2, 0xFFFFFFFFLL, 1LL);
}
a3 = 0;
}
while ( !v5 );
return 0LL;
}

original_code:
static _Bool manage_inventory( PLAYER * pc, LOC * active_loc, int cmd )
{
    _Bool done_with_sub = 0;
    while( done_with_sub == 0) {
        if( ( cmd > 11 )&&( cmd <= 15 ) );
        else while( ( cmd = get_subi_cmd() ) == 0 );
        switch( cmd ) {
            case 12: done_with_sub = equip_me(pc,-1,1); break;
            case 13: done_with_sub = drop_my_item(pc,active_loc,-1,1); break;
            case 14: done_with_sub = unequip_me(pc,-1,1); break;
            case 15: done_with_sub = destroy_my_item(pc,-1,1); break;
            default: return 1;
        }
        cmd = 0;
    }
    return 0;
}

canonical_original_code:
static _Bool manage_inventory(struct PLAYER *pc, struct LOC *active_loc, int cmd)
{
    _Bool done_with_sub = 0;
    while( done_with_sub == 0) {
        if( ( cmd > 11 )&&( cmd <= 15 ) );
        else while( ( cmd = get_subi_cmd() ) == 0 );
        switch( cmd ) {
            case 12: done_with_sub = equip_me(pc,-1,1); break;
            case 13: done_with_sub = drop_my_item(pc,active_loc,-1,1); break;
            case 14: done_with_sub = unequip_me(pc,-1,1); break;
            case 15: done_with_sub = destroy_my_item(pc,-1,1); break;
            default: return 1;
        }
        cmd = 0;
    }
    return 0;
}

variable_types: struct PLAYER { char name[-1]; int stats[6]; struct ITEM { char name[-1]; int stats[2]; int worth; _Bool is_2handed; unsigned short type; } *inventory[10]; struct ITEM *equip[4]; int hp[2]; float explv; int money; int locr; unsigned int is_main; unsigned int is_alive; unsigned int is_human; unsigned int is_awake; } *

variable_types: struct LOC { struct ITEM *litter; struct PLAYER *mon; char icon; _Bool is_trap; } *

variable_types: cmd int


repo: moorescloud/secretapi

decompiled_code:
void gpio_map()
{
int v0; // ebx

if ( !gpio_mmap )
{
v0 = open("/dev/mem", 2);
if ( v0 < 0 )
{
perror("Unable to open /dev/mem");
v0 = 0;
}
gpio_mmap = (__int64)mmap(0LL, 0xFFFuLL, 3, 1, v0, 2147581952LL);
if ( (_DWORD)gpio_mmap == -1 )
{
perror("Unable to mmap file");
gpio_mmap = 0LL;
}
if ( close(v0) == -1 )
perror("Couldn't close file");
}
}

canonical_decompiled_code:
void func10()
{
int v0; // ebx

if ( !gpio_mmap )
{
v0 = open("/dev/mem", 2);
if ( v0 < 0 )
{
perror("Unable to open /dev/mem");
v0 = 0;
}
gpio_mmap = (__int64)mmap(0LL, 0xFFFuLL, 3, 1, v0, 2147581952LL);
if ( (_DWORD)gpio_mmap == -1 )
{
perror("Unable to mmap file");
gpio_mmap = 0LL;
}
if ( close(v0) == -1 )
perror("Couldn't close file");
}
}

original_code:
int *gpio_map() {
 int fd;
 if (gpio_mmap != 0) return;
 fd = open("/dev/mem", 02);
 if( fd < 0 ) {
  perror("Unable to open /dev/mem");
  fd = 0;
 }
 gpio_mmap = mmap(0, 0xfff, 0x1|0x2, 0x01, fd, 0x80018000);
 if( -1 == (int)gpio_mmap) {
  perror("Unable to mmap file");
  gpio_mmap = 0;
 }
 if( -1 == close(fd))
  perror("Couldn't close file");
 fd=0;
}

variable_types: fd int

return_type: int *


decompiled_code:
__int64 __fastcall gpio_rd(__int64 a1)
{
__int64 v2; // rdi

v2 = a1 + 3;
if ( a1 >= 0 )
v2 = a1;
return *(unsigned int *)(gpio_mmap + 4 * (v2 >> 2));
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v2; // rdi

v2 = a1 + 3;
if ( a1 >= 0 )
v2 = a1;
return *(unsigned int *)(gpio_mmap + 4 * (v2 >> 2));
}

original_code:
int gpio_rd(long offset) {
 return gpio_mmap[offset/4];
}

variable_types: offset long


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

result = 4 * a1 + 449;
*(_DWORD *)(gpio_mmap + 4 * result) = 1 << a2;
return result;
}

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

result = 4 * a1 + 449;
*(_DWORD *)(gpio_mmap + 4 * result) = 1 << a2;
return result;
}

original_code:
void gpio_output(int bank, int pin) {
 gpio_mmap[0x1C1 + (bank*4)] = 1 << pin;
}

variable_types: bank int

variable_types: pin int


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

result = 4 * a1 + 450;
*(_DWORD *)(gpio_mmap + 4 * result) = 1 << a2;
return result;
}

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

result = 4 * a1 + 450;
*(_DWORD *)(gpio_mmap + 4 * result) = 1 << a2;
return result;
}

original_code:
void gpio_input(int bank, int pin) {
 gpio_mmap[0x1C2 + (bank*4)] = 1 << pin;
}


decompiled_code:
void spi_close()
{
;
}

canonical_decompiled_code:
void func16()
{
;
}

original_code:
void spi_close()
{
}

canonical_original_code:
void spi_close()
{
}


diep

decompiled_code:
void __fastcall __noreturn diep(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func17(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void diep(char *s)
{
    perror(s);
    exit(1);
}

variable_types:
s
char *


render

decompiled_code:
void render()
{
spi_send();
}

canonical_decompiled_code:
void func18()
{
func7();
}

original_code:
void render(char* buf) {
int j, k;
char* obf;
    obf = &buf[10];
    spi_send(obf, 150);
    return;
}

canonical_original_code:
void render(char *buf) {
int j; int k;
char *obf;
    obf = &buf[10];
    spi_send(obf, 150);
    return;
}

variable_types:
buf
char *

variable_types: j int

variable_types: k int

variable_types:
obf
char *


constant

decompiled_code:
double __fastcall constant(__int64 a1)
{
return *(double *)(a1 + 8);
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1)
{
return *(double *)(a1 + 8);
}

original_code:
double
constant(distn *d)
{
    return (d->mean);
}

canonical_original_code:
double constant(struct _distn *d)
{
    return (d->mean);
}

variable_types: struct _distn { double (*function)(struct _distn *distribution); double mean; double shape; } *

return_type: double


expon

decompiled_code:
double __fastcall expon(__int64 a1)
{
double v1; // xmm0_8

v1 = drand48();
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(v1)) ^ LC0) * *(double *)(a1 + 8);
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1)
{
double v1; // xmm0_8

v1 = drand48();
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(v1)) ^ LC0) * *(double *)(a1 + 8);
}

original_code:
double
expon(distn *d)
{
    double r = (double) drand48();
    double val = -log(r) * d->mean;
    return (val);
}

canonical_original_code:
double expon(struct _distn *d)
{
    double r = (double) drand48();
    double val = -log(r) * d->mean;
    return (val);
}

variable_types: r double

variable_types: val double

user_defined_types: struct _distn { double (*function)(struct _distn *distribution); double mean; double shape; }


paretoon

decompiled_code:
double __fastcall paretoon(__int64 a1)
{
double v1; // xmm0_8
double v2; // rbp

v1 = drand48();
v2 = *(double *)(a1 + 8);
return 1.0 / pow(v1, 1.0 / *(double *)(a1 + 16)) * v2;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1)
{
double v1; // xmm0_8
double v2; // rbp

v1 = drand48();
v2 = *(double *)(a1 + 8);
return 1.0 / pow(v1, 1.0 / *(double *)(a1 + 16)) * v2;
}

original_code:
double paretoon(distn *d)
{
    double r = (double) drand48();
    double val = (d->mean * (1.0/pow(r, 1.0/d->shape)));
    return (val);
}

canonical_original_code:
double paretoon(struct _distn *d)
{
    double r = (double) drand48();
    double val = (d->mean * (1.0/pow(r, 1.0/d->shape)));
    return (val);
}


decompiled_code:
__int64 __fastcall parse_distn(double (__fastcall **a1)(__int64 a1), int *a2, __int64 a3, int a4)
{
int v5; // er13
const char *v6; // r15
__int64 i; // rbx
unsigned int v8; // ebp
int v10; // eax
int v11; // eax
int v12; // eax
int v13; // eax

v5 = *a2 - 1;
*a2 = v5;
v6 = *(const char **)(a3 + 8LL * v5);
for ( i = 0LL; i != 3; ++i )
{
v8 = i;
if ( !strncmp(v6, (&Distn_Function_Type)[i], 0xFFuLL) )
break;
v8 = i + 1;
}
switch ( v8 )
{
case 1u:
if ( a4 - v5 <= 1 )
{
fprintf(stderr, "%s: exponent requries one argument (mean)\n", "parse_distn");
return (unsigned int)-1;
}
*a1 = expon;
v11 = *a2 + 1;
*a2 = v11;
v8 = 0;
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a3 + 8LL * v11), "%lg", a1 + 1) == 1 )
goto LABEL_8;
LABEL_12:
fprintf(stderr, "%s: bad constant %s \n", "parse_distn", *(const char **)(a3 + 8LL * *a2));
return v8;
case 2u:
if ( a4 - v5 <= 2 )
{
fprintf(stderr, "%s: pareto requries two arguments (mean and shape)\n", "parse_distn");
return (unsigned int)-1;
}
*a1 = paretoon;
v12 = *a2 + 1;
*a2 = v12;
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a3 + 8LL * v12), "%lg", a1 + 1) != 1 )
{
fprintf(stderr, "%s: bad mean %s \n", "parse_distn", *(const char **)(a3 + 8LL * *a2));
return 0;
}
v13 = *a2 + 1;
*a2 = v13;
v8 = 0;
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a3 + 8LL * v13), "%lg", a1 + 2) != 1 )
{
fprintf(stderr, "%s: bad shape %s \n", "parse_distn", *(const char **)(a3 + 8LL * *a2));
return v8;
}
goto LABEL_8;
case 0u:
if ( a4 - v5 <= 1 )
{
fprintf(stderr, "%s: constant requries one argument\n", "parse_distn");
return (unsigned int)-1;
}
*a1 = constant;
v10 = *a2 + 1;
*a2 = v10;
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a3 + 8LL * v10), "%lg", a1 + 1) == 1 )
goto LABEL_8;
goto LABEL_12;
}
fprintf(stderr, "%s: unknown distribution type %s\n", "parse_distn", v6);
v8 = -1;
LABEL_8:
++*a2;
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(double (__fastcall **a1)(__int64 a1), int *a2, __int64 a3, int a4)
{
int v5; // er13
const char *v6; // r15
__int64 i; // rbx
unsigned int v8; // ebp
int v10; // eax
int v11; // eax
int v12; // eax
int v13; // eax

v5 = *a2 - 1;
*a2 = v5;
v6 = *(const char **)(a3 + 8LL * v5);
for ( i = 0LL; i != 3; ++i )
{
v8 = i;
if ( !strncmp(v6, (&Distn_Function_Type)[i], 0xFFuLL) )
break;
v8 = i + 1;
}
switch ( v8 )
{
case 1u:
if ( a4 - v5 <= 1 )
{
fprintf(stderr, "%s: exponent requries one argument (mean)\n", "parse_distn");
return (unsigned int)-1;
}
*a1 = expon;
v11 = *a2 + 1;
*a2 = v11;
v8 = 0;
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a3 + 8LL * v11), "%lg", a1 + 1) == 1 )
goto LABEL_8;
LABEL_12:
fprintf(stderr, "%s: bad constant %s \n", "parse_distn", *(const char **)(a3 + 8LL * *a2));
return v8;
case 2u:
if ( a4 - v5 <= 2 )
{
fprintf(stderr, "%s: pareto requries two arguments (mean and shape)\n", "parse_distn");
return (unsigned int)-1;
}
*a1 = paretoon;
v12 = *a2 + 1;
*a2 = v12;
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a3 + 8LL * v12), "%lg", a1 + 1) != 1 )
{
fprintf(stderr, "%s: bad mean %s \n", "parse_distn", *(const char **)(a3 + 8LL * *a2));
return 0;
}
v13 = *a2 + 1;
*a2 = v13;
v8 = 0;
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a3 + 8LL * v13), "%lg", a1 + 2) != 1 )
{
fprintf(stderr, "%s: bad shape %s \n", "parse_distn", *(const char **)(a3 + 8LL * *a2));
return v8;
}
goto LABEL_8;
case 0u:
if ( a4 - v5 <= 1 )
{
fprintf(stderr, "%s: constant requries one argument\n", "parse_distn");
return (unsigned int)-1;
}
*a1 = constant;
v10 = *a2 + 1;
*a2 = v10;
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a3 + 8LL * v10), "%lg", a1 + 1) == 1 )
goto LABEL_8;
goto LABEL_12;
}
fprintf(stderr, "%s: unknown distribution type %s\n", "parse_distn", v6);
v8 = -1;
LABEL_8:
++*a2;
return v8;
}

original_code:
int
parse_distn(distn *distribution, int *optind, char **argv, int argc)
{
    int rv=0,rc;
    int theType;
    (*optind)--;
    for(theType=0; theType < Distn_Function_nTypes; theType++)
    {
        if(!strncmp(argv[*optind], Distn_Function_Type[theType], 255))
            break;
    }
    switch(theType)
    {
        case Distn_Function_Constant:
        {
            if((argc - *optind) < 2)
            {
                fprintf(stderr,
                        "%s: constant requries one argument\n", __FUNCTION__);
                rv = -1;
                goto abort;
            }
            distribution->function = constant;
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->mean);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad constant %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            break;
        }
        case Distn_Function_Exponent:
        {
            if((argc - *optind) < 2)
            {
                fprintf(stderr,
                        "%s: exponent requries one argument (mean)\n", __FUNCTION__);
                rv = -1;
                goto abort;
            }
            distribution->function = expon;
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->mean);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad constant %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            break;
        }
        case Distn_Function_Pareto:
        {
            if((argc - *optind) < 3)
            {
                fprintf(stderr,
                        "%s: pareto requries two arguments (mean and shape)\n",
                        __FUNCTION__);
                rv = -1;
                goto abort;
            }
            distribution->function = paretoon;
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->mean);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad mean %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->shape);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad shape %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            break;
        }
        default:
            fprintf(stderr,
                    "%s: unknown distribution type %s\n",
                    __FUNCTION__, argv[*optind]);
            rv = -1;
    }
    (*optind)++;
abort:
    return rv;
}

canonical_original_code:
int parse_distn(struct _distn *distribution, int *optind, char **argv, int argc)
{
    int rv = 0; int rc;
    int theType;
    (*optind)--;
    for(theType=0; theType < Distn_Function_nTypes; theType++)
    {
        if(!strncmp(argv[*optind], Distn_Function_Type[theType], 255))
            break;
    }
    switch(theType)
    {
        case Distn_Function_Constant:
        {
            if((argc - *optind) < 2)
            {
                fprintf(stderr,
                        "%s: constant requries one argument\n", __FUNCTION__);
                rv = -1;
                goto abort;
            }
            distribution->function = constant;
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->mean);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad constant %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            break;
        }
        case Distn_Function_Exponent:
        {
            if((argc - *optind) < 2)
            {
                fprintf(stderr,
                        "%s: exponent requries one argument (mean)\n", __FUNCTION__);
                rv = -1;
                goto abort;
            }
            distribution->function = expon;
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->mean);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad constant %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            break;
        }
        case Distn_Function_Pareto:
        {
            if((argc - *optind) < 3)
            {
                fprintf(stderr,
                        "%s: pareto requries two arguments (mean and shape)\n",
                        __FUNCTION__);
                rv = -1;
                goto abort;
            }
            distribution->function = paretoon;
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->mean);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad mean %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            (*optind)++;
            rc = sscanf(argv[*optind], "%lg", &distribution->shape);
            if(rc != 1)
            {
                fprintf(stderr,
                        "%s: bad shape %s \n", __FUNCTION__, argv[*optind]);
                goto abort;
            }
            break;
        }
        default:
            fprintf(stderr,
                    "%s: unknown distribution type %s\n",
                    __FUNCTION__, argv[*optind]);
            rv = -1;
    }
    (*optind)++;
abort:
    return rv;
}

variable_types:
optind
int *

variable_types:
argv
char **

variable_types: argc int

variable_types: rv int

variable_types: rc int

variable_types: theType int


decompiled_code:
void __fastcall __noreturn surge_client(int a1, __int64 a2, int a3, unsigned int a4)
{
int i; // er13
__int64 v6; // rbp
double v7; // xmm0_8
__int64 v8; // rdx
int v9; // eax
int v10; // eax
int v11; // ebx
double v12; // r13
int v13; // eax
signed int v14; // eax
__int64 v15; // rdi
int v16; // eax
int v17; // ebx
__int64 v18; // r13
__int64 v19; // rdx
char *v20; // rbp
int v21; // er13
int v22; // er15
int v23; // er14
int v24; // edx
double v25; // rbp
int v26; // eax
__int64 j; // rdi
signed int v28; // ebx
__int64 v29; // rax
int v30; // er13
int v31; // ebp
int v32; // ebp
int v33; // ebp
int v34; // ebp
__int64 v35; // rbp
__int64 v36; // r13
__int64 v37; // r14
__int64 v38; // r15
unsigned int v39; // eax
int v40; // edx
unsigned int v41; // ebx
int v42; // ebp
__int64 v43; // [rsp+0h] [rbp-2F8h]
unsigned int v45; // [rsp+Ch] [rbp-2ECh]
struct timeval timeout; // [rsp+10h] [rbp-2E8h] BYREF
struct timeval tv; // [rsp+20h] [rbp-2D8h] BYREF
__int64 v48; // [rsp+30h] [rbp-2C8h] BYREF
__int64 v49; // [rsp+38h] [rbp-2C0h]
__int64 v50[16]; // [rsp+40h] [rbp-2B8h] BYREF
__int64 v51[16]; // [rsp+C0h] [rbp-238h] BYREF
__int64 v52[16]; // [rsp+140h] [rbp-1B8h] BYREF
char v53[128]; // [rsp+1C0h] [rbp-138h] BYREF
__int64 v54[23]; // [rsp+240h] [rbp-B8h] BYREF

v48 = 0LL;
v49 = 0LL;
v43 = host2ipaddr(a2);
memset(v54, 0, 0x80uLL);
memset(v53, 0, sizeof(v53));
memset(v52, 0, sizeof(v52));
memset(v51, 0, sizeof(v51));
memset(v50, 0, sizeof(v50));
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
v10 = create_tx_tcp(v43, i % a3 + a4);
v11 = v10;
if ( v10 < 0 )
{
fwrite("Unable to open connection!\n", 1uLL, 0x1BuLL, stderr);
exit(-1);
}
if ( maxfd < v10 )
maxfd = v10;
v6 = 4LL * v10;
state[40 * v10 + 34] = v10;
state[8 * v6 + 35 + 8 * v10] = (int)objperpage(&objperpage);
v7 = objsize(&objsize);
v8 = 8 * (v6 + v11);
v9 = (int)v7;
if ( (int)v7 <= 0 )
v9 = 1;
state[v8 + 9] = v9;
state[v8 + 11] = 0;
state[v8 + 10] = 0;
state[v8 + 23] = 0;
v54[v11 / 64] |= 1LL << (v11 % 64);
timeout.tv_usec = (int)(drand48() * 10000.0);
select(0, &fds_zero, &fds_zero, &fds_zero, &timeout);
}
}
while ( 1 )
{
send_request(v54, v53);
v15 = 0LL;
if ( (int)sink_data(v53, v52) > 0 )
{
while ( 1 )
{
v16 = FD_FFSandC(v15, maxfd, v52);
v17 = v16;
if ( !v16 )
break;
v18 = 4LL * v16;
v19 = 40LL * v16;
v20 = (char *)&state[v19 + 30];
tvsub(&timeout, v20, &state[v19 + 26]);
v21 = state[8 * v17 + 23 + 8 * v18];
v22 = timeout.tv_sec;
v23 = timeout.tv_usec;
gettimeofday(&tv, 0LL);
if ( verbose )
fprintf(
stderr,
"%d.%06d Finished with %d after %d bytes. %ld.%03lds = %.4f Mb/s.\n",
LODWORD(tv.tv_sec),
LODWORD(tv.tv_usec),
(unsigned int)v17,
state[40 * v17 + 23],
timeout.tv_sec,
timeout.tv_usec / 1000,
(double)v21 * 8.0 / ((double)v22 * 1000000.0 + (double)v23) / scalar);
close(v17);
state[40 * v17 + 8] = 0;
v24 = state[40 * v17 + 35] - 1;
state[40 * v17 + 35] = v24;
if ( v24 <= 0 )
{
v12 = interpage(&interpage);
state[40 * v17 + 35] = (int)objperpage(&objperpage);
}
else
{
v12 = interobj(&interobj);
}
v13 = (int)(v12 * scalar);
v48 = v13;
v49 = (int)((v12 * scalar - (double)v13) * 1000000.0);
tvadd(&state[40 * state[40 * v17 + 34] + 36], v20, &v48);
if ( verbose )
printf("(%d): time_us %d.%06d opp %d\n", 433LL, (unsigned int)v48, (unsigned int)v49, state[40 * v17 + 35]);
v52[v17 / 64] &= ~(1LL << (v17 % 64));
v14 = state[40 * v17 + 34];
v51[v14 / 64] |= 1LL << (v14 % 64);
v15 = (unsigned int)(v17 + 1);
}
}
v30 = 0;
for ( j = 0LL; ; j = (unsigned int)(v28 + 1) )
{
v28 = FD_FFS(j, maxfd, v51);
if ( !v28 )
break;
gettimeofday(&tv, 0LL);
if ( (unsigned int)tveqless(&state[40 * v28 + 36], &tv) )
{
if ( (int)state[40 * v28 + 35] <= 0 )
{
v25 = interpage(&interpage);
state[35] = (int)objperpage(&objperpage);
v26 = (int)(v25 * scalar);
v48 = v26;
v49 = (int)((v25 * scalar - (double)v26) * 1000000.0);
tvadd(&state[40 * state[34] + 36], (unsigned int)((_DWORD)state + 120), &v48);
}
else
{
v29 = v28 / 64;
v51[v29] &= ~(1LL << (v28 % 64));
v50[v29] |= 1LL << (v28 % 64);
++v30;
}
}
}
if ( verbose && v30 > 0 )
break;
if ( v30 > 0 )
{
LABEL_37:
while ( 1 )
{
v41 = FD_FFSandC((unsigned int)v28, maxfd, v50);
if ( !v41 )
break;
v42 = create_tx_tcp(v43, a4);
state[40 * v42 + 34] = v41;
if ( v42 < 0 )
{
fwrite("Unable to open connection!\n", 1uLL, 0x1BuLL, stderr);
}
else
{
if ( maxfd < v42 )
maxfd = v42;
v40 = (int)objsize(&objsize);
if ( v40 <= 0 )
v40 = 1;
state[40 * v42 + 9] = v40;
state[40 * v42 + 23] = 0;
v54[v42 / 64] |= 1LL << (v42 % 64);
}
v28 = v41 + 1;
}
}
}
v31 = FD_POP(maxfd, v54);
v32 = FD_POP(maxfd, v53) + v31;
v33 = FD_POP(maxfd, v52) + v32;
v34 = FD_POP(maxfd, v51) + v33;
v35 = (unsigned int)FD_POP(maxfd, v50) + v34;
v36 = (unsigned int)FD_POP(maxfd, v50);
v37 = (unsigned int)FD_POP(maxfd, v51);
v38 = (unsigned int)FD_POP(maxfd, v52);
v45 = FD_POP(maxfd, v53);
v39 = FD_POP(maxfd, v54);
fprintf(
stdout,
"%d.%06d %d %d %d %d %d (%d)\n",
LODWORD(tv.tv_sec),
LODWORD(tv.tv_usec),
v39,
v45,
v38,
v37,
v36,
v35);
goto LABEL_37;
}

canonical_decompiled_code:
void __fastcall __noreturn func4(int a1, __int64 a2, int a3, unsigned int a4)
{
int i; // er13
__int64 v6; // rbp
double v7; // xmm0_8
__int64 v8; // rdx
int v9; // eax
int v10; // eax
int v11; // ebx
double v12; // r13
int v13; // eax
signed int v14; // eax
__int64 v15; // rdi
int v16; // eax
int v17; // ebx
__int64 v18; // r13
__int64 v19; // rdx
char *v20; // rbp
int v21; // er13
int v22; // er15
int v23; // er14
int v24; // edx
double v25; // rbp
int v26; // eax
__int64 j; // rdi
signed int v28; // ebx
__int64 v29; // rax
int v30; // er13
int v31; // ebp
int v32; // ebp
int v33; // ebp
int v34; // ebp
__int64 v35; // rbp
__int64 v36; // r13
__int64 v37; // r14
__int64 v38; // r15
unsigned int v39; // eax
int v40; // edx
unsigned int v41; // ebx
int v42; // ebp
__int64 v43; // [rsp+0h] [rbp-2F8h]
unsigned int v45; // [rsp+Ch] [rbp-2ECh]
struct timeval timeout; // [rsp+10h] [rbp-2E8h] BYREF
struct timeval tv; // [rsp+20h] [rbp-2D8h] BYREF
__int64 v48; // [rsp+30h] [rbp-2C8h] BYREF
__int64 v49; // [rsp+38h] [rbp-2C0h]
__int64 v50[16]; // [rsp+40h] [rbp-2B8h] BYREF
__int64 v51[16]; // [rsp+C0h] [rbp-238h] BYREF
__int64 v52[16]; // [rsp+140h] [rbp-1B8h] BYREF
char v53[128]; // [rsp+1C0h] [rbp-138h] BYREF
__int64 v54[23]; // [rsp+240h] [rbp-B8h] BYREF

v48 = 0LL;
v49 = 0LL;
v43 = host2ipaddr(a2);
memset(v54, 0, 0x80uLL);
memset(v53, 0, sizeof(v53));
memset(v52, 0, sizeof(v52));
memset(v51, 0, sizeof(v51));
memset(v50, 0, sizeof(v50));
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
v10 = create_tx_tcp(v43, i % a3 + a4);
v11 = v10;
if ( v10 < 0 )
{
fwrite("Unable to open connection!\n", 1uLL, 0x1BuLL, stderr);
exit(-1);
}
if ( maxfd < v10 )
maxfd = v10;
v6 = 4LL * v10;
state[40 * v10 + 34] = v10;
state[8 * v6 + 35 + 8 * v10] = (int)objperpage(&objperpage);
v7 = objsize(&objsize);
v8 = 8 * (v6 + v11);
v9 = (int)v7;
if ( (int)v7 <= 0 )
v9 = 1;
state[v8 + 9] = v9;
state[v8 + 11] = 0;
state[v8 + 10] = 0;
state[v8 + 23] = 0;
v54[v11 / 64] |= 1LL << (v11 % 64);
timeout.tv_usec = (int)(drand48() * 10000.0);
select(0, &fds_zero, &fds_zero, &fds_zero, &timeout);
}
}
while ( 1 )
{
send_request(v54, v53);
v15 = 0LL;
if ( (int)sink_data(v53, v52) > 0 )
{
while ( 1 )
{
v16 = FD_FFSandC(v15, maxfd, v52);
v17 = v16;
if ( !v16 )
break;
v18 = 4LL * v16;
v19 = 40LL * v16;
v20 = (char *)&state[v19 + 30];
tvsub(&timeout, v20, &state[v19 + 26]);
v21 = state[8 * v17 + 23 + 8 * v18];
v22 = timeout.tv_sec;
v23 = timeout.tv_usec;
gettimeofday(&tv, 0LL);
if ( verbose )
fprintf(
stderr,
"%d.%06d Finished with %d after %d bytes. %ld.%03lds = %.4f Mb/s.\n",
LODWORD(tv.tv_sec),
LODWORD(tv.tv_usec),
(unsigned int)v17,
state[40 * v17 + 23],
timeout.tv_sec,
timeout.tv_usec / 1000,
(double)v21 * 8.0 / ((double)v22 * 1000000.0 + (double)v23) / scalar);
close(v17);
state[40 * v17 + 8] = 0;
v24 = state[40 * v17 + 35] - 1;
state[40 * v17 + 35] = v24;
if ( v24 <= 0 )
{
v12 = interpage(&interpage);
state[40 * v17 + 35] = (int)objperpage(&objperpage);
}
else
{
v12 = interobj(&interobj);
}
v13 = (int)(v12 * scalar);
v48 = v13;
v49 = (int)((v12 * scalar - (double)v13) * 1000000.0);
tvadd(&state[40 * state[40 * v17 + 34] + 36], v20, &v48);
if ( verbose )
printf("(%d): time_us %d.%06d opp %d\n", 433LL, (unsigned int)v48, (unsigned int)v49, state[40 * v17 + 35]);
v52[v17 / 64] &= ~(1LL << (v17 % 64));
v14 = state[40 * v17 + 34];
v51[v14 / 64] |= 1LL << (v14 % 64);
v15 = (unsigned int)(v17 + 1);
}
}
v30 = 0;
for ( j = 0LL; ; j = (unsigned int)(v28 + 1) )
{
v28 = FD_FFS(j, maxfd, v51);
if ( !v28 )
break;
gettimeofday(&tv, 0LL);
if ( (unsigned int)tveqless(&state[40 * v28 + 36], &tv) )
{
if ( (int)state[40 * v28 + 35] <= 0 )
{
v25 = interpage(&interpage);
state[35] = (int)objperpage(&objperpage);
v26 = (int)(v25 * scalar);
v48 = v26;
v49 = (int)((v25 * scalar - (double)v26) * 1000000.0);
tvadd(&state[40 * state[34] + 36], (unsigned int)((_DWORD)state + 120), &v48);
}
else
{
v29 = v28 / 64;
v51[v29] &= ~(1LL << (v28 % 64));
v50[v29] |= 1LL << (v28 % 64);
++v30;
}
}
}
if ( verbose && v30 > 0 )
break;
if ( v30 > 0 )
{
LABEL_37:
while ( 1 )
{
v41 = FD_FFSandC((unsigned int)v28, maxfd, v50);
if ( !v41 )
break;
v42 = create_tx_tcp(v43, a4);
state[40 * v42 + 34] = v41;
if ( v42 < 0 )
{
fwrite("Unable to open connection!\n", 1uLL, 0x1BuLL, stderr);
}
else
{
if ( maxfd < v42 )
maxfd = v42;
v40 = (int)objsize(&objsize);
if ( v40 <= 0 )
v40 = 1;
state[40 * v42 + 9] = v40;
state[40 * v42 + 23] = 0;
v54[v42 / 64] |= 1LL << (v42 % 64);
}
v28 = v41 + 1;
}
}
}
v31 = FD_POP(maxfd, v54);
v32 = FD_POP(maxfd, v53) + v31;
v33 = FD_POP(maxfd, v52) + v32;
v34 = FD_POP(maxfd, v51) + v33;
v35 = (unsigned int)FD_POP(maxfd, v50) + v34;
v36 = (unsigned int)FD_POP(maxfd, v50);
v37 = (unsigned int)FD_POP(maxfd, v51);
v38 = (unsigned int)FD_POP(maxfd, v52);
v45 = FD_POP(maxfd, v53);
v39 = FD_POP(maxfd, v54);
fprintf(
stdout,
"%d.%06d %d %d %d %d %d (%d)\n",
LODWORD(tv.tv_sec),
LODWORD(tv.tv_usec),
v39,
v45,
v38,
v37,
v36,
v35);
goto LABEL_37;
}

original_code:
void
surge_client(int n, char *host, int num_ports, int base_rx_port)
{
    int i;
    fd_set fds_new, fds_active, fds_finished, ids_sleeping, ids_want_to_run;
    unsigned long ipaddr;
    double tmbs=0;
    double time_us;
    struct timeval next_start_time = {0,0};
    struct timeval current_time;
    ipaddr = host2ipaddr(host);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_new)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_active)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_finished)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&ids_sleeping)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&ids_want_to_run)->__fds_bits)[0]) : "memory"); } while (0);
    for(i=0; i<n; i++)
    {
        int fd;
        struct timeval tp={ 0, 0 };
        fd = create_tx_tcp(ipaddr, base_rx_port+(i%num_ports));
        if(fd < 0)
        {
            fprintf(stderr,"Unable to open connection!\n");
            exit(-1);
        }
        if(fd > maxfd) maxfd = fd;
        state[fd].client_id = fd;
        state[fd].object_count = objperpage.function(&objperpage);
        state[fd].tx_target = (((G_os = objsize.function(&objsize)) < 1) ? 1 : G_os);
        state[fd].tx_sent = 0;
        state[fd].tx_pkts = 0;
        state[fd].rx_rcvd = 0;
        ((void) (((&fds_new)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        tp.tv_usec = (int)(drand48()*10000.0);
        select(0, &fds_zero, &fds_zero, &fds_zero, &tp);
    }
    while(1)
    {
        int s, fd, client_id, sink_data_rc, want_to_run_rc=0;
        struct timeval tdiff;
        send_request(&fds_new, &fds_active);
        sink_data_rc = sink_data(&fds_active, &fds_finished);
        for(s=0;
            (sink_data_rc>0) && (fd = FD_FFSandC(s, maxfd, &fds_finished));
            s = fd+1)
        {
            double mbs;
            tvsub(&tdiff, &state[fd].rx_stop, &state[fd].rx_start);
            mbs = (double)(8.0*state[fd].rx_rcvd) /
                (double)(tdiff.tv_sec*1.e6 + tdiff.tv_usec);
            tmbs += mbs;
            gettimeofday(&current_time,((void *)0));
            if(verbose)
                fprintf(stderr,
                        "%d.%06d Finished with %d after %d bytes. "
                        "%ld.%03lds = %.4f Mb/s.\n",
                        (int)current_time.tv_sec,(int)current_time.tv_usec,
                        fd, state[fd].rx_rcvd,
                        (long int)tdiff.tv_sec, (long int)tdiff.tv_usec/1000,
                        mbs/scalar);
            close(fd);
            state[fd].open = 0;
            state[fd].object_count--;
            if(state[fd].object_count > 0)
                time_us = interobj.function(&interobj);
            else
            {
                time_us = interpage.function(&interpage);
                state[fd].object_count = objperpage.function(&objperpage);
            }
            time_us *= scalar;
            next_start_time.tv_sec = (int) time_us;
            next_start_time.tv_usec = (int)
                ((time_us - (double)next_start_time.tv_sec)
                 * 1e6 );
            tvadd(&state[state[fd].client_id].next_start_time,&state[fd].rx_stop,
                  &next_start_time);
            if(verbose)
                printf("(%d): time_us %d.%06d opp %d\n",433,
                       (int)next_start_time.tv_sec,
                       (int)next_start_time.tv_usec,
                       state[fd].object_count);
            ((void) (((&fds_finished)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
            ((void) (((&ids_sleeping)->__fds_bits)[((state[fd].client_id) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((state[fd].client_id) % (8 * (int) sizeof (__fd_mask)))))));
        }
        for(s=0;(client_id = FD_FFS(s, maxfd, &ids_sleeping));
            s = client_id+1)
        {
            gettimeofday(&current_time,((void *)0));
            if(tveqless(&state[client_id].next_start_time,&current_time))
            {
                if(state[client_id].object_count > 0)
                {
                    ((void) (((&ids_sleeping)->__fds_bits)[((client_id) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((client_id) % (8 * (int) sizeof (__fd_mask)))))));
                    ((void) (((&ids_want_to_run)->__fds_bits)[((client_id) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((client_id) % (8 * (int) sizeof (__fd_mask)))))));
                    want_to_run_rc++;
                }
                else
                {
                    time_us = interpage.function(&interpage);
                    state[fd].object_count = objperpage.function(&objperpage);
                    time_us *= scalar;
                    next_start_time.tv_sec = (int) time_us;
                    next_start_time.tv_usec = (int)
                        ((time_us - (double)next_start_time.tv_sec)
                         * 1e6 );
                    tvadd(&state[state[fd].client_id].next_start_time,
                          &state[fd].rx_stop,
                          &next_start_time);
                }
            }
        }
        if(verbose && want_to_run_rc>0)
        {
            fprintf(stdout,"%d.%06d %d %d %d %d %d (%d)\n",
                    (int)current_time.tv_sec,(int)current_time.tv_usec,
                    FD_POP(maxfd,&fds_new),
                    FD_POP(maxfd,&fds_active),
                    FD_POP(maxfd,&fds_finished),
                    FD_POP(maxfd,&ids_sleeping),
                    FD_POP(maxfd,&ids_want_to_run),
                    (FD_POP(maxfd,&fds_new)+
                     FD_POP(maxfd,&fds_active)+
                     FD_POP(maxfd,&fds_finished)+
                     FD_POP(maxfd,&ids_sleeping)+
                     FD_POP(maxfd,&ids_want_to_run)));
        }
        for(s = 0;
            ((want_to_run_rc>0)
             && (client_id = FD_FFSandC(s, maxfd, &ids_want_to_run)));
            s = client_id+1)
        {
            int new_fd;
            new_fd = create_tx_tcp(ipaddr, base_rx_port+(fd%num_ports));
            state[new_fd].client_id=client_id;
            if(new_fd < 0)
            {
                fprintf(stderr,"Unable to open connection!\n");
                continue;
            }
            if(new_fd > maxfd) maxfd = new_fd;
            state[new_fd].tx_target = (((G_os = objsize.function(&objsize)) < 1) ? 1 : G_os);
            state[new_fd].rx_rcvd = 0;
            ((void) (((&fds_new)->__fds_bits)[((new_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((new_fd) % (8 * (int) sizeof (__fd_mask)))))));
        }
    }
}

canonical_original_code:
void surge_client(int n, char *host, int num_ports, int base_rx_port)
{
    int i;
    struct fd_set fds_new; struct fd_set fds_active; struct fd_set fds_finished; struct fd_set ids_sleeping; struct fd_set ids_want_to_run;
    unsigned long ipaddr;
    double tmbs = 0;
    double time_us;
    struct timeval next_start_time = {0,0};
    struct timeval current_time;
    ipaddr = host2ipaddr(host);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_new)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_active)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_finished)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&ids_sleeping)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&ids_want_to_run)->__fds_bits)[0]) : "memory"); } while (0);
    for(i=0; i<n; i++)
    {
        int fd;
        struct timeval tp = { 0, 0 };
        fd = create_tx_tcp(ipaddr, base_rx_port+(i%num_ports));
        if(fd < 0)
        {
            fprintf(stderr,"Unable to open connection!\n");
            exit(-1);
        }
        if(fd > maxfd) maxfd = fd;
        state[fd].client_id = fd;
        state[fd].object_count = objperpage.function(&objperpage);
        state[fd].tx_target = (((G_os = objsize.function(&objsize)) < 1) ? 1 : G_os);
        state[fd].tx_sent = 0;
        state[fd].tx_pkts = 0;
        state[fd].rx_rcvd = 0;
        ((void) (((&fds_new)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        tp.tv_usec = (int)(drand48()*10000.0);
        select(0, &fds_zero, &fds_zero, &fds_zero, &tp);
    }
    while(1)
    {
        int s; int fd; int client_id; int sink_data_rc; int want_to_run_rc = 0;
        struct timeval tdiff;
        send_request(&fds_new, &fds_active);
        sink_data_rc = sink_data(&fds_active, &fds_finished);
        for(s=0;
            (sink_data_rc>0) && (fd = FD_FFSandC(s, maxfd, &fds_finished));
            s = fd+1)
        {
            double mbs;
            tvsub(&tdiff, &state[fd].rx_stop, &state[fd].rx_start);
            mbs = (double)(8.0*state[fd].rx_rcvd) /
                (double)(tdiff.tv_sec*1.e6 + tdiff.tv_usec);
            tmbs += mbs;
            gettimeofday(&current_time,((void *)0));
            if(verbose)
                fprintf(stderr,
                        "%d.%06d Finished with %d after %d bytes. "
                        "%ld.%03lds = %.4f Mb/s.\n",
                        (int)current_time.tv_sec,(int)current_time.tv_usec,
                        fd, state[fd].rx_rcvd,
                        (long)tdiff.tv_sec, (long)tdiff.tv_usec/1000,
                        mbs/scalar);
            close(fd);
            state[fd].open = 0;
            state[fd].object_count--;
            if(state[fd].object_count > 0)
                time_us = interobj.function(&interobj);
            else
            {
                time_us = interpage.function(&interpage);
                state[fd].object_count = objperpage.function(&objperpage);
            }
            time_us *= scalar;
            next_start_time.tv_sec = (int) time_us;
            next_start_time.tv_usec = (int)
                ((time_us - (double)next_start_time.tv_sec)
                 * 1e6 );
            tvadd(&state[state[fd].client_id].next_start_time,&state[fd].rx_stop,
                  &next_start_time);
            if(verbose)
                printf("(%d): time_us %d.%06d opp %d\n",433,
                       (int)next_start_time.tv_sec,
                       (int)next_start_time.tv_usec,
                       state[fd].object_count);
            ((void) (((&fds_finished)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
            ((void) (((&ids_sleeping)->__fds_bits)[((state[fd].client_id) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((state[fd].client_id) % (8 * (int) sizeof (__fd_mask)))))));
        }
        for(s=0;(client_id = FD_FFS(s, maxfd, &ids_sleeping));
            s = client_id+1)
        {
            gettimeofday(&current_time,((void *)0));
            if(tveqless(&state[client_id].next_start_time,&current_time))
            {
                if(state[client_id].object_count > 0)
                {
                    ((void) (((&ids_sleeping)->__fds_bits)[((client_id) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((client_id) % (8 * (int) sizeof (__fd_mask)))))));
                    ((void) (((&ids_want_to_run)->__fds_bits)[((client_id) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((client_id) % (8 * (int) sizeof (__fd_mask)))))));
                    want_to_run_rc++;
                }
                else
                {
                    time_us = interpage.function(&interpage);
                    state[fd].object_count = objperpage.function(&objperpage);
                    time_us *= scalar;
                    next_start_time.tv_sec = (int) time_us;
                    next_start_time.tv_usec = (int)
                        ((time_us - (double)next_start_time.tv_sec)
                         * 1e6 );
                    tvadd(&state[state[fd].client_id].next_start_time,
                          &state[fd].rx_stop,
                          &next_start_time);
                }
            }
        }
        if(verbose && want_to_run_rc>0)
        {
            fprintf(stdout,"%d.%06d %d %d %d %d %d (%d)\n",
                    (int)current_time.tv_sec,(int)current_time.tv_usec,
                    FD_POP(maxfd,&fds_new),
                    FD_POP(maxfd,&fds_active),
                    FD_POP(maxfd,&fds_finished),
                    FD_POP(maxfd,&ids_sleeping),
                    FD_POP(maxfd,&ids_want_to_run),
                    (FD_POP(maxfd,&fds_new)+
                     FD_POP(maxfd,&fds_active)+
                     FD_POP(maxfd,&fds_finished)+
                     FD_POP(maxfd,&ids_sleeping)+
                     FD_POP(maxfd,&ids_want_to_run)));
        }
        for(s = 0;
            ((want_to_run_rc>0)
             && (client_id = FD_FFSandC(s, maxfd, &ids_want_to_run)));
            s = client_id+1)
        {
            int new_fd;
            new_fd = create_tx_tcp(ipaddr, base_rx_port+(fd%num_ports));
            state[new_fd].client_id=client_id;
            if(new_fd < 0)
            {
                fprintf(stderr,"Unable to open connection!\n");
                continue;
            }
            if(new_fd > maxfd) maxfd = new_fd;
            state[new_fd].tx_target = (((G_os = objsize.function(&objsize)) < 1) ? 1 : G_os);
            state[new_fd].rx_rcvd = 0;
            ((void) (((&fds_new)->__fds_bits)[((new_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((new_fd) % (8 * (int) sizeof (__fd_mask)))))));
        }
    }
}

variable_types: n int

variable_types:
host
char *

variable_types: i int

variable_types:
ipaddr
unsigned long

variable_types: tmbs double

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

variable_types: fd int

variable_types: s int

variable_types: mbs double


decompiled_code:
void __fastcall __noreturn continuous_client(int a1, int a2, __int64 a3, int a4, int a5)
{
__int64 v7; // r14
int i; // ebx
__int64 v9; // rsi
int v10; // eax
__int64 v11; // rdi
int v12; // eax
int v13; // ebx
__int64 v14; // rbp
__int64 v15; // rbp
int v16; // eax
struct timeval timeout; // [rsp+10h] [rbp-1C8h] BYREF
__int64 v19[16]; // [rsp+20h] [rbp-1B8h] BYREF
char v20[128]; // [rsp+A0h] [rbp-138h] BYREF
__int64 v21[23]; // [rsp+120h] [rbp-B8h] BYREF

v7 = host2ipaddr(a3);
memset(v21, 0, 0x80uLL);
memset(v20, 0, sizeof(v20));
memset(v19, 0, sizeof(v19));
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v10 = create_tx_tcp(v7, (unsigned int)(i % a4 + a5));
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
if ( v10 < 0 )
{
puts("Unable to open connection!");
exit(-1);
}
if ( maxfd < v10 )
maxfd = v10;
state[40 * v10 + 9] = a2;
state[40 * v10 + 11] = 0;
v9 = 40LL * v10;
state[v9 + 10] = 0;
state[v9 + 23] = 0;
v21[v10 >> 6] |= 1LL << (v10 % 64);
timeout.tv_usec = rand() % 10000;
select(0, &fds_zero, &fds_zero, &fds_zero, &timeout);
}
}
while ( 1 )
{
do
{
send_request(v21, v20);
v11 = 0LL;
}
while ( (int)sink_data(v20, v19) <= 0 );
while ( 1 )
{
v12 = FD_FFSandC(v11, maxfd, v19);
v13 = v12;
if ( !v12 )
break;
v14 = 4LL * v12;
tvsub(&timeout, &state[40 * v12 + 30], &state[40 * v12 + 26]);
v15 = 8 * (v13 + v14);
fprintf(
stderr,
"Finished with %d after %d bytes. %ld.%03lds = %.4f Mb/s.\n",
(unsigned int)v13,
(unsigned int)state[v15 + 23],
timeout.tv_sec,
timeout.tv_usec / 1000,
(double)(int)state[v15 + 23]
* 8.0
/ ((double)SLODWORD(timeout.tv_sec) * 1000000.0 + (double)SLODWORD(timeout.tv_usec))
/ scalar);
close(v13);
state[v15 + 8] = 0;
v19[v13 / 64] &= __ROL8__(-2LL, v13 % 64);
v16 = create_tx_tcp(v7, (unsigned int)(v13 % a4 + a5));
if ( v16 < 0 )
{
fwrite("Unable to open connection!\n", 1uLL, 0x1BuLL, stderr);
}
else
{
if ( maxfd < v16 )
maxfd = v16;
state[40 * v16 + 23] = 0;
v21[v16 >> 6] |= 1LL << (v16 % 64);
}
v11 = (unsigned int)(v13 + 1);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1, int a2, __int64 a3, int a4, int a5)
{
__int64 v7; // r14
int i; // ebx
__int64 v9; // rsi
int v10; // eax
__int64 v11; // rdi
int v12; // eax
int v13; // ebx
__int64 v14; // rbp
__int64 v15; // rbp
int v16; // eax
struct timeval timeout; // [rsp+10h] [rbp-1C8h] BYREF
__int64 v19[16]; // [rsp+20h] [rbp-1B8h] BYREF
char v20[128]; // [rsp+A0h] [rbp-138h] BYREF
__int64 v21[23]; // [rsp+120h] [rbp-B8h] BYREF

v7 = host2ipaddr(a3);
memset(v21, 0, 0x80uLL);
memset(v20, 0, sizeof(v20));
memset(v19, 0, sizeof(v19));
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v10 = create_tx_tcp(v7, (unsigned int)(i % a4 + a5));
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
if ( v10 < 0 )
{
puts("Unable to open connection!");
exit(-1);
}
if ( maxfd < v10 )
maxfd = v10;
state[40 * v10 + 9] = a2;
state[40 * v10 + 11] = 0;
v9 = 40LL * v10;
state[v9 + 10] = 0;
state[v9 + 23] = 0;
v21[v10 >> 6] |= 1LL << (v10 % 64);
timeout.tv_usec = rand() % 10000;
select(0, &fds_zero, &fds_zero, &fds_zero, &timeout);
}
}
while ( 1 )
{
do
{
send_request(v21, v20);
v11 = 0LL;
}
while ( (int)sink_data(v20, v19) <= 0 );
while ( 1 )
{
v12 = FD_FFSandC(v11, maxfd, v19);
v13 = v12;
if ( !v12 )
break;
v14 = 4LL * v12;
tvsub(&timeout, &state[40 * v12 + 30], &state[40 * v12 + 26]);
v15 = 8 * (v13 + v14);
fprintf(
stderr,
"Finished with %d after %d bytes. %ld.%03lds = %.4f Mb/s.\n",
(unsigned int)v13,
(unsigned int)state[v15 + 23],
timeout.tv_sec,
timeout.tv_usec / 1000,
(double)(int)state[v15 + 23]
* 8.0
/ ((double)SLODWORD(timeout.tv_sec) * 1000000.0 + (double)SLODWORD(timeout.tv_usec))
/ scalar);
close(v13);
state[v15 + 8] = 0;
v19[v13 / 64] &= __ROL8__(-2LL, v13 % 64);
v16 = create_tx_tcp(v7, (unsigned int)(v13 % a4 + a5));
if ( v16 < 0 )
{
fwrite("Unable to open connection!\n", 1uLL, 0x1BuLL, stderr);
}
else
{
if ( maxfd < v16 )
maxfd = v16;
state[40 * v16 + 23] = 0;
v21[v16 >> 6] |= 1LL << (v16 % 64);
}
v11 = (unsigned int)(v13 + 1);
}
}
}

original_code:
void
continuous_client(int n, int bytes, char *host, int num_ports, int base_rx_port)
{
    int i;
    fd_set fds_new, fds_active, fds_finished;
    unsigned long ipaddr;
    double tmbs=0;
    ipaddr = host2ipaddr(host);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_new)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_active)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_finished)->__fds_bits)[0]) : "memory"); } while (0);
    for(i=0; i<n; i++)
    {
        int fd = create_tx_tcp(ipaddr, base_rx_port+(i%num_ports));
        struct timeval tp={ 0, 0 };
        if(fd < 0)
        {
            printf("Unable to open connection!\n");
            exit(-1);
        }
        if(fd > maxfd) maxfd = fd;
        state[fd].tx_target = bytes;
        state[fd].tx_sent = 0;
        state[fd].tx_pkts = 0;
        state[fd].rx_rcvd = 0;
        ((void) (((&fds_new)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        tp.tv_usec = rand()%10000;
        select(0, &fds_zero, &fds_zero, &fds_zero, &tp);
    }
    while(1)
    {
        int s, fd, rc;
        struct timeval tdiff;
        send_request(&fds_new, &fds_active);
        rc = sink_data(&fds_active, &fds_finished);
        for(s=0;
            (rc>0) && (fd = FD_FFSandC(s, maxfd, &fds_finished));
            s = fd+1)
        {
            double mbs;
            int new_fd;
            tvsub(&tdiff, &state[fd].rx_stop, &state[fd].rx_start);
            mbs = (double)(8.0*state[fd].rx_rcvd)
                  / (double)(tdiff.tv_sec*1.e6 + tdiff.tv_usec);
            tmbs += mbs;
            fprintf(stderr,
                    "Finished with %d after %d bytes. %ld.%03lds = %.4f "
                    "Mb/s.\n",
                    fd, state[fd].rx_rcvd,
                    (long int)tdiff.tv_sec, (long int)tdiff.tv_usec/1000,
                    mbs/scalar);
            close(fd);
            state[fd].open = 0;
            ((void) (((&fds_finished)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
            new_fd = create_tx_tcp(ipaddr, base_rx_port+(fd%num_ports));
            if(new_fd < 0)
            {
                fprintf(stderr, "Unable to open connection!\n");
                continue;
            }
            if(new_fd > maxfd) maxfd = new_fd;
            state[new_fd].rx_rcvd = 0;
            ((void) (((&fds_new)->__fds_bits)[((new_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((new_fd) % (8 * (int) sizeof (__fd_mask)))))));
        }
    }
}

canonical_original_code:
void continuous_client(int n, int bytes, char *host, int num_ports, int base_rx_port)
{
    int i;
    struct fd_set fds_new; struct fd_set fds_active; struct fd_set fds_finished;
    unsigned long ipaddr;
    double tmbs = 0;
    ipaddr = host2ipaddr(host);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_new)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_active)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_finished)->__fds_bits)[0]) : "memory"); } while (0);
    for(i=0; i<n; i++)
    {
        int fd = create_tx_tcp(ipaddr, base_rx_port+(i%num_ports));
        struct timeval tp = { 0, 0 };
        if(fd < 0)
        {
            printf("Unable to open connection!\n");
            exit(-1);
        }
        if(fd > maxfd) maxfd = fd;
        state[fd].tx_target = bytes;
        state[fd].tx_sent = 0;
        state[fd].tx_pkts = 0;
        state[fd].rx_rcvd = 0;
        ((void) (((&fds_new)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        tp.tv_usec = rand()%10000;
        select(0, &fds_zero, &fds_zero, &fds_zero, &tp);
    }
    while(1)
    {
        int s; int fd; int rc;
        struct timeval tdiff;
        send_request(&fds_new, &fds_active);
        rc = sink_data(&fds_active, &fds_finished);
        for(s=0;
            (rc>0) && (fd = FD_FFSandC(s, maxfd, &fds_finished));
            s = fd+1)
        {
            double mbs;
            int new_fd;
            tvsub(&tdiff, &state[fd].rx_stop, &state[fd].rx_start);
            mbs = (double)(8.0*state[fd].rx_rcvd)
                  / (double)(tdiff.tv_sec*1.e6 + tdiff.tv_usec);
            tmbs += mbs;
            fprintf(stderr,
                    "Finished with %d after %d bytes. %ld.%03lds = %.4f "
                    "Mb/s.\n",
                    fd, state[fd].rx_rcvd,
                    (long)tdiff.tv_sec, (long)tdiff.tv_usec/1000,
                    mbs/scalar);
            close(fd);
            state[fd].open = 0;
            ((void) (((&fds_finished)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
            new_fd = create_tx_tcp(ipaddr, base_rx_port+(fd%num_ports));
            if(new_fd < 0)
            {
                fprintf(stderr, "Unable to open connection!\n");
                continue;
            }
            if(new_fd > maxfd) maxfd = new_fd;
            state[new_fd].rx_rcvd = 0;
            ((void) (((&fds_new)->__fds_bits)[((new_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((new_fd) % (8 * (int) sizeof (__fd_mask)))))));
        }
    }
}

variable_types: bytes int

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


decompiled_code:
int __fastcall simple_client(int a1, unsigned int a2, __int64 a3, int a4, int a5)
{
__int64 v8; // r13
int i; // ebx
__int64 v10; // rsi
int v11; // eax
__int64 v12; // r13
double v13; // xmm0_8
__int64 v14; // rdi
int v15; // ebx
double v18; // [rsp+8h] [rbp-1D0h]
__int64 v19; // [rsp+10h] [rbp-1C8h] BYREF
__int64 v20; // [rsp+18h] [rbp-1C0h]
__int64 v21[16]; // [rsp+20h] [rbp-1B8h] BYREF
char v22[128]; // [rsp+A0h] [rbp-138h] BYREF
__int64 v23[23]; // [rsp+120h] [rbp-B8h] BYREF

v8 = host2ipaddr(a3);
memset(v23, 0, 0x80uLL);
memset(v22, 0, sizeof(v22));
memset(v21, 0, sizeof(v21));
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v11 = create_tx_tcp(v8, (unsigned int)(i % a4 + a5));
if ( v11 < 0 )
{
puts("Unable to open connection!");
exit(-1);
}
if ( maxfd < v11 )
maxfd = v11;
state[40 * v11 + 9] = a2;
v10 = 40LL * v11;
state[v10 + 11] = 0;
state[v10 + 10] = 0;
v23[v11 >> 6] |= 1LL << (v11 % 64);
}
}
v18 = 0.0;
LODWORD(v12) = -1;
do
{
send_request(v23, v22);
v14 = 0LL;
if ( (int)sink_data(v22, v21) > 0 )
{
while ( 1 )
{
v15 = FD_FFSandC(v14, maxfd, v21);
if ( !v15 )
break;
v12 = (unsigned int)FD_POP(maxfd, v22);
tvsub(&v19, &state[40 * v15 + 30], &state[40 * v15 + 26]);
v13 = (double)(int)state[40 * v15 + 23] * 8.0 / ((double)(int)v19 * 1000000.0 + (double)(int)v20);
v18 = v18 + v13;
fprintf(
stderr,
"Finished with %d after %d bytes (%d pkts). %ld.%03lds = %.4f Mb/s. %d active\n",
(unsigned int)v15,
state[40 * v15 + 23],
state[40 * v15 + 22],
v19,
v20 / 1000,
v13 / scalar,
v12);
close(v15);
state[40 * v15 + 8] = 0;
v21[v15 / 64] &= __ROL8__(-2LL, v15 % 64);
v14 = (unsigned int)(v15 + 1);
}
}
}
while ( (_DWORD)v12 );
return fprintf(
stderr,
"Rough total b/w estimate was %.2f Mb/s, Average stream b/w was %.4f Mb/s\n",
v18,
v18 / (double)a1);
}

canonical_decompiled_code:
int __fastcall func0(int a1, unsigned int a2, __int64 a3, int a4, int a5)
{
__int64 v8; // r13
int i; // ebx
__int64 v10; // rsi
int v11; // eax
__int64 v12; // r13
double v13; // xmm0_8
__int64 v14; // rdi
int v15; // ebx
double v18; // [rsp+8h] [rbp-1D0h]
__int64 v19; // [rsp+10h] [rbp-1C8h] BYREF
__int64 v20; // [rsp+18h] [rbp-1C0h]
__int64 v21[16]; // [rsp+20h] [rbp-1B8h] BYREF
char v22[128]; // [rsp+A0h] [rbp-138h] BYREF
__int64 v23[23]; // [rsp+120h] [rbp-B8h] BYREF

v8 = host2ipaddr(a3);
memset(v23, 0, 0x80uLL);
memset(v22, 0, sizeof(v22));
memset(v21, 0, sizeof(v21));
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v11 = create_tx_tcp(v8, (unsigned int)(i % a4 + a5));
if ( v11 < 0 )
{
puts("Unable to open connection!");
exit(-1);
}
if ( maxfd < v11 )
maxfd = v11;
state[40 * v11 + 9] = a2;
v10 = 40LL * v11;
state[v10 + 11] = 0;
state[v10 + 10] = 0;
v23[v11 >> 6] |= 1LL << (v11 % 64);
}
}
v18 = 0.0;
LODWORD(v12) = -1;
do
{
send_request(v23, v22);
v14 = 0LL;
if ( (int)sink_data(v22, v21) > 0 )
{
while ( 1 )
{
v15 = FD_FFSandC(v14, maxfd, v21);
if ( !v15 )
break;
v12 = (unsigned int)FD_POP(maxfd, v22);
tvsub(&v19, &state[40 * v15 + 30], &state[40 * v15 + 26]);
v13 = (double)(int)state[40 * v15 + 23] * 8.0 / ((double)(int)v19 * 1000000.0 + (double)(int)v20);
v18 = v18 + v13;
fprintf(
stderr,
"Finished with %d after %d bytes (%d pkts). %ld.%03lds = %.4f Mb/s. %d active\n",
(unsigned int)v15,
state[40 * v15 + 23],
state[40 * v15 + 22],
v19,
v20 / 1000,
v13 / scalar,
v12);
close(v15);
state[40 * v15 + 8] = 0;
v21[v15 / 64] &= __ROL8__(-2LL, v15 % 64);
v14 = (unsigned int)(v15 + 1);
}
}
}
while ( (_DWORD)v12 );
return fprintf(
stderr,
"Rough total b/w estimate was %.2f Mb/s, Average stream b/w was %.4f Mb/s\n",
v18,
v18 / (double)a1);
}

original_code:
void
simple_client(int n, int bytes, char *host, int num_ports, int base_rx_port)
{
    int i, left;
    fd_set fds_new, fds_active, fds_finished;
    unsigned long ipaddr;
    double tmbs=0;
    ipaddr = host2ipaddr(host);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_new)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_active)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_finished)->__fds_bits)[0]) : "memory"); } while (0);
    for(i=0; i<n; i++)
    {
        int fd = create_tx_tcp(ipaddr, base_rx_port+(i%num_ports));
        if(fd < 0)
        {
            printf("Unable to open connection!\n");
            exit(-1);
        }
        if(fd > maxfd) maxfd = fd;
        state[fd].tx_target = bytes;
        state[fd].tx_sent = 0;
        state[fd].tx_pkts = 0;
        ((void) (((&fds_new)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    }
    left = -1;
    while(left)
    {
        int s, fd, rc;
        struct timeval tdiff;
        send_request(&fds_new, &fds_active);
        rc = sink_data(&fds_active, &fds_finished);
        for(s=0;
            (rc>0) && (fd = FD_FFSandC(s, maxfd, &fds_finished));
            s = fd+1)
        {
            double mbs;
            left = FD_POP(maxfd, &fds_active);
            tvsub(&tdiff, &state[fd].rx_stop, &state[fd].rx_start);
            mbs = (double)(8.0*state[fd].rx_rcvd) /
                (double)(tdiff.tv_sec*1.e6 + tdiff.tv_usec);
            tmbs += mbs;
            fprintf(stderr,
                    "Finished with %d after %d bytes (%d pkts). "
                    "%ld.%03lds = %.4f Mb/s. "
                    "%d active\n",
                    fd, state[fd].rx_rcvd, state[fd].rx_pkts,
                    (long int)tdiff.tv_sec, (long int)tdiff.tv_usec/1000,
                    mbs/scalar, left);
            close(fd);
            state[fd].open=0;
            ((void) (((&fds_finished)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        }
    }
    fprintf(stderr,
            "Rough total b/w estimate was %.2f Mb/s, "
            "Average stream b/w was %.4f Mb/s\n", tmbs, tmbs/n);
}

canonical_original_code:
void simple_client(int n, int bytes, char *host, int num_ports, int base_rx_port)
{
    int i; int left;
    struct fd_set fds_new; struct fd_set fds_active; struct fd_set fds_finished;
    unsigned long ipaddr;
    double tmbs = 0;
    ipaddr = host2ipaddr(host);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_new)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_active)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds_finished)->__fds_bits)[0]) : "memory"); } while (0);
    for(i=0; i<n; i++)
    {
        int fd = create_tx_tcp(ipaddr, base_rx_port+(i%num_ports));
        if(fd < 0)
        {
            printf("Unable to open connection!\n");
            exit(-1);
        }
        if(fd > maxfd) maxfd = fd;
        state[fd].tx_target = bytes;
        state[fd].tx_sent = 0;
        state[fd].tx_pkts = 0;
        ((void) (((&fds_new)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    }
    left = -1;
    while(left)
    {
        int s; int fd; int rc;
        struct timeval tdiff;
        send_request(&fds_new, &fds_active);
        rc = sink_data(&fds_active, &fds_finished);
        for(s=0;
            (rc>0) && (fd = FD_FFSandC(s, maxfd, &fds_finished));
            s = fd+1)
        {
            double mbs;
            left = FD_POP(maxfd, &fds_active);
            tvsub(&tdiff, &state[fd].rx_stop, &state[fd].rx_start);
            mbs = (double)(8.0*state[fd].rx_rcvd) /
                (double)(tdiff.tv_sec*1.e6 + tdiff.tv_usec);
            tmbs += mbs;
            fprintf(stderr,
                    "Finished with %d after %d bytes (%d pkts). "
                    "%ld.%03lds = %.4f Mb/s. "
                    "%d active\n",
                    fd, state[fd].rx_rcvd, state[fd].rx_pkts,
                    (long)tdiff.tv_sec, (long)tdiff.tv_usec/1000,
                    mbs/scalar, left);
            close(fd);
            state[fd].open=0;
            ((void) (((&fds_finished)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        }
    }
    fprintf(stderr,
            "Rough total b/w estimate was %.2f Mb/s, "
            "Average stream b/w was %.4f Mb/s\n", tmbs, tmbs/n);
}

variable_types: left int