decompiled_code:
__int64 __fastcall bitset_intersect(__int64 *a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rsi

result = *((unsigned int *)a1 + 2);
if ( (_DWORD)result != *((_DWORD *)a2 + 2) )
_assert_fail("a->n_words == b->n_words", "src/bitset.c", 0x3Cu, "bitset_intersect");
if ( (int)result > 0 )
{
v3 = *a1;
v4 = *a2;
result = 0LL;
do
{
*(_DWORD *)(v3 + 4 * result) &= *(_DWORD *)(v4 + 4 * result);
++result;
}
while ( *((_DWORD *)a1 + 2) > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rsi

result = *((unsigned int *)a1 + 2);
if ( (_DWORD)result != *((_DWORD *)a2 + 2) )
_assert_fail("a->n_words == b->n_words", "src/bitset.c", 0x3Cu, "bitset_intersect");
if ( (int)result > 0 )
{
v3 = *a1;
v4 = *a2;
result = 0LL;
do
{
*(_DWORD *)(v3 + 4 * result) &= *(_DWORD *)(v4 + 4 * result);
++result;
}
while ( *((_DWORD *)a1 + 2) > (int)result );
}
return result;
}

original_code:
void bitset_intersect(struct _bitset * a, const struct _bitset * b) {
    ((a->n_words == b->n_words) ? (void) (0) : __assert_fail ("a->n_words == b->n_words", "src/bitset.c", 60, __extension__ __PRETTY_FUNCTION__));
    for(int i = 0; i < a->n_words; ++i)
        a->words[i] &= b->words[i];
}

canonical_original_code:
void bitset_intersect(struct _bitset *a, struct _bitset *b) {
    ((a->n_words == b->n_words) ? (void) (0) : __assert_fail ("a->n_words == b->n_words", "src/bitset.c", 60, __extension__ __PRETTY_FUNCTION__));
    for(int i = 0; i < a->n_words; ++i)
        a->words[i] &= b->words[i];
}


repo: lightcaster/fslib

decompiled_code:
float __fastcall real_sum(float a1, float a2)
{
return a1 + a2;
}

canonical_decompiled_code:
float __fastcall func0(float a1, float a2)
{
return a1 + a2;
}

original_code: float real_sum(const float a, const float b) { return a+b; }

canonical_original_code: float real_sum(float a, float b) { return a+b; }

variable_types: a float

variable_types: b float

return_type: float


decompiled_code:
float __fastcall real_product(float a1, float a2)
{
return a1 * a2;
}

canonical_decompiled_code:
float __fastcall func1(float a1, float a2)
{
return a1 * a2;
}

original_code: float real_product(const float a, const float b) { return a*b; }

canonical_original_code: float real_product(float a, float b) { return a*b; }


decompiled_code:
float __fastcall tropical_sum(float a1, float a2)
{
return fminf(a1, a2);
}

canonical_decompiled_code:
float __fastcall func2(float a1, float a2)
{
return fminf(a1, a2);
}

original_code: float tropical_sum(const float a, const float b) { return a < b ? a : b; }

canonical_original_code: float tropical_sum(float a, float b) { return a < b ? a : b; }


decompiled_code:
// attributes: thunk
float __fastcall tropical_product(float a1, float a2)
{
return real_sum(a1, a2);
}

canonical_decompiled_code:
float __fastcall func3(float a1, float a2)
{
return func0(a1, a2);
}

original_code: float tropical_product(const float a, const float b) { return a + b; }

canonical_original_code: float tropical_product(float a, float b) { return a + b; }


decompiled_code:
void __fastcall fst_iter_remove(void *ptr)
{
bitset_remove(*((_QWORD *)ptr + 1));
queue_remove(*((_QWORD *)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
bitset_remove(*((_QWORD *)ptr + 1));
queue_remove(*((_QWORD *)ptr + 2));
free(ptr);
}

original_code:
void fst_iter_remove(struct _fst_iter * iter) {
    bitset_remove(iter->marked);
    queue_remove(iter->queue);
    iter->fst = ((void *)0);
    free(iter);
}

canonical_original_code:
void fst_iter_remove(struct _fst_iter *iter) {
    bitset_remove(iter->marked);
    queue_remove(iter->queue);
    iter->fst = ((void *)0);
    free(iter);
}

variable_types: struct _fst_iter { struct _fst { unsigned int start; unsigned int n_states; unsigned int n_max; unsigned char sr_type; unsigned char flags; struct _state { unsigned int n_arcs; unsigned int n_max; float weight; int final; struct _arc { unsigned int state; float weight; unsigned int ilabel; unsigned int olabel; } *arcs; } *states; } *fst; struct _bitset { unsigned int *words; int n_words; } *marked; struct _queue { struct _qnode { struct _qnode *next; char item[1]; } *head; struct _qnode *tail; unsigned long item_size; unsigned long n_items; } *queue; unsigned int state; } *

return_type: void

user_defined_types: struct _fst_iter { struct _fst *fst; struct _bitset *marked; struct _queue *queue; unsigned int state; }

user_defined_types: struct _fst { unsigned int start; unsigned int n_states; unsigned int n_max; unsigned char sr_type; unsigned char flags; struct _state *states; }

user_defined_types: struct _queue { struct _qnode *head; struct _qnode *tail; unsigned long item_size; unsigned long n_items; }

user_defined_types: struct _state { unsigned int n_arcs; unsigned int n_max; float weight; int final; struct _arc *arcs; }


decompiled_code:
__int64 __fastcall fst_iter_next(__int64 *a1)
{
__int64 v1; // rdx
__int64 v2; // rsi
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // r13
unsigned int v6; // ebp
unsigned int *v7; // rbx
unsigned int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( queue_deque(a1[2], v8) )
{
v1 = v8[0];
v2 = *a1;
v3 = 3LL * v8[0];
*((_DWORD *)a1 + 6) = v8[0];
result = v1;
v5 = *(_QWORD *)(v2 + 16) + 8 * v3;
if ( *(_DWORD *)v5 )
{
v6 = 0;
do
{
while ( 1 )
{
v7 = (unsigned int *)(*(_QWORD *)(v5 + 16) + 16LL * v6);
if ( !(unsigned int)bitset_get(a1[1], *v7) )
break;
if ( *(_DWORD *)v5 <= ++v6 )
goto LABEL_7;
}
++v6;
queue_enque(a1[2], v7);
bitset_set(a1[1], *v7);
}
while ( *(_DWORD *)v5 > v6 );
LABEL_7:
result = *((unsigned int *)a1 + 6);
}
}
else
{
*((_DWORD *)a1 + 6) = -1;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1)
{
__int64 v1; // rdx
__int64 v2; // rsi
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // r13
unsigned int v6; // ebp
unsigned int *v7; // rbx
unsigned int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( queue_deque(a1[2], v8) )
{
v1 = v8[0];
v2 = *a1;
v3 = 3LL * v8[0];
*((_DWORD *)a1 + 6) = v8[0];
result = v1;
v5 = *(_QWORD *)(v2 + 16) + 8 * v3;
if ( *(_DWORD *)v5 )
{
v6 = 0;
do
{
while ( 1 )
{
v7 = (unsigned int *)(*(_QWORD *)(v5 + 16) + 16LL * v6);
if ( !(unsigned int)bitset_get(a1[1], *v7) )
break;
if ( *(_DWORD *)v5 <= ++v6 )
goto LABEL_7;
}
++v6;
queue_enque(a1[2], v7);
bitset_set(a1[1], *v7);
}
while ( *(_DWORD *)v5 > v6 );
LABEL_7:
result = *((unsigned int *)a1 + 6);
}
}
else
{
*((_DWORD *)a1 + 6) = -1;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
uint32_t fst_iter_next(struct _fst_iter * iter) {
    struct _arc * arc;
    struct _state * state;
    uint32_t s;
    uint32_t a;
    if((queue_deque(iter->queue, &s)) != ((void *)0)) {
        iter->state = s;
        state = &iter->fst->states[s];
        for(a=0; a < state->n_arcs; ++a) {
            arc = &state->arcs[a];
            if (bitset_get(iter->marked, arc->state) == 0) {
                queue_enque(iter->queue, &arc->state);
                bitset_set(iter->marked, arc->state);
            }
        }
    } else {
        iter->state = -1;
    }
    return iter->state;
}

canonical_original_code:
unsigned int fst_iter_next(struct _fst_iter *iter) {
    struct _arc *arc;
    struct _state *state;
    unsigned int s;
    unsigned int a;
    if((queue_deque(iter->queue, &s)) != ((void *)0)) {
        iter->state = s;
        state = &iter->fst->states[s];
        for(a=0; a < state->n_arcs; ++a) {
            arc = &state->arcs[a];
            if (bitset_get(iter->marked, arc->state) == 0) {
                queue_enque(iter->queue, &arc->state);
                bitset_set(iter->marked, arc->state);
            }
        }
    } else {
        iter->state = -1;
    }
    return iter->state;
}

variable_types: struct _state { unsigned int n_arcs; unsigned int n_max; float weight; int final; struct _arc { unsigned int state; float weight; unsigned int ilabel; unsigned int olabel; } *arcs; } *

variable_types:
s
unsigned int

variable_types:
a
unsigned int

return_type: unsigned int

user_defined_types: struct _bitset { unsigned int *words; int n_words; }

user_defined_types: struct _qnode { struct _qnode *next; char item[1]; }


decompiled_code:
__int64 __fastcall fst_iter_visited(__int64 a1, __int64 a2)
{
return bitset_get(*(_QWORD *)(a1 + 8), a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return bitset_get(*(_QWORD *)(a1 + 8), a2);
}

original_code:
int fst_iter_visited(struct _fst_iter * iter, uint32_t s) {
    return bitset_get(iter->marked, s);
}

canonical_original_code:
int fst_iter_visited(struct _fst_iter *iter, unsigned int s) {
    return bitset_get(iter->marked, s);
}

return_type: int

user_defined_types: struct _arc { unsigned int state; float weight; unsigned int ilabel; unsigned int olabel; }


decompiled_code:
void __fastcall empty_chain(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[2];
if ( v2[1] )
{
free(*v2);
free(v2[1]);
}
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[2];
if ( v2[1] )
{
free(*v2);
free(v2[1]);
}
free(v2);
}
while ( v1 );
}
}

original_code:
void empty_chain(struct _bitem * bitem) {
    struct _bitem * t_bitem = ((void *)0);
    while(bitem != ((void *)0)) {
        t_bitem = bitem;
        bitem = bitem->next;
        if (t_bitem->value) {
            free(t_bitem->key);
            free(t_bitem->value);
        }
        free(t_bitem);
    }
}

canonical_original_code:
void empty_chain(struct _bitem *bitem) {
    struct _bitem *t_bitem = ((void *)0);
    while(bitem != ((void *)0)) {
        t_bitem = bitem;
        bitem = bitem->next;
        if (t_bitem->value) {
            free(t_bitem->key);
            free(t_bitem->value);
        }
        free(t_bitem);
    }
}

variable_types: struct _bitem { void *key; void *value; struct _bitem *next; } *


decompiled_code:
void __fastcall hash_remove(void *ptr)
{
unsigned __int64 v1; // rbx
__int64 v2; // rax

if ( *((_QWORD *)ptr + 3) )
{
v1 = 0LL;
do
{
v2 = v1++;
empty_chain(*(void **)(*(_QWORD *)ptr + 16 * v2));
}
while ( *((_QWORD *)ptr + 3) > v1 );
}
free(*(void **)ptr);
free(ptr);
}

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

if ( *((_QWORD *)ptr + 3) )
{
v1 = 0LL;
do
{
v2 = v1++;
func0(*(void **)(*(_QWORD *)ptr + 16 * v2));
}
while ( *((_QWORD *)ptr + 3) > v1 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void hash_remove(struct _hash * hash) {
    for (size_t i = 0; i < hash->size; ++i) {
        empty_chain(hash->buckets[i].head);
    }
    free(hash->buckets);
    free(hash);
}

canonical_original_code:
void hash_remove(struct _hash *hash) {
    for (unsigned long i = 0; i < hash->size; ++i) {
        empty_chain(hash->buckets[i].head);
    }
    free(hash->buckets);
    free(hash);
}

variable_types: struct _hash { struct _bucket { struct _bitem { void *key; void *value; struct _bitem *next; } *head; struct _bitem *tail; } *buckets; unsigned long item_size; unsigned long key_size; unsigned long size; unsigned long n_items; unsigned long (*hash_f)(void *key); int (*cmp_f)(void *key_a, void *key_b); } *

variable_types:
i
unsigned long

user_defined_types: struct _hash { struct _bucket *buckets; unsigned long item_size; unsigned long key_size; unsigned long size; unsigned long n_items; unsigned long (*hash_f)(void *key); int (*cmp_f)(void *key_a, void *key_b); }

user_defined_types: struct _bucket { struct _bitem *head; struct _bitem *tail; }


original_code:
void hash_add( struct _hash * hash,
                void * key,
                void * value)
{
    size_t bnum = hash->hash_f(key) % hash->size;
    struct _bucket * bucket = &hash->buckets[bnum];
    for (
                struct _bitem * bi = bucket->head;
                bi != ((void *)0);
                bi = bi->next
    ) {
        if ( hash->cmp_f(key, bi->key) ) {
            memcpy(bi->key, key, hash->key_size);
            memcpy(bi->value, value, hash->item_size);
            return;
        }
    }
    struct _bitem * bitem = malloc(sizeof(struct _bitem));
    bitem->key = key;
    bitem->value = value;
    bitem->next = ((void *)0);
    bitem->key = malloc(hash->key_size);
    memcpy(bitem->key, key, hash->key_size);
    bitem->value = malloc(hash->item_size);
    memcpy(bitem->value, value, hash->item_size);
    if ( bucket->tail == ((void *)0) ) {
        bucket->tail = bucket->head = bitem;
    } else {
        bucket->tail->next = bitem;
        bucket->tail = bitem;
    }
    ++hash->n_items;
    if ( ( ((float)hash->n_items) / hash->size) > 0.75) {
        hash_resize(hash);
    }
}

canonical_original_code:
void hash_add(struct _hash *hash, void *key, void *value)
{
    unsigned long bnum = hash->hash_f(key) % hash->size;
    struct _bucket *bucket = &hash->buckets[bnum];
    for (
                struct _bitem *bi = bucket->head;
                bi != ((void *)0);
                bi = bi->next
    ) {
        if ( hash->cmp_f(key, bi->key) ) {
            memcpy(bi->key, key, hash->key_size);
            memcpy(bi->value, value, hash->item_size);
            return;
        }
    }
    struct _bitem *bitem = malloc(sizeof(struct _bitem));
    bitem->key = key;
    bitem->value = value;
    bitem->next = ((void *)0);
    bitem->key = malloc(hash->key_size);
    memcpy(bitem->key, key, hash->key_size);
    bitem->value = malloc(hash->item_size);
    memcpy(bitem->value, value, hash->item_size);
    if ( bucket->tail == ((void *)0) ) {
        bucket->tail = bucket->head = bitem;
    } else {
        bucket->tail->next = bitem;
        bucket->tail = bitem;
    }
    ++hash->n_items;
    if ( ( ((float)hash->n_items) / hash->size) > 0.75) {
        hash_resize(hash);
    }
}

variable_types:
key
void *

variable_types:
value
void *

variable_types:
bnum
unsigned long

variable_types: struct _bucket { struct _bitem { void *key; void *value; struct _bitem *next; } *head; struct _bitem *tail; } *


original_code:
void hash_resize(struct _hash * hash) {
    size_t old_size = hash->size;
    struct _bucket * old_buckets = hash->buckets;
    hash->size *= 2;
    hash->n_items = 0;
    hash->buckets = (struct _bucket *)malloc(
                hash->size * sizeof(struct _bucket));
    for (size_t i = 0; i < hash->size; i++)
        hash->buckets[i].head = hash->buckets[i].tail = ((void *)0);
    for (size_t i = 0; i < old_size; i++) {
        for ( struct _bitem * bi = old_buckets[i].head;
                bi != ((void *)0);
                bi = bi->next
        ) {
            hash_add(hash, bi->key, bi->value);
        }
    }
    for (size_t i = 0; i < old_size; ++i)
        empty_chain(old_buckets[i].head);
    free(old_buckets);
}

canonical_original_code:
void hash_resize(struct _hash *hash) {
    unsigned long old_size = hash->size;
    struct _bucket *old_buckets = hash->buckets;
    hash->size *= 2;
    hash->n_items = 0;
    hash->buckets = (struct _bucket *)malloc(
                hash->size * sizeof(struct _bucket));
    for (unsigned long i = 0; i < hash->size; i++)
        hash->buckets[i].head = hash->buckets[i].tail = ((void *)0);
    for (unsigned long i = 0; i < old_size; i++) {
        for ( struct _bitem *bi = old_buckets[i].head;
                bi != ((void *)0);
                bi = bi->next
        ) {
            hash_add(hash, bi->key, bi->value);
        }
    }
    for (unsigned long i = 0; i < old_size; ++i)
        empty_chain(old_buckets[i].head);
    free(old_buckets);
}

user_defined_types: struct _bitem { void *key; void *value; struct _bitem *next; }


original_code:
void * hash_get( struct _hash * hash,
                    void * key,
                    void * item)
{
    struct _bucket bucket = hash->buckets[hash->hash_f(key) % hash->size];
    for (
                struct _bitem * bi = bucket.head;
                bi != ((void *)0);
                bi = bi->next
    ) {
        if ( hash->cmp_f(key, bi->key) ) {
            memcpy(item, bi->value, hash->item_size);
            return bi->value;
        }
    }
    return ((void *)0);
}

canonical_original_code:
void *hash_get(struct _hash *hash, void *key, void *item)
{
    struct _bucket bucket = hash->buckets[hash->hash_f(key) % hash->size];
    for (
                struct _bitem *bi = bucket.head;
                bi != ((void *)0);
                bi = bi->next
    ) {
        if ( hash->cmp_f(key, bi->key) ) {
            memcpy(item, bi->value, hash->item_size);
            return bi->value;
        }
    }
    return ((void *)0);
}

variable_types:
item
void *

variable_types: struct _bucket { struct _bitem { void *key; void *value; struct _bitem *next; } *head; struct _bitem *tail; }

return_type: void *


decompiled_code:
float __fastcall assert_arc_equal(__int64 a1, __int64 a2)
{
float result; // xmm0_4

if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
_assert_fail("arc_a->state == arc_b->state", "src/test.c", 7u, "assert_arc_equal");
if ( *(_DWORD *)(a1 + 8) != *(_DWORD *)(a2 + 8) )
_assert_fail("arc_a->ilabel == arc_b->ilabel", "src/test.c", 8u, "assert_arc_equal");
if ( *(_DWORD *)(a1 + 12) != *(_DWORD *)(a2 + 12) )
_assert_fail("arc_a->olabel == arc_b->olabel", "src/test.c", 9u, "assert_arc_equal");
result = *(float *)(a1 + 4);
if ( result != *(float *)(a2 + 4) )
_assert_fail("arc_a->weight == arc_b->weight", "src/test.c", 0xAu, "assert_arc_equal");
return result;
}

canonical_decompiled_code:
float __fastcall func0(__int64 a1, __int64 a2)
{
float result; // xmm0_4

if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
_assert_fail("arc_a->state == arc_b->state", "src/test.c", 7u, "assert_arc_equal");
if ( *(_DWORD *)(a1 + 8) != *(_DWORD *)(a2 + 8) )
_assert_fail("arc_a->ilabel == arc_b->ilabel", "src/test.c", 8u, "assert_arc_equal");
if ( *(_DWORD *)(a1 + 12) != *(_DWORD *)(a2 + 12) )
_assert_fail("arc_a->olabel == arc_b->olabel", "src/test.c", 9u, "assert_arc_equal");
result = *(float *)(a1 + 4);
if ( result != *(float *)(a2 + 4) )
_assert_fail("arc_a->weight == arc_b->weight", "src/test.c", 0xAu, "assert_arc_equal");
return result;
}

original_code:
void assert_arc_equal(const struct _arc * arc_a, const struct _arc * arc_b) {
    ((arc_a->state == arc_b->state) ? (void) (0) : __assert_fail ("arc_a->state == arc_b->state", "src/test.c", 7, __extension__ __PRETTY_FUNCTION__));
    ((arc_a->ilabel == arc_b->ilabel) ? (void) (0) : __assert_fail ("arc_a->ilabel == arc_b->ilabel", "src/test.c", 8, __extension__ __PRETTY_FUNCTION__));
    ((arc_a->olabel == arc_b->olabel) ? (void) (0) : __assert_fail ("arc_a->olabel == arc_b->olabel", "src/test.c", 9, __extension__ __PRETTY_FUNCTION__));
    ((arc_a->weight == arc_b->weight) ? (void) (0) : __assert_fail ("arc_a->weight == arc_b->weight", "src/test.c", 10, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void assert_arc_equal(struct _arc *arc_a, struct _arc *arc_b) {
    ((arc_a->state == arc_b->state) ? (void) (0) : __assert_fail ("arc_a->state == arc_b->state", "src/test.c", 7, __extension__ __PRETTY_FUNCTION__));
    ((arc_a->ilabel == arc_b->ilabel) ? (void) (0) : __assert_fail ("arc_a->ilabel == arc_b->ilabel", "src/test.c", 8, __extension__ __PRETTY_FUNCTION__));
    ((arc_a->olabel == arc_b->olabel) ? (void) (0) : __assert_fail ("arc_a->olabel == arc_b->olabel", "src/test.c", 9, __extension__ __PRETTY_FUNCTION__));
    ((arc_a->weight == arc_b->weight) ? (void) (0) : __assert_fail ("arc_a->weight == arc_b->weight", "src/test.c", 10, __extension__ __PRETTY_FUNCTION__));
}

variable_types: struct _arc { unsigned int state; float weight; unsigned int ilabel; unsigned int olabel; } *


decompiled_code:
__int64 __fastcall assert_state_equal(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(unsigned int *)(a2 + 12);
if ( *(_DWORD *)(a1 + 12) != (_DWORD)result )
_assert_fail("state_a->final == state_b->final", "src/test.c", 0x10u, "assert_state_equal");
return result;
}

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

result = *(unsigned int *)(a2 + 12);
if ( *(_DWORD *)(a1 + 12) != (_DWORD)result )
_assert_fail("state_a->final == state_b->final", "src/test.c", 0x10u, "assert_state_equal");
return result;
}

original_code:
void assert_state_equal(const struct _state * state_a, const struct _state * state_b) {
    ((state_a->final == state_b->final) ? (void) (0) : __assert_fail ("state_a->final == state_b->final", "src/test.c", 16, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void assert_state_equal(struct _state *state_a, struct _state *state_b) {
    ((state_a->final == state_b->final) ? (void) (0) : __assert_fail ("state_a->final == state_b->final", "src/test.c", 16, __extension__ __PRETTY_FUNCTION__));
}


decompiled_code:
void __fastcall assert_fst_equal(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // r15
unsigned int v4; // er12
__int64 v5; // rbx
__int64 v6; // r13
__int64 v7; // rbx
unsigned int v8; // ebp
__int64 v9; // r14
__int64 v10; // r13
unsigned int v11; // ebx
__int64 v12; // rdi
unsigned int v13; // [rsp+4h] [rbp-44h]
__int64 v14; // [rsp+8h] [rbp-40h]

if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
_assert_fail("a->start == b->start", "src/test.c", 0x1Au, "assert_fst_equal");
if ( *(_BYTE *)(a1 + 12) != *(_BYTE *)(a2 + 12) )
_assert_fail("a->sr_type == b->sr_type", "src/test.c", 0x1Bu, "assert_fst_equal");
v2 = *(_DWORD *)(a1 + 4);
v13 = v2;
if ( v2 != *(_DWORD *)(a2 + 4) )
_assert_fail("a->n_states == b->n_states", "src/test.c", 0x1Cu, "assert_fst_equal");
if ( v2 )
{
v3 = *(_QWORD *)(a1 + 16);
v4 = 0;
v14 = *(_QWORD *)(a2 + 16);
do
{
v5 = 24LL * v4;
v6 = v3 + v5;
v7 = v14 + v5;
v8 = *(_DWORD *)v7;
if ( *(_DWORD *)v6 != *(_DWORD *)v7 )
_assert_fail("state_a->n_arcs == state_b->n_arcs", "src/test.c", 0x23u, "assert_fst_equal");
assert_state_equal(v6, v7);
if ( v8 )
{
v9 = *(_QWORD *)(v6 + 16);
v10 = *(_QWORD *)(v7 + 16);
v11 = 0;
do
{
v12 = v9;
++v11;
v9 += 16LL;
assert_arc_equal(v12, v10);
v10 += 16LL;
}
while ( v8 > v11 );
}
++v4;
}
while ( v13 > v4 );
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // r15
unsigned int v4; // er12
__int64 v5; // rbx
__int64 v6; // r13
__int64 v7; // rbx
unsigned int v8; // ebp
__int64 v9; // r14
__int64 v10; // r13
unsigned int v11; // ebx
__int64 v12; // rdi
unsigned int v13; // [rsp+4h] [rbp-44h]
__int64 v14; // [rsp+8h] [rbp-40h]

if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
_assert_fail("a->start == b->start", "src/test.c", 0x1Au, "assert_fst_equal");
if ( *(_BYTE *)(a1 + 12) != *(_BYTE *)(a2 + 12) )
_assert_fail("a->sr_type == b->sr_type", "src/test.c", 0x1Bu, "assert_fst_equal");
v2 = *(_DWORD *)(a1 + 4);
v13 = v2;
if ( v2 != *(_DWORD *)(a2 + 4) )
_assert_fail("a->n_states == b->n_states", "src/test.c", 0x1Cu, "assert_fst_equal");
if ( v2 )
{
v3 = *(_QWORD *)(a1 + 16);
v4 = 0;
v14 = *(_QWORD *)(a2 + 16);
do
{
v5 = 24LL * v4;
v6 = v3 + v5;
v7 = v14 + v5;
v8 = *(_DWORD *)v7;
if ( *(_DWORD *)v6 != *(_DWORD *)v7 )
_assert_fail("state_a->n_arcs == state_b->n_arcs", "src/test.c", 0x23u, "assert_fst_equal");
func1(v6, v7);
if ( v8 )
{
v9 = *(_QWORD *)(v6 + 16);
v10 = *(_QWORD *)(v7 + 16);
v11 = 0;
do
{
v12 = v9;
++v11;
v9 += 16LL;
func0(v12, v10);
v10 += 16LL;
}
while ( v8 > v11 );
}
++v4;
}
while ( v13 > v4 );
}
}

original_code:
void assert_fst_equal(const struct _fst * a, const struct _fst * b) {
    struct _state * state_a;
    struct _state * state_b;
    struct _arc * arc_a;
    struct _arc * arc_b;
    ((a->start == b->start) ? (void) (0) : __assert_fail ("a->start == b->start", "src/test.c", 26, __extension__ __PRETTY_FUNCTION__));
    ((a->sr_type == b->sr_type) ? (void) (0) : __assert_fail ("a->sr_type == b->sr_type", "src/test.c", 27, __extension__ __PRETTY_FUNCTION__));
    ((a->n_states == b->n_states) ? (void) (0) : __assert_fail ("a->n_states == b->n_states", "src/test.c", 28, __extension__ __PRETTY_FUNCTION__));
    for (uint32_t st = 0; st < a->n_states && st < b->n_states; ++st) {
        state_a = &a->states[st];
        state_b = &b->states[st];
        ((state_a->n_arcs == state_b->n_arcs) ? (void) (0) : __assert_fail ("state_a->n_arcs == state_b->n_arcs", "src/test.c", 35, __extension__ __PRETTY_FUNCTION__));
        assert_state_equal( state_a, state_b );
        for (uint32_t arc = 0;
                    arc < state_a->n_arcs && arc < state_b->n_arcs;
                    ++arc) {
            arc_a = &state_a->arcs[arc];
            arc_b = &state_b->arcs[arc];
            assert_arc_equal( arc_a, arc_b );
        }
    }
}

canonical_original_code:
void assert_fst_equal(struct _fst *a, struct _fst *b) {
    struct _state *state_a;
    struct _state *state_b;
    struct _arc *arc_a;
    struct _arc *arc_b;
    ((a->start == b->start) ? (void) (0) : __assert_fail ("a->start == b->start", "src/test.c", 26, __extension__ __PRETTY_FUNCTION__));
    ((a->sr_type == b->sr_type) ? (void) (0) : __assert_fail ("a->sr_type == b->sr_type", "src/test.c", 27, __extension__ __PRETTY_FUNCTION__));
    ((a->n_states == b->n_states) ? (void) (0) : __assert_fail ("a->n_states == b->n_states", "src/test.c", 28, __extension__ __PRETTY_FUNCTION__));
    for (unsigned int st = 0; st < a->n_states && st < b->n_states; ++st) {
        state_a = &a->states[st];
        state_b = &b->states[st];
        ((state_a->n_arcs == state_b->n_arcs) ? (void) (0) : __assert_fail ("state_a->n_arcs == state_b->n_arcs", "src/test.c", 35, __extension__ __PRETTY_FUNCTION__));
        assert_state_equal( state_a, state_b );
        for (unsigned int arc = 0;
                    arc < state_a->n_arcs && arc < state_b->n_arcs;
                    ++arc) {
            arc_a = &state_a->arcs[arc];
            arc_b = &state_b->arcs[arc];
            assert_arc_equal( arc_a, arc_b );
        }
    }
}

variable_types: struct _fst { unsigned int start; unsigned int n_states; unsigned int n_max; unsigned char sr_type; unsigned char flags; struct _state { unsigned int n_arcs; unsigned int n_max; float weight; int final; struct _arc { unsigned int state; float weight; unsigned int ilabel; unsigned int olabel; } *arcs; } *states; } *

variable_types:
b
struct _fst *

variable_types:
st
unsigned int

variable_types:
arc
unsigned int


decompiled_code:
_BOOL8 __fastcall states_cmp(unsigned int *a1, unsigned int *a2)
{
float v3; // [rsp+Ch] [rbp-Ch]

v3 = *((float *)W + *a1);
return v3 == sr(v3, *((float *)W + *a2));
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned int *a1, unsigned int *a2)
{
float v3; // [rsp+Ch] [rbp-Ch]

v3 = *((float *)W + *a1);
return v3 == sr(v3, *((float *)W + *a2));
}

original_code:
static int states_cmp(const void * a, const void * b) {
    return W[*(uint32_t*)a] == sr.sum(
                    W[*(uint32_t*)a],
                    W[*(uint32_t*)b]
    ) ? 1:0;
}

canonical_original_code:
static int states_cmp(void *a, void *b) {
    return W[*(unsigned int *)a] == sr.sum(
                    W[*(unsigned int *)a],
                    W[*(unsigned int *)b]
    ) ? 1:0;
}

variable_types:
a
void *

variable_types:
b
void *


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

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

original_code: static size_t states_hash(void * a) { return *(int*)a; }

canonical_original_code: static unsigned long states_hash(void *a) { return *(int *)a; }

return_type: unsigned long


decompiled_code:
_BOOL8 __fastcall states_key_eq(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

original_code:
static int states_key_eq(void * a, void * b) {
    return *(uint32_t*)a == *(uint32_t*)b;
}

canonical_original_code:
static int states_key_eq(void *a, void *b) {
    return *(unsigned int *)a == *(unsigned int *)b;
}


backtrace

decompiled_code:
char *__fastcall backtrace(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebp
unsigned int v3; // ebx
unsigned int v4; // er13
char *result; // rax
__int64 v6; // rdx
__int64 v7; // rbp

v2 = a2;
((void (*)(void))fst_add_state)();
if ( !a2 )
return (char *)fst_set_final(a1, 0LL, *((float *)&qword_430 + 1));
v3 = a2;
v4 = 0;
do
{
++v4;
fst_add_state(a1);
v3 = *((_DWORD *)B + 4 * v3);
}
while ( v3 );
fst_set_final(a1, v4, *((float *)&qword_430 + 1));
result = (char *)B;
do
{
v6 = v4--;
v7 = 16LL * v2;
fst_add_arc(
a1,
v4,
v6,
*(unsigned int *)&result[v7 + 8],
*(unsigned int *)&result[v7 + 12],
*(float *)&result[v7 + 4]);
result = (char *)B;
v2 = *(_DWORD *)((char *)B + v7);
}
while ( v2 );
return result;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebp
unsigned int v3; // ebx
unsigned int v4; // er13
char *result; // rax
__int64 v6; // rdx
__int64 v7; // rbp

v2 = a2;
((void (*)(void))fst_add_state)();
if ( !a2 )
return (char *)fst_set_final(a1, 0LL, *((float *)&qword_430 + 1));
v3 = a2;
v4 = 0;
do
{
++v4;
fst_add_state(a1);
v3 = *((_DWORD *)B + 4 * v3);
}
while ( v3 );
fst_set_final(a1, v4, *((float *)&qword_430 + 1));
result = (char *)B;
do
{
v6 = v4--;
v7 = 16LL * v2;
fst_add_arc(
a1,
v4,
v6,
*(unsigned int *)&result[v7 + 8],
*(unsigned int *)&result[v7 + 12],
*(float *)&result[v7 + 4]);
result = (char *)B;
v2 = *(_DWORD *)((char *)B + v7);
}
while ( v2 );
return result;
}

original_code:
static void backtrace(struct _fst * path, uint32_t f) {
    struct _arc arc;
    uint32_t s;
    uint32_t n=0;
    fst_add_state(path);
    for(s=f; s != 0; s=B[s].state, ++n)
        fst_add_state(path);
    fst_set_final(path, n, sr.one);
    for(s=f; s != 0; s=B[s].state, --n) {
        arc=B[s];
        fst_add_arc(path, n-1, n, arc.ilabel, arc.olabel, arc.weight);
    }
}

canonical_original_code:
static void backtrace(struct _fst *path, unsigned int f) {
    struct _arc arc;
    unsigned int s;
    unsigned int n = 0;
    fst_add_state(path);
    for(s=f; s != 0; s=B[s].state, ++n)
        fst_add_state(path);
    fst_set_final(path, n, sr.one);
    for(s=f; s != 0; s=B[s].state, --n) {
        arc=B[s];
        fst_add_arc(path, n-1, n, arc.ilabel, arc.olabel, arc.weight);
    }
}

variable_types:
f
unsigned int

variable_types: struct _arc { unsigned int state; float weight; unsigned int ilabel; unsigned int olabel; }

variable_types:
s
unsigned int

variable_types:
n
unsigned int


decompiled_code:
void __fastcall queue_empty(__int64 a1)
{
void *v1; // rbp

v1 = malloc(*(_QWORD *)(a1 + 16));
while ( queue_deque(a1, v1) )
;
*(_QWORD *)(a1 + 24) = 0LL;
free(v1);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
void *v1; // rbp

v1 = malloc(*(_QWORD *)(a1 + 16));
while ( queue_deque(a1, v1) )
;
*(_QWORD *)(a1 + 24) = 0LL;
free(v1);
}

original_code:
void queue_empty(struct _queue * q) {
    void * item = malloc(q->item_size);
    while( queue_deque(q, item) != ((void *)0) );
    q->n_items = 0;
    free (item);
}

canonical_original_code:
void queue_empty(struct _queue *q) {
    void *item = malloc(q->item_size);
    while( queue_deque(q, item) != ((void *)0) );
    q->n_items = 0;
    free (item);
}

variable_types: struct _queue { struct _qnode { struct _qnode *next; char item[1]; } *head; struct _qnode *tail; unsigned long item_size; unsigned long n_items; } *


decompiled_code:
void __fastcall queue_remove(void *ptr)
{
queue_empty((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
func0((__int64)ptr);
free(ptr);
}

original_code:
void queue_remove(struct _queue * q) {
    queue_empty(q);
    free (q);
}

canonical_original_code:
void queue_remove(struct _queue *q) {
    queue_empty(q);
    free (q);
}


original_code:
static void fst_get_finals(struct _fst * fst, struct _queue * finals) {
    struct _state * state;
    for (uint32_t s=0; s < fst->n_states; ++s) {
        state = fst->states + s;
        if (state->final)
            queue_enque(finals, &s);
    }
}

canonical_original_code:
static void fst_get_finals(struct _fst *fst, struct _queue *finals) {
    struct _state *state;
    for (unsigned int s = 0; s < fst->n_states; ++s) {
        state = fst->states + s;
        if (state->final)
            queue_enque(finals, &s);
    }
}

variable_types: struct _state { unsigned int n_arcs; unsigned int n_max; float weight; int final; struct _arc { unsigned int state; float weight; unsigned int ilabel; unsigned int olabel; } *arcs; } *


decompiled_code:
void __fastcall fst_close(__int64 a1, __int64 a2)
{
unsigned int v3; // er12
__int64 v4; // rsi
__int64 v5; // rax
unsigned int v6; // [rsp+0h] [rbp-3Ch] BYREF
char v7[20]; // [rsp+4h] [rbp-38h] BYREF
float v8; // [rsp+18h] [rbp-24h]

if ( *(_QWORD *)(a2 + 24) > 1uLL )
{
sr_get(v7, *(unsigned __int8 *)(a1 + 12));
v3 = fst_add_state(a1);
fst_set_final(a1, v3, v8);
while ( queue_deque(a2, &v6) )
{
v4 = v6;
v5 = *(_QWORD *)(a1 + 16) + 24LL * v6;
*(_DWORD *)(v5 + 12) = 0;
fst_add_arc(a1, v4, v3, 0LL, 0LL, *(float *)(v5 + 8));
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2)
{
unsigned int v3; // er12
__int64 v4; // rsi
__int64 v5; // rax
unsigned int v6; // [rsp+0h] [rbp-3Ch] BYREF
char v7[20]; // [rsp+4h] [rbp-38h] BYREF
float v8; // [rsp+18h] [rbp-24h]

if ( *(_QWORD *)(a2 + 24) > 1uLL )
{
sr_get(v7, *(unsigned __int8 *)(a1 + 12));
v3 = fst_add_state(a1);
fst_set_final(a1, v3, v8);
while ( queue_deque(a2, &v6) )
{
v4 = v6;
v5 = *(_QWORD *)(a1 + 16) + 24LL * v6;
*(_DWORD *)(v5 + 12) = 0;
fst_add_arc(a1, v4, v3, 0LL, 0LL, *(float *)(v5 + 8));
}
}
}

original_code:
void fst_close(struct _fst * fst, struct _queue * finals) {
    if ( finals->n_items < 2)
        return;
    struct _state * state;
    struct _sr sr = sr_get(fst->sr_type);
    uint32_t final;
    uint32_t s;
    final = fst_add_state(fst);
    fst_set_final(fst, final, sr.one);
    while(queue_deque(finals, &s) != ((void *)0)) {
        state = &fst->states[s];
        state->final = 0;
        fst_add_arc( fst,
                        s,
                        final,
                        0,
                        0,
                        state->weight);
    }
}

canonical_original_code:
void fst_close(struct _fst *fst, struct _queue *finals) {
    if ( finals->n_items < 2)
        return;
    struct _state *state;
    struct _sr sr = sr_get(fst->sr_type);
    unsigned int final;
    unsigned int s;
    final = fst_add_state(fst);
    fst_set_final(fst, final, sr.one);
    while(queue_deque(finals, &s) != ((void *)0)) {
        state = &fst->states[s];
        state->final = 0;
        fst_add_arc( fst,
                        s,
                        final,
                        0,
                        0,
                        state->weight);
    }
}

variable_types: struct _sr { float (*sum)(float a, float b); float (*prod)(float a, float b); float zero; float one; }

variable_types:
final
unsigned int


original_code:
void fst_reverse(struct _fst * fst) {
    struct _sr sr = sr_get(fst->sr_type);
    struct _state * state;
    struct _arc * arc;
    struct _fst * orig = fst_create();
    uint32_t s;
    uint32_t start_s = fst->start;
    fst_copy(fst, orig);
    for(s=0; s < fst->n_states; ++s ) {
        state = &fst->states[s];
        state->n_arcs = 0;
        if (state->final) {
            fst->start = s;
            state->final = 0;
        }
    }
    fst_set_final(fst, start_s, sr.one);
    for(s=0; s < orig->n_states; ++s) {
        state = &orig->states[s];
        for(uint32_t a=0; a < state->n_arcs; ++a) {
            arc = &state->arcs[a];
            fst_add_arc( fst,
                            arc->state,
                            s,
                            arc->ilabel,
                            arc->olabel,
                            arc->weight);
        }
    }
    fst_remove(orig);
}

canonical_original_code:
void fst_reverse(struct _fst *fst) {
    struct _sr sr = sr_get(fst->sr_type);
    struct _state *state;
    struct _arc *arc;
    struct _fst *orig = fst_create();
    unsigned int s;
    unsigned int start_s = fst->start;
    fst_copy(fst, orig);
    for(s=0; s < fst->n_states; ++s ) {
        state = &fst->states[s];
        state->n_arcs = 0;
        if (state->final) {
            fst->start = s;
            state->final = 0;
        }
    }
    fst_set_final(fst, start_s, sr.one);
    for(s=0; s < orig->n_states; ++s) {
        state = &orig->states[s];
        for(unsigned int a = 0; a < state->n_arcs; ++a) {
            arc = &state->arcs[a];
            fst_add_arc( fst,
                            arc->state,
                            s,
                            arc->ilabel,
                            arc->olabel,
                            arc->weight);
        }
    }
    fst_remove(orig);
}

variable_types:
a
unsigned int

user_defined_types: struct _sr { float (*sum)(float a, float b); float (*prod)(float a, float b); float zero; float one; }


original_code:
struct _fst * fst_rm_states(struct _fst * fst, struct _bitset * mask) {
    struct _state * state;
    struct _arc * arc;
    uint32_t idx[sizeof(uint32_t) * fst->n_states];
    uint32_t shift = 0;
    for(uint32_t s=0; s < fst->n_states; ++s) {
        if (bitset_get(mask, s) ) {
            ++shift;
        }
        else {
            idx[s] = shift;
            fst->states[s - shift] = fst->states[s];
        }
    }
    fst->n_states -= shift;
    for(uint32_t s=0; s < fst->n_states; ++s) {
        state = &fst->states[s];
        uint32_t sh = 0;
        for(uint32_t a=0; a < state->n_arcs; ++a) {
            arc = &state->arcs[a];
            arc->state -= idx[arc->state];
            if (arc->state >= fst->n_states) {
                ++sh;
            } else {
                state->arcs[a - sh] = state->arcs[a];
            }
        }
        state->n_arcs -= sh;
    }
    return fst;
}

canonical_original_code:
struct _fst *fst_rm_states(struct _fst *fst, struct _bitset *mask) {
    struct _state *state;
    struct _arc *arc;
    unsigned int idx[-1];
    unsigned int shift = 0;
    for(unsigned int s = 0; s < fst->n_states; ++s) {
        if (bitset_get(mask, s) ) {
            ++shift;
        }
        else {
            idx[s] = shift;
            fst->states[s - shift] = fst->states[s];
        }
    }
    fst->n_states -= shift;
    for(unsigned int s = 0; s < fst->n_states; ++s) {
        state = &fst->states[s];
        unsigned int sh = 0;
        for(unsigned int a = 0; a < state->n_arcs; ++a) {
            arc = &state->arcs[a];
            arc->state -= idx[arc->state];
            if (arc->state >= fst->n_states) {
                ++sh;
            } else {
                state->arcs[a - sh] = state->arcs[a];
            }
        }
        state->n_arcs -= sh;
    }
    return fst;
}

variable_types:
fst
struct _fst *

variable_types: struct _bitset { unsigned int *words; int n_words; } *

variable_types:
idx
unsigned int [-1]

variable_types:
shift
unsigned int

variable_types:
sh
unsigned int

return_type: struct _fst { unsigned int start; unsigned int n_states; unsigned int n_max; unsigned char sr_type; unsigned char flags; struct _state { unsigned int n_arcs; unsigned int n_max; float weight; int final; struct _arc { unsigned int state; float weight; unsigned int ilabel; unsigned int olabel; } *arcs; } *states; } *


decompiled_code:
unsigned int *__fastcall fst_trim(unsigned int *a1)
{
__int64 v1; // r14
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // r12

v1 = queue_create(4LL);
fst_get_finals((__int64)a1, v1);
v2 = *(_QWORD *)(v1 + 24);
if ( v2 )
{
if ( v2 != 1 )
fst_close((__int64)a1, v1);
v3 = fst_iter_create(a1);
while ( (unsigned int)fst_iter_next(v3) != -1 )
;
fst_reverse(a1);
v4 = fst_iter_create(a1);
while ( (unsigned int)fst_iter_next(v4) != -1 )
;
fst_reverse(a1);
bitset_intersect(*(_QWORD *)(v3 + 8), *(_QWORD *)(v4 + 8));
bitset_toggle_all(*(_QWORD *)(v3 + 8));
fst_rm_states((__int64)a1, *(_QWORD *)(v3 + 8));
fst_iter_remove(v4);
fst_iter_remove(v3);
}
else
{
fst_empty(a1);
}
queue_remove(v1);
return a1;
}

canonical_decompiled_code:
unsigned int *__fastcall func4(unsigned int *a1)
{
__int64 v1; // r14
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // r12

v1 = queue_create(4LL);
func0((__int64)a1, v1);
v2 = *(_QWORD *)(v1 + 24);
if ( v2 )
{
if ( v2 != 1 )
func1((__int64)a1, v1);
v3 = fst_iter_create(a1);
while ( (unsigned int)fst_iter_next(v3) != -1 )
;
func2(a1);
v4 = fst_iter_create(a1);
while ( (unsigned int)fst_iter_next(v4) != -1 )
;
func2(a1);
bitset_intersect(*(_QWORD *)(v3 + 8), *(_QWORD *)(v4 + 8));
bitset_toggle_all(*(_QWORD *)(v3 + 8));
func3((__int64)a1, *(_QWORD *)(v3 + 8));
fst_iter_remove(v4);
fst_iter_remove(v3);
}
else
{
fst_empty(a1);
}
queue_remove(v1);
return a1;
}

original_code:
struct _fst * fst_trim(struct _fst * fst) {
    struct _queue * finals = queue_create(sizeof(uint32_t));
    fst_get_finals(fst, finals);
    if (finals->n_items == 0) {
        fst_empty(fst);
    } else {
        if (finals->n_items > 1) {
            fst_close(fst, finals);
        }
        struct _fst_iter * iter = fst_iter_create(fst);
        while ( fst_iter_next(iter) != -1 )
            ;
        fst_reverse(fst);
        struct _fst_iter * iter_rev = fst_iter_create(fst);
        while ( fst_iter_next(iter_rev) != -1 )
            ;
        fst_reverse(fst);
        bitset_intersect(iter->marked, iter_rev->marked);
        bitset_toggle_all(iter->marked);
        fst_rm_states(fst, iter->marked);
        fst_iter_remove(iter_rev);
        fst_iter_remove(iter);
    }
    queue_remove(finals);
    return fst;
}

canonical_original_code:
struct _fst *fst_trim(struct _fst *fst) {
    struct _queue *finals = queue_create(sizeof(uint32_t));
    fst_get_finals(fst, finals);
    if (finals->n_items == 0) {
        fst_empty(fst);
    } else {
        if (finals->n_items > 1) {
            fst_close(fst, finals);
        }
        struct _fst_iter *iter = fst_iter_create(fst);
        while ( fst_iter_next(iter) != -1 )
            ;
        fst_reverse(fst);
        struct _fst_iter *iter_rev = fst_iter_create(fst);
        while ( fst_iter_next(iter_rev) != -1 )
            ;
        fst_reverse(fst);
        bitset_intersect(iter->marked, iter_rev->marked);
        bitset_toggle_all(iter->marked);
        fst_rm_states(fst, iter->marked);
        fst_iter_remove(iter_rev);
        fst_iter_remove(iter);
    }
    queue_remove(finals);
    return fst;
}

variable_types: struct _fst_iter { struct _fst { unsigned int start; unsigned int n_states; unsigned int n_max; unsigned char sr_type; unsigned char flags; struct _state { unsigned int n_arcs; unsigned int n_max; float weight; int final; struct _arc { unsigned int state; float weight; unsigned int ilabel; unsigned int olabel; } *arcs; } *states; } *fst; struct _bitset { unsigned int *words; int n_words; } *marked; struct _queue { struct _qnode { struct _qnode *next; char item[1]; } *head; struct _qnode *tail; unsigned long item_size; unsigned long n_items; } *queue; unsigned int state; } *


icomp

decompiled_code:
__int64 __fastcall icomp(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a1 + 2) - *((_DWORD *)a2 + 2));
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a1 + 2) - *((_DWORD *)a2 + 2));
}

original_code:
static int icomp(const void *a, const void *b)
{
  return (int) ( ((struct _arc *)a)->ilabel - ((struct _arc *)b)->ilabel );
}

canonical_original_code:
static int icomp(void *a, void *b)
{
  return (int) ( ((struct _arc *)a)->ilabel - ((struct _arc *)b)->ilabel );
}

variable_types:
a
void *


ocomp

decompiled_code:
__int64 __fastcall ocomp(__int64 a1, __int64 a2)
{
return (unsigned int)(*(_DWORD *)(a1 + 12) - *(_DWORD *)(a2 + 12));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return (unsigned int)(*(_DWORD *)(a1 + 12) - *(_DWORD *)(a2 + 12));
}

original_code:
static int ocomp(const void *a, const void *b)
{
  return (int) ( ((struct _arc *)a)->olabel - ((struct _arc *)b)->olabel );
}

canonical_original_code:
static int ocomp(void *a, void *b)
{
  return (int) ( ((struct _arc *)a)->olabel - ((struct _arc *)b)->olabel );
}

variable_types:
b
void *


decompiled_code:
void __fastcall fst_arc_sort(__int64 a1, int a2)
{
char v2; // al
char v3; // al
int (*v4)(const void *, const void *); // r12
unsigned int i; // ebx
__int64 v6; // rax

v2 = *(_BYTE *)(a1 + 13);
if ( a2 )
{
v3 = v2 | 2;
v4 = (int (*)(const void *, const void *))ocomp;
}
else
{
v3 = v2 | 1;
v4 = (int (*)(const void *, const void *))icomp;
}
*(_BYTE *)(a1 + 13) = v3;
for ( i = 0; *(_DWORD *)(a1 + 4) > i; ++i )
{
v6 = i;
qsort(
*(void **)(*(_QWORD *)(a1 + 16) + 24 * v6 + 16),
*(unsigned int *)(*(_QWORD *)(a1 + 16) + 24 * v6),
0x10uLL,
v4);
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
char v2; // al
char v3; // al
int (*v4)(const void *, const void *); // r12
unsigned int i; // ebx
__int64 v6; // rax

v2 = *(_BYTE *)(a1 + 13);
if ( a2 )
{
v3 = v2 | 2;
v4 = (int (*)(const void *, const void *))ocomp;
}
else
{
v3 = v2 | 1;
v4 = (int (*)(const void *, const void *))icomp;
}
*(_BYTE *)(a1 + 13) = v3;
for ( i = 0; *(_DWORD *)(a1 + 4) > i; ++i )
{
v6 = i;
qsort(
*(void **)(*(_QWORD *)(a1 + 16) + 24 * v6 + 16),
*(unsigned int *)(*(_QWORD *)(a1 + 16) + 24 * v6),
0x10uLL,
v4);
}
}

original_code:
void fst_arc_sort(struct _fst * fst, int sort_outer) {
    struct _state * state;
    int (*comp)(const void *, const void *);
    if (sort_outer == 0) {
        comp=icomp;
        fst->flags |= 0x01;
    } else {
        comp=ocomp;
        fst->flags |= 0x02;
    }
    for(uint32_t s = 0; s < fst->n_states; ++s) {
        state = &fst->states[s];
        qsort( state->arcs,
                state->n_arcs,
                sizeof(struct _arc),
                comp );
    }
}

canonical_original_code:
void fst_arc_sort(struct _fst *fst, int sort_outer) {
    struct _state *state;
    int (*comp)(void *, void *);
    if (sort_outer == 0) {
        comp=icomp;
        fst->flags |= 0x01;
    } else {
        comp=ocomp;
        fst->flags |= 0x02;
    }
    for(unsigned int s = 0; s < fst->n_states; ++s) {
        state = &fst->states[s];
        qsort( state->arcs,
                state->n_arcs,
                sizeof(struct _arc),
                comp );
    }
}

variable_types: struct _fst { unsigned int start; unsigned int n_states; unsigned int n_max; unsigned char sr_type; unsigned char flags; struct _state { unsigned int n_arcs; unsigned int n_max; float weight; int final; struct _arc { unsigned int state; float weight; unsigned int ilabel; unsigned int olabel; } *arcs; } *states; } *

variable_types:
comp
int (*)(void *, void *)


original_code:
static void heap_items_swap(struct _heap * heap, size_t i, size_t j) {
    char * items = heap->items;
    size_t s = heap->item_size;
    char * tmp = malloc(s);
    memcpy(tmp, items + i*s, s);
    memcpy(items + i*s, items + j*s, s);
    memcpy(items + j*s, tmp, s);
    if (heap->ht != ((void *)0)) {
        hash_add(heap->ht, items + i*s, &i);
        hash_add(heap->ht, items + j*s, &j);
    }
    free(tmp);
}

canonical_original_code:
static void heap_items_swap(struct _heap *heap, unsigned long i, unsigned long j) {
    char *items = heap->items;
    unsigned long s = heap->item_size;
    char *tmp = malloc(s);
    memcpy(tmp, items + i*s, s);
    memcpy(items + i*s, items + j*s, s);
    memcpy(items + j*s, tmp, s);
    if (heap->ht != ((void *)0)) {
        hash_add(heap->ht, items + i*s, &i);
        hash_add(heap->ht, items + j*s, &j);
    }
    free(tmp);
}

variable_types: struct _heap { unsigned long n_items; unsigned long n_max; unsigned long item_size; unsigned long limit; int (*cmp)(void *a, void *b); struct _hash { struct _bucket { struct _bitem { void *key; void *value; struct _bitem *next; } *head; struct _bitem *tail; } *buckets; unsigned long item_size; unsigned long key_size; unsigned long size; unsigned long n_items; unsigned long (*hash_f)(void *key); int (*cmp_f)(void *key_a, void *key_b); } *ht; char *items; } *

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types:
items
char *

variable_types:
s
unsigned long

variable_types:
tmp
char *

user_defined_types: struct _heap { unsigned long n_items; unsigned long n_max; unsigned long item_size; unsigned long limit; int (*cmp)(void *a, void *b); struct _hash *ht; char *items; }


original_code:
struct _hash * heap_index(struct _heap * heap, hash_func hsh, cmp_func hcmp) {
    if (heap->ht != ((void *)0))
        hash_remove(heap->ht);
    heap->ht = hash_create( hsh,
                            hcmp,
                            heap->item_size,
                            sizeof(size_t),
                            heap->n_max
                        );
    for (size_t i = 0; i < heap->n_items; ++i)
        hash_add(heap->ht, heap->items + i*heap->item_size, &i);
    return heap->ht;
}

canonical_original_code:
struct _hash *heap_index(struct _heap *heap, unsigned long (*hsh)(void *key), int (*hcmp)(void *key_a, void *key_b)) {
    if (heap->ht != ((void *)0))
        hash_remove(heap->ht);
    heap->ht = hash_create( hsh,
                            hcmp,
                            heap->item_size,
                            sizeof(unsigned long),
                            heap->n_max
                        );
    for (unsigned long i = 0; i < heap->n_items; ++i)
        hash_add(heap->ht, heap->items + i*heap->item_size, &i);
    return heap->ht;
}

variable_types: struct _heap { unsigned long n_items; unsigned long n_max; unsigned long item_size; unsigned long limit; int (*cmp)(void *a, void *b); struct _hash *ht; char *items; } *

variable_types:
hsh
unsigned long (*)(void *key)

variable_types:
hcmp
int (*)(void *key_a, void *key_b)

return_type: struct _hash { struct _bucket { struct _bitem { void *key; void *value; struct _bitem *next; } *head; struct _bitem *tail; } *buckets; unsigned long item_size; unsigned long key_size; unsigned long size; unsigned long n_items; unsigned long (*hash_f)(void *key); int (*cmp_f)(void *key_a, void *key_b); } *


decompiled_code:
void __fastcall heap_remove(void *ptr)
{
void *v2; // rdi

if ( !ptr )
_assert_fail("heap != NULL", "src/heap.c", 0x5Fu, "heap_remove");
v2 = (void *)*((_QWORD *)ptr + 6);
if ( !v2 )
_assert_fail("heap->items != NULL", "src/heap.c", 0x60u, "heap_remove");
if ( *((_QWORD *)ptr + 5) )
{
hash_remove(*((_QWORD *)ptr + 5));
v2 = (void *)*((_QWORD *)ptr + 6);
}
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void *v2; // rdi

if ( !ptr )
_assert_fail("heap != NULL", "src/heap.c", 0x5Fu, "heap_remove");
v2 = (void *)*((_QWORD *)ptr + 6);
if ( !v2 )
_assert_fail("heap->items != NULL", "src/heap.c", 0x60u, "heap_remove");
if ( *((_QWORD *)ptr + 5) )
{
hash_remove(*((_QWORD *)ptr + 5));
v2 = (void *)*((_QWORD *)ptr + 6);
}
free(v2);
free(ptr);
}

original_code:
void heap_remove(struct _heap * heap) {
    ((heap != ((void *)0)) ? (void) (0) : __assert_fail ("heap != NULL", "src/heap.c", 95, __extension__ __PRETTY_FUNCTION__));
    ((heap->items != ((void *)0)) ? (void) (0) : __assert_fail ("heap->items != NULL", "src/heap.c", 96, __extension__ __PRETTY_FUNCTION__));
    if (heap->ht != ((void *)0)) {
        hash_remove(heap->ht);
    }
    free(heap->items);
    free(heap);
}

canonical_original_code:
void heap_remove(struct _heap *heap) {
    ((heap != ((void *)0)) ? (void) (0) : __assert_fail ("heap != NULL", "src/heap.c", 95, __extension__ __PRETTY_FUNCTION__));
    ((heap->items != ((void *)0)) ? (void) (0) : __assert_fail ("heap->items != NULL", "src/heap.c", 96, __extension__ __PRETTY_FUNCTION__));
    if (heap->ht != ((void *)0)) {
        hash_remove(heap->ht);
    }
    free(heap->items);
    free(heap);
}


decompiled_code:
unsigned __int64 __fastcall heap_heapify(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
__int64 v3; // r15
__int64 v4; // r14
__int64 v5; // rbp
unsigned __int64 v6; // rbx
__int64 v7; // rsi
unsigned __int64 v8; // r13

result = *(_QWORD *)a1;
v3 = *(_QWORD *)(a1 + 48);
v4 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 <= a2 )
_assert_fail("i < heap->n_items", "src/heap.c", 0x97u, "heap_heapify");
v5 = a2;
while ( 1 )
{
v8 = 2 * v5 + 2;
v6 = 2 * v5 + 1;
if ( v6 >= result )
break;
result = (*(__int64 (__fastcall **)(unsigned __int64, __int64))(a1 + 32))(v3 + v6 * v4, v3 + v4 * v5);
if ( !(_DWORD)result )
{
result = *(_QWORD *)a1;
break;
}
if ( v8 < *(_QWORD *)a1 )
{
result = (*(__int64 (__fastcall **)(unsigned __int64, unsigned __int64))(a1 + 32))(v3 + v4 * v8, v3 + v6 * v4);
if ( (_DWORD)result )
goto LABEL_6;
}
LABEL_7:
if ( v5 == v6 )
return result;
v7 = v5;
v5 = v6;
heap_items_swap((_QWORD *)a1, v7, v6);
result = *(_QWORD *)a1;
}
if ( v8 < result )
{
result = (*(__int64 (__fastcall **)(unsigned __int64, __int64))(a1 + 32))(v3 + v4 * v8, v3 + v4 * v5);
if ( (_DWORD)result )
{
LABEL_6:
v6 = 2 * v5 + 2;
goto LABEL_7;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
__int64 v3; // r15
__int64 v4; // r14
__int64 v5; // rbp
unsigned __int64 v6; // rbx
__int64 v7; // rsi
unsigned __int64 v8; // r13

result = *(_QWORD *)a1;
v3 = *(_QWORD *)(a1 + 48);
v4 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 <= a2 )
_assert_fail("i < heap->n_items", "src/heap.c", 0x97u, "heap_heapify");
v5 = a2;
while ( 1 )
{
v8 = 2 * v5 + 2;
v6 = 2 * v5 + 1;
if ( v6 >= result )
break;
result = (*(__int64 (__fastcall **)(unsigned __int64, __int64))(a1 + 32))(v3 + v6 * v4, v3 + v4 * v5);
if ( !(_DWORD)result )
{
result = *(_QWORD *)a1;
break;
}
if ( v8 < *(_QWORD *)a1 )
{
result = (*(__int64 (__fastcall **)(unsigned __int64, unsigned __int64))(a1 + 32))(v3 + v4 * v8, v3 + v6 * v4);
if ( (_DWORD)result )
goto LABEL_6;
}
LABEL_7:
if ( v5 == v6 )
return result;
v7 = v5;
v5 = v6;
func0((_QWORD *)a1, v7, v6);
result = *(_QWORD *)a1;
}
if ( v8 < result )
{
result = (*(__int64 (__fastcall **)(unsigned __int64, __int64))(a1 + 32))(v3 + v4 * v8, v3 + v4 * v5);
if ( (_DWORD)result )
{
LABEL_6:
v6 = 2 * v5 + 2;
goto LABEL_7;
}
}
return result;
}

original_code:
void heap_heapify(struct _heap * heap, size_t i) {
    char * items = heap->items;
    size_t s = heap->item_size;
    size_t l, r, mx;
    int done = 0;
    ((i < heap->n_items) ? (void) (0) : __assert_fail ("i < heap->n_items", "src/heap.c", 151, __extension__ __PRETTY_FUNCTION__));
    while (!done) {
        l = (((i + 1) << 1) - 1);
        r = ((i + 1) << 1);
        mx = ( l < heap->n_items && heap->cmp(items + l*s, items + i*s))
            ? l : i;
        mx = ( r < heap->n_items && heap->cmp(items + r*s, items + mx*s))
            ? r : mx;
        if (mx != i) {
            heap_items_swap(heap, i, mx);
            i = mx;
        } else {
            done=1;
        }
    }
}

canonical_original_code:
void heap_heapify(struct _heap *heap, unsigned long i) {
    char *items = heap->items;
    unsigned long s = heap->item_size;
    unsigned long l; unsigned long r; unsigned long mx;
    int done = 0;
    ((i < heap->n_items) ? (void) (0) : __assert_fail ("i < heap->n_items", "src/heap.c", 151, __extension__ __PRETTY_FUNCTION__));
    while (!done) {
        l = (((i + 1) << 1) - 1);
        r = ((i + 1) << 1);
        mx = ( l < heap->n_items && heap->cmp(items + l*s, items + i*s))
            ? l : i;
        mx = ( r < heap->n_items && heap->cmp(items + r*s, items + mx*s))
            ? r : mx;
        if (mx != i) {
            heap_items_swap(heap, i, mx);
            i = mx;
        } else {
            done=1;
        }
    }
}

variable_types:
l
unsigned long

variable_types:
r
unsigned long

variable_types:
mx
unsigned long

variable_types: done int


decompiled_code:
void *__fastcall heap_pop(__int64 *a1, void *a2)
{
void *result; // rax
char *v5; // r12
size_t v6; // r13
__int64 v7; // rsi
__int64 v8; // rdi
__int64 v9[6]; // [rsp+0h] [rbp-30h] BYREF

result = 0LL;
if ( *a1 )
{
v5 = (char *)a1[6];
v6 = a1[2];
memcpy(a2, v5, v6);
v7 = *a1 - 1;
*a1 = v7;
if ( !v7 )
goto LABEL_3;
memcpy(v5, &v5[v6 * v7], v6);
v8 = a1[5];
v9[0] = 0LL;
if ( v8 )
hash_add(v8, v5, v9);
if ( (unsigned __int64)*a1 > 1 )
{
heap_heapify((__int64)a1, 0LL);
result = a2;
}
else
{
LABEL_3:
result = a2;
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 *a1, void *a2)
{
void *result; // rax
char *v5; // r12
size_t v6; // r13
__int64 v7; // rsi
__int64 v8; // rdi
__int64 v9[6]; // [rsp+0h] [rbp-30h] BYREF

result = 0LL;
if ( *a1 )
{
v5 = (char *)a1[6];
v6 = a1[2];
memcpy(a2, v5, v6);
v7 = *a1 - 1;
*a1 = v7;
if ( !v7 )
goto LABEL_3;
memcpy(v5, &v5[v6 * v7], v6);
v8 = a1[5];
v9[0] = 0LL;
if ( v8 )
hash_add(v8, v5, v9);
if ( (unsigned __int64)*a1 > 1 )
{
func3((__int64)a1, 0LL);
result = a2;
}
else
{
LABEL_3:
result = a2;
}
}
return result;
}

original_code:
void * heap_pop(struct _heap * heap, void * item) {
    char * items = heap->items;
    size_t s = heap->item_size;
    if (heap->n_items == 0)
        return ((void *)0);
    memcpy(item, items, s);
    --heap->n_items;
    if (heap->n_items > 0) {
        memcpy(items, items + heap->n_items * s, s);
        size_t i=0;
        if (heap->ht != ((void *)0))
            hash_add(heap->ht, items, &i);
    }
    if (heap->n_items > 1)
        heap_heapify(heap, 0);
    return item;
}

canonical_original_code:
void *heap_pop(struct _heap *heap, void *item) {
    char *items = heap->items;
    unsigned long s = heap->item_size;
    if (heap->n_items == 0)
        return ((void *)0);
    memcpy(item, items, s);
    --heap->n_items;
    if (heap->n_items > 0) {
        memcpy(items, items + heap->n_items * s, s);
        unsigned long i = 0;
        if (heap->ht != ((void *)0))
            hash_add(heap->ht, items, &i);
    }
    if (heap->n_items > 1)
        heap_heapify(heap, 0);
    return item;
}

variable_types:
item
void *


decompiled_code:
void __fastcall heap_update(__int64 a1, const void *a2, unsigned __int64 a3)
{
__int64 v3; // r13
size_t v4; // r12
__int64 v6; // rbx
__int64 v7; // rdi
__int64 v8[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = *(_QWORD *)(a1 + 48);
v4 = *(_QWORD *)(a1 + 16);
v8[0] = a3;
if ( *(_QWORD *)a1 <= a3 )
_assert_fail("i < heap->n_items", "src/heap.c", 0xEEu, "heap_update");
v6 = a3;
if ( !a2 )
goto LABEL_9;
if ( !(*(unsigned int (__fastcall **)(const void *, size_t))(a1 + 32))(a2, v3 + v4 * a3) )
_assert_fail("heap->cmp(item, items + i*s)", "src/heap.c", 0xF3u, "heap_update");
memcpy((void *)(v3 + v4 * v8[0]), a2, v4);
v7 = *(_QWORD *)(a1 + 40);
if ( v7 )
hash_add(v7, a2, v8);
v6 = v8[0];
while ( v6 )
{
if ( !(*(unsigned int (__fastcall **)(size_t, size_t))(a1 + 32))(
v3 + v4 * v6,
v3 + v4 * (((unsigned __int64)(v6 + 1) >> 1) - 1)) )
break;
v6 = ((unsigned __int64)(v8[0] + 1) >> 1) - 1;
heap_items_swap((_QWORD *)a1, v8[0], v6);
v8[0] = v6;
LABEL_9:
;
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, const void *a2, unsigned __int64 a3)
{
__int64 v3; // r13
size_t v4; // r12
__int64 v6; // rbx
__int64 v7; // rdi
__int64 v8[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = *(_QWORD *)(a1 + 48);
v4 = *(_QWORD *)(a1 + 16);
v8[0] = a3;
if ( *(_QWORD *)a1 <= a3 )
_assert_fail("i < heap->n_items", "src/heap.c", 0xEEu, "heap_update");
v6 = a3;
if ( !a2 )
goto LABEL_9;
if ( !(*(unsigned int (__fastcall **)(const void *, size_t))(a1 + 32))(a2, v3 + v4 * a3) )
_assert_fail("heap->cmp(item, items + i*s)", "src/heap.c", 0xF3u, "heap_update");
memcpy((void *)(v3 + v4 * v8[0]), a2, v4);
v7 = *(_QWORD *)(a1 + 40);
if ( v7 )
hash_add(v7, a2, v8);
v6 = v8[0];
while ( v6 )
{
if ( !(*(unsigned int (__fastcall **)(size_t, size_t))(a1 + 32))(
v3 + v4 * v6,
v3 + v4 * (((unsigned __int64)(v6 + 1) >> 1) - 1)) )
break;
v6 = ((unsigned __int64)(v8[0] + 1) >> 1) - 1;
func0((_QWORD *)a1, v8[0], v6);
v8[0] = v6;
LABEL_9:
;
}
}

original_code:
void heap_update(struct _heap * heap, void * item, size_t i) {
    char * items = heap->items;
    size_t s = heap->item_size;
    size_t j;
    ((i < heap->n_items) ? (void) (0) : __assert_fail ("i < heap->n_items", "src/heap.c", 238, __extension__ __PRETTY_FUNCTION__));
    if (item != ((void *)0)) {
        ((heap->cmp(item, items + i*s)) ? (void) (0) : __assert_fail ("heap->cmp(item, items + i*s)", "src/heap.c", 243, __extension__ __PRETTY_FUNCTION__));
        memcpy(items + i*s, item, s);
        if (heap->ht != ((void *)0))
            hash_add(heap->ht, item, &i);
    }
    while (i > 0 && heap->cmp(items + i*s, items + (((i + 1) >> 1) - 1)*s)) {
        j = (((i + 1) >> 1) - 1);
        heap_items_swap(heap, i, j);
        i = j;
    }
}

canonical_original_code:
void heap_update(struct _heap *heap, void *item, unsigned long i) {
    char *items = heap->items;
    unsigned long s = heap->item_size;
    unsigned long j;
    ((i < heap->n_items) ? (void) (0) : __assert_fail ("i < heap->n_items", "src/heap.c", 238, __extension__ __PRETTY_FUNCTION__));
    if (item != ((void *)0)) {
        ((heap->cmp(item, items + i*s)) ? (void) (0) : __assert_fail ("heap->cmp(item, items + i*s)", "src/heap.c", 243, __extension__ __PRETTY_FUNCTION__));
        memcpy(items + i*s, item, s);
        if (heap->ht != ((void *)0))
            hash_add(heap->ht, item, &i);
    }
    while (i > 0 && heap->cmp(items + i*s, items + (((i + 1) >> 1) - 1)*s)) {
        j = (((i + 1) >> 1) - 1);
        heap_items_swap(heap, i, j);
        i = j;
    }
}


original_code:
static void heap_delete_max(struct _heap * heap) {
    char * items = heap->items;
    size_t s = heap->item_size;
    size_t m = 0;
    for (size_t i = 1; i < heap->n_items + 1; ++i) {
        if ( heap->cmp(items +m*s, items + i*s)) m = i;
    }
    if (m != heap->n_items) {
        memcpy(items + m*s, items + heap->n_items*s, s);
        if (heap->ht != ((void *)0))
            hash_add(heap->ht, items + m*s, &m);
        heap_update(heap, ((void *)0), m);
    }
}

canonical_original_code:
static void heap_delete_max(struct _heap *heap) {
    char *items = heap->items;
    unsigned long s = heap->item_size;
    unsigned long m = 0;
    for (unsigned long i = 1; i < heap->n_items + 1; ++i) {
        if ( heap->cmp(items +m*s, items + i*s)) m = i;
    }
    if (m != heap->n_items) {
        memcpy(items + m*s, items + heap->n_items*s, s);
        if (heap->ht != ((void *)0))
            hash_add(heap->ht, items + m*s, &m);
        heap_update(heap, ((void *)0), m);
    }
}

variable_types:
m
unsigned long


original_code:
void heap_insert(struct _heap * heap, void * item) {
    size_t s = heap->item_size;
    if (heap->limit == 0 && heap->n_max == heap->n_items) {
        heap->n_max *= 2;
        heap->items = realloc(heap->items, heap->n_max * s);
    }
    memcpy(heap->items + heap->n_items * s, item, s);
    if (heap->ht != ((void *)0))
        hash_add(heap->ht, item, &heap->n_items);
    if (heap->limit == 0 || heap->n_items < heap->limit) {
        heap_update(heap, ((void *)0), heap->n_items++);
    } else {
        heap_delete_max(heap);
    }
}

canonical_original_code:
void heap_insert(struct _heap *heap, void *item) {
    unsigned long s = heap->item_size;
    if (heap->limit == 0 && heap->n_max == heap->n_items) {
        heap->n_max *= 2;
        heap->items = realloc(heap->items, heap->n_max * s);
    }
    memcpy(heap->items + heap->n_items * s, item, s);
    if (heap->ht != ((void *)0))
        hash_add(heap->ht, item, &heap->n_items);
    if (heap->limit == 0 || heap->n_items < heap->limit) {
        heap_update(heap, ((void *)0), heap->n_items++);
    } else {
        heap_delete_max(heap);
    }
}


decompiled_code:
__int64 __fastcall heap_find(__int64 a1)
{
if ( !*(_QWORD *)(a1 + 40) )
_assert_fail("heap->ht != NULL", "src/heap.c", 0x105u, "heap_find");
return hash_get();
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
if ( !*(_QWORD *)(a1 + 40) )
_assert_fail("heap->ht != NULL", "src/heap.c", 0x105u, "heap_find");
return hash_get();
}

original_code:
void * heap_find(struct _heap * heap, void * item, size_t * pi) {
    ((heap->ht != ((void *)0)) ? (void) (0) : __assert_fail ("heap->ht != NULL", "src/heap.c", 261, __extension__ __PRETTY_FUNCTION__));
    return hash_get(heap->ht, item, pi);
}

canonical_original_code:
void *heap_find(struct _heap *heap, void *item, unsigned long *pi) {
    ((heap->ht != ((void *)0)) ? (void) (0) : __assert_fail ("heap->ht != NULL", "src/heap.c", 261, __extension__ __PRETTY_FUNCTION__));
    return hash_get(heap->ht, item, pi);
}

variable_types:
pi
unsigned long *


decompiled_code:
__int64 __fastcall fst_compile_str(__int64 a1, const char *a2)
{
__int64 v2; // r13
char *v3; // r12
char v5[65560]; // [rsp+0h] [rbp-10018h] BYREF

v2 = 1LL;
strcpy(v5, a2);
while ( 1 )
{
v3 = strtok(v5, "\n");
if ( !v3 )
break;
while ( 1 )
{
if ( (unsigned int)parse_line(a1, v3) )
{
fprintf(stderr, "Invalid input line %zd: %s\n", v2, v3);
exit(1);
}
if ( ++v2 == 1 )
break;
v3 = strtok(0LL, "\n");
if ( !v3 )
return a1;
}
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
__int64 v2; // r13
char *v3; // r12
char v5[65560]; // [rsp+0h] [rbp-10018h] BYREF

v2 = 1LL;
strcpy(v5, a2);
while ( 1 )
{
v3 = strtok(v5, "\n");
if ( !v3 )
break;
while ( 1 )
{
if ( (unsigned int)func6(a1, v3) )
{
fprintf(stderr, "Invalid input line %zd: %s\n", v2, v3);
exit(1);
}
if ( ++v2 == 1 )
break;
v3 = strtok(0LL, "\n");
if ( !v3 )
return a1;
}
}
return a1;
}

original_code:
struct _fst * fst_compile_str(struct _fst * fst, const char * str) {
    char p[0xffff];
    char * tok;
    size_t line = 1;
    strcpy(p, str);
    do {
        if (line == 1)
            tok = strtok(p, "\n");
        else {
            tok = strtok(((void *)0), "\n");
        }
        if (tok)
            if ( _parse_line(fst, tok) != 0) {
                    fprintf(stderr, "Invalid input line %zd: %s\n", line, tok);
                    exit(1);
            }
        ++line;
    } while (tok);
    return fst;
}

canonical_original_code:
struct _fst *fst_compile_str(struct _fst *fst, char *str) {
    char p[65535];
    char *tok;
    unsigned long line = 1;
    strcpy(p, str);
    do {
        if (line == 1)
            tok = strtok(p, "\n");
        else {
            tok = strtok(((void *)0), "\n");
        }
        if (tok)
            if ( _parse_line(fst, tok) != 0) {
                    fprintf(stderr, "Invalid input line %zd: %s\n", line, tok);
                    exit(1);
            }
        ++line;
    } while (tok);
    return fst;
}

variable_types:
fst
struct _fst *

variable_types:
str
char *

variable_types:
tok
char *

variable_types:
line
unsigned long


trt

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

result = symt_getr(a2, a1);
if ( result == -1 )
{
fprintf(stderr, "Unknown token: %s\n", a1);
result = -1LL;
}
return result;
}

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

result = symt_getr(a2, a1);
if ( result == -1 )
{
fprintf(stderr, "Unknown token: %s\n", a1);
result = -1LL;
}
return result;
}

original_code:
static size_t trt(char * token, struct _symt * st) {
    size_t t = symt_getr(st, token);
    if (-1 == t) {
        fprintf(stderr, "Unknown token: %s\n", token);
    }
    return t;
}

canonical_original_code:
static unsigned long trt(char *token, struct _symt *st) {
    unsigned long t = symt_getr(st, token);
    if (-1 == t) {
        fprintf(stderr, "Unknown token: %s\n", token);
    }
    return t;
}

variable_types:
token
char *

variable_types: struct _symt { unsigned long n_items; unsigned long n_max; char **sym; struct _hash { struct _bucket { struct _bitem { void *key; void *value; struct _bitem *next; } *head; struct _bitem *tail; } *buckets; unsigned long item_size; unsigned long key_size; unsigned long size; unsigned long n_items; unsigned long (*hash_f)(void *key); int (*cmp_f)(void *key_a, void *key_b); } *rev; } *

variable_types:
t
unsigned long

user_defined_types: struct _symt { unsigned long n_items; unsigned long n_max; char **sym; struct _hash *rev; }


trn

decompiled_code:
__int64 __fastcall trn(const char *a1)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 10);
if ( *endptr )
{
fprintf(stderr, "Incorrect token: %s\n", a1);
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 10);
if ( *endptr )
{
fprintf(stderr, "Incorrect token: %s\n", a1);
result = -1LL;
}
return result;
}

original_code:
static size_t trn(char * token, struct _symt * st) {
    char * end;
    long dig = strtol(token, &end, 10);
    if (!*end)
        return (size_t)dig;
    fprintf(stderr, "Incorrect token: %s\n", token);
    return -1;
}

canonical_original_code:
static unsigned long trn(char *token, struct _symt *st) {
    char *end;
    long dig = strtol(token, &end, 10);
    if (!*end)
        return (unsigned long)dig;
    fprintf(stderr, "Incorrect token: %s\n", token);
    return -1;
}

variable_types:
end
char *

variable_types: dig long


repo: liheyuan/lincore

decompiled_code:
int test_mydifftime()
{
__int64 v0; // rax
_BYTE v2[16]; // [rsp+0h] [rbp-28h] BYREF
char v3[24]; // [rsp+10h] [rbp-18h] BYREF

curtime(v2);
usleep(5u);
curtime(v3);
v0 = mydifftime(v2, v3);
return printf("Time Diff:%llu\n", v0);
}

canonical_decompiled_code:
int func0()
{
__int64 v0; // rax
_BYTE v2[16]; // [rsp+0h] [rbp-28h] BYREF
char v3[24]; // [rsp+10h] [rbp-18h] BYREF

curtime(v2);
usleep(5u);
curtime(v3);
v0 = mydifftime(v2, v3);
return printf("Time Diff:%llu\n", v0);
}

original_code:
void test_mydifftime()
{
 struct timeval begin, end;
 curtime(&begin);
 usleep(5);
 curtime(&end);
 printf("Time Diff:%llu\n", mydifftime(&begin, &end));
}

canonical_original_code:
void test_mydifftime()
{
 struct timeval begin; struct timeval end;
 curtime(&begin);
 usleep(5);
 curtime(&end);
 printf("Time Diff:%llu\n", mydifftime(&begin, &end));
}

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


decompiled_code:
int test_run()
{
unsigned int v0; // eax
char v2[8192]; // [rsp+0h] [rbp-4068h] BYREF
char v3[2048]; // [rsp+2000h] [rbp-2068h] BYREF
__int64 v4; // [rsp+2800h] [rbp-1868h]
__int64 v5; // [rsp+2808h] [rbp-1860h]
__int64 v6; // [rsp+2810h] [rbp-1858h]
__int64 v7; // [rsp+2818h] [rbp-1850h]
char dest[2048]; // [rsp+2820h] [rbp-1848h] BYREF
char v9[4096]; // [rsp+3020h] [rbp-1048h] BYREF
__int64 v10; // [rsp+4020h] [rbp-48h]
__int64 v11; // [rsp+4028h] [rbp-40h]

v11 = 0LL;
v10 = 0LL;
strncpy(v2, "/tmp/test.bin", 0x800uLL);
strncpy(dest, "/home/liheyuan/code/1000.in", 0x800uLL);
strncpy(v9, "/home/liheyuan/code/1000.out", 0x800uLL);
strncpy(v3, "/home/liheyuan/jail", 0x800uLL);
v7 = 0xFFFFLL;
v5 = 0xFFFFLL;
v6 = 0x2000LL;
v4 = 1000LL;
v0 = run(v2);
printf("Result:%d\n", v0);
printf("Time:%lld ms\n", v11);
return printf("Memory:%lld KB\n", v10);
}

canonical_decompiled_code:
int func1()
{
unsigned int v0; // eax
char v2[8192]; // [rsp+0h] [rbp-4068h] BYREF
char v3[2048]; // [rsp+2000h] [rbp-2068h] BYREF
__int64 v4; // [rsp+2800h] [rbp-1868h]
__int64 v5; // [rsp+2808h] [rbp-1860h]
__int64 v6; // [rsp+2810h] [rbp-1858h]
__int64 v7; // [rsp+2818h] [rbp-1850h]
char dest[2048]; // [rsp+2820h] [rbp-1848h] BYREF
char v9[4096]; // [rsp+3020h] [rbp-1048h] BYREF
__int64 v10; // [rsp+4020h] [rbp-48h]
__int64 v11; // [rsp+4028h] [rbp-40h]

v11 = 0LL;
v10 = 0LL;
strncpy(v2, "/tmp/test.bin", 0x800uLL);
strncpy(dest, "/home/liheyuan/code/1000.in", 0x800uLL);
strncpy(v9, "/home/liheyuan/code/1000.out", 0x800uLL);
strncpy(v3, "/home/liheyuan/jail", 0x800uLL);
v7 = 0xFFFFLL;
v5 = 0xFFFFLL;
v6 = 0x2000LL;
v4 = 1000LL;
v0 = run(v2);
printf("Result:%d\n", v0);
printf("Time:%lld ms\n", v11);
return printf("Memory:%lld KB\n", v10);
}

original_code:
void test_run()
{
 struct RunItem ri;
 ri.use_mem = ri.use_time = 0;
 strncpy(ri.prog_path, "/tmp/test.bin", 2048);
 strncpy(ri.bc_in, "/home/liheyuan/code/1000.in", 2048);
 strncpy(ri.bc_out, "/home/liheyuan/code/1000.out", 2048);
 strncpy(ri.chroot_path, "/home/liheyuan/jail", 2048);
 ri.ml = ri.ol = 65535;
 ri.sl = 8192;
 ri.tl = 1000;
 int ret = run(&ri);
 printf("Result:%d\n", ret);
 printf("Time:%lld ms\n", ri.use_time);
 printf("Memory:%lld KB\n", ri.use_mem);
}

variable_types: struct RunItem { char prog_path[2048]; char prog_file[2048]; char prog_jail_path[2048]; char prog_jail_path_temp[2048]; char chroot_path[2048]; unsigned long long tl; unsigned long long ml; unsigned long long sl; unsigned long long ol; char bc_in[2048]; char bc_out[2048]; char tmp_out[2048]; unsigned long long use_mem; unsigned long long use_time; int result; struct timeval { long tv_sec; long tv_usec; } t_begin; struct timeval t_end; int cpid; int fpid; }

variable_types: ret int

user_defined_types: struct RunItem { char prog_path[2048]; char prog_file[2048]; char prog_jail_path[2048]; char prog_jail_path_temp[2048]; char chroot_path[2048]; unsigned long long tl; unsigned long long ml; unsigned long long sl; unsigned long long ol; char bc_in[2048]; char bc_out[2048]; char tmp_out[2048]; unsigned long long use_mem; unsigned long long use_time; int result; struct timeval t_begin; struct timeval t_end; int cpid; int fpid; }


decompiled_code:
int test_statmem()
{
__int64 v0; // rax

v0 = statmem(4356LL);
return printf("Proc mem: %llu KB", v0);
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rax

v0 = statmem(4356LL);
return printf("Proc mem: %llu KB", v0);
}

original_code:
void test_statmem()
{
 printf("Proc mem: %llu KB", statmem(4356));
}


decompiled_code:
int test_peakmem()
{
__int64 v0; // rax

v0 = peakmem(4354LL);
return printf("Proc peak mem: %llu KB", v0);
}

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

v0 = peakmem(4354LL);
return printf("Proc peak mem: %llu KB", v0);
}

original_code:
void test_peakmem()
{
 printf("Proc peak mem: %llu KB", peakmem(4354));
}


decompiled_code:
int test_copy()
{
unsigned int v0; // eax

v0 = copy("/home/liheyuan/workspace_cpp/LinCore/Debug/LinCore", "/tmp/LinCore");
return printf("Return: %d\n", v0);
}

canonical_decompiled_code:
int func4()
{
unsigned int v0; // eax

v0 = copy("/home/liheyuan/workspace_cpp/LinCore/Debug/LinCore", "/tmp/LinCore");
return printf("Return: %d\n", v0);
}

original_code:
void test_copy()
{
 int ret = copy("/home/liheyuan/workspace_cpp/LinCore/Debug/LinCore",
   "/tmp/LinCore");
 printf("Return: %d\n", ret);
}


decompiled_code:
int test_filecmp()
{
unsigned int v0; // eax

v0 = filecmp("/home/liheyuan/.xsession-errors", "/tmp/.xsession-errors");
return printf("filecmp():%d\n", v0);
}

canonical_decompiled_code:
int func5()
{
unsigned int v0; // eax

v0 = filecmp("/home/liheyuan/.xsession-errors", "/tmp/.xsession-errors");
return printf("filecmp():%d\n", v0);
}

original_code:
void test_filecmp()
{
 char * f1 = "/home/liheyuan/.xsession-errors";
 char * f2 = "/tmp/.xsession-errors";
 printf("filecmp():%d\n", filecmp(f1, f2));
}

canonical_original_code:
void test_filecmp()
{
 char *f1 = "/home/liheyuan/.xsession-errors";
 char *f2 = "/tmp/.xsession-errors";
 printf("filecmp():%d\n", filecmp(f1, f2));
}


decompiled_code:
int test_filecmp_nonblank()
{
unsigned int v0; // eax

v0 = filecmp_nonblank("/home/liheyuan/code/1.txt", "/home/liheyuan/code/2.txt");
return printf("filecmp_nonblank():%d\n", v0);
}

canonical_decompiled_code:
int func6()
{
unsigned int v0; // eax

v0 = filecmp_nonblank("/home/liheyuan/code/1.txt", "/home/liheyuan/code/2.txt");
return printf("filecmp_nonblank():%d\n", v0);
}

original_code:
void test_filecmp_nonblank()
{
 char * f1 = "/home/liheyuan/code/1.txt";
 char * f2 = "/home/liheyuan/code/2.txt";
 printf("filecmp_nonblank():%d\n", filecmp_nonblank(f1, f2));
}

canonical_original_code:
void test_filecmp_nonblank()
{
 char *f1 = "/home/liheyuan/code/1.txt";
 char *f2 = "/home/liheyuan/code/2.txt";
 printf("filecmp_nonblank():%d\n", filecmp_nonblank(f1, f2));
}


decompiled_code:
int test_init_run()
{
int result; // eax
char v1[8192]; // [rsp+0h] [rbp-4068h] BYREF
char dest[8296]; // [rsp+2000h] [rbp-2068h] BYREF

strncpy(v1, "/tmp/test.bin", 0x800uLL);
strncpy(dest, "/home/liheyuan/jail/", 0x800uLL);
if ( (unsigned int)run_before(v1) )
result = puts("Fail to init.");
else
result = puts("Init success.");
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax
char v1[8192]; // [rsp+0h] [rbp-4068h] BYREF
char dest[8296]; // [rsp+2000h] [rbp-2068h] BYREF

strncpy(v1, "/tmp/test.bin", 0x800uLL);
strncpy(dest, "/home/liheyuan/jail/", 0x800uLL);
if ( (unsigned int)run_before(v1) )
result = puts("Fail to init.");
else
result = puts("Init success.");
return result;
}

original_code:
void test_init_run()
{
 struct RunItem ri;
 strncpy(ri.prog_path, "/tmp/test.bin", 2048);
 strncpy(ri.chroot_path, "/home/liheyuan/jail/", 2048);
 if (run_before(&ri))
 {
  printf("Fail to init.\n");
 }
 else
 {
  printf("Init success.\n");
 }
}

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


decompiled_code:
int test_is_file_dir_ok()
{
unsigned int v0; // eax

v0 = isdirok("/home/liheyuan/jail");
return printf("test dir:%d", v0);
}

canonical_decompiled_code:
int func8()
{
unsigned int v0; // eax

v0 = isdirok("/home/liheyuan/jail");
return printf("test dir:%d", v0);
}

original_code:
void test_is_file_dir_ok()
{
 printf("test dir:%d", isdirok("/home/liheyuan/jail"));
}


original_code:
int parse_cmd(int argc, char** argv, struct RunItem* ri)
{
 int i = 1;
 int ft, fm, fi, fo, ff, fj;
 ft = fm = fi = fo = ff = fj = 1;
 unsigned long value;
 while (i < argc)
 {
  if (strlen(argv[i]) == 2 && strncmp(argv[i], "-t", 2) == 0)
  {
   i++;
   value = atoll(argv[i]);
   if (value == 0)
   {
    return 1;
   }
   else
   {
    ft = 0;
    ri->tl = value;
    i++;
    continue;
   }
  }
  if (strlen(argv[i]) == 2 && strncmp(argv[i], "-m", 2) == 0)
  {
   i++;
   value = atoi(argv[i]);
   if (value == 0)
   {
    return 1;
   }
   else
   {
    fm = 0;
    ri->ml = value;
    i++;
    continue;
   }
  }
  if (strlen(argv[i]) == 2 && strncmp(argv[i], "-i", 2) == 0)
  {
   i++;
   strncpy(ri->bc_in, argv[i], 2048);
   i++;
   fi = 0;
   continue;
  }
  if (strlen(argv[i]) == 2 && strncmp(argv[i], "-o", 2) == 0)
  {
   i++;
   strncpy(ri->bc_out, argv[i], 2048);
   i++;
   fo = 0;
   continue;
  }
  if (strlen(argv[i]) == 2 && strncmp(argv[i], "-f", 2) == 0)
  {
   i++;
   strncpy(ri->prog_path, argv[i], 2048);
   i++;
   ff = 0;
   continue;
  }
  if (strlen(argv[i]) == 2 && strncmp(argv[i], "-j", 2) == 0)
  {
   i++;
   strncpy(ri->chroot_path, argv[i], 2048);
   i++;
   fj = 0;
   continue;
  }
  fprintf(stderr, "Unknown option:%s\n", argv[i]);
  return 1;
 }
 if (ft || fm || fi || fo || ff || fj)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}

canonical_original_code:
int parse_cmd(int argc, char **argv, struct RunItem *ri)
{
 int i = 1;
 int ft; int fm; int fi; int fo; int ff; int fj;
 ft = fm = fi = fo = ff = fj = 1;
 unsigned long value;
 while (i < argc)
 {
  if (strlen(argv[i]) == 2 && strncmp(argv[i], "-t", 2) == 0)
  {
   i++;
   value = atoll(argv[i]);
   if (value == 0)
   {
    return 1;
   }
   else
   {
    ft = 0;
    ri->tl = value;
    i++;
    continue;
   }
  }
  if (strlen(argv[i]) == 2 && strncmp(argv[i], "-m", 2) == 0)
  {
   i++;
   value = atoi(argv[i]);
   if (value == 0)
   {
    return 1;
   }
   else
   {
    fm = 0;
    ri->ml = value;
    i++;
    continue;
   }
  }
  if (strlen(argv[i]) == 2 && strncmp(argv[i], "-i", 2) == 0)
  {
   i++;
   strncpy(ri->bc_in, argv[i], 2048);
   i++;
   fi = 0;
   continue;
  }
  if (strlen(argv[i]) == 2 && strncmp(argv[i], "-o", 2) == 0)
  {
   i++;
   strncpy(ri->bc_out, argv[i], 2048);
   i++;
   fo = 0;
   continue;
  }
  if (strlen(argv[i]) == 2 && strncmp(argv[i], "-f", 2) == 0)
  {
   i++;
   strncpy(ri->prog_path, argv[i], 2048);
   i++;
   ff = 0;
   continue;
  }
  if (strlen(argv[i]) == 2 && strncmp(argv[i], "-j", 2) == 0)
  {
   i++;
   strncpy(ri->chroot_path, argv[i], 2048);
   i++;
   fj = 0;
   continue;
  }
  fprintf(stderr, "Unknown option:%s\n", argv[i]);
  return 1;
 }
 if (ft || fm || fi || fo || ff || fj)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct RunItem { char prog_path[2048]; char prog_file[2048]; char prog_jail_path[2048]; char prog_jail_path_temp[2048]; char chroot_path[2048]; unsigned long long tl; unsigned long long ml; unsigned long long sl; unsigned long long ol; char bc_in[2048]; char bc_out[2048]; char tmp_out[2048]; unsigned long long use_mem; unsigned long long use_time; int result; struct timeval { long tv_sec; long tv_usec; } t_begin; struct timeval t_end; int cpid; int fpid; } *

variable_types: i int

variable_types: ft int

variable_types: fm int

variable_types: fi int

variable_types: fo int

variable_types: ff int

variable_types: fj int

variable_types:
value
unsigned long


decompiled_code:
int __fastcall print_result(__int64 a1)
{
printf("Result: %d\n", *(unsigned int *)(a1 + 16432));
printf("Time: %llu ms\n", *(_QWORD *)(a1 + 16424));
return printf("Memory: %llu KB\n", *(_QWORD *)(a1 + 16416));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
printf("Result: %d\n", *(unsigned int *)(a1 + 16432));
printf("Time: %llu ms\n", *(_QWORD *)(a1 + 16424));
return printf("Memory: %llu KB\n", *(_QWORD *)(a1 + 16416));
}

original_code:
void print_result(struct RunItem* ri)
{
 printf("Result: %d\n", ri->result);
 printf("Time: %llu ms\n", ri->use_time);
 printf("Memory: %llu KB\n", ri->use_mem);
}

canonical_original_code:
void print_result(struct RunItem *ri)
{
 printf("Result: %d\n", ri->result);
 printf("Time: %llu ms\n", ri->use_time);
 printf("Memory: %llu KB\n", ri->use_mem);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v5[2063]; // [rsp+0h] [rbp-4078h] BYREF

memset(v5, 0, 0x4060uLL);
v5[1282] = 0x2000LL;
v5[1283] = 0xFFFFLL;
if ( (unsigned int)parse_cmd(argc, (__int64)argv, (__int64)v5) )
{
v3 = -1;
printf(
"Usage:%s \n"
"-t [d time limit (ms)] -m [d memory limit (KB)] \n"
"-i [s bc.in file path] -o [s bc.out file path] \n"
"-f [s prog path] -j [s jail path] \n"
"(-sl [d stack limit (KB) ]) \n"
"(-ol [d output limit (KB) ]) \n"
"\n",
*argv);
}
else
{
v3 = 0;
run(v5);
print_result((__int64)v5);
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v5[2063]; // [rsp+0h] [rbp-4078h] BYREF

memset(v5, 0, 0x4060uLL);
v5[1282] = 0x2000LL;
v5[1283] = 0xFFFFLL;
if ( (unsigned int)func0(argc, (__int64)argv, (__int64)v5) )
{
v3 = -1;
printf(
"Usage:%s \n"
"-t [d time limit (ms)] -m [d memory limit (KB)] \n"
"-i [s bc.in file path] -o [s bc.out file path] \n"
"-f [s prog path] -j [s jail path] \n"
"(-sl [d stack limit (KB) ]) \n"
"(-ol [d output limit (KB) ]) \n"
"\n",
*argv);
}
else
{
v3 = 0;
run(v5);
func1((__int64)v5);
}
return v3;
}

original_code:
int main(int argc, char** argv)
{
 struct RunItem ri =
 { use_mem:0, use_time:0, ol:65535, sl:8192 };
 if (parse_cmd(argc, argv, &ri))
 {
  printf("Usage:%s \n"
   "-t [d time limit (ms)] -m [d memory limit (KB)] \n"
   "-i [s bc.in file path] -o [s bc.out file path] \n"
   "-f [s prog path] -j [s jail path] \n"
   "(-sl [d stack limit (KB) ]) \n"
   "(-ol [d output limit (KB) ]) \n"
   "\n", argv[0]);
  return -1;
 }
 else
 {
  run(&ri);
  print_result(&ri);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct RunItem ri = { use_mem:0, use_time:0, ol:65535, sl:8192 };
 if (parse_cmd(argc, argv, &ri))
 {
  printf("Usage:%s \n"
   "-t [d time limit (ms)] -m [d memory limit (KB)] \n"
   "-i [s bc.in file path] -o [s bc.out file path] \n"
   "-f [s prog path] -j [s jail path] \n"
   "(-sl [d stack limit (KB) ]) \n"
   "(-ol [d output limit (KB) ]) \n"
   "\n", argv[0]);
  return -1;
 }
 else
 {
  run(&ri);
  print_result(&ri);
 }
 return 0;
}


decompiled_code:
__int64 __fastcall run_check(__int64 a1)
{
__int64 result; // rax
int v2; // er8

if ( (unsigned int)isfileok(a1 + 10272) )
{
if ( (unsigned int)isfileok(a1 + 12320) )
{
if ( (unsigned int)isdirok(a1 + 0x2000) )
{
v2 = isfileok(a1);
result = 0LL;
if ( !v2 )
{
*(_DWORD *)(a1 + 16432) = 13;
result = 1LL;
}
}
else
{
*(_DWORD *)(a1 + 16432) = 12;
result = 1LL;
}
}
else
{
*(_DWORD *)(a1 + 16432) = 11;
result = 1LL;
}
}
else
{
*(_DWORD *)(a1 + 16432) = 10;
result = 1LL;
}
return result;
}

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

if ( (unsigned int)isfileok(a1 + 10272) )
{
if ( (unsigned int)isfileok(a1 + 12320) )
{
if ( (unsigned int)isdirok(a1 + 0x2000) )
{
v2 = isfileok(a1);
result = 0LL;
if ( !v2 )
{
*(_DWORD *)(a1 + 16432) = 13;
result = 1LL;
}
}
else
{
*(_DWORD *)(a1 + 16432) = 12;
result = 1LL;
}
}
else
{
*(_DWORD *)(a1 + 16432) = 11;
result = 1LL;
}
}
else
{
*(_DWORD *)(a1 + 16432) = 10;
result = 1LL;
}
return result;
}

original_code:
int run_check(struct RunItem* ri)
{
 if (isfileok(ri->bc_in) == 0)
 {
  ri->result = 10;
  return 1;
 }
 if (isfileok(ri->bc_out) == 0)
 {
  ri->result = 11;
  return 1;
 }
 if (isdirok(ri->chroot_path) == 0)
 {
  ri->result = 12;
  return 1;
 }
 if (isfileok(ri->prog_path) == 0)
 {
  ri->result = 13;
  return 1;
 }
 return 0;
}

canonical_original_code:
int run_check(struct RunItem *ri)
{
 if (isfileok(ri->bc_in) == 0)
 {
  ri->result = 10;
  return 1;
 }
 if (isfileok(ri->bc_out) == 0)
 {
  ri->result = 11;
  return 1;
 }
 if (isdirok(ri->chroot_path) == 0)
 {
  ri->result = 12;
  return 1;
 }
 if (isfileok(ri->prog_path) == 0)
 {
  ri->result = 13;
  return 1;
 }
 return 0;
}


limitres

decompiled_code:
_BOOL8 __fastcall limitres(_QWORD *a1)
{
struct rlimit v2; // [rsp+0h] [rbp-38h] BYREF
struct rlimit rlimits; // [rsp+10h] [rbp-28h] BYREF
struct rlimit v4; // [rsp+20h] [rbp-18h] BYREF

v2.rlim_max = a1[1281] << 10;
v2.rlim_cur = v2.rlim_max;
if ( setrlimit(RLIMIT_AS, &v2) )
return 1LL;
rlimits.rlim_max = a1[1282] << 10;
rlimits.rlim_cur = rlimits.rlim_max;
if ( setrlimit(RLIMIT_STACK, &rlimits) )
return 1LL;
v4.rlim_max = a1[1283] << 10;
v4.rlim_cur = v4.rlim_max;
return setrlimit(RLIMIT_FSIZE, &v4) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_QWORD *a1)
{
struct rlimit v2; // [rsp+0h] [rbp-38h] BYREF
struct rlimit rlimits; // [rsp+10h] [rbp-28h] BYREF
struct rlimit v4; // [rsp+20h] [rbp-18h] BYREF

v2.rlim_max = a1[1281] << 10;
v2.rlim_cur = v2.rlim_max;
if ( setrlimit(RLIMIT_AS, &v2) )
return 1LL;
rlimits.rlim_max = a1[1282] << 10;
rlimits.rlim_cur = rlimits.rlim_max;
if ( setrlimit(RLIMIT_STACK, &rlimits) )
return 1LL;
v4.rlim_max = a1[1283] << 10;
v4.rlim_cur = v4.rlim_max;
return setrlimit(RLIMIT_FSIZE, &v4) != 0;
}

original_code:
int limitres(struct RunItem* ri)
{
 struct rlimit r_mem, r_stack, r_fsize;
 r_mem.rlim_cur = r_mem.rlim_max = ri->ml * 1024L;
 if (setrlimit(RLIMIT_AS, &r_mem) != 0)
 {
  return 1;
 }
 r_stack.rlim_cur = r_stack.rlim_max = ri->sl * 1024L;
 if (setrlimit(RLIMIT_STACK, &r_stack) != 0)
 {
  return 1;
 }
 r_fsize.rlim_cur = r_fsize.rlim_max = ri->ol * 1024L;
 if (setrlimit(RLIMIT_FSIZE, &r_fsize) != 0)
 {
  return 1;
 }
 return 0;
}

canonical_original_code:
int limitres(struct RunItem *ri)
{
 struct rlimit r_mem; struct rlimit r_stack; struct rlimit r_fsize;
 r_mem.rlim_cur = r_mem.rlim_max = ri->ml * 1024L;
 if (setrlimit(RLIMIT_AS, &r_mem) != 0)
 {
  return 1;
 }
 r_stack.rlim_cur = r_stack.rlim_max = ri->sl * 1024L;
 if (setrlimit(RLIMIT_STACK, &r_stack) != 0)
 {
  return 1;
 }
 r_fsize.rlim_cur = r_fsize.rlim_max = ri->ol * 1024L;
 if (setrlimit(RLIMIT_FSIZE, &r_fsize) != 0)
 {
  return 1;
 }
 return 0;
}

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }


setsignal

decompiled_code:
__sighandler_t setsignal()
{
return signal(10, signal_usr1);
}

canonical_decompiled_code:
__sighandler_t func2()
{
return signal(10, signal_usr1);
}

original_code:
void setsignal()
{
 signal(10, signal_usr1);
}


decompiled_code:
char *__fastcall exe_param(char *src)
{
char *v1; // rbp
char *v3; // rdi
__int64 v4; // rax
int v5; // edx

v1 = src;
LODWORD(v4) = strlen(src);
v3 = src + 2048;
LODWORD(v4) = v4 - 1;
if ( (int)v4 >= 0 )
{
v4 = (int)v4;
do
{
v5 = v4;
if ( src[v4] == 47 )
return strcpy(v3, &src[v5 + 1]);
}
while ( (int)--v4 >= 0 );
}
if ( *src == 47 )
{
v5 = 0;
return strcpy(v3, &src[v5 + 1]);
}
return strcpy(v3, v1);
}

canonical_decompiled_code:
char *__fastcall func3(char *src)
{
char *v1; // rbp
char *v3; // rdi
__int64 v4; // rax
int v5; // edx

v1 = src;
LODWORD(v4) = strlen(src);
v3 = src + 2048;
LODWORD(v4) = v4 - 1;
if ( (int)v4 >= 0 )
{
v4 = (int)v4;
do
{
v5 = v4;
if ( src[v4] == 47 )
return strcpy(v3, &src[v5 + 1]);
}
while ( (int)--v4 >= 0 );
}
if ( *src == 47 )
{
v5 = 0;
return strcpy(v3, &src[v5 + 1]);
}
return strcpy(v3, v1);
}

original_code:
void exe_param(struct RunItem* ri)
{
 char* prog = ri->prog_path;
 int len = strlen(prog);
 int pos = 0;
 int i = 0;
 char* p = ri->prog_file;
 for (i = len - 1; i >= 0; i--)
 {
  if (prog[i] == '/')
  {
   pos = i;
   break;
  }
 }
 if (prog[pos] == '/')
 {
  pos++;
 }
 strcpy(p, &prog[pos]);
}

canonical_original_code:
void exe_param(struct RunItem *ri)
{
 char *prog = ri->prog_path;
 int len = strlen(prog);
 int pos = 0;
 int i = 0;
 char *p = ri->prog_file;
 for (i = len - 1; i >= 0; i--)
 {
  if (prog[i] == '/')
  {
   pos = i;
   break;
  }
 }
 if (prog[pos] == '/')
 {
  pos++;
 }
 strcpy(p, &prog[pos]);
}

variable_types:
prog
char *

variable_types: len int

variable_types: pos int

variable_types:
p
char *


decompiled_code:
_BOOL8 change_uid()
{
return setuid(0xFFFEu) != 0;
}

canonical_decompiled_code:
_BOOL8 func4()
{
return setuid(0xFFFEu) != 0;
}

original_code:
int change_uid()
{
 if (setuid(65534) != 0)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}


chrootjail

decompiled_code:
_BOOL8 __fastcall chrootjail(char *path)
{
int v1; // er8
_BOOL8 result; // rax

v1 = chdir(path);
result = 1LL;
if ( v1 != -1 )
result = chroot(path) == -1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(char *path)
{
int v1; // er8
_BOOL8 result; // rax

v1 = chdir(path);
result = 1LL;
if ( v1 != -1 )
result = chroot(path) == -1;
return result;
}

original_code:
int chrootjail(char* path)
{
 if (chdir(path) == -1)
 {
  return 1;
 }
 else
 {
  if (chroot(path) == -1)
  {
   return 1;
  }
  else
  {
   return 0;
  }
 }
}

canonical_original_code:
int chrootjail(char *path)
{
 if (chdir(path) == -1)
 {
  return 1;
 }
 else
 {
  if (chroot(path) == -1)
  {
   return 1;
  }
  else
  {
   return 0;
  }
 }
}

variable_types:
path
char *


original_code:
int cp_exe_jail(struct RunItem* ri)
{
 int len;
 char*tmpath = ri->prog_jail_path_temp;
 strncpy(tmpath, ri->chroot_path, 2048 - 1);
 len = strlen(tmpath);
 if (tmpath[len - 1] != '/')
 {
  tmpath[len] = '/';
  tmpath[len + 1] = '\0';
 }
 strncat(tmpath, ri->prog_file, 2048 - 1);
 ri->prog_jail_path[0] = '/';
 ri->prog_jail_path[1] = '\0';
 strncat(ri->prog_jail_path, ri->prog_file, 2048 - 1);
 return copy(ri->prog_path, ri->prog_jail_path_temp);
}

canonical_original_code:
int cp_exe_jail(struct RunItem *ri)
{
 int len;
 char *tmpath = ri->prog_jail_path_temp;
 strncpy(tmpath, ri->chroot_path, 2048 - 1);
 len = strlen(tmpath);
 if (tmpath[len - 1] != '/')
 {
  tmpath[len] = '/';
  tmpath[len + 1] = '\0';
 }
 strncat(tmpath, ri->prog_file, 2048 - 1);
 ri->prog_jail_path[0] = '/';
 ri->prog_jail_path[1] = '\0';
 strncat(ri->prog_jail_path, ri->prog_file, 2048 - 1);
 return copy(ri->prog_path, ri->prog_jail_path_temp);
}

variable_types:
tmpath
char *


decompiled_code:
__int64 __fastcall run_before(char *src)
{
__int64 result; // rax

*(_OWORD *)(src + 16440) = 0LL;
*((_DWORD *)src + 4108) = 0;
*((_DWORD *)src + 4118) = 0;
*((_QWORD *)src + 2053) = 0LL;
*((_QWORD *)src + 2052) = 0LL;
*(_OWORD *)(src + 16456) = 0LL;
pTV = (__int64)(src + 16440);
*((_DWORD *)src + 4119) = getpid();
exe_param(src);
if ( (unsigned int)cp_exe_jail((__int64)src) )
{
*((_DWORD *)src + 4108) = 6;
result = 1LL;
}
else if ( (unsigned int)exe_priv(src + 6144) )
{
*((_DWORD *)src + 4108) = 7;
result = 1LL;
}
else
{
tmpnam(src + 14368);
setsignal();
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *src)
{
__int64 result; // rax

*(_OWORD *)(src + 16440) = 0LL;
*((_DWORD *)src + 4108) = 0;
*((_DWORD *)src + 4118) = 0;
*((_QWORD *)src + 2053) = 0LL;
*((_QWORD *)src + 2052) = 0LL;
*(_OWORD *)(src + 16456) = 0LL;
pTV = (__int64)(src + 16440);
*((_DWORD *)src + 4119) = getpid();
func3(src);
if ( (unsigned int)func6((__int64)src) )
{
*((_DWORD *)src + 4108) = 6;
result = 1LL;
}
else if ( (unsigned int)exe_priv(src + 6144) )
{
*((_DWORD *)src + 4108) = 7;
result = 1LL;
}
else
{
tmpnam(src + 14368);
func2();
result = 0LL;
}
return result;
}

original_code:
int run_before(struct RunItem* ri)
{
 ri->use_mem = ri->use_time = ri->cpid = ri->result = 0;
 bzero(&ri->t_begin, sizeof(struct timeval));
 bzero(&ri->t_end, sizeof(struct timeval));
 pTV = &(ri->t_begin);
 ri->fpid = getpid();
 exe_param(ri);
 if (cp_exe_jail(ri))
 {
  ri->result = 6;
  return 1;
 }
 if (exe_priv(ri->prog_jail_path_temp))
 {
  ri->result = 7;
  return 1;
 }
 tmpnam(ri->tmp_out);
 setsignal();
 return 0;
}

canonical_original_code:
int run_before(struct RunItem *ri)
{
 ri->use_mem = ri->use_time = ri->cpid = ri->result = 0;
 bzero(&ri->t_begin, sizeof(struct timeval));
 bzero(&ri->t_end, sizeof(struct timeval));
 pTV = &(ri->t_begin);
 ri->fpid = getpid();
 exe_param(ri);
 if (cp_exe_jail(ri))
 {
  ri->result = 6;
  return 1;
 }
 if (exe_priv(ri->prog_jail_path_temp))
 {
  ri->result = 7;
  return 1;
 }
 tmpnam(ri->tmp_out);
 setsignal();
 return 0;
}


decompiled_code:
// attributes: thunk
__int64 update_tmval()
{
return curtime();
}

canonical_decompiled_code:
__int64 func8()
{
return curtime();
}

original_code:
void update_tmval(struct timeval* p)
{
 curtime(p);
}

canonical_original_code:
void update_tmval(struct timeval *p)
{
 curtime(p);
}

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


decompiled_code:
void signal_usr1()
{
update_tmval(pTV);
}

canonical_decompiled_code:
void func9()
{
func8(pTV);
}

original_code:
void signal_usr1(int num)
{
 update_tmval(pTV);
 return;
}

variable_types: num int


decompiled_code:
__int64 __fastcall get_timediff(__int64 a1)
{
return mydifftime(a1 + 16440, a1 + 16456);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return mydifftime(a1 + 16440, a1 + 16456);
}

original_code:
unsigned long long get_timediff(struct RunItem* result)
{
 return mydifftime(&result->t_begin, &result->t_end);
}

canonical_original_code:
unsigned long long get_timediff(struct RunItem *result)
{
 return mydifftime(&result->t_begin, &result->t_end);
}

variable_types: struct RunItem { char prog_path[2048]; char prog_file[2048]; char prog_jail_path[2048]; char prog_jail_path_temp[2048]; char chroot_path[2048]; unsigned long long tl; unsigned long long ml; unsigned long long sl; unsigned long long ol; char bc_in[2048]; char bc_out[2048]; char tmp_out[2048]; unsigned long long use_mem; unsigned long long use_time; int result; struct timeval { long tv_sec; long tv_usec; } t_begin; struct timeval t_end; int cpid; int fpid; } *

return_type: unsigned long long


original_code:
int run_father_while(struct RunItem* ri)
{
 useconds_t tm = 1000 * 5;
 int ret, status;
 update_tmval(&ri->t_end);
 ri->use_mem = max(ri->use_mem, peakmem(ri->cpid));
 ret = waitpid(ri->cpid, &status, 1);
 if (ret == -1)
 {
  ri->result = 8;
  return 1;
 }
 else if (ret == ri->cpid)
 {
  if (
  (((status) & 0x7f) == 0))
  {
   ri->result = 0;
   return 1;
  }
  else
  {
   if (ri->result != 0)
   {
    return 1;
   }
   if ((((signed char) (((status) & 0x7f) + 1) >> 1) > 0) &&
   ((status) & 0x7f) == 11)
   {
    ri->result = 3;
   }
   else
   {
    ri->result = 1;
   }
   return 1;
  }
 }
 else
 {
  if (get_timediff(ri) >= ri->tl)
  {
   kill(ri->cpid, 9);
   ri->result = 2;
   return 0;
  }
  else
  {
   usleep(tm);
   return 0;
  }
 }
}

canonical_original_code:
int run_father_while(struct RunItem *ri)
{
 unsigned int tm = 1000 * 5;
 int ret; int status;
 update_tmval(&ri->t_end);
 ri->use_mem = max(ri->use_mem, peakmem(ri->cpid));
 ret = waitpid(ri->cpid, &status, 1);
 if (ret == -1)
 {
  ri->result = 8;
  return 1;
 }
 else if (ret == ri->cpid)
 {
  if (
  (((status) & 0x7f) == 0))
  {
   ri->result = 0;
   return 1;
  }
  else
  {
   if (ri->result != 0)
   {
    return 1;
   }
   if ((((char) (((status) & 0x7f) + 1) >> 1) > 0) &&
   ((status) & 0x7f) == 11)
   {
    ri->result = 3;
   }
   else
   {
    ri->result = 1;
   }
   return 1;
  }
 }
 else
 {
  if (get_timediff(ri) >= ri->tl)
  {
   kill(ri->cpid, 9);
   ri->result = 2;
   return 0;
  }
  else
  {
   usleep(tm);
   return 0;
  }
 }
}

variable_types:
tm
unsigned int

variable_types: ret int

variable_types: status int


original_code:
void run_after(struct RunItem* ri)
{
 ri->use_time = get_timediff(ri);
 if (ri->result != 0)
 {
  return;
 }
 if (ri->use_mem >= ri->ml)
 {
  ri->result = 3;
 }
 if (filecmp(ri->bc_out, ri->tmp_out) == 0)
 {
  ri->result = 0;
  return;
 }
 else
 {
  if (filecmp_nonblank(ri->bc_out, ri->tmp_out) == 0)
  {
   ri->result = 5;
  }
  else
  {
   ri->result = 4;
  }
 }
 printf("%s\n", ri->tmp_out);
 delete(ri->tmp_out);
 delete(ri->prog_jail_path_temp);
}

canonical_original_code:
void run_after(struct RunItem *ri)
{
 ri->use_time = get_timediff(ri);
 if (ri->result != 0)
 {
  return;
 }
 if (ri->use_mem >= ri->ml)
 {
  ri->result = 3;
 }
 if (filecmp(ri->bc_out, ri->tmp_out) == 0)
 {
  ri->result = 0;
  return;
 }
 else
 {
  if (filecmp_nonblank(ri->bc_out, ri->tmp_out) == 0)
  {
   ri->result = 5;
  }
  else
  {
   ri->result = 4;
  }
 }
 printf("%s\n", ri->tmp_out);
 delete(ri->tmp_out);
 delete(ri->prog_jail_path_temp);
}


decompiled_code:
int __fastcall stdinout_redirect(char *file, char *a2)
{
int result; // eax

if ( close(0) != -1 )
open(file, 0);
result = close(1);
if ( result != -1 )
result = open(a2, 577, 511LL);
return result;
}

canonical_decompiled_code:
int __fastcall func13(char *file, char *a2)
{
int result; // eax

if ( close(0) != -1 )
open(file, 0);
result = close(1);
if ( result != -1 )
result = open(a2, 577, 511LL);
return result;
}

original_code:
void stdinout_redirect(char* input, char* output)
{
 if (close(0) != -1)
 {
  open(input, 00);
 }
 if (close(1) != -1)
 {
  open(output, 01 | 01000 | 0100, 00777);
 }
}

canonical_original_code:
void stdinout_redirect(char *input, char *output)
{
 if (close(0) != -1)
 {
  open(input, 00);
 }
 if (close(1) != -1)
 {
  open(output, 01 | 01000 | 0100, 00777);
 }
}

variable_types:
input
char *

variable_types:
output
char *