// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathmsc.cpp
// Function: incr_adev(unsigned char, BIN*)
void incr_adev(u08 id, struct BIN *bins)
{
S32 b;
S32 t1,t2;
struct BIN *B;
double v;
int vis_bins;
long adev_q_count;
double adev_q_overflow;

   if     (id == PPS_ADEV) { adev_q_count = pps_adev_q_count; adev_q_overflow = pps_adev_q_overflow; }
   else if(id == OSC_ADEV) { adev_q_count = osc_adev_q_count; adev_q_overflow = osc_adev_q_overflow; } 
   else if(id == CHC_ADEV) { adev_q_count = chc_adev_q_count; adev_q_overflow = chc_adev_q_overflow; } 
   else if(id == CHD_ADEV) { adev_q_count = chd_adev_q_count; adev_q_overflow = chd_adev_q_overflow; } 
   else return;

   vis_bins = 0;

   for(b=0; b<n_bins; b++) {
      B = &bins[b];
      if(B->n < 0) break;

      t1 = B->m;
      t2 = t1 + t1;

      if((B->n+t2) >= adev_q_count) break;
//tvb if((B->n+t2) > adev_q_count) break;

      while((B->n+t2) < adev_q_count) {
         v =  get_adev_point(id, B->n+t2);
         v -= get_adev_point(id, B->n+t1) * 2.0;
         v += get_adev_point(id, B->n);

         B->sum += (v * v);
         B->n++;
         adev_mouse();
      }

      if(B->n >= min_points_per_bin) {
         if(B->n && B->tau) {
            B->value = sqrt(B->sum / (2.0 * ((double) B->n + adev_q_overflow))) / B->tau;
            ++vis_bins;
         }
      }
   }

   if(vis_bins > max_adev_rows) max_adev_rows = vis_bins;
}

// Assembly:
movq %rsi, %rdx
cmpl $0x9, %edi
jg 0xfef94
testl %edi, %edi
je 0xfefb2
cmpl $0x5, %edi
jne 0xff164
leaq 0x13dbb5(%rip), %rax    # 0x23cb40
leaq 0x13dba6(%rip), %rcx    # 0x23cb38
jmp 0xfefd0
cmpl $0xa, %edi
je 0xfefc2
cmpl $0xf, %edi
jne 0xff164
leaq 0x13dc87(%rip), %rax    # 0x23cc30
leaq 0x13dc78(%rip), %rcx    # 0x23cc28
jmp 0xfefd0
leaq 0x13dbd7(%rip), %rax    # 0x23cb90
leaq 0x13dbc8(%rip), %rcx    # 0x23cb88
jmp 0xfefd0
leaq 0x13dc17(%rip), %rax    # 0x23cbe0
leaq 0x13dc08(%rip), %rcx    # 0x23cbd8
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x13dcd8(%rip), %rsi    # 0x23ccc0
cmpl $0x0, (%rsi)
jle 0xff13e
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movq (%rcx), %r13
xorl %r8d, %r8d
movzbl %dil, %r14d
xorpd %xmm2, %xmm2
movl $0x0, -0x2c(%rbp)
movq %rdx, -0x40(%rbp)
imulq $0x38, %r8, %r15
movl 0x4(%rdx,%r15), %eax
testl %eax, %eax
js 0xff145
addq %rdx, %r15
movslq (%r15), %rbx
leaq (%rbx,%rbx), %r12
addl %r12d, %eax
cltq
cmpq %rax, %r13
jle 0xff145
movl 0x4(%r15), %eax
leal (%rax,%r12), %ecx
movslq %ecx, %rsi
cmpq %rsi, %r13
jle 0xff0c1
movq %r8, -0x50(%rbp)
movl %r14d, %edi
callq 0x100a1e
movsd %xmm0, -0x38(%rbp)
movslq 0x4(%r15), %rsi
addq %rbx, %rsi
movl %r14d, %edi
callq 0x100a1e
addsd %xmm0, %xmm0
movsd -0x38(%rbp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
movslq 0x4(%r15), %rsi
movl %r14d, %edi
callq 0x100a1e
addsd -0x38(%rbp), %xmm0
mulsd %xmm0, %xmm0
addsd 0x8(%r15), %xmm0
movsd %xmm0, 0x8(%r15)
incl 0x4(%r15)
callq 0xfeec0
movslq 0x4(%r15), %rax
leaq (%rax,%r12), %rsi
cmpq %rsi, %r13
jg 0xff050
movq -0x40(%rbp), %rdx
movq -0x50(%rbp), %r8
xorpd %xmm2, %xmm2
testl %eax, %eax
je 0xff126
leaq 0x13dbf0(%rip), %rcx    # 0x23ccbc
cmpl (%rcx), %eax
jl 0xff126
movsd 0x18(%r15), %xmm0
ucomisd %xmm2, %xmm0
jne 0xff0de
jnp 0xff126
movsd 0x8(%r15), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
addsd -0x48(%rbp), %xmm1
addsd %xmm1, %xmm1
divsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jb 0xff104
sqrtsd %xmm0, %xmm0
jmp 0xff117
movq %r8, %rbx
callq 0x9270
xorpd %xmm2, %xmm2
movq %rbx, %r8
movq -0x40(%rbp), %rdx
divsd 0x18(%r15), %xmm0
movsd %xmm0, 0x10(%r15)
incl -0x2c(%rbp)
incq %r8
leaq 0x13db90(%rip), %rax    # 0x23ccc0
movslq (%rax), %rax
cmpq %rax, %r8
jl 0xff013
jmp 0xff145
movl $0x0, -0x2c(%rbp)
leaq 0x125e34(%rip), %rax    # 0x224f80
movl -0x2c(%rbp), %ecx
cmpl (%rax), %ecx
leaq 0x28(%rsp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jle 0xff164
movl %ecx, (%rax)
retq