// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rsi, %r12
movq %rdi, %rbx
callq 0x1155b
movq %rax, %r14
movq %rbx, %rdi
movq %r12, %rsi
callq 0x100be
movsd 0x8(%rbx), %xmm0
movsd %xmm0, 0x32ea4c(%rip)   # 0x340250
movzwl (%rbx), %eax
movw %ax, 0x32ea4a(%rip)     # 0x340258
movq %r14, %rax
shrq $0x3f, %rax
addq %r14, %rax
sarq %rax
subq %rax, %r12
movq %r12, %r15
sarq $0x3f, %r15
andq 0x209af4(%rip), %r15    # 0x21b320
addq %r12, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x100be
movzwl (%rbx), %eax
orw %ax, 0x32ea14(%rip)     # 0x340258
movsd 0x8(%rbx), %xmm0
movsd %xmm0, 0x32e9ff(%rip)   # 0x340250
movl 0x209c21(%rip), %eax    # 0x21b478
cmpl $0x50, %eax
jne 0x11885
xorl %ecx, %ecx
cmpq $0xe, %rcx
je 0x1187c
movsd 0x10(%rbx,%rcx,8), %xmm0
movsd %xmm0, -0xd0(%rbp,%rcx,8)
movsd %xmm0, -0x170(%rbp,%rcx,8)
incq %rcx
cmpq $0x14, %rcx
jne 0x1185e
movsd 0xf77e3(%rip), %xmm5    # 0x109070
cmpq $0x2, %r14
jl 0x11973
incq %r15
cmpq 0x209a87(%rip), %r15    # 0x21b328
je 0x11973
movl $0x1, %r13d
movsd 0xf77bb(%rip), %xmm5    # 0x109070
leaq -0x220(%rbp), %r12
movsd %xmm5, -0x30(%rbp)
movq 0x209a58(%rip), %rax    # 0x21b320
addq %rax, %r15
incq %r15
subq %rax, %r15
leaq -0x1(%r15), %rsi
cmpq %rax, %rsi
jge 0x118ce
movq %r12, %rdi
callq 0x100be
movzwl -0x220(%rbp), %eax
orw %ax, 0x32e968(%rip)     # 0x340258
movl 0x209b82(%rip), %eax    # 0x21b478
xorl %ecx, %ecx
movsd -0x30(%rbp), %xmm5
cmpq $0x70, %rcx
je 0x11949
movsd -0x210(%rbp,%rcx), %xmm0
cmpl $0x50, %eax
jne 0x1193d
ucomisd -0x170(%rbp,%rcx), %xmm0
jbe 0x11925
movsd %xmm0, -0x170(%rbp,%rcx)
movsd -0xd0(%rbp,%rcx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1193d
movsd %xmm0, -0xd0(%rbp,%rcx)
addsd 0x10(%rbx,%rcx), %xmm0
movsd %xmm0, 0x10(%rbx,%rcx)
addq $0x8, %rcx
cmpq $0xa0, %rcx
jne 0x118fd
addsd 0xf7712(%rip), %xmm5    # 0x109070
incq %r13
cmpq %r14, %r13
je 0x11973
cmpq %r15, 0x2099bb(%rip)    # 0x21b328
jne 0x118bc
xorl %ecx, %ecx
movapd 0xf7813(%rip), %xmm0    # 0x109190
cmpq $0xe, %rcx
je 0x119c8
cmpl $0x50, %eax
jne 0x119b8
movsd -0x170(%rbp,%rcx,8), %xmm1
movapd %xmm1, %xmm3
andpd %xmm0, %xmm3
movsd -0xd0(%rbp,%rcx,8), %xmm2
movapd %xmm2, %xmm4
andpd %xmm0, %xmm4
ucomisd %xmm4, %xmm3
jae 0x119c2
movsd %xmm2, 0x10(%rbx,%rcx,8)
jmp 0x119c8
movsd 0x10(%rbx,%rcx,8), %xmm1
divsd %xmm5, %xmm1
movsd %xmm1, 0x10(%rbx,%rcx,8)
incq %rcx
cmpq $0x14, %rcx
jne 0x1197d
movq %rbx, %rax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq