// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %dil, %al
movb %al, -0x1(%rbp)
movq %rsi, -0x10(%rbp)
movzbl -0x1(%rbp), %eax
cmpl $0x5, %eax
jne 0x15ff8e
leaq 0x13bda6(%rip), %rax    # 0x29bd18
movq (%rax), %rax
movq %rax, -0x40(%rbp)
leaq 0x13bda0(%rip), %rax    # 0x29bd20
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x160014
movzbl -0x1(%rbp), %eax
cmpl $0x0, %eax
jne 0x15ffb7
leaq 0x13bdca(%rip), %rax    # 0x29bd68
movq (%rax), %rax
movq %rax, -0x40(%rbp)
leaq 0x13bdc4(%rip), %rax    # 0x29bd70
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x160012
movzbl -0x1(%rbp), %eax
cmpl $0xa, %eax
jne 0x15ffe0
leaq 0x13bdf1(%rip), %rax    # 0x29bdb8
movq (%rax), %rax
movq %rax, -0x40(%rbp)
leaq 0x13bdeb(%rip), %rax    # 0x29bdc0
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x160010
movzbl -0x1(%rbp), %eax
cmpl $0xf, %eax
jne 0x160009
leaq 0x13be18(%rip), %rax    # 0x29be08
movq (%rax), %rax
movq %rax, -0x40(%rbp)
leaq 0x13be12(%rip), %rax    # 0x29be10
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x16000e
jmp 0x1601ee
jmp 0x160010
jmp 0x160012
jmp 0x160014
movl $0x0, -0x34(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
leaq 0x13be74(%rip), %rcx    # 0x29bea0
cmpl (%rcx), %eax
jge 0x1601d4
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jge 0x160056
jmp 0x1601d4
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
addl -0x1c(%rbp), %eax
cltq
cmpq -0x40(%rbp), %rax
jl 0x16007f
jmp 0x1601d4
jmp 0x160081
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
addl -0x1c(%rbp), %eax
cltq
cmpq -0x40(%rbp), %rax
jge 0x160149
movb -0x1(%rbp), %al
movq -0x28(%rbp), %rcx
movl 0x4(%rcx), %ecx
addl -0x1c(%rbp), %ecx
movslq %ecx, %rsi
movzbl %al, %edi
callq 0x1624e0
movsd %xmm0, -0x30(%rbp)
movb -0x1(%rbp), %al
movq -0x28(%rbp), %rcx
movl 0x4(%rcx), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rsi
movzbl %al, %edi
callq 0x1624e0
movsd -0x30(%rbp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movb -0x1(%rbp), %al
movq -0x28(%rbp), %rcx
movslq 0x4(%rcx), %rsi
movzbl %al, %edi
callq 0x1624e0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd -0x30(%rbp), %xmm2
movq -0x28(%rbp), %rax
movsd 0x8(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rax)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
callq 0x15fe50
jmp 0x160081
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
leaq 0x13bd45(%rip), %rcx    # 0x29be9c
cmpl (%rcx), %eax
jl 0x1601c4
movq -0x28(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x1601c2
movq -0x28(%rbp), %rax
movsd 0x18(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x16017b
jp 0x16017b
jmp 0x1601c2
movq -0x28(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x28(%rbp), %rax
cvtsi2sdl 0x4(%rax), %xmm2
addsd -0x48(%rbp), %xmm2
movsd 0xefb6(%rip), %xmm1     # 0x16f150
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
callq 0x9280
movq -0x28(%rbp), %rax
divsd 0x18(%rax), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x10(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1601c4
jmp 0x1601c6
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x160022
movl -0x34(%rbp), %eax
leaq 0x123f82(%rip), %rcx    # 0x284160
cmpl (%rcx), %eax
jle 0x1601ee
movl -0x34(%rbp), %ecx
leaq 0x123f74(%rip), %rax    # 0x284160
movl %ecx, (%rax)
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)