// File: jkingan[P]ladyheather/heathgps.cpp
// Function: maidenhead_square(double, double)
char *maidenhead_square(double Lat, double Long)
{
static char mls[16];
int i;
int Ext;
Ext = 2;

   // calculate the Maidenhead grid square
   //
   // Based on code by Yves Goergen, http://unclassified.software/source/maidenheadlocator
   // which was based upon code by Dirk Koopman, G1TLH

   Lat = Lat * 180.0 / PI;
   Long = Long * 180.0 / PI;

   i = 0;
   mls[i] = 0;

   Lat += 90.0;
   Long += 180.0;

   mls[i++] = (char) ('A' + (int) (Long / 20.0));
   mls[i++] = (char) ('A' + (int) (Lat / 10.0));

   Long = fmod(Long, 20.0);
   if(Long < 0.0) Long += 20.0;
   Lat = fmod(Lat, 10.0);
   if(Lat < 0.0) Lat += 10.0;

   mls[i++] = (char) ('0' + (int)(Long / 2.0));
   mls[i++] = (char) ('0' + (int)(Lat / 1.0));
   Long = fmod(Long, 2.0);
   if(Long < 0.0) Long += 2.0;
   Lat = fmod(Lat, 1.0);
   if(Lat < 0.0) Lat += 1.0;

   mls[i++] = (char) ('a' + (int)(Long * 12.0));
   mls[i++] = (char) ('a' + (int)(Lat * 24.0));
   Long = fmod(Long, 1.0 / 12.0);
   if(Long < 0) Long += 1.0/12.0;
   Lat = fmod(Lat, 1.0 / 24.0);
   if(Lat < 0.0) Lat += 1.0/24.0;
   mls[i] = 0;

   if(Ext >= 1) {
      mls[i++] = ' ';
      mls[i++] = (char) ('0' + (int)(Long * 120.0));
      mls[i++] = (char) ('0' + (int)(Lat * 240.0));
      Long = fmod(Long, 1.0/120.0);
      if(Long < 0.0) Long += 1.0 / 120.0;
      Lat = fmod(Lat, 1.0 / 240.0);
      if(Lat < 0.0) Lat += 1.0 / 240.0;
      mls[i] = 0;
   }

   if(Ext >= 2) {
      mls[i++] = ' ';
      mls[i++] = (char) ('A' + (int)(Long * 120.0 * 24.0));
      mls[i++] = (char) ('A' + (int)(Lat * 240.0 * 24.0));
      Long = fmod(Long, 1.0 / 120.0 / 24.0);
      if(Long < 0) Long += 1.0 / 120.0 / 24.0;
      Lat = fmod(Lat, 1.0 / 240.0 / 24.0);
      if(Lat < 0) Lat += 1.0 / 240.0 / 24.0;
      mls[i] = 0;
   }

   return &mls[0];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movsd %xmm0, -0x8(%rbp)
movsd %xmm1, -0x10(%rbp)
movl $0x2, -0x18(%rbp)
movsd 0x7b7e7(%rip), %xmm0    # 0x16f078
mulsd -0x8(%rbp), %xmm0
movsd 0x7dd2a(%rip), %xmm1    # 0x1715c8
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
movsd 0x7b7c9(%rip), %xmm0    # 0x16f078
mulsd -0x10(%rbp), %xmm0
movsd 0x7dd0c(%rip), %xmm1    # 0x1715c8
divsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x2e1e79(%rip), %rax    # 0x3d5750
movb $0x0, (%rax,%rcx)
movsd 0x7b7a5(%rip), %xmm0    # 0x16f088
addsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd 0x7b783(%rip), %xmm0    # 0x16f078
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x7b7bc(%rip), %xmm1    # 0x16f0c8
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
addl $0x41, %eax
movb %al, %dl
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %eax, %rcx
leaq 0x2e1e22(%rip), %rax    # 0x3d5750
movb %dl, (%rax,%rcx)
movsd -0x8(%rbp), %xmm0
movsd 0x7b782(%rip), %xmm1    # 0x16f0c0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
addl $0x41, %eax
movb %al, %dl
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %eax, %rcx
leaq 0x2e1df0(%rip), %rax    # 0x3d5750
movb %dl, (%rax,%rcx)
movsd -0x10(%rbp), %xmm0
movsd 0x7b758(%rip), %xmm1    # 0x16f0c8
callq 0x94d0
movsd %xmm0, -0x10(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x10(%rbp), %xmm0
jbe 0xf3996
movsd 0x7b73c(%rip), %xmm0    # 0x16f0c8
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x8(%rbp), %xmm0
movsd 0x7b71d(%rip), %xmm1    # 0x16f0c0
callq 0x94d0
movsd %xmm0, -0x8(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x8(%rbp), %xmm0
jbe 0xf39c9
movsd 0x7b701(%rip), %xmm0    # 0x16f0c0
addsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x7b77a(%rip), %xmm1    # 0x16f150
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
addl $0x30, %eax
movb %al, %dl
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %eax, %rcx
leaq 0x2e1d58(%rip), %rax    # 0x3d5750
movb %dl, (%rax,%rcx)
movsd -0x8(%rbp), %xmm0
movsd 0x7b660(%rip), %xmm1    # 0x16f068
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
addl $0x30, %eax
movb %al, %dl
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %eax, %rcx
leaq 0x2e1d26(%rip), %rax    # 0x3d5750
movb %dl, (%rax,%rcx)
movsd -0x10(%rbp), %xmm0
movsd 0x7b716(%rip), %xmm1    # 0x16f150
callq 0x94d0
movsd %xmm0, -0x10(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x10(%rbp), %xmm0
jbe 0xf3a60
movsd 0x7b6fa(%rip), %xmm0    # 0x16f150
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x8(%rbp), %xmm0
movsd 0x7b5fb(%rip), %xmm1    # 0x16f068
callq 0x94d0
movsd %xmm0, -0x8(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x8(%rbp), %xmm0
jbe 0xf3a93
movsd 0x7b5df(%rip), %xmm0    # 0x16f068
addsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd 0x8f6b5(%rip), %xmm0    # 0x183150
mulsd -0x10(%rbp), %xmm0
cvttsd2si %xmm0, %eax
addl $0x61, %eax
movb %al, %dl
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %eax, %rcx
leaq 0x2e1c92(%rip), %rax    # 0x3d5750
movb %dl, (%rax,%rcx)
movsd 0x7b56f(%rip), %xmm0    # 0x16f038
mulsd -0x8(%rbp), %xmm0
cvttsd2si %xmm0, %eax
addl $0x61, %eax
movb %al, %dl
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %eax, %rcx
leaq 0x2e1c64(%rip), %rax    # 0x3d5750
movb %dl, (%rax,%rcx)
movsd -0x10(%rbp), %xmm0
movsd 0x8f64c(%rip), %xmm1    # 0x183148
callq 0x94d0
movsd %xmm0, -0x10(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x10(%rbp), %xmm0
jbe 0xf3b22
movsd 0x8f630(%rip), %xmm0    # 0x183148
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x8(%rbp), %xmm0
movsd 0x8f629(%rip), %xmm1    # 0x183158
callq 0x94d0
movsd %xmm0, -0x8(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x8(%rbp), %xmm0
jbe 0xf3b55
movsd 0x8f60d(%rip), %xmm0    # 0x183158
addsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x2e1bf0(%rip), %rax    # 0x3d5750
movb $0x0, (%rax,%rcx)
cmpl $0x1, -0x18(%rbp)
jl 0xf3c58
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %eax, %rcx
leaq 0x2e1bcd(%rip), %rax    # 0x3d5750
movb $0x20, (%rax,%rcx)
movsd 0x7db21(%rip), %xmm0    # 0x1716b0
mulsd -0x10(%rbp), %xmm0
cvttsd2si %xmm0, %eax
addl $0x30, %eax
movb %al, %dl
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %eax, %rcx
leaq 0x2e1b9e(%rip), %rax    # 0x3d5750
movb %dl, (%rax,%rcx)
movsd 0x8f5ab(%rip), %xmm0    # 0x183168
mulsd -0x8(%rbp), %xmm0
cvttsd2si %xmm0, %eax
addl $0x30, %eax
movb %al, %dl
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %eax, %rcx
leaq 0x2e1b70(%rip), %rax    # 0x3d5750
movb %dl, (%rax,%rcx)
movsd -0x10(%rbp), %xmm0
movsd 0x8f570(%rip), %xmm1    # 0x183160
callq 0x94d0
movsd %xmm0, -0x10(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x10(%rbp), %xmm0
jbe 0xf3c16
movsd 0x8f554(%rip), %xmm0    # 0x183160
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x8(%rbp), %xmm0
movsd 0x8f54d(%rip), %xmm1    # 0x183170
callq 0x94d0
movsd %xmm0, -0x8(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x8(%rbp), %xmm0
jbe 0xf3c49
movsd 0x8f531(%rip), %xmm0    # 0x183170
addsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x2e1afc(%rip), %rax    # 0x3d5750
movb $0x0, (%rax,%rcx)
cmpl $0x2, -0x18(%rbp)
jl 0xf3d64
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %eax, %rcx
leaq 0x2e1ad9(%rip), %rax    # 0x3d5750
movb $0x20, (%rax,%rcx)
movsd 0x7da2d(%rip), %xmm0    # 0x1716b0
mulsd -0x10(%rbp), %xmm0
movsd 0x7b3a8(%rip), %xmm1    # 0x16f038
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
addl $0x41, %eax
movb %al, %dl
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %eax, %rcx
leaq 0x2e1a9e(%rip), %rax    # 0x3d5750
movb %dl, (%rax,%rcx)
movsd 0x8f4ab(%rip), %xmm0    # 0x183168
mulsd -0x8(%rbp), %xmm0
movsd 0x7b36e(%rip), %xmm1    # 0x16f038
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
addl $0x41, %eax
movb %al, %dl
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %eax, %rcx
leaq 0x2e1a64(%rip), %rax    # 0x3d5750
movb %dl, (%rax,%rcx)
movsd -0x10(%rbp), %xmm0
movsd 0x8f47c(%rip), %xmm1    # 0x183178
callq 0x94d0
movsd %xmm0, -0x10(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x10(%rbp), %xmm0
jbe 0xf3d22
movsd 0x8f460(%rip), %xmm0    # 0x183178
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x8(%rbp), %xmm0
movsd 0x8f451(%rip), %xmm1    # 0x183180
callq 0x94d0
movsd %xmm0, -0x8(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x8(%rbp), %xmm0
jbe 0xf3d55
movsd 0x8f435(%rip), %xmm0    # 0x183180
addsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x2e19f0(%rip), %rax    # 0x3d5750
movb $0x0, (%rax,%rcx)
leaq 0x2e19e5(%rip), %rax    # 0x3d5750
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)