#include <iostream>
#include "sys/time.h"
using namespace std;

double timeInSeconds (timeval& starttime, timeval& stopstime) {
  return 1e-6*(1e6*(stopstime.tv_sec - starttime.tv_sec) + (stopstime.tv_usec - starttime.tv_usec)); 
}

//__device__ double* dev_vector1 = 0;
//__device__ double* dev_vector2 = 0;
//__device__ double* dev_results = 0;
 
__global__ void device_vector_mult (double* v1, double* v2, double* res) {
  // IMPLEMENT ME 6: Multiply the threadIdx.x element of dev_vector1 by the 
  // corresponding element of dev_vector2, and store in dev_results. 
  res[threadIdx.x] = 2 * v1[threadIdx.x] * v2[threadIdx.x];
}

__global__ void device_vector_reduce (double* results, int* length) {
        int len = *length;
        
        while (len > 1) {
                if (threadIdx.x < (len - (len % 2)) / 2) {
                        results[threadIdx.x] += results[threadIdx.x + (len + (len % 2)) / 2];
                }
                len = (len + (len % 2)) / 2;
                __syncthreads();
        }
}



__global__ void device_vector_simpleAdd (double* vec, double* res) {
  if (threadIdx.x == 0) {
    res[0] = 2;
  }
}


int main (int argc, char** argv) {
  int sizeOfVector = 100;
  if (argc > 1) sizeOfVector = atoi(argv[1]); 

  // Declare and fill host-side arrays of doubles. 
  double* vector1 = new double[sizeOfVector];
  double* vector2 = new double[sizeOfVector];
  double* results = new double[sizeOfVector];
  double* gpuresults = new double[sizeOfVector];
  double* gpuAddresults = new double[sizeOfVector];

  srand(42); 
  for (int i = 0; i < sizeOfVector; ++i) {
    vector1[i] = rand() % 100; 
    vector2[i] = rand() % 100; 
    results[i] = 0; 
    gpuresults[i] = 0;
    gpuAddresults[i] = 0;
  }
  timeval startTime;
  timeval interTime; 
  timeval stopsTime; 

  gettimeofday(&startTime, NULL);

  // Use the CPU for this part. 
  // IMPLEMENT ME 1: Multiply each element of vector1 by the corresponding
  // element in vector2 and store in results. 
  for (int i = 0; i < sizeOfVector; ++i) {
        results[i] = vector1[i] * vector2[i];  
  }
  gettimeofday(&interTime, NULL);

  double total = 0;
  // IMPLEMENT ME 2: Sum the results array and store the sum in total.
  for (int i = 0; i < sizeOfVector; ++i) {
        total += results[i];
  }

  gettimeofday(&stopsTime, NULL);

  cout << "Dot product is: " << total << endl;

  // IMPLEMENT ME 3: Time the above operations together and separately
  // using 'gettimeofday'.

  cout << "Time for multiplication (seconds): " << timeInSeconds(startTime, interTime) << endl;
  cout << "Time for addition       (seconds): " << timeInSeconds(interTime, stopsTime) << endl;
  cout << "Overall time            (seconds): " << timeInSeconds(startTime, stopsTime) << endl;

  double* dev_vector1 = 0;
  double* dev_vector2 = 0;
  double* dev_results = 0;

  int sizeInBytes = sizeOfVector * sizeof(double);


  cudaMalloc((void**) &dev_vector1, sizeInBytes);
  cudaMalloc((void**) &dev_vector2, sizeInBytes);
  cudaMalloc((void**) &dev_results, sizeInBytes);

  cudaMemcpy(dev_vector1, vector1, sizeInBytes, cudaMemcpyHostToDevice);
  cudaMemcpy(dev_vector2, vector2, sizeInBytes, cudaMemcpyHostToDevice);

  gettimeofday(&startTime, NULL);
  device_vector_mult<<<1, sizeOfVector>>>(dev_vector1, dev_vector2, dev_results);

  double gputotal = 0;

  cudaMemcpy(gpuresults, dev_results, sizeInBytes, cudaMemcpyDeviceToHost);

  gettimeofday(&interTime, NULL);
  for (int i = 0; i < sizeOfVector; ++i) {
    gputotal += gpuresults[i];
  }

  gettimeofday(&stopsTime, NULL);

  cout << "GPU-mult Dot product is: " << gputotal << endl;

  cout << "GPU-mult Time for multiplication (seconds): " << timeInSeconds(startTime, interTime) << endl;
  cout << "GPU-mult Time for addition       (seconds): " << timeInSeconds(interTime, stopsTime) << endl;
  cout << "GPU-mult Overall time            (seconds): " << timeInSeconds(startTime, stopsTime) << endl;

  double * dev_added = 0;
  cudaMalloc((void**) &dev_added, sizeof(double));


  //device_vector_simpleAdd<<<1, sizeOfVector>>>(dev_results, dev_added);
  device_vector_reduce<<<1, sizeOfVector>>>(dev_results, &sizeOfVector);


  double host_added = 2;
  //cudaMemcpy(&host_added, &dev_added[0], sizeof(double), cudaMemcpyDeviceToHost);
  cudaMemcpy(&host_added, &dev_results[0], sizeof(double), cudaMemcpyDeviceToHost);

  cout <<"GPU-full Dot product is: " << host_added << endl;
  cout << "Size of Vectors is: " << sizeOfVector << endl;

  return 0;
}


	.file	"tmpxft_00312fde_00000000-6_ex1b.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3639:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3639:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB4298:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE4298:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.globl	_Z13timeInSecondsR7timevalS0_
	.type	_Z13timeInSecondsR7timevalS0_, @function
_Z13timeInSecondsR7timevalS0_:
.LFB3635:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rax
	subq	(%rdi), %rax
	cvtsi2sdq	%rax, %xmm0
	movq	8(%rsi), %rax
	mulsd	.LC0(%rip), %xmm0
	subq	8(%rdi), %rax
	cvtsi2sdq	%rax, %xmm1
	addsd	%xmm1, %xmm0
	mulsd	.LC1(%rip), %xmm0
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z13timeInSecondsR7timevalS0_, .-_Z13timeInSecondsR7timevalS0_
	.globl	_Z42__device_stub__Z18device_vector_multPdS_S_PdS_S_
	.type	_Z42__device_stub__Z18device_vector_multPdS_S_PdS_S_, @function
_Z42__device_stub__Z18device_vector_multPdS_S_PdS_S_:
.LFB3661:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L4
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z18device_vector_multPdS_S_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L4:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L6
	call	__stack_chk_fail@PLT
.L6:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3661:
	.size	_Z42__device_stub__Z18device_vector_multPdS_S_PdS_S_, .-_Z42__device_stub__Z18device_vector_multPdS_S_PdS_S_
	.globl	_Z18device_vector_multPdS_S_
	.type	_Z18device_vector_multPdS_S_, @function
_Z18device_vector_multPdS_S_:
.LFB3662:
	.cfi_startproc
	endbr64
	jmp	_Z42__device_stub__Z18device_vector_multPdS_S_PdS_S_
	.cfi_endproc
.LFE3662:
	.size	_Z18device_vector_multPdS_S_, .-_Z18device_vector_multPdS_S_
	.globl	_Z42__device_stub__Z20device_vector_reducePdPiPdPi
	.type	_Z42__device_stub__Z20device_vector_reducePdPiPdPi, @function
_Z42__device_stub__Z20device_vector_reducePdPiPdPi:
.LFB3663:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L10
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z20device_vector_reducePdPi(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L10:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3663:
	.size	_Z42__device_stub__Z20device_vector_reducePdPiPdPi, .-_Z42__device_stub__Z20device_vector_reducePdPiPdPi
	.globl	_Z20device_vector_reducePdPi
	.type	_Z20device_vector_reducePdPi, @function
_Z20device_vector_reducePdPi:
.LFB3664:
	.cfi_startproc
	endbr64
	jmp	_Z42__device_stub__Z20device_vector_reducePdPiPdPi
	.cfi_endproc
.LFE3664:
	.size	_Z20device_vector_reducePdPi, .-_Z20device_vector_reducePdPi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC3:
	.string	"Dot product is: "
.LC4:
	.string	"Time for multiplication (seconds): "
.LC5:
	.string	"Time for addition       (seconds): "
.LC6:
	.string	"Overall time            (seconds): "
.LC7:
	.string	"GPU-mult Dot product is: "
.LC8:
	.string	"GPU-mult Time for multiplication (seconds): "
.LC9:
	.string	"GPU-mult Time for addition       (seconds): "
.LC10:
	.string	"GPU-mult Overall time            (seconds): "
.LC12:
	.string	"GPU-full Dot product is: "
.LC13:
	.string	"Size of Vectors is: "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3636:
	.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
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	decl	%edi
	movl	$100, 20(%rsp)
	jle	.L16
	movq	8(%rsi), %rdi
	call	atoi@PLT
	movl	%eax, 20(%rsp)
.L16:
	movabsq	$1152921504606846975, %rbp
	movslq	20(%rsp), %rdi
	cmpq	%rdi, %rbp
	jb	.L17
	salq	$3, %rdi
	call	_Znam@PLT
	movslq	20(%rsp), %rdi
	movq	%rax, %r15
	cmpq	%rdi, %rbp
	jnb	.L18
.L17:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L32
	call	__cxa_throw_bad_array_new_length@PLT
.L18:
	salq	$3, %rdi
	call	_Znam@PLT
	movslq	20(%rsp), %rdi
	movq	%rax, %r14
	cmpq	%rdi, %rbp
	jb	.L17
	salq	$3, %rdi
	call	_Znam@PLT
	movslq	20(%rsp), %rdi
	movq	%rax, %rbx
	cmpq	%rdi, %rbp
	jb	.L17
	salq	$3, %rdi
	call	_Znam@PLT
	movslq	20(%rsp), %rdi
	movq	%rax, %r13
	cmpq	%rdi, %rbp
	jb	.L17
	salq	$3, %rdi
	xorl	%ebp, %ebp
	call	_Znam@PLT
	movl	$42, %edi
	movq	%rax, %r12
	call	srand@PLT
.L20:
	cmpl	%ebp, 20(%rsp)
	jle	.L33
	call	rand@PLT
	movl	$100, %ecx
	cltd
	idivl	%ecx
	cvtsi2sdl	%edx, %xmm0
	movsd	%xmm0, (%r15,%rbp,8)
	call	rand@PLT
	movl	$100, %ecx
	movq	$0x000000000, (%rbx,%rbp,8)
	cltd
	movq	$0x000000000, (%r12,%rbp,8)
	idivl	%ecx
	movq	$0x000000000, 0(%r13,%rbp,8)
	cvtsi2sdl	%edx, %xmm0
	movsd	%xmm0, (%r14,%rbp,8)
	incq	%rbp
	jmp	.L20
.L33:
	leaq	88(%rsp), %rax
	xorl	%esi, %esi
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	gettimeofday@PLT
	movl	20(%rsp), %edx
	xorl	%eax, %eax
.L22:
	cmpl	%eax, %edx
	jle	.L34
	movsd	(%r15,%rax,8), %xmm0
	mulsd	(%r14,%rax,8), %xmm0
	movsd	%xmm0, (%rbx,%rax,8)
	incq	%rax
	jmp	.L22
.L34:
	leaq	104(%rsp), %r12
	xorl	%esi, %esi
	movq	%r12, %rdi
	call	gettimeofday@PLT
	movl	20(%rsp), %edx
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.L24:
	cmpl	%eax, %edx
	jle	.L35
	addsd	(%rbx,%rax,8), %xmm0
	incq	%rax
	jmp	.L24
.L35:
	leaq	120(%rsp), %rbp
	xorl	%esi, %esi
	movsd	%xmm0, 8(%rsp)
	movq	%rbp, %rdi
	call	gettimeofday@PLT
	leaq	.LC3(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	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	.LC4(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	(%rsp), %rdi
	movq	%r12, %rsi
	movq	%rax, %rdx
	call	_Z13timeInSecondsR7timevalS0_
	movq	%rdx, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC5(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbp, %rsi
	movq	%r12, %rdi
	movq	%rax, %rdx
	call	_Z13timeInSecondsR7timevalS0_
	movq	%rdx, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC6(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	movq	%rax, %rdx
	call	_Z13timeInSecondsR7timevalS0_
	movq	%rdx, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	20(%rsp), %eax
	xorl	%edx, %edx
	leaq	24(%rsp), %rdi
	movq	%rdx, 24(%rsp)
	leal	0(,%rax,8), %ebx
	movq	%rdx, 32(%rsp)
	movslq	%ebx, %rbx
	movq	%rdx, 40(%rsp)
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movq	24(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%r15, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%r14, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	movl	20(%rsp), %eax
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movl	$1, 68(%rsp)
	movq	%rdi, 76(%rsp)
	movl	80(%rsp), %ecx
	movl	%eax, 72(%rsp)
	movq	72(%rsp), %rdx
	movq	%rdi, 60(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L26
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z42__device_stub__Z18device_vector_multPdS_S_PdS_S_
.L26:
	movq	40(%rsp), %rsi
	movq	%rbx, %rdx
	movl	$2, %ecx
	movq	%r13, %rdi
	call	cudaMemcpy@PLT
	xorl	%esi, %esi
	movq	%r12, %rdi
	call	gettimeofday@PLT
	movl	20(%rsp), %edx
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.L27:
	cmpl	%eax, %edx
	jle	.L36
	addsd	0(%r13,%rax,8), %xmm0
	incq	%rax
	jmp	.L27
.L36:
	xorl	%esi, %esi
	movq	%rbp, %rdi
	movsd	%xmm0, 8(%rsp)
	call	gettimeofday@PLT
	leaq	.LC7(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	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	.LC8(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	(%rsp), %rdi
	movq	%r12, %rsi
	movq	%rax, %rdx
	call	_Z13timeInSecondsR7timevalS0_
	movq	%rdx, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC9(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbp, %rsi
	movq	%r12, %rdi
	movq	%rax, %rdx
	call	_Z13timeInSecondsR7timevalS0_
	movq	%rdx, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC10(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	movq	%rax, %rdx
	call	_Z13timeInSecondsR7timevalS0_
	movq	%rdx, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	xorl	%eax, %eax
	leaq	48(%rsp), %rdi
	movl	$8, %esi
	movq	%rax, 48(%rsp)
	call	cudaMalloc@PLT
	movl	20(%rsp), %eax
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movl	$1, 68(%rsp)
	movq	%rdi, 76(%rsp)
	movl	80(%rsp), %ecx
	movl	%eax, 72(%rsp)
	movq	72(%rsp), %rdx
	movq	%rdi, 60(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	movq	40(%rsp), %rdi
	leaq	20(%rsp), %rsi
	call	_Z42__device_stub__Z20device_vector_reducePdPiPdPi
.L29:
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movl	$8, %edx
	movq	.LC11(%rip), %rax
	leaq	72(%rsp), %rdi
	movq	%rax, 72(%rsp)
	call	cudaMemcpy@PLT
	leaq	.LC12(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	72(%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	.LC13(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	20(%rsp), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
.L32:
	call	__stack_chk_fail@PLT
.L30:
	addq	$152, %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
.LFE3636:
	.size	main, .-main
	.text
	.globl	_Z45__device_stub__Z23device_vector_simpleAddPdS_PdS_
	.type	_Z45__device_stub__Z23device_vector_simpleAddPdS_PdS_, @function
_Z45__device_stub__Z23device_vector_simpleAddPdS_PdS_:
.LFB3665:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L37
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z23device_vector_simpleAddPdS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L37:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L39
	call	__stack_chk_fail@PLT
.L39:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3665:
	.size	_Z45__device_stub__Z23device_vector_simpleAddPdS_PdS_, .-_Z45__device_stub__Z23device_vector_simpleAddPdS_PdS_
	.globl	_Z23device_vector_simpleAddPdS_
	.type	_Z23device_vector_simpleAddPdS_, @function
_Z23device_vector_simpleAddPdS_:
.LFB3666:
	.cfi_startproc
	endbr64
	jmp	_Z45__device_stub__Z23device_vector_simpleAddPdS_PdS_
	.cfi_endproc
.LFE3666:
	.size	_Z23device_vector_simpleAddPdS_, .-_Z23device_vector_simpleAddPdS_
	.section	.rodata.str1.1
.LC14:
	.string	"_Z23device_vector_simpleAddPdS_"
.LC15:
	.string	"_Z20device_vector_reducePdPi"
.LC16:
	.string	"_Z18device_vector_multPdS_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3668:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC14(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z23device_vector_simpleAddPdS_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC15(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z20device_vector_reducePdPi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC16(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z18device_vector_multPdS_S_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3668:
	.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	0
	.long	1093567616
	.align 8
.LC1:
	.long	-1598689907
	.long	1051772663
	.align 8
.LC11:
	.long	0
	.long	1073741824
	.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:


#include <hip/hip_runtime.h>
#include <iostream>
#include "sys/time.h"
using namespace std;

double timeInSeconds (timeval& starttime, timeval& stopstime) {
  return 1e-6*(1e6*(stopstime.tv_sec - starttime.tv_sec) + (stopstime.tv_usec - starttime.tv_usec)); 
}

//__device__ double* dev_vector1 = 0;
//__device__ double* dev_vector2 = 0;
//__device__ double* dev_results = 0;
 
__global__ void device_vector_mult (double* v1, double* v2, double* res) {
  // IMPLEMENT ME 6: Multiply the threadIdx.x element of dev_vector1 by the 
  // corresponding element of dev_vector2, and store in dev_results. 
  res[threadIdx.x] = 2 * v1[threadIdx.x] * v2[threadIdx.x];
}

__global__ void device_vector_reduce (double* results, int* length) {
        int len = *length;
        
        while (len > 1) {
                if (threadIdx.x < (len - (len % 2)) / 2) {
                        results[threadIdx.x] += results[threadIdx.x + (len + (len % 2)) / 2];
                }
                len = (len + (len % 2)) / 2;
                __syncthreads();
        }
}



__global__ void device_vector_simpleAdd (double* vec, double* res) {
  if (threadIdx.x == 0) {
    res[0] = 2;
  }
}


int main (int argc, char** argv) {
  int sizeOfVector = 100;
  if (argc > 1) sizeOfVector = atoi(argv[1]); 

  // Declare and fill host-side arrays of doubles. 
  double* vector1 = new double[sizeOfVector];
  double* vector2 = new double[sizeOfVector];
  double* results = new double[sizeOfVector];
  double* gpuresults = new double[sizeOfVector];
  double* gpuAddresults = new double[sizeOfVector];

  srand(42); 
  for (int i = 0; i < sizeOfVector; ++i) {
    vector1[i] = rand() % 100; 
    vector2[i] = rand() % 100; 
    results[i] = 0; 
    gpuresults[i] = 0;
    gpuAddresults[i] = 0;
  }
  timeval startTime;
  timeval interTime; 
  timeval stopsTime; 

  gettimeofday(&startTime, NULL);

  // Use the CPU for this part. 
  // IMPLEMENT ME 1: Multiply each element of vector1 by the corresponding
  // element in vector2 and store in results. 
  for (int i = 0; i < sizeOfVector; ++i) {
        results[i] = vector1[i] * vector2[i];  
  }
  gettimeofday(&interTime, NULL);

  double total = 0;
  // IMPLEMENT ME 2: Sum the results array and store the sum in total.
  for (int i = 0; i < sizeOfVector; ++i) {
        total += results[i];
  }

  gettimeofday(&stopsTime, NULL);

  cout << "Dot product is: " << total << endl;

  // IMPLEMENT ME 3: Time the above operations together and separately
  // using 'gettimeofday'.

  cout << "Time for multiplication (seconds): " << timeInSeconds(startTime, interTime) << endl;
  cout << "Time for addition       (seconds): " << timeInSeconds(interTime, stopsTime) << endl;
  cout << "Overall time            (seconds): " << timeInSeconds(startTime, stopsTime) << endl;

  double* dev_vector1 = 0;
  double* dev_vector2 = 0;
  double* dev_results = 0;

  int sizeInBytes = sizeOfVector * sizeof(double);


  hipMalloc((void**) &dev_vector1, sizeInBytes);
  hipMalloc((void**) &dev_vector2, sizeInBytes);
  hipMalloc((void**) &dev_results, sizeInBytes);

  hipMemcpy(dev_vector1, vector1, sizeInBytes, hipMemcpyHostToDevice);
  hipMemcpy(dev_vector2, vector2, sizeInBytes, hipMemcpyHostToDevice);

  gettimeofday(&startTime, NULL);
  device_vector_mult<<<1, sizeOfVector>>>(dev_vector1, dev_vector2, dev_results);

  double gputotal = 0;

  hipMemcpy(gpuresults, dev_results, sizeInBytes, hipMemcpyDeviceToHost);

  gettimeofday(&interTime, NULL);
  for (int i = 0; i < sizeOfVector; ++i) {
    gputotal += gpuresults[i];
  }

  gettimeofday(&stopsTime, NULL);

  cout << "GPU-mult Dot product is: " << gputotal << endl;

  cout << "GPU-mult Time for multiplication (seconds): " << timeInSeconds(startTime, interTime) << endl;
  cout << "GPU-mult Time for addition       (seconds): " << timeInSeconds(interTime, stopsTime) << endl;
  cout << "GPU-mult Overall time            (seconds): " << timeInSeconds(startTime, stopsTime) << endl;

  double * dev_added = 0;
  hipMalloc((void**) &dev_added, sizeof(double));


  //device_vector_simpleAdd<<<1, sizeOfVector>>>(dev_results, dev_added);
  device_vector_reduce<<<1, sizeOfVector>>>(dev_results, &sizeOfVector);


  double host_added = 2;
  //cudaMemcpy(&host_added, &dev_added[0], sizeof(double), cudaMemcpyDeviceToHost);
  hipMemcpy(&host_added, &dev_results[0], sizeof(double), hipMemcpyDeviceToHost);

  cout <<"GPU-full Dot product is: " << host_added << endl;
  cout << "Size of Vectors is: " << sizeOfVector << endl;

  return 0;
}


	.text
	.file	"ex1b.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 _Z13timeInSecondsR7timevalS0_
.LCPI0_0:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI0_1:
	.quad	0x3eb0c6f7a0b5ed8d              # double 9.9999999999999995E-7
	.text
	.globl	_Z13timeInSecondsR7timevalS0_
	.type	_Z13timeInSecondsR7timevalS0_,@function
_Z13timeInSecondsR7timevalS0_:          # @_Z13timeInSecondsR7timevalS0_
	.cfi_startproc
# %bb.0:
	movq	(%rsi), %rax
	movq	8(%rsi), %rcx
	subq	(%rdi), %rax
	cvtsi2sd	%rax, %xmm1
	mulsd	.LCPI0_0(%rip), %xmm1
	subq	8(%rdi), %rcx
	cvtsi2sd	%rcx, %xmm0
	addsd	%xmm1, %xmm0
	mulsd	.LCPI0_1(%rip), %xmm0
	retq
.Lfunc_end0:
	.size	_Z13timeInSecondsR7timevalS0_, .Lfunc_end0-_Z13timeInSecondsR7timevalS0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z33__device_stub__device_vector_multPdS_S_ # -- Begin function _Z33__device_stub__device_vector_multPdS_S_
	.type	_Z33__device_stub__device_vector_multPdS_S_,@function
_Z33__device_stub__device_vector_multPdS_S_: # @_Z33__device_stub__device_vector_multPdS_S_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z18device_vector_multPdS_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.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
	retq
.Lfunc_end1:
	.size	_Z33__device_stub__device_vector_multPdS_S_, .Lfunc_end1-_Z33__device_stub__device_vector_multPdS_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z35__device_stub__device_vector_reducePdPi # -- Begin function _Z35__device_stub__device_vector_reducePdPi
	.type	_Z35__device_stub__device_vector_reducePdPi,@function
_Z35__device_stub__device_vector_reducePdPi: # @_Z35__device_stub__device_vector_reducePdPi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%rsp, %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z20device_vector_reducePdPi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.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
	retq
.Lfunc_end2:
	.size	_Z35__device_stub__device_vector_reducePdPi, .Lfunc_end2-_Z35__device_stub__device_vector_reducePdPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z38__device_stub__device_vector_simpleAddPdS_ # -- Begin function _Z38__device_stub__device_vector_simpleAddPdS_
	.type	_Z38__device_stub__device_vector_simpleAddPdS_,@function
_Z38__device_stub__device_vector_simpleAddPdS_: # @_Z38__device_stub__device_vector_simpleAddPdS_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%rsp, %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z23device_vector_simpleAddPdS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.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
	retq
.Lfunc_end3:
	.size	_Z38__device_stub__device_vector_simpleAddPdS_, .Lfunc_end3-_Z38__device_stub__device_vector_simpleAddPdS_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI4_0:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI4_1:
	.quad	0x3eb0c6f7a0b5ed8d              # double 9.9999999999999995E-7
	.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	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$100, 4(%rsp)
	cmpl	$2, %edi
	jl	.LBB4_1
# %bb.2:
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r12d
	movl	%eax, 4(%rsp)
	cltq
	leaq	(,%rax,8), %rcx
	testl	%eax, %eax
	movq	$-1, %r15
	cmovnsq	%rcx, %r15
	jmp	.LBB4_3
.LBB4_1:
	movl	$800, %r15d                     # imm = 0x320
	movl	$100, %r12d
.LBB4_3:                                # %.thread
	movq	%r12, 16(%rsp)                  # 8-byte Spill
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r13
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, 40(%rsp)                  # 8-byte Spill
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %rbx
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r15
	movl	$42, %edi
	callq	srand
	movl	%r12d, %r14d
	testl	%r12d, %r12d
	jle	.LBB4_4
# %bb.20:                               # %.lr.ph.preheader
	xorl	%ebp, %ebp
	xorl	%r12d, %r12d
	movq	%r14, 8(%rsp)                   # 8-byte Spill
	movq	%r15, %r14
	movq	%r13, %r15
	movq	40(%rsp), %r13                  # 8-byte Reload
.LBB4_21:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$37, %rcx
	addl	%edx, %ecx
	imull	$100, %ecx, %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	%xmm0, (%r15,%r12,8)
	callq	rand
	cltq
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$37, %rcx
	addl	%edx, %ecx
	imull	$100, %ecx, %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	%xmm0, (%r13,%r12,8)
	movq	%rbp, (%rbx,%r12,8)
	movq	%rbp, (%r14,%r12,8)
	incq	%r12
	cmpq	%r12, 8(%rsp)                   # 8-byte Folded Reload
	jne	.LBB4_21
# %bb.7:                                # %._crit_edge
	leaq	64(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	16(%rsp), %r12                  # 8-byte Reload
	testl	%r12d, %r12d
	movq	%r15, %r13
	movq	%r14, %r15
	movq	8(%rsp), %r14                   # 8-byte Reload
	jle	.LBB4_5
# %bb.8:                                # %.lr.ph66.preheader
	xorl	%eax, %eax
	movq	40(%rsp), %rcx                  # 8-byte Reload
.LBB4_9:                                # %.lr.ph66
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%r13,%rax,8), %xmm0            # xmm0 = mem[0],zero
	mulsd	(%rcx,%rax,8), %xmm0
	movsd	%xmm0, (%rbx,%rax,8)
	incq	%rax
	cmpq	%rax, %r14
	jne	.LBB4_9
# %bb.10:                               # %._crit_edge67
	leaq	48(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	testl	%r12d, %r12d
	jle	.LBB4_6
# %bb.11:                               # %.lr.ph71.preheader
	xorpd	%xmm0, %xmm0
	xorl	%eax, %eax
.LBB4_12:                               # %.lr.ph71
                                        # =>This Inner Loop Header: Depth=1
	addsd	(%rbx,%rax,8), %xmm0
	incq	%rax
	cmpq	%rax, %r14
	jne	.LBB4_12
	jmp	.LBB4_13
.LBB4_4:                                # %._crit_edge.thread
	leaq	64(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
.LBB4_5:                                # %._crit_edge67.thread
	leaq	48(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
.LBB4_6:                                # %._crit_edge67.._crit_edge72_crit_edge
	xorpd	%xmm0, %xmm0
.LBB4_13:
	movsd	%xmm0, 32(%rsp)                 # 8-byte Spill
	leaq	120(%rsp), %rdi
	movq	%rdi, %r12
	xorl	%esi, %esi
	callq	gettimeofday
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$16, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	32(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbp
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%rbp, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbp, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$35, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	48(%rsp), %rbx
	movq	56(%rsp), %rsi
	movq	%rsi, 80(%rsp)                  # 8-byte Spill
	leaq	64(%rsp), %rax
	movq	(%rax), %rdx
	movq	%rdx, 8(%rsp)                   # 8-byte Spill
	movq	8(%rax), %rcx
	movq	%rcx, 32(%rsp)                  # 8-byte Spill
	movq	%rbx, %rax
	subq	%rdx, %rax
	cvtsi2sd	%rax, %xmm1
	movq	%rsi, %rax
	subq	%rcx, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	mulsd	.LCPI4_0(%rip), %xmm1
	addsd	%xmm1, %xmm0
	mulsd	.LCPI4_1(%rip), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbp
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%rbp, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbp, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$35, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r12, %rcx
	movq	(%r12), %r12
	movq	%r12, %rax
	subq	%rbx, %rax
	xorps	%xmm1, %xmm1
	cvtsi2sd	%rax, %xmm1
	movq	8(%rcx), %rbp
	mulsd	.LCPI4_0(%rip), %xmm1
	movq	%rbp, %rax
	subq	80(%rsp), %rax                  # 8-byte Folded Reload
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	addsd	%xmm1, %xmm0
	mulsd	.LCPI4_1(%rip), %xmm0
	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
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$35, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	subq	8(%rsp), %r12                   # 8-byte Folded Reload
	xorps	%xmm1, %xmm1
	cvtsi2sd	%r12, %xmm1
	mulsd	.LCPI4_0(%rip), %xmm1
	subq	32(%rsp), %rbp                  # 8-byte Folded Reload
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rbp, %xmm0
	addsd	%xmm1, %xmm0
	mulsd	.LCPI4_1(%rip), %xmm0
	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
	leaq	96(%rsp), %rbp
	xorl	%eax, %eax
	movq	%rax, (%rbp)
	leaq	88(%rsp), %r12
	movq	%rax, (%r12)
	xorl	%eax, %eax
	leaq	24(%rsp), %rcx
	movq	%rax, (%rcx)
	movq	16(%rsp), %rax                  # 8-byte Reload
	leal	(,%rax,8), %eax
	movslq	%eax, %rbx
	movq	%rbp, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movq	%r12, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movq	(%rbp), %rdi
	movq	%r13, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r12), %rdi
	movq	40(%rsp), %rsi                  # 8-byte Reload
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	64(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	leaq	(%r14,%rdi), %rdx
	decq	%rdx
	movl	$1, %esi
	movq	%rdx, 8(%rsp)                   # 8-byte Spill
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_15
# %bb.14:
	movq	96(%rsp), %rdi
	movq	88(%rsp), %rsi
	movq	24(%rsp), %rdx
	callq	_Z33__device_stub__device_vector_multPdS_S_
.LBB4_15:
	movq	24(%rsp), %rsi
	movq	%r15, %rdi
	movq	%rbx, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	leaq	48(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	cmpl	$0, 16(%rsp)                    # 4-byte Folded Reload
	jle	.LBB4_16
# %bb.22:                               # %.lr.ph76.preheader
	xorpd	%xmm0, %xmm0
	xorl	%eax, %eax
.LBB4_23:                               # %.lr.ph76
                                        # =>This Inner Loop Header: Depth=1
	addsd	(%r15,%rax,8), %xmm0
	incq	%rax
	cmpq	%rax, %r14
	jne	.LBB4_23
	jmp	.LBB4_17
.LBB4_16:
	xorpd	%xmm0, %xmm0
.LBB4_17:                               # %._crit_edge77
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	leaq	120(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$25, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	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
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$44, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	48(%rsp), %r12
	movq	56(%rsp), %rbp
	movq	64(%rsp), %r15
	movq	%r12, %rax
	subq	%r15, %rax
	cvtsi2sd	%rax, %xmm1
	movq	72(%rsp), %r13
	movsd	.LCPI4_0(%rip), %xmm0           # xmm0 = mem[0],zero
	mulsd	%xmm0, %xmm1
	movq	%rbp, %rax
	subq	%r13, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	addsd	%xmm1, %xmm0
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	mulsd	%xmm1, %xmm0
	movl	$_ZSt4cout, %edi
	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.6, %esi
	movl	$44, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%rbx), %r14
	movq	%r14, %rax
	subq	%r12, %rax
	xorps	%xmm1, %xmm1
	cvtsi2sd	%rax, %xmm1
	movq	8(%rbx), %r12
	mulsd	.LCPI4_0(%rip), %xmm1
	movq	%r12, %rax
	subq	%rbp, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	addsd	%xmm1, %xmm0
	mulsd	.LCPI4_1(%rip), %xmm0
	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
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$44, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	subq	%r15, %r14
	xorps	%xmm1, %xmm1
	cvtsi2sd	%r14, %xmm1
	mulsd	.LCPI4_0(%rip), %xmm1
	subq	%r13, %r12
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r12, %xmm0
	addsd	%xmm1, %xmm0
	mulsd	.LCPI4_1(%rip), %xmm0
	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
	leaq	112(%rsp), %rdi
	movq	$0, (%rdi)
	movl	$8, %esi
	callq	hipMalloc
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movl	$1, %esi
	movq	8(%rsp), %rdx                   # 8-byte Reload
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_19
# %bb.18:
	movq	24(%rsp), %rdi
	leaq	4(%rsp), %rsi
	callq	_Z35__device_stub__device_vector_reducePdPi
.LBB4_19:
	movabsq	$4611686018427387904, %rax      # imm = 0x4000000000000000
	leaq	104(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	24(%rsp), %rsi
	movl	$8, %edx
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$25, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movsd	(%rbx), %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
	movl	$_ZSt4cout, %edi
	movl	$.L.str.9, %esi
	movl	$20, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	4(%rsp), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	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	$136, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.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_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z18device_vector_multPdS_S_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z20device_vector_reducePdPi, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z23device_vector_simpleAddPdS_, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB6_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z18device_vector_multPdS_S_,@object # @_Z18device_vector_multPdS_S_
	.section	.rodata,"a",@progbits
	.globl	_Z18device_vector_multPdS_S_
	.p2align	3, 0x0
_Z18device_vector_multPdS_S_:
	.quad	_Z33__device_stub__device_vector_multPdS_S_
	.size	_Z18device_vector_multPdS_S_, 8

	.type	_Z20device_vector_reducePdPi,@object # @_Z20device_vector_reducePdPi
	.globl	_Z20device_vector_reducePdPi
	.p2align	3, 0x0
_Z20device_vector_reducePdPi:
	.quad	_Z35__device_stub__device_vector_reducePdPi
	.size	_Z20device_vector_reducePdPi, 8

	.type	_Z23device_vector_simpleAddPdS_,@object # @_Z23device_vector_simpleAddPdS_
	.globl	_Z23device_vector_simpleAddPdS_
	.p2align	3, 0x0
_Z23device_vector_simpleAddPdS_:
	.quad	_Z38__device_stub__device_vector_simpleAddPdS_
	.size	_Z23device_vector_simpleAddPdS_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Dot product is: "
	.size	.L.str, 17

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Time for multiplication (seconds): "
	.size	.L.str.1, 36

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Time for addition       (seconds): "
	.size	.L.str.2, 36

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Overall time            (seconds): "
	.size	.L.str.3, 36

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"GPU-mult Dot product is: "
	.size	.L.str.4, 26

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"GPU-mult Time for multiplication (seconds): "
	.size	.L.str.5, 45

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"GPU-mult Time for addition       (seconds): "
	.size	.L.str.6, 45

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"GPU-mult Overall time            (seconds): "
	.size	.L.str.7, 45

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"GPU-full Dot product is: "
	.size	.L.str.8, 26

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Size of Vectors is: "
	.size	.L.str.9, 21

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z18device_vector_multPdS_S_"
	.size	.L__unnamed_1, 29

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z20device_vector_reducePdPi"
	.size	.L__unnamed_2, 29

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z23device_vector_simpleAddPdS_"
	.size	.L__unnamed_3, 32

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.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 _Z33__device_stub__device_vector_multPdS_S_
	.addrsig_sym _Z35__device_stub__device_vector_reducePdPi
	.addrsig_sym _Z38__device_stub__device_vector_simpleAddPdS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z18device_vector_multPdS_S_
	.addrsig_sym _Z20device_vector_reducePdPi
	.addrsig_sym _Z23device_vector_simpleAddPdS_
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z18device_vector_multPdS_S_ ; -- Begin function _Z18device_vector_multPdS_S_
	.globl	_Z18device_vector_multPdS_S_
	.p2align	8
	.type	_Z18device_vector_multPdS_S_,@function
_Z18device_vector_multPdS_S_:           ; @_Z18device_vector_multPdS_S_
; %bb.0:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_lshlrev_b32_e32 v4, 3, v0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_clause 0x1
	global_load_b64 v[0:1], v4, s[4:5]
	global_load_b64 v[2:3], v4, s[6:7]
	s_waitcnt vmcnt(1)
	v_add_f64 v[0:1], v[0:1], v[0:1]
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_mul_f64 v[0:1], v[0:1], v[2:3]
	global_store_b64 v4, v[0:1], s[0:1]
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z18device_vector_multPdS_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 24
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 5
		.amdhsa_next_free_sgpr 8
		.amdhsa_reserve_vcc 0
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z18device_vector_multPdS_S_, .Lfunc_end0-_Z18device_vector_multPdS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 92
; NumSgprs: 8
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 0
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 8
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z20device_vector_reducePdPi ; -- Begin function _Z20device_vector_reducePdPi
	.globl	_Z20device_vector_reducePdPi
	.p2align	8
	.type	_Z20device_vector_reducePdPi,@function
_Z20device_vector_reducePdPi:           ; @_Z20device_vector_reducePdPi
; %bb.0:
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_load_b32 s2, s[2:3], 0x0
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s2, 2
	s_cbranch_scc1 .LBB1_5
; %bb.1:                                ; %.lr.ph
	v_lshlrev_b32_e32 v1, 3, v0
	s_mov_b32 s3, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v1, s0, s0, v1
	v_add_co_ci_u32_e64 v2, null, s1, 0, s0
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	s_lshr_b32 s0, s2, 1
	s_and_b32 s1, s2, 1
	v_cmp_gt_u32_e32 vcc_lo, s0, v0
	s_add_i32 s0, s1, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshr_b32 s2, s0, 1
	s_and_saveexec_b32 s1, vcc_lo
	s_cbranch_execz .LBB1_4
; %bb.3:                                ;   in Loop: Header=BB1_2 Depth=1
	s_lshl_b64 s[4:5], s[2:3], 3
	s_delay_alu instid0(SALU_CYCLE_1)
	v_add_co_u32 v3, vcc_lo, v1, s4
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v2, vcc_lo
	s_clause 0x1
	global_load_b64 v[3:4], v[3:4], off
	global_load_b64 v[5:6], v[1:2], off
	s_waitcnt vmcnt(0)
	v_add_f64 v[3:4], v[3:4], v[5:6]
	global_store_b64 v[1:2], v[3:4], off
.LBB1_4:                                ; %._crit_edge12
                                        ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_cmp_gt_u32 s0, 3
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB1_2
.LBB1_5:                                ; %._crit_edge
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z20device_vector_reducePdPi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 16
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 7
		.amdhsa_next_free_sgpr 6
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z20device_vector_reducePdPi, .Lfunc_end1-_Z20device_vector_reducePdPi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 184
; NumSgprs: 8
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 1
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 0
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 8
; NumVGPRsForWavesPerEU: 7
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z23device_vector_simpleAddPdS_ ; -- Begin function _Z23device_vector_simpleAddPdS_
	.globl	_Z23device_vector_simpleAddPdS_
	.p2align	8
	.type	_Z23device_vector_simpleAddPdS_,@function
_Z23device_vector_simpleAddPdS_:        ; @_Z23device_vector_simpleAddPdS_
; %bb.0:
	s_mov_b32 s2, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB2_2
; %bb.1:
	s_load_b64 s[0:1], s[0:1], 0x8
	v_dual_mov_b32 v0, 0 :: v_dual_mov_b32 v1, 2.0
	s_waitcnt lgkmcnt(0)
	global_store_b64 v0, v[0:1], s[0:1]
.LBB2_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z23device_vector_simpleAddPdS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 16
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 2
		.amdhsa_next_free_sgpr 3
		.amdhsa_reserve_vcc 0
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end2:
	.size	_Z23device_vector_simpleAddPdS_, .Lfunc_end2-_Z23device_vector_simpleAddPdS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 52
; NumSgprs: 3
; NumVgprs: 2
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 0
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 3
; NumVGPRsForWavesPerEU: 2
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.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_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 24
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z18device_vector_multPdS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     8
    .sgpr_spill_count: 0
    .symbol:         _Z18device_vector_multPdS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 16
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z20device_vector_reducePdPi
    .private_segment_fixed_size: 0
    .sgpr_count:     8
    .sgpr_spill_count: 0
    .symbol:         _Z20device_vector_reducePdPi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 16
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z23device_vector_simpleAddPdS_
    .private_segment_fixed_size: 0
    .sgpr_count:     3
    .sgpr_spill_count: 0
    .symbol:         _Z23device_vector_simpleAddPdS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     2
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
