decompiled_code:
void __fastcall CommentFrame_free(void *ptr)
{
FrameHeader_free(*(_QWORD *)ptr);
free(*(void **)(*((_QWORD *)ptr + 1) + 16LL));
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) + 16LL));
free(*(void **)(*((_QWORD *)ptr + 1) + 8LL));
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void CommentFrame_free(ID3v2_CommentFrame* frame)
{
    FrameHeader_free(frame->header);
    free(frame->data->comment);
    free(frame->data->short_description);
    free(frame->data);
    free(frame);
}

canonical_original_code:
void CommentFrame_free(struct _ID3v2_CommentFrame *frame)
{
    FrameHeader_free(frame->header);
    free(frame->data->comment);
    free(frame->data->short_description);
    free(frame->data);
    free(frame);
}


decompiled_code:
char *__fastcall CommentFrameData_new(__int64 a1, const void *a2, const void *a3)
{
char v4; // r15
int v5; // ebx
char *v6; // r12
void *v7; // rax
void *v8; // rax
int v10; // [rsp+Ch] [rbp-3Ch]

v4 = string_has_bom(a3);
v5 = ID3v2_strlent(a3);
v10 = ID3v2_strlent(a2);
v6 = (char *)malloc(0x18uLL);
v6[4] = v4;
*(_DWORD *)v6 = v5;
*(_WORD *)(v6 + 5) = *(_WORD *)a1;
v6[7] = *(_BYTE *)(a1 + 2);
v7 = malloc(v5);
*((_QWORD *)v6 + 2) = v7;
memcpy(v7, a3, v5);
v8 = malloc(v10);
*((_QWORD *)v6 + 1) = v8;
memcpy(v8, a2, v10);
return v6;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, const void *a2, const void *a3)
{
char v4; // r15
int v5; // ebx
char *v6; // r12
void *v7; // rax
void *v8; // rax
int v10; // [rsp+Ch] [rbp-3Ch]

v4 = string_has_bom(a3);
v5 = ID3v2_strlent(a3);
v10 = ID3v2_strlent(a2);
v6 = (char *)malloc(0x18uLL);
v6[4] = v4;
*(_DWORD *)v6 = v5;
*(_WORD *)(v6 + 5) = *(_WORD *)a1;
v6[7] = *(_BYTE *)(a1 + 2);
v7 = malloc(v5);
*((_QWORD *)v6 + 2) = v7;
memcpy(v7, a3, v5);
v8 = malloc(v10);
*((_QWORD *)v6 + 1) = v8;
memcpy(v8, a2, v10);
return v6;
}

original_code:
ID3v2_CommentFrameData* CommentFrameData_new(
    const char* lang,
    const char* short_desc,
    const char* comment
)
{
    const char encoding = string_has_bom(comment) ? 1 : 0;
    const int comment_size = ID3v2_strlent(comment);
    const int short_desc_size = ID3v2_strlent(short_desc);
    ID3v2_CommentFrameData* data = (ID3v2_CommentFrameData*) malloc(sizeof(ID3v2_CommentFrameData));
    data->encoding = encoding;
    data->size = comment_size;
    memcpy(data->language, lang, 3);
    data->comment = (char*) malloc(comment_size * sizeof(char));
    memcpy(data->comment, comment, comment_size);
    data->short_description = (char*) malloc(short_desc_size * sizeof(char));
    memcpy(data->short_description, short_desc, short_desc_size);
    return data;
}

canonical_original_code:
struct _ID3v2_CommentFrameData *CommentFrameData_new(char *lang, char *short_desc, char *comment)
{
    char encoding = string_has_bom(comment) ? 1 : 0;
    int comment_size = ID3v2_strlent(comment);
    int short_desc_size = ID3v2_strlent(short_desc);
    struct _ID3v2_CommentFrameData *data = (ID3v2_CommentFrameData*) malloc(sizeof(ID3v2_CommentFrameData));
    data->encoding = encoding;
    data->size = comment_size;
    memcpy(data->language, lang, 3);
    data->comment = (char *) malloc(comment_size * sizeof(char));
    memcpy(data->comment, comment, comment_size);
    data->short_description = (char *) malloc(short_desc_size * sizeof(char));
    memcpy(data->short_description, short_desc, short_desc_size);
    return data;
}

variable_types:
lang
char *

variable_types:
comment
char *

variable_types: encoding char

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


decompiled_code:
__int64 __fastcall TextFrame_to_char_stream(_QWORD *a1)
{
__int64 v1; // rbp
__int64 v2; // r12

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, *(_QWORD *)(a1[1] + 8LL), *(unsigned int *)a1[1]);
return v2;
}

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

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, *(_QWORD *)(a1[1] + 8LL), *(unsigned int *)a1[1]);
return v2;
}

original_code:
CharStream* TextFrame_to_char_stream(ID3v2_TextFrame* 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->text, frame->data->size);
    return frame_cs;
}

canonical_original_code:
struct _CharStream *TextFrame_to_char_stream(struct _ID3v2_TextFrame *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->text, frame->data->size);
    return frame_cs;
}

variable_types: struct _ID3v2_TextFrame { struct _ID3v2_FrameHeader { char id[4]; int size; char flags[2]; } *header; struct _ID3v2_TextFrameData { int size; char encoding; char *text; } *data; } *

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

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


decompiled_code:
void __fastcall TextFrame_free(void *ptr)
{
FrameHeader_free(*(_QWORD *)ptr);
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) + 8LL));
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void TextFrame_free(ID3v2_TextFrame* frame)
{
    FrameHeader_free(frame->header);
    free(frame->data->text);
    free(frame->data);
    free(frame);
}

canonical_original_code:
void TextFrame_free(struct _ID3v2_TextFrame *frame)
{
    FrameHeader_free(frame->header);
    free(frame->data->text);
    free(frame->data);
    free(frame);
}

return_type: void

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

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


decompiled_code:
__int64 __fastcall CharStream_get_cur(int *a1)
{
return *((_QWORD *)a1 + 1) + *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
return *((_QWORD *)a1 + 1) + *a1;
}

original_code:
char* CharStream_get_cur(CharStream* cs)
{
    return cs->stream + cs->cursor;
}

canonical_original_code:
char *CharStream_get_cur(struct _CharStream *cs)
{
    return cs->stream + cs->cursor;
}

return_type: char *

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


decompiled_code:
void *__fastcall CharStream_write(int *a1, const void *a2, int a3)
{
void *v4; // rax
size_t v5; // rdx
void *result; // rax

v4 = (void *)CharStream_get_cur(a1);
result = memcpy(v4, a2, v5);
*a1 += a3;
return result;
}

canonical_decompiled_code:
void *__fastcall func1(int *a1, const void *a2, int a3)
{
void *v4; // rax
size_t v5; // rdx
void *result; // rax

v4 = (void *)func0(a1);
result = memcpy(v4, a2, v5);
*a1 += a3;
return result;
}

original_code:
void CharStream_write(CharStream* cs, const char* data, const int size)
{
    memcpy(CharStream_get_cur(cs), data, size);
    cs->cursor += size;
}

canonical_original_code:
void CharStream_write(struct _CharStream *cs, char *data, int size)
{
    memcpy(CharStream_get_cur(cs), data, size);
    cs->cursor += size;
}

variable_types:
data
char *

variable_types: size int


decompiled_code:
__int64 __fastcall CharStream_read(int *a1, void *a2, unsigned int a3)
{
const void *v3; // rax
size_t v4; // rdx
unsigned int v5; // er12

clamp_int(a3, 0LL, (unsigned int)(a1[1] - *a1));
v3 = (const void *)CharStream_get_cur(a1);
v5 = v4;
memcpy(a2, v3, v4);
*a1 += v5;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, void *a2, unsigned int a3)
{
const void *v3; // rax
size_t v4; // rdx
unsigned int v5; // er12

clamp_int(a3, 0LL, (unsigned int)(a1[1] - *a1));
v3 = (const void *)func0(a1);
v5 = v4;
memcpy(a2, v3, v4);
*a1 += v5;
return v5;
}

original_code:
int CharStream_read(CharStream* cs, char* dest, const int size)
{
    const int final_size = clamp_int(size, 0, cs->size - cs->cursor);
    memcpy(dest, CharStream_get_cur(cs), final_size);
    cs->cursor += final_size;
    return final_size;
}

canonical_original_code:
int CharStream_read(struct _CharStream *cs, char *dest, int size)
{
    int final_size = clamp_int(size, 0, cs->size - cs->cursor);
    memcpy(dest, CharStream_get_cur(cs), final_size);
    cs->cursor += final_size;
    return final_size;
}

variable_types:
dest
char *

return_type: int


decompiled_code:
__int64 __fastcall CharStream_getc(int *a1)
{
int v1; // eax
unsigned int v2; // er8

v1 = *a1;
if ( *a1 >= a1[1] )
return (unsigned int)-1;
v2 = *(char *)(*((_QWORD *)a1 + 1) + v1);
*a1 = v1 + 1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1)
{
int v1; // eax
unsigned int v2; // er8

v1 = *a1;
if ( *a1 >= a1[1] )
return (unsigned int)-1;
v2 = *(char *)(*((_QWORD *)a1 + 1) + v1);
*a1 = v1 + 1;
return v2;
}

original_code:
int CharStream_getc(CharStream* cs)
{
    if (cs->cursor >= cs->size) return (-1);
    int c = cs->stream[cs->cursor];
    cs->cursor++;
    return c;
}

canonical_original_code:
int CharStream_getc(struct _CharStream *cs)
{
    if (cs->cursor >= cs->size) return (-1);
    int c = cs->stream[cs->cursor];
    cs->cursor++;
    return c;
}

variable_types: c int


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

result = CharStream_get_cur(a1);
*a1 += a2;
return result;
}

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

result = func0(a1);
*a1 += a2;
return result;
}

original_code:
char* CharStream_slice(CharStream* cs, const int n)
{
    char* result = CharStream_get_cur(cs);
    cs->cursor += n;
    return result;
}

canonical_original_code:
char *CharStream_slice(struct _CharStream *cs, int n)
{
    char *result = CharStream_get_cur(cs);
    cs->cursor += n;
    return result;
}

variable_types: n int

variable_types:
result
char *


decompiled_code:
void __fastcall CharStream_seek(_DWORD *a1, int a2, int a3)
{
if ( a3 )
{
if ( a3 == 1 )
*a1 = clamp_int((unsigned int)(a2 + *a1), 0LL, (unsigned int)a1[1]);
else
*a1 = clamp_int((unsigned int)(a1[1] + a2), 0LL, (unsigned int)a1[1]);
}
else
{
*a1 = a2;
}
}

canonical_decompiled_code:
void __fastcall func5(_DWORD *a1, int a2, int a3)
{
if ( a3 )
{
if ( a3 == 1 )
*a1 = clamp_int((unsigned int)(a2 + *a1), 0LL, (unsigned int)a1[1]);
else
*a1 = clamp_int((unsigned int)(a1[1] + a2), 0LL, (unsigned int)a1[1]);
}
else
{
*a1 = a2;
}
}

original_code:
void CharStream_seek(CharStream* cs, const int offset, const int whence)
{
    switch (whence)
    {
        case 0:
            cs->cursor = offset;
            break;
        case 1:
            cs->cursor = clamp_int(cs->cursor + offset, 0, cs->size);
            break;
        default:
            cs->cursor = clamp_int(cs->size + offset, 0, cs->size);
            break;
    }
}

canonical_original_code:
void CharStream_seek(struct _CharStream *cs, int offset, int whence)
{
    switch (whence)
    {
        case 0:
            cs->cursor = offset;
            break;
        case 1:
            cs->cursor = clamp_int(cs->cursor + offset, 0, cs->size);
            break;
        default:
            cs->cursor = clamp_int(cs->size + offset, 0, cs->size);
            break;
    }
}

variable_types: offset int

variable_types: whence int


decompiled_code:
void __fastcall CharStream_free(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void CharStream_free(CharStream* cs)
{
    free(cs->stream);
    free(cs);
}

canonical_original_code:
void CharStream_free(struct _CharStream *cs)
{
    free(cs->stream);
    free(cs);
}


decompiled_code:
int __fastcall assert_text_frame(_QWORD *a1, __int64 a2)
{
char v2; // r13
int v3; // ebp
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
int *v7; // rax
size_t v8; // rdx
int result; // eax

v2 = has_bom(*(_QWORD *)(a2 + 16));
v3 = ID3v2_strlen(*(_QWORD *)(a2 + 16)) + 1 - ((v2 == 0) - 1);
assert_frame_header(a1, a2, *(_QWORD *)(a2 + 8), v4, v5, v6, *(_DWORD **)a2, v3 + 1, *(_WORD **)(a2 + 8));
v7 = (int *)a1[1];
v8 = *v7;
if ( (_DWORD)v8 != v3 )
_assert_fail(
"frame->data->size == (frame_size - ID3v2_FRAME_ENCODING_LENGTH)",
"test/assertion_utils.c",
0x2Du,
"assert_text_frame");
if ( *((_BYTE *)v7 + 4) != v2 )
_assert_fail("frame->data->encoding == encoding", "test/assertion_utils.c", 0x2Eu, "assert_text_frame");
result = memcmp(*((const void **)v7 + 1), *(const void **)(a2 + 16), v8);
if ( result )
_assert_fail(
"memcmp(frame->data->text, comparison->text, frame->data->size) == 0",
"test/assertion_utils.c",
0x2Fu,
"assert_text_frame");
return result;
}

canonical_decompiled_code:
int __fastcall func0(_QWORD *a1, __int64 a2)
{
char v2; // r13
int v3; // ebp
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
int *v7; // rax
size_t v8; // rdx
int result; // eax

v2 = has_bom(*(_QWORD *)(a2 + 16));
v3 = ID3v2_strlen(*(_QWORD *)(a2 + 16)) + 1 - ((v2 == 0) - 1);
assert_frame_header(a1, a2, *(_QWORD *)(a2 + 8), v4, v5, v6, *(_DWORD **)a2, v3 + 1, *(_WORD **)(a2 + 8));
v7 = (int *)a1[1];
v8 = *v7;
if ( (_DWORD)v8 != v3 )
_assert_fail(
"frame->data->size == (frame_size - ID3v2_FRAME_ENCODING_LENGTH)",
"test/assertion_utils.c",
0x2Du,
"assert_text_frame");
if ( *((_BYTE *)v7 + 4) != v2 )
_assert_fail("frame->data->encoding == encoding", "test/assertion_utils.c", 0x2Eu, "assert_text_frame");
result = memcmp(*((const void **)v7 + 1), *(const void **)(a2 + 16), v8);
if ( result )
_assert_fail(
"memcmp(frame->data->text, comparison->text, frame->data->size) == 0",
"test/assertion_utils.c",
0x2Fu,
"assert_text_frame");
return result;
}

original_code:
void assert_text_frame(ID3v2_TextFrame* frame, ID3v2_TextFrameInput* comparison)
{
    const char encoding = has_bom(comparison->text) ? 1 : 0;
    const int str_termination_length = encoding == 0 ? 1 : 2;
    const int text_size = ID3v2_strlen(comparison->text) + str_termination_length;
    const int frame_size = text_size + 1;
    assert_frame_header(
        (ID3v2_Frame*) frame,
        (Frame_header_assertion){
            .id = comparison->id,
            .size = frame_size,
            .flags = comparison->flags,
        }
    );
    ((frame->data->size == (frame_size - 1)) ? (void) (0) : __assert_fail ("frame->data->size == (frame_size - ID3v2_FRAME_ENCODING_LENGTH)", "test/assertion_utils.c", 45, __extension__ __PRETTY_FUNCTION__));
    ((frame->data->encoding == encoding) ? (void) (0) : __assert_fail ("frame->data->encoding == encoding", "test/assertion_utils.c", 46, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(frame->data->text, comparison->text, frame->data->size) == 0) ? (void) (0) : __assert_fail ("memcmp(frame->data->text, comparison->text, frame->data->size) == 0", "test/assertion_utils.c", 47, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void assert_text_frame(struct _ID3v2_TextFrame *frame, struct _ID3v2_TextFrameInput *comparison)
{
    char encoding = has_bom(comparison->text) ? 1 : 0;
    int str_termination_length = encoding == 0 ? 1 : 2;
    int text_size = ID3v2_strlen(comparison->text) + str_termination_length;
    int frame_size = text_size + 1;
    assert_frame_header(
        (struct _ID3v2_Frame *) frame,
        (struct _Frame_header_assertion){
            .id = comparison->id,
            .size = frame_size,
            .flags = comparison->flags,
        }
    );
    ((frame->data->size == (frame_size - 1)) ? (void) (0) : __assert_fail ("frame->data->size == (frame_size - ID3v2_FRAME_ENCODING_LENGTH)", "test/assertion_utils.c", 45, __extension__ __PRETTY_FUNCTION__));
    ((frame->data->encoding == encoding) ? (void) (0) : __assert_fail ("frame->data->encoding == encoding", "test/assertion_utils.c", 46, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(frame->data->text, comparison->text, frame->data->size) == 0) ? (void) (0) : __assert_fail ("memcmp(frame->data->text, comparison->text, frame->data->size) == 0", "test/assertion_utils.c", 47, __extension__ __PRETTY_FUNCTION__));
}

variable_types: struct _ID3v2_TextFrameInput { char *id; char *flags; char *text; } *

user_defined_types: struct _Frame_header_assertion { char *id; int size; char *flags; }

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


decompiled_code:
int __fastcall assert_comment_frame(_QWORD *a1, __int64 a2)
{
char v2; // r13
int v3; // er14
int v4; // er12
int v5; // er14
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
int *v10; // rbp
int v11; // er15
__int64 v12; // rax
int result; // eax

v2 = has_bom(*(_QWORD *)(a2 + 24));
v3 = 1 - (((unsigned __int8)has_bom(*(_QWORD *)(a2 + 16)) == 0) - 1);
v4 = ID3v2_strlen(*(_QWORD *)(a2 + 24)) + 1 - ((v2 == 0) - 1);
v5 = ID3v2_strlen(*(_QWORD *)(a2 + 16)) + v3;
assert_frame_header(a1, a2, v6, v7, v8, v9, "COMM", v4 + v5 + 4, *(_WORD **)a2);
v10 = (int *)a1[1];
v11 = *v10;
if ( *v10 != v4 )
_assert_fail("frame->data->size == comment_size", "test/assertion_utils.c", 0x4Au, "assert_comment_frame");
if ( *((_BYTE *)v10 + 4) != v2 )
_assert_fail("frame->data->encoding == comment_encoding", "test/assertion_utils.c", 0x4Bu, "assert_comment_frame");
v12 = *(_QWORD *)(a2 + 8);
if ( *(_WORD *)((char *)v10 + 5) != *(_WORD *)v12 || *((_BYTE *)v10 + 7) != *(_BYTE *)(v12 + 2) )
_assert_fail(
"memcmp(frame->data->language, comparison->language, ID3v2_COMMENT_FRAME_LANGUAGE_LENGTH) == 0",
"test/assertion_utils.c",
0x4Cu,
"assert_comment_frame");
if ( memcmp(*((const void **)v10 + 1), *(const void **)(a2 + 16), v5) )
_assert_fail(
"memcmp( frame->data->short_description, comparison->short_description, short_description_size ) == 0",
"test/assertion_utils.c",
0x50u,
"assert_comment_frame");
result = memcmp(*((const void **)v10 + 2), *(const void **)(a2 + 24), v11);
if ( result )
_assert_fail(
"memcmp(frame->data->comment, comparison->comment, frame->data->size) == 0",
"test/assertion_utils.c",
0x57u,
"assert_comment_frame");
return result;
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1, __int64 a2)
{
char v2; // r13
int v3; // er14
int v4; // er12
int v5; // er14
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
int *v10; // rbp
int v11; // er15
__int64 v12; // rax
int result; // eax

v2 = has_bom(*(_QWORD *)(a2 + 24));
v3 = 1 - (((unsigned __int8)has_bom(*(_QWORD *)(a2 + 16)) == 0) - 1);
v4 = ID3v2_strlen(*(_QWORD *)(a2 + 24)) + 1 - ((v2 == 0) - 1);
v5 = ID3v2_strlen(*(_QWORD *)(a2 + 16)) + v3;
assert_frame_header(a1, a2, v6, v7, v8, v9, "COMM", v4 + v5 + 4, *(_WORD **)a2);
v10 = (int *)a1[1];
v11 = *v10;
if ( *v10 != v4 )
_assert_fail("frame->data->size == comment_size", "test/assertion_utils.c", 0x4Au, "assert_comment_frame");
if ( *((_BYTE *)v10 + 4) != v2 )
_assert_fail("frame->data->encoding == comment_encoding", "test/assertion_utils.c", 0x4Bu, "assert_comment_frame");
v12 = *(_QWORD *)(a2 + 8);
if ( *(_WORD *)((char *)v10 + 5) != *(_WORD *)v12 || *((_BYTE *)v10 + 7) != *(_BYTE *)(v12 + 2) )
_assert_fail(
"memcmp(frame->data->language, comparison->language, ID3v2_COMMENT_FRAME_LANGUAGE_LENGTH) == 0",
"test/assertion_utils.c",
0x4Cu,
"assert_comment_frame");
if ( memcmp(*((const void **)v10 + 1), *(const void **)(a2 + 16), v5) )
_assert_fail(
"memcmp( frame->data->short_description, comparison->short_description, short_description_size ) == 0",
"test/assertion_utils.c",
0x50u,
"assert_comment_frame");
result = memcmp(*((const void **)v10 + 2), *(const void **)(a2 + 24), v11);
if ( result )
_assert_fail(
"memcmp(frame->data->comment, comparison->comment, frame->data->size) == 0",
"test/assertion_utils.c",
0x57u,
"assert_comment_frame");
return result;
}

original_code:
void assert_comment_frame(ID3v2_CommentFrame* frame, ID3v2_CommentFrameInput* comparison)
{
    const char comment_encoding =
        has_bom(comparison->comment) ? 1 : 0;
    const int short_desc_str_termination_length = has_bom(comparison->short_description) ? 2 : 1;
    const int str_termination_length = comment_encoding == 0 ? 1 : 2;
    const int comment_size = ID3v2_strlen(comparison->comment) + str_termination_length;
    const int short_description_size =
        ID3v2_strlen(comparison->short_description) + short_desc_str_termination_length;
    const int frame_size = comment_size + short_description_size + 1 +
                           3;
    assert_frame_header(
        (ID3v2_Frame*) frame,
        (Frame_header_assertion){
            .id = "COMM",
            .size = frame_size,
            .flags = comparison->flags,
        }
    );
    ((frame->data->size == comment_size) ? (void) (0) : __assert_fail ("frame->data->size == comment_size", "test/assertion_utils.c", 74, __extension__ __PRETTY_FUNCTION__));
    ((frame->data->encoding == comment_encoding) ? (void) (0) : __assert_fail ("frame->data->encoding == comment_encoding", "test/assertion_utils.c", 75, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(frame->data->language, comparison->language, 3) == 0) ? (void) (0) : __assert_fail ("memcmp(frame->data->language, comparison->language, ID3v2_COMMENT_FRAME_LANGUAGE_LENGTH) == 0", "test/assertion_utils.c", 76, __extension__ __PRETTY_FUNCTION__));
    ((memcmp( frame->data->short_description, comparison->short_description, short_description_size ) == 0) ? (void) (0) : __assert_fail ("memcmp( frame->data->short_description, comparison->short_description, short_description_size ) == 0", "test/assertion_utils.c", 80, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(frame->data->comment, comparison->comment, frame->data->size) == 0) ? (void) (0) : __assert_fail ("memcmp(frame->data->comment, comparison->comment, frame->data->size) == 0", "test/assertion_utils.c", 87, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void assert_comment_frame(struct _ID3v2_CommentFrame *frame, struct _ID3v2_CommentFrameInput *comparison)
{
    char comment_encoding = has_bom(comparison->comment) ? 1 : 0;
    int short_desc_str_termination_length = has_bom(comparison->short_description) ? 2 : 1;
    int str_termination_length = comment_encoding == 0 ? 1 : 2;
    int comment_size = ID3v2_strlen(comparison->comment) + str_termination_length;
    int short_description_size = ID3v2_strlen(comparison->short_description) + short_desc_str_termination_length;
    int frame_size = comment_size + short_description_size + 1 +
                           3;
    assert_frame_header(
        (struct _ID3v2_Frame *) frame,
        (struct _Frame_header_assertion){
            .id = "COMM",
            .size = frame_size,
            .flags = comparison->flags,
        }
    );
    ((frame->data->size == comment_size) ? (void) (0) : __assert_fail ("frame->data->size == comment_size", "test/assertion_utils.c", 74, __extension__ __PRETTY_FUNCTION__));
    ((frame->data->encoding == comment_encoding) ? (void) (0) : __assert_fail ("frame->data->encoding == comment_encoding", "test/assertion_utils.c", 75, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(frame->data->language, comparison->language, 3) == 0) ? (void) (0) : __assert_fail ("memcmp(frame->data->language, comparison->language, ID3v2_COMMENT_FRAME_LANGUAGE_LENGTH) == 0", "test/assertion_utils.c", 76, __extension__ __PRETTY_FUNCTION__));
    ((memcmp( frame->data->short_description, comparison->short_description, short_description_size ) == 0) ? (void) (0) : __assert_fail ("memcmp( frame->data->short_description, comparison->short_description, short_description_size ) == 0", "test/assertion_utils.c", 80, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(frame->data->comment, comparison->comment, frame->data->size) == 0) ? (void) (0) : __assert_fail ("memcmp(frame->data->comment, comparison->comment, frame->data->size) == 0", "test/assertion_utils.c", 87, __extension__ __PRETTY_FUNCTION__));
}

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

variable_types: struct _ID3v2_CommentFrameInput { char *flags; char *language; char *short_description; char *comment; } *

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


decompiled_code:
int __fastcall assert_apic_frame(_QWORD *a1, __int64 a2)
{
char v2; // al
char v3; // r15
int v4; // er12
int v5; // eax
int v6; // er13
int v7; // ebp
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // r8
__int64 v11; // r9
__int64 v12; // r14
int result; // eax

v2 = has_bom(*(_QWORD *)(a2 + 16));
if ( !*(_QWORD *)(a2 + 16) )
_assert_fail("comparison->description != NULL", "test/assertion_utils.c", 0x5Fu, "assert_apic_frame");
v3 = v2;
v4 = ID3v2_strlent();
if ( !*(_QWORD *)(a2 + 8) )
_assert_fail("comparison->mime_type != NULL", "test/assertion_utils.c", 0x62u, "assert_apic_frame");
v5 = ID3v2_strlent();
v6 = *(_DWORD *)(a2 + 28);
v7 = v5;
assert_frame_header(a1, a2, v8, v9, v10, v11, "APIC", v6 + v4 + v5 + 2, *(_WORD **)a2);
v12 = a1[1];
if ( *(_BYTE *)v12 != v3 )
_assert_fail("frame->data->encoding == encoding", "test/assertion_utils.c", 0x74u, "assert_apic_frame");
if ( v6 != *(_DWORD *)(v12 + 40) )
_assert_fail(
"frame->data->picture_size == comparison->picture_size",
"test/assertion_utils.c",
0x75u,
"assert_apic_frame");
if ( memcmp(*(const void **)(v12 + 32), *(const void **)(a2 + 32), v6) )
_assert_fail(
"memcmp(frame->data->data, comparison->data, comparison->picture_size) == 0",
"test/assertion_utils.c",
0x76u,
"assert_apic_frame");
if ( memcmp(*(const void **)(v12 + 8), *(const void **)(a2 + 8), v7) )
_assert_fail(
"memcmp(frame->data->mime_type, comparison->mime_type, mime_type_size) == 0",
"test/assertion_utils.c",
0x77u,
"assert_apic_frame");
result = memcmp(*(const void **)(v12 + 24), *(const void **)(a2 + 16), v4);
if ( result )
_assert_fail(
"memcmp(frame->data->description, comparison->description, description_size) == 0",
"test/assertion_utils.c",
0x78u,
"assert_apic_frame");
return result;
}

canonical_decompiled_code:
int __fastcall func2(_QWORD *a1, __int64 a2)
{
char v2; // al
char v3; // r15
int v4; // er12
int v5; // eax
int v6; // er13
int v7; // ebp
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // r8
__int64 v11; // r9
__int64 v12; // r14
int result; // eax

v2 = has_bom(*(_QWORD *)(a2 + 16));
if ( !*(_QWORD *)(a2 + 16) )
_assert_fail("comparison->description != NULL", "test/assertion_utils.c", 0x5Fu, "assert_apic_frame");
v3 = v2;
v4 = ID3v2_strlent();
if ( !*(_QWORD *)(a2 + 8) )
_assert_fail("comparison->mime_type != NULL", "test/assertion_utils.c", 0x62u, "assert_apic_frame");
v5 = ID3v2_strlent();
v6 = *(_DWORD *)(a2 + 28);
v7 = v5;
assert_frame_header(a1, a2, v8, v9, v10, v11, "APIC", v6 + v4 + v5 + 2, *(_WORD **)a2);
v12 = a1[1];
if ( *(_BYTE *)v12 != v3 )
_assert_fail("frame->data->encoding == encoding", "test/assertion_utils.c", 0x74u, "assert_apic_frame");
if ( v6 != *(_DWORD *)(v12 + 40) )
_assert_fail(
"frame->data->picture_size == comparison->picture_size",
"test/assertion_utils.c",
0x75u,
"assert_apic_frame");
if ( memcmp(*(const void **)(v12 + 32), *(const void **)(a2 + 32), v6) )
_assert_fail(
"memcmp(frame->data->data, comparison->data, comparison->picture_size) == 0",
"test/assertion_utils.c",
0x76u,
"assert_apic_frame");
if ( memcmp(*(const void **)(v12 + 8), *(const void **)(a2 + 8), v7) )
_assert_fail(
"memcmp(frame->data->mime_type, comparison->mime_type, mime_type_size) == 0",
"test/assertion_utils.c",
0x77u,
"assert_apic_frame");
result = memcmp(*(const void **)(v12 + 24), *(const void **)(a2 + 16), v4);
if ( result )
_assert_fail(
"memcmp(frame->data->description, comparison->description, description_size) == 0",
"test/assertion_utils.c",
0x78u,
"assert_apic_frame");
return result;
}

original_code:
void assert_apic_frame(ID3v2_ApicFrame* frame, ID3v2_ApicFrameInput* comparison)
{
    const char encoding =
        has_bom(comparison->description) ? 1 : 0;
    ((comparison->description != ((void *)0)) ? (void) (0) : __assert_fail ("comparison->description != NULL", "test/assertion_utils.c", 95, __extension__ __PRETTY_FUNCTION__));
    const int description_size = ID3v2_strlent(comparison->description);
    ((comparison->mime_type != ((void *)0)) ? (void) (0) : __assert_fail ("comparison->mime_type != NULL", "test/assertion_utils.c", 98, __extension__ __PRETTY_FUNCTION__));
    const int mime_type_size = ID3v2_strlent(comparison->mime_type);
    const int frame_size = 1 + mime_type_size +
                           1 + description_size +
                           comparison->picture_size;
    assert_frame_header(
        (ID3v2_Frame*) frame,
        (Frame_header_assertion){
            .id = "APIC",
            .size = frame_size,
            .flags = comparison->flags,
        }
    );
    ((frame->data->encoding == encoding) ? (void) (0) : __assert_fail ("frame->data->encoding == encoding", "test/assertion_utils.c", 116, __extension__ __PRETTY_FUNCTION__));
    ((frame->data->picture_size == comparison->picture_size) ? (void) (0) : __assert_fail ("frame->data->picture_size == comparison->picture_size", "test/assertion_utils.c", 117, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(frame->data->data, comparison->data, comparison->picture_size) == 0) ? (void) (0) : __assert_fail ("memcmp(frame->data->data, comparison->data, comparison->picture_size) == 0", "test/assertion_utils.c", 118, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(frame->data->mime_type, comparison->mime_type, mime_type_size) == 0) ? (void) (0) : __assert_fail ("memcmp(frame->data->mime_type, comparison->mime_type, mime_type_size) == 0", "test/assertion_utils.c", 119, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(frame->data->description, comparison->description, description_size) == 0) ? (void) (0) : __assert_fail ("memcmp(frame->data->description, comparison->description, description_size) == 0", "test/assertion_utils.c", 120, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void assert_apic_frame(struct _ID3v2_ApicFrame *frame, struct _ID3v2_ApicFrameInput *comparison)
{
    char encoding = has_bom(comparison->description) ? 1 : 0;
    ((comparison->description != ((void *)0)) ? (void) (0) : __assert_fail ("comparison->description != NULL", "test/assertion_utils.c", 95, __extension__ __PRETTY_FUNCTION__));
    int description_size = ID3v2_strlent(comparison->description);
    ((comparison->mime_type != ((void *)0)) ? (void) (0) : __assert_fail ("comparison->mime_type != NULL", "test/assertion_utils.c", 98, __extension__ __PRETTY_FUNCTION__));
    int mime_type_size = ID3v2_strlent(comparison->mime_type);
    int frame_size = 1 + mime_type_size +
                           1 + description_size +
                           comparison->picture_size;
    assert_frame_header(
        (struct _ID3v2_Frame *) frame,
        (struct _Frame_header_assertion){
            .id = "APIC",
            .size = frame_size,
            .flags = comparison->flags,
        }
    );
    ((frame->data->encoding == encoding) ? (void) (0) : __assert_fail ("frame->data->encoding == encoding", "test/assertion_utils.c", 116, __extension__ __PRETTY_FUNCTION__));
    ((frame->data->picture_size == comparison->picture_size) ? (void) (0) : __assert_fail ("frame->data->picture_size == comparison->picture_size", "test/assertion_utils.c", 117, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(frame->data->data, comparison->data, comparison->picture_size) == 0) ? (void) (0) : __assert_fail ("memcmp(frame->data->data, comparison->data, comparison->picture_size) == 0", "test/assertion_utils.c", 118, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(frame->data->mime_type, comparison->mime_type, mime_type_size) == 0) ? (void) (0) : __assert_fail ("memcmp(frame->data->mime_type, comparison->mime_type, mime_type_size) == 0", "test/assertion_utils.c", 119, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(frame->data->description, comparison->description, description_size) == 0) ? (void) (0) : __assert_fail ("memcmp(frame->data->description, comparison->description, description_size) == 0", "test/assertion_utils.c", 120, __extension__ __PRETTY_FUNCTION__));
}

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 _ID3v2_ApicFrameInput { char *flags; char *mime_type; char *description; char picture_type; int picture_size; char *data; } *

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


decompiled_code:
__int64 __fastcall ID3v2_read_tag_header_from_buffer(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // r12

v1 = CharStream_from_buffer(a1, 10LL);
v2 = TagHeader_parse(v1);
CharStream_free(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // r12

v1 = CharStream_from_buffer(a1, 10LL);
v2 = TagHeader_parse(v1);
CharStream_free(v1);
return v2;
}

original_code:
ID3v2_TagHeader* ID3v2_read_tag_header_from_buffer(const char* buffer)
{
    CharStream* cs = CharStream_from_buffer(buffer, 10);
    ID3v2_TagHeader* header = TagHeader_parse(cs);
    CharStream_free(cs);
    return header;
}

canonical_original_code:
struct _ID3v2_TagHeader *ID3v2_read_tag_header_from_buffer(char *buffer)
{
    struct _CharStream *cs = CharStream_from_buffer(buffer, 10);
    struct _ID3v2_TagHeader *header = TagHeader_parse(cs);
    CharStream_free(cs);
    return header;
}

variable_types:
buffer
char *

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 ID3v2_read_tag_from_buffer(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // r12

v2 = CharStream_from_buffer(a1, a2);
v3 = Tag_parse(v2);
CharStream_free(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // r12

v2 = CharStream_from_buffer(a1, a2);
v3 = Tag_parse(v2);
CharStream_free(v2);
return v3;
}

original_code:
ID3v2_Tag* ID3v2_read_tag_from_buffer(const char* tag_buffer, const int buffer_length)
{
    CharStream* tag_cs = CharStream_from_buffer(tag_buffer, buffer_length);
    ID3v2_Tag* tag = Tag_parse(tag_cs);
    CharStream_free(tag_cs);
    return tag;
}

canonical_original_code:
struct _ID3v2_Tag *ID3v2_read_tag_from_buffer(char *tag_buffer, int buffer_length)
{
    struct _CharStream *tag_cs = CharStream_from_buffer(tag_buffer, buffer_length);
    struct _ID3v2_Tag *tag = Tag_parse(tag_cs);
    CharStream_free(tag_cs);
    return tag;
}

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


decompiled_code:
bool __fastcall has_bom(_WORD *a1)
{
bool result; // al

if ( !a1 )
return 0;
result = 1;
if ( *a1 != 0xFEFF )
result = *a1 == 0xFFFE;
return result;
}

canonical_decompiled_code:
bool __fastcall func0(_WORD *a1)
{
bool result; // al

if ( !a1 )
return 0;
result = 1;
if ( *a1 != 0xFEFF )
result = *a1 == 0xFFFE;
return result;
}

original_code:
_Bool has_bom(const char* string)
{
    if (string == ((void *)0)) return 0;
    return memcmp("\xFF\xFE", string, 2) == 0 || memcmp("\xFE\xFF", string, 2) == 0;
}

canonical_original_code:
_Bool has_bom(char *string)
{
    if (string == ((void *)0)) return 0;
    return memcmp("\xFF\xFE", string, 2) == 0 || memcmp("\xFE\xFF", string, 2) == 0;
}

variable_types:
string
char *


decompiled_code:
void *__fastcall char_to_utf16(void *src, int a2)
{
void *v2; // rax

if ( a2 < 0 )
a2 = ID3v2_strlent();
v2 = malloc(2LL * a2);
return memcpy(v2, src, a2);
}

canonical_decompiled_code:
void *__fastcall func1(void *src, int a2)
{
void *v2; // rax

if ( a2 < 0 )
a2 = ID3v2_strlent();
v2 = malloc(2LL * a2);
return memcpy(v2, src, a2);
}

original_code:
uint16_t* char_to_utf16(const char* string, int size)
{
    size = size < 0 ? ID3v2_strlent(string) : size;
    uint16_t* result = (uint16_t*) malloc(size * sizeof(uint16_t));
    memcpy(result, string, size);
    return result;
}

canonical_original_code:
unsigned short *char_to_utf16(char *string, int size)
{
    size = size < 0 ? ID3v2_strlent(string) : size;
    unsigned short *result = (uint16_t*) malloc(size * sizeof(uint16_t));
    memcpy(result, string, size);
    return result;
}

variable_types:
result
unsigned short *

return_type: unsigned short *


decompiled_code:
int __fastcall println_utf16(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
unsigned __int16 *v3; // rbx
int v4; // esi

if ( a2 > 1 )
{
v2 = a1 + 2LL * (a2 - 2) + 4;
v3 = (unsigned __int16 *)(a1 + 2);
do
{
v4 = *v3;
if ( !(_WORD)v4 )
break;
++v3;
printf("%lc", v4);
}
while ( v3 != (unsigned __int16 *)v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
unsigned __int16 *v3; // rbx
int v4; // esi

if ( a2 > 1 )
{
v2 = a1 + 2LL * (a2 - 2) + 4;
v3 = (unsigned __int16 *)(a1 + 2);
do
{
v4 = *v3;
if ( !(_WORD)v4 )
break;
++v3;
printf("%lc", v4);
}
while ( v3 != (unsigned __int16 *)v2 );
}
return putchar(10);
}

original_code:
void println_utf16(uint16_t* string, int size)
{
    int i = 1;
    while (i < size || size < 0)
    {
        if (string[i] == 0x0000)
        {
            break;
        }
        printf("%lc", string[i]);
        i++;
    }
    printf("\n");
}

canonical_original_code:
void println_utf16(unsigned short *string, int size)
{
    int i = 1;
    while (i < size || size < 0)
    {
        if (string[i] == 0x0000)
        {
            break;
        }
        printf("%lc", string[i]);
        i++;
    }
    printf("\n");
}

variable_types:
string
unsigned short *

variable_types: size int

variable_types: i int


decompiled_code:
int __fastcall print_text_frame_text(char *a1, unsigned int a2)
{
void *v2; // rax

if ( !a1 )
return puts("None");
if ( !has_bom(a1) )
return puts(a1);
v2 = char_to_utf16(a1, a2);
return println_utf16((__int64)v2, a2);
}

canonical_decompiled_code:
int __fastcall func4(char *a1, unsigned int a2)
{
void *v2; // rax

if ( !a1 )
return puts("None");
if ( !func0(a1) )
return puts(a1);
v2 = func1(a1, a2);
return func3((__int64)v2, a2);
}

original_code:
void print_text_frame_text(const char* text, const int size)
{
    if (text == ((void *)0))
    {
        printf("None\n");
    }
    else if (has_bom(text))
    {
        uint16_t* text_utf = char_to_utf16(text, size);
        println_utf16(text_utf, size);
    }
    else
    {
        printf("%s\n", text);
    }
}

canonical_original_code:
void print_text_frame_text(char *text, int size)
{
    if (text == ((void *)0))
    {
        printf("None\n");
    }
    else if (has_bom(text))
    {
        unsigned short *text_utf = char_to_utf16(text, size);
        println_utf16(text_utf, size);
    }
    else
    {
        printf("%s\n", text);
    }
}

variable_types:
text
char *


decompiled_code:
int __fastcall print_text_frame(__int64 a1)
{
int result; // eax

if ( a1 )
result = print_text_frame_text(*(char **)(*(_QWORD *)(a1 + 8) + 8LL), **(_DWORD **)(a1 + 8));
else
result = puts("None");
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
int result; // eax

if ( a1 )
result = func4(*(char **)(*(_QWORD *)(a1 + 8) + 8LL), **(_DWORD **)(a1 + 8));
else
result = puts("None");
return result;
}

original_code:
void print_text_frame(ID3v2_TextFrame* frame)
{
    if (frame == ((void *)0))
    {
        printf("None\n");
        return;
    }
    print_text_frame_text(frame->data->text, frame->data->size);
}

canonical_original_code:
void print_text_frame(struct _ID3v2_TextFrame *frame)
{
    if (frame == ((void *)0))
    {
        printf("None\n");
        return;
    }
    print_text_frame_text(frame->data->text, frame->data->size);
}

variable_types: struct _ID3v2_TextFrame { struct _ID3v2_FrameHeader { char id[4]; int size; char flags[2]; } *header; struct _ID3v2_TextFrameData { int size; char encoding; char *text; } *data; } *


decompiled_code:
int __fastcall print_comment_frame(__int64 a1)
{
int result; // eax

if ( a1 )
result = print_text_frame_text(*(char **)(*(_QWORD *)(a1 + 8) + 16LL), **(_DWORD **)(a1 + 8));
else
result = puts("None");
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
int result; // eax

if ( a1 )
result = func4(*(char **)(*(_QWORD *)(a1 + 8) + 16LL), **(_DWORD **)(a1 + 8));
else
result = puts("None");
return result;
}

original_code:
void print_comment_frame(ID3v2_CommentFrame* frame)
{
    if (frame == ((void *)0))
    {
        printf("None\n");
        return;
    }
    print_text_frame_text(frame->data->comment, frame->data->size);
}

canonical_original_code:
void print_comment_frame(struct _ID3v2_CommentFrame *frame)
{
    if (frame == ((void *)0))
    {
        printf("None\n");
        return;
    }
    print_text_frame_text(frame->data->comment, frame->data->size);
}

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


decompiled_code:
int __fastcall print_comment_frames(__int64 *a1)
{
__int64 *v1; // rbx
int result; // eax

if ( !a1 )
return puts("None");
v1 = a1;
do
{
result = print_comment_frame(*v1);
v1 = (__int64 *)v1[2];
}
while ( v1 );
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 *a1)
{
__int64 *v1; // rbx
int result; // eax

if ( !a1 )
return puts("None");
v1 = a1;
do
{
result = func6(*v1);
v1 = (__int64 *)v1[2];
}
while ( v1 );
return result;
}

original_code:
void print_comment_frames(ID3v2_FrameList* frames)
{
    if (frames == ((void *)0))
    {
        printf("None\n");
        return;
    }
    while (frames != ((void *)0))
    {
        ID3v2_CommentFrame* comment = (ID3v2_CommentFrame*) frames->frame;
        print_comment_frame(comment);
        frames = frames->next;
    }
}

canonical_original_code:
void print_comment_frames(struct _ID3v2_FrameList *frames)
{
    if (frames == ((void *)0))
    {
        printf("None\n");
        return;
    }
    while (frames != ((void *)0))
    {
        struct _ID3v2_CommentFrame *comment = (ID3v2_CommentFrame*) frames->frame;
        print_comment_frame(comment);
        frames = frames->next;
    }
}

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


btoi

decompiled_code:
__int64 __fastcall btoi(unsigned __int8 *a1, int a2)
{
__int64 v2; // rcx
__int64 result; // rax
unsigned int v4; // edx

if ( a2 <= 0 )
return 0LL;
v2 = (__int64)&a1[a2 - 1 + 1];
LODWORD(result) = 0;
do
{
v4 = *a1++;
result = v4 | ((_DWORD)result << 8);
}
while ( a1 != (unsigned __int8 *)v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, int a2)
{
__int64 v2; // rcx
__int64 result; // rax
unsigned int v4; // edx

if ( a2 <= 0 )
return 0LL;
v2 = (__int64)&a1[a2 - 1 + 1];
LODWORD(result) = 0;
do
{
v4 = *a1++;
result = v4 | ((_DWORD)result << 8);
}
while ( a1 != (unsigned __int8 *)v2 );
return result;
}

original_code:
unsigned int btoi(const char* bytes, int size)
{
    unsigned int result = 0x00;
    for (int i = 0; i < size; i++)
    {
        result = result << 8;
        result = result | (unsigned char) bytes[i];
    }
    return result;
}

canonical_original_code:
unsigned int btoi(char *bytes, int size)
{
    unsigned int result = 0x00;
    for (int i = 0; i < size; i++)
    {
        result = result << 8;
        result = result | (unsigned char) bytes[i];
    }
    return result;
}

variable_types:
bytes
char *

variable_types:
result
unsigned int

return_type: unsigned int


decompiled_code:
// attributes: thunk
void __noreturn syncint_encode()
{
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func2()
{
while ( 1 )
;
}

original_code:
int syncint_encode(int value)
{
    int out, mask = 0x7F;
    while (mask ^ 0x7FFFFFFF)
    {
        out = value & ~mask;
        out <<= 1;
        out |= value & mask;
        mask = ((mask + 1) << 8) - 1;
        value = out;
    }
    return out;
}

canonical_original_code:
int syncint_encode(int value)
{
    int out; int mask = 0x7F;
    while (mask ^ 0x7FFFFFFF)
    {
        out = value & ~mask;
        out <<= 1;
        out |= value & mask;
        mask = ((mask + 1) << 8) - 1;
        value = out;
    }
    return out;
}

variable_types: value int

variable_types: out int

variable_types: mask int


decompiled_code:
__int64 __fastcall syncint_decode(unsigned int a1)
{
return (a1 >> 2) & 0x3FC000 | (a1 >> 1) & 0x7F80 | (unsigned __int8)a1 | (HIBYTE(a1) << 21);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return (a1 >> 2) & 0x3FC000 | (a1 >> 1) & 0x7F80 | (unsigned __int8)a1 | (HIBYTE(a1) << 21);
}

original_code:
unsigned int syncint_decode(int value)
{
    unsigned int a, b, c, d, result = 0x0;
    a = value & 0xFF;
    b = (value >> 8) & 0xFF;
    c = (value >> 16) & 0xFF;
    d = (value >> 24) & 0xFF;
    result = result | a;
    result = result | (b << 7);
    result = result | (c << 14);
    result = result | (d << 21);
    return result;
}

canonical_original_code:
unsigned int syncint_decode(int value)
{
    unsigned int a; unsigned int b; unsigned int c; unsigned int d; unsigned int result = 0x0;
    a = value & 0xFF;
    b = (value >> 8) & 0xFF;
    c = (value >> 16) & 0xFF;
    d = (value >> 24) & 0xFF;
    result = result | a;
    result = result | (b << 7);
    result = result | (c << 14);
    result = result | (d << 21);
    return result;
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
c
unsigned int

variable_types:
d
unsigned int


decompiled_code:
__int64 __fastcall clamp_int(signed int a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax

result = a2;
if ( a1 >= (int)a2 )
{
result = a3;
if ( a1 <= (int)a3 )
result = (unsigned int)a1;
}
return result;
}

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

result = a2;
if ( a1 >= (int)a2 )
{
result = a3;
if ( a1 <= (int)a3 )
result = (unsigned int)a1;
}
return result;
}

original_code:
int clamp_int(const int value, const int min, const int max)
{
    return value < min ? min : (value > max ? max : value);
}

canonical_original_code:
int clamp_int(int value, int min, int max)
{
    return value < min ? min : (value > max ? max : value);
}

variable_types: min int

variable_types: max int


decompiled_code:
bool __fastcall string_has_bom(_WORD *a1)
{
bool result; // al

if ( !a1 )
return 0;
result = 1;
if ( *a1 != 0xFEFF )
result = *a1 == 0xFFFE;
return result;
}

canonical_decompiled_code:
bool __fastcall func5(_WORD *a1)
{
bool result; // al

if ( !a1 )
return 0;
result = 1;
if ( *a1 != 0xFEFF )
result = *a1 == 0xFFFE;
return result;
}

original_code:
_Bool string_has_bom(const char* string)
{
    if (string == ((void *)0))
    {
        return 0;
    }
    if (memcmp("\xFF\xFE", string, 2) == 0 || memcmp("\xFE\xFF", string, 2) == 0)
    {
        return 1;
    }
    return 0;
}

canonical_original_code:
_Bool string_has_bom(char *string)
{
    if (string == ((void *)0))
    {
        return 0;
    }
    if (memcmp("\xFF\xFE", string, 2) == 0 || memcmp("\xFE\xFF", string, 2) == 0)
    {
        return 1;
    }
    return 0;
}

variable_types:
string
char *


decompiled_code:
char *__fastcall ID3v2_to_unicode(char *a1)
{
size_t v2; // rbx
size_t v3; // rbp
_WORD *v4; // rdx
__int64 i; // rax

if ( string_has_bom(a1) )
return a1;
v2 = strlen(a1);
v3 = 2 * (int)v2 + 4;
v4 = malloc(v3);
*v4 = -257;
for ( i = 0LL; v2 >= ++i; v4[i] = (unsigned __int8)a1[i - 1] )
;
*((_BYTE *)v4 + v3 - 2) = 0;
*((_BYTE *)v4 + v3 - 1) = 0;
return (char *)v4;
}

canonical_decompiled_code:
char *__fastcall func6(char *a1)
{
size_t v2; // rbx
size_t v3; // rbp
_WORD *v4; // rdx
__int64 i; // rax

if ( func5(a1) )
return a1;
v2 = strlen(a1);
v3 = 2 * (int)v2 + 4;
v4 = malloc(v3);
*v4 = -257;
for ( i = 0LL; v2 >= ++i; v4[i] = (unsigned __int8)a1[i - 1] )
;
*((_BYTE *)v4 + v3 - 2) = 0;
*((_BYTE *)v4 + v3 - 1) = 0;
return (char *)v4;
}

original_code:
char* ID3v2_to_unicode(char* string)
{
    if (string_has_bom(string))
    {
        return string;
    }
    const int str_termination_size = 2;
    const int result_size = (strlen(string) * 2) + 2 + str_termination_size;
    char* result = (char*) malloc(result_size * sizeof(char));
    result[0] = 0xFF;
    result[1] = 0xFE;
    for (int i = 1; i <= strlen(string); i++)
    {
        result[i * 2] = string[i - 1];
        result[(i * 2) + 1] = 0x00;
    }
    result[result_size - 2] = 0x00;
    result[result_size - 1] = 0x00;
    return result;
}

canonical_original_code:
char *ID3v2_to_unicode(char *string)
{
    if (string_has_bom(string))
    {
        return string;
    }
    int str_termination_size = 2;
    int result_size = (strlen(string) * 2) + 2 + str_termination_size;
    char *result = (char*) malloc(result_size * sizeof(char));
    result[0] = 0xFF;
    result[1] = 0xFE;
    for (int i = 1; i <= strlen(string); i++)
    {
        result[i * 2] = string[i - 1];
        result[(i * 2) + 1] = 0x00;
    }
    result[result_size - 2] = 0x00;
    result[result_size - 1] = 0x00;
    return result;
}

variable_types:
result
char *


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

if ( !string_has_bom(a1) )
return (unsigned int)strlen(a1);
if ( !*(_WORD *)a1 )
return 0;
v1 = 2LL;
do
{
v2 = a1[v1 + 1] | a1[v1];
v3 = v1;
v1 += 2LL;
}
while ( v2 );
return v3;
}

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

if ( !func5(a1) )
return (unsigned int)strlen(a1);
if ( !*(_WORD *)a1 )
return 0;
v1 = 2LL;
do
{
v2 = a1[v1 + 1] | a1[v1];
v3 = v1;
v1 += 2LL;
}
while ( v2 );
return v3;
}

original_code:
int ID3v2_strlen(const char* string)
{
    if (!string_has_bom(string))
    {
        return strlen(string);
    }
    char a = -1;
    char b = -1;
    int length = 0;
    while (1)
    {
        a = string[length];
        b = string[length + 1];
        if (a == 0x00 && b == 0x00)
        {
            break;
        }
        length += 2;
    }
    return length;
}

canonical_original_code:
int ID3v2_strlen(char *string)
{
    if (!string_has_bom(string))
    {
        return strlen(string);
    }
    char a = -1;
    char b = -1;
    int length = 0;
    while (1)
    {
        a = string[length];
        b = string[length + 1];
        if (a == 0x00 && b == 0x00)
        {
            break;
        }
        length += 2;
    }
    return length;
}

variable_types: a char

variable_types: b char

variable_types: length int


decompiled_code:
__int64 __fastcall ID3v2_strlent(char *a1)
{
int v1; // ebx

v1 = 1 - (!string_has_bom(a1) - 1);
return v1 + (unsigned int)ID3v2_strlen(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
int v1; // ebx

v1 = 1 - (!func5(a1) - 1);
return v1 + (unsigned int)func7(a1);
}

original_code:
int ID3v2_strlent(const char* string)
{
    const int termination_character_length = string_has_bom(string) ? 2 : 1;
    return ID3v2_strlen(string) + termination_character_length;
}

canonical_original_code:
int ID3v2_strlent(char *string)
{
    int termination_character_length = string_has_bom(string) ? 2 : 1;
    return ID3v2_strlen(string) + termination_character_length;
}


decompiled_code:
__int64 __fastcall FrameHeader_to_char_stream(__int64 a1)
{
__int64 v1; // r12
void *v2; // rbp

v1 = CharStream_new(10LL);
CharStream_write(v1, a1, 4LL);
v2 = (void *)itob(*(unsigned int *)(a1 + 4));
CharStream_write(v1, v2, 4LL);
free(v2);
CharStream_write(v1, a1 + 8, 2LL);
return v1;
}

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

v1 = CharStream_new(10LL);
CharStream_write(v1, a1, 4LL);
v2 = (void *)itob(*(unsigned int *)(a1 + 4));
CharStream_write(v1, v2, 4LL);
free(v2);
CharStream_write(v1, a1 + 8, 2LL);
return v1;
}

original_code:
CharStream* FrameHeader_to_char_stream(ID3v2_FrameHeader* header)
{
    CharStream* header_cs = CharStream_new(10);
    CharStream_write(header_cs, header->id, 4);
    char* size_bytes = itob(header->size);
    CharStream_write(header_cs, size_bytes, 4);
    free(size_bytes);
    CharStream_write(header_cs, (const char*) &header->flags, 2);
    return header_cs;
}

canonical_original_code:
struct _CharStream *FrameHeader_to_char_stream(struct _ID3v2_FrameHeader *header)
{
    struct _CharStream *header_cs = CharStream_new(10);
    CharStream_write(header_cs, header->id, 4);
    char *size_bytes = itob(header->size);
    CharStream_write(header_cs, size_bytes, 4);
    free(size_bytes);
    CharStream_write(header_cs, (char *) &header->flags, 2);
    return header_cs;
}

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

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


decompiled_code:
bool __fastcall FrameHeader_isTextFrame(_BYTE *a1)
{
return *a1 == 84;
}

canonical_decompiled_code:
bool __fastcall func1(_BYTE *a1)
{
return *a1 == 84;
}

original_code:
_Bool FrameHeader_isTextFrame(ID3v2_FrameHeader* header)
{
    return header->id[0] == 'T';
}

canonical_original_code:
_Bool FrameHeader_isTextFrame(struct _ID3v2_FrameHeader *header)
{
    return header->id[0] == 'T';
}


decompiled_code:
bool __fastcall FrameHeader_isCommentFrame(_BYTE *a1)
{
return *a1 == 67;
}

canonical_decompiled_code:
bool __fastcall func2(_BYTE *a1)
{
return *a1 == 67;
}

original_code:
_Bool FrameHeader_isCommentFrame(ID3v2_FrameHeader* header)
{
    return header->id[0] == 'C';
}

canonical_original_code:
_Bool FrameHeader_isCommentFrame(struct _ID3v2_FrameHeader *header)
{
    return header->id[0] == 'C';
}


decompiled_code:
bool __fastcall FrameHeader_isApicFrame(_BYTE *a1)
{
return *a1 == 65;
}

canonical_decompiled_code:
bool __fastcall func3(_BYTE *a1)
{
return *a1 == 65;
}

original_code:
_Bool FrameHeader_isApicFrame(ID3v2_FrameHeader* header)
{
    return header->id[0] == 'A';
}

canonical_original_code:
_Bool FrameHeader_isApicFrame(struct _ID3v2_FrameHeader *header)
{
    return header->id[0] == 'A';
}


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

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

original_code:
void FrameHeader_free(ID3v2_FrameHeader* header)
{
    free(header);
}

canonical_original_code:
void FrameHeader_free(struct _ID3v2_FrameHeader *header)
{
    free(header);
}


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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[2] = 0LL;
result[1] = 0LL;
}
return result;
}

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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[2] = 0LL;
result[1] = 0LL;
}
return result;
}

original_code:
ID3v2_FrameList* FrameList_new()
{
    ID3v2_FrameList* list = (ID3v2_FrameList*) malloc(sizeof(ID3v2_FrameList));
    if (list != ((void *)0))
    {
        list->frame = ((void *)0);
        list->next = ((void *)0);
        list->start = ((void *)0);
    }
    return list;
}

canonical_original_code:
struct _ID3v2_FrameList *FrameList_new()
{
    struct _ID3v2_FrameList *list = (ID3v2_FrameList*) malloc(sizeof(ID3v2_FrameList));
    if (list != ((void *)0))
    {
        list->frame = ((void *)0);
        list->next = ((void *)0);
        list->start = ((void *)0);
    }
    return list;
}

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


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

v2 = a1;
if ( !a1 )
return 0LL;
while ( 1 )
{
v3 = *(const char ***)v2;
if ( !*(_QWORD *)v2 || !strncmp(*v3, a2, 4uLL) )
break;
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return 0LL;
}
return v3;
}

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

v2 = a1;
if ( !a1 )
return 0LL;
while ( 1 )
{
v3 = *(const char ***)v2;
if ( !*(_QWORD *)v2 || !strncmp(*v3, a2, 4uLL) )
break;
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return 0LL;
}
return v3;
}

original_code:
ID3v2_Frame* FrameList_get_frame_by_id(ID3v2_FrameList* list, const char* frame_id)
{
    while (list != ((void *)0) && list->frame != ((void *)0))
    {
        if (strncmp(list->frame->header->id, frame_id, 4) == 0)
        {
            return list->frame;
        }
        list = list->next;
    }
    return ((void *)0);
}

canonical_original_code:
struct _ID3v2_Frame *FrameList_get_frame_by_id(struct _ID3v2_FrameList *list, char *frame_id)
{
    while (list != ((void *)0) && list->frame != ((void *)0))
    {
        if (strncmp(list->frame->header->id, frame_id, 4) == 0)
        {
            return list->frame;
        }
        list = list->next;
    }
    return ((void *)0);
}

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

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


decompiled_code:
const char **__fastcall FrameList_remove_frame_by_id(const char ***a1, const char *a2)
{
const char ***v2; // rbp
const char **v3; // r12
__m128i *v4; // r13
int v5; // eax

if ( !a1 )
return 0LL;
v2 = a1;
while ( 1 )
{
v3 = *v2;
v4 = (__m128i *)v2;
v5 = strncmp(**v2, a2, 4uLL);
v2 = (const char ***)v2[2];
if ( !v5 )
break;
if ( !v2 )
return 0LL;
}
if ( !v2 )
v2 = (const char ***)FrameList_new();
*v4 = _mm_loadu_si128((const __m128i *)v2);
v4[1].m128i_i64[0] = (__int64)v2[2];
free(v2);
return v3;
}

canonical_decompiled_code:
const char **__fastcall func5(const char ***a1, const char *a2)
{
const char ***v2; // rbp
const char **v3; // r12
__m128i *v4; // r13
int v5; // eax

if ( !a1 )
return 0LL;
v2 = a1;
while ( 1 )
{
v3 = *v2;
v4 = (__m128i *)v2;
v5 = strncmp(**v2, a2, 4uLL);
v2 = (const char ***)v2[2];
if ( !v5 )
break;
if ( !v2 )
return 0LL;
}
if ( !v2 )
v2 = (const char ***)func0();
*v4 = _mm_loadu_si128((const __m128i *)v2);
v4[1].m128i_i64[0] = (__int64)v2[2];
free(v2);
return v3;
}

original_code:
ID3v2_Frame* FrameList_remove_frame_by_id(ID3v2_FrameList* list, const char* frame_id)
{
    if (list == ((void *)0)) return ((void *)0);
    while (list != ((void *)0))
    {
        if (strncmp(list->frame->header->id, frame_id, 4) == 0)
        {
            ID3v2_Frame* removed = list->frame;
            ID3v2_FrameList* new_head_old_ptr = list->next != ((void *)0) ? list->next : FrameList_new();
            *list = *new_head_old_ptr;
            free(new_head_old_ptr);
            return removed;
        }
        list = list->next;
    }
    return ((void *)0);
}

canonical_original_code:
struct _ID3v2_Frame *FrameList_remove_frame_by_id(struct _ID3v2_FrameList *list, char *frame_id)
{
    if (list == ((void *)0)) return ((void *)0);
    while (list != ((void *)0))
    {
        if (strncmp(list->frame->header->id, frame_id, 4) == 0)
        {
            struct _ID3v2_Frame *removed = list->frame;
            struct _ID3v2_FrameList *new_head_old_ptr = list->next != ((void *)0) ? list->next : FrameList_new();
            *list = *new_head_old_ptr;
            free(new_head_old_ptr);
            return removed;
        }
        list = list->next;
    }
    return ((void *)0);
}

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


original_code:
ID3v2_Frame* FrameList_remove_frame(ID3v2_FrameList* list, ID3v2_Frame* to_remove)
{
    if (list == ((void *)0)) return ((void *)0);
    while (list != ((void *)0))
    {
        if (list->frame == to_remove)
        {
            ID3v2_FrameList* new_head_old_ptr = list->next != ((void *)0) ? list->next : FrameList_new();
            *list = *new_head_old_ptr;
            free(new_head_old_ptr);
            return to_remove;
        }
        list = list->next;
    }
    return ((void *)0);
}

canonical_original_code:
struct _ID3v2_Frame *FrameList_remove_frame(struct _ID3v2_FrameList *list, struct _ID3v2_Frame *to_remove)
{
    if (list == ((void *)0)) return ((void *)0);
    while (list != ((void *)0))
    {
        if (list->frame == to_remove)
        {
            struct _ID3v2_FrameList *new_head_old_ptr = list->next != ((void *)0) ? list->next : FrameList_new();
            *list = *new_head_old_ptr;
            free(new_head_old_ptr);
            return to_remove;
        }
        list = list->next;
    }
    return ((void *)0);
}


decompiled_code:
int delete_test_main()
{
__int64 v0; // r12
_DWORD *v1; // rax
_DWORD *v2; // rbp

clone_file("extra/file.mp3", "extra/file_edited.mp3");
v0 = ID3v2_read_tag("extra/file_edited.mp3");
if ( !v0 )
v0 = ID3v2_Tag_new_empty();
ID3v2_Tag_delete_frame(v0, "TALB");
ID3v2_Tag_delete_artist(v0);
ID3v2_Tag_delete_album_artist(v0);
ID3v2_Tag_delete_comment_frame(v0, 0LL);
ID3v2_Tag_delete_composer(v0);
ID3v2_Tag_delete_disc_number(v0);
ID3v2_Tag_delete_genre(v0);
ID3v2_Tag_delete_title(v0);
ID3v2_Tag_delete_track(v0);
ID3v2_Tag_delete_year(v0);
ID3v2_Tag_delete_album_cover(v0);
ID3v2_write_tag("extra/file_edited.mp3", v0);
v1 = (_DWORD *)ID3v2_read_tag("extra/file_edited.mp3");
v2 = v1;
if ( !v1 )
_assert_fail("edited_tag != NULL", "test/delete_test.c", 0x34u, "delete_test_main");
if ( *(_DWORD *)(*(_QWORD *)v1 + 8LL) != v1[4] )
_assert_fail(
"edited_tag->header->tag_size == edited_tag->padding_size",
"test/delete_test.c",
0x35u,
"delete_test_main");
if ( ID3v2_Tag_get_artist_frame(v1) )
_assert_fail("ID3v2_Tag_get_artist_frame(edited_tag) == NULL", "test/delete_test.c", 0x37u, "delete_test_main");
if ( ID3v2_Tag_get_album_frame(v2) )
_assert_fail("ID3v2_Tag_get_album_frame(edited_tag) == NULL", "test/delete_test.c", 0x38u, "delete_test_main");
if ( ID3v2_Tag_get_title_frame(v2) )
_assert_fail("ID3v2_Tag_get_title_frame(edited_tag) == NULL", "test/delete_test.c", 0x39u, "delete_test_main");
if ( ID3v2_Tag_get_track_frame(v2) )
_assert_fail("ID3v2_Tag_get_track_frame(edited_tag) == NULL", "test/delete_test.c", 0x3Au, "delete_test_main");
if ( ID3v2_Tag_get_album_artist_frame(v2) )
_assert_fail(
"ID3v2_Tag_get_album_artist_frame(edited_tag) == NULL",
"test/delete_test.c",
0x3Bu,
"delete_test_main");
if ( ID3v2_Tag_get_genre_frame(v2) )
_assert_fail("ID3v2_Tag_get_genre_frame(edited_tag) == NULL", "test/delete_test.c", 0x3Cu, "delete_test_main");
if ( ID3v2_Tag_get_year_frame(v2) )
_assert_fail("ID3v2_Tag_get_year_frame(edited_tag) == NULL", "test/delete_test.c", 0x3Du, "delete_test_main");
if ( ID3v2_Tag_get_disc_number_frame(v2) )
_assert_fail("ID3v2_Tag_get_disc_number_frame(edited_tag) == NULL", "test/delete_test.c", 0x3Eu, "delete_test_main");
if ( ID3v2_Tag_get_composer_frame(v2) )
_assert_fail("ID3v2_Tag_get_composer_frame(edited_tag) == NULL", "test/delete_test.c", 0x3Fu, "delete_test_main");
if ( ID3v2_Tag_get_comment_frame(v2) )
_assert_fail("ID3v2_Tag_get_comment_frame(edited_tag) == NULL", "test/delete_test.c", 0x40u, "delete_test_main");
if ( ID3v2_Tag_get_album_cover_frame(v2) )
_assert_fail("ID3v2_Tag_get_album_cover_frame(edited_tag) == NULL", "test/delete_test.c", 0x41u, "delete_test_main");
ID3v2_delete_tag("extra/file_edited.mp3");
if ( ID3v2_read_tag("extra/file_edited.mp3") )
_assert_fail("deleted_tag == NULL", "test/delete_test.c", 0x45u, "delete_test_main");
remove("extra/file_edited.mp3");
ID3v2_Tag_free(v0);
ID3v2_Tag_free(v2);
return puts("DELETE TEST: OK");
}

canonical_decompiled_code:
int func0()
{
__int64 v0; // r12
_DWORD *v1; // rax
_DWORD *v2; // rbp

clone_file("extra/file.mp3", "extra/file_edited.mp3");
v0 = ID3v2_read_tag("extra/file_edited.mp3");
if ( !v0 )
v0 = ID3v2_Tag_new_empty();
ID3v2_Tag_delete_frame(v0, "TALB");
ID3v2_Tag_delete_artist(v0);
ID3v2_Tag_delete_album_artist(v0);
ID3v2_Tag_delete_comment_frame(v0, 0LL);
ID3v2_Tag_delete_composer(v0);
ID3v2_Tag_delete_disc_number(v0);
ID3v2_Tag_delete_genre(v0);
ID3v2_Tag_delete_title(v0);
ID3v2_Tag_delete_track(v0);
ID3v2_Tag_delete_year(v0);
ID3v2_Tag_delete_album_cover(v0);
ID3v2_write_tag("extra/file_edited.mp3", v0);
v1 = (_DWORD *)ID3v2_read_tag("extra/file_edited.mp3");
v2 = v1;
if ( !v1 )
_assert_fail("edited_tag != NULL", "test/delete_test.c", 0x34u, "delete_test_main");
if ( *(_DWORD *)(*(_QWORD *)v1 + 8LL) != v1[4] )
_assert_fail(
"edited_tag->header->tag_size == edited_tag->padding_size",
"test/delete_test.c",
0x35u,
"delete_test_main");
if ( ID3v2_Tag_get_artist_frame(v1) )
_assert_fail("ID3v2_Tag_get_artist_frame(edited_tag) == NULL", "test/delete_test.c", 0x37u, "delete_test_main");
if ( ID3v2_Tag_get_album_frame(v2) )
_assert_fail("ID3v2_Tag_get_album_frame(edited_tag) == NULL", "test/delete_test.c", 0x38u, "delete_test_main");
if ( ID3v2_Tag_get_title_frame(v2) )
_assert_fail("ID3v2_Tag_get_title_frame(edited_tag) == NULL", "test/delete_test.c", 0x39u, "delete_test_main");
if ( ID3v2_Tag_get_track_frame(v2) )
_assert_fail("ID3v2_Tag_get_track_frame(edited_tag) == NULL", "test/delete_test.c", 0x3Au, "delete_test_main");
if ( ID3v2_Tag_get_album_artist_frame(v2) )
_assert_fail(
"ID3v2_Tag_get_album_artist_frame(edited_tag) == NULL",
"test/delete_test.c",
0x3Bu,
"delete_test_main");
if ( ID3v2_Tag_get_genre_frame(v2) )
_assert_fail("ID3v2_Tag_get_genre_frame(edited_tag) == NULL", "test/delete_test.c", 0x3Cu, "delete_test_main");
if ( ID3v2_Tag_get_year_frame(v2) )
_assert_fail("ID3v2_Tag_get_year_frame(edited_tag) == NULL", "test/delete_test.c", 0x3Du, "delete_test_main");
if ( ID3v2_Tag_get_disc_number_frame(v2) )
_assert_fail("ID3v2_Tag_get_disc_number_frame(edited_tag) == NULL", "test/delete_test.c", 0x3Eu, "delete_test_main");
if ( ID3v2_Tag_get_composer_frame(v2) )
_assert_fail("ID3v2_Tag_get_composer_frame(edited_tag) == NULL", "test/delete_test.c", 0x3Fu, "delete_test_main");
if ( ID3v2_Tag_get_comment_frame(v2) )
_assert_fail("ID3v2_Tag_get_comment_frame(edited_tag) == NULL", "test/delete_test.c", 0x40u, "delete_test_main");
if ( ID3v2_Tag_get_album_cover_frame(v2) )
_assert_fail("ID3v2_Tag_get_album_cover_frame(edited_tag) == NULL", "test/delete_test.c", 0x41u, "delete_test_main");
ID3v2_delete_tag("extra/file_edited.mp3");
if ( ID3v2_read_tag("extra/file_edited.mp3") )
_assert_fail("deleted_tag == NULL", "test/delete_test.c", 0x45u, "delete_test_main");
remove("extra/file_edited.mp3");
ID3v2_Tag_free(v0);
ID3v2_Tag_free(v2);
return puts("DELETE TEST: OK");
}

original_code:
void delete_test_main()
{
    clone_file("extra/file.mp3", "extra/file_edited.mp3");
    ID3v2_Tag* tag = ID3v2_read_tag("extra/file_edited.mp3");
    if (tag == ((void *)0))
    {
        tag = ID3v2_Tag_new_empty();
    }
    ID3v2_Tag_delete_frame(tag, "TALB");
    ID3v2_Tag_delete_artist(tag);
    ID3v2_Tag_delete_album_artist(tag);
    ID3v2_Tag_delete_comment_frame(tag, 0);
    ID3v2_Tag_delete_composer(tag);
    ID3v2_Tag_delete_disc_number(tag);
    ID3v2_Tag_delete_genre(tag);
    ID3v2_Tag_delete_title(tag);
    ID3v2_Tag_delete_track(tag);
    ID3v2_Tag_delete_year(tag);
    ID3v2_Tag_delete_album_cover(tag);
    ID3v2_write_tag("extra/file_edited.mp3", tag);
    ID3v2_Tag* edited_tag = ID3v2_read_tag("extra/file_edited.mp3");
    ((edited_tag != ((void *)0)) ? (void) (0) : __assert_fail ("edited_tag != NULL", "test/delete_test.c", 52, __extension__ __PRETTY_FUNCTION__));
    ((edited_tag->header->tag_size == edited_tag->padding_size) ? (void) (0) : __assert_fail ("edited_tag->header->tag_size == edited_tag->padding_size", "test/delete_test.c", 53, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_artist_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_artist_frame(edited_tag) == NULL", "test/delete_test.c", 55, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_album_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_album_frame(edited_tag) == NULL", "test/delete_test.c", 56, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_title_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_title_frame(edited_tag) == NULL", "test/delete_test.c", 57, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_track_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_track_frame(edited_tag) == NULL", "test/delete_test.c", 58, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_album_artist_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_album_artist_frame(edited_tag) == NULL", "test/delete_test.c", 59, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_genre_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_genre_frame(edited_tag) == NULL", "test/delete_test.c", 60, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_year_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_year_frame(edited_tag) == NULL", "test/delete_test.c", 61, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_disc_number_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_disc_number_frame(edited_tag) == NULL", "test/delete_test.c", 62, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_composer_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_composer_frame(edited_tag) == NULL", "test/delete_test.c", 63, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_comment_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_comment_frame(edited_tag) == NULL", "test/delete_test.c", 64, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_album_cover_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_album_cover_frame(edited_tag) == NULL", "test/delete_test.c", 65, __extension__ __PRETTY_FUNCTION__));
    ID3v2_delete_tag("extra/file_edited.mp3");
    ID3v2_Tag* deleted_tag = ID3v2_read_tag("extra/file_edited.mp3");
    ((deleted_tag == ((void *)0)) ? (void) (0) : __assert_fail ("deleted_tag == NULL", "test/delete_test.c", 69, __extension__ __PRETTY_FUNCTION__));
    remove("extra/file_edited.mp3");
    ID3v2_Tag_free(tag);
    ID3v2_Tag_free(edited_tag);
    printf("DELETE TEST: OK\n");
}

canonical_original_code:
void delete_test_main()
{
    clone_file("extra/file.mp3", "extra/file_edited.mp3");
    struct _ID3v2_Tag *tag = ID3v2_read_tag("extra/file_edited.mp3");
    if (tag == ((void *)0))
    {
        tag = ID3v2_Tag_new_empty();
    }
    ID3v2_Tag_delete_frame(tag, "TALB");
    ID3v2_Tag_delete_artist(tag);
    ID3v2_Tag_delete_album_artist(tag);
    ID3v2_Tag_delete_comment_frame(tag, 0);
    ID3v2_Tag_delete_composer(tag);
    ID3v2_Tag_delete_disc_number(tag);
    ID3v2_Tag_delete_genre(tag);
    ID3v2_Tag_delete_title(tag);
    ID3v2_Tag_delete_track(tag);
    ID3v2_Tag_delete_year(tag);
    ID3v2_Tag_delete_album_cover(tag);
    ID3v2_write_tag("extra/file_edited.mp3", tag);
    struct _ID3v2_Tag *edited_tag = ID3v2_read_tag("extra/file_edited.mp3");
    ((edited_tag != ((void *)0)) ? (void) (0) : __assert_fail ("edited_tag != NULL", "test/delete_test.c", 52, __extension__ __PRETTY_FUNCTION__));
    ((edited_tag->header->tag_size == edited_tag->padding_size) ? (void) (0) : __assert_fail ("edited_tag->header->tag_size == edited_tag->padding_size", "test/delete_test.c", 53, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_artist_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_artist_frame(edited_tag) == NULL", "test/delete_test.c", 55, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_album_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_album_frame(edited_tag) == NULL", "test/delete_test.c", 56, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_title_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_title_frame(edited_tag) == NULL", "test/delete_test.c", 57, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_track_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_track_frame(edited_tag) == NULL", "test/delete_test.c", 58, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_album_artist_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_album_artist_frame(edited_tag) == NULL", "test/delete_test.c", 59, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_genre_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_genre_frame(edited_tag) == NULL", "test/delete_test.c", 60, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_year_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_year_frame(edited_tag) == NULL", "test/delete_test.c", 61, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_disc_number_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_disc_number_frame(edited_tag) == NULL", "test/delete_test.c", 62, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_composer_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_composer_frame(edited_tag) == NULL", "test/delete_test.c", 63, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_comment_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_comment_frame(edited_tag) == NULL", "test/delete_test.c", 64, __extension__ __PRETTY_FUNCTION__));
    ((ID3v2_Tag_get_album_cover_frame(edited_tag) == ((void *)0)) ? (void) (0) : __assert_fail ("ID3v2_Tag_get_album_cover_frame(edited_tag) == NULL", "test/delete_test.c", 65, __extension__ __PRETTY_FUNCTION__));
    ID3v2_delete_tag("extra/file_edited.mp3");
    struct _ID3v2_Tag *deleted_tag = ID3v2_read_tag("extra/file_edited.mp3");
    ((deleted_tag == ((void *)0)) ? (void) (0) : __assert_fail ("deleted_tag == NULL", "test/delete_test.c", 69, __extension__ __PRETTY_FUNCTION__));
    remove("extra/file_edited.mp3");
    ID3v2_Tag_free(tag);
    ID3v2_Tag_free(edited_tag);
    printf("DELETE TEST: 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; } *


osInit

repo: larsks/crashmail

decompiled_code:
__int64 osInit()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
bool osInit(void)
{
   return(1);
}

canonical_original_code:
int osInit()
{
   return(1);
}


osEnd

decompiled_code:
void osEnd()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void osEnd(void)
{
}

canonical_original_code:
void osEnd()
{
}


osCheckPattern

decompiled_code:
__int64 osCheckPattern()
{
return 1LL;
}

original_code:
bool osCheckPattern(char *pattern)
{
   return(1);
}

canonical_original_code:
int osCheckPattern(char *pattern)
{
   return(1);
}

variable_types:
pattern
char *


osMatchPattern

decompiled_code:
_BOOL8 __fastcall osMatchPattern(char *a1, _BYTE *a2)
{
_BYTE *v2; // r13
__int64 v3; // rbx
__int64 v4; // rbp
__int64 v5; // r12
const __int32_t **v6; // rax

v2 = a2;
v3 = *a1;
if ( (_BYTE)v3 )
{
v4 = 0LL;
do
{
if ( (_BYTE)v3 == 42 )
return 1LL;
v5 = (char)a2[v4];
if ( !(_BYTE)v5 )
return 0LL;
if ( (_BYTE)v3 != 63 )
{
v6 = _ctype_tolower_loc();
if ( (*v6)[v5] != (*v6)[v3] )
return 0LL;
}
v3 = a1[++v4];
}
while ( (_BYTE)v3 );
v2 = &a2[v4];
}
return *v2 == 0;
}

original_code:
bool osMatchPattern(char *pattern,char *str)
{
   int c;
   for(c=0;pattern[c];c++)
   {
      if(pattern[c]=='*')
         return(1);
      if(str[c] == 0)
         return(0);
      if(pattern[c]!='?' && tolower(pattern[c])!=tolower(str[c]))
         return(0);
   }
   if(str[c]!=0)
      return(0);
   return(1);
}

canonical_original_code:
int osMatchPattern(char *pattern, char *str)
{
   int c;
   for(c=0;pattern[c];c++)
   {
      if(pattern[c]=='*')
         return(1);
      if(str[c] == 0)
         return(0);
      if(pattern[c]!='?' && tolower(pattern[c])!=tolower(str[c]))
         return(0);
   }
   if(str[c]!=0)
      return(0);
   return(1);
}

variable_types:
str
char *

variable_types: c int


osIsPattern

decompiled_code:
_BOOL8 __fastcall osIsPattern(char *s)
{
char *v1; // r8
_BOOL8 result; // rax

v1 = strchr(s, 63);
result = 1LL;
if ( !v1 )
result = strchr(s, 42) != 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char *s)
{
char *v1; // r8
_BOOL8 result; // rax

v1 = strchr(s, 63);
result = 1LL;
if ( !v1 )
result = strchr(s, 42) != 0LL;
return result;
}

original_code:
bool osIsPattern(char *pat)
{
   if(strchr(pat,'?') || strchr(pat,'*'))
      return(1);
 return(0);
}

canonical_original_code:
int osIsPattern(char *pat)
{
   if(strchr(pat,'?') || strchr(pat,'*'))
      return(1);
 return(0);
}

variable_types:
pat
char *


repo: larsmagne/weaverd

decompiled_code:
void sigpipe_handle_clients()
{
signal(13, sigpipe_handle_clients);
puts("Got a SIGPIPE; continuing.");
}

canonical_decompiled_code:
void func0()
{
signal(13, sigpipe_handle_clients);
puts("Got a SIGPIPE; continuing.");
}

original_code:
void sigpipe_handle_clients(int ignore) {
  signal(13, sigpipe_handle_clients);
  printf("Got a SIGPIPE; continuing.\n");
}

variable_types: ignore int


closedown

decompiled_code:
void __noreturn closedown()
{
char *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
if ( server_socket )
close(server_socket);
flush();
v0 = ctime(&timer);
printf("Closed down at %s", v0);
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
char *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
if ( server_socket )
close(server_socket);
flush();
v0 = ctime(&timer);
printf("Closed down at %s", v0);
exit(0);
}

original_code:
void closedown(int i) {
 time_t now = time(((void *)0));
 if (server_socket)
   close(server_socket);
 flush();
 printf("Closed down at %s", ctime(&now));
 exit(0);
}

canonical_original_code:
void closedown(int i) {
 long now = time(((void *)0));
 if (server_socket)
   close(server_socket);
 flush();
 printf("Closed down at %s", ctime(&now));
 exit(0);
}

variable_types: i int

variable_types: now long


decompiled_code:
__int64 __fastcall parse_args(int argc, char **argv)
{
int v2; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

longind[0] = 0;
while ( 1 )
{
v2 = getopt_long(argc, argv, "hs:i:p:b:", &long_options, longind);
if ( v2 == -1 )
break;
if ( v2 == 112 )
{
port = atoi(optarg);
}
else if ( v2 > 112 )
{
if ( v2 == 115 )
news_spool = optarg;
}
else if ( v2 == 104 )
{
puts("Usage: we:index [--spool <directory>] <directories ...>");
}
else if ( v2 == 105 )
{
index_dir = optarg;
}
}
return (unsigned int)optind;
}

canonical_decompiled_code:
__int64 __fastcall func4(int argc, char **argv)
{
int v2; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

longind[0] = 0;
while ( 1 )
{
v2 = getopt_long(argc, argv, "hs:i:p:b:", &long_options, longind);
if ( v2 == -1 )
break;
if ( v2 == 112 )
{
port = atoi(optarg);
}
else if ( v2 > 112 )
{
if ( v2 == 115 )
news_spool = optarg;
}
else if ( v2 == 104 )
{
puts("Usage: we:index [--spool <directory>] <directories ...>");
}
else if ( v2 == 105 )
{
index_dir = optarg;
}
}
return (unsigned int)optind;
}

original_code:
int parse_args(int argc, char **argv) {
  int option_index = 0, c;
  while (1) {
    c = getopt_long(argc, argv, "hs:i:p:b:", long_options, &option_index);
    if (c == -1)
      break;
    switch (c) {
    case 'i':
      index_dir = optarg;
      break;
    case 's':
      news_spool = optarg;
      break;
    case 'p':
      port = atoi(optarg);
      break;
    case 'h':
      printf ("Usage: we:index [--spool <directory>] <directories ...>\n");
      break;
    default:
      break;
    }
  }
  return optind;
}

canonical_original_code:
int parse_args(int argc, char **argv) {
  int option_index = 0; int c;
  while (1) {
    c = getopt_long(argc, argv, "hs:i:p:b:", long_options, &option_index);
    if (c == -1)
      break;
    switch (c) {
    case 'i':
      index_dir = optarg;
      break;
    case 's':
      news_spool = optarg;
      break;
    case 'p':
      port = atoi(optarg);
      break;
    case 'h':
      printf ("Usage: we:index [--spool <directory>] <directories ...>\n");
      break;
    default:
      break;
    }
  }
  return optind;
}

variable_types: argc int

variable_types:
argv
char **


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
socklen_t v4; // edx
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

parse_args(argc, (char **)argv);
init();
inhibit_thread_flattening = 0;
if ( signal(1, (__sighandler_t)closedown) != (__sighandler_t)-1LL
&& signal(2, (__sighandler_t)closedown) != (__sighandler_t)-1LL
&& signal(13, (__sighandler_t)((char *)sigpipe_handle_clients + 1)) != (__sighandler_t)-1LL )
{
server_socket = socket(2, 1, 0);
if ( server_socket != -1 )
{
setsockopt(server_socket, 1, 2, &so_reuseaddr_0, 4u);
v3 = (unsigned __int16)port;
v5.sa_family = 2;
*(_WORD *)v5.sa_data = _bswap_16(port);
*(_DWORD *)&v5.sa_data[2] = _bswap_32_constprop_0(v3, &v5);
if ( bind(server_socket, &v5, v4) != -1 )
{
if ( listen(server_socket, 120) != -1 )
{
time(&start_time);
handle_clients();
}
perror("Bad listen");
exit(1);
}
perror("Bind");
exit(1);
}
perror("No socket");
exit(1);
}
perror("Signal");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
socklen_t v4; // edx
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

func4(argc, (char **)argv);
init();
inhibit_thread_flattening = 0;
if ( signal(1, (__sighandler_t)closedown) != (__sighandler_t)-1LL
&& signal(2, (__sighandler_t)closedown) != (__sighandler_t)-1LL
&& signal(13, (__sighandler_t)((char *)sigpipe_handle_clients + 1)) != (__sighandler_t)-1LL )
{
server_socket = socket(2, 1, 0);
if ( server_socket != -1 )
{
setsockopt(server_socket, 1, 2, &so_reuseaddr_0, 4u);
v3 = (unsigned __int16)port;
v5.sa_family = 2;
*(_WORD *)v5.sa_data = func2(port);
*(_DWORD *)&v5.sa_data[2] = func3(v3, &v5);
if ( bind(server_socket, &v5, v4) != -1 )
{
if ( listen(server_socket, 120) != -1 )
{
time(&start_time);
func5();
}
perror("Bad listen");
exit(1);
}
perror("Bind");
exit(1);
}
perror("No socket");
exit(1);
}
perror("Signal");
exit(1);
}

original_code:
int main(int argc, char **argv) {
  parse_args(argc, argv);
  struct sockaddr_in sin;
  static int so_reuseaddr = 1;
  init();
  inhibit_thread_flattening = 0;
  if (signal(1, closedown) == ((__sighandler_t) -1)) {
    perror("Signal");
    exit(1);
  }
  if (signal(2, closedown) == ((__sighandler_t) -1)) {
    perror("Signal");
    exit(1);
  }
  if (signal(13, ((__sighandler_t) 1)) == ((__sighandler_t) -1)) {
    perror("Signal");
    exit(1);
  }
  if ((server_socket = socket(2, SOCK_STREAM, 0)) == -1) {
    perror("No socket");
    exit(1);
  }
  setsockopt(server_socket, 1, 2, &so_reuseaddr,
      sizeof(so_reuseaddr));
  sin.sin_family = 2;
  sin.sin_port = htons(port);
  sin.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  if (bind(server_socket, (struct sockaddr*)&sin, sizeof(sin)) == -1) {
    perror("Bind");
    exit(1);
  }
  if (listen(server_socket, 120) == -1) {
    perror("Bad listen");
    exit(1);
  }
  time(&start_time);
  handle_clients();
  exit(1);
}

canonical_original_code:
int main(int argc, char **argv) {
  parse_args(argc, argv);
  struct sockaddr_in sin;
  static int so_reuseaddr = 1;
  init();
  inhibit_thread_flattening = 0;
  if (signal(1, closedown) == ((__sighandler_t) -1)) {
    perror("Signal");
    exit(1);
  }
  if (signal(2, closedown) == ((__sighandler_t) -1)) {
    perror("Signal");
    exit(1);
  }
  if (signal(13, ((void (*)(int)) 1)) == ((__sighandler_t) -1)) {
    perror("Signal");
    exit(1);
  }
  if ((server_socket = socket(2, SOCK_STREAM, 0)) == -1) {
    perror("No socket");
    exit(1);
  }
  setsockopt(server_socket, 1, 2, &so_reuseaddr,
      sizeof(so_reuseaddr));
  sin.sin_family = 2;
  sin.sin_port = htons(port);
  sin.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  if (bind(server_socket, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
    perror("Bind");
    exit(1);
  }
  if (listen(server_socket, 120) == -1) {
    perror("Bad listen");
    exit(1);
  }
  time(&start_time);
  handle_clients();
  exit(1);
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


fusVerticale

original_code:
void fusVerticale(struct tab2D *source, int count, struct tab2D *destination){
    int i = 0, ix = 0;
    char * (*destinationPtr)[destination->colonnes];
    destinationPtr= (char * (*)[destination->colonnes]) destination->ptr;
    for (i = 0; i < count; i++) {
        int k = 0, j = 0;
        char * (*sourcePtr)[source[i].colonnes];
        sourcePtr = (char * (*)[source[i].colonnes]) source[i].ptr;
        for (k = 0; k < source[i].lignes; k++) {
            for (j = 0; j < source[i].colonnes; j++){
                size_t len = strlen(sourcePtr[k][j]) + 1;
                destinationPtr[k + ix][j] = memcpy(malloc(strlen(sourcePtr[k][j]) + 1), sourcePtr[k][j], len);
            }
            for (j = source[i].colonnes; j < destination->colonnes; j++)
                destinationPtr[k + ix][j] = memcpy(malloc(sizeof ("")), "",sizeof (""));
        }
        ix += source[i].lignes;
    }
}

canonical_original_code:
void fusVerticale(struct tab2D *source, int count, struct tab2D *destination){
    int i = 0; int ix = 0;
    char *(*destinationPtr)[-1];
    destinationPtr= (char *(*)[-1]) destination->ptr;
    for (i = 0; i < count; i++) {
        int k = 0; int j = 0;
        char *(*sourcePtr)[-1];
        sourcePtr = (char *(*)[-1]) source[i].ptr;
        for (k = 0; k < source[i].lignes; k++) {
            for (j = 0; j < source[i].colonnes; j++){
                unsigned long len = strlen(sourcePtr[k][j]) + 1;
                destinationPtr[k + ix][j] = memcpy(malloc(strlen(sourcePtr[k][j]) + 1), sourcePtr[k][j], len);
            }
            for (j = source[i].colonnes; j < destination->colonnes; j++)
                destinationPtr[k + ix][j] = memcpy(malloc(sizeof ("")), "",sizeof (""));
        }
        ix += source[i].lignes;
    }
}

variable_types: struct tab2D { int lignes; int colonnes; char **ptr; } *

variable_types: count int

variable_types:
destination
struct tab2D *

variable_types: ix int

variable_types:
destinationPtr
char *(*)[-1]

variable_types: k int

variable_types: j int

variable_types:
sourcePtr
char *(*)[-1]

variable_types:
len
unsigned long


fusHorizontale

original_code:
void fusHorizontale(struct tab2D *source, int count, struct tab2D *destination){
    int i = 0,
    ix = 0;
    char * (*destinationPtr)[destination->colonnes];
    destinationPtr = (char * (*)[destination->colonnes]) destination->ptr;
    for (i = 0; i < count; i++) {
        int k = 0, j = 0;
        char * (*sourcePtr)[source[i].colonnes];
        sourcePtr = (char * (*)[source[i].colonnes]) source[i].ptr;
        for (j = 0; j < source[i].colonnes; j++) {
            for (k = 0; k < source[i].lignes; k++){
                size_t len = strlen(sourcePtr[k][j]) + 1;
                destinationPtr[k][j + ix] = memcpy(malloc(len), sourcePtr[k][j], len);
            }
            for (k = source[i].lignes; k < destination->lignes; k++)
                destinationPtr[k][j + ix] = memcpy(malloc(sizeof ("")), "",sizeof (""));
        }
        ix += source[i].colonnes;
    }
}

canonical_original_code:
void fusHorizontale(struct tab2D *source, int count, struct tab2D *destination){
    int i = 0; int ix = 0;
    char *(*destinationPtr)[-1];
    destinationPtr = (char *(*)[-1]) destination->ptr;
    for (i = 0; i < count; i++) {
        int k = 0; int j = 0;
        char *(*sourcePtr)[-1];
        sourcePtr = (char *(*)[-1]) source[i].ptr;
        for (j = 0; j < source[i].colonnes; j++) {
            for (k = 0; k < source[i].lignes; k++){
                unsigned long len = strlen(sourcePtr[k][j]) + 1;
                destinationPtr[k][j + ix] = memcpy(malloc(len), sourcePtr[k][j], len);
            }
            for (k = source[i].lignes; k < destination->lignes; k++)
                destinationPtr[k][j + ix] = memcpy(malloc(sizeof ("")), "",sizeof (""));
        }
        ix += source[i].colonnes;
    }
}

user_defined_types: struct tab2D { int lignes; int colonnes; char **ptr; }


afficher

decompiled_code:
int __fastcall afficher(__int64 a1, __int64 a2)
{
int result; // eax
__int64 v3; // rbp
int v4; // er13
__int64 v5; // rbx
const char *v6; // rsi

if ( SHIDWORD(a1) <= 0 || (int)a1 <= 0 || !a2 )
return signaler(4LL);
v3 = a2;
v4 = 0;
do
{
v5 = 0LL;
putchar(91);
do
{
v6 = *(const char **)(v3 + 8 * v5++);
printf("%-10s ", v6);
}
while ( SHIDWORD(a1) > (int)v5 );
++v4;
v3 += 8 * (a1 >> 32);
result = puts("]");
}
while ( (int)a1 > v4 );
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
int result; // eax
__int64 v3; // rbp
int v4; // er13
__int64 v5; // rbx
const char *v6; // rsi

if ( SHIDWORD(a1) <= 0 || (int)a1 <= 0 || !a2 )
return signaler(4LL);
v3 = a2;
v4 = 0;
do
{
v5 = 0LL;
putchar(91);
do
{
v6 = *(const char **)(v3 + 8 * v5++);
printf("%-10s ", v6);
}
while ( SHIDWORD(a1) > (int)v5 );
++v4;
v3 += 8 * (a1 >> 32);
result = puts("]");
}
while ( (int)a1 > v4 );
return result;
}

original_code:
void afficher(struct tab2D mat)
{
if (mat.lignes>0 && mat.colonnes>0 && mat.ptr!=((void *)0))
{
    char * (*lignePtr)[mat.colonnes];
    lignePtr = (char * (*)[mat.colonnes]) mat.ptr;
    int i = 0 ;
    for (; i < mat.lignes ; i++)
    {
        printf("[");
        int j = 0;
        for ( ; j < mat.colonnes ; j++)
        {
            printf("%-10s ",lignePtr[i][j]);
        }
        printf("]\n");
    }
}
else
 {
    signaler(4);
 }
}

canonical_original_code:
void afficher(struct tab2D mat)
{
if (mat.lignes>0 && mat.colonnes>0 && mat.ptr!=((void *)0))
{
    char *(*lignePtr)[-1];
    lignePtr = (char *(*)[-1]) mat.ptr;
    int i = 0;
    for (; i < mat.lignes ; i++)
    {
        printf("[");
        int j = 0;
        for ( ; j < mat.colonnes ; j++)
        {
            printf("%-10s ",lignePtr[i][j]);
        }
        printf("]\n");
    }
}
else
 {
    signaler(4);
 }
}

variable_types: struct tab2D { int lignes; int colonnes; char **ptr; }

variable_types:
lignePtr
char *(*)[-1]


fusionner

decompiled_code:
int *__fastcall fusionner(char a1, int *a2, unsigned int a3, __int64 a4)
{
int *result; // rax

if ( a1 == 72 )
return fusHorizontale(a2, a3, a4);
if ( a1 == 86 )
result = (int *)fusVerticale((__int64)a2, a3, a4);
return result;
}

canonical_decompiled_code:
int *__fastcall func3(char a1, int *a2, unsigned int a3, __int64 a4)
{
int *result; // rax

if ( a1 == 72 )
return func1(a2, a3, a4);
if ( a1 == 86 )
result = (int *)func0((__int64)a2, a3, a4);
return result;
}

original_code:
void fusionner(char mode,struct tab2D *t1,int count,struct tab2D *t2){
    if (mode=='H')
    {
        fusHorizontale(t1,count,t2);
    }
    else if (mode=='V')
    {
        fusVerticale(t1,count,t2);
    }
}

canonical_original_code:
void fusionner(char mode, struct tab2D *t1, int count, struct tab2D *t2){
    if (mode=='H')
    {
        fusHorizontale(t1,count,t2);
    }
    else if (mode=='V')
    {
        fusVerticale(t1,count,t2);
    }
}

variable_types: mode char


genererTables

decompiled_code:
int genererTables()
{
unsigned int v0; // er12
unsigned int v1; // ebp
int v2; // ebx
__int64 v3; // rsi
int result; // eax

v0 = 1;
printf("0 1 2 3 4 5 6 7 8 9 \n ");
printf("* ");
putchar(10);
do
{
v1 = 0;
printf("%4d|", v0);
v2 = 1000;
do
{
v3 = v1;
v1 += v0;
printf("%4d", v3);
--v2;
}
while ( v2 );
++v0;
result = putchar(10);
}
while ( v0 != 1000 );
return result;
}

canonical_decompiled_code:
int func7()
{
unsigned int v0; // er12
unsigned int v1; // ebp
int v2; // ebx
__int64 v3; // rsi
int result; // eax

v0 = 1;
printf("0 1 2 3 4 5 6 7 8 9 \n ");
printf("* ");
putchar(10);
do
{
v1 = 0;
printf("%4d|", v0);
v2 = 1000;
do
{
v3 = v1;
v1 += v0;
printf("%4d", v3);
--v2;
}
while ( v2 );
++v0;
result = putchar(10);
}
while ( v0 != 1000 );
return result;
}

variable_types: i int

variable_types: c char


minMax

decompiled_code:
void minMax()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void minMax(int entiers[]) {
    int i;
    int min = 0;
    int max = 0;
}

variable_types:
entiers
int []

variable_types: min int

variable_types: max int


echange

decompiled_code:
__int64 __fastcall echange(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void echange(int* i, int* j){
    int temp= *i;
    *i=*j;
    *j=temp;
}

canonical_original_code:
void echange(int *i, int *j){
    int temp = *i;
    *i=*j;
    *j=temp;
}

variable_types:
i
int *

variable_types:
j
int *

variable_types: temp int


inverse

decompiled_code:
__int64 __fastcall inverse(_DWORD *a1, int a2)
{
__int64 v2; // r9
__int64 result; // rax
int v4; // ecx
int v5; // er8

if ( a2 > 1 )
{
v2 = 2LL * ((_QWORD)a1 + 2 * a2) - 4;
do
{
result = echange(a1, (_DWORD *)(v2 - (_QWORD)a1));
++a1;
}
while ( v4 < v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1, int a2)
{
__int64 v2; // r9
__int64 result; // rax
int v4; // ecx
int v5; // er8

if ( a2 > 1 )
{
v2 = 2LL * ((_QWORD)a1 + 2 * a2) - 4;
do
{
result = func10(a1, (_DWORD *)(v2 - (_QWORD)a1));
++a1;
}
while ( v4 < v5 );
}
return result;
}

original_code:
void inverse(int a[], int taille){
    int i=0;
    for(;i<(taille/2);i++){
        echange(a+i,a+(taille-1-i));
    }
}

canonical_original_code:
void inverse(int a[], int taille){
    int i = 0;
    for(;i<(taille/2);i++){
        echange(a+i,a+(taille-1-i));
    }
}

variable_types:
a
int []

variable_types: taille int


decompiled_code:
int __fastcall affiche_vecteur_int(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi

v2 = a1;
printf("contenu du vecteur: ");
if ( a2 > 0 )
{
v3 = (__int64)&a1[a2 - 1 + 1];
do
{
v4 = *v2++;
printf("%4d", v4);
}
while ( v2 != (unsigned int *)v3 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func12(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi

v2 = a1;
printf("contenu du vecteur: ");
if ( a2 > 0 )
{
v3 = (__int64)&a1[a2 - 1 + 1];
do
{
v4 = *v2++;
printf("%4d", v4);
}
while ( v2 != (unsigned int *)v3 );
}
return putchar(10);
}

original_code:
void affiche_vecteur_int(int a[], int taille){
 int i = 0;
 printf("contenu du vecteur: ");
 for( ; i < taille ; i++){
  printf("%4d", a[i]);
 }
 printf("\n");
}