// File: /workspace/github_c_makefile_star2_O1/pavel-demin[P]ft8d-c/ft8d.c
// Function: sync
void sync()
{
  int i, j, k, m, n, jmax;
  real_t c, sum, r, rmax, s, smax;

  for(i = 0; i < NSYM; ++i)
  {
    memset(buffer, 0, sizeof(complex_t) * NFFT);

    for(j = 0; j < NSPS; ++j)
    {
      buffer[j] = window[j] * signal[i * NSTP + j];
    }

    pffft_transform_ordered(setup, buffer, buffer, NULL, PFFFT_FORWARD);

    for(j = 0; j < NFFT; ++j)
    {
      k = j < NFFT / 2 ? j + NFFT / 2 : j - NFFT / 2;
      map[i * NFFT + k] = cabsf(buffer[j]);
    }
  }

  for(i = 0; i < NFFT; ++i)
  {
    jmax = 0;
    rmax = 0;
    smax = 0;
    for(j = -10 * NSSY; j < 25 * NSSY; ++j)
    {
      r = 0;
      s = 0;
      for(k = 0; k < 7; ++k)
      {
        m = j + (k + 36) * NSSY;
        sum = 0;
        for(n = 0; n < 8; ++n) sum += map[m * NFFT + i + n * NFOS];
        c = map[m * NFFT + i + costas[k] * NFOS];
        r += 7 * c / (sum - c);
        s += 8 * c / sum;
      }
      r /= 7;
      s /= 7;
      if(smax < s)
      {
        jmax = j;
        rmax = r;
        smax = s;
      }
    }
    list[i].i = i;
    list[i].j = jmax;
    list[i].k = 1;
    list[i].r = rmax;
    list[i].s = smax;
  }

  for(i = 2; i < NFFT - 2; ++i)
  {
    if((list[i - 2].s > list[i].s && list[i - 1].s > list[i].s) || (list[i + 1].s > list[i].s && list[i + 2].s > list[i].s))
    {
      list[i].k = 0;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0x4, %ebx
xorl %r14d, %r14d
leaq 0x54e2(%rip), %r15      # 0xb8d0
xorl %eax, %eax
movq %rax, (%rsp)
movq 0x54c5(%rip), %rdi      # 0xb8c0
movl $0x6400, %edx           # imm = 0x6400
xorl %esi, %esi
callq 0x10a0
xorl %eax, %eax
movss (%rax,%r15), %xmm0
movq 0x6dba(%rip), %rcx      # 0xd1d0
addq %rbx, %rcx
movss -0x4(%rcx,%rax,2), %xmm1
mulss %xmm0, %xmm1
mulss (%rcx,%rax,2), %xmm0
movq 0x5491(%rip), %rcx      # 0xb8c0
movss %xmm1, (%rcx,%rax,2)
movss %xmm0, 0x4(%rcx,%rax,2)
addq $0x4, %rax
cmpq $0x1900, %rax           # imm = 0x1900
jne 0x6409
movq 0x6d8b(%rip), %rdi      # 0xd1d8
movq 0x546c(%rip), %rdx      # 0xb8c0
movq %rdx, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x5706
leal -0x640(%r14), %ebp
leal 0x640(%r14), %r13d
xorl %r12d, %r12d
movq 0x5447(%rip), %rax      # 0xb8c0
movsd (%rax,%r12,8), %xmm0
callq 0x1070
cmpq $0x640, %r12            # imm = 0x640
movq 0x6d4e(%rip), %rax      # 0xd1e0
movl %ebp, %ecx
cmovbl %r13d, %ecx
addl %r12d, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
incq %r12
cmpq $0xc80, %r12            # imm = 0xC80
jne 0x6472
movq (%rsp), %rax
incq %rax
addq $0x200, %rbx            # imm = 0x200
addq $0xc80, %r14            # imm = 0xC80
cmpq $0x3a9, %rax            # imm = 0x3A9
jne 0x63f0
movq 0x6d09(%rip), %rax      # 0xd1e0
movq 0x6d0a(%rip), %rcx      # 0xd1e8
leaq 0x32c800(%rax), %rdx
xorl %esi, %esi
leaq 0x52d2(%rip), %rdi      # 0xb7c0
movss 0x237e(%rip), %xmm0     # 0x8874
movss 0x237a(%rip), %xmm1     # 0x8878
leaq (%rax,%rsi,4), %r8
xorps %xmm2, %xmm2
movq $-0x64, %r9
movq %rdx, %r11
xorps %xmm3, %xmm3
xorl %r10d, %r10d
movaps %xmm2, %xmm4
leaq 0x168(%r9), %rbx
movq %r11, %r14
xorl %r15d, %r15d
xorps %xmm2, %xmm2
xorps %xmm5, %xmm5
leaq (%r15,%r15,4), %r12
leaq (%rbx,%r12,2), %r12
xorps %xmm6, %xmm6
xorl %r13d, %r13d
addss (%r14,%r13), %xmm6
addq $0x14, %r13
cmpq $0xa0, %r13
jne 0x6539
movslq (%rdi,%r15,4), %r13
imulq $0x3200, %r12, %r12     # imm = 0x3200
addq %r8, %r12
leaq (%r13,%r13,4), %r13
movss (%r12,%r13,4), %xmm7
movaps %xmm7, %xmm8
mulss %xmm0, %xmm8
movaps %xmm6, %xmm9
subss %xmm7, %xmm9
divss %xmm9, %xmm8
addss %xmm8, %xmm5
mulss %xmm1, %xmm7
divss %xmm6, %xmm7
addss %xmm7, %xmm2
incq %r15
addq $0x1f400, %r14          # imm = 0x1F400
cmpq $0x7, %r15
jne 0x652b
divss %xmm0, %xmm2
ucomiss %xmm4, %xmm2
cmoval %r9d, %r10d
jbe 0x65b1
divss %xmm0, %xmm5
movaps %xmm5, %xmm3
maxss %xmm4, %xmm2
incq %r9
addq $0x3200, %r11           # imm = 0x3200
cmpq $0xfa, %r9
jne 0x6515
leaq (%rsi,%rsi,4), %r8
movl %esi, (%rcx,%r8,4)
movl %r10d, 0x4(%rcx,%r8,4)
movl $0x1, 0x8(%rcx,%r8,4)
movss %xmm3, 0xc(%rcx,%r8,4)
movss %xmm2, 0x10(%rcx,%r8,4)
incq %rsi
addq $0x4, %rdx
cmpq $0xc80, %rsi            # imm = 0xC80
jne 0x64fe
movl $0x60, %eax
movq 0x6bd8(%rip), %rcx      # 0xd1e8
movss -0x50(%rcx,%rax), %xmm1
movss -0x28(%rcx,%rax), %xmm0
ucomiss %xmm0, %xmm1
jbe 0x662c
movss -0x3c(%rcx,%rax), %xmm1
ucomiss %xmm0, %xmm1
ja 0x6641
movss -0x14(%rcx,%rax), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x6649
movss (%rcx,%rax), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x6649
movl $0x0, -0x30(%rcx,%rax)
addq $0x14, %rax
cmpq $0xfa10, %rax           # imm = 0xFA10
jne 0x6610
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq