// File: /workspace/github_cpp_makefile_star2_O1/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 0x25bbd5(%rip), %rax    # 0x30c79c
movl (%rax), %eax
leal -0x41(%rax), %ecx
cmpl $0x16, %ecx
ja 0xb0de4
movl $0x56901b, %edx         # imm = 0x56901B
btl %ecx, %edx
jae 0xb0de4
leaq 0x18e316(%rip), %rdx    # 0x23ef00
movl $0x0, (%rdx)
leaq 0x25bba9(%rip), %rsi    # 0x30c7a0
movl (%rsi), %esi
xorl %edi, %edi
testl %esi, %esi
sete %dil
leaq 0x6de38(%rip), %r8      # 0x11ea40
movsd (%r8,%rdi,8), %xmm0
xorl %r11d, %r11d
movl $0x1, %edi
leaq 0x18e393(%rip), %r8     # 0x23efb0
xorpd %xmm1, %xmm1
leaq 0x2c1a78(%rip), %r9     # 0x3726a0
leaq 0x2c1a79(%rip), %r13    # 0x3726a8
leaq 0x6ef56(%rip), %rbx     # 0x11fb8c
xorl %r14d, %r14d
movl %r11d, %r11d
imulq $0x348, %rdi, %r10      # imm = 0x348
leaq (%r8,%r10), %r15
cmpb $0x0, 0x1(%r8,%r10)
jne 0xb0c5a
cmpl $0x0, 0x1c(%r15)
je 0xb0dd4
incl %r14d
movl %r14d, (%rdx)
cmpl $0x16, %ecx
ja 0xb0c6f
movslq (%rbx,%rcx,4), %r10
addq %rbx, %r10
jmpq *%r10
xorps %xmm2, %xmm2
cvtsi2sd %edi, %xmm2
jmp 0xb0cdc
xorps %xmm2, %xmm2
cvtss2sd 0x238(%r15), %xmm2
jmp 0xb0cdc
xorps %xmm2, %xmm2
cvtsi2sdl 0x18(%r15), %xmm2
jmp 0xb0cdc
xorps %xmm2, %xmm2
cvtss2sd 0x208(%r15), %xmm2
jmp 0xb0cdc
movsd 0x38(%r15), %xmm2
jmp 0xb0cdc
xorps %xmm2, %xmm2
cvtss2sd 0x20(%r15), %xmm2
jmp 0xb0cdc
movsd 0x30(%r15), %xmm2
jmp 0xb0cdc
xorps %xmm2, %xmm2
cvtss2sd 0x20c(%r15), %xmm2
jmp 0xb0cdc
movsd 0x28(%r15), %xmm2
jmp 0xb0cdc
xorps %xmm2, %xmm2
cvtss2sd 0x1fc(%r15), %xmm2
cmpl $0x4d, %eax
je 0xb0cfe
movapd %xmm2, %xmm3
cmpeqsd %xmm1, %xmm3
movapd %xmm3, %xmm4
andpd %xmm0, %xmm4
andnpd %xmm2, %xmm3
orpd %xmm4, %xmm3
movapd %xmm3, %xmm2
testq %r11, %r11
je 0xb0d52
movslq %r11d, %r10
shlq $0x4, %r10
movsd -0x8(%r10,%r9), %xmm3
testl %esi, %esi
je 0xb0d68
ucomisd %xmm3, %xmm2
jae 0xb0d6e
testl %r11d, %r11d
jle 0xb0dd4
movq %r13, %r15
xorl %r12d, %r12d
movsd (%r15), %xmm3
testl %esi, %esi
je 0xb0d3b
ucomisd %xmm3, %xmm2
ja 0xb0d41
jmp 0xb0d88
ucomisd %xmm2, %xmm3
jbe 0xb0d88
incq %r12
addq $0x10, %r15
cmpq %r12, %r11
jne 0xb0d2a
jmp 0xb0dd4
movl %edi, 0x2c1948(%rip)    # 0x3726a0
movsd %xmm2, 0x2c1948(%rip)   # 0x3726a8
movl $0x1, %r11d
jmp 0xb0dd4
ucomisd %xmm2, %xmm3
jb 0xb0d1b
movslq %r11d, %r11
movq %r11, %r10
shlq $0x4, %r10
movl %edi, (%r10,%r9)
movsd %xmm2, 0x8(%r10,%r9)
incl %r11d
jmp 0xb0dd4
cmpl %r12d, %r11d
jle 0xb0dba
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 0xb0d9a
movl %edi, -0x8(%r15)
movsd %xmm2, (%r15)
incl %r11d
leaq 0x18e133(%rip), %rdx    # 0x23ef00
leaq 0x2c18d4(%rip), %r13    # 0x3726a8
incq %rdi
cmpq $0x3e8, %rdi            # imm = 0x3E8
jne 0xb0c39
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq