decompiled_code:
__int64 __fastcall nmea_gen_init(__int64 a1, int *a2)
{
__int64 v2; // rbx
int v3; // er12
__int64 result; // rax
__int64 (__fastcall *v5)(__int64, int *); // rdx

v2 = a1;
v3 = *a2;
nmea_zero_INFO(a2);
*a2 = v3;
*((_QWORD *)a2 + 8) = LC19;
*((_QWORD *)a2 + 9) = LC20;
if ( !a1 )
return 1LL;
result = 1LL;
do
{
v5 = *(__int64 (__fastcall **)(__int64, int *))(v2 + 8);
if ( v5 )
result = v5(v2, a2);
v2 = *(_QWORD *)(v2 + 40);
}
while ( (_DWORD)result && v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int *a2)
{
__int64 v2; // rbx
int v3; // er12
__int64 result; // rax
__int64 (__fastcall *v5)(__int64, int *); // rdx

v2 = a1;
v3 = *a2;
nmea_zero_INFO(a2);
*a2 = v3;
*((_QWORD *)a2 + 8) = LC19;
*((_QWORD *)a2 + 9) = LC20;
if ( !a1 )
return 1LL;
result = 1LL;
do
{
v5 = *(__int64 (__fastcall **)(__int64, int *))(v2 + 8);
if ( v5 )
result = v5(v2, a2);
v2 = *(_QWORD *)(v2 + 40);
}
while ( (_DWORD)result && v2 );
return result;
}

original_code:
int nmea_gen_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
    int RetVal = 1; int smask = info->smask;
    nmeaGENERATOR *igen = gen;
    nmea_zero_INFO(info);
    info->smask = smask;
    info->lat = (5001.2621);
    info->lon = (3613.0595);
    while(RetVal && igen)
    {
        if(igen->init_call)
            RetVal = (*igen->init_call)(igen, info);
        igen = igen->next;
    }
    return RetVal;
}

canonical_original_code:
int nmea_gen_init(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    int RetVal = 1; int smask = info->smask;
    struct _nmeaGENERATOR *igen = gen;
    nmea_zero_INFO(info);
    info->smask = smask;
    info->lat = (5001.2621);
    info->lon = (3613.0595);
    while(RetVal && igen)
    {
        if(igen->init_call)
            RetVal = (*igen->init_call)(igen, info);
        igen = igen->next;
    }
    return RetVal;
}

variable_types: RetVal int

variable_types: smask int


repo: yishii/MapTracer

decompiled_code:
__int64 __fastcall nmea_gen_loop(__int64 a1, __int64 a2)
{
__int64 (*v2)(void); // rax
__int64 result; // rax
__int64 v4; // rdi

v2 = *(__int64 (**)(void))(a1 + 16);
if ( v2 )
{
result = v2();
if ( !(_DWORD)result )
return result;
}
else
{
result = 1LL;
}
v4 = *(_QWORD *)(a1 + 40);
if ( v4 )
result = nmea_gen_loop(v4, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
__int64 (*v2)(void); // rax
__int64 result; // rax
__int64 v4; // rdi

v2 = *(__int64 (**)(void))(a1 + 16);
if ( v2 )
{
result = v2();
if ( !(_DWORD)result )
return result;
}
else
{
result = 1LL;
}
v4 = *(_QWORD *)(a1 + 40);
if ( v4 )
result = func14(v4, a2);
return result;
}

original_code:
int nmea_gen_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
    int RetVal = 1;
    if(gen->loop_call)
        RetVal = (*gen->loop_call)(gen, info);
    if(RetVal && gen->next)
        RetVal = nmea_gen_loop(gen->next, info);
    return RetVal;
}

canonical_original_code:
int nmea_gen_loop(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    int RetVal = 1;
    if(gen->loop_call)
        RetVal = (*gen->loop_call)(gen, info);
    if(RetVal && gen->next)
        RetVal = nmea_gen_loop(gen->next, info);
    return RetVal;
}

variable_types: struct _nmeaGENERATOR { void *gen_data; int (*init_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO { int smask; struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } utc; int sig; int fix; double PDOP; double HDOP; double VDOP; double lat; double lon; double elv; double speed; double direction; double declination; struct _nmeaSATINFO { int inuse; int inview; struct _nmeaSATELLITE { int id; int in_use; int elv; int azimuth; int sig; } sat[-1]; } satinfo; } *info); int (*loop_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*reset_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*destroy_call)(struct _nmeaGENERATOR *gen); struct _nmeaGENERATOR *next; } *

variable_types:
info
struct _nmeaINFO *

return_type: int

user_defined_types: struct _nmeaGENERATOR { void *gen_data; int (*init_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*loop_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*reset_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*destroy_call)(struct _nmeaGENERATOR *gen); struct _nmeaGENERATOR *next; }

user_defined_types: struct _nmeaINFO { int smask; struct _nmeaTIME utc; int sig; int fix; double PDOP; double HDOP; double VDOP; double lat; double lon; double elv; double speed; double direction; double declination; struct _nmeaSATINFO satinfo; }

user_defined_types: struct _nmeaSATINFO { int inuse; int inview; struct _nmeaSATELLITE sat[-1]; }


decompiled_code:
__int64 __fastcall nmea_gen_reset(__int64 a1)
{
__int64 (*v1)(void); // rdx
__int64 result; // rax

v1 = *(__int64 (**)(void))(a1 + 24);
result = 1LL;
if ( v1 )
result = v1();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 (*v1)(void); // rdx
__int64 result; // rax

v1 = *(__int64 (**)(void))(a1 + 24);
result = 1LL;
if ( v1 )
result = v1();
return result;
}

original_code:
int nmea_gen_reset(nmeaGENERATOR *gen, nmeaINFO *info)
{
    int RetVal = 1;
    if(gen->reset_call)
        RetVal = (*gen->reset_call)(gen, info);
    return RetVal;
}

canonical_original_code:
int nmea_gen_reset(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    int RetVal = 1;
    if(gen->reset_call)
        RetVal = (*gen->reset_call)(gen, info);
    return RetVal;
}

user_defined_types: struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; }

user_defined_types: struct _nmeaSATELLITE { int id; int in_use; int elv; int azimuth; int sig; }


decompiled_code:
void __fastcall nmea_gen_destroy(_QWORD *a1)
{
void (__fastcall *v1)(_QWORD *); // rax

if ( a1[5] )
{
nmea_gen_destroy();
a1[5] = 0LL;
}
v1 = (void (__fastcall *)(_QWORD *))a1[4];
if ( v1 )
v1(a1);
free(a1);
}

canonical_decompiled_code:
void __fastcall func16(_QWORD *a1)
{
void (__fastcall *v1)(_QWORD *); // rax

if ( a1[5] )
{
func16();
a1[5] = 0LL;
}
v1 = (void (__fastcall *)(_QWORD *))a1[4];
if ( v1 )
v1(a1);
free(a1);
}

original_code:
void nmea_gen_destroy(nmeaGENERATOR *gen)
{
    if(gen->next)
    {
        nmea_gen_destroy(gen->next);
        gen->next = 0;
    }
    if(gen->destroy_call)
        (*gen->destroy_call)(gen);
    free(gen);
}

canonical_original_code:
void nmea_gen_destroy(struct _nmeaGENERATOR *gen)
{
    if(gen->next)
    {
        nmea_gen_destroy(gen->next);
        gen->next = 0;
    }
    if(gen->destroy_call)
        (*gen->destroy_call)(gen);
    free(gen);
}

return_type: void


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

result = *(_QWORD *)(a1 + 40);
if ( result )
return nmea_gen_add(*(_QWORD *)(a1 + 40));
*(_QWORD *)(a1 + 40) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 40);
if ( result )
return func17(*(_QWORD *)(a1 + 40));
*(_QWORD *)(a1 + 40) = a2;
return result;
}

original_code:
void nmea_gen_add(nmeaGENERATOR *to, nmeaGENERATOR *gen)
{
    if(to->next)
        nmea_gen_add(to->next, gen);
    else
        to->next = gen;
}

canonical_original_code:
void nmea_gen_add(struct _nmeaGENERATOR *to, struct _nmeaGENERATOR *gen)
{
    if(to->next)
        nmea_gen_add(to->next, gen);
    else
        to->next = gen;
}

variable_types:
gen
struct _nmeaGENERATOR *


decompiled_code:
__int64 __fastcall nmea_generate_from(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax

result = nmea_gen_loop(a4, a3);
if ( (_DWORD)result )
result = nmea_generate(a1, a2, a3, a5);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax

result = func14(a4, a3);
if ( (_DWORD)result )
result = nmea_generate(a1, a2, a3, a5);
return result;
}

original_code:
int nmea_generate_from(
    char *buff, int buff_sz,
    nmeaINFO *info,
    nmeaGENERATOR *gen,
    int generate_mask
    )
{
    int retval;
    if(0 != (retval = nmea_gen_loop(gen, info)))
        retval = nmea_generate(buff, buff_sz, info, generate_mask);
    return retval;
}

canonical_original_code:
int nmea_generate_from(char *buff, int buff_sz, struct _nmeaINFO *info, struct _nmeaGENERATOR *gen, int generate_mask)
{
    int retval;
    if(0 != (retval = nmea_gen_loop(gen, info)))
        retval = nmea_generate(buff, buff_sz, info, generate_mask);
    return retval;
}

variable_types:
buff
char *

variable_types: struct _nmeaINFO { int smask; struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } utc; int sig; int fix; double PDOP; double HDOP; double VDOP; double lat; double lon; double elv; double speed; double direction; double declination; struct _nmeaSATINFO { int inuse; int inview; struct _nmeaSATELLITE { int id; int in_use; int elv; int azimuth; int sig; } sat[-1]; } satinfo; } *

variable_types: struct _nmeaGENERATOR { void *gen_data; int (*init_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*loop_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*reset_call)(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info); int (*destroy_call)(struct _nmeaGENERATOR *gen); struct _nmeaGENERATOR *next; } *

variable_types: retval int


decompiled_code:
void __fastcall nmea_destroy_generator(_QWORD *a1)
{
nmea_gen_destroy(a1);
}

canonical_decompiled_code:
void __fastcall func21(_QWORD *a1)
{
func16(a1);
}

original_code:
void nmea_destroy_generator(nmeaGENERATOR *gen)
{
    nmea_gen_destroy(gen);
}

canonical_original_code:
void nmea_destroy_generator(struct _nmeaGENERATOR *gen)
{
    nmea_gen_destroy(gen);
}


decompiled_code:
double __fastcall nmea_random(double a1, double a2)
{
return (double)rand() * (a2 - a1) / 2147483647.0 + a1;
}

canonical_decompiled_code:
double __fastcall func10(double a1, double a2)
{
return (double)rand() * (a2 - a1) / 2147483647.0 + a1;
}

original_code:
double nmea_random(double min, double max)
{
    static double rand_max = 2147483647;
    double rand_val = rand();
    double bounds = max - min;
    return min + (rand_val * bounds) / rand_max;
}

variable_types: min double

variable_types: max double

variable_types: bounds double

return_type: double


decompiled_code:
__int64 __fastcall gui_open(char a1, char a2)
{
__int64 result; // rax
const char *v3; // rax
const char *v4; // rax

if ( (int)SDL_Init(32LL) < 0 )
{
v3 = (const char *)SDL_GetError();
printf("SDL_Init failed (%s)\n", v3);
result = 0LL;
}
else
{
cvbs_resolution = a1;
no_gui_mode = a2;
SDL_GetVideoInfo();
if ( cvbs_resolution )
screen = SDL_SetVideoMode(600LL, 400LL, 16LL, 1LL);
else
screen = SDL_SetVideoMode(600LL, 600LL, 16LL, 1LL);
result = 1LL;
if ( !screen )
{
v4 = (const char *)SDL_GetError();
printf("SDL_SetVideoMode failed (%s)\n", v4);
result = 0LL;
}
}
return result;
}

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

if ( (int)SDL_Init(32LL) < 0 )
{
v3 = (const char *)SDL_GetError();
printf("SDL_Init failed (%s)\n", v3);
result = 0LL;
}
else
{
cvbs_resolution = a1;
no_gui_mode = a2;
SDL_GetVideoInfo();
if ( cvbs_resolution )
screen = SDL_SetVideoMode(600LL, 400LL, 16LL, 1LL);
else
screen = SDL_SetVideoMode(600LL, 600LL, 16LL, 1LL);
result = 1LL;
if ( !screen )
{
v4 = (const char *)SDL_GetError();
printf("SDL_SetVideoMode failed (%s)\n", v4);
result = 0LL;
}
}
return result;
}

original_code:
_Bool gui_open(_Bool cvbs,_Bool no_gui)
{
    if (SDL_Init(0x00000020) < 0){
 printf("SDL_Init failed (%s)\n",SDL_GetError());
 return 0;
    }
    cvbs_resolution = cvbs;
    no_gui_mode = no_gui;
    SDL_VideoInfo* vinfo = SDL_GetVideoInfo();
    if(cvbs_resolution == 0){
      screen = SDL_SetVideoMode(600,
    600,
    16,
    0x00000001);
    } else {
      screen = SDL_SetVideoMode(600,
    400,
    16,
    0x00000001);
    }
    if(!screen){
 printf("SDL_SetVideoMode failed (%s)\n",SDL_GetError());
 return(0);
    }
    return 1;
}

canonical_original_code:
_Bool gui_open(_Bool cvbs, _Bool no_gui)
{
    if (SDL_Init(0x00000020) < 0){
 printf("SDL_Init failed (%s)\n",SDL_GetError());
 return 0;
    }
    cvbs_resolution = cvbs;
    no_gui_mode = no_gui;
    struct SDL_VideoInfo *vinfo = SDL_GetVideoInfo();
    if(cvbs_resolution == 0){
      screen = SDL_SetVideoMode(600,
    600,
    16,
    0x00000001);
    } else {
      screen = SDL_SetVideoMode(600,
    400,
    16,
    0x00000001);
    }
    if(!screen){
 printf("SDL_SetVideoMode failed (%s)\n",SDL_GetError());
 return(0);
    }
    return 1;
}

variable_types: struct SDL_VideoInfo { unsigned int hw_available; unsigned int wm_available; unsigned int UnusedBits1; unsigned int UnusedBits2; unsigned int blit_hw; unsigned int blit_hw_CC; unsigned int blit_hw_A; unsigned int blit_sw; unsigned int blit_sw_CC; unsigned int blit_sw_A; unsigned int blit_fill; unsigned int UnusedBits3; unsigned int video_mem; struct SDL_PixelFormat { struct SDL_Palette { int ncolors; struct SDL_Color { unsigned char r; unsigned char g; unsigned char b; unsigned char unused; } *colors; } *palette; unsigned char BitsPerPixel; unsigned char BytesPerPixel; unsigned char Rloss; unsigned char Gloss; unsigned char Bloss; unsigned char Aloss; unsigned char Rshift; unsigned char Gshift; unsigned char Bshift; unsigned char Ashift; unsigned int Rmask; unsigned int Gmask; unsigned int Bmask; unsigned int Amask; unsigned int colorkey; unsigned char alpha; } *vfmt; int current_w; int current_h; } *

user_defined_types: struct SDL_VideoInfo { unsigned int hw_available; unsigned int wm_available; unsigned int UnusedBits1; unsigned int UnusedBits2; unsigned int blit_hw; unsigned int blit_hw_CC; unsigned int blit_hw_A; unsigned int blit_sw; unsigned int blit_sw_CC; unsigned int blit_sw_A; unsigned int blit_fill; unsigned int UnusedBits3; unsigned int video_mem; struct SDL_PixelFormat *vfmt; int current_w; int current_h; }

user_defined_types: struct SDL_PixelFormat { struct SDL_Palette *palette; unsigned char BitsPerPixel; unsigned char BytesPerPixel; unsigned char Rloss; unsigned char Gloss; unsigned char Bloss; unsigned char Aloss; unsigned char Rshift; unsigned char Gshift; unsigned char Bshift; unsigned char Ashift; unsigned int Rmask; unsigned int Gmask; unsigned int Bmask; unsigned int Amask; unsigned int colorkey; unsigned char alpha; }

user_defined_types: struct SDL_Palette { int ncolors; struct SDL_Color *colors; }


decompiled_code:
__int64 gui_close()
{
SDL_Quit();
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
SDL_Quit();
return 1LL;
}

original_code:
_Bool gui_close(void)
{
    SDL_Quit();
    return 1;
}

canonical_original_code:
_Bool gui_close()
{
    SDL_Quit();
    return 1;
}


decompiled_code:
__int64 __fastcall http_draw_callback_jpeg(__int64 a1, unsigned int a2)
{
return showImageFileOnMemory_FullScreen(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
return func3(a1, a2, 0);
}

original_code:
void http_draw_callback_jpeg(void* buff,int len)
{
    showImageFileOnMemory_FullScreen(buff,len,ImageFormat_JPEG);
}

canonical_original_code:
void http_draw_callback_jpeg(void *buff, int len)
{
    showImageFileOnMemory_FullScreen(buff,len,ImageFormat_JPEG);
}

variable_types:
buff
void *

variable_types: len int


decompiled_code:
__int64 __fastcall http_draw_callback_png(__int64 a1, unsigned int a2)
{
return showImageFileOnMemory_FullScreen(a1, a2, 1u);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
return func3(a1, a2, 1u);
}

original_code:
void http_draw_callback_png(void* buff,int len)
{
    showImageFileOnMemory_FullScreen(buff,len,ImageFormat_PNG);
}

canonical_original_code:
void http_draw_callback_png(void *buff, int len)
{
    showImageFileOnMemory_FullScreen(buff,len,ImageFormat_PNG);
}


decompiled_code:
__int64 nmea_printf(void *s, int a2, const char *a3, ...)
{
__int64 result; // rax
int v4; // er13
int v5; // eax
unsigned int v6; // eax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

result = 0LL;
if ( a2 > 0 )
{
va_start(arg, a3);
v4 = vsnprintf((char *)s, a2, a3, arg);
v5 = 0;
if ( v4 > 0 )
{
v6 = nmea_calc_crc((char *)s + 1, v4 - 1);
v5 = snprintf((char *)s + v4, a2 - v4, "*%02x\r\n", v6);
}
result = (unsigned int)(v4 + v5);
if ( (int)result < 0 || a2 < (int)result )
{
memset(s, 32, a2);
result = (unsigned int)a2;
}
}
return result;
}

canonical_decompiled_code:
__int64 func3(void *s, int a2, const char *a3, ...)
{
__int64 result; // rax
int v4; // er13
int v5; // eax
unsigned int v6; // eax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

result = 0LL;
if ( a2 > 0 )
{
va_start(arg, a3);
v4 = vsnprintf((char *)s, a2, a3, arg);
v5 = 0;
if ( v4 > 0 )
{
v6 = func0((char *)s + 1, v4 - 1);
v5 = snprintf((char *)s + v4, a2 - v4, "*%02x\r\n", v6);
}
result = (unsigned int)(v4 + v5);
if ( (int)result < 0 || a2 < (int)result )
{
memset(s, 32, a2);
result = (unsigned int)a2;
}
}
return result;
}

original_code:
int nmea_printf(char *buff, int buff_sz, const char *format, ...)
{
    int retval, add = 0;
    va_list arg_ptr;
    if(buff_sz <= 0)
        return 0;
    __builtin_va_start(arg_ptr,format);
    retval = vsnprintf(buff, buff_sz, format, arg_ptr);
    if(retval > 0)
    {
        add = snprintf(
            buff + retval, buff_sz - retval, "*%02x\r\n",
            nmea_calc_crc(buff + 1, retval - 1));
    }
    retval += add;
    if(retval < 0 || retval > buff_sz)
    {
        memset(buff, ' ', buff_sz);
        retval = buff_sz;
    }
    __builtin_va_end(arg_ptr);
    return retval;
}

canonical_original_code:
int nmea_printf(char *buff, int buff_sz, char *format, ...)
{
    int retval; int add = 0;
    __builtin_va_list arg_ptr;
    if(buff_sz <= 0)
        return 0;
    __builtin_va_start(arg_ptr,format);
    retval = vsnprintf(buff, buff_sz, format, arg_ptr);
    if(retval > 0)
    {
        add = snprintf(
            buff + retval, buff_sz - retval, "*%02x\r\n",
            nmea_calc_crc(buff + 1, retval - 1));
    }
    retval += add;
    if(retval < 0 || retval > buff_sz)
    {
        memset(buff, ' ', buff_sz);
        retval = buff_sz;
    }
    __builtin_va_end(arg_ptr);
    return retval;
}

variable_types:
format
char *

variable_types: add int


decompiled_code:
__int64 __fastcall nmea_calc_crc(char *a1, int a2)
{
char *v2; // rax
__int64 v3; // rsi
unsigned int v4; // edx

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = (__int64)&a1[a2 - 1 + 1];
v4 = 0;
do
v4 ^= *v2++;
while ( v2 != (char *)v3 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, int a2)
{
char *v2; // rax
__int64 v3; // rsi
unsigned int v4; // edx

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = (__int64)&a1[a2 - 1 + 1];
v4 = 0;
do
v4 ^= *v2++;
while ( v2 != (char *)v3 );
return v4;
}

original_code:
int nmea_calc_crc(const char *buff, int buff_sz)
{
    int chsum = 0,
        it;
    for(it = 0; it < buff_sz; ++it)
        chsum ^= (int)buff[it];
    return chsum;
}

canonical_original_code:
int nmea_calc_crc(char *buff, int buff_sz)
{
    int chsum = 0; int it;
    for(it = 0; it < buff_sz; ++it)
        chsum ^= (int)buff[it];
    return chsum;
}

variable_types: chsum int

variable_types: it int


original_code:
int nmea_atoi(const char *str, int str_sz, int radix)
{
    char *tmp_ptr;
    char buff[(256)];
    int res = 0;
    if(str_sz < (256))
    {
        memcpy(&buff[0], str, str_sz);
        buff[str_sz] = '\0';
        res = strtol(&buff[0], &tmp_ptr, radix);
    }
    return res;
}

canonical_original_code:
int nmea_atoi(char *str, int str_sz, int radix)
{
    char *tmp_ptr;
    char buff[-1];
    int res = 0;
    if(str_sz < (256))
    {
        memcpy(&buff[0], str, str_sz);
        buff[str_sz] = '\0';
        res = strtol(&buff[0], &tmp_ptr, radix);
    }
    return res;
}

variable_types:
str
char *

variable_types: radix int

variable_types:
buff
char [-1]

variable_types: res int


original_code:
double nmea_atof(const char *str, int str_sz)
{
    char *tmp_ptr;
    char buff[(256)];
    double res = 0;
    if(str_sz < (256))
    {
        memcpy(&buff[0], str, str_sz);
        buff[str_sz] = '\0';
        res = strtod(&buff[0], &tmp_ptr);
    }
    return res;
}

canonical_original_code:
double nmea_atof(char *str, int str_sz)
{
    char *tmp_ptr;
    char buff[-1];
    double res = 0;
    if(str_sz < (256))
    {
        memcpy(&buff[0], str, str_sz);
        buff[str_sz] = '\0';
        res = strtod(&buff[0], &tmp_ptr);
    }
    return res;
}

variable_types: res double


decompiled_code:
void *nmea_property()
{
return &prop_0;
}

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

original_code:
nmeaPROPERTY * nmea_property()
{
    static nmeaPROPERTY prop = {
        0, 0, (1024)
        };
    return ∝
}

canonical_original_code:
struct _nmeaPROPERTY *nmea_property()
{
    static struct _nmeaPROPERTY prop = {
        0, 0, (1024)
        };
    return ∝
}

return_type: struct _nmeaPROPERTY { void (*trace_func)(char *str, int str_size); void (*error_func)(char *str, int str_size); int parse_buff_size; } *


decompiled_code:
int nmea_trace(char *format, ...)
{
__int64 (__fastcall **v1)(char *, _QWORD); // rax
__int64 (__fastcall *v2)(char *, _QWORD); // rbp
char v4[1032]; // [rsp+0h] [rbp-4E8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-E0h] BYREF

v1 = (__int64 (__fastcall **)(char *, _QWORD))nmea_property();
v2 = *v1;
if ( *v1 )
{
va_start(arg, format);
LODWORD(v1) = vsnprintf(v4, 0x3FFuLL, format, arg);
if ( (int)v1 > 0 )
LODWORD(v1) = v2(v4, (unsigned int)v1);
}
return (int)v1;
}

canonical_decompiled_code:
int func1(char *format, ...)
{
__int64 (__fastcall **v1)(char *, _QWORD); // rax
__int64 (__fastcall *v2)(char *, _QWORD); // rbp
char v4[1032]; // [rsp+0h] [rbp-4E8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-E0h] BYREF

v1 = (__int64 (__fastcall **)(char *, _QWORD))func0();
v2 = *v1;
if ( *v1 )
{
va_start(arg, format);
LODWORD(v1) = vsnprintf(v4, 0x3FFuLL, format, arg);
if ( (int)v1 > 0 )
LODWORD(v1) = v2(v4, (unsigned int)v1);
}
return (int)v1;
}

original_code:
void nmea_trace(const char *str, ...)
{
    int size;
    va_list arg_list;
    char buff[(1024)];
    nmeaTraceFunc func = nmea_property()->trace_func;
    if(func)
    {
        __builtin_va_start(arg_list,str);
        size = vsnprintf(&buff[0], (1024) - 1, str, arg_list);
        __builtin_va_end(arg_list);
        if(size > 0)
            (*func)(&buff[0], size);
    }
}

canonical_original_code:
void nmea_trace(char *str, ...)
{
    int size;
    __builtin_va_list arg_list;
    char buff[-1];
    void (*func)(char *str, int str_size) = nmea_property()->trace_func;
    if(func)
    {
        __builtin_va_start(arg_list,str);
        size = vsnprintf(&buff[0], (1024) - 1, str, arg_list);
        __builtin_va_end(arg_list);
        if(size > 0)
            (*func)(&buff[0], size);
    }
}

variable_types: size int

variable_types:
func
void (*)(char *str, int str_size)


decompiled_code:
int nmea_error(char *format, ...)
{
_QWORD *v1; // rax
__int64 (__fastcall *v2)(char *, _QWORD); // rbp
char v4[1032]; // [rsp+0h] [rbp-4E8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-E0h] BYREF

v1 = nmea_property();
v2 = (__int64 (__fastcall *)(char *, _QWORD))v1[1];
if ( v2 )
{
va_start(arg, format);
LODWORD(v1) = vsnprintf(v4, 0x3FFuLL, format, arg);
if ( (int)v1 > 0 )
LODWORD(v1) = v2(v4, (unsigned int)v1);
}
return (int)v1;
}

canonical_decompiled_code:
int func2(char *format, ...)
{
_QWORD *v1; // rax
__int64 (__fastcall *v2)(char *, _QWORD); // rbp
char v4[1032]; // [rsp+0h] [rbp-4E8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-E0h] BYREF

v1 = func0();
v2 = (__int64 (__fastcall *)(char *, _QWORD))v1[1];
if ( v2 )
{
va_start(arg, format);
LODWORD(v1) = vsnprintf(v4, 0x3FFuLL, format, arg);
if ( (int)v1 > 0 )
LODWORD(v1) = v2(v4, (unsigned int)v1);
}
return (int)v1;
}

original_code:
void nmea_error(const char *str, ...)
{
    int size;
    va_list arg_list;
    char buff[(1024)];
    nmeaErrorFunc func = nmea_property()->error_func;
    if(func)
    {
        __builtin_va_start(arg_list,str);
        size = vsnprintf(&buff[0], (1024) - 1, str, arg_list);
        __builtin_va_end(arg_list);
        if(size > 0)
            (*func)(&buff[0], size);
    }
}

canonical_original_code:
void nmea_error(char *str, ...)
{
    int size;
    __builtin_va_list arg_list;
    char buff[-1];
    void (*func)(char *str, int str_size) = nmea_property()->error_func;
    if(func)
    {
        __builtin_va_start(arg_list,str);
        size = vsnprintf(&buff[0], (1024) - 1, str, arg_list);
        __builtin_va_end(arg_list);
        if(size > 0)
            (*func)(&buff[0], size);
    }
}


decompiled_code:
__int64 __fastcall googlemaps_createUrl_FromLatLon(const char *a1, char *a2, double a3, double a4)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
sprintf(
a2,
"http://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=%d&size=%dx%d&sensor=%s&key=%s",
a3,
a4,
18LL,
600LL,
600LL,
"true",
a1);
printf("%s :[%s]\n", "googlemaps_createUrl_FromLatLon", a2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, char *a2, double a3, double a4)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
sprintf(
a2,
"http://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=%d&size=%dx%d&sensor=%s&key=%s",
a3,
a4,
18LL,
600LL,
600LL,
"true",
a1);
printf("%s :[%s]\n", "googlemaps_createUrl_FromLatLon", a2);
result = 1LL;
}
return result;
}

original_code:
_Bool googlemaps_createUrl_FromLatLon(double lat,double lon,unsigned char* api_key,unsigned char* url)
{
    int zoom = 18;
    int size_x = 600;
    int size_y = 600;
    _Bool sensor = 1;
    if(url == ((void *)0)){
 return(0);
    }
    if(api_key == ((void *)0)){
 return(0);
    }
    sprintf(url,
     "http://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=%d&size=%dx%d&sensor=%s&key=%s",
     lat,
     lon,
     zoom,
     size_x,
     size_y,
     sensor == 1 ? "true" : "false",
     api_key);
    printf("%s :[%s]\n",__func__,url);
    return(1);
}

canonical_original_code:
_Bool googlemaps_createUrl_FromLatLon(double lat, double lon, unsigned char *api_key, unsigned char *url)
{
    int zoom = 18;
    int size_x = 600;
    int size_y = 600;
    _Bool sensor = 1;
    if(url == ((void *)0)){
 return(0);
    }
    if(api_key == ((void *)0)){
 return(0);
    }
    sprintf(url,
     "http://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=%d&size=%dx%d&sensor=%s&key=%s",
     lat,
     lon,
     zoom,
     size_x,
     size_y,
     sensor == 1 ? "true" : "false",
     api_key);
    printf("%s :[%s]\n",__func__,url);
    return(1);
}

variable_types: lat double

variable_types: lon double

variable_types:
url
unsigned char *

variable_types: zoom int


decompiled_code:
__int64 __fastcall googlestreetview_createUrl_FromLatLon(unsigned int a1, const char *a2, char *a3, double a4, double a5)
{
__int64 result; // rax

if ( !a2 )
return 0LL;
result = 0LL;
if ( a3 )
{
sprintf(
a3,
"http://maps.googleapis.com/maps/api/streetview?size=%dx%d&location=%f,%f&sensor=%s&heading=%d&key=%s",
600LL,
600LL,
a4,
a5,
"true",
a1,
a2);
printf("%s :[%s]\n", "googlestreetview_createUrl_FromLatLon", a3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, const char *a2, char *a3, double a4, double a5)
{
__int64 result; // rax

if ( !a2 )
return 0LL;
result = 0LL;
if ( a3 )
{
sprintf(
a3,
"http://maps.googleapis.com/maps/api/streetview?size=%dx%d&location=%f,%f&sensor=%s&heading=%d&key=%s",
600LL,
600LL,
a4,
a5,
"true",
a1,
a2);
printf("%s :[%s]\n", "googlestreetview_createUrl_FromLatLon", a3);
result = 1LL;
}
return result;
}

original_code:
_Bool googlestreetview_createUrl_FromLatLon(double lat,double lon,int heading,unsigned char* api_key,unsigned char* url)
{
    int size_x = 600;
    int size_y = 600;
    _Bool sensor = 1;
    if(url == ((void *)0)){
 return(0);
    }
    if(api_key == ((void *)0)){
 return(0);
    }
    sprintf(url,
     "http://maps.googleapis.com/maps/api/streetview?size=%dx%d&location=%f,%f&sensor=%s&heading=%d&key=%s",
     size_x,
     size_y,
     lat,
     lon,
     sensor == 1 ? "true" : "false",
     heading,
     api_key);
    printf("%s :[%s]\n",__func__,url);
    return(1);
}

canonical_original_code:
_Bool googlestreetview_createUrl_FromLatLon(double lat, double lon, int heading, unsigned char *api_key, unsigned char *url)
{
    int size_x = 600;
    int size_y = 600;
    _Bool sensor = 1;
    if(url == ((void *)0)){
 return(0);
    }
    if(api_key == ((void *)0)){
 return(0);
    }
    sprintf(url,
     "http://maps.googleapis.com/maps/api/streetview?size=%dx%d&location=%f,%f&sensor=%s&heading=%d&key=%s",
     size_x,
     size_y,
     lat,
     lon,
     sensor == 1 ? "true" : "false",
     heading,
     api_key);
    printf("%s :[%s]\n",__func__,url);
    return(1);
}

variable_types: heading int


decompiled_code:
__int64 __fastcall nmea_time_now(__int64 a1)
{
struct tm *v1; // rax
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v1 = gmtime(&timer);
*(_DWORD *)a1 = v1->tm_year;
*(_DWORD *)(a1 + 4) = v1->tm_mon;
*(_DWORD *)(a1 + 8) = v1->tm_mday;
*(_DWORD *)(a1 + 12) = v1->tm_hour;
*(_DWORD *)(a1 + 16) = v1->tm_min;
result = (unsigned int)v1->tm_sec;
*(_QWORD *)(a1 + 20) = (unsigned int)result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
struct tm *v1; // rax
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v1 = gmtime(&timer);
*(_DWORD *)a1 = v1->tm_year;
*(_DWORD *)(a1 + 4) = v1->tm_mon;
*(_DWORD *)(a1 + 8) = v1->tm_mday;
*(_DWORD *)(a1 + 12) = v1->tm_hour;
*(_DWORD *)(a1 + 16) = v1->tm_min;
result = (unsigned int)v1->tm_sec;
*(_QWORD *)(a1 + 20) = (unsigned int)result;
return result;
}

original_code:
void nmea_time_now(nmeaTIME *stm)
{
    time_t lt;
    struct tm *tt;
    time(&lt);
    tt = gmtime(&lt);
    stm->year = tt->tm_year;
    stm->mon = tt->tm_mon;
    stm->day = tt->tm_mday;
    stm->hour = tt->tm_hour;
    stm->min = tt->tm_min;
    stm->sec = tt->tm_sec;
    stm->hsec = 0;
}

canonical_original_code:
void nmea_time_now(struct _nmeaTIME *stm)
{
    long lt;
    struct tm *tt;
    time(&lt);
    tt = gmtime(&lt);
    stm->year = tt->tm_year;
    stm->mon = tt->tm_mon;
    stm->day = tt->tm_mday;
    stm->hour = tt->tm_hour;
    stm->min = tt->tm_min;
    stm->sec = tt->tm_sec;
    stm->hsec = 0;
}

variable_types: struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } *

variable_types: lt long

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


decompiled_code:
__int64 __fastcall nmea_zero_GPGSV(_QWORD *a1)
{
__int64 result; // rax

*a1 = 0LL;
*(_QWORD *)((char *)a1 + 84) = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 92) >> 3));
return result;
}

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

*a1 = 0LL;
*(_QWORD *)((char *)a1 + 84) = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 92) >> 3));
return result;
}

original_code:
void nmea_zero_GPGSV(nmeaGPGSV *pack)
{
    memset(pack, 0, sizeof(nmeaGPGSV));
}

canonical_original_code:
void nmea_zero_GPGSV(struct _nmeaGPGSV *pack)
{
    memset(pack, 0, sizeof(nmeaGPGSV));
}

variable_types: struct _nmeaGPGSV { int pack_count; int pack_index; int sat_count; struct _nmeaSATELLITE { int id; int in_use; int elv; int azimuth; int sig; } sat_data[-1]; } *

user_defined_types: struct _nmeaGPGSV { int pack_count; int pack_index; int sat_count; struct _nmeaSATELLITE sat_data[-1]; }


decompiled_code:
_BOOL8 __fastcall oled_sendPixel(int a1, __int16 a2)
{
char buf[10]; // [rsp+Eh] [rbp-Ah] BYREF

buf[0] = HIBYTE(a2);
buf[1] = a2;
return write(a1, buf, 2uLL) >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1, __int16 a2)
{
char buf[10]; // [rsp+Eh] [rbp-Ah] BYREF

buf[0] = HIBYTE(a2);
buf[1] = a2;
return write(a1, buf, 2uLL) >= 0;
}

original_code:
_Bool oled_sendPixel(int fd,int color)
{
    _Bool ret = 1;
    unsigned char data[2];
    data[0] = color >> 8;
    data[1] = color & 0xff;
    if(write(fd,data,sizeof(data)) < 0){
 ret = 0;
    }
    return(ret);
}

canonical_original_code:
_Bool oled_sendPixel(int fd, int color)
{
    _Bool ret = 1;
    unsigned char data[2];
    data[0] = color >> 8;
    data[1] = color & 0xff;
    if(write(fd,data,sizeof(data)) < 0){
 ret = 0;
    }
    return(ret);
}

variable_types: fd int

variable_types: color int

variable_types:
data
unsigned char [2]


decompiled_code:
__int64 __fastcall oled_transmitFullScreen(int fd, void *buf)
{
char *v2; // rbx

v2 = (char *)buf;
do
{
write(fd, v2, 0x800uLL);
v2 += 2048;
}
while ( v2 != (char *)buf + 12288 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, void *buf)
{
char *v2; // rbx

v2 = (char *)buf;
do
{
write(fd, v2, 0x800uLL);
v2 += 2048;
}
while ( v2 != (char *)buf + 12288 );
return 1LL;
}

original_code:
_Bool oled_transmitFullScreen(int fd,unsigned char* pixmap)
{
    int i;
    _Bool result;
    for(i=0;i<6;i++){
 result = write(fd,pixmap + 2048*i,2048);
 if(result < 0){
     printf("%s : write error\n",__func__);
     return(0);
 }
    }
    return(1);
}

canonical_original_code:
_Bool oled_transmitFullScreen(int fd, unsigned char *pixmap)
{
    int i;
    _Bool result;
    for(i=0;i<6;i++){
 result = write(fd,pixmap + 2048*i,2048);
 if(result < 0){
     printf("%s : write error\n",__func__);
     return(0);
 }
    }
    return(1);
}

variable_types:
pixmap
unsigned char *

variable_types: i int


decompiled_code:
__int64 __fastcall oled_paintFullScreen(int a1, __int16 a2)
{
char *v2; // rax
_BYTE v4[12288]; // [rsp+0h] [rbp-3008h] BYREF
char v5; // [rsp+3000h] [rbp-8h] BYREF

v2 = v4;
do
{
*v2 = HIBYTE(a2);
v2[1] = a2;
v2 += 2;
}
while ( v2 != &v5 );
return oled_transmitFullScreen(a1, v4);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int16 a2)
{
char *v2; // rax
_BYTE v4[12288]; // [rsp+0h] [rbp-3008h] BYREF
char v5; // [rsp+3000h] [rbp-8h] BYREF

v2 = v4;
do
{
*v2 = HIBYTE(a2);
v2[1] = a2;
v2 += 2;
}
while ( v2 != &v5 );
return func1(a1, v4);
}

original_code:
_Bool oled_paintFullScreen(int fd,int color)
{
    int i;
    unsigned char buff[64*96*2];
    unsigned char* p;
    p = buff;
    for(i=0;i<sizeof(buff);i+=2){
 buff[i] = color >> 8;
 buff[i+1] = color & 0xff;
    }
    oled_transmitFullScreen(fd,buff);
}

canonical_original_code:
_Bool oled_paintFullScreen(int fd, int color)
{
    int i;
    unsigned char buff[-1];
    unsigned char *p;
    p = buff;
    for(i=0;i<sizeof(buff);i+=2){
 buff[i] = color >> 8;
 buff[i+1] = color & 0xff;
    }
    oled_transmitFullScreen(fd,buff);
}

variable_types:
buff
unsigned char [-1]

variable_types:
p
unsigned char *


decompiled_code:
__int64 __fastcall oled_setCommandMode(unsigned __int8 a1)
{
return gpiolib_setDataGpio17(a1 ^ 1u);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1)
{
return gpiolib_setDataGpio17(a1 ^ 1u);
}

original_code:
_Bool oled_setCommandMode(_Bool mode)
{
    return (gpiolib_setDataGpio17(!mode));
}


decompiled_code:
__int64 __fastcall oled_init(int fd)
{
__int64 result; // rax
__int64 v2[3]; // [rsp+0h] [rbp-28h] BYREF
char v3; // [rsp+18h] [rbp-10h]

v2[0] = 0xA05F00153F0075AELL;
v2[1] = 0x3FA8A400A200A174LL;
v2[2] = 0x8083808280810F87LL;
v3 = -81;
oled_setCommandMode(1u);
if ( (int)write(fd, v2, 0x19uLL) < 0 )
{
printf("%s : data write error\n", "oled_init");
result = 0LL;
}
else
{
oled_setCommandMode(0);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd)
{
__int64 result; // rax
__int64 v2[3]; // [rsp+0h] [rbp-28h] BYREF
char v3; // [rsp+18h] [rbp-10h]

v2[0] = 0xA05F00153F0075AELL;
v2[1] = 0x3FA8A400A200A174LL;
v2[2] = 0x8083808280810F87LL;
v3 = -81;
func3(1u);
if ( (int)write(fd, v2, 0x19uLL) < 0 )
{
printf("%s : data write error\n", "oled_init");
result = 0LL;
}
else
{
func3(0);
result = 1LL;
}
return result;
}

original_code:
_Bool oled_init(int fd)
{
    unsigned char init_data[] = {
 0xae,
 0x75,0x00,0x3f,
 0x15,0x00,0x5f,
 0xa0,0x74,
 0xa1,0x00,
 0xa2,0x00,
 0xa4,
 0xa8,0x3f,
 0x87,0x0f,
 0x81,0x80,
 0x82,0x80,
 0x83,0x80,
 0xaf
    };
    int result;
    oled_setCommandMode(1);
    result = write(fd,init_data,sizeof(init_data));
    if(result < 0){
 printf("%s : data write error\n",__func__);
 return(0);
    }
    oled_setCommandMode(0);
    return(1);
}

variable_types: result int


decompiled_code:
int oled_main()
{
int v0; // eax
int v1; // ebx
_BYTE v3[12296]; // [rsp+0h] [rbp-3018h] BYREF
int v4; // [rsp+3008h] [rbp-10h] BYREF
char v5; // [rsp+300Eh] [rbp-Ah] BYREF
char v6[9]; // [rsp+300Fh] [rbp-9h] BYREF

v6[0] = 0;
v5 = 8;
v4 = 8000000;
v0 = open("/dev/spidev0.0", 2);
if ( v0 == -1 )
return puts("Device open error");
v1 = v0;
if ( ioctl(v0, 0x40016B01uLL, v6) < 0 )
return printf("error(L%d)\n", 127LL);
if ( ioctl(v1, 0x80016B01uLL, v6) < 0 )
return printf("error(L%d)\n", 132LL);
if ( ioctl(v1, 0x40016B03uLL, &v5) < 0 )
return printf("error(L%d)\n", 138LL);
if ( ioctl(v1, 0x80016B03uLL, &v5) < 0 )
return printf("error(L%d)\n", 143LL);
if ( ioctl(v1, 0x40046B04uLL, &v4) < 0 )
return printf("error(L%d)\n", 149LL);
if ( ioctl(v1, 0x80046B04uLL, &v4) < 0 )
return printf("error(L%d)\n", 154LL);
oled_init(v1);
while ( (unsigned __int8)fb_getTopLeftBuff_for_OLED(v3, 96LL, 64LL) )
{
if ( !(unsigned __int8)oled_transmitFullScreen(v1, v3) )
return printf("%s : oled_transmitFullScreen returns error\n", "oled_main");
}
return printf("%s : fb_getTopLeftBuffer_for_OLED returns error\n", "oled_main");
}

canonical_decompiled_code:
int func5()
{
int v0; // eax
int v1; // ebx
_BYTE v3[12296]; // [rsp+0h] [rbp-3018h] BYREF
int v4; // [rsp+3008h] [rbp-10h] BYREF
char v5; // [rsp+300Eh] [rbp-Ah] BYREF
char v6[9]; // [rsp+300Fh] [rbp-9h] BYREF

v6[0] = 0;
v5 = 8;
v4 = 8000000;
v0 = open("/dev/spidev0.0", 2);
if ( v0 == -1 )
return puts("Device open error");
v1 = v0;
if ( ioctl(v0, 0x40016B01uLL, v6) < 0 )
return printf("error(L%d)\n", 127LL);
if ( ioctl(v1, 0x80016B01uLL, v6) < 0 )
return printf("error(L%d)\n", 132LL);
if ( ioctl(v1, 0x40016B03uLL, &v5) < 0 )
return printf("error(L%d)\n", 138LL);
if ( ioctl(v1, 0x80016B03uLL, &v5) < 0 )
return printf("error(L%d)\n", 143LL);
if ( ioctl(v1, 0x40046B04uLL, &v4) < 0 )
return printf("error(L%d)\n", 149LL);
if ( ioctl(v1, 0x80046B04uLL, &v4) < 0 )
return printf("error(L%d)\n", 154LL);
func4(v1);
while ( (unsigned __int8)fb_getTopLeftBuff_for_OLED(v3, 96LL, 64LL) )
{
if ( !(unsigned __int8)func1(v1, v3) )
return printf("%s : oled_transmitFullScreen returns error\n", "oled_main");
}
return printf("%s : fb_getTopLeftBuffer_for_OLED returns error\n", "oled_main");
}

variable_types:
mode
unsigned char

variable_types:
bits
unsigned char

variable_types:
speed
unsigned int

variable_types:
delay
unsigned short


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax

if ( (unsigned __int8)gpiolib_init(argc, argv, envp) )
{
gpiolib_setDirectionGpio17(0LL);
if ( (unsigned __int8)fb_init() )
{
oled_main();
result = 0;
}
else
{
puts("fb init error");
result = -1;
}
}
else
{
puts("gpiolib init error");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax

if ( (unsigned __int8)gpiolib_init(argc, argv, envp) )
{
gpiolib_setDirectionGpio17(0LL);
if ( (unsigned __int8)fb_init() )
{
func5();
result = 0;
}
else
{
puts("fb init error");
result = -1;
}
}
else
{
puts("gpiolib init error");
result = -1;
}
return result;
}

original_code:
int main(int argc,char** argv)
{
    _Bool result;
    result = gpiolib_init();
    if(result != 1){
 printf("gpiolib init error\n");
 return(-1);
    }
    gpiolib_setDirectionGpio17(0);
    result = fb_init();
    if(result != 1){
 printf("fb init error\n");
 return(-1);
    }
    oled_main();
}

canonical_original_code:
int main(int argc, char **argv)
{
    _Bool result;
    result = gpiolib_init();
    if(result != 1){
 printf("gpiolib init error\n");
 return(-1);
    }
    gpiolib_setDirectionGpio17(0);
    result = fb_init();
    if(result != 1){
 printf("fb init error\n");
 return(-1);
    }
    oled_main();
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 gpiolib_init()
{
int v0; // eax
int v1; // ebx
__int64 result; // rax

v0 = open("/dev/mem", 1052674);
if ( v0 < 0 )
{
printf("%s : memory open error\n", "gpiolib_init");
result = 0LL;
}
else
{
v1 = v0;
gpio_mem = (__int64)mmap(0LL, 0x1000uLL, 3, 1, v0, 538968064LL);
close(v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
int v1; // ebx
__int64 result; // rax

v0 = open("/dev/mem", 1052674);
if ( v0 < 0 )
{
printf("%s : memory open error\n", "gpiolib_init");
result = 0LL;
}
else
{
v1 = v0;
gpio_mem = (__int64)mmap(0LL, 0x1000uLL, 3, 1, v0, 538968064LL);
close(v1);
result = 1LL;
}
return result;
}

original_code:
_Bool gpiolib_init(void)
{
    int memfd;
    _Bool ret = 0;
    memfd = open("/dev/mem",02|04010000);
    if(memfd < 0){
 printf("%s : memory open error\n",__func__);
    } else {
 gpio_mem = mmap(((void *)0),(1024*4),0x1|0x2,0x01,memfd,((0x20000000) + 0x200000));
 close(memfd);
 ret = 1;
    }
    return(ret);
}

canonical_original_code:
_Bool gpiolib_init()
{
    int memfd;
    _Bool ret = 0;
    memfd = open("/dev/mem",02|04010000);
    if(memfd < 0){
 printf("%s : memory open error\n",__func__);
    } else {
 gpio_mem = mmap(((void *)0),(1024*4),0x1|0x2,0x01,memfd,((0x20000000) + 0x200000));
 close(memfd);
 ret = 1;
    }
    return(ret);
}

variable_types: memfd int


decompiled_code:
__int64 __fastcall gpiolib_setDirectionGpio17(char a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = gpio_mem;
v2 = 0;
if ( gpio_mem )
{
*(_DWORD *)(gpio_mem + 4) &= 0xFF1FFFFF;
v2 = 0;
if ( !a1 )
{
*(_DWORD *)(v1 + 4) |= 0x200000u;
v2 = 1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = gpio_mem;
v2 = 0;
if ( gpio_mem )
{
*(_DWORD *)(gpio_mem + 4) &= 0xFF1FFFFF;
v2 = 0;
if ( !a1 )
{
*(_DWORD *)(v1 + 4) |= 0x200000u;
v2 = 1;
}
}
return v2;
}


decompiled_code:
__int64 __fastcall gpiolib_setDataGpio17(char a1)
{
if ( gpio_mem )
{
if ( a1 )
*(_DWORD *)(gpio_mem + 28) = 0x20000;
else
*(_DWORD *)(gpio_mem + 40) = 0x20000;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
if ( gpio_mem )
{
if ( a1 )
*(_DWORD *)(gpio_mem + 28) = 0x20000;
else
*(_DWORD *)(gpio_mem + 40) = 0x20000;
}
return 0LL;
}

original_code:
_Bool gpiolib_setDataGpio17(_Bool level)
{
    _Bool ret = 0;
    if(gpio_mem != ((void *)0)){
 if(level == 1){
     *(gpio_mem+7) = 1 << 17;
 } else {
     *(gpio_mem+10) = 1 << 17;
 }
    }
    return(ret);
}


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

switch ( a1 )
{
case 9:
result = 6LL;
break;
case 11:
case 13:
result = 5LL;
break;
case 32:
result = 4LL;
break;
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
result = 0LL;
break;
case 45:
result = 7LL;
break;
case 46:
result = 3LL;
break;
case 47:
result = 0LL;
break;
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
result = 1LL;
break;
case 58:
case 59:
case 60:
case 61:
case 62:
case 63:
case 64:
result = 0LL;
break;
case 65:
case 66:
case 67:
case 68:
case 69:
case 70:
case 71:
case 72:
case 73:
case 74:
case 75:
case 76:
case 77:
case 78:
case 79:
case 80:
case 81:
case 82:
case 83:
case 84:
case 85:
case 86:
case 87:
case 88:
case 89:
case 90:
result = 2LL;
break;
case 91:
case 92:
case 93:
case 94:
case 95:
case 96:
result = 0LL;
break;
case 97:
case 98:
case 99:
case 100:
case 101:
case 102:
case 103:
case 104:
case 105:
case 106:
case 107:
case 108:
case 109:
case 110:
case 111:
case 112:
case 113:
case 114:
case 115:
case 116:
case 117:
case 118:
case 119:
case 120:
case 121:
case 122:
result = 2LL;
break;
case 123:
case 124:
case 125:
result = 0LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 9:
result = 6LL;
break;
case 11:
case 13:
result = 5LL;
break;
case 32:
result = 4LL;
break;
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
result = 0LL;
break;
case 45:
result = 7LL;
break;
case 46:
result = 3LL;
break;
case 47:
result = 0LL;
break;
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
result = 1LL;
break;
case 58:
case 59:
case 60:
case 61:
case 62:
case 63:
case 64:
result = 0LL;
break;
case 65:
case 66:
case 67:
case 68:
case 69:
case 70:
case 71:
case 72:
case 73:
case 74:
case 75:
case 76:
case 77:
case 78:
case 79:
case 80:
case 81:
case 82:
case 83:
case 84:
case 85:
case 86:
case 87:
case 88:
case 89:
case 90:
result = 2LL;
break;
case 91:
case 92:
case 93:
case 94:
case 95:
case 96:
result = 0LL;
break;
case 97:
case 98:
case 99:
case 100:
case 101:
case 102:
case 103:
case 104:
case 105:
case 106:
case 107:
case 108:
case 109:
case 110:
case 111:
case 112:
case 113:
case 114:
case 115:
case 116:
case 117:
case 118:
case 119:
case 120:
case 121:
case 122:
result = 2LL;
break;
case 123:
case 124:
case 125:
result = 0LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
inline static xi_char_type_t csv_classify_char( char c )
{
    switch( c )
    {
        case 13:
        case 11:
            return XI_CHAR_NEWLINE;
        case 9:
            return XI_CHAR_TAB;
        case 32:
            return XI_CHAR_SPACE;
        case 33: case 34: case 35: case 36: case 37: case 38: case 39:
        case 40: case 41: case 42: case 43: case 44:
            return XI_CHAR_UNKNOWN;
        case 45:
            return XI_CHAR_MINUS;
        case 46:
            return XI_CHAR_DOT;
        case 47:
            return XI_CHAR_UNKNOWN;
        case 48: case 49: case 50: case 51: case 52: case 53: case 54:
        case 55: case 56:
        case 57:
            return XI_CHAR_NUMBER;
        case 58: case 59: case 60: case 61: case 62: case 63:
        case 64:
            return XI_CHAR_UNKNOWN;
        case 65: case 66: case 67: case 68: case 69: case 70: case 71:
        case 72: case 73: case 74: case 75: case 76: case 77: case 78:
        case 79: case 80: case 81: case 82: case 83: case 84: case 85:
        case 86: case 87: case 88: case 89:
        case 90:
            return XI_CHAR_LETTER;
        case 91: case 92: case 93: case 94: case 95:
        case 96:
            return XI_CHAR_UNKNOWN;
        case 97: case 98: case 99: case 100: case 101: case 102: case 103:
        case 104: case 105: case 106: case 107: case 108: case 109: case 110:
        case 111: case 112: case 113: case 114: case 115: case 116: case 117:
        case 118: case 119: case 120: case 121:
        case 122:
            return XI_CHAR_LETTER;
        case 123:
        case 124:
        case 125:
            return XI_CHAR_UNKNOWN;
        default:
            return XI_CHAR_UNKNOWN;
    }
}

canonical_original_code:
inline static enum xi_char_type_t csv_classify_char(char c)
{
    switch( c )
    {
        case 13:
        case 11:
            return XI_CHAR_NEWLINE;
        case 9:
            return XI_CHAR_TAB;
        case 32:
            return XI_CHAR_SPACE;
        case 33: case 34: case 35: case 36: case 37: case 38: case 39:
        case 40: case 41: case 42: case 43: case 44:
            return XI_CHAR_UNKNOWN;
        case 45:
            return XI_CHAR_MINUS;
        case 46:
            return XI_CHAR_DOT;
        case 47:
            return XI_CHAR_UNKNOWN;
        case 48: case 49: case 50: case 51: case 52: case 53: case 54:
        case 55: case 56:
        case 57:
            return XI_CHAR_NUMBER;
        case 58: case 59: case 60: case 61: case 62: case 63:
        case 64:
            return XI_CHAR_UNKNOWN;
        case 65: case 66: case 67: case 68: case 69: case 70: case 71:
        case 72: case 73: case 74: case 75: case 76: case 77: case 78:
        case 79: case 80: case 81: case 82: case 83: case 84: case 85:
        case 86: case 87: case 88: case 89:
        case 90:
            return XI_CHAR_LETTER;
        case 91: case 92: case 93: case 94: case 95:
        case 96:
            return XI_CHAR_UNKNOWN;
        case 97: case 98: case 99: case 100: case 101: case 102: case 103:
        case 104: case 105: case 106: case 107: case 108: case 109: case 110:
        case 111: case 112: case 113: case 114: case 115: case 116: case 117:
        case 118: case 119: case 120: case 121:
        case 122:
            return XI_CHAR_LETTER;
        case 123:
        case 124:
        case 125:
            return XI_CHAR_UNKNOWN;
        default:
            return XI_CHAR_UNKNOWN;
    }
}

variable_types: c char

return_type: enum xi_char_type_t { XI_CHAR_UNKNOWN=0, XI_CHAR_NUMBER=1, XI_CHAR_LETTER=2, XI_CHAR_DOT=3, XI_CHAR_SPACE=4, XI_CHAR_NEWLINE=5, XI_CHAR_TAB=6, XI_CHAR_MINUS=7 }


decompiled_code:
int __fastcall csv_encode_value(char *a1, size_t a2, const char *a3)
{
int v4; // edx
int result; // eax

if ( !a1 )
_assert_fail("buffer != 0", "csv_data.c", 0x1Cu, "csv_encode_value");
if ( !a2 )
_assert_fail("buffer_size != 0", "csv_data.c", 0x1Du, "csv_encode_value");
if ( !a3 )
_assert_fail("p != 0", "csv_data.c", 0x1Eu, "csv_encode_value");
v4 = *((_DWORD *)a3 + 8);
if ( v4 == 1 )
return snprintf(a1, a2, "%f", *(float *)a3);
if ( v4 == 2 )
return snprintf(a1, a2, "%s", a3);
result = -1;
if ( !v4 )
result = snprintf(a1, a2, "%d", *(unsigned int *)a3);
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *a1, size_t a2, const char *a3)
{
int v4; // edx
int result; // eax

if ( !a1 )
_assert_fail("buffer != 0", "csv_data.c", 0x1Cu, "csv_encode_value");
if ( !a2 )
_assert_fail("buffer_size != 0", "csv_data.c", 0x1Du, "csv_encode_value");
if ( !a3 )
_assert_fail("p != 0", "csv_data.c", 0x1Eu, "csv_encode_value");
v4 = *((_DWORD *)a3 + 8);
if ( v4 == 1 )
return snprintf(a1, a2, "%f", *(float *)a3);
if ( v4 == 2 )
return snprintf(a1, a2, "%s", a3);
result = -1;
if ( !v4 )
result = snprintf(a1, a2, "%d", *(unsigned int *)a3);
return result;
}

original_code:
inline static int csv_encode_value(
      char* buffer
    , size_t buffer_size
    , const xi_datapoint_t* p )
{
    ((void) sizeof ((buffer != 0) ? 1 : 0), __extension__ ({ if (buffer != 0) ; else __assert_fail ("buffer != 0", "csv_data.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((buffer_size != 0) ? 1 : 0), __extension__ ({ if (buffer_size != 0) ; else __assert_fail ("buffer_size != 0", "csv_data.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((p != 0) ? 1 : 0), __extension__ ({ if (p != 0) ; else __assert_fail ("p != 0", "csv_data.c", 30, __extension__ __PRETTY_FUNCTION__); }));
    switch( p->value_type )
    {
        case XI_VALUE_TYPE_I32:
            return snprintf( buffer, buffer_size, "%d", p->value.i32_value );
        case XI_VALUE_TYPE_F32:
            return snprintf( buffer, buffer_size, "%f", p->value.f32_value );
        case XI_VALUE_TYPE_STR:
            return snprintf( buffer, buffer_size, "%s", p->value.str_value );
        default:
            return -1;
    }
}

canonical_original_code:
inline static int csv_encode_value(char *buffer, unsigned long buffer_size, struct xi_datapoint_t *p)
{
    ((void) sizeof ((buffer != 0) ? 1 : 0), __extension__ ({ if (buffer != 0) ; else __assert_fail ("buffer != 0", "csv_data.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((buffer_size != 0) ? 1 : 0), __extension__ ({ if (buffer_size != 0) ; else __assert_fail ("buffer_size != 0", "csv_data.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((p != 0) ? 1 : 0), __extension__ ({ if (p != 0) ; else __assert_fail ("p != 0", "csv_data.c", 30, __extension__ __PRETTY_FUNCTION__); }));
    switch( p->value_type )
    {
        case XI_VALUE_TYPE_I32:
            return snprintf( buffer, buffer_size, "%d", p->value.i32_value );
        case XI_VALUE_TYPE_F32:
            return snprintf( buffer, buffer_size, "%f", p->value.f32_value );
        case XI_VALUE_TYPE_STR:
            return snprintf( buffer, buffer_size, "%s", p->value.str_value );
        default:
            return -1;
    }
}

variable_types:
buffer
char *

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

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 __fastcall csv_decode_value(_BYTE *a1, __int64 a2)
{
unsigned __int64 v2; // r12
__int16 v3; // bx
unsigned __int64 v4; // rbp
__int64 v6; // r15
float v7; // xmm0_4

if ( !a1 )
_assert_fail("buffer != 0", "csv_data.c", 0x7Au, "csv_decode_value");
if ( !a2 )
_assert_fail("p != 0", "csv_data.c", 0x7Bu, "csv_decode_value");
*(_BYTE *)(a2 + 31) = 0;
LOBYTE(v2) = *a1;
if ( *a1 > 0xDu )
{
v3 = 0;
v4 = 0LL;
}
else
{
v3 = 0;
v4 = (0x2401uLL >> v2) & 1;
if ( ((0x2401uLL >> v2) & 1) != 0 )
{
*(_BYTE *)a2 = 0;
LABEL_6:
*(_DWORD *)(a2 + 32) = 2;
return a2;
}
}
v6 = 9217LL;
while ( 1 )
{
v3 = word_C22[12 * (unsigned int)csv_classify_char(v2) + 2 * v3];
if ( (unsigned int)(v3 - 1) <= 4 )
*(_BYTE *)(a2 + v4) = v2;
v2 = (unsigned __int8)a1[++v4];
if ( (unsigned __int8)v2 <= 0xDu )
{
if ( _bittest64(&v6, v2) )
break;
}
if ( v4 == 31 )
{
xi_set_err(26LL);
return 0LL;
}
}
*(_BYTE *)(a2 + v4) = 0;
if ( v3 <= 1 || v3 == 4 )
goto LABEL_6;
if ( v3 == 2 )
{
*(_DWORD *)a2 = atoi((const char *)a2);
*(_DWORD *)(a2 + 32) = 0;
return a2;
}
if ( v3 != 3 )
goto LABEL_6;
v7 = atof((const char *)a2);
*(float *)a2 = v7;
*(_DWORD *)(a2 + 32) = 1;
return a2;
}

original_code:
xi_datapoint_t* csv_decode_value(
    const char* buffer, xi_datapoint_t* p )
{
    ((void) sizeof ((buffer != 0) ? 1 : 0), __extension__ ({ if (buffer != 0) ; else __assert_fail ("buffer != 0", "csv_data.c", 122, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((p != 0) ? 1 : 0), __extension__ ({ if (p != 0) ; else __assert_fail ("p != 0", "csv_data.c", 123, __extension__ __PRETTY_FUNCTION__); }));
    { (p->value.str_value)[ (32) - 1 ] = '\0'; };
    size_t counter = 0;
    static const short states[][6][2] =
    {
        { { XI_CHAR_UNKNOWN , XI_STATE_STRING }, { XI_CHAR_UNKNOWN , XI_STATE_STRING }, { XI_CHAR_UNKNOWN , XI_STATE_STRING }, { XI_CHAR_UNKNOWN , XI_STATE_STRING }, { XI_CHAR_UNKNOWN , XI_STATE_STRING }, { XI_CHAR_UNKNOWN , XI_STATE_STRING } },
        { { XI_CHAR_NUMBER , XI_STATE_NUMBER }, { XI_CHAR_NUMBER , XI_STATE_NUMBER }, { XI_CHAR_NUMBER , XI_STATE_NUMBER }, { XI_CHAR_NUMBER , XI_STATE_FLOAT }, { XI_CHAR_NUMBER , XI_STATE_FLOAT }, { XI_CHAR_NUMBER , XI_STATE_STRING } },
        { { XI_CHAR_LETTER , XI_STATE_STRING }, { XI_CHAR_LETTER , XI_STATE_STRING }, { XI_CHAR_LETTER , XI_STATE_STRING }, { XI_CHAR_LETTER , XI_STATE_STRING }, { XI_CHAR_LETTER , XI_STATE_STRING }, { XI_CHAR_LETTER , XI_STATE_STRING } },
        { { XI_CHAR_DOT , XI_STATE_DOT }, { XI_CHAR_DOT , XI_STATE_DOT }, { XI_CHAR_DOT , XI_STATE_DOT }, { XI_CHAR_DOT , XI_STATE_STRING }, { XI_CHAR_DOT , XI_STATE_STRING }, { XI_CHAR_DOT , XI_STATE_STRING } },
        { { XI_CHAR_SPACE , XI_STATE_STRING }, { XI_CHAR_SPACE , XI_STATE_STRING }, { XI_CHAR_SPACE , XI_STATE_STRING }, { XI_CHAR_SPACE , XI_STATE_STRING }, { XI_CHAR_SPACE , XI_STATE_STRING }, { XI_CHAR_SPACE , XI_STATE_STRING } },
        { { XI_CHAR_NEWLINE , XI_STATE_INITIAL }, { XI_CHAR_NEWLINE , XI_STATE_INITIAL }, { XI_CHAR_NEWLINE , XI_STATE_INITIAL }, { XI_CHAR_NEWLINE , XI_STATE_INITIAL }, { XI_CHAR_NEWLINE , XI_STATE_INITIAL }, { XI_CHAR_NEWLINE , XI_STATE_INITIAL } },
        { { XI_CHAR_TAB , XI_STATE_STRING }, { XI_CHAR_TAB , XI_STATE_STRING }, { XI_CHAR_TAB , XI_STATE_STRING }, { XI_CHAR_TAB , XI_STATE_STRING }, { XI_CHAR_TAB , XI_STATE_STRING }, { XI_CHAR_TAB , XI_STATE_STRING } },
        { { XI_CHAR_MINUS , XI_STATE_MINUS }, { XI_CHAR_MINUS , XI_STATE_STRING }, { XI_CHAR_MINUS , XI_STATE_STRING }, { XI_CHAR_MINUS , XI_STATE_STRING }, { XI_CHAR_MINUS , XI_STATE_STRING }, { XI_CHAR_MINUS , XI_STATE_STRING } }
    };
    char c = *buffer;
    short s = XI_STATE_INITIAL;
    while( c != '\n' && c !='\0' && c!='\r' )
    {
        if( counter >= 32 - 1 )
        {
            xi_set_err( XI_DATAPOINT_VALUE_BUFFER_OVERFLOW );
            return 0;
        }
        xi_char_type_t ct = csv_classify_char( c );
        s = states[ ct ][ s ][ 1 ];
        switch( s )
        {
            case XI_STATE_MINUS:
            case XI_STATE_NUMBER:
            case XI_STATE_FLOAT:
            case XI_STATE_DOT:
            case XI_STATE_STRING:
                p->value.str_value[ counter ] = c;
                break;
        }
        c = *( ++buffer );
        ++counter;
    }
    p->value.str_value[ counter ] = '\0';
    switch( s )
    {
        case XI_STATE_MINUS:
        case XI_STATE_DOT:
        case XI_STATE_INITIAL:
            s = XI_STATE_STRING;
            break;
    }
    switch( s )
    {
        case XI_STATE_NUMBER:
            p->value.i32_value = atoi( p->value.str_value );
            p->value_type = XI_VALUE_TYPE_I32;
            break;
        case XI_STATE_FLOAT:
            p->value.f32_value = atof( p->value.str_value );
            p->value_type = XI_VALUE_TYPE_F32;
            break;
        case XI_STATE_STRING:
        default:
            p->value_type = XI_VALUE_TYPE_STR;
    }
    return p;
}

canonical_original_code:
struct xi_datapoint_t *csv_decode_value(char *buffer, struct xi_datapoint_t *p)
{
    ((void) sizeof ((buffer != 0) ? 1 : 0), __extension__ ({ if (buffer != 0) ; else __assert_fail ("buffer != 0", "csv_data.c", 122, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((p != 0) ? 1 : 0), __extension__ ({ if (p != 0) ; else __assert_fail ("p != 0", "csv_data.c", 123, __extension__ __PRETTY_FUNCTION__); }));
    { (p->value.str_value)[ (32) - 1 ] = '\0'; };
    unsigned long counter = 0;
    static short states[][6][2] = {
        { { XI_CHAR_UNKNOWN , XI_STATE_STRING }, { XI_CHAR_UNKNOWN , XI_STATE_STRING }, { XI_CHAR_UNKNOWN , XI_STATE_STRING }, { XI_CHAR_UNKNOWN , XI_STATE_STRING }, { XI_CHAR_UNKNOWN , XI_STATE_STRING }, { XI_CHAR_UNKNOWN , XI_STATE_STRING } },
        { { XI_CHAR_NUMBER , XI_STATE_NUMBER }, { XI_CHAR_NUMBER , XI_STATE_NUMBER }, { XI_CHAR_NUMBER , XI_STATE_NUMBER }, { XI_CHAR_NUMBER , XI_STATE_FLOAT }, { XI_CHAR_NUMBER , XI_STATE_FLOAT }, { XI_CHAR_NUMBER , XI_STATE_STRING } },
        { { XI_CHAR_LETTER , XI_STATE_STRING }, { XI_CHAR_LETTER , XI_STATE_STRING }, { XI_CHAR_LETTER , XI_STATE_STRING }, { XI_CHAR_LETTER , XI_STATE_STRING }, { XI_CHAR_LETTER , XI_STATE_STRING }, { XI_CHAR_LETTER , XI_STATE_STRING } },
        { { XI_CHAR_DOT , XI_STATE_DOT }, { XI_CHAR_DOT , XI_STATE_DOT }, { XI_CHAR_DOT , XI_STATE_DOT }, { XI_CHAR_DOT , XI_STATE_STRING }, { XI_CHAR_DOT , XI_STATE_STRING }, { XI_CHAR_DOT , XI_STATE_STRING } },
        { { XI_CHAR_SPACE , XI_STATE_STRING }, { XI_CHAR_SPACE , XI_STATE_STRING }, { XI_CHAR_SPACE , XI_STATE_STRING }, { XI_CHAR_SPACE , XI_STATE_STRING }, { XI_CHAR_SPACE , XI_STATE_STRING }, { XI_CHAR_SPACE , XI_STATE_STRING } },
        { { XI_CHAR_NEWLINE , XI_STATE_INITIAL }, { XI_CHAR_NEWLINE , XI_STATE_INITIAL }, { XI_CHAR_NEWLINE , XI_STATE_INITIAL }, { XI_CHAR_NEWLINE , XI_STATE_INITIAL }, { XI_CHAR_NEWLINE , XI_STATE_INITIAL }, { XI_CHAR_NEWLINE , XI_STATE_INITIAL } },
        { { XI_CHAR_TAB , XI_STATE_STRING }, { XI_CHAR_TAB , XI_STATE_STRING }, { XI_CHAR_TAB , XI_STATE_STRING }, { XI_CHAR_TAB , XI_STATE_STRING }, { XI_CHAR_TAB , XI_STATE_STRING }, { XI_CHAR_TAB , XI_STATE_STRING } },
        { { XI_CHAR_MINUS , XI_STATE_MINUS }, { XI_CHAR_MINUS , XI_STATE_STRING }, { XI_CHAR_MINUS , XI_STATE_STRING }, { XI_CHAR_MINUS , XI_STATE_STRING }, { XI_CHAR_MINUS , XI_STATE_STRING }, { XI_CHAR_MINUS , XI_STATE_STRING } }
    };
    char c = *buffer;
    short s = XI_STATE_INITIAL;
    while( c != '\n' && c !='\0' && c!='\r' )
    {
        if( counter >= 32 - 1 )
        {
            xi_set_err( XI_DATAPOINT_VALUE_BUFFER_OVERFLOW );
            return 0;
        }
        enum xi_char_type_t ct = csv_classify_char( c );
        s = states[ ct ][ s ][ 1 ];
        switch( s )
        {
            case XI_STATE_MINUS:
            case XI_STATE_NUMBER:
            case XI_STATE_FLOAT:
            case XI_STATE_DOT:
            case XI_STATE_STRING:
                p->value.str_value[ counter ] = c;
                break;
        }
        c = *( ++buffer );
        ++counter;
    }
    p->value.str_value[ counter ] = '\0';
    switch( s )
    {
        case XI_STATE_MINUS:
        case XI_STATE_DOT:
        case XI_STATE_INITIAL:
            s = XI_STATE_STRING;
            break;
    }
    switch( s )
    {
        case XI_STATE_NUMBER:
            p->value.i32_value = atoi( p->value.str_value );
            p->value_type = XI_VALUE_TYPE_I32;
            break;
        case XI_STATE_FLOAT:
            p->value.f32_value = atof( p->value.str_value );
            p->value_type = XI_VALUE_TYPE_F32;
            break;
        case XI_STATE_STRING:
        default:
            p->value_type = XI_VALUE_TYPE_STR;
    }
    return p;
}

variable_types:
p
struct xi_datapoint_t *

variable_types:
counter
unsigned long

variable_types:
states
short [][6][2]

variable_types: s short

variable_types: enum xi_char_type_t { XI_CHAR_UNKNOWN=0, XI_CHAR_NUMBER=1, XI_CHAR_LETTER=2, XI_CHAR_DOT=3, XI_CHAR_SPACE=4, XI_CHAR_NEWLINE=5, XI_CHAR_TAB=6, XI_CHAR_MINUS=7 }

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


decompiled_code:
__int64 __fastcall csv_encode_datapoint_in_place(char *s, int a2, __int64 a3)
{
unsigned int *v4; // rax
int v5; // eax
int v6; // ebp
int v7; // eax
int v8; // ebp
__int64 v10[6]; // [rsp+8h] [rbp-30h] BYREF

if ( !s )
_assert_fail("in != 0", "csv_data.c", 0xDBu, "csv_encode_datapoint_in_place");
if ( !a3 )
_assert_fail("datapoint != 0", "csv_data.c", 0xDCu, "csv_encode_datapoint_in_place");
if ( *(_QWORD *)(a3 + 40) )
{
v10[0] = *(_QWORD *)(a3 + 40);
v4 = (unsigned int *)xi_gmtime(v10);
v5 = snprintf(
s,
a2,
"%04d-%02d-%02dT%02d:%02d:%02d.%06dZ,",
v4[5] + 1900,
v4[4] + 1,
v4[3],
v4[2],
v4[1],
*v4,
*(_QWORD *)(a3 + 48));
v6 = v5;
if ( v5 < 0 || v5 >= a2 )
goto LABEL_14;
}
else
{
v6 = 0;
}
v7 = csv_encode_value(&s[v6], a2 - v6, (const char *)a3);
if ( v7 >= 0 && a2 - v6 > v7 )
{
v8 = v7 + v6;
snprintf(&s[v8], a2 - v8, "%s", "\n");
if ( a2 - v8 > 1 )
return (unsigned int)(v8 + 1);
}
LABEL_14:
xi_set_err(14LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, int a2, __int64 a3)
{
unsigned int *v4; // rax
int v5; // eax
int v6; // ebp
int v7; // eax
int v8; // ebp
__int64 v10[6]; // [rsp+8h] [rbp-30h] BYREF

if ( !s )
_assert_fail("in != 0", "csv_data.c", 0xDBu, "csv_encode_datapoint_in_place");
if ( !a3 )
_assert_fail("datapoint != 0", "csv_data.c", 0xDCu, "csv_encode_datapoint_in_place");
if ( *(_QWORD *)(a3 + 40) )
{
v10[0] = *(_QWORD *)(a3 + 40);
v4 = (unsigned int *)xi_gmtime(v10);
v5 = snprintf(
s,
a2,
"%04d-%02d-%02dT%02d:%02d:%02d.%06dZ,",
v4[5] + 1900,
v4[4] + 1,
v4[3],
v4[2],
v4[1],
*v4,
*(_QWORD *)(a3 + 48));
v6 = v5;
if ( v5 < 0 || v5 >= a2 )
goto LABEL_14;
}
else
{
v6 = 0;
}
v7 = func1(&s[v6], a2 - v6, (const char *)a3);
if ( v7 >= 0 && a2 - v6 > v7 )
{
v8 = v7 + v6;
snprintf(&s[v8], a2 - v8, "%s", "\n");
if ( a2 - v8 > 1 )
return (unsigned int)(v8 + 1);
}
LABEL_14:
xi_set_err(14LL);
return 0xFFFFFFFFLL;
}

original_code:
int csv_encode_datapoint_in_place(
      char* in, size_t in_size
    , const xi_datapoint_t* datapoint )
{
    ((void) sizeof ((in != 0) ? 1 : 0), __extension__ ({ if (in != 0) ; else __assert_fail ("in != 0", "csv_data.c", 219, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((datapoint != 0) ? 1 : 0), __extension__ ({ if (datapoint != 0) ; else __assert_fail ("datapoint != 0", "csv_data.c", 220, __extension__ __PRETTY_FUNCTION__); }));
    int s = 0;
    int size = in_size;
    int offset = 0;
    if( datapoint->timestamp.timestamp != 0 )
    {
        time_t stamp = datapoint->timestamp.timestamp;
        struct tm* gmtinfo = xi_gmtime( &stamp );
        s = snprintf( in, size
            , "%04d-%02d-%02dT%02d:%02d:%02d.%06dZ,"
            , gmtinfo->tm_year + 1900
            , gmtinfo->tm_mon + 1
            , gmtinfo->tm_mday
            , gmtinfo->tm_hour
            , gmtinfo->tm_min
            , gmtinfo->tm_sec
            , ( int ) datapoint->timestamp.micro );
        { if( (((s) >= (size-offset) || (s) < 0 )) ) { xi_set_err( (XI_CSV_ENCODE_DATAPOINT_BUFFER_OVERRUN) ); goto err_handling; } else { (offset) += (s); }};
    }
    s = csv_encode_value( in + offset, size - offset, datapoint );
    { if( (((s) >= (size-offset) || (s) < 0 )) ) { xi_set_err( (XI_CSV_ENCODE_DATAPOINT_BUFFER_OVERRUN) ); goto err_handling; } else { (offset) += (s); }};
    s = snprintf( in + offset, size - offset, "%s", "\n" );
    { if( (((s) >= (size-offset) || (s) < 0 )) ) { xi_set_err( (XI_CSV_ENCODE_DATAPOINT_BUFFER_OVERRUN) ); goto err_handling; } else { (offset) += (s); }};
    return offset;
err_handling:
    return -1;
}

canonical_original_code:
int csv_encode_datapoint_in_place(char *in, unsigned long in_size, struct xi_datapoint_t *datapoint)
{
    ((void) sizeof ((in != 0) ? 1 : 0), __extension__ ({ if (in != 0) ; else __assert_fail ("in != 0", "csv_data.c", 219, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((datapoint != 0) ? 1 : 0), __extension__ ({ if (datapoint != 0) ; else __assert_fail ("datapoint != 0", "csv_data.c", 220, __extension__ __PRETTY_FUNCTION__); }));
    int s = 0;
    int size = in_size;
    int offset = 0;
    if( datapoint->timestamp.timestamp != 0 )
    {
        long stamp = datapoint->timestamp.timestamp;
        struct tm *gmtinfo = xi_gmtime( &stamp );
        s = snprintf( in, size
            , "%04d-%02d-%02dT%02d:%02d:%02d.%06dZ,"
            , gmtinfo->tm_year + 1900
            , gmtinfo->tm_mon + 1
            , gmtinfo->tm_mday
            , gmtinfo->tm_hour
            , gmtinfo->tm_min
            , gmtinfo->tm_sec
            , ( int ) datapoint->timestamp.micro );
        { if( (((s) >= (size-offset) || (s) < 0 )) ) { xi_set_err( (XI_CSV_ENCODE_DATAPOINT_BUFFER_OVERRUN) ); goto err_handling; } else { (offset) += (s); }};
    }
    s = csv_encode_value( in + offset, size - offset, datapoint );
    { if( (((s) >= (size-offset) || (s) < 0 )) ) { xi_set_err( (XI_CSV_ENCODE_DATAPOINT_BUFFER_OVERRUN) ); goto err_handling; } else { (offset) += (s); }};
    s = snprintf( in + offset, size - offset, "%s", "\n" );
    { if( (((s) >= (size-offset) || (s) < 0 )) ) { xi_set_err( (XI_CSV_ENCODE_DATAPOINT_BUFFER_OVERRUN) ); goto err_handling; } else { (offset) += (s); }};
    return offset;
err_handling:
    return -1;
}

variable_types:
in
char *

variable_types: s int

variable_types: size int

variable_types: offset int

variable_types: stamp long

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

user_defined_types: union xi_datapoint_value_t { int i32_value; float f32_value; char str_value[32]; }

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

user_defined_types: struct xi_timestamp_t { long timestamp; long micro; }


decompiled_code:
char *__fastcall csv_encode_datapoint(__int64 a1)
{
bool v1; // zf
char *result; // rax

if ( !a1 )
_assert_fail("data != 0", "csv_data.c", 0xD1u, "csv_encode_datapoint");
v1 = (unsigned int)csv_encode_datapoint_in_place(XI_CSV_LOCAL_BUFFER, 128, a1) == -1;
result = XI_CSV_LOCAL_BUFFER;
if ( v1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1)
{
bool v1; // zf
char *result; // rax

if ( !a1 )
_assert_fail("data != 0", "csv_data.c", 0xD1u, "csv_encode_datapoint");
v1 = (unsigned int)func3(XI_CSV_LOCAL_BUFFER, 128, a1) == -1;
result = XI_CSV_LOCAL_BUFFER;
if ( v1 )
result = 0LL;
return result;
}

original_code:
const char* csv_encode_datapoint( const xi_datapoint_t* data )
{
    ((void) sizeof ((data != 0) ? 1 : 0), __extension__ ({ if (data != 0) ; else __assert_fail ("data != 0", "csv_data.c", 209, __extension__ __PRETTY_FUNCTION__); }));
    return csv_encode_datapoint_in_place( XI_CSV_LOCAL_BUFFER, sizeof( XI_CSV_LOCAL_BUFFER ), data ) == -1 ? 0 : XI_CSV_LOCAL_BUFFER;
}

canonical_original_code:
char *csv_encode_datapoint(struct xi_datapoint_t *data)
{
    ((void) sizeof ((data != 0) ? 1 : 0), __extension__ ({ if (data != 0) ; else __assert_fail ("data != 0", "csv_data.c", 209, __extension__ __PRETTY_FUNCTION__); }));
    return csv_encode_datapoint_in_place( XI_CSV_LOCAL_BUFFER, sizeof( XI_CSV_LOCAL_BUFFER ), data ) == -1 ? 0 : XI_CSV_LOCAL_BUFFER;
}

return_type: char *


decompiled_code:
char *__fastcall csv_encode_create_datastream(const char *a1, unsigned int *a2)
{
unsigned int v2; // edx
char *result; // rax

if ( !a2 )
_assert_fail("data != 0", "csv_data.c", 0x105u, "csv_encode_create_datastream");
v2 = snprintf(XI_CSV_LOCAL_BUFFER, 0x80uLL, "%s,%d\n", a1, *a2);
result = XI_CSV_LOCAL_BUFFER;
if ( v2 > 0x7F )
{
xi_set_err(15LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func5(const char *a1, unsigned int *a2)
{
unsigned int v2; // edx
char *result; // rax

if ( !a2 )
_assert_fail("data != 0", "csv_data.c", 0x105u, "csv_encode_create_datastream");
v2 = snprintf(XI_CSV_LOCAL_BUFFER, 0x80uLL, "%s,%d\n", a1, *a2);
result = XI_CSV_LOCAL_BUFFER;
if ( v2 > 0x7F )
{
xi_set_err(15LL);
result = 0LL;
}
return result;
}

original_code:
const char* csv_encode_create_datastream(
          const char* datastream_id
        , const xi_datapoint_t* data )
{
    ((void) sizeof ((data != 0) ? 1 : 0), __extension__ ({ if (data != 0) ; else __assert_fail ("data != 0", "csv_data.c", 261, __extension__ __PRETTY_FUNCTION__); }));
    int s = snprintf( XI_CSV_LOCAL_BUFFER, sizeof( XI_CSV_LOCAL_BUFFER )
            , "%s,%d\n", datastream_id, data->value.i32_value );
    int size = 128;
    if( (((s) >= (size) || (s) < 0 )) ) { xi_set_err( (XI_CSV_ENCODE_DATASTREAM_BUFFER_OVERRUN) ); goto err_handling; };
    return XI_CSV_LOCAL_BUFFER;
err_handling:
    return 0;
}

canonical_original_code:
char *csv_encode_create_datastream(char *datastream_id, struct xi_datapoint_t *data)
{
    ((void) sizeof ((data != 0) ? 1 : 0), __extension__ ({ if (data != 0) ; else __assert_fail ("data != 0", "csv_data.c", 261, __extension__ __PRETTY_FUNCTION__); }));
    int s = snprintf( XI_CSV_LOCAL_BUFFER, sizeof( XI_CSV_LOCAL_BUFFER )
            , "%s,%d\n", datastream_id, data->value.i32_value );
    int size = 128;
    if( (((s) >= (size) || (s) < 0 )) ) { xi_set_err( (XI_CSV_ENCODE_DATASTREAM_BUFFER_OVERRUN) ); goto err_handling; };
    return XI_CSV_LOCAL_BUFFER;
err_handling:
    return 0;
}


decompiled_code:
__int64 __fastcall csv_decode_datapoint(const char *a1, __int64 a2)
{
__int64 v2; // rbx
char *v3; // r12
__int64 v4; // rax
__int64 v6; // [rsp+0h] [rbp-78h] BYREF
int v7; // [rsp+8h] [rbp-70h]
int v8; // [rsp+Ch] [rbp-6Ch]
int v9; // [rsp+10h] [rbp-68h]
int v10; // [rsp+14h] [rbp-64h]
int v11; // [rsp+44h] [rbp-34h] BYREF
__int64 v12; // [rsp+48h] [rbp-30h] BYREF
int v13; // [rsp+50h] [rbp-28h] BYREF
int v14; // [rsp+54h] [rbp-24h] BYREF
int v15; // [rsp+58h] [rbp-20h] BYREF
int v16; // [rsp+5Ch] [rbp-1Ch] BYREF

if ( !a1 )
_assert_fail("buffer != 0", "csv_data.c", 0x14Au, "csv_decode_datapoint");
v2 = a2;
if ( !a2 )
_assert_fail("datapoint != 0", "csv_data.c", 0x14Bu, "csv_decode_datapoint");
v3 = strchr(a1, 44);
if ( v3 )
{
if ( (unsigned int)_isoc99_sscanf(
a1,
"%04d-%02d-%02dT%02d:%02d:%02d.%06dZ",
&v16,
&v15,
&v14,
&v13,
(char *)&v12 + 4,
&v12,
&v11) == 7 )
{
v10 = v16 - 1900;
v9 = v15 - 1;
v8 = v14;
v7 = v13;
v6 = v12;
v4 = xi_mktime(&v6);
if ( (_DWORD)v4 == -1 )
{
xi_set_err(18LL);
v2 = 0LL;
}
else
{
*(_QWORD *)(a2 + 40) = v4;
*(_QWORD *)(a2 + 48) = v11;
if ( !csv_decode_value(v3 + 1, a2) )
{
xi_set_err(17LL);
v2 = 0LL;
}
}
}
else
{
xi_set_err(17LL);
v2 = 0LL;
}
}
else
{
xi_set_err(17LL);
v2 = 0LL;
}
return v2;
}

original_code:
xi_datapoint_t* csv_decode_datapoint(
      const char* buffer
    , xi_datapoint_t* datapoint )
{
    ((void) sizeof ((buffer != 0) ? 1 : 0), __extension__ ({ if (buffer != 0) ; else __assert_fail ("buffer != 0", "csv_data.c", 330, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((datapoint != 0) ? 1 : 0), __extension__ ({ if (datapoint != 0) ; else __assert_fail ("datapoint != 0", "csv_data.c", 331, __extension__ __PRETTY_FUNCTION__); }));
    int ye, mo, da, h, m, s, ms;
    const char* beg_of_value = strstr( buffer, "," );
    if( ((beg_of_value) == 0) ) { xi_set_err( ((XI_CSV_DECODE_DATAPOINT_PARSER_ERROR)) ); goto err_handling; };
    beg_of_value += 1;
    {
        int n = sscanf( buffer
            , "%04d-%02d-%02dT%02d:%02d:%02d.%06dZ"
            , &ye, &mo, &da, &h, &m, &s, &ms );
        if( (n != 7) ) { xi_set_err( (XI_CSV_DECODE_DATAPOINT_PARSER_ERROR) ); goto err_handling; };
        {
            struct tm timeinfo;
            timeinfo.tm_year = ye - 1900;
            timeinfo.tm_mon = mo - 1;
            timeinfo.tm_mday = da;
            timeinfo.tm_hour = h;
            timeinfo.tm_min = m;
            timeinfo.tm_sec = s;
            time_t timestamp = xi_mktime( &timeinfo );
            if( (( int )timestamp == -1) ) { xi_set_err( (XI_CSV_TIME_CONVERTION_ERROR) ); goto err_handling; };
            datapoint->timestamp.timestamp = timestamp;
            datapoint->timestamp.micro = ms;
        }
    }
    xi_datapoint_t* r = csv_decode_value( beg_of_value
        , datapoint );
    if( ((r) == 0) ) { xi_set_err( ((XI_CSV_DECODE_DATAPOINT_PARSER_ERROR)) ); goto err_handling; };
    return datapoint;
err_handling:
    return 0;
}

canonical_original_code:
struct xi_datapoint_t *csv_decode_datapoint(char *buffer, struct xi_datapoint_t *datapoint)
{
    ((void) sizeof ((buffer != 0) ? 1 : 0), __extension__ ({ if (buffer != 0) ; else __assert_fail ("buffer != 0", "csv_data.c", 330, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((datapoint != 0) ? 1 : 0), __extension__ ({ if (datapoint != 0) ; else __assert_fail ("datapoint != 0", "csv_data.c", 331, __extension__ __PRETTY_FUNCTION__); }));
    int ye; int mo; int da; int h; int m; int s; int ms;
    char *beg_of_value = strstr( buffer, "," );
    if( ((beg_of_value) == 0) ) { xi_set_err( ((XI_CSV_DECODE_DATAPOINT_PARSER_ERROR)) ); goto err_handling; };
    beg_of_value += 1;
    {
        int n = sscanf( buffer
            , "%04d-%02d-%02dT%02d:%02d:%02d.%06dZ"
            , &ye, &mo, &da, &h, &m, &s, &ms );
        if( (n != 7) ) { xi_set_err( (XI_CSV_DECODE_DATAPOINT_PARSER_ERROR) ); goto err_handling; };
        {
            struct tm timeinfo;
            timeinfo.tm_year = ye - 1900;
            timeinfo.tm_mon = mo - 1;
            timeinfo.tm_mday = da;
            timeinfo.tm_hour = h;
            timeinfo.tm_min = m;
            timeinfo.tm_sec = s;
            long timestamp = xi_mktime( &timeinfo );
            if( (( int )timestamp == -1) ) { xi_set_err( (XI_CSV_TIME_CONVERTION_ERROR) ); goto err_handling; };
            datapoint->timestamp.timestamp = timestamp;
            datapoint->timestamp.micro = ms;
        }
    }
    struct xi_datapoint_t *r = csv_decode_value( beg_of_value
        , datapoint );
    if( ((r) == 0) ) { xi_set_err( ((XI_CSV_DECODE_DATAPOINT_PARSER_ERROR)) ); goto err_handling; };
    return datapoint;
err_handling:
    return 0;
}

variable_types:
datapoint
struct xi_datapoint_t *

variable_types: ye int

variable_types: mo int

variable_types: da int

variable_types: h int

variable_types: m int

variable_types: ms int

variable_types: n int

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: timestamp long


decompiled_code:
__int64 __fastcall csv_decode_feed(char *s, __int64 a2)
{
_QWORD *v3; // rbp
int v4; // er14
char *v5; // r12
__int64 v6; // rbx

v3 = (_QWORD *)(a2 + 40);
v4 = 0;
while ( 1 )
{
*(v3 - 1) = 0LL;
*v3 = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
v3[3] = 0LL;
v3[4] = 0LL;
v3[5] = 0LL;
v3[6] = 0LL;
v5 = strchr(s, 10);
v6 = (__int64)strchr(s, 44);
if ( !v6 )
goto LABEL_8;
if ( (unsigned int)xi_str_copy_untiln(v3 - 3, 16LL, s, 44LL) > 0xF )
break;
v6 = csv_decode_datapoint((const char *)(v6 + 1), (__int64)v3);
if ( !v6 )
{
LABEL_8:
xi_set_err(16LL);
return v6;
}
*(v3 - 1) = 1LL;
s = v5 + 1;
if ( ++v4 == 16 )
break;
v3 += 115;
if ( !v5 )
{
*(_QWORD *)(a2 + 8) = v4;
return a2;
}
}
xi_set_err(16LL);
return 0LL;
}

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 }


decompiled_code:
__int64 xi_get_last_error()
{
unsigned int v0; // ebx

v0 = xi_err;
xi_set_err(0);
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebx

v0 = xi_err;
func0(0);
return v0;
}

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

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 ( !a1 )
_assert_fail("buffer != 0", "http_layer_queries.c", 0x28u, "http_construct_string");
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 func2(char *a1, __int64 a2, const char *a3)
{
int result; // eax

if ( !a1 )
_assert_fail("buffer != 0", "http_layer_queries.c", 0x28u, "http_construct_string");
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


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(XI_ID_BUFFER, 256LL, a2, a3, a4) <= 0xFF )
return http_construct_http_query(a1, XI_ID_BUFFER, 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)func4(XI_ID_BUFFER, 256LL, a2, a3, a4) <= 0xFF )
return func5(a1, XI_ID_BUFFER, 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(XI_ID_BUFFER, 256LL, a2, a3) <= 0xFF )
return http_construct_http_query(a1, XI_ID_BUFFER, 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)func3(XI_ID_BUFFER, 256LL, a2, a3) <= 0xFF )
return func5(a1, XI_ID_BUFFER, 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;
}