// File: /workspace/github_cpp_makefile_star2_O1/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 $0x208, %rsp            # imm = 0x208
movl %edi, -0x34(%rbp)
movl $0xb8, %eax
leaq 0x144ddf(%rip), %rbx    # 0x15dd30
xorpd %xmm0, %xmm0
movabsq $-0x3a0bce1f051928df, %rcx # imm = 0xC5F431E0FAE6D721
movabsq $0x45f431e0fae6d721, %rdx # imm = 0x45F431E0FAE6D721
movq $0x0, -0x10(%rax,%rbx)
movupd %xmm0, -0x58(%rax,%rbx)
movupd %xmm0, -0x48(%rax,%rbx)
movupd %xmm0, -0x38(%rax,%rbx)
movq %rcx, (%rax,%rbx)
movq %rdx, -0x8(%rax,%rbx)
addq $0xe8, %rax
cmpq $0x12d8, %rax           # imm = 0x12D8
jne 0x18f69
movq 0x2023f6(%rip), %rax    # 0x21b398
movq %rax, -0x50(%rbp)
xorl %r14d, %r14d
cmpl $0x0, 0x1c(%r14,%rbx)
jne 0x1904e
movsd 0x28(%r14,%rbx), %xmm0
movsd %xmm0, 0xb8(%r14,%rbx)
movsd %xmm0, 0xb0(%r14,%rbx)
cmpq $0x2b8, %r14            # imm = 0x2B8
jne 0x18fef
ucomisd 0xf012f(%rip), %xmm0    # 0x109110
jne 0x1904e
jp 0x1904e
movsd 0x2f3f8b(%rip), %xmm0   # 0x30cf78
jmp 0x19022
callq 0x5f743
testl %eax, %eax
sete %al
cmpq $0xe80, %r14            # imm = 0xE80
setne %cl
orb %al, %cl
jne 0x19064
movsd 0x28(%r14,%rbx), %xmm0
ucomisd 0xf00fa(%rip), %xmm0    # 0x109110
jne 0x1904e
jp 0x1904e
movsd 0x2f3ba6(%rip), %xmm0   # 0x30cbc8
ucomisd 0xf00ee(%rip), %xmm0    # 0x109118
jne 0x1902e
jnp 0x1904e
callq 0x1325e
movsd %xmm0, 0x28(%r14,%rbx)
movsd %xmm0, 0xb8(%r14,%rbx)
movsd %xmm0, 0xb0(%r14,%rbx)
addq $0xe8, %r14
cmpq $0x1220, %r14           # imm = 0x1220
jne 0x18fa9
jmp 0x190bc
cmpq $0x740, %r14            # imm = 0x740
jne 0x19093
cmpb $0x0, 0x225eca(%rip)    # 0x23ef3e
je 0x19093
movsd 0x28(%r14,%rbx), %xmm0
ucomisd 0xf008b(%rip), %xmm0    # 0x109110
jne 0x1904e
jp 0x1904e
movsd 0x2f3b27(%rip), %xmm0   # 0x30cbb8
jmp 0x1902e
cmpq $0x1d0, %r14            # imm = 0x1D0
jne 0x1904e
movsd 0x28(%r14,%rbx), %xmm0
ucomisd 0xf0065(%rip), %xmm0    # 0x109110
jne 0x1904e
jp 0x1904e
movsd 0x2f3eb9(%rip), %xmm0   # 0x30cf70
jmp 0x19033
movl $0x0, 0x202306(%rip)    # 0x21b3cc
xorl %eax, %eax
movq %rax, 0x2f3ec1(%rip)    # 0x30cf90
movq $0x0, -0x48(%rbp)
movq %rax, 0x202192(%rip)    # 0x21b270
cmpl $0x0, 0x144d17(%rip)    # 0x15ddfc
jne 0x19114
leaq 0x144df6(%rip), %rax    # 0x15dee4
xorl %edx, %edx
movq %rdx, %rcx
cmpq $0x13, %rdx
je 0x19109
cmpl $0x0, (%rax)
leaq 0xe8(%rax), %rax
leaq 0x1(%rcx), %rdx
je 0x190f0
cmpq $0x13, %rcx
setae %al
movq %rax, -0x48(%rbp)
xorps %xmm0, %xmm0
cvtsi2sdq -0x50(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x20213f(%rip), %r12    # 0x21b268
movsd 0x2f43ff(%rip), %xmm0   # 0x30d530
movsd %xmm0, -0x40(%rbp)
leaq -0x180(%rbp), %r14
cmpq 0x2021e4(%rip), %r12    # 0x21b328
je 0x19570
cmpq $0x0, 0x20231e(%rip)    # 0x21b470
je 0x19161
movq %r14, %rdi
movq %r12, %rsi
callq 0x11c44
jmp 0x1916c
movq %r14, %rdi
movq %r12, %rsi
callq 0x10141
cmpb $0x0, -0x48(%rbp)
jne 0x1919b
leaq -0x1(%r12), %rsi
cmpq $0x0, 0x2022f1(%rip)    # 0x21b470
je 0x1918f
leaq -0x230(%rbp), %rdi
callq 0x11c44
jmp 0x1919b
leaq -0x230(%rbp), %rdi
callq 0x10141
cmpq 0x2020c6(%rip), %r12    # 0x21b268
jne 0x191d9
movsd -0x178(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0xb0, %edx
leaq 0x3273ab(%rip), %rdi    # 0x340568
movq %r14, %rsi
callq 0x92b0
movl $0xb0, %edx
leaq -0x230(%rbp), %rdi
movq %r14, %rsi
callq 0x92b0
cmpq $0x0, -0x50(%rbp)
setne %r15b
movq %r14, %rdi
callq 0x18d06
movl $0xb0, %edx
leaq 0x327372(%rip), %rdi    # 0x340568
movq %r14, %rsi
callq 0x92b0
cmpq $0x0, 0x202192(%rip)    # 0x21b398
setg %al
andb %r15b, %al
cmpb $0x1, %al
jne 0x19552
movsd -0x118(%rbp), %xmm0
movsd -0x30(%rbp), %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x120(%rbp), %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x168(%rbp), %xmm0
mulsd -0x160(%rbp), %xmm0
movsd -0x128(%rbp), %xmm1
movsd -0x140(%rbp), %xmm3
mulsd -0x148(%rbp), %xmm3
divsd %xmm2, %xmm1
movsd %xmm1, -0x60(%rbp)
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
movapd %xmm0, %xmm4
cmpneqsd 0xefe97(%rip), %xmm4    # 0x109118
andpd %xmm4, %xmm1
andnpd %xmm0, %xmm4
orpd %xmm1, %xmm4
mulsd 0xefdcb(%rip), %xmm4    # 0x109060
movapd %xmm4, -0xd0(%rbp)
divsd %xmm2, %xmm3
movsd %xmm3, -0x78(%rbp)
movsd -0x150(%rbp), %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x178(%rbp), %xmm0
movsd -0x170(%rbp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, -0x88(%rbp)
movsd -0x130(%rbp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, -0xa8(%rbp)
movsd -0xf0(%rbp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, -0xa0(%rbp)
mulsd 0xefdbd(%rip), %xmm1    # 0x1090c0
movsd %xmm1, -0xb0(%rbp)
movsd -0x158(%rbp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, -0xb8(%rbp)
movsd %xmm0, -0x98(%rbp)
subsd -0x40(%rbp), %xmm0
mulsd 0xefce4(%rip), %xmm0    # 0x109018
movsd %xmm0, -0x90(%rbp)
leaq 0x144abd(%rip), %r15    # 0x15de00
xorl %r13d, %r13d
cmpq $0x3, %r13
jne 0x19379
movsd -0xb8(%rbp), %xmm0
callq 0x1325e
cmpl $0x0, -0x4(%r15)
je 0x193ac
movsd -0x170(%rbp,%r13,8), %xmm1
subsd -0x220(%rbp,%r13,8), %xmm1
jmp 0x19473
callq 0x5f743
testl %eax, %eax
sete %al
cmpq $0x10, %r13
setne %cl
orb %al, %cl
jne 0x193d5
movq 0x2f3c13(%rip), %rax    # 0x30cfa8
cmpb $0x66, (%rax)
movsd -0xb0(%rbp), %xmm0
je 0x19359
movsd -0xa0(%rbp), %xmm0
jmp 0x19359
movsd %xmm0, -0x58(%rbp)
movl %r13d, %edi
callq 0x13ccd
testl %eax, %eax
je 0x193f8
cmpl $0x0, (%r15)
je 0x193f8
movl %r13d, %edi
movsd -0x58(%rbp), %xmm0
callq 0xad8a2
jmp 0x1946f
movb 0x225b63(%rip), %al     # 0x23ef3e
testb %al, %al
sete %cl
cmpq $0x8, %r13
setne %dl
orb %cl, %dl
jne 0x19427
movsd -0xa8(%rbp), %xmm0
jmp 0x19354
movl %r13d, %eax
andl $0x1c, %eax
cmpl $0x4, %eax
movsd -0x58(%rbp), %xmm1
jne 0x1944b
cmpq $0x10000, 0x1ff4bd(%rip) # imm = 0x10000
jne 0x1944b
movl %r13d, %edi
movl $0x1, %esi
movsd -0x98(%rbp), %xmm0
jmp 0x1946a
testb %al, %al
sete %cl
testq %r13, %r13
setne %dl
orb %cl, %dl
jne 0x194ac
movsd 0x1ff472(%rip), %xmm0   # 0x2188b0
mulsd -0x88(%rbp), %xmm0
jmp 0x19359
movsd -0x30(%r15), %xmm0
ucomisd 0xefcbf(%rip), %xmm0    # 0x109118
jne 0x1945d
jnp 0x19473
movl %r13d, %edi
xorl %esi, %esi
movsd -0x90(%rbp), %xmm0
callq 0x13d5d
movapd %xmm0, %xmm1
ucomisd -0x18(%r15), %xmm1
jbe 0x19481
movsd %xmm1, -0x18(%r15)
movsd -0x20(%r15), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x19493
movsd %xmm1, -0x20(%r15)
incq %r13
addq $0xe8, %r15
cmpq $0x14, %r13
jne 0x19346
jmp 0x19552
testb %al, %al
sete %cl
cmpq $0x4, %r13
setne %dl
orb %cl, %dl
jne 0x194ce
movsd 0x1ff3f4(%rip), %xmm0   # 0x2188b8
mulsd -0x80(%rbp), %xmm0
jmp 0x19359
cmpq $0x10, %r13
jb 0x1953e
testb %al, %al
setne %cl
cmpq $0x10, %r13
sete %dl
movsd -0x78(%rbp), %xmm0
testb %cl, %dl
jne 0x19359
testb %al, %al
setne %cl
cmpq $0x11, %r13
sete %dl
movapd -0xd0(%rbp), %xmm0
testb %cl, %dl
jne 0x19359
testb %al, %al
sete %al
cmpq $0x12, %r13
setne %cl
orb %al, %cl
jne 0x1953e
movzbl 0x2f3a48(%rip), %edi    # 0x30cf68
movl $0x1, %esi
movsd -0x70(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
movsd -0x60(%rbp), %xmm2
callq 0x7ace4
jmp 0x19359
movsd -0x170(%rbp,%r13,8), %xmm0
divsd -0x30(%rbp), %xmm0
jmp 0x19359
movq %r12, 0x201d17(%rip)    # 0x21b270
movq %r12, %rdi
movl -0x34(%rbp), %esi
callq 0x114d6
movq %rax, %r12
testq %rax, %rax
jns 0x1913d
movsd 0x2f3a18(%rip), %xmm0   # 0x30cf90
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x19588
jnp 0x1960c
movl $0x98, %eax
xorpd %xmm2, %xmm2
movsd -0x18(%rax,%rbx), %xmm5
movsd -0x38(%rax,%rbx), %xmm4
movsd -0x30(%rax,%rbx), %xmm3
movsd -0x28(%rax,%rbx), %xmm6
movapd %xmm4, %xmm7
mulsd %xmm4, %xmm7
divsd %xmm0, %xmm7
subsd %xmm7, %xmm6
movsd %xmm0, -0x10(%rax,%rbx)
ucomisd %xmm1, %xmm6
jne 0x195cf
jp 0x195cf
movupd %xmm2, -0x8(%rax,%rbx)
jmp 0x195fe
movapd %xmm4, %xmm7
mulsd %xmm3, %xmm7
divsd %xmm0, %xmm7
subsd %xmm7, %xmm5
divsd %xmm6, %xmm5
movsd %xmm5, (%rax,%rbx)
divsd %xmm0, %xmm3
divsd %xmm0, %xmm4
mulsd %xmm5, %xmm4
subsd %xmm4, %xmm3
movsd %xmm3, -0x8(%rax,%rbx)
addq $0xe8, %rax
cmpq $0x12b8, %rax           # imm = 0x12B8
jne 0x19591
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq