// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movapd %xmm0, %xmm2
leaq 0x13c3e6(%rip), %r15    # 0x226d10
xorpd %xmm0, %xmm0
ucomisd (%r15), %xmm0
jae 0xeaaef
movl %edi, %ebx
leaq 0x13c39e(%rip), %rax    # 0x226ce0
cmpl $0x0, (%rax)
jne 0xea956
movsd %xmm2, -0x20(%rbp)
callq 0x10118
movsd -0x20(%rbp), %xmm2
leaq 0x20bebb(%rip), %r14    # 0x2f6818
testl %ebx, %ebx
je 0xea967
movapd %xmm2, %xmm0
jmp 0xea970
movsd (%r14), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, (%r14)
leaq 0x13c25c(%rip), %rbx    # 0x226bd8
cmpq $0x0, (%rbx)
je 0xea99b
leaq 0x13c277(%rip), %rax    # 0x226c00
movapd %xmm2, %xmm1
subsd (%rax), %xmm1
cvtsd2ss %xmm1, %xmm1
cvtss2sd %xmm1, %xmm1
jmp 0xea9b4
leaq 0x20cb8e(%rip), %rax    # 0x2f7530
movsd (%rax), %xmm1
leaq 0x13c2fb(%rip), %rax    # 0x226ca8
movsd %xmm1, (%rax)
xorps %xmm1, %xmm1
leaq 0x13c23d(%rip), %rax    # 0x226bf8
movsd %xmm1, (%rax)
leaq 0x13c23a(%rip), %rax    # 0x226c00
movsd %xmm2, (%rax)
movsd (%r15), %xmm1
pushq $0xa
popq %rdi
callq 0xea263
leaq 0x122afa(%rip), %rcx    # 0x20d4d8
cmpl $0x0, (%rcx)
sete %al
leaq 0x122af5(%rip), %rdx    # 0x20d4e0
cmpb $0x1, (%rdx)
sete %dl
andb %al, %dl
movq (%rbx), %rax
cmpq $0x2, %rax
setl %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xeaa1d
movsd (%r14), %xmm0
leaq 0x122aad(%rip), %rdx    # 0x20d4c0
movsd %xmm0, (%rdx)
movl $0x1, (%rcx)
leaq 0x13c19c(%rip), %rcx    # 0x226bc0
movq (%rcx), %rcx
leaq 0x13c19a(%rip), %rdx    # 0x226bc8
movq (%rdx), %rsi
testq %rcx, %rcx
je 0xeaa4b
movsd (%r14), %xmm0
leaq 0x122a7e(%rip), %rdi    # 0x20d4c0
subsd (%rdi), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
incq %rsi
leaq 0x13c283(%rip), %r15    # 0x226cd8
movq (%r15), %rcx
xorl %edi, %edi
cmpq %rcx, %rsi
cmovlq %rsi, %rdi
movq %rdi, (%rdx)
leaq 0x13c165(%rip), %r14    # 0x226bd0
cmpq (%r14), %rdi
jne 0xeaac7
incq %rdi
movq %rdi, (%r14)
leaq 0x13c163(%rip), %rbx    # 0x226be0
movsd (%rbx), %xmm0
addsd 0x85e7(%rip), %xmm0     # 0xf3070
movsd %xmm0, (%rbx)
callq 0xea169
movsd (%rbx), %xmm0
movq (%r15), %rcx
cvtsi2sd %rcx, %xmm1
ucomisd %xmm1, %xmm0
jb 0xeaacd
leaq 0x13c291(%rip), %rax    # 0x226d3c
cmpb $0x0, (%rax)
je 0xeaacd
callq 0xe8bbd
leaq 0x13c1bc(%rip), %rax    # 0x226c78
movl $0x1, (%rax)
movq (%r15), %rcx
jmp 0xeaacd
incq %rax
movq %rax, (%rbx)
cmpq %rcx, (%r14)
jl 0xeaad6
andq $0x0, (%r14)
callq 0xe9fb8
leaq 0x13c196(%rip), %rbx    # 0x226c78
cmpl $0x0, (%rbx)
je 0xeaaef
callq 0xea4e4
andl $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq