// File: /workspace/github_cpp_makefile_star2_O3/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 0x25b8cf(%rip), %rax    # 0x30c79c
movl (%rax), %eax
leal -0x41(%rax), %ecx
cmpl $0x16, %ecx
ja 0xb10d9
movl $0x56901b, %edx         # imm = 0x56901B
btl %ecx, %edx
jae 0xb10d9
leaq 0x18e010(%rip), %rdx    # 0x23ef00
movl $0x0, (%rdx)
leaq 0x25b8a3(%rip), %rsi    # 0x30c7a0
movl (%rsi), %esi
xorl %edi, %edi
testl %esi, %esi
sete %dil
leaq 0x6dbd2(%rip), %r8      # 0x11eae0
movsd (%r8,%rdi,8), %xmm0
xorl %r11d, %r11d
movl $0x1, %edi
leaq 0x18e08d(%rip), %r8     # 0x23efb0
xorpd %xmm1, %xmm1
leaq 0x2c1772(%rip), %r9     # 0x3726a0
leaq 0x2c1773(%rip), %r13    # 0x3726a8
leaq 0x6ed28(%rip), %rbx     # 0x11fc64
xorl %r14d, %r14d
movl %r11d, %r11d
imulq $0x348, %rdi, %r10      # imm = 0x348
leaq (%r8,%r10), %r15
cmpb $0x0, 0x1(%r8,%r10)
jne 0xb0f60
cmpl $0x0, 0x1c(%r15)
je 0xb10c9
incl %r14d
movl %r14d, (%rdx)
cmpl $0x16, %ecx
ja 0xb0f75
movslq (%rbx,%rcx,4), %r10
addq %rbx, %r10
jmpq *%r10
xorps %xmm2, %xmm2
cvtsi2sd %edi, %xmm2
jmp 0xb0fe2
xorps %xmm2, %xmm2
cvtss2sd 0x238(%r15), %xmm2
jmp 0xb0fe2
xorps %xmm2, %xmm2
cvtsi2sdl 0x18(%r15), %xmm2
jmp 0xb0ff3
xorps %xmm2, %xmm2
cvtss2sd 0x208(%r15), %xmm2
jmp 0xb0fe2
movsd 0x38(%r15), %xmm2
jmp 0xb0fe2
xorps %xmm2, %xmm2
cvtss2sd 0x20(%r15), %xmm2
jmp 0xb0fe2
movsd 0x30(%r15), %xmm2
jmp 0xb0fe2
xorps %xmm2, %xmm2
cvtss2sd 0x20c(%r15), %xmm2
jmp 0xb0fe2
movsd 0x28(%r15), %xmm2
jmp 0xb0fe2
xorps %xmm2, %xmm2
cvtss2sd 0x1fc(%r15), %xmm2
cmpl $0x4d, %eax
je 0xb0ff3
ucomisd %xmm1, %xmm2
jne 0xb0ff3
jp 0xb0ff3
movapd %xmm0, %xmm2
testq %r11, %r11
je 0xb1047
movslq %r11d, %r10
shlq $0x4, %r10
movsd -0x8(%r10,%r9), %xmm3
testl %esi, %esi
je 0xb105d
ucomisd %xmm3, %xmm2
jae 0xb1063
testl %r11d, %r11d
jle 0xb10c9
movq %r13, %r15
xorl %r12d, %r12d
movsd (%r15), %xmm3
testl %esi, %esi
je 0xb1030
ucomisd %xmm3, %xmm2
ja 0xb1036
jmp 0xb107d
ucomisd %xmm2, %xmm3
jbe 0xb107d
incq %r12
addq $0x10, %r15
cmpq %r12, %r11
jne 0xb101f
jmp 0xb10c9
movl %edi, 0x2c1653(%rip)    # 0x3726a0
movsd %xmm2, 0x2c1653(%rip)   # 0x3726a8
movl $0x1, %r11d
jmp 0xb10c9
ucomisd %xmm2, %xmm3
jb 0xb1010
movslq %r11d, %r11
movq %r11, %r10
shlq $0x4, %r10
movl %edi, (%r10,%r9)
movsd %xmm2, 0x8(%r10,%r9)
incl %r11d
jmp 0xb10c9
cmpl %r12d, %r11d
jle 0xb10af
movq %r11, %r13
shlq $0x4, %r13
addq %r9, %r13
movq %r11, %r10
decq %r10
movl -0x10(%r13), %edx
movl %edx, (%r13)
movsd -0x8(%r13), %xmm3
movsd %xmm3, 0x8(%r13)
addq $-0x10, %r13
cmpq %r12, %r10
jg 0xb108f
movl %edi, -0x8(%r15)
movsd %xmm2, (%r15)
incl %r11d
leaq 0x18de3e(%rip), %rdx    # 0x23ef00
leaq 0x2c15df(%rip), %r13    # 0x3726a8
incq %rdi
cmpq $0x3e8, %rdi            # imm = 0x3E8
jne 0xb0f3f
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq