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

v8[0] = a3;
v3 = *(_QWORD *)(a1 + 48);
v4 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 <= a3 )
_assert_fail("i < heap->n_items", "src/heap.c", 0xEEu, "heap_update");
if ( a2 )
{
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 + v8[0] * v4), a2, v4);
v6 = *(_QWORD *)(a1 + 40);
if ( v6 )
hash_add(v6, a2, v8);
}
for ( i = v8[0]; i; v8[0] = i )
{
if ( !(*(unsigned int (__fastcall **)(size_t, size_t))(a1 + 32))(
v3 + v4 * i,
v3 + v4 * (((unsigned __int64)(i + 1) >> 1) - 1)) )
break;
i = ((unsigned __int64)(v8[0] + 1) >> 1) - 1;
heap_items_swap((_QWORD *)a1, v8[0], i);
}
}

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

v8[0] = a3;
v3 = *(_QWORD *)(a1 + 48);
v4 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)a1 <= a3 )
_assert_fail("i < heap->n_items", "src/heap.c", 0xEEu, "heap_update");
if ( a2 )
{
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 + v8[0] * v4), a2, v4);
v6 = *(_QWORD *)(a1 + 40);
if ( v6 )
hash_add(v6, a2, v8);
}
for ( i = v8[0]; i; v8[0] = i )
{
if ( !(*(unsigned int (__fastcall **)(size_t, size_t))(a1 + 32))(
v3 + v4 * i,
v3 + v4 * (((unsigned __int64)(i + 1) >> 1) - 1)) )
break;
i = ((unsigned __int64)(v8[0] + 1) >> 1) - 1;
func0((_QWORD *)a1, v8[0], i);
}
}

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


repo: lightcaster/fslib

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: 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:
items
char *

variable_types:
s
unsigned long

variable_types:
m
unsigned long

variable_types:
i
unsigned long

return_type: void

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

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

variable_types:
item
void *

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


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 *

return_type: void *


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

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

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

strcpy(v5, a2);
for ( i = 1LL; ; ++i )
{
v3 = i == 1 ? strtok(v5, "\n") : strtok(0LL, "\n");
if ( !v3 )
break;
if ( (unsigned int)func6(a1, v3) )
{
fprintf(stderr, "Invalid input line %zd: %s\n", i, v3);
exit(1);
}
}
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

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

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 _state { unsigned int n_arcs; unsigned int n_max; float weight; int final; struct _arc *arcs; }


trt

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

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

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

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

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

return_type: 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(v3);
usleep(5u);
curtime(v2);
v0 = mydifftime(v3, v2);
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(v3);
usleep(5u);
curtime(v2);
v0 = mydifftime(v3, v2);
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

return_type: int


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; // ebx
__int64 v5[2063]; // [rsp+0h] [rbp-4078h] BYREF

memset(v5, 0, 0x4060uLL);
v5[1282] = 0x2000LL;
v5[1283] = 0xFFFFLL;
if ( parse_cmd(argc, (__int64)argv, (__int64)v5) )
{
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);
v3 = -1;
}
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; // ebx
__int64 v5[2063]; // [rsp+0h] [rbp-4078h] BYREF

memset(v5, 0, 0x4060uLL);
v5[1282] = 0x2000LL;
v5[1283] = 0xFFFFLL;
if ( func0(argc, (__int64)argv, (__int64)v5) )
{
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);
v3 = -1;
}
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; // edx

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; // edx

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)
{
int v1; // edx
_BOOL8 result; // rax
int v3; // edx
struct rlimit v4; // [rsp+0h] [rbp-38h] BYREF
struct rlimit v5; // [rsp+10h] [rbp-28h] BYREF
struct rlimit rlimits; // [rsp+20h] [rbp-18h] BYREF

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

canonical_decompiled_code:
_BOOL8 __fastcall func1(_QWORD *a1)
{
int v1; // edx
_BOOL8 result; // rax
int v3; // edx
struct rlimit v4; // [rsp+0h] [rbp-38h] BYREF
struct rlimit v5; // [rsp+10h] [rbp-28h] BYREF
struct rlimit rlimits; // [rsp+20h] [rbp-18h] BYREF

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

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(const char *a1)
{
char *v2; // rdi
__int64 v3; // rax
int v4; // edx
int v5; // esi

LODWORD(v3) = strlen(a1);
v2 = (char *)(a1 + 2048);
LODWORD(v3) = v3 - 1;
if ( (int)v3 >= 0 )
{
v3 = (int)v3;
do
{
v4 = v3;
if ( a1[v3] == 47 )
goto LABEL_9;
}
while ( (int)--v3 >= 0 );
}
if ( *a1 == 47 )
{
v4 = 0;
LABEL_9:
v5 = v4 + 1;
return strcpy(v2, &a1[v5]);
}
v5 = 0;
return strcpy(v2, &a1[v5]);
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1)
{
char *v2; // rdi
__int64 v3; // rax
int v4; // edx
int v5; // esi

LODWORD(v3) = strlen(a1);
v2 = (char *)(a1 + 2048);
LODWORD(v3) = v3 - 1;
if ( (int)v3 >= 0 )
{
v3 = (int)v3;
do
{
v4 = v3;
if ( a1[v3] == 47 )
goto LABEL_9;
}
while ( (int)--v3 >= 0 );
}
if ( *a1 == 47 )
{
v4 = 0;
LABEL_9:
v5 = v4 + 1;
return strcpy(v2, &a1[v5]);
}
v5 = 0;
return strcpy(v2, &a1[v5]);
}

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; // edx
_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; // edx
_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 *


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:
__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 *


decompiled_code:
int __fastcall run_fork_child(__int64 a1)
{
int result; // eax
int *v2; // rax
char *v3; // rax

limitres((_QWORD *)a1);
stdinout_redirect((char *)(a1 + 10272), (char *)(a1 + 14368));
chrootjail((char *)(a1 + 0x2000));
kill(*(_DWORD *)(a1 + 16476), 10);
change_uid();
result = execl((const char *)(a1 + 4096), (const char *)(a1 + 2048), 0LL);
if ( result == -1 )
{
puts("Can't execl.");
v2 = _errno_location();
v3 = strerror(*v2);
result = puts(v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
int result; // eax
int *v2; // rax
char *v3; // rax

func1((_QWORD *)a1);
func13((char *)(a1 + 10272), (char *)(a1 + 14368));
func5((char *)(a1 + 0x2000));
kill(*(_DWORD *)(a1 + 16476), 10);
func4();
result = execl((const char *)(a1 + 4096), (const char *)(a1 + 2048), 0LL);
if ( result == -1 )
{
puts("Can't execl.");
v2 = _errno_location();
v3 = strerror(*v2);
result = puts(v3);
}
return result;
}

original_code:
void run_fork_child(struct RunItem* ri)
{
 limitres(ri);
 stdinout_redirect(ri->bc_in, ri->tmp_out);
 chrootjail(ri->chroot_path);
 kill(ri->fpid, 10);
 change_uid();
 if (execl(ri->prog_jail_path, ri->prog_file, ((void *)0)) == -1)
 {
  printf("Can't execl.\n");
  printf("%s\n", strerror((*__errno_location ())));
 }
}

canonical_original_code:
void run_fork_child(struct RunItem *ri)
{
 limitres(ri);
 stdinout_redirect(ri->bc_in, ri->tmp_out);
 chrootjail(ri->chroot_path);
 kill(ri->fpid, 10);
 change_uid();
 if (execl(ri->prog_jail_path, ri->prog_file, ((void *)0)) == -1)
 {
  printf("Can't execl.\n");
  printf("%s\n", strerror((*__errno_location ())));
 }
}


run

decompiled_code:
__int64 __fastcall run(__int64 a1)
{
__int64 result; // rax
__pid_t v2; // eax

if ( (unsigned int)run_check(a1) )
return *(unsigned int *)(a1 + 16432);
if ( (unsigned int)run_before(a1) )
return *(unsigned int *)(a1 + 16432);
v2 = fork();
*(_DWORD *)(a1 + 16472) = v2;
if ( v2 == -1 )
{
*(_DWORD *)(a1 + 16432) = 8;
result = 8LL;
}
else
{
if ( !v2 )
{
run_fork_child(a1);
exit(0);
}
while ( !(unsigned int)run_father_while(a1) )
;
run_after(a1);
result = *(unsigned int *)(a1 + 16432);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 result; // rax
__pid_t v2; // eax

if ( (unsigned int)func0(a1) )
return *(unsigned int *)(a1 + 16432);
if ( (unsigned int)func7(a1) )
return *(unsigned int *)(a1 + 16432);
v2 = fork();
*(_DWORD *)(a1 + 16472) = v2;
if ( v2 == -1 )
{
*(_DWORD *)(a1 + 16432) = 8;
result = 8LL;
}
else
{
if ( !v2 )
{
func14(a1);
exit(0);
}
while ( !(unsigned int)func11(a1) )
;
func12(a1);
result = *(unsigned int *)(a1 + 16432);
}
return result;
}

original_code:
int run(struct RunItem *ri)
{
 pid_t cpid;
 if (run_check(ri))
 {
  return ri->result;
 }
 if (run_before(ri))
 {
  return ri->result;
 }
 ri->cpid = cpid = fork();
 if (cpid == -1)
 {
  ri->result = 8;
  return ri->result;
 }
 else if (cpid == 0)
 {
  run_fork_child(ri);
  exit(0);
 }
 else
 {
  while (1)
  {
   if (run_father_while(ri))
   {
    break;
   }
  }
  run_after(ri);
  return ri->result;
 }
}

canonical_original_code:
int run(struct RunItem *ri)
{
 int cpid;
 if (run_check(ri))
 {
  return ri->result;
 }
 if (run_before(ri))
 {
  return ri->result;
 }
 ri->cpid = cpid = fork();
 if (cpid == -1)
 {
  ri->result = 8;
  return ri->result;
 }
 else if (cpid == 0)
 {
  run_fork_child(ri);
  exit(0);
 }
 else
 {
  while (1)
  {
   if (run_father_while(ri))
   {
    break;
   }
  }
  run_after(ri);
  return ri->result;
 }
}

variable_types: cpid int


decompiled_code:
int __fastcall exe_priv(const char *a1)
{
return chmod(a1, 0x1FFu);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
return chmod(a1, 0x1FFu);
}

original_code:
int exe_priv(char* file)
{
 return chmod(file, 00777);
}

canonical_original_code:
int exe_priv(char *file)
{
 return chmod(file, 00777);
}

variable_types:
file
char *


delete

decompiled_code:
int __fastcall delete(const char *a1)
{
return unlink(a1);
}

canonical_decompiled_code:
int __fastcall func4(const char *a1)
{
return unlink(a1);
}

original_code:
int delete(char* path)
{
 return unlink(path);
}

canonical_original_code:
int delete(char *path)
{
 return unlink(path);
}


isfileok

decompiled_code:
_BOOL8 __fastcall isfileok(char *name)
{
int v1; // edx
_BOOL8 result; // rax

v1 = access(name, 0);
result = 0LL;
if ( !v1 )
result = access(name, 4) == 0;
return result;
}

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

v1 = access(name, 0);
result = 0LL;
if ( !v1 )
result = access(name, 4) == 0;
return result;
}

original_code:
int isfileok(char* path)
{
 if (access(path, 0) == 0 && access(path, 4) == 0)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}

canonical_original_code:
int isfileok(char *path)
{
 if (access(path, 0) == 0 && access(path, 4) == 0)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}


isdirok

decompiled_code:
_BOOL8 __fastcall isdirok(const char *a1)
{
int v1; // edx
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3);
result = 0LL;
if ( v1 != -1 && (v3.st_mode & 0xF000) == 0x4000 && (v3.st_mode & 0x1C0) != 0 )
result = (v3.st_mode & 0x2D) == 45;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(const char *a1)
{
int v1; // edx
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3);
result = 0LL;
if ( v1 != -1 && (v3.st_mode & 0xF000) == 0x4000 && (v3.st_mode & 0x1C0) != 0 )
result = (v3.st_mode & 0x2D) == 45;
return result;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


curtime

decompiled_code:
int __fastcall curtime(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

original_code:
void curtime(struct timeval* time)
{
 gettimeofday(time, ((void *)0));
}

canonical_original_code:
void curtime(struct timeval *time)
{
 gettimeofday(time, ((void *)0));
}


mydifftime

original_code:
unsigned long long mydifftime(struct timeval* begin, struct timeval* end)
{
 if (begin->tv_sec == 0 && begin->tv_usec == 0)
 {
  return 0;
 }
 else
 {
  long long diff = (end->tv_sec - begin->tv_sec) * 1000000
    + (end->tv_usec - begin->tv_usec);
  if (diff < 0)
  {
   return 0;
  }
  diff /= 1000;
  return diff;
 }
}

canonical_original_code:
unsigned long long mydifftime(struct timeval *begin, struct timeval *end)
{
 if (begin->tv_sec == 0 && begin->tv_usec == 0)
 {
  return 0;
 }
 else
 {
  long long diff = (end->tv_sec - begin->tv_sec) * 1000000
    + (end->tv_usec - begin->tv_usec);
  if (diff < 0)
  {
   return 0;
  }
  diff /= 1000;
  return diff;
 }
}

variable_types:
end
struct timeval *

variable_types:
diff
long long


max

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

result = a2;
if ( a1 >= a2 )
result = a1;
return result;
}

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

result = a2;
if ( a1 >= a2 )
result = a1;
return result;
}

original_code:
unsigned long long max(unsigned long a, unsigned long b)
{
 if (a >= b)
 {
  return a;
 }
 else
 {
  return b;
 }
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long


decompiled_code:
char *__fastcall print_bytes(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
char *v3; // r12

if ( a2 > 0 )
{
v2 = a1;
v3 = buf_0;
do
{
sprintf(v3, "%02X", *v2++);
v3 += 2;
}
while ( v2 != &a1[a2 - 1 + 1] );
}
buf_0[2 * a2] = 0;
return buf_0;
}

canonical_decompiled_code:
char *__fastcall func4(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
char *v3; // r12

if ( a2 > 0 )
{
v2 = a1;
v3 = buf_0;
do
{
sprintf(v3, "%02X", *v2++);
v3 += 2;
}
while ( v2 != &a1[a2 - 1 + 1] );
}
buf_0[2 * a2] = 0;
return buf_0;
}

original_code:
char* print_bytes(gconstpointer p,int size){
    static char buf[10000];
    int t=0;
    for(t=0;t<size;t++){
        sprintf(buf+t*2,"%02X",(*(const guchar*)(p+t)));
    }
    buf[size*2]=0;
    return buf;
}

canonical_original_code:
char *print_bytes(void *p, int size){
    static char buf[10000];
    int t = 0;
    for(t=0;t<size;t++){
        sprintf(buf+t*2,"%02X",(*(unsigned char *)(p+t)));
    }
    buf[size*2]=0;
    return buf;
}

variable_types:
p
void *

variable_types: size int

variable_types:
buf
char [10000]

variable_types: t int

return_type: char *


original_code:
TaskQueue *queue_init(TaskQueue *f,int size1,int size2,int size3){
    if(f==((void *)0)){
        f=((TaskQueue *) g_malloc_n ((1), sizeof (TaskQueue)));
    }
    f->size1=size1;
    f->size2=size2;
    f->size3=size3;
    f->size3_=1;
    f->interval=((Double *) g_malloc_n ((size3+1), sizeof (Double)));
    f->interval[0]=((double)1.79769313486231570814527423731704357e+308L);
    f->dataSize=((int *) g_malloc_n ((size3+1), sizeof (int)));
    f->data=((gpointer *) g_malloc_n ((size3+1), sizeof (gpointer)));
    f->data[0]=g_malloc(size1*(size2+1));
    f->dataSize[0]=0;
    return f;
}

canonical_original_code:
struct _TaskQueue *queue_init(struct _TaskQueue *f, int size1, int size2, int size3){
    if(f==((void *)0)){
        f=((struct _TaskQueue *) g_malloc_n ((1), sizeof (TaskQueue)));
    }
    f->size1=size1;
    f->size2=size2;
    f->size3=size3;
    f->size3_=1;
    f->interval=((double *) g_malloc_n ((size3+1), sizeof (Double)));
    f->interval[0]=((double)1.79769313486231570814527423731704357e+308L);
    f->dataSize=((int *) g_malloc_n ((size3+1), sizeof (int)));
    f->data=((void **) g_malloc_n ((size3+1), sizeof (gpointer)));
    f->data[0]=g_malloc(size1*(size2+1));
    f->dataSize[0]=0;
    return f;
}

variable_types:
f
struct _TaskQueue *

return_type: struct _TaskQueue { int size1; int size2; int size3; int size3_; double *interval; int *dataSize; void **data; } *


original_code:
gpointer queue_pull(TaskQueue *queue){
    do { if (queue->size3_>0) ; else g_assertion_message_expr (((gchar*) 0), "queue.c", 79, ((const char*) (__func__)), "queue->size3_>0"); } while (0);
    gpointer f=queue->data[0];
    *(Dollar*)(f+queue->dataSize[0]*queue->size1)=-1.;
    int t;
    queue->size3_--;
    for(t=0;t<queue->size3_;t++){
        queue->data[t]=queue->data[t+1];
        queue->dataSize[t]=queue->dataSize[t+1];
        queue->interval[t]=queue->interval[t+1];
    }
    if(queue->size3_==0){
        queue->data[0]=g_malloc(queue->size1*(queue->size2+1));
        queue->dataSize[0]=0;
        queue->size3_++;
    }
    return f;
}

canonical_original_code:
void *queue_pull(struct _TaskQueue *queue){
    do { if (queue->size3_>0) ; else g_assertion_message_expr (((char *) 0), "queue.c", 79, ((char *) (__func__)), "queue->size3_>0"); } while (0);
    void *f = queue->data[0];
    *(double *)(f+queue->dataSize[0]*queue->size1)=-1.;
    int t;
    queue->size3_--;
    for(t=0;t<queue->size3_;t++){
        queue->data[t]=queue->data[t+1];
        queue->dataSize[t]=queue->dataSize[t+1];
        queue->interval[t]=queue->interval[t+1];
    }
    if(queue->size3_==0){
        queue->data[0]=g_malloc(queue->size1*(queue->size2+1));
        queue->dataSize[0]=0;
        queue->size3_++;
    }
    return f;
}

variable_types: struct _TaskQueue { int size1; int size2; int size3; int size3_; double *interval; int *dataSize; void **data; } *

variable_types:
f
void *


quickselect

original_code:
Double quickselect(gpointer block,gpointer tmp,int size,gint32 b,gint32 c){
    gint32 r1,r2;
    Double key=((double)1.79769313486231570814527423731704357e+308L);
    while(c!=b&&c!=0){
        r1=g_random_int_range(0,b);
        memcpy(tmp,block+(r1*size),size);
        memcpy(block+(r1*size),block,size);
        r2=0;
        key=(*(Dollar*)(tmp));
        for(r1=1;r1<b;r1++){
            if((*(Dollar*)(block+r1*size))<key){
                memcpy(block+r2*size,block+r1*size,size);
                r2++;
                memcpy(block+r1*size,block+r2*size,size);
            }
        }
        memcpy(block+r2*size,tmp,size);
        if(r2<c){
            r2++;
            block+=r2*size;
            b-=r2;
            c-=r2;
        }else{
            b=r2;
        }
    }
    return key;
}

canonical_original_code:
double quickselect(void *block, void *tmp, int size, int b, int c){
    int r1; int r2;
    double key = ((double)1.79769313486231570814527423731704357e+308L);
    while(c!=b&&c!=0){
        r1=g_random_int_range(0,b);
        memcpy(tmp,block+(r1*size),size);
        memcpy(block+(r1*size),block,size);
        r2=0;
        key=(*(double *)(tmp));
        for(r1=1;r1<b;r1++){
            if((*(double *)(block+r1*size))<key){
                memcpy(block+r2*size,block+r1*size,size);
                r2++;
                memcpy(block+r1*size,block+r2*size,size);
            }
        }
        memcpy(block+r2*size,tmp,size);
        if(r2<c){
            r2++;
            block+=r2*size;
            b-=r2;
            c-=r2;
        }else{
            b=r2;
        }
    }
    return key;
}

variable_types:
block
void *

variable_types:
tmp
void *

variable_types: b int

variable_types: c int

variable_types: key double

return_type: double


original_code:
gchar queue_insert(TaskQueue *queue,gconstpointer element){
    Double key=*(Double*) element;
    int t=-1;
    int ret=0;
    while(queue->interval[++t]<key){}
    if(queue->dataSize[t]<queue->size2){
        void* tmp=malloc(queue->size1);
        memcpy(tmp,element,queue->size1);
        memcpy(queue->data[t]+(queue->dataSize[t])*queue->size1,tmp,queue->size1);
        memcpy(queue->data[t]+(queue->dataSize[t])*queue->size1,element,queue->size1);
        queue->dataSize[t]++;
        ret=0;
    }else{
        gpointer block=queue->data[t];
        memcpy(block+queue->size2*queue->size1,element,queue->size1);
        gpointer tmp=(gpointer)g_malloc(queue->size1);
        Double cutoff = quickselect(block,tmp,queue->size1,(gint32)queue->size2+1,(gint32)((queue->size2+1)/2));
        g_free(tmp);
        int t2;
        for(t2=queue->size3_;t2>t;t2--){
            queue->data[t2]=queue->data[t2-1];
            queue->dataSize[t2]=queue->dataSize[t2-1];
            queue->interval[t2]=queue->interval[t2-1];
        }
        queue->dataSize[t]=(queue->size2+1)/2;
        queue->size3_++;
        if(t!=queue->size3-1){
            int newSize=queue->size2/2+1;
            queue->data[t+1]=((void *)0);
            queue->data[t+1]=(gpointer)g_malloc(queue->size1*(queue->size2+1));
            queue->dataSize[t+1]=newSize;
            memcpy(queue->data[t+1],block+((queue->size2+1)/2)*queue->size1,newSize*queue->size1);
            queue->interval[t]=cutoff;
            if(queue->size3_>queue->size3){
                queue->size3_--;
                g_free(queue->data[queue->size3]);
                queue->interval[queue->size3-1]=((double)1.79769313486231570814527423731704357e+308L);
                ret=3;
            }else{
                ret=2;
            }
        }else{
            queue->size3_--;
            ret=1;
        }
    }
    return ret;
}

canonical_original_code:
char queue_insert(struct _TaskQueue *queue, void *element){
    double key = *(Double*) element;
    int t = -1;
    int ret = 0;
    while(queue->interval[++t]<key){}
    if(queue->dataSize[t]<queue->size2){
        void *tmp = malloc(queue->size1);
        memcpy(tmp,element,queue->size1);
        memcpy(queue->data[t]+(queue->dataSize[t])*queue->size1,tmp,queue->size1);
        memcpy(queue->data[t]+(queue->dataSize[t])*queue->size1,element,queue->size1);
        queue->dataSize[t]++;
        ret=0;
    }else{
        void *block = queue->data[t];
        memcpy(block+queue->size2*queue->size1,element,queue->size1);
        void *tmp = (gpointer)g_malloc(queue->size1);
        double cutoff = quickselect(block,tmp,queue->size1,(gint32)queue->size2+1,(gint32)((queue->size2+1)/2));
        g_free(tmp);
        int t2;
        for(t2=queue->size3_;t2>t;t2--){
            queue->data[t2]=queue->data[t2-1];
            queue->dataSize[t2]=queue->dataSize[t2-1];
            queue->interval[t2]=queue->interval[t2-1];
        }
        queue->dataSize[t]=(queue->size2+1)/2;
        queue->size3_++;
        if(t!=queue->size3-1){
            int newSize = queue->size2/2+1;
            queue->data[t+1]=((void *)0);
            queue->data[t+1]=(void *)g_malloc(queue->size1*(queue->size2+1));
            queue->dataSize[t+1]=newSize;
            memcpy(queue->data[t+1],block+((queue->size2+1)/2)*queue->size1,newSize*queue->size1);
            queue->interval[t]=cutoff;
            if(queue->size3_>queue->size3){
                queue->size3_--;
                g_free(queue->data[queue->size3]);
                queue->interval[queue->size3-1]=((double)1.79769313486231570814527423731704357e+308L);
                ret=3;
            }else{
                ret=2;
            }
        }else{
            queue->size3_--;
            ret=1;
        }
    }
    return ret;
}

variable_types:
element
void *

variable_types: ret int

variable_types: cutoff double

variable_types: newSize int

return_type: char

user_defined_types: struct _TaskQueue { int size1; int size2; int size3; int size3_; double *interval; int *dataSize; void **data; }


decompiled_code:
void __fastcall queue_free(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 3) > 0 )
{
v1 = 0LL;
do
g_free(*(_QWORD *)(*((_QWORD *)ptr + 4) + 8 * v1++));
while ( *((_DWORD *)ptr + 3) > (int)v1 );
}
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 3) > 0 )
{
v1 = 0LL;
do
g_free(*(_QWORD *)(*((_QWORD *)ptr + 4) + 8 * v1++));
while ( *((_DWORD *)ptr + 3) > (int)v1 );
}
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}

original_code:
void queue_free(TaskQueue *queue){
    int t;
    for(t=0;t<queue->size3_;t++){
        g_free(queue->data[t]);
    }
    free(queue->interval);
    free(queue->dataSize);
    free(queue->data);
    free(queue);
}

canonical_original_code:
void queue_free(struct _TaskQueue *queue){
    int t;
    for(t=0;t<queue->size3_;t++){
        g_free(queue->data[t]);
    }
    free(queue->interval);
    free(queue->dataSize);
    free(queue->data);
    free(queue);
}


original_code:
void queue_print(GLogLevelFlags flags, TaskQueue *queue){
    g_log(((gchar*) 0),flags,"--- queue ---");
    g_log(((gchar*) 0),flags,"%4d|%4d|%4d|%4d",queue->size1,queue->size2,queue->size3,queue->size3_);
    int t;
    for(t=0;t<queue->size3_;t++){
        Double a=queue->interval[t];
        int size=queue->dataSize[t];
        g_log(((gchar*) 0),flags,"block:%3d, size:%5d, interval: %5.3lf",t,size,a);
        int t2;
        for(t2=0;t2<size;t2++){
            g_log(((gchar*) 0),flags,"%10.3lf:%s",(*(Dollar*)(queue->data[t]+queue->size1*t2)),print_bytes(queue->data[t]+queue->size1*t2+sizeof(Dollar),queue->size1-sizeof(Dollar)));
        }
    }
    g_log(((gchar*) 0),flags,"--- end queue ---");
}

canonical_original_code:
void queue_print(enum GLogLevelFlags flags, struct _TaskQueue *queue){
    g_log(((char *) 0),flags,"--- queue ---");
    g_log(((char *) 0),flags,"%4d|%4d|%4d|%4d",queue->size1,queue->size2,queue->size3,queue->size3_);
    int t;
    for(t=0;t<queue->size3_;t++){
        double a = queue->interval[t];
        int size = queue->dataSize[t];
        g_log(((char *) 0),flags,"block:%3d, size:%5d, interval: %5.3lf",t,size,a);
        int t2;
        for(t2=0;t2<size;t2++){
            g_log(((char *) 0),flags,"%10.3lf:%s",(*(double *)(queue->data[t]+queue->size1*t2)),print_bytes(queue->data[t]+queue->size1*t2+sizeof(Dollar),queue->size1-sizeof(Dollar)));
        }
    }
    g_log(((char *) 0),flags,"--- end queue ---");
}

variable_types: enum GLogLevelFlags { G_LOG_FLAG_RECURSION=expr, G_LOG_FLAG_FATAL=expr, G_LOG_LEVEL_ERROR=expr, G_LOG_LEVEL_CRITICAL=expr, G_LOG_LEVEL_WARNING=expr, G_LOG_LEVEL_MESSAGE=expr, G_LOG_LEVEL_INFO=expr, G_LOG_LEVEL_DEBUG=expr, G_LOG_LEVEL_MASK=expr }

variable_types: a double


compareTypeCost

decompiled_code:
__int64 __fastcall compareTypeCost(const void *a1, const void *a2)
{
return (*((double *)a1 + 3) > *((double *)a2 + 3)) - (unsigned int)(*((double *)a2 + 3) > *((double *)a1 + 3));
}

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

original_code:
int compareTypeCost (const void *a, const void *b){
    const Double *da = &((const TypeB*) a)->cost;
    const Double *db = &((const TypeB*) b)->cost;
    return (*da > *db) - (*da < *db);
}

canonical_original_code:
int compareTypeCost(void *a, void *b){
    double *da = &((const TypeB*) a)->cost;
    double *db = &((const TypeB*) b)->cost;
    return (*da > *db) - (*da < *db);
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
da
double *

variable_types:
db
double *


setupTypes

original_code:
int setupTypes(TypeB* types,const char* buf){
    int t;
    for(t=0;t<198;t++){
        int i1,i2,i3;
        Double E,Fy,Density,Area,Moment,CostVol;
        char name[6];
        int n=sscanf(buf,"%d %d %d %5s %lf %lf %lf %lf %lf %lf\n",&i1,&i2,&i3,name,&E,&Fy,&Density,&Area,&Moment,&CostVol);
        while(*(buf++)!='\n'){}
        if(n!=10){
            return 1;
        }
        types[t].index=(Byte)(1*i1+99*i2+3*i3);
        strcpy(types[t].name,name);
        types[t].weight=1.25*Density*Area*9.8066/2000;
        types[t].AE=Area*E;
        types[t].cost=CostVol*Area*Density*2;
        types[t].tensionStrength=0.95*Fy*Area;
        types[t].inverseRadiusOfGyration=sqrt(Area/Moment);
        types[t].FyArea_d_CEMoment=Fy*Area/(9.8696044*E*Moment);
        types[t].FyArea=Fy*Area;
    }
    qsort(types,198,sizeof(TypeB),compareTypeCost);
    for(t=0;t<198;++t){
        types[t].index2=t;
    }
    return 0;
}

canonical_original_code:
int setupTypes(struct TypeB *types, char *buf){
    int t;
    for(t=0;t<198;t++){
        int i1; int i2; int i3;
        double E; double Fy; double Density; double Area; double Moment; double CostVol;
        char name[6];
        int n = sscanf(buf,"%d %d %d %5s %lf %lf %lf %lf %lf %lf\n",&i1,&i2,&i3,name,&E,&Fy,&Density,&Area,&Moment,&CostVol);
        while(*(buf++)!='\n'){}
        if(n!=10){
            return 1;
        }
        types[t].index=(Byte)(1*i1+99*i2+3*i3);
        strcpy(types[t].name,name);
        types[t].weight=1.25*Density*Area*9.8066/2000;
        types[t].AE=Area*E;
        types[t].cost=CostVol*Area*Density*2;
        types[t].tensionStrength=0.95*Fy*Area;
        types[t].inverseRadiusOfGyration=sqrt(Area/Moment);
        types[t].FyArea_d_CEMoment=Fy*Area/(9.8696044*E*Moment);
        types[t].FyArea=Fy*Area;
    }
    qsort(types,198,sizeof(TypeB),compareTypeCost);
    for(t=0;t<198;++t){
        types[t].index2=t;
    }
    return 0;
}

variable_types: struct TypeB { unsigned char index; unsigned char index2; char name[6]; double weight; double AE; double cost; double tensionStrength; double inverseRadiusOfGyration; double FyArea_d_CEMoment; double FyArea; } *

variable_types:
buf
char *

variable_types: t int

variable_types: E double

variable_types: Fy double

variable_types: Density double

variable_types: Area double

variable_types: Moment double

variable_types: CostVol double

variable_types:
name
char [6]

variable_types: n int


getCompressionStrength

decompiled_code:
double __fastcall getCompressionStrength(__int64 a1, double a2)
{
double v2; // xmm1_8
double result; // xmm0_8

v2 = a2 * a2 * *(double *)(a1 + 48);
if ( v2 <= 2.25 )
result = pow(0.66, v2) * 0.9 * *(double *)(a1 + 56);
else
result = 0.792 * *(double *)(a1 + 56) / v2;
return result;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1, double a2)
{
double v2; // xmm1_8
double result; // xmm0_8

v2 = a2 * a2 * *(double *)(a1 + 48);
if ( v2 <= 2.25 )
result = pow(0.66, v2) * 0.9 * *(double *)(a1 + 56);
else
result = 0.792 * *(double *)(a1 + 56) / v2;
return result;
}

original_code:
Double getCompressionStrength(const TypeB* type,Double length){
  Double lambda=length*length*type->FyArea_d_CEMoment;
  return lambda<=2.25?
           0.9*pow(0.66,lambda)*type->FyArea:
           0.792*type->FyArea/lambda;
}

canonical_original_code:
double getCompressionStrength(struct TypeB *type, double length){
  double lambda = length*length*type->FyArea_d_CEMoment;
  return lambda<=2.25?
           0.9*pow(0.66,lambda)*type->FyArea:
           0.792*type->FyArea/lambda;
}

variable_types: length double

variable_types: lambda double

user_defined_types: struct TypeB { unsigned char index; unsigned char index2; char name[6]; double weight; double AE; double cost; double tensionStrength; double inverseRadiusOfGyration; double FyArea_d_CEMoment; double FyArea; }


ifPassType

decompiled_code:
_BOOL8 __fastcall ifPassType(__int64 a1, double a2, double a3, double a4, double a5)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(double *)(a1 + 32) >= a3 )
{
result = 0LL;
if ( a5 > a4 * *(double *)(a1 + 40) )
result = getCompressionStrength(a1, a4) >= a2;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, double a2, double a3, double a4, double a5)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(double *)(a1 + 32) >= a3 )
{
result = 0LL;
if ( a5 > a4 * *(double *)(a1 + 40) )
result = func2(a1, a4) >= a2;
}
return result;
}

original_code:
Bool ifPassType(const TypeB* type,Double compression,Double tension,Double length,Double slenderness){
  return (tension <= type->tensionStrength)&&
         (slenderness>length*type->inverseRadiusOfGyration)&&
         (compression <= getCompressionStrength(type,length));
}

canonical_original_code:
int ifPassType(struct TypeB *type, double compression, double tension, double length, double slenderness){
  return (tension <= type->tensionStrength)&&
         (slenderness>length*type->inverseRadiusOfGyration)&&
         (compression <= getCompressionStrength(type,length));
}

variable_types: compression double

variable_types: tension double

variable_types: slenderness double


original_code:
char* type_print(const TypeB* type){
    static char buf[200];
    sprintf(buf,"type[%s|%0.4lfkN|%7.0lf_|$%4.2lf|%5.2lfkN|%3.3lf/m|%3.3lf_|%5.2lfkN]",
            type->name,
            type->weight,
            type->AE,
            type->cost,
            type->tensionStrength,
            type->inverseRadiusOfGyration,
            type->FyArea_d_CEMoment,
            type->FyArea);
    return buf;
}

canonical_original_code:
char *type_print(struct TypeB *type){
    static char buf[200];
    sprintf(buf,"type[%s|%0.4lfkN|%7.0lf_|$%4.2lf|%5.2lfkN|%3.3lf/m|%3.3lf_|%5.2lfkN]",
            type->name,
            type->weight,
            type->AE,
            type->cost,
            type->tensionStrength,
            type->inverseRadiusOfGyration,
            type->FyArea_d_CEMoment,
            type->FyArea);
    return buf;
}

variable_types:
buf
char [200]


readFile

decompiled_code:
__int64 __fastcall readFile(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // [rsp+8h] [rbp-28h] BYREF
__int64 v4; // [rsp+10h] [rbp-20h] BYREF
__int64 v5; // [rsp+18h] [rbp-18h] BYREF

v5 = 0LL;
v4 = 0LL;
g_file_get_contents(a1, &v4, &v3, &v5);
if ( v5 )
{
g_log(0LL, 8LL, "ERROR: %s\n", *(const char **)(v5 + 8));
g_error_free(v5);
result = 0LL;
}
else
{
if ( a2 )
endecrypt_rc4(v4, v3);
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // [rsp+8h] [rbp-28h] BYREF
__int64 v4; // [rsp+10h] [rbp-20h] BYREF
__int64 v5; // [rsp+18h] [rbp-18h] BYREF

v5 = 0LL;
v4 = 0LL;
g_file_get_contents(a1, &v4, &v3, &v5);
if ( v5 )
{
g_log(0LL, 8LL, "ERROR: %s\n", *(const char **)(v5 + 8));
g_error_free(v5);
result = 0LL;
}
else
{
if ( a2 )
endecrypt_rc4(v4, v3);
result = v4;
}
return result;
}

original_code:
guchar* readFile(const gchar* path,Bool encrypt){
    GError* error=((void *)0);
    guchar *buf=((void *)0);
    gsize size;
    g_file_get_contents(path,&buf,&size,&error);
    if (error) {
        g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "ERROR: %s\n",error->message);
        g_error_free(error);
        return 0;
    }
    if(encrypt){
        endecrypt_rc4(buf,(int)size);
    }
    return buf;
}

canonical_original_code:
unsigned char *readFile(char *path, int encrypt){
    struct _GError *error = ((void *)0);
    unsigned char *buf = ((void *)0);
    unsigned long size;
    g_file_get_contents(path,&buf,&size,&error);
    if (error) {
        g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "ERROR: %s\n",error->message);
        g_error_free(error);
        return 0;
    }
    if(encrypt){
        endecrypt_rc4(buf,(int)size);
    }
    return buf;
}

variable_types:
path
char *

variable_types: encrypt int

variable_types: struct _GError { unsigned int domain; int code; char *message; } *

variable_types:
buf
unsigned char *

variable_types:
size
unsigned long

return_type: unsigned char *


writeFile

decompiled_code:
__int64 __fastcall writeFile(__int64 a1, const char *a2, int a3)
{
size_t v4; // rax
size_t v5; // r12
char *v6; // rbx

v4 = strlen(a2);
v5 = v4;
if ( a3 )
{
v6 = strndup(a2, v4);
endecrypt_rc4(v6, (int)v5);
g_file_set_contents(a1, v6, v5, 0LL);
free(v6);
}
else
{
g_file_set_contents(a1, a2, v4, 0LL);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, int a3)
{
size_t v4; // rax
size_t v5; // r12
char *v6; // rbx

v4 = strlen(a2);
v5 = v4;
if ( a3 )
{
v6 = strndup(a2, v4);
endecrypt_rc4(v6, (int)v5);
g_file_set_contents(a1, v6, v5, 0LL);
free(v6);
}
else
{
g_file_set_contents(a1, a2, v4, 0LL);
}
return 0LL;
}

original_code:
int writeFile(const gchar* path, const guchar* buf,Bool encrypt){
    gsize size=strlen(buf);
    GError *error=((void *)0);
    if(encrypt){
        buf=strndup(buf,size);
        endecrypt_rc4(buf,(int)size);
        g_file_set_contents(path,buf,size,error);
        free(buf);
    }else{
        g_file_set_contents(path,buf,size,error);
    }
    if(error!=((void *)0)){
        g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "ERROR: %s\n",error->message);
        g_error_free(error);
        return 2;
    }
    return 0;
}

canonical_original_code:
int writeFile(char *path, unsigned char *buf, int encrypt){
    unsigned long size = strlen(buf);
    struct _GError *error = ((void *)0);
    if(encrypt){
        buf=strndup(buf,size);
        endecrypt_rc4(buf,(int)size);
        g_file_set_contents(path,buf,size,error);
        free(buf);
    }else{
        g_file_set_contents(path,buf,size,error);
    }
    if(error!=((void *)0)){
        g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "ERROR: %s\n",error->message);
        g_error_free(error);
        return 2;
    }
    return 0;
}

user_defined_types: struct _GError { unsigned int domain; int code; char *message; }


findIndex

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

result = 0LL;
while ( *a1 != a2 )
{
result = (unsigned int)(result + 1);
a1 += 64;
if ( (_DWORD)result == 198 )
return 0xFFFFFFFFLL;
}
return result;
}

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

result = 0LL;
while ( *a1 != a2 )
{
result = (unsigned int)(result + 1);
a1 += 64;
if ( (_DWORD)result == 198 )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int findIndex(const TypeB *types,int index){
    int t;
    for(t=0;t<198;t++){
        if(types[t].index==index){
            return t;
        }
    }
    return -1;
}

canonical_original_code:
int findIndex(struct TypeB *types, int index){
    int t;
    for(t=0;t<198;t++){
        if(types[t].index==index){
            return t;
        }
    }
    return -1;
}

variable_types: struct TypeB { unsigned char index; unsigned char index2; char name[6]; double weight; double AE; double cost; double tensionStrength; double inverseRadiusOfGyration; double FyArea_d_CEMoment; double FyArea; } *

variable_types: index int

variable_types: t int


rebaseBridge

original_code:
const BridgeInfo* rebaseBridge(const BridgeInfo* bridgeInfo,gpointer thc_ph){
    BridgeInfo* f=g_memdup(bridgeInfo,sizeof(BridgeInfo));
    f->buf=strdup(f->buf);
    gchar *buf2=f->buf+19 +f->fixedJointSize*6;
    PositionHintB *position=(PositionHintB*)(thc_ph+(sizeof(Dollar)+8*sizeof(Byte)+(f->memberSize)));
    int t1;
    for(t1=f->fixedJointSize;t1<f->totalJointSize;++t1){
        int t2=t1-f->fixedJointSize;
        f->positionHint.xy[t1*2 ]+=((((position->joints[t2]>>4)&15)^8)-8);
        f->positionHint.xy[t1*2+1]+=((((position->joints[t2] )&15)^8)-8);
        sprintf(buf2,"%3d%3d",f->positionHint.xy[t1*2 ],f->positionHint.xy[t1*2+1]);
        buf2+=6;
    }
    memcpy(&f->typeHint,thc_ph,(sizeof(Dollar)+8*sizeof(Byte)+(f->memberSize)));
    char end=*(buf2+8*f->memberSize);
    for(t1=0;t1<f->memberSize;t1++){
        int i=f->types[f->typeHint.bundle[f->typeHint.member[t1]]].index;
        int i1,i2,i3;
        i1=(i)%3;i2=(i)/99;i3=((i)/3)%33;
        sprintf(buf2,"%2d%2d%1d%1d%2d",f->memberLinks[t1].j1+1,f->memberLinks[t1].j2+1,i1,i2,i3);
        buf2+=8;
    }
    *buf2=end;
    return f;
}

canonical_original_code:
struct _BridgeInfo *rebaseBridge(struct _BridgeInfo *bridgeInfo, void *thc_ph){
    struct _BridgeInfo *f = g_memdup(bridgeInfo,sizeof(BridgeInfo));
    f->buf=strdup(f->buf);
    char *buf2 = f->buf+19 +f->fixedJointSize*6;
    struct PositionHintB *position = (PositionHintB*)(thc_ph+(sizeof(Dollar)+8*sizeof(Byte)+(f->memberSize)));
    int t1;
    for(t1=f->fixedJointSize;t1<f->totalJointSize;++t1){
        int t2 = t1-f->fixedJointSize;
        f->positionHint.xy[t1*2 ]+=((((position->joints[t2]>>4)&15)^8)-8);
        f->positionHint.xy[t1*2+1]+=((((position->joints[t2] )&15)^8)-8);
        sprintf(buf2,"%3d%3d",f->positionHint.xy[t1*2 ],f->positionHint.xy[t1*2+1]);
        buf2+=6;
    }
    memcpy(&f->typeHint,thc_ph,(sizeof(double)+8*sizeof(Byte)+(f->memberSize)));
    char end = *(buf2+8*f->memberSize);
    for(t1=0;t1<f->memberSize;t1++){
        int i = f->types[f->typeHint.bundle[f->typeHint.member[t1]]].index;
        int i1; int i2; int i3;
        i1=(i)%3;i2=(i)/99;i3=((i)/3)%33;
        sprintf(buf2,"%2d%2d%1d%1d%2d",f->memberLinks[t1].j1+1,f->memberLinks[t1].j2+1,i1,i2,i3);
        buf2+=8;
    }
    *buf2=end;
    return f;
}

variable_types:
bridgeInfo
struct _BridgeInfo *

variable_types: struct _BridgeInfo { char *buf; int fixedJointSize; int deckSize; double deckWeight; double backWeight; double frontWeight; double slenderness; int fixedIndex[20]; int typeSize; struct TypeB { unsigned char index; unsigned char index2; char name[6]; double weight; double AE; double cost; double tensionStrength; double inverseRadiusOfGyration; double FyArea_d_CEMoment; double FyArea; } types[198]; double bundleCost; int totalJointSize; int memberSize; struct MemberLink { int j1; } memberLinks[120]; double baseCost; struct PositionHint { int xy[-1]; } positionHint; struct TypeHintCostB { double cost; unsigned char bundle[8]; unsigned char member[120]; } typeHint; } *

variable_types: struct PositionHintB { unsigned char joints[30]; } *

variable_types: end char

variable_types: i int

user_defined_types: struct _BridgeInfo { char *buf; int fixedJointSize; int deckSize; double deckWeight; double backWeight; double frontWeight; double slenderness; int fixedIndex[20]; int typeSize; struct TypeB types[198]; double bundleCost; int totalJointSize; int memberSize; struct MemberLink memberLinks[120]; double baseCost; struct PositionHint positionHint; struct TypeHintCostB typeHint; }


saveBridge

decompiled_code:
__int64 __fastcall saveBridge(__int64 a1, const char **a2)
{
return writeFile(a1, *a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char **a2)
{
return func1(a1, *a2, 1);
}

original_code:
void saveBridge(const char* path,const BridgeInfo *bridgeInfo){
    writeFile(path,bridgeInfo->buf,(!(0)));
}

canonical_original_code:
void saveBridge(char *path, struct _BridgeInfo *bridgeInfo){
    writeFile(path,bridgeInfo->buf,(!(0)));
}

user_defined_types: struct TypeHintCostB { double cost; unsigned char bundle[8]; unsigned char member[120]; }


decompiled_code:
void *__fastcall log_get_flag(int a1)
{
__int64 i; // rax
char v2; // dl

for ( i = 0LL; i != 8; ++i )
{
v2 = 32;
if ( _bittest(&a1, i) )
v2 = cbuf_1[i];
byte_141[i] = v2;
}
return &buf_0;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
__int64 i; // rax
char v2; // dl

for ( i = 0LL; i != 8; ++i )
{
v2 = 32;
if ( _bittest(&a1, i) )
v2 = cbuf_1[i];
byte_141[i] = v2;
}
return &buf_0;
}

original_code:
const gchar* log_get_flag(GLogLevelFlags flag){
    static gchar buf[]="[RFECWMID]";
    static const gchar cbuf[]={'R','F','E','C','W','M','I','D'};
    int t=0;
    for(t=0;t<8;t++){
        buf[t+1]=(flag&(1<<t))==0?' ':cbuf[t];
    }
    return buf;
}

canonical_original_code:
char *log_get_flag(enum GLogLevelFlags flag){
    static char buf[] = "[RFECWMID]";
    static char cbuf[] = {'R','F','E','C','W','M','I','D'};
    int t = 0;
    for(t=0;t<8;t++){
        buf[t+1]=(flag&(1<<t))==0?' ':cbuf[t];
    }
    return buf;
}

variable_types: enum GLogLevelFlags { G_LOG_FLAG_RECURSION=expr, G_LOG_FLAG_FATAL=expr, G_LOG_LEVEL_ERROR=expr, G_LOG_LEVEL_CRITICAL=expr, G_LOG_LEVEL_WARNING=expr, G_LOG_LEVEL_MESSAGE=expr, G_LOG_LEVEL_INFO=expr, G_LOG_LEVEL_DEBUG=expr, G_LOG_LEVEL_MASK=expr }

variable_types:
buf
char []

variable_types:
cbuf
char []


decompiled_code:
int __fastcall log_func_FILE(__int64 a1, int a2, const char *a3, FILE *a4)
{
const char *v6; // rax

v6 = (const char *)log_get_flag(a2);
fputs(v6, a4);
fputs(a3, a4);
return fputc(10, a4);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2, const char *a3, FILE *a4)
{
const char *v6; // rax

v6 = (const char *)func0(a2);
fputs(v6, a4);
fputs(a3, a4);
return fputc(10, a4);
}

original_code:
void log_func_FILE(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data){
    fputs(log_get_flag(log_level),user_data);
    fputs(message,user_data);
    fputs("\n",user_data);
}

canonical_original_code:
void log_func_FILE(char *log_domain, enum GLogLevelFlags log_level, char *message, void *user_data){
    fputs(log_get_flag(log_level),user_data);
    fputs(message,user_data);
    fputs("\n",user_data);
}

variable_types:
message
char *

user_defined_types: enum GLogLevelFlags { G_LOG_FLAG_RECURSION=expr, G_LOG_FLAG_FATAL=expr, G_LOG_LEVEL_ERROR=expr, G_LOG_LEVEL_CRITICAL=expr, G_LOG_LEVEL_WARNING=expr, G_LOG_LEVEL_MESSAGE=expr, G_LOG_LEVEL_INFO=expr, G_LOG_LEVEL_DEBUG=expr, G_LOG_LEVEL_MASK=expr }


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

v6 = log_get_flag(a2);
g_io_channel_write_chars(a4, v6, -1LL, 0LL, 0LL);
g_io_channel_write_chars(a4, a3, -1LL, 0LL, 0LL);
return g_io_channel_write_chars(a4, &unk_14C, -1LL, 0LL, 0LL);
}

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

v6 = func0(a2);
g_io_channel_write_chars(a4, v6, -1LL, 0LL, 0LL);
g_io_channel_write_chars(a4, a3, -1LL, 0LL, 0LL);
return g_io_channel_write_chars(a4, &unk_14C, -1LL, 0LL, 0LL);
}

original_code:
void log_func_iochannel(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data){
    g_io_channel_write_chars(user_data,log_get_flag(log_level),-1,((void *)0),((void *)0));
    g_io_channel_write_chars(user_data,message,-1,((void *)0),((void *)0));
    g_io_channel_write_chars(user_data,"\n",-1,((void *)0),((void *)0));
}

canonical_original_code:
void log_func_iochannel(char *log_domain, enum GLogLevelFlags log_level, char *message, void *user_data){
    g_io_channel_write_chars(user_data,log_get_flag(log_level),-1,((void *)0),((void *)0));
    g_io_channel_write_chars(user_data,message,-1,((void *)0),((void *)0));
    g_io_channel_write_chars(user_data,"\n",-1,((void *)0),((void *)0));
}


original_code:
void result_print(GLogLevelFlags flags,const Result* result, const BridgeInfo *bridgeInfo,TypeHintCostB *thc){
    g_log(((gchar*) 0),flags,"--- result ---");
    int jointSize=bridgeInfo->totalJointSize;
    int t1,t2;
    g_log(((gchar*) 0),flags,"cost: %lf",(*(Dollar*)(thc)));
    g_log(((gchar*) 0),flags,"joints:%d , %d",jointSize,bridgeInfo->fixedJointSize);
    g_log(((gchar*) 0),flags,"i :  x  |  y  ");
    for(t1=0;t1<jointSize;t1++){
        g_log(((gchar*) 0),flags,"%2d:%5.2lf|%5.2lf",t1,result->XY[t1*2],result->XY[t1*2+1]);
    }
    int memberSize=bridgeInfo->memberSize;
    g_log(((gchar*) 0),flags,"members:%d",memberSize);
    g_log(((gchar*) 0),flags," i :j1|j2|    T     |    C     |   Tmax   |   Cmax   | T  | C  |length|name");
    for(t1=0;t1<memberSize;t1++){
        const TypeB* type=&bridgeInfo->types[thc->bundle[thc->member[t1]]];
        Double max=result->maxForce[t1];
        Double min=-result->minForce[t1];
        Double max2=type->tensionStrength;
        Double min2=getCompressionStrength(type,result->memberLength[t1]);
        g_log(((gchar*) 0),flags,"%3d:%2d|%2d|%10.2lf|%10.2lf|%10.2lf|%10.2lf|%1.2lf|%1.2lf|%2.3lf|%s",t1,bridgeInfo->memberLinks[t1].j1,bridgeInfo->memberLinks[t1].j2,max,min,max2,min2,max/max2,min/min2,result->memberLength[t1],type->name);
    }
    return 0;
}

canonical_original_code:
void result_print(enum GLogLevelFlags flags, struct _Result *result, struct _BridgeInfo *bridgeInfo, struct TypeHintCostB *thc){
    g_log(((char *) 0),flags,"--- result ---");
    int jointSize = bridgeInfo->totalJointSize;
    int t1; int t2;
    g_log(((char *) 0),flags,"cost: %lf",(*(double *)(thc)));
    g_log(((char *) 0),flags,"joints:%d , %d",jointSize,bridgeInfo->fixedJointSize);
    g_log(((char *) 0),flags,"i :  x  |  y  ");
    for(t1=0;t1<jointSize;t1++){
        g_log(((char *) 0),flags,"%2d:%5.2lf|%5.2lf",t1,result->XY[t1*2],result->XY[t1*2+1]);
    }
    int memberSize = bridgeInfo->memberSize;
    g_log(((char *) 0),flags,"members:%d",memberSize);
    g_log(((char *) 0),flags," i :j1|j2|    T     |    C     |   Tmax   |   Cmax   | T  | C  |length|name");
    for(t1=0;t1<memberSize;t1++){
        struct TypeB *type = &bridgeInfo->types[thc->bundle[thc->member[t1]]];
        double max = result->maxForce[t1];
        double min = -result->minForce[t1];
        double max2 = type->tensionStrength;
        double min2 = getCompressionStrength(type,result->memberLength[t1]);
        g_log(((char *) 0),flags,"%3d:%2d|%2d|%10.2lf|%10.2lf|%10.2lf|%10.2lf|%1.2lf|%1.2lf|%2.3lf|%s",t1,bridgeInfo->memberLinks[t1].j1,bridgeInfo->memberLinks[t1].j2,max,min,max2,min2,max/max2,min/min2,result->memberLength[t1],type->name);
    }
    return 0;
}

variable_types: struct _Result { double XY[-1]; double matrix[-1]; double memberLength[120]; double loads[50]; double jdisplacement[-1]; double memberForce[-1]; double maxForce[120]; double minForce[120]; double totalCost; enum Status { LOADED=0, SOLVED_GOOD=1, SOLVED_UNSTABLE=2, OPTIMIZED_BETTER=3, OPTIMIZED_UNCHANGED=4, OPTIMIZED_WORSE=5, OPTIMIZED_MAX_BUNDLE=6, OPTIMIZED_MAX_COST=7 } status; } *

variable_types:
thc
struct TypeHintCostB *

variable_types: jointSize int

variable_types: memberSize int

variable_types: max double

variable_types: min double

user_defined_types: struct _Result { double XY[-1]; double matrix[-1]; double memberLength[120]; double loads[50]; double jdisplacement[-1]; double memberForce[-1]; double maxForce[120]; double minForce[120]; double totalCost; enum Status status; }


original_code:
void setup_rc4(TRC4State *state, const char *key, int keylen)
{
    unsigned int tmp,x,y;
    if (keylen > 256)
 keylen = 256;
    for (x = 0; x < 256; x++)
        state->buf[x] = x;
    state->x=state->y=0;
    for (x = y = 0; x < 256; x++) {
        y = (y + state->buf[x] + key[x % keylen]) & 255;
        tmp = state->buf[x];
 state->buf[x] = state->buf[y];
 state->buf[y] = tmp;
    }
    state->x = x;
    state->y = y;
}

canonical_original_code:
void setup_rc4(struct TRC4State_t *state, char *key, int keylen)
{
    unsigned int tmp; unsigned int x; unsigned int y;
    if (keylen > 256)
 keylen = 256;
    for (x = 0; x < 256; x++)
        state->buf[x] = x;
    state->x=state->y=0;
    for (x = y = 0; x < 256; x++) {
        y = (y + state->buf[x] + key[x % keylen]) & 255;
        tmp = state->buf[x];
 state->buf[x] = state->buf[y];
 state->buf[y] = tmp;
    }
    state->x = x;
    state->y = y;
}

variable_types: struct TRC4State_t { unsigned char buf[256]; int x; } *

variable_types:
key
char *

variable_types: keylen int

variable_types:
tmp
unsigned int

variable_types:
x
unsigned int

variable_types:
y
unsigned int


original_code:
unsigned long endecrypt_rc4_state(unsigned char *buf, unsigned long len, TRC4State *state)
{
    int x=state->x;
    int y=state->y;
    int i;
    unsigned char *s=(unsigned char*)state;
    unsigned char tmp;
    for(i=0;i<len;i++){
        x=(x+1)&255;
        y=(y+s[x])&255;
        tmp=s[x];
        s[x]=s[y];
        s[y]=tmp;
        buf[i]^=s[(s[x]+s[y])&255];
    }
    state->x=x;
    state->y=y;
    return 0;
}

canonical_original_code:
unsigned long endecrypt_rc4_state(unsigned char *buf, unsigned long len, struct TRC4State_t *state)
{
    int x = state->x;
    int y = state->y;
    int i;
    unsigned char *s = (unsigned char*)state;
    unsigned char tmp;
    for(i=0;i<len;i++){
        x=(x+1)&255;
        y=(y+s[x])&255;
        tmp=s[x];
        s[x]=s[y];
        s[y]=tmp;
        buf[i]^=s[(s[x]+s[y])&255];
    }
    state->x=x;
    state->y=y;
    return 0;
}

variable_types:
buf
unsigned char *

variable_types:
len
unsigned long

variable_types: x int

variable_types: y int

variable_types: i int

variable_types:
s
unsigned char *

variable_types:
tmp
unsigned char

user_defined_types: struct TRC4State_t { unsigned char buf[256]; int x; }


decompiled_code:
__int64 __fastcall endecrypt_rc4(_BYTE *a1, __int64 a2)
{
char v3[288]; // [rsp+0h] [rbp-120h] BYREF

setup_rc4((__int64)v3, (__int64)"QuenchHollow", 12);
return endecrypt_rc4_state(a1, a2, (__int64)v3);
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, __int64 a2)
{
char v3[288]; // [rsp+0h] [rbp-120h] BYREF

func0((__int64)v3, (__int64)"QuenchHollow", 12);
return func1(a1, a2, (__int64)v3);
}

original_code:
unsigned long endecrypt_rc4(unsigned char *buf, unsigned long len){
  TRC4State state;
  setup_rc4(&state, "QuenchHollow", 12);
  return endecrypt_rc4_state(buf, len, &state);
}

canonical_original_code:
unsigned long endecrypt_rc4(unsigned char *buf, unsigned long len){
  struct TRC4State_t state;
  setup_rc4(&state, "QuenchHollow", 12);
  return endecrypt_rc4_state(buf, len, &state);
}

variable_types: struct TRC4State_t { unsigned char buf[256]; int x; }


original_code:
int test3(){
    TaskQueue *queue=queue_init(((void *)0),sizeof(Double),20,10);
    int t;
    Double tmp;
    for(t=0;t<1000;t++){
        tmp=g_random_double();
        queue_insert(queue,&tmp);
    }
    for(t=0;t<queue->size3_;t++){
        Double a=queue->interval[t];
        int size=queue->dataSize[t];
        int t2;
        printf("block %3d, size: %d, interval: %lf\n",t,size,a);
        for(t2=0;t2<size;t2++){
            printf("%lf ",(*(Double*)(queue->data[t]+queue->size1*t2)));
        }
        printf("\n");
    }
    return 0;
}

canonical_original_code:
int test3(){
    struct _TaskQueue *queue = queue_init(((void *)0),sizeof(Double),20,10);
    int t;
    double tmp;
    for(t=0;t<1000;t++){
        tmp=g_random_double();
        queue_insert(queue,&tmp);
    }
    for(t=0;t<queue->size3_;t++){
        double a = queue->interval[t];
        int size = queue->dataSize[t];
        int t2;
        printf("block %3d, size: %d, interval: %lf\n",t,size,a);
        for(t2=0;t2<size;t2++){
            printf("%lf ",(*(double *)(queue->data[t]+queue->size1*t2)));
        }
        printf("\n");
    }
    return 0;
}

variable_types: struct _TaskQueue { int size1; int size2; int size3; int size3_; double *interval; int *dataSize; void **data; } *

variable_types: t int

variable_types: tmp double

variable_types: a double

variable_types: size int


decompiled_code:
__int64 test4()
{
__int64 v0; // r13
double *v1; // r14
double *v2; // r12
double *v3; // r14
double v4; // rbx
unsigned int v5; // eax
__int64 v7[5]; // [rsp+8h] [rbp-28h] BYREF

v0 = table_init(0LL, 8LL, 16LL, 0.5);
v1 = (double *)malloc(0x640uLL);
printf("size: %d,%d\n", 8LL, 8LL);
v2 = v1;
v3 = v1 + 200;
do
{
v7[0] = g_random_double();
v4 = g_random_double();
table_insert(v0, v7);
*v2 = *(double *)v7;
v2[1] = v4;
v5 = table_hash(v7, 8LL, *(unsigned int *)(v0 + 4));
printf(
"%1.5f,%1.5f,%1.5f,%1.5f,%d\n",
*(double *)v7,
v4,
*(double *)(*(_QWORD *)(v0 + 16) + (int)(16 * v5)),
*(double *)(*(_QWORD *)(v0 + 16) + (int)(16 * v5) + 8LL),
v5);
v2 += 2;
}
while ( v2 != v3 );
table_print(32LL, v0);
table_free(v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // r13
double *v1; // r14
double *v2; // r12
double *v3; // r14
double v4; // rbx
unsigned int v5; // eax
__int64 v7[5]; // [rsp+8h] [rbp-28h] BYREF

v0 = table_init(0LL, 8LL, 16LL, 0.5);
v1 = (double *)malloc(0x640uLL);
printf("size: %d,%d\n", 8LL, 8LL);
v2 = v1;
v3 = v1 + 200;
do
{
v7[0] = g_random_double();
v4 = g_random_double();
table_insert(v0, v7);
*v2 = *(double *)v7;
v2[1] = v4;
v5 = table_hash(v7, 8LL, *(unsigned int *)(v0 + 4));
printf(
"%1.5f,%1.5f,%1.5f,%1.5f,%d\n",
*(double *)v7,
v4,
*(double *)(*(_QWORD *)(v0 + 16) + (int)(16 * v5)),
*(double *)(*(_QWORD *)(v0 + 16) + (int)(16 * v5) + 8LL),
v5);
v2 += 2;
}
while ( v2 != v3 );
table_print(32LL, v0);
table_free(v0);
return 0LL;
}

original_code:
int test4(){
    CostTable *table=table_init(((void *)0),sizeof(Double),16,0.5);
    int size=100;
    int t;
    Double *table2=(Double*)malloc(size*2*sizeof(Double));
    Double tmp1;
    Double tmp2;
    printf("size: %d,%d\n",(int)sizeof(Double),(int)sizeof(Dollar));
    for(t=0;t<size;t++){
        tmp1=g_random_double();
        tmp2=g_random_double();
        table_insert(table,&tmp1,tmp2);
        table2[2*t]=tmp1;
        table2[2*t+1]=tmp2;
        int i=table_hash(&tmp1,8,table->size2);
        printf("%1.5f,%1.5f,%1.5f,%1.5f,%d\n",tmp1,tmp2,*(Double*)(table->data+16*i),*(Double*)(table->data+16*i+8),i);
    }
    table_print(G_LOG_LEVEL_MESSAGE,table);
    table_free(table);
    return 0;
}

canonical_original_code:
int test4(){
    struct _CostTable *table = table_init(((void *)0),sizeof(Double),16,0.5);
    int size = 100;
    int t;
    double *table2 = (Double*)malloc(size*2*sizeof(Double));
    double tmp1;
    double tmp2;
    printf("size: %d,%d\n",(int)sizeof(Double),(int)sizeof(Dollar));
    for(t=0;t<size;t++){
        tmp1=g_random_double();
        tmp2=g_random_double();
        table_insert(table,&tmp1,tmp2);
        table2[2*t]=tmp1;
        table2[2*t+1]=tmp2;
        int i = table_hash(&tmp1,8,table->size2);
        printf("%1.5f,%1.5f,%1.5f,%1.5f,%d\n",tmp1,tmp2,*(double *)(table->data+16*i),*(double *)(table->data+16*i+8),i);
    }
    table_print(G_LOG_LEVEL_MESSAGE,table);
    table_free(table);
    return 0;
}

variable_types: struct _CostTable { int size1; int size2; int size2_; float limit; void *data; } *


writeNum

repo: lijnk/vmtrans

decompiled_code:
void __fastcall writeNum(int a1)
{
int v1; // ebx
_BYTE *v2; // rbp
int v3; // er13
int v4; // er12
__int64 v5; // rdx

v1 = a1;
if ( a1 )
{
v3 = (int)log10((double)a1);
v4 = v3 + 1;
v2 = calloc(v3 + 2, 1uLL);
if ( v3 < 0 )
goto LABEL_5;
}
else
{
v2 = calloc(2uLL, 1uLL);
v3 = 0;
v4 = 1;
}
v5 = v3;
do
{
v2[v5] = v1 % 10 + 48;
v1 /= 10;
--v5;
}
while ( (int)v5 >= 0 );
LABEL_5:
fwrite(v2, 1uLL, v4, vm_ofp);
free(v2);
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
int v1; // ebx
_BYTE *v2; // rbp
int v3; // er13
int v4; // er12
__int64 v5; // rdx

v1 = a1;
if ( a1 )
{
v3 = (int)log10((double)a1);
v4 = v3 + 1;
v2 = calloc(v3 + 2, 1uLL);
if ( v3 < 0 )
goto LABEL_5;
}
else
{
v2 = calloc(2uLL, 1uLL);
v3 = 0;
v4 = 1;
}
v5 = v3;
do
{
v2[v5] = v1 % 10 + 48;
v1 /= 10;
--v5;
}
while ( (int)v5 >= 0 );
LABEL_5:
fwrite(v2, 1uLL, v4, vm_ofp);
free(v2);
}

original_code:
void writeNum(int n)
{
 int len = n==0?1:(int)log10((double)n) + 1;
 int temp = n;
 char* str = (char*) calloc(len+1, sizeof(char));
 for(int i = len-1; i>=0; i--)
 {
  str[i] = (temp % 10) + '0';
  temp /= 10;
 }
 fwrite(str, 1, len, _vm_ofp);
 free(str);
}

canonical_original_code:
void writeNum(int n)
{
 int len = n==0?1:(int)log10((double)n) + 1;
 int temp = n;
 char *str = (char*) calloc(len+1, sizeof(char));
 for(int i = len-1; i>=0; i--)
 {
  str[i] = (temp % 10) + '0';
  temp /= 10;
 }
 fwrite(str, 1, len, _vm_ofp);
 free(str);
}

variable_types: n int

variable_types: len int

variable_types: temp int

variable_types:
str
char *