// File: jkingan[P]ladyheather/heather.cpp
// Function: back_filter(long)
struct PLOT_Q back_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;
int j;

   // average the previous "filter_count" queue entries

   if(plot_q_count < filter_count) i = plot_q_count;
   else                            i = disp_filter_size();

   point -= i;
   if(point < 0) point += plot_q_size;
//   if(point >= plot_q_count) point = 0;

   avg = get_plot_q(point);
   filter_jd = avg.q_jd;
   filter_flags = avg.sat_flags;
   count = 1.0F;

   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];
         }
      }
   }

   while(--i > 0) {
      ++point;
      while(point >= plot_q_size) point -= plot_q_size;

      q = get_plot_q(point);
      filter_jd = q.q_jd;
      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 $0x380, %rsp            # imm = 0x380
movq %rdi, -0x380(%rbp)
movq %rdi, -0x378(%rbp)
movq %rsi, -0x8(%rbp)
movq 0x264fa4(%rip), %rax    # 0x27a518
cmpq 0x2650d5(%rip), %rax    # 0x27a650
jge 0x1558d
movq 0x264f94(%rip), %rax    # 0x27a518
movq %rax, -0x208(%rbp)
jmp 0x15599
callq 0x15430
movq %rax, -0x208(%rbp)
movq -0x208(%rbp), %rcx
movq -0x8(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jge 0x155c1
movq 0x264f47(%rip), %rax    # 0x27a500
addq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x2c0(%rbp), %rdi
callq 0x133f0
movq -0x380(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
movq -0x380(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x389e33(%rip)   # 0x39f430
movw (%rax), %ax
movw %ax, 0x389e31(%rip)     # 0x39f438
movsd 0x159a59(%rip), %xmm0   # 0x16f068
movsd %xmm0, -0xc0(%rbp)
cmpl $0x50, 0x26503a(%rip)   # 0x27a658
jne 0x15685
movl $0x0, -0x20c(%rbp)
cmpl $0x14, -0x20c(%rbp)
jge 0x15683
cmpl $0xe, -0x20c(%rbp)
je 0x15670
movq -0x380(%rbp), %rax
movslq -0x20c(%rbp), %rcx
movsd 0x10(%rax,%rcx,8), %xmm0
movslq -0x20c(%rbp), %rax
movsd %xmm0, -0x200(%rbp,%rax,8)
movslq -0x20c(%rbp), %rax
movsd %xmm0, -0x160(%rbp,%rax,8)
jmp 0x15672
movl -0x20c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20c(%rbp)
jmp 0x1562a
jmp 0x15685
jmp 0x15687
movq -0x208(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x208(%rbp)
cmpq $0x0, %rax
jle 0x15837
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq 0x264e46(%rip), %rax    # 0x27a500
jl 0x156d0
movq 0x264e3d(%rip), %rcx    # 0x27a500
movq -0x8(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x8(%rbp)
jmp 0x156af
movq -0x8(%rbp), %rsi
leaq -0x370(%rbp), %rdi
callq 0x133f0
leaq -0xb8(%rbp), %rdi
leaq -0x370(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, 0x389d28(%rip)   # 0x39f430
movzwl -0xb8(%rbp), %ecx
movzwl 0x389d22(%rip), %eax    # 0x39f438
orl %ecx, %eax
movw %ax, 0x389d19(%rip)     # 0x39f438
movsd 0x159941(%rip), %xmm0   # 0x16f068
addsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movl $0x0, -0x20c(%rbp)
cmpl $0x14, -0x20c(%rbp)
jge 0x15832
cmpl $0xe, -0x20c(%rbp)
je 0x1581c
cmpl $0x50, 0x264ef6(%rip)   # 0x27a658
jne 0x157f2
movslq -0x20c(%rbp), %rax
movsd -0xa8(%rbp,%rax,8), %xmm0
movslq -0x20c(%rbp), %rax
ucomisd -0x160(%rbp,%rax,8), %xmm0
jbe 0x157aa
movslq -0x20c(%rbp), %rax
movsd -0xa8(%rbp,%rax,8), %xmm0
movslq -0x20c(%rbp), %rax
movsd %xmm0, -0x160(%rbp,%rax,8)
movslq -0x20c(%rbp), %rax
movsd -0xa8(%rbp,%rax,8), %xmm1
movslq -0x20c(%rbp), %rax
movsd -0x200(%rbp,%rax,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x157f0
movslq -0x20c(%rbp), %rax
movsd -0xa8(%rbp,%rax,8), %xmm0
movslq -0x20c(%rbp), %rax
movsd %xmm0, -0x200(%rbp,%rax,8)
jmp 0x157f2
movq -0x380(%rbp), %rax
movslq -0x20c(%rbp), %rcx
movsd -0xa8(%rbp,%rcx,8), %xmm0
movslq -0x20c(%rbp), %rcx
addsd 0x10(%rax,%rcx,8), %xmm0
movsd %xmm0, 0x10(%rax,%rcx,8)
jmp 0x1581e
movl -0x20c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20c(%rbp)
jmp 0x15741
jmp 0x15687
movl $0x0, -0x20c(%rbp)
cmpl $0x14, -0x20c(%rbp)
jge 0x1592e
cmpl $0xe, -0x20c(%rbp)
je 0x15918
cmpl $0x50, 0x264df6(%rip)   # 0x27a658
jne 0x158f0
movslq -0x20c(%rbp), %rax
movsd -0x160(%rbp,%rax,8), %xmm0
movaps 0x159a11(%rip), %xmm1   # 0x16f290
pand %xmm1, %xmm0
movslq -0x20c(%rbp), %rax
movsd -0x200(%rbp,%rax,8), %xmm1
movaps 0x1599f6(%rip), %xmm2   # 0x16f290
pand %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x158ca
movq -0x380(%rbp), %rax
movslq -0x20c(%rbp), %rcx
movsd -0x160(%rbp,%rcx,8), %xmm0
movslq -0x20c(%rbp), %rcx
movsd %xmm0, 0x10(%rax,%rcx,8)
jmp 0x158ee
movq -0x380(%rbp), %rax
movslq -0x20c(%rbp), %rcx
movsd -0x200(%rbp,%rcx,8), %xmm0
movslq -0x20c(%rbp), %rcx
movsd %xmm0, 0x10(%rax,%rcx,8)
jmp 0x15916
movq -0x380(%rbp), %rax
movsd -0xc0(%rbp), %xmm1
movslq -0x20c(%rbp), %rcx
movsd 0x10(%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rax,%rcx,8)
jmp 0x15918
jmp 0x1591a
movl -0x20c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20c(%rbp)
jmp 0x15841
movq -0x378(%rbp), %rax
addq $0x380, %rsp            # imm = 0x380
popq %rbp
retq
nop