decompiled_code:
int __fastcall assert_apic_frame(__int64 a1, __int64 a2)
{
char v2; // al
char v3; // r15
int v4; // er12
int v5; // ebp
int v6; // er13
int v7; // edx
int v8; // ecx
int v9; // er8
int v10; // er9
__int64 v11; // 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);
assert_frame_header((const void **)a1, a2, v7, v8, v9, v10, "APIC", v6 + v4 + v5 + 2, *(void **)a2);
v11 = *(_QWORD *)(a1 + 8);
if ( *(_BYTE *)v11 != v3 )
_assert_fail("frame->data->encoding == encoding", "test/assertion_utils.c", 0x74u, "assert_apic_frame");
if ( v6 != *(_DWORD *)(v11 + 40) )
_assert_fail(
"frame->data->picture_size == comparison->picture_size",
"test/assertion_utils.c",
0x75u,
"assert_apic_frame");
if ( memcmp(*(const void **)(v11 + 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 **)(v11 + 8), *(const void **)(a2 + 8), v5) )
_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 **)(v11 + 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 func3(__int64 a1, __int64 a2)
{
char v2; // al
char v3; // r15
int v4; // er12
int v5; // ebp
int v6; // er13
int v7; // edx
int v8; // ecx
int v9; // er8
int v10; // er9
__int64 v11; // 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);
func0((const void **)a1, a2, v7, v8, v9, v10, "APIC", v6 + v4 + v5 + 2, *(void **)a2);
v11 = *(_QWORD *)(a1 + 8);
if ( *(_BYTE *)v11 != v3 )
_assert_fail("frame->data->encoding == encoding", "test/assertion_utils.c", 0x74u, "assert_apic_frame");
if ( v6 != *(_DWORD *)(v11 + 40) )
_assert_fail(
"frame->data->picture_size == comparison->picture_size",
"test/assertion_utils.c",
0x75u,
"assert_apic_frame");
if ( memcmp(*(const void **)(v11 + 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 **)(v11 + 8), *(const void **)(a2 + 8), v5) )
_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 **)(v11 + 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; } *


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

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; // rbx
__int64 v2; // rbp

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 _CharStream { int cursor; int size; char *stream; } *

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; // rbx
__int64 v3; // rbp

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rbp

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 _CharStream { int cursor; int size; char *stream; }

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

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

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


decompiled_code:
_BOOL8 __fastcall has_bom(void *s2)
{
int v1; // edx
bool v2; // al

if ( !s2 )
return 0LL;
v1 = memcmp(&unk_371, s2, 2uLL);
v2 = 1;
if ( v1 )
v2 = memcmp(&unk_374, s2, 2uLL) == 0;
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(void *s2)
{
int v1; // edx
bool v2; // al

if ( !s2 )
return 0LL;
v1 = memcmp(&unk_371, s2, 2uLL);
v2 = 1;
if ( v1 )
v2 = memcmp(&unk_374, s2, 2uLL) == 0;
return v2;
}

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: size int

variable_types:
result
unsigned short *

return_type: unsigned short *


decompiled_code:
int __fastcall println_utf16(__int64 a1, unsigned int a2)
{
unsigned int v3; // er13
__int64 v4; // rbx
unsigned __int16 v5; // si
bool v6; // al

if ( a2 > 1 )
{
v3 = a2 >> 31;
v4 = 2LL;
do
{
v5 = *(_WORD *)(a1 + 2 * v4 - 2);
if ( !v5 )
break;
printf("%lc", v5);
v6 = (int)a2 > (int)v4++;
}
while ( (unsigned __int8)v3 | v6 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, unsigned int a2)
{
unsigned int v3; // er13
__int64 v4; // rbx
unsigned __int16 v5; // si
bool v6; // al

if ( a2 > 1 )
{
v3 = a2 >> 31;
v4 = 2LL;
do
{
v5 = *(_WORD *)(a1 + 2 * v4 - 2);
if ( !v5 )
break;
printf("%lc", v5);
v6 = (int)a2 > (int)v4++;
}
while ( (unsigned __int8)v3 | v6 );
}
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: i int

return_type: void


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

if ( !src )
return puts("None");
if ( !has_bom(src) )
return puts((const char *)src);
v2 = char_to_utf16(src, a2);
return println_utf16((__int64)v2, a2);
}

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

if ( !src )
return puts("None");
if ( !func0(src) )
return puts((const char *)src);
v2 = func1(src, 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(*(void **)(*(_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(*(void **)(*(_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; } *

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


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

if ( a1 )
result = print_text_frame_text(*(void **)(*(_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(*(void **)(*(_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);
}

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

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


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

v1 = a1;
if ( !a1 )
return puts("None");
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

v1 = a1;
if ( !a1 )
return puts("None");
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; } *

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


btoi

decompiled_code:
__int64 __fastcall btoi(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rdx
__int64 v3; // rsi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rdx
__int64 v3; // rsi
__int64 result; // rax

if ( a2 <= 0 )
return 0LL;
v2 = a1;
v3 = (__int64)&a1[a2 - 1 + 1];
LODWORD(result) = 0;
do
result = (unsigned int)*v2++ | ((_DWORD)result << 8);
while ( v2 != (unsigned __int8 *)v3 );
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

return_type: 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(void *s2)
{
int v1; // edx
bool result; // al

if ( !s2 )
return 0;
v1 = memcmp(&unk_1D1, s2, 2uLL);
result = 1;
if ( v1 )
result = memcmp(&unk_1D4, s2, 2uLL) == 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func5(void *s2)
{
int v1; // edx
bool result; // al

if ( !s2 )
return 0;
v1 = memcmp(&unk_1D1, s2, 2uLL);
result = 1;
if ( v1 )
result = memcmp(&unk_1D4, s2, 2uLL) == 0;
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 *s)
{
char *v1; // rbp
size_t v3; // r13
char *v4; // r12
__int64 i; // rbx

v1 = s;
if ( !string_has_bom(s) )
{
v3 = (int)(2 * strlen(s) + 4);
v4 = (char *)malloc(v3);
*v4 = -1;
v4[1] = -2;
for ( i = 0LL; strlen(s) >= ++i; *(_WORD *)&v4[2 * i] = (unsigned __int8)s[i - 1] )
;
v4[v3 - 2] = 0;
v4[v3 - 1] = 0;
v1 = v4;
}
return v1;
}

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 *

variable_types: i int

return_type: char *


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

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

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

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

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 *s)
{
int v1; // ebp

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

canonical_decompiled_code:
__int64 __fastcall func8(char *s)
{
int v1; // ebp

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

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; // rbp
void *v2; // r12

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; // rbp
void *v2; // r12

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

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


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:
void __fastcall FrameHeader_free(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func4(void *a1)
{
free(a1);
}

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(const char **a1, const char *a2)
{
const char **v2; // rbx
const char **v3; // rbp

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

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

v2 = a1;
v3 = a1;
if ( a1 )
{
while ( 1 )
{
v3 = (const char **)*v2;
if ( !*v2 || !strncmp(*v3, a2, 4uLL) )
break;
v2 = (const char **)v2[2];
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(__int64 a1, const char *a2)
{
__int64 v2; // rbx
const char **v3; // rbp
__m128i *v4; // rdi

v2 = a1;
if ( !a1 )
return 0LL;
while ( 1 )
{
v3 = *(const char ***)v2;
if ( !strncmp(**(const char ***)v2, a2, 4uLL) )
break;
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return 0LL;
}
v4 = *(__m128i **)(v2 + 16);
if ( !v4 )
v4 = (__m128i *)FrameList_new();
*(__m128i *)v2 = _mm_loadu_si128(v4);
*(_QWORD *)(v2 + 16) = v4[1].m128i_i64[0];
free(v4);
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; // rbp
_DWORD *v1; // rax
_DWORD *v2; // rbx

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; // rbp
_DWORD *v1; // rax
_DWORD *v2; // rbx

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, __int64 a2)
{
char v2; // bl
__int64 v3; // rbp
char v4; // r12
const __int32_t **v5; // rax
_BOOL8 result; // rax

v2 = *a1;
if ( *a1 )
{
v3 = 0LL;
while ( 1 )
{
if ( v2 == 42 )
return 1LL;
v4 = *(_BYTE *)(a2 + v3);
if ( !v4 )
break;
if ( v2 != 63 )
{
v5 = _ctype_tolower_loc();
if ( (*v5)[v4] != (*v5)[v2] )
return 0LL;
}
v2 = a1[++v3];
if ( !v2 )
goto LABEL_10;
}
result = 0LL;
}
else
{
v3 = 0LL;
LABEL_10:
result = *(_BYTE *)(a2 + v3) == 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char *a1, __int64 a2)
{
char v2; // bl
__int64 v3; // rbp
char v4; // r12
const __int32_t **v5; // rax
_BOOL8 result; // rax

v2 = *a1;
if ( *a1 )
{
v3 = 0LL;
while ( 1 )
{
if ( v2 == 42 )
return 1LL;
v4 = *(_BYTE *)(a2 + v3);
if ( !v4 )
break;
if ( v2 != 63 )
{
v5 = _ctype_tolower_loc();
if ( (*v5)[v4] != (*v5)[v2] )
return 0LL;
}
v2 = a1[++v3];
if ( !v2 )
goto LABEL_10;
}
result = 0LL;
}
else
{
v3 = 0LL;
LABEL_10:
result = *(_BYTE *)(a2 + v3) == 0;
}
return result;
}

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; // rdx
_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; // rdx
_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: 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)
{
int v3; // eax
struct sockaddr v4; // [rsp+0h] [rbp-18h] BYREF

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

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

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

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; // r13
int v4; // er14
__int64 v5; // rbx

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

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
int result; // eax
__int64 v3; // r13
int v4; // er14
__int64 v5; // rbx

if ( (int)a1 <= 0 || SHIDWORD(a1) <= 0 || !a2 )
return signaler(4LL);
v3 = a2;
v4 = 0;
do
{
putchar(91);
v5 = 0LL;
do
printf("%-10s ", *(const char **)(v3 + 8 * v5++));
while ( SHIDWORD(a1) > (int)v5 );
result = puts("]");
++v4;
v3 += 8 * (a1 >> 32);
}
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:
void __fastcall fusionner(char a1, __int64 a2, int a3, __int64 a4)
{
if ( a1 == 72 )
{
fusHorizontale(a2, a3, a4);
}
else if ( a1 == 86 )
{
fusVerticale(a2, a3, a4);
}
}

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 i; // er13
unsigned int v1; // ebp
int v2; // ebx
int result; // eax

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

canonical_decompiled_code:
int func7()
{
unsigned int i; // er13
unsigned int v1; // ebp
int v2; // ebx
int result; // eax

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

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)
{
_DWORD *v2; // rbx
int v3; // ebp
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1, int a2)
{
_DWORD *v2; // rbx
int v3; // ebp
__int64 result; // rax

if ( a2 > 1 )
{
v2 = a1;
v3 = 0;
do
{
result = func10(v2, (_DWORD *)(2LL * ((_QWORD)a1 + 2 * a2) - 4 - (_QWORD)v2));
++v3;
++v2;
}
while ( v3 < a2 / 2 );
}
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

variable_types: i int


decompiled_code:
int __fastcall affiche_vecteur_int(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

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

canonical_decompiled_code:
int __fastcall func12(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

printf("contenu du vecteur: ");
if ( a2 > 0 )
{
v2 = a1;
do
printf("%4d", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
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");
}


decompiled_code:
__int64 __fastcall get_nbre_domaines(__int64 a1, int a2)
{
int v2; // eax
int v3; // er9
__int64 v4; // rdx
const char *v5; // rax
__int64 v6; // r8
unsigned int v7; // er9

v2 = nombreArguments();
if ( v2 == a2 )
{
puts("Hors du tableau");
v3 = 0;
}
else
{
v3 = 0;
if ( v2 > a2 )
{
v4 = 8LL * a2;
v5 = *(const char **)(a1 + v4);
if ( v5 )
{
v6 = a1 + v4 + 8;
do
{
if ( strcmp(v5, "-C") )
v3 -= (strcmp(v5, "-L") == 0) - 1;
v6 += 8LL;
v5 = *(const char **)(v6 - 8);
}
while ( v5 );
}
else
{
v3 = 0;
}
}
}
if ( a2 )
v7 = v3 - (a2 == 1);
else
v7 = v3 - 2;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // eax
int v3; // er9
__int64 v4; // rdx
const char *v5; // rax
__int64 v6; // r8
unsigned int v7; // er9

v2 = nombreArguments();
if ( v2 == a2 )
{
puts("Hors du tableau");
v3 = 0;
}
else
{
v3 = 0;
if ( v2 > a2 )
{
v4 = 8LL * a2;
v5 = *(const char **)(a1 + v4);
if ( v5 )
{
v6 = a1 + v4 + 8;
do
{
if ( strcmp(v5, "-C") )
v3 -= (strcmp(v5, "-L") == 0) - 1;
v6 += 8LL;
v5 = *(const char **)(v6 - 8);
}
while ( v5 );
}
else
{
v3 = 0;
}
}
}
if ( a2 )
v7 = v3 - (a2 == 1);
else
v7 = v3 - 2;
return v7;
}

original_code:
int get_nbre_domaines(char *const argv[], int pos) {
    int nbdomaine = 0;
    int nbArg = nombreArguments(argv);
    if (pos == nbArg) {
        printf("Hors du tableau\n");
    }
    if (pos < nbArg) {
        while (*(argv + pos)) {
            nbdomaine++;
            if (!(strcmp(*(argv + pos), "-C")) || !(strcmp(*(argv + pos), "-L"))) {
                nbdomaine--;
            }
            argv++;
        }
    }
    if (pos == 0) {
        nbdomaine = nbdomaine - 2;
    }
    if (pos == 1) {
        nbdomaine--;
    }
    return nbdomaine;
}

canonical_original_code:
int get_nbre_domaines(char *argv[], int pos) {
    int nbdomaine = 0;
    int nbArg = nombreArguments(argv);
    if (pos == nbArg) {
        printf("Hors du tableau\n");
    }
    if (pos < nbArg) {
        while (*(argv + pos)) {
            nbdomaine++;
            if (!(strcmp(*(argv + pos), "-C")) || !(strcmp(*(argv + pos), "-L"))) {
                nbdomaine--;
            }
            argv++;
        }
    }
    if (pos == 0) {
        nbdomaine = nbdomaine - 2;
    }
    if (pos == 1) {
        nbdomaine--;
    }
    return nbdomaine;
}

variable_types:
argv
char *[]

variable_types: pos int

variable_types: nbdomaine int

variable_types: nbArg int


decompiled_code:
__int64 __fastcall get_debut(char *src, int *a2)
{
__int64 result; // rax
int v3; // er13
char *v4; // r14
size_t v5; // rdx
void *v6; // rsp
char *v7; // rax
char v8[14]; // [rsp+0h] [rbp-30h] BYREF
char delim[2]; // [rsp+Eh] [rbp-22h] BYREF

if ( !src )
_assert_fail("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 0x36u, "get_debut");
if ( !a2 )
_assert_fail(
"debut!=NULL && \"ECHEC d'une precondition - debut doit etre alloue hors fonction\"",
"mod_domaine.c",
0x37u,
"get_debut");
if ( (unsigned int)chercherDansChaine("(^[0-9]+-$)", src) )
{
v3 = strlen(src);
v4 = (char *)malloc(v3 + 1);
strncpy(v4, src, v3);
*a2 = atoi(v4);
free(v4);
result = 1LL;
}
else if ( (unsigned int)chercherDansChaine("(^[0-9]+-[0-9]+$)", src) )
{
strcpy(delim, "-");
v5 = (int)(strlen(src) + 1);
v6 = alloca(v5);
strncpy(v8, src, v5);
v7 = strtok(v8, delim);
*a2 = atoi(v7);
result = 1LL;
}
else
{
result = chercherDansChaine("(^-{1}[0-9]+$){1}", src);
if ( (_DWORD)result )
{
*a2 = 0;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, int *a2)
{
__int64 result; // rax
int v3; // er13
char *v4; // r14
size_t v5; // rdx
void *v6; // rsp
char *v7; // rax
char v8[14]; // [rsp+0h] [rbp-30h] BYREF
char delim[2]; // [rsp+Eh] [rbp-22h] BYREF

if ( !src )
_assert_fail("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 0x36u, "get_debut");
if ( !a2 )
_assert_fail(
"debut!=NULL && \"ECHEC d'une precondition - debut doit etre alloue hors fonction\"",
"mod_domaine.c",
0x37u,
"get_debut");
if ( (unsigned int)chercherDansChaine("(^[0-9]+-$)", src) )
{
v3 = strlen(src);
v4 = (char *)malloc(v3 + 1);
strncpy(v4, src, v3);
*a2 = atoi(v4);
free(v4);
result = 1LL;
}
else if ( (unsigned int)chercherDansChaine("(^[0-9]+-[0-9]+$)", src) )
{
strcpy(delim, "-");
v5 = (int)(strlen(src) + 1);
v6 = alloca(v5);
strncpy(v8, src, v5);
v7 = strtok(v8, delim);
*a2 = atoi(v7);
result = 1LL;
}
else
{
result = chercherDansChaine("(^-{1}[0-9]+$){1}", src);
if ( (_DWORD)result )
{
*a2 = 0;
result = 1LL;
}
}
return result;
}

original_code:
int get_debut(char *domaine,int *debut){
  ((void) sizeof ((domaine!=((void *)0) && "le domaine est obligatoire") ? 1 : 0), __extension__ ({ if (domaine!=((void *)0) && "le domaine est obligatoire") ; else __assert_fail ("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 54, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((debut!=((void *)0) && "ECHEC d'une precondition - debut doit etre alloue hors fonction") ? 1 : 0), __extension__ ({ if (debut!=((void *)0) && "ECHEC d'une precondition - debut doit etre alloue hors fonction") ; else __assert_fail ("debut!=NULL && \"ECHEC d'une precondition - debut doit etre alloue hors fonction\"", "mod_domaine.c", 55, __extension__ __PRETTY_FUNCTION__); }));
 if (chercherDansChaine("(^[0-9]+-$)",domaine))
 {
  int longueur=strlen(domaine)+1;
        char * debutStr=malloc(longueur*sizeof(char));
        strncpy(debutStr,domaine,longueur-1);
        *debut=(int)atoi(debutStr);
        free(debutStr);
        return 1;
 }
 else{
  if (chercherDansChaine("(^[0-9]+-[0-9]+$)",domaine))
  {
    int longueur=strlen(domaine)+1;
             char delimiteur[2]="-";
             char domaineTab[longueur];
             strncpy(domaineTab,domaine,longueur);
             char * partie=strtok(domaineTab,delimiteur);
             *debut=(int)atoi(partie);
             return 1;
  }
  else{
   if (chercherDansChaine("(^-{1}[0-9]+$){1}",domaine))
   {
    *debut=0;
    return 1;
   }
  }
 }
 return 0;
}

canonical_original_code:
int get_debut(char *domaine, int *debut){
  ((void) sizeof ((domaine!=((void *)0) && "le domaine est obligatoire") ? 1 : 0), __extension__ ({ if (domaine!=((void *)0) && "le domaine est obligatoire") ; else __assert_fail ("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 54, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((debut!=((void *)0) && "ECHEC d'une precondition - debut doit etre alloue hors fonction") ? 1 : 0), __extension__ ({ if (debut!=((void *)0) && "ECHEC d'une precondition - debut doit etre alloue hors fonction") ; else __assert_fail ("debut!=NULL && \"ECHEC d'une precondition - debut doit etre alloue hors fonction\"", "mod_domaine.c", 55, __extension__ __PRETTY_FUNCTION__); }));
 if (chercherDansChaine("(^[0-9]+-$)",domaine))
 {
  int longueur = strlen(domaine)+1;
        char *debutStr = malloc(longueur*sizeof(char));
        strncpy(debutStr,domaine,longueur-1);
        *debut=(int)atoi(debutStr);
        free(debutStr);
        return 1;
 }
 else{
  if (chercherDansChaine("(^[0-9]+-[0-9]+$)",domaine))
  {
    int longueur = strlen(domaine)+1;
             char delimiteur[2] = "-";
             char domaineTab[-1];
             strncpy(domaineTab,domaine,longueur);
             char *partie = strtok(domaineTab,delimiteur);
             *debut=(int)atoi(partie);
             return 1;
  }
  else{
   if (chercherDansChaine("(^-{1}[0-9]+$){1}",domaine))
   {
    *debut=0;
    return 1;
   }
  }
 }
 return 0;
}

variable_types:
domaine
char *

variable_types:
debut
int *

variable_types: longueur int

variable_types:
debutStr
char *

variable_types:
delimiteur
char [2]

variable_types:
domaineTab
char [-1]

variable_types:
partie
char *


decompiled_code:
__int64 __fastcall get_fin(char *src, int *a2, int a3)
{
__int64 result; // rax
size_t v5; // rdx
void *v6; // rsp
char *v7; // rax
size_t v8; // r13
char *v9; // r14
char v10[14]; // [rsp+0h] [rbp-30h] BYREF
char delim[2]; // [rsp+Eh] [rbp-22h] BYREF

if ( !src )
_assert_fail("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 0x5Fu, "get_fin");
if ( !a2 )
_assert_fail(
"fin!=NULL && \"ECHEC d'une precondition - fin doit etre alloue hors fonction\"",
"mod_domaine.c",
0x60u,
"get_fin");
if ( (unsigned int)chercherDansChaine("(^[0-9]+-$)", src) )
{
*a2 = a3;
result = 1LL;
}
else if ( (unsigned int)chercherDansChaine("(^-{1}[0-9]+$){1}", src) )
{
v8 = (int)(strlen(src) + 1);
v9 = (char *)malloc(v8);
strncpy(v9, src + 1, v8);
*a2 = atoi(v9);
free(v9);
result = 1LL;
}
else
{
result = chercherDansChaine("(^[0-9]+-[0-9]+$)", src);
if ( (_DWORD)result )
{
strcpy(delim, "-");
v5 = (int)(strlen(src) + 1);
v6 = alloca(v5);
strncpy(v10, src, v5);
strtok(v10, delim);
v7 = strtok(0LL, delim);
*a2 = atoi(v7);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, int *a2, int a3)
{
__int64 result; // rax
size_t v5; // rdx
void *v6; // rsp
char *v7; // rax
size_t v8; // r13
char *v9; // r14
char v10[14]; // [rsp+0h] [rbp-30h] BYREF
char delim[2]; // [rsp+Eh] [rbp-22h] BYREF

if ( !src )
_assert_fail("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 0x5Fu, "get_fin");
if ( !a2 )
_assert_fail(
"fin!=NULL && \"ECHEC d'une precondition - fin doit etre alloue hors fonction\"",
"mod_domaine.c",
0x60u,
"get_fin");
if ( (unsigned int)chercherDansChaine("(^[0-9]+-$)", src) )
{
*a2 = a3;
result = 1LL;
}
else if ( (unsigned int)chercherDansChaine("(^-{1}[0-9]+$){1}", src) )
{
v8 = (int)(strlen(src) + 1);
v9 = (char *)malloc(v8);
strncpy(v9, src + 1, v8);
*a2 = atoi(v9);
free(v9);
result = 1LL;
}
else
{
result = chercherDansChaine("(^[0-9]+-[0-9]+$)", src);
if ( (_DWORD)result )
{
strcpy(delim, "-");
v5 = (int)(strlen(src) + 1);
v6 = alloca(v5);
strncpy(v10, src, v5);
strtok(v10, delim);
v7 = strtok(0LL, delim);
*a2 = atoi(v7);
result = 1LL;
}
}
return result;
}

original_code:
int get_fin(char *domaine,int *fin,int max){
 ((void) sizeof ((domaine!=((void *)0) && "le domaine est obligatoire") ? 1 : 0), __extension__ ({ if (domaine!=((void *)0) && "le domaine est obligatoire") ; else __assert_fail ("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 95, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((fin!=((void *)0) && "ECHEC d'une precondition - fin doit etre alloue hors fonction") ? 1 : 0), __extension__ ({ if (fin!=((void *)0) && "ECHEC d'une precondition - fin doit etre alloue hors fonction") ; else __assert_fail ("fin!=NULL && \"ECHEC d'une precondition - fin doit etre alloue hors fonction\"", "mod_domaine.c", 96, __extension__ __PRETTY_FUNCTION__); }));
    if (chercherDansChaine("(^[0-9]+-$)",domaine))
    {
     *fin=(int)max;
     return 1;
    }
    else{
     if (chercherDansChaine("(^-{1}[0-9]+$){1}",domaine))
     {
              int longueur=strlen(domaine)+1;
                    char * finStr=malloc(longueur*sizeof(char));
                    strncpy(finStr,domaine+1,longueur);
                    *fin=(int)atoi(finStr);
                    free(finStr);
                    return 1;
     }
     else{
      if (chercherDansChaine("(^[0-9]+-[0-9]+$)",domaine))
      {
       int longueur=strlen(domaine)+1;
                char delimiteur[2]="-";
                   char domaineTab[longueur];
                   strncpy(domaineTab,domaine,longueur);
                   char * partie=strtok(domaineTab,delimiteur);
                   partie=strtok(((void *)0),delimiteur);
                   *fin=(int)atoi(partie);
                   return 1;
      }
     }
    }
    return 0;
}

canonical_original_code:
int get_fin(char *domaine, int *fin, int max){
 ((void) sizeof ((domaine!=((void *)0) && "le domaine est obligatoire") ? 1 : 0), __extension__ ({ if (domaine!=((void *)0) && "le domaine est obligatoire") ; else __assert_fail ("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 95, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((fin!=((void *)0) && "ECHEC d'une precondition - fin doit etre alloue hors fonction") ? 1 : 0), __extension__ ({ if (fin!=((void *)0) && "ECHEC d'une precondition - fin doit etre alloue hors fonction") ; else __assert_fail ("fin!=NULL && \"ECHEC d'une precondition - fin doit etre alloue hors fonction\"", "mod_domaine.c", 96, __extension__ __PRETTY_FUNCTION__); }));
    if (chercherDansChaine("(^[0-9]+-$)",domaine))
    {
     *fin=(int)max;
     return 1;
    }
    else{
     if (chercherDansChaine("(^-{1}[0-9]+$){1}",domaine))
     {
              int longueur = strlen(domaine)+1;
                    char *finStr = malloc(longueur*sizeof(char));
                    strncpy(finStr,domaine+1,longueur);
                    *fin=(int)atoi(finStr);
                    free(finStr);
                    return 1;
     }
     else{
      if (chercherDansChaine("(^[0-9]+-[0-9]+$)",domaine))
      {
       int longueur = strlen(domaine)+1;
                char delimiteur[2] = "-";
                   char domaineTab[-1];
                   strncpy(domaineTab,domaine,longueur);
                   char *partie = strtok(domaineTab,delimiteur);
                   partie=strtok(((void *)0),delimiteur);
                   *fin=(int)atoi(partie);
                   return 1;
      }
     }
    }
    return 0;
}

variable_types:
fin
int *

variable_types: max int

variable_types:
finStr
char *


nombreArguments

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

if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
++a1;
}
while ( *a1 );
return result;
}

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

if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
++a1;
}
while ( *a1 );
return result;
}

original_code:
int nombreArguments(char *const argv[]){
 int nombre=0;
 while(*argv){
  nombre++;
  argv++;
 }
 return nombre;
}

canonical_original_code:
int nombreArguments(char *argv[]){
 int nombre = 0;
 while(*argv){
  nombre++;
  argv++;
 }
 return nombre;
}

variable_types: nombre int


chercherOption

decompiled_code:
__int64 __fastcall chercherOption(const char **a1, char a2)
{
char v2; // al
const char *v3; // rsi
__int64 v4; // rdx
unsigned int v5; // er9
int v6; // er8
const char *v7; // rsi
__int64 v8; // rdx
const char *v9; // rsi
__int64 v10; // rdx
const char *v11; // rsi
__int64 v12; // rdx

v2 = toupper(a2);
switch ( v2 )
{
case 'L':
v7 = *a1;
if ( !*a1 )
return 0;
v8 = 0LL;
v5 = 0;
v6 = 0;
do
{
if ( !strcmp(v7, "-L") )
{
++v6;
v5 = v8;
}
v7 = a1[++v8];
}
while ( v7 );
break;
case 'C':
v9 = *a1;
if ( !*a1 )
return 0;
v10 = 0LL;
v5 = 0;
v6 = 0;
do
{
if ( !strcmp(v9, "-C") )
{
++v6;
v5 = v10;
}
v9 = a1[++v10];
}
while ( v9 );
break;
case 'V':
v11 = *a1;
if ( !*a1 )
return 0;
v12 = 0LL;
v5 = 0;
v6 = 0;
do
{
if ( !strcmp(v11, "-V") )
{
++v6;
v5 = v12;
}
v11 = a1[++v12];
}
while ( v11 );
break;
case 'H':
v3 = *a1;
if ( !*a1 )
return 0;
v4 = 0LL;
v5 = 0;
v6 = 0;
do
{
if ( !strcmp(v3, "-H") )
{
++v6;
v5 = v4;
}
v3 = a1[++v4];
}
while ( v3 );
break;
default:
signaler(3LL);
return 0;
}
if ( v6 > 1 )
{
signaler(3LL);
v5 = -1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char **a1, char a2)
{
char v2; // al
const char *v3; // rsi
__int64 v4; // rdx
unsigned int v5; // er9
int v6; // er8
const char *v7; // rsi
__int64 v8; // rdx
const char *v9; // rsi
__int64 v10; // rdx
const char *v11; // rsi
__int64 v12; // rdx

v2 = toupper(a2);
switch ( v2 )
{
case 'L':
v7 = *a1;
if ( !*a1 )
return 0;
v8 = 0LL;
v5 = 0;
v6 = 0;
do
{
if ( !strcmp(v7, "-L") )
{
++v6;
v5 = v8;
}
v7 = a1[++v8];
}
while ( v7 );
break;
case 'C':
v9 = *a1;
if ( !*a1 )
return 0;
v10 = 0LL;
v5 = 0;
v6 = 0;
do
{
if ( !strcmp(v9, "-C") )
{
++v6;
v5 = v10;
}
v9 = a1[++v10];
}
while ( v9 );
break;
case 'V':
v11 = *a1;
if ( !*a1 )
return 0;
v12 = 0LL;
v5 = 0;
v6 = 0;
do
{
if ( !strcmp(v11, "-V") )
{
++v6;
v5 = v12;
}
v11 = a1[++v12];
}
while ( v11 );
break;
case 'H':
v3 = *a1;
if ( !*a1 )
return 0;
v4 = 0LL;
v5 = 0;
v6 = 0;
do
{
if ( !strcmp(v3, "-H") )
{
++v6;
v5 = v4;
}
v3 = a1[++v4];
}
while ( v3 );
break;
default:
signaler(3LL);
return 0;
}
if ( v6 > 1 )
{
signaler(3LL);
v5 = -1;
}
return v5;
}

original_code:
int chercherOption(char *const argv[],char option){
 int i=0;
 int occurences=0;
 int pos=0;
 option=toupper(option);
 if (option=='L')
 {
   while (*argv) {
            if (!(strcmp(*argv, "-L"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else if (option=='C')
 {
   while (*argv) {
            if (!(strcmp(*argv, "-C"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else if (option=='V')
 {
  while (*argv) {
            if (!(strcmp(*argv, "-V"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else if (option=='H')
 {
  while (*argv) {
            if (!(strcmp(*argv, "-H"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else{
  signaler(3);
 }
 if (occurences>1)
 {
  signaler(3);
  return -1;
 }
 return pos;
}

canonical_original_code:
int chercherOption(char *argv[], char option){
 int i = 0;
 int occurences = 0;
 int pos = 0;
 option=toupper(option);
 if (option=='L')
 {
   while (*argv) {
            if (!(strcmp(*argv, "-L"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else if (option=='C')
 {
   while (*argv) {
            if (!(strcmp(*argv, "-C"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else if (option=='V')
 {
  while (*argv) {
            if (!(strcmp(*argv, "-V"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else if (option=='H')
 {
  while (*argv) {
            if (!(strcmp(*argv, "-H"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else{
  signaler(3);
 }
 if (occurences>1)
 {
  signaler(3);
  return -1;
 }
 return pos;
}

variable_types: option char

variable_types: occurences int


decompiled_code:
__int64 __fastcall compteur_Lignes(_QWORD *a1, int a2)
{
_QWORD *v2; // rax
unsigned int v3; // edx

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = 0;
do
v3 -= (*v2++ == 0LL) - 1;
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
return v3;
}

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

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = 0;
do
v3 -= (*v2++ == 0LL) - 1;
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
return v3;
}

original_code:
int compteur_Lignes(char ** vecteur, int nbL) {
    int nb = 0;
    int i = 0;
    for (; i < nbL; i++) {
        if (vecteur[i] != 0) {
            nb++;
        }
    }
    return nb;
}

canonical_original_code:
int compteur_Lignes(char **vecteur, int nbL) {
    int nb = 0;
    int i = 0;
    for (; i < nbL; i++) {
        if (vecteur[i] != 0) {
            nb++;
        }
    }
    return nb;
}

variable_types:
vecteur
char **

variable_types: nbL int

variable_types: nb int

variable_types: i int


signaler

decompiled_code:
size_t __fastcall signaler(int a1)
{
size_t result; // rax

switch ( a1 )
{
case 0:
result = fwrite("Erreur d'ouverture du fichier.\n", 1uLL, 0x1FuLL, stderr);
break;
case 1:
result = fwrite("Le fichier ne comporte aucune donnee.\n", 1uLL, 0x26uLL, stderr);
break;
case 2:
result = fwrite("Erreur de syntaxe dans un domaine.\n", 1uLL, 0x23uLL, stderr);
break;
case 3:
result = fwrite("Erreur dans une option.\n", 1uLL, 0x18uLL, stderr);
break;
case 4:
result = fwrite("Tableau vide!\n", 1uLL, 0xEuLL, stderr);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(int a1)
{
size_t result; // rax

switch ( a1 )
{
case 0:
result = fwrite("Erreur d'ouverture du fichier.\n", 1uLL, 0x1FuLL, stderr);
break;
case 1:
result = fwrite("Le fichier ne comporte aucune donnee.\n", 1uLL, 0x26uLL, stderr);
break;
case 2:
result = fwrite("Erreur de syntaxe dans un domaine.\n", 1uLL, 0x23uLL, stderr);
break;
case 3:
result = fwrite("Erreur dans une option.\n", 1uLL, 0x18uLL, stderr);
break;
case 4:
result = fwrite("Tableau vide!\n", 1uLL, 0xEuLL, stderr);
break;
default:
return result;
}
return result;
}

original_code:
void signaler(int code){
 switch (code)
    {
        case 0 :
            fprintf(stderr,"Erreur d'ouverture du fichier.\n");
        break;
        case 2 :
            fprintf(stderr,"Erreur de syntaxe dans un domaine.\n");
            break;
        case 3 :
                fprintf(stderr,"Erreur dans une option.\n");
                break;
        case 1 :
            fprintf(stderr,"Le fichier ne comporte aucune donnee.\n");
            break;
        case 4 :
            fprintf(stderr,"Tableau vide!\n");
            break;
        default :
            break;
    }
}

variable_types: code int