// File: dfrodriguezp[P]PiCM-cpp/functions.cc
// Function: fieldParticles(std::vector<std::vector<std::valarray<double>, std::allocator<std::valarray<double>>>, std::allocator<std::vector<std::valarray<double>, std::allocator<std::valarray<double>>>>> const&, std::vector<std::valarray<double>, std::allocator<std::valarray<double>>> const&, std::vector<unsigned int, std::allocator<unsigned int>> const&, double const&, double const&, unsigned int const&, unsigned int const&, unsigned int const&)
VecArr fieldParticles(const VecVecArr &field,
                      const VecArr &positions,
                      const std::vector<Int> &moves,
                      const Real &dx, const Real &dy,
                      const Int &Nx, const Int &Ny, const Int &N)
{
    VecArr E = valarraysVector(N, 3);

    for (Int p = 0; p < N; ++p)
    {
        if (moves.at(p))
        {
            Int i = std::floor(positions.at(p)[0] / dx);
            Int j = std::floor(positions.at(p)[1] / dy);
            Real hx = positions.at(p)[0] - (i * dx);
            Real hy = positions.at(p)[1] - (j * dy);
            Int nxt_i = Int(mod(Real(i + 1), Real(Nx)));
            Int nxt_j = Int(mod(Real(j + 1), Real(Ny)));

            Real A = (dx - hx) * (dy - hy);
            Real B = (dx - hx) * hy;
            Real C = hx * (dy - hy);
            Real D = hx * hy;

            E[p][0] = field[i][j][0] * A + field[i][nxt_j][0] * B + field[nxt_i][j][0] * C + field[nxt_i][nxt_j][0] * D;
            E[p][1] = field[i][j][1] * A + field[i][nxt_j][1] * B + field[nxt_i][j][1] * C + field[nxt_i][nxt_j][1] * D;
        }
    }

    for (Int i = 0; i < N; ++i)
    {
        E[i] /= (dx * dy);
    }

    return E;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rdi, -0xd8(%rbp)
movq %rdi, %rax
movq %rax, -0xd0(%rbp)
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
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)
movq 0x20(%rbp), %rsi
movl $0x3, -0x38(%rbp)
leaq -0x38(%rbp), %rdx
callq 0xdae0
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq 0x20(%rbp), %rcx
cmpl (%rcx), %eax
jae 0xfce0
movq -0x20(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x110d0
movq %rax, -0xe0(%rbp)
jmp 0xf6e5
movq -0xe0(%rbp), %rax
cmpl $0x0, (%rax)
je 0xfcd0
movq -0x18(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x10bd0
movq %rax, -0xe8(%rbp)
jmp 0xf70c
movq -0xe8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10c10
movq %rax, -0xf0(%rbp)
jmp 0xf725
movq -0xf0(%rbp), %rax
movsd (%rax), %xmm0
movq -0x28(%rbp), %rax
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x34f0
cvttsd2si %xmm0, %rax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x10bd0
movq %rax, -0xf8(%rbp)
jmp 0xf760
movq -0xf8(%rbp), %rdi
movl $0x1, %esi
callq 0x10c10
movq %rax, -0x100(%rbp)
jmp 0xf77a
movq -0x100(%rbp), %rax
movsd (%rax), %xmm0
movq -0x30(%rbp), %rax
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x34f0
cvttsd2si %xmm0, %rax
movl %eax, -0x54(%rbp)
movq -0x18(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x10bd0
movq %rax, -0x108(%rbp)
jmp 0xf7b5
movq -0x108(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10c10
movq %rax, -0x110(%rbp)
jmp 0xf7ce
movq -0x110(%rbp), %rax
movsd (%rax), %xmm0
movl -0x50(%rbp), %eax
cvtsi2sd %rax, %xmm1
movq -0x28(%rbp), %rax
movsd (%rax), %xmm2
mulsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x10bd0
movq %rax, -0x118(%rbp)
jmp 0xf80d
movq -0x118(%rbp), %rdi
movl $0x1, %esi
callq 0x10c10
movq %rax, -0x120(%rbp)
jmp 0xf827
movq -0x120(%rbp), %rax
movsd (%rax), %xmm0
movl -0x54(%rbp), %eax
cvtsi2sd %rax, %xmm1
movq -0x30(%rbp), %rax
movsd (%rax), %xmm2
mulsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movl -0x50(%rbp), %eax
incl %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x78(%rbp)
movq 0x10(%rbp), %rax
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xda30
cvttsd2si %xmm0, %rax
movl %eax, -0x6c(%rbp)
movl -0x54(%rbp), %eax
incl %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x90(%rbp)
movq 0x18(%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, -0x84(%rbp)
movq -0x28(%rbp), %rax
movsd (%rax), %xmm0
movsd -0x60(%rbp), %xmm1
subsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movsd (%rax), %xmm1
movsd -0x68(%rbp), %xmm2
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movq -0x28(%rbp), %rax
movsd (%rax), %xmm0
movsd -0x60(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd -0x68(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x60(%rbp), %xmm0
movq -0x30(%rbp), %rax
movsd (%rax), %xmm1
movsd -0x68(%rbp), %xmm2
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x60(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %eax
movl %eax, %esi
callq 0x11110
movq %rax, %rdi
movl -0x54(%rbp), %eax
movl %eax, %esi
callq 0x10cd0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10c10
movq %rax, -0x128(%rbp)
jmp 0xf97e
movq -0x128(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x140(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x138(%rbp)
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %eax
movl %eax, %esi
callq 0x11110
movq %rax, %rdi
movl -0x84(%rbp), %eax
movl %eax, %esi
callq 0x10cd0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10c10
movq %rax, -0x130(%rbp)
jmp 0xf9d4
movsd -0x138(%rbp), %xmm2
movsd -0x140(%rbp), %xmm0
movq -0x130(%rbp), %rax
movsd (%rax), %xmm1
movsd -0xa8(%rbp), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x150(%rbp)
movq -0x10(%rbp), %rdi
movl -0x6c(%rbp), %eax
movl %eax, %esi
callq 0x11110
movq %rax, %rdi
movl -0x54(%rbp), %eax
movl %eax, %esi
callq 0x10cd0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10c10
movq %rax, -0x148(%rbp)
jmp 0xfa3b
movsd -0x150(%rbp), %xmm1
movq -0x148(%rbp), %rax
movsd (%rax), %xmm0
movsd -0xb0(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x160(%rbp)
movq -0x10(%rbp), %rdi
movl -0x6c(%rbp), %eax
movl %eax, %esi
callq 0x11110
movq %rax, %rdi
movl -0x84(%rbp), %eax
movl %eax, %esi
callq 0x10cd0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10c10
movq %rax, -0x158(%rbp)
jmp 0xfa99
movq -0xd8(%rbp), %rdi
movsd -0x160(%rbp), %xmm1
movq -0x158(%rbp), %rax
movsd (%rax), %xmm0
movsd -0xb8(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x170(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x7d10
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6fb0
movq %rax, -0x168(%rbp)
jmp 0xfaea
movq -0x168(%rbp), %rax
movsd -0x170(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %eax
movl %eax, %esi
callq 0x11110
movq %rax, %rdi
movl -0x54(%rbp), %eax
movl %eax, %esi
callq 0x10cd0
movq %rax, %rdi
movl $0x1, %esi
callq 0x10c10
movq %rax, -0x178(%rbp)
jmp 0xfb2e
movq -0x178(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x190(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x188(%rbp)
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %eax
movl %eax, %esi
callq 0x11110
movq %rax, %rdi
movl -0x84(%rbp), %eax
movl %eax, %esi
callq 0x10cd0
movq %rax, %rdi
movl $0x1, %esi
callq 0x10c10
movq %rax, -0x180(%rbp)
jmp 0xfb85
movsd -0x188(%rbp), %xmm2
movsd -0x190(%rbp), %xmm0
movq -0x180(%rbp), %rax
movsd (%rax), %xmm1
movsd -0xa8(%rbp), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x1a0(%rbp)
movq -0x10(%rbp), %rdi
movl -0x6c(%rbp), %eax
movl %eax, %esi
callq 0x11110
movq %rax, %rdi
movl -0x54(%rbp), %eax
movl %eax, %esi
callq 0x10cd0
movq %rax, %rdi
movl $0x1, %esi
callq 0x10c10
movq %rax, -0x198(%rbp)
jmp 0xfbed
movsd -0x1a0(%rbp), %xmm1
movq -0x198(%rbp), %rax
movsd (%rax), %xmm0
movsd -0xb0(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x1b0(%rbp)
movq -0x10(%rbp), %rdi
movl -0x6c(%rbp), %eax
movl %eax, %esi
callq 0x11110
movq %rax, %rdi
movl -0x84(%rbp), %eax
movl %eax, %esi
callq 0x10cd0
movq %rax, %rdi
movl $0x1, %esi
callq 0x10c10
movq %rax, -0x1a8(%rbp)
jmp 0xfc4c
movq -0xd8(%rbp), %rdi
movsd -0x1b0(%rbp), %xmm1
movq -0x1a8(%rbp), %rax
movsd (%rax), %xmm0
movsd -0xb8(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x1c0(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x7d10
movq %rax, %rdi
movl $0x1, %esi
callq 0x6fb0
movq %rax, -0x1b8(%rbp)
jmp 0xfc9e
movq -0x1b8(%rbp), %rax
movsd -0x1c0(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0xfcd0
movq -0xd8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x76f0
jmp 0xfd72
jmp 0xfcd2
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xf6bf
movl $0x0, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
movq 0x20(%rbp), %rcx
cmpl (%rcx), %eax
jae 0xfd4c
movq -0xd8(%rbp), %rdi
movq -0x28(%rbp), %rax
movsd (%rax), %xmm0
movq -0x30(%rbp), %rax
movsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xc8(%rbp)
movl -0xbc(%rbp), %eax
movl %eax, %esi
callq 0x7d10
movq %rax, %rdi
leaq -0xc8(%rbp), %rsi
callq 0x10c80
jmp 0xfd39
jmp 0xfd3b
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0xfcea
movb $0x1, -0x31(%rbp)
testb $0x1, -0x31(%rbp)
jne 0xfd62
movq -0xd8(%rbp), %rdi
callq 0x76f0
movq -0xd0(%rbp), %rax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3530
nopl (%rax,%rax)