// File: /workspace/github_cpp_makefile_star2_O3/dfrodriguezp[P]PiCM-cpp/functions.cc
// Function: potential(std::vector<std::valarray<double>, std::allocator<std::valarray<double>>> const&, double const&, double const&, unsigned int const&, unsigned int const&)
VecArr potential(const VecArr &rho, const Real &dx, const Real &dy,
                 const Int &Nx, const Int &Ny)
{
    Complex rho_k[Nx][Ny];

    for (Int i = 0; i < Nx; ++i)
    {
        for (Int j = 0; j < Ny; ++j)
        {
            rho_k[i][j] = rho[i][j];
        }
    }

    CArray f(Nx);
    CArray g(Ny);

    for (Int i = 0; i < Nx; ++i)
    {
        for (Int j = 0; j < Ny; ++j)
        {
            g[j] = rho_k[i][j];
        }
        fft(g);
        for (Int j = 0; j < Ny; ++j)
        {
            rho_k[i][j] = g[j];
        }
    }

    for (Int j = 0; j < Ny; ++j)
    {
        for (Int i = 0; i < Nx; ++i)
        {
            f[i] = rho_k[i][j];
        }
        fft(f);
        for (Int i = 0; i < Nx; ++i)
        {
            rho_k[i][j] = f[i];
        }
    }

    Complex phi_k[Nx][Ny];

    for (Int i = 0; i < Nx; ++i)
    {
        for (Int j = 0; j < Ny; ++j)
        {
            phi_k[i][j] = rho_k[i][j];
        }
    }

    Complex i(0.0, 1.0);
    Complex Wx = std::exp(2.0 * std::acos(-1.0) * i / Real(Nx));
    Complex Wy = std::exp(2.0 * std::acos(-1.0) * i / Real(Ny));
    Complex Wn = 1.0;
    Complex Wm = 1.0;
    Real dx_2 = dx * dx;
    Real dy_2 = dy * dy;

    for (Int n = 0; n < Nx; ++n)
    {
        for (Int m = 0; m < Ny; ++m)
        {
            Complex denom = dy_2 * (2.0 - Wn - 1.0 / Wn) + dx_2 * (2.0 - Wm - 1.0 / Wm);
            if (denom != 0.0)
            {
                phi_k[n][m] *= (dx_2 * dy_2) / denom;
            }
            Wm *= Wy;
        }
        Wn *= Wx;
    }

    for (Int i = 0; i < Nx; ++i)
    {
        for (Int j = 0; j < Ny; ++j)
        {
            g[j] = phi_k[i][j];
        }
        ifft(g);
        for (Int j = 0; j < Ny; ++j)
        {
            phi_k[i][j] = g[j];
        }
    }

    for (Int j = 0; j < Ny; ++j)
    {
        for (Int i = 0; i < Nx; ++i)
        {
            f[i] = phi_k[i][j];
        }
        ifft(f);
        for (Int i = 0; i < Nx; ++i)
        {
            phi_k[i][j] = f[i];
        }
    }

    VecArr phi = valarraysVector(Nx, Ny);
    for (Int i = 0; i < Nx; ++i)
    {
        for (Int j = 0; j < Ny; ++j)
        {
            phi[i][j] = std::real(phi_k[i][j]);
        }
    }

    return phi;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %r9, %r13
movq %rcx, -0xb0(%rbp)
movq %rdx, -0xc0(%rbp)
movq %rsi, %rbx
movq %rdi, %r12
movq %r8, -0x38(%rbp)
movl (%r8), %r15d
movl (%r9), %eax
movq %rax, -0x60(%rbp)
imulq %r15, %rax
movq %rax, %rdx
shlq $0x4, %rdx
movq %rsp, %r14
subq %rdx, %r14
movq %r14, %rsp
testq %rax, %rax
je 0x899d
movq %r14, %rdi
xorl %esi, %esi
callq 0x3150
testq %r15, %r15
je 0x89fc
movq (%rbx), %rax
leaq 0x8(%r14), %rcx
movq -0x60(%rbp), %rsi
movq %rsi, %rdx
shlq $0x4, %rdx
leaq (,%rsi,8), %rsi
xorl %edi, %edi
cmpl $0x0, -0x60(%rbp)
je 0x89f1
movq %rdi, %r8
shlq $0x4, %r8
movq 0x8(%rax,%r8), %r8
xorl %r9d, %r9d
movsd (%r8,%r9), %xmm0
movsd %xmm0, -0x8(%rcx,%r9,2)
movq $0x0, (%rcx,%r9,2)
addq $0x8, %r9
cmpq %r9, %rsi
jne 0x89d3
incq %rdi
addq %rdx, %rcx
cmpq %r15, %rdi
jne 0x89be
movq %r14, -0x90(%rbp)
movq %r15, -0x110(%rbp)
movq %r15, %rbx
shlq $0x4, %rbx
movq %rbx, %rdi
callq 0x3290
movq %rax, %r14
movq %rax, -0x108(%rbp)
testl %r15d, %r15d
je 0x8a35
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x3150
movl (%r13), %r15d
movq %r15, -0x100(%rbp)
movq %r15, %rbx
shlq $0x4, %rbx
movq %rbx, %rdi
callq 0x3290
movq %r12, -0xe8(%rbp)
movq %rax, -0xf8(%rbp)
testl %r15d, %r15d
movq %rax, %r15
je 0x8a72
movq %r15, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x3150
movq %r15, -0x40(%rbp)
xorl %r12d, %r12d
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
movq %r13, -0x30(%rbp)
movl (%r13), %r13d
je 0x8af4
movq -0x60(%rbp), %rax
shlq $0x4, %rax
movq %rax, -0x80(%rbp)
xorl %ebx, %ebx
movq -0x90(%rbp), %r15
testl %r13d, %r13d
je 0x8ab7
movl %r13d, %edx
shlq $0x4, %rdx
movq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x3210
leaq -0x100(%rbp), %rdi
callq 0x81ec
movq -0x30(%rbp), %rax
movl (%rax), %r13d
testq %r13, %r13
je 0x8ae2
movq %r13, %rdx
shlq $0x4, %rdx
movq %r15, %rdi
movq -0x40(%rbp), %rsi
callq 0x3210
movq -0x38(%rbp), %rax
movl (%rax), %eax
addq -0x80(%rbp), %r15
incl %ebx
cmpl %ebx, %eax
ja 0x8a9f
jmp 0x8af6
xorl %eax, %eax
testl %r13d, %r13d
je 0x8b81
movq -0x60(%rbp), %r15
shlq $0x4, %r15
xorl %ebx, %ebx
movq -0x90(%rbp), %r13
testl %eax, %eax
je 0x8b35
movl %eax, %eax
shlq $0x4, %rax
xorl %ecx, %ecx
movq %r13, %rdx
movupd (%rdx), %xmm0
movupd %xmm0, (%r14,%rcx)
addq %r15, %rdx
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0x8b1f
leaq -0x110(%rbp), %rdi
callq 0x81ec
movq -0x38(%rbp), %rax
movl (%rax), %eax
testq %rax, %rax
je 0x8b6e
movq %rax, %rcx
shlq $0x4, %rcx
xorl %edx, %edx
movq %r13, %rsi
movupd (%r14,%rdx), %xmm0
movupd %xmm0, (%rsi)
addq %r15, %rsi
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x8b58
incq %rbx
movq -0x30(%rbp), %rcx
movl (%rcx), %r12d
addq $0x10, %r13
cmpq %r12, %rbx
jb 0x8b10
movl %eax, %ebx
movl %r12d, %ecx
movq %rbx, %rax
movq %rcx, -0x48(%rbp)
imulq %rcx, %rax
movq %rax, %rdx
shlq $0x4, %rdx
movq %rsp, %r15
subq %rdx, %r15
movq %r15, %rsp
testq %rax, %rax
je 0x8bb0
movq %r15, %rdi
xorl %esi, %esi
callq 0x3150
movq %r15, -0x50(%rbp)
movq %rbx, -0x80(%rbp)
testq %rbx, %rbx
je 0x8c00
movq -0x48(%rbp), %r15
shlq $0x4, %r15
shlq $0x4, -0x60(%rbp)
movq -0x80(%rbp), %r13
movq -0x50(%rbp), %r12
cmpl $0x0, -0x48(%rbp)
movq -0x90(%rbp), %rbx
je 0x8bed
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x3210
addq -0x60(%rbp), %rbx
movq %rbx, -0x90(%rbp)
addq %r15, %r12
decq %r13
jne 0x8bd2
cvtsi2sdq -0x80(%rbp), %xmm2
xorpd %xmm0, %xmm0
divsd %xmm2, %xmm0
movsd 0x287a(%rip), %xmm1     # 0xb490
divsd %xmm2, %xmm1
callq 0x3300
movsd %xmm0, -0x140(%rbp)
movsd %xmm1, -0x138(%rbp)
movq -0x30(%rbp), %rbx
movl (%rbx), %eax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
xorpd %xmm0, %xmm0
divsd %xmm2, %xmm0
movsd 0x2843(%rip), %xmm1     # 0xb490
divsd %xmm2, %xmm1
callq 0x3300
movsd %xmm0, -0x130(%rbp)
movsd %xmm1, -0x128(%rbp)
movsd 0x23a2(%rip), %xmm0     # 0xb010
movapd %xmm0, -0xe0(%rbp)
movapd %xmm0, -0xd0(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x8eef
movq -0xb0(%rbp), %rax
movsd (%rax), %xmm0
movq -0xc0(%rbp), %rax
movhpd (%rax), %xmm0           # xmm0 = xmm0[0],mem[0]
mulpd %xmm0, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movapd %xmm0, -0x160(%rbp)
mulsd %xmm0, %xmm1
movapd %xmm1, -0x150(%rbp)
movq -0x48(%rbp), %rax
shlq $0x4, %rax
movq %rax, -0x98(%rbp)
xorl %ecx, %ecx
leaq -0xd0(%rbp), %r12
leaq -0x130(%rbp), %r13
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movq %rcx, -0xf0(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x8e48
movq -0x68(%rbp), %r15
xorl %ebx, %ebx
movsd -0xe0(%rbp), %xmm2
movaps %xmm2, -0xc0(%rbp)
movsd -0xd8(%rbp), %xmm3
movaps %xmm3, -0x90(%rbp)
xorpd %xmm1, %xmm1
movsd 0x22e4(%rip), %xmm0     # 0xb010
callq 0x3170
movaps %xmm0, -0x80(%rbp)
movapd %xmm1, -0x60(%rbp)
movsd -0xd0(%rbp), %xmm2
movaps %xmm2, -0x170(%rbp)
movsd -0xc8(%rbp), %xmm3
movaps %xmm3, -0xb0(%rbp)
xorpd %xmm1, %xmm1
movsd 0x22ac(%rip), %xmm0     # 0xb010
callq 0x3170
movapd -0xc0(%rbp), %xmm2
unpcklpd -0x170(%rbp), %xmm2     # xmm2 = xmm2[0],mem[0]
movapd 0x274f(%rip), %xmm3     # 0xb4d0
subpd %xmm2, %xmm3
movapd -0x80(%rbp), %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
subpd %xmm2, %xmm3
movapd -0x160(%rbp), %xmm0
mulpd %xmm0, %xmm3
movapd -0x90(%rbp), %xmm4
unpcklpd -0xb0(%rbp), %xmm4      # xmm4 = xmm4[0],mem[0]
xorpd 0x26ea(%rip), %xmm4     # 0xb4a0
movapd -0x60(%rbp), %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
subpd %xmm2, %xmm4
mulpd %xmm0, %xmm4
movapd %xmm3, %xmm2
unpckhpd %xmm3, %xmm2            # xmm2 = xmm2[1],xmm3[1]
addsd %xmm3, %xmm2
movapd %xmm4, %xmm3
unpckhpd %xmm4, %xmm3            # xmm3 = xmm3[1],xmm4[1]
addsd %xmm4, %xmm3
ucomisd 0x2249(%rip), %xmm2     # 0xb030
jne 0x8df7
jp 0x8df7
ucomisd 0x223d(%rip), %xmm3     # 0xb030
jne 0x8df7
jnp 0x8e27
xorpd %xmm1, %xmm1
movapd -0x150(%rbp), %xmm0
callq 0x3170
movsd %xmm0, -0x120(%rbp)
movsd %xmm1, -0x118(%rbp)
movq %r15, %rdi
leaq -0x120(%rbp), %rsi
callq 0xa1f4
movq %r12, %rdi
movq %r13, %rsi
callq 0xa1f4
incq %rbx
movq -0x30(%rbp), %rax
movl (%rax), %eax
addq $0x10, %r15
cmpq %rax, %rbx
jb 0x8d02
leaq -0xe0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0xa1f4
movq -0xf0(%rbp), %rcx
incq %rcx
movq -0x38(%rbp), %rax
movl (%rax), %eax
movq -0x68(%rbp), %rdx
addq -0x98(%rbp), %rdx
movq %rdx, -0x68(%rbp)
cmpq %rax, %rcx
jb 0x8ce8
movq -0x30(%rbp), %rcx
movl (%rcx), %r13d
testl %eax, %eax
je 0x8ef2
xorl %ebx, %ebx
leaq -0x100(%rbp), %r15
movq -0x50(%rbp), %r12
testl %r13d, %r13d
je 0x8eb3
movl %r13d, %edx
shlq $0x4, %rdx
movq -0x40(%rbp), %rdi
movq %r12, %rsi
callq 0x3210
movq %r15, %rdi
callq 0x83aa
movq -0x30(%rbp), %rax
movl (%rax), %r13d
testq %r13, %r13
je 0x8eda
movq %r13, %rdx
shlq $0x4, %rdx
movq %r12, %rdi
movq -0x40(%rbp), %rsi
callq 0x3210
movq -0x38(%rbp), %rax
movl (%rax), %eax
addq -0x98(%rbp), %r12
incl %ebx
cmpl %ebx, %eax
ja 0x8e9b
jmp 0x8ef4
movl (%rbx), %r13d
xorl %eax, %eax
testl %r13d, %r13d
je 0x8f7f
movq -0x48(%rbp), %rbx
shlq $0x4, %rbx
xorl %r12d, %r12d
leaq -0x110(%rbp), %r15
movq -0x50(%rbp), %r13
testl %eax, %eax
je 0x8f38
movl %eax, %eax
shlq $0x4, %rax
xorl %ecx, %ecx
movq %r13, %rdx
movupd (%rdx), %xmm0
movupd %xmm0, (%r14,%rcx)
addq %rbx, %rdx
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0x8f22
movq %r15, %rdi
callq 0x83aa
movq -0x38(%rbp), %rax
movl (%rax), %eax
testq %rax, %rax
je 0x8f6d
movq %rax, %rcx
shlq $0x4, %rcx
xorl %edx, %edx
movq %r13, %rsi
movupd (%r14,%rdx), %xmm0
movupd %xmm0, (%rsi)
addq %rbx, %rsi
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x8f57
incq %r12
movq -0x30(%rbp), %rcx
movl (%rcx), %ecx
addq $0x10, %r13
cmpq %rcx, %r12
jb 0x8f13
movq -0xe8(%rbp), %rbx
movq %rbx, %rdi
movq -0x38(%rbp), %r12
movq %r12, %rsi
movq -0x30(%rbp), %r15
movq %r15, %rdx
callq 0x858b
movl (%r12), %eax
testq %rax, %rax
movq -0x50(%rbp), %r10
je 0x8ff1
movl (%r15), %ecx
movq (%rbx), %rdx
shlq $0x4, -0x48(%rbp)
movq %rcx, %rsi
shlq $0x3, %rsi
xorl %edi, %edi
testl %ecx, %ecx
je 0x8fe5
movq %rdi, %r8
shlq $0x4, %r8
movq 0x8(%rdx,%r8), %r8
xorl %r9d, %r9d
movsd (%r10,%r9,2), %xmm0
movsd %xmm0, (%r8,%r9)
addq $0x8, %r9
cmpq %r9, %rsi
jne 0x8fd0
incq %rdi
addq -0x48(%rbp), %r10
cmpq %rax, %rdi
jne 0x8fbd
movq -0x40(%rbp), %rdi
callq 0x3270
movq %r14, %rdi
callq 0x3270
movq %rbx, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9021
movq %rax, %rbx
jmp 0x902d
jmp 0x9021
jmp 0x9021
jmp 0x9021
movq %rax, %rbx
movq -0x40(%rbp), %rdi
callq 0x3270
movq %r14, %rdi
callq 0x3270
movq %rbx, %rdi
callq 0x3460