// File: /workspace/github_cpp_makefile_star2_O1/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 0x4fec(%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 0x2e1e
leaq 0x10(%rsp), %rdi
callq 0x3008
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 0x2e1e
leaq 0x10(%rsp), %rdi
callq 0x3008
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 0x2e1e
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x3008
movq 0x28(%rbx), %rax
movq 0x38(%rbx), %rcx
movq %rax, 0x8(%rbx)
movq %rcx, 0x10(%rbx)
movq 0x48(%rbx), %rax
movq %rax, 0x18(%rbx)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r14)
movq $0x0, 0x10(%r14)
cmpl $0x0, 0x54(%rbx)
jle 0x32df
xorl %r14d, %r14d
xorl %ebp, %ebp
cmpl $0x0, 0x54(%rbx)
jle 0x32d4
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
addsd 0x4ef2(%rip), %xmm0     # 0x8100
movsd %xmm0, 0x28(%rsp)
xorl %r15d, %r15d
cmpl $0x0, 0x54(%rbx)
jle 0x32c7
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
addsd 0x4ecf(%rip), %xmm0     # 0x8100
movsd %xmm0, 0x30(%rsp)
movslq %r14d, %r14
xorl %r12d, %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
addsd 0x4eb3(%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 0x4dcb(%rip), %xmm1     # 0x8058
callq 0x2987
movq 0x10(%rbx), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%r13,8)
addsd 0x10(%rsp,%r13,8), %xmm0
movsd %xmm0, 0x10(%rsp,%r13,8)
incq %r13
cmpq $0x3, %r13
jne 0x3281
incq %r14
incl %r12d
cmpl 0x54(%rbx), %r12d
jl 0x323d
incl %r15d
cmpl 0x54(%rbx), %r15d
jl 0x3217
incl %ebp
cmpl 0x54(%rbx), %ebp
jl 0x31f5
movq $0x0, 0x78(%rbx)
movslq 0x50(%rbx), %rax
testq %rax, %rax
jle 0x334a
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x10(%rbx), %rcx
xorl %edx, %edx
movsd 0x4e03(%rip), %xmm1     # 0x8108
movq (%rcx,%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 0x330b
incq %rdx
cmpq %rax, %rdx
jne 0x3305
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x335d
jmp 0x335d
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3008
movq %rbx, %rdi
callq 0x22b0