// File: /workspace/github_c_makefile_star2_O1/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 $0x108, %rsp            # imm = 0x108
movq %rdx, %r15
movl %esi, %ebx
movq %rdi, %r14
leaq 0x5906(%rip), %rsi      # 0xa199
leaq 0xf0(%rsp), %rdx
movl $0x10, %ecx
movq %r15, %rdi
callq 0x7c81
testb %al, %al
je 0x4c04
leaq 0x58eb(%rip), %rsi      # 0xa1a2
leaq 0xe0(%rsp), %rdx
movl $0x10, %ecx
movq %r15, %rdi
callq 0x7c81
testb %al, %al
je 0x4c04
xorl %eax, %eax
movl %eax, 0xb0(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0xa0(%rsp)
movl %eax, 0x20(%rsp)
movapd %xmm0, 0x10(%rsp)
movl %eax, 0x90(%rsp)
movapd %xmm0, 0x80(%rsp)
movl %eax, 0x70(%rsp)
movapd %xmm0, 0x60(%rsp)
leaq 0xf0(%rsp), %rdi
xorl %esi, %esi
callq 0x20a0
movapd %xmm0, %xmm1
xorpd 0x5767(%rip), %xmm1     # 0xa090
movapd %xmm0, 0xd0(%rsp)
maxsd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
movapd %xmm1, %xmm0
callq 0x22e0
movsd %xmm0, 0x8(%rsp)
movapd 0x30(%rsp), %xmm1
subsd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
leaq 0xe0(%rsp), %rdi
xorl %esi, %esi
callq 0x20a0
movapd 0x571e(%rip), %xmm1     # 0xa090
xorpd %xmm0, %xmm1
movapd %xmm0, 0xc0(%rsp)
maxsd %xmm0, %xmm1
movapd %xmm1, 0x40(%rsp)
movapd %xmm1, %xmm0
callq 0x22e0
movsd %xmm0, (%rsp)
movapd 0x40(%rsp), %xmm1
subsd %xmm0, %xmm1
movapd %xmm1, 0x40(%rsp)
leaq 0x5883(%rip), %rsi      # 0xa231
leaq 0x58(%rsp), %rdx
movq %r15, %rdi
callq 0x807c
testb %al, %al
je 0x4a1b
imulq $0x15180, 0x58(%rsp), %rax # imm = 0x15180
leaq 0x100(%rsp), %rdi
movq %rax, (%rdi)
callq 0x22b0
movl 0xc(%rax), %ecx
movl 0x10(%rax), %r8d
incl %r8d
movslq 0x14(%rax), %r9
imulq $0x51eb851f, %r9, %rax  # imm = 0x51EB851F
movq %rax, %rdx
shrq $0x3f, %rdx
sarq $0x25, %rax
addl %edx, %eax
imull $0x64, %eax, %eax
subl %eax, %r9d
leaq 0x57a5(%rip), %rdx      # 0xa1ac
leaq 0xa0(%rsp), %rdi
movl $0x13, %esi
xorl %eax, %eax
callq 0x2120
movapd 0x30(%rsp), %xmm0
movsd 0x563f(%rip), %xmm2     # 0xa068
mulsd %xmm2, %xmm0
movapd %xmm0, 0x30(%rsp)
movsd 0x8(%rsp), %xmm0
movsd 0x562f(%rip), %xmm1     # 0xa070
mulsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movapd 0x40(%rsp), %xmm0
mulsd %xmm2, %xmm0
movapd %xmm0, 0x40(%rsp)
movsd (%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
leaq 0x57ca(%rip), %rsi      # 0xa23a
leaq 0x10(%rsp), %r12
movl $0x14, %ecx
movq %r15, %rdi
movq %r12, %rdx
callq 0x7eec
testb %al, %al
je 0x4adc
leaq 0x5729(%rip), %rdi      # 0xa1b9
movq %r12, %rsi
xorl %eax, %eax
callq 0x7549
movb 0x10(%rsp), %cl
testb %cl, %cl
je 0x4ac4
leaq 0x10(%rsp), %r12
leaq 0x11(%rsp), %rax
movb %cl, (%r12)
xorl %edx, %edx
cmpb $0x3a, %cl
setne %dl
addq %rdx, %r12
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x4aac
movb $0x0, (%r12)
leaq 0x56ff(%rip), %rdi      # 0xa1cf
leaq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x7549
movsd 0x8(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq 0x20a586b(%rip), %r15   # 0x20aa370
callq 0x7328
addq $-0x3e8, %rax           # imm = 0xFC18
cmpq %rax, %r15
jb 0x4b60
movsd 0x20a5843(%rip), %xmm0  # 0x20aa360
mulsd 0x5533(%rip), %xmm0     # 0xa058
leaq 0x56bd(%rip), %rdx      # 0xa1e9
leaq 0x80(%rsp), %rdi
movl $0x13, %esi
movb $0x1, %al
callq 0x2120
movsd 0x20a5820(%rip), %xmm0  # 0x20aa368
leaq 0x5c6d(%rip), %rdx      # 0xa7bc
leaq 0x60(%rsp), %rdi
movl $0x13, %esi
movb $0x1, %al
callq 0x2120
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomisd 0xd0(%rsp), %xmm0
seta %al
ucomisd 0xc0(%rsp), %xmm0
leal 0x4e(%rax,%rax,4), %ebp
movl $0x57, %eax
movl $0x45, %r15d
cmoval %eax, %r15d
leaq 0x5659(%rip), %rdx      # 0xa1ee
leaq 0x10(%rsp), %r12
movq %r14, %rdi
movl %ebx, %esi
movsd 0x8(%rsp), %xmm0
movl %ebp, %ecx
movsd (%rsp), %xmm1
movl %r15d, %r8d
movq %r12, %r9
movb $0x2, %al
callq 0x6798
subq $0x8, %rsp
leaq 0xa8(%rsp), %r10
leaq 0x68(%rsp), %r11
leaq 0x88(%rsp), %r13
leaq 0x562e(%rip), %rdx      # 0xa207
movq %r14, %rdi
movl %ebx, %esi
movq %r12, %rcx
movsd 0x10(%rsp), %xmm0
movl %ebp, %r8d
movsd 0x8(%rsp), %xmm1
movl %r15d, %r9d
movb $0x2, %al
pushq %r10
pushq %r11
pushq %r13
callq 0x6798
addq $0x20, %rsp
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq