repo: bas-t/ffdecsawrapper

decompiled_code:
int __fastcall dump_element_prefix(int a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // rbx
__int64 v4; // rbx

if ( db[4 * a1] == 1000000 )
return puts("PANIC!");
result = dword_4040A4[4 * a1];
switch ( result )
{
case 0:
result = putchar(48);
break;
case 1:
result = putchar(49);
break;
case 2:
result = dword_4040A8[4 * a1] - 10;
switch ( dword_4040A8[4 * a1] )
{
case 10:
result = putchar(97);
break;
case 11:
result = printf("an");
break;
case 20:
result = putchar(98);
break;
case 21:
result = printf("bn");
break;
case 30:
result = putchar(99);
break;
case 31:
result = printf("cn");
break;
case 40:
result = putchar(100);
break;
case 41:
result = printf("dn");
break;
default:
return result;
}
break;
case 3:
printf("FFAND(");
v2 = 4LL * a1;
dump_element_prefix((unsigned int)dword_4040A8[v2]);
putchar(44);
dump_element_prefix((unsigned int)dword_4040AC[v2]);
result = putchar(41);
break;
case 4:
printf("FFOR(");
v3 = 4LL * a1;
dump_element_prefix((unsigned int)dword_4040A8[v3]);
putchar(44);
dump_element_prefix((unsigned int)dword_4040AC[v3]);
result = putchar(41);
break;
case 5:
printf("FFXOR(");
v4 = 4LL * a1;
dump_element_prefix((unsigned int)dword_4040A8[v4]);
putchar(44);
dump_element_prefix((unsigned int)dword_4040AC[v4]);
result = putchar(41);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // rbx
__int64 v4; // rbx

if ( db[4 * a1] == 1000000 )
return puts("PANIC!");
result = dword_4040A4[4 * a1];
switch ( result )
{
case 0:
result = putchar(48);
break;
case 1:
result = putchar(49);
break;
case 2:
result = dword_4040A8[4 * a1] - 10;
switch ( dword_4040A8[4 * a1] )
{
case 10:
result = putchar(97);
break;
case 11:
result = printf("an");
break;
case 20:
result = putchar(98);
break;
case 21:
result = printf("bn");
break;
case 30:
result = putchar(99);
break;
case 31:
result = printf("cn");
break;
case 40:
result = putchar(100);
break;
case 41:
result = printf("dn");
break;
default:
return result;
}
break;
case 3:
printf("FFAND(");
v2 = 4LL * a1;
func7((unsigned int)dword_4040A8[v2]);
putchar(44);
func7((unsigned int)dword_4040AC[v2]);
result = putchar(41);
break;
case 4:
printf("FFOR(");
v3 = 4LL * a1;
func7((unsigned int)dword_4040A8[v3]);
putchar(44);
func7((unsigned int)dword_4040AC[v3]);
result = putchar(41);
break;
case 5:
printf("FFXOR(");
v4 = 4LL * a1;
func7((unsigned int)dword_4040A8[v4]);
putchar(44);
func7((unsigned int)dword_4040AC[v4]);
result = putchar(41);
break;
default:
return result;
}
return result;
}

original_code:
void dump_element_prefix(int e){
  if(db[e].level==1000000){
    printf("PANIC!\n");
    return;
  };
  switch(db[e].op_type){
  case 0:
    printf("0");
    break;
  case 1:
    printf("1");
    break;
  case 2:
    switch(db[e].op1){
    case 10:
      printf("a");
      break;
    case 20:
      printf("b");
      break;
    case 30:
      printf("c");
      break;
    case 40:
      printf("d");
      break;
    case 11:
      printf("an");
      break;
    case 21:
      printf("bn");
      break;
    case 31:
      printf("cn");
      break;
    case 41:
      printf("dn");
      break;
    }
    break;
  case 3:
    printf("FFAND(");
    dump_element_prefix(db[e].op1);
    printf(",");
    dump_element_prefix(db[e].op2);
    printf(")");
    break;
  case 4:
    printf("FFOR(");
    dump_element_prefix(db[e].op1);
    printf(",");
    dump_element_prefix(db[e].op2);
    printf(")");
    break;
  case 5:
    printf("FFXOR(");
    dump_element_prefix(db[e].op1);
    printf(",");
    dump_element_prefix(db[e].op2);
    printf(")");
    break;
  }
}

variable_types: e int


decompiled_code:
int __fastcall dump_element_infix(int a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // rbx
__int64 v4; // rbx

if ( db[4 * a1] == 1000000 )
return puts("PANIC!");
result = dword_4040A4[4 * a1];
switch ( result )
{
case 0:
result = putchar(48);
break;
case 1:
result = putchar(49);
break;
case 2:
result = dword_4040A8[4 * a1] - 10;
switch ( dword_4040A8[4 * a1] )
{
case 10:
result = putchar(97);
break;
case 11:
result = printf("an");
break;
case 20:
result = putchar(98);
break;
case 21:
result = printf("bn");
break;
case 30:
result = putchar(99);
break;
case 31:
result = printf("cn");
break;
case 40:
result = putchar(100);
break;
case 41:
result = printf("dn");
break;
default:
return result;
}
break;
case 3:
printf("( ");
v2 = 4LL * a1;
dump_element_infix((unsigned int)dword_4040A8[v2]);
putchar(38);
dump_element_infix((unsigned int)dword_4040AC[v2]);
result = printf(" )");
break;
case 4:
printf("( ");
v3 = 4LL * a1;
dump_element_infix((unsigned int)dword_4040A8[v3]);
putchar(124);
dump_element_infix((unsigned int)dword_4040AC[v3]);
result = printf(" )");
break;
case 5:
printf("( ");
v4 = 4LL * a1;
dump_element_infix((unsigned int)dword_4040A8[v4]);
putchar(94);
dump_element_infix((unsigned int)dword_4040AC[v4]);
result = printf(" )");
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // rbx
__int64 v4; // rbx

if ( db[4 * a1] == 1000000 )
return puts("PANIC!");
result = dword_4040A4[4 * a1];
switch ( result )
{
case 0:
result = putchar(48);
break;
case 1:
result = putchar(49);
break;
case 2:
result = dword_4040A8[4 * a1] - 10;
switch ( dword_4040A8[4 * a1] )
{
case 10:
result = putchar(97);
break;
case 11:
result = printf("an");
break;
case 20:
result = putchar(98);
break;
case 21:
result = printf("bn");
break;
case 30:
result = putchar(99);
break;
case 31:
result = printf("cn");
break;
case 40:
result = putchar(100);
break;
case 41:
result = printf("dn");
break;
default:
return result;
}
break;
case 3:
printf("( ");
v2 = 4LL * a1;
func8((unsigned int)dword_4040A8[v2]);
putchar(38);
func8((unsigned int)dword_4040AC[v2]);
result = printf(" )");
break;
case 4:
printf("( ");
v3 = 4LL * a1;
func8((unsigned int)dword_4040A8[v3]);
putchar(124);
func8((unsigned int)dword_4040AC[v3]);
result = printf(" )");
break;
case 5:
printf("( ");
v4 = 4LL * a1;
func8((unsigned int)dword_4040A8[v4]);
putchar(94);
func8((unsigned int)dword_4040AC[v4]);
result = printf(" )");
break;
default:
return result;
}
return result;
}

original_code:
void dump_element_infix(int e){
  if(db[e].level==1000000){
    printf("PANIC!\n");
    return;
  };
  switch(db[e].op_type){
  case 0:
    printf("0");
    break;
  case 1:
    printf("1");
    break;
  case 2:
    switch(db[e].op1){
    case 10:
      printf("a");
      break;
    case 20:
      printf("b");
      break;
    case 30:
      printf("c");
      break;
    case 40:
      printf("d");
      break;
    case 11:
      printf("an");
      break;
    case 21:
      printf("bn");
      break;
    case 31:
      printf("cn");
      break;
    case 41:
      printf("dn");
      break;
    }
    break;
  case 3:
    printf("( ");
    dump_element_infix(db[e].op1);
    printf("&");
    dump_element_infix(db[e].op2);
    printf(" )");
    break;
  case 4:
    printf("( ");
    dump_element_infix(db[e].op1);
    printf("|");
    dump_element_infix(db[e].op2);
    printf(" )");
    break;
  case 5:
    printf("( ");
    dump_element_infix(db[e].op1);
    printf("^");
    dump_element_infix(db[e].op2);
    printf(" )");
    break;
  }
}

return_type: void


main

canonical_name: main

variable_types: i int

variable_types: j int

variable_types: l int

variable_types: candidate int

return_type: int


original_code:
int nmea_gen_GPGGA(char *buff, int buff_sz, nmeaGPGGA *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPGGA,%02d%02d%02d.%02d,%07.4f,%C,%07.4f,%C,%1d,%02d,%03.1f,%03.1f,%C,%03.1f,%C,%03.1f,%04d",
        pack->utc.hour, pack->utc.min, pack->utc.sec, pack->utc.hsec,
        pack->lat, pack->ns, pack->lon, pack->ew,
        pack->sig, pack->satinuse, pack->HDOP, pack->elv, pack->elv_units,
        pack->diff, pack->diff_units, pack->dgps_age, pack->dgps_sid);
}

canonical_original_code:
int nmea_gen_GPGGA(char *buff, int buff_sz, struct _nmeaGPGGA *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPGGA,%02d%02d%02d.%02d,%07.4f,%C,%07.4f,%C,%1d,%02d,%03.1f,%03.1f,%C,%03.1f,%C,%03.1f,%04d",
        pack->utc.hour, pack->utc.min, pack->utc.sec, pack->utc.hsec,
        pack->lat, pack->ns, pack->lon, pack->ew,
        pack->sig, pack->satinuse, pack->HDOP, pack->elv, pack->elv_units,
        pack->diff, pack->diff_units, pack->dgps_age, pack->dgps_sid);
}

variable_types:
buff
char *

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

user_defined_types: struct _nmeaGPGGA { struct _nmeaTIME 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; }


original_code:
int nmea_gen_GPGSA(char *buff, int buff_sz, nmeaGPGSA *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPGSA,%C,%1d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%03.1f,%03.1f,%03.1f",
        pack->fix_mode, pack->fix_type,
        pack->sat_prn[0], pack->sat_prn[1], pack->sat_prn[2], pack->sat_prn[3], pack->sat_prn[4], pack->sat_prn[5],
        pack->sat_prn[6], pack->sat_prn[7], pack->sat_prn[8], pack->sat_prn[9], pack->sat_prn[10], pack->sat_prn[11],
        pack->PDOP, pack->HDOP, pack->VDOP);
}

canonical_original_code:
int nmea_gen_GPGSA(char *buff, int buff_sz, struct _nmeaGPGSA *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPGSA,%C,%1d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%02d,%03.1f,%03.1f,%03.1f",
        pack->fix_mode, pack->fix_type,
        pack->sat_prn[0], pack->sat_prn[1], pack->sat_prn[2], pack->sat_prn[3], pack->sat_prn[4], pack->sat_prn[5],
        pack->sat_prn[6], pack->sat_prn[7], pack->sat_prn[8], pack->sat_prn[9], pack->sat_prn[10], pack->sat_prn[11],
        pack->PDOP, pack->HDOP, pack->VDOP);
}

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


original_code:
int nmea_gen_GPGSV(char *buff, int buff_sz, nmeaGPGSV *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPGSV,%1d,%1d,%02d,"
        "%02d,%02d,%03d,%02d,"
        "%02d,%02d,%03d,%02d,"
        "%02d,%02d,%03d,%02d,"
        "%02d,%02d,%03d,%02d",
        pack->pack_count, pack->pack_index + 1, pack->sat_count,
        pack->sat_data[0].id, pack->sat_data[0].elv, pack->sat_data[0].azimuth, pack->sat_data[0].sig,
        pack->sat_data[1].id, pack->sat_data[1].elv, pack->sat_data[1].azimuth, pack->sat_data[1].sig,
        pack->sat_data[2].id, pack->sat_data[2].elv, pack->sat_data[2].azimuth, pack->sat_data[2].sig,
        pack->sat_data[3].id, pack->sat_data[3].elv, pack->sat_data[3].azimuth, pack->sat_data[3].sig);
}

canonical_original_code:
int nmea_gen_GPGSV(char *buff, int buff_sz, struct _nmeaGPGSV *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPGSV,%1d,%1d,%02d,"
        "%02d,%02d,%03d,%02d,"
        "%02d,%02d,%03d,%02d,"
        "%02d,%02d,%03d,%02d,"
        "%02d,%02d,%03d,%02d",
        pack->pack_count, pack->pack_index + 1, pack->sat_count,
        pack->sat_data[0].id, pack->sat_data[0].elv, pack->sat_data[0].azimuth, pack->sat_data[0].sig,
        pack->sat_data[1].id, pack->sat_data[1].elv, pack->sat_data[1].azimuth, pack->sat_data[1].sig,
        pack->sat_data[2].id, pack->sat_data[2].elv, pack->sat_data[2].azimuth, pack->sat_data[2].sig,
        pack->sat_data[3].id, pack->sat_data[3].elv, pack->sat_data[3].azimuth, pack->sat_data[3].sig);
}

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


original_code:
int nmea_gen_GPRMC(char *buff, int buff_sz, nmeaGPRMC *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPRMC,%02d%02d%02d.%02d,%C,%07.4f,%C,%07.4f,%C,%03.1f,%03.1f,%02d%02d%02d,%03.1f,%C,%C",
        pack->utc.hour, pack->utc.min, pack->utc.sec, pack->utc.hsec,
        pack->status, pack->lat, pack->ns, pack->lon, pack->ew,
        pack->speed, pack->direction,
        pack->utc.day, pack->utc.mon + 1, pack->utc.year - 100,
        pack->declination, pack->declin_ew, pack->mode);
}

canonical_original_code:
int nmea_gen_GPRMC(char *buff, int buff_sz, struct _nmeaGPRMC *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPRMC,%02d%02d%02d.%02d,%C,%07.4f,%C,%07.4f,%C,%03.1f,%03.1f,%02d%02d%02d,%03.1f,%C,%C",
        pack->utc.hour, pack->utc.min, pack->utc.sec, pack->utc.hsec,
        pack->status, pack->lat, pack->ns, pack->lon, pack->ew,
        pack->speed, pack->direction,
        pack->utc.day, pack->utc.mon + 1, pack->utc.year - 100,
        pack->declination, pack->declin_ew, pack->mode);
}

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

user_defined_types: struct _nmeaGPRMC { struct _nmeaTIME utc; char status; double lat; char ns; double lon; char ew; double speed; double direction; double declination; char declin_ew; char mode; }


original_code:
int nmea_gen_GPVTG(char *buff, int buff_sz, nmeaGPVTG *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPVTG,%.1f,%C,%.1f,%C,%.1f,%C,%.1f,%C",
        pack->dir, pack->dir_t,
        pack->dec, pack->dec_m,
        pack->spn, pack->spn_n,
        pack->spk, pack->spk_k);
}

canonical_original_code:
int nmea_gen_GPVTG(char *buff, int buff_sz, struct _nmeaGPVTG *pack)
{
    return nmea_printf(buff, buff_sz,
        "$GPVTG,%.1f,%C,%.1f,%C,%.1f,%C,%.1f,%C",
        pack->dir, pack->dir_t,
        pack->dec, pack->dec_m,
        pack->spn, pack->spn_n,
        pack->spk, pack->spk_k);
}

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


original_code:
void nmea_info2GPGGA(const nmeaINFO *info, nmeaGPGGA *pack)
{
    nmea_zero_GPGGA(pack);
    pack->utc = info->utc;
    pack->lat = fabs(info->lat);
    pack->ns = ((info->lat > 0)?'N':'S');
    pack->lon = fabs(info->lon);
    pack->ew = ((info->lon > 0)?'E':'W');
    pack->sig = info->sig;
    pack->satinuse = info->satinfo.inuse;
    pack->HDOP = info->HDOP;
    pack->elv = info->elv;
}

canonical_original_code:
void nmea_info2GPGGA(struct _nmeaINFO *info, struct _nmeaGPGGA *pack)
{
    nmea_zero_GPGGA(pack);
    pack->utc = info->utc;
    pack->lat = fabs(info->lat);
    pack->ns = ((info->lat > 0)?'N':'S');
    pack->lon = fabs(info->lon);
    pack->ew = ((info->lon > 0)?'E':'W');
    pack->sig = info->sig;
    pack->satinuse = info->satinfo.inuse;
    pack->HDOP = info->HDOP;
    pack->elv = info->elv;
}

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 _nmeaGPGGA { struct _nmeaTIME 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; } *

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


original_code:
void nmea_info2GPGSA(const nmeaINFO *info, nmeaGPGSA *pack)
{
    int it;
    nmea_zero_GPGSA(pack);
    pack->fix_type = info->fix;
    pack->PDOP = info->PDOP;
    pack->HDOP = info->HDOP;
    pack->VDOP = info->VDOP;
    for(it = 0; it < (12); ++it)
    {
        pack->sat_prn[it] =
            ((info->satinfo.sat[it].in_use)?info->satinfo.sat[it].id:0);
    }
}

canonical_original_code:
void nmea_info2GPGSA(struct _nmeaINFO *info, struct _nmeaGPGSA *pack)
{
    int it;
    nmea_zero_GPGSA(pack);
    pack->fix_type = info->fix;
    pack->PDOP = info->PDOP;
    pack->HDOP = info->HDOP;
    pack->VDOP = info->VDOP;
    for(it = 0; it < (12); ++it)
    {
        pack->sat_prn[it] =
            ((info->satinfo.sat[it].in_use)?info->satinfo.sat[it].id:0);
    }
}

variable_types: it int

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

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

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


decompiled_code:
__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;
v2.m128d_f64[0] = v1;
if ( COERCE_DOUBLE(*(_QWORD *)&v1 & LC5) < 4.503599627370496e15 )
{
v3.m128d_f64[0] = (double)(int)v1;
*(_QWORD *)&v2.m128d_f64[0] = COERCE_UNSIGNED_INT64(COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v2, v3) & LC9) + v3.m128d_f64[0]) | ~(_QWORD)LC5 & *(_QWORD *)&v1;
}
result = (unsigned int)(int)v2.m128d_f64[0];
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;
v2.m128d_f64[0] = v1;
if ( COERCE_DOUBLE(*(_QWORD *)&v1 & LC5) < 4.503599627370496e15 )
{
v3.m128d_f64[0] = (double)(int)v1;
*(_QWORD *)&v2.m128d_f64[0] = COERCE_UNSIGNED_INT64(COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v2, v3) & LC9) + v3.m128d_f64[0]) | ~(_QWORD)LC5 & *(_QWORD *)&v1;
}
result = (unsigned int)(int)v2.m128d_f64[0];
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;
}


original_code:
void nmea_info2GPGSV(const nmeaINFO *info, nmeaGPGSV *pack, int pack_idx)
{
    int sit, pit;
    nmea_zero_GPGSV(pack);
    pack->sat_count = (info->satinfo.inview <= (12))?info->satinfo.inview:(12);
    pack->pack_count = nmea_gsv_npack(pack->sat_count);
    if(pack->pack_count == 0)
        pack->pack_count = 1;
    if(pack_idx >= pack->pack_count)
        pack->pack_index = pack_idx % pack->pack_count;
    else
        pack->pack_index = pack_idx;
    for(pit = 0, sit = pack->pack_index * (4); pit < (4); ++pit, ++sit)
        pack->sat_data[pit] = info->satinfo.sat[sit];
}

canonical_original_code:
void nmea_info2GPGSV(struct _nmeaINFO *info, struct _nmeaGPGSV *pack, int pack_idx)
{
    int sit; int pit;
    nmea_zero_GPGSV(pack);
    pack->sat_count = (info->satinfo.inview <= (12))?info->satinfo.inview:(12);
    pack->pack_count = nmea_gsv_npack(pack->sat_count);
    if(pack->pack_count == 0)
        pack->pack_count = 1;
    if(pack_idx >= pack->pack_count)
        pack->pack_index = pack_idx % pack->pack_count;
    else
        pack->pack_index = pack_idx;
    for(pit = 0, sit = pack->pack_index * (4); pit < (4); ++pit, ++sit)
        pack->sat_data[pit] = info->satinfo.sat[sit];
}

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

variable_types: sit int

variable_types: pit int


original_code:
void nmea_info2GPRMC(const nmeaINFO *info, nmeaGPRMC *pack)
{
    nmea_zero_GPRMC(pack);
    pack->utc = info->utc;
    pack->status = ((info->sig > 0)?'A':'V');
    pack->lat = fabs(info->lat);
    pack->ns = ((info->lat > 0)?'N':'S');
    pack->lon = fabs(info->lon);
    pack->ew = ((info->lon > 0)?'E':'W');
    pack->speed = info->speed / (1.852);
    pack->direction = info->direction;
    pack->declination = info->declination;
    pack->declin_ew = 'E';
    pack->mode = ((info->sig > 0)?'A':'N');
}

canonical_original_code:
void nmea_info2GPRMC(struct _nmeaINFO *info, struct _nmeaGPRMC *pack)
{
    nmea_zero_GPRMC(pack);
    pack->utc = info->utc;
    pack->status = ((info->sig > 0)?'A':'V');
    pack->lat = fabs(info->lat);
    pack->ns = ((info->lat > 0)?'N':'S');
    pack->lon = fabs(info->lon);
    pack->ew = ((info->lon > 0)?'E':'W');
    pack->speed = info->speed / (1.852);
    pack->direction = info->direction;
    pack->declination = info->declination;
    pack->declin_ew = 'E';
    pack->mode = ((info->sig > 0)?'A':'N');
}

variable_types: struct _nmeaGPRMC { struct _nmeaTIME utc; char status; double lat; char ns; double lon; char ew; double speed; double direction; double declination; char declin_ew; char mode; } *


original_code:
void nmea_info2GPVTG(const nmeaINFO *info, nmeaGPVTG *pack)
{
    nmea_zero_GPVTG(pack);
    pack->dir = info->direction;
    pack->dec = info->declination;
    pack->spn = info->speed / (1.852);
    pack->spk = info->speed;
}

canonical_original_code:
void nmea_info2GPVTG(struct _nmeaINFO *info, struct _nmeaGPVTG *pack)
{
    nmea_zero_GPVTG(pack);
    pack->dir = info->direction;
    pack->dec = info->declination;
    pack->spn = info->speed / (1.852);
    pack->spk = info->speed;
}

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


decompiled_code:
__int64 __fastcall nmea_generate(__int64 a1, int a2, __int64 a3, int a4)
{
unsigned int v6; // ebx
int v7; // er12
unsigned int i; // er14
int v10; // [rsp+Ch] [rbp-20Ch]
char v11[64]; // [rsp+10h] [rbp-208h] BYREF
char v12[96]; // [rsp+50h] [rbp-1C8h] BYREF
unsigned int v13[24]; // [rsp+B0h] [rbp-168h] BYREF
double v14[10]; // [rsp+110h] [rbp-108h] BYREF
__m128i v15[11]; // [rsp+160h] [rbp-B8h] BYREF

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


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


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

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

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


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, _DWORD *a2)
{
a2[8] = 3;
a2[9] = 3;
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: deg double

variable_types: srt double


decompiled_code:
__int64 __fastcall nmea_igen_rotate_init(__int64 a1, _DWORD *a2)
{
a2[8] = 3;
a2[9] = 3;
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


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

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

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

variable_types: min double

variable_types: max double

variable_types: bounds double

return_type: double


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

variable_types: it int


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)
{
__int64 v2; // rbx
int v3; // er12
__int64 result; // rax
__int64 (__fastcall *v5)(__int64, int *); // rdx

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

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

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

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

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

variable_types: RetVal int

variable_types: smask int


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

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

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

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

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

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


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

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

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

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

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

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


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


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

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

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

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

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

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

variable_types:
gen
struct _nmeaGENERATOR *


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

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

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

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

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

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

variable_types:
buff
char *

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

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

variable_types: retval int


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

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

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

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

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


decompiled_code:
__int64 __fastcall nmea_parser_init(_QWORD *a1)
{
int v1; // eax
int v2; // ebp
void *v3; // rax
__int64 result; // rax

v1 = *(_DWORD *)(nmea_property() + 16);
if ( !a1 )
_assert_fail("parser", "src/parser.c", 0x2Cu, "nmea_parser_init");
v2 = 256;
if ( v1 >= 256 )
v2 = v1;
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 0LL;
v3 = malloc(v2);
a1[2] = v3;
if ( v3 )
{
*((_DWORD *)a1 + 6) = v2;
result = 1LL;
}
else
{
nmea_error("Insufficient memory!");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
int v1; // eax
int v2; // ebp
void *v3; // rax
__int64 result; // rax

v1 = *(_DWORD *)(nmea_property() + 16);
if ( !a1 )
_assert_fail("parser", "src/parser.c", 0x2Cu, "nmea_parser_init");
v2 = 256;
if ( v1 >= 256 )
v2 = v1;
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 0LL;
v3 = malloc(v2);
a1[2] = v3;
if ( v3 )
{
*((_DWORD *)a1 + 6) = v2;
result = 1LL;
}
else
{
nmea_error("Insufficient memory!");
result = 0LL;
}
return result;
}

original_code:
int nmea_parser_init(nmeaPARSER *parser)
{
    int resv = 0;
    int buff_size = nmea_property()->parse_buff_size;
    ((void) sizeof ((parser) ? 1 : 0), __extension__ ({ if (parser) ; else __assert_fail ("parser", "src/parser.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    if(buff_size < (256))
        buff_size = (256);
    memset(parser, 0, sizeof(nmeaPARSER));
    if(0 == (parser->buffer = malloc(buff_size)))
        nmea_error("Insufficient memory!");
    else
    {
        parser->buff_size = buff_size;
        resv = 1;
    }
    return resv;
}

canonical_original_code:
int nmea_parser_init(struct _nmeaPARSER *parser)
{
    int resv = 0;
    int buff_size = nmea_property()->parse_buff_size;
    ((void) sizeof ((parser) ? 1 : 0), __extension__ ({ if (parser) ; else __assert_fail ("parser", "src/parser.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    if(buff_size < (256))
        buff_size = (256);
    memset(parser, 0, sizeof(nmeaPARSER));
    if(0 == (parser->buffer = malloc(buff_size)))
        nmea_error("Insufficient memory!");
    else
    {
        parser->buff_size = buff_size;
        resv = 1;
    }
    return resv;
}

variable_types: struct _nmeaPARSER { void *top_node; void *end_node; unsigned char *buffer; int buff_size; int buff_use; } *

variable_types: resv int


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

v1 = *a1;
if ( !a1[2] )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x12Cu, "nmea_parser_top");
v2 = 0;
if ( v1 )
v2 = *v1;
return v2;
}

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

v1 = *a1;
if ( !a1[2] )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x12Cu, "nmea_parser_top");
v2 = 0;
if ( v1 )
v2 = *v1;
return v2;
}

original_code:
int nmea_parser_top(nmeaPARSER *parser)
{
    int retval = GPNON;
    nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node;
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 300, __extension__ __PRETTY_FUNCTION__); }));
    if(node)
        retval = node->packType;
    return retval;
}

canonical_original_code:
int nmea_parser_top(struct _nmeaPARSER *parser)
{
    int retval = GPNON;
    struct _nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node;
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 300, __extension__ __PRETTY_FUNCTION__); }));
    if(node)
        retval = node->packType;
    return retval;
}

variable_types: struct _nmeaParserNODE { int packType; void *pack; struct _nmeaParserNODE *next_node; } *

user_defined_types: struct _nmeaPARSER { void *top_node; void *end_node; unsigned char *buffer; int buff_size; int buff_use; }


decompiled_code:
__int64 __fastcall nmea_parser_pop(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // rax
unsigned int v3; // ebx
__int64 v4; // rdx

v2 = *(_QWORD **)a1;
if ( !*(_QWORD *)(a1 + 16) )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x13Eu, "nmea_parser_pop");
v3 = 0;
if ( v2 )
{
*a2 = v2[1];
v3 = *(_DWORD *)v2;
v4 = v2[2];
*(_QWORD *)a1 = v4;
if ( !v4 )
*(_QWORD *)(a1 + 8) = 0LL;
free(v2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // rax
unsigned int v3; // ebx
__int64 v4; // rdx

v2 = *(_QWORD **)a1;
if ( !*(_QWORD *)(a1 + 16) )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x13Eu, "nmea_parser_pop");
v3 = 0;
if ( v2 )
{
*a2 = v2[1];
v3 = *(_DWORD *)v2;
v4 = v2[2];
*(_QWORD *)a1 = v4;
if ( !v4 )
*(_QWORD *)(a1 + 8) = 0LL;
free(v2);
}
return v3;
}

original_code:
int nmea_parser_pop(nmeaPARSER *parser, void **pack_ptr)
{
    int retval = GPNON;
    nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node;
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 318, __extension__ __PRETTY_FUNCTION__); }));
    if(node)
    {
        *pack_ptr = node->pack;
        retval = node->packType;
        parser->top_node = node->next_node;
        if(!parser->top_node)
            parser->end_node = 0;
        free(node);
    }
    return retval;
}

canonical_original_code:
int nmea_parser_pop(struct _nmeaPARSER *parser, void **pack_ptr)
{
    int retval = GPNON;
    struct _nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node;
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 318, __extension__ __PRETTY_FUNCTION__); }));
    if(node)
    {
        *pack_ptr = node->pack;
        retval = node->packType;
        parser->top_node = node->next_node;
        if(!parser->top_node)
            parser->end_node = 0;
        free(node);
    }
    return retval;
}

user_defined_types: struct _nmeaParserNODE { int packType; void *pack; struct _nmeaParserNODE *next_node; }


decompiled_code:
__int64 __fastcall nmea_parser_peek(int **a1, _QWORD *a2)
{
int *v2; // rax
unsigned int v3; // edx

v2 = *a1;
if ( !a1[2] )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x157u, "nmea_parser_peek");
v3 = 0;
if ( v2 )
{
*a2 = *((_QWORD *)v2 + 1);
v3 = *v2;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(int **a1, _QWORD *a2)
{
int *v2; // rax
unsigned int v3; // edx

v2 = *a1;
if ( !a1[2] )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x157u, "nmea_parser_peek");
v3 = 0;
if ( v2 )
{
*a2 = *((_QWORD *)v2 + 1);
v3 = *v2;
}
return v3;
}

original_code:
int nmea_parser_peek(nmeaPARSER *parser, void **pack_ptr)
{
    int retval = GPNON;
    nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node;
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 343, __extension__ __PRETTY_FUNCTION__); }));
    if(node)
    {
        *pack_ptr = node->pack;
        retval = node->packType;
    }
    return retval;
}

canonical_original_code:
int nmea_parser_peek(struct _nmeaPARSER *parser, void **pack_ptr)
{
    int retval = GPNON;
    struct _nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node;
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 343, __extension__ __PRETTY_FUNCTION__); }));
    if(node)
    {
        *pack_ptr = node->pack;
        retval = node->packType;
    }
    return retval;
}


decompiled_code:
__int64 __fastcall nmea_parser_drop(__int64 a1)
{
_QWORD *v1; // rbp
unsigned int v3; // er12
void *v4; // rdi
__int64 v5; // rax

v1 = *(_QWORD **)a1;
if ( !*(_QWORD *)(a1 + 16) )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x16Cu, "nmea_parser_drop");
v3 = 0;
if ( v1 )
{
v4 = (void *)v1[1];
if ( v4 )
free(v4);
v3 = *(_DWORD *)v1;
v5 = v1[2];
*(_QWORD *)a1 = v5;
if ( !v5 )
*(_QWORD *)(a1 + 8) = 0LL;
free(v1);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
_QWORD *v1; // rbp
unsigned int v3; // er12
void *v4; // rdi
__int64 v5; // rax

v1 = *(_QWORD **)a1;
if ( !*(_QWORD *)(a1 + 16) )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x16Cu, "nmea_parser_drop");
v3 = 0;
if ( v1 )
{
v4 = (void *)v1[1];
if ( v4 )
free(v4);
v3 = *(_DWORD *)v1;
v5 = v1[2];
*(_QWORD *)a1 = v5;
if ( !v5 )
*(_QWORD *)(a1 + 8) = 0LL;
free(v1);
}
return v3;
}

original_code:
int nmea_parser_drop(nmeaPARSER *parser)
{
    int retval = GPNON;
    nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node;
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 364, __extension__ __PRETTY_FUNCTION__); }));
    if(node)
    {
        if(node->pack)
            free(node->pack);
        retval = node->packType;
        parser->top_node = node->next_node;
        if(!parser->top_node)
            parser->end_node = 0;
        free(node);
    }
    return retval;
}

canonical_original_code:
int nmea_parser_drop(struct _nmeaPARSER *parser)
{
    int retval = GPNON;
    struct _nmeaParserNODE *node = (nmeaParserNODE *)parser->top_node;
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 364, __extension__ __PRETTY_FUNCTION__); }));
    if(node)
    {
        if(node->pack)
            free(node->pack);
        retval = node->packType;
        parser->top_node = node->next_node;
        if(!parser->top_node)
            parser->end_node = 0;
        free(node);
    }
    return retval;
}


decompiled_code:
__int64 __fastcall nmea_parser_buff_clear(__int64 a1)
{
if ( !a1 || !*(_QWORD *)(a1 + 16) )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x182u, "nmea_parser_buff_clear");
*(_DWORD *)(a1 + 28) = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( !a1 || !*(_QWORD *)(a1 + 16) )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x182u, "nmea_parser_buff_clear");
*(_DWORD *)(a1 + 28) = 0;
return 1LL;
}

original_code:
int nmea_parser_buff_clear(nmeaPARSER *parser)
{
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 386, __extension__ __PRETTY_FUNCTION__); }));
    parser->buff_use = 0;
    return 1;
}

canonical_original_code:
int nmea_parser_buff_clear(struct _nmeaPARSER *parser)
{
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 386, __extension__ __PRETTY_FUNCTION__); }));
    parser->buff_use = 0;
    return 1;
}


decompiled_code:
__int64 __fastcall nmea_parser_real_push(__int64 a1, const void *a2, int a3)
{
unsigned int i; // ebp
unsigned int v6; // eax
void *v7; // rdx
__int64 v8; // rax
unsigned int v9; // ebx
int v10; // er15
_QWORD *v11; // rax
_QWORD *v12; // r13
void *v13; // rdx
void *v14; // rdx
void *v15; // rdx
void *v16; // rdx
int v17[15]; // [rsp+Ch] [rbp-3Ch] BYREF

if ( !a1 || !*(_QWORD *)(a1 + 16) )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x80u, "nmea_parser_real_push");
if ( *(_DWORD *)(a1 + 28) + a3 >= *(_DWORD *)(a1 + 24) )
nmea_parser_buff_clear(a1);
memcpy((void *)(*(_QWORD *)(a1 + 16) + *(int *)(a1 + 28)), a2, a3);
*(_DWORD *)(a1 + 28) += a3;
for ( i = 0; ; i += v9 )
{
v9 = nmea_find_tail(*(_QWORD *)(a1 + 16) + (int)i, *(_DWORD *)(a1 + 28) - i, v17);
if ( !v9 )
{
if ( i )
{
v6 = *(_DWORD *)(a1 + 28) - i;
*(_DWORD *)(a1 + 28) = v6;
memcpy(*(void **)(a1 + 16), (const void *)(*(_QWORD *)(a1 + 16) + (int)i), (int)v6);
}
return i;
}
if ( v17[0] >= 0 )
break;
LABEL_17:
;
}
v10 = nmea_pack_type(*(_QWORD *)(a1 + 16) + (int)i + 1LL, *(_DWORD *)(a1 + 28) + ~i);
v11 = malloc(0x18uLL);
v12 = v11;
if ( !v11 )
goto LABEL_37;
v11[1] = 0LL;
switch ( v10 )
{
case 1:
v7 = malloc(0x80uLL);
v12[1] = v7;
if ( !v7 )
goto LABEL_36;
*(_DWORD *)v12 = 1;
if ( (unsigned int)nmea_parse_GPGGA(*(_QWORD *)(a1 + 16) + (int)i, v9, v7) )
goto LABEL_12;
goto LABEL_34;
case 2:
v13 = malloc(0x50uLL);
v12[1] = v13;
if ( !v13 )
goto LABEL_36;
*(_DWORD *)v12 = 2;
if ( !(unsigned int)nmea_parse_GPGSA(*(_QWORD *)(a1 + 16) + (int)i, v9, v13) )
goto LABEL_34;
goto LABEL_12;
case 4:
v14 = malloc(0x5CuLL);
v12[1] = v14;
if ( !v14 )
goto LABEL_36;
*(_DWORD *)v12 = 4;
if ( !(unsigned int)nmea_parse_GPGSV(*(_QWORD *)(a1 + 16) + (int)i, v9, v14) )
goto LABEL_34;
goto LABEL_12;
case 8:
v15 = malloc(0x60uLL);
v12[1] = v15;
if ( !v15 )
goto LABEL_36;
*(_DWORD *)v12 = 8;
if ( !(unsigned int)nmea_parse_GPRMC(*(_QWORD *)(a1 + 16) + (int)i, v9, v15) )
goto LABEL_34;
goto LABEL_12;
case 16:
v16 = malloc(0x40uLL);
v12[1] = v16;
if ( v16 )
{
*(_DWORD *)v12 = 16;
if ( (unsigned int)nmea_parse_GPVTG(*(_QWORD *)(a1 + 16) + (int)i, v9, v16) )
{
LABEL_12:
v8 = *(_QWORD *)(a1 + 8);
if ( v8 )
*(_QWORD *)(v8 + 16) = v12;
*(_QWORD *)(a1 + 8) = v12;
if ( !*(_QWORD *)a1 )
*(_QWORD *)a1 = v12;
v12[2] = 0LL;
}
else
{
LABEL_34:
free(v12);
}
goto LABEL_17;
}
LABEL_36:
free(v12);
LABEL_37:
nmea_error("Insufficient memory!");
return (unsigned int)-1;
default:
free(v11);
goto LABEL_17;
}
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const void *a2, int a3)
{
unsigned int i; // ebp
unsigned int v6; // eax
void *v7; // rdx
__int64 v8; // rax
unsigned int v9; // ebx
int v10; // er15
_QWORD *v11; // rax
_QWORD *v12; // r13
void *v13; // rdx
void *v14; // rdx
void *v15; // rdx
void *v16; // rdx
int v17[15]; // [rsp+Ch] [rbp-3Ch] BYREF

if ( !a1 || !*(_QWORD *)(a1 + 16) )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x80u, "nmea_parser_real_push");
if ( *(_DWORD *)(a1 + 28) + a3 >= *(_DWORD *)(a1 + 24) )
func5(a1);
memcpy((void *)(*(_QWORD *)(a1 + 16) + *(int *)(a1 + 28)), a2, a3);
*(_DWORD *)(a1 + 28) += a3;
for ( i = 0; ; i += v9 )
{
v9 = nmea_find_tail(*(_QWORD *)(a1 + 16) + (int)i, *(_DWORD *)(a1 + 28) - i, v17);
if ( !v9 )
{
if ( i )
{
v6 = *(_DWORD *)(a1 + 28) - i;
*(_DWORD *)(a1 + 28) = v6;
memcpy(*(void **)(a1 + 16), (const void *)(*(_QWORD *)(a1 + 16) + (int)i), (int)v6);
}
return i;
}
if ( v17[0] >= 0 )
break;
LABEL_17:
;
}
v10 = nmea_pack_type(*(_QWORD *)(a1 + 16) + (int)i + 1LL, *(_DWORD *)(a1 + 28) + ~i);
v11 = malloc(0x18uLL);
v12 = v11;
if ( !v11 )
goto LABEL_37;
v11[1] = 0LL;
switch ( v10 )
{
case 1:
v7 = malloc(0x80uLL);
v12[1] = v7;
if ( !v7 )
goto LABEL_36;
*(_DWORD *)v12 = 1;
if ( (unsigned int)nmea_parse_GPGGA(*(_QWORD *)(a1 + 16) + (int)i, v9, v7) )
goto LABEL_12;
goto LABEL_34;
case 2:
v13 = malloc(0x50uLL);
v12[1] = v13;
if ( !v13 )
goto LABEL_36;
*(_DWORD *)v12 = 2;
if ( !(unsigned int)nmea_parse_GPGSA(*(_QWORD *)(a1 + 16) + (int)i, v9, v13) )
goto LABEL_34;
goto LABEL_12;
case 4:
v14 = malloc(0x5CuLL);
v12[1] = v14;
if ( !v14 )
goto LABEL_36;
*(_DWORD *)v12 = 4;
if ( !(unsigned int)nmea_parse_GPGSV(*(_QWORD *)(a1 + 16) + (int)i, v9, v14) )
goto LABEL_34;
goto LABEL_12;
case 8:
v15 = malloc(0x60uLL);
v12[1] = v15;
if ( !v15 )
goto LABEL_36;
*(_DWORD *)v12 = 8;
if ( !(unsigned int)nmea_parse_GPRMC(*(_QWORD *)(a1 + 16) + (int)i, v9, v15) )
goto LABEL_34;
goto LABEL_12;
case 16:
v16 = malloc(0x40uLL);
v12[1] = v16;
if ( v16 )
{
*(_DWORD *)v12 = 16;
if ( (unsigned int)nmea_parse_GPVTG(*(_QWORD *)(a1 + 16) + (int)i, v9, v16) )
{
LABEL_12:
v8 = *(_QWORD *)(a1 + 8);
if ( v8 )
*(_QWORD *)(v8 + 16) = v12;
*(_QWORD *)(a1 + 8) = v12;
if ( !*(_QWORD *)a1 )
*(_QWORD *)a1 = v12;
v12[2] = 0LL;
}
else
{
LABEL_34:
free(v12);
}
goto LABEL_17;
}
LABEL_36:
free(v12);
LABEL_37:
nmea_error("Insufficient memory!");
return (unsigned int)-1;
default:
free(v11);
goto LABEL_17;
}
}

original_code:
int nmea_parser_real_push(nmeaPARSER *parser, const char *buff, int buff_sz)
{
    int nparsed = 0, crc, sen_sz, ptype;
    nmeaParserNODE *node = 0;
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 128, __extension__ __PRETTY_FUNCTION__); }));
    if(parser->buff_use + buff_sz >= parser->buff_size)
        nmea_parser_buff_clear(parser);
    memcpy(parser->buffer + parser->buff_use, buff, buff_sz);
    parser->buff_use += buff_sz;
    for(;;node = 0)
    {
        sen_sz = nmea_find_tail(
            (const char *)parser->buffer + nparsed,
            (int)parser->buff_use - nparsed, &crc);
        if(!sen_sz)
        {
            if(nparsed)
                memcpy(
                parser->buffer,
                parser->buffer + nparsed,
                parser->buff_use -= nparsed);
            break;
        }
        else if(crc >= 0)
        {
            ptype = nmea_pack_type(
                (const char *)parser->buffer + nparsed + 1,
                parser->buff_use - nparsed - 1);
            if(0 == (node = malloc(sizeof(nmeaParserNODE))))
                goto mem_fail;
            node->pack = 0;
            switch(ptype)
            {
            case GPGGA:
                if(0 == (node->pack = malloc(sizeof(nmeaGPGGA))))
                    goto mem_fail;
                node->packType = GPGGA;
                if(!nmea_parse_GPGGA(
                    (const char *)parser->buffer + nparsed,
                    sen_sz, (nmeaGPGGA *)node->pack))
                {
                    free(node);
                    node = 0;
                }
                break;
            case GPGSA:
                if(0 == (node->pack = malloc(sizeof(nmeaGPGSA))))
                    goto mem_fail;
                node->packType = GPGSA;
                if(!nmea_parse_GPGSA(
                    (const char *)parser->buffer + nparsed,
                    sen_sz, (nmeaGPGSA *)node->pack))
                {
                    free(node);
                    node = 0;
                }
                break;
            case GPGSV:
                if(0 == (node->pack = malloc(sizeof(nmeaGPGSV))))
                    goto mem_fail;
                node->packType = GPGSV;
                if(!nmea_parse_GPGSV(
                    (const char *)parser->buffer + nparsed,
                    sen_sz, (nmeaGPGSV *)node->pack))
                {
                    free(node);
                    node = 0;
                }
                break;
            case GPRMC:
                if(0 == (node->pack = malloc(sizeof(nmeaGPRMC))))
                    goto mem_fail;
                node->packType = GPRMC;
                if(!nmea_parse_GPRMC(
                    (const char *)parser->buffer + nparsed,
                    sen_sz, (nmeaGPRMC *)node->pack))
                {
                    free(node);
                    node = 0;
                }
                break;
            case GPVTG:
                if(0 == (node->pack = malloc(sizeof(nmeaGPVTG))))
                    goto mem_fail;
                node->packType = GPVTG;
                if(!nmea_parse_GPVTG(
                    (const char *)parser->buffer + nparsed,
                    sen_sz, (nmeaGPVTG *)node->pack))
                {
                    free(node);
                    node = 0;
                }
                break;
            default:
                free(node);
                node = 0;
                break;
            };
            if(node)
            {
                if(parser->end_node)
                    ((nmeaParserNODE *)parser->end_node)->next_node = node;
                parser->end_node = node;
                if(!parser->top_node)
                    parser->top_node = node;
                node->next_node = 0;
            }
        }
        nparsed += sen_sz;
    }
    return nparsed;
mem_fail:
    if(node)
        free(node);
    nmea_error("Insufficient memory!");
    return -1;
}

canonical_original_code:
int nmea_parser_real_push(struct _nmeaPARSER *parser, char *buff, int buff_sz)
{
    int nparsed = 0; int crc; int sen_sz; int ptype;
    struct _nmeaParserNODE *node = 0;
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 128, __extension__ __PRETTY_FUNCTION__); }));
    if(parser->buff_use + buff_sz >= parser->buff_size)
        nmea_parser_buff_clear(parser);
    memcpy(parser->buffer + parser->buff_use, buff, buff_sz);
    parser->buff_use += buff_sz;
    for(;;node = 0)
    {
        sen_sz = nmea_find_tail(
            (char *)parser->buffer + nparsed,
            (int)parser->buff_use - nparsed, &crc);
        if(!sen_sz)
        {
            if(nparsed)
                memcpy(
                parser->buffer,
                parser->buffer + nparsed,
                parser->buff_use -= nparsed);
            break;
        }
        else if(crc >= 0)
        {
            ptype = nmea_pack_type(
                (char *)parser->buffer + nparsed + 1,
                parser->buff_use - nparsed - 1);
            if(0 == (node = malloc(sizeof(nmeaParserNODE))))
                goto mem_fail;
            node->pack = 0;
            switch(ptype)
            {
            case GPGGA:
                if(0 == (node->pack = malloc(sizeof(nmeaGPGGA))))
                    goto mem_fail;
                node->packType = GPGGA;
                if(!nmea_parse_GPGGA(
                    (char *)parser->buffer + nparsed,
                    sen_sz, (struct _nmeaGPGGA *)node->pack))
                {
                    free(node);
                    node = 0;
                }
                break;
            case GPGSA:
                if(0 == (node->pack = malloc(sizeof(nmeaGPGSA))))
                    goto mem_fail;
                node->packType = GPGSA;
                if(!nmea_parse_GPGSA(
                    (char *)parser->buffer + nparsed,
                    sen_sz, (struct _nmeaGPGSA *)node->pack))
                {
                    free(node);
                    node = 0;
                }
                break;
            case GPGSV:
                if(0 == (node->pack = malloc(sizeof(nmeaGPGSV))))
                    goto mem_fail;
                node->packType = GPGSV;
                if(!nmea_parse_GPGSV(
                    (char *)parser->buffer + nparsed,
                    sen_sz, (struct _nmeaGPGSV *)node->pack))
                {
                    free(node);
                    node = 0;
                }
                break;
            case GPRMC:
                if(0 == (node->pack = malloc(sizeof(nmeaGPRMC))))
                    goto mem_fail;
                node->packType = GPRMC;
                if(!nmea_parse_GPRMC(
                    (char *)parser->buffer + nparsed,
                    sen_sz, (struct _nmeaGPRMC *)node->pack))
                {
                    free(node);
                    node = 0;
                }
                break;
            case GPVTG:
                if(0 == (node->pack = malloc(sizeof(nmeaGPVTG))))
                    goto mem_fail;
                node->packType = GPVTG;
                if(!nmea_parse_GPVTG(
                    (char *)parser->buffer + nparsed,
                    sen_sz, (struct _nmeaGPVTG *)node->pack))
                {
                    free(node);
                    node = 0;
                }
                break;
            default:
                free(node);
                node = 0;
                break;
            };
            if(node)
            {
                if(parser->end_node)
                    ((struct _nmeaParserNODE *)parser->end_node)->next_node = node;
                parser->end_node = node;
                if(!parser->top_node)
                    parser->top_node = node;
                node->next_node = 0;
            }
        }
        nparsed += sen_sz;
    }
    return nparsed;
mem_fail:
    if(node)
        free(node);
    nmea_error("Insufficient memory!");
    return -1;
}

variable_types: nparsed int

variable_types: crc int

variable_types: ptype int


decompiled_code:
__int64 __fastcall nmea_parser_push(__int64 a1, const void *a2, int a3)
{
unsigned int v4; // er13
int v5; // ebp

v4 = 0;
do
{
v5 = a3;
if ( *(_DWORD *)(a1 + 24) <= a3 )
v5 = *(_DWORD *)(a1 + 24);
v4 += nmea_parser_real_push(a1, a2, v5);
a3 -= v5;
}
while ( a3 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const void *a2, int a3)
{
unsigned int v4; // er13
int v5; // ebp

v4 = 0;
do
{
v5 = a3;
if ( *(_DWORD *)(a1 + 24) <= a3 )
v5 = *(_DWORD *)(a1 + 24);
v4 += func6(a1, a2, v5);
a3 -= v5;
}
while ( a3 );
return v4;
}

original_code:
int nmea_parser_push(nmeaPARSER *parser, const char *buff, int buff_sz)
{
    int nparse, nparsed = 0;
    do
    {
        if(buff_sz > parser->buff_size)
            nparse = parser->buff_size;
        else
            nparse = buff_sz;
        nparsed += nmea_parser_real_push(
            parser, buff, nparse);
        buff_sz -= nparse;
    } while(buff_sz);
    return nparsed;
}

canonical_original_code:
int nmea_parser_push(struct _nmeaPARSER *parser, char *buff, int buff_sz)
{
    int nparse; int nparsed = 0;
    do
    {
        if(buff_sz > parser->buff_size)
            nparse = parser->buff_size;
        else
            nparse = buff_sz;
        nparsed += nmea_parser_real_push(
            parser, buff, nparse);
        buff_sz -= nparse;
    } while(buff_sz);
    return nparsed;
}

variable_types: nparse int


decompiled_code:
__int64 __fastcall nmea_parse(__int64 a1, const void *a2, int a3, __int64 a4)
{
unsigned int v5; // ebx
int v6; // eax
void *ptr; // [rsp+8h] [rbp-20h] BYREF

ptr = 0LL;
if ( !a1 || !*(_QWORD *)(a1 + 16) )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x56u, "nmea_parse");
nmea_parser_push(a1, a2, a3);
v5 = 0;
while ( 1 )
{
v6 = nmea_parser_pop(a1, &ptr);
if ( !v6 )
return v5;
++v5;
switch ( v6 )
{
case 1:
nmea_GPGGA2info(ptr, a4);
break;
case 2:
nmea_GPGSA2info(ptr, a4);
break;
case 4:
nmea_GPGSV2info(ptr, a4);
break;
case 8:
nmea_GPRMC2info(ptr, a4);
break;
case 16:
nmea_GPVTG2info(ptr, a4);
break;
default:
break;
}
free(ptr);
}
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const void *a2, int a3, __int64 a4)
{
unsigned int v5; // ebx
int v6; // eax
void *ptr; // [rsp+8h] [rbp-20h] BYREF

ptr = 0LL;
if ( !a1 || !*(_QWORD *)(a1 + 16) )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x56u, "nmea_parse");
func7(a1, a2, a3);
v5 = 0;
while ( 1 )
{
v6 = func2(a1, &ptr);
if ( !v6 )
return v5;
++v5;
switch ( v6 )
{
case 1:
nmea_GPGGA2info(ptr, a4);
break;
case 2:
nmea_GPGSA2info(ptr, a4);
break;
case 4:
nmea_GPGSV2info(ptr, a4);
break;
case 8:
nmea_GPRMC2info(ptr, a4);
break;
case 16:
nmea_GPVTG2info(ptr, a4);
break;
default:
break;
}
free(ptr);
}
}

original_code:
int nmea_parse(
    nmeaPARSER *parser,
    const char *buff, int buff_sz,
    nmeaINFO *info
    )
{
    int ptype, nread = 0;
    void *pack = 0;
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 86, __extension__ __PRETTY_FUNCTION__); }));
    nmea_parser_push(parser, buff, buff_sz);
    while(GPNON != (ptype = nmea_parser_pop(parser, &pack)))
    {
        nread++;
        switch(ptype)
        {
        case GPGGA:
            nmea_GPGGA2info((nmeaGPGGA *)pack, info);
            break;
        case GPGSA:
            nmea_GPGSA2info((nmeaGPGSA *)pack, info);
            break;
        case GPGSV:
            nmea_GPGSV2info((nmeaGPGSV *)pack, info);
            break;
        case GPRMC:
            nmea_GPRMC2info((nmeaGPRMC *)pack, info);
            break;
        case GPVTG:
            nmea_GPVTG2info((nmeaGPVTG *)pack, info);
            break;
        };
        free(pack);
    }
    return nread;
}

canonical_original_code:
int nmea_parse(struct _nmeaPARSER *parser, char *buff, int buff_sz, struct _nmeaINFO *info)
{
    int ptype; int nread = 0;
    void *pack = 0;
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 86, __extension__ __PRETTY_FUNCTION__); }));
    nmea_parser_push(parser, buff, buff_sz);
    while(GPNON != (ptype = nmea_parser_pop(parser, &pack)))
    {
        nread++;
        switch(ptype)
        {
        case GPGGA:
            nmea_GPGGA2info((struct _nmeaGPGGA *)pack, info);
            break;
        case GPGSA:
            nmea_GPGSA2info((struct _nmeaGPGSA *)pack, info);
            break;
        case GPGSV:
            nmea_GPGSV2info((struct _nmeaGPGSV *)pack, info);
            break;
        case GPRMC:
            nmea_GPRMC2info((struct _nmeaGPRMC *)pack, info);
            break;
        case GPVTG:
            nmea_GPVTG2info((struct _nmeaGPVTG *)pack, info);
            break;
        };
        free(pack);
    }
    return nread;
}

variable_types: nread int

variable_types:
pack
void *


decompiled_code:
__int64 __fastcall nmea_parser_queue_clear(_QWORD *a1)
{
if ( !a1 )
_assert_fail("parser", "src/parser.c", 0x18Du, "nmea_parser_queue_clear");
while ( *a1 )
nmea_parser_drop((__int64)a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
if ( !a1 )
_assert_fail("parser", "src/parser.c", 0x18Du, "nmea_parser_queue_clear");
while ( *a1 )
func4((__int64)a1);
return 1LL;
}

original_code:
int nmea_parser_queue_clear(nmeaPARSER *parser)
{
    ((void) sizeof ((parser) ? 1 : 0), __extension__ ({ if (parser) ; else __assert_fail ("parser", "src/parser.c", 397, __extension__ __PRETTY_FUNCTION__); }));
    while(parser->top_node)
        nmea_parser_drop(parser);
    return 1;
}

canonical_original_code:
int nmea_parser_queue_clear(struct _nmeaPARSER *parser)
{
    ((void) sizeof ((parser) ? 1 : 0), __extension__ ({ if (parser) ; else __assert_fail ("parser", "src/parser.c", 397, __extension__ __PRETTY_FUNCTION__); }));
    while(parser->top_node)
        nmea_parser_drop(parser);
    return 1;
}


decompiled_code:
__int64 __fastcall nmea_parser_destroy(_QWORD *a1)
{
void *v2; // rdi
__int64 result; // rax

if ( !a1 || (v2 = (void *)a1[2]) == 0LL )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x43u, "nmea_parser_destroy");
free(v2);
result = nmea_parser_queue_clear(a1);
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
void *v2; // rdi
__int64 result; // rax

if ( !a1 || (v2 = (void *)a1[2]) == 0LL )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x43u, "nmea_parser_destroy");
free(v2);
result = func9(a1);
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 0LL;
return result;
}

original_code:
void nmea_parser_destroy(nmeaPARSER *parser)
{
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 67, __extension__ __PRETTY_FUNCTION__); }));
    free(parser->buffer);
    nmea_parser_queue_clear(parser);
    memset(parser, 0, sizeof(nmeaPARSER));
}

canonical_original_code:
void nmea_parser_destroy(struct _nmeaPARSER *parser)
{
    ((void) sizeof ((parser && parser->buffer) ? 1 : 0), __extension__ ({ if (parser && parser->buffer) ; else __assert_fail ("parser && parser->buffer", "src/parser.c", 67, __extension__ __PRETTY_FUNCTION__); }));
    free(parser->buffer);
    nmea_parser_queue_clear(parser);
    memset(parser, 0, sizeof(nmeaPARSER));
}


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

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

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

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

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

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

variable_types: chsum int

variable_types: it int


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

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

variable_types:
str
char *

variable_types: radix int

variable_types:
buff
char [-1]

variable_types: res int


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

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

variable_types: res double


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

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

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

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

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

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

variable_types:
buff
char *

variable_types:
format
char *

variable_types: retval int

variable_types: add int


decompiled_code:
__int64 lsm303_init()
{
__int64 result; // rax
int v1; // edi
int v2; // edi
ssize_t v3; // rdx
char buf; // [rsp+Eh] [rbp-Ah] BYREF
char v5; // [rsp+Fh] [rbp-9h]

if ( useAcc )
{
v1 = open("/dev/i2c-0", 2306);
facc = v1;
if ( v1 == -1 )
{
printf("open_port: Unable to open i2c-bus");
}
else if ( ioctl(v1, 0x703uLL, 24LL) < 0 )
{
puts("Failed to acquire bus access and/or talk to slave.");
}
else
{
buf = 32;
v5 = 39;
if ( write(facc, &buf, 2uLL) == 2 )
{
buf = 35;
v5 = 64;
if ( write(facc, &buf, 2uLL) == 2 )
goto LABEL_2;
puts("Failed to set REG4");
}
else
{
puts("Failed to set REG1");
}
}
return 0LL;
}
LABEL_2:
result = 1LL;
if ( !useMag )
return result;
v2 = open("/dev/i2c-0", 2306);
fmag = v2;
if ( v2 == -1 )
{
printf("open_port: Unable to open i2c-bus");
return 0LL;
}
if ( ioctl(v2, 0x703uLL, 30LL) < 0 )
{
puts("Failed to acquire bus access and/or talk to slave.");
return 0LL;
}
buf = 0;
v5 = 20;
if ( write(fmag, &buf, 2uLL) != 2 )
{
puts("Failed to set CRA REG");
return 0LL;
}
buf = 1;
v5 = 32;
if ( write(fmag, &buf, 2uLL) != 2 )
{
puts("Failed to set CRB REG");
return 0LL;
}
buf = 2;
v5 = 0;
v3 = write(fmag, &buf, 2uLL);
result = 1LL;
if ( v3 != 2 )
{
puts("Failed to set MR REG");
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int v1; // edi
int v2; // edi
ssize_t v3; // rdx
char buf; // [rsp+Eh] [rbp-Ah] BYREF
char v5; // [rsp+Fh] [rbp-9h]

if ( useAcc )
{
v1 = open("/dev/i2c-0", 2306);
facc = v1;
if ( v1 == -1 )
{
printf("open_port: Unable to open i2c-bus");
}
else if ( ioctl(v1, 0x703uLL, 24LL) < 0 )
{
puts("Failed to acquire bus access and/or talk to slave.");
}
else
{
buf = 32;
v5 = 39;
if ( write(facc, &buf, 2uLL) == 2 )
{
buf = 35;
v5 = 64;
if ( write(facc, &buf, 2uLL) == 2 )
goto LABEL_2;
puts("Failed to set REG4");
}
else
{
puts("Failed to set REG1");
}
}
return 0LL;
}
LABEL_2:
result = 1LL;
if ( !useMag )
return result;
v2 = open("/dev/i2c-0", 2306);
fmag = v2;
if ( v2 == -1 )
{
printf("open_port: Unable to open i2c-bus");
return 0LL;
}
if ( ioctl(v2, 0x703uLL, 30LL) < 0 )
{
puts("Failed to acquire bus access and/or talk to slave.");
return 0LL;
}
buf = 0;
v5 = 20;
if ( write(fmag, &buf, 2uLL) != 2 )
{
puts("Failed to set CRA REG");
return 0LL;
}
buf = 1;
v5 = 32;
if ( write(fmag, &buf, 2uLL) != 2 )
{
puts("Failed to set CRB REG");
return 0LL;
}
buf = 2;
v5 = 0;
v3 = write(fmag, &buf, 2uLL);
result = 1LL;
if ( v3 != 2 )
{
puts("Failed to set MR REG");
return 0LL;
}
return result;
}

original_code:
int lsm303_init()
{
    if(useAcc)
    {
        facc = open("/dev/i2c-0", 02 | 0400 | 04000);
        if (facc == -1)
        {
            printf("open_port: Unable to open i2c-bus");
            return 0;
        }
        if (ioctl(facc, 0x0703, 0x18) < 0)
        {
            printf("Failed to acquire bus access and/or talk to slave.\n");
            return 0;
        }
        int8_t LSM303_CTRL_REG1_set = 0b00100111;
        int8_t LSM303_CTRL_REG4_set = 0b01000000;
        int8_t reg[2];
        reg[0] = 0x20;
        reg[1] = LSM303_CTRL_REG1_set;
        if (write(facc, reg, 2) != 2)
        {
            printf("Failed to set REG1\n");
            return 0;
        }
        reg[0] = 0x23;
        reg[1] = LSM303_CTRL_REG4_set;
        if (write(facc, reg, 2) != 2)
        {
            printf("Failed to set REG4\n");
            return 0;
        }
    }
    if(useMag)
    {
        fmag = open("/dev/i2c-0", 02 | 0400 | 04000);
        if (fmag == -1)
        {
            printf("open_port: Unable to open i2c-bus");
            return 0;
        }
        if (ioctl(fmag, 0x0703, 0x1E) < 0)
        {
            printf("Failed to acquire bus access and/or talk to slave.\n");
            return 0;
        }
        int8_t LSM303_CRA_REG_set = 0b00010100;
        int8_t LSM303_CRB_REG_set = 0b00100000;
        int8_t LSM303_MR_REG_set = 0b00000000;
        int8_t reg[2];
        reg[0] = 0x00;
        reg[1] = LSM303_CRA_REG_set;
        if (write(fmag, reg, 2) != 2)
        {
            printf("Failed to set CRA REG\n");
            return 0;
        }
        reg[0] = 0x01;
        reg[1] = LSM303_CRB_REG_set;
        if (write(fmag, reg, 2) != 2)
        {
            printf("Failed to set CRB REG\n");
            return 0;
        }
        reg[0] = 0x02;
        reg[1] = LSM303_MR_REG_set;
        if (write(fmag, reg, 2) != 2)
        {
            printf("Failed to set MR REG\n");
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
int lsm303_init()
{
    if(useAcc)
    {
        facc = open("/dev/i2c-0", 02 | 0400 | 04000);
        if (facc == -1)
        {
            printf("open_port: Unable to open i2c-bus");
            return 0;
        }
        if (ioctl(facc, 0x0703, 0x18) < 0)
        {
            printf("Failed to acquire bus access and/or talk to slave.\n");
            return 0;
        }
        char LSM303_CTRL_REG1_set = 0b00100111;
        char LSM303_CTRL_REG4_set = 0b01000000;
        char reg[2];
        reg[0] = 0x20;
        reg[1] = LSM303_CTRL_REG1_set;
        if (write(facc, reg, 2) != 2)
        {
            printf("Failed to set REG1\n");
            return 0;
        }
        reg[0] = 0x23;
        reg[1] = LSM303_CTRL_REG4_set;
        if (write(facc, reg, 2) != 2)
        {
            printf("Failed to set REG4\n");
            return 0;
        }
    }
    if(useMag)
    {
        fmag = open("/dev/i2c-0", 02 | 0400 | 04000);
        if (fmag == -1)
        {
            printf("open_port: Unable to open i2c-bus");
            return 0;
        }
        if (ioctl(fmag, 0x0703, 0x1E) < 0)
        {
            printf("Failed to acquire bus access and/or talk to slave.\n");
            return 0;
        }
        char LSM303_CRA_REG_set = 0b00010100;
        char LSM303_CRB_REG_set = 0b00100000;
        char LSM303_MR_REG_set = 0b00000000;
        char reg[2];
        reg[0] = 0x00;
        reg[1] = LSM303_CRA_REG_set;
        if (write(fmag, reg, 2) != 2)
        {
            printf("Failed to set CRA REG\n");
            return 0;
        }
        reg[0] = 0x01;
        reg[1] = LSM303_CRB_REG_set;
        if (write(fmag, reg, 2) != 2)
        {
            printf("Failed to set CRB REG\n");
            return 0;
        }
        reg[0] = 0x02;
        reg[1] = LSM303_MR_REG_set;
        if (write(fmag, reg, 2) != 2)
        {
            printf("Failed to set MR REG\n");
            return 0;
        }
    }
    return 1;
}

variable_types:
reg
char [2]


decompiled_code:
__int64 __fastcall lsm303_read_mag_measurements(float *a1)
{
__int64 result; // rax
char v2[6]; // [rsp+9h] [rbp-Fh] BYREF
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 3;
if ( write(fmag, buf, 1uLL) == 1 )
{
if ( read(fmag, v2, 6uLL) == 6 )
{
*a1 = (float)(v2[1] | (v2[0] << 8)) - xyz_mag_offset[0];
a1[1] = (float)(v2[3] | (v2[2] << 8)) - xyz_mag_offset[1];
a1[2] = (float)(v2[5] | (v2[4] << 8)) - xyz_mag_offset[2];
result = 1LL;
}
else
{
puts("Read magnetometer xyz failed");
result = 0LL;
}
}
else
{
puts("Failed set read register");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(float *a1)
{
__int64 result; // rax
char v2[6]; // [rsp+9h] [rbp-Fh] BYREF
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 3;
if ( write(fmag, buf, 1uLL) == 1 )
{
if ( read(fmag, v2, 6uLL) == 6 )
{
*a1 = (float)(v2[1] | (v2[0] << 8)) - xyz_mag_offset[0];
a1[1] = (float)(v2[3] | (v2[2] << 8)) - xyz_mag_offset[1];
a1[2] = (float)(v2[5] | (v2[4] << 8)) - xyz_mag_offset[2];
result = 1LL;
}
else
{
puts("Read magnetometer xyz failed");
result = 0LL;
}
}
else
{
puts("Failed set read register");
result = 0LL;
}
return result;
}

original_code:
int lsm303_read_mag_measurements(float xyz[3])
{
    int8_t readReg = 0x03;
    if (write(fmag, &readReg, 1) != 1)
    {
        printf("Failed set read register\n");
        return 0;
    }
    int8_t buffer[6];
    if(read(fmag, buffer, 6) != 6)
    {
        printf("Read magnetometer xyz failed\n");
        return 0;
    }
    xyz[0] = (float) ((buffer[0]<<8 | buffer[1])-xyz_mag_offset[0]);
    xyz[1] = (float) ((buffer[2]<<8 | buffer[3])-xyz_mag_offset[1]);
    xyz[2] = (float) ((buffer[4]<<8 | buffer[5])-xyz_mag_offset[2]);
    return 1;
}

canonical_original_code:
int lsm303_read_mag_measurements(float xyz[3])
{
    char readReg = 0x03;
    if (write(fmag, &readReg, 1) != 1)
    {
        printf("Failed set read register\n");
        return 0;
    }
    char buffer[6];
    if(read(fmag, buffer, 6) != 6)
    {
        printf("Read magnetometer xyz failed\n");
        return 0;
    }
    xyz[0] = (float) ((buffer[0]<<8 | buffer[1])-xyz_mag_offset[0]);
    xyz[1] = (float) ((buffer[2]<<8 | buffer[3])-xyz_mag_offset[1]);
    xyz[2] = (float) ((buffer[4]<<8 | buffer[5])-xyz_mag_offset[2]);
    return 1;
}

variable_types:
xyz
float [3]

variable_types: readReg char

variable_types:
buffer
char [6]


decompiled_code:
__int64 __fastcall lsm303_read_magnet_raw(_WORD *a1)
{
__int64 result; // rax
__int16 v2[6]; // [rsp+2h] [rbp-16h] BYREF
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 3;
if ( write(fmag, buf, 1uLL) == 1 )
{
if ( read(fmag, v2, 6uLL) == 6 )
{
*a1 = v2[1] | (v2[0] << 8);
a1[1] = v2[3] | (v2[2] << 8);
a1[2] = v2[5] | (v2[4] << 8);
result = 1LL;
}
else
{
puts("Read magnetometer xyz failed");
result = 0LL;
}
}
else
{
puts("Failed set read register");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_WORD *a1)
{
__int64 result; // rax
__int16 v2[6]; // [rsp+2h] [rbp-16h] BYREF
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 3;
if ( write(fmag, buf, 1uLL) == 1 )
{
if ( read(fmag, v2, 6uLL) == 6 )
{
*a1 = v2[1] | (v2[0] << 8);
a1[1] = v2[3] | (v2[2] << 8);
a1[2] = v2[5] | (v2[4] << 8);
result = 1LL;
}
else
{
puts("Read magnetometer xyz failed");
result = 0LL;
}
}
else
{
puts("Failed set read register");
result = 0LL;
}
return result;
}

original_code:
int lsm303_read_magnet_raw(int16_t xyz[3])
{
    int8_t readReg = 0x03;
    if (write(fmag, &readReg, 1) != 1)
    {
        printf("Failed set read register\n");
        return 0;
    }
    int16_t buffer[6];
    if(read(fmag, buffer, 6) != 6)
    {
        printf("Read magnetometer xyz failed\n");
        return 0;
    }
    xyz[0] = (int16_t)((buffer[0]<<8 | buffer[1]));
    xyz[1] = (int16_t)((buffer[2]<<8 | buffer[3]));
    xyz[2] = (int16_t)((buffer[4]<<8 | buffer[5]));
    return 1;
}

canonical_original_code:
int lsm303_read_magnet_raw(short xyz[3])
{
    char readReg = 0x03;
    if (write(fmag, &readReg, 1) != 1)
    {
        printf("Failed set read register\n");
        return 0;
    }
    short buffer[6];
    if(read(fmag, buffer, 6) != 6)
    {
        printf("Read magnetometer xyz failed\n");
        return 0;
    }
    xyz[0] = (short)((buffer[0]<<8 | buffer[1]));
    xyz[1] = (short)((buffer[2]<<8 | buffer[3]));
    xyz[2] = (short)((buffer[4]<<8 | buffer[5]));
    return 1;
}

variable_types:
xyz
short [3]

variable_types:
buffer
short [6]


decompiled_code:
__int64 __fastcall lsm303_read_magnet_gauss(float *a1)
{
__int64 result; // rax
__int16 v2[7]; // [rsp+Ah] [rbp-Eh] BYREF

result = lsm303_read_magnet_raw(v2);
*a1 = (float)v2[0] / 1050.0;
a1[1] = (float)v2[1] / 1050.0;
a1[2] = (float)v2[2] / 950.0;
return result;
}

original_code:
int lsm303_read_magnet_gauss(float xyz_gauss[3])
{
    int status;
    int16_t xyz_raw[3];
    status = lsm303_read_magnet_raw(xyz_raw);
    xyz_gauss[0] = (float)xyz_raw[0] / magnetometer_gain_gauss[0];
    xyz_gauss[1] = (float)xyz_raw[1] / magnetometer_gain_gauss[1];
    xyz_gauss[2] = (float)xyz_raw[2] / magnetometer_gain_gauss[2];
    return status;
}

canonical_original_code:
int lsm303_read_magnet_gauss(float xyz_gauss[3])
{
    int status;
    short xyz_raw[3];
    status = lsm303_read_magnet_raw(xyz_raw);
    xyz_gauss[0] = (float)xyz_raw[0] / magnetometer_gain_gauss[0];
    xyz_gauss[1] = (float)xyz_raw[1] / magnetometer_gain_gauss[1];
    xyz_gauss[2] = (float)xyz_raw[2] / magnetometer_gain_gauss[2];
    return status;
}

variable_types: status int


decompiled_code:
__int64 __fastcall lsm303_read_magnet_gauss_cal(float *a1)
{
__int64 result; // rax
int v2[5]; // [rsp+4h] [rbp-14h] BYREF

result = lsm303_read_magnet_gauss((float *)v2);
*a1 = *(float *)v2 - xyz_mag_offset_gauss[0];
a1[1] = *(float *)&v2[1] - xyz_mag_offset_gauss[1];
a1[2] = *(float *)&v2[2] - xyz_mag_offset_gauss[2];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(float *a1)
{
__int64 result; // rax
int v2[5]; // [rsp+4h] [rbp-14h] BYREF

result = func3((float *)v2);
*a1 = *(float *)v2 - xyz_mag_offset_gauss[0];
a1[1] = *(float *)&v2[1] - xyz_mag_offset_gauss[1];
a1[2] = *(float *)&v2[2] - xyz_mag_offset_gauss[2];
return result;
}

original_code:
int lsm303_read_magnet_gauss_cal(float xyz[3])
{
    int status;
    float xyz_gauss[3];
    status = lsm303_read_magnet_gauss(xyz_gauss);
    xyz[0] = xyz_gauss[0] - xyz_mag_offset_gauss[0];
    xyz[1] = xyz_gauss[1] - xyz_mag_offset_gauss[1];
    xyz[2] = xyz_gauss[2] - xyz_mag_offset_gauss[2];
    return status;
}


decompiled_code:
__int64 __fastcall lsm303_read_magnet_tesla(float *a1)
{
__int64 result; // rax
__int16 v2[7]; // [rsp+Ah] [rbp-Eh] BYREF

result = lsm303_read_magnet_raw(v2);
*a1 = (float)v2[0] / 10500000.0;
a1[1] = (float)v2[1] / 10500000.0;
a1[2] = (float)v2[2] / 9500000.0;
return result;
}

original_code:
int lsm303_read_magnet_tesla(float xyz_tesla[3])
{
    int status;
    int16_t xyz_raw[3];
    status = lsm303_read_magnet_raw(xyz_raw);
    xyz_tesla[0] = (float)xyz_raw[0] / magnetometer_gain_tesla[0];
    xyz_tesla[1] = (float)xyz_raw[1] / magnetometer_gain_tesla[1];
    xyz_tesla[2] = (float)xyz_raw[2] / magnetometer_gain_tesla[2];
    return status;
}

canonical_original_code:
int lsm303_read_magnet_tesla(float xyz_tesla[3])
{
    int status;
    short xyz_raw[3];
    status = lsm303_read_magnet_raw(xyz_raw);
    xyz_tesla[0] = (float)xyz_raw[0] / magnetometer_gain_tesla[0];
    xyz_tesla[1] = (float)xyz_raw[1] / magnetometer_gain_tesla[1];
    xyz_tesla[2] = (float)xyz_raw[2] / magnetometer_gain_tesla[2];
    return status;
}