#include <stdio.h>

#define ARRAY_LEN 4096
#define RUN_COUNT 1000

int max_print=20;
unsigned long long fnd_count=0;

void checker(int round, char* buf)
{
	int i;

	for(i=0; i<ARRAY_LEN; i++)
	{   
		switch(buf[i])
		{
			case 'A':
			case 'B':
			case 'C':
			case 'D':
			case 'E':
			case 'F':
			case 'G':
			case 'H':
			case 'I':
			case 'J':
				if(max_print)
				{
					printf("%d\t%d\t%c\n", round, i, buf[i]);
					max_print--;
				}
				fnd_count++;
				break;

			default:
				break;
		}
	}   
}

int main()
{
	int i;
	size_t buf_size = ARRAY_LEN*sizeof(char);
	char *h_buf, *d_buf;

	cudaSetDevice(0);

	for(i=0; i<RUN_COUNT; i++)
	{
		h_buf = (char*)malloc(buf_size);
		cudaMalloc( (void**)&d_buf, buf_size ); 

		cudaMemcpy( h_buf, d_buf, buf_size, cudaMemcpyDeviceToHost ); 

		checker(i, h_buf);

		free(h_buf);
		cudaFree( d_buf );
	}

	printf("Total find %llu data\n", fnd_count);

	return 0;
}

	.file	"tmpxft_002e7c1f_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\t%d\t%c\n"
	.text
	.globl	_Z7checkeriPc
	.type	_Z7checkeriPc, @function
_Z7checkeriPc:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rdx
	.cfi_def_cfa_offset 48
.L5:
	movsbl	(%r12,%rbx), %r8d
	leal	-65(%r8), %eax
	cmpl	$9, %eax
	ja	.L3
	cmpl	$0, max_print(%rip)
	je	.L4
	movl	%ebx, %ecx
	movl	%ebp, %edx
	movq	%r13, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	decl	max_print(%rip)
.L4:
	incq	fnd_count(%rip)
.L3:
	incq	%rbx
	cmpq	$4096, %rbx
	jne	.L5
	popq	%rax
	.cfi_def_cfa_offset 40
	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
.LFE2027:
	.size	_Z7checkeriPc, .-_Z7checkeriPc
	.section	.rodata.str1.1
.LC1:
	.string	"Total find %llu data\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	xorl	%edi, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %r12
	call	cudaSetDevice@PLT
.L10:
	movl	$4096, %edi
	call	malloc@PLT
	movl	$4096, %esi
	movq	%r12, %rdi
	movq	%rax, %rbx
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	movl	$4096, %edx
	call	cudaMemcpy@PLT
	movq	%rbx, %rsi
	movl	%ebp, %edi
	incl	%ebp
	call	_Z7checkeriPc
	movq	%rbx, %rdi
	call	free@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	cmpl	$1000, %ebp
	jne	.L10
	movq	fnd_count(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2054:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2054:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	fnd_count
	.bss
	.align 8
	.type	fnd_count, @object
	.size	fnd_count, 8
fnd_count:
	.zero	8
	.globl	max_print
	.data
	.align 4
	.type	max_print, @object
	.size	max_print, 4
max_print:
	.long	20
	.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 <stdio.h>

#define ARRAY_LEN 4096
#define RUN_COUNT 1000

int max_print=20;
unsigned long long fnd_count=0;

void checker(int round, char* buf)
{
	int i;

	for(i=0; i<ARRAY_LEN; i++)
	{   
		switch(buf[i])
		{
			case 'A':
			case 'B':
			case 'C':
			case 'D':
			case 'E':
			case 'F':
			case 'G':
			case 'H':
			case 'I':
			case 'J':
				if(max_print)
				{
					printf("%d\t%d\t%c\n", round, i, buf[i]);
					max_print--;
				}
				fnd_count++;
				break;

			default:
				break;
		}
	}   
}

int main()
{
	int i;
	size_t buf_size = ARRAY_LEN*sizeof(char);
	char *h_buf, *d_buf;

	hipSetDevice(0);

	for(i=0; i<RUN_COUNT; i++)
	{
		h_buf = (char*)malloc(buf_size);
		hipMalloc( (void**)&d_buf, buf_size ); 

		hipMemcpy( h_buf, d_buf, buf_size, hipMemcpyDeviceToHost ); 

		checker(i, h_buf);

		free(h_buf);
		hipFree( d_buf );
	}

	printf("Total find %llu data\n", fnd_count);

	return 0;
}

	.text
	.file	"main.hip"
	.globl	_Z7checkeriPc                   # -- Begin function _Z7checkeriPc
	.type	_Z7checkeriPc,@function
_Z7checkeriPc:                          # @_Z7checkeriPc
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	%edi, %ebp
	xorl	%r14d, %r14d
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
	movzbl	(%rbx,%r14), %ecx
	leal	-65(%rcx), %eax
	cmpb	$9, %al
	ja	.LBB0_5
# %bb.2:                                #   in Loop: Header=BB0_1 Depth=1
	cmpl	$0, max_print(%rip)
	je	.LBB0_4
# %bb.3:                                #   in Loop: Header=BB0_1 Depth=1
	movl	$.L.str, %edi
	movl	%ebp, %esi
	movl	%r14d, %edx
                                        # kill: def $ecx killed $ecx killed $rcx
	xorl	%eax, %eax
	callq	printf
	decl	max_print(%rip)
.LBB0_4:                                #   in Loop: Header=BB0_1 Depth=1
	incq	fnd_count(%rip)
.LBB0_5:                                #   in Loop: Header=BB0_1 Depth=1
	incq	%r14
	cmpq	$4096, %r14                     # imm = 0x1000
	jne	.LBB0_1
# %bb.6:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z7checkeriPc, .Lfunc_end0-_Z7checkeriPc
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	xorl	%ebx, %ebx
	xorl	%edi, %edi
	callq	hipSetDevice
	leaq	8(%rsp), %r14
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	movl	$4096, %edi                     # imm = 0x1000
	callq	malloc
	movq	%rax, %r15
	movl	$4096, %esi                     # imm = 0x1000
	movq	%r14, %rdi
	callq	hipMalloc
	movq	8(%rsp), %rsi
	movl	$4096, %edx                     # imm = 0x1000
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%ebx, %edi
	movq	%r15, %rsi
	callq	_Z7checkeriPc
	movq	%r15, %rdi
	callq	free
	movq	8(%rsp), %rdi
	callq	hipFree
	incl	%ebx
	cmpl	$1000, %ebx                     # imm = 0x3E8
	jne	.LBB1_1
# %bb.2:
	movq	fnd_count(%rip), %rsi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.type	max_print,@object               # @max_print
	.data
	.globl	max_print
	.p2align	2, 0x0
max_print:
	.long	20                              # 0x14
	.size	max_print, 4

	.type	fnd_count,@object               # @fnd_count
	.bss
	.globl	fnd_count
	.p2align	3, 0x0
fnd_count:
	.quad	0                               # 0x0
	.size	fnd_count, 8

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

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Total find %llu data\n"
	.size	.L.str.1, 22

	.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 __hip_cuid_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
