//includes creating atoms with mass and temperature using probability function
//based on velocity intervals ranging 3 standard deviations with random angles
//converts spherical coordinates to cartesian coordinates for intial velocities

//Paige Diamond, Zeke Elkins, Shannon White, Kayla Huff, Tim Webber
// 10-30-2014

#include <cmath>
#include <math.h>
#include <iostream>
#include <stdlib.h>
#include <cstdlib> // needed for rand
#include <ctime>//neded for srand(time(0))
#include <fstream> //needed for files
#include <vector>
#include <cfloat>
#include <string>

#define N 1000000

using namespace std;

int main() {

  double mass = 6.63352088E-27; //mass in kg for one atom (ARGON)
  float k = 1.3806488E-23; //m^2 kg s^-2 K^-1
  double temp = 298; //kelvin
  double pi = 3.14159;
  double avgVelocity = 0;
  double velocity[N],velX[N],velY[N],velZ[N],x[N],y[N],z[N],theta[N],phi[N];
  int atomIndexL = 0;
  double velIndex = 0;
  double width = 0;
  double mostProbVel = 0;
  int atomIndex=0;

 
  //Set range for possible values (0-2*average or +-3 standard deviations)

  avgVelocity = (sqrt(2*k*temp/mass))*(2/(sqrt(pi)));

  cout<<"Average velocity" << avgVelocity<< endl;


  mostProbVel = sqrt (2*k*temp/mass);
  velIndex = mostProbVel;
  //most probable velocity is different than average velocity because the distribution is skewed. 
  //We want to start at the "top of the hill" so we always overestimate the boxes and don't 	  
  //run into rounding errors             


  /*for(atomIndex = 0; atomIndex <N; atomIndex++){

  if(atomIndex == 0){
                  
     width = pow(3, 1/3)/(pow((mass/(2*pi*k*temp)),1/2)*pow(N, 1/3)*pow(4*pi, 1/3));

  }*/


  //creates atoms left of the hill until the velocity is equal to zero

  for (atomIndexL=0; atomIndexL < N; atomIndexL++ ){
                
    if (velIndex >= 0.0000){
  
             width = 1/((sqrt((mass/(2*pi*k*temp))*(mass/(2*pi*k*temp))*(mass/(2*pi*k*temp))))*(4*pi*(velIndex*velIndex))*(exp(-(mass*(velIndex*velIndex))/(2*k*temp)))*N);




                x[atomIndex]= static_cast <double> (rand()) / static_cast <double> (RAND_MAX/500);
                y[atomIndex] = static_cast <double> (rand()) / static_cast <double> (RAND_MAX/500);
                z[atomIndex] = static_cast <double> (rand()) / static_cast <double> (RAND_MAX/500);
                theta[atomIndex] = static_cast<double>(rand()) / static_cast<double>(RAND_MAX/(M_PI));
                phi[atomIndex] = static_cast<double>(rand()) / static_cast<double>(RAND_MAX/(2*M_PI));


                //Randomize Velocity within intvel, convert to cartesian coordinates

                velocity[atomIndex]=velIndex - static_cast <double> (rand()) / static_cast <double> (RAND_MAX/width);
                velX[atomIndex]=velocity[atomIndex]*sin(theta[atomIndex])*cos(phi[atomIndex]);
                velY[atomIndex]=velocity[atomIndex]*sin(theta[atomIndex])*sin(phi[atomIndex]);
                velZ[atomIndex]=velocity[atomIndex]*cos(theta[atomIndex]);

                velIndex=velIndex-width; 

                //Update index
                cout << "width" << width << endl;
                cout <<"Atom Index " << atomIndexL << endl;
                cout << "Atom Velocity " << velocity[atomIndex] << endl;
                cout<< velX[atomIndex] << " " << velY[atomIndex] << " " << velZ[atomIndex] << endl;

		atomIndex++;

    	}
    }

  velIndex = mostProbVel;

  //creates remaining atoms to the right of the most probable velocity

  for (; atomIndex<N; atomIndex++){
                  
             width = 1/((sqrt((mass/(2*pi*k*temp))*(mass/(2*pi*k*temp))*(mass/(2*pi*k*temp))))*(4*pi*(velIndex*velIndex))*(exp(-(mass*(velIndex*velIndex))/(2*k*temp)))*N);




             	x[atomIndex]= static_cast <double> (rand()) / static_cast <double> (RAND_MAX/500);
                y[atomIndex] = static_cast <double> (rand()) / static_cast <double> (RAND_MAX/500);
                z[atomIndex] = static_cast <double> (rand()) / static_cast <double> (RAND_MAX/500);
                theta[atomIndex] = static_cast<double>(rand()) / static_cast<double>(RAND_MAX/(M_PI));
                phi[atomIndex] = static_cast<double>(rand()) / static_cast<double>(RAND_MAX/(2*M_PI));


                //Randomize Velocity within intvel, convert to cartesian coordinates

                velocity[atomIndex]=velIndex +  static_cast <double> (rand()) / static_cast <double> (RAND_MAX/width);
                velX[atomIndex]=velocity[atomIndex]*sin(theta[atomIndex])*cos(phi[atomIndex]);
                velY[atomIndex]=velocity[atomIndex]*sin(theta[atomIndex])*sin(phi[atomIndex]);
                velZ[atomIndex]=velocity[atomIndex]*cos(theta[atomIndex]);

                velIndex=velIndex+width; 

                //Update index
                cout << "width" << width << endl;
                cout <<"Atom Index " << atomIndex << endl;
                cout << "Atom Velocity " << velocity[atomIndex] << endl;
                cout<< velX[atomIndex] << " " << velY[atomIndex] << " " << velZ[atomIndex] << endl;

         

    }

  //for (; atomIndex <N; atomIndex++){

  //x[atomIndex]= static_cast <float> (rand()) / static_cast <float> (RAND_MAX/500);
  //  y[atomIndex] = static_cast <float> (rand()) / static_cast <float> (RAND_MAX/500);
  // z[atomIndex] = static_cast <float> (rand()) / static_cast <float> (RAND_MAX/500);
  // theta[atomIndex] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX/(M_PI));
  // phi[atomIndex] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX/(2*M_PI));


  //Randomize Velocity within intvel, convert to cartesian coordinates

  //  velocity[atomIndex]=velIndex;
  // velX[atomIndex]=velocity[atomIndex]*sin(theta[atomIndex])*cos(phi[atomIndex]);
  // velY[atomIndex]=velocity[atomIndex]*sin(theta[atomIndex])*sin(phi[atomIndex]);
  // velZ[atomIndex]=velocity[atomIndex]*cos(theta[atomIndex]);

  // velIndex=velIndex+width; 

  //Update index
  // cout << "width" << width << endl;
  //cout <<"Atom Index " << atomIndex << endl;
  // cout << "Atom Velocity " << velocity[atomIndex] << endl;
  // cout<< velX[atomIndex] << " " << velY[atomIndex] << " " << velZ[atomIndex] << endl;


  /* velocity[N-1]=velIndex;
  x[N-1]= static_cast <float> (rand()) / static_cast <float> (RAND_MAX/500);
  y[N-1] = static_cast <float> (rand()) / static_cast <float> (RAND_MAX/500);
  z[N-1] = static_cast <float> (rand()) / static_cast <float> (RAND_MAX/500);
  theta[N-1] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX/(M_PI));
  phi[N-1] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX/(2*M_PI));
  velX[N-1]=velocity[N-1]*sin(theta[N-1])*cos(phi[N-1]);
  velY[N-1]=velocity[N-1]*sin(theta[N-1])*sin(phi[N-1]);
  velZ[N-1]=velocity[N-1]*cos(theta[N-1]);
  cout <<"Atom Index " << atomIndex << endl;
  cout << "Atom Velocity " << velocity[atomIndex] << endl;
  cout<< velX[atomIndex] << " " << velY[atomIndex] << " " << velZ[atomIndex] << endl;
  */

  double avgCheck = 0;

  //check out average

  for(int j=0; j<atomIndex; j++){

       avgCheck = avgCheck + velocity [j];

  }

  avgCheck = avgCheck / atomIndex;

  cout << "Average: " <<  avgCheck << endl; 

  return 0;

}

	.file	"tmpxft_00210a73_00000000-6_atomVel.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4132:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4132:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB4802:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE4802:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"Average velocity"
.LC14:
	.string	"width"
.LC15:
	.string	"Atom Index "
.LC16:
	.string	"Atom Velocity "
.LC17:
	.string	" "
.LC18:
	.string	"Average: "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB4129:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-7999488(%rsp), %r11
	.cfi_def_cfa 11, 7999544
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$600, %rsp
	.cfi_def_cfa_offset 8000144
	leaq	_ZSt4cout(%rip), %rbx
	xorl	%ebp, %ebp
	xorl	%r12d, %r12d
	leaq	.LC2(%rip), %rsi
	movq	%rbx, %rdi
	movq	%fs:40, %rax
	movq	%rax, 8000072(%rsp)
	xorl	%eax, %eax
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	.LC3(%rip), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movsd	.LC0(%rip), %xmm3
	movaps	%xmm3, %xmm2
.L6:
	xorps	%xmm0, %xmm0
	comisd	%xmm0, %xmm3
	jb	.L4
	movaps	%xmm3, %xmm1
	movsd	%xmm3, 32(%rsp)
	leaq	56(%rsp), %r14
	leaq	48(%rsp), %r15
	mulsd	%xmm3, %xmm1
	movaps	%xmm1, %xmm0
	movsd	%xmm1, 8(%rsp)
	mulsd	.LC4(%rip), %xmm0
	xorps	.LC5(%rip), %xmm0
	divsd	.LC6(%rip), %xmm0
	call	exp@PLT
	movsd	8(%rsp), %xmm1
	mulsd	.LC7(%rip), %xmm1
	mulsd	.LC8(%rip), %xmm1
	mulsd	%xmm0, %xmm1
	movsd	.LC10(%rip), %xmm0
	mulsd	.LC9(%rip), %xmm1
	divsd	%xmm1, %xmm0
	movsd	%xmm0, 8(%rsp)
	call	rand@PLT
	call	rand@PLT
	call	rand@PLT
	call	rand@PLT
	movq	%r15, %rsi
	movq	%r14, %rdi
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC11(%rip), %xmm0
	call	sincos@PLT
	movsd	56(%rsp), %xmm4
	movq	48(%rsp), %r13
	movsd	%xmm4, 24(%rsp)
	call	rand@PLT
	movq	%r15, %rsi
	movq	%r14, %rdi
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC12(%rip), %xmm0
	call	sincos@PLT
	movsd	56(%rsp), %xmm5
	movq	48(%rsp), %r14
	movsd	%xmm5, 16(%rsp)
	call	rand@PLT
	movsd	.LC13(%rip), %xmm1
	divsd	8(%rsp), %xmm1
	movsd	32(%rsp), %xmm3
	cvtsi2sdl	%eax, %xmm0
	movq	%r14, %xmm5
	movslq	%ebp, %rax
	movq	%rbx, %rdi
	movsd	24(%rsp), %xmm4
	movq	%r13, %xmm6
	leaq	.LC14(%rip), %rsi
	incl	%ebp
	divsd	%xmm1, %xmm0
	movaps	%xmm3, %xmm1
	subsd	8(%rsp), %xmm3
	subsd	%xmm0, %xmm1
	mulsd	%xmm1, %xmm4
	movsd	%xmm1, 72(%rsp,%rax,8)
	mulsd	%xmm1, %xmm6
	movsd	%xmm1, 24(%rsp)
	mulsd	%xmm4, %xmm5
	movaps	%xmm4, %xmm0
	mulsd	16(%rsp), %xmm0
	movq	%xmm6, %r13
	movsd	%xmm3, 16(%rsp)
	movq	%xmm5, %r14
	movq	%xmm0, %r15
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	8(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC15(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r12d, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC16(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	24(%rsp), %xmm1
	movq	%rax, %rdi
	movaps	%xmm1, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	%r14, %xmm0
	movq	%rbx, %rdi
	leaq	.LC17(%rip), %r14
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r14, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%r15, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r14, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%r13, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movsd	.LC0(%rip), %xmm2
	movsd	16(%rsp), %xmm3
.L4:
	incl	%r12d
	cmpl	$1000000, %r12d
	jne	.L6
	movslq	%ebp, %r13
.L7:
	cmpl	$999999, %r13d
	movl	%r13d, %r12d
	leaq	72(%rsp), %r14
	jg	.L16
	movaps	%xmm2, %xmm1
	movsd	%xmm2, 40(%rsp)
	leaq	56(%rsp), %r15
	mulsd	%xmm2, %xmm1
	movaps	%xmm1, %xmm0
	movsd	%xmm1, 8(%rsp)
	mulsd	.LC4(%rip), %xmm0
	xorps	.LC5(%rip), %xmm0
	divsd	.LC6(%rip), %xmm0
	call	exp@PLT
	movsd	8(%rsp), %xmm1
	mulsd	.LC7(%rip), %xmm1
	mulsd	.LC8(%rip), %xmm1
	mulsd	%xmm0, %xmm1
	movsd	.LC10(%rip), %xmm0
	mulsd	.LC9(%rip), %xmm1
	divsd	%xmm1, %xmm0
	movsd	%xmm0, 8(%rsp)
	call	rand@PLT
	call	rand@PLT
	call	rand@PLT
	call	rand@PLT
	leaq	48(%rsp), %rsi
	movq	%r15, %rdi
	cvtsi2sdl	%eax, %xmm0
	movq	%rsi, 16(%rsp)
	divsd	.LC11(%rip), %xmm0
	call	sincos@PLT
	movsd	48(%rsp), %xmm4
	movsd	56(%rsp), %xmm3
	movsd	%xmm4, 32(%rsp)
	movsd	%xmm3, 24(%rsp)
	call	rand@PLT
	movq	16(%rsp), %rsi
	movq	%r15, %rdi
	cvtsi2sdl	%eax, %xmm0
	divsd	.LC12(%rip), %xmm0
	call	sincos@PLT
	movsd	56(%rsp), %xmm6
	movq	48(%rsp), %r15
	movsd	%xmm6, 16(%rsp)
	call	rand@PLT
	movsd	.LC13(%rip), %xmm0
	movq	%r15, %xmm7
	divsd	8(%rsp), %xmm0
	cvtsi2sdl	%eax, %xmm1
	movsd	40(%rsp), %xmm2
	movq	%rbx, %rdi
	movsd	24(%rsp), %xmm3
	movsd	32(%rsp), %xmm4
	leaq	.LC14(%rip), %rsi
	divsd	%xmm0, %xmm1
	addsd	%xmm2, %xmm1
	addsd	8(%rsp), %xmm2
	mulsd	%xmm1, %xmm3
	movsd	%xmm2, 24(%rsp)
	mulsd	%xmm1, %xmm4
	movsd	%xmm1, (%r14,%r13,8)
	incq	%r13
	movsd	%xmm1, 32(%rsp)
	mulsd	%xmm3, %xmm7
	movaps	%xmm3, %xmm0
	mulsd	16(%rsp), %xmm0
	movsd	%xmm4, 16(%rsp)
	movq	%xmm7, %r15
	movq	%xmm0, %r14
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	8(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC15(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r12d, %esi
	leaq	.LC17(%rip), %r12
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC16(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	32(%rsp), %xmm1
	movq	%rax, %rdi
	movaps	%xmm1, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	%r15, %xmm0
	movq	%rbx, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r12, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%r14, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r12, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	16(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movsd	24(%rsp), %xmm2
	jmp	.L7
.L16:
	movl	$1000000, %eax
	xorl	%edx, %edx
	xorps	%xmm0, %xmm0
	subl	%ebp, %eax
	cmpl	$1000000, %ebp
	cmovg	%edx, %eax
	xorl	%edx, %edx
	addl	%ebp, %eax
.L9:
	addsd	(%r14,%rdx,8), %xmm0
	incq	%rdx
	cmpl	%edx, %eax
	jg	.L9
	leaq	.LC18(%rip), %rsi
	movq	%rbx, %rdi
	divsd	.LC9(%rip), %xmm0
	movsd	%xmm0, 8(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	8(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	8000072(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$8000088, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4129:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4155:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4155:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	137259829
	.long	1083270925
	.align 8
.LC3:
	.long	519614879
	.long	1083417341
	.align 8
.LC4:
	.long	1292013295
	.long	981494910
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC5:
	.long	0
	.long	-2147483648
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC6:
	.long	1983905792
	.long	1002663404
	.align 8
.LC7:
	.long	-266631570
	.long	1076437497
	.align 8
.LC8:
	.long	-732719678
	.long	1038212476
	.align 8
.LC9:
	.long	0
	.long	1093567616
	.align 8
.LC10:
	.long	0
	.long	1072693248
	.align 8
.LC11:
	.long	1839270434
	.long	1103388464
	.align 8
.LC12:
	.long	1839270434
	.long	1102339888
	.align 8
.LC13:
	.long	-4194304
	.long	1105199103
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

//includes creating atoms with mass and temperature using probability function
//based on velocity intervals ranging 3 standard deviations with random angles
//converts spherical coordinates to cartesian coordinates for intial velocities

//Paige Diamond, Zeke Elkins, Shannon White, Kayla Huff, Tim Webber
// 10-30-2014


#include <hip/hip_runtime.h>
#include <cmath>
#include <math.h>
#include <iostream>
#include <stdlib.h>
#include <cstdlib> // needed for rand
#include <ctime>//neded for srand(time(0))
#include <fstream> //needed for files
#include <vector>
#include <cfloat>
#include <string>

#define N 1000000

using namespace std;

int main() {

  double mass = 6.63352088E-27; //mass in kg for one atom (ARGON)
  float k = 1.3806488E-23; //m^2 kg s^-2 K^-1
  double temp = 298; //kelvin
  double pi = 3.14159;
  double avgVelocity = 0;
  double velocity[N],velX[N],velY[N],velZ[N],x[N],y[N],z[N],theta[N],phi[N];
  int atomIndexL = 0;
  double velIndex = 0;
  double width = 0;
  double mostProbVel = 0;
  int atomIndex=0;

 
  //Set range for possible values (0-2*average or +-3 standard deviations)

  avgVelocity = (sqrt(2*k*temp/mass))*(2/(sqrt(pi)));

  cout<<"Average velocity" << avgVelocity<< endl;


  mostProbVel = sqrt (2*k*temp/mass);
  velIndex = mostProbVel;
  //most probable velocity is different than average velocity because the distribution is skewed. 
  //We want to start at the "top of the hill" so we always overestimate the boxes and don't 	  
  //run into rounding errors             


  /*for(atomIndex = 0; atomIndex <N; atomIndex++){

  if(atomIndex == 0){
                  
     width = pow(3, 1/3)/(pow((mass/(2*pi*k*temp)),1/2)*pow(N, 1/3)*pow(4*pi, 1/3));

  }*/


  //creates atoms left of the hill until the velocity is equal to zero

  for (atomIndexL=0; atomIndexL < N; atomIndexL++ ){
                
    if (velIndex >= 0.0000){
  
             width = 1/((sqrt((mass/(2*pi*k*temp))*(mass/(2*pi*k*temp))*(mass/(2*pi*k*temp))))*(4*pi*(velIndex*velIndex))*(exp(-(mass*(velIndex*velIndex))/(2*k*temp)))*N);




                x[atomIndex]= static_cast <double> (rand()) / static_cast <double> (RAND_MAX/500);
                y[atomIndex] = static_cast <double> (rand()) / static_cast <double> (RAND_MAX/500);
                z[atomIndex] = static_cast <double> (rand()) / static_cast <double> (RAND_MAX/500);
                theta[atomIndex] = static_cast<double>(rand()) / static_cast<double>(RAND_MAX/(M_PI));
                phi[atomIndex] = static_cast<double>(rand()) / static_cast<double>(RAND_MAX/(2*M_PI));


                //Randomize Velocity within intvel, convert to cartesian coordinates

                velocity[atomIndex]=velIndex - static_cast <double> (rand()) / static_cast <double> (RAND_MAX/width);
                velX[atomIndex]=velocity[atomIndex]*sin(theta[atomIndex])*cos(phi[atomIndex]);
                velY[atomIndex]=velocity[atomIndex]*sin(theta[atomIndex])*sin(phi[atomIndex]);
                velZ[atomIndex]=velocity[atomIndex]*cos(theta[atomIndex]);

                velIndex=velIndex-width; 

                //Update index
                cout << "width" << width << endl;
                cout <<"Atom Index " << atomIndexL << endl;
                cout << "Atom Velocity " << velocity[atomIndex] << endl;
                cout<< velX[atomIndex] << " " << velY[atomIndex] << " " << velZ[atomIndex] << endl;

		atomIndex++;

    	}
    }

  velIndex = mostProbVel;

  //creates remaining atoms to the right of the most probable velocity

  for (; atomIndex<N; atomIndex++){
                  
             width = 1/((sqrt((mass/(2*pi*k*temp))*(mass/(2*pi*k*temp))*(mass/(2*pi*k*temp))))*(4*pi*(velIndex*velIndex))*(exp(-(mass*(velIndex*velIndex))/(2*k*temp)))*N);




             	x[atomIndex]= static_cast <double> (rand()) / static_cast <double> (RAND_MAX/500);
                y[atomIndex] = static_cast <double> (rand()) / static_cast <double> (RAND_MAX/500);
                z[atomIndex] = static_cast <double> (rand()) / static_cast <double> (RAND_MAX/500);
                theta[atomIndex] = static_cast<double>(rand()) / static_cast<double>(RAND_MAX/(M_PI));
                phi[atomIndex] = static_cast<double>(rand()) / static_cast<double>(RAND_MAX/(2*M_PI));


                //Randomize Velocity within intvel, convert to cartesian coordinates

                velocity[atomIndex]=velIndex +  static_cast <double> (rand()) / static_cast <double> (RAND_MAX/width);
                velX[atomIndex]=velocity[atomIndex]*sin(theta[atomIndex])*cos(phi[atomIndex]);
                velY[atomIndex]=velocity[atomIndex]*sin(theta[atomIndex])*sin(phi[atomIndex]);
                velZ[atomIndex]=velocity[atomIndex]*cos(theta[atomIndex]);

                velIndex=velIndex+width; 

                //Update index
                cout << "width" << width << endl;
                cout <<"Atom Index " << atomIndex << endl;
                cout << "Atom Velocity " << velocity[atomIndex] << endl;
                cout<< velX[atomIndex] << " " << velY[atomIndex] << " " << velZ[atomIndex] << endl;

         

    }

  //for (; atomIndex <N; atomIndex++){

  //x[atomIndex]= static_cast <float> (rand()) / static_cast <float> (RAND_MAX/500);
  //  y[atomIndex] = static_cast <float> (rand()) / static_cast <float> (RAND_MAX/500);
  // z[atomIndex] = static_cast <float> (rand()) / static_cast <float> (RAND_MAX/500);
  // theta[atomIndex] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX/(M_PI));
  // phi[atomIndex] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX/(2*M_PI));


  //Randomize Velocity within intvel, convert to cartesian coordinates

  //  velocity[atomIndex]=velIndex;
  // velX[atomIndex]=velocity[atomIndex]*sin(theta[atomIndex])*cos(phi[atomIndex]);
  // velY[atomIndex]=velocity[atomIndex]*sin(theta[atomIndex])*sin(phi[atomIndex]);
  // velZ[atomIndex]=velocity[atomIndex]*cos(theta[atomIndex]);

  // velIndex=velIndex+width; 

  //Update index
  // cout << "width" << width << endl;
  //cout <<"Atom Index " << atomIndex << endl;
  // cout << "Atom Velocity " << velocity[atomIndex] << endl;
  // cout<< velX[atomIndex] << " " << velY[atomIndex] << " " << velZ[atomIndex] << endl;


  /* velocity[N-1]=velIndex;
  x[N-1]= static_cast <float> (rand()) / static_cast <float> (RAND_MAX/500);
  y[N-1] = static_cast <float> (rand()) / static_cast <float> (RAND_MAX/500);
  z[N-1] = static_cast <float> (rand()) / static_cast <float> (RAND_MAX/500);
  theta[N-1] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX/(M_PI));
  phi[N-1] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX/(2*M_PI));
  velX[N-1]=velocity[N-1]*sin(theta[N-1])*cos(phi[N-1]);
  velY[N-1]=velocity[N-1]*sin(theta[N-1])*sin(phi[N-1]);
  velZ[N-1]=velocity[N-1]*cos(theta[N-1]);
  cout <<"Atom Index " << atomIndex << endl;
  cout << "Atom Velocity " << velocity[atomIndex] << endl;
  cout<< velX[atomIndex] << " " << velY[atomIndex] << " " << velZ[atomIndex] << endl;
  */

  double avgCheck = 0;

  //check out average

  for(int j=0; j<atomIndex; j++){

       avgCheck = avgCheck + velocity [j];

  }

  avgCheck = avgCheck / atomIndex;

  cout << "Average: " <<  avgCheck << endl; 

  return 0;

}

	.text
	.file	"atomVel.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI0_0:
	.quad	0x4093a2fd1ef8b19f              # double 1256.7471884592449
.LCPI0_1:
	.quad	0x4091670d082e6b35              # double 1113.7627265217718
.LCPI0_2:
	.quad	0x402921f9f01b866e              # double 12.56636
.LCPI0_3:
	.quad	0x3de1dd7cd45395c2              # double 1.2998633607268559E-10
.LCPI0_4:
	.quad	0xba806c7e4d028eef              # double -6.6335208800000003E-27
.LCPI0_5:
	.quad	0x3bc36dec76400000              # double 8.2286664717564733E-21
.LCPI0_6:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI0_7:
	.quad	0x3ff0000000000000              # double 1
.LCPI0_8:
	.quad	0x41c45f306da10a22              # double 683565275.25812173
.LCPI0_9:
	.quad	0x41b45f306da10a22              # double 341782637.62906086
.LCPI0_10:
	.quad	0xc1dfffffffc00000              # double -2147483647
.LCPI0_11:
	.quad	0x41dfffffffc00000              # double 2147483647
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$8000064, %rsp                  # imm = 0x7A1240
	.cfi_def_cfa_offset 8000112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$16, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movsd	.LCPI0_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movsd	.LCPI0_1(%rip), %xmm8           # xmm8 = mem[0],zero
	xorl	%ebx, %ebx
	xorpd	%xmm9, %xmm9
	movsd	.LCPI0_2(%rip), %xmm1           # xmm1 = mem[0],zero
	movsd	.LCPI0_3(%rip), %xmm2           # xmm2 = mem[0],zero
	movsd	.LCPI0_4(%rip), %xmm3           # xmm3 = mem[0],zero
	movsd	.LCPI0_5(%rip), %xmm4           # xmm4 = mem[0],zero
	xorl	%ebp, %ebp
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
	ucomisd	%xmm9, %xmm8
	jb	.LBB0_3
# %bb.2:                                #   in Loop: Header=BB0_1 Depth=1
	movapd	%xmm8, %xmm0
	mulsd	%xmm8, %xmm0
	movapd	%xmm0, %xmm5
	mulsd	%xmm1, %xmm5
	mulsd	%xmm2, %xmm5
	movsd	%xmm5, 24(%rsp)                 # 8-byte Spill
	mulsd	%xmm3, %xmm0
	divsd	%xmm4, %xmm0
	movsd	%xmm8, 8(%rsp)                  # 8-byte Spill
	callq	exp
	mulsd	24(%rsp), %xmm0                 # 8-byte Folded Reload
	mulsd	.LCPI0_6(%rip), %xmm0
	movsd	.LCPI0_7(%rip), %xmm1           # xmm1 = mem[0],zero
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 48(%rsp)                 # 8-byte Spill
	callq	rand
	movslq	%ebx, %rbx
	callq	rand
	callq	rand
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI0_8(%rip), %xmm0
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI0_9(%rip), %xmm0
	movsd	%xmm0, 32(%rsp)                 # 8-byte Spill
	callq	rand
	xorps	%xmm1, %xmm1
	cvtsi2sd	%eax, %xmm1
	movsd	.LCPI0_10(%rip), %xmm0          # xmm0 = mem[0],zero
	divsd	48(%rsp), %xmm0                 # 8-byte Folded Reload
	divsd	%xmm0, %xmm1
	addsd	8(%rsp), %xmm1                  # 8-byte Folded Reload
	movsd	%xmm1, 24(%rsp)                 # 8-byte Spill
	movsd	%xmm1, 64(%rsp,%rbx,8)
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	sin
	mulsd	24(%rsp), %xmm0                 # 8-byte Folded Reload
	movsd	%xmm0, 40(%rsp)                 # 8-byte Spill
	movsd	32(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	cos
	mulsd	40(%rsp), %xmm0                 # 8-byte Folded Reload
	movsd	%xmm0, 40(%rsp)                 # 8-byte Spill
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	sin
	mulsd	24(%rsp), %xmm0                 # 8-byte Folded Reload
	movsd	%xmm0, 56(%rsp)                 # 8-byte Spill
	movsd	32(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	sin
	mulsd	56(%rsp), %xmm0                 # 8-byte Folded Reload
	movsd	%xmm0, 32(%rsp)                 # 8-byte Spill
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	cos
	mulsd	24(%rsp), %xmm0                 # 8-byte Folded Reload
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	subsd	48(%rsp), %xmm0                 # 8-byte Folded Reload
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$5, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	48(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$11, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	%ebp, %esi
	callq	_ZNSolsEi
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$14, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movsd	40(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r14
	movl	$.L.str.4, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r14, %rdi
	movsd	32(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r14
	movl	$.L.str.4, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r14, %rdi
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	xorpd	%xmm9, %xmm9
	movsd	8(%rsp), %xmm8                  # 8-byte Reload
                                        # xmm8 = mem[0],zero
	movsd	.LCPI0_5(%rip), %xmm4           # xmm4 = mem[0],zero
	movsd	.LCPI0_4(%rip), %xmm3           # xmm3 = mem[0],zero
	movsd	.LCPI0_3(%rip), %xmm2           # xmm2 = mem[0],zero
	movsd	.LCPI0_2(%rip), %xmm1           # xmm1 = mem[0],zero
	incl	%ebx
.LBB0_3:                                #   in Loop: Header=BB0_1 Depth=1
	incl	%ebp
	cmpl	$1000000, %ebp                  # imm = 0xF4240
	jne	.LBB0_1
# %bb.4:                                # %.preheader123
	cmpl	$999999, %ebx                   # imm = 0xF423F
	jg	.LBB0_8
# %bb.5:                                # %.lr.ph.preheader
	movslq	%ebx, %r15
	incq	%r15
	movsd	.LCPI0_1(%rip), %xmm8           # xmm8 = mem[0],zero
	movsd	%xmm8, 24(%rsp)                 # 8-byte Spill
	movq	%r15, %r12
.LBB0_6:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	mulsd	%xmm0, %xmm0
	movapd	%xmm0, %xmm5
	mulsd	%xmm1, %xmm5
	mulsd	%xmm2, %xmm5
	movsd	%xmm5, 8(%rsp)                  # 8-byte Spill
	mulsd	%xmm3, %xmm0
	divsd	%xmm4, %xmm0
	callq	exp
	mulsd	8(%rsp), %xmm0                  # 8-byte Folded Reload
	mulsd	.LCPI0_6(%rip), %xmm0
	movsd	.LCPI0_7(%rip), %xmm1           # xmm1 = mem[0],zero
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 48(%rsp)                 # 8-byte Spill
	callq	rand
	callq	rand
	callq	rand
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI0_8(%rip), %xmm0
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI0_9(%rip), %xmm0
	movsd	%xmm0, 32(%rsp)                 # 8-byte Spill
	callq	rand
	xorps	%xmm1, %xmm1
	cvtsi2sd	%eax, %xmm1
	movsd	.LCPI0_11(%rip), %xmm0          # xmm0 = mem[0],zero
	divsd	48(%rsp), %xmm0                 # 8-byte Folded Reload
	divsd	%xmm0, %xmm1
	addsd	24(%rsp), %xmm1                 # 8-byte Folded Reload
	movsd	%xmm1, 8(%rsp)                  # 8-byte Spill
	movsd	%xmm1, 56(%rsp,%r15,8)
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	sin
	mulsd	8(%rsp), %xmm0                  # 8-byte Folded Reload
	movsd	%xmm0, 40(%rsp)                 # 8-byte Spill
	movsd	32(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	cos
	mulsd	40(%rsp), %xmm0                 # 8-byte Folded Reload
	movsd	%xmm0, 40(%rsp)                 # 8-byte Spill
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	sin
	mulsd	8(%rsp), %xmm0                  # 8-byte Folded Reload
	movsd	%xmm0, 56(%rsp)                 # 8-byte Spill
	movsd	32(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	sin
	mulsd	56(%rsp), %xmm0                 # 8-byte Folded Reload
	movsd	%xmm0, 32(%rsp)                 # 8-byte Spill
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	cos
	mulsd	8(%rsp), %xmm0                  # 8-byte Folded Reload
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	addsd	48(%rsp), %xmm0                 # 8-byte Folded Reload
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$5, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	48(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$11, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	%ebx, %esi
	callq	_ZNSolsEi
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$14, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movsd	40(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r14
	movl	$.L.str.4, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r14, %rdi
	movsd	32(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r14
	movl	$.L.str.4, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r14, %rdi
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movsd	.LCPI0_5(%rip), %xmm4           # xmm4 = mem[0],zero
	movsd	.LCPI0_4(%rip), %xmm3           # xmm3 = mem[0],zero
	movsd	.LCPI0_3(%rip), %xmm2           # xmm2 = mem[0],zero
	movsd	.LCPI0_2(%rip), %xmm1           # xmm1 = mem[0],zero
	incl	%ebx
	incq	%r12
	cmpl	$1000000, %r15d                 # imm = 0xF4240
	movq	%r12, %r15
	jne	.LBB0_6
# %bb.7:
	movl	$1000000, %ebx                  # imm = 0xF4240
.LBB0_8:                                # %.lr.ph131.preheader
	movl	%ebx, %eax
	xorpd	%xmm1, %xmm1
	xorl	%ecx, %ecx
.LBB0_9:                                # %.lr.ph131
                                        # =>This Inner Loop Header: Depth=1
	addsd	64(%rsp,%rcx,8), %xmm1
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB0_9
# %bb.10:                               # %._crit_edge
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 8(%rsp)                  # 8-byte Spill
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$9, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	xorl	%eax, %eax
	addq	$8000064, %rsp                  # imm = 0x7A1240
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Average velocity"
	.size	.L.str, 17

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"width"
	.size	.L.str.1, 6

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Atom Index "
	.size	.L.str.2, 12

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Atom Velocity "
	.size	.L.str.3, 15

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	" "
	.size	.L.str.4, 2

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Average: "
	.size	.L.str.5, 10

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
