// File: /workspace/github_cpp_makefile_star2_O1/markondej[P]phase_correl/phase_correl.c
// Function: fft2D
void fft2D(double *data, unsigned width, unsigned height, int inverse) {
    unsigned i, j;

    double *fft_input = (double *)malloc((sizeof(double) * width) << 1);
    double *fft_output = (double *)malloc((sizeof(double) * width) << 1);

    if (inverse) {
        goto horizontal_fft;
    }

vertical_fft:
    for (j = 0; j < height; j++) {
        unsigned offset = j * width;
        for (i = 0; i < width; i++) {
            fft_input[i << 1] = data[offset << 1];
            fft_input[(i << 1) + 1] = data[(offset << 1) + 1];
            offset++;
        }
        dit2fft(fft_input, fft_output, width, inverse);
        offset = j * width;
        for (i = 0; i < width; i++) {
            data[offset << 1] = fft_output[i << 1];
            data[(offset << 1) + 1] = fft_output[(i << 1) + 1];
            offset++;
        }
    }

    if (inverse) {
        goto done;
    }

horizontal_fft:
    for (i = 0; i < width; i++) {
        unsigned offset = i;
        for (j = 0; j < height; j++) {
            fft_input[j << 1] = data[offset << 1];
            fft_input[(j << 1) + 1] = data[(offset << 1) + 1];
            offset += width;
        }
        dit2fft(fft_input, fft_output, height, inverse);
        offset = i;
        for (j = 0; j < height; j++) {
            data[offset << 1] = fft_output[j << 1];
            data[(offset << 1) + 1] = fft_output[(j << 1) + 1];
            offset += width;
        }
    }

    if (inverse) {
        goto vertical_fft;
    }

done:
    free(fft_input);
    free(fft_output);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %ebx
movl %edx, (%rsp)
movq %rdi, %r15
movq %rsi, 0x8(%rsp)
movl %esi, %r13d
movq %r13, 0x20(%rsp)
shlq $0x4, %r13
movq %r13, %rdi
callq 0x1080
movq %rax, %r12
movq %r13, %rdi
callq 0x1080
movq %rax, %r13
movl %ebx, 0x4(%rsp)
testl %ebx, %ebx
jne 0x163d
cmpl $0x0, (%rsp)
je 0x1632
movq 0x20(%rsp), %rax
leaq (%rax,%rax), %rbx
movq 0x8(%rsp), %rax
addl %eax, %eax
movq %rax, 0x10(%rsp)
xorl %ebp, %ebp
xorl %eax, %eax
movl %eax, 0x18(%rsp)
movl %ebp, %r14d
incq %r14
cmpl $0x0, 0x8(%rsp)
je 0x15d2
xorl %eax, %eax
leal (%rax,%rbp), %ecx
movsd (%r15,%rcx,8), %xmm0
movl %eax, %ecx
movsd %xmm0, (%r12,%rcx,8)
leal (%r14,%rax), %ecx
movsd (%r15,%rcx,8), %xmm0
leal 0x1(%rax), %ecx
movsd %xmm0, (%r12,%rcx,8)
addq $0x2, %rax
cmpq %rax, %rbx
jne 0x15a5
movq %r12, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
movl 0x4(%rsp), %ecx
callq 0x1392
cmpl $0x0, 0x8(%rsp)
je 0x161e
xorl %eax, %eax
movl %eax, %ecx
movsd (%r13,%rcx,8), %xmm0
leal (%rax,%rbp), %ecx
movsd %xmm0, (%r15,%rcx,8)
leal 0x1(%rax), %ecx
movsd (%r13,%rcx,8), %xmm0
leal (%r14,%rax), %ecx
movsd %xmm0, (%r15,%rcx,8)
addq $0x2, %rax
cmpq %rax, %rbx
jne 0x15ef
movl 0x18(%rsp), %eax
incl %eax
addq 0x10(%rsp), %rbp
cmpl (%rsp), %eax
jne 0x1592
cmpl $0x0, 0x4(%rsp)
jne 0x170e
cmpl $0x0, 0x8(%rsp)
je 0x1703
movl (%rsp), %ebx
addq %rbx, %rbx
movq 0x8(%rsp), %rax
leal (%rax,%rax), %ebp
xorl %eax, %eax
movl $0x1, %esi
movl (%rsp), %r14d
movq %rax, 0x18(%rsp)
cmpl $0x0, (%rsp)
je 0x169d
movl %esi, %eax
xorl %ecx, %ecx
leal -0x1(%rax), %edx
movsd (%r15,%rdx,8), %xmm0
movl %ecx, %edx
movsd %xmm0, (%r12,%rdx,8)
movl %eax, %edx
movsd (%r15,%rdx,8), %xmm0
leal 0x1(%rcx), %edx
movsd %xmm0, (%r12,%rdx,8)
addq $0x2, %rcx
addl %ebp, %eax
cmpq %rcx, %rbx
jne 0x1670
movq %r12, %rdi
movl %esi, 0x10(%rsp)
movq %r13, %rsi
movl %r14d, %edx
movl 0x4(%rsp), %ecx
callq 0x1392
movl 0x10(%rsp), %esi
testl %r14d, %r14d
je 0x16ef
movl %esi, %eax
xorl %ecx, %ecx
movl %ecx, %edx
movsd (%r13,%rdx,8), %xmm0
leal -0x1(%rax), %edx
movsd %xmm0, (%r15,%rdx,8)
leal 0x1(%rcx), %edx
movsd (%r13,%rdx,8), %xmm0
movl %eax, %edx
movsd %xmm0, (%r15,%rdx,8)
addq $0x2, %rcx
addl %ebp, %eax
cmpq %rcx, %rbx
jne 0x16c0
movq 0x18(%rsp), %rax
incl %eax
addl $0x2, %esi
cmpl 0x8(%rsp), %eax
jne 0x1661
cmpl $0x0, 0x4(%rsp)
jne 0x156f
movq %r12, %rdi
callq 0x1030
movq %r13, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1030