// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl $0x1, %ebx
cmpl $0x2, %edi
jne 0x7441
movq %rsi, %r14
movq 0x8(%rsi), %rdi
addq $0x8, %r14
leaq 0x187b(%rip), %rsi      # 0x8947
callq 0x1110
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x7452
movq (%r14), %rdi
leaq 0x187d(%rip), %rsi      # 0x8966
callq 0x1140
xorl %ebx, %ebx
movb %bl, (%rax)
movq %rax, %r15
movb %bl, -0x5(%rax)
movl $0x75300, %edi          # imm = 0x75300
callq 0x10f0
movq %rax, 0x60c7(%rip)      # 0xd1d0
movl $0xb70200, %edi         # imm = 0xB70200
callq 0x10f0
movq %rax, 0x60c6(%rip)      # 0xd1e0
movl $0xfa00, %edi           # imm = 0xFA00
callq 0x10f0
movq %rax, 0x60bd(%rip)      # 0xd1e8
movl $0x6400, %edi           # imm = 0x6400
callq 0x14b5
movq %rax, 0x4784(%rip)      # 0xb8c0
movl $0xc80, %edi            # imm = 0xC80
movl $0x1, %esi
callq 0x24b7
movq %rax, 0x6086(%rip)      # 0xd1d8
leaq 0x4777(%rip), %r14      # 0xb8d0
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x10(%rsp)
mulsd 0xf4a(%rip), %xmm0      # 0x80b8
movsd 0x178a(%rip), %xmm1     # 0x8900
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x1040
mulss 0x172d(%rip), %xmm0     # 0x88b8
addss 0x1729(%rip), %xmm0     # 0x88bc
movss %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
mulsd 0x1761(%rip), %xmm0     # 0x8908
divsd 0x1751(%rip), %xmm0     # 0x8900
cvtsd2ss %xmm0, %xmm0
callq 0x1040
mulss 0x1700(%rip), %xmm0     # 0x88c0
addss 0x8(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
mulsd 0x1736(%rip), %xmm0     # 0x8910
divsd 0x171e(%rip), %xmm0     # 0x8900
cvtsd2ss %xmm0, %xmm0
callq 0x1040
mulss 0x16d1(%rip), %xmm0     # 0x88c4
addss 0x8(%rsp), %xmm0
movss %xmm0, (%r14)
incq %rbx
addq $0x4, %r14
cmpq $0x640, %rbx            # imm = 0x640
jne 0x7159
leaq -0x4(%r15), %rax
movq %rax, 0x30(%rsp)
addq $-0xb, %r15
movq %r15, 0x38(%rsp)
leaq 0x60(%rsp), %rbx
movl $0x1, %esi
movl $0x8, %edx
movq %rbx, %rdi
movq 0x20(%rsp), %rcx
callq 0x1050
xorl %r14d, %r14d
movsd (%rbx), %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x6c(%rsp), %rbp
leaq 0x5b(%rsp), %rbx
movq 0x5f72(%rip), %rdi      # 0xd1d0
movl $0x1, %esi
movl $0x75300, %edx          # imm = 0x75300
movq 0x20(%rsp), %rcx
callq 0x1050
callq 0x63d4
leal (%r14,%r14,4), %eax
leal (%rax,%rax,2), %eax
movl %eax, 0x1c(%rsp)
xorl %r15d, %r15d
movq 0x5f5c(%rip), %r12      # 0xd1e8
cmpl $0x0, 0x30(%r12,%r15)
je 0x7421
movss 0x38(%r12,%r15), %xmm0
movss 0x1621(%rip), %xmm1     # 0x88c8
ucomiss %xmm0, %xmm1
ja 0x7421
leaq (%r12,%r15), %rdi
addq $0x28, %rdi
cmpl $0x0, 0x1c(%rdi)
je 0x72fc
movss 0x4c(%r12,%r15), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x72fc
leaq (%r12,%r15), %rax
addq $0x3c, %rax
movl 0x10(%rdi), %ecx
movl %ecx, 0x50(%rsp)
movups (%rdi), %xmm0
movaps %xmm0, 0x40(%rsp)
movl 0x10(%rax), %ecx
movl %ecx, 0x10(%rdi)
movups (%rax), %xmm0
movups %xmm0, (%rdi)
movl 0x50(%rsp), %ecx
movl %ecx, 0x10(%rax)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rax)
callq 0x6671
movl $0x1e, %edi
callq 0x6914
testl %eax, %eax
je 0x7421
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x6dfd
testl %eax, %eax
je 0x7421
movl $0x0, 0x44(%r12,%r15)
movl 0x2c(%r12,%r15), %eax
shll $0x6, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x15d2(%rip), %xmm1     # 0x8918
divsd %xmm1, %xmm0
addsd 0x15ce(%rip), %xmm0     # 0x8920
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x28(%r12,%r15), %xmm0
mulsd %xmm1, %xmm0
divsd 0x15b6(%rip), %xmm0     # 0x8928
addsd 0x28(%rsp), %xmm0
addsd 0x15b0(%rip), %xmm0     # 0x8930
movsd 0x1570(%rip), %xmm1     # 0x88f8
addsd %xmm1, %xmm0
callq 0x1130
movq %rbp, %r13
cvttsd2si %xmm0, %ebp
xorps %xmm0, %xmm0
cvtss2sd 0x38(%r12,%r15), %xmm0
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x34(%r12,%r15), %xmm0
addsd 0x1526(%rip), %xmm0     # 0x88e0
cvtsd2ss %xmm0, %xmm0
callq 0x10d0
cvtss2sd %xmm0, %xmm0
mulsd 0x1519(%rip), %xmm0     # 0x88e8
addsd 0x1519(%rip), %xmm0     # 0x88f0
addsd 0x1519(%rip), %xmm0     # 0x88f8
callq 0x1130
cvttsd2si %xmm0, %r8d
xorps %xmm1, %xmm1
cvtss2sd 0x10(%rsp), %xmm1
leaq 0x1571(%rip), %rdi      # 0x896a
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
movl 0x1c(%rsp), %ecx
movsd 0x8(%rsp), %xmm0
movl %ebp, %r9d
movq %r13, %rbp
movb $0x2, %al
pushq %rbx
pushq %r13
callq 0x1080
addq $0x10, %rsp
addq $0x14, %r15
cmpq $0xf9b0, %r15           # imm = 0xF9B0
jne 0x7285
incl %r14d
cmpl $0x4, %r14d
jne 0x7257
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x1170
jmp 0x7441