// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: add_chc_adev_point(double, int)
void add_chc_adev_point(double val, int phase)
{
   if(chc_adev_period <= 0.0) return;
   if(adev_q_allocated == 0) {
      alloc_adev();
   }

   if(phase) chc_phase = val;
   else      chc_phase += val;  // convert time interval to phase

   if(chc_adev_q_count == 0) {
      chc_resid = 0.0;
      chc_adev_jd0 = jd_utc;
   }
   else chc_resid = (float) ((val-last_chc_resid));
   last_chc_resid = val;

   calc_resids(CHC, chc_phase, chc_adev_period);

   if((have_chc_base == 0) && (subtract_base_value == 1) && (chc_adev_q_count <= 1)) {  // aaaaa
      chc_base_value = chc_phase;
      have_chc_base = 1;
   }

   if(chc_adev_q) chc_adev_q[chc_adev_q_in] = (OFS_SIZE) (chc_phase - chc_base_value);

   if(++chc_adev_q_in >= adev_q_size) {  // queue has wrapped
      chc_adev_q_in = 0;
   }

   if(chc_adev_q_in == chc_adev_q_out) {  // queue is full
      ++chc_adev_q_out;               // drop oldest entry from the queue
      chc_adev_q_overflow += 1.0;
      incr_chc_overflow();        // tweek counts in the adev bins

      // Once the adev queue fills up,  the adev results begin to get stale
      // because the incremental adevs are based upon all the points seen in
      // the past.  To keep the adev numbers fresh, we preiodically reset
      // the incremental adev bins.  This causes the adevs to be
      // recalculated from just the values stored in the queue.
      if(chc_adev_q_overflow >= adev_q_size) {  // !!!! wrap >= was >0 
         if(keep_adevs_fresh) {
            reset_chc_bins();              
            adev_freshened = 1;
         }
      }
   }
   else ++chc_adev_q_count;   // keep count of number of entries in the adev queue
   if(chc_adev_q_out >= adev_q_size) chc_adev_q_out = 0;

   // incrementally update the adev bin values with the new data point
   do_incr_chc_adevs();    // recalculate all the adevs from the queued data

   if(adev_freshened) {
      show_adev_info(3);
      adev_freshened = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movsd %xmm0, -0x8(%rbp)
movl %edi, -0xc(%rbp)
xorps %xmm0, %xmm0
leaq 0x139fd6(%rip), %rax    # 0x29bef0
ucomisd (%rax), %xmm0
jb 0x161f25
jmp 0x16219c
leaq 0x139f94(%rip), %rax    # 0x29bec0
cmpl $0x0, (%rax)
jne 0x161f36
callq 0x14040
cmpl $0x0, -0xc(%rbp)
je 0x161f4e
movsd -0x8(%rbp), %xmm0
leaq 0x209ab0(%rip), %rax    # 0x36b9f8
movsd %xmm0, (%rax)
jmp 0x161f69
movsd -0x8(%rbp), %xmm0
leaq 0x209a9e(%rip), %rax    # 0x36b9f8
addsd (%rax), %xmm0
leaq 0x209a93(%rip), %rax    # 0x36b9f8
movsd %xmm0, (%rax)
leaq 0x139e48(%rip), %rax    # 0x29bdb8
cmpq $0x0, (%rax)
jne 0x161f9c
leaq 0x139e5b(%rip), %rax    # 0x29bdd8
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 0x20a785(%rip), %rax    # 0x36c710
movsd (%rax), %xmm0
leaq 0x139ef2(%rip), %rax    # 0x29be88
movsd %xmm0, (%rax)
jmp 0x161fbf
movsd -0x8(%rbp), %xmm0
leaq 0x139e38(%rip), %rax    # 0x29bde0
subsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x139e1d(%rip), %rax    # 0x29bdd8
movsd %xmm0, (%rax)
movsd -0x8(%rbp), %xmm0
leaq 0x139e15(%rip), %rax    # 0x29bde0
movsd %xmm0, (%rax)
leaq 0x209a22(%rip), %rax    # 0x36b9f8
movsd (%rax), %xmm0
leaq 0x139f0f(%rip), %rax    # 0x29bef0
movsd (%rax), %xmm1
movl $0xa, %edi
callq 0x1613f0
leaq 0x1206c2(%rip), %rax    # 0x2826b8
cmpl $0x0, (%rax)
jne 0x16203a
leaq 0x1206be(%rip), %rax    # 0x2826c0
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x16203a
leaq 0x139da7(%rip), %rax    # 0x29bdb8
cmpq $0x1, (%rax)
jg 0x16203a
leaq 0x2099da(%rip), %rax    # 0x36b9f8
movsd (%rax), %xmm0
leaq 0x120677(%rip), %rax    # 0x2826a0
movsd %xmm0, (%rax)
leaq 0x120684(%rip), %rax    # 0x2826b8
movl $0x1, (%rax)
leaq 0x139d5f(%rip), %rax    # 0x29bda0
cmpq $0x0, (%rax)
je 0x162076
leaq 0x2099aa(%rip), %rax    # 0x36b9f8
movsd (%rax), %xmm0
leaq 0x120647(%rip), %rax    # 0x2826a0
subsd (%rax), %xmm0
leaq 0x139d3c(%rip), %rax    # 0x29bda0
movq (%rax), %rax
leaq 0x139d3a(%rip), %rcx    # 0x29bda8
movq (%rcx), %rcx
movsd %xmm0, (%rax,%rcx,8)
leaq 0x139d2b(%rip), %rax    # 0x29bda8
movq (%rax), %rax
addq $0x1, %rax
leaq 0x139d1d(%rip), %rcx    # 0x29bda8
movq %rax, (%rcx)
leaq 0x139e23(%rip), %rcx    # 0x29beb8
cmpq (%rcx), %rax
jl 0x1620a8
leaq 0x139d07(%rip), %rax    # 0x29bda8
movq $0x0, (%rax)
leaq 0x139cf9(%rip), %rax    # 0x29bda8
movq (%rax), %rax
leaq 0x139cf7(%rip), %rcx    # 0x29bdb0
cmpq (%rcx), %rax
jne 0x162138
leaq 0x139ceb(%rip), %rax    # 0x29bdb0
movq (%rax), %rcx
addq $0x1, %rcx
leaq 0x139cdd(%rip), %rax    # 0x29bdb0
movq %rcx, (%rax)
movsd 0xcf8a(%rip), %xmm0     # 0x16f068
leaq 0x139cdb(%rip), %rax    # 0x29bdc0
addsd (%rax), %xmm0
leaq 0x139cd0(%rip), %rax    # 0x29bdc0
movsd %xmm0, (%rax)
callq 0x161190
leaq 0x139cc0(%rip), %rax    # 0x29bdc0
movsd (%rax), %xmm0
leaq 0x139dad(%rip), %rax    # 0x29beb8
cvtsi2sdq (%rax), %xmm1
ucomisd %xmm1, %xmm0
jb 0x162136
leaq 0x139dff(%rip), %rax    # 0x29bf1c
cmpb $0x0, (%rax)
je 0x162134
callq 0x15ed60
leaq 0x139d2a(%rip), %rax    # 0x29be58
movl $0x1, (%rax)
jmp 0x162136
jmp 0x162150
leaq 0x139c79(%rip), %rax    # 0x29bdb8
movq (%rax), %rcx
addq $0x1, %rcx
leaq 0x139c6b(%rip), %rax    # 0x29bdb8
movq %rcx, (%rax)
leaq 0x139c59(%rip), %rax    # 0x29bdb0
movq (%rax), %rax
leaq 0x139d57(%rip), %rcx    # 0x29beb8
cmpq (%rcx), %rax
jl 0x162174
leaq 0x139c43(%rip), %rax    # 0x29bdb0
movq $0x0, (%rax)
callq 0x160e40
leaq 0x139cd8(%rip), %rax    # 0x29be58
cmpl $0x0, (%rax)
je 0x16219c
movl $0x3, %edi
callq 0x161820
leaq 0x139cc2(%rip), %rax    # 0x29be58
movl $0x0, (%rax)
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)