// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq %r8, %rbx
movq %rcx, 0x70(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdi, %r13
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq $0x3, 0x60(%rsp)
movl $0x18, %edi
callq 0x3290
movq %rax, 0x68(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rbx, 0x28(%rsp)
cmpl $0x0, (%rbx)
movl $0x0, %ecx
je 0x9105
xorl %ebx, %ebx
leaq 0x40(%rsp), %r12
leaq 0x60(%rsp), %rbp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
cmpl $0x0, (%r14)
je 0x90e5
xorl %r15d, %r15d
movq %r12, %rdi
movq %rbp, %rsi
callq 0x6ef8
incl %r15d
cmpl (%r14), %r15d
jb 0x90d2
movq %r13, %rdi
movq %r12, %rsi
callq 0xa262
movq %r12, %rdi
callq 0x7026
incl %ebx
movq 0x28(%rsp), %rax
movl (%rax), %ecx
cmpl %ecx, %ebx
jb 0x90b6
movl (%r14), %eax
testl %eax, %eax
movq %r14, 0x38(%rsp)
movq %r13, 0x10(%rsp)
je 0x9244
xorl %ebx, %ebx
movl %ecx, %edx
movl $0x0, %esi
testl %edx, %edx
je 0x9232
movq %rbx, %rax
shlq $0x4, %rax
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
leaq 0x1(%r12), %rbp
movl %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x40(%rsp)
movl %edx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x40(%rsp), %r14
movq %r14, %rdi
leaq 0x8(%rsp), %r13
movq %r13, %rsi
callq 0x8526
cvttsd2si %xmm0, %rax
movq %rax, 0x30(%rsp)
decl %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x28(%rsp), %r12
movl (%r12), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x8526
cvttsd2si %xmm0, %rax
movq 0x58(%rsp), %rcx
movq (%rcx), %rcx
movl %eax, %eax
shlq $0x4, %rax
movq 0x8(%rcx,%rax), %rax
movl 0x30(%rsp), %edx
movsd (%rax,%rbx,8), %xmm0
shlq $0x4, %rdx
movq 0x8(%rcx,%rdx), %rax
subsd (%rax,%rbx,8), %xmm0
movq 0x18(%rsp), %rax
movsd (%rax), %xmm1
addsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r15), %rax
movq 0x20(%rsp), %rcx
movq 0x8(%rax,%rcx), %rax
movsd %xmm0, (%rax)
movl (%r12), %edx
addq $0x18, %r15
movq %rbp, %r12
cmpq %rdx, %rbp
jb 0x913d
movq 0x38(%rsp), %rax
movl (%rax), %eax
movl %edx, %ecx
movl %edx, %esi
movq 0x10(%rsp), %r13
incq %rbx
movl %eax, %edi
movl %esi, %edx
cmpq %rdi, %rbx
jb 0x911e
jmp 0x9246
xorl %eax, %eax
movq %r13, %r14
testl %ecx, %ecx
je 0x937e
xorl %edi, %edi
leaq 0x40(%rsp), %rbx
leaq 0x8(%rsp), %r13
movl $0x0, %edx
testl %eax, %eax
je 0x936e
movl $0x8, %r15d
movq %rdi, %rcx
shlq $0x4, %rcx
movq %rcx, 0x30(%rsp)
movq %rdi, 0x18(%rsp)
leaq (%rdi,%rdi,2), %rcx
movq %rcx, 0x20(%rsp)
xorl %r12d, %r12d
leaq 0x1(%r12), %rbp
movl %ebp, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x40(%rsp)
movl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x8526
cvttsd2si %xmm0, %r14
decl %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x38(%rsp), %rax
movl (%rax), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x8526
cvttsd2si %xmm0, %rax
movq 0x58(%rsp), %rcx
movq (%rcx), %rcx
movq 0x30(%rsp), %rdx
movq 0x8(%rcx,%rdx), %rcx
movl %eax, %eax
movsd (%rcx,%rax,8), %xmm0
movl %r14d, %eax
subsd (%rcx,%rax,8), %xmm0
movq 0x70(%rsp), %rax
movsd (%rax), %xmm1
addsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax,%r15), %rax
movsd %xmm0, 0x8(%rax)
movq 0x38(%rsp), %rax
movl (%rax), %eax
addq $0x10, %r15
movq %rbp, %r12
cmpq %rax, %rbp
jb 0x928d
movq 0x28(%rsp), %rcx
movl (%rcx), %ecx
movl %eax, %edx
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rdi
incq %rdi
movl %ecx, %esi
movl %edx, %eax
cmpq %rsi, %rdi
jb 0x925d
movq 0x68(%rsp), %rdi
callq 0x3270
movq %r14, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x93b8
jmp 0x93a1
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x7026
movq 0x68(%rsp), %rdi
callq 0x3270
movq %r13, %rdi
callq 0x706e
movq %r14, %rdi
callq 0x3460