decompiled_code:
__int64 __fastcall nmea_generate(__int64 a1, int a2, __int64 a3, int a4)
{
unsigned int v6; // er12
int v7; // er14
int v8; // er15
int v10; // edx
int v11; // [rsp+Ch] [rbp-20Ch]
char v12[64]; // [rsp+10h] [rbp-208h] BYREF
double v13[10]; // [rsp+50h] [rbp-1C8h] BYREF
unsigned int v14[24]; // [rsp+A0h] [rbp-178h] BYREF
char v15[96]; // [rsp+100h] [rbp-118h] BYREF
__m128i v16[11]; // [rsp+160h] [rbp-B8h] BYREF

if ( !a1 )
return 0;
v6 = 0;
while ( a4 )
{
if ( (a4 & 1) != 0 )
{
a4 &= 0xFFFFFFFE;
nmea_info2GPGGA(a3, v16);
v6 += nmea_gen_GPGGA(a1 + (int)v6, a2 - v6, (__int64)v16);
if ( (int)(a2 - v6) <= 0 )
return v6;
}
else
{
v7 = a4 & 2;
if ( (a4 & 2) != 0 )
{
a4 &= 0xFFFFFFFD;
nmea_info2GPGSA(a3, (__int64)v13);
v6 += nmea_gen_GPGSA(a1 + (int)v6, a2 - v6, v13);
v8 = a2 - v6;
}
else if ( (a4 & 4) != 0 )
{
v8 = a2 - v6;
v11 = nmea_gsv_npack(*(_DWORD *)(a3 + 116));
if ( v11 > 0 )
{
do
{
if ( v8 <= 0 )
break;
v10 = v7++;
nmea_info2GPGSV(a3, (int *)v14, v10);
v6 += nmea_gen_GPGSV(a1 + (int)v6, (unsigned int)v8, v14);
v8 = a2 - v6;
}
while ( v11 != v7 );
}
a4 &= 0xFFFFFFFB;
}
else if ( (a4 & 8) != 0 )
{
a4 &= 0xFFFFFFF7;
nmea_info2GPRMC(a3, (__int64)v15);
v6 += nmea_gen_GPRMC(a1 + (int)v6, a2 - v6, (__int64)v15);
v8 = a2 - v6;
}
else
{
if ( (a4 & 0x10) == 0 )
return v6;
a4 &= 0xFFFFFFEF;
nmea_info2GPVTG(a3, (__int64)v12);
v6 += nmea_gen_GPVTG(a1 + (int)v6, a2 - v6, (__int64)v12);
v8 = a2 - v6;
}
if ( v8 <= 0 )
return v6;
}
}
return v6;
}

original_code:
int nmea_generate(
    char *buff, int buff_sz,
    const nmeaINFO *info,
    int generate_mask
    )
{
    int gen_count = 0, gsv_it, gsv_count;
    int pack_mask = generate_mask;
    nmeaGPGGA gga;
    nmeaGPGSA gsa;
    nmeaGPGSV gsv;
    nmeaGPRMC rmc;
    nmeaGPVTG vtg;
    if(!buff)
        return 0;
    while(pack_mask)
    {
        if(pack_mask & GPGGA)
        {
            nmea_info2GPGGA(info, &gga);
            gen_count += nmea_gen_GPGGA(buff + gen_count, buff_sz - gen_count, &gga);
            pack_mask &= ~GPGGA;
        }
        else if(pack_mask & GPGSA)
        {
            nmea_info2GPGSA(info, &gsa);
            gen_count += nmea_gen_GPGSA(buff + gen_count, buff_sz - gen_count, &gsa);
            pack_mask &= ~GPGSA;
        }
        else if(pack_mask & GPGSV)
        {
            gsv_count = nmea_gsv_npack(info->satinfo.inview);
            for(gsv_it = 0; gsv_it < gsv_count && buff_sz - gen_count > 0; ++gsv_it)
            {
                nmea_info2GPGSV(info, &gsv, gsv_it);
                gen_count += nmea_gen_GPGSV(buff + gen_count, buff_sz - gen_count, &gsv);
            }
            pack_mask &= ~GPGSV;
        }
        else if(pack_mask & GPRMC)
        {
            nmea_info2GPRMC(info, &rmc);
            gen_count += nmea_gen_GPRMC(buff + gen_count, buff_sz - gen_count, &rmc);
            pack_mask &= ~GPRMC;
        }
        else if(pack_mask & GPVTG)
        {
            nmea_info2GPVTG(info, &vtg);
            gen_count += nmea_gen_GPVTG(buff + gen_count, buff_sz - gen_count, &vtg);
            pack_mask &= ~GPVTG;
        }
        else
            break;
        if(buff_sz - gen_count <= 0)
            break;
    }
    return gen_count;
}

canonical_original_code:
int nmea_generate(char *buff, int buff_sz, struct _nmeaINFO *info, int generate_mask)
{
    int gen_count = 0; int gsv_it; int gsv_count;
    int pack_mask = generate_mask;
    struct _nmeaGPGGA gga;
    struct _nmeaGPGSA gsa;
    struct _nmeaGPGSV gsv;
    struct _nmeaGPRMC rmc;
    struct _nmeaGPVTG vtg;
    if(!buff)
        return 0;
    while(pack_mask)
    {
        if(pack_mask & GPGGA)
        {
            nmea_info2GPGGA(info, &gga);
            gen_count += nmea_gen_GPGGA(buff + gen_count, buff_sz - gen_count, &gga);
            pack_mask &= ~GPGGA;
        }
        else if(pack_mask & GPGSA)
        {
            nmea_info2GPGSA(info, &gsa);
            gen_count += nmea_gen_GPGSA(buff + gen_count, buff_sz - gen_count, &gsa);
            pack_mask &= ~GPGSA;
        }
        else if(pack_mask & GPGSV)
        {
            gsv_count = nmea_gsv_npack(info->satinfo.inview);
            for(gsv_it = 0; gsv_it < gsv_count && buff_sz - gen_count > 0; ++gsv_it)
            {
                nmea_info2GPGSV(info, &gsv, gsv_it);
                gen_count += nmea_gen_GPGSV(buff + gen_count, buff_sz - gen_count, &gsv);
            }
            pack_mask &= ~GPGSV;
        }
        else if(pack_mask & GPRMC)
        {
            nmea_info2GPRMC(info, &rmc);
            gen_count += nmea_gen_GPRMC(buff + gen_count, buff_sz - gen_count, &rmc);
            pack_mask &= ~GPRMC;
        }
        else if(pack_mask & GPVTG)
        {
            nmea_info2GPVTG(info, &vtg);
            gen_count += nmea_gen_GPVTG(buff + gen_count, buff_sz - gen_count, &vtg);
            pack_mask &= ~GPVTG;
        }
        else
            break;
        if(buff_sz - gen_count <= 0)
            break;
    }
    return gen_count;
}

variable_types: struct _nmeaGPGGA { struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } utc; double lat; char ns; double lon; char ew; int sig; int satinuse; double HDOP; double elv; char elv_units; double diff; char diff_units; double dgps_age; int dgps_sid; }

variable_types: struct _nmeaGPGSA { char fix_mode; int fix_type; int sat_prn[-1]; double PDOP; double HDOP; double VDOP; }

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

variable_types: struct _nmeaGPRMC { struct _nmeaTIME { int year; int mon; int day; int hour; int min; int sec; int hsec; } utc; char status; double lat; char ns; double lon; char ew; double speed; double direction; double declination; char declin_ew; char mode; }

variable_types: struct _nmeaGPVTG { double dir; char dir_t; double dec; char dec_m; double spn; char spn_n; double spk; char spk_k; }


repo: yishii/MapTracer

decompiled_code:
__int64 __fastcall nmea_gsv_npack(int a1)
{
double v1; // xmm0_8
__m128d v2; // xmm3
__m128d v3; // xmm1
__int64 result; // rax

v1 = (double)a1 * 0.25;
if ( COERCE_DOUBLE(*(_QWORD *)&v1 & LC5) < 4.503599627370496e15 )
{
v2.m128d_f64[0] = (double)a1 * 0.25;
v3.m128d_f64[0] = (double)(int)v1;
*(_QWORD *)&v1 = COERCE_UNSIGNED_INT64(v3.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v2, v3) & LC9)) | ~LC5 & *(_QWORD *)&v1;
}
result = (unsigned int)(int)v1;
if ( !(_DWORD)result )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
double v1; // xmm0_8
__m128d v2; // xmm3
__m128d v3; // xmm1
__int64 result; // rax

v1 = (double)a1 * 0.25;
if ( COERCE_DOUBLE(*(_QWORD *)&v1 & LC5) < 4.503599627370496e15 )
{
v2.m128d_f64[0] = (double)a1 * 0.25;
v3.m128d_f64[0] = (double)(int)v1;
*(_QWORD *)&v1 = COERCE_UNSIGNED_INT64(v3.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v2, v3) & LC9)) | ~LC5 & *(_QWORD *)&v1;
}
result = (unsigned int)(int)v1;
if ( !(_DWORD)result )
result = 1LL;
return result;
}

original_code:
int nmea_gsv_npack(int sat_count)
{
    int pack_count = (int)ceil(((double)sat_count) / (4));
    if(0 == pack_count)
        pack_count = 1;
    return pack_count;
}

return_type: int


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

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

original_code:
int nmea_igen_noise_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
    return 1;
}

canonical_original_code:
int nmea_igen_noise_init(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    return 1;
}

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 *

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:
// attributes: thunk
__int64 nmea_igen_noise_reset()
{
return nmea_igen_noise_init();
}

canonical_decompiled_code:
__int64 func1()
{
return func0();
}

original_code:
int nmea_igen_noise_reset(nmeaGENERATOR *gen, nmeaINFO *info)
{
    return 1;
}

canonical_original_code:
int nmea_igen_noise_reset(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    return 1;
}

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


original_code:
int nmea_igen_static_reset(nmeaGENERATOR *gen, nmeaINFO *info)
{
    info->satinfo.inuse = 4;
    info->satinfo.inview = 4;
    info->satinfo.sat[0].id = 1;
    info->satinfo.sat[0].in_use = 1;
    info->satinfo.sat[0].elv = 50;
    info->satinfo.sat[0].azimuth = 0;
    info->satinfo.sat[0].sig = 99;
    info->satinfo.sat[1].id = 2;
    info->satinfo.sat[1].in_use = 1;
    info->satinfo.sat[1].elv = 50;
    info->satinfo.sat[1].azimuth = 90;
    info->satinfo.sat[1].sig = 99;
    info->satinfo.sat[2].id = 3;
    info->satinfo.sat[2].in_use = 1;
    info->satinfo.sat[2].elv = 50;
    info->satinfo.sat[2].azimuth = 180;
    info->satinfo.sat[2].sig = 99;
    info->satinfo.sat[3].id = 4;
    info->satinfo.sat[3].in_use = 1;
    info->satinfo.sat[3].elv = 50;
    info->satinfo.sat[3].azimuth = 270;
    info->satinfo.sat[3].sig = 99;
    return 1;
}

canonical_original_code:
int nmea_igen_static_reset(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    info->satinfo.inuse = 4;
    info->satinfo.inview = 4;
    info->satinfo.sat[0].id = 1;
    info->satinfo.sat[0].in_use = 1;
    info->satinfo.sat[0].elv = 50;
    info->satinfo.sat[0].azimuth = 0;
    info->satinfo.sat[0].sig = 99;
    info->satinfo.sat[1].id = 2;
    info->satinfo.sat[1].in_use = 1;
    info->satinfo.sat[1].elv = 50;
    info->satinfo.sat[1].azimuth = 90;
    info->satinfo.sat[1].sig = 99;
    info->satinfo.sat[2].id = 3;
    info->satinfo.sat[2].in_use = 1;
    info->satinfo.sat[2].elv = 50;
    info->satinfo.sat[2].azimuth = 180;
    info->satinfo.sat[2].sig = 99;
    info->satinfo.sat[3].id = 4;
    info->satinfo.sat[3].in_use = 1;
    info->satinfo.sat[3].elv = 50;
    info->satinfo.sat[3].azimuth = 270;
    info->satinfo.sat[3].sig = 99;
    return 1;
}


decompiled_code:
__int64 __fastcall nmea_igen_static_init(__int64 a1, _QWORD *a2)
{
a2[4] = 0x300000003LL;
nmea_igen_static_reset(a1, a2);
return 1LL;
}

original_code:
int nmea_igen_static_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
    info->sig = 3;
    info->fix = 3;
    nmea_igen_static_reset(gen, info);
    return 1;
}

canonical_original_code:
int nmea_igen_static_init(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    info->sig = 3;
    info->fix = 3;
    nmea_igen_static_reset(gen, info);
    return 1;
}


original_code:
int nmea_igen_rotate_reset(nmeaGENERATOR *gen, nmeaINFO *info)
{
    int it;
    double deg = 360 / 8;
    double srt = 0;
    info->satinfo.inuse = 8;
    info->satinfo.inview = 8;
    for(it = 0; it < info->satinfo.inview; ++it)
    {
        info->satinfo.sat[it].id = it + 1;
        info->satinfo.sat[it].in_use = 1;
        info->satinfo.sat[it].elv = 5;
        info->satinfo.sat[it].azimuth = (int)srt;
        info->satinfo.sat[it].sig = 80;
        srt += deg;
    }
    return 1;
}

canonical_original_code:
int nmea_igen_rotate_reset(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    int it;
    double deg = 360 / 8;
    double srt = 0;
    info->satinfo.inuse = 8;
    info->satinfo.inview = 8;
    for(it = 0; it < info->satinfo.inview; ++it)
    {
        info->satinfo.sat[it].id = it + 1;
        info->satinfo.sat[it].in_use = 1;
        info->satinfo.sat[it].elv = 5;
        info->satinfo.sat[it].azimuth = (int)srt;
        info->satinfo.sat[it].sig = 80;
        srt += deg;
    }
    return 1;
}

variable_types: it int

variable_types: deg double

variable_types: srt double


decompiled_code:
__int64 __fastcall nmea_igen_rotate_init(__int64 a1, __int64 a2)
{
*(_QWORD *)(a2 + 32) = 0x300000003LL;
nmea_igen_rotate_reset(a1, a2);
return 1LL;
}

original_code:
int nmea_igen_rotate_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
    info->sig = 3;
    info->fix = 3;
    nmea_igen_rotate_reset(gen, info);
    return 1;
}

canonical_original_code:
int nmea_igen_rotate_init(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    info->sig = 3;
    info->fix = 3;
    nmea_igen_rotate_reset(gen, info);
    return 1;
}


original_code:
int nmea_igen_pos_rmove_init(nmeaGENERATOR *gen, nmeaINFO *info)
{
    info->sig = 3;
    info->fix = 3;
    info->direction = info->declination = 0;
    info->speed = 20;
    return 1;
}

canonical_original_code:
int nmea_igen_pos_rmove_init(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    info->sig = 3;
    info->fix = 3;
    info->direction = info->declination = 0;
    info->speed = 20;
    return 1;
}


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

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

original_code:
int nmea_igen_pos_rmove_destroy(nmeaGENERATOR *gen)
{
    return 1;
}

canonical_original_code:
int nmea_igen_pos_rmove_destroy(struct _nmeaGENERATOR *gen)
{
    return 1;
}


decompiled_code:
__int64 __fastcall nmea_igen_static_loop(__int64 a1, __int64 a2)
{
nmea_time_now(a2 + 4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
nmea_time_now(a2 + 4);
return 1LL;
}

original_code:
int nmea_igen_static_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
    nmea_time_now(&info->utc);
    return 1;
}

canonical_original_code:
int nmea_igen_static_loop(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    nmea_time_now(&info->utc);
    return 1;
}


original_code:
int nmea_igen_rotate_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
    int it;
    int count = info->satinfo.inview;
    double deg = 360 / (count?count:1);
    double srt = (count?(info->satinfo.sat[0].azimuth):0) + 5;
    nmea_time_now(&info->utc);
    for(it = 0; it < count; ++it)
    {
        info->satinfo.sat[it].azimuth =
            (int)((srt >= 360)?srt - 360:srt);
        srt += deg;
    }
    return 1;
}

canonical_original_code:
int nmea_igen_rotate_loop(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    int it;
    int count = info->satinfo.inview;
    double deg = 360 / (count?count:1);
    double srt = (count?(info->satinfo.sat[0].azimuth):0) + 5;
    nmea_time_now(&info->utc);
    for(it = 0; it < count; ++it)
    {
        info->satinfo.sat[it].azimuth =
            (int)((srt >= 360)?srt - 360:srt);
        srt += deg;
    }
    return 1;
}

variable_types: count int


original_code:
int nmea_igen_noise_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
    int it;
    int in_use;
    info->sig = (int)nmea_random(1, 3);
    info->PDOP = nmea_random(0, 9);
    info->HDOP = nmea_random(0, 9);
    info->VDOP = nmea_random(0, 9);
    info->fix = (int)nmea_random(2, 3);
    info->lat = nmea_random(0, 100);
    info->lon = nmea_random(0, 100);
    info->speed = nmea_random(0, 100);
    info->direction = nmea_random(0, 360);
    info->declination = nmea_random(0, 360);
    info->elv = (int)nmea_random(-100, 100);
    info->satinfo.inuse = 0;
    info->satinfo.inview = 0;
    for(it = 0; it < 12; ++it)
    {
        info->satinfo.sat[it].id = it;
        info->satinfo.sat[it].in_use = in_use = (int)nmea_random(0, 3);
        info->satinfo.sat[it].elv = (int)nmea_random(0, 90);
        info->satinfo.sat[it].azimuth = (int)nmea_random(0, 359);
        info->satinfo.sat[it].sig = (int)(in_use?nmea_random(40, 99):nmea_random(0, 40));
        if(in_use)
            info->satinfo.inuse++;
        if(info->satinfo.sat[it].sig > 0)
            info->satinfo.inview++;
    }
    return 1;
}

canonical_original_code:
int nmea_igen_noise_loop(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    int it;
    int in_use;
    info->sig = (int)nmea_random(1, 3);
    info->PDOP = nmea_random(0, 9);
    info->HDOP = nmea_random(0, 9);
    info->VDOP = nmea_random(0, 9);
    info->fix = (int)nmea_random(2, 3);
    info->lat = nmea_random(0, 100);
    info->lon = nmea_random(0, 100);
    info->speed = nmea_random(0, 100);
    info->direction = nmea_random(0, 360);
    info->declination = nmea_random(0, 360);
    info->elv = (int)nmea_random(-100, 100);
    info->satinfo.inuse = 0;
    info->satinfo.inview = 0;
    for(it = 0; it < 12; ++it)
    {
        info->satinfo.sat[it].id = it;
        info->satinfo.sat[it].in_use = in_use = (int)nmea_random(0, 3);
        info->satinfo.sat[it].elv = (int)nmea_random(0, 90);
        info->satinfo.sat[it].azimuth = (int)nmea_random(0, 359);
        info->satinfo.sat[it].sig = (int)(in_use?nmea_random(40, 99):nmea_random(0, 40));
        if(in_use)
            info->satinfo.inuse++;
        if(info->satinfo.sat[it].sig > 0)
            info->satinfo.inview++;
    }
    return 1;
}


original_code:
int nmea_igen_pos_rmove_loop(nmeaGENERATOR *gen, nmeaINFO *info)
{
    nmeaPOS crd;
    info->direction += nmea_random(-10, 10);
    info->speed += nmea_random(-2, 3);
    if(info->direction < 0)
        info->direction = 359 + info->direction;
    if(info->direction > 359)
        info->direction -= 359;
    if(info->speed > 40)
        info->speed = 40;
    if(info->speed < 1)
        info->speed = 1;
    nmea_info2pos(info, &crd);
    nmea_move_horz(&crd, &crd, info->direction, info->speed / 3600);
    nmea_pos2info(&crd, info);
    info->declination = info->direction;
    return 1;
}

canonical_original_code:
int nmea_igen_pos_rmove_loop(struct _nmeaGENERATOR *gen, struct _nmeaINFO *info)
{
    struct _nmeaPOS crd;
    info->direction += nmea_random(-10, 10);
    info->speed += nmea_random(-2, 3);
    if(info->direction < 0)
        info->direction = 359 + info->direction;
    if(info->direction > 359)
        info->direction -= 359;
    if(info->speed > 40)
        info->speed = 40;
    if(info->speed < 1)
        info->speed = 1;
    nmea_info2pos(info, &crd);
    nmea_move_horz(&crd, &crd, info->direction, info->speed / 3600);
    nmea_pos2info(&crd, info);
    info->declination = info->direction;
    return 1;
}

variable_types: struct _nmeaPOS { double lat; double lon; }


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

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

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

v3 = *a2;
nmea_zero_INFO(a2);
*a2 = v3;
*((_QWORD *)a2 + 8) = LC19;
*((_QWORD *)a2 + 9) = LC20;
result = 1LL;
do
{
if ( !a1 )
break;
v5 = *(__int64 (__fastcall **)(__int64, int *))(a1 + 8);
if ( v5 )
result = v5(a1, a2);
a1 = *(_QWORD *)(a1 + 40);
}
while ( (_DWORD)result );
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


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

do
{
while ( 1 )
{
v4 = *(__int64 (__fastcall **)(__int64, __int64))(a1 + 16);
if ( v4 )
break;
a1 = *(_QWORD *)(a1 + 40);
result = 1LL;
if ( !a1 )
return result;
}
result = v4(a1, a2);
if ( !(_DWORD)result )
break;
a1 = *(_QWORD *)(a1 + 40);
}
while ( a1 );
return result;
}

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

do
{
while ( 1 )
{
v4 = *(__int64 (__fastcall **)(__int64, __int64))(a1 + 16);
if ( v4 )
break;
a1 = *(_QWORD *)(a1 + 40);
result = 1LL;
if ( !a1 )
return result;
}
result = v4(a1, a2);
if ( !(_DWORD)result )
break;
a1 = *(_QWORD *)(a1 + 40);
}
while ( a1 );
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;
}


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

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

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

v1 = *(__int64 (**)(void))(a1 + 24);
if ( v1 )
result = v1();
else
result = 1LL;
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;
}


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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 40);
}
while ( a1 );
*(_QWORD *)(result + 40) = a2;
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 40);
}
while ( a1 );
*(_QWORD *)(result + 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

if ( (unsigned int)nmea_gen_loop(a4, a3) )
result = nmea_generate(a1, a2, a3, a5);
else
result = 0LL;
return result;
}

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

if ( (unsigned int)func14(a4, a3) )
result = nmea_generate(a1, a2, a3, a5);
else
result = 0LL;
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:
// attributes: thunk
void __fastcall nmea_destroy_generator(_QWORD *a1)
{
nmea_gen_destroy(a1);
}

canonical_decompiled_code:
void __fastcall func19(_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 (a2 - a1) * (double)rand() / 2147483647.0 + a1;
}

canonical_decompiled_code:
double __fastcall func10(double a1, double a2)
{
return (a2 - a1) * (double)rand() / 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 v2; // rsi
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
unsigned int v6; // er8
__int64 result; // rax
const char *v8; // rax
const char *v9; // rax

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

canonical_decompiled_code:
__int64 __fastcall func1(char a1, char a2)
{
__int64 v2; // rsi
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
unsigned int v6; // er8
__int64 result; // rax
const char *v8; // rax
const char *v9; // rax

if ( (int)SDL_Init(32LL) < 0 )
{
v8 = (const char *)((__int64 (*)(void))SDL_GetError)();
printf("SDL_Init failed (%s)\n", v8);
result = 0LL;
}
else
{
cvbs_resolution = a1;
no_gui_mode = a2;
SDL_GetVideoInfo();
if ( cvbs_resolution )
{
v2 = 400LL;
v3 = SDL_SetVideoMode(600LL, 400LL, 16LL, 1LL);
}
else
{
v2 = 600LL;
v3 = SDL_SetVideoMode(600LL, 600LL, 16LL, 1LL);
}
screen = v3;
v6 = 1;
if ( !v3 )
{
v9 = (const char *)SDL_GetError(600LL, v2, v4, v5, 1LL);
printf("SDL_SetVideoMode failed (%s)\n", v9);
v6 = 0;
}
result = v6;
}
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, __int64 a2)
{
return showImageFileOnMemory_FullScreen(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 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, __int64 a2)
{
return showImageFileOnMemory_FullScreen(a1, a2, 1u);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 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, ...)
{
int v3; // er12
int v4; // eax
unsigned int v6; // eax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

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

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

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

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)
{
__int64 v2; // rcx
__int64 result; // rax
int v4; // edx

if ( a2 <= 0 )
return 0LL;
v2 = (__int64)&a1[a2 - 1 + 1];
LODWORD(result) = 0;
do
{
v4 = *a1++;
result = v4 ^ (unsigned int)result;
}
while ( a1 != (char *)v2 );
return result;
}

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

if ( a2 <= 0 )
return 0LL;
v2 = (__int64)&a1[a2 - 1 + 1];
LODWORD(result) = 0;
do
{
v4 = *a1++;
result = v4 ^ (unsigned int)result;
}
while ( a1 != (char *)v2 );
return result;
}

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


decompiled_code:
__int64 __fastcall nmea_atoi(_DWORD *a1, int a2, int a3)
{
char *endptr; // [rsp+0h] [rbp-110h] BYREF
char nptr[264]; // [rsp+8h] [rbp-108h] BYREF

if ( a2 > 255 )
return 0LL;
if ( (unsigned __int64)a2 >= 8 )
{
*(char **)((char *)&endptr + a2) = *(char **)((char *)a1 + a2 - 8);
qmemcpy(nptr, a1, 8 * ((unsigned __int64)(a2 - 1LL) >> 3));
}
else if ( (a2 & 4) != 0 )
{
*(_DWORD *)nptr = *a1;
*(_DWORD *)&nptr[a2 - 4] = *(_DWORD *)((char *)a1 + a2 - 4);
}
else if ( a2 )
{
nptr[0] = *(_BYTE *)a1;
if ( (a2 & 2) != 0 )
*(_WORD *)&nptr[a2 - 2] = *(_WORD *)((char *)a1 + a2 - 2);
}
nptr[a2] = 0;
return strtol(nptr, &endptr, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, int a2, int a3)
{
char *endptr; // [rsp+0h] [rbp-110h] BYREF
char nptr[264]; // [rsp+8h] [rbp-108h] BYREF

if ( a2 > 255 )
return 0LL;
if ( (unsigned __int64)a2 >= 8 )
{
*(char **)((char *)&endptr + a2) = *(char **)((char *)a1 + a2 - 8);
qmemcpy(nptr, a1, 8 * ((unsigned __int64)(a2 - 1LL) >> 3));
}
else if ( (a2 & 4) != 0 )
{
*(_DWORD *)nptr = *a1;
*(_DWORD *)&nptr[a2 - 4] = *(_DWORD *)((char *)a1 + a2 - 4);
}
else if ( a2 )
{
nptr[0] = *(_BYTE *)a1;
if ( (a2 & 2) != 0 )
*(_WORD *)&nptr[a2 - 2] = *(_WORD *)((char *)a1 + a2 - 2);
}
nptr[a2] = 0;
return strtol(nptr, &endptr, a3);
}

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


decompiled_code:
double __fastcall nmea_atof(_DWORD *a1, int a2)
{
char *endptr; // [rsp+0h] [rbp-110h] BYREF
char nptr[264]; // [rsp+8h] [rbp-108h] BYREF

if ( a2 > 255 )
return 0.0;
if ( (unsigned __int64)a2 >= 8 )
{
*(char **)((char *)&endptr + a2) = *(char **)((char *)a1 + a2 - 8);
qmemcpy(nptr, a1, 8 * ((unsigned __int64)(a2 - 1LL) >> 3));
}
else if ( (a2 & 4) != 0 )
{
*(_DWORD *)nptr = *a1;
*(_DWORD *)&nptr[a2 - 4] = *(_DWORD *)((char *)a1 + a2 - 4);
}
else if ( a2 )
{
nptr[0] = *(_BYTE *)a1;
if ( (a2 & 2) != 0 )
*(_WORD *)&nptr[a2 - 2] = *(_WORD *)((char *)a1 + a2 - 2);
}
nptr[a2] = 0;
return strtod(nptr, &endptr);
}

canonical_decompiled_code:
double __fastcall func2(_DWORD *a1, int a2)
{
char *endptr; // [rsp+0h] [rbp-110h] BYREF
char nptr[264]; // [rsp+8h] [rbp-108h] BYREF

if ( a2 > 255 )
return 0.0;
if ( (unsigned __int64)a2 >= 8 )
{
*(char **)((char *)&endptr + a2) = *(char **)((char *)a1 + a2 - 8);
qmemcpy(nptr, a1, 8 * ((unsigned __int64)(a2 - 1LL) >> 3));
}
else if ( (a2 & 4) != 0 )
{
*(_DWORD *)nptr = *a1;
*(_DWORD *)&nptr[a2 - 4] = *(_DWORD *)((char *)a1 + a2 - 4);
}
else if ( a2 )
{
nptr[0] = *(_BYTE *)a1;
if ( (a2 & 2) != 0 )
*(_WORD *)&nptr[a2 - 2] = *(_WORD *)((char *)a1 + a2 - 2);
}
nptr[a2] = 0;
return strtod(nptr, &endptr);
}

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); // rbx
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

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

canonical_decompiled_code:
int func1(char *format, ...)
{
__int64 (__fastcall **v1)(char *, _QWORD); // rax
__int64 (__fastcall *v2)(char *, _QWORD); // rbx
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

v1 = (__int64 (__fastcall **)(char *, _QWORD))func0();
v2 = *v1;
if ( *v1 )
{
va_start(arg, format);
LODWORD(v1) = vsnprintf(s, 0x3FFuLL, format, arg);
if ( (int)v1 > 0 )
LODWORD(v1) = v2(s, (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); // rbx
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

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

canonical_decompiled_code:
int func2(char *format, ...)
{
_QWORD *v1; // rax
__int64 (__fastcall *v2)(char *, _QWORD); // rbx
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

v1 = func0();
v2 = (__int64 (__fastcall *)(char *, _QWORD))v1[1];
if ( v2 )
{
va_start(arg, format);
LODWORD(v1) = vsnprintf(s, 0x3FFuLL, format, arg);
if ( (int)v1 > 0 )
LODWORD(v1) = v2(s, (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)
{
if ( !a2 || !a1 )
return 0LL;
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);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, char *a2, double a3, double a4)
{
if ( !a2 || !a1 )
return 0LL;
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);
return 1LL;
}

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)
{
if ( !a3 || !a2 )
return 0LL;
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);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, const char *a2, char *a3, double a4, double a5)
{
if ( !a3 || !a2 )
return 0LL;
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);
return 1LL;
}

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(int *a1)
{
struct tm *v1; // rax
int v2; // edx
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v1 = gmtime(&timer);
*a1 = v1->tm_year;
a1[1] = v1->tm_mon;
a1[2] = v1->tm_mday;
a1[3] = v1->tm_hour;
v2 = v1->tm_min;
result = (unsigned int)v1->tm_sec;
a1[6] = 0;
a1[4] = v2;
a1[5] = result;
return result;
}

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

time(&timer);
v1 = gmtime(&timer);
*a1 = v1->tm_year;
a1[1] = v1->tm_mon;
a1[2] = v1->tm_mday;
a1[3] = v1->tm_hour;
v2 = v1->tm_min;
result = (unsigned int)v1->tm_sec;
a1[6] = 0;
a1[4] = v2;
a1[5] = 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)
{
int v1; // ecx
unsigned __int64 v2; // rdi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
int v1; // ecx
unsigned __int64 v2; // rdi
__int64 result; // rax

*a1 = 0LL;
v1 = (int)a1;
v2 = (unsigned __int64)(a1 + 1);
result = 0LL;
*(_QWORD *)(v2 + 76) = 0LL;
memset((void *)(v2 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * ((v1 - (v2 & 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)
{
__int16 buf[5]; // [rsp+Eh] [rbp-Ah] BYREF

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

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

buf[0] = __ROL2__(a2, 8);
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; // r12
char *v3; // rbx
const void *v4; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func1(int fd, void *buf)
{
char *v2; // r12
char *v3; // rbx
const void *v4; // rsi

v2 = (char *)buf + 12288;
v3 = (char *)buf;
do
{
v4 = v3;
v3 += 2048;
write(fd, v4, 0x800uLL);
}
while ( v3 != v2 );
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 += 2;
*(v2 - 1) = a2;
}
while ( v2 != &v5 );
return oled_transmitFullScreen(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
__m128i v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+10h] [rbp-18h]
char v4; // [rsp+18h] [rbp-10h]

v3 = 0x8083808280810F87LL;
v4 = -81;
v2 = _mm_load_si128((const __m128i *)&LC1);
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
__m128i v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+10h] [rbp-18h]
char v4; // [rsp+18h] [rbp-10h]

v3 = 0x8083808280810F87LL;
v4 = -81;
v2 = _mm_load_si128((const __m128i *)&LC1);
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
char v3; // [rsp+Ah] [rbp-300Eh] BYREF
char v4; // [rsp+Bh] [rbp-300Dh] BYREF
int v5; // [rsp+Ch] [rbp-300Ch] BYREF
char buf[12296]; // [rsp+10h] [rbp-3008h] BYREF

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

canonical_decompiled_code:
int func5()
{
int v0; // eax
int v1; // ebx
char v3; // [rsp+Ah] [rbp-300Eh] BYREF
char v4; // [rsp+Bh] [rbp-300Dh] BYREF
int v5; // [rsp+Ch] [rbp-300Ch] BYREF
char buf[12296]; // [rsp+10h] [rbp-3008h] BYREF

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

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

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
__int64 v1; // rax

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


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

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
if ( !gpio_mem )
return 0LL;
if ( a1 )
{
*(_DWORD *)(gpio_mem + 28) = 0x20000;
return 0LL;
}
*(_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)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 9;
result = 0LL;
if ( v1 <= 0x74u )
result = (unsigned __int8)CSWTCH_9[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 9;
result = 0LL;
if ( v1 <= 0x74u )
result = (unsigned __int8)CSWTCH_9[v1];
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 v3; // eax

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");
v3 = *((_DWORD *)a3 + 8);
if ( v3 == 1 )
return snprintf(a1, a2, "%f", *(float *)a3);
if ( v3 == 2 )
return snprintf(a1, a2, "%s", a3);
if ( v3 )
return -1;
return snprintf(a1, a2, "%d", *(unsigned int *)a3);
}

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

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");
v3 = *((_DWORD *)a3 + 8);
if ( v3 == 1 )
return snprintf(a1, a2, "%f", *(float *)a3);
if ( v3 == 2 )
return snprintf(a1, a2, "%s", a3);
if ( v3 )
return -1;
return snprintf(a1, a2, "%d", *(unsigned int *)a3);
}

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(unsigned __int8 *a1, __int64 a2)
{
unsigned __int64 v3; // rsi
unsigned int v4; // eax
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
__int64 v8; // rdx
__int16 v9; // ax
__int64 v10; // rcx
__int64 result; // rax
int v12; // eax
__int64 v13; // rax
double v14; // xmm0_8

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;
v3 = *a1;
if ( (unsigned __int8)v3 <= 0xDu )
{
v13 = 9217LL;
if ( _bittest64(&v13, v3) )
{
*(_BYTE *)a2 = 0;
LABEL_11:
result = a2;
*(_DWORD *)(a2 + 32) = 2;
return result;
}
}
while ( 1 )
{
v4 = csv_classify_char(v3);
v9 = word_8E2[12 * v4 + 2 * v8];
if ( (unsigned int)(v9 - 1) <= 4 )
*(_BYTE *)(a2 + v5) = v3;
v3 = *(unsigned __int8 *)(v6 + v5 + 1);
v10 = v5 + 1;
if ( (unsigned __int8)v3 <= 0xDu )
{
if ( _bittest64(&v7, v3) )
break;
}
if ( v10 == 31 )
{
xi_set_err(26LL);
return 0LL;
}
}
*(_BYTE *)(a2 + v10) = 0;
if ( v9 <= 1 || v9 == 4 )
goto LABEL_11;
if ( v9 == 2 )
{
v12 = atoi((const char *)a2);
*(_DWORD *)(a2 + 32) = 0;
*(_DWORD *)a2 = v12;
return a2;
}
if ( v9 != 3 )
goto LABEL_11;
v14 = atof((const char *)a2);
result = a2;
*(_DWORD *)(a2 + 32) = 1;
*(float *)&v14 = v14;
*(_DWORD *)a2 = LODWORD(v14);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1, __int64 a2)
{
unsigned __int64 v3; // rsi
unsigned int v4; // eax
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
__int64 v8; // rdx
__int16 v9; // ax
__int64 v10; // rcx
__int64 result; // rax
int v12; // eax
__int64 v13; // rax
double v14; // xmm0_8

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;
v3 = *a1;
if ( (unsigned __int8)v3 <= 0xDu )
{
v13 = 9217LL;
if ( _bittest64(&v13, v3) )
{
*(_BYTE *)a2 = 0;
LABEL_11:
result = a2;
*(_DWORD *)(a2 + 32) = 2;
return result;
}
}
while ( 1 )
{
v4 = func0(v3);
v9 = word_8E2[12 * v4 + 2 * v8];
if ( (unsigned int)(v9 - 1) <= 4 )
*(_BYTE *)(a2 + v5) = v3;
v3 = *(unsigned __int8 *)(v6 + v5 + 1);
v10 = v5 + 1;
if ( (unsigned __int8)v3 <= 0xDu )
{
if ( _bittest64(&v7, v3) )
break;
}
if ( v10 == 31 )
{
xi_set_err(26LL);
return 0LL;
}
}
*(_BYTE *)(a2 + v10) = 0;
if ( v9 <= 1 || v9 == 4 )
goto LABEL_11;
if ( v9 == 2 )
{
v12 = atoi((const char *)a2);
*(_DWORD *)(a2 + 32) = 0;
*(_DWORD *)a2 = v12;
return a2;
}
if ( v9 != 3 )
goto LABEL_11;
v14 = atof((const char *)a2);
result = a2;
*(_DWORD *)(a2 + 32) = 1;
*(float *)&v14 = v14;
*(_DWORD *)a2 = LODWORD(v14);
return result;
}

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)
{
char *v4; // r13
int v5; // ebx
int v6; // ebp
int v7; // eax
int v8; // ebp
unsigned int *v10; // rax
int v11; // eax
__int64 v12[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");
v4 = s;
if ( *(_QWORD *)(a3 + 40) )
{
v12[0] = *(_QWORD *)(a3 + 40);
v10 = (unsigned int *)xi_gmtime(v12);
v11 = snprintf(
s,
a2,
"%04d-%02d-%02dT%02d:%02d:%02d.%06dZ,",
v10[5] + 1900,
v10[4] + 1,
v10[3],
v10[2],
v10[1],
*v10,
*(_QWORD *)(a3 + 48));
v6 = v11;
if ( a2 <= v11 )
goto LABEL_11;
v5 = a2 - v11;
s += v11;
}
else
{
v5 = a2;
v6 = 0;
}
v7 = csv_encode_value(s, v5, (const char *)a3);
if ( v7 < v5 && v7 >= 0 )
{
v8 = v7 + v6;
snprintf(&v4[v8], a2 - v8, "%s", "\n");
if ( a2 - v8 > 1 )
return (unsigned int)(v8 + 1);
}
LABEL_11:
xi_set_err(14LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, int a2, __int64 a3)
{
char *v4; // r13
int v5; // ebx
int v6; // ebp
int v7; // eax
int v8; // ebp
unsigned int *v10; // rax
int v11; // eax
__int64 v12[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");
v4 = s;
if ( *(_QWORD *)(a3 + 40) )
{
v12[0] = *(_QWORD *)(a3 + 40);
v10 = (unsigned int *)xi_gmtime(v12);
v11 = snprintf(
s,
a2,
"%04d-%02d-%02dT%02d:%02d:%02d.%06dZ,",
v10[5] + 1900,
v10[4] + 1,
v10[3],
v10[2],
v10[1],
*v10,
*(_QWORD *)(a3 + 48));
v6 = v11;
if ( a2 <= v11 )
goto LABEL_11;
v5 = a2 - v11;
s += v11;
}
else
{
v5 = a2;
v6 = 0;
}
v7 = func1(s, v5, (const char *)a3);
if ( v7 < v5 && v7 >= 0 )
{
v8 = v7 + v6;
snprintf(&v4[v8], a2 - v8, "%s", "\n");
if ( a2 - v8 > 1 )
return (unsigned int)(v8 + 1);
}
LABEL_11:
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; // er8
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; // er8
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; // r12
char *v3; // rbx
__int64 v4; // rax
int v6; // [rsp+4h] [rbp-74h] BYREF
int v7; // [rsp+8h] [rbp-70h] BYREF
int v8; // [rsp+Ch] [rbp-6Ch] BYREF
int v9; // [rsp+10h] [rbp-68h] BYREF
int v10; // [rsp+14h] [rbp-64h] BYREF
int v11; // [rsp+18h] [rbp-60h] BYREF
int v12; // [rsp+1Ch] [rbp-5Ch] BYREF
int v13[22]; // [rsp+20h] [rbp-58h] 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
&& (unsigned int)_isoc99_sscanf(a1, "%04d-%02d-%02dT%02d:%02d:%02d.%06dZ", &v6, &v7, &v8, &v9, &v10, &v11, &v12) == 7 )
{
v13[5] = v6 - 1900;
v13[4] = v7 - 1;
v13[3] = v8;
v13[2] = v9;
v13[1] = v10;
v13[0] = v11;
v4 = xi_mktime(v13);
if ( (_DWORD)v4 == -1 )
{
v2 = 0LL;
xi_set_err(18LL);
return v2;
}
*(_QWORD *)(a2 + 40) = v4;
*(_QWORD *)(a2 + 48) = v12;
if ( csv_decode_value((unsigned __int8 *)v3 + 1, a2) )
return v2;
}
xi_set_err(17LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2)
{
__int64 v2; // r12
char *v3; // rbx
__int64 v4; // rax
int v6; // [rsp+4h] [rbp-74h] BYREF
int v7; // [rsp+8h] [rbp-70h] BYREF
int v8; // [rsp+Ch] [rbp-6Ch] BYREF
int v9; // [rsp+10h] [rbp-68h] BYREF
int v10; // [rsp+14h] [rbp-64h] BYREF
int v11; // [rsp+18h] [rbp-60h] BYREF
int v12; // [rsp+1Ch] [rbp-5Ch] BYREF
int v13[22]; // [rsp+20h] [rbp-58h] 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
&& (unsigned int)_isoc99_sscanf(a1, "%04d-%02d-%02dT%02d:%02d:%02d.%06dZ", &v6, &v7, &v8, &v9, &v10, &v11, &v12) == 7 )
{
v13[5] = v6 - 1900;
v13[4] = v7 - 1;
v13[3] = v8;
v13[2] = v9;
v13[1] = v10;
v13[0] = v11;
v4 = xi_mktime(v13);
if ( (_DWORD)v4 == -1 )
{
v2 = 0LL;
xi_set_err(18LL);
return v2;
}
*(_QWORD *)(a2 + 40) = v4;
*(_QWORD *)(a2 + 48) = v12;
if ( func2((unsigned __int8 *)v3 + 1, a2) )
return v2;
}
xi_set_err(17LL);
return 0LL;
}

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