decompiled_code:
unsigned __int64 __fastcall pc_encode(__int64 a1, __int64 a2, unsigned __int64 a3)
{
int v3; // ebx
__int64 v6; // rcx
unsigned __int64 v7; // rdi
unsigned __int64 v8; // rsi
unsigned __int64 v9; // rax
unsigned __int64 v10; // r14
unsigned __int64 result; // rax

v3 = 1 << a3;
if ( a3 )
{
v6 = 1LL;
while ( 1 )
{
v7 = (unsigned __int64)(1 << v6) >> 1;
if ( (unsigned __int64)v3 > 1 )
{
v8 = 0LL;
do
{
v9 = (1 << v6) * (v8 / v7);
v10 = v9 + v8 % v7;
result = v7 + v8 % v7 + v9;
*(_BYTE *)(a1 + v10) = (*(_BYTE *)(a2 + v10) + *(_BYTE *)(a2 + result)) & 1;
*(_BYTE *)(a1 + result) = *(_BYTE *)(a2 + result);
++v8;
}
while ( v8 < (unsigned __int64)v3 >> 1 );
}
if ( a3 < ++v6 )
break;
a2 = a1;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, __int64 a2, unsigned __int64 a3)
{
int v3; // ebx
__int64 v6; // rcx
unsigned __int64 v7; // rdi
unsigned __int64 v8; // rsi
unsigned __int64 v9; // rax
unsigned __int64 v10; // r14
unsigned __int64 result; // rax

v3 = 1 << a3;
if ( a3 )
{
v6 = 1LL;
while ( 1 )
{
v7 = (unsigned __int64)(1 << v6) >> 1;
if ( (unsigned __int64)v3 > 1 )
{
v8 = 0LL;
do
{
v9 = (1 << v6) * (v8 / v7);
v10 = v9 + v8 % v7;
result = v7 + v8 % v7 + v9;
*(_BYTE *)(a1 + v10) = (*(_BYTE *)(a2 + v10) + *(_BYTE *)(a2 + result)) & 1;
*(_BYTE *)(a1 + result) = *(_BYTE *)(a2 + result);
++v8;
}
while ( v8 < (unsigned __int64)v3 >> 1 );
}
if ( a3 < ++v6 )
break;
a2 = a1;
}
}
return result;
}

original_code:
void pc_encode(Bit* xOut, Bit* u, u_int64_t n) {
    u_int64_t N = 1 << n;
    Bit *in = u;
    u_int64_t step;
    for(step = 1; step <= n; step++){
        u_int64_t group_size = 1 << step;
        u_int64_t op_per_group = group_size >> 1;
        u_int64_t i;
        for(i=0; i<N/2; i++){
            u_int64_t group_n = i/op_per_group;
            u_int64_t index_in_group = i - op_per_group*group_n;
            u_int64_t i1 = group_n*group_size + index_in_group;
            u_int64_t i2 = group_n*group_size + op_per_group + index_in_group;
            xOut[i1] = (in[i1] + in[i2]) & 1;
            xOut[i2] = in[i2];
        }
        in = xOut;
    }
}

canonical_original_code:
void pc_encode(unsigned int *xOut, unsigned int *u, unsigned int n) {
    unsigned int N = 1 << n;
    unsigned int *in = u;
    unsigned int step;
    for(step = 1; step <= n; step++){
        unsigned int group_size = 1 << step;
        unsigned int op_per_group = group_size >> 1;
        unsigned int i;
        for(i=0; i<N/2; i++){
            unsigned int group_n = i/op_per_group;
            unsigned int index_in_group = i - op_per_group*group_n;
            unsigned int i1 = group_n*group_size + index_in_group;
            unsigned int i2 = group_n*group_size + op_per_group + index_in_group;
            xOut[i1] = (in[i1] + in[i2]) & 1;
            xOut[i2] = in[i2];
        }
        in = xOut;
    }
}

variable_types:
xOut
unsigned int *

variable_types:
u
unsigned int *

variable_types:
n
unsigned int

variable_types:
in
unsigned int *


original_code:
void pc_decode_calc_f(double *new_val, double *val, u_int64_t step, u_int64_t n) {
    u_int64_t D = 1 << (n-step);
    u_int64_t i;
    for(i = 0; i < D; i++){
        double a = val[2*i];
        double b = val[2*i+1];
        double v = (1+a*b) / (a+b);
        if(v < (1.0 / (double)(1 << 30))){
            v = (1.0 / (double)(1 << 30));
        }else if(v > ((double)(1 << 30))){
            v = ((double)(1 << 30));
        }
        new_val[i] = v;
    }
}

canonical_original_code:
void pc_decode_calc_f(double *new_val, double *val, unsigned int step, unsigned int n) {
    unsigned int D = 1 << (n-step);
    unsigned int i;
    for(i = 0; i < D; i++){
        double a = val[2*i];
        double b = val[2*i+1];
        double v = (1+a*b) / (a+b);
        if(v < (1.0 / (double)(1 << 30))){
            v = (1.0 / (double)(1 << 30));
        }else if(v > ((double)(1 << 30))){
            v = ((double)(1 << 30));
        }
        new_val[i] = v;
    }
}

variable_types:
val
double *

variable_types:
step
unsigned int

variable_types:
D
unsigned int

variable_types:
i
unsigned int

variable_types: a double

variable_types: b double

variable_types: v double

return_type: void


original_code:
void pc_decode_calc_us(Bit *usOut, u_int64_t stage, Bit *u, u_int64_t uindex){
    u_int64_t dim = 1 << stage;
    u_int64_t dim2 = 1;
    memcpy(usOut, u + uindex - dim, dim);
    u_int64_t s;
    Bit *temp2 = malloc(dim*sizeof(Bit));
    for(s = 1; s <= stage; s++){
        u_int64_t i1, i2;
        for(i1 = 0; i1 < 1<<(stage-s); i1++){
            for(i2 = 0; i2 < 1<<(s-1); i2++){
                Bit even = usOut[(2*i1+1)*dim2+i2];
                Bit odd = usOut[(2*i1)*dim2+i2];
                temp2[i1*dim2*2 + i2*2] = (even + odd) & 1;
                temp2[i1*dim2*2 + i2*2+1] = even;
            }
        }
        dim2 *= 2;
        memcpy(usOut, temp2, dim);
    }
    free(temp2);
}

canonical_original_code:
void pc_decode_calc_us(unsigned int *usOut, unsigned int stage, unsigned int *u, unsigned int uindex){
    unsigned int dim = 1 << stage;
    unsigned int dim2 = 1;
    memcpy(usOut, u + uindex - dim, dim);
    unsigned int s;
    unsigned int *temp2 = malloc(dim*sizeof(Bit));
    for(s = 1; s <= stage; s++){
        unsigned int i1; unsigned int i2;
        for(i1 = 0; i1 < 1<<(stage-s); i1++){
            for(i2 = 0; i2 < 1<<(s-1); i2++){
                unsigned int even = usOut[(2*i1+1)*dim2+i2];
                unsigned int odd = usOut[(2*i1)*dim2+i2];
                temp2[i1*dim2*2 + i2*2] = (even + odd) & 1;
                temp2[i1*dim2*2 + i2*2+1] = even;
            }
        }
        dim2 *= 2;
        memcpy(usOut, temp2, dim);
    }
    free(temp2);
}

variable_types:
usOut
unsigned int *

variable_types:
stage
unsigned int

variable_types:
uindex
unsigned int

variable_types:
dim
unsigned int

variable_types:
s
unsigned int

variable_types:
even
unsigned int

variable_types:
odd
unsigned int


original_code:
void pc_decode_calc_g(double *new_val, double *val, u_int64_t step, u_int64_t n, Bit *u, u_int64_t uindex) {
    u_int64_t D = 1 << (n-step);
    u_int64_t i;
    Bit us[D];
    pc_decode_calc_us(us, n-step, u, uindex);
    for(i = 0; i < D; i++){
        double a = val[2*i];
        double b = val[2*i+1];
        double v;
        if(us[i] == 0){
            v = b*a;
        }else{
            v = b/a;
        }
        if(v < (1.0 / (double)(1 << 30))){
            v = (1.0 / (double)(1 << 30));
        }else if(v > ((double)(1 << 30))){
            v = ((double)(1 << 30));
        }
        new_val[i] = v;
    }
}

canonical_original_code:
void pc_decode_calc_g(double *new_val, double *val, unsigned int step, unsigned int n, unsigned int *u, unsigned int uindex) {
    unsigned int D = 1 << (n-step);
    unsigned int i;
    unsigned int us[-1];
    pc_decode_calc_us(us, n-step, u, uindex);
    for(i = 0; i < D; i++){
        double a = val[2*i];
        double b = val[2*i+1];
        double v;
        if(us[i] == 0){
            v = b*a;
        }else{
            v = b/a;
        }
        if(v < (1.0 / (double)(1 << 30))){
            v = (1.0 / (double)(1 << 30));
        }else if(v > ((double)(1 << 30))){
            v = ((double)(1 << 30));
        }
        new_val[i] = v;
    }
}

variable_types:
u
unsigned int *

variable_types:
us
unsigned int [-1]


decompiled_code:
int __fastcall get_error_rate_file_name(char *a1, __int64 a2, double *a3, __int64 a4)
{
return sprintf(a1, "er_%lu_ch_%d_par_%f_k_%lu.txt", a2, *(unsigned int *)a3, a3[1], a4);
}

canonical_decompiled_code:
int __fastcall func0(char *a1, __int64 a2, double *a3, __int64 a4)
{
return sprintf(a1, "er_%lu_ch_%d_par_%f_k_%lu.txt", a2, *(unsigned int *)a3, a3[1], a4);
}

original_code:
void get_error_rate_file_name(char *filename, u_int64_t n, Channel *channel, u_int64_t K) {
    sprintf(filename, "er_%" "l" "u" "_ch_%d_par_%f" "_k_%" "l" "u" ".txt", n, channel->channel_type, channel->par, K);
}

canonical_original_code:
void get_error_rate_file_name(char *filename, unsigned int n, struct Channel *channel, unsigned int K) {
    sprintf(filename, "er_%" "l" "u" "_ch_%d_par_%f" "_k_%" "l" "u" ".txt", n, channel->channel_type, channel->par, K);
}

variable_types:
filename
char *

variable_types:
n
unsigned int

variable_types: struct Channel { enum ChannelType { ChannelType_BSC=1, ChannelType_BEC=2 } channel_type; double par; } *

variable_types:
K
unsigned int

user_defined_types: struct Channel { enum ChannelType channel_type; double par; }


decompiled_code:
int __fastcall get_error_rate_file_name_tmp(char *a1, __int64 a2, double *a3, __int64 a4)
{
return sprintf(a1, "er_%lu_ch_%d_par_%f_k_%lu.tmp.txt", a2, *(unsigned int *)a3, a3[1], a4);
}

canonical_decompiled_code:
int __fastcall func1(char *a1, __int64 a2, double *a3, __int64 a4)
{
return sprintf(a1, "er_%lu_ch_%d_par_%f_k_%lu.tmp.txt", a2, *(unsigned int *)a3, a3[1], a4);
}

original_code:
void get_error_rate_file_name_tmp(char *filename, u_int64_t n, Channel *channel, u_int64_t K) {
    sprintf(filename, "er_%" "l" "u" "_ch_%d_par_%f" "_k_%" "l" "u" ".tmp.txt", n, channel->channel_type, channel->par, K);
}

canonical_original_code:
void get_error_rate_file_name_tmp(char *filename, unsigned int n, struct Channel *channel, unsigned int K) {
    sprintf(filename, "er_%" "l" "u" "_ch_%d_par_%f" "_k_%" "l" "u" ".tmp.txt", n, channel->channel_type, channel->par, K);
}

user_defined_types: enum ChannelType { ChannelType_BSC=1, ChannelType_BEC=2 }


decompiled_code:
__int64 __fastcall frozen_bits_sort_cmp(const void *a1, const void *a2)
{
__int64 v2; // rax
double v3; // xmm1_8
double v4; // xmm0_8
__int64 result; // rax

v2 = *(_QWORD *)(*((_QWORD *)a1 + 1) + 32LL);
v3 = *(double *)(v2 + 8LL * *(_QWORD *)a1);
v4 = *(double *)(v2 + 8LL * *(_QWORD *)a2);
result = 0xFFFFFFFFLL;
if ( v4 <= v3 )
result = v3 > v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
__int64 v2; // rax
double v3; // xmm1_8
double v4; // xmm0_8
__int64 result; // rax

v2 = *(_QWORD *)(*((_QWORD *)a1 + 1) + 32LL);
v3 = *(double *)(v2 + 8LL * *(_QWORD *)a1);
v4 = *(double *)(v2 + 8LL * *(_QWORD *)a2);
result = 0xFFFFFFFFLL;
if ( v4 <= v3 )
result = v3 > v4;
return result;
}

original_code:
int frozen_bits_sort_cmp(const void *x, const void *y)
{
    struct frozen_bits_index_struct *xx = (struct frozen_bits_index_struct*)x;
    struct frozen_bits_index_struct *yy = (struct frozen_bits_index_struct*)y;
    Bhattacharyya *b = xx->b;
    if (b->Z[xx->index] < b->Z[yy->index]) return -1;
    if (b->Z[xx->index] > b->Z[yy->index]) return 1;
    return 0;
}

canonical_original_code:
int frozen_bits_sort_cmp(void *x, void *y)
{
    struct frozen_bits_index_struct *xx = (struct frozen_bits_index_struct*)x;
    struct frozen_bits_index_struct *yy = (struct frozen_bits_index_struct*)y;
    struct Bhattacharyya *b = xx->b;
    if (b->Z[xx->index] < b->Z[yy->index]) return -1;
    if (b->Z[xx->index] > b->Z[yy->index]) return 1;
    return 0;
}

variable_types:
x
void *

variable_types:
y
void *

variable_types: struct frozen_bits_index_struct { unsigned int index; struct Bhattacharyya { unsigned int n; struct Channel { enum ChannelType { ChannelType_BSC=1, ChannelType_BEC=2 } channel_type; double par; } channel; unsigned int total_samples; double *Z; double *Zvar; } *b; } *

return_type: int

user_defined_types: struct frozen_bits_index_struct { unsigned int index; struct Bhattacharyya *b; }

user_defined_types: struct Bhattacharyya { unsigned int n; struct Channel channel; unsigned int total_samples; double *Z; double *Zvar; }


decompiled_code:
int __fastcall get_bhattacharyya_file_name(char *a1, __int64 a2, double *a3)
{
return sprintf(a1, "bh_%lu_ch_%d_par_%f.txt", a2, *(unsigned int *)a3, a3[1]);
}

canonical_decompiled_code:
int __fastcall func1(char *a1, __int64 a2, double *a3)
{
return sprintf(a1, "bh_%lu_ch_%d_par_%f.txt", a2, *(unsigned int *)a3, a3[1]);
}

original_code:
void get_bhattacharyya_file_name(char *filename, u_int64_t n, Channel *channel) {
    sprintf(filename, "bh_%" "l" "u" "_ch_%d_par_%f" ".txt", n, channel->channel_type, channel->par);
}

canonical_original_code:
void get_bhattacharyya_file_name(char *filename, unsigned int n, struct Channel *channel) {
    sprintf(filename, "bh_%" "l" "u" "_ch_%d_par_%f" ".txt", n, channel->channel_type, channel->par);
}


decompiled_code:
int __fastcall get_bhattacharyya_file_name_tmp(char *a1, __int64 a2, double *a3)
{
return sprintf(a1, "bh_%lu_ch_%d_par_%f.tmp.txt", a2, *(unsigned int *)a3, a3[1]);
}

canonical_decompiled_code:
int __fastcall func2(char *a1, __int64 a2, double *a3)
{
return sprintf(a1, "bh_%lu_ch_%d_par_%f.tmp.txt", a2, *(unsigned int *)a3, a3[1]);
}

original_code:
void get_bhattacharyya_file_name_tmp(char *filename, u_int64_t n, Channel *channel) {
    sprintf(filename, "bh_%" "l" "u" "_ch_%d_par_%f" ".tmp.txt", n, channel->channel_type, channel->par);
}

canonical_original_code:
void get_bhattacharyya_file_name_tmp(char *filename, unsigned int n, struct Channel *channel) {
    sprintf(filename, "bh_%" "l" "u" "_ch_%d_par_%f" ".tmp.txt", n, channel->channel_type, channel->par);
}


decompiled_code:
char *__fastcall get_frozen_bits(void *s, __int64 a2, _QWORD *a3)
{
size_t v4; // rbx
char *v5; // rax
char *v6; // rbp
char *v7; // rdx
__int64 i; // rax
char *result; // rax
char *v10; // rbp

v4 = 1 << *a3;
v5 = (char *)malloc(16 * v4);
v6 = v5;
if ( v4 )
{
v7 = v5;
for ( i = 0LL; i != v4; ++i )
{
*(_QWORD *)v7 = i;
*((_QWORD *)v7 + 1) = a3;
v7 += 16;
}
}
qsort(v6, v4, 0x10uLL, (__compar_fn_t)frozen_bits_sort_cmp);
result = (char *)memset(s, 0, v4);
if ( a2 )
{
result = v6;
v10 = &v6[16 * a2];
do
{
*((_BYTE *)s + *(_QWORD *)result) = 1;
result += 16;
}
while ( result != v10 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func6(void *s, __int64 a2, _QWORD *a3)
{
size_t v4; // rbx
char *v5; // rax
char *v6; // rbp
char *v7; // rdx
__int64 i; // rax
char *result; // rax
char *v10; // rbp

v4 = 1 << *a3;
v5 = (char *)malloc(16 * v4);
v6 = v5;
if ( v4 )
{
v7 = v5;
for ( i = 0LL; i != v4; ++i )
{
*(_QWORD *)v7 = i;
*((_QWORD *)v7 + 1) = a3;
v7 += 16;
}
}
qsort(v6, v4, 0x10uLL, (__compar_fn_t)frozen_bits_sort_cmp);
result = (char *)memset(s, 0, v4);
if ( a2 )
{
result = v6;
v10 = &v6[16 * a2];
do
{
*((_BYTE *)s + *(_QWORD *)result) = 1;
result += 16;
}
while ( result != v10 );
}
return result;
}

original_code:
void get_frozen_bits(Bit *bits, u_int64_t K, Bhattacharyya *b) {
    u_int64_t N = 1 << b->n;
    struct frozen_bits_index_struct *indexes = (struct frozen_bits_index_struct*)malloc(sizeof(struct frozen_bits_index_struct)*N);
    u_int64_t i;
    for(i=0;i<N;i++){
        indexes[i].index = i;
        indexes[i].b = b;
    }
    qsort(indexes, N, sizeof(struct frozen_bits_index_struct), &frozen_bits_sort_cmp);
    memset(bits, 0, N);
    for(i=0;i<K;i++){
        u_int64_t index = indexes[i].index;
        bits[index] = 1;
    }
}

canonical_original_code:
void get_frozen_bits(unsigned int *bits, unsigned int K, struct Bhattacharyya *b) {
    unsigned int N = 1 << b->n;
    struct frozen_bits_index_struct *indexes = (struct frozen_bits_index_struct*)malloc(sizeof(struct frozen_bits_index_struct)*N);
    unsigned int i;
    for(i=0;i<N;i++){
        indexes[i].index = i;
        indexes[i].b = b;
    }
    qsort(indexes, N, sizeof(struct frozen_bits_index_struct), &frozen_bits_sort_cmp);
    memset(bits, 0, N);
    for(i=0;i<K;i++){
        unsigned int index = indexes[i].index;
        bits[index] = 1;
    }
}

variable_types:
bits
unsigned int *

variable_types: struct Bhattacharyya { unsigned int n; struct Channel { enum ChannelType { ChannelType_BSC=1, ChannelType_BEC=2 } channel_type; double par; } channel; unsigned int total_samples; double *Z; double *Zvar; } *

variable_types:
N
unsigned int

variable_types:
i
unsigned int

variable_types:
index
unsigned int


decompiled_code:
int __fastcall apply_channel(_BYTE *a1, unsigned __int8 *a2, __int64 a3, char a4)
{
_BYTE *v4; // rbx
unsigned __int8 *v5; // r12
int result; // eax
unsigned __int8 *v8; // rbp
unsigned __int8 *v9; // r12
_BYTE *v10; // rbp
_BYTE *v11; // rbx

v4 = a1;
v5 = a2;
result = *(_DWORD *)a3;
if ( *(_DWORD *)a3 == 1 )
{
if ( 1 << a4 )
{
v8 = a2;
v9 = &a2[1 << a4];
do
{
if ( *(double *)(a3 + 8) <= (double)rand() / 2147483647.0 )
result = *v8;
else
result = (*v8 + 1) & 1;
*v4 = result;
++v8;
++v4;
}
while ( v8 != v9 );
}
}
else if ( result == 2 && 1 << a4 )
{
v10 = a1;
v11 = &a1[1 << a4];
do
{
result = rand();
if ( *(double *)(a3 + 8) <= (double)result / 2147483647.0 )
{
result = *v5;
*v10 = result;
}
else
{
*v10 = 2;
}
++v10;
++v5;
}
while ( v10 != v11 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(_BYTE *a1, unsigned __int8 *a2, __int64 a3, char a4)
{
_BYTE *v4; // rbx
unsigned __int8 *v5; // r12
int result; // eax
unsigned __int8 *v8; // rbp
unsigned __int8 *v9; // r12
_BYTE *v10; // rbp
_BYTE *v11; // rbx

v4 = a1;
v5 = a2;
result = *(_DWORD *)a3;
if ( *(_DWORD *)a3 == 1 )
{
if ( 1 << a4 )
{
v8 = a2;
v9 = &a2[1 << a4];
do
{
if ( *(double *)(a3 + 8) <= (double)rand() / 2147483647.0 )
result = *v8;
else
result = (*v8 + 1) & 1;
*v4 = result;
++v8;
++v4;
}
while ( v8 != v9 );
}
}
else if ( result == 2 && 1 << a4 )
{
v10 = a1;
v11 = &a1[1 << a4];
do
{
result = rand();
if ( *(double *)(a3 + 8) <= (double)result / 2147483647.0 )
{
result = *v5;
*v10 = result;
}
else
{
*v10 = 2;
}
++v10;
++v5;
}
while ( v10 != v11 );
}
return result;
}

original_code:
void apply_channel(Bit *yOut, Bit *x, const Channel *channel, u_int64_t n) {
    switch (channel->channel_type) {
        case ChannelType_BSC:
        {
            u_int64_t N = 1 << n;
            u_int64_t i;
            for(i=0; i<N; i++){
                double r = (double)rand() / (double)2147483647;
                if(r < channel->par)
                    yOut[i] = (x[i] + 1) & 1;
                else
                    yOut[i] = x[i];
            }
            break;
        }
        case ChannelType_BEC:
        {
            u_int64_t N = 1 << n;
            u_int64_t i;
            for(i=0; i<N; i++){
                double r = (double)rand() / (double)2147483647;
                if(r < channel->par)
                    yOut[i] = 2;
                else
                    yOut[i] = x[i];
            }
            break;
        }
    }
}

canonical_original_code:
void apply_channel(unsigned int *yOut, unsigned int *x, struct Channel *channel, unsigned int n) {
    switch (channel->channel_type) {
        case ChannelType_BSC:
        {
            unsigned int N = 1 << n;
            unsigned int i;
            for(i=0; i<N; i++){
                double r = (double)rand() / (double)2147483647;
                if(r < channel->par)
                    yOut[i] = (x[i] + 1) & 1;
                else
                    yOut[i] = x[i];
            }
            break;
        }
        case ChannelType_BEC:
        {
            unsigned int N = 1 << n;
            unsigned int i;
            for(i=0; i<N; i++){
                double r = (double)rand() / (double)2147483647;
                if(r < channel->par)
                    yOut[i] = 2;
                else
                    yOut[i] = x[i];
            }
            break;
        }
    }
}

variable_types:
yOut
unsigned int *

variable_types:
x
unsigned int *

variable_types: r double


decompiled_code:
double __fastcall channel_probability(__int64 a1, char a2, char a3)
{
double result; // xmm0_8

if ( *(_DWORD *)a1 == 1 )
{
if ( a2 == a3 )
result = 1.0 - *(double *)(a1 + 8);
else
result = *(double *)(a1 + 8);
}
else if ( *(_DWORD *)a1 == 2 )
{
if ( a2 == 2 )
{
result = *(double *)(a1 + 8);
}
else
{
result = 0.0;
if ( a2 == a3 )
result = 1.0 - *(double *)(a1 + 8);
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1, char a2, char a3)
{
double result; // xmm0_8

if ( *(_DWORD *)a1 == 1 )
{
if ( a2 == a3 )
result = 1.0 - *(double *)(a1 + 8);
else
result = *(double *)(a1 + 8);
}
else if ( *(_DWORD *)a1 == 2 )
{
if ( a2 == 2 )
{
result = *(double *)(a1 + 8);
}
else
{
result = 0.0;
if ( a2 == a3 )
result = 1.0 - *(double *)(a1 + 8);
}
}
return result;
}

original_code:
double channel_probability(const Channel *channel, Bit bOut, Bit bIn) {
    switch (channel->channel_type) {
        case ChannelType_BSC:
        {
            if(bOut != bIn)
                return channel->par;
            else
                return 1-channel->par;
        }
        case ChannelType_BEC:
        {
            if(bOut == 2)
                return channel->par;
            else if(bOut == bIn)
                return 1-channel->par;
            else
                return 0;
        }
    }
}

canonical_original_code:
double channel_probability(struct Channel *channel, unsigned int bOut, unsigned int bIn) {
    switch (channel->channel_type) {
        case ChannelType_BSC:
        {
            if(bOut != bIn)
                return channel->par;
            else
                return 1-channel->par;
        }
        case ChannelType_BEC:
        {
            if(bOut == 2)
                return channel->par;
            else if(bOut == bIn)
                return 1-channel->par;
            else
                return 0;
        }
    }
}

variable_types:
bOut
unsigned int

variable_types:
bIn
unsigned int

return_type: double


decompiled_code:
double __fastcall channel_capacity(__int64 a1)
{
double v1; // rbp
double v2; // r14
double result; // xmm0_8
double v4; // [rsp+8h] [rbp-20h]

if ( *(_DWORD *)a1 == 1 )
{
v1 = *(double *)(a1 + 8);
v2 = log2(v1);
v4 = 1.0 - *(double *)(a1 + 8);
result = 1.0 - (COERCE_DOUBLE(*(_QWORD *)&v1 ^ LC3) * v2 - log2(v4) * v4);
}
else if ( *(_DWORD *)a1 == 2 )
{
result = 1.0 - *(double *)(a1 + 8);
}
return result;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1)
{
double v1; // rbp
double v2; // r14
double result; // xmm0_8
double v4; // [rsp+8h] [rbp-20h]

if ( *(_DWORD *)a1 == 1 )
{
v1 = *(double *)(a1 + 8);
v2 = log2(v1);
v4 = 1.0 - *(double *)(a1 + 8);
result = 1.0 - (COERCE_DOUBLE(*(_QWORD *)&v1 ^ LC3) * v2 - log2(v4) * v4);
}
else if ( *(_DWORD *)a1 == 2 )
{
result = 1.0 - *(double *)(a1 + 8);
}
return result;
}

original_code:
double channel_capacity(const Channel *channel) {
    switch (channel->channel_type) {
        case ChannelType_BSC:
        {
            double entropy = - channel->par*log2(channel->par) - (1-channel->par)*log2(1-channel->par);
            return 1-entropy;
        }
        case ChannelType_BEC:
        {
            return 1-channel->par;
        }
    }
}

canonical_original_code:
double channel_capacity(struct Channel *channel) {
    switch (channel->channel_type) {
        case ChannelType_BSC:
        {
            double entropy = - channel->par*log2(channel->par) - (1-channel->par)*log2(1-channel->par);
            return 1-entropy;
        }
        case ChannelType_BEC:
        {
            return 1-channel->par;
        }
    }
}

variable_types: entropy double


original_code:
void double_pack(double x, struct double_packed *r)
{
    double xf = fabs(frexp(x, &r->exp)) - 0.5;
    if (xf < 0.0)
    {
        r->frac = 0;
        return;
    }
    r->frac = 1 + (long long)(xf * 2.0 * (9223372036854775807LL - 1));
    if (x < 0.0)
        r->frac = -r->frac;
}

variable_types: x double

variable_types: struct double_packed { int exp; long long frac; } *

variable_types: xf double


original_code:
double double_unpack(const struct double_packed *p)
{
    double xf, x;
    if (p->frac == 0)
        return 0.0;
    xf = ((double)(llabs(p->frac) - 1) / (9223372036854775807LL - 1)) / 2.0;
    x = ldexp(xf + 0.5, p->exp);
    if (p->frac < 0)
        x = -x;
    return x;
}

canonical_original_code:
double double_unpack(struct double_packed *p)
{
    double xf; double x;
    if (p->frac == 0)
        return 0.0;
    xf = ((double)(llabs(p->frac) - 1) / (9223372036854775807LL - 1)) / 2.0;
    x = ldexp(xf + 0.5, p->exp);
    if (p->frac < 0)
        x = -x;
    return x;
}

user_defined_types: struct double_packed { int exp; long long frac; }


decompiled_code:
void __fastcall pc_decode_step(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 *a6)
{
__int64 v8; // r15
double *v10; // rbp

v8 = a5;
v10 = (double *)malloc(8LL * (1 << (a3 - a4)));
pc_decode_calc_f(v10, v8, a4, a3);
if ( a3 == a4 )
{
pc_decode_update_u_(a1, a2, a6, *v10);
pc_decode_calc_g(v10, a5, a4, a3, a1, *a6);
pc_decode_update_u_(a1, a2, a6, *v10);
}
else
{
pc_decode_step(a1, a2, a3, a4 + 1, v10, a6);
pc_decode_calc_g(v10, a5, a4, a3, a1, *a6);
pc_decode_step(a1, a2, a3, a4 + 1, v10, a6);
}
free(v10);
}

original_code:
void pc_decode_step(Bit *u_, Bit *A, u_int64_t n, u_int64_t step, double *val, u_int64_t *uindex){
    u_int64_t D = 1 << (n-step);
    double *new_val = malloc(sizeof(double)*D);
    pc_decode_calc_f(new_val, val, step, n);
    if(step == n){
        pc_decode_update_u_(u_, A, new_val[0], uindex);
    }else{
        pc_decode_step(u_, A, n, step+1, new_val, uindex);
    }
    pc_decode_calc_g(new_val, val, step, n, u_, *uindex);
    if(step == n){
        pc_decode_update_u_(u_, A, new_val[0], uindex);
    }else{
        pc_decode_step(u_, A, n, step+1, new_val, uindex);
    }
    free(new_val);
}

canonical_original_code:
void pc_decode_step(unsigned int *u_, unsigned int *A, unsigned int n, unsigned int step, double *val, unsigned int *uindex){
    unsigned int D = 1 << (n-step);
    double *new_val = malloc(sizeof(double)*D);
    pc_decode_calc_f(new_val, val, step, n);
    if(step == n){
        pc_decode_update_u_(u_, A, new_val[0], uindex);
    }else{
        pc_decode_step(u_, A, n, step+1, new_val, uindex);
    }
    pc_decode_calc_g(new_val, val, step, n, u_, *uindex);
    if(step == n){
        pc_decode_update_u_(u_, A, new_val[0], uindex);
    }else{
        pc_decode_step(u_, A, n, step+1, new_val, uindex);
    }
    free(new_val);
}

variable_types:
A
unsigned int *

variable_types:
n
unsigned int

variable_types:
step
unsigned int

variable_types:
val
double *

variable_types:
uindex
unsigned int *

variable_types:
D
unsigned int


outb

repo: nicolai-rostov/asus-fancontrol

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

result = a1;
__outbyte(a2, a1);
return result;
}

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

result = a1;
__outbyte(a2, a1);
return result;
}

original_code:
static __inline void
outb (unsigned char __value, unsigned short int __port)
{
  __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));
}

canonical_original_code:
static __inline void outb(unsigned char __value, unsigned short __port)
{
  __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));
}


WEIE

original_code:
uint8_t WEIE() {
 uint16_t Local0 = 0x4000;
 uint8_t Local1 = inb(EC4C) & 0x02;
 while(Local0 != 0 && Local1 == 0x02) {
  Local1 = inb(EC4C) & 0x02;
  Local0--;
  usleep(5*1000);
 }
 return (Local0 == 0);
}

canonical_original_code:
unsigned char WEIE() {
 unsigned short Local0 = 0x4000;
 unsigned char Local1 = inb(EC4C) & 0x02;
 while(Local0 != 0 && Local1 == 0x02) {
  Local1 = inb(EC4C) & 0x02;
  Local0--;
  usleep(5*1000);
 }
 return (Local0 == 0);
}

return_type: unsigned char


WEOE

original_code:
uint8_t WEOE () {
 uint16_t Local0 = 0xFFFF;
 uint8_t Local1 = inb(EC4C) & 0x01;
 while(Local0 != 0 && Local1 == 0x01) {
  Local1 = inb(EC4C) & 0x01;
  Local0--;
  usleep(5*1000);
  inb(EC4D);
 }
 return (Local0 == 0);
}

canonical_original_code:
unsigned char WEOE() {
 unsigned short Local0 = 0xFFFF;
 unsigned char Local1 = inb(EC4C) & 0x01;
 while(Local0 != 0 && Local1 == 0x01) {
  Local1 = inb(EC4C) & 0x01;
  Local0--;
  usleep(5*1000);
  inb(EC4D);
 }
 return (Local0 == 0);
}


WMFN

decompiled_code:
__int64 __fastcall WMFN(unsigned __int8 a1)
{
bool v1; // dl
__int64 result; // rax
bool v3; // dl
bool v4; // dl
bool v5; // dl
bool v6; // dl

v1 = WEOE();
result = 0xFFFFFFFFLL;
if ( !v1 )
{
v3 = WEIE();
result = 0xFFFFFFFFLL;
if ( !v3 )
{
outb(0xFFu, 0x258u);
v4 = WEIE();
result = 0xFFFFFFFFLL;
if ( !v4 )
{
outb(0x98u, 0x258u);
v5 = WEIE();
result = 0xFFFFFFFFLL;
if ( !v5 )
{
outb(a1, 0x257u);
v6 = WEIE();
result = 0xFFFFFFFFLL;
if ( !v6 )
result = (unsigned int)-WEIE();
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 a1)
{
bool v1; // dl
__int64 result; // rax
bool v3; // dl
bool v4; // dl
bool v5; // dl
bool v6; // dl

v1 = func10();
result = 0xFFFFFFFFLL;
if ( !v1 )
{
v3 = func9();
result = 0xFFFFFFFFLL;
if ( !v3 )
{
func8(0xFFu, 0x258u);
v4 = func9();
result = 0xFFFFFFFFLL;
if ( !v4 )
{
func8(0x98u, 0x258u);
v5 = func9();
result = 0xFFFFFFFFLL;
if ( !v5 )
{
func8(a1, 0x257u);
v6 = func9();
result = 0xFFFFFFFFLL;
if ( !v6 )
result = (unsigned int)-func9();
}
}
}
}
return result;
}

original_code:
uint16_t WMFN (uint8_t Arg0) {
 if (WEOE() != 0){ return (0xFFFF); }
 if (WEIE() != 0){ return (0xFFFF); }
 outb(0xFF, EC4C);
 if (WEIE() != 0){ return (0xFFFF); }
 outb(0x98, EC4C);
 if (WEIE() != 0){ return (0xFFFF); }
 outb(Arg0, EC4D);
 if (WEIE() != 0){ return (0xFFFF); }
 if (WEIE() != 0){ return (0xFFFF); }
 return 0;
}

canonical_original_code:
unsigned short WMFN(unsigned char Arg0) {
 if (WEOE() != 0){ return (0xFFFF); }
 if (WEIE() != 0){ return (0xFFFF); }
 outb(0xFF, EC4C);
 if (WEIE() != 0){ return (0xFFFF); }
 outb(0x98, EC4C);
 if (WEIE() != 0){ return (0xFFFF); }
 outb(Arg0, EC4D);
 if (WEIE() != 0){ return (0xFFFF); }
 if (WEIE() != 0){ return (0xFFFF); }
 return 0;
}

return_type: unsigned short


main

canonical_name: main

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

if ( argc != 2 )
{
printf("Usage: %s {auto|1..255}\n", *argv);
return 1;
}
v3 = argv[1];
if ( !strcmp(v3, "auto") )
{
puts("speed: auto");
v7 = -1;
}
else
{
v4 = atoi(v3);
if ( v4 - 1 > 0xFE )
{
printf("Error: the speed %d is not possible\n", v4);
return 1;
}
v7 = v4;
printf("speed: %d (0x%x) [level %d]\n", (unsigned __int8)v4, (unsigned __int8)v4, (unsigned __int8)v4 >> 3);
}
if ( ioperm(0x257uLL, 1uLL, 1) )
{
printf("Error: could not gain access to IO port EC4D (0x%X). Are you root?\n", 599LL);
v5 = 1;
}
else
{
v5 = ioperm(0x258uLL, 1uLL, 1);
if ( v5 )
{
printf("Error: could not gain access to IO port EC4C (0x%X). Are you root?\n", 600LL);
v5 = 1;
}
else
{
WMFN(v7);
}
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
unsigned int v4; // eax
int v5; // ebx
unsigned __int8 v7; // bp

if ( argc != 2 )
{
printf("Usage: %s {auto|1..255}\n", *argv);
return 1;
}
v3 = argv[1];
if ( !strcmp(v3, "auto") )
{
puts("speed: auto");
v7 = -1;
}
else
{
v4 = atoi(v3);
if ( v4 - 1 > 0xFE )
{
printf("Error: the speed %d is not possible\n", v4);
return 1;
}
v7 = v4;
printf("speed: %d (0x%x) [level %d]\n", (unsigned __int8)v4, (unsigned __int8)v4, (unsigned __int8)v4 >> 3);
}
if ( ioperm(0x257uLL, 1uLL, 1) )
{
printf("Error: could not gain access to IO port EC4D (0x%X). Are you root?\n", 599LL);
v5 = 1;
}
else
{
v5 = ioperm(0x258uLL, 1uLL, 1);
if ( v5 )
{
printf("Error: could not gain access to IO port EC4C (0x%X). Are you root?\n", 600LL);
v5 = 1;
}
else
{
func11(v7);
}
}
return v5;
}

original_code:
int main(int argc, char ** argv) {
 if(argc != 2) {
  printf("Usage: %s {auto|1..255}\n", argv[0]);
  return 1;
 }
 uint8_t speed = 0xFF;
 uint8_t level = 0xFF;
 uint8_t max_speed = 0xFF;
 if(strcmp(argv[1], "auto") == 0)
  printf("speed: auto\n");
 else {
  int arg = atoi(argv[1]);
  if(arg < 1 || arg > max_speed) {
   printf("Error: the speed %d is not possible\n", arg);
   return 1;
  }
  speed = arg;
  level = (speed | 0x07) >> 3;
  printf("speed: %d (0x%x) [level %d]\n", speed, speed, level);
 }
 if(ioperm(EC4D, 1, 1)) {
  printf("Error: could not gain access to IO port EC4D (0x%X). Are you root?\n", EC4D);
  return 1;
 }
 if(ioperm(EC4C, 1, 1)) {
  printf("Error: could not gain access to IO port EC4C (0x%X). Are you root?\n", EC4C);
  return 1;
 }
 WMFN(speed);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 if(argc != 2) {
  printf("Usage: %s {auto|1..255}\n", argv[0]);
  return 1;
 }
 unsigned char speed = 0xFF;
 unsigned char level = 0xFF;
 unsigned char max_speed = 0xFF;
 if(strcmp(argv[1], "auto") == 0)
  printf("speed: auto\n");
 else {
  int arg = atoi(argv[1]);
  if(arg < 1 || arg > max_speed) {
   printf("Error: the speed %d is not possible\n", arg);
   return 1;
  }
  speed = arg;
  level = (speed | 0x07) >> 3;
  printf("speed: %d (0x%x) [level %d]\n", speed, speed, level);
 }
 if(ioperm(EC4D, 1, 1)) {
  printf("Error: could not gain access to IO port EC4D (0x%X). Are you root?\n", EC4D);
  return 1;
 }
 if(ioperm(EC4C, 1, 1)) {
  printf("Error: could not gain access to IO port EC4C (0x%X). Are you root?\n", EC4C);
  return 1;
 }
 WMFN(speed);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
speed
unsigned char

variable_types:
level
unsigned char

variable_types: arg int


decompiled_code:
_QWORD *Ring_new()
{
_QWORD *result; // rax

result = (_QWORD *)Mem_calloc(1LL, 16LL, "src/ring.c", 18LL);
*result = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = (_QWORD *)Mem_calloc(1LL, 16LL, "src/ring.c", 18LL);
*result = 0LL;
return result;
}

original_code:
Ring_T Ring_new(void) {
 Ring_T ring;
 ((ring) = Mem_calloc((1), ((long)sizeof *(ring)), "src/ring.c", 18));
 ring->head = ((void *)0);
 return ring;
}

canonical_original_code:
struct Ring_T *Ring_new() {
 struct Ring_T *ring;
 ((ring) = Mem_calloc((1), ((long)sizeof *(ring)), "src/ring.c", 18));
 ring->head = ((void *)0);
 return ring;
}

variable_types: struct Ring_T { struct node { struct node *llink; void *value; } *head; int length; } *

user_defined_types: struct Ring_T { struct node *head; int length; }


decompiled_code:
__int64 __fastcall Ring_length(__int64 a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/ring.c", 44LL);
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/ring.c", 44LL);
return *(unsigned int *)(a1 + 8);
}

original_code:
int Ring_length(Ring_T ring) {
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 44),0)));
 return ring->length;
}

canonical_original_code:
int Ring_length(struct Ring_T *ring) {
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 44),0)));
 return ring->length;
}

user_defined_types: struct node { struct node *llink; void *value; }


decompiled_code:
__int64 __fastcall Ring_get(__int64 a1, int a2)
{
_QWORD *v2; // rax
int v3; // edx
int v5; // ecx
int v6; // edx

if ( !a1 )
Except_raise(&Assert_Failed, "src/ring.c", 49LL);
if ( a2 < 0 || *(_DWORD *)(a1 + 8) <= a2 )
Except_raise(&Assert_Failed, "src/ring.c", 50LL);
v2 = *(_QWORD **)a1;
if ( *(_DWORD *)(a1 + 8) / 2 < a2 )
{
v5 = *(_DWORD *)(a1 + 8) - a2;
v6 = v5 - 1;
if ( v5 > 0 )
{
do
{
v2 = (_QWORD *)*v2;
--v6;
}
while ( v6 != -1 );
}
}
else
{
v3 = a2 - 1;
if ( a2 > 0 )
{
do
{
v2 = (_QWORD *)v2[1];
--v3;
}
while ( v3 != -1 );
}
}
return v2[2];
}

original_code:
void *Ring_get(Ring_T ring, int i) {
 struct node *q;
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 49),0)));
 ((void)((i >= 0 && i < ring->length)||(Except_raise(&(Assert_Failed), "src/ring.c", 50),0)));
 {
  int n;
  q = ring->head;
  if (i <= ring->length/2)
   for (n = i; n-- > 0; )
    q = q->rlink;
  else
   for (n = ring->length - i; n-- > 0; )
    q = q->llink;
 }
 return q->value;
}

canonical_original_code:
void *Ring_get(struct Ring_T *ring, int i) {
 struct node *q;
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 49),0)));
 ((void)((i >= 0 && i < ring->length)||(Except_raise(&(Assert_Failed), "src/ring.c", 50),0)));
 {
  int n;
  q = ring->head;
  if (i <= ring->length/2)
   for (n = i; n-- > 0; )
    q = q->rlink;
  else
   for (n = ring->length - i; n-- > 0; )
    q = q->llink;
 }
 return q->value;
}

variable_types: i int

variable_types: struct node { struct node *llink; void *value; } *

variable_types: n int

return_type: void *


original_code:
void *Ring_put(Ring_T ring, int i, void *x) {
 struct node *q;
 void *prev;
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 66),0)));
 ((void)((i >= 0 && i < ring->length)||(Except_raise(&(Assert_Failed), "src/ring.c", 67),0)));
 {
  int n;
  q = ring->head;
  if (i <= ring->length/2)
   for (n = i; n-- > 0; )
    q = q->rlink;
  else
   for (n = ring->length - i; n-- > 0; )
    q = q->llink;
 }
 prev = q->value;
 q->value = x;
 return prev;
}

canonical_original_code:
void *Ring_put(struct Ring_T *ring, int i, void *x) {
 struct node *q;
 void *prev;
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 66),0)));
 ((void)((i >= 0 && i < ring->length)||(Except_raise(&(Assert_Failed), "src/ring.c", 67),0)));
 {
  int n;
  q = ring->head;
  if (i <= ring->length/2)
   for (n = i; n-- > 0; )
    q = q->rlink;
  else
   for (n = ring->length - i; n-- > 0; )
    q = q->llink;
 }
 prev = q->value;
 q->value = x;
 return prev;
}

variable_types:
x
void *

variable_types:
prev
void *


original_code:
void *Ring_addhi(Ring_T ring, void *x) {
 struct node *p, *q;
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 84),0)));
 ((p) = Mem_alloc(((long)sizeof *(p)), "src/ring.c", 85));
 if ((q = ring->head) != ((void *)0))
  {
   p->llink = q->llink;
   q->llink->rlink = p;
   p->rlink = q;
   q->llink = p;
  }
 else
  ring->head = p->llink = p->rlink = p;
 ring->length++;
 return p->value = x;
}

canonical_original_code:
void *Ring_addhi(struct Ring_T *ring, void *x) {
 struct node *p; struct node *q;
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 84),0)));
 ((p) = Mem_alloc(((long)sizeof *(p)), "src/ring.c", 85));
 if ((q = ring->head) != ((void *)0))
  {
   p->llink = q->llink;
   q->llink->rlink = p;
   p->rlink = q;
   q->llink = p;
  }
 else
  ring->head = p->llink = p->rlink = p;
 ring->length++;
 return p->value = x;
}


decompiled_code:
__int64 __fastcall Ring_addlo(_QWORD **a1, __int64 a2)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/ring.c", 99LL);
Ring_addhi((__int64)a1, a2);
*a1 = (_QWORD *)**a1;
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD **a1, __int64 a2)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/ring.c", 99LL);
func5((__int64)a1, a2);
*a1 = (_QWORD *)**a1;
return a2;
}

original_code:
void *Ring_addlo(Ring_T ring, void *x) {
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 99),0)));
 Ring_addhi(ring, x);
 ring->head = ring->head->llink;
 return x;
}

canonical_original_code:
void *Ring_addlo(struct Ring_T *ring, void *x) {
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 99),0)));
 Ring_addhi(ring, x);
 ring->head = ring->head->llink;
 return x;
}


original_code:
void *Ring_add(Ring_T ring, int pos, void *x) {
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 105),0)));
 ((void)((pos >= -ring->length && pos<=ring->length+1)||(Except_raise(&(Assert_Failed), "src/ring.c", 106),0)));
 if (pos == 1 || pos == -ring->length)
  return Ring_addlo(ring, x);
 else if (pos == 0 || pos == ring->length + 1)
  return Ring_addhi(ring, x);
 else {
  struct node *p, *q;
  int i = pos < 0 ? pos + ring->length : pos - 1;
  {
   int n;
   q = ring->head;
   if (i <= ring->length/2)
    for (n = i; n-- > 0; )
     q = q->rlink;
   else
    for (n = ring->length - i; n-- > 0; )
     q = q->llink;
  }
  ((p) = Mem_alloc(((long)sizeof *(p)), "src/ring.c", 124));
  {
   p->llink = q->llink;
   q->llink->rlink = p;
   p->rlink = q;
   q->llink = p;
  }
  ring->length++;
  return p->value = x;
 }
}

canonical_original_code:
void *Ring_add(struct Ring_T *ring, int pos, void *x) {
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 105),0)));
 ((void)((pos >= -ring->length && pos<=ring->length+1)||(Except_raise(&(Assert_Failed), "src/ring.c", 106),0)));
 if (pos == 1 || pos == -ring->length)
  return Ring_addlo(ring, x);
 else if (pos == 0 || pos == ring->length + 1)
  return Ring_addhi(ring, x);
 else {
  struct node *p; struct node *q;
  int i = pos < 0 ? pos + ring->length : pos - 1;
  {
   int n;
   q = ring->head;
   if (i <= ring->length/2)
    for (n = i; n-- > 0; )
     q = q->rlink;
   else
    for (n = ring->length - i; n-- > 0; )
     q = q->llink;
  }
  ((p) = Mem_alloc(((long)sizeof *(p)), "src/ring.c", 124));
  {
   p->llink = q->llink;
   q->llink->rlink = p;
   p->rlink = q;
   q->llink = p;
  }
  ring->length++;
  return p->value = x;
 }
}

variable_types: pos int


original_code:
void *Ring_remove(Ring_T ring, int i) {
 void *x;
 struct node *q;
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 138),0)));
 ((void)((ring->length > 0)||(Except_raise(&(Assert_Failed), "src/ring.c", 139),0)));
 ((void)((i >= 0 && i < ring->length)||(Except_raise(&(Assert_Failed), "src/ring.c", 140),0)));
 {
  int n;
  q = ring->head;
  if (i <= ring->length/2)
   for (n = i; n-- > 0; )
    q = q->rlink;
  else
   for (n = ring->length - i; n-- > 0; )
    q = q->llink;
 }
 if (i == 0)
  ring->head = ring->head->rlink;
 x = q->value;
 q->llink->rlink = q->rlink;
 q->rlink->llink = q->llink;
 ((void)(Mem_free((q), "src/ring.c", 156), (q) = 0));
 if (--ring->length == 0)
  ring->head = ((void *)0);
 return x;
}

canonical_original_code:
void *Ring_remove(struct Ring_T *ring, int i) {
 void *x;
 struct node *q;
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 138),0)));
 ((void)((ring->length > 0)||(Except_raise(&(Assert_Failed), "src/ring.c", 139),0)));
 ((void)((i >= 0 && i < ring->length)||(Except_raise(&(Assert_Failed), "src/ring.c", 140),0)));
 {
  int n;
  q = ring->head;
  if (i <= ring->length/2)
   for (n = i; n-- > 0; )
    q = q->rlink;
  else
   for (n = ring->length - i; n-- > 0; )
    q = q->llink;
 }
 if (i == 0)
  ring->head = ring->head->rlink;
 x = q->value;
 q->llink->rlink = q->rlink;
 q->rlink->llink = q->llink;
 ((void)(Mem_free((q), "src/ring.c", 156), (q) = 0));
 if (--ring->length == 0)
  ring->head = ((void *)0);
 return x;
}


decompiled_code:
__int64 __fastcall Ring_remhi(__int64 a1)
{
_QWORD *v2; // rdi
__int64 v3; // rbp
_QWORD *v4; // rax
int v5; // eax

if ( !a1 )
Except_raise(&Assert_Failed, "src/ring.c", 164LL);
if ( *(int *)(a1 + 8) <= 0 )
Except_raise(&Assert_Failed, "src/ring.c", 165LL);
v2 = **(_QWORD ***)a1;
v3 = v2[2];
v4 = (_QWORD *)v2[1];
*(_QWORD *)(*v2 + 8LL) = v4;
*v4 = *v2;
Mem_free(v2, "src/ring.c", 170LL);
v5 = *(_DWORD *)(a1 + 8) - 1;
*(_DWORD *)(a1 + 8) = v5;
if ( !v5 )
*(_QWORD *)a1 = 0LL;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
_QWORD *v2; // rdi
__int64 v3; // rbp
_QWORD *v4; // rax
int v5; // eax

if ( !a1 )
Except_raise(&Assert_Failed, "src/ring.c", 164LL);
if ( *(int *)(a1 + 8) <= 0 )
Except_raise(&Assert_Failed, "src/ring.c", 165LL);
v2 = **(_QWORD ***)a1;
v3 = v2[2];
v4 = (_QWORD *)v2[1];
*(_QWORD *)(*v2 + 8LL) = v4;
*v4 = *v2;
Mem_free(v2, "src/ring.c", 170LL);
v5 = *(_DWORD *)(a1 + 8) - 1;
*(_DWORD *)(a1 + 8) = v5;
if ( !v5 )
*(_QWORD *)a1 = 0LL;
return v3;
}

original_code:
void *Ring_remhi(Ring_T ring) {
 void *x;
 struct node *q;
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 164),0)));
 ((void)((ring->length > 0)||(Except_raise(&(Assert_Failed), "src/ring.c", 165),0)));
 q = ring->head->llink;
 x = q->value;
 q->llink->rlink = q->rlink;
 q->rlink->llink = q->llink;
 ((void)(Mem_free((q), "src/ring.c", 170), (q) = 0));
 if (--ring->length == 0)
  ring->head = ((void *)0);
 return x;
}

canonical_original_code:
void *Ring_remhi(struct Ring_T *ring) {
 void *x;
 struct node *q;
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 164),0)));
 ((void)((ring->length > 0)||(Except_raise(&(Assert_Failed), "src/ring.c", 165),0)));
 q = ring->head->llink;
 x = q->value;
 q->llink->rlink = q->rlink;
 q->rlink->llink = q->llink;
 ((void)(Mem_free((q), "src/ring.c", 170), (q) = 0));
 if (--ring->length == 0)
  ring->head = ((void *)0);
 return x;
}


decompiled_code:
__int64 __fastcall Ring_remlo(int *a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/ring.c", 176LL);
if ( a1[2] <= 0 )
Except_raise(&Assert_Failed, "src/ring.c", 177LL);
*(_QWORD *)a1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
return Ring_remhi((__int64)a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/ring.c", 176LL);
if ( a1[2] <= 0 )
Except_raise(&Assert_Failed, "src/ring.c", 177LL);
*(_QWORD *)a1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
return func10((__int64)a1);
}

original_code:
void *Ring_remlo(Ring_T ring) {
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 176),0)));
 ((void)((ring->length > 0)||(Except_raise(&(Assert_Failed), "src/ring.c", 177),0)));
 ring->head = ring->head->rlink;
 return Ring_remhi(ring);
}

canonical_original_code:
void *Ring_remlo(struct Ring_T *ring) {
 ((void)((ring)||(Except_raise(&(Assert_Failed), "src/ring.c", 176),0)));
 ((void)((ring->length > 0)||(Except_raise(&(Assert_Failed), "src/ring.c", 177),0)));
 ring->head = ring->head->rlink;
 return Ring_remhi(ring);
}


cmpatom

decompiled_code:
_BOOL8 __fastcall cmpatom(__int64 a1, __int64 a2)
{
return a2 != a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1, __int64 a2)
{
return a2 != a1;
}

original_code:
static int cmpatom(const void *x, const void *y) {
 return x != y;
}

canonical_original_code:
static int cmpatom(void *x, void *y) {
 return x != y;
}

variable_types:
y
void *


original_code:
Table_T Table_new(int hint,
 int cmp(const void *x, const void *y),
 unsigned hash(const void *key)) {
 Table_T table;
 int i;
 static int primes[] = { 509, 509, 1021, 2053, 4093,
  8191, 16381, 32771, 65521, 0x7fffffff };
 ((void)((hint >= 0)||(Except_raise(&(Assert_Failed), "src/table.c", 33),0)));
 for (i = 1; primes[i] < hint; i++)
  ;
 table = Mem_alloc((sizeof (*table) + primes[i-1]*sizeof (table->buckets[0])), "src/table.c", 36);
 table->size = primes[i-1];
 table->cmp = cmp ? cmp : cmpatom;
 table->hash = hash ? hash : hashatom;
 table->buckets = (struct binding **)(table + 1);
 for (i = 0; i < table->size; i++)
  table->buckets[i] = ((void *)0);
 table->length = 0;
 table->timestamp = 0;
 return table;
}

canonical_original_code:
struct Table_T *Table_new(int hint, int cmp(void *x, void *y), unsigned int hash(void *key)) {
 struct Table_T *table;
 int i;
 static int primes[] = { 509, 509, 1021, 2053, 4093,
  8191, 16381, 32771, 65521, 0x7fffffff };
 ((void)((hint >= 0)||(Except_raise(&(Assert_Failed), "src/table.c", 33),0)));
 for (i = 1; primes[i] < hint; i++)
  ;
 table = Mem_alloc((sizeof (*table) + primes[i-1]*sizeof (table->buckets[0])), "src/table.c", 36);
 table->size = primes[i-1];
 table->cmp = cmp ? cmp : cmpatom;
 table->hash = hash ? hash : hashatom;
 table->buckets = (struct binding **)(table + 1);
 for (i = 0; i < table->size; i++)
  table->buckets[i] = ((void *)0);
 table->length = 0;
 table->timestamp = 0;
 return table;
}

variable_types: hint int

variable_types:
cmp
int (void *x, void *y)

variable_types:
hash
unsigned int (void *key)

variable_types: struct Table_T { int size; int (*cmp)(void *x, void *y); unsigned int (*hash)(void *key); int length; unsigned int timestamp; struct binding { struct binding *link; void *key; void *value; } **buckets; } *

variable_types:
primes
int []

user_defined_types: struct Table_T { int size; int (*cmp)(void *x, void *y); unsigned int (*hash)(void *key); int length; unsigned int timestamp; struct binding **buckets; }


decompiled_code:
__int64 __fastcall Table_get(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx

if ( !a1 )
Except_raise(&Assert_Failed, "src/table.c", 51LL);
if ( !a2 )
Except_raise(&Assert_Failed, "src/table.c", 52LL);
v2 = *(_QWORD **)(*(_QWORD *)(a1 + 32)
+ 8LL * (int)((*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)a1));
if ( !v2 )
return 0LL;
while ( (*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 8))(a2, v2[1]) )
{
v2 = (_QWORD *)*v2;
if ( !v2 )
return 0LL;
}
return v2[2];
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx

if ( !a1 )
Except_raise(&Assert_Failed, "src/table.c", 51LL);
if ( !a2 )
Except_raise(&Assert_Failed, "src/table.c", 52LL);
v2 = *(_QWORD **)(*(_QWORD *)(a1 + 32)
+ 8LL * (int)((*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)a1));
if ( !v2 )
return 0LL;
while ( (*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 8))(a2, v2[1]) )
{
v2 = (_QWORD *)*v2;
if ( !v2 )
return 0LL;
}
return v2[2];
}

original_code:
void *Table_get(Table_T table, const void *key) {
 int i;
 struct binding *p;
 ((void)((table)||(Except_raise(&(Assert_Failed), "src/table.c", 51),0)));
 ((void)((key)||(Except_raise(&(Assert_Failed), "src/table.c", 52),0)));
 i = (*table->hash)(key)%table->size;
 for (p = table->buckets[i]; p; p = p->link)
  if ((*table->cmp)(key, p->key) == 0)
   break;
 return p ? p->value : ((void *)0);
}

canonical_original_code:
void *Table_get(struct Table_T *table, void *key) {
 int i;
 struct binding *p;
 ((void)((table)||(Except_raise(&(Assert_Failed), "src/table.c", 51),0)));
 ((void)((key)||(Except_raise(&(Assert_Failed), "src/table.c", 52),0)));
 i = (*table->hash)(key)%table->size;
 for (p = table->buckets[i]; p; p = p->link)
  if ((*table->cmp)(key, p->key) == 0)
   break;
 return p ? p->value : ((void *)0);
}

variable_types:
key
void *

variable_types: struct binding { struct binding *link; void *key; void *value; } *


decompiled_code:
__int64 __fastcall Table_put(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r13
_QWORD *v5; // rbx
__int64 result; // rax

if ( !a1 )
Except_raise(&Assert_Failed, "src/table.c", 63LL);
if ( !a2 )
Except_raise(&Assert_Failed, "src/table.c", 64LL);
v4 = (int)((*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)a1);
v5 = *(_QWORD **)(*(_QWORD *)(a1 + 32) + 8 * v4);
if ( v5 )
{
while ( (*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 8))(a2, v5[1]) )
{
v5 = (_QWORD *)*v5;
if ( !v5 )
goto LABEL_8;
}
result = v5[2];
}
else
{
LABEL_8:
v5 = (_QWORD *)Mem_alloc(24LL, "src/table.c", 70LL);
v5[1] = a2;
*v5 = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v4);
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v4) = v5;
++*(_DWORD *)(a1 + 24);
result = 0LL;
}
v5[2] = a3;
++*(_DWORD *)(a1 + 28);
return result;
}

original_code:
void *Table_put(Table_T table, const void *key, void *value) {
 int i;
 struct binding *p;
 void *prev;
 ((void)((table)||(Except_raise(&(Assert_Failed), "src/table.c", 63),0)));
 ((void)((key)||(Except_raise(&(Assert_Failed), "src/table.c", 64),0)));
 i = (*table->hash)(key)%table->size;
 for (p = table->buckets[i]; p; p = p->link)
  if ((*table->cmp)(key, p->key) == 0)
   break;
 if (p == ((void *)0)) {
  ((p) = Mem_alloc(((long)sizeof *(p)), "src/table.c", 70));
  p->key = key;
  p->link = table->buckets[i];
  table->buckets[i] = p;
  table->length++;
  prev = ((void *)0);
 } else
  prev = p->value;
 p->value = value;
 table->timestamp++;
 return prev;
}

canonical_original_code:
void *Table_put(struct Table_T *table, void *key, void *value) {
 int i;
 struct binding *p;
 void *prev;
 ((void)((table)||(Except_raise(&(Assert_Failed), "src/table.c", 63),0)));
 ((void)((key)||(Except_raise(&(Assert_Failed), "src/table.c", 64),0)));
 i = (*table->hash)(key)%table->size;
 for (p = table->buckets[i]; p; p = p->link)
  if ((*table->cmp)(key, p->key) == 0)
   break;
 if (p == ((void *)0)) {
  ((p) = Mem_alloc(((long)sizeof *(p)), "src/table.c", 70));
  p->key = key;
  p->link = table->buckets[i];
  table->buckets[i] = p;
  table->length++;
  prev = ((void *)0);
 } else
  prev = p->value;
 p->value = value;
 table->timestamp++;
 return prev;
}

variable_types:
value
void *

user_defined_types: struct binding { struct binding *link; void *key; void *value; }


decompiled_code:
__int64 __fastcall Table_length(__int64 a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/table.c", 83LL);
return *(unsigned int *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/table.c", 83LL);
return *(unsigned int *)(a1 + 24);
}

original_code:
int Table_length(Table_T table) {
 ((void)((table)||(Except_raise(&(Assert_Failed), "src/table.c", 83),0)));
 return table->length;
}

canonical_original_code:
int Table_length(struct Table_T *table) {
 ((void)((table)||(Except_raise(&(Assert_Failed), "src/table.c", 83),0)));
 return table->length;
}


decompiled_code:
__int64 __fastcall Table_map(__int64 a1, __int64 (__fastcall *a2)(_QWORD, _QWORD *, __int64), __int64 a3)
{
int v4; // er14
__int64 v5; // r15
__int64 result; // rax
_QWORD *i; // rbx

if ( !a1 )
result = Except_raise(&Assert_Failed, "src/table.c", 92LL);
if ( !a2 )
result = Except_raise(&Assert_Failed, "src/table.c", 93LL);
v4 = *(_DWORD *)(a1 + 28);
if ( *(int *)a1 > 0 )
{
v5 = 0LL;
do
{
result = *(_QWORD *)(a1 + 32);
for ( i = *(_QWORD **)(result + 8 * v5); i; i = (_QWORD *)*i )
{
result = a2(i[1], i + 2, a3);
if ( *(_DWORD *)(a1 + 28) != v4 )
result = Except_raise(&Assert_Failed, "src/table.c", 98LL);
}
++v5;
}
while ( *(_DWORD *)a1 > (int)v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 (__fastcall *a2)(_QWORD, _QWORD *, __int64), __int64 a3)
{
int v4; // er14
__int64 v5; // r15
__int64 result; // rax
_QWORD *i; // rbx

if ( !a1 )
result = Except_raise(&Assert_Failed, "src/table.c", 92LL);
if ( !a2 )
result = Except_raise(&Assert_Failed, "src/table.c", 93LL);
v4 = *(_DWORD *)(a1 + 28);
if ( *(int *)a1 > 0 )
{
v5 = 0LL;
do
{
result = *(_QWORD *)(a1 + 32);
for ( i = *(_QWORD **)(result + 8 * v5); i; i = (_QWORD *)*i )
{
result = a2(i[1], i + 2, a3);
if ( *(_DWORD *)(a1 + 28) != v4 )
result = Except_raise(&Assert_Failed, "src/table.c", 98LL);
}
++v5;
}
while ( *(_DWORD *)a1 > (int)v5 );
}
return result;
}

original_code:
void Table_map(Table_T table,
 void apply(const void *key, void **value, void *cl),
 void *cl) {
 int i;
 unsigned stamp;
 struct binding *p;
 ((void)((table)||(Except_raise(&(Assert_Failed), "src/table.c", 92),0)));
 ((void)((apply)||(Except_raise(&(Assert_Failed), "src/table.c", 93),0)));
 stamp = table->timestamp;
 for (i = 0; i < table->size; i++)
  for (p = table->buckets[i]; p; p = p->link) {
   apply(p->key, &p->value, cl);
   ((void)((table->timestamp == stamp)||(Except_raise(&(Assert_Failed), "src/table.c", 98),0)));
  }
}

canonical_original_code:
void Table_map(struct Table_T *table, void apply(void *key, void **value, void *cl), void *cl) {
 int i;
 unsigned int stamp;
 struct binding *p;
 ((void)((table)||(Except_raise(&(Assert_Failed), "src/table.c", 92),0)));
 ((void)((apply)||(Except_raise(&(Assert_Failed), "src/table.c", 93),0)));
 stamp = table->timestamp;
 for (i = 0; i < table->size; i++)
  for (p = table->buckets[i]; p; p = p->link) {
   apply(p->key, &p->value, cl);
   ((void)((table->timestamp == stamp)||(Except_raise(&(Assert_Failed), "src/table.c", 98),0)));
  }
}

variable_types: void (void *key, void **value, void *cl)

variable_types:
cl
void *

variable_types:
stamp
unsigned int


partition

original_code:
int partition(int a[], int i, int j) {
 int v, k, t;
 j++;
 k = i;
 v = a[k];
 while (i < j) {
  i++; while (a[i] < v && i < j) i++;
  j--; while (a[j] > v ) j--;
  if (i < j) { t = a[i]; a[i] = a[j]; a[j] = t; }
 }
 t = a[k]; a[k] = a[j]; a[j] = t;
 return j;
}

canonical_original_code:
int partition(int a[], int i, int j) {
 int v; int k; int t;
 j++;
 k = i;
 v = a[k];
 while (i < j) {
  i++; while (a[i] < v && i < j) i++;
  j--; while (a[j] > v ) j--;
  if (i < j) { t = a[i]; a[i] = a[j]; a[j] = t; }
 }
 t = a[k]; a[k] = a[j]; a[j] = t;
 return j;
}

variable_types:
a
int []

variable_types: i int

variable_types: j int

variable_types: v int

variable_types: k int

variable_types: t int


sort

decompiled_code:
__int64 __fastcall sort(__int64 a1, int a2, int a3, __int64 a4)
{
__int64 v5; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+8h] [rbp-20h]
int v7; // [rsp+Ch] [rbp-1Ch]

if ( a3 > 2 )
cutoff = atoi(*(const char **)(a4 + 16));
v5 = a1;
v6 = 0;
v7 = a2 - 1;
quick((__int64)&v5);
return Thread_join(0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3, __int64 a4)
{
__int64 v5; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+8h] [rbp-20h]
int v7; // [rsp+Ch] [rbp-1Ch]

if ( a3 > 2 )
cutoff = atoi(*(const char **)(a4 + 16));
v5 = a1;
v6 = 0;
v7 = a2 - 1;
func2((__int64)&v5);
return Thread_join(0LL);
}

original_code:
void sort(int *x, int n, int argc, char *argv[]) {
 struct args args;
 if (argc >= 3)
  cutoff = atoi(argv[2]);
 args.a = x;
 args.lb = 0;
 args.ub = n - 1;
 quick(&args);
 Thread_join(((void *)0));
}

variable_types:
x
int *

variable_types: n int

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
args
struct args { int *a; int lb; }


cmpatom

variable_types:
x
void *

variable_types:
y
void *


original_code:
Set_T Set_new(int hint,
 int cmp(const void *x, const void *y),
 unsigned hash(const void *x)) {
 Set_T set;
 int i;
 static int primes[] = { 509, 509, 1021, 2053, 4093,
  8191, 16381, 32771, 65521, 0x7fffffff };
 ((void)((hint >= 0)||(Except_raise(&(Assert_Failed), "src/set.c", 54),0)));
 for (i = 1; primes[i] < hint; i++)
  ;
 set = Mem_alloc((sizeof (*set) + primes[i-1]*sizeof (set->buckets[0])), "src/set.c", 57);
 set->size = primes[i-1];
 set->cmp = cmp ? cmp : cmpatom;
 set->hash = hash ? hash : hashatom;
 set->buckets = (struct member **)(set + 1);
 for (i = 0; i < set->size; i++)
  set->buckets[i] = ((void *)0);
 set->length = 0;
 set->timestamp = 0;
 return set;
}

canonical_original_code:
struct Set_T *Set_new(int hint, int cmp(void *x, void *y), unsigned int hash(void *x)) {
 struct Set_T *set;
 int i;
 static int primes[] = { 509, 509, 1021, 2053, 4093,
  8191, 16381, 32771, 65521, 0x7fffffff };
 ((void)((hint >= 0)||(Except_raise(&(Assert_Failed), "src/set.c", 54),0)));
 for (i = 1; primes[i] < hint; i++)
  ;
 set = Mem_alloc((sizeof (*set) + primes[i-1]*sizeof (set->buckets[0])), "src/set.c", 57);
 set->size = primes[i-1];
 set->cmp = cmp ? cmp : cmpatom;
 set->hash = hash ? hash : hashatom;
 set->buckets = (struct member **)(set + 1);
 for (i = 0; i < set->size; i++)
  set->buckets[i] = ((void *)0);
 set->length = 0;
 set->timestamp = 0;
 return set;
}

variable_types: hint int

variable_types:
cmp
int (void *x, void *y)

variable_types:
hash
unsigned int (void *x)

variable_types: struct Set_T { int length; unsigned int timestamp; int (*cmp)(void *x, void *y); unsigned int (*hash)(void *x); int size; struct member { struct member *link; void *member; } **buckets; } *

variable_types:
primes
int []

user_defined_types: struct Set_T { int length; unsigned int timestamp; int (*cmp)(void *x, void *y); unsigned int (*hash)(void *x); int size; struct member **buckets; }


decompiled_code:
_BOOL8 __fastcall Set_member(__int64 a1, __int64 a2)
{
_QWORD *i; // rbx

if ( !a1 )
Except_raise(&Assert_Failed, "src/set.c", 72LL);
if ( !a2 )
Except_raise(&Assert_Failed, "src/set.c", 73LL);
for ( i = *(_QWORD **)(*(_QWORD *)(a1 + 32)
+ 8LL * (int)((*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)(a1 + 24)));
i;
i = (_QWORD *)*i )
{
if ( !(*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 8))(a2, i[1]) )
break;
}
return i != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, __int64 a2)
{
_QWORD *i; // rbx

if ( !a1 )
Except_raise(&Assert_Failed, "src/set.c", 72LL);
if ( !a2 )
Except_raise(&Assert_Failed, "src/set.c", 73LL);
for ( i = *(_QWORD **)(*(_QWORD *)(a1 + 32)
+ 8LL * (int)((*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)(a1 + 24)));
i;
i = (_QWORD *)*i )
{
if ( !(*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 8))(a2, i[1]) )
break;
}
return i != 0LL;
}

original_code:
int Set_member(Set_T set, const void *member) {
 int i;
 struct member *p;
 ((void)((set)||(Except_raise(&(Assert_Failed), "src/set.c", 72),0)));
 ((void)((member)||(Except_raise(&(Assert_Failed), "src/set.c", 73),0)));
 i = (*set->hash)(member)%set->size;
 for (p = set->buckets[i]; p; p = p->link)
  if ((*set->cmp)(member, p->member) == 0)
   break;
 return p != ((void *)0);
}

canonical_original_code:
int Set_member(struct Set_T *set, void *member) {
 int i;
 struct member *p;
 ((void)((set)||(Except_raise(&(Assert_Failed), "src/set.c", 72),0)));
 ((void)((member)||(Except_raise(&(Assert_Failed), "src/set.c", 73),0)));
 i = (*set->hash)(member)%set->size;
 for (p = set->buckets[i]; p; p = p->link)
  if ((*set->cmp)(member, p->member) == 0)
   break;
 return p != ((void *)0);
}

variable_types:
member
void *

variable_types: i int

variable_types: struct member { struct member *link; void *member; } *


decompiled_code:
__int64 __fastcall Set_length(unsigned int *a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/set.c", 118LL);
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1)
{
if ( !a1 )
Except_raise(&Assert_Failed, "src/set.c", 118LL);
return *a1;
}

original_code:
int Set_length(Set_T set) {
 ((void)((set)||(Except_raise(&(Assert_Failed), "src/set.c", 118),0)));
 return set->length;
}

canonical_original_code:
int Set_length(struct Set_T *set) {
 ((void)((set)||(Except_raise(&(Assert_Failed), "src/set.c", 118),0)));
 return set->length;
}

user_defined_types: struct member { struct member *link; void *member; }


decompiled_code:
__int64 __fastcall Set_map(__int64 a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3)
{
int v4; // er14
__int64 v5; // r15
__int64 result; // rax
_QWORD *i; // rbx

if ( !a1 )
result = Except_raise(&Assert_Failed, "src/set.c", 139LL);
if ( !a2 )
result = Except_raise(&Assert_Failed, "src/set.c", 140LL);
v4 = *(_DWORD *)(a1 + 4);
if ( *(int *)(a1 + 24) > 0 )
{
v5 = 0LL;
do
{
result = *(_QWORD *)(a1 + 32);
for ( i = *(_QWORD **)(result + 8 * v5); i; i = (_QWORD *)*i )
{
result = a2(i[1], a3);
if ( *(_DWORD *)(a1 + 4) != v4 )
result = Except_raise(&Assert_Failed, "src/set.c", 145LL);
}
++v5;
}
while ( *(_DWORD *)(a1 + 24) > (int)v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3)
{
int v4; // er14
__int64 v5; // r15
__int64 result; // rax
_QWORD *i; // rbx

if ( !a1 )
result = Except_raise(&Assert_Failed, "src/set.c", 139LL);
if ( !a2 )
result = Except_raise(&Assert_Failed, "src/set.c", 140LL);
v4 = *(_DWORD *)(a1 + 4);
if ( *(int *)(a1 + 24) > 0 )
{
v5 = 0LL;
do
{
result = *(_QWORD *)(a1 + 32);
for ( i = *(_QWORD **)(result + 8 * v5); i; i = (_QWORD *)*i )
{
result = a2(i[1], a3);
if ( *(_DWORD *)(a1 + 4) != v4 )
result = Except_raise(&Assert_Failed, "src/set.c", 145LL);
}
++v5;
}
while ( *(_DWORD *)(a1 + 24) > (int)v5 );
}
return result;
}

original_code:
void Set_map(Set_T set,
 void apply(const void *member, void *cl), void *cl) {
 int i;
 unsigned stamp;
 struct member *p;
 ((void)((set)||(Except_raise(&(Assert_Failed), "src/set.c", 139),0)));
 ((void)((apply)||(Except_raise(&(Assert_Failed), "src/set.c", 140),0)));
 stamp = set->timestamp;
 for (i = 0; i < set->size; i++)
  for (p = set->buckets[i]; p; p = p->link) {
   apply(p->member, cl);
   ((void)((set->timestamp == stamp)||(Except_raise(&(Assert_Failed), "src/set.c", 145),0)));
  }
}

canonical_original_code:
void Set_map(struct Set_T *set, void apply(void *member, void *cl), void *cl) {
 int i;
 unsigned int stamp;
 struct member *p;
 ((void)((set)||(Except_raise(&(Assert_Failed), "src/set.c", 139),0)));
 ((void)((apply)||(Except_raise(&(Assert_Failed), "src/set.c", 140),0)));
 stamp = set->timestamp;
 for (i = 0; i < set->size; i++)
  for (p = set->buckets[i]; p; p = p->link) {
   apply(p->member, cl);
   ((void)((set->timestamp == stamp)||(Except_raise(&(Assert_Failed), "src/set.c", 145),0)));
  }
}

variable_types:
apply
void (void *member, void *cl)

variable_types:
cl
void *

variable_types:
stamp
unsigned int


original_code:
Set_T Set_union(Set_T s, Set_T t) {
 if (s == ((void *)0)) {
  ((void)((t)||(Except_raise(&(Assert_Failed), "src/set.c", 162),0)));
  return copy(t, t->size);
 } else if (t == ((void *)0))
  return copy(s, s->size);
 else {
  Set_T set = copy(s, Arith_max(s->size, t->size));
  ((void)((s->cmp == t->cmp && s->hash == t->hash)||(Except_raise(&(Assert_Failed), "src/set.c", 168),0)));
  { int i;
    struct member *q;
    for (i = 0; i < t->size; i++)
     for (q = t->buckets[i]; q; q = q->link)
   Set_put(set, q->member);
  }
  return set;
 }
}

canonical_original_code:
struct Set_T *Set_union(struct Set_T *s, struct Set_T *t) {
 if (s == ((void *)0)) {
  ((void)((t)||(Except_raise(&(Assert_Failed), "src/set.c", 162),0)));
  return copy(t, t->size);
 } else if (t == ((void *)0))
  return copy(s, s->size);
 else {
  struct Set_T *set = copy(s, Arith_max(s->size, t->size));
  ((void)((s->cmp == t->cmp && s->hash == t->hash)||(Except_raise(&(Assert_Failed), "src/set.c", 168),0)));
  { int i;
    struct member *q;
    for (i = 0; i < t->size; i++)
     for (q = t->buckets[i]; q; q = q->link)
   Set_put(set, q->member);
  }
  return set;
 }
}

variable_types:
s
struct Set_T *

variable_types:
t
struct Set_T *

return_type: struct Set_T { int length; unsigned int timestamp; int (*cmp)(void *x, void *y); unsigned int (*hash)(void *x); int size; struct member { struct member *link; void *member; } **buckets; } *


original_code:
Set_T Set_inter(Set_T s, Set_T t) {
 if (s == ((void *)0)) {
  ((void)((t)||(Except_raise(&(Assert_Failed), "src/set.c", 180),0)));
  return Set_new(t->size, t->cmp, t->hash);
 } else if (t == ((void *)0))
  return Set_new(s->size, s->cmp, s->hash);
 else if (s->length < t->length)
  return Set_inter(t, s);
 else {
  Set_T set = Set_new(Arith_min(s->size, t->size),
   s->cmp, s->hash);
  ((void)((s->cmp == t->cmp && s->hash == t->hash)||(Except_raise(&(Assert_Failed), "src/set.c", 189),0)));
  { int i;
    struct member *q;
    for (i = 0; i < t->size; i++)
     for (q = t->buckets[i]; q; q = q->link)
   if (Set_member(s, q->member))
    {
     struct member *p;
     const void *member = q->member;
     int i = (*set->hash)(member)%set->size;
     ((p) = Mem_alloc(((long)sizeof *(p)), "src/set.c", 199));
     p->member = member;
     p->link = set->buckets[i];
     set->buckets[i] = p;
     set->length++;
    }
  }
  return set;
 }
}

canonical_original_code:
struct Set_T *Set_inter(struct Set_T *s, struct Set_T *t) {
 if (s == ((void *)0)) {
  ((void)((t)||(Except_raise(&(Assert_Failed), "src/set.c", 180),0)));
  return Set_new(t->size, t->cmp, t->hash);
 } else if (t == ((void *)0))
  return Set_new(s->size, s->cmp, s->hash);
 else if (s->length < t->length)
  return Set_inter(t, s);
 else {
  struct Set_T *set = Set_new(Arith_min(s->size, t->size),
   s->cmp, s->hash);
  ((void)((s->cmp == t->cmp && s->hash == t->hash)||(Except_raise(&(Assert_Failed), "src/set.c", 189),0)));
  { int i;
    struct member *q;
    for (i = 0; i < t->size; i++)
     for (q = t->buckets[i]; q; q = q->link)
   if (Set_member(s, q->member))
    {
     struct member *p;
     void *member = q->member;
     int i = (*set->hash)(member)%set->size;
     ((p) = Mem_alloc(((long)sizeof *(p)), "src/set.c", 199));
     p->member = member;
     p->link = set->buckets[i];
     set->buckets[i] = p;
     set->length++;
    }
  }
  return set;
 }
}


original_code:
Set_T Set_minus(Set_T t, Set_T s) {
 if (t == ((void *)0)){
  ((void)((s)||(Except_raise(&(Assert_Failed), "src/set.c", 211),0)));
  return Set_new(s->size, s->cmp, s->hash);
 } else if (s == ((void *)0))
  return copy(t, t->size);
 else {
  Set_T set = Set_new(Arith_min(s->size, t->size),
   s->cmp, s->hash);
  ((void)((s->cmp == t->cmp && s->hash == t->hash)||(Except_raise(&(Assert_Failed), "src/set.c", 218),0)));
  { int i;
    struct member *q;
    for (i = 0; i < t->size; i++)
     for (q = t->buckets[i]; q; q = q->link)
   if (!Set_member(s, q->member))
    {
     struct member *p;
     const void *member = q->member;
     int i = (*set->hash)(member)%set->size;
     ((p) = Mem_alloc(((long)sizeof *(p)), "src/set.c", 228));
     p->member = member;
     p->link = set->buckets[i];
     set->buckets[i] = p;
     set->length++;
    }
  }
  return set;
 }
}

canonical_original_code:
struct Set_T *Set_minus(struct Set_T *t, struct Set_T *s) {
 if (t == ((void *)0)){
  ((void)((s)||(Except_raise(&(Assert_Failed), "src/set.c", 211),0)));
  return Set_new(s->size, s->cmp, s->hash);
 } else if (s == ((void *)0))
  return copy(t, t->size);
 else {
  struct Set_T *set = Set_new(Arith_min(s->size, t->size),
   s->cmp, s->hash);
  ((void)((s->cmp == t->cmp && s->hash == t->hash)||(Except_raise(&(Assert_Failed), "src/set.c", 218),0)));
  { int i;
    struct member *q;
    for (i = 0; i < t->size; i++)
     for (q = t->buckets[i]; q; q = q->link)
   if (!Set_member(s, q->member))
    {
     struct member *p;
     void *member = q->member;
     int i = (*set->hash)(member)%set->size;
     ((p) = Mem_alloc(((long)sizeof *(p)), "src/set.c", 228));
     p->member = member;
     p->link = set->buckets[i];
     set->buckets[i] = p;
     set->length++;
    }
  }
  return set;
 }
}


original_code:
Set_T Set_diff(Set_T s, Set_T t) {
 if (s == ((void *)0)) {
  ((void)((t)||(Except_raise(&(Assert_Failed), "src/set.c", 240),0)));
  return copy(t, t->size);
 } else if (t == ((void *)0))
  return copy(s, s->size);
 else {
  Set_T set = Set_new(Arith_min(s->size, t->size),
   s->cmp, s->hash);
  ((void)((s->cmp == t->cmp && s->hash == t->hash)||(Except_raise(&(Assert_Failed), "src/set.c", 247),0)));
  { int i;
    struct member *q;
    for (i = 0; i < t->size; i++)
     for (q = t->buckets[i]; q; q = q->link)
   if (!Set_member(s, q->member))
    {
     struct member *p;
     const void *member = q->member;
     int i = (*set->hash)(member)%set->size;
     ((p) = Mem_alloc(((long)sizeof *(p)), "src/set.c", 257));
     p->member = member;
     p->link = set->buckets[i];
     set->buckets[i] = p;
     set->length++;
    }
  }
  { Set_T u = t; t = s; s = u; }
  { int i;
    struct member *q;
    for (i = 0; i < t->size; i++)
     for (q = t->buckets[i]; q; q = q->link)
   if (!Set_member(s, q->member))
    {
     struct member *p;
     const void *member = q->member;
     int i = (*set->hash)(member)%set->size;
     ((p) = Mem_alloc(((long)sizeof *(p)), "src/set.c", 274));
     p->member = member;
     p->link = set->buckets[i];
     set->buckets[i] = p;
     set->length++;
    }
  }
  return set;
 }
}

canonical_original_code:
struct Set_T *Set_diff(struct Set_T *s, struct Set_T *t) {
 if (s == ((void *)0)) {
  ((void)((t)||(Except_raise(&(Assert_Failed), "src/set.c", 240),0)));
  return copy(t, t->size);
 } else if (t == ((void *)0))
  return copy(s, s->size);
 else {
  struct Set_T *set = Set_new(Arith_min(s->size, t->size),
   s->cmp, s->hash);
  ((void)((s->cmp == t->cmp && s->hash == t->hash)||(Except_raise(&(Assert_Failed), "src/set.c", 247),0)));
  { int i;
    struct member *q;
    for (i = 0; i < t->size; i++)
     for (q = t->buckets[i]; q; q = q->link)
   if (!Set_member(s, q->member))
    {
     struct member *p;
     void *member = q->member;
     int i = (*set->hash)(member)%set->size;
     ((p) = Mem_alloc(((long)sizeof *(p)), "src/set.c", 257));
     p->member = member;
     p->link = set->buckets[i];
     set->buckets[i] = p;
     set->length++;
    }
  }
  { struct Set_T *u = t; t = s; s = u; }
  { int i;
    struct member *q;
    for (i = 0; i < t->size; i++)
     for (q = t->buckets[i]; q; q = q->link)
   if (!Set_member(s, q->member))
    {
     struct member *p;
     void *member = q->member;
     int i = (*set->hash)(member)%set->size;
     ((p) = Mem_alloc(((long)sizeof *(p)), "src/set.c", 274));
     p->member = member;
     p->link = set->buckets[i];
     set->buckets[i] = p;
     set->length++;
    }
  }
  return set;
 }
}


copy

original_code:
static Set_T copy(Set_T t, int hint) {
 Set_T set;
 ((void)((t)||(Except_raise(&(Assert_Failed), "src/set.c", 28),0)));
 set = Set_new(hint, t->cmp, t->hash);
 { int i;
   struct member *q;
   for (i = 0; i < t->size; i++)
    for (q = t->buckets[i]; q; q = q->link)
  {
   struct member *p;
   const void *member = q->member;
   int i = (*set->hash)(member)%set->size;
   ((p) = Mem_alloc(((long)sizeof *(p)), "src/set.c", 38));
   p->member = member;
   p->link = set->buckets[i];
   set->buckets[i] = p;
   set->length++;
  }
 }
 return set;
}

canonical_original_code:
static struct Set_T *copy(struct Set_T *t, int hint) {
 struct Set_T *set;
 ((void)((t)||(Except_raise(&(Assert_Failed), "src/set.c", 28),0)));
 set = Set_new(hint, t->cmp, t->hash);
 { int i;
   struct member *q;
   for (i = 0; i < t->size; i++)
    for (q = t->buckets[i]; q; q = q->link)
  {
   struct member *p;
   void *member = q->member;
   int i = (*set->hash)(member)%set->size;
   ((p) = Mem_alloc(((long)sizeof *(p)), "src/set.c", 38));
   p->member = member;
   p->link = set->buckets[i];
   set->buckets[i] = p;
   set->length++;
  }
 }
 return set;
}


cmpint

decompiled_code:
__int64 __fastcall cmpint(const void *a1, const void *a2)
{
int v2; // ecx
int v3; // edx
__int64 result; // rax

v2 = **(_DWORD **)a1;
v3 = **(_DWORD **)a2;
result = 0xFFFFFFFFLL;
if ( v2 >= v3 )
result = v2 > v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
int v2; // ecx
int v3; // edx
__int64 result; // rax

v2 = **(_DWORD **)a1;
v3 = **(_DWORD **)a2;
result = 0xFFFFFFFFLL;
if ( v2 >= v3 )
result = v2 > v3;
return result;
}

original_code:
int cmpint(const void *x, const void *y) {
 if (**(int **)x < **(int **)y)
  return -1;
 else if (**(int **)x > **(int **)y)
  return +1;
 else
  return 0;
}

canonical_original_code:
int cmpint(void *x, void *y) {
 if (**(int **)x < **(int **)y)
  return -1;
 else if (**(int **)x > **(int **)y)
  return +1;
 else
  return 0;
}


intcmp

decompiled_code:
__int64 __fastcall intcmp(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+0h] [rbp-10h] BYREF
__int64 v4; // [rsp+8h] [rbp-8h] BYREF

v4 = a1;
v3 = a2;
return cmpint(&v4, &v3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+0h] [rbp-10h] BYREF
__int64 v4; // [rsp+8h] [rbp-8h] BYREF

v4 = a1;
v3 = a2;
return func0(&v4, &v3);
}

original_code:
int intcmp(const void *x, const void *y) {
 return cmpint(&x, &y);
}

canonical_original_code:
int intcmp(void *x, void *y) {
 return cmpint(&x, &y);
}


inthash

decompiled_code:
__int64 __fastcall inthash(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1)
{
return *a1;
}

original_code:
unsigned inthash(const void *x) {
 return *(int *)x;
}

canonical_original_code:
unsigned int inthash(void *x) {
 return *(int *)x;
}

return_type: unsigned int


compare

decompiled_code:
int __fastcall compare(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func3(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
int compare(const void *x, const void *y) {
 return strcmp(*(char **)x, *(char **)y);
}

canonical_original_code:
int compare(void *x, void *y) {
 return strcmp(*(char **)x, *(char **)y);
}


first

original_code:
int first(int c) {
 if (c == '\n')
  linenum++;
 return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha) || c == '_';
}

canonical_original_code:
int first(int c) {
 if (c == '\n')
  linenum++;
 return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha) || c == '_';
}

variable_types: c int


rest

decompiled_code:
_BOOL8 __fastcall rest(int a1)
{
unsigned __int16 v1; // dx
_BOOL8 result; // rax

v1 = (*_ctype_b_loc())[a1];
result = 1LL;
if ( a1 != 95 )
result = (v1 & 0xC00) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(int a1)
{
unsigned __int16 v1; // dx
_BOOL8 result; // rax

v1 = (*_ctype_b_loc())[a1];
result = 1LL;
if ( a1 != 95 )
result = (v1 & 0xC00) != 0;
return result;
}

original_code:
int rest(int c) {
 return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha) || c == '_' || ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit);
}

canonical_original_code:
int rest(int c) {
 return ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha) || c == '_' || ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit);
}


find

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

for ( result = *(__int64 *)((char *)&htab + (a1 & 0x3FF8)); result; result = *(_QWORD *)(result + 8) )
{
if ( *(_QWORD *)(result + 16) == a1 )
break;
}
return result;
}

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

for ( result = *(__int64 *)((char *)&htab + (a1 & 0x3FF8)); result; result = *(_QWORD *)(result + 8) )
{
if ( *(_QWORD *)(result + 16) == a1 )
break;
}
return result;
}

original_code:
static struct descriptor *find(const void *ptr) {
 struct descriptor *bp = htab[(((unsigned long)(ptr)>>3) & (sizeof (htab)/sizeof ((htab)[0])-1))];
 while (bp && bp->ptr != ptr)
  bp = bp->link;
 return bp;
}

canonical_original_code:
static struct descriptor *find(void *ptr) {
 struct descriptor *bp = htab[(((unsigned long)(ptr)>>3) & (sizeof (htab)/sizeof ((htab)[0])-1))];
 while (bp && bp->ptr != ptr)
  bp = bp->link;
 return bp;
}

variable_types:
ptr
void *

variable_types: struct descriptor { struct descriptor *free; struct descriptor *link; void *ptr; long size; char *file; int line; } *


decompiled_code:
void __fastcall Mem_free(__int64 a1, __int64 a2, unsigned int a3)
{
_QWORD *v3; // rbp
_QWORD *v5; // rax

if ( a1 )
{
if ( (a1 & 0xF) != 0 || (v5 = (_QWORD *)find(a1), (v3 = v5) == 0LL) || *v5 )
Except_raise(&Assert_Failed, a2, a3);
*v3 = freelist;
freelist = v3;
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, unsigned int a3)
{
_QWORD *v3; // rbp
_QWORD *v5; // rax

if ( a1 )
{
if ( (a1 & 0xF) != 0 || (v5 = (_QWORD *)func0(a1), (v3 = v5) == 0LL) || *v5 )
Except_raise(&Assert_Failed, a2, a3);
*v3 = freelist;
freelist = v3;
}
}

original_code:
void Mem_free(void *ptr, const char *file, int line) {
 if (ptr) {
  struct descriptor *bp;
  if (((unsigned long)ptr)%(sizeof (union align)) != 0
  || (bp = find(ptr)) == ((void *)0) || bp->free)
   Except_raise(&Assert_Failed, file, line);
  bp->free = freelist.free;
  freelist.free = bp;
 }
}

canonical_original_code:
void Mem_free(void *ptr, char *file, int line) {
 if (ptr) {
  struct descriptor *bp;
  if (((unsigned long)ptr)%(sizeof (union align)) != 0
  || (bp = find(ptr)) == ((void *)0) || bp->free)
   Except_raise(&Assert_Failed, file, line);
  bp->free = freelist.free;
  freelist.free = bp;
 }
}

variable_types:
file
char *

variable_types: line int

user_defined_types: union align { int i; long l; long *lp; void *p; void (*fp)(); float f; double d; long double ld; }

user_defined_types: struct descriptor { struct descriptor *free; struct descriptor *link; void *ptr; long size; char *file; int line; }


decompiled_code:
unsigned __int64 __fastcall Mem_alloc(__int64 a1, __int64 a2, unsigned int a3)
{
_QWORD *v3; // r14
__int64 v5; // r12
void **v6; // rbx
void *v7; // rbp
unsigned __int64 v8; // rbp
__int64 v9; // rbp
void *v10; // rdi
__int64 v11; // rax
size_t size; // [rsp+8h] [rbp-40h]

if ( a1 <= 0 )
Except_raise(&Assert_Failed, "src/memchk.c", 97LL);
v5 = (a1 + 15) & 0xFFFFFFFFFFFFFFF0LL;
v6 = (void **)freelist;
if ( !freelist )
{
LABEL_19:
Except_raise(&Assert_Failed, "src/memchk.c", 132LL);
return 0LL;
}
size = v5 + 4096;
while ( 1 )
{
v9 = (__int64)v6[3];
if ( v9 > v5 )
break;
if ( v6 == &freelist )
{
v10 = malloc(size);
if ( !v10 || (v3 = dalloc((__int64)v10, size, (__int64)"src/memchk.c", 121)) == 0LL )
{
if ( a2 )
Except_raise(&Mem_Failed, a2, a3);
else
Except_raise(&Mem_Failed, "src/memchk.c", 124LL);
}
*v3 = freelist;
freelist = v3;
v6 = (void **)*v6;
}
else
{
LABEL_8:
v6 = (void **)*v6;
if ( !v6 )
goto LABEL_19;
}
}
v7 = (void *)(v9 - v5);
v6[3] = v7;
v8 = (unsigned __int64)v7 + (_QWORD)v6[2];
v6 = (void **)dalloc(v8, v5, a2, a3);
if ( !v6 )
{
if ( a2 )
Except_raise(&Mem_Failed, a2, a3);
else
Except_raise(&Mem_Failed, "src/memchk.c", 112LL);
goto LABEL_8;
}
v11 = (v8 >> 3) & 0x7FF;
v6[1] = (void *)htab[v11];
htab[v11] = (__int64)v6;
return v8;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3)
{
_QWORD *v3; // r14
__int64 v5; // r12
void **v6; // rbx
void *v7; // rbp
unsigned __int64 v8; // rbp
__int64 v9; // rbp
void *v10; // rdi
__int64 v11; // rax
size_t size; // [rsp+8h] [rbp-40h]

if ( a1 <= 0 )
Except_raise(&Assert_Failed, "src/memchk.c", 97LL);
v5 = (a1 + 15) & 0xFFFFFFFFFFFFFFF0LL;
v6 = (void **)freelist;
if ( !freelist )
{
LABEL_19:
Except_raise(&Assert_Failed, "src/memchk.c", 132LL);
return 0LL;
}
size = v5 + 4096;
while ( 1 )
{
v9 = (__int64)v6[3];
if ( v9 > v5 )
break;
if ( v6 == &freelist )
{
v10 = malloc(size);
if ( !v10 || (v3 = dalloc((__int64)v10, size, (__int64)"src/memchk.c", 121)) == 0LL )
{
if ( a2 )
Except_raise(&Mem_Failed, a2, a3);
else
Except_raise(&Mem_Failed, "src/memchk.c", 124LL);
}
*v3 = freelist;
freelist = v3;
v6 = (void **)*v6;
}
else
{
LABEL_8:
v6 = (void **)*v6;
if ( !v6 )
goto LABEL_19;
}
}
v7 = (void *)(v9 - v5);
v6[3] = v7;
v8 = (unsigned __int64)v7 + (_QWORD)v6[2];
v6 = (void **)dalloc(v8, v5, a2, a3);
if ( !v6 )
{
if ( a2 )
Except_raise(&Mem_Failed, a2, a3);
else
Except_raise(&Mem_Failed, "src/memchk.c", 112LL);
goto LABEL_8;
}
v11 = (v8 >> 3) & 0x7FF;
v6[1] = (void *)htab[v11];
htab[v11] = (__int64)v6;
return v8;
}

original_code:
void *Mem_alloc(long nbytes, const char *file, int line){
 struct descriptor *bp;
 void *ptr;
 ((void)((nbytes > 0)||(Except_raise(&(Assert_Failed), "src/memchk.c", 97),0)));
 nbytes = ((nbytes + sizeof (union align) - 1)/
  (sizeof (union align)))*(sizeof (union align));
 for (bp = freelist.free; bp; bp = bp->free) {
  if (bp->size > nbytes) {
   bp->size -= nbytes;
   ptr = (char *)bp->ptr + bp->size;
   if ((bp = dalloc(ptr, nbytes, file, line)) != ((void *)0)) {
    unsigned h = (((unsigned long)(ptr)>>3) & (sizeof (htab)/sizeof ((htab)[0])-1));
    bp->link = htab[h];
    htab[h] = bp;
    return ptr;
   } else
    {
     if (file == ((void *)0))
      Except_raise(&(Mem_Failed), "src/memchk.c", 112);
     else
      Except_raise(&Mem_Failed, file, line);
    }
  }
  if (bp == &freelist) {
   struct descriptor *newptr;
   if ((ptr = malloc(nbytes + ((4096 + sizeof (union align) - 1)/ (sizeof (union align)))*(sizeof (union align)))) == ((void *)0)
   || (newptr = dalloc(ptr, nbytes + ((4096 + sizeof (union align) - 1)/ (sizeof (union align)))*(sizeof (union align)),
     "src/memchk.c", 121)) == ((void *)0))
    {
     if (file == ((void *)0))
      Except_raise(&(Mem_Failed), "src/memchk.c", 124);
     else
      Except_raise(&Mem_Failed, file, line);
    }
   newptr->free = freelist.free;
   freelist.free = newptr;
  }
 }
 ((void)((0)||(Except_raise(&(Assert_Failed), "src/memchk.c", 132),0)));
 return ((void *)0);
}

canonical_original_code:
void *Mem_alloc(long nbytes, char *file, int line){
 struct descriptor *bp;
 void *ptr;
 ((void)((nbytes > 0)||(Except_raise(&(Assert_Failed), "src/memchk.c", 97),0)));
 nbytes = ((nbytes + sizeof (union align) - 1)/
  (sizeof (union align)))*(sizeof (union align));
 for (bp = freelist.free; bp; bp = bp->free) {
  if (bp->size > nbytes) {
   bp->size -= nbytes;
   ptr = (char *)bp->ptr + bp->size;
   if ((bp = dalloc(ptr, nbytes, file, line)) != ((void *)0)) {
    unsigned int h = (((unsigned long)(ptr)>>3) & (sizeof (htab)/sizeof ((htab)[0])-1));
    bp->link = htab[h];
    htab[h] = bp;
    return ptr;
   } else
    {
     if (file == ((void *)0))
      Except_raise(&(Mem_Failed), "src/memchk.c", 112);
     else
      Except_raise(&Mem_Failed, file, line);
    }
  }
  if (bp == &freelist) {
   struct descriptor *newptr;
   if ((ptr = malloc(nbytes + ((4096 + sizeof (union align) - 1)/ (sizeof (union align)))*(sizeof (union align)))) == ((void *)0)
   || (newptr = dalloc(ptr, nbytes + ((4096 + sizeof (union align) - 1)/ (sizeof (union align)))*(sizeof (union align)),
     "src/memchk.c", 121)) == ((void *)0))
    {
     if (file == ((void *)0))
      Except_raise(&(Mem_Failed), "src/memchk.c", 124);
     else
      Except_raise(&Mem_Failed, file, line);
    }
   newptr->free = freelist.free;
   freelist.free = newptr;
  }
 }
 ((void)((0)||(Except_raise(&(Assert_Failed), "src/memchk.c", 132),0)));
 return ((void *)0);
}

variable_types: nbytes long

variable_types:
h
unsigned int


decompiled_code:
void *__fastcall Mem_resize(void *src, __int64 a2, __int64 a3, unsigned int a4)
{
_QWORD *v4; // r15
size_t v5; // rbx
void *v8; // rax
void *v9; // r14
_QWORD *v11; // rax

v5 = a2;
if ( src )
{
if ( a2 > 0 )
goto LABEL_3;
}
else
{
Except_raise(&Assert_Failed, "src/memchk.c", 56LL);
if ( a2 > 0 )
goto LABEL_9;
}
Except_raise(&Assert_Failed, "src/memchk.c", 57LL);
LABEL_3:
if ( ((unsigned __int8)src & 0xF) != 0 )
{
LABEL_4:
Except_raise(&Assert_Failed, a3, a4);
goto LABEL_5;
}
LABEL_9:
v11 = (_QWORD *)find((__int64)src);
v4 = v11;
if ( !v11 || *v11 )
goto LABEL_4;
LABEL_5:
v8 = (void *)Mem_alloc(a2, a3, a4);
v9 = v8;
if ( v4[3] <= a2 )
v5 = v4[3];
memcpy(v8, src, v5);
Mem_free((__int64)src, a3, a4);
return v9;
}

canonical_decompiled_code:
void *__fastcall func3(void *src, __int64 a2, __int64 a3, unsigned int a4)
{
_QWORD *v4; // r15
size_t v5; // rbx
void *v8; // rax
void *v9; // r14
_QWORD *v11; // rax

v5 = a2;
if ( src )
{
if ( a2 > 0 )
goto LABEL_3;
}
else
{
Except_raise(&Assert_Failed, "src/memchk.c", 56LL);
if ( a2 > 0 )
goto LABEL_9;
}
Except_raise(&Assert_Failed, "src/memchk.c", 57LL);
LABEL_3:
if ( ((unsigned __int8)src & 0xF) != 0 )
{
LABEL_4:
Except_raise(&Assert_Failed, a3, a4);
goto LABEL_5;
}
LABEL_9:
v11 = (_QWORD *)func0((__int64)src);
v4 = v11;
if ( !v11 || *v11 )
goto LABEL_4;
LABEL_5:
v8 = (void *)func2(a2, a3, a4);
v9 = v8;
if ( v4[3] <= a2 )
v5 = v4[3];
memcpy(v8, src, v5);
func1((__int64)src, a3, a4);
return v9;
}

original_code:
void *Mem_resize(void *ptr, long nbytes,
 const char *file, int line) {
 struct descriptor *bp;
 void *newptr;
 ((void)((ptr)||(Except_raise(&(Assert_Failed), "src/memchk.c", 56),0)));
 ((void)((nbytes > 0)||(Except_raise(&(Assert_Failed), "src/memchk.c", 57),0)));
 if (((unsigned long)ptr)%(sizeof (union align)) != 0
 || (bp = find(ptr)) == ((void *)0) || bp->free)
  Except_raise(&Assert_Failed, file, line);
 newptr = Mem_alloc(nbytes, file, line);
 memcpy(newptr, ptr,
  nbytes < bp->size ? nbytes : bp->size);
 Mem_free(ptr, file, line);
 return newptr;
}

canonical_original_code:
void *Mem_resize(void *ptr, long nbytes, char *file, int line) {
 struct descriptor *bp;
 void *newptr;
 ((void)((ptr)||(Except_raise(&(Assert_Failed), "src/memchk.c", 56),0)));
 ((void)((nbytes > 0)||(Except_raise(&(Assert_Failed), "src/memchk.c", 57),0)));
 if (((unsigned long)ptr)%(sizeof (union align)) != 0
 || (bp = find(ptr)) == ((void *)0) || bp->free)
  Except_raise(&Assert_Failed, file, line);
 newptr = Mem_alloc(nbytes, file, line);
 memcpy(newptr, ptr,
  nbytes < bp->size ? nbytes : bp->size);
 Mem_free(ptr, file, line);
 return newptr;
}

variable_types:
newptr
void *


decompiled_code:
void *__fastcall Mem_calloc(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
void *v6; // rax

if ( a1 <= 0 )
Except_raise(&Assert_Failed, "src/memchk.c", 70LL);
if ( a2 <= 0 )
Except_raise(&Assert_Failed, "src/memchk.c", 71LL);
v6 = (void *)Mem_alloc(a2 * a1, a3, a4);
return memset(v6, 0, a2 * a1);
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
void *v6; // rax

if ( a1 <= 0 )
Except_raise(&Assert_Failed, "src/memchk.c", 70LL);
if ( a2 <= 0 )
Except_raise(&Assert_Failed, "src/memchk.c", 71LL);
v6 = (void *)func2(a2 * a1, a3, a4);
return memset(v6, 0, a2 * a1);
}

original_code:
void *Mem_calloc(long count, long nbytes,
 const char *file, int line) {
 void *ptr;
 ((void)((count > 0)||(Except_raise(&(Assert_Failed), "src/memchk.c", 70),0)));
 ((void)((nbytes > 0)||(Except_raise(&(Assert_Failed), "src/memchk.c", 71),0)));
 ptr = Mem_alloc(count*nbytes, file, line);
 memset(ptr, '\0', count*nbytes);
 return ptr;
}

canonical_original_code:
void *Mem_calloc(long count, long nbytes, char *file, int line) {
 void *ptr;
 ((void)((count > 0)||(Except_raise(&(Assert_Failed), "src/memchk.c", 70),0)));
 ((void)((nbytes > 0)||(Except_raise(&(Assert_Failed), "src/memchk.c", 71),0)));
 ptr = Mem_alloc(count*nbytes, file, line);
 memset(ptr, '\0', count*nbytes);
 return ptr;
}

variable_types: count long


decompiled_code:
__int64 Chan_new()
{
__int64 v0; // rbx

v0 = Mem_alloc(64LL, "src/chan.c", 15LL);
Sem_init(v0 + 16, 1LL);
Sem_init(v0 + 32, 0LL);
Sem_init(v0 + 48, 0LL);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx

v0 = Mem_alloc(64LL, "src/chan.c", 15LL);
Sem_init(v0 + 16, 1LL);
Sem_init(v0 + 32, 0LL);
Sem_init(v0 + 48, 0LL);
return v0;
}

original_code:
Chan_T Chan_new(void) {
 Chan_T c;
 ((c) = Mem_alloc(((long)sizeof *(c)), "src/chan.c", 15));
 Sem_init(&c->send, 1);
 Sem_init(&c->recv, 0);
 Sem_init(&c->sync, 0);
 return c;
}

canonical_original_code:
struct Chan_T *Chan_new() {
 struct Chan_T *c;
 ((c) = Mem_alloc(((long)sizeof *(c)), "src/chan.c", 15));
 Sem_init(&c->send, 1);
 Sem_init(&c->recv, 0);
 Sem_init(&c->sync, 0);
 return c;
}

variable_types: struct Chan_T { void *ptr; int *size; struct Sem_T { int count; void *queue; } send; } *

user_defined_types: struct Chan_T { void *ptr; int *size; struct Sem_T send; }


decompiled_code:
__int64 __fastcall Chan_send(_QWORD *a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = a3;
if ( !a1 )
Except_raise(&Assert_Failed, "src/chan.c", 22LL);
if ( !a2 )
Except_raise(&Assert_Failed, "src/chan.c", 23LL);
if ( (v4 & 0x80000000) != 0 )
Except_raise(&Assert_Failed, "src/chan.c", 24LL);
Sem_wait(a1 + 2);
*a1 = a2;
a1[1] = &v4;
Sem_signal(a1 + 4);
Sem_wait(a1 + 6);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = a3;
if ( !a1 )
Except_raise(&Assert_Failed, "src/chan.c", 22LL);
if ( !a2 )
Except_raise(&Assert_Failed, "src/chan.c", 23LL);
if ( (v4 & 0x80000000) != 0 )
Except_raise(&Assert_Failed, "src/chan.c", 24LL);
Sem_wait(a1 + 2);
*a1 = a2;
a1[1] = &v4;
Sem_signal(a1 + 4);
Sem_wait(a1 + 6);
return v4;
}

original_code:
int Chan_send(Chan_T c, const void *ptr, int size) {
 ((void)((c)||(Except_raise(&(Assert_Failed), "src/chan.c", 22),0)));
 ((void)((ptr)||(Except_raise(&(Assert_Failed), "src/chan.c", 23),0)));
 ((void)((size >= 0)||(Except_raise(&(Assert_Failed), "src/chan.c", 24),0)));
 Sem_wait(&c->send);
 c->ptr = ptr;
 c->size = &size;
 Sem_signal(&c->recv);
 Sem_wait(&c->sync);
 return size;
}

canonical_original_code:
int Chan_send(struct Chan_T *c, void *ptr, int size) {
 ((void)((c)||(Except_raise(&(Assert_Failed), "src/chan.c", 22),0)));
 ((void)((ptr)||(Except_raise(&(Assert_Failed), "src/chan.c", 23),0)));
 ((void)((size >= 0)||(Except_raise(&(Assert_Failed), "src/chan.c", 24),0)));
 Sem_wait(&c->send);
 c->ptr = ptr;
 c->size = &size;
 Sem_signal(&c->recv);
 Sem_wait(&c->sync);
 return size;
}

variable_types: size int

user_defined_types: struct Sem_T { int count; void *queue; }


decompiled_code:
__int64 __fastcall Chan_receive(__int64 a1, void *a2, int a3)
{
int *v4; // rax
int *v6; // rax

if ( !a1 )
Except_raise(&Assert_Failed, "src/chan.c", 34LL);
if ( !a2 )
Except_raise(&Assert_Failed, "src/chan.c", 35LL);
if ( a3 < 0 )
{
Except_raise(&Assert_Failed, "src/chan.c", 36LL);
Sem_wait(a1 + 32);
v6 = *(int **)(a1 + 8);
if ( a3 > *v6 )
a3 = *v6;
*v6 = a3;
}
else
{
Sem_wait(a1 + 32);
v4 = *(int **)(a1 + 8);
if ( a3 > *v4 )
a3 = *v4;
*v4 = a3;
if ( a3 > 0 )
memcpy(a2, *(const void **)a1, a3);
}
Sem_signal(a1 + 48);
Sem_signal(a1 + 16);
return (unsigned int)a3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, void *a2, int a3)
{
int *v4; // rax
int *v6; // rax

if ( !a1 )
Except_raise(&Assert_Failed, "src/chan.c", 34LL);
if ( !a2 )
Except_raise(&Assert_Failed, "src/chan.c", 35LL);
if ( a3 < 0 )
{
Except_raise(&Assert_Failed, "src/chan.c", 36LL);
Sem_wait(a1 + 32);
v6 = *(int **)(a1 + 8);
if ( a3 > *v6 )
a3 = *v6;
*v6 = a3;
}
else
{
Sem_wait(a1 + 32);
v4 = *(int **)(a1 + 8);
if ( a3 > *v4 )
a3 = *v4;
*v4 = a3;
if ( a3 > 0 )
memcpy(a2, *(const void **)a1, a3);
}
Sem_signal(a1 + 48);
Sem_signal(a1 + 16);
return (unsigned int)a3;
}

original_code:
int Chan_receive(Chan_T c, void *ptr, int size) {
 int n;
 ((void)((c)||(Except_raise(&(Assert_Failed), "src/chan.c", 34),0)));
 ((void)((ptr)||(Except_raise(&(Assert_Failed), "src/chan.c", 35),0)));
 ((void)((size >= 0)||(Except_raise(&(Assert_Failed), "src/chan.c", 36),0)));
 Sem_wait(&c->recv);
 n = *c->size;
 if (size < n)
  n = size;
 *c->size = n;
 if (n > 0)
  memcpy(ptr, c->ptr, n);
 Sem_signal(&c->sync);
 Sem_signal(&c->send);
 return n;
}

canonical_original_code:
int Chan_receive(struct Chan_T *c, void *ptr, int size) {
 int n;
 ((void)((c)||(Except_raise(&(Assert_Failed), "src/chan.c", 34),0)));
 ((void)((ptr)||(Except_raise(&(Assert_Failed), "src/chan.c", 35),0)));
 ((void)((size >= 0)||(Except_raise(&(Assert_Failed), "src/chan.c", 36),0)));
 Sem_wait(&c->recv);
 n = *c->size;
 if (size < n)
  n = size;
 *c->size = n;
 if (n > 0)
  memcpy(ptr, c->ptr, n);
 Sem_signal(&c->sync);
 Sem_signal(&c->send);
 return n;
}

variable_types: n int


decompiled_code:
_QWORD *Arena_new()
{
_QWORD *v0; // rbx

v0 = malloc(0x18uLL);
if ( !v0 )
Except_raise(&Arena_NewFailed, "src/arena.c", 41LL);
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rbx

v0 = malloc(0x18uLL);
if ( !v0 )
Except_raise(&Arena_NewFailed, "src/arena.c", 41LL);
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
return v0;
}

original_code:
Arena_T Arena_new(void) {
 Arena_T arena = malloc(sizeof (*arena));
 if (arena == ((void *)0))
  Except_raise(&(Arena_NewFailed), "src/arena.c", 41);
 arena->prev = ((void *)0);
 arena->limit = arena->avail = ((void *)0);
 return arena;
}

canonical_original_code:
struct Arena_T *Arena_new() {
 struct Arena_T *arena = malloc(sizeof (*arena));
 if (arena == ((void *)0))
  Except_raise(&(Arena_NewFailed), "src/arena.c", 41);
 arena->prev = ((void *)0);
 arena->limit = arena->avail = ((void *)0);
 return arena;
}

variable_types: struct Arena_T { struct Arena_T *prev; char *avail; char *limit; } *


decompiled_code:
void *__fastcall Arena_calloc(__m128i *a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
__m128i *v8; // rax

if ( a2 <= 0 )
Except_raise(&Assert_Failed, "src/arena.c", 88LL);
v8 = Arena_alloc(a1, a3 * a2, a4, a5);
return memset(v8, 0, a3 * a2);
}

canonical_decompiled_code:
void *__fastcall func1(__m128i *a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
__m128i *v8; // rax

if ( a2 <= 0 )
Except_raise(&Assert_Failed, "src/arena.c", 88LL);
v8 = Arena_alloc(a1, a3 * a2, a4, a5);
return memset(v8, 0, a3 * a2);
}

original_code:
void *Arena_calloc(Arena_T arena, long count, long nbytes,
 const char *file, int line) {
 void *ptr;
 ((void)((count > 0)||(Except_raise(&(Assert_Failed), "src/arena.c", 88),0)));
 ptr = Arena_alloc(arena, count*nbytes, file, line);
 memset(ptr, '\0', count*nbytes);
 return ptr;
}

canonical_original_code:
void *Arena_calloc(struct Arena_T *arena, long count, long nbytes, char *file, int line) {
 void *ptr;
 ((void)((count > 0)||(Except_raise(&(Assert_Failed), "src/arena.c", 88),0)));
 ptr = Arena_alloc(arena, count*nbytes, file, line);
 memset(ptr, '\0', count*nbytes);
 return ptr;
}

user_defined_types: struct Arena_T { struct Arena_T *prev; char *avail; char *limit; }


decompiled_code:
void __fastcall Arena_free(__int64 a1)
{
_QWORD *v2; // rbx
_QWORD *v3; // rdi
__int64 v4; // r13
__int64 v5; // r12
int v6; // eax

if ( !a1 )
Except_raise(&Assert_Failed, "src/arena.c", 94LL);
v2 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
v4 = v3[1];
v5 = v3[2];
v6 = nfree;
if ( nfree <= 9 )
{
*v3 = freechunks;
freechunks = *(_QWORD *)a1;
nfree = v6 + 1;
*(_QWORD *)(freechunks + 16) = *(_QWORD *)(a1 + 16);
}
else
{
free(v3);
}
*(_QWORD *)a1 = v2;
*(_QWORD *)(a1 + 8) = v4;
*(_QWORD *)(a1 + 16) = v5;
}
while ( v2 );
}
if ( *(_QWORD *)(a1 + 16) )
Except_raise(&Assert_Failed, "src/arena.c", 106LL);
if ( *(_QWORD *)(a1 + 8) )
Except_raise(&Assert_Failed, "src/arena.c", 107LL);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
_QWORD *v2; // rbx
_QWORD *v3; // rdi
__int64 v4; // r13
__int64 v5; // r12
int v6; // eax

if ( !a1 )
Except_raise(&Assert_Failed, "src/arena.c", 94LL);
v2 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
v4 = v3[1];
v5 = v3[2];
v6 = nfree;
if ( nfree <= 9 )
{
*v3 = freechunks;
freechunks = *(_QWORD *)a1;
nfree = v6 + 1;
*(_QWORD *)(freechunks + 16) = *(_QWORD *)(a1 + 16);
}
else
{
free(v3);
}
*(_QWORD *)a1 = v2;
*(_QWORD *)(a1 + 8) = v4;
*(_QWORD *)(a1 + 16) = v5;
}
while ( v2 );
}
if ( *(_QWORD *)(a1 + 16) )
Except_raise(&Assert_Failed, "src/arena.c", 106LL);
if ( *(_QWORD *)(a1 + 8) )
Except_raise(&Assert_Failed, "src/arena.c", 107LL);
}

original_code:
void Arena_free(Arena_T arena) {
 ((void)((arena)||(Except_raise(&(Assert_Failed), "src/arena.c", 94),0)));
 while (arena->prev) {
  struct Arena_T tmp = *arena->prev;
  if (nfree < 10) {
   arena->prev->prev = freechunks;
   freechunks = arena->prev;
   nfree++;
   freechunks->limit = arena->limit;
  } else
   free(arena->prev);
  *arena = tmp;
 }
 ((void)((arena->limit == ((void *)0))||(Except_raise(&(Assert_Failed), "src/arena.c", 106),0)));
 ((void)((arena->avail == ((void *)0))||(Except_raise(&(Assert_Failed), "src/arena.c", 107),0)));
}

canonical_original_code:
void Arena_free(struct Arena_T *arena) {
 ((void)((arena)||(Except_raise(&(Assert_Failed), "src/arena.c", 94),0)));
 while (arena->prev) {
  struct Arena_T tmp = *arena->prev;
  if (nfree < 10) {
   arena->prev->prev = freechunks;
   freechunks = arena->prev;
   nfree++;
   freechunks->limit = arena->limit;
  } else
   free(arena->prev);
  *arena = tmp;
 }
 ((void)((arena->limit == ((void *)0))||(Except_raise(&(Assert_Failed), "src/arena.c", 106),0)));
 ((void)((arena->avail == ((void *)0))||(Except_raise(&(Assert_Failed), "src/arena.c", 107),0)));
}

variable_types: struct Arena_T { struct Arena_T *prev; char *avail; char *limit; }