// File: /workspace/github_cpp_makefile_star2_O1/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 0x13cfc4(%rip), %r14    # 0x23cd00
xorpd %xmm1, %xmm1
ucomisd (%r14), %xmm1
jae 0xfff78
movl %edi, %ebx
leaq 0x13cf8c(%rip), %rax    # 0x23cce0
cmpl $0x0, (%rax)
jne 0xffd68
movsd %xmm0, -0x20(%rbp)
callq 0x10884
movsd -0x20(%rbp), %xmm0
leaq 0x118b61(%rip), %rax    # 0x2188d0
movq (%rax), %rcx
leaq 0x20ca7f(%rip), %rax    # 0x30c7f8
cmpq $0x40000, %rcx          # imm = 0x40000
jne 0xffd88
movapd %xmm0, %xmm3
jmp 0xffd90
movsd (%rax), %xmm3
addsd %xmm0, %xmm3
cmpq $0x400000, %rcx         # imm = 0x400000
jne 0xffd9d
movapd %xmm0, %xmm3
testl %ebx, %ebx
je 0xffda5
movapd %xmm0, %xmm3
movsd %xmm3, (%rax)
leaq 0x13cd88(%rip), %rax    # 0x23cb38
movq (%rax), %rcx
testq %rcx, %rcx
je 0xffdd0
leaq 0x13cda1(%rip), %rdx    # 0x23cb60
movapd %xmm3, %xmm1
subsd (%rdx), %xmm1
leaq 0x13cd8a(%rip), %rdx    # 0x23cb58
jmp 0xffdf0
leaq 0x13cd81(%rip), %rdx    # 0x23cb58
movq $0x0, (%rdx)
leaq 0x20d74b(%rip), %rdx    # 0x30d530
movsd (%rdx), %xmm1
leaq 0x13cea8(%rip), %rdx    # 0x23cc98
movsd %xmm1, (%rdx)
leaq 0x23fa55(%rip), %rdx    # 0x33f850
movsd 0x38(%rdx), %xmm1
addsd 0x9268(%rip), %xmm1     # 0x109070
movsd %xmm1, 0x38(%rdx)
mulsd (%r14), %xmm1
leaq 0x13cd47(%rip), %rsi    # 0x23cb60
movsd (%rdx), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, (%rdx)
movsd 0x8(%rdx), %xmm2
addsd %xmm3, %xmm2
movsd %xmm2, 0x8(%rdx)
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
addsd 0x10(%rdx), %xmm2
movsd %xmm3, (%rsi)
movsd %xmm2, 0x10(%rdx)
movapd %xmm3, %xmm2
mulsd %xmm3, %xmm2
addsd 0x18(%rdx), %xmm2
movsd %xmm2, 0x18(%rdx)
mulsd %xmm3, %xmm1
addsd 0x20(%rdx), %xmm1
movsd %xmm1, 0x20(%rdx)
cmpq $0x1, %rcx
jg 0xffe98
leaq 0x12365a(%rip), %rdx    # 0x2234d0
cmpl $0x0, (%rdx)
jne 0xffe98
leaq 0x12365e(%rip), %rsi    # 0x2234e0
cmpb $0x1, (%rsi)
jne 0xffe98
leaq 0x123622(%rip), %rsi    # 0x2234b0
movsd %xmm3, (%rsi)
movl $0x1, (%rdx)
leaq 0x13cc81(%rip), %rdx    # 0x23cb20
movq (%rdx), %rdx
testq %rdx, %rdx
je 0xffec1
leaq 0x123602(%rip), %rsi    # 0x2234b0
subsd (%rsi), %xmm3
leaq 0x13cc6f(%rip), %rsi    # 0x23cb28
movq (%rsi), %rsi
movsd %xmm3, (%rdx,%rsi,8)
leaq 0x13cc60(%rip), %rdx    # 0x23cb28
movq (%rdx), %rsi
incq %rsi
leaq 0x13ce03(%rip), %rbx    # 0x23ccd8
xorl %edi, %edi
cmpq (%rbx), %rsi
cmovlq %rsi, %rdi
movq %rdi, (%rdx)
leaq 0x13cc48(%rip), %r14    # 0x23cb30
movq (%r14), %rdx
cmpq %rdx, %rdi
jne 0xfff47
incq %rdx
movq %rdx, (%r14)
leaq 0x13cc43(%rip), %r15    # 0x23cb40
movsd (%r15), %xmm0
addsd 0x9166(%rip), %xmm0     # 0x109070
movsd %xmm0, (%r15)
callq 0xffac5
movsd (%r15), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq (%rbx), %xmm1
ucomisd %xmm1, %xmm0
jb 0xfff4d
leaq 0x13ce0e(%rip), %rax    # 0x23cd3c
cmpb $0x0, (%rax)
je 0xfff4d
callq 0xfe424
leaq 0x13cd39(%rip), %rax    # 0x23cc78
movl $0x1, (%rax)
jmp 0xfff4d
incq %rcx
movq %rcx, (%rax)
movq (%r14), %rax
cmpq (%rbx), %rax
jl 0xfff5c
movq $0x0, (%r14)
callq 0xfef26
leaq 0x13cd10(%rip), %rbx    # 0x23cc78
cmpl $0x0, (%rbx)
je 0xfff78
callq 0xfff83
movl $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq