// File: /workspace/github_cpp_makefile_star2_O2/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 0x3338(%rip), %xmm1     # 0x60f8
callq 0x21f0
movsd %xmm0, 0x58(%rbx)
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 0x2a88
leaq 0x20(%rbx), %rdi
movq %r15, %rsi
callq 0x2b0c
leaq 0x10(%rsp), %rdi
callq 0x2ce8
leaq 0xc(%rsp), %rdx
movl $0x3, (%rdx)
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2a88
leaq 0x30(%rbx), %rdi
movq %r15, %rsi
callq 0x2b0c
leaq 0x10(%rsp), %rdi
callq 0x2ce8
leaq 0xc(%rsp), %rdx
movl $0x3, (%rdx)
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2a88
leaq 0x40(%rbx), %rdi
movq %r15, %rsi
callq 0x2b0c
leaq 0x10(%rsp), %rdi
callq 0x2ce8
movq 0x28(%rbx), %rax
movq 0x38(%rbx), %rcx
movq %rax, 0x8(%rbx)
movq %rcx, 0x10(%rbx)
movq 0x48(%rbx), %rax
movq %rax, 0x18(%rbx)
xorl %eax, %eax
cmpq $0x3, %rax
je 0x2e96
andq $0x0, 0x10(%rsp,%rax,8)
incq %rax
jmp 0x2e85
movl 0x54(%rbx), %eax
xorl %r14d, %r14d
xorl %r15d, %r15d
cmpl %eax, %r14d
jge 0x2f7c
cvtsi2sd %r14d, %xmm0
addsd 0x3253(%rip), %xmm0     # 0x6108
movsd %xmm0, 0x28(%rsp)
xorl %ebp, %ebp
cmpl %eax, %ebp
jge 0x2f74
cvtsi2sd %ebp, %xmm0
addsd 0x3237(%rip), %xmm0     # 0x6108
movsd %xmm0, 0x30(%rsp)
movslq %r15d, %r15
xorl %r12d, %r12d
cmpl %eax, %r12d
jge 0x2f6d
cvtsi2sd %r12d, %xmm0
addsd 0x3215(%rip), %xmm0     # 0x6108
mulsd 0x58(%rbx), %xmm0
movq 0x8(%rbx), %rax
movq (%rax,%r15,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
cmpq $0x3, %r13
je 0x2f5f
xorpd %xmm0, %xmm0
movsd 0x311f(%rip), %xmm1     # 0x6058
callq 0x27f2
movq 0x10(%rbx), %rax
movq (%rax,%r15,8), %rax
movsd %xmm0, (%rax,%r13,8)
addsd 0x10(%rsp,%r13,8), %xmm0
movsd %xmm0, 0x10(%rsp,%r13,8)
incq %r13
jmp 0x2f27
incq %r15
incl %r12d
movl 0x54(%rbx), %eax
jmp 0x2edd
incl %ebp
jmp 0x2ebd
incl %r14d
jmp 0x2e9f
andq $0x0, 0x78(%rbx)
movl 0x50(%rbx), %eax
cvtsi2sd %eax, %xmm0
movq 0x10(%rbx), %rcx
xorl %edx, %edx
testl %eax, %eax
cmovlel %edx, %eax
movsd 0x3165(%rip), %xmm1     # 0x6100
cmpq %rax, %rdx
je 0x2fe4
movq (%rcx,%rdx,8), %rsi
xorl %edi, %edi
cmpq $0x3, %rdi
je 0x2fdf
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
jmp 0x2fa6
incq %rdx
jmp 0x2f9b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2ff7
jmp 0x2ff7
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2ce8
movq %rbx, %rdi
callq 0x2200