// File: 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
subq $0x10, %rsp
movsd %xmm0, -0x8(%rbp)
movl %edi, -0xc(%rbp)
xorps %xmm0, %xmm0
leaq 0x13a26e(%rip), %rax    # 0x29bee8
ucomisd (%rax), %xmm0
jb 0x161c85
jmp 0x161ef4
leaq 0x13a234(%rip), %rax    # 0x29bec0
cmpl $0x0, (%rax)
jne 0x161c96
callq 0x14040
cmpl $0x0, -0xc(%rbp)
je 0x161cae
movsd -0x8(%rbp), %xmm0
leaq 0x209d38(%rip), %rax    # 0x36b9e0
movsd %xmm0, (%rax)
jmp 0x161cc9
movsd -0x8(%rbp), %xmm0
leaq 0x209d26(%rip), %rax    # 0x36b9e0
addsd (%rax), %xmm0
leaq 0x209d1b(%rip), %rax    # 0x36b9e0
movsd %xmm0, (%rax)
leaq 0x13a098(%rip), %rax    # 0x29bd68
cmpq $0x0, (%rax)
jne 0x161cfc
leaq 0x13a0ab(%rip), %rax    # 0x29bd88
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 0x20aa25(%rip), %rax    # 0x36c710
movsd (%rax), %xmm0
leaq 0x13a18a(%rip), %rax    # 0x29be80
movsd %xmm0, (%rax)
jmp 0x161d17
movsd -0x8(%rbp), %xmm0
leaq 0x13a088(%rip), %rax    # 0x29bd90
subsd (%rax), %xmm0
leaq 0x13a075(%rip), %rax    # 0x29bd88
movsd %xmm0, (%rax)
movsd -0x8(%rbp), %xmm0
leaq 0x13a06d(%rip), %rax    # 0x29bd90
movsd %xmm0, (%rax)
leaq 0x209cb2(%rip), %rax    # 0x36b9e0
movsd (%rax), %xmm0
leaq 0x13a1af(%rip), %rax    # 0x29bee8
movsd (%rax), %xmm1
movl $0x1, %edi
callq 0x1613f0
leaq 0x120966(%rip), %rax    # 0x2826b4
cmpl $0x0, (%rax)
jne 0x161d92
leaq 0x120966(%rip), %rax    # 0x2826c0
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x161d92
leaq 0x139fff(%rip), %rax    # 0x29bd68
cmpq $0x1, (%rax)
jg 0x161d92
leaq 0x209c6a(%rip), %rax    # 0x36b9e0
movsd (%rax), %xmm0
leaq 0x120917(%rip), %rax    # 0x282698
movsd %xmm0, (%rax)
leaq 0x120928(%rip), %rax    # 0x2826b4
movl $0x1, (%rax)
leaq 0x139fb7(%rip), %rax    # 0x29bd50
cmpq $0x0, (%rax)
je 0x161dce
leaq 0x209c3a(%rip), %rax    # 0x36b9e0
movsd (%rax), %xmm0
leaq 0x1208e7(%rip), %rax    # 0x282698
subsd (%rax), %xmm0
leaq 0x139f94(%rip), %rax    # 0x29bd50
movq (%rax), %rax
leaq 0x139f92(%rip), %rcx    # 0x29bd58
movq (%rcx), %rcx
movsd %xmm0, (%rax,%rcx,8)
leaq 0x139f83(%rip), %rax    # 0x29bd58
movq (%rax), %rax
addq $0x1, %rax
leaq 0x139f75(%rip), %rcx    # 0x29bd58
movq %rax, (%rcx)
leaq 0x13a0cb(%rip), %rcx    # 0x29beb8
cmpq (%rcx), %rax
jl 0x161e00
leaq 0x139f5f(%rip), %rax    # 0x29bd58
movq $0x0, (%rax)
leaq 0x139f51(%rip), %rax    # 0x29bd58
movq (%rax), %rax
leaq 0x139f4f(%rip), %rcx    # 0x29bd60
cmpq (%rcx), %rax
jne 0x161e90
leaq 0x139f43(%rip), %rax    # 0x29bd60
movq (%rax), %rcx
addq $0x1, %rcx
leaq 0x139f35(%rip), %rax    # 0x29bd60
movq %rcx, (%rax)
movsd 0xd232(%rip), %xmm0     # 0x16f068
leaq 0x139f33(%rip), %rax    # 0x29bd70
addsd (%rax), %xmm0
leaq 0x139f28(%rip), %rax    # 0x29bd70
movsd %xmm0, (%rax)
callq 0x161060
leaq 0x139f18(%rip), %rax    # 0x29bd70
movsd (%rax), %xmm0
leaq 0x13a055(%rip), %rax    # 0x29beb8
cvtsi2sdq (%rax), %xmm1
ucomisd %xmm1, %xmm0
jb 0x161e8e
leaq 0x13a0a7(%rip), %rax    # 0x29bf1c
cmpb $0x0, (%rax)
je 0x161e8c
callq 0x15ecf0
leaq 0x139fd2(%rip), %rax    # 0x29be58
movl $0x1, (%rax)
jmp 0x161e8e
jmp 0x161ea8
leaq 0x139ed1(%rip), %rax    # 0x29bd68
movq (%rax), %rcx
addq $0x1, %rcx
leaq 0x139ec3(%rip), %rax    # 0x29bd68
movq %rcx, (%rax)
leaq 0x139eb1(%rip), %rax    # 0x29bd60
movq (%rax), %rax
leaq 0x139fff(%rip), %rcx    # 0x29beb8
cmpq (%rcx), %rax
jl 0x161ecc
leaq 0x139e9b(%rip), %rax    # 0x29bd60
movq $0x0, (%rax)
callq 0x160df0
leaq 0x139f80(%rip), %rax    # 0x29be58
cmpl $0x0, (%rax)
je 0x161ef4
movl $0x2, %edi
callq 0x161820
leaq 0x139f6a(%rip), %rax    # 0x29be58
movl $0x0, (%rax)
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)