// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathmsc.cpp
// Function: reload_adev_queue(int)
void reload_adev_queue(int reset_phase)
{
long i;
long counter;
long max_count;
struct PLOT_Q q;
int dump_size;
int have_cha_tie, have_chb_tie, have_chc_tie, have_chd_tie;
double cha_tie, chb_tie, chc_tie, chd_tie;
int have_cha_ofs, have_chb_ofs, have_chc_ofs, have_chd_ofs;
double cha_ofs, chb_ofs, chc_ofs, chd_ofs;
double old_cha_ofs, old_chb_ofs, old_chc_ofs, old_chd_ofs;
double cha_tick, chb_tick, chc_tick, chd_tick;
OFS_SIZE old_pps_offset, old_osc_offset;
int old_have_pps_offset, old_have_osc_offset;
long pcount;

   have_cha_tie = have_chb_tie = have_chc_tie = have_chd_tie = 0;
   have_cha_ofs = have_chb_ofs = have_chc_ofs = have_chd_ofs = 0;

   old_have_pps_offset = have_pps_offset;  // receiver derived adev related values
   old_have_osc_offset = have_osc_offset;

   if(reset_phase) dont_reset_phase = 0;
   else            dont_reset_phase = 1;
   if(rcvr_type == TICC_RCVR) {
      if(mtie_q_count[CHA_MTIE]) have_cha_tie = 1;
      if(mtie_q_count[CHB_MTIE]) have_chb_tie = 1;
      if(mtie_q_count[CHC_MTIE]) have_chc_tie = 1;
      if(mtie_q_count[CHD_MTIE]) have_chd_tie = 1;
      reset_queues(RESET_MTIE_Q, 1101);
   }

   if(pps_adev_q_count) have_cha_ofs = 1;
   if(osc_adev_q_count) have_chb_ofs = 1;
   if(chc_adev_q_count) have_chc_ofs = 1;
   if(chd_adev_q_count) have_chd_ofs = 1;


   reset_queues(RESET_ADEV_Q, 1102);   // clear the adev queue
   dont_reset_phase = 0;
////   pause_data = 1;

   max_count = view_interval * (long) PLOT_WIDTH;
   max_count /= (long) plot_mag;
   counter = 0;

   dump_size = 'p';
   if(dump_size == 'p') i = plot_q_col0;  // reloading from the displayed plot area
   else                 i = plot_q_out;   // reloading from the full queue

   if(queue_interval == 0) return;

   cha_tick = pps_adev_period; //  / (double) queue_interval;
   chb_tick = osc_adev_period; //  / (double) queue_interval;
   chc_tick = chc_adev_period; //  / (double) queue_interval;
   chd_tick = chd_adev_period; //  / (double) queue_interval;

   pcount = plot_q_size;
   while(pcount) {
      --pcount;
      q = get_plot_q(i);

      old_cha_ofs = pps_phase;
      old_chb_ofs = osc_phase;
      old_chc_ofs = chc_phase;
      old_chd_ofs = chd_phase;
      old_osc_offset = osc_offset;
      old_pps_offset = pps_offset;

      cha_ofs = cha_tie = 0.0;
      chb_ofs = chb_tie = 0.0;
      chc_ofs = chc_tie = 0.0;
      chd_ofs = chd_tie = 0.0;

      if(queue_interval) {
         cha_ofs = cha_tie = (OFS_SIZE) q.data[PPS] / (OFS_SIZE) queue_interval;
         chb_ofs = chb_tie = (OFS_SIZE) q.data[OSC] / (OFS_SIZE) queue_interval;
         chc_ofs = chc_tie = (OFS_SIZE) q.data[CHC] / (OFS_SIZE) queue_interval;
         chd_ofs = chd_tie = (OFS_SIZE) q.data[CHD] / (OFS_SIZE) queue_interval;
      }

      if(rcvr_type == TICC_RCVR) {  // MTIE data
         --cha_tick;
         --chb_tick;
         --chc_tick;
         --chd_tick;

         if(have_cha_tie && (cha_tick <= 0.0)) add_mtie_point(CHA_MTIE, cha_tie); 
         if(have_chb_tie && (chb_tick <= 0.0)) add_mtie_point(CHB_MTIE, chb_tie); 
         if(have_chc_tie && (chc_tick <= 0.0)) add_mtie_point(CHC_MTIE, chc_tie); 
         if(have_chd_tie && (chd_tick <= 0.0)) add_mtie_point(CHD_MTIE, chd_tie);

         cha_ofs = (OFS_SIZE) q.data[ONE] / (OFS_SIZE) queue_interval;
         chb_ofs = (OFS_SIZE) q.data[TWO] / (OFS_SIZE) queue_interval;
         chc_ofs = (OFS_SIZE) q.data[THREE] / (OFS_SIZE) queue_interval;
         chd_ofs = (OFS_SIZE) q.data[FOUR] / (OFS_SIZE) queue_interval;

         if(have_cha_ofs && (cha_tick <= 0.0)) add_pps_adev_point(cha_ofs, 1);   // adev values
         if(have_chb_ofs && (chb_tick <= 0.0)) add_osc_adev_point(chb_ofs, 1); 
         if(have_chc_ofs && (chc_tick <= 0.0)) add_chc_adev_point(chc_ofs, 1); 
         if(have_chd_ofs && (chd_tick <= 0.0)) add_chd_adev_point(chd_ofs, 1);  

         if(cha_tick <= 0.0) cha_tick = pps_adev_period; // / (double) queue_interval;
         if(cha_tick <= 0.0) chb_tick = osc_adev_period; // / (double) queue_interval;
         if(cha_tick <= 0.0) chc_tick = chc_adev_period; // / (double) queue_interval;
         if(cha_tick <= 0.0) chd_tick = chd_adev_period; // / (double) queue_interval;
      }
      else {  // adevs from receiver data or external TICC
         pps_offset = cha_ofs;
         osc_offset = chb_ofs;
         have_pps_offset = have_cha_ofs;
         have_osc_offset = have_chb_ofs;

         add_rcvr_adev_point(1);

         pps_offset = old_pps_offset;
         osc_offset = old_osc_offset;
         have_pps_offset = old_have_pps_offset;
         have_osc_offset = old_have_osc_offset;
      }

      ++counter;
      if((counter % LOG_GPS_CHECK) == 0) {   // keep serial data from overruning
         get_pending_gps(30);  //!!!! possible recursion
      }
//    if((counter % 1000L) == 1L) {
      if((counter % LOG_SCREEN_RFSH) == 1L) {
         sprintf(out, "Line %ld", counter-1L);
         vidstr(PLOT_TEXT_ROW+4+2, PLOT_TEXT_COL, PROMPT_COLOR, out);
         refresh_page();
      }

      if(dump_size == 'p') {  // reloading from the displayed plot area
         if(counter >= max_count) break;
      }
      if(++i >= plot_q_size) i = 0;  // queue pointer wrapped
   }

   if(rcvr_type == TICC_RCVR) {
      find_global_max();
   }

   force_adev_redraw(11);
   redraw_screen();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
leaq 0x20c233(%rip), %rax    # 0x30d238
movl (%rax), %eax
movl %eax, -0x68(%rbp)
leaq 0x20c223(%rip), %rax    # 0x30d234
movl (%rax), %eax
movl %eax, -0x64(%rbp)
xorl %eax, %eax
testl %edi, %edi
sete %al
leaq 0x6fc40(%rip), %rbx     # 0x170c64
movl %eax, (%rbx)
leaq 0x1178a3(%rip), %rax    # 0x2188d0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0x10107b
cmpl $0x0, 0x353db3(%rip)    # 0x454df0
setne %al
movl %eax, -0x48(%rbp)
cmpl $0x0, 0x353daa(%rip)    # 0x454df4
setne %al
movl %eax, -0x40(%rbp)
cmpl $0x0, 0x353da1(%rip)    # 0x454df8
setne %al
movl %eax, -0x3c(%rbp)
cmpl $0x0, 0x353d98(%rip)    # 0x454dfc
setne %al
movl %eax, -0x44(%rbp)
movl $0x4, %edi
movl $0x44d, %esi            # imm = 0x44D
callq 0x10c56
jmp 0x101097
movl $0x0, -0x44(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x48(%rbp)
leaq 0x13ba9a(%rip), %rax    # 0x23cb38
movq (%rax), %rax
movl $0x0, -0x38(%rbp)
movq %rax, -0xb8(%rbp)
testq %rax, %rax
setne %r14b
leaq 0x13bacb(%rip), %rax    # 0x23cb88
movq (%rax), %rax
movl $0x0, -0x34(%rbp)
movq %rax, -0xb0(%rbp)
testq %rax, %rax
setne %r15b
leaq 0x13bafc(%rip), %rax    # 0x23cbd8
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
leaq 0x13bb3b(%rip), %rax    # 0x23cc28
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
movl $0x1, %edi
movl $0x44e, %esi            # imm = 0x44E
callq 0x10c56
movl $0x0, (%rbx)
leaq 0x11a28d(%rip), %rcx    # 0x21b3a0
leaq 0x11776a(%rip), %rax    # 0x218884
movslq (%rax), %rax
imulq (%rcx), %rax
leaq 0x11a2a8(%rip), %rcx    # 0x21b3d0
movslq (%rcx), %rcx
cqto
idivq %rcx
movq %rax, %rbx
leaq 0x11a25e(%rip), %rax    # 0x21b398
cmpq $0x0, (%rax)
je 0x101688
leaq 0x11a1d5(%rip), %rax    # 0x21b320
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
testq %rax, %rax
je 0x10160b
movl -0x38(%rbp), %eax
movb %r14b, %al
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
movb %r15b, %al
movl %eax, -0x34(%rbp)
leaq 0x13bba1(%rip), %rax    # 0x23cd18
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0x13bb89(%rip), %rax    # 0x23cd10
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
leaq 0x13bb71(%rip), %rax    # 0x23cd08
movsd (%rax), %xmm0
movaps %xmm0, -0x90(%rbp)
leaq 0x13bb57(%rip), %rax    # 0x23cd00
movsd (%rax), %xmm0
movapd %xmm0, -0x80(%rbp)
leaq 0x11a0af(%rip), %rax    # 0x21b268
movq (%rax), %r14
cmpq $0x2, %rbx
movl $0x1, %eax
cmovlq %rax, %rbx
decq %rbx
xorl %r12d, %r12d
movq %rax, -0xe8(%rbp)
movabsq $0x346dc5d63886594b, %rcx # imm = 0x346DC5D63886594B
mulq %rcx
movq %rdx, %r13
leaq -0x198(%rbp), %rdi
movq %r14, %rsi
callq 0x10141
leaq 0x11a19c(%rip), %rax    # 0x21b398
movq (%rax), %rax
xorpd %xmm3, %xmm3
xorpd %xmm2, %xmm2
xorpd %xmm4, %xmm4
xorpd %xmm0, %xmm0
testq %rax, %rax
je 0x10124c
movsd -0x188(%rbp), %xmm0
movsd -0x180(%rbp), %xmm4
movsd -0x138(%rbp), %xmm3
movsd -0x130(%rbp), %xmm2
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
divsd %xmm1, %xmm4
divsd %xmm1, %xmm3
divsd %xmm1, %xmm2
leaq 0x11767d(%rip), %rax    # 0x2188d0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0x1014e6
movsd %xmm2, -0x30(%rbp)
movsd -0x168(%rbp), %xmm1
movsd %xmm1, -0xc0(%rbp)
movsd -0x160(%rbp), %xmm1
movsd %xmm1, -0xc8(%rbp)
movsd -0x158(%rbp), %xmm1
movsd %xmm1, -0xd0(%rbp)
movapd -0x80(%rbp), %xmm1
addsd 0x7e56(%rip), %xmm1     # 0x1090f8
movapd %xmm1, -0x80(%rbp)
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
movsd -0x150(%rbp), %xmm1
movsd %xmm1, -0xd8(%rbp)
setae %al
andb -0x48(%rbp), %al
cmpb $0x1, %al
movsd %xmm3, -0x50(%rbp)
jne 0x1012ea
xorl %edi, %edi
movsd %xmm4, -0x98(%rbp)
callq 0xd7c7d
movsd -0x98(%rbp), %xmm4
movsd -0x50(%rbp), %xmm3
movapd -0x90(%rbp), %xmm0
addsd 0x7dfe(%rip), %xmm0     # 0x1090f8
movapd %xmm0, -0x90(%rbp)
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
setae %al
andb -0x40(%rbp), %al
cmpb $0x1, %al
jne 0x101327
movl $0x1, %edi
movapd %xmm4, %xmm0
callq 0xd7c7d
movsd -0x50(%rbp), %xmm3
movsd -0x58(%rbp), %xmm0
addsd 0x7dc4(%rip), %xmm0     # 0x1090f8
movsd %xmm0, -0x58(%rbp)
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
setae %al
andb -0x3c(%rbp), %al
cmpb $0x1, %al
jne 0x101359
movl $0x2, %edi
movapd %xmm3, %xmm0
callq 0xd7c7d
movsd -0x60(%rbp), %xmm0
addsd 0x7d92(%rip), %xmm0     # 0x1090f8
movsd %xmm0, -0x60(%rbp)
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
setae %al
andb -0x44(%rbp), %al
cmpb $0x1, %al
movsd -0x30(%rbp), %xmm0
jne 0x10138c
movl $0x3, %edi
callq 0xd7c7d
leaq 0x11a005(%rip), %rax    # 0x21b398
xorps %xmm1, %xmm1
cvtsi2sdq (%rax), %xmm1
cmpq $0x0, -0xb8(%rbp)
movsd %xmm1, -0x30(%rbp)
je 0x1013d0
xorpd %xmm0, %xmm0
ucomisd -0x80(%rbp), %xmm0
jb 0x1013d0
movsd -0xc0(%rbp), %xmm0
divsd %xmm1, %xmm0
movl $0x1, %edi
callq 0xffd2b
movsd -0x30(%rbp), %xmm1
cmpq $0x0, -0xb0(%rbp)
je 0x101403
xorpd %xmm0, %xmm0
ucomisd -0x90(%rbp), %xmm0
jb 0x101403
movsd -0xc8(%rbp), %xmm0
divsd %xmm1, %xmm0
movl $0x1, %edi
callq 0x1002ad
movsd -0x30(%rbp), %xmm1
cmpq $0x0, -0xa8(%rbp)
je 0x101433
xorpd %xmm0, %xmm0
ucomisd -0x58(%rbp), %xmm0
jb 0x101433
movsd -0xd0(%rbp), %xmm0
divsd %xmm1, %xmm0
movl $0x1, %edi
callq 0x1004e3
movsd -0x30(%rbp), %xmm1
cmpq $0x0, -0xa0(%rbp)
je 0x10145e
xorpd %xmm0, %xmm0
ucomisd -0x60(%rbp), %xmm0
jb 0x10145e
movsd -0xd8(%rbp), %xmm0
divsd %xmm1, %xmm0
movl $0x1, %edi
callq 0x100745
movapd -0x80(%rbp), %xmm2
movapd %xmm2, %xmm0
xorpd %xmm3, %xmm3
cmplesd %xmm3, %xmm0
leaq 0x13b889(%rip), %rax    # 0x23cd00
movsd (%rax), %xmm1
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
ucomisd %xmm0, %xmm3
leaq 0x13b876(%rip), %rax    # 0x23cd08
movsd (%rax), %xmm1
jb 0x1014a8
leaq 0x13b871(%rip), %rax    # 0x23cd10
movsd (%rax), %xmm2
movsd %xmm2, -0x58(%rbp)
movapd %xmm0, -0x80(%rbp)
cmplesd 0x7c62(%rip), %xmm0     # 0x109118
andpd %xmm0, %xmm1
andnpd -0x90(%rbp), %xmm0
orpd %xmm1, %xmm0
movapd %xmm0, -0x90(%rbp)
jb 0x101564
leaq 0x13b83d(%rip), %rax    # 0x23cd18
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x101564
leaq 0x20b2d3(%rip), %rcx    # 0x30c7c0
movsd (%rcx), %xmm1
movsd %xmm1, -0x30(%rbp)
leaq 0x20b2bb(%rip), %r15    # 0x30c7b8
movsd (%r15), %xmm1
movsd %xmm1, -0x50(%rbp)
movsd %xmm0, (%r15)
movsd %xmm4, (%rcx)
leaq 0x20bd21(%rip), %rcx    # 0x30d238
movl -0x38(%rbp), %eax
movl %eax, (%rcx)
leaq 0x20bd11(%rip), %rcx    # 0x30d234
movl -0x34(%rbp), %eax
movl %eax, (%rcx)
movl $0x1, %edi
callq 0x78195
movsd -0x50(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x30(%rbp), %xmm0
leaq 0x20b278(%rip), %rax    # 0x30c7c0
movsd %xmm0, (%rax)
movl -0x68(%rbp), %eax
leaq 0x20bce2(%rip), %rcx    # 0x30d238
movl %eax, (%rcx)
movl -0x64(%rbp), %eax
leaq 0x20bcd2(%rip), %rcx    # 0x30d234
movl %eax, (%rcx)
movq %r13, %rax
shrq $0xa, %rax
imulq $0x1388, %rax, %rax     # imm = 0x1388
decq %rax
cmpq %r12, %rax
jne 0x101584
movl $0x1e, %edi
callq 0x1cca5
shrq $0xb, %r13
imulq $0x2710, %r13, %rax     # imm = 0x2710
cmpq %r12, %rax
jne 0x1015d6
leaq 0x23ac85(%rip), %r15    # 0x33c220
movq %r15, %rdi
leaq 0x309a9(%rip), %rsi     # 0x131f4e
movq %r12, %rdx
xorl %eax, %eax
callq 0x9060
leaq 0x1172da(%rip), %rax    # 0x218890
movl (%rax), %edi
addl $0x6, %edi
leaq 0x1172ca(%rip), %rax    # 0x21888c
movl (%rax), %esi
movl $0xb, %edx
movq %r15, %rcx
callq 0xe7d0
callq 0xab5f
cmpq %r12, %rbx
movq -0xe8(%rbp), %rax
je 0x10160b
incq %r12
incq %r14
leaq 0x119d31(%rip), %rcx    # 0x21b320
cmpq (%rcx), %r14
movl $0x0, %ecx
cmovgeq %rcx, %r14
incq %rax
cmpq %r12, -0xe0(%rbp)
jne 0x1011cf
leaq 0x1172be(%rip), %rax    # 0x2188d0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0x101620
callq 0xd801e
leaq 0x13d8b5(%rip), %rax    # 0x23eedc
movb $0x0, (%rax)
leaq 0x13b51f(%rip), %rax    # 0x23cb50
movl $0xa, %ecx
movl %ecx, (%rax)
leaq 0x13b561(%rip), %rax    # 0x23cba0
movl %ecx, (%rax)
leaq 0x13b5a8(%rip), %rax    # 0x23cbf0
movl %ecx, (%rax)
leaq 0x13b5e7(%rip), %rax    # 0x23cc38
movl %ecx, (%rax)
leaq 0x13b632(%rip), %rax    # 0x23cc8c
xorl %ecx, %ecx
movl %ecx, (%rax)
leaq 0x117157(%rip), %rax    # 0x2187bc
movl %ecx, (%rax)
leaq 0x117152(%rip), %rax    # 0x2187c0
movl %ecx, (%rax)
leaq 0x121f99(%rip), %rax    # 0x223610
movl (%rax), %edi
movl $0x1, %esi
callq 0x103663
callq 0xfb1a
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq