#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<sys/time.h>

void usage(int exitStatus, char* programName);
int sumArray(int* array, int arraySize);
void getSeqPrimes(int* array, int arraySize);

__host__ __device__ int  isPrime(int value);

__global__ void getPrimes(int* d_array, int N){
    int threadId = 0;
	threadId = blockIdx.x * blockDim.x + threadIdx.x;
    int thisValue = 0;
	thisValue = (threadId * 2) + 1;

    if(threadId < 1)
    	return;

    if(thisValue < N){
		d_array[thisValue] = isPrime(thisValue);
	}
}

__host__ __device__ int isPrime(int value){

	int limit = 0;
	limit = (int) sqrt( (float) value ) + 1;
	int j = 0;
	for(j = 2; j < limit; j++){
		if(value % j == 0){
			return 0;
		}
	}
	return 1;
}


int main(int argc, char** argv){
	if(argc != 3)
		usage(1, argv[0]);

	int N = 0;
	N = (int) atoi(argv[1]);
	int blockSize = 0;
	blockSize = (int) atoi(argv[2]);

	if(!(N | blockSize))
		usage(2, argv[0]);

	int arraySizeInBytes = 0;
	arraySizeInBytes = 0;
	arraySizeInBytes = sizeof(int) * (N + 1);

	// index 0 : start time,  index 1: end time
	struct timeval sequentialTimes[2] = {{0,0},{0,0}};
	struct timeval parallelTimes[2]   = {{0,0},{0,0}};


	// allocate our arrays
	int* h_array = NULL;
	int* d_array = NULL;

	int* seqArray = NULL;
	h_array  = (int*) malloc(arraySizeInBytes);
	seqArray = (int*) calloc(sizeof(int), N + 1);

	// caculate the grid size
	int gridSize = 0;
	gridSize = (int)ceil((N + 1) / 2.0 / blockSize);

	// start parallel timer
	gettimeofday( &(parallelTimes[0]), NULL);

		// allocate device memory for the array
		cudaMalloc(&d_array, arraySizeInBytes);

		// zero the memory in cuda
		cudaMemset(d_array, 0, arraySizeInBytes);

		// run the kernel
		getPrimes<<<gridSize, blockSize>>>(d_array, N);

		// copy the results back to the host array
		cudaMemcpy(h_array, d_array, arraySizeInBytes, cudaMemcpyDeviceToHost);

		// release the device array
		cudaFree(d_array);

	// stop parallel timer
	gettimeofday( &(parallelTimes[1])  , NULL);

	// start sequential timer
	gettimeofday( &(sequentialTimes[0]), NULL);

		// run the sequential version
		getSeqPrimes(seqArray, N + 1);

	// stop sequential timer
	gettimeofday( &(sequentialTimes[1]), NULL);

	// calculated time values
	double parallelSeconds[2] = {0.0, 0.0};
	parallelSeconds[0] = parallelTimes[0].tv_sec + ((double)parallelTimes[0].tv_usec / 1000000);
	parallelSeconds[1] = parallelTimes[1].tv_sec + ((double)parallelTimes[1].tv_usec / 1000000);

	double sequentialSeconds[2] = {0.0, 0.0};
	sequentialSeconds[0] = sequentialTimes[0].tv_sec + ((double)sequentialTimes[0].tv_usec / 1000000);
	sequentialSeconds[1] = sequentialTimes[1].tv_sec + ((double)sequentialTimes[1].tv_usec / 1000000);

	double parallelCost   = 0;
	parallelCost = parallelSeconds[1] - parallelSeconds[0];
	double sequentialCost = 0;
	sequentialCost = sequentialSeconds[1] - sequentialSeconds[0];
	double speedup = 0;
	speedup = sequentialCost / parallelCost;


	int seqSum = 0;
	seqSum = sumArray(seqArray, N + 1);
	
	int parSum = 0;
	parSum = sumArray(h_array, N + 1);

	printf("                     N: %d\n",  N);
	printf("             blockSize: %d\n",  blockSize);
	printf("              gridSize: %d\n",  gridSize);
	printf("sequential prime count: %d\n",  seqSum);
	printf("  parallel prime count: %d\n",  parSum);
	printf("    parallel time cost: %lf\n", parallelCost);
	printf("  sequential time cost: %lf\n", sequentialCost);
	printf("               speedup: %lf\n", speedup);

	free(h_array);
	free(seqArray);

	return 0;
}

void getSeqPrimes(int* array, int arraySize){
	int thisValue = 0;
	for(thisValue = 3; thisValue < arraySize; thisValue += 2){
		array[thisValue] = isPrime(thisValue);
	}
}

int sumArray(int* array, int arraySize){
	int sum = 0;
	int index = 0;
	for(; index < arraySize; ++index){
		sum += array[index];
	}
	return sum;
}

void usage(int exitStatus, char* programName){
	fprintf(stderr, "usage: %s N blockSize\n", programName);
	exit(exitStatus);
}

	.file	"tmpxft_00392d57_00000000-6_lab1.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z7isPrimei
	.type	_Z7isPrimei, @function
_Z7isPrimei:
.LFB2027:
	.cfi_startproc
	endbr64
	cvtsi2ssl	%edi, %xmm0
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	%edi, %ebx
	call	sqrtf@PLT
	movl	$2, %ecx
	cvttss2sil	%xmm0, %esi
.L3:
	cmpl	%ecx, %esi
	jl	.L11
	movl	%ebx, %eax
	cltd
	idivl	%ecx
	movl	%edx, %eax
	testl	%edx, %edx
	je	.L2
	incl	%ecx
	jmp	.L3
.L11:
	movl	$1, %eax
.L2:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z7isPrimei, .-_Z7isPrimei
	.globl	_Z12getSeqPrimesPii
	.type	_Z12getSeqPrimesPii, @function
_Z12getSeqPrimesPii:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	$3, %ebx
.L13:
	movl	%ebx, %edi
	cmpl	%ebx, %ebp
	jle	.L16
	call	_Z7isPrimei
	movl	%eax, (%r12,%rbx,4)
	addq	$2, %rbx
	jmp	.L13
.L16:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z12getSeqPrimesPii, .-_Z12getSeqPrimesPii
	.globl	_Z8sumArrayPii
	.type	_Z8sumArrayPii, @function
_Z8sumArrayPii:
.LFB2030:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	xorl	%edx, %edx
.L18:
	cmpl	%eax, %esi
	jle	.L20
	addl	(%rdi,%rax,4), %edx
	incq	%rax
	jmp	.L18
.L20:
	movl	%edx, %eax
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z8sumArrayPii, .-_Z8sumArrayPii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"usage: %s N blockSize\n"
	.text
	.globl	_Z5usageiPc
	.type	_Z5usageiPc, @function
_Z5usageiPc:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	%edi, %ebx
	movq	stderr(%rip), %rdi
	movq	%rsi, %rcx
	leaq	.LC0(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	%ebx, %edi
	call	exit@PLT
	.cfi_endproc
.LFE2031:
	.size	_Z5usageiPc, .-_Z5usageiPc
	.globl	_Z29__device_stub__Z9getPrimesPiiPii
	.type	_Z29__device_stub__Z9getPrimesPiiPii, @function
_Z29__device_stub__Z9getPrimesPiiPii:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movl	%esi, 4(%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)
	leaq	4(%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	.L23
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z9getPrimesPii(%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
.L23:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z29__device_stub__Z9getPrimesPiiPii, .-_Z29__device_stub__Z9getPrimesPiiPii
	.globl	_Z9getPrimesPii
	.type	_Z9getPrimesPii, @function
_Z9getPrimesPii:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z29__device_stub__Z9getPrimesPiiPii
	.cfi_endproc
.LFE2057:
	.size	_Z9getPrimesPii, .-_Z9getPrimesPii
	.section	.rodata.str1.1
.LC3:
	.string	"                     N: %d\n"
.LC4:
	.string	"             blockSize: %d\n"
.LC5:
	.string	"              gridSize: %d\n"
.LC6:
	.string	"sequential prime count: %d\n"
.LC7:
	.string	"  parallel prime count: %d\n"
.LC8:
	.string	"    parallel time cost: %lf\n"
.LC9:
	.string	"  sequential time cost: %lf\n"
.LC10:
	.string	"               speedup: %lf\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.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
	movq	%rsi, %r12
	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
	cmpl	$3, %edi
	je	.L29
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L38
	movq	(%rsi), %rsi
	movl	$1, %edi
	jmp	.L37
.L29:
	movq	8(%rsi), %rdi
	call	atoi@PLT
	movq	16(%r12), %rdi
	movl	%eax, %ebp
	call	atoi@PLT
	movl	%eax, %ebx
	movl	%ebp, %eax
	orl	%ebx, %eax
	jne	.L31
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L38
	movq	(%r12), %rsi
	movl	$2, %edi
.L37:
	call	_Z5usageiPc
.L31:
	leal	1(%rbp), %r12d
	xorl	%eax, %eax
	leaq	64(%rsp), %rdi
	movl	$8, %ecx
	rep stosl
	leal	0(,%r12,4), %r13d
	leaq	96(%rsp), %rdi
	movl	$8, %ecx
	rep stosl
	movslq	%r13d, %r13
	xorl	%eax, %eax
	movq	%r13, %rdi
	movq	%rax, 32(%rsp)
	call	malloc@PLT
	movslq	%r12d, %rsi
	movl	$4, %edi
	movq	%rax, %r15
	call	calloc@PLT
	cvtsi2sdl	%r12d, %xmm0
	mulsd	.LC1(%rip), %xmm0
	cvtsi2sdl	%ebx, %xmm1
	movq	%rax, (%rsp)
	divsd	%xmm1, %xmm0
	call	ceil@PLT
	xorl	%esi, %esi
	leaq	96(%rsp), %rdi
	cvttsd2sil	%xmm0, %r14d
	call	gettimeofday@PLT
	leaq	32(%rsp), %rdi
	movq	%r13, %rsi
	call	cudaMalloc@PLT
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	movq	%r13, %rdx
	call	cudaMemset@PLT
	movl	%ebx, 52(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	%r14d, 40(%rsp)
	movq	%rax, 56(%rsp)
	movl	60(%rsp), %ecx
	movq	%rax, 44(%rsp)
	movq	52(%rsp), %rdx
	movq	40(%rsp), %rdi
	movl	48(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L33
	movq	32(%rsp), %rdi
	movl	%ebp, %esi
	call	_Z29__device_stub__Z9getPrimesPiiPii
.L33:
	movq	32(%rsp), %rsi
	movl	$2, %ecx
	movq	%r13, %rdx
	movq	%r15, %rdi
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%esi, %esi
	leaq	112(%rsp), %rdi
	call	gettimeofday@PLT
	xorl	%esi, %esi
	leaq	64(%rsp), %rdi
	call	gettimeofday@PLT
	movq	(%rsp), %rdi
	movl	%r12d, %esi
	call	_Z12getSeqPrimesPii
	xorl	%esi, %esi
	leaq	80(%rsp), %rdi
	call	gettimeofday@PLT
	cvtsi2sdq	120(%rsp), %xmm0
	movq	(%rsp), %rdi
	movl	%r12d, %esi
	movsd	.LC2(%rip), %xmm3
	cvtsi2sdq	112(%rsp), %xmm1
	cvtsi2sdq	96(%rsp), %xmm2
	divsd	%xmm3, %xmm0
	addsd	%xmm1, %xmm0
	cvtsi2sdq	104(%rsp), %xmm1
	divsd	%xmm3, %xmm1
	addsd	%xmm2, %xmm1
	cvtsi2sdq	80(%rsp), %xmm2
	subsd	%xmm1, %xmm0
	cvtsi2sdq	88(%rsp), %xmm1
	movsd	%xmm0, 16(%rsp)
	divsd	%xmm3, %xmm1
	addsd	%xmm2, %xmm1
	cvtsi2sdq	72(%rsp), %xmm2
	divsd	%xmm3, %xmm2
	cvtsi2sdq	64(%rsp), %xmm3
	addsd	%xmm3, %xmm2
	subsd	%xmm2, %xmm1
	movaps	%xmm1, %xmm4
	movsd	%xmm1, 24(%rsp)
	divsd	%xmm0, %xmm4
	movsd	%xmm4, 8(%rsp)
	call	_Z8sumArrayPii
	movq	%r15, %rdi
	movl	%eax, %r13d
	call	_Z8sumArrayPii
	movl	%ebp, %edx
	movl	$2, %edi
	leaq	.LC3(%rip), %rsi
	movl	%eax, %r12d
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebx, %edx
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	%r14d, %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC5(%rip), %rsi
	call	__printf_chk@PLT
	movl	%r13d, %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC6(%rip), %rsi
	call	__printf_chk@PLT
	movl	%r12d, %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC7(%rip), %rsi
	call	__printf_chk@PLT
	movsd	16(%rsp), %xmm0
	leaq	.LC8(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	call	__printf_chk@PLT
	movsd	24(%rsp), %xmm1
	leaq	.LC9(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	movaps	%xmm1, %xmm0
	call	__printf_chk@PLT
	movsd	8(%rsp), %xmm0
	leaq	.LC10(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	%r15, %rdi
	call	free@PLT
	movq	(%rsp), %rdi
	call	free@PLT
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L34
.L38:
	call	__stack_chk_fail@PLT
.L34:
	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
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC11:
	.string	"_Z9getPrimesPii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2059:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 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	.LC11(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z9getPrimesPii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	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	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2059:
	.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
.LC1:
	.long	0
	.long	1071644672
	.align 8
.LC2:
	.long	0
	.long	1093567616
	.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<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<sys/time.h>

void usage(int exitStatus, char* programName);
int sumArray(int* array, int arraySize);
void getSeqPrimes(int* array, int arraySize);

__host__ __device__ int  isPrime(int value);

__global__ void getPrimes(int* d_array, int N){
    int threadId = 0;
	threadId = blockIdx.x * blockDim.x + threadIdx.x;
    int thisValue = 0;
	thisValue = (threadId * 2) + 1;

    if(threadId < 1)
    	return;

    if(thisValue < N){
		d_array[thisValue] = isPrime(thisValue);
	}
}

__host__ __device__ int isPrime(int value){

	int limit = 0;
	limit = (int) sqrt( (float) value ) + 1;
	int j = 0;
	for(j = 2; j < limit; j++){
		if(value % j == 0){
			return 0;
		}
	}
	return 1;
}


int main(int argc, char** argv){
	if(argc != 3)
		usage(1, argv[0]);

	int N = 0;
	N = (int) atoi(argv[1]);
	int blockSize = 0;
	blockSize = (int) atoi(argv[2]);

	if(!(N | blockSize))
		usage(2, argv[0]);

	int arraySizeInBytes = 0;
	arraySizeInBytes = 0;
	arraySizeInBytes = sizeof(int) * (N + 1);

	// index 0 : start time,  index 1: end time
	struct timeval sequentialTimes[2] = {{0,0},{0,0}};
	struct timeval parallelTimes[2]   = {{0,0},{0,0}};


	// allocate our arrays
	int* h_array = NULL;
	int* d_array = NULL;

	int* seqArray = NULL;
	h_array  = (int*) malloc(arraySizeInBytes);
	seqArray = (int*) calloc(sizeof(int), N + 1);

	// caculate the grid size
	int gridSize = 0;
	gridSize = (int)ceil((N + 1) / 2.0 / blockSize);

	// start parallel timer
	gettimeofday( &(parallelTimes[0]), NULL);

		// allocate device memory for the array
		hipMalloc(&d_array, arraySizeInBytes);

		// zero the memory in cuda
		hipMemset(d_array, 0, arraySizeInBytes);

		// run the kernel
		getPrimes<<<gridSize, blockSize>>>(d_array, N);

		// copy the results back to the host array
		hipMemcpy(h_array, d_array, arraySizeInBytes, hipMemcpyDeviceToHost);

		// release the device array
		hipFree(d_array);

	// stop parallel timer
	gettimeofday( &(parallelTimes[1])  , NULL);

	// start sequential timer
	gettimeofday( &(sequentialTimes[0]), NULL);

		// run the sequential version
		getSeqPrimes(seqArray, N + 1);

	// stop sequential timer
	gettimeofday( &(sequentialTimes[1]), NULL);

	// calculated time values
	double parallelSeconds[2] = {0.0, 0.0};
	parallelSeconds[0] = parallelTimes[0].tv_sec + ((double)parallelTimes[0].tv_usec / 1000000);
	parallelSeconds[1] = parallelTimes[1].tv_sec + ((double)parallelTimes[1].tv_usec / 1000000);

	double sequentialSeconds[2] = {0.0, 0.0};
	sequentialSeconds[0] = sequentialTimes[0].tv_sec + ((double)sequentialTimes[0].tv_usec / 1000000);
	sequentialSeconds[1] = sequentialTimes[1].tv_sec + ((double)sequentialTimes[1].tv_usec / 1000000);

	double parallelCost   = 0;
	parallelCost = parallelSeconds[1] - parallelSeconds[0];
	double sequentialCost = 0;
	sequentialCost = sequentialSeconds[1] - sequentialSeconds[0];
	double speedup = 0;
	speedup = sequentialCost / parallelCost;


	int seqSum = 0;
	seqSum = sumArray(seqArray, N + 1);
	
	int parSum = 0;
	parSum = sumArray(h_array, N + 1);

	printf("                     N: %d\n",  N);
	printf("             blockSize: %d\n",  blockSize);
	printf("              gridSize: %d\n",  gridSize);
	printf("sequential prime count: %d\n",  seqSum);
	printf("  parallel prime count: %d\n",  parSum);
	printf("    parallel time cost: %lf\n", parallelCost);
	printf("  sequential time cost: %lf\n", sequentialCost);
	printf("               speedup: %lf\n", speedup);

	free(h_array);
	free(seqArray);

	return 0;
}

void getSeqPrimes(int* array, int arraySize){
	int thisValue = 0;
	for(thisValue = 3; thisValue < arraySize; thisValue += 2){
		array[thisValue] = isPrime(thisValue);
	}
}

int sumArray(int* array, int arraySize){
	int sum = 0;
	int index = 0;
	for(; index < arraySize; ++index){
		sum += array[index];
	}
	return sum;
}

void usage(int exitStatus, char* programName){
	fprintf(stderr, "usage: %s N blockSize\n", programName);
	exit(exitStatus);
}

	.text
	.file	"lab1.hip"
	.globl	_Z24__device_stub__getPrimesPii # -- Begin function _Z24__device_stub__getPrimesPii
	.type	_Z24__device_stub__getPrimesPii,@function
_Z24__device_stub__getPrimesPii:        # @_Z24__device_stub__getPrimesPii
	.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	4(%rsp), %rcx
	movl	%esi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z9getPrimesPii, %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_end0:
	.size	_Z24__device_stub__getPrimesPii, .Lfunc_end0-_Z24__device_stub__getPrimesPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z7isPrimei                     # -- Begin function _Z7isPrimei
	.type	_Z7isPrimei,@function
_Z7isPrimei:                            # @_Z7isPrimei
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%edi, %ebx
	cvtsi2ss	%edi, %xmm0
	xorps	%xmm1, %xmm1
	ucomiss	%xmm1, %xmm0
	jb	.LBB1_2
# %bb.1:
	sqrtss	%xmm0, %xmm0
	jmp	.LBB1_3
.LBB1_2:                                # %call.sqrt
	callq	sqrtf
.LBB1_3:                                # %.split
	cvttss2si	%xmm0, %esi
	movl	$1, %ecx
	cmpl	$2, %esi
	jl	.LBB1_8
# %bb.4:                                # %.lr.ph.preheader
	negl	%esi
	movl	$2, %edi
.LBB1_6:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%ebx, %eax
	cltd
	idivl	%edi
	testl	%edx, %edx
	je	.LBB1_7
# %bb.5:                                #   in Loop: Header=BB1_6 Depth=1
	leal	(%rsi,%rdi), %eax
	incl	%eax
	movl	%edi, %edx
	incl	%edx
	movl	%edx, %edi
	cmpl	$1, %eax
	jne	.LBB1_6
	jmp	.LBB1_8
.LBB1_7:
	xorl	%ecx, %ecx
.LBB1_8:                                # %._crit_edge
	movl	%ecx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z7isPrimei, .Lfunc_end1-_Z7isPrimei
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI2_0:
	.quad	0x3fe0000000000000              # double 0.5
.LCPI2_1:
	.quad	0x412e848000000000              # double 1.0E+6
	.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
	movq	%rsi, %rbx
	cmpl	$3, %edi
	jne	.LBB2_21
# %bb.1:
	movq	8(%rbx), %rdi
	callq	atoi
	movl	%eax, %r14d
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, %r15d
	orl	%r14d, %eax
	je	.LBB2_22
# %bb.2:
	leal	1(%r14), %eax
	movl	%eax, 16(%rsp)                  # 4-byte Spill
	movq	%r14, %rcx
	movq	%r14, 32(%rsp)                  # 8-byte Spill
	movslq	%eax, %r14
	leal	4(,%rcx,4), %eax
	xorps	%xmm0, %xmm0
	movaps	%xmm0, 112(%rsp)
	movaps	%xmm0, 96(%rsp)
	leaq	64(%rsp), %r13
	movaps	%xmm0, 16(%r13)
	movaps	%xmm0, (%r13)
	leaq	8(%rsp), %rcx
	movq	$0, (%rcx)
	movslq	%eax, %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %rbx
	movl	$4, %edi
	movq	%r14, %rsi
	callq	calloc
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r14d, %xmm0
	mulsd	.LCPI2_0(%rip), %xmm0
	movq	%rax, %r14
	cvtsi2sd	%r15d, %xmm1
	divsd	%xmm1, %xmm0
	callq	ceil@PLT
	cvttsd2si	%xmm0, %ebp
	movq	%r13, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	leaq	8(%rsp), %r13
	movq	%r13, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	(%r13), %rdi
	xorl	%esi, %esi
	movq	%r12, %rdx
	callq	hipMemset
	movq	%rbp, 56(%rsp)                  # 8-byte Spill
	btsq	$32, %rbp
	movl	%r15d, 28(%rsp)                 # 4-byte Spill
	movl	%r15d, %edx
	btsq	$32, %rdx
	movq	%rbp, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	movq	32(%rsp), %r15                  # 8-byte Reload
	jne	.LBB2_4
# %bb.3:
	movq	8(%rsp), %rdi
	movl	%r15d, %esi
	callq	_Z24__device_stub__getPrimesPii
.LBB2_4:
	movq	8(%rsp), %rsi
	movq	%rbx, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	callq	hipFree
	leaq	80(%rsp), %rdi
	xorl	%r13d, %r13d
	xorl	%esi, %esi
	callq	gettimeofday
	leaq	96(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movl	16(%rsp), %ebp                  # 4-byte Reload
	cmpl	$3, %r15d
	jl	.LBB2_15
# %bb.5:                                # %.lr.ph.preheader.i
	movl	$3, %r12d
	xorpd	%xmm1, %xmm1
.LBB2_6:                                # %.lr.ph.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_13 Depth 2
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r12d, %xmm0
	ucomiss	%xmm1, %xmm0
	jb	.LBB2_8
# %bb.7:                                #   in Loop: Header=BB2_6 Depth=1
	sqrtss	%xmm0, %xmm0
	jmp	.LBB2_9
.LBB2_8:                                # %call.sqrt
                                        #   in Loop: Header=BB2_6 Depth=1
	callq	sqrtf
	xorps	%xmm1, %xmm1
.LBB2_9:                                # %.lr.ph.i.split
                                        #   in Loop: Header=BB2_6 Depth=1
	cvttss2si	%xmm0, %ecx
	cmpl	$2, %ecx
	jl	.LBB2_10
# %bb.12:                               # %.lr.ph.i.i.preheader
                                        #   in Loop: Header=BB2_6 Depth=1
	negl	%ecx
	movl	$2, %esi
.LBB2_13:                               # %.lr.ph.i.i
                                        #   Parent Loop BB2_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorl	%edi, %edi
	movl	%r12d, %eax
	xorl	%edx, %edx
	divl	%esi
	testl	%edx, %edx
	je	.LBB2_14
# %bb.11:                               #   in Loop: Header=BB2_13 Depth=2
	leal	(%rcx,%rsi), %eax
	incl	%eax
	movl	%esi, %edx
	incl	%edx
	movl	%edx, %esi
	cmpl	$1, %eax
	jne	.LBB2_13
.LBB2_10:                               #   in Loop: Header=BB2_6 Depth=1
	movl	$1, %edi
.LBB2_14:                               # %_Z7isPrimei.exit.i
                                        #   in Loop: Header=BB2_6 Depth=1
	movl	%edi, (%r14,%r12,4)
	addq	$2, %r12
	cmpq	%rbp, %r12
	jb	.LBB2_6
.LBB2_15:                               # %_Z12getSeqPrimesPii.exit
	leaq	112(%rsp), %r12
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	64(%rsp), %rax
	movq	72(%rsp), %rcx
	movq	80(%rsp), %rdx
	movq	88(%rsp), %rsi
	movq	-16(%r12), %rdi
	movq	-8(%r12), %r8
	movq	(%r12), %r9
	movq	8(%r12), %r10
	movl	$0, %r12d
	testl	%r15d, %r15d
	js	.LBB2_20
# %bb.16:                               # %.lr.ph.preheader.i44
	xorl	%r11d, %r11d
	xorl	%r13d, %r13d
.LBB2_17:                               # %.lr.ph.i45
                                        # =>This Inner Loop Header: Depth=1
	addl	(%r14,%r11,4), %r13d
	incq	%r11
	cmpq	%r11, %rbp
	jne	.LBB2_17
# %bb.18:                               # %.lr.ph.i51.preheader
	xorl	%r11d, %r11d
	xorl	%r12d, %r12d
.LBB2_19:                               # %.lr.ph.i51
                                        # =>This Inner Loop Header: Depth=1
	addl	(%rbx,%r11,4), %r12d
	incq	%r11
	cmpq	%r11, %rbp
	jne	.LBB2_19
.LBB2_20:                               # %_Z8sumArrayPii.exit56
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r10, %xmm0
	movsd	.LCPI2_1(%rip), %xmm1           # xmm1 = mem[0],zero
	cvtsi2sd	%r9, %xmm3
	divsd	%xmm1, %xmm0
	addsd	%xmm0, %xmm3
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r8, %xmm0
	divsd	%xmm1, %xmm0
	cvtsi2sd	%rdi, %xmm2
	addsd	%xmm0, %xmm2
	subsd	%xmm2, %xmm3
	movsd	%xmm3, 48(%rsp)                 # 8-byte Spill
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rsi, %xmm0
	divsd	%xmm1, %xmm0
	cvtsi2sd	%rdx, %xmm4
	xorps	%xmm2, %xmm2
	cvtsi2sd	%rcx, %xmm2
	addsd	%xmm0, %xmm4
	divsd	%xmm1, %xmm2
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	addsd	%xmm2, %xmm0
	subsd	%xmm0, %xmm4
	movsd	%xmm4, 40(%rsp)                 # 8-byte Spill
	movapd	%xmm3, %xmm0
	divsd	%xmm4, %xmm0
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	movl	$.L.str, %edi
	movl	%r15d, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.1, %edi
	movl	28(%rsp), %esi                  # 4-byte Reload
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.2, %edi
	movq	56(%rsp), %rsi                  # 8-byte Reload
                                        # kill: def $esi killed $esi killed $rsi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.3, %edi
	movl	%r13d, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.4, %edi
	movl	%r12d, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.5, %edi
	movsd	40(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	movl	$.L.str.6, %edi
	movsd	48(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	movl	$.L.str.7, %edi
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	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
.LBB2_21:
	.cfi_def_cfa_offset 192
	movq	(%rbx), %rdx
	movq	stderr(%rip), %rdi
	movl	$.L.str.8, %esi
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.LBB2_22:
	movq	(%rbx), %rdx
	movq	stderr(%rip), %rdi
	movl	$.L.str.8, %esi
	xorl	%eax, %eax
	callq	fprintf
	movl	$2, %edi
	callq	exit
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z5usageiPc                     # -- Begin function _Z5usageiPc
	.type	_Z5usageiPc,@function
_Z5usageiPc:                            # @_Z5usageiPc
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rsi, %rdx
	movl	%edi, %ebx
	movq	stderr(%rip), %rdi
	movl	$.L.str.8, %esi
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebx, %edi
	callq	exit
.Lfunc_end3:
	.size	_Z5usageiPc, .Lfunc_end3-_Z5usageiPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z12getSeqPrimesPii             # -- Begin function _Z12getSeqPrimesPii
	.type	_Z12getSeqPrimesPii,@function
_Z12getSeqPrimesPii:                    # @_Z12getSeqPrimesPii
	.cfi_startproc
# %bb.0:
	cmpl	$4, %esi
	jl	.LBB4_12
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r15d
	movl	$3, %r14d
	xorps	%xmm1, %xmm1
.LBB4_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_9 Depth 2
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r14d, %xmm0
	ucomiss	%xmm1, %xmm0
	jb	.LBB4_4
# %bb.3:                                #   in Loop: Header=BB4_2 Depth=1
	sqrtss	%xmm0, %xmm0
	jmp	.LBB4_5
.LBB4_4:                                # %call.sqrt
                                        #   in Loop: Header=BB4_2 Depth=1
	callq	sqrtf
	xorps	%xmm1, %xmm1
.LBB4_5:                                # %.lr.ph.split
                                        #   in Loop: Header=BB4_2 Depth=1
	cvttss2si	%xmm0, %ecx
	cmpl	$2, %ecx
	jl	.LBB4_6
# %bb.8:                                # %.lr.ph.i.preheader
                                        #   in Loop: Header=BB4_2 Depth=1
	negl	%ecx
	movl	$2, %esi
.LBB4_9:                                # %.lr.ph.i
                                        #   Parent Loop BB4_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorl	%edi, %edi
	movl	%r14d, %eax
	xorl	%edx, %edx
	divl	%esi
	testl	%edx, %edx
	je	.LBB4_10
# %bb.7:                                #   in Loop: Header=BB4_9 Depth=2
	leal	(%rcx,%rsi), %eax
	incl	%eax
	movl	%esi, %edx
	incl	%edx
	movl	%edx, %esi
	cmpl	$1, %eax
	jne	.LBB4_9
.LBB4_6:                                #   in Loop: Header=BB4_2 Depth=1
	movl	$1, %edi
.LBB4_10:                               # %_Z7isPrimei.exit
                                        #   in Loop: Header=BB4_2 Depth=1
	movl	%edi, (%rbx,%r14,4)
	addq	$2, %r14
	cmpq	%r15, %r14
	jb	.LBB4_2
# %bb.11:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB4_12:                               # %._crit_edge
	retq
.Lfunc_end4:
	.size	_Z12getSeqPrimesPii, .Lfunc_end4-_Z12getSeqPrimesPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z8sumArrayPii                  # -- Begin function _Z8sumArrayPii
	.type	_Z8sumArrayPii,@function
_Z8sumArrayPii:                         # @_Z8sumArrayPii
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB5_1
# %bb.2:                                # %.lr.ph.preheader
	movl	%esi, %ecx
	xorl	%edx, %edx
	xorl	%eax, %eax
.LBB5_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	addl	(%rdi,%rdx,4), %eax
	incq	%rdx
	cmpq	%rdx, %rcx
	jne	.LBB5_3
# %bb.4:                                # %._crit_edge
	retq
.LBB5_1:
	xorl	%eax, %eax
	retq
.Lfunc_end5:
	.size	_Z8sumArrayPii, .Lfunc_end5-_Z8sumArrayPii
	.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:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9getPrimesPii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__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	.LBB7_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
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z9getPrimesPii,@object         # @_Z9getPrimesPii
	.section	.rodata,"a",@progbits
	.globl	_Z9getPrimesPii
	.p2align	3, 0x0
_Z9getPrimesPii:
	.quad	_Z24__device_stub__getPrimesPii
	.size	_Z9getPrimesPii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"                     N: %d\n"
	.size	.L.str, 28

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"             blockSize: %d\n"
	.size	.L.str.1, 28

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"              gridSize: %d\n"
	.size	.L.str.2, 28

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"sequential prime count: %d\n"
	.size	.L.str.3, 28

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"  parallel prime count: %d\n"
	.size	.L.str.4, 28

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"    parallel time cost: %lf\n"
	.size	.L.str.5, 29

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"  sequential time cost: %lf\n"
	.size	.L.str.6, 29

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"               speedup: %lf\n"
	.size	.L.str.7, 29

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"usage: %s N blockSize\n"
	.size	.L.str.8, 23

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z9getPrimesPii"
	.size	.L__unnamed_1, 16

	.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 _Z24__device_stub__getPrimesPii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z9getPrimesPii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9getPrimesPii         ; -- Begin function _Z9getPrimesPii
	.globl	_Z9getPrimesPii
	.p2align	8
	.type	_Z9getPrimesPii,@function
_Z9getPrimesPii:                        ; @_Z9getPrimesPii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x1c
	s_load_b32 s3, s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	v_lshlrev_b32_e32 v0, 1, v1
	v_cmp_lt_i32_e32 vcc_lo, 0, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_or_b32_e32 v2, 1, v0
	v_cmp_gt_i32_e64 s2, s3, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_8
; %bb.1:
	v_cvt_f32_i32_e32 v1, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v3, 0x4f800000, v1
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v1
	v_cndmask_b32_e32 v1, v1, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_sqrt_f32_e32 v3, v1
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v4, -1, v3
	v_add_nc_u32_e32 v5, 1, v3
	v_fma_f32 v6, -v4, v3, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v7, -v5, v3, v1
	v_cmp_ge_f32_e64 s2, 0, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v3, v3, v4, s2
	v_cmp_lt_f32_e64 s2, 0, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v3, v3, v5, s2
	s_mov_b32 s2, exec_lo
	v_mul_f32_e32 v4, 0x37800000, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v3, v3, v4, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v1, 0x260
	v_dual_mov_b32 v4, 1 :: v_dual_cndmask_b32 v1, v3, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_i32_f32_e32 v3, v1
	v_cmpx_lt_i32_e32 1, v3
	s_cbranch_execz .LBB0_7
; %bb.2:                                ; %.lr.ph.i.preheader
	v_ashrrev_i32_e32 v1, 31, v2
	v_sub_nc_u32_e32 v3, 1, v3
	s_mov_b32 s4, 2
	s_mov_b32 s3, 0
                                        ; implicit-def: $sgpr5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v2, v2, v1
	v_xor_b32_e32 v2, v2, v1
.LBB0_3:                                ; %.lr.ph.i
                                        ; =>This Inner Loop Header: Depth=1
	s_ashr_i32 s6, s4, 31
	s_or_b32 s5, s5, exec_lo
	s_add_i32 s7, s4, s6
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_xor_b32 s6, s7, s6
	v_cvt_f32_u32_e32 v4, s6
	s_sub_i32 s7, 0, s6
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v4, v4
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v4, 0x4f7ffffe, v4
	v_cvt_u32_f32_e32 v4, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v5, s7, v4
	v_mul_hi_u32 v5, v4, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v4, v4, v5
	v_mul_hi_u32 v4, v2, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v4, v4, s6
	v_sub_nc_u32_e32 v4, v2, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v5, s6, v4
	v_cmp_le_u32_e32 vcc_lo, s6, v4
	v_cndmask_b32_e32 v4, v4, v5, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v5, s6, v4
	v_cmp_le_u32_e32 vcc_lo, s6, v4
	v_cndmask_b32_e32 v4, v4, v5, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v4, v4, v1
	v_sub_nc_u32_e32 v4, v4, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, 0, v4
	v_mov_b32_e32 v4, 0
	s_and_saveexec_b32 s6, vcc_lo
; %bb.4:                                ;   in Loop: Header=BB0_3 Depth=1
	s_add_i32 s4, s4, 1
	s_and_not1_b32 s5, s5, exec_lo
	v_add_nc_u32_e32 v4, s4, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	v_cmp_eq_u32_e32 vcc_lo, 2, v4
	v_mov_b32_e32 v4, 1
	s_and_b32 s7, vcc_lo, exec_lo
	s_or_b32 s5, s5, s7
; %bb.5:                                ; %Flow
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s6
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s6, exec_lo, s5
	s_or_b32 s3, s6, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s3
	s_cbranch_execnz .LBB0_3
; %bb.6:                                ; %Flow10
	s_or_b32 exec_lo, exec_lo, s3
.LBB0_7:                                ; %Flow11
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	s_or_b32 exec_lo, exec_lo, s2
	s_load_b64 s[0:1], s[0:1], 0x0
	v_mov_b32_e32 v1, 0
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b32 v[0:1], v4, off offset:4
.LBB0_8:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9getPrimesPii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 8
		.amdhsa_next_free_sgpr 16
		.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	_Z9getPrimesPii, .Lfunc_end0-_Z9getPrimesPii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 572
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; 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
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9getPrimesPii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9getPrimesPii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
