// File: /workspace/github_cpp_makefile_star2_O1/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 $0x108, %rsp            # imm = 0x108
movq %rcx, -0xb0(%rbp)
movq %rdx, -0x80(%rbp)
movq %rsi, %r14
movq %rdi, %r13
movq %r8, -0x38(%rbp)
movl (%r8), %r15d
movq %r9, -0x30(%rbp)
movl (%r9), %eax
movq %rax, -0x70(%rbp)
imulq %r15, %rax
movq %rax, %rdx
shlq $0x4, %rdx
movq %rsp, %rbx
subq %rdx, %rbx
movq %rbx, %rsp
testq %rax, %rax
je 0x894e
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3150
testq %r15, %r15
je 0x89ad
movq (%r14), %rax
leaq 0x8(%rbx), %rcx
movq -0x70(%rbp), %rsi
movq %rsi, %rdx
shlq $0x4, %rdx
leaq (,%rsi,8), %rsi
xorl %edi, %edi
cmpl $0x0, -0x70(%rbp)
je 0x89a2
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 0x8984
incq %rdi
addq %rdx, %rcx
cmpq %r15, %rdi
jne 0x896f
movq %r15, -0x100(%rbp)
movq %r15, %r12
shlq $0x4, %r12
movq %r12, %rdi
callq 0x3290
movq %rax, %r14
movq %rax, -0xf8(%rbp)
testq %r15, %r15
je 0x89df
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x3150
movq -0x30(%rbp), %rax
movl (%rax), %r12d
movq %r12, -0xf0(%rbp)
movq %r12, %r15
shlq $0x4, %r15
movq %r15, %rdi
callq 0x3290
movq %r13, -0xb8(%rbp)
movq %rax, -0xe8(%rbp)
testl %r12d, %r12d
movq %rax, %r12
je 0x8a1f
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x3150
movq %r12, -0x48(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x8a8b
movq -0x70(%rbp), %r13
shlq $0x4, %r13
xorl %r12d, %r12d
movq %rbx, %r15
movq -0x30(%rbp), %rax
movl (%rax), %edx
testq %rdx, %rdx
je 0x8a55
shlq $0x4, %rdx
movq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x3210
leaq -0xf0(%rbp), %rdi
callq 0x818c
movq -0x30(%rbp), %rax
movl (%rax), %edx
testq %rdx, %rdx
je 0x8a7c
shlq $0x4, %rdx
movq %r15, %rdi
movq -0x48(%rbp), %rsi
callq 0x3210
addq %r13, %r15
incl %r12d
movq -0x38(%rbp), %rax
cmpl %r12d, (%rax)
ja 0x8a3a
movq -0x30(%rbp), %rax
movl (%rax), %eax
testl %eax, %eax
je 0x8b19
movq -0x70(%rbp), %r15
shlq $0x4, %r15
xorl %r12d, %r12d
movq %rbx, %r13
movq -0x38(%rbp), %rax
movl (%rax), %eax
testq %rax, %rax
je 0x8ad1
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 0x8abb
leaq -0x100(%rbp), %rdi
callq 0x818c
movq -0x38(%rbp), %rax
movl (%rax), %eax
testq %rax, %rax
je 0x8b07
shlq $0x4, %rax
xorl %ecx, %ecx
movq %r13, %rdx
movupd (%r14,%rcx), %xmm0
movupd %xmm0, (%rdx)
addq %r15, %rdx
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0x8af1
incq %r12
movq -0x30(%rbp), %rax
movl (%rax), %eax
addq $0x10, %r13
cmpq %rax, %r12
jb 0x8aa7
movq -0x38(%rbp), %rcx
movl (%rcx), %r12d
movl %eax, %ecx
movq %r12, %rax
movq %rcx, -0x40(%rbp)
imulq %rcx, %rax
movq %rax, %rdx
shlq $0x4, %rdx
movq %rsp, %r15
subq %rdx, %r15
movq %r15, %rsp
testq %rax, %rax
je 0x8b4c
movq %r15, %rdi
xorl %esi, %esi
callq 0x3150
movq %r15, -0x58(%rbp)
movq %r12, -0x50(%rbp)
testq %r12, %r12
je 0x8b8e
movq -0x40(%rbp), %r15
shlq $0x4, %r15
shlq $0x4, -0x70(%rbp)
movq -0x50(%rbp), %r13
movq -0x58(%rbp), %r12
cmpl $0x0, -0x40(%rbp)
je 0x8b82
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x3210
addq -0x70(%rbp), %rbx
addq %r15, %r12
decq %r13
jne 0x8b6e
cvtsi2sdq -0x50(%rbp), %xmm2
xorpd %xmm0, %xmm0
divsd %xmm2, %xmm0
movsd 0x28dc(%rip), %xmm1     # 0xb480
divsd %xmm2, %xmm1
callq 0x3300
movsd %xmm0, -0x130(%rbp)
movsd %xmm1, -0x128(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
xorpd %xmm0, %xmm0
divsd %xmm2, %xmm0
movsd 0x28a5(%rip), %xmm1     # 0xb480
divsd %xmm2, %xmm1
callq 0x3300
movsd %xmm0, -0x120(%rbp)
movsd %xmm1, -0x118(%rbp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, -0xa0(%rbp)
xorl %ecx, %ecx
movq %rcx, -0x98(%rbp)
movq %rax, -0x90(%rbp)
movq %rcx, -0x88(%rbp)
movq -0x38(%rbp), %rcx
cmpl $0x0, (%rcx)
je 0x8e2a
movq -0x80(%rbp), %rax
movsd (%rax), %xmm0
mulsd %xmm0, %xmm0
movq -0xb0(%rbp), %rax
movsd (%rax), %xmm1
mulsd %xmm1, %xmm1
movsd %xmm0, -0xe0(%rbp)
movsd %xmm1, -0xd8(%rbp)
mulsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
movq -0x40(%rbp), %rax
shlq $0x4, %rax
movq %rax, -0xc0(%rbp)
xorl %edx, %edx
leaq -0x90(%rbp), %r12
leaq -0x120(%rbp), %r13
movq -0x58(%rbp), %rax
movq %rax, -0x78(%rbp)
movq %rdx, -0xc8(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x8def
movq -0x78(%rbp), %r15
xorl %ebx, %ebx
movsd -0xa0(%rbp), %xmm2
movsd -0x98(%rbp), %xmm3
movapd %xmm3, %xmm1
movapd 0x27d3(%rip), %xmm0     # 0xb490
xorpd %xmm0, %xmm1
movapd %xmm1, -0x70(%rbp)
movsd 0x27ba(%rip), %xmm0     # 0xb488
subsd %xmm2, %xmm0
movsd %xmm0, -0x50(%rbp)
xorpd %xmm1, %xmm1
movsd 0x232d(%rip), %xmm0     # 0xb010
callq 0x3170
movsd -0x50(%rbp), %xmm3
subsd %xmm0, %xmm3
movapd -0x70(%rbp), %xmm2
subsd %xmm1, %xmm2
movsd -0xd8(%rbp), %xmm0
mulsd %xmm0, %xmm3
movsd %xmm3, -0x50(%rbp)
mulsd %xmm0, %xmm2
movapd %xmm2, -0x70(%rbp)
movsd -0x90(%rbp), %xmm2
movsd -0x88(%rbp), %xmm3
movaps %xmm3, %xmm0
xorps 0x2762(%rip), %xmm0     # 0xb490
movaps %xmm0, -0xb0(%rbp)
movsd 0x274b(%rip), %xmm0     # 0xb488
subsd %xmm2, %xmm0
movsd %xmm0, -0x80(%rbp)
xorpd %xmm1, %xmm1
movsd 0x22be(%rip), %xmm0     # 0xb010
callq 0x3170
movsd -0x80(%rbp), %xmm2
movapd -0xb0(%rbp), %xmm3
subsd %xmm0, %xmm2
subsd %xmm1, %xmm3
movsd -0xe0(%rbp), %xmm0
mulsd %xmm0, %xmm2
addsd -0x50(%rbp), %xmm2
mulsd %xmm0, %xmm3
addsd -0x70(%rbp), %xmm3
ucomisd 0x229a(%rip), %xmm2     # 0xb028
jne 0x8d9e
jp 0x8d9e
ucomisd 0x228e(%rip), %xmm3     # 0xb028
jne 0x8d9e
jnp 0x8dce
xorpd %xmm1, %xmm1
movsd -0xd0(%rbp), %xmm0
callq 0x3170
movsd %xmm0, -0x110(%rbp)
movsd %xmm1, -0x108(%rbp)
movq %r15, %rdi
leaq -0x110(%rbp), %rsi
callq 0xa1f8
movq %r12, %rdi
movq %r13, %rsi
callq 0xa1f8
incq %rbx
movq -0x30(%rbp), %rax
movl (%rax), %eax
addq $0x10, %r15
cmpq %rax, %rbx
jb 0x8ca1
leaq -0xa0(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0xa1f8
movq -0xc8(%rbp), %rdx
incq %rdx
movq -0x38(%rbp), %rcx
movl (%rcx), %eax
movq -0x78(%rbp), %rsi
addq -0xc0(%rbp), %rsi
movq %rsi, -0x78(%rbp)
cmpq %rax, %rdx
jb 0x8c87
cmpl $0x0, (%rcx)
je 0x8e92
movq -0x40(%rbp), %rbx
shlq $0x4, %rbx
xorl %r13d, %r13d
leaq -0xf0(%rbp), %r15
movq -0x58(%rbp), %r12
movq -0x30(%rbp), %rax
movl (%rax), %edx
testq %rdx, %rdx
je 0x8e60
shlq $0x4, %rdx
movq -0x48(%rbp), %rdi
movq %r12, %rsi
callq 0x3210
movq %r15, %rdi
callq 0x8371
movq -0x30(%rbp), %rax
movl (%rax), %edx
testq %rdx, %rdx
je 0x8e83
shlq $0x4, %rdx
movq %r12, %rdi
movq -0x48(%rbp), %rsi
callq 0x3210
addq %rbx, %r12
incl %r13d
movq -0x38(%rbp), %rax
cmpl %r13d, (%rax)
ja 0x8e45
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x8f23
movq -0x40(%rbp), %rbx
shlq $0x4, %rbx
xorl %r12d, %r12d
leaq -0x100(%rbp), %r15
movq -0x58(%rbp), %r13
movq -0x38(%rbp), %rax
movl (%rax), %eax
testq %rax, %rax
je 0x8edf
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 0x8ec9
movq %r15, %rdi
callq 0x8371
movq -0x38(%rbp), %rax
movl (%rax), %eax
testq %rax, %rax
je 0x8f11
shlq $0x4, %rax
xorl %ecx, %ecx
movq %r13, %rdx
movupd (%r14,%rcx), %xmm0
movupd %xmm0, (%rdx)
addq %rbx, %rdx
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0x8efb
incq %r12
movq -0x30(%rbp), %rax
movl (%rax), %eax
addq $0x10, %r13
cmpq %rax, %r12
jb 0x8eb5
movq -0xb8(%rbp), %rbx
movq %rbx, %rdi
movq -0x38(%rbp), %r15
movq %r15, %rsi
movq -0x30(%rbp), %rdx
callq 0x854e
movl (%r15), %eax
testq %rax, %rax
movq -0x58(%rbp), %r10
je 0x8f94
movq -0x30(%rbp), %rcx
movl (%rcx), %ecx
movq (%rbx), %rdx
shlq $0x4, -0x40(%rbp)
movq %rcx, %rsi
shlq $0x3, %rsi
xorl %edi, %edi
testl %ecx, %ecx
je 0x8f88
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 0x8f73
incq %rdi
addq -0x40(%rbp), %r10
cmpq %rax, %rdi
jne 0x8f60
movq -0x48(%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 0x8fc4
movq %rax, %rbx
jmp 0x8fd0
jmp 0x8fc4
jmp 0x8fc4
jmp 0x8fc4
movq %rax, %rbx
movq -0x48(%rbp), %rdi
callq 0x3270
movq %r14, %rdi
callq 0x3270
movq %rbx, %rdi
callq 0x3460