original_code:
int us_serial_net_open( const char *serial_device, const char *serial_options )
{
    int fd = -1;
    int e;
    const char *connect_addr = serial_device + 4;
    struct addrinfo *src_ai;
    struct addrinfo *dest_ai;
    char dest_ip[256] = "127.0.0.1";
    char dest_port[64] = "7777";
    (void)serial_options;
    if ( strlen( connect_addr ) > 0 )
    {
        char *end_ip;
        strncpy( dest_ip, connect_addr, sizeof( dest_ip ) );
        dest_ip[sizeof( dest_ip ) - 1] = '\0';
        end_ip = strchr( dest_ip, ',' );
        if ( end_ip )
        {
            *end_ip = '\0';
            strncpy( dest_port, end_ip + 1, sizeof( dest_port ) );
            dest_port[sizeof( dest_port ) - 1] = '\0';
        }
    }
    src_ai = us_net_get_addrinfo( "0.0.0.0", "0", SOCK_STREAM, 0 );
    if ( src_ai == 0 )
    {
        perror( "src getaddrinfo:" );
        abort();
    }
    dest_ai = us_net_get_addrinfo( dest_ip, dest_port, SOCK_STREAM, 0 );
    if ( dest_ai == 0 )
    {
        perror( "dest getaddrinfo:" );
        abort();
    }
    fd = us_net_create_tcp_socket( src_ai, 0 );
    if ( fd < 0 )
    {
        perror( "socket:" );
        abort();
    }
    do
    {
        e = connect( fd, dest_ai->ai_addr, dest_ai->ai_addrlen );
    } while ( e < 0 && (*__errno_location ()) == 4 );
    if ( e < 0 )
    {
        perror( "connect to serial net" );
        close( fd );
        abort();
    }
    do
    {
        e = fcntl( fd, 4, 04000 );
    } while ( e < 0 && (*__errno_location ()) == 4 );
    if ( e < 0 )
    {
        perror( "fcntl F_SETFL O_NONBLOCK failed" );
        close( fd );
        abort();
    }
    freeaddrinfo( src_ai );
    freeaddrinfo( dest_ai );
    return fd;
}

canonical_original_code:
int us_serial_net_open(char *serial_device, char *serial_options)
{
    int fd = -1;
    int e;
    char *connect_addr = serial_device + 4;
    struct addrinfo *src_ai;
    struct addrinfo *dest_ai;
    char dest_ip[256] = "127.0.0.1";
    char dest_port[64] = "7777";
    (void)serial_options;
    if ( strlen( connect_addr ) > 0 )
    {
        char *end_ip;
        strncpy( dest_ip, connect_addr, sizeof( dest_ip ) );
        dest_ip[sizeof( dest_ip ) - 1] = '\0';
        end_ip = strchr( dest_ip, ',' );
        if ( end_ip )
        {
            *end_ip = '\0';
            strncpy( dest_port, end_ip + 1, sizeof( dest_port ) );
            dest_port[sizeof( dest_port ) - 1] = '\0';
        }
    }
    src_ai = us_net_get_addrinfo( "0.0.0.0", "0", SOCK_STREAM, 0 );
    if ( src_ai == 0 )
    {
        perror( "src getaddrinfo:" );
        abort();
    }
    dest_ai = us_net_get_addrinfo( dest_ip, dest_port, SOCK_STREAM, 0 );
    if ( dest_ai == 0 )
    {
        perror( "dest getaddrinfo:" );
        abort();
    }
    fd = us_net_create_tcp_socket( src_ai, 0 );
    if ( fd < 0 )
    {
        perror( "socket:" );
        abort();
    }
    do
    {
        e = connect( fd, dest_ai->ai_addr, dest_ai->ai_addrlen );
    } while ( e < 0 && (*__errno_location ()) == 4 );
    if ( e < 0 )
    {
        perror( "connect to serial net" );
        close( fd );
        abort();
    }
    do
    {
        e = fcntl( fd, 4, 04000 );
    } while ( e < 0 && (*__errno_location ()) == 4 );
    if ( e < 0 )
    {
        perror( "fcntl F_SETFL O_NONBLOCK failed" );
        close( fd );
        abort();
    }
    freeaddrinfo( src_ai );
    freeaddrinfo( dest_ai );
    return fd;
}

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

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


repo: jdkoftinoff/microsupport

decompiled_code:
__int64 __fastcall us_serial_open(char *file, char *s)
{
unsigned int v4; // ebx
int v6; // eax

if ( !memcmp(file, "/dev/", 5uLL) )
{
v6 = open(file, 2);
v4 = v6;
if ( v6 >= 0 && s && !(unsigned __int8)us_serial_setup(v6, s) )
v4 = -1;
}
else if ( !memcmp(file, "tcp:", 4uLL) )
{
v4 = us_serial_net_open((__int64)file);
}
else
{
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *file, char *s)
{
unsigned int v4; // ebx
int v6; // eax

if ( !memcmp(file, "/dev/", 5uLL) )
{
v6 = open(file, 2);
v4 = v6;
if ( v6 >= 0 && s && !(unsigned __int8)func0(v6, s) )
v4 = -1;
}
else if ( !memcmp(file, "tcp:", 4uLL) )
{
v4 = func1((__int64)file);
}
else
{
v4 = -1;
}
return v4;
}

original_code:
int us_serial_open( const char *serial_device, const char *serial_options )
{
    int fd = -1;
    if ( strncmp( serial_device, "/dev/", 5 ) == 0 )
    {
        fd = open( serial_device, 02 );
        if ( fd >= 0 && serial_options )
        {
            if ( !us_serial_setup( fd, serial_options ) )
            {
                fd = -1;
            }
        }
    }
    else if ( strncmp( serial_device, "tcp:", 4 ) == 0 )
    {
        fd = us_serial_net_open( serial_device, serial_options );
    }
    return fd;
}

canonical_original_code:
int us_serial_open(char *serial_device, char *serial_options)
{
    int fd = -1;
    if ( strncmp( serial_device, "/dev/", 5 ) == 0 )
    {
        fd = open( serial_device, 02 );
        if ( fd >= 0 && serial_options )
        {
            if ( !us_serial_setup( fd, serial_options ) )
            {
                fd = -1;
            }
        }
    }
    else if ( strncmp( serial_device, "tcp:", 4 ) == 0 )
    {
        fd = us_serial_net_open( serial_device, serial_options );
    }
    return fd;
}

variable_types: fd int

return_type: int


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

if ( a1 != -1 )
result = close(a1);
return result;
}

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

if ( a1 != -1 )
result = close(a1);
return result;
}

original_code:
void us_serial_close( int fd )
{
    if ( fd != -1 )
        close( fd );
}

canonical_original_code:
void us_serial_close(int fd)
{
    if ( fd != -1 )
        close( fd );
}

return_type: void


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

for ( result = 0LL; result != 16; result += 4LL )
*(_DWORD *)(a1 + result) = *(_DWORD *)(a2 + result) + *(_DWORD *)(a3 + result);
return result;
}

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

for ( result = 0LL; result != 16; result += 4LL )
*(_DWORD *)(a1 + result) = *(_DWORD *)(a2 + result) + *(_DWORD *)(a3 + result);
return result;
}

original_code:
static inline void us_osc_dispatch_index_add( us_osc_dispatch_index_t *self,
                                              const us_osc_dispatch_index_t *src1,
                                              const us_osc_dispatch_index_t *src2 )
{
    int i;
    for ( i = 0; i < ( 4 ); ++i )
        self->axis[i] = src1->axis[i] + src2->axis[i];
}

canonical_original_code:
static inline void us_osc_dispatch_index_add(struct us_osc_dispatch_index_s *self, struct us_osc_dispatch_index_s *src1, struct us_osc_dispatch_index_s *src2)
{
    int i;
    for ( i = 0; i < ( 4 ); ++i )
        self->axis[i] = src1->axis[i] + src2->axis[i];
}

variable_types: struct us_osc_dispatch_index_s { int axis[-1]; } *

variable_types: i int


decompiled_code:
__int64 __fastcall us_osc_dispatch_trie_star_comparator(char a1, char a2)
{
__int64 result; // rax

if ( a1 == 63 || a1 == 42 || a2 == 42 )
result = 0LL;
else
result = (unsigned int)(a1 - a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, char a2)
{
__int64 result; // rax

if ( a1 == 63 || a1 == 42 || a2 == 42 )
result = 0LL;
else
result = (unsigned int)(a1 - a2);
return result;
}

original_code:
int us_osc_dispatch_trie_star_comparator( us_trie_node_value_t a, us_trie_node_value_t b )
{
    if ( a == ( us_trie_node_value_t )( '*' ) || b == ( us_trie_node_value_t )( '*' ) )
    {
        return 0;
    }
    else if ( a == ( us_trie_node_value_t )( '?' ) )
    {
        return 0;
    }
    else
    {
        return (int)( a - b );
    }
}

canonical_original_code:
int us_osc_dispatch_trie_star_comparator(char a, char b)
{
    if ( a == ( us_trie_node_value_t )( '*' ) || b == ( us_trie_node_value_t )( '*' ) )
    {
        return 0;
    }
    else if ( a == ( us_trie_node_value_t )( '?' ) )
    {
        return 0;
    }
    else
    {
        return (int)( a - b );
    }
}

variable_types: a char

variable_types: b char


decompiled_code:
__int64 __fastcall us_osc_dispatch_trie_star_skip(char a1)
{
return (unsigned int)-(a1 == 42);
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
return (unsigned int)-(a1 == 42);
}

original_code:
int us_osc_dispatch_trie_star_skip( us_trie_node_value_t a )
{
    int r;
    if ( a == ( us_trie_node_value_t )( '*' ) )
    {
        r = -1;
    }
    else
    {
        r = 0;
    }
    return r;
}

canonical_original_code:
int us_osc_dispatch_trie_star_skip(char a)
{
    int r;
    if ( a == ( us_trie_node_value_t )( '*' ) )
    {
        r = -1;
    }
    else
    {
        r = 0;
    }
    return r;
}

variable_types: r int


original_code:
void us_osc_dispatch_destroy( us_osc_dispatch_t *self )
{
    if ( self->allocator )
    {
        if ( self->trie )
        {
            self->trie->destroy( self->trie );
        }
    }
}

canonical_original_code:
void us_osc_dispatch_destroy(struct us_osc_dispatch_s *self)
{
    if ( self->allocator )
    {
        if ( self->trie )
        {
            self->trie->destroy( self->trie );
        }
    }
}

variable_types: struct us_osc_dispatch_s { void (*destroy)(struct us_osc_dispatch_s *self); _Bool (*receive_msg)(struct us_osc_dispatch_s *self, struct us_osc_msg_s { void (*destroy)(struct us_osc_msg_s *self); struct us_osc_msg_element_s { void (*destroy)(struct us_osc_msg_element_s *self, struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *allocator); _Bool (*print)(struct us_osc_msg_element_s *self, struct us_print_s { void (*destroy)(struct us_print_s *self); _Bool (*printf)(struct us_print_s *self, char *fmt, ...); _Bool (*vprintf)(struct us_print_s *self, char *fmt, __builtin_va_list ap); } *printer); _Bool (*flatten)(struct us_osc_msg_element_s *self, struct us_buffer_s { void (*destroy)(struct us_buffer_s *self); struct us_allocator_s *m_allocator; unsigned char *m_buffer; unsigned long m_next_in; unsigned long m_next_out; unsigned long m_max_length; } *buf, int *length); struct us_osc_msg_element_s *m_next; char m_code; } *(*append)(struct us_osc_msg_s *self, struct us_osc_msg_element_s *element); _Bool (*print)(struct us_osc_msg_s *self, struct us_print_s *printer); _Bool (*flatten)(struct us_osc_msg_s *self, struct us_buffer_s *buf, int *length); struct us_allocator_s *m_allocator; char *m_address; unsigned int m_address_code; struct us_osc_msg_element_s *m_first_element; struct us_osc_msg_element_s *m_last_element; struct us_osc_msg_s *m_next; } *msg, struct us_osc_sender_s { void (*destroy)(struct us_osc_sender_s *self); _Bool (*can_send)(struct us_osc_sender_s *self); _Bool (*send_msg)(struct us_osc_sender_s *self, struct us_osc_msg_s *msg); _Bool (*form_and_send_msg)(struct us_osc_sender_s *self, char *address, char *typetags, ...); } *sender, void *extra); struct us_allocator_s *allocator; struct us_trie_dyn_s { struct us_trie_s { short m_max_nodes; short m_num_nodes; struct us_trie_node_s { short m_parent; short m_sibling; short m_child; char m_value; unsigned short m_flags; } *m_nodes; short m_first_free; _Bool (*m_query_ignorer)(char); _Bool (*m_db_ignorer)(char); int (*m_db_skip)(char); int (*m_comparator)(char, char); } m_base; void (*destroy)(struct us_trie_dyn_s *); struct us_allocator_s *m_allocator; struct us_trie_node_s *m_nodes; } *trie; _Bool (*notify)(struct us_osc_dispatch_s *self, char *address, struct us_osc_dispatch_table_s { char *address; _Bool (*receive_msg_proc)(struct us_osc_dispatch_s *self, struct us_osc_msg_s *msg, struct us_osc_dispatch_index_s { int axis[-1]; } *index, struct us_osc_sender_s *sender, void *extra); struct us_osc_dispatch_index_s index; } *table_item, struct us_osc_dispatch_index_s *index); struct us_osc_dispatch_map_s { struct us_osc_dispatch_map_entry_s { struct us_osc_dispatch_table_s *table_entry; struct us_osc_dispatch_index_s final_index; } *entries; int max_entries; int num_entries; } map; } *

user_defined_types: struct us_osc_dispatch_s { void (*destroy)(struct us_osc_dispatch_s *self); _Bool (*receive_msg)(struct us_osc_dispatch_s *self, struct us_osc_msg_s *msg, struct us_osc_sender_s *sender, void *extra); struct us_allocator_s *allocator; struct us_trie_dyn_s *trie; _Bool (*notify)(struct us_osc_dispatch_s *self, char *address, struct us_osc_dispatch_table_s *table_item, struct us_osc_dispatch_index_s *index); struct us_osc_dispatch_map_s map; }

user_defined_types: struct us_osc_dispatch_map_s { struct us_osc_dispatch_map_entry_s *entries; int max_entries; int num_entries; }

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

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

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

user_defined_types: struct us_osc_dispatch_table_s { char *address; _Bool (*receive_msg_proc)(struct us_osc_dispatch_s *self, struct us_osc_msg_s *msg, struct us_osc_dispatch_index_s *index, struct us_osc_sender_s *sender, void *extra); struct us_osc_dispatch_index_s index; }

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


decompiled_code:
__int64 __fastcall us_osc_dispatch_receive_msg(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
const char *v6; // r14
__int16 v7; // ax
__int64 result; // rax
__int64 v9; // rax
char v10[2]; // [rsp+Ah] [rbp-2Eh] BYREF
char v11[2]; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned __int16 v12[21]; // [rsp+Eh] [rbp-2Ah] BYREF

v6 = *(const char **)(a2 + 40);
v7 = strlen(v6);
result = us_trie_find(*(_QWORD *)(a1 + 24), v6, (unsigned int)v7, v12, v11, v10, 0LL, 0LL);
if ( (_BYTE)result )
{
v9 = *(_QWORD *)(a1 + 40) + 24LL * v12[0];
result = (*(__int64 (__fastcall **)(__int64, __int64, __int64, __int64, __int64))(*(_QWORD *)v9 + 8LL))(
a1,
a2,
v9 + 8,
a3,
a4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
const char *v6; // r14
__int16 v7; // ax
__int64 result; // rax
__int64 v9; // rax
char v10[2]; // [rsp+Ah] [rbp-2Eh] BYREF
char v11[2]; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned __int16 v12[21]; // [rsp+Eh] [rbp-2Ah] BYREF

v6 = *(const char **)(a2 + 40);
v7 = strlen(v6);
result = us_trie_find(*(_QWORD *)(a1 + 24), v6, (unsigned int)v7, v12, v11, v10, 0LL, 0LL);
if ( (_BYTE)result )
{
v9 = *(_QWORD *)(a1 + 40) + 24LL * v12[0];
result = (*(__int64 (__fastcall **)(__int64, __int64, __int64, __int64, __int64))(*(_QWORD *)v9 + 8LL))(
a1,
a2,
v9 + 8,
a3,
a4);
}
return result;
}

original_code:
_Bool us_osc_dispatch_receive_msg( us_osc_dispatch_t *self, const us_osc_msg_t *msg, us_osc_sender_t *sender, void *extra )
{
    _Bool r = 0;
    us_trie_node_flags_t flags;
    int16_t match_len;
    us_trie_node_id_t match_item;
    if ( us_trie_find( &self->trie->m_base,
                       (us_trie_node_value_t *)msg->m_address,
                       strlen( msg->m_address ),
                       &flags,
                       &match_len,
                       &match_item,
                       0,
                       0 ) )
    {
        us_osc_dispatch_map_entry_t *entry = &self->map.entries[flags];
        r = entry->table_entry->receive_msg_proc( self, msg, &entry->final_index, sender, extra );
    }
    return r;
}

canonical_original_code:
_Bool us_osc_dispatch_receive_msg(struct us_osc_dispatch_s *self, struct us_osc_msg_s *msg, struct us_osc_sender_s *sender, void *extra)
{
    _Bool r = 0;
    unsigned short flags;
    short match_len;
    short match_item;
    if ( us_trie_find( &self->trie->m_base,
                       (char *)msg->m_address,
                       strlen( msg->m_address ),
                       &flags,
                       &match_len,
                       &match_item,
                       0,
                       0 ) )
    {
        struct us_osc_dispatch_map_entry_s *entry = &self->map.entries[flags];
        r = entry->table_entry->receive_msg_proc( self, msg, &entry->final_index, sender, extra );
    }
    return r;
}

variable_types:
msg
struct us_osc_msg_s *

variable_types:
sender
struct us_osc_sender_s *

variable_types:
extra
void *

variable_types:
flags
unsigned short

variable_types: struct us_osc_dispatch_map_entry_s { struct us_osc_dispatch_table_s { char *address; _Bool (*receive_msg_proc)(struct us_osc_dispatch_s { void (*destroy)(struct us_osc_dispatch_s *self); _Bool (*receive_msg)(struct us_osc_dispatch_s *self, struct us_osc_msg_s { void (*destroy)(struct us_osc_msg_s *self); struct us_osc_msg_element_s { void (*destroy)(struct us_osc_msg_element_s *self, struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *allocator); _Bool (*print)(struct us_osc_msg_element_s *self, struct us_print_s { void (*destroy)(struct us_print_s *self); _Bool (*printf)(struct us_print_s *self, char *fmt, ...); _Bool (*vprintf)(struct us_print_s *self, char *fmt, __builtin_va_list ap); } *printer); _Bool (*flatten)(struct us_osc_msg_element_s *self, struct us_buffer_s { void (*destroy)(struct us_buffer_s *self); struct us_allocator_s *m_allocator; unsigned char *m_buffer; unsigned long m_next_in; unsigned long m_next_out; unsigned long m_max_length; } *buf, int *length); struct us_osc_msg_element_s *m_next; char m_code; } *(*append)(struct us_osc_msg_s *self, struct us_osc_msg_element_s *element); _Bool (*print)(struct us_osc_msg_s *self, struct us_print_s *printer); _Bool (*flatten)(struct us_osc_msg_s *self, struct us_buffer_s *buf, int *length); struct us_allocator_s *m_allocator; char *m_address; unsigned int m_address_code; struct us_osc_msg_element_s *m_first_element; struct us_osc_msg_element_s *m_last_element; struct us_osc_msg_s *m_next; } *msg, struct us_osc_sender_s { void (*destroy)(struct us_osc_sender_s *self); _Bool (*can_send)(struct us_osc_sender_s *self); _Bool (*send_msg)(struct us_osc_sender_s *self, struct us_osc_msg_s *msg); _Bool (*form_and_send_msg)(struct us_osc_sender_s *self, char *address, char *typetags, ...); } *sender, void *extra); struct us_allocator_s *allocator; struct us_trie_dyn_s { struct us_trie_s { short m_max_nodes; short m_num_nodes; struct us_trie_node_s { short m_parent; short m_sibling; short m_child; char m_value; unsigned short m_flags; } *m_nodes; short m_first_free; _Bool (*m_query_ignorer)(char); _Bool (*m_db_ignorer)(char); int (*m_db_skip)(char); int (*m_comparator)(char, char); } m_base; void (*destroy)(struct us_trie_dyn_s *); struct us_allocator_s *m_allocator; struct us_trie_node_s *m_nodes; } *trie; _Bool (*notify)(struct us_osc_dispatch_s *self, char *address, struct us_osc_dispatch_table_s *table_item, struct us_osc_dispatch_index_s { int axis[-1]; } *index); struct us_osc_dispatch_map_s { struct us_osc_dispatch_map_entry_s *entries; int max_entries; int num_entries; } map; } *self, struct us_osc_msg_s *msg, struct us_osc_dispatch_index_s *index, struct us_osc_sender_s *sender, void *extra); struct us_osc_dispatch_index_s index; } *table_entry; struct us_osc_dispatch_index_s final_index; } *

user_defined_types: struct us_osc_dispatch_map_entry_s { struct us_osc_dispatch_table_s *table_entry; struct us_osc_dispatch_index_s final_index; }


decompiled_code:
__int64 __fastcall us_osc_dispatch_init(__int64 a1, __int64 a2, unsigned int a3, unsigned __int16 a4)
{
__int64 v5; // rax
unsigned int v6; // edx

*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 24) = us_trie_dyn_create(
a2,
a4,
&us_trie_basic_ignorer,
&us_trie_basic_ignorer,
us_osc_dispatch_trie_star_skip,
us_osc_dispatch_trie_star_comparator);
*(_QWORD *)a1 = us_osc_dispatch_destroy;
*(_QWORD *)(a1 + 8) = us_osc_dispatch_receive_msg;
v5 = (*(__int64 (__fastcall **)(__int64, __int64, _QWORD))(a2 + 8))(a2, 24LL, a3);
*(_QWORD *)(a1 + 40) = v5;
*(_QWORD *)(a1 + 32) = 0LL;
v6 = 0;
if ( v5 )
{
*(_DWORD *)(a1 + 48) = a3;
*(_DWORD *)(a1 + 52) = 0;
v6 = 1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3, unsigned __int16 a4)
{
__int64 v5; // rax
unsigned int v6; // edx

*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 24) = us_trie_dyn_create(
a2,
a4,
&us_trie_basic_ignorer,
&us_trie_basic_ignorer,
us_osc_dispatch_trie_star_skip,
us_osc_dispatch_trie_star_comparator);
*(_QWORD *)a1 = us_osc_dispatch_destroy;
*(_QWORD *)(a1 + 8) = us_osc_dispatch_receive_msg;
v5 = (*(__int64 (__fastcall **)(__int64, __int64, _QWORD))(a2 + 8))(a2, 24LL, a3);
*(_QWORD *)(a1 + 40) = v5;
*(_QWORD *)(a1 + 32) = 0LL;
v6 = 0;
if ( v5 )
{
*(_DWORD *)(a1 + 48) = a3;
*(_DWORD *)(a1 + 52) = 0;
v6 = 1;
}
return v6;
}

original_code:
_Bool us_osc_dispatch_init( us_osc_dispatch_t *self, us_allocator_t *allocator, int max_table_entries, int max_trie_elements )
{
    _Bool r = 0;
    self->allocator = allocator;
    self->trie = us_trie_dyn_create( allocator,
                                     max_trie_elements,
                                     us_trie_basic_ignorer,
                                     us_trie_basic_ignorer,
                                     us_osc_dispatch_trie_star_skip,
                                     us_osc_dispatch_trie_star_comparator );
    self->destroy = us_osc_dispatch_destroy;
    self->receive_msg = us_osc_dispatch_receive_msg;
    self->map.entries = ( us_osc_dispatch_map_entry_t * )( ( allocator )->alloc( ( allocator ), (int32_t)sizeof( us_osc_dispatch_map_entry_t ), ( int32_t )( max_table_entries ) ) );
    self->notify = 0;
    if ( self->map.entries )
    {
        self->map.max_entries = max_table_entries;
        self->map.num_entries = 0;
        r = 1;
    }
    return r;
}

canonical_original_code:
_Bool us_osc_dispatch_init(struct us_osc_dispatch_s *self, struct us_allocator_s *allocator, int max_table_entries, int max_trie_elements)
{
    _Bool r = 0;
    self->allocator = allocator;
    self->trie = us_trie_dyn_create( allocator,
                                     max_trie_elements,
                                     us_trie_basic_ignorer,
                                     us_trie_basic_ignorer,
                                     us_osc_dispatch_trie_star_skip,
                                     us_osc_dispatch_trie_star_comparator );
    self->destroy = us_osc_dispatch_destroy;
    self->receive_msg = us_osc_dispatch_receive_msg;
    self->map.entries = ( struct us_osc_dispatch_map_entry_s * )( ( allocator )->alloc( ( allocator ), (int)sizeof( us_osc_dispatch_map_entry_t ), ( int )( max_table_entries ) ) );
    self->notify = 0;
    if ( self->map.entries )
    {
        self->map.max_entries = max_table_entries;
        self->map.num_entries = 0;
        r = 1;
    }
    return r;
}

variable_types:
allocator
struct us_allocator_s *

user_defined_types: struct us_osc_sender_s { void (*destroy)(struct us_osc_sender_s *self); _Bool (*can_send)(struct us_osc_sender_s *self); _Bool (*send_msg)(struct us_osc_sender_s *self, struct us_osc_msg_s *msg); _Bool (*form_and_send_msg)(struct us_osc_sender_s *self, char *address, char *typetags, ...); }

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

user_defined_types: struct us_osc_dispatch_index_s { int axis[-1]; }

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

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

user_defined_types: struct us_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:
bool __fastcall us_osc_dispatch_add_entry_with_notify(__int64 a1, const char *a2, const char **a3, __int64 a4, __int64 (__fastcall *a5)(__int64, char *, const char **, __int64))
{
int v5; // er14
bool result; // al
const char ***v9; // r15
__int64 v10; // r15
char v11; // dl
__int16 v12; // ax
char v13[312]; // [rsp+0h] [rbp-138h] BYREF

v5 = *(_DWORD *)(a1 + 52);
result = 0;
if ( v5 < *(_DWORD *)(a1 + 48) )
{
v9 = (const char ***)(*(_QWORD *)(a1 + 40) + 24LL * v5);
*v9 = a3;
v10 = (__int64)(v9 + 1);
us_osc_dispatch_index_add(v10, a4, (__int64)(a3 + 2));
strcpy(v13, a2);
strcat(v13, *a3);
if ( !a5 )
{
a5 = *(__int64 (__fastcall **)(__int64, char *, const char **, __int64))(a1 + 32);
if ( !a5 )
goto LABEL_5;
}
v11 = a5(a1, v13, a3, v10);
result = 1;
if ( v11 )
{
LABEL_5:
v12 = strlen(v13);
us_trie_add(*(_QWORD *)(a1 + 24), v13, (unsigned int)v12, (unsigned __int16)v5);
++*(_DWORD *)(a1 + 52);
result = *(_WORD *)(*(_QWORD *)(a1 + 24) + 2LL) < **(_WORD **)(a1 + 24);
}
}
return result;
}

original_code:
_Bool us_osc_dispatch_add_entry_with_notify( us_osc_dispatch_t *self,
                                            const char *address_prefix,
                                            const us_osc_dispatch_table_t *dispatch_table,
                                            const us_osc_dispatch_index_t *index_offset,
                                            us_osc_dispatch_notify_proc_t notify_proc )
{
    _Bool r = 0;
    if ( self->map.num_entries < self->map.max_entries )
    {
        char resultant_address[256];
        int item = self->map.num_entries;
        us_osc_dispatch_map_entry_t *entry = &self->map.entries[item];
        r = 1;
        entry->table_entry = dispatch_table;
        us_osc_dispatch_index_add( &entry->final_index, index_offset, &dispatch_table->index );
        strcpy( resultant_address, address_prefix );
        strcat( resultant_address, dispatch_table->address );
        if ( !notify_proc )
        {
            notify_proc = self->notify;
        }
        if ( !notify_proc || notify_proc( self, resultant_address, dispatch_table, &entry->final_index ) == 1 )
        {
            us_trie_add( &self->trie->m_base,
                         (us_trie_node_value_t *)resultant_address,
                         strlen( resultant_address ),
                         (us_trie_node_flags_t)item );
            self->map.num_entries++;
            if ( self->trie->m_base.m_num_nodes >= self->trie->m_base.m_max_nodes )
            {
                r = 0;
            }
        }
    }
    return r;
}

canonical_original_code:
_Bool us_osc_dispatch_add_entry_with_notify(struct us_osc_dispatch_s *self, char *address_prefix, struct us_osc_dispatch_table_s *dispatch_table, struct us_osc_dispatch_index_s *index_offset, _Bool (*notify_proc)(struct us_osc_dispatch_s *self, char *address, struct us_osc_dispatch_table_s *table_item, struct us_osc_dispatch_index_s *index))
{
    _Bool r = 0;
    if ( self->map.num_entries < self->map.max_entries )
    {
        char resultant_address[256];
        int item = self->map.num_entries;
        struct us_osc_dispatch_map_entry_s *entry = &self->map.entries[item];
        r = 1;
        entry->table_entry = dispatch_table;
        us_osc_dispatch_index_add( &entry->final_index, index_offset, &dispatch_table->index );
        strcpy( resultant_address, address_prefix );
        strcat( resultant_address, dispatch_table->address );
        if ( !notify_proc )
        {
            notify_proc = self->notify;
        }
        if ( !notify_proc || notify_proc( self, resultant_address, dispatch_table, &entry->final_index ) == 1 )
        {
            us_trie_add( &self->trie->m_base,
                         (char *)resultant_address,
                         strlen( resultant_address ),
                         (unsigned short)item );
            self->map.num_entries++;
            if ( self->trie->m_base.m_num_nodes >= self->trie->m_base.m_max_nodes )
            {
                r = 0;
            }
        }
    }
    return r;
}

variable_types: _Bool (*)(struct us_osc_dispatch_s *self, char *address, struct us_osc_dispatch_table_s *table_item, struct us_osc_dispatch_index_s *index)

variable_types: item int


decompiled_code:
bool __fastcall us_osc_dispatch_add_entry(__int64 a1, const char *a2, const char **a3, __int64 a4)
{
return us_osc_dispatch_add_entry_with_notify(a1, a2, a3, a4, 0LL);
}

canonical_decompiled_code:
bool __fastcall func7(__int64 a1, const char *a2, const char **a3, __int64 a4)
{
return func6(a1, a2, a3, a4, 0LL);
}

original_code:
_Bool us_osc_dispatch_add_entry( us_osc_dispatch_t *self,
                                const char *address_prefix,
                                const us_osc_dispatch_table_t *dispatch_table,
                                const us_osc_dispatch_index_t *index_offset )
{
    return us_osc_dispatch_add_entry_with_notify( self, address_prefix, dispatch_table, index_offset, 0 );
}

canonical_original_code:
_Bool us_osc_dispatch_add_entry(struct us_osc_dispatch_s *self, char *address_prefix, struct us_osc_dispatch_table_s *dispatch_table, struct us_osc_dispatch_index_s *index_offset)
{
    return us_osc_dispatch_add_entry_with_notify( self, address_prefix, dispatch_table, index_offset, 0 );
}


decompiled_code:
bool __fastcall us_osc_dispatch_add_table_with_notify(__int64 a1, const char *a2, const char **a3, __int64 a4, __int64 (__fastcall *a5)(__int64, char *, const char **, __int64))
{
const char **v5; // rbx
bool result; // al

v5 = a3;
if ( !*a3 )
return 1;
do
{
result = us_osc_dispatch_add_entry_with_notify(a1, a2, v5, a4, a5);
if ( !result )
break;
v5 += 4;
}
while ( *v5 );
return result;
}

canonical_decompiled_code:
bool __fastcall func8(__int64 a1, const char *a2, const char **a3, __int64 a4, __int64 (__fastcall *a5)(__int64, char *, const char **, __int64))
{
const char **v5; // rbx
bool result; // al

v5 = a3;
if ( !*a3 )
return 1;
do
{
result = func6(a1, a2, v5, a4, a5);
if ( !result )
break;
v5 += 4;
}
while ( *v5 );
return result;
}

original_code:
_Bool us_osc_dispatch_add_table_with_notify( us_osc_dispatch_t *self,
                                            const char *address_prefix,
                                            const us_osc_dispatch_table_t dispatch_table[],
                                            const us_osc_dispatch_index_t *index_offset,
                                            us_osc_dispatch_notify_proc_t notify_proc )
{
    _Bool r = 1;
    while ( dispatch_table->address != 0 )
    {
        if ( !us_osc_dispatch_add_entry_with_notify( self, address_prefix, dispatch_table, index_offset, notify_proc ) )
        {
            r = 0;
            break;
        }
        dispatch_table++;
    }
    return r;
}

canonical_original_code:
_Bool us_osc_dispatch_add_table_with_notify(struct us_osc_dispatch_s *self, char *address_prefix, struct us_osc_dispatch_table_s dispatch_table[], struct us_osc_dispatch_index_s *index_offset, _Bool (*notify_proc)(struct us_osc_dispatch_s *self, char *address, struct us_osc_dispatch_table_s *table_item, struct us_osc_dispatch_index_s *index))
{
    _Bool r = 1;
    while ( dispatch_table->address != 0 )
    {
        if ( !us_osc_dispatch_add_entry_with_notify( self, address_prefix, dispatch_table, index_offset, notify_proc ) )
        {
            r = 0;
            break;
        }
        dispatch_table++;
    }
    return r;
}


decompiled_code:
bool __fastcall us_osc_dispatch_add_table(__int64 a1, const char *a2, const char **a3, __int64 a4)
{
return us_osc_dispatch_add_table_with_notify(a1, a2, a3, a4, 0LL);
}

canonical_decompiled_code:
bool __fastcall func9(__int64 a1, const char *a2, const char **a3, __int64 a4)
{
return func8(a1, a2, a3, a4, 0LL);
}

original_code:
_Bool us_osc_dispatch_add_table( us_osc_dispatch_t *self,
                                const char *address_prefix,
                                const us_osc_dispatch_table_t dispatch_table[],
                                const us_osc_dispatch_index_t *index_offset )
{
    return us_osc_dispatch_add_table_with_notify( self, address_prefix, dispatch_table, index_offset, 0 );
}

canonical_original_code:
_Bool us_osc_dispatch_add_table(struct us_osc_dispatch_s *self, char *address_prefix, struct us_osc_dispatch_table_s dispatch_table[], struct us_osc_dispatch_index_s *index_offset)
{
    return us_osc_dispatch_add_table_with_notify( self, address_prefix, dispatch_table, index_offset, 0 );
}


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

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

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

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

return_type: unsigned long


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

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

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

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

variable_types:
offset
unsigned long

return_type: unsigned char


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

canonical_decompiled_code:
unsigned __int64 __fastcall func2(_QWORD *a1)
{
return (unsigned __int64)(a1[4] + a1[5] - 1LL - a1[3]) % a1[5];
}

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

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


decompiled_code:
__int64 __fastcall us_buffer_write_buffer(_QWORD *a1, _QWORD *a2)
{
unsigned __int64 v2; // rbp
unsigned __int64 v3; // rdx
__int64 result; // rax
__int64 i; // rbx
char v6; // al

v2 = us_buffer_readable_count(a2);
v3 = us_buffer_writable_count(a1);
result = 0LL;
if ( v3 >= v2 )
{
if ( v2 )
{
for ( i = 0LL; i != v2; ++i )
{
v6 = us_buffer_peek(a2, i);
us_buffer_write_byte(a1, v6);
}
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, _QWORD *a2)
{
unsigned __int64 v2; // rbp
unsigned __int64 v3; // rdx
__int64 result; // rax
__int64 i; // rbx
char v6; // al

v2 = func0(a2);
v3 = func2(a1);
result = 0LL;
if ( v3 >= v2 )
{
if ( v2 )
{
for ( i = 0LL; i != v2; ++i )
{
v6 = func1(a2, i);
func3(a1, v6);
}
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
static inline _Bool us_buffer_write_buffer( us_buffer_t *self, const us_buffer_t *buf )
{
    _Bool r = 0;
    size_t rc = us_buffer_readable_count( buf );
    if ( us_buffer_writable_count( self ) >= rc )
    {
        size_t i;
        for ( i = 0; i < rc; ++i )
        {
            us_buffer_write_byte( self, us_buffer_peek( buf, i ) );
        }
        r = 1;
    }
    return r;
}

canonical_original_code:
static inline _Bool us_buffer_write_buffer(struct us_buffer_s *self, struct us_buffer_s *buf)
{
    _Bool r = 0;
    unsigned long rc = us_buffer_readable_count( buf );
    if ( us_buffer_writable_count( self ) >= rc )
    {
        unsigned long i;
        for ( i = 0; i < rc; ++i )
        {
            us_buffer_write_byte( self, us_buffer_peek( buf, i ) );
        }
        r = 1;
    }
    return r;
}

variable_types:
buf
struct us_buffer_s *

variable_types:
rc
unsigned long

variable_types:
i
unsigned long


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

result = *(unsigned int *)(a1 + 24);
if ( (_DWORD)result == 1 )
{
result = us_json_destroy(*(_QWORD *)(a1 + 16));
}
else if ( (_DWORD)result == 4 )
{
result = (**(__int64 (__fastcall ***)(_QWORD))(a1 + 16))(*(_QWORD *)(a1 + 16));
}
*(_DWORD *)(a1 + 24) = 0;
return result;
}

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

result = *(unsigned int *)(a1 + 24);
if ( (_DWORD)result == 1 )
{
result = func8(*(_QWORD *)(a1 + 16));
}
else if ( (_DWORD)result == 4 )
{
result = (**(__int64 (__fastcall ***)(_QWORD))(a1 + 16))(*(_QWORD *)(a1 + 16));
}
*(_DWORD *)(a1 + 24) = 0;
return result;
}

original_code:
void us_json_entry_remove_value( us_json_entry_t *self )
{
    if ( self->m_type == us_json_type_json )
    {
        us_json_destroy( self->value.m_value_json );
    }
    else if ( self->m_type == us_json_type_string_buffer )
    {
        self->value.m_value_string_buffer->destroy( self->value.m_value_string_buffer );
    }
    self->m_type = us_json_type_none;
}

canonical_original_code:
void us_json_entry_remove_value(struct us_json_entry_s *self)
{
    if ( self->m_type == us_json_type_json )
    {
        us_json_destroy( self->value.m_value_json );
    }
    else if ( self->m_type == us_json_type_string_buffer )
    {
        self->value.m_value_string_buffer->destroy( self->value.m_value_string_buffer );
    }
    self->m_type = us_json_type_none;
}

variable_types: struct us_json_entry_s { struct us_allocator_s { void (*destroy)(struct us_allocator_s *self); void *(*alloc)(struct us_allocator_s *self, int length, int count); void *(*realloc)(struct us_allocator_s *self, void *orig_ptr, int length, int count); void (*free)(struct us_allocator_s *self, void *ptr); } *m_allocator; char *m_key; union { 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; } *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; } *

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_json_entry_destroy(__int64 *a1)
{
__int64 result; // rax

if ( a1[4] )
us_json_entry_destroy();
us_json_entry_remove_value((__int64)a1);
result = *a1;
if ( *a1 )
result = (*(__int64 (__fastcall **)(__int64, __int64 *))(result + 24))(*a1, a1);
return result;
}

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

if ( a1[4] )
func7();
func6((__int64)a1);
result = *a1;
if ( *a1 )
result = (*(__int64 (__fastcall **)(__int64, __int64 *))(result + 24))(*a1, a1);
return result;
}

original_code:
void us_json_entry_destroy( us_json_entry_t *self )
{
    if ( self->m_next )
    {
        us_json_entry_destroy( self->m_next );
    }
    us_json_entry_remove_value( self );
    do { if ( ( self->m_allocator ) != 0 && ( self ) != 0 ) ( self->m_allocator )->free( ( self->m_allocator ), ( self ) ); } while ( 0 );
}

canonical_original_code:
void us_json_entry_destroy(struct us_json_entry_s *self)
{
    if ( self->m_next )
    {
        us_json_entry_destroy( self->m_next );
    }
    us_json_entry_remove_value( self );
    do { if ( ( self->m_allocator ) != 0 && ( self ) != 0 ) ( self->m_allocator )->free( ( self->m_allocator ), ( self ) ); } while ( 0 );
}

user_defined_types: 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 }

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


decompiled_code:
__int64 __fastcall us_json_destroy(__int64 a1)
{
__int64 *v2; // rdi
__int64 result; // rax

if ( a1 )
{
v2 = *(__int64 **)(a1 + 16);
if ( v2 )
result = us_json_entry_destroy(v2);
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
}
return result;
}

original_code:
void us_json_destroy( us_json_t *self )
{
    if ( self )
    {
        us_json_entry_t *cur = self->m_first_item;
        if ( cur )
        {
            us_json_entry_destroy( cur );
        }
        self->m_first_item = 0;
        self->m_last_item = 0;
    }
}

canonical_original_code:
void us_json_destroy(struct us_json_s *self)
{
    if ( self )
    {
        struct us_json_entry_s *cur = self->m_first_item;
        if ( cur )
        {
            us_json_entry_destroy( cur );
        }
        self->m_first_item = 0;
        self->m_last_item = 0;
    }
}

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


decompiled_code:
__int64 __fastcall us_json_entry_set_value_json(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = us_json_entry_remove_value(a1);
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = func6(a1);
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 1;
return result;
}

original_code:
void us_json_entry_set_value_json( us_json_entry_t *self, struct us_json_s *value )
{
    us_json_entry_remove_value( self );
    self->value.m_value_json = value;
    self->m_type = us_json_type_json;
}

canonical_original_code:
void us_json_entry_set_value_json(struct us_json_entry_s *self, struct us_json_s *value)
{
    us_json_entry_remove_value( self );
    self->value.m_value_json = value;
    self->m_type = us_json_type_json;
}

variable_types:
value
struct us_json_s *


decompiled_code:
__int64 __fastcall us_json_entry_set_value_string_ptr(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = us_json_entry_remove_value(a1);
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = func6(a1);
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 2;
return result;
}

original_code:
void us_json_entry_set_value_string_ptr( us_json_entry_t *self, const char *s )
{
    us_json_entry_remove_value( self );
    self->value.m_value_string_ptr = s;
    self->m_type = us_json_type_string_ptr;
}

canonical_original_code:
void us_json_entry_set_value_string_ptr(struct us_json_entry_s *self, char *s)
{
    us_json_entry_remove_value( self );
    self->value.m_value_string_ptr = s;
    self->m_type = us_json_type_string_ptr;
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall us_json_entry_set_value_int32_ptr(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = us_json_entry_remove_value(a1);
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = func6(a1);
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 3;
return result;
}

original_code:
void us_json_entry_set_value_int32_ptr( us_json_entry_t *self, int32_t *value )
{
    us_json_entry_remove_value( self );
    self->value.m_value_int32_ptr = value;
    self->m_type = us_json_type_int32_ptr;
}

canonical_original_code:
void us_json_entry_set_value_int32_ptr(struct us_json_entry_s *self, int *value)
{
    us_json_entry_remove_value( self );
    self->value.m_value_int32_ptr = value;
    self->m_type = us_json_type_int32_ptr;
}

variable_types:
value
int *


decompiled_code:
__int64 __fastcall us_json_entry_set_value_string_buffer(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = us_json_entry_remove_value(a1);
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = func6(a1);
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 4;
return result;
}

original_code:
void us_json_entry_set_value_string_buffer( us_json_entry_t *self, us_buffer_t *buf )
{
    us_json_entry_remove_value( self );
    self->value.m_value_string_buffer = buf;
    self->m_type = us_json_type_string_buffer;
}

canonical_original_code:
void us_json_entry_set_value_string_buffer(struct us_json_entry_s *self, struct us_buffer_s *buf)
{
    us_json_entry_remove_value( self );
    self->value.m_value_string_buffer = buf;
    self->m_type = us_json_type_string_buffer;
}


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

result = us_json_entry_remove_value(a1);
*(_DWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 5;
return result;
}

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

result = func6(a1);
*(_DWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 5;
return result;
}

original_code:
void us_json_entry_set_value_int32( us_json_entry_t *self, int32_t value )
{
    us_json_entry_remove_value( self );
    self->value.m_value_int32 = value;
    self->m_type = us_json_type_int32;
}

canonical_original_code:
void us_json_entry_set_value_int32(struct us_json_entry_s *self, int value)
{
    us_json_entry_remove_value( self );
    self->value.m_value_int32 = value;
    self->m_type = us_json_type_int32;
}

variable_types: value int


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

result = (*(__int64 (__fastcall **)(__int64, __int64, __int64))(a1 + 8))(a1, 40LL, 1LL);
if ( result )
{
*(_QWORD *)(result + 8) = a1;
*(_BYTE *)(result + 32) = 0;
*(_QWORD *)result = us_json_destroy;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
}
return result;
}

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

result = (*(__int64 (__fastcall **)(__int64, __int64, __int64))(a1 + 8))(a1, 40LL, 1LL);
if ( result )
{
*(_QWORD *)(result + 8) = a1;
*(_BYTE *)(result + 32) = 0;
*(_QWORD *)result = us_json_destroy;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
}
return result;
}

original_code:
us_json_t *us_json_create( us_allocator_t *allocator )
{
    us_json_t *self = ( us_json_t * )( ( allocator )->alloc( ( allocator ), (int32_t)sizeof( us_json_t ), 1 ) );
    if ( self )
    {
        self->m_allocator = allocator;
        self->m_is_array = 0;
        self->destroy = us_json_destroy;
        self->m_first_item = 0;
        self->m_last_item = 0;
    }
    return self;
}

canonical_original_code:
struct us_json_s *us_json_create(struct us_allocator_s *allocator)
{
    struct us_json_s *self = ( us_json_t * )( ( allocator )->alloc( ( allocator ), (int32_t)sizeof( us_json_t ), 1 ) );
    if ( self )
    {
        self->m_allocator = allocator;
        self->m_is_array = 0;
        self->destroy = us_json_destroy;
        self->m_first_item = 0;
        self->m_last_item = 0;
    }
    return self;
}

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


decompiled_code:
__int64 __fastcall us_json_append_object(__int64 a1, __int64 a2)
{
__int64 *v2; // rbp
__int64 v3; // rbx
__int64 v4; // rax

v2 = (__int64 *)us_json_entry_create(*(_QWORD *)(a1 + 8), a2);
v3 = (__int64)v2;
if ( v2 )
{
v4 = us_json_create(*(_QWORD *)(a1 + 8));
v3 = v4;
if ( v4 )
us_json_entry_set_value_json((__int64)v2, v4);
}
if ( !us_json_append_entry(a1, v2) )
v3 = 0LL;
return v3;
}

original_code:
us_json_t *us_json_append_object( us_json_t *self, const char *key )
{
    us_json_t *j = 0;
    us_json_entry_t *entry = us_json_entry_create( self->m_allocator, key );
    if ( entry )
    {
        j = us_json_create( self->m_allocator );
        if ( j )
        {
            us_json_entry_set_value_json( entry, j );
        }
    }
    if ( !us_json_append_entry( self, entry ) )
    {
        j = 0;
    }
    return j;
}

canonical_original_code:
struct us_json_s *us_json_append_object(struct us_json_s *self, char *key)
{
    struct us_json_s *j = 0;
    struct us_json_entry_s *entry = us_json_entry_create( self->m_allocator, key );
    if ( entry )
    {
        j = us_json_create( self->m_allocator );
        if ( j )
        {
            us_json_entry_set_value_json( entry, j );
        }
    }
    if ( !us_json_append_entry( self, entry ) )
    {
        j = 0;
    }
    return j;
}

variable_types:
self
struct us_json_s *

variable_types:
key
char *


decompiled_code:
__int64 __fastcall us_json_flatten_to_buffer(__int64 a1, __int64 a2)
{
__int64 v3; // rbx
void *v4; // rsi
void *v5; // rsi

v3 = *(_QWORD *)(a1 + 16);
v4 = &unk_572;
if ( !*(_BYTE *)(a1 + 32) )
v4 = &unk_575;
us_buffer_append_string(a2, v4);
for ( ; v3; v3 = *(_QWORD *)(v3 + 32) )
{
us_json_entry_flatten_to_buffer(v3, a2);
if ( !*(_QWORD *)(v3 + 32) )
break;
us_buffer_append_string(a2, &unk_580);
}
v5 = &unk_578;
if ( !*(_BYTE *)(a1 + 32) )
v5 = &unk_57C;
us_buffer_append_string(a2, v5);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2)
{
__int64 v3; // rbx
void *v4; // rsi
void *v5; // rsi

v3 = *(_QWORD *)(a1 + 16);
v4 = &unk_572;
if ( !*(_BYTE *)(a1 + 32) )
v4 = &unk_575;
us_buffer_append_string(a2, v4);
for ( ; v3; v3 = *(_QWORD *)(v3 + 32) )
{
func17(v3, a2);
if ( !*(_QWORD *)(v3 + 32) )
break;
us_buffer_append_string(a2, &unk_580);
}
v5 = &unk_578;
if ( !*(_BYTE *)(a1 + 32) )
v5 = &unk_57C;
us_buffer_append_string(a2, v5);
return 1LL;
}

original_code:
_Bool us_json_flatten_to_buffer( const us_json_t *self, us_buffer_t *buffer )
{
    _Bool r = 1;
    us_json_entry_t *entry = self->m_first_item;
    us_buffer_append_string( buffer, self->m_is_array ? "[ " : "{ " );
    while ( entry )
    {
        us_json_entry_flatten_to_buffer( entry, buffer );
        if ( entry->m_next )
        {
            us_buffer_append_string( buffer, ",\n" );
        }
        entry = entry->m_next;
    }
    us_buffer_append_string( buffer, self->m_is_array ? " ]\n" : " }\n" );
    return r;
}

canonical_original_code:
_Bool us_json_flatten_to_buffer(struct us_json_s *self, struct us_buffer_s *buffer)
{
    _Bool r = 1;
    struct us_json_entry_s *entry = self->m_first_item;
    us_buffer_append_string( buffer, self->m_is_array ? "[ " : "{ " );
    while ( entry )
    {
        us_json_entry_flatten_to_buffer( entry, buffer );
        if ( entry->m_next )
        {
            us_buffer_append_string( buffer, ",\n" );
        }
        entry = entry->m_next;
    }
    us_buffer_append_string( buffer, self->m_is_array ? " ]\n" : " }\n" );
    return r;
}

variable_types:
buffer
struct us_buffer_s *


decompiled_code:
__int64 __fastcall us_json_entry_flatten_to_buffer(__int64 a1, _QWORD *a2)
{
int v2; // ebx
int v3; // ebx
int v4; // ebx
__int64 result; // rax
int v6; // er13
int v7; // ebx
int v8; // er13
int v9; // ebx
char v10[72]; // [rsp+0h] [rbp-48h] BYREF

v2 = 1;
if ( *(_QWORD *)(a1 + 8) )
{
v3 = us_buffer_append_string(a2, &unk_583);
v4 = us_buffer_append_string(a2, *(_QWORD *)(a1 + 8)) & v3;
v2 = us_buffer_append_string(a2, "\" : ") & v4;
}
switch ( *(_DWORD *)(a1 + 24) )
{
case 0:
result = v2 & (unsigned int)us_buffer_append_string(a2, "null");
break;
case 1:
result = v2 & (unsigned int)us_json_flatten_to_buffer(*(_QWORD *)(a1 + 16), (__int64)a2);
break;
case 2:
v6 = us_buffer_append_string(a2, &unk_583);
v7 = v6 & us_buffer_append_string(a2, *(_QWORD *)(a1 + 16)) & v2;
result = v7 & (unsigned int)us_buffer_append_string(a2, &unk_583);
break;
case 3:
snprintf(v10, 0x20uLL, "%d", **(unsigned int **)(a1 + 16));
v2 &= us_buffer_append_string(a2, v10);
goto LABEL_8;
case 4:
v8 = us_buffer_append_string(a2, &unk_583);
v9 = v8 & us_buffer_write_buffer(a2, *(_QWORD **)(a1 + 16)) & v2;
result = v9 & (unsigned int)us_buffer_append_string(a2, &unk_583);
break;
case 5:
LABEL_8:
snprintf(v10, 0x20uLL, "%d", *(unsigned int *)(a1 + 16));
result = v2 & (unsigned int)us_buffer_append_string(a2, v10);
break;
default:
result = 0LL;
if ( us_log_level > 0 )
{
us_log_error_proc("invalid json entry type");
result = 0LL;
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, _QWORD *a2)
{
int v2; // ebx
int v3; // ebx
int v4; // ebx
__int64 result; // rax
int v6; // er13
int v7; // ebx
int v8; // er13
int v9; // ebx
char v10[72]; // [rsp+0h] [rbp-48h] BYREF

v2 = 1;
if ( *(_QWORD *)(a1 + 8) )
{
v3 = us_buffer_append_string(a2, &unk_583);
v4 = us_buffer_append_string(a2, *(_QWORD *)(a1 + 8)) & v3;
v2 = us_buffer_append_string(a2, "\" : ") & v4;
}
switch ( *(_DWORD *)(a1 + 24) )
{
case 0:
result = v2 & (unsigned int)us_buffer_append_string(a2, "null");
break;
case 1:
result = v2 & (unsigned int)func16(*(_QWORD *)(a1 + 16), (__int64)a2);
break;
case 2:
v6 = us_buffer_append_string(a2, &unk_583);
v7 = v6 & us_buffer_append_string(a2, *(_QWORD *)(a1 + 16)) & v2;
result = v7 & (unsigned int)us_buffer_append_string(a2, &unk_583);
break;
case 3:
snprintf(v10, 0x20uLL, "%d", **(unsigned int **)(a1 + 16));
v2 &= us_buffer_append_string(a2, v10);
goto LABEL_8;
case 4:
v8 = us_buffer_append_string(a2, &unk_583);
v9 = v8 & func4(a2, *(_QWORD **)(a1 + 16)) & v2;
result = v9 & (unsigned int)us_buffer_append_string(a2, &unk_583);
break;
case 5:
LABEL_8:
snprintf(v10, 0x20uLL, "%d", *(unsigned int *)(a1 + 16));
result = v2 & (unsigned int)us_buffer_append_string(a2, v10);
break;
default:
result = 0LL;
if ( us_log_level > 0 )
{
us_log_error_proc("invalid json entry type");
result = 0LL;
}
break;
}
return result;
}

original_code:
_Bool us_json_entry_flatten_to_buffer( const us_json_entry_t *self, us_buffer_t *buffer )
{
    _Bool r = 1;
    if ( self->m_key )
    {
        r &= us_buffer_append_string( buffer, "\"" );
        r &= us_buffer_append_string( buffer, self->m_key );
        r &= us_buffer_append_string( buffer, "\" : " );
    }
    switch ( self->m_type )
    {
    case us_json_type_none:
        r &= us_buffer_append_string( buffer, "null" );
        break;
    case us_json_type_json:
        r &= us_json_flatten_to_buffer( self->value.m_value_json, buffer );
        break;
    case us_json_type_string_ptr:
        r &= us_buffer_append_string( buffer, "\"" );
        r &= us_buffer_append_string( buffer, self->value.m_value_string_ptr );
        r &= us_buffer_append_string( buffer, "\"" );
        break;
    case us_json_type_int32_ptr:
    {
        char s[32];
        snprintf( s, sizeof( s ), "%d", *self->value.m_value_int32_ptr );
        r &= us_buffer_append_string( buffer, s );
    }
    case us_json_type_int32:
    {
        char s[32];
        snprintf( s, sizeof( s ), "%d", self->value.m_value_int32 );
        r &= us_buffer_append_string( buffer, s );
    }
    break;
    case us_json_type_string_buffer:
        r &= us_buffer_append_string( buffer, "\"" );
        r &= us_buffer_write_buffer( buffer, self->value.m_value_string_buffer );
        r &= us_buffer_append_string( buffer, "\"" );
        break;
    default:
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "invalid json entry type" ); } while ( 0 );
        r = 0;
        break;
    }
    return r;
}

canonical_original_code:
_Bool us_json_entry_flatten_to_buffer(struct us_json_entry_s *self, struct us_buffer_s *buffer)
{
    _Bool r = 1;
    if ( self->m_key )
    {
        r &= us_buffer_append_string( buffer, "\"" );
        r &= us_buffer_append_string( buffer, self->m_key );
        r &= us_buffer_append_string( buffer, "\" : " );
    }
    switch ( self->m_type )
    {
    case us_json_type_none:
        r &= us_buffer_append_string( buffer, "null" );
        break;
    case us_json_type_json:
        r &= us_json_flatten_to_buffer( self->value.m_value_json, buffer );
        break;
    case us_json_type_string_ptr:
        r &= us_buffer_append_string( buffer, "\"" );
        r &= us_buffer_append_string( buffer, self->value.m_value_string_ptr );
        r &= us_buffer_append_string( buffer, "\"" );
        break;
    case us_json_type_int32_ptr:
    {
        char s[32];
        snprintf( s, sizeof( s ), "%d", *self->value.m_value_int32_ptr );
        r &= us_buffer_append_string( buffer, s );
    }
    case us_json_type_int32:
    {
        char s[32];
        snprintf( s, sizeof( s ), "%d", self->value.m_value_int32 );
        r &= us_buffer_append_string( buffer, s );
    }
    break;
    case us_json_type_string_buffer:
        r &= us_buffer_append_string( buffer, "\"" );
        r &= us_buffer_write_buffer( buffer, self->value.m_value_string_buffer );
        r &= us_buffer_append_string( buffer, "\"" );
        break;
    default:
        do { if ( us_log_level >= ( 1 ) ) us_log_error_proc( "invalid json entry type" ); } while ( 0 );
        r = 0;
        break;
    }
    return r;
}

variable_types:
s
char [32]


decompiled_code:
__int64 __fastcall us_parse_hexdig(_BYTE *a1, __int64 a2, unsigned __int64 a3, unsigned __int64 *a4)
{
unsigned __int64 v6; // rax
unsigned int v7; // edx
char v8; // dl
char v10; // al

v6 = *a4;
v7 = 0;
if ( *a4 < a3 )
{
v8 = *(_BYTE *)(a2 + v6);
*a4 = v6 + 1;
if ( (unsigned __int8)(v8 - 48) > 9u )
{
v10 = v8 & 0xDF;
v7 = 0;
if ( (unsigned __int8)(v10 - 65) <= 5u )
{
*a1 = v10 - 55;
v7 = 1;
}
}
else
{
*a1 = v8 - 48;
v7 = 1;
}
}
return v7;
}

original_code:
_Bool us_parse_hexdig( uint8_t *val, const char *buf, size_t buf_len, size_t *buf_pos )
{
    _Bool r = 0;
    if ( *buf_pos < buf_len )
    {
        char c = buf[*buf_pos];
        ++( *buf_pos );
        if ( c >= '0' && c <= '9' )
        {
            *val = c - '0';
            r = 1;
        }
        else
        {
            c = c & 0xdf;
            if ( c >= 'A' && c <= 'F' )
            {
                *val = c - 'A' + 10;
                r = 1;
            }
        }
    }
    return r;
}

canonical_original_code:
_Bool us_parse_hexdig(unsigned char *val, char *buf, unsigned long buf_len, unsigned long *buf_pos)
{
    _Bool r = 0;
    if ( *buf_pos < buf_len )
    {
        char c = buf[*buf_pos];
        ++( *buf_pos );
        if ( c >= '0' && c <= '9' )
        {
            *val = c - '0';
            r = 1;
        }
        else
        {
            c = c & 0xdf;
            if ( c >= 'A' && c <= 'F' )
            {
                *val = c - 'A' + 10;
                r = 1;
            }
        }
    }
    return r;
}

variable_types:
val
unsigned char *

variable_types:
buf
char *

variable_types: c char


decompiled_code:
char __fastcall us_parse_hexoctet(_BYTE *a1, __int64 a2, unsigned __int64 a3, unsigned __int64 *a4)
{
char v6; // bl
char result; // al
char v8; // [rsp+Eh] [rbp-2Ah] BYREF
char v9[41]; // [rsp+Fh] [rbp-29h] BYREF

v9[0] = 0;
v8 = 0;
v6 = us_parse_hexdig(v9, a2, a3, a4);
result = v6 & us_parse_hexdig(&v8, a2, a3, a4);
if ( result )
*a1 = v8 + 16 * v9[0];
return result;
}

canonical_decompiled_code:
char __fastcall func1(_BYTE *a1, __int64 a2, unsigned __int64 a3, unsigned __int64 *a4)
{
char v6; // bl
char result; // al
char v8; // [rsp+Eh] [rbp-2Ah] BYREF
char v9[41]; // [rsp+Fh] [rbp-29h] BYREF

v9[0] = 0;
v8 = 0;
v6 = func0(v9, a2, a3, a4);
result = v6 & func0(&v8, a2, a3, a4);
if ( result )
*a1 = v8 + 16 * v9[0];
return result;
}

original_code:
_Bool us_parse_hexoctet( uint8_t *val, const char *buf, size_t buf_len, size_t *buf_pos )
{
    _Bool r = 1;
    uint8_t high = 0;
    uint8_t low = 0;
    r &= us_parse_hexdig( &high, buf, buf_len, buf_pos );
    r &= us_parse_hexdig( &low, buf, buf_len, buf_pos );
    if ( r )
    {
        *val = ( high << 4 ) + low;
    }
    return r;
}

canonical_original_code:
_Bool us_parse_hexoctet(unsigned char *val, char *buf, unsigned long buf_len, unsigned long *buf_pos)
{
    _Bool r = 1;
    unsigned char high = 0;
    unsigned char low = 0;
    r &= us_parse_hexdig( &high, buf, buf_len, buf_pos );
    r &= us_parse_hexdig( &low, buf, buf_len, buf_pos );
    if ( r )
    {
        *val = ( high << 4 ) + low;
    }
    return r;
}

variable_types:
high
unsigned char

variable_types:
low
unsigned char


decompiled_code:
int us_logger_stdio_finish()
{
int result; // eax

if ( us_logger_stdio_files )
{
if ( us_logger_stdio_out )
{
fflush(us_logger_stdio_out);
result = fclose(us_logger_stdio_out);
us_logger_stdio_out = 0LL;
}
if ( us_logger_stdio_err )
{
fflush(us_logger_stdio_err);
result = fclose(us_logger_stdio_err);
us_logger_stdio_err = 0LL;
}
}
us_log_error_proc = &us_log_null;
us_log_warn_proc = &us_log_null;
us_log_info_proc = &us_log_null;
us_log_debug_proc = &us_log_null;
us_logger_finish = &us_logger_null_finish;
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

if ( us_logger_stdio_files )
{
if ( us_logger_stdio_out )
{
fflush(us_logger_stdio_out);
result = fclose(us_logger_stdio_out);
us_logger_stdio_out = 0LL;
}
if ( us_logger_stdio_err )
{
fflush(us_logger_stdio_err);
result = fclose(us_logger_stdio_err);
us_logger_stdio_err = 0LL;
}
}
us_log_error_proc = &us_log_null;
us_log_warn_proc = &us_log_null;
us_log_info_proc = &us_log_null;
us_log_debug_proc = &us_log_null;
us_logger_finish = &us_logger_null_finish;
return result;
}

original_code:
void us_logger_stdio_finish( void )
{
    if ( us_logger_stdio_files )
    {
        if ( us_logger_stdio_out )
        {
            fflush( us_logger_stdio_out );
            fclose( us_logger_stdio_out );
            us_logger_stdio_out = 0;
        }
        if ( us_logger_stdio_err )
        {
            fflush( us_logger_stdio_err );
            fclose( us_logger_stdio_err );
            us_logger_stdio_err = 0;
        }
    }
    us_log_error_proc = us_log_null;
    us_log_warn_proc = us_log_null;
    us_log_info_proc = us_log_null;
    us_log_debug_proc = us_log_null;
    us_logger_finish = us_logger_null_finish;
}

canonical_original_code:
void us_logger_stdio_finish()
{
    if ( us_logger_stdio_files )
    {
        if ( us_logger_stdio_out )
        {
            fflush( us_logger_stdio_out );
            fclose( us_logger_stdio_out );
            us_logger_stdio_out = 0;
        }
        if ( us_logger_stdio_err )
        {
            fflush( us_logger_stdio_err );
            fclose( us_logger_stdio_err );
            us_logger_stdio_err = 0;
        }
    }
    us_log_error_proc = us_log_null;
    us_log_warn_proc = us_log_null;
    us_log_info_proc = us_log_null;
    us_log_debug_proc = us_log_null;
    us_logger_finish = us_logger_null_finish;
}


decompiled_code:
int us_log_error_stdio(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
__int64 v3[2]; // [rsp+20h] [rbp-C8h] BYREF

va_start(arg, format);
us_gettimeofday(v3);
fprintf(stderr, "ERROR (@%ld.%ld):\t", v3[0], v3[1]);
vfprintf(stderr, format, arg);
fputc(10, stderr);
return fflush(stderr);
}

canonical_decompiled_code:
int func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
__int64 v3[2]; // [rsp+20h] [rbp-C8h] BYREF

va_start(arg, format);
us_gettimeofday(v3);
fprintf(stderr, "ERROR (@%ld.%ld):\t", v3[0], v3[1]);
vfprintf(stderr, format, arg);
fputc(10, stderr);
return fflush(stderr);
}

original_code:
void us_log_error_stdio( const char *fmt, ... )
{
    struct timeval tv;
    va_list ap;
    __builtin_va_start(ap,fmt);
    us_gettimeofday( &tv );
    fprintf( stderr, "ERROR (@%ld.%ld):\t", (long)tv.tv_sec, (long)tv.tv_usec );
    vfprintf( stderr, fmt, ap );
    fprintf( stderr, "\n" );
    __builtin_va_end(ap);
    fflush( stderr );
}

canonical_original_code:
void us_log_error_stdio(char *fmt, ...)
{
    struct timeval tv;
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    us_gettimeofday( &tv );
    fprintf( stderr, "ERROR (@%ld.%ld):\t", (long)tv.tv_sec, (long)tv.tv_usec );
    vfprintf( stderr, fmt, ap );
    fprintf( stderr, "\n" );
    __builtin_va_end(ap);
    fflush( stderr );
}

variable_types:
fmt
char *

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


decompiled_code:
int us_log_warn_stdio(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
__int64 v3[2]; // [rsp+20h] [rbp-C8h] BYREF

va_start(arg, format);
us_gettimeofday(v3);
fprintf(stderr, "WARNING (@%ld.%ld):\t", v3[0], v3[1]);
vfprintf(stderr, format, arg);
fputc(10, stderr);
return fflush(stderr);
}

canonical_decompiled_code:
int func2(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
__int64 v3[2]; // [rsp+20h] [rbp-C8h] BYREF

va_start(arg, format);
us_gettimeofday(v3);
fprintf(stderr, "WARNING (@%ld.%ld):\t", v3[0], v3[1]);
vfprintf(stderr, format, arg);
fputc(10, stderr);
return fflush(stderr);
}

original_code:
void us_log_warn_stdio( const char *fmt, ... )
{
    struct timeval tv;
    va_list ap;
    __builtin_va_start(ap,fmt);
    us_gettimeofday( &tv );
    fprintf( stderr, "WARNING (@%ld.%ld):\t", (long)tv.tv_sec, (long)tv.tv_usec );
    vfprintf( stderr, fmt, ap );
    fprintf( stderr, "\n" );
    __builtin_va_end(ap);
    fflush( stderr );
}

canonical_original_code:
void us_log_warn_stdio(char *fmt, ...)
{
    struct timeval tv;
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    us_gettimeofday( &tv );
    fprintf( stderr, "WARNING (@%ld.%ld):\t", (long)tv.tv_sec, (long)tv.tv_usec );
    vfprintf( stderr, fmt, ap );
    fprintf( stderr, "\n" );
    __builtin_va_end(ap);
    fflush( stderr );
}

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
int us_log_info_stdio(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
__int64 v3[2]; // [rsp+20h] [rbp-C8h] BYREF

va_start(arg, format);
us_gettimeofday(v3);
fprintf(stderr, "INFO (@%ld.%ld):\t", v3[0], v3[1]);
vfprintf(stdout, format, arg);
fputc(10, stdout);
return fflush(stdout);
}

canonical_decompiled_code:
int func3(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
__int64 v3[2]; // [rsp+20h] [rbp-C8h] BYREF

va_start(arg, format);
us_gettimeofday(v3);
fprintf(stderr, "INFO (@%ld.%ld):\t", v3[0], v3[1]);
vfprintf(stdout, format, arg);
fputc(10, stdout);
return fflush(stdout);
}

original_code:
void us_log_info_stdio( const char *fmt, ... )
{
    struct timeval tv;
    va_list ap;
    __builtin_va_start(ap,fmt);
    us_gettimeofday( &tv );
    fprintf( stderr, "INFO (@%ld.%ld):\t", (long)tv.tv_sec, (long)tv.tv_usec );
    vfprintf( stdout, fmt, ap );
    fprintf( stdout, "\n" );
    __builtin_va_end(ap);
    fflush( stdout );
}

canonical_original_code:
void us_log_info_stdio(char *fmt, ...)
{
    struct timeval tv;
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    us_gettimeofday( &tv );
    fprintf( stderr, "INFO (@%ld.%ld):\t", (long)tv.tv_sec, (long)tv.tv_usec );
    vfprintf( stdout, fmt, ap );
    fprintf( stdout, "\n" );
    __builtin_va_end(ap);
    fflush( stdout );
}


decompiled_code:
int us_log_debug_stdio(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
__int64 v3[2]; // [rsp+20h] [rbp-C8h] BYREF

va_start(arg, format);
us_gettimeofday(v3);
fprintf(stderr, "DEBUG (@%ld.%ld):\t", v3[0], v3[1]);
vfprintf(stdout, format, arg);
fputc(10, stdout);
return fflush(stdout);
}

canonical_decompiled_code:
int func4(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
__int64 v3[2]; // [rsp+20h] [rbp-C8h] BYREF

va_start(arg, format);
us_gettimeofday(v3);
fprintf(stderr, "DEBUG (@%ld.%ld):\t", v3[0], v3[1]);
vfprintf(stdout, format, arg);
fputc(10, stdout);
return fflush(stdout);
}

original_code:
void us_log_debug_stdio( const char *fmt, ... )
{
    struct timeval tv;
    va_list ap;
    __builtin_va_start(ap,fmt);
    us_gettimeofday( &tv );
    fprintf( stderr, "DEBUG (@%ld.%ld):\t", (long)tv.tv_sec, (long)tv.tv_usec );
    vfprintf( stdout, fmt, ap );
    fprintf( stdout, "\n" );
    __builtin_va_end(ap);
    fflush( stdout );
}

canonical_original_code:
void us_log_debug_stdio(char *fmt, ...)
{
    struct timeval tv;
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    us_gettimeofday( &tv );
    fprintf( stderr, "DEBUG (@%ld.%ld):\t", (long)tv.tv_sec, (long)tv.tv_usec );
    vfprintf( stdout, fmt, ap );
    fprintf( stdout, "\n" );
    __builtin_va_end(ap);
    fflush( stdout );
}


decompiled_code:
int us_log_trace_stdio(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
__int64 v3[2]; // [rsp+20h] [rbp-C8h] BYREF

va_start(arg, format);
us_gettimeofday(v3);
fprintf(stderr, "TRACE (@%ld.%ld):\t", v3[0], v3[1]);
vfprintf(stdout, format, arg);
fputc(10, stdout);
return fflush(stdout);
}

canonical_decompiled_code:
int func5(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF
__int64 v3[2]; // [rsp+20h] [rbp-C8h] BYREF

va_start(arg, format);
us_gettimeofday(v3);
fprintf(stderr, "TRACE (@%ld.%ld):\t", v3[0], v3[1]);
vfprintf(stdout, format, arg);
fputc(10, stdout);
return fflush(stdout);
}

original_code:
void us_log_trace_stdio( const char *fmt, ... )
{
    struct timeval tv;
    va_list ap;
    __builtin_va_start(ap,fmt);
    us_gettimeofday( &tv );
    fprintf( stderr, "TRACE (@%ld.%ld):\t", (long)tv.tv_sec, (long)tv.tv_usec );
    vfprintf( stdout, fmt, ap );
    fprintf( stdout, "\n" );
    __builtin_va_end(ap);
    fflush( stdout );
}

canonical_original_code:
void us_log_trace_stdio(char *fmt, ...)
{
    struct timeval tv;
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    us_gettimeofday( &tv );
    fprintf( stderr, "TRACE (@%ld.%ld):\t", (long)tv.tv_sec, (long)tv.tv_usec );
    vfprintf( stdout, fmt, ap );
    fprintf( stdout, "\n" );
    __builtin_va_end(ap);
    fflush( stdout );
}


decompiled_code:
__int64 __fastcall us_logger_init_stdio_files(const char *a1, const char *a2)
{
us_logger_stdio_out = fopen(a1, "at");
if ( us_logger_stdio_out )
{
us_logger_stdio_err = fopen(a2, "at");
if ( us_logger_stdio_err )
{
us_logger_stdio_files = 1;
us_log_error_proc = us_log_error_stdio;
us_log_warn_proc = us_log_warn_stdio;
us_log_info_proc = us_log_info_stdio;
us_log_debug_proc = us_log_debug_stdio;
us_logger_finish = us_logger_stdio_finish;
}
else
{
fclose(us_logger_stdio_out);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, const char *a2)
{
us_logger_stdio_out = fopen(a1, "at");
if ( us_logger_stdio_out )
{
us_logger_stdio_err = fopen(a2, "at");
if ( us_logger_stdio_err )
{
us_logger_stdio_files = 1;
us_log_error_proc = us_log_error_stdio;
us_log_warn_proc = us_log_warn_stdio;
us_log_info_proc = us_log_info_stdio;
us_log_debug_proc = us_log_debug_stdio;
us_logger_finish = us_logger_stdio_finish;
}
else
{
fclose(us_logger_stdio_out);
}
}
return 0LL;
}

original_code:
_Bool us_logger_init_stdio_files( const char *outfilename, const char *errfilename )
{
    _Bool r = 0;
    us_logger_stdio_out = fopen( outfilename, "at" );
    if ( us_logger_stdio_out )
    {
        us_logger_stdio_err = fopen( errfilename, "at" );
        if ( us_logger_stdio_err )
        {
            us_logger_stdio_files = 1;
            us_log_error_proc = us_log_error_stdio;
            us_log_warn_proc = us_log_warn_stdio;
            us_log_info_proc = us_log_info_stdio;
            us_log_debug_proc = us_log_debug_stdio;
            us_logger_finish = us_logger_stdio_finish;
        }
        else
        {
            fclose( us_logger_stdio_out );
        }
    }
    return r;
}

canonical_original_code:
_Bool us_logger_init_stdio_files(char *outfilename, char *errfilename)
{
    _Bool r = 0;
    us_logger_stdio_out = fopen( outfilename, "at" );
    if ( us_logger_stdio_out )
    {
        us_logger_stdio_err = fopen( errfilename, "at" );
        if ( us_logger_stdio_err )
        {
            us_logger_stdio_files = 1;
            us_log_error_proc = us_log_error_stdio;
            us_log_warn_proc = us_log_warn_stdio;
            us_log_info_proc = us_log_info_stdio;
            us_log_debug_proc = us_log_debug_stdio;
            us_logger_finish = us_logger_stdio_finish;
        }
        else
        {
            fclose( us_logger_stdio_out );
        }
    }
    return r;
}

variable_types:
outfilename
char *

variable_types:
errfilename
char *


decompiled_code:
__int64 __fastcall us_simple_allocator_print(__int64 a1, __int64 a2)
{
return (*(__int64 (**)(__int64, const char *, ...))(a2 + 8))(
a2,
"Allocator:\n current_position: %d\n raw_memory: 0x%08p\n raw_memory_length: 0x%08lx\n",
*(unsigned int *)(a1 + 44),
*(const void **)(a1 + 32),
*(unsigned int *)(a1 + 40));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return (*(__int64 (**)(__int64, const char *, ...))(a2 + 8))(
a2,
"Allocator:\n current_position: %d\n raw_memory: 0x%08p\n raw_memory_length: 0x%08lx\n",
*(unsigned int *)(a1 + 44),
*(const void **)(a1 + 32),
*(unsigned int *)(a1 + 40));
}

original_code:
_Bool us_simple_allocator_print( us_simple_allocator_t *self, us_print_t *printer )
{
    _Bool r = 1;
    r &= printer->printf( printer,
                          "Allocator:\n current_position: %d\n"
                          " raw_memory: 0x%08p\n"
                          " raw_memory_length: 0x%08lx\n",
                          self->m_current_position,
                          self->m_raw_memory,
                          self->m_raw_memory_length );
    return r;
}

canonical_original_code:
_Bool us_simple_allocator_print(struct us_simple_allocator_s *self, struct us_print_s *printer)
{
    _Bool r = 1;
    r &= printer->printf( printer,
                          "Allocator:\n current_position: %d\n"
                          " raw_memory: 0x%08p\n"
                          " raw_memory_length: 0x%08lx\n",
                          self->m_current_position,
                          self->m_raw_memory,
                          self->m_raw_memory_length );
    return r;
}

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

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

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


decompiled_code:
int print_indention()
{
unsigned __int64 v0; // rbx
int result; // eax

if ( s_Level )
{
v0 = 0LL;
do
{
result = printf("%s", " ");
++v0;
}
while ( s_Level > v0 );
}
return result;
}

canonical_decompiled_code:
int func0()
{
unsigned __int64 v0; // rbx
int result; // eax

if ( s_Level )
{
v0 = 0LL;
do
{
result = printf("%s", " ");
++v0;
}
while ( s_Level > v0 );
}
return result;
}

original_code:
static void print_indention()
{
    size_t i;
    for ( i = 0; i < s_Level; ++i )
    {
        printf ( "%s", s_pIndention );
    }
}

canonical_original_code:
static void print_indention()
{
    unsigned long i;
    for ( i = 0; i < s_Level; ++i )
    {
        printf ( "%s", s_pIndention );
    }
}

variable_types:
i
unsigned long


print

decompiled_code:
__int64 __fastcall print(__int64 a1, int a2, const char **a3)
{
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();
s_IsKey = 0;
printf("integer: %lld\n", *a3);
break;
case 6:
if ( !s_IsKey )
print_indention();
s_IsKey = 0;
printf("float: %f\n", *(double *)a3);
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();
s_IsKey = 0;
printf("string: '%s'\n", *a3);
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)
{
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();
s_IsKey = 0;
printf("integer: %lld\n", *a3);
break;
case 6:
if ( !s_IsKey )
func0();
s_IsKey = 0;
printf("float: %f\n", *(double *)a3);
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();
s_IsKey = 0;
printf("string: '%s'\n", *a3);
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; } *


decompiled_code:
__int64 us_testutil_start()
{
__int64 result; // rax
__int64 v1; // rbx
__int64 v2; // rbp
int v3; // esi
__int64 v4; // rax
__int64 v5; // 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);
us_testutil_session_allocator = v1;
v2 = us_testutil_sys_allocator;
us_testutil_printer_stdout = us_print_file_init(&us_testutil_printer_stdout_impl, stdout);
v3 = (int)stderr;
v4 = us_print_file_init(&us_testutil_printer_stderr_impl, stderr);
v5 = v4;
us_testutil_printer_stderr = v4;
if ( v4 && us_testutil_printer_stdout )
{
LOBYTE(v4) = v1 == 0;
LOBYTE(v3) = v2 == 0;
result = (v3 | (unsigned int)v4) ^ 1;
}
else
{
result = 0LL;
}
us_stdout = us_testutil_printer_stdout;
us_stderr = v5;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // rbx
__int64 v2; // rbp
int v3; // esi
__int64 v4; // rax
__int64 v5; // 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);
us_testutil_session_allocator = v1;
v2 = us_testutil_sys_allocator;
us_testutil_printer_stdout = us_print_file_init(&us_testutil_printer_stdout_impl, stdout);
v3 = (int)stderr;
v4 = us_print_file_init(&us_testutil_printer_stderr_impl, stderr);
v5 = v4;
us_testutil_printer_stderr = v4;
if ( v4 && us_testutil_printer_stdout )
{
LOBYTE(v4) = v1 == 0;
LOBYTE(v3) = v2 == 0;
result = (v3 | (unsigned int)v4) ^ 1;
}
else
{
result = 0LL;
}
us_stdout = us_testutil_printer_stdout;
us_stderr = v5;
}
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

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

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

if ( us_testutil_sys_allocator )
(*(void (__fastcall **)(__int64))us_testutil_sys_allocator)(us_testutil_sys_allocator);
result = us_testutil_session_allocator;
if ( us_testutil_session_allocator )
result = (*(__int64 (__fastcall **)(__int64))us_testutil_session_allocator)(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 );
    }
}


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


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


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

va_start(arg, a2);
result = 0LL;
if ( a1 )
{
v4 = *(_DWORD *)(a1 + 36);
v5 = *(_DWORD *)(a1 + 32) - v4;
if ( v5 > 0 )
{
v6 = vsnprintf((char *)(*(_QWORD *)(a1 + 24) + v4), v5, a2, arg);
result = 0LL;
if ( v5 > v6 )
{
*(_DWORD *)(a1 + 36) += v6;
result = 1LL;
}
}
}
return result;
}

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

va_start(arg, a2);
result = 0LL;
if ( a1 )
{
v4 = *(_DWORD *)(a1 + 36);
v5 = *(_DWORD *)(a1 + 32) - v4;
if ( v5 > 0 )
{
v6 = vsnprintf((char *)(*(_QWORD *)(a1 + 24) + v4), v5, a2, arg);
result = 0LL;
if ( v5 > v6 )
{
*(_DWORD *)(a1 + 36) += v6;
result = 1LL;
}
}
}
return result;
}

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 result; // rax
int v5; // edi
int v6; // ebp
int v7; // edx

result = 0LL;
if ( a1 )
{
v5 = *(_DWORD *)(a1 + 36);
v6 = *(_DWORD *)(a1 + 32) - v5;
if ( v6 > 0 )
{
v7 = vsnprintf((char *)(*(_QWORD *)(a1 + 24) + v5), v6, a2, a3);
result = 0LL;
if ( v6 > v7 )
{
*(_DWORD *)(a1 + 36) += v7;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2, void *a3)
{
__int64 result; // rax
int v5; // edi
int v6; // ebp
int v7; // edx

result = 0LL;
if ( a1 )
{
v5 = *(_DWORD *)(a1 + 36);
v6 = *(_DWORD *)(a1 + 32) - v5;
if ( v6 > 0 )
{
v7 = vsnprintf((char *)(*(_QWORD *)(a1 + 24) + v5), v6, a2, a3);
result = 0LL;
if ( v6 > v7 )
{
*(_DWORD *)(a1 + 36) += v7;
result = 1LL;
}
}
}
return result;
}

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