decompiled_code:
__int64 __fastcall us_midi_parser_system_byte(__int64 a1, char a2, _BYTE *a3)
{
__int64 result; // rax

if ( (unsigned __int8)a2 < 0xF0u )
{
LABEL_12:
*(_DWORD *)(a1 + 32) = 0;
result = 0LL;
}
else
{
switch ( a2 )
{
case -16:
*(_DWORD *)(a1 + 32) = 5;
us_midi_sysex_start(*(_QWORD *)(a1 + 24));
result = 0LL;
break;
case -15:
us_midi_msg_set_status((_BYTE *)(a1 + 16), 241);
*(_DWORD *)(a1 + 32) = 4;
result = 0LL;
break;
case -14:
*(_DWORD *)(a1 + 32) = 2;
us_midi_msg_set_status((_BYTE *)(a1 + 16), 242);
result = 0LL;
break;
case -13:
*(_DWORD *)(a1 + 32) = 1;
us_midi_msg_set_status((_BYTE *)(a1 + 16), 243);
result = 0LL;
break;
case -12:
case -11:
case -3:
goto LABEL_12;
case -10:
case -8:
case -7:
case -6:
case -5:
case -4:
case -2:
us_midi_msg_set_status(a3, a2);
result = 1LL;
break;
case -9:
result = 0LL;
if ( *(_DWORD *)(a1 + 32) == 5 )
{
*(_DWORD *)(a1 + 32) = 0;
us_midi_sysex_end(*(_QWORD *)(a1 + 24));
us_midi_msg_set_status(a3, 240);
result = 1LL;
}
break;
case -1:
*(_DWORD *)(a1 + 32) = 0;
result = 0LL;
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, char a2, _BYTE *a3)
{
__int64 result; // rax

if ( (unsigned __int8)a2 < 0xF0u )
{
LABEL_12:
*(_DWORD *)(a1 + 32) = 0;
result = 0LL;
}
else
{
switch ( a2 )
{
case -16:
*(_DWORD *)(a1 + 32) = 5;
func17(*(_QWORD *)(a1 + 24));
result = 0LL;
break;
case -15:
func7((_BYTE *)(a1 + 16), 241);
*(_DWORD *)(a1 + 32) = 4;
result = 0LL;
break;
case -14:
*(_DWORD *)(a1 + 32) = 2;
func7((_BYTE *)(a1 + 16), 242);
result = 0LL;
break;
case -13:
*(_DWORD *)(a1 + 32) = 1;
func7((_BYTE *)(a1 + 16), 243);
result = 0LL;
break;
case -12:
case -11:
case -3:
goto LABEL_12;
case -10:
case -8:
case -7:
case -6:
case -5:
case -4:
case -2:
func7(a3, a2);
result = 1LL;
break;
case -9:
result = 0LL;
if ( *(_DWORD *)(a1 + 32) == 5 )
{
*(_DWORD *)(a1 + 32) = 0;
func13(*(_QWORD *)(a1 + 24));
func7(a3, 240);
result = 1LL;
}
break;
case -1:
*(_DWORD *)(a1 + 32) = 0;
result = 0LL;
break;
}
}
return result;
}

original_code:
_Bool us_midi_parser_system_byte( us_midi_parser_t *self, uint8_t b, us_midi_msg_t *msg )
{
    switch ( b )
    {
    case US_MIDI_RESET:
    {
        self->m_state = US_MIDI_PARSER_STATE_FIND_STATUS;
        return 0;
    }
    case US_MIDI_SYSEX_START:
    {
        self->m_state = US_MIDI_PARSER_STATE_SYSEX_DATA;
        us_midi_sysex_start( self->m_sysex );
        return 0;
    }
    case US_MIDI_SYSEX_END:
    {
        if ( self->m_state != US_MIDI_PARSER_STATE_SYSEX_DATA )
        {
            return 0;
        }
        self->m_state = US_MIDI_PARSER_STATE_FIND_STATUS;
        us_midi_sysex_end( self->m_sysex );
        us_midi_msg_set_status( msg, US_MIDI_SYSEX_START );
        return 1;
    }
    case US_MIDI_MTC:
    {
        us_midi_msg_set_status( &self->m_tmp_msg, US_MIDI_MTC );
        self->m_state = US_MIDI_PARSER_STATE_FIRST_OF_ONE_NORUN;
        return 0;
    }
    case US_MIDI_SONG_POSITION:
    {
        self->m_state = US_MIDI_PARSER_STATE_FIRST_OF_TWO;
        us_midi_msg_set_status( &self->m_tmp_msg, US_MIDI_SONG_POSITION );
        return 0;
    }
    case US_MIDI_SONG_SELECT:
    {
        self->m_state = US_MIDI_PARSER_STATE_FIRST_OF_ONE;
        us_midi_msg_set_status( &self->m_tmp_msg, US_MIDI_SONG_SELECT );
        return 0;
    }
    case US_MIDI_TUNE_REQUEST:
    case US_MIDI_TIMING_CLOCK:
    case US_MIDI_MEASURE_END:
    case US_MIDI_START:
    case US_MIDI_CONTINUE:
    case US_MIDI_STOP:
    case US_MIDI_ACTIVE_SENSE:
    {
        us_midi_msg_set_status( msg, b );
        return 1;
    }
    default:
    {
        self->m_state = US_MIDI_PARSER_STATE_FIND_STATUS;
        return 0;
    }
    }
}

canonical_original_code:
_Bool us_midi_parser_system_byte(struct us_midi_parser_s *self, unsigned char b, struct us_midi_msg_s *msg)
{
    switch ( b )
    {
    case US_MIDI_RESET:
    {
        self->m_state = US_MIDI_PARSER_STATE_FIND_STATUS;
        return 0;
    }
    case US_MIDI_SYSEX_START:
    {
        self->m_state = US_MIDI_PARSER_STATE_SYSEX_DATA;
        us_midi_sysex_start( self->m_sysex );
        return 0;
    }
    case US_MIDI_SYSEX_END:
    {
        if ( self->m_state != US_MIDI_PARSER_STATE_SYSEX_DATA )
        {
            return 0;
        }
        self->m_state = US_MIDI_PARSER_STATE_FIND_STATUS;
        us_midi_sysex_end( self->m_sysex );
        us_midi_msg_set_status( msg, US_MIDI_SYSEX_START );
        return 1;
    }
    case US_MIDI_MTC:
    {
        us_midi_msg_set_status( &self->m_tmp_msg, US_MIDI_MTC );
        self->m_state = US_MIDI_PARSER_STATE_FIRST_OF_ONE_NORUN;
        return 0;
    }
    case US_MIDI_SONG_POSITION:
    {
        self->m_state = US_MIDI_PARSER_STATE_FIRST_OF_TWO;
        us_midi_msg_set_status( &self->m_tmp_msg, US_MIDI_SONG_POSITION );
        return 0;
    }
    case US_MIDI_SONG_SELECT:
    {
        self->m_state = US_MIDI_PARSER_STATE_FIRST_OF_ONE;
        us_midi_msg_set_status( &self->m_tmp_msg, US_MIDI_SONG_SELECT );
        return 0;
    }
    case US_MIDI_TUNE_REQUEST:
    case US_MIDI_TIMING_CLOCK:
    case US_MIDI_MEASURE_END:
    case US_MIDI_START:
    case US_MIDI_CONTINUE:
    case US_MIDI_STOP:
    case US_MIDI_ACTIVE_SENSE:
    {
        us_midi_msg_set_status( msg, b );
        return 1;
    }
    default:
    {
        self->m_state = US_MIDI_PARSER_STATE_FIND_STATUS;
        return 0;
    }
    }
}

variable_types:
msg
struct us_midi_msg_s *

user_defined_types: enum us_midi_parser_state_t { US_MIDI_PARSER_STATE_FIND_STATUS=0, US_MIDI_PARSER_STATE_FIRST_OF_ONE=1, US_MIDI_PARSER_STATE_FIRST_OF_TWO=2, US_MIDI_PARSER_STATE_SECOND_OF_TWO=3, US_MIDI_PARSER_STATE_FIRST_OF_ONE_NORUN=4, US_MIDI_PARSER_STATE_SYSEX_DATA=5 }


repo: jdkoftinoff/microsupport

decompiled_code:
__int64 __fastcall us_midi_parser_status_byte(__int64 a1, char a2)
{
char v2; // al

v2 = us_midi_get_message_length(a2);
if ( v2 == 2 )
{
*(_DWORD *)(a1 + 32) = 1;
us_midi_msg_set_status((_BYTE *)(a1 + 16), a2);
}
else if ( v2 == 3 )
{
*(_DWORD *)(a1 + 32) = 2;
us_midi_msg_set_status((_BYTE *)(a1 + 16), a2);
}
else
{
*(_DWORD *)(a1 + 32) = 0;
us_midi_msg_set_status((_BYTE *)(a1 + 16), 0);
}
return 0LL;
}

original_code:
_Bool us_midi_parser_status_byte( us_midi_parser_t *self, uint8_t b, us_midi_msg_t *msg )
{
    int8_t len = us_midi_get_message_length( b );
    (void)msg;
    if ( len == 2 )
    {
        self->m_state = US_MIDI_PARSER_STATE_FIRST_OF_ONE;
        us_midi_msg_set_status( &self->m_tmp_msg, b );
    }
    else if ( len == 3 )
    {
        self->m_state = US_MIDI_PARSER_STATE_FIRST_OF_TWO;
        us_midi_msg_set_status( &self->m_tmp_msg, b );
    }
    else
    {
        self->m_state = US_MIDI_PARSER_STATE_FIND_STATUS;
        us_midi_msg_set_status( &self->m_tmp_msg, 0 );
    }
    return 0;
}

canonical_original_code:
_Bool us_midi_parser_status_byte(struct us_midi_parser_s *self, unsigned char b, struct us_midi_msg_s *msg)
{
    char len = us_midi_get_message_length( b );
    (void)msg;
    if ( len == 2 )
    {
        self->m_state = US_MIDI_PARSER_STATE_FIRST_OF_ONE;
        us_midi_msg_set_status( &self->m_tmp_msg, b );
    }
    else if ( len == 3 )
    {
        self->m_state = US_MIDI_PARSER_STATE_FIRST_OF_TWO;
        us_midi_msg_set_status( &self->m_tmp_msg, b );
    }
    else
    {
        self->m_state = US_MIDI_PARSER_STATE_FIND_STATUS;
        us_midi_msg_set_status( &self->m_tmp_msg, 0 );
    }
    return 0;
}

variable_types: struct us_midi_parser_s { void (*destroy)(struct us_midi_parser_s *self); struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *m_allocator; struct us_midi_msg_s { unsigned char status; unsigned char byte1; unsigned char byte2; unsigned char byte3; } m_tmp_msg; struct us_midi_sysex_s { void (*destroy)(struct us_midi_sysex_s *self); struct us_allocator_s *m_allocator; struct us_buffer_s { void (*destroy)(struct us_buffer_s *self); struct us_allocator_s *m_allocator; unsigned char *m_buffer; unsigned long m_next_in; unsigned long m_next_out; unsigned long m_max_length; } *m_buffer; } *m_sysex; enum us_midi_parser_state_t { US_MIDI_PARSER_STATE_FIND_STATUS=0, US_MIDI_PARSER_STATE_FIRST_OF_ONE=1, US_MIDI_PARSER_STATE_FIRST_OF_TWO=2, US_MIDI_PARSER_STATE_SECOND_OF_TWO=3, US_MIDI_PARSER_STATE_FIRST_OF_ONE_NORUN=4, US_MIDI_PARSER_STATE_SYSEX_DATA=5 } m_state; } *

variable_types:
b
unsigned char

variable_types: len char

user_defined_types: struct us_midi_parser_s { void (*destroy)(struct us_midi_parser_s *self); struct us_allocator_s *m_allocator; struct us_midi_msg_s m_tmp_msg; struct us_midi_sysex_s *m_sysex; enum us_midi_parser_state_t m_state; }

user_defined_types: struct us_midi_sysex_s { void (*destroy)(struct us_midi_sysex_s *self); struct us_allocator_s *m_allocator; struct us_buffer_s *m_buffer; }


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

switch ( *(_DWORD *)(a1 + 32) )
{
case 0:
result = 0LL;
break;
case 1:
us_midi_msg_set_byte1(a1 + 16, a2);
*a3 = *(_DWORD *)(a1 + 16);
result = 1LL;
break;
case 2:
us_midi_msg_set_byte1(a1 + 16, a2);
*(_DWORD *)(a1 + 32) = 3;
result = 0LL;
break;
case 3:
us_midi_msg_set_byte2(a1 + 16, a2);
*(_DWORD *)(a1 + 32) = 2;
*a3 = *(_DWORD *)(a1 + 16);
result = 1LL;
break;
case 4:
us_midi_msg_set_byte1(a1 + 16, a2);
*(_DWORD *)(a1 + 32) = 0;
*a3 = *(_DWORD *)(a1 + 16);
result = 1LL;
break;
case 5:
us_midi_sysex_put_byte(*(_QWORD *)(a1 + 24), a2);
result = 0LL;
break;
default:
*(_DWORD *)(a1 + 32) = 0;
result = 0LL;
break;
}
return result;
}

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

switch ( *(_DWORD *)(a1 + 32) )
{
case 0:
result = 0LL;
break;
case 1:
func8(a1 + 16, a2);
*a3 = *(_DWORD *)(a1 + 16);
result = 1LL;
break;
case 2:
func8(a1 + 16, a2);
*(_DWORD *)(a1 + 32) = 3;
result = 0LL;
break;
case 3:
func9(a1 + 16, a2);
*(_DWORD *)(a1 + 32) = 2;
*a3 = *(_DWORD *)(a1 + 16);
result = 1LL;
break;
case 4:
func8(a1 + 16, a2);
*(_DWORD *)(a1 + 32) = 0;
*a3 = *(_DWORD *)(a1 + 16);
result = 1LL;
break;
case 5:
func12(*(_QWORD *)(a1 + 24), a2);
result = 0LL;
break;
default:
*(_DWORD *)(a1 + 32) = 0;
result = 0LL;
break;
}
return result;
}

original_code:
_Bool us_midi_parser_data_byte( us_midi_parser_t *self, uint8_t b, us_midi_msg_t *msg )
{
    switch ( self->m_state )
    {
    case US_MIDI_PARSER_STATE_FIND_STATUS:
    {
        return 0;
    }
    case US_MIDI_PARSER_STATE_FIRST_OF_ONE:
    {
        us_midi_msg_set_byte1( &self->m_tmp_msg, b );
        *msg = self->m_tmp_msg;
        return 1;
    }
    case US_MIDI_PARSER_STATE_FIRST_OF_TWO:
    {
        us_midi_msg_set_byte1( &self->m_tmp_msg, b );
        self->m_state = US_MIDI_PARSER_STATE_SECOND_OF_TWO;
        return 0;
    }
    case US_MIDI_PARSER_STATE_SECOND_OF_TWO:
    {
        us_midi_msg_set_byte2( &self->m_tmp_msg, b );
        self->m_state = US_MIDI_PARSER_STATE_FIRST_OF_TWO;
        *msg = self->m_tmp_msg;
        return 1;
    }
    case US_MIDI_PARSER_STATE_FIRST_OF_ONE_NORUN:
    {
        us_midi_msg_set_byte1( &self->m_tmp_msg, b );
        self->m_state = US_MIDI_PARSER_STATE_FIND_STATUS;
        *msg = self->m_tmp_msg;
        return 1;
    }
    case US_MIDI_PARSER_STATE_SYSEX_DATA:
    {
        us_midi_sysex_put_byte( self->m_sysex, b );
        return 0;
    }
    default:
    {
        self->m_state = US_MIDI_PARSER_STATE_FIND_STATUS;
        return 0;
    }
    }
    return 0;
}

canonical_original_code:
_Bool us_midi_parser_data_byte(struct us_midi_parser_s *self, unsigned char b, struct us_midi_msg_s *msg)
{
    switch ( self->m_state )
    {
    case US_MIDI_PARSER_STATE_FIND_STATUS:
    {
        return 0;
    }
    case US_MIDI_PARSER_STATE_FIRST_OF_ONE:
    {
        us_midi_msg_set_byte1( &self->m_tmp_msg, b );
        *msg = self->m_tmp_msg;
        return 1;
    }
    case US_MIDI_PARSER_STATE_FIRST_OF_TWO:
    {
        us_midi_msg_set_byte1( &self->m_tmp_msg, b );
        self->m_state = US_MIDI_PARSER_STATE_SECOND_OF_TWO;
        return 0;
    }
    case US_MIDI_PARSER_STATE_SECOND_OF_TWO:
    {
        us_midi_msg_set_byte2( &self->m_tmp_msg, b );
        self->m_state = US_MIDI_PARSER_STATE_FIRST_OF_TWO;
        *msg = self->m_tmp_msg;
        return 1;
    }
    case US_MIDI_PARSER_STATE_FIRST_OF_ONE_NORUN:
    {
        us_midi_msg_set_byte1( &self->m_tmp_msg, b );
        self->m_state = US_MIDI_PARSER_STATE_FIND_STATUS;
        *msg = self->m_tmp_msg;
        return 1;
    }
    case US_MIDI_PARSER_STATE_SYSEX_DATA:
    {
        us_midi_sysex_put_byte( self->m_sysex, b );
        return 0;
    }
    default:
    {
        self->m_state = US_MIDI_PARSER_STATE_FIND_STATUS;
        return 0;
    }
    }
    return 0;
}

user_defined_types: struct us_midi_msg_s { unsigned char status; unsigned char byte1; unsigned char byte2; unsigned char byte3; }

user_defined_types: struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); }

user_defined_types: struct us_buffer_s { void (*destroy)(struct us_buffer_s *self); struct us_allocator_s *m_allocator; unsigned char *m_buffer; unsigned long m_next_in; unsigned long m_next_out; unsigned long m_max_length; }


decompiled_code:
__int64 __fastcall us_midi_parser_parse(__int64 a1, char a2, _BYTE *a3)
{
us_midi_msg_init(a3);
if ( a2 >= 0 )
return us_midi_parser_data_byte(a1, a2, a3);
if ( (a2 & 0xF0) == 0xF0 )
return us_midi_parser_system_byte(a1, a2, a3);
us_midi_parser_status_byte(a1, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1, char a2, _BYTE *a3)
{
func5(a3);
if ( a2 >= 0 )
return func24(a1, a2, a3);
if ( (a2 & 0xF0) == 0xF0 )
return func22(a1, a2, a3);
func23(a1, a2);
return 0LL;
}

original_code:
_Bool us_midi_parser_parse( us_midi_parser_t *self, uint8_t b, us_midi_msg_t *msg )
{
    us_midi_msg_init( msg );
    if ( b & 0x80 )
    {
        uint8_t status = ( uint8_t )( b & 0xf0 );
        if ( status == 0xf0 )
        {
            return us_midi_parser_system_byte( self, b, msg );
        }
        else
        {
            us_midi_parser_status_byte( self, b, msg );
            return 0;
        }
    }
    else
    {
        return us_midi_parser_data_byte( self, b, msg );
    }
}

canonical_original_code:
_Bool us_midi_parser_parse(struct us_midi_parser_s *self, unsigned char b, struct us_midi_msg_s *msg)
{
    us_midi_msg_init( msg );
    if ( b & 0x80 )
    {
        unsigned char status = ( uint8_t )( b & 0xf0 );
        if ( status == 0xf0 )
        {
            return us_midi_parser_system_byte( self, b, msg );
        }
        else
        {
            us_midi_parser_status_byte( self, b, msg );
            return 0;
        }
    }
    else
    {
        return us_midi_parser_data_byte( self, b, msg );
    }
}

variable_types:
status
unsigned char


decompiled_code:
__int64 __fastcall us_buffer_readable_count(_QWORD *a1)
{
return (a1[3] + a1[5] - a1[4]) % a1[5];
}

original_code:
static inline size_t us_buffer_readable_count( const us_buffer_t *self )
{
    return ( self->m_next_in - self->m_next_out + self->m_max_length ) % self->m_max_length;
}

canonical_original_code:
static inline unsigned long us_buffer_readable_count(struct us_buffer_s *self)
{
    return ( self->m_next_in - self->m_next_out + self->m_max_length ) % self->m_max_length;
}

variable_types: struct us_buffer_s { void (*destroy)(struct us_buffer_s *self); struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *m_allocator; unsigned char *m_buffer; unsigned long m_next_in; unsigned long m_next_out; unsigned long m_max_length; } *

return_type: unsigned long


decompiled_code:
__int64 __fastcall test_unflatten(__int64 a1, _QWORD *a2, __int64 a3)
{
unsigned int v4; // ebp
__int64 v5; // rax
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // r13
unsigned int v9; // er12
unsigned int v10; // eax
unsigned int v11; // er14
__int64 v12; // r12
__int64 v13; // rax
__int64 v14; // r13

if ( us_log_level > 3 )
us_log_debug_proc("At '%s':%d function '%s'", "../../../src/us_test_osc_msg_main.c", 52LL, "test_unflatten");
if ( us_log_level > 2 )
us_log_info_proc("unflattening message");
v4 = us_osc_msg_is_msg_bundle(a2);
if ( (_BYTE)v4 )
{
if ( us_log_level > 2 )
us_log_info_proc("unflattening bundle");
v5 = us_buffer_readable_count(a2);
v6 = us_osc_msg_bundle_unflatten(a1, a2, v5, 0LL);
if ( v6 )
{
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "Parsed bundle: \n");
(*(void (__fastcall **)(__int64, __int64))(v6 + 16))(v6, a3);
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "\n");
v7 = us_buffer_create(a1, 4096LL);
v8 = v7;
if ( v7 )
{
v9 = (*(__int64 (__fastcall **)(__int64, __int64, _QWORD))(v6 + 24))(v6, v7, 0LL);
if ( (_BYTE)v9 )
{
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "Flattened message buffer contents:\n");
us_buffer_print(v8, a3);
v4 = v9;
}
}
}
else
{
v4 = 0;
}
}
else
{
v10 = us_osc_msg_is_msg(a2);
v11 = v10;
if ( (_BYTE)v10 )
{
if ( us_log_level > 2 )
us_log_info_proc("unflattening message");
v12 = us_osc_msg_unflatten(a1, a2, 0LL);
if ( v12 )
{
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "Parsed message: \n");
(*(void (__fastcall **)(__int64, __int64))(v12 + 16))(v12, a3);
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "\n");
v13 = us_buffer_create(a1, 4096LL);
v14 = v13;
v4 = v11;
if ( v13 )
{
v4 = (*(__int64 (__fastcall **)(__int64, __int64, _QWORD))(v12 + 24))(v12, v13, 0LL);
if ( (_BYTE)v4 )
{
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "Flattened message buffer contents:\n");
us_buffer_print(v14, a3);
}
else
{
v4 = v11;
}
}
}
}
else
{
v4 = v10;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2, __int64 a3)
{
unsigned int v4; // ebp
__int64 v5; // rax
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // r13
unsigned int v9; // er12
unsigned int v10; // eax
unsigned int v11; // er14
__int64 v12; // r12
__int64 v13; // rax
__int64 v14; // r13

if ( us_log_level > 3 )
us_log_debug_proc("At '%s':%d function '%s'", "../../../src/us_test_osc_msg_main.c", 52LL, "test_unflatten");
if ( us_log_level > 2 )
us_log_info_proc("unflattening message");
v4 = us_osc_msg_is_msg_bundle(a2);
if ( (_BYTE)v4 )
{
if ( us_log_level > 2 )
us_log_info_proc("unflattening bundle");
v5 = func0(a2);
v6 = us_osc_msg_bundle_unflatten(a1, a2, v5, 0LL);
if ( v6 )
{
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "Parsed bundle: \n");
(*(void (__fastcall **)(__int64, __int64))(v6 + 16))(v6, a3);
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "\n");
v7 = us_buffer_create(a1, 4096LL);
v8 = v7;
if ( v7 )
{
v9 = (*(__int64 (__fastcall **)(__int64, __int64, _QWORD))(v6 + 24))(v6, v7, 0LL);
if ( (_BYTE)v9 )
{
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "Flattened message buffer contents:\n");
us_buffer_print(v8, a3);
v4 = v9;
}
}
}
else
{
v4 = 0;
}
}
else
{
v10 = us_osc_msg_is_msg(a2);
v11 = v10;
if ( (_BYTE)v10 )
{
if ( us_log_level > 2 )
us_log_info_proc("unflattening message");
v12 = us_osc_msg_unflatten(a1, a2, 0LL);
if ( v12 )
{
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "Parsed message: \n");
(*(void (__fastcall **)(__int64, __int64))(v12 + 16))(v12, a3);
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "\n");
v13 = us_buffer_create(a1, 4096LL);
v14 = v13;
v4 = v11;
if ( v13 )
{
v4 = (*(__int64 (__fastcall **)(__int64, __int64, _QWORD))(v12 + 24))(v12, v13, 0LL);
if ( (_BYTE)v4 )
{
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "Flattened message buffer contents:\n");
us_buffer_print(v14, a3);
}
else
{
v4 = v11;
}
}
}
}
else
{
v4 = v10;
}
}
return v4;
}

original_code:
static _Bool test_unflatten( us_allocator_t *allocator, us_buffer_t *buffer, us_print_t *printer )
{
    _Bool r = 0;
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "At '%s':%d function '%s'", "../../../src/us_test_osc_msg_main.c", 52, __FUNCTION__ ); } while ( 0 );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "unflattening message" ); } while ( 0 );
    if ( us_osc_msg_is_msg_bundle( buffer ) )
    {
        us_osc_msg_bundle_t *bundle;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "unflattening bundle" ); } while ( 0 );
        bundle = us_osc_msg_bundle_unflatten( allocator, buffer, us_buffer_readable_count( buffer ), 0 );
        if ( bundle )
        {
            r = 1;
            printer->printf( printer, "Parsed bundle: \n" );
            bundle->print( bundle, printer );
            printer->printf( printer, "\n" );
            {
                us_buffer_t *second_buffer = us_buffer_create( allocator, 4096 );
                if ( second_buffer )
                {
                    if ( bundle->flatten( bundle, second_buffer, 0 ) )
                    {
                        {
                            printer->printf( printer, "Flattened message buffer contents:\n" );
                            us_buffer_print( second_buffer, printer );
                        }
                    }
                }
            }
        }
    }
    else if ( us_osc_msg_is_msg( buffer ) )
    {
        us_osc_msg_t *msg;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "unflattening message" ); } while ( 0 );
        msg = us_osc_msg_unflatten( allocator, buffer, 0 );
        if ( msg )
        {
            r = 1;
            printer->printf( printer, "Parsed message: \n" );
            msg->print( msg, printer );
            printer->printf( printer, "\n" );
            {
                us_buffer_t *second_buffer = us_buffer_create( allocator, 4096 );
                if ( second_buffer )
                {
                    if ( msg->flatten( msg, second_buffer, 0 ) )
                    {
                        {
                            printer->printf( printer, "Flattened message buffer contents:\n" );
                            us_buffer_print( second_buffer, printer );
                        }
                    }
                }
            }
        }
    }
    return r;
}

canonical_original_code:
static _Bool test_unflatten(struct us_allocator_s *allocator, struct us_buffer_s *buffer, struct us_print_s *printer)
{
    _Bool r = 0;
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "At '%s':%d function '%s'", "../../../src/us_test_osc_msg_main.c", 52, __FUNCTION__ ); } while ( 0 );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "unflattening message" ); } while ( 0 );
    if ( us_osc_msg_is_msg_bundle( buffer ) )
    {
        struct us_osc_msg_bundle_s *bundle;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "unflattening bundle" ); } while ( 0 );
        bundle = us_osc_msg_bundle_unflatten( allocator, buffer, us_buffer_readable_count( buffer ), 0 );
        if ( bundle )
        {
            r = 1;
            printer->printf( printer, "Parsed bundle: \n" );
            bundle->print( bundle, printer );
            printer->printf( printer, "\n" );
            {
                struct us_buffer_s *second_buffer = us_buffer_create( allocator, 4096 );
                if ( second_buffer )
                {
                    if ( bundle->flatten( bundle, second_buffer, 0 ) )
                    {
                        {
                            printer->printf( printer, "Flattened message buffer contents:\n" );
                            us_buffer_print( second_buffer, printer );
                        }
                    }
                }
            }
        }
    }
    else if ( us_osc_msg_is_msg( buffer ) )
    {
        struct us_osc_msg_s *msg;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "unflattening message" ); } while ( 0 );
        msg = us_osc_msg_unflatten( allocator, buffer, 0 );
        if ( msg )
        {
            r = 1;
            printer->printf( printer, "Parsed message: \n" );
            msg->print( msg, printer );
            printer->printf( printer, "\n" );
            {
                struct us_buffer_s *second_buffer = us_buffer_create( allocator, 4096 );
                if ( second_buffer )
                {
                    if ( msg->flatten( msg, second_buffer, 0 ) )
                    {
                        {
                            printer->printf( printer, "Flattened message buffer contents:\n" );
                            us_buffer_print( second_buffer, printer );
                        }
                    }
                }
            }
        }
    }
    return r;
}

variable_types: struct us_osc_msg_bundle_s { void (*destroy)(struct us_osc_msg_bundle_s *self); struct us_osc_msg_s { void (*destroy)(struct us_osc_msg_s *self); struct us_osc_msg_element_s { void (*destroy)(struct us_osc_msg_element_s *self, struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *allocator); _Bool (*print)(struct us_osc_msg_element_s *self, struct us_print_s { void (*destroy)(struct us_print_s *self); _Bool (*printf)(struct us_print_s *self, char *fmt, ...); _Bool (*vprintf)(struct us_print_s *self, char *fmt, __builtin_va_list ap); } *printer); _Bool (*flatten)(struct us_osc_msg_element_s *self, struct us_buffer_s { void (*destroy)(struct us_buffer_s *self); struct us_allocator_s *m_allocator; unsigned char *m_buffer; unsigned long m_next_in; unsigned long m_next_out; unsigned long m_max_length; } *buf, int *length); struct us_osc_msg_element_s *m_next; char m_code; } *(*append)(struct us_osc_msg_s *self, struct us_osc_msg_element_s *element); _Bool (*print)(struct us_osc_msg_s *self, struct us_print_s *printer); _Bool (*flatten)(struct us_osc_msg_s *self, struct us_buffer_s *buf, int *length); struct us_allocator_s *m_allocator; char *m_address; unsigned int m_address_code; struct us_osc_msg_element_s *m_first_element; struct us_osc_msg_element_s *m_last_element; struct us_osc_msg_s *m_next; } *(*append)(struct us_osc_msg_bundle_s *self, struct us_osc_msg_s *msg); _Bool (*print)(struct us_osc_msg_bundle_s *self, struct us_print_s *printer); _Bool (*flatten)(struct us_osc_msg_bundle_s *self, struct us_buffer_s *buf, int *length); unsigned int m_timetag_high; unsigned int m_timetag_low; struct us_osc_msg_s *m_first_msg; struct us_osc_msg_s *m_last_msg; } *

user_defined_types: struct us_osc_msg_bundle_s { void (*destroy)(struct us_osc_msg_bundle_s *self); struct us_osc_msg_s *(*append)(struct us_osc_msg_bundle_s *self, struct us_osc_msg_s *msg); _Bool (*print)(struct us_osc_msg_bundle_s *self, struct us_print_s *printer); _Bool (*flatten)(struct us_osc_msg_bundle_s *self, struct us_buffer_s *buf, int *length); unsigned int m_timetag_high; unsigned int m_timetag_low; struct us_osc_msg_s *m_first_msg; struct us_osc_msg_s *m_last_msg; }

user_defined_types: struct us_osc_msg_s { void (*destroy)(struct us_osc_msg_s *self); struct us_osc_msg_element_s *(*append)(struct us_osc_msg_s *self, struct us_osc_msg_element_s *element); _Bool (*print)(struct us_osc_msg_s *self, struct us_print_s *printer); _Bool (*flatten)(struct us_osc_msg_s *self, struct us_buffer_s *buf, int *length); struct us_allocator_s *m_allocator; char *m_address; unsigned int m_address_code; struct us_osc_msg_element_s *m_first_element; struct us_osc_msg_element_s *m_last_element; struct us_osc_msg_s *m_next; }

user_defined_types: struct us_osc_msg_element_s { void (*destroy)(struct us_osc_msg_element_s *self, struct us_allocator_s *allocator); _Bool (*print)(struct us_osc_msg_element_s *self, struct us_print_s *printer); _Bool (*flatten)(struct us_osc_msg_element_s *self, struct us_buffer_s *buf, int *length); struct us_osc_msg_element_s *m_next; char m_code; }


decompiled_code:
__int64 __fastcall do_test_osc_msg(__int64 a1, _QWORD *a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // r12
unsigned int v6; // ebp

if ( us_log_level > 3 )
us_log_debug_proc("At '%s':%d function '%s'", "../../../src/us_test_osc_msg_main.c", 121LL, "do_test_osc_msg");
if ( us_log_level > 2 )
us_log_info_proc("creating test message");
v4 = us_osc_msg_form(a1, "/out/1/gain/db", ",fs", "some string", 20.0);
v5 = v4;
v6 = 0;
if ( v4 )
{
us_osc_msg_print(v4, a3);
if ( a2 )
{
if ( us_log_level > 3 )
us_log_debug_proc("flattening test message");
v6 = (*(__int64 (__fastcall **)(__int64, _QWORD *, _QWORD))(v5 + 24))(v5, a2, 0LL);
if ( (_BYTE)v6 )
{
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "Flattened message buffer contents:\n");
us_buffer_print(a2, a3);
v6 = test_unflatten(a1, a2, a3);
}
}
}
(*(void (**)(__int64, const char *, ...))(a3 + 8))(a3, "\nResult: %d\n\n", (unsigned __int8)v6);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // r12
unsigned int v6; // ebp

if ( us_log_level > 3 )
us_log_debug_proc("At '%s':%d function '%s'", "../../../src/us_test_osc_msg_main.c", 121LL, "do_test_osc_msg");
if ( us_log_level > 2 )
us_log_info_proc("creating test message");
v4 = us_osc_msg_form(a1, "/out/1/gain/db", ",fs", "some string", 20.0);
v5 = v4;
v6 = 0;
if ( v4 )
{
us_osc_msg_print(v4, a3);
if ( a2 )
{
if ( us_log_level > 3 )
us_log_debug_proc("flattening test message");
v6 = (*(__int64 (__fastcall **)(__int64, _QWORD *, _QWORD))(v5 + 24))(v5, a2, 0LL);
if ( (_BYTE)v6 )
{
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "Flattened message buffer contents:\n");
us_buffer_print(a2, a3);
v6 = func1(a1, a2, a3);
}
}
}
(*(void (**)(__int64, const char *, ...))(a3 + 8))(a3, "\nResult: %d\n\n", (unsigned __int8)v6);
return v6;
}

original_code:
static _Bool do_test_osc_msg( us_allocator_t *allocator, us_buffer_t *buffer, us_print_t *printer )
{
    _Bool r = 0;
    us_osc_msg_t *msg;
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "At '%s':%d function '%s'", "../../../src/us_test_osc_msg_main.c", 121, __FUNCTION__ ); } while ( 0 );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "creating test message" ); } while ( 0 );
    msg = us_osc_msg_form( allocator, "/out/1/gain/db", ",fs", 20.0f, "some string" );
    if ( msg )
    {
        us_osc_msg_print( msg, printer );
        if ( buffer )
        {
            do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "flattening test message" ); } while ( 0 );
            if ( msg->flatten( msg, buffer, 0 ) )
            {
                {
                    printer->printf( printer, "Flattened message buffer contents:\n" );
                    us_buffer_print( buffer, printer );
                }
                r = test_unflatten( allocator, buffer, printer );
            }
        }
    }
    printer->printf( printer, "\nResult: %d\n\n", r );
    return r;
}

canonical_original_code:
static _Bool do_test_osc_msg(struct us_allocator_s *allocator, struct us_buffer_s *buffer, struct us_print_s *printer)
{
    _Bool r = 0;
    struct us_osc_msg_s *msg;
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "At '%s':%d function '%s'", "../../../src/us_test_osc_msg_main.c", 121, __FUNCTION__ ); } while ( 0 );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "creating test message" ); } while ( 0 );
    msg = us_osc_msg_form( allocator, "/out/1/gain/db", ",fs", 20.0f, "some string" );
    if ( msg )
    {
        us_osc_msg_print( msg, printer );
        if ( buffer )
        {
            do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "flattening test message" ); } while ( 0 );
            if ( msg->flatten( msg, buffer, 0 ) )
            {
                {
                    printer->printf( printer, "Flattened message buffer contents:\n" );
                    us_buffer_print( buffer, printer );
                }
                r = test_unflatten( allocator, buffer, printer );
            }
        }
    }
    printer->printf( printer, "\nResult: %d\n\n", r );
    return r;
}

variable_types: struct us_osc_msg_s { void (*destroy)(struct us_osc_msg_s *self); struct us_osc_msg_element_s { void (*destroy)(struct us_osc_msg_element_s *self, struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *allocator); _Bool (*print)(struct us_osc_msg_element_s *self, struct us_print_s { void (*destroy)(struct us_print_s *self); _Bool (*printf)(struct us_print_s *self, char *fmt, ...); _Bool (*vprintf)(struct us_print_s *self, char *fmt, __builtin_va_list ap); } *printer); _Bool (*flatten)(struct us_osc_msg_element_s *self, struct us_buffer_s { void (*destroy)(struct us_buffer_s *self); struct us_allocator_s *m_allocator; unsigned char *m_buffer; unsigned long m_next_in; unsigned long m_next_out; unsigned long m_max_length; } *buf, int *length); struct us_osc_msg_element_s *m_next; char m_code; } *(*append)(struct us_osc_msg_s *self, struct us_osc_msg_element_s *element); _Bool (*print)(struct us_osc_msg_s *self, struct us_print_s *printer); _Bool (*flatten)(struct us_osc_msg_s *self, struct us_buffer_s *buf, int *length); struct us_allocator_s *m_allocator; char *m_address; unsigned int m_address_code; struct us_osc_msg_element_s *m_first_element; struct us_osc_msg_element_s *m_last_element; struct us_osc_msg_s *m_next; } *


decompiled_code:
__int64 __fastcall do_test_osc_msg_bundle(__int64 a1, _QWORD *a2, __int64 a3)
{
__int64 v4; // rbx
void (__fastcall *v5)(__int64, __int64); // r13
__int64 v6; // rax
void (__fastcall *v7)(__int64, __int64); // r13
__int64 v8; // rax
unsigned int v9; // er13
__int64 v10; // rax

if ( us_log_level > 3 )
us_log_debug_proc(
"At '%s':%d function '%s'",
"../../../src/us_test_osc_msg_main.c",
172LL,
"do_test_osc_msg_bundle");
if ( us_log_level > 2 )
us_log_info_proc("creating test bundle");
v4 = us_osc_msg_bundle_create(a1, 0LL, 0LL);
v5 = *(void (__fastcall **)(__int64, __int64))(v4 + 8);
v6 = us_osc_msg_form(a1, "/in/1/level/db", ",fs", "some string", -10.0);
v5(v4, v6);
v7 = *(void (__fastcall **)(__int64, __int64))(v4 + 8);
v8 = us_osc_msg_form(a1, "/out/1/level/db", ",fs", "another string", 40.0);
v7(v4, v8);
us_osc_msg_bundle_print(v4, a3);
v9 = 0;
if ( a2 )
{
v9 = (*(__int64 (__fastcall **)(__int64, _QWORD *, _QWORD))(v4 + 24))(v4, a2, 0LL);
if ( (_BYTE)v9 )
{
v10 = us_buffer_readable_count(a2);
(*(void (**)(__int64, const char *, ...))(a3 + 8))(a3, "bundle size: %ld\n", v10);
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "Flattened message bundle buffer contents:\n");
us_buffer_print(a2, a3);
v9 = test_unflatten(a1, a2, a3);
}
}
(*(void (**)(__int64, const char *, ...))(a3 + 8))(a3, "\nResult: %d\n\n", (unsigned __int8)v9);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2, __int64 a3)
{
__int64 v4; // rbx
void (__fastcall *v5)(__int64, __int64); // r13
__int64 v6; // rax
void (__fastcall *v7)(__int64, __int64); // r13
__int64 v8; // rax
unsigned int v9; // er13
__int64 v10; // rax

if ( us_log_level > 3 )
us_log_debug_proc(
"At '%s':%d function '%s'",
"../../../src/us_test_osc_msg_main.c",
172LL,
"do_test_osc_msg_bundle");
if ( us_log_level > 2 )
us_log_info_proc("creating test bundle");
v4 = us_osc_msg_bundle_create(a1, 0LL, 0LL);
v5 = *(void (__fastcall **)(__int64, __int64))(v4 + 8);
v6 = us_osc_msg_form(a1, "/in/1/level/db", ",fs", "some string", -10.0);
v5(v4, v6);
v7 = *(void (__fastcall **)(__int64, __int64))(v4 + 8);
v8 = us_osc_msg_form(a1, "/out/1/level/db", ",fs", "another string", 40.0);
v7(v4, v8);
us_osc_msg_bundle_print(v4, a3);
v9 = 0;
if ( a2 )
{
v9 = (*(__int64 (__fastcall **)(__int64, _QWORD *, _QWORD))(v4 + 24))(v4, a2, 0LL);
if ( (_BYTE)v9 )
{
v10 = func0(a2);
(*(void (**)(__int64, const char *, ...))(a3 + 8))(a3, "bundle size: %ld\n", v10);
(*(void (__fastcall **)(__int64, const char *))(a3 + 8))(a3, "Flattened message bundle buffer contents:\n");
us_buffer_print(a2, a3);
v9 = func1(a1, a2, a3);
}
}
(*(void (**)(__int64, const char *, ...))(a3 + 8))(a3, "\nResult: %d\n\n", (unsigned __int8)v9);
return v9;
}

original_code:
static _Bool do_test_osc_msg_bundle( us_allocator_t *allocator, us_buffer_t *buffer, us_print_t *printer )
{
    _Bool r = 0;
    us_osc_msg_bundle_t *bundle;
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "At '%s':%d function '%s'", "../../../src/us_test_osc_msg_main.c", 172, __FUNCTION__ ); } while ( 0 );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "creating test bundle" ); } while ( 0 );
    bundle = us_osc_msg_bundle_create( allocator, 0, 0 );
    bundle->append( bundle, us_osc_msg_form( allocator, "/in/1/level/db", ",fs", -10.0f, "some string" ) );
    bundle->append( bundle, us_osc_msg_form( allocator, "/out/1/level/db", ",fs", 40.0, "another string" ) );
    if ( bundle )
    {
        us_osc_msg_bundle_print( bundle, printer );
        if ( buffer )
        {
            if ( bundle->flatten( bundle, buffer, 0 ) )
            {
                int32_t bundle_size = (int32_t)us_buffer_readable_count( buffer );
                {
                    printer->printf( printer, "bundle size: %ld\n", bundle_size );
                    printer->printf( printer, "Flattened message bundle buffer contents:\n" );
                    us_buffer_print( buffer, printer );
                }
                r = test_unflatten( allocator, buffer, printer );
            }
        }
    }
    printer->printf( printer, "\nResult: %d\n\n", r );
    return r;
}

canonical_original_code:
static _Bool do_test_osc_msg_bundle(struct us_allocator_s *allocator, struct us_buffer_s *buffer, struct us_print_s *printer)
{
    _Bool r = 0;
    struct us_osc_msg_bundle_s *bundle;
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "At '%s':%d function '%s'", "../../../src/us_test_osc_msg_main.c", 172, __FUNCTION__ ); } while ( 0 );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "creating test bundle" ); } while ( 0 );
    bundle = us_osc_msg_bundle_create( allocator, 0, 0 );
    bundle->append( bundle, us_osc_msg_form( allocator, "/in/1/level/db", ",fs", -10.0f, "some string" ) );
    bundle->append( bundle, us_osc_msg_form( allocator, "/out/1/level/db", ",fs", 40.0, "another string" ) );
    if ( bundle )
    {
        us_osc_msg_bundle_print( bundle, printer );
        if ( buffer )
        {
            if ( bundle->flatten( bundle, buffer, 0 ) )
            {
                int bundle_size = (int32_t)us_buffer_readable_count( buffer );
                {
                    printer->printf( printer, "bundle size: %ld\n", bundle_size );
                    printer->printf( printer, "Flattened message bundle buffer contents:\n" );
                    us_buffer_print( buffer, printer );
                }
                r = test_unflatten( allocator, buffer, printer );
            }
        }
    }
    printer->printf( printer, "\nResult: %d\n\n", r );
    return r;
}

variable_types: struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *

variable_types: struct us_buffer_s { void (*destroy)(struct us_buffer_s *self); struct us_allocator_s *m_allocator; unsigned char *m_buffer; unsigned long m_next_in; unsigned long m_next_out; unsigned long m_max_length; } *

variable_types: struct us_print_s { void (*destroy)(struct us_print_s *self); _Bool (*printf)(struct us_print_s *self, char *fmt, ...); _Bool (*vprintf)(struct us_print_s *self, char *fmt, __builtin_va_list ap); } *


decompiled_code:
__int64 __fastcall us_test_osc_msg_main(unsigned int a1, __int64 a2)
{
int v2; // ebx
_QWORD *v4; // rbp
_QWORD *v5; // rbp

v2 = us_testutil_start(0x2000LL, 0x2000LL, a1, a2);
if ( (_BYTE)v2 )
{
us_logger_printer_start(us_testutil_printer_stdout, us_testutil_printer_stderr);
if ( us_log_level > 2 )
us_log_info_proc("Hello world from %s compiled on %s", "../../../src/us_test_osc_msg_main.c", "May 23 2025");
if ( us_log_level > 3 )
{
us_log_debug_proc("resetting session allocator");
if ( us_log_level > 3 )
us_log_debug_proc("allocating 4k buffer from session");
}
v4 = (_QWORD *)us_buffer_create(us_testutil_session_allocator, 4096LL);
if ( v4 )
{
if ( us_log_level > 3 )
us_log_debug_proc("testing msg");
v2 = do_test_osc_msg(us_testutil_session_allocator, v4, us_stdout);
((void (__fastcall *)(_QWORD *))*v4)(v4);
}
else if ( us_log_level > 0 )
{
us_log_error_proc("error allocating buffer");
}
if ( us_log_level > 3 )
us_log_debug_proc("resetting session allocator");
us_simple_allocator_reset(&us_testutil_session_allocator_impl);
if ( us_log_level > 3 )
us_log_debug_proc("allocating 4k buffer from session");
v5 = (_QWORD *)us_buffer_create(us_testutil_session_allocator, 4096LL);
if ( v5 )
{
if ( us_log_level > 3 )
us_log_debug_proc("testing bundle");
v2 &= do_test_osc_msg_bundle(us_testutil_session_allocator, v5, us_stdout);
((void (__fastcall *)(_QWORD *))*v5)(v5);
}
else if ( us_log_level > 0 )
{
us_log_error_proc("error allocating buffer");
}
us_logger_finish();
us_testutil_finish();
}
return (unsigned __int8)v2 ^ 1u;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2)
{
int v2; // ebx
_QWORD *v4; // rbp
_QWORD *v5; // rbp

v2 = us_testutil_start(0x2000LL, 0x2000LL, a1, a2);
if ( (_BYTE)v2 )
{
us_logger_printer_start(us_testutil_printer_stdout, us_testutil_printer_stderr);
if ( us_log_level > 2 )
us_log_info_proc("Hello world from %s compiled on %s", "../../../src/us_test_osc_msg_main.c", "May 23 2025");
if ( us_log_level > 3 )
{
us_log_debug_proc("resetting session allocator");
if ( us_log_level > 3 )
us_log_debug_proc("allocating 4k buffer from session");
}
v4 = (_QWORD *)us_buffer_create(us_testutil_session_allocator, 4096LL);
if ( v4 )
{
if ( us_log_level > 3 )
us_log_debug_proc("testing msg");
v2 = func2(us_testutil_session_allocator, v4, us_stdout);
((void (__fastcall *)(_QWORD *))*v4)(v4);
}
else if ( us_log_level > 0 )
{
us_log_error_proc("error allocating buffer");
}
if ( us_log_level > 3 )
us_log_debug_proc("resetting session allocator");
us_simple_allocator_reset(&us_testutil_session_allocator_impl);
if ( us_log_level > 3 )
us_log_debug_proc("allocating 4k buffer from session");
v5 = (_QWORD *)us_buffer_create(us_testutil_session_allocator, 4096LL);
if ( v5 )
{
if ( us_log_level > 3 )
us_log_debug_proc("testing bundle");
v2 &= func3(us_testutil_session_allocator, v5, us_stdout);
((void (__fastcall *)(_QWORD *))*v5)(v5);
}
else if ( us_log_level > 0 )
{
us_log_error_proc("error allocating buffer");
}
us_logger_finish();
us_testutil_finish();
}
return (unsigned __int8)v2 ^ 1u;
}

original_code:
int us_test_osc_msg_main( int argc, const char **argv )
{
    _Bool r = 1;
    r = us_testutil_start( 8192, 8192, argc, argv );
    if ( r )
    {
        us_logger_printer_start( us_testutil_printer_stdout, us_testutil_printer_stderr );
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Hello world from %s compiled on %s", "../../../src/us_test_osc_msg_main.c", "Apr 24 2024" ); } while ( 0 );
        {
            us_buffer_t *buffer = 0;
            do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "resetting session allocator" ); } while ( 0 );
            do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "allocating 4k buffer from session" ); } while ( 0 );
            buffer = us_buffer_create( us_testutil_session_allocator, 4096 );
            if ( buffer )
            {
                do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "testing msg" ); } while ( 0 );
                r &= do_test_osc_msg( us_testutil_session_allocator, buffer, us_stdout );
                buffer->destroy( buffer );
            }
            else
            {
                do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "error allocating buffer" ); } while ( 0 );
            }
        }
        {
            us_buffer_t *buffer = 0;
            do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "resetting session allocator" ); } while ( 0 );
            us_simple_allocator_reset( &us_testutil_session_allocator_impl );
            do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "allocating 4k buffer from session" ); } while ( 0 );
            buffer = us_buffer_create( us_testutil_session_allocator, 4096 );
            if ( buffer )
            {
                do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "testing bundle" ); } while ( 0 );
                r &= do_test_osc_msg_bundle( us_testutil_session_allocator, buffer, us_stdout );
                buffer->destroy( buffer );
            }
            else
            {
                do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "error allocating buffer" ); } while ( 0 );
            }
        }
        us_logger_finish();
        us_testutil_finish();
    }
    return r ? 0 : 1;
}

canonical_original_code:
int us_test_osc_msg_main(int argc, char **argv)
{
    _Bool r = 1;
    r = us_testutil_start( 8192, 8192, argc, argv );
    if ( r )
    {
        us_logger_printer_start( us_testutil_printer_stdout, us_testutil_printer_stderr );
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Hello world from %s compiled on %s", "../../../src/us_test_osc_msg_main.c", "Apr 24 2024" ); } while ( 0 );
        {
            struct us_buffer_s *buffer = 0;
            do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "resetting session allocator" ); } while ( 0 );
            do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "allocating 4k buffer from session" ); } while ( 0 );
            buffer = us_buffer_create( us_testutil_session_allocator, 4096 );
            if ( buffer )
            {
                do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "testing msg" ); } while ( 0 );
                r &= do_test_osc_msg( us_testutil_session_allocator, buffer, us_stdout );
                buffer->destroy( buffer );
            }
            else
            {
                do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "error allocating buffer" ); } while ( 0 );
            }
        }
        {
            struct us_buffer_s *buffer = 0;
            do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "resetting session allocator" ); } while ( 0 );
            us_simple_allocator_reset( &us_testutil_session_allocator_impl );
            do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "allocating 4k buffer from session" ); } while ( 0 );
            buffer = us_buffer_create( us_testutil_session_allocator, 4096 );
            if ( buffer )
            {
                do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "testing bundle" ); } while ( 0 );
                r &= do_test_osc_msg_bundle( us_testutil_session_allocator, buffer, us_stdout );
                buffer->destroy( buffer );
            }
            else
            {
                do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "error allocating buffer" ); } while ( 0 );
            }
        }
        us_logger_finish();
        us_testutil_finish();
    }
    return r ? 0 : 1;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


decompiled_code:
void us_simple_allocator_destroy()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void us_simple_allocator_destroy( us_allocator_t *self )
{
    (void)self;
}

canonical_original_code:
void us_simple_allocator_destroy(struct us_allocator_s *self)
{
    (void)self;
}

return_type: void


original_code:
void *us_simple_allocator_alloc( us_allocator_t *self_, int32_t length, int32_t count )
{
    us_simple_allocator_t *self = (us_simple_allocator_t *)self_;
    void *result = 0;
    int32_t total_size_to_allocate = ( ( ( length * count ) + ( uint32_t )( sizeof( uint32_t ) ) - 1 ) & ( uint32_t ) ~( sizeof( uint32_t ) - 1 ) );
    if ( ( self->m_current_position + total_size_to_allocate ) <= ( self->m_raw_memory_length ) )
    {
        result = ( (char *)self->m_raw_memory ) + self->m_current_position;
        self->m_current_position += total_size_to_allocate;
    }
    return result;
}

canonical_original_code:
void *us_simple_allocator_alloc(struct us_allocator_s *self_, int length, int count)
{
    struct us_simple_allocator_s *self = (us_simple_allocator_t *)self_;
    void *result = 0;
    int total_size_to_allocate = ( ( ( length * count ) + ( uint32_t )( sizeof( uint32_t ) ) - 1 ) & ( uint32_t ) ~( sizeof( uint32_t ) - 1 ) );
    if ( ( self->m_current_position + total_size_to_allocate ) <= ( self->m_raw_memory_length ) )
    {
        result = ( (char *)self->m_raw_memory ) + self->m_current_position;
        self->m_current_position += total_size_to_allocate;
    }
    return result;
}

variable_types: length int

variable_types: count int

variable_types: struct us_simple_allocator_s { struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } m_base; void *m_raw_memory; int m_raw_memory_length; int m_current_position; } *

variable_types:
result
void *

return_type: void *

user_defined_types: struct us_simple_allocator_s { struct us_allocator_s m_base; void *m_raw_memory; int m_raw_memory_length; int m_current_position; }


decompiled_code:
void us_simple_allocator_free()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void us_simple_allocator_free( struct us_allocator_s *self_, const void *ptr )
{
    (void)self_;
    (void)ptr;
}

canonical_original_code:
void us_simple_allocator_free(struct us_allocator_s *self_, void *ptr)
{
    (void)self_;
    (void)ptr;
}

variable_types:
ptr
void *


decompiled_code:
void us_malloc_allocator_destroy()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void us_malloc_allocator_destroy( us_allocator_t *self_ )
{
    (void)self_;
}

canonical_original_code:
void us_malloc_allocator_destroy(struct us_allocator_s *self_)
{
    (void)self_;
}


decompiled_code:
void *__fastcall us_simple_allocator_realloc(__int64 a1, const void *a2, unsigned int a3, unsigned int a4)
{
void *v6; // rax
void *v7; // r12

v6 = (void *)(*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD))(a1 + 8))(a1, a3, a4);
v7 = v6;
if ( v6 )
{
memcpy(v6, a2, (a4 * a3 + 3) & 0xFFFFFFFC);
(*(void (__fastcall **)(__int64, const void *))(a1 + 24))(a1, a2);
}
return v7;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1, const void *a2, unsigned int a3, unsigned int a4)
{
void *v6; // rax
void *v7; // r12

v6 = (void *)(*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD))(a1 + 8))(a1, a3, a4);
v7 = v6;
if ( v6 )
{
memcpy(v6, a2, (a4 * a3 + 3) & 0xFFFFFFFC);
(*(void (__fastcall **)(__int64, const void *))(a1 + 24))(a1, a2);
}
return v7;
}

original_code:
void *us_simple_allocator_realloc( struct us_allocator_s *self_, const void *orig_ptr, int32_t length, int32_t count )
{
    void *new_ptr = self_->alloc( self_, length, count );
    if ( new_ptr )
    {
        memcpy( new_ptr, orig_ptr, ( ( ( length * count ) + ( uint32_t )( sizeof( uint32_t ) ) - 1 ) & ( uint32_t ) ~( sizeof( uint32_t ) - 1 ) ) );
        self_->free( self_, orig_ptr );
    }
    return new_ptr;
}

canonical_original_code:
void *us_simple_allocator_realloc(struct us_allocator_s *self_, void *orig_ptr, int length, int count)
{
    void *new_ptr = self_->alloc( self_, length, count );
    if ( new_ptr )
    {
        memcpy( new_ptr, orig_ptr, ( ( ( length * count ) + ( unsigned int )( sizeof( unsigned int ) ) - 1 ) & ( unsigned int ) ~( sizeof( unsigned int ) - 1 ) ) );
        self_->free( self_, orig_ptr );
    }
    return new_ptr;
}


decompiled_code:
void *__fastcall us_malloc_allocator_alloc(__int64 a1, int a2, int a3)
{
return malloc((a3 * a2 + 3) & 0xFFFFFFFC);
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, int a2, int a3)
{
return malloc((a3 * a2 + 3) & 0xFFFFFFFC);
}

original_code:
void *us_malloc_allocator_alloc( us_allocator_t *self, int32_t length, int32_t count )
{
    (void)self;
    return malloc( ( ( ( length * count ) + ( uint32_t )( sizeof( uint32_t ) ) - 1 ) & ( uint32_t ) ~( sizeof( uint32_t ) - 1 ) ) );
}

canonical_original_code:
void *us_malloc_allocator_alloc(struct us_allocator_s *self, int length, int count)
{
    (void)self;
    return malloc( ( ( ( length * count ) + ( unsigned int )( sizeof( unsigned int ) ) - 1 ) & ( unsigned int ) ~( sizeof( unsigned int ) - 1 ) ) );
}


decompiled_code:
void *__fastcall us_malloc_allocator_realloc(__int64 a1, void *a2, int a3, int a4)
{
return realloc(a2, (a4 * a3 + 3) & 0xFFFFFFFC);
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, void *a2, int a3, int a4)
{
return realloc(a2, (a4 * a3 + 3) & 0xFFFFFFFC);
}

original_code:
void *us_malloc_allocator_realloc( struct us_allocator_s *self, const void *orig_ptr, int32_t length, int32_t count )
{
    (void)self;
    return realloc( (void *)orig_ptr, ( ( ( length * count ) + ( uint32_t )( sizeof( uint32_t ) ) - 1 ) & ( uint32_t ) ~( sizeof( uint32_t ) - 1 ) ) );
}

canonical_original_code:
void *us_malloc_allocator_realloc(struct us_allocator_s *self, void *orig_ptr, int length, int count)
{
    (void)self;
    return realloc( (void *)orig_ptr, ( ( ( length * count ) + ( unsigned int )( sizeof( unsigned int ) ) - 1 ) & ( unsigned int ) ~( sizeof( unsigned int ) - 1 ) ) );
}


decompiled_code:
void __fastcall us_malloc_allocator_free(__int64 a1, void *a2)
{
free(a2);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, void *a2)
{
free(a2);
}

original_code:
void us_malloc_allocator_free( struct us_allocator_s *self, const void *ptr )
{
    (void)self;
    free( (void *)ptr );
}

canonical_original_code:
void us_malloc_allocator_free(struct us_allocator_s *self, void *ptr)
{
    (void)self;
    free( (void *)ptr );
}


decompiled_code:
char *__fastcall us_strdup(__int64 a1, const char *a2)
{
int v2; // eax
char *v3; // rax
char *v4; // rbx

v2 = strlen(a2);
v3 = (char *)(*(__int64 (__fastcall **)(__int64, __int64, _QWORD))(a1 + 8))(a1, 1LL, (unsigned int)(v2 + 1));
v4 = v3;
if ( v3 )
strcpy(v3, a2);
return v4;
}

canonical_decompiled_code:
char *__fastcall func8(__int64 a1, const char *a2)
{
int v2; // eax
char *v3; // rax
char *v4; // rbx

v2 = strlen(a2);
v3 = (char *)(*(__int64 (__fastcall **)(__int64, __int64, _QWORD))(a1 + 8))(a1, 1LL, (unsigned int)(v2 + 1));
v4 = v3;
if ( v3 )
strcpy(v3, a2);
return v4;
}

original_code:
char *us_strdup( struct us_allocator_s *allocator, const char *src )
{
    size_t len = strlen( src );
    char *p = ( char * )( ( allocator )->alloc( ( allocator ), (int32_t)sizeof( char ), ( int32_t )( len + 1 ) ) );
    if ( p )
    {
        strcpy( p, src );
    }
    return p;
}

canonical_original_code:
char *us_strdup(struct us_allocator_s *allocator, char *src)
{
    unsigned long len = strlen( src );
    char *p = ( char * )( ( allocator )->alloc( ( allocator ), (int32_t)sizeof( char ), ( int32_t )( len + 1 ) ) );
    if ( p )
    {
        strcpy( p, src );
    }
    return p;
}

variable_types:
src
char *

variable_types:
len
unsigned long

variable_types:
p
char *

return_type: char *


decompiled_code:
void __fastcall us_simple_allocator_reset(__int64 a1)
{
*(_DWORD *)(a1 + 44) = 0;
}

original_code:
void us_simple_allocator_reset( us_simple_allocator_t *self )
{
    self->m_current_position = 0;
}

canonical_original_code:
void us_simple_allocator_reset(struct us_simple_allocator_s *self)
{
    self->m_current_position = 0;
}


decompiled_code:
__int64 __fastcall us_buffer_peek(_QWORD *a1, __int64 a2)
{
return *(unsigned __int8 *)(a1[2] + (unsigned __int64)(a1[4] + a2) % a1[5]);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2)
{
return *(unsigned __int8 *)(a1[2] + (unsigned __int64)(a1[4] + a2) % a1[5]);
}

original_code:
static inline uint8_t us_buffer_peek( const us_buffer_t *self, size_t offset )
{
    return self->m_buffer[( self->m_next_out + offset ) % self->m_max_length];
}

canonical_original_code:
static inline unsigned char us_buffer_peek(struct us_buffer_s *self, unsigned long offset)
{
    return self->m_buffer[( self->m_next_out + offset ) % self->m_max_length];
}

variable_types:
offset
unsigned long

return_type: unsigned char


original_code:
_Bool us_buffer_print( us_buffer_t *self, us_print_t *printer )
{
    _Bool r = 0;
    if ( self && printer )
    {
        size_t len = us_buffer_readable_count( self );
        r = 1;
        r &= printer->printf( printer, "length: 0x%x\nContents:\n", len );
        if ( r )
        {
            size_t i;
            for ( i = 0; i < len; ++i )
            {
                r &= printer->printf( printer, "%02x ", us_buffer_peek( self, i ) );
                if ( !r )
                    break;
            }
            r &= printer->printf( printer, "\n" );
        }
    }
    return r;
}

canonical_original_code:
_Bool us_buffer_print(struct us_buffer_s *self, struct us_print_s *printer)
{
    _Bool r = 0;
    if ( self && printer )
    {
        unsigned long len = us_buffer_readable_count( self );
        r = 1;
        r &= printer->printf( printer, "length: 0x%x\nContents:\n", len );
        if ( r )
        {
            unsigned long i;
            for ( i = 0; i < len; ++i )
            {
                r &= printer->printf( printer, "%02x ", us_buffer_peek( self, i ) );
                if ( !r )
                    break;
            }
            r &= printer->printf( printer, "\n" );
        }
    }
    return r;
}

variable_types: struct us_buffer_s { void (*destroy)(struct us_buffer_s *self); struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *m_allocator; unsigned char *m_buffer; unsigned long m_next_in; unsigned long m_next_out; unsigned long m_max_length; } *

variable_types:
i
unsigned long

user_defined_types: struct us_print_s { void (*destroy)(struct us_print_s *self); _Bool (*printf)(struct us_print_s *self, char *fmt, ...); _Bool (*vprintf)(struct us_print_s *self, char *fmt, __builtin_va_list ap); }


decompiled_code:
__int64 __fastcall us_buffer_print_string(_QWORD *a1, __int64 a2)
{
unsigned int v2; // ebx
__int64 v3; // r13
__int64 i; // r14
unsigned __int8 v5; // al

LOBYTE(v2) = a2 != 0 && a1 != 0LL;
if ( (_BYTE)v2 )
{
v3 = us_buffer_readable_count(a1);
v2 = (*(__int64 (**)(__int64, const char *, ...))(a2 + 8))(a2, "length: 0x%x\nContents:\n", v3);
if ( (_BYTE)v2 )
{
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
{
v5 = us_buffer_peek(a1, i);
v2 = (*(__int64 (**)(__int64, const char *, ...))(a2 + 8))(a2, "%c", v5);
if ( !(_BYTE)v2 )
break;
}
}
v2 &= (*(__int64 (__fastcall **)(__int64, const char *))(a2 + 8))(a2, "\n");
}
}
return v2;
}

original_code:
_Bool us_buffer_print_string( us_buffer_t *self, us_print_t *printer )
{
    _Bool r = 0;
    if ( self && printer )
    {
        size_t len = us_buffer_readable_count( self );
        r = 1;
        r &= printer->printf( printer, "length: 0x%x\nContents:\n", len );
        if ( r )
        {
            size_t i;
            for ( i = 0; i < len; ++i )
            {
                r &= printer->printf( printer, "%c", us_buffer_peek( self, i ) );
                if ( !r )
                    break;
            }
            r &= printer->printf( printer, "\n" );
        }
    }
    return r;
}

canonical_original_code:
_Bool us_buffer_print_string(struct us_buffer_s *self, struct us_print_s *printer)
{
    _Bool r = 0;
    if ( self && printer )
    {
        unsigned long len = us_buffer_readable_count( self );
        r = 1;
        r &= printer->printf( printer, "length: 0x%x\nContents:\n", len );
        if ( r )
        {
            unsigned long i;
            for ( i = 0; i < len; ++i )
            {
                r &= printer->printf( printer, "%c", us_buffer_peek( self, i ) );
                if ( !r )
                    break;
            }
            r &= printer->printf( printer, "\n" );
        }
    }
    return r;
}


decompiled_code:
void __fastcall us_trie_node_set_end(__int64 a1)
{
*(_WORD *)(a1 + 8) |= 0x8000u;
}

original_code:
static inline void us_trie_node_set_end( us_trie_node_t *self )
{
    self->m_flags |= ( uint16_t )( 0x8000 );
}

canonical_original_code:
static inline void us_trie_node_set_end(struct us_trie_node_s *self)
{
    self->m_flags |= ( unsigned short )( 0x8000 );
}

variable_types: struct us_trie_node_s { short m_parent; short m_sibling; short m_child; char m_value; unsigned short m_flags; } *


decompiled_code:
__int64 __fastcall us_trie_dyn_destroy(__int64 a1)
{
__int64 result; // rax

if ( *(_QWORD *)(a1 + 72) )
{
result = *(_QWORD *)(a1 + 64);
if ( !result )
return result;
(*(void (__fastcall **)(_QWORD))(result + 24))(*(_QWORD *)(a1 + 64));
}
result = *(_QWORD *)(a1 + 64);
if ( result )
result = (*(__int64 (__fastcall **)(_QWORD, __int64))(result + 24))(*(_QWORD *)(a1 + 64), a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax

if ( *(_QWORD *)(a1 + 72) )
{
result = *(_QWORD *)(a1 + 64);
if ( !result )
return result;
(*(void (__fastcall **)(_QWORD))(result + 24))(*(_QWORD *)(a1 + 64));
}
result = *(_QWORD *)(a1 + 64);
if ( result )
result = (*(__int64 (__fastcall **)(_QWORD, __int64))(result + 24))(*(_QWORD *)(a1 + 64), a1);
return result;
}

original_code:
void us_trie_dyn_destroy( us_trie_dyn_t *self )
{
    if ( self->m_nodes != 0 )
    {
        do { if ( ( self->m_allocator ) != 0 && ( self->m_nodes ) != 0 ) ( self->m_allocator )->free( ( self->m_allocator ), ( self->m_nodes ) ); } while ( 0 );
    }
    do { if ( ( self->m_allocator ) != 0 && ( self ) != 0 ) ( self->m_allocator )->free( ( self->m_allocator ), ( self ) ); } while ( 0 );
}

canonical_original_code:
void us_trie_dyn_destroy(struct us_trie_dyn_s *self)
{
    if ( self->m_nodes != 0 )
    {
        do { if ( ( self->m_allocator ) != 0 && ( self->m_nodes ) != 0 ) ( self->m_allocator )->free( ( self->m_allocator ), ( self->m_nodes ) ); } while ( 0 );
    }
    do { if ( ( self->m_allocator ) != 0 && ( self ) != 0 ) ( self->m_allocator )->free( ( self->m_allocator ), ( self ) ); } while ( 0 );
}

variable_types: struct us_trie_dyn_s { struct us_trie_s { short m_max_nodes; short m_num_nodes; struct us_trie_node_s { short m_parent; short m_sibling; short m_child; char m_value; unsigned short m_flags; } *m_nodes; short m_first_free; _Bool (*m_query_ignorer)(char); _Bool (*m_db_ignorer)(char); int (*m_db_skip)(char); int (*m_comparator)(char, char); } m_base; void (*destroy)(struct us_trie_dyn_s *); struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *m_allocator; struct us_trie_node_s *m_nodes; } *

user_defined_types: struct us_trie_dyn_s { struct us_trie_s m_base; void (*destroy)(struct us_trie_dyn_s *); struct us_allocator_s *m_allocator; struct us_trie_node_s *m_nodes; }

user_defined_types: struct us_trie_s { short m_max_nodes; short m_num_nodes; struct us_trie_node_s *m_nodes; short m_first_free; _Bool (*m_query_ignorer)(char); _Bool (*m_db_ignorer)(char); int (*m_db_skip)(char); int (*m_comparator)(char, char); }


original_code:
void us_trie_clear( us_trie_t *self )
{
    us_trie_node_id_t i;
    for ( i = 0; i < self->m_max_nodes; ++i )
    {
        us_trie_node_clear( &self->m_nodes[i] );
        self->m_first_free = 0;
        self->m_num_nodes = 0;
    }
}

canonical_original_code:
void us_trie_clear(struct us_trie_s *self)
{
    short i;
    for ( i = 0; i < self->m_max_nodes; ++i )
    {
        us_trie_node_clear( &self->m_nodes[i] );
        self->m_first_free = 0;
        self->m_num_nodes = 0;
    }
}

variable_types: struct us_trie_s { short m_max_nodes; short m_num_nodes; struct us_trie_node_s { short m_parent; short m_sibling; short m_child; char m_value; unsigned short m_flags; } *m_nodes; short m_first_free; _Bool (*m_query_ignorer)(char); _Bool (*m_db_ignorer)(char); int (*m_db_skip)(char); int (*m_comparator)(char, char); } *

variable_types: i short


original_code:
void us_trie_remove( us_trie_t *self, us_trie_node_id_t item )
{
    us_trie_node_release( &self->m_nodes[item] );
    if ( item < self->m_first_free )
        self->m_first_free = item;
}

canonical_original_code:
void us_trie_remove(struct us_trie_s *self, short item)
{
    us_trie_node_release( &self->m_nodes[item] );
    if ( item < self->m_first_free )
        self->m_first_free = item;
}

variable_types: item short

user_defined_types: struct us_trie_node_s { short m_parent; short m_sibling; short m_child; char m_value; unsigned short m_flags; }


original_code:
us_trie_node_id_t us_trie_find_next_free( us_trie_t *self )
{
    us_trie_node_id_t num = self->m_max_nodes;
    for ( ; self->m_first_free < num; ++self->m_first_free )
    {
        if ( us_trie_node_is_free( &self->m_nodes[self->m_first_free] ) )
        {
            break;
        }
    }
    if ( self->m_first_free == num )
    {
        self->m_first_free = -1;
    }
    return self->m_first_free;
}

canonical_original_code:
short us_trie_find_next_free(struct us_trie_s *self)
{
    short num = self->m_max_nodes;
    for ( ; self->m_first_free < num; ++self->m_first_free )
    {
        if ( us_trie_node_is_free( &self->m_nodes[self->m_first_free] ) )
        {
            break;
        }
    }
    if ( self->m_first_free == num )
    {
        self->m_first_free = -1;
    }
    return self->m_first_free;
}

variable_types: num short

return_type: short


original_code:
us_trie_node_id_t
    us_trie_add_child( us_trie_t *self, us_trie_node_id_t parent_item, us_trie_node_value_t value, us_trie_node_flags_t flags )
{
    us_trie_node_id_t item = us_trie_find_next_free( self );
    us_trie_node_t *buf = self->m_nodes;
    buf[item].m_sibling = 0;
    buf[item].m_child = 0;
    buf[item].m_value = value;
    buf[item].m_flags = flags;
    buf[item].m_parent = parent_item;
    if ( parent_item != item && parent_item != -1 )
    {
        int last_child = buf[parent_item].m_child;
        if ( last_child )
        {
            while ( buf[last_child].m_sibling )
            {
                last_child = buf[last_child].m_sibling;
            }
            buf[last_child].m_sibling = item;
        }
        else
        {
            if ( parent_item != -1 )
                buf[parent_item].m_child = item;
        }
    }
    if ( item >= self->m_num_nodes )
        self->m_num_nodes = item + 1;
    return item;
}

canonical_original_code:
short us_trie_add_child(struct us_trie_s *self, short parent_item, char value, unsigned short flags)
{
    short item = us_trie_find_next_free( self );
    struct us_trie_node_s *buf = self->m_nodes;
    buf[item].m_sibling = 0;
    buf[item].m_child = 0;
    buf[item].m_value = value;
    buf[item].m_flags = flags;
    buf[item].m_parent = parent_item;
    if ( parent_item != item && parent_item != -1 )
    {
        int last_child = buf[parent_item].m_child;
        if ( last_child )
        {
            while ( buf[last_child].m_sibling )
            {
                last_child = buf[last_child].m_sibling;
            }
            buf[last_child].m_sibling = item;
        }
        else
        {
            if ( parent_item != -1 )
                buf[parent_item].m_child = item;
        }
    }
    if ( item >= self->m_num_nodes )
        self->m_num_nodes = item + 1;
    return item;
}

variable_types: value char

variable_types:
flags
unsigned short


original_code:
us_trie_node_id_t us_trie_add_sibling( us_trie_t *self,
                                       us_trie_node_id_t last_sibling_item,
                                       us_trie_node_value_t value,
                                       us_trie_node_flags_t flags )
{
    us_trie_node_id_t item = us_trie_find_next_free( self );
    us_trie_node_t *buf = self->m_nodes;
    buf[item].m_sibling = 0;
    buf[item].m_child = 0;
    buf[item].m_value = value;
    buf[item].m_flags = flags;
    buf[item].m_parent = buf[last_sibling_item].m_parent;
    buf[last_sibling_item].m_sibling = item;
    if ( item > self->m_num_nodes )
        self->m_num_nodes = item;
    return item;
}

canonical_original_code:
short us_trie_add_sibling(struct us_trie_s *self, short last_sibling_item, char value, unsigned short flags)
{
    short item = us_trie_find_next_free( self );
    struct us_trie_node_s *buf = self->m_nodes;
    buf[item].m_sibling = 0;
    buf[item].m_child = 0;
    buf[item].m_value = value;
    buf[item].m_flags = flags;
    buf[item].m_parent = buf[last_sibling_item].m_parent;
    buf[last_sibling_item].m_sibling = item;
    if ( item > self->m_num_nodes )
        self->m_num_nodes = item;
    return item;
}


original_code:
void us_trie_add( us_trie_t *self, const us_trie_node_value_t *list, int16_t list_len, us_trie_node_flags_t flags )
{
    us_trie_node_id_t list_pos = 0;
    while ( list_pos < list_len && self->m_query_ignorer( list[list_pos] ) )
        ++list_pos;
    if ( us_trie_node_is_free( &self->m_nodes[0] ) )
    {
        us_trie_node_id_t i = -1;
        while ( list_pos < list_len )
        {
            if ( !self->m_db_ignorer( list[list_pos] ) )
            {
                i = us_trie_add_child( self, i, list[list_pos], flags );
            }
            list_pos++;
        }
        i = us_trie_add_child( self, i, 0, flags );
        us_trie_node_set_end( &self->m_nodes[i] );
        return;
    }
    else
    {
        us_trie_node_id_t i = 0;
        while ( 1 )
        {
            while ( list_pos < list_len && self->m_query_ignorer( list[list_pos] ) )
                ++list_pos;
            if ( list_pos == list_len )
            {
                i = us_trie_add_child( self, self->m_nodes[i].m_parent, 0, flags );
                us_trie_node_set_end( &self->m_nodes[i] );
                return;
            }
            if ( us_trie_find_sibling( self, i, list[list_pos], &i ) )
            {
                ++list_pos;
                if ( self->m_nodes[i].m_child == 0 )
                {
                    while ( list_pos < list_len )
                    {
                        if ( !self->m_query_ignorer( list[list_pos] ) )
                            i = us_trie_add_child( self, i, list[list_pos], flags );
                        list_pos++;
                    }
                    i = us_trie_add_child( self, i, 0, flags );
                    us_trie_node_set_end( &self->m_nodes[i] );
                    return;
                }
                else
                {
                    i = self->m_nodes[i].m_child;
                }
            }
            else
            {
                i = us_trie_add_sibling( self, i, list[list_pos++], flags );
                while ( list_pos < list_len )
                {
                    if ( !self->m_query_ignorer( list[list_pos] ) )
                        i = us_trie_add_child( self, i, list[list_pos], flags );
                    list_pos++;
                }
                i = us_trie_add_child( self, i, 0, flags );
                us_trie_node_set_end( &self->m_nodes[i] );
                return;
            }
        }
    }
}

canonical_original_code:
void us_trie_add(struct us_trie_s *self, char *list, short list_len, unsigned short flags)
{
    short list_pos = 0;
    while ( list_pos < list_len && self->m_query_ignorer( list[list_pos] ) )
        ++list_pos;
    if ( us_trie_node_is_free( &self->m_nodes[0] ) )
    {
        short i = -1;
        while ( list_pos < list_len )
        {
            if ( !self->m_db_ignorer( list[list_pos] ) )
            {
                i = us_trie_add_child( self, i, list[list_pos], flags );
            }
            list_pos++;
        }
        i = us_trie_add_child( self, i, 0, flags );
        us_trie_node_set_end( &self->m_nodes[i] );
        return;
    }
    else
    {
        short i = 0;
        while ( 1 )
        {
            while ( list_pos < list_len && self->m_query_ignorer( list[list_pos] ) )
                ++list_pos;
            if ( list_pos == list_len )
            {
                i = us_trie_add_child( self, self->m_nodes[i].m_parent, 0, flags );
                us_trie_node_set_end( &self->m_nodes[i] );
                return;
            }
            if ( us_trie_find_sibling( self, i, list[list_pos], &i ) )
            {
                ++list_pos;
                if ( self->m_nodes[i].m_child == 0 )
                {
                    while ( list_pos < list_len )
                    {
                        if ( !self->m_query_ignorer( list[list_pos] ) )
                            i = us_trie_add_child( self, i, list[list_pos], flags );
                        list_pos++;
                    }
                    i = us_trie_add_child( self, i, 0, flags );
                    us_trie_node_set_end( &self->m_nodes[i] );
                    return;
                }
                else
                {
                    i = self->m_nodes[i].m_child;
                }
            }
            else
            {
                i = us_trie_add_sibling( self, i, list[list_pos++], flags );
                while ( list_pos < list_len )
                {
                    if ( !self->m_query_ignorer( list[list_pos] ) )
                        i = us_trie_add_child( self, i, list[list_pos], flags );
                    list_pos++;
                }
                i = us_trie_add_child( self, i, 0, flags );
                us_trie_node_set_end( &self->m_nodes[i] );
                return;
            }
        }
    }
}

variable_types:
list
char *


decompiled_code:
bool __fastcall us_buffer_can_write_byte(_QWORD *a1)
{
return (unsigned __int64)(a1[3] + 1LL) % a1[5] != a1[4];
}

canonical_decompiled_code:
bool __fastcall func0(_QWORD *a1)
{
return (unsigned __int64)(a1[3] + 1LL) % a1[5] != a1[4];
}

original_code:
static inline _Bool us_buffer_can_write_byte( const us_buffer_t *self )
{
    return ( ( self->m_next_in + 1 ) % self->m_max_length ) != self->m_next_out;
}

canonical_original_code:
static inline _Bool us_buffer_can_write_byte(struct us_buffer_s *self)
{
    return ( ( self->m_next_in + 1 ) % self->m_max_length ) != self->m_next_out;
}


decompiled_code:
__int64 __fastcall us_buffer_append_byte(_QWORD *a1, char a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx

LOBYTE(v2) = us_buffer_can_write_byte(a1);
v3 = v2;
if ( (_BYTE)v2 )
us_buffer_write_byte(a1, a2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, char a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx

LOBYTE(v2) = func0(a1);
v3 = v2;
if ( (_BYTE)v2 )
func1(a1, a2);
return v3;
}

original_code:
static inline _Bool us_buffer_append_byte( us_buffer_t *self, int value )
{
    _Bool r = 0;
    if ( us_buffer_can_write_byte( self ) )
    {
        uint8_t byte_value = (uint8_t)value;
        us_buffer_write_byte( self, byte_value );
        r = 1;
    }
    return r;
}

canonical_original_code:
static inline _Bool us_buffer_append_byte(struct us_buffer_s *self, int value)
{
    _Bool r = 0;
    if ( us_buffer_can_write_byte( self ) )
    {
        unsigned char byte_value = (uint8_t)value;
        us_buffer_write_byte( self, byte_value );
        r = 1;
    }
    return r;
}

variable_types: value int


decompiled_code:
bool __fastcall us_cgi_is_escapable(char a1)
{
bool result; // al
const unsigned __int16 *v2; // rcx
const char *v3; // rdx

result = 1;
if ( a1 >= 0 )
{
v2 = *_ctype_b_loc();
result = 0;
if ( (v2[a1] & 8) == 0 )
{
if ( a1 == 33 )
{
result = 1;
}
else
{
v3 = "!*'();:@&=+$,/?%#[]";
do
{
++v3;
result = *v3 == 0 || *v3 == (unsigned __int8)a1;
}
while ( !result );
}
}
}
return result;
}

canonical_decompiled_code:
bool __fastcall func3(char a1)
{
bool result; // al
const unsigned __int16 *v2; // rcx
const char *v3; // rdx

result = 1;
if ( a1 >= 0 )
{
v2 = *_ctype_b_loc();
result = 0;
if ( (v2[a1] & 8) == 0 )
{
if ( a1 == 33 )
{
result = 1;
}
else
{
v3 = "!*'();:@&=+$,/?%#[]";
do
{
++v3;
result = *v3 == 0 || *v3 == (unsigned __int8)a1;
}
while ( !result );
}
}
}
return result;
}

original_code:
_Bool us_cgi_is_escapable( char c )
{
    const char *p;
    if ( ( c & 0x80 ) == 0x80 )
    {
        return 1;
    }
    if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalnum) )
    {
        return 0;
    }
    for ( p = us_cgi_rfc3986_reserved_chars; *p != 0; ++p )
    {
        if ( *p == c )
            return 1;
    }
    return 1;
}

canonical_original_code:
_Bool us_cgi_is_escapable(char c)
{
    char *p;
    if ( ( c & 0x80 ) == 0x80 )
    {
        return 1;
    }
    if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalnum) )
    {
        return 0;
    }
    for ( p = us_cgi_rfc3986_reserved_chars; *p != 0; ++p )
    {
        if ( *p == c )
            return 1;
    }
    return 1;
}

variable_types: c char


decompiled_code:
__int64 __fastcall us_cgi_unescape(char *a1, int a2, _QWORD *a3)
{
char *v4; // rbx
char v5; // r13
int v6; // er12
char v7; // bp
__int32_t v8; // edx
char v9; // al
__int64 result; // rax

if ( a2 <= 0 )
return 1LL;
v4 = a1;
v5 = 0;
v6 = 0;
do
{
v7 = *v4;
if ( v6 )
{
v8 = (*_ctype_toupper_loc())[v7];
v9 = v8 - 55;
if ( (char)v8 <= 9 )
v9 = v8 - 48;
v5 = v9 + 16 * v5;
if ( !--v6 )
{
result = us_buffer_append_byte(a3, v5);
if ( !(_BYTE)result )
return result;
}
}
else if ( v7 == 37 )
{
v5 = 0;
v6 = 2;
}
else
{
result = us_buffer_append_byte(a3, v7);
if ( !(_BYTE)result )
return result;
}
++v4;
}
while ( v4 != &a1[a2 - 1 + 1] );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, int a2, _QWORD *a3)
{
char *v4; // rbx
char v5; // r13
int v6; // er12
char v7; // bp
__int32_t v8; // edx
char v9; // al
__int64 result; // rax

if ( a2 <= 0 )
return 1LL;
v4 = a1;
v5 = 0;
v6 = 0;
do
{
v7 = *v4;
if ( v6 )
{
v8 = (*_ctype_toupper_loc())[v7];
v9 = v8 - 55;
if ( (char)v8 <= 9 )
v9 = v8 - 48;
v5 = v9 + 16 * v5;
if ( !--v6 )
{
result = func2(a3, v5);
if ( !(_BYTE)result )
return result;
}
}
else if ( v7 == 37 )
{
v5 = 0;
v6 = 2;
}
else
{
result = func2(a3, v7);
if ( !(_BYTE)result )
return result;
}
++v4;
}
while ( v4 != &a1[a2 - 1 + 1] );
return 1LL;
}

original_code:
_Bool us_cgi_unescape( const char *src, int src_len, us_buffer_t *dest_buf )
{
    int i;
    int in_percent = 0;
    int partial = 0;
    for ( i = 0; i < src_len; ++i )
    {
        char c = src[i];
        if ( in_percent )
        {
            int v;
            c = toupper( c );
            v = c - '0';
            if ( c > 9 )
                v = c - 'A' + 10;
            partial = partial << 4;
            partial += v;
            in_percent--;
            if ( in_percent == 0 )
            {
                c = (char)partial;
                if ( !us_buffer_append_byte( dest_buf, c ) )
                {
                    return 0;
                }
            }
        }
        else if ( c == '%' )
        {
            in_percent = 2;
            partial = 0;
        }
        else
        {
            if ( !us_buffer_append_byte( dest_buf, c ) )
            {
                return 0;
            }
        }
    }
    return 1;
}

canonical_original_code:
_Bool us_cgi_unescape(char *src, int src_len, struct us_buffer_s *dest_buf)
{
    int i;
    int in_percent = 0;
    int partial = 0;
    for ( i = 0; i < src_len; ++i )
    {
        char c = src[i];
        if ( in_percent )
        {
            int v;
            c = toupper( c );
            v = c - '0';
            if ( c > 9 )
                v = c - 'A' + 10;
            partial = partial << 4;
            partial += v;
            in_percent--;
            if ( in_percent == 0 )
            {
                c = (char)partial;
                if ( !us_buffer_append_byte( dest_buf, c ) )
                {
                    return 0;
                }
            }
        }
        else if ( c == '%' )
        {
            in_percent = 2;
            partial = 0;
        }
        else
        {
            if ( !us_buffer_append_byte( dest_buf, c ) )
            {
                return 0;
            }
        }
    }
    return 1;
}

variable_types:
src
char *

variable_types: i int

variable_types: partial int

variable_types: v int


decompiled_code:
__int64 __fastcall us_cgi_escape(char *a1, int a2, _QWORD *a3)
{
char *v4; // rbx
__int64 result; // rax
unsigned __int8 v6; // r13
char v7; // r14
char v8[44]; // [rsp+0h] [rbp-2Ch] BYREF

if ( a2 <= 0 )
return 1LL;
v4 = a1;
do
{
v6 = *v4;
v7 = *v4;
if ( us_cgi_is_escapable(*v4) )
{
v8[0] = 37;
v8[1] = us_cgi_tohexdigit[v6 >> 4];
v8[2] = us_cgi_tohexdigit[v6 & 0xF];
result = us_buffer_append_data(a3, v8, 3LL);
if ( !(_BYTE)result )
return result;
}
else
{
result = us_buffer_append_byte(a3, v7);
if ( !(_BYTE)result )
return result;
}
++v4;
}
while ( v4 != &a1[a2 - 1 + 1] );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, int a2, _QWORD *a3)
{
char *v4; // rbx
__int64 result; // rax
unsigned __int8 v6; // r13
char v7; // r14
char v8[44]; // [rsp+0h] [rbp-2Ch] BYREF

if ( a2 <= 0 )
return 1LL;
v4 = a1;
do
{
v6 = *v4;
v7 = *v4;
if ( func3(*v4) )
{
v8[0] = 37;
v8[1] = us_cgi_tohexdigit[v6 >> 4];
v8[2] = us_cgi_tohexdigit[v6 & 0xF];
result = us_buffer_append_data(a3, v8, 3LL);
if ( !(_BYTE)result )
return result;
}
else
{
result = func2(a3, v7);
if ( !(_BYTE)result )
return result;
}
++v4;
}
while ( v4 != &a1[a2 - 1 + 1] );
return 1LL;
}

original_code:
_Bool us_cgi_escape( const char *src, int src_len, us_buffer_t *dest_buf )
{
    int i;
    for ( i = 0; i < src_len; ++i )
    {
        char c = src[i];
        if ( us_cgi_is_escapable( c ) )
        {
            char escaped[4];
            escaped[0] = '%';
            escaped[1] = us_cgi_tohexdigit[( c >> 4 ) & 0xf];
            escaped[2] = us_cgi_tohexdigit[c & 0xf];
            if ( !us_buffer_append_data( dest_buf, escaped, 3 ) )
            {
                return 0;
            }
        }
        else
        {
            if ( !us_buffer_append_byte( dest_buf, c ) )
            {
                return 0;
            }
        }
    }
    return 1;
}

canonical_original_code:
_Bool us_cgi_escape(char *src, int src_len, struct us_buffer_s *dest_buf)
{
    int i;
    for ( i = 0; i < src_len; ++i )
    {
        char c = src[i];
        if ( us_cgi_is_escapable( c ) )
        {
            char escaped[4];
            escaped[0] = '%';
            escaped[1] = us_cgi_tohexdigit[( c >> 4 ) & 0xf];
            escaped[2] = us_cgi_tohexdigit[c & 0xf];
            if ( !us_buffer_append_data( dest_buf, escaped, 3 ) )
            {
                return 0;
            }
        }
        else
        {
            if ( !us_buffer_append_byte( dest_buf, c ) )
            {
                return 0;
            }
        }
    }
    return 1;
}

variable_types: struct us_buffer_s { void (*destroy)(struct us_buffer_s *self); struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *m_allocator; unsigned char *m_buffer; unsigned long m_next_in; unsigned long m_next_out; unsigned long m_max_length; } *

variable_types:
escaped
char [4]


decompiled_code:
void us_platform_sigterm()
{
us_platform_sigterm_seen = 1;
}

canonical_decompiled_code:
void func0()
{
us_platform_sigterm_seen = 1;
}

original_code:
static void us_platform_sigterm( int s )
{
    (void)s;
    us_platform_sigterm_seen = 1;
}

canonical_original_code:
static void us_platform_sigterm(int s)
{
    (void)s;
    us_platform_sigterm_seen = 1;
}

variable_types: s int


decompiled_code:
void us_platform_sigint()
{
us_platform_sigint_seen = 1;
}

canonical_decompiled_code:
void func1()
{
us_platform_sigint_seen = 1;
}

original_code:
static void us_platform_sigint( int s )
{
    (void)s;
    us_platform_sigint_seen = 1;
}

canonical_original_code:
static void us_platform_sigint(int s)
{
    (void)s;
    us_platform_sigint_seen = 1;
}


decompiled_code:
__int64 us_platform_init_sockets()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)(us_platform_sigterm + 1);
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
sigaction(13, &v1, 0LL);
v1.sa_handler = (__sighandler_t)us_platform_sigterm;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
sigaction(15, &v1, 0LL);
v1.sa_handler = (__sighandler_t)us_platform_sigint;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
sigaction(2, &v1, 0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)(us_platform_sigterm + 1);
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
sigaction(13, &v1, 0LL);
v1.sa_handler = (__sighandler_t)us_platform_sigterm;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
sigaction(15, &v1, 0LL);
v1.sa_handler = (__sighandler_t)us_platform_sigint;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
sigaction(2, &v1, 0LL);
return 1LL;
}

original_code:
_Bool us_platform_init_sockets( void )
{
    struct sigaction act;
    act.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
    sigemptyset( &act.sa_mask );
    act.sa_flags = 0;
    sigaction( 13, &act, ((void *)0) );
    act.__sigaction_handler.sa_handler = us_platform_sigterm;
    sigemptyset( &act.sa_mask );
    act.sa_flags = 0;
    sigaction( 15, &act, ((void *)0) );
    act.__sigaction_handler.sa_handler = us_platform_sigint;
    sigemptyset( &act.sa_mask );
    act.sa_flags = 0;
    sigaction( 2, &act, ((void *)0) );
    return 1;
}

canonical_original_code:
_Bool us_platform_init_sockets()
{
    struct sigaction act;
    act.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
    sigemptyset( &act.sa_mask );
    act.sa_flags = 0;
    sigaction( 13, &act, ((void *)0) );
    act.__sigaction_handler.sa_handler = us_platform_sigterm;
    sigemptyset( &act.sa_mask );
    act.sa_flags = 0;
    sigaction( 15, &act, ((void *)0) );
    act.__sigaction_handler.sa_handler = us_platform_sigint;
    sigemptyset( &act.sa_mask );
    act.sa_flags = 0;
    sigaction( 2, &act, ((void *)0) );
    return 1;
}

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

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

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


decompiled_code:
int __fastcall us_gettimeofday(struct timeval *a1)
{
int result; // eax

result = gettimeofday(a1, 0LL);
if ( result )
{
perror("gettimeofday");
abort();
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(struct timeval *a1)
{
int result; // eax

result = gettimeofday(a1, 0LL);
if ( result )
{
perror("gettimeofday");
abort();
}
return result;
}

original_code:
void us_gettimeofday( struct timeval *tv )
{
    int r;
    r = gettimeofday( tv, 0 );
    if ( r != 0 )
    {
        perror( "gettimeofday" );
        abort();
    }
}

canonical_original_code:
void us_gettimeofday(struct timeval *tv)
{
    int r;
    r = gettimeofday( tv, 0 );
    if ( r != 0 )
    {
        perror( "gettimeofday" );
        abort();
    }
}

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

variable_types: r int


decompiled_code:
__int64 us_test_http_request()
{
__int64 v0; // rax
unsigned int v1; // ebp
void (__fastcall **v2)(_QWORD); // rbx
__int64 v4; // rax
void (__fastcall **v5)(_QWORD); // r12
__int64 v6; // rax
void (__fastcall **v7)(_QWORD); // r13

v0 = us_http_request_header_create(us_testutil_session_allocator);
v1 = 0;
if ( v0 )
{
v2 = (void (__fastcall **)(_QWORD))v0;
v1 = us_http_request_header_init_get(v0, "www.jdkoftinoff.com:80", "/products/d-mitri/");
if ( (_BYTE)v1 )
{
v4 = us_buffer_create(us_testutil_session_allocator, 4096LL);
v5 = (void (__fastcall **)(_QWORD))v4;
v1 = 0;
if ( v4 )
{
v1 = us_http_request_header_flatten(v2, v4);
if ( (_BYTE)v1 )
{
if ( us_log_level > 2 )
us_log_info_proc("generated request:");
us_buffer_print_string(v5, us_testutil_printer_stdout);
v6 = us_http_request_header_create(us_testutil_session_allocator);
v7 = (void (__fastcall **)(_QWORD))v6;
if ( v6 )
{
if ( (unsigned __int8)us_http_request_header_parse(v6, v5) )
{
if ( us_log_level > 2 )
us_log_info_proc("parsed request:");
us_buffer_reset(v5);
v1 = us_http_request_header_flatten(v7, v5);
us_buffer_print_string(v5, us_testutil_printer_stdout);
}
(*v7)(v7);
}
}
(*v5)(v5);
}
(*v2)(v2);
}
}
return v1;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
unsigned int v1; // ebp
void (__fastcall **v2)(_QWORD); // rbx
__int64 v4; // rax
void (__fastcall **v5)(_QWORD); // r12
__int64 v6; // rax
void (__fastcall **v7)(_QWORD); // r13

v0 = us_http_request_header_create(us_testutil_session_allocator);
v1 = 0;
if ( v0 )
{
v2 = (void (__fastcall **)(_QWORD))v0;
v1 = us_http_request_header_init_get(v0, "www.jdkoftinoff.com:80", "/products/d-mitri/");
if ( (_BYTE)v1 )
{
v4 = us_buffer_create(us_testutil_session_allocator, 4096LL);
v5 = (void (__fastcall **)(_QWORD))v4;
v1 = 0;
if ( v4 )
{
v1 = us_http_request_header_flatten(v2, v4);
if ( (_BYTE)v1 )
{
if ( us_log_level > 2 )
us_log_info_proc("generated request:");
us_buffer_print_string(v5, us_testutil_printer_stdout);
v6 = us_http_request_header_create(us_testutil_session_allocator);
v7 = (void (__fastcall **)(_QWORD))v6;
if ( v6 )
{
if ( (unsigned __int8)us_http_request_header_parse(v6, v5) )
{
if ( us_log_level > 2 )
us_log_info_proc("parsed request:");
us_buffer_reset(v5);
v1 = us_http_request_header_flatten(v7, v5);
us_buffer_print_string(v5, us_testutil_printer_stdout);
}
(*v7)(v7);
}
}
(*v5)(v5);
}
(*v2)(v2);
}
}
return v1;
}

original_code:
static _Bool us_test_http_request( void )
{
    _Bool r = 0;
    us_http_request_header_t *req;
    req = us_http_request_header_create( us_testutil_session_allocator );
    if ( req )
    {
        r = us_http_request_header_init_get( req, "www.jdkoftinoff.com:80", "/products/d-mitri/" );
    }
    if ( r )
    {
        us_buffer_t *buf;
        buf = us_buffer_create( us_testutil_session_allocator, 4096 );
        if ( buf )
        {
            r &= us_http_request_header_flatten( req, buf );
            if ( r )
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "generated request:" ); } while ( 0 );
                us_buffer_print_string( buf, us_testutil_printer_stdout );
                {
                    us_http_request_header_t *parsed_req;
                    parsed_req = us_http_request_header_create( us_testutil_session_allocator );
                    if ( parsed_req )
                    {
                        if ( us_http_request_header_parse( parsed_req, buf ) )
                        {
                            do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "parsed request:" ); } while ( 0 );
                            us_buffer_reset( buf );
                            r &= us_http_request_header_flatten( parsed_req, buf );
                            us_buffer_print_string( buf, us_testutil_printer_stdout );
                        }
                        parsed_req->destroy( parsed_req );
                    }
                }
            }
            buf->destroy( buf );
        }
        else
        {
            r = 0;
        }
        req->destroy( req );
    }
    else
    {
        r = 0;
    }
    return r;
}

canonical_original_code:
static _Bool us_test_http_request()
{
    _Bool r = 0;
    struct us_http_request_header_s *req;
    req = us_http_request_header_create( us_testutil_session_allocator );
    if ( req )
    {
        r = us_http_request_header_init_get( req, "www.jdkoftinoff.com:80", "/products/d-mitri/" );
    }
    if ( r )
    {
        struct us_buffer_s *buf;
        buf = us_buffer_create( us_testutil_session_allocator, 4096 );
        if ( buf )
        {
            r &= us_http_request_header_flatten( req, buf );
            if ( r )
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "generated request:" ); } while ( 0 );
                us_buffer_print_string( buf, us_testutil_printer_stdout );
                {
                    struct us_http_request_header_s *parsed_req;
                    parsed_req = us_http_request_header_create( us_testutil_session_allocator );
                    if ( parsed_req )
                    {
                        if ( us_http_request_header_parse( parsed_req, buf ) )
                        {
                            do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "parsed request:" ); } while ( 0 );
                            us_buffer_reset( buf );
                            r &= us_http_request_header_flatten( parsed_req, buf );
                            us_buffer_print_string( buf, us_testutil_printer_stdout );
                        }
                        parsed_req->destroy( parsed_req );
                    }
                }
            }
            buf->destroy( buf );
        }
        else
        {
            r = 0;
        }
        req->destroy( req );
    }
    else
    {
        r = 0;
    }
    return r;
}

variable_types: struct us_http_request_header_s { void (*destroy)(struct us_http_request_header_s *); struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *m_allocator; char *m_method; char *m_path; char *m_version; struct us_http_header_item_list_s { void (*destroy)(struct us_http_header_item_list_s *self); struct us_http_header_item_s { char *m_key; char *m_value; struct us_http_header_item_s *m_next; } *(*add)(struct us_http_header_item_list_s *self, char *key, char *value); struct us_http_header_item_s *(*addn)(struct us_http_header_item_list_s *self, char *key, int key_len, char *value, int value_len); _Bool (*remove)(struct us_http_header_item_list_s *self, struct us_http_header_item_s *item); struct us_http_header_item_s *(*find)(struct us_http_header_item_list_s *self, char *key); struct us_allocator_s *m_allocator; struct us_http_header_item_s *m_first; } *m_items; } *

user_defined_types: struct us_http_request_header_s { void (*destroy)(struct us_http_request_header_s *); struct us_allocator_s *m_allocator; char *m_method; char *m_path; char *m_version; struct us_http_header_item_list_s *m_items; }

user_defined_types: struct us_http_header_item_list_s { void (*destroy)(struct us_http_header_item_list_s *self); struct us_http_header_item_s *(*add)(struct us_http_header_item_list_s *self, char *key, char *value); struct us_http_header_item_s *(*addn)(struct us_http_header_item_list_s *self, char *key, int key_len, char *value, int value_len); _Bool (*remove)(struct us_http_header_item_list_s *self, struct us_http_header_item_s *item); struct us_http_header_item_s *(*find)(struct us_http_header_item_list_s *self, char *key); struct us_allocator_s *m_allocator; struct us_http_header_item_s *m_first; }