// File: /workspace/github_cpp_makefile_star2_O3/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, 0x18(%rsp)
movq %rcx, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq 0xb0(%rsp), %rbx
leaq 0x30(%rsp), %rdx
movl $0x3, (%rdx)
movq %rdi, (%rsp)
movq %rbx, %rsi
callq 0x858b
movl (%rbx), %ecx
testl %ecx, %ecx
je 0x96d6
movl $0x8, %ebp
xorl %ebx, %ebx
movq 0x50(%rsp), %rdx
movq (%rdx), %rax
movq 0x8(%rdx), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rbx, %rdx
jbe 0x96e9
cmpl $0x0, (%rax,%rbx,4)
je 0x966d
movq 0x48(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
cmpq %rbx, %rdx
jbe 0x96fa
movq (%rax,%rbp), %rax
movq 0x18(%rsp), %rcx
movsd (%rcx), %xmm2
movsd %xmm2, 0x10(%rsp)
movsd (%rax), %xmm1
movsd %xmm1, 0x28(%rsp)
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movapd %xmm1, %xmm0
divsd %xmm2, %xmm0
callq 0x3430
cvttsd2si %xmm0, %r15
movq 0x20(%rsp), %rax
movsd (%rax), %xmm1
movsd %xmm1, 0x58(%rsp)
movsd 0x8(%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x3430
cvttsd2si %xmm0, %r12
movl %r15d, %eax
movq %rax, 0x60(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x10(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
movl %r12d, %r13d
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
mulsd 0x58(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
incl %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0xa0(%rsp), %rax
movl (%rax), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0x30(%rsp), %r15
movq %r15, %rdi
leaq 0x38(%rsp), %r14
movq %r14, %rsi
callq 0x8526
cvttsd2si %xmm0, %rax
movq %rax, 0x10(%rsp)
incl %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0xa8(%rsp), %rax
movl (%rax), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x8526
cvttsd2si %xmm0, %rcx
movq 0x18(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x28(%rsp), %xmm4
subsd %xmm4, %xmm0
movq 0x20(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x8(%rsp), %xmm3
subsd %xmm3, %xmm1
movapd %xmm3, %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm0
mulsd %xmm4, %xmm1
mulsd %xmm4, %xmm3
movapd %xmm3, %xmm5
movq 0x40(%rsp), %rax
movq (%rax), %rdx
movq 0x60(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq (%rdx,%rax,8), %rsi
shlq $0x4, %r13
movq 0x8(%rsi,%r13), %rax
movl %ecx, %ecx
shlq $0x4, %rcx
movq 0x8(%rsi,%rcx), %rsi
movsd (%rsi), %xmm3
mulsd %xmm2, %xmm3
movsd (%rax), %xmm4
mulsd %xmm0, %xmm4
addsd %xmm3, %xmm4
movl 0x10(%rsp), %edi
leaq (%rdi,%rdi,2), %rdi
movq (%rdx,%rdi,8), %rdx
movq 0x8(%rdx,%r13), %rdi
movsd (%rdi), %xmm3
mulsd %xmm1, %xmm3
addsd %xmm4, %xmm3
movq 0x8(%rdx,%rcx), %rcx
movsd (%rcx), %xmm4
mulsd %xmm5, %xmm4
addsd %xmm3, %xmm4
movq (%rsp), %rdx
movq (%rdx), %rdx
movq (%rdx,%rbp), %rdx
movsd %xmm4, (%rdx)
mulsd 0x8(%rsi), %xmm2
mulsd 0x8(%rax), %xmm0
addsd %xmm2, %xmm0
mulsd 0x8(%rdi), %xmm1
mulsd 0x8(%rcx), %xmm5
addsd %xmm0, %xmm1
addsd %xmm1, %xmm5
movsd %xmm5, 0x8(%rdx)
movq 0xb0(%rsp), %rax
movl (%rax), %ecx
incq %rbx
movl %ecx, %eax
addq $0x10, %rbp
cmpq %rax, %rbx
jb 0x941f
testl %ecx, %ecx
je 0x96d6
movq (%rsp), %rcx
movq (%rcx), %rcx
xorl %edx, %edx
movq %rdx, %rsi
shlq $0x4, %rsi
movq (%rcx,%rsi), %rdi
testq %rdi, %rdi
jle 0x96ce
movq 0x18(%rsp), %r8
movsd (%r8), %xmm0
movq 0x20(%rsp), %r8
mulsd (%r8), %xmm0
movq 0x8(%rcx,%rsi), %rsi
leaq (%rsi,%rdi,8), %rdi
movsd (%rsi), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsi)
addq $0x8, %rsi
cmpq %rdi, %rsi
jb 0x96b9
incq %rdx
cmpq %rax, %rdx
jne 0x968c
movq (%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c75(%rip), %rdi      # 0xb365
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3380
leaq 0x1c64(%rip), %rdi      # 0xb365
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3380
jmp 0x970d
movq %rax, %rbx
movq (%rsp), %rdi
callq 0x7026
movq %rbx, %rdi
callq 0x3460