// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: sort_sat_table()
void sort_sat_table()
{
int i, j;
int k;
int m;
double val;

   // Creates a list of sat info values (sig levels, az, or el) sorted in 
   // in ascending ot descending order along with their PRNs.  This list 
   // can be used to display the sat info table columns in sorted order.

   if     (sort_by == SORT_SIGS) ;
   else if(sort_by == SORT_ELEV) ;
   else if(sort_by == SORT_AZ) ;
   else if(sort_by == SORT_DOPPLER) ;
   else if(sort_by == SORT_PRN) ;
   else if(sort_by == SORT_CARRIER) ;
   else if(sort_by == SORT_RANGE) ;
   else if(sort_by == SORT_BIAS) ;
   else if(sort_by == SORT_URA) ;
   else if(sort_by == SORT_STATE) ;
   else return;

   j = 0;

   track_count = 0;
   for(i=1; i<=MAX_PRN; i++) {
      if(sat[i].disabled) ; 
      else if(sat[i].level_msg == 0) continue;  // sat prn not tracked
      ++track_count;

      if     (sort_by == SORT_SIGS)    val = sat[i].sig_level;  // the sat's signal level
      else if(sort_by == SORT_ELEV)    val = sat[i].elevation;  // the sat's elevation
      else if(sort_by == SORT_AZ)      val = sat[i].azimuth;    // the sat's azimuth
      else if(sort_by == SORT_BIAS)    val = sat[i].sat_bias;   // the sat's clock bias 
      else if(sort_by == SORT_PRN)     val = (float) i;         // the sat's PRN
      else if(sort_by == SORT_DOPPLER) {
         val = sat[i].doppler;        // the sat's doppler
      }
      else if(sort_by == SORT_CARRIER) {
         val = sat[i].code_phase;     // the sat's carrier phase
      }
      else if(sort_by == SORT_RANGE) {
         val = sat[i].range;          // the sat's pseudorange
      }
      else if(sort_by == SORT_URA)   {
         val = sat[i].sv_accuracy;    // the sat's ura
      }
      else if(sort_by == SORT_STATE)   {
         val = (double) sat[i].state; // the sat's state
      }
      else val = (double) i;

      if(sort_by == SORT_STATE) ;
      else if(val == 0.0) {  // keep invalid vals at the end of the list
         if(sort_ascend) val = 10.0E20;
         else            val = (-10.0E20);
      }

      if(j == 0) {  // first entry
         sat_sort[j].prn = i;
         sat_sort[j].val = val;
         ++j;
         continue;
      }
      else if(sort_ascend) {  // sort in ascending order
         if(val >= sat_sort[j-1].val) {  // insert at end of list
            sat_sort[j].prn = i;
            sat_sort[j].val = val;
            ++j;
            continue;
         }
      }
      else {  // sort in descending order
         if(val <= sat_sort[j-1].val) {  // insert at end of list
            sat_sort[j].prn = i;
            sat_sort[j].val = val;
            ++j;
            continue;
         }
      }

      for(k=0; k<j; k++) {  // see where this value lies in the list so far
         if(sort_ascend) {
            if(val > sat_sort[k].val) continue;  // it's greater than the current value
         }
         else {
            if(val < sat_sort[k].val) continue;  // it's less than the current value
         }

         for(m=j; m>k; m--) {  // move lower value entries down one position
            sat_sort[m].prn = sat_sort[m-1].prn;
            sat_sort[m].val = sat_sort[m-1].val;
         }

         sat_sort[k].prn = i;    // insert new value in the list
         sat_sort[k].val = val;
         ++j;
         break;
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leaq 0x255b3d(%rip), %rax    # 0x2f679c
movl (%rax), %eax
leal -0x41(%rax), %ecx
cmpl $0x16, %ecx
ja 0xa0e5a
movl $0x56901b, %edx         # imm = 0x56901B
btl %ecx, %edx
jae 0xa0e5a
leaq 0x18827e(%rip), %rbx    # 0x228f00
andl $0x0, (%rbx)
leaq 0x255b14(%rip), %rdx    # 0x2f67a0
movl (%rdx), %esi
xorl %edx, %edx
testl %esi, %esi
sete %dl
leaq 0x67da4(%rip), %rdi     # 0x108a40
movsd (%rdi,%rdx,8), %xmm0
xorl %edi, %edi
movabsq $0x1, %r8
leaq 0x1882fc(%rip), %r9     # 0x228fb0
xorpd %xmm1, %xmm1
leaq 0x2bb9e1(%rip), %r11    # 0x35c6a0
leaq 0x68ee2(%rip), %r14     # 0x109ba8
xorl %r15d, %r15d
cmpq $0x3e8, %r8             # imm = 0x3E8
je 0xa0e5a
imulq $0x348, %r8, %r10       # imm = 0x348
leaq (%r9,%r10), %rdx
cmpb $0x0, 0x1(%r9,%r10)
jne 0xa0cf3
cmpl $0x0, 0x1c(%rdx)
je 0xa0e52
incl %edi
movl %edi, (%rbx)
cmpl $0x16, %ecx
ja 0xa0d06
movslq (%r14,%rcx,4), %r10
addq %r14, %r10
jmpq *%r10
cvtsi2sd %r8d, %xmm2
jmp 0xa0d56
cvtss2sd 0x238(%rdx), %xmm2
jmp 0xa0d56
cvtsi2sdl 0x18(%rdx), %xmm2
jmp 0xa0d67
cvtss2sd 0x208(%rdx), %xmm2
jmp 0xa0d56
movsd 0x38(%rdx), %xmm2
jmp 0xa0d56
cvtss2sd 0x20(%rdx), %xmm2
jmp 0xa0d56
movsd 0x30(%rdx), %xmm2
jmp 0xa0d56
cvtss2sd 0x20c(%rdx), %xmm2
jmp 0xa0d56
movsd 0x28(%rdx), %xmm2
jmp 0xa0d56
cvtss2sd 0x1fc(%rdx), %xmm2
cmpl $0x4d, %eax
je 0xa0d67
ucomisd %xmm1, %xmm2
jne 0xa0d67
jp 0xa0d67
movapd %xmm0, %xmm2
testl %r15d, %r15d
je 0xa0d97
movslq %r15d, %r13
movq %r13, %r12
shlq $0x4, %r12
movsd -0x8(%r12,%r11), %xmm3
testl %esi, %esi
je 0xa0db1
ucomisd %xmm3, %xmm2
jb 0xa0dbb
movl %r8d, (%r12,%r11)
movsd %xmm2, 0x8(%r12,%r11)
jmp 0xa0e4f
movl %r8d, 0x2bb902(%rip)    # 0x35c6a0
movsd %xmm2, 0x2bb902(%rip)   # 0x35c6a8
movl $0x1, %r15d
jmp 0xa0e52
ucomisd %xmm2, %xmm3
jae 0xa0e3d
movq %rax, %r14
movq %rbx, %rax
testl %r15d, %r15d
movl $0x0, %edx
cmovgl %r15d, %edx
leaq 0x2bb8d4(%rip), %rbx    # 0x35c6a8
xorl %r10d, %r10d
cmpq %r10, %rdx
je 0xa0e2e
movsd (%rbx), %xmm3
testl %esi, %esi
je 0xa0dec
ucomisd %xmm3, %xmm2
ja 0xa0df2
jmp 0xa0dfb
ucomisd %xmm2, %xmm3
jbe 0xa0dfb
incq %r10
addq $0x10, %rbx
jmp 0xa0dd7
addq %r11, %r12
cmpq %r10, %r13
jle 0xa0e23
decq %r13
movl -0x10(%r12), %edx
movl %edx, (%r12)
movsd -0x8(%r12), %xmm3
movsd %xmm3, 0x8(%r12)
addq $-0x10, %r12
jmp 0xa0dfe
movl %r8d, -0x8(%rbx)
movsd %xmm2, (%rbx)
incl %r15d
movq %rax, %rbx
movq %r14, %rax
leaq 0x68d6d(%rip), %r14     # 0x109ba8
jmp 0xa0e52
movslq %r15d, %rdx
shlq $0x4, %rdx
movl %r8d, (%rdx,%r11)
movsd %xmm2, 0x8(%rdx,%r11)
incl %r15d
incq %r8
jmp 0xa0cc9
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq