#include <iostream>
#include <cstdlib>
#include <math.h>
#include <chrono>
#include <iomanip>
#include <fstream>
using namespace std;
using namespace std::chrono;
typedef unsigned long long ULL;
ofstream primeresult;
ofstream timeresult;

__global__ void cuda_erastothenes_sieve (ULL *marked, ULL *limit, ULL *n, int *totalThreads) {
    int index = blockIdx.x * blockDim.x + threadIdx.x;
    //printf("index %d,limit %llu , n %llu , totalThreads %d \n",index, *limit , *n , *totalThreads);
    //printf("block %d, thread %d \n", blockIdx.x, threadIdx.x);
    marked[0]=1;
    marked[1]=1;
    index=index+2;
    if(*totalThreads>*n || index >*limit){
        return ;
    }else if(*totalThreads ==1){
        for(ULL p=2;p<=*limit;p++){
            for(ULL multiple=2*p; multiple<*n; multiple+=p){
                marked[multiple]=1;
            }    
        }
    }
    else{
        //printf("index %d,limit %llu , n %llu , totalThreads %d \n",index, *limit , *n , *totalThreads);
        for(ULL p=index;p<=*limit;p+=*totalThreads){
                if(marked[p]==1 || p%2==0 && p>2) return;
                //printf("index %d , p%llu \n",index,p);
                for(ULL multiple=2*p; multiple<*n; multiple+=p){
                    //printf("multiple %llu \n",multiple);
                    marked[multiple]=1;
                }
        }
    }
    __syncthreads();
}


int main(int argc, char **argv){
    ULL size;
    ULL *list,*d_list,limit,*d_limit,*d_n,n;
    n=atoi(argv[1]);
    int threads=atoi(argv[2]);
    //int thread_per_block=atoi(argv[3]);
    int blocks= floor(n/threads);
    int totalThreads = threads;
    int *d_totalThreads; 
    primeresult.open("cudaSieveList.txt");
    timeresult.open("cudaSieveResult.txt",ios::out | ios::app );

    size = n*sizeof(ULL);
    limit = floor(sqrt(n));

    
    cudaMalloc((void**)&d_list,size);
    cudaMalloc((void**)&d_limit,sizeof(ULL));
    cudaMalloc((void**)&d_n,sizeof(ULL));
    cudaMalloc((void**)&d_totalThreads,sizeof(int));
    
    list = (ULL*) malloc(size);
 
    memset(list,0,size);
    cudaMemset(d_list, 0, size);

    cudaMemcpy(d_list           ,list           ,size           ,cudaMemcpyHostToDevice);
    cudaMemcpy(d_limit          ,&limit         ,sizeof(ULL)    ,cudaMemcpyHostToDevice);
    cudaMemcpy(d_n              ,&n             ,sizeof(ULL)    ,cudaMemcpyHostToDevice);
    cudaMemcpy(d_totalThreads   ,&totalThreads  ,sizeof(int)    ,cudaMemcpyHostToDevice);


    auto begin= std::chrono::high_resolution_clock::now();
    cuda_erastothenes_sieve<<<blocks,threads>>>(d_list,d_limit,d_n,d_totalThreads);
    auto end = std::chrono::high_resolution_clock::now();

    auto duration = duration_cast<std::chrono::microseconds>(end - begin);
    
    timeresult<<duration.count()<<endl;

    cudaMemcpy(list,d_list, size, cudaMemcpyDeviceToHost);

    cudaDeviceSynchronize();

    // check for error
    cudaError_t error = cudaGetLastError();
    if(error != cudaSuccess)
    {
      // print the CUDA error message and exit
      printf("CUDA error: %s\n", cudaGetErrorString(error));
      return 0;
    }
    
   for(ULL i=0;i<n;i++){
       if(list[i]==0){
            primeresult<<i<<endl;
            //cout<<i<<endl;
        };
    } 


    
    //cout<<duration.count()<<endl;

    free(list);
    cudaFree(d_list);
    cudaFree(d_limit);
    cudaFree(d_n);
    primeresult.close();
    timeresult.close();
    return 0;
}
	.file	"tmpxft_0025a103_00000000-6_cudaSieve.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4110:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4110:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z49__device_stub__Z23cuda_erastothenes_sievePyS_S_PiPyS_S_Pi
	.type	_Z49__device_stub__Z23cuda_erastothenes_sievePyS_S_PiPyS_S_Pi, @function
_Z49__device_stub__Z23cuda_erastothenes_sievePyS_S_PiPyS_S_Pi:
.LFB4132:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z23cuda_erastothenes_sievePyS_S_Pi(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4132:
	.size	_Z49__device_stub__Z23cuda_erastothenes_sievePyS_S_PiPyS_S_Pi, .-_Z49__device_stub__Z23cuda_erastothenes_sievePyS_S_PiPyS_S_Pi
	.globl	_Z23cuda_erastothenes_sievePyS_S_Pi
	.type	_Z23cuda_erastothenes_sievePyS_S_Pi, @function
_Z23cuda_erastothenes_sievePyS_S_Pi:
.LFB4133:
	.cfi_startproc
	endbr64
	jmp	_Z49__device_stub__Z23cuda_erastothenes_sievePyS_S_PiPyS_S_Pi
	.cfi_endproc
.LFE4133:
	.size	_Z23cuda_erastothenes_sievePyS_S_Pi, .-_Z23cuda_erastothenes_sievePyS_S_Pi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"cudaSieveList.txt"
.LC1:
	.string	"cudaSieveResult.txt"
.LC3:
	.string	"CUDA error: %s\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB4104:
	.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
	leaq	primeresult(%rip), %r14
	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
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	8(%rsi), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	call	atoi@PLT
	movq	16(%rbp), %rdi
	movslq	%eax, %rbx
	movq	%rbx, 48(%rsp)
	call	atoi@PLT
	movl	$16, %edx
	leaq	.LC0(%rip), %rsi
	movq	%r14, %rdi
	movslq	%eax, %rbp
	movl	%ebp, 12(%rsp)
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode@PLT
	movl	$17, %edx
	leaq	.LC1(%rip), %rsi
	leaq	timeresult(%rip), %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode@PLT
	movq	48(%rsp), %rax
	leaq	0(,%rax,8), %r13
	testq	%rax, %rax
	js	.L9
	cvtsi2sdq	%rax, %xmm0
	jmp	.L10
.L9:
	movq	%rax, %rdx
	andl	$1, %eax
	shrq	%rdx
	orq	%rax, %rdx
	cvtsi2sdq	%rdx, %xmm0
	addsd	%xmm0, %xmm0
.L10:
	call	sqrt@PLT
	call	trunc@PLT
	movsd	.LC2(%rip), %xmm1
	comisd	%xmm1, %xmm0
	jnb	.L11
	cvttsd2siq	%xmm0, %rax
	movq	%rax, 24(%rsp)
	jmp	.L12
.L11:
	subsd	%xmm1, %xmm0
	cvttsd2siq	%xmm0, %rax
	movq	%rax, 24(%rsp)
	btcq	$63, 24(%rsp)
.L12:
	leaq	16(%rsp), %rdi
	movq	%r13, %rsi
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movl	$8, %esi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movl	$8, %esi
	call	cudaMalloc@PLT
	movl	$4, %esi
	leaq	56(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	%r13, %rdi
	call	malloc@PLT
	movq	%r13, %rcx
	movq	%r13, %rdx
	xorl	%esi, %esi
	movq	%rax, %rdi
	movq	%rax, %r12
	call	__memset_chk@PLT
	movq	16(%rsp), %rdi
	movq	%r13, %rdx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movq	16(%rsp), %rdi
	movq	%r13, %rdx
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rdi
	leaq	24(%rsp), %rsi
	movl	$1, %ecx
	movl	$8, %edx
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rdi
	leaq	48(%rsp), %rsi
	movl	$1, %ecx
	movl	$8, %edx
	call	cudaMemcpy@PLT
	movq	56(%rsp), %rdi
	movl	$4, %edx
	leaq	12(%rsp), %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	xorl	%edx, %edx
	movl	%ebp, 76(%rsp)
	movq	%rax, %r15
	movabsq	$4294967297, %rax
	movq	%rax, 80(%rsp)
	movq	%rbx, %rax
	divq	%rbp
	testq	%rax, %rax
	js	.L13
	cvtsi2sdq	%rax, %xmm0
	jmp	.L14
.L13:
	movq	%rax, %rdx
	andl	$1, %eax
	shrq	%rdx
	orq	%rax, %rdx
	cvtsi2sdq	%rdx, %xmm0
	addsd	%xmm0, %xmm0
.L14:
	cvttsd2sil	%xmm0, %eax
	movl	84(%rsp), %ecx
	movq	76(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	%eax, 64(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 68(%rsp)
	movq	64(%rsp), %rdi
	movl	72(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L15
	movq	56(%rsp), %rcx
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	16(%rsp), %rdi
	call	_Z49__device_stub__Z23cuda_erastothenes_sievePyS_S_PiPyS_S_Pi
.L15:
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	$1000, %ecx
	leaq	timeresult(%rip), %rdi
	xorl	%ebx, %ebx
	subq	%r15, %rax
	cqto
	idivq	%rcx
	movq	%rax, %rsi
	call	_ZNSo9_M_insertIlEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	16(%rsp), %rsi
	movq	%r12, %rdi
	movq	%r13, %rdx
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	call	cudaDeviceSynchronize@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L16
	call	cudaGetErrorString@PLT
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L17
.L19:
	cmpq	$0, (%r12,%rbx,8)
	jne	.L18
	movq	%r14, %rdi
	movq	%rbx, %rsi
	call	_ZNSo9_M_insertIyEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
.L18:
	incq	%rbx
.L16:
	cmpq	48(%rsp), %rbx
	jb	.L19
	movq	%r12, %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r14, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE5closeEv@PLT
	leaq	timeresult(%rip), %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE5closeEv@PLT
.L17:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$104, %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
.LFE4104:
	.size	main, .-main
	.section	.rodata.str1.1
.LC4:
	.string	"_Z23cuda_erastothenes_sievePyS_S_Pi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4135:
	.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	.LC4(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z23cuda_erastothenes_sievePyS_S_Pi(%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
.LFE4135:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text.startup
	.type	_GLOBAL__sub_I_primeresult, @function
_GLOBAL__sub_I_primeresult:
.LFB4866:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	__dso_handle(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	leaq	primeresult(%rip), %rbx
	pushq	%rax
	.cfi_def_cfa_offset 32
	movq	%rbx, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1Ev@PLT
	movq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@GOTPCREL(%rip), %rdi
	movq	%rbp, %rdx
	movq	%rbx, %rsi
	leaq	timeresult(%rip), %rbx
	call	__cxa_atexit@PLT
	movq	%rbx, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1Ev@PLT
	movq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@GOTPCREL(%rip), %rdi
	movq	%rbp, %rdx
	popq	%rcx
	.cfi_def_cfa_offset 24
	movq	%rbx, %rsi
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	__cxa_atexit@PLT
	.cfi_endproc
.LFE4866:
	.size	_GLOBAL__sub_I_primeresult, .-_GLOBAL__sub_I_primeresult
	.section	.init_array
	.align 8
	.quad	_GLOBAL__sub_I_primeresult
	.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
	.globl	timeresult
	.bss
	.align 32
	.type	timeresult, @object
	.size	timeresult, 512
timeresult:
	.zero	512
	.globl	primeresult
	.align 32
	.type	primeresult, @object
	.size	primeresult, 512
primeresult:
	.zero	512
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC2:
	.long	0
	.long	1138753536
	.hidden	__dso_handle
	.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 <cstdlib>
#include <math.h>
#include <chrono>
#include <iomanip>
#include <fstream>
using namespace std;
using namespace std::chrono;
typedef unsigned long long ULL;
ofstream primeresult;
ofstream timeresult;

__global__ void cuda_erastothenes_sieve (ULL *marked, ULL *limit, ULL *n, int *totalThreads) {
    int index = blockIdx.x * blockDim.x + threadIdx.x;
    //printf("index %d,limit %llu , n %llu , totalThreads %d \n",index, *limit , *n , *totalThreads);
    //printf("block %d, thread %d \n", blockIdx.x, threadIdx.x);
    marked[0]=1;
    marked[1]=1;
    index=index+2;
    if(*totalThreads>*n || index >*limit){
        return ;
    }else if(*totalThreads ==1){
        for(ULL p=2;p<=*limit;p++){
            for(ULL multiple=2*p; multiple<*n; multiple+=p){
                marked[multiple]=1;
            }    
        }
    }
    else{
        //printf("index %d,limit %llu , n %llu , totalThreads %d \n",index, *limit , *n , *totalThreads);
        for(ULL p=index;p<=*limit;p+=*totalThreads){
                if(marked[p]==1 || p%2==0 && p>2) return;
                //printf("index %d , p%llu \n",index,p);
                for(ULL multiple=2*p; multiple<*n; multiple+=p){
                    //printf("multiple %llu \n",multiple);
                    marked[multiple]=1;
                }
        }
    }
    __syncthreads();
}


int main(int argc, char **argv){
    ULL size;
    ULL *list,*d_list,limit,*d_limit,*d_n,n;
    n=atoi(argv[1]);
    int threads=atoi(argv[2]);
    //int thread_per_block=atoi(argv[3]);
    int blocks= floor(n/threads);
    int totalThreads = threads;
    int *d_totalThreads; 
    primeresult.open("cudaSieveList.txt");
    timeresult.open("cudaSieveResult.txt",ios::out | ios::app );

    size = n*sizeof(ULL);
    limit = floor(sqrt(n));

    
    hipMalloc((void**)&d_list,size);
    hipMalloc((void**)&d_limit,sizeof(ULL));
    hipMalloc((void**)&d_n,sizeof(ULL));
    hipMalloc((void**)&d_totalThreads,sizeof(int));
    
    list = (ULL*) malloc(size);
 
    memset(list,0,size);
    hipMemset(d_list, 0, size);

    hipMemcpy(d_list           ,list           ,size           ,hipMemcpyHostToDevice);
    hipMemcpy(d_limit          ,&limit         ,sizeof(ULL)    ,hipMemcpyHostToDevice);
    hipMemcpy(d_n              ,&n             ,sizeof(ULL)    ,hipMemcpyHostToDevice);
    hipMemcpy(d_totalThreads   ,&totalThreads  ,sizeof(int)    ,hipMemcpyHostToDevice);


    auto begin= std::chrono::high_resolution_clock::now();
    cuda_erastothenes_sieve<<<blocks,threads>>>(d_list,d_limit,d_n,d_totalThreads);
    auto end = std::chrono::high_resolution_clock::now();

    auto duration = duration_cast<std::chrono::microseconds>(end - begin);
    
    timeresult<<duration.count()<<endl;

    hipMemcpy(list,d_list, size, hipMemcpyDeviceToHost);

    hipDeviceSynchronize();

    // check for error
    hipError_t error = hipGetLastError();
    if(error != hipSuccess)
    {
      // print the CUDA error message and exit
      printf("CUDA error: %s\n", hipGetErrorString(error));
      return 0;
    }
    
   for(ULL i=0;i<n;i++){
       if(list[i]==0){
            primeresult<<i<<endl;
            //cout<<i<<endl;
        };
    } 


    
    //cout<<duration.count()<<endl;

    free(list);
    hipFree(d_list);
    hipFree(d_limit);
    hipFree(d_n);
    primeresult.close();
    timeresult.close();
    return 0;
}
	.text
	.file	"cudaSieve.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z38__device_stub__cuda_erastothenes_sievePyS_S_Pi # -- Begin function _Z38__device_stub__cuda_erastothenes_sievePyS_S_Pi
	.type	_Z38__device_stub__cuda_erastothenes_sievePyS_S_Pi,@function
_Z38__device_stub__cuda_erastothenes_sievePyS_S_Pi: # @_Z38__device_stub__cuda_erastothenes_sievePyS_S_Pi
	.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), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	16(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%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	$_Z23cuda_erastothenes_sievePyS_S_Pi, %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_end0:
	.size	_Z38__device_stub__cuda_erastothenes_sievePyS_S_Pi, .Lfunc_end0-_Z38__device_stub__cuda_erastothenes_sievePyS_S_Pi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	1127219200                      # 0x43300000
	.long	1160773632                      # 0x45300000
	.long	0                               # 0x0
	.long	0                               # 0x0
.LCPI1_1:
	.quad	0x4330000000000000              # double 4503599627370496
	.quad	0x4530000000000000              # double 1.9342813113834067E+25
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI1_2:
	.quad	0x43e0000000000000              # double 9.2233720368547758E+18
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.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, %r14
	movq	8(%rsi), %rdi
	callq	atoi
	movslq	%eax, %rbx
	leaq	8(%rsp), %rax
	movq	%rbx, (%rax)
	movq	16(%r14), %rdi
	callq	atoi
	movslq	%eax, %r12
	movq	%rbx, %rax
	xorl	%edx, %edx
	divq	%r12
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	leaq	28(%rsp), %rax
	movl	%r12d, (%rax)
	movl	$primeresult, %edi
	movl	$.L.str, %esi
	movl	$16, %edx
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode
	movl	$timeresult, %edi
	movl	$.L.str.2, %esi
	movl	$17, %edx
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode
	movq	%rbx, %xmm0
	shlq	$3, %rbx
	punpckldq	.LCPI1_0(%rip), %xmm0   # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
	subpd	.LCPI1_1(%rip), %xmm0
	movapd	%xmm0, %xmm1
	unpckhpd	%xmm0, %xmm1                    # xmm1 = xmm1[1],xmm0[1]
	addsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	sqrtsd	%xmm1, %xmm0
	callq	floor@PLT
	cvttsd2si	%xmm0, %rax
	movq	%rax, %rcx
	sarq	$63, %rcx
	subsd	.LCPI1_2(%rip), %xmm0
	cvttsd2si	%xmm0, %rdx
	andq	%rcx, %rdx
	orq	%rax, %rdx
	leaq	64(%rsp), %rax
	movq	%rdx, (%rax)
	leaq	16(%rsp), %rbp
	movq	%rbp, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	leaq	48(%rsp), %r15
	movl	$8, %esi
	movq	%r15, %rdi
	callq	hipMalloc
	leaq	40(%rsp), %r13
	movl	$8, %esi
	movq	%r13, %rdi
	callq	hipMalloc
	leaq	32(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	movl	$1, %edi
	movq	%rbx, %rsi
	callq	calloc@PLT
	movq	%rax, %r14
	movq	(%rbp), %rdi
	xorl	%esi, %esi
	movq	%rbx, %rdx
	callq	hipMemset
	movq	(%rbp), %rdi
	movq	%r14, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r15), %rdi
	movl	$8, %edx
	leaq	64(%rsp), %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r13), %rdi
	movl	$8, %edx
	leaq	8(%rsp), %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	32(%rsp), %rax
	movq	(%rax), %rdi
	movl	$4, %edx
	leaq	28(%rsp), %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %r15
	movl	56(%rsp), %edi                  # 4-byte Reload
	btsq	$32, %rdi
	movl	%r12d, %edx
	btsq	$32, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_2
# %bb.1:
	movq	16(%rsp), %rdi
	movq	48(%rsp), %rsi
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rcx
	callq	_Z38__device_stub__cuda_erastothenes_sievePyS_S_Pi
.LBB1_2:
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%r15, %rax
	movabsq	$2361183241434822607, %rcx      # imm = 0x20C49BA5E353F7CF
	imulq	%rcx
	movq	%rdx, %rsi
	shrq	$63, %rsi
	sarq	$7, %rdx
	addq	%rdx, %rsi
	movl	$timeresult, %edi
	callq	_ZNSo9_M_insertIlEERSoT_
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	16(%rsp), %rsi
	movq	%r14, %rdi
	movq	%rbx, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	callq	hipDeviceSynchronize
	callq	hipGetLastError
	testl	%eax, %eax
	je	.LBB1_3
# %bb.9:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_10
.LBB1_3:                                # %.preheader
	movq	8(%rsp), %rax
	testq	%rax, %rax
	je	.LBB1_8
# %bb.4:                                # %.lr.ph.preheader
	xorl	%ebx, %ebx
.LBB1_5:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	cmpq	$0, (%r14,%rbx,8)
	jne	.LBB1_7
# %bb.6:                                #   in Loop: Header=BB1_5 Depth=1
	movl	$primeresult, %edi
	movq	%rbx, %rsi
	callq	_ZNSo9_M_insertIyEERSoT_
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	8(%rsp), %rax
.LBB1_7:                                #   in Loop: Header=BB1_5 Depth=1
	incq	%rbx
	cmpq	%rax, %rbx
	jb	.LBB1_5
.LBB1_8:                                # %._crit_edge
	movq	%r14, %rdi
	callq	free
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movl	$primeresult, %edi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE5closeEv
	movl	$timeresult, %edi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE5closeEv
.LBB1_10:
	xorl	%eax, %eax
	addq	$72, %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_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.section	.text.startup,"ax",@progbits
	.type	_GLOBAL__sub_I_cudaSieve.hip,@function # -- Begin function _GLOBAL__sub_I_cudaSieve.hip
_GLOBAL__sub_I_cudaSieve.hip:           # @_GLOBAL__sub_I_cudaSieve.hip
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$primeresult, %edi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1Ev
	movl	$_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev, %edi
	movl	$primeresult, %esi
	movl	$__dso_handle, %edx
	callq	__cxa_atexit
	movl	$timeresult, %edi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1Ev
	movl	$_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev, %edi
	movl	$timeresult, %esi
	movl	$__dso_handle, %edx
	popq	%rax
	.cfi_def_cfa_offset 8
	jmp	__cxa_atexit                    # TAILCALL
.Lfunc_end2:
	.size	_GLOBAL__sub_I_cudaSieve.hip, .Lfunc_end2-_GLOBAL__sub_I_cudaSieve.hip
	.cfi_endproc
                                        # -- End function
	.text
	.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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z23cuda_erastothenes_sievePyS_S_Pi, %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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	primeresult,@object             # @primeresult
	.bss
	.globl	primeresult
	.p2align	3, 0x0
primeresult:
	.zero	512
	.size	primeresult, 512

	.hidden	__dso_handle
	.type	timeresult,@object              # @timeresult
	.globl	timeresult
	.p2align	3, 0x0
timeresult:
	.zero	512
	.size	timeresult, 512

	.type	_Z23cuda_erastothenes_sievePyS_S_Pi,@object # @_Z23cuda_erastothenes_sievePyS_S_Pi
	.section	.rodata,"a",@progbits
	.globl	_Z23cuda_erastothenes_sievePyS_S_Pi
	.p2align	3, 0x0
_Z23cuda_erastothenes_sievePyS_S_Pi:
	.quad	_Z38__device_stub__cuda_erastothenes_sievePyS_S_Pi
	.size	_Z23cuda_erastothenes_sievePyS_S_Pi, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"cudaSieveList.txt"
	.size	.L.str, 18

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"cudaSieveResult.txt"
	.size	.L.str.2, 20

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"CUDA error: %s\n"
	.size	.L.str.3, 16

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z23cuda_erastothenes_sievePyS_S_Pi"
	.size	.L__unnamed_1, 36

	.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	_GLOBAL__sub_I_cudaSieve.hip
	.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 _Z38__device_stub__cuda_erastothenes_sievePyS_S_Pi
	.addrsig_sym _GLOBAL__sub_I_cudaSieve.hip
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym primeresult
	.addrsig_sym __dso_handle
	.addrsig_sym timeresult
	.addrsig_sym _Z23cuda_erastothenes_sievePyS_S_Pi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z23cuda_erastothenes_sievePyS_S_Pi ; -- Begin function _Z23cuda_erastothenes_sievePyS_S_Pi
	.globl	_Z23cuda_erastothenes_sievePyS_S_Pi
	.p2align	8
	.type	_Z23cuda_erastothenes_sievePyS_S_Pi,@function
_Z23cuda_erastothenes_sievePyS_S_Pi:    ; @_Z23cuda_erastothenes_sievePyS_S_Pi
; %bb.0:
	s_load_b256 s[4:11], s[0:1], 0x0
	v_dual_mov_b32 v1, 1 :: v_dual_mov_b32 v2, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_dual_mov_b32 v3, v1 :: v_dual_mov_b32 v4, v2
	s_waitcnt lgkmcnt(0)
	global_store_b128 v2, v[1:4], s[4:5]
	global_load_b64 v[3:4], v2, s[8:9]
	s_load_b32 s2, s[10:11], 0x0
	s_waitcnt lgkmcnt(0)
	s_ashr_i32 s3, s2, 31
	s_waitcnt vmcnt(0)
	v_cmp_gt_u64_e32 vcc_lo, s[2:3], v[3:4]
	s_cbranch_vccnz .LBB0_25
; %bb.1:
	global_load_b64 v[1:2], v2, s[6:7]
	s_load_b32 s0, s[0:1], 0x2c
	s_waitcnt lgkmcnt(0)
	s_and_b32 s0, s0, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	s_mul_i32 s15, s15, s0
	s_mov_b32 s0, exec_lo
	v_add3_u32 v5, v0, s15, 2
	v_ashrrev_i32_e32 v6, 31, v5
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_ge_u64_e64 v[1:2], v[5:6]
	s_cbranch_execz .LBB0_25
; %bb.2:
	s_cmp_eq_u32 s2, 1
	s_cbranch_scc1 .LBB0_14
; %bb.3:                                ; %.lr.ph50.preheader
	v_lshlrev_b64 v[11:12], 4, v[5:6]
	v_lshlrev_b64 v[7:8], 3, v[5:6]
	v_dual_mov_b32 v10, 0 :: v_dual_mov_b32 v9, 1
	v_dual_mov_b32 v16, v2 :: v_dual_mov_b32 v15, v1
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_u32 v11, vcc_lo, s4, v11
	v_add_co_ci_u32_e32 v12, vcc_lo, s5, v12, vcc_lo
	v_dual_mov_b32 v14, v4 :: v_dual_mov_b32 v13, v3
	s_lshl_b64 s[10:11], s[2:3], 4
	s_lshl_b64 s[12:13], s[2:3], 3
	s_mov_b32 s14, 0
                                        ; implicit-def: $sgpr1
                                        ; implicit-def: $sgpr15
                                        ; implicit-def: $sgpr16
.LBB0_4:                                ; %.lr.ph50
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_8 Depth 2
	v_lshlrev_b64 v[17:18], 3, v[5:6]
	s_or_b32 s16, s16, exec_lo
	s_or_b32 s15, s15, exec_lo
	s_mov_b32 s17, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v17, vcc_lo, s4, v17
	v_add_co_ci_u32_e32 v18, vcc_lo, s5, v18, vcc_lo
	global_load_b64 v[17:18], v[17:18], off
	s_waitcnt vmcnt(0)
	v_cmpx_ne_u64_e32 1, v[17:18]
	s_cbranch_execz .LBB0_12
; %bb.5:                                ;   in Loop: Header=BB0_4 Depth=1
	v_and_b32_e32 v0, 1, v5
	v_cmp_gt_u64_e32 vcc_lo, 3, v[5:6]
	s_mov_b32 s19, -1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_eq_u32_e64 s0, 1, v0
	s_or_b32 s20, vcc_lo, s0
	s_mov_b32 s0, -1
	s_and_saveexec_b32 s18, s20
	s_cbranch_execz .LBB0_11
; %bb.6:                                ;   in Loop: Header=BB0_4 Depth=1
	v_lshlrev_b64 v[17:18], 1, v[5:6]
	s_mov_b32 s19, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_lt_u64_e64 v[17:18], v[13:14]
	s_cbranch_execz .LBB0_10
; %bb.7:                                ; %.lr.ph.preheader
                                        ;   in Loop: Header=BB0_4 Depth=1
	v_dual_mov_b32 v16, v12 :: v_dual_mov_b32 v15, v11
	s_mov_b32 s20, 0
.LBB0_8:                                ; %.lr.ph
                                        ;   Parent Loop BB0_4 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	global_store_b64 v[15:16], v[9:10], off
	global_load_b64 v[13:14], v10, s[8:9]
	v_add_co_u32 v17, vcc_lo, v17, v5
	v_add_co_ci_u32_e32 v18, vcc_lo, v18, v6, vcc_lo
	v_add_co_u32 v15, s0, v15, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v16, s0, v16, v8, s0
	s_waitcnt vmcnt(0)
	v_cmp_ge_u64_e32 vcc_lo, v[17:18], v[13:14]
	s_or_b32 s20, vcc_lo, s20
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s20
	s_cbranch_execnz .LBB0_8
; %bb.9:                                ; %._crit_edge.loopexit
                                        ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s20
	global_load_b64 v[15:16], v10, s[6:7]
.LBB0_10:                               ; %Flow
                                        ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s19
	v_add_co_u32 v5, vcc_lo, v5, s2
	v_add_co_ci_u32_e32 v6, vcc_lo, s3, v6, vcc_lo
	v_add_co_u32 v11, vcc_lo, v11, s10
	v_add_co_ci_u32_e32 v12, vcc_lo, s11, v12, vcc_lo
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cmp_gt_u64_e32 vcc_lo, v[5:6], v[15:16]
	v_add_co_u32 v7, s0, v7, s12
	v_add_co_ci_u32_e64 v8, s0, s13, v8, s0
	s_xor_b32 s0, exec_lo, -1
	s_or_not1_b32 s19, vcc_lo, exec_lo
.LBB0_11:                               ; %Flow91
                                        ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s18
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 s16, s16, exec_lo
	s_and_b32 s0, s0, exec_lo
	s_and_not1_b32 s15, s15, exec_lo
	s_and_b32 s18, s19, exec_lo
	s_or_b32 s16, s16, s0
	s_or_b32 s15, s15, s18
.LBB0_12:                               ; %Flow90
                                        ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s17
	s_xor_b32 s0, s16, -1
	s_and_b32 s17, exec_lo, s15
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_or_b32 s14, s17, s14
	s_and_not1_b32 s1, s1, exec_lo
	s_and_b32 s0, s0, exec_lo
	s_or_b32 s1, s1, s0
	s_and_not1_b32 exec_lo, exec_lo, s14
	s_cbranch_execnz .LBB0_4
; %bb.13:                               ; %loop.exit.guard
	s_or_b32 exec_lo, exec_lo, s14
	s_mov_b32 s0, 0
	s_branch .LBB0_15
.LBB0_14:
	s_mov_b32 s0, -1
	s_mov_b32 s1, 0
.LBB0_15:                               ; %Flow96
	s_and_b32 vcc_lo, exec_lo, s0
	s_cbranch_vccz .LBB0_23
; %bb.16:                               ; %.preheader
	v_cmp_gt_u64_e32 vcc_lo, 2, v[1:2]
	s_mov_b64 s[0:1], 2
	s_cbranch_vccnz .LBB0_22
; %bb.17:                               ; %.lr.ph57.preheader
	v_dual_mov_b32 v6, 0 :: v_dual_mov_b32 v5, 1
	s_add_u32 s2, s4, 32
	s_addc_u32 s3, s5, 0
	s_mov_b64 s[4:5], 16
.LBB0_18:                               ; %.lr.ph57
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_19 Depth 2
	s_lshl_b64 s[10:11], s[0:1], 1
	s_mov_b64 s[12:13], s[2:3]
	v_cmp_ge_u64_e32 vcc_lo, s[10:11], v[3:4]
	s_cbranch_vccnz .LBB0_21
.LBB0_19:                               ; %.lr.ph53
                                        ;   Parent Loop BB0_18 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	global_store_b64 v6, v[5:6], s[12:13]
	global_load_b64 v[3:4], v6, s[8:9]
	s_add_u32 s10, s10, s0
	s_addc_u32 s11, s11, s1
	s_add_u32 s12, s12, s4
	s_addc_u32 s13, s13, s5
	s_waitcnt vmcnt(0)
	v_cmp_ge_u64_e32 vcc_lo, s[10:11], v[3:4]
	s_cbranch_vccz .LBB0_19
; %bb.20:                               ; %._crit_edge54.loopexit
                                        ;   in Loop: Header=BB0_18 Depth=1
	global_load_b64 v[1:2], v6, s[6:7]
.LBB0_21:                               ; %._crit_edge54
                                        ;   in Loop: Header=BB0_18 Depth=1
	s_add_u32 s0, s0, 1
	s_addc_u32 s1, s1, 0
	s_add_u32 s2, s2, 16
	s_waitcnt vmcnt(0)
	v_cmp_gt_u64_e32 vcc_lo, s[0:1], v[1:2]
	s_addc_u32 s3, s3, 0
	s_add_u32 s4, s4, 8
	s_addc_u32 s5, s5, 0
	s_cbranch_vccz .LBB0_18
.LBB0_22:                               ; %Flow94
	s_mov_b32 s1, -1
.LBB0_23:                               ; %Flow97
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 exec_lo, exec_lo, s1
	s_cbranch_execz .LBB0_25
; %bb.24:                               ; %.critedge
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
.LBB0_25:                               ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z23cuda_erastothenes_sievePyS_S_Pi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 19
		.amdhsa_next_free_sgpr 21
		.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	_Z23cuda_erastothenes_sievePyS_S_Pi, .Lfunc_end0-_Z23cuda_erastothenes_sievePyS_S_Pi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 788
; NumSgprs: 23
; NumVgprs: 19
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 23
; NumVGPRsForWavesPerEU: 19
; 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
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z23cuda_erastothenes_sievePyS_S_Pi
    .private_segment_fixed_size: 0
    .sgpr_count:     23
    .sgpr_spill_count: 0
    .symbol:         _Z23cuda_erastothenes_sievePyS_S_Pi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     19
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
