#include <cuda.h>
#include <iostream>
#include <random>
#include <chrono>

#define N 300000
#define BLOCK_SIZE_X 1024

#define checkCudaErrors(msg) err_msg(msg, __LINE__)

void err_msg(cudaError_t msg, int x)
{
 if (msg != cudaSuccess) {
   std::cerr << "In line: " << x << ". error: " << cudaGetErrorString(msg) << std::endl;
   exit(1);
 }

 return;
}

__global__ void findMax(float *x, float *y, float *z, int full_size, int half_size)
{
  int index = threadIdx.x + blockIdx.x * blockDim.x;
  int stride = blockDim.x * gridDim.x;

  for (int i = index; i < half_size; i += stride) {
    x[i] = (i + half_size < full_size) ? ((x[i] >= x[i + half_size]) ? x[i] : x[i + half_size]) : x[i];
    y[i] = (i + half_size < full_size) ? ((y[i] >= y[i + half_size]) ? y[i] : y[i + half_size]) : y[i];
    z[i] = (i + half_size < full_size) ? ((z[i] >= z[i + half_size]) ? z[i] : z[i + half_size]) : z[i];
  }
}

__global__ void findMin(float *x, float *y, float *z, int full_size, int half_size)
{
  int index = threadIdx.x + blockIdx.x * blockDim.x;
  int stride = blockDim.x * gridDim.x;

  for (int i = index; i < half_size; i += stride) {
    x[i] = (i + half_size < full_size) ? ((x[i] <= x[i + half_size]) ? x[i] : x[i + half_size]) : x[i];
    y[i] = (i + half_size < full_size) ? ((y[i] <= y[i + half_size]) ? y[i] : y[i + half_size]) : y[i];
    z[i] = (i + half_size < full_size) ? ((z[i] <= z[i + half_size]) ? z[i] : z[i + half_size]) : z[i];
  }
}

int main()
{
  int points_num = N;
  float *x, *y, *z;
  float *max_x, *max_y, *max_z, *min_x, *min_y, *min_z;
  float a_max_x, a_min_x, a_max_y, a_min_y, a_max_z, a_min_z;
  float *d_x, *d_y, *d_z;

  std::chrono::time_point<std::chrono::system_clock> start, end;
  double time;

  x = new float[N];
  y = new float[N];
  z = new float[N];

  std::mt19937 mt(10);

  for (int i = 0; i < N; i++) {
    x[i] = mt() / 10000.0;
    y[i] = mt() / 10000.0;
    z[i] = mt() / 10000.0;
  }

  
  start = std::chrono::system_clock::now();

  a_max_x = a_min_x = x[0];
  a_max_y = a_min_y = y[0];
  a_max_z = a_min_z = z[0];

  for (int i = 1; i < N; i++) {
    a_max_x = (a_max_x > x[i]) ? a_max_x : x[i];
    a_min_x = (a_min_x < x[i]) ? a_min_x : x[i];

    a_max_y = (a_max_y > y[i]) ? a_max_y : y[i];
    a_min_y = (a_min_y < y[i]) ? a_min_y : y[i];

    a_max_z = (a_max_z > z[i]) ? a_max_z : z[i];
    a_min_z = (a_min_z < z[i]) ? a_min_z : z[i];
  }

  end = std::chrono::system_clock::now();

  time = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / 1000.0;

  std::cout << "CPU sort: " << time << "ms." << std::endl;

  checkCudaErrors(cudaMalloc(&d_x, sizeof(float) * points_num));
  checkCudaErrors(cudaMalloc(&d_y, sizeof(float) * points_num));
  checkCudaErrors(cudaMalloc(&d_z, sizeof(float) * points_num));

  checkCudaErrors(cudaMemcpy(d_x, x, sizeof(float) * points_num, cudaMemcpyHostToDevice));
  checkCudaErrors(cudaMemcpy(d_y, y, sizeof(float) * points_num, cudaMemcpyHostToDevice));
  checkCudaErrors(cudaMemcpy(d_z, z, sizeof(float) * points_num, cudaMemcpyHostToDevice));

  start = std::chrono::system_clock::now();

  checkCudaErrors(cudaMalloc(&max_x, sizeof(float) * points_num));
  checkCudaErrors(cudaMalloc(&max_y, sizeof(float) * points_num));
  checkCudaErrors(cudaMalloc(&max_z, sizeof(float) * points_num));
  checkCudaErrors(cudaMalloc(&min_x, sizeof(float) * points_num));
  checkCudaErrors(cudaMalloc(&min_y, sizeof(float) * points_num));
  checkCudaErrors(cudaMalloc(&min_z, sizeof(float) * points_num));

  checkCudaErrors(cudaMemcpy(max_x, d_x, sizeof(float) * points_num, cudaMemcpyDeviceToDevice));
  checkCudaErrors(cudaMemcpy(max_y, d_y, sizeof(float) * points_num, cudaMemcpyDeviceToDevice));
  checkCudaErrors(cudaMemcpy(max_z, d_z, sizeof(float) * points_num, cudaMemcpyDeviceToDevice));

  checkCudaErrors(cudaMemcpy(min_x, d_x, sizeof(float) * points_num, cudaMemcpyDeviceToDevice));
  checkCudaErrors(cudaMemcpy(min_y, d_y, sizeof(float) * points_num, cudaMemcpyDeviceToDevice));
  checkCudaErrors(cudaMemcpy(min_z, d_z, sizeof(float) * points_num, cudaMemcpyDeviceToDevice));

  while (points_num > 1) {
    int half_points_num = (points_num - 1) / 2 + 1;
    int block_x = (half_points_num > BLOCK_SIZE_X) ? BLOCK_SIZE_X : half_points_num;
    int grid_x = (half_points_num - 1) / block_x + 1;

    findMax<<<grid_x, block_x>>>(max_x, max_y, max_z, points_num, half_points_num);
    checkCudaErrors(cudaGetLastError());

    findMin<<<grid_x, block_x>>>(min_x, min_y, min_z, points_num, half_points_num);
    checkCudaErrors(cudaGetLastError());

    points_num = half_points_num;
  }

  checkCudaErrors(cudaDeviceSynchronize());

  checkCudaErrors(cudaMemcpy(&a_max_x, max_x, sizeof(float), cudaMemcpyDeviceToHost));
  checkCudaErrors(cudaMemcpy(&a_max_y, max_y, sizeof(float), cudaMemcpyDeviceToHost));
  checkCudaErrors(cudaMemcpy(&a_max_z, max_z, sizeof(float), cudaMemcpyDeviceToHost));

  checkCudaErrors(cudaMemcpy(&a_min_x, min_x, sizeof(float), cudaMemcpyDeviceToHost));
  checkCudaErrors(cudaMemcpy(&a_min_y, min_y, sizeof(float), cudaMemcpyDeviceToHost));
  checkCudaErrors(cudaMemcpy(&a_min_z, min_z, sizeof(float), cudaMemcpyDeviceToHost));

  end = std::chrono::system_clock::now();

  time = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / 1000.0;

  std::cout << "GPU sort: " << time << "ms." << std::endl;

  checkCudaErrors(cudaFree(max_x));
  checkCudaErrors(cudaFree(max_y));
  checkCudaErrors(cudaFree(max_z));
  checkCudaErrors(cudaFree(min_x));
  checkCudaErrors(cudaFree(min_y));
  checkCudaErrors(cudaFree(min_z));
  checkCudaErrors(cudaFree(d_x));
  checkCudaErrors(cudaFree(d_y));
  checkCudaErrors(cudaFree(d_z));

  delete[] x;
  delete[] y;
  delete[] z;

  return 0;
}
	.file	"tmpxft_00214bcd_00000000-6_sort.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4828:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4828:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"In line: "
.LC1:
	.string	". error: "
	.text
	.globl	_Z7err_msg9cudaErrori
	.type	_Z7err_msg9cudaErrori, @function
_Z7err_msg9cudaErrori:
.LFB4818:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L2
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%esi, %ebp
	leaq	.LC0(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	leaq	_ZSt4cerr(%rip), %rdi
	pushq	%rax
	.cfi_def_cfa_offset 32
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebx, %edi
	movq	%rax, %rbp
	call	cudaGetErrorString@PLT
	movq	%rbp, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	$1, %edi
	call	exit@PLT
.L2:
	.cfi_def_cfa_offset 8
	.cfi_restore 3
	.cfi_restore 6
	ret
	.cfi_endproc
.LFE4818:
	.size	_Z7err_msg9cudaErrori, .-_Z7err_msg9cudaErrori
	.globl	_Z32__device_stub__Z7findMaxPfS_S_iiPfS_S_ii
	.type	_Z32__device_stub__Z7findMaxPfS_S_iiPfS_S_ii, @function
_Z32__device_stub__Z7findMaxPfS_S_iiPfS_S_ii:
.LFB4850:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z7findMaxPfS_S_ii(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L8:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4850:
	.size	_Z32__device_stub__Z7findMaxPfS_S_iiPfS_S_ii, .-_Z32__device_stub__Z7findMaxPfS_S_iiPfS_S_ii
	.globl	_Z7findMaxPfS_S_ii
	.type	_Z7findMaxPfS_S_ii, @function
_Z7findMaxPfS_S_ii:
.LFB4851:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z7findMaxPfS_S_iiPfS_S_ii
	.cfi_endproc
.LFE4851:
	.size	_Z7findMaxPfS_S_ii, .-_Z7findMaxPfS_S_ii
	.globl	_Z32__device_stub__Z7findMinPfS_S_iiPfS_S_ii
	.type	_Z32__device_stub__Z7findMinPfS_S_iiPfS_S_ii, @function
_Z32__device_stub__Z7findMinPfS_S_iiPfS_S_ii:
.LFB4852:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z7findMinPfS_S_ii(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L13:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4852:
	.size	_Z32__device_stub__Z7findMinPfS_S_iiPfS_S_ii, .-_Z32__device_stub__Z7findMinPfS_S_iiPfS_S_ii
	.globl	_Z7findMinPfS_S_ii
	.type	_Z7findMinPfS_S_ii, @function
_Z7findMinPfS_S_ii:
.LFB4853:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z7findMinPfS_S_iiPfS_S_ii
	.cfi_endproc
.LFE4853:
	.size	_Z7findMinPfS_S_ii, .-_Z7findMinPfS_S_ii
	.section	.rodata.str1.1
.LC2:
	.string	"_Z7findMinPfS_S_ii"
.LC3:
	.string	"_Z7findMaxPfS_S_ii"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4855:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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	.LC2(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z7findMinPfS_S_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC3(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z7findMaxPfS_S_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	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	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4855:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv,"axG",@progbits,_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv,comdat
	.align 2
	.weak	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
	.type	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv, @function
_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv:
.LFB5377:
	.cfi_startproc
	endbr64
	movq	%rdi, %rax
	xorl	%edx, %edx
	movl	$2567483615, %edi
.L22:
	movq	(%rax,%rdx,8), %rsi
	incq	%rdx
	movq	(%rax,%rdx,8), %rcx
	andq	$-2147483648, %rsi
	andl	$2147483647, %ecx
	orq	%rsi, %rcx
	movq	%rcx, %rsi
	shrq	%rsi
	xorq	3168(%rax,%rdx,8), %rsi
	andl	$1, %ecx
	je	.L21
	movq	%rdi, %rcx
.L21:
	xorq	%rsi, %rcx
	movq	%rcx, -8(%rax,%rdx,8)
	cmpq	$227, %rdx
	jne	.L22
	movl	$2567483615, %edi
.L24:
	movq	(%rax,%rdx,8), %rsi
	incq	%rdx
	movq	(%rax,%rdx,8), %rcx
	andq	$-2147483648, %rsi
	andl	$2147483647, %ecx
	orq	%rsi, %rcx
	movq	%rcx, %rsi
	shrq	%rsi
	xorq	-1824(%rax,%rdx,8), %rsi
	andl	$1, %ecx
	je	.L23
	movq	%rdi, %rcx
.L23:
	xorq	%rsi, %rcx
	movq	%rcx, -8(%rax,%rdx,8)
	cmpq	$623, %rdx
	jne	.L24
	movq	4984(%rax), %rdx
	movq	(%rax), %rcx
	andq	$-2147483648, %rdx
	andl	$2147483647, %ecx
	orq	%rcx, %rdx
	movq	%rdx, %rcx
	shrq	%rcx
	xorq	3168(%rax), %rcx
	andl	$1, %edx
	je	.L25
	movl	$2567483615, %edx
.L25:
	xorq	%rcx, %rdx
	movq	%rdx, 4984(%rax)
	xorl	%edx, %edx
	movq	%rdx, 4992(%rax)
	ret
	.cfi_endproc
.LFE5377:
	.size	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv, .-_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
	.section	.text._ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv,"axG",@progbits,_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv,comdat
	.align 2
	.weak	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	.type	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv, @function
_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv:
.LFB5203:
	.cfi_startproc
	endbr64
	cmpq	$623, 4992(%rdi)
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	jbe	.L38
	call	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
.L38:
	movq	4992(%rbx), %rax
	leaq	1(%rax), %rdx
	movq	(%rbx,%rax,8), %rax
	movq	%rdx, 4992(%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 8
	movq	%rax, %rdx
	shrq	$11, %rdx
	movl	%edx, %edx
	xorq	%rax, %rdx
	movq	%rdx, %rax
	salq	$7, %rax
	andl	$2636928640, %eax
	xorq	%rdx, %rax
	movq	%rax, %rdx
	salq	$15, %rdx
	andl	$4022730752, %edx
	xorq	%rax, %rdx
	movq	%rdx, %rax
	shrq	$18, %rax
	xorq	%rdx, %rax
	ret
	.cfi_endproc
.LFE5203:
	.size	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv, .-_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	.section	.rodata.str1.1
.LC6:
	.string	"CPU sort: "
.LC7:
	.string	"ms."
.LC8:
	.string	"GPU sort: "
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB4819:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$4096, %rsp
	.cfi_def_cfa_offset 4152
	orq	$0, (%rsp)
	subq	$1080, %rsp
	.cfi_def_cfa_offset 5232
	movl	$1200000, %edi
	movq	%fs:40, %rax
	movq	%rax, 5160(%rsp)
	xorl	%eax, %eax
	leaq	160(%rsp), %r14
	call	_Znam@PLT
	movl	$1200000, %edi
	movq	%rax, %r12
	call	_Znam@PLT
	movl	$1200000, %edi
	movq	%rax, %rbp
	call	_Znam@PLT
	movl	$1, %edx
	movq	$10, 160(%rsp)
	movq	%rax, %rbx
.L41:
	movq	-8(%r14,%rdx,8), %rax
	movq	%rax, %rcx
	shrq	$30, %rcx
	xorq	%rcx, %rax
	imulq	$1812433253, %rax, %rax
	addl	%edx, %eax
	movq	%rax, (%r14,%rdx,8)
	incq	%rdx
	cmpq	$624, %rdx
	jne	.L41
	movq	$624, 5152(%rsp)
	xorl	%r13d, %r13d
.L48:
	movq	%r14, %rdi
	call	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	testq	%rax, %rax
	js	.L42
	cvtsi2sdq	%rax, %xmm0
	jmp	.L43
.L42:
	movq	%rax, %rdx
	andl	$1, %eax
	shrq	%rdx
	orq	%rax, %rdx
	cvtsi2sdq	%rdx, %xmm0
	addsd	%xmm0, %xmm0
.L43:
	divsd	.LC4(%rip), %xmm0
	movq	%r14, %rdi
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r12,%r13)
	call	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	testq	%rax, %rax
	js	.L44
	cvtsi2sdq	%rax, %xmm0
	jmp	.L45
.L44:
	movq	%rax, %rdx
	andl	$1, %eax
	shrq	%rdx
	orq	%rax, %rdx
	cvtsi2sdq	%rdx, %xmm0
	addsd	%xmm0, %xmm0
.L45:
	divsd	.LC4(%rip), %xmm0
	movq	%r14, %rdi
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 0(%rbp,%r13)
	call	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	testq	%rax, %rax
	js	.L46
	cvtsi2sdq	%rax, %xmm0
	jmp	.L47
.L46:
	movq	%rax, %rdx
	andl	$1, %eax
	shrq	%rdx
	orq	%rax, %rdx
	cvtsi2sdq	%rdx, %xmm0
	addsd	%xmm0, %xmm0
.L47:
	divsd	.LC4(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rbx,%r13)
	addq	$4, %r13
	cmpq	$1200000, %r13
	jne	.L48
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movss	(%r12), %xmm2
	movss	0(%rbp), %xmm1
	movl	$4, %edx
	movss	(%rbx), %xmm0
	movq	%rax, %r13
	movaps	%xmm1, %xmm4
	movaps	%xmm2, %xmm5
	movaps	%xmm0, %xmm3
.L61:
	movss	(%r12,%rdx), %xmm6
	maxss	%xmm6, %xmm2
	minss	%xmm6, %xmm5
	movss	0(%rbp,%rdx), %xmm6
	maxss	%xmm6, %xmm1
	minss	%xmm6, %xmm4
	movss	(%rbx,%rdx), %xmm6
	addq	$4, %rdx
	maxss	%xmm6, %xmm0
	minss	%xmm6, %xmm3
	cmpq	$1200000, %rdx
	jne	.L61
	movss	%xmm2, 40(%rsp)
	movabsq	$4294967297, %r15
	movss	%xmm5, 44(%rsp)
	movss	%xmm1, 48(%rsp)
	movss	%xmm4, 52(%rsp)
	movss	%xmm3, 60(%rsp)
	movss	%xmm0, 56(%rsp)
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	$1000, %ecx
	leaq	.LC6(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	subq	%r13, %rax
	movl	$300000, %r13d
	cqto
	idivq	%rcx
	cvtsi2sdq	%rax, %xmm0
	divsd	.LC5(%rip), %xmm0
	movsd	%xmm0, 8(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	8(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC7(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	leaq	112(%rsp), %rdi
	movl	$1200000, %esi
	call	cudaMalloc@PLT
	movl	$92, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	leaq	120(%rsp), %rdi
	movl	$1200000, %esi
	call	cudaMalloc@PLT
	movl	$93, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	leaq	128(%rsp), %rdi
	movl	$1200000, %esi
	call	cudaMalloc@PLT
	movl	$94, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	112(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	movl	$1200000, %edx
	call	cudaMemcpy@PLT
	movl	$96, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	120(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$1200000, %edx
	call	cudaMemcpy@PLT
	movl	$97, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	128(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$1200000, %edx
	call	cudaMemcpy@PLT
	movl	$98, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	leaq	64(%rsp), %rdi
	movl	$1200000, %esi
	movq	%rax, 16(%rsp)
	call	cudaMalloc@PLT
	movl	$102, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	leaq	72(%rsp), %rdi
	movl	$1200000, %esi
	call	cudaMalloc@PLT
	movl	$103, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	leaq	80(%rsp), %rdi
	movl	$1200000, %esi
	call	cudaMalloc@PLT
	movl	$104, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	leaq	88(%rsp), %rdi
	movl	$1200000, %esi
	call	cudaMalloc@PLT
	movl	$105, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	leaq	96(%rsp), %rdi
	movl	$1200000, %esi
	call	cudaMalloc@PLT
	movl	$106, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	leaq	104(%rsp), %rdi
	movl	$1200000, %esi
	call	cudaMalloc@PLT
	movl	$107, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	112(%rsp), %rsi
	movq	64(%rsp), %rdi
	movl	$3, %ecx
	movl	$1200000, %edx
	call	cudaMemcpy@PLT
	movl	$109, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	120(%rsp), %rsi
	movq	72(%rsp), %rdi
	movl	$3, %ecx
	movl	$1200000, %edx
	call	cudaMemcpy@PLT
	movl	$110, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	80(%rsp), %rdi
	movl	$3, %ecx
	movq	128(%rsp), %rsi
	movl	$1200000, %edx
	call	cudaMemcpy@PLT
	movl	$111, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	112(%rsp), %rsi
	movq	88(%rsp), %rdi
	movl	$3, %ecx
	movl	$1200000, %edx
	call	cudaMemcpy@PLT
	movl	$113, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	120(%rsp), %rsi
	movq	96(%rsp), %rdi
	movl	$3, %ecx
	movl	$1200000, %edx
	call	cudaMemcpy@PLT
	movl	$114, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	104(%rsp), %rdi
	movl	$3, %ecx
	movq	128(%rsp), %rsi
	movl	$1200000, %edx
	call	cudaMemcpy@PLT
	movl	$115, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movl	$19, 28(%rsp)
.L64:
	leal	-1(%r13), %eax
	movl	$1024, %r14d
	movl	%r13d, 8(%rsp)
	sarl	%eax
	movq	%r15, 152(%rsp)
	movl	156(%rsp), %ecx
	leal	1(%rax), %r13d
	movq	%r15, 140(%rsp)
	movl	144(%rsp), %esi
	cmpl	%r14d, %r13d
	cmovle	%r13d, %r14d
	cltd
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	idivl	%r14d
	movl	%r14d, 148(%rsp)
	movq	148(%rsp), %rdx
	incl	%eax
	movl	%eax, 136(%rsp)
	movq	136(%rsp), %rdi
	movl	%eax, 24(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L62
	movl	8(%rsp), %ecx
	movq	80(%rsp), %rdx
	movl	%r13d, %r8d
	movq	72(%rsp), %rsi
	movq	64(%rsp), %rdi
	call	_Z32__device_stub__Z7findMaxPfS_S_iiPfS_S_ii
.L62:
	call	cudaGetLastError@PLT
	movl	$123, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movl	24(%rsp), %eax
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r15, 152(%rsp)
	movl	156(%rsp), %ecx
	movq	%r15, 140(%rsp)
	movl	144(%rsp), %esi
	movl	%r14d, 148(%rsp)
	movq	148(%rsp), %rdx
	movl	%eax, 136(%rsp)
	movq	136(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L63
	movl	8(%rsp), %ecx
	movq	104(%rsp), %rdx
	movl	%r13d, %r8d
	movq	96(%rsp), %rsi
	movq	88(%rsp), %rdi
	call	_Z32__device_stub__Z7findMinPfS_S_iiPfS_S_ii
.L63:
	call	cudaGetLastError@PLT
	movl	$126, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	decl	28(%rsp)
	jne	.L64
	call	cudaDeviceSynchronize@PLT
	movl	$131, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	64(%rsp), %rsi
	movl	$2, %ecx
	movl	$4, %edx
	leaq	40(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	$133, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	72(%rsp), %rsi
	movl	$2, %ecx
	movl	$4, %edx
	leaq	48(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	$134, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	80(%rsp), %rsi
	movl	$2, %ecx
	movl	$4, %edx
	leaq	56(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	$135, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	88(%rsp), %rsi
	movl	$2, %ecx
	movl	$4, %edx
	leaq	44(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	$137, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	96(%rsp), %rsi
	movl	$2, %ecx
	movl	$4, %edx
	leaq	52(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	$138, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	104(%rsp), %rsi
	movl	$2, %ecx
	movl	$4, %edx
	leaq	60(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	$139, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movq	16(%rsp), %rcx
	leaq	.LC8(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	subq	%rcx, %rax
	movl	$1000, %ecx
	cqto
	idivq	%rcx
	cvtsi2sdq	%rax, %xmm0
	divsd	.LC5(%rip), %xmm0
	movsd	%xmm0, 8(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	8(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC7(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movl	$147, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movl	$148, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movl	$149, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	88(%rsp), %rdi
	call	cudaFree@PLT
	movl	$150, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	96(%rsp), %rdi
	call	cudaFree@PLT
	movl	$151, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	104(%rsp), %rdi
	call	cudaFree@PLT
	movl	$152, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	112(%rsp), %rdi
	call	cudaFree@PLT
	movl	$153, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	120(%rsp), %rdi
	call	cudaFree@PLT
	movl	$154, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	128(%rsp), %rdi
	call	cudaFree@PLT
	movl	$155, %esi
	movl	%eax, %edi
	call	_Z7err_msg9cudaErrori
	movq	%r12, %rdi
	call	_ZdaPv@PLT
	movq	%rbp, %rdi
	call	_ZdaPv@PLT
	movq	%rbx, %rdi
	call	_ZdaPv@PLT
	movq	5160(%rsp), %rax
	subq	%fs:40, %rax
	je	.L65
	call	__stack_chk_fail@PLT
.L65:
	addq	$5176, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4819:
	.size	main, .-main
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC4:
	.long	0
	.long	1086556160
	.align 8
.LC5:
	.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 <iostream>
#include <random>
#include <chrono>

#define N 300000
#define BLOCK_SIZE_X 1024

#define checkCudaErrors(msg) err_msg(msg, __LINE__)

void err_msg(hipError_t msg, int x)
{
 if (msg != hipSuccess) {
   std::cerr << "In line: " << x << ". error: " << hipGetErrorString(msg) << std::endl;
   exit(1);
 }

 return;
}

__global__ void findMax(float *x, float *y, float *z, int full_size, int half_size)
{
  int index = threadIdx.x + blockIdx.x * blockDim.x;
  int stride = blockDim.x * gridDim.x;

  for (int i = index; i < half_size; i += stride) {
    x[i] = (i + half_size < full_size) ? ((x[i] >= x[i + half_size]) ? x[i] : x[i + half_size]) : x[i];
    y[i] = (i + half_size < full_size) ? ((y[i] >= y[i + half_size]) ? y[i] : y[i + half_size]) : y[i];
    z[i] = (i + half_size < full_size) ? ((z[i] >= z[i + half_size]) ? z[i] : z[i + half_size]) : z[i];
  }
}

__global__ void findMin(float *x, float *y, float *z, int full_size, int half_size)
{
  int index = threadIdx.x + blockIdx.x * blockDim.x;
  int stride = blockDim.x * gridDim.x;

  for (int i = index; i < half_size; i += stride) {
    x[i] = (i + half_size < full_size) ? ((x[i] <= x[i + half_size]) ? x[i] : x[i + half_size]) : x[i];
    y[i] = (i + half_size < full_size) ? ((y[i] <= y[i + half_size]) ? y[i] : y[i + half_size]) : y[i];
    z[i] = (i + half_size < full_size) ? ((z[i] <= z[i + half_size]) ? z[i] : z[i + half_size]) : z[i];
  }
}

int main()
{
  int points_num = N;
  float *x, *y, *z;
  float *max_x, *max_y, *max_z, *min_x, *min_y, *min_z;
  float a_max_x, a_min_x, a_max_y, a_min_y, a_max_z, a_min_z;
  float *d_x, *d_y, *d_z;

  std::chrono::time_point<std::chrono::system_clock> start, end;
  double time;

  x = new float[N];
  y = new float[N];
  z = new float[N];

  std::mt19937 mt(10);

  for (int i = 0; i < N; i++) {
    x[i] = mt() / 10000.0;
    y[i] = mt() / 10000.0;
    z[i] = mt() / 10000.0;
  }

  
  start = std::chrono::system_clock::now();

  a_max_x = a_min_x = x[0];
  a_max_y = a_min_y = y[0];
  a_max_z = a_min_z = z[0];

  for (int i = 1; i < N; i++) {
    a_max_x = (a_max_x > x[i]) ? a_max_x : x[i];
    a_min_x = (a_min_x < x[i]) ? a_min_x : x[i];

    a_max_y = (a_max_y > y[i]) ? a_max_y : y[i];
    a_min_y = (a_min_y < y[i]) ? a_min_y : y[i];

    a_max_z = (a_max_z > z[i]) ? a_max_z : z[i];
    a_min_z = (a_min_z < z[i]) ? a_min_z : z[i];
  }

  end = std::chrono::system_clock::now();

  time = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / 1000.0;

  std::cout << "CPU sort: " << time << "ms." << std::endl;

  checkCudaErrors(hipMalloc(&d_x, sizeof(float) * points_num));
  checkCudaErrors(hipMalloc(&d_y, sizeof(float) * points_num));
  checkCudaErrors(hipMalloc(&d_z, sizeof(float) * points_num));

  checkCudaErrors(hipMemcpy(d_x, x, sizeof(float) * points_num, hipMemcpyHostToDevice));
  checkCudaErrors(hipMemcpy(d_y, y, sizeof(float) * points_num, hipMemcpyHostToDevice));
  checkCudaErrors(hipMemcpy(d_z, z, sizeof(float) * points_num, hipMemcpyHostToDevice));

  start = std::chrono::system_clock::now();

  checkCudaErrors(hipMalloc(&max_x, sizeof(float) * points_num));
  checkCudaErrors(hipMalloc(&max_y, sizeof(float) * points_num));
  checkCudaErrors(hipMalloc(&max_z, sizeof(float) * points_num));
  checkCudaErrors(hipMalloc(&min_x, sizeof(float) * points_num));
  checkCudaErrors(hipMalloc(&min_y, sizeof(float) * points_num));
  checkCudaErrors(hipMalloc(&min_z, sizeof(float) * points_num));

  checkCudaErrors(hipMemcpy(max_x, d_x, sizeof(float) * points_num, hipMemcpyDeviceToDevice));
  checkCudaErrors(hipMemcpy(max_y, d_y, sizeof(float) * points_num, hipMemcpyDeviceToDevice));
  checkCudaErrors(hipMemcpy(max_z, d_z, sizeof(float) * points_num, hipMemcpyDeviceToDevice));

  checkCudaErrors(hipMemcpy(min_x, d_x, sizeof(float) * points_num, hipMemcpyDeviceToDevice));
  checkCudaErrors(hipMemcpy(min_y, d_y, sizeof(float) * points_num, hipMemcpyDeviceToDevice));
  checkCudaErrors(hipMemcpy(min_z, d_z, sizeof(float) * points_num, hipMemcpyDeviceToDevice));

  while (points_num > 1) {
    int half_points_num = (points_num - 1) / 2 + 1;
    int block_x = (half_points_num > BLOCK_SIZE_X) ? BLOCK_SIZE_X : half_points_num;
    int grid_x = (half_points_num - 1) / block_x + 1;

    findMax<<<grid_x, block_x>>>(max_x, max_y, max_z, points_num, half_points_num);
    checkCudaErrors(hipGetLastError());

    findMin<<<grid_x, block_x>>>(min_x, min_y, min_z, points_num, half_points_num);
    checkCudaErrors(hipGetLastError());

    points_num = half_points_num;
  }

  checkCudaErrors(hipDeviceSynchronize());

  checkCudaErrors(hipMemcpy(&a_max_x, max_x, sizeof(float), hipMemcpyDeviceToHost));
  checkCudaErrors(hipMemcpy(&a_max_y, max_y, sizeof(float), hipMemcpyDeviceToHost));
  checkCudaErrors(hipMemcpy(&a_max_z, max_z, sizeof(float), hipMemcpyDeviceToHost));

  checkCudaErrors(hipMemcpy(&a_min_x, min_x, sizeof(float), hipMemcpyDeviceToHost));
  checkCudaErrors(hipMemcpy(&a_min_y, min_y, sizeof(float), hipMemcpyDeviceToHost));
  checkCudaErrors(hipMemcpy(&a_min_z, min_z, sizeof(float), hipMemcpyDeviceToHost));

  end = std::chrono::system_clock::now();

  time = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / 1000.0;

  std::cout << "GPU sort: " << time << "ms." << std::endl;

  checkCudaErrors(hipFree(max_x));
  checkCudaErrors(hipFree(max_y));
  checkCudaErrors(hipFree(max_z));
  checkCudaErrors(hipFree(min_x));
  checkCudaErrors(hipFree(min_y));
  checkCudaErrors(hipFree(min_z));
  checkCudaErrors(hipFree(d_x));
  checkCudaErrors(hipFree(d_y));
  checkCudaErrors(hipFree(d_z));

  delete[] x;
  delete[] y;
  delete[] z;

  return 0;
}
	.text
	.file	"sort.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z7err_msg10hipError_ti         # -- Begin function _Z7err_msg10hipError_ti
	.type	_Z7err_msg10hipError_ti,@function
_Z7err_msg10hipError_ti:                # @_Z7err_msg10hipError_ti
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jne	.LBB0_2
# %bb.1:
	retq
.LBB0_2:
	pushq	%rbp
	.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 %rbp, -16
	movl	%esi, %ebp
	movl	%edi, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	%ebp, %esi
	callq	_ZNSolsEi
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %r14
	movl	%ebx, %edi
	callq	hipGetErrorString
	movq	%r14, %rdi
	movq	%rax, %rsi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z7err_msg10hipError_ti, .Lfunc_end0-_Z7err_msg10hipError_ti
	.cfi_endproc
                                        # -- End function
	.globl	_Z22__device_stub__findMaxPfS_S_ii # -- Begin function _Z22__device_stub__findMaxPfS_S_ii
	.type	_Z22__device_stub__findMaxPfS_S_ii,@function
_Z22__device_stub__findMaxPfS_S_ii:     # @_Z22__device_stub__findMaxPfS_S_ii
	.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	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	movq	%rsp, %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%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	$_Z7findMaxPfS_S_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	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_end1:
	.size	_Z22__device_stub__findMaxPfS_S_ii, .Lfunc_end1-_Z22__device_stub__findMaxPfS_S_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z22__device_stub__findMinPfS_S_ii # -- Begin function _Z22__device_stub__findMinPfS_S_ii
	.type	_Z22__device_stub__findMinPfS_S_ii,@function
_Z22__device_stub__findMinPfS_S_ii:     # @_Z22__device_stub__findMinPfS_S_ii
	.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	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	movq	%rsp, %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%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	$_Z7findMinPfS_S_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	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_end2:
	.size	_Z22__device_stub__findMinPfS_S_ii, .Lfunc_end2-_Z22__device_stub__findMinPfS_S_ii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI3_0:
	.long	1127219200                      # 0x43300000
	.long	1160773632                      # 0x45300000
	.long	0                               # 0x0
	.long	0                               # 0x0
.LCPI3_1:
	.quad	0x4330000000000000              # double 4503599627370496
	.quad	0x4530000000000000              # double 1.9342813113834067E+25
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI3_2:
	.quad	0x40c3880000000000              # double 1.0E+4
.LCPI3_3:
	.quad	0x408f400000000000              # double 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	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$5128, %rsp                     # imm = 0x1408
	.cfi_def_cfa_offset 5184
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$1200000, %edi                  # imm = 0x124F80
	callq	_Znam
	movq	%rax, %r14
	movl	$1200000, %edi                  # imm = 0x124F80
	callq	_Znam
	movq	%rax, %r13
	movl	$1200000, %edi                  # imm = 0x124F80
	callq	_Znam
	movq	%rax, %r15
	movq	$10, 128(%rsp)
	movl	$1, %eax
	movl	$10, %ecx
.LBB3_1:                                # =>This Inner Loop Header: Depth=1
	movq	%rcx, %rdx
	shrq	$30, %rdx
	xorl	%ecx, %edx
	imull	$1812433253, %edx, %ecx         # imm = 0x6C078965
	addl	%eax, %ecx
	movq	%rcx, 128(%rsp,%rax,8)
	incq	%rax
	cmpq	$624, %rax                      # imm = 0x270
	jne	.LBB3_1
# %bb.2:                                # %_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEC2Em.exit
	leaq	128(%rsp), %r12
	movq	$624, 4992(%r12)                # imm = 0x270
	xorl	%ebx, %ebx
.LBB3_3:                                # =>This Inner Loop Header: Depth=1
	movq	%r12, %rdi
	callq	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	movq	%rax, %xmm0
	movdqa	.LCPI3_0(%rip), %xmm1           # xmm1 = [1127219200,1160773632,0,0]
	punpckldq	%xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
	movapd	.LCPI3_1(%rip), %xmm1           # xmm1 = [4.503599627370496E+15,1.9342813113834067E+25]
	subpd	%xmm1, %xmm0
	movapd	%xmm0, %xmm1
	unpckhpd	%xmm0, %xmm1                    # xmm1 = xmm1[1],xmm0[1]
	addsd	%xmm0, %xmm1
	movsd	.LCPI3_2(%rip), %xmm0           # xmm0 = mem[0],zero
	divsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	movss	%xmm0, (%r14,%rbx,4)
	movq	%r12, %rdi
	callq	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	movq	%rax, %xmm0
	punpckldq	.LCPI3_0(%rip), %xmm0   # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
	subpd	.LCPI3_1(%rip), %xmm0
	movapd	%xmm0, %xmm1
	unpckhpd	%xmm0, %xmm1                    # xmm1 = xmm1[1],xmm0[1]
	addsd	%xmm0, %xmm1
	divsd	.LCPI3_2(%rip), %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	movss	%xmm0, (%r13,%rbx,4)
	movq	%r12, %rdi
	callq	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	movq	%rax, %xmm0
	punpckldq	.LCPI3_0(%rip), %xmm0   # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
	subpd	.LCPI3_1(%rip), %xmm0
	movapd	%xmm0, %xmm1
	unpckhpd	%xmm0, %xmm1                    # xmm1 = xmm1[1],xmm0[1]
	addsd	%xmm0, %xmm1
	divsd	.LCPI3_2(%rip), %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	movss	%xmm0, (%r15,%rbx,4)
	incq	%rbx
	cmpq	$300000, %rbx                   # imm = 0x493E0
	jne	.LBB3_3
# %bb.4:
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %r12
	movss	(%r14), %xmm2                   # xmm2 = mem[0],zero,zero,zero
	movss	(%r13), %xmm1                   # xmm1 = mem[0],zero,zero,zero
	movss	(%r15), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	movl	$1, %eax
	movaps	%xmm2, %xmm3
	movaps	%xmm1, %xmm4
	movaps	%xmm0, %xmm5
.LBB3_5:                                # =>This Inner Loop Header: Depth=1
	movss	(%r14,%rax,4), %xmm6            # xmm6 = mem[0],zero,zero,zero
	maxss	%xmm6, %xmm2
	minss	%xmm6, %xmm3
	movss	(%r13,%rax,4), %xmm6            # xmm6 = mem[0],zero,zero,zero
	maxss	%xmm6, %xmm1
	minss	%xmm6, %xmm4
	movss	(%r15,%rax,4), %xmm6            # xmm6 = mem[0],zero,zero,zero
	maxss	%xmm6, %xmm0
	minss	%xmm6, %xmm5
	incq	%rax
	cmpq	$300000, %rax                   # imm = 0x493E0
	jne	.LBB3_5
# %bb.6:
	movss	%xmm2, 92(%rsp)
	movss	%xmm3, 88(%rsp)
	movss	%xmm1, 84(%rsp)
	movss	%xmm4, 80(%rsp)
	movss	%xmm0, 76(%rsp)
	movss	%xmm5, 72(%rsp)
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%r12, %rax
	movabsq	$2361183241434822607, %rcx      # imm = 0x20C49BA5E353F7CF
	imulq	%rcx
	movq	%rdx, %rax
	shrq	$63, %rax
	sarq	$7, %rdx
	addq	%rax, %rdx
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rdx, %xmm0
	divsd	.LCPI3_3(%rip), %xmm0
	movsd	%xmm0, 32(%rsp)                 # 8-byte Spill
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$10, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	32(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str.3, %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
	leaq	104(%rsp), %rdi
	movl	$1200000, %esi                  # imm = 0x124F80
	movq	%rdi, %rbp
	callq	hipMalloc
	movl	%eax, %edi
	movl	$92, %esi
	callq	_Z7err_msg10hipError_ti
	leaq	96(%rsp), %rdi
	movl	$1200000, %esi                  # imm = 0x124F80
	movq	%rdi, %r12
	callq	hipMalloc
	movl	%eax, %edi
	movl	$93, %esi
	callq	_Z7err_msg10hipError_ti
	leaq	120(%rsp), %rbx
	movl	$1200000, %esi                  # imm = 0x124F80
	movq	%rbx, %rdi
	callq	hipMalloc
	movl	%eax, %edi
	movl	$94, %esi
	callq	_Z7err_msg10hipError_ti
	movq	(%rbp), %rdi
	movl	$1200000, %edx                  # imm = 0x124F80
	movq	%r14, 32(%rsp)                  # 8-byte Spill
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$96, %esi
	callq	_Z7err_msg10hipError_ti
	movq	(%r12), %rdi
	movl	$1200000, %edx                  # imm = 0x124F80
	movq	%r13, 112(%rsp)                 # 8-byte Spill
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$97, %esi
	callq	_Z7err_msg10hipError_ti
	movq	(%rbx), %rdi
	movl	$1200000, %edx                  # imm = 0x124F80
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$98, %esi
	callq	_Z7err_msg10hipError_ti
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	leaq	64(%rsp), %r12
	movl	$1200000, %esi                  # imm = 0x124F80
	movq	%r12, %rdi
	callq	hipMalloc
	movl	%eax, %edi
	movl	$102, %esi
	callq	_Z7err_msg10hipError_ti
	leaq	56(%rsp), %rbp
	movl	$1200000, %esi                  # imm = 0x124F80
	movq	%rbp, %rdi
	callq	hipMalloc
	movl	%eax, %edi
	movl	$103, %esi
	callq	_Z7err_msg10hipError_ti
	leaq	48(%rsp), %r13
	movl	$1200000, %esi                  # imm = 0x124F80
	movq	%r13, %rdi
	callq	hipMalloc
	movl	%eax, %edi
	movl	$104, %esi
	callq	_Z7err_msg10hipError_ti
	leaq	40(%rsp), %r14
	movl	$1200000, %esi                  # imm = 0x124F80
	movq	%r14, %rdi
	callq	hipMalloc
	movl	%eax, %edi
	movl	$105, %esi
	callq	_Z7err_msg10hipError_ti
	leaq	16(%rsp), %rdi
	movl	$1200000, %esi                  # imm = 0x124F80
	callq	hipMalloc
	movl	%eax, %edi
	movl	$106, %esi
	callq	_Z7err_msg10hipError_ti
	leaq	8(%rsp), %rdi
	movl	$1200000, %esi                  # imm = 0x124F80
	callq	hipMalloc
	movl	%eax, %edi
	movl	$107, %esi
	callq	_Z7err_msg10hipError_ti
	movq	(%r12), %rdi
	leaq	104(%rsp), %r12
	movq	(%r12), %rsi
	movl	$1200000, %edx                  # imm = 0x124F80
	movl	$3, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$109, %esi
	callq	_Z7err_msg10hipError_ti
	movq	(%rbp), %rdi
	leaq	96(%rsp), %rbp
	movq	(%rbp), %rsi
	movl	$1200000, %edx                  # imm = 0x124F80
	movl	$3, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$110, %esi
	callq	_Z7err_msg10hipError_ti
	movq	(%r13), %rdi
	movq	(%rbx), %rsi
	movl	$1200000, %edx                  # imm = 0x124F80
	movl	$3, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$111, %esi
	callq	_Z7err_msg10hipError_ti
	movq	(%r14), %rdi
	movq	(%r12), %rsi
	movl	$1200000, %edx                  # imm = 0x124F80
	movl	$3, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$113, %esi
	callq	_Z7err_msg10hipError_ti
	leaq	16(%rsp), %rax
	movq	(%rax), %rdi
	movq	(%rbp), %rsi
	movl	$1200000, %edx                  # imm = 0x124F80
	movl	$3, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$114, %esi
	callq	_Z7err_msg10hipError_ti
	leaq	8(%rsp), %rax
	movq	(%rax), %rdi
	movq	(%rbx), %rsi
	movl	$1200000, %edx                  # imm = 0x124F80
	movl	$3, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$115, %esi
	callq	_Z7err_msg10hipError_ti
	movl	$300000, %r12d                  # imm = 0x493E0
	movl	$1024, %r14d                    # imm = 0x400
.LBB3_7:                                # =>This Inner Loop Header: Depth=1
	leal	-1(%r12), %eax
	shrl	%eax
	leal	1(%rax), %ebp
	cmpl	%r14d, %ebp
	movl	$1024, %r13d                    # imm = 0x400
	cmovbl	%ebp, %r13d
                                        # kill: def $eax killed $eax killed $rax
	xorl	%edx, %edx
	divl	%r13d
                                        # kill: def $eax killed $eax def $rax
	movabsq	$4294967296, %rcx               # imm = 0x100000000
	leaq	(%rcx,%rax), %rbx
	incq	%rbx
	orq	%rcx, %r13
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_9
# %bb.8:                                #   in Loop: Header=BB3_7 Depth=1
	movq	64(%rsp), %rdi
	movq	56(%rsp), %rsi
	movq	48(%rsp), %rdx
	movl	%r12d, %ecx
	movl	%ebp, %r8d
	callq	_Z22__device_stub__findMaxPfS_S_ii
.LBB3_9:                                #   in Loop: Header=BB3_7 Depth=1
	callq	hipGetLastError
	movl	%eax, %edi
	movl	$123, %esi
	callq	_Z7err_msg10hipError_ti
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_11
# %bb.10:                               #   in Loop: Header=BB3_7 Depth=1
	movq	40(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	movl	%r12d, %ecx
	movl	%ebp, %r8d
	callq	_Z22__device_stub__findMinPfS_S_ii
.LBB3_11:                               #   in Loop: Header=BB3_7 Depth=1
	callq	hipGetLastError
	movl	%eax, %edi
	movl	$126, %esi
	callq	_Z7err_msg10hipError_ti
	cmpl	$2, %r12d
	movl	%ebp, %r12d
	ja	.LBB3_7
# %bb.12:
	callq	hipDeviceSynchronize
	movl	%eax, %edi
	movl	$131, %esi
	callq	_Z7err_msg10hipError_ti
	movq	64(%rsp), %rsi
	leaq	92(%rsp), %rdi
	movl	$4, %edx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$133, %esi
	callq	_Z7err_msg10hipError_ti
	movq	56(%rsp), %rsi
	leaq	84(%rsp), %rdi
	movl	$4, %edx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$134, %esi
	callq	_Z7err_msg10hipError_ti
	movq	48(%rsp), %rsi
	leaq	76(%rsp), %rdi
	movl	$4, %edx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$135, %esi
	callq	_Z7err_msg10hipError_ti
	movq	40(%rsp), %rsi
	leaq	88(%rsp), %rdi
	movl	$4, %edx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$137, %esi
	callq	_Z7err_msg10hipError_ti
	movq	16(%rsp), %rsi
	leaq	80(%rsp), %rdi
	movl	$4, %edx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$138, %esi
	callq	_Z7err_msg10hipError_ti
	movq	8(%rsp), %rsi
	leaq	72(%rsp), %rdi
	movl	$4, %edx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$139, %esi
	callq	_Z7err_msg10hipError_ti
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	24(%rsp), %rax                  # 8-byte Folded Reload
	movabsq	$2361183241434822607, %rcx      # imm = 0x20C49BA5E353F7CF
	imulq	%rcx
	movq	%rdx, %rax
	shrq	$63, %rax
	sarq	$7, %rdx
	addq	%rax, %rdx
	cvtsi2sd	%rdx, %xmm0
	divsd	.LCPI3_3(%rip), %xmm0
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$10, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str.3, %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
	movq	64(%rsp), %rdi
	callq	hipFree
	movl	%eax, %edi
	movl	$147, %esi
	callq	_Z7err_msg10hipError_ti
	movq	56(%rsp), %rdi
	callq	hipFree
	movl	%eax, %edi
	movl	$148, %esi
	callq	_Z7err_msg10hipError_ti
	movq	48(%rsp), %rdi
	callq	hipFree
	movl	%eax, %edi
	movl	$149, %esi
	callq	_Z7err_msg10hipError_ti
	movq	40(%rsp), %rdi
	callq	hipFree
	movl	%eax, %edi
	movl	$150, %esi
	callq	_Z7err_msg10hipError_ti
	movq	16(%rsp), %rdi
	callq	hipFree
	movl	%eax, %edi
	movl	$151, %esi
	callq	_Z7err_msg10hipError_ti
	movq	8(%rsp), %rdi
	callq	hipFree
	movl	%eax, %edi
	movl	$152, %esi
	callq	_Z7err_msg10hipError_ti
	movq	104(%rsp), %rdi
	callq	hipFree
	movl	%eax, %edi
	movl	$153, %esi
	callq	_Z7err_msg10hipError_ti
	movq	96(%rsp), %rdi
	callq	hipFree
	movl	%eax, %edi
	movl	$154, %esi
	callq	_Z7err_msg10hipError_ti
	movq	120(%rsp), %rdi
	callq	hipFree
	movl	%eax, %edi
	movl	$155, %esi
	callq	_Z7err_msg10hipError_ti
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	_ZdaPv
	movq	112(%rsp), %rdi                 # 8-byte Reload
	callq	_ZdaPv
	movq	%r15, %rdi
	callq	_ZdaPv
	xorl	%eax, %eax
	addq	$5128, %rsp                     # imm = 0x1408
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv,"axG",@progbits,_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv,comdat
	.weak	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv # -- Begin function _ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	.p2align	1, 0x90
	.type	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv,@function
_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv: # @_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movq	4992(%rdi), %rax
	cmpq	$624, %rax                      # imm = 0x270
	jb	.LBB4_2
# %bb.1:
	movq	%rbx, %rdi
	callq	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
	movq	4992(%rbx), %rax
.LBB4_2:
	leaq	1(%rax), %rcx
	movq	%rcx, 4992(%rbx)
	movq	(%rbx,%rax,8), %rax
	movq	%rax, %rcx
	shrq	$11, %rcx
	movl	%ecx, %ecx
	xorq	%rax, %rcx
	movl	%ecx, %eax
	shll	$7, %eax
	andl	$-1658038656, %eax              # imm = 0x9D2C5680
	xorq	%rcx, %rax
	movl	%eax, %ecx
	shll	$15, %ecx
	andl	$-272236544, %ecx               # imm = 0xEFC60000
	xorq	%rax, %rcx
	movq	%rcx, %rax
	shrq	$18, %rax
	xorq	%rcx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv, .Lfunc_end4-_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv,"axG",@progbits,_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv,comdat
	.weak	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv # -- Begin function _ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
	.p2align	1, 0x90
	.type	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv,@function
_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv: # @_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
	.cfi_startproc
# %bb.0:
	movl	$2567483615, %eax               # imm = 0x9908B0DF
	movq	(%rdi), %rdx
	xorl	%ecx, %ecx
.LBB5_1:                                # =>This Inner Loop Header: Depth=1
	andq	$-2147483648, %rdx              # imm = 0x80000000
	movq	8(%rdi,%rcx,8), %rsi
	movl	%esi, %r8d
	andl	$2147483646, %r8d               # imm = 0x7FFFFFFE
	orq	%rdx, %r8
	shrq	%r8
	xorq	3176(%rdi,%rcx,8), %r8
	movq	%rsi, %rdx
                                        # kill: def $esi killed $esi killed $rsi def $rsi
	andl	$1, %esi
	negl	%esi
	andl	%eax, %esi
	xorq	%r8, %rsi
	movq	%rsi, (%rdi,%rcx,8)
	leaq	1(%rcx), %rsi
	movq	%rsi, %rcx
	cmpq	$227, %rsi
	jne	.LBB5_1
# %bb.2:                                # %.preheader.preheader
	movq	1816(%rdi), %rdx
	movl	$228, %ecx
.LBB5_3:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	andq	$-2147483648, %rdx              # imm = 0x80000000
	movq	(%rdi,%rcx,8), %rsi
	movl	%esi, %r8d
	andl	$2147483646, %r8d               # imm = 0x7FFFFFFE
	orq	%rdx, %r8
	shrq	%r8
	xorq	-1824(%rdi,%rcx,8), %r8
	movq	%rsi, %rdx
                                        # kill: def $esi killed $esi killed $rsi def $rsi
	andl	$1, %esi
	negl	%esi
	andl	%eax, %esi
	xorq	%r8, %rsi
	movq	%rsi, -8(%rdi,%rcx,8)
	incq	%rcx
	cmpq	$624, %rcx                      # imm = 0x270
	jne	.LBB5_3
# %bb.4:
	movq	$-2147483648, %rcx              # imm = 0x80000000
	andq	4984(%rdi), %rcx
	movq	(%rdi), %rdx
	movl	%edx, %esi
	andl	$2147483646, %esi               # imm = 0x7FFFFFFE
	orq	%rcx, %rsi
	shrq	%rsi
	xorq	3168(%rdi), %rsi
	andl	$1, %edx
	negl	%edx
	andl	%eax, %edx
	xorq	%rsi, %rdx
	movq	%rdx, 4984(%rdi)
	movq	$0, 4992(%rdi)
	retq
.Lfunc_end5:
	.size	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv, .Lfunc_end5-_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
	.cfi_endproc
                                        # -- End function
	.text
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7findMaxPfS_S_ii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7findMinPfS_S_ii, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.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	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"In line: "
	.size	.L.str, 10

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	". error: "
	.size	.L.str.1, 10

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

	.type	_Z7findMinPfS_S_ii,@object      # @_Z7findMinPfS_S_ii
	.globl	_Z7findMinPfS_S_ii
	.p2align	3, 0x0
_Z7findMinPfS_S_ii:
	.quad	_Z22__device_stub__findMinPfS_S_ii
	.size	_Z7findMinPfS_S_ii, 8

	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"CPU sort: "
	.size	.L.str.2, 11

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

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z7findMaxPfS_S_ii"
	.size	.L__unnamed_1, 19

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z7findMinPfS_S_ii"
	.size	.L__unnamed_2, 19

	.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 _Z22__device_stub__findMaxPfS_S_ii
	.addrsig_sym _Z22__device_stub__findMinPfS_S_ii
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _ZSt4cerr
	.addrsig_sym _Z7findMaxPfS_S_ii
	.addrsig_sym _Z7findMinPfS_S_ii
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z7findMaxPfS_S_ii      ; -- Begin function _Z7findMaxPfS_S_ii
	.globl	_Z7findMaxPfS_S_ii
	.p2align	8
	.type	_Z7findMaxPfS_S_ii,@function
_Z7findMaxPfS_S_ii:                     ; @_Z7findMaxPfS_S_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s6, s[0:1], 0x2c
	s_load_b64 s[2:3], s[0:1], 0x18
	s_add_u32 s4, s0, 32
	s_addc_u32 s5, s1, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s10, s6, 0xffff
	s_mov_b32 s6, exec_lo
	v_mad_u64_u32 v[1:2], null, s15, s10, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB0_9
; %bb.1:                                ; %.lr.ph.preheader
	s_load_b32 s11, s[4:5], 0x0
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[8:9], s[0:1], 0x10
	s_ashr_i32 s1, s3, 31
	s_mov_b32 s0, s3
	v_ashrrev_i32_e32 v2, 31, v1
	s_lshl_b64 s[16:17], s[0:1], 2
	s_mov_b32 s18, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s10, s11, s10
	s_add_u32 s1, s6, s16
	s_addc_u32 s14, s7, s17
	s_ashr_i32 s11, s10, 31
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b64 s[12:13], s[10:11], 2
	s_add_u32 s11, s8, s16
	s_addc_u32 s15, s9, s17
	s_add_u32 s16, s4, s16
	s_addc_u32 s17, s5, s17
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	v_add_co_u32 v4, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v3, vcc_lo
	v_add_nc_u32_e32 v6, s3, v1
	global_load_b32 v0, v[4:5], off
	v_cmp_gt_i32_e32 vcc_lo, s2, v6
	s_and_saveexec_b32 s19, vcc_lo
	s_cbranch_execz .LBB0_4
; %bb.3:                                ;   in Loop: Header=BB0_2 Depth=1
	v_add_co_u32 v6, s0, s16, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v7, s0, s17, v3, s0
	global_load_b32 v6, v[6:7], off
	s_waitcnt vmcnt(0)
	v_cmp_ge_f32_e64 s0, v0, v6
	v_cndmask_b32_e64 v0, v6, v0, s0
.LBB0_4:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s19
	v_add_co_u32 v6, s0, s6, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v7, s0, s7, v3, s0
	s_waitcnt vmcnt(0)
	global_store_b32 v[4:5], v0, off
	global_load_b32 v0, v[6:7], off
	s_and_saveexec_b32 s19, vcc_lo
	s_cbranch_execz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_2 Depth=1
	v_add_co_u32 v4, s0, s1, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v5, s0, s14, v3, s0
	global_load_b32 v4, v[4:5], off
	s_waitcnt vmcnt(0)
	v_cmp_ge_f32_e64 s0, v0, v4
	v_cndmask_b32_e64 v0, v4, v0, s0
.LBB0_6:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s19
	v_add_co_u32 v4, s0, s8, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v5, s0, s9, v3, s0
	s_waitcnt vmcnt(0)
	global_store_b32 v[6:7], v0, off
	global_load_b32 v0, v[4:5], off
	s_and_saveexec_b32 s0, vcc_lo
	s_cbranch_execz .LBB0_8
; %bb.7:                                ;   in Loop: Header=BB0_2 Depth=1
	v_add_co_u32 v6, vcc_lo, s11, v2
	v_add_co_ci_u32_e32 v7, vcc_lo, s15, v3, vcc_lo
	global_load_b32 v6, v[6:7], off
	s_waitcnt vmcnt(0)
	v_cmp_ge_f32_e32 vcc_lo, v0, v6
	v_cndmask_b32_e32 v0, v6, v0, vcc_lo
.LBB0_8:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	s_add_u32 s1, s1, s12
	s_addc_u32 s14, s14, s13
	v_add_nc_u32_e32 v1, s10, v1
	s_add_u32 s6, s6, s12
	s_addc_u32 s7, s7, s13
	s_add_u32 s11, s11, s12
	s_addc_u32 s15, s15, s13
	s_add_u32 s8, s8, s12
	s_addc_u32 s9, s9, s13
	v_cmp_le_i32_e32 vcc_lo, s3, v1
	s_add_u32 s16, s16, s12
	s_addc_u32 s17, s17, s13
	s_add_u32 s4, s4, s12
	s_addc_u32 s5, s5, s13
	s_or_b32 s18, vcc_lo, s18
	s_waitcnt vmcnt(0)
	global_store_b32 v[4:5], v0, off
	s_and_not1_b32 exec_lo, exec_lo, s18
	s_cbranch_execnz .LBB0_2
.LBB0_9:                                ; %Flow105
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7findMaxPfS_S_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 8
		.amdhsa_next_free_sgpr 20
		.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	_Z7findMaxPfS_S_ii, .Lfunc_end0-_Z7findMaxPfS_S_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 536
; NumSgprs: 22
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 22
; 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
	.protected	_Z7findMinPfS_S_ii      ; -- Begin function _Z7findMinPfS_S_ii
	.globl	_Z7findMinPfS_S_ii
	.p2align	8
	.type	_Z7findMinPfS_S_ii,@function
_Z7findMinPfS_S_ii:                     ; @_Z7findMinPfS_S_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s6, s[0:1], 0x2c
	s_load_b64 s[2:3], s[0:1], 0x18
	s_add_u32 s4, s0, 32
	s_addc_u32 s5, s1, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s10, s6, 0xffff
	s_mov_b32 s6, exec_lo
	v_mad_u64_u32 v[1:2], null, s15, s10, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB1_9
; %bb.1:                                ; %.lr.ph.preheader
	s_load_b32 s11, s[4:5], 0x0
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[8:9], s[0:1], 0x10
	s_ashr_i32 s1, s3, 31
	s_mov_b32 s0, s3
	v_ashrrev_i32_e32 v2, 31, v1
	s_lshl_b64 s[16:17], s[0:1], 2
	s_mov_b32 s18, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s10, s11, s10
	s_add_u32 s1, s6, s16
	s_addc_u32 s14, s7, s17
	s_ashr_i32 s11, s10, 31
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b64 s[12:13], s[10:11], 2
	s_add_u32 s11, s8, s16
	s_addc_u32 s15, s9, s17
	s_add_u32 s16, s4, s16
	s_addc_u32 s17, s5, s17
.LBB1_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	v_add_co_u32 v4, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v3, vcc_lo
	v_add_nc_u32_e32 v6, s3, v1
	global_load_b32 v0, v[4:5], off
	v_cmp_gt_i32_e32 vcc_lo, s2, v6
	s_and_saveexec_b32 s19, vcc_lo
	s_cbranch_execz .LBB1_4
; %bb.3:                                ;   in Loop: Header=BB1_2 Depth=1
	v_add_co_u32 v6, s0, s16, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v7, s0, s17, v3, s0
	global_load_b32 v6, v[6:7], off
	s_waitcnt vmcnt(0)
	v_cmp_le_f32_e64 s0, v0, v6
	v_cndmask_b32_e64 v0, v6, v0, s0
.LBB1_4:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s19
	v_add_co_u32 v6, s0, s6, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v7, s0, s7, v3, s0
	s_waitcnt vmcnt(0)
	global_store_b32 v[4:5], v0, off
	global_load_b32 v0, v[6:7], off
	s_and_saveexec_b32 s19, vcc_lo
	s_cbranch_execz .LBB1_6
; %bb.5:                                ;   in Loop: Header=BB1_2 Depth=1
	v_add_co_u32 v4, s0, s1, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v5, s0, s14, v3, s0
	global_load_b32 v4, v[4:5], off
	s_waitcnt vmcnt(0)
	v_cmp_le_f32_e64 s0, v0, v4
	v_cndmask_b32_e64 v0, v4, v0, s0
.LBB1_6:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s19
	v_add_co_u32 v4, s0, s8, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v5, s0, s9, v3, s0
	s_waitcnt vmcnt(0)
	global_store_b32 v[6:7], v0, off
	global_load_b32 v0, v[4:5], off
	s_and_saveexec_b32 s0, vcc_lo
	s_cbranch_execz .LBB1_8
; %bb.7:                                ;   in Loop: Header=BB1_2 Depth=1
	v_add_co_u32 v6, vcc_lo, s11, v2
	v_add_co_ci_u32_e32 v7, vcc_lo, s15, v3, vcc_lo
	global_load_b32 v6, v[6:7], off
	s_waitcnt vmcnt(0)
	v_cmp_le_f32_e32 vcc_lo, v0, v6
	v_cndmask_b32_e32 v0, v6, v0, vcc_lo
.LBB1_8:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	s_add_u32 s1, s1, s12
	s_addc_u32 s14, s14, s13
	v_add_nc_u32_e32 v1, s10, v1
	s_add_u32 s6, s6, s12
	s_addc_u32 s7, s7, s13
	s_add_u32 s11, s11, s12
	s_addc_u32 s15, s15, s13
	s_add_u32 s8, s8, s12
	s_addc_u32 s9, s9, s13
	v_cmp_le_i32_e32 vcc_lo, s3, v1
	s_add_u32 s16, s16, s12
	s_addc_u32 s17, s17, s13
	s_add_u32 s4, s4, s12
	s_addc_u32 s5, s5, s13
	s_or_b32 s18, vcc_lo, s18
	s_waitcnt vmcnt(0)
	global_store_b32 v[4:5], v0, off
	s_and_not1_b32 exec_lo, exec_lo, s18
	s_cbranch_execnz .LBB1_2
.LBB1_9:                                ; %Flow105
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7findMinPfS_S_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 8
		.amdhsa_next_free_sgpr 20
		.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_end1:
	.size	_Z7findMinPfS_S_ii, .Lfunc_end1-_Z7findMinPfS_S_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 536
; NumSgprs: 22
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 22
; 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
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7findMaxPfS_S_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     22
    .sgpr_spill_count: 0
    .symbol:         _Z7findMaxPfS_S_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .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
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7findMinPfS_S_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     22
    .sgpr_spill_count: 0
    .symbol:         _Z7findMinPfS_S_ii.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
