decompiled_code:
__int64 __fastcall lbs_strv_minimize(_QWORD *a1)
{
__int64 v1; // r12
__int64 v2; // rbx

if ( (int)((__int64 (*)(void))lbs_array_minimize)() < 0 )
return 0xFFFFFFFFLL;
v1 = a1[3];
v2 = 0LL;
if ( v1 )
{
while ( (int)lbs_array_minimize(*a1 + 48 * v2) >= 0 )
{
if ( v1 == ++v2 )
return 0LL;
}
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1)
{
__int64 v1; // r12
__int64 v2; // rbx

if ( (int)((__int64 (*)(void))lbs_array_minimize)() < 0 )
return 0xFFFFFFFFLL;
v1 = a1[3];
v2 = 0LL;
if ( v1 )
{
while ( (int)lbs_array_minimize(*a1 + 48 * v2) >= 0 )
{
if ( v1 == ++v2 )
return 0LL;
}
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
int lbs_strv_minimize (LbsStrv* strv) {
    if (lbs_array_minimize (&strv->array) < 0) {
        return -1;
    }
    size_t i;
    size_t len = (((_Generic (((&((_Generic (((strv)), LbsStrv*: ((strv))))->array))), LbsArray*: ((&((_Generic (((strv)), LbsStrv*: ((strv))))->array)))))->len));
    for (i = 0; i < len; i++) {
        LbsArray* str = (&((*(((LbsArray*)((&((strv)->array))->data))+((i))))));
        if (lbs_array_minimize (str) < 0) {
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int lbs_strv_minimize(struct LbsStrvStruct *strv) {
    if (lbs_array_minimize (&strv->array) < 0) {
        return -1;
    }
    unsigned long i;
    unsigned long len = (((_Generic (((&((_Generic (((strv)), LbsStrv*: ((strv))))->array))), LbsArray*: ((&((_Generic (((strv)), LbsStrv*: ((strv))))->array)))))->len));
    for (i = 0; i < len; i++) {
        struct LbsArrayStruct *str = (&((*(((LbsArray*)((&((strv)->array))->data))+((i))))));
        if (lbs_array_minimize (str) < 0) {
            return -1;
        }
    }
    return 0;
}


decompiled_code:
int __fastcall lbs_strv_generic_cmp(const char **a1, _QWORD *a2)
{
const char *v4; // rdi
__int64 v5; // rbx
int result; // eax
const char *v7; // rsi

v4 = *a1;
v5 = 0LL;
if ( v4 )
{
do
{
v7 = (const char *)a2[v5];
if ( !v7 )
return 1;
result = strcmp(v4, v7);
if ( result )
return result;
v4 = a1[++v5];
}
while ( v4 );
a2 = (_QWORD *)((char *)a2 + v5 * 8);
}
return -(*a2 != 0LL);
}

canonical_decompiled_code:
int __fastcall func15(const char **a1, _QWORD *a2)
{
const char *v4; // rdi
__int64 v5; // rbx
int result; // eax
const char *v7; // rsi

v4 = *a1;
v5 = 0LL;
if ( v4 )
{
do
{
v7 = (const char *)a2[v5];
if ( !v7 )
return 1;
result = strcmp(v4, v7);
if ( result )
return result;
v4 = a1[++v5];
}
while ( v4 );
a2 = (_QWORD *)((char *)a2 + v5 * 8);
}
return -(*a2 != 0LL);
}

original_code:
int lbs_strv_generic_cmp (
    const char* const* bstrv1, const char* const* bstrv2) {
    int i;
    for (i = 0; bstrv1[i] != ((void *)0) && bstrv2[i] != ((void *)0); i++) {
        int r = strcmp (bstrv1[i], bstrv2[i]);
        if (r != 0) {
            return r;
        }
    }
    if (bstrv1[i] != ((void *)0)) {
        return 1;
    }
    if (bstrv2[i] != ((void *)0)) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lbs_strv_generic_cmp(char **bstrv1, char **bstrv2) {
    int i;
    for (i = 0; bstrv1[i] != ((void *)0) && bstrv2[i] != ((void *)0); i++) {
        int r = strcmp (bstrv1[i], bstrv2[i]);
        if (r != 0) {
            return r;
        }
    }
    if (bstrv1[i] != ((void *)0)) {
        return 1;
    }
    if (bstrv2[i] != ((void *)0)) {
        return -1;
    }
    return 0;
}

variable_types: i int

variable_types: r int

return_type: int


decompiled_code:
void __fastcall lbs_strv_generic_free(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

v2 = *(void **)ptr;
if ( v2 )
{
v3 = (void **)((char *)ptr + 8);
do
{
free(v2);
v2 = *v3++;
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func16(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

v2 = *(void **)ptr;
if ( v2 )
{
v3 = (void **)((char *)ptr + 8);
do
{
free(v2);
v2 = *v3++;
}
while ( v2 );
}
free(ptr);
}

original_code:
void lbs_strv_generic_free (char** bstrv) {
    int i;
    for (i = 0; bstrv[i] != ((void *)0); i++) {
        free (bstrv[i]);
    }
    free (bstrv);
}

canonical_original_code:
void lbs_strv_generic_free(char **bstrv) {
    int i;
    for (i = 0; bstrv[i] != ((void *)0); i++) {
        free (bstrv[i]);
    }
    free (bstrv);
}

variable_types:
bstrv
char **

return_type: void


decompiled_code:
void *__fastcall lbs_array2_copy_in(_QWORD *a1, const void *a2)
{
return memcpy((char *)a1 + 28, a2, a1[2] * a1[1] * *a1);
}

canonical_decompiled_code:
void *__fastcall func0(_QWORD *a1, const void *a2)
{
return memcpy((char *)a1 + 28, a2, a1[2] * a1[1] * *a1);
}

original_code:
void lbs_array2_copy_in (LbsArray2* array2, const void* copy_in) {
    memcpy (array2->data, copy_in, array2->size * array2->lenx * array2->leny);
}

canonical_original_code:
void lbs_array2_copy_in(struct LbsArray2Struct *array2, void *copy_in) {
    memcpy (array2->data, copy_in, array2->size * array2->lenx * array2->leny);
}

variable_types: struct LbsArray2Struct { unsigned long size; unsigned long lenx; unsigned long leny; unsigned int ref_count; char data[]; } *


decompiled_code:
void *__fastcall lbs_array2_copy_out(_QWORD *a1, void *a2)
{
return memcpy(a2, (char *)a1 + 28, a1[2] * a1[1] * *a1);
}

canonical_decompiled_code:
void *__fastcall func1(_QWORD *a1, void *a2)
{
return memcpy(a2, (char *)a1 + 28, a1[2] * a1[1] * *a1);
}

original_code:
void lbs_array2_copy_out (LbsArray2* array2, void* copy_out) {
    memcpy (copy_out, array2->data, array2->size * array2->lenx * array2->leny);
}

canonical_original_code:
void lbs_array2_copy_out(struct LbsArray2Struct *array2, void *copy_out) {
    memcpy (copy_out, array2->data, array2->size * array2->lenx * array2->leny);
}

user_defined_types: struct LbsArray2Struct { unsigned long size; unsigned long lenx; unsigned long leny; unsigned int ref_count; char data[]; }


decompiled_code:
__int64 __fastcall lbs_array2_ref_generic(__int64 a1)
{
++*(_DWORD *)(a1 + 24);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
++*(_DWORD *)(a1 + 24);
return a1;
}

original_code:
void* lbs_array2_ref_generic (void* array2_generic) {
    LbsArray2* array2 = ((LbsArray2*)(array2_generic));
    array2->ref_count++;
    return array2;
}

canonical_original_code:
void *lbs_array2_ref_generic(void *array2_generic) {
    struct LbsArray2Struct *array2 = ((LbsArray2*)(array2_generic));
    array2->ref_count++;
    return array2;
}

return_type: void *


decompiled_code:
void __fastcall lbs_array2_unref_generic(_DWORD *a1)
{
if ( a1 )
{
if ( a1[6] == 1 )
free(a1);
else
--a1[6];
}
}

canonical_decompiled_code:
void __fastcall func3(_DWORD *a1)
{
if ( a1 )
{
if ( a1[6] == 1 )
free(a1);
else
--a1[6];
}
}

original_code:
void lbs_array2_unref_generic (void* array2_generic) {
    if (array2_generic == ((void *)0)) {
        return;
    }
    LbsArray2* array2 = ((LbsArray2*)(array2_generic));
    array2->ref_count--;
    if (array2->ref_count <= 0) {
        free (array2_generic);
    }
}

canonical_original_code:
void lbs_array2_unref_generic(void *array2_generic) {
    if (array2_generic == ((void *)0)) {
        return;
    }
    struct LbsArray2Struct *array2 = ((LbsArray2*)(array2_generic));
    array2->ref_count--;
    if (array2->ref_count <= 0) {
        free (array2_generic);
    }
}


decompiled_code:
__int64 __fastcall lbs_array_init_with_max(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
void *v5; // rax

if ( !a2 )
return 0xFFFFFFFFLL;
if ( a3 )
{
v5 = malloc(a3 * a2);
if ( !v5 )
return 0xFFFFFFFFLL;
*(_QWORD *)a1 = v5;
}
else
{
*(_QWORD *)a1 = 0LL;
}
*(_QWORD *)(a1 + 8) = 0LL;
result = 0LL;
*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 24) = a3;
*(_QWORD *)(a1 + 32) = a3;
*(_DWORD *)(a1 + 40) = 1;
*(_BYTE *)(a1 + 44) = 0;
return result;
}

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

if ( !a2 )
return 0xFFFFFFFFLL;
if ( a3 )
{
v5 = malloc(a3 * a2);
if ( !v5 )
return 0xFFFFFFFFLL;
*(_QWORD *)a1 = v5;
}
else
{
*(_QWORD *)a1 = 0LL;
}
*(_QWORD *)(a1 + 8) = 0LL;
result = 0LL;
*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 24) = a3;
*(_QWORD *)(a1 + 32) = a3;
*(_DWORD *)(a1 + 40) = 1;
*(_BYTE *)(a1 + 44) = 0;
return result;
}

original_code:
int lbs_array_init_with_max (LbsArray* array, size_t size, size_t max) {
    if (size <= 0) {
        return -1;
    }
    if (max > 0) {
        void* data = malloc (size * max);
        if (data == ((void *)0)) {
            return -1;
        }
        array->data = data;
    } else {
        array->data = ((void *)0);
    }
    array->free_func = ((void *)0);
    array->size = size;
    array->len = max;
    array->max = max;
    array->ref_count = 1;
    array->is_alloc = 0;
    return 0;
}

canonical_original_code:
int lbs_array_init_with_max(struct LbsArrayStruct *array, unsigned long size, unsigned long max) {
    if (size <= 0) {
        return -1;
    }
    if (max > 0) {
        void *data = malloc (size * max);
        if (data == ((void *)0)) {
            return -1;
        }
        array->data = data;
    } else {
        array->data = ((void *)0);
    }
    array->free_func = ((void *)0);
    array->size = size;
    array->len = max;
    array->max = max;
    array->ref_count = 1;
    array->is_alloc = 0;
    return 0;
}

variable_types: struct LbsArrayStruct { void *data; void (*free_func)(void *data); unsigned long size; unsigned long len; unsigned long max; unsigned int ref_count; _Bool is_alloc; } *

variable_types:
size
unsigned long

variable_types:
max
unsigned long

variable_types:
data
void *


decompiled_code:
__int64 __fastcall lbs_array_ref_generic(__int64 a1)
{
++*(_DWORD *)(a1 + 40);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
++*(_DWORD *)(a1 + 40);
return a1;
}

original_code:
void* lbs_array_ref_generic (void* array_generic) {
    LbsArray* array = ((LbsArray*)(array_generic));
    array->ref_count++;
    return array;
}

canonical_original_code:
void *lbs_array_ref_generic(void *array_generic) {
    struct LbsArrayStruct *array = ((LbsArray*)(array_generic));
    array->ref_count++;
    return array;
}

user_defined_types: struct LbsArrayStruct { void *data; void (*free_func)(void *data); unsigned long size; unsigned long len; unsigned long max; unsigned int ref_count; _Bool is_alloc; }


decompiled_code:
void __fastcall lbs_array_free_generic(void *ptr)
{
void (__fastcall *v1)(_QWORD); // rax
_QWORD *v2; // r12
unsigned __int64 v3; // rbx

if ( ptr )
{
v1 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 1);
v2 = *(_QWORD **)ptr;
if ( v1 && *((_QWORD *)ptr + 3) )
{
v3 = 0LL;
while ( 1 )
{
++v3;
v1(*v2);
v2 = (_QWORD *)((char *)v2 + *((_QWORD *)ptr + 2));
if ( *((_QWORD *)ptr + 3) <= v3 )
break;
v1 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 1);
}
v2 = *(_QWORD **)ptr;
}
free(v2);
if ( *((_BYTE *)ptr + 44) )
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
void (__fastcall *v1)(_QWORD); // rax
_QWORD *v2; // r12
unsigned __int64 v3; // rbx

if ( ptr )
{
v1 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 1);
v2 = *(_QWORD **)ptr;
if ( v1 && *((_QWORD *)ptr + 3) )
{
v3 = 0LL;
while ( 1 )
{
++v3;
v1(*v2);
v2 = (_QWORD *)((char *)v2 + *((_QWORD *)ptr + 2));
if ( *((_QWORD *)ptr + 3) <= v3 )
break;
v1 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 1);
}
v2 = *(_QWORD **)ptr;
}
free(v2);
if ( *((_BYTE *)ptr + 44) )
free(ptr);
}
}

original_code:
void lbs_array_free_generic (void* array_generic) {
    if (array_generic == ((void *)0)) {
        return;
    }
    LbsArray* array = ((LbsArray*)(array_generic));
    if (array->free_func != ((void *)0)) {
        size_t i = 0;
        char* d = array->data;
        for (; i < array->len; i++, d += array->size) {
            (*(array->free_func)) (*((void**)d));
        }
    }
    free (array->data);
    if (array->is_alloc) {
        free (array);
    }
}

canonical_original_code:
void lbs_array_free_generic(void *array_generic) {
    if (array_generic == ((void *)0)) {
        return;
    }
    struct LbsArrayStruct *array = ((LbsArray*)(array_generic));
    if (array->free_func != ((void *)0)) {
        unsigned long i = 0;
        char *d = array->data;
        for (; i < array->len; i++, d += array->size) {
            (*(array->free_func)) (*((void **)d));
        }
    }
    free (array->data);
    if (array->is_alloc) {
        free (array);
    }
}

variable_types:
i
unsigned long

variable_types:
d
char *


decompiled_code:
void __fastcall lbs_array_unref_generic(void *ptr)
{
if ( ptr )
{
if ( (*((_DWORD *)ptr + 10))-- == 1 )
lbs_array_free_generic(ptr);
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
if ( ptr )
{
if ( (*((_DWORD *)ptr + 10))-- == 1 )
func3(ptr);
}
}

original_code:
void lbs_array_unref_generic (void* array_generic) {
    if (array_generic == ((void *)0)) {
        return;
    }
    LbsArray* array = ((LbsArray*)(array_generic));
    array->ref_count--;
    if (array->ref_count <= 0) {
        (lbs_array_free_generic ((_Generic (((array)), LbsArray*: ((array))))));
    }
}

canonical_original_code:
void lbs_array_unref_generic(void *array_generic) {
    if (array_generic == ((void *)0)) {
        return;
    }
    struct LbsArrayStruct *array = ((LbsArray*)(array_generic));
    array->ref_count--;
    if (array->ref_count <= 0) {
        (lbs_array_free_generic ((_Generic (((array)), struct LbsArrayStruct *: ((array))))));
    }
}


decompiled_code:
__int64 __fastcall lbs_array_drop_struct(_BYTE *a1)
{
__int64 v1; // r12

v1 = *(_QWORD *)a1;
if ( a1[44] )
free(a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1)
{
__int64 v1; // r12

v1 = *(_QWORD *)a1;
if ( a1[44] )
free(a1);
return v1;
}

original_code:
void* lbs_array_drop_struct (LbsArray* array) {
    if (!array->is_alloc) {
        return array->data;
    }
    void* data = array->data;
    free (array);
    return data;
}

canonical_original_code:
void *lbs_array_drop_struct(struct LbsArrayStruct *array) {
    if (!array->is_alloc) {
        return array->data;
    }
    void *data = array->data;
    free (array);
    return data;
}


decompiled_code:
__int64 __fastcall lbs_array_set_max(__int64 a1, __int64 a2)
{
void *v2; // rax

v2 = realloc(*(void **)a1, *(_QWORD *)(a1 + 16) * a2);
if ( !v2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 32) = a2;
*(_QWORD *)a1 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
void *v2; // rax

v2 = realloc(*(void **)a1, *(_QWORD *)(a1 + 16) * a2);
if ( !v2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 32) = a2;
*(_QWORD *)a1 = v2;
return 0LL;
}

original_code:
int lbs_array_set_max (LbsArray* array, size_t max) {
    void* ptr = realloc (array->data, array->size * max);
    if (ptr == ((void *)0)) {
        return -1;
    }
    array->max = max;
    array->data = ptr;
    return 0;
}

canonical_original_code:
int lbs_array_set_max(struct LbsArrayStruct *array, unsigned long max) {
    void *ptr = realloc (array->data, array->size * max);
    if (ptr == ((void *)0)) {
        return -1;
    }
    array->max = max;
    array->data = ptr;
    return 0;
}

variable_types:
ptr
void *


decompiled_code:
__int64 __fastcall lbs_array_set_len(__int64 a1, unsigned __int64 a2)
{
if ( *(_QWORD *)(a1 + 32) < a2 && (int)lbs_array_set_max(a1, a2) < 0 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 24) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int64 a2)
{
if ( *(_QWORD *)(a1 + 32) < a2 && (int)func6(a1, a2) < 0 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 24) = a2;
return 0LL;
}

original_code:
int lbs_array_set_len (LbsArray* array, size_t len) {
    if (len > (array->max)){
        if (lbs_array_set_max (array, len) < 0) {
            return -1;
        } else {
            array->len = len;
        }
    } else {
        array->len = len;
        return 0;
    }
    return 0;
}

canonical_original_code:
int lbs_array_set_len(struct LbsArrayStruct *array, unsigned long len) {
    if (len > (array->max)){
        if (lbs_array_set_max (array, len) < 0) {
            return -1;
        } else {
            array->len = len;
        }
    } else {
        array->len = len;
        return 0;
    }
    return 0;
}

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall lbs_array_append_data(_QWORD *a1, const void *a2)
{
unsigned __int64 v4; // rsi
__int64 v5; // rdi

v4 = a1[4];
v5 = a1[3];
if ( v4 >= v5 + 1 )
goto LABEL_5;
if ( v4 )
{
if ( (int)lbs_array_set_max((__int64)a1, 2 * v4) >= 0 )
goto LABEL_4;
}
else if ( (int)lbs_array_set_max((__int64)a1, 1LL) >= 0 )
{
LABEL_4:
v5 = a1[3];
LABEL_5:
memcpy((void *)(*a1 + a1[2] * v5), a2, a1[2]);
++a1[3];
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, const void *a2)
{
unsigned __int64 v4; // rsi
__int64 v5; // rdi

v4 = a1[4];
v5 = a1[3];
if ( v4 >= v5 + 1 )
goto LABEL_5;
if ( v4 )
{
if ( (int)func6((__int64)a1, 2 * v4) >= 0 )
goto LABEL_4;
}
else if ( (int)func6((__int64)a1, 1LL) >= 0 )
{
LABEL_4:
v5 = a1[3];
LABEL_5:
memcpy((void *)(*a1 + a1[2] * v5), a2, a1[2]);
++a1[3];
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int lbs_array_append_data (LbsArray* array, const void* data) {
    if (array->max < array->len + 1) {
        if (array->max > 0) {
            if (lbs_array_set_max (array, array->max * 2) < 0) {
                return -1;
            }
        } else {
            if (lbs_array_set_max (array, 1) < 0){
                return -1;
            }
        }
    }
    memcpy (((void*)(((char*)((array)->data))+(((array)->size)*(array->len)))), data, array->size);
    array->len++;
    return 0;
}

canonical_original_code:
int lbs_array_append_data(struct LbsArrayStruct *array, void *data) {
    if (array->max < array->len + 1) {
        if (array->max > 0) {
            if (lbs_array_set_max (array, array->max * 2) < 0) {
                return -1;
            }
        } else {
            if (lbs_array_set_max (array, 1) < 0){
                return -1;
            }
        }
    }
    memcpy (((void *)(((char *)((array)->data))+(((array)->size)*(array->len)))), data, array->size);
    array->len++;
    return 0;
}


decompiled_code:
__int64 __fastcall lbs_array_append_ptr(_QWORD *a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return lbs_array_append_data(a1, &v3);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return func9(a1, &v3);
}

original_code:
int lbs_array_append_ptr (LbsArray* array, const void* ptr) {
    return lbs_array_append_data (array, &ptr);
}

canonical_original_code:
int lbs_array_append_ptr(struct LbsArrayStruct *array, void *ptr) {
    return lbs_array_append_data (array, &ptr);
}


decompiled_code:
__int64 __fastcall lbs_array_append_mass(_QWORD *a1, const void *a2, __int64 a3)
{
unsigned __int64 v6; // rsi
__int64 v7; // rdi
unsigned __int64 v8; // rax

v6 = a1[4];
v7 = a1[3];
v8 = a3 + v7;
if ( v6 >= a3 + v7 )
goto LABEL_8;
do
{
if ( !v6 )
{
v6 = 1LL;
if ( v8 <= 1 )
break;
}
v6 *= 2LL;
}
while ( v6 < v8 );
a1[4] = v6;
if ( (int)lbs_array_set_max((__int64)a1, v6) >= 0 )
{
v7 = a1[3];
LABEL_8:
memcpy((void *)(*a1 + a1[2] * v7), a2, a3 * a1[2]);
a1[3] += a3;
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1, const void *a2, __int64 a3)
{
unsigned __int64 v6; // rsi
__int64 v7; // rdi
unsigned __int64 v8; // rax

v6 = a1[4];
v7 = a1[3];
v8 = a3 + v7;
if ( v6 >= a3 + v7 )
goto LABEL_8;
do
{
if ( !v6 )
{
v6 = 1LL;
if ( v8 <= 1 )
break;
}
v6 *= 2LL;
}
while ( v6 < v8 );
a1[4] = v6;
if ( (int)func6((__int64)a1, v6) >= 0 )
{
v7 = a1[3];
LABEL_8:
memcpy((void *)(*a1 + a1[2] * v7), a2, a3 * a1[2]);
a1[3] += a3;
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int lbs_array_append_mass (LbsArray* array, const void* data, size_t count) {
    _Bool need_expand = 0;
    while (array->max < array->len + count) {
        need_expand = 1;
        if (array->max > 0) {
            array->max *= 2;
        } else {
            array->max = 1;
        }
    }
    if (need_expand) {
        if (lbs_array_set_max (array, array->max) < 0) {
            return -1;
        }
    }
    memcpy (((void*)(((char*)((array)->data))+(((array)->size)*(array->len)))), data, array->size * count);
    array->len += count;
    return 0;
}

canonical_original_code:
int lbs_array_append_mass(struct LbsArrayStruct *array, void *data, unsigned long count) {
    _Bool need_expand = 0;
    while (array->max < array->len + count) {
        need_expand = 1;
        if (array->max > 0) {
            array->max *= 2;
        } else {
            array->max = 1;
        }
    }
    if (need_expand) {
        if (lbs_array_set_max (array, array->max) < 0) {
            return -1;
        }
    }
    memcpy (((void *)(((char *)((array)->data))+(((array)->size)*(array->len)))), data, array->size * count);
    array->len += count;
    return 0;
}

variable_types:
count
unsigned long


decompiled_code:
__int64 __fastcall lbs_array_minimize(__int64 a1)
{
unsigned int v1; // er12
unsigned __int64 v2; // rsi
__int64 result; // rax
void *v4; // rax
__int64 v5; // rdx

v1 = 0;
v2 = *(_QWORD *)(a1 + 24);
if ( *(_QWORD *)(a1 + 32) <= v2 )
return v1;
v4 = realloc(*(void **)a1, *(_QWORD *)(a1 + 16) * v2);
if ( !v4 )
return (unsigned int)-1;
v5 = *(_QWORD *)(a1 + 24);
*(_QWORD *)a1 = v4;
result = 0LL;
*(_QWORD *)(a1 + 32) = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
unsigned int v1; // er12
unsigned __int64 v2; // rsi
__int64 result; // rax
void *v4; // rax
__int64 v5; // rdx

v1 = 0;
v2 = *(_QWORD *)(a1 + 24);
if ( *(_QWORD *)(a1 + 32) <= v2 )
return v1;
v4 = realloc(*(void **)a1, *(_QWORD *)(a1 + 16) * v2);
if ( !v4 )
return (unsigned int)-1;
v5 = *(_QWORD *)(a1 + 24);
*(_QWORD *)a1 = v4;
result = 0LL;
*(_QWORD *)(a1 + 32) = v5;
return result;
}

original_code:
int lbs_array_minimize (LbsArray* array) {
    if (array->max > array->len) {
        void* ptr = realloc (array->data, array->size * array->len);
        if (ptr == ((void *)0)) {
            return -1;
        }
        array->max = array->len;
        array->data = ptr;
    }
    return 0;
}

canonical_original_code:
int lbs_array_minimize(struct LbsArrayStruct *array) {
    if (array->max > array->len) {
        void *ptr = realloc (array->data, array->size * array->len);
        if (ptr == ((void *)0)) {
            return -1;
        }
        array->max = array->len;
        array->data = ptr;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall lbs_array_remove(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rcx
unsigned __int64 v3; // rax
unsigned int v4; // er12

v1 = *(_QWORD *)(a1 + 24);
if ( !v1 )
return (unsigned int)-1;
v2 = *(_QWORD *)(a1 + 32);
v3 = v1 - 1;
v4 = 0;
*(_QWORD *)(a1 + 24) = v3;
if ( v3 >= 2 * v2 )
return v4;
lbs_array_minimize(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rcx
unsigned __int64 v3; // rax
unsigned int v4; // er12

v1 = *(_QWORD *)(a1 + 24);
if ( !v1 )
return (unsigned int)-1;
v2 = *(_QWORD *)(a1 + 32);
v3 = v1 - 1;
v4 = 0;
*(_QWORD *)(a1 + 24) = v3;
if ( v3 >= 2 * v2 )
return v4;
func12(a1);
return 0LL;
}

original_code:
int lbs_array_remove (LbsArray* array) {
    if (array->len <= 0) {
        return -1;
    }
    array->len--;
    if (array->len < array->max * 2) {
        lbs_array_minimize (array);
    }
    return 0;
}

canonical_original_code:
int lbs_array_remove(struct LbsArrayStruct *array) {
    if (array->len <= 0) {
        return -1;
    }
    array->len--;
    if (array->len < array->max * 2) {
        lbs_array_minimize (array);
    }
    return 0;
}


decompiled_code:
void __fastcall lbs_list_meta_free(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void (__fastcall *v3)(_QWORD); // rax

if ( ptr )
{
if ( *((_QWORD *)ptr + 2) )
{
v1 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
while ( 1 )
{
v2 = v1;
v1 = (_QWORD *)v1[1];
v3 = (void (__fastcall *)(_QWORD))v2[2];
if ( !v3 )
{
v3 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 3);
if ( !v3 )
break;
}
v3(v2[3]);
free(v2);
if ( !v1 )
goto LABEL_9;
}
free(v2);
}
while ( v1 );
}
}
LABEL_9:
free(ptr);
}
}

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

if ( ptr )
{
if ( *((_QWORD *)ptr + 2) )
{
v1 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
while ( 1 )
{
v2 = v1;
v1 = (_QWORD *)v1[1];
v3 = (void (__fastcall *)(_QWORD))v2[2];
if ( !v3 )
{
v3 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 3);
if ( !v3 )
break;
}
v3(v2[3]);
free(v2);
if ( !v1 )
goto LABEL_9;
}
free(v2);
}
while ( v1 );
}
}
LABEL_9:
free(ptr);
}
}

original_code:
void lbs_list_meta_free (LbsListMeta* list) {
    if (list == ((void *)0)) {
        return;
    }
    if (list->len <= 0) {
        free (list);
        return;
    }
    LbsList *iter, *next;
    for (iter = list->first; iter != ((void *)0); iter = next) {
        next = iter->next;
        if (iter->free_func != ((void *)0)) {
            (*(iter->free_func)) (iter->data);
        } else if (list->free_func != ((void *)0)) {
            (*(list->free_func)) (iter->data);
        }
        free (iter);
    }
    free (list);
}

canonical_original_code:
void lbs_list_meta_free(struct LbsListMetaStruct *list) {
    if (list == ((void *)0)) {
        return;
    }
    if (list->len <= 0) {
        free (list);
        return;
    }
    struct LbsListStruct *iter; struct LbsListStruct *next;
    for (iter = list->first; iter != ((void *)0); iter = next) {
        next = iter->next;
        if (iter->free_func != ((void *)0)) {
            (*(iter->free_func)) (iter->data);
        } else if (list->free_func != ((void *)0)) {
            (*(list->free_func)) (iter->data);
        }
        free (iter);
    }
    free (list);
}

variable_types: struct LbsListMetaStruct { struct LbsListStruct { struct LbsListStruct *prev; struct LbsListStruct *next; void (*free_func)(void *data); void *data; } *first; struct LbsListStruct *last; unsigned long len; void (*free_func)(void *data); } *

user_defined_types: struct LbsListMetaStruct { struct LbsListStruct *first; struct LbsListStruct *last; unsigned long len; void (*free_func)(void *data); }


original_code:
void lbs_list_remove (LbsListMeta* list, LbsList* node) {
    if (list != ((void *)0)) {
        if (list->first == node) {
            list->first = node->next;
        }
        if (list->last == node) {
            list->last = node->prev;
        }
        if (list->len > 0) {
            list->len--;
        }
    }
    LbsList* old_next = node->next;
    LbsList* old_prev = node->prev;
    if (node->free_func != ((void *)0)) {
        (*(node->free_func)) (node->data);
    } else if (list != ((void *)0) && list->free_func != ((void *)0)) {
        (*(list->free_func)) (node->data);
    }
    free (node);
    if (old_next != ((void *)0)) {
        old_next->prev = old_prev;
    }
    if (old_prev != ((void *)0)) {
        old_prev->next = old_next;
    }
}

canonical_original_code:
void lbs_list_remove(struct LbsListMetaStruct *list, struct LbsListStruct *node) {
    if (list != ((void *)0)) {
        if (list->first == node) {
            list->first = node->next;
        }
        if (list->last == node) {
            list->last = node->prev;
        }
        if (list->len > 0) {
            list->len--;
        }
    }
    struct LbsListStruct *old_next = node->next;
    struct LbsListStruct *old_prev = node->prev;
    if (node->free_func != ((void *)0)) {
        (*(node->free_func)) (node->data);
    } else if (list != ((void *)0) && list->free_func != ((void *)0)) {
        (*(list->free_func)) (node->data);
    }
    free (node);
    if (old_next != ((void *)0)) {
        old_next->prev = old_prev;
    }
    if (old_prev != ((void *)0)) {
        old_prev->next = old_next;
    }
}

variable_types:
node
struct LbsListStruct *

variable_types: struct LbsListStruct { struct LbsListStruct *prev; struct LbsListStruct *next; void (*free_func)(void *data); void *data; } *


decompiled_code:
__int64 lbs_sysdep_get_executable()
{
__int64 result; // rax

result = lbs_posix_readlink("/proc/self/exe");
if ( !result )
{
result = lbs_posix_readlink("/proc/curproc/exe");
if ( !result )
result = lbs_posix_readlink("/proc/curproc/file");
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

result = lbs_posix_readlink("/proc/self/exe");
if ( !result )
{
result = lbs_posix_readlink("/proc/curproc/exe");
if ( !result )
result = lbs_posix_readlink("/proc/curproc/file");
}
return result;
}

original_code:
char* lbs_sysdep_get_executable (void) {
 char* myexec;
 if ((myexec = lbs_posix_readlink ("/proc/self/exe")) != ((void *)0)) {
  return myexec;
 }
 if ((myexec = lbs_posix_readlink ("/proc/curproc/exe")) != ((void *)0)) {
  return myexec;
 }
 if ((myexec = lbs_posix_readlink ("/proc/curproc/file")) != ((void *)0)) {
  return myexec;
 }
 return ((void *)0);
}

canonical_original_code:
char *lbs_sysdep_get_executable() {
 char *myexec;
 if ((myexec = lbs_posix_readlink ("/proc/self/exe")) != ((void *)0)) {
  return myexec;
 }
 if ((myexec = lbs_posix_readlink ("/proc/curproc/exe")) != ((void *)0)) {
  return myexec;
 }
 if ((myexec = lbs_posix_readlink ("/proc/curproc/file")) != ((void *)0)) {
  return myexec;
 }
 return ((void *)0);
}

variable_types:
myexec
char *

return_type: char *


decompiled_code:
__int64 __fastcall lbs_sysdep_get_resource(__int64 a1)
{
const char *v1; // rax
char *v2; // rbp
char *v3; // rax
bool v4; // bl
__int64 v5; // rcx
__int64 result; // rax
__int64 v7; // [rsp+8h] [rbp-20h]

v1 = (const char *)lbs_sysdep_get_executable();
if ( v1 )
{
v2 = (char *)v1;
v3 = strrchr(v1, 47);
v4 = v2 != v3 && v3 != 0LL;
if ( v4 )
{
*v3 = 0;
v4 = 0;
}
}
else
{
v4 = 0;
v2 = (char *)lbs_posix_getcwd();
if ( !v2 )
{
v4 = 1;
v2 = "./";
}
}
if ( (unsigned __int8)lbs_str_has_suffix(v2, "/") )
{
result = lbs_posix_strcat(v2, a1, 0LL, v5);
if ( v4 )
return result;
LABEL_8:
v7 = result;
free(v2);
return v7;
}
result = lbs_posix_strcat(v2, "/", a1, 0LL);
if ( !v4 )
goto LABEL_8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
const char *v1; // rax
char *v2; // rbp
char *v3; // rax
bool v4; // bl
__int64 v5; // rcx
__int64 result; // rax
__int64 v7; // [rsp+8h] [rbp-20h]

v1 = (const char *)func0();
if ( v1 )
{
v2 = (char *)v1;
v3 = strrchr(v1, 47);
v4 = v2 != v3 && v3 != 0LL;
if ( v4 )
{
*v3 = 0;
v4 = 0;
}
}
else
{
v4 = 0;
v2 = (char *)lbs_posix_getcwd();
if ( !v2 )
{
v4 = 1;
v2 = "./";
}
}
if ( (unsigned __int8)lbs_str_has_suffix(v2, "/") )
{
result = lbs_posix_strcat(v2, a1, 0LL, v5);
if ( v4 )
return result;
LABEL_8:
v7 = result;
free(v2);
return v7;
}
result = lbs_posix_strcat(v2, "/", a1, 0LL);
if ( !v4 )
goto LABEL_8;
return result;
}

original_code:
char* lbs_sysdep_get_resource (const char* filename) {
 char *myexec, *myres;
 _Bool myexec_static = 0;
 myexec = lbs_sysdep_get_executable ();
 if (myexec == ((void *)0)) {
  myexec = lbs_posix_getcwd ();
  if (myexec == ((void *)0)) {
   myexec = "./";
   myexec_static = 1;
  }
 } else {
  char* dirsep = strrchr (myexec, '/');
  if (dirsep != ((void *)0) && dirsep != myexec) {
   *dirsep = '\0';
  }
 }
 if (lbs_str_has_suffix (myexec, "/")) {
  myres = lbs_posix_strcat (myexec, filename, (char*)((void *)0));
 } else {
  myres = lbs_posix_strcat (myexec, "/", filename, (char*)((void *)0));
 }
 if (!myexec_static) {
  free (myexec);
 }
 return myres;
}

canonical_original_code:
char *lbs_sysdep_get_resource(char *filename) {
 char *myexec; char *myres;
 _Bool myexec_static = 0;
 myexec = lbs_sysdep_get_executable ();
 if (myexec == ((void *)0)) {
  myexec = lbs_posix_getcwd ();
  if (myexec == ((void *)0)) {
   myexec = "./";
   myexec_static = 1;
  }
 } else {
  char *dirsep = strrchr (myexec, '/');
  if (dirsep != ((void *)0) && dirsep != myexec) {
   *dirsep = '\0';
  }
 }
 if (lbs_str_has_suffix (myexec, "/")) {
  myres = lbs_posix_strcat (myexec, filename, (char *)((void *)0));
 } else {
  myres = lbs_posix_strcat (myexec, "/", filename, (char *)((void *)0));
 }
 if (!myexec_static) {
  free (myexec);
 }
 return myres;
}

variable_types:
filename
char *

variable_types:
myres
char *

variable_types:
dirsep
char *


convolve

repo: larmel/Master

original_code:
void convolve(int size, const float * restrict input, float * restrict output)
{
    int i, j;
    for (i = 2; i < size - 2; ++i)
    {
        output[i] = 0;
        for (j = 0; j < 5; ++j)
            output[i] += input[i-2+j] * kernel[j];
    }
}

canonical_original_code:
void convolve(int size, float *input, float *output)
{
    int i; int j;
    for (i = 2; i < size - 2; ++i)
    {
        output[i] = 0;
        for (j = 0; j < 5; ++j)
            output[i] += input[i-2+j] * kernel[j];
    }
}

variable_types: size int

variable_types:
input
float *

variable_types:
output
float *

variable_types: i int

variable_types: j int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
void *v4; // r12
char *v5; // r13

v3 = 0;
if ( argc > 1 )
v3 = atoi(argv[1]);
v4 = malloc((size_t)&dword_400000);
v5 = (char *)malloc((size_t)"atoi");
convolve(0x100000LL, v4, &v5[4 * v3]);
printf("Offset: %d : (%p, %p)\n", (unsigned int)v3, v4, v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
void *v4; // r12
char *v5; // r13

v3 = 0;
if ( argc > 1 )
v3 = atoi(argv[1]);
v4 = malloc((size_t)&dword_400000);
v5 = (char *)malloc((size_t)"atoi");
func7(0x100000LL, v4, &v5[4 * v3]);
printf("Offset: %d : (%p, %p)\n", (unsigned int)v3, v4, v5);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    int offset = argc > 1 ? atoi(argv[1]) : 0, i = 0;
    float *input = malloc( 0x100000 * sizeof(float));
    float *result = malloc((0x100000 + 0x100) * sizeof(float));
    convolve(0x100000, input, (result + offset));
    printf("Offset: %d : (%p, %p)\n", offset, input, result);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int offset = argc > 1 ? atoi(argv[1]) : 0; int i = 0;
    float *input = malloc( 0x100000 * sizeof(float));
    float *result = malloc((0x100000 + 0x100) * sizeof(float));
    convolve(0x100000, input, (result + offset));
    printf("Offset: %d : (%p, %p)\n", offset, input, result);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: offset int

variable_types:
result
float *


loop

decompiled_code:
__int64 __fastcall loop(int a1)
{
__int64 result; // rax
int v2; // edx

result = i == 42;
do
{
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
v2 = i++;
}
while ( v2 <= 19088742 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 result; // rax
int v2; // edx

result = i == 42;
do
{
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
if ( !i )
result = (unsigned int)(result + a1 * i * i + 1);
v2 = i++;
}
while ( v2 <= 19088742 );
return result;
}

variable_types: a int

variable_types: b int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
i = loop(10LL, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
i = func6(10LL, argv, envp);
return 0;
}

original_code:
int main()
{
    i = loop(10);
    return 0;
}

canonical_original_code:
int main()
{
    i = loop(10);
    return 0;
}


repo: larsbrinkhoff/ptrace-proxy

decompiled_code:
__int64 __fastcall syscall_get_number(unsigned int a1)
{
return ptrace(PTRACE_PEEKUSER, a1, 80LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return ptrace(PTRACE_PEEKUSER, a1, 80LL, 0LL);
}

original_code:
int
syscall_get_number (pid_t pid)
{
  return ptrace (PTRACE_PEEKUSER, pid, (8 * 10), 0);
}

canonical_original_code:
int syscall_get_number(int pid)
{
  return ptrace (PTRACE_PEEKUSER, pid, (8 * 10), 0);
}

variable_types: pid int


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

result = ptrace(PTRACE_POKEUSER, a1, 80LL, 39LL);
if ( (_DWORD)result == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "ptproxy: couldn't cancel syscall: %s\n", v3);
exit(1);
}
return result;
}

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

result = ptrace(PTRACE_POKEUSER, a1, 80LL, 39LL);
if ( (_DWORD)result == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "ptproxy: couldn't cancel syscall: %s\n", v3);
exit(1);
}
return result;
}

original_code:
void
syscall_cancel (pid_t pid)
{
  int err;
  err = ptrace (PTRACE_POKEUSER, pid, (8 * 10), 39);
  if (err == -1)
    {
      fprintf (stderr, "ptproxy: couldn't cancel syscall: %s\n",
        strerror ((*__errno_location ())));
      exit (1);
    }
}

canonical_original_code:
void syscall_cancel(int pid)
{
  int err;
  err = ptrace (PTRACE_POKEUSER, pid, (8 * 10), 39);
  if (err == -1)
    {
      fprintf (stderr, "ptproxy: couldn't cancel syscall: %s\n",
        strerror ((*__errno_location ())));
      exit (1);
    }
}

variable_types: err int


decompiled_code:
__int64 __fastcall syscall_get_args(unsigned int a1, __int64 *a2, __int64 *a3, __int64 *a4, __int64 *a5, __int64 *a6)
{
__int64 result; // rax

*a2 = ptrace(PTRACE_PEEKUSER, a1, 112LL, 0LL);
*a3 = ptrace(PTRACE_PEEKUSER, a1, 104LL, 0LL);
*a4 = ptrace(PTRACE_PEEKUSER, a1, 96LL, 0LL);
*a5 = ptrace(PTRACE_PEEKUSER, a1, 56LL, 0LL);
result = ptrace(PTRACE_PEEKUSER, a1, 72LL, 0LL);
*a6 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 *a2, __int64 *a3, __int64 *a4, __int64 *a5, __int64 *a6)
{
__int64 result; // rax

*a2 = ptrace(PTRACE_PEEKUSER, a1, 112LL, 0LL);
*a3 = ptrace(PTRACE_PEEKUSER, a1, 104LL, 0LL);
*a4 = ptrace(PTRACE_PEEKUSER, a1, 96LL, 0LL);
*a5 = ptrace(PTRACE_PEEKUSER, a1, 56LL, 0LL);
result = ptrace(PTRACE_PEEKUSER, a1, 72LL, 0LL);
*a6 = result;
return result;
}

original_code:
void
syscall_get_args (pid_t pid, long *arg1, long *arg2,
    long *arg3, long *arg4, long *arg5)
{
  *arg1 = ptrace (PTRACE_PEEKUSER, pid, (8 * 14), 0);
  *arg2 = ptrace (PTRACE_PEEKUSER, pid, (8 * 13), 0);
  *arg3 = ptrace (PTRACE_PEEKUSER, pid, (8 * 12), 0);
  *arg4 = ptrace (PTRACE_PEEKUSER, pid, (8 * 7), 0);
  *arg5 = ptrace (PTRACE_PEEKUSER, pid, (8 * 9), 0);
}

canonical_original_code:
void syscall_get_args(int pid, long *arg1, long *arg2, long *arg3, long *arg4, long *arg5)
{
  *arg1 = ptrace (PTRACE_PEEKUSER, pid, (8 * 14), 0);
  *arg2 = ptrace (PTRACE_PEEKUSER, pid, (8 * 13), 0);
  *arg3 = ptrace (PTRACE_PEEKUSER, pid, (8 * 12), 0);
  *arg4 = ptrace (PTRACE_PEEKUSER, pid, (8 * 7), 0);
  *arg5 = ptrace (PTRACE_PEEKUSER, pid, (8 * 9), 0);
}


decompiled_code:
__int64 __fastcall syscall_set_result(unsigned int a1, __int64 a2)
{
return ptrace(PTRACE_POKEUSER, a1, 80LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2)
{
return ptrace(PTRACE_POKEUSER, a1, 80LL, a2);
}

original_code:
void
syscall_set_result (pid_t pid, long result)
{
  ptrace (PTRACE_POKEUSER, pid, (8 * 10), result);
}

canonical_original_code:
void syscall_set_result(int pid, long result)
{
  ptrace (PTRACE_POKEUSER, pid, (8 * 10), result);
}

variable_types: result long


decompiled_code:
__int64 __fastcall syscall_continue(unsigned int a1)
{
return ptrace(PTRACE_SYSCALL, a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return ptrace(PTRACE_SYSCALL, a1, 0LL, 0LL);
}

original_code:
void
syscall_continue (pid_t pid)
{
  ptrace (PTRACE_SYSCALL, pid, 0, 0);
}

canonical_original_code:
void syscall_continue(int pid)
{
  ptrace (PTRACE_SYSCALL, pid, 0, 0);
}


original_code:
void
proxy_wait (struct debugger *debugger, enum wait_type type, pid_t pid,
     int *status, int options, void *rusage)
{
  debugger->wait_status_ptr = status;
  debugger->wait_options = options;
}

canonical_original_code:
void proxy_wait(struct debugger *debugger, enum wait_type type, int pid, int *status, int options, void *rusage)
{
  debugger->wait_status_ptr = status;
  debugger->wait_options = options;
}

variable_types: struct debugger { int pid; long result; int wait_options; int *wait_status_ptr; unsigned int stopped; void (*handle_trace)(struct debugger *); struct debugee { int pid; int wait_status; unsigned int died; unsigned int event; unsigned int first_stop; unsigned int stopped; unsigned int trace_singlestep; unsigned int trace_syscall; unsigned int traced; unsigned int zombie; struct debugger *debugger; } *debugee; } *

variable_types: enum wait_type { WAIT_WAIT=0, WAIT_WAITPID=1, WAIT_WAIT3=2, WAIT_WAIT4=3 }

variable_types:
status
int *

variable_types: options int

variable_types:
rusage
void *

user_defined_types: struct debugger { int pid; long result; int wait_options; int *wait_status_ptr; unsigned int stopped; void (*handle_trace)(struct debugger *); struct debugee *debugee; }


decompiled_code:
__int64 __fastcall proxy_wait_return(unsigned int *a1)
{
__int64 v1; // rcx
char v2; // al
char v3; // dl
int v4; // esi
__int64 result; // rax
char v6; // al

v1 = *((_QWORD *)a1 + 6);
v2 = *(_BYTE *)(v1 + 8);
v3 = a1[8] & 0xFE;
*((_BYTE *)a1 + 32) = v3;
if ( (v2 & 1) != 0 || (v4 = a1[4], v4 < 0) )
{
*((_QWORD *)a1 + 1) = -10LL;
return debugger_cancelled_return(a1);
}
if ( (v2 & 0x82) != 0x82 )
{
result = v2 & 2;
if ( (v4 & 1) == 0 )
goto LABEL_5;
LABEL_7:
if ( !(_BYTE)result )
{
*((_QWORD *)a1 + 1) = 0LL;
return debugger_cancelled_return(a1);
}
goto LABEL_12;
}
v6 = v2 | 1;
*(_BYTE *)(v1 + 8) = v6;
result = v6 & 2;
if ( (v4 & 1) != 0 )
goto LABEL_7;
LABEL_5:
if ( !(_BYTE)result )
{
*((_BYTE *)a1 + 32) = v3 | 1;
return result;
}
LABEL_12:
*(_BYTE *)(v1 + 8) &= 0xFDu;
ptrace(PTRACE_POKEDATA, *a1, *((_QWORD *)a1 + 3), *(unsigned int *)(v1 + 4));
*((_QWORD *)a1 + 1) = **((int **)a1 + 6);
return debugger_cancelled_return(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
__int64 v1; // rcx
char v2; // al
char v3; // dl
int v4; // esi
__int64 result; // rax
char v6; // al

v1 = *((_QWORD *)a1 + 6);
v2 = *(_BYTE *)(v1 + 8);
v3 = a1[8] & 0xFE;
*((_BYTE *)a1 + 32) = v3;
if ( (v2 & 1) != 0 || (v4 = a1[4], v4 < 0) )
{
*((_QWORD *)a1 + 1) = -10LL;
return debugger_cancelled_return(a1);
}
if ( (v2 & 0x82) != 0x82 )
{
result = v2 & 2;
if ( (v4 & 1) == 0 )
goto LABEL_5;
LABEL_7:
if ( !(_BYTE)result )
{
*((_QWORD *)a1 + 1) = 0LL;
return debugger_cancelled_return(a1);
}
goto LABEL_12;
}
v6 = v2 | 1;
*(_BYTE *)(v1 + 8) = v6;
result = v6 & 2;
if ( (v4 & 1) != 0 )
goto LABEL_7;
LABEL_5:
if ( !(_BYTE)result )
{
*((_BYTE *)a1 + 32) = v3 | 1;
return result;
}
LABEL_12:
*(_BYTE *)(v1 + 8) &= 0xFDu;
ptrace(PTRACE_POKEDATA, *a1, *((_QWORD *)a1 + 3), *(unsigned int *)(v1 + 4));
*((_QWORD *)a1 + 1) = **((int **)a1 + 6);
return debugger_cancelled_return(a1);
}

original_code:
void
proxy_wait_return (struct debugger *debugger)
{
  debugger->stopped = 0;
  if (debugger->debugee->died)
    {
      debugger->result = -10;
      debugger_cancelled_return (debugger);
      return;
    }
  if (debugger->wait_options & 0x80000000)
    {
      debugger->result = -10;
      debugger_cancelled_return (debugger);
      return;
    }
  if (debugger->debugee->zombie && debugger->debugee->event)
    debugger->debugee->died = 1;
  if (debugger->wait_options & 1)
    {
      if (debugger->debugee->event)
 {
   debugger->debugee->event = 0;
   ptrace (PTRACE_POKEDATA, debugger->pid,
    debugger->wait_status_ptr, debugger->debugee->wait_status);
   debugger->result = debugger->debugee->pid;
 }
      else
 {
   debugger->result = 0;
 }
      debugger_cancelled_return (debugger);
      return;
    }
  if (debugger->debugee->event)
    {
      debugger->debugee->event = 0;
      ptrace (PTRACE_POKEDATA, debugger->pid,
       debugger->wait_status_ptr, debugger->debugee->wait_status);
      debugger->result = debugger->debugee->pid;
      debugger_cancelled_return (debugger);
      return;
    }
  debugger->stopped = 1;
}

canonical_original_code:
void proxy_wait_return(struct debugger *debugger)
{
  debugger->stopped = 0;
  if (debugger->debugee->died)
    {
      debugger->result = -10;
      debugger_cancelled_return (debugger);
      return;
    }
  if (debugger->wait_options & 0x80000000)
    {
      debugger->result = -10;
      debugger_cancelled_return (debugger);
      return;
    }
  if (debugger->debugee->zombie && debugger->debugee->event)
    debugger->debugee->died = 1;
  if (debugger->wait_options & 1)
    {
      if (debugger->debugee->event)
 {
   debugger->debugee->event = 0;
   ptrace (PTRACE_POKEDATA, debugger->pid,
    debugger->wait_status_ptr, debugger->debugee->wait_status);
   debugger->result = debugger->debugee->pid;
 }
      else
 {
   debugger->result = 0;
 }
      debugger_cancelled_return (debugger);
      return;
    }
  if (debugger->debugee->event)
    {
      debugger->debugee->event = 0;
      ptrace (PTRACE_POKEDATA, debugger->pid,
       debugger->wait_status_ptr, debugger->debugee->wait_status);
      debugger->result = debugger->debugee->pid;
      debugger_cancelled_return (debugger);
      return;
    }
  debugger->stopped = 1;
}

user_defined_types: struct debugee { int pid; int wait_status; unsigned int died; unsigned int event; unsigned int first_stop; unsigned int stopped; unsigned int trace_singlestep; unsigned int trace_syscall; unsigned int traced; unsigned int zombie; struct debugger *debugger; }


decompiled_code:
__int64 __fastcall debugger_syscall(unsigned int *a1)
{
int v2; // ebp
__int64 (__fastcall *v3)(); // rax
__int64 v4; // rdi
unsigned int v6; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
__int64 v8; // [rsp+18h] [rbp-30h] BYREF
__int64 v9; // [rsp+20h] [rbp-28h] BYREF
char v10[32]; // [rsp+28h] [rbp-20h] BYREF

v2 = syscall_get_number(*a1);
syscall_get_args(*a1, &v6, &v7, &v8, &v9, v10);
if ( v2 == 61 )
{
proxy_wait(a1, 3LL, v6, v7, (unsigned int)v8, v9);
*((_QWORD *)a1 + 5) = &proxy_wait_return;
LABEL_7:
syscall_cancel(*a1);
return syscall_continue(*a1);
}
if ( v2 == 101 )
{
proxy_ptrace(a1, v6, (unsigned int)v7, v8, v9);
*((_QWORD *)a1 + 5) = debugger_cancelled_return;
goto LABEL_7;
}
v3 = debugger_normal_return;
v4 = *a1;
if ( v2 == 59 )
v3 = debugger_syscall;
*((_QWORD *)a1 + 5) = v3;
return syscall_continue(v4);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
int v2; // ebp
__int64 (__fastcall *v3)(); // rax
__int64 v4; // rdi
unsigned int v6; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
__int64 v8; // [rsp+18h] [rbp-30h] BYREF
__int64 v9; // [rsp+20h] [rbp-28h] BYREF
char v10[32]; // [rsp+28h] [rbp-20h] BYREF

v2 = syscall_get_number(*a1);
syscall_get_args(*a1, &v6, &v7, &v8, &v9, v10);
if ( v2 == 61 )
{
proxy_wait(a1, 3LL, v6, v7, (unsigned int)v8, v9);
*((_QWORD *)a1 + 5) = &proxy_wait_return;
LABEL_7:
syscall_cancel(*a1);
return syscall_continue(*a1);
}
if ( v2 == 101 )
{
proxy_ptrace(a1, v6, (unsigned int)v7, v8, v9);
*((_QWORD *)a1 + 5) = debugger_cancelled_return;
goto LABEL_7;
}
v3 = debugger_normal_return;
v4 = *a1;
if ( v2 == 59 )
v3 = debugger_syscall;
*((_QWORD *)a1 + 5) = v3;
return syscall_continue(v4);
}

original_code:
extern void
debugger_syscall (debugger_state *debugger)
{
  int cancel = 0;
  long arg1, arg2, arg3, arg4, arg5;
  int syscall;
  syscall = syscall_get_number (debugger->pid);
  syscall_get_args (debugger->pid, &arg1, &arg2, &arg3, &arg4, &arg5);
  switch (syscall)
    {
    case 59:
      debugger->handle_trace = debugger_syscall;
      break;
    case 101:
      proxy_ptrace (debugger, arg1, arg2, arg3, arg4);
      cancel = 1;
      debugger->handle_trace = debugger_cancelled_return;
      break;
    case 61:
      proxy_wait (debugger,
    syscall == 61 ? WAIT_WAIT4 : -1,
    arg1, (int *)arg2, arg3, (void *)arg4);
      cancel = 1;
      debugger->handle_trace = proxy_wait_return;
      break;
    default:
      debugger->handle_trace = debugger_normal_return;
    }
  if (cancel)
    syscall_cancel (debugger->pid);
  syscall_continue (debugger->pid);
}

canonical_original_code:
extern void debugger_syscall(struct debugger *debugger)
{
  int cancel = 0;
  long arg1; long arg2; long arg3; long arg4; long arg5;
  int syscall;
  syscall = syscall_get_number (debugger->pid);
  syscall_get_args (debugger->pid, &arg1, &arg2, &arg3, &arg4, &arg5);
  switch (syscall)
    {
    case 59:
      debugger->handle_trace = debugger_syscall;
      break;
    case 101:
      proxy_ptrace (debugger, arg1, arg2, arg3, arg4);
      cancel = 1;
      debugger->handle_trace = debugger_cancelled_return;
      break;
    case 61:
      proxy_wait (debugger,
    syscall == 61 ? WAIT_WAIT4 : -1,
    arg1, (int *)arg2, arg3, (void *)arg4);
      cancel = 1;
      debugger->handle_trace = proxy_wait_return;
      break;
    default:
      debugger->handle_trace = debugger_normal_return;
    }
  if (cancel)
    syscall_cancel (debugger->pid);
  syscall_continue (debugger->pid);
}

variable_types: cancel int

variable_types: syscall int


decompiled_code:
__int64 __fastcall debugger_normal_return(unsigned int *a1)
{
*((_QWORD *)a1 + 5) = debugger_syscall;
return syscall_continue(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
*((_QWORD *)a1 + 5) = debugger_syscall;
return syscall_continue(*a1);
}

original_code:
void
debugger_normal_return (debugger_state *debugger)
{
  debugger->handle_trace = debugger_syscall;
  syscall_continue (debugger->pid);
}

canonical_original_code:
void debugger_normal_return(struct debugger *debugger)
{
  debugger->handle_trace = debugger_syscall;
  syscall_continue (debugger->pid);
}


decompiled_code:
__int64 __fastcall debugger_cancelled_return(unsigned int *a1)
{
syscall_set_result(*a1, *((_QWORD *)a1 + 1));
*((_QWORD *)a1 + 5) = debugger_syscall;
return syscall_continue(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1)
{
syscall_set_result(*a1, *((_QWORD *)a1 + 1));
*((_QWORD *)a1 + 5) = debugger_syscall;
return syscall_continue(*a1);
}

original_code:
void
debugger_cancelled_return (debugger_state *debugger)
{
  syscall_set_result (debugger->pid, debugger->result);
  debugger->handle_trace = debugger_syscall;
  syscall_continue (debugger->pid);
}

canonical_original_code:
void debugger_cancelled_return(struct debugger *debugger)
{
  syscall_set_result (debugger->pid, debugger->result);
  debugger->handle_trace = debugger_syscall;
  syscall_continue (debugger->pid);
}


proxy

decompiled_code:
unsigned int __fastcall proxy(__pid_t a1, int a2)
{
int v2; // ebp
unsigned int result; // eax
__pid_t v4; // eax
char v5; // al
int stat_loc; // [rsp+Ch] [rbp-7Ch] BYREF
int v7[2]; // [rsp+10h] [rbp-78h] BYREF
char v8; // [rsp+18h] [rbp-70h]
__pid_t *v9; // [rsp+20h] [rbp-68h]
__pid_t pid[8]; // [rsp+30h] [rbp-58h] BYREF
char v11; // [rsp+50h] [rbp-38h]
__int64 (__fastcall *v12)(unsigned int *); // [rsp+58h] [rbp-30h]
int *v13; // [rsp+60h] [rbp-28h]

v2 = a2;
pid[0] = a1;
v13 = v7;
v11 &= 0xFEu;
v7[0] = a2;
v9 = pid;
v12 = debugger_syscall;
v8 = v8 & 0x30 | 4;
result = sleep(1u);
if ( a1 != -1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v4 = waitpid(-1, &stat_loc, 2);
if ( v4 != -1 )
break;
if ( *_errno_location() != 4 )
goto LABEL_23;
}
if ( a1 == v4 )
break;
if ( v4 == v2 )
{
v5 = v8 | 0xA;
v7[1] = stat_loc;
v8 |= 0xAu;
if ( (_BYTE)stat_loc == 127 )
{
if ( (v5 & 4) != 0 )
{
ptrace(PTRACE_CONT, (unsigned int)v7[0], 0LL, 0LL);
v5 = v8 & 0xF1;
v8 &= 0xF1u;
}
}
else
{
if ( (stat_loc & 0x7F) != 0 && (char)((stat_loc & 0x7F) + 1) <= 1 )
goto LABEL_23;
v2 = -1;
v5 = v8 | 0x80;
v8 |= 0x80u;
}
if ( (v5 & 8) != 0 )
{
kill(pid[0], 17);
if ( (v11 & 1) != 0 )
proxy_wait_return(pid);
}
}
}
if ( (_BYTE)stat_loc != 127 )
break;
if ( BYTE1(stat_loc) == 5 )
v12((unsigned int *)pid);
else
ptrace(PTRACE_SYSCALL, (unsigned int)pid[0], 0LL);
}
result = stat_loc & 0x7F;
if ( (stat_loc & 0x7F) != 0 && (char)++result <= 1 )
LABEL_23:
exit(1);
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func3(__pid_t a1, int a2)
{
int v2; // ebp
unsigned int result; // eax
__pid_t v4; // eax
char v5; // al
int stat_loc; // [rsp+Ch] [rbp-7Ch] BYREF
int v7[2]; // [rsp+10h] [rbp-78h] BYREF
char v8; // [rsp+18h] [rbp-70h]
__pid_t *v9; // [rsp+20h] [rbp-68h]
__pid_t pid[8]; // [rsp+30h] [rbp-58h] BYREF
char v11; // [rsp+50h] [rbp-38h]
__int64 (__fastcall *v12)(unsigned int *); // [rsp+58h] [rbp-30h]
int *v13; // [rsp+60h] [rbp-28h]

v2 = a2;
pid[0] = a1;
v13 = v7;
v11 &= 0xFEu;
v7[0] = a2;
v9 = pid;
v12 = debugger_syscall;
v8 = v8 & 0x30 | 4;
result = sleep(1u);
if ( a1 != -1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v4 = waitpid(-1, &stat_loc, 2);
if ( v4 != -1 )
break;
if ( *_errno_location() != 4 )
goto LABEL_23;
}
if ( a1 == v4 )
break;
if ( v4 == v2 )
{
v5 = v8 | 0xA;
v7[1] = stat_loc;
v8 |= 0xAu;
if ( (_BYTE)stat_loc == 127 )
{
if ( (v5 & 4) != 0 )
{
ptrace(PTRACE_CONT, (unsigned int)v7[0], 0LL, 0LL);
v5 = v8 & 0xF1;
v8 &= 0xF1u;
}
}
else
{
if ( (stat_loc & 0x7F) != 0 && (char)((stat_loc & 0x7F) + 1) <= 1 )
goto LABEL_23;
v2 = -1;
v5 = v8 | 0x80;
v8 |= 0x80u;
}
if ( (v5 & 8) != 0 )
{
kill(pid[0], 17);
if ( (v11 & 1) != 0 )
proxy_wait_return(pid);
}
}
}
if ( (_BYTE)stat_loc != 127 )
break;
if ( BYTE1(stat_loc) == 5 )
v12((unsigned int *)pid);
else
ptrace(PTRACE_SYSCALL, (unsigned int)pid[0], 0LL);
}
result = stat_loc & 0x7F;
if ( (stat_loc & 0x7F) != 0 && (char)++result <= 1 )
LABEL_23:
exit(1);
}
return result;
}

original_code:
void
proxy (pid_t debugger_pid, pid_t child)
{
  debugger_state debugger;
  debugee_state debugee;
  int status;
  int pid;
  debugger.handle_trace = debugger_syscall;
  debugger.pid = debugger_pid;
  debugger.debugee = &debugee;
  debugger.stopped = 0;
  debugee.traced = 0;
  debugee.stopped = 0;
  debugee.event = 0;
  debugee.zombie = 0;
  debugee.died = 0;
  debugee.first_stop = 1;
  debugee.pid = child;
  debugee.debugger = &debugger;
  sleep (1);
  while (debugger_pid != -1)
    {
      do
 {
   pid = waitpid (-1, &status, 2);
 }
      while (pid == -1 && (*__errno_location ()) == 4);
      if (pid == -1)
 {
   exit (1);
 }
      if (pid == debugger_pid)
        {
   if ((((status) & 0xff) == 0x7f))
     {
       if ((((status) & 0xff00) >> 8) == 5)
  {
    debugger.handle_trace (&debugger);
  }
       else
  {
    ptrace (PTRACE_SYSCALL, debugger.pid, 0, (((status) & 0xff00) >> 8));
  }
     }
   else if ((((status) & 0x7f) == 0))
     {
       debugger_pid = -1;
     }
   else if ((((signed char) (((status) & 0x7f) + 1) >> 1) > 0))
     {
       debugger_pid = -1;
     }
   else
     {
       exit (1);
     }
        }
      else if (pid == child)
        {
   debugee.stopped = 1;
   debugee.event = 1;
   debugee.wait_status = status;
   if ((((status) & 0xff) == 0x7f))
     {
       if (debugee.first_stop)
  {
    ptrace (PTRACE_CONT, debugee.pid, 0, 0);
    debugee.stopped = 0;
    debugee.event = 0;
    debugee.first_stop = 0;
  }
     }
   else if ((((status) & 0x7f) == 0))
     {
              debugee.zombie = 1;
       child = -1;
     }
   else if ((((signed char) (((status) & 0x7f) + 1) >> 1) > 0))
     {
              debugee.zombie = 1;
       child = -1;
     }
   else
     {
       exit (1);
     }
   if (debugee.stopped)
     {
       int r;
       r = kill (debugger.pid, 17);
       if (debugger.stopped)
  proxy_wait_return (&debugger);
     }
        }
    }
}

canonical_original_code:
void proxy(int debugger_pid, int child)
{
  struct debugger debugger;
  struct debugee debugee;
  int status;
  int pid;
  debugger.handle_trace = debugger_syscall;
  debugger.pid = debugger_pid;
  debugger.debugee = &debugee;
  debugger.stopped = 0;
  debugee.traced = 0;
  debugee.stopped = 0;
  debugee.event = 0;
  debugee.zombie = 0;
  debugee.died = 0;
  debugee.first_stop = 1;
  debugee.pid = child;
  debugee.debugger = &debugger;
  sleep (1);
  while (debugger_pid != -1)
    {
      do
 {
   pid = waitpid (-1, &status, 2);
 }
      while (pid == -1 && (*__errno_location ()) == 4);
      if (pid == -1)
 {
   exit (1);
 }
      if (pid == debugger_pid)
        {
   if ((((status) & 0xff) == 0x7f))
     {
       if ((((status) & 0xff00) >> 8) == 5)
  {
    debugger.handle_trace (&debugger);
  }
       else
  {
    ptrace (PTRACE_SYSCALL, debugger.pid, 0, (((status) & 0xff00) >> 8));
  }
     }
   else if ((((status) & 0x7f) == 0))
     {
       debugger_pid = -1;
     }
   else if ((((char) (((status) & 0x7f) + 1) >> 1) > 0))
     {
       debugger_pid = -1;
     }
   else
     {
       exit (1);
     }
        }
      else if (pid == child)
        {
   debugee.stopped = 1;
   debugee.event = 1;
   debugee.wait_status = status;
   if ((((status) & 0xff) == 0x7f))
     {
       if (debugee.first_stop)
  {
    ptrace (PTRACE_CONT, debugee.pid, 0, 0);
    debugee.stopped = 0;
    debugee.event = 0;
    debugee.first_stop = 0;
  }
     }
   else if ((((status) & 0x7f) == 0))
     {
              debugee.zombie = 1;
       child = -1;
     }
   else if ((((char) (((status) & 0x7f) + 1) >> 1) > 0))
     {
              debugee.zombie = 1;
       child = -1;
     }
   else
     {
       exit (1);
     }
   if (debugee.stopped)
     {
       int r;
       r = kill (debugger.pid, 17);
       if (debugger.stopped)
  proxy_wait_return (&debugger);
     }
        }
    }
}

variable_types: child int

variable_types: struct debugger { int pid; long result; int wait_options; int *wait_status_ptr; unsigned int stopped; void (*handle_trace)(struct debugger *); struct debugee { int pid; int wait_status; unsigned int died; unsigned int event; unsigned int first_stop; unsigned int stopped; unsigned int trace_singlestep; unsigned int trace_syscall; unsigned int traced; unsigned int zombie; struct debugger *debugger; } *debugee; }

variable_types: struct debugee { int pid; int wait_status; unsigned int died; unsigned int event; unsigned int first_stop; unsigned int stopped; unsigned int trace_singlestep; unsigned int trace_syscall; unsigned int traced; unsigned int zombie; struct debugger { int pid; long result; int wait_options; int *wait_status_ptr; unsigned int stopped; void (*handle_trace)(struct debugger *); struct debugee *debugee; } *debugger; }

variable_types: status int

variable_types: r int


decompiled_code:
int get_test_empty()
{
if ( ID3v2_read_tag("./extra/no_tag.mp3") )
_assert_fail("no_tag == NULL", "test/get_test.c", 0xACu, "get_test_empty");
if ( ID3v2_read_tag("./extra/empty.mp3") )
_assert_fail("empty_tag == NULL", "test/get_test.c", 0xAFu, "get_test_empty");
return puts("GET TEST EMPTY: OK");
}

canonical_decompiled_code:
int func1()
{
if ( ID3v2_read_tag("./extra/no_tag.mp3") )
_assert_fail("no_tag == NULL", "test/get_test.c", 0xACu, "get_test_empty");
if ( ID3v2_read_tag("./extra/empty.mp3") )
_assert_fail("empty_tag == NULL", "test/get_test.c", 0xAFu, "get_test_empty");
return puts("GET TEST EMPTY: OK");
}

original_code:
void get_test_empty()
{
    ID3v2_Tag* no_tag = ID3v2_read_tag("./extra/no_tag.mp3");
    ((no_tag == ((void *)0)) ? (void) (0) : __assert_fail ("no_tag == NULL", "test/get_test.c", 172, __extension__ __PRETTY_FUNCTION__));
    ID3v2_Tag* empty_tag = ID3v2_read_tag("./extra/empty.mp3");
    ((empty_tag == ((void *)0)) ? (void) (0) : __assert_fail ("empty_tag == NULL", "test/get_test.c", 175, __extension__ __PRETTY_FUNCTION__));
    printf("GET TEST EMPTY: OK\n");
}

canonical_original_code:
void get_test_empty()
{
    struct _ID3v2_Tag *no_tag = ID3v2_read_tag("./extra/no_tag.mp3");
    ((no_tag == ((void *)0)) ? (void) (0) : __assert_fail ("no_tag == NULL", "test/get_test.c", 172, __extension__ __PRETTY_FUNCTION__));
    struct _ID3v2_Tag *empty_tag = ID3v2_read_tag("./extra/empty.mp3");
    ((empty_tag == ((void *)0)) ? (void) (0) : __assert_fail ("empty_tag == NULL", "test/get_test.c", 175, __extension__ __PRETTY_FUNCTION__));
    printf("GET TEST EMPTY: OK\n");
}

variable_types: struct _ID3v2_Tag { struct _ID3v2_TagHeader { char identifier[3]; char major_version; char minor_version; char flags; unsigned int tag_size; unsigned int extended_header_size; } *header; struct _ID3v2_FrameList { struct _ID3v2_Frame { struct _ID3v2_FrameHeader { char id[4]; int size; char flags[2]; } *header; void *data; } *frame; struct _ID3v2_FrameList *start; struct _ID3v2_FrameList *next; } *frames; int padding_size; } *

user_defined_types: struct _ID3v2_Tag { struct _ID3v2_TagHeader *header; struct _ID3v2_FrameList *frames; int padding_size; }

user_defined_types: struct _ID3v2_FrameList { struct _ID3v2_Frame *frame; struct _ID3v2_FrameList *start; struct _ID3v2_FrameList *next; }

user_defined_types: struct _ID3v2_Frame { struct _ID3v2_FrameHeader *header; void *data; }


decompiled_code:
int get_test_main()
{
get_test_existing();
return get_test_empty();
}

canonical_decompiled_code:
int func2()
{
func0();
return func1();
}

original_code:
void get_test_main()
{
    get_test_existing();
    get_test_empty();
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
get_test_main(argc, argv, envp);
set_test_main();
delete_test_main();
compat_test_main();
return 0;
}

original_code:
int main()
{
    get_test_main();
    set_test_main();
    delete_test_main();
    compat_test_main();
}


decompiled_code:
__int64 __fastcall ApicFrame_to_char_stream(_QWORD *a1)
{
__int64 v1; // rbp
__int64 v2; // r12
unsigned int v3; // eax
unsigned int v4; // eax

if ( !a1 )
return 0LL;
v1 = FrameHeader_to_char_stream(*a1);
v2 = CharStream_new((unsigned int)(*(_DWORD *)(*a1 + 4LL) + 10));
CharStream_write(v2, *(_QWORD *)(v1 + 8), *(unsigned int *)(v1 + 4));
CharStream_free(v1);
CharStream_write(v2, a1[1], 1LL);
v3 = ID3v2_strlent(*(_QWORD *)(a1[1] + 8LL));
CharStream_write(v2, *(_QWORD *)(a1[1] + 8LL), v3);
CharStream_write(v2, a1[1] + 16LL, 1LL);
v4 = ID3v2_strlent(*(_QWORD *)(a1[1] + 24LL));
CharStream_write(v2, *(_QWORD *)(a1[1] + 24LL), v4);
CharStream_write(v2, *(_QWORD *)(a1[1] + 32LL), *(unsigned int *)(a1[1] + 40LL));
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 v1; // rbp
__int64 v2; // r12
unsigned int v3; // eax
unsigned int v4; // eax

if ( !a1 )
return 0LL;
v1 = FrameHeader_to_char_stream(*a1);
v2 = CharStream_new((unsigned int)(*(_DWORD *)(*a1 + 4LL) + 10));
CharStream_write(v2, *(_QWORD *)(v1 + 8), *(unsigned int *)(v1 + 4));
CharStream_free(v1);
CharStream_write(v2, a1[1], 1LL);
v3 = ID3v2_strlent(*(_QWORD *)(a1[1] + 8LL));
CharStream_write(v2, *(_QWORD *)(a1[1] + 8LL), v3);
CharStream_write(v2, a1[1] + 16LL, 1LL);
v4 = ID3v2_strlent(*(_QWORD *)(a1[1] + 24LL));
CharStream_write(v2, *(_QWORD *)(a1[1] + 24LL), v4);
CharStream_write(v2, *(_QWORD *)(a1[1] + 32LL), *(unsigned int *)(a1[1] + 40LL));
return v2;
}

original_code:
CharStream* ApicFrame_to_char_stream(ID3v2_ApicFrame* frame)
{
    if (frame == ((void *)0)) return ((void *)0);
    CharStream* frame_header_cs = FrameHeader_to_char_stream(frame->header);
    CharStream* frame_cs = CharStream_new(frame->header->size + 10);
    CharStream_write(frame_cs, frame_header_cs->stream, frame_header_cs->size);
    CharStream_free(frame_header_cs);
    CharStream_write(frame_cs, &frame->data->encoding, 1);
    CharStream_write(frame_cs, frame->data->mime_type, ID3v2_strlent(frame->data->mime_type));
    CharStream_write(frame_cs, &frame->data->picture_type, 1);
    CharStream_write(frame_cs, frame->data->description, ID3v2_strlent(frame->data->description));
    CharStream_write(frame_cs, frame->data->data, frame->data->picture_size);
    return frame_cs;
}

canonical_original_code:
struct _CharStream *ApicFrame_to_char_stream(struct _ID3v2_ApicFrame *frame)
{
    if (frame == ((void *)0)) return ((void *)0);
    struct _CharStream *frame_header_cs = FrameHeader_to_char_stream(frame->header);
    struct _CharStream *frame_cs = CharStream_new(frame->header->size + 10);
    CharStream_write(frame_cs, frame_header_cs->stream, frame_header_cs->size);
    CharStream_free(frame_header_cs);
    CharStream_write(frame_cs, &frame->data->encoding, 1);
    CharStream_write(frame_cs, frame->data->mime_type, ID3v2_strlent(frame->data->mime_type));
    CharStream_write(frame_cs, &frame->data->picture_type, 1);
    CharStream_write(frame_cs, frame->data->description, ID3v2_strlent(frame->data->description));
    CharStream_write(frame_cs, frame->data->data, frame->data->picture_size);
    return frame_cs;
}

variable_types: struct _ID3v2_ApicFrame { struct _ID3v2_FrameHeader { char id[4]; int size; char flags[2]; } *header; struct _ID3v2_ApicFrameData { char encoding; char *mime_type; char picture_type; char *description; char *data; int picture_size; } *data; } *

variable_types: struct _CharStream { int cursor; int size; char *stream; } *

user_defined_types: struct _ID3v2_ApicFrame { struct _ID3v2_FrameHeader *header; struct _ID3v2_ApicFrameData *data; }


decompiled_code:
void __fastcall ApicFrame_free(void *ptr)
{
FrameHeader_free(*(_QWORD *)ptr);
free(*(void **)(*((_QWORD *)ptr + 1) + 32LL));
free(*(void **)(*((_QWORD *)ptr + 1) + 24LL));
free(*(void **)(*((_QWORD *)ptr + 1) + 8LL));
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
FrameHeader_free(*(_QWORD *)ptr);
free(*(void **)(*((_QWORD *)ptr + 1) + 32LL));
free(*(void **)(*((_QWORD *)ptr + 1) + 24LL));
free(*(void **)(*((_QWORD *)ptr + 1) + 8LL));
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void ApicFrame_free(ID3v2_ApicFrame* frame)
{
    FrameHeader_free(frame->header);
    free(frame->data->data);
    free(frame->data->description);
    free(frame->data->mime_type);
    free(frame->data);
    free(frame);
}

canonical_original_code:
void ApicFrame_free(struct _ID3v2_ApicFrame *frame)
{
    FrameHeader_free(frame->header);
    free(frame->data->data);
    free(frame->data->description);
    free(frame->data->mime_type);
    free(frame->data);
    free(frame);
}

user_defined_types: struct _ID3v2_FrameHeader { char id[4]; int size; char flags[2]; }

user_defined_types: struct _ID3v2_ApicFrameData { char encoding; char *mime_type; char picture_type; char *description; char *data; int picture_size; }


decompiled_code:
int compat_test_main()
{
__int64 v0; // rbp
void *v1; // r15
void *v2; // rbx
__int64 v3; // rax
const void **v4; // r12
int v5; // eax
__int64 v6; // rax
const void **v7; // r14
int v8; // eax
__int64 v9; // rax
const void **v10; // r13
int v11; // eax
__int64 v12; // rax
__int64 v13; // r8
__int64 v14; // rax
__int64 v15; // rbp
__int64 v16; // rax
const void **v17; // r12
int v18; // eax
__int64 v19; // rax
const void **v20; // r14
int v21; // eax
__int64 v22; // rax
const void **v23; // r13
int v24; // eax
__int64 v25; // rax
void **v26; // r15
void *s2; // [rsp+0h] [rbp-48h]
void **ptr; // [rsp+8h] [rbp-40h]

clone_file("extra/file.mp3", "extra/file_edited.mp3");
v0 = load_tag("extra/file_edited.mp3");
if ( !v0 )
v0 = new_tag();
v1 = (void *)ID3v2_to_unicode("Smoke And Shadows");
v2 = (void *)ID3v2_to_unicode("Ethereal Darkness");
s2 = (void *)ID3v2_to_unicode("Rivers");
v3 = tag_get_album(v0);
v4 = (const void **)parse_text_frame_content(v3);
v5 = ID3v2_strlent("Smoke And Shadows");
if ( memcmp(v4[1], v1, v5) )
_assert_fail(
"memcmp(album_content->data, album, ID3v2_strlent(\"Smoke And Shadows\")) == 0",
"test/compat_test.c",
0x26u,
"compat_test_main");
v6 = tag_get_artist(v0);
v7 = (const void **)parse_text_frame_content(v6);
v8 = ID3v2_strlent("Ethereal Darkness");
if ( memcmp(v7[1], v2, v8) )
_assert_fail(
"memcmp(artist_content->data, artist, ID3v2_strlent(\"Ethereal Darkness\")) == 0",
"test/compat_test.c",
0x2Au,
"compat_test_main");
v9 = tag_get_title(v0);
v10 = (const void **)parse_text_frame_content(v9);
v11 = ID3v2_strlent("Rivers");
if ( memcmp(v10[1], s2, v11) )
_assert_fail(
"memcmp(title_content->data, title, ID3v2_strlent(\"Rivers\")) == 0",
"test/compat_test.c",
0x2Eu,
"compat_test_main");
v12 = tag_get_year(v0);
v13 = parse_text_frame_content(v12);
if ( **(_DWORD **)(v13 + 8) != 959524914 )
_assert_fail("memcmp(year_content->data, \"2019\", 4) == 0", "test/compat_test.c", 0x32u, "compat_test_main");
ptr = (void **)v13;
free((void *)v7[1]);
free(v7);
free((void *)v4[1]);
free(v4);
free((void *)v10[1]);
free(v10);
free(ptr[1]);
free(ptr);
free(v1);
free(v2);
free(s2);
tag_set_album("Album", 0LL, v0);
tag_set_artist("Artist", 0LL, v0);
tag_set_title("Title", 0LL, v0);
tag_set_year("0000", 0LL, v0);
set_tag("extra/file_edited.mp3", v0);
free_tag(v0);
v14 = load_tag("extra/file_edited.mp3");
v15 = v14;
if ( !v14 )
_assert_fail("tag != NULL", "test/compat_test.c", 0x4Eu, "compat_test_main");
v16 = tag_get_album(v14);
v17 = (const void **)parse_text_frame_content(v16);
v18 = ID3v2_strlent("Album");
if ( memcmp(v17[1], "Album", v18) )
_assert_fail(
"memcmp(album_content->data, \"Album\", ID3v2_strlent(\"Album\")) == 0",
"test/compat_test.c",
0x52u,
"compat_test_main");
v19 = tag_get_artist(v15);
v20 = (const void **)parse_text_frame_content(v19);
v21 = ID3v2_strlent("Artist");
if ( memcmp(v20[1], "Artist", v21) )
_assert_fail(
"memcmp(artist_content->data, \"Artist\", ID3v2_strlent(\"Artist\")) == 0",
"test/compat_test.c",
0x56u,
"compat_test_main");
v22 = tag_get_title(v15);
v23 = (const void **)parse_text_frame_content(v22);
v24 = ID3v2_strlent("Title");
if ( memcmp(v23[1], "Title", v24) )
_assert_fail(
"memcmp(title_content->data, \"Title\", ID3v2_strlent(\"Title\")) == 0",
"test/compat_test.c",
0x5Au,
"compat_test_main");
v25 = tag_get_year(v15);
v26 = (void **)parse_text_frame_content(v25);
if ( *(_DWORD *)v26[1] != 808464432 )
_assert_fail("memcmp(year_content->data, \"0000\", 4) == 0", "test/compat_test.c", 0x5Eu, "compat_test_main");
remove("extra/file_edited.mp3");
free_tag(v15);
free((void *)v20[1]);
free(v20);
free((void *)v17[1]);
free(v17);
free((void *)v23[1]);
free(v23);
free(v26[1]);
free(v26);
return puts("COMPAT TEST: OK");
}

canonical_decompiled_code:
int func0()
{
__int64 v0; // rbp
void *v1; // r15
void *v2; // rbx
__int64 v3; // rax
const void **v4; // r12
int v5; // eax
__int64 v6; // rax
const void **v7; // r14
int v8; // eax
__int64 v9; // rax
const void **v10; // r13
int v11; // eax
__int64 v12; // rax
__int64 v13; // r8
__int64 v14; // rax
__int64 v15; // rbp
__int64 v16; // rax
const void **v17; // r12
int v18; // eax
__int64 v19; // rax
const void **v20; // r14
int v21; // eax
__int64 v22; // rax
const void **v23; // r13
int v24; // eax
__int64 v25; // rax
void **v26; // r15
void *s2; // [rsp+0h] [rbp-48h]
void **ptr; // [rsp+8h] [rbp-40h]

clone_file("extra/file.mp3", "extra/file_edited.mp3");
v0 = load_tag("extra/file_edited.mp3");
if ( !v0 )
v0 = new_tag();
v1 = (void *)ID3v2_to_unicode("Smoke And Shadows");
v2 = (void *)ID3v2_to_unicode("Ethereal Darkness");
s2 = (void *)ID3v2_to_unicode("Rivers");
v3 = tag_get_album(v0);
v4 = (const void **)parse_text_frame_content(v3);
v5 = ID3v2_strlent("Smoke And Shadows");
if ( memcmp(v4[1], v1, v5) )
_assert_fail(
"memcmp(album_content->data, album, ID3v2_strlent(\"Smoke And Shadows\")) == 0",
"test/compat_test.c",
0x26u,
"compat_test_main");
v6 = tag_get_artist(v0);
v7 = (const void **)parse_text_frame_content(v6);
v8 = ID3v2_strlent("Ethereal Darkness");
if ( memcmp(v7[1], v2, v8) )
_assert_fail(
"memcmp(artist_content->data, artist, ID3v2_strlent(\"Ethereal Darkness\")) == 0",
"test/compat_test.c",
0x2Au,
"compat_test_main");
v9 = tag_get_title(v0);
v10 = (const void **)parse_text_frame_content(v9);
v11 = ID3v2_strlent("Rivers");
if ( memcmp(v10[1], s2, v11) )
_assert_fail(
"memcmp(title_content->data, title, ID3v2_strlent(\"Rivers\")) == 0",
"test/compat_test.c",
0x2Eu,
"compat_test_main");
v12 = tag_get_year(v0);
v13 = parse_text_frame_content(v12);
if ( **(_DWORD **)(v13 + 8) != 959524914 )
_assert_fail("memcmp(year_content->data, \"2019\", 4) == 0", "test/compat_test.c", 0x32u, "compat_test_main");
ptr = (void **)v13;
free((void *)v7[1]);
free(v7);
free((void *)v4[1]);
free(v4);
free((void *)v10[1]);
free(v10);
free(ptr[1]);
free(ptr);
free(v1);
free(v2);
free(s2);
tag_set_album("Album", 0LL, v0);
tag_set_artist("Artist", 0LL, v0);
tag_set_title("Title", 0LL, v0);
tag_set_year("0000", 0LL, v0);
set_tag("extra/file_edited.mp3", v0);
free_tag(v0);
v14 = load_tag("extra/file_edited.mp3");
v15 = v14;
if ( !v14 )
_assert_fail("tag != NULL", "test/compat_test.c", 0x4Eu, "compat_test_main");
v16 = tag_get_album(v14);
v17 = (const void **)parse_text_frame_content(v16);
v18 = ID3v2_strlent("Album");
if ( memcmp(v17[1], "Album", v18) )
_assert_fail(
"memcmp(album_content->data, \"Album\", ID3v2_strlent(\"Album\")) == 0",
"test/compat_test.c",
0x52u,
"compat_test_main");
v19 = tag_get_artist(v15);
v20 = (const void **)parse_text_frame_content(v19);
v21 = ID3v2_strlent("Artist");
if ( memcmp(v20[1], "Artist", v21) )
_assert_fail(
"memcmp(artist_content->data, \"Artist\", ID3v2_strlent(\"Artist\")) == 0",
"test/compat_test.c",
0x56u,
"compat_test_main");
v22 = tag_get_title(v15);
v23 = (const void **)parse_text_frame_content(v22);
v24 = ID3v2_strlent("Title");
if ( memcmp(v23[1], "Title", v24) )
_assert_fail(
"memcmp(title_content->data, \"Title\", ID3v2_strlent(\"Title\")) == 0",
"test/compat_test.c",
0x5Au,
"compat_test_main");
v25 = tag_get_year(v15);
v26 = (void **)parse_text_frame_content(v25);
if ( *(_DWORD *)v26[1] != 808464432 )
_assert_fail("memcmp(year_content->data, \"0000\", 4) == 0", "test/compat_test.c", 0x5Eu, "compat_test_main");
remove("extra/file_edited.mp3");
free_tag(v15);
free((void *)v20[1]);
free(v20);
free((void *)v17[1]);
free(v17);
free((void *)v23[1]);
free(v23);
free(v26[1]);
free(v26);
return puts("COMPAT TEST: OK");
}

original_code:
void compat_test_main()
{
    clone_file("extra/file.mp3", "extra/file_edited.mp3");
    ID3v2_tag* tag = load_tag("extra/file_edited.mp3");
    if (tag == ((void *)0)) tag = new_tag();
    char* album = ID3v2_to_unicode("Smoke And Shadows");
    char* artist = ID3v2_to_unicode("Ethereal Darkness");
    char* title = ID3v2_to_unicode("Rivers");
    ID3v2_frame* album_frame = tag_get_album(tag);
    ID3v2_frame_text_content* album_content = parse_text_frame_content(album_frame);
    ((memcmp(album_content->data, album, ID3v2_strlent("Smoke And Shadows")) == 0) ? (void) (0) : __assert_fail ("memcmp(album_content->data, album, ID3v2_strlent(\"Smoke And Shadows\")) == 0", "test/compat_test.c", 38, __extension__ __PRETTY_FUNCTION__));
    ID3v2_frame* artist_frame = tag_get_artist(tag);
    ID3v2_frame_text_content* artist_content = parse_text_frame_content(artist_frame);
    ((memcmp(artist_content->data, artist, ID3v2_strlent("Ethereal Darkness")) == 0) ? (void) (0) : __assert_fail ("memcmp(artist_content->data, artist, ID3v2_strlent(\"Ethereal Darkness\")) == 0", "test/compat_test.c", 42, __extension__ __PRETTY_FUNCTION__));
    ID3v2_frame* title_frame = tag_get_title(tag);
    ID3v2_frame_text_content* title_content = parse_text_frame_content(title_frame);
    ((memcmp(title_content->data, title, ID3v2_strlent("Rivers")) == 0) ? (void) (0) : __assert_fail ("memcmp(title_content->data, title, ID3v2_strlent(\"Rivers\")) == 0", "test/compat_test.c", 46, __extension__ __PRETTY_FUNCTION__));
    ID3v2_frame* year_frame = tag_get_year(tag);
    ID3v2_frame_text_content* year_content = parse_text_frame_content(year_frame);
    ((memcmp(year_content->data, "2019", 4) == 0) ? (void) (0) : __assert_fail ("memcmp(year_content->data, \"2019\", 4) == 0", "test/compat_test.c", 50, __extension__ __PRETTY_FUNCTION__));
    free(artist_content->data);
    free(artist_content);
    free(album_content->data);
    free(album_content);
    free(title_content->data);
    free(title_content);
    free(year_content->data);
    free(year_content);
    free(album);
    free(artist);
    free(title);
    tag_set_album("Album", 0, tag);
    tag_set_artist("Artist", 0, tag);
    tag_set_title("Title", 0, tag);
    tag_set_year("0000", 0, tag);
    set_tag("extra/file_edited.mp3", tag);
    free_tag(tag);
    tag = load_tag("extra/file_edited.mp3");
    ((tag != ((void *)0)) ? (void) (0) : __assert_fail ("tag != NULL", "test/compat_test.c", 78, __extension__ __PRETTY_FUNCTION__));
    album_frame = tag_get_album(tag);
    album_content = parse_text_frame_content(album_frame);
    ((memcmp(album_content->data, "Album", ID3v2_strlent("Album")) == 0) ? (void) (0) : __assert_fail ("memcmp(album_content->data, \"Album\", ID3v2_strlent(\"Album\")) == 0", "test/compat_test.c", 82, __extension__ __PRETTY_FUNCTION__));
    artist_frame = tag_get_artist(tag);
    artist_content = parse_text_frame_content(artist_frame);
    ((memcmp(artist_content->data, "Artist", ID3v2_strlent("Artist")) == 0) ? (void) (0) : __assert_fail ("memcmp(artist_content->data, \"Artist\", ID3v2_strlent(\"Artist\")) == 0", "test/compat_test.c", 86, __extension__ __PRETTY_FUNCTION__));
    title_frame = tag_get_title(tag);
    title_content = parse_text_frame_content(title_frame);
    ((memcmp(title_content->data, "Title", ID3v2_strlent("Title")) == 0) ? (void) (0) : __assert_fail ("memcmp(title_content->data, \"Title\", ID3v2_strlent(\"Title\")) == 0", "test/compat_test.c", 90, __extension__ __PRETTY_FUNCTION__));
    year_frame = tag_get_year(tag);
    year_content = parse_text_frame_content(year_frame);
    ((memcmp(year_content->data, "0000", 4) == 0) ? (void) (0) : __assert_fail ("memcmp(year_content->data, \"0000\", 4) == 0", "test/compat_test.c", 94, __extension__ __PRETTY_FUNCTION__));
    remove("extra/file_edited.mp3");
    free_tag(tag);
    free(artist_content->data);
    free(artist_content);
    free(album_content->data);
    free(album_content);
    free(title_content->data);
    free(title_content);
    free(year_content->data);
    free(year_content);
    printf("COMPAT TEST: OK\n");
}

canonical_original_code:
void compat_test_main()
{
    clone_file("extra/file.mp3", "extra/file_edited.mp3");
    struct ID3v2_tag *tag = load_tag("extra/file_edited.mp3");
    if (tag == ((void *)0)) tag = new_tag();
    char *album = ID3v2_to_unicode("Smoke And Shadows");
    char *artist = ID3v2_to_unicode("Ethereal Darkness");
    char *title = ID3v2_to_unicode("Rivers");
    struct ID3v2_frame *album_frame = tag_get_album(tag);
    struct ID3v2_frame_text_content *album_content = parse_text_frame_content(album_frame);
    ((memcmp(album_content->data, album, ID3v2_strlent("Smoke And Shadows")) == 0) ? (void) (0) : __assert_fail ("memcmp(album_content->data, album, ID3v2_strlent(\"Smoke And Shadows\")) == 0", "test/compat_test.c", 38, __extension__ __PRETTY_FUNCTION__));
    struct ID3v2_frame *artist_frame = tag_get_artist(tag);
    struct ID3v2_frame_text_content *artist_content = parse_text_frame_content(artist_frame);
    ((memcmp(artist_content->data, artist, ID3v2_strlent("Ethereal Darkness")) == 0) ? (void) (0) : __assert_fail ("memcmp(artist_content->data, artist, ID3v2_strlent(\"Ethereal Darkness\")) == 0", "test/compat_test.c", 42, __extension__ __PRETTY_FUNCTION__));
    struct ID3v2_frame *title_frame = tag_get_title(tag);
    struct ID3v2_frame_text_content *title_content = parse_text_frame_content(title_frame);
    ((memcmp(title_content->data, title, ID3v2_strlent("Rivers")) == 0) ? (void) (0) : __assert_fail ("memcmp(title_content->data, title, ID3v2_strlent(\"Rivers\")) == 0", "test/compat_test.c", 46, __extension__ __PRETTY_FUNCTION__));
    struct ID3v2_frame *year_frame = tag_get_year(tag);
    struct ID3v2_frame_text_content *year_content = parse_text_frame_content(year_frame);
    ((memcmp(year_content->data, "2019", 4) == 0) ? (void) (0) : __assert_fail ("memcmp(year_content->data, \"2019\", 4) == 0", "test/compat_test.c", 50, __extension__ __PRETTY_FUNCTION__));
    free(artist_content->data);
    free(artist_content);
    free(album_content->data);
    free(album_content);
    free(title_content->data);
    free(title_content);
    free(year_content->data);
    free(year_content);
    free(album);
    free(artist);
    free(title);
    tag_set_album("Album", 0, tag);
    tag_set_artist("Artist", 0, tag);
    tag_set_title("Title", 0, tag);
    tag_set_year("0000", 0, tag);
    set_tag("extra/file_edited.mp3", tag);
    free_tag(tag);
    tag = load_tag("extra/file_edited.mp3");
    ((tag != ((void *)0)) ? (void) (0) : __assert_fail ("tag != NULL", "test/compat_test.c", 78, __extension__ __PRETTY_FUNCTION__));
    album_frame = tag_get_album(tag);
    album_content = parse_text_frame_content(album_frame);
    ((memcmp(album_content->data, "Album", ID3v2_strlent("Album")) == 0) ? (void) (0) : __assert_fail ("memcmp(album_content->data, \"Album\", ID3v2_strlent(\"Album\")) == 0", "test/compat_test.c", 82, __extension__ __PRETTY_FUNCTION__));
    artist_frame = tag_get_artist(tag);
    artist_content = parse_text_frame_content(artist_frame);
    ((memcmp(artist_content->data, "Artist", ID3v2_strlent("Artist")) == 0) ? (void) (0) : __assert_fail ("memcmp(artist_content->data, \"Artist\", ID3v2_strlent(\"Artist\")) == 0", "test/compat_test.c", 86, __extension__ __PRETTY_FUNCTION__));
    title_frame = tag_get_title(tag);
    title_content = parse_text_frame_content(title_frame);
    ((memcmp(title_content->data, "Title", ID3v2_strlent("Title")) == 0) ? (void) (0) : __assert_fail ("memcmp(title_content->data, \"Title\", ID3v2_strlent(\"Title\")) == 0", "test/compat_test.c", 90, __extension__ __PRETTY_FUNCTION__));
    year_frame = tag_get_year(tag);
    year_content = parse_text_frame_content(year_frame);
    ((memcmp(year_content->data, "0000", 4) == 0) ? (void) (0) : __assert_fail ("memcmp(year_content->data, \"0000\", 4) == 0", "test/compat_test.c", 94, __extension__ __PRETTY_FUNCTION__));
    remove("extra/file_edited.mp3");
    free_tag(tag);
    free(artist_content->data);
    free(artist_content);
    free(album_content->data);
    free(album_content);
    free(title_content->data);
    free(title_content);
    free(year_content->data);
    free(year_content);
    printf("COMPAT TEST: OK\n");
}

variable_types: struct ID3v2_tag { char *raw; struct ID3v2_header { char tag[3]; char major_version; char minor_version; char flags; int tag_size; int extended_header_size; } *tag_header; struct _ID3v2_frame_list { struct ID3v2_frame { char frame_id[4]; int size; char flags[2]; char *data; struct _ID3v2_Frame { struct _ID3v2_FrameHeader { char id[4]; int size; char flags[2]; } *header; void *data; } *frame; } *frame; struct _ID3v2_frame_list *start; struct _ID3v2_frame_list *last; struct _ID3v2_frame_list *next; } *frames; struct _ID3v2_Tag { struct _ID3v2_TagHeader { char identifier[3]; char major_version; char minor_version; char flags; unsigned int tag_size; unsigned int extended_header_size; } *header; struct _ID3v2_FrameList { struct _ID3v2_Frame *frame; struct _ID3v2_FrameList *start; struct _ID3v2_FrameList *next; } *frames; int padding_size; } *tag; } *

variable_types:
album
char *

variable_types:
artist
char *

variable_types:
title
char *

variable_types: struct ID3v2_frame_text_content { int size; char encoding; char *data; } *

user_defined_types: struct ID3v2_tag { char *raw; struct ID3v2_header *tag_header; struct _ID3v2_frame_list *frames; struct _ID3v2_Tag *tag; }

user_defined_types: struct ID3v2_frame { char frame_id[4]; int size; char flags[2]; char *data; struct _ID3v2_Frame *frame; }

user_defined_types: struct _ID3v2_frame_list { struct ID3v2_frame *frame; struct _ID3v2_frame_list *start; struct _ID3v2_frame_list *last; struct _ID3v2_frame_list *next; }


decompiled_code:
__int64 __fastcall Frame_parse(__int64 a1, unsigned int a2)
{
__int64 v3; // rax
_QWORD *v4; // rbp
_QWORD *v5; // rax
size_t v6; // rdi
_QWORD *v7; // r13
void *v8; // rax
__int64 result; // rax

v3 = FrameHeader_parse();
v4 = (_QWORD *)v3;
if ( !v3 )
return (__int64)v4;
if ( (unsigned __int8)FrameHeader_isTextFrame(v3) )
{
CharStream_seek(a1, 4294967286LL, 1LL);
FrameHeader_free(v4);
result = TextFrame_parse(a1, a2);
}
else if ( (unsigned __int8)FrameHeader_isCommentFrame(v4) )
{
CharStream_seek(a1, 4294967286LL, 1LL);
FrameHeader_free(v4);
result = CommentFrame_parse(a1, a2);
}
else
{
if ( !(unsigned __int8)FrameHeader_isApicFrame(v4) )
{
v5 = malloc(0x10uLL);
v6 = *((int *)v4 + 1);
*v5 = v4;
v7 = v5;
v4 = v5;
v8 = malloc(v6);
v7[1] = v8;
CharStream_read(a1, v8, (unsigned int)v6);
return (__int64)v4;
}
CharStream_seek(a1, 4294967286LL, 1LL);
FrameHeader_free(v4);
result = ApicFrame_parse(a1, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
__int64 v3; // rax
_QWORD *v4; // rbp
_QWORD *v5; // rax
size_t v6; // rdi
_QWORD *v7; // r13
void *v8; // rax
__int64 result; // rax

v3 = FrameHeader_parse();
v4 = (_QWORD *)v3;
if ( !v3 )
return (__int64)v4;
if ( (unsigned __int8)FrameHeader_isTextFrame(v3) )
{
CharStream_seek(a1, 4294967286LL, 1LL);
FrameHeader_free(v4);
result = TextFrame_parse(a1, a2);
}
else if ( (unsigned __int8)FrameHeader_isCommentFrame(v4) )
{
CharStream_seek(a1, 4294967286LL, 1LL);
FrameHeader_free(v4);
result = CommentFrame_parse(a1, a2);
}
else
{
if ( !(unsigned __int8)FrameHeader_isApicFrame(v4) )
{
v5 = malloc(0x10uLL);
v6 = *((int *)v4 + 1);
*v5 = v4;
v7 = v5;
v4 = v5;
v8 = malloc(v6);
v7[1] = v8;
CharStream_read(a1, v8, (unsigned int)v6);
return (__int64)v4;
}
CharStream_seek(a1, 4294967286LL, 1LL);
FrameHeader_free(v4);
result = ApicFrame_parse(a1, a2);
}
return result;
}

original_code:
ID3v2_Frame* Frame_parse(CharStream* frame_cs, int id3_major_version)
{
    ID3v2_FrameHeader* header = FrameHeader_parse(frame_cs, id3_major_version);
    if (header == ((void *)0)) return ((void *)0);
    if (FrameHeader_isTextFrame(header))
    {
        CharStream_seek(frame_cs, -10, 1);
        FrameHeader_free(header);
        return (ID3v2_Frame*) TextFrame_parse(frame_cs, id3_major_version);
    }
    else if (FrameHeader_isCommentFrame(header))
    {
        CharStream_seek(frame_cs, -10, 1);
        FrameHeader_free(header);
        return (ID3v2_Frame*) CommentFrame_parse(frame_cs, id3_major_version);
    }
    else if (FrameHeader_isApicFrame(header))
    {
        CharStream_seek(frame_cs, -10, 1);
        FrameHeader_free(header);
        return (ID3v2_Frame*) ApicFrame_parse(frame_cs, id3_major_version);
    }
    ID3v2_Frame* frame = (ID3v2_Frame*) malloc(sizeof(ID3v2_Frame));
    frame->header = header;
    frame->data = (char*) malloc(header->size * sizeof(char));
    CharStream_read(frame_cs, frame->data, header->size);
    return frame;
}

canonical_original_code:
struct _ID3v2_Frame *Frame_parse(struct _CharStream *frame_cs, int id3_major_version)
{
    struct _ID3v2_FrameHeader *header = FrameHeader_parse(frame_cs, id3_major_version);
    if (header == ((void *)0)) return ((void *)0);
    if (FrameHeader_isTextFrame(header))
    {
        CharStream_seek(frame_cs, -10, 1);
        FrameHeader_free(header);
        return (struct _ID3v2_Frame *) TextFrame_parse(frame_cs, id3_major_version);
    }
    else if (FrameHeader_isCommentFrame(header))
    {
        CharStream_seek(frame_cs, -10, 1);
        FrameHeader_free(header);
        return (struct _ID3v2_Frame *) CommentFrame_parse(frame_cs, id3_major_version);
    }
    else if (FrameHeader_isApicFrame(header))
    {
        CharStream_seek(frame_cs, -10, 1);
        FrameHeader_free(header);
        return (struct _ID3v2_Frame *) ApicFrame_parse(frame_cs, id3_major_version);
    }
    struct _ID3v2_Frame *frame = (ID3v2_Frame*) malloc(sizeof(ID3v2_Frame));
    frame->header = header;
    frame->data = (char *) malloc(header->size * sizeof(char));
    CharStream_read(frame_cs, frame->data, header->size);
    return frame;
}

variable_types: struct _ID3v2_Frame { struct _ID3v2_FrameHeader { char id[4]; int size; char flags[2]; } *header; void *data; } *

user_defined_types: struct _CharStream { int cursor; int size; char *stream; }


decompiled_code:
__int64 __fastcall Frame_to_char_stream(_QWORD *a1)
{
__int64 v1; // r12
__int64 v2; // rax

if ( !a1 )
return 0LL;
if ( (unsigned __int8)FrameHeader_isTextFrame(*a1) )
return TextFrame_to_char_stream(a1);
if ( (unsigned __int8)FrameHeader_isCommentFrame(*a1) )
return CommentFrame_to_char_stream(a1);
if ( (unsigned __int8)FrameHeader_isApicFrame(*a1) )
return ApicFrame_to_char_stream(a1);
v1 = CharStream_new((unsigned int)(*(_DWORD *)(*a1 + 4LL) + 10));
v2 = FrameHeader_to_char_stream(*a1);
CharStream_write(v1, *(_QWORD *)(v2 + 8), 10LL);
CharStream_write(v1, a1[1], *(unsigned int *)(*a1 + 4LL));
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 v1; // r12
__int64 v2; // rax

if ( !a1 )
return 0LL;
if ( (unsigned __int8)FrameHeader_isTextFrame(*a1) )
return TextFrame_to_char_stream(a1);
if ( (unsigned __int8)FrameHeader_isCommentFrame(*a1) )
return CommentFrame_to_char_stream(a1);
if ( (unsigned __int8)FrameHeader_isApicFrame(*a1) )
return ApicFrame_to_char_stream(a1);
v1 = CharStream_new((unsigned int)(*(_DWORD *)(*a1 + 4LL) + 10));
v2 = FrameHeader_to_char_stream(*a1);
CharStream_write(v1, *(_QWORD *)(v2 + 8), 10LL);
CharStream_write(v1, a1[1], *(unsigned int *)(*a1 + 4LL));
return v1;
}

original_code:
CharStream* Frame_to_char_stream(ID3v2_Frame* frame)
{
    if (frame == ((void *)0)) return ((void *)0);
    if (FrameHeader_isTextFrame(frame->header))
    {
        return TextFrame_to_char_stream((ID3v2_TextFrame*) frame);
    }
    else if (FrameHeader_isCommentFrame(frame->header))
    {
        return CommentFrame_to_char_stream((ID3v2_CommentFrame*) frame);
    }
    else if (FrameHeader_isApicFrame(frame->header))
    {
        return ApicFrame_to_char_stream((ID3v2_ApicFrame*) frame);
    }
    else
    {
        CharStream* frame_cs = CharStream_new(frame->header->size + 10);
        CharStream* header_cs = FrameHeader_to_char_stream(frame->header);
        CharStream_write(frame_cs, header_cs->stream, 10);
        CharStream_write(frame_cs, frame->data, frame->header->size);
        return frame_cs;
    }
}

canonical_original_code:
struct _CharStream *Frame_to_char_stream(struct _ID3v2_Frame *frame)
{
    if (frame == ((void *)0)) return ((void *)0);
    if (FrameHeader_isTextFrame(frame->header))
    {
        return TextFrame_to_char_stream((struct _ID3v2_TextFrame *) frame);
    }
    else if (FrameHeader_isCommentFrame(frame->header))
    {
        return CommentFrame_to_char_stream((struct _ID3v2_CommentFrame *) frame);
    }
    else if (FrameHeader_isApicFrame(frame->header))
    {
        return ApicFrame_to_char_stream((struct _ID3v2_ApicFrame *) frame);
    }
    else
    {
        struct _CharStream *frame_cs = CharStream_new(frame->header->size + 10);
        struct _CharStream *header_cs = FrameHeader_to_char_stream(frame->header);
        CharStream_write(frame_cs, header_cs->stream, 10);
        CharStream_write(frame_cs, frame->data, frame->header->size);
        return frame_cs;
    }
}

return_type: struct _CharStream { int cursor; int size; char *stream; } *

user_defined_types: struct _ID3v2_TextFrame { struct _ID3v2_FrameHeader *header; struct _ID3v2_TextFrameData *data; }

user_defined_types: struct _ID3v2_CommentFrame { struct _ID3v2_FrameHeader *header; struct _ID3v2_CommentFrameData *data; }

user_defined_types: struct _ID3v2_TextFrameData { int size; char encoding; char *text; }

user_defined_types: struct _ID3v2_CommentFrameData { int size; char encoding; char language[3]; char *short_description; char *comment; }


decompiled_code:
void __fastcall ID3v2_Frame_free(void **a1)
{
if ( a1 )
{
if ( (unsigned __int8)FrameHeader_isTextFrame(*a1) )
{
TextFrame_free(a1);
}
else if ( (unsigned __int8)FrameHeader_isCommentFrame(*a1) )
{
CommentFrame_free(a1);
}
else if ( (unsigned __int8)FrameHeader_isApicFrame(*a1) )
{
ApicFrame_free(a1);
}
else
{
free(*a1);
free(a1[1]);
}
}
}

canonical_decompiled_code:
void __fastcall func2(void **a1)
{
if ( a1 )
{
if ( (unsigned __int8)FrameHeader_isTextFrame(*a1) )
{
TextFrame_free(a1);
}
else if ( (unsigned __int8)FrameHeader_isCommentFrame(*a1) )
{
CommentFrame_free(a1);
}
else if ( (unsigned __int8)FrameHeader_isApicFrame(*a1) )
{
ApicFrame_free(a1);
}
else
{
free(*a1);
free(a1[1]);
}
}
}

original_code:
void ID3v2_Frame_free(ID3v2_Frame* frame)
{
    if (frame == ((void *)0)) return;
    if (FrameHeader_isTextFrame(frame->header))
    {
        TextFrame_free((ID3v2_TextFrame*) frame);
    }
    else if (FrameHeader_isCommentFrame(frame->header))
    {
        CommentFrame_free((ID3v2_CommentFrame*) frame);
    }
    else if (FrameHeader_isApicFrame(frame->header))
    {
        ApicFrame_free((ID3v2_ApicFrame*) frame);
    }
    else
    {
        free(frame->header);
        free(frame->data);
    }
}

canonical_original_code:
void ID3v2_Frame_free(struct _ID3v2_Frame *frame)
{
    if (frame == ((void *)0)) return;
    if (FrameHeader_isTextFrame(frame->header))
    {
        TextFrame_free((struct _ID3v2_TextFrame *) frame);
    }
    else if (FrameHeader_isCommentFrame(frame->header))
    {
        CommentFrame_free((struct _ID3v2_CommentFrame *) frame);
    }
    else if (FrameHeader_isApicFrame(frame->header))
    {
        ApicFrame_free((struct _ID3v2_ApicFrame *) frame);
    }
    else
    {
        free(frame->header);
        free(frame->data);
    }
}


decompiled_code:
_BYTE *TagHeader_new_empty()
{
return TagHeader_new(3, 0, 0, 0, 0);
}

canonical_decompiled_code:
_BYTE *func0()
{
return TagHeader_new(3, 0, 0, 0, 0);
}

original_code:
ID3v2_TagHeader* TagHeader_new_empty()
{
    return TagHeader_new(3, 0, 0, 0, 0);
}

canonical_original_code:
struct _ID3v2_TagHeader *TagHeader_new_empty()
{
    return TagHeader_new(3, 0, 0, 0, 0);
}

return_type: struct _ID3v2_TagHeader { char identifier[3]; char major_version; char minor_version; char flags; unsigned int tag_size; unsigned int extended_header_size; } *


decompiled_code:
// attributes: thunk
void ID3v2_TagHeader_free(void *ptr)
{
free(ptr);
}

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

original_code:
void ID3v2_TagHeader_free(ID3v2_TagHeader* header)
{
    free(header);
}

canonical_original_code:
void ID3v2_TagHeader_free(struct _ID3v2_TagHeader *header)
{
    free(header);
}

variable_types: struct _ID3v2_TagHeader { char identifier[3]; char major_version; char minor_version; char flags; unsigned int tag_size; unsigned int extended_header_size; } *


decompiled_code:
__int64 __fastcall CommentFrame_to_char_stream(_QWORD *a1)
{
__int64 v1; // rbp
__int64 v2; // r12
unsigned int v3; // eax

if ( !a1 )
return 0LL;
v1 = FrameHeader_to_char_stream(*a1);
v2 = CharStream_new((unsigned int)(*(_DWORD *)(*a1 + 4LL) + 10));
CharStream_write(v2, *(_QWORD *)(v1 + 8), *(unsigned int *)(v1 + 4));
CharStream_free(v1);
CharStream_write(v2, a1[1] + 4LL, 1LL);
CharStream_write(v2, a1[1] + 5LL, 3LL);
v3 = ID3v2_strlent(*(_QWORD *)(a1[1] + 8LL));
CharStream_write(v2, *(_QWORD *)(a1[1] + 8LL), v3);
CharStream_write(v2, *(_QWORD *)(a1[1] + 16LL), *(unsigned int *)a1[1]);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 v1; // rbp
__int64 v2; // r12
unsigned int v3; // eax

if ( !a1 )
return 0LL;
v1 = FrameHeader_to_char_stream(*a1);
v2 = CharStream_new((unsigned int)(*(_DWORD *)(*a1 + 4LL) + 10));
CharStream_write(v2, *(_QWORD *)(v1 + 8), *(unsigned int *)(v1 + 4));
CharStream_free(v1);
CharStream_write(v2, a1[1] + 4LL, 1LL);
CharStream_write(v2, a1[1] + 5LL, 3LL);
v3 = ID3v2_strlent(*(_QWORD *)(a1[1] + 8LL));
CharStream_write(v2, *(_QWORD *)(a1[1] + 8LL), v3);
CharStream_write(v2, *(_QWORD *)(a1[1] + 16LL), *(unsigned int *)a1[1]);
return v2;
}

original_code:
CharStream* CommentFrame_to_char_stream(ID3v2_CommentFrame* frame)
{
    if (frame == ((void *)0)) return ((void *)0);
    CharStream* frame_header_cs = FrameHeader_to_char_stream(frame->header);
    CharStream* frame_cs = CharStream_new(frame->header->size + 10);
    CharStream_write(frame_cs, frame_header_cs->stream, frame_header_cs->size);
    CharStream_free(frame_header_cs);
    CharStream_write(frame_cs, &frame->data->encoding, 1);
    CharStream_write(frame_cs, frame->data->language, 3);
    CharStream_write(
        frame_cs,
        frame->data->short_description,
        ID3v2_strlent(frame->data->short_description)
    );
    CharStream_write(frame_cs, frame->data->comment, frame->data->size);
    return frame_cs;
}

canonical_original_code:
struct _CharStream *CommentFrame_to_char_stream(struct _ID3v2_CommentFrame *frame)
{
    if (frame == ((void *)0)) return ((void *)0);
    struct _CharStream *frame_header_cs = FrameHeader_to_char_stream(frame->header);
    struct _CharStream *frame_cs = CharStream_new(frame->header->size + 10);
    CharStream_write(frame_cs, frame_header_cs->stream, frame_header_cs->size);
    CharStream_free(frame_header_cs);
    CharStream_write(frame_cs, &frame->data->encoding, 1);
    CharStream_write(frame_cs, frame->data->language, 3);
    CharStream_write(
        frame_cs,
        frame->data->short_description,
        ID3v2_strlent(frame->data->short_description)
    );
    CharStream_write(frame_cs, frame->data->comment, frame->data->size);
    return frame_cs;
}

variable_types: struct _ID3v2_CommentFrame { struct _ID3v2_FrameHeader { char id[4]; int size; char flags[2]; } *header; struct _ID3v2_CommentFrameData { int size; char encoding; char language[3]; char *short_description; char *comment; } *data; } *