// File: 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
leaq 0x27bb21(%rip), %rax    # 0x36b97c
cmpl $0x53, (%rax)
jne 0xefe65
jmp 0xefefd
leaq 0x27bb10(%rip), %rax    # 0x36b97c
cmpl $0x45, (%rax)
jne 0xefe76
jmp 0xefefb
leaq 0x27baff(%rip), %rax    # 0x36b97c
cmpl $0x41, (%rax)
jne 0xefe84
jmp 0xefef9
leaq 0x27baf1(%rip), %rax    # 0x36b97c
cmpl $0x44, (%rax)
jne 0xefe92
jmp 0xefef7
leaq 0x27bae3(%rip), %rax    # 0x36b97c
cmpl $0x50, (%rax)
jne 0xefea0
jmp 0xefef5
leaq 0x27bad5(%rip), %rax    # 0x36b97c
cmpl $0x57, (%rax)
jne 0xefeae
jmp 0xefef3
leaq 0x27bac7(%rip), %rax    # 0x36b97c
cmpl $0x52, (%rax)
jne 0xefebc
jmp 0xefef1
leaq 0x27bab9(%rip), %rax    # 0x36b97c
cmpl $0x42, (%rax)
jne 0xefeca
jmp 0xefeef
leaq 0x27baab(%rip), %rax    # 0x36b97c
cmpl $0x55, (%rax)
jne 0xefed8
jmp 0xefeed
leaq 0x27ba9d(%rip), %rax    # 0x36b97c
cmpl $0x4d, (%rax)
jne 0xefee6
jmp 0xefeeb
jmp 0xf042c
jmp 0xefeed
jmp 0xefeef
jmp 0xefef1
jmp 0xefef3
jmp 0xefef5
jmp 0xefef7
jmp 0xefef9
jmp 0xefefb
jmp 0xefefd
movl $0x0, -0x8(%rbp)
leaq 0x1ae1d5(%rip), %rax    # 0x29e0e0
movl $0x0, (%rax)
movl $0x1, -0x4(%rbp)
cmpl $0x3e7, -0x4(%rbp)      # imm = 0x3E7
jg 0xf042c
movslq -0x4(%rbp), %rcx
leaq 0x1ae260(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
cmpb $0x0, 0x1(%rax)
je 0xeff42
jmp 0xeff64
movslq -0x4(%rbp), %rcx
leaq 0x1ae243(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
cmpl $0x0, 0x1c(%rax)
jne 0xeff62
jmp 0xf041e
jmp 0xeff64
leaq 0x1ae175(%rip), %rax    # 0x29e0e0
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x1ae169(%rip), %rax    # 0x29e0e0
movl %ecx, (%rax)
leaq 0x27b9fc(%rip), %rax    # 0x36b97c
cmpl $0x53, (%rax)
jne 0xeffad
movslq -0x4(%rbp), %rcx
leaq 0x1ae200(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss 0x20(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xf017b
leaq 0x27b9c8(%rip), %rax    # 0x36b97c
cmpl $0x45, (%rax)
jne 0xeffe4
movslq -0x4(%rbp), %rcx
leaq 0x1ae1cc(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss 0x20c(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xf0179
leaq 0x27b991(%rip), %rax    # 0x36b97c
cmpl $0x41, (%rax)
jne 0xf001b
movslq -0x4(%rbp), %rcx
leaq 0x1ae195(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss 0x208(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xf0177
leaq 0x27b95a(%rip), %rax    # 0x36b97c
cmpl $0x42, (%rax)
jne 0xf0052
movslq -0x4(%rbp), %rcx
leaq 0x1ae15e(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss 0x238(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xf0175
leaq 0x27b923(%rip), %rax    # 0x36b97c
cmpl $0x50, (%rax)
jne 0xf0071
cvtsi2ssl -0x4(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xf0173
leaq 0x27b904(%rip), %rax    # 0x36b97c
cmpl $0x44, (%rax)
jne 0xf00a1
movslq -0x4(%rbp), %rcx
leaq 0x1ae108(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movsd 0x30(%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xf0171
leaq 0x27b8d4(%rip), %rax    # 0x36b97c
cmpl $0x57, (%rax)
jne 0xf00d1
movslq -0x4(%rbp), %rcx
leaq 0x1ae0d8(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xf016f
leaq 0x27b8a4(%rip), %rax    # 0x36b97c
cmpl $0x52, (%rax)
jne 0xf00fe
movslq -0x4(%rbp), %rcx
leaq 0x1ae0a8(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movsd 0x38(%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xf016d
leaq 0x27b877(%rip), %rax    # 0x36b97c
cmpl $0x55, (%rax)
jne 0xf0132
movslq -0x4(%rbp), %rcx
leaq 0x1ae07b(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss 0x1fc(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xf016b
leaq 0x27b843(%rip), %rax    # 0x36b97c
cmpl $0x4d, (%rax)
jne 0xf015f
movslq -0x4(%rbp), %rcx
leaq 0x1ae047(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
cvtsi2sdl 0x18(%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xf0169
cvtsi2sdl -0x4(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xf016b
jmp 0xf016d
jmp 0xf016f
jmp 0xf0171
jmp 0xf0173
jmp 0xf0175
jmp 0xf0177
jmp 0xf0179
jmp 0xf017b
leaq 0x27b7fa(%rip), %rax    # 0x36b97c
cmpl $0x4d, (%rax)
jne 0xf0189
jmp 0xf01c5
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xf01c3
jp 0xf01c3
leaq 0x27b7e0(%rip), %rax    # 0x36b980
cmpl $0x0, (%rax)
je 0xf01b4
movsd 0x92f3b(%rip), %xmm0    # 0x1830e8
movsd %xmm0, -0x18(%rbp)
jmp 0xf01c1
movsd 0x92f24(%rip), %xmm0    # 0x1830e0
movsd %xmm0, -0x18(%rbp)
jmp 0xf01c3
jmp 0xf01c5
cmpl $0x0, -0x8(%rbp)
jne 0xf020c
movl -0x4(%rbp), %ecx
movslq -0x8(%rbp), %rdx
leaq 0x2e16f7(%rip), %rax    # 0x3d18d0
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movsd -0x18(%rbp), %xmm0
movslq -0x8(%rbp), %rcx
leaq 0x2e16de(%rip), %rax    # 0x3d18d0
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xf041e
leaq 0x27b76d(%rip), %rax    # 0x36b980
cmpl $0x0, (%rax)
je 0xf027e
movsd -0x18(%rbp), %xmm0
movl -0x8(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x2e16a3(%rip), %rax    # 0x3d18d0
shlq $0x4, %rcx
addq %rcx, %rax
ucomisd 0x8(%rax), %xmm0
jb 0xf027c
movl -0x4(%rbp), %ecx
movslq -0x8(%rbp), %rdx
leaq 0x2e1687(%rip), %rax    # 0x3d18d0
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movsd -0x18(%rbp), %xmm0
movslq -0x8(%rbp), %rcx
leaq 0x2e166e(%rip), %rax    # 0x3d18d0
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xf041e
jmp 0xf02e8
movsd -0x18(%rbp), %xmm1
movl -0x8(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x2e163d(%rip), %rax    # 0x3d18d0
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0xf02e6
movl -0x4(%rbp), %ecx
movslq -0x8(%rbp), %rdx
leaq 0x2e161d(%rip), %rax    # 0x3d18d0
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movsd -0x18(%rbp), %xmm0
movslq -0x8(%rbp), %rcx
leaq 0x2e1604(%rip), %rax    # 0x3d18d0
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xf041e
jmp 0xf02e8
jmp 0xf02ea
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xf041c
leaq 0x27b67c(%rip), %rax    # 0x36b980
cmpl $0x0, (%rax)
je 0xf032e
movsd -0x18(%rbp), %xmm0
movslq -0xc(%rbp), %rcx
leaq 0x2e15b7(%rip), %rax    # 0x3d18d0
shlq $0x4, %rcx
addq %rcx, %rax
ucomisd 0x8(%rax), %xmm0
jbe 0xf032c
jmp 0xf040e
jmp 0xf0357
movsd -0x18(%rbp), %xmm1
movslq -0xc(%rbp), %rcx
leaq 0x2e1592(%rip), %rax    # 0x3d18d0
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xf0355
jmp 0xf040e
jmp 0xf0357
movl -0x8(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0xc(%rbp), %eax
jle 0xf03d0
movl -0x10(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x2e155b(%rip), %rax    # 0x3d18d0
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %ecx
movslq -0x10(%rbp), %rdx
leaq 0x2e1547(%rip), %rax    # 0x3d18d0
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x10(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x2e152e(%rip), %rax    # 0x3d18d0
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movslq -0x10(%rbp), %rcx
leaq 0x2e1517(%rip), %rax    # 0x3d18d0
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xf035d
movl -0x4(%rbp), %ecx
movslq -0xc(%rbp), %rdx
leaq 0x2e14f2(%rip), %rax    # 0x3d18d0
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movsd -0x18(%rbp), %xmm0
movslq -0xc(%rbp), %rcx
leaq 0x2e14d9(%rip), %rax    # 0x3d18d0
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xf041c
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xf02f1
jmp 0xf041e
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xeff18
popq %rbp
retq
nop