// File: /workspace/github_cpp_makefile_star2_O3/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 0x113695(%rip), %rax    # 0x21b3cc
movl $0x0, (%rax)
leaq 0x113524(%rip), %rax    # 0x21b268
movq (%rax), %r14
leaq 0x23804a(%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 0x113626(%rip), %r13    # 0x21b398
movq %rax, %rbx
leaq 0x1135ac(%rip), %rax    # 0x21b328
cmpq (%rax), %r14
je 0x107e26
leaq 0x1136e4(%rip), %rax    # 0x21b470
cmpq $0x0, (%rax)
je 0x107da3
leaq -0xf0(%rbp), %rdi
movq %r14, %rsi
callq 0x11bc7
jmp 0x107dc9
leaq -0x1a0(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x100be
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 0x237fc0(%rip), %rax    # 0x33fda0
movq (%rax), %rax
movss %xmm0, (%rax,%rbx,4)
movq (%r13), %rcx
testq %rcx, %rcx
je 0x107e02
xorps %xmm1, %xmm1
cvtsi2ss %rcx, %xmm1
divss %xmm1, %xmm0
movss %xmm0, (%rax,%rbx,4)
cmpq %rbx, %r15
je 0x107e21
movq %r14, %rdi
xorl %esi, %esi
callq 0x1144e
movq %rax, %r14
leaq 0x1(%rbx), %rax
testq %r14, %r14
jns 0x107d72
incq %rbx
jmp 0x107e2f
testq %rbx, %rbx
je 0x107ff6
movq %rbx, %rax
decq %rax
je 0x107e50
movl $0x1, %edx
xorl %ecx, %ecx
movq %rdx, %rsi
notq %rsi
addq %rdx, %rdx
incl %ecx
andq %rsi, %rax
jne 0x107e3e
jmp 0x107e52
xorl %ecx, %ecx
movl $0x1, %eax
shll %cl, %eax
movslq %eax, %rsi
cmpq %rsi, %rbx
setl %cl
shrq %cl, %rsi
leaq 0x237f0c(%rip), %rax    # 0x33fd78
movq (%rax), %rax
cmpq %rax, %rsi
cmovgeq %rax, %rsi
leaq 0x237f0b(%rip), %r15    # 0x33fd88
movq $0x1, (%r15)
leaq 0x237ef5(%rip), %rax    # 0x33fd80
movq %rsi, (%rax)
cmpq $0x2, %rsi
jl 0x108006
leaq 0x113501(%rip), %rax    # 0x21b3a0
movq (%rax), %rcx
leaq 0x110957(%rip), %r12    # 0x218800
movslq (%r12), %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 0x1134ec(%rip), %rax    # 0x21b3d0
xorps %xmm1, %xmm1
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
leaq 0x113462(%rip), %rax    # 0x21b358
divsd (%rax), %xmm0
movsd 0x121e(%rip), %xmm1     # 0x109120
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x2e232(%rip), %rcx     # 0x136144
leaq 0x2e234(%rip), %rsi     # 0x13614d
cmovaq %rcx, %rsi
movq %rdx, (%r15)
leaq 0x1279(%rip), %rcx      # 0x1091a0
divsd (%rcx,%rax,8), %xmm0
leaq 0x2342ed(%rip), %rdi    # 0x33c220
movb $0x1, %al
callq 0x9060
leaq 0x23738b(%rip), %rbx    # 0x33f2cc
cmpl $0x2, (%rbx)
je 0x107fa1
leaq 0x1134dd(%rip), %rax    # 0x21b42a
cmpb $0x0, (%rax)
leaq 0x1abfd(%rip), %rax     # 0x122b54
leaq 0x2e219(%rip), %r8      # 0x136177
cmoveq %rax, %r8
leaq 0x237e17(%rip), %rax    # 0x33fd80
movq (%rax), %rdx
imulq $0xe8, -0x30(%rbp), %rax
leaq 0x55db5(%rip), %rcx     # 0x15dd30
movq (%rcx,%rax), %r9
leaq 0x2368ca(%rip), %rdi    # 0x33e850
leaq 0x2e1c9(%rip), %rsi     # 0x136156
leaq 0x23428c(%rip), %rcx    # 0x33c220
xorl %eax, %eax
callq 0x9060
movl $0x3, (%rbx)
leaq 0x237dd8(%rip), %rax    # 0x33fd80
movq (%rax), %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
movss %xmm0, -0x30(%rbp)
leaq 0x237de1(%rip), %rcx    # 0x33fda0
movq (%rcx), %rdi
leaq 0x237def(%rip), %rcx    # 0x33fdb8
movq (%rcx), %rsi
testq %rax, %rax
je 0x107fef
decq %rax
je 0x10800d
movl $0x1, %ecx
xorl %edx, %edx
movq %rcx, %r8
notq %r8
addq %rcx, %rcx
incl %edx
andq %r8, %rax
jne 0x107fdd
jmp 0x10800f
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jmp 0x10800f
leaq 0x237d83(%rip), %rax    # 0x33fd80
movq $0x0, (%rax)
xorl %ebx, %ebx
xorl %esi, %esi
jmp 0x1084d5
xorl %edx, %edx
movss -0x30(%rbp), %xmm0
mulss %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
callq 0x107b44
movl $0xefa18f08, 0x34ef30(%rip) # imm = 0xEFA18F08
movl $0x6fa18f08, 0x34ef2a(%rip) # imm = 0x6FA18F08
leaq 0x237d43(%rip), %rax    # 0x33fd80
movq (%rax), %rax
cmpq $0x4, %rax
jl 0x1080ca
shrq %rax
leaq 0x237d64(%rip), %rcx    # 0x33fdb8
movq (%rcx), %rcx
decq %rax
movss 0x24896(%rip), %xmm1    # 0x12c8f8
movss 0x2488a(%rip), %xmm0    # 0x12c8f4
xorl %edx, %edx
movss 0x8(%rcx,%rdx,8), %xmm3
movss 0xc(%rcx,%rdx,8), %xmm2
mulss %xmm3, %xmm3
mulss %xmm2, %xmm2
addss %xmm3, %xmm2
ucomiss %xmm0, %xmm2
jbe 0x108094
movss %xmm2, 0x34eecb(%rip)   # 0x456f5c
movaps %xmm2, %xmm0
ucomiss %xmm2, %xmm1
jbe 0x1080a4
movss %xmm2, 0x34eebf(%rip)   # 0x456f60
movaps %xmm2, %xmm1
incq %rdx
cmpq %rdx, %rax
jne 0x10806c
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x1080d2
jp 0x1080d2
movl $0x3f800000, 0x34ee9c(%rip) # imm = 0x3F800000
movss 0x4fa4(%rip), %xmm0     # 0x10d06c
jmp 0x1080d2
movss 0x24822(%rip), %xmm0    # 0x12c8f4
divss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
maxsd 0x246e5(%rip), %xmm0    # 0x12c7c8
callq 0x9160
movsd %xmm0, -0x38(%rbp)
movss 0x34ee6b(%rip), %xmm0   # 0x456f60
divss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
maxsd 0x246c2(%rip), %xmm0    # 0x12c7c8
callq 0x9160
leaq 0x204696(%rip), %rax    # 0x30c7a8
cmpb $0x46, (%rax)
jne 0x108325
leaq 0x113362(%rip), %rbx    # 0x21b484
movl (%rbx), %edi
movl (%r12), %edx
leaq 0x1106e5(%rip), %r13    # 0x218814
movl (%r13), %eax
negl %eax
addl %edx, %eax
addl $-0x2, %eax
cmpl %eax, %edi
jge 0x108325
leaq 0x237c37(%rip), %rax    # 0x33fd80
cmpq $0x4, (%rax)
jl 0x1082cf
movsd 0xf4d(%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 0x237c04(%rip), %r12    # 0x33fd94
movl $0x1, %r13d
leaq 0x1132e3(%rip), %r14    # 0x21b480
leaq 0x237c14(%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 0x108202
movss -0x40(%rbp), %xmm1
ucomiss -0x38(%rbp), %xmm1
jne 0x1081d4
jnp 0x108202
divss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
maxsd 0x245e3(%rip), %xmm0    # 0x12c7c8
callq 0x9160
mulsd 0xeb6(%rip), %xmm0      # 0x1090a8
cvtsd2ss %xmm0, %xmm0
subss -0x38(%rbp), %xmm0
divss -0x3c(%rbp), %xmm0
jmp 0x10822a
movss 0x34ed52(%rip), %xmm1   # 0x456f5c
movss 0x34ed4e(%rip), %xmm2   # 0x456f60
ucomiss %xmm2, %xmm1
jne 0x108219
jnp 0x108227
subss %xmm2, %xmm0
subss %xmm2, %xmm1
divss %xmm1, %xmm0
jmp 0x10822a
xorps %xmm0, %xmm0
mulss 0x246ca(%rip), %xmm0    # 0x12c8fc
xorps %xmm1, %xmm1
subss %xmm0, %xmm1
movaps %xmm0, %xmm2
cmpltss 0x4e4b(%rip), %xmm2     # 0x10d090
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 (%rbx), %edi
leal 0x1(%rdi), %ecx
movl %ecx, (%rbx)
movl (%r14), %esi
movzbl %al, %edx
callq 0xe657
incq %r15
leaq 0x237ae5(%rip), %rax    # 0x33fd80
movq (%rax), %rax
movq %rax, %rcx
shrq $0x3f, %rcx
addq %rax, %rcx
sarq %rcx
cmpq %rcx, %r15
jl 0x10819d
movl (%rbx), %edi
leaq 0x110543(%rip), %r12    # 0x218800
movl (%r12), %edx
leaq 0x237ac0(%rip), %r15    # 0x33fd88
leaq 0x110545(%rip), %r13    # 0x218814
leaq 0x1131aa(%rip), %r14    # 0x21b480
movl (%r14), %ecx
decl %edx
movl %ecx, %esi
xorl %r8d, %r8d
callq 0xe38a
movl (%r14), %ecx
incl %ecx
movl %ecx, (%r14)
movl (%r12), %edx
decl %edx
xorl %edi, %edi
movl %ecx, %esi
movl $0xc, %r8d
callq 0xe38a
movl $0x0, (%rbx)
leaq 0x1104f5(%rip), %rax    # 0x218804
movl (%rax), %eax
movl (%r13), %ecx
addl %ecx, %ecx
subl %ecx, %eax
cmpl %eax, (%r14)
jl 0x108325
movl $0x0, (%r14)
leaq 0x1130a0(%rip), %rax    # 0x21b3cc
movl $0x0, (%rax)
leaq 0x112f2f(%rip), %rax    # 0x21b268
movq (%rax), %rsi
leaq 0x112fe5(%rip), %rax    # 0x21b328
movq (%rax), %rax
cmpq %rax, %rsi
jne 0x108352
xorl %ebx, %ebx
jmp 0x1084d5
movq (%r15), %rcx
xorl %ebx, %ebx
leaq -0x1a0(%rbp), %r14
leaq -0xf0(%rbp), %r15
movq %rsi, %r12
movq %rsi, -0x38(%rbp)
testq %rcx, %rcx
jle 0x108491
xorl %r13d, %r13d
movq %r14, %rdi
movq %r12, %rsi
callq 0x100be
movl $0xb0, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x92b0
leaq 0x2379e6(%rip), %rax    # 0x33fd80
movq (%rax), %rax
movq %rax, %rcx
shrq $0x3f, %rcx
addq %rax, %rcx
sarq %rcx
xorpd %xmm0, %xmm0
cmpq %rcx, %rbx
jge 0x108423
testq %rbx, %rbx
je 0x108409
leaq 0x2379f9(%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 0x2379b4(%rip), %rax    # 0x33fd94
cmpb $0x0, (%rax)
je 0x108413
divss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
maxsd 0x243d2(%rip), %xmm0    # 0x12c7c8
callq 0x9160
mulsd 0xca5(%rip), %xmm0      # 0x1090a8
cvtsd2ss %xmm0, %xmm0
jmp 0x10841b
movq $0x0, -0x70(%rbp)
jmp 0x108439
divss 0x34eb41(%rip), %xmm0   # 0x456f5c
cvtss2sd %xmm0, %xmm0
movq %r12, -0x38(%rbp)
movsd %xmm0, -0x70(%rbp)
cmpq $0x1, %rbx
jne 0x108439
leaq 0x112e7b(%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 0x1028a
leaq 0x1(%r12), %rcx
leaq 0x112ecd(%rip), %rax    # 0x21b328
movq (%rax), %rax
cmpq %rax, %rcx
je 0x1084d1
leaq 0x112eb6(%rip), %rcx    # 0x21b320
movq (%rcx), %rcx
addq %rcx, %r12
incq %r12
subq %rcx, %r12
cmpq %rcx, %r12
jge 0x108473
incq %r13
leaq 0x237903(%rip), %rcx    # 0x33fd88
movq (%rcx), %rcx
cmpq %r13, %rcx
jg 0x108378
incq %rbx
leaq 0x2378e5(%rip), %rdx    # 0x33fd80
movq (%rdx), %rdx
movq %rdx, %rsi
shrq $0x3f, %rsi
addq %rdx, %rsi
sarq %rsi
cmpq %rsi, %rbx
movq -0x38(%rbp), %rsi
jl 0x1084c6
leaq 0x110345(%rip), %rdx    # 0x218800
movslq (%rdx), %rdx
addq %rdx, %rdx
cmpq %rdx, %rbx
jge 0x1084d5
cmpq %rax, %r12
jne 0x108368
jmp 0x1084d5
movq -0x38(%rbp), %rsi
leaq 0x112dd4(%rip), %rax    # 0x21b2b0
movq %rsi, 0x10(%rax)
movq %rbx, %rax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq