Init

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

result = SDL_Init(0xFFFFLL);
if ( (_DWORD)result != -1 )
{
globals = SDL_SetVideoMode(a1, a2, 32LL, 0LL);
if ( globals )
{
SDL_WM_SetCaption(a3, 0LL);
result = TTF_Init();
if ( (_DWORD)result != -1 )
{
*((_DWORD *)&globals + 13) = 1;
*((_DWORD *)&globals + 14) = 0;
*((_DWORD *)&globals + 11) = 0;
*((_DWORD *)&globals + 12) = SDL_GetTicks();
MenuInit();
GameInit();
CreditsInit();
HighScoreInit();
EndSceneInit();
result = 0LL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

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

result = SDL_Init(0xFFFFLL);
if ( (_DWORD)result != -1 )
{
globals = SDL_SetVideoMode(a1, a2, 32LL, 0LL);
if ( globals )
{
SDL_WM_SetCaption(a3, 0LL);
result = TTF_Init();
if ( (_DWORD)result != -1 )
{
*((_DWORD *)&globals + 13) = 1;
*((_DWORD *)&globals + 14) = 0;
*((_DWORD *)&globals + 11) = 0;
*((_DWORD *)&globals + 12) = SDL_GetTicks();
MenuInit();
GameInit();
CreditsInit();
HighScoreInit();
EndSceneInit();
result = 0LL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

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

repo: yippee-ki-yay/ShootToKill

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

return_type: void


Update

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

++*((_DWORD *)&globals + 11);
*((_DWORD *)&globals + 10) = SDL_GetTicks();
SDL_Flip(globals);
while ( 1 )
{
result = SDL_PollEvent((unsigned int)((_DWORD)&globals + 8));
if ( !(_DWORD)result )
return result;
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 )
*((_DWORD *)&globals + 13) = 0;
}
}

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

++*((_DWORD *)&globals + 11);
*((_DWORD *)&globals + 10) = SDL_GetTicks();
SDL_Flip(globals);
while ( 1 )
{
result = SDL_PollEvent((unsigned int)((_DWORD)&globals + 8));
if ( !(_DWORD)result )
return result;
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 )
*((_DWORD *)&globals + 13) = 0;
}
}

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

return_type: int


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 + 12) = result;
*((_DWORD *)&globals + 11) = 0;
}
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 + 12) = result;
*((_DWORD *)&globals + 11) = 0;
}
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()
{
switch ( *((_DWORD *)&globals + 14) )
{
case 0:
MenuDraw(globals);
break;
case 1:
GameDraw(globals, (unsigned int)((_DWORD)&globals + 56));
break;
case 2:
CreditsDraw(globals);
break;
case 3:
HighScoreDraw(globals);
break;
case 4:
*((_DWORD *)&globals + 13) = 0;
break;
case 5:
EndSceneDraw(globals);
break;
default:
return ShowFps();
}
return ShowFps();
}

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

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()
{
char v1[12]; // [rsp+Ch] [rbp-Ch] BYREF

v1[3] = 0;
v1[0] = -1;
v1[1] = -1;
v1[2] = -1;
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()
{
char v1[12]; // [rsp+Ch] [rbp-Ch] BYREF

v1[3] = 0;
v1[0] = -1;
v1[1] = -1;
v1[2] = -1;
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);
}

variable_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

*(_QWORD *)&v5.c_iflag = 0LL;
*(_QWORD *)&v5.c_cflag = 0LL;
*(_QWORD *)&v5.c_line = 0LL;
*(_QWORD *)&v5.c_cc[7] = 0LL;
*(_QWORD *)&v5.c_cc[15] = 0LL;
*(_QWORD *)&v5.c_cc[23] = 0LL;
*(_QWORD *)&v5.c_cc[31] = 0LL;
v5.c_ospeed = 0;
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_cflag = a2 & 0x7FFFFCBF | 0x8B0;
v5.c_iflag = 0;
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

*(_QWORD *)&v5.c_iflag = 0LL;
*(_QWORD *)&v5.c_cflag = 0LL;
*(_QWORD *)&v5.c_line = 0LL;
*(_QWORD *)&v5.c_cc[7] = 0LL;
*(_QWORD *)&v5.c_cc[15] = 0LL;
*(_QWORD *)&v5.c_cc[23] = 0LL;
*(_QWORD *)&v5.c_cc[31] = 0LL;
v5.c_ospeed = 0;
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_cflag = a2 & 0x7FFFFCBF | 0x8B0;
v5.c_iflag = 0;
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);
gps_param = 0uLL;
xmmword_5D0 = 0uLL;
xmmword_5E0 = 0uLL;
demo_mode = a2;
result = 1LL;
}
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);
gps_param = 0uLL;
xmmword_5D0 = 0uLL;
xmmword_5E0 = 0uLL;
demo_mode = a2;
result = 1LL;
}
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

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

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

result = 0LL;
if ( tty_fd )
{
nmea_parser_destroy(&parser);
close(tty_fd);
tty_fd = 0;
result = 1LL;
}
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))
{
ssize_t v1; // rax
char v2; // bl
double v3; // r13
double v4; // xmm0_8
__int64 v6[2]; // [rsp+0h] [rbp-1038h] BYREF
char buf[4136]; // [rsp+10h] [rbp-1028h] BYREF

if ( tty_fd )
{
pthread_mutex_lock(&gps_mutex);
gps_retrieve_loop = 1;
pthread_mutex_unlock(&gps_mutex);
do
{
pthread_mutex_lock(&gps_mutex);
v2 = gps_retrieve_loop;
pthread_mutex_unlock(&gps_mutex);
v1 = read(tty_fd, buf, 0x1000uLL);
if ( (int)v1 > 0 )
{
buf[(int)v1] = 0;
nmea_parse(&parser, buf, v1, &info);
nmea_info2pos(&info, v6);
v3 = convert_radian_to_degree(*(double *)v6);
v4 = convert_radian_to_degree(*(double *)&v6[1]);
if ( *a1 )
(*a1)(v3, v4);
pthread_mutex_lock(&gps_mutex);
if ( demo_mode )
{
gps_param = __PAIR128__(LC6, LC5);
}
else
{
*(double *)&gps_param = v3;
*((double *)&gps_param + 1) = v4;
}
*(_QWORD *)&xmmword_5D0 = qword_460;
DWORD2(xmmword_5D0) = (int)*(double *)&qword_490;
*(_QWORD *)&xmmword_5E0 = qword_4A0;
DWORD2(xmmword_5E0) = dword_4B4;
HIDWORD(xmmword_5E0) = dword_4B0;
LODWORD(v1) = pthread_mutex_unlock(&gps_mutex);
}
}
while ( v2 );
}
else
{
printf("gps is not initialized");
LODWORD(v1) = 0;
}
return v1;
}

canonical_decompiled_code:
int __fastcall func6(void (__fastcall **a1)(double, double))
{
ssize_t v1; // rax
char v2; // bl
double v3; // r13
double v4; // xmm0_8
__int64 v6[2]; // [rsp+0h] [rbp-1038h] BYREF
char buf[4136]; // [rsp+10h] [rbp-1028h] BYREF

if ( tty_fd )
{
pthread_mutex_lock(&gps_mutex);
gps_retrieve_loop = 1;
pthread_mutex_unlock(&gps_mutex);
do
{
pthread_mutex_lock(&gps_mutex);
v2 = gps_retrieve_loop;
pthread_mutex_unlock(&gps_mutex);
v1 = read(tty_fd, buf, 0x1000uLL);
if ( (int)v1 > 0 )
{
buf[(int)v1] = 0;
nmea_parse(&parser, buf, v1, &info);
nmea_info2pos(&info, v6);
v3 = func1(*(double *)v6);
v4 = func1(*(double *)&v6[1]);
if ( *a1 )
(*a1)(v3, v4);
pthread_mutex_lock(&gps_mutex);
if ( demo_mode )
{
gps_param = __PAIR128__(LC6, LC5);
}
else
{
*(double *)&gps_param = v3;
*((double *)&gps_param + 1) = v4;
}
*(_QWORD *)&xmmword_5D0 = qword_460;
DWORD2(xmmword_5D0) = (int)*(double *)&qword_490;
*(_QWORD *)&xmmword_5E0 = qword_4A0;
DWORD2(xmmword_5E0) = dword_4B4;
HIDWORD(xmmword_5E0) = dword_4B0;
LODWORD(v1) = pthread_mutex_unlock(&gps_mutex);
}
}
while ( v2 );
}
else
{
printf("gps is not initialized");
LODWORD(v1) = 0;
}
return v1;
}

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_5D0);
a1[2] = _mm_load_si128((const __m128i *)&xmmword_5E0);
}
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_5D0);
a1[2] = _mm_load_si128((const __m128i *)&xmmword_5E0);
}
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)
{
int v5; // er15
int v6; // er12
char *v7; // rdi
int v8; // er14

v5 = a2 * a3;
v6 = a2 * a3;
if ( content_buffer )
goto LABEL_2;
if ( current_content_size != -1 && current_content_size <= 0xFFFFF )
{
content_buffer = malloc(current_content_size);
current_pos_1 = 0;
if ( !content_buffer )
{
printf("%s : memory allocation error\n", "retriever_write_callback");
v7 = (char *)content_buffer;
if ( !content_buffer )
return 0;
v6 = 0;
goto LABEL_3;
}
LABEL_2:
v7 = (char *)content_buffer;
LABEL_3:
v8 = current_pos_1;
memcpy(&v7[current_pos_1], src, a2 * a3);
current_pos_1 = v5 + v8;
}
return v6;
}

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

v5 = a2 * a3;
v6 = a2 * a3;
if ( content_buffer )
goto LABEL_2;
if ( current_content_size != -1 && current_content_size <= 0xFFFFF )
{
content_buffer = malloc(current_content_size);
current_pos_1 = 0;
if ( !content_buffer )
{
printf("%s : memory allocation error\n", "retriever_write_callback");
v7 = (char *)content_buffer;
if ( !content_buffer )
return 0;
v6 = 0;
goto LABEL_3;
}
LABEL_2:
v7 = (char *)content_buffer;
LABEL_3:
v8 = current_pos_1;
memcpy(&v7[current_pos_1], src, a2 * a3);
current_pos_1 = v5 + v8;
}
return v6;
}

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:
__int64 __fastcall retriever_header_callback(void *src, __int64 a2, __int64 a3)
{
size_t v3; // rsi
__int64 v4; // rbp
char *v5; // rax
char *v6; // rbx

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

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

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

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(_QWORD *a1)
{
int v1; // eax
int v2; // ebp
void *v3; // rax
__int64 result; // rax

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

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

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

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

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

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

variable_types: resv int


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

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

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

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

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

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

variable_types: 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; // rax
unsigned int v3; // ebx
__int64 v4; // rdx

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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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


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

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

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

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

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

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

variable_types: nparsed int

variable_types: crc int

variable_types: ptype int

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)
{
unsigned int v4; // er13
int v5; // ebp

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

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

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

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

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

variable_types: nparse int


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

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

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

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

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

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

variable_types: 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);
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = 0LL;
return result;
}

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

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

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

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


decompiled_code:
__int64 __fastcall 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; // r15
unsigned __int8 v4; // r12
unsigned __int8 v5; // r14
int v7; // eax
char v8[64]; // [rsp+0h] [rbp-88h] BYREF
pthread_t th; // [rsp+40h] [rbp-48h] BYREF
pthread_t newthread[8]; // [rsp+48h] [rbp-40h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // r15
unsigned __int8 v4; // r12
unsigned __int8 v5; // r14
int v7; // eax
char v8[64]; // [rsp+0h] [rbp-88h] BYREF
pthread_t th; // [rsp+40h] [rbp-48h] BYREF
pthread_t newthread[8]; // [rsp+48h] [rbp-40h] BYREF

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

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


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


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

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

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

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

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

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

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

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

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


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

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

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

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

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


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

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

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

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

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

variable_types:
info
struct _nmeaINFO *

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


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

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

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

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


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

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


decompiled_code:
__int64 __fastcall nmea_igen_static_init(__int64 a1, _DWORD *a2)
{
a2[8] = 3;
a2[9] = 3;
nmea_igen_static_reset(a1, a2);
return 1LL;
}

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

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


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

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

variable_types: deg double

variable_types: srt double


decompiled_code:
__int64 __fastcall nmea_igen_rotate_init(__int64 a1, _DWORD *a2)
{
a2[8] = 3;
a2[9] = 3;
nmea_igen_rotate_reset(a1, a2);
return 1LL;
}

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

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


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

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


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

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

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

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


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

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

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

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


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

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

variable_types: count int


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

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


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

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

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