// File: /workspace/github_cpp_makefile_star2_O1/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
leaq 0x113da4(%rip), %rax    # 0x21b3cc
movl $0x0, (%rax)
leaq 0x113c33(%rip), %rax    # 0x21b268
movq (%rax), %r14
leaq 0x238759(%rip), %rax    # 0x33fd98
movq %r14, (%rax)
movslq %esi, %rax
movq %rax, -0x30(%rbp)
cmpq $0x2, %rdi
movl $0x1, %r15d
cmovgeq %rdi, %r15
decq %r15
xorl %eax, %eax
leaq 0x113d35(%rip), %r13    # 0x21b398
movq %rax, %rbx
leaq 0x113cbb(%rip), %rax    # 0x21b328
cmpq (%rax), %r14
je 0x107715
leaq 0x113df3(%rip), %rax    # 0x21b470
cmpq $0x0, (%rax)
je 0x107694
leaq -0xf0(%rbp), %rdi
movq %r14, %rsi
callq 0x11c44
jmp 0x1076ba
leaq -0x1a0(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x10141
movl $0xb0, %edx
leaq -0xf0(%rbp), %rdi
movq %r12, %rsi
callq 0x92b0
movq -0x30(%rbp), %rax
xorps %xmm0, %xmm0
cvtsd2ss -0xe0(%rbp,%rax,8), %xmm0
leaq 0x2386cf(%rip), %rax    # 0x33fda0
movq (%rax), %rax
movss %xmm0, (%rax,%rbx,4)
movq (%r13), %rcx
testq %rcx, %rcx
je 0x1076f3
xorps %xmm1, %xmm1
cvtsi2ss %rcx, %xmm1
divss %xmm1, %xmm0
movss %xmm0, (%rax,%rbx,4)
cmpq %rbx, %r15
je 0x107712
movq %r14, %rdi
xorl %esi, %esi
callq 0x114d6
movq %rax, %r14
leaq 0x1(%rbx), %rax
testq %r14, %r14
jns 0x107663
incq %rbx
testq %rbx, %rbx
jle 0x10773b
movq %rbx, %rax
decq %rax
je 0x10774b
movl $0x1, %edx
xorl %ecx, %ecx
movq %rdx, %rsi
notq %rsi
addq %rdx, %rdx
incl %ecx
andq %rsi, %rax
jne 0x107729
jmp 0x10774d
leaq 0x23863e(%rip), %rax    # 0x33fd80
movq $0x0, (%rax)
jmp 0x10778f
xorl %ecx, %ecx
movl $0x1, %eax
shll %cl, %eax
movslq %eax, %rsi
cmpq %rsi, %rbx
setl %cl
shrq %cl, %rsi
leaq 0x238611(%rip), %rax    # 0x33fd78
movq (%rax), %rax
cmpq %rax, %rsi
cmovgeq %rax, %rsi
leaq 0x238610(%rip), %r8     # 0x33fd88
movq $0x1, (%r8)
leaq 0x2385fa(%rip), %rax    # 0x33fd80
movq %rsi, (%rax)
cmpq $0x2, %rsi
jge 0x1077b1
xorl %ecx, %ecx
leaq 0x113b18(%rip), %rax    # 0x21b2b0
movq %rcx, 0x10(%rax)
movq %rbx, %rax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x113be8(%rip), %rax    # 0x21b3a0
movq (%rax), %rcx
leaq 0x11103e(%rip), %r14    # 0x218800
movslq (%r14), %rax
imulq %rcx, %rax
movq %rsi, %rdi
shrq %rdi
cqto
idivq %rdi
cmpq $0x2, %rax
movl $0x1, %edx
cmovgeq %rax, %rdx
xorps %xmm1, %xmm1
cvtsi2sd %rsi, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd %xmm1, %xmm0
leaq 0x113bd4(%rip), %rax    # 0x21b3d0
xorps %xmm1, %xmm1
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
leaq 0x113b4a(%rip), %rax    # 0x21b358
divsd (%rax), %xmm0
movsd 0x1906(%rip), %xmm1     # 0x109120
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x2e821(%rip), %rcx     # 0x13604b
leaq 0x2e823(%rip), %rsi     # 0x136054
cmovaq %rcx, %rsi
movq %rdx, (%r8)
leaq 0x1951(%rip), %rcx      # 0x109190
divsd (%rcx,%rax,8), %xmm0
leaq 0x2349d5(%rip), %rdi    # 0x33c220
movb $0x1, %al
callq 0x9060
leaq 0x237a73(%rip), %rbx    # 0x33f2cc
cmpl $0x2, (%rbx)
je 0x1078b9
leaq 0x113bc5(%rip), %rax    # 0x21b42a
cmpb $0x0, (%rax)
leaq 0x1b205(%rip), %rax     # 0x122a74
leaq 0x2e808(%rip), %r8      # 0x13607e
cmoveq %rax, %r8
leaq 0x2384ff(%rip), %rax    # 0x33fd80
movq (%rax), %rdx
imulq $0xe8, -0x30(%rbp), %rax
leaq 0x5649d(%rip), %rcx     # 0x15dd30
movq (%rcx,%rax), %r9
leaq 0x236fb2(%rip), %rdi    # 0x33e850
leaq 0x2e7b8(%rip), %rsi     # 0x13605d
leaq 0x234974(%rip), %rcx    # 0x33c220
xorl %eax, %eax
callq 0x9060
movl $0x3, (%rbx)
leaq 0x2384c0(%rip), %rax    # 0x33fd80
movq (%rax), %rax
leaq 0x2384d6(%rip), %rcx    # 0x33fda0
movq (%rcx), %rdi
leaq 0x2384e4(%rip), %rcx    # 0x33fdb8
movq (%rcx), %rsi
testq %rax, %rax
je 0x1078fe
movq %rax, %rcx
decq %rcx
je 0x107905
movl $0x1, %r8d
xorl %edx, %edx
movq %r8, %r9
notq %r9
addq %r8, %r8
incl %edx
andq %r9, %rcx
jne 0x1078ec
jmp 0x107907
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jmp 0x107907
xorl %edx, %edx
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
movss %xmm0, -0x30(%rbp)
callq 0x107450
movl $0xefa18f08, 0x34f719(%rip) # imm = 0xEFA18F08
movl $0x6fa18f08, 0x34f713(%rip) # imm = 0x6FA18F08
leaq 0x23844c(%rip), %rax    # 0x33fd80
movq (%rax), %rdx
cmpq $0x4, %rdx
jl 0x1079ac
shrq %rdx
movss 0x34f6f8(%rip), %xmm0   # 0x457040
movss 0x34f6ec(%rip), %xmm1   # 0x45703c
leaq 0x238461(%rip), %rax    # 0x33fdb8
movq (%rax), %rax
cmpq $0x3, %rdx
movl $0x2, %ecx
cmovgeq %rdx, %rcx
decq %rcx
xorl %edx, %edx
movss 0x8(%rax,%rdx,8), %xmm3
movss 0xc(%rax,%rdx,8), %xmm2
mulss %xmm3, %xmm3
mulss %xmm2, %xmm2
addss %xmm3, %xmm2
ucomiss %xmm1, %xmm2
jbe 0x107994
movss %xmm2, 0x34f6ab(%rip)   # 0x45703c
movaps %xmm2, %xmm1
ucomiss %xmm2, %xmm0
jbe 0x1079a4
movss %xmm2, 0x34f69f(%rip)   # 0x457040
movaps %xmm2, %xmm0
incq %rdx
cmpq %rdx, %rcx
jne 0x10796c
movss -0x30(%rbp), %xmm0
mulss %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
movss 0x34f67a(%rip), %xmm0   # 0x45703c
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x1079d7
jp 0x1079d7
movl $0x3f800000, 0x34f665(%rip) # imm = 0x3F800000
movss 0x34f65d(%rip), %xmm0   # 0x45703c
divss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
maxsd 0x24cf0(%rip), %xmm0    # 0x12c6e0
callq 0x9160
movsd %xmm0, -0x38(%rbp)
movss 0x34f63e(%rip), %xmm0   # 0x457040
divss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
maxsd 0x24ccd(%rip), %xmm0    # 0x12c6e0
callq 0x9160
leaq 0x204d89(%rip), %rax    # 0x30c7a8
cmpb $0x46, (%rax)
jne 0x107c1d
movl (%r14), %eax
leaq 0x110de2(%rip), %rcx    # 0x218814
subl (%rcx), %eax
leaq 0x113a49(%rip), %r14    # 0x21b484
addl $-0x2, %eax
cmpl %eax, (%r14)
jge 0x107c1d
leaq 0x238332(%rip), %rax    # 0x33fd80
cmpq $0x4, (%rax)
jl 0x107bba
movsd 0x1648(%rip), %xmm1     # 0x1090a8
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)
movl $0x1, %r15d
leaq 0x2382ff(%rip), %r12    # 0x33fd94
movl $0x1, %r13d
leaq 0x1139de(%rip), %rbx    # 0x21b480
leaq 0x23830f(%rip), %rax    # 0x33fdb8
movq (%rax), %rax
movss (%rax,%r15,8), %xmm1
movss 0x4(%rax,%r15,8), %xmm0
mulss %xmm1, %xmm1
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
cmpb $0x0, (%r12)
je 0x107b07
movss -0x40(%rbp), %xmm1
ucomiss -0x38(%rbp), %xmm1
jne 0x107ad9
jnp 0x107b07
divss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
maxsd 0x24bf6(%rip), %xmm0    # 0x12c6e0
callq 0x9160
mulsd 0x15b1(%rip), %xmm0     # 0x1090a8
cvtsd2ss %xmm0, %xmm0
subss -0x38(%rbp), %xmm0
divss -0x3c(%rbp), %xmm0
jmp 0x107b2f
movss 0x34f52d(%rip), %xmm1   # 0x45703c
movss 0x34f529(%rip), %xmm2   # 0x457040
ucomiss %xmm2, %xmm1
jne 0x107b1e
jnp 0x107b2c
subss %xmm2, %xmm0
subss %xmm2, %xmm1
divss %xmm1, %xmm0
jmp 0x107b2f
xorps %xmm0, %xmm0
mulss 0x16e8d(%rip), %xmm0    # 0x11e9c4
xorps %xmm1, %xmm1
subss %xmm0, %xmm1
movaps %xmm0, %xmm2
cmpltss 0x54b2(%rip), %xmm2     # 0x10cffc
andps %xmm2, %xmm1
andnps %xmm0, %xmm2
orps %xmm1, %xmm2
cvttss2si %xmm2, %eax
cltq
imulq $-0x77777777, %rax, %rcx # imm = 0x88888889
shrq $0x20, %rcx
addl %eax, %ecx
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x3, %ecx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
leal 0x1(%rax), %ecx
testl %eax, %eax
movzbl %cl, %eax
cmovsl %r13d, %eax
movl (%r14), %edi
leal 0x1(%rdi), %ecx
movl %ecx, (%r14)
movl (%rbx), %esi
movzbl %al, %edx
callq 0xe6a0
incq %r15
leaq 0x2381df(%rip), %rax    # 0x33fd80
movq (%rax), %rax
movq %rax, %rcx
shrq $0x3f, %rcx
addq %rax, %rcx
sarq %rcx
cmpq %rcx, %r15
jl 0x107aa2
movl (%r14), %edi
leaq 0x1138bc(%rip), %rbx    # 0x21b480
movl (%rbx), %ecx
leaq 0x110c33(%rip), %r15    # 0x218800
movl (%r15), %edx
decl %edx
movl %ecx, %esi
xorl %r8d, %r8d
callq 0xe3c3
movl (%rbx), %ecx
incl %ecx
movl %ecx, (%rbx)
movl (%r15), %edx
decl %edx
xorl %edi, %edi
movl %ecx, %esi
movl $0xc, %r8d
callq 0xe3c3
movl $0x0, (%r14)
leaq 0x110c00(%rip), %rax    # 0x218804
movl (%rax), %eax
leaq 0x110c07(%rip), %rcx    # 0x218814
movl (%rcx), %ecx
addl %ecx, %ecx
subl %ecx, %eax
cmpl %eax, (%rbx)
jl 0x107c1d
movl $0x0, (%rbx)
leaq 0x1137a8(%rip), %rax    # 0x21b3cc
movl $0x0, (%rax)
leaq 0x113637(%rip), %rax    # 0x21b268
movq (%rax), %rcx
leaq 0x1136ed(%rip), %rax    # 0x21b328
cmpq (%rax), %rcx
jne 0x107c47
xorl %ebx, %ebx
jmp 0x107791
xorl %ebx, %ebx
leaq -0x1a0(%rbp), %r14
leaq -0xf0(%rbp), %r15
movq %rcx, %r12
leaq 0x238127(%rip), %rdx    # 0x33fd88
movq %rcx, -0x38(%rbp)
cmpq $0x0, (%rdx)
jle 0x107d81
xorl %r13d, %r13d
movq %r14, %rdi
movq %r12, %rsi
callq 0x10141
movl $0xb0, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x92b0
leaq 0x2380ec(%rip), %rax    # 0x33fd80
movq (%rax), %rax
movq %rax, %rcx
shrq $0x3f, %rcx
addq %rax, %rcx
sarq %rcx
cmpq %rcx, %rbx
jge 0x107cff
testq %rbx, %rbx
je 0x107cff
leaq 0x238103(%rip), %rax    # 0x33fdb8
movq (%rax), %rax
movss (%rax,%rbx,8), %xmm1
movss 0x4(%rax,%rbx,8), %xmm0
mulss %xmm1, %xmm1
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
leaq 0x2380be(%rip), %rax    # 0x33fd94
cmpb $0x0, (%rax)
je 0x107d09
divss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
maxsd 0x249f4(%rip), %xmm0    # 0x12c6e0
callq 0x9160
mulsd 0x13af(%rip), %xmm0     # 0x1090a8
cvtsd2ss %xmm0, %xmm0
jmp 0x107d11
movq $0x0, -0x70(%rbp)
jmp 0x107d1e
divss 0x34f32b(%rip), %xmm0   # 0x45703c
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
movq %r12, -0x38(%rbp)
cmpq $0x1, %rbx
jne 0x107d2f
leaq 0x113585(%rip), %rax    # 0x21b2b0
movq %r12, 0x8(%rax)
movl $0x16, %ecx
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r12, %rdi
callq 0x1030d
leaq 0x1(%r12), %rax
leaq 0x1135d7(%rip), %rcx    # 0x21b328
cmpq (%rcx), %rax
je 0x107dcf
leaq 0x1135c3(%rip), %rax    # 0x21b320
movq (%rax), %rax
addq %rax, %r12
incq %r12
subq %rax, %r12
cmpq %rax, %r12
jge 0x107d66
incq %r13
leaq 0x238010(%rip), %rdx    # 0x33fd88
cmpq %r13, (%rdx)
jg 0x107c72
incq %rbx
leaq 0x237ff5(%rip), %rax    # 0x33fd80
movq (%rax), %rax
movq %rax, %rcx
shrq $0x3f, %rcx
addq %rax, %rcx
sarq %rcx
cmpq %rcx, %rbx
movq -0x38(%rbp), %rcx
jl 0x107dba
leaq 0x110a55(%rip), %rax    # 0x218800
movslq (%rax), %rax
addq %rax, %rax
cmpq %rax, %rbx
jge 0x107791
leaq 0x113567(%rip), %rax    # 0x21b328
cmpq (%rax), %r12
jne 0x107c61
jmp 0x107791
movq -0x38(%rbp), %rcx
jmp 0x107791