#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cassert>
constexpr size_t BLOCK_SIZE = 1024; // Размер блока.
constexpr size_t SIZE = 2048;

// Отдельный компаратор  сравнивает пару ключей
// и производит обмен соответствующих элементов и
// ключей для обеспечения заданного порядка.
__device__ void Comparator (uint& keyA, uint& valA, uint& keyB, uint& valB, uint dir) {
  uint t;
  // Поменять местами (keyA, valA) и (keyB, valB)
  if ( (keyA > keyB) == dir ) {
    t = keyA;
    keyA = keyB;
    keyB = t;
    t = valA;
    valA = valB;
    valB = t;
  }
}

__global__ void bitonicSortShared (uint* dstKey,
                                   uint* dstVal,
                                   uint* srcKey,
                                   uint* srcVal,
                                   uint arrayLength,
                                   uint dir) {
  __shared__ uint sk [BLOCK_SIZE * 2];
  __shared__ uint sv [BLOCK_SIZE * 2];
  int index = blockIdx.x * BLOCK_SIZE * 2 + threadIdx.x;
  sk [threadIdx.x] = srcKey[index];
  sv [threadIdx.x] = srcVal[index];
  sk [threadIdx.x + BLOCK_SIZE] = srcKey [index + BLOCK_SIZE];
  sv [threadIdx.x + BLOCK_SIZE] = srcVal [index + BLOCK_SIZE];
  assert(threadIdx.x + BLOCK_SIZE < SIZE && index + BLOCK_SIZE < SIZE);

  for (uint size = 2; size < arrayLength; size <<= 1u )
  {
    // Битоническое слияние
    uint ddd = dir ^ ((threadIdx.x & (size / 2)) != 0);
    for (uint stride = size >> 1u; stride > 0; stride >>= 1u)
    {
      __syncthreads ();
      uint pos = 2 * threadIdx.x - (threadIdx.x & (stride - 1));
      assert(pos + stride < 2 * BLOCK_SIZE);
      Comparator( sk[pos], sv[pos], sk[pos+stride], sv[pos+stride], ddd);
    }
    __syncthreads();
  }

  for (uint stride = arrayLength >> 1u; stride > 0; stride >>= 1u)
  {
    __syncthreads ();
    uint pos = 2 * threadIdx.x - (threadIdx.x & (stride - 1));
    // assert(pos + stride < 2 * BLOCK_SIZE);
    Comparator( sk[pos], sv[pos], sk[pos + stride], sv[pos+stride], dir);
//    Comparator(srcKey[blockIdx.x * BLOCK_SIZE * 2 + pos], srcVal[blockIdx.x * BLOCK_SIZE * 2 + pos],
//               srcKey[blockIdx.x * BLOCK_SIZE * 2 + pos + stride], srcVal[blockIdx.x * BLOCK_SIZE * 2 + pos + stride], dir);
  }
  __syncthreads ();
  dstKey[index] = sk[threadIdx.x] ;
  dstVal[index] = sv[threadIdx.x] ;
  dstKey[index + BLOCK_SIZE] = sk[threadIdx.x + BLOCK_SIZE];
  dstVal[index + BLOCK_SIZE] = sv[threadIdx.x + BLOCK_SIZE];
}


__host__ int main()
{
  uint* key_arr = new uint[SIZE];
  uint* value_arr = new uint[SIZE];

  for (size_t i=0; i<SIZE; i++)
  {
    key_arr[i] = uint(rand()) % 100;
    value_arr[i] = i;
  }
  uint* dst_key_arr = new uint[SIZE];
  cudaMalloc((void **)&dst_key_arr, SIZE * sizeof(uint));
  uint* dst_value_arr = new uint[SIZE];
  cudaMalloc((void **)&dst_value_arr, SIZE * sizeof(uint));

  uint* cuda_key_arr;
  cudaMalloc((void **)&cuda_key_arr, SIZE * sizeof(uint));
  cudaMemcpy(cuda_key_arr, key_arr, SIZE * sizeof(uint),cudaMemcpyHostToDevice);

  uint* cuda_value_arr;
  cudaMalloc((void **)&cuda_value_arr, SIZE * sizeof(uint));
  cudaMemcpy(cuda_value_arr, value_arr, SIZE * sizeof(uint),cudaMemcpyHostToDevice);

  cudaEvent_t start, stop;
  float gpuTime = 0.0f;

//  printf("Elapsed time: %.2f\n", gpuTime);
//  for(size_t i=0; i<SIZE; i++)
//  {
//    std::cout << key_arr[i] << " ";
//  }
  std::cout << std::endl;

  cudaEventCreate (&start);
  cudaEventCreate (&stop);
  cudaEventRecord (start, 0);

  bitonicSortShared<<<dim3(SIZE / (2 * BLOCK_SIZE)), dim3(BLOCK_SIZE)>>>(dst_key_arr,
                                                                         dst_value_arr,
                                                                         cuda_key_arr,
                                                                         cuda_value_arr,
                                                                         SIZE,
                                                                         1);


  cudaEventRecord(stop, 0);
  cudaEventSynchronize(stop);
  cudaEventElapsedTime(&gpuTime, start, stop);

  cudaMemcpy(value_arr, dst_value_arr, SIZE * sizeof(uint), cudaMemcpyDeviceToHost);
  cudaMemcpy(key_arr, dst_key_arr, SIZE * sizeof(uint), cudaMemcpyDeviceToHost);


  printf("Elapsed time: %.2f\n", gpuTime);
  for(size_t i=0; i<SIZE-1; i++)
  {
    if (key_arr[i] > key_arr[i+1])
      std::cout << "Error " << key_arr[i] << "> " << key_arr[i+1] << std::endl;
  }
  std::cout << std::endl;



  delete [] key_arr;
  cudaFree(cuda_key_arr);
  cudaFree(cuda_value_arr);
  cudaFree(dst_value_arr);
  cudaFree(dst_key_arr);
}
	.file	"tmpxft_002f5665_00000000-6_lab5.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3639:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3639:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z10ComparatorRjS_S_S_j
	.type	_Z10ComparatorRjS_S_S_j, @function
_Z10ComparatorRjS_S_S_j:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE3635:
	.size	_Z10ComparatorRjS_S_S_j, .-_Z10ComparatorRjS_S_S_j
	.globl	_Z45__device_stub__Z17bitonicSortSharedPjS_S_S_jjPjS_S_S_jj
	.type	_Z45__device_stub__Z17bitonicSortSharedPjS_S_S_jjPjS_S_S_jj, @function
_Z45__device_stub__Z17bitonicSortSharedPjS_S_S_jjPjS_S_S_jj:
.LFB3661:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 12(%rsp)
	movl	%r9d, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L4
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z17bitonicSortSharedPjS_S_S_jj(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L4:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L6
	call	__stack_chk_fail@PLT
.L6:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3661:
	.size	_Z45__device_stub__Z17bitonicSortSharedPjS_S_S_jjPjS_S_S_jj, .-_Z45__device_stub__Z17bitonicSortSharedPjS_S_S_jjPjS_S_S_jj
	.globl	_Z17bitonicSortSharedPjS_S_S_jj
	.type	_Z17bitonicSortSharedPjS_S_S_jj, @function
_Z17bitonicSortSharedPjS_S_S_jj:
.LFB3662:
	.cfi_startproc
	endbr64
	jmp	_Z45__device_stub__Z17bitonicSortSharedPjS_S_S_jjPjS_S_S_jj
	.cfi_endproc
.LFE3662:
	.size	_Z17bitonicSortSharedPjS_S_S_jj, .-_Z17bitonicSortSharedPjS_S_S_jj
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"Elapsed time: %.2f\n"
.LC2:
	.string	"Error "
.LC3:
	.string	"> "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3636:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$8192, %edi
	movl	$100, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$104, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	call	_Znam@PLT
	movl	$8192, %edi
	movq	%rax, %rbx
	call	_Znam@PLT
	movq	%rax, %r12
.L11:
	call	rand@PLT
	xorl	%edx, %edx
	movl	%ebp, (%r12,%rbp,4)
	divl	%r13d
	movl	%edx, (%rbx,%rbp,4)
	incq	%rbp
	cmpq	$2048, %rbp
	jne	.L11
	movl	$8192, %edi
	leaq	_ZSt4cout(%rip), %r13
	call	_Znam@PLT
	movl	$8192, %esi
	leaq	16(%rsp), %rdi
	movq	%rax, 16(%rsp)
	call	cudaMalloc@PLT
	movl	$8192, %edi
	call	_Znam@PLT
	leaq	24(%rsp), %rdi
	movl	$8192, %esi
	movq	%rax, 24(%rsp)
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movl	$8192, %esi
	call	cudaMalloc@PLT
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$8192, %edx
	call	cudaMemcpy@PLT
	leaq	40(%rsp), %rdi
	movl	$8192, %esi
	call	cudaMalloc@PLT
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	movl	$8192, %edx
	call	cudaMemcpy@PLT
	movq	%r13, %rdi
	movl	$0x00000000, 12(%rsp)
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$10, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L12
	movq	40(%rsp), %rcx
	movq	32(%rsp), %rdx
	movl	$1, %r9d
	movl	$2048, %r8d
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	call	_Z45__device_stub__Z17bitonicSortSharedPjS_S_S_jjPjS_S_S_jj
.L12:
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	xorl	%ebp, %ebp
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	leaq	12(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	24(%rsp), %rsi
	movq	%r12, %rdi
	movl	$2, %ecx
	movl	$8192, %edx
	leaq	.LC2(%rip), %r12
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	movl	$8192, %edx
	call	cudaMemcpy@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	12(%rsp), %xmm0
	call	__printf_chk@PLT
.L14:
	movl	(%rbx,%rbp,4), %eax
	incq	%rbp
	cmpl	%eax, (%rbx,%rbp,4)
	jnb	.L13
	movq	%r12, %rsi
	movq	%r13, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	-4(%rbx,%rbp,4), %esi
	movq	%rax, %rdi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	(%rbx,%rbp,4), %esi
	movq	%rax, %rdi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
.L13:
	cmpq	$2047, %rbp
	jne	.L14
	movq	%r13, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	%rbx, %rdi
	call	_ZdaPv@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$104, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3636:
	.size	main, .-main
	.section	.rodata.str1.1
.LC4:
	.string	"_Z17bitonicSortSharedPjS_S_S_jj"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3664:
	.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	_Z17bitonicSortSharedPjS_S_S_jj(%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
.LFE3664:
	.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
	.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 <cstdio>
#include <cstdlib>
#include <iostream>
#include <cassert>
constexpr size_t BLOCK_SIZE = 1024; // Размер блока.
constexpr size_t SIZE = 2048;

// Отдельный компаратор  сравнивает пару ключей
// и производит обмен соответствующих элементов и
// ключей для обеспечения заданного порядка.
__device__ void Comparator (uint& keyA, uint& valA, uint& keyB, uint& valB, uint dir) {
  uint t;
  // Поменять местами (keyA, valA) и (keyB, valB)
  if ( (keyA > keyB) == dir ) {
    t = keyA;
    keyA = keyB;
    keyB = t;
    t = valA;
    valA = valB;
    valB = t;
  }
}

__global__ void bitonicSortShared (uint* dstKey,
                                   uint* dstVal,
                                   uint* srcKey,
                                   uint* srcVal,
                                   uint arrayLength,
                                   uint dir) {
  __shared__ uint sk [BLOCK_SIZE * 2];
  __shared__ uint sv [BLOCK_SIZE * 2];
  int index = blockIdx.x * BLOCK_SIZE * 2 + threadIdx.x;
  sk [threadIdx.x] = srcKey[index];
  sv [threadIdx.x] = srcVal[index];
  sk [threadIdx.x + BLOCK_SIZE] = srcKey [index + BLOCK_SIZE];
  sv [threadIdx.x + BLOCK_SIZE] = srcVal [index + BLOCK_SIZE];
  assert(threadIdx.x + BLOCK_SIZE < SIZE && index + BLOCK_SIZE < SIZE);

  for (uint size = 2; size < arrayLength; size <<= 1u )
  {
    // Битоническое слияние
    uint ddd = dir ^ ((threadIdx.x & (size / 2)) != 0);
    for (uint stride = size >> 1u; stride > 0; stride >>= 1u)
    {
      __syncthreads ();
      uint pos = 2 * threadIdx.x - (threadIdx.x & (stride - 1));
      assert(pos + stride < 2 * BLOCK_SIZE);
      Comparator( sk[pos], sv[pos], sk[pos+stride], sv[pos+stride], ddd);
    }
    __syncthreads();
  }

  for (uint stride = arrayLength >> 1u; stride > 0; stride >>= 1u)
  {
    __syncthreads ();
    uint pos = 2 * threadIdx.x - (threadIdx.x & (stride - 1));
    // assert(pos + stride < 2 * BLOCK_SIZE);
    Comparator( sk[pos], sv[pos], sk[pos + stride], sv[pos+stride], dir);
//    Comparator(srcKey[blockIdx.x * BLOCK_SIZE * 2 + pos], srcVal[blockIdx.x * BLOCK_SIZE * 2 + pos],
//               srcKey[blockIdx.x * BLOCK_SIZE * 2 + pos + stride], srcVal[blockIdx.x * BLOCK_SIZE * 2 + pos + stride], dir);
  }
  __syncthreads ();
  dstKey[index] = sk[threadIdx.x] ;
  dstVal[index] = sv[threadIdx.x] ;
  dstKey[index + BLOCK_SIZE] = sk[threadIdx.x + BLOCK_SIZE];
  dstVal[index + BLOCK_SIZE] = sv[threadIdx.x + BLOCK_SIZE];
}


__host__ int main()
{
  uint* key_arr = new uint[SIZE];
  uint* value_arr = new uint[SIZE];

  for (size_t i=0; i<SIZE; i++)
  {
    key_arr[i] = uint(rand()) % 100;
    value_arr[i] = i;
  }
  uint* dst_key_arr = new uint[SIZE];
  hipMalloc((void **)&dst_key_arr, SIZE * sizeof(uint));
  uint* dst_value_arr = new uint[SIZE];
  hipMalloc((void **)&dst_value_arr, SIZE * sizeof(uint));

  uint* cuda_key_arr;
  hipMalloc((void **)&cuda_key_arr, SIZE * sizeof(uint));
  hipMemcpy(cuda_key_arr, key_arr, SIZE * sizeof(uint),hipMemcpyHostToDevice);

  uint* cuda_value_arr;
  hipMalloc((void **)&cuda_value_arr, SIZE * sizeof(uint));
  hipMemcpy(cuda_value_arr, value_arr, SIZE * sizeof(uint),hipMemcpyHostToDevice);

  hipEvent_t start, stop;
  float gpuTime = 0.0f;

//  printf("Elapsed time: %.2f\n", gpuTime);
//  for(size_t i=0; i<SIZE; i++)
//  {
//    std::cout << key_arr[i] << " ";
//  }
  std::cout << std::endl;

  hipEventCreate (&start);
  hipEventCreate (&stop);
  hipEventRecord (start, 0);

  bitonicSortShared<<<dim3(SIZE / (2 * BLOCK_SIZE)), dim3(BLOCK_SIZE)>>>(dst_key_arr,
                                                                         dst_value_arr,
                                                                         cuda_key_arr,
                                                                         cuda_value_arr,
                                                                         SIZE,
                                                                         1);


  hipEventRecord(stop, 0);
  hipEventSynchronize(stop);
  hipEventElapsedTime(&gpuTime, start, stop);

  hipMemcpy(value_arr, dst_value_arr, SIZE * sizeof(uint), hipMemcpyDeviceToHost);
  hipMemcpy(key_arr, dst_key_arr, SIZE * sizeof(uint), hipMemcpyDeviceToHost);


  printf("Elapsed time: %.2f\n", gpuTime);
  for(size_t i=0; i<SIZE-1; i++)
  {
    if (key_arr[i] > key_arr[i+1])
      std::cout << "Error " << key_arr[i] << "> " << key_arr[i+1] << std::endl;
  }
  std::cout << std::endl;



  delete [] key_arr;
  hipFree(cuda_key_arr);
  hipFree(cuda_value_arr);
  hipFree(dst_value_arr);
  hipFree(dst_key_arr);
}
	.text
	.file	"lab5.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z32__device_stub__bitonicSortSharedPjS_S_S_jj # -- Begin function _Z32__device_stub__bitonicSortSharedPjS_S_S_jj
	.type	_Z32__device_stub__bitonicSortSharedPjS_S_S_jj,@function
_Z32__device_stub__bitonicSortSharedPjS_S_S_jj: # @_Z32__device_stub__bitonicSortSharedPjS_S_S_jj
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	12(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	8(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%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	$_Z17bitonicSortSharedPjS_S_S_jj, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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	_Z32__device_stub__bitonicSortSharedPjS_S_S_jj, .Lfunc_end0-_Z32__device_stub__bitonicSortSharedPjS_S_S_jj
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$64, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	$8192, %edi                     # imm = 0x2000
	callq	_Znam
	movq	%rax, %rbx
	movl	$8192, %edi                     # imm = 0x2000
	callq	_Znam
	movq	%rax, %r14
	xorl	%r15d, %r15d
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	movl	%eax, %ecx
	imulq	$1374389535, %rcx, %rcx         # imm = 0x51EB851F
	shrq	$37, %rcx
	imull	$100, %ecx, %ecx
	subl	%ecx, %eax
	movl	%eax, (%rbx,%r15,4)
	movl	%r15d, (%r14,%r15,4)
	incq	%r15
	cmpq	$2048, %r15                     # imm = 0x800
	jne	.LBB1_1
# %bb.2:
	movl	$8192, %edi                     # imm = 0x2000
	callq	_Znam
	leaq	24(%rsp), %rdi
	movq	%rax, (%rdi)
	movl	$8192, %esi                     # imm = 0x2000
	callq	hipMalloc
	movl	$8192, %edi                     # imm = 0x2000
	callq	_Znam
	leaq	16(%rsp), %rdi
	movq	%rax, (%rdi)
	movl	$8192, %esi                     # imm = 0x2000
	callq	hipMalloc
	leaq	48(%rsp), %r15
	movl	$8192, %esi                     # imm = 0x2000
	movq	%r15, %rdi
	callq	hipMalloc
	movq	(%r15), %rdi
	movl	$8192, %edx                     # imm = 0x2000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	40(%rsp), %r15
	movl	$8192, %esi                     # imm = 0x2000
	movq	%r15, %rdi
	callq	hipMalloc
	movq	(%r15), %rdi
	movl	$8192, %edx                     # imm = 0x2000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$0, 36(%rsp)
	movl	$_ZSt4cout, %eax
	movq	_ZSt4cout(%rip), %rcx
	movq	-24(%rcx), %rdi
	addq	%rax, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	leaq	56(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventCreate
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	leaq	1023(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_4
# %bb.3:
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rcx
	movl	$2048, %r8d                     # imm = 0x800
	movl	$1, %r9d
	callq	_Z32__device_stub__bitonicSortSharedPjS_S_S_jj
.LBB1_4:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	movq	56(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	36(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventElapsedTime
	movq	16(%rsp), %rsi
	movl	$8192, %edx                     # imm = 0x2000
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	24(%rsp), %rsi
	movl	$8192, %edx                     # imm = 0x2000
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	cvtss2sd	(%r15), %xmm0
	movl	$.L.str, %edi
	movb	$1, %al
	callq	printf
	movl	$1, %r15d
.LBB1_5:                                # =>This Inner Loop Header: Depth=1
	movl	-4(%rbx,%r15,4), %eax
	cmpl	(%rbx,%r15,4), %eax
	jbe	.LBB1_7
# %bb.6:                                #   in Loop: Header=BB1_5 Depth=1
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$6, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	-4(%rbx,%r15,4), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertImEERSoT_
	movq	%rax, %r14
	movl	$.L.str.2, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	(%rbx,%r15,4), %esi
	movq	%r14, %rdi
	callq	_ZNSo9_M_insertImEERSoT_
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB1_7:                                #   in Loop: Header=BB1_5 Depth=1
	incq	%r15
	cmpq	$2048, %r15                     # imm = 0x800
	jne	.LBB1_5
# %bb.8:
	movq	_ZSt4cout(%rip), %rax
	movl	$_ZSt4cout, %ecx
	movq	-24(%rax), %rdi
	addq	%rcx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rbx, %rdi
	callq	_ZdaPv
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$64, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	main, .Lfunc_end1-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	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z17bitonicSortSharedPjS_S_S_jj, %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_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z17bitonicSortSharedPjS_S_S_jj,@object # @_Z17bitonicSortSharedPjS_S_S_jj
	.section	.rodata,"a",@progbits
	.globl	_Z17bitonicSortSharedPjS_S_S_jj
	.p2align	3, 0x0
_Z17bitonicSortSharedPjS_S_S_jj:
	.quad	_Z32__device_stub__bitonicSortSharedPjS_S_S_jj
	.size	_Z17bitonicSortSharedPjS_S_S_jj, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Elapsed time: %.2f\n"
	.size	.L.str, 20

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Error "
	.size	.L.str.1, 7

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"> "
	.size	.L.str.2, 3

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z17bitonicSortSharedPjS_S_S_jj"
	.size	.L__unnamed_1, 32

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

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z32__device_stub__bitonicSortSharedPjS_S_S_jj
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z17bitonicSortSharedPjS_S_S_jj
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z17bitonicSortSharedPjS_S_S_jj ; -- Begin function _Z17bitonicSortSharedPjS_S_S_jj
	.globl	_Z17bitonicSortSharedPjS_S_S_jj
	.p2align	8
	.type	_Z17bitonicSortSharedPjS_S_S_jj,@function
_Z17bitonicSortSharedPjS_S_S_jj:        ; @_Z17bitonicSortSharedPjS_S_S_jj
; %bb.0:
	s_load_b256 s[4:11], s[0:1], 0x0
	v_lshl_or_b32 v3, s15, 11, v0
	s_load_b64 s[0:1], s[0:1], 0x20
	s_mov_b32 s2, 2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v4, 31, v3
	v_lshlrev_b64 v[1:2], 2, v[3:4]
	v_or_b32_e32 v3, 0x400, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[3:4], 2, v[3:4]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v5, vcc_lo, s8, v1
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v6, vcc_lo, s9, v2, vcc_lo
	v_add_co_u32 v7, vcc_lo, s10, v1
	v_add_co_ci_u32_e32 v8, vcc_lo, s11, v2, vcc_lo
	v_add_co_u32 v9, vcc_lo, s8, v3
	v_add_co_ci_u32_e32 v10, vcc_lo, s9, v4, vcc_lo
	v_add_co_u32 v11, vcc_lo, s10, v3
	v_add_co_ci_u32_e32 v12, vcc_lo, s11, v4, vcc_lo
	global_load_b32 v6, v[5:6], off
	global_load_b32 v7, v[7:8], off
	global_load_b32 v8, v[9:10], off
	global_load_b32 v9, v[11:12], off
	v_lshlrev_b32_e32 v5, 2, v0
	s_cmp_lt_u32 s0, 3
	s_waitcnt vmcnt(1)
	ds_store_2addr_stride64_b32 v5, v6, v8 offset1:16
	s_waitcnt vmcnt(0)
	ds_store_2addr_stride64_b32 v5, v7, v9 offset0:32 offset1:48
	s_cbranch_scc1 .LBB0_8
; %bb.1:                                ; %.lr.ph55
	v_lshlrev_b32_e32 v6, 1, v0
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
	s_cmp_eq_u32 s2, 0
	s_cbranch_scc1 .LBB0_7
; %bb.3:                                ; %.lr.ph.preheader
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_lshr_b32 s3, s2, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_and_b32_e32 v7, s3, v0
	s_mov_b32 s3, s2
	v_cmp_ne_u32_e32 vcc_lo, 0, v7
	v_cndmask_b32_e64 v7, 0, 1, vcc_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_xor_b32_e32 v7, s1, v7
.LBB0_4:                                ; %.lr.ph
                                        ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_lshr_b32 s8, s3, 1
	s_waitcnt lgkmcnt(0)
	s_add_i32 s9, s8, -1
	s_barrier
	v_and_b32_e32 v8, s9, v0
	buffer_gl0_inv
	s_mov_b32 s9, exec_lo
	v_sub_nc_u32_e32 v11, v6, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b32_e32 v8, 2, v11
	v_lshl_add_u32 v9, s8, 2, v8
	ds_load_b32 v10, v8
	ds_load_b32 v12, v9
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_u32_e32 vcc_lo, v10, v12
	v_cndmask_b32_e64 v13, 0, 1, vcc_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_eq_u32_e64 v7, v13
	s_cbranch_execz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_4 Depth=2
	v_add_lshl_u32 v11, v11, s8, 2
	ds_load_b32 v13, v11 offset:8192
	ds_load_b32 v14, v8 offset:8192
	ds_store_b32 v8, v12
	ds_store_b32 v9, v10
	s_waitcnt lgkmcnt(3)
	ds_store_b32 v8, v13 offset:8192
	s_waitcnt lgkmcnt(3)
	ds_store_b32 v11, v14 offset:8192
.LBB0_6:                                ; %_Z10ComparatorRjS_S_S_j.exit
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_or_b32 exec_lo, exec_lo, s9
	s_cmp_lt_u32 s3, 4
	s_mov_b32 s3, s8
	s_cbranch_scc0 .LBB0_4
.LBB0_7:                                ; %._crit_edge
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_lshl_b32 s2, s2, 1
	s_waitcnt lgkmcnt(0)
	s_cmp_ge_u32 s2, s0
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_2
.LBB0_8:                                ; %.preheader
	v_or_b32_e32 v6, 0x2000, v5
	s_cmp_lt_u32 s0, 2
	s_cbranch_scc1 .LBB0_13
; %bb.9:                                ; %.lr.ph58
	v_lshlrev_b32_e32 v7, 1, v0
.LBB0_10:                               ; =>This Inner Loop Header: Depth=1
	s_lshr_b32 s2, s0, 1
	s_waitcnt lgkmcnt(0)
	s_add_i32 s3, s2, -1
	s_barrier
	v_and_b32_e32 v8, s3, v0
	buffer_gl0_inv
	s_mov_b32 s3, exec_lo
	v_sub_nc_u32_e32 v11, v7, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b32_e32 v8, 2, v11
	v_lshl_add_u32 v9, s2, 2, v8
	ds_load_b32 v10, v8
	ds_load_b32 v12, v9
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_u32_e32 vcc_lo, v10, v12
	v_cndmask_b32_e64 v13, 0, 1, vcc_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_eq_u32_e64 s1, v13
	s_cbranch_execz .LBB0_12
; %bb.11:                               ;   in Loop: Header=BB0_10 Depth=1
	v_add_lshl_u32 v11, v11, s2, 2
	ds_load_b32 v13, v11 offset:8192
	ds_load_b32 v14, v8 offset:8192
	ds_store_b32 v8, v12
	ds_store_b32 v9, v10
	s_waitcnt lgkmcnt(3)
	ds_store_b32 v8, v13 offset:8192
	s_waitcnt lgkmcnt(3)
	ds_store_b32 v11, v14 offset:8192
.LBB0_12:                               ; %_Z10ComparatorRjS_S_S_j.exit50
                                        ;   in Loop: Header=BB0_10 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_cmp_lt_u32 s0, 4
	s_mov_b32 s0, s2
	s_cbranch_scc0 .LBB0_10
.LBB0_13:                               ; %._crit_edge59
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_2addr_stride64_b32 v[7:8], v5 offset1:16
	ds_load_2addr_stride64_b32 v[5:6], v6 offset1:16
	v_add_co_u32 v9, vcc_lo, s4, v1
	v_add_co_ci_u32_e32 v10, vcc_lo, s5, v2, vcc_lo
	v_add_co_u32 v0, vcc_lo, s6, v1
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v2, vcc_lo
	v_add_co_u32 v11, vcc_lo, s4, v3
	v_add_co_ci_u32_e32 v12, vcc_lo, s5, v4, vcc_lo
	v_add_co_u32 v2, vcc_lo, s6, v3
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v4, vcc_lo
	s_waitcnt lgkmcnt(1)
	global_store_b32 v[9:10], v7, off
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[0:1], v5, off
	global_store_b32 v[11:12], v8, off
	global_store_b32 v[2:3], v6, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z17bitonicSortSharedPjS_S_S_jj
		.amdhsa_group_segment_fixed_size 16384
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 40
		.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 15
		.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	_Z17bitonicSortSharedPjS_S_S_jj, .Lfunc_end0-_Z17bitonicSortSharedPjS_S_S_jj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 776
; NumSgprs: 18
; NumVgprs: 15
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 16384 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 15
; 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:     by_value
      - .offset:         36
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 16384
    .kernarg_segment_align: 8
    .kernarg_segment_size: 40
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z17bitonicSortSharedPjS_S_S_jj
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z17bitonicSortSharedPjS_S_S_jj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     15
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
