// File: /workspace/github_c_makefile_star2_O0/pavel-demin[P]ft8d-c/ft8d.c
// Function: main
int main(int argc, char **argv)
{
  FILE *fp;
  double dialfreq;
  int i, j, freq;
  sync_t *curr, *next, temp;
  char *date, *time, *suffix, call[12], grid[5];
  real_t dt, a[4] = {0.35875, 0.48829, 0.14128, 0.01168};

  if(argc != 2)
  {
    return EXIT_FAILURE;
  }

  if((fp = fopen(argv[1], "rb")) == NULL)
  {
    fprintf(stderr, "Cannot open input file %s.\n", argv[1]);
    return EXIT_FAILURE;
  }

  suffix = strstr(argv[1], ".c2");
  *suffix = 0;
  time = suffix - 4;
  *(suffix - 5) = 0;
  date = suffix - 11;

  signal = malloc(sizeof(complex_t) * 60000);
  map = malloc(sizeof(real_t) * NSYM * NFFT);
  list = malloc(sizeof(sync_t) * NFFT);

  buffer = pffft_aligned_malloc(sizeof(complex_t) * NFFT);
  setup = pffft_new_setup(NFFT, PFFFT_COMPLEX);

  for(i = 0; i < NSPS; ++i)
  {
    window[i] = a[0] -
      a[1] * cosf(2.0 * M_PI * i / (NSPS - 1)) +
      a[2] * cosf(4.0 * M_PI * i / (NSPS - 1)) -
      a[3] * cosf(6.0 * M_PI * i / (NSPS - 1));
  }

  fread(&dialfreq, 1, 8, fp);

  for(i = 0; i < 4; ++i)
  {
    fread(signal, 1, 480000, fp);

    sync();

    for(j = 2; j < NFFT - 2; ++j)
    {
      curr = &list[j];
      next = &list[j + 1];

      if(curr->k == 0 || curr->s < 2.5) continue;

      if(next->k != 0 && next->s > curr->s)
      {
        temp = *curr;
        *curr = *next;
        *next = temp;
      }

      process(curr);

      if(!decode(30) || !unpack(call, grid)) continue;

      next->k = 0;

      dt = curr->j * NSTP / 4.0e3 - 0.5;
      freq = floor(dialfreq + curr->i * 4.0e3 / NFFT - 2.0e3 + 0.5);
      printf("%6s %4s%02d %5.1f %3d %5.2f %8d %11s %4s\n", date, time, i * 15, curr->s, snr(curr), dt, freq, call, grid);
    }
  }

  return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x15e0(%rip), %rax      # 0x18c70
movq %rax, -0xa0(%rbp)
movq 0x15da(%rip), %rax      # 0x18c78
movq %rax, -0x98(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0x176b7
movl $0x1, -0x4(%rbp)
jmp 0x17b8a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x15ba(%rip), %rsi      # 0x18c80
callq 0x1120
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x17701
movq 0x391c(%rip), %rax      # 0x1aff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x1595(%rip), %rsi      # 0x18c83
movb $0x0, %al
callq 0x10c0
movl $0x1, -0x4(%rbp)
jmp 0x17b8a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x158f(%rip), %rsi      # 0x18c9f
callq 0x1150
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movb $0x0, (%rax)
movq -0x70(%rbp), %rax
addq $-0x4, %rax
movq %rax, -0x68(%rbp)
movq -0x70(%rbp), %rax
movb $0x0, -0x5(%rax)
movq -0x70(%rbp), %rax
addq $-0xb, %rax
movq %rax, -0x60(%rbp)
movl $0x75300, %edi          # imm = 0x75300
callq 0x1100
movq %rax, 0x5a8f(%rip)      # 0x1d1e0
movl $0xb70200, %edi         # imm = 0xB70200
callq 0x1100
movq %rax, 0x5a8e(%rip)      # 0x1d1f0
movl $0xfa00, %edi           # imm = 0xFA00
callq 0x1100
movq %rax, 0x5a85(%rip)      # 0x1d1f8
movl $0x6400, %edi           # imm = 0x6400
callq 0x2090
movq %rax, 0x414c(%rip)      # 0x1b8d0
movl $0xc80, %edi            # imm = 0xC80
movl $0x1, %esi
callq 0x6150
movq %rax, 0x5a4e(%rip)      # 0x1d1e8
movl $0x0, -0x24(%rbp)
cmpl $0x640, -0x24(%rbp)     # imm = 0x640
jge 0x178f9
movss -0xa0(%rbp), %xmm0
movss %xmm0, -0xb8(%rbp)
movss -0x9c(%rbp), %xmm0
movss %xmm0, -0xb4(%rbp)
cvtsi2sdl -0x24(%rbp), %xmm1
movsd 0x8a5(%rip), %xmm0      # 0x18080
mulsd %xmm1, %xmm0
movsd 0x1459(%rip), %xmm1     # 0x18c40
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x1040
movss -0xb8(%rbp), %xmm1
movaps %xmm0, %xmm2
movss -0xb4(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0xb0(%rbp)
movss -0x98(%rbp), %xmm0
movss %xmm0, -0xac(%rbp)
cvtsi2sdl -0x24(%rbp), %xmm1
movsd 0x140f(%rip), %xmm0     # 0x18c50
mulsd %xmm1, %xmm0
movsd 0x13f3(%rip), %xmm1     # 0x18c40
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x1040
movss -0xb0(%rbp), %xmm1
movaps %xmm0, %xmm2
movss -0xac(%rbp), %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0xa8(%rbp)
movss -0x94(%rbp), %xmm0
movss %xmm0, -0xa4(%rbp)
cvtsi2sdl -0x24(%rbp), %xmm1
movsd 0x13ae(%rip), %xmm0     # 0x18c48
mulsd %xmm1, %xmm0
movsd 0x139a(%rip), %xmm1     # 0x18c40
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x1040
movss -0xa8(%rbp), %xmm1
movaps %xmm0, %xmm2
movss -0xa4(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movslq -0x24(%rbp), %rcx
leaq 0x3ffa(%rip), %rax      # 0x1b8e0
movss %xmm0, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x177a1
movq -0x18(%rbp), %rcx
leaq -0x20(%rbp), %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0x1050
movl $0x0, -0x24(%rbp)
cmpl $0x4, -0x24(%rbp)
jge 0x17b83
movq 0x58b8(%rip), %rdi      # 0x1d1e0
movq -0x18(%rbp), %rcx
movl $0x1, %esi
movl $0x75300, %edx          # imm = 0x75300
callq 0x1050
callq 0x16180
movl $0x2, -0x28(%rbp)
cmpl $0xc7e, -0x28(%rbp)     # imm = 0xC7E
jge 0x17b73
movq 0x589d(%rip), %rax      # 0x1d1f8
movslq -0x28(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq 0x5887(%rip), %rax      # 0x1d1f8
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x179aa
movq -0x38(%rbp), %rax
movss 0x10(%rax), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x127c(%rip), %xmm0     # 0x18c20
ucomisd %xmm1, %xmm0
jbe 0x179af
jmp 0x17b65
movq -0x40(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x17a1a
movq -0x40(%rbp), %rax
movss 0x10(%rax), %xmm0
movq -0x38(%rbp), %rax
ucomiss 0x10(%rax), %xmm0
jbe 0x17a1a
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x54(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x4c(%rbp)
movl 0x10(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movl 0x10(%rcx), %ecx
movl %ecx, 0x10(%rax)
movq -0x40(%rbp), %rax
movq -0x54(%rbp), %rcx
movq %rcx, (%rax)
movq -0x4c(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x44(%rbp), %ecx
movl %ecx, 0x10(%rax)
movq -0x38(%rbp), %rdi
callq 0x166b0
movl $0x1e, %edi
callq 0x16b20
cmpl $0x0, %eax
je 0x17a47
leaq -0x7c(%rbp), %rdi
leaq -0x81(%rbp), %rsi
callq 0x17250
cmpl $0x0, %eax
jne 0x17a4c
jmp 0x17b65
movq -0x40(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
shll $0x6, %eax
cvtsi2sd %eax, %xmm0
movsd 0x11cb(%rip), %xmm1     # 0x18c38
divsd %xmm1, %xmm0
movsd 0x1187(%rip), %xmm1     # 0x18c00
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x88(%rbp)
movsd -0x20(%rbp), %xmm0
movq -0x38(%rbp), %rax
cvtsi2sdl (%rax), %xmm1
movsd 0x119a(%rip), %xmm2     # 0x18c38
mulsd %xmm2, %xmm1
movsd 0x1186(%rip), %xmm2     # 0x18c30
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd 0x116e(%rip), %xmm1     # 0x18c28
subsd %xmm1, %xmm0
movsd 0x113a(%rip), %xmm1     # 0x18c00
addsd %xmm1, %xmm0
callq 0x1140
cvttsd2si %xmm0, %eax
movl %eax, -0x2c(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0xd0(%rbp)
imull $0xf, -0x24(%rbp), %eax
movl %eax, -0xc4(%rbp)
movq -0x38(%rbp), %rax
movss 0x10(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xc0(%rbp)
movq -0x38(%rbp), %rdi
callq 0x17600
movq -0xd8(%rbp), %rsi
movq -0xd0(%rbp), %rdx
movl -0xc4(%rbp), %ecx
movsd -0xc0(%rbp), %xmm0
movl %eax, %r8d
movss -0x88(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movl -0x2c(%rbp), %r9d
leaq -0x7c(%rbp), %r10
leaq -0x81(%rbp), %rax
leaq 0x114e(%rip), %rdi      # 0x18ca3
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x2, %al
callq 0x1080
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x17947
jmp 0x17b75
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x17917
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq