// File: markondej[P]phase_correl/phase_correl.c
// Function: sum2fft
void sum2fft(const double *input, double *output, unsigned size, int inverse) {
    unsigned k;

    double temp[4], cosfi, sinfi,
        dfi = (inverse ? 2.0 : -2.0) * M_PI / (double)(size << 1),
        kfi = 0.0;

    for (k = 0; k < size; k++) {
        cosfi = cos(kfi); sinfi = sin(kfi);
        temp[0] = input[k << 1]; temp[1] = input[(k << 1) + 1];
        temp[2] = input[(k + size) << 1]; temp[3] = input[((k + size) << 1) + 1];

        output[k << 1] = temp[0] + cosfi * temp[2] - sinfi * temp[3];
        output[(k << 1) + 1] = temp[1] + sinfi * temp[2] + cosfi * temp[3];
        output[(k + size) << 1] = temp[0] - cosfi * temp[2] + sinfi * temp[3];
        output[((k + size) << 1) + 1] = temp[1] - sinfi * temp[2] - cosfi * temp[3];
        kfi += dfi;
    }
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movl %edx, 0x54(%rsp)
movl %ecx, 0x50(%rsp)
movl 0x50(%rsp), %eax
testl %eax, %eax
setne %al
movzbl %al, %eax
movl %eax, %ecx
leaq 0x1d75(%rip), %rax      # 0x3010
movsd (%rax,%rcx,8), %xmm0
movl 0x54(%rsp), %eax
addl %eax, %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, (%rsp)
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x54(%rsp), %eax
jae 0x14eb
movsd (%rsp), %xmm0
callq 0x1080
movsd %xmm0, 0x18(%rsp)
movsd (%rsp), %xmm0
callq 0x10a0
movsd %xmm0, 0x10(%rsp)
movq 0x60(%rsp), %rax
movl 0x4c(%rsp), %ecx
shll %ecx
movl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x60(%rsp), %rax
movl 0x4c(%rsp), %ecx
shll %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x60(%rsp), %rax
movl 0x4c(%rsp), %ecx
addl 0x54(%rsp), %ecx
shll %ecx
movl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x60(%rsp), %rax
movl 0x4c(%rsp), %ecx
addl 0x54(%rsp), %ecx
shll %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x20(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
movsd 0x38(%rsp), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x58(%rsp), %rax
movl 0x4c(%rsp), %ecx
shll %ecx
movl %ecx, %ecx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x28(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
movsd 0x38(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x58(%rsp), %rax
movl 0x4c(%rsp), %ecx
shll %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x20(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
movsd 0x38(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x58(%rsp), %rax
movl 0x4c(%rsp), %ecx
addl 0x54(%rsp), %ecx
shll %ecx
movl %ecx, %ecx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x28(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
movsd 0x38(%rsp), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x58(%rsp), %rax
movl 0x4c(%rsp), %ecx
addl 0x54(%rsp), %ecx
shll %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x8(%rsp), %xmm0
addsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x12c5
addq $0x68, %rsp
retq