// File: /workspace/github_c_makefile_star2_O3/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
xorl %ebx, %ebx
leaq 0x56f4(%rip), %r14      # 0xb8d0
xorl %r15d, %r15d
xorl %eax, %eax
movq %rax, (%rsp)
movq 0x56d4(%rip), %rdi      # 0xb8c0
movl $0x6400, %edx           # imm = 0x6400
xorl %esi, %esi
callq 0x10a0
xorl %eax, %eax
movq 0x6fcf(%rip), %rcx      # 0xd1d0
addq %r15, %rcx
movq 0x56b5(%rip), %rdx      # 0xb8c0
movsd (%rcx,%rax,2), %xmm0
movss (%rax,%r14), %xmm1
unpcklps %xmm1, %xmm1            # xmm1 = xmm1[0,0,1,1]
mulps %xmm0, %xmm1
movlps %xmm1, (%rdx,%rax,2)
addq $0x4, %rax
cmpq $0x1900, %rax           # imm = 0x1900
jne 0x61fa
movq 0x6fa5(%rip), %rdi      # 0xd1d8
movq 0x5686(%rip), %rdx      # 0xb8c0
movq %rdx, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x5523
leal -0x640(%rbx), %ebp
leal 0x640(%rbx), %r13d
xorl %r12d, %r12d
movq 0x5662(%rip), %rax      # 0xb8c0
movsd (%rax,%r12,8), %xmm0
callq 0x1070
cmpq $0x640, %r12            # imm = 0x640
movq 0x6f69(%rip), %rcx      # 0xd1e0
movl %ebp, %eax
cmovbl %r13d, %eax
addl %r12d, %eax
cltq
movss %xmm0, (%rcx,%rax,4)
incq %r12
cmpq $0xc80, %r12            # imm = 0xC80
jne 0x6257
movq (%rsp), %rax
incq %rax
addq $0x200, %r15            # imm = 0x200
addq $0xc80, %rbx            # imm = 0xC80
cmpq $0x3a9, %rax            # imm = 0x3A9
jne 0x61e1
movq 0x6f2d(%rip), %rax      # 0xd1e8
leaq 0x32c800(%rcx), %rdx
xorl %esi, %esi
leaq 0x54f5(%rip), %rdi      # 0xb7c0
movsd 0x25cd(%rip), %xmm0     # 0x88a0
movaps 0x25d6(%rip), %xmm1     # 0x88b0
xorps %xmm2, %xmm2
movq $-0x64, %r9
movq %rdx, %r10
xorl %r8d, %r8d
leaq 0x168(%r9), %r11
movq %r10, %rbx
xorl %r14d, %r14d
xorps %xmm3, %xmm3
leaq (%r14,%r14,4), %r15
leaq (%r11,%r15,2), %r15
imulq $0xc80, %r15, %r15      # imm = 0xC80
addq %rsi, %r15
xorps %xmm4, %xmm4
xorl %r12d, %r12d
addss (%rbx,%r12), %xmm4
addq $0x14, %r12
cmpq $0xa0, %r12
jne 0x6312
movslq (%rdi,%r14,4), %r12
leaq (%rcx,%r15,4), %r15
leaq (%r12,%r12,4), %r12
movss (%r15,%r12,4), %xmm5
movaps %xmm4, %xmm6
subss %xmm5, %xmm6
shufps $0x0, %xmm5, %xmm5      # xmm5 = xmm5[0,0,0,0]
mulps %xmm0, %xmm5
unpcklps %xmm4, %xmm6            # xmm6 = xmm6[0],xmm4[0],xmm6[1],xmm4[1]
divps %xmm6, %xmm5
addps %xmm5, %xmm3
incq %r14
addq $0x1f400, %rbx          # imm = 0x1F400
cmpq $0x7, %r14
jne 0x62fa
divps %xmm1, %xmm3
movaps %xmm2, %xmm4
cmpltps %xmm3, %xmm4
pextrw $0x2, %xmm4, %r11d
testb $0x1, %r11b
cmovnel %r9d, %r8d
shufps $0x55, %xmm4, %xmm4     # xmm4 = xmm4[1,1,1,1]
andps %xmm4, %xmm3
andnps %xmm2, %xmm4
movaps %xmm4, %xmm2
orps %xmm3, %xmm2
incq %r9
addq $0x3200, %r10           # imm = 0x3200
cmpq $0xfa, %r9
jne 0x62ea
leaq (%rsi,%rsi,4), %r9
movl %esi, (%rax,%r9,4)
movl %r8d, 0x4(%rax,%r9,4)
movl $0x1, 0x8(%rax,%r9,4)
movlps %xmm2, 0xc(%rax,%r9,4)
incq %rsi
addq $0x4, %rdx
cmpq $0xc80, %rsi            # imm = 0xC80
jne 0x62da
movl $0x60, %ecx
movss -0x50(%rax,%rcx), %xmm1
movss -0x28(%rax,%rcx), %xmm0
ucomiss %xmm0, %xmm1
jbe 0x63ee
movss -0x3c(%rax,%rcx), %xmm1
ucomiss %xmm0, %xmm1
ja 0x6403
movss -0x14(%rax,%rcx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x640b
movss (%rax,%rcx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x640b
movl $0x0, -0x30(%rax,%rcx)
addq $0x14, %rcx
cmpq $0xfa10, %rcx           # imm = 0xFA10
jne 0x63d2
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq