#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <chrono>
#include <stdio.h>

#define NB_THREADS 1024
#define NB_NUMBERS 200
#define NB_EXPERIMENTS 100


void print_vector(int* array, int k) {
  for(size_t i=0; i < k; i++) {
    printf("%d ", array[i]);
  }
  printf("\n");
}

bool compare_vectors(int *v1, std::vector<int> v2) {
  for(int i=0; i < v2.size(); i++) {
    if (v1[i] != v2[i]) {
      printf("wrong at %d %d vs %d\n", i, v1[i], v2[i]);
      return false;
    }
  }
  return true;
}

std::vector<int> create_vector(int N) {
  std::vector<int> res;
  for(int i=0; i < N; i++) {
    res.push_back(i);
  }
  return res;
}


__global__
void bubble_sort(int *A, int n) {
  __shared__ int end[NB_THREADS]; // termination condition for each thread
  __shared__ int race[NB_NUMBERS]; // race condition for each element of input array
  for (int u=0; u<NB_THREADS; u++) { end[u] = 0; }
  for (int v=0; v<NB_NUMBERS; v++) { race[v] = 1; }
  int temp;
  int index = threadIdx.x;
  while (1) {
    end[index] = 1;
    for (int i=0; i<n; i++) {
      while (1) {
        if ((race[i] == 1 && race[i-1] == 1) || (i == 0 && race[i] == 1)) {
          if (A[i-1] > A[i]) {
            // Block race condition
            race[i] = 0;
            race[i-1] = 0;

            // Swap
            temp = A[i-1];
            A[i-1] = A[i];
            A[i] = temp;

            // Release race condition
            end[index] = 0;
            race[i] = 1;
            race[i-1] = 1;
          }
          break;
        }
      }
    }
    if (end[index] == 1) { break; }
  }
}

int main(void) {
  for (int e=0; e<NB_EXPERIMENTS; e++) {
    // Init random input array
    int range = NB_NUMBERS;
    std::vector<int> v = create_vector(range);
    std::vector<int> v_orig = create_vector(range);
    std::random_shuffle ( v.begin(), v.end() );
    std::random_shuffle ( v.begin(), v.end() );

    int *x;
    cudaMallocManaged(&x, range*sizeof(int));
    for (int i = 0; i < range; i++) {
      x[i] = v[i];
      printf("%d %d\n", x[i], v[i]);
    }
    print_vector(x, range);

    // Sort
    bubble_sort<<<1, NB_THREADS>>>(x, range);

    cudaDeviceSynchronize();

    // Check output
    if (!compare_vectors(x, v_orig)) {
      printf("%s\n", "Wrong algorithm");
      print_vector(x, range);
      break;
    } else { printf("%s %d\n", "True algorithm", e); }

    // Free memory
    cudaFree(x);
  }
}


	.file	"tmpxft_0022fbf0_00000000-6_gpu_sort.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB5057:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE5057:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d "
.LC1:
	.string	"\n"
	.text
	.globl	_Z12print_vectorPii
	.type	_Z12print_vectorPii, @function
_Z12print_vectorPii:
.LFB5035:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movslq	%esi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
.L3:
	cmpq	%rbp, %rbx
	jnb	.L7
	movl	(%r12,%rbx,4), %edx
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%rbx
	call	__printf_chk@PLT
	jmp	.L3
.L7:
	popq	%rbx
	.cfi_def_cfa_offset 24
	leaq	.LC1(%rip), %rsi
	popq	%rbp
	.cfi_def_cfa_offset 16
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE5035:
	.size	_Z12print_vectorPii, .-_Z12print_vectorPii
	.section	.rodata.str1.1
.LC2:
	.string	"wrong at %d %d vs %d\n"
	.text
	.globl	_Z15compare_vectorsPiSt6vectorIiSaIiEE
	.type	_Z15compare_vectorsPiSt6vectorIiSaIiEE, @function
_Z15compare_vectorsPiSt6vectorIiSaIiEE:
.LFB5036:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rcx
	movq	8(%rsi), %rax
	xorl	%edx, %edx
	subq	%rcx, %rax
	sarq	$2, %rax
.L9:
	cmpq	%rax, %rdx
	je	.L17
	leaq	1(%rdx), %rsi
	movl	(%rdi,%rdx,4), %r9d
	movl	-4(%rcx,%rsi,4), %r8d
	cmpl	%r8d, %r9d
	je	.L12
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	%r9d, %ecx
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
.L12:
	movq	%rsi, %rdx
	jmp	.L9
.L17:
	movb	$1, %al
	ret
	.cfi_endproc
.LFE5036:
	.size	_Z15compare_vectorsPiSt6vectorIiSaIiEE, .-_Z15compare_vectorsPiSt6vectorIiSaIiEE
	.globl	_Z32__device_stub__Z11bubble_sortPiiPii
	.type	_Z32__device_stub__Z11bubble_sortPiiPii, @function
_Z32__device_stub__Z11bubble_sortPiiPii:
.LFB5079:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movl	%esi, 4(%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L18
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z11bubble_sortPii(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L18:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5079:
	.size	_Z32__device_stub__Z11bubble_sortPiiPii, .-_Z32__device_stub__Z11bubble_sortPiiPii
	.globl	_Z11bubble_sortPii
	.type	_Z11bubble_sortPii, @function
_Z11bubble_sortPii:
.LFB5080:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z11bubble_sortPiiPii
	.cfi_endproc
.LFE5080:
	.size	_Z11bubble_sortPii, .-_Z11bubble_sortPii
	.section	.rodata.str1.1
.LC3:
	.string	"_Z11bubble_sortPii"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB5082:
	.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	.LC3(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z11bubble_sortPii(%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
.LFE5082:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZNSt6vectorIiSaIiEED2Ev,"axG",@progbits,_ZNSt6vectorIiSaIiEED5Ev,comdat
	.align 2
	.weak	_ZNSt6vectorIiSaIiEED2Ev
	.type	_ZNSt6vectorIiSaIiEED2Ev, @function
_ZNSt6vectorIiSaIiEED2Ev:
.LFB5438:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	testq	%rax, %rax
	je	.L25
	movq	16(%rdi), %rsi
	movq	%rax, %rdi
	subq	%rax, %rsi
	jmp	_ZdlPvm@PLT
.L25:
	ret
	.cfi_endproc
.LFE5438:
	.size	_ZNSt6vectorIiSaIiEED2Ev, .-_ZNSt6vectorIiSaIiEED2Ev
	.weak	_ZNSt6vectorIiSaIiEED1Ev
	.set	_ZNSt6vectorIiSaIiEED1Ev,_ZNSt6vectorIiSaIiEED2Ev
	.section	.text._ZSt14random_shuffleIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_,"axG",@progbits,_ZSt14random_shuffleIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_,comdat
	.weak	_ZSt14random_shuffleIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_
	.type	_ZSt14random_shuffleIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_, @function
_ZSt14random_shuffleIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_:
.LFB5447:
	.cfi_startproc
	endbr64
	cmpq	%rsi, %rdi
	jne	.L34
	ret
.L34:
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	4(%rdi), %rbx
.L29:
	cmpq	%rbx, %r12
	je	.L38
	call	rand@PLT
	movq	%rbx, %rcx
	subq	%rbp, %rcx
	cltq
	sarq	$2, %rcx
	cqto
	incq	%rcx
	idivq	%rcx
	leaq	0(%rbp,%rdx,4), %rax
	cmpq	%rbx, %rax
	je	.L30
	movl	(%rbx), %edx
	movl	(%rax), %ecx
	movl	%ecx, (%rbx)
	movl	%edx, (%rax)
.L30:
	addq	$4, %rbx
	jmp	.L29
.L38:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5447:
	.size	_ZSt14random_shuffleIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_, .-_ZSt14random_shuffleIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_
	.section	.rodata._ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_.str1.1,"aMS",@progbits,1
.LC4:
	.string	"vector::_M_realloc_insert"
	.section	.text._ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_,"axG",@progbits,_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_,comdat
	.align 2
	.weak	_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_
	.type	_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_, @function
_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_:
.LFB5628:
	.cfi_startproc
	endbr64
	movabsq	$2305843009213693951, %rcx
	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	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	8(%rdi), %rax
	movq	(%rdi), %r14
	movq	%rax, %rbx
	movq	%rax, (%rsp)
	subq	%r14, %rbx
	sarq	$2, %rbx
	cmpq	%rcx, %rbx
	jne	.L40
	leaq	.LC4(%rip), %rdi
	call	_ZSt20__throw_length_errorPKc@PLT
.L40:
	cmpq	%r14, (%rsp)
	movl	$1, %eax
	movq	%rsi, %r15
	movq	%rdi, %r13
	cmovne	%rbx, %rax
	movq	%rsi, %rbp
	addq	%rax, %rbx
	setc	%al
	subq	%r14, %r15
	movzbl	%al, %eax
	testq	%rax, %rax
	jne	.L50
	xorl	%r12d, %r12d
	testq	%rbx, %rbx
	je	.L45
	movabsq	$2305843009213693951, %rax
	cmpq	%rax, %rbx
	cmova	%rax, %rbx
	jmp	.L44
.L50:
	movq	%rcx, %rbx
.L44:
	leaq	0(,%rbx,4), %rdi
	movq	%rdx, 8(%rsp)
	call	_Znwm@PLT
	movq	8(%rsp), %rdx
	movq	%rax, %r12
.L45:
	movl	(%rdx), %eax
	movl	%eax, (%r12,%r15)
	testq	%r15, %r15
	jle	.L46
	movq	%r15, %rdx
	movq	%r14, %rsi
	movq	%r12, %rdi
	call	memmove@PLT
.L46:
	movq	(%rsp), %rax
	leaq	4(%r12,%r15), %rdx
	subq	%rbp, %rax
	testq	%rax, %rax
	jle	.L47
	movq	%rdx, %rdi
	movq	%rbp, %rsi
	movq	%rax, %rcx
	rep movsb
.L47:
	leaq	(%rdx,%rax), %rbp
	testq	%r14, %r14
	je	.L48
	movq	16(%r13), %rsi
	movq	%r14, %rdi
	subq	%r14, %rsi
	call	_ZdlPvm@PLT
.L48:
	leaq	(%r12,%rbx,4), %rax
	movq	%r12, 0(%r13)
	movq	%rbp, 8(%r13)
	movq	%rax, 16(%r13)
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5628:
	.size	_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_, .-_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_
	.text
	.globl	_Z13create_vectori
	.type	_Z13create_vectori, @function
_Z13create_vectori:
.LFB5037:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA5037
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	%esi, %r12d
	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
	movq	%rdi, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	xorl	%eax, %eax
	leaq	4(%rsp), %r13
	movq	%rax, (%rdi)
	movq	%rax, 8(%rdi)
	movq	%rax, 16(%rdi)
.L58:
	movl	%ebp, 4(%rsp)
	cmpl	%ebp, %r12d
	jle	.L69
	movq	8(%rbx), %rsi
	cmpq	16(%rbx), %rsi
	je	.L59
	movl	%ebp, (%rsi)
	addq	$4, %rsi
	movq	%rsi, 8(%rbx)
	jmp	.L60
.L59:
	movq	%r13, %rdx
	movq	%rbx, %rdi
.LEHB0:
	call	_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_
.LEHE0:
.L60:
	incl	%ebp
	jmp	.L58
.L65:
	endbr64
	movq	%rax, %rbp
.L62:
	movq	%rbx, %rdi
	call	_ZNSt6vectorIiSaIiEED1Ev
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L68
	movq	%rbp, %rdi
.LEHB1:
	call	_Unwind_Resume@PLT
.LEHE1:
.L69:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L64
.L68:
	call	__stack_chk_fail@PLT
.L64:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	movq	%rbx, %rax
	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
.LFE5037:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA5037:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE5037-.LLSDACSB5037
.LLSDACSB5037:
	.uleb128 .LEHB0-.LFB5037
	.uleb128 .LEHE0-.LEHB0
	.uleb128 .L65-.LFB5037
	.uleb128 0
	.uleb128 .LEHB1-.LFB5037
	.uleb128 .LEHE1-.LEHB1
	.uleb128 0
	.uleb128 0
.LLSDACSE5037:
	.text
	.size	_Z13create_vectori, .-_Z13create_vectori
	.section	.rodata.str1.1
.LC5:
	.string	"%d %d\n"
.LC6:
	.string	"Wrong algorithm"
.LC7:
	.string	"%s\n"
.LC8:
	.string	"True algorithm"
.LC9:
	.string	"%s %d\n"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB5054:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA5054
	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
	xorl	%r13d, %r13d
	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	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %r12
.L82:
	leaq	32(%rsp), %rbp
	movl	$200, %esi
	movq	%rbp, %rdi
.LEHB2:
	call	_Z13create_vectori
.LEHE2:
	movl	$200, %esi
	movq	%r12, %rdi
.LEHB3:
	call	_Z13create_vectori
.LEHE3:
	movq	40(%rsp), %rbx
	movq	32(%rsp), %r14
	movq	%rbx, %rsi
	movq	%r14, %rdi
	call	_ZSt14random_shuffleIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_
	movq	%rbx, %rsi
	movq	%r14, %rdi
	call	_ZSt14random_shuffleIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_
	leaq	8(%rsp), %rdi
	movl	$1, %edx
	movl	$800, %esi
.LEHB4:
	call	cudaMallocManaged@PLT
	xorl	%ebx, %ebx
	leaq	.LC5(%rip), %r15
.L71:
	movl	(%r14,%rbx), %edx
	movq	8(%rsp), %rax
	movq	%r15, %rsi
	movl	$2, %edi
	movl	%edx, (%rax,%rbx)
	movl	%edx, %ecx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addq	$4, %rbx
	cmpq	$800, %rbx
	jne	.L71
	movq	8(%rsp), %rdi
	movl	$200, %esi
	call	_Z12print_vectorPii
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	salq	$10, %rdx
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movl	$1, 88(%rsp)
	movq	%rdx, 80(%rsp)
	movq	%rdi, 20(%rsp)
	movl	$1, 28(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L72
	movq	8(%rsp), %rdi
	movl	$200, %esi
	call	_Z32__device_stub__Z11bubble_sortPiiPii
.L72:
	call	cudaDeviceSynchronize@PLT
	movq	56(%rsp), %r14
	movq	64(%rsp), %rbx
	xorl	%eax, %eax
	movq	%rax, 80(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rax, 96(%rsp)
	subq	%r14, %rbx
	je	.L89
	movabsq	$9223372036854775804, %rax
	cmpq	%rbx, %rax
	jnb	.L74
	testq	%rbx, %rbx
	jns	.L75
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L96
	call	_ZSt28__throw_bad_array_new_lengthv@PLT
.L75:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L96
	call	_ZSt17__throw_bad_allocv@PLT
.L74:
	movq	%rbx, %rdi
	call	_Znwm@PLT
.LEHE4:
	movq	%rax, %rdi
	jmp	.L73
.L89:
	xorl	%edi, %edi
.L73:
	leaq	(%rdi,%rbx), %r15
	movq	%rdi, 80(%rsp)
	movq	%r15, 96(%rsp)
	cmpq	$4, %rbx
	jle	.L78
	movq	%rbx, %rdx
	movq	%r14, %rsi
	call	memmove@PLT
	jmp	.L79
.L78:
	jne	.L79
	movl	(%r14), %eax
	movl	%eax, (%rdi)
.L79:
	leaq	80(%rsp), %r14
	movq	8(%rsp), %rdi
	movq	%r15, 88(%rsp)
	movq	%r14, %rsi
.LEHB5:
	call	_Z15compare_vectorsPiSt6vectorIiSaIiEE
.LEHE5:
	movl	%eax, %ebx
	movq	%r14, %rdi
	call	_ZNSt6vectorIiSaIiEED1Ev
	testb	%bl, %bl
	jne	.L80
	leaq	.LC6(%rip), %rdx
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
.LEHB6:
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	movl	$200, %esi
	call	_Z12print_vectorPii
	movq	%r12, %rdi
	call	_ZNSt6vectorIiSaIiEED1Ev
	movq	%rbp, %rdi
	call	_ZNSt6vectorIiSaIiEED1Ev
	jmp	.L83
.L80:
	movl	%r13d, %ecx
	leaq	.LC8(%rip), %rdx
	leaq	.LC9(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
.LEHE6:
	movq	%r12, %rdi
	incl	%r13d
	call	_ZNSt6vectorIiSaIiEED1Ev
	movq	%rbp, %rdi
	call	_ZNSt6vectorIiSaIiEED1Ev
	cmpl	$100, %r13d
	jne	.L82
.L83:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L88
	jmp	.L96
.L92:
	endbr64
	movq	%rax, %rbx
.L84:
	movq	%r14, %rdi
	call	_ZNSt6vectorIiSaIiEED1Ev
	jmp	.L85
.L91:
	endbr64
	movq	%rax, %rbx
.L85:
	movq	%r12, %rdi
	call	_ZNSt6vectorIiSaIiEED1Ev
	jmp	.L86
.L90:
	endbr64
	movq	%rax, %rbx
.L86:
	movq	%rbp, %rdi
	call	_ZNSt6vectorIiSaIiEED1Ev
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L96
	movq	%rbx, %rdi
.LEHB7:
	call	_Unwind_Resume@PLT
.LEHE7:
.L96:
	call	__stack_chk_fail@PLT
.L88:
	addq	$120, %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
.LFE5054:
	.section	.gcc_except_table
.LLSDA5054:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE5054-.LLSDACSB5054
.LLSDACSB5054:
	.uleb128 .LEHB2-.LFB5054
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB3-.LFB5054
	.uleb128 .LEHE3-.LEHB3
	.uleb128 .L90-.LFB5054
	.uleb128 0
	.uleb128 .LEHB4-.LFB5054
	.uleb128 .LEHE4-.LEHB4
	.uleb128 .L91-.LFB5054
	.uleb128 0
	.uleb128 .LEHB5-.LFB5054
	.uleb128 .LEHE5-.LEHB5
	.uleb128 .L92-.LFB5054
	.uleb128 0
	.uleb128 .LEHB6-.LFB5054
	.uleb128 .LEHE6-.LEHB6
	.uleb128 .L91-.LFB5054
	.uleb128 0
	.uleb128 .LEHB7-.LFB5054
	.uleb128 .LEHE7-.LEHB7
	.uleb128 0
	.uleb128 0
.LLSDACSE5054:
	.section	.text.startup
	.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
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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 <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <chrono>
#include <stdio.h>

#define NB_THREADS 1024
#define NB_NUMBERS 200
#define NB_EXPERIMENTS 100


void print_vector(int* array, int k) {
  for(size_t i=0; i < k; i++) {
    printf("%d ", array[i]);
  }
  printf("\n");
}

bool compare_vectors(int *v1, std::vector<int> v2) {
  for(int i=0; i < v2.size(); i++) {
    if (v1[i] != v2[i]) {
      printf("wrong at %d %d vs %d\n", i, v1[i], v2[i]);
      return false;
    }
  }
  return true;
}

std::vector<int> create_vector(int N) {
  std::vector<int> res;
  for(int i=0; i < N; i++) {
    res.push_back(i);
  }
  return res;
}


__global__
void bubble_sort(int *A, int n) {
  __shared__ int end[NB_THREADS]; // termination condition for each thread
  __shared__ int race[NB_NUMBERS]; // race condition for each element of input array
  for (int u=0; u<NB_THREADS; u++) { end[u] = 0; }
  for (int v=0; v<NB_NUMBERS; v++) { race[v] = 1; }
  int temp;
  int index = threadIdx.x;
  while (1) {
    end[index] = 1;
    for (int i=0; i<n; i++) {
      while (1) {
        if ((race[i] == 1 && race[i-1] == 1) || (i == 0 && race[i] == 1)) {
          if (A[i-1] > A[i]) {
            // Block race condition
            race[i] = 0;
            race[i-1] = 0;

            // Swap
            temp = A[i-1];
            A[i-1] = A[i];
            A[i] = temp;

            // Release race condition
            end[index] = 0;
            race[i] = 1;
            race[i-1] = 1;
          }
          break;
        }
      }
    }
    if (end[index] == 1) { break; }
  }
}

int main(void) {
  for (int e=0; e<NB_EXPERIMENTS; e++) {
    // Init random input array
    int range = NB_NUMBERS;
    std::vector<int> v = create_vector(range);
    std::vector<int> v_orig = create_vector(range);
    std::random_shuffle ( v.begin(), v.end() );
    std::random_shuffle ( v.begin(), v.end() );

    int *x;
    hipMallocManaged(&x, range*sizeof(int));
    for (int i = 0; i < range; i++) {
      x[i] = v[i];
      printf("%d %d\n", x[i], v[i]);
    }
    print_vector(x, range);

    // Sort
    bubble_sort<<<1, NB_THREADS>>>(x, range);

    hipDeviceSynchronize();

    // Check output
    if (!compare_vectors(x, v_orig)) {
      printf("%s\n", "Wrong algorithm");
      print_vector(x, range);
      break;
    } else { printf("%s %d\n", "True algorithm", e); }

    // Free memory
    hipFree(x);
  }
}


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

                                        # End of file scope inline assembly
	.globl	_Z12print_vectorPii             # -- Begin function _Z12print_vectorPii
	.type	_Z12print_vectorPii,@function
_Z12print_vectorPii:                    # @_Z12print_vectorPii
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	je	.LBB0_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movslq	%esi, %r14
	xorl	%r15d, %r15d
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	(%rbx,%r15,4), %esi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB0_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB0_4:                                # %._crit_edge
	movl	$10, %edi
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end0:
	.size	_Z12print_vectorPii, .Lfunc_end0-_Z12print_vectorPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z15compare_vectorsPiSt6vectorIiSaIiEE # -- Begin function _Z15compare_vectorsPiSt6vectorIiSaIiEE
	.type	_Z15compare_vectorsPiSt6vectorIiSaIiEE,@function
_Z15compare_vectorsPiSt6vectorIiSaIiEE: # @_Z15compare_vectorsPiSt6vectorIiSaIiEE
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	(%rsi), %r8
	movq	8(%rsi), %rax
	subq	%r8, %rax
	je	.LBB1_1
# %bb.2:                                # %.lr.ph.preheader
	sarq	$2, %rax
	cmpq	$1, %rax
	movq	%rax, %r9
	adcq	$0, %r9
	movl	(%rdi), %edx
	movl	(%r8), %ecx
	xorl	%esi, %esi
	movl	$0, %ebx
	cmpl	%ecx, %edx
	jne	.LBB1_7
# %bb.3:                                # %.lr.ph41.preheader
	decq	%r9
	xorl	%esi, %esi
.LBB1_4:                                # %.lr.ph41
                                        # =>This Inner Loop Header: Depth=1
	cmpq	%rsi, %r9
	je	.LBB1_8
# %bb.5:                                # %.lr.ph
                                        #   in Loop: Header=BB1_4 Depth=1
	movl	4(%rdi,%rsi,4), %edx
	movl	4(%r8,%rsi,4), %ecx
	incq	%rsi
	cmpl	%ecx, %edx
	je	.LBB1_4
# %bb.6:                                # %.lr.ph._crit_edge
	cmpq	%rsi, %rax
	setbe	%bl
.LBB1_7:
	movl	$.L.str.2, %edi
                                        # kill: def $esi killed $esi killed $rsi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_9
.LBB1_1:
	movb	$1, %bl
	jmp	.LBB1_9
.LBB1_8:                                # %.loopexit.loopexit
	incq	%rsi
	cmpq	%rsi, %rax
	setbe	%bl
.LBB1_9:                                # %.loopexit
	movl	%ebx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z15compare_vectorsPiSt6vectorIiSaIiEE, .Lfunc_end1-_Z15compare_vectorsPiSt6vectorIiSaIiEE
	.cfi_endproc
                                        # -- End function
	.globl	_Z13create_vectori              # -- Begin function _Z13create_vectori
	.type	_Z13create_vectori,@function
_Z13create_vectori:                     # @_Z13create_vectori
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movq	%rdi, %rbx
	xorps	%xmm0, %xmm0
	movups	%xmm0, (%rdi)
	movq	$0, 16(%rdi)
	movl	$0, 12(%rsp)
	testl	%esi, %esi
	jle	.LBB2_6
# %bb.1:                                # %.lr.ph
	movl	%esi, %ebp
	xorl	%eax, %eax
	leaq	12(%rsp), %r14
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
	movq	8(%rbx), %rsi
	cmpq	16(%rbx), %rsi
	je	.LBB2_4
# %bb.3:                                #   in Loop: Header=BB2_2 Depth=1
	movl	%eax, (%rsi)
	addq	$4, %rsi
	movq	%rsi, 8(%rbx)
	jmp	.LBB2_5
.LBB2_4:                                #   in Loop: Header=BB2_2 Depth=1
.Ltmp0:
	movq	%rbx, %rdi
	movq	%r14, %rdx
	callq	_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_
.Ltmp1:
.LBB2_5:                                # %_ZNSt6vectorIiSaIiEE9push_backERKi.exit
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	12(%rsp), %eax
	incl	%eax
	movl	%eax, 12(%rsp)
	cmpl	%ebp, %eax
	jl	.LBB2_2
.LBB2_6:                                # %._crit_edge
	movq	%rbx, %rax
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB2_7:
	.cfi_def_cfa_offset 48
.Ltmp2:
	movq	%rax, %r14
	movq	(%rbx), %rdi
	testq	%rdi, %rdi
	je	.LBB2_9
# %bb.8:
	callq	_ZdlPv
.LBB2_9:                                # %_ZNSt6vectorIiSaIiEED2Ev.exit
	movq	%r14, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end2:
	.size	_Z13create_vectori, .Lfunc_end2-_Z13create_vectori
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table2:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 1 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp2-.Lfunc_begin0           #     jumps to .Ltmp2
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp1-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Lfunc_end2-.Ltmp1             #   Call between .Ltmp1 and .Lfunc_end2
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.globl	_Z26__device_stub__bubble_sortPii # -- Begin function _Z26__device_stub__bubble_sortPii
	.type	_Z26__device_stub__bubble_sortPii,@function
_Z26__device_stub__bubble_sortPii:      # @_Z26__device_stub__bubble_sortPii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	4(%rsp), %rcx
	movl	%esi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z11bubble_sortPii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z26__device_stub__bubble_sortPii, .Lfunc_end3-_Z26__device_stub__bubble_sortPii
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
.Lfunc_begin1:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception1
# %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	$88, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	40(%rsp), %r14
	leaq	64(%rsp), %rbp
	xorl	%ebx, %ebx
.LBB4_1:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_5 Depth 2
                                        #     Child Loop BB4_12 Depth 2
                                        #     Child Loop BB4_17 Depth 2
	leaq	16(%rsp), %rdi
	movl	$200, %esi
	callq	_Z13create_vectori
.Ltmp3:
	movq	%r14, %rdi
	movl	$200, %esi
	callq	_Z13create_vectori
.Ltmp4:
# %bb.2:                                #   in Loop: Header=BB4_1 Depth=1
	movq	16(%rsp), %r15
	movq	24(%rsp), %r12
	cmpq	%r12, %r15
	je	.LBB4_15
# %bb.3:                                # %.preheader.i
                                        #   in Loop: Header=BB4_1 Depth=1
	leaq	4(%r15), %rax
	cmpq	%r12, %rax
	je	.LBB4_9
# %bb.4:                                # %.lr.ph.i
                                        #   in Loop: Header=BB4_1 Depth=1
	movl	$4, %r13d
.LBB4_5:                                #   Parent Loop BB4_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	movq	%r13, %rcx
	sarq	$2, %rcx
	incq	%rcx
	cqto
	idivq	%rcx
	leaq	(,%rdx,4), %rax
	cmpq	%rax, %r13
	je	.LBB4_7
# %bb.6:                                #   in Loop: Header=BB4_5 Depth=2
	leaq	(%r15,%r13), %rax
	leaq	(%r15,%rdx,4), %rcx
	movl	(%rax), %edx
	movl	(%rcx), %esi
	movl	%esi, (%rax)
	movl	%edx, (%rcx)
.LBB4_7:                                #   in Loop: Header=BB4_5 Depth=2
	leaq	(%r15,%r13), %rax
	addq	$4, %rax
	addq	$4, %r13
	cmpq	%r12, %rax
	jne	.LBB4_5
# %bb.8:                                # %_ZSt14random_shuffleIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_.exit.loopexit
                                        #   in Loop: Header=BB4_1 Depth=1
	movq	16(%rsp), %r15
	movq	24(%rsp), %r12
.LBB4_9:                                # %_ZSt14random_shuffleIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_.exit
                                        #   in Loop: Header=BB4_1 Depth=1
	cmpq	%r12, %r15
	je	.LBB4_15
# %bb.10:                               # %.preheader.i35
                                        #   in Loop: Header=BB4_1 Depth=1
	leaq	4(%r15), %rax
	cmpq	%r12, %rax
	je	.LBB4_15
# %bb.11:                               # %.lr.ph.i38
                                        #   in Loop: Header=BB4_1 Depth=1
	movl	$4, %r13d
.LBB4_12:                               #   Parent Loop BB4_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	movq	%r13, %rcx
	sarq	$2, %rcx
	incq	%rcx
	cqto
	idivq	%rcx
	leaq	(,%rdx,4), %rax
	cmpq	%rax, %r13
	je	.LBB4_14
# %bb.13:                               #   in Loop: Header=BB4_12 Depth=2
	leaq	(%r15,%r13), %rax
	leaq	(%r15,%rdx,4), %rcx
	movl	(%rax), %edx
	movl	(%rcx), %esi
	movl	%esi, (%rax)
	movl	%edx, (%rcx)
.LBB4_14:                               #   in Loop: Header=BB4_12 Depth=2
	leaq	(%r15,%r13), %rax
	addq	$4, %rax
	addq	$4, %r13
	cmpq	%r12, %rax
	jne	.LBB4_12
.LBB4_15:                               # %_ZSt14random_shuffleIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEEvT_S7_.exit43
                                        #   in Loop: Header=BB4_1 Depth=1
.Ltmp6:
	movl	$800, %esi                      # imm = 0x320
	leaq	8(%rsp), %rdi
	movl	$1, %edx
	callq	hipMallocManaged
.Ltmp7:
# %bb.16:                               # %_ZL16hipMallocManagedIiE10hipError_tPPT_mj.exit.preheader
                                        #   in Loop: Header=BB4_1 Depth=1
	xorl	%r15d, %r15d
.LBB4_17:                               # %_ZL16hipMallocManagedIiE10hipError_tPPT_mj.exit
                                        #   Parent Loop BB4_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	16(%rsp), %rax
	movl	(%rax,%r15,4), %edx
	movq	8(%rsp), %rax
	movl	%edx, (%rax,%r15,4)
	movl	$.L.str.3, %edi
	movl	%edx, %esi
	xorl	%eax, %eax
	callq	printf
	incq	%r15
	cmpq	$200, %r15
	jne	.LBB4_17
# %bb.18:                               #   in Loop: Header=BB4_1 Depth=1
	movq	8(%rsp), %rdi
	movl	$200, %esi
	callq	_Z12print_vectorPii
.Ltmp8:
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movl	$1, %esi
	movabsq	$4294968320, %rdx               # imm = 0x100000400
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
.Ltmp9:
# %bb.19:                               #   in Loop: Header=BB4_1 Depth=1
	testl	%eax, %eax
	jne	.LBB4_21
# %bb.20:                               #   in Loop: Header=BB4_1 Depth=1
	movq	8(%rsp), %rdi
.Ltmp10:
	movl	$200, %esi
	callq	_Z26__device_stub__bubble_sortPii
.Ltmp11:
.LBB4_21:                               #   in Loop: Header=BB4_1 Depth=1
.Ltmp12:
	callq	hipDeviceSynchronize
.Ltmp13:
# %bb.22:                               #   in Loop: Header=BB4_1 Depth=1
	movq	8(%rsp), %r15
.Ltmp14:
	movq	%rbp, %rdi
	movq	%r14, %rsi
	callq	_ZNSt6vectorIiSaIiEEC2ERKS1_
.Ltmp15:
# %bb.23:                               #   in Loop: Header=BB4_1 Depth=1
	movq	%r15, %rdi
	movq	%rbp, %rsi
	callq	_Z15compare_vectorsPiSt6vectorIiSaIiEE
	movl	%eax, %r15d
	movq	64(%rsp), %rdi
	testq	%rdi, %rdi
	je	.LBB4_25
# %bb.24:                               #   in Loop: Header=BB4_1 Depth=1
	callq	_ZdlPv
.LBB4_25:                               # %_ZNSt6vectorIiSaIiEED2Ev.exit
                                        #   in Loop: Header=BB4_1 Depth=1
	testb	%r15b, %r15b
	je	.LBB4_26
# %bb.33:                               #   in Loop: Header=BB4_1 Depth=1
	movl	$.L.str.6, %edi
	movl	$.L.str.7, %esi
	movl	%ebx, %edx
	xorl	%eax, %eax
	callq	printf
	movq	8(%rsp), %rdi
.Ltmp16:
	callq	hipFree
.Ltmp17:
	jmp	.LBB4_34
.LBB4_26:                               #   in Loop: Header=BB4_1 Depth=1
	movl	$.L.str.5, %edi
	callq	puts@PLT
	movq	8(%rsp), %rdi
	movl	$200, %esi
	callq	_Z12print_vectorPii
.LBB4_34:                               #   in Loop: Header=BB4_1 Depth=1
	movq	40(%rsp), %rdi
	testq	%rdi, %rdi
	je	.LBB4_36
# %bb.35:                               #   in Loop: Header=BB4_1 Depth=1
	callq	_ZdlPv
.LBB4_36:                               # %_ZNSt6vectorIiSaIiEED2Ev.exit47
                                        #   in Loop: Header=BB4_1 Depth=1
	movq	16(%rsp), %rdi
	testq	%rdi, %rdi
	je	.LBB4_38
# %bb.37:                               #   in Loop: Header=BB4_1 Depth=1
	callq	_ZdlPv
.LBB4_38:                               # %_ZNSt6vectorIiSaIiEED2Ev.exit49
                                        #   in Loop: Header=BB4_1 Depth=1
	incl	%ebx
	cmpl	$100, %ebx
	setne	%al
	testb	%al, %r15b
	jne	.LBB4_1
# %bb.39:
	xorl	%eax, %eax
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB4_27:
	.cfi_def_cfa_offset 144
.Ltmp5:
	movq	%rax, %rbx
	jmp	.LBB4_28
.LBB4_31:                               # %_ZNSt6vectorIiSaIiEED2Ev.exit45
.Ltmp18:
	movq	%rax, %rbx
	movq	40(%rsp), %rdi
	testq	%rdi, %rdi
	je	.LBB4_28
# %bb.32:
	callq	_ZdlPv
.LBB4_28:                               # %_ZNSt6vectorIiSaIiEED2Ev.exit51
	movq	16(%rsp), %rdi
	testq	%rdi, %rdi
	je	.LBB4_30
# %bb.29:
	callq	_ZdlPv
.LBB4_30:                               # %_ZNSt6vectorIiSaIiEED2Ev.exit53
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table4:
.Lexception1:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end1-.Lcst_begin1
.Lcst_begin1:
	.uleb128 .Lfunc_begin1-.Lfunc_begin1    # >> Call Site 1 <<
	.uleb128 .Ltmp3-.Lfunc_begin1           #   Call between .Lfunc_begin1 and .Ltmp3
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp3-.Lfunc_begin1           # >> Call Site 2 <<
	.uleb128 .Ltmp4-.Ltmp3                  #   Call between .Ltmp3 and .Ltmp4
	.uleb128 .Ltmp5-.Lfunc_begin1           #     jumps to .Ltmp5
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp6-.Lfunc_begin1           # >> Call Site 3 <<
	.uleb128 .Ltmp17-.Ltmp6                 #   Call between .Ltmp6 and .Ltmp17
	.uleb128 .Ltmp18-.Lfunc_begin1          #     jumps to .Ltmp18
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp17-.Lfunc_begin1          # >> Call Site 4 <<
	.uleb128 .Lfunc_end4-.Ltmp17            #   Call between .Ltmp17 and .Lfunc_end4
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end1:
	.p2align	2, 0x0
                                        # -- End function
	.section	.text._ZNSt6vectorIiSaIiEEC2ERKS1_,"axG",@progbits,_ZNSt6vectorIiSaIiEEC2ERKS1_,comdat
	.weak	_ZNSt6vectorIiSaIiEEC2ERKS1_    # -- Begin function _ZNSt6vectorIiSaIiEEC2ERKS1_
	.p2align	1, 0x90
	.type	_ZNSt6vectorIiSaIiEEC2ERKS1_,@function
_ZNSt6vectorIiSaIiEEC2ERKS1_:           # @_ZNSt6vectorIiSaIiEEC2ERKS1_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %r14
	movq	%rdi, %rbx
	movq	8(%rsi), %rax
	movq	(%rsi), %rcx
	movq	%rax, %r12
	subq	%rcx, %r12
	sarq	$2, %r12
	xorps	%xmm0, %xmm0
	movups	%xmm0, (%rdi)
	movq	$0, 16(%rdi)
	cmpq	%rcx, %rax
	je	.LBB5_1
# %bb.2:
	movq	%rbx, %rdi
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	_ZNSt15__new_allocatorIiE8allocateEmPKv
	movq	%rax, %r15
	jmp	.LBB5_3
.LBB5_1:
	xorl	%r15d, %r15d
.LBB5_3:
	movq	%r15, (%rbx)
	movq	%r15, 8(%rbx)
	leaq	(%r15,%r12,4), %rax
	movq	%rax, 16(%rbx)
	movq	(%r14), %rsi
	movq	8(%r14), %r14
	subq	%rsi, %r14
	cmpq	$5, %r14
	jl	.LBB5_5
# %bb.4:
	movq	%r15, %rdi
	movq	%r14, %rdx
	callq	memmove@PLT
.LBB5_7:
	addq	%r14, %r15
	movq	%r15, 8(%rbx)
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB5_5:
	.cfi_def_cfa_offset 48
	cmpq	$4, %r14
	jne	.LBB5_7
# %bb.6:
	movl	(%rsi), %eax
	movl	%eax, (%r15)
	jmp	.LBB5_7
.Lfunc_end5:
	.size	_ZNSt6vectorIiSaIiEEC2ERKS1_, .Lfunc_end5-_ZNSt6vectorIiSaIiEEC2ERKS1_
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_,"axG",@progbits,_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_,comdat
	.weak	_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_ # -- Begin function _ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_
	.p2align	1, 0x90
	.type	_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_,@function
_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_: # @_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdx, (%rsp)                    # 8-byte Spill
	movq	%rsi, %r12
	movq	%rdi, %rbx
	movl	$1, %esi
	movl	$.L.str.8, %edx
	callq	_ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc
	movq	(%rbx), %r13
	movq	8(%rbx), %r15
	movq	%r12, 8(%rsp)                   # 8-byte Spill
	subq	%r13, %r12
	movq	%r12, %r14
	sarq	$2, %r14
	testq	%rax, %rax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	je	.LBB6_1
# %bb.2:
	movq	%rbx, %rdi
	movq	%rax, %rsi
	xorl	%edx, %edx
	callq	_ZNSt15__new_allocatorIiE8allocateEmPKv
	movq	%rax, %rbp
	jmp	.LBB6_3
.LBB6_1:
	xorl	%ebp, %ebp
.LBB6_3:                                # %_ZNSt12_Vector_baseIiSaIiEE11_M_allocateEm.exit
	movq	(%rsp), %rax                    # 8-byte Reload
	movl	(%rax), %eax
	movl	%eax, (%rbp,%r14,4)
	testq	%r12, %r12
	jle	.LBB6_5
# %bb.4:
	movq	%rbp, %rdi
	movq	%r13, %rsi
	movq	%r12, %rdx
	callq	memmove@PLT
.LBB6_5:                                # %_ZNSt6vectorIiSaIiEE11_S_relocateEPiS2_S2_RS0_.exit
	addq	%rbp, %r12
	addq	$4, %r12
	movq	8(%rsp), %rsi                   # 8-byte Reload
	subq	%rsi, %r15
	testq	%r15, %r15
	jle	.LBB6_7
# %bb.6:
	movq	%r12, %rdi
	movq	%r15, %rdx
	callq	memmove@PLT
.LBB6_7:                                # %_ZNSt6vectorIiSaIiEE11_S_relocateEPiS2_S2_RS0_.exit16
	testq	%r13, %r13
	je	.LBB6_9
# %bb.8:
	movq	%r13, %rdi
	callq	_ZdlPv
.LBB6_9:                                # %_ZNSt12_Vector_baseIiSaIiEE13_M_deallocateEPim.exit
	addq	%r15, %r12
	movq	%rbp, (%rbx)
	movq	%r12, 8(%rbx)
	movq	16(%rsp), %rax                  # 8-byte Reload
	leaq	(,%rax,4), %rax
	addq	%rbp, %rax
	movq	%rax, 16(%rbx)
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_, .Lfunc_end6-_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJRKiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc,"axG",@progbits,_ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc,comdat
	.weak	_ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc # -- Begin function _ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc
	.p2align	1, 0x90
	.type	_ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc,@function
_ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc: # @_ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc
	.cfi_startproc
# %bb.0:
	movabsq	$2305843009213693951, %rcx      # imm = 0x1FFFFFFFFFFFFFFF
	movq	8(%rdi), %r8
	subq	(%rdi), %r8
	sarq	$2, %r8
	movq	%rcx, %rax
	subq	%r8, %rax
	cmpq	%rsi, %rax
	jb	.LBB7_2
# %bb.1:
	cmpq	%rsi, %r8
	cmovaq	%r8, %rsi
	leaq	(%rsi,%r8), %rax
	cmpq	%rcx, %rax
	cmovaeq	%rcx, %rax
	addq	%r8, %rsi
	cmovbq	%rcx, %rax
	retq
.LBB7_2:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	%rdx, %rdi
	callq	_ZSt20__throw_length_errorPKc
.Lfunc_end7:
	.size	_ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc, .Lfunc_end7-_ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt15__new_allocatorIiE8allocateEmPKv,"axG",@progbits,_ZNSt15__new_allocatorIiE8allocateEmPKv,comdat
	.weak	_ZNSt15__new_allocatorIiE8allocateEmPKv # -- Begin function _ZNSt15__new_allocatorIiE8allocateEmPKv
	.p2align	1, 0x90
	.type	_ZNSt15__new_allocatorIiE8allocateEmPKv,@function
_ZNSt15__new_allocatorIiE8allocateEmPKv: # @_ZNSt15__new_allocatorIiE8allocateEmPKv
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	%rsi, %rax
	shrq	$61, %rax
	jne	.LBB8_1
# %bb.3:
	shlq	$2, %rsi
	movq	%rsi, %rdi
	popq	%rax
	.cfi_def_cfa_offset 8
	jmp	_Znwm                           # TAILCALL
.LBB8_1:
	.cfi_def_cfa_offset 16
	shrq	$62, %rsi
	je	.LBB8_2
# %bb.4:
	callq	_ZSt28__throw_bad_array_new_lengthv
.LBB8_2:
	callq	_ZSt17__throw_bad_allocv
.Lfunc_end8:
	.size	_ZNSt15__new_allocatorIiE8allocateEmPKv, .Lfunc_end8-_ZNSt15__new_allocatorIiE8allocateEmPKv
	.cfi_endproc
                                        # -- End function
	.text
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB9_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB9_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z11bubble_sortPii, %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_end9:
	.size	__hip_module_ctor, .Lfunc_end9-__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	.LBB10_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
.LBB10_2:
	retq
.Lfunc_end10:
	.size	__hip_module_dtor, .Lfunc_end10-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%d "
	.size	.L.str, 4

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"wrong at %d %d vs %d\n"
	.size	.L.str.2, 22

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

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Wrong algorithm"
	.size	.L.str.5, 16

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"%s %d\n"
	.size	.L.str.6, 7

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"True algorithm"
	.size	.L.str.7, 15

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"vector::_M_realloc_insert"
	.size	.L.str.8, 26

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z11bubble_sortPii"
	.size	.L__unnamed_1, 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 __gxx_personality_v0
	.addrsig_sym _Z26__device_stub__bubble_sortPii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z11bubble_sortPii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z11bubble_sortPii      ; -- Begin function _Z11bubble_sortPii
	.globl	_Z11bubble_sortPii
	.p2align	8
	.type	_Z11bubble_sortPii,@function
_Z11bubble_sortPii:                     ; @_Z11bubble_sortPii
; %bb.0:                                ; %.preheader36.preheader
	s_clause 0x1
	s_load_b32 s6, s[0:1], 0x8
	s_load_b64 s[2:3], s[0:1], 0x0
	v_mov_b32_e32 v2, 0
	s_waitcnt lgkmcnt(0)
	s_cmp_gt_i32 s6, 0
	s_cselect_b32 s0, -1, 0
	s_add_u32 s2, s2, -4
	v_cndmask_b32_e64 v0, 0, 1, s0
	s_addc_u32 s3, s3, -1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e64 s0, 1, v0
.LBB0_1:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_3 Depth 2
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 vcc_lo, exec_lo, s0
	s_mov_b32 s1, 1
	s_cbranch_vccnz .LBB0_6
; %bb.2:                                ; %.preheader.preheader
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_mov_b64 s[4:5], s[2:3]
	s_mov_b32 s7, s6
.LBB0_3:                                ; %.preheader
                                        ;   Parent Loop BB0_1 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	global_load_b64 v[0:1], v2, s[4:5]
	s_waitcnt vmcnt(0)
	v_cmp_gt_i32_e32 vcc_lo, v0, v1
	s_cbranch_vccz .LBB0_5
; %bb.4:                                ;   in Loop: Header=BB0_3 Depth=2
	v_dual_mov_b32 v3, v1 :: v_dual_mov_b32 v4, v0
	s_mov_b32 s1, 0
	global_store_b64 v2, v[3:4], s[4:5]
.LBB0_5:                                ;   in Loop: Header=BB0_3 Depth=2
	s_add_u32 s4, s4, 4
	s_addc_u32 s5, s5, 0
	s_add_i32 s7, s7, -1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s7, 0
	s_cbranch_scc0 .LBB0_3
.LBB0_6:                                ; %._crit_edge
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_cmp_eq_u32 s1, 1
	s_cbranch_scc0 .LBB0_1
; %bb.7:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11bubble_sortPii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 12
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 5
		.amdhsa_next_free_sgpr 8
		.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	_Z11bubble_sortPii, .Lfunc_end0-_Z11bubble_sortPii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 172
; NumSgprs: 10
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 10
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 12
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z11bubble_sortPii
    .private_segment_fixed_size: 0
    .sgpr_count:     10
    .sgpr_spill_count: 0
    .symbol:         _Z11bubble_sortPii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
