// File: jkingan[P]ladyheather/heathgps.cpp
// Function: calc_mgrs_square(int, int, int)
void calc_mgrs_square(int set, int row, int col) 
{
char *l1, *l2;

   //
   // Retrieve the Square Identification (two-character letter code), for the
   // given row, column and set identifier (set refers to the zone set:
   // zones 1-6 have a unique set of square identifiers; these identifiers are
   // repeated for zones 7-12, etc.)
   // See p. 10 of the "United States National Grid" white paper for a diagram
   // of the zone sets.
   // 

   if((set < 0) || (row < 0) || (row > 19) || (col < 0) || (col > 7)) {
      strcpy(mgrs_square, "??");
      return;
   }

   // handle case of last row
   if(row == 0) row = 19;
   else         row -= 1;

   // handle case of last column
   if(col == 0)  col = 7;
   else col -= 1;

   set = (set % 6);
   if(set == 0) set = 6;

   switch (set) {
      case 1:
          l1 = "ABCDEFGH";              // column ids
          l2 = "ABCDEFGHJKLMNPQRSTUV";  // row ids
          break;

      case 2:
          l1 = "JKLMNPQR";
          l2 = "FGHJKLMNPQRSTUVABCDE";
          break;

      case 3:
          l1 = "STUVWXYZ";
          l2 = "ABCDEFGHJKLMNPQRSTUV";
          break;

      case 4:
          l1 = "ABCDEFGH";
          l2 = "FGHJKLMNPQRSTUVABCDE";
          break;

      case 5:
          l1 = "JKLMNPQR";
          l2 = "ABCDEFGHJKLMNPQRSTUV";
          break;

      case 6:
          l1 = "STUVWXYZ";
          l2 = "FGHJKLMNPQRSTUVABCDE";
          break;

      default:
          l1 = "????????";
          l2 = "????????????????????";
          break;
   }

   mgrs_square[0] = l1[col];
   mgrs_square[1] = l2[row];
   mgrs_square[2] = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
cmpl $0x0, -0x4(%rbp)
jl 0xf430f
cmpl $0x0, -0x8(%rbp)
jl 0xf430f
cmpl $0x13, -0x8(%rbp)
jg 0xf430f
cmpl $0x0, -0xc(%rbp)
jl 0xf430f
cmpl $0x7, -0xc(%rbp)
jle 0xf4327
leaq 0x2e148a(%rip), %rdi    # 0x3d57a0
leaq 0x96352(%rip), %rsi     # 0x18a66f
callq 0x9350
jmp 0xf446c
cmpl $0x0, -0x8(%rbp)
jne 0xf4336
movl $0x13, -0x8(%rbp)
jmp 0xf433f
movl -0x8(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x8(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0xf434e
movl $0x7, -0xc(%rbp)
jmp 0xf4357
movl -0xc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xc(%rbp)
movl -0x4(%rbp), %eax
movl $0x6, %ecx
cltd
idivl %ecx
movl %edx, -0x4(%rbp)
cmpl $0x0, -0x4(%rbp)
jne 0xf4372
movl $0x6, -0x4(%rbp)
movl -0x4(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0x5, %eax
ja 0xf442d
movq -0x28(%rbp), %rax
leaq 0x8f05f(%rip), %rcx     # 0x1833f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x96277(%rip), %rax     # 0x18a618
movq %rax, -0x18(%rbp)
leaq 0x96275(%rip), %rax     # 0x18a621
movq %rax, -0x20(%rbp)
jmp 0xf4443
leaq 0x9627a(%rip), %rax     # 0x18a636
movq %rax, -0x18(%rbp)
leaq 0x96278(%rip), %rax     # 0x18a63f
movq %rax, -0x20(%rbp)
jmp 0xf4443
leaq 0x96280(%rip), %rax     # 0x18a654
movq %rax, -0x18(%rbp)
leaq 0x96242(%rip), %rax     # 0x18a621
movq %rax, -0x20(%rbp)
jmp 0xf4443
leaq 0x9622c(%rip), %rax     # 0x18a618
movq %rax, -0x18(%rbp)
leaq 0x96248(%rip), %rax     # 0x18a63f
movq %rax, -0x20(%rbp)
jmp 0xf4443
leaq 0x96232(%rip), %rax     # 0x18a636
movq %rax, -0x18(%rbp)
leaq 0x96212(%rip), %rax     # 0x18a621
movq %rax, -0x20(%rbp)
jmp 0xf4443
leaq 0x96238(%rip), %rax     # 0x18a654
movq %rax, -0x18(%rbp)
leaq 0x96218(%rip), %rax     # 0x18a63f
movq %rax, -0x20(%rbp)
jmp 0xf4443
leaq 0x96235(%rip), %rax     # 0x18a669
movq %rax, -0x18(%rbp)
leaq 0x9621e(%rip), %rax     # 0x18a65d
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movslq -0xc(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, 0x2e134c(%rip)     # 0x3d57a0
movq -0x20(%rbp), %rax
movslq -0x8(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, 0x2e133c(%rip)     # 0x3d57a1
movb $0x0, 0x2e1336(%rip)    # 0x3d57a2
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)