#include <iostream>
#include <cstring>
#include <fstream>
#include "time.h"


using namespace std;

__host__ void preprocesamientoKMP(char* pattern, int m, int f[])
{
    int k;
    f[0] = -1;
    for (int i = 1; i < m; i++){
        k = f[i - 1];
        while (k >= 0){
            if (pattern[k] == pattern[i - 1])
                break;
            else
                k = f[k];
        }
        f[i] = k + 1;
    }
}

__global__ void KMP(char* pattern, char* target,int f[],int c[],int sizePattern, int sizeText)
{
    int index = blockIdx.x*blockDim.x + threadIdx.x;

    int i = sizePattern * index;
    int j = sizePattern * (index + 2)-1;

    if(i > sizeText)
        return;
    if(j > sizeText)
        j = sizeText;

    int k = 0;        
    while (i < j)
    {
        if (k == -1)
        {
            i++;
            k = 0;
        }
        else if (target[i] == pattern[k])
        {
            i++;
            k++;
            if (k == sizePattern)
            {
                c[i - sizePattern] = i - sizePattern;
                i = i - k + 1;
            }
        }
        else
            k = f[k];
    }
    return;
}
 
int main(int argc, char* argv[])
{
    // constante de tamaño
    const int S = 40000000;
    
    // cantidad de threads
    int M = 1024;

    // controla tamaño de char 1 a 4
    int charSize = 4;

    // varibles en CPU
    char *tar;
    char *pat;
    tar = (char*)malloc(2000000);
    pat = (char*)malloc(S*charSize);
    
    // Variables en GPU
    char *d_tar;
    char *d_pat;

    // Stream Files
    ifstream inputFileText;
    ifstream inputFilePattern;
    ofstream outputFileText;

    // Abrir archivos
    inputFileText.open(argv[1]);
    inputFilePattern.open(argv[2]);
    outputFileText.open("DATA/result.txt");

    inputFileText>>tar;
    inputFilePattern>>pat;

    int m = strlen(tar);
    int n = strlen(pat);
    int *fault;
    int *coin;

    fault = new int[m];
    coin = new int[m];

    int *d_fault;
    int *d_coin;

    // inicializar arreglo c con -1 para procesamiento y resultados
    for(int i = 0;i<m; i++)
        coin[i] = -1;


    //num blocks
    int blocks = (m/n+M)/M;

    printf("Copiando datos a GPU\n");
    
    //time_t timeL_init, timeL_end, timeT_end, timeT_init;
    cudaEvent_t start, stop, local_s, local_e;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);
    cudaEventCreate(&local_s);
    cudaEventCreate(&local_e);
    
    preprocesamientoKMP(pat, m, fault);
    cudaEventRecord(start);
    /* Crear variables en cuda */
    cudaMalloc((void **)&d_tar, m*charSize);
    cudaMalloc((void **)&d_pat, n*charSize);
    cudaMalloc((void **)&d_fault, m*charSize);
    cudaMalloc((void **)&d_coin, m*charSize);

    /* Copia de datos a GPU */
    cudaMemcpy(d_tar, tar, m*charSize, cudaMemcpyHostToDevice);
    cudaMemcpy(d_pat, pat, n*charSize, cudaMemcpyHostToDevice);
    cudaMemcpy(d_fault, fault, m*charSize, cudaMemcpyHostToDevice);
    cudaMemcpy(d_coin, coin, m*charSize, cudaMemcpyHostToDevice);
    
    cudaEventRecord(local_s);
    KMP<<<blocks,M>>>(d_pat, d_tar ,d_fault, d_coin, n, m);
    cudaEventRecord(local_e);

    cudaMemcpy(coin, d_coin, m*charSize, cudaMemcpyDeviceToHost);

    // liberar memoria de GPU
    cudaFree(d_tar);
    cudaFree(d_pat);
    cudaFree(d_fault);
    cudaFree(d_coin);
    cudaEventRecord(stop);

    float milis, local;
    cudaEventSynchronize(stop);
    cudaEventSynchronize(local_e);
    cudaEventElapsedTime(&milis, start, stop);
    cudaEventElapsedTime(&local, local_s, local_e);
    
    // mostrar resultados
    for(int i = 0;i<m; i++)
        if(coin[i]!=-1)
            outputFileText<<"position: "<<i<<"\tmatch: "<<coin[i]<<'\n';
    
    
    printf("Blocks: %i Threads: %i n: %i m:%i\n", (m/n+M)/M, M, n, m);
    printf("Tiempo ejecucion: %1.15f ml.\n", milis);
    printf("Tiempo ejecucion kernel: %1.15f ml.\n", local);

    return 0;
}

	.file	"tmpxft_00202b58_00000000-6_kmp_CUDA.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3770:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3770:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z19preprocesamientoKMPPciPi
	.type	_Z19preprocesamientoKMPPciPi, @function
_Z19preprocesamientoKMPPciPi:
.LFB3766:
	.cfi_startproc
	endbr64
	movl	$-1, (%rdx)
	movl	$1, %eax
.L3:
	cmpl	%eax, %esi
	jle	.L10
	movl	-4(%rdx,%rax,4), %ecx
.L4:
	testl	%ecx, %ecx
	js	.L7
	movslq	%ecx, %r8
	movb	-1(%rdi,%rax), %r9b
	cmpb	%r9b, (%rdi,%r8)
	jne	.L5
.L7:
	incl	%ecx
	movl	%ecx, (%rdx,%rax,4)
	incq	%rax
	jmp	.L3
.L5:
	movl	(%rdx,%r8,4), %ecx
	jmp	.L4
.L10:
	ret
	.cfi_endproc
.LFE3766:
	.size	_Z19preprocesamientoKMPPciPi, .-_Z19preprocesamientoKMPPciPi
	.globl	_Z31__device_stub__Z3KMPPcS_PiS0_iiPcS_PiS0_ii
	.type	_Z31__device_stub__Z3KMPPcS_PiS0_iiPcS_PiS0_ii, @function
_Z31__device_stub__Z3KMPPcS_PiS0_iiPcS_PiS0_ii:
.LFB3792:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 12(%rsp)
	movl	%r9d, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L11
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z3KMPPcS_PiS0_ii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L11:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3792:
	.size	_Z31__device_stub__Z3KMPPcS_PiS0_iiPcS_PiS0_ii, .-_Z31__device_stub__Z3KMPPcS_PiS0_iiPcS_PiS0_ii
	.globl	_Z3KMPPcS_PiS0_ii
	.type	_Z3KMPPcS_PiS0_ii, @function
_Z3KMPPcS_PiS0_ii:
.LFB3793:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z3KMPPcS_PiS0_iiPcS_PiS0_ii
	.cfi_endproc
.LFE3793:
	.size	_Z3KMPPcS_PiS0_ii, .-_Z3KMPPcS_PiS0_ii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"_Z3KMPPcS_PiS0_ii"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3795:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC0(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z3KMPPcS_PiS0_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
.LFE3795:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_,"axG",@progbits,_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_,comdat
	.weak	_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_
	.type	_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_, @function
_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_:
.LFB4127:
	.cfi_startproc
	endbr64
	movabsq	$9223372036854775807, %rdx
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	call	_ZSt17__istream_extractRSiPcl@PLT
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4127:
	.size	_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_, .-_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_
	.section	.rodata.str1.1
.LC1:
	.string	"DATA/result.txt"
.LC2:
	.string	"Copiando datos a GPU\n"
.LC3:
	.string	"position: "
.LC4:
	.string	"\tmatch: "
.LC5:
	.string	"Blocks: %i Threads: %i n: %i m:%i\n"
.LC6:
	.string	"Tiempo ejecucion: %1.15f ml.\n"
.LC7:
	.string	"Tiempo ejecucion kernel: %1.15f ml.\n"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB3767:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3767
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$2000000, %edi
	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
	movq	%rsi, %rbx
	subq	$1736, %rsp
	.cfi_def_cfa_offset 1792
	movq	%fs:40, %rax
	movq	%rax, 1720(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$160000000, %edi
	movq	%rax, %r14
	call	malloc@PLT
	movq	%rax, 16(%rsp)
	leaq	680(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 24(%rsp)
.LEHB0:
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev@PLT
.LEHE0:
	leaq	1200(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 32(%rsp)
.LEHB1:
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev@PLT
.LEHE1:
	leaq	168(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 40(%rsp)
.LEHB2:
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1Ev@PLT
.LEHE2:
	movq	8(%rbx), %rsi
	movq	24(%rsp), %rdi
	movl	$8, %edx
.LEHB3:
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode@PLT
	movq	16(%rbx), %rsi
	movq	32(%rsp), %rdi
	movl	$8, %edx
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode@PLT
	movq	40(%rsp), %rdi
	movl	$16, %edx
	leaq	.LC1(%rip), %rsi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode@PLT
	movq	24(%rsp), %rdi
	movq	%r14, %rsi
	call	_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_
	movq	16(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_
	movq	%r14, %rdi
	call	strlen@PLT
	movq	16(%rsp), %rdi
	movq	%rax, %r12
	movl	%eax, %r13d
	call	strlen@PLT
	movabsq	$2305843009213693950, %rdx
	movq	%rax, %rbp
	movl	%eax, %r15d
	movslq	%r12d, %rax
	cmpq	%rax, %rdx
	jb	.L21
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	_Znam@PLT
	movq	8(%rsp), %rdi
	movq	%rax, 48(%rsp)
	call	_Znam@PLT
	movq	%rax, %rbx
	xorl	%eax, %eax
	jmp	.L24
.L21:
	movq	1720(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L47
	call	__cxa_throw_bad_array_new_length@PLT
.L24:
	cmpl	%eax, %r13d
	jle	.L50
	movl	$-1, (%rbx,%rax,4)
	incq	%rax
	jmp	.L24
.L50:
	movl	%r13d, %eax
	movl	$1024, %ecx
	movl	$2, %edi
	cltd
	leaq	.LC2(%rip), %rsi
	idivl	%r15d
	addl	$1024, %eax
	cltd
	idivl	%ecx
	movl	%eax, 60(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	112(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	120(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	128(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	136(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	16(%rsp), %rdi
	movq	48(%rsp), %rdx
	movl	%r13d, %esi
	call	_Z19preprocesamientoKMPPciPi
	movq	112(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	8(%rsp), %rsi
	leaq	80(%rsp), %rdi
	call	cudaMalloc@PLT
	leal	0(,%rbp,4), %r15d
	leaq	88(%rsp), %rdi
	movslq	%r15d, %r15
	movq	%r15, %rsi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	96(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	104(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdx
	movq	80(%rsp), %rdi
	movl	$1, %ecx
	movq	%r14, %rsi
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rsi
	movq	88(%rsp), %rdi
	movl	$1, %ecx
	movq	%r15, %rdx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	48(%rsp), %rsi
	movl	$1, %ecx
	movq	96(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	104(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	call	cudaMemcpy@PLT
	movq	128(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	60(%rsp), %eax
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$10, %rdx
	movl	$1, %ecx
	movl	$1, 164(%rsp)
	movl	%eax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 148(%rsp)
	movq	144(%rsp), %rdi
	movl	152(%rsp), %esi
	movq	%rdx, 156(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	je	.L26
.L28:
	movq	136(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	jmp	.L51
.L26:
	movq	104(%rsp), %rcx
	movq	96(%rsp), %rdx
	movl	%r12d, %r9d
	movl	%ebp, %r8d
	movq	80(%rsp), %rsi
	movq	88(%rsp), %rdi
	call	_Z31__device_stub__Z3KMPPcS_PiS0_iiPcS_PiS0_ii
	jmp	.L28
.L51:
	movq	8(%rsp), %rdx
	movq	104(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	call	cudaMemcpy@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rdi
	call	cudaFree@PLT
	movq	96(%rsp), %rdi
	call	cudaFree@PLT
	movq	104(%rsp), %rdi
	call	cudaFree@PLT
	movq	120(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	120(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	136(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	120(%rsp), %rdx
	movq	112(%rsp), %rsi
	leaq	144(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	136(%rsp), %rdx
	movq	128(%rsp), %rsi
	leaq	156(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	xorl	%r14d, %r14d
	leaq	.LC3(%rip), %r15
.L29:
	cmpl	%r14d, %r13d
	jle	.L52
	cmpl	$-1, (%rbx,%r14,4)
	je	.L30
	leaq	168(%rsp), %rdi
	movq	%r15, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movl	%r14d, %esi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	leaq	.LC4(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	(%rbx,%r14,4), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	movq	(%rax), %rax
	movb	$10, 79(%rsp)
	movq	-24(%rax), %rax
	cmpq	$0, 16(%rdi,%rax)
	je	.L31
	leaq	79(%rsp), %rsi
	movl	$1, %edx
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
	jmp	.L30
.L31:
	movl	$10, %esi
	call	_ZNSo3putEc@PLT
.L30:
	incq	%r14
	jmp	.L29
.L52:
	movl	60(%rsp), %edx
	movl	%r12d, %r9d
	movl	%ebp, %r8d
	movl	$1024, %ecx
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	144(%rsp), %xmm0
	call	__printf_chk@PLT
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	156(%rsp), %xmm0
	call	__printf_chk@PLT
.LEHE3:
	leaq	168(%rsp), %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	leaq	1200(%rsp), %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	leaq	680(%rsp), %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	1720(%rsp), %rax
	subq	%fs:40, %rax
	je	.L38
	jmp	.L47
.L43:
	endbr64
	movq	%rax, %rbx
.L34:
	movq	40(%rsp), %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	jmp	.L35
.L42:
	endbr64
	movq	%rax, %rbx
.L35:
	movq	32(%rsp), %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	jmp	.L36
.L41:
	endbr64
	movq	%rax, %rbx
.L36:
	movq	24(%rsp), %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	1720(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L47
	movq	%rbx, %rdi
.LEHB4:
	call	_Unwind_Resume@PLT
.LEHE4:
.L47:
	call	__stack_chk_fail@PLT
.L38:
	addq	$1736, %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
.LFE3767:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA3767:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3767-.LLSDACSB3767
.LLSDACSB3767:
	.uleb128 .LEHB0-.LFB3767
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB3767
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L41-.LFB3767
	.uleb128 0
	.uleb128 .LEHB2-.LFB3767
	.uleb128 .LEHE2-.LEHB2
	.uleb128 .L42-.LFB3767
	.uleb128 0
	.uleb128 .LEHB3-.LFB3767
	.uleb128 .LEHE3-.LEHB3
	.uleb128 .L43-.LFB3767
	.uleb128 0
	.uleb128 .LEHB4-.LFB3767
	.uleb128 .LEHE4-.LEHB4
	.uleb128 0
	.uleb128 0
.LLSDACSE3767:
	.section	.text.startup
	.size	main, .-main
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <iostream>
#include <cstring>
#include <fstream>
#include "time.h"


using namespace std;

__host__ void preprocesamientoKMP(char* pattern, int m, int f[])
{
    int k;
    f[0] = -1;
    for (int i = 1; i < m; i++){
        k = f[i - 1];
        while (k >= 0){
            if (pattern[k] == pattern[i - 1])
                break;
            else
                k = f[k];
        }
        f[i] = k + 1;
    }
}

__global__ void KMP(char* pattern, char* target,int f[],int c[],int sizePattern, int sizeText)
{
    int index = blockIdx.x*blockDim.x + threadIdx.x;

    int i = sizePattern * index;
    int j = sizePattern * (index + 2)-1;

    if(i > sizeText)
        return;
    if(j > sizeText)
        j = sizeText;

    int k = 0;        
    while (i < j)
    {
        if (k == -1)
        {
            i++;
            k = 0;
        }
        else if (target[i] == pattern[k])
        {
            i++;
            k++;
            if (k == sizePattern)
            {
                c[i - sizePattern] = i - sizePattern;
                i = i - k + 1;
            }
        }
        else
            k = f[k];
    }
    return;
}
 
int main(int argc, char* argv[])
{
    // constante de tamaño
    const int S = 40000000;
    
    // cantidad de threads
    int M = 1024;

    // controla tamaño de char 1 a 4
    int charSize = 4;

    // varibles en CPU
    char *tar;
    char *pat;
    tar = (char*)malloc(2000000);
    pat = (char*)malloc(S*charSize);
    
    // Variables en GPU
    char *d_tar;
    char *d_pat;

    // Stream Files
    ifstream inputFileText;
    ifstream inputFilePattern;
    ofstream outputFileText;

    // Abrir archivos
    inputFileText.open(argv[1]);
    inputFilePattern.open(argv[2]);
    outputFileText.open("DATA/result.txt");

    inputFileText>>tar;
    inputFilePattern>>pat;

    int m = strlen(tar);
    int n = strlen(pat);
    int *fault;
    int *coin;

    fault = new int[m];
    coin = new int[m];

    int *d_fault;
    int *d_coin;

    // inicializar arreglo c con -1 para procesamiento y resultados
    for(int i = 0;i<m; i++)
        coin[i] = -1;


    //num blocks
    int blocks = (m/n+M)/M;

    printf("Copiando datos a GPU\n");
    
    //time_t timeL_init, timeL_end, timeT_end, timeT_init;
    hipEvent_t start, stop, local_s, local_e;
    hipEventCreate(&start);
    hipEventCreate(&stop);
    hipEventCreate(&local_s);
    hipEventCreate(&local_e);
    
    preprocesamientoKMP(pat, m, fault);
    hipEventRecord(start);
    /* Crear variables en cuda */
    hipMalloc((void **)&d_tar, m*charSize);
    hipMalloc((void **)&d_pat, n*charSize);
    hipMalloc((void **)&d_fault, m*charSize);
    hipMalloc((void **)&d_coin, m*charSize);

    /* Copia de datos a GPU */
    hipMemcpy(d_tar, tar, m*charSize, hipMemcpyHostToDevice);
    hipMemcpy(d_pat, pat, n*charSize, hipMemcpyHostToDevice);
    hipMemcpy(d_fault, fault, m*charSize, hipMemcpyHostToDevice);
    hipMemcpy(d_coin, coin, m*charSize, hipMemcpyHostToDevice);
    
    hipEventRecord(local_s);
    KMP<<<blocks,M>>>(d_pat, d_tar ,d_fault, d_coin, n, m);
    hipEventRecord(local_e);

    hipMemcpy(coin, d_coin, m*charSize, hipMemcpyDeviceToHost);

    // liberar memoria de GPU
    hipFree(d_tar);
    hipFree(d_pat);
    hipFree(d_fault);
    hipFree(d_coin);
    hipEventRecord(stop);

    float milis, local;
    hipEventSynchronize(stop);
    hipEventSynchronize(local_e);
    hipEventElapsedTime(&milis, start, stop);
    hipEventElapsedTime(&local, local_s, local_e);
    
    // mostrar resultados
    for(int i = 0;i<m; i++)
        if(coin[i]!=-1)
            outputFileText<<"position: "<<i<<"\tmatch: "<<coin[i]<<'\n';
    
    
    printf("Blocks: %i Threads: %i n: %i m:%i\n", (m/n+M)/M, M, n, m);
    printf("Tiempo ejecucion: %1.15f ml.\n", milis);
    printf("Tiempo ejecucion kernel: %1.15f ml.\n", local);

    return 0;
}

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

                                        # End of file scope inline assembly
	.globl	_Z19preprocesamientoKMPPciPi    # -- Begin function _Z19preprocesamientoKMPPciPi
	.type	_Z19preprocesamientoKMPPciPi,@function
_Z19preprocesamientoKMPPciPi:           # @_Z19preprocesamientoKMPPciPi
	.cfi_startproc
# %bb.0:
	movl	$-1, (%rdx)
	cmpl	$2, %esi
	jl	.LBB0_6
# %bb.1:                                # %.lr.ph.preheader
	movl	%esi, %eax
	movl	$1, %ecx
.LBB0_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_3 Depth 2
	leaq	-1(%rcx), %r8
	movq	%r8, %rsi
.LBB0_3:                                #   Parent Loop BB0_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%rdx,%rsi,4), %esi
	testl	%esi, %esi
	js	.LBB0_5
# %bb.4:                                #   in Loop: Header=BB0_3 Depth=2
	movb	(%rdi,%rsi), %r9b
	cmpb	(%rdi,%r8), %r9b
	jne	.LBB0_3
.LBB0_5:                                #   in Loop: Header=BB0_2 Depth=1
	incl	%esi
	movl	%esi, (%rdx,%rcx,4)
	incq	%rcx
	cmpq	%rax, %rcx
	jne	.LBB0_2
.LBB0_6:                                # %._crit_edge
	retq
.Lfunc_end0:
	.size	_Z19preprocesamientoKMPPciPi, .Lfunc_end0-_Z19preprocesamientoKMPPciPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z18__device_stub__KMPPcS_PiS0_ii # -- Begin function _Z18__device_stub__KMPPcS_PiS0_ii
	.type	_Z18__device_stub__KMPPcS_PiS0_ii,@function
_Z18__device_stub__KMPPcS_PiS0_ii:      # @_Z18__device_stub__KMPPcS_PiS0_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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	12(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	8(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	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	$_Z3KMPPcS_PiS0_ii, %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	_Z18__device_stub__KMPPcS_PiS0_ii, .Lfunc_end1-_Z18__device_stub__KMPPcS_PiS0_ii
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %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	$1656, %rsp                     # imm = 0x678
	.cfi_def_cfa_offset 1712
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	$2000000, %edi                  # imm = 0x1E8480
	callq	malloc
	movq	%rax, %rbp
	movl	$160000000, %edi                # imm = 0x9896800
	callq	malloc
	movq	%rax, %r13
	leaq	624(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev
.Ltmp0:
	leaq	104(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev
.Ltmp1:
# %bb.1:
.Ltmp3:
	leaq	1144(%rsp), %rdi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1Ev
.Ltmp4:
# %bb.2:
	movq	8(%rbx), %rsi
.Ltmp6:
	leaq	624(%rsp), %rdi
	movl	$8, %edx
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode
.Ltmp7:
# %bb.3:
	movq	16(%rbx), %rsi
.Ltmp8:
	leaq	104(%rsp), %rdi
	movl	$8, %edx
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode
.Ltmp9:
# %bb.4:
.Ltmp10:
	leaq	1144(%rsp), %rdi
	movl	$.L.str, %esi
	movl	$16, %edx
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode
.Ltmp11:
# %bb.5:
	leaq	624(%rsp), %rdi
	movq	(%rdi), %rax
	movq	-24(%rax), %rax
	movq	640(%rsp,%rax), %rbx
.Ltmp12:
	movl	$2000000, %edx                  # imm = 0x1E8480
	movq	%rbp, %rsi
	callq	_ZSt17__istream_extractRSiPcl
.Ltmp13:
# %bb.6:                                # %.noexc83
	movq	624(%rsp), %rax
	movq	-24(%rax), %rax
	cmpl	$0, 656(%rsp,%rax)
	jne	.LBB2_12
# %bb.7:                                # %.noexc83
	addq	$-2000001, %rbx                 # imm = 0xFFE17B7F
	cmpq	$-2000001, %rbx                 # imm = 0xFFE17B7F
	ja	.LBB2_12
# %bb.8:
	movq	856(%rsp,%rax), %rdi
	movq	16(%rdi), %rax
	cmpq	24(%rdi), %rax
	jae	.LBB2_9
.LBB2_12:                               # %_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_.exit
	leaq	104(%rsp), %rdi
	movq	(%rdi), %rax
	movq	-24(%rax), %rax
	movq	120(%rsp,%rax), %rbx
.Ltmp18:
	movl	$160000000, %edx                # imm = 0x9896800
	movq	%r13, %rsi
	callq	_ZSt17__istream_extractRSiPcl
.Ltmp19:
# %bb.13:                               # %.noexc90
	movq	104(%rsp), %rax
	movq	-24(%rax), %rax
	cmpl	$0, 136(%rsp,%rax)
	jne	.LBB2_19
# %bb.14:                               # %.noexc90
	addq	$-160000001, %rbx               # imm = 0xF67697FF
	cmpq	$-160000001, %rbx               # imm = 0xF67697FF
	ja	.LBB2_19
# %bb.15:
	movq	336(%rsp,%rax), %rdi
	movq	16(%rdi), %rax
	cmpq	24(%rdi), %rax
	jae	.LBB2_16
.LBB2_19:                               # %_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_.exit94
	movq	%rbp, %rdi
	callq	strlen
	movq	%rax, %r12
	movq	%r13, %rdi
	callq	strlen
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movq	%r12, %rax
	shlq	$32, %rax
	movq	%rax, %rcx
	sarq	$30, %rcx
	testq	%rax, %rax
	movq	$-1, %rbx
	cmovnsq	%rcx, %rbx
.Ltmp25:
	movq	%rbx, %rdi
	callq	_Znam
.Ltmp26:
# %bb.20:
.Ltmp27:
	movq	%rax, %r14
	movq	%rbx, %rdi
	callq	_Znam
.Ltmp28:
# %bb.21:
	movq	%rax, %r15
	movq	%rbp, 8(%rsp)                   # 8-byte Spill
	testl	%r12d, %r12d
	jle	.LBB2_23
# %bb.22:                               # %.lr.ph.preheader
	movl	%r12d, %edx
	shlq	$2, %rdx
	movq	%r15, %rdi
	movl	$255, %esi
	callq	memset@PLT
.LBB2_23:                               # %._crit_edge
	movl	%r12d, %eax
	cltd
	idivl	16(%rsp)                        # 4-byte Folded Reload
                                        # kill: def $eax killed $eax def $rax
	leal	1024(%rax), %ecx
	addl	$2047, %eax                     # imm = 0x7FF
	testl	%ecx, %ecx
	cmovnsl	%ecx, %eax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movl	$.Lstr, %edi
	callq	puts@PLT
.Ltmp30:
	leaq	96(%rsp), %rdi
	callq	hipEventCreate
.Ltmp31:
# %bb.24:
.Ltmp32:
	leaq	48(%rsp), %rdi
	callq	hipEventCreate
.Ltmp33:
# %bb.25:
.Ltmp34:
	leaq	88(%rsp), %rdi
	callq	hipEventCreate
.Ltmp35:
# %bb.26:
.Ltmp36:
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
.Ltmp37:
# %bb.27:
	movl	$-1, (%r14)
	cmpl	$2, %r12d
	jl	.LBB2_33
# %bb.28:                               # %.lr.ph.preheader.i
	movl	%r12d, %eax
	movl	$1, %ecx
.LBB2_29:                               # %.lr.ph.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_30 Depth 2
	leaq	-1(%rcx), %rsi
	movq	%rsi, %rdx
.LBB2_30:                               #   Parent Loop BB2_29 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r14,%rdx,4), %edx
	testl	%edx, %edx
	js	.LBB2_32
# %bb.31:                               #   in Loop: Header=BB2_30 Depth=2
	movb	(%r13,%rdx), %dil
	cmpb	(%r13,%rsi), %dil
	jne	.LBB2_30
.LBB2_32:                               #   in Loop: Header=BB2_29 Depth=1
	incl	%edx
	movl	%edx, (%r14,%rcx,4)
	incq	%rcx
	cmpq	%rax, %rcx
	jne	.LBB2_29
.LBB2_33:                               # %_Z19preprocesamientoKMPPciPi.exit
	movq	96(%rsp), %rdi
.Ltmp38:
	xorl	%esi, %esi
	callq	hipEventRecord
.Ltmp39:
# %bb.34:
	leal	(,%r12,4), %eax
	movslq	%eax, %rbp
.Ltmp40:
	leaq	72(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
.Ltmp41:
# %bb.35:
	movq	16(%rsp), %rax                  # 8-byte Reload
	leal	(,%rax,4), %eax
	movslq	%eax, %rbx
.Ltmp42:
	leaq	64(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
.Ltmp43:
# %bb.36:
.Ltmp44:
	leaq	56(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
.Ltmp45:
# %bb.37:
.Ltmp46:
	leaq	24(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
.Ltmp47:
# %bb.38:
	movq	72(%rsp), %rdi
.Ltmp48:
	movq	8(%rsp), %rsi                   # 8-byte Reload
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
.Ltmp49:
# %bb.39:
	movq	64(%rsp), %rdi
.Ltmp50:
	movq	%r13, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
.Ltmp51:
# %bb.40:
	movq	56(%rsp), %rdi
.Ltmp52:
	movq	%r14, %rsi
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
.Ltmp53:
# %bb.41:
	movq	24(%rsp), %rdi
.Ltmp54:
	movq	%r15, %rsi
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
.Ltmp55:
# %bb.42:
	movq	88(%rsp), %rdi
.Ltmp56:
	xorl	%esi, %esi
	callq	hipEventRecord
.Ltmp57:
# %bb.43:
	movq	32(%rsp), %rax                  # 8-byte Reload
	sarl	$10, %eax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movl	%eax, %edi
	btsq	$32, %rdi
.Ltmp58:
	movabsq	$4294968320, %rdx               # imm = 0x100000400
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
.Ltmp59:
# %bb.44:
	testl	%eax, %eax
	jne	.LBB2_46
# %bb.45:
	movq	64(%rsp), %rdi
	movq	72(%rsp), %rsi
	movq	56(%rsp), %rdx
	movq	24(%rsp), %rcx
.Ltmp60:
	movq	16(%rsp), %r8                   # 8-byte Reload
                                        # kill: def $r8d killed $r8d killed $r8
	movl	%r12d, %r9d
	callq	_Z18__device_stub__KMPPcS_PiS0_ii
.Ltmp61:
.LBB2_46:
	movq	40(%rsp), %rdi
.Ltmp62:
	xorl	%esi, %esi
	callq	hipEventRecord
.Ltmp63:
# %bb.47:
	movq	24(%rsp), %rsi
.Ltmp64:
	movq	%r15, %rdi
	movq	%rbp, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
.Ltmp65:
# %bb.48:
	movq	72(%rsp), %rdi
.Ltmp66:
	callq	hipFree
.Ltmp67:
# %bb.49:
	movq	64(%rsp), %rdi
.Ltmp68:
	callq	hipFree
.Ltmp69:
# %bb.50:
	movq	56(%rsp), %rdi
.Ltmp70:
	callq	hipFree
.Ltmp71:
# %bb.51:
	movq	24(%rsp), %rdi
.Ltmp72:
	callq	hipFree
.Ltmp73:
# %bb.52:
	movq	48(%rsp), %rdi
.Ltmp74:
	xorl	%esi, %esi
	callq	hipEventRecord
.Ltmp75:
# %bb.53:
	movq	48(%rsp), %rdi
.Ltmp77:
	callq	hipEventSynchronize
.Ltmp78:
# %bb.54:
	movq	40(%rsp), %rdi
.Ltmp79:
	callq	hipEventSynchronize
.Ltmp80:
# %bb.55:
	movq	96(%rsp), %rsi
	movq	48(%rsp), %rdx
.Ltmp81:
	leaq	84(%rsp), %rdi
	callq	hipEventElapsedTime
.Ltmp82:
# %bb.56:
	movq	88(%rsp), %rsi
	movq	40(%rsp), %rdx
.Ltmp83:
	leaq	80(%rsp), %rdi
	callq	hipEventElapsedTime
.Ltmp84:
# %bb.57:                               # %.preheader
	movq	%r12, 8(%rsp)                   # 8-byte Spill
	testl	%r12d, %r12d
	jle	.LBB2_73
# %bb.58:                               # %.lr.ph106.preheader
	movl	8(%rsp), %r12d                  # 4-byte Reload
	xorl	%r14d, %r14d
	leaq	1144(%rsp), %r13
	leaq	7(%rsp), %rbp
.LBB2_59:                               # %.lr.ph106
                                        # =>This Inner Loop Header: Depth=1
	cmpl	$-1, (%r15,%r14,4)
	je	.LBB2_72
# %bb.60:                               #   in Loop: Header=BB2_59 Depth=1
.Ltmp86:
	movl	$.L.str.2, %esi
	movl	$10, %edx
	movq	%r13, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp87:
# %bb.61:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
                                        #   in Loop: Header=BB2_59 Depth=1
.Ltmp88:
	movq	%r13, %rdi
	movl	%r14d, %esi
	callq	_ZNSolsEi
.Ltmp89:
# %bb.62:                               #   in Loop: Header=BB2_59 Depth=1
.Ltmp90:
	movq	%rax, %rbx
	movl	$.L.str.3, %esi
	movl	$8, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp91:
# %bb.63:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit97
                                        #   in Loop: Header=BB2_59 Depth=1
	movl	(%r15,%r14,4), %esi
.Ltmp92:
	movq	%rbx, %rdi
	callq	_ZNSolsEi
.Ltmp93:
# %bb.64:                               #   in Loop: Header=BB2_59 Depth=1
	movb	$10, 7(%rsp)
	movq	(%rax), %rcx
	movq	-24(%rcx), %rcx
	cmpq	$0, 16(%rax,%rcx)
	je	.LBB2_71
# %bb.65:                               #   in Loop: Header=BB2_59 Depth=1
.Ltmp94:
	movl	$1, %edx
	movq	%rax, %rdi
	movq	%rbp, %rsi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp95:
	jmp	.LBB2_72
.LBB2_71:                               #   in Loop: Header=BB2_59 Depth=1
.Ltmp96:
	movq	%rax, %rdi
	movl	$10, %esi
	callq	_ZNSo3putEc
.Ltmp97:
.LBB2_72:                               #   in Loop: Header=BB2_59 Depth=1
	incq	%r14
	cmpq	%r14, %r12
	jne	.LBB2_59
.LBB2_73:                               # %._crit_edge107
	movl	$.L.str.4, %edi
	movq	32(%rsp), %rsi                  # 8-byte Reload
                                        # kill: def $esi killed $esi killed $rsi
	movl	$1024, %edx                     # imm = 0x400
	movq	16(%rsp), %rcx                  # 8-byte Reload
                                        # kill: def $ecx killed $ecx killed $rcx
	movq	8(%rsp), %r8                    # 8-byte Reload
                                        # kill: def $r8d killed $r8d killed $r8
	xorl	%eax, %eax
	callq	printf
	cvtss2sd	84(%rsp), %xmm0
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	80(%rsp), %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	movq	_ZTTSt14basic_ofstreamIcSt11char_traitsIcEE(%rip), %rax
	leaq	1152(%rsp), %rdi
	movq	%rax, -8(%rdi)
	movq	_ZTTSt14basic_ofstreamIcSt11char_traitsIcEE+24(%rip), %rcx
	movq	-24(%rax), %rax
	movq	%rcx, 1144(%rsp,%rax)
	callq	_ZNSt13basic_filebufIcSt11char_traitsIcEED2Ev
	leaq	1392(%rsp), %rdi
	callq	_ZNSt8ios_baseD2Ev
	leaq	104(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	leaq	624(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	xorl	%eax, %eax
	addq	$1656, %rsp                     # imm = 0x678
	.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_9:                                # %_ZNSt15basic_streambufIcSt11char_traitsIcEE5sgetcEv.exit.i
	.cfi_def_cfa_offset 1712
	movq	(%rdi), %rax
.Ltmp14:
	callq	*72(%rax)
.Ltmp15:
# %bb.10:                               # %.noexc84
	cmpl	$-1, %eax
	jne	.LBB2_12
# %bb.11:
	movq	624(%rsp), %rax
	movq	-24(%rax), %rax
	leaq	(%rsp,%rax), %rdi
	addq	$624, %rdi                      # imm = 0x270
	movl	32(%rdi), %esi
	orl	$2, %esi
.Ltmp16:
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.Ltmp17:
	jmp	.LBB2_12
.LBB2_16:                               # %_ZNSt15basic_streambufIcSt11char_traitsIcEE5sgetcEv.exit.i88
	movq	(%rdi), %rax
.Ltmp20:
	callq	*72(%rax)
.Ltmp21:
# %bb.17:                               # %.noexc91
	cmpl	$-1, %eax
	jne	.LBB2_19
# %bb.18:
	movq	104(%rsp), %rax
	movq	-24(%rax), %rax
	leaq	(%rsp,%rax), %rdi
	addq	$104, %rdi
	movl	32(%rdi), %esi
	orl	$2, %esi
.Ltmp22:
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.Ltmp23:
	jmp	.LBB2_19
.LBB2_67:
.Ltmp5:
	movq	%rax, %rbx
	jmp	.LBB2_76
.LBB2_66:
.Ltmp2:
	movq	%rax, %rbx
	jmp	.LBB2_77
.LBB2_69:
.Ltmp29:
	jmp	.LBB2_75
.LBB2_74:
.Ltmp85:
	jmp	.LBB2_75
.LBB2_68:
.Ltmp24:
	jmp	.LBB2_75
.LBB2_70:
.Ltmp76:
	jmp	.LBB2_75
.LBB2_78:
.Ltmp98:
.LBB2_75:
	movq	%rax, %rbx
	leaq	1144(%rsp), %rdi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev
.LBB2_76:
	leaq	104(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
.LBB2_77:
	leaq	624(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table2:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp2-.Lfunc_begin0           #     jumps to .Ltmp2
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp3-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp4-.Ltmp3                  #   Call between .Ltmp3 and .Ltmp4
	.uleb128 .Ltmp5-.Lfunc_begin0           #     jumps to .Ltmp5
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp6-.Lfunc_begin0           # >> Call Site 4 <<
	.uleb128 .Ltmp19-.Ltmp6                 #   Call between .Ltmp6 and .Ltmp19
	.uleb128 .Ltmp24-.Lfunc_begin0          #     jumps to .Ltmp24
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp25-.Lfunc_begin0          # >> Call Site 5 <<
	.uleb128 .Ltmp28-.Ltmp25                #   Call between .Ltmp25 and .Ltmp28
	.uleb128 .Ltmp29-.Lfunc_begin0          #     jumps to .Ltmp29
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp28-.Lfunc_begin0          # >> Call Site 6 <<
	.uleb128 .Ltmp30-.Ltmp28                #   Call between .Ltmp28 and .Ltmp30
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp30-.Lfunc_begin0          # >> Call Site 7 <<
	.uleb128 .Ltmp75-.Ltmp30                #   Call between .Ltmp30 and .Ltmp75
	.uleb128 .Ltmp76-.Lfunc_begin0          #     jumps to .Ltmp76
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp77-.Lfunc_begin0          # >> Call Site 8 <<
	.uleb128 .Ltmp84-.Ltmp77                #   Call between .Ltmp77 and .Ltmp84
	.uleb128 .Ltmp85-.Lfunc_begin0          #     jumps to .Ltmp85
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp86-.Lfunc_begin0          # >> Call Site 9 <<
	.uleb128 .Ltmp97-.Ltmp86                #   Call between .Ltmp86 and .Ltmp97
	.uleb128 .Ltmp98-.Lfunc_begin0          #     jumps to .Ltmp98
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp14-.Lfunc_begin0          # >> Call Site 10 <<
	.uleb128 .Ltmp23-.Ltmp14                #   Call between .Ltmp14 and .Ltmp23
	.uleb128 .Ltmp24-.Lfunc_begin0          #     jumps to .Ltmp24
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp23-.Lfunc_begin0          # >> Call Site 11 <<
	.uleb128 .Lfunc_end2-.Ltmp23            #   Call between .Ltmp23 and .Lfunc_end2
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z3KMPPcS_PiS0_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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB4_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z3KMPPcS_PiS0_ii,@object       # @_Z3KMPPcS_PiS0_ii
	.section	.rodata,"a",@progbits
	.globl	_Z3KMPPcS_PiS0_ii
	.p2align	3, 0x0
_Z3KMPPcS_PiS0_ii:
	.quad	_Z18__device_stub__KMPPcS_PiS0_ii
	.size	_Z3KMPPcS_PiS0_ii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"DATA/result.txt"
	.size	.L.str, 16

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

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"\tmatch: "
	.size	.L.str.3, 9

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Blocks: %i Threads: %i n: %i m:%i\n"
	.size	.L.str.4, 35

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Tiempo ejecucion: %1.15f ml.\n"
	.size	.L.str.5, 30

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Tiempo ejecucion kernel: %1.15f ml.\n"
	.size	.L.str.6, 37

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z3KMPPcS_PiS0_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	"Copiando datos a GPU"
	.size	.Lstr, 21

	.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 _Z18__device_stub__KMPPcS_PiS0_ii
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z3KMPPcS_PiS0_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z3KMPPcS_PiS0_ii       ; -- Begin function _Z3KMPPcS_PiS0_ii
	.globl	_Z3KMPPcS_PiS0_ii
	.p2align	8
	.type	_Z3KMPPcS_PiS0_ii,@function
_Z3KMPPcS_PiS0_ii:                      ; @_Z3KMPPcS_PiS0_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b64 s[8:9], s[0:1], 0x20
	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_mov_b32 s2, exec_lo
	v_mul_lo_u32 v4, v1, s8
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_ge_i32_e64 s9, v4
	s_cbranch_execz .LBB0_14
; %bb.1:
	s_lshl_b32 s2, s8, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add3_u32 v0, v4, s2, -1
	v_min_i32_e32 v3, s9, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_lt_i32_e32 vcc_lo, v4, v3
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_14
; %bb.2:                                ; %.lr.ph.preheader
	s_load_b256 s[0:7], s[0:1], 0x0
	v_mov_b32_e32 v0, 0
	s_ashr_i32 s9, s8, 31
	s_mov_b32 s10, 0
	s_waitcnt lgkmcnt(0)
	s_add_u32 s6, s6, 4
	s_addc_u32 s7, s7, 0
.LBB0_3:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s11, exec_lo
	v_cmpx_ne_u32_e32 -1, v0
	s_xor_b32 s11, exec_lo, s11
	s_cbranch_execz .LBB0_11
; %bb.4:                                ;   in Loop: Header=BB0_3 Depth=1
	v_ashrrev_i32_e32 v2, 31, v4
	v_ashrrev_i32_e32 v1, 31, v0
	v_add_co_u32 v5, vcc_lo, s2, v4
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_add_co_ci_u32_e32 v6, vcc_lo, s3, v2, vcc_lo
	v_add_co_u32 v7, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v8, vcc_lo, s1, v1, vcc_lo
	global_load_u8 v5, v[5:6], off
	global_load_u8 v6, v[7:8], off
	s_waitcnt vmcnt(0)
	v_cmp_ne_u16_e32 vcc_lo, v5, v6
                                        ; implicit-def: $vgpr5
	s_and_saveexec_b32 s12, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s12, exec_lo, s12
	s_cbranch_execz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_3 Depth=1
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	global_load_b32 v5, v[0:1], off
                                        ; implicit-def: $vgpr0
                                        ; implicit-def: $vgpr1_vgpr2
.LBB0_6:                                ; %Flow61
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_and_not1_saveexec_b32 s12, s12
	s_cbranch_execz .LBB0_10
; %bb.7:                                ;   in Loop: Header=BB0_3 Depth=1
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v5, 1, v0
	v_add_nc_u32_e32 v1, 1, v4
	s_mov_b32 s13, exec_lo
	s_delay_alu instid0(VALU_DEP_2)
	v_cmpx_eq_u32_e64 s8, v5
	s_cbranch_execz .LBB0_9
; %bb.8:                                ;   in Loop: Header=BB0_3 Depth=1
	v_sub_co_u32 v4, vcc_lo, v4, s8
	v_subrev_co_ci_u32_e32 v5, vcc_lo, s9, v2, vcc_lo
	v_sub_nc_u32_e32 v0, v1, v0
	v_subrev_nc_u32_e32 v2, s8, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	v_mov_b32_e32 v1, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v6, vcc_lo, s6, v4
	v_add_co_ci_u32_e32 v7, vcc_lo, s7, v5, vcc_lo
	v_mov_b32_e32 v5, s8
	global_store_b32 v[6:7], v2, off
.LBB0_9:                                ; %Flow
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s13
	v_mov_b32_e32 v4, v1
.LBB0_10:                               ; %Flow62
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s12
	s_waitcnt vmcnt(0)
	v_mov_b32_e32 v0, v5
.LBB0_11:                               ; %Flow63
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_and_not1_saveexec_b32 s11, s11
; %bb.12:                               ;   in Loop: Header=BB0_3 Depth=1
	v_add_nc_u32_e32 v4, 1, v4
	v_mov_b32_e32 v0, 0
; %bb.13:                               ;   in Loop: Header=BB0_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s11
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_ge_i32_e32 vcc_lo, v4, v3
	s_or_b32 s10, vcc_lo, s10
	s_and_not1_b32 exec_lo, exec_lo, s10
	s_cbranch_execnz .LBB0_3
.LBB0_14:                               ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z3KMPPcS_PiS0_ii
		.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 9
		.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	_Z3KMPPcS_PiS0_ii, .Lfunc_end0-_Z3KMPPcS_PiS0_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 436
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; 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
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         36
        .size:           4
        .value_kind:     by_value
      - .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:           _Z3KMPPcS_PiS0_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z3KMPPcS_PiS0_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
