#include <fstream>
#include <iostream>
#include <chrono> 
# include <mutex>
#include <stdio.h>
#include <string.h>

using namespace std;
# define NO_OF_CHARS 256  

char* getFileContents(const char*);

// preprocessing function 
__device__ void badCharHeuristic(char* str, int size,
	int badchar[NO_OF_CHARS]) {
	int i;

	// Initialize all occurrences as -1  
	for (i = 0; i < NO_OF_CHARS; i++)
		badchar[i] = -1;

	// Fill the actual value of last occurrence  
	for (i = 0; i < size; i++)
		badchar[(int)str[i]] = i;
}

//implementation Boyer Moore Algorithm
__global__ void search(const char* txt, char* pat, int chunk_size, int pat_size, int * t, int threads_per_block) {

	int offset = blockIdx.x* threads_per_block* chunk_size;
	int i = threadIdx.x;
	int start = offset+(i * chunk_size);
	int m = pat_size;
	int n = chunk_size;

	int badchar[NO_OF_CHARS];

	badCharHeuristic(pat, m, badchar);

	int s = 0; // s = shift of pattern
	while (s <= (n - m)) {
		int j = m - 1;
		while (j >= 0 && pat[j] == txt[s + j + start]) {
			j--;
		}
		if (j < 0) {
			//cout << "found pattern at = " << s << endl;
			atomicAdd(t, 1);
			s += (s + m < n) ? m - badchar[txt[s + m + start]] : 1;
		}
		else {
			int a = j - badchar[txt[s + j + start]];
			if (a < 1) {
				s += 1;
			}
			else {
				s += a;
			}
		}
	}
}

/* Driver code */
int main(int argc, char* argv[]) {
	/*
	input format: <file to search> <search pattern> <num thread blocks> <num threads>
	*/

	if (argc != 5) {
		cout << "input format: <file to search> <search pattern>  <num threads> <num thread blocks>";
		return -1;
	}
	char* file = argv[1];
	char* pat_ = argv[2];

	int pat_len = strlen(pat_);
	char* pat;
	
	cudaMallocManaged(&pat, pat_len);
	//copy input pattern from normal memory to shared CPU/GPU memory
	for (int i = 0; i < pat_len; i++) {
		pat[i] = pat_[i];
	}
	//shared count variable - needed by cpu and gpu
	int* total;
	cudaMallocManaged(&total, sizeof(int));

	//should check all these to prevent errors but naa. my project my rules
	char * contents = getFileContents(file);
	int num_threads = atoi(argv[4]);
	int num_blocks = atoi(argv[3]);

	int partitionLength = strlen(contents) / num_threads;
	auto start = chrono::high_resolution_clock::now();

	int threads_per_block = num_threads / num_blocks;
	//make num blocks * threads per block gpu threads
	search <<<num_blocks, threads_per_block >>> (contents, pat, partitionLength, pat_len,total, threads_per_block );
	//wait for GPU operations to terminate
	cudaDeviceSynchronize();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);

	cout << duration.count() << endl;
	//free shared variables
	cudaFree(contents);
	cudaFree(pat);
	cudaFree(total);
	return 0;
}

char* getFileContents(const char* filename) {
	ifstream in(filename, ios::in | ios::binary);
	if (in) {
		in.seekg(0, ios::end);
		int len = in.tellg();

		char* contents;
		cudaMallocManaged(&contents, len * sizeof(char));

		in.seekg(0, ios::beg);
		in.read(&contents[0], len);
		in.close();

		return(contents);
	}
	throw(errno);
}
	.file	"tmpxft_003883e9_00000000-6_kernel.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3959:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3959:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z16badCharHeuristicPciPi
	.type	_Z16badCharHeuristicPciPi, @function
_Z16badCharHeuristicPciPi:
.LFB3951:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE3951:
	.size	_Z16badCharHeuristicPciPi, .-_Z16badCharHeuristicPciPi
	.globl	_Z33__device_stub__Z6searchPKcPciiPiiPKcPciiPii
	.type	_Z33__device_stub__Z6searchPKcPciiPiiPKcPciiPii, @function
_Z33__device_stub__Z6searchPKcPciiPiiPKcPciiPii:
.LFB3981:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movl	%edx, 28(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 24(%rsp)
	leaq	64(%rsp), %rcx
	movq	%r8, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L4
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z6searchPKcPciiPii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L4:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L6
	call	__stack_chk_fail@PLT
.L6:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3981:
	.size	_Z33__device_stub__Z6searchPKcPciiPiiPKcPciiPii, .-_Z33__device_stub__Z6searchPKcPciiPiiPKcPciiPii
	.globl	_Z6searchPKcPciiPii
	.type	_Z6searchPKcPciiPii, @function
_Z6searchPKcPciiPii:
.LFB3982:
	.cfi_startproc
	endbr64
	jmp	_Z33__device_stub__Z6searchPKcPciiPiiPKcPciiPii
	.cfi_endproc
.LFE3982:
	.size	_Z6searchPKcPciiPii, .-_Z6searchPKcPciiPii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"_Z6searchPKcPciiPii"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3984:
	.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	.LC0(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z6searchPKcPciiPii(%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
.LFE3984:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.text
	.globl	_Z15getFileContentsPKc
	.type	_Z15getFileContentsPKc, @function
_Z15getFileContentsPKc:
.LFB3956:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3956
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rdi, %rsi
	movl	$12, %edx
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$552, %rsp
	.cfi_def_cfa_offset 576
	movq	%fs:40, %rax
	movq	%rax, 536(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
.LEHB0:
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode@PLT
.LEHE0:
	testb	$5, 304(%rsp)
	jne	.L13
	movl	$2, %edx
	xorl	%esi, %esi
	movq	%rbx, %rdi
.LEHB1:
	call	_ZNSi5seekgElSt12_Ios_Seekdir@PLT
	movq	%rbx, %rdi
	call	_ZNSi5tellgEv@PLT
	movslq	%eax, %rbp
	leaq	8(%rsp), %rdi
	movl	$1, %edx
	movq	%rbp, %rsi
	call	cudaMallocManaged@PLT
	xorl	%edx, %edx
	xorl	%esi, %esi
	movq	%rbx, %rdi
	call	_ZNSi5seekgElSt12_Ios_Seekdir@PLT
	movq	8(%rsp), %rsi
	movq	%rbp, %rdx
	movq	%rbx, %rdi
	call	_ZNSi4readEPcl@PLT
	movq	%rbx, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE5closeEv@PLT
	movq	%rbx, %rdi
	movq	8(%rsp), %rbp
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	536(%rsp), %rax
	subq	%fs:40, %rax
	je	.L17
	jmp	.L19
.L13:
	movl	$4, %edi
	call	__cxa_allocate_exception@PLT
	movq	%rax, %rbp
	call	__errno_location@PLT
	movl	(%rax), %eax
	movl	%eax, 0(%rbp)
	movq	536(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L19
	xorl	%edx, %edx
	leaq	_ZTIi(%rip), %rsi
	movq	%rbp, %rdi
	call	__cxa_throw@PLT
.LEHE1:
.L18:
	endbr64
	movq	%rax, %rbp
.L15:
	movq	%rbx, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	536(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L19
	movq	%rbp, %rdi
.LEHB2:
	call	_Unwind_Resume@PLT
.LEHE2:
.L19:
	call	__stack_chk_fail@PLT
.L17:
	addq	$552, %rsp
	.cfi_def_cfa_offset 24
	movq	%rbp, %rax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3956:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA3956:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3956-.LLSDACSB3956
.LLSDACSB3956:
	.uleb128 .LEHB0-.LFB3956
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB3956
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L18-.LFB3956
	.uleb128 0
	.uleb128 .LEHB2-.LFB3956
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE3956:
	.text
	.size	_Z15getFileContentsPKc, .-_Z15getFileContentsPKc
	.section	.rodata.str1.1
.LC1:
	.string	"input format: <file to search> <search pattern>  <num threads> <num thread blocks>"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB3952:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	cmpl	$5, %edi
	je	.L23
	movl	$82, %edx
	leaq	.LC1(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
	orl	$-1, %eax
	jmp	.L22
.L23:
	movq	16(%rsi), %r12
	movq	8(%rsi), %rbx
	movq	%rsi, %rbp
	movq	%r12, %rdi
	call	strlen@PLT
	leaq	16(%rsp), %rdi
	movl	$1, %edx
	movslq	%eax, %rsi
	movl	%eax, %r14d
	call	cudaMallocManaged@PLT
	xorl	%eax, %eax
.L25:
	cmpl	%eax, %r14d
	jle	.L30
	movb	(%r12,%rax), %cl
	movq	16(%rsp), %rdx
	movb	%cl, (%rdx,%rax)
	incq	%rax
	jmp	.L25
.L30:
	movl	$1, %edx
	movl	$4, %esi
	leaq	24(%rsp), %rdi
	call	cudaMallocManaged@PLT
	movq	%rbx, %rdi
	call	_Z15getFileContentsPKc
	movq	32(%rbp), %rdi
	movq	%rax, %r12
	call	atoi@PLT
	movq	24(%rbp), %rdi
	movslq	%eax, %rbx
	call	atoi@PLT
	movq	%r12, %rdi
	movl	%eax, %ebp
	call	strlen@PLT
	movq	%rax, 8(%rsp)
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	%ebp, 32(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%rax, %r13
	movl	%ebx, %eax
	cltd
	idivl	%ebp
	movl	%eax, 44(%rsp)
	movl	%eax, %r15d
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movl	52(%rsp), %ecx
	movq	%rax, 36(%rsp)
	movq	44(%rsp), %rdx
	movq	32(%rsp), %rdi
	movl	40(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L27
	movq	8(%rsp), %rax
	xorl	%edx, %edx
	movq	24(%rsp), %r8
	movl	%r15d, %r9d
	movq	16(%rsp), %rsi
	movl	%r14d, %ecx
	movq	%r12, %rdi
	divq	%rbx
	movl	%eax, %edx
	call	_Z33__device_stub__Z6searchPKcPciiPiiPKcPciiPii
.L27:
	call	cudaDeviceSynchronize@PLT
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	$1000, %ecx
	leaq	_ZSt4cout(%rip), %rdi
	subq	%r13, %rax
	cqto
	idivq	%rcx
	movq	%rax, %rsi
	call	_ZNSo9_M_insertIlEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	%r12, %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%eax, %eax
.L22:
	movq	56(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$72, %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
.LFE3952:
	.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 <fstream>
#include <iostream>
#include <chrono> 
# include <mutex>
#include <stdio.h>
#include <string.h>

using namespace std;
# define NO_OF_CHARS 256  

char* getFileContents(const char*);

// preprocessing function 
__device__ void badCharHeuristic(char* str, int size,
	int badchar[NO_OF_CHARS]) {
	int i;

	// Initialize all occurrences as -1  
	for (i = 0; i < NO_OF_CHARS; i++)
		badchar[i] = -1;

	// Fill the actual value of last occurrence  
	for (i = 0; i < size; i++)
		badchar[(int)str[i]] = i;
}

//implementation Boyer Moore Algorithm
__global__ void search(const char* txt, char* pat, int chunk_size, int pat_size, int * t, int threads_per_block) {

	int offset = blockIdx.x* threads_per_block* chunk_size;
	int i = threadIdx.x;
	int start = offset+(i * chunk_size);
	int m = pat_size;
	int n = chunk_size;

	int badchar[NO_OF_CHARS];

	badCharHeuristic(pat, m, badchar);

	int s = 0; // s = shift of pattern
	while (s <= (n - m)) {
		int j = m - 1;
		while (j >= 0 && pat[j] == txt[s + j + start]) {
			j--;
		}
		if (j < 0) {
			//cout << "found pattern at = " << s << endl;
			atomicAdd(t, 1);
			s += (s + m < n) ? m - badchar[txt[s + m + start]] : 1;
		}
		else {
			int a = j - badchar[txt[s + j + start]];
			if (a < 1) {
				s += 1;
			}
			else {
				s += a;
			}
		}
	}
}

/* Driver code */
int main(int argc, char* argv[]) {
	/*
	input format: <file to search> <search pattern> <num thread blocks> <num threads>
	*/

	if (argc != 5) {
		cout << "input format: <file to search> <search pattern>  <num threads> <num thread blocks>";
		return -1;
	}
	char* file = argv[1];
	char* pat_ = argv[2];

	int pat_len = strlen(pat_);
	char* pat;
	
	hipMallocManaged(&pat, pat_len);
	//copy input pattern from normal memory to shared CPU/GPU memory
	for (int i = 0; i < pat_len; i++) {
		pat[i] = pat_[i];
	}
	//shared count variable - needed by cpu and gpu
	int* total;
	hipMallocManaged(&total, sizeof(int));

	//should check all these to prevent errors but naa. my project my rules
	char * contents = getFileContents(file);
	int num_threads = atoi(argv[4]);
	int num_blocks = atoi(argv[3]);

	int partitionLength = strlen(contents) / num_threads;
	auto start = chrono::high_resolution_clock::now();

	int threads_per_block = num_threads / num_blocks;
	//make num blocks * threads per block gpu threads
	search <<<num_blocks, threads_per_block >>> (contents, pat, partitionLength, pat_len,total, threads_per_block );
	//wait for GPU operations to terminate
	hipDeviceSynchronize();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);

	cout << duration.count() << endl;
	//free shared variables
	hipFree(contents);
	hipFree(pat);
	hipFree(total);
	return 0;
}

char* getFileContents(const char* filename) {
	ifstream in(filename, ios::in | ios::binary);
	if (in) {
		in.seekg(0, ios::end);
		int len = in.tellg();

		char* contents;
		hipMallocManaged(&contents, len * sizeof(char));

		in.seekg(0, ios::beg);
		in.read(&contents[0], len);
		in.close();

		return(contents);
	}
	throw(errno);
}
	.text
	.file	"kernel.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z21__device_stub__searchPKcPciiPii # -- Begin function _Z21__device_stub__searchPKcPciiPii
	.type	_Z21__device_stub__searchPKcPciiPii,@function
_Z21__device_stub__searchPKcPciiPii:    # @_Z21__device_stub__searchPKcPciiPii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	20(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	16(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%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	$_Z6searchPKcPciiPii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z21__device_stub__searchPKcPciiPii, .Lfunc_end0-_Z21__device_stub__searchPKcPciiPii
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$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
	cmpl	$5, %edi
	jne	.LBB1_1
# %bb.2:
	movq	%rsi, %r15
	movq	8(%rsi), %rbx
	movq	16(%rsi), %r14
	movq	%r14, %rdi
	callq	strlen
	movq	%rax, %r13
	movslq	%r13d, %r12
	movq	%rsp, %rdi
	movq	%r12, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	testl	%r12d, %r12d
	jle	.LBB1_5
# %bb.3:                                # %.lr.ph.preheader
	movl	%r13d, %eax
	xorl	%ecx, %ecx
.LBB1_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movb	(%r14,%rcx), %dl
	movq	(%rsp), %rsi
	movb	%dl, (%rsi,%rcx)
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB1_4
.LBB1_5:                                # %._crit_edge
	movq	%r13, 16(%rsp)                  # 8-byte Spill
	leaq	8(%rsp), %rdi
	movl	$4, %esi
	movl	$1, %edx
	callq	hipMallocManaged
	movq	%rbx, %rdi
	callq	_Z15getFileContentsPKc
	movq	%rax, %rbx
	movq	32(%r15), %rdi
	callq	atoi
	movl	%eax, %ebp
	movq	24(%r15), %rdi
	callq	atoi
	movl	%eax, %r15d
	movq	%rbx, %rdi
	callq	strlen
	movq	%rax, %r14
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %r12
	movl	%ebp, %eax
	cltd
	idivl	%r15d
	movl	%eax, %r13d
	movl	%r15d, %edi
	btsq	$32, %rdi
	movq	%r13, %rdx
	btsq	$32, %rdx
	xorl	%r15d, %r15d
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_7
# %bb.6:
	movslq	%ebp, %rcx
	movq	%r14, %rax
	xorl	%edx, %edx
	divq	%rcx
	movq	(%rsp), %rsi
	movq	8(%rsp), %r8
	movq	%rbx, %rdi
	movl	%eax, %edx
	movq	16(%rsp), %rcx                  # 8-byte Reload
                                        # kill: def $ecx killed $ecx killed $rcx
	movl	%r13d, %r9d
	callq	_Z21__device_stub__searchPKcPciiPii
.LBB1_7:
	callq	hipDeviceSynchronize
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%r12, %rax
	movabsq	$2361183241434822607, %rcx      # imm = 0x20C49BA5E353F7CF
	imulq	%rcx
	movq	%rdx, %rsi
	shrq	$63, %rsi
	sarq	$7, %rdx
	addq	%rdx, %rsi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIlEERSoT_
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rbx, %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	jmp	.LBB1_8
.LBB1_1:
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$82, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$-1, %r15d
.LBB1_8:
	movl	%r15d, %eax
	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_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z15getFileContentsPKc          # -- Begin function _Z15getFileContentsPKc
	.type	_Z15getFileContentsPKc,@function
_Z15getFileContentsPKc:                 # @_Z15getFileContentsPKc
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$528, %rsp                      # imm = 0x210
	.cfi_def_cfa_offset 544
	.cfi_offset %rbx, -16
	movq	%rdi, %rsi
	leaq	8(%rsp), %rbx
	movq	%rbx, %rdi
	movl	$12, %edx
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode
	movq	(%rbx), %rax
	movq	-24(%rax), %rax
	testb	$5, 40(%rsp,%rax)
	jne	.LBB2_12
# %bb.1:
.Ltmp2:
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	_ZNSi5seekgElSt12_Ios_Seekdir
.Ltmp3:
# %bb.2:
.Ltmp5:
	leaq	8(%rsp), %rdi
	callq	_ZNSi5tellgEv
.Ltmp6:
# %bb.3:
	movslq	%eax, %rbx
.Ltmp8:
	movq	%rsp, %rdi
	movq	%rbx, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
.Ltmp9:
# %bb.4:                                # %_ZL16hipMallocManagedIcE10hipError_tPPT_mj.exit
.Ltmp10:
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	_ZNSi5seekgElSt12_Ios_Seekdir
.Ltmp11:
# %bb.5:
	movq	(%rsp), %rsi
.Ltmp12:
	leaq	8(%rsp), %rdi
	movq	%rbx, %rdx
	callq	_ZNSi4readEPcl
.Ltmp13:
# %bb.6:
.Ltmp14:
	leaq	8(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE5closeEv
.Ltmp15:
# %bb.7:
	movq	(%rsp), %rbx
	leaq	8(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	movq	%rbx, %rax
	addq	$528, %rsp                      # imm = 0x210
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB2_12:
	.cfi_def_cfa_offset 544
	movl	$4, %edi
	callq	__cxa_allocate_exception
	movq	%rax, %rbx
	callq	__errno_location
	movl	(%rax), %eax
	movl	%eax, (%rbx)
.Ltmp0:
	movl	$_ZTIi, %esi
	movq	%rbx, %rdi
	xorl	%edx, %edx
	callq	__cxa_throw
.Ltmp1:
# %bb.13:
.LBB2_8:
.Ltmp7:
	jmp	.LBB2_11
.LBB2_10:
.Ltmp4:
	jmp	.LBB2_11
.LBB2_9:
.Ltmp16:
.LBB2_11:
	movq	%rax, %rbx
	leaq	8(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end2:
	.size	_Z15getFileContentsPKc, .Lfunc_end2-_Z15getFileContentsPKc
	.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 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp2-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp2
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp2-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp3-.Ltmp2                  #   Call between .Ltmp2 and .Ltmp3
	.uleb128 .Ltmp4-.Lfunc_begin0           #     jumps to .Ltmp4
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp5-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp6-.Ltmp5                  #   Call between .Ltmp5 and .Ltmp6
	.uleb128 .Ltmp7-.Lfunc_begin0           #     jumps to .Ltmp7
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp8-.Lfunc_begin0           # >> Call Site 4 <<
	.uleb128 .Ltmp15-.Ltmp8                 #   Call between .Ltmp8 and .Ltmp15
	.uleb128 .Ltmp16-.Lfunc_begin0          #     jumps to .Ltmp16
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp15-.Lfunc_begin0          # >> Call Site 5 <<
	.uleb128 .Ltmp0-.Ltmp15                 #   Call between .Ltmp15 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 6 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp4-.Lfunc_begin0           #     jumps to .Ltmp4
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp1-.Lfunc_begin0           # >> Call Site 7 <<
	.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
	.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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6searchPKcPciiPii, %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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z6searchPKcPciiPii,@object     # @_Z6searchPKcPciiPii
	.section	.rodata,"a",@progbits
	.globl	_Z6searchPKcPciiPii
	.p2align	3, 0x0
_Z6searchPKcPciiPii:
	.quad	_Z21__device_stub__searchPKcPciiPii
	.size	_Z6searchPKcPciiPii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"input format: <file to search> <search pattern>  <num threads> <num thread blocks>"
	.size	.L.str, 83

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6searchPKcPciiPii"
	.size	.L__unnamed_1, 20

	.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 _Z21__device_stub__searchPKcPciiPii
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z6searchPKcPciiPii
	.addrsig_sym _ZSt4cout
	.addrsig_sym _ZTIi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6searchPKcPciiPii     ; -- Begin function _Z6searchPKcPciiPii
	.globl	_Z6searchPKcPciiPii
	.p2align	8
	.type	_Z6searchPKcPciiPii,@function
_Z6searchPKcPciiPii:                    ; @_Z6searchPKcPciiPii
; %bb.0:
	v_mov_b32_e32 v1, -1
	s_mov_b32 s2, 0
.LBB0_1:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_i32 s3, s2, 16
	s_add_i32 s2, s2, 4
	scratch_store_b32 off, v1, s3
	s_cmpk_eq_i32 s2, 0x400
	s_cbranch_scc0 .LBB0_1
; %bb.2:                                ; %.preheader.i
	s_clause 0x1
	s_load_b64 s[2:3], s[0:1], 0x10
	s_load_b128 s[4:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s3, 1
	s_cbranch_scc1 .LBB0_5
; %bb.3:                                ; %.lr.ph.i.preheader
	v_mov_b32_e32 v1, 0
	s_mov_b64 s[8:9], 0
.LBB0_4:                                ; %.lr.ph.i
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s10, s6, s8
	s_addc_u32 s11, s7, s9
	v_mov_b32_e32 v3, s8
	global_load_i8 v2, v1, s[10:11]
	s_add_u32 s8, s8, 1
	s_addc_u32 s9, s9, 0
	s_cmp_lg_u32 s3, s8
	s_waitcnt vmcnt(0)
	v_lshlrev_b32_e32 v2, 2, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v2, 16, v2
	scratch_store_b32 v2, v3, off
	s_cbranch_scc1 .LBB0_4
.LBB0_5:                                ; %_Z16badCharHeuristicPciPi.exit
	s_sub_i32 s8, s2, s3
	s_mov_b32 s9, 0
	s_cmp_lt_i32 s8, 0
	s_cbranch_scc1 .LBB0_21
; %bb.6:                                ; %.preheader.preheader
	s_clause 0x1
	s_load_b32 s10, s[0:1], 0x20
	s_load_b64 s[0:1], s[0:1], 0x18
	v_mov_b32_e32 v3, 0
	s_waitcnt lgkmcnt(0)
	v_mad_u64_u32 v[1:2], null, s15, s10, v[0:1]
	s_min_i32 s10, s3, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_add_i32 s10, s10, -1
	v_mul_lo_u32 v0, v1, s2
	s_delay_alu instid0(VALU_DEP_1)
	v_dual_mov_b32 v1, 0 :: v_dual_add_nc_u32 v2, -1, v0
.LBB0_7:                                ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_8 Depth 2
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v4, v2, v1
	s_mov_b32 s11, 0
	s_mov_b32 s15, s3
                                        ; implicit-def: $sgpr12
                                        ; implicit-def: $sgpr13
.LBB0_8:                                ;   Parent Loop BB0_7 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_gt_i32 s15, 0
	s_cselect_b32 s14, -1, 0
	s_or_b32 s13, s13, exec_lo
	s_cmp_lt_i32 s15, 1
	s_cbranch_scc1 .LBB0_10
; %bb.9:                                ;   in Loop: Header=BB0_8 Depth=2
	v_add_nc_u32_e32 v5, s15, v4
	s_add_i32 s16, s15, -1
	s_and_not1_b32 s13, s13, exec_lo
	v_mov_b32_e32 v7, s16
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v6, 31, v5
	v_add_co_u32 v5, vcc_lo, s4, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s5, v6, vcc_lo
	global_load_u8 v7, v7, s[6:7]
	global_load_u8 v5, v[5:6], off
	s_waitcnt vmcnt(0)
	v_cmp_ne_u16_e32 vcc_lo, v7, v5
	s_and_b32 s15, vcc_lo, exec_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 s13, s13, s15
	s_mov_b32 s15, s16
	s_branch .LBB0_11
.LBB0_10:                               ;   in Loop: Header=BB0_8 Depth=2
	s_mov_b32 s16, s10
                                        ; implicit-def: $sgpr15
.LBB0_11:                               ; %Flow88
                                        ;   in Loop: Header=BB0_8 Depth=2
	s_and_b32 s17, exec_lo, s13
	v_mov_b32_e32 v5, s16
	s_or_b32 s11, s17, s11
	s_and_not1_b32 s12, s12, exec_lo
	s_and_b32 s14, s14, exec_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 s12, s12, s14
	s_and_not1_b32 exec_lo, exec_lo, s11
	s_cbranch_execnz .LBB0_8
; %bb.12:                               ; %.critedge
                                        ;   in Loop: Header=BB0_7 Depth=1
	s_or_b32 exec_lo, exec_lo, s11
                                        ; implicit-def: $vgpr4
	s_and_saveexec_b32 s11, s12
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s11, exec_lo, s11
	s_cbranch_execz .LBB0_14
; %bb.13:                               ;   in Loop: Header=BB0_7 Depth=1
	v_add3_u32 v4, v1, v0, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v7, 31, v4
	v_add_co_u32 v6, vcc_lo, s4, v4
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v7, vcc_lo
	global_load_i8 v4, v[6:7], off
	s_waitcnt vmcnt(0)
	v_lshl_add_u32 v4, v4, 2, 16
	scratch_load_b32 v4, v4, off
	s_waitcnt vmcnt(0)
	v_sub_nc_u32_e32 v4, v5, v4
	s_delay_alu instid0(VALU_DEP_1)
	v_max_i32_e32 v4, 1, v4
.LBB0_14:                               ; %Flow85
                                        ;   in Loop: Header=BB0_7 Depth=1
	s_and_not1_saveexec_b32 s11, s11
	s_cbranch_execz .LBB0_20
; %bb.15:                               ;   in Loop: Header=BB0_7 Depth=1
	s_mov_b32 s13, exec_lo
	s_mov_b32 s12, exec_lo
	v_mbcnt_lo_u32_b32 v4, s13, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_eq_u32_e32 0, v4
	s_cbranch_execz .LBB0_17
; %bb.16:                               ;   in Loop: Header=BB0_7 Depth=1
	s_bcnt1_i32_b32 s13, s13
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mov_b32_e32 v4, s13
	global_atomic_add_u32 v3, v4, s[0:1]
.LBB0_17:                               ;   in Loop: Header=BB0_7 Depth=1
	s_or_b32 exec_lo, exec_lo, s12
	v_dual_mov_b32 v4, 1 :: v_dual_add_nc_u32 v5, s3, v1
	s_mov_b32 s12, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s2, v5
	s_cbranch_execz .LBB0_19
; %bb.18:                               ;   in Loop: Header=BB0_7 Depth=1
	v_add_nc_u32_e32 v4, v5, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v5, 31, v4
	v_add_co_u32 v4, vcc_lo, s4, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v5, vcc_lo
	global_load_i8 v4, v[4:5], off
	s_waitcnt vmcnt(0)
	v_lshl_add_u32 v4, v4, 2, 16
	scratch_load_b32 v4, v4, off
	s_waitcnt vmcnt(0)
	v_sub_nc_u32_e32 v4, s3, v4
.LBB0_19:                               ; %Flow
                                        ;   in Loop: Header=BB0_7 Depth=1
	s_or_b32 exec_lo, exec_lo, s12
.LBB0_20:                               ; %Flow86
                                        ;   in Loop: Header=BB0_7 Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_or_b32 exec_lo, exec_lo, s11
	v_add_nc_u32_e32 v1, v4, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_lt_i32_e32 vcc_lo, s8, v1
	s_or_b32 s9, vcc_lo, s9
	s_and_not1_b32 exec_lo, exec_lo, s9
	s_cbranch_execnz .LBB0_7
.LBB0_21:                               ; %._crit_edge
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6searchPKcPciiPii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 1040
		.amdhsa_kernarg_size 36
		.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 1
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 8
		.amdhsa_next_free_sgpr 18
		.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	_Z6searchPKcPciiPii, .Lfunc_end0-_Z6searchPKcPciiPii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 664
; NumSgprs: 20
; NumVgprs: 8
; ScratchSize: 1040
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 20
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 1
; 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
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 36
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6searchPKcPciiPii
    .private_segment_fixed_size: 1040
    .sgpr_count:     20
    .sgpr_spill_count: 0
    .symbol:         _Z6searchPKcPciiPii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
