decompiled_code:
__int64 __fastcall rxe_backref_table_free(__int64 a1)
{
rxe_mem_free(*(_QWORD *)(a1 + 8));
return rxe_mem_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
rxe_mem_free(*(_QWORD *)(a1 + 8));
return rxe_mem_free(a1);
}

original_code:
void rxe_backref_table_free(struct rxe_backref_table *brt)
{
    rxe_mem_free(brt->bkref);
    rxe_mem_free(brt);
}


repo: marcocarnut/rxe

original_code:
void rxe_backref_table_add(struct rxe_backref_table *brt, struct rxe *rxe)
{
    if (!brt) return;
    if (brt->nbackrefs == brt->maxbackrefs) {
        struct rxe **new_bkref;
        new_bkref = ((struct rxe * *)kmalloc(sizeof(struct rxe *)*(brt->nbackrefs*2),"bkreftbl.c",42));
        int size = brt->nbackrefs*sizeof(struct rxe *);
        memcpy(new_bkref,brt->bkref,size);
        rxe_mem_free(brt->bkref);
        brt->bkref = new_bkref;
        brt->maxbackrefs *= 2;
    }
    brt->bkref[brt->nbackrefs++] = rxe;
}

canonical_original_code:
void rxe_backref_table_add(struct rxe_backref_table *brt, struct rxe *rxe)
{
    if (!brt) return;
    if (brt->nbackrefs == brt->maxbackrefs) {
        struct rxe **new_bkref;
        new_bkref = ((struct rxe **)kmalloc(sizeof(struct rxe *)*(brt->nbackrefs*2),"bkreftbl.c",42));
        int size = brt->nbackrefs*sizeof(struct rxe *);
        memcpy(new_bkref,brt->bkref,size);
        rxe_mem_free(brt->bkref);
        brt->bkref = new_bkref;
        brt->maxbackrefs *= 2;
    }
    brt->bkref[brt->nbackrefs++] = rxe;
}

variable_types: struct rxe_backref_table { int nbackrefs; int maxbackrefs; struct rxe { int nalts; enum rxe_parse_status { RXE_OK=0, RXE_INFINITE=1, RXE_TOO_MANY_PARENS=2, RXE_TOO_LITTLE_PARENS=3, RXE_LONE_QUANTIFIER=4, RXE_NESTED_QUANTIFIERS=5, RXE_UNTERMINATED_LITERAL=6, RXE_UNTERMINATED_CLASS=7, RXE_UNTERMINATED_REPEAT=8, RXE_UNTERMINATED_FLAGS=9, RXE_BAD_REPETITION=10, RXE_UNIMPLEMENTED=11, RXE_INVALID_BACKREF=12, RXE_INVALID_CONSTANT=13, RXE_UNTERMINATED_HEX_CONSTANT=14 } status; struct rxe_alt { int nnodes; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } nitems[1]; struct __mpz_struct start[1]; struct rxe_node { int len; char *str; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; int iterator; int is_backref; struct rxe *rxe; struct rxe_node *prev; struct rxe_node *next; } *curr; struct rxe_node *head; struct rxe_node *tail; struct rxe_alt *prev; struct rxe_alt *next; } *head; struct rxe_alt *tail; struct rxe_alt *curr; struct __mpz_struct nitems[1]; struct rxe_backref_table *brt; int flags; } **bkref; } *

variable_types:
rxe
struct rxe *

variable_types: struct rxe { int nalts; enum rxe_parse_status { RXE_OK=0, RXE_INFINITE=1, RXE_TOO_MANY_PARENS=2, RXE_TOO_LITTLE_PARENS=3, RXE_LONE_QUANTIFIER=4, RXE_NESTED_QUANTIFIERS=5, RXE_UNTERMINATED_LITERAL=6, RXE_UNTERMINATED_CLASS=7, RXE_UNTERMINATED_REPEAT=8, RXE_UNTERMINATED_FLAGS=9, RXE_BAD_REPETITION=10, RXE_UNIMPLEMENTED=11, RXE_INVALID_BACKREF=12, RXE_INVALID_CONSTANT=13, RXE_UNTERMINATED_HEX_CONSTANT=14 } status; struct rxe_alt { int nnodes; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } nitems[1]; struct __mpz_struct start[1]; struct rxe_node { int len; char *str; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; int iterator; int is_backref; struct rxe *rxe; struct rxe_node *prev; struct rxe_node *next; } *curr; struct rxe_node *head; struct rxe_node *tail; struct rxe_alt *prev; struct rxe_alt *next; } *head; struct rxe_alt *tail; struct rxe_alt *curr; struct __mpz_struct nitems[1]; struct rxe_backref_table { int nbackrefs; int maxbackrefs; struct rxe **bkref; } *brt; int flags; } **

variable_types: size int

return_type: void

user_defined_types: struct rxe { int nalts; enum rxe_parse_status status; struct rxe_alt *head; struct rxe_alt *tail; struct rxe_alt *curr; struct __mpz_struct nitems[1]; struct rxe_backref_table *brt; int flags; }

user_defined_types: struct rxe_alt { int nnodes; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; struct rxe_node *curr; struct rxe_node *head; struct rxe_node *tail; struct rxe_alt *prev; struct rxe_alt *next; }


decompiled_code:
__int64 __fastcall rxe_free_alt(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi

v2 = *(_QWORD *)(a1 + 48);
while ( v2 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 72);
rxe_free_node(v3);
}
_gmpz_clear(a1 + 24);
_gmpz_clear(a1 + 8);
return rxe_mem_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi

v2 = *(_QWORD *)(a1 + 48);
while ( v2 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 72);
rxe_free_node(v3);
}
_gmpz_clear(a1 + 24);
_gmpz_clear(a1 + 8);
return rxe_mem_free(a1);
}

original_code:
void rxe_free_alt(struct rxe_alt *alt)
{
    struct rxe_node *node,*next;
    for ( node = alt->head ; node ; node = next ) {
        next = node->next;
        rxe_free_node(node);
    }
    __gmpz_clear(alt->start);
    __gmpz_clear(alt->nitems);
    rxe_mem_free(alt);
}

canonical_original_code:
void rxe_free_alt(struct rxe_alt *alt)
{
    struct rxe_node *node; struct rxe_node *next;
    for ( node = alt->head ; node ; node = next ) {
        next = node->next;
        rxe_free_node(node);
    }
    __gmpz_clear(alt->start);
    __gmpz_clear(alt->nitems);
    rxe_mem_free(alt);
}

variable_types: struct rxe_alt { int nnodes; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } nitems[1]; struct __mpz_struct start[1]; struct rxe_node { int len; char *str; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; int iterator; int is_backref; struct rxe { int nalts; enum rxe_parse_status { RXE_OK=0, RXE_INFINITE=1, RXE_TOO_MANY_PARENS=2, RXE_TOO_LITTLE_PARENS=3, RXE_LONE_QUANTIFIER=4, RXE_NESTED_QUANTIFIERS=5, RXE_UNTERMINATED_LITERAL=6, RXE_UNTERMINATED_CLASS=7, RXE_UNTERMINATED_REPEAT=8, RXE_UNTERMINATED_FLAGS=9, RXE_BAD_REPETITION=10, RXE_UNIMPLEMENTED=11, RXE_INVALID_BACKREF=12, RXE_INVALID_CONSTANT=13, RXE_UNTERMINATED_HEX_CONSTANT=14 } status; struct rxe_alt *head; struct rxe_alt *tail; struct rxe_alt *curr; struct __mpz_struct nitems[1]; struct rxe_backref_table { int nbackrefs; int maxbackrefs; struct rxe **bkref; } *brt; int flags; } *rxe; struct rxe_node *prev; struct rxe_node *next; } *curr; struct rxe_node *head; struct rxe_node *tail; struct rxe_alt *prev; struct rxe_alt *next; } *

variable_types: struct rxe_node { int len; char *str; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } nitems[1]; struct __mpz_struct start[1]; int iterator; int is_backref; struct rxe { int nalts; enum rxe_parse_status { RXE_OK=0, RXE_INFINITE=1, RXE_TOO_MANY_PARENS=2, RXE_TOO_LITTLE_PARENS=3, RXE_LONE_QUANTIFIER=4, RXE_NESTED_QUANTIFIERS=5, RXE_UNTERMINATED_LITERAL=6, RXE_UNTERMINATED_CLASS=7, RXE_UNTERMINATED_REPEAT=8, RXE_UNTERMINATED_FLAGS=9, RXE_BAD_REPETITION=10, RXE_UNIMPLEMENTED=11, RXE_INVALID_BACKREF=12, RXE_INVALID_CONSTANT=13, RXE_UNTERMINATED_HEX_CONSTANT=14 } status; struct rxe_alt { int nnodes; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; struct rxe_node *curr; struct rxe_node *head; struct rxe_node *tail; struct rxe_alt *prev; struct rxe_alt *next; } *head; struct rxe_alt *tail; struct rxe_alt *curr; struct __mpz_struct nitems[1]; struct rxe_backref_table { int nbackrefs; int maxbackrefs; struct rxe **bkref; } *brt; int flags; } *rxe; struct rxe_node *prev; struct rxe_node *next; } *

user_defined_types: struct rxe_node { int len; char *str; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; int iterator; int is_backref; struct rxe *rxe; struct rxe_node *prev; struct rxe_node *next; }


decompiled_code:
__int64 __fastcall mpz_len(__int64 a1)
{
unsigned int v1; // er12
_BYTE v3[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = 0;
_gmpz_init_set_ui(v3, 10LL);
while ( 1 )
{
++v1;
if ( (int)_gmpz_cmp(v3, a1) > 0 )
break;
_gmpz_mul_ui(v3, v3, 10LL);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // er12
_BYTE v3[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = 0;
_gmpz_init_set_ui(v3, 10LL);
while ( 1 )
{
++v1;
if ( (int)_gmpz_cmp(v3, a1) > 0 )
break;
_gmpz_mul_ui(v3, v3, 10LL);
}
return v1;
}

original_code:
int mpz_len(mpz_t x)
{
    mpz_t r;
    __gmpz_init_set_ui(r,10);
    int len = 0;
    for (;;) {
        len++;
        if (__gmpz_cmp(r,x)>0) return len;
        __gmpz_mul_ui(r,r,10);
    }
}

canonical_original_code:
int mpz_len(struct __mpz_struct x[1])
{
    struct __mpz_struct r[1];
    __gmpz_init_set_ui(r,10);
    int len = 0;
    for (;;) {
        len++;
        if (__gmpz_cmp(r,x)>0) return len;
        __gmpz_mul_ui(r,r,10);
    }
}

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

variable_types: len int

return_type: int


die

decompiled_code:
void __noreturn die(int status, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
vfprintf(stderr, a2, arg);
exit(status);
}

canonical_decompiled_code:
void __noreturn func2(int status, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
vfprintf(stderr, a2, arg);
exit(status);
}

original_code:
void die(int code, char *msg, ...)
{
    va_list list_ptr;
    __builtin_va_start(list_ptr,msg);
    vfprintf(stderr,msg,list_ptr);
    __builtin_va_end(list_ptr);
    exit(code);
}

canonical_original_code:
void die(int code, char *msg, ...)
{
    __builtin_va_list list_ptr;
    __builtin_va_start(list_ptr,msg);
    vfprintf(stderr,msg,list_ptr);
    __builtin_va_end(list_ptr);
    exit(code);
}

variable_types: code int

variable_types:
msg
char *


enumerate

decompiled_code:
__int64 __fastcall enumerate(__int64 a1, char a2, int a3, __int64 a4, __int64 a5, char a6)
{
int v9; // eax
int v10; // er13
int v11; // eax
int v12; // er13
__int64 result; // rax
char v15[16]; // [rsp+10h] [rbp-F8h] BYREF
char v16[16]; // [rsp+20h] [rbp-E8h] BYREF
char v17[4]; // [rsp+30h] [rbp-D8h] BYREF
int v18; // [rsp+34h] [rbp-D4h]
char v19[4]; // [rsp+40h] [rbp-C8h] BYREF
int v20; // [rsp+44h] [rbp-C4h]
char v21[16]; // [rsp+50h] [rbp-B8h] BYREF
char s[168]; // [rsp+60h] [rbp-A8h] BYREF

_gmpz_init(v15);
if ( *(_DWORD *)(a5 + 4) )
{
_gmpz_add(v15, a4, a5);
_gmpz_sub_ui(v15, v15, 1LL);
}
else
{
_gmpz_set(v15, a1 + 32);
}
_gmpz_sub_ui(v15, v15, 1 - a3);
v9 = mpz_len((__int64)v15);
v10 = v9 + (v9 - 1) / 3 - 1;
v11 = mpz_len(a4);
v12 = v10 - (v11 + (v11 - 1) / 3 - 1);
_gmpz_init_set(v16, a4);
_gmpz_init(v21);
_gmpz_init_set_ui(v17, 10LL);
_gmpz_cdiv_q(v21, v16, v17);
_gmpz_mul(v17, v17, v21);
if ( !v18 )
_gmpz_set_ui(v17, 10LL);
_gmpz_init_set_ui(v19, 1000LL);
_gmpz_cdiv_q(v21, v16, v19);
_gmpz_mul(v19, v19, v21);
if ( !v20 )
_gmpz_set_ui(v19, 1000LL);
_gmpz_sub_ui(a4, a4, a3);
if ( (unsigned int)rxe_seek(a1, a4) )
die(100, "seek past end");
do
{
rxe_current(s, 100LL, a1);
if ( (a2 & 2) != 0 )
{
printf("%*s", v12, (const char *)&unk_52A);
print_grouped(stdout, 0LL, (__int64)v16, " ", a6);
_gmpz_add_ui(v16, v16, 1LL);
if ( !(unsigned int)_gmpz_cmp(v16, v17) )
{
_gmpz_mul_ui(v17, v17, 10LL);
if ( (unsigned int)_gmpz_cmp(v16, v19) )
{
--v12;
}
else
{
v12 -= 2;
_gmpz_mul_ui(v19, v19, 1000LL);
}
}
}
puts(s);
result = rxe_iterate(a1);
if ( (_DWORD)result )
break;
if ( *(_DWORD *)(a5 + 4) )
{
_gmpz_sub_ui(a5, a5, 1LL);
result = *(unsigned int *)(a5 + 4);
if ( !(_DWORD)result )
break;
}
}
while ( (a2 & 1) == 0 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2, int a3, __int64 a4, __int64 a5, char a6)
{
int v9; // eax
int v10; // er13
int v11; // eax
int v12; // er13
__int64 result; // rax
char v15[16]; // [rsp+10h] [rbp-F8h] BYREF
char v16[16]; // [rsp+20h] [rbp-E8h] BYREF
char v17[4]; // [rsp+30h] [rbp-D8h] BYREF
int v18; // [rsp+34h] [rbp-D4h]
char v19[4]; // [rsp+40h] [rbp-C8h] BYREF
int v20; // [rsp+44h] [rbp-C4h]
char v21[16]; // [rsp+50h] [rbp-B8h] BYREF
char s[168]; // [rsp+60h] [rbp-A8h] BYREF

_gmpz_init(v15);
if ( *(_DWORD *)(a5 + 4) )
{
_gmpz_add(v15, a4, a5);
_gmpz_sub_ui(v15, v15, 1LL);
}
else
{
_gmpz_set(v15, a1 + 32);
}
_gmpz_sub_ui(v15, v15, 1 - a3);
v9 = func1((__int64)v15);
v10 = v9 + (v9 - 1) / 3 - 1;
v11 = func1(a4);
v12 = v10 - (v11 + (v11 - 1) / 3 - 1);
_gmpz_init_set(v16, a4);
_gmpz_init(v21);
_gmpz_init_set_ui(v17, 10LL);
_gmpz_cdiv_q(v21, v16, v17);
_gmpz_mul(v17, v17, v21);
if ( !v18 )
_gmpz_set_ui(v17, 10LL);
_gmpz_init_set_ui(v19, 1000LL);
_gmpz_cdiv_q(v21, v16, v19);
_gmpz_mul(v19, v19, v21);
if ( !v20 )
_gmpz_set_ui(v19, 1000LL);
_gmpz_sub_ui(a4, a4, a3);
if ( (unsigned int)rxe_seek(a1, a4) )
func2(100, "seek past end");
do
{
rxe_current(s, 100LL, a1);
if ( (a2 & 2) != 0 )
{
printf("%*s", v12, (const char *)&unk_52A);
func0(stdout, 0LL, (__int64)v16, " ", a6);
_gmpz_add_ui(v16, v16, 1LL);
if ( !(unsigned int)_gmpz_cmp(v16, v17) )
{
_gmpz_mul_ui(v17, v17, 10LL);
if ( (unsigned int)_gmpz_cmp(v16, v19) )
{
--v12;
}
else
{
v12 -= 2;
_gmpz_mul_ui(v19, v19, 1000LL);
}
}
}
puts(s);
result = rxe_iterate(a1);
if ( (_DWORD)result )
break;
if ( *(_DWORD *)(a5 + 4) )
{
_gmpz_sub_ui(a5, a5, 1LL);
result = *(unsigned int *)(a5 + 4);
if ( !(_DWORD)result )
break;
}
}
while ( (a2 & 1) == 0 );
return result;
}

original_code:
void enumerate(struct rxe *rxe, int flags, int offset, mpz_t from, mpz_t cnt, char sep)
{
    mpz_t final;
    __gmpz_init(final);
    if (((cnt)->_mp_size < 0 ? -1 : (cnt)->_mp_size > 0)) {
        __gmpz_add(final,from,cnt);
        __gmpz_sub_ui(final,final,1);
    } else {
        __gmpz_set(final,rxe->nitems);
    }
    __gmpz_sub_ui(final,final,1-offset);
    int nd = mpz_len(final);
    nd += (nd-1)/3-1;
    int nd0 = mpz_len(from);
    nd -= nd0+(nd0-1)/3-1;
    mpz_t count,step1,step2;
    __gmpz_init_set(count,from);
    mpz_t q;
    __gmpz_init(q);
    __gmpz_init_set_ui(step1,10);
    __gmpz_cdiv_q(q,count,step1);
    __gmpz_mul(step1,step1,q);
    if (!((step1)->_mp_size < 0 ? -1 : (step1)->_mp_size > 0)) __gmpz_set_ui(step1,10);
    __gmpz_init_set_ui(step2,1000);
    __gmpz_cdiv_q(q,count,step2);
    __gmpz_mul(step2,step2,q);
    if (!((step2)->_mp_size < 0 ? -1 : (step2)->_mp_size > 0)) __gmpz_set_ui(step2,1000);
    __gmpz_sub_ui(from,from,offset);
    if (rxe_seek(rxe,from)) die(100,"seek past end");
    for (;;) {
         char str[100 +1];
         rxe_current(str,100,rxe);
         if (flags & 2) {
            printf("%*s",nd,"");
            print_grouped(stdout,((void *)0),count," ",sep);
            __gmpz_add_ui(count,count,1);
            if (!__gmpz_cmp(count,step1)) {
                nd--; __gmpz_mul_ui(step1,step1,10);
                if (!__gmpz_cmp(count,step2)) {
                    nd--; __gmpz_mul_ui(step2,step2,1000);
                }
            }
         }
         printf("%s\n",str);
         if (!(!rxe_iterate(rxe))) break;
         if (((cnt)->_mp_size < 0 ? -1 : (cnt)->_mp_size > 0)) {
             __gmpz_sub_ui(cnt,cnt,1);
             if (!((cnt)->_mp_size < 0 ? -1 : (cnt)->_mp_size > 0)) break;
         }
         if (flags & 1) break;
    }
}

canonical_original_code:
void enumerate(struct rxe *rxe, int flags, int offset, struct __mpz_struct from[1], struct __mpz_struct cnt[1], char sep)
{
    struct __mpz_struct final[1];
    __gmpz_init(final);
    if (((cnt)->_mp_size < 0 ? -1 : (cnt)->_mp_size > 0)) {
        __gmpz_add(final,from,cnt);
        __gmpz_sub_ui(final,final,1);
    } else {
        __gmpz_set(final,rxe->nitems);
    }
    __gmpz_sub_ui(final,final,1-offset);
    int nd = mpz_len(final);
    nd += (nd-1)/3-1;
    int nd0 = mpz_len(from);
    nd -= nd0+(nd0-1)/3-1;
    struct __mpz_struct count[1]; struct __mpz_struct step1[1]; struct __mpz_struct step2[1];
    __gmpz_init_set(count,from);
    struct __mpz_struct q[1];
    __gmpz_init(q);
    __gmpz_init_set_ui(step1,10);
    __gmpz_cdiv_q(q,count,step1);
    __gmpz_mul(step1,step1,q);
    if (!((step1)->_mp_size < 0 ? -1 : (step1)->_mp_size > 0)) __gmpz_set_ui(step1,10);
    __gmpz_init_set_ui(step2,1000);
    __gmpz_cdiv_q(q,count,step2);
    __gmpz_mul(step2,step2,q);
    if (!((step2)->_mp_size < 0 ? -1 : (step2)->_mp_size > 0)) __gmpz_set_ui(step2,1000);
    __gmpz_sub_ui(from,from,offset);
    if (rxe_seek(rxe,from)) die(100,"seek past end");
    for (;;) {
         char str[-1];
         rxe_current(str,100,rxe);
         if (flags & 2) {
            printf("%*s",nd,"");
            print_grouped(stdout,((void *)0),count," ",sep);
            __gmpz_add_ui(count,count,1);
            if (!__gmpz_cmp(count,step1)) {
                nd--; __gmpz_mul_ui(step1,step1,10);
                if (!__gmpz_cmp(count,step2)) {
                    nd--; __gmpz_mul_ui(step2,step2,1000);
                }
            }
         }
         printf("%s\n",str);
         if (!(!rxe_iterate(rxe))) break;
         if (((cnt)->_mp_size < 0 ? -1 : (cnt)->_mp_size > 0)) {
             __gmpz_sub_ui(cnt,cnt,1);
             if (!((cnt)->_mp_size < 0 ? -1 : (cnt)->_mp_size > 0)) break;
         }
         if (flags & 1) break;
    }
}

variable_types: struct rxe { int nalts; enum rxe_parse_status { RXE_OK=0, RXE_INFINITE=1, RXE_TOO_MANY_PARENS=2, RXE_TOO_LITTLE_PARENS=3, RXE_LONE_QUANTIFIER=4, RXE_NESTED_QUANTIFIERS=5, RXE_UNTERMINATED_LITERAL=6, RXE_UNTERMINATED_CLASS=7, RXE_UNTERMINATED_REPEAT=8, RXE_UNTERMINATED_FLAGS=9, RXE_BAD_REPETITION=10, RXE_UNIMPLEMENTED=11, RXE_INVALID_BACKREF=12, RXE_INVALID_CONSTANT=13, RXE_UNTERMINATED_HEX_CONSTANT=14 } status; struct rxe_alt { int nnodes; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } nitems[1]; struct __mpz_struct start[1]; struct rxe_node { int len; char *str; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; int iterator; int is_backref; struct rxe *rxe; struct rxe_node *prev; struct rxe_node *next; } *curr; struct rxe_node *head; struct rxe_node *tail; struct rxe_alt *prev; struct rxe_alt *next; } *head; struct rxe_alt *tail; struct rxe_alt *curr; struct __mpz_struct nitems[1]; struct rxe_backref_table { int nbackrefs; int maxbackrefs; struct rxe **bkref; } *brt; int flags; } *

variable_types: flags int

variable_types: offset int

variable_types:
from
struct __mpz_struct [1]

variable_types:
cnt
struct __mpz_struct [1]

variable_types: sep char

variable_types: nd int

variable_types:
str
char [-1]


original_code:
struct rxe_node *rxe_new_node(struct rxe_alt *alt)
{
    struct rxe_node *node = ((struct rxe_node *)kmalloc(sizeof(struct rxe_node)*(1),"rxe_node.c",21));
    node->next = ((void *)0);
    node->prev = alt->tail;
    __gmpz_init(node->nitems);
    __gmpz_init(node->start);
    node->len = node->iterator = 0;
    node->is_backref = 0;
    node->str = ((void *)0);
    node->rxe = ((void *)0);
    alt->nnodes++;
    if (alt->tail) alt->tail->next = node;
    alt->tail = node;
    if (!alt->head) alt->head = node;
    if (!alt->curr) alt->curr = node;
    return node;
}

variable_types:
alt
struct rxe_alt *

return_type: struct rxe_node { int len; char *str; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } nitems[1]; struct __mpz_struct start[1]; int iterator; int is_backref; struct rxe { int nalts; enum rxe_parse_status { RXE_OK=0, RXE_INFINITE=1, RXE_TOO_MANY_PARENS=2, RXE_TOO_LITTLE_PARENS=3, RXE_LONE_QUANTIFIER=4, RXE_NESTED_QUANTIFIERS=5, RXE_UNTERMINATED_LITERAL=6, RXE_UNTERMINATED_CLASS=7, RXE_UNTERMINATED_REPEAT=8, RXE_UNTERMINATED_FLAGS=9, RXE_BAD_REPETITION=10, RXE_UNIMPLEMENTED=11, RXE_INVALID_BACKREF=12, RXE_INVALID_CONSTANT=13, RXE_UNTERMINATED_HEX_CONSTANT=14 } status; struct rxe_alt { int nnodes; struct __mpz_struct nitems[1]; struct __mpz_struct start[1]; struct rxe_node *curr; struct rxe_node *head; struct rxe_node *tail; struct rxe_alt *prev; struct rxe_alt *next; } *head; struct rxe_alt *tail; struct rxe_alt *curr; struct __mpz_struct nitems[1]; struct rxe_backref_table { int nbackrefs; int maxbackrefs; struct rxe **bkref; } *brt; int flags; } *rxe; struct rxe_node *prev; struct rxe_node *next; } *


original_code:
void rxe_free_node_data(struct rxe_node *node)
{
    if (node->rxe) {
        rxe_free(node->rxe);
        node->rxe = ((void *)0);
    }
    if (node->len) {
        free(node->str);
        node->len = 0;
        node->str = ((void *)0);
    }
}

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }

user_defined_types: enum rxe_parse_status { RXE_OK=0, RXE_INFINITE=1, RXE_TOO_MANY_PARENS=2, RXE_TOO_LITTLE_PARENS=3, RXE_LONE_QUANTIFIER=4, RXE_NESTED_QUANTIFIERS=5, RXE_UNTERMINATED_LITERAL=6, RXE_UNTERMINATED_CLASS=7, RXE_UNTERMINATED_REPEAT=8, RXE_UNTERMINATED_FLAGS=9, RXE_BAD_REPETITION=10, RXE_UNIMPLEMENTED=11, RXE_INVALID_BACKREF=12, RXE_INVALID_CONSTANT=13, RXE_UNTERMINATED_HEX_CONSTANT=14 }

user_defined_types: struct rxe_backref_table { int nbackrefs; int maxbackrefs; struct rxe **bkref; }


decompiled_code:
__int64 __fastcall rxe_free_node(__int64 a1)
{
rxe_free_node_data(a1);
return rxe_mem_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
func1(a1);
return rxe_mem_free(a1);
}

original_code:
void rxe_free_node(struct rxe_node *node)
{
    rxe_free_node_data(node);
    rxe_mem_free(node);
}


nrerror

repo: marcom/dss-opt

decompiled_code:
void __fastcall __noreturn nrerror(const char *a1)
{
fprintf(stderr, "\n%s\n", a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
fprintf(stderr, "\n%s\n", a1);
exit(0);
}

original_code:
void nrerror(char *message)       /* output message upon error */
{
    fprintf(stderr, "\n%s\n", message);
    exit(0);
}

variable_types:
message
char *


space

decompiled_code:
void *__fastcall space(size_t size)
{
void *result; // rax

result = calloc(1uLL, (unsigned int)size);
if ( !result )
{
fprintf(stderr, "SPACE: requested size: %d\n", (unsigned int)size);
nrerror("SPACE allocation failure -> no memory");
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(size_t size)
{
void *result; // rax

result = calloc(1uLL, (unsigned int)size);
if ( !result )
{
fprintf(stderr, "SPACE: requested size: %d\n", (unsigned int)size);
func7("SPACE allocation failure -> no memory");
}
return result;
}

original_code:
void *space(unsigned size)
{
    void *pointer;

    if ( (pointer = (void *) calloc(1, size)) == NULL) {
       fprintf(stderr,"SPACE: requested size: %d\n", size);
       nrerror("SPACE allocation failure -> no memory");
    }
    return  pointer;
}

canonical_original_code:
void *space(unsigned int size)
{
    void *pointer;

    if ( (pointer = (void *) calloc(1, size)) == NULL) {
       fprintf(stderr,"SPACE: requested size: %d\n", size);
       nrerror("SPACE allocation failure -> no memory");
    }
    return  pointer;
}

variable_types:
size
unsigned int

variable_types:
pointer
void *

return_type: void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er13
__int64 v4; // r12
char *v5; // rbp
char v6; // bl
size_t v7; // rax
void *v8; // r14
void *v9; // rdi
char *v10; // rdi
char s[2]; // [rsp+10h] [rbp-7568h] BYREF

v3 = 0;
v4 = 0LL;
v5 = 0LL;
while ( fgets(s, 30000, stdin) && *(_WORD *)s != 64 )
{
v6 = s[0];
v7 = strlen(s);
if ( v6 == 46 )
{
LABEL_9:
v8 = (void *)space(v7);
if ( (unsigned int)__isoc99_sscanf() == 2 )
{
++v3;
if ( v8 )
{
if ( !v5 )
{
v5 = (char *)space(0xAuLL);
sprintf(v5, "%d", v3);
}
((void (__fastcall *)(const char *, __int64, void *, char *))write_ct_file)("-", v4, v8, v5);
v9 = (void *)v4;
v4 = 0LL;
free(v9);
free(v8);
v10 = v5;
v5 = 0LL;
free(v10);
}
}
else
{
free(v8);
}
}
else if ( v6 <= 46 )
{
if ( (unsigned __int8)(v6 - 40) <= 1u )
goto LABEL_9;
LABEL_15:
v4 = space((unsigned int)(v7 + 1));
__isoc99_sscanf();
}
else
{
if ( v6 != 62 )
goto LABEL_15;
v5 = (char *)space(v7);
__isoc99_sscanf();
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er13
__int64 v4; // r12
char *v5; // rbp
char v6; // bl
size_t v7; // rax
void *v8; // r14
void *v9; // rdi
char *v10; // rdi
char s[2]; // [rsp+10h] [rbp-7568h] BYREF

v3 = 0;
v4 = 0LL;
v5 = 0LL;
while ( fgets(s, 30000, stdin) && *(_WORD *)s != 64 )
{
v6 = s[0];
v7 = strlen(s);
if ( v6 == 46 )
{
LABEL_9:
v8 = (void *)func8(v7);
if ( (unsigned int)__isoc99_sscanf() == 2 )
{
++v3;
if ( v8 )
{
if ( !v5 )
{
v5 = (char *)func8(0xAuLL);
sprintf(v5, "%d", v3);
}
((void (__fastcall *)(const char *, __int64, void *, char *))write_ct_file)("-", v4, v8, v5);
v9 = (void *)v4;
v4 = 0LL;
free(v9);
free(v8);
v10 = v5;
v5 = 0LL;
free(v10);
}
}
else
{
free(v8);
}
}
else if ( v6 <= 46 )
{
if ( (unsigned __int8)(v6 - 40) <= 1u )
goto LABEL_9;
LABEL_15:
v4 = func8((unsigned int)(v7 + 1));
__isoc99_sscanf();
}
else
{
if ( v6 != 62 )
goto LABEL_15;
v5 = (char *)func8(v7);
__isoc99_sscanf();
}
}
return 0;
}

original_code:
int main(void)
{
   char line[MAXLENGTH+1];
   char *string=NULL, *structure=NULL, *name=NULL;
   float energy;
   int n=0;

   while (fgets(line, MAXLENGTH, stdin)!=NULL) {
       if (strcmp(line,"@")==0) break;

       switch (line[0]) {
       case '>': name = (char *) space(strlen(line));
	 sscanf(line,"> %s", name);
	 break;
       case '.':
       case '(':
       case ')': structure = (char *) space(strlen(line));
	 if (sscanf(line,"%s (%f)", structure, &energy)!=2) {
	   free(structure); structure=NULL; break;
	 }
	 n++;
	 break;
       default: string = (char *) space(strlen(line)+1);
	 sscanf(line, "%s", string);
       }
       if (structure!=NULL) {
	 if (name==NULL) {
	   name = (char *) space(10);
	   sprintf(name,"%d",n);
	 }
	 write_ct_file("-", string, structure, name, energy);
      	 free(string);
	 free(structure);
	 free(name);
	 string = structure = name = NULL;
       }
   }
   return 0;
}

canonical_original_code:
int main()
{
   char line[-1];
   char *string = NULL; char *structure = NULL; char *name = NULL;
   float energy;
   int n = 0;

   while (fgets(line, MAXLENGTH, stdin)!=NULL) {
       if (strcmp(line,"@")==0) break;

       switch (line[0]) {
       case '>': name = (char *) space(strlen(line));
	 sscanf(line,"> %s", name);
	 break;
       case '.':
       case '(':
       case ')': structure = (char *) space(strlen(line));
	 if (sscanf(line,"%s (%f)", structure, &energy)!=2) {
	   free(structure); structure=NULL; break;
	 }
	 n++;
	 break;
       default: string = (char *) space(strlen(line)+1);
	 sscanf(line, "%s", string);
       }
       if (structure!=NULL) {
	 if (name==NULL) {
	   name = (char *) space(10);
	   sprintf(name,"%d",n);
	 }
	 write_ct_file("-", string, structure, name, energy);
      	 free(string);
	 free(structure);
	 free(name);
	 string = structure = name = NULL;
       }
   }
   return 0;
}

variable_types:
line
char [-1]

variable_types:
string
char *

variable_types:
structure
char *

variable_types:
name
char *

variable_types: energy float

variable_types: n int


original_code:
static double
calc_dmin(double **p, size_t ndim, size_t i)
{
    size_t j, k;
    double d, di_min = 0;
    for (j = 0; j < ndim; j++) {
        d = 0;
        for (k = 0; k < ndim; k++) {
            if (k != j)
                d += p[i][k] * p[i][k];
            else
                d += (p[i][k] - 1) * (p[i][k] - 1);
        }
        d = sqrt(d);
        if (j == 0 || d < di_min)
            di_min = d;
    }
    return di_min;
}

canonical_original_code:
static double calc_dmin(double **p, unsigned long ndim, unsigned long i)
{
    unsigned long j; unsigned long k;
    double d; double di_min = 0;
    for (j = 0; j < ndim; j++) {
        d = 0;
        for (k = 0; k < ndim; k++) {
            if (k != j)
                d += p[i][k] * p[i][k];
            else
                d += (p[i][k] - 1) * (p[i][k] - 1);
        }
        d = sqrt(d);
        if (j == 0 || d < di_min)
            di_min = d;
    }
    return di_min;
}

variable_types:
p
double **

variable_types:
ndim
unsigned long

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types:
k
unsigned long

variable_types: d double

return_type: double


decompiled_code:
__int64 __fastcall system_is_exploded(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax
unsigned int v5; // er8
__int64 v6; // rcx
__int64 v7; // rax
double v8; // xmm0_8

v4 = dary2d_is_finite();
v5 = 1;
if ( (_BYTE)v4 )
{
v5 = v4;
v6 = 0LL;
if ( a2 )
{
while ( !a3 )
{
LABEL_9:
if ( a2 == ++v6 )
goto LABEL_10;
}
v7 = 0LL;
while ( 1 )
{
v8 = *(double *)(*(_QWORD *)(a1 + 8 * v6) + 8 * v7);
if ( v8 < -1.0 || v8 > 2.0 )
break;
if ( a3 == ++v7 )
goto LABEL_9;
}
}
else
{
LABEL_10:
v5 = 0;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax
unsigned int v5; // er8
__int64 v6; // rcx
__int64 v7; // rax
double v8; // xmm0_8

v4 = dary2d_is_finite();
v5 = 1;
if ( (_BYTE)v4 )
{
v5 = v4;
v6 = 0LL;
if ( a2 )
{
while ( !a3 )
{
LABEL_9:
if ( a2 == ++v6 )
goto LABEL_10;
}
v7 = 0LL;
while ( 1 )
{
v8 = *(double *)(*(_QWORD *)(a1 + 8 * v6) + 8 * v7);
if ( v8 < -1.0 || v8 > 2.0 )
break;
if ( a3 == ++v7 )
goto LABEL_9;
}
}
else
{
LABEL_10:
v5 = 0;
}
}
return v5;
}

original_code:
_Bool
system_is_exploded(double **p, size_t n1, size_t n2)
{
    size_t i, j;
    if (! dary2d_is_finite(p, n1, n2))
        return 1;
    for (i = 0; i < n1; i++)
        for (j = 0; j < n2; j++)
            if (p[i][j] < -1.0 || p[i][j] > 2.0)
                return 1;
    return 0;
}

canonical_original_code:
_Bool system_is_exploded(double **p, unsigned long n1, unsigned long n2)
{
    unsigned long i; unsigned long j;
    if (! dary2d_is_finite(p, n1, n2))
        return 1;
    for (i = 0; i < n1; i++)
        for (j = 0; j < n2; j++)
            if (p[i][j] < -1.0 || p[i][j] > 2.0)
                return 1;
    return 0;
}


decompiled_code:
double __fastcall calc_entropy(_QWORD *a1, __int64 a2, __int64 a3)
{
double v4; // rbx
__int64 i; // r13
__int64 v7; // rbx
double v8; // xmm0_8
double v9; // xmm1_8
double v10; // xmm2_8
double v12; // [rsp+0h] [rbp-30h]

v4 = *(double *)&LC4;
v12 = 0.0;
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v7 = 0LL;
if ( a3 )
{
do
{
v8 = *(double *)(*a1 + 8 * v7++);
v12 = plogp_sane(v8) + v12;
}
while ( a3 != v7 );
}
++a1;
}
*(_QWORD *)&v4 = *(_QWORD *)&v12 ^ LC5;
}
if ( a3 < 0 )
{
v9 = log((double)(int)(a3 & 1 | ((unsigned __int64)a3 >> 1)) + (double)(int)(a3 & 1 | ((unsigned __int64)a3 >> 1)));
if ( a2 >= 0 )
goto LABEL_9;
LABEL_12:
v10 = (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1)) + (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1));
return v4 / v10 / v9;
}
v9 = log((double)(int)a3);
if ( a2 < 0 )
goto LABEL_12;
LABEL_9:
v10 = (double)(int)a2;
return v4 / v10 / v9;
}

original_code:
double
calc_entropy(double **p, size_t n1, size_t n2)
{
    size_t i, j;
    double s = 0;
    for (i = 0; i < n1; i++)
        for (j = 0; j < n2; j++)
            s += plogp_sane(p[i][j]);
    s = - s / n1 / log(n2);
    return s;
}

canonical_original_code:
double calc_entropy(double **p, unsigned long n1, unsigned long n2)
{
    unsigned long i; unsigned long j;
    double s = 0;
    for (i = 0; i < n1; i++)
        for (j = 0; j < n2; j++)
            s += plogp_sane(p[i][j]);
    s = - s / n1 / log(n2);
    return s;
}

variable_types: s double


decompiled_code:
__int64 __fastcall is_bad_bp(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4, unsigned int a5)
{
int v5; // eax
int v7; // eax
unsigned __int8 v8; // [rsp+0h] [rbp-2h]

v8 = *(_BYTE *)(a1 + a3);
v5 = *(unsigned __int8 *)(a1 + a2);
if ( v5 == 67 && v8 == 71 )
return 0;
if ( v5 != 71 )
{
LABEL_6:
if ( v5 == 85 && v8 == 71 )
return 0;
if ( v5 == 65 && v8 == 85 )
return 0;
v7 = v5 - 85;
if ( !v7 )
{
v7 = v8 - 65;
if ( v8 == 65 )
v7 = 0;
}
LOBYTE(a5) = v7 != 0;
return a5;
}
if ( v8 != 67 )
{
if ( v8 == 85 )
return 0;
goto LABEL_6;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4, unsigned int a5)
{
int v5; // eax
int v7; // eax
unsigned __int8 v8; // [rsp+0h] [rbp-2h]

v8 = *(_BYTE *)(a1 + a3);
v5 = *(unsigned __int8 *)(a1 + a2);
if ( v5 == 67 && v8 == 71 )
return 0;
if ( v5 != 71 )
{
LABEL_6:
if ( v5 == 85 && v8 == 71 )
return 0;
if ( v5 == 65 && v8 == 85 )
return 0;
v7 = v5 - 85;
if ( !v7 )
{
v7 = v8 - 65;
if ( v8 == 65 )
v7 = 0;
}
LOBYTE(a5) = v7 != 0;
return a5;
}
if ( v8 != 67 )
{
if ( v8 == 85 )
return 0;
goto LABEL_6;
}
return 0LL;
}

original_code:
_Bool
is_bad_bp(char *seq, uint i, uint j)
{
    char bp[3];
    bp[2] = '\0';
    bp[0] = seq[i];
    bp[1] = seq[j];
    if (strcmp(bp, "CG") && strcmp(bp, "GC") &&
        strcmp(bp, "GU") && strcmp(bp, "UG") &&
        strcmp(bp, "AU") && strcmp(bp, "UA")) {
        return 1;
    }
    return 0;
}

canonical_original_code:
_Bool is_bad_bp(char *seq, unsigned int i, unsigned int j)
{
    char bp[3];
    bp[2] = '\0';
    bp[0] = seq[i];
    bp[1] = seq[j];
    if (strcmp(bp, "CG") && strcmp(bp, "GC") &&
        strcmp(bp, "GU") && strcmp(bp, "UG") &&
        strcmp(bp, "AU") && strcmp(bp, "UA")) {
        return 1;
    }
    return 0;
}

variable_types:
seq
char *

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
bp
char [3]


decompiled_code:
void __fastcall show_bad_bp(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
unsigned __int64 i; // rbx
unsigned int v8; // er9
__int64 v9; // rcx
unsigned int v10; // er9
unsigned int v11; // er10
unsigned __int64 v12; // rsi

if ( a3 )
{
for ( i = 0LL; i != a3; ++i )
{
while ( 1 )
{
v8 = *(_DWORD *)(a2 + 4 * i);
if ( v8 != 0x7FFFFFFF && v8 >= i && (unsigned __int8)is_bad_bp(a1, i, v8, v8, a5) )
break;
if ( a3 == ++i )
return;
}
v11 = *(char *)(a1 + i);
v12 = i;
printf("bad bp: %zu %u: %c%c\n", v12, v10, v11, (unsigned int)*(char *)(a1 + v9));
}
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
unsigned __int64 i; // rbx
unsigned int v8; // er9
__int64 v9; // rcx
unsigned int v10; // er9
unsigned int v11; // er10
unsigned __int64 v12; // rsi

if ( a3 )
{
for ( i = 0LL; i != a3; ++i )
{
while ( 1 )
{
v8 = *(_DWORD *)(a2 + 4 * i);
if ( v8 != 0x7FFFFFFF && v8 >= i && (unsigned __int8)func4(a1, i, v8, v8, a5) )
break;
if ( a3 == ++i )
return;
}
v11 = *(char *)(a1 + i);
v12 = i;
printf("bad bp: %zu %u: %c%c\n", v12, v10, v11, (unsigned int)*(char *)(a1 + v9));
}
}
}

original_code:
void
show_bad_bp(char *seq, uint *pairs, size_t n)
{
    size_t i;
    for (i = 0; i < n; i++) {
        if (pairs[i] == ((0x7fffffff * 2U + 1U) / 2) || i > pairs[i])
            continue;
        if (is_bad_bp(seq, i, pairs[i]))
            printf("bad bp: %zu %u: %c%c\n", i, pairs[i],
                   seq[i], seq[pairs[i]]);
    }
}

canonical_original_code:
void show_bad_bp(char *seq, unsigned int *pairs, unsigned long n)
{
    unsigned long i;
    for (i = 0; i < n; i++) {
        if (pairs[i] == ((0x7fffffff * 2U + 1U) / 2) || i > pairs[i])
            continue;
        if (is_bad_bp(seq, i, pairs[i]))
            printf("bad bp: %zu %u: %c%c\n", i, pairs[i],
                   seq[i], seq[pairs[i]]);
    }
}

variable_types:
pairs
unsigned int *

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall fix_bad_bp(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 v7; // r11
unsigned __int64 i; // rcx
unsigned int v9; // edx

v7 = 0LL;
if ( a3 )
{
for ( i = 0LL; i != a3; ++i )
{
v9 = *(_DWORD *)(a2 + 4 * i);
if ( v9 != 0x7FFFFFFF && v9 >= i && (unsigned __int8)is_bad_bp(a1, i, v9, i, a5) )
{
*(_BYTE *)(a1 + i) = 71;
++v7;
*(_BYTE *)(a1 + *(unsigned int *)(a2 + 4 * i)) = 67;
}
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 v7; // r11
unsigned __int64 i; // rcx
unsigned int v9; // edx

v7 = 0LL;
if ( a3 )
{
for ( i = 0LL; i != a3; ++i )
{
v9 = *(_DWORD *)(a2 + 4 * i);
if ( v9 != 0x7FFFFFFF && v9 >= i && (unsigned __int8)func4(a1, i, v9, i, a5) )
{
*(_BYTE *)(a1 + i) = 71;
++v7;
*(_BYTE *)(a1 + *(unsigned int *)(a2 + 4 * i)) = 67;
}
}
}
return v7;
}

original_code:
size_t
fix_bad_bp(char *seq, uint *pairs, size_t n)
{
    size_t i, nfix = 0;
    for (i = 0; i < n; i++) {
        if (pairs[i] == ((0x7fffffff * 2U + 1U) / 2) || i > pairs[i])
            continue;
        if (is_bad_bp(seq, i, pairs[i])) {
            seq[i] = 'G';
            seq[pairs[i]] = 'C';
            nfix++;
        }
    }
    return nfix;
}

canonical_original_code:
unsigned long fix_bad_bp(char *seq, unsigned int *pairs, unsigned long n)
{
    unsigned long i; unsigned long nfix = 0;
    for (i = 0; i < n; i++) {
        if (pairs[i] == ((0x7fffffff * 2U + 1U) / 2) || i > pairs[i])
            continue;
        if (is_bad_bp(seq, i, pairs[i])) {
            seq[i] = 'G';
            seq[pairs[i]] = 'C';
            nfix++;
        }
    }
    return nfix;
}

variable_types:
nfix
unsigned long

return_type: unsigned long


original_code:
void
show_bad_prob(double **p, size_t n, size_t ndim, _Bool verbose)
{
    size_t i;
    double di_min, d_max = 0, d_avg = 0;
    for (i = 0; i < n; i++) {
        di_min = calc_dmin(p, ndim, i);
        if (di_min > d_max)
            d_max = di_min;
        d_avg += di_min;
    }
    d_avg /= n;
    if (verbose) {
        printf("p: d_max = %f\n", d_max);
        printf("p: d_avg = %f\n", d_avg);
        printf("\n");
    }
}

canonical_original_code:
void show_bad_prob(double **p, unsigned long n, unsigned long ndim, _Bool verbose)
{
    unsigned long i;
    double di_min; double d_max = 0; double d_avg = 0;
    for (i = 0; i < n; i++) {
        di_min = calc_dmin(p, ndim, i);
        if (di_min > d_max)
            d_max = di_min;
        d_avg += di_min;
    }
    d_avg /= n;
    if (verbose) {
        printf("p: d_max = %f\n", d_max);
        printf("p: d_avg = %f\n", d_avg);
        printf("\n");
    }
}


decompiled_code:
__int64 __fastcall print_for_movie(__int64 a1, __int64 a2, __int64 a3, const char *a4)
{
pseq_to_str();
puts(a4);
return dary2d_print(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3, const char *a4)
{
pseq_to_str();
puts(a4);
return dary2d_print(a1, a2, a3);
}

original_code:
void
print_for_movie(double **p, size_t n, size_t ndim, char *seq)
{
    pseq_to_str(p, n, ndim, seq);
    printf("%s\n", seq);
    dary2d_print(p, n, ndim);
}

canonical_original_code:
void print_for_movie(double **p, unsigned long n, unsigned long ndim, char *seq)
{
    pseq_to_str(p, n, ndim, seq);
    printf("%s\n", seq);
    dary2d_print(p, n, ndim);
}


original_code:
void
md_remove_net_momentum_no_rescale(uint n, uint ndim, double **v, double *mass)
{
    uint i, j;
    double *psum = xmalloc(ndim * sizeof(*psum));
    for (i = 0; i < ndim; i++)
        psum[i] = 0;
    for (i = 0; i < n; i++)
        for (j = 0; j < ndim; j++)
            psum[j] += v[i][j] * mass[i];
    for (j = 0; j < ndim; j++)
        psum[j] /= n;
    for (i = 0; i < n; i++)
        for (j = 0; j < ndim; j++)
            v[i][j] -= psum[j] / mass[i];
    free(psum);
}

canonical_original_code:
void md_remove_net_momentum_no_rescale(unsigned int n, unsigned int ndim, double **v, double *mass)
{
    unsigned int i; unsigned int j;
    double *psum = xmalloc(ndim * sizeof(*psum));
    for (i = 0; i < ndim; i++)
        psum[i] = 0;
    for (i = 0; i < n; i++)
        for (j = 0; j < ndim; j++)
            psum[j] += v[i][j] * mass[i];
    for (j = 0; j < ndim; j++)
        psum[j] /= n;
    for (i = 0; i < n; i++)
        for (j = 0; j < ndim; j++)
            v[i][j] -= psum[j] / mass[i];
    free(psum);
}

variable_types:
n
unsigned int

variable_types:
ndim
unsigned int

variable_types:
v
double **

variable_types:
mass
double *

variable_types:
psum
double *


decompiled_code:
void __fastcall md_rescale_temperature(int a1, int a2, __int64 a3, __int64 a4, double a5, double a6, double a7)
{
double v8; // xmm6_8
double v9; // xmm2_8
double **v10; // rcx
double *v11; // rax
__int64 v12; // rdx
double v13; // xmm0_8

v8 = a7 / COERCE_DOUBLE(md_calc_temperature(a1, a2, a3, a4, a5, a6));
if ( v8 < 0.0 )
v9 = sqrt(v8);
else
v9 = sqrt(v8);
if ( a1 )
{
v10 = (double **)a3;
do
{
if ( a2 )
{
v11 = *v10;
v12 = (__int64)&(*v10)[(unsigned int)(a2 - 1) + 1];
do
{
v13 = *v11++;
*(v11 - 1) = v13 * v9;
}
while ( (double *)v12 != v11 );
}
++v10;
}
while ( v10 != (double **)(a3 + 8LL * (unsigned int)(a1 - 1) + 8) );
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2, __int64 a3, __int64 a4, double a5, double a6, double a7)
{
double v8; // xmm6_8
double v9; // xmm2_8
double **v10; // rcx
double *v11; // rax
__int64 v12; // rdx
double v13; // xmm0_8

v8 = a7 / COERCE_DOUBLE(md_calc_temperature(a1, a2, a3, a4, a5, a6));
if ( v8 < 0.0 )
v9 = sqrt(v8);
else
v9 = sqrt(v8);
if ( a1 )
{
v10 = (double **)a3;
do
{
if ( a2 )
{
v11 = *v10;
v12 = (__int64)&(*v10)[(unsigned int)(a2 - 1) + 1];
do
{
v13 = *v11++;
*(v11 - 1) = v13 * v9;
}
while ( (double *)v12 != v11 );
}
++v10;
}
while ( v10 != (double **)(a3 + 8LL * (unsigned int)(a1 - 1) + 8) );
}
}

original_code:
void
md_rescale_temperature(uint n, uint ndim, double **v, double *mass,
                       double kb, double ndof, double T_desired)
{
    uint i, j;
    double T, scale;
    T = md_calc_temperature(n, ndim, v, mass, kb, ndof);
    scale = sqrt(T_desired / T);
    for (i = 0; i < n; i++)
        for (j = 0; j < ndim; j++)
            v[i][j] *= scale;
}

canonical_original_code:
void md_rescale_temperature(unsigned int n, unsigned int ndim, double **v, double *mass, double kb, double ndof, double T_desired)
{
    unsigned int i; unsigned int j;
    double T; double scale;
    T = md_calc_temperature(n, ndim, v, mass, kb, ndof);
    scale = sqrt(T_desired / T);
    for (i = 0; i < n; i++)
        for (j = 0; j < ndim; j++)
            v[i][j] *= scale;
}

variable_types: kb double

variable_types: ndof double

variable_types: T double

variable_types: scale double


decompiled_code:
void __fastcall md_init_velocities_random(int a1, unsigned int a2, __int64 *a3, double *a4, double a5, double a6, double a7)
{
__int64 *v9; // r12
__int64 *v10; // r14
__int64 v11; // rbx
__int64 v12; // rsi

v9 = a3;
if ( a1 )
{
v10 = a3;
v11 = (__int64)&a3[(unsigned int)(a1 - 1) + 1];
do
{
v12 = *v10++;
random_dvec_uniform_direction(a2, v12);
}
while ( v10 != (__int64 *)v11 );
}
md_remove_net_momentum_no_rescale(a1, a2, v9, a4);
md_rescale_temperature(a1, a2, (__int64)v9, (__int64)a4, a5, a6, a7);
}

original_code:
void
md_init_velocities_random(uint n, uint ndim, double **v, double *mass,
                          double kb, double ndof, double T)
{
    uint i;
    for (i = 0; i < n; i++)
        random_dvec_uniform_direction(ndim, v[i]);
    md_remove_net_momentum_no_rescale(n, ndim, v, mass);
    md_rescale_temperature(n, ndim, v, mass, kb, ndof, T);
}

canonical_original_code:
void md_init_velocities_random(unsigned int n, unsigned int ndim, double **v, double *mass, double kb, double ndof, double T)
{
    unsigned int i;
    for (i = 0; i < n; i++)
        random_dvec_uniform_direction(ndim, v[i]);
    md_remove_net_momentum_no_rescale(n, ndim, v, mass);
    md_rescale_temperature(n, ndim, v, mass, kb, ndof, T);
}


decompiled_code:
void __fastcall md_init_velocities_maxwell_boltzmann(int a1, unsigned int a2, __int64 *a3, double *a4, double a5, double a6, double a7)
{
__int64 *v7; // rbx
__int64 v8; // r13
__int64 v9; // r15
double *v10; // r14
__int64 *v11; // [rsp+8h] [rbp-60h]

v11 = a3;
if ( a1 )
{
v7 = a3;
v8 = (__int64)&a3[(unsigned int)(a1 - 1) + 1];
do
{
v9 = 0LL;
if ( a2 )
{
do
{
v10 = (double *)(v9 + *v7);
v9 += 8LL;
*v10 = random_double_normal(0.0, 1.0);
}
while ( 8LL * (a2 - 1) + 8 != v9 );
}
++v7;
}
while ( v7 != (__int64 *)v8 );
}
md_remove_net_momentum_no_rescale(a1, a2, v11, a4);
md_rescale_temperature(a1, a2, (__int64)v11, (__int64)a4, a5, a6, a7);
}

original_code:
void
md_init_velocities_maxwell_boltzmann(uint n, uint ndim, double **v,
                                     double *mass, double kb, double ndof,
                                     double T)
{
    uint i, j;
    for (i = 0; i < n; i++)
        for (j = 0; j < ndim; j++)
            v[i][j] = random_double_normal(0, 1);
    md_remove_net_momentum_no_rescale(n, ndim, v, mass);
    md_rescale_temperature(n, ndim, v, mass, kb, ndof, T);
}

canonical_original_code:
void md_init_velocities_maxwell_boltzmann(unsigned int n, unsigned int ndim, double **v, double *mass, double kb, double ndof, double T)
{
    unsigned int i; unsigned int j;
    for (i = 0; i < n; i++)
        for (j = 0; j < ndim; j++)
            v[i][j] = random_double_normal(0, 1);
    md_remove_net_momentum_no_rescale(n, ndim, v, mass);
    md_rescale_temperature(n, ndim, v, mass, kb, ndof, T);
}


decompiled_code:
void __fastcall md_rescale_temperature_berendsen(int a1, int a2, __int64 a3, __int64 a4, double a5, double a6, double a7, double a8, double a9)
{
double v10; // xmm1_8
double v11; // xmm1_8
double **v12; // rcx
double *v13; // rax
__int64 v14; // rdx
double v15; // xmm0_8

v10 = (a7 / COERCE_DOUBLE(md_calc_temperature(a1, a2, a3, a4, a5, a6)) - 1.0) * (a8 / a9) + 1.0;
if ( v10 < 0.0 )
v11 = sqrt(v10);
else
v11 = sqrt(v10);
if ( a1 )
{
v12 = (double **)a3;
do
{
if ( a2 )
{
v13 = *v12;
v14 = (__int64)&(*v12)[(unsigned int)(a2 - 1) + 1];
do
{
v15 = *v13++;
*(v13 - 1) = v15 * v11;
}
while ( (double *)v14 != v13 );
}
++v12;
}
while ( v12 != (double **)(a3 + 8LL * (unsigned int)(a1 - 1) + 8) );
}
}

canonical_decompiled_code:
void __fastcall func4(int a1, int a2, __int64 a3, __int64 a4, double a5, double a6, double a7, double a8, double a9)
{
double v10; // xmm1_8
double v11; // xmm1_8
double **v12; // rcx
double *v13; // rax
__int64 v14; // rdx
double v15; // xmm0_8

v10 = (a7 / COERCE_DOUBLE(md_calc_temperature(a1, a2, a3, a4, a5, a6)) - 1.0) * (a8 / a9) + 1.0;
if ( v10 < 0.0 )
v11 = sqrt(v10);
else
v11 = sqrt(v10);
if ( a1 )
{
v12 = (double **)a3;
do
{
if ( a2 )
{
v13 = *v12;
v14 = (__int64)&(*v12)[(unsigned int)(a2 - 1) + 1];
do
{
v15 = *v13++;
*(v13 - 1) = v15 * v11;
}
while ( (double *)v14 != v13 );
}
++v12;
}
while ( v12 != (double **)(a3 + 8LL * (unsigned int)(a1 - 1) + 8) );
}
}

original_code:
void
md_rescale_temperature_berendsen(uint n, uint ndim, double **v, double *mass,
                                 double kb, double ndof, double T_desired,
                                 double timestep, double tau)
{
    uint i, j;
    double T, scale;
    T = md_calc_temperature(n, ndim, v, mass, kb, ndof);
    scale = sqrt(1 + (timestep / tau) * (T_desired / T - 1));
    for (i = 0; i < n; i++)
        for (j = 0; j < ndim; j++)
            v[i][j] *= scale;
}

canonical_original_code:
void md_rescale_temperature_berendsen(unsigned int n, unsigned int ndim, double **v, double *mass, double kb, double ndof, double T_desired, double timestep, double tau)
{
    unsigned int i; unsigned int j;
    double T; double scale;
    T = md_calc_temperature(n, ndim, v, mass, kb, ndof);
    scale = sqrt(1 + (timestep / tau) * (T_desired / T - 1));
    for (i = 0; i < n; i++)
        for (j = 0; j < ndim; j++)
            v[i][j] *= scale;
}

variable_types: timestep double

variable_types: tau double


original_code:
void
md_integrate_step_leapfrog(uint n, uint ndim, double **r, double **v,
                           double **gradU, double *mass, double timestep)
{
    uint i, j;
    for (i = 0; i < n; i++)
        for (j = 0; j < ndim; j++) {
            v[i][j] -= timestep * gradU[i][j] / mass[i];
            r[i][j] += timestep * v[i][j];
        }
}

canonical_original_code:
void md_integrate_step_leapfrog(unsigned int n, unsigned int ndim, double **r, double **v, double **gradU, double *mass, double timestep)
{
    unsigned int i; unsigned int j;
    for (i = 0; i < n; i++)
        for (j = 0; j < ndim; j++) {
            v[i][j] -= timestep * gradU[i][j] / mass[i];
            r[i][j] += timestep * v[i][j];
        }
}

variable_types:
r
double **

variable_types:
gradU
double **

variable_types:
i
unsigned int


decompiled_code:
// attributes: thunk
void random_seed(unsigned int seed)
{
srand(seed);
}

canonical_decompiled_code:
void func0(unsigned int seed)
{
srand(seed);
}

original_code:
void
random_seed(uint seed)
{
    srand(seed);
}

variable_types:
seed
unsigned int


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

gettimeofday(&v1, 0LL);
return LODWORD(v1.tv_usec);
}

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

gettimeofday(&v1, 0LL);
return LODWORD(v1.tv_usec);
}

original_code:
uint
random_get_seedval_from_current_time()
{
    struct timeval tv;
    gettimeofday(&tv, ((void *)0));
    return tv.tv_usec;
}

canonical_original_code:
unsigned int random_get_seedval_from_current_time()
{
    struct timeval tv;
    gettimeofday(&tv, ((void *)0));
    return tv.tv_usec;
}

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

return_type: unsigned int


decompiled_code:
void random_seed_with_current_time()
{
unsigned int v0; // eax

v0 = random_get_seedval_from_current_time();
random_seed(v0);
}

canonical_decompiled_code:
void func2()
{
unsigned int v0; // eax

v0 = func1();
func0(v0);
}

original_code:
void
random_seed_with_current_time()
{
    random_seed(random_get_seedval_from_current_time());
}


decompiled_code:
double random_double_uniform()
{
return (double)rand() / 2147483647.0;
}

canonical_decompiled_code:
double func3()
{
return (double)rand() / 2147483647.0;
}

original_code:
double
random_double_uniform()
{
    return ((double) rand()) / ((double) 2147483647);
}


decompiled_code:
__int64 __fastcall random_uint(unsigned int a1, unsigned int a2)
{
double v2; // xmm0_8
__int64 result; // rax

if ( a1 > a2 )
_assert_fail("a <= b", "ctools/random.c", 0x2Eu, "random_uint");
v2 = (double)(int)(a2 + 1 - a1) * random_double_uniform();
result = a1 + (int)v2;
if ( __CFADD__(a1, (int)v2) || a2 < (unsigned int)result )
_assert_fail("a <= r && r <= b", "ctools/random.c", 0x35u, "random_uint");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2)
{
double v2; // xmm0_8
__int64 result; // rax

if ( a1 > a2 )
_assert_fail("a <= b", "ctools/random.c", 0x2Eu, "random_uint");
v2 = (double)(int)(a2 + 1 - a1) * func3();
result = a1 + (int)v2;
if ( __CFADD__(a1, (int)v2) || a2 < (unsigned int)result )
_assert_fail("a <= r && r <= b", "ctools/random.c", 0x35u, "random_uint");
return result;
}

original_code:
uint
random_uint(uint a, uint b)
{
    uint r;
    ((a <= b) ? (void) (0) : __assert_fail ("a <= b", "ctools/random.c", 46, __extension__ __PRETTY_FUNCTION__));
    r = a + (uint) ((b - a + 1) * random_double_uniform());
    ((a <= r && r <= b) ? (void) (0) : __assert_fail ("a <= r && r <= b", "ctools/random.c", 53, __extension__ __PRETTY_FUNCTION__));
    return r;
}

canonical_original_code:
unsigned int random_uint(unsigned int a, unsigned int b)
{
    unsigned int r;
    ((a <= b) ? (void) (0) : __assert_fail ("a <= b", "ctools/random.c", 46, __extension__ __PRETTY_FUNCTION__));
    r = a + (uint) ((b - a + 1) * random_double_uniform());
    ((a <= r && r <= b) ? (void) (0) : __assert_fail ("a <= r && r <= b", "ctools/random.c", 53, __extension__ __PRETTY_FUNCTION__));
    return r;
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
r
unsigned int


decompiled_code:
double __fastcall random_double_normal(double a1, double a2)
{
double v2; // xmm0_8
double v3; // xmm0_8
double v4; // xmm2_8
double v5; // xmm0_8
double v6; // xmm0_8
double v8; // [rsp+8h] [rbp-20h]
double v9; // [rsp+8h] [rbp-20h]

do
{
do
{
v2 = random_double_uniform();
v8 = v2 + v2 - 1.0;
v3 = random_double_uniform();
v4 = v8 * v8 + (v3 + v3 - 1.0) * (v3 + v3 - 1.0);
}
while ( v4 >= 1.0 );
}
while ( v4 == 0.0 );
v9 = v8 * a2;
v5 = log(v4) * -2.0 / v4;
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
return v6 * v9 + a1;
}

canonical_decompiled_code:
double __fastcall func5(double a1, double a2)
{
double v2; // xmm0_8
double v3; // xmm0_8
double v4; // xmm2_8
double v5; // xmm0_8
double v6; // xmm0_8
double v8; // [rsp+8h] [rbp-20h]
double v9; // [rsp+8h] [rbp-20h]

do
{
do
{
v2 = func3();
v8 = v2 + v2 - 1.0;
v3 = func3();
v4 = v8 * v8 + (v3 + v3 - 1.0) * (v3 + v3 - 1.0);
}
while ( v4 >= 1.0 );
}
while ( v4 == 0.0 );
v9 = v8 * a2;
v5 = log(v4) * -2.0 / v4;
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
return v6 * v9 + a1;
}

original_code:
double
random_double_normal(double mu, double sigma)
{
    double v1, v2, s;
    do {
        v1 = 2.0 * random_double_uniform() - 1.0;
        v2 = 2.0 * random_double_uniform() - 1.0;
        s = v1 * v1 + v2 * v2;
    } while (s >= 1.0 || s == 0.0);
    return mu + sigma * v1 * sqrt(-2.0 * log(s) / s);
}

canonical_original_code:
double random_double_normal(double mu, double sigma)
{
    double v1; double v2; double s;
    do {
        v1 = 2.0 * random_double_uniform() - 1.0;
        v2 = 2.0 * random_double_uniform() - 1.0;
        s = v1 * v1 + v2 * v2;
    } while (s >= 1.0 || s == 0.0);
    return mu + sigma * v1 * sqrt(-2.0 * log(s) / s);
}

variable_types: mu double

variable_types: sigma double

variable_types: s double


decompiled_code:
void __fastcall random_dvec_uniform_direction(int a1, double *a2)
{
double *v2; // r12
double *v3; // rbp
__int64 v4; // rbx
double *v5; // r15
double v6; // xmm1_8
double v7; // xmm0_8
double v8; // xmm0_8
double v9; // xmm1_8

v2 = a2 + 1;
v3 = a2;
v4 = (__int64)&a2[(unsigned int)(a1 - 1) + 1];
do
{
do
{
v5 = a2;
v6 = 0.0;
}
while ( !a1 );
do
{
++v5;
v7 = random_double_uniform();
v8 = v7 + v7 - 1.0;
*(v5 - 1) = v8;
v6 = v6 + v8 * v8;
}
while ( v5 != (double *)v4 );
}
while ( v6 == 0.0 || v6 > 1.0 );
if ( v6 < 0.0 )
v9 = sqrt(v6);
else
v9 = sqrt(v6);
while ( 1 )
{
*v3 = *v3 * (1.0 / v9);
v3 = v2;
if ( v2 == (double *)v4 )
break;
++v2;
}
}

original_code:
void
random_dvec_uniform_direction(uint ndim, double *v)
{
    uint i;
    double len2, scale, tmp;
    while (1) {
        len2 = 0;
        for (i = 0; i < ndim; i++) {
            tmp = 2 * random_double_uniform() - 1;
            v[i] = tmp;
            len2 += tmp * tmp;
        }
        if (len2 <= 1 && len2 != 0) {
            scale = 1 / sqrt(len2);
            for (i = 0; i < ndim; i++)
                v[i] *= scale;
            break;
        }
    }
}

canonical_original_code:
void random_dvec_uniform_direction(unsigned int ndim, double *v)
{
    unsigned int i;
    double len2; double scale; double tmp;
    while (1) {
        len2 = 0;
        for (i = 0; i < ndim; i++) {
            tmp = 2 * random_double_uniform() - 1;
            v[i] = tmp;
            len2 += tmp * tmp;
        }
        if (len2 <= 1 && len2 != 0) {
            scale = 1 / sqrt(len2);
            for (i = 0; i < ndim; i++)
                v[i] *= scale;
            break;
        }
    }
}

variable_types:
ndim
unsigned int

variable_types:
v
double *

variable_types: tmp double


decompiled_code:
void __fastcall x_ensure_positive(const char *a1, const char *a2, double a3)
{
if ( a3 <= 0.0 )
{
printf("%s: %s must be > 0 (is %f)\n", a1, a2, a3);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func0(const char *a1, const char *a2, double a3)
{
if ( a3 <= 0.0 )
{
printf("%s: %s must be > 0 (is %f)\n", a1, a2, a3);
exit(1);
}
}

original_code:
void
x_ensure_positive(char *progname, char *optname, double val)
{
    if (! (val > 0)) {
        printf("%s: %s must be > 0 (is %f)\n",
               progname, optname, val);
        exit(1);
    }
}

variable_types:
progname
char *

variable_types:
optname
char *

variable_types: val double


decompiled_code:
void __fastcall print_design_score_info_for_seq(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5, unsigned int a6, double a7, double a8, double a9, double a10, double a11)
{
_QWORD *v15; // rax
void *v17; // r15
_QWORD *v18; // rdx
_QWORD *v19; // rsi
__int64 v20; // [rsp+8h] [rbp-70h]
double v21; // [rsp+8h] [rbp-70h]
double v22; // [rsp+10h] [rbp-68h]
double v24; // [rsp+18h] [rbp-60h]
double v25; // [rsp+20h] [rbp-58h]
double v26; // [rsp+28h] [rbp-50h]
double v28; // [rsp+30h] [rbp-48h]

v20 = a3;
v15 = (_QWORD *)xmalloc(8 * (a3 + (unsigned __int64)(a4 * a3)));
v17 = v15;
if ( v20 )
{
v18 = &v15[v20];
v19 = v18;
do
{
*v15++ = v18;
v18 += a4;
}
while ( v15 != v19 );
}
xstr_to_pseq(a3, a4, a2, v17);
puts("design score");
printf("kpi = %f\n", a7);
printf("kpa = %f\n", a8);
printf("kpur = %f\n", a9);
printf("kneg = %f\n", a10);
printf("khet = %f\n", a11);
printf("het_window = %u\n", a6);
v21 = calc_interactions_pseq(a1, v17);
v22 = dss_calc_U_pa(v17, a3, a4, a8);
v24 = dss_calc_U_pi(v17, a3, a4, a7);
v25 = dss_calc_U_pur_cauchy(v17, a3, a4, a9);
v26 = dss_calc_U_negdesign_nj(v17, a3, a4, a5, *(_QWORD *)(a1 + 24), a10);
v28 = dss_calc_U_het(v17, a3, a4, a6, *(_QWORD *)(a1 + 24), a11);
printf("score_nn = % 5.2f\n", 0.01 * v21);
printf("score_pa = % 5.2f\n", 0.01 * v22);
printf("score_pi = % 5.2f\n", 0.01 * v24);
printf("score_pur = % 5.2f\n", 0.01 * v25);
printf("score_neg = % 5.2f\n", 0.01 * v26);
printf("score_het = % 5.2f\n", 0.01 * v28);
printf("score_total = % 5.2f\n", (v21 + v22 + v24 + v25 + v26 + v28) * 0.01);
putchar(10);
free(v17);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5, unsigned int a6, double a7, double a8, double a9, double a10, double a11)
{
_QWORD *v15; // rax
void *v17; // r15
_QWORD *v18; // rdx
_QWORD *v19; // rsi
__int64 v20; // [rsp+8h] [rbp-70h]
double v21; // [rsp+8h] [rbp-70h]
double v22; // [rsp+10h] [rbp-68h]
double v24; // [rsp+18h] [rbp-60h]
double v25; // [rsp+20h] [rbp-58h]
double v26; // [rsp+28h] [rbp-50h]
double v28; // [rsp+30h] [rbp-48h]

v20 = a3;
v15 = (_QWORD *)xmalloc(8 * (a3 + (unsigned __int64)(a4 * a3)));
v17 = v15;
if ( v20 )
{
v18 = &v15[v20];
v19 = v18;
do
{
*v15++ = v18;
v18 += a4;
}
while ( v15 != v19 );
}
xstr_to_pseq(a3, a4, a2, v17);
puts("design score");
printf("kpi = %f\n", a7);
printf("kpa = %f\n", a8);
printf("kpur = %f\n", a9);
printf("kneg = %f\n", a10);
printf("khet = %f\n", a11);
printf("het_window = %u\n", a6);
v21 = calc_interactions_pseq(a1, v17);
v22 = dss_calc_U_pa(v17, a3, a4, a8);
v24 = dss_calc_U_pi(v17, a3, a4, a7);
v25 = dss_calc_U_pur_cauchy(v17, a3, a4, a9);
v26 = dss_calc_U_negdesign_nj(v17, a3, a4, a5, *(_QWORD *)(a1 + 24), a10);
v28 = dss_calc_U_het(v17, a3, a4, a6, *(_QWORD *)(a1 + 24), a11);
printf("score_nn = % 5.2f\n", 0.01 * v21);
printf("score_pa = % 5.2f\n", 0.01 * v22);
printf("score_pi = % 5.2f\n", 0.01 * v24);
printf("score_pur = % 5.2f\n", 0.01 * v25);
printf("score_neg = % 5.2f\n", 0.01 * v26);
printf("score_het = % 5.2f\n", 0.01 * v28);
printf("score_total = % 5.2f\n", (v21 + v22 + v24 + v25 + v26 + v28) * 0.01);
putchar(10);
free(v17);
}

original_code:
void
print_design_score_info_for_seq(struct nn_inter *inter, char *seq,
                                uint n, uint ndim, double **K_nj, double kpi,
                                double kpa, double kpur, double kneg,
                                double khet, uint het_window)
{
    double **p, score_total, score_nn, score_pa, score_pi, score_pur, score_neg, score_het;
    do { p = xmalloc(n * sizeof(*p) + n * ndim * sizeof(**p)); for (size_t ii = 0; ii < n; ii++) p[ii] = ((__typeof__(*p)) (p + n)) + ii * ndim; } while(0);
    xstr_to_pseq(n, ndim, seq, p);
    printf("design score\n");
    printf("kpi         = %f\n", kpi);
    printf("kpa         = %f\n", kpa);
    printf("kpur        = %f\n", kpur);
    printf("kneg        = %f\n", kneg);
    printf("khet        = %f\n", khet);
    printf("het_window  = %u\n", het_window);
    score_nn = calc_interactions_pseq(inter, p);
    score_pa = dss_calc_U_pa(p, n, ndim, kpa);
    score_pi = dss_calc_U_pi(p, n, ndim, kpi);
    score_pur = dss_calc_U_pur_cauchy(p, n, ndim, kpur);
    score_neg = dss_calc_U_negdesign_nj(p, n, ndim, kneg, K_nj, inter->pairs);
    score_het = dss_calc_U_het(p, n, ndim, khet, het_window, inter->pairs);
    score_total = score_nn + score_pa + score_pi + score_pur + score_neg + score_het;
    printf("score_nn    = % 5.2f\n", score_nn * 0.01);
    printf("score_pa    = % 5.2f\n", score_pa * 0.01);
    printf("score_pi    = % 5.2f\n", score_pi * 0.01);
    printf("score_pur   = % 5.2f\n", score_pur * 0.01);
    printf("score_neg   = % 5.2f\n", score_neg * 0.01);
    printf("score_het   = % 5.2f\n", score_het * 0.01);
    printf("score_total = % 5.2f\n", score_total * 0.01);
    printf("\n");
    free(p);
}

canonical_original_code:
void print_design_score_info_for_seq(struct nn_inter *inter, char *seq, unsigned int n, unsigned int ndim, double **K_nj, double kpi, double kpa, double kpur, double kneg, double khet, unsigned int het_window)
{
    double **p; double score_total; double score_nn; double score_pa; double score_pi; double score_pur; double score_neg; double score_het;
    do { p = xmalloc(n * sizeof(*p) + n * ndim * sizeof(**p)); for (unsigned long ii = 0; ii < n; ii++) p[ii] = ((__typeof__(*p)) (p + n)) + ii * ndim; } while(0);
    xstr_to_pseq(n, ndim, seq, p);
    printf("design score\n");
    printf("kpi         = %f\n", kpi);
    printf("kpa         = %f\n", kpa);
    printf("kpur        = %f\n", kpur);
    printf("kneg        = %f\n", kneg);
    printf("khet        = %f\n", khet);
    printf("het_window  = %u\n", het_window);
    score_nn = calc_interactions_pseq(inter, p);
    score_pa = dss_calc_U_pa(p, n, ndim, kpa);
    score_pi = dss_calc_U_pi(p, n, ndim, kpi);
    score_pur = dss_calc_U_pur_cauchy(p, n, ndim, kpur);
    score_neg = dss_calc_U_negdesign_nj(p, n, ndim, kneg, K_nj, inter->pairs);
    score_het = dss_calc_U_het(p, n, ndim, khet, het_window, inter->pairs);
    score_total = score_nn + score_pa + score_pi + score_pur + score_neg + score_het;
    printf("score_nn    = % 5.2f\n", score_nn * 0.01);
    printf("score_pa    = % 5.2f\n", score_pa * 0.01);
    printf("score_pi    = % 5.2f\n", score_pi * 0.01);
    printf("score_pur   = % 5.2f\n", score_pur * 0.01);
    printf("score_neg   = % 5.2f\n", score_neg * 0.01);
    printf("score_het   = % 5.2f\n", score_het * 0.01);
    printf("score_total = % 5.2f\n", score_total * 0.01);
    printf("\n");
    free(p);
}

variable_types: struct nn_inter { unsigned int n; unsigned int *pairs; struct nn_stack { unsigned int i1; } *stack; struct nn_hairpin { unsigned int i; } *hairpin; struct nn_bulge { unsigned int i1; } *bulge; struct nn_intloop { unsigned int i1; } *intloop; struct nn_multiloop { unsigned int unpaired; unsigned int (*stems)[2]; unsigned int (*dangle5)[3]; unsigned int (*dangle3)[3]; } extloop; struct nn_multiloop *multiloop; } *

variable_types:
seq
char *

variable_types:
n
unsigned int

variable_types: kpi double

variable_types: kpa double

variable_types: kpur double

variable_types: kneg double

variable_types: khet double

variable_types:
p
double **

variable_types:
ii
unsigned long

user_defined_types: struct nn_inter { unsigned int n; unsigned int *pairs; struct nn_stack *stack; struct nn_hairpin *hairpin; struct nn_bulge *bulge; struct nn_intloop *intloop; struct nn_multiloop extloop; struct nn_multiloop *multiloop; }


decompiled_code:
char *option_string()
{
unsigned int v0; // er12
size_t v1; // rax
size_t v3; // rax
double v4; // [rsp+8h] [rbp-10h]

options_0[0] = 0;
if ( noGU )
strcpy(options_0, "-noGU ");
if ( no_closingGU )
strcat(options_0, "-noCloseGU ");
if ( !tetra_loop )
*(_DWORD *)&options_0[strlen(options_0)] = 2110509;
if ( noLonelyPairs )
strcat(options_0, "-noLP ");
if ( fold_constrained )
*(_DWORD *)&options_0[strlen(options_0)] = 2114349;
v0 = dangles;
if ( dangles != 1 )
{
v1 = strlen(options_0);
sprintf(&options_0[v1], "-d%d ", v0);
}
if ( temperature != 37.0 )
{
v4 = temperature;
v3 = strlen(options_0);
sprintf(&options_0[v3], "-T %f ", v4);
}
return options_0;
}

canonical_decompiled_code:
char *func0()
{
unsigned int v0; // er12
size_t v1; // rax
size_t v3; // rax
double v4; // [rsp+8h] [rbp-10h]

options_0[0] = 0;
if ( noGU )
strcpy(options_0, "-noGU ");
if ( no_closingGU )
strcat(options_0, "-noCloseGU ");
if ( !tetra_loop )
*(_DWORD *)&options_0[strlen(options_0)] = 2110509;
if ( noLonelyPairs )
strcat(options_0, "-noLP ");
if ( fold_constrained )
*(_DWORD *)&options_0[strlen(options_0)] = 2114349;
v0 = dangles;
if ( dangles != 1 )
{
v1 = strlen(options_0);
sprintf(&options_0[v1], "-d%d ", v0);
}
if ( temperature != 37.0 )
{
v4 = temperature;
v3 = strlen(options_0);
sprintf(&options_0[v3], "-T %f ", v4);
}
return options_0;
}

original_code:
char * option_string(void) {
  static char options[100];
  *options = '\0';
  if (noGU) strcat(options, "-noGU ");
  if (no_closingGU) strcat(options, "-noCloseGU ");
  if (!tetra_loop) strcat(options, "-4 ");
  if (noLonelyPairs) strcat(options, "-noLP ");
  if (fold_constrained) strcat(options, "-C ");
  if (dangles!=1) sprintf(options+strlen(options), "-d%d ", dangles);
  if (temperature!=37.0)
    sprintf(options+strlen(options), "-T %f ", temperature);
  return options;
}

canonical_original_code:
char *option_string() {
  static char options[100];
  *options = '\0';
  if (noGU) strcat(options, "-noGU ");
  if (no_closingGU) strcat(options, "-noCloseGU ");
  if (!tetra_loop) strcat(options, "-4 ");
  if (noLonelyPairs) strcat(options, "-noLP ");
  if (fold_constrained) strcat(options, "-C ");
  if (dangles!=1) sprintf(options+strlen(options), "-d%d ", dangles);
  if (temperature!=37.0)
    sprintf(options+strlen(options), "-T %f ", temperature);
  return options;
}

variable_types:
options
char [100]

return_type: char *


decompiled_code:
void __fastcall dary_set(double *a1, __int64 a2, double a3)
{
double *v3; // rax

if ( a2 )
{
v3 = &a1[a2];
do
*a1++ = a3;
while ( a1 != v3 );
}
}

canonical_decompiled_code:
void __fastcall func0(double *a1, __int64 a2, double a3)
{
double *v3; // rax

if ( a2 )
{
v3 = &a1[a2];
do
*a1++ = a3;
while ( a1 != v3 );
}
}

original_code:
void
dary_set(double *a, size_t n, double val)
{
    size_t i;
    for (i = 0; i < n; i++)
        a[i] = val;
}

canonical_original_code:
void dary_set(double *a, unsigned long n, double val)
{
    unsigned long i;
    for (i = 0; i < n; i++)
        a[i] = val;
}

variable_types:
a
double *

variable_types:
n
unsigned long

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall dary_equal(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax

if ( !a3 )
return 1LL;
v3 = 0LL;
while ( *(double *)(a1 + 8 * v3) == *(double *)(a2 + 8 * v3) )
{
if ( a3 == ++v3 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax

if ( !a3 )
return 1LL;
v3 = 0LL;
while ( *(double *)(a1 + 8 * v3) == *(double *)(a2 + 8 * v3) )
{
if ( a3 == ++v3 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool
dary_equal(double *a, double *b, size_t n)
{
    size_t i;
    for (i = 0; i < n; i++)
        if (a[i] != b[i])
            return 0;
    return 1;
}

canonical_original_code:
_Bool dary_equal(double *a, double *b, unsigned long n)
{
    unsigned long i;
    for (i = 0; i < n; i++)
        if (a[i] != b[i])
            return 0;
    return 1;
}

variable_types:
b
double *


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

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

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

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

original_code:
void
dary_print(double *a, size_t n)
{
    size_t i;
    for (i = 0; i < n; i++)
        printf("% f\n", a[i]);
}

canonical_original_code:
void dary_print(double *a, unsigned long n)
{
    unsigned long i;
    for (i = 0; i < n; i++)
        printf("% f\n", a[i]);
}


decompiled_code:
__int64 __fastcall dary_is_finite(__int64 a1, __int64 a2)
{
__int64 v2; // rax

if ( !a2 )
return 1LL;
v2 = 0LL;
while ( COERCE_DOUBLE(*(_QWORD *)(a1 + 8 * v2) & LC1) <= 1.797693134862316e308 )
{
if ( a2 == ++v2 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool
dary_is_finite(double *a, size_t n)
{
    size_t i;
    for (i = 0; i < n; i++)
        if (! __builtin_isfinite (a[i]))
            return 0;
    return 1;
}

canonical_original_code:
_Bool dary_is_finite(double *a, unsigned long n)
{
    unsigned long i;
    for (i = 0; i < n; i++)
        if (! __builtin_isfinite (a[i]))
            return 0;
    return 1;
}


decompiled_code:
void __fastcall dary2d_set(__int64 a1, __int64 a2, __int64 a3, double a4)
{
__int64 i; // rcx
double *v6; // rax
double *v7; // rdx

if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
{
if ( a2 )
{
v6 = *(double **)(a3 + 8 * i);
v7 = &v6[a2];
do
*v6++ = a4;
while ( v7 != v6 );
}
}
}
}

original_code:
void
dary2d_set(size_t n1, size_t n2, double **a, double val)
{
    size_t i, j;
    for (i = 0; i < n1; i++)
        for (j = 0; j < n2; j++)
            a[i][j] = val;
}

canonical_original_code:
void dary2d_set(unsigned long n1, unsigned long n2, double **a, double val)
{
    unsigned long i; unsigned long j;
    for (i = 0; i < n1; i++)
        for (j = 0; j < n2; j++)
            a[i][j] = val;
}

variable_types:
a
double **

variable_types:
j
unsigned long


original_code:
_Bool
dary2d_equal(double **a, double **b, size_t n1, size_t n2)
{
    size_t i, j;
    for (i = 0; i < n1; i++)
        for (j = 0; j < n2; j++)
            if (a[i][j] != b[i][j])
                return 0;
    return 1;
}

canonical_original_code:
_Bool dary2d_equal(double **a, double **b, unsigned long n1, unsigned long n2)
{
    unsigned long i; unsigned long j;
    for (i = 0; i < n1; i++)
        for (j = 0; j < n2; j++)
            if (a[i][j] != b[i][j])
                return 0;
    return 1;
}

variable_types:
b
double **


decompiled_code:
int __fastcall dary2d_print(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 i; // r13
__int64 v6; // rbx
double v7; // xmm0_8
int result; // eax

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v6 = 0LL;
if ( a3 )
{
do
{
v7 = *(double *)(*a1 + 8 * v6++);
printf(" % f", v7);
}
while ( a3 != v6 );
}
++a1;
result = putchar(10);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 i; // r13
__int64 v6; // rbx
double v7; // xmm0_8
int result; // eax

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v6 = 0LL;
if ( a3 )
{
do
{
v7 = *(double *)(*a1 + 8 * v6++);
printf(" % f", v7);
}
while ( a3 != v6 );
}
++a1;
result = putchar(10);
}
}
return result;
}

original_code:
void
dary2d_print(double **a, size_t n1, size_t n2)
{
    size_t i, j;
    for (i = 0; i < n1; i++) {
        for (j = 0; j < n2; j++)
            printf(" % f", a[i][j]);
        printf("\n");
    }
}

canonical_original_code:
void dary2d_print(double **a, unsigned long n1, unsigned long n2)
{
    unsigned long i; unsigned long j;
    for (i = 0; i < n1; i++) {
        for (j = 0; j < n2; j++)
            printf(" % f", a[i][j]);
        printf("\n");
    }
}


original_code:
_Bool
dary2d_is_finite(double **a, size_t n1, size_t n2)
{
    size_t i, j;
    for (i = 0; i < n1; i++)
        for (j = 0; j < n2; j++)
            if (! __builtin_isfinite (a[i][j]))
                return 0;
    return 1;
}

canonical_original_code:
_Bool dary2d_is_finite(double **a, unsigned long n1, unsigned long n2)
{
    unsigned long i; unsigned long j;
    for (i = 0; i < n1; i++)
        for (j = 0; j < n2; j++)
            if (! __builtin_isfinite (a[i][j]))
                return 0;
    return 1;
}


xfail

decompiled_code:
void __noreturn xfail(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
printf(a1, va);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
printf(a1, va);
exit(1);
}

original_code:
void
__attribute__((format (__printf__, 1, 2)))
xfail(const char *format, ...)
{
    va_list args;
    __builtin_va_start(args,format);
    printf(format, args);
    __builtin_va_end(args);
    exit(1);
}

canonical_original_code:
void xfail(char *format, ...)
{
    __builtin_va_list args;
    __builtin_va_start(args,format);
    printf(format, args);
    __builtin_va_end(args);
    exit(1);
}

variable_types:
format
char *


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
xfail("ERROR: xmalloc(): malloc(%lu) failed\n", a1);
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
func0("ERROR: xmalloc(): malloc(%lu) failed\n", a1);
return result;
}

original_code:
void *
xmalloc(size_t size)
{
    void *p;
    if ((p = malloc(size)) == ((void *)0))
        xfail("ERROR: xmalloc(): malloc(%lu) failed\n", (ulong) size);
    return p;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
    void *p;
    if ((p = malloc(size)) == ((void *)0))
        xfail("ERROR: xmalloc(): malloc(%lu) failed\n", (unsigned long) size);
    return p;
}

variable_types:
size
unsigned long

variable_types:
p
void *


nrerror

decompiled_code:
void __fastcall __noreturn nrerror(const char *a1)
{
fprintf(stderr, "\n%s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "\n%s\n", a1);
exit(1);
}

original_code:
void nrerror(char *message)       /* output message upon error */
{
    fprintf(stderr, "\n%s\n", message);
    exit(0);
}

variable_types:
message
char *


space

decompiled_code:
void *__fastcall space(size_t size)
{
void *v1; // r12
int *v3; // rax

v1 = calloc(1uLL, (unsigned int)size);
if ( !v1 )
{
v3 = _errno_location();
if ( *v3 == 22 )
{
fprintf(stderr, "SPACE: requested size: %d\n", (unsigned int)size);
nrerror("SPACE allocation failure -> EINVAL");
}
if ( *v3 == 12 )
nrerror("SPACE allocation failure -> no memory");
}
return v1;
}

canonical_decompiled_code:
void *__fastcall func1(size_t size)
{
void *v1; // r12
int *v3; // rax

v1 = calloc(1uLL, (unsigned int)size);
if ( !v1 )
{
v3 = _errno_location();
if ( *v3 == 22 )
{
fprintf(stderr, "SPACE: requested size: %d\n", (unsigned int)size);
func0("SPACE allocation failure -> EINVAL");
}
if ( *v3 == 12 )
func0("SPACE allocation failure -> no memory");
}
return v1;
}

original_code:
void *space(unsigned size)
{
    void *pointer;

    if ( (pointer = (void *) calloc(1, size)) == NULL) {
       fprintf(stderr,"SPACE: requested size: %d\n", size);
       nrerror("SPACE allocation failure -> no memory");
    }
    return  pointer;
}

canonical_original_code:
void *space(unsigned int size)
{
    void *pointer;

    if ( (pointer = (void *) calloc(1, size)) == NULL) {
       fprintf(stderr,"SPACE: requested size: %d\n", size);
       nrerror("SPACE allocation failure -> no memory");
    }
    return  pointer;
}

variable_types:
size
unsigned int

variable_types:
pointer
void *


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, unsigned int a2)
{
void *v2; // r12
int *v4; // rax

if ( !a1 )
return space(a2);
v2 = realloc(a1, a2);
if ( !v2 )
{
v4 = _errno_location();
if ( *v4 == 22 )
{
fprintf(stderr, "xrealloc: requested size: %d\n", a2);
nrerror("xrealloc allocation failure -> EINVAL");
}
if ( *v4 == 12 )
nrerror("xrealloc allocation failure -> no memory");
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, unsigned int a2)
{
void *v2; // r12
int *v4; // rax

if ( !a1 )
return func1(a2);
v2 = realloc(a1, a2);
if ( !v2 )
{
v4 = _errno_location();
if ( *v4 == 22 )
{
fprintf(stderr, "xrealloc: requested size: %d\n", a2);
func0("xrealloc allocation failure -> EINVAL");
}
if ( *v4 == 12 )
func0("xrealloc allocation failure -> no memory");
}
return v2;
}

original_code:
void *xrealloc (void *p, unsigned size) {
  if (p == 0)
    return space(size);
  p = (void *) realloc(p, size);
  if (p == NULL) {
#ifdef EINVAL
    if (errno==EINVAL) {
      fprintf(stderr,"xrealloc: requested size: %d\n", size);
      nrerror("xrealloc allocation failure -> EINVAL");
    }
    if (errno==ENOMEM)
#endif
      nrerror("xrealloc allocation failure -> no memory");
  }
  return p;
}

canonical_original_code:
void *xrealloc(void *p, unsigned int size) {
  if (p == 0)
    return space(size);
  p = (void *) realloc(p, size);
  if (p == NULL) {
#ifdef EINVAL
    if (errno==EINVAL) {
      fprintf(stderr,"xrealloc: requested size: %d\n", size);
      nrerror("xrealloc allocation failure -> EINVAL");
    }
    if (errno==ENOMEM)
#endif
      nrerror("xrealloc allocation failure -> no memory");
  }
  return p;
}


decompiled_code:
__int64 __fastcall encode_char(char a1)
{
__int64 result; // rax
char *v2; // rsi

if ( energy_set > 0 )
return (unsigned int)(a1 - 64);
v2 = strchr("_ACGUTXKI", a1);
result = 0LL;
if ( v2 )
result = (unsigned int)v2 - (unsigned int)"_ACGUTXKI" - ((int)((_DWORD)v2 - (unsigned int)"_ACGUTXKI") > 4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
__int64 result; // rax
char *v2; // rsi

if ( energy_set > 0 )
return (unsigned int)(a1 - 64);
v2 = strchr("_ACGUTXKI", a1);
result = 0LL;
if ( v2 )
result = (unsigned int)v2 - (unsigned int)"_ACGUTXKI" - ((int)((_DWORD)v2 - (unsigned int)"_ACGUTXKI") > 4);
return result;
}

original_code:
static int encode_char(char c) {
  /* return numerical representation of base used e.g. in pair[][] */
  int code;
  if (energy_set>0) code = (int) (c-'A')+1;
  else {
    const char *pos;
    pos = strchr(Law_and_Order, c);
    if (pos==NULL) code=0;
    else code = (int) (pos-Law_and_Order);
    if (code>4) code--; /* make T and U equivalent */
  }
  return code;
}

canonical_original_code:
static int encode_char(char c) {
  /* return numerical representation of base used e.g. in pair[][] */
  int code;
  if (energy_set>0) code = (int) (c-'A')+1;
  else {
    char *pos;
    pos = strchr(Law_and_Order, c);
    if (pos==NULL) code=0;
    else code = (int) (pos-Law_and_Order);
    if (code>4) code--; /* make T and U equivalent */
  }
  return code;
}

variable_types: c char

variable_types: code int

variable_types:
pos
char *


consensus

original_code:
char *consensus(const char *AS[]) {
  /* simple consensus sequence (most frequent character) */
  char *string;
  int i,n;
  n = strlen(AS[0]);
  string = (char *) space((n+1)*sizeof(char));
  for (i=0; i<n; i++) {
    int s,c,fm, freq[8] = {0,0,0,0,0,0,0,0};
    for (s=0; AS[s]!=NULL; s++)
      freq[encode_char(AS[s][i])]++;
    for (s=c=fm=0; s<8; s++) /* find the most frequent char */
      if (freq[s]>fm) {c=s, fm=freq[c];}
    if (s>4) s++; /* skip T */
    string[i]=Law_and_Order[c];
  }
  return string;
}

canonical_original_code:
char *consensus(char *AS[]) {
  /* simple consensus sequence (most frequent character) */
  char *string;
  int i; int n;
  n = strlen(AS[0]);
  string = (char *) space((n+1)*sizeof(char));
  for (i=0; i<n; i++) {
    int s; int c; int fm; int freq[8] = {0,0,0,0,0,0,0,0};
    for (s=0; AS[s]!=NULL; s++)
      freq[encode_char(AS[s][i])]++;
    for (s=c=fm=0; s<8; s++) /* find the most frequent char */
      if (freq[s]>fm) {c=s, fm=freq[c];}
    if (s>4) s++; /* skip T */
    string[i]=Law_and_Order[c];
  }
  return string;
}

variable_types:
AS
char *[]

variable_types:
string
char *

variable_types: i int

variable_types: n int

variable_types: s int

variable_types: c int

variable_types: fm int

variable_types:
freq
int [8]


original_code:
char *consens_mis(const char*AS[]) {
  /* MIS displays the 'most informative sequence' (Freyhult et al 2004),
     elements in columns with frequency greater than the background
     frequency are projected into iupac notation. Columns where gaps are
     over-represented are in lower case. */

  char *cons;
  int i, s, n, N, c;
  int bgfreq[8] = {0,0,0,0,0,0,0,0};

  n = strlen(AS[0]);
  for (N=0; AS[N]!=NULL; N++);
  cons = (char *) space((n+1)*sizeof(char));

  for (i=0; i<n; i++)
    for (s=0; s<N; s++) {
      c = encode_char(AS[s][i]);
      if (c>4) c=5;
      bgfreq[c]++;
    }

  for (i=0; i<n; i++) {
    int freq[8] = {0,0,0,0,0,0,0,0};
    int code = 0;
    for (s=0; s<N; s++) {
      c = encode_char(AS[s][i]);
      if (c>4) c=5;
      freq[c]++;
    }
    for (c=4; c>0; c--) {
      code <<=1;
      if (freq[c]*n>=bgfreq[c]) code++;
    }
    cons[i] = IUP[code];
    if (freq[0]*n>bgfreq[0])
      cons[i] = tolower(IUP[code]);
  }
  return cons;
}

canonical_original_code:
char *consens_mis(char *AS[]) {
  /* MIS displays the 'most informative sequence' (Freyhult et al 2004),
     elements in columns with frequency greater than the background
     frequency are projected into iupac notation. Columns where gaps are
     over-represented are in lower case. */

  char *cons;
  int i; int s; int n; int N; int c;
  int bgfreq[8] = {0,0,0,0,0,0,0,0};

  n = strlen(AS[0]);
  for (N=0; AS[N]!=NULL; N++);
  cons = (char *) space((n+1)*sizeof(char));

  for (i=0; i<n; i++)
    for (s=0; s<N; s++) {
      c = encode_char(AS[s][i]);
      if (c>4) c=5;
      bgfreq[c]++;
    }

  for (i=0; i<n; i++) {
    int freq[8] = {0,0,0,0,0,0,0,0};
    int code = 0;
    for (s=0; s<N; s++) {
      c = encode_char(AS[s][i]);
      if (c>4) c=5;
      freq[c]++;
    }
    for (c=4; c>0; c--) {
      code <<=1;
      if (freq[c]*n>=bgfreq[c]) code++;
    }
    cons[i] = IUP[code];
    if (freq[0]*n>bgfreq[0])
      cons[i] = tolower(IUP[code]);
  }
  return cons;
}

variable_types:
cons
char *

variable_types: N int

variable_types:
bgfreq
int [8]


decompiled_code:
double __fastcall plogp_sane(double a1)
{
double v1; // xmm1_8

if ( a1 > 0.000001 )
v1 = fmin(a1, 1.0);
else
v1 = LC0;
return log(v1) * v1;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
double v1; // xmm1_8

if ( a1 > 0.000001 )
v1 = fmin(a1, 1.0);
else
v1 = LC0;
return log(v1) * v1;
}

variable_types: p double


tokenize

decompiled_code:
const char *__fastcall tokenize(void *ptr)
{
int v2; // eax
const char *v3; // r12
char *v4; // rax
char *v5; // rbx
char *v6; // rbp
int v7; // er14
const char *v8; // rdi
char v9; // al

v2 = strlen((const char *)ptr);
v3 = (const char *)space((unsigned int)(v2 + 1));
_isoc99_sscanf(ptr, "%s", v3);
v4 = strchr(v3, 38);
if ( v4 )
{
v5 = v4;
v6 = v4 + 1;
v7 = (_DWORD)v4 - (_DWORD)v3 + 1;
v8 = v4 + 1;
if ( v7 >= strlen(v3) )
v7 = -1;
if ( strchr(v8, 38) )
nrerror("more than one cut-point in input");
if ( *v5 )
{
while ( 1 )
{
v9 = v5[1];
*v5 = v9;
v5 = v6;
if ( !v9 )
break;
++v6;
}
}
if ( v7 >= 0 )
{
if ( cut_point == -1 )
{
cut_point = v7;
}
else if ( cut_point != v7 )
{
fprintf(stderr, "cut_point = %d cut = %d\n", cut_point, (unsigned int)v7);
nrerror("Sequence and Structure have different cut points.");
}
}
}
free(ptr);
return v3;
}

canonical_decompiled_code:
const char *__fastcall func2(void *ptr)
{
int v2; // eax
const char *v3; // r12
char *v4; // rax
char *v5; // rbx
char *v6; // rbp
int v7; // er14
const char *v8; // rdi
char v9; // al

v2 = strlen((const char *)ptr);
v3 = (const char *)space((unsigned int)(v2 + 1));
_isoc99_sscanf(ptr, "%s", v3);
v4 = strchr(v3, 38);
if ( v4 )
{
v5 = v4;
v6 = v4 + 1;
v7 = (_DWORD)v4 - (_DWORD)v3 + 1;
v8 = v4 + 1;
if ( v7 >= strlen(v3) )
v7 = -1;
if ( strchr(v8, 38) )
nrerror("more than one cut-point in input");
if ( *v5 )
{
while ( 1 )
{
v9 = v5[1];
*v5 = v9;
v5 = v6;
if ( !v9 )
break;
++v6;
}
}
if ( v7 >= 0 )
{
if ( cut_point == -1 )
{
cut_point = v7;
}
else if ( cut_point != v7 )
{
fprintf(stderr, "cut_point = %d cut = %d\n", cut_point, (unsigned int)v7);
nrerror("Sequence and Structure have different cut points.");
}
}
}
free(ptr);
return v3;
}

original_code:
void tokenize(char *line, char **seq1, char **seq2) {
  char *pos;
  int cut = -1;
  int i;
  pos = strchr(line, '&');
  if (pos) {
    cut = (int) (pos-line)+1;
    (*seq1) = (char *) space((cut+1)*sizeof(char));
    (*seq2) = (char *) space(((strlen(line)-cut)+2)*sizeof(char));

    if (strchr(pos+1, '&')) nrerror("more than one cut-point in input");
    *pos = '\0';
    (void) sscanf(line, "%s", *seq1);
    (void) sscanf(pos+1, "%s", *seq2);
  } else {
    (*seq1) = (char *) space((strlen(line)+1)*sizeof(char));
    (*seq2) = NULL;
    sscanf(line, "%s", *seq1);
  }

  if (cut > -1) {
    if (cut_point==-1) cut_point = cut;
    else if (cut_point != cut) {
      fprintf(stderr,"cut_point = %d cut = %d\n", cut_point, cut);
      nrerror("Sequence and Structure have different cut points.");
    }
  }
  free(line);
  return;
}

variable_types:
line
char *

variable_types: cut int


decompiled_code:
char *__fastcall tokenize(char *s)
{
int v1; // eax
char *v2; // rbp
int v3; // eax
char *v4; // r12
char *v5; // rsi
int v6; // er13

v1 = strlen(s);
v2 = (char *)space((unsigned int)(v1 + 1));
v3 = strlen(s);
v4 = (char *)space((unsigned int)(v3 + 1));
_isoc99_sscanf(s, "%s", v2);
*v4 = 0;
v5 = strtok(v2, "&");
v6 = strlen(v5) + 1;
do
{
strcat(v4, v5);
v5 = strtok(0LL, "&");
}
while ( v5 );
if ( v6 <= strlen(v4) && v6 >= 0 )
{
if ( cut_point == -1 )
{
cut_point = v6;
}
else if ( cut_point != v6 )
{
fprintf(stderr, "cut_point = %d cut = %d\n", cut_point, (unsigned int)v6);
nrerror("Sequence and Structure have different cut points.");
}
}
free(v2);
return v4;
}

canonical_decompiled_code:
char *__fastcall func1(char *s)
{
int v1; // eax
char *v2; // rbp
int v3; // eax
char *v4; // r12
char *v5; // rsi
int v6; // er13

v1 = strlen(s);
v2 = (char *)space((unsigned int)(v1 + 1));
v3 = strlen(s);
v4 = (char *)space((unsigned int)(v3 + 1));
_isoc99_sscanf(s, "%s", v2);
*v4 = 0;
v5 = strtok(v2, "&");
v6 = strlen(v5) + 1;
do
{
strcat(v4, v5);
v5 = strtok(0LL, "&");
}
while ( v5 );
if ( v6 <= strlen(v4) && v6 >= 0 )
{
if ( cut_point == -1 )
{
cut_point = v6;
}
else if ( cut_point != v6 )
{
fprintf(stderr, "cut_point = %d cut = %d\n", cut_point, (unsigned int)v6);
nrerror("Sequence and Structure have different cut points.");
}
}
free(v2);
return v4;
}

canonical_original_code:
void tokenize(char *line, char **seq1, char **seq2) {
  char *pos;
  int cut = -1;
  int i;
  pos = strchr(line, '&');
  if (pos) {
    cut = (int) (pos-line)+1;
    (*seq1) = (char *) space((cut+1)*sizeof(char));
    (*seq2) = (char *) space(((strlen(line)-cut)+2)*sizeof(char));

    if (strchr(pos+1, '&')) nrerror("more than one cut-point in input");
    *pos = '\0';
    (void) sscanf(line, "%s", *seq1);
    (void) sscanf(pos+1, "%s", *seq2);
  } else {
    (*seq1) = (char *) space((strlen(line)+1)*sizeof(char));
    (*seq2) = NULL;
    sscanf(line, "%s", *seq1);
  }

  if (cut > -1) {
    if (cut_point==-1) cut_point = cut;
    else if (cut_point != cut) {
      fprintf(stderr,"cut_point = %d cut = %d\n", cut_point, cut);
      nrerror("Sequence and Structure have different cut points.");
    }
  }
  free(line);
  return;
}


shuffle

repo: marcomorain/shuffle

original_code:
static void shuffle(line_buffer* lines) {
  sranddev();
  int n = ((*lines).n);
  for (int i = 0; i < n - 1; i++) {
    int j = i + rand() / (2147483647 / (n - i) + 1);
    char* t = ((*lines).a[(j)]);
    ((*lines).a[(j)]) = ((*lines).a[(i)]);
    ((*lines).a[(i)]) = t;
  }
}

canonical_original_code:
static void shuffle(struct line_buffer *lines) {
  sranddev();
  int n = ((*lines).n);
  for (int i = 0; i < n - 1; i++) {
    int j = i + rand() / (2147483647 / (n - i) + 1);
    char *t = ((*lines).a[(j)]);
    ((*lines).a[(j)]) = ((*lines).a[(i)]);
    ((*lines).a[(i)]) = t;
  }
}

variable_types: struct line_buffer { unsigned long n; char **a; } *

variable_types: j int

variable_types:
t
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rbx
const char *v4; // rdi
__int64 v6[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+10h] [rbp-18h]

v6[1] = 0LL;
v6[0] = 0LL;
v7 = 0LL;
read_lines_constprop_0(stdin, v6);
shuffle(v6);
if ( v6[0] )
{
v3 = 0LL;
do
{
v4 = *(const char **)(v7 + 8 * v3++);
fputs(v4, stdout);
}
while ( v6[0] > v3 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rbx
const char *v4; // rdi
__int64 v6[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+10h] [rbp-18h]

v6[1] = 0LL;
v6[0] = 0LL;
v7 = 0LL;
func2(stdin, v6);
func1(v6);
if ( v6[0] )
{
v3 = 0LL;
do
{
v4 = *(const char **)(v7 + 8 * v3++);
fputs(v4, stdout);
}
while ( v6[0] > v3 );
}
return 0;
}

original_code:
int main(int argc, char** argv) {
  (void)argc;
  (void)argv;
  line_buffer buffer;
  ((buffer).n = (buffer).m = 0, (buffer).a = 0);
  read_lines(stdin, &buffer);
  shuffle(&buffer);
  for (size_t i=0; i<((buffer).n); i++) {
    fputs(((buffer).a[(i)]), stdout);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  (void)argc;
  (void)argv;
  struct line_buffer buffer;
  ((buffer).n = (buffer).m = 0, (buffer).a = 0);
  read_lines(stdin, &buffer);
  shuffle(&buffer);
  for (unsigned long i = 0; i<((buffer).n); i++) {
    fputs(((buffer).a[(i)]), stdout);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct line_buffer { unsigned long n; char **a; }

variable_types:
i
unsigned long


exitmessage

repo: marcotaubmann/tinyjpeg-pthreads

decompiled_code:
void __fastcall __noreturn exitmessage(const char *a1)
{
puts(a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
puts(a1);
exit(0);
}

original_code:
static void exitmessage(const char *message)
{
  printf("%s\n", message);
  exit(0);
}

canonical_original_code:
static void exitmessage(char *message)
{
  printf("%s\n", message);
  exit(0);
}

variable_types:
message
char *


usage

decompiled_code:
void __noreturn usage()
{
fwrite("Usage: loadjpeg [option] input_filename.jpeg output_filename.tga \n", 1uLL, 0x42uLL, stderr);
fwrite("option:\n", 1uLL, 8uLL, stderr);
fwrite(" --benchmark - Measure the timing of 1 conversion\n", 1uLL, 0x33uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func4()
{
fwrite("Usage: loadjpeg [option] input_filename.jpeg output_filename.tga \n", 1uLL, 0x42uLL, stderr);
fwrite("option:\n", 1uLL, 8uLL, stderr);
fwrite(" --benchmark - Measure the timing of 1 conversion\n", 1uLL, 0x33uLL, stderr);
exit(1);
}

original_code:
static void usage(void)
{
  fprintf(stderr, "Usage: loadjpeg [option] input_filename.jpeg output_filename.tga \n");
  fprintf(stderr, "option:\n");
  fprintf(stderr, "  --benchmark - Measure the timing of 1 conversion\n");
  exit(1);
}

canonical_original_code:
static void usage()
{
  fprintf(stderr, "Usage: loadjpeg [option] input_filename.jpeg output_filename.tga \n");
  fprintf(stderr, "option:\n");
  fprintf(stderr, "  --benchmark - Measure the timing of 1 conversion\n");
  exit(1);
}


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er11
const char **v4; // r8
__int64 v5; // rax
bool v6; // cf
bool v7; // zf
int i; // er9
const char **v9; // rbp
__int64 v10; // rcx
int v11; // ecx
const char *v12; // r12
__int64 v14; // rax
struct timeval v15; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

if ( argc <= 2 )
goto LABEL_13;
v3 = argc;
v4 = argv;
v5 = 1LL;
v6 = 0;
v7 = 1;
for ( i = 0; ; i = 1 )
{
v9 = (const char **)v4[v5];
v10 = 12LL;
*(_QWORD *)&argc = "--benchmark";
argv = v9;
do
{
if ( !v10 )
break;
v6 = *(_BYTE *)argv < **(_BYTE **)&argc;
v7 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v10;
}
while ( v7 );
v11 = v5 + 1;
LOBYTE(envp) = (!v6 && !v7) - v6;
++v5;
v6 = 0;
v7 = (_BYTE)envp == 0;
if ( (_BYTE)envp )
break;
}
if ( v11 >= v3 )
LABEL_13:
usage(*(_QWORD *)&argc, argv, envp);
v12 = v4[v5];
if ( i )
{
gettimeofday(&v15, 0LL);
convert_one_image((const char *)v9, v12);
gettimeofday(&tv, 0LL);
v14 = timevaldiff(&v15, &tv);
printf("Decoding finished in %.2fs (%ld ms)\n", (double)(int)v14 / 1000.0, v14);
}
else
{
convert_one_image((const char *)v9, v4[v5]);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er11
const char **v4; // r8
__int64 v5; // rax
bool v6; // cf
bool v7; // zf
int i; // er9
const char **v9; // rbp
__int64 v10; // rcx
int v11; // ecx
const char *v12; // r12
__int64 v14; // rax
struct timeval v15; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

if ( argc <= 2 )
goto LABEL_13;
v3 = argc;
v4 = argv;
v5 = 1LL;
v6 = 0;
v7 = 1;
for ( i = 0; ; i = 1 )
{
v9 = (const char **)v4[v5];
v10 = 12LL;
*(_QWORD *)&argc = "--benchmark";
argv = v9;
do
{
if ( !v10 )
break;
v6 = *(_BYTE *)argv < **(_BYTE **)&argc;
v7 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v10;
}
while ( v7 );
v11 = v5 + 1;
LOBYTE(envp) = (!v6 && !v7) - v6;
++v5;
v6 = 0;
v7 = (_BYTE)envp == 0;
if ( (_BYTE)envp )
break;
}
if ( v11 >= v3 )
LABEL_13:
func4(*(_QWORD *)&argc, argv, envp);
v12 = v4[v5];
if ( i )
{
gettimeofday(&v15, 0LL);
func7((const char *)v9, v12);
gettimeofday(&tv, 0LL);
v14 = timevaldiff(&v15, &tv);
printf("Decoding finished in %.2fs (%ld ms)\n", (double)(int)v14 / 1000.0, v14);
}
else
{
func7((const char *)v9, v4[v5]);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  char *output_filename, *input_filename;
  timer start, finish;
  long elapsed;
  int current_argument;
  int benchmark_mode = 0;
  if (argc < 3)
    usage();
  current_argument = 1;
  while (1)
  {
    if (strcmp(argv[current_argument], "--benchmark")==0)
      benchmark_mode = 1;
    else
      break;
    current_argument++;
  }
  if (argc < current_argument+2)
    usage();
  input_filename = argv[current_argument];
  output_filename = argv[current_argument+1];
  if(benchmark_mode)
    gettimeofday(&start, ((void *)0));;
  convert_one_image(input_filename, output_filename);
  if(benchmark_mode) {
    gettimeofday(&finish, ((void *)0));;
    elapsed = timevaldiff(&start, &finish);
    printf("Decoding finished in %.2fs (%ld ms)\n", (double)elapsed/1000, elapsed);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char *output_filename; char *input_filename;
  struct timeval start; struct timeval finish;
  long elapsed;
  int current_argument;
  int benchmark_mode = 0;
  if (argc < 3)
    usage();
  current_argument = 1;
  while (1)
  {
    if (strcmp(argv[current_argument], "--benchmark")==0)
      benchmark_mode = 1;
    else
      break;
    current_argument++;
  }
  if (argc < current_argument+2)
    usage();
  input_filename = argv[current_argument];
  output_filename = argv[current_argument+1];
  if(benchmark_mode)
    gettimeofday(&start, ((void *)0));;
  convert_one_image(input_filename, output_filename);
  if(benchmark_mode) {
    gettimeofday(&finish, ((void *)0));;
    elapsed = timevaldiff(&start, &finish);
    printf("Decoding finished in %.2fs (%ld ms)\n", (double)elapsed/1000, elapsed);
  }
  return 0;
}

variable_types:
argv
char *[]

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

variable_types: elapsed long


exitmessage

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
puts(a1);
exit(0);
}


decompiled_code:
int __fastcall idct_data_buffer_init(__int64 a1)
{
pthread_mutex_t *v1; // rax
pthread_cond_t *v2; // rax

*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
v1 = (pthread_mutex_t *)malloc(0x28uLL);
*(_QWORD *)(a1 + 24) = v1;
if ( !v1 )
exitmessage("Not enough memory to alloc new mutex for idct buffer\n");
pthread_mutex_init(v1, 0LL);
v2 = (pthread_cond_t *)malloc(0x30uLL);
*(_QWORD *)(a1 + 32) = v2;
if ( !v2 )
exitmessage("Not enough memory to alloc new cond for idct buffer\n");
return pthread_cond_init(v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
pthread_mutex_t *v1; // rax
pthread_cond_t *v2; // rax

*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
v1 = (pthread_mutex_t *)malloc(0x28uLL);
*(_QWORD *)(a1 + 24) = v1;
if ( !v1 )
func0("Not enough memory to alloc new mutex for idct buffer\n");
pthread_mutex_init(v1, 0LL);
v2 = (pthread_cond_t *)malloc(0x30uLL);
*(_QWORD *)(a1 + 32) = v2;
if ( !v2 )
func0("Not enough memory to alloc new cond for idct buffer\n");
return pthread_cond_init(v2, 0LL);
}

original_code:
void idct_data_buffer_init(struct idct_data_buffer *b){
 b->elements = 0;
 b->first = ((void *)0);
 b->last = ((void *)0);
 b->mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
 if (b->mutex == ((void *)0))
  exitmessage("Not enough memory to alloc new mutex for idct buffer\n");
 pthread_mutex_init(b->mutex, ((void *)0));
 b->cond = (pthread_cond_t *)malloc(sizeof(pthread_cond_t));
 if (b->cond == ((void *)0))
  exitmessage("Not enough memory to alloc new cond for idct buffer\n");
 pthread_cond_init(b->cond, ((void *)0));
}

canonical_original_code:
void idct_data_buffer_init(struct idct_data_buffer *b){
 b->elements = 0;
 b->first = ((void *)0);
 b->last = ((void *)0);
 b->mutex = (union pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
 if (b->mutex == ((void *)0))
  exitmessage("Not enough memory to alloc new mutex for idct buffer\n");
 pthread_mutex_init(b->mutex, ((void *)0));
 b->cond = (union pthread_cond_t *)malloc(sizeof(pthread_cond_t));
 if (b->cond == ((void *)0))
  exitmessage("Not enough memory to alloc new cond for idct buffer\n");
 pthread_cond_init(b->cond, ((void *)0));
}

variable_types: struct idct_data_buffer { int elements; struct idct_data_buffer_element { enum element_type { DATA=0, FINISH=1 } type; struct idct_data { short DCT_Y[4][64]; short DCT_C[2][64]; } idata; struct idct_data_buffer_element *next; } *first; struct idct_data_buffer_element *last; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } *cond; } *

user_defined_types: struct idct_data_buffer { int elements; struct idct_data_buffer_element *first; struct idct_data_buffer_element *last; union pthread_mutex_t *mutex; union pthread_cond_t *cond; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct idct_data_buffer_element { enum element_type type; struct idct_data idata; struct idct_data_buffer_element *next; }