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

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

   if(osc_adev_q_count == 0) {
      osc_resid = 0.0;
      osc_adev_jd0 = jd_utc;
   }
   else osc_resid = ((val) - last_osc_resid);
   last_osc_resid = val;

   calc_resids(OSC, osc_phase, osc_adev_period);

   if((have_osc_base == 0) && (subtract_base_value == 1) && (osc_adev_q_count <= 1)) {  // aaaaa
      osc_base_value = osc_phase;
      have_osc_base = 1;
   }

   if(osc_adev_q) osc_adev_q[osc_adev_q_in] = (OFS_SIZE) (osc_phase - osc_base_value);

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

   if(osc_adev_q_in == osc_adev_q_out) {  // queue is full
      ++osc_adev_q_out;               // drop oldest entry from the queue
      osc_adev_q_overflow += 1.0;
      incr_osc_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(osc_adev_q_overflow >= adev_q_size) {  // !!!! wrap >= was >0 
         if(keep_adevs_fresh) {
            reset_osc_bins();              
            adev_freshened = 1;
         }
      }
   }
   else ++osc_adev_q_count;   // keep count of number of entries in the adev queue
   if(osc_adev_q_out >= adev_q_size) osc_adev_q_out = 0;

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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
leaq 0x13ca4a(%rip), %r14    # 0x23cd08
xorpd %xmm1, %xmm1
ucomisd (%r14), %xmm1
jae 0x1004d8
movl %edi, %ebx
leaq 0x13ca0a(%rip), %rax    # 0x23cce0
cmpl $0x0, (%rax)
jne 0x1002ea
movsd %xmm0, -0x20(%rbp)
callq 0x10884
movsd -0x20(%rbp), %xmm0
leaq 0x20c50f(%rip), %rax    # 0x30c800
testl %ebx, %ebx
je 0x1002fb
movapd %xmm0, %xmm3
jmp 0x100303
movsd (%rax), %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, (%rax)
leaq 0x13c87a(%rip), %rax    # 0x23cb88
movq (%rax), %rcx
testq %rcx, %rcx
je 0x10032e
leaq 0x13c893(%rip), %rdx    # 0x23cbb0
movapd %xmm0, %xmm1
subsd (%rdx), %xmm1
leaq 0x13c87c(%rip), %rdx    # 0x23cba8
jmp 0x10034e
leaq 0x13c873(%rip), %rdx    # 0x23cba8
movq $0x0, (%rdx)
leaq 0x20d1ed(%rip), %rdx    # 0x30d530
movsd (%rdx), %xmm1
leaq 0x13c952(%rip), %rdx    # 0x23cca0
movsd %xmm1, (%rdx)
leaq 0x23f4f7(%rip), %rdx    # 0x33f850
movsd 0x78(%rdx), %xmm1
addsd 0x8d0a(%rip), %xmm1     # 0x109070
movsd %xmm1, 0x78(%rdx)
mulsd (%r14), %xmm1
leaq 0x13c839(%rip), %rsi    # 0x23cbb0
movsd 0x40(%rdx), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x40(%rdx)
movsd 0x48(%rdx), %xmm2
addsd %xmm3, %xmm2
movsd %xmm2, 0x48(%rdx)
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
addsd 0x50(%rdx), %xmm2
movsd %xmm0, (%rsi)
movsd %xmm2, 0x50(%rdx)
movapd %xmm3, %xmm2
mulsd %xmm3, %xmm2
addsd 0x58(%rdx), %xmm2
movsd %xmm2, 0x58(%rdx)
mulsd %xmm3, %xmm1
addsd 0x60(%rdx), %xmm1
movsd %xmm1, 0x60(%rdx)
cmpq $0x1, %rcx
jg 0x1003f8
leaq 0x1230fe(%rip), %rdx    # 0x2234d4
cmpl $0x0, (%rdx)
jne 0x1003f8
leaq 0x1230fe(%rip), %rsi    # 0x2234e0
cmpb $0x1, (%rsi)
jne 0x1003f8
leaq 0x1230ca(%rip), %rsi    # 0x2234b8
movsd %xmm3, (%rsi)
movl $0x1, (%rdx)
leaq 0x13c771(%rip), %rdx    # 0x23cb70
movq (%rdx), %rdx
testq %rdx, %rdx
je 0x100421
leaq 0x1230aa(%rip), %rsi    # 0x2234b8
subsd (%rsi), %xmm3
leaq 0x13c75f(%rip), %rsi    # 0x23cb78
movq (%rsi), %rsi
movsd %xmm3, (%rdx,%rsi,8)
leaq 0x13c750(%rip), %rdx    # 0x23cb78
movq (%rdx), %rsi
incq %rsi
leaq 0x13c8a3(%rip), %rbx    # 0x23ccd8
xorl %edi, %edi
cmpq (%rbx), %rsi
cmovlq %rsi, %rdi
movq %rdi, (%rdx)
leaq 0x13c738(%rip), %r14    # 0x23cb80
movq (%r14), %rdx
cmpq %rdx, %rdi
jne 0x1004a7
incq %rdx
movq %rdx, (%r14)
leaq 0x13c733(%rip), %r15    # 0x23cb90
movsd (%r15), %xmm0
addsd 0x8c06(%rip), %xmm0     # 0x109070
movsd %xmm0, (%r15)
callq 0xffb3e
movsd (%r15), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq (%rbx), %xmm1
ucomisd %xmm1, %xmm0
jb 0x1004ad
leaq 0x13c8ae(%rip), %rax    # 0x23cd3c
cmpb $0x0, (%rax)
je 0x1004ad
callq 0xfe485
leaq 0x13c7d9(%rip), %rax    # 0x23cc78
movl $0x1, (%rax)
jmp 0x1004ad
incq %rcx
movq %rcx, (%rax)
movq (%r14), %rax
cmpq (%rbx), %rax
jl 0x1004bc
movq $0x0, (%r14)
callq 0xff9b8
leaq 0x13c7b0(%rip), %rbx    # 0x23cc78
cmpl $0x0, (%rbx)
je 0x1004d8
callq 0xfff83
movl $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq