#include<stdio.h>
#include<cuda.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <math.h>

#define N 100000
using namespace std;
static const long BLK_SIZE =1000 ;
#define CUDA_CHECK_RETURN(value) {											\
	cudaError_t _m_cudaStat = value;										\
	if (_m_cudaStat != cudaSuccess) {										\
		fprintf(stderr, "Error %s at line %d in file %s\n",					\
				cudaGetErrorString(_m_cudaStat), __LINE__, __FILE__);		\
		exit(1);															\
	} }



__global__ void sort(int *c,int *count)
{
    int l;
    if(*count%2==0)
          l=*count/2;
    else
         l=(*count/2)+1;
    for(int i=0;i<l;i++)
    {
            if(threadIdx.x%2==0)  //even phase
            {
                if(c[threadIdx.x]>c[threadIdx.x+1])
                {
                    int temp=c[threadIdx.x];
                    c[threadIdx.x]=c[threadIdx.x+1];
                    c[threadIdx.x+1]=temp;
                }

            __syncthreads();
            }
            else     //odd phase
            {
                if(c[threadIdx.x]>c[threadIdx.x+1])
                {
                    int temp=c[threadIdx.x];
                    c[threadIdx.x]=c[threadIdx.x+1];
                    c[threadIdx.x+1]=temp;
                }

            __syncthreads();
            }
    }

}

void swap(int *xp, int *yp)
{
	int temp = *xp;
	*xp = *yp;
	*yp = temp;
}

// An optimized version of Bubble Sort
void bubbleSort(int arr[], int n)
{

}

int main()
{
int a[N],b[N];
    for (int i = 0; i < N; i++) {
  		a[i] = (float) rand() / (float) RAND_MAX * 100;

  	}


  printf("ORIGINAL ARRAY : \n");
  for(int i=0;i<N;i++)
          {

          printf("%d ",a[i]);
          }


  int *c,*count;
  int k=N;


  cudaMalloc((void**)&c,sizeof(int)*N);
  cudaMalloc((void**)&count,sizeof(int));
  cudaMemcpy(c,&a,sizeof(int)*N,cudaMemcpyHostToDevice);
  cudaMemcpy(count,&k,sizeof(int),cudaMemcpyHostToDevice);


  //Time kernel launch
  	//Time kernel launch
  	cudaEvent_t start, stop;
  	CUDA_CHECK_RETURN(cudaEventCreate(&start));
  	CUDA_CHECK_RETURN(cudaEventCreate(&stop));
  	float elapsedTime;

  	CUDA_CHECK_RETURN(cudaEventRecord(start, 0));



  sort<<< ceil(N/(float)BLK_SIZE),BLK_SIZE >>>(c,count);

  CUDA_CHECK_RETURN(cudaEventRecord(stop, 0));

  	CUDA_CHECK_RETURN(cudaEventSynchronize(stop));
  	CUDA_CHECK_RETURN(cudaEventElapsedTime(&elapsedTime, start, stop));
  	CUDA_CHECK_RETURN(cudaThreadSynchronize());	// Wait for the GPU launched work to complete
  	CUDA_CHECK_RETURN(cudaGetLastError()); //Check if an error occurred in device code
  	CUDA_CHECK_RETURN(cudaEventDestroy(start));
  	CUDA_CHECK_RETURN(cudaEventDestroy(stop));
  	cout << "done.\nElapsed kernel time: " << elapsedTime << " ms\n";

  	cout << "Copying results back to host .... "<<endl;

  cudaMemcpy(&b,c,sizeof(int)*N,cudaMemcpyDeviceToHost);
  printf("\nSORTED ARRAY : \n");

  for(int i=0;i<N;i++)
      {
         printf("%d ",b[i]);
      }

  //Add code to time host calculations
  	clock_t st, ed;

  	st = clock();
  	//bool valid = true;

  //bubbleSort(a,N);

  	int i, j;
  	bool swapped;
  	for (i = 0; i < N-1; i++)
  	{
  		swapped = false;
  		for (j = 0; j < N-i-1; j++)
  		{
  			if (a[j] > a[j+1])
  			{
  			swap(&a[j], &a[j+1]);
  			swapped = true;
  			}
  		}

  		// IF no two elements were swapped by inner loop, then break
  		if (swapped == false)
  			break;
  	}

  printf("\n");
        printf("BYCPU");
        printf("\n");
  for(int i=0;i<N;i++)
        {

	  printf("%d ",a[i]);
        }
  ed = clock() - st;
  	cout << "Elapsed time on host: " << ((float) ed) / CLOCKS_PER_SEC * 1000
  			<< " ms" << endl;

}




	.file	"tmpxft_0035fe95_00000000-6_pr1.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3640:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3640:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z4swapPiS_
	.type	_Z4swapPiS_, @function
_Z4swapPiS_:
.LFB3635:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	movl	(%rsi), %edx
	movl	%edx, (%rdi)
	movl	%eax, (%rsi)
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z4swapPiS_, .-_Z4swapPiS_
	.globl	_Z10bubbleSortPii
	.type	_Z10bubbleSortPii, @function
_Z10bubbleSortPii:
.LFB3636:
	.cfi_startproc
	endbr64
	ret
	.cfi_endproc
.LFE3636:
	.size	_Z10bubbleSortPii, .-_Z10bubbleSortPii
	.globl	_Z25__device_stub__Z4sortPiS_PiS_
	.type	_Z25__device_stub__Z4sortPiS_PiS_, @function
_Z25__device_stub__Z4sortPiS_PiS_:
.LFB3662:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L4
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z4sortPiS_(%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
.L4:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L6
	call	__stack_chk_fail@PLT
.L6:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3662:
	.size	_Z25__device_stub__Z4sortPiS_PiS_, .-_Z25__device_stub__Z4sortPiS_PiS_
	.globl	_Z4sortPiS_
	.type	_Z4sortPiS_, @function
_Z4sortPiS_:
.LFB3663:
	.cfi_startproc
	endbr64
	jmp	_Z25__device_stub__Z4sortPiS_PiS_
	.cfi_endproc
.LFE3663:
	.size	_Z4sortPiS_, .-_Z4sortPiS_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"ORIGINAL ARRAY : \n"
.LC3:
	.string	"%d "
.LC4:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/prateeksri6689/Car-Racing-Game-Using-Parallel-Programming-/master/pr1.cu"
.LC5:
	.string	"Error %s at line %d in file %s\n"
.LC6:
	.string	"done.\nElapsed kernel time: "
.LC7:
	.string	" ms\n"
.LC8:
	.string	"Copying results back to host .... "
.LC9:
	.string	"\nSORTED ARRAY : \n"
.LC10:
	.string	"\n"
.LC11:
	.string	"BYCPU"
.LC12:
	.string	"Elapsed time on host: "
.LC15:
	.string	" ms"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3637:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798768
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1360, %rsp
	.cfi_def_cfa_offset 800128
	xorl	%ebp, %ebp
	movq	%fs:40, %rax
	movq	%rax, 800072(%rsp)
	xorl	%eax, %eax
.L11:
	call	rand@PLT
	leaq	72(%rsp), %rbx
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	mulss	.LC1(%rip), %xmm0
	cvttss2sil	%xmm0, %eax
	movl	%eax, (%rbx,%rbp,4)
	incq	%rbp
	cmpq	$100000, %rbp
	jne	.L11
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebp, %ebp
	call	__printf_chk@PLT
	leaq	.LC3(%rip), %r14
.L12:
	movl	(%rbx,%rbp,4), %edx
	movq	%r14, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%rbp
	call	__printf_chk@PLT
	cmpq	$100000, %rbp
	jne	.L12
	leaq	16(%rsp), %rdi
	movl	$400000, %esi
	movl	$100000, 12(%rsp)
	call	cudaMalloc@PLT
	leaq	24(%rsp), %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$400000, %edx
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	leaq	12(%rsp), %rsi
	movl	$1, %ecx
	movl	$4, %edx
	call	cudaMemcpy@PLT
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L13
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$99, %r8d
	movq	%rax, %rcx
	jmp	.L40
.L13:
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L14
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$100, %r8d
	movq	%rax, %rcx
.L40:
	movq	stderr(%rip), %rdi
	leaq	.LC5(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L14:
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L15
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$103, %r8d
	movq	%rax, %rcx
	jmp	.L40
.L15:
	movl	$536871037, %edx
	movl	$1073741849, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$3, %rdx
	salq	$2, %rdi
	movl	$1, %ecx
	movl	$1, %esi
	movq	%rdx, 60(%rsp)
	movl	$1, 68(%rsp)
	movq	%rdi, 48(%rsp)
	movl	$1, 56(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L16
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	call	_Z25__device_stub__Z4sortPiS_PiS_
.L16:
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L17
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$109, %r8d
	movq	%rax, %rcx
	jmp	.L40
.L17:
	movq	40(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L18
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$111, %r8d
	movq	%rax, %rcx
	jmp	.L40
.L18:
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	leaq	60(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L19
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$112, %r8d
	movq	%rax, %rcx
	jmp	.L40
.L19:
	call	cudaThreadSynchronize@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L20
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$113, %r8d
	movq	%rax, %rcx
	jmp	.L40
.L20:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L21
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$114, %r8d
	movq	%rax, %rcx
	jmp	.L40
.L21:
	movq	32(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L22
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$115, %r8d
	movq	%rax, %rcx
	jmp	.L40
.L22:
	movq	40(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L23
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %r9
	movl	$116, %r8d
	movq	%rax, %rcx
	jmp	.L40
.L23:
	leaq	_ZSt4cout(%rip), %r12
	leaq	.LC6(%rip), %rsi
	xorl	%ebp, %ebp
	movq	%r12, %rdi
	leaq	400072(%rsp), %r13
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	60(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC7(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC8(%rip), %rsi
	movq	%r12, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movq	%r13, %rdi
	movl	$400000, %edx
	call	cudaMemcpy@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L24:
	movl	0(%r13,%rbp,4), %edx
	movq	%r14, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%rbp
	call	__printf_chk@PLT
	cmpq	$100000, %rbp
	jne	.L24
	call	clock@PLT
	leaq	400068(%rsp), %rdx
	movq	%rax, %r13
.L25:
	movq	%rbx, %rax
	xorl	%ecx, %ecx
.L27:
	movl	(%rax), %esi
	movl	4(%rax), %edi
	cmpl	%edi, %esi
	jle	.L26
	movl	%edi, (%rax)
	movb	$1, %cl
	movl	%esi, 4(%rax)
.L26:
	addq	$4, %rax
	cmpq	%rdx, %rax
	jne	.L27
	testb	%cl, %cl
	je	.L28
	subq	$4, %rdx
	cmpq	%rbx, %rdx
	jne	.L25
.L28:
	leaq	.LC10(%rip), %rbp
	movl	$2, %edi
	xorl	%eax, %eax
	movq	%rbp, %rsi
	call	__printf_chk@PLT
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%ebp, %ebp
.L29:
	movl	(%rbx,%rbp,4), %edx
	movq	%r14, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%rbp
	call	__printf_chk@PLT
	cmpq	$100000, %rbp
	jne	.L29
	call	clock@PLT
	leaq	.LC12(%rip), %rsi
	movq	%r12, %rdi
	subq	%r13, %rax
	movq	%rax, %rbx
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtsi2ssq	%rbx, %xmm0
	divss	.LC13(%rip), %xmm0
	mulss	.LC14(%rip), %xmm0
	movq	%rax, %rdi
	cvtss2sd	%xmm0, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC15(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	800072(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$800080, %rsp
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3637:
	.size	main, .-main
	.section	.rodata.str1.1
.LC16:
	.string	"_Z4sortPiS_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3665:
	.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	.LC16(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z4sortPiS_(%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
.LFE3665:
	.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.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	805306368
	.align 4
.LC1:
	.long	1120403456
	.align 4
.LC13:
	.long	1232348160
	.align 4
.LC14:
	.long	1148846080
	.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<stdio.h>
#include<hip/hip_runtime.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <math.h>

#define N 100000
using namespace std;
static const long BLK_SIZE =1000 ;
#define CUDA_CHECK_RETURN(value) {											\
	hipError_t _m_cudaStat = value;										\
	if (_m_cudaStat != hipSuccess) {										\
		fprintf(stderr, "Error %s at line %d in file %s\n",					\
				hipGetErrorString(_m_cudaStat), __LINE__, __FILE__);		\
		exit(1);															\
	} }



__global__ void sort(int *c,int *count)
{
    int l;
    if(*count%2==0)
          l=*count/2;
    else
         l=(*count/2)+1;
    for(int i=0;i<l;i++)
    {
            if(threadIdx.x%2==0)  //even phase
            {
                if(c[threadIdx.x]>c[threadIdx.x+1])
                {
                    int temp=c[threadIdx.x];
                    c[threadIdx.x]=c[threadIdx.x+1];
                    c[threadIdx.x+1]=temp;
                }

            __syncthreads();
            }
            else     //odd phase
            {
                if(c[threadIdx.x]>c[threadIdx.x+1])
                {
                    int temp=c[threadIdx.x];
                    c[threadIdx.x]=c[threadIdx.x+1];
                    c[threadIdx.x+1]=temp;
                }

            __syncthreads();
            }
    }

}

void swap(int *xp, int *yp)
{
	int temp = *xp;
	*xp = *yp;
	*yp = temp;
}

// An optimized version of Bubble Sort
void bubbleSort(int arr[], int n)
{

}

int main()
{
int a[N],b[N];
    for (int i = 0; i < N; i++) {
  		a[i] = (float) rand() / (float) RAND_MAX * 100;

  	}


  printf("ORIGINAL ARRAY : \n");
  for(int i=0;i<N;i++)
          {

          printf("%d ",a[i]);
          }


  int *c,*count;
  int k=N;


  hipMalloc((void**)&c,sizeof(int)*N);
  hipMalloc((void**)&count,sizeof(int));
  hipMemcpy(c,&a,sizeof(int)*N,hipMemcpyHostToDevice);
  hipMemcpy(count,&k,sizeof(int),hipMemcpyHostToDevice);


  //Time kernel launch
  	//Time kernel launch
  	hipEvent_t start, stop;
  	CUDA_CHECK_RETURN(hipEventCreate(&start));
  	CUDA_CHECK_RETURN(hipEventCreate(&stop));
  	float elapsedTime;

  	CUDA_CHECK_RETURN(hipEventRecord(start, 0));



  sort<<< ceil(N/(float)BLK_SIZE),BLK_SIZE >>>(c,count);

  CUDA_CHECK_RETURN(hipEventRecord(stop, 0));

  	CUDA_CHECK_RETURN(hipEventSynchronize(stop));
  	CUDA_CHECK_RETURN(hipEventElapsedTime(&elapsedTime, start, stop));
  	CUDA_CHECK_RETURN(hipDeviceSynchronize());	// Wait for the GPU launched work to complete
  	CUDA_CHECK_RETURN(hipGetLastError()); //Check if an error occurred in device code
  	CUDA_CHECK_RETURN(hipEventDestroy(start));
  	CUDA_CHECK_RETURN(hipEventDestroy(stop));
  	cout << "done.\nElapsed kernel time: " << elapsedTime << " ms\n";

  	cout << "Copying results back to host .... "<<endl;

  hipMemcpy(&b,c,sizeof(int)*N,hipMemcpyDeviceToHost);
  printf("\nSORTED ARRAY : \n");

  for(int i=0;i<N;i++)
      {
         printf("%d ",b[i]);
      }

  //Add code to time host calculations
  	clock_t st, ed;

  	st = clock();
  	//bool valid = true;

  //bubbleSort(a,N);

  	int i, j;
  	bool swapped;
  	for (i = 0; i < N-1; i++)
  	{
  		swapped = false;
  		for (j = 0; j < N-i-1; j++)
  		{
  			if (a[j] > a[j+1])
  			{
  			swap(&a[j], &a[j+1]);
  			swapped = true;
  			}
  		}

  		// IF no two elements were swapped by inner loop, then break
  		if (swapped == false)
  			break;
  	}

  printf("\n");
        printf("BYCPU");
        printf("\n");
  for(int i=0;i<N;i++)
        {

	  printf("%d ",a[i]);
        }
  ed = clock() - st;
  	cout << "Elapsed time on host: " << ((float) ed) / CLOCKS_PER_SEC * 1000
  			<< " ms" << endl;

}




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

                                        # End of file scope inline assembly
	.globl	_Z19__device_stub__sortPiS_     # -- Begin function _Z19__device_stub__sortPiS_
	.type	_Z19__device_stub__sortPiS_,@function
_Z19__device_stub__sortPiS_:            # @_Z19__device_stub__sortPiS_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%rsp, %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z4sortPiS_, %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	_Z19__device_stub__sortPiS_, .Lfunc_end0-_Z19__device_stub__sortPiS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z4swapPiS_                     # -- Begin function _Z4swapPiS_
	.type	_Z4swapPiS_,@function
_Z4swapPiS_:                            # @_Z4swapPiS_
	.cfi_startproc
# %bb.0:
	movl	(%rdi), %eax
	movl	(%rsi), %ecx
	movl	%ecx, (%rdi)
	movl	%eax, (%rsi)
	retq
.Lfunc_end1:
	.size	_Z4swapPiS_, .Lfunc_end1-_Z4swapPiS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z10bubbleSortPii               # -- Begin function _Z10bubbleSortPii
	.type	_Z10bubbleSortPii,@function
_Z10bubbleSortPii:                      # @_Z10bubbleSortPii
	.cfi_startproc
# %bb.0:
	retq
.Lfunc_end2:
	.size	_Z10bubbleSortPii, .Lfunc_end2-_Z10bubbleSortPii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI3_0:
	.long	0x30000000                      # float 4.65661287E-10
.LCPI3_1:
	.long	0x42c80000                      # float 100
.LCPI3_2:
	.long	0x49742400                      # float 1.0E+6
.LCPI3_3:
	.long	0x447a0000                      # float 1000
	.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	%rbx
	.cfi_def_cfa_offset 40
	subq	$800056, %rsp                   # imm = 0xC3538
	.cfi_def_cfa_offset 800096
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	xorl	%ebx, %ebx
.LBB3_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI3_0(%rip), %xmm0
	mulss	.LCPI3_1(%rip), %xmm0
	cvttss2si	%xmm0, %eax
	movl	%eax, 48(%rsp,%rbx,4)
	incq	%rbx
	cmpq	$100000, %rbx                   # imm = 0x186A0
	jne	.LBB3_1
# %bb.2:
	movl	$.Lstr, %edi
	callq	puts@PLT
	xorl	%ebx, %ebx
.LBB3_3:                                # =>This Inner Loop Header: Depth=1
	movl	48(%rsp,%rbx,4), %esi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%rbx
	cmpq	$100000, %rbx                   # imm = 0x186A0
	jne	.LBB3_3
# %bb.4:
	leaq	44(%rsp), %rbx
	movl	$100000, (%rbx)                 # imm = 0x186A0
	leaq	24(%rsp), %r14
	movl	$400000, %esi                   # imm = 0x61A80
	movq	%r14, %rdi
	callq	hipMalloc
	leaq	32(%rsp), %r15
	movl	$4, %esi
	movq	%r15, %rdi
	callq	hipMalloc
	movq	(%r14), %rdi
	leaq	48(%rsp), %rsi
	movl	$400000, %edx                   # imm = 0x61A80
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r15), %rdi
	movl	$4, %edx
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB3_5
# %bb.7:
	movq	%rsp, %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB3_8
# %bb.9:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB3_10
# %bb.11:
	movabsq	$4294967396, %rdi               # imm = 0x100000064
	leaq	900(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_13
# %bb.12:
	movq	24(%rsp), %rdi
	movq	32(%rsp), %rsi
	callq	_Z19__device_stub__sortPiS_
.LBB3_13:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB3_14
# %bb.15:
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	testl	%eax, %eax
	jne	.LBB3_16
# %bb.17:
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	20(%rsp), %rdi
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB3_18
# %bb.19:
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB3_20
# %bb.21:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB3_22
# %bb.23:
	movq	8(%rsp), %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB3_24
# %bb.25:
	movq	(%rsp), %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB3_26
# %bb.27:
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$27, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtss2sd	20(%rsp), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str.5, %esi
	movl	$4, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.6, %esi
	movl	$34, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	24(%rsp), %rsi
	leaq	400048(%rsp), %rdi
	movl	$400000, %edx                   # imm = 0x61A80
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	xorl	%ebx, %ebx
.LBB3_28:                               # =>This Inner Loop Header: Depth=1
	movl	400048(%rsp,%rbx,4), %esi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%rbx
	cmpq	$100000, %rbx                   # imm = 0x186A0
	jne	.LBB3_28
# %bb.29:
	xorl	%ebp, %ebp
	movl	$99999, %r14d                   # imm = 0x1869F
	callq	clock
	movq	%rax, %rbx
.LBB3_31:                               # %.lr.ph.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_32 Depth 2
	movl	48(%rsp), %ecx
	xorl	%eax, %eax
	xorl	%edx, %edx
.LBB3_32:                               # %.lr.ph
                                        #   Parent Loop BB3_31 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	52(%rsp,%rax,4), %esi
	cmpl	%esi, %ecx
	jle	.LBB3_33
# %bb.34:                               #   in Loop: Header=BB3_32 Depth=2
	movl	%esi, 48(%rsp,%rax,4)
	movl	%ecx, 52(%rsp,%rax,4)
	movb	$1, %dl
	jmp	.LBB3_35
.LBB3_33:                               #   in Loop: Header=BB3_32 Depth=2
	movl	%esi, %ecx
.LBB3_35:                               #   in Loop: Header=BB3_32 Depth=2
	incq	%rax
	cmpq	%rax, %r14
	jne	.LBB3_32
# %bb.36:                               # %._crit_edge
                                        #   in Loop: Header=BB3_31 Depth=1
	testb	$1, %dl
	je	.LBB3_37
# %bb.30:                               #   in Loop: Header=BB3_31 Depth=1
	incl	%ebp
	decq	%r14
	cmpl	$99999, %ebp                    # imm = 0x1869F
	jne	.LBB3_31
.LBB3_37:
	movl	$10, %edi
	callq	putchar@PLT
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$10, %edi
	callq	putchar@PLT
	xorl	%r14d, %r14d
.LBB3_38:                               # =>This Inner Loop Header: Depth=1
	movl	48(%rsp,%r14,4), %esi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r14
	cmpq	$100000, %r14                   # imm = 0x186A0
	jne	.LBB3_38
# %bb.39:
	callq	clock
	movq	%rax, %r14
	subq	%rbx, %r14
	movl	$_ZSt4cout, %edi
	movl	$.L.str.10, %esi
	movl	$22, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtsi2ss	%r14, %xmm0
	divss	.LCPI3_2(%rip), %xmm0
	mulss	.LCPI3_3(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str.11, %esi
	movl	$3, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	xorl	%eax, %eax
	addq	$800056, %rsp                   # imm = 0xC3538
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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
.LBB3_5:
	.cfi_def_cfa_offset 800096
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.3, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$99, %ecx
	jmp	.LBB3_6
.LBB3_8:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.3, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$100, %ecx
	jmp	.LBB3_6
.LBB3_10:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.3, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$103, %ecx
	jmp	.LBB3_6
.LBB3_14:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.3, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$109, %ecx
	jmp	.LBB3_6
.LBB3_16:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.3, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$111, %ecx
	jmp	.LBB3_6
.LBB3_18:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.3, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$112, %ecx
	jmp	.LBB3_6
.LBB3_20:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.3, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$113, %ecx
	jmp	.LBB3_6
.LBB3_22:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.3, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$114, %ecx
	jmp	.LBB3_6
.LBB3_24:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.3, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$115, %ecx
	jmp	.LBB3_6
.LBB3_26:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.3, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$116, %ecx
.LBB3_6:
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	main, .Lfunc_end3-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	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z4sortPiS_, %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_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z4sortPiS_,@object             # @_Z4sortPiS_
	.section	.rodata,"a",@progbits
	.globl	_Z4sortPiS_
	.p2align	3, 0x0
_Z4sortPiS_:
	.quad	_Z19__device_stub__sortPiS_
	.size	_Z4sortPiS_, 8

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

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Error %s at line %d in file %s\n"
	.size	.L.str.2, 32

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/prateeksri6689/Car-Racing-Game-Using-Parallel-Programming-/master/pr1.hip"
	.size	.L.str.3, 136

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"done.\nElapsed kernel time: "
	.size	.L.str.4, 28

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	" ms\n"
	.size	.L.str.5, 5

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Copying results back to host .... "
	.size	.L.str.6, 35

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"BYCPU"
	.size	.L.str.9, 6

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Elapsed time on host: "
	.size	.L.str.10, 23

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z4sortPiS_"
	.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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"ORIGINAL ARRAY : "
	.size	.Lstr, 18

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"\nSORTED ARRAY : "
	.size	.Lstr.1, 17

	.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__sortPiS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z4sortPiS_
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z4sortPiS_             ; -- Begin function _Z4sortPiS_
	.globl	_Z4sortPiS_
	.p2align	8
	.type	_Z4sortPiS_,@function
_Z4sortPiS_:                            ; @_Z4sortPiS_
; %bb.0:
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_load_b32 s3, s[2:3], 0x0
	s_waitcnt lgkmcnt(0)
	s_bitcmp1_b32 s3, 0
	s_cselect_b32 s2, -1, 0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 vcc_lo, exec_lo, s2
	s_cbranch_vccz .LBB0_2
; %bb.1:
	s_lshr_b32 s2, s3, 31
	s_mov_b32 s4, 0
	s_add_i32 s2, s3, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_ashr_i32 s2, s2, 1
	s_add_i32 s2, s2, 1
	s_branch .LBB0_3
.LBB0_2:
	s_mov_b32 s4, -1
                                        ; implicit-def: $sgpr2
.LBB0_3:                                ; %Flow33
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 vcc_lo, exec_lo, s4
	s_cbranch_vccnz .LBB0_5
; %bb.4:
	s_ashr_i32 s2, s3, 1
.LBB0_5:
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_lt_i32 s2, 1
	s_cbranch_scc1 .LBB0_16
; %bb.6:                                ; %.lr.ph
	v_and_b32_e32 v1, 1, v0
	v_lshlrev_b32_e32 v0, 2, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_eq_u32_e32 vcc_lo, 1, v1
	v_add_co_u32 v0, s0, s0, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v1, null, s1, 0, s0
.LBB0_7:                                ; =>This Inner Loop Header: Depth=1
	global_load_b64 v[2:3], v[0:1], off
	s_waitcnt vmcnt(0)
	v_cmp_gt_i32_e64 s0, v2, v3
	s_and_saveexec_b32 s1, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s1, exec_lo, s1
	s_cbranch_execz .LBB0_11
; %bb.8:                                ;   in Loop: Header=BB0_7 Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	s_and_saveexec_b32 s3, s0
	s_cbranch_execz .LBB0_10
; %bb.9:                                ;   in Loop: Header=BB0_7 Depth=1
	v_mov_b32_e32 v4, v2
	global_store_b64 v[0:1], v[3:4], off
.LBB0_10:                               ;   in Loop: Header=BB0_7 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_waitcnt_vscnt null, 0x0
	s_barrier
                                        ; implicit-def: $vgpr2_vgpr3
.LBB0_11:                               ; %Flow
                                        ;   in Loop: Header=BB0_7 Depth=1
	s_and_not1_saveexec_b32 s1, s1
	s_cbranch_execz .LBB0_15
; %bb.12:                               ;   in Loop: Header=BB0_7 Depth=1
	s_and_saveexec_b32 s3, s0
	s_cbranch_execz .LBB0_14
; %bb.13:                               ;   in Loop: Header=BB0_7 Depth=1
	v_mov_b32_e32 v4, v2
	global_store_b64 v[0:1], v[3:4], off
.LBB0_14:                               ;   in Loop: Header=BB0_7 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_waitcnt_vscnt null, 0x0
	s_barrier
.LBB0_15:                               ; %Flow30
                                        ;   in Loop: Header=BB0_7 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_add_i32 s2, s2, -1
	buffer_gl0_inv
	s_cmp_eq_u32 s2, 0
	s_cbranch_scc0 .LBB0_7
.LBB0_16:                               ; %._crit_edge
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4sortPiS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 16
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 5
		.amdhsa_next_free_sgpr 5
		.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	_Z4sortPiS_, .Lfunc_end0-_Z4sortPiS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 280
; NumSgprs: 7
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 0
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 7
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.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
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 16
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z4sortPiS_
    .private_segment_fixed_size: 0
    .sgpr_count:     7
    .sgpr_spill_count: 0
    .symbol:         _Z4sortPiS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
