// File: /workspace/github_cpp_makefile_star2_O3/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
leaq 0x13bf36(%rip), %r14    # 0x23cd18
xorpd %xmm1, %xmm1
ucomisd (%r14), %xmm1
jae 0x10101c
movl %edi, %ebx
leaq 0x13bee6(%rip), %rax    # 0x23cce0
cmpl $0x0, (%rax)
jne 0x100e0e
movsd %xmm0, -0x20(%rbp)
callq 0x10802
movsd -0x20(%rbp), %xmm0
leaq 0x20ba0b(%rip), %rax    # 0x30c820
testl %ebx, %ebx
je 0x100e1f
movapd %xmm0, %xmm3
jmp 0x100e27
movsd (%rax), %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, (%rax)
leaq 0x13bdf6(%rip), %rax    # 0x23cc28
movq (%rax), %rcx
testq %rcx, %rcx
je 0x100e53
leaq 0x13be17(%rip), %rdx    # 0x23cc58
movapd %xmm0, %xmm1
subsd (%rdx), %xmm1
cvtsd2ss %xmm1, %xmm1
cvtss2sd %xmm1, %xmm1
jmp 0x100e6c
leaq 0x20c6d6(%rip), %rdx    # 0x30d530
movsd (%rdx), %xmm1
leaq 0x13be4b(%rip), %rdx    # 0x23ccb0
movsd %xmm1, (%rdx)
xorps %xmm1, %xmm1
leaq 0x23e9dd(%rip), %rdx    # 0x33f850
movsd 0x2f8(%rdx), %xmm2
addsd 0x81ed(%rip), %xmm2     # 0x109070
movsd %xmm2, 0x2f8(%rdx)
mulsd (%r14), %xmm2
leaq 0x13bdb9(%rip), %rsi    # 0x23cc50
movsd %xmm1, (%rsi)
leaq 0x13bdb6(%rip), %rsi    # 0x23cc58
movsd 0x2c0(%rdx), %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, 0x2c0(%rdx)
movsd 0x2c8(%rdx), %xmm1
addsd %xmm3, %xmm1
movsd %xmm1, 0x2c8(%rdx)
movapd %xmm2, %xmm1
mulsd %xmm2, %xmm1
addsd 0x2d0(%rdx), %xmm1
movsd %xmm0, (%rsi)
movsd %xmm1, 0x2d0(%rdx)
movapd %xmm3, %xmm1
mulsd %xmm3, %xmm1
addsd 0x2d8(%rdx), %xmm1
movsd %xmm1, 0x2d8(%rdx)
mulsd %xmm3, %xmm2
addsd 0x2e0(%rdx), %xmm2
movsd %xmm2, 0x2e0(%rdx)
cmpq $0x1, %rcx
jg 0x100f41
leaq 0x1225bd(%rip), %rdx    # 0x2234dc
cmpl $0x0, (%rdx)
jne 0x100f41
leaq 0x1225b5(%rip), %rsi    # 0x2234e0
cmpb $0x1, (%rsi)
jne 0x100f41
leaq 0x122591(%rip), %rsi    # 0x2234c8
movsd %xmm3, (%rsi)
movl $0x1, (%rdx)
leaq 0x13bcc8(%rip), %rdx    # 0x23cc10
movq (%rdx), %rdx
leaq 0x13bcc6(%rip), %rsi    # 0x23cc18
movq (%rsi), %rdi
testq %rdx, %rdx
je 0x100f6b
leaq 0x122567(%rip), %r8     # 0x2234c8
subsd (%r8), %xmm3
movsd %xmm3, (%rdx,%rdi,8)
incq %rdi
leaq 0x13bd63(%rip), %r14    # 0x23ccd8
movq (%r14), %rdx
xorl %r8d, %r8d
cmpq %rdx, %rdi
cmovlq %rdi, %r8
movq %r8, (%rsi)
leaq 0x13bc94(%rip), %rbx    # 0x23cc20
cmpq (%rbx), %r8
jne 0x100fee
incq %r8
movq %r8, (%rbx)
leaq 0x13bc92(%rip), %r15    # 0x23cc30
movsd (%r15), %xmm0
addsd 0x80c5(%rip), %xmm0     # 0x109070
movsd %xmm0, (%r15)
callq 0x1002db
movsd (%r15), %xmm0
movq (%r14), %rdx
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
ucomisd %xmm1, %xmm0
jb 0x100ff4
leaq 0x13bd6a(%rip), %rax    # 0x23cd3c
cmpb $0x0, (%rax)
je 0x100ff4
callq 0xfebce
leaq 0x13bc95(%rip), %rax    # 0x23cc78
movl $0x1, (%rax)
movq (%r14), %rdx
jmp 0x100ff4
incq %rcx
movq %rcx, (%rax)
cmpq %rdx, (%rbx)
jl 0x101000
movq $0x0, (%rbx)
callq 0x1000f2
leaq 0x13bc6c(%rip), %rbx    # 0x23cc78
cmpl $0x0, (%rbx)
je 0x10101c
callq 0x100623
movl $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq