// File: /workspace/github_cpp_makefile_star2_O3/joraso[P]Glassius/Particles.cpp
// Function: Particles::Initialize()
void Particles::Initialize(){
    /* places the particle positions on a square lattice, each at the center of
    a unit cell. Does not initialize energies or forces (they are set to zero
    implicilty, but does randomize velocities and subtract off the cmv. */
    int xi, yi, zi, k, n; n=0;
    
    // Setting other parameters from Nside (number of particles along a side
    // of the box) and rho (number density).
    N = Nside*Nside*Nside;
    lengthscale = pow(rho, -1.0/3.0);
    sidelength = lengthscale*Nside;
    
    //std::cout << "Sidelength is " << sidelength << std::endl;
    //std::cout << "lengthscale is " << lengthscale << std::endl;
    //std::cout << "N is " << N << std::endl;
    //std::cout << "Nside is " << Nside << std::endl;
    
    // Setting up the trajectory matrices. Note the dimensionality is hard-
    // coded to 3.
    positions = Matrix(N,3);
    velocities = Matrix(N,3);
    forces = Matrix(N,3);
    r = positions.Data();
    v = velocities.Data();
    f = forces.Data();
    
    // Tracking the center-of-mass velocity
    double cmv[3];
    for(k=0;k<3;k++){cmv[k] = 0;}
    
    // initializing positions, velocities.
    for(zi=0;zi<Nside;zi++){
       //std::cout << "zi=" << zi << std::endl;
       //std::cout << "zcoord=" << lengthscale*(zi+0.5) << std::endl;
       for(yi=0;yi<Nside;yi++){
         for(xi=0;xi<Nside;xi++){
            r[n][0] = lengthscale*(xi+0.5);
            r[n][1] = lengthscale*(yi+0.5);
            r[n][2] = lengthscale*(zi+0.5);
            for(k=0;k<3;k++){
                v[n][k] = chaos::gaussian(0.0, 1.0);
                cmv[k] += v[n][k];
            }
            n++;
         }
       }
    }
    
    // Subtracting off the center-of-mass velocity, and calculating KE.
    kinetic_energy = 0;
    for(n=0;n<N;n++){
        for(k=0;k<3;k++){
            v[n][k] -= (cmv[k]/N);
            kinetic_energy += (24.0)*v[n][k]*v[n][k];
        }
    }
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movl 0x54(%rdi), %eax
movl %eax, %ecx
imull %eax, %ecx
imull %eax, %ecx
leaq 0x50(%rdi), %r14
movl %ecx, 0x50(%rdi)
movsd 0x68(%rdi), %xmm0
movsd 0x4fe0(%rip), %xmm1     # 0x80f8
callq 0x22a0
movsd %xmm0, 0x58(%rbx)
xorps %xmm1, %xmm1
cvtsi2sdl 0x54(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rbx)
leaq 0xc(%rsp), %rdx
movl $0x3, (%rdx)
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2d90
leaq 0x20(%rbx), %rdi
movq %r15, %rsi
callq 0x2e1c
leaq 0x10(%rsp), %rdi
callq 0x300a
leaq 0xc(%rsp), %rdx
movl $0x3, (%rdx)
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2d90
leaq 0x30(%rbx), %rdi
movq %r15, %rsi
callq 0x2e1c
leaq 0x10(%rsp), %rdi
callq 0x300a
leaq 0xc(%rsp), %rdx
movl $0x3, (%rdx)
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2d90
leaq 0x40(%rbx), %rdi
movq %r15, %rsi
callq 0x2e1c
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x300a
movq 0x28(%rbx), %rcx
movq 0x38(%rbx), %rax
movq %rcx, 0x8(%rbx)
movq %rax, 0x10(%rbx)
movq 0x48(%rbx), %rcx
movq %rcx, 0x18(%rbx)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r14)
movq $0x0, 0x10(%r14)
movl 0x54(%rbx), %ecx
testl %ecx, %ecx
jle 0x32e8
xorl %r14d, %r14d
xorl %ebp, %ebp
testl %ecx, %ecx
jle 0x32de
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
addsd 0x4ee7(%rip), %xmm0     # 0x8100
movsd %xmm0, 0x28(%rsp)
xorl %r15d, %r15d
testl %ecx, %ecx
jle 0x32d2
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
addsd 0x4ec6(%rip), %xmm0     # 0x8100
movsd %xmm0, 0x30(%rsp)
movslq %r14d, %r14
xorl %r12d, %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
addsd 0x4eaa(%rip), %xmm0     # 0x8100
mulsd 0x58(%rbx), %xmm0
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax)
movsd 0x58(%rbx), %xmm0
mulsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x8(%rax)
movsd 0x58(%rbx), %xmm0
mulsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x10(%rax)
xorl %r13d, %r13d
xorpd %xmm0, %xmm0
movsd 0x4dc2(%rip), %xmm1     # 0x8058
callq 0x2987
movq 0x10(%rbx), %rax
movq (%rax,%r14,8), %rcx
movsd %xmm0, (%rcx,%r13,8)
addsd 0x10(%rsp,%r13,8), %xmm0
movsd %xmm0, 0x10(%rsp,%r13,8)
incq %r13
cmpq $0x3, %r13
jne 0x328a
incq %r14
incl %r12d
movl 0x54(%rbx), %ecx
cmpl %ecx, %r12d
jl 0x3246
incl %r15d
cmpl %ecx, %r15d
jl 0x3222
incl %ebp
cmpl %ecx, %ebp
jl 0x3202
movq $0x0, 0x78(%rbx)
movslq 0x50(%rbx), %rcx
testq %rcx, %rcx
jle 0x334f
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
xorl %edx, %edx
movsd 0x4dfe(%rip), %xmm1     # 0x8108
movq (%rax,%rdx,8), %rsi
xorl %edi, %edi
movsd 0x10(%rsp,%rdi,8), %xmm2
divsd %xmm0, %xmm2
movsd (%rsi,%rdi,8), %xmm3
subsd %xmm2, %xmm3
movsd %xmm3, (%rsi,%rdi,8)
movapd %xmm3, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm3, %xmm2
addsd 0x78(%rbx), %xmm2
movsd %xmm2, 0x78(%rbx)
incq %rdi
cmpq $0x3, %rdi
jne 0x3310
incq %rdx
cmpq %rcx, %rdx
jne 0x330a
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3362
jmp 0x3362
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x300a
movq %rbx, %rdi
callq 0x22b0
nop