// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, 0x20(%rsp)
movq %r8, %rbp
movq %rcx, 0x48(%rsp)
movq %rdx, %rbx
movq %rsi, 0x38(%rsp)
movq 0xb0(%rsp), %r15
movq %rsp, %rdx
movl $0x3, (%rdx)
movq %rdi, 0x8(%rsp)
movq %r15, %rsi
callq 0x60c5
pushq $0x8
popq %r14
xorl %r12d, %r12d
movq %rbx, 0x40(%rsp)
movl (%r15), %eax
cmpq %rax, %r12
jae 0x70bd
movq 0x48(%rsp), %rdi
movq %r12, %rsi
callq 0x78b2
cmpl $0x0, (%rax)
je 0x70b1
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7746
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
divsd (%rbp), %xmm0
callq 0x2400
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7746
movq 0x8(%rax), %rax
movsd 0x8(%rax), %xmm0
movq 0x20(%rsp), %rax
divsd (%rax), %xmm0
callq 0x2400
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7746
movq %r14, 0x60(%rsp)
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd (%rbp), %xmm0
movsd %xmm0, 0x50(%rsp)
movq %rbx, %rdi
movq %r12, 0x58(%rsp)
movq %r12, %rsi
callq 0x7746
movq %rbp, %r12
cvttsd2si 0x18(%rsp), %rcx
cvttsd2si 0x10(%rsp), %rbp
movl %ecx, %edx
movq %rdx, 0x18(%rsp)
cvtsi2sd %rdx, %xmm0
mulsd 0x50(%rsp), %xmm0
movq 0x8(%rax), %rax
movsd 0x8(%rax), %xmm2
movl %ebp, %ebx
cvtsi2sd %rbx, %xmm1
movsd 0x28(%rsp), %xmm3
subsd %xmm0, %xmm3
movsd %xmm3, 0x28(%rsp)
movq 0x20(%rsp), %r13
mulsd (%r13), %xmm1
subsd %xmm1, %xmm2
movsd %xmm2, 0x10(%rsp)
incl %ecx
cvtsi2sd %rcx, %xmm0
movsd %xmm0, (%rsp)
movq 0xa0(%rsp), %rax
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x30(%rsp)
movq %rsp, %r15
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
callq 0x6060
movq %r13, %r14
cvttsd2si %xmm0, %r13
incl %ebp
cvtsi2sd %rbp, %xmm0
movsd %xmm0, (%rsp)
movq 0xa8(%rsp), %rax
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
callq 0x6060
cvttsd2si %xmm0, %rcx
movsd (%r12), %xmm1
movsd 0x28(%rsp), %xmm4
subsd %xmm4, %xmm1
movsd (%r14), %xmm0
movsd 0x10(%rsp), %xmm3
subsd %xmm3, %xmm0
movapd %xmm3, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm0, %xmm1
mulsd %xmm4, %xmm0
mulsd %xmm4, %xmm3
movapd %xmm3, %xmm5
movq 0x38(%rsp), %rax
movq (%rax), %rdx
imulq $0x18, 0x18(%rsp), %rax
movq (%rdx,%rax), %rsi
shlq $0x4, %rbx
movq 0x8(%rsi,%rbx), %rax
movl %ecx, %ecx
shlq $0x4, %rcx
movq 0x8(%rsi,%rcx), %rsi
movsd (%rsi), %xmm3
mulsd %xmm2, %xmm3
movsd (%rax), %xmm4
mulsd %xmm1, %xmm4
addsd %xmm3, %xmm4
movl %r13d, %edi
imulq $0x18, %rdi, %rdi
movq (%rdx,%rdi), %rdx
movq 0x8(%rdx,%rbx), %rdi
movsd (%rdi), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm4, %xmm3
movq 0x8(%rdx,%rcx), %rcx
movsd (%rcx), %xmm4
mulsd %xmm5, %xmm4
addsd %xmm3, %xmm4
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
movq 0x60(%rsp), %r14
movq (%rdx,%r14), %rdx
movsd %xmm4, (%rdx)
mulsd 0x8(%rsi), %xmm2
mulsd 0x8(%rax), %xmm1
addsd %xmm2, %xmm1
mulsd 0x8(%rdi), %xmm0
addsd %xmm1, %xmm0
mulsd 0x8(%rcx), %xmm5
addsd %xmm0, %xmm5
movsd %xmm5, 0x8(%rdx)
movq %r12, %rbp
movq 0xb0(%rsp), %r15
movq 0x40(%rsp), %rbx
movq 0x58(%rsp), %r12
incq %r12
addq $0x10, %r14
jmp 0x6e5a
xorl %ebx, %ebx
movq %rsp, %r12
xorl %r14d, %r14d
movl %eax, %eax
cmpq %rax, %r14
jae 0x70fe
movsd (%rbp), %xmm0
movq 0x20(%rsp), %rax
mulsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq %rbx, %rdi
movq %r12, %rsi
callq 0x778a
incq %r14
movl (%r15), %eax
addq $0x10, %rbx
jmp 0x70c5
movq 0x8(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x711c
jmp 0x711c
jmp 0x711c
jmp 0x711c
jmp 0x711c
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x4b46
movq %r14, %rdi
callq 0x2430