decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
char *v5; // r13
const char **v6; // rax
void (__fastcall *v7)(_QWORD); // rdx
void (*v8)(void); // rdx

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "c:t:i:h");
if ( v4 == -1 )
break;
if ( v4 == 104 )
{
usage(stdout, *argv);
exit(0);
}
if ( v4 > 104 )
{
if ( v4 == 105 )
{
v5 = optarg;
iterations = atoi(optarg);
if ( iterations <= 0 )
{
fprintf(stderr, "Invalid argument '%s'. Number of iterations must be positive.\n", v5);
goto LABEL_7;
}
}
else
{
if ( v4 != 116 )
goto LABEL_11;
if ( !(unsigned int)set_test_impl(optarg) )
LABEL_7:
v3 = 1;
}
}
else if ( v4 == 99 )
{
if ( !(unsigned int)set_cs_impl(optarg) )
goto LABEL_7;
}
else if ( v4 > 99 || (v3 = 1, v4 != 58) && v4 != 63 )
{
LABEL_11:
abort();
}
}
if ( v3 )
{
usage(stderr, *argv);
exit(1);
}
v6 = (const char **)cs_impl;
v7 = (void (__fastcall *)(_QWORD))*((_QWORD *)cs_impl + 3);
if ( v7 )
{
v7(*((unsigned int *)test_impl + 4));
v6 = (const char **)cs_impl;
}
enter_critical = (__int64)v6[5];
exit_critical = (__int64)v6[6];
printf(
"Configuration:\n\tTest implementation: %s\n\tCritical sections implementation: %s\n\tIterations: %i\n\n",
*(const char **)test_impl,
*v6,
(unsigned int)iterations);
start_threads();
v8 = (void (*)(void))*((_QWORD *)cs_impl + 4);
if ( v8 )
v8();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
char *v5; // r13
const char **v6; // rax
void (__fastcall *v7)(_QWORD); // rdx
void (*v8)(void); // rdx

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "c:t:i:h");
if ( v4 == -1 )
break;
if ( v4 == 104 )
{
func6(stdout, *argv);
exit(0);
}
if ( v4 > 104 )
{
if ( v4 == 105 )
{
v5 = optarg;
iterations = atoi(optarg);
if ( iterations <= 0 )
{
fprintf(stderr, "Invalid argument '%s'. Number of iterations must be positive.\n", v5);
goto LABEL_7;
}
}
else
{
if ( v4 != 116 )
goto LABEL_11;
if ( !(unsigned int)func5(optarg) )
LABEL_7:
v3 = 1;
}
}
else if ( v4 == 99 )
{
if ( !(unsigned int)func4(optarg) )
goto LABEL_7;
}
else if ( v4 > 99 || (v3 = 1, v4 != 58) && v4 != 63 )
{
LABEL_11:
abort();
}
}
if ( v3 )
{
func6(stderr, *argv);
exit(1);
}
v6 = (const char **)cs_impl;
v7 = (void (__fastcall *)(_QWORD))*((_QWORD *)cs_impl + 3);
if ( v7 )
{
v7(*((unsigned int *)test_impl + 4));
v6 = (const char **)cs_impl;
}
enter_critical = (__int64)v6[5];
exit_critical = (__int64)v6[6];
printf(
"Configuration:\n\tTest implementation: %s\n\tCritical sections implementation: %s\n\tIterations: %i\n\n",
*(const char **)test_impl,
*v6,
(unsigned int)iterations);
func7();
v8 = (void (*)(void))*((_QWORD *)cs_impl + 4);
if ( v8 )
v8();
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
        int opt;
        int errexit = 0;
        extern char *optarg;
        extern int optind, optopt;
        while ((opt = getopt(argc, argv, "c:t:i:h")) != -1) {
                switch (opt) {
                case 'c':
                        if (!set_cs_impl(optarg))
                                errexit = 1;
                        break;
                case 't':
                        if (!set_test_impl(optarg))
                                errexit = 1;
                        break;
                case 'i':
                        iterations = atoi(optarg);
                        if(iterations <= 0){
                                fprintf(stderr,
                                        "Invalid argument '%s'. Number of iterations "
                                        "must be positive.\n",
                                        optarg);
                                errexit = 1;
                        }
                        break;
                case 'h':
                        usage(stdout, argv[0]);
                        exit(0);
                case ':':
                case '?':
                        errexit = 1;
                        break;
                default:
                        abort();
                }
        }
        if (errexit) {
                usage(stderr, argv[0]);
                exit(1);
        }
        if (cs_impl->init)
                cs_impl->init(test_impl->num_threads);
        enter_critical = cs_impl->enter;
        exit_critical = cs_impl->exit;
        printf("Configuration:\n"
               "\tTest implementation: %s\n"
               "\tCritical sections implementation: %s\n"
               "\tIterations: %i\n"
               "\n",
               test_impl->name, cs_impl->name, iterations);
        start_threads();
        if (cs_impl->fini)
                cs_impl->fini();
        return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
        int opt;
        int errexit = 0;
        extern char *optarg;
        extern int optind; extern int optopt;
        while ((opt = getopt(argc, argv, "c:t:i:h")) != -1) {
                switch (opt) {
                case 'c':
                        if (!set_cs_impl(optarg))
                                errexit = 1;
                        break;
                case 't':
                        if (!set_test_impl(optarg))
                                errexit = 1;
                        break;
                case 'i':
                        iterations = atoi(optarg);
                        if(iterations <= 0){
                                fprintf(stderr,
                                        "Invalid argument '%s'. Number of iterations "
                                        "must be positive.\n",
                                        optarg);
                                errexit = 1;
                        }
                        break;
                case 'h':
                        usage(stdout, argv[0]);
                        exit(0);
                case ':':
                case '?':
                        errexit = 1;
                        break;
                default:
                        abort();
                }
        }
        if (errexit) {
                usage(stderr, argv[0]);
                exit(1);
        }
        if (cs_impl->init)
                cs_impl->init(test_impl->num_threads);
        enter_critical = cs_impl->enter;
        exit_critical = cs_impl->exit;
        printf("Configuration:\n"
               "\tTest implementation: %s\n"
               "\tCritical sections implementation: %s\n"
               "\tIterations: %i\n"
               "\n",
               test_impl->name, cs_impl->name, iterations);
        start_threads();
        if (cs_impl->fini)
                cs_impl->fini();
        return 0;
}

variable_types: opt int


variable_types: jj int

variable_types: kk int

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: B int

variable_types: r double

return_type: void


decompiled_code:
double *matmul_ref()
{
__int64 *v0; // rcx
__int64 i; // r10
__int64 *v2; // rsi
__int64 *v3; // rdi
double v4; // xmm1_8
double *result; // rax
double *v6; // rdx
double v7; // xmm0_8

v0 = mat_a;
for ( i = 0LL; i != 2000; ++i )
{
v2 = &mat_ref[i];
v3 = mat_a;
do
{
v4 = *(double *)v2;
result = (double *)&mat_b[i];
v6 = (double *)v3;
do
{
v7 = *v6 * *result;
result += 2000;
++v6;
v4 = v4 + v7;
}
while ( result != (double *)v0 );
*(double *)v2 = v4;
v2 += 2000;
v3 += 2000;
}
while ( v2 != &mat_c[i] );
v0 = (__int64 *)(result + 1);
}
return result;
}

canonical_decompiled_code:
double *func8()
{
__int64 *v0; // rcx
__int64 i; // r10
__int64 *v2; // rsi
__int64 *v3; // rdi
double v4; // xmm1_8
double *result; // rax
double *v6; // rdx
double v7; // xmm0_8

v0 = mat_a;
for ( i = 0LL; i != 2000; ++i )
{
v2 = &mat_ref[i];
v3 = mat_a;
do
{
v4 = *(double *)v2;
result = (double *)&mat_b[i];
v6 = (double *)v3;
do
{
v7 = *v6 * *result;
result += 2000;
++v6;
v4 = v4 + v7;
}
while ( result != (double *)v0 );
*(double *)v2 = v4;
v2 += 2000;
v3 += 2000;
}
while ( v2 != &mat_c[i] );
v0 = (__int64 *)(result + 1);
}
return result;
}


original_code:
static void
init_matrices()
{
        int i, j;
        for (i = 0; i < 2000; i++) {
                for (j = 0; j < 2000; j++) {
                        mat_a[i][j] = ((i + j) & 0x0F) * 0x1P-4;
                        mat_b[i][j] = (((i << 1) + (j >> 1)) & 0x0F) * 0x1P-4;
                }
        }
        memset(mat_c, 0, sizeof(mat_c));
        memset(mat_ref, 0, sizeof(mat_ref));
}

canonical_original_code:
static void init_matrices()
{
        int i; int j;
        for (i = 0; i < 2000; i++) {
                for (j = 0; j < 2000; j++) {
                        mat_a[i][j] = ((i + j) & 0x0F) * 0x1P-4;
                        mat_b[i][j] = (((i << 1) + (j >> 1)) & 0x0F) * 0x1P-4;
                }
        }
        memset(mat_c, 0, sizeof(mat_c));
        memset(mat_ref, 0, sizeof(mat_ref));
}


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

if ( gettimeofday(&v1, 0LL) )
{
fwrite("gettimeofday failed. Aborting.\n", 1uLL, 0x1FuLL, stderr);
abort();
}
return (double)SLODWORD(v1.tv_usec) * 0.000001 + (double)SLODWORD(v1.tv_sec);
}

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

if ( gettimeofday(&v1, 0LL) )
{
fwrite("gettimeofday failed. Aborting.\n", 1uLL, 0x1FuLL, stderr);
abort();
}
return (double)SLODWORD(v1.tv_usec) * 0.000001 + (double)SLODWORD(v1.tv_sec);
}

original_code:
static double
get_time()
{
        struct timeval tv;
        if (gettimeofday(&tv, ((void *)0))) {
                fprintf(stderr, "gettimeofday failed. Aborting.\n");
                abort();
        }
        return tv.tv_sec + tv.tv_usec * 1E-6;
}

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

return_type: double


main

canonical_name: main

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

v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "vh");
if ( v5 == -1 )
break;
if ( v5 == 104 )
{
usage(stdout, *argv);
exit(0);
}
if ( v5 > 104 )
{
v4 = 1;
if ( v5 != 118 )
goto LABEL_9;
}
else
{
if ( v5 == 58 )
{
fprintf(stderr, "%s: option -%c requries an operand\n", *argv, (unsigned int)optopt);
}
else
{
if ( v5 != 63 )
LABEL_9:
abort();
fprintf(stderr, "%s: illegal option -- %c\n", *argv, (unsigned int)optopt);
}
v3 = 1;
}
}
if ( v3 )
{
usage(stderr, *argv);
exit(2);
}
init_matrices();
run_multiply(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
unsigned int v4; // er12
int v5; // eax

v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "vh");
if ( v5 == -1 )
break;
if ( v5 == 104 )
{
func10(stdout, *argv);
exit(0);
}
if ( v5 > 104 )
{
v4 = 1;
if ( v5 != 118 )
goto LABEL_9;
}
else
{
if ( v5 == 58 )
{
fprintf(stderr, "%s: option -%c requries an operand\n", *argv, (unsigned int)optopt);
}
else
{
if ( v5 != 63 )
LABEL_9:
abort();
fprintf(stderr, "%s: illegal option -- %c\n", *argv, (unsigned int)optopt);
}
v3 = 1;
}
}
if ( v3 )
{
func10(stderr, *argv);
exit(2);
}
func11();
func13(v4);
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
        int c;
        int errexit;
        int verify;
        extern char *optarg;
        extern int optind, optopt, opterr;
        errexit = 0;
        verify = 0;
        while ((c = getopt(argc, argv, "vh")) != -1) {
                switch (c) {
                case 'v':
                        verify = 1;
                        break;
                case 'h':
                        usage(stdout, argv[0]);
                        exit(0);
                        break;
                case ':':
                        fprintf(stderr, "%s: option -%c requries an operand\n",
                                argv[0], optopt);
                        errexit = 1;
                        break;
                case '?':
                        fprintf(stderr, "%s: illegal option -- %c\n",
                                argv[0], optopt);
                        errexit = 1;
                        break;
                default:
                        abort();
                }
        }
        if (errexit) {
                usage(stderr, argv[0]);
                exit(2);
        }
        init_matrices();
        run_multiply(verify);
        return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
        int c;
        int errexit;
        int verify;
        extern char *optarg;
        extern int optind; extern int optopt; extern int opterr;
        errexit = 0;
        verify = 0;
        while ((c = getopt(argc, argv, "vh")) != -1) {
                switch (c) {
                case 'v':
                        verify = 1;
                        break;
                case 'h':
                        usage(stdout, argv[0]);
                        exit(0);
                        break;
                case ':':
                        fprintf(stderr, "%s: option -%c requries an operand\n",
                                argv[0], optopt);
                        errexit = 1;
                        break;
                case '?':
                        fprintf(stderr, "%s: illegal option -- %c\n",
                                argv[0], optopt);
                        errexit = 1;
                        break;
                default:
                        abort();
                }
        }
        if (errexit) {
                usage(stderr, argv[0]);
                exit(2);
        }
        init_matrices();
        run_multiply(verify);
        return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: errexit int

variable_types: verify int

variable_types:
optarg
char *

variable_types: optind int

variable_types: optopt int

variable_types: opterr int

return_type: int


original_code:
static int
verify_result()
{
        double e_sum;
        int i, j;
        e_sum = 0;
        for (i = 0; i < 2000; i++) {
                for (j = 0; j < 2000; j++) {
                        e_sum += mat_c[i][j] < mat_ref[i][j] ?
                                mat_ref[i][j] - mat_c[i][j] :
                                mat_c[i][j] - mat_ref[i][j];
                }
        }
        return e_sum < 1E-6;
}

canonical_original_code:
static int verify_result()
{
        double e_sum;
        int i; int j;
        e_sum = 0;
        for (i = 0; i < 2000; i++) {
                for (j = 0; j < 2000; j++) {
                        e_sum += mat_c[i][j] < mat_ref[i][j] ?
                                mat_ref[i][j] - mat_c[i][j] :
                                mat_c[i][j] - mat_ref[i][j];
                }
        }
        return e_sum < 1E-6;
}


decompiled_code:
int __fastcall run_multiply(int a1)
{
double v1; // xmm0_8
int result; // eax
double v3; // xmm0_8
double v4; // [rsp+8h] [rbp-10h]
double v5; // [rsp+8h] [rbp-10h]

v4 = get_time();
matmul_opt();
v1 = get_time();
result = printf("Time: %.4f\n", v1 - v4);
if ( a1 )
{
printf("Verifying solution... ");
v5 = get_time();
matmul_ref();
v3 = get_time();
if ( verify_result() )
puts("OK");
else
puts("MISMATCH");
result = printf("Reference runtime: %f\n", v3 - v5);
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(int a1)
{
double v1; // xmm0_8
int result; // eax
double v3; // xmm0_8
double v4; // [rsp+8h] [rbp-10h]
double v5; // [rsp+8h] [rbp-10h]

v4 = func12();
func7();
v1 = func12();
result = printf("Time: %.4f\n", v1 - v4);
if ( a1 )
{
printf("Verifying solution... ");
v5 = func12();
func8();
v3 = func12();
if ( func9() )
puts("OK");
else
puts("MISMATCH");
result = printf("Reference runtime: %f\n", v3 - v5);
}
return result;
}

original_code:
static void
run_multiply(int verify)
{
        double time_start, time_stop;
        time_start = get_time();
        matmul_opt();
        time_stop = get_time();
        printf("Time: %.4f\n", time_stop - time_start);
        if (verify) {
                printf("Verifying solution... ");
                time_start = get_time();
                matmul_ref();
                time_stop = get_time();
                if (verify_result())
                        printf("OK\n");
                else
                        printf("MISMATCH\n");
                printf("Reference runtime: %f\n", time_stop - time_start);
        }
}

canonical_original_code:
static void run_multiply(int verify)
{
        double time_start; double time_stop;
        time_start = get_time();
        matmul_opt();
        time_stop = get_time();
        printf("Time: %.4f\n", time_stop - time_start);
        if (verify) {
                printf("Verifying solution... ");
                time_start = get_time();
                matmul_ref();
                time_stop = get_time();
                if (verify_result())
                        printf("OK\n");
                else
                        printf("MISMATCH\n");
                printf("Reference runtime: %f\n", time_stop - time_start);
        }
}


canonical_decompiled_code:
void func0()
{
free(lh_threads);
free(lock_cells);
}

original_code:
static void
impl_fini()
{
        free(lh_threads);
        free(lock_cells);
}


decompiled_code:
char *__fastcall impl_init(int a1)
{
char *v1; // rbx
char *result; // rax
char *v3; // rdx
char *v4; // rcx

num_threads = a1;
lh_threads = malloc((__int64)a1 << 12);
v1 = (char *)lh_threads;
result = (char *)malloc((__int64)a1 << 12);
lock_cells = result;
if ( !result || !v1 )
_assert_fail("lh_threads && lock_cells", "cs_queue.c", 0x64u, "impl_init");
lock_l = (__int64)&lock_cell0;
if ( a1 > 0 )
{
v3 = v1 + 8;
v4 = &result[4096 * (unsigned __int64)(unsigned int)a1];
do
{
*((_QWORD *)v3 - 1) = result;
v3 += 4096;
*((_QWORD *)v3 - 512) = result;
result += 4096;
}
while ( result != v4 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(int a1)
{
char *v1; // rbx
char *result; // rax
char *v3; // rdx
char *v4; // rcx

num_threads = a1;
lh_threads = malloc((__int64)a1 << 12);
v1 = (char *)lh_threads;
result = (char *)malloc((__int64)a1 << 12);
lock_cells = result;
if ( !result || !v1 )
_assert_fail("lh_threads && lock_cells", "cs_queue.c", 0x64u, "impl_init");
lock_l = (__int64)&lock_cell0;
if ( a1 > 0 )
{
v3 = v1 + 8;
v4 = &result[4096 * (unsigned __int64)(unsigned int)a1];
do
{
*((_QWORD *)v3 - 1) = result;
v3 += 4096;
*((_QWORD *)v3 - 512) = result;
result += 4096;
}
while ( result != v4 );
}
return result;
}

original_code:
static void
impl_init(int _num_threads)
{
        num_threads = _num_threads;
        lh_threads = malloc(sizeof(*lh_threads) * num_threads);
        lock_cells = malloc(sizeof(*lock_cells) * num_threads);
        ((lh_threads && lock_cells) ? (void) (0) : __assert_fail ("lh_threads && lock_cells", "cs_queue.c", 100, __extension__ __PRETTY_FUNCTION__));
        lock_l = &lock_cell0;
        for (int i = 0; i < num_threads; i++) {
                lh_threads[i].i = &lock_cells[i].v;
                lh_threads[i].p = lh_threads[i].i;
        }
}


decompiled_code:
__int64 __fastcall impl_enter_critical(int a1)
{
if ( a1 < 0 || num_threads <= a1 )
_assert_fail("thread >= 0 && thread < num_threads", "cs_queue.c", 0x77u, "impl_enter_critical");
return lh_acquire_constprop_0((__int64 *)lh_threads + 512 * (__int64)a1, (_QWORD *)lh_threads + 512 * (__int64)a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
if ( a1 < 0 || num_threads <= a1 )
_assert_fail("thread >= 0 && thread < num_threads", "cs_queue.c", 0x77u, "impl_enter_critical");
return func2((__int64 *)lh_threads + 512 * (__int64)a1, (_QWORD *)lh_threads + 512 * (__int64)a1 + 1);
}

original_code:
static void
impl_enter_critical(int thread)
{
        ((thread >= 0 && thread < num_threads) ? (void) (0) : __assert_fail ("thread >= 0 && thread < num_threads", "cs_queue.c", 119, __extension__ __PRETTY_FUNCTION__));
        lh_acquire((int ** volatile)&lock_l,
                   (int ** volatile)&lh_threads[thread].i,
                   (volatile int **)&lh_threads[thread].p);
}

canonical_original_code:
static void impl_enter_critical(int thread)
{
        ((thread >= 0 && thread < num_threads) ? (void) (0) : __assert_fail ("thread >= 0 && thread < num_threads", "cs_queue.c", 119, __extension__ __PRETTY_FUNCTION__));
        lh_acquire((int **)&lock_l,
                   (int **)&lh_threads[thread].i,
                   (int **)&lh_threads[thread].p);
}

variable_types: thread int


decompiled_code:
__int64 matvec_ref()
{
float *v0; // r8
float *v1; // rdi
int v2; // ecx
float *v3; // rsi
float v4; // xmm1_4
__int64 result; // rax
float v6; // xmm0_4

v0 = (float *)mat_a;
v1 = (float *)vec_b;
v2 = 0;
v3 = (float *)vec_ref;
do
{
v4 = *v3;
for ( result = 0LL; result != 0x4000; ++result )
{
v6 = v0[(int)(result | v2)] * v1[result];
v4 = v4 + v6;
*v3 = v4;
}
v2 += 0x4000;
++v3;
}
while ( v2 != 0x10000000 );
return result;
}

canonical_decompiled_code:
__int64 func7()
{
float *v0; // r8
float *v1; // rdi
int v2; // ecx
float *v3; // rsi
float v4; // xmm1_4
__int64 result; // rax
float v6; // xmm0_4

v0 = (float *)mat_a;
v1 = (float *)vec_b;
v2 = 0;
v3 = (float *)vec_ref;
do
{
v4 = *v3;
for ( result = 0LL; result != 0x4000; ++result )
{
v6 = v0[(int)(result | v2)] * v1[result];
v4 = v4 + v6;
*v3 = v4;
}
v2 += 0x4000;
++v3;
}
while ( v2 != 0x10000000 );
return result;
}


init

decompiled_code:
void *init()
{
void *v0; // rbx
void *v1; // r13
void *v2; // r12
void *v3; // rbp
int v4; // esi
int v5; // er9
__int64 v6; // r8
int i; // eax
int v8; // ecx
int v9; // edx
char v10; // al

v0 = mm_malloc_constprop_0(0x40000000uLL);
mat_a = v0;
v1 = mm_malloc_constprop_0(0x10000uLL);
vec_b = v1;
v2 = mm_malloc_constprop_0(0x10000uLL);
vec_c = v2;
vec_ref = mm_malloc_constprop_0(0x10000uLL);
v3 = vec_ref;
if ( v2 == 0LL || v0 == 0LL || v1 == 0LL || !vec_ref )
{
fwrite("Memory allocation failed\n", 1uLL, 0x19uLL, stderr);
abort();
}
v4 = 0;
v5 = 0;
v6 = 0LL;
do
{
for ( i = 0; i != 0x4000; ++i )
{
v8 = ((_BYTE)i + (_BYTE)v4) & 0xF;
v9 = i | ((_DWORD)v6 << 14);
*((float *)v0 + v9) = (float)v8 * 0.25;
}
v10 = v5;
v4 += 7;
v5 += 17;
*((float *)v1 + v6++) = (float)(v10 & 0xF) * 0.25;
}
while ( v4 != 114688 );
memset(v2, 0, 0x10000uLL);
return memset(v3, 0, 0x10000uLL);
}

canonical_original_code:
static void init()
{
        int i; int j;
        mat_a = _mm_malloc(sizeof(*mat_a) * (1 << 14) * (1 << 14), 16);
        vec_b = _mm_malloc(sizeof(*vec_b) * (1 << 14), 16);
        vec_c = _mm_malloc(sizeof(*vec_c) * (1 << 14), 16);
        vec_ref = _mm_malloc(sizeof(*vec_ref) * (1 << 14), 16);
        if (!mat_a || !vec_b || !vec_c || !vec_ref) {
                fprintf(stderr, "Memory allocation failed\n");
                abort();
        }
        for (i = 0; i < (1 << 14); i++) {
                for (j = 0; j < (1 << 14); j++)
                        mat_a[(((i) << 14) | (j))] = ((7 * i + j) & 0x0F) * 0x1P-2F;
                vec_b[i] = ((i * 17) & 0x0F) * 0x1P-2F;
        }
        memset(vec_c, 0, sizeof(*vec_c) * (1 << 14));
        memset(vec_ref, 0, sizeof(*vec_ref) * (1 << 14));
}


decompiled_code:
int __fastcall util_monotonic_time(struct timespec *tp)
{
int result; // eax

result = clock_gettime(1, tp);
if ( result )
{
perror("clock_gettime failed");
abort();
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(struct timespec *tp)
{
int result; // eax

result = clock_gettime(1, tp);
if ( result )
{
perror("clock_gettime failed");
abort();
}
return result;
}

original_code:
void
util_monotonic_time(struct timespec *ts)
{
        if (clock_gettime(1, ts) != 0) {
                perror("clock_gettime failed");
                abort();
        }
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } *


decompiled_code:
double __fastcall util_time_diff(__int64 *a1, __int64 *a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // rsi

v2 = *a2;
if ( *a2 > *a1 )
{
v3 = a2[1];
v4 = a1[1];
}
else if ( *a2 != *a1 || (v3 = a2[1], v4 = a1[1], v3 < v4) )
{
__assert_fail(
"ts_stop->tv_sec > ts_start->tv_sec || (ts_stop->tv_sec == ts_start->tv_sec && ts_stop->tv_nsec >= ts_start->tv_nsec)",
"util.c",
0x27u,
"util_time_diff");
}
return (double)((int)v3 - (int)v4) * 0.000000001 + (double)(int)(v2 - *a1);
}

canonical_decompiled_code:
double __fastcall func15(__int64 *a1, __int64 *a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // rsi

v2 = *a2;
if ( *a2 > *a1 )
{
v3 = a2[1];
v4 = a1[1];
}
else if ( *a2 != *a1 || (v3 = a2[1], v4 = a1[1], v3 < v4) )
{
__assert_fail(
"ts_stop->tv_sec > ts_start->tv_sec || (ts_stop->tv_sec == ts_start->tv_sec && ts_stop->tv_nsec >= ts_start->tv_nsec)",
"util.c",
0x27u,
"util_time_diff");
}
return (double)((int)v3 - (int)v4) * 0.000000001 + (double)(int)(v2 - *a1);
}

original_code:
double
util_time_diff(struct timespec *ts_start, struct timespec *ts_stop)
{
        ((void) sizeof ((ts_stop->tv_sec > ts_start->tv_sec || (ts_stop->tv_sec == ts_start->tv_sec && ts_stop->tv_nsec >= ts_start->tv_nsec)) ? 1 : 0), __extension__ ({ if (ts_stop->tv_sec > ts_start->tv_sec || (ts_stop->tv_sec == ts_start->tv_sec && ts_stop->tv_nsec >= ts_start->tv_nsec)) ; else __assert_fail ("ts_stop->tv_sec > ts_start->tv_sec || (ts_stop->tv_sec == ts_start->tv_sec && ts_stop->tv_nsec >= ts_start->tv_nsec)", "util.c", 39, __extension__ __PRETTY_FUNCTION__); }));
        return ts_stop->tv_sec - ts_start->tv_sec +
                (ts_stop->tv_nsec - ts_start->tv_nsec) * 1E-9;
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
int __fastcall print_vector_epi8(__m128i a1)
{
__int64 v1; // r14
__int64 v3; // [rsp-E0h] [rbp-120h]
__int64 v4; // [rsp-D8h] [rbp-118h]
__int64 v5; // [rsp-D0h] [rbp-110h]
__int64 v6; // [rsp-C8h] [rbp-108h]
__int64 v7; // [rsp-B8h] [rbp-F8h]
__int64 v8; // [rsp-B0h] [rbp-F0h]
__int64 v9; // [rsp-A8h] [rbp-E8h]
__int64 v10; // [rsp-A0h] [rbp-E0h]
__int64 v11; // [rsp-98h] [rbp-D8h]
__int64 v12; // [rsp-90h] [rbp-D0h]
__int64 v13; // [rsp-88h] [rbp-C8h]
__int64 v14; // [rsp-80h] [rbp-C0h]
__int64 v15; // [rsp-78h] [rbp-B8h]
__int64 v16; // [rsp-70h] [rbp-B0h]
unsigned int v17; // [rsp+4h] [rbp-3Ch]

v17 = (char)_mm_extract_epi8(a1, 5);
v16 = (unsigned int)(char)_mm_extract_epi8(a1, 4);
v15 = (unsigned int)(char)_mm_extract_epi8(a1, 3);
v14 = (unsigned int)(char)_mm_extract_epi8(a1, 2);
v13 = (unsigned int)(char)_mm_extract_epi8(a1, 1);
v12 = (unsigned int)(char)_mm_extract_epi8(a1, 0);
v11 = (unsigned int)(char)_mm_extract_epi8(a1, 15);
v10 = (unsigned int)(char)_mm_extract_epi8(a1, 14);
v9 = (unsigned int)(char)_mm_extract_epi8(a1, 13);
v8 = (unsigned int)(char)_mm_extract_epi8(a1, 12);
v7 = (unsigned int)(char)_mm_extract_epi8(a1, 11);
v1 = (unsigned int)(char)_mm_extract_epi8(a1, 10);
v6 = (unsigned int)(char)_mm_extract_epi8(a1, 9);
v5 = (unsigned int)(char)_mm_extract_epi8(a1, 8);
v4 = (unsigned int)(char)_mm_extract_epi8(a1, 7);
v3 = (unsigned int)(char)_mm_extract_epi8(a1, 6);
return printf(
"%.2hhx%.2hhx%.2hhx%.2hhx %.2hhx%.2hhx%.2hhx%.2hhx %.2hhx%.2hhx%.2hhx%.2hhx %.2hhx%.2hhx%.2hhx%.2hhx %c%c%c%c "
"%c%c%c%c %c%c%c%c %c%c%c%c\n",
v12,
v13,
v14,
v15,
v16,
v17,
v3,
v4,
v5,
v6,
v1,
v7,
v8,
v9,
v10,
v11,
v12,
v13,
v14,
v15,
v16,
v17,
v3,
v4,
v5,
v6,
v1,
v7,
v8,
v9,
v10,
v11);
}

canonical_decompiled_code:
int __fastcall func16(__m128i a1)
{
__int64 v1; // r14
__int64 v3; // [rsp-E0h] [rbp-120h]
__int64 v4; // [rsp-D8h] [rbp-118h]
__int64 v5; // [rsp-D0h] [rbp-110h]
__int64 v6; // [rsp-C8h] [rbp-108h]
__int64 v7; // [rsp-B8h] [rbp-F8h]
__int64 v8; // [rsp-B0h] [rbp-F0h]
__int64 v9; // [rsp-A8h] [rbp-E8h]
__int64 v10; // [rsp-A0h] [rbp-E0h]
__int64 v11; // [rsp-98h] [rbp-D8h]
__int64 v12; // [rsp-90h] [rbp-D0h]
__int64 v13; // [rsp-88h] [rbp-C8h]
__int64 v14; // [rsp-80h] [rbp-C0h]
__int64 v15; // [rsp-78h] [rbp-B8h]
__int64 v16; // [rsp-70h] [rbp-B0h]
unsigned int v17; // [rsp+4h] [rbp-3Ch]

v17 = (char)_mm_extract_epi8(a1, 5);
v16 = (unsigned int)(char)_mm_extract_epi8(a1, 4);
v15 = (unsigned int)(char)_mm_extract_epi8(a1, 3);
v14 = (unsigned int)(char)_mm_extract_epi8(a1, 2);
v13 = (unsigned int)(char)_mm_extract_epi8(a1, 1);
v12 = (unsigned int)(char)_mm_extract_epi8(a1, 0);
v11 = (unsigned int)(char)_mm_extract_epi8(a1, 15);
v10 = (unsigned int)(char)_mm_extract_epi8(a1, 14);
v9 = (unsigned int)(char)_mm_extract_epi8(a1, 13);
v8 = (unsigned int)(char)_mm_extract_epi8(a1, 12);
v7 = (unsigned int)(char)_mm_extract_epi8(a1, 11);
v1 = (unsigned int)(char)_mm_extract_epi8(a1, 10);
v6 = (unsigned int)(char)_mm_extract_epi8(a1, 9);
v5 = (unsigned int)(char)_mm_extract_epi8(a1, 8);
v4 = (unsigned int)(char)_mm_extract_epi8(a1, 7);
v3 = (unsigned int)(char)_mm_extract_epi8(a1, 6);
return printf(
"%.2hhx%.2hhx%.2hhx%.2hhx %.2hhx%.2hhx%.2hhx%.2hhx %.2hhx%.2hhx%.2hhx%.2hhx %.2hhx%.2hhx%.2hhx%.2hhx %c%c%c%c "
"%c%c%c%c %c%c%c%c %c%c%c%c\n",
v12,
v13,
v14,
v15,
v16,
v17,
v3,
v4,
v5,
v6,
v1,
v7,
v8,
v9,
v10,
v11,
v12,
v13,
v14,
v15,
v16,
v17,
v3,
v4,
v5,
v6,
v1,
v7,
v8,
v9,
v10,
v11);
}

variable_types:
v
long long

variable_types:
cv
char *


decompiled_code:
int __fastcall print_vector_pd(__m128d a1)
{
return printf("%f %f\n", a1.m128d_f64[0], _mm_unpackhi_pd(a1, a1).m128d_f64[0]);
}

canonical_decompiled_code:
int __fastcall func17(__m128d a1)
{
return printf("%f %f\n", a1.m128d_f64[0], _mm_unpackhi_pd(a1, a1).m128d_f64[0]);
}

original_code:
void
print_vector_pd(__m128d v)
{
        const double *dv = (double *)&v;
        printf("%f %f\n", dv[0], dv[1]);
}

canonical_original_code:
void print_vector_pd(double v)
{
        double *dv = (double *)&v;
        printf("%f %f\n", dv[0], dv[1]);
}

variable_types: v double

variable_types:
dv
double *


original_code:
void
print_vector_ps(__m128 v)
{
        const float *sv = (float *)&v;
        printf("%f %f %f %f\n",
               sv[0], sv[1], sv[2], sv[3]);
}

canonical_original_code:
void print_vector_ps(float v)
{
        float *sv = (float *)&v;
        printf("%f %f %f %f\n",
               sv[0], sv[1], sv[2], sv[3]);
}

variable_types: v float

variable_types:
sv
float *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
init(argc, argv, envp);
run_multiply();
mm_free(mat_a);
mm_free(vec_b);
mm_free(vec_c);
mm_free(vec_ref);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func13(argc, argv, envp);
func10();
func11(mat_a);
func11(vec_b);
func11(vec_c);
func11(vec_ref);
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
        init();
        run_multiply();
        _mm_free(mat_a);
        _mm_free(vec_b);
        _mm_free(vec_c);
        _mm_free(vec_ref);
        return 0;
}

variable_types: argc int


original_code:
static int
verify_result()
{
        float e_sum;
        int i;
        e_sum = 0;
        for (i = 0; i < (1 << 14); i++) {
                e_sum += vec_c[i] < vec_ref[i] ?
                        vec_ref[i] - vec_c[i] :
                        vec_c[i] - vec_ref[i];
        }
        printf("e_sum: %.e\n", e_sum);
        return e_sum < 1E-6;
}

variable_types: i int


decompiled_code:
int run_multiply()
{
int result; // eax
double v1; // [rsp+0h] [rbp-38h]
double v2; // [rsp+8h] [rbp-30h]
struct timespec tp; // [rsp+10h] [rbp-28h] BYREF
struct timespec v4; // [rsp+20h] [rbp-18h] BYREF

puts("Starting SSE run...");
util_monotonic_time(&tp);
matvec_sse();
util_monotonic_time(&v4);
v2 = util_time_diff(&tp, &v4);
printf("SSE run completed in %.2f s\n", v2);
puts("Starting reference run...");
util_monotonic_time(&tp);
matvec_ref();
util_monotonic_time(&v4);
v1 = util_time_diff(&tp, &v4);
printf("Reference run completed in %.2f s\n", v1);
printf("Speedup: %.2f\n", v1 / v2);
if ( verify_result() )
result = puts("OK");
else
result = puts("MISMATCH");
return result;
}

canonical_decompiled_code:
int func10()
{
int result; // eax
double v1; // [rsp+0h] [rbp-38h]
double v2; // [rsp+8h] [rbp-30h]
struct timespec tp; // [rsp+10h] [rbp-28h] BYREF
struct timespec v4; // [rsp+20h] [rbp-18h] BYREF

puts("Starting SSE run...");
func14(&tp);
func9();
func14(&v4);
v2 = func15(&tp, &v4);
printf("SSE run completed in %.2f s\n", v2);
puts("Starting reference run...");
func14(&tp);
func7();
func14(&v4);
v1 = func15(&tp, &v4);
printf("Reference run completed in %.2f s\n", v1);
printf("Speedup: %.2f\n", v1 / v2);
if ( func8() )
result = puts("OK");
else
result = puts("MISMATCH");
return result;
}

original_code:
static void
run_multiply()
{
        struct timespec ts_start, ts_stop;
        double runtime_ref, runtime_sse;
        printf("Starting SSE run...\n");
        util_monotonic_time(&ts_start);
        matvec_sse();
        util_monotonic_time(&ts_stop);
        runtime_sse = util_time_diff(&ts_start, &ts_stop);
        printf("SSE run completed in %.2f s\n",
               runtime_sse);
        printf("Starting reference run...\n");
        util_monotonic_time(&ts_start);
 matvec_ref();
        util_monotonic_time(&ts_stop);
        runtime_ref = util_time_diff(&ts_start, &ts_stop);
        printf("Reference run completed in %.2f s\n",
               runtime_ref);
        printf("Speedup: %.2f\n",
               runtime_ref / runtime_sse);
 if (verify_result())
     printf("OK\n");
 else
     printf("MISMATCH\n");
}

canonical_original_code:
static void run_multiply()
{
        struct timespec ts_start; struct timespec ts_stop;
        double runtime_ref; double runtime_sse;
        printf("Starting SSE run...\n");
        util_monotonic_time(&ts_start);
        matvec_sse();
        util_monotonic_time(&ts_stop);
        runtime_sse = util_time_diff(&ts_start, &ts_stop);
        printf("SSE run completed in %.2f s\n",
               runtime_sse);
        printf("Starting reference run...\n");
        util_monotonic_time(&ts_start);
 matvec_ref();
        util_monotonic_time(&ts_stop);
        runtime_ref = util_time_diff(&ts_start, &ts_stop);
        printf("Reference run completed in %.2f s\n",
               runtime_ref);
        printf("Speedup: %.2f\n",
               runtime_ref / runtime_sse);
 if (verify_result())
     printf("OK\n");
 else
     printf("MISMATCH\n");
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
void *__fastcall thread_compute(void *a1)
{
unsigned int v1; // ebp
unsigned int v2; // er13
unsigned int v3; // er12
unsigned int v4; // er12
__int64 v5; // rdx
int v6; // ebx
double *v7; // rdx
double v8; // xmm0_8
double *i; // rax
double v10; // xmm1_8

v1 = *(_DWORD *)a1;
v2 = *(_DWORD *)a1 * (gs_size / (int)gs_nthreads);
v3 = gs_size / (int)gs_nthreads + v2;
if ( !*(_DWORD *)a1 )
v2 = 1;
v4 = v3 - (gs_nthreads - 1 == v1);
gs_verbose_printf("%i: lbound: %i, rbound: %i\n", v1, v2, v4);
v5 = gs_iterations;
if ( gs_iterations > 0 )
{
v6 = 0;
do
{
if ( *(double *)&global_error <= gs_tolerance )
break;
thread_sweep_constprop_0(v1, v2, v4);
if ( gs_nthreads - 1 == v1 )
{
global_error = 0LL;
if ( (int)gs_nthreads > 0 )
{
v7 = (double *)threads;
v8 = 0.0;
for ( i = (double *)((char *)threads + 80); ; i += 10 )
{
v10 = v7[2];
v7 = i;
v8 = v8 + v10;
if ( i == (double *)((char *)threads + 80 * v1 + 80) )
break;
}
global_error = *(_QWORD *)&v8;
}
}
++v6;
pthread_barrier_wait(&barrier);
*((_DWORD *)threads + 20 * (int)v1 + 6) = 0;
pthread_barrier_wait(&barrier);
v5 = gs_iterations;
}
while ( gs_iterations > v6 );
}
gs_verbose_printf("\t**** Thread %d done after %d iterations ****\n", v1, v5);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
unsigned int v1; // ebp
unsigned int v2; // er13
unsigned int v3; // er12
unsigned int v4; // er12
__int64 v5; // rdx
int v6; // ebx
double *v7; // rdx
double v8; // xmm0_8
double *i; // rax
double v10; // xmm1_8

v1 = *(_DWORD *)a1;
v2 = *(_DWORD *)a1 * (gs_size / (int)gs_nthreads);
v3 = gs_size / (int)gs_nthreads + v2;
if ( !*(_DWORD *)a1 )
v2 = 1;
v4 = v3 - (gs_nthreads - 1 == v1);
gs_verbose_printf("%i: lbound: %i, rbound: %i\n", v1, v2, v4);
v5 = gs_iterations;
if ( gs_iterations > 0 )
{
v6 = 0;
do
{
if ( *(double *)&global_error <= gs_tolerance )
break;
func0(v1, v2, v4);
if ( gs_nthreads - 1 == v1 )
{
global_error = 0LL;
if ( (int)gs_nthreads > 0 )
{
v7 = (double *)threads;
v8 = 0.0;
for ( i = (double *)((char *)threads + 80); ; i += 10 )
{
v10 = v7[2];
v7 = i;
v8 = v8 + v10;
if ( i == (double *)((char *)threads + 80 * v1 + 80) )
break;
}
global_error = *(_QWORD *)&v8;
}
}
++v6;
pthread_barrier_wait(&barrier);
*((_DWORD *)threads + 20 * (int)v1 + 6) = 0;
pthread_barrier_wait(&barrier);
v5 = gs_iterations;
}
while ( gs_iterations > v6 );
}
gs_verbose_printf("\t**** Thread %d done after %d iterations ****\n", v1, v5);
return 0LL;
}

original_code:
static void *
thread_compute(void *_self)
{
        thread_info_t *self = (thread_info_t *)_self;
        const int tid = self->thread_id;
        int lbound = (gs_size/gs_nthreads)*tid;
 int rbound = lbound + gs_size/gs_nthreads;
 if (tid == 0)
  lbound++;
 if (tid == gs_nthreads-1)
  rbound--;
        gs_verbose_printf("%i: lbound: %i, rbound: %i\n",
                          tid, lbound, rbound);
        for (int iter = 0;
             iter < gs_iterations && global_error > gs_tolerance;
             iter++) {
                if (0) fprintf(stderr, "%i: Starting iteration %i\n", tid, iter);
                thread_sweep(tid, iter, lbound, rbound);
  if(tid == (gs_nthreads - 1)) {
   global_error = 0;
   for (int i=0;i<gs_nthreads;i++)
    global_error+=threads[i].error;
  }
                if (0) fprintf(stderr, "%d: iteration %d done\n", tid, iter);
  pthread_barrier_wait(&barrier);
  threads[tid].c_row = 0;
  pthread_barrier_wait(&barrier);
        }
        gs_verbose_printf(
                "\t****  Thread %d done after %d iterations ****\n",
                tid, gs_iterations);
        return ((void *)0);
}

canonical_original_code:
static void *thread_compute(void *_self)
{
        struct thread_info_t *self = (thread_info_t *)_self;
        int tid = self->thread_id;
        int lbound = (gs_size/gs_nthreads)*tid;
 int rbound = lbound + gs_size/gs_nthreads;
 if (tid == 0)
  lbound++;
 if (tid == gs_nthreads-1)
  rbound--;
        gs_verbose_printf("%i: lbound: %i, rbound: %i\n",
                          tid, lbound, rbound);
        for (int iter = 0;
             iter < gs_iterations && global_error > gs_tolerance;
             iter++) {
                if (0) fprintf(stderr, "%i: Starting iteration %i\n", tid, iter);
                thread_sweep(tid, iter, lbound, rbound);
  if(tid == (gs_nthreads - 1)) {
   global_error = 0;
   for (int i = 0;i<gs_nthreads;i++)
    global_error+=threads[i].error;
  }
                if (0) fprintf(stderr, "%d: iteration %d done\n", tid, iter);
  pthread_barrier_wait(&barrier);
  threads[tid].c_row = 0;
  pthread_barrier_wait(&barrier);
        }
        gs_verbose_printf(
                "\t****  Thread %d done after %d iterations ****\n",
                tid, gs_iterations);
        return ((void *)0);
}

variable_types: struct thread_info_t { int thread_id; unsigned long thread; double error; int c_row; double padding[6]; } *

variable_types: tid int

variable_types: lbound int

variable_types: rbound int

variable_types: iter int

return_type: void *


decompiled_code:
int gsi_init()
{
_DWORD *v0; // rax
unsigned int v1; // er8
_DWORD *v2; // rdx

gs_verbose_printf("\t**** Initializing the environment ****\n");
v0 = malloc(80LL * (int)gs_nthreads);
threads = v0;
if ( !v0 )
{
fwrite("Failed to allocate memory for thread information.\n", 1uLL, 0x32uLL, stderr);
exit(1);
}
v1 = gs_nthreads;
*(double *)&global_error = gs_tolerance + 1.0;
if ( (int)gs_nthreads > 0 )
{
v2 = &v0[20 * gs_nthreads];
do
{
v0[6] = 0;
v0 += 20;
}
while ( v0 != v2 );
}
return pthread_barrier_init(&barrier, 0LL, v1);
}

canonical_decompiled_code:
int func2()
{
_DWORD *v0; // rax
unsigned int v1; // er8
_DWORD *v2; // rdx

gs_verbose_printf("\t**** Initializing the environment ****\n");
v0 = malloc(80LL * (int)gs_nthreads);
threads = v0;
if ( !v0 )
{
fwrite("Failed to allocate memory for thread information.\n", 1uLL, 0x32uLL, stderr);
exit(1);
}
v1 = gs_nthreads;
*(double *)&global_error = gs_tolerance + 1.0;
if ( (int)gs_nthreads > 0 )
{
v2 = &v0[20 * gs_nthreads];
do
{
v0[6] = 0;
v0 += 20;
}
while ( v0 != v2 );
}
return pthread_barrier_init(&barrier, 0LL, v1);
}

original_code:
void
gsi_init()
{
        gs_verbose_printf("\t****  Initializing the  environment ****\n");
        threads = (thread_info_t *)malloc(gs_nthreads * sizeof(thread_info_t));
        if (!threads) {
                fprintf(stderr,
                        "Failed to allocate memory for thread information.\n");
                exit(1);
        }
        global_error = gs_tolerance + 1;
 for (int i=0;i<gs_nthreads;i++)
  threads[i].c_row = 0;
 pthread_barrier_init(&barrier,((void *)0),gs_nthreads);
}

canonical_original_code:
void gsi_init()
{
        gs_verbose_printf("\t****  Initializing the  environment ****\n");
        threads = (struct thread_info_t *)malloc(gs_nthreads * sizeof(thread_info_t));
        if (!threads) {
                fprintf(stderr,
                        "Failed to allocate memory for thread information.\n");
                exit(1);
        }
        global_error = gs_tolerance + 1;
 for (int i = 0;i<gs_nthreads;i++)
  threads[i].c_row = 0;
 pthread_barrier_init(&barrier,((void *)0),gs_nthreads);
}

user_defined_types: struct thread_info_t { int thread_id; unsigned long thread; double error; int c_row; double padding[6]; }


decompiled_code:
int gsi_finish()
{
gs_verbose_printf("\t**** Cleaning environment ****\n");
if ( threads )
free(threads);
return pthread_barrier_destroy(&barrier);
}

canonical_decompiled_code:
int func3()
{
gs_verbose_printf("\t**** Cleaning environment ****\n");
if ( threads )
free(threads);
return pthread_barrier_destroy(&barrier);
}

original_code:
void
gsi_finish()
{
        gs_verbose_printf("\t****  Cleaning environment ****\n");
        if (threads)
                free(threads);
 pthread_barrier_destroy(&barrier);
}


decompiled_code:
int gsi_calculate()
{
unsigned int v0; // er13
__int64 v1; // rbx
pthread_t *v2; // rcx
unsigned int v3; // eax
signed int v4; // er12
__int64 v5; // rbx
unsigned int v6; // eax

v0 = 0;
v1 = 0LL;
if ( (int)gs_nthreads > 0 )
{
do
{
gs_verbose_printf("\tSpawning thread %d\n", v0);
v2 = (pthread_t *)((char *)threads + v1);
*(_DWORD *)v2 = v0;
v3 = pthread_create(v2 + 1, 0LL, thread_compute, v2);
v4 = v3;
if ( v3 )
{
fprintf(stderr, "Error: pthread_create() failed: %d, thread %d\n", v3, v0);
goto LABEL_12;
}
++v0;
v1 += 80LL;
}
while ( (int)gs_nthreads > (int)v0 );
if ( (int)gs_nthreads > 0 )
{
v5 = 0LL;
while ( 1 )
{
v6 = pthread_join(*(_QWORD *)((char *)threads + v5 + 8), 0LL);
if ( v6 )
break;
++v4;
v5 += 80LL;
if ( (int)gs_nthreads <= v4 )
goto LABEL_8;
}
fprintf(stderr, "Error: pthread_join() failed: %d, thread %d\n", v6, (unsigned int)v4);
LABEL_12:
exit(1);
}
}
LABEL_8:
if ( gs_tolerance >= *(double *)&global_error )
return puts("Solution converged!");
puts("Solution did NOT converge.");
return puts("Note: This is normal if you are using the default settings.");
}

canonical_decompiled_code:
int func4()
{
unsigned int v0; // er13
__int64 v1; // rbx
pthread_t *v2; // rcx
unsigned int v3; // eax
signed int v4; // er12
__int64 v5; // rbx
unsigned int v6; // eax

v0 = 0;
v1 = 0LL;
if ( (int)gs_nthreads > 0 )
{
do
{
gs_verbose_printf("\tSpawning thread %d\n", v0);
v2 = (pthread_t *)((char *)threads + v1);
*(_DWORD *)v2 = v0;
v3 = pthread_create(v2 + 1, 0LL, thread_compute, v2);
v4 = v3;
if ( v3 )
{
fprintf(stderr, "Error: pthread_create() failed: %d, thread %d\n", v3, v0);
goto LABEL_12;
}
++v0;
v1 += 80LL;
}
while ( (int)gs_nthreads > (int)v0 );
if ( (int)gs_nthreads > 0 )
{
v5 = 0LL;
while ( 1 )
{
v6 = pthread_join(*(_QWORD *)((char *)threads + v5 + 8), 0LL);
if ( v6 )
break;
++v4;
v5 += 80LL;
if ( (int)gs_nthreads <= v4 )
goto LABEL_8;
}
fprintf(stderr, "Error: pthread_join() failed: %d, thread %d\n", v6, (unsigned int)v4);
LABEL_12:
exit(1);
}
}
LABEL_8:
if ( gs_tolerance >= *(double *)&global_error )
return puts("Solution converged!");
puts("Solution did NOT converge.");
return puts("Note: This is normal if you are using the default settings.");
}

original_code:
void
gsi_calculate()
{
        int err;
        for (int t = 0; t < gs_nthreads; t++) {
                gs_verbose_printf("\tSpawning thread %d\n",t);
                threads[t].thread_id = t;
                err = pthread_create(&threads[t].thread, ((void *)0),
                                     thread_compute, &threads[t]);
                if (err) {
                        fprintf(stderr,
                                "Error: pthread_create() failed: %d, "
                                "thread %d\n",
                                err, t);
                        exit(1);
                }
        }
        for (int t = 0; t < gs_nthreads; t++) {
                err = pthread_join(threads[t].thread, ((void *)0));
                if (err) {
                        fprintf(stderr,
                                "Error: pthread_join() failed: %d, "
                                "thread %d\n",
                                err, t);
                        exit(1);
                }
        }
        if (global_error <= gs_tolerance)
                printf("Solution converged!\n");
        else {
                printf("Solution did NOT converge.\n");
                printf("Note: This is normal if you are using the "
                       "default settings.\n");
        }
}

variable_types: err int

variable_types: t int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er15
int v4; // eax
unsigned __int8 *v5; // rbx
int v6; // er12
signed int v7; // ebp
signed int v8; // er14
int v9; // er12
unsigned __int8 *v10; // r13
_BYTE v11[8248]; // [rsp+0h] [rbp-2038h] BYREF

if ( argc != 1 )
{
fprintf(stderr, "usage: %s <in-file >out-file\n", *argv);
exit(1);
}
v3 = 0;
fwrite("#\n", 1uLL, 2uLL, _bss_start);
fwrite("# Miscellaneous data structures:\n", 1uLL, 0x21uLL, _bss_start);
fwrite("# WARNING - this file is automatically generated!\n", 1uLL, 0x32uLL, _bss_start);
fwrite("#\n", 1uLL, 2uLL, _bss_start);
fputc(10, _bss_start);
fwrite("\t.data\n", 1uLL, 7uLL, _bss_start);
fwrite("\t.globl input_data\n", 1uLL, 0x13uLL, _bss_start);
fwrite("input_data:\n", 1uLL, 0xCuLL, _bss_start);
while ( 1 )
{
v4 = read(0, v11, 0x2000uLL);
if ( v4 <= 0 )
{
fwrite("\t.globl input_len\n", 1uLL, 0x12uLL, _bss_start);
fprintf(_bss_start, "input_len:\t.long\t0x%x\n", v3);
fflush(_bss_start);
fclose(_bss_start);
exit(0);
}
v5 = v11;
v6 = 0;
v7 = 0;
v8 = (v4 + 3) & 0xFFFFFFFC;
do
{
v10 = v5 + 4;
if ( !v6 )
{
v10 = v5;
v9 = v7;
LABEL_7:
v7 = v9;
v5 = v10 + 4;
v6 = 1;
fwrite("\t.long\t", 1uLL, 7uLL, _bss_start);
fprintf(_bss_start, "0x%02X%02X%02X%02X", *v10, v10[1], v10[2], v10[3]);
goto LABEL_8;
}
++v6;
fprintf(_bss_start, "0x%02X%02X%02X%02X", *v5, v5[1], v5[2], v5[3]);
if ( v6 == 4 )
{
v9 = v7 + 4;
fprintf(_bss_start, " # %x \n", v3 + v7 - 12);
fflush(_bss_start);
if ( v8 <= v7 + 4 )
goto LABEL_13;
goto LABEL_7;
}
v5 += 4;
LABEL_8:
v7 += 4;
fputc(44, _bss_start);
}
while ( v8 > v7 );
fwrite("0\n", 1uLL, 2uLL, _bss_start);
LABEL_13:
v3 += v8;
}
}

original_code:
int
main (int argc, const char * const * argv)
{
    int offset = 0, clear_screen = 0, end_common_opts = 0, retval;
    const char *title = ((void *)0);
    (void) setlocale (6, "");
    if (argc < 2) {
 Usage (argv[0]);
 exit (-1);
    }
    while (offset < argc - 1 && !end_common_opts) {
 if (!strcmp (argv[offset + 1], "--title")) {
     if (argc - offset < 3 || title != ((void *)0)) {
  Usage (argv[0]);
  exit (-1);
     } else {
  title = argv[offset + 2];
  offset += 2;
     }
        } else if (!strcmp (argv[offset + 1], "--backtitle")) {
            if (backtitle != ((void *)0)) {
                Usage (argv[0]);
                exit (-1);
            } else {
                backtitle = argv[offset + 2];
                offset += 2;
            }
 } else if (!strcmp (argv[offset + 1], "--clear")) {
     if (clear_screen) {
  Usage (argv[0]);
  exit (-1);
     } else if (argc == 2) {
  init_dialog ();
  wrefresh(stdscr);
  end_dialog ();
  return 0;
     } else {
  clear_screen = 1;
  offset++;
     }
 } else
     end_common_opts = 1;
    }
    if (argc - 1 == offset) {
 Usage (argv[0]);
 exit (-1);
    }
    for (modePtr = modes; modePtr->name; modePtr++)
 if (!strcmp (argv[offset + 1], modePtr->name))
     break;
    if (!modePtr->name)
 Usage (argv[0]);
    if (argc - offset < modePtr->argmin)
 Usage (argv[0]);
    if (modePtr->argmax && argc - offset > modePtr->argmax)
 Usage (argv[0]);
    if (title && strlen(title) > atoi(argv[offset+4])-4)
 title[atoi(argv[offset+4])-4] = 0;
    init_dialog ();
    retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset);
    if (clear_screen) {
 attr_clear (stdscr, LINES, COLS, attributes[0]);
 wrefresh(stdscr);
    }
    end_dialog();
    exit (retval);
}

canonical_original_code:
int main(int argc, char **argv)
{
    int offset = 0; int clear_screen = 0; int end_common_opts = 0; int retval;
    char *title = ((void *)0);
    (void) setlocale (6, "");
    if (argc < 2) {
 Usage (argv[0]);
 exit (-1);
    }
    while (offset < argc - 1 && !end_common_opts) {
 if (!strcmp (argv[offset + 1], "--title")) {
     if (argc - offset < 3 || title != ((void *)0)) {
  Usage (argv[0]);
  exit (-1);
     } else {
  title = argv[offset + 2];
  offset += 2;
     }
        } else if (!strcmp (argv[offset + 1], "--backtitle")) {
            if (backtitle != ((void *)0)) {
                Usage (argv[0]);
                exit (-1);
            } else {
                backtitle = argv[offset + 2];
                offset += 2;
            }
 } else if (!strcmp (argv[offset + 1], "--clear")) {
     if (clear_screen) {
  Usage (argv[0]);
  exit (-1);
     } else if (argc == 2) {
  init_dialog ();
  wrefresh(stdscr);
  end_dialog ();
  return 0;
     } else {
  clear_screen = 1;
  offset++;
     }
 } else
     end_common_opts = 1;
    }
    if (argc - 1 == offset) {
 Usage (argv[0]);
 exit (-1);
    }
    for (modePtr = modes; modePtr->name; modePtr++)
 if (!strcmp (argv[offset + 1], modePtr->name))
     break;
    if (!modePtr->name)
 Usage (argv[0]);
    if (argc - offset < modePtr->argmin)
 Usage (argv[0]);
    if (modePtr->argmax && argc - offset > modePtr->argmax)
 Usage (argv[0]);
    if (title && strlen(title) > atoi(argv[offset+4])-4)
 title[atoi(argv[offset+4])-4] = 0;
    init_dialog ();
    retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset);
    if (clear_screen) {
 attr_clear (stdscr, LINES, COLS, attributes[0]);
 wrefresh(stdscr);
    }
    end_dialog();
    exit (retval);
}

variable_types:
argv
char **

variable_types: offset int

variable_types: retval int

variable_types:
title
char *


decompiled_code:
char *get_line()
{
int v0; // ebp
_BYTE *v1; // rbx
char v2; // al
__int64 v3; // rdx
int v4; // eax
int v6; // er12
int v7; // eax
int v8; // eax

v0 = 0;
v1 = page;
end_reached = 0;
v2 = *(_BYTE *)page;
if ( *(_BYTE *)page == 10 )
{
line_0[0] = 0;
LABEL_12:
page = v1 + 1;
return line_0;
}
do
{
while ( 1 )
{
if ( !v2 )
{
v6 = fd;
v7 = lseek(fd, 0LL, 1);
if ( v7 == -1 )
{
endwin();
fwrite("\nError moving file pointer in get_line().\n", 1uLL, 0x2AuLL, stderr);
exit(-1);
}
if ( file_size <= v7 )
{
if ( !end_reached )
end_reached = 1;
v4 = end_reached;
if ( v0 > 2048 )
return line_0;
goto LABEL_21;
}
v8 = read(v6, buf, 0x2800uLL);
bytes_read = v8;
if ( v8 == -1 )
{
endwin();
fwrite("\nError reading file in get_line().\n", 1uLL, 0x23uLL, stderr);
exit(-1);
}
v1 = buf;
*((_BYTE *)buf + v8) = 0;
page = v1;
goto LABEL_4;
}
if ( v0 > 2047 )
break;
v3 = v0;
++v1;
++v0;
page = v1;
line_0[v3] = v2;
LABEL_4:
v2 = *v1;
if ( *v1 == 10 )
goto LABEL_10;
}
if ( v0 == 2048 )
{
byte_1740 = 0;
v0 = 2049;
}
v2 = *++v1;
page = v1;
}
while ( v2 != 10 );
LABEL_10:
v4 = end_reached;
if ( v0 > 2048 )
{
if ( end_reached )
return line_0;
goto LABEL_12;
}
LABEL_21:
line_0[v0] = 0;
if ( !v4 )
goto LABEL_12;
return line_0;
}

canonical_decompiled_code:
char *func0()
{
int v0; // ebp
_BYTE *v1; // rbx
char v2; // al
__int64 v3; // rdx
int v4; // eax
int v6; // er12
int v7; // eax
int v8; // eax

v0 = 0;
v1 = page;
end_reached = 0;
v2 = *(_BYTE *)page;
if ( *(_BYTE *)page == 10 )
{
line_0[0] = 0;
LABEL_12:
page = v1 + 1;
return line_0;
}
do
{
while ( 1 )
{
if ( !v2 )
{
v6 = fd;
v7 = lseek(fd, 0LL, 1);
if ( v7 == -1 )
{
endwin();
fwrite("\nError moving file pointer in get_line().\n", 1uLL, 0x2AuLL, stderr);
exit(-1);
}
if ( file_size <= v7 )
{
if ( !end_reached )
end_reached = 1;
v4 = end_reached;
if ( v0 > 2048 )
return line_0;
goto LABEL_21;
}
v8 = read(v6, buf, 0x2800uLL);
bytes_read = v8;
if ( v8 == -1 )
{
endwin();
fwrite("\nError reading file in get_line().\n", 1uLL, 0x23uLL, stderr);
exit(-1);
}
v1 = buf;
*((_BYTE *)buf + v8) = 0;
page = v1;
goto LABEL_4;
}
if ( v0 > 2047 )
break;
v3 = v0;
++v1;
++v0;
page = v1;
line_0[v3] = v2;
LABEL_4:
v2 = *v1;
if ( *v1 == 10 )
goto LABEL_10;
}
if ( v0 == 2048 )
{
byte_1740 = 0;
v0 = 2049;
}
v2 = *++v1;
page = v1;
}
while ( v2 != 10 );
LABEL_10:
v4 = end_reached;
if ( v0 > 2048 )
{
if ( end_reached )
return line_0;
goto LABEL_12;
}
LABEL_21:
line_0[v0] = 0;
if ( !v4 )
goto LABEL_12;
return line_0;
}

original_code:
static char *
get_line (void)
{
    int i = 0, fpos;
    static char line[2048 + 1];
    end_reached = 0;
    while (*page != '\n') {
 if (*page == '\0') {
     if ((fpos = lseek (fd, 0, 1)) == -1) {
  endwin ();
  fprintf (stderr, "\nError moving file pointer in "
    "get_line().\n");
  exit (-1);
     }
     if (fpos < file_size) {
  if ((bytes_read = read (fd, buf, (10*1024))) == -1) {
      endwin ();
      fprintf (stderr, "\nError reading file in get_line().\n");
      exit (-1);
  }
  buf[bytes_read] = '\0';
  page = buf;
     } else {
  if (!end_reached)
      end_reached = 1;
  break;
     }
 } else if (i < 2048)
     line[i++] = *(page++);
 else {
     if (i == 2048)
  line[i++] = '\0';
     page++;
 }
    }
    if (i <= 2048)
 line[i] = '\0';
    if (!end_reached)
 page++;
    return line;
}

canonical_original_code:
static char *get_line()
{
    int i = 0; int fpos;
    static char line[-1];
    end_reached = 0;
    while (*page != '\n') {
 if (*page == '\0') {
     if ((fpos = lseek (fd, 0, 1)) == -1) {
  endwin ();
  fprintf (stderr, "\nError moving file pointer in "
    "get_line().\n");
  exit (-1);
     }
     if (fpos < file_size) {
  if ((bytes_read = read (fd, buf, (10*1024))) == -1) {
      endwin ();
      fprintf (stderr, "\nError reading file in get_line().\n");
      exit (-1);
  }
  buf[bytes_read] = '\0';
  page = buf;
     } else {
  if (!end_reached)
      end_reached = 1;
  break;
     }
 } else if (i < 2048)
     line[i++] = *(page++);
 else {
     if (i == 2048)
  line[i++] = '\0';
     page++;
 }
    }
    if (i <= 2048)
 line[i] = '\0';
    if (!end_reached)
 page++;
    return line;
}

variable_types: fpos int

variable_types:
line
char [-1]

return_type: char *


decompiled_code:
char *__fastcall back_lines(int a1)
{
char *v1; // rbp
char *v2; // r12
char *v3; // rax
bool v4; // zf
int v5; // er13
char *result; // rax
int v7; // er14
int v8; // ebx
__int64 v9; // r15
int v10; // eax
int v11; // er13
int v12; // ebx
__int64 v13; // rbp
int v14; // eax

begin_reached = 0;
v1 = (char *)page;
if ( !end_reached )
{
v2 = (char *)buf;
v3 = (char *)page;
if ( buf != page )
{
LABEL_3:
v1 = v3 - 1;
v4 = *(v3 - 1) == 10;
page = v3 - 1;
if ( !v4 )
{
endwin();
fwrite("\nInternal error in back_lines().\n", 1uLL, 0x21uLL, stderr);
exit(-1);
}
goto LABEL_4;
}
v11 = fd;
result = (char *)lseek(fd, 0LL, 1);
v12 = (int)result;
if ( (_DWORD)result != -1 )
{
v13 = bytes_read;
if ( bytes_read >= (int)result )
{
LABEL_19:
begin_reached = 1;
return result;
}
if ( bytes_read + 5119 >= (int)result )
{
if ( lseek(v11, 0LL, 0) != -1 )
{
page = &v2[v12 - v13];
goto LABEL_25;
}
}
else if ( lseek(v11, -5120 - bytes_read, 1) != -1 )
{
page = v2 + 5120;
LABEL_25:
v14 = read(v11, v2, 0x2800uLL);
bytes_read = v14;
if ( v14 == -1 )
{
LABEL_31:
endwin();
fwrite("\nError reading file in back_lines().\n", 1uLL, 0x25uLL, stderr);
exit(-1);
}
*((_BYTE *)buf + v14) = 0;
v3 = (char *)page;
goto LABEL_3;
}
}
LABEL_29:
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
LABEL_4:
if ( a1 > 0 )
{
v5 = 0;
while ( 1 )
{
result = v1;
if ( buf == v1 )
{
v7 = fd;
result = (char *)lseek(fd, 0LL, 1);
v8 = (int)result;
if ( (_DWORD)result == -1 )
goto LABEL_29;
v9 = bytes_read;
if ( bytes_read >= (int)result )
goto LABEL_19;
if ( bytes_read + 5119 < (int)result )
{
if ( lseek(v7, -5120 - bytes_read, 1) == -1 )
goto LABEL_29;
page = v1 + 5120;
}
else
{
if ( lseek(v7, 0LL, 0) == -1 )
goto LABEL_29;
page = &v1[v8 - v9];
}
v10 = read(v7, v1, 0x2800uLL);
bytes_read = v10;
if ( v10 == -1 )
goto LABEL_31;
*((_BYTE *)buf + v10) = 0;
result = (char *)page;
}
v1 = result - 1;
v4 = *(result - 1) == 10;
page = result - 1;
if ( v4 && a1 == ++v5 )
goto LABEL_18;
}
}
result = v1 + 1;
LABEL_18:
page = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(int a1)
{
char *v1; // rbp
char *v2; // r12
char *v3; // rax
bool v4; // zf
int v5; // er13
char *result; // rax
int v7; // er14
int v8; // ebx
__int64 v9; // r15
int v10; // eax
int v11; // er13
int v12; // ebx
__int64 v13; // rbp
int v14; // eax

begin_reached = 0;
v1 = (char *)page;
if ( !end_reached )
{
v2 = (char *)buf;
v3 = (char *)page;
if ( buf != page )
{
LABEL_3:
v1 = v3 - 1;
v4 = *(v3 - 1) == 10;
page = v3 - 1;
if ( !v4 )
{
endwin();
fwrite("\nInternal error in back_lines().\n", 1uLL, 0x21uLL, stderr);
exit(-1);
}
goto LABEL_4;
}
v11 = fd;
result = (char *)lseek(fd, 0LL, 1);
v12 = (int)result;
if ( (_DWORD)result != -1 )
{
v13 = bytes_read;
if ( bytes_read >= (int)result )
{
LABEL_19:
begin_reached = 1;
return result;
}
if ( bytes_read + 5119 >= (int)result )
{
if ( lseek(v11, 0LL, 0) != -1 )
{
page = &v2[v12 - v13];
goto LABEL_25;
}
}
else if ( lseek(v11, -5120 - bytes_read, 1) != -1 )
{
page = v2 + 5120;
LABEL_25:
v14 = read(v11, v2, 0x2800uLL);
bytes_read = v14;
if ( v14 == -1 )
{
LABEL_31:
endwin();
fwrite("\nError reading file in back_lines().\n", 1uLL, 0x25uLL, stderr);
exit(-1);
}
*((_BYTE *)buf + v14) = 0;
v3 = (char *)page;
goto LABEL_3;
}
}
LABEL_29:
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
LABEL_4:
if ( a1 > 0 )
{
v5 = 0;
while ( 1 )
{
result = v1;
if ( buf == v1 )
{
v7 = fd;
result = (char *)lseek(fd, 0LL, 1);
v8 = (int)result;
if ( (_DWORD)result == -1 )
goto LABEL_29;
v9 = bytes_read;
if ( bytes_read >= (int)result )
goto LABEL_19;
if ( bytes_read + 5119 < (int)result )
{
if ( lseek(v7, -5120 - bytes_read, 1) == -1 )
goto LABEL_29;
page = v1 + 5120;
}
else
{
if ( lseek(v7, 0LL, 0) == -1 )
goto LABEL_29;
page = &v1[v8 - v9];
}
v10 = read(v7, v1, 0x2800uLL);
bytes_read = v10;
if ( v10 == -1 )
goto LABEL_31;
*((_BYTE *)buf + v10) = 0;
result = (char *)page;
}
v1 = result - 1;
v4 = *(result - 1) == 10;
page = result - 1;
if ( v4 && a1 == ++v5 )
goto LABEL_18;
}
}
result = v1 + 1;
LABEL_18:
page = result;
return result;
}

original_code:
static void
back_lines (int n)
{
    int i, fpos;
    begin_reached = 0;
    if (!end_reached) {
 if (page == buf) {
     if ((fpos = lseek (fd, 0, 1)) == -1) {
  endwin ();
  fprintf (stderr, "\nError moving file pointer in "
    "back_lines().\n");
  exit (-1);
     }
     if (fpos > bytes_read) {
  if (fpos < (10*1024) / 2 + bytes_read) {
      if (lseek (fd, 0, 0) == -1) {
   endwin ();
   fprintf (stderr, "\nError moving file pointer in "
     "back_lines().\n");
   exit (-1);
      }
      page = buf + fpos - bytes_read;
  } else {
      if (lseek (fd, -((10*1024) / 2 + bytes_read), 1)
   == -1) {
   endwin ();
   fprintf (stderr, "\nError moving file pointer "
     "in back_lines().\n");
   exit (-1);
      }
      page = buf + (10*1024) / 2;
  }
  if ((bytes_read = read (fd, buf, (10*1024))) == -1) {
      endwin ();
      fprintf (stderr, "\nError reading file in back_lines().\n");
      exit (-1);
  }
  buf[bytes_read] = '\0';
     } else {
  begin_reached = 1;
  return;
     }
 }
 if (*(--page) != '\n') {
     endwin ();
     fprintf (stderr, "\nInternal error in back_lines().\n");
     exit (-1);
 }
    }
    for (i = 0; i < n; i++)
 do {
     if (page == buf) {
  if ((fpos = lseek (fd, 0, 1)) == -1) {
      endwin ();
      fprintf (stderr,
     "\nError moving file pointer in back_lines().\n");
      exit (-1);
  }
  if (fpos > bytes_read) {
      if (fpos < (10*1024) / 2 + bytes_read) {
   if (lseek (fd, 0, 0) == -1) {
       endwin ();
       fprintf (stderr, "\nError moving file pointer "
         "in back_lines().\n");
       exit (-1);
   }
   page = buf + fpos - bytes_read;
      } else {
   if (lseek (fd, -((10*1024) / 2 + bytes_read),
       1) == -1) {
       endwin ();
       fprintf (stderr, "\nError moving file pointer"
         " in back_lines().\n");
       exit (-1);
   }
   page = buf + (10*1024) / 2;
      }
      if ((bytes_read = read (fd, buf, (10*1024))) == -1) {
   endwin ();
   fprintf (stderr, "\nError reading file in "
     "back_lines().\n");
   exit (-1);
      }
      buf[bytes_read] = '\0';
  } else {
      begin_reached = 1;
      return;
  }
     }
 } while (*(--page) != '\n');
    page++;
}

canonical_original_code:
static void back_lines(int n)
{
    int i; int fpos;
    begin_reached = 0;
    if (!end_reached) {
 if (page == buf) {
     if ((fpos = lseek (fd, 0, 1)) == -1) {
  endwin ();
  fprintf (stderr, "\nError moving file pointer in "
    "back_lines().\n");
  exit (-1);
     }
     if (fpos > bytes_read) {
  if (fpos < (10*1024) / 2 + bytes_read) {
      if (lseek (fd, 0, 0) == -1) {
   endwin ();
   fprintf (stderr, "\nError moving file pointer in "
     "back_lines().\n");
   exit (-1);
      }
      page = buf + fpos - bytes_read;
  } else {
      if (lseek (fd, -((10*1024) / 2 + bytes_read), 1)
   == -1) {
   endwin ();
   fprintf (stderr, "\nError moving file pointer "
     "in back_lines().\n");
   exit (-1);
      }
      page = buf + (10*1024) / 2;
  }
  if ((bytes_read = read (fd, buf, (10*1024))) == -1) {
      endwin ();
      fprintf (stderr, "\nError reading file in back_lines().\n");
      exit (-1);
  }
  buf[bytes_read] = '\0';
     } else {
  begin_reached = 1;
  return;
     }
 }
 if (*(--page) != '\n') {
     endwin ();
     fprintf (stderr, "\nInternal error in back_lines().\n");
     exit (-1);
 }
    }
    for (i = 0; i < n; i++)
 do {
     if (page == buf) {
  if ((fpos = lseek (fd, 0, 1)) == -1) {
      endwin ();
      fprintf (stderr,
     "\nError moving file pointer in back_lines().\n");
      exit (-1);
  }
  if (fpos > bytes_read) {
      if (fpos < (10*1024) / 2 + bytes_read) {
   if (lseek (fd, 0, 0) == -1) {
       endwin ();
       fprintf (stderr, "\nError moving file pointer "
         "in back_lines().\n");
       exit (-1);
   }
   page = buf + fpos - bytes_read;
      } else {
   if (lseek (fd, -((10*1024) / 2 + bytes_read),
       1) == -1) {
       endwin ();
       fprintf (stderr, "\nError moving file pointer"
         " in back_lines().\n");
       exit (-1);
   }
   page = buf + (10*1024) / 2;
      }
      if ((bytes_read = read (fd, buf, (10*1024))) == -1) {
   endwin ();
   fprintf (stderr, "\nError reading file in "
     "back_lines().\n");
   exit (-1);
      }
      buf[bytes_read] = '\0';
  } else {
      begin_reached = 1;
      return;
  }
     }
 } while (*(--page) != '\n');
    page++;
}

variable_types: n int


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

v1 = (unsigned __int16)(a1 + WORD2(a1)) + (((unsigned int)a1 + HIDWORD(a1)) >> 16);
return (unsigned __int16)(v1 + WORD1(v1)) + (((unsigned __int16)v1 + (v1 >> 16)) >> 16);
}

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

v1 = (unsigned __int16)(a1 + WORD2(a1)) + (((unsigned int)a1 + HIDWORD(a1)) >> 16);
return (unsigned __int16)(v1 + WORD1(v1)) + (((unsigned __int16)v1 + (v1 >> 16)) >> 16);
}

original_code:
static inline unsigned short from64to16(unsigned long x)
{
 x = (x & 0xffffffff) + (x >> 32);
 x = (x & 0xffff) + (x >> 16);
 x = (x & 0xffff) + (x >> 16);
 x = (x & 0xffff) + (x >> 16);
 return x;
}

variable_types:
x
unsigned long

return_type: unsigned short


original_code:
static inline unsigned long do_csum(unsigned char * buff, int len)
{
 int odd, count;
 unsigned long result = 0;
 if (len <= 0)
  goto out;
 odd = 1 & (unsigned long) buff;
 if (odd) {
  result = *buff << 8;
  len--;
  buff++;
 }
 count = len >> 1;
 if (count) {
  if (2 & (unsigned long) buff) {
   result += *(unsigned short *) buff;
   count--;
   len -= 2;
   buff += 2;
  }
  count >>= 1;
  if (count) {
   if (4 & (unsigned long) buff) {
    result += *(unsigned int *) buff;
    count--;
    len -= 4;
    buff += 4;
   }
   count >>= 1;
   if (count) {
    unsigned long carry = 0;
    do {
     unsigned long w = *(unsigned long *) buff;
     count--;
     buff += 8;
     result += carry;
     result += w;
     carry = (w > result);
    } while (count);
    result += carry;
    result = (result & 0xffffffff) + (result >> 32);
   }
   if (len & 4) {
    result += *(unsigned int *) buff;
    buff += 4;
   }
  }
  if (len & 2) {
   result += *(unsigned short *) buff;
   buff += 2;
  }
 }
 if (len & 1)
  result += *buff;
 result = from64to16(result);
 if (odd)
  result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
out:
 return result;
}

canonical_original_code:
static inline unsigned long do_csum(unsigned char *buff, int len)
{
 int odd; int count;
 unsigned long result = 0;
 if (len <= 0)
  goto out;
 odd = 1 & (unsigned long) buff;
 if (odd) {
  result = *buff << 8;
  len--;
  buff++;
 }
 count = len >> 1;
 if (count) {
  if (2 & (unsigned long) buff) {
   result += *(unsigned short *) buff;
   count--;
   len -= 2;
   buff += 2;
  }
  count >>= 1;
  if (count) {
   if (4 & (unsigned long) buff) {
    result += *(unsigned int *) buff;
    count--;
    len -= 4;
    buff += 4;
   }
   count >>= 1;
   if (count) {
    unsigned long carry = 0;
    do {
     unsigned long w = *(unsigned long *) buff;
     count--;
     buff += 8;
     result += carry;
     result += w;
     carry = (w > result);
    } while (count);
    result += carry;
    result = (result & 0xffffffff) + (result >> 32);
   }
   if (len & 4) {
    result += *(unsigned int *) buff;
    buff += 4;
   }
  }
  if (len & 2) {
   result += *(unsigned short *) buff;
   buff += 2;
  }
 }
 if (len & 1)
  result += *buff;
 result = from64to16(result);
 if (odd)
  result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
out:
 return result;
}

variable_types:
buff
unsigned char *

variable_types: len int

variable_types: odd int

variable_types: count int

variable_types:
result
unsigned long

variable_types:
carry
unsigned long

variable_types:
w
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall csum_tcpudp_magic(__int64 a1, __int64 a2, uint16_t a3, unsigned __int16 a4, unsigned int a5)
{
__int64 v5; // r12
int v7; // eax

v5 = a5 + a2;
LOWORD(v7) = ntohs(a3);
return (unsigned int)~from64to16(((__int64)v7 << 16) + a1 + v5 + ((unsigned __int64)a4 << 8));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, uint16_t a3, unsigned __int16 a4, unsigned int a5)
{
__int64 v5; // r12
int v7; // eax

v5 = a5 + a2;
LOWORD(v7) = ntohs(a3);
return (unsigned int)~func0(((__int64)v7 << 16) + a1 + v5 + ((unsigned __int64)a4 << 8));
}

original_code:
unsigned short int csum_tcpudp_magic(unsigned long saddr,
       unsigned long daddr,
       unsigned short len,
       unsigned short proto,
       unsigned int sum)
{
 return ~from64to16(saddr + daddr + sum +
  ((unsigned long) ntohs(len) << 16) +
  ((unsigned long) proto << 8));
}

canonical_original_code:
unsigned short csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len, unsigned short proto, unsigned int sum)
{
 return ~from64to16(saddr + daddr + sum +
  ((unsigned long) ntohs(len) << 16) +
  ((unsigned long) proto << 8));
}

variable_types:
saddr
unsigned long

variable_types:
daddr
unsigned long

variable_types:
len
unsigned short

variable_types:
proto
unsigned short

variable_types:
sum
unsigned int


decompiled_code:
__int64 __fastcall ip_fast_csum(unsigned __int8 *a1, int a2)
{
return (unsigned int)~do_csum(a1, 4 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1, int a2)
{
return (unsigned int)~func1(a1, 4 * a2);
}

original_code:
unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl)
{
 return ~do_csum(iph,ihl*4);
}

canonical_original_code:
unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl)
{
 return ~do_csum(iph,ihl*4);
}

variable_types:
iph
unsigned char *

variable_types:
ihl
unsigned int


decompiled_code:
unsigned __int64 __fastcall csum_partial(unsigned __int8 *a1, int a2)
{
unsigned __int64 v2; // rax
unsigned int v3; // er10

v2 = do_csum(a1, a2);
return (unsigned int)v2 + v3 + ((v2 + v3) >> 32);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(unsigned __int8 *a1, int a2)
{
unsigned __int64 v2; // rax
unsigned int v3; // er10

v2 = func1(a1, a2);
return (unsigned int)v2 + v3 + ((v2 + v3) >> 32);
}

original_code:
unsigned int csum_partial(unsigned char * buff, int len, unsigned int sum)
{
 unsigned long result = do_csum(buff, len);
 result += sum;
 result = (result & 0xffffffff) + (result >> 32);
 return result;
}

canonical_original_code:
unsigned int csum_partial(unsigned char *buff, int len, unsigned int sum)
{
 unsigned long result = do_csum(buff, len);
 result += sum;
 result = (result & 0xffffffff) + (result >> 32);
 return result;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall ip_compute_csum(unsigned __int8 *a1, int a2)
{
unsigned __int64 v2; // rax

v2 = do_csum(a1, a2);
return (unsigned int)~from64to16(v2);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1, int a2)
{
unsigned __int64 v2; // rax

v2 = func1(a1, a2);
return (unsigned int)~func0(v2);
}

original_code:
unsigned short ip_compute_csum(unsigned char * buff, int len)
{
 return ~from64to16(do_csum(buff,len));
}

canonical_original_code:
unsigned short ip_compute_csum(unsigned char *buff, int len)
{
 return ~from64to16(do_csum(buff,len));
}


decompiled_code:
void __noreturn sys_iopl()
{
panic("sys_iopl");
}

canonical_decompiled_code:
void __noreturn func2()
{
func1("sys_iopl");
}

original_code: void sys_iopl(void) { _panic("sys_iopl"); }

canonical_original_code: void sys_iopl() { _panic("sys_iopl"); }


decompiled_code:
void __noreturn sys_vm86()
{
panic("sys_vm86");
}

canonical_decompiled_code:
void __noreturn func3()
{
func1("sys_vm86");
}

original_code: void sys_vm86(void) { _panic("sys_vm86"); }

canonical_original_code: void sys_vm86() { _panic("sys_vm86"); }


decompiled_code:
void __noreturn sys_modify_ldt()
{
panic("sys_modify_ldt");
}

canonical_decompiled_code:
void __noreturn func4()
{
func1("sys_modify_ldt");
}

original_code: void sys_modify_ldt(void) { _panic("sys_modify_ldt"); }

canonical_original_code: void sys_modify_ldt() { _panic("sys_modify_ldt"); }


decompiled_code:
void __noreturn sys_ipc()
{
panic("sys_ipc");
}

canonical_decompiled_code:
void __noreturn func5()
{
func1("sys_ipc");
}

original_code: void sys_ipc(void) {_panic("sys_ipc"); }

canonical_original_code: void sys_ipc() {_panic("sys_ipc"); }


decompiled_code:
void __noreturn sys_newselect()
{
panic("sys_newselect");
}

canonical_decompiled_code:
void __noreturn func6()
{
func1("sys_newselect");
}

original_code: void sys_newselect(void) {_panic("sys_newselect"); }

canonical_original_code: void sys_newselect() {_panic("sys_newselect"); }


decompiled_code:
__int64 saved_command_line()
{
return panic("saved_command_line");
}

canonical_decompiled_code:
__int64 func8()
{
return func1("saved_command_line");
}

original_code:
void
saved_command_line(void)
{
 panic("saved_command_line");
}

canonical_original_code:
void saved_command_line()
{
 panic("saved_command_line");
}


decompiled_code:
__int64 KSTK_EIP()
{
return panic("KSTK_EIP");
}

canonical_decompiled_code:
__int64 func9()
{
return func1("KSTK_EIP");
}

original_code:
void
KSTK_EIP(void)
{
 panic("KSTK_EIP");
}

canonical_original_code:
void KSTK_EIP()
{
 panic("KSTK_EIP");
}


decompiled_code:
__int64 KSTK_ESP()
{
return panic("KSTK_ESP");
}

canonical_decompiled_code:
__int64 func10()
{
return func1("KSTK_ESP");
}

original_code:
void
KSTK_ESP(void)
{
 panic("KSTK_ESP");
}

canonical_original_code:
void KSTK_ESP()
{
 panic("KSTK_ESP");
}


decompiled_code:
__int64 scsi_register_module()
{
return panic("scsi_register_module");
}

canonical_decompiled_code:
__int64 func11()
{
return func1("scsi_register_module");
}

original_code:
void
scsi_register_module(void)
{
 panic("scsi_register_module");
}

canonical_original_code:
void scsi_register_module()
{
 panic("scsi_register_module");
}


decompiled_code:
__int64 scsi_unregister_module()
{
return panic("scsi_unregister_module");
}

canonical_decompiled_code:
__int64 func12()
{
return func1("scsi_unregister_module");
}

original_code:
void
scsi_unregister_module(void)
{
 panic("scsi_unregister_module");
}

canonical_original_code:
void scsi_unregister_module()
{
 panic("scsi_unregister_module");
}


toOpcodeName

repo: shaybarak/MaabaGdalia

decompiled_code:
void *__fastcall toOpcodeName(unsigned int a1)
{
void *result; // rax

switch ( a1 )
{
case 0u:
result = &unk_402008;
break;
case 1u:
result = &unk_40203A;
break;
case 2u:
result = &unk_40200C;
break;
case 3u:
result = &unk_402010;
break;
case 4u:
result = &unk_402014;
break;
case 5u:
result = &unk_402019;
break;
case 6u:
result = &unk_402018;
break;
case 7u:
result = &unk_40201C;
break;
case 8u:
result = &unk_402020;
break;
case 9u:
result = &unk_402023;
break;
case 0x10u:
result = &unk_402026;
break;
case 0x11u:
result = &unk_40202A;
break;
case 0x12u:
result = &unk_40202E;
break;
case 0x13u:
result = &unk_402032;
break;
case 0x14u:
result = &unk_402036;
break;
case 0x18u:
result = &unk_402004;
break;
default:
printf("Illegal opcode %d!\n", a1);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(unsigned int a1)
{
void *result; // rax

switch ( a1 )
{
case 0u:
result = &unk_402008;
break;
case 1u:
result = &unk_40203A;
break;
case 2u:
result = &unk_40200C;
break;
case 3u:
result = &unk_402010;
break;
case 4u:
result = &unk_402014;
break;
case 5u:
result = &unk_402019;
break;
case 6u:
result = &unk_402018;
break;
case 7u:
result = &unk_40201C;
break;
case 8u:
result = &unk_402020;
break;
case 9u:
result = &unk_402023;
break;
case 0x10u:
result = &unk_402026;
break;
case 0x11u:
result = &unk_40202A;
break;
case 0x12u:
result = &unk_40202E;
break;
case 0x13u:
result = &unk_402032;
break;
case 0x14u:
result = &unk_402036;
break;
case 0x18u:
result = &unk_402004;
break;
default:
printf("Illegal opcode %d!\n", a1);
exit(1);
}
return result;
}

original_code:
char* toOpcodeName(Opcode opcode) {
   switch (opcode) {
   case ADD: return "ADD";
   case SUB: return "SUB";
   case LSF: return "LSF";
   case RSF: return "RSF";
   case AND: return "AND";
   case OR: return "OR";
   case XOR: return "XOR";
   case LHI: return "LHI";
   case LD: return "LD";
   case ST: return "ST";
   case JLT: return "JLT";
   case JLE: return "JLE";
   case JEQ: return "JEQ";
   case JNE: return "JNE";
   case JIN: return "JIN";
   case HLT: return "HLT";
   default:
 printf("Illegal opcode %d!\n", opcode);
 exit(1);
   }
   return ((void *)0);
}

canonical_original_code:
char *toOpcodeName(enum Opcode opcode) {
   switch (opcode) {
   case ADD: return "ADD";
   case SUB: return "SUB";
   case LSF: return "LSF";
   case RSF: return "RSF";
   case AND: return "AND";
   case OR: return "OR";
   case XOR: return "XOR";
   case LHI: return "LHI";
   case LD: return "LD";
   case ST: return "ST";
   case JLT: return "JLT";
   case JLE: return "JLE";
   case JEQ: return "JEQ";
   case JNE: return "JNE";
   case JIN: return "JIN";
   case HLT: return "HLT";
   default:
 printf("Illegal opcode %d!\n", opcode);
 exit(1);
   }
   return ((void *)0);
}

variable_types: enum Opcode { ADD=0, SUB=1, LSF=2, RSF=3, AND=4, OR=5, XOR=6, LHI=7, LD=8, ST=9, JLT=16, JLE=17, JEQ=18, JNE=19, JIN=20, HLT=24 }


fetch

original_code:
Instruction fetch(unsigned int inst) {
 Instruction out;
 out.opcode = (Opcode)(unsigned int)((inst >> 25) & 0x1F);
 out.dst = (inst >> 22) & 0x7;
 out.src0 = (inst >> 19) & 0x7;
 out.src1 = (inst >> 16) & 0x7;
 out.immediate = (inst) & 0xffff;
 return out;
}

canonical_original_code:
struct Instruction fetch(unsigned int inst) {
 struct Instruction out;
 out.opcode = (enum Opcode)(unsigned int)((inst >> 25) & 0x1F);
 out.dst = (inst >> 22) & 0x7;
 out.src0 = (inst >> 19) & 0x7;
 out.src1 = (inst >> 16) & 0x7;
 out.immediate = (inst) & 0xffff;
 return out;
}

variable_types:
inst
unsigned int

variable_types: struct Instruction { int unused; enum Opcode { ADD=0, SUB=1, LSF=2, RSF=3, AND=4, OR=5, XOR=6, LHI=7, LD=8, ST=9, JLT=16, JLE=17, JEQ=18, JNE=19, JIN=20, HLT=24 } opcode; unsigned int dst; unsigned int src0; unsigned int src1; int immediate; int val0; int val1; }

user_defined_types: struct Instruction { int unused; enum Opcode opcode; unsigned int dst; unsigned int src0; unsigned int src1; int immediate; int val0; int val1; }


decode

original_code:
void decode(Instruction* inst, int* regs) {
 inst->val0 = (inst->src0 == 1 || inst->opcode == LHI) ? inst->immediate : regs[inst->src0];
 inst->val1 = (inst->src1 == 1) ? inst->immediate : regs[inst->src1];
}

canonical_original_code:
void decode(struct Instruction *inst, int *regs) {
 inst->val0 = (inst->src0 == 1 || inst->opcode == LHI) ? inst->immediate : regs[inst->src0];
 inst->val1 = (inst->src1 == 1) ? inst->immediate : regs[inst->src1];
}

variable_types: struct Instruction { int unused; enum Opcode { ADD=0, SUB=1, LSF=2, RSF=3, AND=4, OR=5, XOR=6, LHI=7, LD=8, ST=9, JLT=16, JLE=17, JEQ=18, JNE=19, JIN=20, HLT=24 } opcode; unsigned int dst; unsigned int src0; unsigned int src1; int immediate; int val0; int val1; } *

variable_types:
regs
int *


main

repo: shazame/project-euler

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // [rsp+Ch] [rbp-4CCh] BYREF
__int128 v5; // [rsp+10h] [rbp-4C8h] BYREF
char v6[1184]; // [rsp+20h] [rbp-4B8h] BYREF
__int16 v7; // [rsp+4C0h] [rbp-18h]

memset(v6, 0, sizeof(v6));
v5 = 0LL;
v4 = 0;
v7 = 0;
genword(&v4, 0LL, 3LL, 0LL, &v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // [rsp+Ch] [rbp-4CCh] BYREF
__int128 v5; // [rsp+10h] [rbp-4C8h] BYREF
char v6[1184]; // [rsp+20h] [rbp-4B8h] BYREF
__int16 v7; // [rsp+4C0h] [rbp-18h]

memset(v6, 0, sizeof(v6));
v5 = 0LL;
v4 = 0;
v7 = 0;
func9(&v4, 0LL, 3LL, 0LL, &v5);
return 0;
}

original_code:
int main(void) {
 char buffer[4] = {0, 0, 0, 0}, result[1201 +1] = "";
 genword(buffer, 0, 3, 0, result);
 return 0;
}

canonical_original_code:
int main() {
 char buffer[4] = {0, 0, 0, 0}; char result[-1] = "";
 genword(buffer, 0, 3, 0, result);
 return 0;
}

variable_types:
buffer
char [4]

variable_types:
result
char [-1]


XOR

decompiled_code:
__int64 __fastcall XOR(int a1, unsigned int a2)
{
return a1 ^ a2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, unsigned int a2)
{
return a1 ^ a2;
}

original_code:
char XOR(char c1, char c2) {
 return (c1 ^ c2);
}

return_type: char


decode

original_code:
int decode(char result[1201 +1], const char key[4]) {
 int i = 0;
 for (i = 0; i < 1201; i++) {
  result[i] = XOR(cipher[i], key[i%3]);
  if (i < 1201 - 1) {
   if (result[i] < 8) {
    return 0;
   }
   else {
    switch(result[i]) {
     case '{':
     case '}':
     case '#':
     case '`':
      return 0;
     default:
      break;
    }
   }
  }
 }
 result[1201] = '\0';
 return 1;
}

canonical_original_code:
int decode(char result[-1], char key[4]) {
 int i = 0;
 for (i = 0; i < 1201; i++) {
  result[i] = XOR(cipher[i], key[i%3]);
  if (i < 1201 - 1) {
   if (result[i] < 8) {
    return 0;
   }
   else {
    switch(result[i]) {
     case '{':
     case '}':
     case '#':
     case '`':
      return 0;
     default:
      break;
    }
   }
  }
 }
 result[1201] = '\0';
 return 1;
}

variable_types:
key
char [4]

variable_types: i int


genword

decompiled_code:
int __fastcall genword(char *a1, int a2, int a3, unsigned int a4, const char *a5)
{
__int64 i; // rbp
char v7; // r13
char v8; // r12
char v9; // r14
int result; // eax
unsigned int v11; // er13
char *v12; // rbp
char v13; // al

if ( a3 == 1 )
{
if ( a4 > 0x19 )
__assert_fail("curcar < NBCAR && curcar >= 0", "problem059.c", 0x40u, "genword");
for ( i = (int)a4; ; ++i )
{
a1[a2] = C[i];
v7 = *a1;
v8 = a1[1];
v9 = a1[2];
result = decode((__int64)a5, a1);
if ( result == 1 )
result = printf("%s:%s\n\n", a1, a5);
if ( *a1 != v7 || a1[1] != v8 || a1[2] != v9 )
__assert_fail("tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]", "problem059.c", 0x47u, "genword");
if ( (_DWORD)i == 25 )
break;
}
}
else
{
v11 = a3 - 1;
v12 = C;
do
{
v13 = *v12++;
a1[a2] = v13;
result = genword(a1, (unsigned int)(a2 + 1), v11, 0LL, a5);
}
while ( v12 != &_bss_start );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(char *a1, int a2, int a3, unsigned int a4, const char *a5)
{
__int64 i; // rbp
char v7; // r13
char v8; // r12
char v9; // r14
int result; // eax
unsigned int v11; // er13
char *v12; // rbp
char v13; // al

if ( a3 == 1 )
{
if ( a4 > 0x19 )
__assert_fail("curcar < NBCAR && curcar >= 0", "problem059.c", 0x40u, "genword");
for ( i = (int)a4; ; ++i )
{
a1[a2] = C[i];
v7 = *a1;
v8 = a1[1];
v9 = a1[2];
result = func8((__int64)a5, a1);
if ( result == 1 )
result = printf("%s:%s\n\n", a1, a5);
if ( *a1 != v7 || a1[1] != v8 || a1[2] != v9 )
__assert_fail("tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]", "problem059.c", 0x47u, "genword");
if ( (_DWORD)i == 25 )
break;
}
}
else
{
v11 = a3 - 1;
v12 = C;
do
{
v13 = *v12++;
a1[a2] = v13;
result = func9(a1, (unsigned int)(a2 + 1), v11, 0LL, a5);
}
while ( v12 != &_bss_start );
}
return result;
}

original_code:
void genword(char * buffer, int begin, int size, int curcar, char result[1201 +1]) {
 int i = 0;
 char tmp1, tmp2, tmp3;
 if (size == 1) {
  ((void) sizeof ((curcar < 26 && curcar >= 0) ? 1 : 0), __extension__ ({ if (curcar < 26 && curcar >= 0) ; else __assert_fail ("curcar < NBCAR && curcar >= 0", "problem059.c", 64, __extension__ __PRETTY_FUNCTION__); }));
  buffer[begin] = C[curcar];
  tmp1 = buffer[0], tmp2 = buffer[1], tmp3 = buffer[2];
  if (decode(result, buffer) == 1) {
   printf("%s:%s\n\n", buffer, result);
  }
  ((void) sizeof ((tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]) ? 1 : 0), __extension__ ({ if (tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]) ; else __assert_fail ("tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]", "problem059.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  if (curcar >= 26 -1) {
   return;
  }
  genword(buffer, begin, size, curcar+1, result);
 }
 else {
  for (i = 0; i < 26; i++) {
   buffer[begin] = C[i];
   genword(buffer, begin+1, size-1, 0, result);
  }
 }
}

canonical_original_code:
void genword(char *buffer, int begin, int size, int curcar, char result[-1]) {
 int i = 0;
 char tmp1; char tmp2; char tmp3;
 if (size == 1) {
  ((void) sizeof ((curcar < 26 && curcar >= 0) ? 1 : 0), __extension__ ({ if (curcar < 26 && curcar >= 0) ; else __assert_fail ("curcar < NBCAR && curcar >= 0", "problem059.c", 64, __extension__ __PRETTY_FUNCTION__); }));
  buffer[begin] = C[curcar];
  tmp1 = buffer[0], tmp2 = buffer[1], tmp3 = buffer[2];
  if (decode(result, buffer) == 1) {
   printf("%s:%s\n\n", buffer, result);
  }
  ((void) sizeof ((tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]) ? 1 : 0), __extension__ ({ if (tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]) ; else __assert_fail ("tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]", "problem059.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  if (curcar >= 26 -1) {
   return;
  }
  genword(buffer, begin, size, curcar+1, result);
 }
 else {
  for (i = 0; i < 26; i++) {
   buffer[begin] = C[i];
   genword(buffer, begin+1, size-1, 0, result);
  }
 }
}

variable_types:
buffer
char *

variable_types: begin int

variable_types: size int

variable_types: curcar int


main

repo: shcabin/memory-leak-detector

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp

xmalloc(256LL, "test.c", 10LL);
v3 = xmalloc(128LL, "test.c", 11LL);
xstrdup("0123456789abcdef", "test.c", 12LL);
xcalloc(1LL, 32LL, "test.c", 13LL);
xfree(v3);
return report_mem_leak();
}

original_code:
void main()
{
 void *ptr;
 ptr=xmalloc(256, "test.c", 10);
 ptr=xmalloc(128, "test.c", 11);
 xstrdup("0123456789abcdef", "test.c", 12);
 xcalloc(1, 32, "test.c", 13);
 xfree(ptr);
 report_mem_leak();
}

variable_types:
ptr
void *


repo: sheepdog/sheepdog

original_code:
void ec_init_tables(int k, int rows, unsigned char *a, unsigned char *g_tbls)
{
 int i, j;
 for (i = 0; i < rows; i++) {
  for (j = 0; j < k; j++) {
   gf_vect_mul_init(*a++, g_tbls);
   g_tbls += 32;
  }
 }
}

canonical_original_code:
void ec_init_tables(int k, int rows, unsigned char *a, unsigned char *g_tbls)
{
 int i; int j;
 for (i = 0; i < rows; i++) {
  for (j = 0; j < k; j++) {
   gf_vect_mul_init(*a++, g_tbls);
   g_tbls += 32;
  }
 }
}

variable_types: k int

variable_types: rows int

variable_types:
a
unsigned char *

variable_types: j int


decompiled_code:
__int64 __fastcall ec_encode_data_sse(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, _QWORD *a6)
{
_QWORD *v7; // r12
__int64 v8; // r13
__int64 v9; // rbx
_QWORD *v10; // r8
__int64 v11; // rdx
__int64 result; // rax
_QWORD *v13; // [rsp+0h] [rbp-58h]
__int64 v14; // [rsp+8h] [rbp-50h]
__int64 v15; // [rsp+10h] [rbp-48h]
unsigned int v16; // [rsp+18h] [rbp-40h]
int v17; // [rsp+1Ch] [rbp-3Ch]

v7 = a6;
v14 = a4;
if ( (int)a1 <= 15 )
return ec_encode_data_base(a1, a2, a3, a4);
if ( (int)a3 <= 3 )
{
v13 = a6;
}
else
{
v8 = a4;
v17 = a3 - 4;
v16 = (unsigned int)(a3 - 4) >> 2;
v9 = (int)((_DWORD)a2 << 7);
v15 = v16 + 1;
v13 = &a6[4 * v15];
do
{
v10 = v7;
v11 = v8;
v8 += v9;
v7 += 4;
gf_4vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v11, a5, v10);
}
while ( v7 != v13 );
v14 += v15 * v9;
result = -v16;
LODWORD(a3) = v17 - 4 * v16;
}
switch ( (_DWORD)a3 )
{
case 2:
return gf_2vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v14, a5, v13);
case 3:
return gf_3vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v14, a5, v13);
case 1:
result = gf_vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v14, a5, *v13);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, _QWORD *a6)
{
_QWORD *v7; // r12
__int64 v8; // r13
__int64 v9; // rbx
_QWORD *v10; // r8
__int64 v11; // rdx
__int64 result; // rax
_QWORD *v13; // [rsp+0h] [rbp-58h]
__int64 v14; // [rsp+8h] [rbp-50h]
__int64 v15; // [rsp+10h] [rbp-48h]
unsigned int v16; // [rsp+18h] [rbp-40h]
int v17; // [rsp+1Ch] [rbp-3Ch]

v7 = a6;
v14 = a4;
if ( (int)a1 <= 15 )
return ec_encode_data_base(a1, a2, a3, a4);
if ( (int)a3 <= 3 )
{
v13 = a6;
}
else
{
v8 = a4;
v17 = a3 - 4;
v16 = (unsigned int)(a3 - 4) >> 2;
v9 = (int)((_DWORD)a2 << 7);
v15 = v16 + 1;
v13 = &a6[4 * v15];
do
{
v10 = v7;
v11 = v8;
v8 += v9;
v7 += 4;
gf_4vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v11, a5, v10);
}
while ( v7 != v13 );
v14 += v15 * v9;
result = -v16;
LODWORD(a3) = v17 - 4 * v16;
}
switch ( (_DWORD)a3 )
{
case 2:
return gf_2vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v14, a5, v13);
case 3:
return gf_3vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v14, a5, v13);
case 1:
result = gf_vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v14, a5, *v13);
break;
}
return result;
}

original_code:
void ec_encode_data_sse(int len, int k, int rows, unsigned char *g_tbls, unsigned char **data,
   unsigned char **coding)
{
 if (len < 16) {
  ec_encode_data_base(len, k, rows, g_tbls, data, coding);
  return;
 }
 while (rows >= 4) {
  gf_4vect_dot_prod_sse(len, k, g_tbls, data, coding);
  g_tbls += 4 * k * 32;
  coding += 4;
  rows -= 4;
 }
 switch (rows) {
 case 3:
  gf_3vect_dot_prod_sse(len, k, g_tbls, data, coding);
  break;
 case 2:
  gf_2vect_dot_prod_sse(len, k, g_tbls, data, coding);
  break;
 case 1:
  gf_vect_dot_prod_sse(len, k, g_tbls, data, *coding);
  break;
 case 0:
  break;
 }
}

variable_types: len int

variable_types:
data
unsigned char **

variable_types:
coding
unsigned char **


decompiled_code:
__int64 __fastcall ec_encode_data_avx(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, _QWORD *a6)
{
_QWORD *v7; // r12
__int64 v8; // r13
__int64 v9; // rbx
_QWORD *v10; // r8
__int64 v11; // rdx
__int64 result; // rax
_QWORD *v13; // [rsp+0h] [rbp-58h]
__int64 v14; // [rsp+8h] [rbp-50h]
__int64 v15; // [rsp+10h] [rbp-48h]
unsigned int v16; // [rsp+18h] [rbp-40h]
int v17; // [rsp+1Ch] [rbp-3Ch]

v7 = a6;
v14 = a4;
if ( (int)a1 <= 15 )
return ec_encode_data_base(a1, a2, a3, a4);
if ( (int)a3 <= 3 )
{
v13 = a6;
}
else
{
v8 = a4;
v17 = a3 - 4;
v16 = (unsigned int)(a3 - 4) >> 2;
v9 = (int)((_DWORD)a2 << 7);
v15 = v16 + 1;
v13 = &a6[4 * v15];
do
{
v10 = v7;
v11 = v8;
v8 += v9;
v7 += 4;
gf_4vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v11, a5, v10);
}
while ( v7 != v13 );
v14 += v15 * v9;
result = -v16;
LODWORD(a3) = v17 - 4 * v16;
}
switch ( (_DWORD)a3 )
{
case 2:
return gf_2vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v14, a5, v13);
case 3:
return gf_3vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v14, a5, v13);
case 1:
result = gf_vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v14, a5, *v13);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, _QWORD *a6)
{
_QWORD *v7; // r12
__int64 v8; // r13
__int64 v9; // rbx
_QWORD *v10; // r8
__int64 v11; // rdx
__int64 result; // rax
_QWORD *v13; // [rsp+0h] [rbp-58h]
__int64 v14; // [rsp+8h] [rbp-50h]
__int64 v15; // [rsp+10h] [rbp-48h]
unsigned int v16; // [rsp+18h] [rbp-40h]
int v17; // [rsp+1Ch] [rbp-3Ch]

v7 = a6;
v14 = a4;
if ( (int)a1 <= 15 )
return ec_encode_data_base(a1, a2, a3, a4);
if ( (int)a3 <= 3 )
{
v13 = a6;
}
else
{
v8 = a4;
v17 = a3 - 4;
v16 = (unsigned int)(a3 - 4) >> 2;
v9 = (int)((_DWORD)a2 << 7);
v15 = v16 + 1;
v13 = &a6[4 * v15];
do
{
v10 = v7;
v11 = v8;
v8 += v9;
v7 += 4;
gf_4vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v11, a5, v10);
}
while ( v7 != v13 );
v14 += v15 * v9;
result = -v16;
LODWORD(a3) = v17 - 4 * v16;
}
switch ( (_DWORD)a3 )
{
case 2:
return gf_2vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v14, a5, v13);
case 3:
return gf_3vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v14, a5, v13);
case 1:
result = gf_vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v14, a5, *v13);
break;
}
return result;
}

original_code:
void ec_encode_data_avx(int len, int k, int rows, unsigned char *g_tbls, unsigned char **data,
   unsigned char **coding)
{
 if (len < 16) {
  ec_encode_data_base(len, k, rows, g_tbls, data, coding);
  return;
 }
 while (rows >= 4) {
  gf_4vect_dot_prod_avx(len, k, g_tbls, data, coding);
  g_tbls += 4 * k * 32;
  coding += 4;
  rows -= 4;
 }
 switch (rows) {
 case 3:
  gf_3vect_dot_prod_avx(len, k, g_tbls, data, coding);
  break;
 case 2:
  gf_2vect_dot_prod_avx(len, k, g_tbls, data, coding);
  break;
 case 1:
  gf_vect_dot_prod_avx(len, k, g_tbls, data, *coding);
  break;
 case 0:
  break;
 }
}


decompiled_code:
__int64 __fastcall ec_encode_data_avx2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, _QWORD *a6)
{
_QWORD *v7; // r12
__int64 v8; // r13
__int64 v9; // rbx
_QWORD *v10; // r8
__int64 v11; // rdx
__int64 result; // rax
_QWORD *v13; // [rsp+0h] [rbp-58h]
__int64 v14; // [rsp+8h] [rbp-50h]
__int64 v15; // [rsp+10h] [rbp-48h]
unsigned int v16; // [rsp+18h] [rbp-40h]
int v17; // [rsp+1Ch] [rbp-3Ch]

v7 = a6;
v14 = a4;
if ( (int)a1 <= 31 )
return ec_encode_data_base(a1, a2, a3, a4);
if ( (int)a3 <= 3 )
{
v13 = a6;
}
else
{
v8 = a4;
v17 = a3 - 4;
v16 = (unsigned int)(a3 - 4) >> 2;
v9 = (int)((_DWORD)a2 << 7);
v15 = v16 + 1;
v13 = &a6[4 * v15];
do
{
v10 = v7;
v11 = v8;
v8 += v9;
v7 += 4;
gf_4vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v11, a5, v10);
}
while ( v7 != v13 );
v14 += v15 * v9;
result = -v16;
LODWORD(a3) = v17 - 4 * v16;
}
switch ( (_DWORD)a3 )
{
case 2:
return gf_2vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v14, a5, v13);
case 3:
return gf_3vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v14, a5, v13);
case 1:
result = gf_vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v14, a5, *v13);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, _QWORD *a6)
{
_QWORD *v7; // r12
__int64 v8; // r13
__int64 v9; // rbx
_QWORD *v10; // r8
__int64 v11; // rdx
__int64 result; // rax
_QWORD *v13; // [rsp+0h] [rbp-58h]
__int64 v14; // [rsp+8h] [rbp-50h]
__int64 v15; // [rsp+10h] [rbp-48h]
unsigned int v16; // [rsp+18h] [rbp-40h]
int v17; // [rsp+1Ch] [rbp-3Ch]

v7 = a6;
v14 = a4;
if ( (int)a1 <= 31 )
return ec_encode_data_base(a1, a2, a3, a4);
if ( (int)a3 <= 3 )
{
v13 = a6;
}
else
{
v8 = a4;
v17 = a3 - 4;
v16 = (unsigned int)(a3 - 4) >> 2;
v9 = (int)((_DWORD)a2 << 7);
v15 = v16 + 1;
v13 = &a6[4 * v15];
do
{
v10 = v7;
v11 = v8;
v8 += v9;
v7 += 4;
gf_4vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v11, a5, v10);
}
while ( v7 != v13 );
v14 += v15 * v9;
result = -v16;
LODWORD(a3) = v17 - 4 * v16;
}
switch ( (_DWORD)a3 )
{
case 2:
return gf_2vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v14, a5, v13);
case 3:
return gf_3vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v14, a5, v13);
case 1:
result = gf_vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v14, a5, *v13);
break;
}
return result;
}

original_code:
void ec_encode_data_avx2(int len, int k, int rows, unsigned char *g_tbls, unsigned char **data,
    unsigned char **coding)
{
 if (len < 32) {
  ec_encode_data_base(len, k, rows, g_tbls, data, coding);
  return;
 }
 while (rows >= 4) {
  gf_4vect_dot_prod_avx2(len, k, g_tbls, data, coding);
  g_tbls += 4 * k * 32;
  coding += 4;
  rows -= 4;
 }
 switch (rows) {
 case 3:
  gf_3vect_dot_prod_avx2(len, k, g_tbls, data, coding);
  break;
 case 2:
  gf_2vect_dot_prod_avx2(len, k, g_tbls, data, coding);
  break;
 case 1:
  gf_vect_dot_prod_avx2(len, k, g_tbls, data, *coding);
  break;
 case 0:
  break;
 }
}


repo: sheheitthey/pipeserver

decompiled_code:
void *__fastcall pollset_construct(int *a1)
{
void *result; // rax

pollpool_construct();
result = malloc(8LL * *a1);
a1[14] = 0;
*((_QWORD *)a1 + 6) = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int *a1)
{
void *result; // rax

pollpool_construct();
result = malloc(8LL * *a1);
a1[14] = 0;
*((_QWORD *)a1 + 6) = result;
return result;
}

original_code:
void
pollset_construct(pollset *ps, struct pollfd *ufds, int len,
                  int sendbuf_len, int recvbuf_len)
{
    pollpool_construct(&ps->pp, ufds, len, sendbuf_len, recvbuf_len);
    ps->handles=(pollconn**)malloc(sizeof(pollconn*)*ps->pp.len);
    ps->handles_len=0;
}

canonical_original_code:
void pollset_construct(struct pollset *ps, struct pollfd *ufds, int len, int sendbuf_len, int recvbuf_len)
{
    pollpool_construct(&ps->pp, ufds, len, sendbuf_len, recvbuf_len);
    ps->handles=(struct pollconn **)malloc(sizeof(struct pollconn *)*ps->pp.len);
    ps->handles_len=0;
}

variable_types: struct pollset { struct pollpool { int len; struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } *

variable_types:
ufds
struct pollfd *

user_defined_types: struct pollset { struct pollpool pp; struct pollconn **handles; int handles_len; }

user_defined_types: struct pollconn { struct pollsock s; struct sockaddr_in saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; }

user_defined_types: struct pollpool { int len; struct pollconn *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; }

user_defined_types: struct pollsock { struct pollfd *pfd; struct tcpbuf sendbuf; struct tcpbuf recvbuf; }

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


decompiled_code:
void __fastcall pollset_destruct(__int64 a1)
{
pollpool_destruct();
free(*(void **)(a1 + 48));
*(_QWORD *)(a1 + 48) = 0LL;
*(_DWORD *)(a1 + 56) = 0;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
pollpool_destruct();
free(*(void **)(a1 + 48));
*(_QWORD *)(a1 + 48) = 0LL;
*(_DWORD *)(a1 + 56) = 0;
}

original_code:
void
pollset_destruct(pollset *ps)
{
    pollpool_destruct(&ps->pp);
    free(ps->handles);
    ps->handles=((void *)0);
    ps->handles_len=0;
}

canonical_original_code:
void pollset_destruct(struct pollset *ps)
{
    pollpool_destruct(&ps->pp);
    free(ps->handles);
    ps->handles=((void *)0);
    ps->handles_len=0;
}

user_defined_types: struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; }

user_defined_types: struct tcpbuf { int len; int pos; unsigned char *data; }

user_defined_types: struct pollfd { int fd; short events; short revents; }