// File: jkingan[P]ladyheather/heather.cpp
// Function: center_filter(long)
struct PLOT_Q center_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 "filter_count / 2" queue entries each side of the specified queue entry

   f_count = disp_filter_size();

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

   point = point - (f_count / 2);
   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(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];
         }
      }
   }

   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 $0x440, %rsp            # imm = 0x440
movq %rdi, -0x438(%rbp)
movq %rdi, -0x440(%rbp)
movq %rsi, -0x8(%rbp)
callq 0x15430
movq %rax, -0x210(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x2c8(%rbp), %rdi
callq 0x133f0
movq -0x438(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
movq -0x438(%rbp), %rdi
movsd 0x8(%rdi), %xmm0
movsd %xmm0, 0x389a8b(%rip)   # 0x39f430
movw (%rdi), %ax
movw %ax, 0x389a89(%rip)     # 0x39f438
movq -0x8(%rbp), %rax
movq %rax, -0x430(%rbp)
movq -0x210(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x430(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jge 0x159f2
movq 0x264b16(%rip), %rax    # 0x27a500
addq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x378(%rbp), %rdi
callq 0x133f0
movq -0x438(%rbp), %rdi
leaq -0x378(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
movq -0x438(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x389a02(%rip)   # 0x39f430
movzwl (%rax), %ecx
movzwl 0x389a00(%rip), %eax    # 0x39f438
orl %ecx, %eax
movw %ax, 0x3899f7(%rip)     # 0x39f438
movsd 0x15961f(%rip), %xmm0   # 0x16f068
movsd %xmm0, -0xc0(%rbp)
cmpl $0x50, 0x264c00(%rip)   # 0x27a658
jne 0x15abf
movl $0x0, -0x214(%rbp)
cmpl $0x14, -0x214(%rbp)
jge 0x15abd
cmpl $0xe, -0x214(%rbp)
je 0x15aaa
movq -0x438(%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 0x15aac
movl -0x214(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x214(%rbp)
jmp 0x15a64
jmp 0x15abf
movq $0x1, -0x208(%rbp)
movq -0x208(%rbp), %rax
cmpq -0x210(%rbp), %rax
jge 0x15c86
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
cmpq 0x264a17(%rip), %rax    # 0x27a508
jne 0x15af8
jmp 0x15c86
jmp 0x15afa
movq -0x8(%rbp), %rax
cmpq 0x2649fb(%rip), %rax    # 0x27a500
jl 0x15b1b
movq 0x2649f2(%rip), %rcx    # 0x27a500
movq -0x8(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x8(%rbp)
jmp 0x15afa
movq -0x8(%rbp), %rsi
leaq -0x428(%rbp), %rdi
callq 0x133f0
leaq -0xb8(%rbp), %rdi
leaq -0x428(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
movzwl -0xb8(%rbp), %ecx
movzwl 0x3898e7(%rip), %eax    # 0x39f438
orl %ecx, %eax
movw %ax, 0x3898de(%rip)     # 0x39f438
movsd 0x159506(%rip), %xmm0   # 0x16f068
addsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movl $0x0, -0x214(%rbp)
cmpl $0x14, -0x214(%rbp)
jge 0x15c6d
cmpl $0xe, -0x214(%rbp)
je 0x15c57
cmpl $0x50, 0x264abb(%rip)   # 0x27a658
jne 0x15c2d
movslq -0x214(%rbp), %rax
movsd -0xa8(%rbp,%rax,8), %xmm0
movslq -0x214(%rbp), %rax
ucomisd -0x160(%rbp,%rax,8), %xmm0
jbe 0x15be5
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 0x15c2b
movslq -0x214(%rbp), %rax
movsd -0xa8(%rbp,%rax,8), %xmm0
movslq -0x214(%rbp), %rax
movsd %xmm0, -0x200(%rbp,%rax,8)
jmp 0x15c2d
movq -0x438(%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 0x15c59
movl -0x214(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x214(%rbp)
jmp 0x15b7c
jmp 0x15c6f
movq -0x208(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x208(%rbp)
jmp 0x15aca
movl $0x0, -0x214(%rbp)
cmpl $0x14, -0x214(%rbp)
jge 0x15d7d
cmpl $0xe, -0x214(%rbp)
je 0x15d67
cmpl $0x50, 0x2649a7(%rip)   # 0x27a658
jne 0x15d3f
movslq -0x214(%rbp), %rax
movsd -0x160(%rbp,%rax,8), %xmm0
movaps 0x1595c2(%rip), %xmm1   # 0x16f290
pand %xmm1, %xmm0
movslq -0x214(%rbp), %rax
movsd -0x200(%rbp,%rax,8), %xmm1
movaps 0x1595a7(%rip), %xmm2   # 0x16f290
pand %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x15d19
movq -0x438(%rbp), %rax
movslq -0x214(%rbp), %rcx
movsd -0x160(%rbp,%rcx,8), %xmm0
movslq -0x214(%rbp), %rcx
movsd %xmm0, 0x10(%rax,%rcx,8)
jmp 0x15d3d
movq -0x438(%rbp), %rax
movslq -0x214(%rbp), %rcx
movsd -0x200(%rbp,%rcx,8), %xmm0
movslq -0x214(%rbp), %rcx
movsd %xmm0, 0x10(%rax,%rcx,8)
jmp 0x15d65
movq -0x438(%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 0x15d67
jmp 0x15d69
movl -0x214(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x214(%rbp)
jmp 0x15c90
movq -0x440(%rbp), %rax
addq $0x440, %rsp            # imm = 0x440
popq %rbp
retq
nopl (%rax)