// File: jkingan[P]ladyheather/heather.cpp
// Function: forward_filter(long)
struct PLOT_Q forward_filter(long point)
{
struct PLOT_Q avg;
struct PLOT_Q q;
DATA_SIZE count;
DATA_SIZE max[NUM_PLOTS+DERIVED_PLOTS];
DATA_SIZE min[NUM_PLOTS+DERIVED_PLOTS];
long i;
long f_count;
int j;

   // average the next "filter_count" queue entries
   avg = get_plot_q(point);
   filter_jd = avg.q_jd;
   filter_flags = avg.sat_flags;
   count = 1.0F;

   if(point == plot_q_in) return avg;

   if(disp_filter_type == 'P') {  // min/max filter
      for(j=0; j<NUM_PLOTS+DERIVED_PLOTS; j++) {
         if(j != FFT) {
            max[j] = min[j] = avg.data[j];
         }
      }
   }

   f_count = disp_filter_size();
   for(i=1; i<f_count; i++) {
      if(++point == plot_q_in) {  // at the end of the plot data
         break;
      }
      while(point >= plot_q_size) point -= plot_q_size;

      q = get_plot_q(point);
      filter_flags |= q.sat_flags;
      count += (DATA_SIZE) 1.0;

      for(j=0; j<NUM_PLOTS+DERIVED_PLOTS; j++) {
         if(j != FFT) {
            if(disp_filter_type == 'P') {
               if(q.data[j] > max[j]) max[j] = q.data[j];
               if(q.data[j] < min[j]) min[j] = q.data[j];
            }

            avg.data[j] += q.data[j];
         }
      }
   }

   for(j=0; j<NUM_PLOTS+DERIVED_PLOTS; j++) {  // derived_plots OK
      if(j != FFT) {
         if(disp_filter_type == 'P') {
            if(fabs(max[j]) >= fabs(min[j])) avg.data[j] = max[j];
            else                             avg.data[j] = min[j];
         }
         else {
            avg.data[j] /= count;
         }
      }
   }

   return avg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x390, %rsp            # imm = 0x390
movq %rdi, -0x380(%rbp)
movq %rdi, -0x388(%rbp)
movq %rsi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x2c8(%rbp), %rdi
callq 0x133f0
movq -0x380(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
movq -0x380(%rbp), %rdi
movsd 0x8(%rdi), %xmm0
movsd %xmm0, 0x389647(%rip)   # 0x39f430
movw (%rdi), %ax
movw %ax, 0x389645(%rip)     # 0x39f438
movsd 0x15926d(%rip), %xmm0   # 0x16f068
movsd %xmm0, -0xc0(%rbp)
movq -0x8(%rbp), %rax
cmpq 0x2646fa(%rip), %rax    # 0x27a508
jne 0x15e15
jmp 0x1614f
cmpl $0x50, 0x26483c(%rip)   # 0x27a658
jne 0x15e83
movl $0x0, -0x214(%rbp)
cmpl $0x14, -0x214(%rbp)
jge 0x15e81
cmpl $0xe, -0x214(%rbp)
je 0x15e6e
movq -0x380(%rbp), %rax
movslq -0x214(%rbp), %rcx
movsd 0x10(%rax,%rcx,8), %xmm0
movslq -0x214(%rbp), %rax
movsd %xmm0, -0x200(%rbp,%rax,8)
movslq -0x214(%rbp), %rax
movsd %xmm0, -0x160(%rbp,%rax,8)
jmp 0x15e70
movl -0x214(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x214(%rbp)
jmp 0x15e28
jmp 0x15e83
callq 0x15430
movq %rax, -0x210(%rbp)
movq $0x1, -0x208(%rbp)
movq -0x208(%rbp), %rax
cmpq -0x210(%rbp), %rax
jge 0x16056
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
cmpq 0x264647(%rip), %rax    # 0x27a508
jne 0x15ec8
jmp 0x16056
jmp 0x15eca
movq -0x8(%rbp), %rax
cmpq 0x26462b(%rip), %rax    # 0x27a500
jl 0x15eeb
movq 0x264622(%rip), %rcx    # 0x27a500
movq -0x8(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x8(%rbp)
jmp 0x15eca
movq -0x8(%rbp), %rsi
leaq -0x378(%rbp), %rdi
callq 0x133f0
leaq -0xb8(%rbp), %rdi
leaq -0x378(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
movzwl -0xb8(%rbp), %ecx
movzwl 0x389517(%rip), %eax    # 0x39f438
orl %ecx, %eax
movw %ax, 0x38950e(%rip)     # 0x39f438
movsd 0x159136(%rip), %xmm0   # 0x16f068
addsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movl $0x0, -0x214(%rbp)
cmpl $0x14, -0x214(%rbp)
jge 0x1603d
cmpl $0xe, -0x214(%rbp)
je 0x16027
cmpl $0x50, 0x2646eb(%rip)   # 0x27a658
jne 0x15ffd
movslq -0x214(%rbp), %rax
movsd -0xa8(%rbp,%rax,8), %xmm0
movslq -0x214(%rbp), %rax
ucomisd -0x160(%rbp,%rax,8), %xmm0
jbe 0x15fb5
movslq -0x214(%rbp), %rax
movsd -0xa8(%rbp,%rax,8), %xmm0
movslq -0x214(%rbp), %rax
movsd %xmm0, -0x160(%rbp,%rax,8)
movslq -0x214(%rbp), %rax
movsd -0xa8(%rbp,%rax,8), %xmm1
movslq -0x214(%rbp), %rax
movsd -0x200(%rbp,%rax,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x15ffb
movslq -0x214(%rbp), %rax
movsd -0xa8(%rbp,%rax,8), %xmm0
movslq -0x214(%rbp), %rax
movsd %xmm0, -0x200(%rbp,%rax,8)
jmp 0x15ffd
movq -0x380(%rbp), %rax
movslq -0x214(%rbp), %rcx
movsd -0xa8(%rbp,%rcx,8), %xmm0
movslq -0x214(%rbp), %rcx
addsd 0x10(%rax,%rcx,8), %xmm0
movsd %xmm0, 0x10(%rax,%rcx,8)
jmp 0x16029
movl -0x214(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x214(%rbp)
jmp 0x15f4c
jmp 0x1603f
movq -0x208(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x208(%rbp)
jmp 0x15e9a
movl $0x0, -0x214(%rbp)
cmpl $0x14, -0x214(%rbp)
jge 0x1614d
cmpl $0xe, -0x214(%rbp)
je 0x16137
cmpl $0x50, 0x2645d7(%rip)   # 0x27a658
jne 0x1610f
movslq -0x214(%rbp), %rax
movsd -0x160(%rbp,%rax,8), %xmm0
movaps 0x1591f2(%rip), %xmm1   # 0x16f290
pand %xmm1, %xmm0
movslq -0x214(%rbp), %rax
movsd -0x200(%rbp,%rax,8), %xmm1
movaps 0x1591d7(%rip), %xmm2   # 0x16f290
pand %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x160e9
movq -0x380(%rbp), %rax
movslq -0x214(%rbp), %rcx
movsd -0x160(%rbp,%rcx,8), %xmm0
movslq -0x214(%rbp), %rcx
movsd %xmm0, 0x10(%rax,%rcx,8)
jmp 0x1610d
movq -0x380(%rbp), %rax
movslq -0x214(%rbp), %rcx
movsd -0x200(%rbp,%rcx,8), %xmm0
movslq -0x214(%rbp), %rcx
movsd %xmm0, 0x10(%rax,%rcx,8)
jmp 0x16135
movq -0x380(%rbp), %rax
movsd -0xc0(%rbp), %xmm1
movslq -0x214(%rbp), %rcx
movsd 0x10(%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rax,%rcx,8)
jmp 0x16137
jmp 0x16139
movl -0x214(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x214(%rbp)
jmp 0x16060
jmp 0x1614f
movq -0x388(%rbp), %rax
addq $0x390, %rsp            # imm = 0x390
popq %rbp
retq
nop