// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movq %r8, 0x18(%rsp)
movq %rcx, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq 0xb0(%rsp), %rbx
leaq 0x28(%rsp), %rdx
movl $0x3, (%rdx)
movq %rdi, (%rsp)
movq %rbx, %rsi
callq 0x854e
movl (%rbx), %ecx
testl %ecx, %ecx
je 0x9643
movl $0x8, %ebp
xorl %ebx, %ebx
movq %r12, 0x38(%rsp)
movq 0x50(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rbx, %rdx
jbe 0x96ab
cmpl $0x0, (%rax,%rbx,4)
je 0x962a
movq 0x48(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
cmpq %rbx, %rdx
jbe 0x96bc
movq (%rax,%rbp), %rax
movq 0x18(%rsp), %rcx
movsd (%rcx), %xmm2
movsd %xmm2, 0x10(%rsp)
movsd (%rax), %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movapd %xmm1, %xmm0
divsd %xmm2, %xmm0
callq 0x3430
cvttsd2si %xmm0, %r15
movsd (%r12), %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 0x20(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x20(%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, 0x28(%rsp)
movq 0xa0(%rsp), %rax
movl (%rax), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x28(%rsp), %r15
movq %r15, %rdi
leaq 0x30(%rsp), %r14
movq %r14, %rsi
callq 0x84e9
cvttsd2si %xmm0, %rax
movq %rax, 0x10(%rsp)
incl %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
movq 0x38(%rsp), %r12
movsd %xmm0, 0x28(%rsp)
movq 0xa8(%rsp), %rax
movl (%rax), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x84e9
cvttsd2si %xmm0, %rcx
movq 0x18(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x20(%rsp), %xmm4
subsd %xmm4, %xmm1
movsd (%r12), %xmm0
movsd 0x8(%rsp), %xmm3
subsd %xmm3, %xmm0
movapd %xmm3, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm0, %xmm1
mulsd %xmm4, %xmm0
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 %xmm1, %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 %xmm0, %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), %xmm1
addsd %xmm2, %xmm1
mulsd 0x8(%rdi), %xmm0
addsd %xmm1, %xmm0
mulsd 0x8(%rcx), %xmm5
addsd %xmm0, %xmm5
movsd %xmm5, 0x8(%rdx)
movq 0xb0(%rsp), %rax
movl (%rax), %ecx
incq %rbx
addq $0x10, %rbp
cmpl %ecx, %ebx
jb 0x93e7
testl %ecx, %ecx
je 0x9698
movq (%rsp), %rax
movq (%rax), %rax
movl %ecx, %ecx
xorl %edx, %edx
movq 0x18(%rsp), %r8
movq %rdx, %rsi
shlq $0x4, %rsi
movq (%rax,%rsi), %rdi
testq %rdi, %rdi
jle 0x9690
movsd (%r8), %xmm0
mulsd (%r12), %xmm0
movq 0x8(%rax,%rsi), %rsi
leaq (%rsi,%rdi,8), %rdi
movsd (%rsi), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsi)
addq $0x8, %rsi
cmpq %rdi, %rsi
jb 0x967b
incq %rdx
cmpq %rcx, %rdx
jne 0x9657
movq (%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ca3(%rip), %rdi      # 0xb355
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3380
leaq 0x1c92(%rip), %rdi      # 0xb355
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3380
jmp 0x96cf
movq %rax, %rbx
movq (%rsp), %rdi
callq 0x6ff6
movq %rbx, %rdi
callq 0x3460