decompiled_code:
__int64 __fastcall base2_inherit_vtable(__int64 *a1, __int64 *a2, char a3)
{
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax

if ( !a1 || !a2 )
{
printf("(%s:%u) ERROR: Invalid input, parent_vtable(%p) child_vtable(%p)\n", "base2.c", 330LL, a1, a2);
return 2LL;
}
if ( *a2 )
{
if ( a2[1] )
{
if ( a2[2] )
{
LABEL_6:
if ( a2[3] )
goto LABEL_7;
v5 = a1[3];
a2[3] = v5;
if ( !a3 )
goto LABEL_7;
goto LABEL_15;
}
v8 = a1[2];
a2[2] = v8;
if ( !a3 )
{
LABEL_30:
if ( !a2[3] )
a2[3] = a1[3];
LABEL_7:
if ( a2[4] )
return 1LL;
v6 = a1[4];
a2[4] = v6;
if ( !a3 )
return 1LL;
goto LABEL_18;
}
goto LABEL_26;
}
v7 = a1[1];
a2[1] = v7;
if ( a3 )
goto LABEL_23;
goto LABEL_35;
}
v4 = *a1;
*a2 = *a1;
if ( !a3 )
{
if ( a2[1] )
{
if ( a2[2] )
goto LABEL_30;
goto LABEL_36;
}
a2[1] = a1[1];
LABEL_35:
if ( a2[2] )
goto LABEL_6;
LABEL_36:
a2[2] = a1[2];
goto LABEL_30;
}
if ( !v4 )
{
printf("(%s:%u) ERROR: Invalid input, delete_fn(%p)\n", "base2.c", 335LL, 0LL);
return 2LL;
}
if ( !a2[1] )
{
v7 = a1[1];
a2[1] = v7;
LABEL_23:
if ( !v7 )
{
printf("(%s:%u) ERROR: Invalid input, type_string_fn(%p)\n", "base2.c", 337LL, 0LL);
return 2LL;
}
if ( a2[2] )
goto LABEL_6;
goto LABEL_25;
}
if ( !a2[2] )
{
LABEL_25:
v8 = a1[2];
a2[2] = v8;
LABEL_26:
if ( !v8 )
{
printf("(%s:%u) ERROR: Invalid input, string_fn(%p)\n", "base2.c", 339LL, 0LL);
return 2LL;
}
}
if ( a2[3] )
goto LABEL_7;
v5 = a1[3];
a2[3] = v5;
LABEL_15:
if ( v5 )
{
if ( a2[4] )
return 1LL;
v6 = a1[4];
a2[4] = v6;
LABEL_18:
if ( !v6 )
{
printf("(%s:%u) ERROR: Invalid input, increase_val1_fn(%p)\n", "base2.c", 343LL, 0LL);
return 2LL;
}
return 1LL;
}
printf("(%s:%u) ERROR: Invalid input, string_size_fn(%p)\n", "base2.c", 341LL, 0LL);
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1, __int64 *a2, char a3)
{
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax

if ( !a1 || !a2 )
{
printf("(%s:%u) ERROR: Invalid input, parent_vtable(%p) child_vtable(%p)\n", "base2.c", 330LL, a1, a2);
return 2LL;
}
if ( *a2 )
{
if ( a2[1] )
{
if ( a2[2] )
{
LABEL_6:
if ( a2[3] )
goto LABEL_7;
v5 = a1[3];
a2[3] = v5;
if ( !a3 )
goto LABEL_7;
goto LABEL_15;
}
v8 = a1[2];
a2[2] = v8;
if ( !a3 )
{
LABEL_30:
if ( !a2[3] )
a2[3] = a1[3];
LABEL_7:
if ( a2[4] )
return 1LL;
v6 = a1[4];
a2[4] = v6;
if ( !a3 )
return 1LL;
goto LABEL_18;
}
goto LABEL_26;
}
v7 = a1[1];
a2[1] = v7;
if ( a3 )
goto LABEL_23;
goto LABEL_35;
}
v4 = *a1;
*a2 = *a1;
if ( !a3 )
{
if ( a2[1] )
{
if ( a2[2] )
goto LABEL_30;
goto LABEL_36;
}
a2[1] = a1[1];
LABEL_35:
if ( a2[2] )
goto LABEL_6;
LABEL_36:
a2[2] = a1[2];
goto LABEL_30;
}
if ( !v4 )
{
printf("(%s:%u) ERROR: Invalid input, delete_fn(%p)\n", "base2.c", 335LL, 0LL);
return 2LL;
}
if ( !a2[1] )
{
v7 = a1[1];
a2[1] = v7;
LABEL_23:
if ( !v7 )
{
printf("(%s:%u) ERROR: Invalid input, type_string_fn(%p)\n", "base2.c", 337LL, 0LL);
return 2LL;
}
if ( a2[2] )
goto LABEL_6;
goto LABEL_25;
}
if ( !a2[2] )
{
LABEL_25:
v8 = a1[2];
a2[2] = v8;
LABEL_26:
if ( !v8 )
{
printf("(%s:%u) ERROR: Invalid input, string_fn(%p)\n", "base2.c", 339LL, 0LL);
return 2LL;
}
}
if ( a2[3] )
goto LABEL_7;
v5 = a1[3];
a2[3] = v5;
LABEL_15:
if ( v5 )
{
if ( a2[4] )
return 1LL;
v6 = a1[4];
a2[4] = v6;
LABEL_18:
if ( !v6 )
{
printf("(%s:%u) ERROR: Invalid input, increase_val1_fn(%p)\n", "base2.c", 343LL, 0LL);
return 2LL;
}
return 1LL;
}
printf("(%s:%u) ERROR: Invalid input, string_size_fn(%p)\n", "base2.c", 341LL, 0LL);
return 2LL;
}

original_code:
my_rc_e
base2_inherit_vtable (const base2_vtable_st *parent_vtable,
                      base2_vtable_st *child_vtable,
                      _Bool do_null_check)
{
    my_rc_e rc = MY_RC_E_SUCCESS;
    extern char (*CT_ASSERT(void)) [sizeof(char[1 - 2*!(5 == (sizeof(base2_vtable_st)/sizeof(void*)))])];
    if ((((void *)0) == parent_vtable) || (((void *)0) == child_vtable)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, parent_vtable(%p) " "child_vtable(%p)" "\n", "base2.c", 330, parent_vtable, child_vtable); } while (0);
        return (MY_RC_E_EINVAL);
    }
    do { if (((void *)0) == child_vtable->delete_fn) { child_vtable->delete_fn = parent_vtable->delete_fn; if (do_null_check && (((void *)0) == child_vtable->delete_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "delete_fn" "(%p)" "\n", "base2.c", 335, child_vtable->delete_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->type_string_fn) { child_vtable->type_string_fn = parent_vtable->type_string_fn; if (do_null_check && (((void *)0) == child_vtable->type_string_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "type_string_fn" "(%p)" "\n", "base2.c", 337, child_vtable->type_string_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->string_fn) { child_vtable->string_fn = parent_vtable->string_fn; if (do_null_check && (((void *)0) == child_vtable->string_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "string_fn" "(%p)" "\n", "base2.c", 339, child_vtable->string_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->string_size_fn) { child_vtable->string_size_fn = parent_vtable->string_size_fn; if (do_null_check && (((void *)0) == child_vtable->string_size_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "string_size_fn" "(%p)" "\n", "base2.c", 341, child_vtable->string_size_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->increase_val1_fn) { child_vtable->increase_val1_fn = parent_vtable->increase_val1_fn; if (do_null_check && (((void *)0) == child_vtable->increase_val1_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "increase_val1_fn" "(%p)" "\n", "base2.c", 343, child_vtable->increase_val1_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    return (MY_RC_E_SUCCESS);
err_exit:
    return (rc);
}

canonical_original_code:
enum my_rc_e_ base2_inherit_vtable(struct base2_vtable_st_ *parent_vtable, struct base2_vtable_st_ *child_vtable, _Bool do_null_check)
{
    enum my_rc_e_ rc = MY_RC_E_SUCCESS;
    extern char (*CT_ASSERT())[-1];
    if ((((void *)0) == parent_vtable) || (((void *)0) == child_vtable)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, parent_vtable(%p) " "child_vtable(%p)" "\n", "base2.c", 330, parent_vtable, child_vtable); } while (0);
        return (MY_RC_E_EINVAL);
    }
    do { if (((void *)0) == child_vtable->delete_fn) { child_vtable->delete_fn = parent_vtable->delete_fn; if (do_null_check && (((void *)0) == child_vtable->delete_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "delete_fn" "(%p)" "\n", "base2.c", 335, child_vtable->delete_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->type_string_fn) { child_vtable->type_string_fn = parent_vtable->type_string_fn; if (do_null_check && (((void *)0) == child_vtable->type_string_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "type_string_fn" "(%p)" "\n", "base2.c", 337, child_vtable->type_string_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->string_fn) { child_vtable->string_fn = parent_vtable->string_fn; if (do_null_check && (((void *)0) == child_vtable->string_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "string_fn" "(%p)" "\n", "base2.c", 339, child_vtable->string_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->string_size_fn) { child_vtable->string_size_fn = parent_vtable->string_size_fn; if (do_null_check && (((void *)0) == child_vtable->string_size_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "string_size_fn" "(%p)" "\n", "base2.c", 341, child_vtable->string_size_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    do { if (((void *)0) == child_vtable->increase_val1_fn) { child_vtable->increase_val1_fn = parent_vtable->increase_val1_fn; if (do_null_check && (((void *)0) == child_vtable->increase_val1_fn)) { do { printf("(%s:%u) ERROR: " "Invalid input, " "increase_val1_fn" "(%p)" "\n", "base2.c", 343, child_vtable->increase_val1_fn); } while (0); rc = MY_RC_E_EINVAL; goto err_exit; } } } while (0);
    return (MY_RC_E_SUCCESS);
err_exit:
    return (rc);
}

variable_types: struct base2_vtable_st_ { void (*delete_fn)(struct base2_st_ { struct base2_private_st_ { struct base2_vtable_st_ *vtable; } *private_h; unsigned int val1; } *base2_h); char *(*type_string_fn)(struct base2_st_ *base2_h); enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 } (*string_fn)(struct base2_st_ *base2_h, char *buffer, unsigned long buffer_size); enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 } (*string_size_fn)(struct base2_st_ *base2_h, unsigned long *buffer_size); enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 } (*increase_val1_fn)(struct base2_st_ *base2_h); } *


decompiled_code:
__int64 __fastcall base2_set_vtable(__int64 ***a1, __int64 *a2)
{
unsigned int v2; // er13
__int64 result; // rax

if ( a1 && a2 )
{
if ( *a1 )
{
v2 = base2_inherit_vtable((__int64 *)base2_vtable, a2, 1);
if ( !(unsigned __int8)my_rc_e_is_notok(v2) )
{
v2 = 1;
**a1 = a2;
}
}
else
{
v2 = 2;
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)->private_h(%p)\n", "base2.c", 373LL, a1, 0LL);
}
result = v2;
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) vtable(%p)\n", "base2.c", 368LL, a1, a2);
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 ***a1, __int64 *a2)
{
unsigned int v2; // er13
__int64 result; // rax

if ( a1 && a2 )
{
if ( *a1 )
{
v2 = func12((__int64 *)base2_vtable, a2, 1);
if ( !(unsigned __int8)my_rc_e_is_notok(v2) )
{
v2 = 1;
**a1 = a2;
}
}
else
{
v2 = 2;
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)->private_h(%p)\n", "base2.c", 373LL, a1, 0LL);
}
result = v2;
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p) vtable(%p)\n", "base2.c", 368LL, a1, a2);
result = 2LL;
}
return result;
}

original_code:
my_rc_e
base2_set_vtable (base2_handle base2_h, base2_vtable_st *vtable)
{
    my_rc_e rc;
    if ((((void *)0) == base2_h) || (((void *)0) == vtable)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p) vtable(%p)" "\n", "base2.c", 368, base2_h, vtable); } while (0);
        return (MY_RC_E_EINVAL);
    }
    if (((void *)0) == base2_h->private_h) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p)->private_h(%p)" "\n", "base2.c", 373, base2_h, base2_h->private_h); } while (0);
        return (MY_RC_E_EINVAL);
    }
    rc = base2_inherit_vtable(&base2_vtable, vtable, 1);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    base2_h->private_h->vtable = vtable;
    return (MY_RC_E_SUCCESS);
}

canonical_original_code:
enum my_rc_e_ base2_set_vtable(struct base2_st_ *base2_h, struct base2_vtable_st_ *vtable)
{
    enum my_rc_e_ rc;
    if ((((void *)0) == base2_h) || (((void *)0) == vtable)) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p) vtable(%p)" "\n", "base2.c", 368, base2_h, vtable); } while (0);
        return (MY_RC_E_EINVAL);
    }
    if (((void *)0) == base2_h->private_h) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p)->private_h(%p)" "\n", "base2.c", 373, base2_h, base2_h->private_h); } while (0);
        return (MY_RC_E_EINVAL);
    }
    rc = base2_inherit_vtable(&base2_vtable, vtable, 1);
    if (my_rc_e_is_notok(rc)) {
        return (rc);
    }
    base2_h->private_h->vtable = vtable;
    return (MY_RC_E_SUCCESS);
}

variable_types: struct base2_st_ { struct base2_private_st_ { struct base2_vtable_st_ { void (*delete_fn)(struct base2_st_ *base2_h); char *(*type_string_fn)(struct base2_st_ *base2_h); enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 } (*string_fn)(struct base2_st_ *base2_h, char *buffer, unsigned long buffer_size); enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 } (*string_size_fn)(struct base2_st_ *base2_h, unsigned long *buffer_size); enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 } (*increase_val1_fn)(struct base2_st_ *base2_h); } *vtable; } *private_h; unsigned int val1; } *

variable_types:
vtable
struct base2_vtable_st_ *

user_defined_types: struct base2_st_ { struct base2_private_st_ *private_h; unsigned int val1; }

user_defined_types: struct base2_private_st_ { struct base2_vtable_st_ *vtable; }

user_defined_types: struct base2_vtable_st_ { void (*delete_fn)(struct base2_st_ *base2_h); char *(*type_string_fn)(struct base2_st_ *base2_h); enum my_rc_e_ (*string_fn)(struct base2_st_ *base2_h, char *buffer, unsigned long buffer_size); enum my_rc_e_ (*string_size_fn)(struct base2_st_ *base2_h, unsigned long *buffer_size); enum my_rc_e_ (*increase_val1_fn)(struct base2_st_ *base2_h); }


decompiled_code:
__int64 __fastcall base2_init(__int64 a1)
{
_QWORD *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = calloc(1uLL, 8uLL);
*(_QWORD *)a1 = v1;
if ( v1 )
{
*v1 = base2_vtable;
result = 1LL;
*(_DWORD *)(a1 + 8) = 7;
}
else
{
result = 3LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 404LL, 0LL);
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
_QWORD *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = calloc(1uLL, 8uLL);
*(_QWORD *)a1 = v1;
if ( v1 )
{
*v1 = base2_vtable;
result = 1LL;
*(_DWORD *)(a1 + 8) = 7;
}
else
{
result = 3LL;
}
}
else
{
printf("(%s:%u) ERROR: Invalid input, base2_h(%p)\n", "base2.c", 404LL, 0LL);
result = 2LL;
}
return result;
}

original_code:
my_rc_e
base2_init (base2_handle base2_h)
{
    my_rc_e rc = MY_RC_E_SUCCESS;
    if (((void *)0) == base2_h) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p)" "\n", "base2.c", 404, base2_h); } while (0);
        return (MY_RC_E_EINVAL);
    }
    base2_h->private_h = calloc(1, sizeof(*base2_h->private_h));
    if (((void *)0) == base2_h->private_h) {
        rc = MY_RC_E_ENOMEM;
        goto err_exit;
    }
    base2_h->private_h->vtable = &base2_vtable;
    base2_h->val1 = 7;
    return (MY_RC_E_SUCCESS);
err_exit:
    if (((void *)0) != base2_h->private_h) {
        free(base2_h->private_h);
        base2_h->private_h = ((void *)0);
    }
    return (rc);
}

canonical_original_code:
enum my_rc_e_ base2_init(struct base2_st_ *base2_h)
{
    enum my_rc_e_ rc = MY_RC_E_SUCCESS;
    if (((void *)0) == base2_h) {
        do { printf("(%s:%u) ERROR: " "Invalid input, base2_h(%p)" "\n", "base2.c", 404, base2_h); } while (0);
        return (MY_RC_E_EINVAL);
    }
    base2_h->private_h = calloc(1, sizeof(*base2_h->private_h));
    if (((void *)0) == base2_h->private_h) {
        rc = MY_RC_E_ENOMEM;
        goto err_exit;
    }
    base2_h->private_h->vtable = &base2_vtable;
    base2_h->val1 = 7;
    return (MY_RC_E_SUCCESS);
err_exit:
    if (((void *)0) != base2_h->private_h) {
        free(base2_h->private_h);
        base2_h->private_h = ((void *)0);
    }
    return (rc);
}

variable_types: enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 }


decompiled_code:
bool __fastcall my_rc_e_is_notok(int a1)
{
return a1 != 1;
}

canonical_decompiled_code:
bool __fastcall func0(int a1)
{
return a1 != 1;
}

original_code:
_Bool
my_rc_e_is_notok (my_rc_e rc)
{
    return (MY_RC_E_SUCCESS != rc);
}

canonical_original_code:
_Bool my_rc_e_is_notok(enum my_rc_e_ rc)
{
    return (MY_RC_E_SUCCESS != rc);
}

user_defined_types: enum my_rc_e_ { MY_RC_E_INVALID=0, MY_RC_E_SUCCESS=1, MY_RC_E_EINVAL=2, MY_RC_E_ENOMEM=3, MY_RC_E_MAX=4 }


decompiled_code:
bool __fastcall my_rc_e_is_ok(int a1)
{
return a1 == 1;
}

canonical_decompiled_code:
bool __fastcall func1(int a1)
{
return a1 == 1;
}

original_code:
_Bool
my_rc_e_is_ok (my_rc_e rc)
{
    return (MY_RC_E_SUCCESS == rc);
}

canonical_original_code:
_Bool my_rc_e_is_ok(enum my_rc_e_ rc)
{
    return (MY_RC_E_SUCCESS == rc);
}


decompiled_code:
bool __fastcall my_rc_e_is_valid(unsigned int a1)
{
return a1 <= 4;
}

canonical_decompiled_code:
bool __fastcall func2(unsigned int a1)
{
return a1 <= 4;
}

original_code:
_Bool
my_rc_e_is_valid (my_rc_e rc)
{
    return ((rc >= MY_RC_E_INVALID) && (rc <= MY_RC_E_MAX));
}

canonical_original_code:
_Bool my_rc_e_is_valid(enum my_rc_e_ rc)
{
    return ((rc >= MY_RC_E_INVALID) && (rc <= MY_RC_E_MAX));
}


decompiled_code:
const char *__fastcall my_rc_e_get_string(unsigned int a1)
{
bool v1; // r8
const char *result; // rax

v1 = my_rc_e_is_valid(a1);
result = "__Invalid__";
if ( v1 )
result = my_rc_e_string[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(unsigned int a1)
{
bool v1; // r8
const char *result; // rax

v1 = func2(a1);
result = "__Invalid__";
if ( v1 )
result = my_rc_e_string[a1];
return result;
}

original_code:
const char *
my_rc_e_get_string (my_rc_e rc)
{
    const char* retval = "__Invalid__";
    if (my_rc_e_is_valid(rc)) {
        retval = my_rc_e_string[rc];
    }
    return (retval);
}

canonical_original_code:
char *my_rc_e_get_string(enum my_rc_e_ rc)
{
    char *retval = "__Invalid__";
    if (my_rc_e_is_valid(rc)) {
        retval = my_rc_e_string[rc];
    }
    return (retval);
}

variable_types:
retval
char *

return_type: char *


initialiseTime

repo: matthewpage/wavegen

decompiled_code:
struct tm *__fastcall initialiseTime(__int64 a1)
{
struct tm *result; // rax
int v2; // [rsp+Ch] [rbp-1Ch] BYREF
int v3; // [rsp+10h] [rbp-18h] BYREF
int v4; // [rsp+14h] [rbp-14h] BYREF
time_t timer; // [rsp+18h] [rbp-10h] BYREF

_isoc99_sscanf(a1, "%d:%d:%d", &v2, &v3, &v4);
time(&timer);
result = localtime(&timer);
currentTime = result;
result->tm_hour = v2;
result->tm_min = v3;
result->tm_sec = v4;
return result;
}

canonical_decompiled_code:
struct tm *__fastcall func0(__int64 a1)
{
struct tm *result; // rax
int v2; // [rsp+Ch] [rbp-1Ch] BYREF
int v3; // [rsp+10h] [rbp-18h] BYREF
int v4; // [rsp+14h] [rbp-14h] BYREF
time_t timer; // [rsp+18h] [rbp-10h] BYREF

_isoc99_sscanf(a1, "%d:%d:%d", &v2, &v3, &v4);
time(&timer);
result = localtime(&timer);
currentTime = result;
result->tm_hour = v2;
result->tm_min = v3;
result->tm_sec = v4;
return result;
}

original_code:
void initialiseTime(char* startTime) {
 int hour;
 int min;
 int sec;
 sscanf(startTime, "%d:%d:%d", &hour, &min, &sec);
 time_t tmpTime;
 time(&tmpTime);
 currentTime = localtime(&tmpTime);
 currentTime->tm_hour = hour;
 currentTime->tm_min = min;
 currentTime->tm_sec = sec;
}

canonical_original_code:
void initialiseTime(char *startTime) {
 int hour;
 int min;
 int sec;
 sscanf(startTime, "%d:%d:%d", &hour, &min, &sec);
 long tmpTime;
 time(&tmpTime);
 currentTime = localtime(&tmpTime);
 currentTime->tm_hour = hour;
 currentTime->tm_min = min;
 currentTime->tm_sec = sec;
}

variable_types:
startTime
char *

variable_types: hour int

variable_types: min int

variable_types: sec int

variable_types: tmpTime long

return_type: void


incrementTime

decompiled_code:
time_t __fastcall incrementTime(int a1)
{
struct tm *v2; // rdi

v2 = currentTime;
currentTime->tm_sec += a1;
return mktime(v2);
}

canonical_decompiled_code:
time_t __fastcall func1(int a1)
{
struct tm *v2; // rdi

v2 = currentTime;
currentTime->tm_sec += a1;
return mktime(v2);
}

original_code:
void incrementTime(int s) {
 currentTime->tm_sec += s;
 mktime(currentTime);
}

variable_types: s int


drawTimeLine

decompiled_code:
time_t drawTimeLine()
{
int v0; // ebp
__int64 v1; // r8
time_t result; // rax
unsigned int v3; // er12
unsigned int v4; // er13
unsigned int i; // ebx
char s[48]; // [rsp+8h] [rbp-30h] BYREF

v0 = secondsPerTick * gConfig[14];
v1 = (unsigned int)imageHeight;
result = (unsigned int)(v0 + imageWidth);
if ( (int)result > 0 )
{
v3 = imageHeight - 10;
v4 = imageHeight - 22;
for ( i = 0; ; i += v0 )
{
gdImageLine(imageHandle, i, v3, i, v1, (unsigned int)textColour);
sprintf(
s,
"%02d:%02d:%02d",
(unsigned int)currentTime->tm_hour,
(unsigned int)currentTime->tm_min,
(unsigned int)currentTime->tm_sec);
gdImageString(imageHandle, fontHandle, i - 24, v4, s, (unsigned int)textColour);
result = incrementTime(secondsPerTick);
if ( imageWidth <= (int)i )
break;
v1 = (unsigned int)imageHeight;
}
}
imageHasChanged = 1;
return result;
}

canonical_decompiled_code:
time_t func2()
{
int v0; // ebp
__int64 v1; // r8
time_t result; // rax
unsigned int v3; // er12
unsigned int v4; // er13
unsigned int i; // ebx
char s[48]; // [rsp+8h] [rbp-30h] BYREF

v0 = secondsPerTick * gConfig[14];
v1 = (unsigned int)imageHeight;
result = (unsigned int)(v0 + imageWidth);
if ( (int)result > 0 )
{
v3 = imageHeight - 10;
v4 = imageHeight - 22;
for ( i = 0; ; i += v0 )
{
gdImageLine(imageHandle, i, v3, i, v1, (unsigned int)textColour);
sprintf(
s,
"%02d:%02d:%02d",
(unsigned int)currentTime->tm_hour,
(unsigned int)currentTime->tm_min,
(unsigned int)currentTime->tm_sec);
gdImageString(imageHandle, fontHandle, i - 24, v4, s, (unsigned int)textColour);
result = func1(secondsPerTick);
if ( imageWidth <= (int)i )
break;
v1 = (unsigned int)imageHeight;
}
}
imageHasChanged = 1;
return result;
}

original_code:
void drawTimeLine() {
 int lineHeight = imageHeight - 10;
 int textHeight = imageHeight - 22;
 int pixelsPerTick = gConfig.peaksPerSecond * secondsPerTick;
 int i;
 for (i = 0; i < (imageWidth + pixelsPerTick); i += pixelsPerTick) {
  int position = i;
  gdImageLine(imageHandle, position, lineHeight, position, imageHeight,
    textColour);
  char newTime[8];
  sprintf(newTime, "%02d:%02d:%02d", currentTime->tm_hour,
    currentTime->tm_min, currentTime->tm_sec);
  gdImageString(imageHandle, fontHandle, position - 24, textHeight,
    newTime, textColour);
  incrementTime(secondsPerTick);
 }
 imageHasChanged = 1;
}

variable_types: lineHeight int

variable_types: textHeight int

variable_types: pixelsPerTick int

variable_types: i int

variable_types: position int

variable_types:
newTime
char [8]


startImageFile

decompiled_code:
time_t startImageFile()
{
int v0; // eax

debug(7LL, "Starting a new image file");
imageWidth = gConfig[15] * gConfig[14];
imageHandle = gdImageCreateTrueColor((unsigned int)imageWidth, (unsigned int)imageHeight);
fontHandle = gdFontGetSmall();
waveformColour = gdImageColorAllocate(imageHandle, 0LL, 255LL, 0LL);
v0 = gdImageColorAllocate(imageHandle, 255LL, 255LL, 255LL);
currentPixel = 0;
textColour = v0;
return drawTimeLine();
}

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

debug(7LL, "Starting a new image file");
imageWidth = gConfig[15] * gConfig[14];
imageHandle = gdImageCreateTrueColor((unsigned int)imageWidth, (unsigned int)imageHeight);
fontHandle = gdFontGetSmall();
waveformColour = gdImageColorAllocate(imageHandle, 0LL, 255LL, 0LL);
v0 = gdImageColorAllocate(imageHandle, 255LL, 255LL, 255LL);
currentPixel = 0;
textColour = v0;
return func2();
}

original_code:
void startImageFile() {
 debug(7, "Starting a new image file");
 imageWidth = gConfig.peaksPerSecond * gConfig.secondsPerFile;
 imageHandle = gdImageCreateTrueColor(imageWidth, imageHeight);
 fontHandle = gdFontGetSmall();
 waveformColour = gdImageColorAllocate(imageHandle, 0, 255, 0);
 textColour = gdImageColorAllocate(imageHandle, 255, 255, 255);
 currentPixel = 0;
 drawTimeLine();
}


endImageFile

decompiled_code:
time_t endImageFile()
{
debug(7LL, "Closing image file");
updateImageFile(1);
++currentFile;
return incrementTime(-secondsPerTick);
}

canonical_decompiled_code:
time_t func5()
{
debug(7LL, "Closing image file");
func3(1);
++currentFile;
return func1(-secondsPerTick);
}

original_code:
void endImageFile() {
 debug(7, "Closing image file");
 updateImageFile(1);
 currentFile++;
 incrementTime(-secondsPerTick);
}


defaultConfig

original_code:
static void defaultConfig()
{
 gConfig.inputFile = "";
 gConfig.outputPath = "";
 gConfig.baseFileName = "waveform_";
 gConfig.startTime = "00:00:00";
 gConfig.peaksPerSecond = 16;
 gConfig.secondsPerFile = 300;
 gConfig.sampleRate = 44100;
 gConfig.channels = 1;
 gConfig.fileStartOffset = 0;
 gConfig.waitTime = 1;
 gConfig.timesToCheck = 5;
}


debug

decompiled_code:
int debug(int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = (int)arg[0].reg_save_area;
if ( debugLevel >= a1 )
{
vfprintf(stderr, a2, arg);
fputc(10, stderr);
result = fflush(stderr);
}
return result;
}

canonical_decompiled_code:
int func3(int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = (int)arg[0].reg_save_area;
if ( debugLevel >= a1 )
{
vfprintf(stderr, a2, arg);
fputc(10, stderr);
result = fflush(stderr);
}
return result;
}

original_code:
void debug(int level, const char * template, ...)
{
 va_list ap;
 __builtin_va_start(ap,template);
 if (debugLevel < level) return;
 vfprintf(stderr, template, ap);
 fprintf(stderr,"\n");
 fflush(stderr);
 __builtin_va_end(ap);
 return;
}

canonical_original_code:
void debug(int level, char *template, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,template);
 if (debugLevel < level) return;
 vfprintf(stderr, template, ap);
 fprintf(stderr,"\n");
 fflush(stderr);
 __builtin_va_end(ap);
 return;
}

variable_types: level int

variable_types:
template
char *


readArguments

decompiled_code:
__int64 __fastcall readArguments(int a1, __int64 a2)
{
int v2; // eax
int v3; // ebx
__int64 v4; // rcx
_BYTE *v5; // rdx
int v6; // eax
float v7; // xmm0_4
int v8; // eax
__int64 result; // rax

v2 = 1;
if ( a1 > 1 )
{
do
{
v3 = v2 + 1;
v4 = 8LL * v2;
v5 = *(_BYTE **)(a2 + v4);
if ( *v5 == 45 )
{
switch ( v5[1] )
{
case 'c':
v3 = v2 + 2;
*((_DWORD *)&gConfig + 9) = atoi(*(const char **)(a2 + v4 + 8));
break;
case 'f':
v3 = v2 + 2;
*(&gConfig + 2) = *(_QWORD *)(a2 + v4 + 8);
break;
case 'i':
v3 = v2 + 2;
gConfig = *(_QWORD *)(a2 + v4 + 8);
break;
case 'l':
v3 = v2 + 2;
*((_DWORD *)&gConfig + 15) = atoi(*(const char **)(a2 + v4 + 8));
break;
case 'n':
v3 = v2 + 2;
*((_DWORD *)&gConfig + 11) = atoi(*(const char **)(a2 + v4 + 8));
break;
case 'o':
v3 = v2 + 2;
*(&gConfig + 1) = *(_QWORD *)(a2 + v4 + 8);
break;
case 'p':
v3 = v2 + 2;
*((_DWORD *)&gConfig + 14) = atoi(*(const char **)(a2 + v4 + 8));
break;
case 'r':
v3 = v2 + 2;
*((_DWORD *)&gConfig + 8) = atoi(*(const char **)(a2 + v4 + 8));
break;
case 's':
v3 = v2 + 2;
*(&gConfig + 6) = atol(*(const char **)(a2 + v4 + 8));
break;
case 't':
v3 = v2 + 2;
*(&gConfig + 3) = *(_QWORD *)(a2 + v4 + 8);
break;
case 'w':
v3 = v2 + 2;
*((_DWORD *)&gConfig + 10) = atoi(*(const char **)(a2 + v4 + 8));
break;
default:
break;
}
}
v2 = v3;
}
while ( a1 > v3 );
}
if ( gConfig )
{
if ( *(&gConfig + 1) )
{
v6 = *((_DWORD *)&gConfig + 9);
v7 = (float)*((int *)&gConfig + 14);
if ( v6 != 2 )
v6 = 1;
*((_DWORD *)&gConfig + 9) = v6;
v8 = *((_DWORD *)&gConfig + 8);
if ( v8 != 48000 )
v8 = 44100;
*((_DWORD *)&gConfig + 8) = v8;
*(float *)&peakCoEfficient = v7 / (float)v8;
debug(6, "output path: %s");
debug(6, "input file: %s", (const char *)gConfig);
debug(6, "base file name: %s", (const char *)*(&gConfig + 2));
debug(6, "file offset: %d", *(&gConfig + 6));
debug(6, "sample rate: %d", *((unsigned int *)&gConfig + 8));
debug(6, "peaks per second: %d", *((unsigned int *)&gConfig + 14));
debug(6, "channels: %d", *((unsigned int *)&gConfig + 9));
debug(6, "wait time: %d", *((unsigned int *)&gConfig + 10));
debug(6, "start time: %s", (const char *)*(&gConfig + 3));
debug(6, "seconds per file: %d", *((unsigned int *)&gConfig + 15));
result = 0LL;
}
else
{
debug(1, "You must pass an output file. Use -o <output file>");
result = 1LL;
}
}
else
{
debug(1, "You must pass an input file. Use -i <input file>");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, __int64 a2)
{
int v2; // eax
int v3; // ebx
__int64 v4; // rcx
_BYTE *v5; // rdx
int v6; // eax
float v7; // xmm0_4
int v8; // eax
__int64 result; // rax

v2 = 1;
if ( a1 > 1 )
{
do
{
v3 = v2 + 1;
v4 = 8LL * v2;
v5 = *(_BYTE **)(a2 + v4);
if ( *v5 == 45 )
{
switch ( v5[1] )
{
case 'c':
v3 = v2 + 2;
*((_DWORD *)&gConfig + 9) = atoi(*(const char **)(a2 + v4 + 8));
break;
case 'f':
v3 = v2 + 2;
*(&gConfig + 2) = *(_QWORD *)(a2 + v4 + 8);
break;
case 'i':
v3 = v2 + 2;
gConfig = *(_QWORD *)(a2 + v4 + 8);
break;
case 'l':
v3 = v2 + 2;
*((_DWORD *)&gConfig + 15) = atoi(*(const char **)(a2 + v4 + 8));
break;
case 'n':
v3 = v2 + 2;
*((_DWORD *)&gConfig + 11) = atoi(*(const char **)(a2 + v4 + 8));
break;
case 'o':
v3 = v2 + 2;
*(&gConfig + 1) = *(_QWORD *)(a2 + v4 + 8);
break;
case 'p':
v3 = v2 + 2;
*((_DWORD *)&gConfig + 14) = atoi(*(const char **)(a2 + v4 + 8));
break;
case 'r':
v3 = v2 + 2;
*((_DWORD *)&gConfig + 8) = atoi(*(const char **)(a2 + v4 + 8));
break;
case 's':
v3 = v2 + 2;
*(&gConfig + 6) = atol(*(const char **)(a2 + v4 + 8));
break;
case 't':
v3 = v2 + 2;
*(&gConfig + 3) = *(_QWORD *)(a2 + v4 + 8);
break;
case 'w':
v3 = v2 + 2;
*((_DWORD *)&gConfig + 10) = atoi(*(const char **)(a2 + v4 + 8));
break;
default:
break;
}
}
v2 = v3;
}
while ( a1 > v3 );
}
if ( gConfig )
{
if ( *(&gConfig + 1) )
{
v6 = *((_DWORD *)&gConfig + 9);
v7 = (float)*((int *)&gConfig + 14);
if ( v6 != 2 )
v6 = 1;
*((_DWORD *)&gConfig + 9) = v6;
v8 = *((_DWORD *)&gConfig + 8);
if ( v8 != 48000 )
v8 = 44100;
*((_DWORD *)&gConfig + 8) = v8;
*(float *)&peakCoEfficient = v7 / (float)v8;
func3(6, "output path: %s");
func3(6, "input file: %s", (const char *)gConfig);
func3(6, "base file name: %s", (const char *)*(&gConfig + 2));
func3(6, "file offset: %d", *(&gConfig + 6));
func3(6, "sample rate: %d", *((unsigned int *)&gConfig + 8));
func3(6, "peaks per second: %d", *((unsigned int *)&gConfig + 14));
func3(6, "channels: %d", *((unsigned int *)&gConfig + 9));
func3(6, "wait time: %d", *((unsigned int *)&gConfig + 10));
func3(6, "start time: %s", (const char *)*(&gConfig + 3));
func3(6, "seconds per file: %d", *((unsigned int *)&gConfig + 15));
result = 0LL;
}
else
{
func3(1, "You must pass an output file. Use -o <output file>");
result = 1LL;
}
}
else
{
func3(1, "You must pass an input file. Use -i <input file>");
result = 1LL;
}
return result;
}

original_code:
static int readArguments(int argc, char** argv)
{
 int opts;
 for (opts = 1; opts < argc; opts++) {
  if (argv[opts][0] == '-') {
   switch (argv[opts][1]) {
   case 'i':
    gConfig.inputFile = argv[++opts];
    break;
   case 'o':
    gConfig.outputPath = argv[++opts];
    break;
   case 'f':
    gConfig.baseFileName = argv[++opts];
    break;
   case 'r':
    gConfig.sampleRate = atoi(argv[++opts]);
    break;
   case 'p':
    gConfig.peaksPerSecond = atoi(argv[++opts]);
    break;
   case 's':
    gConfig.fileStartOffset = atol(argv[++opts]);
    break;
   case 'c':
    gConfig.channels = atoi(argv[++opts]);
    break;
   case 'w':
    gConfig.waitTime = atoi(argv[++opts]);
    break;
   case 'n':
    gConfig.timesToCheck = atoi(argv[++opts]);
    break;
   case 't':
    gConfig.startTime = argv[++opts];
    break;
   case 'l':
    gConfig.secondsPerFile = atoi(argv[++opts]);
    break;
   }
  }
 }
 if (gConfig.inputFile == ((void *)0))
 {
  debug(1, "You must pass an input file. Use -i <input file>");
  return 1;
 }
 if (gConfig.outputPath == ((void *)0))
 {
  debug(1, "You must pass an output file. Use -o <output file>");
  return 1;
 }
 switch (gConfig.channels)
 {
  case 2:
   gConfig.channels = 2;
   break;
  default:
   gConfig.channels = 1;
   break;
 }
 switch (gConfig.sampleRate)
 {
  case 48000:
   gConfig.sampleRate = 48000;
   break;
  default:
   gConfig.sampleRate = 44100;
   break;
 }
 peakCoEfficient = (float) gConfig.peaksPerSecond / (float) gConfig.sampleRate;
 debug(6, "output path: %s", gConfig.outputPath);
 debug(6, "input file: %s", gConfig.inputFile);
 debug(6, "base file name: %s", gConfig.baseFileName);
 debug(6, "file offset: %d", gConfig.fileStartOffset);
 debug(6, "sample rate: %d", gConfig.sampleRate);
 debug(6, "peaks per second: %d", gConfig.peaksPerSecond);
 debug(6, "channels: %d", gConfig.channels);
 debug(6, "wait time: %d", gConfig.waitTime);
 debug(6, "start time: %s", gConfig.startTime);
 debug(6, "seconds per file: %d", gConfig.secondsPerFile);
 return 0;
}

canonical_original_code:
static int readArguments(int argc, char **argv)
{
 int opts;
 for (opts = 1; opts < argc; opts++) {
  if (argv[opts][0] == '-') {
   switch (argv[opts][1]) {
   case 'i':
    gConfig.inputFile = argv[++opts];
    break;
   case 'o':
    gConfig.outputPath = argv[++opts];
    break;
   case 'f':
    gConfig.baseFileName = argv[++opts];
    break;
   case 'r':
    gConfig.sampleRate = atoi(argv[++opts]);
    break;
   case 'p':
    gConfig.peaksPerSecond = atoi(argv[++opts]);
    break;
   case 's':
    gConfig.fileStartOffset = atol(argv[++opts]);
    break;
   case 'c':
    gConfig.channels = atoi(argv[++opts]);
    break;
   case 'w':
    gConfig.waitTime = atoi(argv[++opts]);
    break;
   case 'n':
    gConfig.timesToCheck = atoi(argv[++opts]);
    break;
   case 't':
    gConfig.startTime = argv[++opts];
    break;
   case 'l':
    gConfig.secondsPerFile = atoi(argv[++opts]);
    break;
   }
  }
 }
 if (gConfig.inputFile == ((void *)0))
 {
  debug(1, "You must pass an input file. Use -i <input file>");
  return 1;
 }
 if (gConfig.outputPath == ((void *)0))
 {
  debug(1, "You must pass an output file. Use -o <output file>");
  return 1;
 }
 switch (gConfig.channels)
 {
  case 2:
   gConfig.channels = 2;
   break;
  default:
   gConfig.channels = 1;
   break;
 }
 switch (gConfig.sampleRate)
 {
  case 48000:
   gConfig.sampleRate = 48000;
   break;
  default:
   gConfig.sampleRate = 44100;
   break;
 }
 peakCoEfficient = (float) gConfig.peaksPerSecond / (float) gConfig.sampleRate;
 debug(6, "output path: %s", gConfig.outputPath);
 debug(6, "input file: %s", gConfig.inputFile);
 debug(6, "base file name: %s", gConfig.baseFileName);
 debug(6, "file offset: %d", gConfig.fileStartOffset);
 debug(6, "sample rate: %d", gConfig.sampleRate);
 debug(6, "peaks per second: %d", gConfig.peaksPerSecond);
 debug(6, "channels: %d", gConfig.channels);
 debug(6, "wait time: %d", gConfig.waitTime);
 debug(6, "start time: %s", gConfig.startTime);
 debug(6, "seconds per file: %d", gConfig.secondsPerFile);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opts int

return_type: int


main

canonical_name: main

repo: matthewshafer/crossing

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char v4; // al
__int64 v6[7]; // [rsp+0h] [rbp-38h] BYREF

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "u:p:f:m:");
if ( v4 == -1 )
break;
if ( v4 == 112 )
{
v3 += 100;
v6[1] = (__int64)optarg;
}
else if ( v4 > 112 )
{
if ( v4 == 117 )
{
v3 += 1000;
v6[0] = (__int64)optarg;
}
}
else if ( v4 == 102 )
{
v3 += 10;
v6[2] = (__int64)optarg;
}
else if ( v4 == 109 )
{
++v3;
v6[3] = (__int64)optarg;
}
}
if ( v3 == 1111 )
crossing_send_notification(v6);
else
puts("not enough args");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 crossing_data userdata;
 char c;
 int flags = 0;
 while((c = getopt(argc, argv, "u:p:f:m:")) != -1)
 {
  switch(c)
  {
   case 'u':
    userdata.username = optarg;
    flags += 1000;
    break;
   case 'p':
    userdata.password = optarg;
    flags += 100;
    break;
   case 'f':
    userdata.from = optarg;
    flags += 10;
    break;
   case 'm':
    userdata.message = optarg;
    flags += 1;
    break;
  }
 }
 if(flags == 1111)
 {
  crossing_send_notification(&userdata);
 }
 else
 {
  printf("not enough args\n");
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct crossing_data userdata;
 char c;
 int flags = 0;
 while((c = getopt(argc, argv, "u:p:f:m:")) != -1)
 {
  switch(c)
  {
   case 'u':
    userdata.username = optarg;
    flags += 1000;
    break;
   case 'p':
    userdata.password = optarg;
    flags += 100;
    break;
   case 'f':
    userdata.from = optarg;
    flags += 10;
    break;
   case 'm':
    userdata.message = optarg;
    flags += 1;
    break;
  }
 }
 if(flags == 1111)
 {
  crossing_send_notification(&userdata);
 }
 else
 {
  printf("not enough args\n");
 }
 return 0;
}

variable_types:
argv
char *[]

variable_types: struct crossing_data { char *username; char *password; char *from; char *message; }

variable_types: c char

variable_types: flags int


repo: matthiaskramm/cagekeeper

decompiled_code:
__int64 __fastcall add2(__int64 a1, int a2, int a3)
{
return (unsigned int)(a2 + a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, int a3)
{
return (unsigned int)(a2 + a3);
}

original_code:
static int add2(void*context, int x, int y)
{
    return x+y;
}

canonical_original_code:
static int add2(void *context, int x, int y)
{
    return x+y;
}

variable_types:
context
void *

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall add3(__int64 a1, int a2, int a3, int a4)
{
return (unsigned int)(a3 + a2 + a4);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int a3, int a4)
{
return (unsigned int)(a3 + a2 + a4);
}

original_code:
static int add3(void*context, int x, int y, int z)
{
    return x+y+z;
}

canonical_original_code:
static int add3(void *context, int x, int y, int z)
{
    return x+y+z;
}

variable_types: z int


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

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

original_code:
static float fadd2(void*context, float x, float y)
{
    return x+y;
}

canonical_original_code:
static float fadd2(void *context, float x, float y)
{
    return x+y;
}

variable_types: x float

variable_types: y float

return_type: float


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

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

original_code:
static float fadd3(void*context, float x, float y, float z)
{
    return x+y+z;
}

canonical_original_code:
static float fadd3(void *context, float x, float y, float z)
{
    return x+y+z;
}

variable_types: z float


negate

decompiled_code:
__int64 __fastcall negate(__int64 a1, int a2)
{
return a2 ^ 1u;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
return a2 ^ 1u;
}

original_code:
static _Bool negate(void*context, _Bool b)
{
    return !b;
}

canonical_original_code:
static _Bool negate(void *context, _Bool b)
{
    return !b;
}


decompiled_code:
__int64 __fastcall get_array(__int64 a1, int a2, int a3)
{
__int64 v4; // r14
int v5; // er12
int v6; // er15
__int64 v7; // rbp
unsigned int v8; // ebx
__int64 v9; // rsi

v4 = array_new();
if ( a2 > 0 )
{
v5 = a3;
v6 = a3 + 10 * a2;
do
{
v7 = array_new();
if ( a3 > 0 )
{
v8 = v5 - a3;
do
{
v9 = v8++;
array_append_int32(v7, v9);
}
while ( v5 != v8 );
}
v5 += 10;
array_append(v4, v7);
}
while ( v5 != v6 );
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, int a3)
{
__int64 v4; // r14
int v5; // er12
int v6; // er15
__int64 v7; // rbp
unsigned int v8; // ebx
__int64 v9; // rsi

v4 = array_new();
if ( a2 > 0 )
{
v5 = a3;
v6 = a3 + 10 * a2;
do
{
v7 = array_new();
if ( a3 > 0 )
{
v8 = v5 - a3;
do
{
v9 = v8++;
array_append_int32(v7, v9);
}
while ( v5 != v8 );
}
v5 += 10;
array_append(v4, v7);
}
while ( v5 != v6 );
}
return v4;
}

original_code:
static value_t* get_array(void*context, int width, int height)
{
    value_t*columns = array_new();
    int x;
    for(x=0;x<width;x++) {
        int y;
        value_t*column = array_new();
        for(y=0;y<height;y++) {
            array_append_int32(column, x*10+y);
        }
        array_append(columns, column);
    }
    return columns;
}

canonical_original_code:
static struct _value *get_array(void *context, int width, int height)
{
    struct _value *columns = array_new();
    int x;
    for(x=0;x<width;x++) {
        int y;
        struct _value *column = array_new();
        for(y=0;y<height;y++) {
            array_append_int32(column, x*10+y);
        }
        array_append(columns, column);
    }
    return columns;
}

variable_types: width int

variable_types: height int

variable_types: struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *

user_defined_types: struct _value { enum _type type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); }


original_code:
static value_t* concat_arrays(void*context, value_t*array1, value_t*array2)
{
    int i;
    value_t*a = array_new();
    for(i=0;i<array1->length;i++) {
        array_append(a, value_clone(array1->data[i]));
    }
    for(i=0;i<array2->length;i++) {
        array_append(a, value_clone(array2->data[i]));
    }
    return a;
}

canonical_original_code:
static struct _value *concat_arrays(void *context, struct _value *array1, struct _value *array2)
{
    int i;
    struct _value *a = array_new();
    for(i=0;i<array1->length;i++) {
        array_append(a, value_clone(array1->data[i]));
    }
    for(i=0;i<array2->length;i++) {
        array_append(a, value_clone(array2->data[i]));
    }
    return a;
}

variable_types: i int

return_type: struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *


decompiled_code:
char *__fastcall concat_strings(__int64 a1, const char *a2, const char *a3)
{
int v4; // ebx
int v5; // ebp
char *v6; // r12

v4 = strlen(a2);
v5 = strlen(a3);
v6 = (char *)malloc(v5 + v4 + 1);
memcpy(v6, a2, v4);
memcpy(&v6[v4], a3, v5);
v6[v5 + v4] = 0;
return v6;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 a1, const char *a2, const char *a3)
{
int v4; // ebx
int v5; // ebp
char *v6; // r12

v4 = strlen(a2);
v5 = strlen(a3);
v6 = (char *)malloc(v5 + v4 + 1);
memcpy(v6, a2, v4);
memcpy(&v6[v4], a3, v5);
v6[v5 + v4] = 0;
return v6;
}

original_code:
static char* concat_strings(void*context, char*s1, char*s2)
{
    int l1 = strlen(s1);
    int l2 = strlen(s2);
    char*tmp = malloc(l1+l2+1);
    memcpy(tmp, s1, l1);
    memcpy(tmp+l1, s2, l2);
    tmp[l1+l2] = 0;
    return tmp;
}

canonical_original_code:
static char *concat_strings(void *context, char *s1, char *s2)
{
    int l1 = strlen(s1);
    int l2 = strlen(s2);
    char *tmp = malloc(l1+l2+1);
    memcpy(tmp, s1, l1);
    memcpy(tmp+l1, s2, l2);
    tmp[l1+l2] = 0;
    return tmp;
}

variable_types:
tmp
char *


trace

decompiled_code:
int __fastcall trace(__int64 a1, const char *a2)
{
return puts(a2);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, const char *a2)
{
return puts(a2);
}

original_code:
static void trace(void*context, char*s)
{
    printf("%s\n", s);
}

canonical_original_code:
static void trace(void *context, char *s)
{
    printf("%s\n", s);
}

variable_types:
s
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r11
const char **v4; // rax
int v5; // ecx
char v6; // r9
const char **v7; // r8
__int64 v8; // rdi
const char *v9; // rdx
const char *v10; // r12
const char *v11; // rdi
__int64 v12; // rbx
void (__fastcall *v13)(__int64, const char *, __int64); // rbp
__int64 v14; // rax
void (__fastcall *v15)(__int64, const char *, __int64); // rbp
__int64 v16; // rax
void (__fastcall *v17)(__int64, const char *, __int64); // rbp
__int64 v18; // rax
void (__fastcall *v19)(__int64, const char *, __int64); // rbp
__int64 v20; // rax
void (__fastcall *v21)(__int64, const char *, __int64); // rbp
__int64 v22; // rax
__int64 v23; // rsi
__int64 v24; // rbp
int result; // eax
__int64 v26; // r12
__int64 v27; // rdi
__int64 v28; // rsi
__int64 v29; // rax
__int64 v30; // r12
__int64 v31; // rax
__int64 v32; // rsi
__int64 v33; // rax
__int64 v34; // r12
__int64 v35; // rbp
__int64 v36; // rax
__int64 v37; // rsi
__int64 v38; // rax
__int64 v39; // r12
__int64 v40; // r12
__int64 v41; // r12
__int64 v42; // r12

v3 = *argv;
if ( argc <= 1 )
goto LABEL_39;
v4 = argv + 1;
v5 = 0;
v6 = 1;
v7 = &argv[(unsigned int)(argc - 2) + 2];
do
{
while ( 1 )
{
v9 = *v4;
if ( **v4 == 45 )
break;
v8 = v5;
++v4;
++v5;
argv[v8] = v9;
if ( v7 == v4 )
goto LABEL_8;
}
if ( v9[1] == 117 )
v6 = 0;
++v4;
}
while ( v7 != v4 );
LABEL_8:
if ( !v5 )
{
LABEL_39:
printf("Usage:\n\t%s <program>\n", v3);
exit(1);
}
v10 = *argv;
v11 = *argv;
if ( v6 )
v12 = interpreter_by_extension(v11);
else
v12 = unsafe_interpreter_by_extension(v11);
if ( v12 )
{
define_function(v12, "trace", trace, 0LL, "s", &LC1);
define_function(v12, "get_array", get_array, 0LL, "ii", "[");
define_function(v12, "add2", add2, 0LL, "ii", "i");
define_function(v12, "add3", add3, 0LL, "iii", "i");
define_function(v12, "fadd2", fadd2, 0LL, "ff", "f");
define_function(v12, "fadd3", fadd3, 0LL, "fff", "f");
define_function(v12, "concat_strings", concat_strings, 0LL, "ss", "s");
define_function(v12, "concat_arrays", concat_arrays, 0LL, "[[", "[");
define_function(v12, "negate", negate, 0LL, "b", "b");
v13 = *(void (__fastcall **)(__int64, const char *, __int64))(v12 + 32);
v14 = value_new_int32(3LL);
v13(v12, "global_int", v14);
v15 = *(void (__fastcall **)(__int64, const char *, __int64))(v12 + 32);
v16 = value_new_array();
v15(v12, "global_array", v16);
v17 = *(void (__fastcall **)(__int64, const char *, __int64))(v12 + 32);
v18 = value_new_boolean(1LL);
v17(v12, "global_boolean", v18);
v19 = *(void (__fastcall **)(__int64, const char *, __int64))(v12 + 32);
v20 = value_new_float32(3.0);
v19(v12, "global_float", v20);
v21 = *(void (__fastcall **)(__int64, const char *, __int64))(v12 + 32);
v22 = value_new_string("foobar");
v21(v12, "global_string", v22);
v23 = read_file(v10);
if ( v23 )
{
if ( (*(unsigned __int8 (__fastcall **)(__int64, __int64))(v12 + 48))(v12, v23) )
{
v24 = 0LL;
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v12 + 56))(v12, "call_noargs") )
{
v26 = value_new_array();
v24 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v12 + 64))(v12, "call_noargs", v26);
value_destroy(v26);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v12 + 56))(v12, "call_int") )
{
v42 = value_new_array();
array_append_int32(v42, 0LL);
v24 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v12 + 64))(v12, "call_int", v42);
value_destroy(v42);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v12 + 56))(v12, "call_float") )
{
v41 = value_new_array();
array_append_float32(v41, 0.0);
v24 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v12 + 64))(v12, "call_float", v41);
value_destroy(v41);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v12 + 56))(v12, "call_string") )
{
v40 = value_new_array();
array_append_string(v40, "foobar");
v24 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v12 + 64))(v12, "call_string", v40);
value_destroy(v40);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v12 + 56))(v12, "call_boolean") )
{
v39 = value_new_array();
array_append_boolean(v39, 0LL);
v24 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v12 + 64))(v12, "call_boolean", v39);
value_destroy(v39);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v12 + 56))(v12, "call_array") )
{
v34 = value_new_array();
v35 = value_new_array();
v36 = value_new_int32(1LL);
array_append(v35, v36);
v37 = value_new_int32(2LL);
array_append(v35, v37);
v38 = value_new_int32(3LL);
array_append(v35, v38);
array_append(v34, v35);
v24 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v12 + 64))(v12, "call_array", v34);
value_destroy(v34);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v12 + 56))(v12, "call_int_and_float_and_string") )
{
v30 = value_new_array();
v31 = value_new_int32(1LL);
array_append(v30, v31);
v32 = value_new_float32(2.0);
array_append(v30, v32);
v33 = value_new_string("foobar");
array_append(v30, v33);
v24 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v12 + 64))(
v12,
"call_int_and_float_and_string",
v30);
value_destroy(v30);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v12 + 56))(v12, "call_boolean_and_array") )
{
v27 = value_new_array();
v28 = value_new_boolean(1LL);
array_append(v27, v28);
v29 = value_new_array();
array_append(v27, v29);
v24 = (*(__int64 (__fastcall **)(__int64, const char *, __int64))(v12 + 64))(
v12,
"call_boolean_and_array",
v27);
value_destroy(v27);
}
if ( (*(unsigned __int8 (__fastcall **)(__int64, const char *))(v12 + 56))(v12, "test") )
v24 = (*(__int64 (__fastcall **)(__int64, const char *, void *))(v12 + 64))(v12, "test", &empty_array);
(*(void (__fastcall **)(__int64))(v12 + 72))(v12);
if ( v24 && *(_DWORD *)v24 == 4 )
{
fputs(*(const char **)(v24 + 16), stdout);
fputc(10, stdout);
result = strcmp(*(const char **)(v24 + 16), "ok") != 0;
}
else
{
value_dump(v24);
fputc(10, stdout);
result = 1;
}
}
else
{
fwrite("Error compiling script\n", 1uLL, 0x17uLL, stderr);
(*(void (__fastcall **)(__int64))(v12 + 72))(v12);
result = 1;
}
}
else
{
fprintf(stderr, "Error reading script %s\n", v10);
result = 1;
}
}
else
{
fprintf(stderr, "Couldn't initialize %sinterpreter for %s\n", (const char *)&LC1, v10);
result = 1;
}
return result;
}

original_code:
int main(int argn, char*argv[])
{
    char*program = argv[0];
    _Bool sandbox = 1;
    int i,j=0;
    for(i=1;i<argn;i++) {
        if(argv[i][0]=='-') {
            switch(argv[i][1]) {
                case 'u':
                    sandbox = 0;
                break;
            }
        } else {
            argv[j++] = argv[i];
        }
    }
    argn = j;
    if(argn < 1) {
        printf("Usage:\n\t%s <program>\n", program);
        exit(1);
    }
    char*filename = argv[0];
    language_t*l;
    if(sandbox) {
        l = interpreter_by_extension(filename);
    } else {
        l = unsafe_interpreter_by_extension(filename);
    }
    if(!l) {
        fprintf(stderr, "Couldn't initialize %sinterpreter for %s\n", l?"sandboxed":"", filename);
        return 1;
    }
    define_function(l, "trace", trace, ((void *)0), "s",""),
    define_function(l, "get_array", get_array, ((void *)0), "ii","["),
    define_function(l, "add2", add2, ((void *)0), "ii", "i"),
    define_function(l, "add3", add3, ((void *)0), "iii", "i"),
    define_function(l, "fadd2", fadd2, ((void *)0), "ff", "f"),
    define_function(l, "fadd3", fadd3, ((void *)0), "fff", "f"),
    define_function(l, "concat_strings", concat_strings, ((void *)0), "ss", "s"),
    define_function(l, "concat_arrays", concat_arrays, ((void *)0), "[[", "["),
    define_function(l, "negate", negate, ((void *)0), "b", "b"),
    l->define_constant(l, "global_int", value_new_int32(3));
    l->define_constant(l, "global_array", value_new_array());
    l->define_constant(l, "global_boolean", value_new_boolean(1));
    l->define_constant(l, "global_float", value_new_float32(3.0));
    l->define_constant(l, "global_string", value_new_string("foobar"));
    char* script = read_file(filename);
    if(!script) {
        fprintf(stderr, "Error reading script %s\n", filename);
        return 1;
    }
    _Bool compiled = l->compile_script(l, script);
    if(!compiled) {
        fprintf(stderr, "Error compiling script\n");
        l->destroy(l);
        return 1;
    }
    value_t*ret = ((void *)0);
    if(l->is_function(l, "call_noargs")) {
        value_t*args = value_new_array();
        ret = l->call_function(l, "call_noargs", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_int")) {
        value_t*args = value_new_array();
        array_append_int32(args, 0);
        ret = l->call_function(l, "call_int", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_float")) {
        value_t*args = value_new_array();
        array_append_float32(args, 0);
        ret = l->call_function(l, "call_float", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_string")) {
        value_t*args = value_new_array();
        array_append_string(args, "foobar");
        ret = l->call_function(l, "call_string", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_boolean")) {
        value_t*args = value_new_array();
        array_append_boolean(args, 0);
        ret = l->call_function(l, "call_boolean", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_array")) {
        value_t*args = value_new_array();
        value_t*a = value_new_array();
        array_append(a, value_new_int32(1));
        array_append(a, value_new_int32(2));
        array_append(a, value_new_int32(3));
        array_append(args, a);
        ret = l->call_function(l, "call_array", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_int_and_float_and_string")) {
        value_t*args = value_new_array();
        array_append(args, value_new_int32(1));
        array_append(args, value_new_float32(2));
        array_append(args, value_new_string("foobar"));
        ret = l->call_function(l, "call_int_and_float_and_string", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_boolean_and_array")) {
        value_t*args = value_new_array();
        array_append(args, value_new_boolean(1));
        array_append(args, value_new_array());
        ret = l->call_function(l, "call_boolean_and_array", args);
        value_destroy(args);
    }
    if(l->is_function(l, "test")) {
        ret = l->call_function(l, "test", (&empty_array));
    }
    l->destroy(l);
    if(ret && ret->type == TYPE_STRING) {
        fputs(ret->str, stdout);
        fputc('\n', stdout);
        if(!strcmp(ret->str, "ok"))
            return 0;
        else
            return 1;
    } else {
        value_dump(ret);
        fputc('\n', stdout);
        return 1;
    }
}

canonical_original_code:
int main(int argn, char *argv[])
{
    char *program = argv[0];
    _Bool sandbox = 1;
    int i; int j = 0;
    for(i=1;i<argn;i++) {
        if(argv[i][0]=='-') {
            switch(argv[i][1]) {
                case 'u':
                    sandbox = 0;
                break;
            }
        } else {
            argv[j++] = argv[i];
        }
    }
    argn = j;
    if(argn < 1) {
        printf("Usage:\n\t%s <program>\n", program);
        exit(1);
    }
    char *filename = argv[0];
    struct _language *l;
    if(sandbox) {
        l = interpreter_by_extension(filename);
    } else {
        l = unsafe_interpreter_by_extension(filename);
    }
    if(!l) {
        fprintf(stderr, "Couldn't initialize %sinterpreter for %s\n", l?"sandboxed":"", filename);
        return 1;
    }
    define_function(l, "trace", trace, ((void *)0), "s",""),
    define_function(l, "get_array", get_array, ((void *)0), "ii","["),
    define_function(l, "add2", add2, ((void *)0), "ii", "i"),
    define_function(l, "add3", add3, ((void *)0), "iii", "i"),
    define_function(l, "fadd2", fadd2, ((void *)0), "ff", "f"),
    define_function(l, "fadd3", fadd3, ((void *)0), "fff", "f"),
    define_function(l, "concat_strings", concat_strings, ((void *)0), "ss", "s"),
    define_function(l, "concat_arrays", concat_arrays, ((void *)0), "[[", "["),
    define_function(l, "negate", negate, ((void *)0), "b", "b"),
    l->define_constant(l, "global_int", value_new_int32(3));
    l->define_constant(l, "global_array", value_new_array());
    l->define_constant(l, "global_boolean", value_new_boolean(1));
    l->define_constant(l, "global_float", value_new_float32(3.0));
    l->define_constant(l, "global_string", value_new_string("foobar"));
    char *script = read_file(filename);
    if(!script) {
        fprintf(stderr, "Error reading script %s\n", filename);
        return 1;
    }
    _Bool compiled = l->compile_script(l, script);
    if(!compiled) {
        fprintf(stderr, "Error compiling script\n");
        l->destroy(l);
        return 1;
    }
    struct _value *ret = ((void *)0);
    if(l->is_function(l, "call_noargs")) {
        struct _value *args = value_new_array();
        ret = l->call_function(l, "call_noargs", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_int")) {
        struct _value *args = value_new_array();
        array_append_int32(args, 0);
        ret = l->call_function(l, "call_int", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_float")) {
        struct _value *args = value_new_array();
        array_append_float32(args, 0);
        ret = l->call_function(l, "call_float", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_string")) {
        struct _value *args = value_new_array();
        array_append_string(args, "foobar");
        ret = l->call_function(l, "call_string", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_boolean")) {
        struct _value *args = value_new_array();
        array_append_boolean(args, 0);
        ret = l->call_function(l, "call_boolean", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_array")) {
        struct _value *args = value_new_array();
        struct _value *a = value_new_array();
        array_append(a, value_new_int32(1));
        array_append(a, value_new_int32(2));
        array_append(a, value_new_int32(3));
        array_append(args, a);
        ret = l->call_function(l, "call_array", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_int_and_float_and_string")) {
        struct _value *args = value_new_array();
        array_append(args, value_new_int32(1));
        array_append(args, value_new_float32(2));
        array_append(args, value_new_string("foobar"));
        ret = l->call_function(l, "call_int_and_float_and_string", args);
        value_destroy(args);
    }
    if(l->is_function(l, "call_boolean_and_array")) {
        struct _value *args = value_new_array();
        array_append(args, value_new_boolean(1));
        array_append(args, value_new_array());
        ret = l->call_function(l, "call_boolean_and_array", args);
        value_destroy(args);
    }
    if(l->is_function(l, "test")) {
        ret = l->call_function(l, "test", (&empty_array));
    }
    l->destroy(l);
    if(ret && ret->type == TYPE_STRING) {
        fputs(ret->str, stdout);
        fputc('\n', stdout);
        if(!strcmp(ret->str, "ok"))
            return 0;
        else
            return 1;
    } else {
        value_dump(ret);
        fputc('\n', stdout);
        return 1;
    }
}

variable_types: argn int

variable_types:
argv
char *[]

variable_types:
program
char *

variable_types: j int

variable_types:
filename
char *

variable_types: struct _language { void *internal; char *name; _Bool timeout; _Bool (*initialize)(struct _language *li, unsigned long maxmem); void (*define_constant)(struct _language *li, char *name, struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *value); void (*define_function)(struct _language *li, char *name, struct _value *f); _Bool (*compile_script)(struct _language *li, char *script); _Bool (*is_function)(struct _language *li, char *name); struct _value *(*call_function)(struct _language *li, char *name, struct _value *args); void (*destroy)(struct _language *li); void *user; void (*log)(void *user, char *line); } *

variable_types:
script
char *

user_defined_types: struct _language { void *internal; char *name; _Bool timeout; _Bool (*initialize)(struct _language *li, unsigned long maxmem); void (*define_constant)(struct _language *li, char *name, struct _value *value); void (*define_function)(struct _language *li, char *name, struct _value *f); _Bool (*compile_script)(struct _language *li, char *script); _Bool (*is_function)(struct _language *li, char *name); struct _value *(*call_function)(struct _language *li, char *name, struct _value *args); void (*destroy)(struct _language *li); void *user; void (*log)(void *user, char *line); }


sigalarm

decompiled_code:
void __noreturn sigalarm()
{
longjmp(timeout_jmp, 1);
}

canonical_decompiled_code:
void __noreturn func0()
{
longjmp(timeout_jmp, 1);
}

original_code:
static void sigalarm(int signal)
{
    longjmp(timeout_jmp, 1);
}

variable_types: signal int


decompiled_code:
__int64 __fastcall raw_interpreter_by_extension(const char *a1)
{
const char *v1; // rbp
char *v2; // rax
__int64 v3; // rcx
const char *v4; // rdi
bool v5; // cf
bool v6; // zf
const char *v7; // rsi
int v8; // eax

v1 = a1;
v2 = strrchr(a1, 46);
v3 = 4LL;
v4 = (const char *)&LC0;
v5 = 0;
v6 = v2 == 0LL;
if ( v2 )
v1 = v2 + 1;
v7 = v1;
do
{
if ( !v3 )
break;
v5 = *v7 < (unsigned int)*v4;
v6 = *v7++ == *v4++;
--v3;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
return lua_interpreter_new(v4, v7);
v8 = *(unsigned __int8 *)v1;
if ( v8 == 112 && v1[1] == 121 && !v1[2] )
return python_interpreter_new(v4, v7);
if ( v8 == 114 && v1[1] == 98 && !v1[2] )
return ruby_interpreter_new(v4, v7);
return javascript_interpreter_new(v4, v7);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
const char *v1; // rbp
char *v2; // rax
__int64 v3; // rcx
const char *v4; // rdi
bool v5; // cf
bool v6; // zf
const char *v7; // rsi
int v8; // eax

v1 = a1;
v2 = strrchr(a1, 46);
v3 = 4LL;
v4 = (const char *)&LC0;
v5 = 0;
v6 = v2 == 0LL;
if ( v2 )
v1 = v2 + 1;
v7 = v1;
do
{
if ( !v3 )
break;
v5 = *v7 < (unsigned int)*v4;
v6 = *v7++ == *v4++;
--v3;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
return lua_interpreter_new(v4, v7);
v8 = *(unsigned __int8 *)v1;
if ( v8 == 112 && v1[1] == 121 && !v1[2] )
return python_interpreter_new(v4, v7);
if ( v8 == 114 && v1[1] == 98 && !v1[2] )
return ruby_interpreter_new(v4, v7);
return javascript_interpreter_new(v4, v7);
}

original_code:
static language_t* raw_interpreter_by_extension(const char*filename)
{
    const char*dot = strrchr(filename, '.');
    const char*extension = dot ? dot+1 : filename;
    language_t*core = ((void *)0);
    if(!strcmp(extension, "lua"))
        return lua_interpreter_new();
    else if(!strcmp(extension, "py"))
        return python_interpreter_new();
    else if(!strcmp(extension, "rb"))
        return ruby_interpreter_new();
    else
        return javascript_interpreter_new();
}

canonical_original_code:
static struct _language *raw_interpreter_by_extension(char *filename)
{
    char *dot = strrchr(filename, '.');
    char *extension = dot ? dot+1 : filename;
    struct _language *core = ((void *)0);
    if(!strcmp(extension, "lua"))
        return lua_interpreter_new();
    else if(!strcmp(extension, "py"))
        return python_interpreter_new();
    else if(!strcmp(extension, "rb"))
        return ruby_interpreter_new();
    else
        return javascript_interpreter_new();
}

variable_types:
dot
char *

variable_types:
extension
char *

return_type: struct _language { void *internal; char *name; _Bool timeout; _Bool (*initialize)(struct _language *li, unsigned long maxmem); void (*define_constant)(struct _language *li, char *name, struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *value); void (*define_function)(struct _language *li, char *name, struct _value *f); _Bool (*compile_script)(struct _language *li, char *script); _Bool (*is_function)(struct _language *li, char *name); struct _value *(*call_function)(struct _language *li, char *name, struct _value *args); void (*destroy)(struct _language *li); void *user; void (*log)(void *user, char *line); } *


decompiled_code:
__int64 __fastcall call_function_with_timeout(__int64 a1, const char *a2, __int64 a3, unsigned int a4, _BYTE *a5)
{
return with_timeout(a1, 0LL, a2, a3, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, __int64 a3, unsigned int a4, _BYTE *a5)
{
return func2(a1, 0LL, a2, a3, a4, a5);
}

original_code:
value_t* call_function_with_timeout(language_t*l, const char*function, value_t*args, int max_seconds, _Bool*timeout)
{
    return with_timeout(l, ((void *)0), function, args, max_seconds, timeout);
}

canonical_original_code:
struct _value *call_function_with_timeout(struct _language *l, char *function, struct _value *args, int max_seconds, _Bool *timeout)
{
    return with_timeout(l, ((void *)0), function, args, max_seconds, timeout);
}

variable_types: struct _language { void *internal; char *name; _Bool timeout; _Bool (*initialize)(struct _language *li, unsigned long maxmem); void (*define_constant)(struct _language *li, char *name, struct _value *value); void (*define_function)(struct _language *li, char *name, struct _value *f); _Bool (*compile_script)(struct _language *li, char *script); _Bool (*is_function)(struct _language *li, char *name); struct _value *(*call_function)(struct _language *li, char *name, struct _value *args); void (*destroy)(struct _language *li); void *user; void (*log)(void *user, char *line); } *

variable_types:
function
char *

variable_types:
args
struct _value *

variable_types:
timeout
_Bool *

user_defined_types: enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 }


decompiled_code:
// attributes: thunk
__int64 __fastcall compile_and_run_function_with_timeout(__int64 a1, __int64 a2, const char *a3, __int64 a4, unsigned int a5, _BYTE *a6)
{
return with_timeout(a1, a2, a3, a4, a5, a6);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, const char *a3, __int64 a4, unsigned int a5, _BYTE *a6)
{
return func2(a1, a2, a3, a4, a5, a6);
}

original_code:
value_t* compile_and_run_function_with_timeout(language_t*l, const char*script, const char*function, value_t*args, int max_seconds, _Bool*timeout)
{
    return with_timeout(l, script, function, args, max_seconds, timeout);
}

canonical_original_code:
struct _value *compile_and_run_function_with_timeout(struct _language *l, char *script, char *function, struct _value *args, int max_seconds, _Bool *timeout)
{
    return with_timeout(l, script, function, args, max_seconds, timeout);
}


decompiled_code:
__int64 __fastcall wrap_sandbox(_QWORD *a1)
{
if ( !*a1 )
return proxy_new();
fwrite("Can't wrap sandbox, language already initialized\n", 1uLL, 0x31uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
if ( !*a1 )
return proxy_new();
fwrite("Can't wrap sandbox, language already initialized\n", 1uLL, 0x31uLL, stderr);
return 0LL;
}

original_code:
language_t* wrap_sandbox(language_t*language)
{
    if(language->internal) {
        fprintf(stderr, "Can't wrap sandbox, language already initialized\n");
        return ((void *)0);
    }
    return proxy_new(language);
}

canonical_original_code:
struct _language *wrap_sandbox(struct _language *language)
{
    if(language->internal) {
        fprintf(stderr, "Can't wrap sandbox, language already initialized\n");
        return ((void *)0);
    }
    return proxy_new(language);
}

variable_types:
language
struct _language *


decompiled_code:
__int64 __fastcall interpreter_by_extension(const char *a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)raw_interpreter_by_extension(a1);
return wrap_sandbox(v1);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)func1(a1);
return func5(v1);
}

original_code:
language_t* interpreter_by_extension(const char*filename)
{
    return wrap_sandbox(raw_interpreter_by_extension(filename));
}

canonical_original_code:
struct _language *interpreter_by_extension(char *filename)
{
    return wrap_sandbox(raw_interpreter_by_extension(filename));
}


decompiled_code:
__int64 __fastcall unsafe_interpreter_by_extension(const char *a1)
{
__int64 v1; // r12

v1 = raw_interpreter_by_extension(a1);
if ( (*(unsigned __int8 (__fastcall **)(__int64, _QWORD))(v1 + 24))(v1, config_maxmem) )
return v1;
(*(void (__fastcall **)(__int64))(v1 + 72))(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
__int64 v1; // r12

v1 = func1(a1);
if ( (*(unsigned __int8 (__fastcall **)(__int64, _QWORD))(v1 + 24))(v1, config_maxmem) )
return v1;
(*(void (__fastcall **)(__int64))(v1 + 72))(v1);
return 0LL;
}

original_code:
language_t* unsafe_interpreter_by_extension(const char*filename)
{
    language_t*li = raw_interpreter_by_extension(filename);
    _Bool ret = li->initialize(li, config_maxmem);
    if(!ret) {
        li->destroy(li);
        return ((void *)0);
    }
    return li;
}

canonical_original_code:
struct _language *unsafe_interpreter_by_extension(char *filename)
{
    struct _language *li = raw_interpreter_by_extension(filename);
    _Bool ret = li->initialize(li, config_maxmem);
    if(!ret) {
        li->destroy(li);
        return ((void *)0);
    }
    return li;
}


decompiled_code:
__int64 __fastcall define_int_constant(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rbp

v3 = value_new_int32(a3);
(*(void (__fastcall **)(__int64, __int64, __int64))(a1 + 32))(a1, a2, v3);
return value_destroy(v3);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rbp

v3 = value_new_int32(a3);
(*(void (__fastcall **)(__int64, __int64, __int64))(a1 + 32))(a1, a2, v3);
return value_destroy(v3);
}

original_code:
void define_int_constant(language_t*li, const char*name, int i)
{
    value_t* v = value_new_int32(i);
    li->define_constant(li, name, v);
    value_destroy(v);
}

canonical_original_code:
void define_int_constant(struct _language *li, char *name, int i)
{
    struct _value *v = value_new_int32(i);
    li->define_constant(li, name, v);
    value_destroy(v);
}

variable_types:
name
char *

variable_types: i int

variable_types: struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *


decompiled_code:
__int64 __fastcall define_string_constant(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbp

v3 = value_new_string(a3);
(*(void (__fastcall **)(__int64, __int64, __int64))(a1 + 32))(a1, a2, v3);
return value_destroy(v3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbp

v3 = value_new_string(a3);
(*(void (__fastcall **)(__int64, __int64, __int64))(a1 + 32))(a1, a2, v3);
return value_destroy(v3);
}

original_code:
void define_string_constant(language_t*li, const char*name, const char*s)
{
    value_t* v = value_new_string(s);
    li->define_constant(li, name, v);
    value_destroy(v);
}

canonical_original_code:
void define_string_constant(struct _language *li, char *name, char *s)
{
    struct _value *v = value_new_string(s);
    li->define_constant(li, name, v);
    value_destroy(v);
}

variable_types:
s
char *


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

v2 = value_new_cfunction();
return (*(__int64 (__fastcall **)(__int64, __int64, __int64))(a1 + 40))(a1, a2, v2);
}

original_code:
void define_function(language_t*li, const char*name, void*call, void*context, const char*params, const char*ret)
{
    value_t* v = value_new_cfunction(li, name, call, context, params, ret);
    li->define_function(li, name, v);
}

canonical_original_code:
void define_function(struct _language *li, char *name, void *call, void *context, char *params, char *ret)
{
    struct _value *v = value_new_cfunction(li, name, call, context, params, ret);
    li->define_function(li, name, v);
}

variable_types:
call
void *

variable_types:
context
void *

variable_types:
params
char *

variable_types:
ret
char *


decompiled_code:
__int64 __fastcall call_int_function(__int64 a1, __int64 a2)
{
__int64 v2; // r13
_DWORD *v3; // rbp
unsigned int v4; // er12

v2 = array_new();
v3 = (_DWORD *)(*(__int64 (__fastcall **)(__int64, __int64, __int64))(a1 + 64))(a1, a2, v2);
value_destroy(v2);
if ( *v3 == 2 )
{
v4 = v3[4];
}
else
{
v4 = -1;
language_error(a1, "expected return value to be an integer");
}
value_destroy(v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v2; // r13
_DWORD *v3; // rbp
unsigned int v4; // er12

v2 = array_new();
v3 = (_DWORD *)(*(__int64 (__fastcall **)(__int64, __int64, __int64))(a1 + 64))(a1, a2, v2);
value_destroy(v2);
if ( *v3 == 2 )
{
v4 = v3[4];
}
else
{
v4 = -1;
language_error(a1, "expected return value to be an integer");
}
value_destroy(v3);
return v4;
}

original_code:
int call_int_function(language_t*li, const char*name)
{
    value_t*args = array_new();
    value_t*ret = li->call_function(li, name, args);
    value_destroy(args);
    int r;
    if(ret->type != TYPE_INT32) {
        language_error(li, "expected return value to be an integer");
        r = -1;
    } else {
        r = ret->i32;
    }
    value_destroy(ret);
    return r;
}

canonical_original_code:
int call_int_function(struct _language *li, char *name)
{
    struct _value *args = array_new();
    struct _value *ret = li->call_function(li, name, args);
    value_destroy(args);
    int r;
    if(ret->type != TYPE_INT32) {
        language_error(li, "expected return value to be an integer");
        r = -1;
    } else {
        r = ret->i32;
    }
    value_destroy(ret);
    return r;
}

variable_types: struct _language { void *internal; char *name; _Bool timeout; _Bool (*initialize)(struct _language *li, unsigned long maxmem); void (*define_constant)(struct _language *li, char *name, struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *value); void (*define_function)(struct _language *li, char *name, struct _value *f); _Bool (*compile_script)(struct _language *li, char *script); _Bool (*is_function)(struct _language *li, char *name); struct _value *(*call_function)(struct _language *li, char *name, struct _value *args); void (*destroy)(struct _language *li); void *user; void (*log)(void *user, char *line); } *

variable_types: r int


decompiled_code:
int dbg_printf(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stdout, format, arg);
putchar(10);
return fflush(stdout);
}

canonical_decompiled_code:
int func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stdout, format, arg);
putchar(10);
return fflush(stdout);
}

original_code:
char* dbg_printf(const char*format, ...)
{
    va_list arglist;
    __builtin_va_start(arglist,format);
    vfprintf(stdout, format, arglist);
    printf("\n");
    __builtin_va_end(arglist);
    fflush(stdout);
}

canonical_original_code:
char *dbg_printf(char *format, ...)
{
    __builtin_va_list arglist;
    __builtin_va_start(arglist,format);
    vfprintf(stdout, format, arglist);
    printf("\n");
    __builtin_va_end(arglist);
    fflush(stdout);
}

variable_types:
format
char *


memdup

decompiled_code:
void *__fastcall memdup(void *src, size_t n)
{
void *v2; // rax
void *v3; // r8

v2 = malloc(n);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, n);
return v3;
}

canonical_decompiled_code:
void *__fastcall func1(void *src, size_t n)
{
void *v2; // rax
void *v3; // r8

v2 = malloc(n);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, n);
return v3;
}

original_code:
void*memdup(const void*ptr, size_t size)
{
    void*new_ptr = malloc(size);
    if(!new_ptr)
        return ((void *)0);
    memcpy(new_ptr, ptr, size);
    return new_ptr;
}

canonical_original_code:
void *memdup(void *ptr, unsigned long size)
{
    void *new_ptr = malloc(size);
    if(!new_ptr)
        return ((void *)0);
    memcpy(new_ptr, ptr, size);
    return new_ptr;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

return_type: void *


allocprintf

decompiled_code:
char *allocprintf(char *format, ...)
{
size_t v1; // rbp
char *v2; // r12
char s; // [rsp+Fh] [rbp-F9h] BYREF
gcc_va_list arg; // [rsp+10h] [rbp-F8h] BYREF
gcc_va_list va1; // [rsp+28h] [rbp-E0h] BYREF

va_start(va1, format);
va_start(arg, format);
v1 = vsnprintf(&s, 1uLL, format, arg) + 1;
v2 = (char *)malloc(v1);
vsnprintf(v2, v1, format, va1);
return v2;
}

canonical_decompiled_code:
char *func2(char *format, ...)
{
size_t v1; // rbp
char *v2; // r12
char s; // [rsp+Fh] [rbp-F9h] BYREF
gcc_va_list arg; // [rsp+10h] [rbp-F8h] BYREF
gcc_va_list va1; // [rsp+28h] [rbp-E0h] BYREF

va_start(va1, format);
va_start(arg, format);
v1 = vsnprintf(&s, 1uLL, format, arg) + 1;
v2 = (char *)malloc(v1);
vsnprintf(v2, v1, format, va1);
return v2;
}

original_code:
char* allocprintf(const char*format, ...)
{
    va_list arglist1;
    __builtin_va_start(arglist1,format);
    char dummy;
    int l = vsnprintf(&dummy, 1, format, arglist1);
    __builtin_va_end(arglist1);
    va_list arglist2;
    __builtin_va_start(arglist2,format);
    char*buf = malloc(l+1);
    vsnprintf(buf, l+1, format, arglist2);
    __builtin_va_end(arglist2);
    return buf;
}

canonical_original_code:
char *allocprintf(char *format, ...)
{
    __builtin_va_list arglist1;
    __builtin_va_start(arglist1,format);
    char dummy;
    int l = vsnprintf(&dummy, 1, format, arglist1);
    __builtin_va_end(arglist1);
    __builtin_va_list arglist2;
    __builtin_va_start(arglist2,format);
    char *buf = malloc(l+1);
    vsnprintf(buf, l+1, format, arglist2);
    __builtin_va_end(arglist2);
    return buf;
}

variable_types: dummy char

variable_types: l int

variable_types:
buf
char *


decompiled_code:
void *__fastcall concat_paths(void *src, char *a2)
{
size_t v2; // rbx
int v3; // er12
int v4; // ecx
int v5; // edx
__int64 v6; // r14
char *v7; // rbp
int v8; // eax
void *v9; // r12

LODWORD(v2) = strlen((const char *)src);
v3 = v2;
v4 = strlen(a2);
v5 = v4;
if ( (_DWORD)v2 )
{
v2 = (int)v2;
while ( 1 )
{
v3 = v2;
if ( *((char *)src + v2 - 1) != 47 )
break;
v3 = --v2;
if ( !(_DWORD)v2 )
goto LABEL_6;
}
v6 = v2 + 1;
}
else
{
LABEL_6:
v6 = 1LL;
v2 = 0LL;
}
v7 = a2;
v8 = 0;
if ( v4 > 0 )
{
do
{
if ( *v7 != 47 )
{
v5 = v4 - v8;
goto LABEL_12;
}
++v8;
++v7;
}
while ( v4 != v8 );
v5 = 0;
v7 = &a2[v4];
}
LABEL_12:
v9 = malloc(v3 + v5 + 2);
memcpy(v9, src, v2);
*((_BYTE *)v9 + v2) = 47;
strcpy((char *)v9 + v6, v7);
return v9;
}

canonical_decompiled_code:
void *__fastcall func3(void *src, char *a2)
{
size_t v2; // rbx
int v3; // er12
int v4; // ecx
int v5; // edx
__int64 v6; // r14
char *v7; // rbp
int v8; // eax
void *v9; // r12

LODWORD(v2) = strlen((const char *)src);
v3 = v2;
v4 = strlen(a2);
v5 = v4;
if ( (_DWORD)v2 )
{
v2 = (int)v2;
while ( 1 )
{
v3 = v2;
if ( *((char *)src + v2 - 1) != 47 )
break;
v3 = --v2;
if ( !(_DWORD)v2 )
goto LABEL_6;
}
v6 = v2 + 1;
}
else
{
LABEL_6:
v6 = 1LL;
v2 = 0LL;
}
v7 = a2;
v8 = 0;
if ( v4 > 0 )
{
do
{
if ( *v7 != 47 )
{
v5 = v4 - v8;
goto LABEL_12;
}
++v8;
++v7;
}
while ( v4 != v8 );
v5 = 0;
v7 = &a2[v4];
}
LABEL_12:
v9 = malloc(v3 + v5 + 2);
memcpy(v9, src, v2);
*((_BYTE *)v9 + v2) = 47;
strcpy((char *)v9 + v6, v7);
return v9;
}

original_code:
char* concat_paths(const char*base, const char*add)
{
    int l1 = strlen(base);
    int l2 = strlen(add);
    int pos = 0;
    char*n = 0;
    while(l1 && base[l1-1] == path_seperator)
 l1--;
    while(pos < l2 && add[pos] == path_seperator)
 pos++;
    n = (char*)malloc(l1 + (l2-pos) + 2);
    memcpy(n,base,l1);
    n[l1]=path_seperator;
    strcpy(&n[l1+1],&add[pos]);
    return n;
}

canonical_original_code:
char *concat_paths(char *base, char *add)
{
    int l1 = strlen(base);
    int l2 = strlen(add);
    int pos = 0;
    char *n = 0;
    while(l1 && base[l1-1] == path_seperator)
 l1--;
    while(pos < l2 && add[pos] == path_seperator)
 pos++;
    n = (char *)malloc(l1 + (l2-pos) + 2);
    memcpy(n,base,l1);
    n[l1]=path_seperator;
    strcpy(&n[l1+1],&add[pos]);
    return n;
}

variable_types:
base
char *

variable_types:
add
char *

variable_types: pos int

variable_types:
n
char *


decompiled_code:
int __fastcall mkdir_p(const char *a1)
{
char *v1; // rbp
char v2; // al
char *v3; // rbx

v1 = strdup(a1);
v2 = *v1;
v3 = v1;
if ( *v1 != 47 )
goto LABEL_6;
do
v2 = *++v3;
while ( v2 == 47 );
while ( v2 )
{
while ( 1 )
{
++v3;
if ( v2 != 47 )
break;
*(v3 - 1) = 0;
mkdir(v1, 0x1C0u);
v2 = *v3;
*(v3 - 1) = 47;
if ( !v2 )
return mkdir(v1, 0x1C0u);
}
v2 = *v3;
LABEL_6:
;
}
return mkdir(v1, 0x1C0u);
}

canonical_decompiled_code:
int __fastcall func4(const char *a1)
{
char *v1; // rbp
char v2; // al
char *v3; // rbx

v1 = strdup(a1);
v2 = *v1;
v3 = v1;
if ( *v1 != 47 )
goto LABEL_6;
do
v2 = *++v3;
while ( v2 == 47 );
while ( v2 )
{
while ( 1 )
{
++v3;
if ( v2 != 47 )
break;
*(v3 - 1) = 0;
mkdir(v1, 0x1C0u);
v2 = *v3;
*(v3 - 1) = 47;
if ( !v2 )
return mkdir(v1, 0x1C0u);
}
v2 = *v3;
LABEL_6:
;
}
return mkdir(v1, 0x1C0u);
}

original_code:
void mkdir_p(const char*_path)
{
    char*path = strdup(_path);
    char*p = path;
    while(*p == path_seperator) {
        p++;
    }
    while(*p) {
        while(*p && *p != path_seperator) {
            p++;
        }
        if(!*p)
            break;
        *p = 0;
        mkdir(path, 0700);
        *p = path_seperator;
        p++;
    }
    mkdir(path, 0700);
}

canonical_original_code:
void mkdir_p(char *_path)
{
    char *path = strdup(_path);
    char *p = path;
    while(*p == path_seperator) {
        p++;
    }
    while(*p) {
        while(*p && *p != path_seperator) {
            p++;
        }
        if(!*p)
            break;
        *p = 0;
        mkdir(path, 0700);
        *p = path_seperator;
        p++;
    }
    mkdir(path, 0700);
}

variable_types:
path
char *

variable_types:
p
char *


decompiled_code:
bool __fastcall read_with_retry(int fd, __int64 a2, int a3)
{
int v4; // ebx
int v5; // eax
bool result; // al
int *v7; // rax

if ( a3 > 0 )
{
v4 = 0;
while ( 1 )
{
v5 = read(fd, (void *)(a2 + v4), (unsigned int)(a3 - v4));
if ( v5 < 0 )
{
v7 = _errno_location();
result = *v7 == 11 || *v7 == 4;
if ( !result )
return result;
}
else
{
if ( !v5 )
return 0;
v4 += v5;
}
if ( a3 <= v4 )
return 1;
}
}
return 1;
}

canonical_decompiled_code:
bool __fastcall func6(int fd, __int64 a2, int a3)
{
int v4; // ebx
int v5; // eax
bool result; // al
int *v7; // rax

if ( a3 > 0 )
{
v4 = 0;
while ( 1 )
{
v5 = read(fd, (void *)(a2 + v4), (unsigned int)(a3 - v4));
if ( v5 < 0 )
{
v7 = _errno_location();
result = *v7 == 11 || *v7 == 4;
if ( !result )
return result;
}
else
{
if ( !v5 )
return 0;
v4 += v5;
}
if ( a3 <= v4 )
return 1;
}
}
return 1;
}

original_code:
_Bool read_with_retry(int fd, void* data, int len)
{
    int pos = 0;
    while(pos<len) {
        int ret = read(fd, data+pos, len-pos);
        if(ret<0) {
            if((*__errno_location ()) == 4 || (*__errno_location ()) == 11)
                continue;
            return 0;
        }
        if(ret==0) {
            return 0;
        }
        pos += ret;
    }
    return 1;
}

canonical_original_code:
_Bool read_with_retry(int fd, void *data, int len)
{
    int pos = 0;
    while(pos<len) {
        int ret = read(fd, data+pos, len-pos);
        if(ret<0) {
            if((*__errno_location ()) == 4 || (*__errno_location ()) == 11)
                continue;
            return 0;
        }
        if(ret==0) {
            return 0;
        }
        pos += ret;
    }
    return 1;
}

variable_types: fd int

variable_types:
data
void *

variable_types: len int

variable_types: ret int


decompiled_code:
bool __fastcall read_with_timeout(int fd, __int64 a2, int a3, struct timeval *a4)
{
int v6; // ebx
__int64 v7; // rbx
int v8; // eax
int v10; // eax
int v11; // eax
int v12; // [rsp+14h] [rbp-C4h]
fd_set readfds; // [rsp+20h] [rbp-B8h] BYREF

if ( !a4 )
return read_with_retry(fd, a2, a3);
memset(&readfds, 0, sizeof(readfds));
v6 = fd + 63;
v12 = 0;
if ( fd >= 0 )
v6 = fd;
v7 = v6 >> 6;
readfds.fds_bits[v7] |= 1LL << (fd % 64);
if ( a3 > 0 )
{
do
{
while ( select(fd + 1, &readfds, 0LL, 0LL, a4) < 0 )
{
v8 = *_errno_location();
if ( v8 != 4 && v8 != 11 )
return 0;
}
if ( (readfds.fds_bits[v7] & (1LL << (fd % 64))) == 0 )
return 0;
v10 = read(fd, (void *)(a2 + v12), (unsigned int)(a3 - v12));
if ( v10 < 0 )
{
v11 = *_errno_location();
if ( v11 != 4 && v11 != 11 )
return 0;
}
else
{
if ( !v10 )
return 0;
v12 += v10;
}
}
while ( v12 < a3 );
}
return 1;
}

canonical_decompiled_code:
bool __fastcall func7(int fd, __int64 a2, int a3, struct timeval *a4)
{
int v6; // ebx
__int64 v7; // rbx
int v8; // eax
int v10; // eax
int v11; // eax
int v12; // [rsp+14h] [rbp-C4h]
fd_set readfds; // [rsp+20h] [rbp-B8h] BYREF

if ( !a4 )
return func6(fd, a2, a3);
memset(&readfds, 0, sizeof(readfds));
v6 = fd + 63;
v12 = 0;
if ( fd >= 0 )
v6 = fd;
v7 = v6 >> 6;
readfds.fds_bits[v7] |= 1LL << (fd % 64);
if ( a3 > 0 )
{
do
{
while ( select(fd + 1, &readfds, 0LL, 0LL, a4) < 0 )
{
v8 = *_errno_location();
if ( v8 != 4 && v8 != 11 )
return 0;
}
if ( (readfds.fds_bits[v7] & (1LL << (fd % 64))) == 0 )
return 0;
v10 = read(fd, (void *)(a2 + v12), (unsigned int)(a3 - v12));
if ( v10 < 0 )
{
v11 = *_errno_location();
if ( v11 != 4 && v11 != 11 )
return 0;
}
else
{
if ( !v10 )
return 0;
v12 += v10;
}
}
while ( v12 < a3 );
}
return 1;
}

original_code:
_Bool read_with_timeout(int fd, void* data, int len, struct timeval* timeout)
{
    if(!timeout) {
        return read_with_retry(fd, data, len);
    }
    fd_set readfds;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&readfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    int pos = 0;
    while(pos<len) {
        int ret;
        while(1) {
            ret = select(fd+1, &readfds, ((void *)0), ((void *)0), timeout);
            if(ret<0) {
                if((*__errno_location ()) == 4 || (*__errno_location ()) == 11)
                    continue;
                return 0;
            }
            if(ret>=0)
                break;
        }
        if(!((((&readfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            return 0;
        }
        ret = read(fd, data+pos, len-pos);
        if(ret<0) {
            if((*__errno_location ()) == 4 || (*__errno_location ()) == 11)
                continue;
            return 0;
        }
        if(ret==0) {
            return 0;
        }
        pos += ret;
    }
    return 1;
}

canonical_original_code:
_Bool read_with_timeout(int fd, void *data, int len, struct timeval *timeout)
{
    if(!timeout) {
        return read_with_retry(fd, data, len);
    }
    struct fd_set readfds;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&readfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    int pos = 0;
    while(pos<len) {
        int ret;
        while(1) {
            ret = select(fd+1, &readfds, ((void *)0), ((void *)0), timeout);
            if(ret<0) {
                if((*__errno_location ()) == 4 || (*__errno_location ()) == 11)
                    continue;
                return 0;
            }
            if(ret>=0)
                break;
        }
        if(!((((&readfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            return 0;
        }
        ret = read(fd, data+pos, len-pos);
        if(ret<0) {
            if((*__errno_location ()) == 4 || (*__errno_location ()) == 11)
                continue;
            return 0;
        }
        if(ret==0) {
            return 0;
        }
        pos += ret;
    }
    return 1;
}

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

variable_types:
readfds
struct fd_set { long __fds_bits[-1]; }


decompiled_code:
void __fastcall __noreturn handle_signal(int status)
{
puts("signal");
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int status)
{
puts("signal");
exit(status);
}

original_code:
static void handle_signal(int signal, siginfo_t*siginfo, void*ucontext)
{
    void*here;
    printf("signal\n");
    Dl_info info;
    void**stack_top = &here;
    int i = 0;
    _exit(signal);
}

canonical_original_code:
static void handle_signal(int signal, struct siginfo_t *siginfo, void *ucontext)
{
    void *here;
    printf("signal\n");
    struct Dl_info info;
    void **stack_top = &here;
    int i = 0;
    _exit(signal);
}

variable_types: signal int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
ucontext
void *

variable_types:
here
void *

variable_types: struct Dl_info { char *dli_fname; void *dli_fbase; char *dli_sname; void *dli_saddr; }

variable_types: i int

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
int seccomp_lockdown()
{
int result; // eax
struct rlimit64 v1; // [rsp+0h] [rbp-168h] BYREF
__int16 v2; // [rsp+10h] [rbp-158h] BYREF
char *v3; // [rsp+18h] [rbp-150h]
char v4[328]; // [rsp+20h] [rbp-148h] BYREF

setenv("MALLOC_CHECK_", "0", 1);
sig.sa_handler = (__sighandler_t)handle_signal;
dword_1E8 = 4;
sigaction(11, &sig, 0LL);
sigaction(6, &sig, 0LL);
v1.rlim_max = config_maxmem + 0x10000;
v1.rlim_cur = v1.rlim_max;
setrlimit64(RLIMIT_DATA, &v1);
qmemcpy(v4, &unk_260, 0x140uLL);
v2 = 40;
v3 = v4;
if ( prctl(38, 1LL, 0LL, 0LL, 0LL) || (result = prctl(22, 2LL, &v2, 0LL, 0LL)) != 0 )
{
fwrite("could not enter secure computation mode\n", 1uLL, 0x28uLL, stderr);
perror("prctl");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
struct rlimit64 v1; // [rsp+0h] [rbp-168h] BYREF
__int16 v2; // [rsp+10h] [rbp-158h] BYREF
char *v3; // [rsp+18h] [rbp-150h]
char v4[328]; // [rsp+20h] [rbp-148h] BYREF

setenv("MALLOC_CHECK_", "0", 1);
sig.sa_handler = (__sighandler_t)handle_signal;
dword_1E8 = 4;
sigaction(11, &sig, 0LL);
sigaction(6, &sig, 0LL);
v1.rlim_max = config_maxmem + 0x10000;
v1.rlim_cur = v1.rlim_max;
setrlimit64(RLIMIT_DATA, &v1);
qmemcpy(v4, &unk_260, 0x140uLL);
v2 = 40;
v3 = v4;
if ( prctl(38, 1LL, 0LL, 0LL, 0LL) || (result = prctl(22, 2LL, &v2, 0LL, 0LL)) != 0 )
{
fwrite("could not enter secure computation mode\n", 1uLL, 0x28uLL, stderr);
perror("prctl");
exit(1);
}
return result;
}

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

variable_types: struct sock_filter { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; } []

variable_types: struct sock_fprog { unsigned short len; struct sock_filter { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; } *filter; }

user_defined_types: struct sock_fprog { unsigned short len; struct sock_filter *filter; }


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

result = calloc(1uLL, 0x60uLL);
result[1] = "lua";
result[3] = initialize_lua;
result[6] = compile_script_lua;
result[7] = is_function_lua;
result[8] = call_function_lua;
result[5] = define_function_lua;
result[4] = define_constant_lua;
result[9] = destroy_lua;
return result;
}

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

result = calloc(1uLL, 0x60uLL);
result[1] = "lua";
result[3] = initialize_lua;
result[6] = compile_script_lua;
result[7] = is_function_lua;
result[8] = call_function_lua;
result[5] = define_function_lua;
result[4] = define_constant_lua;
result[9] = destroy_lua;
return result;
}

original_code:
language_t* lua_interpreter_new()
{
    language_t * li = calloc(1, sizeof(language_t));
    li->name = "lua";
    li->initialize = initialize_lua;
    li->compile_script = compile_script_lua;
    li->is_function = is_function_lua;
    li->call_function = call_function_lua;
    li->define_function = define_function_lua;
    li->define_constant = define_constant_lua;
    li->destroy = destroy_lua;
    return li;
}

canonical_original_code:
struct _language *lua_interpreter_new()
{
    struct _language *li = calloc(1, sizeof(language_t));
    li->name = "lua";
    li->initialize = initialize_lua;
    li->compile_script = compile_script_lua;
    li->is_function = is_function_lua;
    li->call_function = call_function_lua;
    li->define_function = define_function_lua;
    li->define_constant = define_constant_lua;
    li->destroy = destroy_lua;
    return li;
}

variable_types: struct _language { void *internal; char *name; _Bool timeout; _Bool (*initialize)(struct _language *li, unsigned long maxmem); void (*define_constant)(struct _language *li, char *name, struct _value { enum _type { TYPE_VOID=0, TYPE_FLOAT32=1, TYPE_INT32=2, TYPE_BOOLEAN=3, TYPE_STRING=4, TYPE_ARRAY=5, TYPE_FUNCTION=6 } type; void *internal; union { int i32; float f32; _Bool b; char *str; struct { struct _value *(*call)(struct _value *v, struct _value *params); int num_params; }; struct { int length; struct _value **data; }; }; void (*destroy)(struct _value *destroy); } *value); void (*define_function)(struct _language *li, char *name, struct _value *f); _Bool (*compile_script)(struct _language *li, char *script); _Bool (*is_function)(struct _language *li, char *name); struct _value *(*call_function)(struct _language *li, char *name, struct _value *args); void (*destroy)(struct _language *li); void *user; void (*log)(void *user, char *line); } *


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

result = calloc(1uLL, 0x60uLL);
result[1] = "py";
result[3] = initialize_py;
result[6] = compile_script_py;
result[7] = is_function_py;
result[8] = call_function_py;
result[4] = define_constant_py;
result[5] = define_function_py;
result[9] = destroy_py;
return result;
}

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

result = calloc(1uLL, 0x60uLL);
result[1] = "py";
result[3] = initialize_py;
result[6] = compile_script_py;
result[7] = is_function_py;
result[8] = call_function_py;
result[4] = define_constant_py;
result[5] = define_function_py;
result[9] = destroy_py;
return result;
}

original_code:
language_t* python_interpreter_new()
{
    language_t * li = calloc(1, sizeof(language_t));
    li->name = "py";
    li->initialize = initialize_py;
    li->compile_script = compile_script_py;
    li->is_function = is_function_py;
    li->call_function = call_function_py;
    li->define_constant = define_constant_py;
    li->define_function = define_function_py;
    li->destroy = destroy_py;
    return li;
}

canonical_original_code:
struct _language *python_interpreter_new()
{
    struct _language *li = calloc(1, sizeof(language_t));
    li->name = "py";
    li->initialize = initialize_py;
    li->compile_script = compile_script_py;
    li->is_function = is_function_py;
    li->call_function = call_function_py;
    li->define_constant = define_constant_py;
    li->define_function = define_function_py;
    li->destroy = destroy_py;
    return li;
}


setComplement

repo: matthiasr/revcomp

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

complement[a1] = a2;
complement[a2] = a1;
result = a1 | 0x20;
complement[result] = a2;
complement[a2 | 0x20] = a1;
return result;
}

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

complement[a1] = a2;
complement[a2] = a1;
result = a1 | 0x20;
complement[result] = a2;
complement[a2 | 0x20] = a1;
return result;
}

original_code:
void
setComplement(char c1, char c2)
{
 complement[c1] = c2;
 complement[c2] = c1;
 complement[c1 | 0x20] = c2;
 complement[c2 | 0x20] = c1;
}