decompiled_code:
void __fastcall xly_chord(int a1)
{
_DWORD *v1; // rax
_DWORD *v2; // rdx
_DWORD *v3; // rax
_DWORD *v4; // rdx
__int64 i; // r15
__int64 k; // r14
__int64 m; // r14
unsigned int j; // ebx
__int64 v9; // rbp
unsigned int l; // ebx
__int64 v11; // rbp
unsigned int n; // ebx
__int64 v13; // rbp

v1 = malloc(4LL * n_ties);
ties_duplicate = v1;
if ( v1 )
{
if ( n_ties > 0 )
{
v2 = &v1[n_ties];
do
*v1++ = -1;
while ( v1 != v2 );
}
v3 = malloc(4LL * n_slurs);
slurs_duplicate = v3;
if ( v3 )
{
if ( n_slurs > 0 )
{
v4 = &v3[n_slurs];
do
*v3++ = -1;
while ( v3 != v4 );
}
fwrite("Chord analysis...\n", 1uLL, 0x12uLL, stderr);
for ( i = 0LL; n_part > (int)i; ++i )
{
v9 = 0LL;
for ( j = 0; *(_DWORD *)(part + 16 * i) > (signed int)j; v9 += 72LL )
{
fprintf(stderr, " ........ part %d, staff %d\n", (unsigned int)i, j);
do_staff_chording(*(_QWORD *)(part + 16 * i + 8) + v9, a1);
++j;
}
}
fwrite("Pending slur analysis...\n", 1uLL, 0x19uLL, stderr);
for ( k = 0LL; n_part > (int)k; ++k )
{
v11 = 0LL;
for ( l = 0; *(_DWORD *)(part + 16 * k) > (signed int)l; v11 += 72LL )
{
fprintf(stderr, " ........ part %d, staff %d\n", (unsigned int)k, l);
do_staff_slur_pending(*(_QWORD *)(part + 16 * k + 8) + v11);
++l;
}
}
fwrite("Multibar rest aggregation...\n", 1uLL, 0x1DuLL, stderr);
for ( m = 0LL; n_part > (int)m; ++m )
{
v13 = 0LL;
for ( n = 0; *(_DWORD *)(part + 16 * m) > (signed int)n; v13 += 72LL )
{
fprintf(stderr, " ........ part %d, staff %d\n", (unsigned int)m, n);
do_staff_multibar_aggregate(*(_QWORD *)(part + 16 * m + 8) + v13);
++n;
}
}
free(ties_duplicate);
free(slurs_duplicate);
}
else
{
fprintf(stderr, "%s:%d malloc(%zd) fails\n", "xly_chord.c", 290LL, 4LL * n_slurs);
}
}
else
{
fprintf(stderr, "%s:%d malloc(%zd) fails\n", "xly_chord.c", 281LL, 4LL * n_ties);
}
}

canonical_decompiled_code:
void __fastcall func5(int a1)
{
_DWORD *v1; // rax
_DWORD *v2; // rdx
_DWORD *v3; // rax
_DWORD *v4; // rdx
__int64 i; // r15
__int64 k; // r14
__int64 m; // r14
unsigned int j; // ebx
__int64 v9; // rbp
unsigned int l; // ebx
__int64 v11; // rbp
unsigned int n; // ebx
__int64 v13; // rbp

v1 = malloc(4LL * n_ties);
ties_duplicate = v1;
if ( v1 )
{
if ( n_ties > 0 )
{
v2 = &v1[n_ties];
do
*v1++ = -1;
while ( v1 != v2 );
}
v3 = malloc(4LL * n_slurs);
slurs_duplicate = v3;
if ( v3 )
{
if ( n_slurs > 0 )
{
v4 = &v3[n_slurs];
do
*v3++ = -1;
while ( v3 != v4 );
}
fwrite("Chord analysis...\n", 1uLL, 0x12uLL, stderr);
for ( i = 0LL; n_part > (int)i; ++i )
{
v9 = 0LL;
for ( j = 0; *(_DWORD *)(part + 16 * i) > (signed int)j; v9 += 72LL )
{
fprintf(stderr, " ........ part %d, staff %d\n", (unsigned int)i, j);
func3(*(_QWORD *)(part + 16 * i + 8) + v9, a1);
++j;
}
}
fwrite("Pending slur analysis...\n", 1uLL, 0x19uLL, stderr);
for ( k = 0LL; n_part > (int)k; ++k )
{
v11 = 0LL;
for ( l = 0; *(_DWORD *)(part + 16 * k) > (signed int)l; v11 += 72LL )
{
fprintf(stderr, " ........ part %d, staff %d\n", (unsigned int)k, l);
func1(*(_QWORD *)(part + 16 * k + 8) + v11);
++l;
}
}
fwrite("Multibar rest aggregation...\n", 1uLL, 0x1DuLL, stderr);
for ( m = 0LL; n_part > (int)m; ++m )
{
v13 = 0LL;
for ( n = 0; *(_DWORD *)(part + 16 * m) > (signed int)n; v13 += 72LL )
{
fprintf(stderr, " ........ part %d, staff %d\n", (unsigned int)m, n);
func4(*(_QWORD *)(part + 16 * m + 8) + v13);
++n;
}
}
free(ties_duplicate);
free(slurs_duplicate);
}
else
{
fprintf(stderr, "%s:%d malloc(%zd) fails\n", "xly_chord.c", 290LL, 4LL * n_slurs);
}
}
else
{
fprintf(stderr, "%s:%d malloc(%zd) fails\n", "xly_chord.c", 281LL, 4LL * n_ties);
}
}

original_code:
void
xly_chord(int do_chording)
{
    int p;
    int f;
    int i;
    ties_duplicate = malloc(n_ties * sizeof *ties_duplicate);
    if (ties_duplicate == ((void *)0)) {
        fprintf(stderr, "%s:%d malloc(%zd) fails\n", "xly_chord.c", 281,
                n_ties * sizeof *ties_duplicate);
        return;
    }
    for (i = 0; i < n_ties; i++) {
        ties_duplicate[i] = -1;
    }
    slurs_duplicate = malloc(n_slurs * sizeof *slurs_duplicate);
    if (slurs_duplicate == ((void *)0)) {
        fprintf(stderr, "%s:%d malloc(%zd) fails\n", "xly_chord.c", 290,
                n_slurs * sizeof *slurs_duplicate);
        return;
    }
    for (i = 0; i < n_slurs; i++) {
        slurs_duplicate[i] = -1;
    }
    fprintf(stderr, "Chord analysis...\n");
    for (p = 0; p < n_part; p++) {
        for (f = 0; f < part[p].n_staff; f++) {
            fprintf(stderr, "      ........ part %d, staff %d\n", p, f);
            do_staff_chording(&part[p].staff[f], do_chording);
        }
    }
    fprintf(stderr, "Pending slur analysis...\n");
    for (p = 0; p < n_part; p++) {
        for (f = 0; f < part[p].n_staff; f++) {
            fprintf(stderr, "      ........ part %d, staff %d\n", p, f);
            do_staff_slur_pending(&part[p].staff[f]);
        }
    }
    fprintf(stderr, "Multibar rest aggregation...\n");
    for (p = 0; p < n_part; p++) {
        for (f = 0; f < part[p].n_staff; f++) {
            fprintf(stderr, "      ........ part %d, staff %d\n", p, f);
            do_staff_multibar_aggregate(&part[p].staff[f]);
        }
    }
    free(ties_duplicate);
    free(slurs_duplicate);
}


repo: rfhh/lily-contribs

decompiled_code:
void xly_chord_init()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void
xly_chord_init(void)
{
}

canonical_original_code:
void xly_chord_init()
{
}

return_type: void


decompiled_code:
void xly_chord_end()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void
xly_chord_end(void)
{
}

canonical_original_code:
void xly_chord_end()
{
}


doindent

decompiled_code:
int __fastcall doindent(int a1)
{
int v1; // edi
int v2; // ebx
int result; // eax

v1 = a1 - 1;
if ( v1 && 4 * v1 )
{
v2 = 0;
do
{
result = putchar(32);
++v2;
}
while ( 4 * v1 != v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
int v1; // edi
int v2; // ebx
int result; // eax

v1 = a1 - 1;
if ( v1 && 4 * v1 )
{
v2 = 0;
do
{
result = putchar(32);
++v2;
}
while ( 4 * v1 != v2 );
}
return result;
}

original_code:
void
doindent(unsigned indent)
{
    int i;
    if ((--indent) <= 0 )
        return;
    indent *= 4;
    for (i = 0; i < indent; i++)
        printf(" ");
}

canonical_original_code:
void doindent(unsigned int indent)
{
    int i;
    if ((--indent) <= 0 )
        return;
    indent *= 4;
    for (i = 0; i < indent; i++)
        printf(" ");
}

variable_types:
indent
unsigned int

variable_types: i int


printSHORT

decompiled_code:
__int64 __fastcall printSHORT(__int16 a1, const char *a2)
{
__int64 result; // rax

if ( xly_verbose )
result = verbose_printf(" %s=%d", a2, (unsigned int)a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 a1, const char *a2)
{
__int64 result; // rax

if ( xly_verbose )
result = verbose_printf(" %s=%d", a2, (unsigned int)a1);
return result;
}

original_code:
void
printSHORT(SHORT h, const char *strComment)
{
    ((xly_verbose) ? verbose_printf(" %s=%d", strComment, h) : RIFFIO_OK);
}

canonical_original_code:
void printSHORT(short h, char *strComment)
{
    ((xly_verbose) ? verbose_printf(" %s=%d", strComment, h) : RIFFIO_OK);
}

variable_types: h short

variable_types:
strComment
char *


printSTROFFSET

decompiled_code:
__int64 __fastcall printSTROFFSET(__int64 a1, const char *a2)
{
__int64 result; // rax

if ( xly_verbose )
result = verbose_printf(" // %s\n", a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
__int64 result; // rax

if ( xly_verbose )
result = verbose_printf(" // %s\n", a2);
return result;
}

original_code:
void
printSTROFFSET(STROFFSET offset, const char *strComment)
{
    ((xly_verbose) ? verbose_printf(" // %s\n", strComment) : RIFFIO_OK);
}

canonical_original_code:
void printSTROFFSET(long offset, char *strComment)
{
    ((xly_verbose) ? verbose_printf(" // %s\n", strComment) : RIFFIO_OK);
}

variable_types: offset long


printRATIONAL

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

if ( xly_verbose )
result = verbose_printf(" %s=%d/%d", a2, (unsigned int)(__int16)a1, (unsigned int)(a1 >> 16));
return result;
}

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

if ( xly_verbose )
result = verbose_printf(" %s=%d/%d", a2, (unsigned int)(__int16)a1, (unsigned int)(a1 >> 16));
return result;
}

original_code:
void
printRATIONAL(RATIONAL r, const char *strComment)
{
    ((xly_verbose) ? verbose_printf(" %s=%d/%d", strComment, r.numerator, r.denominator) : RIFFIO_OK);
}

canonical_original_code:
void printRATIONAL(struct RATIONAL r, char *strComment)
{
    ((xly_verbose) ? verbose_printf(" %s=%d/%d", strComment, r.numerator, r.denominator) : RIFFIO_OK);
}

variable_types: struct RATIONAL { short numerator; short denominator; }


printBYTE

decompiled_code:
__int64 __fastcall printBYTE(unsigned __int8 a1, const char *a2)
{
__int64 result; // rax

if ( xly_verbose )
result = verbose_printf(" %s=%u", a2, a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1, const char *a2)
{
__int64 result; // rax

if ( xly_verbose )
result = verbose_printf(" %s=%u", a2, a1);
return result;
}

original_code:
void
printBYTE(BYTE b, const char *strComment)
{
    ((xly_verbose) ? verbose_printf(" %s=%u", strComment, b) : RIFFIO_OK);
}

canonical_original_code:
void printBYTE(unsigned char b, char *strComment)
{
    ((xly_verbose) ? verbose_printf(" %s=%u", strComment, b) : RIFFIO_OK);
}

variable_types:
b
unsigned char


printSIGNEDBYTE

decompiled_code:
__int64 __fastcall printSIGNEDBYTE(char a1, const char *a2)
{
__int64 result; // rax

if ( xly_verbose )
result = verbose_printf(" %s=%d", a2, (unsigned int)a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1, const char *a2)
{
__int64 result; // rax

if ( xly_verbose )
result = verbose_printf(" %s=%d", a2, (unsigned int)a1);
return result;
}

original_code:
void
printSIGNEDBYTE(SIGNEDBYTE sb, const char *strComment)
{
    ((xly_verbose) ? verbose_printf(" %s=%d", strComment, sb) : RIFFIO_OK);
}

canonical_original_code:
void printSIGNEDBYTE(char sb, char *strComment)
{
    ((xly_verbose) ? verbose_printf(" %s=%d", strComment, sb) : RIFFIO_OK);
}

variable_types: sb char


decompiled_code:
__int64 xly_init()
{
xly_partial_init();
xly_chord_init();
xly_repeat_init();
xly_voice_init();
return xly_dump_init();
}

canonical_decompiled_code:
__int64 func1()
{
xly_partial_init();
xly_chord_init();
xly_repeat_init();
xly_voice_init();
return xly_dump_init();
}

original_code:
void
xly_init(void)
{
    xly_partial_init();
    xly_chord_init();
    xly_repeat_init();
    xly_voice_init();
    xly_dump_init();
}

canonical_original_code:
void xly_init()
{
    xly_partial_init();
    xly_chord_init();
    xly_repeat_init();
    xly_voice_init();
    xly_dump_init();
}


decompiled_code:
__int64 xly_end()
{
xly_dump_end();
xly_partial_end();
xly_repeat_end();
xly_chord_end();
return xly_voice_end();
}

canonical_decompiled_code:
__int64 func2()
{
xly_dump_end();
xly_partial_end();
xly_repeat_end();
xly_chord_end();
return xly_voice_end();
}

original_code:
void
xly_end(void)
{
    xly_dump_end();
    xly_partial_end();
    xly_repeat_end();
    xly_chord_end();
    xly_voice_end();
}

canonical_original_code:
void xly_end()
{
    xly_dump_end();
    xly_partial_end();
    xly_repeat_end();
    xly_chord_end();
    xly_voice_end();
}


decompiled_code:
__int64 xly_partial()
{
__int64 i; // r14
__int64 result; // rax
__int64 v2; // rdx
__int64 j; // rbx
_BYTE v4[72]; // [rsp+0h] [rbp-48h] BYREF

fwrite("Find partial start...\n", 1uLL, 0x16uLL, stderr);
_gmpq_init(v4);
for ( i = 0LL; n_part > (int)i; ++i )
{
v2 = part + 16 * i;
for ( j = 0LL; *(_DWORD *)v2 > (int)j; ++j )
{
do_staff_partial((__int64)v4, *(_QWORD *)(v2 + 8) + 72 * j);
if ( (unsigned int)j | (unsigned int)i )
{
if ( !(unsigned int)_gmpq_equal(v4, &xly_t_partial) )
{
fprintf(stderr, "Uh oh -- partial part %d staff %d = ", (unsigned int)i, (unsigned int)j);
_gmpq_out_str(stderr, 10LL, v4);
fwrite(" global = ", 1uLL, 0xAuLL, stderr);
_gmpq_out_str(stderr, 10LL, &xly_t_partial);
fputc(10, stderr);
}
}
else
{
_gmpq_set(&xly_t_partial, v4);
}
v2 = part + 16 * i;
}
}
result = _gmpq_clear(v4);
if ( xly_verbose )
{
result = verbose_printf("Partial = ");
if ( xly_verbose )
{
result = _gmpq_out_str(stderr, 10LL, &xly_t_partial);
if ( xly_verbose )
result = verbose_printf("\n");
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 i; // r14
__int64 result; // rax
__int64 v2; // rdx
__int64 j; // rbx
_BYTE v4[72]; // [rsp+0h] [rbp-48h] BYREF

fwrite("Find partial start...\n", 1uLL, 0x16uLL, stderr);
_gmpq_init(v4);
for ( i = 0LL; n_part > (int)i; ++i )
{
v2 = part + 16 * i;
for ( j = 0LL; *(_DWORD *)v2 > (int)j; ++j )
{
func0((__int64)v4, *(_QWORD *)(v2 + 8) + 72 * j);
if ( (unsigned int)j | (unsigned int)i )
{
if ( !(unsigned int)_gmpq_equal(v4, &xly_t_partial) )
{
fprintf(stderr, "Uh oh -- partial part %d staff %d = ", (unsigned int)i, (unsigned int)j);
_gmpq_out_str(stderr, 10LL, v4);
fwrite(" global = ", 1uLL, 0xAuLL, stderr);
_gmpq_out_str(stderr, 10LL, &xly_t_partial);
fputc(10, stderr);
}
}
else
{
_gmpq_set(&xly_t_partial, v4);
}
v2 = part + 16 * i;
}
}
result = _gmpq_clear(v4);
if ( xly_verbose )
{
result = verbose_printf("Partial = ");
if ( xly_verbose )
{
result = _gmpq_out_str(stderr, 10LL, &xly_t_partial);
if ( xly_verbose )
result = verbose_printf("\n");
}
}
return result;
}

original_code:
void
xly_partial(void)
{
    int p;
    int f;
    mpq_t t;
    fprintf(stderr, "Find partial start...\n");
    __gmpq_init(t);
    for (p = 0; p < n_part; p++) {
        for (f = 0; f < part[p].n_staff; f++) {
            do_staff_partial(&t, &part[p].staff[f]);
            if (p == 0 && f == 0) {
                __gmpq_set(xly_t_partial, t);
            } else if (! __gmpq_equal(t, xly_t_partial)) {
                fprintf(stderr, "Uh oh -- partial part %d staff %d = ", p, f);
                __gmpq_out_str(stderr, 10, t);
                fprintf(stderr, " global = ");
                __gmpq_out_str(stderr, 10, xly_t_partial);
                fprintf(stderr, "\n");
            }
        }
    }
    __gmpq_clear(t);
    ((xly_verbose) ? verbose_printf("Partial = ") : RIFFIO_OK);
    ((xly_verbose) ? __gmpq_out_str(stderr, 10, xly_t_partial) : RIFFIO_OK);
    ((xly_verbose) ? verbose_printf("\n") : RIFFIO_OK);
}

canonical_original_code:
void xly_partial()
{
    int p;
    int f;
    struct __mpq_struct t[1];
    fprintf(stderr, "Find partial start...\n");
    __gmpq_init(t);
    for (p = 0; p < n_part; p++) {
        for (f = 0; f < part[p].n_staff; f++) {
            do_staff_partial(&t, &part[p].staff[f]);
            if (p == 0 && f == 0) {
                __gmpq_set(xly_t_partial, t);
            } else if (! __gmpq_equal(t, xly_t_partial)) {
                fprintf(stderr, "Uh oh -- partial part %d staff %d = ", p, f);
                __gmpq_out_str(stderr, 10, t);
                fprintf(stderr, " global = ");
                __gmpq_out_str(stderr, 10, xly_t_partial);
                fprintf(stderr, "\n");
            }
        }
    }
    __gmpq_clear(t);
    ((xly_verbose) ? verbose_printf("Partial = ") : RIFFIO_OK);
    ((xly_verbose) ? __gmpq_out_str(stderr, 10, xly_t_partial) : RIFFIO_OK);
    ((xly_verbose) ? verbose_printf("\n") : RIFFIO_OK);
}

variable_types: p int

variable_types: f int

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

user_defined_types: struct __mpq_struct { struct __mpz_struct _mp_num; struct __mpz_struct _mp_den; }


decompiled_code:
__int64 xly_partial_init()
{
return _gmpq_init(&xly_t_partial);
}

canonical_decompiled_code:
__int64 func2()
{
return _gmpq_init(&xly_t_partial);
}

original_code:
void
xly_partial_init(void)
{
    __gmpq_init(xly_t_partial);
}

canonical_original_code:
void xly_partial_init()
{
    __gmpq_init(xly_t_partial);
}


decompiled_code:
void xly_partial_end()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void
xly_partial_end(void)
{
}

canonical_original_code:
void xly_partial_end()
{
}


decompiled_code:
void __fastcall increase_tuplets(int a1)
{
if ( n_tuplet <= a1 )
{
n_tuplet = a1 + 1;
global_tuplet = realloc(global_tuplet, 56LL * (a1 + 1));
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
if ( n_tuplet <= a1 )
{
n_tuplet = a1 + 1;
global_tuplet = realloc(global_tuplet, 56LL * (a1 + 1));
}
}

original_code:
static void
increase_tuplets(int ID)
{
    if (ID < n_tuplet) {
        return;
    }
    n_tuplet = ID + 1;
    global_tuplet = realloc(global_tuplet, n_tuplet * sizeof(*global_tuplet));
}

variable_types: ID int


repo: rfjakob/earlyoom

decompiled_code:
void __fastcall handle_sigterm(unsigned int a1)
{
printf("blocking SIGTERM %d\n", a1);
}

canonical_decompiled_code:
void __fastcall func7(unsigned int a1)
{
printf("blocking SIGTERM %d\n", a1);
}

original_code:
void handle_sigterm(int sig)
{
    printf("blocking SIGTERM %d\n", sig);
}

variable_types: sig int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
size_t v4; // r12
__int64 v5; // r14
__int64 v6; // rbp
_BYTE *v7; // rax
int v8; // edx
__int64 v9; // r15
__int64 v10; // r15
struct timeval v11; // [rsp+0h] [rbp-68h] BYREF
struct timeval tv; // [rsp+10h] [rbp-58h] BYREF
unsigned __int64 v13; // [rsp+28h] [rbp-40h]

v13 = __readfsqword(0x28u);
v3 = sysconf(30);
v4 = 10 * v3;
signal(15, (__sighandler_t)handle_sigterm);
gettimeofday(&v11, 0LL);
v5 = 0LL;
v6 = 0LL;
while ( 1 )
{
do
{
while ( 1 )
{
v7 = malloc(v4);
if ( v7 )
break;
puts("malloc failed");
}
v8 = 10;
do
{
*v7 = -85;
v7 += v3;
--v8;
}
while ( v8 );
++v6;
}
while ( v6 != 1000 * (v6 / 1000) );
v9 = v6 * v4 + 0xFFFFF;
if ( ((v6 * v4) & 0x8000000000000000LL) == 0LL )
v9 = v6 * v4;
v10 = v9 >> 20;
gettimeofday(&tv, 0LL);
printf(
"%4ld MiB (%4ld MiB/s)\n",
v10,
1000000 * (v10 - v5) / (tv.tv_usec + 1000000 * (tv.tv_sec - v11.tv_sec) - v11.tv_usec));
gettimeofday(&v11, 0LL);
v5 = v10;
}
}

original_code:
int main()
{
    long page_size = sysconf(_SC_PAGESIZE);
    long bs = page_size * 10;
    long cnt = 0, last_sum = 0;
    struct timeval tv1;
    signal(15, handle_sigterm);
    gettimeofday(&tv1, ((void *)0));
    while (1) {
        char* p = malloc(bs);
        if (!p) {
            printf("malloc failed\n");
            continue;
        }
        for (int i = 0; i < 10; i++) {
            p[i * page_size] = 0xab;
        }
        cnt++;
        if (cnt % 1000 == 0) {
            long sum = bs * cnt / 1024 / 1024;
            struct timeval tv2;
            gettimeofday(&tv2, ((void *)0));
            long delta = tv2.tv_sec - tv1.tv_sec;
            delta *= 1000000;
            delta = delta + tv2.tv_usec - tv1.tv_usec;
            long mbps = (sum - last_sum) * 1000000 / delta;
            printf("%4ld MiB (%4ld MiB/s)\n", sum, mbps);
            last_sum = sum;
            gettimeofday(&tv1, ((void *)0));
        }
    }
}

canonical_original_code:
int main()
{
    long page_size = sysconf(_SC_PAGESIZE);
    long bs = page_size * 10;
    long cnt = 0; long last_sum = 0;
    struct timeval tv1;
    signal(15, handle_sigterm);
    gettimeofday(&tv1, ((void *)0));
    while (1) {
        char *p = malloc(bs);
        if (!p) {
            printf("malloc failed\n");
            continue;
        }
        for (int i = 0; i < 10; i++) {
            p[i * page_size] = 0xab;
        }
        cnt++;
        if (cnt % 1000 == 0) {
            long sum = bs * cnt / 1024 / 1024;
            struct timeval tv2;
            gettimeofday(&tv2, ((void *)0));
            long delta = tv2.tv_sec - tv1.tv_sec;
            delta *= 1000000;
            delta = delta + tv2.tv_usec - tv1.tv_usec;
            long mbps = (sum - last_sum) * 1000000 / delta;
            printf("%4ld MiB (%4ld MiB/s)\n", sum, mbps);
            last_sum = sum;
            gettimeofday(&tv1, ((void *)0));
        }
    }
}

variable_types: bs long

variable_types: cnt long

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

variable_types:
p
char *

variable_types: sum long

variable_types: delta long

variable_types: mbps long

return_type: int


randf

repo: rgharpuray/VoIP-opt

decompiled_code:
float randf()
{
return (float)rand() * 4.6566129e-10;
}

canonical_decompiled_code:
float func0()
{
return (float)rand() * 4.6566129e-10;
}

original_code:
float randf()
{
  return ((float)rand())/(float)2147483647;
}

return_type: float


randgaussian

decompiled_code:
float randgaussian()
{
float v0; // xmm0_4
double v1; // xmm0_8
float v2; // xmm0_4
double v4; // [rsp+8h] [rbp-10h]

v0 = randf();
v1 = (float)(logf(v0) * -2.0);
if ( v1 < 0.0 )
v4 = sqrt(v1);
else
v4 = sqrt(v1);
v2 = randf();
return cosf(v2 * 6.283185) * v4;
}

canonical_decompiled_code:
float func1()
{
float v0; // xmm0_4
double v1; // xmm0_8
float v2; // xmm0_4
double v4; // [rsp+8h] [rbp-10h]

v0 = func0();
v1 = (float)(logf(v0) * -2.0);
if ( v1 < 0.0 )
v4 = sqrt(v1);
else
v4 = sqrt(v1);
v2 = func0();
return cosf(v2 * 6.283185) * v4;
}

original_code:
float randgaussian()
{
  return sqrt(-2*logf(randf()))*cosf(2*pi*randf());
}


decompiled_code:
__int64 markov_transition()
{
float v0; // xmm0_4
__int64 result; // rax

v0 = randf();
if ( !nstates )
LABEL_5:
_assert_fail("0", "src/markov.c", 0x29u, "markov_transition");
result = 0LL;
while ( 1 )
{
v0 = v0 - *(float *)(transition_rates + 4LL * (unsigned int)(state * nstates) + 4 * result);
if ( v0 <= 0.0 )
break;
if ( ++result == nstates )
goto LABEL_5;
}
state = result;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
float v0; // xmm0_4
__int64 result; // rax

v0 = func0();
if ( !nstates )
LABEL_5:
_assert_fail("0", "src/markov.c", 0x29u, "markov_transition");
result = 0LL;
while ( 1 )
{
v0 = v0 - *(float *)(transition_rates + 4LL * (unsigned int)(state * nstates) + 4 * result);
if ( v0 <= 0.0 )
break;
if ( ++result == nstates )
goto LABEL_5;
}
state = result;
return result;
}

original_code:
void markov_transition()
{
  float random = randf();
  float* ptr = &(transition_rates[nstates*state]);
  for(int i = 0; i < nstates; i++) {
    random -= ptr[i];
    if(random <= 0.0f) {
      state = i;
      return;
    }
  }
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/markov.c", 41, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void markov_transition()
{
  float random = randf();
  float *ptr = &(transition_rates[nstates*state]);
  for(int i = 0; i < nstates; i++) {
    random -= ptr[i];
    if(random <= 0.0f) {
      state = i;
      return;
    }
  }
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "src/markov.c", 41, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: random float

variable_types:
ptr
float *

variable_types: i int


decompiled_code:
_BOOL8 markov_emission()
{
int v0; // ebx

v0 = state;
if ( state < 0 || state >= (unsigned int)nstates )
_assert_fail("(state >= 0)&&(state < nstates)", "src/markov.c", 0x31u, "markov_emission");
return *(float *)(drop_rates + 4LL * v0) > randf();
}

canonical_decompiled_code:
_BOOL8 func3()
{
int v0; // ebx

v0 = state;
if ( state < 0 || state >= (unsigned int)nstates )
_assert_fail("(state >= 0)&&(state < nstates)", "src/markov.c", 0x31u, "markov_emission");
return *(float *)(drop_rates + 4LL * v0) > func0();
}

canonical_original_code:
enum mmvalue markov_emission()
{
  ((void) sizeof (((state >= 0)&&(state < nstates)) ? 1 : 0), __extension__ ({ if ((state >= 0)&&(state < nstates)) ; else __assert_fail ("(state >= 0)&&(state < nstates)", "src/markov.c", 49, __extension__ __PRETTY_FUNCTION__); }));
  float random = randf();
  return (random < drop_rates[state]) ? MM_DROP : MM_ACCEPT;
}

return_type: enum mmvalue { MM_ACCEPT=0, MM_DROP=1 }


decompiled_code:
float *__fastcall markov_initmodel_lowhigh(__m128i a1, __m128i a2, float a3, float a4)
{
_DWORD *v4; // rax
float *result; // rax

nstates = 2;
v4 = malloc(8uLL);
drop_rates = (__int64)v4;
*v4 = _mm_cvtsi128_si32(a1);
v4[1] = _mm_cvtsi128_si32(a2);
result = (float *)malloc(0x10uLL);
transition_rates = (__int64)result;
*result = 1.0 - (float)(1.0 / a3);
result[1] = 1.0 / a3;
result[2] = 1.0 / a4;
result[3] = 1.0 - (float)(1.0 / a4);
state = 0;
return result;
}

canonical_decompiled_code:
float *__fastcall func4(__m128i a1, __m128i a2, float a3, float a4)
{
_DWORD *v4; // rax
float *result; // rax

nstates = 2;
v4 = malloc(8uLL);
drop_rates = (__int64)v4;
*v4 = _mm_cvtsi128_si32(a1);
v4[1] = _mm_cvtsi128_si32(a2);
result = (float *)malloc(0x10uLL);
transition_rates = (__int64)result;
*result = 1.0 - (float)(1.0 / a3);
result[1] = 1.0 / a3;
result[2] = 1.0 / a4;
result[3] = 1.0 - (float)(1.0 / a4);
state = 0;
return result;
}

original_code:
void markov_initmodel_lowhigh(float low_lr, float high_lr, float low_meanlength, float high_meanlength)
{
  nstates = 2;
  drop_rates = malloc(2*sizeof(float));
  drop_rates[0] = low_lr;
  drop_rates[1] = high_lr;
  transition_rates = malloc(4*sizeof(float));
  transition_rates[0] = 1.0f - 1.0f/low_meanlength;
  transition_rates[1] = 1.0f/low_meanlength;
  transition_rates[2] = 1.0f/high_meanlength;
  transition_rates[3] = 1.0f - 1.0f/high_meanlength;
  state = 0;
}


original_code:
static void skip_string(void)
{
  while (*p)
    p++;
  p++;
}

canonical_original_code:
static void skip_string()
{
  while (*p)
    p++;
  p++;
}


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

result = "WEAK";
if ( (a1 & 0x40) == 0 )
{
result = "GLOB";
if ( (a1 & 8) == 0 )
{
result = "LOCL";
if ( (a1 & 0x20) != 0 )
result = "COMM";
}
}
return result;
}

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

result = "WEAK";
if ( (a1 & 0x40) == 0 )
{
result = "GLOB";
if ( (a1 & 8) == 0 )
{
result = "LOCL";
if ( (a1 & 0x20) != 0 )
result = "COMM";
}
}
return result;
}

original_code:
static const char *bind_name(int flags)
{
  if (flags & 64)
    return "WEAK";
  if (flags & 8)
    return "GLOB";
  if (flags & 32)
    return "COMM";
  return "LOCL";
}

canonical_original_code:
static char *bind_name(int flags)
{
  if (flags & 64)
    return "WEAK";
  if (flags & 8)
    return "GLOB";
  if (flags & 32)
    return "COMM";
  return "LOCL";
}

variable_types: flags int

return_type: char *


decompiled_code:
const char *__fastcall def_name(__int64 a1, __int64 a2, int a3)
{
int v4; // edx
const char *result; // rax
int v6; // eax

v4 = *(_DWORD *)(a1 + 16);
result = "*UND*";
if ( v4 != 2 )
{
result = "*ABS*";
if ( v4 != 3 )
{
result = "???";
if ( v4 == 1 )
{
v6 = *(_DWORD *)(a1 + 24);
if ( v6 <= a3 && v6 > 0 )
result = *(const char **)(a2 + 32LL * v6 - 24);
else
result = "???";
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func9(__int64 a1, __int64 a2, int a3)
{
int v4; // edx
const char *result; // rax
int v6; // eax

v4 = *(_DWORD *)(a1 + 16);
result = "*UND*";
if ( v4 != 2 )
{
result = "*ABS*";
if ( v4 != 3 )
{
result = "???";
if ( v4 == 1 )
{
v6 = *(_DWORD *)(a1 + 24);
if ( v6 <= a3 && v6 > 0 )
result = *(const char **)(a2 + 32LL * v6 - 24);
else
result = "???";
}
}
}
return result;
}

original_code:
static const char *def_name(struct vobj_symbol *vs,
                            struct vobj_section *sec,int nsecs)
{
  switch (vs->type) {
    case 3:
      return "*ABS*";
    case 2:
      return "*UND*";
    case 1:
      if (vs->sec>0 && vs->sec<=nsecs)
        return sec[vs->sec-1].name;
  }
  return "???";
}

canonical_original_code:
static char *def_name(struct vobj_symbol *vs, struct vobj_section *sec, int nsecs)
{
  switch (vs->type) {
    case 3:
      return "*ABS*";
    case 2:
      return "*UND*";
    case 1:
      if (vs->sec>0 && vs->sec<=nsecs)
        return sec[vs->sec-1].name;
  }
  return "???";
}

variable_types: struct vobj_symbol { unsigned long offs; char *name; int type; long val; } *

variable_types: struct vobj_section { unsigned long offs; char *name; long dsize; } *

variable_types: nsecs int


decompiled_code:
unsigned __int64 __fastcall read_number(int a1)
{
char *v1; // rdx
__int64 v2; // rax
char v3; // cl
unsigned __int64 v4; // rdx
unsigned __int8 v5; // r8
__int64 v6; // rax
unsigned __int64 v7; // rcx
int v8; // ecx

v1 = (char *)p;
if ( p >= (unsigned __int64)vobj + vlen )
{
fwrite("\nObject file is corrupt! Aborting.\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
v2 = ++p;
v3 = *v1;
v4 = (unsigned __int8)*v1;
if ( v3 < 0 )
{
v4 = 0LL;
v5 = v3 + 0x80;
if ( v3 != (char)0x80 )
{
v6 = v5 + v2;
p = v6;
v7 = v6 + ~(unsigned __int64)(unsigned __int8)(v3 + 127);
v4 = 0LL;
do
v4 = *(unsigned __int8 *)--v6 | (v4 << 8);
while ( v6 != v7 );
if ( a1 )
{
v8 = 8 * v5;
if ( _bittest64((const __int64 *)&v4, (unsigned int)(v8 - 1)) )
v4 |= -1LL << v8;
}
}
}
return v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func12(int a1)
{
char *v1; // rdx
__int64 v2; // rax
char v3; // cl
unsigned __int64 v4; // rdx
unsigned __int8 v5; // r8
__int64 v6; // rax
unsigned __int64 v7; // rcx
int v8; // ecx

v1 = (char *)p;
if ( p >= (unsigned __int64)vobj + vlen )
{
fwrite("\nObject file is corrupt! Aborting.\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
v2 = ++p;
v3 = *v1;
v4 = (unsigned __int8)*v1;
if ( v3 < 0 )
{
v4 = 0LL;
v5 = v3 + 0x80;
if ( v3 != (char)0x80 )
{
v6 = v5 + v2;
p = v6;
v7 = v6 + ~(unsigned __int64)(unsigned __int8)(v3 + 127);
v4 = 0LL;
do
v4 = *(unsigned __int8 *)--v6 | (v4 << 8);
while ( v6 != v7 );
if ( a1 )
{
v8 = 8 * v5;
if ( _bittest64((const __int64 *)&v4, (unsigned int)(v8 - 1)) )
v4 |= -1LL << v8;
}
}
}
return v4;
}

original_code:
static taddr read_number(int is_signed)
{
  taddr val;
  ubyte n,*q;
  int size;
  if (p >= vobj+vlen) {
    fprintf(stderr,"\nObject file is corrupt! Aborting.\n");
    exit(1);
  }
  if ((n = *p++) <= 0x7f)
    return (taddr)n;
  val = 0;
  if (n -= 0x80) {
    size = n << 3;
    p += n;
    q = p;
    while (n--)
      val = (val<<8) | *(--q);
    if (is_signed && (val & (1LL<<(size-1))))
      val |= ~((taddr)(1LL<<(size))-1);
  }
  return val;
}

canonical_original_code:
static long read_number(int is_signed)
{
  long val;
  unsigned char n; unsigned char *q;
  int size;
  if (p >= vobj+vlen) {
    fprintf(stderr,"\nObject file is corrupt! Aborting.\n");
    exit(1);
  }
  if ((n = *p++) <= 0x7f)
    return (long)n;
  val = 0;
  if (n -= 0x80) {
    size = n << 3;
    p += n;
    q = p;
    while (n--)
      val = (val<<8) | *(--q);
    if (is_signed && (val & (1LL<<(size-1))))
      val |= ~((taddr)(1LL<<(size))-1);
  }
  return val;
}

variable_types: val long

variable_types:
n
unsigned char

variable_types:
q
unsigned char *

variable_types: size int

return_type: long


decompiled_code:
unsigned __int64 __fastcall read_symbol(__int64 a1)
{
__int64 v1; // rax
unsigned __int64 result; // rax

v1 = p;
*(_QWORD *)a1 = p - (_QWORD)vobj;
*(_QWORD *)(a1 + 8) = v1;
skip_string();
*(_DWORD *)(a1 + 16) = read_number(0);
*(_DWORD *)(a1 + 20) = read_number(0);
*(_DWORD *)(a1 + 24) = read_number(0);
*(_QWORD *)(a1 + 32) = read_number(1);
result = read_number(0);
*(_DWORD *)(a1 + 28) = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func13(__int64 a1)
{
__int64 v1; // rax
unsigned __int64 result; // rax

v1 = p;
*(_QWORD *)a1 = p - (_QWORD)vobj;
*(_QWORD *)(a1 + 8) = v1;
func7();
*(_DWORD *)(a1 + 16) = func12(0);
*(_DWORD *)(a1 + 20) = func12(0);
*(_DWORD *)(a1 + 24) = func12(0);
*(_QWORD *)(a1 + 32) = func12(1);
result = func12(0);
*(_DWORD *)(a1 + 28) = result;
return result;
}

original_code:
static void read_symbol(struct vobj_symbol *vsym)
{
  vsym->offs = p - vobj;
  vsym->name = (const char *)p;
  skip_string();
  vsym->type = (int)read_number(0);
  vsym->flags = (int)read_number(0);
  vsym->sec = (int)read_number(0);
  vsym->val = read_number(1);
  vsym->size = (int)read_number(0);
}

canonical_original_code:
static void read_symbol(struct vobj_symbol *vsym)
{
  vsym->offs = p - vobj;
  vsym->name = (char *)p;
  skip_string();
  vsym->type = (int)read_number(0);
  vsym->flags = (int)read_number(0);
  vsym->sec = (int)read_number(0);
  vsym->val = read_number(1);
  vsym->size = (int)read_number(0);
}

user_defined_types: struct vobj_symbol { unsigned long offs; char *name; int type; long val; }


decompiled_code:
int __fastcall read_section(_QWORD *a1, __int64 a2, int a3)
{
__int64 v4; // rax
const char *v5; // r12
unsigned __int64 v6; // r13
unsigned int v7; // ebp
int v8; // ebx
int v9; // er15
__int64 v10; // rax
int v11; // er12
unsigned __int64 v12; // rax
unsigned __int8 v13; // bl
signed __int64 v14; // r13
int v15; // ebp
unsigned __int64 v16; // rsi
int v17; // eax
__int64 v18; // rcx
const void *v19; // rdx
int v21; // [rsp+8h] [rbp-60h]
unsigned __int64 v22; // [rsp+10h] [rbp-58h]
unsigned __int64 v23; // [rsp+18h] [rbp-50h]

v4 = p;
*a1 = p - (_QWORD)vobj;
a1[1] = v4;
skip_string();
v5 = (const char *)p;
skip_string();
v6 = read_number(0);
v7 = read_number(0);
a1[2] = read_number(0);
v8 = read_number(0);
v9 = v8;
a1[3] = read_number(0);
print_sep();
printf(
"%08llx: SECTION \"%s\" (attributes=\"%s\")\nFlags: %-8lx Alignment: %-6d Total size: %-9lld File size: %-9lld\n",
bptmask & *a1,
(const char *)a1[1],
v5,
v6,
v7,
a1[2],
a1[3]);
if ( !v8 )
{
v10 = a1[3];
p += v10;
return v10;
}
if ( v8 == 1 )
{
printf("%d Relocation%s present.\n", 1LL, emptystr);
p += a1[3];
}
else
{
printf("%d Relocation%s present.\n", (unsigned int)v8, "s");
v10 = a1[3];
p += v10;
if ( v8 <= 0 )
return v10;
}
v11 = 0;
do
{
if ( !v11 )
puts("\nfile offs sectoffs pos sz mask type symbol+addend");
printf("%08llx: ", bptmask & (p - (_QWORD)vobj));
v13 = read_number(0);
if ( v13 > 0x11u )
{
v12 = read_number(0);
p += v12;
LODWORD(v10) = printf("special relocation type %-3d with a size of %d bytes\n", v13, v12);
}
else
{
v14 = read_number(0);
v15 = read_number(0);
v21 = read_number(0);
v22 = read_number(1);
v23 = read_number(1);
v16 = read_number(0);
if ( v14 < 0 || v14 + (v15 >> 3) >= a1[2] )
{
LODWORD(v10) = printf("offset 0x%llx is outside of section!\n", bptmask & (v14 + (v15 >> 3)));
}
else
{
v17 = v16 - 1;
if ( (int)v16 - 1 < 0 || v17 >= a3 )
{
LODWORD(v10) = printf("symbol index %d is illegal!\n", v16);
}
else if ( v21 < 0 || (v18 = (unsigned int)(bpb * bpt), (int)v18 < v21) )
{
LODWORD(v10) = printf("size of %d bits is illegal!\n", (unsigned int)v21);
}
else if ( v15 < 0 || (int)v18 < v15 + v21 )
{
LODWORD(v10) = printf(
"bit field start=%d, size=%d doesn't fit into target address type (%d bits)!\n",
(unsigned int)v15,
(unsigned int)v21,
v18);
}
else
{
v19 = *(const void **)(a2 + 40LL * v17 + 8);
if ( !memcmp(v19, " *current pc", 0xCuLL) )
v19 = (const void *)a1[1];
LODWORD(v10) = printf(
"%08llx %02d %02d %8llx %-8s %s%+lld\n",
bptmask & v14,
(unsigned int)v15,
(unsigned int)v21,
bptmask & v22,
(&reloc_name)[v13],
(const char *)v19,
v23);
}
}
}
++v11;
}
while ( v9 != v11 );
return v10;
}

canonical_decompiled_code:
int __fastcall func14(_QWORD *a1, __int64 a2, int a3)
{
__int64 v4; // rax
const char *v5; // r12
unsigned __int64 v6; // r13
unsigned int v7; // ebp
int v8; // ebx
int v9; // er15
__int64 v10; // rax
int v11; // er12
unsigned __int64 v12; // rax
unsigned __int8 v13; // bl
signed __int64 v14; // r13
int v15; // ebp
unsigned __int64 v16; // rsi
int v17; // eax
__int64 v18; // rcx
const void *v19; // rdx
int v21; // [rsp+8h] [rbp-60h]
unsigned __int64 v22; // [rsp+10h] [rbp-58h]
unsigned __int64 v23; // [rsp+18h] [rbp-50h]

v4 = p;
*a1 = p - (_QWORD)vobj;
a1[1] = v4;
func7();
v5 = (const char *)p;
func7();
v6 = func12(0);
v7 = func12(0);
a1[2] = func12(0);
v8 = func12(0);
v9 = v8;
a1[3] = func12(0);
func11();
printf(
"%08llx: SECTION \"%s\" (attributes=\"%s\")\nFlags: %-8lx Alignment: %-6d Total size: %-9lld File size: %-9lld\n",
bptmask & *a1,
(const char *)a1[1],
v5,
v6,
v7,
a1[2],
a1[3]);
if ( !v8 )
{
v10 = a1[3];
p += v10;
return v10;
}
if ( v8 == 1 )
{
printf("%d Relocation%s present.\n", 1LL, emptystr);
p += a1[3];
}
else
{
printf("%d Relocation%s present.\n", (unsigned int)v8, "s");
v10 = a1[3];
p += v10;
if ( v8 <= 0 )
return v10;
}
v11 = 0;
do
{
if ( !v11 )
puts("\nfile offs sectoffs pos sz mask type symbol+addend");
printf("%08llx: ", bptmask & (p - (_QWORD)vobj));
v13 = func12(0);
if ( v13 > 0x11u )
{
v12 = func12(0);
p += v12;
LODWORD(v10) = printf("special relocation type %-3d with a size of %d bytes\n", v13, v12);
}
else
{
v14 = func12(0);
v15 = func12(0);
v21 = func12(0);
v22 = func12(1);
v23 = func12(1);
v16 = func12(0);
if ( v14 < 0 || v14 + (v15 >> 3) >= a1[2] )
{
LODWORD(v10) = printf("offset 0x%llx is outside of section!\n", bptmask & (v14 + (v15 >> 3)));
}
else
{
v17 = v16 - 1;
if ( (int)v16 - 1 < 0 || v17 >= a3 )
{
LODWORD(v10) = printf("symbol index %d is illegal!\n", v16);
}
else if ( v21 < 0 || (v18 = (unsigned int)(bpb * bpt), (int)v18 < v21) )
{
LODWORD(v10) = printf("size of %d bits is illegal!\n", (unsigned int)v21);
}
else if ( v15 < 0 || (int)v18 < v15 + v21 )
{
LODWORD(v10) = printf(
"bit field start=%d, size=%d doesn't fit into target address type (%d bits)!\n",
(unsigned int)v15,
(unsigned int)v21,
v18);
}
else
{
v19 = *(const void **)(a2 + 40LL * v17 + 8);
if ( !memcmp(v19, " *current pc", 0xCuLL) )
v19 = (const void *)a1[1];
LODWORD(v10) = printf(
"%08llx %02d %02d %8llx %-8s %s%+lld\n",
bptmask & v14,
(unsigned int)v15,
(unsigned int)v21,
bptmask & v22,
(&reloc_name)[v13],
(const char *)v19,
v23);
}
}
}
++v11;
}
while ( v9 != v11 );
return v10;
}

original_code:
static void read_section(struct vobj_section *vsect,
                         struct vobj_symbol *vsym,int nsyms)
{
  const char *attr;
  unsigned long flags;
  int align,nrelocs,i;
  vsect->offs = p - vobj;
  vsect->name = p;
  skip_string();
  attr = p;
  skip_string();
  flags = (unsigned long)read_number(0);
  align = (int)read_number(0);
  vsect->dsize = read_number(0);
  nrelocs = (int)read_number(0);
  vsect->fsize = read_number(0);
  print_sep();
  printf("%08llx: SECTION \"%s\" (attributes=\"%s\")\n"
         "Flags: %-8lx  Alignment: %-6d "
         "Total size: %-9lld File size: %-9lld\n",
         (unsigned long long)((vsect->offs)&bptmask),vsect->name,attr,flags,align,
         vsect->dsize,vsect->fsize);
  if (nrelocs)
    printf("%d Relocation%s present.\n",nrelocs,nrelocs==1?emptystr:sstr);
  p += vsect->fsize;
  for (i=0; i<nrelocs; i++) {
    ubyte type;
    if (i == 0) {
      printf("\nfile offs sectoffs pos sz mask     type     symbol+addend\n");
    }
    printf("%08llx: ",(unsigned long long)((p-vobj)&bptmask));
    type = (ubyte)read_number(0);
    if (type<sizeof(reloc_name)/sizeof(reloc_name[0])) {
      taddr offs,mask,addend;
      int bpos,bsiz,sym;
      const char *basesym;
      offs = read_number(0);
      bpos = (int)read_number(0);
      bsiz = (int)read_number(0);
      mask = read_number(1);
      addend = read_number(1);
      sym = (int)read_number(0) - 1;
      if (offs<0 || offs+(bpos>>3)>=vsect->dsize) {
        printf("offset 0x%llx is outside of section!\n",
               (unsigned long long)((offs+(bpos>>3))&bptmask));
        continue;
      }
      if (sym<0 || sym>=nsyms) {
        printf("symbol index %d is illegal!\n",sym+1);
        continue;
      }
      if (bsiz<0 || bsiz>bpt*bpb) {
        printf("size of %d bits is illegal!\n",bsiz);
        continue;
      }
      if (bpos<0 || bpos+bsiz>bpt*bpb) {
        printf("bit field start=%d, size=%d doesn't fit into target address "
               "type (%d bits)!\n",bpos,bsiz,bpt*bpb);
        continue;
      }
      basesym = vsym[sym].name;
      if (!strncmp(basesym," *current pc",12)) {
        basesym = vsect->name;
      }
      printf("%08llx  %02d %02d %8llx %-8s %s%+lld\n",
             (unsigned long long)((offs)&bptmask),bpos,bsiz,(unsigned long long)((mask)&bptmask),
             reloc_name[type],basesym,addend);
    }
    else {
      taddr rsize;
      rsize = read_number(0);
      p += rsize;
      printf("special relocation type %-3d with a size of %d bytes\n",
             (int)type,(int)rsize);
    }
  }
}

canonical_original_code:
static void read_section(struct vobj_section *vsect, struct vobj_symbol *vsym, int nsyms)
{
  char *attr;
  unsigned long flags;
  int align; int nrelocs; int i;
  vsect->offs = p - vobj;
  vsect->name = p;
  skip_string();
  attr = p;
  skip_string();
  flags = (unsigned long)read_number(0);
  align = (int)read_number(0);
  vsect->dsize = read_number(0);
  nrelocs = (int)read_number(0);
  vsect->fsize = read_number(0);
  print_sep();
  printf("%08llx: SECTION \"%s\" (attributes=\"%s\")\n"
         "Flags: %-8lx  Alignment: %-6d "
         "Total size: %-9lld File size: %-9lld\n",
         (unsigned long long)((vsect->offs)&bptmask),vsect->name,attr,flags,align,
         vsect->dsize,vsect->fsize);
  if (nrelocs)
    printf("%d Relocation%s present.\n",nrelocs,nrelocs==1?emptystr:sstr);
  p += vsect->fsize;
  for (i=0; i<nrelocs; i++) {
    unsigned char type;
    if (i == 0) {
      printf("\nfile offs sectoffs pos sz mask     type     symbol+addend\n");
    }
    printf("%08llx: ",(unsigned long long)((p-vobj)&bptmask));
    type = (unsigned char)read_number(0);
    if (type<sizeof(reloc_name)/sizeof(reloc_name[0])) {
      long offs; long mask; long addend;
      int bpos; int bsiz; int sym;
      char *basesym;
      offs = read_number(0);
      bpos = (int)read_number(0);
      bsiz = (int)read_number(0);
      mask = read_number(1);
      addend = read_number(1);
      sym = (int)read_number(0) - 1;
      if (offs<0 || offs+(bpos>>3)>=vsect->dsize) {
        printf("offset 0x%llx is outside of section!\n",
               (unsigned long long)((offs+(bpos>>3))&bptmask));
        continue;
      }
      if (sym<0 || sym>=nsyms) {
        printf("symbol index %d is illegal!\n",sym+1);
        continue;
      }
      if (bsiz<0 || bsiz>bpt*bpb) {
        printf("size of %d bits is illegal!\n",bsiz);
        continue;
      }
      if (bpos<0 || bpos+bsiz>bpt*bpb) {
        printf("bit field start=%d, size=%d doesn't fit into target address "
               "type (%d bits)!\n",bpos,bsiz,bpt*bpb);
        continue;
      }
      basesym = vsym[sym].name;
      if (!strncmp(basesym," *current pc",12)) {
        basesym = vsect->name;
      }
      printf("%08llx  %02d %02d %8llx %-8s %s%+lld\n",
             (unsigned long long)((offs)&bptmask),bpos,bsiz,(unsigned long long)((mask)&bptmask),
             reloc_name[type],basesym,addend);
    }
    else {
      long rsize;
      rsize = read_number(0);
      p += rsize;
      printf("special relocation type %-3d with a size of %d bytes\n",
             (int)type,(int)rsize);
    }
  }
}

variable_types: nsyms int

variable_types:
attr
char *

variable_types:
flags
unsigned long

variable_types: align int

variable_types: nrelocs int

variable_types:
type
unsigned char

variable_types: offs long

variable_types: mask long

variable_types: addend long

variable_types: bpos int

variable_types: bsiz int

variable_types: sym int

variable_types:
basesym
char *

variable_types: rsize long

user_defined_types: struct vobj_section { unsigned long offs; char *name; long dsize; }


vobjdump

decompiled_code:
__int64 vobjdump()
{
int v0; // ebx
unsigned int v1; // eax
__int64 result; // rax
unsigned int v3; // eax
const char *v4; // r14
unsigned __int64 v5; // rbp
int v6; // er12
int v7; // er13
const char *v8; // rdx
__int64 v9; // rbx
size_t v10; // r12
__int64 v11; // rbp
int i; // er12
__int64 v13; // r14
int j; // er12
const char *v15; // r15
__int64 v16; // r14
const char *v17; // rax
size_t v18; // r12
void *v19; // rax
_QWORD *v20; // [rsp+8h] [rbp-50h]
const char *v21; // [rsp+10h] [rbp-48h]
int v22; // [rsp+18h] [rbp-40h]
int v23; // [rsp+1Ch] [rbp-3Ch]

p = (__int64)vobj;
if ( (unsigned __int64)vlen <= 4
|| *(_BYTE *)vobj != 86
|| *((_BYTE *)vobj + 1) != 79
|| *((_BYTE *)vobj + 2) != 66
|| *((_BYTE *)vobj + 3) != 74 )
{
fwrite("Not a VOBJ file!\n", 1uLL, 0x11uLL, stderr);
return 1LL;
}
p = (__int64)vobj + 5;
v0 = *((unsigned __int8 *)vobj + 4);
if ( (unsigned int)(v0 - 1) > 1 )
{
fprintf(stderr, "Wrong endianess: %d\n", *((unsigned __int8 *)vobj + 4));
return 1LL;
}
v1 = read_number(0);
bpb = v1;
if ( v1 != 8 )
{
fprintf(stderr, "%d bits per byte not supported!\n", v1);
return 1LL;
}
v3 = read_number(0);
bpt = v3;
if ( v3 > 8 )
{
fprintf(stderr, "%d bytes per taddr not supported!\n", v3);
return 1LL;
}
bptmask = (1LL << ((unsigned __int8)bpb * (unsigned __int8)v3)) - 1;
v4 = (const char *)p;
skip_string();
v5 = read_number(0);
v22 = v5;
v6 = read_number(0);
v7 = v6;
print_sep();
v8 = emptystr;
if ( (_DWORD)v5 != 1 )
v8 = "s";
if ( v6 == 1 )
{
printf(
"VOBJ %s (%s endian), %d bits per byte, %d bytes per word.\n%d symbol%s.\n%d section%s.\n",
v4,
endian_name[v0 - 1],
(unsigned int)bpb,
(unsigned int)bpt,
1LL,
emptystr,
v5,
v8);
goto LABEL_34;
}
printf(
"VOBJ %s (%s endian), %d bits per byte, %d bytes per word.\n%d symbol%s.\n%d section%s.\n",
v4,
endian_name[v0 - 1],
(unsigned int)bpb,
(unsigned int)bpt,
(unsigned int)v6,
"s",
v5,
v8);
v9 = 0LL;
if ( v6 )
{
LABEL_34:
v18 = 40LL * v6;
v19 = malloc(v18);
v9 = (__int64)v19;
if ( !v19 )
{
fprintf(stderr, "Cannot allocate %ld bytes for symbols!\n", v18);
return 1LL;
}
v13 = (__int64)v19;
for ( i = 0; i < v7; ++i )
{
read_symbol(v13);
v13 += 40LL;
}
}
v10 = 32LL * (int)v5;
v20 = malloc(v10);
v11 = 0LL;
if ( v20 )
{
while ( v22 > (int)v11 )
read_section(&v20[4 * v11++], v9, v7);
for ( j = 0; j < v7; ++j )
{
if ( !j )
{
putchar(10);
print_sep();
puts("SYMBOL TABLE\nfile offs bind size type def value name");
}
v15 = *(const char **)(v9 + 8);
if ( strncmp(v15, " *current pc", 0xCuLL) )
{
v16 = bptmask;
v21 = def_name(v9, (__int64)v20, v22);
v23 = *(_DWORD *)(v9 + 20);
v17 = bind_name(v23);
printf(
"%08llx: %-4s %08x %-4s %8.8s %8llx %s\n",
*(_QWORD *)v9 & v16,
v17,
*(unsigned int *)(v9 + 28),
(const char *)*(&type_name + (v23 & 7)),
v21,
*(_QWORD *)(v9 + 32) & v16,
v15);
}
v9 += 40LL;
}
result = 0LL;
}
else
{
fprintf(stderr, "Cannot allocate %ld bytes for sections!\n", v10);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func15()
{
int v0; // ebx
unsigned int v1; // eax
__int64 result; // rax
unsigned int v3; // eax
const char *v4; // r14
unsigned __int64 v5; // rbp
int v6; // er12
int v7; // er13
const char *v8; // rdx
__int64 v9; // rbx
size_t v10; // r12
__int64 v11; // rbp
int i; // er12
__int64 v13; // r14
int j; // er12
const char *v15; // r15
__int64 v16; // r14
const char *v17; // rax
size_t v18; // r12
void *v19; // rax
_QWORD *v20; // [rsp+8h] [rbp-50h]
const char *v21; // [rsp+10h] [rbp-48h]
int v22; // [rsp+18h] [rbp-40h]
int v23; // [rsp+1Ch] [rbp-3Ch]

p = (__int64)vobj;
if ( (unsigned __int64)vlen <= 4
|| *(_BYTE *)vobj != 86
|| *((_BYTE *)vobj + 1) != 79
|| *((_BYTE *)vobj + 2) != 66
|| *((_BYTE *)vobj + 3) != 74 )
{
fwrite("Not a VOBJ file!\n", 1uLL, 0x11uLL, stderr);
return 1LL;
}
p = (__int64)vobj + 5;
v0 = *((unsigned __int8 *)vobj + 4);
if ( (unsigned int)(v0 - 1) > 1 )
{
fprintf(stderr, "Wrong endianess: %d\n", *((unsigned __int8 *)vobj + 4));
return 1LL;
}
v1 = func12(0);
bpb = v1;
if ( v1 != 8 )
{
fprintf(stderr, "%d bits per byte not supported!\n", v1);
return 1LL;
}
v3 = func12(0);
bpt = v3;
if ( v3 > 8 )
{
fprintf(stderr, "%d bytes per taddr not supported!\n", v3);
return 1LL;
}
bptmask = (1LL << ((unsigned __int8)bpb * (unsigned __int8)v3)) - 1;
v4 = (const char *)p;
func7();
v5 = func12(0);
v22 = v5;
v6 = func12(0);
v7 = v6;
func11();
v8 = emptystr;
if ( (_DWORD)v5 != 1 )
v8 = "s";
if ( v6 == 1 )
{
printf(
"VOBJ %s (%s endian), %d bits per byte, %d bytes per word.\n%d symbol%s.\n%d section%s.\n",
v4,
endian_name[v0 - 1],
(unsigned int)bpb,
(unsigned int)bpt,
1LL,
emptystr,
v5,
v8);
goto LABEL_34;
}
printf(
"VOBJ %s (%s endian), %d bits per byte, %d bytes per word.\n%d symbol%s.\n%d section%s.\n",
v4,
endian_name[v0 - 1],
(unsigned int)bpb,
(unsigned int)bpt,
(unsigned int)v6,
"s",
v5,
v8);
v9 = 0LL;
if ( v6 )
{
LABEL_34:
v18 = 40LL * v6;
v19 = malloc(v18);
v9 = (__int64)v19;
if ( !v19 )
{
fprintf(stderr, "Cannot allocate %ld bytes for symbols!\n", v18);
return 1LL;
}
v13 = (__int64)v19;
for ( i = 0; i < v7; ++i )
{
func13(v13);
v13 += 40LL;
}
}
v10 = 32LL * (int)v5;
v20 = malloc(v10);
v11 = 0LL;
if ( v20 )
{
while ( v22 > (int)v11 )
func14(&v20[4 * v11++], v9, v7);
for ( j = 0; j < v7; ++j )
{
if ( !j )
{
putchar(10);
func11();
puts("SYMBOL TABLE\nfile offs bind size type def value name");
}
v15 = *(const char **)(v9 + 8);
if ( strncmp(v15, " *current pc", 0xCuLL) )
{
v16 = bptmask;
v21 = func9(v9, (__int64)v20, v22);
v23 = *(_DWORD *)(v9 + 20);
v17 = func8(v23);
printf(
"%08llx: %-4s %08x %-4s %8.8s %8llx %s\n",
*(_QWORD *)v9 & v16,
v17,
*(unsigned int *)(v9 + 28),
(const char *)*(&type_name + (v23 & 7)),
v21,
*(_QWORD *)(v9 + 32) & v16,
v15);
}
v9 += 40LL;
}
result = 0LL;
}
else
{
fprintf(stderr, "Cannot allocate %ld bytes for sections!\n", v10);
result = 1LL;
}
return result;
}

original_code:
static int vobjdump(void)
{
  p = vobj;
  if (vlen>4 && p[0]==0x56 && p[1]==0x4f && p[2]==0x42 && p[3]==0x4a) {
    int endian,nsecs,nsyms,i;
    const char *cpu_name;
    struct vobj_symbol *vsymbols = ((void *)0);
    struct vobj_section *vsect = ((void *)0);
    p += 4;
    endian = (int)*p++;
    if (endian<1 || endian>2) {
      fprintf(stderr,"Wrong endianess: %d\n",endian);
      return 1;
    }
    bpb = (int)read_number(0);
    if (bpb != 8) {
      fprintf(stderr,"%d bits per byte not supported!\n",bpb);
      return 1;
    }
    bpt = (int)read_number(0);
    if (bpt > sizeof(taddr)) {
      fprintf(stderr,"%d bytes per taddr not supported!\n",bpt);
      return 1;
    }
    bptmask = ((taddr)(1LL<<(bpt*bpb))-1);
    cpu_name = p;
    skip_string();
    nsecs = (int)read_number(0);
    nsyms = (int)read_number(0);
    print_sep();
    printf("VOBJ %s (%s endian), %d bits per byte, %d bytes per word.\n"
           "%d symbol%s.\n%d section%s.\n",
           cpu_name,endian_name[endian-1],bpb,bpt,
           nsyms,nsyms==1?emptystr:sstr,nsecs,nsecs==1?emptystr:sstr);
    if (nsyms) {
      if (vsymbols = malloc(nsyms * sizeof(struct vobj_symbol))) {
        for (i=0; i<nsyms; i++)
          read_symbol(&vsymbols[i]);
      }
      else {
        fprintf(stderr,"Cannot allocate %ld bytes for symbols!\n",
                (long)(nsyms * sizeof(struct vobj_symbol)));
        return 1;
      }
    }
    if (vsect = malloc(nsecs * sizeof(struct vobj_section))) {
      for (i=0; i<nsecs; i++)
        read_section(&vsect[i],vsymbols,nsyms);
    }
    else {
      fprintf(stderr,"Cannot allocate %ld bytes for sections!\n",
              (long)(nsecs * sizeof(struct vobj_section)));
      return 1;
    }
    for (i=0; i<nsyms; i++) {
      struct vobj_symbol *vs = &vsymbols[i];
      if (i == 0) {
        printf("\n");
        print_sep();
        printf("SYMBOL TABLE\n"
               "file offs bind size     type def      value    name\n");
      }
      if (!strncmp(vs->name," *current pc",12))
        continue;
      printf("%08llx: %-4s %08x %-4s %8.8s %8llx %s\n",
             (unsigned long long)((vs->offs)&bptmask),bind_name(vs->flags),(unsigned)vs->size,
             type_name[((vs)->flags&7)],def_name(vs,vsect,nsecs),
             (unsigned long long)((vs->val)&bptmask),vs->name);
    }
  }
  else {
    fprintf(stderr,"Not a VOBJ file!\n");
    return 1;
  }
  return 0;
}

canonical_original_code:
static int vobjdump()
{
  p = vobj;
  if (vlen>4 && p[0]==0x56 && p[1]==0x4f && p[2]==0x42 && p[3]==0x4a) {
    int endian; int nsecs; int nsyms; int i;
    char *cpu_name;
    struct vobj_symbol *vsymbols = ((void *)0);
    struct vobj_section *vsect = ((void *)0);
    p += 4;
    endian = (int)*p++;
    if (endian<1 || endian>2) {
      fprintf(stderr,"Wrong endianess: %d\n",endian);
      return 1;
    }
    bpb = (int)read_number(0);
    if (bpb != 8) {
      fprintf(stderr,"%d bits per byte not supported!\n",bpb);
      return 1;
    }
    bpt = (int)read_number(0);
    if (bpt > sizeof(taddr)) {
      fprintf(stderr,"%d bytes per taddr not supported!\n",bpt);
      return 1;
    }
    bptmask = ((taddr)(1LL<<(bpt*bpb))-1);
    cpu_name = p;
    skip_string();
    nsecs = (int)read_number(0);
    nsyms = (int)read_number(0);
    print_sep();
    printf("VOBJ %s (%s endian), %d bits per byte, %d bytes per word.\n"
           "%d symbol%s.\n%d section%s.\n",
           cpu_name,endian_name[endian-1],bpb,bpt,
           nsyms,nsyms==1?emptystr:sstr,nsecs,nsecs==1?emptystr:sstr);
    if (nsyms) {
      if (vsymbols = malloc(nsyms * sizeof(struct vobj_symbol))) {
        for (i=0; i<nsyms; i++)
          read_symbol(&vsymbols[i]);
      }
      else {
        fprintf(stderr,"Cannot allocate %ld bytes for symbols!\n",
                (long)(nsyms * sizeof(struct vobj_symbol)));
        return 1;
      }
    }
    if (vsect = malloc(nsecs * sizeof(struct vobj_section))) {
      for (i=0; i<nsecs; i++)
        read_section(&vsect[i],vsymbols,nsyms);
    }
    else {
      fprintf(stderr,"Cannot allocate %ld bytes for sections!\n",
              (long)(nsecs * sizeof(struct vobj_section)));
      return 1;
    }
    for (i=0; i<nsyms; i++) {
      struct vobj_symbol *vs = &vsymbols[i];
      if (i == 0) {
        printf("\n");
        print_sep();
        printf("SYMBOL TABLE\n"
               "file offs bind size     type def      value    name\n");
      }
      if (!strncmp(vs->name," *current pc",12))
        continue;
      printf("%08llx: %-4s %08x %-4s %8.8s %8llx %s\n",
             (unsigned long long)((vs->offs)&bptmask),bind_name(vs->flags),(unsigned int)vs->size,
             type_name[((vs)->flags&7)],def_name(vs,vsect,nsecs),
             (unsigned long long)((vs->val)&bptmask),vs->name);
    }
  }
  else {
    fprintf(stderr,"Not a VOBJ file!\n");
    return 1;
  }
  return 0;
}

variable_types: endian int

variable_types: nsecs int

variable_types: i int

variable_types: struct vobj_symbol { unsigned long offs; char *name; int type; long val; } *

variable_types: struct vobj_section { unsigned long offs; char *name; long dsize; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int v4; // eax
unsigned int v5; // ebx

initscr();
raw();
cbreak();
noecho();
v3 = 0;
do
{
while ( 1 )
{
v4 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
v5 = v4;
if ( v4 != 42 )
break;
if ( v3 )
{
wattr_off(stdscr__NCURSES6_TINFO_5_0_19991023, 0x200000uLL, 0LL);
v3 = 0;
}
else
{
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x200000uLL, 0LL);
v3 = 1;
}
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}
waddch(stdscr__NCURSES6_TINFO_5_0_19991023, v4);
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
}
while ( v5 != 113 );
endwin();
return 0;
}

original_code:
int main(char* argvs[], int argc) {
  int ch, bold = 0;
  initscr();
  raw();
  cbreak();
  noecho();
  do {
    ch = wgetch(stdscr);
    if (ch == '*') {
      bold = !bold;
      if (bold) {
        wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
      } else {
        wattr_off(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
      }
    } else {
      waddch(stdscr,(ch));
    }
    wrefresh(stdscr);
  } while (ch != 'q');
  endwin();
  return 0;
}

canonical_original_code:
int main(char *argvs[], int argc) {
  int ch; int bold = 0;
  initscr();
  raw();
  cbreak();
  noecho();
  do {
    ch = wgetch(stdscr);
    if (ch == '*') {
      bold = !bold;
      if (bold) {
        wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
      } else {
        wattr_off(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
      }
    } else {
      waddch(stdscr,(ch));
    }
    wrefresh(stdscr);
  } while (ch != 'q');
  endwin();
  return 0;
}

variable_types:
argvs
char *[]

variable_types: argc int

variable_types: ch int

variable_types: bold int


sigcatch

repo: rhilenova/mamewm

decompiled_code:
void __fastcall sigcatch(int a1)
{
sigcode = a1;
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
sigcode = a1;
}

original_code:
void sigcatch(int sig)
{
    sigcode = sig;
}

variable_types: sig int


cleanup

decompiled_code:
void __fastcall __noreturn cleanup(int status)
{
xcb_set_input_focus(connection, 0, 1u, 0);
xcb_flush(connection);
xcb_disconnect(connection);
printf("Shutting down %s...\n", (const char *)program_name);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(int status)
{
xcb_set_input_focus(connection, 0, 1u, 0);
xcb_flush(connection);
xcb_disconnect(connection);
printf("Shutting down %s...\n", (const char *)program_name);
exit(status);
}

original_code:
void cleanup(int code)
{
    xcb_set_input_focus(connection, 0L, XCB_INPUT_FOCUS_POINTER_ROOT,
                        0L);
    xcb_flush(connection);
    xcb_disconnect(connection);
    printf("Shutting down %s...\n", program_name);
    exit(code);
}

variable_types: code int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v3; // rax
__int16 v4; // cx
const char *v5; // rsi
int v6; // ebx
const xcb_setup_t *v7; // rax
xcb_window_t v8; // er14
__int64 i; // rbp
const char *v10; // r12
uint16_t v11; // ax
xcb_intern_atom_reply_t *v12; // rax
xcb_void_cookie_t v13; // eax
uint32_t value_list; // [rsp+8h] [rbp-60h] BYREF
char *s[4]; // [rsp+10h] [rbp-58h]
xcb_intern_atom_cookie_t cookie[13]; // [rsp+34h] [rbp-34h]

s[0] = "_NET_WM_DESKTOP";
s[1] = "WM_DELETE_WINDOW";
s[2] = "WM_PROTOCOLS";
if ( argc <= 1 )
{
v5 = *argv;
program_name = (__int64)v5;
LABEL_11:
printf("Starting %s...\n", v5);
if ( signal(2, sigcatch) != (__sighandler_t)-1LL )
{
if ( signal(15, sigcatch) != (__sighandler_t)-1LL )
{
if ( signal(17, (__sighandler_t)1) != (__sighandler_t)-1LL )
{
connection = xcb_connect(0LL, 0LL);
v6 = xcb_connection_has_error(connection);
if ( v6 )
{
perror("xcb_connect");
exit(-1);
}
v7 = xcb_get_setup(connection);
v8 = xcb_setup_roots_iterator(v7).data->root;
for ( i = 0LL; i != 3; ++i )
{
v10 = s[i];
v11 = strlen(v10);
cookie[(int)i] = xcb_intern_atom(connection, 0, v11, v10);
}
while ( 1 )
{
v12 = xcb_intern_atom_reply(connection, cookie[v6], &xcb_error);
if ( !xcb_error )
free(v12);
if ( ++v6 == 3 )
{
value_list = 1703936;
v13.sequence = xcb_change_window_attributes_checked(connection, v8, 0x800u, &value_list).sequence;
xcb_error = xcb_request_check(connection, v13);
xcb_flush(connection);
if ( xcb_error )
fprintf(
stderr,
"MAMEwm: Can't subscribe to events - error code %d. Another window manager already running?\n",
xcb_error->error_code);
cleanup(sigcode);
}
}
}
perror("setting SIGCHLD handler");
exit(-1);
}
perror("setting SIGTERM handler");
exit(-1);
}
perror("setting SIGINT handler");
exit(-1);
}
v3 = argv + 1;
v4 = 0;
while ( 1 )
{
if ( **v3 == 45 )
{
if ( (*v3)[1] != 118 )
{
v5 = *argv;
program_name = (__int64)v5;
goto LABEL_5;
}
Verbose = 1;
}
else
{
v4 = 1;
}
if ( ++v3 == &argv[(unsigned int)(argc - 2) + 2] )
{
v5 = *argv;
program_name = (__int64)v5;
if ( v4 != 1 )
goto LABEL_11;
LABEL_5:
fprintf(stderr, "usage: %s [-v]\n", v5);
exit(-1);
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v3; // rax
__int16 v4; // cx
const char *v5; // rsi
int v6; // ebx
const xcb_setup_t *v7; // rax
xcb_window_t v8; // er14
__int64 i; // rbp
const char *v10; // r12
uint16_t v11; // ax
xcb_intern_atom_reply_t *v12; // rax
xcb_void_cookie_t v13; // eax
uint32_t value_list; // [rsp+8h] [rbp-60h] BYREF
char *s[4]; // [rsp+10h] [rbp-58h]
xcb_intern_atom_cookie_t cookie[13]; // [rsp+34h] [rbp-34h]

s[0] = "_NET_WM_DESKTOP";
s[1] = "WM_DELETE_WINDOW";
s[2] = "WM_PROTOCOLS";
if ( argc <= 1 )
{
v5 = *argv;
program_name = (__int64)v5;
LABEL_11:
printf("Starting %s...\n", v5);
if ( signal(2, sigcatch) != (__sighandler_t)-1LL )
{
if ( signal(15, sigcatch) != (__sighandler_t)-1LL )
{
if ( signal(17, (__sighandler_t)1) != (__sighandler_t)-1LL )
{
connection = xcb_connect(0LL, 0LL);
v6 = xcb_connection_has_error(connection);
if ( v6 )
{
perror("xcb_connect");
exit(-1);
}
v7 = xcb_get_setup(connection);
v8 = xcb_setup_roots_iterator(v7).data->root;
for ( i = 0LL; i != 3; ++i )
{
v10 = s[i];
v11 = strlen(v10);
cookie[(int)i] = xcb_intern_atom(connection, 0, v11, v10);
}
while ( 1 )
{
v12 = xcb_intern_atom_reply(connection, cookie[v6], &xcb_error);
if ( !xcb_error )
free(v12);
if ( ++v6 == 3 )
{
value_list = 1703936;
v13.sequence = xcb_change_window_attributes_checked(connection, v8, 0x800u, &value_list).sequence;
xcb_error = xcb_request_check(connection, v13);
xcb_flush(connection);
if ( xcb_error )
fprintf(
stderr,
"MAMEwm: Can't subscribe to events - error code %d. Another window manager already running?\n",
xcb_error->error_code);
func8(sigcode);
}
}
}
perror("setting SIGCHLD handler");
exit(-1);
}
perror("setting SIGTERM handler");
exit(-1);
}
perror("setting SIGINT handler");
exit(-1);
}
v3 = argv + 1;
v4 = 0;
while ( 1 )
{
if ( **v3 == 45 )
{
if ( (*v3)[1] != 118 )
{
v5 = *argv;
program_name = (__int64)v5;
goto LABEL_5;
}
Verbose = 1;
}
else
{
v4 = 1;
}
if ( ++v3 == &argv[(unsigned int)(argc - 2) + 2] )
{
v5 = *argv;
program_name = (__int64)v5;
if ( v4 != 1 )
goto LABEL_11;
LABEL_5:
fprintf(stderr, "usage: %s [-v]\n", v5);
exit(-1);
}
}
}

original_code:
int main(int argc, char* argv[])
{
    xcb_screen_t *screen;
    xcb_window_t root;
    const short ATOM_NUMBER = 3;
    char *atom_names[] = {"_NET_WM_DESKTOP",
                          "WM_DELETE_WINDOW",
                          "WM_PROTOCOLS"};
    xcb_intern_atom_cookie_t cookies[ATOM_NUMBER];
    xcb_atom_t atoms[ATOM_NUMBER];
    int counter;
    short error = 0;
    uint32_t mask = 0;
    uint32_t values[2];
    xcb_void_cookie_t cookie;
    for(counter = 1; counter < argc; ++counter)
    {
        if(argv[counter][0] == '-')
        {
            switch (argv[counter][1])
            {
                case 'v':
                    Verbose = 1;
                    continue;
            }
            error = 1;
            break;
        } else
        {
            error = 1;
        }
    }
    program_name = argv[0];
    if(error == 1)
    {
        fprintf(stderr, "usage:  %s [-v]\n", program_name);
        exit(-1);
    }
    printf("Starting %s...\n", argv[0]);
    if(signal(2, sigcatch) == ((__sighandler_t) -1))
    {
        perror("setting SIGINT handler");
        exit(-1);
    }
    if(signal(15, sigcatch) == ((__sighandler_t) -1))
    {
        perror("setting SIGTERM handler");
        exit(-1);
    }
    if(signal(17, ((__sighandler_t) 1)) == ((__sighandler_t) -1))
    {
        perror("setting SIGCHLD handler");
        exit(-1);
    }
    connection = xcb_connect(((void *)0), ((void *)0));
    if(xcb_connection_has_error(connection))
    {
        perror("xcb_connect");
        exit(-1);
    }
    screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data;
    root = screen->root;
    for(counter = 0; counter < ATOM_NUMBER; ++counter)
    {
        cookies[counter] = xcb_intern_atom(connection, 0,
                                           strlen(atom_names[counter]),
                                           atom_names[counter]);
    }
    for(counter = 0; counter < ATOM_NUMBER; ++counter)
    {
        xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection,
                                                               cookies[counter],
                                                               &xcb_error);
        if(xcb_error == ((void *)0))
        {
            atoms[counter] = reply->atom;
            free(reply);
        }
    }
    mask = XCB_CW_EVENT_MASK;
    values[0] = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
                XCB_EVENT_MASK_STRUCTURE_NOTIFY |
                XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY;
    cookie = xcb_change_window_attributes_checked(connection, root, mask,
                                                  values);
    xcb_error = xcb_request_check(connection, cookie);
    xcb_flush(connection);
    if (xcb_error != ((void *)0))
    {
        fprintf(stderr, "MAMEwm: Can't subscribe to events - error code %d."
                " Another window manager already running?\n",
                xcb_error->error_code);
    }
    cleanup(sigcode);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct xcb_screen_t *screen;
    unsigned int root;
    short ATOM_NUMBER = 3;
    char *atom_names[] = {"_NET_WM_DESKTOP",
                          "WM_DELETE_WINDOW",
                          "WM_PROTOCOLS"};
    struct xcb_intern_atom_cookie_t cookies[-1];
    unsigned int atoms[-1];
    int counter;
    short error = 0;
    unsigned int mask = 0;
    unsigned int values[2];
    struct xcb_void_cookie_t cookie;
    for(counter = 1; counter < argc; ++counter)
    {
        if(argv[counter][0] == '-')
        {
            switch (argv[counter][1])
            {
                case 'v':
                    Verbose = 1;
                    continue;
            }
            error = 1;
            break;
        } else
        {
            error = 1;
        }
    }
    program_name = argv[0];
    if(error == 1)
    {
        fprintf(stderr, "usage:  %s [-v]\n", program_name);
        exit(-1);
    }
    printf("Starting %s...\n", argv[0]);
    if(signal(2, sigcatch) == ((__sighandler_t) -1))
    {
        perror("setting SIGINT handler");
        exit(-1);
    }
    if(signal(15, sigcatch) == ((__sighandler_t) -1))
    {
        perror("setting SIGTERM handler");
        exit(-1);
    }
    if(signal(17, ((void (*)(int)) 1)) == ((__sighandler_t) -1))
    {
        perror("setting SIGCHLD handler");
        exit(-1);
    }
    connection = xcb_connect(((void *)0), ((void *)0));
    if(xcb_connection_has_error(connection))
    {
        perror("xcb_connect");
        exit(-1);
    }
    screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data;
    root = screen->root;
    for(counter = 0; counter < ATOM_NUMBER; ++counter)
    {
        cookies[counter] = xcb_intern_atom(connection, 0,
                                           strlen(atom_names[counter]),
                                           atom_names[counter]);
    }
    for(counter = 0; counter < ATOM_NUMBER; ++counter)
    {
        struct xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection,
                                                               cookies[counter],
                                                               &xcb_error);
        if(xcb_error == ((void *)0))
        {
            atoms[counter] = reply->atom;
            free(reply);
        }
    }
    mask = XCB_CW_EVENT_MASK;
    values[0] = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
                XCB_EVENT_MASK_STRUCTURE_NOTIFY |
                XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY;
    cookie = xcb_change_window_attributes_checked(connection, root, mask,
                                                  values);
    xcb_error = xcb_request_check(connection, cookie);
    xcb_flush(connection);
    if (xcb_error != ((void *)0))
    {
        fprintf(stderr, "MAMEwm: Can't subscribe to events - error code %d."
                " Another window manager already running?\n",
                xcb_error->error_code);
    }
    cleanup(sigcode);
    return 0;
}

variable_types:
argv
char *[]

variable_types: struct xcb_screen_t { unsigned int root; unsigned int default_colormap; unsigned int white_pixel; unsigned int black_pixel; unsigned int current_input_masks; unsigned short width_in_pixels; unsigned short height_in_pixels; unsigned short width_in_millimeters; unsigned short height_in_millimeters; unsigned short min_installed_maps; unsigned short max_installed_maps; unsigned int root_visual; unsigned char backing_stores; unsigned char save_unders; unsigned char root_depth; unsigned char allowed_depths_len; } *

variable_types:
root
unsigned int

variable_types: struct xcb_intern_atom_cookie_t { unsigned int sequence; } [-1]

variable_types:
atoms
unsigned int [-1]

variable_types: counter int

variable_types: error short

variable_types:
mask
unsigned int

variable_types:
values
unsigned int [2]

variable_types: struct xcb_void_cookie_t { unsigned int sequence; }

variable_types: struct xcb_intern_atom_reply_t { unsigned char response_type; unsigned char pad0; unsigned short sequence; unsigned int length; unsigned int atom; } *


decompiled_code:
__int64 __fastcall update_pri(int a1, int a2)
{
__int64 v2; // rax
double v4; // xmm0_8
double v5; // xmm1_8

if ( *(_DWORD *)(heap_A + 16LL * a1) != a2 )
return fwrite("Error update_pri!\n", 1uLL, 0x12uLL, DFILE);
v2 = adjlist + 72LL * a2;
if ( *(_DWORD *)(v2 + 32) != a1 )
return fwrite("Error update_pri!\n", 1uLL, 0x12uLL, DFILE);
v4 = *(double *)(v2 + 16);
if ( v4 == 0.0 )
{
v4 = *(double *)(v2 + 24);
}
else
{
v5 = *(double *)(v2 + 24);
if ( v5 != 0.0 )
{
if ( v4 <= v5 )
v4 = v5 - v4 - 1.0;
else
v4 = v4 - v5 - 1.0;
}
}
return update(v4);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__int64 v2; // rax
double v4; // xmm0_8
double v5; // xmm1_8

if ( *(_DWORD *)(heap_A + 16LL * a1) != a2 )
return fwrite("Error update_pri!\n", 1uLL, 0x12uLL, DFILE);
v2 = adjlist + 72LL * a2;
if ( *(_DWORD *)(v2 + 32) != a1 )
return fwrite("Error update_pri!\n", 1uLL, 0x12uLL, DFILE);
v4 = *(double *)(v2 + 16);
if ( v4 == 0.0 )
{
v4 = *(double *)(v2 + 24);
}
else
{
v5 = *(double *)(v2 + 24);
if ( v5 != 0.0 )
{
if ( v4 <= v5 )
v4 = v5 - v4 - 1.0;
else
v4 = v4 - v5 - 1.0;
}
}
return update(v4);
}

original_code:
void update_pri(int hi, int pi)
{
    double pr;
    if ((heap_A[hi].pid != pi)||(adjlist[pi].hid != hi)) {
        fprintf(DFILE,"Error update_pri!\n");
        return;
    }
    if (adjlist[pi].in==0.0) {
        pr = adjlist[pi].out;
    }
    else if (adjlist[pi].out == 0.0) {
        pr = adjlist[pi].in;
    }
    else {
        if (adjlist[pi].in > adjlist[pi].out) {
            pr = adjlist[pi].in - adjlist[pi].out - 1;
        }
        else {
            pr = adjlist[pi].out - adjlist[pi].in - 1;
        }
    }
    update(hi,pr);
}

variable_types: hi int

variable_types: pi int

variable_types: pr double


decompiled_code:
__int64 __fastcall opp_update(int a1)
{
__int64 result; // rax
double *v2; // rbx
__int64 v3; // rbp
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm0_8
double v7; // rdi
__int64 v8; // rdx
int v9; // ecx
double v10; // xmm0_8
double v11; // xmm1_8
double v12; // xmm1_8

result = opplist;
v2 = *(double **)(opplist + 8LL * a1);
if ( v2 )
{
v3 = 72LL * a1;
do
{
v7 = *v2;
if ( defer && (result = adjlist + 72LL * SLODWORD(v7), *(_WORD *)(result + 8) == 0xFFFF) )
{
v2 = (double *)*((_QWORD *)v2 + 2);
}
else
{
result = adjlist;
v8 = adjlist + 72LL * SLODWORD(v7);
if ( !*(_WORD *)(v8 + 10) )
{
v9 = *(_DWORD *)(v8 + 32);
if ( v9 )
{
result = v3 + adjlist;
v4 = *(double *)(v3 + adjlist + 16);
v5 = *(double *)(v3 + adjlist + 24);
if ( v4 <= v5 )
{
if ( v5 > v4 )
{
v12 = COERCE_DOUBLE(*(_QWORD *)&v5 ^ LC3) * v2[1];
if ( v12 > *(double *)(v8 + 16) )
{
*(double *)(v8 + 16) = v12;
result = update_pri(v9, SLODWORD(v7));
}
}
}
else
{
v6 = COERCE_DOUBLE(*(_QWORD *)&v4 ^ LC3) * v2[1];
if ( v6 > *(double *)(v8 + 24) )
{
*(double *)(v8 + 24) = v6;
result = update_pri(v9, SLODWORD(v7));
}
}
}
else
{
result = v3 + adjlist;
v10 = *(double *)(v3 + adjlist + 16);
v11 = *(double *)(v3 + adjlist + 24);
if ( v10 > v11 )
{
*(double *)(v8 + 24) = COERCE_DOUBLE(*(_QWORD *)&v10 ^ LC3) * v2[1];
result = insert_heap();
}
else if ( v11 > v10 )
{
*(double *)(v8 + 16) = COERCE_DOUBLE(*(_QWORD *)&v11 ^ LC3) * v2[1];
result = insert_heap();
}
}
}
v2 = (double *)*((_QWORD *)v2 + 2);
}
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 result; // rax
double *v2; // rbx
__int64 v3; // rbp
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm0_8
double v7; // rdi
__int64 v8; // rdx
int v9; // ecx
double v10; // xmm0_8
double v11; // xmm1_8
double v12; // xmm1_8

result = opplist;
v2 = *(double **)(opplist + 8LL * a1);
if ( v2 )
{
v3 = 72LL * a1;
do
{
v7 = *v2;
if ( defer && (result = adjlist + 72LL * SLODWORD(v7), *(_WORD *)(result + 8) == 0xFFFF) )
{
v2 = (double *)*((_QWORD *)v2 + 2);
}
else
{
result = adjlist;
v8 = adjlist + 72LL * SLODWORD(v7);
if ( !*(_WORD *)(v8 + 10) )
{
v9 = *(_DWORD *)(v8 + 32);
if ( v9 )
{
result = v3 + adjlist;
v4 = *(double *)(v3 + adjlist + 16);
v5 = *(double *)(v3 + adjlist + 24);
if ( v4 <= v5 )
{
if ( v5 > v4 )
{
v12 = COERCE_DOUBLE(*(_QWORD *)&v5 ^ LC3) * v2[1];
if ( v12 > *(double *)(v8 + 16) )
{
*(double *)(v8 + 16) = v12;
result = func0(v9, SLODWORD(v7));
}
}
}
else
{
v6 = COERCE_DOUBLE(*(_QWORD *)&v4 ^ LC3) * v2[1];
if ( v6 > *(double *)(v8 + 24) )
{
*(double *)(v8 + 24) = v6;
result = func0(v9, SLODWORD(v7));
}
}
}
else
{
result = v3 + adjlist;
v10 = *(double *)(v3 + adjlist + 16);
v11 = *(double *)(v3 + adjlist + 24);
if ( v10 > v11 )
{
*(double *)(v8 + 24) = COERCE_DOUBLE(*(_QWORD *)&v10 ^ LC3) * v2[1];
result = insert_heap();
}
else if ( v11 > v10 )
{
*(double *)(v8 + 16) = COERCE_DOUBLE(*(_QWORD *)&v11 ^ LC3) * v2[1];
result = insert_heap();
}
}
}
v2 = (double *)*((_QWORD *)v2 + 2);
}
}
while ( v2 );
}
return result;
}

original_code:
void opp_update(int pi)
{
    struct plist *pindex;
    int npi, nhi;
    double temp;
    pindex = opplist[pi];
    while (pindex!=((void *)0)) {
        npi = pindex->pid;
        if (defer) {
            if (adjlist[npi].bad == -1) {
                pindex = pindex->next;
                continue;
            }
        }
        if (adjlist[npi].label == 0) {
            if (adjlist[npi].hid == 0) {
                if (adjlist[pi].in > adjlist[pi].out) {
                    adjlist[npi].out = (-1.0) * adjlist[pi].in * pindex->angle;
                    insert_heap(npi,adjlist[npi].out);
                }
                else if (adjlist[pi].in < adjlist[pi].out) {
                    adjlist[npi].in = (-1.0) * adjlist[pi].out * pindex->angle;
                    insert_heap(npi,adjlist[npi].in);
                }
            }
            else {
                nhi = adjlist[npi].hid;
                if (adjlist[pi].in > adjlist[pi].out) {
                    temp = (-1.0) * adjlist[pi].in * pindex->angle;
                    if (temp > adjlist[npi].out) {
                        adjlist[npi].out = temp;
                        update_pri(nhi,npi);
                    }
                }
                else if (adjlist[pi].in < adjlist[pi].out) {
                    temp = (-1.0) * adjlist[pi].out * pindex->angle;
                    if (temp > adjlist[npi].in) {
                        adjlist[npi].in = temp;
                        update_pri(nhi,npi);
                    }
                }
            }
        }
        pindex = pindex->next;
    }
}

canonical_original_code:
void opp_update(int pi)
{
    struct plist *pindex;
    int npi; int nhi;
    double temp;
    pindex = opplist[pi];
    while (pindex!=((void *)0)) {
        npi = pindex->pid;
        if (defer) {
            if (adjlist[npi].bad == -1) {
                pindex = pindex->next;
                continue;
            }
        }
        if (adjlist[npi].label == 0) {
            if (adjlist[npi].hid == 0) {
                if (adjlist[pi].in > adjlist[pi].out) {
                    adjlist[npi].out = (-1.0) * adjlist[pi].in * pindex->angle;
                    insert_heap(npi,adjlist[npi].out);
                }
                else if (adjlist[pi].in < adjlist[pi].out) {
                    adjlist[npi].in = (-1.0) * adjlist[pi].out * pindex->angle;
                    insert_heap(npi,adjlist[npi].in);
                }
            }
            else {
                nhi = adjlist[npi].hid;
                if (adjlist[pi].in > adjlist[pi].out) {
                    temp = (-1.0) * adjlist[pi].in * pindex->angle;
                    if (temp > adjlist[npi].out) {
                        adjlist[npi].out = temp;
                        update_pri(nhi,npi);
                    }
                }
                else if (adjlist[pi].in < adjlist[pi].out) {
                    temp = (-1.0) * adjlist[pi].out * pindex->angle;
                    if (temp > adjlist[npi].in) {
                        adjlist[npi].in = temp;
                        update_pri(nhi,npi);
                    }
                }
            }
        }
        pindex = pindex->next;
    }
}

variable_types: struct plist { long pid; double angle; struct plist *next; } *

variable_types: npi int

variable_types: nhi int

variable_types: temp double


decompiled_code:
__int64 __fastcall sym_update(int a1)
{
__int64 v1; // r13
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbp
int v5; // edi
double v6; // xmm0_8
double v7; // xmm1_8
double v8; // xmm0_8
__int64 v9; // r12
__int64 v10; // rbp
double v11; // xmm0_8
int v12; // ecx
double v13; // xmm1_8
double v14; // xmm2_8
double v15; // xmm1_8

v1 = 72LL * a1;
result = adjlist;
v3 = *(_QWORD *)(adjlist + v1);
while ( v3 )
{
v9 = *(_QWORD *)(v3 + 24);
if ( defer && (result = adjlist + 72LL * (int)v9, *(_WORD *)(result + 8) == 0xFFFF) )
{
v3 = *(_QWORD *)(v3 + 32);
}
else
{
v10 = 72LL * (int)v9;
result = adjlist + v10;
if ( !*(_WORD *)(adjlist + v10 + 10) )
{
v11 = *(double *)(v3 + 8);
if ( v11 > theta )
{
v12 = *(_DWORD *)(result + 32);
if ( v12 )
{
if ( *(_DWORD *)(heap_A + 16LL * v12) != (_DWORD)v9 )
fwrite("ERROR\n", 1uLL, 6uLL, DFILE);
v4 = adjlist + v10;
v5 = *(_DWORD *)(v4 + 32);
result = adjlist + v1;
v6 = *(double *)(adjlist + v1 + 16);
v7 = *(double *)(adjlist + v1 + 24);
if ( v6 <= v7 )
{
if ( v7 > v6 )
{
v15 = v7 * *(double *)(v3 + 8);
if ( v15 > *(double *)(v4 + 24) )
{
*(double *)(v4 + 24) = v15;
result = update_pri(v5, v9);
}
}
}
else
{
v8 = v6 * *(double *)(v3 + 8);
if ( v8 > *(double *)(v4 + 16) )
{
*(double *)(v4 + 16) = v8;
result = update_pri(v5, v9);
}
}
}
else
{
v13 = *(double *)(v1 + adjlist + 16);
v14 = *(double *)(v1 + adjlist + 24);
if ( v13 > v14 )
{
*(double *)(result + 16) = v11 * v13;
result = insert_heap((unsigned int)v9);
}
else if ( v14 > v13 )
{
*(double *)(result + 24) = v11 * v14;
result = insert_heap((unsigned int)v9);
}
}
}
}
v3 = *(_QWORD *)(v3 + 32);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // r13
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbp
int v5; // edi
double v6; // xmm0_8
double v7; // xmm1_8
double v8; // xmm0_8
__int64 v9; // r12
__int64 v10; // rbp
double v11; // xmm0_8
int v12; // ecx
double v13; // xmm1_8
double v14; // xmm2_8
double v15; // xmm1_8

v1 = 72LL * a1;
result = adjlist;
v3 = *(_QWORD *)(adjlist + v1);
while ( v3 )
{
v9 = *(_QWORD *)(v3 + 24);
if ( defer && (result = adjlist + 72LL * (int)v9, *(_WORD *)(result + 8) == 0xFFFF) )
{
v3 = *(_QWORD *)(v3 + 32);
}
else
{
v10 = 72LL * (int)v9;
result = adjlist + v10;
if ( !*(_WORD *)(adjlist + v10 + 10) )
{
v11 = *(double *)(v3 + 8);
if ( v11 > theta )
{
v12 = *(_DWORD *)(result + 32);
if ( v12 )
{
if ( *(_DWORD *)(heap_A + 16LL * v12) != (_DWORD)v9 )
fwrite("ERROR\n", 1uLL, 6uLL, DFILE);
v4 = adjlist + v10;
v5 = *(_DWORD *)(v4 + 32);
result = adjlist + v1;
v6 = *(double *)(adjlist + v1 + 16);
v7 = *(double *)(adjlist + v1 + 24);
if ( v6 <= v7 )
{
if ( v7 > v6 )
{
v15 = v7 * *(double *)(v3 + 8);
if ( v15 > *(double *)(v4 + 24) )
{
*(double *)(v4 + 24) = v15;
result = func0(v5, v9);
}
}
}
else
{
v8 = v6 * *(double *)(v3 + 8);
if ( v8 > *(double *)(v4 + 16) )
{
*(double *)(v4 + 16) = v8;
result = func0(v5, v9);
}
}
}
else
{
v13 = *(double *)(v1 + adjlist + 16);
v14 = *(double *)(v1 + adjlist + 24);
if ( v13 > v14 )
{
*(double *)(result + 16) = v11 * v13;
result = insert_heap((unsigned int)v9);
}
else if ( v14 > v13 )
{
*(double *)(result + 24) = v11 * v14;
result = insert_heap((unsigned int)v9);
}
}
}
}
v3 = *(_QWORD *)(v3 + 32);
}
}
return result;
}

original_code:
void sym_update(int pi)
{
    struct edgesimp *eindex;
    int npi, nhi;
    double temp;
    eindex = adjlist[pi].eptr;
    while (eindex!=((void *)0)) {
        npi = eindex->pid;
        if (defer) {
            if (adjlist[npi].bad == -1) {
                eindex = eindex->next;
                continue;
            }
        }
        if ((adjlist[npi].label==0) && (eindex->angle > theta)) {
            if (adjlist[npi].hid == 0) {
                if (adjlist[pi].in > adjlist[pi].out) {
                    adjlist[npi].in = adjlist[pi].in * eindex->angle;
                    insert_heap(npi,adjlist[npi].in);
                }
                else if (adjlist[pi].in < adjlist[pi].out) {
                    adjlist[npi].out = adjlist[pi].out * eindex->angle;
                    insert_heap(npi,adjlist[npi].out);
                }
            }
            else {
                if (heap_A[adjlist[npi].hid].pid != npi) fprintf(DFILE,"ERROR\n");
                nhi = adjlist[npi].hid;
                if (adjlist[pi].in > adjlist[pi].out) {
                    temp = adjlist[pi].in * eindex->angle;
                    if (temp > adjlist[npi].in) {
                        adjlist[npi].in = temp;
                        update_pri(nhi,npi);
                    }
                }
                else if (adjlist[pi].in < adjlist[pi].out) {
                    temp = adjlist[pi].out * eindex->angle;
                    if (temp > adjlist[npi].out) {
                        adjlist[npi].out = temp;
                        update_pri(nhi,npi);
                    }
                }
            }
        }
        eindex = eindex->next;
    }
}

canonical_original_code:
void sym_update(int pi)
{
    struct edgesimp *eindex;
    int npi; int nhi;
    double temp;
    eindex = adjlist[pi].eptr;
    while (eindex!=((void *)0)) {
        npi = eindex->pid;
        if (defer) {
            if (adjlist[npi].bad == -1) {
                eindex = eindex->next;
                continue;
            }
        }
        if ((adjlist[npi].label==0) && (eindex->angle > theta)) {
            if (adjlist[npi].hid == 0) {
                if (adjlist[pi].in > adjlist[pi].out) {
                    adjlist[npi].in = adjlist[pi].in * eindex->angle;
                    insert_heap(npi,adjlist[npi].in);
                }
                else if (adjlist[pi].in < adjlist[pi].out) {
                    adjlist[npi].out = adjlist[pi].out * eindex->angle;
                    insert_heap(npi,adjlist[npi].out);
                }
            }
            else {
                if (heap_A[adjlist[npi].hid].pid != npi) fprintf(DFILE,"ERROR\n");
                nhi = adjlist[npi].hid;
                if (adjlist[pi].in > adjlist[pi].out) {
                    temp = adjlist[pi].in * eindex->angle;
                    if (temp > adjlist[npi].in) {
                        adjlist[npi].in = temp;
                        update_pri(nhi,npi);
                    }
                }
                else if (adjlist[pi].in < adjlist[pi].out) {
                    temp = adjlist[pi].out * eindex->angle;
                    if (temp > adjlist[npi].out) {
                        adjlist[npi].out = temp;
                        update_pri(nhi,npi);
                    }
                }
            }
        }
        eindex = eindex->next;
    }
}

variable_types: struct edgesimp { short kth; double angle; struct simplex { struct simplex *next; short mark; double *vv; double sqradius; short status; long poleindex; short edgestatus[6]; long visit; struct basis_s { struct basis_s *next; int ref_count; int lscale; double sqa; double vecs[1]; } *normal; struct neighbor { double *vert; struct simplex *simp; struct basis_s *basis; } peak; struct neighbor neigh[1]; } *simp; long pid; struct edgesimp *next; } *

user_defined_types: struct edgesimp { short kth; double angle; struct simplex *simp; long pid; struct edgesimp *next; }

user_defined_types: struct simplex { struct simplex *next; short mark; double *vv; double sqradius; short status; long poleindex; short edgestatus[6]; long visit; struct basis_s *normal; struct neighbor peak; struct neighbor neigh[1]; }


propagate

decompiled_code:
__int64 propagate()
{
int v0; // ebx

v0 = extract_max();
*(_WORD *)(adjlist + 72LL * v0 + 10) = (*(double *)(adjlist + 72LL * v0 + 16) > *(double *)(adjlist + 72LL * v0 + 24))
+ 1;
if ( v0 != -1 )
{
opp_update(v0);
sym_update(v0);
}
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // ebx

v0 = extract_max();
*(_WORD *)(adjlist + 72LL * v0 + 10) = (*(double *)(adjlist + 72LL * v0 + 16) > *(double *)(adjlist + 72LL * v0 + 24))
+ 1;
if ( v0 != -1 )
{
func1(v0);
func2(v0);
}
return (unsigned int)v0;
}

original_code:
int propagate()
{
    int pid;
    pid = extract_max();
    if (adjlist[pid].in > adjlist[pid].out)
        adjlist[pid].label = 2;
    else adjlist[pid].label = 1;
    if (pid != -1) {
        opp_update(pid);
        sym_update(pid);
    }
    return pid;
}

variable_types: pid int


decompiled_code:
void __fastcall label_unlabeled(int a1)
{
__int64 i; // rbp
int v2; // er14
int *v3; // rbx
__int64 v4; // r12
__int64 v5; // rcx
__int64 v6; // rsi
__int64 v7; // rax
double v8; // rbx
__int16 v9; // dx
__int64 v10; // r13
__int64 v11; // rax
double v12; // [rsp+0h] [rbp-48h]

if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
{
v10 = 72 * i;
v11 = adjlist + 72 * i;
if ( *(_WORD *)(v11 + 10) )
continue;
v3 = *(int **)(opplist + 8 * i);
if ( v3 )
{
v2 = 0;
do
{
v4 = 72LL * *v3;
if ( *(_WORD *)(adjlist + v4 + 10) )
{
fwrite("opp is labeled\n", 1uLL, 0xFuLL, DFILE);
if ( v2 )
{
if ( *(__int16 *)(adjlist + v4 + 10) != v2 )
{
fwrite("opp poles have inconsistent labels\n", 1uLL, 0x23uLL, DFILE);
v2 = 0;
}
}
else
{
v2 = *(__int16 *)(adjlist + v4 + 10);
}
}
v3 = (int *)*((_QWORD *)v3 + 2);
}
while ( v3 );
v5 = adjlist;
v6 = adjlist + v10;
v7 = *(_QWORD *)(adjlist + 72 * i);
if ( !v7 )
{
LABEL_27:
if ( v2 )
*(_WORD *)(v6 + 10) = (v2 != 2) + 1;
else
fprintf(DFILE, "1: cannot label pole %d\n", (unsigned int)i);
continue;
}
}
else
{
if ( !*(_QWORD *)v11 )
{
fwrite("no opp pole, no adjacent pole!\n", 1uLL, 0x1FuLL, DFILE);
continue;
}
v5 = adjlist;
v6 = adjlist + v10;
v7 = *(_QWORD *)(adjlist + 72 * i);
v2 = 0;
}
v8 = *(double *)&LC5;
v12 = *(double *)&LC5;
do
{
v9 = *(_WORD *)(v5 + 72LL * *(int *)(v7 + 24) + 10);
if ( v9 == 2 )
{
v12 = fmax(*(double *)(v7 + 8), v12);
}
else if ( v9 == 1 )
{
v8 = fmax(*(double *)(v7 + 8), v8);
}
v7 = *(_QWORD *)(v7 + 32);
}
while ( v7 );
if ( v12 == -3.0 )
{
if ( v8 == -3.0 )
goto LABEL_27;
if ( v8 <= deep )
{
if ( !v2 )
goto LABEL_37;
*(_WORD *)(v6 + 10) = (v2 != 2) + 1;
}
else
{
*(_WORD *)(v6 + 10) = 1;
}
}
else
{
if ( v8 != -3.0 )
{
if ( v12 <= deep )
{
if ( v8 <= deep )
{
if ( v2 )
*(_WORD *)(v6 + 10) = (v2 != 2) + 1;
else
fprintf(DFILE, "3: cannot label pole %d\n", (unsigned int)i);
}
else
{
*(_WORD *)(v6 + 10) = 1;
}
}
else if ( v8 <= deep )
{
*(_WORD *)(v6 + 10) = 2;
}
else if ( v2 )
{
*(_WORD *)(v6 + 10) = (v2 != 2) + 1;
}
else
{
fprintf(
DFILE,
"intersect both deeply but no opp,in %f out %f.try to label more deeply intersected label.\n",
v12,
v8);
if ( v12 <= v8 )
*(_WORD *)(adjlist + v10 + 10) = 1;
else
*(_WORD *)(adjlist + v10 + 10) = 2;
}
continue;
}
if ( v12 <= deep )
{
if ( v2 )
{
*(_WORD *)(v6 + 10) = (v2 != 2) + 1;
continue;
}
LABEL_37:
fprintf(DFILE, "2: cannot label pole %d\n", (unsigned int)i);
continue;
}
*(_WORD *)(v6 + 10) = 2;
}
}
}
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
__int64 i; // rbp
int v2; // er14
int *v3; // rbx
__int64 v4; // r12
__int64 v5; // rcx
__int64 v6; // rsi
__int64 v7; // rax
double v8; // rbx
__int16 v9; // dx
__int64 v10; // r13
__int64 v11; // rax
double v12; // [rsp+0h] [rbp-48h]

if ( a1 > 0 )
{
for ( i = 0LL; i != a1; ++i )
{
v10 = 72 * i;
v11 = adjlist + 72 * i;
if ( *(_WORD *)(v11 + 10) )
continue;
v3 = *(int **)(opplist + 8 * i);
if ( v3 )
{
v2 = 0;
do
{
v4 = 72LL * *v3;
if ( *(_WORD *)(adjlist + v4 + 10) )
{
fwrite("opp is labeled\n", 1uLL, 0xFuLL, DFILE);
if ( v2 )
{
if ( *(__int16 *)(adjlist + v4 + 10) != v2 )
{
fwrite("opp poles have inconsistent labels\n", 1uLL, 0x23uLL, DFILE);
v2 = 0;
}
}
else
{
v2 = *(__int16 *)(adjlist + v4 + 10);
}
}
v3 = (int *)*((_QWORD *)v3 + 2);
}
while ( v3 );
v5 = adjlist;
v6 = adjlist + v10;
v7 = *(_QWORD *)(adjlist + 72 * i);
if ( !v7 )
{
LABEL_27:
if ( v2 )
*(_WORD *)(v6 + 10) = (v2 != 2) + 1;
else
fprintf(DFILE, "1: cannot label pole %d\n", (unsigned int)i);
continue;
}
}
else
{
if ( !*(_QWORD *)v11 )
{
fwrite("no opp pole, no adjacent pole!\n", 1uLL, 0x1FuLL, DFILE);
continue;
}
v5 = adjlist;
v6 = adjlist + v10;
v7 = *(_QWORD *)(adjlist + 72 * i);
v2 = 0;
}
v8 = *(double *)&LC5;
v12 = *(double *)&LC5;
do
{
v9 = *(_WORD *)(v5 + 72LL * *(int *)(v7 + 24) + 10);
if ( v9 == 2 )
{
v12 = fmax(*(double *)(v7 + 8), v12);
}
else if ( v9 == 1 )
{
v8 = fmax(*(double *)(v7 + 8), v8);
}
v7 = *(_QWORD *)(v7 + 32);
}
while ( v7 );
if ( v12 == -3.0 )
{
if ( v8 == -3.0 )
goto LABEL_27;
if ( v8 <= deep )
{
if ( !v2 )
goto LABEL_37;
*(_WORD *)(v6 + 10) = (v2 != 2) + 1;
}
else
{
*(_WORD *)(v6 + 10) = 1;
}
}
else
{
if ( v8 != -3.0 )
{
if ( v12 <= deep )
{
if ( v8 <= deep )
{
if ( v2 )
*(_WORD *)(v6 + 10) = (v2 != 2) + 1;
else
fprintf(DFILE, "3: cannot label pole %d\n", (unsigned int)i);
}
else
{
*(_WORD *)(v6 + 10) = 1;
}
}
else if ( v8 <= deep )
{
*(_WORD *)(v6 + 10) = 2;
}
else if ( v2 )
{
*(_WORD *)(v6 + 10) = (v2 != 2) + 1;
}
else
{
fprintf(
DFILE,
"intersect both deeply but no opp,in %f out %f.try to label more deeply intersected label.\n",
v12,
v8);
if ( v12 <= v8 )
*(_WORD *)(adjlist + v10 + 10) = 1;
else
*(_WORD *)(adjlist + v10 + 10) = 2;
}
continue;
}
if ( v12 <= deep )
{
if ( v2 )
{
*(_WORD *)(v6 + 10) = (v2 != 2) + 1;
continue;
}
LABEL_37:
fprintf(DFILE, "2: cannot label pole %d\n", (unsigned int)i);
continue;
}
*(_WORD *)(v6 + 10) = 2;
}
}
}
}

original_code:
void label_unlabeled(int num)
{
    struct plist *pindex;
    struct edgesimp *eindex;
    int npi,i, opplabel;
    int tlabel;
    double tangle, tangle1;
    for (i=0;i<num;i++) {
        if (adjlist[i].label == 0) {
            tlabel = 0;
            opplabel = 0;
            pindex = opplist[i];
            if ((pindex == ((void *)0))&&(adjlist[i].eptr==((void *)0))) {
                fprintf(DFILE,"no opp pole, no adjacent pole!\n");
                continue;
            }
            while (pindex!=((void *)0)) {
                npi = pindex->pid;
                if (adjlist[npi].label != 0) {
                    fprintf(DFILE,"opp is labeled\n");
                    if (opplabel == 0) opplabel = adjlist[npi].label;
                    else if (opplabel != adjlist[npi].label) {
                        fprintf(DFILE,"opp poles have inconsistent labels\n");
                        opplabel = 0;
                    }
                }
                pindex = pindex->next;
            }
            tangle = -3.0;
            tangle1 = -3.0;
            eindex = adjlist[i].eptr;
            while (eindex != ((void *)0)) {
                npi = eindex->pid;
                if (adjlist[npi].label == 2) {
                    if (tangle < eindex->angle) {
                        tangle = eindex->angle;
                    }
                }
                else if (adjlist[npi].label == 1) {
                    if (tangle1 < eindex->angle) {
                        tangle1 = eindex->angle;
                    }
                }
                eindex = eindex->next;
            }
            if (tangle == -3.0) {
                if (tangle1 == -3.0) {
                    if (opplabel == 0) {
                        fprintf(DFILE, "1: cannot label pole %d\n", i);
                    }
                    else if (opplabel == 2) {
                        adjlist[i].label = 1;
                    }
                    else adjlist[i].label = 2;
                }
                else if (tangle1 > deep) {
                    adjlist[i].label = 1;
                }
                else {
                    if (opplabel == 0) {
                        fprintf(DFILE, "2: cannot label pole %d\n", i);
                    }
                    else if (opplabel == 2) {
                        adjlist[i].label = 1;
                    }
                    else adjlist[i].label = 2;
                }
            }
            else if (tangle1 == -3.0) {
                if (tangle > deep) {
                    adjlist[i].label = 2;
                }
                else {
                    if (opplabel == 0) {
                        fprintf(DFILE, "2: cannot label pole %d\n", i);
                    }
                    else if (opplabel == 2) {
                        adjlist[i].label = 1;
                    }
                    else adjlist[i].label = 2;
                }
            }
            else {
                if (tangle > deep) {
                    if (tangle1 > deep) {
                        if (opplabel == 0) {
                            fprintf(DFILE,"intersect both deeply but no opp,in %f out %f.try to label more deeply intersected label.\n", tangle, tangle1);
                            if (tangle > tangle1) {
                                adjlist[i].label = 2;
                            }
                            else adjlist[i].label = 1;
                        }
                        else if (opplabel == 2) {
                            adjlist[i].label = 1;
                        }
                        else adjlist[i].label = 2;
                    }
                    else {
                        adjlist[i].label = 2;
                    }
                }
                else if (tangle1 > deep) {
                    adjlist[i].label = 1;
                }
                else {
                    if (opplabel == 0) {
                        fprintf(DFILE, "3: cannot label pole %d\n", i);
                    }
                    else if (opplabel == 2) {
                        adjlist[i].label = 1;
                    }
                    else adjlist[i].label = 2;
                }
            }
        }
    }
}

canonical_original_code:
void label_unlabeled(int num)
{
    struct plist *pindex;
    struct edgesimp *eindex;
    int npi; int i; int opplabel;
    int tlabel;
    double tangle; double tangle1;
    for (i=0;i<num;i++) {
        if (adjlist[i].label == 0) {
            tlabel = 0;
            opplabel = 0;
            pindex = opplist[i];
            if ((pindex == ((void *)0))&&(adjlist[i].eptr==((void *)0))) {
                fprintf(DFILE,"no opp pole, no adjacent pole!\n");
                continue;
            }
            while (pindex!=((void *)0)) {
                npi = pindex->pid;
                if (adjlist[npi].label != 0) {
                    fprintf(DFILE,"opp is labeled\n");
                    if (opplabel == 0) opplabel = adjlist[npi].label;
                    else if (opplabel != adjlist[npi].label) {
                        fprintf(DFILE,"opp poles have inconsistent labels\n");
                        opplabel = 0;
                    }
                }
                pindex = pindex->next;
            }
            tangle = -3.0;
            tangle1 = -3.0;
            eindex = adjlist[i].eptr;
            while (eindex != ((void *)0)) {
                npi = eindex->pid;
                if (adjlist[npi].label == 2) {
                    if (tangle < eindex->angle) {
                        tangle = eindex->angle;
                    }
                }
                else if (adjlist[npi].label == 1) {
                    if (tangle1 < eindex->angle) {
                        tangle1 = eindex->angle;
                    }
                }
                eindex = eindex->next;
            }
            if (tangle == -3.0) {
                if (tangle1 == -3.0) {
                    if (opplabel == 0) {
                        fprintf(DFILE, "1: cannot label pole %d\n", i);
                    }
                    else if (opplabel == 2) {
                        adjlist[i].label = 1;
                    }
                    else adjlist[i].label = 2;
                }
                else if (tangle1 > deep) {
                    adjlist[i].label = 1;
                }
                else {
                    if (opplabel == 0) {
                        fprintf(DFILE, "2: cannot label pole %d\n", i);
                    }
                    else if (opplabel == 2) {
                        adjlist[i].label = 1;
                    }
                    else adjlist[i].label = 2;
                }
            }
            else if (tangle1 == -3.0) {
                if (tangle > deep) {
                    adjlist[i].label = 2;
                }
                else {
                    if (opplabel == 0) {
                        fprintf(DFILE, "2: cannot label pole %d\n", i);
                    }
                    else if (opplabel == 2) {
                        adjlist[i].label = 1;
                    }
                    else adjlist[i].label = 2;
                }
            }
            else {
                if (tangle > deep) {
                    if (tangle1 > deep) {
                        if (opplabel == 0) {
                            fprintf(DFILE,"intersect both deeply but no opp,in %f out %f.try to label more deeply intersected label.\n", tangle, tangle1);
                            if (tangle > tangle1) {
                                adjlist[i].label = 2;
                            }
                            else adjlist[i].label = 1;
                        }
                        else if (opplabel == 2) {
                            adjlist[i].label = 1;
                        }
                        else adjlist[i].label = 2;
                    }
                    else {
                        adjlist[i].label = 2;
                    }
                }
                else if (tangle1 > deep) {
                    adjlist[i].label = 1;
                }
                else {
                    if (opplabel == 0) {
                        fprintf(DFILE, "3: cannot label pole %d\n", i);
                    }
                    else if (opplabel == 2) {
                        adjlist[i].label = 1;
                    }
                    else adjlist[i].label = 2;
                }
            }
        }
    }
}

variable_types: num int

variable_types: i int

variable_types: opplabel int

variable_types: tlabel int

variable_types: tangle double

user_defined_types: struct plist { long pid; double angle; struct plist *next; }

user_defined_types: struct neighbor { double *vert; struct simplex *simp; struct basis_s *basis; }

user_defined_types: struct basis_s { struct basis_s *next; int ref_count; int lscale; double sqa; double vecs[1]; }


decompiled_code:
double double_rand()
{
return erand48(X);
}

canonical_decompiled_code:
double func0()
{
return erand48(X);
}

original_code: double double_rand(void) {return erand48(X);}

canonical_original_code: double double_rand() {return erand48(X);}

return_type: double