// File: /workspace/github_c_makefile_star2_O2/canboat[P]canboat/n2kd/gps_ais.c
// Function: nmea0183GLL
extern void nmea0183GLL(StringBuffer *msg183, int src, const char *msg)
{
  char latString[LAT_LENGTH];
  char lonString[LON_LENGTH];

  if (getJSONValue(msg, "Latitude", latString, sizeof(latString)) && getJSONValue(msg, "Longitude", lonString, sizeof(lonString)))
  {
    char    dateString[OTHER_LENGTH] = "";
    char    timeString[OTHER_LENGTH] = "";
    char    sogString[OTHER_LENGTH]  = "";
    char    cogString[OTHER_LENGTH]  = "";
    char    latHemisphere;
    char    lonHemisphere;
    double  latitude  = convert2kCoordinateToNMEA0183(latString, "NS", &latHemisphere);
    double  longitude = convert2kCoordinateToNMEA0183(lonString, "EW", &lonHemisphere);
    int64_t date;

    if (getJSONInt64(msg, "Date", &date))
    {
      time_t     t  = date * 86400;
      struct tm *tm = gmtime(&t);

      snprintf(dateString, STRSIZE(dateString), "%02d%02d%02d", tm->tm_mday, tm->tm_mon + 1, tm->tm_year % 100);
    }

    if (getJSONLookupName(msg, "Time", timeString, sizeof(timeString)))
    {
      logDebug("Got time string '%s'\n", timeString);
      removeChar(timeString, ':');
      logDebug("Cleaned time string '%s'\n", timeString);
    }

    if (g_sog_cog_ts >= getNow() - 1000)
    {
      snprintf(sogString, STRSIZE(sogString), "%.2f", SPEED_M_S_TO_KNOTS(g_sog));
      snprintf(cogString, STRSIZE(cogString), "%.1f", g_cog);
    }

    nmea0183CreateMessage(msg183, src, "GLL,%.4f,%c,%.4f,%c,%s,A", latitude, latHemisphere, longitude, lonHemisphere, timeString);
    nmea0183CreateMessage(msg183,
                          src,
                          "RMC,%s,A,%.4f,%c,%.4f,%c,%s,%s,%s,,,A",
                          timeString,
                          latitude,
                          latHemisphere,
                          longitude,
                          lonHemisphere,
                          sogString,
                          cogString,
                          dateString);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, %r15
movl %esi, %ebx
movq %rdi, %r14
leaq 0x4b7b(%rip), %rsi      # 0x9199
leaq 0xb0(%rsp), %rdx
pushq $0x10
popq %rcx
movq %r15, %rdi
callq 0x7415
testb %al, %al
je 0x486c
leaq 0x4b62(%rip), %rsi      # 0x91a2
leaq 0xa0(%rsp), %rdx
pushq $0x10
popq %rcx
movq %r15, %rdi
callq 0x7415
testb %al, %al
je 0x486c
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
andl $0x0, 0x90(%rsp)
movaps %xmm0, 0x20(%rsp)
andl $0x0, 0x30(%rsp)
movaps %xmm0, 0x60(%rsp)
andl $0x0, 0x70(%rsp)
movaps %xmm0, 0x40(%rsp)
andl $0x0, 0x50(%rsp)
leaq 0x4b19(%rip), %rsi      # 0x91ac
leaq 0xb0(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x487e
movsd %xmm0, 0x18(%rsp)
leaq 0x4afd(%rip), %rsi      # 0x91af
leaq 0xa0(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x487e
movsd %xmm0, 0x10(%rsp)
leaq 0x4b66(%rip), %rsi      # 0x9237
leaq 0x38(%rsp), %rdx
movq %r15, %rdi
callq 0x77fd
testb %al, %al
je 0x472a
imulq $0x15180, 0x38(%rsp), %rax # imm = 0x15180
leaq 0xc0(%rsp), %rdi
movq %rax, (%rdi)
callq 0x22c0
movl 0xc(%rax), %ecx
movl 0x10(%rax), %r8d
incl %r8d
movl 0x14(%rax), %eax
pushq $0x64
popq %rsi
cltd
idivl %esi
movl %edx, %r9d
leaq 0x4a9a(%rip), %rdx      # 0x91b2
leaq 0x80(%rsp), %rdi
pushq $0x13
popq %rsi
xorl %eax, %eax
callq 0x2120
leaq 0x4b0f(%rip), %rsi      # 0x9240
leaq 0x20(%rsp), %r12
pushq $0x14
popq %rcx
movq %r15, %rdi
movq %r12, %rdx
callq 0x7684
testb %al, %al
je 0x478e
leaq 0x4a70(%rip), %rdi      # 0x91bf
movq %r12, %rsi
xorl %eax, %eax
callq 0x6d78
movq %r12, %rax
movb (%rax), %cl
testb %cl, %cl
je 0x4776
movb %cl, (%r12)
xorl %edx, %edx
cmpb $0x3a, %cl
setne %dl
addq %rdx, %r12
incq %rax
jmp 0x475c
movb $0x0, (%r12)
leaq 0x4a53(%rip), %rdi      # 0x91d5
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x6d78
movq 0x20a4beb(%rip), %r15   # 0x20a9380
callq 0x6b84
addq $-0x3e8, %rax           # imm = 0xFC18
cmpq %rax, %r15
jb 0x47ed
movsd 0x20a4bc3(%rip), %xmm0  # 0x20a9370
mulsd 0x48ab(%rip), %xmm0     # 0x9060
leaq 0x4a33(%rip), %rdx      # 0x91ef
leaq 0x60(%rsp), %rdi
pushq $0x13
popq %r15
movq %r15, %rsi
movb $0x1, %al
callq 0x2120
movsd 0x20a4ba1(%rip), %xmm0  # 0x20a9378
leaq 0x4fde(%rip), %rdx      # 0x97bc
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
movb $0x1, %al
callq 0x2120
movsbl 0xf(%rsp), %ebp
movsbl 0xe(%rsp), %r15d
leaq 0x49f5(%rip), %rdx      # 0x91f4
leaq 0x20(%rsp), %r12
movq %r14, %rdi
movl %ebx, %esi
movsd 0x18(%rsp), %xmm0
movl %ebp, %ecx
movsd 0x10(%rsp), %xmm1
movl %r15d, %r8d
movq %r12, %r9
movb $0x2, %al
callq 0x61b4
subq $0x8, %rsp
leaq 0x88(%rsp), %r10
leaq 0x48(%rsp), %r11
leaq 0x68(%rsp), %r13
leaq 0x49cc(%rip), %rdx      # 0x920d
movq %r14, %rdi
movl %ebx, %esi
movq %r12, %rcx
movsd 0x20(%rsp), %xmm0
movl %ebp, %r8d
movsd 0x18(%rsp), %xmm1
movl %r15d, %r9d
movb $0x2, %al
pushq %r10
pushq %r11
pushq %r13
callq 0x61b4
addq $0x20, %rsp
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq