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


struct timeval startTime, stopTime;
int started = 0;

void start_timer() {
 started = 1;
 gettimeofday(&startTime, NULL);
}

double stop_timer() {
 long seconds, useconds;
 double duration = -1;

 if (started) {
   gettimeofday(&stopTime, NULL);
   seconds  = stopTime.tv_sec  - startTime.tv_sec;
   useconds = stopTime.tv_usec - startTime.tv_usec;
   duration = (seconds * 1000.0) + (useconds / 1000.0);
   started = 0;
 }
 return duration;
}




void  printprimes(int limit, int *arr) {
  int c;
  //#pragma omp parallel for shared(arr, limit) private(c)
  for(c = 2; c <limit; c++) {
      if(arr[c] == 0) {
          fprintf(stdout,"%d ", c);
      }
  }
  fprintf(stdout,"\n");
  /* code */
}



__global__ void init(int *arr, int sqroot, int limit) {
  int c;
  for(c = 2; c <= sqroot; c++) {
      if(arr[c] == 0) {
          /*
          #pragma omp parallel for shared(arr, limit, c) private(m)
          for(m = c+1; m < limit; m++) {
              if(m%c == 0) {
                  arr[m] = 1;
              }
          }
          */
          int tid = c+1+ threadIdx.x + (blockIdx.x * blockDim.x);
          if (tid<limit){
            if (tid % c ==0) {
          		arr[tid] = 1;
          	}
          }


      }
  }
}

double getThreadAndInfo(cudaDeviceProp devProp)
{
  /*
    printf("Major revision number:         %d\n",  devProp.major);
    printf("Minor revision number:         %d\n",  devProp.minor);
    printf("Name:                          %s\n",  devProp.name);
    printf("Total global memory:           %lu\n",  devProp.totalGlobalMem);
    printf("Total shared memory per block: %lu\n",  devProp.sharedMemPerBlock);
    printf("Total registers per block:     %d\n",  devProp.regsPerBlock);
    printf("Warp size:                     %d\n",  devProp.warpSize);
    printf("Maximum memory pitch:          %lu\n",  devProp.memPitch);
    printf("Maximum threads per block:     %i\n",  devProp.maxThreadsPerBlock);
    for (int i = 0; i < 3; ++i)
    printf("Maximum dimension %d of block:  %d\n", i, devProp.maxThreadsDim[i]);
    for (int i = 0; i < 3; ++i)
    printf("Maximum dimension %d of grid:   %d\n", i, devProp.maxGridSize[i]);
    printf("Clock rate:                    %d\n",  devProp.clockRate);
    printf("Total constant memory:         %lu\n",  devProp.totalConstMem);
    printf("Texture alignment:             %lu\n",  devProp.textureAlignment);
    printf("Concurrent copy and execution: %s\n",  (devProp.deviceOverlap ? "Yes" : "No"));
    printf("Number of multiprocessors:     %d\n",  devProp.multiProcessorCount);
    printf("Kernel execution timeout:      %s\n",  (devProp.kernelExecTimeoutEnabled ? "Yes" : "No"));
    */
    return devProp.maxThreadsPerBlock;
}

int main(int argc, char **argv) {
    // Number of CUDA devices
    int threads=1000000;
    int devCount;
    cudaGetDeviceCount(&devCount);
    //printf("CUDA Device Query...\n");
    //printf("There are %d CUDA devices.\n", devCount);

    // Iterate through devices
    for (int i = 0; i < devCount; ++i)
    {
        // Get device properties
        //printf("\nCUDA Device #%d\n", i);
        cudaDeviceProp devProp;
       cudaGetDeviceProperties(&devProp, i);
       if (getThreadAndInfo(devProp)<threads){
         threads=getThreadAndInfo(devProp);
       }

    }

    int N=10;
    int limit ;
    if (argc>3){
      fprintf(stderr, "Error: uso: %s [limite_superior_positivo]\n", argv[0]);
      return -1;

    }else if (argc==2 || argc==3) {
      int parsed=atoi(argv[1]);
      if (parsed<0){
        fprintf(stderr, "Error: uso: %s [limite_superior_positivo]\n", argv[0]);
        return -1;
      }else{
        limit=parsed;
      }
      if (argc==3) {
        N=1;
      }
    }else {
      limit=16;
    }




      int *arr;

      double ms;
      ms = 0;
      int i;
      int *p_array;
      for (i = 0; i < N; i++) {
        start_timer();
        //->
        int sqroot = (int)sqrt(limit);
        arr = (int*)malloc(limit * sizeof(int));
        cudaMalloc((void**) &p_array, limit * sizeof(int));
        cudaMemset(p_array, 0, limit*sizeof(int));
        if (limit<=threads){
		threads=limit;
          init<<<1, threads>>>(p_array, sqroot, limit);
        }else{
          init<<<int(limit/threads)+1, threads>>>(p_array, sqroot, limit);
        }



        cudaMemcpy(arr, p_array, limit * sizeof(int), cudaMemcpyDeviceToHost);

        //->
        ms += stop_timer();
      }


      if (argc==2){
        printf("times %i - avg time = %.5lf ms, %i threads\n",N,(ms / N), threads);
      }






      //




          printprimes(limit, arr);



      free(arr);

  cudaFree(p_array);


    return 0;
}


	.file	"tmpxft_0026d902_00000000-6_sieve.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	_Z11start_timerv
	.type	_Z11start_timerv, @function
_Z11start_timerv:
.LFB2027:
	.cfi_startproc
	endbr64
	xorl	%esi, %esi
	leaq	startTime(%rip), %rdi
	movl	$1, started(%rip)
	jmp	gettimeofday@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z11start_timerv, .-_Z11start_timerv
	.globl	_Z10stop_timerv
	.type	_Z10stop_timerv, @function
_Z10stop_timerv:
.LFB2028:
	.cfi_startproc
	endbr64
	cmpl	$0, started(%rip)
	movsd	.LC0(%rip), %xmm0
	je	.L7
	pushq	%rax
	.cfi_def_cfa_offset 16
	xorl	%esi, %esi
	leaq	stopTime(%rip), %rdi
	call	gettimeofday@PLT
	movq	stopTime(%rip), %rax
	subq	startTime(%rip), %rax
	xorl	%edx, %edx
	cvtsi2sdq	%rax, %xmm0
	movq	8+stopTime(%rip), %rax
	subq	8+startTime(%rip), %rax
	movl	%edx, started(%rip)
	cvtsi2sdq	%rax, %xmm1
	movsd	.LC1(%rip), %xmm2
	popq	%rcx
	.cfi_def_cfa_offset 8
	mulsd	%xmm2, %xmm0
	divsd	%xmm2, %xmm1
	addsd	%xmm1, %xmm0
	ret
.L7:
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z10stop_timerv, .-_Z10stop_timerv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"%d "
.LC3:
	.string	"\n"
	.text
	.globl	_Z11printprimesiPi
	.type	_Z11printprimesiPi, @function
_Z11printprimesiPi:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC2(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	$2, %ebx
	pushq	%r8
	.cfi_def_cfa_offset 48
.L12:
	movq	stdout(%rip), %rdi
	cmpl	%ebx, %ebp
	jle	.L16
	cmpl	$0, (%r12,%rbx,4)
	jne	.L13
	movl	%ebx, %ecx
	movq	%r13, %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L13:
	incq	%rbx
	jmp	.L12
.L16:
	popq	%rcx
	.cfi_def_cfa_offset 40
	leaq	.LC3(%rip), %rdx
	popq	%rbx
	.cfi_def_cfa_offset 32
	movl	$2, %esi
	popq	%rbp
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	__fprintf_chk@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z11printprimesiPi, .-_Z11printprimesiPi
	.globl	_Z16getThreadAndInfo14cudaDeviceProp
	.type	_Z16getThreadAndInfo14cudaDeviceProp, @function
_Z16getThreadAndInfo14cudaDeviceProp:
.LFB2030:
	.cfi_startproc
	endbr64
	cvtsi2sdl	328(%rsp), %xmm0
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z16getThreadAndInfo14cudaDeviceProp, .-_Z16getThreadAndInfo14cudaDeviceProp
	.globl	_Z25__device_stub__Z4initPiiiPiii
	.type	_Z25__device_stub__Z4initPiiiPiii, @function
_Z25__device_stub__Z4initPiiiPiii:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	32(%rsp), %rdi
	movl	%esi, 4(%rsp)
	leaq	44(%rsp), %rsi
	movl	%edx, (%rsp)
	leaq	16(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L18
	pushq	24(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z4initPiii(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 144
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L18:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z25__device_stub__Z4initPiiiPiii, .-_Z25__device_stub__Z4initPiiiPiii
	.globl	_Z4initPiii
	.type	_Z4initPiii, @function
_Z4initPiii:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z25__device_stub__Z4initPiiiPiii
	.cfi_endproc
.LFE2057:
	.size	_Z4initPiii, .-_Z4initPiii
	.section	.rodata.str1.1
.LC5:
	.string	"Error: uso: %s [limite_superior_positivo]\n"
.LC6:
	.string	"times %i - avg time = %.5lf ms, %i threads\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2031:
	.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
	movl	%edi, %r13d
	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
	movl	$1000000, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$1128, %rsp
	.cfi_def_cfa_offset 1184
	movq	%fs:40, %rax
	movq	%rax, 1112(%rsp)
	xorl	%eax, %eax
	leaq	44(%rsp), %rdi
	leaq	80(%rsp), %r14
	call	cudaGetDeviceCount@PLT
.L24:
	cmpl	%ebx, 44(%rsp)
	jle	.L41
	movl	%ebx, %esi
	movq	%r14, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movl	400(%rsp), %eax
	cmpl	%eax, %ebp
	cmovg	%eax, %ebp
	incl	%ebx
	jmp	.L24
.L41:
	cmpl	$3, %r13d
	jle	.L26
.L29:
	movq	(%r12), %rcx
	movq	stderr(%rip), %rdi
	leaq	.LC5(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	orl	$-1, %eax
	jmp	.L23
.L26:
	leal	-2(%r13), %eax
	cmpl	$1, %eax
	ja	.L37
	movq	8(%r12), %rdi
	call	atoi@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	js	.L29
	xorl	%r12d, %r12d
	cmpl	$3, %r13d
	setne	%r12b
	leal	1(%r12,%r12,8), %r12d
	jmp	.L28
.L37:
	movl	$16, %ebx
	movl	$10, %r12d
.L28:
	movq	$0x000000000, 8(%rsp)
	movslq	%ebx, %rax
	xorl	%r15d, %r15d
	movabsq	$4294967297, %r14
	salq	$2, %rax
	movq	%rax, (%rsp)
.L34:
	call	_Z11start_timerv
	cvtsi2sdl	%ebx, %xmm0
	call	sqrt@PLT
	movq	(%rsp), %rdi
	cvttsd2sil	%xmm0, %eax
	movl	%eax, 28(%rsp)
	call	malloc@PLT
	movq	(%rsp), %rsi
	leaq	48(%rsp), %rdi
	movq	%rax, 16(%rsp)
	call	cudaMalloc@PLT
	movq	(%rsp), %rdx
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaMemset@PLT
	cmpl	%ebp, %ebx
	jg	.L30
	movq	%r14, 72(%rsp)
	movl	76(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	%ebx, 68(%rsp)
	movq	68(%rsp), %rdx
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r14, 56(%rsp)
	movl	$1, 64(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	movl	28(%rsp), %esi
	movq	48(%rsp), %rdi
	movl	%ebx, %edx
	call	_Z25__device_stub__Z4initPiiiPiii
.L31:
	movl	%ebx, %ebp
	jmp	.L32
.L30:
	movl	%ebx, %eax
	movq	%r14, 72(%rsp)
	movl	76(%rsp), %ecx
	xorl	%r9d, %r9d
	cltd
	movq	%r14, 60(%rsp)
	movl	64(%rsp), %esi
	xorl	%r8d, %r8d
	idivl	%ebp
	movl	%ebp, 68(%rsp)
	movq	68(%rsp), %rdx
	incl	%eax
	movl	%eax, 56(%rsp)
	movq	56(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L32
	movl	28(%rsp), %esi
	movq	48(%rsp), %rdi
	movl	%ebx, %edx
	call	_Z25__device_stub__Z4initPiiiPiii
.L32:
	movq	(%rsp), %rdx
	movq	48(%rsp), %rsi
	movl	$2, %ecx
	incl	%r15d
	movq	16(%rsp), %rdi
	call	cudaMemcpy@PLT
	call	_Z10stop_timerv
	addsd	8(%rsp), %xmm0
	movsd	%xmm0, 8(%rsp)
	cmpl	%r15d, %r12d
	jne	.L34
	cmpl	$2, %r13d
	jne	.L35
	cvtsi2sdl	%r12d, %xmm1
	movl	%ebp, %ecx
	movl	%r12d, %edx
	movl	$2, %edi
	leaq	.LC6(%rip), %rsi
	movb	$1, %al
	divsd	%xmm1, %xmm0
	call	__printf_chk@PLT
.L35:
	movq	16(%rsp), %rsi
	movl	%ebx, %edi
	call	_Z11printprimesiPi
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%eax, %eax
.L23:
	movq	1112(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L36
	call	__stack_chk_fail@PLT
.L36:
	addq	$1128, %rsp
	.cfi_def_cfa_offset 56
	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
.LFE2031:
	.size	main, .-main
	.section	.rodata.str1.1
.LC7:
	.string	"_Z4initPiii"
	.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	.LC7(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z4initPiii(%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
	.globl	started
	.bss
	.align 4
	.type	started, @object
	.size	started, 4
started:
	.zero	4
	.globl	stopTime
	.align 16
	.type	stopTime, @object
	.size	stopTime, 16
stopTime:
	.zero	16
	.globl	startTime
	.align 16
	.type	startTime, @object
	.size	startTime, 16
startTime:
	.zero	16
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	0
	.long	-1074790400
	.align 8
.LC1:
	.long	0
	.long	1083129856
	.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 <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>


struct timeval startTime, stopTime;
int started = 0;

void start_timer() {
 started = 1;
 gettimeofday(&startTime, NULL);
}

double stop_timer() {
 long seconds, useconds;
 double duration = -1;

 if (started) {
   gettimeofday(&stopTime, NULL);
   seconds  = stopTime.tv_sec  - startTime.tv_sec;
   useconds = stopTime.tv_usec - startTime.tv_usec;
   duration = (seconds * 1000.0) + (useconds / 1000.0);
   started = 0;
 }
 return duration;
}




void  printprimes(int limit, int *arr) {
  int c;
  //#pragma omp parallel for shared(arr, limit) private(c)
  for(c = 2; c <limit; c++) {
      if(arr[c] == 0) {
          fprintf(stdout,"%d ", c);
      }
  }
  fprintf(stdout,"\n");
  /* code */
}



__global__ void init(int *arr, int sqroot, int limit) {
  int c;
  for(c = 2; c <= sqroot; c++) {
      if(arr[c] == 0) {
          /*
          #pragma omp parallel for shared(arr, limit, c) private(m)
          for(m = c+1; m < limit; m++) {
              if(m%c == 0) {
                  arr[m] = 1;
              }
          }
          */
          int tid = c+1+ threadIdx.x + (blockIdx.x * blockDim.x);
          if (tid<limit){
            if (tid % c ==0) {
          		arr[tid] = 1;
          	}
          }


      }
  }
}

double getThreadAndInfo(hipDeviceProp_t devProp)
{
  /*
    printf("Major revision number:         %d\n",  devProp.major);
    printf("Minor revision number:         %d\n",  devProp.minor);
    printf("Name:                          %s\n",  devProp.name);
    printf("Total global memory:           %lu\n",  devProp.totalGlobalMem);
    printf("Total shared memory per block: %lu\n",  devProp.sharedMemPerBlock);
    printf("Total registers per block:     %d\n",  devProp.regsPerBlock);
    printf("Warp size:                     %d\n",  devProp.warpSize);
    printf("Maximum memory pitch:          %lu\n",  devProp.memPitch);
    printf("Maximum threads per block:     %i\n",  devProp.maxThreadsPerBlock);
    for (int i = 0; i < 3; ++i)
    printf("Maximum dimension %d of block:  %d\n", i, devProp.maxThreadsDim[i]);
    for (int i = 0; i < 3; ++i)
    printf("Maximum dimension %d of grid:   %d\n", i, devProp.maxGridSize[i]);
    printf("Clock rate:                    %d\n",  devProp.clockRate);
    printf("Total constant memory:         %lu\n",  devProp.totalConstMem);
    printf("Texture alignment:             %lu\n",  devProp.textureAlignment);
    printf("Concurrent copy and execution: %s\n",  (devProp.deviceOverlap ? "Yes" : "No"));
    printf("Number of multiprocessors:     %d\n",  devProp.multiProcessorCount);
    printf("Kernel execution timeout:      %s\n",  (devProp.kernelExecTimeoutEnabled ? "Yes" : "No"));
    */
    return devProp.maxThreadsPerBlock;
}

int main(int argc, char **argv) {
    // Number of CUDA devices
    int threads=1000000;
    int devCount;
    hipGetDeviceCount(&devCount);
    //printf("CUDA Device Query...\n");
    //printf("There are %d CUDA devices.\n", devCount);

    // Iterate through devices
    for (int i = 0; i < devCount; ++i)
    {
        // Get device properties
        //printf("\nCUDA Device #%d\n", i);
        hipDeviceProp_t devProp;
       hipGetDeviceProperties(&devProp, i);
       if (getThreadAndInfo(devProp)<threads){
         threads=getThreadAndInfo(devProp);
       }

    }

    int N=10;
    int limit ;
    if (argc>3){
      fprintf(stderr, "Error: uso: %s [limite_superior_positivo]\n", argv[0]);
      return -1;

    }else if (argc==2 || argc==3) {
      int parsed=atoi(argv[1]);
      if (parsed<0){
        fprintf(stderr, "Error: uso: %s [limite_superior_positivo]\n", argv[0]);
        return -1;
      }else{
        limit=parsed;
      }
      if (argc==3) {
        N=1;
      }
    }else {
      limit=16;
    }




      int *arr;

      double ms;
      ms = 0;
      int i;
      int *p_array;
      for (i = 0; i < N; i++) {
        start_timer();
        //->
        int sqroot = (int)sqrt(limit);
        arr = (int*)malloc(limit * sizeof(int));
        hipMalloc((void**) &p_array, limit * sizeof(int));
        hipMemset(p_array, 0, limit*sizeof(int));
        if (limit<=threads){
		threads=limit;
          init<<<1, threads>>>(p_array, sqroot, limit);
        }else{
          init<<<int(limit/threads)+1, threads>>>(p_array, sqroot, limit);
        }



        hipMemcpy(arr, p_array, limit * sizeof(int), hipMemcpyDeviceToHost);

        //->
        ms += stop_timer();
      }


      if (argc==2){
        printf("times %i - avg time = %.5lf ms, %i threads\n",N,(ms / N), threads);
      }






      //




          printprimes(limit, arr);



      free(arr);

  hipFree(p_array);


    return 0;
}


	.text
	.file	"sieve.hip"
	.globl	_Z11start_timerv                # -- Begin function _Z11start_timerv
	.type	_Z11start_timerv,@function
_Z11start_timerv:                       # @_Z11start_timerv
	.cfi_startproc
# %bb.0:
	movl	$1, started(%rip)
	movl	$startTime, %edi
	xorl	%esi, %esi
	jmp	gettimeofday                    # TAILCALL
.Lfunc_end0:
	.size	_Z11start_timerv, .Lfunc_end0-_Z11start_timerv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z10stop_timerv
.LCPI1_0:
	.quad	0xbff0000000000000              # double -1
.LCPI1_1:
	.quad	0x408f400000000000              # double 1000
	.text
	.globl	_Z10stop_timerv
	.type	_Z10stop_timerv,@function
_Z10stop_timerv:                        # @_Z10stop_timerv
	.cfi_startproc
# %bb.0:
	cmpl	$0, started(%rip)
	je	.LBB1_1
# %bb.2:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$stopTime, %edi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	stopTime(%rip), %rax
	subq	startTime(%rip), %rax
	movq	stopTime+8(%rip), %rcx
	subq	startTime+8(%rip), %rcx
	cvtsi2sd	%rax, %xmm1
	movsd	.LCPI1_1(%rip), %xmm2           # xmm2 = mem[0],zero
	cvtsi2sd	%rcx, %xmm0
	mulsd	%xmm2, %xmm1
	divsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	movl	$0, started(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	retq
.LBB1_1:
	movsd	.LCPI1_0(%rip), %xmm0           # xmm0 = mem[0],zero
	retq
.Lfunc_end1:
	.size	_Z10stop_timerv, .Lfunc_end1-_Z10stop_timerv
	.cfi_endproc
                                        # -- End function
	.globl	_Z11printprimesiPi              # -- Begin function _Z11printprimesiPi
	.type	_Z11printprimesiPi,@function
_Z11printprimesiPi:                     # @_Z11printprimesiPi
	.cfi_startproc
# %bb.0:
	cmpl	$3, %edi
	jl	.LBB2_6
# %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	%rsi, %rbx
	movl	%edi, %r15d
	movl	$2, %r14d
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	cmpl	$0, (%rbx,%r14,4)
	jne	.LBB2_4
# %bb.3:                                #   in Loop: Header=BB2_2 Depth=1
	movq	stdout(%rip), %rdi
	movl	$.L.str, %esi
	movl	%r14d, %edx
	xorl	%eax, %eax
	callq	fprintf
.LBB2_4:                                #   in Loop: Header=BB2_2 Depth=1
	incq	%r14
	cmpq	%r14, %r15
	jne	.LBB2_2
# %bb.5:
	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
.LBB2_6:                                # %._crit_edge
	movq	stdout(%rip), %rsi
	movl	$10, %edi
	jmp	fputc@PLT                       # TAILCALL
.Lfunc_end2:
	.size	_Z11printprimesiPi, .Lfunc_end2-_Z11printprimesiPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z19__device_stub__initPiii     # -- Begin function _Z19__device_stub__initPiii
	.type	_Z19__device_stub__initPiii,@function
_Z19__device_stub__initPiii:            # @_Z19__device_stub__initPiii
	.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	$96, %rsp
	.cfi_def_cfa_offset 144
	.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)
	movq	%rsp, %rsi
	movl	%edx, (%rsi)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%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	$_Z4initPiii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$112, %rsp
	.cfi_adjust_cfa_offset -112
	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	_Z19__device_stub__initPiii, .Lfunc_end3-_Z19__device_stub__initPiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z16getThreadAndInfo20hipDeviceProp_tR0600 # -- Begin function _Z16getThreadAndInfo20hipDeviceProp_tR0600
	.type	_Z16getThreadAndInfo20hipDeviceProp_tR0600,@function
_Z16getThreadAndInfo20hipDeviceProp_tR0600: # @_Z16getThreadAndInfo20hipDeviceProp_tR0600
	.cfi_startproc
# %bb.0:
	cvtsi2sdl	328(%rsp), %xmm0
	retq
.Lfunc_end4:
	.size	_Z16getThreadAndInfo20hipDeviceProp_tR0600, .Lfunc_end4-_Z16getThreadAndInfo20hipDeviceProp_tR0600
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI5_0:
	.quad	0x0000000000000000              # double 0
	.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	$1528, %rsp                     # imm = 0x5F8
	.cfi_def_cfa_offset 1584
	.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
	movl	%edi, %r12d
	leaq	12(%rsp), %r14
	movq	%r14, %rdi
	callq	hipGetDeviceCount
	cmpl	$0, (%r14)
	jle	.LBB5_1
# %bb.4:                                # %.lr.ph
	xorl	%r14d, %r14d
	movl	$1000000, %ebp                  # imm = 0xF4240
	leaq	56(%rsp), %r15
.LBB5_5:                                # =>This Inner Loop Header: Depth=1
	movq	%r15, %rdi
	movl	%r14d, %esi
	callq	hipGetDevicePropertiesR0600
	movl	376(%rsp), %eax
	cmpl	%ebp, %eax
	cmovll	%eax, %ebp
	incl	%r14d
	cmpl	12(%rsp), %r14d
	jl	.LBB5_5
	jmp	.LBB5_2
.LBB5_1:
	movl	$1000000, %ebp                  # imm = 0xF4240
.LBB5_2:                                # %._crit_edge
	cmpl	$3, %r12d
	jg	.LBB5_3
# %bb.6:
	movl	%r12d, %eax
	andl	$-2, %eax
	cmpl	$2, %eax
	movl	%r12d, 8(%rsp)                  # 4-byte Spill
	jne	.LBB5_7
# %bb.8:
	movq	8(%rbx), %rdi
	callq	atoi
	testl	%eax, %eax
	js	.LBB5_3
# %bb.9:                                # %.thread
	movl	%eax, %r14d
	xorl	%eax, %eax
	cmpl	$3, %r12d
	setne	%al
	leal	(%rax,%rax,8), %ebx
	incl	%ebx
	jmp	.LBB5_10
.LBB5_7:
	movl	$10, %ebx
	movl	$16, %r14d
.LBB5_10:
	movabsq	$4294967296, %rax               # imm = 0x100000000
	cvtsi2sd	%r14d, %xmm0
	movl	%r14d, %r12d
	leaq	(,%r12,4), %r13
	btsq	$32, %r12
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	sqrtsd	%xmm0, %xmm0
	movsd	%xmm0, 32(%rsp)                 # 8-byte Spill
	incq	%rax
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	movl	%ebx, 4(%rsp)                   # 4-byte Spill
	xorpd	%xmm1, %xmm1
.LBB5_11:                               # =>This Inner Loop Header: Depth=1
	movsd	%xmm1, 48(%rsp)                 # 8-byte Spill
	movl	$1, started(%rip)
	movl	$startTime, %edi
	xorl	%esi, %esi
	callq	gettimeofday
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	ucomisd	.LCPI5_0(%rip), %xmm0
	movsd	32(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	jae	.LBB5_13
# %bb.12:                               # %call.sqrt
                                        #   in Loop: Header=BB5_11 Depth=1
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	sqrt
.LBB5_13:                               # %.split
                                        #   in Loop: Header=BB5_11 Depth=1
	movsd	%xmm0, 40(%rsp)                 # 8-byte Spill
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %r15
	leaq	56(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	movq	%r13, %rdx
	callq	hipMemset
	cmpl	%ebp, %r14d
	jle	.LBB5_14
# %bb.15:                               #   in Loop: Header=BB5_11 Depth=1
	movl	%r14d, %eax
	cltd
	idivl	%ebp
                                        # kill: def $eax killed $eax def $rax
	leal	1(%rax), %edi
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %rdi
	movl	%ebp, %edx
	orq	%rax, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	jmp	.LBB5_16
.LBB5_14:                               #   in Loop: Header=BB5_11 Depth=1
	movq	24(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	movl	%r14d, %ebp
.LBB5_16:                               #   in Loop: Header=BB5_11 Depth=1
	testl	%eax, %eax
	jne	.LBB5_18
# %bb.17:                               # %.sink.split
                                        #   in Loop: Header=BB5_11 Depth=1
	cvttsd2si	40(%rsp), %esi          # 8-byte Folded Reload
	movq	56(%rsp), %rdi
	movl	%r14d, %edx
	callq	_Z19__device_stub__initPiii
.LBB5_18:                               #   in Loop: Header=BB5_11 Depth=1
	movq	56(%rsp), %rsi
	movq	%r15, %rdi
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	callq	_Z10stop_timerv
	movsd	48(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	addsd	%xmm0, %xmm1
	decl	%ebx
	jne	.LBB5_11
# %bb.19:
	cmpl	$2, 8(%rsp)                     # 4-byte Folded Reload
	jne	.LBB5_21
# %bb.20:
	movl	4(%rsp), %esi                   # 4-byte Reload
	xorps	%xmm0, %xmm0
	cvtsi2sd	%esi, %xmm0
	divsd	%xmm0, %xmm1
	movl	$.L.str.3, %edi
	movapd	%xmm1, %xmm0
	movl	%ebp, %edx
	movb	$1, %al
	callq	printf
.LBB5_21:
	movl	%r14d, %edi
	movq	%r15, %rsi
	callq	_Z11printprimesiPi
	movq	%r15, %rdi
	callq	free
	movq	56(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
.LBB5_22:
	addq	$1528, %rsp                     # imm = 0x5F8
	.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
.LBB5_3:
	.cfi_def_cfa_offset 1584
	movq	stderr(%rip), %rdi
	movq	(%rbx), %rdx
	movl	$.L.str.2, %esi
	xorl	%eax, %eax
	callq	fprintf
	movl	$-1, %eax
	jmp	.LBB5_22
.Lfunc_end5:
	.size	main, .Lfunc_end5-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:
	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	$_Z4initPiii, %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	startTime,@object               # @startTime
	.bss
	.globl	startTime
	.p2align	3, 0x0
startTime:
	.zero	16
	.size	startTime, 16

	.type	stopTime,@object                # @stopTime
	.globl	stopTime
	.p2align	3, 0x0
stopTime:
	.zero	16
	.size	stopTime, 16

	.type	started,@object                 # @started
	.globl	started
	.p2align	2, 0x0
started:
	.long	0                               # 0x0
	.size	started, 4

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

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

	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"Error: uso: %s [limite_superior_positivo]\n"
	.size	.L.str.2, 43

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"times %i - avg time = %.5lf ms, %i threads\n"
	.size	.L.str.3, 44

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z4initPiii"
	.size	.L__unnamed_1, 12

	.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 _Z19__device_stub__initPiii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym startTime
	.addrsig_sym stopTime
	.addrsig_sym _Z4initPiii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z4initPiii             ; -- Begin function _Z4initPiii
	.globl	_Z4initPiii
	.p2align	8
	.type	_Z4initPiii,@function
_Z4initPiii:                            ; @_Z4initPiii
; %bb.0:
	s_load_b64 s[2:3], s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s2, 2
	s_cbranch_scc1 .LBB0_8
; %bb.1:                                ; %.lr.ph
	s_load_b64 s[4:5], s[0:1], 0x0
	s_add_u32 s0, s0, 16
	v_dual_mov_b32 v3, 0 :: v_dual_add_nc_u32 v2, 3, v0
	v_mov_b32_e32 v4, 1
	s_addc_u32 s1, s1, 0
	s_add_i32 s2, s2, -1
	s_mov_b32 s8, 0
	s_waitcnt lgkmcnt(0)
	s_add_u32 s6, s4, 8
	s_addc_u32 s7, s5, 0
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	global_load_b32 v0, v3, s[6:7]
	s_waitcnt vmcnt(0)
	v_cmp_ne_u32_e32 vcc_lo, 0, v0
	s_cbranch_vccnz .LBB0_7
; %bb.3:                                ;   in Loop: Header=BB0_2 Depth=1
	s_load_b32 s9, s[0:1], 0xc
	v_add_nc_u32_e32 v5, s8, v2
	s_waitcnt lgkmcnt(0)
	s_and_b32 s9, s9, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	s_mul_i32 s10, s15, s9
	s_mov_b32 s9, exec_lo
	v_add_nc_u32_e32 v0, s10, v5
	v_cmpx_gt_i32_e64 s3, v0
	s_cbranch_execz .LBB0_6
; %bb.4:                                ;   in Loop: Header=BB0_2 Depth=1
	s_add_i32 s11, s8, 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_ashr_i32 s12, s11, 31
	s_add_i32 s11, s11, s12
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_xor_b32 s11, s11, s12
	v_cvt_f32_u32_e32 v1, s11
	s_sub_i32 s12, 0, s11
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v1, v1
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v1, 0x4f7ffffe, v1
	v_cvt_u32_f32_e32 v6, v1
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v7, s12, v6
	v_add3_u32 v5, v1, s10, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_xor_b32_e32 v5, v5, v1
	v_mul_hi_u32 v7, v6, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v6, v6, v7
	v_mul_hi_u32 v6, v5, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v6, v6, s11
	v_sub_nc_u32_e32 v5, v5, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v6, s11, v5
	v_cmp_le_u32_e32 vcc_lo, s11, v5
	v_cndmask_b32_e32 v5, v5, v6, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v6, s11, v5
	v_cmp_le_u32_e32 vcc_lo, s11, v5
	v_cndmask_b32_e32 v5, v5, v6, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v5, v5, v1
	v_sub_nc_u32_e32 v5, v5, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_eq_u32_e32 vcc_lo, 0, v5
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_2 Depth=1
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	global_store_b32 v[0:1], v4, off
.LBB0_6:                                ; %Flow24
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s9
.LBB0_7:                                ;   in Loop: Header=BB0_2 Depth=1
	s_add_i32 s8, s8, 1
	s_add_u32 s6, s6, 4
	s_addc_u32 s7, s7, 0
	s_cmp_lg_u32 s2, s8
	s_cbranch_scc1 .LBB0_2
.LBB0_8:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4initPiii
		.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	_Z4initPiii, .Lfunc_end0-_Z4initPiii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 396
; 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:         12
        .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:           _Z4initPiii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z4initPiii.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
