// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathmsc.cpp
// Function: process_signal(long, int)
long process_signal(long length, int id)
{
long i;
long last_i;
long j;
int k;
struct PLOT_Q q;
DATA_SIZE show_time;
float a;
float tempflt;
float max_db, min_db;
int color;

   last_i = 0;
   plot_column = 0;

   j = 0;
   i = plot_q_col0;
   fft_queue_0 = i;
   while(i != plot_q_in) {  // copy queue data to FFT buffers
      if(filter_count) q = filter_plot_q(i);
      else             q = get_plot_q(i);

      tsignal[j] = (float) q.data[id];  // * window[j];
      if(queue_interval) tsignal[j] /= queue_interval;
      if(++j >= length) {
         break;  // buffer is full
      }

      i = next_q_point(i, STOP_AT_Q_END);
      if(i < 0) {
         break;
      }
   }

   if(j <= 0) {
      fft_length = 0;
      goto done;
   }

   length = (1 << logg2(j));  // adjust fft length for short data
   if(length > j) length /= 2;
   if(length > max_fft_len) length = max_fft_len;

   fft_scale = 1;
   fft_length = length;
   if(fft_length < 2) goto done;  //fft_scale = 1;
   else               fft_scale = ((view_interval * (long)SCREEN_WIDTH) / (fft_length/2L));
   if(fft_scale < 1)  fft_scale = 1;

   show_time = ((DATA_SIZE) (fft_length)) * ((DATA_SIZE) view_interval);  // seconds per screen
   show_time /= (DATA_SIZE) plot_mag;
   show_time /= nav_rate;
   if(show_time < (DATA_SIZE) (2.0*60.0*60.0)) sprintf(out, "%.1f min", show_time/(DATA_SIZE) 60.0);
   else                                        sprintf(out, "%.1f hrs", show_time/(DATA_SIZE) (60.0*60.0));
   if(title_type != USER) {
      sprintf(plot_title, "%ld point FFT of %s of%s%s data.", 
          fft_length, out, show_live_fft?" live ":" ", plot[id].plot_id);
      title_type = OTHER;
   }

   a = (float) fft_length * (float) fft_length;
   rfft(&tsignal[0], fft_out, logg2(fft_length));

   fft_max = (float) (-BIG_NUM);
   fft_min = (float) (BIG_NUM);
   for(j=1; j<fft_length/2; j++) {
      tempflt  = fft_out[j].real * fft_out[j].real;
      tempflt += fft_out[j].imag * fft_out[j].imag;
      if(tempflt > fft_max) fft_max = tempflt;
      if(tempflt < fft_min) fft_min = tempflt;
   }
   if(fft_max == 0.0F) fft_max = 1.0F;
   max_db = (float) (10.0 * log10(MAX(fft_max/a, 1.e-16))) ;
   min_db = (float) (10.0 * log10(MAX(fft_min/a, 1.e-16))) ;

   if((zoom_screen == 'F') && (fft_col < (SCREEN_WIDTH-TEXT_HEIGHT-2))) {  // FFT waterfall
      for(j=1; j<fft_length/2; j++) {
         tempflt  = fft_out[j].real * fft_out[j].real;
         tempflt += fft_out[j].imag * fft_out[j].imag;

         if(fft_db && (max_db != min_db)) {  // calc FFT in dB
           tempflt /= a;
           tempflt = (float) (10.0 * log10(MAX(tempflt, 1.e-16))) ;
           tempflt -= min_db;
           tempflt /= (max_db-min_db);  // 0..1
         }
         else if(fft_max != fft_min) {
            tempflt -= fft_min;
            tempflt /= (fft_max-fft_min);  // 0..1
         }
         else tempflt = 0.0F;
         tempflt *= 15.0F;    // 15 - number of colors used
         if(tempflt < 0.0F) tempflt = 0.0F-tempflt;
         color = ((int) tempflt) % 15;
         if(color < 0) color = 0;
         else if(color > 14) color = 14;
         dot(fft_col++, fft_row, color+1);
      }

      line(fft_col,fft_row, SCREEN_WIDTH-1, fft_row, BLACK);
      ++fft_row;
      line(0,fft_row, SCREEN_WIDTH-1, fft_row, RED);
      fft_col = 0;
      if(fft_row >= (SCREEN_HEIGHT-TEXT_HEIGHT*2)) fft_row = 0;
   }

   plot_column = 0;
   j = 0;
   i = last_i = plot_q_col0;

   // place fft results into the plot queue FFT plot data
   while(i != plot_q_in) {  
      for(k=0; k<fft_scale; k++) { // expand plot horizontally so that it is easier to read
         q = get_plot_q(i);

         if(j >= fft_length/2) q.data[FFT] = (DATA_SIZE) 0.0;  // fill out queue with 0's
         else if(j == 0)       q.data[FFT] = (DATA_SIZE) 0.0;  // drop the DC value because it messes up scaling
         else {   // insert FFT results into plot queue data
            tempflt  = fft_out[j].real * fft_out[j].real;
            tempflt += fft_out[j].imag * fft_out[j].imag;
            if(fft_db) {  // calc FFT in dB
              tempflt /= a;
              tempflt = (float) (10.0 * log10(MAX(tempflt, 1.e-16))) ;
            }
            else {
               tempflt /= fft_max;
            }
            q.data[FFT] = (DATA_SIZE) tempflt;
            last_i = i;
         }
         if(j == 1) mark_q_entry[1] = i;

         put_plot_q(i, q);
         if(++i == plot_q_in) goto done;
         while(i >= plot_q_size) i -= plot_q_size;
      }
      j++;
      if((j >= fft_length/2) && (j >= SCREEN_WIDTH*2)) break;
   }

   done:
   mark_q_entry[2] = last_i;
   return j;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdi, %r13
leaq 0x114183(%rip), %rax    # 0x2053cc
andl $0x0, (%rax)
leaq 0x114015(%rip), %rax    # 0x205268
movq (%rax), %r15
leaq 0x238b3b(%rip), %rax    # 0x329d98
movq %r15, (%rax)
movslq %esi, %rax
movq %rax, -0x30(%rbp)
xorl %r14d, %r14d
leaq 0x114127(%rip), %r12    # 0x205398
leaq 0x1140b0(%rip), %rax    # 0x205328
cmpq (%rax), %r15
je 0xf1321
leaq 0x1141e8(%rip), %rax    # 0x205470
cmpq $0x0, (%rax)
je 0xf129f
leaq -0xf0(%rbp), %rdi
movq %r15, %rsi
callq 0x11478
jmp 0xf12c5
leaq -0x1a0(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xf9c7
movl $0xb0, %edx
leaq -0xf0(%rbp), %rdi
movq %rbx, %rsi
callq 0x92a0
movq -0x30(%rbp), %rax
cvtsd2ss -0xe0(%rbp,%rax,8), %xmm0
leaq 0x238ac7(%rip), %rax    # 0x329da0
movq (%rax), %rax
movss %xmm0, (%rax,%r14,4)
movq (%r12), %rcx
testq %rcx, %rcx
je 0xf12fa
cvtsi2ss %rcx, %xmm1
divss %xmm1, %xmm0
movss %xmm0, (%rax,%r14,4)
leaq 0x1(%r14), %rbx
cmpq %r13, %rbx
jge 0xf131c
movq %r15, %rdi
xorl %esi, %esi
callq 0x10d47
movq %rax, %r15
incq %r14
testq %rax, %rax
jns 0xf1271
movq %rbx, %r14
jmp 0xf132a
testq %r14, %r14
je 0xf1702
movq %r14, %rdi
callq 0xf11f7
pushq $0x1
popq %rdx
movl %eax, %ecx
shll %cl, %edx
movslq %edx, %rsi
cmpq %rsi, %r14
setl %cl
shrq %cl, %rsi
leaq 0x238a2c(%rip), %rax    # 0x329d78
movq (%rax), %rax
cmpq %rax, %rsi
cmovgeq %rax, %rsi
leaq 0x238a2b(%rip), %r8     # 0x329d88
movq $0x1, (%r8)
leaq 0x238a15(%rip), %rax    # 0x329d80
movq %rsi, (%rax)
cmpq $0x2, %rsi
jl 0xf1710
leaq 0x114021(%rip), %rax    # 0x2053a0
movq (%rax), %rcx
leaq 0x111477(%rip), %rax    # 0x202800
movslq (%rax), %rax
imulq %rcx, %rax
movq %rsi, %rdi
shrq %rdi
cqto
idivq %rdi
cmpq $0x2, %rax
pushq $0x1
popq %r13
cmovlq %r13, %rax
cvtsi2sd %rsi, %xmm1
cvtsi2sd %rcx, %xmm0
mulsd %xmm1, %xmm0
leaq 0x114014(%rip), %rcx    # 0x2053d0
cvtsi2sdl (%rcx), %xmm1
divsd %xmm1, %xmm0
leaq 0x113f8d(%rip), %rcx    # 0x205358
divsd (%rcx), %xmm0
movsd 0x1d49(%rip), %xmm1     # 0xf3120
xorl %ecx, %ecx
ucomisd %xmm0, %xmm1
seta %cl
leaq 0x2ec69(%rip), %rdx     # 0x120050
leaq 0x2ec6b(%rip), %rsi     # 0x120059
cmovaq %rdx, %rsi
movq %rax, (%r8)
leaq 0x1da4(%rip), %rax      # 0xf31a0
divsd (%rax,%rcx,8), %xmm0
leaq 0x234e18(%rip), %rdi    # 0x326220
movb $0x1, %al
callq 0x9060
leaq 0x237eb6(%rip), %rbx    # 0x3292cc
cmpl $0x2, (%rbx)
je 0xf1476
leaq 0x114008(%rip), %rax    # 0x20542a
cmpb $0x0, (%rax)
leaq 0x1b670(%rip), %rax     # 0x10ca9c
leaq 0x2ec50(%rip), %r8      # 0x120083
cmoveq %rax, %r8
leaq 0x238942(%rip), %rax    # 0x329d80
movq (%rax), %rdx
imulq $0xe8, -0x30(%rbp), %rax
leaq 0x568e0(%rip), %rcx     # 0x147d30
movq (%rcx,%rax), %r9
leaq 0x2373f5(%rip), %rdi    # 0x328850
leaq 0x2ec00(%rip), %rsi     # 0x120062
leaq 0x234db7(%rip), %rcx    # 0x326220
xorl %eax, %eax
callq 0x9060
movl $0x3, (%rbx)
leaq 0x238903(%rip), %r15    # 0x329d80
movq (%r15), %rdi
cvtsi2ss %rdi, %xmm0
movss %xmm0, -0x30(%rbp)
leaq 0x23890f(%rip), %rax    # 0x329da0
movq (%rax), %rbx
leaq 0x23891d(%rip), %r12    # 0x329db8
movq (%r12), %r14
callq 0xf11f7
movq %rbx, %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0xf1078
movl $0xefa18f08, 0x34faa1(%rip) # imm = 0xEFA18F08
movl $0x6fa18f08, 0x34fa9b(%rip) # imm = 0x6FA18F08
movq (%r15), %rax
pushq $0x2
popq %rcx
cqto
idivq %rcx
movq (%r12), %rcx
movss 0x25338(%rip), %xmm0    # 0x116814
movss 0x25334(%rip), %xmm1    # 0x116818
cmpq %rax, %r13
jge 0xf1527
movss (%rcx,%r13,8), %xmm3
movss 0x4(%rcx,%r13,8), %xmm2
mulss %xmm3, %xmm3
mulss %xmm2, %xmm2
addss %xmm3, %xmm2
ucomiss %xmm0, %xmm2
jbe 0xf1512
movss %xmm2, 0x34fa4d(%rip)   # 0x440f5c
movaps %xmm2, %xmm0
ucomiss %xmm2, %xmm1
jbe 0xf1522
movss %xmm2, 0x34fa41(%rip)   # 0x440f60
movaps %xmm2, %xmm1
incq %r13
jmp 0xf14e4
movss -0x30(%rbp), %xmm1
mulss %xmm1, %xmm1
movss %xmm1, -0x30(%rbp)
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0xf1551
jp 0xf1551
movl $0x3f800000, 0x34fa13(%rip) # imm = 0x3F800000
movss 0x5b9b(%rip), %xmm0     # 0xf70ec
divss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
maxsd 0x25186(%rip), %xmm0    # 0x1166e8
callq 0x9160
movsd %xmm0, -0x38(%rbp)
movss 0x34f9ec(%rip), %xmm0   # 0x440f60
divss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
maxsd 0x25163(%rip), %xmm0    # 0x1166e8
callq 0x9160
leaq 0x205217(%rip), %rax    # 0x2f67a8
cmpb $0x46, (%rax)
jne 0xf1773
leaq 0x11125f(%rip), %rax    # 0x202800
movl (%rax), %eax
leaq 0x11126a(%rip), %rcx    # 0x202814
subl (%rcx), %eax
leaq 0x113ed1(%rip), %r14    # 0x205484
addl $-0x2, %eax
cmpl %eax, (%r14)
jge 0xf1773
movsd 0x1ae1(%rip), %xmm1     # 0xf30a8
movsd -0x38(%rbp), %xmm2
mulsd %xmm1, %xmm2
cvtsd2ss %xmm2, %xmm2
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm2, -0x40(%rbp)
movss %xmm0, -0x38(%rbp)
subss %xmm0, %xmm2
movss %xmm2, -0x3c(%rbp)
pushq $0x1
popq %r13
leaq 0x23879a(%rip), %rbx    # 0x329d94
pushq $0xf
popq %r15
leaq 0x113e7b(%rip), %r12    # 0x205480
leaq 0x238774(%rip), %rax    # 0x329d80
movq (%rax), %rax
cqto
pushq $0x2
popq %rcx
idivq %rcx
cmpq %rax, %r13
jge 0xf1717
leaq 0x238791(%rip), %rax    # 0x329db8
movq (%rax), %rax
movss (%rax,%r13,8), %xmm1
movss 0x4(%rax,%r13,8), %xmm0
mulss %xmm1, %xmm1
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
cmpb $0x0, (%rbx)
je 0xf1683
movss -0x40(%rbp), %xmm1
ucomiss -0x38(%rbp), %xmm1
jne 0xf1655
jnp 0xf1683
divss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
maxsd 0x25082(%rip), %xmm0    # 0x1166e8
callq 0x9160
mulsd 0x1a35(%rip), %xmm0     # 0xf30a8
cvtsd2ss %xmm0, %xmm0
subss -0x38(%rbp), %xmm0
divss -0x3c(%rbp), %xmm0
jmp 0xf16ab
movss 0x34f8d1(%rip), %xmm1   # 0x440f5c
movss 0x34f8cd(%rip), %xmm2   # 0x440f60
ucomiss %xmm2, %xmm1
jne 0xf169a
jnp 0xf16a8
subss %xmm2, %xmm0
subss %xmm2, %xmm1
divss %xmm1, %xmm0
jmp 0xf16ab
xorps %xmm0, %xmm0
mulss 0x25169(%rip), %xmm0    # 0x11681c
xorps %xmm1, %xmm1
subss %xmm0, %xmm1
movaps %xmm0, %xmm2
cmpltss 0x5a4a(%rip), %xmm2     # 0xf7110
andps %xmm2, %xmm1
andnps %xmm0, %xmm2
orps %xmm1, %xmm2
cvttss2si %xmm2, %eax
cltd
idivl %r15d
leal 0x1(%rdx), %eax
testl %edx, %edx
movzbl %al, %eax
pushq $0x1
popq %rcx
cmovsl %ecx, %eax
movl (%r14), %edi
leal 0x1(%rdi), %ecx
movl %ecx, (%r14)
movl (%r12), %esi
movzbl %al, %edx
callq 0xe1a7
incq %r13
jmp 0xf1605
leaq 0x238677(%rip), %rax    # 0x329d80
andq $0x0, (%rax)
xorl %r14d, %r14d
xorl %edx, %edx
jmp 0xf190c
movl (%r14), %edi
movl (%r12), %ecx
leaq 0x1110db(%rip), %rbx    # 0x202800
movl (%rbx), %edx
decl %edx
movl %ecx, %esi
xorl %r8d, %r8d
callq 0xdedf
movl (%r12), %ecx
incl %ecx
movl %ecx, (%r12)
movl (%rbx), %edx
decl %edx
pushq $0xc
popq %r8
xorl %edi, %edi
movl %ecx, %esi
callq 0xdedf
andl $0x0, (%r14)
leaq 0x1110ab(%rip), %rax    # 0x202804
movl (%rax), %eax
leaq 0x1110b2(%rip), %rcx    # 0x202814
movl (%rcx), %ecx
addl %ecx, %ecx
subl %ecx, %eax
cmpl %eax, (%r12)
jl 0xf1773
andl $0x0, (%r12)
leaq 0x113c52(%rip), %rax    # 0x2053cc
andl $0x0, (%rax)
leaq 0x113ae4(%rip), %rax    # 0x205268
movq (%rax), %rdx
leaq 0x113b9a(%rip), %rax    # 0x205328
movq (%rax), %rcx
xorl %r14d, %r14d
leaq -0x1a0(%rbp), %rbx
leaq -0xf0(%rbp), %r15
movq %rdx, %r13
leaq 0x2385dc(%rip), %rsi    # 0x329d88
cmpq %rcx, %r13
je 0xf190c
movq %rdx, -0x38(%rbp)
xorl %r12d, %r12d
cmpq %r12, (%rsi)
jle 0xf18ce
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf9c7
movl $0xb0, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x92a0
leaq 0x238599(%rip), %rax    # 0x329d80
movq (%rax), %rax
cqto
pushq $0x2
popq %rcx
idivq %rcx
xorpd %xmm0, %xmm0
cmpq %rax, %r14
jge 0xf186a
testq %r14, %r14
je 0xf1853
leaq 0x2385b1(%rip), %rax    # 0x329db8
movq (%rax), %rax
movss (%rax,%r14,8), %xmm1
movss 0x4(%rax,%r14,8), %xmm0
mulss %xmm1, %xmm1
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
leaq 0x23856a(%rip), %rax    # 0x329d94
cmpb $0x0, (%rax)
je 0xf185a
divss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
maxsd 0x24ea8(%rip), %xmm0    # 0x1166e8
callq 0x9160
mulsd 0x185b(%rip), %xmm0     # 0xf30a8
cvtsd2ss %xmm0, %xmm0
jmp 0xf1862
andq $0x0, -0x70(%rbp)
jmp 0xf1880
divss 0x34f6fa(%rip), %xmm0   # 0x440f5c
cvtss2sd %xmm0, %xmm0
movq %r13, -0x38(%rbp)
movsd %xmm0, -0x70(%rbp)
cmpq $0x1, %r14
jne 0xf1880
leaq 0x113a34(%rip), %rax    # 0x2052b0
movq %r13, 0x8(%rax)
pushq $0x16
popq %rcx
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r13, %rdi
callq 0xfb93
leaq 0x1(%r13), %rax
leaq 0x113a89(%rip), %rcx    # 0x205328
movq (%rcx), %rcx
cmpq %rcx, %rax
je 0xf1908
leaq 0x113a72(%rip), %rax    # 0x205320
movq (%rax), %rax
addq %rax, %r13
incq %r13
subq %rax, %r13
cmpq %rax, %r13
jge 0xf18b7
incq %r12
leaq 0x2384bf(%rip), %rsi    # 0x329d88
jmp 0xf17bc
incq %r14
leaq 0x2384a8(%rip), %rax    # 0x329d80
movq (%rax), %rax
cqto
pushq $0x2
popq %rdi
idivq %rdi
cmpq %rax, %r14
movq -0x38(%rbp), %rdx
jl 0xf17ac
leaq 0x110f09(%rip), %rax    # 0x202800
movslq (%rax), %rax
addq %rax, %rax
cmpq %rax, %r14
jl 0xf17ac
jmp 0xf190c
movq -0x38(%rbp), %rdx
leaq 0x11399d(%rip), %rax    # 0x2052b0
movq %rdx, 0x10(%rax)
movq %r14, %rax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq