// File: /workspace/github_cpp_makefile_star2_O2/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
movapd %xmm0, %xmm2
leaq 0x13c5bc(%rip), %r15    # 0x226d08
xorpd %xmm0, %xmm0
ucomisd (%r15), %xmm0
jae 0xea90a
movl %edi, %ebx
leaq 0x13c57c(%rip), %rax    # 0x226ce0
cmpl $0x0, (%rax)
jne 0xea778
movsd %xmm2, -0x20(%rbp)
callq 0x10118
movsd -0x20(%rbp), %xmm2
leaq 0x20c081(%rip), %r14    # 0x2f6800
testl %ebx, %ebx
je 0xea789
movapd %xmm2, %xmm0
jmp 0xea792
movsd (%r14), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, (%r14)
leaq 0x13c3ea(%rip), %rbx    # 0x226b88
cmpq $0x0, (%rbx)
je 0xea7b5
leaq 0x13c405(%rip), %rax    # 0x226bb0
movapd %xmm2, %xmm1
subsd (%rax), %xmm1
jmp 0xea7cf
leaq 0x20cd74(%rip), %rax    # 0x2f7530
movsd (%rax), %xmm1
leaq 0x13c4d9(%rip), %rax    # 0x226ca0
movsd %xmm1, (%rax)
xorpd %xmm1, %xmm1
leaq 0x13c3d2(%rip), %rax    # 0x226ba8
movsd %xmm1, (%rax)
leaq 0x13c3cf(%rip), %rax    # 0x226bb0
movsd %xmm2, (%rax)
movsd (%r15), %xmm1
pushq $0x1
popq %rdi
callq 0xea263
leaq 0x122cdb(%rip), %rcx    # 0x20d4d4
cmpl $0x0, (%rcx)
sete %al
leaq 0x122cda(%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 0xea838
movsd (%r14), %xmm0
leaq 0x122c8a(%rip), %rdx    # 0x20d4b8
movsd %xmm0, (%rdx)
movl $0x1, (%rcx)
leaq 0x13c331(%rip), %rcx    # 0x226b70
movq (%rcx), %rcx
leaq 0x13c32f(%rip), %rdx    # 0x226b78
movq (%rdx), %rsi
testq %rcx, %rcx
je 0xea866
movsd (%r14), %xmm0
leaq 0x122c5b(%rip), %rdi    # 0x20d4b8
subsd (%rdi), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
incq %rsi
leaq 0x13c468(%rip), %r15    # 0x226cd8
movq (%r15), %rcx
xorl %edi, %edi
cmpq %rcx, %rsi
cmovlq %rsi, %rdi
movq %rdi, (%rdx)
leaq 0x13c2fa(%rip), %r14    # 0x226b80
cmpq (%r14), %rdi
jne 0xea8e2
incq %rdi
movq %rdi, (%r14)
leaq 0x13c2f8(%rip), %rbx    # 0x226b90
movsd (%rbx), %xmm0
addsd 0x87cc(%rip), %xmm0     # 0xf3070
movsd %xmm0, (%rbx)
callq 0xea0ec
movsd (%rbx), %xmm0
movq (%r15), %rcx
cvtsi2sd %rcx, %xmm1
ucomisd %xmm1, %xmm0
jb 0xea8e8
leaq 0x13c476(%rip), %rax    # 0x226d3c
cmpb $0x0, (%rax)
je 0xea8e8
callq 0xe8b5f
leaq 0x13c3a1(%rip), %rax    # 0x226c78
movl $0x1, (%rax)
movq (%r15), %rcx
jmp 0xea8e8
incq %rax
movq %rax, (%rbx)
cmpq %rcx, (%r14)
jl 0xea8f1
andq $0x0, (%r14)
callq 0xe9f78
leaq 0x13c37b(%rip), %rbx    # 0x226c78
cmpl $0x0, (%rbx)
je 0xea90a
callq 0xea4e4
andl $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq