MenuInit

decompiled_code:
__int64 MenuInit()
{
ButtonInit(&start, "../../Resource/start.png", 290LL, 100LL);
ButtonInit(&quit, "../../Resource/quit.png", 290LL, 400LL);
ButtonInit(&highscore, "../../Resource/highscore.png", 290LL, 200LL);
ButtonInit(&credits, "../../Resource/credits.png", 290LL, 300LL);
return ImageLoad("../../Resource/matrix.png", &background);
}

canonical_decompiled_code:
__int64 func0()
{
ButtonInit(&start, "../../Resource/start.png", 290LL, 100LL);
ButtonInit(&quit, "../../Resource/quit.png", 290LL, 400LL);
ButtonInit(&highscore, "../../Resource/highscore.png", 290LL, 200LL);
ButtonInit(&credits, "../../Resource/credits.png", 290LL, 300LL);
return ImageLoad("../../Resource/matrix.png", &background);
}

original_code:
void MenuInit()
{
    ButtonInit(&start, "../../Resource/start.png", 290, 100);
    ButtonInit(&quit, "../../Resource/quit.png", 290, 400);
    ButtonInit(&highscore, "../../Resource/highscore.png", 290, 200);
    ButtonInit(&credits, "../../Resource/credits.png", 290, 300);
    ImageLoad("../../Resource/matrix.png", &background);
}


MenuDelete

repo: yippee-ki-yay/ShootToKill

decompiled_code:
__int64 MenuDelete()
{
ButtonDelete(&start);
ButtonDelete(&quit);
ButtonDelete(&highscore);
ButtonDelete(&credits);
return ImageDelete(&background);
}

canonical_decompiled_code:
__int64 func1()
{
ButtonDelete(&start);
ButtonDelete(&quit);
ButtonDelete(&highscore);
ButtonDelete(&credits);
return ImageDelete(&background);
}

original_code:
void MenuDelete()
{
    ButtonDelete(&start);
    ButtonDelete(&quit);
    ButtonDelete(&highscore);
    ButtonDelete(&credits);
    ImageDelete(&background);
}

return_type: void


compare

decompiled_code:
__int64 __fastcall compare(const void *a1, const void *a2)
{
int v2; // eax
bool v3; // cc
__int64 result; // rax

v2 = *((_DWORD *)a2 + 4);
v3 = *((_DWORD *)a1 + 4) <= v2;
result = *((_DWORD *)a1 + 4) < v2;
if ( !v3 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
int v2; // eax
bool v3; // cc
__int64 result; // rax

v2 = *((_DWORD *)a2 + 4);
v3 = *((_DWORD *)a1 + 4) <= v2;
result = *((_DWORD *)a1 + 4) < v2;
if ( !v3 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int compare(const void *a, const void *b)
{
  Score* f = (Score*)a;
  Score* s = (Score*)b;
    if(f->score > s->score)
        return -1;
    else if(f->score < s->score)
        return 1;
       return 0;
}

canonical_original_code:
int compare(void *a, void *b)
{
  struct Score *f = (Score*)a;
  struct Score *s = (Score*)b;
    if(f->score > s->score)
        return -1;
    else if(f->score < s->score)
        return 1;
       return 0;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct Score { char name[16]; int score; } *

return_type: int


HighScoreDelete

decompiled_code:
__int64 HighScoreDelete()
{
char *v0; // rbx
char *v1; // rdi
char *v2; // rbx
char *v3; // rdi
__int64 result; // rax

v0 = (char *)&high;
ImageDelete(&h_background);
ButtonDelete(&h_back);
TextDelete(&h_text);
fclose(fp);
do
{
v1 = v0;
v0 += 24;
TextDelete(v1);
}
while ( v0 != (char *)&high + 240 );
v2 = (char *)&names;
do
{
v3 = v2;
v2 += 24;
result = TextDelete(v3);
}
while ( (char *)(unsigned int)((_DWORD)&names + 240) != v2 );
return result;
}

canonical_decompiled_code:
__int64 func2()
{
char *v0; // rbx
char *v1; // rdi
char *v2; // rbx
char *v3; // rdi
__int64 result; // rax

v0 = (char *)&high;
ImageDelete(&h_background);
ButtonDelete(&h_back);
TextDelete(&h_text);
fclose(fp);
do
{
v1 = v0;
v0 += 24;
TextDelete(v1);
}
while ( v0 != (char *)&high + 240 );
v2 = (char *)&names;
do
{
v3 = v2;
v2 += 24;
result = TextDelete(v3);
}
while ( (char *)(unsigned int)((_DWORD)&names + 240) != v2 );
return result;
}

original_code:
void HighScoreDelete()
{
    ImageDelete(&h_background);
    ButtonDelete(&h_back);
    TextDelete(&h_text);
      fclose(fp);
    int i = 0;
    for(; i < 10; ++i)
    {
        TextDelete(&high[i]);
    }
    for(i = 0; i < 10; ++i)
    {
        TextDelete(&names[i]);
    }
}

variable_types: i int


HighScoreAdd

decompiled_code:
int __fastcall HighScoreAdd(char *src, unsigned int a2, int a3)
{
__int64 v3; // rbx
FILE *v4; // rdi
int result; // eax
char v6[40]; // [rsp+0h] [rbp-28h] BYREF

v3 = a3 - 1;
strncpy(v6, src, a3);
v4 = fp;
v6[v3] = 0;
fprintf(v4, "%s %d\n", v6, a2);
result = fflush(fp);
++n_lines;
return result;
}

canonical_decompiled_code:
int __fastcall func3(char *src, unsigned int a2, int a3)
{
__int64 v3; // rbx
FILE *v4; // rdi
int result; // eax
char v6[40]; // [rsp+0h] [rbp-28h] BYREF

v3 = a3 - 1;
strncpy(v6, src, a3);
v4 = fp;
v6[v3] = 0;
fprintf(v4, "%s %d\n", v6, a2);
result = fflush(fp);
++n_lines;
return result;
}

original_code:
void HighScoreAdd(char* name, int score, int size)
{
    char tmp[16];
    strncpy(tmp, name, size);
    tmp[size - 1] = '\0';
    fprintf(fp,"%s %d\n", tmp, score);
    fflush(fp);
    n_lines++;
}

canonical_original_code:
void HighScoreAdd(char *name, int score, int size)
{
    char tmp[16];
    strncpy(tmp, name, size);
    tmp[size - 1] = '\0';
    fprintf(fp,"%s %d\n", tmp, score);
    fflush(fp);
    n_lines++;
}

variable_types:
name
char *

variable_types: score int

variable_types: size int

variable_types:
tmp
char [16]


HighScoreRead

decompiled_code:
void HighScoreRead()
{
int v0; // ebp
char *v1; // rbx
FILE *i; // rdi
char *v3; // rdi
size_t v4; // rsi
int v5; // [rsp+Ch] [rbp-2Ch] BYREF
char src[40]; // [rsp+10h] [rbp-28h] BYREF

v0 = 0;
v1 = scores;
fp = fopen("../../Resource/highscore.txt", "a+");
for ( i = fp; ; i = fp )
{
if ( fscanf(i, "%s %d", src, &v5) == -1 )
{
v4 = v0;
goto LABEL_6;
}
if ( v0 == 200 )
break;
v3 = v1;
++v0;
v1 += 20;
*((_DWORD *)v1 - 1) = v5;
strcpy(v3, src);
}
v4 = 200LL;
LABEL_6:
qsort(scores, v4, 0x14uLL, (__compar_fn_t)compare);
tt = v0;
}

canonical_decompiled_code:
void func6()
{
int v0; // ebp
char *v1; // rbx
FILE *i; // rdi
char *v3; // rdi
size_t v4; // rsi
int v5; // [rsp+Ch] [rbp-2Ch] BYREF
char src[40]; // [rsp+10h] [rbp-28h] BYREF

v0 = 0;
v1 = scores;
fp = fopen("../../Resource/highscore.txt", "a+");
for ( i = fp; ; i = fp )
{
if ( fscanf(i, "%s %d", src, &v5) == -1 )
{
v4 = v0;
goto LABEL_6;
}
if ( v0 == 200 )
break;
v3 = v1;
++v0;
v1 += 20;
*((_DWORD *)v1 - 1) = v5;
strcpy(v3, src);
}
v4 = 200LL;
LABEL_6:
qsort(scores, v4, 0x14uLL, (__compar_fn_t)compare);
tt = v0;
}

original_code:
void HighScoreRead()
{
    int i = 0, skor;
    char ime[16];
    fp = fopen("../../Resource/highscore.txt", "a+");
    while(fscanf(fp, "%s %d", ime, &skor) != (-1) && i < 200)
    {
        scores[i].score = skor;
        strcpy(scores[i].name, ime);
        i++;
    }
    qsort(scores, i, sizeof(Score), compare);
    tt= i;
}

canonical_original_code:
void HighScoreRead()
{
    int i = 0; int skor;
    char ime[16];
    fp = fopen("../../Resource/highscore.txt", "a+");
    while(fscanf(fp, "%s %d", ime, &skor) != (-1) && i < 200)
    {
        scores[i].score = skor;
        strcpy(scores[i].name, ime);
        i++;
    }
    qsort(scores, i, sizeof(Score), compare);
    tt= i;
}

variable_types: skor int

variable_types:
ime
char [16]


HighScoreInit

decompiled_code:
void HighScoreInit()
{
char *v0; // rbx
char *v1; // rdi
char *v2; // rbx
char *v3; // rdi
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = (char *)&high;
v4 = 0xFFFFFF;
ImageLoad("../../Resource/matrix.png", &h_background);
TextLoad(&h_text, "../../Resource/alien.ttf", 46LL);
TextPos(&h_text, 200LL, 50LL);
TextColor(&h_text, &v4);
ButtonInit(&h_back, "../../Resource/back.png", 700LL, 500LL);
v5[0] = 0xFFFFFF;
n_lines = 0;
tt = 0;
do
{
TextLoad(v0, "../../Resource/alien.ttf", 30LL);
v1 = v0;
v0 += 24;
TextColor(v1, v5);
}
while ( v0 != (char *)&high + 240 );
v2 = (char *)&names;
do
{
TextLoad(v2, "../../Resource/alien.ttf", 30LL);
v3 = v2;
v2 += 24;
TextColor(v3, v5);
}
while ( (char *)(unsigned int)((_DWORD)&names + 240) != v2 );
HighScoreRead();
}

canonical_decompiled_code:
void func7()
{
char *v0; // rbx
char *v1; // rdi
char *v2; // rbx
char *v3; // rdi
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = (char *)&high;
v4 = 0xFFFFFF;
ImageLoad("../../Resource/matrix.png", &h_background);
TextLoad(&h_text, "../../Resource/alien.ttf", 46LL);
TextPos(&h_text, 200LL, 50LL);
TextColor(&h_text, &v4);
ButtonInit(&h_back, "../../Resource/back.png", 700LL, 500LL);
v5[0] = 0xFFFFFF;
n_lines = 0;
tt = 0;
do
{
TextLoad(v0, "../../Resource/alien.ttf", 30LL);
v1 = v0;
v0 += 24;
TextColor(v1, v5);
}
while ( v0 != (char *)&high + 240 );
v2 = (char *)&names;
do
{
TextLoad(v2, "../../Resource/alien.ttf", 30LL);
v3 = v2;
v2 += 24;
TextColor(v3, v5);
}
while ( (char *)(unsigned int)((_DWORD)&names + 240) != v2 );
func6();
}

original_code:
void HighScoreInit()
{
    SDL_Color textColor = { 255, 255, 255 };
    ImageLoad("../../Resource/matrix.png", &h_background);
    TextLoad(&h_text, "../../Resource/alien.ttf", 46);
    TextPos(&h_text, 200, 50);
    TextColor(&h_text, &textColor);
    ButtonInit(&h_back, "../../Resource/back.png", 700, 500);
    n_lines = 0;
      tt = 0;
    SDL_Color color = {255, 255, 255};
    int i = 0;
    for(; i < 10; ++i)
    {
        TextLoad(&high[i], "../../Resource/alien.ttf", 30);
        TextColor(&high[i], &color);
    }
     for(i = 0; i < 10; ++i)
    {
        TextLoad(&names[i], "../../Resource/alien.ttf", 30);
        TextColor(&names[i], &color);
    }
    HighScoreRead();
}

canonical_original_code:
void HighScoreInit()
{
    struct SDL_Color textColor = { 255, 255, 255 };
    ImageLoad("../../Resource/matrix.png", &h_background);
    TextLoad(&h_text, "../../Resource/alien.ttf", 46);
    TextPos(&h_text, 200, 50);
    TextColor(&h_text, &textColor);
    ButtonInit(&h_back, "../../Resource/back.png", 700, 500);
    n_lines = 0;
      tt = 0;
    struct SDL_Color color = {255, 255, 255};
    int i = 0;
    for(; i < 10; ++i)
    {
        TextLoad(&high[i], "../../Resource/alien.ttf", 30);
        TextColor(&high[i], &color);
    }
     for(i = 0; i < 10; ++i)
    {
        TextLoad(&names[i], "../../Resource/alien.ttf", 30);
        TextColor(&names[i], &color);
    }
    HighScoreRead();
}

variable_types: struct SDL_Color { unsigned char r; unsigned char g; unsigned char b; unsigned char unused; }


BulletDelete

decompiled_code:
__int64 BulletDelete()
{
__int64 *v0; // rbx
void *v1; // rdi
__int64 result; // rax

v0 = &bullets;
do
{
v1 = (void *)*v0;
v0 += 3;
free(v1);
result = ImageDelete(*(v0 - 3));
}
while ( v0 != &bullets + 300 );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 *v0; // rbx
void *v1; // rdi
__int64 result; // rax

v0 = &bullets;
do
{
v1 = (void *)*v0;
v0 += 3;
free(v1);
result = ImageDelete(*(v0 - 3));
}
while ( v0 != &bullets + 300 );
return result;
}

original_code:
void BulletDelete()
{
    int i;
    for(i = 0; i < 100; ++i)
    {
        free(bullets[i].img_bullet);
        ImageDelete(bullets[i].img_bullet);
    }
}


BulletFire

decompiled_code:
__int64 __fastcall BulletFire(int a1, int a2, int a3)
{
__int64 v4; // rax
unsigned __int64 v5; // rdx
__int64 result; // rax
float *v7; // rdx

LODWORD(v4) = 0;
v5 = (unsigned int)((_DWORD)bullets + 16);
do
{
if ( *(_DWORD *)v5 == 1 )
{
v4 = (int)v4;
LODWORD(bullets[3 * (int)v4 + 2]) = 2;
goto LABEL_5;
}
LODWORD(v4) = v4 + 1;
v5 += 24LL;
}
while ( (_DWORD)v4 != 100 );
v4 = 100LL;
LABEL_5:
result = 3 * v4;
v7 = (float *)bullets[result];
*v7 = (float)a1;
v7[1] = (float)a2;
if ( a3 )
{
if ( a3 == 2 )
*(float *)&bullets[result + 1] = *(float *)&bullets[result + 1] - 10.0;
}
else
{
*(float *)&bullets[result + 1] = *(float *)&bullets[result + 1] + 10.0;
}
return result * 8;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, int a3)
{
__int64 v4; // rax
unsigned __int64 v5; // rdx
__int64 result; // rax
float *v7; // rdx

LODWORD(v4) = 0;
v5 = (unsigned int)((_DWORD)bullets + 16);
do
{
if ( *(_DWORD *)v5 == 1 )
{
v4 = (int)v4;
LODWORD(bullets[3 * (int)v4 + 2]) = 2;
goto LABEL_5;
}
LODWORD(v4) = v4 + 1;
v5 += 24LL;
}
while ( (_DWORD)v4 != 100 );
v4 = 100LL;
LABEL_5:
result = 3 * v4;
v7 = (float *)bullets[result];
*v7 = (float)a1;
v7[1] = (float)a2;
if ( a3 )
{
if ( a3 == 2 )
*(float *)&bullets[result + 1] = *(float *)&bullets[result + 1] - 10.0;
}
else
{
*(float *)&bullets[result + 1] = *(float *)&bullets[result + 1] + 10.0;
}
return result * 8;
}

original_code:
void BulletFire(int x, int y, int side)
{
    int i;
    for(i = 0; i < 100; ++i)
    {
        if(bullets[i].state == 1)
        {
            bullets[i].state = 2;
            break;
        }
    }
    bullets[i].img_bullet->x = x;
    bullets[i].img_bullet->y = y;
    if(side == 0)
    bullets[i].vel.x += 10;
    else if(side == 2)
    bullets[i].vel.x -= 10;
}

variable_types: x int

variable_types: y int

variable_types: side int


BulletMiss

decompiled_code:
__int64 *BulletMiss()
{
__int64 *result; // rax

result = bullets;
do
{
while ( *((_DWORD *)result + 4) != 2 || *(float *)*result <= 800.0 )
{
result += 3;
if ( result == &bullets[300] )
return result;
}
*((_DWORD *)result + 4) = 1;
result += 3;
*((_DWORD *)result - 4) = 0;
}
while ( result != &bullets[300] );
return result;
}

canonical_decompiled_code:
__int64 *func3()
{
__int64 *result; // rax

result = bullets;
do
{
while ( *((_DWORD *)result + 4) != 2 || *(float *)*result <= 800.0 )
{
result += 3;
if ( result == &bullets[300] )
return result;
}
*((_DWORD *)result + 4) = 1;
result += 3;
*((_DWORD *)result - 4) = 0;
}
while ( result != &bullets[300] );
return result;
}

original_code:
void BulletMiss()
{
    int i;
    for(i = 0; i < 100; ++i)
    {
        if(bullets[i].state == 2)
        {
            if(bullets[i].img_bullet->x > 800)
            {
                bullets[i].state = 1;
                bullets[i].vel.x = 0;
            }
        }
    }
}


PlayerInit

decompiled_code:
__int64 PlayerInit()
{
_QWORD *v0; // rax

AnimLoad("../../Resource/hero0.png", (unsigned int)((_DWORD)player + 16));
AnimFrameSize((unsigned int)((_DWORD)player + 16), 49LL, 65LL);
AnimSet((unsigned int)((_DWORD)player + 16), "trci desno", 1LL, 3LL, 0LL);
AnimSet((unsigned int)((_DWORD)player + 16), "trci levo", 1LL, 3LL, 1LL);
AnimSet((unsigned int)((_DWORD)player + 16), "pucaj desno", 1LL, 3LL, 2LL);
AnimSet((unsigned int)((_DWORD)player + 16), "stoji desno", 1LL, 1LL, 0LL);
AnimSet((unsigned int)((_DWORD)player + 16), "stoji levo", 1LL, 1LL, 1LL);
AnimSet((unsigned int)((_DWORD)player + 16), "pucaj levo", 1LL, 3LL, 3LL);
v0 = (_QWORD *)player[130];
player[1] = 0LL;
player_state = 0;
player_side = 2;
*v0 = 0x43C8000043AF0000LL;
return BulletInit("../../Resource/fireball.png");
}

canonical_decompiled_code:
__int64 func0()
{
_QWORD *v0; // rax

AnimLoad("../../Resource/hero0.png", (unsigned int)((_DWORD)player + 16));
AnimFrameSize((unsigned int)((_DWORD)player + 16), 49LL, 65LL);
AnimSet((unsigned int)((_DWORD)player + 16), "trci desno", 1LL, 3LL, 0LL);
AnimSet((unsigned int)((_DWORD)player + 16), "trci levo", 1LL, 3LL, 1LL);
AnimSet((unsigned int)((_DWORD)player + 16), "pucaj desno", 1LL, 3LL, 2LL);
AnimSet((unsigned int)((_DWORD)player + 16), "stoji desno", 1LL, 1LL, 0LL);
AnimSet((unsigned int)((_DWORD)player + 16), "stoji levo", 1LL, 1LL, 1LL);
AnimSet((unsigned int)((_DWORD)player + 16), "pucaj levo", 1LL, 3LL, 3LL);
v0 = (_QWORD *)player[130];
player[1] = 0LL;
player_state = 0;
player_side = 2;
*v0 = 0x43C8000043AF0000LL;
return BulletInit("../../Resource/fireball.png");
}

original_code:
void PlayerInit()
{
    AnimLoad("../../Resource/hero0.png", &(player.anim_player));
    AnimFrameSize(&(player.anim_player), 49, 65);
    AnimSet(&(player.anim_player), "trci desno", 1, 3, 0);
    AnimSet(&(player.anim_player), "trci levo", 1, 3, 1);
    AnimSet(&(player.anim_player), "pucaj desno", 1, 3, 2);
    AnimSet(&(player.anim_player), "stoji desno", 1, 1, 0);
    AnimSet(&(player.anim_player), "stoji levo", 1, 1, 1);
    AnimSet(&(player.anim_player), "pucaj levo", 1, 3, 3);
    player.vel.x = 0;
    player.vel.y = 0;
    player_state = 0;
    player_side = 2;
    player.anim_player.img_anim->x = 350;
    player.anim_player.img_anim->y = 400;
    BulletInit("../../Resource/fireball.png");
}


PlayerDelete

decompiled_code:
__int64 PlayerDelete()
{
AnimDelete((unsigned int)((_DWORD)player + 16));
return BulletDelete();
}

canonical_decompiled_code:
__int64 func1()
{
AnimDelete((unsigned int)((_DWORD)player + 16));
return BulletDelete();
}

original_code:
void PlayerDelete()
{
    AnimDelete(&(player.anim_player));
    BulletDelete();
}


PlayerUpdate

decompiled_code:
float *PlayerUpdate()
{
float *v0; // rax
float v1; // xmm1_4
float v2; // xmm0_4
float v3; // xmm1_4
float v4; // xmm0_4
float *result; // rax

v0 = (float *)player[130];
v1 = v0[1];
*v0 = *v0 + *(float *)&player[1];
v2 = *((float *)&player[1] + 1);
v3 = v1 + v2;
v0[1] = v3;
if ( v3 >= 490.0 )
v4 = 0.0;
else
v4 = v2 + 0.03;
*((float *)&player[1] + 1) = v4;
BulletMiss();
result = (float *)player[130];
if ( *result < 760.0 )
{
if ( *result <= 0.0 )
*result = 0.0;
}
else
{
*result = 760.0;
}
return result;
}

canonical_decompiled_code:
float *func4()
{
float *v0; // rax
float v1; // xmm1_4
float v2; // xmm0_4
float v3; // xmm1_4
float v4; // xmm0_4
float *result; // rax

v0 = (float *)player[130];
v1 = v0[1];
*v0 = *v0 + *(float *)&player[1];
v2 = *((float *)&player[1] + 1);
v3 = v1 + v2;
v0[1] = v3;
if ( v3 >= 490.0 )
v4 = 0.0;
else
v4 = v2 + 0.03;
*((float *)&player[1] + 1) = v4;
BulletMiss();
result = (float *)player[130];
if ( *result < 760.0 )
{
if ( *result <= 0.0 )
*result = 0.0;
}
else
{
*result = 760.0;
}
return result;
}

original_code:
void PlayerUpdate()
{
    player.anim_player.img_anim->x += player.vel.x;
    player.anim_player.img_anim->y += player.vel.y;
    if(player.anim_player.img_anim->y < 490)
    {
        player.vel.y += 0.03;
    }
    else
        player.vel.y = 0;
    BulletMiss();
    if(player.anim_player.img_anim->x >= 800 - 40)
            player.anim_player.img_anim->x = 800 - 40;
    if(player.anim_player.img_anim->x <= 0)
            player.anim_player.img_anim->x = 0;
}


PlayerRestart

decompiled_code:
_QWORD *PlayerRestart()
{
_QWORD *result; // rax

result = (_QWORD *)player[130];
player[1] = 0LL;
*result = 0x43C8000043AF0000LL;
return result;
}

canonical_decompiled_code:
_QWORD *func5()
{
_QWORD *result; // rax

result = (_QWORD *)player[130];
player[1] = 0LL;
*result = 0x43C8000043AF0000LL;
return result;
}

original_code:
void PlayerRestart()
{
     player.vel.x = 0;
    player.vel.y = 0;
    player.anim_player.img_anim->x = 350;
    player.anim_player.img_anim->y = 400;
}


Init

decompiled_code:
__int64 __fastcall Init(unsigned int a1, unsigned int a2, __int64 a3)
{
if ( (unsigned int)SDL_Init(0xFFFFLL) == -1 )
return 0xFFFFFFFFLL;
globals = SDL_SetVideoMode(a1, a2, 32LL, 0LL);
if ( !globals )
return 0xFFFFFFFFLL;
SDL_WM_SetCaption(a3, 0LL);
if ( (unsigned int)TTF_Init() == -1 )
return 0xFFFFFFFFLL;
*(__int64 *)((char *)&globals + 52) = 1LL;
*((_DWORD *)&globals + 11) = 0;
*((_DWORD *)&globals + 12) = SDL_GetTicks();
MenuInit();
GameInit();
CreditsInit();
HighScoreInit();
EndSceneInit();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2, __int64 a3)
{
if ( (unsigned int)SDL_Init(0xFFFFLL) == -1 )
return 0xFFFFFFFFLL;
globals = SDL_SetVideoMode(a1, a2, 32LL, 0LL);
if ( !globals )
return 0xFFFFFFFFLL;
SDL_WM_SetCaption(a3, 0LL);
if ( (unsigned int)TTF_Init() == -1 )
return 0xFFFFFFFFLL;
*(__int64 *)((char *)&globals + 52) = 1LL;
*((_DWORD *)&globals + 11) = 0;
*((_DWORD *)&globals + 12) = SDL_GetTicks();
MenuInit();
GameInit();
CreditsInit();
HighScoreInit();
EndSceneInit();
return 0LL;
}

original_code:
int Init(int x, int y, char* title)
{
 if(SDL_Init(0x0000FFFF) == -1)
  return -1;
 globals.screen = SDL_SetVideoMode(x,y, 32, 0x00000000);
 if(globals.screen == ((void *)0)) return -1;
 SDL_WM_SetCaption(title, ((void *)0));
 if(TTF_Init() == -1) return -1;
 globals.running = 1;
 globals.curr_state = 0;
 globals.frame = 0;
    globals.second = SDL_GetTicks();
    MenuInit();
    GameInit();
    CreditsInit();
    HighScoreInit();
    EndSceneInit();
 return 0;
}

canonical_original_code:
int Init(int x, int y, char *title)
{
 if(SDL_Init(0x0000FFFF) == -1)
  return -1;
 globals.screen = SDL_SetVideoMode(x,y, 32, 0x00000000);
 if(globals.screen == ((void *)0)) return -1;
 SDL_WM_SetCaption(title, ((void *)0));
 if(TTF_Init() == -1) return -1;
 globals.running = 1;
 globals.curr_state = 0;
 globals.frame = 0;
    globals.second = SDL_GetTicks();
    MenuInit();
    GameInit();
    CreditsInit();
    HighScoreInit();
    EndSceneInit();
 return 0;
}

variable_types:
title
char *


Destroy

decompiled_code:
__int64 Destroy()
{
MenuDelete();
GameDelete();
CreditsDelete();
HighScoreDelete();
EndSceneDelete();
TTF_Quit();
return SDL_Quit();
}

canonical_decompiled_code:
__int64 func1()
{
MenuDelete();
GameDelete();
CreditsDelete();
HighScoreDelete();
EndSceneDelete();
TTF_Quit();
return SDL_Quit();
}

original_code:
void Destroy()
{
    MenuDelete();
    GameDelete();
    CreditsDelete();
    HighScoreDelete();
    EndSceneDelete();
    TTF_Quit();
 SDL_Quit();
}


Update

decompiled_code:
__int64 Update()
{
int v0; // eax
__int64 v1; // rdi
__int64 result; // rax

++*((_DWORD *)&globals + 11);
v0 = SDL_GetTicks();
v1 = globals;
*((_DWORD *)&globals + 10) = v0;
SDL_Flip(v1);
while ( 1 )
{
result = SDL_PollEvent((unsigned int)((_DWORD)&globals + 8));
if ( !(_DWORD)result )
return result;
while ( 1 )
{
switch ( *((_DWORD *)&globals + 14) )
{
case 0:
MenuEvents((unsigned int)((_DWORD)&globals + 8), (unsigned int)((_DWORD)&globals + 56));
break;
case 1:
GameEvent((unsigned int)((_DWORD)&globals + 8), (unsigned int)((_DWORD)&globals + 56));
break;
case 2:
CreditsEvent((unsigned int)((_DWORD)&globals + 8), (unsigned int)((_DWORD)&globals + 56));
break;
case 3:
HighScoreEvent((unsigned int)((_DWORD)&globals + 8), (unsigned int)((_DWORD)&globals + 56));
break;
case 5:
EndSceneEvent(globals, (unsigned int)((_DWORD)&globals + 8), (unsigned int)((_DWORD)&globals + 56));
break;
default:
break;
}
if ( *((_BYTE *)&globals + 8) != 12 )
break;
*((_DWORD *)&globals + 13) = 0;
result = SDL_PollEvent((unsigned int)((_DWORD)&globals + 8));
if ( !(_DWORD)result )
return result;
}
}
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
__int64 v1; // rdi
__int64 result; // rax

++*((_DWORD *)&globals + 11);
v0 = SDL_GetTicks();
v1 = globals;
*((_DWORD *)&globals + 10) = v0;
SDL_Flip(v1);
while ( 1 )
{
result = SDL_PollEvent((unsigned int)((_DWORD)&globals + 8));
if ( !(_DWORD)result )
return result;
while ( 1 )
{
switch ( *((_DWORD *)&globals + 14) )
{
case 0:
MenuEvents((unsigned int)((_DWORD)&globals + 8), (unsigned int)((_DWORD)&globals + 56));
break;
case 1:
GameEvent((unsigned int)((_DWORD)&globals + 8), (unsigned int)((_DWORD)&globals + 56));
break;
case 2:
CreditsEvent((unsigned int)((_DWORD)&globals + 8), (unsigned int)((_DWORD)&globals + 56));
break;
case 3:
HighScoreEvent((unsigned int)((_DWORD)&globals + 8), (unsigned int)((_DWORD)&globals + 56));
break;
case 5:
EndSceneEvent(globals, (unsigned int)((_DWORD)&globals + 8), (unsigned int)((_DWORD)&globals + 56));
break;
default:
break;
}
if ( *((_BYTE *)&globals + 8) != 12 )
break;
*((_DWORD *)&globals + 13) = 0;
result = SDL_PollEvent((unsigned int)((_DWORD)&globals + 8));
if ( !(_DWORD)result )
return result;
}
}
}

original_code:
void Update()
{
    globals.frame++;
    globals.start = SDL_GetTicks();
 SDL_Flip(globals.screen);
 while(SDL_PollEvent(&(globals.event)))
 {
     switch(globals.curr_state)
     {
            case 0:
                MenuEvents(&(globals.event), &(globals.curr_state));
                break;
            case 1:
                GameEvent(&(globals.event),&(globals.curr_state));
                break;
            case 2:
                CreditsEvent(&(globals.event), &(globals.curr_state));
                break;
            case 3:
                HighScoreEvent(&(globals.event), &(globals.curr_state));
                break;
            case 5:
                EndSceneEvent(globals.screen, &(globals.event), &(globals.curr_state));
                break;
     };
  if(globals.event.type == SDL_QUIT)
   globals.running = 0;
 }
}


IsRunning

decompiled_code:
__int64 IsRunning()
{
return *((unsigned int *)&globals + 13);
}

canonical_decompiled_code:
__int64 func3()
{
return *((unsigned int *)&globals + 13);
}


ShowFps

decompiled_code:
__int64 ShowFps()
{
int v0; // eax
__int64 result; // rax

v0 = SDL_GetTicks() - *((_DWORD *)&globals + 10);
if ( v0 <= 15 )
SDL_Delay((unsigned int)(16 - v0));
result = (unsigned int)SDL_GetTicks() - *((_DWORD *)&globals + 12);
if ( (unsigned int)result > 0x3E8 )
{
result = SDL_GetTicks();
*((_DWORD *)&globals + 11) = 0;
*((_DWORD *)&globals + 12) = result;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
__int64 result; // rax

v0 = SDL_GetTicks() - *((_DWORD *)&globals + 10);
if ( v0 <= 15 )
SDL_Delay((unsigned int)(16 - v0));
result = (unsigned int)SDL_GetTicks() - *((_DWORD *)&globals + 12);
if ( (unsigned int)result > 0x3E8 )
{
result = SDL_GetTicks();
*((_DWORD *)&globals + 11) = 0;
*((_DWORD *)&globals + 12) = result;
}
return result;
}

original_code:
void ShowFps()
{
    int now = SDL_GetTicks();
  if( (now - globals.start) < (1000/60))
  {
     SDL_Delay((1000/60) - (now - globals.start));
  }
  if(SDL_GetTicks() - globals.second > 1000)
  {
       globals.second = SDL_GetTicks();
       globals.frame = 0;
  }
}

variable_types: now int


Draw

decompiled_code:
__int64 Draw()
{
__int64 result; // rax

switch ( *((_DWORD *)&globals + 14) )
{
case 0:
MenuDraw(globals);
result = ShowFps();
break;
case 1:
GameDraw(globals, (unsigned int)((_DWORD)&globals + 56));
result = ShowFps();
break;
case 2:
CreditsDraw(globals);
result = ShowFps();
break;
case 3:
HighScoreDraw(globals);
result = ShowFps();
break;
case 4:
*((_DWORD *)&globals + 13) = 0;
result = ShowFps();
break;
case 5:
EndSceneDraw(globals);
result = ShowFps();
break;
default:
result = ShowFps();
break;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax

switch ( *((_DWORD *)&globals + 14) )
{
case 0:
MenuDraw(globals);
result = func4();
break;
case 1:
GameDraw(globals, (unsigned int)((_DWORD)&globals + 56));
result = func4();
break;
case 2:
CreditsDraw(globals);
result = func4();
break;
case 3:
HighScoreDraw(globals);
result = func4();
break;
case 4:
*((_DWORD *)&globals + 13) = 0;
result = func4();
break;
case 5:
EndSceneDraw(globals);
result = func4();
break;
default:
result = func4();
break;
}
return result;
}

original_code:
void Draw()
{
    switch(globals.curr_state)
    {
        case 0:
            MenuDraw(globals.screen);
            break;
        case 1:
            GameDraw(globals.screen, &(globals.curr_state));
            break;
        case 2:
            CreditsDraw(globals.screen);
            break;
        case 3:
            HighScoreDraw(globals.screen);
            break;
        case 5:
            EndSceneDraw(globals.screen);
            break;
        case 4:
                globals.running = 0;
                break;
    };
    ShowFps();
}


CreditsInit

decompiled_code:
__int64 CreditsInit()
{
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = 0xFFFFFF;
ImageLoad("../../Resource/matrix.png", &c_background);
TextLoad(&t, "../../Resource/alien.ttf", 30LL);
TextPos(&t, 20LL, 250LL);
TextColor(&t, v1);
return ButtonInit(&back, "../../Resource/back.png", 700LL, 500LL);
}

canonical_decompiled_code:
__int64 func0()
{
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = 0xFFFFFF;
ImageLoad("../../Resource/matrix.png", &c_background);
TextLoad(&t, "../../Resource/alien.ttf", 30LL);
TextPos(&t, 20LL, 250LL);
TextColor(&t, v1);
return ButtonInit(&back, "../../Resource/back.png", 700LL, 500LL);
}

original_code:
void CreditsInit()
{
    SDL_Color textColor = { 255, 255, 255 };
    ImageLoad("../../Resource/matrix.png", &c_background);
    TextLoad(&t, "../../Resource/alien.ttf", 30);
    TextPos(&t, 20, 250);
    TextColor(&t, &textColor);
    ButtonInit(&back, "../../Resource/back.png", 700, 500);
}

canonical_original_code:
void CreditsInit()
{
    struct SDL_Color textColor = { 255, 255, 255 };
    ImageLoad("../../Resource/matrix.png", &c_background);
    TextLoad(&t, "../../Resource/alien.ttf", 30);
    TextPos(&t, 20, 250);
    TextColor(&t, &textColor);
    ButtonInit(&back, "../../Resource/back.png", 700, 500);
}

user_defined_types: struct SDL_Color { unsigned char r; unsigned char g; unsigned char b; unsigned char unused; }


CreditsDelete

decompiled_code:
__int64 CreditsDelete()
{
ImageDelete(&c_background);
ButtonDelete(&back);
return TextDelete(&t);
}

canonical_decompiled_code:
__int64 func3()
{
ImageDelete(&c_background);
ButtonDelete(&back);
return TextDelete(&t);
}

original_code:
void CreditsDelete()
{
    ImageDelete(&c_background);
    ButtonDelete(&back);
    TextDelete(&t);
}


repo: yishii/MapTracer

decompiled_code:
double __fastcall convert_radian_to_degree(double a1)
{
return a1 / 0.0174532925199433;
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
return a1 / 0.0174532925199433;
}

original_code:
static double convert_radian_to_degree(double rad)
{
    return (rad / (3.14159265358979323846/180));
}

variable_types: rad double

return_type: double


error

decompiled_code:
int __fastcall error(void *buf, int a2)
{
printf("Error: ");
write(1, buf, a2);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(void *buf, int a2)
{
printf("Error: ");
write(1, buf, a2);
return putchar(10);
}

original_code:
void error(const char *str, int str_size)
{
    printf("Error: ");
    write(1, str, str_size);
    printf("\n");
}

canonical_original_code:
void error(char *str, int str_size)
{
    printf("Error: ");
    write(1, str, str_size);
    printf("\n");
}

variable_types:
str
char *


decompiled_code:
int __fastcall set_interface_attribs(int fd, int a2)
{
int result; // eax
int *v3; // rax
int *v4; // rax
struct termios v5; // [rsp+0h] [rbp-58h] BYREF

v5.c_ospeed = 0;
*(_QWORD *)&v5.c_cc[31] = 0LL;
*(_OWORD *)&v5.c_iflag = 0LL;
*(_OWORD *)&v5.c_line = 0LL;
*(_OWORD *)&v5.c_cc[15] = 0LL;
if ( tcgetattr(fd, &v5) )
{
v3 = _errno_location();
printf("error %d from tcgetattr", (unsigned int)*v3);
result = -1;
}
else
{
*(_WORD *)&v5.c_cc[5] = 25602;
v5.c_iflag = 0;
v5.c_cflag = a2 & 0x7FFFFCBF | 0x8B0;
v5.c_lflag = 35378;
result = tcsetattr(fd, 0, &v5);
if ( result )
{
v4 = _errno_location();
printf("error %d from tcsetattr", (unsigned int)*v4);
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(int fd, int a2)
{
int result; // eax
int *v3; // rax
int *v4; // rax
struct termios v5; // [rsp+0h] [rbp-58h] BYREF

v5.c_ospeed = 0;
*(_QWORD *)&v5.c_cc[31] = 0LL;
*(_OWORD *)&v5.c_iflag = 0LL;
*(_OWORD *)&v5.c_line = 0LL;
*(_OWORD *)&v5.c_cc[15] = 0LL;
if ( tcgetattr(fd, &v5) )
{
v3 = _errno_location();
printf("error %d from tcgetattr", (unsigned int)*v3);
result = -1;
}
else
{
*(_WORD *)&v5.c_cc[5] = 25602;
v5.c_iflag = 0;
v5.c_cflag = a2 & 0x7FFFFCBF | 0x8B0;
v5.c_lflag = 35378;
result = tcsetattr(fd, 0, &v5);
if ( result )
{
v4 = _errno_location();
printf("error %d from tcsetattr", (unsigned int)*v4);
result = -1;
}
}
return result;
}

original_code:
int set_interface_attribs (int fd, int speed)
{
    struct termios tty;
    memset (&tty, 0, sizeof tty);
    if (tcgetattr (fd, &tty) != 0){
 printf ("error %d from tcgetattr", (*__errno_location ()));
 return -1;
    }
    tty.c_cc[6] = 100;
    tty.c_cc[5] = 2;
    tty.c_cflag = 0000060;
    tty.c_cflag |= speed;
    tty.c_cflag |= (0004000 | 0000200);
    tty.c_cflag &= ~(0000400 | 0001000);
    tty.c_cflag &= ~0000100;
    tty.c_cflag &= ~020000000000;
    tty.c_iflag = 0;
    tty.c_lflag = 0000002 | 0100000 | 0000020 | 0000040 | 0001000 | 0004000;
    if (tcsetattr (fd, 0, &tty) != 0){
 printf ("error %d from tcsetattr", (*__errno_location ()));
 return -1;
    }
    return 0;
}

canonical_original_code:
int set_interface_attribs(int fd, int speed)
{
    struct termios tty;
    memset (&tty, 0, sizeof tty);
    if (tcgetattr (fd, &tty) != 0){
 printf ("error %d from tcgetattr", (*__errno_location ()));
 return -1;
    }
    tty.c_cc[6] = 100;
    tty.c_cc[5] = 2;
    tty.c_cflag = 0000060;
    tty.c_cflag |= speed;
    tty.c_cflag |= (0004000 | 0000200);
    tty.c_cflag &= ~(0000400 | 0001000);
    tty.c_cflag &= ~0000100;
    tty.c_cflag &= ~020000000000;
    tty.c_iflag = 0;
    tty.c_lflag = 0000002 | 0100000 | 0000020 | 0000040 | 0001000 | 0004000;
    if (tcsetattr (fd, 0, &tty) != 0){
 printf ("error %d from tcsetattr", (*__errno_location ()));
 return -1;
    }
    return 0;
}

variable_types: fd int

variable_types: speed int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


gpsOpen

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

result = 0LL;
if ( !tty_fd )
{
tty_fd = open(a1, 2306);
set_interface_attribs(tty_fd, 12);
*(_QWORD *)nmea_property() = trace;
*(_QWORD *)(nmea_property() + 8) = trace;
nmea_zero_INFO(&info);
nmea_parser_init(&parser);
demo_mode = a2;
result = 1LL;
gps_param = 0LL;
xmmword_5F0 = 0LL;
xmmword_600 = 0LL;
}
return result;
}

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

result = 0LL;
if ( !tty_fd )
{
tty_fd = open(a1, 2306);
func3(tty_fd, 12);
*(_QWORD *)nmea_property() = trace;
*(_QWORD *)(nmea_property() + 8) = trace;
nmea_zero_INFO(&info);
nmea_parser_init(&parser);
demo_mode = a2;
result = 1LL;
gps_param = 0LL;
xmmword_5F0 = 0LL;
xmmword_600 = 0LL;
}
return result;
}

original_code:
_Bool gpsOpen(char* interface,_Bool demo)
{
    _Bool ret = 0;
    if(tty_fd == 0){
 tty_fd = open(interface,02 | 0400 | 04000);
 set_interface_attribs(tty_fd,0000014);
 nmea_property()->trace_func = &trace;
 nmea_property()->error_func = &trace;
 nmea_zero_INFO(&info);
 nmea_parser_init(&parser);
 memset(&gps_param,0,sizeof(gps_param));
 demo_mode = demo;
 ret = 1;
    }
    return ret;
}

canonical_original_code:
_Bool gpsOpen(char *interface, _Bool demo)
{
    _Bool ret = 0;
    if(tty_fd == 0){
 tty_fd = open(interface,02 | 0400 | 04000);
 set_interface_attribs(tty_fd,0000014);
 nmea_property()->trace_func = &trace;
 nmea_property()->error_func = &trace;
 nmea_zero_INFO(&info);
 nmea_parser_init(&parser);
 memset(&gps_param,0,sizeof(gps_param));
 demo_mode = demo;
 ret = 1;
    }
    return ret;
}

variable_types:
interface
char *


gpsClose

decompiled_code:
__int64 gpsClose()
{
__int64 result; // rax

if ( !tty_fd )
return 0LL;
nmea_parser_destroy(&parser);
close(tty_fd);
result = 1LL;
tty_fd = 0;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax

if ( !tty_fd )
return 0LL;
nmea_parser_destroy(&parser);
close(tty_fd);
result = 1LL;
tty_fd = 0;
return result;
}

original_code:
_Bool gpsClose()
{
    _Bool ret = 0;
    if(tty_fd != 0){
 nmea_parser_destroy(&parser);
 close(tty_fd);
 tty_fd = 0;
 ret = 1;
    }
    return ret;
}


gpsStartRetriever

decompiled_code:
int __fastcall gpsStartRetriever(void (__fastcall **a1)(double, double))
{
char v1; // bl
ssize_t v2; // rax
double v3; // r14
double v4; // xmm0_8
double v5; // xmm1_8
__int64 v7[2]; // [rsp+10h] [rbp-1028h] BYREF
char buf[4120]; // [rsp+20h] [rbp-1018h] BYREF

if ( tty_fd )
{
pthread_mutex_lock(&gps_mutex);
gps_retrieve_loop = 1;
pthread_mutex_unlock(&gps_mutex);
do
{
while ( 1 )
{
pthread_mutex_lock(&gps_mutex);
v1 = gps_retrieve_loop;
pthread_mutex_unlock(&gps_mutex);
v2 = read(tty_fd, buf, 0x1000uLL);
if ( (int)v2 > 0 )
break;
if ( !v1 )
return v2;
}
buf[(int)v2] = 0;
nmea_parse(&parser, buf, v2, &info);
nmea_info2pos(&info, v7);
v3 = convert_radian_to_degree(*(double *)v7);
v4 = convert_radian_to_degree(*(double *)&v7[1]);
v5 = v4;
if ( *a1 )
{
(*a1)(v3, v4);
v5 = v4;
}
pthread_mutex_lock(&gps_mutex);
if ( demo_mode )
{
gps_param = __PAIR128__(LC6, LC5);
}
else
{
*(double *)&gps_param = v3;
*((double *)&gps_param + 1) = v5;
}
*(_QWORD *)&xmmword_5F0 = qword_480;
*(_QWORD *)&xmmword_600 = qword_4C0;
DWORD2(xmmword_5F0) = (int)*(double *)&qword_4B0;
DWORD2(xmmword_600) = dword_4D4;
HIDWORD(xmmword_600) = dword_4D0;
LODWORD(v2) = pthread_mutex_unlock(&gps_mutex);
}
while ( v1 );
}
else
{
printf("gps is not initialized");
LODWORD(v2) = 0;
}
return v2;
}

canonical_decompiled_code:
int __fastcall func6(void (__fastcall **a1)(double, double))
{
char v1; // bl
ssize_t v2; // rax
double v3; // r14
double v4; // xmm0_8
double v5; // xmm1_8
__int64 v7[2]; // [rsp+10h] [rbp-1028h] BYREF
char buf[4120]; // [rsp+20h] [rbp-1018h] BYREF

if ( tty_fd )
{
pthread_mutex_lock(&gps_mutex);
gps_retrieve_loop = 1;
pthread_mutex_unlock(&gps_mutex);
do
{
while ( 1 )
{
pthread_mutex_lock(&gps_mutex);
v1 = gps_retrieve_loop;
pthread_mutex_unlock(&gps_mutex);
v2 = read(tty_fd, buf, 0x1000uLL);
if ( (int)v2 > 0 )
break;
if ( !v1 )
return v2;
}
buf[(int)v2] = 0;
nmea_parse(&parser, buf, v2, &info);
nmea_info2pos(&info, v7);
v3 = func1(*(double *)v7);
v4 = func1(*(double *)&v7[1]);
v5 = v4;
if ( *a1 )
{
(*a1)(v3, v4);
v5 = v4;
}
pthread_mutex_lock(&gps_mutex);
if ( demo_mode )
{
gps_param = __PAIR128__(LC6, LC5);
}
else
{
*(double *)&gps_param = v3;
*((double *)&gps_param + 1) = v5;
}
*(_QWORD *)&xmmword_5F0 = qword_480;
*(_QWORD *)&xmmword_600 = qword_4C0;
DWORD2(xmmword_5F0) = (int)*(double *)&qword_4B0;
DWORD2(xmmword_600) = dword_4D4;
HIDWORD(xmmword_600) = dword_4D0;
LODWORD(v2) = pthread_mutex_unlock(&gps_mutex);
}
while ( v1 );
}
else
{
printf("gps is not initialized");
LODWORD(v2) = 0;
}
return v2;
}

original_code:
_Bool gpsStartRetriever(struct gps_callback_params* params)
{
    int result;
    unsigned char buff[4096];
    nmeaPOS dpos;
    int it = 0;
    _Bool loop;
    double lat;
    double lon;
    if(tty_fd == 0){
 printf("gps is not initialized");
 return(0);
    }
    pthread_mutex_lock(&gps_mutex);
    gps_retrieve_loop = 1;
    pthread_mutex_unlock(&gps_mutex);
    loop = 1;
    while(loop){
 pthread_mutex_lock(&gps_mutex);
 loop = gps_retrieve_loop;
 pthread_mutex_unlock(&gps_mutex);
 result = read(tty_fd,buff,sizeof(buff));
 if(result > 0){
     buff[result] = 0;
     nmea_parse(&parser, &buff[0], result, &info);
     nmea_info2pos(&info, &dpos);
     lat = convert_radian_to_degree(dpos.lat);
     lon = convert_radian_to_degree(dpos.lon);
     if(params->callback != ((void *)0)){
  params->callback(lat,lon);
     }
     pthread_mutex_lock(&gps_mutex);
     {
  if(demo_mode == 1){
      gps_param.lat = 34.700779;
      gps_param.lon = 135.496518;
  } else {
      gps_param.lat = lat;
      gps_param.lon = lon;
  }
  gps_param.sig = info.sig;
  gps_param.fix = info.fix;
  gps_param.elv = info.elv;
  gps_param.dir = info.direction;
  gps_param.sat_inview = info.satinfo.inview;
  gps_param.sat_inuse = info.satinfo.inuse;
     }
     pthread_mutex_unlock(&gps_mutex);
 }
    }
}

canonical_original_code:
_Bool gpsStartRetriever(struct gps_callback_params *params)
{
    int result;
    unsigned char buff[4096];
    struct _nmeaPOS dpos;
    int it = 0;
    _Bool loop;
    double lat;
    double lon;
    if(tty_fd == 0){
 printf("gps is not initialized");
 return(0);
    }
    pthread_mutex_lock(&gps_mutex);
    gps_retrieve_loop = 1;
    pthread_mutex_unlock(&gps_mutex);
    loop = 1;
    while(loop){
 pthread_mutex_lock(&gps_mutex);
 loop = gps_retrieve_loop;
 pthread_mutex_unlock(&gps_mutex);
 result = read(tty_fd,buff,sizeof(buff));
 if(result > 0){
     buff[result] = 0;
     nmea_parse(&parser, &buff[0], result, &info);
     nmea_info2pos(&info, &dpos);
     lat = convert_radian_to_degree(dpos.lat);
     lon = convert_radian_to_degree(dpos.lon);
     if(params->callback != ((void *)0)){
  params->callback(lat,lon);
     }
     pthread_mutex_lock(&gps_mutex);
     {
  if(demo_mode == 1){
      gps_param.lat = 34.700779;
      gps_param.lon = 135.496518;
  } else {
      gps_param.lat = lat;
      gps_param.lon = lon;
  }
  gps_param.sig = info.sig;
  gps_param.fix = info.fix;
  gps_param.elv = info.elv;
  gps_param.dir = info.direction;
  gps_param.sat_inview = info.satinfo.inview;
  gps_param.sat_inuse = info.satinfo.inuse;
     }
     pthread_mutex_unlock(&gps_mutex);
 }
    }
}

variable_types: struct gps_callback_params { void (*callback)(double lat, double lon); } *

variable_types: result int

variable_types:
buff
unsigned char [4096]

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

variable_types: it int

variable_types: lat double

variable_types: lon double


gpsGetCurrentParams

decompiled_code:
__int64 __fastcall gpsGetCurrentParams(__m128i *a1)
{
if ( a1 )
{
*a1 = _mm_load_si128((const __m128i *)&gps_param);
a1[1] = _mm_load_si128((const __m128i *)&xmmword_5F0);
a1[2] = _mm_load_si128((const __m128i *)&xmmword_600);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__m128i *a1)
{
if ( a1 )
{
*a1 = _mm_load_si128((const __m128i *)&gps_param);
a1[1] = _mm_load_si128((const __m128i *)&xmmword_5F0);
a1[2] = _mm_load_si128((const __m128i *)&xmmword_600);
}
return 0LL;
}

original_code:
_Bool gpsGetCurrentParams(struct gpsParams* p)
{
    _Bool ret = 0;
    if(p != ((void *)0)){
 memcpy(p,&gps_param,sizeof(gps_param));
    }
    return(ret);
}

canonical_original_code:
_Bool gpsGetCurrentParams(struct gpsParams *p)
{
    _Bool ret = 0;
    if(p != ((void *)0)){
 memcpy(p,&gps_param,sizeof(gps_param));
    }
    return(ret);
}

variable_types: struct gpsParams { double lat; double lon; int sig; int fix; int elv; double dir; int sat_inview; int sat_inuse; } *


gpsStopRetriever

decompiled_code:
int gpsStopRetriever()
{
pthread_mutex_lock(&gps_mutex);
gps_retrieve_loop = 0;
return pthread_mutex_unlock(&gps_mutex);
}

canonical_decompiled_code:
int func8()
{
pthread_mutex_lock(&gps_mutex);
gps_retrieve_loop = 0;
return pthread_mutex_unlock(&gps_mutex);
}

original_code:
_Bool gpsStopRetriever(void)
{
  pthread_mutex_lock(&gps_mutex);
  gps_retrieve_loop = 0;
  pthread_mutex_unlock(&gps_mutex);
}

canonical_original_code:
_Bool gpsStopRetriever()
{
  pthread_mutex_lock(&gps_mutex);
  gps_retrieve_loop = 0;
  pthread_mutex_unlock(&gps_mutex);
}


decompiled_code:
__int64 __fastcall retriever_write_callback(void *src, __int64 a2, __int64 a3)
{
__int64 result; // rax
int v5; // er12
char *v7; // rdi
int v8; // er14
char *v9; // rax

LODWORD(result) = a2 * a3;
v5 = a2 * a3;
if ( content_buffer )
{
v7 = (char *)content_buffer + current_pos_1;
v8 = current_pos_1 + v5;
LABEL_3:
memcpy(v7, src, a2 * a3);
result = v5;
current_pos_1 = v8;
return result;
}
if ( current_content_size == -1 || current_content_size > 0xFFFFF )
return (int)result;
v9 = (char *)malloc(current_content_size);
current_pos_1 = 0;
content_buffer = v9;
v7 = v9;
if ( v9 )
{
v8 = v5;
goto LABEL_3;
}
printf("%s : memory allocation error\n", "retriever_write_callback");
if ( content_buffer )
{
v8 = current_pos_1 + v5;
v7 = (char *)content_buffer + current_pos_1;
v5 = 0;
goto LABEL_3;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *src, __int64 a2, __int64 a3)
{
__int64 result; // rax
int v5; // er12
char *v7; // rdi
int v8; // er14
char *v9; // rax

LODWORD(result) = a2 * a3;
v5 = a2 * a3;
if ( content_buffer )
{
v7 = (char *)content_buffer + current_pos_1;
v8 = current_pos_1 + v5;
LABEL_3:
memcpy(v7, src, a2 * a3);
result = v5;
current_pos_1 = v8;
return result;
}
if ( current_content_size == -1 || current_content_size > 0xFFFFF )
return (int)result;
v9 = (char *)malloc(current_content_size);
current_pos_1 = 0;
content_buffer = v9;
v7 = v9;
if ( v9 )
{
v8 = v5;
goto LABEL_3;
}
printf("%s : memory allocation error\n", "retriever_write_callback");
if ( content_buffer )
{
v8 = current_pos_1 + v5;
v7 = (char *)content_buffer + current_pos_1;
v5 = 0;
goto LABEL_3;
}
return 0LL;
}

original_code:
static size_t retriever_write_callback(char* ptr,size_t size,size_t nmemb,void* userdata)
{
    int ret = nmemb*size;
    static int current_pos = 0;
    if(content_buffer == ((void *)0)){
 if(current_content_size != -1 && current_content_size < (1024*1024)){
     content_buffer = malloc(current_content_size);
     current_pos = 0;
     if(content_buffer == ((void *)0)){
  printf("%s : memory allocation error\n",__func__);
  ret = 0;
     }
 }
    }
    if(content_buffer != ((void *)0)){
 memcpy(content_buffer+current_pos,ptr,nmemb*size);
 current_pos += size*nmemb;
    }
    return(ret);
}

canonical_original_code:
static unsigned long retriever_write_callback(char *ptr, unsigned long size, unsigned long nmemb, void *userdata)
{
    int ret = nmemb*size;
    static int current_pos = 0;
    if(content_buffer == ((void *)0)){
 if(current_content_size != -1 && current_content_size < (1024*1024)){
     content_buffer = malloc(current_content_size);
     current_pos = 0;
     if(content_buffer == ((void *)0)){
  printf("%s : memory allocation error\n",__func__);
  ret = 0;
     }
 }
    }
    if(content_buffer != ((void *)0)){
 memcpy(content_buffer+current_pos,ptr,nmemb*size);
 current_pos += size*nmemb;
    }
    return(ret);
}

variable_types:
ptr
char *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
userdata
void *

variable_types: ret int

return_type: unsigned long


decompiled_code:
size_t __fastcall retriever_header_callback(void *src, __int64 a2, __int64 a3)
{
size_t v3; // r12
char *v4; // rax
char *v5; // rbp

v3 = a3 * a2;
v4 = (char *)malloc(a3 * a2 + 1);
if ( v4 )
{
v5 = v4;
memcpy(v4, src, v3);
v5[v3] = 0;
if ( !memcmp("Content-Length: ", v5, 0x10uLL) )
{
sscanf(v5 + 16, "%d", &current_content_size);
printf("CONTENT-SIZE = %ld\n", (unsigned int)current_content_size);
}
free(v5);
}
else
{
v3 = -1LL;
printf("%s : Memory allocation error\n", "retriever_header_callback");
}
return v3;
}

canonical_decompiled_code:
size_t __fastcall func1(void *src, __int64 a2, __int64 a3)
{
size_t v3; // r12
char *v4; // rax
char *v5; // rbp

v3 = a3 * a2;
v4 = (char *)malloc(a3 * a2 + 1);
if ( v4 )
{
v5 = v4;
memcpy(v4, src, v3);
v5[v3] = 0;
if ( !memcmp("Content-Length: ", v5, 0x10uLL) )
{
sscanf(v5 + 16, "%d", &current_content_size);
printf("CONTENT-SIZE = %ld\n", (unsigned int)current_content_size);
}
free(v5);
}
else
{
v3 = -1LL;
printf("%s : Memory allocation error\n", "retriever_header_callback");
}
return v3;
}

original_code:
static size_t retriever_header_callback(char* ptr,size_t size,size_t nmemb,void* userdata)
{
    char* buff = malloc(size*nmemb+1);
    int len = strlen("Content-Length: ");
    if(buff == ((void *)0)){
 printf("%s : Memory allocation error\n",__func__);
 return(-1);
    }
    memcpy((void*)buff,(const void*)ptr,size*nmemb);
    buff[size*nmemb] = 0;
    if(strncmp("Content-Length: ",buff,len) == 0){
 sscanf(buff+len,"%d",&current_content_size);
 printf("CONTENT-SIZE = %ld\n",current_content_size);
    }
    free(buff);
    return(nmemb*size);
}

canonical_original_code:
static unsigned long retriever_header_callback(char *ptr, unsigned long size, unsigned long nmemb, void *userdata)
{
    char *buff = malloc(size*nmemb+1);
    int len = strlen("Content-Length: ");
    if(buff == ((void *)0)){
 printf("%s : Memory allocation error\n",__func__);
 return(-1);
    }
    memcpy((void *)buff,(void *)ptr,size*nmemb);
    buff[size*nmemb] = 0;
    if(strncmp("Content-Length: ",buff,len) == 0){
 sscanf(buff+len,"%d",&current_content_size);
 printf("CONTENT-SIZE = %ld\n",current_content_size);
    }
    free(buff);
    return(nmemb*size);
}

variable_types:
buff
char *

variable_types: len int


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

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

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

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

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

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

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

variable_types: resv int


decompiled_code:
__int64 __fastcall nmea_parser_top(unsigned int **a1)
{
unsigned int *v1; // rax
unsigned int v2; // 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: retval int

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

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


decompiled_code:
__int64 __fastcall gui_thread(void *a1)
{
gui_EventHandler(a1);
puts("\nGUI THREAD TERMINATED");
return gpsStopRetriever();
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1)
{
gui_EventHandler(a1);
puts("\nGUI THREAD TERMINATED");
return gpsStopRetriever();
}

original_code:
void gui_thread(void *arg)
{
    gui_EventHandler();
    printf("\nGUI THREAD TERMINATED\n");
    gpsStopRetriever();
}

variable_types:
arg
void *


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

v2 = 0LL;
return gpsStartRetriever(&v2);
}

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

v2 = 0LL;
return gpsStartRetriever(&v2);
}

original_code:
void gps_receiver_thread(void* arg)
{
    struct gps_callback_params param;
    memset(&param,0,sizeof(param));
    param.callback = ((void *)0);
    gpsStartRetriever(&param);
}

canonical_original_code:
void gps_receiver_thread(void *arg)
{
    struct gps_callback_params param;
    memset(&param,0,sizeof(param));
    param.callback = ((void *)0);
    gpsStartRetriever(&param);
}

variable_types: struct gps_callback_params { void (*callback)(double lat, double lon); }


usage

decompiled_code:
int usage()
{
puts("maptracer [tty device for GPS module] [option]");
puts(" Copyright(C) 2013 Yasuhiro ISHII\n");
puts(" [option]");
puts(" -c : CVBS mode(low resolution mode)");
puts(" -n : No GUI mode(for debug)");
puts(" -p [tty] : Specify tty device");
return puts(" -d : DEMO Mode");
}

canonical_decompiled_code:
int func2()
{
puts("maptracer [tty device for GPS module] [option]");
puts(" Copyright(C) 2013 Yasuhiro ISHII\n");
puts(" [option]");
puts(" -c : CVBS mode(low resolution mode)");
puts(" -n : No GUI mode(for debug)");
puts(" -p [tty] : Specify tty device");
return puts(" -d : DEMO Mode");
}

original_code:
void usage(void)
{
    printf("maptracer [tty device for GPS module] [option]\n");
    printf(" Copyright(C) 2013 Yasuhiro ISHII\n\n");
    printf(" [option]\n");
    printf("  -c        : CVBS mode(low resolution mode)\n");
    printf("  -n        : No GUI mode(for debug)\n");
    printf("  -p [tty]  : Specify tty device\n");
    printf("  -d        : DEMO Mode\n");
}

canonical_original_code:
void usage()
{
    printf("maptracer [tty device for GPS module] [option]\n");
    printf(" Copyright(C) 2013 Yasuhiro ISHII\n\n");
    printf(" [option]\n");
    printf("  -c        : CVBS mode(low resolution mode)\n");
    printf("  -n        : No GUI mode(for debug)\n");
    printf("  -p [tty]  : Specify tty device\n");
    printf("  -d        : DEMO Mode\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // r14
unsigned __int8 v4; // bp
unsigned __int8 v5; // r13
int v6; // eax
pthread_t th; // [rsp+0h] [rbp-78h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
char dest[104]; // [rsp+10h] [rbp-68h] BYREF

if ( argc != 1 )
{
v3 = 0;
puts("MapTracer is launched");
v4 = 0;
v5 = 0;
XInitThreads();
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "p:cnd");
if ( v6 == -1 )
{
gpsOpen(dest, v4);
gui_open(v5, v3);
pthread_create(&th, 0LL, (void *(*)(void *))gps_receiver_thread, 0LL);
pthread_create(&newthread, 0LL, (void *(*)(void *))gui_thread, 0LL);
pthread_join(th, 0LL);
pthread_join(newthread, 0LL);
gui_close();
gpsClose();
return 0;
}
if ( v6 != 110 )
break;
v3 = 1;
puts("No GUI Mode(debug)");
}
if ( v6 <= 110 )
break;
if ( v6 == 112 )
strcpy(dest, optarg);
else
LABEL_13:
usage();
}
if ( v6 == 99 )
{
v5 = 1;
puts("cvbs");
}
else
{
if ( v6 != 100 )
goto LABEL_13;
v4 = 1;
}
}
}
usage();
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // r14
unsigned __int8 v4; // bp
unsigned __int8 v5; // r13
int v6; // eax
pthread_t th; // [rsp+0h] [rbp-78h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-70h] BYREF
char dest[104]; // [rsp+10h] [rbp-68h] BYREF

if ( argc != 1 )
{
v3 = 0;
puts("MapTracer is launched");
v4 = 0;
v5 = 0;
XInitThreads();
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "p:cnd");
if ( v6 == -1 )
{
gpsOpen(dest, v4);
gui_open(v5, v3);
pthread_create(&th, 0LL, (void *(*)(void *))gps_receiver_thread, 0LL);
pthread_create(&newthread, 0LL, (void *(*)(void *))gui_thread, 0LL);
pthread_join(th, 0LL);
pthread_join(newthread, 0LL);
gui_close();
gpsClose();
return 0;
}
if ( v6 != 110 )
break;
v3 = 1;
puts("No GUI Mode(debug)");
}
if ( v6 <= 110 )
break;
if ( v6 == 112 )
strcpy(dest, optarg);
else
LABEL_13:
func2();
}
if ( v6 == 99 )
{
v5 = 1;
puts("cvbs");
}
else
{
if ( v6 != 100 )
goto LABEL_13;
v4 = 1;
}
}
}
func2();
return -1;
}

original_code:
int main(int argc,char** argv)
{
    pthread_t gps_th;
    pthread_t gui_th;
    int opt;
    _Bool cvbs_resolution = 0;
    _Bool demo_mode = 0;
    _Bool no_gui_mode = 0;
    unsigned char tty_dev[64];
    if(argc == 1){
 usage();
 return -1;
    }
    printf("MapTracer is launched\n");
    XInitThreads();
    while((opt = getopt(argc,argv,"p:cnd")) != -1){
 switch(opt){
 case 'c':
     cvbs_resolution = 1;
     printf("cvbs\n");
     break;
 case 'p':
     strcpy(tty_dev,optarg);
     break;
 case 'n':
     printf("No GUI Mode(debug)\n");
     no_gui_mode = 1;
     break;
 case 'd':
     demo_mode = 1;
     break;
 default:
   usage();
     break;
 }
    }
    gpsOpen(tty_dev,demo_mode);
    gui_open(cvbs_resolution,no_gui_mode);
    pthread_create(&gps_th,((void *)0),gps_receiver_thread,((void *)0));
    pthread_create(&gui_th,((void *)0),gui_thread,((void *)0));
    pthread_join(gps_th);
    pthread_join(gui_th);
    gui_close();
    gpsClose();
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned long gps_th;
    unsigned long gui_th;
    int opt;
    _Bool cvbs_resolution = 0;
    _Bool demo_mode = 0;
    _Bool no_gui_mode = 0;
    unsigned char tty_dev[64];
    if(argc == 1){
 usage();
 return -1;
    }
    printf("MapTracer is launched\n");
    XInitThreads();
    while((opt = getopt(argc,argv,"p:cnd")) != -1){
 switch(opt){
 case 'c':
     cvbs_resolution = 1;
     printf("cvbs\n");
     break;
 case 'p':
     strcpy(tty_dev,optarg);
     break;
 case 'n':
     printf("No GUI Mode(debug)\n");
     no_gui_mode = 1;
     break;
 case 'd':
     demo_mode = 1;
     break;
 default:
   usage();
     break;
 }
    }
    gpsOpen(tty_dev,demo_mode);
    gui_open(cvbs_resolution,no_gui_mode);
    pthread_create(&gps_th,((void *)0),gps_receiver_thread,((void *)0));
    pthread_create(&gui_th,((void *)0),gui_thread,((void *)0));
    pthread_join(gps_th);
    pthread_join(gui_th);
    gui_close();
    gpsClose();
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int


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

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

variable_types:
buff
char *

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


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

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

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


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

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

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


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

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

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


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

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

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


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

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

variable_types: struct _nmeaGPGGA { struct _nmeaTIME utc; double lat; char ns; double lon; char ew; int sig; int satinuse; double HDOP; double elv; char elv_units; double diff; char diff_units; double dgps_age; int dgps_sid; } *


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

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

variable_types: it int


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

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

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

variable_types: sit int

variable_types: pit int


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

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

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

variable_types: struct _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; } *


decompiled_code:
__int64 __fastcall nmea_info2GPVTG(__int64 a1, __int64 a2)
{
__int64 result; // rax
double v3; // xmm0_8

result = nmea_zero_GPVTG(a2);
*(_QWORD *)a2 = *(_QWORD *)(a1 + 96);
*(_QWORD *)(a2 + 16) = *(_QWORD *)(a1 + 104);
v3 = *(double *)(a1 + 88);
*(double *)(a2 + 48) = v3;
*(double *)(a2 + 32) = v3 / 1.852;
return result;
}

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

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