// CMPE297-6 HW2
// CUDA version Rabin-Karp

#include<stdio.h>
#include<iostream>

#define NUM_PATTERN 4
#define PATTERN_MAX_LENGTH 15
/*ADD CODE HERE: Implement the parallel version of the sequential Rabin-Karp*/
__global__ void 
findIfExistsCu(char* input, int input_length, char* pattern, int *pattern_length, int *patHash, char* result, unsigned long long* runtime)
{
    //printf("Starting kernal thread %d block %d with pattern start %d\n",threadIdx.x,blockIdx.x,pattern_length[threadIdx.x]);
    
    unsigned long long start_time = clock64();
    int loc_in_input = threadIdx.x;
    int pattern_num = blockIdx.x; 
    int input_hash,i;

    //printf("input section: ");
    for(input_hash=0,i=loc_in_input;i<pattern_length[pattern_num]+loc_in_input;i++) {
        //printf("%c",input[i]);
        input_hash=((input_hash << 8) + input[i]) % 997;
    }
    //printf("\n");
    int j;
    bool match = true;
    __syncthreads();
    if (input_hash == patHash[pattern_num]) {
        int pattern_start_index = 0;
        for(int pat=0;pat < blockIdx.x;pat++) {
            pattern_start_index += pattern_length[pat];
        } 
        for(j=loc_in_input;j<loc_in_input+pattern_length[pattern_num];j++) {
           //printf("Block %d Thread %d [%d] pattern char %c input char %c\n",blockIdx.x,threadIdx.x,j,pattern[j-loc_in_input],input[j]);
           match &= (pattern[pattern_start_index+(j-loc_in_input)] == input[j]);
        }
        result[pattern_num] |= match?1:0;
    }

    if(result[pattern_num]){
        //printf("***pattern found in kernel at [%d]\n",pattern_num);
    }else {
       //////////////// printf("nothing here\n");
    }
	unsigned long long stop_time = clock64();
    runtime[(input_length*pattern_num)+loc_in_input] = (unsigned long long)(stop_time-start_time);
}

int main()
{
	// host variables
	char input[] = "Searching for multiple patterns in the input sequence."; 	/*Sample Input*/
	const char *pattern[NUM_PATTERN] = {"multiple","s i","ddd","seq"}; 		/*Sample Pattern*/
    char *patternflat;
    int patHash[NUM_PATTERN]; 			/*hash for the pattern*/
	char* result; 				/*Result array*/
	int pattern_length[NUM_PATTERN];		/*Pattern Length*/
	int input_length = strlen(input); 		/*Input Length*/
	// device variables
	char* d_input;
	char* d_pattern;
	char* d_result;
    int * d_pattern_length;
    int * d_patHash;
    
    int patternflat_length=0;
	/*Calculate the hash of the pattern*/
    for(int pl = 0; pl < NUM_PATTERN;pl++) {
        pattern_length[pl]=strlen(pattern[pl]);
        patternflat_length += pattern_length[pl];
    }
    patternflat = (char*)malloc(patternflat_length * sizeof(char));
    int flatindex = 0;
    for(int p = 0;p < NUM_PATTERN;p++) {
        //printf("strlen for \"%s\" is %d\n",pattern[p],pattern_length[p]);	
        memcpy(patternflat+flatindex,pattern[p],pattern_length[p]);
        flatindex += pattern_length[p];
        for (int i = 0; i < pattern_length[p]; i++)
        {
            patHash[p] = (patHash[p] * 256 + pattern[p][i]) % 997;
        }
   
    }
    //printf("\ndone calculating hash\n");
	// measure the execution time by using clock() api in the kernel as we did in Lab3
	int runtime_size = input_length*NUM_PATTERN*sizeof(unsigned long long);

    // Error code to check return values for CUDA calls
    cudaError_t err = cudaSuccess;
	
    unsigned long long* d_runtime;
	result = (char *) malloc((NUM_PATTERN)*sizeof(char));
    memset(result,0,NUM_PATTERN*sizeof(char));
	unsigned long long* runtime = (unsigned long long *) malloc(runtime_size);
	memset(runtime,0,runtime_size);
    err = cudaMalloc((void **)&d_runtime,runtime_size);
    
    if (err != cudaSuccess) {
        fprintf(stderr,"Failed to allocated d_runtime (error code %s)!\n",cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    
	/*ADD CODE HERE: Allocate memory on the GPU and copy or set the appropriate values from the HOST*/
    
	
    err = cudaMalloc((void **)&d_input,input_length);
    if (err != cudaSuccess) {
        fprintf(stderr,"Failed to allocated input (error code %s)!\n",cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }

    err = cudaMalloc((void **)&d_pattern,flatindex*sizeof(char));
    if (err != cudaSuccess) {
        fprintf(stderr,"Failed to allocated input (error code %s)!\n",cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }

    err = cudaMalloc((void **)&d_pattern_length,NUM_PATTERN*sizeof(int));
    if (err != cudaSuccess) {
        fprintf(stderr,"Failed to allocated pattern_length[] (error code %s)!\n",cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    
    err = cudaMalloc((void **)&d_patHash,NUM_PATTERN*sizeof(int));
    if (err != cudaSuccess) {
        fprintf(stderr,"Failed to allocated patHash[] (error code %s)!\n",cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }

    err = cudaMalloc((void **)&d_result,(NUM_PATTERN)*sizeof(char));
    if (err != cudaSuccess) {
        fprintf(stderr,"Failer to allocate result (error code %s)!\n",cudaGetErrorString(err));
    }
    err = cudaMemcpy(d_result,result,NUM_PATTERN*sizeof(char),cudaMemcpyHostToDevice);
    if (err != cudaSuccess) {
        fprintf(stderr,"Failed to copy result (error code %s)!\n",cudaGetErrorString(err));
    }
    
    err = cudaMemcpy(d_pattern,patternflat,flatindex*sizeof(char),cudaMemcpyHostToDevice);
    if (err != cudaSuccess) {
        fprintf(stderr,"Failed to copy pattern (error code %s)!\n",cudaGetErrorString(err));
    }

    err = cudaMemcpy(d_pattern_length,pattern_length,NUM_PATTERN*sizeof(int),cudaMemcpyHostToDevice);
    if (err != cudaSuccess) {
        fprintf(stderr,"Failed to copy pattern_length[] (error code %s)!\n",cudaGetErrorString(err));
    }
    
    err = cudaMemcpy(d_patHash,patHash,NUM_PATTERN*sizeof(int),cudaMemcpyHostToDevice);
    if (err != cudaSuccess) {
        fprintf(stderr,"Failed to copy payHash[] (error code %s)!\n",cudaGetErrorString(err));
    }

    err = cudaMemcpy(d_input,input,input_length,cudaMemcpyHostToDevice);
    if (err != cudaSuccess) {
        fprintf(stderr,"Failed to copy input (error code %s)!\n",cudaGetErrorString(err));
    }

	/*ADD CODE HERE: Launch the kernel and pass the arguments*/
    int blocks = NUM_PATTERN;
    int threads = input_length;
	findIfExistsCu<<<blocks,threads>>>(d_input,input_length,d_pattern,d_pattern_length,d_patHash,d_result,d_runtime);
    err = cudaGetLastError();
    if (err != cudaSuccess) {
        fprintf(stderr,"Failed to launch kernel (error code %s)!\n",cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }

    err = cudaMemcpy(result,d_result,NUM_PATTERN*sizeof(char),cudaMemcpyDeviceToHost);
    if (err != cudaSuccess) {
        fprintf(stderr,"Failed to copy back result (error code %s)!\n",cudaGetErrorString(err)); 
        exit(EXIT_FAILURE);
    }	
    cudaThreadSynchronize();	
	/*ADD CODE HERE: Copy the execution times from the GPU memory to HOST Code*/		


    cudaMemcpy(runtime, d_runtime, runtime_size, cudaMemcpyDeviceToHost);
    cudaThreadSynchronize();

    unsigned long long elapsed_time = 0;
    for(int i = 0; i < input_length*NUM_PATTERN; i++)
        if(elapsed_time < runtime[i])
            elapsed_time = runtime[i];

	printf("\nTotal cycles: %d \n", (int)elapsed_time);

    printf("Searching for multiple patterns in the input sequence\n");
    printf("Input string = %s\n",input);
    for (int i = 0;i < NUM_PATTERN;i++) {
        printf("Pattern: \"%s\" %s\n",pattern[i],result[i]?"was found":"was not found");
    }	
	/*ADD CODE HERE: COPY the result and print the result as in the HW description*/
	
	return 0;
}


	.file	"tmpxft_0037281d_00000000-6_cmpe297_hw2_rabin_karp_multiple.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3638:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3638:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z46__device_stub__Z14findIfExistsCuPciS_PiS0_S_PyPciS_PiS0_S_Py
	.type	_Z46__device_stub__Z14findIfExistsCuPciS_PiS0_S_PyPciS_PiS0_S_Py, @function
_Z46__device_stub__Z14findIfExistsCuPciS_PiS0_S_PyPciS_PiS0_S_Py:
.LFB3660:
	.cfi_startproc
	endbr64
	subq	$200, %rsp
	.cfi_def_cfa_offset 208
	movq	208(%rsp), %rax
	movq	%rdi, 56(%rsp)
	leaq	80(%rsp), %rdi
	movl	%esi, 52(%rsp)
	leaq	92(%rsp), %rsi
	movq	%rdx, 40(%rsp)
	leaq	64(%rsp), %rdx
	movq	%rcx, 32(%rsp)
	leaq	72(%rsp), %rcx
	movq	%r8, 24(%rsp)
	movq	%r9, 16(%rsp)
	movq	%rax, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 184(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rax
	movl	$1, 88(%rsp)
	movq	%rax, 128(%rsp)
	leaq	52(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 176(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 80(%rsp)
	movq	%rax, 92(%rsp)
	movl	$1, 100(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	72(%rsp)
	.cfi_def_cfa_offset 216
	leaq	_Z14findIfExistsCuPciS_PiS0_S_Py(%rip), %rdi
	pushq	72(%rsp)
	.cfi_def_cfa_offset 224
	movq	108(%rsp), %rcx
	movl	116(%rsp), %r8d
	movq	96(%rsp), %rsi
	movl	104(%rsp), %edx
	leaq	144(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 216
	popq	%rdx
	.cfi_def_cfa_offset 208
.L2:
	movq	184(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$200, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3660:
	.size	_Z46__device_stub__Z14findIfExistsCuPciS_PiS0_S_PyPciS_PiS0_S_Py, .-_Z46__device_stub__Z14findIfExistsCuPciS_PiS0_S_PyPciS_PiS0_S_Py
	.globl	_Z14findIfExistsCuPciS_PiS0_S_Py
	.type	_Z14findIfExistsCuPciS_PiS0_S_Py, @function
_Z14findIfExistsCuPciS_PiS0_S_Py:
.LFB3661:
	.cfi_startproc
	endbr64
	jmp	_Z46__device_stub__Z14findIfExistsCuPciS_PiS0_S_PyPciS_PiS0_S_Py
	.cfi_endproc
.LFE3661:
	.size	_Z14findIfExistsCuPciS_PiS0_S_Py, .-_Z14findIfExistsCuPciS_PiS0_S_Py
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"was found"
.LC1:
	.string	"was not found"
.LC3:
	.string	"multiple"
.LC4:
	.string	"s i"
.LC5:
	.string	"ddd"
.LC6:
	.string	"seq"
.LC7:
	.string	"Failed to allocated d_runtime (error code %s)!\n"
.LC8:
	.string	"Failed to allocated input (error code %s)!\n"
.LC9:
	.string	"Failed to allocated pattern_length[] (error code %s)!\n"
.LC10:
	.string	"Failed to allocated patHash[] (error code %s)!\n"
.LC11:
	.string	"Failer to allocate result (error code %s)!\n"
.LC12:
	.string	"Failed to copy result (error code %s)!\n"
.LC13:
	.string	"Failed to copy pattern (error code %s)!\n"
.LC14:
	.string	"Failed to copy pattern_length[] (error code %s)!\n"
.LC15:
	.string	"Failed to copy payHash[] (error code %s)!\n"
.LC16:
	.string	"Failed to copy input (error code %s)!\n"
.LC17:
	.string	"Failed to launch kernel (error code %s)!\n"
.LC18:
	.string	"Failed to copy back result (error code %s)!\n"
.LC19:
	.string	"\nTotal cycles: %d \n"
.LC20:
	.string	"Searching for multiple patterns in the input sequence\n"
.LC21:
	.string	"Input string = %s\n"
.LC22:
	.string	"Pattern: \"%s\" %s\n"
.LC2:
	.string	"Searching for multiple patterns in the input sequence."
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC2(%rip), %rsi
	movl	$55, %ecx
	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
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$248, %rsp
	.cfi_def_cfa_offset 304
	movq	%fs:40, %rax
	movq	%rax, 232(%rsp)
	xorl	%eax, %eax
	leaq	.LC3(%rip), %rax
	leaq	177(%rsp), %rdi
	movq	%rax, 144(%rsp)
	leaq	.LC4(%rip), %rax
	leaq	144(%rsp), %r14
	movq	%rax, 152(%rsp)
	leaq	.LC5(%rip), %rax
	leaq	128(%rsp), %r15
	rep movsb
	movq	%rax, 160(%rsp)
	leaq	.LC6(%rip), %rax
	movq	%rax, 168(%rsp)
	leaq	177(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	strlen@PLT
	movl	%eax, 28(%rsp)
	movq	%rax, %rbx
.L9:
	movq	(%r14,%r12,8), %rdi
	call	strlen@PLT
	movl	%eax, (%r15,%r12,4)
	incq	%r12
	addl	%eax, %ebp
	cmpq	$4, %r12
	jne	.L9
	movslq	%ebp, %rbp
	xorl	%r12d, %r12d
	xorl	%r13d, %r13d
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rax, 16(%rsp)
.L12:
	movslq	%r13d, %rdi
	movq	16(%rsp), %rax
	movq	(%r14,%r12,2), %rsi
	cmpq	%rdi, %rbp
	movq	%rdi, %rcx
	movslq	(%r15,%r12), %rdx
	cmovnb	%rbp, %rcx
	movq	%rsi, (%rsp)
	movl	%edx, 24(%rsp)
	subq	%rdi, %rcx
	addq	%rax, %rdi
	call	__memcpy_chk@PLT
	movl	24(%rsp), %r9d
	movq	(%rsp), %rsi
	xorl	%ecx, %ecx
	addl	%r9d, %r13d
.L10:
	cmpl	%ecx, %r9d
	jle	.L57
	movl	112(%rsp,%r12), %eax
	movsbl	(%rsi,%rcx), %edx
	movl	$997, %edi
	incq	%rcx
	sall	$8, %eax
	addl	%edx, %eax
	cltd
	idivl	%edi
	movl	%edx, 112(%rsp,%r12)
	jmp	.L10
.L57:
	addq	$4, %r12
	cmpq	$16, %r12
	jne	.L12
	leal	0(,%rbx,4), %eax
	movl	$4, %edi
	movl	%eax, 24(%rsp)
	call	malloc@PLT
	xorl	%esi, %esi
	movl	%esi, (%rax)
	movq	%rax, %rbp
	movl	%ebx, %eax
	sall	$5, %eax
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	malloc@PLT
	movq	(%rsp), %rcx
	xorl	%esi, %esi
	movq	%rax, %rdi
	movq	%rax, %r12
	movq	%rcx, %rdx
	call	__memset_chk@PLT
	movq	(%rsp), %rsi
	leaq	80(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L13
	call	cudaGetErrorString@PLT
	leaq	.LC7(%rip), %rdx
	movq	%rax, %rcx
	jmp	.L55
.L13:
	leaq	40(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L14
.L56:
	call	cudaGetErrorString@PLT
	leaq	.LC8(%rip), %rdx
	movq	%rax, %rcx
.L55:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L14:
	movslq	%r13d, %r13
	leaq	48(%rsp), %rdi
	movq	%r13, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L56
	leaq	64(%rsp), %rdi
	movl	$16, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L16
	call	cudaGetErrorString@PLT
	leaq	.LC9(%rip), %rdx
	movq	%rax, %rcx
	jmp	.L55
.L16:
	leaq	72(%rsp), %rdi
	movl	$16, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L17
	call	cudaGetErrorString@PLT
	leaq	.LC10(%rip), %rdx
	movq	%rax, %rcx
	jmp	.L55
.L17:
	leaq	56(%rsp), %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L18
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC11(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L18:
	movq	56(%rsp), %rdi
	movl	$1, %ecx
	movl	$4, %edx
	movq	%rbp, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L19
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC12(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L19:
	movq	48(%rsp), %rdi
	movq	16(%rsp), %rsi
	movl	$1, %ecx
	movq	%r13, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L20
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC13(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L20:
	movq	64(%rsp), %rdi
	movl	$1, %ecx
	movl	$16, %edx
	movq	%r15, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L21
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC14(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L21:
	movq	72(%rsp), %rdi
	leaq	112(%rsp), %rsi
	movl	$1, %ecx
	movl	$16, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L22
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC15(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L22:
	movq	40(%rsp), %rdi
	movq	8(%rsp), %rsi
	movl	$1, %ecx
	movq	%rbx, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L23
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC16(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L23:
	movl	%ebx, 100(%rsp)
	movl	$1073741825, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	salq	$2, %rdi
	movl	$1, %esi
	movl	$1, 96(%rsp)
	movq	%rax, 104(%rsp)
	movl	108(%rsp), %ecx
	movq	100(%rsp), %rdx
	movq	%rdi, 88(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	pushq	%rax
	.cfi_def_cfa_offset 312
	pushq	88(%rsp)
	.cfi_def_cfa_offset 320
	movq	72(%rsp), %r9
	movq	88(%rsp), %r8
	movq	80(%rsp), %rcx
	movq	64(%rsp), %rdx
	movl	44(%rsp), %esi
	movq	56(%rsp), %rdi
	call	_Z46__device_stub__Z14findIfExistsCuPciS_PiS0_S_PyPciS_PiS0_S_Py
	popq	%rdx
	.cfi_def_cfa_offset 312
	popq	%rcx
	.cfi_def_cfa_offset 304
.L24:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L25
	call	cudaGetErrorString@PLT
	leaq	.LC17(%rip), %rdx
	movq	%rax, %rcx
	jmp	.L55
.L25:
	movq	56(%rsp), %rsi
	movq	%rbp, %rdi
	movl	$2, %ecx
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L26
	call	cudaGetErrorString@PLT
	leaq	.LC18(%rip), %rdx
	movq	%rax, %rcx
	jmp	.L55
.L26:
	call	cudaThreadSynchronize@PLT
	movq	(%rsp), %rdx
	movq	80(%rsp), %rsi
	movq	%r12, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	call	cudaThreadSynchronize@PLT
	xorl	%eax, %eax
	xorl	%edx, %edx
.L27:
	cmpl	%eax, 24(%rsp)
	jle	.L58
	movq	(%r12,%rax,8), %rcx
	cmpq	%rcx, %rdx
	cmovb	%rcx, %rdx
	incq	%rax
	jmp	.L27
.L58:
	leaq	.LC19(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
	leaq	.LC20(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	8(%rsp), %rdx
	leaq	.LC21(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	leaq	.LC1(%rip), %r12
	call	__printf_chk@PLT
.L30:
	cmpb	$0, 0(%rbp,%rbx)
	movq	(%r14,%rbx,8), %rdx
	leaq	.LC0(%rip), %rcx
	leaq	.LC22(%rip), %rsi
	cmove	%r12, %rcx
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%rbx
	call	__printf_chk@PLT
	cmpq	$4, %rbx
	jne	.L30
	movq	232(%rsp), %rax
	subq	%fs:40, %rax
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$248, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3635:
	.size	main, .-main
	.section	.rodata.str1.1
.LC23:
	.string	"_Z14findIfExistsCuPciS_PiS0_S_Py"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3663:
	.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	.LC23(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14findIfExistsCuPciS_PiS0_S_Py(%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
.LFE3663:
	.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
	.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:

// CMPE297-6 HW2
// CUDA version Rabin-Karp


#include <hip/hip_runtime.h>
#include<stdio.h>
#include<iostream>

#define NUM_PATTERN 4
#define PATTERN_MAX_LENGTH 15
/*ADD CODE HERE: Implement the parallel version of the sequential Rabin-Karp*/
__global__ void 
findIfExistsCu(char* input, int input_length, char* pattern, int *pattern_length, int *patHash, char* result, unsigned long long* runtime)
{
    //printf("Starting kernal thread %d block %d with pattern start %d\n",threadIdx.x,blockIdx.x,pattern_length[threadIdx.x]);
    
    unsigned long long start_time = clock64();
    int loc_in_input = threadIdx.x;
    int pattern_num = blockIdx.x; 
    int input_hash,i;

    //printf("input section: ");
    for(input_hash=0,i=loc_in_input;i<pattern_length[pattern_num]+loc_in_input;i++) {
        //printf("%c",input[i]);
        input_hash=((input_hash << 8) + input[i]) % 997;
    }
    //printf("\n");
    int j;
    bool match = true;
    __syncthreads();
    if (input_hash == patHash[pattern_num]) {
        int pattern_start_index = 0;
        for(int pat=0;pat < blockIdx.x;pat++) {
            pattern_start_index += pattern_length[pat];
        } 
        for(j=loc_in_input;j<loc_in_input+pattern_length[pattern_num];j++) {
           //printf("Block %d Thread %d [%d] pattern char %c input char %c\n",blockIdx.x,threadIdx.x,j,pattern[j-loc_in_input],input[j]);
           match &= (pattern[pattern_start_index+(j-loc_in_input)] == input[j]);
        }
        result[pattern_num] |= match?1:0;
    }

    if(result[pattern_num]){
        //printf("***pattern found in kernel at [%d]\n",pattern_num);
    }else {
       //////////////// printf("nothing here\n");
    }
	unsigned long long stop_time = clock64();
    runtime[(input_length*pattern_num)+loc_in_input] = (unsigned long long)(stop_time-start_time);
}

int main()
{
	// host variables
	char input[] = "Searching for multiple patterns in the input sequence."; 	/*Sample Input*/
	const char *pattern[NUM_PATTERN] = {"multiple","s i","ddd","seq"}; 		/*Sample Pattern*/
    char *patternflat;
    int patHash[NUM_PATTERN]; 			/*hash for the pattern*/
	char* result; 				/*Result array*/
	int pattern_length[NUM_PATTERN];		/*Pattern Length*/
	int input_length = strlen(input); 		/*Input Length*/
	// device variables
	char* d_input;
	char* d_pattern;
	char* d_result;
    int * d_pattern_length;
    int * d_patHash;
    
    int patternflat_length=0;
	/*Calculate the hash of the pattern*/
    for(int pl = 0; pl < NUM_PATTERN;pl++) {
        pattern_length[pl]=strlen(pattern[pl]);
        patternflat_length += pattern_length[pl];
    }
    patternflat = (char*)malloc(patternflat_length * sizeof(char));
    int flatindex = 0;
    for(int p = 0;p < NUM_PATTERN;p++) {
        //printf("strlen for \"%s\" is %d\n",pattern[p],pattern_length[p]);	
        memcpy(patternflat+flatindex,pattern[p],pattern_length[p]);
        flatindex += pattern_length[p];
        for (int i = 0; i < pattern_length[p]; i++)
        {
            patHash[p] = (patHash[p] * 256 + pattern[p][i]) % 997;
        }
   
    }
    //printf("\ndone calculating hash\n");
	// measure the execution time by using clock() api in the kernel as we did in Lab3
	int runtime_size = input_length*NUM_PATTERN*sizeof(unsigned long long);

    // Error code to check return values for CUDA calls
    hipError_t err = hipSuccess;
	
    unsigned long long* d_runtime;
	result = (char *) malloc((NUM_PATTERN)*sizeof(char));
    memset(result,0,NUM_PATTERN*sizeof(char));
	unsigned long long* runtime = (unsigned long long *) malloc(runtime_size);
	memset(runtime,0,runtime_size);
    err = hipMalloc((void **)&d_runtime,runtime_size);
    
    if (err != hipSuccess) {
        fprintf(stderr,"Failed to allocated d_runtime (error code %s)!\n",hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    
	/*ADD CODE HERE: Allocate memory on the GPU and copy or set the appropriate values from the HOST*/
    
	
    err = hipMalloc((void **)&d_input,input_length);
    if (err != hipSuccess) {
        fprintf(stderr,"Failed to allocated input (error code %s)!\n",hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }

    err = hipMalloc((void **)&d_pattern,flatindex*sizeof(char));
    if (err != hipSuccess) {
        fprintf(stderr,"Failed to allocated input (error code %s)!\n",hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }

    err = hipMalloc((void **)&d_pattern_length,NUM_PATTERN*sizeof(int));
    if (err != hipSuccess) {
        fprintf(stderr,"Failed to allocated pattern_length[] (error code %s)!\n",hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    
    err = hipMalloc((void **)&d_patHash,NUM_PATTERN*sizeof(int));
    if (err != hipSuccess) {
        fprintf(stderr,"Failed to allocated patHash[] (error code %s)!\n",hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }

    err = hipMalloc((void **)&d_result,(NUM_PATTERN)*sizeof(char));
    if (err != hipSuccess) {
        fprintf(stderr,"Failer to allocate result (error code %s)!\n",hipGetErrorString(err));
    }
    err = hipMemcpy(d_result,result,NUM_PATTERN*sizeof(char),hipMemcpyHostToDevice);
    if (err != hipSuccess) {
        fprintf(stderr,"Failed to copy result (error code %s)!\n",hipGetErrorString(err));
    }
    
    err = hipMemcpy(d_pattern,patternflat,flatindex*sizeof(char),hipMemcpyHostToDevice);
    if (err != hipSuccess) {
        fprintf(stderr,"Failed to copy pattern (error code %s)!\n",hipGetErrorString(err));
    }

    err = hipMemcpy(d_pattern_length,pattern_length,NUM_PATTERN*sizeof(int),hipMemcpyHostToDevice);
    if (err != hipSuccess) {
        fprintf(stderr,"Failed to copy pattern_length[] (error code %s)!\n",hipGetErrorString(err));
    }
    
    err = hipMemcpy(d_patHash,patHash,NUM_PATTERN*sizeof(int),hipMemcpyHostToDevice);
    if (err != hipSuccess) {
        fprintf(stderr,"Failed to copy payHash[] (error code %s)!\n",hipGetErrorString(err));
    }

    err = hipMemcpy(d_input,input,input_length,hipMemcpyHostToDevice);
    if (err != hipSuccess) {
        fprintf(stderr,"Failed to copy input (error code %s)!\n",hipGetErrorString(err));
    }

	/*ADD CODE HERE: Launch the kernel and pass the arguments*/
    int blocks = NUM_PATTERN;
    int threads = input_length;
	findIfExistsCu<<<blocks,threads>>>(d_input,input_length,d_pattern,d_pattern_length,d_patHash,d_result,d_runtime);
    err = hipGetLastError();
    if (err != hipSuccess) {
        fprintf(stderr,"Failed to launch kernel (error code %s)!\n",hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }

    err = hipMemcpy(result,d_result,NUM_PATTERN*sizeof(char),hipMemcpyDeviceToHost);
    if (err != hipSuccess) {
        fprintf(stderr,"Failed to copy back result (error code %s)!\n",hipGetErrorString(err)); 
        exit(EXIT_FAILURE);
    }	
    hipDeviceSynchronize();	
	/*ADD CODE HERE: Copy the execution times from the GPU memory to HOST Code*/		


    hipMemcpy(runtime, d_runtime, runtime_size, hipMemcpyDeviceToHost);
    hipDeviceSynchronize();

    unsigned long long elapsed_time = 0;
    for(int i = 0; i < input_length*NUM_PATTERN; i++)
        if(elapsed_time < runtime[i])
            elapsed_time = runtime[i];

	printf("\nTotal cycles: %d \n", (int)elapsed_time);

    printf("Searching for multiple patterns in the input sequence\n");
    printf("Input string = %s\n",input);
    for (int i = 0;i < NUM_PATTERN;i++) {
        printf("Pattern: \"%s\" %s\n",pattern[i],result[i]?"was found":"was not found");
    }	
	/*ADD CODE HERE: COPY the result and print the result as in the HW description*/
	
	return 0;
}


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

                                        # End of file scope inline assembly
	.globl	_Z29__device_stub__findIfExistsCuPciS_PiS0_S_Py # -- Begin function _Z29__device_stub__findIfExistsCuPciS_PiS0_S_Py
	.type	_Z29__device_stub__findIfExistsCuPciS_PiS0_S_Py,@function
_Z29__device_stub__findIfExistsCuPciS_PiS0_S_Py: # @_Z29__device_stub__findIfExistsCuPciS_PiS0_S_Py
	.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	$160, %rsp
	.cfi_def_cfa_offset 208
	.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	4(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	48(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	32(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	24(%rsp), %r8
	movq	%r9, (%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	208(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%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	$_Z14findIfExistsCuPciS_PiS0_S_Py, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$176, %rsp
	.cfi_adjust_cfa_offset -176
	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	_Z29__device_stub__findIfExistsCuPciS_PiS0_S_Py, .Lfunc_end0-_Z29__device_stub__findIfExistsCuPciS_PiS0_S_Py
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI1_0:
	.byte	83                              # 0x53
	.byte	101                             # 0x65
	.byte	97                              # 0x61
	.byte	114                             # 0x72
	.byte	99                              # 0x63
	.byte	104                             # 0x68
	.byte	105                             # 0x69
	.byte	110                             # 0x6e
	.byte	103                             # 0x67
	.byte	32                              # 0x20
	.byte	102                             # 0x66
	.byte	111                             # 0x6f
	.byte	114                             # 0x72
	.byte	32                              # 0x20
	.byte	109                             # 0x6d
	.byte	117                             # 0x75
.LCPI1_1:
	.byte	108                             # 0x6c
	.byte	116                             # 0x74
	.byte	105                             # 0x69
	.byte	112                             # 0x70
	.byte	108                             # 0x6c
	.byte	101                             # 0x65
	.byte	32                              # 0x20
	.byte	112                             # 0x70
	.byte	97                              # 0x61
	.byte	116                             # 0x74
	.byte	116                             # 0x74
	.byte	101                             # 0x65
	.byte	114                             # 0x72
	.byte	110                             # 0x6e
	.byte	115                             # 0x73
	.byte	32                              # 0x20
.LCPI1_2:
	.byte	105                             # 0x69
	.byte	110                             # 0x6e
	.byte	32                              # 0x20
	.byte	116                             # 0x74
	.byte	104                             # 0x68
	.byte	101                             # 0x65
	.byte	32                              # 0x20
	.byte	105                             # 0x69
	.byte	110                             # 0x6e
	.byte	112                             # 0x70
	.byte	117                             # 0x75
	.byte	116                             # 0x74
	.byte	32                              # 0x20
	.byte	115                             # 0x73
	.byte	101                             # 0x65
	.byte	113                             # 0x71
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$200, %rsp
	.cfi_def_cfa_offset 256
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movaps	.LCPI1_0(%rip), %xmm0           # xmm0 = [83,101,97,114,99,104,105,110,103,32,102,111,114,32,109,117]
	leaq	144(%rsp), %rdi
	movaps	%xmm0, (%rdi)
	movaps	.LCPI1_1(%rip), %xmm0           # xmm0 = [108,116,105,112,108,101,32,112,97,116,116,101,114,110,115,32]
	movaps	%xmm0, 16(%rdi)
	movaps	.LCPI1_2(%rip), %xmm0           # xmm0 = [105,110,32,116,104,101,32,105,110,112,117,116,32,115,101,113]
	movaps	%xmm0, 32(%rdi)
	movl	$1668179317, 48(%rdi)           # imm = 0x636E6575
	movw	$11877, 52(%rdi)                # imm = 0x2E65
	movb	$0, 54(%rdi)
	movq	$.L.str, 80(%rsp)
	movq	$.L.str.1, 88(%rsp)
	movq	$.L.str.2, 96(%rsp)
	movq	$.L.str.3, 104(%rsp)
	callq	strlen
	movq	%rax, %rbx
	xorl	%r14d, %r14d
	xorl	%ebp, %ebp
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	movq	80(%rsp,%r14,8), %rdi
	callq	strlen
	movl	%eax, 112(%rsp,%r14,4)
	addl	%eax, %ebp
	incq	%r14
	cmpq	$4, %r14
	jne	.LBB1_1
# %bb.2:
	movslq	%ebp, %rdi
	callq	malloc
	movq	%rax, %r13
	xorl	%ebp, %ebp
	xorl	%r12d, %r12d
.LBB1_3:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_5 Depth 2
	movslq	%r12d, %rdi
	addq	%r13, %rdi
	movq	80(%rsp,%rbp,8), %r15
	movslq	112(%rsp,%rbp,4), %r14
	movq	%r15, %rsi
	movq	%r14, %rdx
	callq	memcpy@PLT
	testq	%r14, %r14
	jle	.LBB1_6
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB1_3 Depth=1
	movl	%r14d, %eax
	movl	128(%rsp,%rbp,4), %ecx
	xorl	%edx, %edx
.LBB1_5:                                #   Parent Loop BB1_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	shll	$8, %ecx
	movsbl	(%r15,%rdx), %esi
	addl	%ecx, %esi
	movslq	%esi, %rcx
	imulq	$-2089327119, %rcx, %rsi        # imm = 0x837765F1
	shrq	$32, %rsi
	addl	%ecx, %esi
	movl	%esi, %edi
	shrl	$31, %edi
	sarl	$9, %esi
	addl	%edi, %esi
	imull	$997, %esi, %esi                # imm = 0x3E5
	subl	%esi, %ecx
	movl	%ecx, 128(%rsp,%rbp,4)
	incq	%rdx
	cmpq	%rdx, %rax
	jne	.LBB1_5
.LBB1_6:                                # %._crit_edge
                                        #   in Loop: Header=BB1_3 Depth=1
	addl	%r14d, %r12d
	incq	%rbp
	cmpq	$4, %rbp
	jne	.LBB1_3
# %bb.7:
	movl	%ebx, %ebp
	shll	$5, %ebp
	movl	$4, %edi
	callq	malloc
	movq	%rax, %r14
	movl	$0, (%rax)
	movslq	%ebp, %rbp
	movl	$1, %edi
	movq	%rbp, %rsi
	callq	calloc@PLT
	movq	%rax, %r15
	leaq	32(%rsp), %rdi
	movq	%rbp, 72(%rsp)                  # 8-byte Spill
	movq	%rbp, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_8
# %bb.10:
	movslq	%ebx, %rbp
	leaq	64(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_11
# %bb.12:
	movslq	%r12d, %r12
	leaq	56(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_11
# %bb.13:
	leaq	48(%rsp), %rdi
	movl	$16, %esi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_14
# %bb.15:
	leaq	40(%rsp), %rdi
	movl	$16, %esi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_16
# %bb.17:
	leaq	24(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_18
.LBB1_19:
	movq	24(%rsp), %rdi
	movl	$4, %edx
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_20
.LBB1_21:
	movq	56(%rsp), %rdi
	movq	%r13, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_22
.LBB1_23:
	movq	48(%rsp), %rdi
	leaq	112(%rsp), %rsi
	movl	$16, %edx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_24
.LBB1_25:
	movq	40(%rsp), %rdi
	leaq	128(%rsp), %rsi
	movl	$16, %edx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_26
.LBB1_27:
	movq	64(%rsp), %rdi
	leaq	144(%rsp), %rsi
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_28
.LBB1_29:
	movl	%ebx, %edx
	btsq	$32, %rdx
	movabsq	$4294967296, %rdi               # imm = 0x100000000
	orq	$4, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_31
# %bb.30:
	movq	64(%rsp), %rdi
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rcx
	movq	40(%rsp), %r8
	movq	24(%rsp), %r9
	movq	32(%rsp), %rax
	movq	%rax, (%rsp)
	movl	%ebx, %esi
	callq	_Z29__device_stub__findIfExistsCuPciS_PiS0_S_Py
.LBB1_31:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_32
# %bb.33:
	movq	24(%rsp), %rsi
	movl	$4, %edx
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_34
# %bb.35:
	callq	hipDeviceSynchronize
	movq	32(%rsp), %rsi
	movq	%r15, %rdi
	movq	72(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	callq	hipDeviceSynchronize
	testl	%ebx, %ebx
	jle	.LBB1_36
# %bb.40:                               # %.lr.ph129.preheader
	leal	(,%rbx,4), %ecx
	cmpl	$2, %ecx
	movl	$1, %eax
	cmovgel	%ecx, %eax
	xorl	%ecx, %ecx
	xorl	%esi, %esi
.LBB1_41:                               # %.lr.ph129
                                        # =>This Inner Loop Header: Depth=1
	movq	%rsi, %rdx
	movq	(%r15,%rcx,8), %rsi
	cmpq	%rsi, %rdx
	cmovaq	%rdx, %rsi
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB1_41
	jmp	.LBB1_37
.LBB1_36:
	xorl	%esi, %esi
.LBB1_37:                               # %._crit_edge130
	movl	$.L.str.16, %edi
                                        # kill: def $esi killed $esi killed $rsi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr, %edi
	callq	puts@PLT
	leaq	144(%rsp), %rsi
	movl	$.L.str.18, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.21, %ebx
	xorl	%r15d, %r15d
.LBB1_38:                               # =>This Inner Loop Header: Depth=1
	cmpb	$0, (%r14,%r15)
	movq	80(%rsp,%r15,8), %rsi
	movl	$.L.str.20, %edx
	cmoveq	%rbx, %rdx
	movl	$.L.str.19, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r15
	cmpq	$4, %r15
	jne	.LBB1_38
# %bb.39:
	xorl	%eax, %eax
	addq	$200, %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
.LBB1_18:
	.cfi_def_cfa_offset 256
	movq	stderr(%rip), %rcx
	movq	%rcx, 16(%rsp)                  # 8-byte Spill
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	movq	16(%rsp), %rdi                  # 8-byte Reload
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_19
.LBB1_20:
	movq	stderr(%rip), %rcx
	movq	%rcx, 16(%rsp)                  # 8-byte Spill
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.9, %esi
	movq	16(%rsp), %rdi                  # 8-byte Reload
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_21
.LBB1_22:
	movq	stderr(%rip), %r12
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movq	%r12, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_23
.LBB1_24:
	movq	stderr(%rip), %r12
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	movq	%r12, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_25
.LBB1_26:
	movq	stderr(%rip), %r12
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movq	%r12, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_27
.LBB1_28:
	movq	stderr(%rip), %r12
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.13, %esi
	movq	%r12, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_29
.LBB1_11:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %esi
	jmp	.LBB1_9
.LBB1_8:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	jmp	.LBB1_9
.LBB1_14:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.6, %esi
	jmp	.LBB1_9
.LBB1_16:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.7, %esi
	jmp	.LBB1_9
.LBB1_32:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.14, %esi
	jmp	.LBB1_9
.LBB1_34:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.15, %esi
.LBB1_9:
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.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	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14findIfExistsCuPciS_PiS0_S_Py, %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_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z14findIfExistsCuPciS_PiS0_S_Py,@object # @_Z14findIfExistsCuPciS_PiS0_S_Py
	.section	.rodata,"a",@progbits
	.globl	_Z14findIfExistsCuPciS_PiS0_S_Py
	.p2align	3, 0x0
_Z14findIfExistsCuPciS_PiS0_S_Py:
	.quad	_Z29__device_stub__findIfExistsCuPciS_PiS0_S_Py
	.size	_Z14findIfExistsCuPciS_PiS0_S_Py, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"multiple"
	.size	.L.str, 9

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"s i"
	.size	.L.str.1, 4

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"ddd"
	.size	.L.str.2, 4

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Failed to allocated d_runtime (error code %s)!\n"
	.size	.L.str.4, 48

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Failed to allocated input (error code %s)!\n"
	.size	.L.str.5, 44

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Failed to allocated pattern_length[] (error code %s)!\n"
	.size	.L.str.6, 55

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Failed to allocated patHash[] (error code %s)!\n"
	.size	.L.str.7, 48

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Failer to allocate result (error code %s)!\n"
	.size	.L.str.8, 44

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Failed to copy result (error code %s)!\n"
	.size	.L.str.9, 40

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Failed to copy pattern (error code %s)!\n"
	.size	.L.str.10, 41

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Failed to copy pattern_length[] (error code %s)!\n"
	.size	.L.str.11, 50

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Failed to copy payHash[] (error code %s)!\n"
	.size	.L.str.12, 43

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Failed to copy input (error code %s)!\n"
	.size	.L.str.13, 39

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Failed to launch kernel (error code %s)!\n"
	.size	.L.str.14, 42

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"Failed to copy back result (error code %s)!\n"
	.size	.L.str.15, 45

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"\nTotal cycles: %d \n"
	.size	.L.str.16, 20

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"Input string = %s\n"
	.size	.L.str.18, 19

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"Pattern: \"%s\" %s\n"
	.size	.L.str.19, 18

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"was found"
	.size	.L.str.20, 10

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"was not found"
	.size	.L.str.21, 14

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14findIfExistsCuPciS_PiS0_S_Py"
	.size	.L__unnamed_1, 33

	.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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Searching for multiple patterns in the input sequence"
	.size	.Lstr, 54

	.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 _Z29__device_stub__findIfExistsCuPciS_PiS0_S_Py
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z14findIfExistsCuPciS_PiS0_S_Py
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14findIfExistsCuPciS_PiS0_S_Py ; -- Begin function _Z14findIfExistsCuPciS_PiS0_S_Py
	.globl	_Z14findIfExistsCuPciS_PiS0_S_Py
	.p2align	8
	.type	_Z14findIfExistsCuPciS_PiS0_S_Py,@function
_Z14findIfExistsCuPciS_PiS0_S_Py:       ; @_Z14findIfExistsCuPciS_PiS0_S_Py
; %bb.0:
	s_load_b256 s[4:11], s[0:1], 0x10
	s_mov_b32 s12, s15
	s_ashr_i32 s13, s15, 31
	v_mov_b32_e32 v1, 0
	s_lshl_b64 s[18:19], s[12:13], 2
	s_getreg_b32 s20, hwreg(HW_REG_SHADER_CYCLES, 0, 20)
	s_mov_b32 s21, 0
	s_waitcnt lgkmcnt(0)
	s_add_u32 s2, s6, s18
	s_addc_u32 s3, s7, s19
	global_load_b32 v2, v1, s[2:3]
	s_clause 0x1
	s_load_b64 s[16:17], s[0:1], 0x0
	s_load_b64 s[14:15], s[0:1], 0x30
	s_waitcnt vmcnt(0)
	v_cmp_gt_i32_e32 vcc_lo, 1, v2
	s_cbranch_vccnz .LBB0_4
; %bb.1:                                ; %.lr.ph.preheader
	v_dual_mov_b32 v1, 0 :: v_dual_add_nc_u32 v4, v2, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_dual_mov_b32 v3, v1 :: v_dual_mov_b32 v2, v0
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v5, vcc_lo, s16, v2
	v_add_co_ci_u32_e32 v6, vcc_lo, s17, v3, vcc_lo
	v_add_co_u32 v2, vcc_lo, v2, 1
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	global_load_i8 v5, v[5:6], off
	v_cmp_ge_i32_e32 vcc_lo, v2, v4
	s_or_b32 s21, vcc_lo, s21
	s_waitcnt vmcnt(0)
	v_lshl_add_u32 v1, v1, 8, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_i32 v5, 0x837765f1, v1
	v_add_nc_u32_e32 v5, v5, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshrrev_b32_e32 v6, 31, v5
	v_ashrrev_i32_e32 v5, 9, v5
	v_add_nc_u32_e32 v5, v5, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_i32_i24_e32 v5, 0x3e5, v5
	v_sub_nc_u32_e32 v1, v1, v5
	s_and_not1_b32 exec_lo, exec_lo, s21
	s_cbranch_execnz .LBB0_2
; %bb.3:                                ; %Flow108
	s_or_b32 exec_lo, exec_lo, s21
.LBB0_4:                                ; %._crit_edge
	v_mov_b32_e32 v2, 0
	s_add_u32 s8, s8, s18
	s_addc_u32 s9, s9, s19
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	global_load_b32 v2, v2, s[8:9]
	s_mov_b32 s8, exec_lo
	s_waitcnt vmcnt(0)
	v_cmpx_eq_u32_e64 v1, v2
	s_cbranch_execz .LBB0_14
; %bb.5:                                ; %.preheader49
	s_cmp_eq_u32 s12, 0
	s_mov_b32 s9, 0
	s_cbranch_scc1 .LBB0_8
; %bb.6:                                ; %.lr.ph57.preheader
	v_mov_b32_e32 v1, 0
	s_mov_b32 s18, s12
.LBB0_7:                                ; %.lr.ph57
                                        ; =>This Inner Loop Header: Depth=1
	global_load_b32 v2, v1, s[6:7]
	s_add_i32 s18, s18, -1
	s_waitcnt vmcnt(0)
	v_readfirstlane_b32 s19, v2
	s_delay_alu instid0(VALU_DEP_1)
	s_add_i32 s9, s19, s9
	s_add_u32 s6, s6, 4
	s_addc_u32 s7, s7, 0
	s_cmp_eq_u32 s18, 0
	s_cbranch_scc0 .LBB0_7
.LBB0_8:                                ; %.preheader
	v_mov_b32_e32 v1, 0
	global_load_b32 v2, v1, s[2:3]
	s_waitcnt vmcnt(0)
	v_cmp_gt_i32_e32 vcc_lo, 1, v2
	s_cbranch_vccnz .LBB0_12
; %bb.9:                                ; %.lr.ph61
	v_dual_mov_b32 v3, v1 :: v_dual_add_nc_u32 v4, v2, v0
	v_mov_b32_e32 v2, v0
	s_mov_b32 s7, -1
	s_mov_b32 s6, 0
                                        ; implicit-def: $sgpr3
.LBB0_10:                               ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_u32 v5, vcc_lo, s16, v2
	s_ashr_i32 s2, s9, 31
	v_add_co_ci_u32_e32 v6, vcc_lo, s17, v3, vcc_lo
	s_add_u32 s18, s4, s9
	s_addc_u32 s19, s5, s2
	global_load_u8 v7, v1, s[18:19]
	global_load_u8 v5, v[5:6], off
	v_add_co_u32 v2, vcc_lo, v2, 1
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	s_add_i32 s9, s9, 1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_cmp_ge_i32_e64 s2, v2, v4
	s_waitcnt vmcnt(0)
	v_cmp_eq_u16_e32 vcc_lo, v7, v5
	s_and_b32 s7, s7, vcc_lo
	s_or_b32 s6, s2, s6
	s_and_not1_b32 s2, s3, exec_lo
	s_and_b32 s3, s7, exec_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 s3, s2, s3
	s_and_not1_b32 exec_lo, exec_lo, s6
	s_cbranch_execnz .LBB0_10
; %bb.11:                               ; %Flow
	s_or_b32 exec_lo, exec_lo, s6
	s_branch .LBB0_13
.LBB0_12:
	s_mov_b32 s3, -1
.LBB0_13:                               ; %._crit_edge62
	v_mov_b32_e32 v1, 0
	s_add_u32 s4, s10, s12
	s_addc_u32 s5, s11, s13
	v_cndmask_b32_e64 v3, 0, 1, s3
	global_load_u8 v2, v1, s[4:5]
	s_waitcnt vmcnt(0)
	v_or_b32_e32 v2, v2, v3
	global_store_b8 v1, v2, s[4:5]
.LBB0_14:                               ; %Flow107
	s_or_b32 exec_lo, exec_lo, s8
	s_load_b32 s0, s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	v_mad_u64_u32 v[1:2], null, s12, s0, v[0:1]
	s_getreg_b32 s0, hwreg(HW_REG_SHADER_CYCLES, 0, 20)
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	s_sub_u32 s0, s0, s20
	s_subb_u32 s1, 0, 0
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[0:1], 3, v[1:2]
	v_dual_mov_b32 v3, s1 :: v_dual_mov_b32 v2, s0
	v_add_co_u32 v0, vcc_lo, s14, v0
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v1, vcc_lo, s15, v1, vcc_lo
	global_store_b64 v[0:1], v[2:3], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14findIfExistsCuPciS_PiS0_S_Py
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 56
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 8
		.amdhsa_next_free_sgpr 22
		.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	_Z14findIfExistsCuPciS_PiS0_S_Py, .Lfunc_end0-_Z14findIfExistsCuPciS_PiS0_S_Py
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 660
; NumSgprs: 24
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 24
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         40
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         48
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 56
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14findIfExistsCuPciS_PiS0_S_Py
    .private_segment_fixed_size: 0
    .sgpr_count:     24
    .sgpr_spill_count: 0
    .symbol:         _Z14findIfExistsCuPciS_PiS0_S_Py.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
