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

v0 = us_http_response_header_create(us_testutil_session_allocator);
v1 = 0;
if ( v0 )
{
v2 = v0;
v3 = us_http_response_header_init_ok(v0, 200LL, "text/html", 76LL, 1LL);
v4 = us_buffer_create(us_testutil_session_allocator, 4096LL);
v5 = (void (__fastcall **)(_QWORD))v4;
if ( v4 )
{
v1 = v3;
LOBYTE(v1) = us_http_response_header_flatten(v2, v4) & v3;
if ( (_BYTE)v1 )
{
if ( us_log_level > 2 )
us_log_info_proc("generated response:");
us_buffer_print_string(v5, us_testutil_printer_stdout);
(*(void (**)(_QWORD, const char *, ...))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"%s\n",
"<title>Test</title>
Hello There
");
v6 = us_http_response_header_create(us_testutil_session_allocator);
v7 = (void (__fastcall **)(_QWORD))v6;
if ( v6 )
{
if ( (unsigned __int8)us_http_response_header_parse(v6, v5) )
{
if ( us_log_level > 2 )
us_log_info_proc("parsed response:");
us_buffer_reset(v5);
v1 = us_http_response_header_flatten(v7, v5);
us_buffer_print_string(v5, us_testutil_printer_stdout);
}
(*v7)(v7);
}
}
(*v5)(v5);
}
}
return v1;
}

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

v0 = us_http_response_header_create(us_testutil_session_allocator);
v1 = 0;
if ( v0 )
{
v2 = v0;
v3 = us_http_response_header_init_ok(v0, 200LL, "text/html", 76LL, 1LL);
v4 = us_buffer_create(us_testutil_session_allocator, 4096LL);
v5 = (void (__fastcall **)(_QWORD))v4;
if ( v4 )
{
v1 = v3;
LOBYTE(v1) = us_http_response_header_flatten(v2, v4) & v3;
if ( (_BYTE)v1 )
{
if ( us_log_level > 2 )
us_log_info_proc("generated response:");
us_buffer_print_string(v5, us_testutil_printer_stdout);
(*(void (**)(_QWORD, const char *, ...))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"%s\n",
"<title>Test</title>
Hello There
");
v6 = us_http_response_header_create(us_testutil_session_allocator);
v7 = (void (__fastcall **)(_QWORD))v6;
if ( v6 )
{
if ( (unsigned __int8)us_http_response_header_parse(v6, v5) )
{
if ( us_log_level > 2 )
us_log_info_proc("parsed response:");
us_buffer_reset(v5);
v1 = us_http_response_header_flatten(v7, v5);
us_buffer_print_string(v5, us_testutil_printer_stdout);
}
(*v7)(v7);
}
}
(*v5)(v5);
}
}
return v1;
}

original_code:
static _Bool us_test_http_response( void )
{
    _Bool r = 0;
    const char *html = "<title>Test</title>
Hello There
";
    us_http_response_header_t *resp;
    resp = us_http_response_header_create( us_testutil_session_allocator );
    if ( resp )
    {
        r = us_http_response_header_init_ok( resp, 200, "text/html", ( uint32_t )( strlen( html ) ), 1 );
    }
    if ( resp )
    {
        us_buffer_t *buf;
        buf = us_buffer_create( us_testutil_session_allocator, 4096 );
        if ( buf )
        {
            r &= us_http_response_header_flatten( resp, buf );
            if ( r )
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "generated response:" ); } while ( 0 );
                us_buffer_print_string( buf, us_testutil_printer_stdout );
                us_testutil_printer_stdout->printf( us_testutil_printer_stdout, "%s\n", html );
                {
                    us_http_response_header_t *parsed_resp;
                    parsed_resp = us_http_response_header_create( us_testutil_session_allocator );
                    if ( parsed_resp )
                    {
                        if ( us_http_response_header_parse( parsed_resp, buf ) )
                        {
                            do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "parsed response:" ); } while ( 0 );
                            us_buffer_reset( buf );
                            r &= us_http_response_header_flatten( parsed_resp, buf );
                            us_buffer_print_string( buf, us_testutil_printer_stdout );
                        }
                        parsed_resp->destroy( parsed_resp );
                    }
                }
            }
            buf->destroy( buf );
        }
        else
        {
            r = 0;
        }
    }
    else
    {
        r = 0;
    }
    return r;
}

canonical_original_code:
static _Bool us_test_http_response()
{
    _Bool r = 0;
    char *html = "<title>Test</title>
Hello There
";
    struct us_http_response_header_s *resp;
    resp = us_http_response_header_create( us_testutil_session_allocator );
    if ( resp )
    {
        r = us_http_response_header_init_ok( resp, 200, "text/html", ( unsigned int )( strlen( html ) ), 1 );
    }
    if ( resp )
    {
        struct us_buffer_s *buf;
        buf = us_buffer_create( us_testutil_session_allocator, 4096 );
        if ( buf )
        {
            r &= us_http_response_header_flatten( resp, buf );
            if ( r )
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "generated response:" ); } while ( 0 );
                us_buffer_print_string( buf, us_testutil_printer_stdout );
                us_testutil_printer_stdout->printf( us_testutil_printer_stdout, "%s\n", html );
                {
                    struct us_http_response_header_s *parsed_resp;
                    parsed_resp = us_http_response_header_create( us_testutil_session_allocator );
                    if ( parsed_resp )
                    {
                        if ( us_http_response_header_parse( parsed_resp, buf ) )
                        {
                            do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "parsed response:" ); } while ( 0 );
                            us_buffer_reset( buf );
                            r &= us_http_response_header_flatten( parsed_resp, buf );
                            us_buffer_print_string( buf, us_testutil_printer_stdout );
                        }
                        parsed_resp->destroy( parsed_resp );
                    }
                }
            }
            buf->destroy( buf );
        }
        else
        {
            r = 0;
        }
    }
    else
    {
        r = 0;
    }
    return r;
}

variable_types:
html
char *

variable_types: struct us_http_response_header_s { void (*destroy)(struct us_http_response_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; int m_code; 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_response_header_s { void (*destroy)(struct us_http_response_header_s *); struct us_allocator_s *m_allocator; int m_code; char *m_version; struct us_http_header_item_list_s *m_items; }


repo: jdkoftinoff/microsupport

decompiled_code:
__int64 us_test_http()
{
unsigned int v0; // ebx
unsigned int v1; // eax

v0 = us_test_http_request();
if ( !(_BYTE)v0 && us_log_level > 0 )
us_log_error_proc("http request test failed");
v1 = us_test_http_response();
if ( !(_BYTE)v1 )
{
v0 = v1;
if ( us_log_level > 0 )
us_log_error_proc("http response test failed");
}
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx
unsigned int v1; // eax

v0 = func0();
if ( !(_BYTE)v0 && us_log_level > 0 )
us_log_error_proc("http request test failed");
v1 = func1();
if ( !(_BYTE)v1 )
{
v0 = v1;
if ( us_log_level > 0 )
us_log_error_proc("http response test failed");
}
return v0;
}

original_code:
static _Bool us_test_http( void )
{
    _Bool r = 1;
    if ( !us_test_http_request() )
    {
        r = 0;
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "http request test failed" ); } while ( 0 );
    }
    if ( !us_test_http_response() )
    {
        r = 0;
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "http response test failed" ); } while ( 0 );
    }
    return r;
}

canonical_original_code:
static _Bool us_test_http()
{
    _Bool r = 1;
    if ( !us_test_http_request() )
    {
        r = 0;
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "http request test failed" ); } while ( 0 );
    }
    if ( !us_test_http_response() )
    {
        r = 0;
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "http response test failed" ); } while ( 0 );
    }
    return r;
}


decompiled_code:
__int64 __fastcall us_test_http_main(unsigned int a1, const char **a2)
{
unsigned int v2; // ebp

v2 = 1;
if ( (unsigned __int8)us_testutil_start(4096LL, 4096LL, a1, a2) )
{
us_logger_printer_start(us_testutil_printer_stdout, us_testutil_printer_stderr);
us_log_level = 4;
us_log_info_proc("Hello world from %s compiled on %s", "../../../src/us_test_http_main.c", "May 23 2025");
v2 = (unsigned __int8)us_test_http() ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing %s", *a2);
us_logger_finish();
us_testutil_finish();
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, const char **a2)
{
unsigned int v2; // ebp

v2 = 1;
if ( (unsigned __int8)us_testutil_start(4096LL, 4096LL, a1, a2) )
{
us_logger_printer_start(us_testutil_printer_stdout, us_testutil_printer_stderr);
us_log_level = 4;
us_log_info_proc("Hello world from %s compiled on %s", "../../../src/us_test_http_main.c", "May 23 2025");
v2 = (unsigned __int8)func2() ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing %s", *a2);
us_logger_finish();
us_testutil_finish();
}
return v2;
}

original_code:
int us_test_http_main( int argc, const char **argv )
{
    int r = 1;
    if ( us_testutil_start( 4096, 4096, argc, argv ) )
    {
        us_logger_printer_start( us_testutil_printer_stdout, us_testutil_printer_stderr );
        do { us_log_level = ( ( 4 ) ); } while ( 0 );
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Hello world from %s compiled on %s", "../../../src/us_test_http_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_http() )
            r = 0;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing %s", argv[0] ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}

canonical_original_code:
int us_test_http_main(int argc, char **argv)
{
    int r = 1;
    if ( us_testutil_start( 4096, 4096, argc, argv ) )
    {
        us_logger_printer_start( us_testutil_printer_stdout, us_testutil_printer_stderr );
        do { us_log_level = ( ( 4 ) ); } while ( 0 );
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Hello world from %s compiled on %s", "../../../src/us_test_http_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_http() )
            r = 0;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing %s", argv[0] ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: r int

return_type: int


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

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_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

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


decompiled_code:
__int64 __fastcall print_sysex(__int64 a1)
{
__int64 result; // rax
int v2; // ebx
int v3; // ebp
int v4; // ebx
unsigned __int8 v5; // al

result = us_midi_sysex_get_length(a1);
v2 = result;
v3 = result;
if ( us_log_level > 2 )
result = us_log_info_proc("Sysex Len=%d", (unsigned int)result);
if ( v2 > 0 )
{
v4 = 0;
do
{
if ( us_log_level > 2 )
{
v5 = us_midi_sysex_get_data(a1, v4);
result = us_log_info_proc("%02x ", v5);
}
++v4;
}
while ( v3 != v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
int v2; // ebx
int v3; // ebp
int v4; // ebx
unsigned __int8 v5; // al

result = func6(a1);
v2 = result;
v3 = result;
if ( us_log_level > 2 )
result = us_log_info_proc("Sysex Len=%d", (unsigned int)result);
if ( v2 > 0 )
{
v4 = 0;
do
{
if ( us_log_level > 2 )
{
v5 = func7(a1, v4);
result = us_log_info_proc("%02x ", v5);
}
++v4;
}
while ( v3 != v4 );
}
return result;
}

original_code:
static void print_sysex( us_midi_sysex_t *ex )
{
    int i;
    int l = (int)us_midi_sysex_get_length( ex );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Sysex Len=%d", l ); } while ( 0 );
    for ( i = 0; i < l; ++i )
    {
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "%02x ", (int)us_midi_sysex_get_data( ex, i ) ); } while ( 0 );
    }
}

canonical_original_code:
static void print_sysex(struct us_midi_sysex_s *ex)
{
    int i;
    int l = (int)us_midi_sysex_get_length( ex );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Sysex Len=%d", l ); } while ( 0 );
    for ( i = 0; i < l; ++i )
    {
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "%02x ", (int)us_midi_sysex_get_data( ex, i ) ); } while ( 0 );
    }
}

variable_types: struct us_midi_sysex_s { void (*destroy)(struct us_midi_sysex_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_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; } *

variable_types: i int

variable_types: l int

return_type: void

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 print_msg(unsigned __int8 *a1)
{
int v1; // ebp
__int64 result; // rax
unsigned __int8 v3; // al
unsigned __int8 v4; // bp
unsigned __int8 v5; // al
unsigned __int8 v6; // r12
unsigned __int8 v7; // bp
unsigned __int8 v8; // al
char v9[168]; // [rsp+0h] [rbp-A8h] BYREF

v1 = (char)us_midi_msg_get_length();
if ( us_log_level <= 2 )
{
if ( v1 == 1 || v1 == 2 )
goto LABEL_5;
goto LABEL_4;
}
us_log_info_proc("Msg : ");
if ( v1 == 1 )
{
if ( us_log_level > 2 )
{
v3 = us_midi_msg_get_status(a1);
us_log_info_proc(" %02x \t=", v3);
}
}
else
{
if ( v1 != 2 )
{
LABEL_4:
if ( v1 == 3 && us_log_level > 2 )
{
v6 = us_midi_msg_get_byte2((__int64)a1);
v7 = us_midi_msg_get_byte1((__int64)a1);
v8 = us_midi_msg_get_status(a1);
us_log_info_proc(" %02x %02x %02x \t=", v8, v7, v6);
}
goto LABEL_5;
}
if ( us_log_level > 2 )
{
v4 = us_midi_msg_get_byte1((__int64)a1);
v5 = us_midi_msg_get_status(a1);
us_log_info_proc(" %02x %02x \t=", v5, v4);
}
}
LABEL_5:
result = us_midi_msg_to_text(a1, v9, 129LL);
if ( us_log_level > 2 )
result = us_log_info_proc("%s", v9);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1)
{
int v1; // ebp
__int64 result; // rax
unsigned __int8 v3; // al
unsigned __int8 v4; // bp
unsigned __int8 v5; // al
unsigned __int8 v6; // r12
unsigned __int8 v7; // bp
unsigned __int8 v8; // al
char v9[168]; // [rsp+0h] [rbp-A8h] BYREF

v1 = (char)us_midi_msg_get_length();
if ( us_log_level <= 2 )
{
if ( v1 == 1 || v1 == 2 )
goto LABEL_5;
goto LABEL_4;
}
us_log_info_proc("Msg : ");
if ( v1 == 1 )
{
if ( us_log_level > 2 )
{
v3 = func2(a1);
us_log_info_proc(" %02x \t=", v3);
}
}
else
{
if ( v1 != 2 )
{
LABEL_4:
if ( v1 == 3 && us_log_level > 2 )
{
v6 = func4((__int64)a1);
v7 = func3((__int64)a1);
v8 = func2(a1);
us_log_info_proc(" %02x %02x %02x \t=", v8, v7, v6);
}
goto LABEL_5;
}
if ( us_log_level > 2 )
{
v4 = func3((__int64)a1);
v5 = func2(a1);
us_log_info_proc(" %02x %02x \t=", v5, v4);
}
}
LABEL_5:
result = us_midi_msg_to_text(a1, v9, 129LL);
if ( us_log_level > 2 )
result = us_log_info_proc("%s", v9);
return result;
}

original_code:
static void print_msg( us_midi_msg_t *m )
{
    char buf[129];
    int l = us_midi_msg_get_length( m );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Msg : " ); } while ( 0 );
    if ( l == 1 )
    {
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( " %02x \t=", us_midi_msg_get_status( m ) ); } while ( 0 );
    }
    else if ( l == 2 )
    {
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( " %02x %02x \t=", us_midi_msg_get_status( m ), us_midi_msg_get_byte1( m ) ); } while ( 0 );
    }
    else if ( l == 3 )
    {
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( " %02x %02x %02x \t=", us_midi_msg_get_status( m ), us_midi_msg_get_byte1( m ), us_midi_msg_get_byte2( m ) ); } while ( 0 );
    }
    us_midi_msg_to_text( m, buf, sizeof( buf ) );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "%s", buf ); } while ( 0 );
}

canonical_original_code:
static void print_msg(struct us_midi_msg_s *m)
{
    char buf[129];
    int l = us_midi_msg_get_length( m );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Msg : " ); } while ( 0 );
    if ( l == 1 )
    {
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( " %02x \t=", us_midi_msg_get_status( m ) ); } while ( 0 );
    }
    else if ( l == 2 )
    {
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( " %02x %02x \t=", us_midi_msg_get_status( m ), us_midi_msg_get_byte1( m ) ); } while ( 0 );
    }
    else if ( l == 3 )
    {
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( " %02x %02x %02x \t=", us_midi_msg_get_status( m ), us_midi_msg_get_byte1( m ), us_midi_msg_get_byte2( m ) ); } while ( 0 );
    }
    us_midi_msg_to_text( m, buf, sizeof( buf ) );
    do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "%s", buf ); } while ( 0 );
}

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

variable_types:
buf
char [129]


decompiled_code:
__int64 __fastcall us_test_midi_main(unsigned int a1, const char **a2)
{
unsigned int v2; // ebp

v2 = 1;
if ( (unsigned __int8)us_testutil_start(4096LL, 4096LL, a1, a2) )
{
us_logger_printer_start(us_testutil_printer_stdout, us_testutil_printer_stderr);
us_log_level = 4;
us_log_info_proc("Hello world from %s compiled on %s", "../../../src/us_test_midi_main.c", "May 23 2025");
v2 = (unsigned __int8)us_test_midi_parser(test_data_1, 38) ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing %s", *a2);
us_logger_finish();
us_testutil_finish();
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, const char **a2)
{
unsigned int v2; // ebp

v2 = 1;
if ( (unsigned __int8)us_testutil_start(4096LL, 4096LL, a1, a2) )
{
us_logger_printer_start(us_testutil_printer_stdout, us_testutil_printer_stderr);
us_log_level = 4;
us_log_info_proc("Hello world from %s compiled on %s", "../../../src/us_test_midi_main.c", "May 23 2025");
v2 = (unsigned __int8)func11(test_data_1, 38) ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing %s", *a2);
us_logger_finish();
us_testutil_finish();
}
return v2;
}

original_code:
int us_test_midi_main( int argc, const char **argv )
{
    int r = 1;
    if ( us_testutil_start( 4096, 4096, argc, argv ) )
    {
        us_logger_printer_start( us_testutil_printer_stdout, us_testutil_printer_stderr );
        do { us_log_level = ( ( 4 ) ); } while ( 0 );
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Hello world from %s compiled on %s", "../../../src/us_test_midi_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_midi_parser( test_data_1, sizeof( test_data_1 ) ) )
            r = 0;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing %s", argv[0] ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}

canonical_original_code:
int us_test_midi_main(int argc, char **argv)
{
    int r = 1;
    if ( us_testutil_start( 4096, 4096, argc, argv ) )
    {
        us_logger_printer_start( us_testutil_printer_stdout, us_testutil_printer_stderr );
        do { us_log_level = ( ( 4 ) ); } while ( 0 );
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Hello world from %s compiled on %s", "../../../src/us_test_midi_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_midi_parser( test_data_1, sizeof( test_data_1 ) ) )
            r = 0;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing %s", argv[0] ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}


decompiled_code:
void us_logger_udp_finish()
{
if ( us_logger_udp_socket != -1 )
{
closesocket(us_logger_udp_socket);
us_logger_udp_socket = -1;
}
if ( us_logger_udp_dest_addrinfo )
{
freeaddrinfo(us_logger_udp_dest_addrinfo);
us_logger_udp_dest_addrinfo = 0LL;
}
us_log_error_proc = &us_log_null;
us_log_warn_proc = &us_log_null;
us_log_info_proc = &us_log_null;
us_log_debug_proc = &us_log_null;
us_logger_finish = &us_logger_null_finish;
}

canonical_decompiled_code:
void func1()
{
if ( us_logger_udp_socket != -1 )
{
func0(us_logger_udp_socket);
us_logger_udp_socket = -1;
}
if ( us_logger_udp_dest_addrinfo )
{
freeaddrinfo(us_logger_udp_dest_addrinfo);
us_logger_udp_dest_addrinfo = 0LL;
}
us_log_error_proc = &us_log_null;
us_log_warn_proc = &us_log_null;
us_log_info_proc = &us_log_null;
us_log_debug_proc = &us_log_null;
us_logger_finish = &us_logger_null_finish;
}

original_code:
void us_logger_udp_finish()
{
    if ( us_logger_udp_socket != -1 )
    {
        closesocket( us_logger_udp_socket );
        us_logger_udp_socket = -1;
    }
    if ( us_logger_udp_dest_addrinfo != ((void *)0) )
    {
        freeaddrinfo( us_logger_udp_dest_addrinfo );
        us_logger_udp_dest_addrinfo = ((void *)0);
    }
    us_log_error_proc = us_log_null;
    us_log_warn_proc = us_log_null;
    us_log_info_proc = us_log_null;
    us_log_debug_proc = us_log_null;
    us_logger_finish = us_logger_null_finish;
}


decompiled_code:
ssize_t us_log_udp_send()
{
ssize_t result; // rax

if ( us_logger_udp_socket != -1 )
result = sendto(
us_logger_udp_socket,
*((const void **)&us_logger_udp_printer_impl + 3),
*((int *)&us_logger_udp_printer_impl + 9),
0,
us_logger_udp_dest_addrinfo->ai_addr,
us_logger_udp_dest_addrinfo->ai_addrlen);
return result;
}

canonical_decompiled_code:
ssize_t func2()
{
ssize_t result; // rax

if ( us_logger_udp_socket != -1 )
result = sendto(
us_logger_udp_socket,
*((const void **)&us_logger_udp_printer_impl + 3),
*((int *)&us_logger_udp_printer_impl + 9),
0,
us_logger_udp_dest_addrinfo->ai_addr,
us_logger_udp_dest_addrinfo->ai_addrlen);
return result;
}

original_code:
void us_log_udp_send( void )
{
    if ( us_logger_udp_socket != -1 )
    {
        if ( sendto( us_logger_udp_socket,
                     us_logger_udp_printer_impl.m_buffer,
                     us_logger_udp_printer_impl.m_cur_length,
                     0,
                     us_logger_udp_dest_addrinfo->ai_addr,
                     us_logger_udp_dest_addrinfo->ai_addrlen ) < 0 )
        {
        }
    }
}

canonical_original_code:
void us_log_udp_send()
{
    if ( us_logger_udp_socket != -1 )
    {
        if ( sendto( us_logger_udp_socket,
                     us_logger_udp_printer_impl.m_buffer,
                     us_logger_udp_printer_impl.m_cur_length,
                     0,
                     us_logger_udp_dest_addrinfo->ai_addr,
                     us_logger_udp_dest_addrinfo->ai_addrlen ) < 0 )
        {
        }
    }
}


decompiled_code:
ssize_t us_log_error_udp(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
*((_DWORD *)&us_logger_udp_printer_impl + 9) = 0;
(*(void (__fastcall **)(__int64, const char *))(us_logger_udp_printer + 8))(us_logger_udp_printer, "ERROR:\t");
(*(void (__fastcall **)(__int64, __int64, __va_list_tag *))(us_logger_udp_printer + 16))(
us_logger_udp_printer,
a1,
va);
return us_log_udp_send();
}

canonical_decompiled_code:
ssize_t func3(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
*((_DWORD *)&us_logger_udp_printer_impl + 9) = 0;
(*(void (__fastcall **)(__int64, const char *))(us_logger_udp_printer + 8))(us_logger_udp_printer, "ERROR:\t");
(*(void (__fastcall **)(__int64, __int64, __va_list_tag *))(us_logger_udp_printer + 16))(
us_logger_udp_printer,
a1,
va);
return func2();
}

original_code:
void us_log_error_udp( const char *fmt, ... )
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    us_logger_udp_printer_impl.m_cur_length = 0;
    us_logger_udp_printer->printf( us_logger_udp_printer, "ERROR:\t" );
    us_logger_udp_printer->vprintf( us_logger_udp_printer, fmt, ap );
    us_log_udp_send();
    __builtin_va_end(ap);
}

canonical_original_code:
void us_log_error_udp(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    us_logger_udp_printer_impl.m_cur_length = 0;
    us_logger_udp_printer->printf( us_logger_udp_printer, "ERROR:\t" );
    us_logger_udp_printer->vprintf( us_logger_udp_printer, fmt, ap );
    us_log_udp_send();
    __builtin_va_end(ap);
}

variable_types:
fmt
char *


decompiled_code:
ssize_t us_log_warn_udp(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
*((_DWORD *)&us_logger_udp_printer_impl + 9) = 0;
(*(void (__fastcall **)(__int64, const char *))(us_logger_udp_printer + 8))(us_logger_udp_printer, "WARNING:\t");
(*(void (__fastcall **)(__int64, __int64, __va_list_tag *))(us_logger_udp_printer + 16))(
us_logger_udp_printer,
a1,
va);
return us_log_udp_send();
}

canonical_decompiled_code:
ssize_t func4(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
*((_DWORD *)&us_logger_udp_printer_impl + 9) = 0;
(*(void (__fastcall **)(__int64, const char *))(us_logger_udp_printer + 8))(us_logger_udp_printer, "WARNING:\t");
(*(void (__fastcall **)(__int64, __int64, __va_list_tag *))(us_logger_udp_printer + 16))(
us_logger_udp_printer,
a1,
va);
return func2();
}

original_code:
void us_log_warn_udp( const char *fmt, ... )
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    us_logger_udp_printer_impl.m_cur_length = 0;
    us_logger_udp_printer->printf( us_logger_udp_printer, "WARNING:\t" );
    us_logger_udp_printer->vprintf( us_logger_udp_printer, fmt, ap );
    us_log_udp_send();
    __builtin_va_end(ap);
}

canonical_original_code:
void us_log_warn_udp(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    us_logger_udp_printer_impl.m_cur_length = 0;
    us_logger_udp_printer->printf( us_logger_udp_printer, "WARNING:\t" );
    us_logger_udp_printer->vprintf( us_logger_udp_printer, fmt, ap );
    us_log_udp_send();
    __builtin_va_end(ap);
}


decompiled_code:
ssize_t us_log_info_udp(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
*((_DWORD *)&us_logger_udp_printer_impl + 9) = 0;
(*(void (__fastcall **)(__int64, const char *))(us_logger_udp_printer + 8))(us_logger_udp_printer, "INFO:\t");
(*(void (__fastcall **)(__int64, __int64, __va_list_tag *))(us_logger_udp_printer + 16))(
us_logger_udp_printer,
a1,
va);
return us_log_udp_send();
}

canonical_decompiled_code:
ssize_t func5(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
*((_DWORD *)&us_logger_udp_printer_impl + 9) = 0;
(*(void (__fastcall **)(__int64, const char *))(us_logger_udp_printer + 8))(us_logger_udp_printer, "INFO:\t");
(*(void (__fastcall **)(__int64, __int64, __va_list_tag *))(us_logger_udp_printer + 16))(
us_logger_udp_printer,
a1,
va);
return func2();
}

original_code:
void us_log_info_udp( const char *fmt, ... )
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    us_logger_udp_printer_impl.m_cur_length = 0;
    us_logger_udp_printer->printf( us_logger_udp_printer, "INFO:\t" );
    us_logger_udp_printer->vprintf( us_logger_udp_printer, fmt, ap );
    us_log_udp_send();
    __builtin_va_end(ap);
}

canonical_original_code:
void us_log_info_udp(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    us_logger_udp_printer_impl.m_cur_length = 0;
    us_logger_udp_printer->printf( us_logger_udp_printer, "INFO:\t" );
    us_logger_udp_printer->vprintf( us_logger_udp_printer, fmt, ap );
    us_log_udp_send();
    __builtin_va_end(ap);
}


decompiled_code:
ssize_t us_log_debug_udp(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
*((_DWORD *)&us_logger_udp_printer_impl + 9) = 0;
(*(void (__fastcall **)(__int64, const char *))(us_logger_udp_printer + 8))(us_logger_udp_printer, "DEBUG:\t");
(*(void (__fastcall **)(__int64, __int64, __va_list_tag *))(us_logger_udp_printer + 16))(
us_logger_udp_printer,
a1,
va);
return us_log_udp_send();
}

canonical_decompiled_code:
ssize_t func6(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
*((_DWORD *)&us_logger_udp_printer_impl + 9) = 0;
(*(void (__fastcall **)(__int64, const char *))(us_logger_udp_printer + 8))(us_logger_udp_printer, "DEBUG:\t");
(*(void (__fastcall **)(__int64, __int64, __va_list_tag *))(us_logger_udp_printer + 16))(
us_logger_udp_printer,
a1,
va);
return func2();
}

original_code:
void us_log_debug_udp( const char *fmt, ... )
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    us_logger_udp_printer_impl.m_cur_length = 0;
    us_logger_udp_printer->printf( us_logger_udp_printer, "DEBUG:\t" );
    us_logger_udp_printer->vprintf( us_logger_udp_printer, fmt, ap );
    us_log_udp_send();
    __builtin_va_end(ap);
}

canonical_original_code:
void us_log_debug_udp(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    us_logger_udp_printer_impl.m_cur_length = 0;
    us_logger_udp_printer->printf( us_logger_udp_printer, "DEBUG:\t" );
    us_logger_udp_printer->vprintf( us_logger_udp_printer, fmt, ap );
    us_log_udp_send();
    __builtin_va_end(ap);
}


decompiled_code:
ssize_t us_log_trace_udp(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
*((_DWORD *)&us_logger_udp_printer_impl + 9) = 0;
(*(void (__fastcall **)(__int64, const char *))(us_logger_udp_printer + 8))(us_logger_udp_printer, "TRACE:\t");
(*(void (__fastcall **)(__int64, __int64, __va_list_tag *))(us_logger_udp_printer + 16))(
us_logger_udp_printer,
a1,
va);
return us_log_udp_send();
}

canonical_decompiled_code:
ssize_t func7(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
*((_DWORD *)&us_logger_udp_printer_impl + 9) = 0;
(*(void (__fastcall **)(__int64, const char *))(us_logger_udp_printer + 8))(us_logger_udp_printer, "TRACE:\t");
(*(void (__fastcall **)(__int64, __int64, __va_list_tag *))(us_logger_udp_printer + 16))(
us_logger_udp_printer,
a1,
va);
return func2();
}

original_code:
void us_log_trace_udp( const char *fmt, ... )
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    us_logger_udp_printer_impl.m_cur_length = 0;
    us_logger_udp_printer->printf( us_logger_udp_printer, "TRACE:\t" );
    us_logger_udp_printer->vprintf( us_logger_udp_printer, fmt, ap );
    us_log_udp_send();
    __builtin_va_end(ap);
}

canonical_original_code:
void us_log_trace_udp(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    us_logger_udp_printer_impl.m_cur_length = 0;
    us_logger_udp_printer->printf( us_logger_udp_printer, "TRACE:\t" );
    us_logger_udp_printer->vprintf( us_logger_udp_printer, fmt, ap );
    us_log_udp_send();
    __builtin_va_end(ap);
}


decompiled_code:
__int64 __fastcall us_logger_udp_start(char *name, char *service)
{
char *v2; // rbx
int v3; // eax
const char *v5; // r8
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

v2 = name;
us_logger_udp_printer = us_printraw_init(&us_logger_udp_printer_impl, &us_logger_udp_buffer, 1500LL);
if ( !us_logger_udp_printer )
{
LABEL_10:
if ( us_logger_udp_socket != -1 )
closesocket(us_logger_udp_socket);
us_logger_udp_socket = -1;
return 0LL;
}
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_socktype = 2;
req.ai_protocol = 17;
v3 = getaddrinfo(name, service, &req, &pai);
if ( !v3 )
{
us_logger_udp_socket = -1;
if ( us_logger_udp_dest_addrinfo )
freeaddrinfo(us_logger_udp_dest_addrinfo);
us_logger_udp_dest_addrinfo = pai;
us_logger_udp_socket = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
if ( us_logger_udp_socket >= 0 )
{
us_log_error_proc = us_log_error_udp;
us_log_warn_proc = us_log_warn_udp;
us_log_info_proc = us_log_info_udp;
us_log_debug_proc = us_log_debug_udp;
us_log_trace_proc = us_log_trace_udp;
us_logger_finish = us_logger_udp_finish;
return 1LL;
}
goto LABEL_10;
}
v5 = gai_strerror(v3);
if ( !name )
v2 = "(null)";
fprintf(stderr, "getaddrinfo(): %s service:%s: %s\n", v2, service, v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *name, char *service)
{
char *v2; // rbx
int v3; // eax
const char *v5; // r8
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

v2 = name;
us_logger_udp_printer = us_printraw_init(&us_logger_udp_printer_impl, &us_logger_udp_buffer, 1500LL);
if ( !us_logger_udp_printer )
{
LABEL_10:
if ( us_logger_udp_socket != -1 )
func0(us_logger_udp_socket);
us_logger_udp_socket = -1;
return 0LL;
}
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_socktype = 2;
req.ai_protocol = 17;
v3 = getaddrinfo(name, service, &req, &pai);
if ( !v3 )
{
us_logger_udp_socket = -1;
if ( us_logger_udp_dest_addrinfo )
freeaddrinfo(us_logger_udp_dest_addrinfo);
us_logger_udp_dest_addrinfo = pai;
us_logger_udp_socket = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
if ( us_logger_udp_socket >= 0 )
{
us_log_error_proc = us_log_error_udp;
us_log_warn_proc = us_log_warn_udp;
us_log_info_proc = us_log_info_udp;
us_log_debug_proc = us_log_debug_udp;
us_log_trace_proc = us_log_trace_udp;
us_logger_finish = us_logger_udp_finish;
return 1LL;
}
goto LABEL_10;
}
v5 = gai_strerror(v3);
if ( !name )
v2 = "(null)";
fprintf(stderr, "getaddrinfo(): %s service:%s: %s\n", v2, service, v5);
return 0LL;
}

original_code:
_Bool us_logger_udp_start( const char *dest_addr, const char *service )
{
    _Bool r = 0;
    struct addrinfo hints, *ai;
    int gai;
    us_logger_udp_printer
        = us_printraw_init( &us_logger_udp_printer_impl, us_logger_udp_buffer, sizeof( us_logger_udp_buffer ) );
    if ( us_logger_udp_printer )
    {
        memset( &hints, 0, sizeof( hints ) );
        hints.ai_family = 0;
        hints.ai_socktype = SOCK_DGRAM;
        hints.ai_protocol = IPPROTO_UDP;
        gai = getaddrinfo( dest_addr, service, &hints, &ai );
        if ( gai )
        {
            fprintf( stderr,
                     "getaddrinfo(): %s service:%s: %s\n",
                     dest_addr != ((void *)0) ? dest_addr : "(null)",
                     service,
                     gai_strerror( gai ) );
            return ( r );
        }
        us_logger_udp_socket = -1;
        if ( us_logger_udp_dest_addrinfo != ((void *)0) )
        {
            freeaddrinfo( us_logger_udp_dest_addrinfo );
            us_logger_udp_dest_addrinfo = ((void *)0);
        }
        us_logger_udp_dest_addrinfo = ai;
        us_logger_udp_socket = socket( us_logger_udp_dest_addrinfo->ai_family,
                                       us_logger_udp_dest_addrinfo->ai_socktype,
                                       us_logger_udp_dest_addrinfo->ai_protocol );
        if ( us_logger_udp_socket >= 0 )
        {
            r = 1;
        }
    }
    if ( r )
    {
        us_log_error_proc = us_log_error_udp;
        us_log_warn_proc = us_log_warn_udp;
        us_log_info_proc = us_log_info_udp;
        us_log_debug_proc = us_log_debug_udp;
        us_log_trace_proc = us_log_trace_udp;
        us_logger_finish = us_logger_udp_finish;
    }
    else
    {
        if ( us_logger_udp_socket != -1 )
        {
            closesocket( us_logger_udp_socket );
        }
        us_logger_udp_socket = -1;
    }
    return r;
}

canonical_original_code:
_Bool us_logger_udp_start(char *dest_addr, char *service)
{
    _Bool r = 0;
    struct addrinfo hints; struct addrinfo *ai;
    int gai;
    us_logger_udp_printer
        = us_printraw_init( &us_logger_udp_printer_impl, us_logger_udp_buffer, sizeof( us_logger_udp_buffer ) );
    if ( us_logger_udp_printer )
    {
        memset( &hints, 0, sizeof( hints ) );
        hints.ai_family = 0;
        hints.ai_socktype = SOCK_DGRAM;
        hints.ai_protocol = IPPROTO_UDP;
        gai = getaddrinfo( dest_addr, service, &hints, &ai );
        if ( gai )
        {
            fprintf( stderr,
                     "getaddrinfo(): %s service:%s: %s\n",
                     dest_addr != ((void *)0) ? dest_addr : "(null)",
                     service,
                     gai_strerror( gai ) );
            return ( r );
        }
        us_logger_udp_socket = -1;
        if ( us_logger_udp_dest_addrinfo != ((void *)0) )
        {
            freeaddrinfo( us_logger_udp_dest_addrinfo );
            us_logger_udp_dest_addrinfo = ((void *)0);
        }
        us_logger_udp_dest_addrinfo = ai;
        us_logger_udp_socket = socket( us_logger_udp_dest_addrinfo->ai_family,
                                       us_logger_udp_dest_addrinfo->ai_socktype,
                                       us_logger_udp_dest_addrinfo->ai_protocol );
        if ( us_logger_udp_socket >= 0 )
        {
            r = 1;
        }
    }
    if ( r )
    {
        us_log_error_proc = us_log_error_udp;
        us_log_warn_proc = us_log_warn_udp;
        us_log_info_proc = us_log_info_udp;
        us_log_debug_proc = us_log_debug_udp;
        us_log_trace_proc = us_log_trace_udp;
        us_logger_finish = us_logger_udp_finish;
    }
    else
    {
        if ( us_logger_udp_socket != -1 )
        {
            closesocket( us_logger_udp_socket );
        }
        us_logger_udp_socket = -1;
    }
    return r;
}

variable_types:
service
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: gai int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall us_example_mudp_tx(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // er12
unsigned int i; // ebx
int v8; // eax
int v9; // eax
char v10[256]; // [rsp+0h] [rbp-518h] BYREF
char s[1048]; // [rsp+100h] [rbp-418h] BYREF

v4 = us_net_get_addrinfo(a1, a2, 2LL, 0LL);
if ( (unsigned __int8)us_net_get_nameinfo(v4, s, 1023LL, v10, 255LL) )
{
if ( us_log_level > 2 )
us_log_info_proc("multicastgroup: %s port %s", s, v10);
}
else
{
perror("getnameinfo:");
}
v5 = us_net_create_multicast_tx_udp_socket(0LL, v4, a3);
if ( v5 > 0 )
{
for ( i = 0; ; ++i )
{
sprintf(s, "packet contents: %08d", i);
v8 = strlen(s);
v9 = sendto(v5, s, v8, 0, *(const struct sockaddr **)(v4 + 24), *(_DWORD *)(v4 + 16));
if ( v9 <= 0 )
break;
if ( us_log_level > 2 )
us_log_info_proc("sent packet %d, %d bytes", i, (unsigned int)v9);
sleep(1u);
}
perror("sendto:");
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // er12
unsigned int i; // ebx
int v8; // eax
int v9; // eax
char v10[256]; // [rsp+0h] [rbp-518h] BYREF
char s[1048]; // [rsp+100h] [rbp-418h] BYREF

v4 = us_net_get_addrinfo(a1, a2, 2LL, 0LL);
if ( (unsigned __int8)us_net_get_nameinfo(v4, s, 1023LL, v10, 255LL) )
{
if ( us_log_level > 2 )
us_log_info_proc("multicastgroup: %s port %s", s, v10);
}
else
{
perror("getnameinfo:");
}
v5 = us_net_create_multicast_tx_udp_socket(0LL, v4, a3);
if ( v5 > 0 )
{
for ( i = 0; ; ++i )
{
sprintf(s, "packet contents: %08d", i);
v8 = strlen(s);
v9 = sendto(v5, s, v8, 0, *(const struct sockaddr **)(v4 + 24), *(_DWORD *)(v4 + 16));
if ( v9 <= 0 )
break;
if ( us_log_level > 2 )
us_log_info_proc("sent packet %d, %d bytes", i, (unsigned int)v9);
sleep(1u);
}
perror("sendto:");
}
return 0LL;
}

original_code:
_Bool us_example_mudp_tx (
    const char *multicast_address,
    const char *multicast_service,
    const char *interface
)
{
    int fd;
    _Bool r = 0;
    struct addrinfo *multicastgroup;
    multicastgroup = us_net_get_addrinfo ( multicast_address, multicast_service, SOCK_DGRAM, 0 );
    {
        char multicastgroup_name[1024];
        char multicastgroup_serv[256];
        if ( us_net_get_nameinfo ( multicastgroup, multicastgroup_name, sizeof ( multicastgroup_name ) - 1, multicastgroup_serv, sizeof ( multicastgroup_serv ) - 1 ) )
        {
            do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "multicastgroup: %s port %s", multicastgroup_name, multicastgroup_serv ); } while ( 0 );
        }
        else
        {
            perror ( "getnameinfo:" );
        }
    }
    fd = us_net_create_multicast_tx_udp_socket ( 0, multicastgroup, interface );
    if ( fd > 0 )
    {
        int cnt = 0;
        while ( 1 )
        {
            char buf[1024];
            int buf_len;
            int sent_len;
            sprintf ( buf, "packet contents: %08d", cnt );
            buf_len = strlen ( buf );
            sent_len = sendto ( fd, buf, buf_len, 0, multicastgroup->ai_addr, multicastgroup->ai_addrlen );
            if ( sent_len > 0 )
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "sent packet %d, %d bytes", cnt, sent_len ); } while ( 0 );
            }
            else
            {
                perror ( "sendto:" );
                break;
            }
            sleep ( 1 );
            cnt++;
        }
    }
    return r;
}

canonical_original_code:
_Bool us_example_mudp_tx(char *multicast_address, char *multicast_service, char *interface)
{
    int fd;
    _Bool r = 0;
    struct addrinfo *multicastgroup;
    multicastgroup = us_net_get_addrinfo ( multicast_address, multicast_service, SOCK_DGRAM, 0 );
    {
        char multicastgroup_name[1024];
        char multicastgroup_serv[256];
        if ( us_net_get_nameinfo ( multicastgroup, multicastgroup_name, sizeof ( multicastgroup_name ) - 1, multicastgroup_serv, sizeof ( multicastgroup_serv ) - 1 ) )
        {
            do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "multicastgroup: %s port %s", multicastgroup_name, multicastgroup_serv ); } while ( 0 );
        }
        else
        {
            perror ( "getnameinfo:" );
        }
    }
    fd = us_net_create_multicast_tx_udp_socket ( 0, multicastgroup, interface );
    if ( fd > 0 )
    {
        int cnt = 0;
        while ( 1 )
        {
            char buf[1024];
            int buf_len;
            int sent_len;
            sprintf ( buf, "packet contents: %08d", cnt );
            buf_len = strlen ( buf );
            sent_len = sendto ( fd, buf, buf_len, 0, multicastgroup->ai_addr, multicastgroup->ai_addrlen );
            if ( sent_len > 0 )
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "sent packet %d, %d bytes", cnt, sent_len ); } while ( 0 );
            }
            else
            {
                perror ( "sendto:" );
                break;
            }
            sleep ( 1 );
            cnt++;
        }
    }
    return r;
}

variable_types:
interface
char *

variable_types: fd int

variable_types: cnt int

variable_types:
buf
char [1024]

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


main

canonical_name: main

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

if ( argc <= 2 )
{
fprintf(stderr, "usage:\n\t%s multicast_address multicast_service (interface)\n", *argv);
fprintf(stderr, "example:\n\t%s ff31::8000:1234 30001\n", *argv);
exit(1);
}
v3 = 1;
if ( (unsigned __int8)us_testutil_start(4096LL, 4096LL, (unsigned int)argc, argv) )
{
v4 = argv[1];
v5 = argv[2];
v6 = (const char *)&unk_28D;
if ( argc > 3 )
v6 = argv[3];
us_logger_printer_start(us_testutil_printer_stdout, us_testutil_printer_stderr);
us_log_level = 4;
us_log_info_proc("Hello world from %s compiled on %s", "../../../examples/us_example_mudp_tx.c", "May 23 2025");
v3 = (unsigned __int8)us_example_mudp_tx((__int64)v4, (__int64)v5, (__int64)v6) ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing %s", *argv);
us_logger_finish();
us_testutil_finish();
}
return v3;
}

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

if ( argc <= 2 )
{
fprintf(stderr, "usage:\n\t%s multicast_address multicast_service (interface)\n", *argv);
fprintf(stderr, "example:\n\t%s ff31::8000:1234 30001\n", *argv);
exit(1);
}
v3 = 1;
if ( (unsigned __int8)us_testutil_start(4096LL, 4096LL, (unsigned int)argc, argv) )
{
v4 = argv[1];
v5 = argv[2];
v6 = (const char *)&unk_28D;
if ( argc > 3 )
v6 = argv[3];
us_logger_printer_start(us_testutil_printer_stdout, us_testutil_printer_stderr);
us_log_level = 4;
us_log_info_proc("Hello world from %s compiled on %s", "../../../examples/us_example_mudp_tx.c", "May 23 2025");
v3 = (unsigned __int8)func0((__int64)v4, (__int64)v5, (__int64)v6) ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing %s", *argv);
us_logger_finish();
us_testutil_finish();
}
return v3;
}

original_code:
int main ( int argc, const char **argv )
{
    int r = 1;
    if ( argc < 3 )
    {
        fprintf ( stderr, "usage:\n\t%s multicast_address multicast_service (interface)\n", argv[0] );
        fprintf ( stderr, "example:\n\t%s ff31::8000:1234 30001\n", argv[0] );
        exit ( 1 );
    }
    if ( us_testutil_start ( 4096, 4096, argc, argv ) )
    {
        const char *multicast_address = argv[1];
        const char *multicast_service = argv[2];
        const char *interface = "";
        if ( argc > 3 )
            interface = argv[3];
        us_logger_printer_start ( us_testutil_printer_stdout, us_testutil_printer_stderr );
        do { us_log_level = ( ( 4 ) ); } while ( 0 );
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Hello world from %s compiled on %s", "../../../examples/us_example_mudp_tx.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_example_mudp_tx ( multicast_address, multicast_service, interface ) )
            r = 0;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing %s", argv[0] ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int r = 1;
    if ( argc < 3 )
    {
        fprintf ( stderr, "usage:\n\t%s multicast_address multicast_service (interface)\n", argv[0] );
        fprintf ( stderr, "example:\n\t%s ff31::8000:1234 30001\n", argv[0] );
        exit ( 1 );
    }
    if ( us_testutil_start ( 4096, 4096, argc, argv ) )
    {
        char *multicast_address = argv[1];
        char *multicast_service = argv[2];
        char *interface = "";
        if ( argc > 3 )
            interface = argv[3];
        us_logger_printer_start ( us_testutil_printer_stdout, us_testutil_printer_stderr );
        do { us_log_level = ( ( 4 ) ); } while ( 0 );
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Hello world from %s compiled on %s", "../../../examples/us_example_mudp_tx.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_example_mudp_tx ( multicast_address, multicast_service, interface ) )
            r = 0;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing %s", argv[0] ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}

variable_types: argc int

variable_types:
argv
char **


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


decompiled_code:
__int64 __fastcall us_buffer_read_byte(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // ecx

v1 = a1[4];
v2 = *(unsigned __int8 *)(a1[2] + v1);
a1[4] = (unsigned __int64)(v1 + 1) % a1[5];
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // ecx

v1 = a1[4];
v2 = *(unsigned __int8 *)(a1[2] + v1);
a1[4] = (unsigned __int64)(v1 + 1) % a1[5];
return v2;
}

original_code:
static inline uint8_t us_buffer_read_byte( us_buffer_t *self )
{
    uint8_t r = self->m_buffer[self->m_next_out];
    self->m_next_out = ( self->m_next_out + 1 ) % self->m_max_length;
    return r;
}

canonical_original_code:
static inline unsigned char us_buffer_read_byte(struct us_buffer_s *self)
{
    unsigned char r = self->m_buffer[self->m_next_out];
    self->m_next_out = ( self->m_next_out + 1 ) % self->m_max_length;
    return r;
}

variable_types:
r
unsigned 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 func3(_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:
unsigned __int64 __fastcall us_buffer_write(_QWORD *a1, char *a2, __int64 a3)
{
char *v3; // rbx
char *v4; // rbp
unsigned __int64 result; // rax

if ( a3 )
{
v3 = a2;
v4 = &a2[a3];
do
result = us_buffer_write_byte(a1, *v3++);
while ( v3 != v4 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(_QWORD *a1, char *a2, __int64 a3)
{
char *v3; // rbx
char *v4; // rbp
unsigned __int64 result; // rax

if ( a3 )
{
v3 = a2;
v4 = &a2[a3];
do
result = func4(a1, *v3++);
while ( v3 != v4 );
}
return result;
}

original_code:
static inline void us_buffer_write( us_buffer_t *self, const uint8_t *src_data, size_t src_data_cnt )
{
    size_t i;
    for ( i = 0; i < src_data_cnt; ++i )
    {
        us_buffer_write_byte( self, src_data[i] );
    }
}

canonical_original_code:
static inline void us_buffer_write(struct us_buffer_s *self, unsigned char *src_data, unsigned long src_data_cnt)
{
    unsigned long i;
    for ( i = 0; i < src_data_cnt; ++i )
    {
        us_buffer_write_byte( self, src_data[i] );
    }
}

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall us_example_reactor_handler_quitter_readable(__int64 a1)
{
_QWORD *v1; // rbx

v1 = (_QWORD *)(a1 + 136);
while ( us_buffer_can_read_byte((__int64)v1) )
{
if ( (unsigned __int8)us_buffer_read_byte(v1) == 81 )
global_quit = 1;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
_QWORD *v1; // rbx

v1 = (_QWORD *)(a1 + 136);
while ( func1((__int64)v1) )
{
if ( (unsigned __int8)func2(v1) == 81 )
global_quit = 1;
}
return 1LL;
}

original_code:
_Bool us_example_reactor_handler_quitter_readable (
    us_reactor_handler_tcp_t *self_
)
{
    us_reactor_handler_tcp_t *self = ( us_reactor_handler_tcp_t * ) self_;
    while ( us_buffer_can_read_byte ( &self->m_incoming_queue ) )
    {
        char c = ( char ) us_buffer_read_byte ( &self->m_incoming_queue );
        if ( c == 'Q' )
        {
            global_quit = 1;
        }
    }
    return 1;
}

canonical_original_code:
_Bool us_example_reactor_handler_quitter_readable(struct us_reactor_handler_tcp_s *self_)
{
    struct us_reactor_handler_tcp_s *self = ( us_reactor_handler_tcp_t * ) self_;
    while ( us_buffer_can_read_byte ( &self->m_incoming_queue ) )
    {
        char c = ( char ) us_buffer_read_byte ( &self->m_incoming_queue );
        if ( c == 'Q' )
        {
            global_quit = 1;
        }
    }
    return 1;
}

variable_types: struct us_reactor_handler_tcp_s { struct us_reactor_handler_s { void (*destroy)(struct us_reactor_handler_s *self); void (*close)(struct us_reactor_handler_s *self); _Bool (*tick)(struct us_reactor_handler_s *self); _Bool (*readable)(struct us_reactor_handler_s *self); _Bool (*writable)(struct us_reactor_handler_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; _Bool m_finished; struct us_reactor_handler_s *m_next; struct us_reactor_s { void (*destroy)(struct us_reactor_s *self); struct us_allocator_s *m_allocator; struct us_reactor_handler_s *m_handlers; int m_timeout; int m_max_handlers; int m_num_handlers; struct pollfd { int fd; short events; short revents; } *m_poll_handlers; _Bool (*poll)(struct us_reactor_s *self, int timeout); _Bool (*add_item)(struct us_reactor_s *self, struct us_reactor_handler_s *item); _Bool (*remove_item)(struct us_reactor_s *self, struct us_reactor_handler_s *item); } *m_reactor; void *m_extra; int m_fd; _Bool m_wake_on_readable; _Bool m_wake_on_writable; } m_base; 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_outgoing_queue; struct us_buffer_s m_incoming_queue; void (*close)(struct us_reactor_handler_tcp_s *self); _Bool (*connected)(struct us_reactor_handler_tcp_s *self, struct sockaddr { unsigned short sa_family; char sa_data[14]; } *addr, unsigned int addrlen); _Bool (*tick)(struct us_reactor_handler_tcp_s *self); _Bool (*readable)(struct us_reactor_handler_tcp_s *self); _Bool (*writable)(struct us_reactor_handler_tcp_s *self); _Bool (*incoming_eof)(struct us_reactor_handler_tcp_s *self); void (*closed)(struct us_reactor_handler_tcp_s *self); } *

variable_types: c char

user_defined_types: struct us_reactor_handler_tcp_s { struct us_reactor_handler_s m_base; struct us_buffer_s m_outgoing_queue; struct us_buffer_s m_incoming_queue; void (*close)(struct us_reactor_handler_tcp_s *self); _Bool (*connected)(struct us_reactor_handler_tcp_s *self, struct sockaddr *addr, unsigned int addrlen); _Bool (*tick)(struct us_reactor_handler_tcp_s *self); _Bool (*readable)(struct us_reactor_handler_tcp_s *self); _Bool (*writable)(struct us_reactor_handler_tcp_s *self); _Bool (*incoming_eof)(struct us_reactor_handler_tcp_s *self); void (*closed)(struct us_reactor_handler_tcp_s *self); }

user_defined_types: struct us_reactor_handler_s { void (*destroy)(struct us_reactor_handler_s *self); void (*close)(struct us_reactor_handler_s *self); _Bool (*tick)(struct us_reactor_handler_s *self); _Bool (*readable)(struct us_reactor_handler_s *self); _Bool (*writable)(struct us_reactor_handler_s *self); struct us_allocator_s *m_allocator; _Bool m_finished; struct us_reactor_handler_s *m_next; struct us_reactor_s *m_reactor; void *m_extra; int m_fd; _Bool m_wake_on_readable; _Bool m_wake_on_writable; }

user_defined_types: struct us_reactor_s { void (*destroy)(struct us_reactor_s *self); struct us_allocator_s *m_allocator; struct us_reactor_handler_s *m_handlers; int m_timeout; int m_max_handlers; int m_num_handlers; struct pollfd *m_poll_handlers; _Bool (*poll)(struct us_reactor_s *self, int timeout); _Bool (*add_item)(struct us_reactor_s *self, struct us_reactor_handler_s *item); _Bool (*remove_item)(struct us_reactor_s *self, struct us_reactor_handler_s *item); }


decompiled_code:
__int64 us_example_reactor_handler_http_create()
{
return us_reactor_handler_tcp_create();
}

canonical_decompiled_code:
__int64 func7()
{
return us_reactor_handler_tcp_create();
}

original_code:
us_reactor_handler_t * us_example_reactor_handler_http_create ( us_allocator_t *allocator )
{
    return us_reactor_handler_tcp_create(allocator);
}

canonical_original_code:
struct us_reactor_handler_s *us_example_reactor_handler_http_create(struct us_allocator_s *allocator)
{
    return us_reactor_handler_tcp_create(allocator);
}

variable_types:
allocator
struct us_allocator_s *

return_type: struct us_reactor_handler_s { void (*destroy)(struct us_reactor_handler_s *self); void (*close)(struct us_reactor_handler_s *self); _Bool (*tick)(struct us_reactor_handler_s *self); _Bool (*readable)(struct us_reactor_handler_s *self); _Bool (*writable)(struct us_reactor_handler_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; _Bool m_finished; struct us_reactor_handler_s *m_next; struct us_reactor_s { void (*destroy)(struct us_reactor_s *self); struct us_allocator_s *m_allocator; struct us_reactor_handler_s *m_handlers; int m_timeout; int m_max_handlers; int m_num_handlers; struct pollfd { int fd; short events; short revents; } *m_poll_handlers; _Bool (*poll)(struct us_reactor_s *self, int timeout); _Bool (*add_item)(struct us_reactor_s *self, struct us_reactor_handler_s *item); _Bool (*remove_item)(struct us_reactor_s *self, struct us_reactor_handler_s *item); } *m_reactor; void *m_extra; int m_fd; _Bool m_wake_on_readable; _Bool m_wake_on_writable; } *


decompiled_code:
__int64 us_example_reactor_handler_echo_create()
{
return us_reactor_handler_tcp_create();
}

canonical_decompiled_code:
__int64 func8()
{
return us_reactor_handler_tcp_create();
}

original_code:
us_reactor_handler_t *
us_example_reactor_handler_echo_create ( us_allocator_t *allocator )
{
    return us_reactor_handler_tcp_create( allocator );
}

canonical_original_code:
struct us_reactor_handler_s *us_example_reactor_handler_echo_create(struct us_allocator_s *allocator)
{
    return us_reactor_handler_tcp_create( allocator );
}

user_defined_types: struct pollfd { int fd; short events; short revents; }


decompiled_code:
__int64 us_example_reactor_handler_quitter_create()
{
return us_reactor_handler_tcp_create();
}

canonical_decompiled_code:
__int64 func9()
{
return us_reactor_handler_tcp_create();
}

original_code:
us_reactor_handler_t *
us_example_reactor_handler_quitter_create ( us_allocator_t *allocator )
{
    return us_reactor_handler_tcp_create( allocator );
}

canonical_original_code:
struct us_reactor_handler_s *us_example_reactor_handler_quitter_create(struct us_allocator_s *allocator)
{
    return us_reactor_handler_tcp_create( allocator );
}


decompiled_code:
__int64 __fastcall us_example_reactor_handler_http_init(_QWORD *a1, __int64 a2)
{
unsigned int v2; // ebp

v2 = us_reactor_handler_tcp_client_init(a1, a2);
if ( (_BYTE)v2 )
{
a1[26] = us_example_reactor_handler_http_readable;
a1[25] = us_example_reactor_handler_http_tick;
a1[29] = us_example_reactor_handler_http_closed;
us_buffer_write(a1 + 11, "GET / HTTP/1.0\r\nHost: github.com\r\n\r\n", 36LL);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, __int64 a2)
{
unsigned int v2; // ebp

v2 = us_reactor_handler_tcp_client_init(a1, a2);
if ( (_BYTE)v2 )
{
a1[26] = us_example_reactor_handler_http_readable;
a1[25] = us_example_reactor_handler_http_tick;
a1[29] = us_example_reactor_handler_http_closed;
func5(a1 + 11, "GET / HTTP/1.0\r\nHost: github.com\r\n\r\n", 36LL);
}
return v2;
}

original_code:
_Bool us_example_reactor_handler_http_init (
    us_reactor_handler_t *self_,
    us_allocator_t *allocator,
    int fd,
    void *extra,
    int queue_buf_size,
    const char *server_host,
    const char *server_port,
    _Bool keep_open
)
{
    us_reactor_handler_tcp_t *self = (us_reactor_handler_tcp_t *)self_;
    _Bool r = us_reactor_handler_tcp_client_init(self_, allocator, fd, extra, queue_buf_size, server_host, server_port, keep_open);
    if ( r )
    {
        static const char *req = "GET / HTTP/1.0\r\nHost: ""github.com""\r\n\r\n";
        self->readable = us_example_reactor_handler_http_readable;
        self->tick = us_example_reactor_handler_http_tick;
        self->closed = us_example_reactor_handler_http_closed;
        us_buffer_write(&self->m_outgoing_queue, (const uint8_t*)req, strlen(req) );
    }
    return r;
}

canonical_original_code:
_Bool us_example_reactor_handler_http_init(struct us_reactor_handler_s *self_, struct us_allocator_s *allocator, int fd, void *extra, int queue_buf_size, char *server_host, char *server_port, _Bool keep_open)
{
    struct us_reactor_handler_tcp_s *self = (us_reactor_handler_tcp_t *)self_;
    _Bool r = us_reactor_handler_tcp_client_init(self_, allocator, fd, extra, queue_buf_size, server_host, server_port, keep_open);
    if ( r )
    {
        static char *req = "GET / HTTP/1.0\r\nHost: ""github.com""\r\n\r\n";
        self->readable = us_example_reactor_handler_http_readable;
        self->tick = us_example_reactor_handler_http_tick;
        self->closed = us_example_reactor_handler_http_closed;
        us_buffer_write(&self->m_outgoing_queue, (unsigned char *)req, strlen(req) );
    }
    return r;
}

variable_types: struct us_reactor_handler_s { void (*destroy)(struct us_reactor_handler_s *self); void (*close)(struct us_reactor_handler_s *self); _Bool (*tick)(struct us_reactor_handler_s *self); _Bool (*readable)(struct us_reactor_handler_s *self); _Bool (*writable)(struct us_reactor_handler_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; _Bool m_finished; struct us_reactor_handler_s *m_next; struct us_reactor_s { void (*destroy)(struct us_reactor_s *self); struct us_allocator_s *m_allocator; struct us_reactor_handler_s *m_handlers; int m_timeout; int m_max_handlers; int m_num_handlers; struct pollfd { int fd; short events; short revents; } *m_poll_handlers; _Bool (*poll)(struct us_reactor_s *self, int timeout); _Bool (*add_item)(struct us_reactor_s *self, struct us_reactor_handler_s *item); _Bool (*remove_item)(struct us_reactor_s *self, struct us_reactor_handler_s *item); } *m_reactor; void *m_extra; int m_fd; _Bool m_wake_on_readable; _Bool m_wake_on_writable; } *

variable_types:
extra
void *

variable_types:
req
char *


decompiled_code:
__int64 __fastcall us_example_reactor_handler_echo_readable(__int64 a1)
{
_QWORD *i; // rbp
unsigned __int8 v2; // bl
const __int32_t **v3; // rax

for ( i = (_QWORD *)(a1 + 88);
us_buffer_can_write_byte(i) && us_buffer_can_read_byte(a1 + 136);
us_buffer_write_byte(i, (*v3)[v2]) )
{
v2 = us_buffer_read_byte((_QWORD *)(a1 + 136));
v3 = _ctype_toupper_loc();
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
_QWORD *i; // rbp
unsigned __int8 v2; // bl
const __int32_t **v3; // rax

for ( i = (_QWORD *)(a1 + 88);
func3(i) && func1(a1 + 136);
func4(i, (*v3)[v2]) )
{
v2 = func2((_QWORD *)(a1 + 136));
v3 = _ctype_toupper_loc();
}
return 1LL;
}

original_code:
_Bool us_example_reactor_handler_echo_readable (
    us_reactor_handler_tcp_t *self_
)
{
    us_reactor_handler_tcp_t *self = ( us_reactor_handler_tcp_t * ) self_;
    while ( us_buffer_can_write_byte ( &self->m_outgoing_queue ) &&
            us_buffer_can_read_byte ( &self->m_incoming_queue ) )
    {
        uint8_t c = us_buffer_read_byte ( &self->m_incoming_queue );
        c = toupper ( c );
        us_buffer_write_byte ( &self->m_outgoing_queue, c );
    }
    return 1;
}

canonical_original_code:
_Bool us_example_reactor_handler_echo_readable(struct us_reactor_handler_tcp_s *self_)
{
    struct us_reactor_handler_tcp_s *self = ( us_reactor_handler_tcp_t * ) self_;
    while ( us_buffer_can_write_byte ( &self->m_outgoing_queue ) &&
            us_buffer_can_read_byte ( &self->m_incoming_queue ) )
    {
        unsigned char c = us_buffer_read_byte ( &self->m_incoming_queue );
        c = toupper ( c );
        us_buffer_write_byte ( &self->m_outgoing_queue, c );
    }
    return 1;
}

variable_types:
c
unsigned char


decompiled_code:
__int64 __fastcall us_example_reactor_handler_echo_init(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = us_reactor_handler_tcp_init(a1, a2, a3, a4, 0x4000LL);
*(_QWORD *)(a1 + 208) = us_example_reactor_handler_echo_readable;
*(_QWORD *)(a1 + 200) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = us_reactor_handler_tcp_init(a1, a2, a3, a4, 0x4000LL);
*(_QWORD *)(a1 + 208) = us_example_reactor_handler_echo_readable;
*(_QWORD *)(a1 + 200) = 0LL;
return result;
}

original_code:
_Bool us_example_reactor_handler_echo_init (
    us_reactor_handler_t *self_,
    us_allocator_t *allocator,
    int fd,
    void *extra
)
{
    us_reactor_handler_tcp_t *self = ( us_reactor_handler_tcp_t * ) self_;
    _Bool r;
    r = us_reactor_handler_tcp_init (
            &self->m_base,
            allocator,
            fd,
            extra,
            16384
        );
    self->readable = us_example_reactor_handler_echo_readable;
    self->tick = 0;
    return r;
}

canonical_original_code:
_Bool us_example_reactor_handler_echo_init(struct us_reactor_handler_s *self_, struct us_allocator_s *allocator, int fd, void *extra)
{
    struct us_reactor_handler_tcp_s *self = ( us_reactor_handler_tcp_t * ) self_;
    _Bool r;
    r = us_reactor_handler_tcp_init (
            &self->m_base,
            allocator,
            fd,
            extra,
            16384
        );
    self->readable = us_example_reactor_handler_echo_readable;
    self->tick = 0;
    return r;
}


decompiled_code:
__int64 __fastcall us_example_reactor_handler_quitter_init(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = us_reactor_handler_tcp_init(a1, a2, a3, a4, 2048LL);
*(_QWORD *)(a1 + 208) = us_example_reactor_handler_quitter_readable;
*(_QWORD *)(a1 + 200) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = us_reactor_handler_tcp_init(a1, a2, a3, a4, 2048LL);
*(_QWORD *)(a1 + 208) = us_example_reactor_handler_quitter_readable;
*(_QWORD *)(a1 + 200) = 0LL;
return result;
}

original_code:
_Bool us_example_reactor_handler_quitter_init (
    us_reactor_handler_t *self_,
    us_allocator_t *allocator,
    int fd,
    void *extra
)
{
    us_reactor_handler_tcp_t *self = ( us_reactor_handler_tcp_t * ) self_;
    _Bool r;
    r = us_reactor_handler_tcp_init (
            &self->m_base,
            allocator,
            fd,
            extra,
            2048
        );
    self->readable = us_example_reactor_handler_quitter_readable;
    self->tick = 0;
    return r;
}

canonical_original_code:
_Bool us_example_reactor_handler_quitter_init(struct us_reactor_handler_s *self_, struct us_allocator_s *allocator, int fd, void *extra)
{
    struct us_reactor_handler_tcp_s *self = ( us_reactor_handler_tcp_t * ) self_;
    _Bool r;
    r = us_reactor_handler_tcp_init (
            &self->m_base,
            allocator,
            fd,
            extra,
            2048
        );
    self->readable = us_example_reactor_handler_quitter_readable;
    self->tick = 0;
    return r;
}


decompiled_code:
__int64 __fastcall us_example_reactor_echo_server_init(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return us_reactor_handler_tcp_server_init(
a1,
a2,
a3,
a4,
us_example_reactor_handler_echo_create,
us_example_reactor_handler_echo_init);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return us_reactor_handler_tcp_server_init(
a1,
a2,
a3,
a4,
us_example_reactor_handler_echo_create,
us_example_reactor_handler_echo_init);
}

original_code:
_Bool us_example_reactor_echo_server_init (
    us_reactor_handler_t *self,
    us_allocator_t *allocator,
    int fd,
    void *extra
)
{
    return us_reactor_handler_tcp_server_init (
               self,
               allocator,
               fd,
               extra,
               us_example_reactor_handler_echo_create,
               us_example_reactor_handler_echo_init
           );
}

canonical_original_code:
_Bool us_example_reactor_echo_server_init(struct us_reactor_handler_s *self, struct us_allocator_s *allocator, int fd, void *extra)
{
    return us_reactor_handler_tcp_server_init (
               self,
               allocator,
               fd,
               extra,
               us_example_reactor_handler_echo_create,
               us_example_reactor_handler_echo_init
           );
}


decompiled_code:
__int64 __fastcall us_example_reactor_quitter_server_init(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return us_reactor_handler_tcp_server_init(
a1,
a2,
a3,
a4,
us_example_reactor_handler_quitter_create,
us_example_reactor_handler_quitter_init);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return us_reactor_handler_tcp_server_init(
a1,
a2,
a3,
a4,
us_example_reactor_handler_quitter_create,
us_example_reactor_handler_quitter_init);
}

original_code:
_Bool us_example_reactor_quitter_server_init (
    us_reactor_handler_t *self,
    us_allocator_t *allocator,
    int fd,
    void *extra
)
{
    return us_reactor_handler_tcp_server_init (
               self,
               allocator,
               fd,
               extra,
               us_example_reactor_handler_quitter_create,
               us_example_reactor_handler_quitter_init
           );
}

canonical_original_code:
_Bool us_example_reactor_quitter_server_init(struct us_reactor_handler_s *self, struct us_allocator_s *allocator, int fd, void *extra)
{
    return us_reactor_handler_tcp_server_init (
               self,
               allocator,
               fd,
               extra,
               us_example_reactor_handler_quitter_create,
               us_example_reactor_handler_quitter_init
           );
}


decompiled_code:
__int64 __fastcall us_example_reactor_handler_echo_connected(__int64 a1, const struct sockaddr *a2, socklen_t a3)
{
int v3; // edx
__int64 result; // rax
char serv[32]; // [rsp+8h] [rbp-438h] BYREF
char host[1048]; // [rsp+28h] [rbp-418h] BYREF

v3 = getnameinfo(a2, a3, host, 0x401u, serv, 0x20u, 3);
result = 0LL;
if ( !v3 )
{
fprintf(stdout, "Accepting connection from '%s' port '%s'\n", host, serv);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, const struct sockaddr *a2, socklen_t a3)
{
int v3; // edx
__int64 result; // rax
char serv[32]; // [rsp+8h] [rbp-438h] BYREF
char host[1048]; // [rsp+28h] [rbp-418h] BYREF

v3 = getnameinfo(a2, a3, host, 0x401u, serv, 0x20u, 3);
result = 0LL;
if ( !v3 )
{
fprintf(stdout, "Accepting connection from '%s' port '%s'\n", host, serv);
result = 1LL;
}
return result;
}

original_code:
_Bool us_example_reactor_handler_echo_connected (
    us_reactor_handler_tcp_t *self,
    struct sockaddr *addr,
    socklen_t addrlen
)
{
    _Bool r = 0;
    char host[1025];
    char serv[32];
    (void)self;
    if ( getnameinfo (
                addr,
                addrlen,
                host,
                sizeof ( host ),
                serv,
                sizeof ( serv ),
                1 | 2 ) == 0
       )
    {
        fprintf ( stdout, "Accepting connection from '%s' port '%s'\n", host, serv );
        r = 1;
    }
    return r;
}

canonical_original_code:
_Bool us_example_reactor_handler_echo_connected(struct us_reactor_handler_tcp_s *self, struct sockaddr *addr, unsigned int addrlen)
{
    _Bool r = 0;
    char host[1025];
    char serv[32];
    (void)self;
    if ( getnameinfo (
                addr,
                addrlen,
                host,
                sizeof ( host ),
                serv,
                sizeof ( serv ),
                1 | 2 ) == 0
       )
    {
        fprintf ( stdout, "Accepting connection from '%s' port '%s'\n", host, serv );
        r = 1;
    }
    return r;
}

variable_types:
addr
struct sockaddr *

variable_types:
addrlen
unsigned int

variable_types:
host
char [1025]

variable_types:
serv
char [32]


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

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

original_code:
_Bool us_example_reactor_handler_echo_tick (
    us_reactor_handler_tcp_t *self
)
{
    (void)self;
    return 1;
}

canonical_original_code:
_Bool us_example_reactor_handler_echo_tick(struct us_reactor_handler_tcp_s *self)
{
    (void)self;
    return 1;
}


decompiled_code:
__int64 __fastcall us_example_reactor(__int64 a1)
{
unsigned int v1; // ebx
__int64 v3[11]; // [rsp+0h] [rbp-58h] BYREF

if ( !(unsigned __int8)us_reactor_init(v3, a1, 16LL)
|| !(unsigned __int8)us_reactor_create_tcp_client(
v3,
a1,
stdout,
4096LL,
"github.com",
"80",
0LL,
us_example_reactor_handler_http_create,
us_example_reactor_handler_http_init)
|| !(unsigned __int8)us_reactor_create_server(
v3,
a1,
0LL,
"8989",
1LL,
0LL,
&us_reactor_handler_tcp_server_create,
us_example_reactor_echo_server_init) )
{
return 0;
}
v1 = us_reactor_create_server(
v3,
a1,
0LL,
"8988",
1LL,
0LL,
&us_reactor_handler_tcp_server_create,
us_example_reactor_quitter_server_init);
if ( (_BYTE)v1 )
{
while ( !global_quit )
{
if ( !((unsigned __int8 (__fastcall *)(__int64 *, __int64))v3[6])(v3, 2000LL) )
break;
fwrite("tick\n", 1uLL, 5uLL, stdout);
}
((void (__fastcall *)(__int64 *))v3[0])(v3);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
unsigned int v1; // ebx
__int64 v3[11]; // [rsp+0h] [rbp-58h] BYREF

if ( !(unsigned __int8)us_reactor_init(v3, a1, 16LL)
|| !(unsigned __int8)us_reactor_create_tcp_client(
v3,
a1,
stdout,
4096LL,
"github.com",
"80",
0LL,
us_example_reactor_handler_http_create,
us_example_reactor_handler_http_init)
|| !(unsigned __int8)us_reactor_create_server(
v3,
a1,
0LL,
"8989",
1LL,
0LL,
&us_reactor_handler_tcp_server_create,
us_example_reactor_echo_server_init) )
{
return 0;
}
v1 = us_reactor_create_server(
v3,
a1,
0LL,
"8988",
1LL,
0LL,
&us_reactor_handler_tcp_server_create,
us_example_reactor_quitter_server_init);
if ( (_BYTE)v1 )
{
while ( !global_quit )
{
if ( !((unsigned __int8 (__fastcall *)(__int64 *, __int64))v3[6])(v3, 2000LL) )
break;
fwrite("tick\n", 1uLL, 5uLL, stdout);
}
((void (__fastcall *)(__int64 *))v3[0])(v3);
}
return v1;
}

original_code:
_Bool us_example_reactor ( us_allocator_t *allocator )
{
    _Bool r = 0;
    us_reactor_t reactor;
    r = us_reactor_init (
            &reactor,
            allocator,
            16
        );
    if ( r )
    {
        r = us_reactor_create_tcp_client(
                &reactor,
                allocator,
                (void *)stdout,
                4096,
                "github.com", "80", 0,
                us_example_reactor_handler_http_create,
                us_example_reactor_handler_http_init
            );
    }
    if ( r )
    {
        r = us_reactor_create_server (
                &reactor,
                allocator,
                0, "8989",
                SOCK_STREAM,
                0,
                us_reactor_handler_tcp_server_create,
                us_example_reactor_echo_server_init
            );
    }
    if ( r )
    {
        r = us_reactor_create_server (
                &reactor,
                allocator,
                0, "8988",
                SOCK_STREAM,
                0,
                us_reactor_handler_tcp_server_create,
                us_example_reactor_quitter_server_init
            );
    }
    if ( r )
    {
        while ( !global_quit && reactor.poll ( &reactor, 2000 ) )
        {
            fprintf ( stdout, "tick\n" );
        }
        reactor.destroy ( &reactor );
        r = 1;
    }
    return r;
}

canonical_original_code:
_Bool us_example_reactor(struct us_allocator_s *allocator)
{
    _Bool r = 0;
    struct us_reactor_s reactor;
    r = us_reactor_init (
            &reactor,
            allocator,
            16
        );
    if ( r )
    {
        r = us_reactor_create_tcp_client(
                &reactor,
                allocator,
                (void *)stdout,
                4096,
                "github.com", "80", 0,
                us_example_reactor_handler_http_create,
                us_example_reactor_handler_http_init
            );
    }
    if ( r )
    {
        r = us_reactor_create_server (
                &reactor,
                allocator,
                0, "8989",
                SOCK_STREAM,
                0,
                us_reactor_handler_tcp_server_create,
                us_example_reactor_echo_server_init
            );
    }
    if ( r )
    {
        r = us_reactor_create_server (
                &reactor,
                allocator,
                0, "8988",
                SOCK_STREAM,
                0,
                us_reactor_handler_tcp_server_create,
                us_example_reactor_quitter_server_init
            );
    }
    if ( r )
    {
        while ( !global_quit && reactor.poll ( &reactor, 2000 ) )
        {
            fprintf ( stdout, "tick\n" );
        }
        reactor.destroy ( &reactor );
        r = 1;
    }
    return r;
}

variable_types: struct us_reactor_s { void (*destroy)(struct us_reactor_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_reactor_handler_s { void (*destroy)(struct us_reactor_handler_s *self); void (*close)(struct us_reactor_handler_s *self); _Bool (*tick)(struct us_reactor_handler_s *self); _Bool (*readable)(struct us_reactor_handler_s *self); _Bool (*writable)(struct us_reactor_handler_s *self); struct us_allocator_s *m_allocator; _Bool m_finished; struct us_reactor_handler_s *m_next; struct us_reactor_s *m_reactor; void *m_extra; int m_fd; _Bool m_wake_on_readable; _Bool m_wake_on_writable; } *m_handlers; int m_timeout; int m_max_handlers; int m_num_handlers; struct pollfd { int fd; short events; short revents; } *m_poll_handlers; _Bool (*poll)(struct us_reactor_s *self, int timeout); _Bool (*add_item)(struct us_reactor_s *self, struct us_reactor_handler_s *item); _Bool (*remove_item)(struct us_reactor_s *self, struct us_reactor_handler_s *item); }


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

*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 8) = a3;
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
result = (unsigned int)(a3 - 1);
if ( (a3 & (unsigned int)result) != 0 )
{
if ( us_log_level > 0 )
us_log_error_proc("logic error, queue size is not a power of two");
abort();
}
return result;
}

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

*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 8) = a3;
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
result = (unsigned int)(a3 - 1);
if ( (a3 & (unsigned int)result) != 0 )
{
if ( us_log_level > 0 )
us_log_error_proc("logic error, queue size is not a power of two");
abort();
}
return result;
}

original_code:
void us_queue_init( us_queue_t *self, uint8_t *buf, int buf_size )
{
    self->m_buf = buf;
    self->m_buf_size = buf_size;
    self->m_next_in = 0;
    self->m_next_out = 0;
    if ( ( buf_size & ( buf_size - 1 ) ) != 0 )
    {
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "logic error, queue size is not a power of two" ); } while ( 0 );
        abort();
    }
}

canonical_original_code:
void us_queue_init(struct us_queue_s *self, unsigned char *buf, int buf_size)
{
    self->m_buf = buf;
    self->m_buf_size = buf_size;
    self->m_next_in = 0;
    self->m_next_out = 0;
    if ( ( buf_size & ( buf_size - 1 ) ) != 0 )
    {
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "logic error, queue size is not a power of two" ); } while ( 0 );
        abort();
    }
}

variable_types: struct us_queue_s { int m_next_in; int m_next_out; int m_buf_size; unsigned char *m_buf; } *

variable_types:
buf
unsigned char *


decompiled_code:
__int64 __fastcall us_queue_read(__int64 a1, _BYTE *a2, int a3)
{
__int64 result; // rax
_BYTE *v4; // rdx
__int64 v5; // rsi

result = (unsigned int)a3;
if ( a3 > 0 )
{
v4 = a2;
v5 = (__int64)&a2[(unsigned int)(result - 1) + 1];
do
{
*v4 = *(_BYTE *)(*(_QWORD *)(a1 + 16) + *(int *)(a1 + 4));
result = (unsigned int)(*(_DWORD *)(a1 + 4) + 1);
*(_DWORD *)(a1 + 4) = result;
if ( (_DWORD)result == *(_DWORD *)(a1 + 8) )
*(_DWORD *)(a1 + 4) = 0;
++v4;
}
while ( v4 != (_BYTE *)v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _BYTE *a2, int a3)
{
__int64 result; // rax
_BYTE *v4; // rdx
__int64 v5; // rsi

result = (unsigned int)a3;
if ( a3 > 0 )
{
v4 = a2;
v5 = (__int64)&a2[(unsigned int)(result - 1) + 1];
do
{
*v4 = *(_BYTE *)(*(_QWORD *)(a1 + 16) + *(int *)(a1 + 4));
result = (unsigned int)(*(_DWORD *)(a1 + 4) + 1);
*(_DWORD *)(a1 + 4) = result;
if ( (_DWORD)result == *(_DWORD *)(a1 + 8) )
*(_DWORD *)(a1 + 4) = 0;
++v4;
}
while ( v4 != (_BYTE *)v5 );
}
return result;
}

original_code:
void us_queue_read( us_queue_t *self, uint8_t *dest_data, int dest_data_cnt )
{
    int i;
    for ( i = 0; i < dest_data_cnt; ++i )
    {
        dest_data[i] = self->m_buf[self->m_next_out];
        if ( ++self->m_next_out == self->m_buf_size )
        {
            self->m_next_out = 0;
        }
    }
}

canonical_original_code:
void us_queue_read(struct us_queue_s *self, unsigned char *dest_data, int dest_data_cnt)
{
    int i;
    for ( i = 0; i < dest_data_cnt; ++i )
    {
        dest_data[i] = self->m_buf[self->m_next_out];
        if ( ++self->m_next_out == self->m_buf_size )
        {
            self->m_next_out = 0;
        }
    }
}

variable_types: i int

user_defined_types: struct us_queue_s { int m_next_in; int m_next_out; int m_buf_size; unsigned char *m_buf; }


decompiled_code:
__int64 __fastcall us_queue_write(int *a1, _BYTE *a2, int a3)
{
__int64 result; // rax
_BYTE *v4; // rdx
__int64 v5; // r8

result = (unsigned int)a3;
if ( a3 > 0 )
{
v4 = a2;
v5 = (__int64)&a2[(unsigned int)(result - 1) + 1];
do
{
*(_BYTE *)(*((_QWORD *)a1 + 2) + *a1) = *v4;
result = (unsigned int)(*a1 + 1);
*a1 = result;
if ( (_DWORD)result == a1[2] )
*a1 = 0;
++v4;
}
while ( v4 != (_BYTE *)v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, _BYTE *a2, int a3)
{
__int64 result; // rax
_BYTE *v4; // rdx
__int64 v5; // r8

result = (unsigned int)a3;
if ( a3 > 0 )
{
v4 = a2;
v5 = (__int64)&a2[(unsigned int)(result - 1) + 1];
do
{
*(_BYTE *)(*((_QWORD *)a1 + 2) + *a1) = *v4;
result = (unsigned int)(*a1 + 1);
*a1 = result;
if ( (_DWORD)result == a1[2] )
*a1 = 0;
++v4;
}
while ( v4 != (_BYTE *)v5 );
}
return result;
}

original_code:
void us_queue_write( us_queue_t *self, const uint8_t *src_data, int src_data_cnt )
{
    int i;
    for ( i = 0; i < src_data_cnt; i++ )
    {
        self->m_buf[self->m_next_in] = src_data[i];
        if ( ++self->m_next_in == self->m_buf_size )
        {
            self->m_next_in = 0;
        }
    }
}

canonical_original_code:
void us_queue_write(struct us_queue_s *self, unsigned char *src_data, int src_data_cnt)
{
    int i;
    for ( i = 0; i < src_data_cnt; i++ )
    {
        self->m_buf[self->m_next_in] = src_data[i];
        if ( ++self->m_next_in == self->m_buf_size )
        {
            self->m_next_in = 0;
        }
    }
}


decompiled_code:
char __fastcall us_osc_msg_bundle_print(__int64 a1, __int64 a2)
{
char result; // al
__int64 v3; // rbx

result = a2 != 0 && a1 != 0;
if ( result )
{
result = (*(__int64 (**)(__int64, const char *, ...))(a2 + 8))(
a2,
"msg_bundle_t: timetag: 0x%08lx%08lx\n",
*(unsigned int *)(a1 + 32),
*(unsigned int *)(a1 + 36));
v3 = *(_QWORD *)(a1 + 40);
if ( v3 )
{
if ( result )
{
do
{
result = (*(__int64 (__fastcall **)(__int64, __int64))(v3 + 16))(v3, a2);
v3 = *(_QWORD *)(v3 + 72);
}
while ( v3 && result );
}
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func0(__int64 a1, __int64 a2)
{
char result; // al
__int64 v3; // rbx

result = a2 != 0 && a1 != 0;
if ( result )
{
result = (*(__int64 (**)(__int64, const char *, ...))(a2 + 8))(
a2,
"msg_bundle_t: timetag: 0x%08lx%08lx\n",
*(unsigned int *)(a1 + 32),
*(unsigned int *)(a1 + 36));
v3 = *(_QWORD *)(a1 + 40);
if ( v3 )
{
if ( result )
{
do
{
result = (*(__int64 (__fastcall **)(__int64, __int64))(v3 + 16))(v3, a2);
v3 = *(_QWORD *)(v3 + 72);
}
while ( v3 && result );
}
}
}
return result;
}

original_code:
_Bool us_osc_msg_bundle_print( const us_osc_msg_bundle_t *self, us_print_t *printer )
{
    _Bool r = 0;
    if ( self && printer )
    {
        us_osc_msg_t *cur = 0;
        r = 1;
        r &= printer->printf( printer, "msg_bundle_t:  timetag: 0x%08lx%08lx\n", self->m_timetag_high, self->m_timetag_low );
        cur = self->m_first_msg;
        while ( cur && r )
        {
            r &= cur->print( cur, printer );
            cur = cur->m_next;
        }
    }
    return r;
}

canonical_original_code:
_Bool us_osc_msg_bundle_print(struct us_osc_msg_bundle_s *self, struct us_print_s *printer)
{
    _Bool r = 0;
    if ( self && printer )
    {
        struct us_osc_msg_s *cur = 0;
        r = 1;
        r &= printer->printf( printer, "msg_bundle_t:  timetag: 0x%08lx%08lx\n", self->m_timetag_high, self->m_timetag_low );
        cur = self->m_first_msg;
        while ( cur && r )
        {
            r &= cur->print( cur, printer );
            cur = cur->m_next;
        }
    }
    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; } *

variable_types:
printer
struct us_print_s *

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:
char __fastcall us_osc_msg_print(__int64 a1, __int64 a2)
{
char result; // al
__int64 v3; // rbx

result = a2 != 0 && a1 != 0;
if ( result )
{
result = (*(__int64 (**)(__int64, const char *, ...))(a2 + 8))(
a2,
"msg_t: address: '%s'\n",
*(const char **)(a1 + 40));
v3 = *(_QWORD *)(a1 + 56);
if ( v3 )
{
if ( result )
{
do
{
result = (*(__int64 (__fastcall **)(__int64, __int64))(v3 + 8))(v3, a2);
v3 = *(_QWORD *)(v3 + 24);
}
while ( v3 && result );
}
}
}
return result;
}

original_code:
_Bool us_osc_msg_print( const us_osc_msg_t *self, us_print_t *printer )
{
    _Bool r = 0;
    if ( self && printer )
    {
        us_osc_msg_element_t *cur = 0;
        r = 1;
        r &= printer->printf( printer, "msg_t: address: '%s'\n", self->m_address );
        cur = self->m_first_element;
        while ( cur && r )
        {
            r &= cur->print( cur, printer );
            cur = cur->m_next;
        }
    }
    return r;
}

canonical_original_code:
_Bool us_osc_msg_print(struct us_osc_msg_s *self, struct us_print_s *printer)
{
    _Bool r = 0;
    if ( self && printer )
    {
        struct us_osc_msg_element_s *cur = 0;
        r = 1;
        r &= printer->printf( printer, "msg_t: address: '%s'\n", self->m_address );
        cur = self->m_first_element;
        while ( cur && r )
        {
            r &= cur->print( cur, printer );
            cur = cur->m_next;
        }
    }
    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 us_osc_msg_element_print(__int64 a1, __int64 a2)
{
return (*(__int64 (**)(__int64, const char *, ...))(a2 + 8))(
a2,
"UNKNOWN TYPE: '%c'\n",
(unsigned int)*(char *)(a1 + 32));
}

original_code:
_Bool us_osc_msg_element_print( const us_osc_msg_element_t *self, us_print_t *printer )
{
    return printer->printf( printer, "UNKNOWN TYPE: '%c'\n", self->m_code );
}

canonical_original_code:
_Bool us_osc_msg_element_print(struct us_osc_msg_element_s *self, struct us_print_s *printer)
{
    return printer->printf( printer, "UNKNOWN TYPE: '%c'\n", self->m_code );
}

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


decompiled_code:
__int64 __fastcall us_osc_msg_element_a_print(__int64 a1, __int64 a2)
{
return (*(__int64 (**)(__int64, const char *, ...))(a2 + 8))(
a2,
"msg_element_%c_t: 0x%08lx%08lx\n",
(unsigned int)*(char *)(a1 + 32),
*(unsigned int *)(a1 + 40),
*(unsigned int *)(a1 + 44));
}

original_code:
_Bool us_osc_msg_element_a_print( const us_osc_msg_element_t *self_, us_print_t *printer )
{
    us_osc_msg_element_a_t *self = (us_osc_msg_element_a_t *)self_;
    return printer->printf(
        printer, "msg_element_%c_t: 0x%08lx%08lx\n", self->m_base.m_code, self->m_time_high, self->m_time_low );
}

canonical_original_code:
_Bool us_osc_msg_element_a_print(struct us_osc_msg_element_s *self_, struct us_print_s *printer)
{
    struct us_osc_msg_element_a_s *self = (us_osc_msg_element_a_t *)self_;
    return printer->printf(
        printer, "msg_element_%c_t: 0x%08lx%08lx\n", self->m_base.m_code, self->m_time_high, self->m_time_low );
}

variable_types: struct us_osc_msg_element_a_s { 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; } m_base; unsigned int m_time_high; unsigned int m_time_low; } *

user_defined_types: struct us_osc_msg_element_a_s { struct us_osc_msg_element_s m_base; unsigned int m_time_high; unsigned int m_time_low; }