// File: /workspace/github_cpp_makefile_star2_O2/dfrodriguezp[P]PiCM-cpp/functions.cc
// Function: fieldNodes(std::vector<std::valarray<double>, std::allocator<std::valarray<double>>> const&, double const&, double const&, unsigned int const&, unsigned int const&)
VecVecArr fieldNodes(const VecArr &phi, const Real &dx, const Real &dy,
                     const Int &Nx, const Int &Ny)
{
    VecVecArr E;
    Array zeros(0.0, 3);
    for (Int i = 0; i < Nx; ++i)
    {
        VecArr rows;
        for (Int j = 0; j < Ny; ++j)
        {
            rows.push_back(zeros);
        }
        E.push_back(rows);
    }

    for (Int j = 0; j < Ny; ++j)
    {
        for (Int i = 0; i < Nx; ++i)
        {
            Int nxt_i = Int(mod(Real(i + 1), Real(Nx)));
            Int prv_i = Int(mod(Real(i - 1), Real(Nx)));
            E[i][j][0] = (phi[prv_i][j] - phi[nxt_i][j]) / (dx * 2.0);
        }
    }

    for (Int i = 0; i < Nx; ++i)
    {
        for (Int j = 0; j < Ny; ++j)
        {
            Int nxt_j = Int(mod(Real(j + 1), Real(Ny)));
            Int prv_j = Int(mod(Real(j - 1), Real(Ny)));

            E[i][j][1] = (phi[i][prv_j] - phi[i][nxt_j]) / (dy * 2.0);
        }
    }

    return E;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, 0x38(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, 0x60(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, 0x58(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
movq %rdi, 0x8(%rsp)
andq $0x0, 0x10(%rdi)
leaq 0x40(%rsp), %rsi
andq $0x0, (%rsi)
leaq 0x68(%rsp), %rdi
pushq $0x3
popq %rdx
callq 0x7708
xorl %ebx, %ebx
leaq 0x40(%rsp), %r12
leaq 0x68(%rsp), %rbp
movq 0x28(%rsp), %rax
movl (%rax), %eax
cmpl %eax, %ebx
jae 0x6ba5
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
xorl %r15d, %r15d
movq 0x38(%rsp), %rax
cmpl (%rax), %r15d
jae 0x6b8c
movq %r12, %rdi
movq %rbp, %rsi
callq 0x49ca
incl %r15d
jmp 0x6b72
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x7886
movq %r12, %rdi
callq 0x4b46
incl %ebx
jmp 0x6b54
xorl %r15d, %r15d
movq 0x38(%rsp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %r15
jae 0x6cb2
movq %r15, %rcx
shlq $0x4, %rcx
movq %rcx, 0x20(%rsp)
xorl %ebp, %ebp
xorl %r12d, %r12d
movl %eax, %ecx
cmpq %rcx, %r12
jae 0x6caa
leaq 0x1(%r12), %rax
movq %rax, 0x30(%rsp)
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x40(%rsp)
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x40(%rsp), %r13
movq %r13, %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x6060
cvttsd2si %xmm0, %r14
decl %r12d
cvtsi2sd %r12, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x28(%rsp), %r12
movl (%r12), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6060
cvttsd2si %xmm0, %rax
movl %eax, %eax
movq 0x58(%rsp), %rcx
movq (%rcx), %rcx
shlq $0x4, %rax
movq 0x8(%rcx,%rax), %rax
movsd (%rax,%r15,8), %xmm0
movl %r14d, %eax
shlq $0x4, %rax
movq 0x8(%rcx,%rax), %rax
subsd (%rax,%r15,8), %xmm0
movq 0x18(%rsp), %rax
movsd (%rax), %xmm1
addsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%rax,%rbp), %rax
movq 0x20(%rsp), %rcx
movq 0x8(%rax,%rcx), %rax
movsd %xmm0, (%rax)
movl (%r12), %eax
addq $0x18, %rbp
movq 0x30(%rsp), %r12
jmp 0x6bc9
incq %r15
jmp 0x6ba8
xorl %edx, %edx
movl %eax, %eax
cmpq %rax, %rdx
jae 0x6dbf
movq %rdx, %rax
shlq $0x4, %rax
movq %rax, 0x30(%rsp)
movq %rdx, 0x18(%rsp)
imulq $0x18, %rdx, %rax
movq %rax, 0x20(%rsp)
pushq $0x8
popq %rbx
xorl %ebp, %ebp
movl %ecx, %eax
cmpq %rax, %rbp
jae 0x6dab
leaq 0x1(%rbp), %r12
movl %r12d, %ecx
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x40(%rsp)
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x40(%rsp), %r13
movq %r13, %rdi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0x6060
cvttsd2si %xmm0, %r14
decl %ebp
cvtsi2sd %rbp, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x38(%rsp), %rbp
movl (%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x6060
cvttsd2si %xmm0, %rax
movq 0x58(%rsp), %rcx
movq (%rcx), %rcx
movl %eax, %eax
movq 0x30(%rsp), %rdx
movq 0x8(%rcx,%rdx), %rcx
movsd (%rcx,%rax,8), %xmm0
movl %r14d, %eax
subsd (%rcx,%rax,8), %xmm0
movq 0x60(%rsp), %rax
movsd (%rax), %xmm1
addsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx), %rax
movq (%rax,%rbx), %rax
movsd %xmm0, 0x8(%rax)
movl (%rbp), %ecx
addq $0x10, %rbx
movq %r12, %rbp
jmp 0x6cde
movq 0x18(%rsp), %rdx
incq %rdx
movq 0x28(%rsp), %rax
movl (%rax), %eax
jmp 0x6cb4
movq 0x70(%rsp), %rdi
callq 0x2230
movq 0x8(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x6dfb
jmp 0x6de4
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x4b46
movq 0x70(%rsp), %rdi
callq 0x2230
movq 0x8(%rsp), %rdi
callq 0x4b68
movq %r14, %rdi
callq 0x2430