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

if(rcvr_type == BRANDY_RCVR) phase = 1;  // receiver outputs phase instead of time for the pps_offset
if(rcvr_type == RFTG_RCVR) phase = 1;
   if(phase) pps_phase = val;
   else      pps_phase += val;  // convert time interval to phase

   if(pps_adev_q_count == 0) {
      pps_resid = 0.0;
      pps_adev_jd0 = jd_utc;
   }
   else pps_resid = (pps_phase - last_pps_resid);
   last_pps_resid = pps_phase;

   calc_resids(PPS, pps_phase, pps_adev_period);

//sprintf(debug_text, "phase:%.12f  last:%.12f  diff:%.12f %.12f", pps_phase,last_pps_phase, (pps_phase-last_pps_phase), (pps_phase-last_pps_phase)/1.0E9);

   if((have_pps_base == 0) && (subtract_base_value == 1) && (pps_adev_q_count <= 1)) {  // aaaaa
      pps_base_value = pps_phase;
      have_pps_base = 1;
   }

   if(pps_adev_q) {
      pps_adev_q[pps_adev_q_in] = (OFS_SIZE) (pps_phase - pps_base_value);
   }

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

   if(pps_adev_q_in == pps_adev_q_out) {  // queue is full
      ++pps_adev_q_out;           // drop oldest entry from the queue
      pps_adev_q_overflow += 1.0;
      incr_pps_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(pps_adev_q_overflow >= adev_q_size) {  // !!!! wrap >= was >0
         if(keep_adevs_fresh) {
            reset_pps_bins();              
            adev_freshened = 1;
         }
      }
   }
   else ++pps_adev_q_count;   // keep count of number of entries in the adev queue
   if(pps_adev_q_out >= adev_q_size) pps_adev_q_out = 0;

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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
leaq 0x13c919(%rip), %r14    # 0x23cd00
xorpd %xmm1, %xmm1
ucomisd (%r14), %xmm1
jae 0x100618
movl %edi, %ebx
leaq 0x13c8e1(%rip), %rax    # 0x23cce0
cmpl $0x0, (%rax)
jne 0x100413
movsd %xmm0, -0x20(%rbp)
callq 0x10802
movsd -0x20(%rbp), %xmm0
leaq 0x1184b6(%rip), %rax    # 0x2188d0
movq (%rax), %rcx
leaq 0x20c3d4(%rip), %rax    # 0x30c7f8
cmpq $0x40000, %rcx          # imm = 0x40000
jne 0x100433
movapd %xmm0, %xmm3
jmp 0x10043b
movsd (%rax), %xmm3
addsd %xmm0, %xmm3
cmpq $0x400000, %rcx         # imm = 0x400000
jne 0x100448
movapd %xmm0, %xmm3
testl %ebx, %ebx
je 0x100450
movapd %xmm0, %xmm3
movsd %xmm3, (%rax)
leaq 0x13c6dd(%rip), %rax    # 0x23cb38
movq (%rax), %rcx
testq %rcx, %rcx
je 0x100474
leaq 0x13c6f6(%rip), %rdx    # 0x23cb60
movapd %xmm3, %xmm1
subsd (%rdx), %xmm1
jmp 0x10048e
leaq 0x20d0b5(%rip), %rdx    # 0x30d530
movsd (%rdx), %xmm1
leaq 0x13c812(%rip), %rdx    # 0x23cc98
movsd %xmm1, (%rdx)
xorpd %xmm1, %xmm1
leaq 0x23f3bb(%rip), %rdx    # 0x33f850
movsd 0x38(%rdx), %xmm2
addsd 0x8bce(%rip), %xmm2     # 0x109070
movsd %xmm2, 0x38(%rdx)
mulsd (%r14), %xmm2
leaq 0x13c6a5(%rip), %rsi    # 0x23cb58
movsd %xmm1, (%rsi)
leaq 0x13c6a2(%rip), %rsi    # 0x23cb60
movsd (%rdx), %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, (%rdx)
movsd 0x8(%rdx), %xmm1
addsd %xmm3, %xmm1
movsd %xmm1, 0x8(%rdx)
movapd %xmm2, %xmm1
mulsd %xmm2, %xmm1
addsd 0x10(%rdx), %xmm1
movsd %xmm3, (%rsi)
movsd %xmm1, 0x10(%rdx)
movapd %xmm3, %xmm1
mulsd %xmm3, %xmm1
addsd 0x18(%rdx), %xmm1
movsd %xmm1, 0x18(%rdx)
mulsd %xmm3, %xmm2
addsd 0x20(%rdx), %xmm2
movsd %xmm2, 0x20(%rdx)
cmpq $0x1, %rcx
jg 0x10053d
leaq 0x122fb5(%rip), %rdx    # 0x2234d0
cmpl $0x0, (%rdx)
jne 0x10053d
leaq 0x122fb9(%rip), %rsi    # 0x2234e0
cmpb $0x1, (%rsi)
jne 0x10053d
leaq 0x122f7d(%rip), %rsi    # 0x2234b0
movsd %xmm3, (%rsi)
movl $0x1, (%rdx)
leaq 0x13c5dc(%rip), %rdx    # 0x23cb20
movq (%rdx), %rdx
leaq 0x13c5da(%rip), %rsi    # 0x23cb28
movq (%rsi), %rdi
testq %rdx, %rdx
je 0x100567
leaq 0x122f53(%rip), %r8     # 0x2234b0
subsd (%r8), %xmm3
movsd %xmm3, (%rdx,%rdi,8)
incq %rdi
leaq 0x13c767(%rip), %r14    # 0x23ccd8
movq (%r14), %rdx
xorl %r8d, %r8d
cmpq %rdx, %rdi
cmovlq %rdi, %r8
movq %r8, (%rsi)
leaq 0x13c5a8(%rip), %rbx    # 0x23cb30
cmpq (%rbx), %r8
jne 0x1005ea
incq %r8
movq %r8, (%rbx)
leaq 0x13c5a6(%rip), %r15    # 0x23cb40
movsd (%r15), %xmm0
addsd 0x8ac9(%rip), %xmm0     # 0x109070
movsd %xmm0, (%r15)
callq 0x100170
movsd (%r15), %xmm0
movq (%r14), %rdx
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1005f0
leaq 0x13c76e(%rip), %rax    # 0x23cd3c
cmpb $0x0, (%rax)
je 0x1005f0
callq 0xfeaab
leaq 0x13c699(%rip), %rax    # 0x23cc78
movl $0x1, (%rax)
movq (%r14), %rdx
jmp 0x1005f0
incq %rcx
movq %rcx, (%rax)
cmpq %rdx, (%rbx)
jl 0x1005fc
movq $0x0, (%rbx)
callq 0xff5fe
leaq 0x13c670(%rip), %rbx    # 0x23cc78
cmpl $0x0, (%rbx)
je 0x100618
callq 0x100623
movl $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq