#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <time.h>

#include <vector>

#include <cuda.h>

const int A = 1920;
const int B = 132;
const int C = 396;

std::vector<float> TakeNaive(const std::vector<float>& x,
                             const std::vector<int>& indices) {
    std::vector<float> y(A * C);
    for (int i = 0; i < A; ++i) {
        for (int j = 0; j < C; ++j) {
            y[i * C + j] = x[i * B + indices[j]];
        }
    }
    return y;
}

void* GPUMalloc(size_t sz) {
    void* p = nullptr;
    cudaError_t err = cudaMalloc(&p, sz);
    if (err != cudaSuccess) {
        fprintf(stderr, "CUDA error: %s\n", cudaGetErrorString(err));
        abort();
    }
    return p;
}

void GPUMemcpy(void* dst, const void* src, size_t cnt, enum cudaMemcpyKind kind) {
    cudaError_t err = cudaMemcpy(dst, src, cnt, kind);
    if (err != cudaSuccess) {
        fprintf(stderr, "CUDA error: %s\n", cudaGetErrorString(err));
        abort();
    }
}

__global__ void TakeCudaKernel(float* x, int* indices, float* y, int n) {
    int i = blockIdx.x;
    int j = threadIdx.x;
    y[i * C + j] = x[i * B + indices[j]];
}

std::vector<float> TakeCuda(const std::vector<float>& x,
                            const std::vector<int>& indices,
                            int n) {
    std::vector<float> y(A * C);
    float* xg = (float*)GPUMalloc(x.size() * sizeof(x[0]));
    int* ig = (int*)GPUMalloc(indices.size() * sizeof(indices[0]));
    float* yg = (float*)GPUMalloc(y.size() * sizeof(y[0]));
    fprintf(stderr, "memcpy xg\n");
    GPUMemcpy(xg, x.data(), x.size() * sizeof(x[0]), cudaMemcpyHostToDevice);
    fprintf(stderr, "memcpy ig\n");
    GPUMemcpy(ig, indices.data(), indices.size() * sizeof(indices[0]), cudaMemcpyHostToDevice);

    fprintf(stderr, "take\n");
    clock_t start = clock();
    for (int i = 0; i < n; ++i) {
        TakeCudaKernel<<<A, C>>>(xg, ig, yg, 0);
    }

    cudaError_t err = cudaDeviceSynchronize();
    if (err != cudaSuccess) {
        fprintf(stderr, "CUDA error: %s\n", cudaGetErrorString(err));
        abort();
    }

    fprintf(stderr, "Elapsed %f\n",
            ((double)(clock() - start)) / CLOCKS_PER_SEC);

    fprintf(stderr, "memcpy yg\n");
    GPUMemcpy(&y[0], yg, y.size() * sizeof(y[0]), cudaMemcpyDeviceToHost);
    fprintf(stderr, "done\n");
    return y;
}

int main() {
    std::vector<float> x(A * B);
    std::vector<int> indices(C);
    for (size_t i = 0; i < x.size(); ++i) {
        x[i] = i;
    }
    for (size_t i = 0; i < indices.size(); ++i) {
        indices[i] = i * i % C;
    }

    std::vector<float> ey = TakeNaive(x, indices);
    std::vector<float> ay = TakeCuda(x, indices, 1);

    for (size_t i = 0; i < ey.size(); ++i) {
        //fprintf(stderr, "%zu %f %f\n", i, ey[i], ay[i]);
        assert(abs(ey[i] - ay[i]) < 1e-10);
    }

    TakeCuda(x, indices, 40);
}

	.file	"tmpxft_002da31c_00000000-6_take.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2912:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2912:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"CUDA error: %s\n"
	.text
	.globl	_Z9GPUMallocm
	.type	_Z9GPUMallocm, @function
_Z9GPUMallocm:
.LFB2906:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	%rdi, %rsi
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	xorl	%eax, %eax
	movq	%rax, (%rsp)
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L3
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC0(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	call	abort@PLT
.L3:
	movq	(%rsp), %rax
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2906:
	.size	_Z9GPUMallocm, .-_Z9GPUMallocm
	.globl	_Z9GPUMemcpyPvPKvm14cudaMemcpyKind
	.type	_Z9GPUMemcpyPvPKvm14cudaMemcpyKind, @function
_Z9GPUMemcpyPvPKvm14cudaMemcpyKind:
.LFB2907:
	.cfi_startproc
	endbr64
	pushq	%r8
	.cfi_def_cfa_offset 16
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L7
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC0(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	call	abort@PLT
.L7:
	popq	%rax
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2907:
	.size	_Z9GPUMemcpyPvPKvm14cudaMemcpyKind, .-_Z9GPUMemcpyPvPKvm14cudaMemcpyKind
	.globl	_Z39__device_stub__Z14TakeCudaKernelPfPiS_iPfPiS_i
	.type	_Z39__device_stub__Z14TakeCudaKernelPfPiS_iPfPiS_i, @function
_Z39__device_stub__Z14TakeCudaKernelPfPiS_iPfPiS_i:
.LFB2934:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L10
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z14TakeCudaKernelPfPiS_i(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L10:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2934:
	.size	_Z39__device_stub__Z14TakeCudaKernelPfPiS_iPfPiS_i, .-_Z39__device_stub__Z14TakeCudaKernelPfPiS_iPfPiS_i
	.globl	_Z14TakeCudaKernelPfPiS_i
	.type	_Z14TakeCudaKernelPfPiS_i, @function
_Z14TakeCudaKernelPfPiS_i:
.LFB2935:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z14TakeCudaKernelPfPiS_iPfPiS_i
	.cfi_endproc
.LFE2935:
	.size	_Z14TakeCudaKernelPfPiS_i, .-_Z14TakeCudaKernelPfPiS_i
	.section	.rodata.str1.1
.LC1:
	.string	"_Z14TakeCudaKernelPfPiS_i"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2937:
	.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	.LC1(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14TakeCudaKernelPfPiS_i(%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
.LFE2937:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.rodata._ZNSt6vectorIfSaIfEEC2EmRKS0_.str1.1,"aMS",@progbits,1
.LC2:
	.string	"cannot create std::vector larger than max_size()"
	.section	.text._ZNSt6vectorIfSaIfEEC2EmRKS0_,"axG",@progbits,_ZNSt6vectorIfSaIfEEC5EmRKS0_,comdat
	.align 2
	.weak	_ZNSt6vectorIfSaIfEEC2EmRKS0_
	.type	_ZNSt6vectorIfSaIfEEC2EmRKS0_, @function
_ZNSt6vectorIfSaIfEEC2EmRKS0_:
.LFB2992:
	.cfi_startproc
	endbr64
	movabsq	$2305843009213693951, %rax
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	cmpq	%rsi, %rax
	jnb	.L18
	leaq	.LC2(%rip), %rdi
	call	_ZSt20__throw_length_errorPKc@PLT
.L18:
	xorl	%eax, %eax
	movq	%rdi, %rbx
	leaq	0(,%rsi,4), %r12
	movq	%rsi, %rbp
	movq	%rax, (%rdi)
	movq	%rax, 8(%rdi)
	movq	%rax, 16(%rdi)
	xorl	%eax, %eax
	testq	%rsi, %rsi
	je	.L19
	movq	%r12, %rdi
	call	_Znwm@PLT
.L19:
	addq	%rax, %r12
	movq	%rax, (%rbx)
	movq	%rax, 8(%rbx)
	movq	%r12, 16(%rbx)
	testq	%rbp, %rbp
	je	.L20
	movl	$0x00000000, (%rax)
	addq	$4, %rax
	decq	%rbp
	je	.L20
.L21:
	cmpq	%rax, %r12
	je	.L20
	movl	$0x00000000, (%rax)
	addq	$4, %rax
	jmp	.L21
.L20:
	movq	%rax, 8(%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2992:
	.size	_ZNSt6vectorIfSaIfEEC2EmRKS0_, .-_ZNSt6vectorIfSaIfEEC2EmRKS0_
	.weak	_ZNSt6vectorIfSaIfEEC1EmRKS0_
	.set	_ZNSt6vectorIfSaIfEEC1EmRKS0_,_ZNSt6vectorIfSaIfEEC2EmRKS0_
	.text
	.globl	_Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE
	.type	_Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE, @function
_Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE:
.LFB2896:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rsi, %rbp
	movl	$760320, %esi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	7(%rsp), %rdx
	call	_ZNSt6vectorIfSaIfEEC1EmRKS0_
	movq	(%r12), %r8
	movq	0(%rbp), %rdi
	xorl	%edx, %edx
	movq	(%rbx), %rcx
.L33:
	xorl	%eax, %eax
.L34:
	movl	(%r8,%rax), %esi
	addl	%edx, %esi
	movslq	%esi, %rsi
	movss	(%rdi,%rsi,4), %xmm0
	movss	%xmm0, (%rcx,%rax)
	addq	$4, %rax
	cmpq	$1584, %rax
	jne	.L34
	addl	$132, %edx
	addq	$1584, %rcx
	cmpl	$253440, %edx
	jne	.L33
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L36
	call	__stack_chk_fail@PLT
.L36:
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2896:
	.size	_Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE, .-_Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE
	.section	.text._ZNSt6vectorIfSaIfEED2Ev,"axG",@progbits,_ZNSt6vectorIfSaIfEED5Ev,comdat
	.align 2
	.weak	_ZNSt6vectorIfSaIfEED2Ev
	.type	_ZNSt6vectorIfSaIfEED2Ev, @function
_ZNSt6vectorIfSaIfEED2Ev:
.LFB2995:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	testq	%rax, %rax
	je	.L39
	movq	16(%rdi), %rsi
	movq	%rax, %rdi
	subq	%rax, %rsi
	jmp	_ZdlPvm@PLT
.L39:
	ret
	.cfi_endproc
.LFE2995:
	.size	_ZNSt6vectorIfSaIfEED2Ev, .-_ZNSt6vectorIfSaIfEED2Ev
	.weak	_ZNSt6vectorIfSaIfEED1Ev
	.set	_ZNSt6vectorIfSaIfEED1Ev,_ZNSt6vectorIfSaIfEED2Ev
	.section	.rodata.str1.1
.LC4:
	.string	"memcpy xg\n"
.LC5:
	.string	"memcpy ig\n"
.LC6:
	.string	"take\n"
.LC8:
	.string	"Elapsed %f\n"
.LC9:
	.string	"memcpy yg\n"
.LC10:
	.string	"done\n"
	.text
	.globl	_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi
	.type	_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi, @function
_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi:
.LFB2908:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA2908
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	movl	$760320, %esi
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%ecx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rdx
.LEHB0:
	call	_ZNSt6vectorIfSaIfEEC1EmRKS0_
.LEHE0:
	movq	8(%r14), %rdi
	subq	(%r14), %rdi
.LEHB1:
	call	_Z9GPUMallocm
	movq	8(%r12), %rdi
	subq	(%r12), %rdi
	movq	%rax, (%rsp)
	call	_Z9GPUMallocm
	movq	8(%rbx), %rdi
	subq	(%rbx), %rdi
	movq	%rax, %rbp
	call	_Z9GPUMallocm
	movq	stderr(%rip), %rdi
	movq	%rax, 8(%rsp)
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC4(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	(%r14), %rsi
	movq	8(%r14), %rdx
	movl	$1, %ecx
	movq	(%rsp), %rdi
	subq	%rsi, %rdx
	call	_Z9GPUMemcpyPvPKvm14cudaMemcpyKind
	movq	stderr(%rip), %rdi
	leaq	.LC5(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	(%r12), %rsi
	movq	8(%r12), %rdx
	movl	$1, %ecx
	movq	%rbp, %rdi
	subq	%rsi, %rdx
	call	_Z9GPUMemcpyPvPKvm14cudaMemcpyKind
	movq	stderr(%rip), %rdi
	leaq	.LC6(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	call	clock@PLT
	xorl	%r14d, %r14d
	movabsq	$4294967692, %r15
	movq	%rax, %r12
.L42:
	cmpl	%r13d, %r14d
	jge	.L54
	movl	$33554447, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r15, %rdx
	movl	$1, %ecx
	salq	$7, %rdi
	movl	$1, %esi
	movq	%r15, 28(%rsp)
	movl	$1, 36(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	je	.L43
.L44:
	incl	%r14d
	jmp	.L42
.L43:
	movq	8(%rsp), %rdx
	movq	(%rsp), %rdi
	xorl	%ecx, %ecx
	movq	%rbp, %rsi
	call	_Z39__device_stub__Z14TakeCudaKernelPfPiS_iPfPiS_i
	jmp	.L44
.L54:
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L46
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdx
	call	__fprintf_chk@PLT
	call	abort@PLT
.L46:
	call	clock@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC8(%rip), %rdx
	subq	%r12, %rax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC7(%rip), %xmm0
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	leaq	.LC9(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	(%rbx), %rdi
	movq	8(%rbx), %rdx
	movl	$2, %ecx
	movq	8(%rsp), %rsi
	subq	%rdi, %rdx
	call	_Z9GPUMemcpyPvPKvm14cudaMemcpyKind
	movq	stderr(%rip), %rdi
	leaq	.LC10(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.LEHE1:
	jmp	.L55
.L50:
	endbr64
	movq	%rax, %rbp
.L47:
	movq	%rbx, %rdi
	call	_ZNSt6vectorIfSaIfEED1Ev
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L53
	movq	%rbp, %rdi
.LEHB2:
	call	_Unwind_Resume@PLT
.LEHE2:
.L55:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L49
.L53:
	call	__stack_chk_fail@PLT
.L49:
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	movq	%rbx, %rax
	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
.LFE2908:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA2908:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE2908-.LLSDACSB2908
.LLSDACSB2908:
	.uleb128 .LEHB0-.LFB2908
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB2908
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L50-.LFB2908
	.uleb128 0
	.uleb128 .LEHB2-.LFB2908
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE2908:
	.text
	.size	_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi, .-_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi
	.section	.text._ZNSt12_Vector_baseIiSaIiEED2Ev,"axG",@progbits,_ZNSt12_Vector_baseIiSaIiEED5Ev,comdat
	.align 2
	.weak	_ZNSt12_Vector_baseIiSaIiEED2Ev
	.type	_ZNSt12_Vector_baseIiSaIiEED2Ev, @function
_ZNSt12_Vector_baseIiSaIiEED2Ev:
.LFB3099:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	testq	%rax, %rax
	je	.L56
	movq	16(%rdi), %rsi
	movq	%rax, %rdi
	subq	%rax, %rsi
	jmp	_ZdlPvm@PLT
.L56:
	ret
	.cfi_endproc
.LFE3099:
	.size	_ZNSt12_Vector_baseIiSaIiEED2Ev, .-_ZNSt12_Vector_baseIiSaIiEED2Ev
	.weak	_ZNSt12_Vector_baseIiSaIiEED1Ev
	.set	_ZNSt12_Vector_baseIiSaIiEED1Ev,_ZNSt12_Vector_baseIiSaIiEED2Ev
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB2909:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA2909
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	$253440, %esi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	addq	$-128, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	96(%rsp), %rbx
	movq	%rsp, %rbp
	movq	%rbp, %rdi
	movq	%rbx, %rdx
.LEHB3:
	call	_ZNSt6vectorIfSaIfEEC1EmRKS0_
.LEHE3:
	xorl	%r8d, %r8d
	movl	$1584, %edi
	movq	%r8, 32(%rsp)
	movq	%r8, 40(%rsp)
.LEHB4:
	call	_Znwm@PLT
.LEHE4:
	leaq	1584(%rax), %rdx
	xorl	%edi, %edi
	movq	%rax, 24(%rsp)
	movq	%rax, %rcx
	movq	%rdx, 40(%rsp)
	movl	%edi, (%rax)
	xorl	%eax, %eax
.L59:
	addq	$4, %rax
	cmpq	$1584, %rax
	je	.L77
	xorl	%esi, %esi
	movl	%esi, (%rcx,%rax)
	jmp	.L59
.L77:
	movq	(%rsp), %rsi
	movq	8(%rsp), %rax
	movq	%rdx, 32(%rsp)
	xorl	%edx, %edx
	subq	%rsi, %rax
	sarq	$2, %rax
.L61:
	cmpq	%rax, %rdx
	je	.L78
	cvtsi2ssq	%rdx, %xmm0
	movss	%xmm0, (%rsi,%rdx,4)
	incq	%rdx
	jmp	.L61
.L78:
	xorl	%esi, %esi
	movl	$396, %edi
.L63:
	movq	%rsi, %rax
	xorl	%edx, %edx
	imulq	%rsi, %rax
	divq	%rdi
	movl	%edx, (%rcx,%rsi,4)
	incq	%rsi
	cmpq	$396, %rsi
	jne	.L63
	leaq	48(%rsp), %r13
	leaq	24(%rsp), %r12
	movq	%rbp, %rsi
	movq	%r12, %rdx
	movq	%r13, %rdi
.LEHB5:
	call	_Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE
.LEHE5:
	leaq	72(%rsp), %r14
	movl	$1, %ecx
	movq	%r12, %rdx
	movq	%rbp, %rsi
	movq	%r14, %rdi
.LEHB6:
	call	_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi
.LEHE6:
	movl	$40, %ecx
	movq	%r12, %rdx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
.LEHB7:
	call	_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi
.LEHE7:
	movq	%rbx, %rdi
	call	_ZNSt6vectorIfSaIfEED1Ev
	movq	%r14, %rdi
	call	_ZNSt6vectorIfSaIfEED1Ev
	movq	%r13, %rdi
	call	_ZNSt6vectorIfSaIfEED1Ev
	movq	%r12, %rdi
	call	_ZNSt12_Vector_baseIiSaIiEED2Ev
	movq	%rbp, %rdi
	call	_ZNSt6vectorIfSaIfEED1Ev
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L69
	jmp	.L75
.L73:
	endbr64
	movq	%rax, %rbx
.L64:
	movq	%r14, %rdi
	call	_ZNSt6vectorIfSaIfEED1Ev
	jmp	.L65
.L72:
	endbr64
	movq	%rax, %rbx
.L65:
	movq	%r13, %rdi
	call	_ZNSt6vectorIfSaIfEED1Ev
	jmp	.L66
.L71:
	endbr64
	movq	%rax, %rbx
.L66:
	movq	%r12, %rdi
	call	_ZNSt12_Vector_baseIiSaIiEED2Ev
	jmp	.L67
.L70:
	endbr64
	movq	%rax, %rbx
.L67:
	movq	%rbp, %rdi
	call	_ZNSt6vectorIfSaIfEED1Ev
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L75
	movq	%rbx, %rdi
.LEHB8:
	call	_Unwind_Resume@PLT
.LEHE8:
.L75:
	call	__stack_chk_fail@PLT
.L69:
	subq	$-128, %rsp
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2909:
	.section	.gcc_except_table
.LLSDA2909:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE2909-.LLSDACSB2909
.LLSDACSB2909:
	.uleb128 .LEHB3-.LFB2909
	.uleb128 .LEHE3-.LEHB3
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB4-.LFB2909
	.uleb128 .LEHE4-.LEHB4
	.uleb128 .L70-.LFB2909
	.uleb128 0
	.uleb128 .LEHB5-.LFB2909
	.uleb128 .LEHE5-.LEHB5
	.uleb128 .L71-.LFB2909
	.uleb128 0
	.uleb128 .LEHB6-.LFB2909
	.uleb128 .LEHE6-.LEHB6
	.uleb128 .L72-.LFB2909
	.uleb128 0
	.uleb128 .LEHB7-.LFB2909
	.uleb128 .LEHE7-.LEHB7
	.uleb128 .L73-.LFB2909
	.uleb128 0
	.uleb128 .LEHB8-.LFB2909
	.uleb128 .LEHE8-.LEHB8
	.uleb128 0
	.uleb128 0
.LLSDACSE2909:
	.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
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC7:
	.long	0
	.long	1093567616
	.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 <assert.h>
#include <math.h>
#include <stdio.h>
#include <time.h>

#include <vector>

#include <hip/hip_runtime.h>

const int A = 1920;
const int B = 132;
const int C = 396;

std::vector<float> TakeNaive(const std::vector<float>& x,
                             const std::vector<int>& indices) {
    std::vector<float> y(A * C);
    for (int i = 0; i < A; ++i) {
        for (int j = 0; j < C; ++j) {
            y[i * C + j] = x[i * B + indices[j]];
        }
    }
    return y;
}

void* GPUMalloc(size_t sz) {
    void* p = nullptr;
    hipError_t err = hipMalloc(&p, sz);
    if (err != hipSuccess) {
        fprintf(stderr, "CUDA error: %s\n", hipGetErrorString(err));
        abort();
    }
    return p;
}

void GPUMemcpy(void* dst, const void* src, size_t cnt, enum hipMemcpyKind kind) {
    hipError_t err = hipMemcpy(dst, src, cnt, kind);
    if (err != hipSuccess) {
        fprintf(stderr, "CUDA error: %s\n", hipGetErrorString(err));
        abort();
    }
}

__global__ void TakeCudaKernel(float* x, int* indices, float* y, int n) {
    int i = blockIdx.x;
    int j = threadIdx.x;
    y[i * C + j] = x[i * B + indices[j]];
}

std::vector<float> TakeCuda(const std::vector<float>& x,
                            const std::vector<int>& indices,
                            int n) {
    std::vector<float> y(A * C);
    float* xg = (float*)GPUMalloc(x.size() * sizeof(x[0]));
    int* ig = (int*)GPUMalloc(indices.size() * sizeof(indices[0]));
    float* yg = (float*)GPUMalloc(y.size() * sizeof(y[0]));
    fprintf(stderr, "memcpy xg\n");
    GPUMemcpy(xg, x.data(), x.size() * sizeof(x[0]), hipMemcpyHostToDevice);
    fprintf(stderr, "memcpy ig\n");
    GPUMemcpy(ig, indices.data(), indices.size() * sizeof(indices[0]), hipMemcpyHostToDevice);

    fprintf(stderr, "take\n");
    clock_t start = clock();
    for (int i = 0; i < n; ++i) {
        TakeCudaKernel<<<A, C>>>(xg, ig, yg, 0);
    }

    hipError_t err = hipDeviceSynchronize();
    if (err != hipSuccess) {
        fprintf(stderr, "CUDA error: %s\n", hipGetErrorString(err));
        abort();
    }

    fprintf(stderr, "Elapsed %f\n",
            ((double)(clock() - start)) / CLOCKS_PER_SEC);

    fprintf(stderr, "memcpy yg\n");
    GPUMemcpy(&y[0], yg, y.size() * sizeof(y[0]), hipMemcpyDeviceToHost);
    fprintf(stderr, "done\n");
    return y;
}

int main() {
    std::vector<float> x(A * B);
    std::vector<int> indices(C);
    for (size_t i = 0; i < x.size(); ++i) {
        x[i] = i;
    }
    for (size_t i = 0; i < indices.size(); ++i) {
        indices[i] = i * i % C;
    }

    std::vector<float> ey = TakeNaive(x, indices);
    std::vector<float> ay = TakeCuda(x, indices, 1);

    for (size_t i = 0; i < ey.size(); ++i) {
        //fprintf(stderr, "%zu %f %f\n", i, ey[i], ay[i]);
        assert(abs(ey[i] - ay[i]) < 1e-10);
    }

    TakeCuda(x, indices, 40);
}

	.text
	.file	"take.hip"
	.globl	_Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE # -- Begin function _Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE
	.type	_Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE,@function
_Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE: # @_Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.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, %r15
	movq	%rsi, %r12
	movq	%rdi, %rbx
	movl	$3041280, %edi                  # imm = 0x2E6800
	callq	_Znwm
	movq	%rax, %r14
	movq	%rax, (%rbx)
	leaq	3041280(%rax), %rbp
	movq	%rbp, 16(%rbx)
	xorl	%r13d, %r13d
	movl	$3041280, %edx                  # imm = 0x2E6800
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movq	%rbp, 8(%rbx)
	movq	(%r15), %rax
	movq	(%r12), %rcx
.LBB0_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_2 Depth 2
	movl	%r13d, %edx
	shll	$7, %edx
	leal	(%rdx,%r13,4), %edx
	movslq	%edx, %rdx
	xorl	%esi, %esi
.LBB0_2:                                #   Parent Loop BB0_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movslq	(%rax,%rsi,4), %rdi
	addq	%rdx, %rdi
	movss	(%rcx,%rdi,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%r14,%rsi,4)
	incq	%rsi
	cmpq	$396, %rsi                      # imm = 0x18C
	jne	.LBB0_2
# %bb.3:                                #   in Loop: Header=BB0_1 Depth=1
	incq	%r13
	addq	$1584, %r14                     # imm = 0x630
	cmpq	$1920, %r13                     # imm = 0x780
	jne	.LBB0_1
# %bb.4:
	movq	%rbx, %rax
	addq	$8, %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_end0:
	.size	_Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE, .Lfunc_end0-_Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE
	.cfi_endproc
                                        # -- End function
	.globl	_Z9GPUMallocm                   # -- Begin function _Z9GPUMallocm
	.type	_Z9GPUMallocm,@function
_Z9GPUMallocm:                          # @_Z9GPUMallocm
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	movq	%rdi, %rsi
	leaq	8(%rsp), %rdi
	movq	$0, (%rdi)
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_2
# %bb.1:
	movq	8(%rsp), %rax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB1_2:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	callq	abort
.Lfunc_end1:
	.size	_Z9GPUMallocm, .Lfunc_end1-_Z9GPUMallocm
	.cfi_endproc
                                        # -- End function
	.globl	_Z9GPUMemcpyPvPKvm13hipMemcpyKind # -- Begin function _Z9GPUMemcpyPvPKvm13hipMemcpyKind
	.type	_Z9GPUMemcpyPvPKvm13hipMemcpyKind,@function
_Z9GPUMemcpyPvPKvm13hipMemcpyKind:      # @_Z9GPUMemcpyPvPKvm13hipMemcpyKind
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_2
# %bb.1:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB2_2:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	callq	abort
.Lfunc_end2:
	.size	_Z9GPUMemcpyPvPKvm13hipMemcpyKind, .Lfunc_end2-_Z9GPUMemcpyPvPKvm13hipMemcpyKind
	.cfi_endproc
                                        # -- End function
	.globl	_Z29__device_stub__TakeCudaKernelPfPiS_i # -- Begin function _Z29__device_stub__TakeCudaKernelPfPiS_i
	.type	_Z29__device_stub__TakeCudaKernelPfPiS_i,@function
_Z29__device_stub__TakeCudaKernelPfPiS_i: # @_Z29__device_stub__TakeCudaKernelPfPiS_i
	.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	$112, %rsp
	.cfi_def_cfa_offset 160
	.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)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%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	$_Z14TakeCudaKernelPfPiS_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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	_Z29__device_stub__TakeCudaKernelPfPiS_i, .Lfunc_end3-_Z29__device_stub__TakeCudaKernelPfPiS_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi
.LCPI4_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi
	.type	_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi,@function
_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi: # @_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %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
	movl	%ecx, %ebp
	movq	%rdx, %rbx
	movq	%rsi, %r14
	movq	%rdi, %r12
	movl	$3041280, %edi                  # imm = 0x2E6800
	callq	_Znwm
	movq	%rax, (%r12)
	leaq	3041280(%rax), %r15
	movq	%r15, 16(%r12)
	movl	$3041280, %edx                  # imm = 0x2E6800
	movq	%rax, (%rsp)                    # 8-byte Spill
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movq	%r12, 16(%rsp)                  # 8-byte Spill
	movq	%r15, 8(%r12)
	movq	8(%r14), %rdi
	subq	(%r14), %rdi
.Ltmp0:
	callq	_Z9GPUMallocm
.Ltmp1:
# %bb.1:
	movq	%rax, %r12
	movq	8(%rbx), %rdi
	subq	(%rbx), %rdi
.Ltmp3:
	callq	_Z9GPUMallocm
.Ltmp4:
# %bb.2:
.Ltmp6:
	movq	%rax, %r13
	movl	$3041280, %edi                  # imm = 0x2E6800
	callq	_Z9GPUMallocm
.Ltmp7:
# %bb.3:
	movq	%rax, %r15
	movq	stderr(%rip), %rcx
	movl	$.L.str.1, %edi
	movl	$10, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movq	(%r14), %rsi
	movq	8(%r14), %rdx
	subq	%rsi, %rdx
.Ltmp8:
	movq	%r12, %rdi
	movl	$1, %ecx
	callq	_Z9GPUMemcpyPvPKvm13hipMemcpyKind
.Ltmp9:
# %bb.4:
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$10, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movq	(%rbx), %rsi
	movq	8(%rbx), %rdx
	subq	%rsi, %rdx
.Ltmp10:
	movq	%r13, %rdi
	movl	$1, %ecx
	callq	_Z9GPUMemcpyPvPKvm13hipMemcpyKind
.Ltmp11:
# %bb.5:
	movq	stderr(%rip), %rcx
	movl	$.L.str.3, %edi
	movl	$5, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	callq	clock
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	testl	%ebp, %ebp
	jle	.LBB4_11
# %bb.6:
	movabsq	$4294969216, %r14               # imm = 0x100000780
	movabsq	$4294967692, %rbx               # imm = 0x10000018C
.LBB4_7:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
.Ltmp13:
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
.Ltmp14:
# %bb.8:                                #   in Loop: Header=BB4_7 Depth=1
	testl	%eax, %eax
	jne	.LBB4_10
# %bb.9:                                #   in Loop: Header=BB4_7 Depth=1
.Ltmp15:
	movq	%r12, %rdi
	movq	%r13, %rsi
	movq	%r15, %rdx
	xorl	%ecx, %ecx
	callq	_Z29__device_stub__TakeCudaKernelPfPiS_i
.Ltmp16:
.LBB4_10:                               #   in Loop: Header=BB4_7 Depth=1
	decl	%ebp
	jne	.LBB4_7
.LBB4_11:                               # %._crit_edge
.Ltmp18:
	callq	hipDeviceSynchronize
.Ltmp19:
# %bb.12:
	movq	stderr(%rip), %rbx
	testl	%eax, %eax
	jne	.LBB4_13
# %bb.19:
	callq	clock
	subq	8(%rsp), %rax                   # 8-byte Folded Reload
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI4_0(%rip), %xmm0
	movl	$.L.str.4, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	movq	stderr(%rip), %rcx
	movl	$.L.str.5, %edi
	movl	$10, %esi
	movl	$1, %edx
	callq	fwrite@PLT
.Ltmp22:
	movl	$3041280, %edx                  # imm = 0x2E6800
	movq	(%rsp), %rdi                    # 8-byte Reload
	movq	%r15, %rsi
	movl	$2, %ecx
	callq	_Z9GPUMemcpyPvPKvm13hipMemcpyKind
.Ltmp23:
# %bb.20:
	movq	stderr(%rip), %rcx
	movl	$.L.str.6, %edi
	movl	$5, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movq	16(%rsp), %rax                  # 8-byte Reload
	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
.LBB4_13:
	.cfi_def_cfa_offset 80
.Ltmp20:
	movl	%eax, %edi
	callq	hipGetErrorString
.Ltmp21:
# %bb.14:
	movl	$.L.str, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	callq	abort
.LBB4_15:
.Ltmp5:
	jmp	.LBB4_22
.LBB4_21:
.Ltmp2:
	jmp	.LBB4_22
.LBB4_18:
.Ltmp24:
	jmp	.LBB4_22
.LBB4_16:
.Ltmp12:
	jmp	.LBB4_22
.LBB4_17:
.Ltmp17:
.LBB4_22:                               # %_ZNSt6vectorIfSaIfEED2Ev.exit
	movq	%rax, %rbx
	movq	(%rsp), %rdi                    # 8-byte Reload
	callq	_ZdlPv
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end4:
	.size	_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi, .Lfunc_end4-_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table4:
.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 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp2-.Lfunc_begin0           #     jumps to .Ltmp2
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp3-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp4-.Ltmp3                  #   Call between .Ltmp3 and .Ltmp4
	.uleb128 .Ltmp5-.Lfunc_begin0           #     jumps to .Ltmp5
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp6-.Lfunc_begin0           # >> Call Site 4 <<
	.uleb128 .Ltmp11-.Ltmp6                 #   Call between .Ltmp6 and .Ltmp11
	.uleb128 .Ltmp12-.Lfunc_begin0          #     jumps to .Ltmp12
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp13-.Lfunc_begin0          # >> Call Site 5 <<
	.uleb128 .Ltmp16-.Ltmp13                #   Call between .Ltmp13 and .Ltmp16
	.uleb128 .Ltmp17-.Lfunc_begin0          #     jumps to .Ltmp17
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp18-.Lfunc_begin0          # >> Call Site 6 <<
	.uleb128 .Ltmp21-.Ltmp18                #   Call between .Ltmp18 and .Ltmp21
	.uleb128 .Ltmp24-.Lfunc_begin0          #     jumps to .Ltmp24
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp21-.Lfunc_begin0          # >> Call Site 7 <<
	.uleb128 .Lfunc_end4-.Ltmp21            #   Call between .Ltmp21 and .Lfunc_end4
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.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	%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
	subq	$120, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	$1013760, %edi                  # imm = 0xF7800
	callq	_Znwm
	movq	%rax, %rbx
	movq	%rax, 24(%rsp)
	leaq	1013760(%rax), %r14
	movq	%r14, 40(%rsp)
	movl	$1013760, %edx                  # imm = 0xF7800
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movq	%r14, 32(%rsp)
.Ltmp25:
	movl	$1584, %edi                     # imm = 0x630
	callq	_Znwm
.Ltmp26:
# %bb.1:
	movq	%rax, %r14
	movq	%rax, (%rsp)
	movq	%rax, %r12
	addq	$1584, %r12                     # imm = 0x630
	movq	%r12, 16(%rsp)
	xorl	%r15d, %r15d
	movl	$1584, %edx                     # imm = 0x630
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movq	%r12, 8(%rsp)
.LBB5_2:                                # =>This Inner Loop Header: Depth=1
	testq	%r15, %r15
	js	.LBB5_3
# %bb.4:                                #   in Loop: Header=BB5_2 Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r15, %xmm0
	jmp	.LBB5_5
.LBB5_3:                                #   in Loop: Header=BB5_2 Depth=1
	movq	%r15, %rax
	shrq	%rax
	movl	%r15d, %ecx
	andl	$1, %ecx
	orq	%rax, %rcx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rcx, %xmm0
	addss	%xmm0, %xmm0
.LBB5_5:                                #   in Loop: Header=BB5_2 Depth=1
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	$253440, %r15                   # imm = 0x3DE00
	jne	.LBB5_2
# %bb.6:                                # %.preheader40.preheader
	xorl	%eax, %eax
	movl	$2776544515, %ecx               # imm = 0xA57EB503
.LBB5_7:                                # %.preheader40
                                        # =>This Inner Loop Header: Depth=1
	movl	%eax, %edx
	imull	%edx, %edx
	movq	%rdx, %rsi
	imulq	%rcx, %rsi
	shrq	$40, %rsi
	imull	$396, %esi, %esi                # imm = 0x18C
	subl	%esi, %edx
	movl	%edx, (%r14,%rax,4)
	incq	%rax
	cmpq	$396, %rax                      # imm = 0x18C
	jne	.LBB5_7
# %bb.8:
.Ltmp28:
	leaq	72(%rsp), %rdi
	leaq	24(%rsp), %rsi
	movq	%rsp, %rdx
	callq	_Z9TakeNaiveRKSt6vectorIfSaIfEERKS_IiSaIiEE
.Ltmp29:
# %bb.9:
.Ltmp31:
	leaq	48(%rsp), %rdi
	leaq	24(%rsp), %rsi
	movq	%rsp, %rdx
	movl	$1, %ecx
	callq	_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi
.Ltmp32:
# %bb.10:                               # %.preheader
	movq	72(%rsp), %r15
.Ltmp34:
	leaq	96(%rsp), %rdi
	leaq	24(%rsp), %rsi
	movq	%rsp, %rdx
	movl	$40, %ecx
	callq	_Z8TakeCudaRKSt6vectorIfSaIfEERKS_IiSaIiEEi
.Ltmp35:
# %bb.11:
	movq	96(%rsp), %rdi
	testq	%rdi, %rdi
	je	.LBB5_13
# %bb.12:
	callq	_ZdlPv
.LBB5_13:                               # %_ZNSt6vectorIfSaIfEED2Ev.exit
	movq	48(%rsp), %rdi
	testq	%rdi, %rdi
	je	.LBB5_15
# %bb.14:
	callq	_ZdlPv
.LBB5_15:                               # %_ZNSt6vectorIfSaIfEED2Ev.exit25
	testq	%r15, %r15
	je	.LBB5_17
# %bb.16:
	movq	%r15, %rdi
	callq	_ZdlPv
.LBB5_17:                               # %_ZNSt6vectorIfSaIfEED2Ev.exit30
	movq	%r14, %rdi
	callq	_ZdlPv
	movq	%rbx, %rdi
	callq	_ZdlPv
	xorl	%eax, %eax
	addq	$120, %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_20:
	.cfi_def_cfa_offset 160
.Ltmp36:
	movq	%rax, %r12
	movq	48(%rsp), %rdi
	testq	%rdi, %rdi
	je	.LBB5_22
# %bb.21:
	callq	_ZdlPv
	jmp	.LBB5_22
.LBB5_19:
.Ltmp33:
	movq	%rax, %r12
	movq	72(%rsp), %r15
.LBB5_22:                               # %_ZNSt6vectorIfSaIfEED2Ev.exit32
	testq	%r15, %r15
	je	.LBB5_24
# %bb.23:
	movq	%r15, %rdi
	callq	_ZdlPv
	jmp	.LBB5_24
.LBB5_18:
.Ltmp30:
	movq	%rax, %r12
.LBB5_24:                               # %_ZNSt6vectorIiSaIiEED2Ev.exit36
	movq	%r14, %rdi
	callq	_ZdlPv
	jmp	.LBB5_25
.LBB5_26:
.Ltmp27:
	movq	%rax, %r12
.LBB5_25:                               # %_ZNSt6vectorIfSaIfEED2Ev.exit38
	movq	%rbx, %rdi
	callq	_ZdlPv
	movq	%r12, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table5:
.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 .Ltmp25-.Lfunc_begin1          #   Call between .Lfunc_begin1 and .Ltmp25
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp25-.Lfunc_begin1          # >> Call Site 2 <<
	.uleb128 .Ltmp26-.Ltmp25                #   Call between .Ltmp25 and .Ltmp26
	.uleb128 .Ltmp27-.Lfunc_begin1          #     jumps to .Ltmp27
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp26-.Lfunc_begin1          # >> Call Site 3 <<
	.uleb128 .Ltmp28-.Ltmp26                #   Call between .Ltmp26 and .Ltmp28
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp28-.Lfunc_begin1          # >> Call Site 4 <<
	.uleb128 .Ltmp29-.Ltmp28                #   Call between .Ltmp28 and .Ltmp29
	.uleb128 .Ltmp30-.Lfunc_begin1          #     jumps to .Ltmp30
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp31-.Lfunc_begin1          # >> Call Site 5 <<
	.uleb128 .Ltmp32-.Ltmp31                #   Call between .Ltmp31 and .Ltmp32
	.uleb128 .Ltmp33-.Lfunc_begin1          #     jumps to .Ltmp33
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp34-.Lfunc_begin1          # >> Call Site 6 <<
	.uleb128 .Ltmp35-.Ltmp34                #   Call between .Ltmp34 and .Ltmp35
	.uleb128 .Ltmp36-.Lfunc_begin1          #     jumps to .Ltmp36
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp35-.Lfunc_begin1          # >> Call Site 7 <<
	.uleb128 .Lfunc_end5-.Ltmp35            #   Call between .Ltmp35 and .Lfunc_end5
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end1:
	.p2align	2, 0x0
                                        # -- 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	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14TakeCudaKernelPfPiS_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB7_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"CUDA error: %s\n"
	.size	.L.str, 16

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

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"memcpy xg\n"
	.size	.L.str.1, 11

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"memcpy ig\n"
	.size	.L.str.2, 11

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"take\n"
	.size	.L.str.3, 6

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Elapsed %f\n"
	.size	.L.str.4, 12

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"memcpy yg\n"
	.size	.L.str.5, 11

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"done\n"
	.size	.L.str.6, 6

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14TakeCudaKernelPfPiS_i"
	.size	.L__unnamed_1, 26

	.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 _Z29__device_stub__TakeCudaKernelPfPiS_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z14TakeCudaKernelPfPiS_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14TakeCudaKernelPfPiS_i ; -- Begin function _Z14TakeCudaKernelPfPiS_i
	.globl	_Z14TakeCudaKernelPfPiS_i
	.p2align	8
	.type	_Z14TakeCudaKernelPfPiS_i,@function
_Z14TakeCudaKernelPfPiS_i:              ; @_Z14TakeCudaKernelPfPiS_i
; %bb.0:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_lshlrev_b32_e32 v1, 2, v0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	global_load_b32 v1, v1, s[6:7]
	s_waitcnt vmcnt(0)
	v_mad_u64_u32 v[2:3], null, 0x84, s15, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	v_lshlrev_b64 v[1:2], 2, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v1, vcc_lo, s4, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s5, v2, vcc_lo
	global_load_b32 v3, v[1:2], off
	v_mad_u64_u32 v[1:2], null, 0x18c, s15, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_waitcnt vmcnt(0)
	global_store_b32 v[0:1], v3, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14TakeCudaKernelPfPiS_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 28
		.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 4
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z14TakeCudaKernelPfPiS_i, .Lfunc_end0-_Z14TakeCudaKernelPfPiS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 156
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 4
; Occupancy: 16
; WaveLimiterHint : 1
; 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
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 28
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14TakeCudaKernelPfPiS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z14TakeCudaKernelPfPiS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
