// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heather.cpp
// Function: calc_queue_stats(int)
void calc_queue_stats(int stop)
{
long i;
int k;
struct PLOT_Q q;
struct PLOT_Q q2;
DATA_SIZE sxx, syy, sxy;
DATA_SIZE qi;
DATA_SIZE val;
double jd0;
double t;
int have_deriv;

   // prepare to calculate the statistics values of the plots
   for(k=0; k<NUM_PLOTS+DERIVED_PLOTS; k++) {
      plot[k].sum_x        = (DATA_SIZE) 0.0;
      plot[k].sum_y        = (DATA_SIZE) 0.0;
      plot[k].sum_xx       = (DATA_SIZE) 0.0;
      plot[k].sum_yy       = (DATA_SIZE) 0.0;
      plot[k].sum_xy       = (DATA_SIZE) 0.0;
      plot[k].stat_count   = (DATA_SIZE) 0.0;
      plot[k].sum_change   = (DATA_SIZE) 0.0;
      plot[k].max_disp_val = (DATA_SIZE) (-BIG_NUM);
      plot[k].min_disp_val = (DATA_SIZE) (BIG_NUM);
   }

   qi = (DATA_SIZE) queue_interval;

   if(1 || auto_center) {  // set min/max values in case auto scaling is off
      for(k=0; k<NUM_PLOTS+DERIVED_PLOTS; k++) {
         if(plot[k].float_center == 0) {
            plot[k].min_disp_val = plot[k].max_disp_val = plot[k].plot_center;
            if(k == TEMP) {      // !!!! ref_scale?
               if(plot[k].plot_center == NEED_CENTER) {
                  if(last_temperature) plot[k].min_disp_val = plot[k].max_disp_val = plot[k].plot_center = scale_temp((double) last_temperature);
               }
            }
else if(enviro_mode() && (k == PRESSURE)) {      // !!!! ref_scale?
    if(plot[k].plot_center == NEED_CENTER) {
       if(last_pressure) plot[k].min_disp_val = plot[k].max_disp_val = plot[k].plot_center = scale_temp((double) last_pressure);
    }
 }
            else if(luxor && (k == TC2)) {      // !!!! ref_scale?
               if(plot[k].plot_center == NEED_CENTER) {
                  plot[k].min_disp_val = plot[k].max_disp_val = plot[k].plot_center = scale_temp((double) tc2);
               }
            }
            else if(k == DAC) {  // !!!! ref_scale?
               if(plot[k].plot_center == NEED_CENTER) {
                  plot[k].min_disp_val = plot[k].max_disp_val = plot[k].plot_center = last_dac_voltage;
               }
            }
            else if(luxor && (k == PPS)) {
               // !!!!!! luxor do something?
            }
         }
      }
   }

   plot_column = 0;
   stat_count = 0.0F;
   plot_q_last_col = 0;

   have_deriv = 0;
   for(k=0; k<NUM_PLOTS+DERIVED_PLOTS; k++) {  // see if any derivative plots are enabled
      if(plot[k].show_deriv) {
         have_deriv = 1;
         break;
      }
   }

   i = plot_q_col0;
   jd0 = jd_utc;
   while(i != plot_q_in) {  // scan the data that is in the plot window
      if(filter_count) q = filter_plot_q(i);
      else             q = get_plot_q(i);

      if(have_deriv) {  // showing plot derivative  // get previous queue entry
         if(filter_count) q2 = filter_plot_q(i-1);   // plot filtered data
         else             q2 = get_plot_q(i-1);      // plot raw data
      }

      if(i == plot_q_col0) {
         jd0 = q.q_jd;
         last_q = q;
q2 = q;
      }

      add_stat_point(&q);   // update statistics values
      last_q = q;

      if((queue_interval > 0) && qi) {  // find plot min and max value
         for(k=0; k<NUM_PLOTS+DERIVED_PLOTS; k++) {
            if(k == TEMP) val = scale_temp((double) q.data[TEMP]/(double) qi);
else if(enviro_mode() && (k == PRESSURE)) val = scale_pressure((double) q.data[PRESSURE]/(double) qi);
            else if(luxor && (k == TC2)) val = scale_temp((double)q.data[k]/(double)qi);
            else if(luxor && (k == LUX1)) val = q.data[k]/qi*(DATA_SIZE) lux_scale;
            else if(luxor && (k == LUX2)) val = q.data[k]/qi*(DATA_SIZE) lum_scale;
            else if(k >= NUM_PLOTS) {  // derived plots DERIVED_PLOTS !!!!!
               if(luxor && (k == BATTW)) {        // battery watts
                  val = q.data[BATTI]*q.data[BATTV] / qi;
               }
               else if(luxor && (k == LEDW)) {   // LED watts
                  val = q.data[LEDI]*q.data[LEDV] / qi;
               }
               else if(luxor && (k == EFF)) { // driver efficency
                  val = q.data[BATTI]*q.data[BATTV];
                  if(val) val = q.data[LEDI]*q.data[LEDV] / val;
                  val *= (DATA_SIZE) 100.0;
               }
               else if(luxor && (k == CCT)) { // color temo
                  val = (DATA_SIZE) calc_cct(cct_type, 1, (double)q.data[REDHZ]/(double)qi, (double)q.data[GREENHZ]/(double)qi, (double)q.data[BLUEHZ]/(double)qi);
               }
               else {
//                val = (DATA_SIZE) 0.0;
                  val = q.data[k] / qi;
               }
            }
            else val = q.data[k] / qi;

            if(plot[k].show_deriv) {   // calculate plot derivative value
               val = q.data[k] - q2.data[k];
            }
            else if(tie_plot(k) && plot[k].show_freq) {
               val = (DATA_SIZE) tie_to_freq(k, val);
            }
            else if(phase_plot(k)) {  // calculate TICC_RCVR phase value with trend line removed
               val = remove_trend(k, 1, q.q_jd, val);
            }
            else if(plot[k].drift_rate) {  // calculate value with trend line removed
               t = q.q_jd - jd0;
               t *= (24.0*60.0*60.0);
               val = remove_trend(k, 0, t, val);
            }

            if(val > plot[k].max_disp_val) plot[k].max_disp_val = val;
            if(val < plot[k].min_disp_val) plot[k].min_disp_val = val;
         }
      }

      plot_q_last_col = i;
      i = next_q_point(i, stop);
      if(i < 0) break;      // end of plot data reached
   }

   if(stat_count == (DATA_SIZE) 0.0) return;

   for(k=0; k<NUM_PLOTS+DERIVED_PLOTS; k++) { // calculate linear regression values
      sxy = plot[k].sum_xy - ((plot[k].sum_x*plot[k].sum_y)/stat_count);
      syy = plot[k].sum_yy - ((plot[k].sum_y*plot[k].sum_y)/stat_count);
      sxx = plot[k].sum_xx - ((plot[k].sum_x*plot[k].sum_x)/stat_count);
      plot[k].stat_count = stat_count;
      if(sxx == 0.0F) {
         plot[k].a1 = plot[k].a0 = (DATA_SIZE) 0.0;
      }
      else {
         plot[k].a1 = (sxy / sxx);
         plot[k].a0 = (plot[k].sum_y/stat_count) - (plot[k].a1*(plot[k].sum_x/stat_count));
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movl %edi, -0x34(%rbp)
movl $0xb8, %eax
leaq 0x12f89e(%rip), %r15    # 0x147d30
xorpd %xmm0, %xmm0
movabsq $-0x3a0bce1f051928df, %rcx # imm = 0xC5F431E0FAE6D721
movabsq $0x45f431e0fae6d721, %rdx # imm = 0x45F431E0FAE6D721
cmpq $0x12d8, %rax           # imm = 0x12D8
je 0x184de
andq $0x0, -0x10(%rax,%r15)
movupd %xmm0, -0x58(%rax,%r15)
movupd %xmm0, -0x48(%rax,%r15)
movupd %xmm0, -0x38(%rax,%r15)
movq %rcx, (%rax,%r15)
movq %rdx, -0x8(%rax,%r15)
addq $0xe8, %rax
jmp 0x184aa
movq 0x1eceb3(%rip), %rax    # 0x205398
movq %rax, -0x48(%rbp)
xorl %ebx, %ebx
cmpq $0x1220, %rbx           # imm = 0x1220
je 0x185fe
cmpl $0x0, 0x1c(%rbx,%r15)
jne 0x1859d
movsd 0x28(%rbx,%r15), %xmm0
movsd %xmm0, 0xb8(%rbx,%r15)
movsd %xmm0, 0xb0(%rbx,%r15)
cmpq $0x2b8, %rbx            # imm = 0x2B8
jne 0x1853e
ucomisd 0xdabe0(%rip), %xmm0    # 0xf3110
jne 0x1859d
jp 0x1859d
movsd 0x2dea3c(%rip), %xmm0   # 0x2f6f78
jmp 0x18571
callq 0x57eca
testl %eax, %eax
sete %al
cmpq $0xe80, %rbx            # imm = 0xE80
setne %cl
orb %al, %cl
jne 0x185a9
movsd 0x28(%rbx,%r15), %xmm0
ucomisd 0xdabab(%rip), %xmm0    # 0xf3110
jne 0x1859d
jp 0x1859d
movsd 0x2de657(%rip), %xmm0   # 0x2f6bc8
ucomisd 0xdab9f(%rip), %xmm0    # 0xf3118
jne 0x1857d
jnp 0x1859d
callq 0x12952
movsd %xmm0, 0x28(%rbx,%r15)
movsd %xmm0, 0xb8(%rbx,%r15)
movsd %xmm0, 0xb0(%rbx,%r15)
addq $0xe8, %rbx
jmp 0x184eb
cmpq $0x740, %rbx            # imm = 0x740
jne 0x185d8
cmpb $0x0, 0x210985(%rip)    # 0x228f3e
je 0x185d8
movsd 0x28(%rbx,%r15), %xmm0
ucomisd 0xdab46(%rip), %xmm0    # 0xf3110
jne 0x1859d
jp 0x1859d
movsd 0x2de5e2(%rip), %xmm0   # 0x2f6bb8
jmp 0x1857d
cmpq $0x1d0, %rbx            # imm = 0x1D0
jne 0x1859d
movsd 0x28(%rbx,%r15), %xmm0
ucomisd 0xdab20(%rip), %xmm0    # 0xf3110
jne 0x1859d
jp 0x1859d
movsd 0x2de974(%rip), %xmm0   # 0x2f6f70
jmp 0x18582
andl $0x0, 0x1ecdc7(%rip)    # 0x2053cc
andq $0x0, 0x2de983(%rip)    # 0x2f6f90
andq $0x0, 0x1ecc5b(%rip)    # 0x205270
cvtsi2sdq -0x48(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x12f7d5(%rip), %rax    # 0x147dfc
xorl %ecx, %ecx
movq %rcx, %r13
cmpq $0x14, %rcx
je 0x18642
leaq 0x1(%r13), %rcx
cmpl $0x0, (%rax)
leaq 0xe8(%rax), %rax
je 0x18629
movq 0x1ecc1f(%rip), %r12    # 0x205268
movsd 0x2deedf(%rip), %xmm0   # 0x2f7530
movsd %xmm0, -0x40(%rbp)
leaq -0x170(%rbp), %r14
cmpq 0x1eccc4(%rip), %r12    # 0x205328
je 0x18a7f
cmpq $0x0, 0x1ecdfe(%rip)    # 0x205470
je 0x18681
movq %r14, %rdi
movq %r12, %rsi
callq 0x11478
jmp 0x1868c
movq %r14, %rdi
movq %r12, %rsi
callq 0xf9c7
cmpq $0x13, %r13
ja 0x186bb
leaq -0x1(%r12), %rsi
cmpq $0x0, 0x1ecdd1(%rip)    # 0x205470
je 0x186af
leaq -0x220(%rbp), %rdi
callq 0x11478
jmp 0x186bb
leaq -0x220(%rbp), %rdi
callq 0xf9c7
cmpq 0x1ecba6(%rip), %r12    # 0x205268
jne 0x186f9
movsd -0x168(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0xb0, %edx
leaq 0x311e8b(%rip), %rdi    # 0x32a568
movq %r14, %rsi
callq 0x92a0
movl $0xb0, %edx
leaq -0x220(%rbp), %rdi
movq %r14, %rsi
callq 0x92a0
cmpq $0x0, -0x48(%rbp)
setne %bl
movq %r14, %rdi
callq 0x18245
movl $0xb0, %edx
leaq 0x311e53(%rip), %rdi    # 0x32a568
movq %r14, %rsi
callq 0x92a0
cmpq $0x0, 0x1ecc73(%rip)    # 0x205398
setg %al
andb %bl, %al
cmpb $0x1, %al
jne 0x18a5a
movsd -0x108(%rbp), %xmm0
movsd -0x30(%rbp), %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x110(%rbp), %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x158(%rbp), %xmm0
mulsd -0x150(%rbp), %xmm0
movsd -0x118(%rbp), %xmm1
movsd -0x130(%rbp), %xmm3
mulsd -0x138(%rbp), %xmm3
divsd %xmm2, %xmm1
movsd %xmm1, -0x58(%rbp)
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
movapd %xmm0, %xmm4
cmpneqsd 0xda979(%rip), %xmm4    # 0xf3118
andpd %xmm4, %xmm1
andnpd %xmm0, %xmm4
orpd %xmm1, %xmm4
mulsd 0xda8ad(%rip), %xmm4    # 0xf3060
movapd %xmm4, -0xc0(%rbp)
divsd %xmm2, %xmm3
movsd %xmm3, -0x70(%rbp)
movsd -0x140(%rbp), %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x168(%rbp), %xmm0
movsd -0x160(%rbp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, -0x80(%rbp)
movsd -0x120(%rbp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, -0xa0(%rbp)
movsd -0xe0(%rbp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, -0x98(%rbp)
mulsd 0xda8a2(%rip), %xmm1    # 0xf30c0
movsd %xmm1, -0xa8(%rbp)
movsd -0x148(%rbp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, -0xb0(%rbp)
movsd %xmm0, -0x90(%rbp)
subsd -0x40(%rbp), %xmm0
mulsd 0xda7c9(%rip), %xmm0    # 0xf3018
movsd %xmm0, -0x88(%rbp)
leaq 0x12f5a2(%rip), %r14    # 0x147e00
xorl %ebx, %ebx
cmpq $0x3, %rbx
je 0x188a3
cmpq $0x14, %rbx
je 0x18a5a
callq 0x57eca
testl %eax, %eax
sete %al
cmpq $0x10, %rbx
setne %cl
orb %al, %cl
jne 0x188f5
movq 0x2de71c(%rip), %rax    # 0x2f6fa8
cmpb $0x66, (%rax)
movsd -0xa8(%rbp), %xmm0
je 0x188b0
movsd -0x98(%rbp), %xmm0
jmp 0x188b0
movsd -0xb0(%rbp), %xmm0
callq 0x12952
cmpl $0x0, -0x4(%r14)
je 0x188ce
movsd -0x160(%rbp,%rbx,8), %xmm1
subsd -0x210(%rbp,%rbx,8), %xmm1
jmp 0x18988
movsd %xmm0, -0x50(%rbp)
movl %ebx, %edi
callq 0x13376
testl %eax, %eax
je 0x18915
cmpl $0x0, (%r14)
je 0x18915
movl %ebx, %edi
movsd -0x50(%rbp), %xmm0
callq 0x9daff
jmp 0x18984
movb 0x210643(%rip), %al     # 0x228f3e
testb %al, %al
sete %cl
cmpq $0x8, %rbx
setne %dl
orb %cl, %dl
jne 0x18940
movsd -0xa0(%rbp), %xmm0
jmp 0x188ab
movl %ebx, %eax
andl $0x1c, %eax
cmpl $0x4, %eax
movsd -0x50(%rbp), %xmm1
jne 0x18961
cmpq $0x10000, 0x1e9fa1(%rip) # imm = 0x10000
jne 0x18961
movl %ebx, %edi
pushq $0x1
popq %rsi
movsd -0x90(%rbp), %xmm0
jmp 0x1897f
testb %al, %al
sete %cl
testq %rbx, %rbx
setne %dl
orb %cl, %dl
jne 0x189b7
movsd 0x1e9f59(%rip), %xmm0   # 0x2028b0
mulsd -0x80(%rbp), %xmm0
jmp 0x188b0
movsd -0x30(%r14), %xmm0
ucomisd 0xda7a9(%rip), %xmm0    # 0xf3118
jne 0x18973
jnp 0x18988
movl %ebx, %edi
xorl %esi, %esi
movsd -0x88(%rbp), %xmm0
callq 0x133fc
movapd %xmm0, %xmm1
ucomisd -0x18(%r14), %xmm1
jbe 0x18996
movsd %xmm1, -0x18(%r14)
movsd -0x20(%r14), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x189a8
movsd %xmm1, -0x20(%r14)
incq %rbx
addq $0xe8, %r14
jmp 0x18860
testb %al, %al
sete %cl
cmpq $0x4, %rbx
setne %dl
orb %cl, %dl
jne 0x189d9
movsd 0x1e9ee9(%rip), %xmm0   # 0x2028b8
mulsd -0x78(%rbp), %xmm0
jmp 0x188b0
cmpq $0x10, %rbx
jb 0x18a47
testb %al, %al
setne %cl
cmpq $0x10, %rbx
sete %dl
movsd -0x70(%rbp), %xmm0
testb %cl, %dl
jne 0x188b0
testb %al, %al
setne %cl
cmpq $0x11, %rbx
sete %dl
movapd -0xc0(%rbp), %xmm0
testb %cl, %dl
jne 0x188b0
testb %al, %al
sete %al
cmpq $0x12, %rbx
setne %cl
orb %al, %cl
jne 0x18a47
movzbl 0x2de53d(%rip), %edi    # 0x2f6f68
pushq $0x1
popq %rsi
movsd -0x68(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
movsd -0x58(%rbp), %xmm2
callq 0x702c1
jmp 0x188b0
movsd -0x160(%rbp,%rbx,8), %xmm0
divsd -0x30(%rbp), %xmm0
jmp 0x188b0
movq %r12, 0x1ec80f(%rip)    # 0x205270
movq %r12, %rdi
movl -0x34(%rbp), %esi
callq 0x10d47
movq %rax, %r12
testq %rax, %rax
leaq -0x170(%rbp), %r14
jns 0x1865d
movsd 0x2de509(%rip), %xmm0   # 0x2f6f90
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x18aa5
jp 0x18aa5
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x98, %eax
cmpq $0x12b8, %rax           # imm = 0x12B8
je 0x18a93
movsd -0x18(%rax,%r15), %xmm1
movsd -0x38(%rax,%r15), %xmm3
movsd -0x30(%rax,%r15), %xmm2
movsd -0x28(%rax,%r15), %xmm4
movapd %xmm3, %xmm5
mulsd %xmm3, %xmm5
divsd %xmm0, %xmm5
subsd %xmm5, %xmm4
movsd %xmm0, -0x10(%rax,%r15)
xorpd %xmm5, %xmm5
ucomisd %xmm5, %xmm4
xorpd %xmm6, %xmm6
jne 0x18af5
jnp 0x18b21
movapd %xmm3, %xmm5
mulsd %xmm2, %xmm5
divsd %xmm0, %xmm5
subsd %xmm5, %xmm1
divsd %xmm4, %xmm1
divsd %xmm0, %xmm2
divsd %xmm0, %xmm3
mulsd %xmm1, %xmm3
subsd %xmm3, %xmm2
movapd %xmm2, %xmm5
movapd %xmm1, %xmm6
movsd %xmm5, -0x8(%rax,%r15)
movsd %xmm6, (%rax,%r15)
addq $0xe8, %rax
jmp 0x18aaa