// File: /workspace/github_cpp_makefile_star2_O1/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
leaq 0x13c81c(%rip), %r14    # 0x23cd10
xorpd %xmm1, %xmm1
ucomisd (%r14), %xmm1
jae 0x10073a
movl %edi, %ebx
leaq 0x13c7d4(%rip), %rax    # 0x23cce0
cmpl $0x0, (%rax)
jne 0x100520
movsd %xmm0, -0x20(%rbp)
callq 0x10884
movsd -0x20(%rbp), %xmm0
leaq 0x20c2f1(%rip), %rax    # 0x30c818
testl %ebx, %ebx
je 0x100531
movapd %xmm0, %xmm3
jmp 0x100539
movsd (%rax), %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, (%rax)
leaq 0x13c694(%rip), %rax    # 0x23cbd8
movq (%rax), %rcx
testq %rcx, %rcx
je 0x10056c
leaq 0x13c6ad(%rip), %rdx    # 0x23cc00
movapd %xmm0, %xmm1
subsd (%rdx), %xmm1
cvtsd2ss %xmm1, %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x13c68e(%rip), %rdx    # 0x23cbf8
jmp 0x10058c
leaq 0x13c685(%rip), %rdx    # 0x23cbf8
movq $0x0, (%rdx)
leaq 0x20cfaf(%rip), %rdx    # 0x30d530
movsd (%rdx), %xmm1
leaq 0x13c71c(%rip), %rdx    # 0x23cca8
movsd %xmm1, (%rdx)
leaq 0x23f2b9(%rip), %rdx    # 0x33f850
movsd 0x2b8(%rdx), %xmm1
addsd 0x8ac9(%rip), %xmm1     # 0x109070
movsd %xmm1, 0x2b8(%rdx)
mulsd (%r14), %xmm1
leaq 0x13c645(%rip), %rsi    # 0x23cc00
movsd 0x280(%rdx), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x280(%rdx)
movsd 0x288(%rdx), %xmm2
addsd %xmm3, %xmm2
movsd %xmm2, 0x288(%rdx)
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
addsd 0x290(%rdx), %xmm2
movsd %xmm0, (%rsi)
movsd %xmm2, 0x290(%rdx)
movapd %xmm3, %xmm2
mulsd %xmm3, %xmm2
addsd 0x298(%rdx), %xmm2
movsd %xmm2, 0x298(%rdx)
mulsd %xmm3, %xmm1
addsd 0x2a0(%rdx), %xmm1
movsd %xmm1, 0x2a0(%rdx)
cmpq $0x1, %rcx
jg 0x10065a
leaq 0x122ea0(%rip), %rdx    # 0x2234d8
cmpl $0x0, (%rdx)
jne 0x10065a
leaq 0x122e9c(%rip), %rsi    # 0x2234e0
cmpb $0x1, (%rsi)
jne 0x10065a
leaq 0x122e70(%rip), %rsi    # 0x2234c0
movsd %xmm3, (%rsi)
movl $0x1, (%rdx)
leaq 0x13c55f(%rip), %rdx    # 0x23cbc0
movq (%rdx), %rdx
testq %rdx, %rdx
je 0x100683
leaq 0x122e50(%rip), %rsi    # 0x2234c0
subsd (%rsi), %xmm3
leaq 0x13c54d(%rip), %rsi    # 0x23cbc8
movq (%rsi), %rsi
movsd %xmm3, (%rdx,%rsi,8)
leaq 0x13c53e(%rip), %rdx    # 0x23cbc8
movq (%rdx), %rsi
incq %rsi
leaq 0x13c641(%rip), %rbx    # 0x23ccd8
xorl %edi, %edi
cmpq (%rbx), %rsi
cmovlq %rsi, %rdi
movq %rdi, (%rdx)
leaq 0x13c526(%rip), %r14    # 0x23cbd0
movq (%r14), %rdx
cmpq %rdx, %rdi
jne 0x100709
incq %rdx
movq %rdx, (%r14)
leaq 0x13c521(%rip), %r15    # 0x23cbe0
movsd (%r15), %xmm0
addsd 0x89a4(%rip), %xmm0     # 0x109070
movsd %xmm0, (%r15)
callq 0xffbb7
movsd (%r15), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq (%rbx), %xmm1
ucomisd %xmm1, %xmm0
jb 0x10070f
leaq 0x13c64c(%rip), %rax    # 0x23cd3c
cmpb $0x0, (%rax)
je 0x10070f
callq 0xfe4e6
leaq 0x13c577(%rip), %rax    # 0x23cc78
movl $0x1, (%rax)
jmp 0x10070f
incq %rcx
movq %rcx, (%rax)
movq (%r14), %rax
cmpq (%rbx), %rax
jl 0x10071e
movq $0x0, (%r14)
callq 0xff9fe
leaq 0x13c54e(%rip), %rbx    # 0x23cc78
cmpl $0x0, (%rbx)
je 0x10073a
callq 0xfff83
movl $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq