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

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; // er8

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; // r8
unsigned int v3; // er12
__int64 v4; // rax

v2 = *(_QWORD **)a1;
if ( !*(_QWORD *)(a1 + 16) )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x13Eu, "nmea_parser_pop");
v3 = 0;
if ( v2 )
{
v3 = *(_DWORD *)v2;
*a2 = v2[1];
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; // r8
unsigned int v3; // er12
__int64 v4; // rax

v2 = *(_QWORD **)a1;
if ( !*(_QWORD *)(a1 + 16) )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x13Eu, "nmea_parser_pop");
v3 = 0;
if ( v2 )
{
v3 = *(_DWORD *)v2;
*a2 = v2[1];
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;
}

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

variable_types: retval int

return_type: int

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


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

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

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

v2 = *a1;
if ( !a1[2] )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x157u, "nmea_parser_peek");
v3 = 0;
if ( v2 )
{
v3 = *v2;
*a2 = *((_QWORD *)v2 + 1);
}
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 v2; // 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");
v2 = 0;
if ( v1 )
{
v4 = (void *)v1[1];
if ( v4 )
free(v4);
v5 = v1[2];
v2 = *(_DWORD *)v1;
*(_QWORD *)a1 = v5;
if ( !v5 )
*(_QWORD *)(a1 + 8) = 0LL;
free(v1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
_QWORD *v1; // rbp
unsigned int v2; // 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");
v2 = 0;
if ( v1 )
{
v4 = (void *)v1[1];
if ( v4 )
free(v4);
v5 = v1[2];
v2 = *(_DWORD *)v1;
*(_QWORD *)a1 = v5;
if ( !v5 )
*(_QWORD *)(a1 + 8) = 0LL;
free(v1);
}
return v2;
}

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, double a4)
{
__int64 v5; // rdi
__int64 v6; // rax
int v8; // er12
int v9; // ebx
int v10; // esi
unsigned int v11; // ebx
int v12; // er15
_QWORD *v13; // rax
_QWORD *v14; // r14
void *v15; // rax
__int64 v16; // rdi
void *v17; // rax
__int64 v18; // rdi
__int64 v19; // rax
bool v20; // zf
void *v21; // rax
__int64 v22; // rdi
void *v23; // rax
__int64 v24; // rdi
void *v25; // rax
__int64 v26; // rdi
char *v28; // rdi
int v29; // eax
int v30[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( !a1 || (v5 = *(_QWORD *)(a1 + 16)) == 0 )
_assert_fail("parser && parser->buffer", "src/parser.c", 0x80u, "nmea_parser_real_push");
v6 = *(int *)(a1 + 28);
if ( (int)v6 + a3 >= *(_DWORD *)(a1 + 24) )
{
nmea_parser_buff_clear(a1);
v5 = *(_QWORD *)(a1 + 16);
v6 = *(int *)(a1 + 28);
}
v8 = 0;
memcpy((void *)(v6 + v5), a2, a3);
v9 = *(_DWORD *)(a1 + 28) + a3;
*(_DWORD *)(a1 + 28) = v9;
v10 = v9;
while ( 1 )
{
v11 = nmea_find_tail(v8 + *(_QWORD *)(a1 + 16), (unsigned int)(v10 - v8), v30);
if ( !v11 )
{
if ( v8 )
{
v28 = *(char **)(a1 + 16);
v29 = *(_DWORD *)(a1 + 28) - v8;
*(_DWORD *)(a1 + 28) = v29;
memcpy(v28, &v28[v8], v29);
}
return (unsigned int)v8;
}
if ( v30[0] >= 0 )
break;
LABEL_6:
v10 = *(_DWORD *)(a1 + 28);
v8 += v11;
}
v12 = nmea_pack_type(*(_QWORD *)(a1 + 16) + v8 + 1LL, (unsigned int)(*(_DWORD *)(a1 + 28) + ~v8));
v13 = malloc(0x18uLL);
v14 = v13;
if ( !v13 )
goto LABEL_34;
v13[1] = 0LL;
switch ( v12 )
{
case 1:
v15 = malloc(0x80uLL);
v14[1] = v15;
if ( !v15 )
goto LABEL_33;
v16 = *(_QWORD *)(a1 + 16);
*(_DWORD *)v14 = 1;
if ( (unsigned int)nmea_parse_GPGGA(v8 + v16, v11, v15) )
goto LABEL_16;
goto LABEL_29;
case 2:
v23 = malloc(0x50uLL);
v14[1] = v23;
if ( !v23 )
goto LABEL_33;
v24 = *(_QWORD *)(a1 + 16);
*(_DWORD *)v14 = 2;
if ( !(unsigned int)nmea_parse_GPGSA(v8 + v24, v11, v23) )
goto LABEL_29;
goto LABEL_16;
case 4:
v25 = malloc(0x5CuLL);
v14[1] = v25;
if ( !v25 )
goto LABEL_33;
v26 = *(_QWORD *)(a1 + 16);
*(_DWORD *)v14 = 4;
if ( !(unsigned int)nmea_parse_GPGSV(v8 + v26, v11, v25) )
goto LABEL_29;
goto LABEL_16;
case 8:
v21 = malloc(0x60uLL);
v14[1] = v21;
if ( !v21 )
goto LABEL_33;
v22 = *(_QWORD *)(a1 + 16);
*(_DWORD *)v14 = 8;
if ( !(unsigned int)nmea_parse_GPRMC(v8 + v22, v11, v21) )
goto LABEL_29;
goto LABEL_16;
case 16:
v17 = malloc(0x40uLL);
v14[1] = v17;
if ( v17 )
{
v18 = *(_QWORD *)(a1 + 16);
*(_DWORD *)v14 = 16;
if ( (unsigned int)nmea_parse_GPVTG(v8 + v18, v11, v17) )
{
LABEL_16:
v19 = *(_QWORD *)(a1 + 8);
if ( v19 )
*(_QWORD *)(v19 + 16) = v14;
v20 = *(_QWORD *)a1 == 0LL;
*(_QWORD *)(a1 + 8) = v14;
if ( v20 )
*(_QWORD *)a1 = v14;
v14[2] = 0LL;
}
else
{
LABEL_29:
free(v14);
}
goto LABEL_6;
}
LABEL_33:
free(v14);
LABEL_34:
v8 = -1;
nmea_error("Insufficient memory!", a4);
return (unsigned int)v8;
default:
goto LABEL_29;
}
}

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:
buff
char *

variable_types: nparsed int

variable_types: crc int

variable_types: ptype int

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

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 _nmeaGPGSV { int pack_count; int pack_index; int sat_count; struct _nmeaSATELLITE sat_data[-1]; }

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

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

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_parser_push(__int64 a1, const void *a2, int a3, double a4)
{
unsigned int v4; // er13
int v6; // ebp

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

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

v4 = 0;
do
{
v6 = a3;
if ( *(_DWORD *)(a1 + 24) <= a3 )
v6 = *(_DWORD *)(a1 + 24);
v4 += func6(a1, a2, v6, a4);
a3 -= v6;
}
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, double a5)
{
unsigned int v7; // er12
int v8; // eax
void *v9; // rdi
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");
v7 = 0;
nmea_parser_push(a1, a2, a3, a5);
while ( 1 )
{
v8 = nmea_parser_pop(a1, &ptr);
if ( !v8 )
return v7;
v9 = ptr;
++v7;
switch ( v8 )
{
case 1:
nmea_GPGGA2info(ptr, a4);
free(ptr);
break;
case 2:
nmea_GPGSA2info(ptr, a4);
free(ptr);
break;
case 4:
nmea_GPGSV2info(ptr, a4);
free(ptr);
break;
case 8:
nmea_GPRMC2info(ptr, a4);
free(ptr);
break;
case 16:
nmea_GPVTG2info(ptr, a4);
v9 = ptr;
goto LABEL_7;
default:
LABEL_7:
free(v9);
break;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const void *a2, int a3, __int64 a4, double a5)
{
unsigned int v7; // er12
int v8; // eax
void *v9; // rdi
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");
v7 = 0;
func7(a1, a2, a3, a5);
while ( 1 )
{
v8 = func2(a1, &ptr);
if ( !v8 )
return v7;
v9 = ptr;
++v7;
switch ( v8 )
{
case 1:
nmea_GPGGA2info(ptr, a4);
free(ptr);
break;
case 2:
nmea_GPGSA2info(ptr, a4);
free(ptr);
break;
case 4:
nmea_GPGSV2info(ptr, a4);
free(ptr);
break;
case 8:
nmea_GPRMC2info(ptr, a4);
free(ptr);
break;
case 16:
nmea_GPVTG2info(ptr, a4);
v9 = ptr;
goto LABEL_7;
default:
LABEL_7:
free(v9);
break;
}
}
}

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: 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: nread int

variable_types:
pack
void *

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

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


decompiled_code:
__int64 __fastcall nmea_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);
*(_OWORD *)a1 = 0LL;
*((_OWORD *)a1 + 1) = 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);
*(_OWORD *)a1 = 0LL;
*((_OWORD *)a1 + 1) = 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));
}

return_type: void


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

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

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

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

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

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

variable_types: chsum int

variable_types: it int


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

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

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

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

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

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

variable_types:
str
char *

variable_types: radix int

variable_types:
buff
char [-1]

variable_types: res int


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

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

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

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

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

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

variable_types: res double

return_type: double


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

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

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

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

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

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

variable_types:
format
char *

variable_types: add int


decompiled_code:
__int64 lsm303_init()
{
__int16 buf[5]; // [rsp+Eh] [rbp-Ah] BYREF

if ( useAcc )
{
facc = open("/dev/i2c-0", 2306);
if ( facc == -1 )
{
LABEL_14:
printf("open_port: Unable to open i2c-bus");
return 0LL;
}
if ( ioctl(facc, 0x703uLL, 24LL) < 0 )
goto LABEL_13;
buf[0] = 10016;
if ( write(facc, buf, 2uLL) != 2 )
{
puts("Failed to set REG1");
return 0LL;
}
buf[0] = 16419;
if ( write(facc, buf, 2uLL) != 2 )
{
puts("Failed to set REG4");
return 0LL;
}
}
if ( !useMag )
return 1LL;
fmag = open("/dev/i2c-0", 2306);
if ( fmag == -1 )
goto LABEL_14;
if ( ioctl(fmag, 0x703uLL, 30LL) < 0 )
{
LABEL_13:
puts("Failed to acquire bus access and/or talk to slave.");
return 0LL;
}
buf[0] = 5120;
if ( write(fmag, buf, 2uLL) == 2 )
{
buf[0] = 8193;
if ( write(fmag, buf, 2uLL) == 2 )
{
buf[0] = 2;
if ( write(fmag, buf, 2uLL) == 2 )
return 1LL;
puts("Failed to set MR REG");
}
else
{
puts("Failed to set CRB REG");
}
}
else
{
puts("Failed to set CRA REG");
}
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
__int16 buf[5]; // [rsp+Eh] [rbp-Ah] BYREF

if ( useAcc )
{
facc = open("/dev/i2c-0", 2306);
if ( facc == -1 )
{
LABEL_14:
printf("open_port: Unable to open i2c-bus");
return 0LL;
}
if ( ioctl(facc, 0x703uLL, 24LL) < 0 )
goto LABEL_13;
buf[0] = 10016;
if ( write(facc, buf, 2uLL) != 2 )
{
puts("Failed to set REG1");
return 0LL;
}
buf[0] = 16419;
if ( write(facc, buf, 2uLL) != 2 )
{
puts("Failed to set REG4");
return 0LL;
}
}
if ( !useMag )
return 1LL;
fmag = open("/dev/i2c-0", 2306);
if ( fmag == -1 )
goto LABEL_14;
if ( ioctl(fmag, 0x703uLL, 30LL) < 0 )
{
LABEL_13:
puts("Failed to acquire bus access and/or talk to slave.");
return 0LL;
}
buf[0] = 5120;
if ( write(fmag, buf, 2uLL) == 2 )
{
buf[0] = 8193;
if ( write(fmag, buf, 2uLL) == 2 )
{
buf[0] = 2;
if ( write(fmag, buf, 2uLL) == 2 )
return 1LL;
puts("Failed to set MR REG");
}
else
{
puts("Failed to set CRB REG");
}
}
else
{
puts("Failed to set CRA REG");
}
return 0LL;
}

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
int v2; // edx
int v3; // eax
int v4; // eax
int v5; // edx
float v6; // xmm0_4
int v7; // eax
float v8; // xmm0_4
char buf; // [rsp+9h] [rbp-Fh] BYREF
char v10[14]; // [rsp+Ah] [rbp-Eh] BYREF

buf = 3;
if ( write(fmag, &buf, 1uLL) == 1 )
{
if ( read(fmag, v10, 6uLL) == 6 )
{
v2 = v10[3];
v3 = v10[2] << 8;
*a1 = (float)(v10[1] | (v10[0] << 8)) - xyz_mag_offset[0];
v4 = v2 | v3;
v5 = v10[5];
v6 = (float)v4;
v7 = v10[4] << 8;
a1[1] = v6 - xyz_mag_offset[1];
v8 = (float)(v5 | v7) - xyz_mag_offset[2];
result = 1LL;
a1[2] = v8;
}
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
int v2; // edx
int v3; // eax
int v4; // eax
int v5; // edx
float v6; // xmm0_4
int v7; // eax
float v8; // xmm0_4
char buf; // [rsp+9h] [rbp-Fh] BYREF
char v10[14]; // [rsp+Ah] [rbp-Eh] BYREF

buf = 3;
if ( write(fmag, &buf, 1uLL) == 1 )
{
if ( read(fmag, v10, 6uLL) == 6 )
{
v2 = v10[3];
v3 = v10[2] << 8;
*a1 = (float)(v10[1] | (v10[0] << 8)) - xyz_mag_offset[0];
v4 = v2 | v3;
v5 = v10[5];
v6 = (float)v4;
v7 = v10[4] << 8;
a1[1] = v6 - xyz_mag_offset[1];
v8 = (float)(v5 | v7) - xyz_mag_offset[2];
result = 1LL;
a1[2] = v8;
}
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
char buf; // [rsp+3h] [rbp-15h] BYREF
__int16 v3[10]; // [rsp+4h] [rbp-14h] BYREF

buf = 3;
if ( write(fmag, &buf, 1uLL) == 1 )
{
if ( read(fmag, v3, 6uLL) == 6 )
{
*a1 = v3[1] | (v3[0] << 8);
a1[1] = v3[3] | (v3[2] << 8);
a1[2] = v3[5] | (v3[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
char buf; // [rsp+3h] [rbp-15h] BYREF
__int16 v3[10]; // [rsp+4h] [rbp-14h] BYREF

buf = 3;
if ( write(fmag, &buf, 1uLL) == 1 )
{
if ( read(fmag, v3, 6uLL) == 6 )
{
*a1 = v3[1] | (v3[0] << 8);
a1[1] = v3[3] | (v3[2] << 8);
a1[2] = v3[5] | (v3[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
int v2; // edx
float v3; // xmm0_4
int v4; // edx
__int16 v5[7]; // [rsp+Ah] [rbp-Eh] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func3(float *a1)
{
__int64 result; // rax
int v2; // edx
float v3; // xmm0_4
int v4; // edx
__int16 v5[7]; // [rsp+Ah] [rbp-Eh] BYREF

result = func2(v5);
v2 = v5[1];
*a1 = (float)v5[0] / 1050.0;
v3 = (float)v2;
v4 = v5[2];
a1[1] = v3 / 1050.0;
a1[2] = (float)v4 / 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
int v2; // edx
float v3; // xmm0_4
int v4; // edx
__int16 v5[7]; // [rsp+Ah] [rbp-Eh] BYREF

result = lsm303_read_magnet_raw(v5);
v2 = v5[1];
*a1 = (float)v5[0] / 10500000.0;
v3 = (float)v2;
v4 = v5[2];
a1[1] = v3 / 10500000.0;
a1[2] = (float)v4 / 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;
}


decompiled_code:
float lsm303_magnet_angle_rad()
{
int v1[5]; // [rsp+4h] [rbp-14h] BYREF

lsm303_read_magnet_gauss_cal((float *)v1);
return atan2(COERCE_FLOAT(v1[1] ^ LC14), *(float *)v1);
}

canonical_decompiled_code:
float func6()
{
int v1[5]; // [rsp+4h] [rbp-14h] BYREF

func4((float *)v1);
return atan2(COERCE_FLOAT(v1[1] ^ LC14), *(float *)v1);
}

original_code:
float lsm303_magnet_angle_rad()
{
    float xyz[3];
    lsm303_read_magnet_gauss_cal(xyz);
    return atan2(-xyz[1], xyz[0]);
}

return_type: float


decompiled_code:
__int64 __fastcall lsm303_read_acc_measurements(float *a1)
{
__int64 result; // rax
int v2; // edx
int v3; // eax
int v4; // eax
int v5; // edx
float v6; // xmm0_4
int v7; // eax
float v8; // xmm0_4
char buf; // [rsp+9h] [rbp-Fh] BYREF
char v10[14]; // [rsp+Ah] [rbp-Eh] BYREF

buf = -88;
if ( write(facc, &buf, 1uLL) == 1 )
{
if ( read(facc, v10, 6uLL) == 6 )
{
v2 = v10[3];
v3 = v10[2] << 8;
*a1 = (float)(v10[1] | (v10[0] << 8)) - xyz_acc_offset[0];
v4 = v2 | v3;
v5 = v10[5];
v6 = (float)v4;
v7 = v10[4] << 8;
a1[1] = v6 - xyz_acc_offset[1];
v8 = (float)(v5 | v7) - xyz_acc_offset[2];
result = 1LL;
a1[2] = v8;
}
else
{
puts("Read accelerometer xyz failed");
result = 0LL;
}
}
else
{
puts("Failed set read register");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(float *a1)
{
__int64 result; // rax
int v2; // edx
int v3; // eax
int v4; // eax
int v5; // edx
float v6; // xmm0_4
int v7; // eax
float v8; // xmm0_4
char buf; // [rsp+9h] [rbp-Fh] BYREF
char v10[14]; // [rsp+Ah] [rbp-Eh] BYREF

buf = -88;
if ( write(facc, &buf, 1uLL) == 1 )
{
if ( read(facc, v10, 6uLL) == 6 )
{
v2 = v10[3];
v3 = v10[2] << 8;
*a1 = (float)(v10[1] | (v10[0] << 8)) - xyz_acc_offset[0];
v4 = v2 | v3;
v5 = v10[5];
v6 = (float)v4;
v7 = v10[4] << 8;
a1[1] = v6 - xyz_acc_offset[1];
v8 = (float)(v5 | v7) - xyz_acc_offset[2];
result = 1LL;
a1[2] = v8;
}
else
{
puts("Read accelerometer xyz failed");
result = 0LL;
}
}
else
{
puts("Failed set read register");
result = 0LL;
}
return result;
}

original_code:
int lsm303_read_acc_measurements(float xyz[3])
{
    int8_t readReg = 0x28 | 0b10000000;
    if (write(facc, &readReg, 1) != 1)
    {
        printf("Failed set read register\n");
        return 0;
    }
    int8_t buffer[6];
    if(read(facc, buffer, 6) != 6)
    {
        printf("Read accelerometer xyz failed\n");
        return 0;
    }
    xyz[0] = (float) ((buffer[0]<<8 | buffer[1])-xyz_acc_offset[0]);
    xyz[1] = (float) ((buffer[2]<<8 | buffer[3])-xyz_acc_offset[1]);
    xyz[2] = (float) ((buffer[4]<<8 | buffer[5])-xyz_acc_offset[2]);
    return 1;
}

canonical_original_code:
int lsm303_read_acc_measurements(float xyz[3])
{
    char readReg = 0x28 | 0b10000000;
    if (write(facc, &readReg, 1) != 1)
    {
        printf("Failed set read register\n");
        return 0;
    }
    char buffer[6];
    if(read(facc, buffer, 6) != 6)
    {
        printf("Read accelerometer xyz failed\n");
        return 0;
    }
    xyz[0] = (float) ((buffer[0]<<8 | buffer[1])-xyz_acc_offset[0]);
    xyz[1] = (float) ((buffer[2]<<8 | buffer[3])-xyz_acc_offset[1]);
    xyz[2] = (float) ((buffer[4]<<8 | buffer[5])-xyz_acc_offset[2]);
    return 1;
}


decompiled_code:
__int64 __fastcall lsm303_read_acc_raw(_WORD *a1)
{
__int64 result; // rax
char buf; // [rsp+9h] [rbp-Fh] BYREF
char v3[14]; // [rsp+Ah] [rbp-Eh] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func8(_WORD *a1)
{
__int64 result; // rax
char buf; // [rsp+9h] [rbp-Fh] BYREF
char v3[14]; // [rsp+Ah] [rbp-Eh] BYREF

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

original_code:
int lsm303_read_acc_raw(int16_t xyz[3])
{
    int8_t readReg = 0x28 | 0b10000000;
    if (write(facc, &readReg, 1) != 1)
    {
        printf("Failed set read register\n");
        return 0;
    }
    int8_t buffer[6];
    if(read(facc, buffer, 6) != 6)
    {
        printf("Read accelerometer 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_acc_raw(short xyz[3])
{
    char readReg = 0x28 | 0b10000000;
    if (write(facc, &readReg, 1) != 1)
    {
        printf("Failed set read register\n");
        return 0;
    }
    char buffer[6];
    if(read(facc, buffer, 6) != 6)
    {
        printf("Read accelerometer 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;
}


decompiled_code:
__int64 __fastcall lsm303_read_acc_SI(float *a1)
{
__int64 result; // rax
int v2; // edx
float v3; // xmm0_4
int v4; // edx
__int16 v5[7]; // [rsp+Ah] [rbp-Eh] BYREF

result = lsm303_read_acc_raw(v5);
v2 = v5[1];
*a1 = (float)v5[0] / 1000.0;
v3 = (float)v2;
v4 = v5[2];
a1[1] = v3 / 1000.0;
a1[2] = (float)v4 / 1000.0;
return result;
}

original_code:
int lsm303_read_acc_SI(float xyz[3])
{
    int status;
    int16_t xyz_raw[3];
    status = lsm303_read_acc_raw(xyz_raw);
    xyz[0] = (float)xyz_raw[0] / accelerometer_gain_SI;
    xyz[1] = (float)xyz_raw[1] / accelerometer_gain_SI;
    xyz[2] = (float)xyz_raw[2] / accelerometer_gain_SI;
    return status;
}

canonical_original_code:
int lsm303_read_acc_SI(float xyz[3])
{
    int status;
    short xyz_raw[3];
    status = lsm303_read_acc_raw(xyz_raw);
    xyz[0] = (float)xyz_raw[0] / accelerometer_gain_SI;
    xyz[1] = (float)xyz_raw[1] / accelerometer_gain_SI;
    xyz[2] = (float)xyz_raw[2] / accelerometer_gain_SI;
    return status;
}


original_code:
float lsm303_mag_convert_to_deg_2D(int16_t xy[])
{
    float angle_rad, angle_deg;
    angle_rad = atan2(xy[1], xy[0]);
    angle_deg = angle_rad*360/(2*3.14159265358979323846);
    angle_deg = fmod(angle_deg + 180.0, 360.0) - 180.0;
    return(angle_deg);
}

canonical_original_code:
float lsm303_mag_convert_to_deg_2D(short xy[])
{
    float angle_rad; float angle_deg;
    angle_rad = atan2(xy[1], xy[0]);
    angle_deg = angle_rad*360/(2*3.14159265358979323846);
    angle_deg = fmod(angle_deg + 180.0, 360.0) - 180.0;
    return(angle_deg);
}

variable_types:
xy
short []


decompiled_code:
__int64 __fastcall lsm303_calibrate_acc(float a1, float a2, float a3)
{
unsigned int v3; // er12
int v4; // ebx
int v5; // eax
__int64 result; // rax
int v7[9]; // [rsp+14h] [rbp-24h] BYREF

v3 = 0;
v4 = 100;
do
{
v5 = lsm303_read_acc_measurements((float *)v7);
a3 = a3 + *(float *)v7;
v3 += v5;
a2 = a2 + *(float *)&v7[1];
a1 = a1 + *(float *)&v7[2];
--v4;
}
while ( v4 );
result = v3;
xyz_acc_offset[0] = a3 / 100.0;
xyz_acc_offset[1] = a2 / 100.0;
xyz_acc_offset[2] = (float)(a1 / 100.0) - 16384.0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(float a1, float a2, float a3)
{
unsigned int v3; // er12
int v4; // ebx
int v5; // eax
__int64 result; // rax
int v7[9]; // [rsp+14h] [rbp-24h] BYREF

v3 = 0;
v4 = 100;
do
{
v5 = func7((float *)v7);
a3 = a3 + *(float *)v7;
v3 += v5;
a2 = a2 + *(float *)&v7[1];
a1 = a1 + *(float *)&v7[2];
--v4;
}
while ( v4 );
result = v3;
xyz_acc_offset[0] = a3 / 100.0;
xyz_acc_offset[1] = a2 / 100.0;
xyz_acc_offset[2] = (float)(a1 / 100.0) - 16384.0;
return result;
}

original_code:
int lsm303_calibrate_acc()
{
    int status = 0;
    float xyz[3];
    float x_avg, y_avg, z_avg;
    int i,n;
    n = 100;
    int16_t x_pre_def = 0;
    int16_t y_pre_def = 0;
    int16_t z_pre_def = 16384;
    for(i=0; i<n; i++)
    {
        status += lsm303_read_acc_measurements(xyz);
        x_avg += xyz[0];
        y_avg += xyz[1];
        z_avg += xyz[2];
    }
    x_avg /= n;
    y_avg /= n;
    z_avg /= n;
    xyz_acc_offset[0] = x_avg-x_pre_def;
    xyz_acc_offset[1] = y_avg-y_pre_def;
    xyz_acc_offset[2] = z_avg-z_pre_def;
    return status;
}

canonical_original_code:
int lsm303_calibrate_acc()
{
    int status = 0;
    float xyz[3];
    float x_avg; float y_avg; float z_avg;
    int i; int n;
    n = 100;
    short x_pre_def = 0;
    short y_pre_def = 0;
    short z_pre_def = 16384;
    for(i=0; i<n; i++)
    {
        status += lsm303_read_acc_measurements(xyz);
        x_avg += xyz[0];
        y_avg += xyz[1];
        z_avg += xyz[2];
    }
    x_avg /= n;
    y_avg /= n;
    z_avg /= n;
    xyz_acc_offset[0] = x_avg-x_pre_def;
    xyz_acc_offset[1] = y_avg-y_pre_def;
    xyz_acc_offset[2] = z_avg-z_pre_def;
    return status;
}

variable_types: i int

variable_types: n int


decompiled_code:
__int64 __fastcall lsm303_calibrate_mag(float a1, float a2, float a3)
{
unsigned int v3; // er12
int v4; // ebx
int v5; // eax
__int64 result; // rax
int v7[9]; // [rsp+14h] [rbp-24h] BYREF

v3 = 0;
v4 = 100;
do
{
v5 = lsm303_read_mag_measurements((float *)v7);
a3 = a3 + *(float *)v7;
v3 += v5;
a2 = a2 + *(float *)&v7[1];
a1 = a1 + *(float *)&v7[2];
--v4;
}
while ( v4 );
result = v3;
xyz_mag_offset[0] = -190.0 - (float)(a3 / 100.0);
xyz_mag_offset[1] = -5.0 - (float)(a2 / 100.0);
xyz_mag_offset[2] = -420.0 - (float)(a1 / 100.0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(float a1, float a2, float a3)
{
unsigned int v3; // er12
int v4; // ebx
int v5; // eax
__int64 result; // rax
int v7[9]; // [rsp+14h] [rbp-24h] BYREF

v3 = 0;
v4 = 100;
do
{
v5 = func1((float *)v7);
a3 = a3 + *(float *)v7;
v3 += v5;
a2 = a2 + *(float *)&v7[1];
a1 = a1 + *(float *)&v7[2];
--v4;
}
while ( v4 );
result = v3;
xyz_mag_offset[0] = -190.0 - (float)(a3 / 100.0);
xyz_mag_offset[1] = -5.0 - (float)(a2 / 100.0);
xyz_mag_offset[2] = -420.0 - (float)(a1 / 100.0);
return result;
}

original_code:
int lsm303_calibrate_mag()
{
    int status = 0;
    float xyz[3];
    float x_avg, y_avg, z_avg;
    int i, n;
    n = 100;
    int16_t x_pre_def = -190;
    int16_t y_pre_def = -5;
    int16_t z_pre_def = -420;
    for (i = 0; i < n; i++)
    {
        status += lsm303_read_mag_measurements(xyz);
        x_avg += xyz[0];
        y_avg += xyz[1];
        z_avg += xyz[2];
    }
    x_avg /= n;
    y_avg /= n;
    z_avg /= n;
    xyz_mag_offset[0] = x_pre_def-x_avg;
    xyz_mag_offset[1] = y_pre_def-y_avg;
    xyz_mag_offset[2] = z_pre_def-z_avg;
    return status;
}

canonical_original_code:
int lsm303_calibrate_mag()
{
    int status = 0;
    float xyz[3];
    float x_avg; float y_avg; float z_avg;
    int i; int n;
    n = 100;
    short x_pre_def = -190;
    short y_pre_def = -5;
    short z_pre_def = -420;
    for (i = 0; i < n; i++)
    {
        status += lsm303_read_mag_measurements(xyz);
        x_avg += xyz[0];
        y_avg += xyz[1];
        z_avg += xyz[2];
    }
    x_avg /= n;
    y_avg /= n;
    z_avg /= n;
    xyz_mag_offset[0] = x_pre_def-x_avg;
    xyz_mag_offset[1] = y_pre_def-y_avg;
    xyz_mag_offset[2] = z_pre_def-z_avg;
    return status;
}


decompiled_code:
__int64 itg3200_init()
{
int v0; // eax
__int64 result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = open("/dev/i2c-0", 2306);
fgyro = v0;
if ( v0 == -1 )
{
printf("open_port: Unable to open i2c-bus");
result = 0LL;
}
else if ( ioctl(v0, 0x703uLL, 105LL) < 0 )
{
puts("Failed to acquire bus access and/or talk to slave.");
result = 0LL;
}
else
{
buf[0] = 0;
if ( write(fgyro, buf, 1uLL) == 1 )
{
if ( read(fgyro, buf, 1uLL) == 1 )
{
printf("Got whoami register: %x\n", (unsigned int)buf[0]);
result = 1LL;
}
else
{
puts("Failed to write to gyro");
result = 0LL;
}
}
else
{
puts("Failed to write to gyro (whoami-reg)");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
__int64 result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = open("/dev/i2c-0", 2306);
fgyro = v0;
if ( v0 == -1 )
{
printf("open_port: Unable to open i2c-bus");
result = 0LL;
}
else if ( ioctl(v0, 0x703uLL, 105LL) < 0 )
{
puts("Failed to acquire bus access and/or talk to slave.");
result = 0LL;
}
else
{
buf[0] = 0;
if ( write(fgyro, buf, 1uLL) == 1 )
{
if ( read(fgyro, buf, 1uLL) == 1 )
{
printf("Got whoami register: %x\n", (unsigned int)buf[0]);
result = 1LL;
}
else
{
puts("Failed to write to gyro");
result = 0LL;
}
}
else
{
puts("Failed to write to gyro (whoami-reg)");
result = 0LL;
}
}
return result;
}

original_code:
int itg3200_init()
{
    fgyro = open("/dev/i2c-0", 02 | 0400 | 04000);
    if (fgyro == -1)
    {
        printf("open_port: Unable to open i2c-bus");
        return 0;
    }
    else
    {
        if (ioctl(fgyro, 0x0703, 0x69) < 0)
        {
            printf("Failed to acquire bus access and/or talk to slave.\n");
            return 0;
        }
        int8_t whoami = 0x00;
        if (write(fgyro, &whoami, 1) != 1)
        {
            printf("Failed to write to gyro (whoami-reg)\n");
            return 0;
        }
        if (read(fgyro, &whoami, 1) != 1)
        {
            printf("Failed to write to gyro\n");
            return 0;
        }
        printf("Got whoami register: %x\n", whoami);
        return 1;
    }
}

canonical_original_code:
int itg3200_init()
{
    fgyro = open("/dev/i2c-0", 02 | 0400 | 04000);
    if (fgyro == -1)
    {
        printf("open_port: Unable to open i2c-bus");
        return 0;
    }
    else
    {
        if (ioctl(fgyro, 0x0703, 0x69) < 0)
        {
            printf("Failed to acquire bus access and/or talk to slave.\n");
            return 0;
        }
        char whoami = 0x00;
        if (write(fgyro, &whoami, 1) != 1)
        {
            printf("Failed to write to gyro (whoami-reg)\n");
            return 0;
        }
        if (read(fgyro, &whoami, 1) != 1)
        {
            printf("Failed to write to gyro\n");
            return 0;
        }
        printf("Got whoami register: %x\n", whoami);
        return 1;
    }
}

variable_types: whoami char


decompiled_code:
__int64 __fastcall itg3200_read_raw(int *a1)
{
__int64 result; // rax
int v2; // edx
int v3; // eax
int v4; // edx
char buf; // [rsp+9h] [rbp-Fh] BYREF
char v6[14]; // [rsp+Ah] [rbp-Eh] BYREF

buf = 29;
if ( write(fgyro, &buf, 1uLL) == 1 )
{
if ( read(fgyro, v6, 6uLL) == 6 )
{
v2 = v6[3];
*a1 = v6[1] | (v6[0] << 8);
v3 = v2 | (v6[2] << 8);
v4 = v6[5];
a1[1] = v3;
a1[2] = v4 | (v6[4] << 8);
result = 1LL;
}
else
{
puts("Read gyro xyz failed");
result = 0LL;
}
}
else
{
puts("Failed toaa write read Register to gyro");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1)
{
__int64 result; // rax
int v2; // edx
int v3; // eax
int v4; // edx
char buf; // [rsp+9h] [rbp-Fh] BYREF
char v6[14]; // [rsp+Ah] [rbp-Eh] BYREF

buf = 29;
if ( write(fgyro, &buf, 1uLL) == 1 )
{
if ( read(fgyro, v6, 6uLL) == 6 )
{
v2 = v6[3];
*a1 = v6[1] | (v6[0] << 8);
v3 = v2 | (v6[2] << 8);
v4 = v6[5];
a1[1] = v3;
a1[2] = v4 | (v6[4] << 8);
result = 1LL;
}
else
{
puts("Read gyro xyz failed");
result = 0LL;
}
}
else
{
puts("Failed toaa write read Register to gyro");
result = 0LL;
}
return result;
}

original_code:
int itg3200_read_raw(int xyz_raw[3])
{
    int8_t readRegister = 0x1D;
    if (write(fgyro, &readRegister, 1) != 1)
    {
        printf("Failed toaa write read Register to gyro\n");
        return 0;
    }
    int8_t buffer[6];
    if(read(fgyro, buffer, 6) != 6)
    {
        printf("Read gyro xyz failed\n");
        return 0;
    }
    xyz_raw[0] = buffer[0]<<8 | buffer[1];
    xyz_raw[1] = buffer[2]<<8 | buffer[3];
    xyz_raw[2] = buffer[4]<<8 | buffer[5];
    return 1;
}

canonical_original_code:
int itg3200_read_raw(int xyz_raw[3])
{
    char readRegister = 0x1D;
    if (write(fgyro, &readRegister, 1) != 1)
    {
        printf("Failed toaa write read Register to gyro\n");
        return 0;
    }
    char buffer[6];
    if(read(fgyro, buffer, 6) != 6)
    {
        printf("Read gyro xyz failed\n");
        return 0;
    }
    xyz_raw[0] = buffer[0]<<8 | buffer[1];
    xyz_raw[1] = buffer[2]<<8 | buffer[3];
    xyz_raw[2] = buffer[4]<<8 | buffer[5];
    return 1;
}

variable_types: readRegister char


original_code:
int itg3200_read_rad(float xyz_rad[3])
{
        int status = 0;
        static float factor = 1.0 / (8.0 * 14.375) * 0.017453293;
        int xyz_raw[3];
        status = itg3200_read_raw(xyz_raw);
        xyz_rad[0] = xyz_raw[0] * factor;
        xyz_rad[1] = xyz_raw[1] * factor;
        xyz_rad[2] = xyz_raw[2] * factor;
        return status;
}

variable_types: factor float


original_code:
int itg3200_read_deg(float xyz_deg[3])
{
        int status = 0;
        static float factor = 0.125 / 14.375;
        int xyz_raw[3];
        status = itg3200_read_raw(xyz_raw);
        xyz_deg[0] = xyz_raw[0] * factor;
        xyz_deg[1] = xyz_raw[1] * factor;
        xyz_deg[2] = xyz_raw[2] * factor;
        return status;
}


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

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

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

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

original_code:
int itg3200_read_rad_calibrated(float xyz_rad_cal[3])
{
        int status;
        float xyz_rad[3];
        status = itg3200_read_rad(xyz_rad);
        xyz_rad_cal[0] = xyz_rad[0] - xyz_gyro_offset[0];
        xyz_rad_cal[1] = xyz_rad[1] - xyz_gyro_offset[1];
        xyz_rad_cal[2] = xyz_rad[2] - xyz_gyro_offset[2];
        return status;
}


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

result = itg3200_read_deg((float *)v5);
v2 = *(float *)v5 - xyz_gyro_offset[0] * 57.29578;
*a1 = v2;
v3 = *(float *)&v5[1] - xyz_gyro_offset[1] * 57.29578;
a1[1] = v3;
v4 = *(float *)&v5[2] - xyz_gyro_offset[2] * 57.29578;
a1[2] = v4;
return result;
}

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

result = func3((float *)v5);
v2 = *(float *)v5 - xyz_gyro_offset[0] * 57.29578;
*a1 = v2;
v3 = *(float *)&v5[1] - xyz_gyro_offset[1] * 57.29578;
a1[1] = v3;
v4 = *(float *)&v5[2] - xyz_gyro_offset[2] * 57.29578;
a1[2] = v4;
return result;
}

original_code:
int itg3200_read_deg_calibrated(float xyz_deg_cal[3])
{
        int status;
        float xyz_deg[3];
        status = itg3200_read_deg(xyz_deg);
        xyz_deg_cal[0] = xyz_deg[0] - xyz_gyro_offset[0] * 57.29578;
        xyz_deg_cal[1] = xyz_deg[1] - xyz_gyro_offset[1] * 57.29578;
        xyz_deg_cal[2] = xyz_deg[2] - xyz_gyro_offset[2] * 57.29578;
        return status;
}


decompiled_code:
__int64 itg3200_calibrate_gyro()
{
float v0; // xmm0_4
unsigned int v1; // er12
float v2; // xmm1_4
int v3; // ebx
float v4; // xmm2_4
int v5; // eax
__int64 result; // rax
int v7[9]; // [rsp+10h] [rbp-24h] BYREF

v0 = 0.0;
v1 = 0;
v2 = 0.0;
v3 = 100;
v4 = 0.0;
do
{
v5 = itg3200_read_rad((float *)v7);
v4 = v4 + *(float *)v7;
v1 += v5;
v2 = v2 + *(float *)&v7[1];
v0 = v0 + *(float *)&v7[2];
--v3;
}
while ( v3 );
result = v1;
xyz_gyro_offset[0] = v4 / 100.0;
xyz_gyro_offset[1] = v2 / 100.0;
xyz_gyro_offset[2] = v0 / 100.0;
return result;
}

original_code:
int itg3200_calibrate_gyro()
{
        int status = 0;
        int n = 100;
        int i;
        float xyz[3];
        float x_sum, y_sum, z_sum;
        x_sum = 0.0;
        y_sum = 0.0;
        z_sum = 0.0;
        for (i = 0; i < n; i++)
        {
                status += itg3200_read_rad(xyz);
                x_sum += xyz[0];
                y_sum += xyz[1];
                z_sum += xyz[2];
        }
        xyz_gyro_offset[0] = x_sum / n;
        xyz_gyro_offset[1] = y_sum / n;
        xyz_gyro_offset[2] = z_sum / n;
        return status;
}

canonical_original_code:
int itg3200_calibrate_gyro()
{
        int status = 0;
        int n = 100;
        int i;
        float xyz[3];
        float x_sum; float y_sum; float z_sum;
        x_sum = 0.0;
        y_sum = 0.0;
        z_sum = 0.0;
        for (i = 0; i < n; i++)
        {
                status += itg3200_read_rad(xyz);
                x_sum += xyz[0];
                y_sum += xyz[1];
                z_sum += xyz[2];
        }
        xyz_gyro_offset[0] = x_sum / n;
        xyz_gyro_offset[1] = y_sum / n;
        xyz_gyro_offset[2] = z_sum / n;
        return status;
}


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

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

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

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

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


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

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

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

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

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

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

variable_types:
str
char *

variable_types: size int

variable_types:
buff
char [-1]

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


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

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

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

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

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

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


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

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

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

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

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

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

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

variable_types: lt long

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


decompiled_code:
void __fastcall wait_period(__int64 a1)
{
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned int)read(*(_DWORD *)a1, &buf, 8uLL) == -1 )
perror("read timer");
else
*(_QWORD *)(a1 + 8) += buf;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned int)read(*(_DWORD *)a1, &buf, 8uLL) == -1 )
perror("read timer");
else
*(_QWORD *)(a1 + 8) += buf;
}

original_code:
static void wait_period (struct periodic_info *info)
{
        unsigned long long missed;
        int ret;
        ret = read (info->timer_fd, &missed, sizeof (missed));
        if (ret == -1)
        {
                perror ("read timer");
                return;
        }
        info->wakeups_missed += missed;
}

canonical_original_code:
static void wait_period(struct periodic_info *info)
{
        unsigned long long missed;
        int ret;
        ret = read (info->timer_fd, &missed, sizeof (missed));
        if (ret == -1)
        {
                perror ("read timer");
                return;
        }
        info->wakeups_missed += missed;
}

variable_types: struct periodic_info { int timer_fd; unsigned long long wakeups_missed; } *

variable_types:
missed
unsigned long long

variable_types: ret int


decompiled_code:
void __noreturn thread_DisplayValues()
{
unsigned int v0; // eax
time_t v1; // [rsp+0h] [rbp-38h] BYREF
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char v3[16]; // [rsp+10h] [rbp-28h] BYREF
__int64 v4[3]; // [rsp+20h] [rbp-18h] BYREF

make_periodic_isra_0(100000, (__int64)v3);
v0 = time(0LL);
srand(v0);
time(&v1);
while ( 1 )
{
time(&timer);
timer -= v1;
printw("Current Sensor output:\n");
printw("%ld s\n\n", timer);
if ( useMag )
{
printw("Magnetometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", mag_xyz[0], mag_xyz[1], mag_xyz[2]);
if ( useAcc )
{
LABEL_9:
printw("Accelerometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", acc_xyz[0], acc_xyz[1], acc_xyz[2]);
if ( !useGyro )
goto LABEL_4;
goto LABEL_10;
}
}
else if ( useAcc )
{
goto LABEL_9;
}
if ( !useGyro )
goto LABEL_4;
LABEL_10:
printw("Gyroscope:\t X:\t%f\tY:\t%f\tZ:\t%f\n", gyro_xyz[0], gyro_xyz[1], gyro_xyz[2]);
LABEL_4:
if ( useGPS )
{
nmea_info2pos(gpsInfo, v4);
printw(
"GPS:\t\t Long.:\t%f\tLat.:\t%f\tAlt.:\t%f\n",
180.0 * *(double *)v4 / 3.141592653589793,
180.0 * *(double *)&v4[1] / 3.141592653589793,
gpsInfo[10]);
}
wrefresh(stdscr);
werase(stdscr);
wait_period((__int64)v3);
}
}

canonical_decompiled_code:
void __noreturn func2()
{
unsigned int v0; // eax
time_t v1; // [rsp+0h] [rbp-38h] BYREF
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char v3[16]; // [rsp+10h] [rbp-28h] BYREF
__int64 v4[3]; // [rsp+20h] [rbp-18h] BYREF

func1(100000, (__int64)v3);
v0 = time(0LL);
srand(v0);
time(&v1);
while ( 1 )
{
time(&timer);
timer -= v1;
printw("Current Sensor output:\n");
printw("%ld s\n\n", timer);
if ( useMag )
{
printw("Magnetometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", mag_xyz[0], mag_xyz[1], mag_xyz[2]);
if ( useAcc )
{
LABEL_9:
printw("Accelerometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", acc_xyz[0], acc_xyz[1], acc_xyz[2]);
if ( !useGyro )
goto LABEL_4;
goto LABEL_10;
}
}
else if ( useAcc )
{
goto LABEL_9;
}
if ( !useGyro )
goto LABEL_4;
LABEL_10:
printw("Gyroscope:\t X:\t%f\tY:\t%f\tZ:\t%f\n", gyro_xyz[0], gyro_xyz[1], gyro_xyz[2]);
LABEL_4:
if ( useGPS )
{
nmea_info2pos(gpsInfo, v4);
printw(
"GPS:\t\t Long.:\t%f\tLat.:\t%f\tAlt.:\t%f\n",
180.0 * *(double *)v4 / 3.141592653589793,
180.0 * *(double *)&v4[1] / 3.141592653589793,
gpsInfo[10]);
}
wrefresh(stdscr);
werase(stdscr);
func0((__int64)v3);
}
}

original_code:
void * thread_DisplayValues()
{
    struct periodic_info info;
    make_periodic (100000, &info);
    nmeaPOS dpos;
    srand ( time(((void *)0)) );
    time_t startTime;
    time(&startTime);
    while(1)
    {
        time_t currentTime;
        time ( &currentTime );
        currentTime -= startTime;
        printw("Current Sensor output:\n");
        printw("%ld s\n\n", currentTime );
        if(useMag) printw("Magnetometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", mag_xyz[0], mag_xyz[1], mag_xyz[2]);
        if(useAcc) printw("Accelerometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", acc_xyz[0], acc_xyz[1], acc_xyz[2]);
        if(useGyro) printw("Gyroscope:\t X:\t%f\tY:\t%f\tZ:\t%f\n", gyro_xyz[0], gyro_xyz[1], gyro_xyz[2]);
        if(useGPS)
        {
            nmea_info2pos(&gpsInfo, &dpos);
            printw("GPS:\t\t Long.:\t%f\tLat.:\t%f\tAlt.:\t%f\n", 180*dpos.lat/3.14159265358979323846, 180*dpos.lon/3.14159265358979323846, gpsInfo.elv);
        }
        wrefresh(stdscr);
        werase(stdscr);
        wait_period(&info);
    }
}

canonical_original_code:
void *thread_DisplayValues()
{
    struct periodic_info info;
    make_periodic (100000, &info);
    struct _nmeaPOS dpos;
    srand ( time(((void *)0)) );
    long startTime;
    time(&startTime);
    while(1)
    {
        long currentTime;
        time ( &currentTime );
        currentTime -= startTime;
        printw("Current Sensor output:\n");
        printw("%ld s\n\n", currentTime );
        if(useMag) printw("Magnetometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", mag_xyz[0], mag_xyz[1], mag_xyz[2]);
        if(useAcc) printw("Accelerometer:\t X:\t%f\tY:\t%f\tZ:\t%f\n", acc_xyz[0], acc_xyz[1], acc_xyz[2]);
        if(useGyro) printw("Gyroscope:\t X:\t%f\tY:\t%f\tZ:\t%f\n", gyro_xyz[0], gyro_xyz[1], gyro_xyz[2]);
        if(useGPS)
        {
            nmea_info2pos(&gpsInfo, &dpos);
            printw("GPS:\t\t Long.:\t%f\tLat.:\t%f\tAlt.:\t%f\n", 180*dpos.lat/3.14159265358979323846, 180*dpos.lon/3.14159265358979323846, gpsInfo.elv);
        }
        wrefresh(stdscr);
        werase(stdscr);
        wait_period(&info);
    }
}

variable_types: struct periodic_info { int timer_fd; unsigned long long wakeups_missed; }

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

variable_types: startTime long

variable_types: currentTime long

return_type: void *


decompiled_code:
void __noreturn thread_SensorFusion()
{
_BYTE v0[24]; // [rsp+0h] [rbp-18h] BYREF

if ( !useGyro || (unsigned int)itg3200_init() && (unsigned int)itg3200_calibrate_gyro() )
{
if ( !(useMag | useAcc) )
goto LABEL_3;
}
else
{
status_0 = 0;
if ( !(useAcc | useMag) )
goto LABEL_16;
}
if ( !(unsigned int)lsm303_init() )
{
status_0 = 0;
goto LABEL_16;
}
LABEL_3:
if ( status_0 )
{
make_periodic_isra_0(100000, (__int64)v0);
while ( 1 )
{
if ( useGyro )
{
itg3200_read_deg(gyro_xyz);
if ( !useAcc )
goto LABEL_6;
}
else if ( !useAcc )
{
goto LABEL_6;
}
lsm303_read_acc_SI(acc_xyz);
LABEL_6:
if ( useMag )
lsm303_read_mag_measurements(mag_xyz);
wait_period((__int64)v0);
}
}
LABEL_16:
perror("i2c-init failed\n");
exit(1);
}

canonical_decompiled_code:
void __noreturn func3()
{
_BYTE v0[24]; // [rsp+0h] [rbp-18h] BYREF

if ( !useGyro || (unsigned int)itg3200_init() && (unsigned int)itg3200_calibrate_gyro() )
{
if ( !(useMag | useAcc) )
goto LABEL_3;
}
else
{
status_0 = 0;
if ( !(useAcc | useMag) )
goto LABEL_16;
}
if ( !(unsigned int)lsm303_init() )
{
status_0 = 0;
goto LABEL_16;
}
LABEL_3:
if ( status_0 )
{
func1(100000, (__int64)v0);
while ( 1 )
{
if ( useGyro )
{
itg3200_read_deg(gyro_xyz);
if ( !useAcc )
goto LABEL_6;
}
else if ( !useAcc )
{
goto LABEL_6;
}
lsm303_read_acc_SI(acc_xyz);
LABEL_6:
if ( useMag )
lsm303_read_mag_measurements(mag_xyz);
func0((__int64)v0);
}
}
LABEL_16:
perror("i2c-init failed\n");
exit(1);
}

original_code:
void * thread_SensorFusion()
{
    struct periodic_info info;
    static int status = 1;
    if(useGyro)
        if (!itg3200_init())
            status = 0;
        else if (!itg3200_calibrate_gyro())
            status = 0;
    if(useAcc || useMag)
        if (!lsm303_init())
            status = 0;
    if (status)
    {
        make_periodic (100000, &info);
        while(1)
        {
           if(useGyro) itg3200_read_deg(gyro_xyz);
           if(useAcc) lsm303_read_acc_SI(acc_xyz);
           if(useMag) lsm303_read_mag_measurements(mag_xyz);
           wait_period(&info);
        }
    }
    perror("i2c-init failed\n");
    exit(1);
}

canonical_original_code:
void *thread_SensorFusion()
{
    struct periodic_info info;
    static int status = 1;
    if(useGyro)
        if (!itg3200_init())
            status = 0;
        else if (!itg3200_calibrate_gyro())
            status = 0;
    if(useAcc || useMag)
        if (!lsm303_init())
            status = 0;
    if (status)
    {
        make_periodic (100000, &info);
        while(1)
        {
           if(useGyro) itg3200_read_deg(gyro_xyz);
           if(useAcc) lsm303_read_acc_SI(acc_xyz);
           if(useMag) lsm303_read_mag_measurements(mag_xyz);
           wait_period(&info);
        }
    }
    perror("i2c-init failed\n");
    exit(1);
}

variable_types: status int

user_defined_types: struct periodic_info { int timer_fd; unsigned long long wakeups_missed; }


decompiled_code:
void __noreturn thread_getGPS()
{
int v0; // eax
int v1; // ebp
__int64 v2; // rbx
char v3; // al
__int64 v4; // rdx
char buf; // [rsp+Fh] [rbp-229h] BYREF
char v6[16]; // [rsp+10h] [rbp-228h] BYREF
char v7[536]; // [rsp+20h] [rbp-218h] BYREF

v0 = open("/dev/ttyUSB0", 2306);
if ( v0 == -1 )
{
perror("open_port: Unable to open /dev/ttyS0 -\n");
exit(1);
}
v1 = v0;
fcntl(v0, 4, 0LL);
make_periodic_isra_0(500000, (__int64)v6);
while ( 1 )
{
LABEL_4:
v2 = 1LL;
do
{
if ( read(v1, &buf, 1uLL) != 1 )
{
wait_period((__int64)v6);
goto LABEL_4;
}
v3 = buf;
v4 = (unsigned int)v2;
v6[v2++ + 15] = buf;
}
while ( v3 != 10 );
nmea_parse(&parser, v7, v4, gpsInfo);
}
}

canonical_decompiled_code:
void __noreturn func4()
{
int v0; // eax
int v1; // ebp
__int64 v2; // rbx
char v3; // al
__int64 v4; // rdx
char buf; // [rsp+Fh] [rbp-229h] BYREF
char v6[16]; // [rsp+10h] [rbp-228h] BYREF
char v7[536]; // [rsp+20h] [rbp-218h] BYREF

v0 = open("/dev/ttyUSB0", 2306);
if ( v0 == -1 )
{
perror("open_port: Unable to open /dev/ttyS0 -\n");
exit(1);
}
v1 = v0;
fcntl(v0, 4, 0LL);
func1(500000, (__int64)v6);
while ( 1 )
{
LABEL_4:
v2 = 1LL;
do
{
if ( read(v1, &buf, 1uLL) != 1 )
{
func0((__int64)v6);
goto LABEL_4;
}
v3 = buf;
v4 = (unsigned int)v2;
v6[v2++ + 15] = buf;
}
while ( v3 != 10 );
nmea_parse(&parser, v7, v4, gpsInfo);
}
}

original_code:
void * thread_getGPS()
{
    struct periodic_info info;
    int fd = open("/dev/ttyUSB0", 02 | 0400 | 04000);
    if (fd == -1)
    {
        perror("open_port: Unable to open /dev/ttyS0 -\n");
        exit(1);
    }
    else
    {
        fcntl(fd, 4, 0);
        make_periodic (500000, &info);
        char buffer[512];
        while(1)
        {
            char c;
            int index = 0;
            while(read(fd, &c, 1) == 1 )
            {
                buffer[index] = c;
                index++;
                if (c == '\n')
                {
                    nmea_parse(&parser, &buffer[0], index, &gpsInfo);
                    index = 0;
                }
            }
            wait_period(&info);
        }
    }
}

canonical_original_code:
void *thread_getGPS()
{
    struct periodic_info info;
    int fd = open("/dev/ttyUSB0", 02 | 0400 | 04000);
    if (fd == -1)
    {
        perror("open_port: Unable to open /dev/ttyS0 -\n");
        exit(1);
    }
    else
    {
        fcntl(fd, 4, 0);
        make_periodic (500000, &info);
        char buffer[512];
        while(1)
        {
            char c;
            int index = 0;
            while(read(fd, &c, 1) == 1 )
            {
                buffer[index] = c;
                index++;
                if (c == '\n')
                {
                    nmea_parse(&parser, &buffer[0], index, &gpsInfo);
                    index = 0;
                }
            }
            wait_period(&info);
        }
    }
}

variable_types: fd int

variable_types:
buffer
char [512]

variable_types: c char

variable_types: index int


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

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

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

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

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

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

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char *v4; // rbp
size_t v5; // r12
pthread_t v7; // [rsp+8h] [rbp-40h] BYREF
pthread_t th; // [rsp+10h] [rbp-38h] BYREF
pthread_t newthread[6]; // [rsp+18h] [rbp-30h] BYREF

if ( argc > 1 )
{
v3 = argv;
do
{
v4 = *v3;
if ( **v3 == 45 )
{
useGyro = 0;
v5 = 1LL;
useMag = 0;
useAcc = 0;
useGPS = 0;
while ( 2 )
{
if ( strlen(v4) > v5 )
{
switch ( v4[v5] )
{
case 'A':
case 'a':
useAcc = 1;
goto LABEL_10;
case 'G':
case 'g':
useGyro = 1;
goto LABEL_10;
case 'M':
case 'm':
useMag = 1;
goto LABEL_10;
case 'P':
case 'p':
useGPS = 1;
LABEL_10:
++v5;
continue;
default:
puts("Usage:");
puts("If no parameter is given all sensors are use.");
puts("Only use certain sensors with:");
puts("\t-m/-M:\t include magnetometer");
puts("\t-a/-A:\t include accelerometer");
puts("\t-g/-G:\t include gyroscope");
puts("\t-p/-P:\t include GPS position\n");
return 1;
}
}
break;
}
}
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 1) + 1] );
}
initscr();
if ( useGPS )
{
nmea_zero_INFO(&gpsInfo, argv);
nmea_parser_init(&parser);
pthread_create(&v7, 0LL, (void *(*)(void *))&thread_getGPS, 0LL);
pthread_join(v7, 0LL);
}
pthread_create(newthread, 0LL, (void *(*)(void *))&thread_SensorFusion, 0LL);
pthread_create(&th, 0LL, (void *(*)(void *))&thread_DisplayValues, 0LL);
pthread_join(th, 0LL);
pthread_join(newthread[0], 0LL);
endwin();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    if (argc != 1)
    {
        int i;
        for (i = 0; i< argc; i++)
            if (argv[i][0] == '-')
            {
                useGyro = 0;
                useMag = 0;
                useAcc = 0;
                useGPS = 0;
                int j;
                for (j = 1; j< strlen(argv[i]); j++)
                    switch (argv[i][j])
                    {
                    case 'm':
                    case 'M': useMag = 1; break;
                    case 'a':
                    case 'A': useAcc = 1; break;
                    case 'G':
                    case 'g': useGyro = 1; break;
                    case 'p':
                    case 'P': useGPS = 1; break;
                    default: printf("Usage:\n");
                        printf("If no parameter is given all sensors are use.\n");
                        printf("Only use certain sensors with:\n");
                        printf("\t-m/-M:\t include magnetometer\n");
                        printf("\t-a/-A:\t include accelerometer\n");
                        printf("\t-g/-G:\t include gyroscope\n");
                        printf("\t-p/-P:\t include GPS position\n\n");
                        return 1;
                    }
            }
    }
    initscr();
      pthread_t t_1;
      pthread_t t_2;
      pthread_t t_3;
      if(useGPS)
      {
        nmea_zero_INFO(&gpsInfo);
        nmea_parser_init(&parser);
        pthread_create (&t_1, ((void *)0), thread_getGPS, ((void *)0)) ;
        pthread_join (t_1, ((void *)0));
      }
      pthread_create (&t_3, ((void *)0), thread_SensorFusion, ((void *)0)) ;
      pthread_create (&t_2, ((void *)0), thread_DisplayValues, ((void *)0)) ;
       pthread_join (t_2, ((void *)0));
       pthread_join (t_3, ((void *)0));
      endwin();
      return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    if (argc != 1)
    {
        int i;
        for (i = 0; i< argc; i++)
            if (argv[i][0] == '-')
            {
                useGyro = 0;
                useMag = 0;
                useAcc = 0;
                useGPS = 0;
                int j;
                for (j = 1; j< strlen(argv[i]); j++)
                    switch (argv[i][j])
                    {
                    case 'm':
                    case 'M': useMag = 1; break;
                    case 'a':
                    case 'A': useAcc = 1; break;
                    case 'G':
                    case 'g': useGyro = 1; break;
                    case 'p':
                    case 'P': useGPS = 1; break;
                    default: printf("Usage:\n");
                        printf("If no parameter is given all sensors are use.\n");
                        printf("Only use certain sensors with:\n");
                        printf("\t-m/-M:\t include magnetometer\n");
                        printf("\t-a/-A:\t include accelerometer\n");
                        printf("\t-g/-G:\t include gyroscope\n");
                        printf("\t-p/-P:\t include GPS position\n\n");
                        return 1;
                    }
            }
    }
    initscr();
      unsigned long t_1;
      unsigned long t_2;
      unsigned long t_3;
      if(useGPS)
      {
        nmea_zero_INFO(&gpsInfo);
        nmea_parser_init(&parser);
        pthread_create (&t_1, ((void *)0), thread_getGPS, ((void *)0)) ;
        pthread_join (t_1, ((void *)0));
      }
      pthread_create (&t_3, ((void *)0), thread_SensorFusion, ((void *)0)) ;
      pthread_create (&t_2, ((void *)0), thread_DisplayValues, ((void *)0)) ;
       pthread_join (t_2, ((void *)0));
       pthread_join (t_3, ((void *)0));
      endwin();
      return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: j int


original_code:
static uint8_t read_bits(const uint8_t *data, size_t idx)
{
    size_t idx_base = idx / 8;
    size_t idx_off = idx % 8;
    return 0x3F &
        ((data[idx_base] >> idx_off) | (data[idx_base+1] << (8 - idx_off)));
}

canonical_original_code:
static unsigned char read_bits(unsigned char *data, unsigned long idx)
{
    unsigned long idx_base = idx / 8;
    unsigned long idx_off = idx % 8;
    return 0x3F &
        ((data[idx_base] >> idx_off) | (data[idx_base+1] << (8 - idx_off)));
}

variable_types:
data
unsigned char *

variable_types:
idx
unsigned long

return_type: unsigned char


decompiled_code:
__int64 __fastcall base64_todigit(char a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0x3F;
if ( (unsigned __int8)v1 <= 9u )
return (unsigned int)(v1 + 48);
if ( (unsigned __int8)(v1 - 10) <= 0x19u )
return (unsigned int)(v1 + 87);
if ( (unsigned __int8)(v1 - 36) <= 0x19u )
return (unsigned int)(v1 + 29);
result = 61LL;
if ( (_BYTE)v1 == 62 )
result = 45LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0x3F;
if ( (unsigned __int8)v1 <= 9u )
return (unsigned int)(v1 + 48);
if ( (unsigned __int8)(v1 - 10) <= 0x19u )
return (unsigned int)(v1 + 87);
if ( (unsigned __int8)(v1 - 36) <= 0x19u )
return (unsigned int)(v1 + 29);
result = 61LL;
if ( (_BYTE)v1 == 62 )
result = 45LL;
return result;
}

original_code:
static char base64_todigit(uint8_t val)
{
    val &= 0x3F;
    if (val < 10)
    {
        return val + '0';
    }
    val -= 10;
    if (val < 26)
    {
        return val + 'a';
    }
    val -= 26;
    if (val < 26)
    {
        return val + 'A';
    }
    val -= 26;
    if (val == 0)
    {
        return '-';
    }
    if (val == 1)
    {
        return '=';
    }
    return (-1);
}

canonical_original_code:
static char base64_todigit(unsigned char val)
{
    val &= 0x3F;
    if (val < 10)
    {
        return val + '0';
    }
    val -= 10;
    if (val < 26)
    {
        return val + 'a';
    }
    val -= 26;
    if (val < 26)
    {
        return val + 'A';
    }
    val -= 26;
    if (val == 0)
    {
        return '-';
    }
    if (val == 1)
    {
        return '=';
    }
    return (-1);
}

variable_types:
val
unsigned char

return_type: char