// File: 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
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0xf8(%rbp)
movq %rdi, %rax
movq %rax, -0xf0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movb $0x0, -0x31(%rbp)
callq 0x7620
movq $0x0, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movl $0x3, %edx
callq 0x10b70
jmp 0xf1c9
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jae 0xf26a
leaq -0x78(%rbp), %rdi
callq 0x70e0
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
jae 0xf241
leaq -0x78(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x71c0
jmp 0xf209
jmp 0xf20b
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0xf1ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xf643
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x76f0
jmp 0xf61c
movq -0xf8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x11060
jmp 0xf253
leaq -0x78(%rbp), %rdi
callq 0x76f0
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0xf1d0
movl $0x0, -0x80(%rbp)
movl -0x80(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
jae 0xf436
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jae 0xf426
movl -0x84(%rbp), %eax
incl %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xda30
cvttsd2si %xmm0, %rax
movl %eax, -0x88(%rbp)
movl -0x84(%rbp), %eax
decl %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0xda30
cvttsd2si %xmm0, %rax
movl %eax, -0x9c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x9c(%rbp), %eax
movl %eax, %esi
callq 0x10cd0
movq %rax, %rdi
movl -0x80(%rbp), %eax
movl %eax, %esi
callq 0x10c10
movq %rax, -0x100(%rbp)
jmp 0xf34f
movq -0x100(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x110(%rbp)
movq -0x10(%rbp), %rdi
movl -0x88(%rbp), %eax
movl %eax, %esi
callq 0x10cd0
movq %rax, %rdi
movl -0x80(%rbp), %eax
movl %eax, %esi
callq 0x10c10
movq %rax, -0x108(%rbp)
jmp 0xf389
movq -0xf8(%rbp), %rdi
movsd -0x110(%rbp), %xmm0
movq -0x108(%rbp), %rax
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd (%rax), %xmm1
addsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x120(%rbp)
movl -0x84(%rbp), %eax
movl %eax, %esi
callq 0x7cf0
movq %rax, %rdi
movl -0x80(%rbp), %eax
movl %eax, %esi
callq 0x7d10
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6fb0
movq %rax, -0x118(%rbp)
jmp 0xf3ee
movq -0x118(%rbp), %rax
movsd -0x120(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0xf28a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xf61c
jmp 0xf428
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0xf271
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jae 0xf607
movl $0x0, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
jae 0xf5f1
movl -0xb8(%rbp), %eax
incl %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0xc8(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0xda30
cvttsd2si %xmm0, %rax
movl %eax, -0xbc(%rbp)
movl -0xb8(%rbp), %eax
decl %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0xe0(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0xe8(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0xda30
cvttsd2si %xmm0, %rax
movl %eax, -0xd4(%rbp)
movq -0x10(%rbp), %rdi
movl -0xb4(%rbp), %eax
movl %eax, %esi
callq 0x10cd0
movq %rax, %rdi
movl -0xd4(%rbp), %eax
movl %eax, %esi
callq 0x10c10
movq %rax, -0x128(%rbp)
jmp 0xf524
movq -0x128(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x138(%rbp)
movq -0x10(%rbp), %rdi
movl -0xb4(%rbp), %eax
movl %eax, %esi
callq 0x10cd0
movq %rax, %rdi
movl -0xbc(%rbp), %eax
movl %eax, %esi
callq 0x10c10
movq %rax, -0x130(%rbp)
jmp 0xf561
movq -0xf8(%rbp), %rdi
movsd -0x138(%rbp), %xmm0
movq -0x130(%rbp), %rax
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movsd (%rax), %xmm1
addsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x148(%rbp)
movl -0xb4(%rbp), %eax
movl %eax, %esi
callq 0x7cf0
movq %rax, %rdi
movl -0xb8(%rbp), %eax
movl %eax, %esi
callq 0x7d10
movq %rax, %rdi
movl $0x1, %esi
callq 0x6fb0
movq %rax, -0x140(%rbp)
jmp 0xf5ca
movq -0x140(%rbp), %rax
movsd -0x148(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0xf45c
jmp 0xf5f3
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0xf440
movb $0x1, -0x31(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x7340
testb $0x1, -0x31(%rbp)
jne 0xf633
jmp 0xf627
leaq -0x48(%rbp), %rdi
callq 0x7340
jmp 0xf643
movq -0xf8(%rbp), %rdi
callq 0x7780
movq -0xf0(%rbp), %rax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0xf8(%rbp), %rdi
callq 0x7780
movq -0x58(%rbp), %rdi
callq 0x3530
nopl (%rax,%rax)