/**
 *  Writed By: Huaxia Wang
 *  hwang122@hawk.iit.edu
 **/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define CHECK_ERR(x)                                            \
    if (x != cudaSuccess) {                                     \
        fprintf(stderr, "%s in %s at line %d\n",                \
                cudaGetErrorString(err), __FILE__, __LINE__);   \
        exit(-1);                                               \
    }                                                           \

#define FILE_LINE 5120000
#define LINE_WIDTH 128

//device function, used to locate the searching word in a sentence
__device__ char *d_strstr(const char *str1, const char *str2, int width)
{
    char *cp = (char *)str1;
    char *s1, *s2;
	
	//if searching word is empty, return the sentence
    if(!*str2)
        return ((char*)str1);

    int i = 0;
	//keep searching until return the end of sentence
    while(i < width)
    {
        s1 = cp;
        s2 = (char *)str2;

        while(*s1 && *s2 && !(*s1 - *s2))
            s1++, s2++;

        if(!*s2)
            return cp;
        cp++;
        i++;
    }

    return NULL;
}

//device memcpy, used to copy certain length memory from source to destination
__device__ char *d_memcpy(char *dest, char *src, int count)
{
    char *result = dest;
	
	//check whether there is a memory overlap
    if(dest <= src || dest >= (src + count))
    {
        while(count--)
            *(char *)dest++ = *(char *)src++;
    }
    else
    {
        dest += count - 1;
        src += count - 1;

        while(count--)
            *(char *)dest-- = *(char *)src--;
    }

    return result;
}

//callable function in CPU, which fulfill the grep function
__global__ void d_Grep(char *d_File, char *d_regex, char *result, int line, int width){
    int i = blockDim.x * blockIdx.x + threadIdx.x;
    char *pch;
    if(i < line)
    {
        pch = d_strstr(&d_File[i*width], d_regex, width);
        if(pch != NULL)
            d_memcpy(&result[i*width], &d_File[i*width], sizeof(char)*width);
    }
}

int main(int argc, char* argv[])
{
    cudaError_t err;
	
	//get arguments from command line
    char *Filename = argv[1];
	char *Regexp = argv[2];
    if(Regexp==NULL||Filename==NULL){
        printf("Usage: #./program [file name] [searching words]");
        return -1;
    }
	//open file
    FILE *f;
    f = fopen(Filename, "r");
    if(f == NULL)
    {
        printf("Fail to open file!\n");
        return -1;
    }

    char **file;
    char *result;
    int i;
	//store file and searching results
    file = (char **)malloc(sizeof(char*)*FILE_LINE);
    result = (char *)malloc(sizeof(char)*FILE_LINE*LINE_WIDTH);
	
    //keep the continuity of memory
    file[0] = (char *)malloc(sizeof(char)*FILE_LINE*LINE_WIDTH);
    for(i = 1; i < FILE_LINE; i++)
        file[i] = file[i-1] + LINE_WIDTH;

	//get file contents
    for(i = 0; i < FILE_LINE; i++)
    {
        fgets(file[i], LINE_WIDTH, f);
    }
	
	//allocate memory in GPU, and copy data to it
    char *d_file, *d_regex, *d_result;
    err = cudaMalloc((void**) &d_file, sizeof(char)*FILE_LINE*LINE_WIDTH);
    CHECK_ERR(err);

    err = cudaMalloc((void**) &d_regex, strlen(Regexp));
    CHECK_ERR(err);

    err = cudaMalloc((void**) &d_result, sizeof(char)*FILE_LINE*LINE_WIDTH);
    CHECK_ERR(err);
	
	err = cudaMemset(d_result, 0, sizeof(char)*FILE_LINE*LINE_WIDTH);
	CHECK_ERR(err);

    err = cudaMemcpy(d_file, &file[0][0], sizeof(char)*FILE_LINE*LINE_WIDTH, cudaMemcpyHostToDevice);
    CHECK_ERR(err);

    err = cudaMemcpy(d_regex, Regexp,  strlen(Regexp), cudaMemcpyHostToDevice);
    CHECK_ERR(err);

	//set number of threads in a block
    int numThread = 512;
    int numBlock = ceil((double)FILE_LINE/numThread);
    d_Grep<<<numBlock, numThread>>>(d_file, d_regex, d_result, FILE_LINE, LINE_WIDTH);
	
	cudaDeviceSynchronize();

    err = cudaMemcpy(result, d_result, sizeof(char)*FILE_LINE*LINE_WIDTH, cudaMemcpyDeviceToHost);
    CHECK_ERR(err);
	
	//free all the GPU memory
	err = cudaFree(d_file);
	CHECK_ERR(err);
	
	err = cudaFree(d_regex);
	CHECK_ERR(err);
	
	err = cudaFree(d_result);
	CHECK_ERR(err);

	//print the results
    for(i = 0; i < FILE_LINE; i++)
    {
        if(&result[i*LINE_WIDTH] != NULL)
            printf("%s", &result[i*LINE_WIDTH]);
    }

	free(file);
	free(result);
	
    return 0;
}

	.file	"tmpxft_0039a86c_00000000-6_cuda_grep.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z8d_strstrPKcS0_i
	.type	_Z8d_strstrPKcS0_i, @function
_Z8d_strstrPKcS0_i:
.LFB2027:
	.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
.LFE2027:
	.size	_Z8d_strstrPKcS0_i, .-_Z8d_strstrPKcS0_i
	.globl	_Z8d_memcpyPcS_i
	.type	_Z8d_memcpyPcS_i, @function
_Z8d_memcpyPcS_i:
.LFB2174:
	.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
.LFE2174:
	.size	_Z8d_memcpyPcS_i, .-_Z8d_memcpyPcS_i
	.globl	_Z31__device_stub__Z6d_GrepPcS_S_iiPcS_S_ii
	.type	_Z31__device_stub__Z6d_GrepPcS_S_iiPcS_S_ii, @function
_Z31__device_stub__Z6d_GrepPcS_S_iiPcS_S_ii:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L6
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z6d_GrepPcS_S_ii(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L6:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z31__device_stub__Z6d_GrepPcS_S_iiPcS_S_ii, .-_Z31__device_stub__Z6d_GrepPcS_S_iiPcS_S_ii
	.globl	_Z6d_GrepPcS_S_ii
	.type	_Z6d_GrepPcS_S_ii, @function
_Z6d_GrepPcS_S_ii:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z6d_GrepPcS_S_iiPcS_S_ii
	.cfi_endproc
.LFE2055:
	.size	_Z6d_GrepPcS_S_ii, .-_Z6d_GrepPcS_S_ii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Usage: #./program [file name] [searching words]"
.LC1:
	.string	"r"
.LC2:
	.string	"Fail to open file!\n"
.LC3:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/hwang122/CUDA/master/cuda_grep.cu"
.LC4:
	.string	"%s in %s at line %d\n"
.LC5:
	.string	"%s"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	movq	16(%rsi), %r12
	movq	8(%rsi), %rdi
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	testq	%r12, %r12
	je	.L34
	testq	%rdi, %rdi
	jne	.L13
.L34:
	leaq	.LC0(%rip), %rsi
	jmp	.L43
.L13:
	leaq	.LC1(%rip), %rsi
	call	fopen@PLT
	movq	%rax, %r14
	testq	%rax, %rax
	jne	.L16
	leaq	.LC2(%rip), %rsi
.L43:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	orl	$-1, %eax
	jmp	.L12
.L16:
	movl	$40960000, %edi
	call	malloc@PLT
	movl	$655360000, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	movl	$655360000, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movq	%rax, (%rbx)
	xorl	%eax, %eax
.L18:
	movq	(%rbx,%rax), %rcx
	leaq	128(%rcx), %rdx
	movq	%rdx, 8(%rbx,%rax)
	addq	$8, %rax
	cmpq	$40959992, %rax
	jne	.L18
	xorl	%r13d, %r13d
.L19:
	movq	(%rbx,%r13,8), %rdi
	movq	%r14, %rcx
	movl	$128, %edx
	orq	$-1, %rsi
	incq	%r13
	call	__fgets_chk@PLT
	cmpq	$5120000, %r13
	jne	.L19
	leaq	8(%rsp), %rdi
	movl	$655360000, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L20
	call	cudaGetErrorString@PLT
	movl	$125, %r9d
	movq	%rax, %rcx
	jmp	.L44
.L20:
	movq	%r12, %rdi
	call	strlen@PLT
	leaq	16(%rsp), %rdi
	movq	%rax, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L21
	call	cudaGetErrorString@PLT
	movl	$128, %r9d
	movq	%rax, %rcx
.L44:
	movq	stderr(%rip), %rdi
	leaq	.LC3(%rip), %r8
	leaq	.LC4(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L21:
	leaq	24(%rsp), %rdi
	movl	$655360000, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L22
	call	cudaGetErrorString@PLT
	movl	$131, %r9d
	movq	%rax, %rcx
	jmp	.L44
.L22:
	movq	24(%rsp), %rdi
	movl	$655360000, %edx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L23
	call	cudaGetErrorString@PLT
	movl	$134, %r9d
	movq	%rax, %rcx
	jmp	.L44
.L23:
	movq	8(%rsp), %rdi
	movq	(%rbx), %rsi
	movl	$1, %ecx
	movl	$655360000, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L24
	call	cudaGetErrorString@PLT
	movl	$137, %r9d
	movq	%rax, %rcx
	jmp	.L44
.L24:
	movq	%r12, %rdi
	call	strlen@PLT
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	movq	%rax, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L25
	call	cudaGetErrorString@PLT
	movl	$140, %r9d
	movq	%rax, %rcx
	jmp	.L44
.L25:
	movl	$8388609, %edx
	movl	$268436081, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$9, %rdx
	salq	$4, %rdi
	movl	$1, %ecx
	movl	$1, %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L26
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	$5120000, %ecx
	movl	$128, %r8d
	movq	8(%rsp), %rdi
	call	_Z31__device_stub__Z6d_GrepPcS_S_iiPcS_S_ii
.L26:
	call	cudaDeviceSynchronize@PLT
	movq	24(%rsp), %rsi
	movq	%rbp, %rdi
	movl	$2, %ecx
	movl	$655360000, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L27
	call	cudaGetErrorString@PLT
	movl	$150, %r9d
	movq	%rax, %rcx
	jmp	.L44
.L27:
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L28
	call	cudaGetErrorString@PLT
	movl	$154, %r9d
	movq	%rax, %rcx
	jmp	.L44
.L28:
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L29
	call	cudaGetErrorString@PLT
	movl	$157, %r9d
	movq	%rax, %rcx
	jmp	.L44
.L29:
	movq	24(%rsp), %rdi
	movq	%rbp, %r12
	leaq	655360000(%rbp), %r13
	leaq	.LC5(%rip), %r14
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L32
	call	cudaGetErrorString@PLT
	movl	$160, %r9d
	movq	%rax, %rcx
	jmp	.L44
.L32:
	testq	%r12, %r12
	je	.L31
	movq	%r12, %rdx
	movq	%r14, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L31:
	subq	$-128, %r12
	cmpq	%r13, %r12
	jne	.L32
	movq	%rbx, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	xorl	%eax, %eax
.L12:
	movq	56(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	addq	$64, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC6:
	.string	"_Z6d_GrepPcS_S_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.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	.LC6(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z6d_GrepPcS_S_ii(%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
.LFE2057:
	.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:

/**
 *  Writed By: Huaxia Wang
 *  hwang122@hawk.iit.edu
 **/


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define CHECK_ERR(x)                                            \
    if (x != hipSuccess) {                                     \
        fprintf(stderr, "%s in %s at line %d\n",                \
                hipGetErrorString(err), __FILE__, __LINE__);   \
        exit(-1);                                               \
    }                                                           \

#define FILE_LINE 5120000
#define LINE_WIDTH 128

//device function, used to locate the searching word in a sentence
__device__ char *d_strstr(const char *str1, const char *str2, int width)
{
    char *cp = (char *)str1;
    char *s1, *s2;
	
	//if searching word is empty, return the sentence
    if(!*str2)
        return ((char*)str1);

    int i = 0;
	//keep searching until return the end of sentence
    while(i < width)
    {
        s1 = cp;
        s2 = (char *)str2;

        while(*s1 && *s2 && !(*s1 - *s2))
            s1++, s2++;

        if(!*s2)
            return cp;
        cp++;
        i++;
    }

    return NULL;
}

//device memcpy, used to copy certain length memory from source to destination
__device__ char *d_memcpy(char *dest, char *src, int count)
{
    char *result = dest;
	
	//check whether there is a memory overlap
    if(dest <= src || dest >= (src + count))
    {
        while(count--)
            *(char *)dest++ = *(char *)src++;
    }
    else
    {
        dest += count - 1;
        src += count - 1;

        while(count--)
            *(char *)dest-- = *(char *)src--;
    }

    return result;
}

//callable function in CPU, which fulfill the grep function
__global__ void d_Grep(char *d_File, char *d_regex, char *result, int line, int width){
    int i = blockDim.x * blockIdx.x + threadIdx.x;
    char *pch;
    if(i < line)
    {
        pch = d_strstr(&d_File[i*width], d_regex, width);
        if(pch != NULL)
            d_memcpy(&result[i*width], &d_File[i*width], sizeof(char)*width);
    }
}

int main(int argc, char* argv[])
{
    hipError_t err;
	
	//get arguments from command line
    char *Filename = argv[1];
	char *Regexp = argv[2];
    if(Regexp==NULL||Filename==NULL){
        printf("Usage: #./program [file name] [searching words]");
        return -1;
    }
	//open file
    FILE *f;
    f = fopen(Filename, "r");
    if(f == NULL)
    {
        printf("Fail to open file!\n");
        return -1;
    }

    char **file;
    char *result;
    int i;
	//store file and searching results
    file = (char **)malloc(sizeof(char*)*FILE_LINE);
    result = (char *)malloc(sizeof(char)*FILE_LINE*LINE_WIDTH);
	
    //keep the continuity of memory
    file[0] = (char *)malloc(sizeof(char)*FILE_LINE*LINE_WIDTH);
    for(i = 1; i < FILE_LINE; i++)
        file[i] = file[i-1] + LINE_WIDTH;

	//get file contents
    for(i = 0; i < FILE_LINE; i++)
    {
        fgets(file[i], LINE_WIDTH, f);
    }
	
	//allocate memory in GPU, and copy data to it
    char *d_file, *d_regex, *d_result;
    err = hipMalloc((void**) &d_file, sizeof(char)*FILE_LINE*LINE_WIDTH);
    CHECK_ERR(err);

    err = hipMalloc((void**) &d_regex, strlen(Regexp));
    CHECK_ERR(err);

    err = hipMalloc((void**) &d_result, sizeof(char)*FILE_LINE*LINE_WIDTH);
    CHECK_ERR(err);
	
	err = hipMemset(d_result, 0, sizeof(char)*FILE_LINE*LINE_WIDTH);
	CHECK_ERR(err);

    err = hipMemcpy(d_file, &file[0][0], sizeof(char)*FILE_LINE*LINE_WIDTH, hipMemcpyHostToDevice);
    CHECK_ERR(err);

    err = hipMemcpy(d_regex, Regexp,  strlen(Regexp), hipMemcpyHostToDevice);
    CHECK_ERR(err);

	//set number of threads in a block
    int numThread = 512;
    int numBlock = ceil((double)FILE_LINE/numThread);
    d_Grep<<<numBlock, numThread>>>(d_file, d_regex, d_result, FILE_LINE, LINE_WIDTH);
	
	hipDeviceSynchronize();

    err = hipMemcpy(result, d_result, sizeof(char)*FILE_LINE*LINE_WIDTH, hipMemcpyDeviceToHost);
    CHECK_ERR(err);
	
	//free all the GPU memory
	err = hipFree(d_file);
	CHECK_ERR(err);
	
	err = hipFree(d_regex);
	CHECK_ERR(err);
	
	err = hipFree(d_result);
	CHECK_ERR(err);

	//print the results
    for(i = 0; i < FILE_LINE; i++)
    {
        if(&result[i*LINE_WIDTH] != NULL)
            printf("%s", &result[i*LINE_WIDTH]);
    }

	free(file);
	free(result);
	
    return 0;
}

	.text
	.file	"cuda_grep.hip"
	.globl	_Z21__device_stub__d_GrepPcS_S_ii # -- Begin function _Z21__device_stub__d_GrepPcS_S_ii
	.type	_Z21__device_stub__d_GrepPcS_S_ii,@function
_Z21__device_stub__d_GrepPcS_S_ii:      # @_Z21__device_stub__d_GrepPcS_S_ii
	.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	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	movq	%rsp, %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z6d_GrepPcS_S_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	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__d_GrepPcS_S_ii, .Lfunc_end0-_Z21__device_stub__d_GrepPcS_S_ii
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	16(%rsi), %r15
	testq	%r15, %r15
	je	.LBB1_24
# %bb.1:
	movq	8(%rsi), %rdi
	testq	%rdi, %rdi
	je	.LBB1_24
# %bb.2:
	movl	$.L.str.1, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_25
# %bb.3:
	movq	%rax, %r12
	movl	$40960000, %edi                 # imm = 0x2710000
	callq	malloc
	movq	%rax, %rbx
	movl	$655360000, %edi                # imm = 0x27100000
	callq	malloc
	movq	%rax, %r14
	movl	$655360000, %edi                # imm = 0x27100000
	callq	malloc
	movq	%rax, (%rbx)
	subq	$-128, %rax
	movl	$1, %ecx
.LBB1_4:                                # =>This Inner Loop Header: Depth=1
	movq	%rax, (%rbx,%rcx,8)
	incq	%rcx
	subq	$-128, %rax
	cmpq	$5120000, %rcx                  # imm = 0x4E2000
	jne	.LBB1_4
# %bb.5:                                # %.preheader87.preheader
	xorl	%r13d, %r13d
.LBB1_6:                                # %.preheader87
                                        # =>This Inner Loop Header: Depth=1
	movq	(%rbx,%r13,8), %rdi
	movl	$128, %esi
	movq	%r12, %rdx
	callq	fgets
	incq	%r13
	cmpq	$5120000, %r13                  # imm = 0x4E2000
	jne	.LBB1_6
# %bb.7:
	leaq	24(%rsp), %rdi
	movl	$655360000, %esi                # imm = 0x27100000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_28
# %bb.8:
	movq	%r15, %rdi
	callq	strlen
	leaq	16(%rsp), %rdi
	movq	%rax, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_29
# %bb.9:
	leaq	8(%rsp), %rdi
	movl	$655360000, %esi                # imm = 0x27100000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_30
# %bb.10:
	movq	8(%rsp), %rdi
	movl	$655360000, %edx                # imm = 0x27100000
	xorl	%esi, %esi
	callq	hipMemset
	testl	%eax, %eax
	jne	.LBB1_31
# %bb.11:
	movq	24(%rsp), %rdi
	movq	(%rbx), %rsi
	movl	$655360000, %edx                # imm = 0x27100000
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_32
# %bb.12:
	movq	16(%rsp), %r12
	movq	%r15, %rdi
	callq	strlen
	movq	%r12, %rdi
	movq	%r15, %rsi
	movq	%rax, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_33
# %bb.13:
	movabsq	$4294967808, %rdx               # imm = 0x100000200
	leaq	9488(%rdx), %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_15
# %bb.14:
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	movl	$5120000, %ecx                  # imm = 0x4E2000
	movl	$128, %r8d
	callq	_Z21__device_stub__d_GrepPcS_S_ii
.LBB1_15:
	callq	hipDeviceSynchronize
	movq	8(%rsp), %rsi
	movl	$655360000, %edx                # imm = 0x27100000
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_34
# %bb.16:
	movq	24(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_35
# %bb.17:
	movq	16(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_36
# %bb.18:
	movq	8(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_37
# %bb.19:                               # %.preheader
	xorl	%r15d, %r15d
.LBB1_20:                               # =>This Inner Loop Header: Depth=1
	testq	%r14, %r14
	je	.LBB1_22
# %bb.21:                               #   in Loop: Header=BB1_20 Depth=1
	leaq	(%r14,%r15), %rsi
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
.LBB1_22:                               #   in Loop: Header=BB1_20 Depth=1
	subq	$-128, %r15
	cmpq	$655360000, %r15                # imm = 0x27100000
	jne	.LBB1_20
# %bb.23:
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	xorl	%eax, %eax
	jmp	.LBB1_27
.LBB1_24:
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_26
.LBB1_25:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB1_26:
	movl	$-1, %eax
.LBB1_27:
	addq	$32, %rsp
	.cfi_def_cfa_offset 48
	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
.LBB1_28:
	.cfi_def_cfa_offset 80
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	movl	$.L.str.4, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$127, %r8d
	jmp	.LBB1_38
.LBB1_29:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	movl	$.L.str.4, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$130, %r8d
	jmp	.LBB1_38
.LBB1_30:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	movl	$.L.str.4, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$133, %r8d
	jmp	.LBB1_38
.LBB1_31:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	movl	$.L.str.4, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$136, %r8d
	jmp	.LBB1_38
.LBB1_32:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	movl	$.L.str.4, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$139, %r8d
	jmp	.LBB1_38
.LBB1_33:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	movl	$.L.str.4, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$142, %r8d
	jmp	.LBB1_38
.LBB1_34:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	movl	$.L.str.4, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$152, %r8d
	jmp	.LBB1_38
.LBB1_35:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	movl	$.L.str.4, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$156, %r8d
	jmp	.LBB1_38
.LBB1_36:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	movl	$.L.str.4, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$159, %r8d
	jmp	.LBB1_38
.LBB1_37:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	movl	$.L.str.4, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$162, %r8d
.LBB1_38:
	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	$_Z6d_GrepPcS_S_ii, %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	_Z6d_GrepPcS_S_ii,@object       # @_Z6d_GrepPcS_S_ii
	.section	.rodata,"a",@progbits
	.globl	_Z6d_GrepPcS_S_ii
	.p2align	3, 0x0
_Z6d_GrepPcS_S_ii:
	.quad	_Z21__device_stub__d_GrepPcS_S_ii
	.size	_Z6d_GrepPcS_S_ii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Usage: #./program [file name] [searching words]"
	.size	.L.str, 48

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"r"
	.size	.L.str.1, 2

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%s in %s at line %d\n"
	.size	.L.str.3, 21

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/hwang122/CUDA/master/cuda_grep.hip"
	.size	.L.str.4, 97

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%s"
	.size	.L.str.5, 3

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6d_GrepPcS_S_ii"
	.size	.L__unnamed_1, 18

	.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	"Fail to open file!"
	.size	.Lstr, 19

	.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__d_GrepPcS_S_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z6d_GrepPcS_S_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6d_GrepPcS_S_ii       ; -- Begin function _Z6d_GrepPcS_S_ii
	.globl	_Z6d_GrepPcS_S_ii
	.p2align	8
	.type	_Z6d_GrepPcS_S_ii,@function
_Z6d_GrepPcS_S_ii:                      ; @_Z6d_GrepPcS_S_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x2c
	s_load_b64 s[2:3], s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_cmp_gt_i32_e32 vcc_lo, s2, v1
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB0_32
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_mov_b32_e32 v0, 0
	v_mul_lo_u32 v8, v1, s3
	s_delay_alu instid0(VALU_DEP_1)
	v_ashrrev_i32_e32 v9, 31, v8
	s_waitcnt lgkmcnt(0)
	global_load_u8 v0, v0, s[6:7]
	s_waitcnt vmcnt(0)
	v_cmp_eq_u16_e32 vcc_lo, 0, v0
	v_add_co_u32 v0, s2, s4, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v1, s2, s5, v9, s2
	v_dual_mov_b32 v7, v1 :: v_dual_mov_b32 v6, v0
	s_cbranch_vccnz .LBB0_19
; %bb.2:                                ; %.preheader27.i
	s_cmp_lt_i32 s3, 1
	s_cbranch_scc1 .LBB0_18
; %bb.3:                                ; %.preheader.i.preheader
	v_dual_mov_b32 v10, 0 :: v_dual_mov_b32 v5, v1
	v_mov_b32_e32 v4, v0
	s_mov_b32 s2, 0
	s_mov_b32 s13, 0
                                        ; implicit-def: $sgpr12
                                        ; implicit-def: $sgpr14
.LBB0_4:                                ; %.preheader.i
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_6 Depth 2
	global_load_u8 v11, v[4:5], off
	v_dual_mov_b32 v2, v4 :: v_dual_mov_b32 v3, v5
	v_dual_mov_b32 v4, s6 :: v_dual_mov_b32 v5, s7
	s_mov_b32 s15, exec_lo
	s_waitcnt vmcnt(0)
	v_cmpx_ne_u16_e32 0, v11
	s_cbranch_execz .LBB0_12
; %bb.5:                                ; %.lr.ph.i.preheader
                                        ;   in Loop: Header=BB0_4 Depth=1
	s_mov_b64 s[8:9], 0
	s_mov_b32 s16, 0
                                        ; implicit-def: $sgpr17
                                        ; implicit-def: $sgpr19
                                        ; implicit-def: $sgpr18
.LBB0_6:                                ; %.lr.ph.i
                                        ;   Parent Loop BB0_4 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_add_u32 s10, s6, s8
	s_addc_u32 s11, s7, s9
	v_and_b32_e32 v5, 0xff, v11
	global_load_u8 v4, v10, s[10:11]
	s_or_b32 s18, s18, exec_lo
	s_or_b32 s19, s19, exec_lo
	s_mov_b32 s20, exec_lo
                                        ; implicit-def: $vgpr11
	s_waitcnt vmcnt(0)
	v_cmpx_eq_u16_e64 v5, v4
	s_cbranch_execz .LBB0_8
; %bb.7:                                ;   in Loop: Header=BB0_6 Depth=2
	v_add_co_u32 v4, vcc_lo, v2, s8
	v_add_co_ci_u32_e32 v5, vcc_lo, s9, v3, vcc_lo
	s_add_u32 s8, s8, 1
	s_addc_u32 s9, s9, 0
	s_and_not1_b32 s19, s19, exec_lo
	global_load_u8 v11, v[4:5], off offset:1
	s_and_not1_b32 s18, s18, exec_lo
	s_waitcnt vmcnt(0)
	v_cmp_eq_u16_e32 vcc_lo, 0, v11
	s_and_b32 s21, vcc_lo, exec_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 s19, s19, s21
.LBB0_8:                                ; %Flow81
                                        ;   in Loop: Header=BB0_6 Depth=2
	s_or_b32 exec_lo, exec_lo, s20
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 s20, exec_lo, s19
	v_dual_mov_b32 v6, s8 :: v_dual_mov_b32 v7, s9
	s_or_b32 s16, s20, s16
	v_dual_mov_b32 v4, s10 :: v_dual_mov_b32 v5, s11
	s_and_not1_b32 s10, s17, exec_lo
	s_and_b32 s11, s18, exec_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 s17, s10, s11
	s_and_not1_b32 exec_lo, exec_lo, s16
	s_cbranch_execnz .LBB0_6
; %bb.9:                                ; %loop.exit.guard71
                                        ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s16
	s_xor_b32 s8, s17, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_saveexec_b32 s9, s8
	s_xor_b32 s8, exec_lo, s9
; %bb.10:                               ; %.critedge.i.loopexitsplit
                                        ;   in Loop: Header=BB0_4 Depth=1
	v_add_co_u32 v4, vcc_lo, s6, v6
	v_add_co_ci_u32_e32 v5, vcc_lo, s7, v7, vcc_lo
; %bb.11:                               ; %Flow80
                                        ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s8
.LBB0_12:                               ; %Flow82
                                        ;   in Loop: Header=BB0_4 Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 exec_lo, exec_lo, s15
	global_load_u8 v4, v[4:5], off
	s_mov_b32 s11, -1
	s_or_b32 s14, s14, exec_lo
                                        ; implicit-def: $sgpr8_sgpr9
	s_waitcnt vmcnt(0)
	v_cmp_ne_u16_e32 vcc_lo, 0, v4
                                        ; implicit-def: $vgpr4_vgpr5
	s_and_saveexec_b32 s10, vcc_lo
; %bb.13:                               ;   in Loop: Header=BB0_4 Depth=1
	s_add_i32 s13, s13, 1
	v_add_co_u32 v4, vcc_lo, v2, 1
	s_cmp_eq_u32 s13, s3
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v3, vcc_lo
	s_cselect_b32 s11, -1, 0
	s_mov_b64 s[8:9], 0
	s_and_not1_b32 s14, s14, exec_lo
	s_or_not1_b32 s11, s11, exec_lo
; %bb.14:                               ; %Flow83
                                        ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_4) | instid1(SALU_CYCLE_1)
	s_and_b32 s10, exec_lo, s11
	v_dual_mov_b32 v6, s8 :: v_dual_mov_b32 v7, s9
	s_or_b32 s2, s10, s2
	s_and_not1_b32 s8, s12, exec_lo
	s_and_b32 s9, s14, exec_lo
	s_or_b32 s12, s8, s9
	s_and_not1_b32 exec_lo, exec_lo, s2
	s_cbranch_execnz .LBB0_4
; %bb.15:                               ; %loop.exit.guard
	s_or_b32 exec_lo, exec_lo, s2
	s_and_saveexec_b32 s2, s12
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s2, exec_lo, s2
; %bb.16:                               ; %_Z8d_strstrPKcS0_i.exit.loopexit.split.loop.exit21
	v_dual_mov_b32 v7, v3 :: v_dual_mov_b32 v6, v2
; %bb.17:                               ; %Flow79
	s_or_b32 exec_lo, exec_lo, s2
	s_branch .LBB0_19
.LBB0_18:
	v_mov_b32_e32 v6, 0
	v_mov_b32_e32 v7, 0
.LBB0_19:                               ; %_Z8d_strstrPKcS0_i.exit
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u64_e32 vcc_lo, 0, v[6:7]
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_32
; %bb.20:
	s_load_b64 s[0:1], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	v_cmp_le_u64_e64 s5, s[0:1], s[4:5]
	v_add_co_u32 v2, vcc_lo, s0, v8
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v9, vcc_lo
	s_delay_alu instid0(VALU_DEP_3)
	s_and_b32 vcc_lo, exec_lo, s5
	s_cbranch_vccnz .LBB0_22
; %bb.21:
	s_mov_b32 s0, s3
	s_ashr_i32 s1, s3, 31
	v_add_co_u32 v4, vcc_lo, v0, s0
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v1, vcc_lo
	s_and_not1_b32 s4, s5, exec_lo
	s_mov_b32 s2, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_le_u64_e32 vcc_lo, v[4:5], v[2:3]
	s_and_b32 s5, vcc_lo, exec_lo
	s_or_b32 s5, s4, s5
	s_branch .LBB0_23
.LBB0_22:
	s_mov_b32 s2, 0
                                        ; implicit-def: $vgpr4_vgpr5
                                        ; implicit-def: $sgpr0_sgpr1
.LBB0_23:                               ; %Flow75
	s_and_saveexec_b32 s4, s5
	s_cbranch_execz .LBB0_28
; %bb.24:
	s_cmp_eq_u32 s3, 0
	s_cbranch_scc1 .LBB0_27
; %bb.25:
	v_dual_mov_b32 v7, v3 :: v_dual_mov_b32 v6, v2
	s_mov_b32 s5, s3
.LBB0_26:                               ; %.lr.ph.i18
                                        ; =>This Inner Loop Header: Depth=1
	global_load_u8 v10, v[0:1], off
	v_add_co_u32 v0, vcc_lo, v0, 1
	v_add_co_ci_u32_e32 v1, vcc_lo, 0, v1, vcc_lo
	v_add_co_u32 v8, vcc_lo, v6, 1
	v_add_co_ci_u32_e32 v9, vcc_lo, 0, v7, vcc_lo
	s_add_i32 s5, s5, -1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s5, 0
	s_waitcnt vmcnt(0)
	global_store_b8 v[6:7], v10, off
	v_dual_mov_b32 v6, v8 :: v_dual_mov_b32 v7, v9
	s_cbranch_scc0 .LBB0_26
.LBB0_27:                               ; %Flow72
	s_and_not1_b32 s2, s2, exec_lo
.LBB0_28:                               ; %Flow76
	s_or_b32 exec_lo, exec_lo, s4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 exec_lo, exec_lo, s2
	s_cbranch_execz .LBB0_32
; %bb.29:
	s_cmp_eq_u32 s3, 0
	s_cbranch_scc1 .LBB0_32
; %bb.30:                               ; %.lr.ph34.preheader.i
	v_add_co_u32 v0, vcc_lo, v2, s0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v3, vcc_lo
	v_add_co_u32 v2, vcc_lo, v4, -1
	v_add_co_ci_u32_e32 v3, vcc_lo, -1, v5, vcc_lo
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v0, vcc_lo, v0, -1
	v_add_co_ci_u32_e32 v1, vcc_lo, -1, v1, vcc_lo
.LBB0_31:                               ; %.lr.ph34.i
                                        ; =>This Inner Loop Header: Depth=1
	global_load_u8 v6, v[2:3], off
	v_add_co_u32 v2, vcc_lo, v2, -1
	v_add_co_ci_u32_e32 v3, vcc_lo, -1, v3, vcc_lo
	v_add_co_u32 v4, vcc_lo, v0, -1
	v_add_co_ci_u32_e32 v5, vcc_lo, -1, v1, vcc_lo
	s_add_i32 s3, s3, -1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s3, 0
	s_waitcnt vmcnt(0)
	global_store_b8 v[0:1], v6, off
	v_dual_mov_b32 v0, v4 :: v_dual_mov_b32 v1, v5
	s_cbranch_scc0 .LBB0_31
.LBB0_32:                               ; %_Z8d_memcpyPcS_i.exit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6d_GrepPcS_S_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 12
		.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	_Z6d_GrepPcS_S_ii, .Lfunc_end0-_Z6d_GrepPcS_S_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 924
; NumSgprs: 24
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 24
; NumVGPRsForWavesPerEU: 12
; 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
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6d_GrepPcS_S_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     24
    .sgpr_spill_count: 0
    .symbol:         _Z6d_GrepPcS_S_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     12
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
