// File: /workspace/github_cpp_makefile_star2_O2/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 0x20bf55(%rip), %rax    # 0x2f7238
movl (%rax), %eax
movl %eax, -0x78(%rbp)
leaq 0x20bf45(%rip), %rax    # 0x2f7234
movl (%rax), %eax
movl %eax, -0x74(%rbp)
xorl %eax, %eax
testl %edi, %edi
sete %al
leaq 0x6f962(%rip), %rbx     # 0x15ac64
movl %eax, (%rbx)
leaq 0x1175c5(%rip), %rax    # 0x2028d0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0xeb357
cmpl $0x0, 0x3539f5(%rip)    # 0x43ed10
setne %al
movl %eax, -0x40(%rbp)
cmpl $0x0, 0x3539ec(%rip)    # 0x43ed14
setne %al
movl %eax, -0x38(%rbp)
cmpl $0x0, 0x3539e3(%rip)    # 0x43ed18
setne %al
movl %eax, -0x34(%rbp)
cmpl $0x0, 0x3539da(%rip)    # 0x43ed1c
setne %al
movl %eax, -0x3c(%rbp)
pushq $0x4
popq %rdi
movl $0x44d, %esi            # imm = 0x44D
callq 0x104b9
jmp 0xeb373
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x40(%rbp)
leaq 0x13b7be(%rip), %rax    # 0x226b38
movq (%rax), %rax
xorl %r12d, %r12d
movq %rax, -0xb8(%rbp)
testq %rax, %rax
setne %r14b
leaq 0x13b7f3(%rip), %rax    # 0x226b88
movq (%rax), %rax
xorl %r13d, %r13d
movq %rax, -0xb0(%rbp)
testq %rax, %rax
setne %r15b
leaq 0x13b828(%rip), %rax    # 0x226bd8
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
leaq 0x13b867(%rip), %rax    # 0x226c28
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
pushq $0x1
popq %rdi
movl $0x44e, %esi            # imm = 0x44E
callq 0x104b9
andl $0x0, (%rbx)
leaq 0x119fbe(%rip), %rcx    # 0x2053a0
leaq 0x11749b(%rip), %rax    # 0x202884
movslq (%rax), %rax
imulq (%rcx), %rax
leaq 0x119fd9(%rip), %rcx    # 0x2053d0
movslq (%rcx), %rcx
cqto
idivq %rcx
movq %rax, -0xe0(%rbp)
leaq 0x119f8b(%rip), %rax    # 0x205398
cmpq $0x0, (%rax)
je 0xeb8cf
movb %r14b, %r12b
movl %r12d, -0x70(%rbp)
movb %r15b, %r13b
leaq 0x119e40(%rip), %rax    # 0x205268
movq (%rax), %r14
leaq 0x13b8ce(%rip), %rax    # 0x226d00
movsd (%rax), %xmm0
movaps %xmm0, -0x90(%rbp)
leaq 0x13b8c4(%rip), %rax    # 0x226d08
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0x13b8bc(%rip), %rax    # 0x226d10
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
leaq 0x13b8b4(%rip), %rax    # 0x226d18
movsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq 0x119eac(%rip), %rax    # 0x205320
movq (%rax), %rax
movq %rax, -0xd8(%rbp)
pushq $0x1
popq %rcx
xorl %r12d, %r12d
movl %r13d, -0x6c(%rbp)
leaq 0x119f09(%rip), %r15    # 0x205398
movq %rcx, %rax
xorl %edx, %edx
movl $0x2710, %esi           # imm = 0x2710
divq %rsi
movq %rax, %rbx
movq %rcx, -0xe8(%rbp)
movq %rcx, %rax
xorl %edx, %edx
movl $0x1388, %ecx           # imm = 0x1388
divq %rcx
cmpq %r12, -0xd8(%rbp)
je 0xeb8b0
movq %rax, %r13
leaq -0x198(%rbp), %rdi
movq %r14, %rsi
callq 0xf9c7
movq (%r15), %rax
testq %rax, %rax
je 0xeb511
movsd -0x188(%rbp), %xmm0
movsd -0x180(%rbp), %xmm4
movsd -0x138(%rbp), %xmm3
movsd -0x130(%rbp), %xmm2
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
divsd %xmm1, %xmm4
divsd %xmm1, %xmm3
divsd %xmm1, %xmm2
jmp 0xeb521
xorpd %xmm3, %xmm3
xorpd %xmm2, %xmm2
xorpd %xmm4, %xmm4
xorpd %xmm0, %xmm0
leaq 0x1173a8(%rip), %rax    # 0x2028d0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0xeb788
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 -0x90(%rbp), %xmm1
addsd 0x7b7e(%rip), %xmm1     # 0xf30f8
movapd %xmm1, -0x90(%rbp)
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
movsd -0x150(%rbp), %xmm1
movsd %xmm1, -0x68(%rbp)
setae %al
andb -0x40(%rbp), %al
cmpb $0x1, %al
movsd %xmm3, -0x48(%rbp)
jne 0xeb5c2
xorl %edi, %edi
movsd %xmm4, -0x98(%rbp)
callq 0xc696a
movsd -0x98(%rbp), %xmm4
movsd -0x48(%rbp), %xmm3
movsd -0x60(%rbp), %xmm0
addsd 0x7b29(%rip), %xmm0     # 0xf30f8
movsd %xmm0, -0x60(%rbp)
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
setae %al
andb -0x38(%rbp), %al
cmpb $0x1, %al
jne 0xeb5f7
pushq $0x1
popq %rdi
movapd %xmm4, %xmm0
callq 0xc696a
movsd -0x48(%rbp), %xmm3
movsd -0x58(%rbp), %xmm0
addsd 0x7af4(%rip), %xmm0     # 0xf30f8
movsd %xmm0, -0x58(%rbp)
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
setae %al
andb -0x34(%rbp), %al
cmpb $0x1, %al
jne 0xeb627
pushq $0x2
popq %rdi
movapd %xmm3, %xmm0
callq 0xc696a
movsd -0x50(%rbp), %xmm0
addsd 0x7ac4(%rip), %xmm0     # 0xf30f8
movsd %xmm0, -0x50(%rbp)
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
setae %al
andb -0x3c(%rbp), %al
cmpb $0x1, %al
movsd -0x30(%rbp), %xmm0
jne 0xeb658
pushq $0x3
popq %rdi
callq 0xc696a
cvtsi2sdq (%r15), %xmm1
cmpq $0x0, -0xb8(%rbp)
movsd %xmm1, -0x30(%rbp)
je 0xeb693
xorpd %xmm0, %xmm0
ucomisd -0x90(%rbp), %xmm0
jb 0xeb693
movsd -0xc0(%rbp), %xmm0
divsd %xmm1, %xmm0
pushq $0x1
popq %rdi
callq 0xea2e5
movsd -0x30(%rbp), %xmm1
cmpq $0x0, -0xb0(%rbp)
je 0xeb6c1
xorpd %xmm0, %xmm0
ucomisd -0x60(%rbp), %xmm0
jb 0xeb6c1
movsd -0xc8(%rbp), %xmm0
divsd %xmm1, %xmm0
pushq $0x1
popq %rdi
callq 0xea737
movsd -0x30(%rbp), %xmm1
cmpq $0x0, -0xa8(%rbp)
je 0xeb6ef
xorpd %xmm0, %xmm0
ucomisd -0x58(%rbp), %xmm0
jb 0xeb6ef
movsd -0xd0(%rbp), %xmm0
divsd %xmm1, %xmm0
pushq $0x1
popq %rdi
callq 0xea915
movsd -0x30(%rbp), %xmm1
cmpq $0x0, -0xa0(%rbp)
je 0xeb715
xorpd %xmm0, %xmm0
ucomisd -0x50(%rbp), %xmm0
jb 0xeb715
movsd -0x68(%rbp), %xmm0
divsd %xmm1, %xmm0
pushq $0x1
popq %rdi
callq 0xeaafa
movapd -0x90(%rbp), %xmm2
movapd %xmm2, %xmm0
xorpd %xmm3, %xmm3
cmplesd %xmm3, %xmm0
leaq 0x13b5cf(%rip), %rax    # 0x226d00
movsd (%rax), %xmm1
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movapd %xmm0, -0x90(%rbp)
ucomisd %xmm0, %xmm3
jb 0xeb81c
leaq 0x13b5b6(%rip), %rax    # 0x226d10
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
leaq 0x13b59e(%rip), %rax    # 0x226d08
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0x13b59e(%rip), %rax    # 0x226d18
movsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0xeb81c
leaq 0x20b031(%rip), %rax    # 0x2f67c0
movq %r13, -0x30(%rbp)
movq %rbx, %r13
movq %r14, %rbx
movq %rax, %r14
movsd (%rax), %xmm1
movsd %xmm1, -0x48(%rbp)
leaq 0x20b00c(%rip), %r15    # 0x2f67b8
movsd (%r15), %xmm1
movsd %xmm1, -0x68(%rbp)
movsd %xmm0, (%r15)
movsd %xmm4, (%rax)
leaq 0x20ba72(%rip), %rcx    # 0x2f7238
movl -0x70(%rbp), %eax
movl %eax, (%rcx)
leaq 0x20ba62(%rip), %rcx    # 0x2f7234
movl -0x6c(%rbp), %eax
movl %eax, (%rcx)
pushq $0x1
popq %rdi
callq 0x6da12
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%r14)
movq %rbx, %r14
movq %r13, %rbx
movq -0x30(%rbp), %r13
movl -0x78(%rbp), %eax
leaq 0x20ba31(%rip), %rcx    # 0x2f7238
movl %eax, (%rcx)
leaq 0x119b88(%rip), %r15    # 0x205398
movl -0x74(%rbp), %eax
leaq 0x20ba1a(%rip), %rcx    # 0x2f7234
movl %eax, (%rcx)
imulq $0x1388, %r13, %rax     # imm = 0x1388
decq %rax
cmpq %r12, %rax
jne 0xeb833
pushq $0x1e
popq %rdi
callq 0x1bdb5
imulq $0x2710, %rbx, %rax     # imm = 0x2710
cmpq %r12, %rax
jne 0xeb87f
leaq 0x23a9da(%rip), %rbx    # 0x326220
movq %rbx, %rdi
leaq 0x3070e(%rip), %rsi     # 0x11bf5e
movq %r12, %rdx
xorl %eax, %eax
callq 0x9060
leaq 0x11702f(%rip), %rax    # 0x202890
movl (%rax), %edi
addl $0x6, %edi
leaq 0x11701f(%rip), %rax    # 0x20288c
movl (%rax), %esi
pushq $0xb
popq %rdx
movq %rbx, %rcx
callq 0xe2d2
callq 0xaa05
incq %r12
cmpq -0xe0(%rbp), %r12
jge 0xeb8b0
incq %r14
leaq 0x119a8b(%rip), %rax    # 0x205320
cmpq (%rax), %r14
movl $0x0, %eax
cmovgeq %rax, %r14
movq -0xe8(%rbp), %rcx
incq %rcx
jmp 0xeb48f
leaq 0x117019(%rip), %rax    # 0x2028d0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0xeb8c5
callq 0xc6cd3
callq 0xc7144
callq 0xf426
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq