decompiled_code:
__int64 __fastcall csv_decode_feed(char *s, __int64 a2)
{
int v3; // er12
__int64 v4; // rbx
char *v5; // rbp
char *v6; // rax
const char *v7; // r15
__int64 result; // rax

v3 = 0;
v4 = a2 + 40;
do
{
*(_QWORD *)(v4 - 8) = 0LL;
*(_QWORD *)(v4 + 48) = 0LL;
*(_OWORD *)v4 = 0LL;
*(_OWORD *)(v4 + 16) = 0LL;
*(_OWORD *)(v4 + 32) = 0LL;
v5 = strchr(s, 10);
v6 = strchr(s, 44);
v7 = v6 + 1;
if ( !v6
|| (unsigned int)xi_str_copy_untiln(v4 - 24, 16LL, s, 44LL) > 0xF
|| !csv_decode_datapoint(v7, v4)
|| (++v3, *(_QWORD *)(v4 - 8) = 1LL, s = v5 + 1, v3 == 16) )
{
xi_set_err(16LL);
return 0LL;
}
v4 += 920LL;
}
while ( v5 );
result = a2;
*(_QWORD *)(a2 + 8) = v3;
return result;
}

original_code:
xi_feed_t* csv_decode_feed(
      const char* buffer
    , xi_feed_t* feed )
{
    const char* current = buffer;
    int32_t counter = 0;
    char* end_of_line = ( char* ) 1;
    while( end_of_line )
    {
        xi_datastream_t* d = &feed->datastreams[ counter ];
        d->datapoint_count = 0;
        xi_datapoint_t* p = &d->datapoints[ 0 ];
        memset( p, 0, sizeof( xi_datapoint_t ) );
        end_of_line = strstr( current, "\n" );
        const char* end_of_datastream_id = strstr( current, "," );
        const char* beg_of_datapoint = end_of_datastream_id + 1;
        if( ((beg_of_datapoint) == 0) ) { xi_set_err( ((XI_CSV_DECODE_FEED_PARSER_ERROR)) ); goto err_handling; };
        if( ((end_of_datastream_id) == 0) ) { xi_set_err( ((XI_CSV_DECODE_FEED_PARSER_ERROR)) ); goto err_handling; };
        int size = sizeof( d->datastream_id );
        int s = xi_str_copy_untiln( d->datastream_id, size
            , current, ',' );
        if( (((s) >= (size) || (s) < 0 )) ) { xi_set_err( (XI_CSV_DECODE_FEED_PARSER_ERROR) ); goto err_handling; };
        xi_datapoint_t* ret = csv_decode_datapoint( beg_of_datapoint, p );
        if( ((ret) == 0) ) { xi_set_err( ((XI_CSV_DECODE_FEED_PARSER_ERROR)) ); goto err_handling; }
        d->datapoint_count = 1;
        current = end_of_line + 1;
        if( (++counter == 16) ) { xi_set_err( (XI_CSV_DECODE_FEED_PARSER_ERROR) ); goto err_handling; };
    }
    feed->datastream_count = counter;
    return feed;
err_handling:
    return 0;
}

canonical_original_code:
struct xi_feed_t *csv_decode_feed(char *buffer, struct xi_feed_t *feed)
{
    char *current = buffer;
    int counter = 0;
    char *end_of_line = ( char* ) 1;
    while( end_of_line )
    {
        struct xi_datastream_t *d = &feed->datastreams[ counter ];
        d->datapoint_count = 0;
        struct xi_datapoint_t *p = &d->datapoints[ 0 ];
        memset( p, 0, sizeof( xi_datapoint_t ) );
        end_of_line = strstr( current, "\n" );
        char *end_of_datastream_id = strstr( current, "," );
        char *beg_of_datapoint = end_of_datastream_id + 1;
        if( ((beg_of_datapoint) == 0) ) { xi_set_err( ((XI_CSV_DECODE_FEED_PARSER_ERROR)) ); goto err_handling; };
        if( ((end_of_datastream_id) == 0) ) { xi_set_err( ((XI_CSV_DECODE_FEED_PARSER_ERROR)) ); goto err_handling; };
        int size = sizeof( d->datastream_id );
        int s = xi_str_copy_untiln( d->datastream_id, size
            , current, ',' );
        if( (((s) >= (size) || (s) < 0 )) ) { xi_set_err( (XI_CSV_DECODE_FEED_PARSER_ERROR) ); goto err_handling; };
        struct xi_datapoint_t *ret = csv_decode_datapoint( beg_of_datapoint, p );
        if( ((ret) == 0) ) { xi_set_err( ((XI_CSV_DECODE_FEED_PARSER_ERROR)) ); goto err_handling; }
        d->datapoint_count = 1;
        current = end_of_line + 1;
        if( (++counter == 16) ) { xi_set_err( (XI_CSV_DECODE_FEED_PARSER_ERROR) ); goto err_handling; };
    }
    feed->datastream_count = counter;
    return feed;
err_handling:
    return 0;
}

variable_types:
buffer
char *

variable_types:
feed
struct xi_feed_t *

variable_types:
current
char *

variable_types: counter int

variable_types: struct xi_datastream_t { char datastream_id[16]; unsigned long datapoint_count; struct xi_datapoint_t { union xi_datapoint_value_t { int i32_value; float f32_value; char str_value[32]; } value; enum xi_value_type_t { XI_VALUE_TYPE_I32=0, XI_VALUE_TYPE_F32=1, XI_VALUE_TYPE_STR=2, XI_VALUE_TYPE_COUNT=3 } value_type; struct xi_timestamp_t { long timestamp; long micro; } timestamp; } datapoints[16]; } *

variable_types: struct xi_datapoint_t { union xi_datapoint_value_t { int i32_value; float f32_value; char str_value[32]; } value; enum xi_value_type_t { XI_VALUE_TYPE_I32=0, XI_VALUE_TYPE_F32=1, XI_VALUE_TYPE_STR=2, XI_VALUE_TYPE_COUNT=3 } value_type; struct xi_timestamp_t { long timestamp; long micro; } timestamp; } *

return_type: struct xi_feed_t { int feed_id; unsigned long datastream_count; struct xi_datastream_t { char datastream_id[16]; unsigned long datapoint_count; struct xi_datapoint_t { union xi_datapoint_value_t { int i32_value; float f32_value; char str_value[32]; } value; enum xi_value_type_t { XI_VALUE_TYPE_I32=0, XI_VALUE_TYPE_F32=1, XI_VALUE_TYPE_STR=2, XI_VALUE_TYPE_COUNT=3 } value_type; struct xi_timestamp_t { long timestamp; long micro; } timestamp; } datapoints[16]; } datastreams[16]; } *

user_defined_types: struct xi_datastream_t { char datastream_id[16]; unsigned long datapoint_count; struct xi_datapoint_t datapoints[16]; }

user_defined_types: struct xi_feed_t { int feed_id; unsigned long datastream_count; struct xi_datastream_t datastreams[16]; }


decompiled_code:
void __fastcall xi_set_err(int a1)
{
xi_err = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
xi_err = a1;
}

original_code:
void xi_set_err( xi_err_t e )
{
    xi_err = e;
}

canonical_original_code:
void xi_set_err(enum xi_err_t e)
{
    xi_err = e;
}

variable_types: enum xi_err_t { XI_NO_ERR=0, XI_OUT_OF_MEMORY=1, XI_HTTP_STATUS_PARSE_ERROR=2, XI_HTTP_HEADER_PARSE_ERROR=3, XI_HTTP_PARSE_ERROR=4, XI_HTTP_ENCODE_CREATE_DATASTREAM=5, XI_HTTP_ENCODE_UPDATE_DATASTREAM=6, XI_HTTP_ENCODE_GET_DATASTREAM=7, XI_HTTP_ENCODE_DELETE_DATASTREAM=8, XI_HTTP_ENCODE_DELETE_DATAPOINT=9, XI_HTTP_ENCODE_DELETE_RANGE_DATAPOINT=10, XI_HTTP_ENCODE_UPDATE_FEED=11, XI_HTTP_CONSTRUCT_REQUEST_BUFFER_OVERRUN=12, XI_HTTP_CONSTRUCT_CONTENT_BUFFER_OVERRUN=13, XI_CSV_ENCODE_DATAPOINT_BUFFER_OVERRUN=14, XI_CSV_ENCODE_DATASTREAM_BUFFER_OVERRUN=15, XI_CSV_DECODE_FEED_PARSER_ERROR=16, XI_CSV_DECODE_DATAPOINT_PARSER_ERROR=17, XI_CSV_TIME_CONVERTION_ERROR=18, XI_SOCKET_INITIALIZATION_ERROR=19, XI_SOCKET_GETHOSTBYNAME_ERROR=20, XI_SOCKET_CONNECTION_ERROR=21, XI_SOCKET_SHUTDOWN_ERROR=22, XI_SOCKET_WRITE_ERROR=23, XI_SOCKET_READ_ERROR=24, XI_SOCKET_CLOSE_ERROR=25, XI_DATAPOINT_VALUE_BUFFER_OVERFLOW=26, XI_ERR_COUNT=27 }

return_type: void


decompiled_code:
void xi_get_last_error()
{
xi_set_err(0);
}

canonical_decompiled_code:
void func1()
{
func0(0);
}

original_code:
xi_err_t xi_get_last_error()
{
    xi_err_t ret = xi_err;
    xi_set_err( XI_NO_ERR );
    return ret;
}

canonical_original_code:
enum xi_err_t xi_get_last_error()
{
    enum xi_err_t ret = xi_err;
    xi_set_err( XI_NO_ERR );
    return ret;
}

return_type: enum xi_err_t { XI_NO_ERR=0, XI_OUT_OF_MEMORY=1, XI_HTTP_STATUS_PARSE_ERROR=2, XI_HTTP_HEADER_PARSE_ERROR=3, XI_HTTP_PARSE_ERROR=4, XI_HTTP_ENCODE_CREATE_DATASTREAM=5, XI_HTTP_ENCODE_UPDATE_DATASTREAM=6, XI_HTTP_ENCODE_GET_DATASTREAM=7, XI_HTTP_ENCODE_DELETE_DATASTREAM=8, XI_HTTP_ENCODE_DELETE_DATAPOINT=9, XI_HTTP_ENCODE_DELETE_RANGE_DATAPOINT=10, XI_HTTP_ENCODE_UPDATE_FEED=11, XI_HTTP_CONSTRUCT_REQUEST_BUFFER_OVERRUN=12, XI_HTTP_CONSTRUCT_CONTENT_BUFFER_OVERRUN=13, XI_CSV_ENCODE_DATAPOINT_BUFFER_OVERRUN=14, XI_CSV_ENCODE_DATASTREAM_BUFFER_OVERRUN=15, XI_CSV_DECODE_FEED_PARSER_ERROR=16, XI_CSV_DECODE_DATAPOINT_PARSER_ERROR=17, XI_CSV_TIME_CONVERTION_ERROR=18, XI_SOCKET_INITIALIZATION_ERROR=19, XI_SOCKET_GETHOSTBYNAME_ERROR=20, XI_SOCKET_CONNECTION_ERROR=21, XI_SOCKET_SHUTDOWN_ERROR=22, XI_SOCKET_WRITE_ERROR=23, XI_SOCKET_READ_ERROR=24, XI_SOCKET_CLOSE_ERROR=25, XI_DATAPOINT_VALUE_BUFFER_OVERFLOW=26, XI_ERR_COUNT=27 }


decompiled_code:
char *__fastcall xi_get_error_string(__int16 a1)
{
if ( a1 < 0 )
a1 = 0;
if ( a1 > 26 )
a1 = 26;
return (&xi_err_string)[a1];
}

canonical_decompiled_code:
char *__fastcall func2(__int16 a1)
{
if ( a1 < 0 )
a1 = 0;
if ( a1 > 26 )
a1 = 26;
return (&xi_err_string)[a1];
}

original_code:
const char* xi_get_error_string( xi_err_t e )
{
    return xi_err_string[ (((( short ) e))<((0))?((0)):((( short ) e)))<((XI_ERR_COUNT - 1))?(((( short ) e))<((0))?((0)):((( short ) e))):((XI_ERR_COUNT - 1)) ];
}

canonical_original_code:
char *xi_get_error_string(enum xi_err_t e)
{
    return xi_err_string[ (((( short ) e))<((0))?((0)):((( short ) e)))<((XI_ERR_COUNT - 1))?(((( short ) e))<((0))?((0)):((( short ) e))):((XI_ERR_COUNT - 1)) ];
}

return_type: char *

user_defined_types: enum xi_err_t { XI_NO_ERR=0, XI_OUT_OF_MEMORY=1, XI_HTTP_STATUS_PARSE_ERROR=2, XI_HTTP_HEADER_PARSE_ERROR=3, XI_HTTP_PARSE_ERROR=4, XI_HTTP_ENCODE_CREATE_DATASTREAM=5, XI_HTTP_ENCODE_UPDATE_DATASTREAM=6, XI_HTTP_ENCODE_GET_DATASTREAM=7, XI_HTTP_ENCODE_DELETE_DATASTREAM=8, XI_HTTP_ENCODE_DELETE_DATAPOINT=9, XI_HTTP_ENCODE_DELETE_RANGE_DATAPOINT=10, XI_HTTP_ENCODE_UPDATE_FEED=11, XI_HTTP_CONSTRUCT_REQUEST_BUFFER_OVERRUN=12, XI_HTTP_CONSTRUCT_CONTENT_BUFFER_OVERRUN=13, XI_CSV_ENCODE_DATAPOINT_BUFFER_OVERRUN=14, XI_CSV_ENCODE_DATASTREAM_BUFFER_OVERRUN=15, XI_CSV_DECODE_FEED_PARSER_ERROR=16, XI_CSV_DECODE_DATAPOINT_PARSER_ERROR=17, XI_CSV_TIME_CONVERTION_ERROR=18, XI_SOCKET_INITIALIZATION_ERROR=19, XI_SOCKET_GETHOSTBYNAME_ERROR=20, XI_SOCKET_CONNECTION_ERROR=21, XI_SOCKET_SHUTDOWN_ERROR=22, XI_SOCKET_WRITE_ERROR=23, XI_SOCKET_READ_ERROR=24, XI_SOCKET_CLOSE_ERROR=25, XI_DATAPOINT_VALUE_BUFFER_OVERFLOW=26, XI_ERR_COUNT=27 }


decompiled_code:
int __fastcall http_construct_string(char *a1, __int64 a2, const char *a3)
{
int result; // eax

if ( !a2 )
_assert_fail("buffer_size != 0", "http_layer_queries.c", 0x29u, "http_construct_string");
result = 0;
if ( a3 )
{
result = snprintf(a1, (int)a2, "/%s", a3);
if ( result >= (int)a2 || result < 0 )
{
xi_set_err(12LL);
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *a1, __int64 a2, const char *a3)
{
int result; // eax

if ( !a2 )
_assert_fail("buffer_size != 0", "http_layer_queries.c", 0x29u, "http_construct_string");
result = 0;
if ( a3 )
{
result = snprintf(a1, (int)a2, "/%s", a3);
if ( result >= (int)a2 || result < 0 )
{
xi_set_err(12LL);
result = -1;
}
}
return result;
}

original_code:
inline static int http_construct_string(
      char* buffer, size_t buffer_size
    , const char* string_id )
{
    ((void) sizeof ((buffer != 0) ? 1 : 0), __extension__ ({ if (buffer != 0) ; else __assert_fail ("buffer != 0", "http_layer_queries.c", 40, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((buffer_size != 0) ? 1 : 0), __extension__ ({ if (buffer_size != 0) ; else __assert_fail ("buffer_size != 0", "http_layer_queries.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    int s = 0;
    int size = buffer_size;
    if( string_id )
    {
        s = snprintf( buffer, size
            , XI_HTTP_ID_TEMPLATE, string_id );
        if( (((s) >= (size) || (s) < 0 )) ) { xi_set_err( (XI_HTTP_CONSTRUCT_REQUEST_BUFFER_OVERRUN) ); goto err_handling; };
    }
    return s;
err_handling:
    return -1;
}

canonical_original_code:
inline static int http_construct_string(char *buffer, unsigned long buffer_size, char *string_id)
{
    ((void) sizeof ((buffer != 0) ? 1 : 0), __extension__ ({ if (buffer != 0) ; else __assert_fail ("buffer != 0", "http_layer_queries.c", 40, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((buffer_size != 0) ? 1 : 0), __extension__ ({ if (buffer_size != 0) ; else __assert_fail ("buffer_size != 0", "http_layer_queries.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    int s = 0;
    int size = buffer_size;
    if( string_id )
    {
        s = snprintf( buffer, size
            , XI_HTTP_ID_TEMPLATE, string_id );
        if( (((s) >= (size) || (s) < 0 )) ) { xi_set_err( (XI_HTTP_CONSTRUCT_REQUEST_BUFFER_OVERRUN) ); goto err_handling; };
    }
    return s;
err_handling:
    return -1;
}

variable_types: s int

variable_types: size int

return_type: int


decompiled_code:
char *__fastcall http_construct_request_datapoint(const char *a1, unsigned int *a2, const char *a3, const char *a4, const char *a5)
{
if ( !a1 )
_assert_fail("http_method != 0", "http_layer_queries.c", 0xC9u, "http_construct_request_datapoint");
if ( !a2 )
_assert_fail("feed_id != 0", "http_layer_queries.c", 0xCAu, "http_construct_request_datapoint");
if ( !a3 )
_assert_fail("datastream != 0", "http_layer_queries.c", 0xCBu, "http_construct_request_datapoint");
if ( !a5 )
_assert_fail("x_api_key != 0", "http_layer_queries.c", 0xCCu, "http_construct_request_datapoint");
if ( (unsigned int)http_construct_datapoint_constprop_0(a2, a3, a4) <= 0xFF )
return http_construct_http_query_constprop_0(a1, 0LL, a5);
xi_set_err(13LL);
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func6(const char *a1, unsigned int *a2, const char *a3, const char *a4, const char *a5)
{
if ( !a1 )
_assert_fail("http_method != 0", "http_layer_queries.c", 0xC9u, "http_construct_request_datapoint");
if ( !a2 )
_assert_fail("feed_id != 0", "http_layer_queries.c", 0xCAu, "http_construct_request_datapoint");
if ( !a3 )
_assert_fail("datastream != 0", "http_layer_queries.c", 0xCBu, "http_construct_request_datapoint");
if ( !a5 )
_assert_fail("x_api_key != 0", "http_layer_queries.c", 0xCCu, "http_construct_request_datapoint");
if ( (unsigned int)func5(a2, a3, a4) <= 0xFF )
return func1(a1, 0LL, a5);
xi_set_err(13LL);
return 0LL;
}

original_code:
const char* http_construct_request_datapoint(
          const char* http_method
        , const int32_t* feed_id
        , const char* datastream
        , const char* datapoint
        , const char* x_api_key )
{
    ((void) sizeof ((http_method != 0) ? 1 : 0), __extension__ ({ if (http_method != 0) ; else __assert_fail ("http_method != 0", "http_layer_queries.c", 201, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((feed_id != 0) ? 1 : 0), __extension__ ({ if (feed_id != 0) ; else __assert_fail ("feed_id != 0", "http_layer_queries.c", 202, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((datastream != 0) ? 1 : 0), __extension__ ({ if (datastream != 0) ; else __assert_fail ("datastream != 0", "http_layer_queries.c", 203, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((x_api_key != 0) ? 1 : 0), __extension__ ({ if (x_api_key != 0) ; else __assert_fail ("x_api_key != 0", "http_layer_queries.c", 204, __extension__ __PRETTY_FUNCTION__); }));
    int s = http_construct_datapoint( XI_ID_BUFFER, 256
        , feed_id, datastream, datapoint );
    if( (((s) >= (256) || (s) < 0 )) ) { xi_set_err( (XI_HTTP_CONSTRUCT_CONTENT_BUFFER_OVERRUN) ); goto err_handling; };
    return http_construct_http_query( http_method, XI_ID_BUFFER, 0, x_api_key );
err_handling:
    return 0;
}

canonical_original_code:
char *http_construct_request_datapoint(char *http_method, int *feed_id, char *datastream, char *datapoint, char *x_api_key)
{
    ((void) sizeof ((http_method != 0) ? 1 : 0), __extension__ ({ if (http_method != 0) ; else __assert_fail ("http_method != 0", "http_layer_queries.c", 201, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((feed_id != 0) ? 1 : 0), __extension__ ({ if (feed_id != 0) ; else __assert_fail ("feed_id != 0", "http_layer_queries.c", 202, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((datastream != 0) ? 1 : 0), __extension__ ({ if (datastream != 0) ; else __assert_fail ("datastream != 0", "http_layer_queries.c", 203, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((x_api_key != 0) ? 1 : 0), __extension__ ({ if (x_api_key != 0) ; else __assert_fail ("x_api_key != 0", "http_layer_queries.c", 204, __extension__ __PRETTY_FUNCTION__); }));
    int s = http_construct_datapoint( XI_ID_BUFFER, 256
        , feed_id, datastream, datapoint );
    if( (((s) >= (256) || (s) < 0 )) ) { xi_set_err( (XI_HTTP_CONSTRUCT_CONTENT_BUFFER_OVERRUN) ); goto err_handling; };
    return http_construct_http_query( http_method, XI_ID_BUFFER, 0, x_api_key );
err_handling:
    return 0;
}

variable_types:
datastream
char *

variable_types:
datapoint
char *


decompiled_code:
char *__fastcall http_construct_request_datastream(const char *a1, unsigned int *a2, const char *a3, const char *a4)
{
if ( !a1 )
_assert_fail("http_method != 0", "http_layer_queries.c", 0xE1u, "http_construct_request_datastream");
if ( !a2 )
_assert_fail("feed_id != 0", "http_layer_queries.c", 0xE2u, "http_construct_request_datastream");
if ( !a4 )
_assert_fail("x_api_key != 0", "http_layer_queries.c", 0xE3u, "http_construct_request_datastream");
if ( (unsigned int)http_construct_datastream_constprop_0(a2, a3) <= 0xFF )
return http_construct_http_query_constprop_0(a1, 0LL, a4);
xi_set_err(13LL);
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1, unsigned int *a2, const char *a3, const char *a4)
{
if ( !a1 )
_assert_fail("http_method != 0", "http_layer_queries.c", 0xE1u, "http_construct_request_datastream");
if ( !a2 )
_assert_fail("feed_id != 0", "http_layer_queries.c", 0xE2u, "http_construct_request_datastream");
if ( !a4 )
_assert_fail("x_api_key != 0", "http_layer_queries.c", 0xE3u, "http_construct_request_datastream");
if ( (unsigned int)func4(a2, a3) <= 0xFF )
return func1(a1, 0LL, a4);
xi_set_err(13LL);
return 0LL;
}

original_code:
const char* http_construct_request_datastream(
          const char* http_method
        , const int32_t* feed_id
        , const char* datastream
        , const char* x_api_key )
{
    ((void) sizeof ((http_method != 0) ? 1 : 0), __extension__ ({ if (http_method != 0) ; else __assert_fail ("http_method != 0", "http_layer_queries.c", 225, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((feed_id != 0) ? 1 : 0), __extension__ ({ if (feed_id != 0) ; else __assert_fail ("feed_id != 0", "http_layer_queries.c", 226, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((x_api_key != 0) ? 1 : 0), __extension__ ({ if (x_api_key != 0) ; else __assert_fail ("x_api_key != 0", "http_layer_queries.c", 227, __extension__ __PRETTY_FUNCTION__); }));
    int s = http_construct_datastream( XI_ID_BUFFER, 256
        , feed_id, datastream );
    if( (((s) >= (256) || (s) < 0 )) ) { xi_set_err( (XI_HTTP_CONSTRUCT_CONTENT_BUFFER_OVERRUN) ); goto err_handling; }
    return http_construct_http_query( http_method, XI_ID_BUFFER, 0, x_api_key );
err_handling:
    return 0;
}

canonical_original_code:
char *http_construct_request_datastream(char *http_method, int *feed_id, char *datastream, char *x_api_key)
{
    ((void) sizeof ((http_method != 0) ? 1 : 0), __extension__ ({ if (http_method != 0) ; else __assert_fail ("http_method != 0", "http_layer_queries.c", 225, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((feed_id != 0) ? 1 : 0), __extension__ ({ if (feed_id != 0) ; else __assert_fail ("feed_id != 0", "http_layer_queries.c", 226, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((x_api_key != 0) ? 1 : 0), __extension__ ({ if (x_api_key != 0) ; else __assert_fail ("x_api_key != 0", "http_layer_queries.c", 227, __extension__ __PRETTY_FUNCTION__); }));
    int s = http_construct_datastream( XI_ID_BUFFER, 256
        , feed_id, datastream );
    if( (((s) >= (256) || (s) < 0 )) ) { xi_set_err( (XI_HTTP_CONSTRUCT_CONTENT_BUFFER_OVERRUN) ); goto err_handling; }
    return http_construct_http_query( http_method, XI_ID_BUFFER, 0, x_api_key );
err_handling:
    return 0;
}


decompiled_code:
char *__fastcall http_construct_request_feed(const char *a1, unsigned int *a2, const char *a3, const char *a4)
{
if ( !a1 )
_assert_fail("http_method != 0", "http_layer_queries.c", 0xF8u, "http_construct_request_feed");
if ( !a3 )
_assert_fail("x_api_key != 0", "http_layer_queries.c", 0xF9u, "http_construct_request_feed");
if ( (unsigned int)http_construct_feed_constprop_0(a2) <= 0xFF )
return http_construct_http_query_constprop_0(a1, a4, a3);
xi_set_err(13LL);
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func8(const char *a1, unsigned int *a2, const char *a3, const char *a4)
{
if ( !a1 )
_assert_fail("http_method != 0", "http_layer_queries.c", 0xF8u, "http_construct_request_feed");
if ( !a3 )
_assert_fail("x_api_key != 0", "http_layer_queries.c", 0xF9u, "http_construct_request_feed");
if ( (unsigned int)func3(a2) <= 0xFF )
return func1(a1, a4, a3);
xi_set_err(13LL);
return 0LL;
}

original_code:
const char* http_construct_request_feed(
          const char* http_method
        , const int32_t* feed_id
        , const char* x_api_key
        , const char* query_suffix )
{
    ((void) sizeof ((http_method != 0) ? 1 : 0), __extension__ ({ if (http_method != 0) ; else __assert_fail ("http_method != 0", "http_layer_queries.c", 248, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((x_api_key != 0) ? 1 : 0), __extension__ ({ if (x_api_key != 0) ; else __assert_fail ("x_api_key != 0", "http_layer_queries.c", 249, __extension__ __PRETTY_FUNCTION__); }));
    int s = http_construct_feed( XI_ID_BUFFER, 256, feed_id );
    if( (((s) >= (256) || (s) < 0 )) ) { xi_set_err( (XI_HTTP_CONSTRUCT_CONTENT_BUFFER_OVERRUN) ); goto err_handling; };
    return http_construct_http_query( http_method, XI_ID_BUFFER, query_suffix, x_api_key );
err_handling:
    return 0;
}

canonical_original_code:
char *http_construct_request_feed(char *http_method, int *feed_id, char *x_api_key, char *query_suffix)
{
    ((void) sizeof ((http_method != 0) ? 1 : 0), __extension__ ({ if (http_method != 0) ; else __assert_fail ("http_method != 0", "http_layer_queries.c", 248, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((x_api_key != 0) ? 1 : 0), __extension__ ({ if (x_api_key != 0) ; else __assert_fail ("x_api_key != 0", "http_layer_queries.c", 249, __extension__ __PRETTY_FUNCTION__); }));
    int s = http_construct_feed( XI_ID_BUFFER, 256, feed_id );
    if( (((s) >= (256) || (s) < 0 )) ) { xi_set_err( (XI_HTTP_CONSTRUCT_CONTENT_BUFFER_OVERRUN) ); goto err_handling; };
    return http_construct_http_query( http_method, XI_ID_BUFFER, query_suffix, x_api_key );
err_handling:
    return 0;
}


decompiled_code:
char *__fastcall http_construct_content(unsigned int a1)
{
snprintf(XI_CONTENT_BUFFER, 0x100uLL, "Content-Type: text/plain\r\nContent-Length: %d\r\n", a1);
return XI_CONTENT_BUFFER;
}

canonical_decompiled_code:
char *__fastcall func9(unsigned int a1)
{
snprintf(XI_CONTENT_BUFFER, 0x100uLL, "Content-Type: text/plain\r\nContent-Length: %d\r\n", a1);
return XI_CONTENT_BUFFER;
}

original_code:
const char* http_construct_content(
          int32_t content_size )
{
    int s = snprintf( XI_CONTENT_BUFFER, 256
      , XI_HTTP_CONTENT_TEMPLATE, content_size );
    if( (((s) >= (256) || (s) < 0 )) ) { xi_set_err( (XI_HTTP_CONSTRUCT_CONTENT_BUFFER_OVERRUN) ); goto err_handling; };
    return XI_CONTENT_BUFFER;
err_handling:
    return 0;
}

canonical_original_code:
char *http_construct_content(int content_size)
{
    int s = snprintf( XI_CONTENT_BUFFER, 256
      , XI_HTTP_CONTENT_TEMPLATE, content_size );
    if( (((s) >= (256) || (s) < 0 )) ) { xi_set_err( (XI_HTTP_CONSTRUCT_CONTENT_BUFFER_OVERRUN) ); goto err_handling; };
    return XI_CONTENT_BUFFER;
err_handling:
    return 0;
}


decompiled_code:
void **get_comm_layer()
{
return &_posix_comm_layer_0;
}

canonical_decompiled_code:
void **func0()
{
return &_posix_comm_layer_0;
}

original_code:
const comm_layer_t* get_comm_layer()
{
    static comm_layer_t __posix_comm_layer =
    {
          &posix_open_connection
        , &posix_send_data
        , &posix_read_data
        , &posix_close_connection
    };
    return &__posix_comm_layer;
}

canonical_original_code:
struct comm_layer_t *get_comm_layer()
{
    static struct comm_layer_t __posix_comm_layer = {
          &posix_open_connection
        , &posix_send_data
        , &posix_read_data
        , &posix_close_connection
    };
    return &__posix_comm_layer;
}

return_type: struct comm_layer_t { struct connection_t { void *layer_specific; char *address; int port; unsigned long bytes_sent; unsigned long bytes_received; } *(*open_connection)(char *address, int port); int (*send_data)(struct connection_t *conn, char *data, unsigned long size); int (*read_data)(struct connection_t *conn, char *buffer, unsigned long buffer_size); void (*close_connection)(struct connection_t *conn); } *

user_defined_types: struct comm_layer_t { struct connection_t *(*open_connection)(char *address, int port); int (*send_data)(struct connection_t *conn, char *data, unsigned long size); int (*read_data)(struct connection_t *conn, char *buffer, unsigned long buffer_size); void (*close_connection)(struct connection_t *conn); }


decompiled_code:
__int64 __fastcall posix_open_connection(__int64 a1, int a2)
{
int *v2; // rbp
__int64 v3; // r12
__int64 v4; // rax
int v5; // eax
struct hostent *v6; // rax
char **v7; // rax
__int16 v8; // ax
int v9; // edi
socklen_t v10; // edx
__int64 result; // rax
__int64 v12; // rdi
struct sockaddr v13; // [rsp+0h] [rbp-38h] BYREF

if ( !a1 )
_assert_fail("address != 0", "comm_layers/posix/posix_comm.c", 0x20u, "posix_open_connection");
v2 = (int *)xi_alloc(4LL);
if ( v2 )
{
v3 = xi_alloc(40LL);
if ( v3 )
{
v4 = xi_str_dup(a1);
*(_DWORD *)(v3 + 16) = a2;
*(_QWORD *)(v3 + 8) = v4;
if ( v4 )
{
v5 = socket(2, 1, 0);
*v2 = v5;
if ( v5 == -1
|| (*(_QWORD *)&v13.sa_family = xi_globals / 0x3E8uLL,
*(_QWORD *)&v13.sa_data[6] = 1000 * (xi_globals % 0x3E8uLL),
setsockopt(v5, 1, 20, &v13, 0x10u) < 0)
|| setsockopt(*v2, 1, 21, &v13, 0x10u) < 0 )
{
xi_set_err(19LL);
result = 0LL;
}
else
{
*(_QWORD *)v3 = v2;
v6 = gethostbyname(*(const char **)(v3 + 8));
if ( v6 )
{
v13 = 0LL;
v7 = v6->h_addr_list;
v13.sa_family = 2;
*(_DWORD *)&v13.sa_data[2] = *(_DWORD *)*v7;
v8 = _bswap_16(a2);
v9 = *v2;
*(_WORD *)v13.sa_data = v8;
if ( connect(v9, &v13, v10) == -1 )
{
v3 = 0LL;
xi_set_err(21LL);
}
else if ( *v2 == -1 )
{
_assert_fail(
"pos_comm_data->socket_fd != -1",
"comm_layers/posix/posix_comm.c",
0x79u,
"posix_open_connection");
}
}
else
{
v3 = 0LL;
xi_set_err(20LL);
}
result = v3;
}
}
else
{
xi_set_err(1LL);
xi_free(v2);
v12 = *(_QWORD *)(v3 + 8);
if ( v12 )
{
xi_free(v12);
*(_QWORD *)(v3 + 8) = 0LL;
}
xi_free(v3);
result = 0LL;
}
}
else
{
xi_set_err(1LL);
xi_free(v2);
result = 0LL;
}
}
else
{
xi_set_err(1LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int *v2; // rbp
__int64 v3; // r12
__int64 v4; // rax
int v5; // eax
struct hostent *v6; // rax
char **v7; // rax
__int16 v8; // ax
int v9; // edi
socklen_t v10; // edx
__int64 result; // rax
__int64 v12; // rdi
struct sockaddr v13; // [rsp+0h] [rbp-38h] BYREF

if ( !a1 )
_assert_fail("address != 0", "comm_layers/posix/posix_comm.c", 0x20u, "posix_open_connection");
v2 = (int *)xi_alloc(4LL);
if ( v2 )
{
v3 = xi_alloc(40LL);
if ( v3 )
{
v4 = xi_str_dup(a1);
*(_DWORD *)(v3 + 16) = a2;
*(_QWORD *)(v3 + 8) = v4;
if ( v4 )
{
v5 = socket(2, 1, 0);
*v2 = v5;
if ( v5 == -1
|| (*(_QWORD *)&v13.sa_family = xi_globals / 0x3E8uLL,
*(_QWORD *)&v13.sa_data[6] = 1000 * (xi_globals % 0x3E8uLL),
setsockopt(v5, 1, 20, &v13, 0x10u) < 0)
|| setsockopt(*v2, 1, 21, &v13, 0x10u) < 0 )
{
xi_set_err(19LL);
result = 0LL;
}
else
{
*(_QWORD *)v3 = v2;
v6 = gethostbyname(*(const char **)(v3 + 8));
if ( v6 )
{
v13 = 0LL;
v7 = v6->h_addr_list;
v13.sa_family = 2;
*(_DWORD *)&v13.sa_data[2] = *(_DWORD *)*v7;
v8 = func0(a2);
v9 = *v2;
*(_WORD *)v13.sa_data = v8;
if ( connect(v9, &v13, v10) == -1 )
{
v3 = 0LL;
xi_set_err(21LL);
}
else if ( *v2 == -1 )
{
_assert_fail(
"pos_comm_data->socket_fd != -1",
"comm_layers/posix/posix_comm.c",
0x79u,
"posix_open_connection");
}
}
else
{
v3 = 0LL;
xi_set_err(20LL);
}
result = v3;
}
}
else
{
xi_set_err(1LL);
xi_free(v2);
v12 = *(_QWORD *)(v3 + 8);
if ( v12 )
{
xi_free(v12);
*(_QWORD *)(v3 + 8) = 0LL;
}
xi_free(v3);
result = 0LL;
}
}
else
{
xi_set_err(1LL);
xi_free(v2);
result = 0LL;
}
}
else
{
xi_set_err(1LL);
result = 0LL;
}
return result;
}

original_code:
connection_t* posix_open_connection( const char* address, int32_t port )
{
    ((void) sizeof ((address != 0) ? 1 : 0), __extension__ ({ if (address != 0) ; else __assert_fail ("address != 0", "comm_layers/posix/posix_comm.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    posix_comm_layer_data_specific_t* pos_comm_data = 0;
    connection_t* conn = 0;
    pos_comm_data
        = ( posix_comm_layer_data_specific_t* ) xi_alloc(
                sizeof( posix_comm_layer_data_specific_t ) );
    if( ((pos_comm_data) == 0) ) { xi_set_err( (XI_OUT_OF_MEMORY) ); goto err_handling; };
    conn
        = ( connection_t* ) xi_alloc(
                sizeof( connection_t ) );
    if( ((conn) == 0) ) { xi_set_err( (XI_OUT_OF_MEMORY) ); goto err_handling; };
    conn->address = xi_str_dup( address );
    conn->port = port;
    if( ((conn->address) == 0) ) { xi_set_err( (XI_OUT_OF_MEMORY) ); goto err_handling; };
    pos_comm_data->socket_fd = socket( 2, SOCK_STREAM, 0 );
    if( pos_comm_data->socket_fd == -1 )
    {
        xi_set_err( XI_SOCKET_INITIALIZATION_ERROR );
        return 0;
    }
    {
        struct timeval timeout;
        timeout.tv_sec = xi_globals.network_timeout / 1000;
        timeout.tv_usec = ( xi_globals.network_timeout - timeout.tv_sec * 1000 ) * 1000;
        if ( setsockopt( pos_comm_data->socket_fd, 1
                , 20, ( char * )&timeout,
                  sizeof( timeout ) ) < 0 )
        {
            xi_set_err( XI_SOCKET_INITIALIZATION_ERROR );
            return 0;
        }
        if ( setsockopt( pos_comm_data->socket_fd, 1
                , 21, ( char * )&timeout,
                  sizeof( timeout ) ) < 0 )
        {
            xi_set_err( XI_SOCKET_INITIALIZATION_ERROR );
            return 0;
        }
    }
    conn->layer_specific = ( void* ) pos_comm_data;
    struct sockaddr_in name;
    struct hostent* hostinfo;
    hostinfo = gethostbyname( conn->address );
    if( hostinfo == ((void *)0) )
    {
        xi_set_err( XI_SOCKET_GETHOSTBYNAME_ERROR );
        return 0;
    }
    memset( &name, 0, sizeof( struct sockaddr_in ) );
    name.sin_family = 2;
    name.sin_addr = *( ( struct in_addr* ) hostinfo->h_addr_list[0] );
    name.sin_port = htons( port );
    if( connect( pos_comm_data->socket_fd, ( struct sockaddr* ) &name, sizeof( struct sockaddr ) ) == -1 )
    {
        xi_set_err( XI_SOCKET_CONNECTION_ERROR );
        return 0;
    }
    ((void) sizeof ((conn != 0) ? 1 : 0), __extension__ ({ if (conn != 0) ; else __assert_fail ("conn != 0", "comm_layers/posix/posix_comm.c", 120, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((pos_comm_data->socket_fd != -1) ? 1 : 0), __extension__ ({ if (pos_comm_data->socket_fd != -1) ; else __assert_fail ("pos_comm_data->socket_fd != -1", "comm_layers/posix/posix_comm.c", 121, __extension__ __PRETTY_FUNCTION__); }));
    return conn;
err_handling:
    if( pos_comm_data ) { if( (pos_comm_data) ) { xi_free(pos_comm_data); (pos_comm_data) = 0; }; }
    if( conn ) { if( (conn->address) ) { xi_free(conn->address); (conn->address) = 0; }; }
    if( (conn) ) { xi_free(conn); (conn) = 0; };
    return 0;
}

canonical_original_code:
struct connection_t *posix_open_connection(char *address, int port)
{
    ((void) sizeof ((address != 0) ? 1 : 0), __extension__ ({ if (address != 0) ; else __assert_fail ("address != 0", "comm_layers/posix/posix_comm.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    struct posix_comm_layer_data_specific_t *pos_comm_data = 0;
    struct connection_t *conn = 0;
    pos_comm_data
        = ( struct posix_comm_layer_data_specific_t * ) xi_alloc(
                sizeof( posix_comm_layer_data_specific_t ) );
    if( ((pos_comm_data) == 0) ) { xi_set_err( (XI_OUT_OF_MEMORY) ); goto err_handling; };
    conn
        = ( struct connection_t * ) xi_alloc(
                sizeof( connection_t ) );
    if( ((conn) == 0) ) { xi_set_err( (XI_OUT_OF_MEMORY) ); goto err_handling; };
    conn->address = xi_str_dup( address );
    conn->port = port;
    if( ((conn->address) == 0) ) { xi_set_err( (XI_OUT_OF_MEMORY) ); goto err_handling; };
    pos_comm_data->socket_fd = socket( 2, SOCK_STREAM, 0 );
    if( pos_comm_data->socket_fd == -1 )
    {
        xi_set_err( XI_SOCKET_INITIALIZATION_ERROR );
        return 0;
    }
    {
        struct timeval timeout;
        timeout.tv_sec = xi_globals.network_timeout / 1000;
        timeout.tv_usec = ( xi_globals.network_timeout - timeout.tv_sec * 1000 ) * 1000;
        if ( setsockopt( pos_comm_data->socket_fd, 1
                , 20, ( char * )&timeout,
                  sizeof( timeout ) ) < 0 )
        {
            xi_set_err( XI_SOCKET_INITIALIZATION_ERROR );
            return 0;
        }
        if ( setsockopt( pos_comm_data->socket_fd, 1
                , 21, ( char * )&timeout,
                  sizeof( timeout ) ) < 0 )
        {
            xi_set_err( XI_SOCKET_INITIALIZATION_ERROR );
            return 0;
        }
    }
    conn->layer_specific = ( void * ) pos_comm_data;
    struct sockaddr_in name;
    struct hostent *hostinfo;
    hostinfo = gethostbyname( conn->address );
    if( hostinfo == ((void *)0) )
    {
        xi_set_err( XI_SOCKET_GETHOSTBYNAME_ERROR );
        return 0;
    }
    memset( &name, 0, sizeof( struct sockaddr_in ) );
    name.sin_family = 2;
    name.sin_addr = *( ( struct in_addr * ) hostinfo->h_addr_list[0] );
    name.sin_port = htons( port );
    if( connect( pos_comm_data->socket_fd, ( struct sockaddr * ) &name, sizeof( struct sockaddr ) ) == -1 )
    {
        xi_set_err( XI_SOCKET_CONNECTION_ERROR );
        return 0;
    }
    ((void) sizeof ((conn != 0) ? 1 : 0), __extension__ ({ if (conn != 0) ; else __assert_fail ("conn != 0", "comm_layers/posix/posix_comm.c", 120, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((pos_comm_data->socket_fd != -1) ? 1 : 0), __extension__ ({ if (pos_comm_data->socket_fd != -1) ; else __assert_fail ("pos_comm_data->socket_fd != -1", "comm_layers/posix/posix_comm.c", 121, __extension__ __PRETTY_FUNCTION__); }));
    return conn;
err_handling:
    if( pos_comm_data ) { if( (pos_comm_data) ) { xi_free(pos_comm_data); (pos_comm_data) = 0; }; }
    if( conn ) { if( (conn->address) ) { xi_free(conn->address); (conn->address) = 0; }; }
    if( (conn) ) { xi_free(conn); (conn) = 0; };
    return 0;
}

variable_types:
address
char *

variable_types: port int

variable_types: struct posix_comm_layer_data_specific_t { int socket_fd; } *

variable_types: struct connection_t { void *layer_specific; char *address; int port; unsigned long bytes_sent; unsigned long bytes_received; } *

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

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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


decompiled_code:
ssize_t __fastcall posix_send_data(__int64 a1, const void *a2, size_t a3)
{
ssize_t result; // rax
ssize_t v4; // [rsp+8h] [rbp-10h]

if ( !a1 )
_assert_fail("conn != 0", "comm_layers/posix/posix_comm.c", 0x89u, "posix_send_data");
if ( !*(_QWORD *)a1 )
_assert_fail("conn->layer_specific != 0", "comm_layers/posix/posix_comm.c", 0x8Au, "posix_send_data");
if ( !a2 )
_assert_fail("data != 0", "comm_layers/posix/posix_comm.c", 0x8Bu, "posix_send_data");
if ( !a3 )
_assert_fail("size != 0", "comm_layers/posix/posix_comm.c", 0x8Cu, "posix_send_data");
result = write(**(_DWORD **)a1, a2, a3);
if ( (_DWORD)result == -1 )
{
v4 = result;
xi_set_err(23LL);
result = v4;
*(_QWORD *)(a1 + 24) += (int)v4;
}
else
{
*(_QWORD *)(a1 + 24) += (int)result;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(__int64 a1, const void *a2, size_t a3)
{
ssize_t result; // rax
ssize_t v4; // [rsp+8h] [rbp-10h]

if ( !a1 )
_assert_fail("conn != 0", "comm_layers/posix/posix_comm.c", 0x89u, "posix_send_data");
if ( !*(_QWORD *)a1 )
_assert_fail("conn->layer_specific != 0", "comm_layers/posix/posix_comm.c", 0x8Au, "posix_send_data");
if ( !a2 )
_assert_fail("data != 0", "comm_layers/posix/posix_comm.c", 0x8Bu, "posix_send_data");
if ( !a3 )
_assert_fail("size != 0", "comm_layers/posix/posix_comm.c", 0x8Cu, "posix_send_data");
result = write(**(_DWORD **)a1, a2, a3);
if ( (_DWORD)result == -1 )
{
v4 = result;
xi_set_err(23LL);
result = v4;
*(_QWORD *)(a1 + 24) += (int)v4;
}
else
{
*(_QWORD *)(a1 + 24) += (int)result;
}
return result;
}

original_code:
int posix_send_data( connection_t* conn, const char* data, size_t size )
{
    ((void) sizeof ((conn != 0) ? 1 : 0), __extension__ ({ if (conn != 0) ; else __assert_fail ("conn != 0", "comm_layers/posix/posix_comm.c", 137, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((conn->layer_specific != 0) ? 1 : 0), __extension__ ({ if (conn->layer_specific != 0) ; else __assert_fail ("conn->layer_specific != 0", "comm_layers/posix/posix_comm.c", 138, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((data != 0) ? 1 : 0), __extension__ ({ if (data != 0) ; else __assert_fail ("data != 0", "comm_layers/posix/posix_comm.c", 139, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((size != 0) ? 1 : 0), __extension__ ({ if (size != 0) ; else __assert_fail ("size != 0", "comm_layers/posix/posix_comm.c", 140, __extension__ __PRETTY_FUNCTION__); }));
    posix_comm_layer_data_specific_t* pos_comm_data
        = ( posix_comm_layer_data_specific_t* ) conn->layer_specific;
    int bytes_written = write( pos_comm_data->socket_fd, data, size );
    if( bytes_written == - 1 )
    {
        xi_set_err( XI_SOCKET_WRITE_ERROR );
    }
    conn->bytes_sent += bytes_written;
    return bytes_written;
}

canonical_original_code:
int posix_send_data(struct connection_t *conn, char *data, unsigned long size)
{
    ((void) sizeof ((conn != 0) ? 1 : 0), __extension__ ({ if (conn != 0) ; else __assert_fail ("conn != 0", "comm_layers/posix/posix_comm.c", 137, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((conn->layer_specific != 0) ? 1 : 0), __extension__ ({ if (conn->layer_specific != 0) ; else __assert_fail ("conn->layer_specific != 0", "comm_layers/posix/posix_comm.c", 138, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((data != 0) ? 1 : 0), __extension__ ({ if (data != 0) ; else __assert_fail ("data != 0", "comm_layers/posix/posix_comm.c", 139, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((size != 0) ? 1 : 0), __extension__ ({ if (size != 0) ; else __assert_fail ("size != 0", "comm_layers/posix/posix_comm.c", 140, __extension__ __PRETTY_FUNCTION__); }));
    struct posix_comm_layer_data_specific_t *pos_comm_data = ( posix_comm_layer_data_specific_t* ) conn->layer_specific;
    int bytes_written = write( pos_comm_data->socket_fd, data, size );
    if( bytes_written == - 1 )
    {
        xi_set_err( XI_SOCKET_WRITE_ERROR );
    }
    conn->bytes_sent += bytes_written;
    return bytes_written;
}

variable_types:
data
char *

variable_types:
size
unsigned long

user_defined_types: struct connection_t { void *layer_specific; char *address; int port; unsigned long bytes_sent; unsigned long bytes_received; }

user_defined_types: struct posix_comm_layer_data_specific_t { int socket_fd; }


decompiled_code:
ssize_t __fastcall posix_read_data(__int64 a1, void *a2, size_t a3)
{
int *v3; // rbp
void *v5; // rax
ssize_t result; // rax
ssize_t v7; // [rsp+8h] [rbp-20h]

if ( !a1 )
_assert_fail("conn != 0", "comm_layers/posix/posix_comm.c", 0xA2u, "posix_read_data");
v3 = *(int **)a1;
if ( !*(_QWORD *)a1 )
_assert_fail("conn->layer_specific != 0", "comm_layers/posix/posix_comm.c", 0xA3u, "posix_read_data");
if ( !a2 )
_assert_fail("buffer != 0", "comm_layers/posix/posix_comm.c", 0xA4u, "posix_read_data");
if ( !a3 )
_assert_fail("buffer_size != 0", "comm_layers/posix/posix_comm.c", 0xA5u, "posix_read_data");
v5 = memset(a2, 0, a3);
result = read(*v3, v5, a3);
if ( (_DWORD)result == -1 )
{
v7 = result;
xi_set_err(24LL);
result = v7;
*(_QWORD *)(a1 + 32) += (int)v7;
}
else
{
*(_QWORD *)(a1 + 32) += (int)result;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(__int64 a1, void *a2, size_t a3)
{
int *v3; // rbp
void *v5; // rax
ssize_t result; // rax
ssize_t v7; // [rsp+8h] [rbp-20h]

if ( !a1 )
_assert_fail("conn != 0", "comm_layers/posix/posix_comm.c", 0xA2u, "posix_read_data");
v3 = *(int **)a1;
if ( !*(_QWORD *)a1 )
_assert_fail("conn->layer_specific != 0", "comm_layers/posix/posix_comm.c", 0xA3u, "posix_read_data");
if ( !a2 )
_assert_fail("buffer != 0", "comm_layers/posix/posix_comm.c", 0xA4u, "posix_read_data");
if ( !a3 )
_assert_fail("buffer_size != 0", "comm_layers/posix/posix_comm.c", 0xA5u, "posix_read_data");
v5 = memset(a2, 0, a3);
result = read(*v3, v5, a3);
if ( (_DWORD)result == -1 )
{
v7 = result;
xi_set_err(24LL);
result = v7;
*(_QWORD *)(a1 + 32) += (int)v7;
}
else
{
*(_QWORD *)(a1 + 32) += (int)result;
}
return result;
}

original_code:
int posix_read_data( connection_t* conn, char* buffer, size_t buffer_size )
{
    ((void) sizeof ((conn != 0) ? 1 : 0), __extension__ ({ if (conn != 0) ; else __assert_fail ("conn != 0", "comm_layers/posix/posix_comm.c", 162, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((conn->layer_specific != 0) ? 1 : 0), __extension__ ({ if (conn->layer_specific != 0) ; else __assert_fail ("conn->layer_specific != 0", "comm_layers/posix/posix_comm.c", 163, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((buffer != 0) ? 1 : 0), __extension__ ({ if (buffer != 0) ; else __assert_fail ("buffer != 0", "comm_layers/posix/posix_comm.c", 164, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((buffer_size != 0) ? 1 : 0), __extension__ ({ if (buffer_size != 0) ; else __assert_fail ("buffer_size != 0", "comm_layers/posix/posix_comm.c", 165, __extension__ __PRETTY_FUNCTION__); }));
    posix_comm_layer_data_specific_t* pos_comm_data
        = ( posix_comm_layer_data_specific_t* ) conn->layer_specific;
    memset( buffer, 0, buffer_size );
    int bytes_read = read( pos_comm_data->socket_fd, buffer, buffer_size );
    if( bytes_read == -1 )
    {
        xi_set_err( XI_SOCKET_READ_ERROR );
    }
    conn->bytes_received += bytes_read;
    return bytes_read;
}

canonical_original_code:
int posix_read_data(struct connection_t *conn, char *buffer, unsigned long buffer_size)
{
    ((void) sizeof ((conn != 0) ? 1 : 0), __extension__ ({ if (conn != 0) ; else __assert_fail ("conn != 0", "comm_layers/posix/posix_comm.c", 162, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((conn->layer_specific != 0) ? 1 : 0), __extension__ ({ if (conn->layer_specific != 0) ; else __assert_fail ("conn->layer_specific != 0", "comm_layers/posix/posix_comm.c", 163, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((buffer != 0) ? 1 : 0), __extension__ ({ if (buffer != 0) ; else __assert_fail ("buffer != 0", "comm_layers/posix/posix_comm.c", 164, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((buffer_size != 0) ? 1 : 0), __extension__ ({ if (buffer_size != 0) ; else __assert_fail ("buffer_size != 0", "comm_layers/posix/posix_comm.c", 165, __extension__ __PRETTY_FUNCTION__); }));
    struct posix_comm_layer_data_specific_t *pos_comm_data = ( posix_comm_layer_data_specific_t* ) conn->layer_specific;
    memset( buffer, 0, buffer_size );
    int bytes_read = read( pos_comm_data->socket_fd, buffer, buffer_size );
    if( bytes_read == -1 )
    {
        xi_set_err( XI_SOCKET_READ_ERROR );
    }
    conn->bytes_received += bytes_read;
    return bytes_read;
}

variable_types:
buffer
char *


decompiled_code:
__int64 __fastcall posix_close_connection(__int64 a1)
{
int *v1; // rbx
int *v3; // rdi
__int64 v4; // rdi

if ( !a1 )
_assert_fail("conn != 0", "comm_layers/posix/posix_comm.c", 0xBCu, "posix_close_connection");
v1 = *(int **)a1;
if ( shutdown(**(_DWORD **)a1, 2) == -1 )
{
xi_set_err(22LL);
close(*v1);
}
else if ( close(*v1) == -1 )
{
xi_set_err(25LL);
}
v3 = *(int **)a1;
if ( *(_QWORD *)a1 )
{
xi_free(v3);
*(_QWORD *)a1 = 0LL;
}
v4 = *(_QWORD *)(a1 + 8);
if ( v4 )
{
xi_free(v4);
*(_QWORD *)(a1 + 8) = 0LL;
}
return xi_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int *v1; // rbx
int *v3; // rdi
__int64 v4; // rdi

if ( !a1 )
_assert_fail("conn != 0", "comm_layers/posix/posix_comm.c", 0xBCu, "posix_close_connection");
v1 = *(int **)a1;
if ( shutdown(**(_DWORD **)a1, 2) == -1 )
{
xi_set_err(22LL);
close(*v1);
}
else if ( close(*v1) == -1 )
{
xi_set_err(25LL);
}
v3 = *(int **)a1;
if ( *(_QWORD *)a1 )
{
xi_free(v3);
*(_QWORD *)a1 = 0LL;
}
v4 = *(_QWORD *)(a1 + 8);
if ( v4 )
{
xi_free(v4);
*(_QWORD *)(a1 + 8) = 0LL;
}
return xi_free(a1);
}

original_code:
void posix_close_connection( connection_t* conn )
{
    ((void) sizeof ((conn != 0) ? 1 : 0), __extension__ ({ if (conn != 0) ; else __assert_fail ("conn != 0", "comm_layers/posix/posix_comm.c", 188, __extension__ __PRETTY_FUNCTION__); }));
    posix_comm_layer_data_specific_t* pos_comm_data
        = ( posix_comm_layer_data_specific_t* ) conn->layer_specific;
    if( shutdown( pos_comm_data->socket_fd, SHUT_RDWR ) == -1 )
    {
        xi_set_err( XI_SOCKET_SHUTDOWN_ERROR );
        close( pos_comm_data->socket_fd );
        goto err_handling;
    }
    if( close( pos_comm_data->socket_fd ) == -1 )
    {
        xi_set_err( XI_SOCKET_CLOSE_ERROR );
        goto err_handling;
    }
err_handling:
    if( conn ) { if( (conn->layer_specific) ) { xi_free(conn->layer_specific); (conn->layer_specific) = 0; }; }
    if( conn ) { if( (conn->address) ) { xi_free(conn->address); (conn->address) = 0; }; }
    if( (conn) ) { xi_free(conn); (conn) = 0; };
    return;
}

canonical_original_code:
void posix_close_connection(struct connection_t *conn)
{
    ((void) sizeof ((conn != 0) ? 1 : 0), __extension__ ({ if (conn != 0) ; else __assert_fail ("conn != 0", "comm_layers/posix/posix_comm.c", 188, __extension__ __PRETTY_FUNCTION__); }));
    struct posix_comm_layer_data_specific_t *pos_comm_data = ( posix_comm_layer_data_specific_t* ) conn->layer_specific;
    if( shutdown( pos_comm_data->socket_fd, SHUT_RDWR ) == -1 )
    {
        xi_set_err( XI_SOCKET_SHUTDOWN_ERROR );
        close( pos_comm_data->socket_fd );
        goto err_handling;
    }
    if( close( pos_comm_data->socket_fd ) == -1 )
    {
        xi_set_err( XI_SOCKET_CLOSE_ERROR );
        goto err_handling;
    }
err_handling:
    if( conn ) { if( (conn->layer_specific) ) { xi_free(conn->layer_specific); (conn->layer_specific) = 0; }; }
    if( conn ) { if( (conn->address) ) { xi_free(conn->address); (conn->address) = 0; }; }
    if( (conn) ) { xi_free(conn); (conn) = 0; };
    return;
}


decompiled_code:
__int64 __fastcall classify_header(char *s1)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcasecmp(s1, &XI_HTTP_TOKEN_NAMES[64 * v1]) )
{
if ( ++v1 == 6 )
return 9LL;
}
return (unsigned __int16)v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcasecmp(s1, &XI_HTTP_TOKEN_NAMES[64 * v1]) )
{
if ( ++v1 == 6 )
return 9LL;
}
return (unsigned __int16)v1;
}

original_code:
static inline http_header_type_t classify_header( const char* header )
{
    for( unsigned short i = 0; i < XI_HTTP_HEADER_COUNT - 1; ++i )
    {
        if( strcasecmp( header, XI_HTTP_TOKEN_NAMES[ i ] ) == 0 )
            return ( http_header_type_t ) i;
    }
    return XI_HTTP_HEADER_UNKNOWN;
}

canonical_original_code:
static inline enum http_header_type_t classify_header(char *header)
{
    for( unsigned short i = 0; i < XI_HTTP_HEADER_COUNT - 1; ++i )
    {
        if( strcasecmp( header, XI_HTTP_TOKEN_NAMES[ i ] ) == 0 )
            return ( enum http_header_type_t ) i;
    }
    return XI_HTTP_HEADER_UNKNOWN;
}

variable_types:
header
char *

variable_types:
i
unsigned short

return_type: enum http_header_type_t { XI_HTTP_HEADER_DATE=0, XI_HTTP_HEADER_CONTENT_TYPE=1, XI_HTTP_HEADER_CONTENT_LENGTH=2, XI_HTTP_HEADER_CONNECTION=3, XI_HTTP_HEADER_X_REQUEST_ID=4, XI_HTTP_HEADER_CACHE_CONTROL=5, XI_HTTP_HEADER_VARY=6, XI_HTTP_HEADER_COUNT=7, XI_HTTP_HEADER_AGE=8, XI_HTTP_HEADER_UNKNOWN=9, XI_HTTP_HEADERS_COUNT=10 }


decompiled_code:
char *__fastcall parse_http_status(__int64 a1, const char *a2)
{
char *v2; // rax
char *v3; // r12

v2 = strstr(a2, "\r\n");
if ( v2 )
{
v3 = v2 + 2;
if ( (unsigned int)_isoc99_sscanf(a2, "HTTP/%d.%d %d %32[^\r\n]\r\n", a1, a1 + 4, a1 + 8, a1 + 12) == 4 )
return v3;
}
xi_set_err(2LL);
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, const char *a2)
{
char *v2; // rax
char *v3; // r12

v2 = strstr(a2, "\r\n");
if ( v2 )
{
v3 = v2 + 2;
if ( (unsigned int)_isoc99_sscanf(a2, "HTTP/%d.%d %d %32[^\r\n]\r\n", a1, a1 + 4, a1 + 8, a1 + 12) == 4 )
return v3;
}
xi_set_err(2LL);
return 0LL;
}

original_code:
const char* parse_http_status( http_response_t* response, const char* content )
{
    int c = 0;
    const char* header_end_ptr = strstr( content, XI_HTTP_CRLF );
    if( ((header_end_ptr) == 0) ) { xi_set_err( ((XI_HTTP_STATUS_PARSE_ERROR)) ); goto err_handling; };
    header_end_ptr += 2;
    c = sscanf( content
        , XI_HTTP_STATUS_PATTERN, &response->http_version1, &response->http_version2, &response->http_status, response->http_status_string );
    if( (c != 4) ) { xi_set_err( (XI_HTTP_STATUS_PARSE_ERROR) ); goto err_handling; };
    return header_end_ptr;
err_handling:
    return 0;
}

canonical_original_code:
char *parse_http_status(struct http_response_t *response, char *content)
{
    int c = 0;
    char *header_end_ptr = strstr( content, XI_HTTP_CRLF );
    if( ((header_end_ptr) == 0) ) { xi_set_err( ((XI_HTTP_STATUS_PARSE_ERROR)) ); goto err_handling; };
    header_end_ptr += 2;
    c = sscanf( content
        , XI_HTTP_STATUS_PATTERN, &response->http_version1, &response->http_version2, &response->http_status, response->http_status_string );
    if( (c != 4) ) { xi_set_err( (XI_HTTP_STATUS_PARSE_ERROR) ); goto err_handling; };
    return header_end_ptr;
err_handling:
    return 0;
}

variable_types: struct http_response_t { int http_version1; int http_version2; int http_status; char http_status_string[32]; struct http_header_t { enum http_header_type_t { XI_HTTP_HEADER_DATE=0, XI_HTTP_HEADER_CONTENT_TYPE=1, XI_HTTP_HEADER_CONTENT_LENGTH=2, XI_HTTP_HEADER_CONNECTION=3, XI_HTTP_HEADER_X_REQUEST_ID=4, XI_HTTP_HEADER_CACHE_CONTROL=5, XI_HTTP_HEADER_VARY=6, XI_HTTP_HEADER_COUNT=7, XI_HTTP_HEADER_AGE=8, XI_HTTP_HEADER_UNKNOWN=9, XI_HTTP_HEADERS_COUNT=10 } header_type; char name[64]; char value[64]; } *http_headers_checklist[-1]; struct http_header_t http_headers[16]; unsigned long http_headers_size; char http_content[512]; } *

variable_types:
content
char *

variable_types: c int

user_defined_types: struct http_response_t { int http_version1; int http_version2; int http_status; char http_status_string[32]; struct http_header_t *http_headers_checklist[-1]; struct http_header_t http_headers[16]; unsigned long http_headers_size; char http_content[512]; }

user_defined_types: struct http_header_t { enum http_header_type_t header_type; char name[64]; char value[64]; }


original_code:
const char* parse_http_header( http_response_t* response
    , const char* content )
{
    const char* header_end_ptr = strstr( content, XI_HTTP_CRLF );
    const char* header_name_end_ptr = strstr( content, ":" );
    if( ((header_end_ptr) == 0) ) { xi_set_err( ((XI_HTTP_HEADER_PARSE_ERROR)) ); goto err_handling; };
    if( ((header_name_end_ptr) == 0) ) { xi_set_err( ((XI_HTTP_HEADER_PARSE_ERROR)) ); goto err_handling; };
    if( (header_name_end_ptr > header_end_ptr) ) { xi_set_err( (XI_HTTP_HEADER_PARSE_ERROR) ); goto err_handling; };
    {
        int size = sizeof( response->http_headers[ response->http_headers_size ].name );
        if( (header_name_end_ptr - content > size - 1) ) { xi_set_err( (XI_HTTP_HEADER_PARSE_ERROR) ); goto err_handling; };
        memcpy( response->http_headers[ response->http_headers_size ].name
            , content, (size - 1)<(header_name_end_ptr - content)?(size - 1):(header_name_end_ptr - content) );
        { (response->http_headers[ response->http_headers_size ].name)[ (size) - 1 ] = '\0'; };
    }
    header_name_end_ptr += 2;
    {
        int size = sizeof( response->http_headers[ response->http_headers_size ].value );
        if( (header_end_ptr - header_name_end_ptr > size - 1) ) { xi_set_err( (XI_HTTP_HEADER_PARSE_ERROR) ); goto err_handling; };
        memcpy( response->http_headers[ response->http_headers_size ].value
            , header_name_end_ptr, (size - 1)<(header_end_ptr - header_name_end_ptr)?(size - 1):(header_end_ptr - header_name_end_ptr) );
        { (response->http_headers[ response->http_headers_size ].value)[ (size) - 1 ] = '\0'; };
    }
    {
        http_header_type_t ht = classify_header(
            response->http_headers[ response->http_headers_size ].name );
        if( ht != XI_HTTP_HEADER_UNKNOWN )
        {
            response->http_headers_checklist[ ht ] =
                &response->http_headers[ response->http_headers_size ];
        }
        response->http_headers[ response->http_headers_size ].header_type = ht;
        response->http_headers_size += 1;
        if( (response->http_headers_size >= 16) ) { xi_set_err( (XI_HTTP_HEADER_PARSE_ERROR) ); goto err_handling; };
        header_end_ptr += sizeof( XI_HTTP_CRLF ) - 1;
    }
    return header_end_ptr;
err_handling:
    return 0;
}

canonical_original_code:
char *parse_http_header(struct http_response_t *response, char *content)
{
    char *header_end_ptr = strstr( content, XI_HTTP_CRLF );
    char *header_name_end_ptr = strstr( content, ":" );
    if( ((header_end_ptr) == 0) ) { xi_set_err( ((XI_HTTP_HEADER_PARSE_ERROR)) ); goto err_handling; };
    if( ((header_name_end_ptr) == 0) ) { xi_set_err( ((XI_HTTP_HEADER_PARSE_ERROR)) ); goto err_handling; };
    if( (header_name_end_ptr > header_end_ptr) ) { xi_set_err( (XI_HTTP_HEADER_PARSE_ERROR) ); goto err_handling; };
    {
        int size = sizeof( response->http_headers[ response->http_headers_size ].name );
        if( (header_name_end_ptr - content > size - 1) ) { xi_set_err( (XI_HTTP_HEADER_PARSE_ERROR) ); goto err_handling; };
        memcpy( response->http_headers[ response->http_headers_size ].name
            , content, (size - 1)<(header_name_end_ptr - content)?(size - 1):(header_name_end_ptr - content) );
        { (response->http_headers[ response->http_headers_size ].name)[ (size) - 1 ] = '\0'; };
    }
    header_name_end_ptr += 2;
    {
        int size = sizeof( response->http_headers[ response->http_headers_size ].value );
        if( (header_end_ptr - header_name_end_ptr > size - 1) ) { xi_set_err( (XI_HTTP_HEADER_PARSE_ERROR) ); goto err_handling; };
        memcpy( response->http_headers[ response->http_headers_size ].value
            , header_name_end_ptr, (size - 1)<(header_end_ptr - header_name_end_ptr)?(size - 1):(header_end_ptr - header_name_end_ptr) );
        { (response->http_headers[ response->http_headers_size ].value)[ (size) - 1 ] = '\0'; };
    }
    {
        enum http_header_type_t ht = classify_header(
            response->http_headers[ response->http_headers_size ].name );
        if( ht != XI_HTTP_HEADER_UNKNOWN )
        {
            response->http_headers_checklist[ ht ] =
                &response->http_headers[ response->http_headers_size ];
        }
        response->http_headers[ response->http_headers_size ].header_type = ht;
        response->http_headers_size += 1;
        if( (response->http_headers_size >= 16) ) { xi_set_err( (XI_HTTP_HEADER_PARSE_ERROR) ); goto err_handling; };
        header_end_ptr += sizeof( XI_HTTP_CRLF ) - 1;
    }
    return header_end_ptr;
err_handling:
    return 0;
}

variable_types: size int

variable_types: enum http_header_type_t { XI_HTTP_HEADER_DATE=0, XI_HTTP_HEADER_CONTENT_TYPE=1, XI_HTTP_HEADER_CONTENT_LENGTH=2, XI_HTTP_HEADER_CONNECTION=3, XI_HTTP_HEADER_X_REQUEST_ID=4, XI_HTTP_HEADER_CACHE_CONTROL=5, XI_HTTP_HEADER_VARY=6, XI_HTTP_HEADER_COUNT=7, XI_HTTP_HEADER_AGE=8, XI_HTTP_HEADER_UNKNOWN=9, XI_HTTP_HEADERS_COUNT=10 }


decompiled_code:
__int64 __fastcall parse_http(__int64 a1, const char *a2)
{
__int64 v3; // rdi
char *v4; // rax
char *v5; // rbp
const char *v6; // r12
char *v7; // rsi
char *v8; // rax
unsigned int v9; // eax
__int64 result; // rax

v3 = a1 + 8;
*(_QWORD *)(v3 - 8) = 0LL;
*(_QWORD *)(v3 + 2744) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 2760) >> 3));
v4 = strstr(a2, "\r\n\r\n");
if ( v4 && (v5 = v4 + 2, v6 = v4 + 4, (v7 = parse_http_status(a1, a2)) != 0LL) )
{
do
{
v8 = parse_http_header(a1, v7);
v7 = v8;
}
while ( v8 && v5 != v8 );
v9 = xi_get_last_error(a1, v8);
if ( v9 )
{
xi_set_err(v9);
result = 0LL;
}
else
{
strncpy((char *)(a1 + 2248), v6, 0x200uLL);
result = a1;
}
}
else
{
xi_set_err(4LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
__int64 v3; // rdi
char *v4; // rax
char *v5; // rbp
const char *v6; // r12
char *v7; // rsi
char *v8; // rax
unsigned int v9; // eax
__int64 result; // rax

v3 = a1 + 8;
*(_QWORD *)(v3 - 8) = 0LL;
*(_QWORD *)(v3 + 2744) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 2760) >> 3));
v4 = strstr(a2, "\r\n\r\n");
if ( v4 && (v5 = v4 + 2, v6 = v4 + 4, (v7 = func1(a1, a2)) != 0LL) )
{
do
{
v8 = func2(a1, v7);
v7 = v8;
}
while ( v8 && v5 != v8 );
v9 = xi_get_last_error(a1, v8);
if ( v9 )
{
xi_set_err(v9);
result = 0LL;
}
else
{
strncpy((char *)(a1 + 2248), v6, 0x200uLL);
result = a1;
}
}
else
{
xi_set_err(4LL);
result = 0LL;
}
return result;
}

original_code:
http_response_t* parse_http( http_response_t* response, const char* content )
{
    memset( response, 0, sizeof( http_response_t ) );
    const char* ptr_to_headers_end = strstr( content, XI_HTTP_CRLFX2 );
    if( ((ptr_to_headers_end) == 0) ) { xi_set_err( ((XI_HTTP_PARSE_ERROR)) ); goto err_handling; };
    ptr_to_headers_end += sizeof( XI_HTTP_CRLF ) - 1;
    const char* payload_begin = ptr_to_headers_end + sizeof( XI_HTTP_CRLF ) - 1;
    if( ((payload_begin) == 0) ) { xi_set_err( ((XI_HTTP_PARSE_ERROR)) ); goto err_handling; };
    const char* ptr = parse_http_status( response, content );
    if( ((ptr) == 0) ) { xi_set_err( ((XI_HTTP_PARSE_ERROR)) ); goto err_handling; };
    while( ( ptr = parse_http_header( response, ptr ) ) != '\0'
        && ptr != ptr_to_headers_end );
    xi_err_t e = xi_get_last_error();
    if( (e != XI_NO_ERR) ) { xi_set_err( (e) ); goto err_handling; };
    strncpy( response->http_content, payload_begin, sizeof( response->http_content ) );
    return response;
err_handling:
    return 0;
}

canonical_original_code:
struct http_response_t *parse_http(struct http_response_t *response, char *content)
{
    memset( response, 0, sizeof( http_response_t ) );
    char *ptr_to_headers_end = strstr( content, XI_HTTP_CRLFX2 );
    if( ((ptr_to_headers_end) == 0) ) { xi_set_err( ((XI_HTTP_PARSE_ERROR)) ); goto err_handling; };
    ptr_to_headers_end += sizeof( XI_HTTP_CRLF ) - 1;
    char *payload_begin = ptr_to_headers_end + sizeof( XI_HTTP_CRLF ) - 1;
    if( ((payload_begin) == 0) ) { xi_set_err( ((XI_HTTP_PARSE_ERROR)) ); goto err_handling; };
    char *ptr = parse_http_status( response, content );
    if( ((ptr) == 0) ) { xi_set_err( ((XI_HTTP_PARSE_ERROR)) ); goto err_handling; };
    while( ( ptr = parse_http_header( response, ptr ) ) != '\0'
        && ptr != ptr_to_headers_end );
    enum xi_err_t e = xi_get_last_error();
    if( (e != XI_NO_ERR) ) { xi_set_err( (e) ); goto err_handling; };
    strncpy( response->http_content, payload_begin, sizeof( response->http_content ) );
    return response;
err_handling:
    return 0;
}

variable_types:
response
struct http_response_t *

variable_types:
ptr
char *

variable_types: enum xi_err_t { XI_NO_ERR=0, XI_OUT_OF_MEMORY=1, XI_HTTP_STATUS_PARSE_ERROR=2, XI_HTTP_HEADER_PARSE_ERROR=3, XI_HTTP_PARSE_ERROR=4, XI_HTTP_ENCODE_CREATE_DATASTREAM=5, XI_HTTP_ENCODE_UPDATE_DATASTREAM=6, XI_HTTP_ENCODE_GET_DATASTREAM=7, XI_HTTP_ENCODE_DELETE_DATASTREAM=8, XI_HTTP_ENCODE_DELETE_DATAPOINT=9, XI_HTTP_ENCODE_DELETE_RANGE_DATAPOINT=10, XI_HTTP_ENCODE_UPDATE_FEED=11, XI_HTTP_CONSTRUCT_REQUEST_BUFFER_OVERRUN=12, XI_HTTP_CONSTRUCT_CONTENT_BUFFER_OVERRUN=13, XI_CSV_ENCODE_DATAPOINT_BUFFER_OVERRUN=14, XI_CSV_ENCODE_DATASTREAM_BUFFER_OVERRUN=15, XI_CSV_DECODE_FEED_PARSER_ERROR=16, XI_CSV_DECODE_DATAPOINT_PARSER_ERROR=17, XI_CSV_TIME_CONVERTION_ERROR=18, XI_SOCKET_INITIALIZATION_ERROR=19, XI_SOCKET_GETHOSTBYNAME_ERROR=20, XI_SOCKET_CONNECTION_ERROR=21, XI_SOCKET_SHUTDOWN_ERROR=22, XI_SOCKET_WRITE_ERROR=23, XI_SOCKET_READ_ERROR=24, XI_SOCKET_CLOSE_ERROR=25, XI_DATAPOINT_VALUE_BUFFER_OVERFLOW=26, XI_ERR_COUNT=27 }

return_type: struct http_response_t { int http_version1; int http_version2; int http_status; char http_status_string[32]; struct http_header_t { enum http_header_type_t { XI_HTTP_HEADER_DATE=0, XI_HTTP_HEADER_CONTENT_TYPE=1, XI_HTTP_HEADER_CONTENT_LENGTH=2, XI_HTTP_HEADER_CONNECTION=3, XI_HTTP_HEADER_X_REQUEST_ID=4, XI_HTTP_HEADER_CACHE_CONTROL=5, XI_HTTP_HEADER_VARY=6, XI_HTTP_HEADER_COUNT=7, XI_HTTP_HEADER_AGE=8, XI_HTTP_HEADER_UNKNOWN=9, XI_HTTP_HEADERS_COUNT=10 } header_type; char name[64]; char value[64]; } *http_headers_checklist[-1]; struct http_header_t http_headers[16]; unsigned long http_headers_size; char http_content[512]; } *


decompiled_code:
void **get_csv_data_layer()
{
return &_csv_data_layer_0;
}

canonical_decompiled_code:
void **func0()
{
return &_csv_data_layer_0;
}

original_code:
const data_layer_t* get_csv_data_layer()
{
    static const data_layer_t __csv_data_layer = {
          csv_encode_datapoint
        , csv_encode_datapoint_in_place
        , csv_encode_create_datastream
        , csv_decode_feed
        , csv_decode_datapoint
    };
    return &__csv_data_layer;
}

canonical_original_code:
struct data_layer_t *get_csv_data_layer()
{
    static struct data_layer_t __csv_data_layer = {
          csv_encode_datapoint
        , csv_encode_datapoint_in_place
        , csv_encode_create_datastream
        , csv_decode_feed
        , csv_decode_datapoint
    };
    return &__csv_data_layer;
}

return_type: struct data_layer_t { char *(*encode_datapoint)(struct xi_datapoint_t { union xi_datapoint_value_t { int i32_value; float f32_value; char str_value[32]; } value; enum xi_value_type_t { XI_VALUE_TYPE_I32=0, XI_VALUE_TYPE_F32=1, XI_VALUE_TYPE_STR=2, XI_VALUE_TYPE_COUNT=3 } value_type; struct xi_timestamp_t { long timestamp; long micro; } timestamp; } *dp); int (*encode_datapoint_in_place)(char *buffer, unsigned long buffer_size, struct xi_datapoint_t *dp); char *(*encode_create_datastream)(char *data, struct xi_datapoint_t *dp); struct xi_feed_t { int feed_id; unsigned long datastream_count; struct xi_datastream_t { char datastream_id[16]; unsigned long datapoint_count; struct xi_datapoint_t datapoints[16]; } datastreams[16]; } *(*decode_feed)(char *data, struct xi_feed_t *feed); struct xi_datapoint_t *(*decode_datapoint)(char *data, struct xi_datapoint_t *dp); } *

user_defined_types: struct data_layer_t { char *(*encode_datapoint)(struct xi_datapoint_t *dp); int (*encode_datapoint_in_place)(char *buffer, unsigned long buffer_size, struct xi_datapoint_t *dp); char *(*encode_create_datastream)(char *data, struct xi_datapoint_t *dp); struct xi_feed_t *(*decode_feed)(char *data, struct xi_feed_t *feed); struct xi_datapoint_t *(*decode_datapoint)(char *data, struct xi_datapoint_t *dp); }

user_defined_types: struct xi_datapoint_t { union xi_datapoint_value_t value; enum xi_value_type_t value_type; struct xi_timestamp_t timestamp; }


decompiled_code:
__int64 xi_printf(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, format);
vsnprintf(s, 0x200uLL, format, arg);
if ( USER_PRINT )
USER_PRINT(s);
else
printf("%s", s);
return 0LL;
}

canonical_decompiled_code:
__int64 func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, format);
vsnprintf(s, 0x200uLL, format, arg);
if ( USER_PRINT )
USER_PRINT(s);
else
printf("%s", s);
return 0LL;
}

original_code:
int xi_printf( const char *fmt, ... )
{
    char buffer[ 512 ];
    int n = 0;
    va_list ap;
    __builtin_va_start(ap,fmt);
    vsnprintf( buffer, 512, fmt, ap );
    __builtin_va_end(ap);
    if( USER_PRINT )
    {
        USER_PRINT( buffer );
    }
    else
    {
        printf( "%s", buffer );
    }
    return n;
}

canonical_original_code:
int xi_printf(char *fmt, ...)
{
    char buffer[512];
    int n = 0;
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    vsnprintf( buffer, 512, fmt, ap );
    __builtin_va_end(ap);
    if( USER_PRINT )
    {
        USER_PRINT( buffer );
    }
    else
    {
        printf( "%s", buffer );
    }
    return n;
}

variable_types:
fmt
char *

variable_types:
buffer
char [512]

variable_types: n int


decompiled_code:
// attributes: thunk
void *xi_alloc(size_t size)
{
return malloc(size);
}

canonical_decompiled_code:
void *func0(size_t size)
{
return malloc(size);
}

original_code:
void* xi_alloc( size_t b )
{
    return ( void* ) malloc( b );
}

canonical_original_code:
void *xi_alloc(unsigned long b)
{
    return ( void * ) malloc( b );
}

variable_types:
b
unsigned long

return_type: void *


decompiled_code:
// attributes: thunk
void xi_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func1(void *ptr)
{
free(ptr);
}

original_code:
void xi_free( void* p )
{
    free( p );
}

canonical_original_code:
void xi_free(void *p)
{
    free( p );
}

variable_types:
p
void *


decompiled_code:
void *__fastcall xi_str_dup(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

if ( !src )
_assert_fail("s != 0", "xi_helpers.c", 0x16u, "xi_str_dup");
v1 = strlen((const char *)src) + 1;
v2 = (void *)xi_alloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

canonical_decompiled_code:
void *__fastcall func0(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

if ( !src )
_assert_fail("s != 0", "xi_helpers.c", 0x16u, "xi_str_dup");
v1 = strlen((const char *)src) + 1;
v2 = (void *)xi_alloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

original_code:
char* xi_str_dup( const char* s )
{
    ((void) sizeof ((s != 0) ? 1 : 0), __extension__ ({ if (s != 0) ; else __assert_fail ("s != 0", "xi_helpers.c", 22, __extension__ __PRETTY_FUNCTION__); }));
    size_t len = strlen( s );
    char * ret = xi_alloc( len + 1 );
    if( ret == 0 ) { return 0; }
    memcpy( ret, s, len + 1 );
    return ret;
}

canonical_original_code:
char *xi_str_dup(char *s)
{
    ((void) sizeof ((s != 0) ? 1 : 0), __extension__ ({ if (s != 0) ; else __assert_fail ("s != 0", "xi_helpers.c", 22, __extension__ __PRETTY_FUNCTION__); }));
    unsigned long len = strlen( s );
    char *ret = xi_alloc( len + 1 );
    if( ret == 0 ) { return 0; }
    memcpy( ret, s, len + 1 );
    return ret;
}

variable_types:
s
char *

variable_types:
len
unsigned long

variable_types:
ret
char *


decompiled_code:
unsigned __int64 __fastcall xi_str_copy_untiln(_BYTE *a1, unsigned __int64 a2, char *a3, char a4)
{
char v5; // dl
unsigned __int64 result; // rax

if ( !a1 )
_assert_fail("dst != 0", "xi_helpers.c", 0x22u, "xi_str_copy_untiln");
if ( a2 <= 1 )
_assert_fail("dst_size > 1", "xi_helpers.c", 0x23u, "xi_str_copy_untiln");
if ( !a3 )
_assert_fail("src != 0", "xi_helpers.c", 0x24u, "xi_str_copy_untiln");
v5 = *a3;
if ( v5 == a4 || !v5 )
{
*a1 = 0;
result = 0LL;
}
else
{
result = 0LL;
do
{
++result;
*a1++ = v5;
v5 = a3[result];
}
while ( v5 != 0 && v5 != a4 && a2 - 1 > result );
*a1 = 0;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(_BYTE *a1, unsigned __int64 a2, char *a3, char a4)
{
char v5; // dl
unsigned __int64 result; // rax

if ( !a1 )
_assert_fail("dst != 0", "xi_helpers.c", 0x22u, "xi_str_copy_untiln");
if ( a2 <= 1 )
_assert_fail("dst_size > 1", "xi_helpers.c", 0x23u, "xi_str_copy_untiln");
if ( !a3 )
_assert_fail("src != 0", "xi_helpers.c", 0x24u, "xi_str_copy_untiln");
v5 = *a3;
if ( v5 == a4 || !v5 )
{
*a1 = 0;
result = 0LL;
}
else
{
result = 0LL;
do
{
++result;
*a1++ = v5;
v5 = a3[result];
}
while ( v5 != 0 && v5 != a4 && a2 - 1 > result );
*a1 = 0;
}
return result;
}

original_code:
int xi_str_copy_untiln( char* dst, size_t dst_size, const char* src, char delim )
{
    ((void) sizeof ((dst != 0) ? 1 : 0), __extension__ ({ if (dst != 0) ; else __assert_fail ("dst != 0", "xi_helpers.c", 34, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((dst_size > 1) ? 1 : 0), __extension__ ({ if (dst_size > 1) ; else __assert_fail ("dst_size > 1", "xi_helpers.c", 35, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((src != 0) ? 1 : 0), __extension__ ({ if (src != 0) ; else __assert_fail ("src != 0", "xi_helpers.c", 36, __extension__ __PRETTY_FUNCTION__); }));
    size_t counter = 0;
    size_t real_size = dst_size - 1;
    while( *src != delim && counter < real_size && *src != '\0' )
    {
        *dst++ = *src++;
        counter++;
    }
    *dst = '\0';
    return counter;
}

canonical_original_code:
int xi_str_copy_untiln(char *dst, unsigned long dst_size, char *src, char delim)
{
    ((void) sizeof ((dst != 0) ? 1 : 0), __extension__ ({ if (dst != 0) ; else __assert_fail ("dst != 0", "xi_helpers.c", 34, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((dst_size > 1) ? 1 : 0), __extension__ ({ if (dst_size > 1) ; else __assert_fail ("dst_size > 1", "xi_helpers.c", 35, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((src != 0) ? 1 : 0), __extension__ ({ if (src != 0) ; else __assert_fail ("src != 0", "xi_helpers.c", 36, __extension__ __PRETTY_FUNCTION__); }));
    unsigned long counter = 0;
    unsigned long real_size = dst_size - 1;
    while( *src != delim && counter < real_size && *src != '\0' )
    {
        *dst++ = *src++;
        counter++;
    }
    *dst = '\0';
    return counter;
}

variable_types:
dst
char *

variable_types:
src
char *

variable_types: delim char

variable_types:
counter
unsigned long


original_code:
time_t xi_mktime(register struct tm *timep)
{
    register long day, year;
    register int tm_year;
    int yday, month;
    register signed long seconds;
    int overflow;
    timep->tm_min += timep->tm_sec / 60;
    timep->tm_sec %= 60;
    if (timep->tm_sec < 0) {
         timep->tm_sec += 60;
         timep->tm_min--;
    }
    timep->tm_hour += timep->tm_min / 60;
    timep->tm_min = timep->tm_min % 60;
    if (timep->tm_min < 0) {
         timep->tm_min += 60;
         timep->tm_hour--;
    }
    day = timep->tm_hour / 24;
    timep->tm_hour= timep->tm_hour % 24;
    if (timep->tm_hour < 0) {
         timep->tm_hour += 24;
         day--;
    }
    timep->tm_year += timep->tm_mon / 12;
    timep->tm_mon %= 12;
    if (timep->tm_mon < 0) {
         timep->tm_mon += 12;
         timep->tm_year--;
    }
    day += (timep->tm_mday - 1);
    while (day < 0) {
         if(--timep->tm_mon < 0) {
                 timep->tm_year--;
                 timep->tm_mon = 11;
         }
         day += _ytab[(!((1900 + timep->tm_year) % 4) && (((1900 + timep->tm_year) % 100) || !((1900 + timep->tm_year) % 400)))][timep->tm_mon];
    }
    while (day >= _ytab[(!((1900 + timep->tm_year) % 4) && (((1900 + timep->tm_year) % 100) || !((1900 + timep->tm_year) % 400)))][timep->tm_mon]) {
         day -= _ytab[(!((1900 + timep->tm_year) % 4) && (((1900 + timep->tm_year) % 100) || !((1900 + timep->tm_year) % 400)))][timep->tm_mon];
         if (++(timep->tm_mon) == 12) {
                 timep->tm_mon = 0;
                 timep->tm_year++;
         }
    }
    timep->tm_mday = day + 1;
    year = 1970;
    if (timep->tm_year < year - 1900) return (time_t)-1;
    seconds = 0;
    day = 0;
    overflow = 0;
    tm_year = timep->tm_year + 1900;
    if (0x7fffffffffffffffL / 365 < tm_year - year) overflow++;
    day = (tm_year - year) * 365;
    if (0x7fffffffffffffffL - day < (tm_year - year) / 4 + 1) overflow++;
    day += (tm_year - year) / 4
         + ((tm_year % 4) && tm_year % 4 < year % 4);
    day -= (tm_year - year) / 100
         + ((tm_year % 100) && tm_year % 100 < year % 100);
    day += (tm_year - year) / 400
         + ((tm_year % 400) && tm_year % 400 < year % 400);
    yday = month = 0;
    while (month < timep->tm_mon) {
         yday += _ytab[(!((tm_year) % 4) && (((tm_year) % 100) || !((tm_year) % 400)))][month];
         month++;
    }
    yday += (timep->tm_mday - 1);
    if (day + yday < 0) overflow++;
    day += yday;
    timep->tm_yday = yday;
    timep->tm_wday = (day + 4) % 7;
    seconds = ( ( timep->tm_hour * 60L ) + timep->tm_min ) * 60L + timep->tm_sec;
    if ( ( (0x7fffffffffffffffL * 2UL + 1UL) - seconds ) / (24L * 60L * 60L) < ( unsigned long ) day ) overflow++;
    seconds += day * (24L * 60L * 60L);
    if ( overflow ) return ( time_t ) - 1;
    if ( ( time_t ) seconds != seconds) return ( time_t ) - 1;
    return ( time_t ) seconds;
}

canonical_original_code:
long xi_mktime(struct tm *timep)
{
    register long day; register long year;
    register int tm_year;
    int yday; int month;
    register long seconds;
    int overflow;
    timep->tm_min += timep->tm_sec / 60;
    timep->tm_sec %= 60;
    if (timep->tm_sec < 0) {
         timep->tm_sec += 60;
         timep->tm_min--;
    }
    timep->tm_hour += timep->tm_min / 60;
    timep->tm_min = timep->tm_min % 60;
    if (timep->tm_min < 0) {
         timep->tm_min += 60;
         timep->tm_hour--;
    }
    day = timep->tm_hour / 24;
    timep->tm_hour= timep->tm_hour % 24;
    if (timep->tm_hour < 0) {
         timep->tm_hour += 24;
         day--;
    }
    timep->tm_year += timep->tm_mon / 12;
    timep->tm_mon %= 12;
    if (timep->tm_mon < 0) {
         timep->tm_mon += 12;
         timep->tm_year--;
    }
    day += (timep->tm_mday - 1);
    while (day < 0) {
         if(--timep->tm_mon < 0) {
                 timep->tm_year--;
                 timep->tm_mon = 11;
         }
         day += _ytab[(!((1900 + timep->tm_year) % 4) && (((1900 + timep->tm_year) % 100) || !((1900 + timep->tm_year) % 400)))][timep->tm_mon];
    }
    while (day >= _ytab[(!((1900 + timep->tm_year) % 4) && (((1900 + timep->tm_year) % 100) || !((1900 + timep->tm_year) % 400)))][timep->tm_mon]) {
         day -= _ytab[(!((1900 + timep->tm_year) % 4) && (((1900 + timep->tm_year) % 100) || !((1900 + timep->tm_year) % 400)))][timep->tm_mon];
         if (++(timep->tm_mon) == 12) {
                 timep->tm_mon = 0;
                 timep->tm_year++;
         }
    }
    timep->tm_mday = day + 1;
    year = 1970;
    if (timep->tm_year < year - 1900) return (time_t)-1;
    seconds = 0;
    day = 0;
    overflow = 0;
    tm_year = timep->tm_year + 1900;
    if (0x7fffffffffffffffL / 365 < tm_year - year) overflow++;
    day = (tm_year - year) * 365;
    if (0x7fffffffffffffffL - day < (tm_year - year) / 4 + 1) overflow++;
    day += (tm_year - year) / 4
         + ((tm_year % 4) && tm_year % 4 < year % 4);
    day -= (tm_year - year) / 100
         + ((tm_year % 100) && tm_year % 100 < year % 100);
    day += (tm_year - year) / 400
         + ((tm_year % 400) && tm_year % 400 < year % 400);
    yday = month = 0;
    while (month < timep->tm_mon) {
         yday += _ytab[(!((tm_year) % 4) && (((tm_year) % 100) || !((tm_year) % 400)))][month];
         month++;
    }
    yday += (timep->tm_mday - 1);
    if (day + yday < 0) overflow++;
    day += yday;
    timep->tm_yday = yday;
    timep->tm_wday = (day + 4) % 7;
    seconds = ( ( timep->tm_hour * 60L ) + timep->tm_min ) * 60L + timep->tm_sec;
    if ( ( (0x7fffffffffffffffL * 2UL + 1UL) - seconds ) / (24L * 60L * 60L) < ( unsigned long ) day ) overflow++;
    seconds += day * (24L * 60L * 60L);
    if ( overflow ) return ( time_t ) - 1;
    if ( ( long ) seconds != seconds) return ( time_t ) - 1;
    return ( long ) seconds;
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: day long

variable_types: year long

variable_types: yday int

variable_types: month int

variable_types: seconds long

variable_types: overflow int

return_type: long


decompiled_code:
// attributes: thunk
struct tm *xi_gmtime(const time_t *timer)
{
return gmtime(timer);
}

canonical_decompiled_code:
struct tm *func3(const time_t *timer)
{
return gmtime(timer);
}

original_code:
struct tm* xi_gmtime( time_t* t )
{
    return gmtime( t );
}

canonical_original_code:
struct tm *xi_gmtime(long *t)
{
    return gmtime( t );
}

variable_types:
t
long *

return_type: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
void **get_http_transport_layer()
{
return &_http_transport_layer_0;
}

canonical_decompiled_code:
void **func0()
{
return &_http_transport_layer_0;
}

original_code:
transport_layer_t* get_http_transport_layer( void )
{
    static transport_layer_t __http_transport_layer =
    {
          &http_encode_update_feed
        , &http_encode_get_feed
        , &http_encode_create_datastream
        , &http_encode_update_datastream
        , &http_encode_get_datastream
        , &http_encode_delete_datastream
        , &http_encode_delete_datapoint
        , &http_encode_datapoint_delete_range
        , &http_decode_reply
    };
    return &__http_transport_layer;
}

canonical_original_code:
struct transport_layer_t *get_http_transport_layer()
{
    static struct transport_layer_t __http_transport_layer = {
          &http_encode_update_feed
        , &http_encode_get_feed
        , &http_encode_create_datastream
        , &http_encode_update_datastream
        , &http_encode_get_datastream
        , &http_encode_delete_datastream
        , &http_encode_delete_datapoint
        , &http_encode_datapoint_delete_range
        , &http_decode_reply
    };
    return &__http_transport_layer;
}

return_type: struct transport_layer_t { char *(*encode_update_feed)(struct data_layer_t { char *(*encode_datapoint)(struct xi_datapoint_t { union xi_datapoint_value_t { int i32_value; float f32_value; char str_value[32]; } value; enum xi_value_type_t { XI_VALUE_TYPE_I32=0, XI_VALUE_TYPE_F32=1, XI_VALUE_TYPE_STR=2, XI_VALUE_TYPE_COUNT=3 } value_type; struct xi_timestamp_t { long timestamp; long micro; } timestamp; } *dp); int (*encode_datapoint_in_place)(char *buffer, unsigned long buffer_size, struct xi_datapoint_t *dp); char *(*encode_create_datastream)(char *data, struct xi_datapoint_t *dp); struct xi_feed_t { int feed_id; unsigned long datastream_count; struct xi_datastream_t { char datastream_id[16]; unsigned long datapoint_count; struct xi_datapoint_t datapoints[16]; } datastreams[16]; } *(*decode_feed)(char *data, struct xi_feed_t *feed); struct xi_datapoint_t *(*decode_datapoint)(char *data, struct xi_datapoint_t *dp); } *, char *api_key, struct xi_feed_t *feed); char *(*encode_get_feed)(struct data_layer_t *, char *api_key, struct xi_feed_t *feed); char *(*encode_create_datastream)(struct data_layer_t *, char *api_key, int feed_id, char *datastream_id, union xi_datapoint_value_t *dp); char *(*encode_update_datastream)(struct data_layer_t *, char *api_key, int feed_id, char *datastream_id, union xi_datapoint_value_t *value); char *(*encode_get_datastream)(struct data_layer_t *, char *api_key, int feed_id, char *datastream_id); char *(*encode_delete_datastream)(struct data_layer_t *, char *api_key, int feed_id, char *datastream_id); char *(*encode_delete_datapoint)(struct data_layer_t *, char *api_key, int feed_id, char *datastream_id, struct xi_datapoint_t *datapoint); char *(*encode_datapoint_delete_range)(struct data_layer_t *, char *api_key, int feed_id, char *datastream_id, struct xi_timestamp_t *start, struct xi_timestamp_t *end); struct xi_response_t { struct http_response_t { int http_version1; int http_version2; int http_status; char http_status_string[32]; struct http_header_t { enum http_header_type_t { XI_HTTP_HEADER_DATE=0, XI_HTTP_HEADER_CONTENT_TYPE=1, XI_HTTP_HEADER_CONTENT_LENGTH=2, XI_HTTP_HEADER_CONNECTION=3, XI_HTTP_HEADER_X_REQUEST_ID=4, XI_HTTP_HEADER_CACHE_CONTROL=5, XI_HTTP_HEADER_VARY=6, XI_HTTP_HEADER_COUNT=7, XI_HTTP_HEADER_AGE=8, XI_HTTP_HEADER_UNKNOWN=9, XI_HTTP_HEADERS_COUNT=10 } header_type; char name[64]; char value[64]; } *http_headers_checklist[-1]; struct http_header_t http_headers[16]; unsigned long http_headers_size; char http_content[512]; } http; } *(*decode_reply)(struct data_layer_t *, char *data); } *

user_defined_types: struct transport_layer_t { char *(*encode_update_feed)(struct data_layer_t *, char *api_key, struct xi_feed_t *feed); char *(*encode_get_feed)(struct data_layer_t *, char *api_key, struct xi_feed_t *feed); char *(*encode_create_datastream)(struct data_layer_t *, char *api_key, int feed_id, char *datastream_id, union xi_datapoint_value_t *dp); char *(*encode_update_datastream)(struct data_layer_t *, char *api_key, int feed_id, char *datastream_id, union xi_datapoint_value_t *value); char *(*encode_get_datastream)(struct data_layer_t *, char *api_key, int feed_id, char *datastream_id); char *(*encode_delete_datastream)(struct data_layer_t *, char *api_key, int feed_id, char *datastream_id); char *(*encode_delete_datapoint)(struct data_layer_t *, char *api_key, int feed_id, char *datastream_id, struct xi_datapoint_t *datapoint); char *(*encode_datapoint_delete_range)(struct data_layer_t *, char *api_key, int feed_id, char *datastream_id, struct xi_timestamp_t *start, struct xi_timestamp_t *end); struct xi_response_t *(*decode_reply)(struct data_layer_t *, char *data); }

user_defined_types: struct xi_response_t { struct http_response_t http; }


main

canonical_name: main

repo: yixia/libmicrohttpd

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return test_wrap("ip addr option", test_ip_addr_option, envp) != 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return func10("ip addr option", test_ip_addr_option, envp) != 0;
}

original_code:
int
main (int argc, char *const *argv)
{
  unsigned int errorCount = 0;
  errorCount += test_wrap ("ip addr option", &test_ip_addr_option);
  return errorCount != 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  unsigned int errorCount = 0;
  errorCount += test_wrap ("ip addr option", &test_ip_addr_option);
  return errorCount != 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
errorCount
unsigned int


decompiled_code:
__int64 __fastcall test_wrap(const char *a1, __int64 (*a2)(void))
{
unsigned int v2; // er12
__int64 result; // rax

fprintf(_bss_start, "running test: %s ", a1);
v2 = a2();
if ( v2 )
{
fwrite("[fail]\n", 1uLL, 7uLL, _bss_start);
result = v2;
}
else
{
fwrite("[pass]\n", 1uLL, 7uLL, _bss_start);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, __int64 (*a2)(void))
{
unsigned int v2; // er12
__int64 result; // rax

fprintf(_bss_start, "running test: %s ", a1);
v2 = a2();
if ( v2 )
{
fwrite("[fail]\n", 1uLL, 7uLL, _bss_start);
result = v2;
}
else
{
fwrite("[pass]\n", 1uLL, 7uLL, _bss_start);
result = 0LL;
}
return result;
}

original_code:
int
test_wrap (char *test_name, int (*test) (void))
{
  int ret;
  fprintf (stdout, "running test: %s ", test_name);
  ret = test ();
  if (ret == 0)
    {
      fprintf (stdout, "[pass]\n");
    }
  else
    {
      fprintf (stdout, "[fail]\n");
    }
  return ret;
}

canonical_original_code:
int test_wrap(char *test_name, int (*test)())
{
  int ret;
  fprintf (stdout, "running test: %s ", test_name);
  ret = test ();
  if (ret == 0)
    {
      fprintf (stdout, "[pass]\n");
    }
  else
    {
      fprintf (stdout, "[fail]\n");
    }
  return ret;
}

variable_types:
test
int (*)()

variable_types: ret int


decompiled_code:
int __fastcall parse_version_number(char **a1)
{
char *v1; // rdx
__int64 v3; // rax
__int64 v4; // rdi
char v6[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = *a1;
v3 = 0LL;
while ( 1 )
{
v4 = (int)v3;
if ( (unsigned __int8)(*v1 - 48) > 9u )
break;
v6[v3++] = *v1++;
*a1 = v1;
if ( v3 == 16 )
{
v4 = 16LL;
break;
}
}
v6[v4] = 0;
return atoi(v6);
}

original_code:
static int
parse_version_number (const char **s)
{
  int i = 0;
  char num[17];
  while (i < 16 && ((**s >= '0') & (**s <= '9')))
    {
      num[i] = **s;
      (*s)++;
      i++;
    }
  num[i] = '\0';
  return atoi (num);
}

canonical_original_code:
static int parse_version_number(char **s)
{
  int i = 0;
  char num[17];
  while (i < 16 && ((**s >= '0') & (**s <= '9')))
    {
      num[i] = **s;
      (*s)++;
      i++;
    }
  num[i] = '\0';
  return atoi (num);
}

variable_types:
s
char **

variable_types: i int

variable_types:
num
char [17]


decompiled_code:
__int64 __fastcall curl_check_version(char *a1)
{
const char *v1; // rbp
char *v2; // rax
char *v3; // rbp
__int64 result; // rax
int v5; // [rsp+8h] [rbp-30h] BYREF
int v6; // [rsp+Ch] [rbp-2Ch] BYREF
int v7; // [rsp+10h] [rbp-28h] BYREF
int v8; // [rsp+14h] [rbp-24h] BYREF
int v9; // [rsp+18h] [rbp-20h] BYREF
int v10[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v1 = (const char *)curl_version();
fprintf(stderr, "curl version: %s\n", v1);
v2 = strchr(v1, 47);
if ( !v2 )
goto LABEL_7;
v3 = v2 + 1;
if ( !parse_version_string(a1, &v8, &v9, v10) || !parse_version_string(v3, &v5, &v6, &v7) )
goto LABEL_7;
result = 0LL;
if ( v5 <= v8 && (v5 != v8 || v6 <= v9 && (v6 != v9 || v7 <= v10[0] && v7 != v10[0])) )
{
fprintf(stderr, "Error: running curl test depends on local libcurl version > %s\n", a1);
LABEL_7:
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
const char *v1; // rbp
char *v2; // rax
char *v3; // rbp
__int64 result; // rax
int v5; // [rsp+8h] [rbp-30h] BYREF
int v6; // [rsp+Ch] [rbp-2Ch] BYREF
int v7; // [rsp+10h] [rbp-28h] BYREF
int v8; // [rsp+14h] [rbp-24h] BYREF
int v9; // [rsp+18h] [rbp-20h] BYREF
int v10[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v1 = (const char *)curl_version();
fprintf(stderr, "curl version: %s\n", v1);
v2 = strchr(v1, 47);
if ( !v2 )
goto LABEL_7;
v3 = v2 + 1;
if ( !func1(a1, &v8, &v9, v10) || !func1(v3, &v5, &v6, &v7) )
goto LABEL_7;
result = 0LL;
if ( v5 <= v8 && (v5 != v8 || v6 <= v9 && (v6 != v9 || v7 <= v10[0] && v7 != v10[0])) )
{
fprintf(stderr, "Error: running curl test depends on local libcurl version > %s\n", a1);
LABEL_7:
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
curl_check_version (const char *req_version)
{
  const char *ver;
  const char *curl_ver;
  int loc_major, loc_minor, loc_micro;
  int rq_major, rq_minor, rq_micro;
  ver = curl_version ();
  fprintf (stderr, "curl version: %s\n", ver);
  curl_ver = strchr (ver, '/');
  if (curl_ver == ((void *)0))
    return -1;
  curl_ver++;
  if ( (((void *)0) == parse_version_string (req_version, &rq_major, &rq_minor, &rq_micro)) ||
       (((void *)0) == parse_version_string (curl_ver, &loc_major, &loc_minor, &loc_micro)) )
    return -1;
  if ((loc_major > rq_major
       || (loc_major == rq_major && loc_minor > rq_minor)
       || (loc_major == rq_major && loc_minor == rq_minor
           && loc_micro > rq_micro) || (loc_major == rq_major
                                        && loc_minor == rq_minor
                                        && loc_micro == rq_micro)) == 0)
    {
      fprintf (stderr,
               "Error: running curl test depends on local libcurl version > %s\n",
               req_version);
      return -1;
    }
  return 0;
}

canonical_original_code:
int curl_check_version(char *req_version)
{
  char *ver;
  char *curl_ver;
  int loc_major; int loc_minor; int loc_micro;
  int rq_major; int rq_minor; int rq_micro;
  ver = curl_version ();
  fprintf (stderr, "curl version: %s\n", ver);
  curl_ver = strchr (ver, '/');
  if (curl_ver == ((void *)0))
    return -1;
  curl_ver++;
  if ( (((void *)0) == parse_version_string (req_version, &rq_major, &rq_minor, &rq_micro)) ||
       (((void *)0) == parse_version_string (curl_ver, &loc_major, &loc_minor, &loc_micro)) )
    return -1;
  if ((loc_major > rq_major
       || (loc_major == rq_major && loc_minor > rq_minor)
       || (loc_major == rq_major && loc_minor == rq_minor
           && loc_micro > rq_micro) || (loc_major == rq_major
                                        && loc_minor == rq_minor
                                        && loc_micro == rq_micro)) == 0)
    {
      fprintf (stderr,
               "Error: running curl test depends on local libcurl version > %s\n",
               req_version);
      return -1;
    }
  return 0;
}

variable_types:
ver
char *


cupsLutDelete

decompiled_code:
void __fastcall cupsLutDelete(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void
cupsLutDelete(cups_lut_t *lut)
{
  if (lut != ((void *)0))
    free(lut);
}

canonical_original_code:
void cupsLutDelete(struct cups_lut_s *lut)
{
  if (lut != ((void *)0))
    free(lut);
}

variable_types: struct cups_lut_s { short intensity; short pixel; int error; } *


cupsCheckBytes

decompiled_code:
__int64 __fastcall cupsCheckBytes(_BYTE *a1, int a2)
{
_BYTE *v2; // rsi

while ( a2 > 7 )
{
if ( *a1 )
return 0LL;
if ( a1[1] )
return 0LL;
if ( a1[2] )
return 0LL;
if ( a1[3] )
return 0LL;
if ( a1[4] )
return 0LL;
if ( a1[5] )
return 0LL;
if ( a1[6] )
return 0LL;
a1 += 8;
if ( *(a1 - 1) )
return 0LL;
a2 -= 8;
}
if ( a2 > 0 )
{
v2 = &a1[a2];
while ( !*a1++ )
{
if ( a1 == v2 )
return 1LL;
}
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, int a2)
{
_BYTE *v2; // rsi

while ( a2 > 7 )
{
if ( *a1 )
return 0LL;
if ( a1[1] )
return 0LL;
if ( a1[2] )
return 0LL;
if ( a1[3] )
return 0LL;
if ( a1[4] )
return 0LL;
if ( a1[5] )
return 0LL;
if ( a1[6] )
return 0LL;
a1 += 8;
if ( *(a1 - 1) )
return 0LL;
a2 -= 8;
}
if ( a2 > 0 )
{
v2 = &a1[a2];
while ( !*a1++ )
{
if ( a1 == v2 )
return 1LL;
}
return 0LL;
}
return 1LL;
}

original_code:
int
cupsCheckBytes(const unsigned char *bytes,
               int length)
{
  while (length > 7)
  {
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    length -= 8;
  }
  while (length > 0)
    if (*bytes++)
      return (0);
    else
      length --;
  return (1);
}

canonical_original_code:
int cupsCheckBytes(unsigned char *bytes, int length)
{
  while (length > 7)
  {
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    if (*bytes++)
      return (0);
    length -= 8;
  }
  while (length > 0)
    if (*bytes++)
      return (0);
    else
      length --;
  return (1);
}

variable_types:
bytes
unsigned char *

variable_types: length int


cupsCheckValue

decompiled_code:
__int64 __fastcall cupsCheckValue(_BYTE *a1, int a2, char a3)
{
_BYTE *v3; // rsi

while ( a2 > 7 )
{
if ( *a1 != a3 )
return 0LL;
if ( a1[1] != a3 )
return 0LL;
if ( a1[2] != a3 )
return 0LL;
if ( a1[3] != a3 )
return 0LL;
if ( a1[4] != a3 )
return 0LL;
if ( a1[5] != a3 )
return 0LL;
if ( a1[6] != a3 )
return 0LL;
a1 += 8;
if ( *(a1 - 1) != a3 )
return 0LL;
a2 -= 8;
}
if ( a2 > 0 )
{
v3 = &a1[a2];
while ( *a1++ == a3 )
{
if ( a1 == v3 )
return 1LL;
}
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, int a2, char a3)
{
_BYTE *v3; // rsi

while ( a2 > 7 )
{
if ( *a1 != a3 )
return 0LL;
if ( a1[1] != a3 )
return 0LL;
if ( a1[2] != a3 )
return 0LL;
if ( a1[3] != a3 )
return 0LL;
if ( a1[4] != a3 )
return 0LL;
if ( a1[5] != a3 )
return 0LL;
if ( a1[6] != a3 )
return 0LL;
a1 += 8;
if ( *(a1 - 1) != a3 )
return 0LL;
a2 -= 8;
}
if ( a2 > 0 )
{
v3 = &a1[a2];
while ( *a1++ == a3 )
{
if ( a1 == v3 )
return 1LL;
}
return 0LL;
}
return 1LL;
}

original_code:
int
cupsCheckValue(const unsigned char *bytes,
               int length,
        const unsigned char value)
{
  while (length > 7)
  {
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    length -= 8;
  }
  while (length > 0)
    if (*bytes++ != value)
      return (0);
    else
      length --;
  return (1);
}

canonical_original_code:
int cupsCheckValue(unsigned char *bytes, int length, unsigned char value)
{
  while (length > 7)
  {
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    if (*bytes++ != value)
      return (0);
    length -= 8;
  }
  while (length > 0)
    if (*bytes++ != value)
      return (0);
    else
      length --;
  return (1);
}

variable_types:
value
unsigned char


repo: ykli/misc

decompiled_code:
__int64 __fastcall faac_sqrt(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdi
__int64 v3; // rdx
__int64 v4; // rdi
bool v5; // cc

result = 0LL;
if ( a1 > 0 )
{
if ( a1 <= 0xFFFF )
{
for ( LODWORD(result) = 0; a1 <= 6553; LODWORD(result) = result - 1 )
a1 *= 4LL;
}
else
{
do
{
a1 >>= 2;
LODWORD(result) = result + 1;
}
while ( a1 > 0xFFFF );
}
v2 = ((*((int *)&faac_table_sqrt + (int)(a1 >> 2)) * (((__int64)(int)((a1 >> 2) + 1) << 16) - (a1 << 14))) >> 16)
+ ((*((int *)&faac_table_sqrt + (int)((a1 >> 2) + 1)) * ((a1 << 14) - (a1 >> 2 << 16))) >> 16);
v3 = v2 << result;
v4 = v2 >> -(char)result;
v5 = (int)result <= 0;
result = v3;
if ( v5 )
result = v4;
}
return result;
}

variable_types: x long

variable_types: y long

variable_types: n int


decompiled_code:
__int64 __fastcall faac_log(__int64 a1)
{
__int64 result; // rax
int v2; // edi
int v3; // eax

result = 0LL;
if ( a1 > 0 )
{
if ( a1 <= 0xFFFF )
{
for ( LODWORD(result) = 0; a1 <= 6553; LODWORD(result) = result - 1 )
a1 *= 2LL;
}
else
{
do
{
a1 >>= 1;
LODWORD(result) = result + 1;
}
while ( a1 > 0xFFFF );
}
v2 = ((*((int *)&faac_table_log + (int)(a1 >> 2)) * (((__int64)(int)((a1 >> 2) + 1) << 16) - (a1 << 14))) >> 16)
+ ((*((int *)&faac_table_log + (int)((a1 >> 2) + 1)) * ((a1 << 14) - (a1 >> 2 << 16))) >> 16);
if ( (int)result < 0 )
v3 = -*((_DWORD *)&faac_table_log2 - (int)result);
else
v3 = *((_DWORD *)&faac_table_log2 + (int)result);
result = (unsigned int)(v2 + v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
int v2; // edi
int v3; // eax

result = 0LL;
if ( a1 > 0 )
{
if ( a1 <= 0xFFFF )
{
for ( LODWORD(result) = 0; a1 <= 6553; LODWORD(result) = result - 1 )
a1 *= 2LL;
}
else
{
do
{
a1 >>= 1;
LODWORD(result) = result + 1;
}
while ( a1 > 0xFFFF );
}
v2 = ((*((int *)&faac_table_log + (int)(a1 >> 2)) * (((__int64)(int)((a1 >> 2) + 1) << 16) - (a1 << 14))) >> 16)
+ ((*((int *)&faac_table_log + (int)((a1 >> 2) + 1)) * ((a1 << 14) - (a1 >> 2 << 16))) >> 16);
if ( (int)result < 0 )
v3 = -*((_DWORD *)&faac_table_log2 - (int)result);
else
v3 = *((_DWORD *)&faac_table_log2 + (int)result);
result = (unsigned int)(v2 + v3);
}
return result;
}

variable_types: y int


decompiled_code:
__int64 __fastcall faac_pow(__int64 a1)
{
__int64 result; // rax
int v2; // eax
int v3; // er9
int v4; // esi
int v5; // eax
int v6; // edi

result = 0LL;
if ( a1 )
{
v2 = faac_log(a1);
v4 = 0;
v5 = (v3 * (__int64)((v2 << 16) / 45426)) >> 16;
if ( v5 < 0 )
{
v5 = -v5;
v4 = 1;
}
v6 = (int)(unsigned __int16)v5 >> 2;
result = ((unsigned int)((*((int *)&faac_table_pow + v6) * (((__int64)(v6 + 1) << 16) - ((unsigned __int16)v5 << 14))) >> 16)
+ (unsigned int)((*((int *)&faac_table_pow + v6 + 1) * (((unsigned __int16)v5 << 14) - ((__int64)v6 << 16))) >> 16)) << SBYTE2(v5);
if ( v4 )
{
if ( (_DWORD)result )
result = 0x100000000LL / (int)result;
else
result = 0x7FFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
int v2; // eax
int v3; // er9
int v4; // esi
int v5; // eax
int v6; // edi

result = 0LL;
if ( a1 )
{
v2 = func1(a1);
v4 = 0;
v5 = (v3 * (__int64)((v2 << 16) / 45426)) >> 16;
if ( v5 < 0 )
{
v5 = -v5;
v4 = 1;
}
v6 = (int)(unsigned __int16)v5 >> 2;
result = ((unsigned int)((*((int *)&faac_table_pow + v6) * (((__int64)(v6 + 1) << 16) - ((unsigned __int16)v5 << 14))) >> 16)
+ (unsigned int)((*((int *)&faac_table_pow + v6 + 1) * (((unsigned __int16)v5 << 14) - ((__int64)v6 << 16))) >> 16)) << SBYTE2(v5);
if ( v4 )
{
if ( (_DWORD)result )
result = 0x100000000LL / (int)result;
else
result = 0x7FFFFFFFLL;
}
}
return result;
}

variable_types: z int

variable_types: fracx int

variable_types: zi int

variable_types: zf int

variable_types: neg int


decompiled_code:
__int64 __fastcall faac_pow34(unsigned int a1)
{
__int64 result; // rax
int v2; // eax
int v3; // edx
char v4; // si
char v5; // cl

result = a1;
if ( a1 )
{
v2 = abs32(a1);
if ( v2 <= 0x1FFFF )
{
v3 = 0;
do
{
v2 *= 16;
v4 = v3;
v3 -= 3;
}
while ( v2 <= 0x1FFFF );
v5 = 3 - v4;
return (unsigned int)(*((int *)&faac_table_pow34 + ((v2 + 64) >> 7)) >> v5);
}
v5 = 0;
if ( v2 <= 0x200000 )
return (unsigned int)(*((int *)&faac_table_pow34 + ((v2 + 64) >> 7)) >> v5);
do
{
v2 >>= 4;
v5 += 3;
}
while ( v2 > 0x200000 );
result = (unsigned int)(*((_DWORD *)&faac_table_pow34 + ((v2 + 64) >> 7)) << v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 result; // rax
int v2; // eax
int v3; // edx
char v4; // si
char v5; // cl

result = a1;
if ( a1 )
{
v2 = abs32(a1);
if ( v2 <= 0x1FFFF )
{
v3 = 0;
do
{
v2 *= 16;
v4 = v3;
v3 -= 3;
}
while ( v2 <= 0x1FFFF );
v5 = 3 - v4;
return (unsigned int)(*((int *)&faac_table_pow34 + ((v2 + 64) >> 7)) >> v5);
}
v5 = 0;
if ( v2 <= 0x200000 )
return (unsigned int)(*((int *)&faac_table_pow34 + ((v2 + 64) >> 7)) >> v5);
do
{
v2 >>= 4;
v5 += 3;
}
while ( v2 > 0x200000 );
result = (unsigned int)(*((_DWORD *)&faac_table_pow34 + ((v2 + 64) >> 7)) << v5);
}
return result;
}

variable_types: x int


decompiled_code:
void faac_fixed_init()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void faac_fixed_init()
{
}

canonical_original_code:
void faac_fixed_init()
{
}