InitSFX

repo: bradharding/doomretro

decompiled_code:
void *InitSFX()
{
__int64 v0; // rbx
int v1; // ebp
_QWORD *v2; // rdx
__int64 v3; // rax
void *result; // rax

s_sfx = (__int64)original_s_sfx;
numsfx = 700;
deh_soundnames_size = 701;
deh_soundnames = malloc(0x15E8uLL);
v0 = 8LL;
v1 = 1;
do
{
v3 = 0LL;
if ( *(_BYTE *)(s_sfx + 4 * v0) )
v3 = M_StringDuplicate();
v2 = deh_soundnames;
*(_QWORD *)((char *)deh_soundnames + v0) = v3;
++v1;
v0 += 8LL;
}
while ( numsfx > v1 );
*v2 = 0LL;
v2[numsfx] = 0LL;
result = calloc(numsfx, 1uLL);
sfx_state = result;
return result;
}

canonical_decompiled_code:
void *func0()
{
__int64 v0; // rbx
int v1; // ebp
_QWORD *v2; // rdx
__int64 v3; // rax
void *result; // rax

s_sfx = (__int64)original_s_sfx;
numsfx = 700;
deh_soundnames_size = 701;
deh_soundnames = malloc(0x15E8uLL);
v0 = 8LL;
v1 = 1;
do
{
v3 = 0LL;
if ( *(_BYTE *)(s_sfx + 4 * v0) )
v3 = M_StringDuplicate();
v2 = deh_soundnames;
*(_QWORD *)((char *)deh_soundnames + v0) = v3;
++v1;
v0 += 8LL;
}
while ( numsfx > v1 );
*v2 = 0LL;
v2[numsfx] = 0LL;
result = calloc(numsfx, 1uLL);
sfx_state = result;
return result;
}

original_code:
void InitSFX(void)
{
    s_sfx = original_s_sfx;
    numsfx = NUMSFX;
    deh_soundnames_size = numsfx + 1;
    deh_soundnames = malloc(deh_soundnames_size * sizeof(*deh_soundnames));
    for (int i = 1; i < numsfx; i++)
        deh_soundnames[i] = (*s_sfx[i].name1 ? M_StringDuplicate(s_sfx[i].name1) : ((void *)0));
    deh_soundnames[0] = ((void *)0);
    deh_soundnames[numsfx] = ((void *)0);
    sfx_state = calloc(numsfx, sizeof(*sfx_state));
}

canonical_original_code:
void InitSFX()
{
    s_sfx = original_s_sfx;
    numsfx = NUMSFX;
    deh_soundnames_size = numsfx + 1;
    deh_soundnames = malloc(deh_soundnames_size * sizeof(*deh_soundnames));
    for (int i = 1; i < numsfx; i++)
        deh_soundnames[i] = (*s_sfx[i].name1 ? M_StringDuplicate(s_sfx[i].name1) : ((void *)0));
    deh_soundnames[0] = ((void *)0);
    deh_soundnames[numsfx] = ((void *)0);
    sfx_state = calloc(numsfx, sizeof(*sfx_state));
}

return_type: void


FreeSFX

decompiled_code:
void FreeSFX()
{
__int64 v0; // rbp
__int64 v1; // rbx
void *v2; // rdi

if ( deh_soundnames_size > 1 )
{
v0 = 8LL * (unsigned int)deh_soundnames_size;
v1 = 8LL;
do
{
v2 = *(void **)((char *)deh_soundnames + v1);
if ( v2 )
free(v2);
v1 += 8LL;
}
while ( v1 != v0 );
}
free(deh_soundnames);
free(sfx_state);
}

canonical_decompiled_code:
void func1()
{
__int64 v0; // rbp
__int64 v1; // rbx
void *v2; // rdi

if ( deh_soundnames_size > 1 )
{
v0 = 8LL * (unsigned int)deh_soundnames_size;
v1 = 8LL;
do
{
v2 = *(void **)((char *)deh_soundnames + v1);
if ( v2 )
free(v2);
v1 += 8LL;
}
while ( v1 != v0 );
}
free(deh_soundnames);
free(sfx_state);
}

original_code:
void FreeSFX(void)
{
    for (int i = 1; i < deh_soundnames_size; i++)
        if (deh_soundnames[i])
            free(deh_soundnames[i]);
    free(deh_soundnames);
    free(sfx_state);
}

canonical_original_code:
void FreeSFX()
{
    for (int i = 1; i < deh_soundnames_size; i++)
        if (deh_soundnames[i])
            free(deh_soundnames[i]);
    free(deh_soundnames);
    free(sfx_state);
}

variable_types: i int


decompiled_code:
void __fastcall dsdh_EnsureSFXCapacity(int a1)
{
int v1; // ebp
int v2; // ecx
__int64 v3; // rax
__int64 v4; // rdx
int v5; // eax

v1 = numsfx;
if ( a1 >= numsfx )
{
while ( 1 )
{
v5 = 2 * v1;
numsfx = 2 * v1;
if ( first_allocation_0 )
{
first_allocation_0 = 0;
s_sfx = (__int64)malloc(32LL * v5);
memcpy((void *)s_sfx, original_s_sfx, 32LL * v1);
}
else
{
s_sfx = I_Realloc(s_sfx, 32LL * v5);
}
memset((void *)(s_sfx + 32LL * v1), 0, 32LL * (numsfx - v1));
sfx_state = (void *)I_Realloc(sfx_state, numsfx);
memset((char *)sfx_state + v1, 0, numsfx - v1);
v2 = numsfx;
if ( numsfx > v1 )
{
v3 = s_sfx + 32LL * v1;
v4 = s_sfx + 32 * ((unsigned int)(numsfx - 1 - v1) + (__int64)v1) + 32;
do
{
*(_DWORD *)(v3 + 24) = 127;
*(_DWORD *)(v3 + 28) = -1;
v3 += 32LL;
}
while ( v3 != v4 );
}
if ( a1 < v2 )
break;
v1 = v2;
}
}
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
int v1; // ebp
int v2; // ecx
__int64 v3; // rax
__int64 v4; // rdx
int v5; // eax

v1 = numsfx;
if ( a1 >= numsfx )
{
while ( 1 )
{
v5 = 2 * v1;
numsfx = 2 * v1;
if ( first_allocation_0 )
{
first_allocation_0 = 0;
s_sfx = (__int64)malloc(32LL * v5);
memcpy((void *)s_sfx, original_s_sfx, 32LL * v1);
}
else
{
s_sfx = I_Realloc(s_sfx, 32LL * v5);
}
memset((void *)(s_sfx + 32LL * v1), 0, 32LL * (numsfx - v1));
sfx_state = (void *)I_Realloc(sfx_state, numsfx);
memset((char *)sfx_state + v1, 0, numsfx - v1);
v2 = numsfx;
if ( numsfx > v1 )
{
v3 = s_sfx + 32LL * v1;
v4 = s_sfx + 32 * ((unsigned int)(numsfx - 1 - v1) + (__int64)v1) + 32;
do
{
*(_DWORD *)(v3 + 24) = 127;
*(_DWORD *)(v3 + 28) = -1;
v3 += 32LL;
}
while ( v3 != v4 );
}
if ( a1 < v2 )
break;
v1 = v2;
}
}
}

original_code:
void dsdh_EnsureSFXCapacity(const int limit)
{
    static int first_allocation = 1;
    while (limit >= numsfx)
    {
        const int old_numsfx = numsfx;
        numsfx *= 2;
        if (first_allocation)
        {
            first_allocation = 0;
            s_sfx = malloc(numsfx * sizeof(*s_sfx));
            memcpy(s_sfx, original_s_sfx, old_numsfx * sizeof(*s_sfx));
        }
        else
            s_sfx = I_Realloc(s_sfx, numsfx * sizeof(*s_sfx));
        memset(s_sfx + old_numsfx, 0, (numsfx - old_numsfx) * sizeof(*s_sfx));
        sfx_state = I_Realloc(sfx_state, numsfx * sizeof(*sfx_state));
        memset(sfx_state + old_numsfx, 0,
            (numsfx - old_numsfx) * sizeof(*sfx_state));
        for (int i = old_numsfx; i < numsfx; i++)
        {
            s_sfx[i].priority = 127;
            s_sfx[i].lumpnum = -1;
        }
    }
}

canonical_original_code:
void dsdh_EnsureSFXCapacity(int limit)
{
    static int first_allocation = 1;
    while (limit >= numsfx)
    {
        int old_numsfx = numsfx;
        numsfx *= 2;
        if (first_allocation)
        {
            first_allocation = 0;
            s_sfx = malloc(numsfx * sizeof(*s_sfx));
            memcpy(s_sfx, original_s_sfx, old_numsfx * sizeof(*s_sfx));
        }
        else
            s_sfx = I_Realloc(s_sfx, numsfx * sizeof(*s_sfx));
        memset(s_sfx + old_numsfx, 0, (numsfx - old_numsfx) * sizeof(*s_sfx));
        sfx_state = I_Realloc(sfx_state, numsfx * sizeof(*sfx_state));
        memset(sfx_state + old_numsfx, 0,
            (numsfx - old_numsfx) * sizeof(*sfx_state));
        for (int i = old_numsfx; i < numsfx; i++)
        {
            s_sfx[i].priority = 127;
            s_sfx[i].lumpnum = -1;
        }
    }
}

variable_types: limit int


decompiled_code:
__int64 __fastcall dsdh_GetDehSFXIndex(const char *a1, size_t a2)
{
const char *v2; // rbx
char *v3; // r14
char *v4; // rbp
int v5; // er12
unsigned int v6; // er13

if ( numsfx <= 1 )
return (unsigned int)-1;
v2 = (const char *)(s_sfx + 32);
v3 = (char *)sfx_state + (unsigned int)(numsfx - 2) + 2;
v4 = (char *)sfx_state + 1;
v5 = -(int)sfx_state;
do
{
v6 = v5 + (_DWORD)v4;
if ( *v2 && strlen(v2) == a2 && !strncasecmp(v2, a1, a2) && !*v4 )
{
*v4 = 1;
return v6;
}
v2 += 32;
++v4;
}
while ( v4 != v3 );
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, size_t a2)
{
const char *v2; // rbx
char *v3; // r14
char *v4; // rbp
int v5; // er12
unsigned int v6; // er13

if ( numsfx <= 1 )
return (unsigned int)-1;
v2 = (const char *)(s_sfx + 32);
v3 = (char *)sfx_state + (unsigned int)(numsfx - 2) + 2;
v4 = (char *)sfx_state + 1;
v5 = -(int)sfx_state;
do
{
v6 = v5 + (_DWORD)v4;
if ( *v2 && strlen(v2) == a2 && !strncasecmp(v2, a1, a2) && !*v4 )
{
*v4 = 1;
return v6;
}
v2 += 32;
++v4;
}
while ( v4 != v3 );
return (unsigned int)-1;
}

original_code:
int dsdh_GetDehSFXIndex(const char *key, size_t length)
{
    for (int i = 1; i < numsfx; i++)
        if (*s_sfx[i].name1
            && strlen(s_sfx[i].name1) == length
            && !strncasecmp(s_sfx[i].name1, key, length)
            && !sfx_state[i])
        {
            sfx_state[i] = 1;
            return i;
        }
    return -1;
}

canonical_original_code:
int dsdh_GetDehSFXIndex(char *key, unsigned long length)
{
    for (int i = 1; i < numsfx; i++)
        if (*s_sfx[i].name1
            && strlen(s_sfx[i].name1) == length
            && !strncasecmp(s_sfx[i].name1, key, length)
            && !sfx_state[i])
        {
            sfx_state[i] = 1;
            return i;
        }
    return -1;
}

variable_types:
key
char *

variable_types:
length
unsigned long

return_type: int


decompiled_code:
__int64 __fastcall dsdh_GetOriginalSFXIndex(char *nptr)
{
_QWORD *v2; // r13
const char *v3; // rdi
__int64 v4; // rbx
unsigned int v5; // er12
char v6; // bl
const unsigned __int16 *v7; // rdx
char *v8; // rax

v2 = deh_soundnames;
v3 = (const char *)*((_QWORD *)deh_soundnames + 1);
if ( v3 )
{
v4 = 1LL;
while ( 1 )
{
v5 = v4;
if ( !strncasecmp(v3, nptr, 6uLL) )
break;
v3 = (const char *)v2[++v4];
if ( !v3 )
goto LABEL_5;
}
}
else
{
LABEL_5:
v6 = *nptr;
if ( *nptr )
{
v7 = *_ctype_b_loc();
v8 = nptr;
while ( (v7[v6] & 0x800) != 0 )
{
v6 = *++v8;
if ( !*v8 )
goto LABEL_9;
}
v5 = -1;
}
else
{
LABEL_9:
v5 = atoi(nptr);
dsdh_EnsureSFXCapacity(v5);
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *nptr)
{
_QWORD *v2; // r13
const char *v3; // rdi
__int64 v4; // rbx
unsigned int v5; // er12
char v6; // bl
const unsigned __int16 *v7; // rdx
char *v8; // rax

v2 = deh_soundnames;
v3 = (const char *)*((_QWORD *)deh_soundnames + 1);
if ( v3 )
{
v4 = 1LL;
while ( 1 )
{
v5 = v4;
if ( !strncasecmp(v3, nptr, 6uLL) )
break;
v3 = (const char *)v2[++v4];
if ( !v3 )
goto LABEL_5;
}
}
else
{
LABEL_5:
v6 = *nptr;
if ( *nptr )
{
v7 = *_ctype_b_loc();
v8 = nptr;
while ( (v7[v6] & 0x800) != 0 )
{
v6 = *++v8;
if ( !*v8 )
goto LABEL_9;
}
v5 = -1;
}
else
{
LABEL_9:
v5 = atoi(nptr);
func2(v5);
}
}
return v5;
}

original_code:
int dsdh_GetOriginalSFXIndex(const char *key)
{
    int limit;
    for (int i = 1; deh_soundnames[i]; i++)
        if (!strncasecmp(deh_soundnames[i], key, 6))
            return i;
    for (const char *c = key; *c; c++)
        if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISdigit))
            return -1;
    limit = atoi(key);
    dsdh_EnsureSFXCapacity(limit);
    return limit;
}

canonical_original_code:
int dsdh_GetOriginalSFXIndex(char *key)
{
    int limit;
    for (int i = 1; deh_soundnames[i]; i++)
        if (!strncasecmp(deh_soundnames[i], key, 6))
            return i;
    for (char *c = key; *c; c++)
        if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISdigit))
            return -1;
    limit = atoi(key);
    dsdh_EnsureSFXCapacity(limit);
    return limit;
}

variable_types:
c
char *


MIN

decompiled_code:
__int64 __fastcall MIN(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

original_code:
__attribute__((const)) static inline int MIN(int a, int b)
{
    return (a < b ? a : b);
}

variable_types: a int

variable_types: b int


decompiled_code:
__int64 M_BigRandom()
{
bigseed = 214013 * bigseed + 2531011;
return HIWORD(bigseed);
}

canonical_decompiled_code:
__int64 func2()
{
bigseed = 214013 * bigseed + 2531011;
return HIWORD(bigseed);
}

original_code:
static inline int M_BigRandom(void)
{
    return ((bigseed = 214013 * bigseed + 2531011) >> 16);
}

canonical_original_code:
static inline int M_BigRandom()
{
    return ((bigseed = 214013 * bigseed + 2531011) >> 16);
}


decompiled_code:
__int64 Wipe_DoMelt()
{
__int64 v0; // rbx
unsigned int v1; // ecx
int v2; // esi
int v3; // edi
int v4; // eax

if ( SCREENWIDTH <= 1 )
return 1LL;
v0 = 0LL;
v1 = 1;
do
{
v2 = y[v0];
if ( v2 < 0 )
{
y[v0] = v2 + 1;
v1 = 0;
}
else if ( v2 <= 15 )
{
Wipe_Melt(v0, v2 + 1);
v1 = 0;
}
else
{
v3 = SCREENHEIGHT;
if ( v2 < SCREENHEIGHT )
{
if ( SCREENHEIGHT < 0 )
v3 = SCREENHEIGHT + 15;
v4 = MIN(v3 >> 4, SCREENHEIGHT - v2);
Wipe_Melt(v0, v4);
v1 = 0;
}
}
++v0;
}
while ( SCREENWIDTH / 2 > (int)v0 );
return v1;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx
unsigned int v1; // ecx
int v2; // esi
int v3; // edi
int v4; // eax

if ( SCREENWIDTH <= 1 )
return 1LL;
v0 = 0LL;
v1 = 1;
do
{
v2 = y[v0];
if ( v2 < 0 )
{
y[v0] = v2 + 1;
v1 = 0;
}
else if ( v2 <= 15 )
{
func3(v0, v2 + 1);
v1 = 0;
}
else
{
v3 = SCREENHEIGHT;
if ( v2 < SCREENHEIGHT )
{
if ( SCREENHEIGHT < 0 )
v3 = SCREENHEIGHT + 15;
v4 = func0(v3 >> 4, SCREENHEIGHT - v2);
func3(v0, v4);
v1 = 0;
}
}
++v0;
}
while ( SCREENWIDTH / 2 > (int)v0 );
return v1;
}

original_code:
static _Bool Wipe_DoMelt(void)
{
    _Bool done = 1;
    for (int i = 0; i < SCREENWIDTH / 2; i++)
        if (y[i] < 0)
        {
            y[i]++;
            done = 0;
        }
        else if (y[i] < 16)
        {
            Wipe_Melt(i, y[i] + 1);
            done = 0;
        }
        else if (y[i] < SCREENHEIGHT)
        {
            Wipe_Melt(i, MIN(SCREENHEIGHT / 16, SCREENHEIGHT - y[i]));
            done = 0;
        }
    return done;
}

canonical_original_code:
static _Bool Wipe_DoMelt()
{
    _Bool done = 1;
    for (int i = 0; i < SCREENWIDTH / 2; i++)
        if (y[i] < 0)
        {
            y[i]++;
            done = 0;
        }
        else if (y[i] < 16)
        {
            Wipe_Melt(i, y[i] + 1);
            done = 0;
        }
        else if (y[i] < SCREENHEIGHT)
        {
            Wipe_Melt(i, MIN(SCREENHEIGHT / 16, SCREENHEIGHT - y[i]));
            done = 0;
        }
    return done;
}


decompiled_code:
void *__fastcall Wipe_ShittyColMajorXform(void *dest)
{
int v2; // er12
int v3; // ebp
int v4; // edi
_WORD *v5; // r11
int v6; // er9
int v7; // er10
_WORD *v8; // rdx
__int64 v9; // rax

v2 = SCREENHEIGHT;
if ( SCREENHEIGHT > 0 )
{
v3 = SCREENWIDTH;
v4 = SCREENWIDTH / 2;
v5 = &src;
v6 = 0;
v7 = 0;
do
{
if ( v3 > 1 )
{
v8 = v5;
v9 = 0LL;
do
{
*v8 = *((_WORD *)dest + v6 / 2 + v9++);
v8 += v2;
}
while ( v4 > (int)v9 );
}
++v7;
++v5;
v6 += v3;
}
while ( v7 != v2 );
}
return memcpy(dest, &src, (int)SCREENAREA);
}

canonical_decompiled_code:
void *__fastcall func5(void *dest)
{
int v2; // er12
int v3; // ebp
int v4; // edi
_WORD *v5; // r11
int v6; // er9
int v7; // er10
_WORD *v8; // rdx
__int64 v9; // rax

v2 = SCREENHEIGHT;
if ( SCREENHEIGHT > 0 )
{
v3 = SCREENWIDTH;
v4 = SCREENWIDTH / 2;
v5 = &src;
v6 = 0;
v7 = 0;
do
{
if ( v3 > 1 )
{
v8 = v5;
v9 = 0LL;
do
{
*v8 = *((_WORD *)dest + v6 / 2 + v9++);
v8 += v2;
}
while ( v4 > (int)v9 );
}
++v7;
++v5;
v6 += v3;
}
while ( v7 != v2 );
}
return memcpy(dest, &src, (int)SCREENAREA);
}

original_code:
static void Wipe_ShittyColMajorXform(short *dest)
{
    for (int yy = 0; yy < SCREENHEIGHT; yy++)
        for (int xx = 0; xx < SCREENWIDTH / 2; xx++)
            src[yy + xx * SCREENHEIGHT] = dest[yy * SCREENWIDTH / 2 + xx];
    memcpy(dest, src, SCREENAREA);
}

variable_types:
dest
short *

variable_types: yy int

variable_types: xx int


decompiled_code:
__int64 Wipe_InitMelt()
{
__int64 result; // rax
__int64 v1; // rbx
int v2; // ebp
int v3; // eax
int v4; // eax

Wipe_ShittyColMajorXform(*(&screens + 2));
Wipe_ShittyColMajorXform(*(&screens + 3));
result = (unsigned int)-(M_BigRandom() & 0xF);
dword_2F1FE4[0] = result;
y[0] = result;
if ( SCREENWIDTH > 3 )
{
v1 = 2LL;
do
{
v2 = dword_2F1FDC[v1];
v3 = M_BigRandom();
v4 = BETWEEN(0xFFFFFFF1, v2 + v3 % 3 - 1, 0);
dword_2F1FE4[v1] = v4;
y[v1] = v4;
v1 += 2LL;
result = (unsigned int)(SCREENWIDTH - 1);
}
while ( (int)result > (int)v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
__int64 v1; // rbx
int v2; // ebp
int v3; // eax
int v4; // eax

func5(*(&screens + 2));
func5(*(&screens + 3));
result = (unsigned int)-(func2() & 0xF);
dword_2F1FE4[0] = result;
y[0] = result;
if ( SCREENWIDTH > 3 )
{
v1 = 2LL;
do
{
v2 = dword_2F1FDC[v1];
v3 = func2();
v4 = func1(0xFFFFFFF1, v2 + v3 % 3 - 1, 0);
dword_2F1FE4[v1] = v4;
y[v1] = v4;
v1 += 2LL;
result = (unsigned int)(SCREENWIDTH - 1);
}
while ( (int)result > (int)v1 );
}
return result;
}

original_code:
static void Wipe_InitMelt(void)
{
    Wipe_ShittyColMajorXform((short *)screens[2]);
    Wipe_ShittyColMajorXform((short *)screens[3]);
    y[0] = y[1] = -(M_BigRandom() & 15);
    for (int i = 2; i < SCREENWIDTH - 1; i += 2)
        y[i] = y[i + 1] = BETWEEN(-15, y[i - 1] + M_BigRandom() % 3 - 1, 0);
}

canonical_original_code:
static void Wipe_InitMelt()
{
    Wipe_ShittyColMajorXform((short *)screens[2]);
    Wipe_ShittyColMajorXform((short *)screens[3]);
    y[0] = y[1] = -(M_BigRandom() & 15);
    for (int i = 2; i < SCREENWIDTH - 1; i += 2)
        y[i] = y[i + 1] = BETWEEN(-15, y[i - 1] + M_BigRandom() % 3 - 1, 0);
}


decompiled_code:
void *Wipe_StartScreen()
{
return memcpy(*(&screens + 2), screens, (int)SCREENAREA);
}

canonical_decompiled_code:
void *func7()
{
return memcpy(*(&screens + 2), screens, (int)SCREENAREA);
}

original_code:
void Wipe_StartScreen(void)
{
    memcpy(screens[2], screens[0], SCREENAREA);
}

canonical_original_code:
void Wipe_StartScreen()
{
    memcpy(screens[2], screens[0], SCREENAREA);
}


decompiled_code:
void *Wipe_EndScreen()
{
memcpy(*(&screens + 3), screens, (int)SCREENAREA);
return memcpy(screens, *(&screens + 2), (int)SCREENAREA);
}

canonical_decompiled_code:
void *func8()
{
memcpy(*(&screens + 3), screens, (int)SCREENAREA);
return memcpy(screens, *(&screens + 2), (int)SCREENAREA);
}

original_code:
void Wipe_EndScreen(void)
{
    memcpy(screens[3], screens[0], SCREENAREA);
    memcpy(screens[0], screens[2], SCREENAREA);
}

canonical_original_code:
void Wipe_EndScreen()
{
    memcpy(screens[3], screens[0], SCREENAREA);
    memcpy(screens[0], screens[2], SCREENAREA);
}


decompiled_code:
__int64 Wipe_ScreenWipe()
{
if ( !go_0 )
{
go_0 = 1;
Wipe_InitMelt();
}
if ( (unsigned __int8)Wipe_DoMelt() )
go_0 = 0;
return (unsigned __int8)go_0 ^ 1u;
}

canonical_decompiled_code:
__int64 func9()
{
if ( !go_0 )
{
go_0 = 1;
func6();
}
if ( (unsigned __int8)func4() )
go_0 = 0;
return (unsigned __int8)go_0 ^ 1u;
}

original_code:
_Bool Wipe_ScreenWipe(void)
{
    static _Bool go;
    if (!go)
    {
        go = 1;
        Wipe_InitMelt();
    }
    if (Wipe_DoMelt())
        go = 0;
    return !go;
}

canonical_original_code:
_Bool Wipe_ScreenWipe()
{
    static _Bool go;
    if (!go)
    {
        go = 1;
        Wipe_InitMelt();
    }
    if (Wipe_DoMelt())
        go = 0;
    return !go;
}


decompiled_code:
__int64 __fastcall cht_CheckCheat(_QWORD *a1, unsigned __int8 a2)
{
int v2; // eax
size_t v3; // r12
const char *v4; // r13
const __int32_t *v5; // rax
__int32_t v6; // edx
size_t v7; // rdx
__int64 result; // rax
unsigned __int64 v9; // r12
int v10; // er12

if ( !consolecheat || (result = M_StringCompare(&consolecheat, *a1), !(_BYTE)result) )
{
v2 = *((_DWORD *)a1 + 9);
if ( v2 && maptime - v2 > (*((_BYTE *)a1 + 12) == 0 ? 70 : 140) )
{
a1[2] = 0LL;
*((_DWORD *)a1 + 6) = 0;
}
*((_DWORD *)a1 + 9) = maptime;
v3 = a1[2];
v4 = (const char *)*a1;
if ( v3 >= strlen((const char *)*a1) )
{
v10 = *((_DWORD *)a1 + 6);
if ( v10 >= *((_DWORD *)a1 + 2) )
goto LABEL_22;
if ( ((*_ctype_b_loc())[a2] & 0x800) == 0 )
{
a1[2] = 0LL;
*((_DWORD *)a1 + 6) = 0;
*((_DWORD *)a1 + 9) = 0;
return 0LL;
}
*((_BYTE *)a1 + v10 + 28) = a2;
*((_DWORD *)a1 + 6) = v10 + 1;
}
else
{
v5 = *_ctype_toupper_loc();
v6 = v5[a2];
if ( v5[v4[v3]] == v6 )
{
v9 = v3 + 1;
a1[2] = v9;
*((_DWORD *)a1 + 6) = 0;
if ( v9 > 1 && !*((_BYTE *)a1 + 40) )
cheatkey = a2;
}
else
{
a1[2] = v5[*v4] == v6;
*((_DWORD *)a1 + 6) = 0;
}
}
v7 = strlen((const char *)*a1);
result = 0LL;
if ( a1[2] < v7 )
return result;
if ( *((_DWORD *)a1 + 6) < *((_DWORD *)a1 + 2) )
return 0LL;
LABEL_22:
a1[2] = 0LL;
*((_DWORD *)a1 + 6) = 0;
*((_DWORD *)a1 + 9) = 0;
return 1LL;
}
consolecheat = 0;
if ( consolecheatparm )
{
*((_BYTE *)a1 + 28) = consolecheatparm;
*((_BYTE *)a1 + 29) = *((_BYTE *)&consolecheatparm + 1);
*((_DWORD *)a1 + 6) = 2;
consolecheatparm = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, unsigned __int8 a2)
{
int v2; // eax
size_t v3; // r12
const char *v4; // r13
const __int32_t *v5; // rax
__int32_t v6; // edx
size_t v7; // rdx
__int64 result; // rax
unsigned __int64 v9; // r12
int v10; // er12

if ( !consolecheat || (result = M_StringCompare(&consolecheat, *a1), !(_BYTE)result) )
{
v2 = *((_DWORD *)a1 + 9);
if ( v2 && maptime - v2 > (*((_BYTE *)a1 + 12) == 0 ? 70 : 140) )
{
a1[2] = 0LL;
*((_DWORD *)a1 + 6) = 0;
}
*((_DWORD *)a1 + 9) = maptime;
v3 = a1[2];
v4 = (const char *)*a1;
if ( v3 >= strlen((const char *)*a1) )
{
v10 = *((_DWORD *)a1 + 6);
if ( v10 >= *((_DWORD *)a1 + 2) )
goto LABEL_22;
if ( ((*_ctype_b_loc())[a2] & 0x800) == 0 )
{
a1[2] = 0LL;
*((_DWORD *)a1 + 6) = 0;
*((_DWORD *)a1 + 9) = 0;
return 0LL;
}
*((_BYTE *)a1 + v10 + 28) = a2;
*((_DWORD *)a1 + 6) = v10 + 1;
}
else
{
v5 = *_ctype_toupper_loc();
v6 = v5[a2];
if ( v5[v4[v3]] == v6 )
{
v9 = v3 + 1;
a1[2] = v9;
*((_DWORD *)a1 + 6) = 0;
if ( v9 > 1 && !*((_BYTE *)a1 + 40) )
cheatkey = a2;
}
else
{
a1[2] = v5[*v4] == v6;
*((_DWORD *)a1 + 6) = 0;
}
}
v7 = strlen((const char *)*a1);
result = 0LL;
if ( a1[2] < v7 )
return result;
if ( *((_DWORD *)a1 + 6) < *((_DWORD *)a1 + 2) )
return 0LL;
LABEL_22:
a1[2] = 0LL;
*((_DWORD *)a1 + 6) = 0;
*((_DWORD *)a1 + 9) = 0;
return 1LL;
}
consolecheat = 0;
if ( consolecheatparm )
{
*((_BYTE *)a1 + 28) = consolecheatparm;
*((_BYTE *)a1 + 29) = *((_BYTE *)&consolecheatparm + 1);
*((_DWORD *)a1 + 6) = 2;
consolecheatparm = 0;
}
return result;
}

original_code:
_Bool cht_CheckCheat(cheatseq_t *cht, unsigned char key)
{
    if (*consolecheat && M_StringCompare(consolecheat, cht->sequence))
    {
        consolecheat[0] = '\0';
        if (*consolecheatparm)
        {
            cht->parameter_buf[0] = consolecheatparm[0];
            cht->parameter_buf[1] = consolecheatparm[1];
            cht->param_chars_read = 2;
            consolecheatparm[0] = '\0';
        }
        return 1;
    }
    if (cht->timeout && maptime - cht->timeout > (cht->longtimeout ? (4 * 35) : (4 * 35) / 2))
    {
        cht->chars_read = 0;
        cht->param_chars_read = 0;
    }
    cht->timeout = maptime;
    if (cht->chars_read < strlen(cht->sequence))
    {
        if (toupper(key) == toupper(cht->sequence[cht->chars_read]))
            cht->chars_read++;
        else
            cht->chars_read = (toupper(key) == toupper(cht->sequence[0]));
        cht->param_chars_read = 0;
        if (cht->chars_read > 1 && !cht->movekey)
            cheatkey = key;
    }
    else if (cht->param_chars_read < cht->parameter_chars)
    {
        if (!((*__ctype_b_loc ())[(int) ((key))] & (unsigned short int) _ISdigit))
        {
            cht->chars_read = 0;
            cht->param_chars_read = 0;
            cht->timeout = 0;
            return 0;
        }
        else
        {
            cht->parameter_buf[cht->param_chars_read] = key;
            cht->param_chars_read++;
        }
    }
    if (cht->chars_read >= strlen(cht->sequence) && cht->param_chars_read >= cht->parameter_chars)
    {
        cht->chars_read = 0;
        cht->param_chars_read = 0;
        cht->timeout = 0;
        return 1;
    }
    return 0;
}

canonical_original_code:
_Bool cht_CheckCheat(struct cheatseq_t *cht, unsigned char key)
{
    if (*consolecheat && M_StringCompare(consolecheat, cht->sequence))
    {
        consolecheat[0] = '\0';
        if (*consolecheatparm)
        {
            cht->parameter_buf[0] = consolecheatparm[0];
            cht->parameter_buf[1] = consolecheatparm[1];
            cht->param_chars_read = 2;
            consolecheatparm[0] = '\0';
        }
        return 1;
    }
    if (cht->timeout && maptime - cht->timeout > (cht->longtimeout ? (4 * 35) : (4 * 35) / 2))
    {
        cht->chars_read = 0;
        cht->param_chars_read = 0;
    }
    cht->timeout = maptime;
    if (cht->chars_read < strlen(cht->sequence))
    {
        if (toupper(key) == toupper(cht->sequence[cht->chars_read]))
            cht->chars_read++;
        else
            cht->chars_read = (toupper(key) == toupper(cht->sequence[0]));
        cht->param_chars_read = 0;
        if (cht->chars_read > 1 && !cht->movekey)
            cheatkey = key;
    }
    else if (cht->param_chars_read < cht->parameter_chars)
    {
        if (!((*__ctype_b_loc ())[(int) ((key))] & (unsigned short) _ISdigit))
        {
            cht->chars_read = 0;
            cht->param_chars_read = 0;
            cht->timeout = 0;
            return 0;
        }
        else
        {
            cht->parameter_buf[cht->param_chars_read] = key;
            cht->param_chars_read++;
        }
    }
    if (cht->chars_read >= strlen(cht->sequence) && cht->param_chars_read >= cht->parameter_chars)
    {
        cht->chars_read = 0;
        cht->param_chars_read = 0;
        cht->timeout = 0;
        return 1;
    }
    return 0;
}

variable_types: struct cheatseq_t { char *sequence; int parameter_chars; _Bool longtimeout; unsigned long chars_read; int param_chars_read; char parameter_buf[5]; int timeout; _Bool movekey; } *

variable_types:
key
unsigned char


decompiled_code:
void *__fastcall cht_GetParam(__int64 a1, void *a2)
{
return memcpy(a2, (const void *)(a1 + 28), *(int *)(a1 + 8));
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, void *a2)
{
return memcpy(a2, (const void *)(a1 + 28), *(int *)(a1 + 8));
}

original_code:
void cht_GetParam(const cheatseq_t *cht, char *buffer)
{
    memcpy(buffer, cht->parameter_buf, cht->parameter_chars);
}

canonical_original_code:
void cht_GetParam(struct cheatseq_t *cht, char *buffer)
{
    memcpy(buffer, cht->parameter_buf, cht->parameter_chars);
}

variable_types:
buffer
char *

user_defined_types: struct cheatseq_t { char *sequence; int parameter_chars; _Bool longtimeout; unsigned long chars_read; int param_chars_read; char parameter_buf[5]; int timeout; _Bool movekey; }


decompiled_code:
__int64 M_SubRandom()
{
int v0; // edx

v0 = (unsigned __int8)rndtable[(unsigned __int8)(seed + 1)];
seed = (unsigned __int8)(seed + 2);
return v0 - (unsigned int)(unsigned __int8)rndtable[seed];
}

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

v0 = (unsigned __int8)rndtable[(unsigned __int8)(seed + 1)];
seed = (unsigned __int8)(seed + 2);
return v0 - (unsigned int)(unsigned __int8)rndtable[seed];
}

original_code:
static inline int M_SubRandom(void)
{
    const int r = rndtable[(seed = (seed + 1) & 255)];
    return (r - rndtable[(seed = (seed + 1) & 255)]);
}

canonical_original_code:
static inline int M_SubRandom()
{
    int r = rndtable[(seed = (seed + 1) & 255)];
    return (r - rndtable[(seed = (seed + 1) & 255)]);
}

variable_types: r int


FixedToAngle

decompiled_code:
unsigned __int64 __fastcall FixedToAngle(int a1)
{
return (unsigned __int64)(11930464LL * a1) >> 16;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(int a1)
{
return (unsigned __int64)(11930464LL * a1) >> 16;
}

original_code:
__attribute__((const)) inline static angle_t FixedToAngle(fixed_t a)
{
    return (angle_t)(((uint64_t)a * (0x20000000 / 45)) >> 16);
}

canonical_original_code:
inline static unsigned int FixedToAngle(int a)
{
    return (angle_t)(((unsigned long)a * (0x20000000 / 45)) >> 16);
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall P_RandomHitscanAngle(int a1)
{
__int64 v1; // rbx

if ( a1 < 0 )
v1 = (unsigned int)FixedToAngle(-a1);
else
v1 = (unsigned int)FixedToAngle(a1);
return v1 * (int)M_SubRandom() / 255;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // rbx

if ( a1 < 0 )
v1 = (unsigned int)func1(-a1);
else
v1 = (unsigned int)func1(a1);
return v1 * (int)func0() / 255;
}

original_code:
int P_RandomHitscanAngle(const fixed_t spread)
{
    return (int)(((int64_t)(spread < 0 ? FixedToAngle(-spread) : FixedToAngle(spread)) * M_SubRandom()) / 255);
}

canonical_original_code:
int P_RandomHitscanAngle(int spread)
{
    return (int)(((long)(spread < 0 ? FixedToAngle(-spread) : FixedToAngle(spread)) * M_SubRandom()) / 255);
}

variable_types: spread int


decompiled_code:
__int64 __fastcall P_RandomHitscanSlope(int a1)
{
int v1; // edx
int v2; // eax

v1 = P_RandomHitscanAngle(a1);
v2 = 0;
if ( v1 <= 0x40000000 )
{
v2 = 4095;
if ( v1 >= -1073741824 )
v2 = (0x40000000 - v1) >> 19;
}
return *((unsigned int *)&finetangent + v2);
}

original_code:
int P_RandomHitscanSlope(const fixed_t spread)
{
    const int angle = P_RandomHitscanAngle(spread);
    return finetangent[(angle > 0x40000000 ? 0 : (-angle > 0x40000000 ? 8192 / 2 - 1 : (0x40000000 - angle) >> 19))];
}

canonical_original_code:
int P_RandomHitscanSlope(int spread)
{
    int angle = P_RandomHitscanAngle(spread);
    return finetangent[(angle > 0x40000000 ? 0 : (-angle > 0x40000000 ? 8192 / 2 - 1 : (0x40000000 - angle) >> 19))];
}

variable_types: angle int


InitStates

decompiled_code:
_DWORD *InitStates()
{
__int64 v0; // rdx
__int64 v1; // rax
_DWORD *result; // rax
__int64 v3; // rdx

numstates = 4000;
states = (__int64)&original_states;
deh_codeptr = malloc(0x7D00uLL);
v0 = 0LL;
v1 = 0LL;
do
{
*((_QWORD *)deh_codeptr + v1++) = *(_QWORD *)(states + v0 + 16);
v0 += 80LL;
}
while ( numstates > (int)v1 );
defined_codeptr_args = calloc(numstates, 1uLL);
result = (_DWORD *)(states + 38228);
v3 = states + 39268;
do
{
*result |= 1u;
result += 20;
}
while ( result != (_DWORD *)v3 );
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
__int64 v0; // rdx
__int64 v1; // rax
_DWORD *result; // rax
__int64 v3; // rdx

numstates = 4000;
states = (__int64)&original_states;
deh_codeptr = malloc(0x7D00uLL);
v0 = 0LL;
v1 = 0LL;
do
{
*((_QWORD *)deh_codeptr + v1++) = *(_QWORD *)(states + v0 + 16);
v0 += 80LL;
}
while ( numstates > (int)v1 );
defined_codeptr_args = calloc(numstates, 1uLL);
result = (_DWORD *)(states + 38228);
v3 = states + 39268;
do
{
*result |= 1u;
result += 20;
}
while ( result != (_DWORD *)v3 );
return result;
}

original_code:
void InitStates(void)
{
    numstates = NUMSTATES;
    states = original_states;
    deh_codeptr = malloc(numstates * sizeof(*deh_codeptr));
    for (int i = 0; i < numstates; i++)
        deh_codeptr[i] = states[i].action;
    defined_codeptr_args = calloc(numstates, sizeof(*defined_codeptr_args));
    for (int i = S_SARG_RUN1; i <= S_SARG_PAIN2; i++)
        states[i].flags |= 0x00000001;
}

canonical_original_code:
void InitStates()
{
    numstates = NUMSTATES;
    states = original_states;
    deh_codeptr = malloc(numstates * sizeof(*deh_codeptr));
    for (int i = 0; i < numstates; i++)
        deh_codeptr[i] = states[i].action;
    defined_codeptr_args = calloc(numstates, sizeof(*defined_codeptr_args));
    for (int i = S_SARG_RUN1; i <= S_SARG_PAIN2; i++)
        states[i].flags |= 0x00000001;
}


FreeStates

decompiled_code:
void FreeStates()
{
free(defined_codeptr_args);
free(deh_codeptr);
}

canonical_decompiled_code:
void func1()
{
free(defined_codeptr_args);
free(deh_codeptr);
}

original_code:
void FreeStates(void)
{
    free(defined_codeptr_args);
    free(deh_codeptr);
}


decompiled_code:
void __fastcall dsdh_EnsureStatesCapacity(int a1)
{
int i; // ebx
__int64 v2; // rbp
__int64 v3; // rax
int v4; // eax

for ( i = numstates; numstates <= a1; i = numstates )
{
v4 = 2 * i;
numstates = 2 * i;
if ( first_allocation_0 )
{
first_allocation_0 = 0;
states = (__int64)malloc(80LL * v4);
memcpy((void *)states, &original_states, 80LL * i);
}
else
{
states = I_Realloc(states, 80LL * v4);
}
v2 = 80LL * i;
memset((void *)(states + v2), 0, 80LL * (numstates - i));
deh_codeptr = (void *)I_Realloc(deh_codeptr, 8LL * numstates);
memset((char *)deh_codeptr + 8 * i, 0, 8LL * (numstates - i));
defined_codeptr_args = (void *)I_Realloc(defined_codeptr_args, numstates);
memset((char *)defined_codeptr_args + i, 0, numstates - i);
for ( ; numstates > i; v2 += 80LL )
{
*(_DWORD *)(states + v2) = 138;
v3 = states + v2;
*(_DWORD *)(v3 + 8) = -1;
*(_DWORD *)(v3 + 24) = i++;
}
}
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
int i; // ebx
__int64 v2; // rbp
__int64 v3; // rax
int v4; // eax

for ( i = numstates; numstates <= a1; i = numstates )
{
v4 = 2 * i;
numstates = 2 * i;
if ( first_allocation_0 )
{
first_allocation_0 = 0;
states = (__int64)malloc(80LL * v4);
memcpy((void *)states, &original_states, 80LL * i);
}
else
{
states = I_Realloc(states, 80LL * v4);
}
v2 = 80LL * i;
memset((void *)(states + v2), 0, 80LL * (numstates - i));
deh_codeptr = (void *)I_Realloc(deh_codeptr, 8LL * numstates);
memset((char *)deh_codeptr + 8 * i, 0, 8LL * (numstates - i));
defined_codeptr_args = (void *)I_Realloc(defined_codeptr_args, numstates);
memset((char *)defined_codeptr_args + i, 0, numstates - i);
for ( ; numstates > i; v2 += 80LL )
{
*(_DWORD *)(states + v2) = 138;
v3 = states + v2;
*(_DWORD *)(v3 + 8) = -1;
*(_DWORD *)(v3 + 24) = i++;
}
}
}

original_code:
void dsdh_EnsureStatesCapacity(const int limit)
{
    static _Bool first_allocation = 1;
    while (limit >= numstates)
    {
        const int old_numstates = numstates;
        numstates *= 2;
        if (first_allocation)
        {
            first_allocation = 0;
            states = malloc(numstates * sizeof(*states));
            memcpy(states, original_states, old_numstates * sizeof(*states));
        }
        else
            states = I_Realloc(states, numstates * sizeof(*states));
        memset(states + old_numstates, 0, (numstates - old_numstates) * sizeof(*states));
        deh_codeptr = I_Realloc(deh_codeptr, numstates * sizeof(*deh_codeptr));
        memset(deh_codeptr + old_numstates, 0, (numstates - old_numstates) * sizeof(*deh_codeptr));
        defined_codeptr_args = I_Realloc(defined_codeptr_args, numstates * sizeof(*defined_codeptr_args));
        memset(defined_codeptr_args + old_numstates, 0,
            (numstates - old_numstates) * sizeof(*defined_codeptr_args));
        for (int i = old_numstates; i < numstates; i++)
        {
            states[i].sprite = SPR_TNT1;
            states[i].tics = -1;
            states[i].nextstate = i;
        }
    }
}

canonical_original_code:
void dsdh_EnsureStatesCapacity(int limit)
{
    static _Bool first_allocation = 1;
    while (limit >= numstates)
    {
        int old_numstates = numstates;
        numstates *= 2;
        if (first_allocation)
        {
            first_allocation = 0;
            states = malloc(numstates * sizeof(*states));
            memcpy(states, original_states, old_numstates * sizeof(*states));
        }
        else
            states = I_Realloc(states, numstates * sizeof(*states));
        memset(states + old_numstates, 0, (numstates - old_numstates) * sizeof(*states));
        deh_codeptr = I_Realloc(deh_codeptr, numstates * sizeof(*deh_codeptr));
        memset(deh_codeptr + old_numstates, 0, (numstates - old_numstates) * sizeof(*deh_codeptr));
        defined_codeptr_args = I_Realloc(defined_codeptr_args, numstates * sizeof(*defined_codeptr_args));
        memset(defined_codeptr_args + old_numstates, 0,
            (numstates - old_numstates) * sizeof(*defined_codeptr_args));
        for (int i = old_numstates; i < numstates; i++)
        {
            states[i].sprite = SPR_TNT1;
            states[i].tics = -1;
            states[i].nextstate = i;
        }
    }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
int v4; // ebp
__int64 v5; // rbx

myargc = argc;
v3 = malloc(8LL * argc);
myargv = v3;
if ( v3 )
{
v4 = myargc;
memcpy(v3, argv, 8LL * myargc);
if ( v4 > 0 )
{
v5 = 0LL;
do
M_NormalizeSlashes(*(_QWORD *)(myargv + 8 * v5++));
while ( myargc > (int)v5 );
}
}
D_DoomMain();
return 0;
}

original_code:
int main(int argc, char **argv)
{
    myargc = argc;
    if ((myargv = (char **)malloc(myargc * sizeof(myargv[0]))))
    {
        memcpy(myargv, argv, myargc * sizeof(myargv[0]));
        for (int i = 0; i < myargc; i++)
            M_NormalizeSlashes(myargv[i]);
    }
    D_DoomMain();
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


AllocateMIDIChannel

decompiled_code:
__int64 AllocateMIDIChannel()
{
int *v0; // rax
int v1; // edx
__int64 result; // rax

v0 = &channel_map;
v1 = -1;
do
{
if ( v1 < *v0 )
v1 = *v0;
++v0;
}
while ( v0 != &tracksize );
result = (unsigned int)(v1 + 1);
if ( v1 == 8 )
result = 10LL;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int *v0; // rax
int v1; // edx
__int64 result; // rax

v0 = &channel_map;
v1 = -1;
do
{
if ( v1 < *v0 )
v1 = *v0;
++v0;
}
while ( v0 != &tracksize );
result = (unsigned int)(v1 + 1);
if ( v1 == 8 )
result = 10LL;
return result;
}

original_code:
static int AllocateMIDIChannel(void)
{
    int result;
    int max = -1;
    for (int i = 0; i < 16; i++)
        if (channel_map[i] > max)
            max = channel_map[i];
    result = max + 1;
    if (result == 9)
        result++;
    return result;
}

canonical_original_code:
static int AllocateMIDIChannel()
{
    int result;
    int max = -1;
    for (int i = 0; i < 16; i++)
        if (channel_map[i] > max)
            max = channel_map[i];
    result = max + 1;
    if (result == 9)
        result++;
    return result;
}

variable_types: result int

variable_types: max int

variable_types: i int


decompiled_code:
unsigned __int64 R_InitSkyMap()
{
unsigned int v0; // ebx
int v1; // eax
const char *v2; // rdi
int v3; // esi
unsigned __int64 result; // rax
int v5; // ecx
int v6; // esi
int v7; // eax
int v8; // ecx

v0 = gamemap + 2 * (5 * gameepisode - 5);
skyflatnum = R_FlatNumForName("F_SKY1");
*(_DWORD *)(terraintypes + 4LL * skyflatnum) = 1;
v1 = P_GetMapSky1Texture(v0);
skytexture = v1;
if ( (mouselook || keyboardmouselook || mousemouselook != -1 || autotilt || weaponrecoil && r_screensize == 8)
&& !nomouselook )
{
canmouselook = 1;
if ( v1 )
goto LABEL_40;
}
else
{
canmouselook = 0;
if ( v1 && !BTSX )
goto LABEL_40;
}
if ( gamemode == 2 )
{
if ( gamemission == 4 )
{
if ( gamemap > 3 && gamemap != 9 )
goto LABEL_12;
}
else if ( gamemap > 11 )
{
if ( gamemap > 20 )
goto LABEL_12;
goto LABEL_20;
}
goto LABEL_23;
}
if ( gameepisode == 4 )
{
skytexture = R_TextureNumForName("SKY4");
goto LABEL_40;
}
if ( gameepisode <= 4 )
{
if ( gameepisode != 2 )
{
if ( gameepisode == 3 )
{
LABEL_12:
skytexture = R_TextureNumForName("SKY3");
goto LABEL_40;
}
goto LABEL_23;
}
LABEL_20:
skytexture = R_TextureNumForName("SKY2");
goto LABEL_40;
}
if ( gameepisode != 5 )
{
LABEL_23:
skytexture = R_TextureNumForName("SKY1");
goto LABEL_40;
}
v2 = "SKY5_ZD";
if ( (unsigned int)R_CheckTextureNumForName("SKY5_ZD") == -1 )
v2 = "SKY5";
skytexture = R_TextureNumForName(v2);
LABEL_40:
skyscrolldelta = P_GetMapSky1ScrollDelta(v0);
if ( canmouselook )
{
v5 = *(__int16 *)(textureheight + 4LL * skytexture + 2);
if ( (unsigned int)(v5 - 128) > 0x47 )
{
if ( v5 <= 200 )
{
skytexturemid = 0;
}
else
{
v3 = 264;
if ( r_screensize <= 7 )
v3 = menuactive == 0 ? 238 : 264;
skytexturemid = ((v5 * (200 - v5)) << 16) / v3;
}
}
else
{
v6 = 264;
if ( r_screensize <= 7 )
v6 = menuactive == 0 ? 238 : 264;
skytexturemid = -3538944 * v5 / v6;
}
v7 = v5 * (13107200LL * SCREENWIDTH / (unsigned __int64)(SCREENHEIGHT * (__int64)viewwidth));
v8 = 264;
if ( r_screensize <= 7 )
v8 = menuactive == 0 ? 238 : 264;
result = (unsigned int)(v7 / v8);
skyiscale = result;
}
else
{
skytexturemid = 6553600;
result = 13107200LL * SCREENWIDTH / (unsigned __int64)(SCREENHEIGHT * (__int64)viewwidth);
skyiscale = result;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 func0()
{
unsigned int v0; // ebx
int v1; // eax
const char *v2; // rdi
int v3; // esi
unsigned __int64 result; // rax
int v5; // ecx
int v6; // esi
int v7; // eax
int v8; // ecx

v0 = gamemap + 2 * (5 * gameepisode - 5);
skyflatnum = R_FlatNumForName("F_SKY1");
*(_DWORD *)(terraintypes + 4LL * skyflatnum) = 1;
v1 = P_GetMapSky1Texture(v0);
skytexture = v1;
if ( (mouselook || keyboardmouselook || mousemouselook != -1 || autotilt || weaponrecoil && r_screensize == 8)
&& !nomouselook )
{
canmouselook = 1;
if ( v1 )
goto LABEL_40;
}
else
{
canmouselook = 0;
if ( v1 && !BTSX )
goto LABEL_40;
}
if ( gamemode == 2 )
{
if ( gamemission == 4 )
{
if ( gamemap > 3 && gamemap != 9 )
goto LABEL_12;
}
else if ( gamemap > 11 )
{
if ( gamemap > 20 )
goto LABEL_12;
goto LABEL_20;
}
goto LABEL_23;
}
if ( gameepisode == 4 )
{
skytexture = R_TextureNumForName("SKY4");
goto LABEL_40;
}
if ( gameepisode <= 4 )
{
if ( gameepisode != 2 )
{
if ( gameepisode == 3 )
{
LABEL_12:
skytexture = R_TextureNumForName("SKY3");
goto LABEL_40;
}
goto LABEL_23;
}
LABEL_20:
skytexture = R_TextureNumForName("SKY2");
goto LABEL_40;
}
if ( gameepisode != 5 )
{
LABEL_23:
skytexture = R_TextureNumForName("SKY1");
goto LABEL_40;
}
v2 = "SKY5_ZD";
if ( (unsigned int)R_CheckTextureNumForName("SKY5_ZD") == -1 )
v2 = "SKY5";
skytexture = R_TextureNumForName(v2);
LABEL_40:
skyscrolldelta = P_GetMapSky1ScrollDelta(v0);
if ( canmouselook )
{
v5 = *(__int16 *)(textureheight + 4LL * skytexture + 2);
if ( (unsigned int)(v5 - 128) > 0x47 )
{
if ( v5 <= 200 )
{
skytexturemid = 0;
}
else
{
v3 = 264;
if ( r_screensize <= 7 )
v3 = menuactive == 0 ? 238 : 264;
skytexturemid = ((v5 * (200 - v5)) << 16) / v3;
}
}
else
{
v6 = 264;
if ( r_screensize <= 7 )
v6 = menuactive == 0 ? 238 : 264;
skytexturemid = -3538944 * v5 / v6;
}
v7 = v5 * (13107200LL * SCREENWIDTH / (unsigned __int64)(SCREENHEIGHT * (__int64)viewwidth));
v8 = 264;
if ( r_screensize <= 7 )
v8 = menuactive == 0 ? 238 : 264;
result = (unsigned int)(v7 / v8);
skyiscale = result;
}
else
{
skytexturemid = 6553600;
result = 13107200LL * SCREENWIDTH / (unsigned __int64)(SCREENHEIGHT * (__int64)viewwidth);
skyiscale = result;
}
return result;
}

original_code:
void R_InitSkyMap(void)
{
    const int map = (gameepisode - 1) * 10 + gamemap;
    skyflatnum = R_FlatNumForName("F_SKY1");
    terraintypes[skyflatnum] = SKY;
    skytexture = P_GetMapSky1Texture(map);
    canmouselook = ((mouselook || keyboardmouselook || mousemouselook != -1 || autotilt
        || (weaponrecoil && r_screensize == 8)) && !nomouselook);
    if (!skytexture || (BTSX && !canmouselook))
    {
        if (gamemode == commercial)
        {
            if (gamemission == pack_nerve)
            {
                if (gamemap < 4 || gamemap == 9)
                    skytexture = R_TextureNumForName("SKY1");
                else
                    skytexture = R_TextureNumForName("SKY3");
            }
            else
            {
                if (gamemap < 12)
                    skytexture = R_TextureNumForName("SKY1");
                else if (gamemap < 21)
                    skytexture = R_TextureNumForName("SKY2");
                else
                    skytexture = R_TextureNumForName("SKY3");
            }
        }
        else
        {
            switch (gameepisode)
            {
                default:
                case 1:
                    skytexture = R_TextureNumForName("SKY1");
                    break;
                case 2:
                    skytexture = R_TextureNumForName("SKY2");
                    break;
                case 3:
                    skytexture = R_TextureNumForName("SKY3");
                    break;
                case 4:
                    skytexture = R_TextureNumForName("SKY4");
                    break;
                case 5:
                    skytexture = R_TextureNumForName(R_CheckTextureNumForName("SKY5_ZD") != -1 ? "SKY5_ZD" : "SKY5");
                    break;
            }
        }
    }
    skyscrolldelta = P_GetMapSky1ScrollDelta(map);
    if (canmouselook)
    {
        const int skyheight = textureheight[skytexture] >> 16;
        if (skyheight >= 128 && skyheight < 200)
            skytexturemid = -54 * (1 << 16) * skyheight / (200 + (r_screensize < 8 && !menuactive ? 38 : 64));
        else if (skyheight > 200)
            skytexturemid = (200 - skyheight) * (1 << 16) * skyheight / (200 + (r_screensize < 8 && !menuactive ? 38 : 64));
        else
            skytexturemid = 0;
        skyiscale = (fixed_t)(((uint64_t)SCREENWIDTH * 200 * (1 << 16)) / ((uint64_t)viewwidth * SCREENHEIGHT))
            * skyheight / (200 + (r_screensize < 8 && !menuactive ? 38 : 64));
    }
    else
    {
        skytexturemid = 200 / 2 * (1 << 16);
        skyiscale = (fixed_t)(((uint64_t)SCREENWIDTH * 200 * (1 << 16)) / ((uint64_t)viewwidth * SCREENHEIGHT));
    }
}

canonical_original_code:
void R_InitSkyMap()
{
    int map = (gameepisode - 1) * 10 + gamemap;
    skyflatnum = R_FlatNumForName("F_SKY1");
    terraintypes[skyflatnum] = SKY;
    skytexture = P_GetMapSky1Texture(map);
    canmouselook = ((mouselook || keyboardmouselook || mousemouselook != -1 || autotilt
        || (weaponrecoil && r_screensize == 8)) && !nomouselook);
    if (!skytexture || (BTSX && !canmouselook))
    {
        if (gamemode == commercial)
        {
            if (gamemission == pack_nerve)
            {
                if (gamemap < 4 || gamemap == 9)
                    skytexture = R_TextureNumForName("SKY1");
                else
                    skytexture = R_TextureNumForName("SKY3");
            }
            else
            {
                if (gamemap < 12)
                    skytexture = R_TextureNumForName("SKY1");
                else if (gamemap < 21)
                    skytexture = R_TextureNumForName("SKY2");
                else
                    skytexture = R_TextureNumForName("SKY3");
            }
        }
        else
        {
            switch (gameepisode)
            {
                default:
                case 1:
                    skytexture = R_TextureNumForName("SKY1");
                    break;
                case 2:
                    skytexture = R_TextureNumForName("SKY2");
                    break;
                case 3:
                    skytexture = R_TextureNumForName("SKY3");
                    break;
                case 4:
                    skytexture = R_TextureNumForName("SKY4");
                    break;
                case 5:
                    skytexture = R_TextureNumForName(R_CheckTextureNumForName("SKY5_ZD") != -1 ? "SKY5_ZD" : "SKY5");
                    break;
            }
        }
    }
    skyscrolldelta = P_GetMapSky1ScrollDelta(map);
    if (canmouselook)
    {
        int skyheight = textureheight[skytexture] >> 16;
        if (skyheight >= 128 && skyheight < 200)
            skytexturemid = -54 * (1 << 16) * skyheight / (200 + (r_screensize < 8 && !menuactive ? 38 : 64));
        else if (skyheight > 200)
            skytexturemid = (200 - skyheight) * (1 << 16) * skyheight / (200 + (r_screensize < 8 && !menuactive ? 38 : 64));
        else
            skytexturemid = 0;
        skyiscale = (fixed_t)(((unsigned long)SCREENWIDTH * 200 * (1 << 16)) / ((unsigned long)viewwidth * SCREENHEIGHT))
            * skyheight / (200 + (r_screensize < 8 && !menuactive ? 38 : 64));
    }
    else
    {
        skytexturemid = 200 / 2 * (1 << 16);
        skyiscale = (fixed_t)(((unsigned long)SCREENWIDTH * 200 * (1 << 16)) / ((unsigned long)viewwidth * SCREENHEIGHT));
    }
}

variable_types: map int

variable_types: skyheight int


original_code:
void M_AddToBox(fixed_t *box, fixed_t x, fixed_t y)
{
    if (x < box[BOXLEFT])
        box[BOXLEFT] = x;
    else if (x > box[BOXRIGHT])
        box[BOXRIGHT] = x;
    if (y < box[BOXBOTTOM])
        box[BOXBOTTOM] = y;
    else if (y > box[BOXTOP])
        box[BOXTOP] = y;
}

canonical_original_code:
void M_AddToBox(int *box, int x, int y)
{
    if (x < box[BOXLEFT])
        box[BOXLEFT] = x;
    else if (x > box[BOXRIGHT])
        box[BOXRIGHT] = x;
    if (y < box[BOXBOTTOM])
        box[BOXBOTTOM] = y;
    else if (y > box[BOXTOP])
        box[BOXTOP] = y;
}

variable_types:
box
int *

variable_types: x int

variable_types: y int


TryRunTics

decompiled_code:
__int64 TryRunTics()
{
unsigned __int128 v0; // rax
__int64 v1; // r12
__int64 v2; // rbx
char v3; // bp
int i; // ebx

*(_QWORD *)&v0 = I_GetTime();
v1 = v0 - lastmadetic_1;
if ( vid_capfps != 35 && !splashscreen )
{
lastmadetic_1 = v0;
v0 = 0x20C49BA5E353F7CFLL * (unsigned __int128)(((35 * I_GetTimeMS() % 0x3E8uLL) << 13) & 0x1FFFFFFFFFFFFFFFLL);
fractionaltic = *((_QWORD *)&v0 + 1) >> 4;
v2 = v1 - 1;
v3 = 1;
if ( !v1 )
goto LABEL_8;
goto LABEL_6;
}
lastmadetic_1 = v0;
v2 = v1 - 1;
v3 = 0;
if ( v1 )
{
LABEL_6:
while ( 1 )
{
I_StartTic();
*(_QWORD *)&v0 = (unsigned int)maketic_0;
if ( maketic_0 - gametime > 4 )
break;
++maketic_0;
G_BuildTiccmd(&localcmds[12 * ((int)v0 % 8)]);
*(_QWORD *)&v0 = v2 - 1;
if ( !v2 )
break;
--v2;
}
LABEL_8:
i = maketic_0 - gametime;
if ( maketic_0 == gametime && v3 )
return v0;
}
for ( i = maketic_0 - gametime; i; --i )
{
if ( advancetitle )
D_DoAdvanceTitle();
if ( menuactive )
M_Ticker();
*(_QWORD *)&v0 = G_Ticker();
++gametime;
if ( localcmds[4] < 0 )
localcmds[4] = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int128 v0; // rax
__int64 v1; // r12
__int64 v2; // rbx
char v3; // bp
int i; // ebx

*(_QWORD *)&v0 = I_GetTime();
v1 = v0 - lastmadetic_1;
if ( vid_capfps != 35 && !splashscreen )
{
lastmadetic_1 = v0;
v0 = 0x20C49BA5E353F7CFLL * (unsigned __int128)(((35 * I_GetTimeMS() % 0x3E8uLL) << 13) & 0x1FFFFFFFFFFFFFFFLL);
fractionaltic = *((_QWORD *)&v0 + 1) >> 4;
v2 = v1 - 1;
v3 = 1;
if ( !v1 )
goto LABEL_8;
goto LABEL_6;
}
lastmadetic_1 = v0;
v2 = v1 - 1;
v3 = 0;
if ( v1 )
{
LABEL_6:
while ( 1 )
{
I_StartTic();
*(_QWORD *)&v0 = (unsigned int)maketic_0;
if ( maketic_0 - gametime > 4 )
break;
++maketic_0;
G_BuildTiccmd(&localcmds[12 * ((int)v0 % 8)]);
*(_QWORD *)&v0 = v2 - 1;
if ( !v2 )
break;
--v2;
}
LABEL_8:
i = maketic_0 - gametime;
if ( maketic_0 == gametime && v3 )
return v0;
}
for ( i = maketic_0 - gametime; i; --i )
{
if ( advancetitle )
D_DoAdvanceTitle();
if ( menuactive )
M_Ticker();
*(_QWORD *)&v0 = G_Ticker();
++gametime;
if ( localcmds[4] < 0 )
localcmds[4] = 0;
}
return v0;
}

original_code:
void TryRunTics(void)
{
    static int maketic;
    static uint64_t lastmadetic;
    uint64_t newtics = I_GetTime() - lastmadetic;
    int runtics;
    const _Bool uncapped = !(vid_capfps == 35 || splashscreen);
    lastmadetic += newtics;
    if (uncapped)
        fractionaltic = ((I_GetTimeMS() * 35) % 1000) * (1 << 16) / 1000;
    while (newtics--)
    {
        I_StartTic();
        if (maketic - gametime > 8 / 2)
            break;
        G_BuildTiccmd(&localcmds[maketic++ % 8]);
    }
    if (!(runtics = maketic - gametime) && uncapped)
        return;
    while (runtics--)
    {
        if (advancetitle)
            D_DoAdvanceTitle();
        if (menuactive)
            M_Ticker();
        G_Ticker();
        gametime++;
        if (localcmds[0].buttons & BT_SPECIAL)
            localcmds[0].buttons = 0;
    }
}

canonical_original_code:
void TryRunTics()
{
    static int maketic;
    static unsigned long lastmadetic;
    unsigned long newtics = I_GetTime() - lastmadetic;
    int runtics;
    _Bool uncapped = !(vid_capfps == 35 || splashscreen);
    lastmadetic += newtics;
    if (uncapped)
        fractionaltic = ((I_GetTimeMS() * 35) % 1000) * (1 << 16) / 1000;
    while (newtics--)
    {
        I_StartTic();
        if (maketic - gametime > 8 / 2)
            break;
        G_BuildTiccmd(&localcmds[maketic++ % 8]);
    }
    if (!(runtics = maketic - gametime) && uncapped)
        return;
    while (runtics--)
    {
        if (advancetitle)
            D_DoAdvanceTitle();
        if (menuactive)
            M_Ticker();
        G_Ticker();
        gametime++;
        if (localcmds[0].buttons & BT_SPECIAL)
            localcmds[0].buttons = 0;
    }
}

variable_types: maketic int

variable_types:
lastmadetic
unsigned long

variable_types:
newtics
unsigned long

variable_types: runtics int


repo: bramp/threadnetperf

decompiled_code:
__int64 __fastcall start_daemon(__int64 a1)
{
unsigned int v2; // ebp
int v3; // edi
int *v5; // rbx
char *v6; // rax
int *v7; // rbx
char *v8; // rax
int *v9; // rbx
char *v10; // rax
int *v11; // rbx
char *v12; // rax
char v13[1068]; // [rsp+0h] [rbp-458h] BYREF
int optval; // [rsp+42Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+430h] [rbp-28h] BYREF

optval = 1;
if ( !a1 )
_assert_fail("settings != NULL", "remote.c", 0x18u, "start_daemon");
v2 = listen_socket;
if ( listen_socket != -1 )
_assert_fail("listen_socket == INVALID_SOCKET", "remote.c", 0x19u, "start_daemon");
v3 = socket(2, 1, 6);
listen_socket = v3;
if ( v3 == -1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "%s:%d socket() error (%d) %s\n", "remote.c", 30LL, (unsigned int)*v5, v6);
LABEL_13:
close_ign_signal((unsigned int)listen_socket);
listen_socket = -1;
return v2;
}
if ( setsockopt(v3, 1, 2, &optval, 4u) == -1 )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(
stderr,
"%s:%d setsockopt(SOL_SOCKET, SO_REUSEADDR) error (%d) %s\n",
"remote.c",
36LL,
(unsigned int)*v7,
v8);
goto LABEL_13;
}
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = _bswap_16(43981);
if ( bind(listen_socket, &addr, 0x10u) == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "%s:%d bind() error (%d) %s\n", "remote.c", 47LL, (unsigned int)*v9, v10);
goto LABEL_13;
}
if ( listen(listen_socket, 128) == -1 )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "%s:%d listen() error (%d) %s\n", "remote.c", 53LL, (unsigned int)*v11, v12);
goto LABEL_13;
}
v2 = 0;
if ( (*(_BYTE *)(a1 + 12) & 2) != 0 )
{
addr_to_ipstr(&addr, 16LL, v13, 1058LL);
printf("Daemon is listening on %s\n", v13);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v2; // ebp
int v3; // edi
int *v5; // rbx
char *v6; // rax
int *v7; // rbx
char *v8; // rax
int *v9; // rbx
char *v10; // rax
int *v11; // rbx
char *v12; // rax
char v13[1068]; // [rsp+0h] [rbp-458h] BYREF
int optval; // [rsp+42Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+430h] [rbp-28h] BYREF

optval = 1;
if ( !a1 )
_assert_fail("settings != NULL", "remote.c", 0x18u, "start_daemon");
v2 = listen_socket;
if ( listen_socket != -1 )
_assert_fail("listen_socket == INVALID_SOCKET", "remote.c", 0x19u, "start_daemon");
v3 = socket(2, 1, 6);
listen_socket = v3;
if ( v3 == -1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "%s:%d socket() error (%d) %s\n", "remote.c", 30LL, (unsigned int)*v5, v6);
LABEL_13:
close_ign_signal((unsigned int)listen_socket);
listen_socket = -1;
return v2;
}
if ( setsockopt(v3, 1, 2, &optval, 4u) == -1 )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(
stderr,
"%s:%d setsockopt(SOL_SOCKET, SO_REUSEADDR) error (%d) %s\n",
"remote.c",
36LL,
(unsigned int)*v7,
v8);
goto LABEL_13;
}
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = func0(43981);
if ( bind(listen_socket, &addr, 0x10u) == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "%s:%d bind() error (%d) %s\n", "remote.c", 47LL, (unsigned int)*v9, v10);
goto LABEL_13;
}
if ( listen(listen_socket, 128) == -1 )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "%s:%d listen() error (%d) %s\n", "remote.c", 53LL, (unsigned int)*v11, v12);
goto LABEL_13;
}
v2 = 0;
if ( (*(_BYTE *)(a1 + 12) & 2) != 0 )
{
addr_to_ipstr(&addr, 16LL, v13, 1058LL);
printf("Daemon is listening on %s\n", v13);
}
return v2;
}

original_code:
int start_daemon(const struct settings * settings) {
 struct sockaddr_in addr;
 int one = 1;
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "remote.c", 24, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((listen_socket == (-1)) ? 1 : 0), __extension__ ({ if (listen_socket == (-1)) ; else __assert_fail ("listen_socket == INVALID_SOCKET", "remote.c", 25, __extension__ __PRETTY_FUNCTION__); }));
 listen_socket = socket( 2, SOCK_STREAM, IPPROTO_TCP);
 if ( listen_socket == (-1) ) {
  fprintf(stderr, "%s:%d socket() error (%d) %s\n", "remote.c", 30, (*__errno_location ()), strerror((*__errno_location ())) );
  goto bail;
 }
 if ( setsockopt(listen_socket, 1, 2, (char *)&one, sizeof(one)) == (-1) ) {
  fprintf(stderr, "%s:%d setsockopt(SOL_SOCKET, SO_REUSEADDR) error (%d) %s\n", "remote.c", 36, (*__errno_location ()), strerror((*__errno_location ())) );
  goto bail;
 }
 memset(&addr, 0, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 addr.sin_port = htons( 0xABCD );
 if ( bind(listen_socket, (struct sockaddr *) &addr, sizeof(addr)) == (-1)) {
  fprintf(stderr, "%s:%d bind() error (%d) %s\n", "remote.c", 47, (*__errno_location ()), strerror((*__errno_location ())) );
  goto bail;
 }
 if ( listen(listen_socket, 128) == (-1) ) {
  fprintf(stderr, "%s:%d listen() error (%d) %s\n", "remote.c", 53, (*__errno_location ()), strerror((*__errno_location ())) );
  goto bail;
 }
 if ( settings->verbose ) {
  char addr_str[1025 + 32 + 1];
  addr_to_ipstr((struct sockaddr *)&addr, sizeof(addr), addr_str, sizeof(addr_str));
  printf("Daemon is listening on %s\n", addr_str);
 }
 return 0;
bail:
 close_ign_signal(listen_socket);
 listen_socket = (-1);
 return -1;
}

canonical_original_code:
int start_daemon(struct settings *settings) {
 struct sockaddr_in addr;
 int one = 1;
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "remote.c", 24, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((listen_socket == (-1)) ? 1 : 0), __extension__ ({ if (listen_socket == (-1)) ; else __assert_fail ("listen_socket == INVALID_SOCKET", "remote.c", 25, __extension__ __PRETTY_FUNCTION__); }));
 listen_socket = socket( 2, SOCK_STREAM, IPPROTO_TCP);
 if ( listen_socket == (-1) ) {
  fprintf(stderr, "%s:%d socket() error (%d) %s\n", "remote.c", 30, (*__errno_location ()), strerror((*__errno_location ())) );
  goto bail;
 }
 if ( setsockopt(listen_socket, 1, 2, (char *)&one, sizeof(one)) == (-1) ) {
  fprintf(stderr, "%s:%d setsockopt(SOL_SOCKET, SO_REUSEADDR) error (%d) %s\n", "remote.c", 36, (*__errno_location ()), strerror((*__errno_location ())) );
  goto bail;
 }
 memset(&addr, 0, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 addr.sin_port = htons( 0xABCD );
 if ( bind(listen_socket, (struct sockaddr *) &addr, sizeof(addr)) == (-1)) {
  fprintf(stderr, "%s:%d bind() error (%d) %s\n", "remote.c", 47, (*__errno_location ()), strerror((*__errno_location ())) );
  goto bail;
 }
 if ( listen(listen_socket, 128) == (-1) ) {
  fprintf(stderr, "%s:%d listen() error (%d) %s\n", "remote.c", 53, (*__errno_location ()), strerror((*__errno_location ())) );
  goto bail;
 }
 if ( settings->verbose ) {
  char addr_str[-1];
  addr_to_ipstr((struct sockaddr *)&addr, sizeof(addr), addr_str, sizeof(addr_str));
  printf("Daemon is listening on %s\n", addr_str);
 }
 return 0;
bail:
 close_ign_signal(listen_socket);
 listen_socket = (-1);
 return -1;
}

variable_types: struct settings { unsigned int duration; int type; int protocol; unsigned int daemon; unsigned int verbose; unsigned int dirty; unsigned int timestamp; unsigned int disable_nagles; unsigned int reverse; unsigned int quiet; double confidence_lvl; double confidence_int; unsigned int min_iterations; unsigned int max_iterations; unsigned int message_size; unsigned int socket_size; unsigned int rate; char *server_host; unsigned short port; unsigned int tests; struct test { unsigned int clientcores; unsigned int servercores; unsigned int connections; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; } *test; unsigned int clientcores; unsigned int servercores; unsigned int threaded_model; } *

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

variable_types: one int

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

user_defined_types: struct settings { unsigned int duration; int type; int protocol; unsigned int daemon; unsigned int verbose; unsigned int dirty; unsigned int timestamp; unsigned int disable_nagles; unsigned int reverse; unsigned int quiet; double confidence_lvl; double confidence_int; unsigned int min_iterations; unsigned int max_iterations; unsigned int message_size; unsigned int socket_size; unsigned int rate; char *server_host; unsigned short port; unsigned int tests; struct test *test; unsigned int clientcores; unsigned int servercores; unsigned int threaded_model; }

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

user_defined_types: struct test { unsigned int clientcores; unsigned int servercores; unsigned int connections; struct sockaddr_storage addr; unsigned int addr_len; }


decompiled_code:
__int64 __fastcall connect_daemon(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
int *v4; // rbp
char *v5; // rax
int *v6; // rbp
char *v7; // rax
int *v8; // rbp
char *v9; // rax
char v10[1068]; // [rsp+0h] [rbp-458h] BYREF
int v11; // [rsp+42Ch] [rbp-2Ch] BYREF
__int64 v12[5]; // [rsp+430h] [rbp-28h] BYREF

v11 = 16;
if ( !a1 )
_assert_fail("settings != NULL", "remote.c", 0x51u, "connect_daemon");
v1 = socket(2, 1, 6);
v2 = v1;
if ( v1 == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "%s:%d socket() error (%d) %s\n", "remote.c", 85LL, (unsigned int)*v4, v5);
LABEL_14:
close_ign_signal(v2);
return (unsigned int)-1;
}
if ( (unsigned int)set_socket_timeout(v1, 30000LL) )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "%s:%d set_socket_timeout() error (%d) %s\n", "remote.c", 90LL, (unsigned int)*v6, v7);
goto LABEL_14;
}
v12[0] = 0LL;
v12[1] = 0LL;
if ( (unsigned int)str_to_addr(*(_QWORD *)(a1 + 56), v12, &v11) )
{
fprintf(stderr, "%s:%d str_to_addr() error\n", "remote.c", 96LL);
goto LABEL_14;
}
if ( !WORD1(v12[0]) )
WORD1(v12[0]) = _bswap_16(43981);
if ( (*(_BYTE *)(a1 + 12) & 2) != 0 )
{
addr_to_ipstr(v12, 16LL, v10, 1058LL);
printf("Connecting to daemon %s\n", v10);
}
if ( (unsigned int)connect_ign_signal(v2, v12, 16LL) == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(stderr, "%s:%d connect() error (%d) %s\n", "remote.c", 113LL, (unsigned int)*v8, v9);
goto LABEL_14;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
int *v4; // rbp
char *v5; // rax
int *v6; // rbp
char *v7; // rax
int *v8; // rbp
char *v9; // rax
char v10[1068]; // [rsp+0h] [rbp-458h] BYREF
int v11; // [rsp+42Ch] [rbp-2Ch] BYREF
__int64 v12[5]; // [rsp+430h] [rbp-28h] BYREF

v11 = 16;
if ( !a1 )
_assert_fail("settings != NULL", "remote.c", 0x51u, "connect_daemon");
v1 = socket(2, 1, 6);
v2 = v1;
if ( v1 == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "%s:%d socket() error (%d) %s\n", "remote.c", 85LL, (unsigned int)*v4, v5);
LABEL_14:
close_ign_signal(v2);
return (unsigned int)-1;
}
if ( (unsigned int)set_socket_timeout(v1, 30000LL) )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "%s:%d set_socket_timeout() error (%d) %s\n", "remote.c", 90LL, (unsigned int)*v6, v7);
goto LABEL_14;
}
v12[0] = 0LL;
v12[1] = 0LL;
if ( (unsigned int)str_to_addr(*(_QWORD *)(a1 + 56), v12, &v11) )
{
fprintf(stderr, "%s:%d str_to_addr() error\n", "remote.c", 96LL);
goto LABEL_14;
}
if ( !WORD1(v12[0]) )
WORD1(v12[0]) = func0(43981);
if ( (*(_BYTE *)(a1 + 12) & 2) != 0 )
{
addr_to_ipstr(v12, 16LL, v10, 1058LL);
printf("Connecting to daemon %s\n", v10);
}
if ( (unsigned int)connect_ign_signal(v2, v12, 16LL) == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(stderr, "%s:%d connect() error (%d) %s\n", "remote.c", 113LL, (unsigned int)*v8, v9);
goto LABEL_14;
}
return v2;
}

original_code:
int connect_daemon(const struct settings *settings) {
 int s;
 struct sockaddr_in addr;
 socklen_t addr_len = sizeof(addr);
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "remote.c", 81, __extension__ __PRETTY_FUNCTION__); }));
 s = socket( 2, SOCK_STREAM, IPPROTO_TCP);
 if ( s == (-1) ) {
  fprintf(stderr, "%s:%d socket() error (%d) %s\n", "remote.c", 85, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 if ( set_socket_timeout(s, 30000) ) {
  fprintf(stderr, "%s:%d set_socket_timeout() error (%d) %s\n", "remote.c", 90, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 memset(&addr, 0, sizeof(addr));
 if ( str_to_addr( settings->server_host, (struct sockaddr *)&addr, &addr_len ) ) {
  fprintf(stderr, "%s:%d str_to_addr() error\n", "remote.c", 96);
  goto cleanup;
 }
 if ( addr.sin_port == 0 )
  addr.sin_port = htons( 0xABCD );
 if ( settings->verbose ) {
  char addr_str[1025 + 32 + 1];
  addr_to_ipstr((struct sockaddr *)&addr, sizeof(addr), addr_str, sizeof(addr_str));
  printf("Connecting to daemon %s\n", addr_str);
 }
 if ( connect_ign_signal(s, (struct sockaddr *)&addr, sizeof(addr) ) == (-1) ) {
  fprintf(stderr, "%s:%d connect() error (%d) %s\n", "remote.c", 113, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 return s;
cleanup:
 close_ign_signal(s);
 return (-1);
}

canonical_original_code:
int connect_daemon(struct settings *settings) {
 int s;
 struct sockaddr_in addr;
 unsigned int addr_len = sizeof(addr);
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "remote.c", 81, __extension__ __PRETTY_FUNCTION__); }));
 s = socket( 2, SOCK_STREAM, IPPROTO_TCP);
 if ( s == (-1) ) {
  fprintf(stderr, "%s:%d socket() error (%d) %s\n", "remote.c", 85, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 if ( set_socket_timeout(s, 30000) ) {
  fprintf(stderr, "%s:%d set_socket_timeout() error (%d) %s\n", "remote.c", 90, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 memset(&addr, 0, sizeof(addr));
 if ( str_to_addr( settings->server_host, (struct sockaddr *)&addr, &addr_len ) ) {
  fprintf(stderr, "%s:%d str_to_addr() error\n", "remote.c", 96);
  goto cleanup;
 }
 if ( addr.sin_port == 0 )
  addr.sin_port = htons( 0xABCD );
 if ( settings->verbose ) {
  char addr_str[-1];
  addr_to_ipstr((struct sockaddr *)&addr, sizeof(addr), addr_str, sizeof(addr_str));
  printf("Connecting to daemon %s\n", addr_str);
 }
 if ( connect_ign_signal(s, (struct sockaddr *)&addr, sizeof(addr) ) == (-1) ) {
  fprintf(stderr, "%s:%d connect() error (%d) %s\n", "remote.c", 113, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 return s;
cleanup:
 close_ign_signal(s);
 return (-1);
}

variable_types: s int

user_defined_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }


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

result = close_ign_signal((unsigned int)listen_socket);
listen_socket = -1;
return result;
}

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

result = close_ign_signal((unsigned int)listen_socket);
listen_socket = -1;
return result;
}

original_code:
void close_daemon( ) {
 close_ign_signal(listen_socket);
 listen_socket = (-1);
}

canonical_original_code:
void close_daemon() {
 close_ign_signal(listen_socket);
 listen_socket = (-1);
}


decompiled_code:
__int64 __fastcall send_test(int a1, __int64 a2)
{
__int64 result; // rax
int *v3; // rbx
char *v4; // rax

if ( a1 == -1 )
_assert_fail("s != INVALID_SOCKET", "remote.c", 0x83u, "send_test");
if ( !a2 )
_assert_fail("settings != NULL", "remote.c", 0x84u, "send_test");
result = send_settings();
if ( (_DWORD)result )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "%s:%d send_settings() error (%d) %s\n", "remote.c", 135LL, (unsigned int)*v3, v4);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, __int64 a2)
{
__int64 result; // rax
int *v3; // rbx
char *v4; // rax

if ( a1 == -1 )
_assert_fail("s != INVALID_SOCKET", "remote.c", 0x83u, "send_test");
if ( !a2 )
_assert_fail("settings != NULL", "remote.c", 0x84u, "send_test");
result = send_settings();
if ( (_DWORD)result )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "%s:%d send_settings() error (%d) %s\n", "remote.c", 135LL, (unsigned int)*v3, v4);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int send_test( int s, const struct settings *settings) {
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "remote.c", 131, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "remote.c", 132, __extension__ __PRETTY_FUNCTION__); }));
 if ( send_settings(s, settings) ) {
  fprintf(stderr, "%s:%d send_settings() error (%d) %s\n", "remote.c", 135, (*__errno_location ()), strerror((*__errno_location ())) );
  return -1;
 }
 return 0;
}

canonical_original_code:
int send_test(int s, struct settings *settings) {
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "remote.c", 131, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "remote.c", 132, __extension__ __PRETTY_FUNCTION__); }));
 if ( send_settings(s, settings) ) {
  fprintf(stderr, "%s:%d send_settings() error (%d) %s\n", "remote.c", 135, (*__errno_location ()), strerror((*__errno_location ())) );
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall accept_test(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx
int *v5; // rbp
char *v6; // rax
int *v7; // rbx
char *v8; // rax
int *v9; // rbx
char *v10; // rax
char v11[1068]; // [rsp+0h] [rbp-4C8h] BYREF
int v12; // [rsp+42Ch] [rbp-9Ch] BYREF
char v13[152]; // [rsp+430h] [rbp-98h] BYREF

v12 = 128;
if ( (_DWORD)a1 == -1 )
_assert_fail("listen_socket != INVALID_SOCKET", "remote.c", 0x94u, "accept_test");
if ( !a2 )
_assert_fail("recv_settings != NULL", "remote.c", 0x95u, "accept_test");
v2 = accept_ign_signal(a1, v13, &v12);
v3 = v2;
if ( v2 == -1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "%s:%d accept() error (%d) %s\n", "remote.c", 153LL, (unsigned int)*v5, v6);
}
else if ( (unsigned int)set_socket_timeout(v2, 30000LL) )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "%s:%d set_socket_timeout() error (%d) %s\n", "remote.c", 158LL, (unsigned int)*v7, v8);
v3 = -1;
}
else if ( (unsigned int)read_settings(v3, a2) )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "%s:%d read_settings() error (%d) %s\n", "remote.c", 163LL, (unsigned int)*v9, v10);
v3 = -1;
}
else if ( (*(_BYTE *)(a2 + 12) & 2) != 0 )
{
addr_to_ipstr(v13, 128LL, v11, 1058LL);
printf("Incoming control connection %s\n", v11);
puts("Received tests");
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx
int *v5; // rbp
char *v6; // rax
int *v7; // rbx
char *v8; // rax
int *v9; // rbx
char *v10; // rax
char v11[1068]; // [rsp+0h] [rbp-4C8h] BYREF
int v12; // [rsp+42Ch] [rbp-9Ch] BYREF
char v13[152]; // [rsp+430h] [rbp-98h] BYREF

v12 = 128;
if ( (_DWORD)a1 == -1 )
_assert_fail("listen_socket != INVALID_SOCKET", "remote.c", 0x94u, "accept_test");
if ( !a2 )
_assert_fail("recv_settings != NULL", "remote.c", 0x95u, "accept_test");
v2 = accept_ign_signal(a1, v13, &v12);
v3 = v2;
if ( v2 == -1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "%s:%d accept() error (%d) %s\n", "remote.c", 153LL, (unsigned int)*v5, v6);
}
else if ( (unsigned int)set_socket_timeout(v2, 30000LL) )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "%s:%d set_socket_timeout() error (%d) %s\n", "remote.c", 158LL, (unsigned int)*v7, v8);
v3 = -1;
}
else if ( (unsigned int)read_settings(v3, a2) )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "%s:%d read_settings() error (%d) %s\n", "remote.c", 163LL, (unsigned int)*v9, v10);
v3 = -1;
}
else if ( (*(_BYTE *)(a2 + 12) & 2) != 0 )
{
addr_to_ipstr(v13, 128LL, v11, 1058LL);
printf("Incoming control connection %s\n", v11);
puts("Received tests");
}
return v3;
}

original_code:
int accept_test( int listen_socket, struct settings *recv_settings) {
 int s = (-1);
 struct sockaddr_storage addr;
 socklen_t addr_len = sizeof(addr);
 ((void) sizeof ((listen_socket != (-1)) ? 1 : 0), __extension__ ({ if (listen_socket != (-1)) ; else __assert_fail ("listen_socket != INVALID_SOCKET", "remote.c", 148, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((recv_settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (recv_settings != ((void *)0)) ; else __assert_fail ("recv_settings != NULL", "remote.c", 149, __extension__ __PRETTY_FUNCTION__); }));
 s = accept_ign_signal(listen_socket, (struct sockaddr *)&addr, &addr_len);
 if ( s == (-1)) {
  fprintf(stderr, "%s:%d accept() error (%d) %s\n", "remote.c", 153, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 if ( set_socket_timeout(s, 30000) ) {
  fprintf(stderr, "%s:%d set_socket_timeout() error (%d) %s\n", "remote.c", 158, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 if ( read_settings ( s, recv_settings ) ) {
  fprintf(stderr, "%s:%d read_settings() error (%d) %s\n", "remote.c", 163, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 if ( recv_settings->verbose ) {
  char addr_str[1025 + 32 + 1];
  addr_to_ipstr((struct sockaddr *)&addr, sizeof(addr), addr_str, sizeof(addr_str));
  printf("Incoming control connection %s\n", addr_str);
  printf("Received tests\n");
 }
 return s;
cleanup:
 return (-1);
}

canonical_original_code:
int accept_test(int listen_socket, struct settings *recv_settings) {
 int s = (-1);
 struct sockaddr_storage addr;
 unsigned int addr_len = sizeof(addr);
 ((void) sizeof ((listen_socket != (-1)) ? 1 : 0), __extension__ ({ if (listen_socket != (-1)) ; else __assert_fail ("listen_socket != INVALID_SOCKET", "remote.c", 148, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((recv_settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (recv_settings != ((void *)0)) ; else __assert_fail ("recv_settings != NULL", "remote.c", 149, __extension__ __PRETTY_FUNCTION__); }));
 s = accept_ign_signal(listen_socket, (struct sockaddr *)&addr, &addr_len);
 if ( s == (-1)) {
  fprintf(stderr, "%s:%d accept() error (%d) %s\n", "remote.c", 153, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 if ( set_socket_timeout(s, 30000) ) {
  fprintf(stderr, "%s:%d set_socket_timeout() error (%d) %s\n", "remote.c", 158, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 if ( read_settings ( s, recv_settings ) ) {
  fprintf(stderr, "%s:%d read_settings() error (%d) %s\n", "remote.c", 163, (*__errno_location ()), strerror((*__errno_location ())) );
  goto cleanup;
 }
 if ( recv_settings->verbose ) {
  char addr_str[-1];
  addr_to_ipstr((struct sockaddr *)&addr, sizeof(addr), addr_str, sizeof(addr_str));
  printf("Incoming control connection %s\n", addr_str);
  printf("Received tests\n");
 }
 return s;
cleanup:
 return (-1);
}

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }


decompiled_code:
__int64 __fastcall remote_setup_data(_QWORD *a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // rbx
unsigned int v4; // ebp

if ( !a1 )
_assert_fail("data != NULL", "remote.c", 0xBDu, "remote_setup_data");
if ( *a1 )
_assert_fail("*data == NULL", "remote.c", 0xBEu, "remote_setup_data");
v2 = malloc(8uLL);
v3 = v2;
*a1 = v2;
if ( !v2 )
return (unsigned int)-1;
*v2 = a2;
v4 = create_stats_socket();
v3[1] = v4;
if ( v4 != -1 )
return 0;
fprintf(stderr, "%s:%d create_stats_socket() error\n", "remote.c", 204LL);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // rbx
unsigned int v4; // ebp

if ( !a1 )
_assert_fail("data != NULL", "remote.c", 0xBDu, "remote_setup_data");
if ( *a1 )
_assert_fail("*data == NULL", "remote.c", 0xBEu, "remote_setup_data");
v2 = malloc(8uLL);
v3 = v2;
*a1 = v2;
if ( !v2 )
return (unsigned int)-1;
*v2 = a2;
v4 = create_stats_socket();
v3[1] = v4;
if ( v4 != -1 )
return 0;
fprintf(stderr, "%s:%d create_stats_socket() error\n", "remote.c", 204LL);
return v4;
}

original_code:
int remote_setup_data(void** data, int s) {
 struct remote_data *remote_data;
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "remote.c", 189, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((*data == ((void *)0)) ? 1 : 0), __extension__ ({ if (*data == ((void *)0)) ; else __assert_fail ("*data == NULL", "remote.c", 190, __extension__ __PRETTY_FUNCTION__); }));
 remote_data = malloc( sizeof( *remote_data) );
 *data = remote_data;
 if ( remote_data == ((void *)0) ) {
  return -1;
 }
 remote_data->control_socket = s;
 remote_data->stats_socket = create_stats_socket();
 if( remote_data->stats_socket == (-1) ) {
  fprintf(stderr, "%s:%d create_stats_socket() error\n", "remote.c", 204 );
  return -1;
 }
 return 0;
}

canonical_original_code:
int remote_setup_data(void **data, int s) {
 struct remote_data *remote_data;
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "remote.c", 189, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((*data == ((void *)0)) ? 1 : 0), __extension__ ({ if (*data == ((void *)0)) ; else __assert_fail ("*data == NULL", "remote.c", 190, __extension__ __PRETTY_FUNCTION__); }));
 remote_data = malloc( sizeof( *remote_data) );
 *data = remote_data;
 if ( remote_data == ((void *)0) ) {
  return -1;
 }
 remote_data->control_socket = s;
 remote_data->stats_socket = create_stats_socket();
 if( remote_data->stats_socket == (-1) ) {
  fprintf(stderr, "%s:%d create_stats_socket() error\n", "remote.c", 204 );
  return -1;
 }
 return 0;
}

variable_types:
data
void **

variable_types: struct remote_data { int control_socket; int stats_socket; } *


decompiled_code:
__int64 __fastcall remote_accept(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
int v3; // ebx

result = accept_test((unsigned int)listen_socket, a1);
v3 = result;
if ( (_DWORD)result != -1 )
{
result = remote_setup_data(a2, result);
if ( (_DWORD)result )
{
close(v3);
result = 0xFFFFFFFFLL;
}
}
return result;
}

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

result = func5((unsigned int)listen_socket, a1);
v3 = result;
if ( (_DWORD)result != -1 )
{
result = func6(a2, result);
if ( (_DWORD)result )
{
close(v3);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int remote_accept(struct settings *settings, void **data) {
 int s = (-1);
 s = accept_test( listen_socket, settings );
 if ( s == (-1) )
  return -1;
 if ( remote_setup_data(data, s) ) {
  close(s);
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall remote_connect(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
int v3; // ebx

if ( !a1 )
_assert_fail("settings != NULL", "remote.c", 0xE7u, "remote_connect");
result = connect_daemon(a1);
v3 = result;
if ( (_DWORD)result != -1 )
{
if ( (unsigned int)send_test(result, a1) )
{
fprintf(stderr, "%s:%d send_test() error\n", "remote.c", 239LL);
close(v3);
result = 0xFFFFFFFFLL;
}
else
{
result = remote_setup_data(a2, v3);
if ( (_DWORD)result )
{
close(v3);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
int v3; // ebx

if ( !a1 )
_assert_fail("settings != NULL", "remote.c", 0xE7u, "remote_connect");
result = func2(a1);
v3 = result;
if ( (_DWORD)result != -1 )
{
if ( (unsigned int)func4(result, a1) )
{
fprintf(stderr, "%s:%d send_test() error\n", "remote.c", 239LL);
close(v3);
result = 0xFFFFFFFFLL;
}
else
{
result = func6(a2, v3);
if ( (_DWORD)result )
{
close(v3);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int remote_connect(struct settings *settings, void** data) {
 int s = (-1);
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "remote.c", 231, __extension__ __PRETTY_FUNCTION__); }));
 s = connect_daemon(settings);
 if ( s == (-1) ) {
  return -1;
 }
 if ( send_test( s, settings) ) {
  fprintf(stderr, "%s:%d send_test() error\n", "remote.c", 239 );
  close(s);
  return -1;
 }
 if ( remote_setup_data(data, s) ) {
  close(s);
  return -1;
 }
 return 0;
}

canonical_original_code:
int remote_connect(struct settings *settings, void **data) {
 int s = (-1);
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "remote.c", 231, __extension__ __PRETTY_FUNCTION__); }));
 s = connect_daemon(settings);
 if ( s == (-1) ) {
  return -1;
 }
 if ( send_test( s, settings) ) {
  fprintf(stderr, "%s:%d send_test() error\n", "remote.c", 239 );
  close(s);
  return -1;
 }
 if ( remote_setup_data(data, s) ) {
  close(s);
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall remote_cleanup(__int64 a1, unsigned int *a2)
{
unsigned int v2; // ebp
unsigned int v3; // ebp

if ( !a1 )
_assert_fail("settings != NULL", "remote.c", 0xFEu, "remote_cleanup");
if ( a2 )
{
v2 = *a2;
if ( *a2 != -1 )
{
shutdown(v2, 2);
close_ign_signal(v2);
}
v3 = a2[1];
if ( v3 != -1 )
{
shutdown(v3, 2);
close_ign_signal(v3);
}
free(a2);
}
return 0LL;
}

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

if ( !a1 )
_assert_fail("settings != NULL", "remote.c", 0xFEu, "remote_cleanup");
if ( a2 )
{
v2 = *a2;
if ( *a2 != -1 )
{
shutdown(v2, 2);
close_ign_signal(v2);
}
v3 = a2[1];
if ( v3 != -1 )
{
shutdown(v3, 2);
close_ign_signal(v3);
}
free(a2);
}
return 0LL;
}

original_code:
int remote_cleanup(const struct settings *settings, void* data) {
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "remote.c", 254, __extension__ __PRETTY_FUNCTION__); }));
 if (data) {
  int s = ((struct remote_data*)data)->control_socket;
  if ( s != (-1) ) {
   shutdown ( s, SHUT_RDWR );
   close_ign_signal(s);
  }
  s = ((struct remote_data*)data)->stats_socket;
  if ( s != (-1) ) {
   shutdown ( s, SHUT_RDWR );
   close_ign_signal(s);
  }
  free ( data );
 }
 return 0;
}

canonical_original_code:
int remote_cleanup(struct settings *settings, void *data) {
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "remote.c", 254, __extension__ __PRETTY_FUNCTION__); }));
 if (data) {
  int s = ((struct remote_data*)data)->control_socket;
  if ( s != (-1) ) {
   shutdown ( s, SHUT_RDWR );
   close_ign_signal(s);
  }
  s = ((struct remote_data *)data)->stats_socket;
  if ( s != (-1) ) {
   shutdown ( s, SHUT_RDWR );
   close_ign_signal(s);
  }
  free ( data );
 }
 return 0;
}

variable_types:
data
void *

user_defined_types: struct remote_data { int control_socket; int stats_socket; }


decompiled_code:
__int64 __fastcall remote_collect_results(__int64 a1, __int64 a2, unsigned int (__fastcall *a3)(__int64, __int64 *, unsigned int *), unsigned int *a4)
{
unsigned int v6; // er15
unsigned int v7; // eax
unsigned int v8; // ebx
__int64 result; // rax
int *v10; // rbx
char *v11; // rax
__int64 v12[13]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("settings != NULL", "remote.c", 0x11Bu, "remote_collect_results");
if ( !a2 )
_assert_fail("total_stats != NULL", "remote.c", 0x11Cu, "remote_collect_results");
if ( !a4 )
_assert_fail("data != NULL", "remote.c", 0x11Du, "remote_collect_results");
if ( *(_QWORD *)(a2 + 40) )
_assert_fail("total_stats->duration == 0", "remote.c", 0x120u, "remote_collect_results");
v6 = *a4;
if ( *a4 == -1 )
_assert_fail("s != INVALID_SOCKET", "remote.c", 0x123u, "remote_collect_results");
v7 = *(_DWORD *)(a1 + 84);
v8 = 0;
if ( v7 )
{
while ( 1 )
{
v12[0] = 0LL;
v12[1] = 0LL;
v12[2] = 0LL;
v12[3] = 0LL;
v12[4] = 0LL;
v12[5] = 0LL;
if ( (int)read_results(v6, v12) < 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "%s:%d read_results(%d) error (%d) %s\n", "remote.c", 298LL, v6, (unsigned int)*v10, v11);
goto LABEL_17;
}
if ( a3(a1, v12, a4) )
break;
stats_add(a2, v12);
++v8;
v7 = *(_DWORD *)(a1 + 84);
if ( v7 <= v8 )
goto LABEL_10;
}
fprintf(stderr, "%s:%d print_results() error\n", "remote.c", 303LL);
LABEL_17:
result = 0xFFFFFFFFLL;
}
else
{
LABEL_10:
*(_QWORD *)(a2 + 40) /= (unsigned __int64)v7;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, unsigned int (__fastcall *a3)(__int64, __int64 *, unsigned int *), unsigned int *a4)
{
unsigned int v6; // er15
unsigned int v7; // eax
unsigned int v8; // ebx
__int64 result; // rax
int *v10; // rbx
char *v11; // rax
__int64 v12[13]; // [rsp+0h] [rbp-68h] BYREF

if ( !a1 )
_assert_fail("settings != NULL", "remote.c", 0x11Bu, "remote_collect_results");
if ( !a2 )
_assert_fail("total_stats != NULL", "remote.c", 0x11Cu, "remote_collect_results");
if ( !a4 )
_assert_fail("data != NULL", "remote.c", 0x11Du, "remote_collect_results");
if ( *(_QWORD *)(a2 + 40) )
_assert_fail("total_stats->duration == 0", "remote.c", 0x120u, "remote_collect_results");
v6 = *a4;
if ( *a4 == -1 )
_assert_fail("s != INVALID_SOCKET", "remote.c", 0x123u, "remote_collect_results");
v7 = *(_DWORD *)(a1 + 84);
v8 = 0;
if ( v7 )
{
while ( 1 )
{
v12[0] = 0LL;
v12[1] = 0LL;
v12[2] = 0LL;
v12[3] = 0LL;
v12[4] = 0LL;
v12[5] = 0LL;
if ( (int)read_results(v6, v12) < 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "%s:%d read_results(%d) error (%d) %s\n", "remote.c", 298LL, v6, (unsigned int)*v10, v11);
goto LABEL_17;
}
if ( a3(a1, v12, a4) )
break;
stats_add(a2, v12);
++v8;
v7 = *(_DWORD *)(a1 + 84);
if ( v7 <= v8 )
goto LABEL_10;
}
fprintf(stderr, "%s:%d print_results() error\n", "remote.c", 303LL);
LABEL_17:
result = 0xFFFFFFFFLL;
}
else
{
LABEL_10:
*(_QWORD *)(a2 + 40) /= (unsigned __int64)v7;
result = 0LL;
}
return result;
}

original_code:
int remote_collect_results(const struct settings *settings, struct stats *total_stats, int (*print_results)(const struct settings *, const struct stats *, void * data), void *data) {
 unsigned int core = 0;
 int s;
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "remote.c", 283, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((total_stats != ((void *)0)) ? 1 : 0), __extension__ ({ if (total_stats != ((void *)0)) ; else __assert_fail ("total_stats != NULL", "remote.c", 284, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "remote.c", 285, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((total_stats->duration == 0) ? 1 : 0), __extension__ ({ if (total_stats->duration == 0) ; else __assert_fail ("total_stats->duration == 0", "remote.c", 288, __extension__ __PRETTY_FUNCTION__); }));
 s = ((struct remote_data*)data)->control_socket;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "remote.c", 291, __extension__ __PRETTY_FUNCTION__); }));
 for ( ; core < settings->servercores; core++ ) {
  struct stats stats;
  memset(&stats, 0 , sizeof(stats));
  if ( read_results( s, &stats )< 0) {
   fprintf(stderr, "%s:%d read_results(%d) error (%d) %s\n", "remote.c", 298, s, (*__errno_location ()), strerror((*__errno_location ())) );
   return -1;
  }
  if ( print_results(settings, &stats, data) ) {
   fprintf(stderr, "%s:%d print_results() error\n", "remote.c", 303 );
   return -1;
  }
  stats_add( total_stats, &stats );
 }
 total_stats->duration /= settings->servercores;
 return 0;
}

canonical_original_code:
int remote_collect_results(struct settings *settings, struct stats *total_stats, int (*print_results)(struct settings *, struct stats *, void *data), void *data) {
 unsigned int core = 0;
 int s;
 ((void) sizeof ((settings != ((void *)0)) ? 1 : 0), __extension__ ({ if (settings != ((void *)0)) ; else __assert_fail ("settings != NULL", "remote.c", 283, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((total_stats != ((void *)0)) ? 1 : 0), __extension__ ({ if (total_stats != ((void *)0)) ; else __assert_fail ("total_stats != NULL", "remote.c", 284, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "remote.c", 285, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((total_stats->duration == 0) ? 1 : 0), __extension__ ({ if (total_stats->duration == 0) ; else __assert_fail ("total_stats->duration == 0", "remote.c", 288, __extension__ __PRETTY_FUNCTION__); }));
 s = ((struct remote_data *)data)->control_socket;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "remote.c", 291, __extension__ __PRETTY_FUNCTION__); }));
 for ( ; core < settings->servercores; core++ ) {
  struct stats stats;
  memset(&stats, 0 , sizeof(stats));
  if ( read_results( s, &stats )< 0) {
   fprintf(stderr, "%s:%d read_results(%d) error (%d) %s\n", "remote.c", 298, s, (*__errno_location ()), strerror((*__errno_location ())) );
   return -1;
  }
  if ( print_results(settings, &stats, data) ) {
   fprintf(stderr, "%s:%d print_results() error\n", "remote.c", 303 );
   return -1;
  }
  stats_add( total_stats, &stats );
 }
 total_stats->duration /= settings->servercores;
 return 0;
}

variable_types: struct stats { unsigned int cores; unsigned long long bytes_received; unsigned long long pkts_received; unsigned long long pkts_time; unsigned long long timestamps; unsigned long long duration; } *

variable_types: int (*)(struct settings *, struct stats *, void *data)

variable_types:
core
unsigned int


decompiled_code:
__int64 __fastcall remote_send_results(__int64 a1, __int64 a2, _DWORD *a3)
{
if ( *a3 == -1 )
_assert_fail("s != INVALID_SOCKET", "remote.c", 0x13Fu, "remote_send_results");
return send_results();
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, _DWORD *a3)
{
if ( *a3 == -1 )
_assert_fail("s != INVALID_SOCKET", "remote.c", 0x13Fu, "remote_send_results");
return send_results();
}

original_code:
int remote_send_results (const struct settings *settings, const struct stats *stats, void * data) {
 int s = ((struct remote_data*)data)->control_socket;
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "remote.c", 318, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "remote.c", 319, __extension__ __PRETTY_FUNCTION__); }));
 return send_results(s, stats);
}

canonical_original_code:
int remote_send_results(struct settings *settings, struct stats *stats, void *data) {
 int s = ((struct remote_data*)data)->control_socket;
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "remote.c", 318, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "remote.c", 319, __extension__ __PRETTY_FUNCTION__); }));
 return send_results(s, stats);
}

user_defined_types: struct stats { unsigned int cores; unsigned long long bytes_received; unsigned long long pkts_received; unsigned long long pkts_time; unsigned long long timestamps; unsigned long long duration; }


decompiled_code:
_BOOL8 __fastcall signal_remote(__int64 a1, char a2)
{
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
if ( (_DWORD)a1 == -1 )
_assert_fail("s != INVALID_SOCKET", "remote.c", 0x145u, "signal_remote");
return send_ign_signal(a1, v3, 1LL, 0LL) != 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(__int64 a1, char a2)
{
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
if ( (_DWORD)a1 == -1 )
_assert_fail("s != INVALID_SOCKET", "remote.c", 0x145u, "signal_remote");
return send_ign_signal(a1, v3, 1LL, 0LL) != 1;
}

original_code:
int signal_remote( int s, unsigned char code ) {
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "remote.c", 325, __extension__ __PRETTY_FUNCTION__); }));
 return send_ign_signal(s, &code, 1, 0) != 1;
}

canonical_original_code:
int signal_remote(int s, unsigned char code) {
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "remote.c", 325, __extension__ __PRETTY_FUNCTION__); }));
 return send_ign_signal(s, &code, 1, 0) != 1;
}

variable_types:
code
unsigned char


decompiled_code:
__int64 __fastcall wait_remote(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax
int *v3; // rbp
char *v4; // rax
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( (_DWORD)a1 == -1 )
_assert_fail("s != INVALID_SOCKET", "remote.c", 0x14Bu, "wait_remote");
if ( recv_ign_signal(a1, v5, 1LL, 0LL) == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "remote.c", 334LL, (unsigned int)a1, (unsigned int)*v3, v4);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
if ( v5[0] != a2 )
{
fprintf(
stderr,
"%s:%d wait_remote() invalid code (expected %d got %d)\n",
"remote.c",
336LL,
a2,
(unsigned __int8)v5[0]);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax
int *v3; // rbp
char *v4; // rax
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( (_DWORD)a1 == -1 )
_assert_fail("s != INVALID_SOCKET", "remote.c", 0x14Bu, "wait_remote");
if ( recv_ign_signal(a1, v5, 1LL, 0LL) == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "remote.c", 334LL, (unsigned int)a1, (unsigned int)*v3, v4);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
if ( v5[0] != a2 )
{
fprintf(
stderr,
"%s:%d wait_remote() invalid code (expected %d got %d)\n",
"remote.c",
336LL,
a2,
(unsigned __int8)v5[0]);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int wait_remote( int s, unsigned char code ) {
 unsigned char code2;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "remote.c", 331, __extension__ __PRETTY_FUNCTION__); }));
 if ( recv_ign_signal(s, &code2, 1, 0) == (-1) ) {
  fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "remote.c", 334, s, (*__errno_location ()), strerror((*__errno_location ())) );
 } else if ( code2 != code ) {
  fprintf(stderr, "%s:%d wait_remote() invalid code (expected %d got %d)\n", "remote.c", 336, code, code2 );
 } else {
  return 0;
 }
 return -1;
}

canonical_original_code:
int wait_remote(int s, unsigned char code) {
 unsigned char code2;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "remote.c", 331, __extension__ __PRETTY_FUNCTION__); }));
 if ( recv_ign_signal(s, &code2, 1, 0) == (-1) ) {
  fprintf(stderr, "%s:%d recv(%d) error (%d) %s\n", "remote.c", 334, s, (*__errno_location ()), strerror((*__errno_location ())) );
 } else if ( code2 != code ) {
  fprintf(stderr, "%s:%d wait_remote() invalid code (expected %d got %d)\n", "remote.c", 336, code, code2 );
 } else {
  return 0;
 }
 return -1;
}


decompiled_code:
_BOOL8 __fastcall signal_ready(__int64 a1, unsigned int *a2)
{
__int64 v2; // rdi

if ( !a2 )
_assert_fail("data != NULL", "remote.c", 0x15Au, "signal_ready");
v2 = *a2;
if ( (_DWORD)v2 == -1 )
_assert_fail("s != INVALID_SOCKET", "remote.c", 0x15Cu, "signal_ready");
return signal_remote(v2, 2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(__int64 a1, unsigned int *a2)
{
__int64 v2; // rdi

if ( !a2 )
_assert_fail("data != NULL", "remote.c", 0x15Au, "signal_ready");
v2 = *a2;
if ( (_DWORD)v2 == -1 )
_assert_fail("s != INVALID_SOCKET", "remote.c", 0x15Cu, "signal_ready");
return func12(v2, 2);
}

original_code:
int signal_ready( const struct settings *settings, void *data ) {
 int s;
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "remote.c", 346, __extension__ __PRETTY_FUNCTION__); }));
 s = ((struct remote_data*)data)->control_socket;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "remote.c", 348, __extension__ __PRETTY_FUNCTION__); }));
 return signal_remote( s, 2 );
}

canonical_original_code:
int signal_ready(struct settings *settings, void *data) {
 int s;
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "remote.c", 346, __extension__ __PRETTY_FUNCTION__); }));
 s = ((struct remote_data *)data)->control_socket;
 ((void) sizeof ((s != (-1)) ? 1 : 0), __extension__ ({ if (s != (-1)) ; else __assert_fail ("s != INVALID_SOCKET", "remote.c", 348, __extension__ __PRETTY_FUNCTION__); }));
 return signal_remote( s, 2 );
}