// File: /workspace/github_cpp_makefile_star2_O3/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 $0x168, %rsp            # imm = 0x168
leaq 0x20bbbe(%rip), %rax    # 0x30d238
movl (%rax), %eax
movl %eax, -0x70(%rbp)
leaq 0x20bbae(%rip), %rax    # 0x30d234
movl (%rax), %eax
movl %eax, -0x6c(%rbp)
xorl %eax, %eax
testl %edi, %edi
sete %al
leaq 0x6f5cb(%rip), %rbx     # 0x170c64
movl %eax, (%rbx)
leaq 0x11722e(%rip), %rax    # 0x2188d0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0x1016f0
cmpl $0x0, 0x35365e(%rip)    # 0x454d10
setne %al
movl %eax, -0x48(%rbp)
cmpl $0x0, 0x353655(%rip)    # 0x454d14
setne %al
movl %eax, -0x40(%rbp)
cmpl $0x0, 0x35364c(%rip)    # 0x454d18
setne %al
movl %eax, -0x3c(%rbp)
cmpl $0x0, 0x353643(%rip)    # 0x454d1c
setne %al
movl %eax, -0x44(%rbp)
movl $0x4, %edi
movl $0x44d, %esi            # imm = 0x44D
callq 0x10bd1
jmp 0x10170c
movl $0x0, -0x44(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x48(%rbp)
leaq 0x13b425(%rip), %rax    # 0x23cb38
movq (%rax), %rax
movl $0x0, -0x38(%rbp)
movq %rax, -0xa8(%rbp)
testq %rax, %rax
setne %r14b
leaq 0x13b456(%rip), %rax    # 0x23cb88
movq (%rax), %rax
movl $0x0, -0x34(%rbp)
movq %rax, -0xa0(%rbp)
testq %rax, %rax
setne %r15b
leaq 0x13b487(%rip), %rax    # 0x23cbd8
movq (%rax), %rax
movq %rax, -0x98(%rbp)
leaq 0x13b4c6(%rip), %rax    # 0x23cc28
movq (%rax), %rax
movq %rax, -0x90(%rbp)
movl $0x1, %edi
movl $0x44e, %esi            # imm = 0x44E
callq 0x10bd1
movl $0x0, (%rbx)
leaq 0x119c18(%rip), %rcx    # 0x21b3a0
leaq 0x1170f5(%rip), %rax    # 0x218884
movslq (%rax), %rax
imulq (%rcx), %rax
leaq 0x119c33(%rip), %rcx    # 0x21b3d0
movslq (%rcx), %rcx
cqto
idivq %rcx
movq %rax, %rbx
leaq 0x119be9(%rip), %rax    # 0x21b398
cmpq $0x0, (%rax)
je 0x101cd4
leaq 0x119b60(%rip), %rax    # 0x21b320
movq (%rax), %rax
movq %rax, -0xd0(%rbp)
testq %rax, %rax
je 0x101c57
movl -0x38(%rbp), %eax
movb %r14b, %al
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
movb %r15b, %al
movl %eax, -0x34(%rbp)
leaq 0x13b52c(%rip), %rax    # 0x23cd18
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
leaq 0x13b514(%rip), %rax    # 0x23cd10
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0x13b4fc(%rip), %rax    # 0x23cd08
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
leaq 0x13b4e4(%rip), %rax    # 0x23cd00
movsd (%rax), %xmm0
movapd %xmm0, -0x80(%rbp)
leaq 0x119a3c(%rip), %rax    # 0x21b268
movq (%rax), %r14
cmpq $0x2, %rbx
movl $0x1, %eax
cmovlq %rax, %rbx
decq %rbx
xorl %r12d, %r12d
movq %rax, -0xd8(%rbp)
movabsq $0x346dc5d63886594b, %rcx # imm = 0x346DC5D63886594B
mulq %rcx
movq %rdx, %r13
leaq -0x188(%rbp), %rdi
movq %r14, %rsi
callq 0x100be
leaq 0x119b29(%rip), %rax    # 0x21b398
movq (%rax), %rax
xorpd %xmm3, %xmm3
xorpd %xmm2, %xmm2
xorpd %xmm4, %xmm4
xorpd %xmm0, %xmm0
testq %rax, %rax
je 0x1018bf
movsd -0x178(%rbp), %xmm0
movsd -0x170(%rbp), %xmm4
movsd -0x128(%rbp), %xmm3
movsd -0x120(%rbp), %xmm2
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
divsd %xmm1, %xmm4
divsd %xmm1, %xmm3
divsd %xmm1, %xmm2
leaq 0x11700a(%rip), %rax    # 0x2188d0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0x101b32
movsd %xmm2, -0x30(%rbp)
movsd -0x158(%rbp), %xmm1
movsd %xmm1, -0xb0(%rbp)
movsd -0x150(%rbp), %xmm1
movsd %xmm1, -0xb8(%rbp)
movsd -0x148(%rbp), %xmm1
movsd %xmm1, -0xc0(%rbp)
movapd -0x80(%rbp), %xmm1
addsd 0x77e3(%rip), %xmm1     # 0x1090f8
movapd %xmm1, -0x80(%rbp)
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
movsd -0x140(%rbp), %xmm1
movsd %xmm1, -0xc8(%rbp)
setae %al
andb -0x48(%rbp), %al
cmpb $0x1, %al
movsd %xmm3, -0x50(%rbp)
jne 0x10195d
xorl %edi, %edi
movsd %xmm4, -0x88(%rbp)
callq 0xd83bd
movsd -0x88(%rbp), %xmm4
movsd -0x50(%rbp), %xmm3
movsd -0x58(%rbp), %xmm0
addsd 0x778e(%rip), %xmm0     # 0x1090f8
movsd %xmm0, -0x58(%rbp)
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
setae %al
andb -0x40(%rbp), %al
cmpb $0x1, %al
jne 0x101994
movl $0x1, %edi
movapd %xmm4, %xmm0
callq 0xd83bd
movsd -0x50(%rbp), %xmm3
movsd -0x60(%rbp), %xmm0
addsd 0x7757(%rip), %xmm0     # 0x1090f8
movsd %xmm0, -0x60(%rbp)
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
setae %al
andb -0x3c(%rbp), %al
cmpb $0x1, %al
jne 0x1019c6
movl $0x2, %edi
movapd %xmm3, %xmm0
callq 0xd83bd
movsd -0x68(%rbp), %xmm0
addsd 0x7725(%rip), %xmm0     # 0x1090f8
movsd %xmm0, -0x68(%rbp)
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
setae %al
andb -0x44(%rbp), %al
cmpb $0x1, %al
movsd -0x30(%rbp), %xmm0
jne 0x1019f9
movl $0x3, %edi
callq 0xd83bd
leaq 0x119998(%rip), %rax    # 0x21b398
xorps %xmm1, %xmm1
cvtsi2sdq (%rax), %xmm1
cmpq $0x0, -0xa8(%rbp)
movsd %xmm1, -0x30(%rbp)
je 0x101a3d
xorpd %xmm0, %xmm0
ucomisd -0x80(%rbp), %xmm0
jb 0x101a3d
movsd -0xb0(%rbp), %xmm0
divsd %xmm1, %xmm0
movl $0x1, %edi
callq 0x1003d6
movsd -0x30(%rbp), %xmm1
cmpq $0x0, -0xa0(%rbp)
je 0x101a6d
xorpd %xmm0, %xmm0
ucomisd -0x58(%rbp), %xmm0
jb 0x101a6d
movsd -0xb8(%rbp), %xmm0
divsd %xmm1, %xmm0
movl $0x1, %edi
callq 0x100950
movsd -0x30(%rbp), %xmm1
cmpq $0x0, -0x98(%rbp)
je 0x101a9d
xorpd %xmm0, %xmm0
ucomisd -0x60(%rbp), %xmm0
jb 0x101a9d
movsd -0xc0(%rbp), %xmm0
divsd %xmm1, %xmm0
movl $0x1, %edi
callq 0x100b7b
movsd -0x30(%rbp), %xmm1
cmpq $0x0, -0x90(%rbp)
je 0x101ac8
xorpd %xmm0, %xmm0
ucomisd -0x68(%rbp), %xmm0
jb 0x101ac8
movsd -0xc8(%rbp), %xmm0
divsd %xmm1, %xmm0
movl $0x1, %edi
callq 0x100dd1
movapd -0x80(%rbp), %xmm2
movapd %xmm2, %xmm0
xorpd %xmm3, %xmm3
cmplesd %xmm3, %xmm0
leaq 0x13b21f(%rip), %rax    # 0x23cd00
movsd (%rax), %xmm1
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movapd %xmm0, -0x80(%rbp)
ucomisd %xmm0, %xmm3
jb 0x101bb0
leaq 0x13b209(%rip), %rax    # 0x23cd10
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0x13b1f1(%rip), %rax    # 0x23cd08
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
leaq 0x13b1f1(%rip), %rax    # 0x23cd18
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x101bb0
leaq 0x20ac87(%rip), %rcx    # 0x30c7c0
movsd (%rcx), %xmm1
movsd %xmm1, -0x30(%rbp)
leaq 0x20ac6f(%rip), %r15    # 0x30c7b8
movsd (%r15), %xmm1
movsd %xmm1, -0x50(%rbp)
movsd %xmm0, (%r15)
movsd %xmm4, (%rcx)
leaq 0x20b6d5(%rip), %rcx    # 0x30d238
movl -0x38(%rbp), %eax
movl %eax, (%rcx)
leaq 0x20b6c5(%rip), %rcx    # 0x30d234
movl -0x34(%rbp), %eax
movl %eax, (%rcx)
movl $0x1, %edi
callq 0x77f10
movsd -0x50(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x30(%rbp), %xmm0
leaq 0x20ac2c(%rip), %rax    # 0x30c7c0
movsd %xmm0, (%rax)
movl -0x70(%rbp), %eax
leaq 0x20b696(%rip), %rcx    # 0x30d238
movl %eax, (%rcx)
movl -0x6c(%rbp), %eax
leaq 0x20b686(%rip), %rcx    # 0x30d234
movl %eax, (%rcx)
movq %r13, %rax
shrq $0xa, %rax
imulq $0x1388, %rax, %rax     # imm = 0x1388
decq %rax
cmpq %r12, %rax
jne 0x101bd0
movl $0x1e, %edi
callq 0x1cce4
shrq $0xb, %r13
imulq $0x2710, %r13, %rax     # imm = 0x2710
cmpq %r12, %rax
jne 0x101c22
leaq 0x23a639(%rip), %r15    # 0x33c220
movq %r15, %rdi
leaq 0x3044d(%rip), %rsi     # 0x13203e
movq %r12, %rdx
xorl %eax, %eax
callq 0x9060
leaq 0x116c8e(%rip), %rax    # 0x218890
movl (%rax), %edi
addl $0x6, %edi
leaq 0x116c7e(%rip), %rax    # 0x21888c
movl (%rax), %esi
movl $0xb, %edx
movq %r15, %rcx
callq 0xe787
callq 0xab54
cmpq %r12, %rbx
movq -0xd8(%rbp), %rax
je 0x101c57
incq %r12
incq %r14
leaq 0x1196e5(%rip), %rcx    # 0x21b320
cmpq (%rcx), %r14
movl $0x0, %ecx
cmovgeq %rcx, %r14
incq %rax
cmpq %r12, -0xd0(%rbp)
jne 0x101842
leaq 0x116c72(%rip), %rax    # 0x2188d0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0x101c6c
callq 0xd872b
leaq 0x13d269(%rip), %rax    # 0x23eedc
movb $0x0, (%rax)
leaq 0x13aed3(%rip), %rax    # 0x23cb50
movl $0xa, %ecx
movl %ecx, (%rax)
leaq 0x13af15(%rip), %rax    # 0x23cba0
movl %ecx, (%rax)
leaq 0x13af5c(%rip), %rax    # 0x23cbf0
movl %ecx, (%rax)
leaq 0x13af9b(%rip), %rax    # 0x23cc38
movl %ecx, (%rax)
leaq 0x13afe6(%rip), %rax    # 0x23cc8c
xorl %ecx, %ecx
movl %ecx, (%rax)
leaq 0x116b0b(%rip), %rax    # 0x2187bc
movl %ecx, (%rax)
leaq 0x116b06(%rip), %rax    # 0x2187c0
movl %ecx, (%rax)
leaq 0x12194d(%rip), %rax    # 0x223610
movl (%rax), %edi
movl $0x1, %esi
callq 0x103d0b
callq 0xfa97
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq