// File: /workspace/github_cpp_makefile_star2_O3/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 0x144dcb(%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 0x18f7d
movq 0x2023e2(%rip), %rax    # 0x21b398
movq %rax, -0x50(%rbp)
xorl %r14d, %r14d
cmpl $0x0, 0x1c(%r14,%rbx)
jne 0x19062
movsd 0x28(%r14,%rbx), %xmm0
movsd %xmm0, 0xb8(%r14,%rbx)
movsd %xmm0, 0xb0(%r14,%rbx)
cmpq $0x2b8, %r14            # imm = 0x2B8
jne 0x19003
ucomisd 0xf011b(%rip), %xmm0    # 0x109110
jne 0x19062
jp 0x19062
movsd 0x2f3f77(%rip), %xmm0   # 0x30cf78
jmp 0x19036
callq 0x5f6cb
testl %eax, %eax
sete %al
cmpq $0xe80, %r14            # imm = 0xE80
setne %cl
orb %al, %cl
jne 0x19078
movsd 0x28(%r14,%rbx), %xmm0
ucomisd 0xf00e6(%rip), %xmm0    # 0x109110
jne 0x19062
jp 0x19062
movsd 0x2f3b92(%rip), %xmm0   # 0x30cbc8
ucomisd 0xf00da(%rip), %xmm0    # 0x109118
jne 0x19042
jnp 0x19062
callq 0x131c9
movsd %xmm0, 0x28(%r14,%rbx)
movsd %xmm0, 0xb8(%r14,%rbx)
movsd %xmm0, 0xb0(%r14,%rbx)
addq $0xe8, %r14
cmpq $0x1220, %r14           # imm = 0x1220
jne 0x18fbd
jmp 0x190d0
cmpq $0x740, %r14            # imm = 0x740
jne 0x190a7
cmpb $0x0, 0x225eb6(%rip)    # 0x23ef3e
je 0x190a7
movsd 0x28(%r14,%rbx), %xmm0
ucomisd 0xf0077(%rip), %xmm0    # 0x109110
jne 0x19062
jp 0x19062
movsd 0x2f3b13(%rip), %xmm0   # 0x30cbb8
jmp 0x19042
cmpq $0x1d0, %r14            # imm = 0x1D0
jne 0x19062
movsd 0x28(%r14,%rbx), %xmm0
ucomisd 0xf0051(%rip), %xmm0    # 0x109110
jne 0x19062
jp 0x19062
movsd 0x2f3ea5(%rip), %xmm0   # 0x30cf70
jmp 0x19047
movl $0x0, 0x2022f2(%rip)    # 0x21b3cc
xorl %eax, %eax
movq %rax, 0x2f3ead(%rip)    # 0x30cf90
movq $0x0, -0x48(%rbp)
movq %rax, 0x20217e(%rip)    # 0x21b270
cmpl $0x0, 0x144d03(%rip)    # 0x15ddfc
jne 0x19128
leaq 0x144de2(%rip), %rax    # 0x15dee4
xorl %edx, %edx
movq %rdx, %rcx
cmpq $0x13, %rdx
je 0x1911d
cmpl $0x0, (%rax)
leaq 0xe8(%rax), %rax
leaq 0x1(%rcx), %rdx
je 0x19104
cmpq $0x13, %rcx
setae %al
movq %rax, -0x48(%rbp)
xorps %xmm0, %xmm0
cvtsi2sdq -0x50(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x20212b(%rip), %r12    # 0x21b268
movsd 0x2f43eb(%rip), %xmm0   # 0x30d530
movsd %xmm0, -0x40(%rbp)
leaq -0x180(%rbp), %r14
cmpq 0x2021d0(%rip), %r12    # 0x21b328
je 0x19584
cmpq $0x0, 0x20230a(%rip)    # 0x21b470
je 0x19175
movq %r14, %rdi
movq %r12, %rsi
callq 0x11bc7
jmp 0x19180
movq %r14, %rdi
movq %r12, %rsi
callq 0x100be
cmpb $0x0, -0x48(%rbp)
jne 0x191af
leaq -0x1(%r12), %rsi
cmpq $0x0, 0x2022dd(%rip)    # 0x21b470
je 0x191a3
leaq -0x230(%rbp), %rdi
callq 0x11bc7
jmp 0x191af
leaq -0x230(%rbp), %rdi
callq 0x100be
cmpq 0x2020b2(%rip), %r12    # 0x21b268
jne 0x191ed
movsd -0x178(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0xb0, %edx
leaq 0x327397(%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 0x18d1a
movl $0xb0, %edx
leaq 0x32735e(%rip), %rdi    # 0x340568
movq %r14, %rsi
callq 0x92b0
cmpq $0x0, 0x20217e(%rip)    # 0x21b398
setg %al
andb %r15b, %al
cmpb $0x1, %al
jne 0x19566
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 0xefe83(%rip), %xmm4    # 0x109118
andpd %xmm4, %xmm1
andnpd %xmm0, %xmm4
orpd %xmm1, %xmm4
mulsd 0xefdb7(%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 0xefda9(%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 0xefcd0(%rip), %xmm0    # 0x109018
movsd %xmm0, -0x90(%rbp)
leaq 0x144aa9(%rip), %r15    # 0x15de00
xorl %r13d, %r13d
cmpq $0x3, %r13
jne 0x1938d
movsd -0xb8(%rbp), %xmm0
callq 0x131c9
cmpl $0x0, -0x4(%r15)
je 0x193c0
movsd -0x170(%rbp,%r13,8), %xmm1
subsd -0x220(%rbp,%r13,8), %xmm1
jmp 0x19487
callq 0x5f6cb
testl %eax, %eax
sete %al
cmpq $0x10, %r13
setne %cl
orb %al, %cl
jne 0x193e9
movq 0x2f3bff(%rip), %rax    # 0x30cfa8
cmpb $0x66, (%rax)
movsd -0xb0(%rbp), %xmm0
je 0x1936d
movsd -0xa0(%rbp), %xmm0
jmp 0x1936d
movsd %xmm0, -0x58(%rbp)
movl %r13d, %edi
callq 0x13c3e
testl %eax, %eax
je 0x1940c
cmpl $0x0, (%r15)
je 0x1940c
movl %r13d, %edi
movsd -0x58(%rbp), %xmm0
callq 0xadb42
jmp 0x19483
movb 0x225b4f(%rip), %al     # 0x23ef3e
testb %al, %al
sete %cl
cmpq $0x8, %r13
setne %dl
orb %cl, %dl
jne 0x1943b
movsd -0xa8(%rbp), %xmm0
jmp 0x19368
movl %r13d, %eax
andl $0x1c, %eax
cmpl $0x4, %eax
movsd -0x58(%rbp), %xmm1
jne 0x1945f
cmpq $0x10000, 0x1ff4a9(%rip) # imm = 0x10000
jne 0x1945f
movl %r13d, %edi
movl $0x1, %esi
movsd -0x98(%rbp), %xmm0
jmp 0x1947e
testb %al, %al
sete %cl
testq %r13, %r13
setne %dl
orb %cl, %dl
jne 0x194c0
movsd 0x1ff45e(%rip), %xmm0   # 0x2188b0
mulsd -0x88(%rbp), %xmm0
jmp 0x1936d
movsd -0x30(%r15), %xmm0
ucomisd 0xefcab(%rip), %xmm0    # 0x109118
jne 0x19471
jnp 0x19487
movl %r13d, %edi
xorl %esi, %esi
movsd -0x90(%rbp), %xmm0
callq 0x13cce
movapd %xmm0, %xmm1
ucomisd -0x18(%r15), %xmm1
jbe 0x19495
movsd %xmm1, -0x18(%r15)
movsd -0x20(%r15), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x194a7
movsd %xmm1, -0x20(%r15)
incq %r13
addq $0xe8, %r15
cmpq $0x14, %r13
jne 0x1935a
jmp 0x19566
testb %al, %al
sete %cl
cmpq $0x4, %r13
setne %dl
orb %cl, %dl
jne 0x194e2
movsd 0x1ff3e0(%rip), %xmm0   # 0x2188b8
mulsd -0x80(%rbp), %xmm0
jmp 0x1936d
cmpq $0x10, %r13
jb 0x19552
testb %al, %al
setne %cl
cmpq $0x10, %r13
sete %dl
movsd -0x78(%rbp), %xmm0
testb %cl, %dl
jne 0x1936d
testb %al, %al
setne %cl
cmpq $0x11, %r13
sete %dl
movapd -0xd0(%rbp), %xmm0
testb %cl, %dl
jne 0x1936d
testb %al, %al
sete %al
cmpq $0x12, %r13
setne %cl
orb %al, %cl
jne 0x19552
movzbl 0x2f3a34(%rip), %edi    # 0x30cf68
movl $0x1, %esi
movsd -0x70(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
movsd -0x60(%rbp), %xmm2
callq 0x7aa82
jmp 0x1936d
movsd -0x170(%rbp,%r13,8), %xmm0
divsd -0x30(%rbp), %xmm0
jmp 0x1936d
movq %r12, 0x201d03(%rip)    # 0x21b270
movq %r12, %rdi
movl -0x34(%rbp), %esi
callq 0x1144e
movq %rax, %r12
testq %rax, %rax
jns 0x19151
movsd 0x2f3a04(%rip), %xmm0   # 0x30cf90
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1959c
jnp 0x19628
movl $0x98, %eax
movsd -0x18(%rax,%rbx), %xmm1
movsd -0x38(%rax,%rbx), %xmm3
movsd -0x30(%rax,%rbx), %xmm2
movsd -0x28(%rax,%rbx), %xmm4
movapd %xmm3, %xmm5
mulsd %xmm3, %xmm5
divsd %xmm0, %xmm5
subsd %xmm5, %xmm4
movsd %xmm0, -0x10(%rax,%rbx)
xorpd %xmm5, %xmm5
ucomisd %xmm5, %xmm4
xorpd %xmm6, %xmm6
jne 0x195df
jnp 0x1960b
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,%rbx)
movsd %xmm6, (%rax,%rbx)
addq $0xe8, %rax
cmpq $0x12b8, %rax           # imm = 0x12B8
jne 0x195a1
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq