print

decompiled_code:
__int64 __fastcall print(__int64 a1, int a2, const char **a3)
{
const char *v5; // rsi
const char *v6; // rsi
double v7; // xmm0_8

switch ( a2 )
{
case 1:
if ( !s_IsKey )
print_indention();
s_IsKey = 0;
puts("[");
++s_Level;
break;
case 2:
if ( s_IsKey )
_assert_fail("!s_IsKey", "../../../examples/us_example_json.c", 0x77u, "print");
if ( s_Level )
--s_Level;
print_indention();
puts("]");
break;
case 3:
if ( !s_IsKey )
print_indention();
s_IsKey = 0;
puts("{");
++s_Level;
break;
case 4:
if ( s_IsKey )
_assert_fail("!s_IsKey", "../../../examples/us_example_json.c", 0x85u, "print");
if ( s_Level )
--s_Level;
print_indention();
puts("}");
break;
case 5:
if ( !s_IsKey )
print_indention();
v6 = *a3;
s_IsKey = 0;
printf("integer: %lld\n", v6);
break;
case 6:
if ( !s_IsKey )
print_indention();
v7 = *(double *)a3;
s_IsKey = 0;
printf("float: %f\n", v7);
break;
case 7:
if ( !s_IsKey )
print_indention();
s_IsKey = 0;
puts("null");
break;
case 8:
if ( !s_IsKey )
print_indention();
s_IsKey = 0;
puts("true");
break;
case 9:
if ( !s_IsKey )
print_indention();
s_IsKey = 0;
puts("false");
break;
case 10:
if ( !s_IsKey )
print_indention();
v5 = *a3;
s_IsKey = 0;
printf("string: '%s'\n", v5);
break;
case 11:
s_IsKey = 1;
print_indention();
printf("key = '%s', value = ", *a3);
break;
default:
_assert_fail("0", "../../../examples/us_example_json.c", 0xB5u, "print");
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, const char **a3)
{
const char *v5; // rsi
const char *v6; // rsi
double v7; // xmm0_8

switch ( a2 )
{
case 1:
if ( !s_IsKey )
func0();
s_IsKey = 0;
puts("[");
++s_Level;
break;
case 2:
if ( s_IsKey )
_assert_fail("!s_IsKey", "../../../examples/us_example_json.c", 0x77u, "print");
if ( s_Level )
--s_Level;
func0();
puts("]");
break;
case 3:
if ( !s_IsKey )
func0();
s_IsKey = 0;
puts("{");
++s_Level;
break;
case 4:
if ( s_IsKey )
_assert_fail("!s_IsKey", "../../../examples/us_example_json.c", 0x85u, "print");
if ( s_Level )
--s_Level;
func0();
puts("}");
break;
case 5:
if ( !s_IsKey )
func0();
v6 = *a3;
s_IsKey = 0;
printf("integer: %lld\n", v6);
break;
case 6:
if ( !s_IsKey )
func0();
v7 = *(double *)a3;
s_IsKey = 0;
printf("float: %f\n", v7);
break;
case 7:
if ( !s_IsKey )
func0();
s_IsKey = 0;
puts("null");
break;
case 8:
if ( !s_IsKey )
func0();
s_IsKey = 0;
puts("true");
break;
case 9:
if ( !s_IsKey )
func0();
s_IsKey = 0;
puts("false");
break;
case 10:
if ( !s_IsKey )
func0();
v5 = *a3;
s_IsKey = 0;
printf("string: '%s'\n", v5);
break;
case 11:
s_IsKey = 1;
func0();
printf("key = '%s', value = ", *a3);
break;
default:
_assert_fail("0", "../../../examples/us_example_json.c", 0xB5u, "print");
}
return 1LL;
}

original_code:
static int print ( void* ctx, int type, const us_json_value_t* value )
{
    (void)ctx;
    switch ( type )
    {
    case US_JSON_T_ARRAY_BEGIN:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "[\n" );
        ++s_Level;
        break;
    case US_JSON_T_ARRAY_END:
        ((void) sizeof ((!s_IsKey) ? 1 : 0), __extension__ ({ if (!s_IsKey) ; else __assert_fail ("!s_IsKey", "../../../examples/us_example_json.c", 119, __extension__ __PRETTY_FUNCTION__); }));
        if ( s_Level > 0 )
            --s_Level;
        print_indention();
        printf ( "]\n" );
        break;
    case US_JSON_T_OBJECT_BEGIN:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "{\n" );
        ++s_Level;
        break;
    case US_JSON_T_OBJECT_END:
        ((void) sizeof ((!s_IsKey) ? 1 : 0), __extension__ ({ if (!s_IsKey) ; else __assert_fail ("!s_IsKey", "../../../examples/us_example_json.c", 133, __extension__ __PRETTY_FUNCTION__); }));
        if ( s_Level > 0 )
            --s_Level;
        print_indention();
        printf ( "}\n" );
        break;
    case US_JSON_T_INTEGER:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "integer: ""%lld""\n", value->vu.integer_value );
        break;
    case US_JSON_T_FLOAT:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "float: %f\n", value->vu.float_value );
        break;
    case US_JSON_T_NULL:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "null\n" );
        break;
    case US_JSON_T_TRUE:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "true\n" );
        break;
    case US_JSON_T_FALSE:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "false\n" );
        break;
    case US_JSON_T_KEY:
        s_IsKey = 1;
        print_indention();
        printf ( "key = '%s', value = ", value->vu.str.value );
        break;
    case US_JSON_T_STRING:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "string: '%s'\n", value->vu.str.value );
        break;
    default:
        ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "../../../examples/us_example_json.c", 181, __extension__ __PRETTY_FUNCTION__); }));
        break;
    }
    return 1;
}

canonical_original_code:
static int print(void *ctx, int type, struct us_json_value_struct *value)
{
    (void)ctx;
    switch ( type )
    {
    case US_JSON_T_ARRAY_BEGIN:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "[\n" );
        ++s_Level;
        break;
    case US_JSON_T_ARRAY_END:
        ((void) sizeof ((!s_IsKey) ? 1 : 0), __extension__ ({ if (!s_IsKey) ; else __assert_fail ("!s_IsKey", "../../../examples/us_example_json.c", 119, __extension__ __PRETTY_FUNCTION__); }));
        if ( s_Level > 0 )
            --s_Level;
        print_indention();
        printf ( "]\n" );
        break;
    case US_JSON_T_OBJECT_BEGIN:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "{\n" );
        ++s_Level;
        break;
    case US_JSON_T_OBJECT_END:
        ((void) sizeof ((!s_IsKey) ? 1 : 0), __extension__ ({ if (!s_IsKey) ; else __assert_fail ("!s_IsKey", "../../../examples/us_example_json.c", 133, __extension__ __PRETTY_FUNCTION__); }));
        if ( s_Level > 0 )
            --s_Level;
        print_indention();
        printf ( "}\n" );
        break;
    case US_JSON_T_INTEGER:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "integer: ""%lld""\n", value->vu.integer_value );
        break;
    case US_JSON_T_FLOAT:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "float: %f\n", value->vu.float_value );
        break;
    case US_JSON_T_NULL:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "null\n" );
        break;
    case US_JSON_T_TRUE:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "true\n" );
        break;
    case US_JSON_T_FALSE:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "false\n" );
        break;
    case US_JSON_T_KEY:
        s_IsKey = 1;
        print_indention();
        printf ( "key = '%s', value = ", value->vu.str.value );
        break;
    case US_JSON_T_STRING:
        if ( !s_IsKey )
            print_indention();
        s_IsKey = 0;
        printf ( "string: '%s'\n", value->vu.str.value );
        break;
    default:
        ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "../../../examples/us_example_json.c", 181, __extension__ __PRETTY_FUNCTION__); }));
        break;
    }
    return 1;
}

variable_types:
ctx
void *

variable_types: type int

variable_types: struct us_json_value_struct { union { long long integer_value; double float_value; struct { char *value; unsigned long length; } str; } vu; } *


repo: jdkoftinoff/microsupport

decompiled_code:
__int64 us_testutil_start()
{
__int64 result; // rax
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // rax
int v5; // esi
__int64 v6; // rax
__int64 v7; // rdx

result = us_platform_init_sockets();
if ( (_BYTE)result )
{
us_testutil_sys_allocator = 0LL;
us_testutil_session_allocator = 0LL;
us_testutil_sys_allocator = us_malloc_allocator_init(&us_testutil_sys_allocator_impl);
v1 = us_simple_allocator_init(&us_testutil_session_allocator_impl, &us_testutil_session_sys_buffer, 0x4000LL);
v2 = us_testutil_sys_allocator;
us_testutil_session_allocator = v1;
v3 = v1;
v4 = us_print_file_init(&us_testutil_printer_stdout_impl, stdout);
v5 = (int)stderr;
us_testutil_printer_stdout = v4;
v6 = us_print_file_init(&us_testutil_printer_stderr_impl, stderr);
us_testutil_printer_stderr = v6;
v7 = v6;
if ( v6 && us_testutil_printer_stdout )
{
LOBYTE(v6) = v3 == 0;
LOBYTE(v5) = v2 == 0;
result = (v5 | (unsigned int)v6) ^ 1;
}
else
{
result = 0LL;
}
us_stdout = us_testutil_printer_stdout;
us_stderr = v7;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // rax
int v5; // esi
__int64 v6; // rax
__int64 v7; // rdx

result = us_platform_init_sockets();
if ( (_BYTE)result )
{
us_testutil_sys_allocator = 0LL;
us_testutil_session_allocator = 0LL;
us_testutil_sys_allocator = us_malloc_allocator_init(&us_testutil_sys_allocator_impl);
v1 = us_simple_allocator_init(&us_testutil_session_allocator_impl, &us_testutil_session_sys_buffer, 0x4000LL);
v2 = us_testutil_sys_allocator;
us_testutil_session_allocator = v1;
v3 = v1;
v4 = us_print_file_init(&us_testutil_printer_stdout_impl, stdout);
v5 = (int)stderr;
us_testutil_printer_stdout = v4;
v6 = us_print_file_init(&us_testutil_printer_stderr_impl, stderr);
us_testutil_printer_stderr = v6;
v7 = v6;
if ( v6 && us_testutil_printer_stdout )
{
LOBYTE(v6) = v3 == 0;
LOBYTE(v5) = v2 == 0;
result = (v5 | (unsigned int)v6) ^ 1;
}
else
{
result = 0LL;
}
us_stdout = us_testutil_printer_stdout;
us_stderr = v7;
}
return result;
}

original_code:
_Bool us_testutil_start( int32_t US_UNUSED_sys_allocator_size __attribute__( ( unused ) ), int32_t session_allocator_size, int argc, const char **argv )
{
    _Bool r = 1;
    (void)argc;
    (void)argv;
    r = us_platform_init_sockets();
    if ( !r )
    {
        return r;
    }
    us_testutil_sys_allocator = 0;
    us_testutil_session_allocator = 0;
    us_testutil_sys_allocator = us_malloc_allocator_init( &us_testutil_sys_allocator_impl );
    (void)session_allocator_size;
    us_testutil_session_allocator
        = us_simple_allocator_init( &us_testutil_session_allocator_impl,
                                    &us_testutil_session_sys_buffer,
                                    ( int32_t )( ( 4096 ) * sizeof( int32_t ) ) );
    if ( !us_testutil_sys_allocator || !us_testutil_session_allocator )
    {
        r = 0;
    }
    us_testutil_printer_stdout = us_print_file_init( &us_testutil_printer_stdout_impl, stdout );
    us_testutil_printer_stderr = us_print_file_init( &us_testutil_printer_stderr_impl, stderr );
    if ( !us_testutil_printer_stdout || !us_testutil_printer_stderr )
    {
        r = 0;
    }
    us_stdout = us_testutil_printer_stdout;
    us_stderr = us_testutil_printer_stderr;
    return r;
}

canonical_original_code:
_Bool us_testutil_start(int US_UNUSED_sys_allocator_size, int session_allocator_size, int argc, char **argv)
{
    _Bool r = 1;
    (void)argc;
    (void)argv;
    r = us_platform_init_sockets();
    if ( !r )
    {
        return r;
    }
    us_testutil_sys_allocator = 0;
    us_testutil_session_allocator = 0;
    us_testutil_sys_allocator = us_malloc_allocator_init( &us_testutil_sys_allocator_impl );
    (void)session_allocator_size;
    us_testutil_session_allocator
        = us_simple_allocator_init( &us_testutil_session_allocator_impl,
                                    &us_testutil_session_sys_buffer,
                                    ( int )( ( 4096 ) * sizeof( int ) ) );
    if ( !us_testutil_sys_allocator || !us_testutil_session_allocator )
    {
        r = 0;
    }
    us_testutil_printer_stdout = us_print_file_init( &us_testutil_printer_stdout_impl, stdout );
    us_testutil_printer_stderr = us_print_file_init( &us_testutil_printer_stderr_impl, stderr );
    if ( !us_testutil_printer_stdout || !us_testutil_printer_stderr )
    {
        r = 0;
    }
    us_stdout = us_testutil_printer_stdout;
    us_stderr = us_testutil_printer_stderr;
    return r;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 us_testutil_finish()
{
__int64 result; // rax

result = us_testutil_sys_allocator;
if ( !us_testutil_sys_allocator )
{
if ( !us_testutil_session_allocator )
return result;
return (*(__int64 (**)(void))us_testutil_session_allocator)();
}
result = (*(__int64 (__fastcall **)(__int64))us_testutil_sys_allocator)(us_testutil_sys_allocator);
if ( us_testutil_session_allocator )
return (*(__int64 (**)(void))us_testutil_session_allocator)();
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

result = us_testutil_sys_allocator;
if ( !us_testutil_sys_allocator )
{
if ( !us_testutil_session_allocator )
return result;
return (*(__int64 (**)(void))us_testutil_session_allocator)();
}
result = (*(__int64 (__fastcall **)(__int64))us_testutil_sys_allocator)(us_testutil_sys_allocator);
if ( us_testutil_session_allocator )
return (*(__int64 (**)(void))us_testutil_session_allocator)();
return result;
}

original_code:
void us_testutil_finish( void )
{
    if ( us_testutil_sys_allocator )
    {
        us_testutil_sys_allocator->destroy( us_testutil_sys_allocator );
    }
    if ( us_testutil_session_allocator )
    {
        us_testutil_session_allocator->destroy( us_testutil_session_allocator );
    }
}

canonical_original_code:
void us_testutil_finish()
{
    if ( us_testutil_sys_allocator )
    {
        us_testutil_sys_allocator->destroy( us_testutil_sys_allocator );
    }
    if ( us_testutil_session_allocator )
    {
        us_testutil_session_allocator->destroy( us_testutil_session_allocator );
    }
}

return_type: void


decompiled_code:
void us_log_null()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void us_log_null( const char *fmt, ... )
{
    (void)fmt;
}

canonical_original_code:
void us_log_null(char *fmt, ...)
{
    (void)fmt;
}

variable_types:
fmt
char *


decompiled_code:
void us_logger_null_finish()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void us_logger_null_finish( void )
{
}

canonical_original_code:
void us_logger_null_finish()
{
}


decompiled_code:
void us_printraw_destroy()
{
;
}

original_code:
void us_printraw_destroy( us_print_t *self )
{
    (void)self;
}

canonical_original_code:
void us_printraw_destroy(struct us_print_s *self)
{
    (void)self;
}

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


decompiled_code:
__int64 us_printraw_printf(__int64 a1, const char *a2, ...)
{
__int64 v3; // rdi
int v4; // ebp
int v6; // eax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
if ( !a1 )
return 0LL;
v3 = *(int *)(a1 + 36);
v4 = *(_DWORD *)(a1 + 32) - v3;
if ( v4 <= 0 )
return 0LL;
v6 = vsnprintf((char *)(*(_QWORD *)(a1 + 24) + v3), v4, a2, arg);
if ( v4 <= v6 )
return 0LL;
*(_DWORD *)(a1 + 36) += v6;
return 1LL;
}

canonical_decompiled_code:
__int64 func4(__int64 a1, const char *a2, ...)
{
__int64 v3; // rdi
int v4; // ebp
int v6; // eax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
if ( !a1 )
return 0LL;
v3 = *(int *)(a1 + 36);
v4 = *(_DWORD *)(a1 + 32) - v3;
if ( v4 <= 0 )
return 0LL;
v6 = vsnprintf((char *)(*(_QWORD *)(a1 + 24) + v3), v4, a2, arg);
if ( v4 <= v6 )
return 0LL;
*(_DWORD *)(a1 + 36) += v6;
return 1LL;
}

original_code:
_Bool us_printraw_printf( us_print_t *self_, const char *fmt, ... )
{
    _Bool r = 0;
    va_list ap;
    us_printraw_t *self = (us_printraw_t *)self_;
    __builtin_va_start(ap,fmt);
    if ( self )
    {
        char *cur_ptr = self->m_buffer + self->m_cur_length;
        int max_len = self->m_max_length - self->m_cur_length;
        if ( max_len > 0 )
        {
            int result = vsnprintf( cur_ptr, max_len, fmt, ap );
            if ( result < max_len )
            {
                self->m_cur_length += result;
                r = 1;
            }
        }
    }
    __builtin_va_end(ap);
    return r;
}

canonical_original_code:
_Bool us_printraw_printf(struct us_print_s *self_, char *fmt, ...)
{
    _Bool r = 0;
    __builtin_va_list ap;
    struct us_printraw_s *self = (us_printraw_t *)self_;
    __builtin_va_start(ap,fmt);
    if ( self )
    {
        char *cur_ptr = self->m_buffer + self->m_cur_length;
        int max_len = self->m_max_length - self->m_cur_length;
        if ( max_len > 0 )
        {
            int result = vsnprintf( cur_ptr, max_len, fmt, ap );
            if ( result < max_len )
            {
                self->m_cur_length += result;
                r = 1;
            }
        }
    }
    __builtin_va_end(ap);
    return r;
}

variable_types: struct us_printraw_s { 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); } m_base; char *m_buffer; int m_max_length; int m_cur_length; } *

variable_types: result int

user_defined_types: struct us_printraw_s { struct us_print_s m_base; char *m_buffer; int m_max_length; int m_cur_length; }


decompiled_code:
__int64 __fastcall us_printraw_vprintf(__int64 a1, const char *a2, void *a3)
{
__int64 v4; // rdi
int v5; // ebp
int v7; // eax

if ( !a1 )
return 0LL;
v4 = *(int *)(a1 + 36);
v5 = *(_DWORD *)(a1 + 32) - v4;
if ( v5 <= 0 )
return 0LL;
v7 = vsnprintf((char *)(*(_QWORD *)(a1 + 24) + v4), v5, a2, a3);
if ( v5 <= v7 )
return 0LL;
*(_DWORD *)(a1 + 36) += v7;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2, void *a3)
{
__int64 v4; // rdi
int v5; // ebp
int v7; // eax

if ( !a1 )
return 0LL;
v4 = *(int *)(a1 + 36);
v5 = *(_DWORD *)(a1 + 32) - v4;
if ( v5 <= 0 )
return 0LL;
v7 = vsnprintf((char *)(*(_QWORD *)(a1 + 24) + v4), v5, a2, a3);
if ( v5 <= v7 )
return 0LL;
*(_DWORD *)(a1 + 36) += v7;
return 1LL;
}

original_code:
_Bool us_printraw_vprintf( us_print_t *self_, const char *fmt, va_list ap )
{
    _Bool r = 0;
    us_printraw_t *self = (us_printraw_t *)self_;
    if ( self )
    {
        char *cur_ptr = self->m_buffer + self->m_cur_length;
        int max_len = self->m_max_length - self->m_cur_length;
        if ( max_len > 0 )
        {
            int result = vsnprintf( cur_ptr, max_len, fmt, ap );
            if ( result < max_len )
            {
                self->m_cur_length += result;
                r = 1;
            }
        }
    }
    return r;
}

canonical_original_code:
_Bool us_printraw_vprintf(struct us_print_s *self_, char *fmt, __builtin_va_list ap)
{
    _Bool r = 0;
    struct us_printraw_s *self = (us_printraw_t *)self_;
    if ( self )
    {
        char *cur_ptr = self->m_buffer + self->m_cur_length;
        int max_len = self->m_max_length - self->m_cur_length;
        if ( max_len > 0 )
        {
            int result = vsnprintf( cur_ptr, max_len, fmt, ap );
            if ( result < max_len )
            {
                self->m_cur_length += result;
                r = 1;
            }
        }
    }
    return r;
}

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


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

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

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

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

return_type: unsigned long

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


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

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

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

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

variable_types:
offset
unsigned long

return_type: unsigned char

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


decompiled_code:
__int64 us_test_json()
{
__int64 v0; // rbp
void (__fastcall **v1)(_QWORD); // r12
const char *v2; // rdx
__int64 v3; // rax
_QWORD *v4; // rbp
unsigned int v5; // er13
__int64 v6; // rbx
__int64 v7; // r14
char *v8; // rbx
__int64 v9; // r14
int v10; // er13
int v11; // eax
int v12; // er13
__int64 i; // rax
int v14; // eax
__int64 v15; // r12
__int64 v16; // rbx
unsigned __int8 v17; // al
__int64 v18; // rax
__int64 v20[2]; // [rsp+0h] [rbp-C8h] BYREF
__int128 v21; // [rsp+10h] [rbp-B8h]
_QWORD v22[2]; // [rsp+20h] [rbp-A8h] BYREF
__int128 v23; // [rsp+30h] [rbp-98h]
_QWORD v24[2]; // [rsp+40h] [rbp-88h] BYREF
__int128 v25; // [rsp+50h] [rbp-78h]
__int64 v26[5]; // [rsp+60h] [rbp-68h] BYREF
int v27; // [rsp+88h] [rbp-40h]
char v28; // [rsp+8Ch] [rbp-3Ch] BYREF

v0 = us_testutil_sys_allocator;
v1 = (void (__fastcall **)(_QWORD))us_json_create(us_testutil_sys_allocator);
v3 = us_buffer_create(v0, "hing %s", v2);
if ( !v3 )
us_test_json_cold();
v4 = (_QWORD *)v3;
v5 = 0;
if ( v1 )
{
v22[1] = 0LL;
v22[0] = 0x6E6F6E726556LL;
v24[0] = 0x6164616E6143LL;
v26[0] = 0x300000001LL;
v26[1] = 0xA00000006LL;
v26[2] = 0xE0000000FLL;
v24[1] = 0LL;
v26[3] = 0x40000000BLL;
v20[0] = 1717986634LL;
v20[1] = 0LL;
v26[4] = 0x100000002LL;
v27 = 0;
v21 = 0LL;
v23 = 0LL;
v25 = 0LL;
v6 = us_json_append_string_ptr(v1, "name", v20);
if ( us_json_append_int32_ptr(v1, "hitpoints", &hitpoints_0) )
LOBYTE(v5) = v6 != 0;
v7 = us_json_append_object(v1, "address");
if ( !us_json_append_string_ptr(v7, "city", v22) )
v5 = 0;
if ( !us_json_append_string_ptr(v7, "country", v24) )
v5 = 0;
v8 = (char *)v26;
v9 = us_json_append_object(v1, "histogram");
us_json_set_array_constprop_0(v9);
while ( us_json_append_int32_ptr(v9, 0LL, v8) )
{
v8 += 4;
if ( v8 == &v28 )
goto LABEL_12;
}
v5 = 0;
LABEL_12:
v10 = us_json_flatten_to_buffer(v1, v4) & v5;
v11 = us_buffer_append_string(v4, ", \n");
strcpy((char *)v20, "John");
v12 = v11 & v10;
strcpy((char *)v22, "Berkeley");
hitpoints_0 = 999;
strcpy((char *)v24, "United States");
for ( i = 0LL; i != 11; ++i )
*((_DWORD *)v26 + i) = i * i;
v5 = us_json_flatten_to_buffer(v1, v4) & v12;
(*v1)(v1);
}
v14 = us_buffer_readable_count(v4);
if ( v14 > 0 )
{
v15 = (unsigned int)(v14 - 1);
v16 = 0LL;
do
{
v17 = us_buffer_peek(v4, v16);
fputc(v17, stdout);
v18 = v16++;
}
while ( v18 != v15 );
}
fputc(10, stdout);
return v5;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbp
void (__fastcall **v1)(_QWORD); // r12
const char *v2; // rdx
__int64 v3; // rax
_QWORD *v4; // rbp
unsigned int v5; // er13
__int64 v6; // rbx
__int64 v7; // r14
char *v8; // rbx
__int64 v9; // r14
int v10; // er13
int v11; // eax
int v12; // er13
__int64 i; // rax
int v14; // eax
__int64 v15; // r12
__int64 v16; // rbx
unsigned __int8 v17; // al
__int64 v18; // rax
__int64 v20[2]; // [rsp+0h] [rbp-C8h] BYREF
__int128 v21; // [rsp+10h] [rbp-B8h]
_QWORD v22[2]; // [rsp+20h] [rbp-A8h] BYREF
__int128 v23; // [rsp+30h] [rbp-98h]
_QWORD v24[2]; // [rsp+40h] [rbp-88h] BYREF
__int128 v25; // [rsp+50h] [rbp-78h]
__int64 v26[5]; // [rsp+60h] [rbp-68h] BYREF
int v27; // [rsp+88h] [rbp-40h]
char v28; // [rsp+8Ch] [rbp-3Ch] BYREF

v0 = us_testutil_sys_allocator;
v1 = (void (__fastcall **)(_QWORD))us_json_create(us_testutil_sys_allocator);
v3 = us_buffer_create(v0, "hing %s", v2);
if ( !v3 )
func5();
v4 = (_QWORD *)v3;
v5 = 0;
if ( v1 )
{
v22[1] = 0LL;
v22[0] = 0x6E6F6E726556LL;
v24[0] = 0x6164616E6143LL;
v26[0] = 0x300000001LL;
v26[1] = 0xA00000006LL;
v26[2] = 0xE0000000FLL;
v24[1] = 0LL;
v26[3] = 0x40000000BLL;
v20[0] = 1717986634LL;
v20[1] = 0LL;
v26[4] = 0x100000002LL;
v27 = 0;
v21 = 0LL;
v23 = 0LL;
v25 = 0LL;
v6 = us_json_append_string_ptr(v1, "name", v20);
if ( us_json_append_int32_ptr(v1, "hitpoints", &hitpoints_0) )
LOBYTE(v5) = v6 != 0;
v7 = us_json_append_object(v1, "address");
if ( !us_json_append_string_ptr(v7, "city", v22) )
v5 = 0;
if ( !us_json_append_string_ptr(v7, "country", v24) )
v5 = 0;
v8 = (char *)v26;
v9 = us_json_append_object(v1, "histogram");
func2(v9);
while ( us_json_append_int32_ptr(v9, 0LL, v8) )
{
v8 += 4;
if ( v8 == &v28 )
goto LABEL_12;
}
v5 = 0;
LABEL_12:
v10 = us_json_flatten_to_buffer(v1, v4) & v5;
v11 = us_buffer_append_string(v4, ", \n");
strcpy((char *)v20, "John");
v12 = v11 & v10;
strcpy((char *)v22, "Berkeley");
hitpoints_0 = 999;
strcpy((char *)v24, "United States");
for ( i = 0LL; i != 11; ++i )
*((_DWORD *)v26 + i) = i * i;
v5 = us_json_flatten_to_buffer(v1, v4) & v12;
(*v1)(v1);
}
v14 = func0(v4);
if ( v14 > 0 )
{
v15 = (unsigned int)(v14 - 1);
v16 = 0LL;
do
{
v17 = func1(v4, v16);
fputc(v17, stdout);
v18 = v16++;
}
while ( v18 != v15 );
}
fputc(10, stdout);
return v5;
}

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 v3; // er12

if ( !(unsigned __int8)us_testutil_start(4096LL, 4096LL, a1, a2) )
return 1LL;
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");
v3 = (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 v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, const char **a2)
{
unsigned int v3; // er12

if ( !(unsigned __int8)us_testutil_start(4096LL, 4096LL, a1, a2) )
return 1LL;
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");
v3 = (unsigned __int8)func3() ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing %s", *a2);
us_logger_finish();
us_testutil_finish();
return v3;
}

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

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 v3; // er12

if ( !(unsigned __int8)us_testutil_start(2048LL, 2048LL, a1, a2) )
return 1LL;
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");
v3 = (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 v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2)
{
unsigned int v3; // er12

if ( !(unsigned __int8)us_testutil_start(2048LL, 2048LL, a1, a2) )
return 1LL;
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");
v3 = (unsigned __int8)func0() ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing us_test_buffer");
us_logger_finish();
us_testutil_finish();
return v3;
}

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

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 us_test_buffer_queue()
{
int v0; // ebx
int v1; // ebx
const char *v2; // rdi
int v3; // ebx
__int64 v4; // rdx
__int64 v5; // rcx
const char *v6; // rdi
int v7; // ebx
__int64 v8; // rdx
__int64 v9; // rcx
int v10; // ebx
int v11; // ebx
unsigned __int8 v12; // al
__int64 v13; // rsi
int v14; // eax
int v15; // ebx
__int64 v16; // rdx
int v17; // ebp
__int64 v18; // rbx
__int64 v19; // rdx
__int64 v20; // rcx
int v22; // ecx
unsigned __int8 v23; // al
unsigned __int8 v24; // al
int v25; // [rsp+2h] [rbp-26h] BYREF
char v26[34]; // [rsp+6h] [rbp-22h] BYREF

v25 = 1432778632;
strcpy(v26, "D3\"");
*(_WORD *)&v26[7] = 0;
v26[9] = 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_constprop_0(7LL, 0);
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( us_buffer_can_write_byte_constprop_0() )
us_buffer_write_byte_constprop_0(1);
v1 = us_validate_buffer_constprop_0(6LL, 1u) & v0;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( us_buffer_can_write_byte_constprop_0() )
us_buffer_write_byte_constprop_0(5);
v2 = (_BYTE *)(us_buffer_write_byte_constprop_0 + 5);
v3 = us_validate_buffer_constprop_0(5LL, 2u) & v1;
if ( us_log_level > 3 )
{
v2 = "Try read first byte";
us_log_debug_proc("Try read first byte");
}
if ( us_buffer_can_read_byte_constprop_0() )
{
v24 = us_buffer_read_byte_constprop_0(v2, 2LL, v4, v5);
if ( v24 != 1 )
{
v3 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x01, got 0x%02x", v24);
}
}
v6 = (_BYTE *)(us_buffer_write_byte_constprop_0 + 6);
v7 = us_validate_buffer_constprop_0(6LL, 1u) & v3;
if ( us_log_level > 3 )
{
v6 = "Try read second byte";
us_log_debug_proc("Try read second byte");
}
if ( us_buffer_can_read_byte_constprop_0() )
{
v23 = us_buffer_read_byte_constprop_0(v6, 1LL, v8, v9);
if ( v23 != 5 )
{
v7 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x05, got 0x%02x", v23);
}
}
v10 = us_validate_buffer_constprop_0(7LL, 0) & v7;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( us_buffer_writable_count_constprop_0() > 6 )
us_buffer_write_constprop_0((char *)&v25);
v11 = us_validate_buffer_constprop_0(0LL, 7u) & v10;
if ( us_log_level <= 3 )
{
v12 = us_buffer_peek_constprop_0();
v13 = (unsigned __int8)v26[2];
if ( v26[2] == v12 )
goto LABEL_27;
v11 = 0;
if ( v22 <= 0 )
goto LABEL_27;
goto LABEL_24;
}
us_log_debug_proc("Try peek 7th byte");
v12 = us_buffer_peek_constprop_0();
v13 = (unsigned __int8)v26[2];
if ( v26[2] != v12 )
{
v11 = 0;
if ( us_log_level <= 0 )
goto LABEL_27;
LABEL_24:
v11 = 0;
us_log_error_proc("Expected 0x%02x, got 0x%02x", v13, v12);
v14 = us_log_level;
goto LABEL_25;
}
v14 = us_log_level;
LABEL_25:
if ( v14 > 3 )
us_log_debug_proc("Try skip 7 bytes");
LABEL_27:
us_buffer_skip_constprop_0();
v15 = us_validate_buffer_constprop_0(7LL, 0) & v11;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( us_buffer_writable_count_constprop_0() > 6 )
us_buffer_write_constprop_0((char *)&v25);
v17 = v15 & us_validate_buffer_constprop_0(0LL, 7u);
if ( us_log_level > 3 )
us_log_debug_proc("Try read 7 bytes");
v18 = 0LL;
us_buffer_read_constprop_0((__int64)&v26[3], 7LL, v16);
do
{
v19 = *((unsigned __int8 *)&v25 + v18);
v20 = (unsigned __int8)v26[v18 + 3];
if ( (_BYTE)v19 != (_BYTE)v20 )
{
v17 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected byte %d to be 0x%02x, got 0x%02x", (unsigned int)v18, v19, v20);
}
++v18;
}
while ( v18 != 7 );
return v17 & (unsigned int)us_validate_buffer_constprop_0(7LL, 0);
}

canonical_decompiled_code:
__int64 func13()
{
int v0; // ebx
int v1; // ebx
const char *v2; // rdi
int v3; // ebx
__int64 v4; // rdx
__int64 v5; // rcx
const char *v6; // rdi
int v7; // ebx
__int64 v8; // rdx
__int64 v9; // rcx
int v10; // ebx
int v11; // ebx
unsigned __int8 v12; // al
__int64 v13; // rsi
int v14; // eax
int v15; // ebx
__int64 v16; // rdx
int v17; // ebp
__int64 v18; // rbx
__int64 v19; // rdx
__int64 v20; // rcx
int v22; // ecx
unsigned __int8 v23; // al
unsigned __int8 v24; // al
int v25; // [rsp+2h] [rbp-26h] BYREF
char v26[34]; // [rsp+6h] [rbp-22h] BYREF

v25 = 1432778632;
strcpy(v26, "D3\"");
*(_WORD *)&v26[7] = 0;
v26[9] = 0;
if ( us_log_level > 3 )
us_log_debug_proc("init buffer of 8 elements");
us_buffer_init(&buffer, 0LL, &mem, 8LL);
v0 = func12(7LL, 0);
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( func2() )
func0(1);
v1 = func12(6LL, 1u) & v0;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( func2() )
func0(5);
v2 = (_BYTE *)(us_buffer_write_byte_constprop_0 + 5);
v3 = func12(5LL, 2u) & v1;
if ( us_log_level > 3 )
{
v2 = "Try read first byte";
us_log_debug_proc("Try read first byte");
}
if ( func9() )
{
v24 = func7(v2, 2LL, v4, v5);
if ( v24 != 1 )
{
v3 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x01, got 0x%02x", v24);
}
}
v6 = (_BYTE *)(us_buffer_write_byte_constprop_0 + 6);
v7 = func12(6LL, 1u) & v3;
if ( us_log_level > 3 )
{
v6 = "Try read second byte";
us_log_debug_proc("Try read second byte");
}
if ( func9() )
{
v23 = func7(v6, 1LL, v8, v9);
if ( v23 != 5 )
{
v7 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x05, got 0x%02x", v23);
}
}
v10 = func12(7LL, 0) & v7;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( func3() > 6 )
func1((char *)&v25);
v11 = func12(0LL, 7u) & v10;
if ( us_log_level <= 3 )
{
v12 = func6();
v13 = (unsigned __int8)v26[2];
if ( v26[2] == v12 )
goto LABEL_27;
v11 = 0;
if ( v22 <= 0 )
goto LABEL_27;
goto LABEL_24;
}
us_log_debug_proc("Try peek 7th byte");
v12 = func6();
v13 = (unsigned __int8)v26[2];
if ( v26[2] != v12 )
{
v11 = 0;
if ( us_log_level <= 0 )
goto LABEL_27;
LABEL_24:
v11 = 0;
us_log_error_proc("Expected 0x%02x, got 0x%02x", v13, v12);
v14 = us_log_level;
goto LABEL_25;
}
v14 = us_log_level;
LABEL_25:
if ( v14 > 3 )
us_log_debug_proc("Try skip 7 bytes");
LABEL_27:
func5();
v15 = func12(7LL, 0) & v11;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( func3() > 6 )
func1((char *)&v25);
v17 = v15 & func12(0LL, 7u);
if ( us_log_level > 3 )
us_log_debug_proc("Try read 7 bytes");
v18 = 0LL;
func8((__int64)&v26[3], 7LL, v16);
do
{
v19 = *((unsigned __int8 *)&v25 + v18);
v20 = (unsigned __int8)v26[v18 + 3];
if ( (_BYTE)v19 != (_BYTE)v20 )
{
v17 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected byte %d to be 0x%02x, got 0x%02x", (unsigned int)v18, v19, v20);
}
++v18;
}
while ( v18 != 7 );
return v17 & (unsigned int)func12(7LL, 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; // rax
__int64 v1; // r12
int v2; // er14
int v3; // ebp
int v4; // ebx
int v5; // ebx
int v7; // [rsp+4h] [rbp-B4h] BYREF
int v8; // [rsp+8h] [rbp-B0h] BYREF
int v9; // [rsp+Ch] [rbp-ACh] BYREF
__int64 v10; // [rsp+10h] [rbp-A8h] BYREF
int v11; // [rsp+18h] [rbp-A0h]
__int16 v12; // [rsp+1Ch] [rbp-9Ch]
char v13; // [rsp+1Eh] [rbp-9Ah]

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

canonical_decompiled_code:
__int64 func14()
{
__int64 v0; // rax
__int64 v1; // r12
int v2; // er14
int v3; // ebp
int v4; // ebx
int v5; // ebx
int v7; // [rsp+4h] [rbp-B4h] BYREF
int v8; // [rsp+8h] [rbp-B0h] BYREF
int v9; // [rsp+Ch] [rbp-ACh] BYREF
__int64 v10; // [rsp+10h] [rbp-A8h] BYREF
int v11; // [rsp+18h] [rbp-A0h]
__int16 v12; // [rsp+1Ch] [rbp-9Ch]
char v13; // [rsp+1Eh] [rbp-9Ah]

v0 = us_buffer_create(us_testutil_sys_allocator, 500LL);
if ( v0 )
{
v1 = v0;
v2 = 100;
v3 = 1;
do
{
v4 = 10;
while ( (unsigned __int8)us_buffer_append_rounded_string(v1, "Rounded String")
&& (unsigned __int8)us_buffer_append_int32(v1, 305419896LL)
&& (unsigned __int8)us_buffer_append_uint64(v1, 2309737967LL, 19088743LL) )
{
if ( !(_BYTE)v3 )
goto LABEL_7;
if ( !--v4 )
goto LABEL_8;
}
if ( us_log_level > 0 )
us_log_error_proc("unable to append items");
LABEL_7:
v3 = 0;
LABEL_8:
v5 = 10;
while ( (unsigned __int8)us_buffer_read_rounded_string(v1, &v10, 128LL) )
{
if ( v10 != 0x206465646E756F52LL || v11 != 1769108563 || v12 != 26478 || v13 )
{
if ( us_log_level > 0 )
us_log_error_proc("unable to validate rounded string");
goto LABEL_13;
}
if ( !(unsigned __int8)us_buffer_read_int32(v1, &v7) )
{
if ( us_log_level > 0 )
us_log_error_proc("unable to read int32");
goto LABEL_13;
}
if ( v7 != 305419896 )
{
if ( us_log_level > 0 )
us_log_error_proc("unable to validate int32");
goto LABEL_13;
}
if ( !(unsigned __int8)us_buffer_read_uint64(v1, &v8, &v9) )
{
if ( us_log_level > 0 )
us_log_error_proc("unable to read uint64");
goto LABEL_13;
}
if ( v8 != -1985229329 || v9 != 19088743 )
{
if ( us_log_level > 0 )
us_log_error_proc("unable to validate uint64");
goto LABEL_13;
}
if ( !(_BYTE)v3 )
goto LABEL_13;
if ( !--v5 )
goto LABEL_14;
}
if ( us_log_level > 0 )
us_log_error_proc("unable to read rounded string");
LABEL_13:
v3 = 0;
(*(void (__fastcall **)(_QWORD, const char *))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"contents of test buffer:\n");
us_buffer_print(v1, us_testutil_printer_stdout);
(*(void (__fastcall **)(_QWORD, const char *))(us_testutil_printer_stdout + 8LL))(
us_testutil_printer_stdout,
"\n");
LABEL_14:
--v2;
}
while ( v2 );
}
else
{
v3 = 1;
if ( us_log_level > 0 )
us_log_error_proc("expected to allocate 1024 bytes from allocator for buffer but failed");
}
return v3 & (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: 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 v3; // er12

if ( !(unsigned __int8)us_testutil_start(2048LL, 2048LL, a1, a2) )
return 1LL;
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");
v3 = (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 v3;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1, __int64 a2)
{
unsigned int v3; // er12

if ( !(unsigned __int8)us_testutil_start(2048LL, 2048LL, a1, a2) )
return 1LL;
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");
v3 = (unsigned __int8)func14() ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing us_test_buffer");
us_logger_finish();
us_testutil_finish();
return v3;
}

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; // rbp
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; // rbp
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; // er12
const char *v4; // r12
const char *v5; // r13
const char *v6; // r14

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];
if ( argc == 3 )
v6 = (const char *)&unk_147;
else
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; // er12
const char *v4; // r12
const char *v5; // r13
const char *v6; // r14

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];
if ( argc == 3 )
v6 = (const char *)&unk_147;
else
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;
}


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 v3; // er12

if ( !(unsigned __int8)us_testutil_start(4096LL, 4096LL, a1, a2) )
return 1LL;
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");
v3 = (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 v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, const char **a2)
{
unsigned int v3; // er12

if ( !(unsigned __int8)us_testutil_start(4096LL, 4096LL, a1, a2) )
return 1LL;
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");
v3 = (unsigned __int8)func0() ^ 1;
if ( us_log_level > 2 )
us_log_info_proc("Finishing %s", *a2);
us_logger_finish();
us_testutil_finish();
return v3;
}

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


decompiled_code:
__int64 us_test_queue()
{
int v0; // ebx
int v1; // ebx
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // eax
int v6; // edi
int v7; // ebx
char v8; // al
__int64 v9; // rsi
int v10; // eax
int v11; // ebx
int v12; // ebp
__int64 v13; // rbx
char v15; // al
unsigned __int8 v16; // al
unsigned __int8 v17; // al
int v18; // [rsp+2h] [rbp-26h] BYREF
char v19[34]; // [rsp+6h] [rbp-22h] BYREF

v18 = 1432778632;
strcpy(v19, "D3\"");
*(_WORD *)&v19[7] = 0;
v19[9] = 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_constprop_0(7u, 0);
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( us_queue_can_write_byte_constprop_0() )
us_queue_write_byte_constprop_0(1);
v1 = us_validate_queue_constprop_0(6u, 1u) & v0;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( us_queue_can_write_byte_constprop_0() )
us_queue_write_byte_constprop_0(5);
v2 = us_validate_queue_constprop_0(5u, 2u) & v1;
if ( us_log_level > 3 )
us_log_debug_proc("Try read first byte");
if ( us_queue_can_read_byte_constprop_0() )
{
v17 = us_queue_read_byte_constprop_0();
if ( v17 != 1 )
{
v2 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x01, got 0x%02x", v17);
}
}
v3 = us_validate_queue_constprop_0(6u, 1u) & v2;
if ( us_log_level > 3 )
us_log_debug_proc("Try read second byte");
if ( us_queue_can_read_byte_constprop_0() )
{
v16 = us_queue_read_byte_constprop_0();
if ( v16 != 5 )
{
v3 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x05, got 0x%02x", v16);
}
}
v4 = us_validate_queue_constprop_0(7u, 0) & v3;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( (int)us_queue_writable_count_constprop_0() > 6 )
us_queue_write(&queue, &v18, 7LL);
v5 = us_validate_queue_constprop_0(0, 7u);
v6 = us_log_level;
v7 = v5 & v4;
if ( us_log_level <= 3 )
{
v15 = us_queue_peek_constprop_0();
v9 = (unsigned __int8)v19[2];
if ( v19[2] == v15 )
goto LABEL_27;
v7 = 0;
if ( v6 <= 0 )
goto LABEL_27;
goto LABEL_24;
}
us_log_debug_proc("Try peek 7th byte");
v8 = us_queue_peek_constprop_0();
v9 = (unsigned __int8)v19[2];
if ( v19[2] != v8 )
{
v7 = 0;
if ( us_log_level <= 0 )
goto LABEL_27;
LABEL_24:
v7 = 0;
us_log_error_proc("Expected 0x%02x, got 0x%02x", v9);
v10 = us_log_level;
goto LABEL_25;
}
v10 = us_log_level;
LABEL_25:
if ( v10 > 3 )
us_log_debug_proc("Try skip 7 bytes");
LABEL_27:
us_queue_skip_constprop_0();
v11 = us_validate_queue_constprop_0(7u, 0) & v7;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( (int)us_queue_writable_count_constprop_0() > 6 )
us_queue_write(&queue, &v18, 7LL);
v12 = v11 & us_validate_queue_constprop_0(0, 7u);
if ( us_log_level > 3 )
us_log_debug_proc("Try read 7 bytes");
v13 = 0LL;
us_queue_read(&queue, &v19[3], 7LL);
do
{
if ( *((_BYTE *)&v18 + v13) != v19[v13 + 3] )
{
v12 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected byte %d to be 0x%02x, got 0x%02x", (unsigned int)v13);
}
++v13;
}
while ( v13 != 7 );
return v12 & (unsigned int)us_validate_queue_constprop_0(7u, 0);
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // ebx
int v1; // ebx
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // eax
int v6; // edi
int v7; // ebx
char v8; // al
__int64 v9; // rsi
int v10; // eax
int v11; // ebx
int v12; // ebp
__int64 v13; // rbx
char v15; // al
unsigned __int8 v16; // al
unsigned __int8 v17; // al
int v18; // [rsp+2h] [rbp-26h] BYREF
char v19[34]; // [rsp+6h] [rbp-22h] BYREF

v18 = 1432778632;
strcpy(v19, "D3\"");
*(_WORD *)&v19[7] = 0;
v19[9] = 0;
if ( us_log_level > 3 )
us_log_debug_proc("init queue of 8 elements");
us_queue_init(&queue, &mem, 8LL);
v0 = func8(7u, 0);
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( func1() )
func0(1);
v1 = func8(6u, 1u) & v0;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 1 byte");
if ( func1() )
func0(5);
v2 = func8(5u, 2u) & v1;
if ( us_log_level > 3 )
us_log_debug_proc("Try read first byte");
if ( func6() )
{
v17 = func5();
if ( v17 != 1 )
{
v2 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x01, got 0x%02x", v17);
}
}
v3 = func8(6u, 1u) & v2;
if ( us_log_level > 3 )
us_log_debug_proc("Try read second byte");
if ( func6() )
{
v16 = func5();
if ( v16 != 5 )
{
v3 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected 0x05, got 0x%02x", v16);
}
}
v4 = func8(7u, 0) & v3;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( (int)func2() > 6 )
us_queue_write(&queue, &v18, 7LL);
v5 = func8(0, 7u);
v6 = us_log_level;
v7 = v5 & v4;
if ( us_log_level <= 3 )
{
v15 = func4();
v9 = (unsigned __int8)v19[2];
if ( v19[2] == v15 )
goto LABEL_27;
v7 = 0;
if ( v6 <= 0 )
goto LABEL_27;
goto LABEL_24;
}
us_log_debug_proc("Try peek 7th byte");
v8 = func4();
v9 = (unsigned __int8)v19[2];
if ( v19[2] != v8 )
{
v7 = 0;
if ( us_log_level <= 0 )
goto LABEL_27;
LABEL_24:
v7 = 0;
us_log_error_proc("Expected 0x%02x, got 0x%02x", v9);
v10 = us_log_level;
goto LABEL_25;
}
v10 = us_log_level;
LABEL_25:
if ( v10 > 3 )
us_log_debug_proc("Try skip 7 bytes");
LABEL_27:
func3();
v11 = func8(7u, 0) & v7;
if ( us_log_level > 3 )
us_log_debug_proc("Try write 7 bytes");
if ( (int)func2() > 6 )
us_queue_write(&queue, &v18, 7LL);
v12 = v11 & func8(0, 7u);
if ( us_log_level > 3 )
us_log_debug_proc("Try read 7 bytes");
v13 = 0LL;
us_queue_read(&queue, &v19[3], 7LL);
do
{
if ( *((_BYTE *)&v18 + v13) != v19[v13 + 3] )
{
v12 = 0;
if ( us_log_level > 0 )
us_log_error_proc("Expected byte %d to be 0x%02x, got 0x%02x", (unsigned int)v13);
}
++v13;
}
while ( v13 != 7 );
return v12 & (unsigned int)func8(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 us_test_queue_main()
{
unsigned int v1; // er12

if ( !(unsigned __int8)us_testutil_start("%s", "%s") )
return 1LL;
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 func10()
{
unsigned int v1; // er12

if ( !(unsigned __int8)us_testutil_start("%s", "%s") )
return 1LL;
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)
{
__time_t v2; // r8
__int64 v3; // rax
__time_t v4; // rsi
int v5; // er8
__int64 result; // rax
struct timeval v7; // [rsp+0h] [rbp-28h] BYREF
__int64 v8; // [rsp+10h] [rbp-18h]
__time_t v9; // [rsp+18h] [rbp-10h]

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

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

v2 = a2[1];
v7.tv_sec = *a2;
v3 = a2[2];
v4 = a2[3];
v8 = v3;
v7.tv_usec = v2 / 1000;
v9 = v4 / 1000;
v5 = utimes(a1, &v7);
result = 0LL;
if ( v5 == -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; // er12

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; // er12

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