decompiled_code:
_BOOL8 __fastcall xdr_half_long_string(XDR *a1, char *a2)
{
return xdr_hls(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(XDR *a1, char *a2)
{
return func12(a1, a2) != 0;
}

original_code:
bool_t
xdr_half_long_string (XDR *xdrs, half_long_string *objp)
{
 register int32_t *buf;
  if (!xdr_hls (xdrs, objp))
   return (0);
 return (1);
}

canonical_original_code:
int xdr_half_long_string(struct XDR *xdrs, struct hls *objp)
{
 register int *buf;
  if (!xdr_hls (xdrs, objp))
   return (0);
 return (1);
}

user_defined_types: struct hls { char str1[1024]; char str2[1024]; }


repo: nicogarcia/sd

decompiled_code:
_BOOL8 __fastcall xdr_long_string(__int64 a1, __int64 a2)
{
return (unsigned int)xdr_ls(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1, __int64 a2)
{
return (unsigned int)func11(a1, a2) != 0;
}

original_code:
bool_t
xdr_long_string (XDR *xdrs, long_string *objp)
{
 register int32_t *buf;
  if (!xdr_ls (xdrs, objp))
   return (0);
 return (1);
}

canonical_original_code:
int xdr_long_string(struct XDR *xdrs, struct ls *objp)
{
 register int *buf;
  if (!xdr_ls (xdrs, objp))
   return (0);
 return (1);
}

variable_types: struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *

variable_types:
objp
struct ls { char str[2048]; } *

variable_types:
buf
int *

return_type: int

user_defined_types: struct XDR { enum xdr_op x_op; struct xdr_ops *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; }


decompiled_code:
_BOOL8 __fastcall xdr_half_long_string(__int64 a1, __int64 a2)
{
return (unsigned int)xdr_hls(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1, __int64 a2)
{
return (unsigned int)func12(a1, a2) != 0;
}

variable_types: struct hls { char str1[1024]; char str2[1024]; } *

user_defined_types: enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 }

user_defined_types: struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); }


decompiled_code:
_BOOL8 __fastcall xdr_ls(XDR *a1, char *a2)
{
return xdr_vector(a1, a2, 0x800u, 1u, (xdrproc_t)xdr_char) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(XDR *a1, char *a2)
{
return xdr_vector(a1, a2, 0x800u, 1u, (xdrproc_t)xdr_char) != 0;
}

original_code:
bool_t
xdr_ls (XDR *xdrs, ls *objp)
{
 register int32_t *buf;
 int i;
  if (!xdr_vector (xdrs, (char *)objp->str, 2048,
  sizeof (char), (xdrproc_t) xdr_char))
   return (0);
 return (1);
}

canonical_original_code:
int xdr_ls(struct XDR *xdrs, struct ls *objp)
{
 register int *buf;
 int i;
  if (!xdr_vector (xdrs, (char *)objp->str, 2048,
  sizeof (char), (int (*)(struct XDR *, void *, ...)) xdr_char))
   return (0);
 return (1);
}

variable_types: i int


decompiled_code:
_BOOL8 __fastcall xdr_hls(XDR *a1, char *a2)
{
_BOOL8 result; // rax

if ( xdr_vector(a1, a2, 0x400u, 1u, (xdrproc_t)xdr_char) )
result = xdr_vector(a1, a2 + 1024, 0x400u, 1u, (xdrproc_t)xdr_char) != 0;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(XDR *a1, char *a2)
{
_BOOL8 result; // rax

if ( xdr_vector(a1, a2, 0x400u, 1u, (xdrproc_t)xdr_char) )
result = xdr_vector(a1, a2 + 1024, 0x400u, 1u, (xdrproc_t)xdr_char) != 0;
else
result = 0LL;
return result;
}

original_code:
bool_t
xdr_hls (XDR *xdrs, hls *objp)
{
 register int32_t *buf;
 int i;
  if (!xdr_vector (xdrs, (char *)objp->str1, 1024,
  sizeof (char), (xdrproc_t) xdr_char))
   return (0);
  if (!xdr_vector (xdrs, (char *)objp->str2, 1024,
  sizeof (char), (xdrproc_t) xdr_char))
   return (0);
 return (1);
}

canonical_original_code:
int xdr_hls(struct XDR *xdrs, struct hls *objp)
{
 register int *buf;
 int i;
  if (!xdr_vector (xdrs, (char *)objp->str1, 1024,
  sizeof (char), (int (*)(struct XDR *, void *, ...)) xdr_char))
   return (0);
  if (!xdr_vector (xdrs, (char *)objp->str2, 1024,
  sizeof (char), (int (*)(struct XDR *, void *, ...)) xdr_char))
   return (0);
 return (1);
}


decompiled_code:
void __fastcall pc_decode_construction_step(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, _QWORD *a7)
{
double *v11; // rbp

v11 = (double *)malloc(8LL * (1 << (a4 - a5)));
pc_decode_calc_f(v11, a6, a5, a4);
if ( a4 == a5 )
{
pc_decode_construction_update_Z(a1, a2, a7, *v11);
pc_decode_calc_g(v11, a6, a4, a4, a3, *a7);
pc_decode_construction_update_Z(a1, a2, a7, *v11);
}
else
{
pc_decode_construction_step(a1, a2, a3, a4, a5 + 1, (_DWORD)v11, (__int64)a7);
pc_decode_calc_g(v11, a6, a5, a4, a3, *a7);
pc_decode_construction_step(a1, a2, a3, a4, a5 + 1, (_DWORD)v11, (__int64)a7);
}
free(v11);
}

original_code:
void pc_decode_construction_step(double *Z, double *Zvar, Bit *u, 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(D*sizeof(double));
    pc_decode_calc_f(new_val, val, step, n);
    if(step == n){
        pc_decode_construction_update_Z(Z, Zvar, new_val[0], uindex);
    }else{
        pc_decode_construction_step(Z, Zvar, u, n, step+1, new_val, uindex);
    }
    pc_decode_calc_g(new_val, val, step, n, u, *uindex);
    if(step == n){
        pc_decode_construction_update_Z(Z, Zvar, new_val[0], uindex);
    }else{
        pc_decode_construction_step(Z, Zvar, u, n, step+1, new_val, uindex);
    }
    free(new_val);
}

canonical_original_code:
void pc_decode_construction_step(double *Z, double *Zvar, unsigned int *u, unsigned int n, unsigned int step, double *val, unsigned int *uindex){
    unsigned int D = 1 << (n-step);
    double *new_val = malloc(D*sizeof(double));
    pc_decode_calc_f(new_val, val, step, n);
    if(step == n){
        pc_decode_construction_update_Z(Z, Zvar, new_val[0], uindex);
    }else{
        pc_decode_construction_step(Z, Zvar, u, n, step+1, new_val, uindex);
    }
    pc_decode_calc_g(new_val, val, step, n, u, *uindex);
    if(step == n){
        pc_decode_construction_update_Z(Z, Zvar, new_val[0], uindex);
    }else{
        pc_decode_construction_step(Z, Zvar, u, n, step+1, new_val, uindex);
    }
    free(new_val);
}

variable_types:
Z
double *

variable_types:
Zvar
double *

variable_types:
u
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

return_type: void


original_code:
void pc_decode_construction(double *Z, double *Zvar, Bit *y, const Channel *channel, Bit *u, u_int64_t n) {
    u_int64_t N = 1 << n;
    u_int64_t uindex = 0;
    double *delta = malloc(N*sizeof(double));
    u_int64_t i;
    for(i = 0; i < N; i++){
        u_int64_t i2 = bit_reverse_index(i, n);
        double n_,d_,v;
        n_ = channel_probability(channel, y[i2], 0);
        d_ = channel_probability(channel, y[i2], 1);
        if(d_ == 0){
            v = ((double)(1 << 30));
        }else{
            v = n_/d_;
            if(v < (1.0 / (double)(1 << 30))){
                v = (1.0 / (double)(1 << 30));
            }else if(v > ((double)(1 << 30))){
                v = ((double)(1 << 30));
            }
        }
        delta[i] = v;
    }
    pc_decode_construction_step(Z, Zvar, u, n, 1, delta, &uindex);
    free(delta);
}

canonical_original_code:
void pc_decode_construction(double *Z, double *Zvar, unsigned int *y, struct Channel *channel, unsigned int *u, unsigned int n) {
    unsigned int N = 1 << n;
    unsigned int uindex = 0;
    double *delta = malloc(N*sizeof(double));
    unsigned int i;
    for(i = 0; i < N; i++){
        unsigned int i2 = bit_reverse_index(i, n);
        double n_; double d_; double v;
        n_ = channel_probability(channel, y[i2], 0);
        d_ = channel_probability(channel, y[i2], 1);
        if(d_ == 0){
            v = ((double)(1 << 30));
        }else{
            v = n_/d_;
            if(v < (1.0 / (double)(1 << 30))){
                v = (1.0 / (double)(1 << 30));
            }else if(v > ((double)(1 << 30))){
                v = ((double)(1 << 30));
            }
        }
        delta[i] = v;
    }
    pc_decode_construction_step(Z, Zvar, u, n, 1, delta, &uindex);
    free(delta);
}

variable_types:
y
unsigned int *

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

variable_types:
N
unsigned int

variable_types:
uindex
unsigned int

variable_types:
delta
double *

variable_types:
i
unsigned int

variable_types: v double

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


decompiled_code:
void __fastcall pc_construction(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v5; // r15
size_t v7; // r13
void *v9; // rbp
void *v10; // r14
__int64 v11; // r15

v5 = a5;
v7 = 1 << a3;
v9 = malloc(v7);
v10 = malloc(v7);
if ( v5 )
{
v11 = 0LL;
do
{
++v11;
random_bits(v9, v7);
pc_encode(v10, v9, a3);
apply_channel(v10, v10, a4, a3);
pc_decode_construction(a1, a2, (__int64)v10, a4, (__int64)v9, a3);
}
while ( a5 != v11 );
}
free(v9);
free(v10);
}

original_code:
void pc_construction(double *Z, double *Zvar, u_int64_t n, const Channel *channel, u_int64_t n_samples) {
    u_int64_t N = 1 << n;
    u_int64_t i;
    Bit *u = malloc(N*sizeof(Bit));
    Bit *x = malloc(N*sizeof(Bit));
    for(i = 0; i < n_samples; i++){
        random_bits(u, N);
        pc_encode(x, u, n);
        Bit *y = x;
        apply_channel(y, x, channel, n);
        pc_decode_construction(Z, Zvar, y, channel, u, n);
    }
    free(u);
    free(x);
}

canonical_original_code:
void pc_construction(double *Z, double *Zvar, unsigned int n, struct Channel *channel, unsigned int n_samples) {
    unsigned int N = 1 << n;
    unsigned int i;
    unsigned int *u = malloc(N*sizeof(Bit));
    unsigned int *x = malloc(N*sizeof(Bit));
    for(i = 0; i < n_samples; i++){
        random_bits(u, N);
        pc_encode(x, u, n);
        unsigned int *y = x;
        apply_channel(y, x, channel, n);
        pc_decode_construction(Z, Zvar, y, channel, u, n);
    }
    free(u);
    free(x);
}

variable_types:
x
unsigned int *

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


decompiled_code:
void __fastcall random_bits(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbx

if ( a2 )
{
v2 = a1;
do
*v2++ = rand() & 1;
while ( v2 != &a1[a2] );
}
}

canonical_decompiled_code:
void __fastcall func0(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbx

if ( a2 )
{
v2 = a1;
do
*v2++ = rand() & 1;
while ( v2 != &a1[a2] );
}
}

original_code:
void random_bits(Bit *bits, u_int64_t N) {
    u_int64_t i;
    for(i=0; i<N; i++){
        bits[i] = rand() & 1;
    }
}

canonical_original_code:
void random_bits(unsigned int *bits, unsigned int N) {
    unsigned int i;
    for(i=0; i<N; i++){
        bits[i] = rand() & 1;
    }
}

variable_types:
bits
unsigned int *


original_code:
void random_bits_f(Bit *bits, Bit *A, u_int64_t N) {
    u_int64_t i;
    for(i=0; i<N; i++){
        if(A[i] == 0)
            bits[i] = 0;
        else
            bits[i] = rand() & 1;
    }
}

canonical_original_code:
void random_bits_f(unsigned int *bits, unsigned int *A, unsigned int N) {
    unsigned int i;
    for(i=0; i<N; i++){
        if(A[i] == 0)
            bits[i] = 0;
        else
            bits[i] = rand() & 1;
    }
}

variable_types:
A
unsigned int *


decompiled_code:
int __fastcall print_bits(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbx

if ( a2 )
{
v2 = a1;
do
{
if ( *v2 )
{
if ( *v2 == 1 )
putchar(49);
else
putchar(63);
}
else
{
putchar(48);
}
++v2;
putchar(32);
}
while ( v2 != &a1[a2] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rbx

if ( a2 )
{
v2 = a1;
do
{
if ( *v2 )
{
if ( *v2 == 1 )
putchar(49);
else
putchar(63);
}
else
{
putchar(48);
}
++v2;
putchar(32);
}
while ( v2 != &a1[a2] );
}
return putchar(10);
}

original_code:
void print_bits(Bit *bits, u_int64_t N) {
    u_int64_t i;
    for(i=0; i<N; printf(" "), i++){
        if(bits[i] == 0)
            printf("0");
        else if(bits[i] == 1)
            printf("1");
        else
            printf("?");
    }
    printf("\n");
}

canonical_original_code:
void print_bits(unsigned int *bits, unsigned int N) {
    unsigned int i;
    for(i=0; i<N; printf(" "), i++){
        if(bits[i] == 0)
            printf("0");
        else if(bits[i] == 1)
            printf("1");
        else
            printf("?");
    }
    printf("\n");
}


decompiled_code:
int __fastcall print_doubles(__int64 a1, __int64 a2)
{
__int64 i; // rbx
double v3; // xmm0_8

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v3 = *(double *)(a1 + 8 * i);
printf("%f", v3);
putchar(32);
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2)
{
__int64 i; // rbx
double v3; // xmm0_8

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v3 = *(double *)(a1 + 8 * i);
printf("%f", v3);
putchar(32);
}
}
return putchar(10);
}

original_code:
void print_doubles(double *doubles, u_int64_t N) {
    u_int64_t i;
    for(i=0; i<N; printf(" "), i++){
        printf("%f", doubles[i]);
    }
    printf("\n");
}

canonical_original_code:
void print_doubles(double *doubles, unsigned int N) {
    unsigned int i;
    for(i=0; i<N; printf(" "), i++){
        printf("%f", doubles[i]);
    }
    printf("\n");
}

variable_types:
doubles
double *


decompiled_code:
__int64 __fastcall bit_reverse_index(unsigned __int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // r8
char v4; // cl
__int64 v5; // rax

if ( !a2 )
return 0LL;
v2 = 0LL;
v3 = 0LL;
do
{
v4 = a2 - 1 - v2;
v5 = (a1 >> v2++) & 1;
v3 |= v5 << v4;
}
while ( a2 != v2 );
return v3;
}

original_code:
u_int64_t bit_reverse_index(u_int64_t index, u_int64_t n) {
    u_int64_t index2 = 0;
    u_int64_t i;
    for(i=0; i < n; i++){
        index2 |= ((index >> i) & 1) << (n-i-1);
    }
    return index2;
}

canonical_original_code:
unsigned int bit_reverse_index(unsigned int index, unsigned int n) {
    unsigned int index2 = 0;
    unsigned int i;
    for(i=0; i < n; i++){
        index2 |= ((index >> i) & 1) << (n-i-1);
    }
    return index2;
}

variable_types:
index
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall pc_encode(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 result; // rax
unsigned __int64 v6; // r11
__int64 v7; // rcx
unsigned __int64 v9; // rdi
unsigned __int64 v10; // rsi
unsigned __int64 v11; // rax
unsigned __int64 v12; // rdx
unsigned __int64 v13; // rax
unsigned __int64 v14; // r12
unsigned __int64 v15; // rdx

result = (unsigned int)(1 << a3);
if ( a3 )
{
v6 = (unsigned __int64)(int)result >> 1;
v7 = 1LL;
while ( 1 )
{
v9 = (unsigned __int64)(1 << v7) >> 1;
if ( v6 )
{
v10 = 0LL;
do
{
v11 = v10++;
v12 = v11 % v9;
v13 = (1 << v7) * (v11 / v9);
v14 = v13 + v12;
v15 = v13 + v9 + v12;
*(_BYTE *)(a1 + v14) = (*(_BYTE *)(a2 + v14) + *(_BYTE *)(a2 + v15)) & 1;
result = *(unsigned __int8 *)(a2 + v15);
*(_BYTE *)(a1 + v15) = result;
}
while ( v10 != v6 );
}
if ( a3 < ++v7 )
break;
a2 = a1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 result; // rax
unsigned __int64 v6; // r11
__int64 v7; // rcx
unsigned __int64 v9; // rdi
unsigned __int64 v10; // rsi
unsigned __int64 v11; // rax
unsigned __int64 v12; // rdx
unsigned __int64 v13; // rax
unsigned __int64 v14; // r12
unsigned __int64 v15; // rdx

result = (unsigned int)(1 << a3);
if ( a3 )
{
v6 = (unsigned __int64)(int)result >> 1;
v7 = 1LL;
while ( 1 )
{
v9 = (unsigned __int64)(1 << v7) >> 1;
if ( v6 )
{
v10 = 0LL;
do
{
v11 = v10++;
v12 = v11 % v9;
v13 = (1 << v7) * (v11 / v9);
v14 = v13 + v12;
v15 = v13 + v9 + v12;
*(_BYTE *)(a1 + v14) = (*(_BYTE *)(a2 + v14) + *(_BYTE *)(a2 + v15)) & 1;
result = *(unsigned __int8 *)(a2 + v15);
*(_BYTE *)(a1 + v15) = result;
}
while ( v10 != v6 );
}
if ( a3 < ++v7 )
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 *


decompiled_code:
double *__fastcall pc_decode_calc_f(double *a1, double *a2, char a3, char a4)
{
char v4; // cl
double *result; // rax
double v6; // xmm0_8
double v7; // xmm0_8

v4 = a4 - a3;
result = (double *)(1 << v4);
if ( 1 << v4 )
{
result = &a2[2 * (_QWORD)result];
do
{
v7 = (*a2 * a2[1] + 1.0) / (*a2 + a2[1]);
if ( v7 >= 9.313225746154785e-10 )
v6 = fmin(1073741824.0, v7);
else
v6 = *(double *)&LC0;
a2 += 2;
*a1++ = v6;
}
while ( result != a2 );
}
return result;
}

canonical_decompiled_code:
double *__fastcall func0(double *a1, double *a2, char a3, char a4)
{
char v4; // cl
double *result; // rax
double v6; // xmm0_8
double v7; // xmm0_8

v4 = a4 - a3;
result = (double *)(1 << v4);
if ( 1 << v4 )
{
result = &a2[2 * (_QWORD)result];
do
{
v7 = (*a2 * a2[1] + 1.0) / (*a2 + a2[1]);
if ( v7 >= 9.313225746154785e-10 )
v6 = fmin(1073741824.0, v7);
else
v6 = *(double *)&LC0;
a2 += 2;
*a1++ = v6;
}
while ( result != a2 );
}
return result;
}

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: a double

variable_types: b double


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:
i
unsigned int

variable_types:
us
unsigned int [-1]

variable_types: v double


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


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);
}


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; } *

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; // r12
char *v5; // rax
char *v6; // rbx
char *v7; // rdx
__int64 i; // rax
char *result; // rax
__int64 v10; // rdx

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

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

v4 = 1 << *a3;
v5 = (char *)malloc(16 * v4);
v6 = v5;
if ( v4 )
{
v7 = v5;
for ( i = 0LL; i != v4; ++i )
{
*(_QWORD *)v7 = i;
v7 += 16;
*((_QWORD *)v7 - 1) = a3;
}
}
qsort(v6, v4, 0x10uLL, (__compar_fn_t)frozen_bits_sort_cmp);
result = (char *)memset(s, 0, v4);
if ( a2 )
{
result = v6;
do
{
v10 = *(_QWORD *)result;
result += 16;
*((_BYTE *)s + v10) = 1;
}
while ( &v6[16 * a2] != result );
}
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:
index
unsigned int


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)
{
if ( *(_DWORD *)a1 == 1 )
{
result = *(double *)(a1 + 8);
if ( a2 == a3 )
result = 1.0 - result;
}
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)
{
if ( *(_DWORD *)a1 == 1 )
{
result = *(double *)(a1 + 8);
if ( a2 == a3 )
result = 1.0 - result;
}
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 result; // xmm0_8
double v2; // [rsp+8h] [rbp-20h]
double v3; // [rsp+10h] [rbp-18h]
double v4; // [rsp+18h] [rbp-10h]

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

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

if ( *(_DWORD *)a1 == 1 )
{
v4 = *(double *)(a1 + 8);
v2 = log2(v4);
v3 = 1.0 - *(double *)(a1 + 8);
result = 1.0 - (COERCE_DOUBLE(*(_QWORD *)&v4 ^ LC3) * v2 - v3 * log2(v3));
}
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)
{
double *v10; // rbp
__int64 v11; // rcx
__int64 v12; // r8

v10 = (double *)malloc(8LL * (1 << (a3 - a4)));
pc_decode_calc_f(v10, a5, a4, a3);
if ( a3 == a4 )
{
pc_decode_update_u_(a1, a2, a6, *v10);
pc_decode_calc_g(v10, a5, a3, v11, v12, *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


main

canonical_name: main

repo: nicolai-rostov/asus-fancontrol

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

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

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

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


outb

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)
{
__int64 result; // rax

if ( WEOE() || WEIE() || (outb(0xFFu, 0x258u), WEIE()) || (outb(0x98u, 0x258u), WEIE()) || (outb(a1, 0x257u), WEIE()) )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(WEIE() != 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 a1)
{
__int64 result; // rax

if ( func10() || func9() || (func8(0xFFu, 0x258u), func9()) || (func8(0x98u, 0x258u), func9()) || (func8(a1, 0x257u), func9()) )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(func9() != 0);
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


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 )
return *(unsigned int *)(a1 + 8);
Except_raise(&Assert_Failed, "src/ring.c", 44LL);
return *(&loc_4 + 1);
}

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

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; }


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;
}


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 )
{
if ( a2 )
goto LABEL_3;
}
else
{
Except_raise(&Assert_Failed, "src/table.c", 51LL);
if ( a2 )
goto LABEL_3;
}
Except_raise(&Assert_Failed, "src/table.c", 52LL);
LABEL_3:
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 )
{
if ( a2 )
goto LABEL_3;
}
else
{
Except_raise(&Assert_Failed, "src/table.c", 51LL);
if ( a2 )
goto LABEL_3;
}
Except_raise(&Assert_Failed, "src/table.c", 52LL);
LABEL_3:
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)
{
signed int v4; // edx
_QWORD *v5; // rbx
__int64 v6; // r14
__int64 result; // rax
_QWORD *v8; // rax
_QWORD *v9; // r14

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
signed int v4; // edx
_QWORD *v5; // rbx
__int64 v6; // r14
__int64 result; // rax
_QWORD *v8; // rax
_QWORD *v9; // r14

if ( a1 )
{
if ( a2 )
goto LABEL_3;
}
else
{
Except_raise(&Assert_Failed, "src/table.c", 63LL);
if ( a2 )
goto LABEL_3;
}
Except_raise(&Assert_Failed, "src/table.c", 64LL);
LABEL_3:
v4 = (*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)a1;
v5 = *(_QWORD **)(*(_QWORD *)(a1 + 32) + 8LL * v4);
v6 = 8LL * v4;
if ( v5 )
{
while ( (*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 8))(a2, v5[1]) )
{
v5 = (_QWORD *)*v5;
if ( !v5 )
goto LABEL_9;
}
result = v5[2];
}
else
{
LABEL_9:
v8 = (_QWORD *)Mem_alloc(24LL, "src/table.c", 70LL);
v9 = (_QWORD *)(*(_QWORD *)(a1 + 32) + v6);
v8[1] = a2;
v5 = v8;
*v8 = *v9;
result = 0LL;
*v9 = v5;
++*(_DWORD *)(a1 + 24);
}
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 )
return *(unsigned int *)(a1 + 24);
Except_raise(&Assert_Failed, "src/table.c", 83LL);
return 8658703LL;
}

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

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(unsigned int *a1, __int64 (__fastcall *a2)(_QWORD, _QWORD *, __int64), __int64 a3)
{
__int64 result; // rax
unsigned int v5; // er14
__int64 v6; // r15
_QWORD *i; // rbx

if ( a1 )
{
if ( a2 )
goto LABEL_3;
}
else
{
Except_raise(&Assert_Failed, "src/table.c", 92LL);
if ( a2 )
goto LABEL_3;
}
Except_raise(&Assert_Failed, "src/table.c", 93LL);
LABEL_3:
result = *a1;
v5 = a1[7];
if ( (int)result > 0 )
{
v6 = 0LL;
do
{
result = *((_QWORD *)a1 + 4);
for ( i = *(_QWORD **)(result + 8 * v6); i; i = (_QWORD *)*i )
{
result = a2(i[1], i + 2, a3);
if ( a1[7] != v5 )
result = Except_raise(&Assert_Failed, "src/table.c", 98LL);
}
++v6;
}
while ( (int)*a1 > (int)v6 );
}
return result;
}

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

if ( a1 )
{
if ( a2 )
goto LABEL_3;
}
else
{
Except_raise(&Assert_Failed, "src/table.c", 92LL);
if ( a2 )
goto LABEL_3;
}
Except_raise(&Assert_Failed, "src/table.c", 93LL);
LABEL_3:
result = *a1;
v5 = a1[7];
if ( (int)result > 0 )
{
v6 = 0LL;
do
{
result = *((_QWORD *)a1 + 4);
for ( i = *(_QWORD **)(result + 8 * v6); i; i = (_QWORD *)*i )
{
result = a2(i[1], i + 2, a3);
if ( a1[7] != v5 )
result = Except_raise(&Assert_Failed, "src/table.c", 98LL);
}
++v6;
}
while ( (int)*a1 > (int)v6 );
}
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;
v7 = a2 - 1;
v6 = 0;
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;
v7 = a2 - 1;
v6 = 0;
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:
__int64 __fastcall Set_member(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx

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

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

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

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 )
return *a1;
Except_raise(&Assert_Failed, "src/set.c", 118LL);
return *(unsigned int *)cmpatom;
}

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

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)
{
__int64 result; // rax
int v5; // er14
__int64 v6; // r15
_QWORD *i; // rbx

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

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

if ( a1 )
{
if ( a2 )
goto LABEL_3;
}
else
{
Except_raise(&Assert_Failed, "src/set.c", 139LL);
if ( a2 )
goto LABEL_3;
}
Except_raise(&Assert_Failed, "src/set.c", 140LL);
LABEL_3:
result = *(unsigned int *)(a1 + 24);
v5 = *(_DWORD *)(a1 + 4);
if ( (int)result > 0 )
{
v6 = 0LL;
do
{
result = *(_QWORD *)(a1 + 32);
for ( i = *(_QWORD **)(result + 8 * v6); i; i = (_QWORD *)*i )
{
result = a2(i[1], a3);
if ( *(_DWORD *)(a1 + 4) != v5 )
result = Except_raise(&Assert_Failed, "src/set.c", 145LL);
}
++v6;
}
while ( *(_DWORD *)(a1 + 24) > (int)v6 );
}
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


decompiled_code:
__int64 __fastcall Set_union(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
int v4; // eax
__int64 v5; // r12
__int64 v6; // rbp
_QWORD *i; // rbx
__int64 result; // rax

if ( a1 )
{
v3 = *(unsigned int *)(a1 + 24);
if ( a2 )
{
v4 = Arith_max(v3, *(unsigned int *)(a2 + 24));
v5 = copy(a1, v4);
if ( *(_QWORD *)(a1 + 8) != *(_QWORD *)(a2 + 8) || *(_QWORD *)(a1 + 16) != *(_QWORD *)(a2 + 16) )
Except_raise(&Assert_Failed, "src/set.c", 168LL);
if ( *(int *)(a2 + 24) > 0 )
{
v6 = 0LL;
do
{
for ( i = *(_QWORD **)(*(_QWORD *)(a2 + 32) + 8 * v6); i; i = (_QWORD *)*i )
Set_put(v5, i[1]);
++v6;
}
while ( *(_DWORD *)(a2 + 24) > (int)v6 );
}
result = v5;
}
else
{
result = copy(a1, v3);
}
}
else
{
if ( !a2 )
Except_raise(&Assert_Failed, "src/set.c", 162LL);
result = copy(a2, *(_DWORD *)(a2 + 24));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
int v4; // eax
__int64 v5; // r12
__int64 v6; // rbp
_QWORD *i; // rbx
__int64 result; // rax

if ( a1 )
{
v3 = *(unsigned int *)(a1 + 24);
if ( a2 )
{
v4 = Arith_max(v3, *(unsigned int *)(a2 + 24));
v5 = func3(a1, v4);
if ( *(_QWORD *)(a1 + 8) != *(_QWORD *)(a2 + 8) || *(_QWORD *)(a1 + 16) != *(_QWORD *)(a2 + 16) )
Except_raise(&Assert_Failed, "src/set.c", 168LL);
if ( *(int *)(a2 + 24) > 0 )
{
v6 = 0LL;
do
{
for ( i = *(_QWORD **)(*(_QWORD *)(a2 + 32) + 8 * v6); i; i = (_QWORD *)*i )
Set_put(v5, i[1]);
++v6;
}
while ( *(_DWORD *)(a2 + 24) > (int)v6 );
}
result = v5;
}
else
{
result = func3(a1, v3);
}
}
else
{
if ( !a2 )
Except_raise(&Assert_Failed, "src/set.c", 162LL);
result = func3(a2, *(_DWORD *)(a2 + 24));
}
return result;
}

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; // eax
bool v3; // cc
__int64 result; // rax

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

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

v2 = **(_DWORD **)a2;
v3 = **(_DWORD **)a1 < v2;
result = **(_DWORD **)a1 > v2;
if ( v3 )
result = 0xFFFFFFFFLL;
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;
}


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)
{
_QWORD *v1; // rbx
_QWORD *v2; // rax

if ( a1 )
{
if ( (a1 & 0xF) != 0 || (v2 = (_QWORD *)find(a1), (v1 = v2) == 0LL) || *v2 )
Except_raise(&Assert_Failed);
*v1 = freelist;
freelist = v1;
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rax

if ( a1 )
{
if ( (a1 & 0xF) != 0 || (v2 = (_QWORD *)func0(a1), (v1 = v2) == 0LL) || *v2 )
Except_raise(&Assert_Failed);
*v1 = freelist;
freelist = v1;
}
}

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; }