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


repo: jdkoftinoff/microsupport

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

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 us_test_json()
{
__int64 v0; // rbx
void (__fastcall **v1)(_QWORD); // r12
__int64 v2; // rax
_QWORD *v3; // rbp
unsigned int v4; // er13
__int64 v5; // rbx
__int64 v6; // rbx
__int64 v7; // r14
char *v8; // rbx
int v9; // er13
int v10; // er13
__int64 i; // rax
int v12; // eax
__int64 v13; // r12
__int64 v14; // rbx
unsigned __int8 v15; // al
__int64 v16; // rax
__int64 v18[4]; // [rsp+0h] [rbp-C8h] BYREF
_QWORD v19[4]; // [rsp+20h] [rbp-A8h] BYREF
_QWORD v20[4]; // [rsp+40h] [rbp-88h] BYREF
int v21[11]; // [rsp+60h] [rbp-68h] BYREF
char v22; // [rsp+8Ch] [rbp-3Ch] BYREF

v0 = us_testutil_sys_allocator;
v1 = (void (__fastcall **)(_QWORD))us_json_create(us_testutil_sys_allocator);
v2 = us_buffer_create(v0, 1024LL);
if ( !v2 )
abort();
v3 = (_QWORD *)v2;
v4 = 0;
if ( v1 )
{
v18[0] = 1717986634LL;
v18[1] = 0LL;
v18[2] = 0LL;
v18[3] = 0LL;
v19[0] = 0x6E6F6E726556LL;
v19[1] = 0LL;
v19[2] = 0LL;
v19[3] = 0LL;
v20[0] = 0x6164616E6143LL;
v20[1] = 0LL;
v20[2] = 0LL;
v20[3] = 0LL;
v21[0] = 1;
v21[1] = 3;
v21[2] = 6;
v21[3] = 10;
v21[4] = 15;
v21[5] = 14;
v21[6] = 11;
v21[7] = 4;
v21[8] = 2;
v21[9] = 1;
v21[10] = 0;
v5 = us_json_append_string_ptr(v1, "name", v18);
if ( us_json_append_int32_ptr(v1, "hitpoints", &hitpoints_0) )
LOBYTE(v4) = v5 != 0;
v6 = us_json_append_object(v1, "address");
if ( !us_json_append_string_ptr(v6, "city", v19) )
v4 = 0;
if ( !us_json_append_string_ptr(v6, "country", v20) )
v4 = 0;
v7 = us_json_append_object(v1, "histogram");
us_json_set_array(v7, 1);
v8 = (char *)v21;
while ( us_json_append_int32_ptr(v7, 0LL, v8) )
{
v8 += 4;
if ( v8 == &v22 )
goto LABEL_12;
}
v4 = 0;
LABEL_12:
v9 = us_json_flatten_to_buffer(v1, v3) & v4;
v10 = us_buffer_append_string(v3, ", \n") & v9;
strcpy((char *)v18, "John");
strcpy((char *)v19, "Berkeley");
strcpy((char *)v20, "United States");
hitpoints_0 = 999;
for ( i = 0LL; i != 11; ++i )
v21[i] = i * i;
v4 = us_json_flatten_to_buffer(v1, v3) & v10;
(*v1)(v1);
}
v12 = us_buffer_readable_count(v3);
if ( v12 > 0 )
{
v13 = (unsigned int)(v12 - 1);
v14 = 0LL;
do
{
v15 = us_buffer_peek(v3, v14);
fputc(v15, stdout);
v16 = v14++;
}
while ( v16 != v13 );
}
fputc(10, stdout);
return v4;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbx
void (__fastcall **v1)(_QWORD); // r12
__int64 v2; // rax
_QWORD *v3; // rbp
unsigned int v4; // er13
__int64 v5; // rbx
__int64 v6; // rbx
__int64 v7; // r14
char *v8; // rbx
int v9; // er13
int v10; // er13
__int64 i; // rax
int v12; // eax
__int64 v13; // r12
__int64 v14; // rbx
unsigned __int8 v15; // al
__int64 v16; // rax
__int64 v18[4]; // [rsp+0h] [rbp-C8h] BYREF
_QWORD v19[4]; // [rsp+20h] [rbp-A8h] BYREF
_QWORD v20[4]; // [rsp+40h] [rbp-88h] BYREF
int v21[11]; // [rsp+60h] [rbp-68h] BYREF
char v22; // [rsp+8Ch] [rbp-3Ch] BYREF

v0 = us_testutil_sys_allocator;
v1 = (void (__fastcall **)(_QWORD))us_json_create(us_testutil_sys_allocator);
v2 = us_buffer_create(v0, 1024LL);
if ( !v2 )
abort();
v3 = (_QWORD *)v2;
v4 = 0;
if ( v1 )
{
v18[0] = 1717986634LL;
v18[1] = 0LL;
v18[2] = 0LL;
v18[3] = 0LL;
v19[0] = 0x6E6F6E726556LL;
v19[1] = 0LL;
v19[2] = 0LL;
v19[3] = 0LL;
v20[0] = 0x6164616E6143LL;
v20[1] = 0LL;
v20[2] = 0LL;
v20[3] = 0LL;
v21[0] = 1;
v21[1] = 3;
v21[2] = 6;
v21[3] = 10;
v21[4] = 15;
v21[5] = 14;
v21[6] = 11;
v21[7] = 4;
v21[8] = 2;
v21[9] = 1;
v21[10] = 0;
v5 = us_json_append_string_ptr(v1, "name", v18);
if ( us_json_append_int32_ptr(v1, "hitpoints", &hitpoints_0) )
LOBYTE(v4) = v5 != 0;
v6 = us_json_append_object(v1, "address");
if ( !us_json_append_string_ptr(v6, "city", v19) )
v4 = 0;
if ( !us_json_append_string_ptr(v6, "country", v20) )
v4 = 0;
v7 = us_json_append_object(v1, "histogram");
func2(v7, 1);
v8 = (char *)v21;
while ( us_json_append_int32_ptr(v7, 0LL, v8) )
{
v8 += 4;
if ( v8 == &v22 )
goto LABEL_12;
}
v4 = 0;
LABEL_12:
v9 = us_json_flatten_to_buffer(v1, v3) & v4;
v10 = us_buffer_append_string(v3, ", \n") & v9;
strcpy((char *)v18, "John");
strcpy((char *)v19, "Berkeley");
strcpy((char *)v20, "United States");
hitpoints_0 = 999;
for ( i = 0LL; i != 11; ++i )
v21[i] = i * i;
v4 = us_json_flatten_to_buffer(v1, v3) & v10;
(*v1)(v1);
}
v12 = func0(v3);
if ( v12 > 0 )
{
v13 = (unsigned int)(v12 - 1);
v14 = 0LL;
do
{
v15 = func1(v3, v14);
fputc(v15, stdout);
v16 = v14++;
}
while ( v16 != v13 );
}
fputc(10, stdout);
return v4;
}

original_code:
static _Bool us_test_json( void )
{
    _Bool r = 0;
    us_allocator_t *allocator = us_testutil_sys_allocator;
    us_json_t *j = us_json_create( allocator );
    us_buffer_t *b = us_buffer_create( allocator, 1024 );
    if ( !b )
    {
        abort();
    }
    if ( j )
    {
        int i;
        us_json_t *a = 0;
        us_json_t *a1 = 0;
        char name[32] = "Jeff";
        char city[32] = "Vernon";
        char country[32] = "Canada";
        int32_t histogram[11] = {1, 3, 6, 10, 15, 14, 11, 4, 2, 1, 0};
        static int32_t hitpoints = 90210;
        r = 1;
        if ( !us_json_append_string_ptr( j, "name", name ) )
            r = 0;
        if ( !us_json_append_int32_ptr( j, "hitpoints", &hitpoints ) )
            r = 0;
        a = us_json_append_object( j, "address" );
        if ( !us_json_append_string_ptr( a, "city", city ) )
            r = 0;
        if ( !us_json_append_string_ptr( a, "country", country ) )
            r = 0;
        a1 = us_json_append_object( j, "histogram" );
        us_json_set_array( a1, 1 );
        for ( i = 0; i < (int)( sizeof( histogram ) / sizeof( histogram[0] ) ); ++i )
        {
            if ( !us_json_append_int32_ptr( a1, 0, &histogram[i] ) )
            {
                r = 0;
                break;
            }
        }
        r &= us_json_flatten_to_buffer( j, b );
        r &= us_buffer_append_string( b, ", \n" );
        strcpy( name, "John" );
        strcpy( city, "Berkeley" );
        strcpy( country, "United States" );
        hitpoints = 999;
        for ( i = 0; i < (int)( sizeof( histogram ) / sizeof( histogram[0] ) ); ++i )
        {
            histogram[i] = i * i;
        }
        r &= us_json_flatten_to_buffer( j, b );
        j->destroy( j );
    }
    {
        int i = 0;
        int len = (int)us_buffer_readable_count( b );
        for ( i = 0; i < len; ++i )
        {
            fprintf( stdout, "%c", us_buffer_peek( b, i ) );
        }
        fprintf( stdout, "\n" );
    }
    return r;
}

canonical_original_code:
static _Bool us_test_json()
{
    _Bool r = 0;
    struct us_allocator_s *allocator = us_testutil_sys_allocator;
    struct us_json_s *j = us_json_create( allocator );
    struct us_buffer_s *b = us_buffer_create( allocator, 1024 );
    if ( !b )
    {
        abort();
    }
    if ( j )
    {
        int i;
        struct us_json_s *a = 0;
        struct us_json_s *a1 = 0;
        char name[32] = "Jeff";
        char city[32] = "Vernon";
        char country[32] = "Canada";
        int histogram[11] = {1, 3, 6, 10, 15, 14, 11, 4, 2, 1, 0};
        static int hitpoints = 90210;
        r = 1;
        if ( !us_json_append_string_ptr( j, "name", name ) )
            r = 0;
        if ( !us_json_append_int32_ptr( j, "hitpoints", &hitpoints ) )
            r = 0;
        a = us_json_append_object( j, "address" );
        if ( !us_json_append_string_ptr( a, "city", city ) )
            r = 0;
        if ( !us_json_append_string_ptr( a, "country", country ) )
            r = 0;
        a1 = us_json_append_object( j, "histogram" );
        us_json_set_array( a1, 1 );
        for ( i = 0; i < (int)( sizeof( histogram ) / sizeof( histogram[0] ) ); ++i )
        {
            if ( !us_json_append_int32_ptr( a1, 0, &histogram[i] ) )
            {
                r = 0;
                break;
            }
        }
        r &= us_json_flatten_to_buffer( j, b );
        r &= us_buffer_append_string( b, ", \n" );
        strcpy( name, "John" );
        strcpy( city, "Berkeley" );
        strcpy( country, "United States" );
        hitpoints = 999;
        for ( i = 0; i < (int)( sizeof( histogram ) / sizeof( histogram[0] ) ); ++i )
        {
            histogram[i] = i * i;
        }
        r &= us_json_flatten_to_buffer( j, b );
        j->destroy( j );
    }
    {
        int i = 0;
        int len = (int)us_buffer_readable_count( b );
        for ( i = 0; i < len; ++i )
        {
            fprintf( stdout, "%c", us_buffer_peek( b, i ) );
        }
        fprintf( stdout, "\n" );
    }
    return r;
}

variable_types: struct us_json_s { void (*destroy)(struct us_json_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_json_entry_s { struct us_allocator_s *m_allocator; char *m_key; union { struct us_json_s *m_value_json; char *m_value_string_ptr; int *m_value_int32_ptr; 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_value_string_buffer; int m_value_int32; } value; enum us_json_type_t { us_json_type_none=0, us_json_type_json=1, us_json_type_string_ptr=2, us_json_type_int32_ptr=3, us_json_type_string_buffer=4, us_json_type_int32=5 } m_type; struct us_json_entry_s *m_next; } *m_first_item; struct us_json_entry_s *m_last_item; _Bool m_is_array; } *

variable_types: i int

variable_types:
name
char [32]

variable_types:
city
char [32]

variable_types:
country
char [32]

variable_types:
histogram
int [11]

variable_types: hitpoints int

variable_types: len int

user_defined_types: struct us_json_s { void (*destroy)(struct us_json_s *self); struct us_allocator_s *m_allocator; struct us_json_entry_s *m_first_item; struct us_json_entry_s *m_last_item; _Bool m_is_array; }

user_defined_types: struct us_json_entry_s { struct us_allocator_s *m_allocator; char *m_key; union { struct us_json_s *m_value_json; char *m_value_string_ptr; int *m_value_int32_ptr; struct us_buffer_s *m_value_string_buffer; int m_value_int32; } value; enum us_json_type_t m_type; struct us_json_entry_s *m_next; }


decompiled_code:
__int64 __fastcall us_test_json_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_json_main.c", "May 23 2025");
v2 = (unsigned __int8)us_test_json() ^ 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 func4(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_json_main.c", "May 23 2025");
v2 = (unsigned __int8)func3() ^ 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_json_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_json_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_json() )
            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_json_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_json_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_json() )
            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 us_trie_dump()
{
return 0LL;
}

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

original_code:
_Bool us_trie_dump( us_trie_t *US_UNUSED_self __attribute__( ( unused ) ),
                   const char *US_UNUSED_prefix __attribute__( ( unused ) ),
                   const char *US_UNUSED_c_filename __attribute__( ( unused ) ),
                   const char *US_UNUSED_h_filename __attribute__( ( unused ) ),
                   us_print_t *US_UNUSED_c_file_printer __attribute__( ( unused ) ),
                   us_print_t *US_UNUSED_h_file_printer __attribute__( ( unused ) ) )
{
    return 0;
}

canonical_original_code:
_Bool us_trie_dump(struct us_trie_s *US_UNUSED_self, char *US_UNUSED_prefix, char *US_UNUSED_c_filename, char *US_UNUSED_h_filename, struct us_print_s *US_UNUSED_c_file_printer, struct us_print_s *US_UNUSED_h_file_printer)
{
    return 0;
}

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

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

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


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

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

original_code:
static _Bool us_test_line_parse( void )
{
    _Bool r = 1;
    return r;
}

canonical_original_code:
static _Bool us_test_line_parse()
{
    _Bool r = 1;
    return r;
}


decompiled_code:
__int64 __fastcall us_test_line_parse_main(unsigned int a1, __int64 a2)
{
unsigned int v2; // ebx

v2 = 1;
if ( (unsigned __int8)us_testutil_start(2048LL, 2048LL, 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_line_parse_main.c", "May 23 2025");
v2 = (unsigned __int8)us_test_line_parse() ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing us_test_buffer");
us_logger_finish();
us_testutil_finish();
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2)
{
unsigned int v2; // ebx

v2 = 1;
if ( (unsigned __int8)us_testutil_start(2048LL, 2048LL, 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_line_parse_main.c", "May 23 2025");
v2 = (unsigned __int8)func0() ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing us_test_buffer");
us_logger_finish();
us_testutil_finish();
}
return v2;
}

original_code:
int us_test_line_parse_main( int argc, const char **argv )
{
    int r = 1;
    if ( us_testutil_start( 2048, 2048, 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_line_parse_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_line_parse() )
            r = 0;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing us_test_buffer" ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}

canonical_original_code:
int us_test_line_parse_main(int argc, char **argv)
{
    int r = 1;
    if ( us_testutil_start( 2048, 2048, 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_line_parse_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_line_parse() )
            r = 0;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing us_test_buffer" ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}


decompiled_code:
__int64 us_test_buffer_queue()
{
int v0; // ebx
int v1; // ebx
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx
unsigned __int8 v6; // al
unsigned __int8 v7; // si
int v8; // ebx
int v9; // er12
__int64 i; // rbx
unsigned __int8 v11; // al
unsigned __int8 v12; // al
unsigned __int8 v13; // dl
unsigned __int8 v14; // cl
int v16; // [rsp+2h] [rbp-26h] BYREF
__int16 v17; // [rsp+6h] [rbp-22h]
char v18; // [rsp+8h] [rbp-20h]
int v19; // [rsp+9h] [rbp-1Fh] BYREF
__int16 v20[13]; // [rsp+Dh] [rbp-1Bh] BYREF

v19 = 1432778632;
qmemcpy(v20, "D3\"", 3);
v16 = 0;
v17 = 0;
v18 = 0;
if ( us_log_level > 3 )
us_log_debug_proc("init buffer of 8 elements");
us_buffer_init(buffer, 0LL, &mem, 8LL);
v0 = us_validate_buffer(buffer, 7u, 0);
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( us_buffer_can_write_byte(buffer) )
us_buffer_write_byte(buffer, 1);
v1 = us_validate_buffer(buffer, 6u, 1u) & v0;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( us_buffer_can_write_byte(buffer) )
us_buffer_write_byte(buffer, 5);
v2 = us_validate_buffer(buffer, 5u, 2u) & v1;
if ( us_log_level > 3 )
us_log_debug_proc("Try read first byte");
if ( us_buffer_can_read_byte((__int64)buffer) )
{
v11 = us_buffer_read_byte(buffer);
if ( v11 != 1 )
{
v2 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x01, got 0x%02x", v11);
}
}
v3 = us_validate_buffer(buffer, 6u, 1u) & v2;
if ( us_log_level > 3 )
us_log_debug_proc("Try read second byte");
if ( us_buffer_can_read_byte((__int64)buffer) )
{
v12 = us_buffer_read_byte(buffer);
if ( v12 != 5 )
{
v3 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x05, got 0x%02x", v12);
}
}
v4 = us_validate_buffer(buffer, 7u, 0) & v3;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( us_buffer_writable_count(buffer) > 6 )
us_buffer_write(buffer, (char *)&v19, 7LL);
v5 = us_validate_buffer(buffer, 0, 7u) & v4;
if ( us_log_level <= 3 )
{
v6 = us_buffer_peek(buffer, 6LL);
v7 = v20[1];
if ( v6 == LOBYTE(v20[1]) )
goto LABEL_27;
v5 = 0;
if ( us_log_level <= 0 )
goto LABEL_27;
goto LABEL_24;
}
us_log_debug_proc("Try peek 7th byte");
v6 = us_buffer_peek(buffer, 6LL);
v7 = v20[1];
if ( LOBYTE(v20[1]) != v6 )
{
v5 = 0;
if ( us_log_level > 0 )
{
LABEL_24:
us_log_error_proc("Expected 0x%02x, got 0x%02x", v7, v6);
v5 = 0;
goto LABEL_25;
}
}
LABEL_25:
if ( us_log_level > 3 )
us_log_debug_proc("Try skip 7 bytes");
LABEL_27:
us_buffer_skip((__int64)buffer, 7LL);
v8 = us_validate_buffer(buffer, 7u, 0) & v5;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( us_buffer_writable_count(buffer) > 6 )
us_buffer_write(buffer, (char *)&v19, 7LL);
v9 = v8 & us_validate_buffer(buffer, 0, 7u);
if ( us_log_level > 3 )
us_log_debug_proc("Try read 7 bytes");
us_buffer_read(buffer, &v16, 7LL);
for ( i = 0LL; i != 7; ++i )
{
v13 = *((_BYTE *)&v19 + i);
v14 = *((_BYTE *)&v16 + i);
if ( v13 != v14 )
{
v9 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected byte %d to be 0x%02x, got 0x%02x", (unsigned int)i, v13, v14);
}
}
return v9 & (unsigned int)us_validate_buffer(buffer, 7u, 0);
}

canonical_decompiled_code:
__int64 func13()
{
int v0; // ebx
int v1; // ebx
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx
unsigned __int8 v6; // al
unsigned __int8 v7; // si
int v8; // ebx
int v9; // er12
__int64 i; // rbx
unsigned __int8 v11; // al
unsigned __int8 v12; // al
unsigned __int8 v13; // dl
unsigned __int8 v14; // cl
int v16; // [rsp+2h] [rbp-26h] BYREF
__int16 v17; // [rsp+6h] [rbp-22h]
char v18; // [rsp+8h] [rbp-20h]
int v19; // [rsp+9h] [rbp-1Fh] BYREF
__int16 v20[13]; // [rsp+Dh] [rbp-1Bh] BYREF

v19 = 1432778632;
qmemcpy(v20, "D3\"", 3);
v16 = 0;
v17 = 0;
v18 = 0;
if ( us_log_level > 3 )
us_log_debug_proc("init buffer of 8 elements");
us_buffer_init(buffer, 0LL, &mem, 8LL);
v0 = func12(buffer, 7u, 0);
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( func9(buffer) )
func10(buffer, 1);
v1 = func12(buffer, 6u, 1u) & v0;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( func9(buffer) )
func10(buffer, 5);
v2 = func12(buffer, 5u, 2u) & v1;
if ( us_log_level > 3 )
us_log_debug_proc("Try read first byte");
if ( func2((__int64)buffer) )
{
v11 = func3(buffer);
if ( v11 != 1 )
{
v2 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x01, got 0x%02x", v11);
}
}
v3 = func12(buffer, 6u, 1u) & v2;
if ( us_log_level > 3 )
us_log_debug_proc("Try read second byte");
if ( func2((__int64)buffer) )
{
v12 = func3(buffer);
if ( v12 != 5 )
{
v3 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x05, got 0x%02x", v12);
}
}
v4 = func12(buffer, 7u, 0) & v3;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( func7(buffer) > 6 )
func11(buffer, (char *)&v19, 7LL);
v5 = func12(buffer, 0, 7u) & v4;
if ( us_log_level <= 3 )
{
v6 = func5(buffer, 6LL);
v7 = v20[1];
if ( v6 == LOBYTE(v20[1]) )
goto LABEL_27;
v5 = 0;
if ( us_log_level <= 0 )
goto LABEL_27;
goto LABEL_24;
}
us_log_debug_proc("Try peek 7th byte");
v6 = func5(buffer, 6LL);
v7 = v20[1];
if ( LOBYTE(v20[1]) != v6 )
{
v5 = 0;
if ( us_log_level > 0 )
{
LABEL_24:
us_log_error_proc("Expected 0x%02x, got 0x%02x", v7, v6);
v5 = 0;
goto LABEL_25;
}
}
LABEL_25:
if ( us_log_level > 3 )
us_log_debug_proc("Try skip 7 bytes");
LABEL_27:
func6((__int64)buffer, 7LL);
v8 = func12(buffer, 7u, 0) & v5;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( func7(buffer) > 6 )
func11(buffer, (char *)&v19, 7LL);
v9 = v8 & func12(buffer, 0, 7u);
if ( us_log_level > 3 )
us_log_debug_proc("Try read 7 bytes");
func4(buffer, &v16, 7LL);
for ( i = 0LL; i != 7; ++i )
{
v13 = *((_BYTE *)&v19 + i);
v14 = *((_BYTE *)&v16 + i);
if ( v13 != v14 )
{
v9 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected byte %d to be 0x%02x, got 0x%02x", (unsigned int)i, v13, v14);
}
}
return v9 & (unsigned int)func12(buffer, 7u, 0);
}

original_code:
static _Bool us_test_buffer_queue( void )
{
    _Bool r = 1;
    uint16_t i;
    uint8_t v;
    uint8_t test_7_bytes[7] = {0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22};
    uint8_t read_7_bytes[7] = {0, 0, 0, 0, 0, 0, 0};
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "init buffer of 8 elements" ); } while ( 0 );
    us_buffer_init( &buffer, 0, mem, 8 );
    r &= us_validate_buffer( &buffer, 7, 0 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 1 byte" ); } while ( 0 );
    if ( us_buffer_can_write_byte( &buffer ) )
    {
        us_buffer_write_byte( &buffer, 0x01 );
    }
    r &= us_validate_buffer( &buffer, 6, 1 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 1 byte" ); } while ( 0 );
    if ( us_buffer_can_write_byte( &buffer ) )
    {
        us_buffer_write_byte( &buffer, 0x05 );
    }
    r &= us_validate_buffer( &buffer, 5, 2 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try read first byte" ); } while ( 0 );
    if ( us_buffer_can_read_byte( &buffer ) )
    {
        v = us_buffer_read_byte( &buffer );
        if ( v != 0x01 )
        {
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected 0x01, got 0x%02x", v ); } while ( 0 );
            r = 0;
        }
    }
    r &= us_validate_buffer( &buffer, 6, 1 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try read second byte" ); } while ( 0 );
    if ( us_buffer_can_read_byte( &buffer ) )
    {
        v = us_buffer_read_byte( &buffer );
        if ( v != 0x05 )
        {
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected 0x05, got 0x%02x", v ); } while ( 0 );
            r = 0;
        }
    }
    r &= us_validate_buffer( &buffer, 7, 0 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 7 bytes" ); } while ( 0 );
    if ( us_buffer_writable_count( &buffer ) >= 7 )
    {
        us_buffer_write( &buffer, test_7_bytes, sizeof( test_7_bytes ) );
    }
    r &= us_validate_buffer( &buffer, 0, 7 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try peek 7th byte" ); } while ( 0 );
    v = us_buffer_peek( &buffer, 6 );
    if ( v != test_7_bytes[6] )
    {
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected 0x%02x, got 0x%02x", test_7_bytes[6], v ); } while ( 0 );
        r = 0;
    }
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try skip 7 bytes" ); } while ( 0 );
    us_buffer_skip( &buffer, 7 );
    r &= us_validate_buffer( &buffer, 7, 0 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 7 bytes" ); } while ( 0 );
    if ( us_buffer_writable_count( &buffer ) >= 7 )
    {
        us_buffer_write( &buffer, test_7_bytes, sizeof( test_7_bytes ) );
    }
    r &= us_validate_buffer( &buffer, 0, 7 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try read 7 bytes" ); } while ( 0 );
    us_buffer_read( &buffer, read_7_bytes, sizeof( read_7_bytes ) );
    for ( i = 0; i < sizeof( read_7_bytes ); ++i )
    {
        if ( test_7_bytes[i] != read_7_bytes[i] )
        {
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected byte %d to be 0x%02x, got 0x%02x", i, test_7_bytes[i], read_7_bytes[i] ); } while ( 0 );
            r = 0;
        }
    }
    r &= us_validate_buffer( &buffer, 7, 0 );
    return r;
}

canonical_original_code:
static _Bool us_test_buffer_queue()
{
    _Bool r = 1;
    unsigned short i;
    unsigned char v;
    unsigned char test_7_bytes[7] = {0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22};
    unsigned char read_7_bytes[7] = {0, 0, 0, 0, 0, 0, 0};
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "init buffer of 8 elements" ); } while ( 0 );
    us_buffer_init( &buffer, 0, mem, 8 );
    r &= us_validate_buffer( &buffer, 7, 0 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 1 byte" ); } while ( 0 );
    if ( us_buffer_can_write_byte( &buffer ) )
    {
        us_buffer_write_byte( &buffer, 0x01 );
    }
    r &= us_validate_buffer( &buffer, 6, 1 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 1 byte" ); } while ( 0 );
    if ( us_buffer_can_write_byte( &buffer ) )
    {
        us_buffer_write_byte( &buffer, 0x05 );
    }
    r &= us_validate_buffer( &buffer, 5, 2 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try read first byte" ); } while ( 0 );
    if ( us_buffer_can_read_byte( &buffer ) )
    {
        v = us_buffer_read_byte( &buffer );
        if ( v != 0x01 )
        {
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected 0x01, got 0x%02x", v ); } while ( 0 );
            r = 0;
        }
    }
    r &= us_validate_buffer( &buffer, 6, 1 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try read second byte" ); } while ( 0 );
    if ( us_buffer_can_read_byte( &buffer ) )
    {
        v = us_buffer_read_byte( &buffer );
        if ( v != 0x05 )
        {
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected 0x05, got 0x%02x", v ); } while ( 0 );
            r = 0;
        }
    }
    r &= us_validate_buffer( &buffer, 7, 0 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 7 bytes" ); } while ( 0 );
    if ( us_buffer_writable_count( &buffer ) >= 7 )
    {
        us_buffer_write( &buffer, test_7_bytes, sizeof( test_7_bytes ) );
    }
    r &= us_validate_buffer( &buffer, 0, 7 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try peek 7th byte" ); } while ( 0 );
    v = us_buffer_peek( &buffer, 6 );
    if ( v != test_7_bytes[6] )
    {
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected 0x%02x, got 0x%02x", test_7_bytes[6], v ); } while ( 0 );
        r = 0;
    }
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try skip 7 bytes" ); } while ( 0 );
    us_buffer_skip( &buffer, 7 );
    r &= us_validate_buffer( &buffer, 7, 0 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 7 bytes" ); } while ( 0 );
    if ( us_buffer_writable_count( &buffer ) >= 7 )
    {
        us_buffer_write( &buffer, test_7_bytes, sizeof( test_7_bytes ) );
    }
    r &= us_validate_buffer( &buffer, 0, 7 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try read 7 bytes" ); } while ( 0 );
    us_buffer_read( &buffer, read_7_bytes, sizeof( read_7_bytes ) );
    for ( i = 0; i < sizeof( read_7_bytes ); ++i )
    {
        if ( test_7_bytes[i] != read_7_bytes[i] )
        {
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected byte %d to be 0x%02x, got 0x%02x", i, test_7_bytes[i], read_7_bytes[i] ); } while ( 0 );
            r = 0;
        }
    }
    r &= us_validate_buffer( &buffer, 7, 0 );
    return r;
}

variable_types:
i
unsigned short

variable_types:
v
unsigned char


decompiled_code:
__int64 us_test_buffer()
{
__int64 v0; // r12
int v1; // er14
int v2; // ebx
int v4; // ebp
int v5; // ebp
char v6; // r15
char v7; // al
bool v8; // cf
bool v9; // zf
const char *v10; // rdi
__int64 v11; // rcx
char *v12; // rsi
int v13; // [rsp+4h] [rbp-C4h] BYREF
int v14; // [rsp+8h] [rbp-C0h] BYREF
int v15; // [rsp+Ch] [rbp-BCh] BYREF
char v16[184]; // [rsp+10h] [rbp-B8h] BYREF

v0 = us_buffer_create(us_testutil_sys_allocator, 500LL);
v1 = 100;
v2 = 1;
if ( v0 )
{
do
{
v4 = 10;
while ( (unsigned __int8)us_buffer_append_rounded_string(v0, "Rounded String")
&& (unsigned __int8)us_buffer_append_int32(v0, 305419896LL)
&& (unsigned __int8)us_buffer_append_uint64(v0, 2309737967LL, 19088743LL) )
{
if ( (_BYTE)v2 )
{
if ( --v4 )
continue;
}
goto LABEL_13;
}
if ( us_log_level > 0 )
us_log_error_proc("unable to append items");
v2 = 0;
LABEL_13:
v5 = 10;
while ( 1 )
{
v7 = us_buffer_read_rounded_string(v0, v16, 128LL);
v8 = 0;
v9 = v7 == 0;
if ( !v7 )
break;
v10 = "Rounded String";
v11 = 15LL;
v12 = v16;
do
{
if ( !v11 )
break;
v8 = (unsigned __int8)*v12 < (unsigned int)*v10;
v9 = *v12++ == *v10++;
--v11;
}
while ( v9 );
if ( (!v8 && !v9) != v8 )
{
if ( us_log_level > 0 )
us_log_error_proc("unable to validate rounded string", v12);
goto LABEL_39;
}
if ( !(unsigned __int8)us_buffer_read_int32(v0, &v13) )
{
if ( us_log_level > 0 )
us_log_error_proc("unable to read int32");
goto LABEL_39;
}
if ( v13 != 305419896 )
{
if ( us_log_level > 0 )
us_log_error_proc("unable to validate int32");
goto LABEL_39;
}
v6 = us_buffer_read_uint64(v0, &v14, &v15);
if ( v6 )
{
if ( v14 != -1985229329 || v15 != 19088743 )
{
v6 = 0;
if ( us_log_level > 0 )
us_log_error_proc("unable to validate uint64");
}
}
else if ( us_log_level > 0 )
{
us_log_error_proc("unable to read uint64");
}
LOBYTE(v2) = v6 & v2;
if ( !(_BYTE)v2 )
goto LABEL_39;
if ( !--v5 )
goto LABEL_40;
}
if ( us_log_level > 0 )
us_log_error_proc("unable to read rounded string");
LABEL_39:
(*(void (__fastcall **)(_QWORD, const char *))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"contents of test buffer:\n");
us_buffer_print(v0, us_testutil_printer_stdout);
(*(void (__fastcall **)(_QWORD, const char *))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"\n");
v2 = 0;
LABEL_40:
--v1;
}
while ( v1 );
}
else
{
v2 = 1;
if ( us_log_level > 0 )
us_log_error_proc("expected to allocate 1024 bytes from allocator for buffer but failed");
}
return v2 & (unsigned int)us_test_buffer_queue();
}

canonical_decompiled_code:
__int64 func14()
{
__int64 v0; // r12
int v1; // er14
int v2; // ebx
int v4; // ebp
int v5; // ebp
char v6; // r15
char v7; // al
bool v8; // cf
bool v9; // zf
const char *v10; // rdi
__int64 v11; // rcx
char *v12; // rsi
int v13; // [rsp+4h] [rbp-C4h] BYREF
int v14; // [rsp+8h] [rbp-C0h] BYREF
int v15; // [rsp+Ch] [rbp-BCh] BYREF
char v16[184]; // [rsp+10h] [rbp-B8h] BYREF

v0 = us_buffer_create(us_testutil_sys_allocator, 500LL);
v1 = 100;
v2 = 1;
if ( v0 )
{
do
{
v4 = 10;
while ( (unsigned __int8)us_buffer_append_rounded_string(v0, "Rounded String")
&& (unsigned __int8)us_buffer_append_int32(v0, 305419896LL)
&& (unsigned __int8)us_buffer_append_uint64(v0, 2309737967LL, 19088743LL) )
{
if ( (_BYTE)v2 )
{
if ( --v4 )
continue;
}
goto LABEL_13;
}
if ( us_log_level > 0 )
us_log_error_proc("unable to append items");
v2 = 0;
LABEL_13:
v5 = 10;
while ( 1 )
{
v7 = us_buffer_read_rounded_string(v0, v16, 128LL);
v8 = 0;
v9 = v7 == 0;
if ( !v7 )
break;
v10 = "Rounded String";
v11 = 15LL;
v12 = v16;
do
{
if ( !v11 )
break;
v8 = (unsigned __int8)*v12 < (unsigned int)*v10;
v9 = *v12++ == *v10++;
--v11;
}
while ( v9 );
if ( (!v8 && !v9) != v8 )
{
if ( us_log_level > 0 )
us_log_error_proc("unable to validate rounded string", v12);
goto LABEL_39;
}
if ( !(unsigned __int8)us_buffer_read_int32(v0, &v13) )
{
if ( us_log_level > 0 )
us_log_error_proc("unable to read int32");
goto LABEL_39;
}
if ( v13 != 305419896 )
{
if ( us_log_level > 0 )
us_log_error_proc("unable to validate int32");
goto LABEL_39;
}
v6 = us_buffer_read_uint64(v0, &v14, &v15);
if ( v6 )
{
if ( v14 != -1985229329 || v15 != 19088743 )
{
v6 = 0;
if ( us_log_level > 0 )
us_log_error_proc("unable to validate uint64");
}
}
else if ( us_log_level > 0 )
{
us_log_error_proc("unable to read uint64");
}
LOBYTE(v2) = v6 & v2;
if ( !(_BYTE)v2 )
goto LABEL_39;
if ( !--v5 )
goto LABEL_40;
}
if ( us_log_level > 0 )
us_log_error_proc("unable to read rounded string");
LABEL_39:
(*(void (__fastcall **)(_QWORD, const char *))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"contents of test buffer:\n");
us_buffer_print(v0, us_testutil_printer_stdout);
(*(void (__fastcall **)(_QWORD, const char *))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"\n");
v2 = 0;
LABEL_40:
--v1;
}
while ( v1 );
}
else
{
v2 = 1;
if ( us_log_level > 0 )
us_log_error_proc("expected to allocate 1024 bytes from allocator for buffer but failed");
}
return v2 & (unsigned int)func13();
}

original_code:
static _Bool us_test_buffer( void )
{
    _Bool r = 1;
    int repeat_count = 10;
    int big_loop = 100;
    us_buffer_t *buf = us_buffer_create( us_testutil_sys_allocator, 500 );
    if ( buf )
    {
        int i;
        int j;
        for ( j = 0; j < big_loop; ++j )
        {
            for ( i = 0; i < repeat_count; ++i )
            {
                _Bool r1 = 0;
                if ( us_buffer_append_rounded_string( buf, "Rounded String" ) )
                {
                    if ( us_buffer_append_int32( buf, 0x12345678 ) )
                    {
                        if ( us_buffer_append_uint64( buf, 0x89abcdef, 0x01234567 ) )
                        {
                            r1 = 1;
                        }
                    }
                }
                if ( !r1 )
                {
                    do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to append items" ); } while ( 0 );
                }
                r &= r1;
                if ( !r )
                    break;
            }
            for ( i = 0; i < repeat_count; ++i )
            {
                _Bool r1 = 0;
                {
                    char rs[128];
                    if ( us_buffer_read_rounded_string( buf, rs, sizeof( rs ) ) )
                    {
                        if ( strcmp( rs, "Rounded String" ) == 0 )
                        {
                            int32_t v;
                            if ( us_buffer_read_int32( buf, &v ) )
                            {
                                if ( v == 0x12345678 )
                                {
                                    uint32_t a, b;
                                    if ( us_buffer_read_uint64( buf, &a, &b ) )
                                    {
                                        if ( a == 0x89abcdef && b == 0x01234567 )
                                        {
                                            r1 = 1;
                                        }
                                        else
                                        {
                                            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to validate uint64" ); } while ( 0 );
                                        }
                                    }
                                    else
                                    {
                                        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to read uint64" ); } while ( 0 );
                                    }
                                }
                                else
                                {
                                    do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to validate int32" ); } while ( 0 );
                                }
                            }
                            else
                            {
                                do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to read int32" ); } while ( 0 );
                            }
                        }
                        else
                        {
                            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to validate rounded string" ); } while ( 0 );
                        }
                    }
                    else
                    {
                        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to read rounded string" ); } while ( 0 );
                    }
                }
                r &= r1;
                if ( !r )
                {
                    us_testutil_printer_stdout->printf( us_testutil_printer_stdout, "contents of test buffer:\n" );
                    us_buffer_print( buf, us_testutil_printer_stdout );
                    us_testutil_printer_stdout->printf( us_testutil_printer_stdout, "\n" );
                    break;
                }
            }
        }
    }
    else
    {
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "expected to allocate 1024 bytes from allocator for buffer but failed" ); } while ( 0 );
    }
    r &= us_test_buffer_queue();
    return r;
}

canonical_original_code:
static _Bool us_test_buffer()
{
    _Bool r = 1;
    int repeat_count = 10;
    int big_loop = 100;
    struct us_buffer_s *buf = us_buffer_create( us_testutil_sys_allocator, 500 );
    if ( buf )
    {
        int i;
        int j;
        for ( j = 0; j < big_loop; ++j )
        {
            for ( i = 0; i < repeat_count; ++i )
            {
                _Bool r1 = 0;
                if ( us_buffer_append_rounded_string( buf, "Rounded String" ) )
                {
                    if ( us_buffer_append_int32( buf, 0x12345678 ) )
                    {
                        if ( us_buffer_append_uint64( buf, 0x89abcdef, 0x01234567 ) )
                        {
                            r1 = 1;
                        }
                    }
                }
                if ( !r1 )
                {
                    do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to append items" ); } while ( 0 );
                }
                r &= r1;
                if ( !r )
                    break;
            }
            for ( i = 0; i < repeat_count; ++i )
            {
                _Bool r1 = 0;
                {
                    char rs[128];
                    if ( us_buffer_read_rounded_string( buf, rs, sizeof( rs ) ) )
                    {
                        if ( strcmp( rs, "Rounded String" ) == 0 )
                        {
                            int v;
                            if ( us_buffer_read_int32( buf, &v ) )
                            {
                                if ( v == 0x12345678 )
                                {
                                    unsigned int a; unsigned int b;
                                    if ( us_buffer_read_uint64( buf, &a, &b ) )
                                    {
                                        if ( a == 0x89abcdef && b == 0x01234567 )
                                        {
                                            r1 = 1;
                                        }
                                        else
                                        {
                                            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to validate uint64" ); } while ( 0 );
                                        }
                                    }
                                    else
                                    {
                                        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to read uint64" ); } while ( 0 );
                                    }
                                }
                                else
                                {
                                    do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to validate int32" ); } while ( 0 );
                                }
                            }
                            else
                            {
                                do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to read int32" ); } while ( 0 );
                            }
                        }
                        else
                        {
                            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to validate rounded string" ); } while ( 0 );
                        }
                    }
                    else
                    {
                        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "unable to read rounded string" ); } while ( 0 );
                    }
                }
                r &= r1;
                if ( !r )
                {
                    us_testutil_printer_stdout->printf( us_testutil_printer_stdout, "contents of test buffer:\n" );
                    us_buffer_print( buf, us_testutil_printer_stdout );
                    us_testutil_printer_stdout->printf( us_testutil_printer_stdout, "\n" );
                    break;
                }
            }
        }
    }
    else
    {
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "expected to allocate 1024 bytes from allocator for buffer but failed" ); } while ( 0 );
    }
    r &= us_test_buffer_queue();
    return r;
}

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

variable_types: j int

variable_types:
rs
char [128]

variable_types: v int

variable_types:
a
unsigned int

variable_types:
b
unsigned int


decompiled_code:
__int64 __fastcall us_test_buffer_main(unsigned int a1, __int64 a2)
{
unsigned int v2; // ebx

v2 = 1;
if ( (unsigned __int8)us_testutil_start(2048LL, 2048LL, 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_buffer_main.c", "May 23 2025");
v2 = (unsigned __int8)us_test_buffer() ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing us_test_buffer");
us_logger_finish();
us_testutil_finish();
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1, __int64 a2)
{
unsigned int v2; // ebx

v2 = 1;
if ( (unsigned __int8)us_testutil_start(2048LL, 2048LL, 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_buffer_main.c", "May 23 2025");
v2 = (unsigned __int8)func14() ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing us_test_buffer");
us_logger_finish();
us_testutil_finish();
}
return v2;
}

original_code:
int us_test_buffer_main( int argc, const char **argv )
{
    int r = 1;
    if ( us_testutil_start( 2048, 2048, 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_buffer_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_buffer() )
            r = 0;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing us_test_buffer" ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}

canonical_original_code:
int us_test_buffer_main(int argc, char **argv)
{
    int r = 1;
    if ( us_testutil_start( 2048, 2048, 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_buffer_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_buffer() )
            r = 0;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing us_test_buffer" ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}


decompiled_code:
__int64 __fastcall us_example_mudp_rx(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
int v5; // ebx
int v6; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-91Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-918h] BYREF
char buf[2072]; // [rsp+110h] [rbp-818h] BYREF

v4 = us_net_get_addrinfo(a1, a2, 2LL, 1LL);
if ( (unsigned __int8)us_net_get_nameinfo(v4, buf, 1023LL, &addr, 255LL) )
{
if ( us_log_level > 2 )
us_log_info_proc("multicastgroup: %s port %s", buf, (const char *)&addr);
}
else
{
perror("getnameinfo:");
}
v5 = us_net_create_multicast_rx_udp_socket(0LL, v4, a3);
if ( v5 > 0 )
{
while ( 1 )
{
addr_len = 128;
v6 = recvfrom(v5, buf, 0x800uLL, 0, &addr, &addr_len);
if ( v6 <= 0 )
break;
if ( us_log_level > 2 )
us_log_info_proc("got packet %d bytes", (unsigned int)v6);
}
perror("recvfrom:");
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
int v5; // ebx
int v6; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-91Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-918h] BYREF
char buf[2072]; // [rsp+110h] [rbp-818h] BYREF

v4 = us_net_get_addrinfo(a1, a2, 2LL, 1LL);
if ( (unsigned __int8)us_net_get_nameinfo(v4, buf, 1023LL, &addr, 255LL) )
{
if ( us_log_level > 2 )
us_log_info_proc("multicastgroup: %s port %s", buf, (const char *)&addr);
}
else
{
perror("getnameinfo:");
}
v5 = us_net_create_multicast_rx_udp_socket(0LL, v4, a3);
if ( v5 > 0 )
{
while ( 1 )
{
addr_len = 128;
v6 = recvfrom(v5, buf, 0x800uLL, 0, &addr, &addr_len);
if ( v6 <= 0 )
break;
if ( us_log_level > 2 )
us_log_info_proc("got packet %d bytes", (unsigned int)v6);
}
perror("recvfrom:");
}
return 0LL;
}

original_code:
_Bool us_example_mudp_rx (
    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, 1 );
    {
        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_rx_udp_socket ( 0, multicastgroup, interface );
    if ( fd > 0 )
    {
        while ( 1 )
        {
            struct sockaddr_storage remote_addr;
            socklen_t remote_addr_len = sizeof ( remote_addr );
            char buf[2048];
            int len;
            len = recvfrom ( fd, buf, sizeof ( buf ), 0, ( struct sockaddr * ) &remote_addr, &remote_addr_len );
            if ( len > 0 )
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "got packet %d bytes", len ); } while ( 0 );
            }
            else
            {
                perror ( "recvfrom:" );
                break;
            }
        }
    }
    return r;
}

canonical_original_code:
_Bool us_example_mudp_rx(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, 1 );
    {
        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_rx_udp_socket ( 0, multicastgroup, interface );
    if ( fd > 0 )
    {
        while ( 1 )
        {
            struct sockaddr_storage remote_addr;
            unsigned int remote_addr_len = sizeof ( remote_addr );
            char buf[2048];
            int len;
            len = recvfrom ( fd, buf, sizeof ( buf ), 0, ( struct sockaddr * ) &remote_addr, &remote_addr_len );
            if ( len > 0 )
            {
                do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "got packet %d bytes", len ); } while ( 0 );
            }
            else
            {
                perror ( "recvfrom:" );
                break;
            }
        }
    }
    return r;
}

variable_types:
interface
char *

variable_types: fd int

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: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
buf
char [2048]

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


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_246;
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_rx.c", "May 23 2025");
v3 = (unsigned __int8)us_example_mudp_rx((__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_246;
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_rx.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_rx.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_example_mudp_rx ( 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_rx.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_example_mudp_rx ( 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 **


decompiled_code:
__int64 us_test_net()
{
if ( us_log_level > 0 )
us_log_error_proc("Unimplemented");
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
if ( us_log_level > 0 )
us_log_error_proc("Unimplemented");
return 0LL;
}

original_code:
static _Bool us_test_net( void )
{
    _Bool r = 0;
    do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Unimplemented" ); } while ( 0 );
    return r;
}

canonical_original_code:
static _Bool us_test_net()
{
    _Bool r = 0;
    do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Unimplemented" ); } while ( 0 );
    return r;
}


decompiled_code:
__int64 __fastcall us_test_net_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_net_main.c", "May 23 2025");
v2 = (unsigned __int8)us_test_net() ^ 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 func1(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_net_main.c", "May 23 2025");
v2 = (unsigned __int8)func0() ^ 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_net_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_net_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_net() )
            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_net_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_net_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_net() )
            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: r int


decompiled_code:
__int64 us_test_queue()
{
int v0; // ebx
int v1; // ebx
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx
unsigned __int8 v6; // al
unsigned __int8 v7; // si
int v8; // ebx
int v9; // er12
__int64 i; // rbx
unsigned __int8 v11; // al
unsigned __int8 v12; // al
unsigned __int8 v13; // dl
unsigned __int8 v14; // cl
int v16; // [rsp+2h] [rbp-26h] BYREF
__int16 v17; // [rsp+6h] [rbp-22h]
char v18; // [rsp+8h] [rbp-20h]
int v19; // [rsp+9h] [rbp-1Fh] BYREF
__int16 v20[13]; // [rsp+Dh] [rbp-1Bh] BYREF

v19 = 1432778632;
qmemcpy(v20, "D3\"", 3);
v16 = 0;
v17 = 0;
v18 = 0;
if ( us_log_level > 3 )
us_log_debug_proc("init queue of 8 elements");
us_queue_init(&queue, &mem, 8LL);
v0 = us_validate_queue(&queue, 7u, 0);
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( us_queue_can_write_byte(&queue) )
us_queue_write_byte(&queue, 1);
v1 = us_validate_queue(&queue, 6u, 1u) & v0;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( us_queue_can_write_byte(&queue) )
us_queue_write_byte(&queue, 5);
v2 = us_validate_queue(&queue, 5u, 2u) & v1;
if ( us_log_level > 3 )
us_log_debug_proc("Try read first byte");
if ( us_queue_can_read_byte(&queue) )
{
v11 = us_queue_read_byte((__int64)&queue);
if ( v11 != 1 )
{
v2 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x01, got 0x%02x", v11);
}
}
v3 = us_validate_queue(&queue, 6u, 1u) & v2;
if ( us_log_level > 3 )
us_log_debug_proc("Try read second byte");
if ( us_queue_can_read_byte(&queue) )
{
v12 = us_queue_read_byte((__int64)&queue);
if ( v12 != 5 )
{
v3 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x05, got 0x%02x", v12);
}
}
v4 = us_validate_queue(&queue, 7u, 0) & v3;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( (int)us_queue_writable_count(&queue) > 6 )
us_queue_write(&queue, &v19, 7LL);
v5 = us_validate_queue(&queue, 0, 7u) & v4;
if ( us_log_level <= 3 )
{
v6 = us_queue_peek((__int64)&queue, 6);
v7 = v20[1];
if ( v6 == LOBYTE(v20[1]) )
goto LABEL_27;
v5 = 0;
if ( us_log_level <= 0 )
goto LABEL_27;
goto LABEL_24;
}
us_log_debug_proc("Try peek 7th byte");
v6 = us_queue_peek((__int64)&queue, 6);
v7 = v20[1];
if ( LOBYTE(v20[1]) != v6 )
{
v5 = 0;
if ( us_log_level > 0 )
{
LABEL_24:
us_log_error_proc("Expected 0x%02x, got 0x%02x", v7, v6);
v5 = 0;
goto LABEL_25;
}
}
LABEL_25:
if ( us_log_level > 3 )
us_log_debug_proc("Try skip 7 bytes");
LABEL_27:
us_queue_skip((__int64)&queue, 7);
v8 = us_validate_queue(&queue, 7u, 0) & v5;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( (int)us_queue_writable_count(&queue) > 6 )
us_queue_write(&queue, &v19, 7LL);
v9 = v8 & us_validate_queue(&queue, 0, 7u);
if ( us_log_level > 3 )
us_log_debug_proc("Try read 7 bytes");
us_queue_read(&queue, &v16, 7LL);
for ( i = 0LL; i != 7; ++i )
{
v13 = *((_BYTE *)&v19 + i);
v14 = *((_BYTE *)&v16 + i);
if ( v13 != v14 )
{
v9 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected byte %d to be 0x%02x, got 0x%02x", (unsigned int)i, v13, v14);
}
}
return v9 & (unsigned int)us_validate_queue(&queue, 7u, 0);
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // ebx
int v1; // ebx
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx
unsigned __int8 v6; // al
unsigned __int8 v7; // si
int v8; // ebx
int v9; // er12
__int64 i; // rbx
unsigned __int8 v11; // al
unsigned __int8 v12; // al
unsigned __int8 v13; // dl
unsigned __int8 v14; // cl
int v16; // [rsp+2h] [rbp-26h] BYREF
__int16 v17; // [rsp+6h] [rbp-22h]
char v18; // [rsp+8h] [rbp-20h]
int v19; // [rsp+9h] [rbp-1Fh] BYREF
__int16 v20[13]; // [rsp+Dh] [rbp-1Bh] BYREF

v19 = 1432778632;
qmemcpy(v20, "D3\"", 3);
v16 = 0;
v17 = 0;
v18 = 0;
if ( us_log_level > 3 )
us_log_debug_proc("init queue of 8 elements");
us_queue_init(&queue, &mem, 8LL);
v0 = func8(&queue, 7u, 0);
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( func6(&queue) )
func7(&queue, 1);
v1 = func8(&queue, 6u, 1u) & v0;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( func6(&queue) )
func7(&queue, 5);
v2 = func8(&queue, 5u, 2u) & v1;
if ( us_log_level > 3 )
us_log_debug_proc("Try read first byte");
if ( func1(&queue) )
{
v11 = func2((__int64)&queue);
if ( v11 != 1 )
{
v2 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x01, got 0x%02x", v11);
}
}
v3 = func8(&queue, 6u, 1u) & v2;
if ( us_log_level > 3 )
us_log_debug_proc("Try read second byte");
if ( func1(&queue) )
{
v12 = func2((__int64)&queue);
if ( v12 != 5 )
{
v3 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x05, got 0x%02x", v12);
}
}
v4 = func8(&queue, 7u, 0) & v3;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( (int)func5(&queue) > 6 )
us_queue_write(&queue, &v19, 7LL);
v5 = func8(&queue, 0, 7u) & v4;
if ( us_log_level <= 3 )
{
v6 = func3((__int64)&queue, 6);
v7 = v20[1];
if ( v6 == LOBYTE(v20[1]) )
goto LABEL_27;
v5 = 0;
if ( us_log_level <= 0 )
goto LABEL_27;
goto LABEL_24;
}
us_log_debug_proc("Try peek 7th byte");
v6 = func3((__int64)&queue, 6);
v7 = v20[1];
if ( LOBYTE(v20[1]) != v6 )
{
v5 = 0;
if ( us_log_level > 0 )
{
LABEL_24:
us_log_error_proc("Expected 0x%02x, got 0x%02x", v7, v6);
v5 = 0;
goto LABEL_25;
}
}
LABEL_25:
if ( us_log_level > 3 )
us_log_debug_proc("Try skip 7 bytes");
LABEL_27:
func4((__int64)&queue, 7);
v8 = func8(&queue, 7u, 0) & v5;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( (int)func5(&queue) > 6 )
us_queue_write(&queue, &v19, 7LL);
v9 = v8 & func8(&queue, 0, 7u);
if ( us_log_level > 3 )
us_log_debug_proc("Try read 7 bytes");
us_queue_read(&queue, &v16, 7LL);
for ( i = 0LL; i != 7; ++i )
{
v13 = *((_BYTE *)&v19 + i);
v14 = *((_BYTE *)&v16 + i);
if ( v13 != v14 )
{
v9 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected byte %d to be 0x%02x, got 0x%02x", (unsigned int)i, v13, v14);
}
}
return v9 & (unsigned int)func8(&queue, 7u, 0);
}

original_code:
static _Bool us_test_queue( void )
{
    _Bool r = 1;
    uint16_t i;
    uint8_t v;
    uint8_t test_7_bytes[7] = {0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22};
    uint8_t read_7_bytes[7] = {0, 0, 0, 0, 0, 0, 0};
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "init queue of 8 elements" ); } while ( 0 );
    us_queue_init( &queue, mem, 8 );
    r &= us_validate_queue( &queue, 7, 0 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 1 byte" ); } while ( 0 );
    if ( us_queue_can_write_byte( &queue ) )
    {
        us_queue_write_byte( &queue, 0x01 );
    }
    r &= us_validate_queue( &queue, 6, 1 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 1 byte" ); } while ( 0 );
    if ( us_queue_can_write_byte( &queue ) )
    {
        us_queue_write_byte( &queue, 0x05 );
    }
    r &= us_validate_queue( &queue, 5, 2 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try read first byte" ); } while ( 0 );
    if ( us_queue_can_read_byte( &queue ) )
    {
        v = us_queue_read_byte( &queue );
        if ( v != 0x01 )
        {
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected 0x01, got 0x%02x", v ); } while ( 0 );
            r = 0;
        }
    }
    r &= us_validate_queue( &queue, 6, 1 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try read second byte" ); } while ( 0 );
    if ( us_queue_can_read_byte( &queue ) )
    {
        v = us_queue_read_byte( &queue );
        if ( v != 0x05 )
        {
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected 0x05, got 0x%02x", v ); } while ( 0 );
            r = 0;
        }
    }
    r &= us_validate_queue( &queue, 7, 0 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 7 bytes" ); } while ( 0 );
    if ( us_queue_writable_count( &queue ) >= 7 )
    {
        us_queue_write( &queue, test_7_bytes, sizeof( test_7_bytes ) );
    }
    r &= us_validate_queue( &queue, 0, 7 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try peek 7th byte" ); } while ( 0 );
    v = us_queue_peek( &queue, 6 );
    if ( v != test_7_bytes[6] )
    {
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected 0x%02x, got 0x%02x", test_7_bytes[6], v ); } while ( 0 );
        r = 0;
    }
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try skip 7 bytes" ); } while ( 0 );
    us_queue_skip( &queue, 7 );
    r &= us_validate_queue( &queue, 7, 0 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 7 bytes" ); } while ( 0 );
    if ( us_queue_writable_count( &queue ) >= 7 )
    {
        us_queue_write( &queue, test_7_bytes, sizeof( test_7_bytes ) );
    }
    r &= us_validate_queue( &queue, 0, 7 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try read 7 bytes" ); } while ( 0 );
    us_queue_read( &queue, read_7_bytes, sizeof( read_7_bytes ) );
    for ( i = 0; i < sizeof( read_7_bytes ); ++i )
    {
        if ( test_7_bytes[i] != read_7_bytes[i] )
        {
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected byte %d to be 0x%02x, got 0x%02x", i, test_7_bytes[i], read_7_bytes[i] ); } while ( 0 );
            r = 0;
        }
    }
    r &= us_validate_queue( &queue, 7, 0 );
    return r;
}

canonical_original_code:
static _Bool us_test_queue()
{
    _Bool r = 1;
    unsigned short i;
    unsigned char v;
    unsigned char test_7_bytes[7] = {0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22};
    unsigned char read_7_bytes[7] = {0, 0, 0, 0, 0, 0, 0};
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "init queue of 8 elements" ); } while ( 0 );
    us_queue_init( &queue, mem, 8 );
    r &= us_validate_queue( &queue, 7, 0 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 1 byte" ); } while ( 0 );
    if ( us_queue_can_write_byte( &queue ) )
    {
        us_queue_write_byte( &queue, 0x01 );
    }
    r &= us_validate_queue( &queue, 6, 1 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 1 byte" ); } while ( 0 );
    if ( us_queue_can_write_byte( &queue ) )
    {
        us_queue_write_byte( &queue, 0x05 );
    }
    r &= us_validate_queue( &queue, 5, 2 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try read first byte" ); } while ( 0 );
    if ( us_queue_can_read_byte( &queue ) )
    {
        v = us_queue_read_byte( &queue );
        if ( v != 0x01 )
        {
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected 0x01, got 0x%02x", v ); } while ( 0 );
            r = 0;
        }
    }
    r &= us_validate_queue( &queue, 6, 1 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try read second byte" ); } while ( 0 );
    if ( us_queue_can_read_byte( &queue ) )
    {
        v = us_queue_read_byte( &queue );
        if ( v != 0x05 )
        {
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected 0x05, got 0x%02x", v ); } while ( 0 );
            r = 0;
        }
    }
    r &= us_validate_queue( &queue, 7, 0 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 7 bytes" ); } while ( 0 );
    if ( us_queue_writable_count( &queue ) >= 7 )
    {
        us_queue_write( &queue, test_7_bytes, sizeof( test_7_bytes ) );
    }
    r &= us_validate_queue( &queue, 0, 7 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try peek 7th byte" ); } while ( 0 );
    v = us_queue_peek( &queue, 6 );
    if ( v != test_7_bytes[6] )
    {
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected 0x%02x, got 0x%02x", test_7_bytes[6], v ); } while ( 0 );
        r = 0;
    }
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try skip 7 bytes" ); } while ( 0 );
    us_queue_skip( &queue, 7 );
    r &= us_validate_queue( &queue, 7, 0 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try write 7 bytes" ); } while ( 0 );
    if ( us_queue_writable_count( &queue ) >= 7 )
    {
        us_queue_write( &queue, test_7_bytes, sizeof( test_7_bytes ) );
    }
    r &= us_validate_queue( &queue, 0, 7 );
    do { if ( us_log_level >= ( 4 ) ) us_log_debug_proc( "Try read 7 bytes" ); } while ( 0 );
    us_queue_read( &queue, read_7_bytes, sizeof( read_7_bytes ) );
    for ( i = 0; i < sizeof( read_7_bytes ); ++i )
    {
        if ( test_7_bytes[i] != read_7_bytes[i] )
        {
            do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "Expected byte %d to be 0x%02x, got 0x%02x", i, test_7_bytes[i], read_7_bytes[i] ); } while ( 0 );
            r = 0;
        }
    }
    r &= us_validate_queue( &queue, 7, 0 );
    return r;
}


decompiled_code:
__int64 __fastcall us_test_queue_main(unsigned int a1)
{
unsigned int v1; // ebx

v1 = 1;
if ( (unsigned __int8)us_testutil_start("=%d, next_out=%d", 2048LL, a1) )
{
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_queue_main.c", "May 23 2025");
v1 = (unsigned __int8)us_test_queue() ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing us_test_buffer");
us_logger_finish();
us_testutil_finish();
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
unsigned int v1; // ebx

v1 = 1;
if ( (unsigned __int8)us_testutil_start("=%d, next_out=%d", 2048LL, a1) )
{
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_queue_main.c", "May 23 2025");
v1 = (unsigned __int8)func9() ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing us_test_buffer");
us_logger_finish();
us_testutil_finish();
}
return v1;
}

original_code:
int us_test_queue_main( int argc, const char **argv )
{
    int r = 1;
    if ( us_testutil_start( 2048, 2048, 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_queue_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_queue() )
            r = 0;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing us_test_buffer" ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}

canonical_original_code:
int us_test_queue_main(int argc, char **argv)
{
    int r = 1;
    if ( us_testutil_start( 2048, 2048, 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_queue_main.c", "Apr 24 2024" ); } while ( 0 );
        if ( us_test_queue() )
            r = 0;
        do { if ( us_log_level >= ( 3 ) ) us_log_info_proc( "Finishing us_test_buffer" ); } while ( 0 );
        us_logger_finish();
        us_testutil_finish();
    }
    return r;
}


repo: jdlourenco/gpu

decompiled_code:
__int64 __fastcall xmp_utimens(const char *a1, __time_t *a2)
{
int v2; // edx
__int64 result; // rax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF
__time_t v5; // [rsp+10h] [rbp-18h]
__time_t v6; // [rsp+18h] [rbp-10h]

v4.tv_sec = *a2;
v4.tv_usec = a2[1] / 1000;
v5 = a2[2];
v6 = a2[3] / 1000;
v2 = utimes(a1, &v4);
result = 0LL;
if ( v2 == -1 )
result = (unsigned int)-*_errno_location();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, __time_t *a2)
{
int v2; // edx
__int64 result; // rax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF
__time_t v5; // [rsp+10h] [rbp-18h]
__time_t v6; // [rsp+18h] [rbp-10h]

v4.tv_sec = *a2;
v4.tv_usec = a2[1] / 1000;
v5 = a2[2];
v6 = a2[3] / 1000;
v2 = utimes(a1, &v4);
result = 0LL;
if ( v2 == -1 )
result = (unsigned int)-*_errno_location();
return result;
}

original_code:
static int xmp_utimens(const char *path, const struct timespec ts[2])
{
  int res;
  struct timeval tv[2];
  tv[0].tv_sec = ts[0].tv_sec;
  tv[0].tv_usec = ts[0].tv_nsec / 1000;
  tv[1].tv_sec = ts[1].tv_sec;
  tv[1].tv_usec = ts[1].tv_nsec / 1000;
  res = utimes(path, tv);
  if (res == -1)
    return -(*__errno_location ());
  return 0;
}

canonical_original_code:
static int xmp_utimens(char *path, struct timespec ts[2])
{
  int res;
  struct timeval tv[2];
  tv[0].tv_sec = ts[0].tv_sec;
  tv[0].tv_usec = ts[0].tv_nsec / 1000;
  tv[1].tv_sec = ts[1].tv_sec;
  tv[1].tv_usec = ts[1].tv_nsec / 1000;
  res = utimes(path, tv);
  if (res == -1)
    return -(*__errno_location ());
  return 0;
}

variable_types:
path
char *

variable_types: struct timespec { long tv_sec; long tv_nsec; } [2]

variable_types: res int

variable_types: struct timeval { long tv_sec; long tv_usec; } [2]


decompiled_code:
__int64 __fastcall hello_write(__int64 a1, const void *a2, size_t a3, __off64_t a4, __int64 a5)
{
unsigned int v6; // ebp

v6 = pwrite64(*(_DWORD *)(a5 + 24), a2, a3, a4);
if ( v6 == -1 )
v6 = -*_errno_location();
close(*(_QWORD *)(a5 + 24));
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const void *a2, size_t a3, __off64_t a4, __int64 a5)
{
unsigned int v6; // ebp

v6 = pwrite64(*(_DWORD *)(a5 + 24), a2, a3, a4);
if ( v6 == -1 )
v6 = -*_errno_location();
close(*(_QWORD *)(a5 + 24));
return v6;
}

original_code:
static int hello_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
  int res;
  res = pwrite(fi->fh, buf, size, offset);
  if (res == -1)
    res = -(*__errno_location ());
  close(fi->fh);
  return res;
}

canonical_original_code:
static int hello_write(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *fi) {
  int res;
  res = pwrite(fi->fh, buf, size, offset);
  if (res == -1)
    res = -(*__errno_location ());
  close(fi->fh);
  return res;
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types: offset long

variable_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *


decompiled_code:
__int64 __fastcall hello_read(__int64 a1, void *a2, size_t a3, __off64_t a4, __int64 a5)
{
unsigned int v6; // ebp

v6 = pread64(*(_DWORD *)(a5 + 24), a2, a3, a4);
if ( v6 == -1 )
v6 = -*_errno_location();
close(*(_QWORD *)(a5 + 24));
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, void *a2, size_t a3, __off64_t a4, __int64 a5)
{
unsigned int v6; // ebp

v6 = pread64(*(_DWORD *)(a5 + 24), a2, a3, a4);
if ( v6 == -1 )
v6 = -*_errno_location();
close(*(_QWORD *)(a5 + 24));
return v6;
}

original_code:
static int hello_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
  int res;
  res = pread(fi->fh, buf, size, offset);
  if (res == -1)
    res = -(*__errno_location ());
  close(fi->fh);
  return res;
}

canonical_original_code:
static int hello_read(char *path, char *buf, unsigned long size, long offset, struct fuse_file_info *fi) {
  int res;
  res = pread(fi->fh, buf, size, offset);
  if (res == -1)
    res = -(*__errno_location ());
  close(fi->fh);
  return res;
}

user_defined_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; }


decompiled_code:
__int64 __fastcall hello_open(char *src, __int64 a2)
{
size_t v2; // rax
char *v3; // rbp
size_t v4; // rax
char *v5; // rax

v2 = strlen(src);
v3 = (char *)malloc(v2 + 14);
strcpy(v3, "/home/ze/back");
strcat(v3, src);
printf("FUSE: call to open %s\ncache:", src);
show_cache_entries(file_cache);
if ( (unsigned int)contains_entry(file_cache, src) )
{
puts("File in cache");
}
else
{
puts("File not in cache");
if ( (unsigned int)copy_file(v3, src) )
puts("copy to cache failed");
}
v4 = strlen(src);
v5 = (char *)malloc(v4 + 13);
strcpy(v5, "/tmp/cudaram");
strcat(v5, src);
*(_QWORD *)(a2 + 24) = open64(v3, *(_DWORD *)a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src, __int64 a2)
{
size_t v2; // rax
char *v3; // rbp
size_t v4; // rax
char *v5; // rax

v2 = strlen(src);
v3 = (char *)malloc(v2 + 14);
strcpy(v3, "/home/ze/back");
strcat(v3, src);
printf("FUSE: call to open %s\ncache:", src);
show_cache_entries(file_cache);
if ( (unsigned int)contains_entry(file_cache, src) )
{
puts("File in cache");
}
else
{
puts("File not in cache");
if ( (unsigned int)copy_file(v3, src) )
puts("copy to cache failed");
}
v4 = strlen(src);
v5 = (char *)malloc(v4 + 13);
strcpy(v5, "/tmp/cudaram");
strcat(v5, src);
*(_QWORD *)(a2 + 24) = open64(v3, *(_DWORD *)a2);
return 0LL;
}

original_code:
static int hello_open(const char *path, struct fuse_file_info *fi) {
  int fd;
  char* back_path = malloc(sizeof(char) * (strlen(backing_dir) + strlen(path) + 1));
  char* cache_path;
  strcpy(back_path,backing_dir);
  strcat(back_path,path);
  printf("FUSE: call to open %s\ncache:",path);
  show_cache_entries(file_cache);
  if(contains_entry(file_cache,(char *) path))
    printf("File in cache\n");
  else {
    printf("File not in cache\n");
    if(copy_file(back_path, (char*)path))
      printf("copy to cache failed\n");
  }
  cache_path = malloc(sizeof(char) * (strlen(cache_dir) + strlen(path) + 1));
  strcpy(cache_path,cache_dir);
  strcat(cache_path,path);
  fd = open(back_path, fi->flags);
  fi->fh = fd;
  return 0;
}

canonical_original_code:
static int hello_open(char *path, struct fuse_file_info *fi) {
  int fd;
  char *back_path = malloc(sizeof(char) * (strlen(backing_dir) + strlen(path) + 1));
  char *cache_path;
  strcpy(back_path,backing_dir);
  strcat(back_path,path);
  printf("FUSE: call to open %s\ncache:",path);
  show_cache_entries(file_cache);
  if(contains_entry(file_cache,(char *) path))
    printf("File in cache\n");
  else {
    printf("File not in cache\n");
    if(copy_file(back_path, (char *)path))
      printf("copy to cache failed\n");
  }
  cache_path = malloc(sizeof(char) * (strlen(cache_dir) + strlen(path) + 1));
  strcpy(cache_path,cache_dir);
  strcat(cache_path,path);
  fd = open(back_path, fi->flags);
  fi->fh = fd;
  return 0;
}


decompiled_code:
__int64 __fastcall xmp_chown(const char *a1, __uid_t a2, __gid_t a3)
{
int v3; // edx
__int64 result; // rax

v3 = lchown(a1, a2, a3);
result = 0LL;
if ( v3 == -1 )
result = (unsigned int)-*_errno_location();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, __uid_t a2, __gid_t a3)
{
int v3; // edx
__int64 result; // rax

v3 = lchown(a1, a2, a3);
result = 0LL;
if ( v3 == -1 )
result = (unsigned int)-*_errno_location();
return result;
}

original_code:
static int xmp_chown(const char *path, uid_t uid, gid_t gid)
{
  int res;
  res = lchown(path, uid, gid);
  if (res == -1)
    return -(*__errno_location ());
  return 0;
}

canonical_original_code:
static int xmp_chown(char *path, unsigned int uid, unsigned int gid)
{
  int res;
  res = lchown(path, uid, gid);
  if (res == -1)
    return -(*__errno_location ());
  return 0;
}

variable_types:
uid
unsigned int

variable_types:
gid
unsigned int


decompiled_code:
__int64 __fastcall xmp_chmod(const char *a1, __mode_t a2)
{
int v2; // edx
__int64 result; // rax

v2 = chmod(a1, a2);
result = 0LL;
if ( v2 == -1 )
result = (unsigned int)-*_errno_location();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __mode_t a2)
{
int v2; // edx
__int64 result; // rax

v2 = chmod(a1, a2);
result = 0LL;
if ( v2 == -1 )
result = (unsigned int)-*_errno_location();
return result;
}

original_code:
static int xmp_chmod(const char *path, mode_t mode)
{
  int res;
  res = chmod(path, mode);
  if (res == -1)
    return -(*__errno_location ());
  return 0;
}

canonical_original_code:
static int xmp_chmod(char *path, unsigned int mode)
{
  int res;
  res = chmod(path, mode);
  if (res == -1)
    return -(*__errno_location ());
  return 0;
}

variable_types:
mode
unsigned int


decompiled_code:
__int64 __fastcall xmp_mkdir(char *src, __mode_t mode)
{
size_t v2; // rax
char *v3; // rbx

v2 = strlen(src);
v3 = (char *)malloc(v2 + 14);
strcpy(v3, "/home/ze/back");
strcat(v3, src);
printf("FUSE: call to mkdir %s\n", src);
printf("FUSE: will create dir on %s\n", v3);
return (unsigned int)-(mkdir(v3, mode) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *src, __mode_t mode)
{
size_t v2; // rax
char *v3; // rbx

v2 = strlen(src);
v3 = (char *)malloc(v2 + 14);
strcpy(v3, "/home/ze/back");
strcat(v3, src);
printf("FUSE: call to mkdir %s\n", src);
printf("FUSE: will create dir on %s\n", v3);
return (unsigned int)-(mkdir(v3, mode) != 0);
}

original_code:
static int xmp_mkdir(const char *path, mode_t mode) {
  char* back_path = malloc(sizeof(char) * (strlen(backing_dir) + strlen(path) + 1));
  strcpy(back_path,backing_dir);
  strcat(back_path,path);
  printf("FUSE: call to mkdir %s\n",path);
  printf("FUSE: will create dir on %s\n",back_path);
  if(mkdir(back_path, mode))
    return -1;
  return 0;
}

canonical_original_code:
static int xmp_mkdir(char *path, unsigned int mode) {
  char *back_path = malloc(sizeof(char) * (strlen(backing_dir) + strlen(path) + 1));
  strcpy(back_path,backing_dir);
  strcat(back_path,path);
  printf("FUSE: call to mkdir %s\n",path);
  printf("FUSE: will create dir on %s\n",back_path);
  if(mkdir(back_path, mode))
    return -1;
  return 0;
}


decompiled_code:
__int64 __fastcall xmp_mknod(const char *a1, __mode_t a2, __dev_t a3)
{
int v3; // eax
int v4; // eax
unsigned int v5; // edx

v3 = a2 & 0xF000;
if ( v3 == 0x8000 )
{
v4 = open64(a1, 193, a2);
if ( v4 >= 0 )
v4 = close(v4);
}
else if ( v3 == 4096 )
{
v4 = mkfifo(a1, a2);
}
else
{
v4 = mknod(a1, a2, a3);
}
v5 = 0;
if ( v4 == -1 )
v5 = -*_errno_location();
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, __mode_t a2, __dev_t a3)
{
int v3; // eax
int v4; // eax
unsigned int v5; // edx

v3 = a2 & 0xF000;
if ( v3 == 0x8000 )
{
v4 = open64(a1, 193, a2);
if ( v4 >= 0 )
v4 = close(v4);
}
else if ( v3 == 4096 )
{
v4 = mkfifo(a1, a2);
}
else
{
v4 = mknod(a1, a2, a3);
}
v5 = 0;
if ( v4 == -1 )
v5 = -*_errno_location();
return v5;
}

original_code:
static int xmp_mknod(const char *path, mode_t mode, dev_t rdev)
{
  int res;
  if (((((mode)) & 0170000) == (0100000))) {
    res = open(path, 0100 | 0200 | 01, mode);
    if (res >= 0)
      res = close(res);
  } else if (((((mode)) & 0170000) == (0010000)))
    res = mkfifo(path, mode);
  else
    res = mknod(path, mode, rdev);
  if (res == -1)
    return -(*__errno_location ());
  return 0;
}

canonical_original_code:
static int xmp_mknod(char *path, unsigned int mode, unsigned long rdev)
{
  int res;
  if (((((mode)) & 0170000) == (0100000))) {
    res = open(path, 0100 | 0200 | 01, mode);
    if (res >= 0)
      res = close(res);
  } else if (((((mode)) & 0170000) == (0010000)))
    res = mkfifo(path, mode);
  else
    res = mknod(path, mode, rdev);
  if (res == -1)
    return -(*__errno_location ());
  return 0;
}

variable_types:
rdev
unsigned long


decompiled_code:
int __fastcall hello_getattr(char *src, struct stat64 *buf)
{
size_t v2; // rax
char *v3; // rbx
int result; // eax

printf("FUSE: call to getattr of %s\n", src);
v2 = strlen(src);
v3 = (char *)malloc(v2 + 14);
strcpy(v3, "/home/ze/back");
strcat(v3, src);
result = lstat64(v3, buf);
if ( result == -1 )
result = -*_errno_location();
return result;
}

canonical_decompiled_code:
int __fastcall func9(char *src, struct stat64 *buf)
{
size_t v2; // rax
char *v3; // rbx
int result; // eax

printf("FUSE: call to getattr of %s\n", src);
v2 = strlen(src);
v3 = (char *)malloc(v2 + 14);
strcpy(v3, "/home/ze/back");
strcat(v3, src);
result = lstat64(v3, buf);
if ( result == -1 )
result = -*_errno_location();
return result;
}

original_code:
static int hello_getattr(const char *path, struct stat *stbuf) {
  int res;
  char* back_path;
  printf("FUSE: call to getattr of %s\n",path);
  back_path = (char*) malloc(sizeof(char) * (strlen(backing_dir)+strlen(path)+1));
  strcpy(back_path,backing_dir);
  strcat(back_path,path);
  res = lstat(back_path, stbuf);
  if (res == -1)
    return -(*__errno_location ());
  return res;
}

canonical_original_code:
static int hello_getattr(char *path, struct stat *stbuf) {
  int res;
  char *back_path;
  printf("FUSE: call to getattr of %s\n",path);
  back_path = (char *) malloc(sizeof(char) * (strlen(backing_dir)+strlen(path)+1));
  strcpy(back_path,backing_dir);
  strcat(back_path,path);
  res = lstat(back_path, stbuf);
  if (res == -1)
    return -(*__errno_location ());
  return res;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
char *__fastcall extract_filename(char *src)
{
size_t v1; // rax
char *v2; // rbx
char *v3; // rax
const char *v4; // rbx
size_t v5; // rax
char *v6; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
strcpy(v2, src);
v3 = strtok(v2, "//");
do
{
v4 = v3;
v3 = strtok(0LL, "//");
}
while ( v3 );
v5 = strlen(v4);
v6 = (char *)malloc(v5 + 1);
return strcpy(v6, v4);
}

canonical_decompiled_code:
char *__fastcall func10(char *src)
{
size_t v1; // rax
char *v2; // rbx
char *v3; // rax
const char *v4; // rbx
size_t v5; // rax
char *v6; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
strcpy(v2, src);
v3 = strtok(v2, "//");
do
{
v4 = v3;
v3 = strtok(0LL, "//");
}
while ( v3 );
v5 = strlen(v4);
v6 = (char *)malloc(v5 + 1);
return strcpy(v6, v4);
}

original_code:
char* extract_filename(const char* path) {
  char* pathname = malloc(sizeof(char)*(strlen(path)+1));
  strcpy(pathname,path);
  const char* delim = "//";
  char* result;
  char* filename;
  char* aux;
  filename = strtok(pathname,delim);
  while((aux = strtok(((void *)0),delim)) != ((void *)0))
    filename = aux;
  result = malloc(sizeof(char) * strlen(filename)+1);
  strcpy(result,filename);
  return result;
}

canonical_original_code:
char *extract_filename(char *path) {
  char *pathname = malloc(sizeof(char)*(strlen(path)+1));
  strcpy(pathname,path);
  char *delim = "//";
  char *result;
  char *filename;
  char *aux;
  filename = strtok(pathname,delim);
  while((aux = strtok(((void *)0),delim)) != ((void *)0))
    filename = aux;
  result = malloc(sizeof(char) * strlen(filename)+1);
  strcpy(result,filename);
  return result;
}

variable_types:
pathname
char *

variable_types:
delim
char *

variable_types:
result
char *

variable_types:
filename
char *

variable_types:
aux
char *

return_type: char *


decompiled_code:
__int64 __fastcall xmp_truncate(char *a1, __off64_t a2)
{
char *v2; // rbp
size_t v3; // rax
char *v4; // rbx
int v5; // edx
__int64 result; // rax

v2 = extract_filename(a1);
v3 = strlen(v2);
v4 = (char *)malloc(v3 + 15);
strcpy(v4, "/home/ze/back");
*(_WORD *)&v4[strlen(v4)] = 47;
strcat(v4, v2);
printf("FUSE: call to truncate %s\n", v2);
printf("FUSE: will truncate %s to %jd bytes\n", v4, a2);
v5 = truncate64(v4, a2);
result = 0LL;
if ( v5 == -1 )
result = (unsigned int)-*_errno_location();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1, __off64_t a2)
{
char *v2; // rbp
size_t v3; // rax
char *v4; // rbx
int v5; // edx
__int64 result; // rax

v2 = func10(a1);
v3 = strlen(v2);
v4 = (char *)malloc(v3 + 15);
strcpy(v4, "/home/ze/back");
*(_WORD *)&v4[strlen(v4)] = 47;
strcat(v4, v2);
printf("FUSE: call to truncate %s\n", v2);
printf("FUSE: will truncate %s to %jd bytes\n", v4, a2);
v5 = truncate64(v4, a2);
result = 0LL;
if ( v5 == -1 )
result = (unsigned int)-*_errno_location();
return result;
}

original_code:
static int xmp_truncate(const char *path, off_t size) {
  int res;
  char* filename = extract_filename(path);
  char* back_path = malloc(sizeof(char) * (strlen(backing_dir) + 1 + strlen(filename) + 1));
  strcpy(back_path,backing_dir);
  strcat(back_path,"/");
  strcat(back_path,filename);
  printf("FUSE: call to truncate %s\n",filename);
  printf("FUSE: will truncate %s to %jd bytes\n",back_path,size);
  res = truncate(back_path, size);
  if (res == -1)
    return -(*__errno_location ());
  return 0;
}

canonical_original_code:
static int xmp_truncate(char *path, long size) {
  int res;
  char *filename = extract_filename(path);
  char *back_path = malloc(sizeof(char) * (strlen(backing_dir) + 1 + strlen(filename) + 1));
  strcpy(back_path,backing_dir);
  strcat(back_path,"/");
  strcat(back_path,filename);
  printf("FUSE: call to truncate %s\n",filename);
  printf("FUSE: will truncate %s to %jd bytes\n",back_path,size);
  res = truncate(back_path, size);
  if (res == -1)
    return -(*__errno_location ());
  return 0;
}

variable_types:
path
char *

variable_types: size long


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v4 = 0LL;
return fuse_main_real(argc, argv, &hello_oper, 360LL, &v4);
}

original_code:
int main(int argc, char *argv[]) {
  cache* file_cache = ((void *)0);
  return fuse_main_real(argc, argv, &hello_oper, sizeof(*(&hello_oper)), &file_cache);
}

canonical_original_code:
int main(int argc, char *argv[]) {
  struct cache_t *file_cache = ((void *)0);
  return fuse_main_real(argc, argv, &hello_oper, sizeof(*(&hello_oper)), &file_cache);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct cache_t { struct cache_entry_t { char *filename; struct cache_entry_t *next; } *file_cache; short cache_size; } *

user_defined_types: struct cache_t { struct cache_entry_t *file_cache; short cache_size; }