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

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

   if(chd_adev_q_count == 0) {
      chd_resid = 0.0;
      chd_adev_jd0 = jd_utc;
   }
   else chd_resid = (float) ((val-last_chd_resid));
   last_chd_resid = val;

   calc_resids(CHD, chd_phase, chd_adev_period);

   if((have_chd_base == 0) && (subtract_base_value == 1) && (chd_adev_q_count <= 1)) {  // aaaaa
      chd_base_value = chd_phase;
      have_chd_base = 1;
   }

   if(chd_adev_q) chd_adev_q[chd_adev_q_in] = (OFS_SIZE) (chd_phase - chd_base_value);

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

   if(chd_adev_q_in == chd_adev_q_out) {  // queue is full
      ++chd_adev_q_out;               // drop oldest entry from the queue
      chd_adev_q_overflow += 1.0;
      incr_chd_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(chd_adev_q_overflow >= adev_q_size) {  // !!!! wrap >= was >0 
         if(keep_adevs_fresh) {
            reset_chd_bins();              
            adev_freshened = 1;
         }
      }
   }
   else ++chd_adev_q_count;   // keep count of number of entries in the adev queue
   if(chd_adev_q_out >= adev_q_size) chd_adev_q_out = 0;

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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movapd %xmm0, %xmm2
leaq 0x13c209(%rip), %r15    # 0x226d18
xorpd %xmm0, %xmm0
ucomisd (%r15), %xmm0
jae 0xeacd4
movl %edi, %ebx
leaq 0x13c1b9(%rip), %rax    # 0x226ce0
cmpl $0x0, (%rax)
jne 0xeab3b
movsd %xmm2, -0x20(%rbp)
callq 0x10118
movsd -0x20(%rbp), %xmm2
leaq 0x20bcde(%rip), %r14    # 0x2f6820
testl %ebx, %ebx
je 0xeab4c
movapd %xmm2, %xmm0
jmp 0xeab55
movsd (%r14), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, (%r14)
leaq 0x13c0c7(%rip), %rbx    # 0x226c28
cmpq $0x0, (%rbx)
je 0xeab80
leaq 0x13c0ea(%rip), %rax    # 0x226c58
movapd %xmm2, %xmm1
subsd (%rax), %xmm1
cvtsd2ss %xmm1, %xmm1
cvtss2sd %xmm1, %xmm1
jmp 0xeab99
leaq 0x20c9a9(%rip), %rax    # 0x2f7530
movsd (%rax), %xmm1
leaq 0x13c11e(%rip), %rax    # 0x226cb0
movsd %xmm1, (%rax)
xorps %xmm1, %xmm1
leaq 0x13c0b0(%rip), %rax    # 0x226c50
movsd %xmm1, (%rax)
leaq 0x13c0ad(%rip), %rax    # 0x226c58
movsd %xmm2, (%rax)
movsd (%r15), %xmm1
pushq $0xb
popq %rdi
callq 0xea263
leaq 0x122919(%rip), %rcx    # 0x20d4dc
cmpl $0x0, (%rcx)
sete %al
leaq 0x122910(%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 0xeac02
movsd (%r14), %xmm0
leaq 0x1228d0(%rip), %rdx    # 0x20d4c8
movsd %xmm0, (%rdx)
movl $0x1, (%rcx)
leaq 0x13c007(%rip), %rcx    # 0x226c10
movq (%rcx), %rcx
leaq 0x13c005(%rip), %rdx    # 0x226c18
movq (%rdx), %rsi
testq %rcx, %rcx
je 0xeac30
movsd (%r14), %xmm0
leaq 0x1228a1(%rip), %rdi    # 0x20d4c8
subsd (%rdi), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
incq %rsi
leaq 0x13c09e(%rip), %r15    # 0x226cd8
movq (%r15), %rcx
xorl %edi, %edi
cmpq %rcx, %rsi
cmovlq %rsi, %rdi
movq %rdi, (%rdx)
leaq 0x13bfd0(%rip), %r14    # 0x226c20
cmpq (%r14), %rdi
jne 0xeacac
incq %rdi
movq %rdi, (%r14)
leaq 0x13bfce(%rip), %rbx    # 0x226c30
movsd (%rbx), %xmm0
addsd 0x8402(%rip), %xmm0     # 0xf3070
movsd %xmm0, (%rbx)
callq 0xea1e6
movsd (%rbx), %xmm0
movq (%r15), %rcx
cvtsi2sd %rcx, %xmm1
ucomisd %xmm1, %xmm0
jb 0xeacb2
leaq 0x13c0ac(%rip), %rax    # 0x226d3c
cmpb $0x0, (%rax)
je 0xeacb2
callq 0xe8c1b
leaq 0x13bfd7(%rip), %rax    # 0x226c78
movl $0x1, (%rax)
movq (%r15), %rcx
jmp 0xeacb2
incq %rax
movq %rax, (%rbx)
cmpq %rcx, (%r14)
jl 0xeacbb
andq $0x0, (%r14)
callq 0xe9ff9
leaq 0x13bfb1(%rip), %rbx    # 0x226c78
cmpl $0x0, (%rbx)
je 0xeacd4
callq 0xea4e4
andl $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq