// File: /workspace/github_c_makefile_star2_O3/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 $0xe8, %rsp
movq %rdx, %r12
movl %esi, %ebx
movq %rdi, %r14
leaq 0x5956(%rip), %rsi      # 0xa199
leaq 0xd0(%rsp), %rdx
movl $0x10, %ecx
movq %r12, %rdi
callq 0x7c22
testb %al, %al
je 0x4b9d
leaq 0x593b(%rip), %rsi      # 0xa1a2
leaq 0xc0(%rsp), %rdx
movl $0x10, %ecx
movq %r12, %rdi
callq 0x7c22
testb %al, %al
je 0x4b9d
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 0xd0(%rsp), %rdi
xorl %esi, %esi
callq 0x20a0
movapd %xmm0, %xmm1
xorpd 0x57b7(%rip), %xmm1     # 0xa090
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x58c3(%rip), %rcx      # 0xa1ac
maxsd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
movsbl (%rax,%rcx), %ebp
movapd %xmm1, %xmm0
callq 0x22e0
movsd %xmm0, 0x8(%rsp)
movapd 0x30(%rsp), %xmm1
subsd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
leaq 0xc0(%rsp), %rdi
xorl %esi, %esi
callq 0x20a0
movapd 0x5763(%rip), %xmm1     # 0xa090
xorpd %xmm0, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x586e(%rip), %rcx      # 0xa1af
maxsd %xmm0, %xmm1
movapd %xmm1, 0x40(%rsp)
movsbl (%rax,%rcx), %r15d
movapd %xmm1, %xmm0
callq 0x22e0
movsd %xmm0, (%rsp)
movapd 0x40(%rsp), %xmm1
subsd %xmm0, %xmm1
movapd %xmm1, 0x40(%rsp)
leaq 0x58c2(%rip), %rsi      # 0xa237
leaq 0x58(%rsp), %rdx
movq %r12, %rdi
callq 0x8037
testb %al, %al
je 0x49e2
imulq $0x15180, 0x58(%rsp), %rax # imm = 0x15180
leaq 0xe0(%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 0x57e4(%rip), %rdx      # 0xa1b2
leaq 0xa0(%rsp), %rdi
movl $0x13, %esi
xorl %eax, %eax
callq 0x2120
movapd 0x30(%rsp), %xmm0
movsd 0x5680(%rip), %xmm2     # 0xa070
mulsd %xmm2, %xmm0
movapd %xmm0, 0x30(%rsp)
movsd 0x8(%rsp), %xmm0
movsd 0x5670(%rip), %xmm1     # 0xa078
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 0x5809(%rip), %rsi      # 0xa240
leaq 0x10(%rsp), %r13
movl $0x14, %ecx
movq %r12, %rdi
movq %r13, %rdx
callq 0x7ea7
testb %al, %al
je 0x4aa3
leaq 0x5768(%rip), %rdi      # 0xa1bf
movq %r13, %rsi
xorl %eax, %eax
callq 0x7509
movb 0x10(%rsp), %cl
testb %cl, %cl
je 0x4a8b
leaq 0x10(%rsp), %r13
leaq 0x11(%rsp), %rax
movb %cl, (%r13)
xorl %edx, %edx
cmpb $0x3a, %cl
setne %dl
addq %rdx, %r13
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x4a73
movb $0x0, (%r13)
leaq 0x573e(%rip), %rdi      # 0xa1d5
leaq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x7509
movsd 0x8(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq 0x20a58a4(%rip), %r12   # 0x20aa370
callq 0x72e8
addq $-0x3e8, %rax           # imm = 0xFC18
cmpq %rax, %r12
jb 0x4b27
movsd 0x20a587c(%rip), %xmm0  # 0x20aa360
mulsd 0x5574(%rip), %xmm0     # 0xa060
leaq 0x56fc(%rip), %rdx      # 0xa1ef
leaq 0x80(%rsp), %rdi
movl $0x13, %esi
movb $0x1, %al
callq 0x2120
movsd 0x20a5859(%rip), %xmm0  # 0x20aa368
leaq 0x5ca6(%rip), %rdx      # 0xa7bc
leaq 0x60(%rsp), %rdi
movl $0x13, %esi
movb $0x1, %al
callq 0x2120
leaq 0x56c6(%rip), %rdx      # 0xa1f4
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 0x6728
subq $0x8, %rsp
leaq 0xa8(%rsp), %r10
leaq 0x68(%rsp), %r11
leaq 0x88(%rsp), %r13
leaq 0x569b(%rip), %rdx      # 0xa20d
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 0x6728
addq $0x20, %rsp
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq