#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include <time.h>

#define SRC_LINES 10000 // 40
#define CMP_LINES 1000 // 4
#define LINE_MAXLEN 13000 // 100
#define BLOCK_SIZE 1000 // 4


/* Print error message and exit with error status. If PERR is not 0,
    display current errno status. */
static void
error_print (int perr, char *fmt, va_list ap)
{
    vfprintf (stderr, fmt, ap);
    if (perr)
        perror (" ");
    else
        fprintf (stderr, "\n");
    exit (1);  
}
     
/* Print error message and exit with error status. */
static void
errf (char *fmt, ...)
{
    va_list ap;
       
    va_start (ap, fmt);
    error_print (0, fmt, ap);
    va_end (ap);
}
     
/* Print error message followed by errno status and exit
    with error code. */
static void
perrf (char *fmt, ...)
{
    va_list ap;
       
    va_start (ap, fmt);
    error_print (1, fmt, ap);
    va_end (ap);
}

static void
cudaErrhnd(cudaError_t err){
    if(err)
        errf("Error: %s", cudaGetErrorString(err));
}

void replaceFoundWord(FILE *sfp, FILE *ofp, char *marker, unsigned int lineCount, fpos_t startPos)
{
    char *strbuf = (char*)malloc(LINE_MAXLEN);
    int i;

    fsetpos (sfp, &startPos);
    for (i = 0; i < lineCount; i++) 
    {
        strcpy(strbuf, "\0");
        if (fgets(strbuf, LINE_MAXLEN, sfp) != NULL) 
        {
            //linectr++;
            if (marker[i] == 'n') 
            {
                fprintf(ofp, "%s", strbuf);
            } 
            else 
            {
                fprintf(ofp, "%s", "---\n");
            }
        }
    }

}

__device__
int cdStrcmp(const char *s1, const char *s2){
    for ( ; *s1 == *s2; s1++, s2++)
	    if (*s1 == '\0')
	        return 0;
    return ((*(unsigned char *)s1 < *(unsigned char *)s2) ? -1 : +1);
}

__global__
void ckCountWord(char *src, unsigned int srcLineAmount, char *cmp, char *elim, int *count) {
	// get next line from sfp
    int tid = threadIdx.x + blockIdx.x * blockDim.x;
    int lineIdx = tid * LINE_MAXLEN;
    int i;
    char *srcWord, *cmpWord;
	
	for (i = 0; i < srcLineAmount; i++) {
        srcWord = &src[i * LINE_MAXLEN];
        cmpWord = &cmp[lineIdx];

	    if(cdStrcmp(srcWord, cmpWord) == 0){
            elim[i] = 'y'; // mark as found
            count[tid] += 1;
        }
        
	}
}

int main(int argc, char **argv)
{
    if (argc < 3)
        errf("Please fill the input file and comparer");

    time_t begin = time(NULL);

    FILE *sfp = fopen (argv[1], "r");
    FILE *cfp = fopen (argv[2], "r");
    FILE *ofp = fopen ("replace-result.txt", "w");
    FILE *nfp = fopen ("count-result.txt", "w");

    if (!sfp)
        perrf("cannot open file `%s'", argv[1]);
    if (!cfp)
        perrf("cannot open file `%s'", argv[2]);
    if (!ofp)
        perrf("cannot create file `%s'", "replace-result.txt");
    if (!nfp)
        perrf("cannot create file `%s'", "count-result.txt");
    
    int i,j;

	char *D_srcSec, *H_srcSec, *D_elim, *H_elim, *D_cmpSec, *H_cmpSec;
    int *D_count, *H_count;	
    
    size_t srcSecSize = SRC_LINES * LINE_MAXLEN;
    size_t cmpSecSize = CMP_LINES * LINE_MAXLEN;

	printf("Allocating Memory for Host\n");
    H_srcSec = (char*)malloc(srcSecSize);
    H_elim = (char*)malloc(SRC_LINES);
	H_cmpSec = (char*)malloc(cmpSecSize);
    H_count = (int*)malloc(sizeof(int) * CMP_LINES);
	printf("Allocating Memory for Device\n");
    cudaErrhnd(cudaMalloc((void**)&D_srcSec, srcSecSize));
    cudaErrhnd(cudaMalloc((void**)&D_elim, SRC_LINES));
    cudaErrhnd(cudaMalloc((void**)&D_cmpSec, cmpSecSize));
    cudaErrhnd(cudaMalloc((void**)&D_count, sizeof(int) * CMP_LINES));

	// main task
	printf("Initializing Data\n");
	for(i = 0; i < CMP_LINES; i++){
		if(fgets(&H_cmpSec[i * LINE_MAXLEN], LINE_MAXLEN, cfp) == NULL) break;
    }
    
    cudaErrhnd(cudaMemcpy(D_cmpSec, H_cmpSec, cmpSecSize, cudaMemcpyHostToDevice));

    cudaErrhnd(cudaMemset(D_count, 0, sizeof(int) * CMP_LINES));

    int itr = 0;
    fpos_t startPos;

	for(i = 1; i != 0;){
        itr += 1;
	if(itr % 100 == 0) printf("Computing section number %d.\n",itr);
        fgetpos(sfp, &startPos);

		for(j = 0; j < SRC_LINES; j++){
			if(fgets(&H_srcSec[j * LINE_MAXLEN], LINE_MAXLEN, sfp) == NULL){
                i = 0;
                break;
            }
        }

        if(j == 0) break;

        cudaErrhnd(cudaMemset(D_elim, 'n', j));
        
        cudaErrhnd(cudaMemcpy(D_srcSec, H_srcSec, srcSecSize, cudaMemcpyHostToDevice));
				
        ckCountWord<<<CMP_LINES/BLOCK_SIZE,BLOCK_SIZE>>>(D_srcSec, j, D_cmpSec, D_elim, D_count);

        cudaDeviceSynchronize();

        cudaErrhnd(cudaGetLastError());

        cudaErrhnd(cudaMemcpy(H_elim, D_elim, j, cudaMemcpyDeviceToHost));

        replaceFoundWord(sfp, ofp, H_elim, j, startPos);
    }

    cudaErrhnd(cudaMemcpy(H_count, D_count, sizeof(int) * CMP_LINES, cudaMemcpyDeviceToHost));
    
    cudaFree(D_srcSec);
    cudaFree(D_elim);
    cudaFree(D_cmpSec);
    cudaFree(D_count);
    free(H_srcSec);
    free(H_elim);
    
    // test output
/*
    for(i=0; i<CMP_LINES; i++){
        printf("%d\n", H_count[i]);
    }
*/    
    // modify files
    for(i=0; i < CMP_LINES; i++){
        fprintf(nfp, "%d ", H_count[i]);
        fprintf(nfp, "%s", &H_cmpSec[i * LINE_MAXLEN]);
    }

    time_t end = time(NULL);

    fprintf(nfp, "\nComputed in %.6f seconds.\n", difftime(end,begin));


    free(H_cmpSec);
    free(H_count);
    
    fclose(sfp);
    fclose(cfp);
    fclose(ofp);
    fclose(nfp);

    return 0;

}

	.file	"tmpxft_002a6d4f_00000000-6_wordcount.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2036:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2036:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	" "
	.section	.text.unlikely,"ax",@progbits
	.type	_ZL5perrfPcz, @function
_ZL5perrfPcz:
.LFB2029:
	.cfi_startproc
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$216, %rsp
	.cfi_def_cfa_offset 224
	movq	%rsi, 40(%rsp)
	movq	%rdx, 48(%rsp)
	movq	%rcx, 56(%rsp)
	movq	%r8, 64(%rsp)
	movq	%r9, 72(%rsp)
	testb	%al, %al
	je	.L3
	movaps	%xmm0, 80(%rsp)
	movaps	%xmm1, 96(%rsp)
	movaps	%xmm2, 112(%rsp)
	movaps	%xmm3, 128(%rsp)
	movaps	%xmm4, 144(%rsp)
	movaps	%xmm5, 160(%rsp)
	movaps	%xmm6, 176(%rsp)
	movaps	%xmm7, 192(%rsp)
.L3:
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	movq	%rdi, %rdx
	leaq	224(%rsp), %rax
	movq	%rsp, %rcx
	movq	stderr(%rip), %rdi
	movq	%rax, 8(%rsp)
	movl	$2, %esi
	leaq	32(%rsp), %rax
	movl	$8, (%rsp)
	movl	$48, 4(%rsp)
	movq	%rax, 16(%rsp)
	call	__vfprintf_chk@PLT
	leaq	.LC0(%rip), %rdi
	call	perror@PLT
	movl	$1, %edi
	call	exit@PLT
	.cfi_endproc
.LFE2029:
	.size	_ZL5perrfPcz, .-_ZL5perrfPcz
	.section	.rodata.str1.1
.LC1:
	.string	"\n"
	.text
	.type	_ZL4errfPcz, @function
_ZL4errfPcz:
.LFB2028:
	.cfi_startproc
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$216, %rsp
	.cfi_def_cfa_offset 224
	movq	%rsi, 40(%rsp)
	movq	%rdx, 48(%rsp)
	movq	%rcx, 56(%rsp)
	movq	%r8, 64(%rsp)
	movq	%r9, 72(%rsp)
	testb	%al, %al
	je	.L8
	movaps	%xmm0, 80(%rsp)
	movaps	%xmm1, 96(%rsp)
	movaps	%xmm2, 112(%rsp)
	movaps	%xmm3, 128(%rsp)
	movaps	%xmm4, 144(%rsp)
	movaps	%xmm5, 160(%rsp)
	movaps	%xmm6, 176(%rsp)
	movaps	%xmm7, 192(%rsp)
.L8:
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	movq	%rdi, %rdx
	leaq	224(%rsp), %rax
	movq	%rsp, %rcx
	movq	stderr(%rip), %rdi
	movq	%rax, 8(%rsp)
	movl	$2, %esi
	leaq	32(%rsp), %rax
	movl	$8, (%rsp)
	movl	$48, 4(%rsp)
	movq	%rax, 16(%rsp)
	call	__vfprintf_chk@PLT
	movq	stderr(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
	.cfi_endproc
.LFE2028:
	.size	_ZL4errfPcz, .-_ZL4errfPcz
	.section	.rodata.str1.1
.LC2:
	.string	"Error: %s"
	.text
	.type	_ZL10cudaErrhnd9cudaError, @function
_ZL10cudaErrhnd9cudaError:
.LFB2030:
	.cfi_startproc
	testl	%edi, %edi
	je	.L11
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	cudaGetErrorString@PLT
	leaq	.LC2(%rip), %rdi
	movq	%rax, %rsi
	xorl	%eax, %eax
	call	_ZL4errfPcz
.L11:
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_ZL10cudaErrhnd9cudaError, .-_ZL10cudaErrhnd9cudaError
	.section	.rodata.str1.1
.LC3:
	.string	"%s"
.LC4:
	.string	"---\n"
	.text
	.globl	_Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t
	.type	_Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t, @function
_Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC3(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	movl	$13000, %edi
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdx, %rbx
	addq	%rbx, %rbp
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%r8, (%rsp)
	movq	%r9, 8(%rsp)
	call	malloc@PLT
	movq	%rsp, %rsi
	movq	%r13, %rdi
	movq	%rax, %r12
	call	fsetpos@PLT
.L17:
	cmpq	%rbp, %rbx
	je	.L26
	movb	$0, (%r12)
	movq	%r13, %rcx
	movl	$13000, %edx
	movq	%r12, %rdi
	movl	$13000, %esi
	call	__fgets_chk@PLT
	testq	%rax, %rax
	je	.L18
	cmpb	$110, (%rbx)
	movq	%r12, %rcx
	je	.L25
	leaq	.LC4(%rip), %rcx
.L25:
	movq	%r15, %rdx
	movl	$2, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L18:
	incq	%rbx
	jmp	.L17
.L26:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t, .-_Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t
	.globl	_Z8cdStrcmpPKcS0_
	.type	_Z8cdStrcmpPKcS0_, @function
_Z8cdStrcmpPKcS0_:
.LFB2032:
	.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
.LFE2032:
	.size	_Z8cdStrcmpPKcS0_, .-_Z8cdStrcmpPKcS0_
	.globl	_Z38__device_stub__Z11ckCountWordPcjS_S_PiPcjS_S_Pi
	.type	_Z38__device_stub__Z11ckCountWordPcjS_S_PiPcjS_S_Pi, @function
_Z38__device_stub__Z11ckCountWordPcjS_S_PiPcjS_S_Pi:
.LFB2058:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movl	%esi, 36(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movq	%r8, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	36(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z11ckCountWordPcjS_S_Pi(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L29:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z38__device_stub__Z11ckCountWordPcjS_S_PiPcjS_S_Pi, .-_Z38__device_stub__Z11ckCountWordPcjS_S_PiPcjS_S_Pi
	.globl	_Z11ckCountWordPcjS_S_Pi
	.type	_Z11ckCountWordPcjS_S_Pi, @function
_Z11ckCountWordPcjS_S_Pi:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z11ckCountWordPcjS_S_PiPcjS_S_Pi
	.cfi_endproc
.LFE2059:
	.size	_Z11ckCountWordPcjS_S_Pi, .-_Z11ckCountWordPcjS_S_Pi
	.section	.rodata.str1.1
.LC5:
	.string	"Please fill the input file and comparer"
.LC6:
	.string	"r"
.LC7:
	.string	"w"
.LC8:
	.string	"replace-result.txt"
.LC9:
	.string	"count-result.txt"
.LC10:
	.string	"cannot open file `%s'"
.LC11:
	.string	"cannot create file `%s'"
.LC12:
	.string	"Allocating Memory for Host\n"
.LC13:
	.string	"Allocating Memory for Device\n"
.LC14:
	.string	"Initializing Data\n"
.LC15:
	.string	"Computing section number %d.\n"
.LC16:
	.string	"%d "
.LC17:
	.string	"\nComputed in %.6f seconds.\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	jg	.L35
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L66
	leaq	.LC5(%rip), %rdi
	xorl	%eax, %eax
	call	_ZL4errfPcz
.L35:
	movq	%rsi, %r13
	xorl	%edi, %edi
	leaq	.LC6(%rip), %rbp
	call	time@PLT
	movq	8(%r13), %rdi
	movq	%rbp, %rsi
	leaq	.LC8(%rip), %r12
	movq	%rax, 48(%rsp)
	call	fopen@PLT
	movq	16(%r13), %rdi
	movq	%rbp, %rsi
	leaq	.LC7(%rip), %rbp
	movq	%rax, %rbx
	call	fopen@PLT
	movq	%rbp, %rsi
	movq	%r12, %rdi
	movq	%rax, 16(%rsp)
	call	fopen@PLT
	movq	%rbp, %rsi
	leaq	.LC9(%rip), %rbp
	movq	%rbp, %rdi
	movq	%rax, 24(%rsp)
	call	fopen@PLT
	movq	%rax, 8(%rsp)
	testq	%rbx, %rbx
	jne	.L37
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L66
	movq	8(%r13), %rsi
	jmp	.L69
.L37:
	cmpq	$0, 16(%rsp)
	jne	.L39
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L66
	movq	16(%r13), %rsi
.L69:
	leaq	.LC10(%rip), %rdi
	jmp	.L67
.L39:
	cmpq	$0, 24(%rsp)
	jne	.L41
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	movq	%r12, %rsi
	je	.L68
	jmp	.L66
.L41:
	cmpq	$0, 8(%rsp)
	jne	.L43
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	movq	%rbp, %rsi
	jne	.L66
.L68:
	leaq	.LC11(%rip), %rdi
.L67:
	xorl	%eax, %eax
	call	_ZL5perrfPcz
.L43:
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	movl	$13000000, %r14d
	call	__printf_chk@PLT
	movl	$130000000, %edi
	call	malloc@PLT
	movl	$10000, %edi
	movq	%rax, 32(%rsp)
	call	malloc@PLT
	movl	$13000000, %edi
	movq	%rax, 40(%rsp)
	call	malloc@PLT
	movl	$4000, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	leaq	13000000(%rbp), %r13
	movq	%rax, %r12
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$130000000, %esi
	leaq	64(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	call	_ZL10cudaErrhnd9cudaError
	movl	$10000, %esi
	leaq	72(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	call	_ZL10cudaErrhnd9cudaError
	movl	$13000000, %esi
	leaq	80(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	call	_ZL10cudaErrhnd9cudaError
	movl	$4000, %esi
	leaq	88(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	call	_ZL10cudaErrhnd9cudaError
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L46:
	movq	%r13, %rdi
	movq	16(%rsp), %rcx
	movl	$13000, %edx
	movq	%r14, %rsi
	subq	%r14, %rdi
	call	__fgets_chk@PLT
	testq	%rax, %rax
	je	.L45
	subq	$13000, %r14
	jne	.L46
.L45:
	movq	80(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	xorl	%r13d, %r13d
	movl	$13000000, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	call	_ZL10cudaErrhnd9cudaError
	movq	88(%rsp), %rdi
	movl	$4000, %edx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movl	%eax, %edi
	call	_ZL10cudaErrhnd9cudaError
.L53:
	incl	%r13d
	movl	$100, %ecx
	movl	%r13d, %eax
	cltd
	idivl	%ecx
	testl	%edx, %edx
	jne	.L47
	movl	%r13d, %edx
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L47:
	leaq	120(%rsp), %rsi
	movq	%rbx, %rdi
	xorl	%r15d, %r15d
	call	fgetpos@PLT
.L49:
	imulq	$-13000, %r15, %rax
	movq	32(%rsp), %rdi
	movq	%rbx, %rcx
	movl	$13000, %edx
	subq	%rax, %rdi
	leaq	130000000(%rax), %rsi
	call	__fgets_chk@PLT
	testq	%rax, %rax
	je	.L48
	incq	%r15
	cmpq	$10000, %r15
	jne	.L49
	movl	$1, %r15d
	movl	$10000, %r14d
	jmp	.L50
.L48:
	movl	%r15d, %r14d
	testl	%r15d, %r15d
	jne	.L56
.L54:
	movq	88(%rsp), %rsi
	movl	$2, %ecx
	movq	%r12, %rdi
	xorl	%r14d, %r14d
	movl	$4000, %edx
	leaq	.LC16(%rip), %r13
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	call	_ZL10cudaErrhnd9cudaError
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	free@PLT
	movq	40(%rsp), %rdi
	call	free@PLT
	jmp	.L51
.L56:
	xorl	%r15d, %r15d
.L50:
	movslq	%r14d, %rax
	movq	72(%rsp), %rdi
	movl	$110, %esi
	movq	%rax, %rdx
	movq	%rax, 56(%rsp)
	call	cudaMemset@PLT
	movl	%eax, %edi
	call	_ZL10cudaErrhnd9cudaError
	movq	32(%rsp), %rsi
	movq	64(%rsp), %rdi
	movl	$1, %ecx
	movl	$130000000, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	call	_ZL10cudaErrhnd9cudaError
	movl	$536871037, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$3, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L52
	movq	88(%rsp), %r8
	movq	72(%rsp), %rcx
	movl	%r14d, %esi
	movq	80(%rsp), %rdx
	movq	64(%rsp), %rdi
	call	_Z38__device_stub__Z11ckCountWordPcjS_S_PiPcjS_S_Pi
.L52:
	call	cudaDeviceSynchronize@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	call	_ZL10cudaErrhnd9cudaError
	movq	72(%rsp), %rsi
	movq	40(%rsp), %rdi
	movslq	%r14d, %rdx
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	call	_ZL10cudaErrhnd9cudaError
	movq	120(%rsp), %r8
	movl	%r14d, %ecx
	movq	%rbx, %rdi
	movq	128(%rsp), %r9
	movq	40(%rsp), %rdx
	movq	24(%rsp), %rsi
	call	_Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t
	testl	%r15d, %r15d
	jne	.L53
	jmp	.L54
.L51:
	movl	(%r12,%r14,4), %ecx
	movq	8(%rsp), %rdi
	movq	%r13, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	imulq	$13000, %r14, %rcx
	xorl	%eax, %eax
	incq	%r14
	movq	8(%rsp), %rdi
	leaq	.LC3(%rip), %rdx
	movl	$2, %esi
	addq	%rbp, %rcx
	call	__fprintf_chk@PLT
	cmpq	$1000, %r14
	jne	.L51
	xorl	%edi, %edi
	call	time@PLT
	movq	48(%rsp), %rsi
	movq	%rax, %rdi
	call	difftime@PLT
	movq	8(%rsp), %rdi
	leaq	.LC17(%rip), %rdx
	movb	$1, %al
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	16(%rsp), %rdi
	call	fclose@PLT
	movq	24(%rsp), %rdi
	call	fclose@PLT
	movq	8(%rsp), %rdi
	call	fclose@PLT
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L55
.L66:
	call	__stack_chk_fail@PLT
.L55:
	addq	$152, %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
.LFE2033:
	.size	main, .-main
	.section	.rodata.str1.1
.LC18:
	.string	"_Z11ckCountWordPcjS_S_Pi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2061:
	.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	.LC18(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z11ckCountWordPcjS_S_Pi(%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
.LFE2061:
	.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:


#include <hip/hip_runtime.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include <time.h>

#define SRC_LINES 10000 // 40
#define CMP_LINES 1000 // 4
#define LINE_MAXLEN 13000 // 100
#define BLOCK_SIZE 1000 // 4


/* Print error message and exit with error status. If PERR is not 0,
    display current errno status. */
static void
error_print (int perr, char *fmt, va_list ap)
{
    vfprintf (stderr, fmt, ap);
    if (perr)
        perror (" ");
    else
        fprintf (stderr, "\n");
    exit (1);  
}
     
/* Print error message and exit with error status. */
static void
errf (char *fmt, ...)
{
    va_list ap;
       
    va_start (ap, fmt);
    error_print (0, fmt, ap);
    va_end (ap);
}
     
/* Print error message followed by errno status and exit
    with error code. */
static void
perrf (char *fmt, ...)
{
    va_list ap;
       
    va_start (ap, fmt);
    error_print (1, fmt, ap);
    va_end (ap);
}

static void
cudaErrhnd(hipError_t err){
    if(err)
        errf("Error: %s", hipGetErrorString(err));
}

void replaceFoundWord(FILE *sfp, FILE *ofp, char *marker, unsigned int lineCount, fpos_t startPos)
{
    char *strbuf = (char*)malloc(LINE_MAXLEN);
    int i;

    fsetpos (sfp, &startPos);
    for (i = 0; i < lineCount; i++) 
    {
        strcpy(strbuf, "\0");
        if (fgets(strbuf, LINE_MAXLEN, sfp) != NULL) 
        {
            //linectr++;
            if (marker[i] == 'n') 
            {
                fprintf(ofp, "%s", strbuf);
            } 
            else 
            {
                fprintf(ofp, "%s", "---\n");
            }
        }
    }

}

__device__
int cdStrcmp(const char *s1, const char *s2){
    for ( ; *s1 == *s2; s1++, s2++)
	    if (*s1 == '\0')
	        return 0;
    return ((*(unsigned char *)s1 < *(unsigned char *)s2) ? -1 : +1);
}

__global__
void ckCountWord(char *src, unsigned int srcLineAmount, char *cmp, char *elim, int *count) {
	// get next line from sfp
    int tid = threadIdx.x + blockIdx.x * blockDim.x;
    int lineIdx = tid * LINE_MAXLEN;
    int i;
    char *srcWord, *cmpWord;
	
	for (i = 0; i < srcLineAmount; i++) {
        srcWord = &src[i * LINE_MAXLEN];
        cmpWord = &cmp[lineIdx];

	    if(cdStrcmp(srcWord, cmpWord) == 0){
            elim[i] = 'y'; // mark as found
            count[tid] += 1;
        }
        
	}
}

int main(int argc, char **argv)
{
    if (argc < 3)
        errf("Please fill the input file and comparer");

    time_t begin = time(NULL);

    FILE *sfp = fopen (argv[1], "r");
    FILE *cfp = fopen (argv[2], "r");
    FILE *ofp = fopen ("replace-result.txt", "w");
    FILE *nfp = fopen ("count-result.txt", "w");

    if (!sfp)
        perrf("cannot open file `%s'", argv[1]);
    if (!cfp)
        perrf("cannot open file `%s'", argv[2]);
    if (!ofp)
        perrf("cannot create file `%s'", "replace-result.txt");
    if (!nfp)
        perrf("cannot create file `%s'", "count-result.txt");
    
    int i,j;

	char *D_srcSec, *H_srcSec, *D_elim, *H_elim, *D_cmpSec, *H_cmpSec;
    int *D_count, *H_count;	
    
    size_t srcSecSize = SRC_LINES * LINE_MAXLEN;
    size_t cmpSecSize = CMP_LINES * LINE_MAXLEN;

	printf("Allocating Memory for Host\n");
    H_srcSec = (char*)malloc(srcSecSize);
    H_elim = (char*)malloc(SRC_LINES);
	H_cmpSec = (char*)malloc(cmpSecSize);
    H_count = (int*)malloc(sizeof(int) * CMP_LINES);
	printf("Allocating Memory for Device\n");
    cudaErrhnd(hipMalloc((void**)&D_srcSec, srcSecSize));
    cudaErrhnd(hipMalloc((void**)&D_elim, SRC_LINES));
    cudaErrhnd(hipMalloc((void**)&D_cmpSec, cmpSecSize));
    cudaErrhnd(hipMalloc((void**)&D_count, sizeof(int) * CMP_LINES));

	// main task
	printf("Initializing Data\n");
	for(i = 0; i < CMP_LINES; i++){
		if(fgets(&H_cmpSec[i * LINE_MAXLEN], LINE_MAXLEN, cfp) == NULL) break;
    }
    
    cudaErrhnd(hipMemcpy(D_cmpSec, H_cmpSec, cmpSecSize, hipMemcpyHostToDevice));

    cudaErrhnd(hipMemset(D_count, 0, sizeof(int) * CMP_LINES));

    int itr = 0;
    fpos_t startPos;

	for(i = 1; i != 0;){
        itr += 1;
	if(itr % 100 == 0) printf("Computing section number %d.\n",itr);
        fgetpos(sfp, &startPos);

		for(j = 0; j < SRC_LINES; j++){
			if(fgets(&H_srcSec[j * LINE_MAXLEN], LINE_MAXLEN, sfp) == NULL){
                i = 0;
                break;
            }
        }

        if(j == 0) break;

        cudaErrhnd(hipMemset(D_elim, 'n', j));
        
        cudaErrhnd(hipMemcpy(D_srcSec, H_srcSec, srcSecSize, hipMemcpyHostToDevice));
				
        ckCountWord<<<CMP_LINES/BLOCK_SIZE,BLOCK_SIZE>>>(D_srcSec, j, D_cmpSec, D_elim, D_count);

        hipDeviceSynchronize();

        cudaErrhnd(hipGetLastError());

        cudaErrhnd(hipMemcpy(H_elim, D_elim, j, hipMemcpyDeviceToHost));

        replaceFoundWord(sfp, ofp, H_elim, j, startPos);
    }

    cudaErrhnd(hipMemcpy(H_count, D_count, sizeof(int) * CMP_LINES, hipMemcpyDeviceToHost));
    
    hipFree(D_srcSec);
    hipFree(D_elim);
    hipFree(D_cmpSec);
    hipFree(D_count);
    free(H_srcSec);
    free(H_elim);
    
    // test output
/*
    for(i=0; i<CMP_LINES; i++){
        printf("%d\n", H_count[i]);
    }
*/    
    // modify files
    for(i=0; i < CMP_LINES; i++){
        fprintf(nfp, "%d ", H_count[i]);
        fprintf(nfp, "%s", &H_cmpSec[i * LINE_MAXLEN]);
    }

    time_t end = time(NULL);

    fprintf(nfp, "\nComputed in %.6f seconds.\n", difftime(end,begin));


    free(H_cmpSec);
    free(H_count);
    
    fclose(sfp);
    fclose(cfp);
    fclose(ofp);
    fclose(nfp);

    return 0;

}

	.text
	.file	"wordcount.hip"
	.globl	_Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t # -- Begin function _Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t
	.type	_Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t,@function
_Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t: # @_Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%ecx, %ebp
	movq	%rdx, %rbx
	movq	%rsi, %r14
	movq	%rdi, %r15
	leaq	8(%rsp), %r13
	movq	%r8, (%r13)
	movq	%r9, 8(%r13)
	movl	$13000, %edi                    # imm = 0x32C8
	callq	malloc
	movq	%rax, %r12
	movq	%r15, %rdi
	movq	%r13, %rsi
	callq	fsetpos
	testl	%ebp, %ebp
	je	.LBB0_7
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %r13d
	xorl	%ebp, %ebp
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movb	$0, (%r12)
	movq	%r12, %rdi
	movl	$13000, %esi                    # imm = 0x32C8
	movq	%r15, %rdx
	callq	fgets
	testq	%rax, %rax
	je	.LBB0_6
# %bb.3:                                # %.sink.split
                                        #   in Loop: Header=BB0_2 Depth=1
	cmpb	$110, (%rbx,%rbp)
	movq	%r12, %rdi
	je	.LBB0_5
# %bb.4:                                # %.sink.split
                                        #   in Loop: Header=BB0_2 Depth=1
	movl	$.L.str.2, %edi
.LBB0_5:                                # %.sink.split
                                        #   in Loop: Header=BB0_2 Depth=1
	movq	%r14, %rsi
	callq	fputs@PLT
.LBB0_6:                                #   in Loop: Header=BB0_2 Depth=1
	incq	%rbp
	cmpq	%rbp, %r13
	jne	.LBB0_2
.LBB0_7:                                # %._crit_edge
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t, .Lfunc_end0-_Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t
	.cfi_endproc
                                        # -- End function
	.globl	_Z26__device_stub__ckCountWordPcjS_S_Pi # -- Begin function _Z26__device_stub__ckCountWordPcjS_S_Pi
	.type	_Z26__device_stub__ckCountWordPcjS_S_Pi,@function
_Z26__device_stub__ckCountWordPcjS_S_Pi: # @_Z26__device_stub__ckCountWordPcjS_S_Pi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	12(%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	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%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	$_Z11ckCountWordPcjS_S_Pi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z26__device_stub__ckCountWordPcjS_S_Pi, .Lfunc_end1-_Z26__device_stub__ckCountWordPcjS_S_Pi
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$2, %edi
	jle	.LBB2_22
# %bb.1:
	movq	%rsi, %r14
	xorl	%edi, %edi
	callq	time
	movq	%rax, %r13
	movq	8(%r14), %rdi
	movl	$.L.str.4, %esi
	callq	fopen
	movq	%rax, %rbx
	movq	16(%r14), %rdi
	movl	$.L.str.4, %esi
	callq	fopen
	movq	%rax, %r15
	movl	$.L.str.5, %edi
	movl	$.L.str.6, %esi
	callq	fopen
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	movl	$.L.str.7, %edi
	movl	$.L.str.6, %esi
	callq	fopen
	testq	%rbx, %rbx
	je	.LBB2_23
# %bb.2:
	testq	%r15, %r15
	je	.LBB2_24
# %bb.3:
	cmpq	$0, 24(%rsp)                    # 8-byte Folded Reload
	je	.LBB2_27
# %bb.4:
	movq	%rax, %r12
	testq	%rax, %rax
	je	.LBB2_28
# %bb.5:
	movq	%r13, 80(%rsp)                  # 8-byte Spill
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$130000000, %edi                # imm = 0x7BFA480
	callq	malloc
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movl	$10000, %edi                    # imm = 0x2710
	callq	malloc
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	movl	$13000000, %edi                 # imm = 0xC65D40
	callq	malloc
	movq	%rax, %r13
	movl	$4000, %edi                     # imm = 0xFA0
	callq	malloc
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	leaq	48(%rsp), %rdi
	movl	$130000000, %esi                # imm = 0x7BFA480
	callq	hipMalloc
	movl	%eax, %edi
	callq	_ZL10cudaErrhnd10hipError_t
	leaq	16(%rsp), %rdi
	movl	$10000, %esi                    # imm = 0x2710
	callq	hipMalloc
	movl	%eax, %edi
	callq	_ZL10cudaErrhnd10hipError_t
	leaq	40(%rsp), %rdi
	movl	$13000000, %esi                 # imm = 0xC65D40
	callq	hipMalloc
	movl	%eax, %edi
	callq	_ZL10cudaErrhnd10hipError_t
	leaq	8(%rsp), %rdi
	movl	$4000, %esi                     # imm = 0xFA0
	callq	hipMalloc
	movl	%eax, %edi
	callq	_ZL10cudaErrhnd10hipError_t
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	xorl	%r14d, %r14d
.LBB2_6:                                # =>This Inner Loop Header: Depth=1
	leaq	(%r14,%r13), %rdi
	movl	$13000, %esi                    # imm = 0x32C8
	movq	%r15, %rdx
	callq	fgets
	testq	%rax, %rax
	je	.LBB2_8
# %bb.7:                                #   in Loop: Header=BB2_6 Depth=1
	leaq	13000(%r14), %rax
	cmpq	$12987000, %r14                 # imm = 0xC62A78
	movq	%rax, %r14
	jne	.LBB2_6
.LBB2_8:
	movq	%r15, 88(%rsp)                  # 8-byte Spill
	movabsq	$4294967297, %r14               # imm = 0x100000001
	movq	40(%rsp), %rdi
	movl	$13000000, %edx                 # imm = 0xC65D40
	movq	%r13, 72(%rsp)                  # 8-byte Spill
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	callq	_ZL10cudaErrhnd10hipError_t
	movq	8(%rsp), %rdi
	movl	$4000, %edx                     # imm = 0xFA0
	xorl	%esi, %esi
	callq	hipMemset
	movl	%eax, %edi
	callq	_ZL10cudaErrhnd10hipError_t
	leaq	999(%r14), %rax
	movq	%rax, 96(%rsp)                  # 8-byte Spill
	xorl	%ebp, %ebp
.LBB2_9:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_12 Depth 2
	incl	%ebp
	imull	$-1030792151, %ebp, %eax        # imm = 0xC28F5C29
	rorl	$2, %eax
	cmpl	$42949672, %eax                 # imm = 0x28F5C28
	ja	.LBB2_11
# %bb.10:                               #   in Loop: Header=BB2_9 Depth=1
	movl	$.L.str.13, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
.LBB2_11:                               #   in Loop: Header=BB2_9 Depth=1
	movq	%rbx, %rdi
	leaq	104(%rsp), %rsi
	callq	fgetpos
	movq	32(%rsp), %r15                  # 8-byte Reload
	xorl	%r14d, %r14d
.LBB2_12:                               #   Parent Loop BB2_9 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%r15, %rdi
	movl	$13000, %esi                    # imm = 0x32C8
	movq	%rbx, %rdx
	callq	fgets
	movq	%rax, %r13
	testq	%rax, %rax
	je	.LBB2_15
# %bb.13:                               #   in Loop: Header=BB2_12 Depth=2
	incq	%r14
	addq	$13000, %r15                    # imm = 0x32C8
	cmpq	$10000, %r14                    # imm = 0x2710
	jne	.LBB2_12
# %bb.14:                               #   in Loop: Header=BB2_9 Depth=1
	movl	$10000, %r14d                   # imm = 0x2710
	jmp	.LBB2_16
.LBB2_15:                               #   in Loop: Header=BB2_9 Depth=1
	testl	%r14d, %r14d
	je	.LBB2_19
.LBB2_16:                               # %.thread
                                        #   in Loop: Header=BB2_9 Depth=1
	movq	16(%rsp), %rdi
	movl	%r14d, %r15d
	movl	$110, %esi
	movq	%r15, %rdx
	callq	hipMemset
	movl	%eax, %edi
	callq	_ZL10cudaErrhnd10hipError_t
	movq	48(%rsp), %rdi
	movl	$130000000, %edx                # imm = 0x7BFA480
	movq	32(%rsp), %rsi                  # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	callq	_ZL10cudaErrhnd10hipError_t
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movl	$1, %esi
	movq	96(%rsp), %rdx                  # 8-byte Reload
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_18
# %bb.17:                               #   in Loop: Header=BB2_9 Depth=1
	movq	48(%rsp), %rdi
	movq	40(%rsp), %rdx
	movq	16(%rsp), %rcx
	movq	8(%rsp), %r8
	movl	%r15d, %esi
	callq	_Z26__device_stub__ckCountWordPcjS_S_Pi
.LBB2_18:                               #   in Loop: Header=BB2_9 Depth=1
	callq	hipDeviceSynchronize
	callq	hipGetLastError
	movl	%eax, %edi
	callq	_ZL10cudaErrhnd10hipError_t
	movq	16(%rsp), %rsi
	movq	56(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	callq	_ZL10cudaErrhnd10hipError_t
	movq	104(%rsp), %r8
	movq	112(%rsp), %r9
	movq	%rbx, %rdi
	movq	24(%rsp), %rsi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	%r15d, %ecx
	callq	_Z16replaceFoundWordP8_IO_FILES0_Pcj9_G_fpos_t
	testq	%r13, %r13
	jne	.LBB2_9
.LBB2_19:
	movq	8(%rsp), %rsi
	movl	$4000, %edx                     # imm = 0xFA0
	movq	64(%rsp), %rbp                  # 8-byte Reload
	movq	%rbp, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	callq	_ZL10cudaErrhnd10hipError_t
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	56(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	72(%rsp), %r13                  # 8-byte Reload
	movq	%r13, %r14
	xorl	%r15d, %r15d
.LBB2_20:                               # =>This Inner Loop Header: Depth=1
	movl	(%rbp,%r15,4), %edx
	movl	$.L.str.14, %esi
	movq	%r12, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movq	%r14, %rdi
	movq	%r12, %rsi
	callq	fputs@PLT
	incq	%r15
	addq	$13000, %r14                    # imm = 0x32C8
	cmpq	$1000, %r15                     # imm = 0x3E8
	jne	.LBB2_20
# %bb.21:
	xorl	%edi, %edi
	callq	time
	movq	%rax, %rdi
	movq	80(%rsp), %rsi                  # 8-byte Reload
	callq	difftime
	movl	$.L.str.15, %esi
	movq	%r12, %rdi
	movb	$1, %al
	callq	fprintf
	movq	%r13, %rdi
	callq	free
	movq	%rbp, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	fclose
	movq	88(%rsp), %rdi                  # 8-byte Reload
	callq	fclose
	movq	24(%rsp), %rdi                  # 8-byte Reload
	callq	fclose
	movq	%r12, %rdi
	callq	fclose
	xorl	%eax, %eax
	addq	$120, %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
.LBB2_22:
	.cfi_def_cfa_offset 176
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	_ZL4errfPcz
.LBB2_23:
	movq	8(%r14), %rsi
	jmp	.LBB2_25
.LBB2_24:
	movq	16(%r14), %rsi
.LBB2_25:
	movl	$.L.str.8, %edi
	jmp	.LBB2_26
.LBB2_27:
	movl	$.L.str.9, %edi
	movl	$.L.str.5, %esi
	jmp	.LBB2_26
.LBB2_28:
	movl	$.L.str.9, %edi
	movl	$.L.str.7, %esi
.LBB2_26:
	xorl	%eax, %eax
	callq	_ZL5perrfPcz
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.type	_ZL4errfPcz,@function           # -- Begin function _ZL4errfPcz
_ZL4errfPcz:                            # @_ZL4errfPcz
	.cfi_startproc
# %bb.0:
	subq	$216, %rsp
	.cfi_def_cfa_offset 224
	movq	%rdi, %r10
	leaq	32(%rsp), %rdi
	movq	%rsi, 8(%rdi)
	movq	%rdx, 16(%rdi)
	movq	%rcx, 24(%rdi)
	movq	%r8, 32(%rdi)
	movq	%r9, 40(%rdi)
	testb	%al, %al
	je	.LBB3_2
# %bb.1:
	movaps	%xmm0, 80(%rsp)
	movaps	%xmm1, 96(%rsp)
	movaps	%xmm2, 112(%rsp)
	movaps	%xmm3, 128(%rsp)
	movaps	%xmm4, 144(%rsp)
	movaps	%xmm5, 160(%rsp)
	movaps	%xmm6, 176(%rsp)
	movaps	%xmm7, 192(%rsp)
.LBB3_2:
	movq	%rsp, %rdx
	movq	%rdi, 16(%rdx)
	leaq	224(%rsp), %rax
	movq	%rax, 8(%rdx)
	movabsq	$206158430216, %rax             # imm = 0x3000000008
	movq	%rax, (%rdx)
	xorl	%edi, %edi
	movq	%r10, %rsi
	callq	_ZL11error_printiPcP13__va_list_tag
.Lfunc_end3:
	.size	_ZL4errfPcz, .Lfunc_end3-_ZL4errfPcz
	.cfi_endproc
                                        # -- End function
	.type	_ZL5perrfPcz,@function          # -- Begin function _ZL5perrfPcz
_ZL5perrfPcz:                           # @_ZL5perrfPcz
	.cfi_startproc
# %bb.0:
	subq	$216, %rsp
	.cfi_def_cfa_offset 224
	movq	%rdi, %r10
	leaq	32(%rsp), %rdi
	movq	%rsi, 8(%rdi)
	movq	%rdx, 16(%rdi)
	movq	%rcx, 24(%rdi)
	movq	%r8, 32(%rdi)
	movq	%r9, 40(%rdi)
	testb	%al, %al
	je	.LBB4_2
# %bb.1:
	movaps	%xmm0, 80(%rsp)
	movaps	%xmm1, 96(%rsp)
	movaps	%xmm2, 112(%rsp)
	movaps	%xmm3, 128(%rsp)
	movaps	%xmm4, 144(%rsp)
	movaps	%xmm5, 160(%rsp)
	movaps	%xmm6, 176(%rsp)
	movaps	%xmm7, 192(%rsp)
.LBB4_2:
	movq	%rsp, %rdx
	movq	%rdi, 16(%rdx)
	leaq	224(%rsp), %rax
	movq	%rax, 8(%rdx)
	movabsq	$206158430216, %rax             # imm = 0x3000000008
	movq	%rax, (%rdx)
	movl	$1, %edi
	movq	%r10, %rsi
	callq	_ZL11error_printiPcP13__va_list_tag
.Lfunc_end4:
	.size	_ZL5perrfPcz, .Lfunc_end4-_ZL5perrfPcz
	.cfi_endproc
                                        # -- End function
	.type	_ZL10cudaErrhnd10hipError_t,@function # -- Begin function _ZL10cudaErrhnd10hipError_t
_ZL10cudaErrhnd10hipError_t:            # @_ZL10cudaErrhnd10hipError_t
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jne	.LBB5_2
# %bb.1:
	retq
.LBB5_2:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	hipGetErrorString
	movl	$.L.str.18, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	_ZL4errfPcz
.Lfunc_end5:
	.size	_ZL10cudaErrhnd10hipError_t, .Lfunc_end5-_ZL10cudaErrhnd10hipError_t
	.cfi_endproc
                                        # -- End function
	.type	_ZL11error_printiPcP13__va_list_tag,@function # -- Begin function _ZL11error_printiPcP13__va_list_tag
_ZL11error_printiPcP13__va_list_tag:    # @_ZL11error_printiPcP13__va_list_tag
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%edi, %ebx
	movq	stderr(%rip), %rdi
	callq	vfprintf
	testl	%ebx, %ebx
	je	.LBB6_2
# %bb.1:
	movl	$.L.str.16, %edi
	callq	perror
.LBB6_3:
	movl	$1, %edi
	callq	exit
.LBB6_2:
	movq	stderr(%rip), %rsi
	movl	$10, %edi
	callq	fputc@PLT
	jmp	.LBB6_3
.Lfunc_end6:
	.size	_ZL11error_printiPcP13__va_list_tag, .Lfunc_end6-_ZL11error_printiPcP13__va_list_tag
	.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	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z11ckCountWordPcjS_S_Pi, %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_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__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	.LBB8_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
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"---\n"
	.size	.L.str.2, 5

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

	.type	.L.str.3,@object                # @.str.3
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.3:
	.asciz	"Please fill the input file and comparer"
	.size	.L.str.3, 40

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"replace-result.txt"
	.size	.L.str.5, 19

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"w"
	.size	.L.str.6, 2

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"count-result.txt"
	.size	.L.str.7, 17

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"cannot open file `%s'"
	.size	.L.str.8, 22

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"cannot create file `%s'"
	.size	.L.str.9, 24

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Computing section number %d.\n"
	.size	.L.str.13, 30

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"%d "
	.size	.L.str.14, 4

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"\nComputed in %.6f seconds.\n"
	.size	.L.str.15, 28

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

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"Error: %s"
	.size	.L.str.18, 10

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z11ckCountWordPcjS_S_Pi"
	.size	.L__unnamed_1, 25

	.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	"Allocating Memory for Host"
	.size	.Lstr, 27

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Allocating Memory for Device"
	.size	.Lstr.1, 29

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Initializing Data"
	.size	.Lstr.2, 18

	.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 _Z26__device_stub__ckCountWordPcjS_S_Pi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z11ckCountWordPcjS_S_Pi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z11ckCountWordPcjS_S_Pi ; -- Begin function _Z11ckCountWordPcjS_S_Pi
	.globl	_Z11ckCountWordPcjS_S_Pi
	.p2align	8
	.type	_Z11ckCountWordPcjS_S_Pi,@function
_Z11ckCountWordPcjS_S_Pi:               ; @_Z11ckCountWordPcjS_S_Pi
; %bb.0:
	s_load_b32 s10, s[0:1], 0x8
	s_mov_b32 s11, 0
	s_waitcnt lgkmcnt(0)
	s_cmp_eq_u32 s10, 0
	s_cbranch_scc1 .LBB0_11
; %bb.1:                                ; %.lr.ph
	s_clause 0x2
	s_load_b32 s2, s[0:1], 0x34
	s_load_b128 s[4:7], s[0:1], 0x10
	s_load_b64 s[8:9], s[0:1], 0x20
	v_dual_mov_b32 v8, 0 :: v_dual_mov_b32 v9, 0x79
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_load_b64 s[2:3], s[0:1], 0x0
	v_mul_lo_u32 v0, 0x32c8, v1
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	v_ashrrev_i32_e32 v4, 31, v0
	v_add_co_u32 v0, vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v4, vcc_lo
	v_add_co_u32 v2, vcc_lo, s8, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s9, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v4, vcc_lo, v0, 1
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v1, vcc_lo
	s_waitcnt lgkmcnt(0)
	s_add_u32 s4, s2, 1
	s_addc_u32 s5, s3, 0
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
	s_mul_i32 s0, s11, 0x32c8
	s_mov_b32 s1, exec_lo
	v_mov_b32_e32 v6, s0
	global_load_u8 v10, v6, s[2:3]
	global_load_u8 v6, v[0:1], off
	s_waitcnt vmcnt(0)
	v_cmpx_eq_u16_e64 v10, v6
	s_cbranch_execz .LBB0_10
; %bb.3:                                ; %.lr.ph.i.preheader
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_dual_mov_b32 v7, v5 :: v_dual_mov_b32 v6, v4
	s_mov_b32 s12, 0
	s_mov_b64 s[8:9], s[4:5]
                                        ; implicit-def: $sgpr13
                                        ; implicit-def: $sgpr14
.LBB0_4:                                ; %.lr.ph.i
                                        ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_and_b32_e32 v10, 0xff, v10
	s_or_b32 s14, s14, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_eq_u16_e32 vcc_lo, 0, v10
	s_cbranch_vccnz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_4 Depth=2
	global_load_u8 v10, v8, s[8:9]
	global_load_u8 v11, v[6:7], off
	v_add_co_u32 v6, s0, v6, 1
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v7, s0, 0, v7, s0
	s_add_u32 s8, s8, 1
	s_addc_u32 s9, s9, 0
	s_and_not1_b32 s14, s14, exec_lo
	s_mov_b32 s0, 0
	s_waitcnt vmcnt(0)
	v_cmp_ne_u16_e32 vcc_lo, v10, v11
	s_and_b32 s15, vcc_lo, exec_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 s14, s14, s15
	s_branch .LBB0_7
.LBB0_6:                                ;   in Loop: Header=BB0_4 Depth=2
	s_mov_b32 s0, -1
                                        ; implicit-def: $vgpr10
                                        ; implicit-def: $vgpr6_vgpr7
                                        ; implicit-def: $sgpr8_sgpr9
.LBB0_7:                                ; %Flow37
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_and_b32 s15, exec_lo, s14
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_or_b32 s12, s15, s12
	s_and_not1_b32 s13, s13, exec_lo
	s_and_b32 s0, s0, exec_lo
	s_or_b32 s13, s13, s0
	s_and_not1_b32 exec_lo, exec_lo, s12
	s_cbranch_execnz .LBB0_4
; %bb.8:                                ; %loop.exit.guard
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s12
	s_and_saveexec_b32 s0, s13
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s0, exec_lo, s0
	s_cbranch_execz .LBB0_10
; %bb.9:                                ; %.critedge
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_mov_b32_e32 v6, s11
	global_store_b8 v6, v9, s[6:7]
	global_load_b32 v6, v[2:3], off
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v6, 1, v6
	global_store_b32 v[2:3], v6, off
.LBB0_10:                               ; %Flow38
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_add_i32 s11, s11, 1
	s_add_u32 s4, s4, 0x32c8
	s_addc_u32 s5, s5, 0
	s_cmp_lg_u32 s11, s10
	s_cbranch_scc1 .LBB0_2
.LBB0_11:                               ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11ckCountWordPcjS_S_Pi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z11ckCountWordPcjS_S_Pi, .Lfunc_end0-_Z11ckCountWordPcjS_S_Pi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 480
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; 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
      - .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
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z11ckCountWordPcjS_S_Pi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z11ckCountWordPcjS_S_Pi.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
