decompiled_code:
__int64 test_bloom_filter()
{
const char *v0; // rbp
const char **v1; // rbx
size_t i; // rdx
__int64 v3; // rbx
size_t v4; // rdx
const char *v5; // rbp
unsigned int v6; // eax
size_t v7; // rdx
const char *v8; // rbp
unsigned int v9; // eax
_BYTE v11[136]; // [rsp+0h] [rbp-88h] BYREF

v0 = "this is test";
v1 = (const char **)inarray_1;
tcase_fn_start("test_bloom_filter", "test_bloomfilter.c", 23LL);
dbloom_filter_init(v11, 10000LL, 40LL);
for ( i = 12LL; ; i = strlen(*v1) )
{
++v1;
dbloom_filter_add(v11, v0, i);
v0 = *v1;
if ( !*v1 )
break;
}
v3 = 0LL;
v4 = 11LL;
v5 = "not in here";
while ( 1 )
{
v6 = dbloom_filter_find(v11, v5, v4);
if ( v6 )
{
v9 = ck_assert_failed(
"test_bloomfilter.c",
43LL,
"Assertion 'ret == 0' failed",
"find failed, index:%d, ret: %d!",
(unsigned int)v3,
v6);
goto LABEL_14;
}
++v3;
mark_point("test_bloomfilter.c", 43LL);
v5 = notinarray_0[v3];
if ( !v5 )
break;
v4 = strlen(notinarray_0[v3]);
}
v3 = 0LL;
v7 = 12LL;
v8 = "this is test";
while ( 1 )
{
v9 = dbloom_filter_find(v11, v8, v7);
if ( v9 != 1 )
break;
++v3;
mark_point("test_bloomfilter.c", 48LL);
v8 = inarray_1[v3];
if ( !v8 )
return dbloom_filter_fini(v11);
v7 = strlen(inarray_1[v3]);
}
LABEL_14:
ck_assert_failed(
"test_bloomfilter.c",
48LL,
"Assertion 'ret == 1' failed",
"find failed, index:%d, ret:%d!",
(unsigned int)v3,
v9);
return test_bloom_init();
}

canonical_decompiled_code:
__int64 func2()
{
const char *v0; // rbp
const char **v1; // rbx
size_t i; // rdx
__int64 v3; // rbx
size_t v4; // rdx
const char *v5; // rbp
unsigned int v6; // eax
size_t v7; // rdx
const char *v8; // rbp
unsigned int v9; // eax
_BYTE v11[136]; // [rsp+0h] [rbp-88h] BYREF

v0 = "this is test";
v1 = (const char **)inarray_1;
tcase_fn_start("test_bloom_filter", "test_bloomfilter.c", 23LL);
dbloom_filter_init(v11, 10000LL, 40LL);
for ( i = 12LL; ; i = strlen(*v1) )
{
++v1;
dbloom_filter_add(v11, v0, i);
v0 = *v1;
if ( !*v1 )
break;
}
v3 = 0LL;
v4 = 11LL;
v5 = "not in here";
while ( 1 )
{
v6 = dbloom_filter_find(v11, v5, v4);
if ( v6 )
{
v9 = ck_assert_failed(
"test_bloomfilter.c",
43LL,
"Assertion 'ret == 0' failed",
"find failed, index:%d, ret: %d!",
(unsigned int)v3,
v6);
goto LABEL_14;
}
++v3;
mark_point("test_bloomfilter.c", 43LL);
v5 = notinarray_0[v3];
if ( !v5 )
break;
v4 = strlen(notinarray_0[v3]);
}
v3 = 0LL;
v7 = 12LL;
v8 = "this is test";
while ( 1 )
{
v9 = dbloom_filter_find(v11, v8, v7);
if ( v9 != 1 )
break;
++v3;
mark_point("test_bloomfilter.c", 48LL);
v8 = inarray_1[v3];
if ( !v8 )
return dbloom_filter_fini(v11);
v7 = strlen(inarray_1[v3]);
}
LABEL_14:
ck_assert_failed(
"test_bloomfilter.c",
48LL,
"Assertion 'ret == 1' failed",
"find failed, index:%d, ret:%d!",
(unsigned int)v3,
v9);
return func3();
}

original_code:
static void test_bloom_filter (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_bloom_filter", "test_bloomfilter.c", 23);
{
    struct dbloom_filter filter;
    dbloom_filter_init(&filter, 10000, 40);
    static char* inarray[] = {
        "this is test",
        "all is here",
        "devlib",
        ((void *)0)
    };
    static char* notinarray[] = {
        "not in here",
        "hh",
        ((void *)0)
    };
    for(int i = 0; inarray[i] != ((void *)0); ++i){
        dbloom_filter_add(&filter, inarray[i], strlen(inarray[i]));
    }
    for(int i = 0; notinarray[i] != ((void *)0); ++i){
        int ret = dbloom_filter_find(&filter, notinarray[i], strlen(notinarray[i]));
        (ret == 0) ? _mark_point("test_bloomfilter.c", 43) : _ck_assert_failed("test_bloomfilter.c", 43, "Assertion '""ret == 0""' failed" , "find failed, index:%d, ret: %d!", i, ret, ((void *)0));
    }
    for(int i = 0; inarray[i] != ((void *)0); ++i){
        int ret = dbloom_filter_find(&filter, inarray[i], strlen(inarray[i]));
        (ret == 1) ? _mark_point("test_bloomfilter.c", 48) : _ck_assert_failed("test_bloomfilter.c", 48, "Assertion '""ret == 1""' failed" , "find failed, index:%d, ret:%d!", i, ret, ((void *)0));
    }
    dbloom_filter_fini(&filter);
}
}

canonical_original_code:
static void test_bloom_filter(int _i){ tcase_fn_start ("""test_bloom_filter", "test_bloomfilter.c", 23);
{
    struct dbloom_filter filter;
    dbloom_filter_init(&filter, 10000, 40);
    static char *inarray[] = {
        "this is test",
        "all is here",
        "devlib",
        ((void *)0)
    };
    static char *notinarray[] = {
        "not in here",
        "hh",
        ((void *)0)
    };
    for(int i = 0; inarray[i] != ((void *)0); ++i){
        dbloom_filter_add(&filter, inarray[i], strlen(inarray[i]));
    }
    for(int i = 0; notinarray[i] != ((void *)0); ++i){
        int ret = dbloom_filter_find(&filter, notinarray[i], strlen(notinarray[i]));
        (ret == 0) ? _mark_point("test_bloomfilter.c", 43) : _ck_assert_failed("test_bloomfilter.c", 43, "Assertion '""ret == 0""' failed" , "find failed, index:%d, ret: %d!", i, ret, ((void *)0));
    }
    for(int i = 0; inarray[i] != ((void *)0); ++i){
        int ret = dbloom_filter_find(&filter, inarray[i], strlen(inarray[i]));
        (ret == 1) ? _mark_point("test_bloomfilter.c", 48) : _ck_assert_failed("test_bloomfilter.c", 48, "Assertion '""ret == 1""' failed" , "find failed, index:%d, ret:%d!", i, ret, ((void *)0));
    }
    dbloom_filter_fini(&filter);
}
}

variable_types: struct dbloom_filter { unsigned int (*hash[-1])(char *, unsigned int); int capacity; int func_count; unsigned int fail_count; char *buffer; }

variable_types:
inarray
char *[]

variable_types:
notinarray
char *[]


repo: magiczhao/devlib

decompiled_code:
__int64 test_bloom_init()
{
__int64 result; // rax
_BYTE v1[120]; // [rsp+0h] [rbp-78h] BYREF

tcase_fn_start("test_bloom_init", "test_bloomfilter.c", 14LL);
if ( (unsigned int)dbloom_filter_init(v1, 100000LL, 100LL) )
{
ck_assert_failed("test_bloomfilter.c", 18LL, "Assertion 'ret == 0' failed", "init failed", 0LL);
result = bloomfilter_suite();
}
else
{
mark_point("test_bloomfilter.c", 18LL);
result = dbloom_filter_fini(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
_BYTE v1[120]; // [rsp+0h] [rbp-78h] BYREF

tcase_fn_start("test_bloom_init", "test_bloomfilter.c", 14LL);
if ( (unsigned int)dbloom_filter_init(v1, 100000LL, 100LL) )
{
ck_assert_failed("test_bloomfilter.c", 18LL, "Assertion 'ret == 0' failed", "init failed", 0LL);
result = func4();
}
else
{
mark_point("test_bloomfilter.c", 18LL);
result = dbloom_filter_fini(v1);
}
return result;
}

original_code:
static void test_bloom_init (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_bloom_init", "test_bloomfilter.c", 14);
{
    struct dbloom_filter filter;
    int ret = dbloom_filter_init(&filter, 100000, 100);
    (ret == 0) ? _mark_point("test_bloomfilter.c", 18) : _ck_assert_failed("test_bloomfilter.c", 18, "Assertion '""ret == 0""' failed" , "init failed", ((void *)0));
    dbloom_filter_fini(&filter);
}
}

canonical_original_code:
static void test_bloom_init(int _i){ tcase_fn_start ("""test_bloom_init", "test_bloomfilter.c", 14);
{
    struct dbloom_filter filter;
    int ret = dbloom_filter_init(&filter, 100000, 100);
    (ret == 0) ? _mark_point("test_bloomfilter.c", 18) : _ck_assert_failed("test_bloomfilter.c", 18, "Assertion '""ret == 0""' failed" , "init failed", ((void *)0));
    dbloom_filter_fini(&filter);
}
}

variable_types: ret int

return_type: void

user_defined_types: struct dbloom_filter { unsigned int (*hash[-1])(char *, unsigned int); int capacity; int func_count; unsigned int fail_count; char *buffer; }


setup

decompiled_code:
__int64 setup()
{
return dbloom_filter_init(&gbfilter, 10000LL, 40LL);
}

canonical_decompiled_code:
__int64 func0()
{
return dbloom_filter_init(&gbfilter, 10000LL, 40LL);
}

original_code:
void setup(void)
{
    dbloom_filter_init(&gbfilter, 10000, 40);
}

canonical_original_code:
void setup()
{
    dbloom_filter_init(&gbfilter, 10000, 40);
}


decompiled_code:
__int64 __fastcall dhash_table_init(__int64 a1, int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
_QWORD *v5; // rax
__int64 v6; // rdx

*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
*(_QWORD *)(a1 + 16) = a4;
*(_QWORD *)(a1 + 24) = malloc(16LL * a2);
result = fixed_pool_init(a1 + 32, (unsigned int)(16 * a2), 40LL);
if ( (_DWORD)result != -1 )
{
v5 = *(_QWORD **)(a1 + 24);
if ( v5 )
{
if ( a2 > 0 )
{
v6 = (__int64)&v5[2 * (unsigned int)(a2 - 1) + 2];
do
{
*v5 = v5;
v5[1] = v5;
v5 += 2;
}
while ( v5 != (_QWORD *)v6 );
}
result = 0LL;
}
else
{
fixed_pool_fini(a1 + 32);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
_QWORD *v5; // rax
__int64 v6; // rdx

*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
*(_QWORD *)(a1 + 16) = a4;
*(_QWORD *)(a1 + 24) = malloc(16LL * a2);
result = fixed_pool_init(a1 + 32, (unsigned int)(16 * a2), 40LL);
if ( (_DWORD)result != -1 )
{
v5 = *(_QWORD **)(a1 + 24);
if ( v5 )
{
if ( a2 > 0 )
{
v6 = (__int64)&v5[2 * (unsigned int)(a2 - 1) + 2];
do
{
*v5 = v5;
v5[1] = v5;
v5 += 2;
}
while ( v5 != (_QWORD *)v6 );
}
result = 0LL;
}
else
{
fixed_pool_fini(a1 + 32);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int dhash_table_init(struct dhash_table* ht, int capacity,
    dhash_func hash, compare_func comp)
{
    ht->capacity = capacity;
    ht->hash = hash;
    ht->compare = comp;
    ht->buckets = (struct dlist_node*) malloc(sizeof(struct dlist_node) * capacity);
    int fret = fixed_pool_init(&ht->allocator, capacity * 16, sizeof(struct dhash_node));
    if(fret == -1){
        return -1;
    }
    if(ht->buckets){
        for(int i = 0; i < capacity; ++i){
            do{ (&(ht->buckets[i]))->prev = (&(ht->buckets[i])); (&(ht->buckets[i]))->next = (&(ht->buckets[i])); }while(0);
        }
        return 0;
    }
    fixed_pool_fini(&ht->allocator);
    return -1;
}

canonical_original_code:
int dhash_table_init(struct dhash_table *ht, int capacity, unsigned int (*hash)(char *, unsigned int), int (*comp)(char *, int, char *, int))
{
    ht->capacity = capacity;
    ht->hash = hash;
    ht->compare = comp;
    ht->buckets = (struct dlist_node *) malloc(sizeof(struct dlist_node) * capacity);
    int fret = fixed_pool_init(&ht->allocator, capacity * 16, sizeof(struct dhash_node));
    if(fret == -1){
        return -1;
    }
    if(ht->buckets){
        for(int i = 0; i < capacity; ++i){
            do{ (&(ht->buckets[i]))->prev = (&(ht->buckets[i])); (&(ht->buckets[i]))->next = (&(ht->buckets[i])); }while(0);
        }
        return 0;
    }
    fixed_pool_fini(&ht->allocator);
    return -1;
}

variable_types: struct dhash_table { int capacity; unsigned int (*hash)(char *, unsigned int); int (*compare)(char *, int, char *, int); struct dlist_node { struct dlist_node *prev; struct dlist_node *next; } *buckets; struct fixed_dmem_pool { struct dlist_node head; int item_size; int total_size; char *buffer; char *position; } allocator; } *

variable_types: capacity int

variable_types:
hash
unsigned int (*)(char *, unsigned int)

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

variable_types: fret int

variable_types: i int

return_type: int

user_defined_types: struct dhash_table { int capacity; unsigned int (*hash)(char *, unsigned int); int (*compare)(char *, int, char *, int); struct dlist_node *buckets; struct fixed_dmem_pool allocator; }


decompiled_code:
void __fastcall dhash_table_fini(__int64 a1)
{
fixed_pool_fini(a1 + 32);
free(*(void **)(a1 + 24));
*(_QWORD *)(a1 + 24) = 0LL;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
fixed_pool_fini(a1 + 32);
free(*(void **)(a1 + 24));
*(_QWORD *)(a1 + 24) = 0LL;
}

original_code:
void dhash_table_fini(struct dhash_table* ht)
{
    fixed_pool_fini(&ht->allocator);
    free(ht->buckets);
    ht->buckets = ((void *)0);
    return;
}

canonical_original_code:
void dhash_table_fini(struct dhash_table *ht)
{
    fixed_pool_fini(&ht->allocator);
    free(ht->buckets);
    ht->buckets = ((void *)0);
    return;
}

user_defined_types: struct fixed_dmem_pool { struct dlist_node head; int item_size; int total_size; char *buffer; char *position; }

user_defined_types: struct dlist_node { struct dlist_node *prev; struct dlist_node *next; }


decompiled_code:
__int64 __fastcall dhash_table_add(__int64 a1, __int64 a2, unsigned int a3, __int64 a4)
{
unsigned int v6; // ebp
__int64 v7; // rax
__int64 v8; // rdi
__int64 result; // rax

if ( dhash_find(a1, a2, a3) )
{
*_errno_location() = 17;
result = 0xFFFFFFFFLL;
}
else
{
v6 = (*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 8))(a2, a3) % *(_DWORD *)a1;
v7 = d_fp_malloc(a1 + 32, 40LL);
if ( v7 )
{
*(_DWORD *)(v7 + 16) = a3;
*(_QWORD *)(v7 + 24) = a2;
v8 = *(_QWORD *)(a1 + 24) + 16LL * v6;
*(_QWORD *)(v7 + 32) = a4;
dlist_add_isra_0(v8, (_QWORD *)v7);
result = 0LL;
}
else
{
*_errno_location() = 12;
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned int a3, __int64 a4)
{
unsigned int v6; // ebp
__int64 v7; // rax
__int64 v8; // rdi
__int64 result; // rax

if ( func0(a1, a2, a3) )
{
*_errno_location() = 17;
result = 0xFFFFFFFFLL;
}
else
{
v6 = (*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 8))(a2, a3) % *(_DWORD *)a1;
v7 = d_fp_malloc(a1 + 32, 40LL);
if ( v7 )
{
*(_DWORD *)(v7 + 16) = a3;
*(_QWORD *)(v7 + 24) = a2;
v8 = *(_QWORD *)(a1 + 24) + 16LL * v6;
*(_QWORD *)(v7 + 32) = a4;
dlist_add_isra_0(v8, (_QWORD *)v7);
result = 0LL;
}
else
{
*_errno_location() = 12;
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int dhash_table_add(struct dhash_table* ht, char* key, int key_size, void* value)
{
    if(_dhash_find(ht, key, key_size) == ((void *)0)){
        unsigned int hval = ht->hash(key, key_size);
        unsigned int hpos = hval % ht->capacity;
        struct dhash_node* node = (struct dhash_node*)d_fp_malloc(&ht->allocator, sizeof(struct dhash_node));
        if(node){
            do{ ((&node->key))->size = (key_size); ((&node->key))->buffer = key; }while(0);
            node->value = value;
            dlist_add(&(ht->buckets[hpos]), &node->lnode);
        }else{
            (*__errno_location ()) = 12;
            return -1;
        }
    }else{
        (*__errno_location ()) = 17;
        return -1;
    }
    return 0;
}

canonical_original_code:
int dhash_table_add(struct dhash_table *ht, char *key, int key_size, void *value)
{
    if(_dhash_find(ht, key, key_size) == ((void *)0)){
        unsigned int hval = ht->hash(key, key_size);
        unsigned int hpos = hval % ht->capacity;
        struct dhash_node *node = (struct dhash_node*)d_fp_malloc(&ht->allocator, sizeof(struct dhash_node));
        if(node){
            do{ ((&node->key))->size = (key_size); ((&node->key))->buffer = key; }while(0);
            node->value = value;
            dlist_add(&(ht->buckets[hpos]), &node->lnode);
        }else{
            (*__errno_location ()) = 12;
            return -1;
        }
    }else{
        (*__errno_location ()) = 17;
        return -1;
    }
    return 0;
}

variable_types:
key
char *

variable_types:
value
void *

variable_types:
hval
unsigned int

variable_types:
hpos
unsigned int

variable_types: struct dhash_node { struct dlist_node { struct dlist_node *prev; struct dlist_node *next; } lnode; struct dstring { int size; char *buffer; } key; void *value; } *

user_defined_types: struct dhash_node { struct dlist_node lnode; struct dstring key; void *value; }


decompiled_code:
__int64 __fastcall dhash_table_find(__int64 a1, __int64 a2, unsigned int a3, _QWORD *a4)
{
__int64 v5; // rax
unsigned int v6; // er8

v5 = dhash_find(a1, a2, a3);
v6 = 0;
if ( v5 )
{
v6 = 1;
*a4 = *(_QWORD *)(v5 + 32);
}
return v6;
}

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

v5 = func0(a1, a2, a3);
v6 = 0;
if ( v5 )
{
v6 = 1;
*a4 = *(_QWORD *)(v5 + 32);
}
return v6;
}

original_code:
int dhash_table_find(struct dhash_table* ht, char* key, int key_size, void** value)
{
    struct dhash_node* node = _dhash_find(ht, key, key_size);
    if(node){
        *value = node->value;
        return 1;
    }
    return 0;
}

canonical_original_code:
int dhash_table_find(struct dhash_table *ht, char *key, int key_size, void **value)
{
    struct dhash_node *node = _dhash_find(ht, key, key_size);
    if(node){
        *value = node->value;
        return 1;
    }
    return 0;
}

variable_types:
value
void **

user_defined_types: struct dstring { int size; char *buffer; }


decompiled_code:
__int64 test_clear_bit()
{
tcase_fn_start("test_clear_bit", "test_bitop.c", 19LL);
return mark_point("test_bitop.c", 23LL);
}

canonical_decompiled_code:
__int64 func0()
{
tcase_fn_start("test_clear_bit", "test_bitop.c", 19LL);
return mark_point("test_bitop.c", 23LL);
}

original_code:
static void test_clear_bit (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_clear_bit", "test_bitop.c", 19);
{
    char cval = 9;
    do{*(&cval) ^= (1 << 3);}while(0);
    (cval == 1) ? _mark_point("test_bitop.c", 23) : _ck_assert_failed("test_bitop.c", 23, "Assertion '""cval == 1""' failed" , "clear bit failed", ((void *)0));
}
}

canonical_original_code:
static void test_clear_bit(int _i){ tcase_fn_start ("""test_clear_bit", "test_bitop.c", 19);
{
    char cval = 9;
    do{*(&cval) ^= (1 << 3);}while(0);
    (cval == 1) ? _mark_point("test_bitop.c", 23) : _ck_assert_failed("test_bitop.c", 23, "Assertion '""cval == 1""' failed" , "clear bit failed", ((void *)0));
}
}

variable_types: cval char


decompiled_code:
__int64 test_set_bit()
{
tcase_fn_start("test_set_bit", "test_bitop.c", 4LL);
mark_point("test_bitop.c", 8LL);
mark_point("test_bitop.c", 11LL);
return mark_point("test_bitop.c", 15LL);
}

canonical_decompiled_code:
__int64 func1()
{
tcase_fn_start("test_set_bit", "test_bitop.c", 4LL);
mark_point("test_bitop.c", 8LL);
mark_point("test_bitop.c", 11LL);
return mark_point("test_bitop.c", 15LL);
}

original_code:
static void test_set_bit (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_set_bit", "test_bitop.c", 4);
{
    char cval = 0;
    do{*(&cval) |= (1 << 3);}while(0);
    (cval == 8) ? _mark_point("test_bitop.c", 8) : _ck_assert_failed("test_bitop.c", 8, "Assertion '""cval == 8""' failed" , "set bit failed", ((void *)0));
    cval = 0;
    do{*(&cval) |= (1 << 0);}while(0);
    (cval == 1) ? _mark_point("test_bitop.c", 11) : _ck_assert_failed("test_bitop.c", 11, "Assertion '""cval == 1""' failed" , "set zero bit failed", ((void *)0));
    int ival = 0;
    do{*(&ival) |= (1 << 10);}while(0);
    (ival == 1024) ? _mark_point("test_bitop.c", 15) : _ck_assert_failed("test_bitop.c", 15, "Assertion '""ival == 1024""' failed" , "set int failed", ((void *)0));
}
}

canonical_original_code:
static void test_set_bit(int _i){ tcase_fn_start ("""test_set_bit", "test_bitop.c", 4);
{
    char cval = 0;
    do{*(&cval) |= (1 << 3);}while(0);
    (cval == 8) ? _mark_point("test_bitop.c", 8) : _ck_assert_failed("test_bitop.c", 8, "Assertion '""cval == 8""' failed" , "set bit failed", ((void *)0));
    cval = 0;
    do{*(&cval) |= (1 << 0);}while(0);
    (cval == 1) ? _mark_point("test_bitop.c", 11) : _ck_assert_failed("test_bitop.c", 11, "Assertion '""cval == 1""' failed" , "set zero bit failed", ((void *)0));
    int ival = 0;
    do{*(&ival) |= (1 << 10);}while(0);
    (ival == 1024) ? _mark_point("test_bitop.c", 15) : _ck_assert_failed("test_bitop.c", 15, "Assertion '""ival == 1024""' failed" , "set int failed", ((void *)0));
}
}

variable_types: ival int


decompiled_code:
_BOOL8 __fastcall package_complete(const void *a1, int a2)
{
return memchr(a1, 10, a2) != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const void *a1, int a2)
{
return memchr(a1, 10, a2) != 0LL;
}

original_code:
int package_complete(const char* buffer, int size)
{
    if(memchr(buffer, '\n', size)){
        return 1;
    }
    return 0;
}

canonical_original_code:
int package_complete(char *buffer, int size)
{
    if(memchr(buffer, '\n', size)){
        return 1;
    }
    return 0;
}

variable_types:
buffer
char *

variable_types: size int


decompiled_code:
int __fastcall dlock_init(pthread_mutex_t *a1)
{
return pthread_mutex_init(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(pthread_mutex_t *a1)
{
return pthread_mutex_init(a1, 0LL);
}

original_code:
int dlock_init(pthread_mutex_t* lock)
{
    return pthread_mutex_init(lock, ((void *)0));
}

canonical_original_code:
int dlock_init(union pthread_mutex_t *lock)
{
    return pthread_mutex_init(lock, ((void *)0));
}

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *

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

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


decompiled_code:
size_t test_kmp()
{
char *v0; // rbx
size_t result; // rax
const char *v2; // rbx
__int64 v3; // rbp
int v4; // eax
__int64 v5; // rbx
unsigned int v6; // eax
int v7; // [rsp+0h] [rbp-38h] BYREF
char *v8; // [rsp+8h] [rbp-30h]
int v9; // [rsp+10h] [rbp-28h] BYREF
const char *v10; // [rsp+18h] [rbp-20h]

tcase_fn_start("test_kmp", "test_string.c", 19LL);
v0 = big;
result = strlen(big);
v8 = v0;
v2 = tests;
v7 = result;
if ( tests )
{
v3 = 0LL;
while ( 1 )
{
v4 = strlen(v2);
v10 = v2;
v5 = 2 * v3;
v9 = v4;
v6 = kmp_search(&v7, &v9);
if ( LODWORD((&tests)[2 * v3 + 1]) != v6 )
break;
++v3;
result = mark_point("test_string.c", 29LL);
v2 = (&tests)[v5 + 2];
if ( !v2 )
return result;
}
ck_assert_failed(
"test_string.c",
29LL,
"Assertion 'pos == tests[index].expected' failed",
"test case %d failed, pos:%d, string:%s",
(unsigned int)v3,
v6,
(&tests)[2 * (int)v3]);
result = dstring_suite();
}
return result;
}

canonical_decompiled_code:
size_t func0()
{
char *v0; // rbx
size_t result; // rax
const char *v2; // rbx
__int64 v3; // rbp
int v4; // eax
__int64 v5; // rbx
unsigned int v6; // eax
int v7; // [rsp+0h] [rbp-38h] BYREF
char *v8; // [rsp+8h] [rbp-30h]
int v9; // [rsp+10h] [rbp-28h] BYREF
const char *v10; // [rsp+18h] [rbp-20h]

tcase_fn_start("test_kmp", "test_string.c", 19LL);
v0 = big;
result = strlen(big);
v8 = v0;
v2 = tests;
v7 = result;
if ( tests )
{
v3 = 0LL;
while ( 1 )
{
v4 = strlen(v2);
v10 = v2;
v5 = 2 * v3;
v9 = v4;
v6 = kmp_search(&v7, &v9);
if ( LODWORD((&tests)[2 * v3 + 1]) != v6 )
break;
++v3;
result = mark_point("test_string.c", 29LL);
v2 = (&tests)[v5 + 2];
if ( !v2 )
return result;
}
ck_assert_failed(
"test_string.c",
29LL,
"Assertion 'pos == tests[index].expected' failed",
"test case %d failed, pos:%d, string:%s",
(unsigned int)v3,
v6,
(&tests)[2 * (int)v3]);
result = func1();
}
return result;
}

original_code:
static void test_kmp (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_kmp", "test_string.c", 19);
{
    struct dstring haystack;
    struct dstring needle;
    do{ (&haystack)->size = (strlen(big)); (&haystack)->buffer = big; }while(0);
    int index = 0;
    while(1){
        if(tests[index].str){
            do{ (&needle)->size = (strlen(tests[index].str)); (&needle)->buffer = tests[index].str; }while(0);
            int pos = kmp_search(&haystack, &needle);
            (pos == tests[index].expected) ? _mark_point("test_string.c", 29) : _ck_assert_failed("test_string.c", 29, "Assertion '""pos == tests[index].expected""' failed" , "test case %d failed, pos:%d, string:%s", index, pos, tests[index].str, ((void *)0));
        }else{break;}
        index++;
    }
}
}

canonical_original_code:
static void test_kmp(int _i){ tcase_fn_start ("""test_kmp", "test_string.c", 19);
{
    struct dstring haystack;
    struct dstring needle;
    do{ (&haystack)->size = (strlen(big)); (&haystack)->buffer = big; }while(0);
    int index = 0;
    while(1){
        if(tests[index].str){
            do{ (&needle)->size = (strlen(tests[index].str)); (&needle)->buffer = tests[index].str; }while(0);
            int pos = kmp_search(&haystack, &needle);
            (pos == tests[index].expected) ? _mark_point("test_string.c", 29) : _ck_assert_failed("test_string.c", 29, "Assertion '""pos == tests[index].expected""' failed" , "test case %d failed, pos:%d, string:%s", index, pos, tests[index].str, ((void *)0));
        }else{break;}
        index++;
    }
}
}

variable_types: struct dstring { int size; char *buffer; }

variable_types: index int

variable_types: pos int


original_code:
int kmp_search(const struct dstring* haystack, const struct dstring* needle)
{
    char* p = ((needle)->buffer);
    char* h = ((haystack)->buffer);
    int pptable[((needle)->size)];
    for(int i = 0; i < ((needle)->size); ++i){
        if(i == 0){pptable[i] = 0; continue;}
        if(*(p + pptable[i - 1]) == *(p + i)){
            pptable[i] = pptable[i - 1] + 1;
        }else{
            pptable[i] = 0;
        }
    }
    int pos = 0;
    while((h - ((haystack)->buffer)) < ((haystack)->size)){
        if(*h == *(p + pos)){
            if(pos + 1 == ((needle)->size)){
                return h - ((haystack)->buffer) - ((needle)->size) + 1;
            }
            ++pos;
        }else{
            if(pos > 0) pos = pptable[pos - 1];
            else pos = 0;
        }
        ++h;
    }
    if(pos == ((needle)->size))return pos - ((needle)->size);
    return -1;
}

canonical_original_code:
int kmp_search(struct dstring *haystack, struct dstring *needle)
{
    char *p = ((needle)->buffer);
    char *h = ((haystack)->buffer);
    int pptable[-1];
    for(int i = 0; i < ((needle)->size); ++i){
        if(i == 0){pptable[i] = 0; continue;}
        if(*(p + pptable[i - 1]) == *(p + i)){
            pptable[i] = pptable[i - 1] + 1;
        }else{
            pptable[i] = 0;
        }
    }
    int pos = 0;
    while((h - ((haystack)->buffer)) < ((haystack)->size)){
        if(*h == *(p + pos)){
            if(pos + 1 == ((needle)->size)){
                return h - ((haystack)->buffer) - ((needle)->size) + 1;
            }
            ++pos;
        }else{
            if(pos > 0) pos = pptable[pos - 1];
            else pos = 0;
        }
        ++h;
    }
    if(pos == ((needle)->size))return pos - ((needle)->size);
    return -1;
}

variable_types: struct dstring { int size; char *buffer; } *

variable_types:
needle
struct dstring *

variable_types:
p
char *

variable_types:
h
char *

variable_types:
pptable
int [-1]


decompiled_code:
__int64 __fastcall set_nonblock(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3, 0LL);
BYTE1(v1) |= 8u;
return (unsigned int)-(fcntl(fd, 4, v1) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3, 0LL);
BYTE1(v1) |= 8u;
return (unsigned int)-(fcntl(fd, 4, v1) != 0);
}

original_code:
inline int set_nonblock(int fd)
{
    int flag = fcntl(fd, 3, 0);
    if(fcntl(fd, 4, flag | 04000) != 0) return -1;
    return 0;
}

variable_types: fd int

variable_types: flag int


original_code:
int init_config(struct frame_config* config)
{
    memset(config, 0, sizeof(struct frame_config));
    config->threads = 0;
    config->nodelay = 1;
    config->send_buffer_size = 8192;
    config->recv_buffer_size = 8192;
    config->backlog = 5;
    return 0;
}

canonical_original_code:
int init_config(struct frame_config *config)
{
    memset(config, 0, sizeof(struct frame_config));
    config->threads = 0;
    config->nodelay = 1;
    config->send_buffer_size = 8192;
    config->recv_buffer_size = 8192;
    config->backlog = 5;
    return 0;
}

variable_types: struct frame_config { char *listen_ip; char *run_dir; char *tcc_buffer; char *cblib; char *networklib; int threads; int nodelay; int recv_buffer_size; int send_buffer_size; int backlog; short listen_port; } *


decompiled_code:
void __fastcall fini_config(__int64 a1)
{
free(*(void **)(a1 + 16));
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code:
void fini_config(struct frame_config* config)
{
    free(config->tcc_buffer);
    config->tcc_buffer = ((void *)0);
}

canonical_original_code:
void fini_config(struct frame_config *config)
{
    free(config->tcc_buffer);
    config->tcc_buffer = ((void *)0);
}

user_defined_types: struct frame_config { char *listen_ip; char *run_dir; char *tcc_buffer; char *cblib; char *networklib; int threads; int nodelay; int recv_buffer_size; int send_buffer_size; int backlog; short listen_port; }


decompiled_code:
int test_lock()
{
pthread_mutex_t v1; // [rsp+0h] [rbp-38h] BYREF

tcase_fn_start("test_lock", "test_lock.c", 3LL);
if ( (unsigned int)dlock_init(&v1) )
{
ck_assert_failed("test_lock.c", 7LL, "Assertion 'ret == 0' failed", "init lock failed", 0LL);
LABEL_6:
ck_assert_failed("test_lock.c", 13LL, "Assertion 'ret == 0' failed", "try lock unlocked failed", 0LL);
goto LABEL_7;
}
mark_point("test_lock.c", 7LL);
pthread_mutex_lock(&v1);
if ( pthread_mutex_trylock(&v1) )
{
mark_point("test_lock.c", 10LL);
pthread_mutex_unlock(&v1);
if ( !pthread_mutex_trylock(&v1) )
{
mark_point("test_lock.c", 13LL);
return pthread_mutex_unlock(&v1);
}
goto LABEL_6;
}
LABEL_7:
ck_assert_failed("test_lock.c", 10LL, "Assertion 'ret != 0' failed", "try lock failed", 0LL);
return lock_suite();
}

canonical_decompiled_code:
int func0()
{
pthread_mutex_t v1; // [rsp+0h] [rbp-38h] BYREF

tcase_fn_start("test_lock", "test_lock.c", 3LL);
if ( (unsigned int)dlock_init(&v1) )
{
ck_assert_failed("test_lock.c", 7LL, "Assertion 'ret == 0' failed", "init lock failed", 0LL);
LABEL_6:
ck_assert_failed("test_lock.c", 13LL, "Assertion 'ret == 0' failed", "try lock unlocked failed", 0LL);
goto LABEL_7;
}
mark_point("test_lock.c", 7LL);
pthread_mutex_lock(&v1);
if ( pthread_mutex_trylock(&v1) )
{
mark_point("test_lock.c", 10LL);
pthread_mutex_unlock(&v1);
if ( !pthread_mutex_trylock(&v1) )
{
mark_point("test_lock.c", 13LL);
return pthread_mutex_unlock(&v1);
}
goto LABEL_6;
}
LABEL_7:
ck_assert_failed("test_lock.c", 10LL, "Assertion 'ret != 0' failed", "try lock failed", 0LL);
return func1();
}

original_code:
static void test_lock (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_lock", "test_lock.c", 3);
{
    pthread_mutex_t lock;
    int ret = dlock_init(&lock);
    (ret == 0) ? _mark_point("test_lock.c", 7) : _ck_assert_failed("test_lock.c", 7, "Assertion '""ret == 0""' failed" , "init lock failed", ((void *)0));
    pthread_mutex_lock(&lock);
    ret = pthread_mutex_trylock(&lock);
    (ret != 0) ? _mark_point("test_lock.c", 10) : _ck_assert_failed("test_lock.c", 10, "Assertion '""ret != 0""' failed" , "try lock failed", ((void *)0));
    pthread_mutex_unlock(&lock);
    ret = pthread_mutex_trylock(&lock);
    (ret == 0) ? _mark_point("test_lock.c", 13) : _ck_assert_failed("test_lock.c", 13, "Assertion '""ret == 0""' failed" , "try lock unlocked failed", ((void *)0));
    pthread_mutex_unlock(&lock);
}
}

canonical_original_code:
static void test_lock(int _i){ tcase_fn_start ("""test_lock", "test_lock.c", 3);
{
    union pthread_mutex_t lock;
    int ret = dlock_init(&lock);
    (ret == 0) ? _mark_point("test_lock.c", 7) : _ck_assert_failed("test_lock.c", 7, "Assertion '""ret == 0""' failed" , "init lock failed", ((void *)0));
    pthread_mutex_lock(&lock);
    ret = pthread_mutex_trylock(&lock);
    (ret != 0) ? _mark_point("test_lock.c", 10) : _ck_assert_failed("test_lock.c", 10, "Assertion '""ret != 0""' failed" , "try lock failed", ((void *)0));
    pthread_mutex_unlock(&lock);
    ret = pthread_mutex_trylock(&lock);
    (ret == 0) ? _mark_point("test_lock.c", 13) : _ck_assert_failed("test_lock.c", 13, "Assertion '""ret == 0""' failed" , "try lock unlocked failed", ((void *)0));
    pthread_mutex_unlock(&lock);
}
}

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; }

variable_types: ret int


repo: maginth/bistromathique

decompiled_code:
__int64 __fastcall ft_uatoi(_BYTE *a1)
{
int v1; // eax
unsigned int i; // er8

v1 = (char)*a1;
for ( i = 0; *a1; v1 = (char)*a1 )
{
++a1;
i = v1 + 10 * i - 48;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
int v1; // eax
unsigned int i; // er8

v1 = (char)*a1;
for ( i = 0; *a1; v1 = (char)*a1 )
{
++a1;
i = v1 + 10 * i - 48;
}
return i;
}

original_code:
static unsigned int ft_uatoi(char *nbr)
{
 unsigned int res;
 res = 0;
 while (*nbr)
 {
  res = *nbr - '0' + res * 10;
  nbr = nbr + 1;
 }
 return (res);
}

variable_types:
nbr
char *

variable_types:
res
unsigned int

return_type: unsigned int


decompiled_code:
ssize_t __fastcall ft_fill_buff(void *buf, size_t nbytes)
{
__int64 v2; // rbx
ssize_t result; // rax
size_t v4; // rax

v2 = 0LL;
result = read(0, buf, nbytes);
if ( result == -1 )
{
LABEL_6:
v4 = ft_strlen_constprop_0();
write(2, byte_11A, v4);
result = 1LL;
}
else
{
while ( result )
{
v2 += result;
result = read(0, buf, nbytes - v2);
if ( result == -1 )
goto LABEL_6;
}
*((_BYTE *)buf + v2) = 0;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(void *buf, size_t nbytes)
{
__int64 v2; // rbx
ssize_t result; // rax
size_t v4; // rax

v2 = 0LL;
result = read(0, buf, nbytes);
if ( result == -1 )
{
LABEL_6:
v4 = func1();
write(2, byte_11A, v4);
result = 1LL;
}
else
{
while ( result )
{
v2 += result;
result = read(0, buf, nbytes - v2);
if ( result == -1 )
goto LABEL_6;
}
*((_BYTE *)buf + v2) = 0;
}
return result;
}

original_code:
static int ft_fill_buff(char* buf, size_t size)
{
 size_t size_read;
 ssize_t ret;
 size_read = 0;
 ret = read(0, buf, size);
 if (ret == -1)
 {
  write(2, "syntax error\n", ft_strlen("syntax error\n"));
  return (1);
 }
 while (ret != 0)
 {
  size_read = size_read + ret;
  ret = read(0, buf, size - size_read);
  if (ret == -1)
  {
   write(2, "syntax error\n", ft_strlen("syntax error\n"));
   return (1);
  }
 }
 buf[size_read] = 0;
 return (0);
}

canonical_original_code:
static int ft_fill_buff(char *buf, unsigned long size)
{
 unsigned long size_read;
 long ret;
 size_read = 0;
 ret = read(0, buf, size);
 if (ret == -1)
 {
  write(2, "syntax error\n", ft_strlen("syntax error\n"));
  return (1);
 }
 while (ret != 0)
 {
  size_read = size_read + ret;
  ret = read(0, buf, size - size_read);
  if (ret == -1)
  {
   write(2, "syntax error\n", ft_strlen("syntax error\n"));
   return (1);
  }
 }
 buf[size_read] = 0;
 return (0);
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types: ret long


decompiled_code:
ssize_t __fastcall ft_check_args_n_malloc_buf(void *a1, __int64 a2, _QWORD *a3)
{
size_t v4; // rbp
void *v5; // rax
size_t v7; // rax

if ( (_DWORD)a1 == 4 )
{
v4 = (unsigned int)ft_uatoi(*(_BYTE **)(a2 + 24));
v5 = malloc(v4 + 1);
*a3 = v5;
a1 = v5;
if ( v5 )
return ft_fill_buff(v5, v4);
}
v7 = ft_strlen_constprop_0(a1);
write(2, byte_11A, v7);
return 1LL;
}

canonical_decompiled_code:
ssize_t __fastcall func3(void *a1, __int64 a2, _QWORD *a3)
{
size_t v4; // rbp
void *v5; // rax
size_t v7; // rax

if ( (_DWORD)a1 == 4 )
{
v4 = (unsigned int)func0(*(_BYTE **)(a2 + 24));
v5 = malloc(v4 + 1);
*a3 = v5;
a1 = v5;
if ( v5 )
return func2(v5, v4);
}
v7 = func1(a1);
write(2, byte_11A, v7);
return 1LL;
}

original_code:
static int ft_check_args_n_malloc_buf(int argc, char **argv, char **buf)
{
 size_t size;
 if (argc != 4)
 {
  write(2, "syntax error\n", ft_strlen("syntax error\n"));
  return (1);
 }
 size = ft_uatoi(argv[3]);
 *buf = malloc(sizeof(**buf) * (size + 1));
 if (*buf == 0)
 {
  write(2, "syntax error\n", ft_strlen("syntax error\n"));
  return (1);
 }
 return (ft_fill_buff(*buf, size));
}

canonical_original_code:
static int ft_check_args_n_malloc_buf(int argc, char **argv, char **buf)
{
 unsigned long size;
 if (argc != 4)
 {
  write(2, "syntax error\n", ft_strlen("syntax error\n"));
  return (1);
 }
 size = ft_uatoi(argv[3]);
 *buf = malloc(sizeof(**buf) * (size + 1));
 if (*buf == 0)
 {
  write(2, "syntax error\n", ft_strlen("syntax error\n"));
  return (1);
 }
 return (ft_fill_buff(*buf, size));
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
buf
char **


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er8
int result; // eax
__int64 v5; // [rsp+8h] [rbp-10h] BYREF

v3 = ft_check_args_n_malloc_buf(*(void **)&argc, (__int64)argv, &v5);
result = 1;
if ( !v3 )
result = eval_expr(argv[1], argv[2], v5);
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er8
int result; // eax
__int64 v5; // [rsp+8h] [rbp-10h] BYREF

v3 = func3(*(void **)&argc, (__int64)argv, &v5);
result = 1;
if ( !v3 )
result = eval_expr(argv[1], argv[2], v5);
return result;
}

original_code:
int main(int argc, char **argv)
{
 char *buf;
 if (ft_check_args_n_malloc_buf(argc, argv, &buf))
 {
  return (1);
 }
 return (eval_expr(argv[1], argv[2], buf));
}


decompiled_code:
ssize_t __fastcall ft_putstr(void *buf, int fd)
{
_BYTE *v3; // rbx
_BYTE *v4; // rsi
ssize_t result; // rax

if ( *(_BYTE *)buf )
{
v3 = buf;
do
{
v4 = v3++;
result = write(fd, v4, 1uLL);
}
while ( *v3 );
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func0(void *buf, int fd)
{
_BYTE *v3; // rbx
_BYTE *v4; // rsi
ssize_t result; // rax

if ( *(_BYTE *)buf )
{
v3 = buf;
do
{
v4 = v3++;
result = write(fd, v4, 1uLL);
}
while ( *v3 );
}
return result;
}

original_code:
void ft_putstr(char *str, int output)
{
 while (*str)
 {
  write(output, str, 1);
  str++;
 }
}

variable_types:
str
char *

variable_types: output int


decompiled_code:
__int64 __fastcall ft_length_nbr(char *a1)
{
__int64 v1; // rax
__int64 v2; // rdx
unsigned int v3; // er8

if ( g_tab_test[*a1] < 0 )
return 0LL;
v1 = 1LL;
do
{
v2 = a1[v1];
v3 = v1++;
}
while ( g_tab_test[v2] >= 0 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
__int64 v1; // rax
__int64 v2; // rdx
unsigned int v3; // er8

if ( g_tab_test[*a1] < 0 )
return 0LL;
v1 = 1LL;
do
{
v2 = a1[v1];
v3 = v1++;
}
while ( g_tab_test[v2] >= 0 );
return v3;
}

original_code:
int ft_length_nbr(char *str)
{
 int i;
 i = 0;
 while (g_tab_test[(int)str[i]] >= 0)
 {
  i++;
 }
 return (i);
}

variable_types: i int


decompiled_code:
_BOOL8 __fastcall init_test_tab(char *a1, char *a2)
{
_BYTE *v2; // rdx
int v3; // ecx
__int64 v4; // rax
__int64 v5; // rax
int v6; // edi
int v7; // ecx

v2 = a1;
memset(g_tab_test, 0xFFu, sizeof(g_tab_test));
v3 = 0;
v4 = *a1;
if ( !(_BYTE)v4 )
{
LABEL_11:
v5 = *a2;
if ( !(_BYTE)v5 )
return 1LL;
goto LABEL_7;
}
while ( g_tab_test[v4] == -1 )
{
++v2;
g_tab_test[v4] = v3;
v4 = (char)*v2;
if ( !(_BYTE)v4 )
goto LABEL_11;
++v3;
}
v5 = *a2;
if ( (_BYTE)v5 )
{
LABEL_7:
v6 = (_DWORD)a2 - 2;
do
{
v7 = v6 - (_DWORD)a2;
if ( g_tab_test[v5] != -1 )
return 0LL;
++a2;
g_tab_test[v5] = v7;
v5 = *a2;
}
while ( (_BYTE)v5 );
}
return !*v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char *a1, char *a2)
{
_BYTE *v2; // rdx
int v3; // ecx
__int64 v4; // rax
__int64 v5; // rax
int v6; // edi
int v7; // ecx

v2 = a1;
memset(g_tab_test, 0xFFu, sizeof(g_tab_test));
v3 = 0;
v4 = *a1;
if ( !(_BYTE)v4 )
{
LABEL_11:
v5 = *a2;
if ( !(_BYTE)v5 )
return 1LL;
goto LABEL_7;
}
while ( g_tab_test[v4] == -1 )
{
++v2;
g_tab_test[v4] = v3;
v4 = (char)*v2;
if ( !(_BYTE)v4 )
goto LABEL_11;
++v3;
}
v5 = *a2;
if ( (_BYTE)v5 )
{
LABEL_7:
v6 = (_DWORD)a2 - 2;
do
{
v7 = v6 - (_DWORD)a2;
if ( g_tab_test[v5] != -1 )
return 0LL;
++a2;
g_tab_test[v5] = v7;
v5 = *a2;
}
while ( (_BYTE)v5 );
}
return !*v2;
}

original_code:
int init_test_tab(char *base, char *oper)
{
 int i;
 i = 256;
 while (i)
 {
  g_tab_test[--i] = -1;
 }
 while (*base && g_tab_test[(int)*base] == -1)
 {
  g_tab_test[(int)*base] = i++;
  base++;
 }
 i = -2;
 while (*oper && g_tab_test[(int)*oper] == -1)
 {
  g_tab_test[(int)*oper] = i--;
  oper++;
 }
 return (!*base && !*oper);
}

variable_types:
base
char *

variable_types:
oper
char *


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

result = calloc(0x800uLL, 1uLL);
result[g_plus] = &add_big;
result[g_minus] = &add_big;
result[g_mult] = &mult_big;
result[g_div] = &div_big;
result[g_mod] = &mod_big;
return result;
}

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

result = calloc(0x800uLL, 1uLL);
result[g_plus] = &add_big;
result[g_minus] = &add_big;
result[g_mult] = &mult_big;
result[g_div] = &div_big;
result[g_mod] = &mod_big;
return result;
}

original_code:
t_fbig *init_fptr()
{
 t_fbig *op;
 int i;
 op = malloc(sizeof(*op) * 256);
 i = 0;
 while (i < 256)
 {
  op[i++] = ((void *)0);
 }
 op[(int)g_plus] = &add_big;
 op[(int)g_minus] = &add_big;
 op[(int)g_mult] = &mult_big;
 op[(int)g_div] = &div_big;
 op[(int)g_mod] = &mod_big;
 return (op);
}

canonical_original_code:
struct s_big_char *(**init_fptr())(struct s_big_char *, struct s_big_char *)
{
 struct s_big_char *(**op)(struct s_big_char *, struct s_big_char *);
 int i;
 op = malloc(sizeof(*op) * 256);
 i = 0;
 while (i < 256)
 {
  op[i++] = ((void *)0);
 }
 op[(int)g_plus] = &add_big;
 op[(int)g_minus] = &add_big;
 op[(int)g_mult] = &mult_big;
 op[(int)g_div] = &div_big;
 op[(int)g_mod] = &mod_big;
 return (op);
}

variable_types: struct s_big_char { unsigned char *data; int len; int buf_len; int sgn; } *(**)(struct s_big_char *, struct s_big_char *)


decompiled_code:
ssize_t __fastcall ft_putconvert(void *buf, __int64 a2)
{
__int64 v2; // rbp
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rsi

v2 = *(int *)(a2 + 8);
if ( (_DWORD)v2 )
{
if ( *(_DWORD *)(a2 + 16) == -1 )
write(1, &unk_678, 1uLL);
v4 = (int)v2 - 1;
v5 = v2 - 2 - (unsigned int)(v2 - 1);
do
{
v6 = *(unsigned __int8 *)(*(_QWORD *)a2 + v4--);
write(1, (char *)buf + v6, 1uLL);
}
while ( v5 != v4 );
}
else
{
write(1, buf, 1uLL);
}
return write(1, &unk_67A, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func4(void *buf, __int64 a2)
{
__int64 v2; // rbp
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rsi

v2 = *(int *)(a2 + 8);
if ( (_DWORD)v2 )
{
if ( *(_DWORD *)(a2 + 16) == -1 )
write(1, &unk_678, 1uLL);
v4 = (int)v2 - 1;
v5 = v2 - 2 - (unsigned int)(v2 - 1);
do
{
v6 = *(unsigned __int8 *)(*(_QWORD *)a2 + v4--);
write(1, (char *)buf + v6, 1uLL);
}
while ( v5 != v4 );
}
else
{
write(1, buf, 1uLL);
}
return write(1, &unk_67A, 1uLL);
}

original_code:
void ft_putconvert(char *base, t_big a)
{
 int i;
 i = a->len;
 if (a->len == 0)
 {
  write(1, base, 1);
 }
 else if (a->sgn == -1)
 {
  write(1, "-", 1);
 }
 while (i--)
 {
  write(1, &base[(int)(a->data[i])], 1);
 }
 write(1, "\n", 1);
}

canonical_original_code:
void ft_putconvert(char *base, struct s_big_char *a)
{
 int i;
 i = a->len;
 if (a->len == 0)
 {
  write(1, base, 1);
 }
 else if (a->sgn == -1)
 {
  write(1, "-", 1);
 }
 while (i--)
 {
  write(1, &base[(int)(a->data[i])], 1);
 }
 write(1, "\n", 1);
}

variable_types: struct s_big_char { unsigned char *data; int len; int buf_len; int sgn; } *


decompiled_code:
__int64 __fastcall calc_digit(unsigned __int8 *a1, int a2)
{
int v2; // eax
int v3; // edx

v2 = ((unsigned __int8)g_base * (a1[1] + (unsigned __int8)g_base * a1[2]) + *a1 + 1) / a2;
v3 = ((unsigned __int8)g_base * (a1[1] + (unsigned __int8)g_base * a1[2]) + *a1 + 1) % a2;
LOBYTE(v3) = (unsigned __int8)g_base <= v2;
return (unsigned int)(v2 - v3);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, int a2)
{
int v2; // eax
int v3; // edx

v2 = ((unsigned __int8)g_base * (a1[1] + (unsigned __int8)g_base * a1[2]) + *a1 + 1) / a2;
v3 = ((unsigned __int8)g_base * (a1[1] + (unsigned __int8)g_base * a1[2]) + *a1 + 1) % a2;
LOBYTE(v3) = (unsigned __int8)g_base <= v2;
return (unsigned int)(v2 - v3);
}

original_code:
t_uchar calc_digit(t_uchar *lead_a, int lead_b)
{
 int digit;
 digit = ((lead_a[2] * g_base + lead_a[1]) * g_base
  + *lead_a + 1) / lead_b;
 return (digit >= g_base ? digit - 1 : digit);
}

canonical_original_code:
unsigned char calc_digit(unsigned char *lead_a, int lead_b)
{
 int digit;
 digit = ((lead_a[2] * g_base + lead_a[1]) * g_base
  + *lead_a + 1) / lead_b;
 return (digit >= g_base ? digit - 1 : digit);
}

variable_types: digit int

return_type: unsigned char


decompiled_code:
__int64 __fastcall divmod_data(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbp
unsigned __int8 *v5; // rax
int v6; // er12
__int64 result; // rax
unsigned int v8; // ebx
__int64 v10; // r15
__int64 v11; // rbp
bool v12; // cf
unsigned __int8 *v13; // rdi
unsigned int v14; // eax
__int64 v15; // rdx
__int64 v16; // rcx
__int64 v17; // rax
unsigned __int64 v18; // rax
__int64 v19; // rdx
unsigned __int64 v20; // rax
__int64 v21; // rax
unsigned __int8 v22; // [rsp+7h] [rbp-41h]
char v23; // [rsp+7h] [rbp-41h]

v4 = *(int *)(a3 + 8);
v5 = (unsigned __int8 *)(**(_QWORD **)(a2 + 8) + *(int *)(*(_QWORD *)(a2 + 8) + 8LL) - 2LL);
v6 = *v5 + (unsigned __int8)g_base * v5[1];
result = *(int *)(a1 + 8);
if ( (_DWORD)v4 )
{
v8 = v4 - 1;
v10 = *(_QWORD *)a1 + result - 2;
v11 = v4 - v10;
do
{
while ( 1 )
{
v13 = (unsigned __int8 *)v10--;
v14 = calc_digit(v13, v6);
LOBYTE(v16) = v14;
if ( (_BYTE)v14 )
{
v22 = v14;
v17 = get_mult((unsigned __int8)v14, a2, v15, v14);
v18 = cmp_big(a1, v17, v8);
v16 = v22;
v20 = v18 >> 63;
LOBYTE(v16) = v22 - v20;
if ( v22 != (_BYTE)v20 )
break;
}
result = v10 + *(_QWORD *)a3;
*(_BYTE *)(result + v11) = v16;
v12 = v8-- == 0;
if ( v12 )
return result;
}
v23 = v22 - v20;
v21 = get_mult((unsigned __int8)v16, a2, v19, v16);
offset_sub(a1, v21, v8);
adjust_length(a1);
result = v10 + *(_QWORD *)a3;
*(_BYTE *)(result + v11) = v23;
v12 = v8-- == 0;
}
while ( !v12 );
}
return result;
}

original_code:
void divmod_data(t_big a, t_big *mult_b, t_big res)
{
 t_big m;
 t_uchar digit;
 int offset;
 t_uchar *lead_a;
 int lead_b;
 lead_a = mult_b[1]->data + mult_b[1]->len - 2;
 lead_b = lead_a[1] * g_base + lead_a[0];
 offset = res->len;
 lead_a = (t_uchar*)(a->data + a->len - 2);
 while (offset--)
 {
  if ((digit = calc_digit(lead_a--, lead_b)))
  {
   m = get_mult(digit, mult_b);
   digit -= cmp_big(a, m, offset) < 0;
   if (digit)
   {
    m = get_mult(digit, mult_b);
    offset_sub(a, m, offset);
    adjust_length(a);
   }
  }
  res->data[offset] = digit;
 }
}

canonical_original_code:
void divmod_data(struct s_big_char *a, struct s_big_char **mult_b, struct s_big_char *res)
{
 struct s_big_char *m;
 unsigned char digit;
 int offset;
 unsigned char *lead_a;
 int lead_b;
 lead_a = mult_b[1]->data + mult_b[1]->len - 2;
 lead_b = lead_a[1] * g_base + lead_a[0];
 offset = res->len;
 lead_a = (unsigned char *)(a->data + a->len - 2);
 while (offset--)
 {
  if ((digit = calc_digit(lead_a--, lead_b)))
  {
   m = get_mult(digit, mult_b);
   digit -= cmp_big(a, m, offset) < 0;
   if (digit)
   {
    m = get_mult(digit, mult_b);
    offset_sub(a, m, offset);
    adjust_length(a);
   }
  }
  res->data[offset] = digit;
 }
}

variable_types:
res
struct s_big_char *

variable_types:
digit
unsigned char

variable_types: offset int

user_defined_types: struct s_big_char { unsigned char *data; int len; int buf_len; int sgn; }


decompiled_code:
__int64 __fastcall divmod_big(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r12
__int64 v4; // [rsp+0h] [rbp-20h]

result = g_zero_big;
if ( *(_DWORD *)(a1 + 8) >= *(_DWORD *)(a2 + 8) )
{
v3 = create_table(a2);
v4 = create_big((unsigned int)(*(_DWORD *)(a1 + 8) - *(_DWORD *)(a2 + 8) + 1), 0LL);
*(_DWORD *)(v4 + 16) = *(_DWORD *)(a2 + 16) * *(_DWORD *)(a1 + 16);
divmod_data(a1, v3, v4);
destruct_table(v3);
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r12
__int64 v4; // [rsp+0h] [rbp-20h]

result = g_zero_big;
if ( *(_DWORD *)(a1 + 8) >= *(_DWORD *)(a2 + 8) )
{
v3 = create_table(a2);
v4 = create_big((unsigned int)(*(_DWORD *)(a1 + 8) - *(_DWORD *)(a2 + 8) + 1), 0LL);
*(_DWORD *)(v4 + 16) = *(_DWORD *)(a2 + 16) * *(_DWORD *)(a1 + 16);
func1(a1, v3, v4);
destruct_table(v3);
result = v4;
}
return result;
}

original_code:
t_big divmod_big(t_big a, t_big b)
{
 t_big *mult_b;
 t_big res;
 if (a->len >= b->len)
 {
  mult_b = create_table(b);
  res = create_big(a->len - b->len + 1, 0);
  res->sgn = a->sgn * b->sgn;
  divmod_data(a, mult_b, res);
  destruct_table(mult_b);
  return (res);
 }
 return (g_zero_big);
}

canonical_original_code:
struct s_big_char *divmod_big(struct s_big_char *a, struct s_big_char *b)
{
 struct s_big_char **mult_b;
 struct s_big_char *res;
 if (a->len >= b->len)
 {
  mult_b = create_table(b);
  res = create_big(a->len - b->len + 1, 0);
  res->sgn = a->sgn * b->sgn;
  divmod_data(a, mult_b, res);
  destruct_table(mult_b);
  return (res);
 }
 return (g_zero_big);
}

variable_types:
a
struct s_big_char *

variable_types:
b
struct s_big_char *

variable_types: struct s_big_char { unsigned char *data; int len; int buf_len; int sgn; } **


decompiled_code:
__int64 __fastcall div_big(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = 0LL;
if ( *(_DWORD *)(a2 + 8) )
{
v2 = divmod_big(a1, a2);
adjust_length(v2);
destruct_big(a1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = 0LL;
if ( *(_DWORD *)(a2 + 8) )
{
v2 = func2(a1, a2);
adjust_length(v2);
destruct_big(a1);
}
return v2;
}

original_code:
t_big div_big(t_big a, t_big b)
{
 t_big res;
 if (b->len == 0)
 {
  return (((void *)0));
 }
 res = divmod_big(a, b);
 adjust_length(res);
 destruct_big(a);
 return (res);
}

canonical_original_code:
struct s_big_char *div_big(struct s_big_char *a, struct s_big_char *b)
{
 struct s_big_char *res;
 if (b->len == 0)
 {
  return (((void *)0));
 }
 res = divmod_big(a, b);
 adjust_length(res);
 destruct_big(a);
 return (res);
}

return_type: struct s_big_char { unsigned char *data; int len; int buf_len; int sgn; } *


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

if ( !*(_DWORD *)(a2 + 8) )
return 0LL;
v2 = divmod_big(a1, a2);
destruct_big(v2);
adjust_length(a1);
return a1;
}

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

if ( !*(_DWORD *)(a2 + 8) )
return 0LL;
v2 = func2(a1, a2);
destruct_big(v2);
adjust_length(a1);
return a1;
}

original_code:
t_big mod_big(t_big a, t_big b)
{
 if (b->len == 0)
 {
  return (((void *)0));
 }
 destruct_big(divmod_big(a, b));
 adjust_length(a);
 return (a);
}

canonical_original_code:
struct s_big_char *mod_big(struct s_big_char *a, struct s_big_char *b)
{
 if (b->len == 0)
 {
  return (((void *)0));
 }
 destruct_big(divmod_big(a, b));
 adjust_length(a);
 return (a);
}


original_code:
t_big read_struct(t_elem elem)
{
 t_big res;
 char *digit;
 int n;
 t_uchar *data;
 res = create_big(elem->len, 0);
 data = res->data;
 res->sgn = elem->sgn;
 n = elem->len;
 digit = elem->start + n - 1;
 while (n--)
 {
  *data = *digit;
  digit--;
  data++;
 }
 return (res);
}

canonical_original_code:
struct s_big_char *read_struct(struct s_element *elem)
{
 struct s_big_char *res;
 char *digit;
 int n;
 unsigned char *data;
 res = create_big(elem->len, 0);
 data = res->data;
 res->sgn = elem->sgn;
 n = elem->len;
 digit = elem->start + n - 1;
 while (n--)
 {
  *data = *digit;
  digit--;
  data++;
 }
 return (res);
}

variable_types: struct s_element { int sgn; struct s_element *a; struct s_element *b; struct s_big_char *(*op)(struct s_big_char *, struct s_big_char *); char *start; int len; } *

variable_types:
digit
char *

variable_types: n int

variable_types:
data
unsigned char *


original_code:
void offset_add(t_big a, t_big b, int offset)
{
 add_data((t_ulong*)(a->data + offset), (t_ulong*)b->data, (((t_ulong*)b->data) + (((b)->len + 7) >> 3)));
}

canonical_original_code:
void offset_add(struct s_big_char *a, struct s_big_char *b, int offset)
{
 add_data((unsigned long long *)(a->data + offset), (unsigned long long *)b->data, (((unsigned long long *)b->data) + (((b)->len + 7) >> 3)));
}


decompiled_code:
unsigned __int64 __fastcall offset_sub(_QWORD *a1, __int64 a2, int a3)
{
return sub_data((__int64 *)(*a1 + a3), *(char **)a2, (char *)(*(_QWORD *)a2 + 8LL * ((*(_DWORD *)(a2 + 8) + 7) >> 3)));
}

original_code:
void offset_sub(t_big a, t_big b, int offset)
{
 sub_data((t_ulong*)(a->data + offset), (t_ulong*)b->data, (((t_ulong*)b->data) + (((b)->len + 7) >> 3)));
}

canonical_original_code:
void offset_sub(struct s_big_char *a, struct s_big_char *b, int offset)
{
 sub_data((unsigned long long *)(a->data + offset), (unsigned long long *)b->data, (((unsigned long long *)b->data) + (((b)->len + 7) >> 3)));
}


eval

original_code:
t_big eval(t_elem elem)
{
 t_big res;
 if (!elem->op)
 {
  return (read_struct(elem));
 }
 res = elem->op(eval(elem->a), eval(elem->b));
 res->sgn *= elem->sgn;
 return (res);
}

canonical_original_code:
struct s_big_char *eval(struct s_element *elem)
{
 struct s_big_char *res;
 if (!elem->op)
 {
  return (read_struct(elem));
 }
 res = elem->op(eval(elem->a), eval(elem->b));
 res->sgn *= elem->sgn;
 return (res);
}

user_defined_types: struct s_element { int sgn; struct s_element *a; struct s_element *b; struct s_big_char *(*op)(struct s_big_char *, struct s_big_char *); char *start; int len; }


decompiled_code:
__int64 __fastcall ft_strlen2(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

if ( !*a1 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // er8

if ( !*a1 )
return 0LL;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int ft_strlen2(char *strlen)
{
 int i;
 i = 0;
 while (strlen[i] != 0)
 {
  i = i + 1;
 }
 return (i);
}

variable_types:
strlen
char *


decompiled_code:
__int64 __fastcall init_global(_BYTE *a1, char *a2)
{
__int64 v2; // rdx
__int64 v3; // rax
__int64 result; // rax

g_base = ft_strlen2(a1);
g_compl = -g_base;
g_compl_8 = v2 * (unsigned __int8)-g_base;
v3 = create_big(0LL, 0LL);
g_oper = (__int64)a2;
g_zero_big = v3;
g_little_endian = 1;
g_bra = *a2;
g_ket = a2[1];
g_plus = a2[2];
g_minus = a2[3];
g_mult = a2[4];
g_div = a2[5];
result = (unsigned __int8)a2[6];
g_mod = a2[6];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, char *a2)
{
__int64 v2; // rdx
__int64 v3; // rax
__int64 result; // rax

g_base = func1(a1);
g_compl = -g_base;
g_compl_8 = v2 * (unsigned __int8)-g_base;
v3 = create_big(0LL, 0LL);
g_oper = (__int64)a2;
g_zero_big = v3;
g_little_endian = 1;
g_bra = *a2;
g_ket = a2[1];
g_plus = a2[2];
g_minus = a2[3];
g_mult = a2[4];
g_div = a2[5];
result = (unsigned __int8)a2[6];
g_mod = a2[6];
return result;
}

original_code:
void init_global(char *base, char *oper)
{
 t_ulong ul1;
 ul1= 1ULL;
 g_base = ft_strlen2(base);
 g_compl = 256 - g_base;
 g_compl_8 = g_compl * 0x0101010101010101;
 g_zero_big = create_big(0, 0);
 g_little_endian = *(char*)&ul1;
 g_oper = oper;
 g_bra = oper[0];
 g_ket = oper[1];
 g_plus = oper[2];
 g_minus = oper[3];
 g_mult = oper[4];
 g_div = oper[5];
 g_mod = oper[6];
}

canonical_original_code:
void init_global(char *base, char *oper)
{
 unsigned long long ul1;
 ul1= 1ULL;
 g_base = ft_strlen2(base);
 g_compl = 256 - g_base;
 g_compl_8 = g_compl * 0x0101010101010101;
 g_zero_big = create_big(0, 0);
 g_little_endian = *(char *)&ul1;
 g_oper = oper;
 g_bra = oper[0];
 g_ket = oper[1];
 g_plus = oper[2];
 g_minus = oper[3];
 g_mult = oper[4];
 g_div = oper[5];
 g_mod = oper[6];
}


decompiled_code:
__int64 __fastcall eval_expr(_BYTE *a1, char *a2, __int64 a3)
{
__int64 v4; // rdi
__int64 v5; // rdi
__int64 v6; // rax
__int64 result; // rax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v8[0] = a3;
if ( (unsigned int)init_test_tab()
&& (init_global(a1, a2), g_op = init_fptr(), (v4 = parse(v8)) != 0)
&& (v5 = parse_op(v4, v8, 0LL)) != 0 )
{
v6 = eval(v5);
ft_putconvert(a1, v6);
result = 0LL;
}
else
{
ft_putstr("syntax error\n", 2LL);
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1, char *a2, __int64 a3)
{
__int64 v4; // rdi
__int64 v5; // rdi
__int64 v6; // rax
__int64 result; // rax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v8[0] = a3;
if ( (unsigned int)init_test_tab()
&& (func2(a1, a2), g_op = init_fptr(), (v4 = parse(v8)) != 0)
&& (v5 = parse_op(v4, v8, 0LL)) != 0 )
{
v6 = func0(v5);
ft_putconvert(a1, v6);
result = 0LL;
}
else
{
ft_putstr("syntax error\n", 2LL);
result = 2LL;
}
return result;
}

original_code:
int eval_expr(char *base, char *oper, char *str)
{
 t_elem parsed;
 if (init_test_tab(base, oper))
 {
  init_global(base, oper);
  g_op = init_fptr();
  parsed = parse(&str);
  if (parsed)
  {
   parsed = parse_op(parsed, &str, '\0');
   if (parsed)
   {
    ft_putconvert(base, eval(parsed));
    return (0);
   }
  }
 }
 ft_putstr("syntax error\n", 2);
 return (2);
}

canonical_original_code:
int eval_expr(char *base, char *oper, char *str)
{
 struct s_element *parsed;
 if (init_test_tab(base, oper))
 {
  init_global(base, oper);
  g_op = init_fptr();
  parsed = parse(&str);
  if (parsed)
  {
   parsed = parse_op(parsed, &str, '\0');
   if (parsed)
   {
    ft_putconvert(base, eval(parsed));
    return (0);
   }
  }
 }
 ft_putstr("syntax error\n", 2);
 return (2);
}

variable_types:
str
char *

variable_types: struct s_element { int sgn; struct s_element *a; struct s_element *b; struct s_big_char { unsigned char *data; int len; int buf_len; int sgn; } *(*op)(struct s_big_char *, struct s_big_char *); char *start; int len; } *


decompiled_code:
__int64 __fastcall destruct_table(__int64 a1)
{
__int64 v1; // rbx
__int64 v3; // rdi
__int64 result; // rax

LODWORD(v1) = (unsigned __int8)g_base - 1;
if ( g_base != 1 )
{
v1 = (int)v1;
do
{
v3 = *(_QWORD *)(a1 + 8 * v1--);
result = destruct_big(v3);
}
while ( (_DWORD)v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
__int64 v3; // rdi
__int64 result; // rax

LODWORD(v1) = (unsigned __int8)g_base - 1;
if ( g_base != 1 )
{
v1 = (int)v1;
do
{
v3 = *(_QWORD *)(a1 + 8 * v1--);
result = destruct_big(v3);
}
while ( (_DWORD)v1 );
}
return result;
}

original_code:
void destruct_table(t_big *table)
{
 int i;
 i = g_base;
 while (--i)
 {
  destruct_big(table[i]);
 }
}

canonical_original_code:
void destruct_table(struct s_big_char **table)
{
 int i;
 i = g_base;
 while (--i)
 {
  destruct_big(table[i]);
 }
}

variable_types: i int


decompiled_code:
__int64 __fastcall get_mult(unsigned __int8 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v4; // rax
__int64 v5; // r12
__int64 v6; // rax

v2 = a2 + 8LL * a1;
if ( *(_QWORD *)v2 )
return *(_QWORD *)v2;
v4 = get_mult((unsigned __int8)((a1 >> 1) + (a1 & 1)));
v5 = cp_big(v4);
v6 = get_mult(a1 >> 1);
offset_add(v5, v6, 0LL);
adjust_length(v5);
*(_QWORD *)v2 = v5;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v4; // rax
__int64 v5; // r12
__int64 v6; // rax

v2 = a2 + 8LL * a1;
if ( *(_QWORD *)v2 )
return *(_QWORD *)v2;
v4 = func1((unsigned __int8)((a1 >> 1) + (a1 & 1)));
v5 = cp_big(v4);
v6 = func1(a1 >> 1);
offset_add(v5, v6, 0LL);
adjust_length(v5);
*(_QWORD *)v2 = v5;
return v5;
}

original_code:
t_big get_mult(t_uchar c, t_big *table)
{
 t_big half;
 if (!table[c])
 {
  half = cp_big(get_mult((c >> 1) + (c & 1), table));
  offset_add(half, get_mult(c >> 1, table), 0);
  adjust_length(half);
  table[c] = half;
 }
 return (table[c]);
}

canonical_original_code:
struct s_big_char *get_mult(unsigned char c, struct s_big_char **table)
{
 struct s_big_char *half;
 if (!table[c])
 {
  half = cp_big(get_mult((c >> 1) + (c & 1), table));
  offset_add(half, get_mult(c >> 1, table), 0);
  adjust_length(half);
  table[c] = half;
 }
 return (table[c]);
}

variable_types:
c
unsigned char

variable_types:
table
struct s_big_char **


original_code:
long long cmp_big(t_big a, t_big b, int offset)
{
 t_ulong *ia;
 t_ulong *ib;
 t_ulong *end;
 int res;
 res = a->len - b->len - offset;
 if (res == 0)
 {
  ia = (t_ulong*)(a->data + a->len) - 1;
  ib = (t_ulong*)(b->data + b->len) - 1;
  end = ib - ((b->len - 1) >> 3);
  while (ib != end && *ia == *ib)
  {
   ia--;
   ib--;
  }
  return (*ia - *ib);
 }
 return (res);
}

canonical_original_code:
long long cmp_big(struct s_big_char *a, struct s_big_char *b, int offset)
{
 unsigned long long *ia;
 unsigned long long *ib;
 unsigned long long *end;
 int res;
 res = a->len - b->len - offset;
 if (res == 0)
 {
  ia = (unsigned long long *)(a->data + a->len) - 1;
  ib = (unsigned long long *)(b->data + b->len) - 1;
  end = ib - ((b->len - 1) >> 3);
  while (ib != end && *ia == *ib)
  {
   ia--;
   ib--;
  }
  return (*ia - *ib);
 }
 return (res);
}

variable_types: struct s_big_char { unsigned char *data; int len; int buf_len; int sgn; } *

variable_types:
ia
unsigned long long *

variable_types:
ib
unsigned long long *

variable_types:
end
unsigned long long *

variable_types: res int

return_type: long long


decompiled_code:
void __fastcall destruct_big(void *ptr)
{
if ( ptr )
{
if ( (void *)g_zero_big != ptr )
{
free((void *)(*(_QWORD *)ptr - 8LL));
free(ptr);
}
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
if ( (void *)g_zero_big != ptr )
{
free((void *)(*(_QWORD *)ptr - 8LL));
free(ptr);
}
}
}

original_code:
void destruct_big(t_big x)
{
 if (x && x != g_zero_big)
 {
  free(x->data - 8);
  free(x);
 }
}

canonical_original_code:
void destruct_big(struct s_big_char *x)
{
 if (x && x != g_zero_big)
 {
  free(x->data - 8);
  free(x);
 }
}


decompiled_code:
__int64 __fastcall adjust_length(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx
__int64 v4; // rdx

result = *((int *)a1 + 2);
v2 = *a1;
v3 = result;
if ( *(_BYTE *)(*a1 + result) )
{
result = (int)result + 1;
do
{
*((_DWORD *)a1 + 2) = result;
v3 = (int)result++;
}
while ( *(_BYTE *)(v2 + result - 1) );
}
if ( (_DWORD)v3 )
{
result = (int)v3 - 1;
v4 = v3 - 2 - (unsigned int)(v3 - 1);
do
{
if ( *(_BYTE *)(v2 + result) )
break;
*((_DWORD *)a1 + 2) = result--;
}
while ( v4 != result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx
__int64 v4; // rdx

result = *((int *)a1 + 2);
v2 = *a1;
v3 = result;
if ( *(_BYTE *)(*a1 + result) )
{
result = (int)result + 1;
do
{
*((_DWORD *)a1 + 2) = result;
v3 = (int)result++;
}
while ( *(_BYTE *)(v2 + result - 1) );
}
if ( (_DWORD)v3 )
{
result = (int)v3 - 1;
v4 = v3 - 2 - (unsigned int)(v3 - 1);
do
{
if ( *(_BYTE *)(v2 + result) )
break;
*((_DWORD *)a1 + 2) = result--;
}
while ( v4 != result );
}
return result;
}

original_code:
void adjust_length(t_big x)
{
 while (x->data[x->len])
 {
  x->len++;
 }
 while (x->len && !x->data[x->len - 1])
 {
  x->len--;
 }
}

canonical_original_code:
void adjust_length(struct s_big_char *x)
{
 while (x->data[x->len])
 {
  x->len++;
 }
 while (x->len && !x->data[x->len - 1])
 {
  x->len--;
 }
}


original_code:
t_big mult_big(t_big a, t_big b)
{
 t_big *mult_a;
 t_big res;
 if (b->len > a->len)
 {
  return (mult_big(b, a));
 }
 if (b->len == 0)
 {
  return (g_zero_big);
 }
 mult_a = create_table(a);
 res = create_big(a->len + b->len + 1, 1);
 res->sgn = a->sgn * b->sgn;
 mult_data(mult_a, b, res);
 destruct_table(mult_a);
 destruct_big(b);
 adjust_length(res);
 return (res);
}

canonical_original_code:
struct s_big_char *mult_big(struct s_big_char *a, struct s_big_char *b)
{
 struct s_big_char **mult_a;
 struct s_big_char *res;
 if (b->len > a->len)
 {
  return (mult_big(b, a));
 }
 if (b->len == 0)
 {
  return (g_zero_big);
 }
 mult_a = create_table(a);
 res = create_big(a->len + b->len + 1, 1);
 res->sgn = a->sgn * b->sgn;
 mult_data(mult_a, b, res);
 destruct_table(mult_a);
 destruct_big(b);
 adjust_length(res);
 return (res);
}

variable_types:
a
struct s_big_char *

variable_types:
b
struct s_big_char *


decompiled_code:
__int64 __fastcall read_sgn(_BYTE **a1)
{
_BYTE *v1; // rax
unsigned int v2; // er8

v1 = *a1;
v2 = 1;
while ( *v1 == g_plus )
{
if ( g_plus == g_minus )
goto LABEL_3;
LABEL_4:
++v1;
}
if ( *v1 == g_minus )
{
LABEL_3:
v2 = -v2;
goto LABEL_4;
}
*a1 = v1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE **a1)
{
_BYTE *v1; // rax
unsigned int v2; // er8

v1 = *a1;
v2 = 1;
while ( *v1 == g_plus )
{
if ( g_plus == g_minus )
goto LABEL_3;
LABEL_4:
++v1;
}
if ( *v1 == g_minus )
{
LABEL_3:
v2 = -v2;
goto LABEL_4;
}
*a1 = v1;
return v2;
}

original_code:
int read_sgn(char **res)
{
 int sign;
 char *str;
 str = *res;
 sign = 1;
 while (*str == g_plus || *str == g_minus)
 {
  if (*str == g_minus)
  {
   sign = -sign;
  }
  str++;
 }
 *res = str;
 return (sign);
}

variable_types:
res
char **

variable_types: sign int


decompiled_code:
__int64 __fastcall parse_op(__int64 a1, char **a2, char a3)
{
char v3; // r12
char *v4; // rax
__int64 v5; // rdx
void *v6; // r14
__int64 v7; // rax
__int64 v8; // rax

while ( 1 )
{
v3 = a3;
v4 = *a2;
v5 = **a2;
if ( (_BYTE)v5 == v3 )
break;
v6 = *(void **)(g_op + 8 * v5);
if ( !v6 )
return 0LL;
*a2 = &v4[v6 != &add_big];
v7 = parse(a2);
if ( !v7 )
return 0LL;
if ( v6 == &add_big )
{
v7 = parse_prio(v7, a2, (unsigned int)v3);
if ( !v7 )
return 0LL;
}
v8 = create_elem(a1, v7, v6);
a3 = v3;
a1 = v8;
}
*a2 = v4 + 1;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char **a2, char a3)
{
char v3; // r12
char *v4; // rax
__int64 v5; // rdx
void *v6; // r14
__int64 v7; // rax
__int64 v8; // rax

while ( 1 )
{
v3 = a3;
v4 = *a2;
v5 = **a2;
if ( (_BYTE)v5 == v3 )
break;
v6 = *(void **)(g_op + 8 * v5);
if ( !v6 )
return 0LL;
*a2 = &v4[v6 != &add_big];
v7 = parse(a2);
if ( !v7 )
return 0LL;
if ( v6 == &add_big )
{
v7 = func1(v7, a2, (unsigned int)v3);
if ( !v7 )
return 0LL;
}
v8 = create_elem(a1, v7, v6);
a3 = v3;
a1 = v8;
}
*a2 = v4 + 1;
return a1;
}

original_code:
t_elem parse_op(t_elem a, char **str, char close)
{
 t_elem b;
 t_fbig op;
 if (**str == close)
 {
  (*str)++;
  return (a);
 }
 op = g_op[(int)**str];
 if (op)
 {
  (*str) += op != add_big;
  b = parse(str);
  if (b)
  {
   b = (op == add_big) ? parse_prio(b, str, close) : b;
   return (b ? parse_op(create_elem(a, b, op), str, close) : ((void *)0));
  }
 }
 return (((void *)0));
}

canonical_original_code:
struct s_element *parse_op(struct s_element *a, char **str, char close)
{
 struct s_element *b;
 struct s_big_char *(*op)(struct s_big_char *, struct s_big_char *);
 if (**str == close)
 {
  (*str)++;
  return (a);
 }
 op = g_op[(int)**str];
 if (op)
 {
  (*str) += op != add_big;
  b = parse(str);
  if (b)
  {
   b = (op == add_big) ? parse_prio(b, str, close) : b;
   return (b ? parse_op(create_elem(a, b, op), str, close) : ((void *)0));
  }
 }
 return (((void *)0));
}

variable_types:
a
struct s_element *

variable_types:
str
char **

variable_types: close char

variable_types: struct s_big_char { unsigned char *data; int len; int buf_len; int sgn; } *(*)(struct s_big_char *, struct s_big_char *)

return_type: struct s_element { int sgn; struct s_element *a; struct s_element *b; struct s_big_char { unsigned char *data; int len; int buf_len; int sgn; } *(*op)(struct s_big_char *, struct s_big_char *); char *start; int len; } *


decompiled_code:
__int64 __fastcall parse_prio(__int64 a1, char **a2, char a3)
{
char **v3; // rbp
char v4; // bl
char *v5; // rax
__int64 v6; // rsi
void *v7; // r12
_DWORD *v8; // rax
char v9; // dl
__int64 result; // rax
__int64 v11; // rax

while ( 1 )
{
v3 = a2;
v4 = a3;
v5 = *a2;
v6 = **a2;
v7 = *(void **)(g_op + 8 * v6);
if ( !v7 )
break;
if ( v7 == &add_big )
return a1;
*v3 = v5 + 1;
v8 = parse(v3);
if ( !v8 )
{
v9 = **v3;
goto LABEL_5;
}
v11 = create_elem(a1, v8, v7);
a3 = v4;
a2 = v3;
a1 = v11;
}
v9 = v6;
LABEL_5:
result = 0LL;
if ( v4 != v9 )
return result;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char **a2, char a3)
{
char **v3; // rbp
char v4; // bl
char *v5; // rax
__int64 v6; // rsi
void *v7; // r12
_DWORD *v8; // rax
char v9; // dl
__int64 result; // rax
__int64 v11; // rax

while ( 1 )
{
v3 = a2;
v4 = a3;
v5 = *a2;
v6 = **a2;
v7 = *(void **)(g_op + 8 * v6);
if ( !v7 )
break;
if ( v7 == &add_big )
return a1;
*v3 = v5 + 1;
v8 = parse(v3);
if ( !v8 )
{
v9 = **v3;
goto LABEL_5;
}
v11 = create_elem(a1, v8, v7);
a3 = v4;
a2 = v3;
a1 = v11;
}
v9 = v6;
LABEL_5:
result = 0LL;
if ( v4 != v9 )
return result;
return a1;
}

original_code:
t_elem parse_prio(t_elem a, char **str, char close)
{
 t_fbig op;
 t_elem b;
 op = g_op[(int)(**str)];
 if (op)
 {
  if (op == add_big)
  {
   return (a);
  }
  (*str)++;
  b = parse(str);
  if (b)
  {
   return (parse_prio(create_elem(a, b, op), str, close));
  }
 }
 return (**str == close ? a : ((void *)0));
}

canonical_original_code:
struct s_element *parse_prio(struct s_element *a, char **str, char close)
{
 struct s_big_char *(*op)(struct s_big_char *, struct s_big_char *);
 struct s_element *b;
 op = g_op[(int)(**str)];
 if (op)
 {
  if (op == add_big)
  {
   return (a);
  }
  (*str)++;
  b = parse(str);
  if (b)
  {
   return (parse_prio(create_elem(a, b, op), str, close));
  }
 }
 return (**str == close ? a : ((void *)0));
}

variable_types: struct s_element { int sgn; struct s_element *a; struct s_element *b; struct s_big_char { unsigned char *data; int len; int buf_len; int sgn; } *(*op)(struct s_big_char *, struct s_big_char *); char *start; int len; } *


repo: magusbr/brickoptimizer

variable_types: struct mask_t { unsigned long m[10]; } *

variable_types:
mt
struct mask_t { unsigned long m[10]; }


decompiled_code:
int __fastcall mask_bitwise_print(__int64 *a1)
{
__int64 *v1; // rbx
__int64 v2; // rsi

v1 = a1;
do
{
v2 = *v1++;
printf("%lu", v2);
}
while ( v1 != a1 + 10 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(__int64 *a1)
{
__int64 *v1; // rbx
__int64 v2; // rsi

v1 = a1;
do
{
v2 = *v1++;
printf("%lu", v2);
}
while ( v1 != a1 + 10 );
return putchar(10);
}

original_code:
void mask_bitwise_print(mask_t* ptr)
{
 int i;
 for (i = 0; i < 10; i++)
 {
  printf("%" "l" "u", ptr->m[i]);
 }
 printf("\n");
}

canonical_original_code:
void mask_bitwise_print(struct mask_t *ptr)
{
 int i;
 for (i = 0; i < 10; i++)
 {
  printf("%" "l" "u", ptr->m[i]);
 }
 printf("\n");
}

variable_types: i int


repo: mahkoh/scrot

decompiled_code:
// attributes: thunk
__int64 image_init()
{
return image_X11_init();
}

canonical_decompiled_code:
__int64 func0()
{
return image_X11_init();
}

original_code:
void image_init(void)
{
 image_X11_init();
}

canonical_original_code:
void image_init()
{
 image_X11_init();
}


decompiled_code:
// attributes: thunk
__int64 image_from_screen()
{
return image_X11_from_screen();
}

canonical_decompiled_code:
__int64 func1()
{
return image_X11_from_screen();
}

original_code:
Image image_from_screen(void)
{
 return image_X11_from_screen();
}

canonical_original_code:
void *image_from_screen()
{
 return image_X11_from_screen();
}

return_type: void *


decompiled_code:
// attributes: thunk
__int64 image_from_area()
{
return image_X11_from_area();
}

canonical_decompiled_code:
__int64 func2()
{
return image_X11_from_area();
}

original_code:
Image image_from_area(struct Area *area)
{
 return image_X11_from_area(area);
}

canonical_original_code:
void *image_from_area(struct Area *area)
{
 return image_X11_from_area(area);
}

variable_types: struct Area { int x; int y; int width; int height; } *


decompiled_code:
__int64 image_width()
{
imlib_context_set_image();
return imlib_image_get_width();
}

canonical_decompiled_code:
__int64 func3()
{
imlib_context_set_image();
return imlib_image_get_width();
}

original_code:
int image_width(Image image)
{
 imlib_context_set_image(image);
 return imlib_image_get_width();
}

canonical_original_code:
int image_width(void *image)
{
 imlib_context_set_image(image);
 return imlib_image_get_width();
}

variable_types:
image
void *


decompiled_code:
__int64 image_height()
{
imlib_context_set_image();
return imlib_image_get_height();
}

canonical_decompiled_code:
__int64 func4()
{
imlib_context_set_image();
return imlib_image_get_height();
}

original_code:
int image_height(Image image)
{
 imlib_context_set_image(image);
 return imlib_image_get_height();
}

canonical_original_code:
int image_height(void *image)
{
 imlib_context_set_image(image);
 return imlib_image_get_height();
}


decompiled_code:
__int64 __fastcall image_concat(__int64 a1, int a2)
{
signed __int64 v2; // rax
void *v3; // rsp
void *v4; // rsp
__int64 v6; // r12
unsigned int v7; // er13
int v8; // eax
int v9; // eax
int v10; // ecx
unsigned int v11; // er12
__int64 v12; // rcx
__int64 v13; // rdx
__int64 v14; // r12
int v15; // er13
int v16; // er8
__int64 v17; // rdi
_DWORD v19[2]; // [rsp+0h] [rbp-50h]
__int64 v20; // [rsp+8h] [rbp-48h]
int v21; // [rsp+14h] [rbp-3Ch]
__int64 v22; // [rsp+18h] [rbp-38h]

v22 = a2;
v2 = 16 * ((unsigned __int64)(4LL * a2 + 15) >> 4);
v3 = alloca(v2);
v4 = alloca(v2);
if ( a2 <= 0 )
{
v20 = imlib_create_image(0LL, 0LL);
imlib_context_set_image(v20);
imlib_context_set_color(255LL, 0LL, 0LL, 0LL);
imlib_image_fill_rectangle(0LL, 0LL, 0LL, 0LL);
imlib_context_set_anti_alias(0LL);
imlib_context_set_dither(1LL);
imlib_context_set_blend(0LL);
imlib_context_set_angle(0.0);
}
else
{
LODWORD(v20) = 0;
v6 = 0LL;
v7 = 0;
do
{
imlib_context_set_image(*(_QWORD *)(a1 + 8 * v6));
v8 = imlib_image_get_height();
v19[v6] = v8;
v21 = v8;
v9 = imlib_image_get_width();
v10 = v21;
v19[v6] = v9;
if ( (int)v7 < v10 )
v7 = v10;
LODWORD(v20) = v9 + v20;
++v6;
}
while ( v22 != v6 );
v11 = v20;
v20 = imlib_create_image((unsigned int)v20, v7);
imlib_context_set_image(v20);
imlib_context_set_color(255LL, 0LL, 0LL, 0LL);
v12 = v7;
v13 = v11;
v14 = 0LL;
v15 = 0;
imlib_image_fill_rectangle(0LL, 0LL, v13, v12);
imlib_context_set_anti_alias(0LL);
imlib_context_set_dither(1LL);
imlib_context_set_blend(0LL);
imlib_context_set_angle(0.0);
do
{
v16 = v19[v14];
v17 = *(_QWORD *)(a1 + 8 * v14++);
v21 = v16;
imlib_blend_image_onto_image(v17, 0LL, 0LL, 0LL);
v15 += v21;
}
while ( v14 != v22 );
}
return v20;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
signed __int64 v2; // rax
void *v3; // rsp
void *v4; // rsp
__int64 v6; // r12
unsigned int v7; // er13
int v8; // eax
int v9; // eax
int v10; // ecx
unsigned int v11; // er12
__int64 v12; // rcx
__int64 v13; // rdx
__int64 v14; // r12
int v15; // er13
int v16; // er8
__int64 v17; // rdi
_DWORD v19[2]; // [rsp+0h] [rbp-50h]
__int64 v20; // [rsp+8h] [rbp-48h]
int v21; // [rsp+14h] [rbp-3Ch]
__int64 v22; // [rsp+18h] [rbp-38h]

v22 = a2;
v2 = 16 * ((unsigned __int64)(4LL * a2 + 15) >> 4);
v3 = alloca(v2);
v4 = alloca(v2);
if ( a2 <= 0 )
{
v20 = imlib_create_image(0LL, 0LL);
imlib_context_set_image(v20);
imlib_context_set_color(255LL, 0LL, 0LL, 0LL);
imlib_image_fill_rectangle(0LL, 0LL, 0LL, 0LL);
imlib_context_set_anti_alias(0LL);
imlib_context_set_dither(1LL);
imlib_context_set_blend(0LL);
imlib_context_set_angle(0.0);
}
else
{
LODWORD(v20) = 0;
v6 = 0LL;
v7 = 0;
do
{
imlib_context_set_image(*(_QWORD *)(a1 + 8 * v6));
v8 = imlib_image_get_height();
v19[v6] = v8;
v21 = v8;
v9 = imlib_image_get_width();
v10 = v21;
v19[v6] = v9;
if ( (int)v7 < v10 )
v7 = v10;
LODWORD(v20) = v9 + v20;
++v6;
}
while ( v22 != v6 );
v11 = v20;
v20 = imlib_create_image((unsigned int)v20, v7);
imlib_context_set_image(v20);
imlib_context_set_color(255LL, 0LL, 0LL, 0LL);
v12 = v7;
v13 = v11;
v14 = 0LL;
v15 = 0;
imlib_image_fill_rectangle(0LL, 0LL, v13, v12);
imlib_context_set_anti_alias(0LL);
imlib_context_set_dither(1LL);
imlib_context_set_blend(0LL);
imlib_context_set_angle(0.0);
do
{
v16 = v19[v14];
v17 = *(_QWORD *)(a1 + 8 * v14++);
v21 = v16;
imlib_blend_image_onto_image(v17, 0LL, 0LL, 0LL);
v15 += v21;
}
while ( v14 != v22 );
}
return v20;
}

original_code:
Image image_concat(Image images[], int count)
{
 int total_width = 0;
 int max_height = 0;
 int widths[count];
 int heights[count];
 for (int i = 0; i < count; i++) {
  imlib_context_set_image(images[i]);
  heights[i] = imlib_image_get_height();
  widths[i] = imlib_image_get_width();
  max_height = heights[i] > max_height ? heights[i] : max_height;
  total_width += widths[i];
 }
 Imlib_Image ret = imlib_create_image(total_width, max_height);
 imlib_context_set_image(ret);
 imlib_context_set_color(255, 0, 0, 0);
 imlib_image_fill_rectangle(0, 0, total_width, max_height);
 imlib_context_set_anti_alias(0);
 imlib_context_set_dither(1);
 imlib_context_set_blend(0);
 imlib_context_set_angle(0);
 int x = 0;
 for (int i = 0; i < count; i++) {
  imlib_blend_image_onto_image(images[i], 0, 0, 0, widths[i], heights[i], x, 0, widths[i], heights[i]);
  x += widths[i];
 }
 return ret;
}

canonical_original_code:
void *image_concat(void *images[], int count)
{
 int total_width = 0;
 int max_height = 0;
 int widths[-1];
 int heights[-1];
 for (int i = 0; i < count; i++) {
  imlib_context_set_image(images[i]);
  heights[i] = imlib_image_get_height();
  widths[i] = imlib_image_get_width();
  max_height = heights[i] > max_height ? heights[i] : max_height;
  total_width += widths[i];
 }
 void *ret = imlib_create_image(total_width, max_height);
 imlib_context_set_image(ret);
 imlib_context_set_color(255, 0, 0, 0);
 imlib_image_fill_rectangle(0, 0, total_width, max_height);
 imlib_context_set_anti_alias(0);
 imlib_context_set_dither(1);
 imlib_context_set_blend(0);
 imlib_context_set_angle(0);
 int x = 0;
 for (int i = 0; i < count; i++) {
  imlib_blend_image_onto_image(images[i], 0, 0, 0, widths[i], heights[i], x, 0, widths[i], heights[i]);
  x += widths[i];
 }
 return ret;
}

variable_types:
images
void *[]

variable_types: count int

variable_types:
widths
int [-1]

variable_types:
heights
int [-1]

variable_types:
ret
void *

variable_types: x int


decompiled_code:
bool __fastcall image_save(__int64 a1, const char *a2)
{
char *v2; // rax
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = strrchr(a2, 46);
if ( v2 )
imlib_image_set_format(v2 + 1);
imlib_context_set_image(a1);
imlib_save_image_with_error_return(a2, v4);
return v4[0] != 0;
}

canonical_decompiled_code:
bool __fastcall func6(__int64 a1, const char *a2)
{
char *v2; // rax
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = strrchr(a2, 46);
if ( v2 )
imlib_image_set_format(v2 + 1);
imlib_context_set_image(a1);
imlib_save_image_with_error_return(a2, v4);
return v4[0] != 0;
}

original_code:
_Bool image_save(Image image, char *filename)
{
 char *tmp = strrchr(filename, '.');
 if (tmp) {
  imlib_image_set_format(tmp + 1);
 }
 Imlib_Load_Error err;
 imlib_context_set_image(image);
 imlib_save_image_with_error_return(filename, &err);
 return err != IMLIB_LOAD_ERROR_NONE;
}

canonical_original_code:
_Bool image_save(void *image, char *filename)
{
 char *tmp = strrchr(filename, '.');
 if (tmp) {
  imlib_image_set_format(tmp + 1);
 }
 enum _imlib_load_error err;
 imlib_context_set_image(image);
 imlib_save_image_with_error_return(filename, &err);
 return err != IMLIB_LOAD_ERROR_NONE;
}

variable_types:
filename
char *

variable_types:
tmp
char *

variable_types: enum _imlib_load_error { IMLIB_LOAD_ERROR_NONE=0, IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST=1, IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY=2, IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ=3, IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT=4, IMLIB_LOAD_ERROR_PATH_TOO_LONG=5, IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT=6, IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY=7, IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE=8, IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS=9, IMLIB_LOAD_ERROR_OUT_OF_MEMORY=10, IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS=11, IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE=12, IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE=13, IMLIB_LOAD_ERROR_UNKNOWN=14 }


decompiled_code:
__int64 __fastcall image_scale(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
imlib_context_set_image(a1);
imlib_context_set_anti_alias(1LL);
return imlib_create_cropped_scaled_image(0LL, 0LL, a2, a3, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
imlib_context_set_image(a1);
imlib_context_set_anti_alias(1LL);
return imlib_create_cropped_scaled_image(0LL, 0LL, a2, a3, a4, a5);
}

original_code:
Image image_scale(Image image, int cwidth, int cheight, int twidth, int theight)
{
 imlib_context_set_image(image);
 imlib_context_set_anti_alias(1);
 return imlib_create_cropped_scaled_image(0, 0, cwidth, cheight, twidth, theight);
}

canonical_original_code:
void *image_scale(void *image, int cwidth, int cheight, int twidth, int theight)
{
 imlib_context_set_image(image);
 imlib_context_set_anti_alias(1);
 return imlib_create_cropped_scaled_image(0, 0, cwidth, cheight, twidth, theight);
}

variable_types: cwidth int

variable_types: cheight int

variable_types: twidth int

variable_types: theight int


decompiled_code:
__int64 __fastcall image_set_quality(__int64 a1, unsigned int a2)
{
imlib_context_set_image(a1);
return imlib_image_attach_data_value("quality", 0LL, a2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
imlib_context_set_image(a1);
return imlib_image_attach_data_value("quality", 0LL, a2, 0LL);
}

original_code:
void image_set_quality(Image image, int quality)
{
 imlib_context_set_image(image);
 imlib_image_attach_data_value("quality", ((void *)0), quality, ((void *)0));
}

canonical_original_code:
void image_set_quality(void *image, int quality)
{
 imlib_context_set_image(image);
 imlib_image_attach_data_value("quality", ((void *)0), quality, ((void *)0));
}

variable_types: quality int


decompiled_code:
__int64 __fastcall image_format(__int64 a1)
{
imlib_context_set_image(a1);
return imlib_image_format();
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
imlib_context_set_image(a1);
return imlib_image_format();
}

original_code:
char *image_format(Image image)
{
 imlib_context_set_image(image);
 return imlib_image_format();
}

canonical_original_code:
char *image_format(void *image)
{
 imlib_context_set_image(image);
 return imlib_image_format();
}

return_type: char *


decompiled_code:
unsigned int scrot_delay()
{
unsigned int result; // eax
signed int v1; // edi
int v2; // ebx

result = opt;
v1 = *(_DWORD *)(opt + 28LL);
if ( v1 > 0 )
{
if ( *(_BYTE *)(opt + 48LL) )
{
printf("Taking shot in ");
v2 = *(_DWORD *)(opt + 28LL);
if ( v2 > 0 )
{
do
{
printf("%d.. ", (unsigned int)v2);
fflush(stdout);
sleep(1u);
--v2;
}
while ( v2 );
}
result = puts("0.");
}
else
{
result = sleep(v1);
}
}
return result;
}

canonical_decompiled_code:
unsigned int func0()
{
unsigned int result; // eax
signed int v1; // edi
int v2; // ebx

result = opt;
v1 = *(_DWORD *)(opt + 28LL);
if ( v1 > 0 )
{
if ( *(_BYTE *)(opt + 48LL) )
{
printf("Taking shot in ");
v2 = *(_DWORD *)(opt + 28LL);
if ( v2 > 0 )
{
do
{
printf("%d.. ", (unsigned int)v2);
fflush(stdout);
sleep(1u);
--v2;
}
while ( v2 );
}
result = puts("0.");
}
else
{
result = sleep(v1);
}
}
return result;
}

original_code:
static void scrot_delay(void)
{
 if (opt->delay < 1)
  return;
 if (!opt->countdown) {
  sleep(opt->delay);
  return;
 }
 printf("Taking shot in ");
 for (int i = opt->delay; i > 0; i--) {
  printf("%d.. ", i);
  fflush(stdout);
  sleep(1);
 }
 printf("0.\n");
}

canonical_original_code:
static void scrot_delay()
{
 if (opt->delay < 1)
  return;
 if (!opt->countdown) {
  sleep(opt->delay);
  return;
 }
 printf("Taking shot in ");
 for (int i = opt->delay; i > 0; i--) {
  printf("%d.. ", i);
  fflush(stdout);
  sleep(1);
 }
 printf("0.\n");
}

variable_types: i int


decompiled_code:
__int64 scrot_shoot_all_screens()
{
int v0; // eax
__int64 v1; // r13
unsigned int v2; // er14
__int64 v3; // rbx
void *v4; // rsp
_QWORD v6[4]; // [rsp+0h] [rbp-20h] BYREF

v0 = display_num_screens();
if ( v0 <= 1 )
return image_from_screen();
v1 = v0;
v2 = v0;
v3 = 0LL;
v4 = alloca(8LL * v0);
do
{
display_open_screen((unsigned int)v3);
v6[v3++] = image_from_screen();
}
while ( v3 != v1 );
return image_concat(v6, v2);
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
__int64 v1; // r13
unsigned int v2; // er14
__int64 v3; // rbx
void *v4; // rsp
_QWORD v6[4]; // [rsp+0h] [rbp-20h] BYREF

v0 = display_num_screens();
if ( v0 <= 1 )
return image_from_screen();
v1 = v0;
v2 = v0;
v3 = 0LL;
v4 = alloca(8LL * v0);
do
{
display_open_screen((unsigned int)v3);
v6[v3++] = image_from_screen();
}
while ( v3 != v1 );
return image_concat(v6, v2);
}

original_code:
static Image scrot_shoot_all_screens(void)
{
 int screens = display_num_screens();
 if (screens < 2)
  return image_from_screen();
 Image images[screens];
 for (int i = 0; i < screens; i++) {
  display_open_screen(i);
  images[i] = image_from_screen();
 }
 return image_concat(images, screens);
}

canonical_original_code:
static void *scrot_shoot_all_screens()
{
 int screens = display_num_screens();
 if (screens < 2)
  return image_from_screen();
 void *images[-1];
 for (int i = 0; i < screens; i++) {
  display_open_screen(i);
  images[i] = image_from_screen();
 }
 return image_concat(images, screens);
}

variable_types: screens int

variable_types:
images
void *[-1]


decompiled_code:
__int64 scrot_shoot()
{
__int64 v0; // rbp
__int64 result; // rax

if ( (*(_DWORD *)(opt + 48LL) & 0xFFFF00) != 0 )
{
if ( *(_BYTE *)(opt + 49LL) )
v0 = display_select_area();
else
v0 = display_select_window();
if ( !v0 )
util_error("Couldn't select area\n");
scrot_delay();
result = image_from_area(v0);
}
else
{
scrot_delay();
if ( *(_BYTE *)(opt + 52LL) )
result = scrot_shoot_all_screens();
else
result = image_from_screen();
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbp
__int64 result; // rax

if ( (*(_DWORD *)(opt + 48LL) & 0xFFFF00) != 0 )
{
if ( *(_BYTE *)(opt + 49LL) )
v0 = display_select_area();
else
v0 = display_select_window();
if ( !v0 )
util_error("Couldn't select area\n");
func0();
result = image_from_area(v0);
}
else
{
func0();
if ( *(_BYTE *)(opt + 52LL) )
result = func1();
else
result = image_from_screen();
}
return result;
}

original_code:
static Image scrot_shoot(void)
{
 if (opt->select || opt->window) {
  struct Area *area;
  if (opt->select)
   area = display_select_area();
  else
   area = display_select_window();
  if (area == ((void *)0))
   util_error("Couldn't select area\n");
  scrot_delay();
  return image_from_area(area);
 }
 scrot_delay();
 if (opt->multidisp)
  return scrot_shoot_all_screens();
 return image_from_screen();
}

canonical_original_code:
static void *scrot_shoot()
{
 if (opt->select || opt->window) {
  struct Area *area;
  if (opt->select)
   area = display_select_area();
  else
   area = display_select_window();
  if (area == ((void *)0))
   util_error("Couldn't select area\n");
  scrot_delay();
  return image_from_area(area);
 }
 scrot_delay();
 if (opt->multidisp)
  return scrot_shoot_all_screens();
 return image_from_screen();
}

variable_types: struct Area { int x; int y; int width; int height; } *


decompiled_code:
__int64 __fastcall scrot_create_thumbnail(__int64 a1)
{
unsigned int v1; // er12
unsigned int v2; // er9
__int64 v3; // rcx
__int64 v4; // r8
int v6; // eax

v1 = image_width();
v2 = image_height(a1);
v3 = *(unsigned int *)(opt + 40LL);
v4 = *(unsigned int *)(opt + 44LL);
if ( (int)v3 <= 0 )
{
if ( (int)v4 <= 0 )
{
v6 = *(_DWORD *)(opt + 36LL);
v3 = (unsigned int)((int)(v1 * v6) / 100);
v4 = (unsigned int)((int)(v2 * v6) / 100);
}
else if ( !(_DWORD)v3 )
{
v3 = (unsigned int)((int)(v1 * v4) / (int)v2);
}
}
else if ( !(_DWORD)v4 )
{
v4 = (unsigned int)((int)(v2 * v3) / (int)v1);
}
return image_scale(a1, v1, v2, v3, v4);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v1; // er12
unsigned int v2; // er9
__int64 v3; // rcx
__int64 v4; // r8
int v6; // eax

v1 = image_width();
v2 = image_height(a1);
v3 = *(unsigned int *)(opt + 40LL);
v4 = *(unsigned int *)(opt + 44LL);
if ( (int)v3 <= 0 )
{
if ( (int)v4 <= 0 )
{
v6 = *(_DWORD *)(opt + 36LL);
v3 = (unsigned int)((int)(v1 * v6) / 100);
v4 = (unsigned int)((int)(v2 * v6) / 100);
}
else if ( !(_DWORD)v3 )
{
v3 = (unsigned int)((int)(v1 * v4) / (int)v2);
}
}
else if ( !(_DWORD)v4 )
{
v4 = (unsigned int)((int)(v2 * v3) / (int)v1);
}
return image_scale(a1, v1, v2, v3, v4);
}

original_code:
static Image scrot_create_thumbnail(Image image)
{
 int cwidth = image_width(image);
 int cheight = image_height(image);
 int twidth;
 int theight;
 if (opt->thumb_width > 0 || opt->thumb_height > 0) {
  if (opt->thumb_width == 0) {
   twidth = cwidth * opt->thumb_height / cheight;
   theight = opt->thumb_height;
  } else if (opt->thumb_height == 0) {
   twidth = opt->thumb_width;
   theight = cheight * opt->thumb_width / cwidth;
  } else {
   twidth = opt->thumb_width;
   theight = opt->thumb_height;
  }
 } else {
  twidth = cwidth * opt->thumb / 100;
  theight = cheight * opt->thumb / 100;
 }
 return image_scale(image, cwidth, cheight, twidth, theight);
}

canonical_original_code:
static void *scrot_create_thumbnail(void *image)
{
 int cwidth = image_width(image);
 int cheight = image_height(image);
 int twidth;
 int theight;
 if (opt->thumb_width > 0 || opt->thumb_height > 0) {
  if (opt->thumb_width == 0) {
   twidth = cwidth * opt->thumb_height / cheight;
   theight = opt->thumb_height;
  } else if (opt->thumb_height == 0) {
   twidth = opt->thumb_width;
   theight = cheight * opt->thumb_width / cwidth;
  } else {
   twidth = opt->thumb_width;
   theight = opt->thumb_height;
  }
 } else {
  twidth = cwidth * opt->thumb / 100;
  theight = cheight * opt->thumb / 100;
 }
 return image_scale(image, cwidth, cheight, twidth, theight);
}

variable_types:
image
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
struct tm *v4; // rbp
const char *v5; // r12
__int64 v6; // rax
const char *v7; // r13
__int64 v8; // rdi
const char *v9; // rax
__int64 v11; // r14
time_t timer; // [rsp+8h] [rbp-30h] BYREF

options_init(argc, argv, envp);
if ( !(unsigned __int8)display_init() )
util_error("Can't open display.\n");
image_init();
v3 = scrot_shoot();
if ( !v3 )
util_error("no image grabbed\n");
image_set_quality(v3, *(unsigned int *)(opt + 32LL));
time(&timer);
v4 = localtime(&timer);
v5 = (const char *)util_fmt_str(*opt, v4, 0LL, 0LL, v3);
if ( (unsigned __int8)image_save(v3, v5) )
util_error("Saving to file %s failed\n", v5);
v6 = opt;
v7 = 0LL;
if ( *(_DWORD *)(opt + 36LL) )
{
v11 = scrot_create_thumbnail(v3);
if ( !v11 )
util_error("Unable to create scaled Image\n");
v7 = (const char *)util_fmt_str(*(_QWORD *)(opt + 8LL), v4, 0LL, 0LL, v11);
if ( (unsigned __int8)image_save(v11, v7) )
util_error("Saving thumbnail %s failed\n", v7);
v6 = opt;
}
v8 = *(_QWORD *)(v6 + 16);
if ( v8 )
{
v9 = (const char *)util_fmt_str(v8, v4, v5, v7, v3);
system(v9);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
struct tm *v4; // rbp
const char *v5; // r12
__int64 v6; // rax
const char *v7; // r13
__int64 v8; // rdi
const char *v9; // rax
__int64 v11; // r14
time_t timer; // [rsp+8h] [rbp-30h] BYREF

options_init(argc, argv, envp);
if ( !(unsigned __int8)display_init() )
util_error("Can't open display.\n");
image_init();
v3 = func2();
if ( !v3 )
util_error("no image grabbed\n");
image_set_quality(v3, *(unsigned int *)(opt + 32LL));
time(&timer);
v4 = localtime(&timer);
v5 = (const char *)util_fmt_str(*opt, v4, 0LL, 0LL, v3);
if ( (unsigned __int8)image_save(v3, v5) )
util_error("Saving to file %s failed\n", v5);
v6 = opt;
v7 = 0LL;
if ( *(_DWORD *)(opt + 36LL) )
{
v11 = func3(v3);
if ( !v11 )
util_error("Unable to create scaled Image\n");
v7 = (const char *)util_fmt_str(*(_QWORD *)(opt + 8LL), v4, 0LL, 0LL, v11);
if ( (unsigned __int8)image_save(v11, v7) )
util_error("Saving thumbnail %s failed\n", v7);
v6 = opt;
}
v8 = *(_QWORD *)(v6 + 16);
if ( v8 )
{
v9 = (const char *)util_fmt_str(v8, v4, v5, v7, v3);
system(v9);
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
 options_init(argc, argv);
 if(!display_init())
  util_error("Can't open display.\n");
 image_init();
 Image image = scrot_shoot();
 if (image == ((void *)0))
  util_error("no image grabbed\n");
 image_set_quality(image, opt->quality);
 time_t t;
 time(&t);
 struct tm *tm = localtime(&t);
 char *path_image = util_fmt_str(opt->output_file, tm, ((void *)0), ((void *)0), image);
 char *path_thumb = ((void *)0);
 _Bool error = image_save(image, path_image);
 if (error)
  util_error("Saving to file %s failed\n", path_image);
 if (opt->thumb != 0) {
  Image thumbnail = scrot_create_thumbnail(image);
  if (thumbnail == ((void *)0))
   util_error("Unable to create scaled Image\n");
  path_thumb = util_fmt_str(opt->thumb_file, tm, ((void *)0), ((void *)0), thumbnail);
  error = image_save(thumbnail, path_thumb);
  if (error)
   util_error("Saving thumbnail %s failed\n", path_thumb);
 }
 if (opt->exec != ((void *)0)) {
  char *execstr = util_fmt_str(opt->exec, tm, path_image, path_thumb, image);
  system(execstr);
 }
}

canonical_original_code:
int main(int argc, char **argv)
{
 options_init(argc, argv);
 if(!display_init())
  util_error("Can't open display.\n");
 image_init();
 void *image = scrot_shoot();
 if (image == ((void *)0))
  util_error("no image grabbed\n");
 image_set_quality(image, opt->quality);
 long t;
 time(&t);
 struct tm *tm = localtime(&t);
 char *path_image = util_fmt_str(opt->output_file, tm, ((void *)0), ((void *)0), image);
 char *path_thumb = ((void *)0);
 _Bool error = image_save(image, path_image);
 if (error)
  util_error("Saving to file %s failed\n", path_image);
 if (opt->thumb != 0) {
  void *thumbnail = scrot_create_thumbnail(image);
  if (thumbnail == ((void *)0))
   util_error("Unable to create scaled Image\n");
  path_thumb = util_fmt_str(opt->thumb_file, tm, ((void *)0), ((void *)0), thumbnail);
  error = image_save(thumbnail, path_thumb);
  if (error)
   util_error("Saving thumbnail %s failed\n", path_thumb);
 }
 if (opt->exec != ((void *)0)) {
  char *execstr = util_fmt_str(opt->exec, tm, path_image, path_thumb, image);
  system(execstr);
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: t long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; } *

variable_types:
thumbnail
void *

variable_types:
execstr
char *


decompiled_code:
__int64 __fastcall display_X11_area_sanitize(int *a1)
{
int v1; // edx
int v2; // er9
__int64 result; // rax
int v4; // er8
__int64 v5; // rsi
int v6; // ecx
int v7; // edx

v1 = *a1;
v2 = *a1 + a1[2];
if ( *a1 < 0 )
{
a1[2] = v2;
v1 = 0;
*a1 = 0;
}
result = (unsigned int)a1[1];
v4 = result + a1[3];
if ( (int)result < 0 )
{
a1[3] = v4;
result = 0LL;
a1[1] = 0;
}
v5 = scr;
v6 = *(_DWORD *)(scr + 24);
if ( v6 < v2 )
a1[2] = v6 - v1;
v7 = *(_DWORD *)(v5 + 28);
if ( v7 < v4 )
a1[3] = v7 - result;
return result;
}

original_code:
static void display_X11_area_sanitize(struct Area *area)
{
 if (area->x < 0) {
  area->width += area->x;
  area->x = 0;
 }
 if (area->y < 0) {
  area->height += area->y;
  area->y = 0;
 }
 if (area->x + area->width > scr->width)
  area->width = scr->width - area->x;
 if (area->y + area->height > scr->height)
  area->height = scr->height - area->y;
}

user_defined_types: struct Area { int x; int y; int width; int height; }


decompiled_code:
__int64 display_X11_init()
{
Display *v0; // rax
__int64 v1; // rdx
__int64 result; // rax

v0 = XOpenDisplay(0LL);
disp = v0;
if ( !v0 )
return 0LL;
v1 = (__int64)&v0->screens[(__int64)v0->default_screen];
result = 1LL;
scr = v1;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
Display *v0; // rax
__int64 v1; // rdx
__int64 result; // rax

v0 = XOpenDisplay(0LL);
disp = v0;
if ( !v0 )
return 0LL;
v1 = (__int64)&v0->screens[(__int64)v0->default_screen];
result = 1LL;
scr = v1;
return result;
}

original_code:
_Bool display_X11_init(void)
{
 disp = XOpenDisplay(((void *)0));
 if (disp == ((void *)0))
  return 0;
 scr = (&((_XPrivDisplay)(disp))->screens[(((_XPrivDisplay)(disp))->default_screen)]);
 return 1;
}

canonical_original_code:
_Bool display_X11_init()
{
 disp = XOpenDisplay(((void *)0));
 if (disp == ((void *)0))
  return 0;
 scr = (&((_XPrivDisplay)(disp))->screens[(((_XPrivDisplay)(disp))->default_screen)]);
 return 1;
}


decompiled_code:
__int64 display_X11_num_screens()
{
return (unsigned int)disp->nscreens;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)disp->nscreens;
}

original_code:
int display_X11_num_screens(void)
{
 return (((_XPrivDisplay)(disp))->nscreens);
}

canonical_original_code:
int display_X11_num_screens()
{
 return (((_XPrivDisplay)(disp))->nscreens);
}


decompiled_code:
int __fastcall options_init_thumbnail(_DWORD *a1, char *a2)
{
char *v2; // rax
char *v3; // rax
const char *v4; // r12
int v5; // eax
int v6; // ebp

if ( strchr(a2, 120) )
{
v2 = strtok(a2, "x");
a1[10] = atoi(v2);
v3 = strtok(0LL, "x");
v4 = v3;
if ( !v3 )
return (int)v3;
v5 = atoi(a2);
a1[10] = v5;
v6 = v5;
LODWORD(v3) = atoi(v4);
a1[11] = (_DWORD)v3;
if ( v6 < 0 )
a1[10] = 1;
if ( (int)v3 < 0 )
a1[11] = 1;
if ( !*((_QWORD *)a1 + 5) )
{
a1[9] = 0;
return (int)v3;
}
goto LABEL_10;
}
LODWORD(v3) = atoi(a2);
a1[9] = (_DWORD)v3;
if ( (int)v3 <= 0 )
{
LABEL_10:
a1[9] = 1;
return (int)v3;
}
if ( (int)v3 > 100 )
a1[9] = 100;
return (int)v3;
}

original_code:
static void options_init_thumbnail(struct Options *tmp_opt, char *arg)
{
 if (strchr(arg, 'x')) {
  char *tok = strtok(arg, "x");
  tmp_opt->thumb_width = atoi(tok);
  tok = strtok(((void *)0), "x");
  if (tok) {
   tmp_opt->thumb_width = atoi(arg);
   tmp_opt->thumb_height = atoi(tok);
   if (tmp_opt->thumb_width < 0) {
    tmp_opt->thumb_width = 1;
   }
   if (tmp_opt->thumb_height < 0) {
    tmp_opt->thumb_height = 1;
   }
   if (tmp_opt->thumb_width == 0 && tmp_opt->thumb_height == 0) {
    tmp_opt->thumb = 0;
   }
   else {
    tmp_opt->thumb = 1;
   }
  }
 } else {
  tmp_opt->thumb = atoi(arg);
  if (tmp_opt->thumb < 1) {
   tmp_opt->thumb = 1;
  } else if (tmp_opt->thumb > 100) {
   tmp_opt->thumb = 100;
  }
 }
}

variable_types: struct Options { char *output_file; char *thumb_file; char *exec; int debug_level; int delay; int quality; int thumb; int thumb_width; int thumb_height; _Bool countdown; _Bool select; _Bool window; _Bool border; _Bool multidisp; } *

variable_types:
arg
char *

variable_types:
tok
char *