////////////////////////////////////////////////////////////
//Ho Thien Luan -> History Tracking!
// 1. multi_pat_asm_naive_cpu.cu 
// 2. 
//
//
//
////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <cuda_runtime.h>
//#include "cuPrintf.cu"


#define FILENAME_MAXLEN     256
#define THREAD_BLOCK_EXP   (7)
#define THREAD_BLOCK_SIZE  (1 << THREAD_BLOCK_EXP)

__global__ void ASM_kernel(char *g_input_string, int input_size, int *g_pattern_table, int pattern_length, int no_of_patterns, int *g_matched_result)
{
    int tid  = threadIdx.x ;
    int gbid = blockIdx.y * gridDim.x + blockIdx.x ;
    int start = gbid*THREAD_BLOCK_SIZE + tid;
    int max_pattern_length = pattern_length +1; 
    int result;

  if (start < (input_size-pattern_length+1)) {

    for (int j = 0; j < no_of_patterns; j++) {
      result = 0;
      for (int i = 0; i<pattern_length ; i++) {

        if ((g_input_string[ start + i ] != '\n') & (g_input_string[ start + i ] != g_pattern_table[j*max_pattern_length+i])) {
	    result ++;
	    //g_matched_result[start*no_of_patterns + j] = g_matched_result[start*no_of_patterns + j] + 1;
        }
      }
      g_matched_result[start*no_of_patterns + j] = result;
    }
  }
    //cuPrintf("threadIdx.x = %d \t bit_vector = %d \n", start, bit_vector);
}

////////////////////////////////
void ASM_process_top (char *g_input_string, size_t input_size,  int *g_pattern_table, int pattern_length, int no_of_patterns, int *g_matched_result)
{

    // num_blocks = # of thread blocks to cover input stream
    int num_blocks = (input_size-pattern_length+1)/THREAD_BLOCK_SIZE + 1 ;


        dim3  dimBlock( THREAD_BLOCK_SIZE, 1 ) ;
        dim3  dimGrid ;

        int p = num_blocks >> 15 ;
        dimGrid.x = num_blocks ;
        if ( p ){
            dimGrid.x = 1<<15 ;
            dimGrid.y = p+1 ;
        }
    //cudaPrintfInit();////for cuPrintf

    ASM_kernel <<< dimGrid, dimBlock >>>((char*)g_input_string, input_size, (int*) g_pattern_table, pattern_length, no_of_patterns, g_matched_result);

    //cudaPrintfDisplay();////for cuPrintf
    //cudaPrintfEnd();        ////for cuPrintf
}

int main(int argc, char **argv)
{
    char inputFile[FILENAME_MAXLEN];
    char patternFile[FILENAME_MAXLEN];
    strcpy( inputFile, argv[2]) ;
    strcpy( patternFile, argv[1]) ;
    //int k_par = 4;
    int k_par;
    k_par = strtol(argv[3], NULL, 10);
////////////////////////////////////////////////////////////////////////////////////
//Process input patterns
    int pattern_size;
    char *h_pattern = NULL ;
    int len;

    size_t  sizeOfTableEntry ;
    int  sizeOfTableInBytes ; // numOfTableEntry * sizeOfTableEntry
    size_t  sizeOfPatternInBytes ; // no_of_patterns * sizeOfTableEntry

    int max_pattern_length = 0;
    int no_of_patterns = 0;

    FILE* fpattern = fopen( patternFile, "rb");
    assert ( NULL != fpattern ) ;
    // obtain pattern file
    fseek (fpattern , 0 , SEEK_END);
    pattern_size = ftell (fpattern);
    rewind (fpattern);

    // allocate a buffer to contains all patterns
    h_pattern = (char *) malloc (sizeof(char)*pattern_size);
    assert( NULL != h_pattern );

    // copy the file into the buffer
    pattern_size = fread (h_pattern, 1, pattern_size, fpattern);
    fclose(fpattern);
    //printf ("pattern size = %d\n",pattern_size); 
    //printf ("pattern = %s\n",h_pattern); 
    //Processing to get max_pattern_length & no_of_patterns
    len = 0;
    for( int i = 0 ; i < pattern_size ; i++){
        if ( '\n' == h_pattern[i] ){
            if ( (i > 0) && ('\n' != h_pattern[i-1]) ){ // non-empty line
		no_of_patterns = no_of_patterns + 1;	
		if (max_pattern_length < len+1) {max_pattern_length = len+1;}
            }
            len = 0 ;
        }else{
            len++ ;
        }
    }

   // Create pattern_table, pattern_length_table
    sizeOfTableEntry = sizeof(int) ;
    sizeOfPatternInBytes = no_of_patterns * sizeOfTableEntry; // 1-D to store size of each patterns
    sizeOfTableInBytes = no_of_patterns * max_pattern_length; //2-D to store patterns

    int* pattern_table = (int*) malloc( sizeof(int)*sizeOfTableInBytes ) ;
    int* pattern_length_table = (int*) malloc( sizeOfPatternInBytes ) ;

    //Processing to fill pattern_table & pattern_length_table 
    len = 0;
    int no_patterns = 0;
    for( int i = 0 ; i < pattern_size ; i++){
        if ( '\n' == h_pattern[i] ){
            if ( (i > 0) && ('\n' != h_pattern[i-1]) ){ // non-empty line
		pattern_length_table[no_patterns] = len;
		no_patterns = no_patterns + 1;	
            }
            len = 0 ;
        }else{
	    pattern_table[no_patterns*max_pattern_length + len] = h_pattern[i]; 	
            len++ ;
        }
    }
   //Print to pattern_table/pattern_length_table to check
/*
    for (int i = 0; i < no_of_patterns; i++) {
	printf("\npattern no %d has length = %d-> ",i, pattern_length_table[i]);
	for (int j = 0; j < pattern_length_table[i]; j++) {
	    printf("%4d",pattern_table[i*max_pattern_length+j]);
	}
    }
*/
///////////////////////////////////////////////////////////////
//Prepare input string
    int input_size;
    char *h_input_string = NULL ;
    int  *h_matched_result = NULL ;

    //open to read file
    FILE* fpin = fopen( inputFile, "rb");
    assert ( NULL != fpin ) ;
    
    // sets the file position of the stream to the given offset. 
    fseek (fpin , 0 , SEEK_END);
    input_size = ftell (fpin);
    rewind (fpin);
    
    // allocate memory to contain the whole file
    h_input_string = (char *) malloc (sizeof(char)*input_size);
    assert( NULL != h_input_string );

    int size_matched_result = input_size * no_of_patterns;
    h_matched_result = (int *) malloc (sizeof(int)*size_matched_result); // each input has no_of_patterns results
    assert( NULL != h_matched_result );
    memset( h_matched_result, 0, size_matched_result ) ;

    // copy the file into the buffer
    input_size = fread (h_input_string, 1, input_size, fpin);
    fclose(fpin);

    //////////////////
    //printf("\ninput size -> %4d -> \n",input_size);
   // printf("%s\n",h_input_string);
/*
    //AmSM with Naive Method in CPU
    
    struct timespec t_start, t_end;
    double elapsedTime;
    clock_gettime (CLOCK_REALTIME, &t_start);
    //printf ("starttime s = %li, ns = %li\n",t_start.tv_sec, t_start.tv_nsec);

    for(int i = 0; i < input_size-max_pattern_length+1; i++) {
	for (int j = 0; j < no_of_patterns; j++) { 
	h_matched_result[i*no_of_patterns+j] = 0;
	    for (int k = 0; k < pattern_length_table[j]; k++) {
		if ((h_input_string[i+k] != '\n') & (h_input_string[i+k] != pattern_table[j*max_pattern_length+k])) {
		    h_matched_result[i*no_of_patterns+j] = h_matched_result[i*no_of_patterns+j] + 1;
		}
	    }
        }
    }

    clock_gettime(CLOCK_REALTIME, &t_end);
    //printf ("endtime s = %li, ns = %li\n",t_end.tv_sec, t_end.tv_nsec);
    elapsedTime = (t_end.tv_sec*1000+t_end.tv_nsec/1000000)-(t_start.tv_sec*1000+t_start.tv_nsec/1000000);
*/

    //AmSM with Naive Method in GPU
    char *g_input_string;
    //char *g_pattern;
    int *g_matched_result;
    int *g_pattern_table;

    cudaMalloc (&g_input_string, sizeof(char)*input_size);
    cudaMalloc (&g_matched_result, sizeof(int)*size_matched_result);
    cudaMalloc (&g_pattern_table, sizeof(int)*sizeOfTableInBytes);

    cudaMemcpy (g_input_string, h_input_string, sizeof(char)*input_size, cudaMemcpyHostToDevice );
    cudaMemcpy (g_pattern_table, pattern_table, sizeof(int)*sizeOfTableInBytes, cudaMemcpyHostToDevice);

    // record time setting
    cudaEvent_t start, stop;
    float time;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);
    cudaEventRecord(start, 0);


    // step 3: run ASM on GPU           
    ASM_process_top ( g_input_string, input_size, g_pattern_table, (max_pattern_length-1), no_of_patterns, g_matched_result) ;

    // record time setting
    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&time, start, stop);

    cudaMemcpy (h_matched_result, g_matched_result, sizeof(int)*size_matched_result, cudaMemcpyDeviceToHost );


    // Print Result
 int total_result = 0;
    for(int i = 0; i < input_size-max_pattern_length+1; i++) {
	for (int j = 0; j < no_of_patterns; j++) { 
	     //printf("Input location %d with pattern %d has Hamming distance = %d\n",i, j, h_matched_result[RESULT_TABLE_MAP(i,j)]);
	     if(h_matched_result[i*no_of_patterns+j] <= k_par) {total_result++;}
	    }
        }
    printf("\n\n\n");
    printf("###########################################################\n");
    printf("#--Multi Fix-Length Patterns Approximate String Matching--#\n");
    printf("#---------------------------------------------------------#\n");
    printf("#----------------Naive Approach in GPU--------------------#\n");
    printf("###########################################################\n");
    printf("#--No of Patterns            |\t\t %10d \t  #\n",no_of_patterns);
    printf("#---------------------------------------------------------#\n");
    printf("#--Pattern Length            |\t\t %10d \t  #\n",max_pattern_length-1);
    printf("#---------------------------------------------------------#\n");
    printf("#--Input Size (bytes)        |\t\t %10d \t  #\n", input_size );
    printf("#---------------------------------------------------------#\n");
    printf("#--Total matched with k = %d  |\t\t %10d \t  #\n", k_par, total_result);
    printf("#---------------------------------------------------------#\n");
    printf("#--Total elapsed time (ms)   |\t\t %10f \t  #\n", time);
    printf("#---------------------------------------------------------#\n");
    printf("#--Throughput Result (Gbps)  |\t\t %10f \t  #\n", (float)(input_size*8)/(time*1000000) );
    printf("###########################################################\n");

     
    free(h_pattern);
    free(h_input_string);
    free(h_matched_result); 
    free(pattern_table);
    free(pattern_length_table);
            
    return 0;
}

	.file	"tmpxft_00377ebb_00000000-6_2_Naive_GPU.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z38__device_stub__Z10ASM_kernelPciPiiiS0_PciPiiiS0_
	.type	_Z38__device_stub__Z10ASM_kernelPciPiiiS0_PciPiiiS0_, @function
_Z38__device_stub__Z10ASM_kernelPciPiiiS0_PciPiiiS0_:
.LFB2053:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movl	%esi, 36(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 32(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 20(%rsp)
	movq	%r9, 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	36(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	20(%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	.L2
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z10ASM_kernelPciPiiiS0_(%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
.L2:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z38__device_stub__Z10ASM_kernelPciPiiiS0_PciPiiiS0_, .-_Z38__device_stub__Z10ASM_kernelPciPiiiS0_PciPiiiS0_
	.globl	_Z10ASM_kernelPciPiiiS0_
	.type	_Z10ASM_kernelPciPiiiS0_, @function
_Z10ASM_kernelPciPiiiS0_:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z10ASM_kernelPciPiiiS0_PciPiiiS0_
	.cfi_endproc
.LFE2054:
	.size	_Z10ASM_kernelPciPiiiS0_, .-_Z10ASM_kernelPciPiiiS0_
	.globl	_Z15ASM_process_topPcmPiiiS0_
	.type	_Z15ASM_process_topPcmPiiiS0_, @function
_Z15ASM_process_topPcmPiiiS0_:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	1(%rsi), %rax
	movq	%rsi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%r9, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%r8d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdx, %r12
	movslq	%ecx, %rdx
	movabsq	$4294967297, %rcx
	subq	%rdx, %rax
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	movl	$33554433, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	shrq	$7, %rax
	movq	%rdx, %rbx
	salq	$7, %rdi
	incl	%eax
	movl	%eax, %edx
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	sarl	$15, %edx
	movq	%rdi, 8(%rsp)
	movl	$1, 16(%rsp)
	movq	%rcx, 24(%rsp)
	jne	.L9
	movl	%eax, 20(%rsp)
	jmp	.L10
.L9:
	leal	1(%rdx), %eax
	movl	$32768, 20(%rsp)
	movl	%eax, 24(%rsp)
.L10:
	movl	16(%rsp), %ecx
	movq	8(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	20(%rsp), %rdi
	movl	28(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movq	%r14, %r9
	movl	%r13d, %r8d
	movl	%ebx, %ecx
	movq	%r12, %rdx
	popq	%rbx
	.cfi_def_cfa_offset 48
	movl	%r15d, %esi
	movq	%rbp, %rdi
	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
	jmp	_Z38__device_stub__Z10ASM_kernelPciPiiiS0_PciPiiiS0_
.L8:
	.cfi_restore_state
	addq	$40, %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
.LFE2027:
	.size	_Z15ASM_process_topPcmPiiiS0_, .-_Z15ASM_process_topPcmPiiiS0_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"rb"
.LC1:
	.string	"\n\n\n"
.LC2:
	.string	"###########################################################\n"
.LC3:
	.string	"#--Multi Fix-Length Patterns Approximate String Matching--#\n"
.LC4:
	.string	"#---------------------------------------------------------#\n"
.LC5:
	.string	"#----------------Naive Approach in GPU--------------------#\n"
.LC6:
	.string	"#--No of Patterns            |\t\t %10d \t  #\n"
.LC7:
	.string	"#--Pattern Length            |\t\t %10d \t  #\n"
.LC8:
	.string	"#--Input Size (bytes)        |\t\t %10d \t  #\n"
.LC9:
	.string	"#--Total matched with k = %d  |\t\t %10d \t  #\n"
.LC10:
	.string	"#--Total elapsed time (ms)   |\t\t %10f \t  #\n"
.LC12:
	.string	"#--Throughput Result (Gbps)  |\t\t %10f \t  #\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$256, %edx
	xorl	%r15d, %r15d
	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	$648, %rsp
	.cfi_def_cfa_offset 704
	movq	16(%rsi), %rsi
	movq	%fs:40, %rax
	movq	%rax, 632(%rsp)
	xorl	%eax, %eax
	leaq	120(%rsp), %r14
	leaq	376(%rsp), %rbp
	movq	%r14, %rdi
	call	__strcpy_chk@PLT
	movq	8(%rbx), %rsi
	movq	%rbp, %rdi
	movl	$256, %edx
	call	__strcpy_chk@PLT
	movq	24(%rbx), %rdi
	movl	$10, %edx
	xorl	%esi, %esi
	call	__isoc23_strtol@PLT
	movq	%rbp, %rdi
	leaq	.LC0(%rip), %rsi
	movl	%eax, 52(%rsp)
	call	fopen@PLT
	movl	$2, %edx
	xorl	%esi, %esi
	movq	%rax, %rbx
	movq	%rax, %rdi
	call	fseek@PLT
	movq	%rbx, %rdi
	call	ftell@PLT
	movq	%rbx, %rdi
	movq	%rax, %rbp
	call	rewind@PLT
	movslq	%ebp, %rbp
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rbx, %r8
	movq	%rbp, %rcx
	movl	$1, %edx
	movq	%rbp, %rsi
	movq	%rax, %rdi
	movq	%rax, %r12
	call	__fread_chk@PLT
	movq	%rbx, %rdi
	xorl	%ebx, %ebx
	movl	%eax, %ebp
	call	fclose@PLT
	xorl	%edx, %edx
	xorl	%eax, %eax
.L14:
	cmpl	%edx, %ebp
	jle	.L34
	cmpb	$10, (%r12,%rdx)
	jne	.L15
	testq	%rdx, %rdx
	je	.L30
	cmpb	$10, -1(%r12,%rdx)
	je	.L30
	incl	%ebx
	cmpl	%r15d, %eax
	jl	.L30
	leal	1(%rax), %r15d
	jmp	.L30
.L15:
	incl	%eax
	jmp	.L16
.L30:
	xorl	%eax, %eax
.L16:
	incq	%rdx
	jmp	.L14
.L34:
	movl	%r15d, %r13d
	imull	%ebx, %r13d
	movslq	%r13d, %r13
	leaq	0(,%r13,4), %rax
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movslq	%ebx, %rdi
	salq	$2, %rdi
	movq	%rax, 24(%rsp)
	call	malloc@PLT
	xorl	%edx, %edx
	xorl	%esi, %esi
	movq	%rax, %r13
	xorl	%eax, %eax
.L18:
	cmpl	%edx, %ebp
	jle	.L35
	movsbl	(%r12,%rdx), %edi
	cmpb	$10, %dil
	jne	.L19
	testq	%rdx, %rdx
	je	.L32
	cmpb	$10, -1(%r12,%rdx)
	je	.L32
	movslq	%esi, %rcx
	incl	%esi
	movl	%eax, 0(%r13,%rcx,4)
	jmp	.L32
.L19:
	movl	%r15d, %ecx
	movq	24(%rsp), %r10
	imull	%esi, %ecx
	addl	%eax, %ecx
	incl	%eax
	movslq	%ecx, %rcx
	movl	%edi, (%r10,%rcx,4)
	jmp	.L20
.L32:
	xorl	%eax, %eax
.L20:
	incq	%rdx
	jmp	.L18
.L35:
	movq	%r14, %rdi
	leaq	.LC0(%rip), %rsi
	call	fopen@PLT
	xorl	%esi, %esi
	movl	$2, %edx
	movq	%rax, %r14
	movq	%rax, %rdi
	call	fseek@PLT
	movq	%r14, %rdi
	call	ftell@PLT
	movq	%r14, %rdi
	movq	%rax, %rbp
	call	rewind@PLT
	movslq	%ebp, %rax
	imull	%ebx, %ebp
	movq	%rax, %rdi
	movq	%rax, 40(%rsp)
	call	malloc@PLT
	movslq	%ebp, %rdx
	movq	%rax, 32(%rsp)
	leaq	0(,%rdx,4), %rbp
	movq	%rdx, 56(%rsp)
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	56(%rsp), %rdx
	movq	%rbp, %rcx
	xorl	%esi, %esi
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	__memset_chk@PLT
	movq	40(%rsp), %rcx
	movq	32(%rsp), %rdi
	movq	%r14, %r8
	movl	$1, %edx
	movq	%rcx, %rsi
	call	__fread_chk@PLT
	movq	%r14, %rdi
	movq	%rax, 40(%rsp)
	movl	40(%rsp), %eax
	movl	%eax, 56(%rsp)
	call	fclose@PLT
	movslq	40(%rsp), %r14
	leaq	80(%rsp), %rdi
	movq	%r14, %rsi
	call	cudaMalloc@PLT
	leaq	88(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rsi
	leaq	96(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	32(%rsp), %rsi
	movq	80(%rsp), %rdi
	movq	%r14, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdx
	movq	24(%rsp), %rsi
	movl	$1, %ecx
	movq	96(%rsp), %rdi
	call	cudaMemcpy@PLT
	leaq	104(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	112(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	104(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	88(%rsp), %r9
	movl	%ebx, %r8d
	movq	%r14, %rsi
	movq	96(%rsp), %rdx
	leal	-1(%r15), %eax
	movq	80(%rsp), %rdi
	xorl	%r14d, %r14d
	movl	%eax, %ecx
	movl	%eax, 16(%rsp)
	call	_Z15ASM_process_topPcmPiiiS0_
	movq	112(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	112(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	112(%rsp), %rdx
	movq	104(%rsp), %rsi
	leaq	76(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	8(%rsp), %rdi
	movq	88(%rsp), %rsi
	movq	%rbp, %rdx
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movl	56(%rsp), %edi
	xorl	%edx, %edx
	xorl	%ecx, %ecx
	subl	%r15d, %edi
.L22:
	cmpl	%ecx, %edi
	jl	.L25
	movq	8(%rsp), %rsi
	movslq	%edx, %rax
	leaq	(%rsi,%rax,4), %rsi
	xorl	%eax, %eax
.L26:
	cmpl	%eax, %ebx
	jle	.L36
	movl	52(%rsp), %r11d
	cmpl	%r11d, (%rsi,%rax,4)
	jg	.L23
	incl	%r14d
.L23:
	incq	%rax
	jmp	.L26
.L36:
	incl	%ecx
	addl	%ebx, %edx
	jmp	.L22
.L25:
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	.LC4(%rip), %rbp
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebx, %edx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	16(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC7(%rip), %rsi
	call	__printf_chk@PLT
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	56(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC8(%rip), %rsi
	call	__printf_chk@PLT
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	52(%rsp), %edx
	movl	%r14d, %ecx
	xorl	%eax, %eax
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	76(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	%rbp, %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	40(%rsp), %r15d
	movl	$2, %edi
	movb	$1, %al
	movss	.LC11(%rip), %xmm1
	mulss	76(%rsp), %xmm1
	leaq	.LC12(%rip), %rsi
	sall	$3, %r15d
	cvtsi2ssl	%r15d, %xmm0
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	32(%rsp), %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	632(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$648, %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
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC13:
	.string	"_Z10ASM_kernelPciPiiiS0_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2056:
	.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	.LC13(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z10ASM_kernelPciPiiiS0_(%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
.LFE2056:
	.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
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC11:
	.long	1232348160
	.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:

////////////////////////////////////////////////////////////
//Ho Thien Luan -> History Tracking!
// 1. multi_pat_asm_naive_cpu.cu 
// 2. 
//
//
//
////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <hip/hip_runtime.h>
//#include "cuPrintf.cu"


#define FILENAME_MAXLEN     256
#define THREAD_BLOCK_EXP   (7)
#define THREAD_BLOCK_SIZE  (1 << THREAD_BLOCK_EXP)

__global__ void ASM_kernel(char *g_input_string, int input_size, int *g_pattern_table, int pattern_length, int no_of_patterns, int *g_matched_result)
{
    int tid  = threadIdx.x ;
    int gbid = blockIdx.y * gridDim.x + blockIdx.x ;
    int start = gbid*THREAD_BLOCK_SIZE + tid;
    int max_pattern_length = pattern_length +1; 
    int result;

  if (start < (input_size-pattern_length+1)) {

    for (int j = 0; j < no_of_patterns; j++) {
      result = 0;
      for (int i = 0; i<pattern_length ; i++) {

        if ((g_input_string[ start + i ] != '\n') & (g_input_string[ start + i ] != g_pattern_table[j*max_pattern_length+i])) {
	    result ++;
	    //g_matched_result[start*no_of_patterns + j] = g_matched_result[start*no_of_patterns + j] + 1;
        }
      }
      g_matched_result[start*no_of_patterns + j] = result;
    }
  }
    //cuPrintf("threadIdx.x = %d \t bit_vector = %d \n", start, bit_vector);
}

////////////////////////////////
void ASM_process_top (char *g_input_string, size_t input_size,  int *g_pattern_table, int pattern_length, int no_of_patterns, int *g_matched_result)
{

    // num_blocks = # of thread blocks to cover input stream
    int num_blocks = (input_size-pattern_length+1)/THREAD_BLOCK_SIZE + 1 ;


        dim3  dimBlock( THREAD_BLOCK_SIZE, 1 ) ;
        dim3  dimGrid ;

        int p = num_blocks >> 15 ;
        dimGrid.x = num_blocks ;
        if ( p ){
            dimGrid.x = 1<<15 ;
            dimGrid.y = p+1 ;
        }
    //cudaPrintfInit();////for cuPrintf

    ASM_kernel <<< dimGrid, dimBlock >>>((char*)g_input_string, input_size, (int*) g_pattern_table, pattern_length, no_of_patterns, g_matched_result);

    //cudaPrintfDisplay();////for cuPrintf
    //cudaPrintfEnd();        ////for cuPrintf
}

int main(int argc, char **argv)
{
    char inputFile[FILENAME_MAXLEN];
    char patternFile[FILENAME_MAXLEN];
    strcpy( inputFile, argv[2]) ;
    strcpy( patternFile, argv[1]) ;
    //int k_par = 4;
    int k_par;
    k_par = strtol(argv[3], NULL, 10);
////////////////////////////////////////////////////////////////////////////////////
//Process input patterns
    int pattern_size;
    char *h_pattern = NULL ;
    int len;

    size_t  sizeOfTableEntry ;
    int  sizeOfTableInBytes ; // numOfTableEntry * sizeOfTableEntry
    size_t  sizeOfPatternInBytes ; // no_of_patterns * sizeOfTableEntry

    int max_pattern_length = 0;
    int no_of_patterns = 0;

    FILE* fpattern = fopen( patternFile, "rb");
    assert ( NULL != fpattern ) ;
    // obtain pattern file
    fseek (fpattern , 0 , SEEK_END);
    pattern_size = ftell (fpattern);
    rewind (fpattern);

    // allocate a buffer to contains all patterns
    h_pattern = (char *) malloc (sizeof(char)*pattern_size);
    assert( NULL != h_pattern );

    // copy the file into the buffer
    pattern_size = fread (h_pattern, 1, pattern_size, fpattern);
    fclose(fpattern);
    //printf ("pattern size = %d\n",pattern_size); 
    //printf ("pattern = %s\n",h_pattern); 
    //Processing to get max_pattern_length & no_of_patterns
    len = 0;
    for( int i = 0 ; i < pattern_size ; i++){
        if ( '\n' == h_pattern[i] ){
            if ( (i > 0) && ('\n' != h_pattern[i-1]) ){ // non-empty line
		no_of_patterns = no_of_patterns + 1;	
		if (max_pattern_length < len+1) {max_pattern_length = len+1;}
            }
            len = 0 ;
        }else{
            len++ ;
        }
    }

   // Create pattern_table, pattern_length_table
    sizeOfTableEntry = sizeof(int) ;
    sizeOfPatternInBytes = no_of_patterns * sizeOfTableEntry; // 1-D to store size of each patterns
    sizeOfTableInBytes = no_of_patterns * max_pattern_length; //2-D to store patterns

    int* pattern_table = (int*) malloc( sizeof(int)*sizeOfTableInBytes ) ;
    int* pattern_length_table = (int*) malloc( sizeOfPatternInBytes ) ;

    //Processing to fill pattern_table & pattern_length_table 
    len = 0;
    int no_patterns = 0;
    for( int i = 0 ; i < pattern_size ; i++){
        if ( '\n' == h_pattern[i] ){
            if ( (i > 0) && ('\n' != h_pattern[i-1]) ){ // non-empty line
		pattern_length_table[no_patterns] = len;
		no_patterns = no_patterns + 1;	
            }
            len = 0 ;
        }else{
	    pattern_table[no_patterns*max_pattern_length + len] = h_pattern[i]; 	
            len++ ;
        }
    }
   //Print to pattern_table/pattern_length_table to check
/*
    for (int i = 0; i < no_of_patterns; i++) {
	printf("\npattern no %d has length = %d-> ",i, pattern_length_table[i]);
	for (int j = 0; j < pattern_length_table[i]; j++) {
	    printf("%4d",pattern_table[i*max_pattern_length+j]);
	}
    }
*/
///////////////////////////////////////////////////////////////
//Prepare input string
    int input_size;
    char *h_input_string = NULL ;
    int  *h_matched_result = NULL ;

    //open to read file
    FILE* fpin = fopen( inputFile, "rb");
    assert ( NULL != fpin ) ;
    
    // sets the file position of the stream to the given offset. 
    fseek (fpin , 0 , SEEK_END);
    input_size = ftell (fpin);
    rewind (fpin);
    
    // allocate memory to contain the whole file
    h_input_string = (char *) malloc (sizeof(char)*input_size);
    assert( NULL != h_input_string );

    int size_matched_result = input_size * no_of_patterns;
    h_matched_result = (int *) malloc (sizeof(int)*size_matched_result); // each input has no_of_patterns results
    assert( NULL != h_matched_result );
    memset( h_matched_result, 0, size_matched_result ) ;

    // copy the file into the buffer
    input_size = fread (h_input_string, 1, input_size, fpin);
    fclose(fpin);

    //////////////////
    //printf("\ninput size -> %4d -> \n",input_size);
   // printf("%s\n",h_input_string);
/*
    //AmSM with Naive Method in CPU
    
    struct timespec t_start, t_end;
    double elapsedTime;
    clock_gettime (CLOCK_REALTIME, &t_start);
    //printf ("starttime s = %li, ns = %li\n",t_start.tv_sec, t_start.tv_nsec);

    for(int i = 0; i < input_size-max_pattern_length+1; i++) {
	for (int j = 0; j < no_of_patterns; j++) { 
	h_matched_result[i*no_of_patterns+j] = 0;
	    for (int k = 0; k < pattern_length_table[j]; k++) {
		if ((h_input_string[i+k] != '\n') & (h_input_string[i+k] != pattern_table[j*max_pattern_length+k])) {
		    h_matched_result[i*no_of_patterns+j] = h_matched_result[i*no_of_patterns+j] + 1;
		}
	    }
        }
    }

    clock_gettime(CLOCK_REALTIME, &t_end);
    //printf ("endtime s = %li, ns = %li\n",t_end.tv_sec, t_end.tv_nsec);
    elapsedTime = (t_end.tv_sec*1000+t_end.tv_nsec/1000000)-(t_start.tv_sec*1000+t_start.tv_nsec/1000000);
*/

    //AmSM with Naive Method in GPU
    char *g_input_string;
    //char *g_pattern;
    int *g_matched_result;
    int *g_pattern_table;

    hipMalloc (&g_input_string, sizeof(char)*input_size);
    hipMalloc (&g_matched_result, sizeof(int)*size_matched_result);
    hipMalloc (&g_pattern_table, sizeof(int)*sizeOfTableInBytes);

    hipMemcpy (g_input_string, h_input_string, sizeof(char)*input_size, hipMemcpyHostToDevice );
    hipMemcpy (g_pattern_table, pattern_table, sizeof(int)*sizeOfTableInBytes, hipMemcpyHostToDevice);

    // record time setting
    hipEvent_t start, stop;
    float time;
    hipEventCreate(&start);
    hipEventCreate(&stop);
    hipEventRecord(start, 0);


    // step 3: run ASM on GPU           
    ASM_process_top ( g_input_string, input_size, g_pattern_table, (max_pattern_length-1), no_of_patterns, g_matched_result) ;

    // record time setting
    hipEventRecord(stop, 0);
    hipEventSynchronize(stop);
    hipEventElapsedTime(&time, start, stop);

    hipMemcpy (h_matched_result, g_matched_result, sizeof(int)*size_matched_result, hipMemcpyDeviceToHost );


    // Print Result
 int total_result = 0;
    for(int i = 0; i < input_size-max_pattern_length+1; i++) {
	for (int j = 0; j < no_of_patterns; j++) { 
	     //printf("Input location %d with pattern %d has Hamming distance = %d\n",i, j, h_matched_result[RESULT_TABLE_MAP(i,j)]);
	     if(h_matched_result[i*no_of_patterns+j] <= k_par) {total_result++;}
	    }
        }
    printf("\n\n\n");
    printf("###########################################################\n");
    printf("#--Multi Fix-Length Patterns Approximate String Matching--#\n");
    printf("#---------------------------------------------------------#\n");
    printf("#----------------Naive Approach in GPU--------------------#\n");
    printf("###########################################################\n");
    printf("#--No of Patterns            |\t\t %10d \t  #\n",no_of_patterns);
    printf("#---------------------------------------------------------#\n");
    printf("#--Pattern Length            |\t\t %10d \t  #\n",max_pattern_length-1);
    printf("#---------------------------------------------------------#\n");
    printf("#--Input Size (bytes)        |\t\t %10d \t  #\n", input_size );
    printf("#---------------------------------------------------------#\n");
    printf("#--Total matched with k = %d  |\t\t %10d \t  #\n", k_par, total_result);
    printf("#---------------------------------------------------------#\n");
    printf("#--Total elapsed time (ms)   |\t\t %10f \t  #\n", time);
    printf("#---------------------------------------------------------#\n");
    printf("#--Throughput Result (Gbps)  |\t\t %10f \t  #\n", (float)(input_size*8)/(time*1000000) );
    printf("###########################################################\n");

     
    free(h_pattern);
    free(h_input_string);
    free(h_matched_result); 
    free(pattern_table);
    free(pattern_length_table);
            
    return 0;
}

	.text
	.file	"2_Naive_GPU.hip"
	.globl	_Z25__device_stub__ASM_kernelPciPiiiS0_ # -- Begin function _Z25__device_stub__ASM_kernelPciPiiiS0_
	.type	_Z25__device_stub__ASM_kernelPciPiiiS0_,@function
_Z25__device_stub__ASM_kernelPciPiiiS0_: # @_Z25__device_stub__ASM_kernelPciPiiiS0_
	.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	20(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	48(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	16(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	12(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	40(%rsp), %r8
	movq	%r9, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z10ASM_kernelPciPiiiS0_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z25__device_stub__ASM_kernelPciPiiiS0_, .Lfunc_end0-_Z25__device_stub__ASM_kernelPciPiiiS0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z15ASM_process_topPcmPiiiS0_   # -- Begin function _Z15ASM_process_topPcmPiiiS0_
	.type	_Z15ASM_process_topPcmPiiiS0_,@function
_Z15ASM_process_topPcmPiiiS0_:          # @_Z15ASM_process_topPcmPiiiS0_
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.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	%r9, %rbx
	movl	%r8d, %ebp
	movl	%ecx, %r14d
	movq	%rdx, %r15
	movq	%rsi, %r12
	movq	%rdi, %r13
	movslq	%ecx, %rax
	movq	%rsi, %rcx
	subq	%rax, %rcx
	incq	%rcx
	shrq	$7, %rcx
	incl	%ecx
	movq	%rcx, %rax
	btsq	$32, %rax
	movl	%ecx, %edi
	sarl	$15, %edi
	incl	%edi
	shlq	$32, %rdi
	orq	$32768, %rdi                    # imm = 0x8000
	cmpl	$32768, %ecx                    # imm = 0x8000
	cmovbq	%rax, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$128, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	je	.LBB1_2
# %bb.1:
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_2:
	.cfi_def_cfa_offset 64
	movq	%r13, %rdi
	movl	%r12d, %esi
	movq	%r15, %rdx
	movl	%r14d, %ecx
	movl	%ebp, %r8d
	movq	%rbx, %r9
	addq	$8, %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
	jmp	_Z25__device_stub__ASM_kernelPciPiiiS0_ # TAILCALL
.Lfunc_end1:
	.size	_Z15ASM_process_topPcmPiiiS0_, .Lfunc_end1-_Z15ASM_process_topPcmPiiiS0_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x49742400                      # float 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$648, %rsp                      # imm = 0x288
	.cfi_def_cfa_offset 704
	.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
	movq	16(%rsi), %rsi
	leaq	128(%rsp), %rdi
	callq	strcpy
	movq	8(%rbx), %rsi
	leaq	384(%rsp), %r12
	movq	%r12, %rdi
	callq	strcpy
	movq	24(%rbx), %rdi
	xorl	%r15d, %r15d
	xorl	%esi, %esi
	movl	$10, %edx
	callq	__isoc23_strtol
	movq	%rax, %r14
	movl	$.L.str, %esi
	movq	%r12, %rdi
	callq	fopen
	movq	%rax, %r12
	movq	%rax, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	fseek
	movq	%r12, %rdi
	callq	ftell
	movq	%rax, %rbx
	movq	%r12, %rdi
	callq	rewind
	movslq	%ebx, %r13
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %rbx
	movl	$1, %esi
	movq	%rax, %rdi
	movq	%r13, %rdx
	movq	%r12, %rcx
	callq	fread
	movq	%rax, %r13
	movq	%r12, %rdi
	callq	fclose
	movl	$0, %ebp
	testl	%r13d, %r13d
	jle	.LBB2_6
# %bb.1:                                # %.lr.ph.preheader
	movl	%r13d, %eax
	xorl	%ecx, %ecx
	xorl	%esi, %esi
	xorl	%ebp, %ebp
	xorl	%r15d, %r15d
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	cmpb	$10, (%rbx,%rcx)
	jne	.LBB2_11
# %bb.3:                                #   in Loop: Header=BB2_2 Depth=1
	xorl	%edx, %edx
	testq	%rcx, %rcx
	je	.LBB2_12
# %bb.4:                                #   in Loop: Header=BB2_2 Depth=1
	cmpb	$10, -1(%rbx,%rcx)
	je	.LBB2_12
# %bb.5:                                #   in Loop: Header=BB2_2 Depth=1
	incl	%r15d
	leal	1(%rsi), %edi
	cmpl	%esi, %ebp
	cmovlel	%edi, %ebp
	jmp	.LBB2_12
.LBB2_11:                               #   in Loop: Header=BB2_2 Depth=1
	incl	%esi
	movl	%esi, %edx
.LBB2_12:                               #   in Loop: Header=BB2_2 Depth=1
	incq	%rcx
	movl	%edx, %esi
	cmpq	%rcx, %rax
	jne	.LBB2_2
.LBB2_6:                                # %._crit_edge
	movl	%ebp, %eax
	movq	%r15, 96(%rsp)                  # 8-byte Spill
	imull	%r15d, %eax
	movslq	%eax, %rdi
	shlq	$2, %rdi
	movq	%rdi, 24(%rsp)                  # 8-byte Spill
	callq	malloc
	movq	%rax, %r12
	testl	%r13d, %r13d
	jle	.LBB2_13
# %bb.7:                                # %.lr.ph147.preheader
	movl	%r13d, %eax
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	xorl	%esi, %esi
.LBB2_8:                                # %.lr.ph147
                                        # =>This Inner Loop Header: Depth=1
	movsbl	(%rbx,%rcx), %edi
	cmpl	$10, %edi
	jne	.LBB2_20
# %bb.9:                                #   in Loop: Header=BB2_8 Depth=1
	xorl	%esi, %esi
	testq	%rcx, %rcx
	je	.LBB2_21
# %bb.10:                               #   in Loop: Header=BB2_8 Depth=1
	xorl	%edi, %edi
	cmpb	$10, -1(%rbx,%rcx)
	setne	%dil
	addl	%edi, %edx
	jmp	.LBB2_21
.LBB2_20:                               #   in Loop: Header=BB2_8 Depth=1
	movl	%edx, %r8d
	imull	%ebp, %r8d
	addl	%esi, %r8d
	movslq	%r8d, %r8
	movl	%edi, (%r12,%r8,4)
	incl	%esi
.LBB2_21:                               #   in Loop: Header=BB2_8 Depth=1
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB2_8
.LBB2_13:                               # %._crit_edge148
	leaq	128(%rsp), %rdi
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %r15
	xorl	%r13d, %r13d
	movq	%rax, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	fseek
	movq	%r15, 16(%rsp)                  # 8-byte Spill
	movq	%r15, %rdi
	callq	ftell
	movq	%r12, 48(%rsp)                  # 8-byte Spill
	movq	%rbp, 104(%rsp)                 # 8-byte Spill
	movq	%rax, %rbp
	movq	%r15, %rdi
	callq	rewind
	movslq	%ebp, %rbp
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movq	96(%rsp), %r15                  # 8-byte Reload
	movl	%r15d, %eax
	imull	%ebp, %eax
	movslq	%eax, %r12
	leaq	(,%r12,4), %rdi
	movq	%rdi, 40(%rsp)                  # 8-byte Spill
	callq	malloc
	movq	%rax, 112(%rsp)                 # 8-byte Spill
	movq	%rax, %rdi
	xorl	%esi, %esi
	movq	%r12, %rdx
	callq	memset@PLT
	movl	$1, %esi
	movq	32(%rsp), %rdi                  # 8-byte Reload
	movq	%rbp, %rdx
	movq	16(%rsp), %rbp                  # 8-byte Reload
	movq	%rbp, %rcx
	callq	fread
	movq	%rax, %r12
	movq	%rbp, %rdi
	callq	fclose
	movq	%r12, 16(%rsp)                  # 8-byte Spill
	movslq	%r12d, %r12
	leaq	80(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	72(%rsp), %rdi
	movq	40(%rsp), %rsi                  # 8-byte Reload
	callq	hipMalloc
	leaq	64(%rsp), %rdi
	movq	24(%rsp), %rbp                  # 8-byte Reload
	movq	%rbp, %rsi
	callq	hipMalloc
	leaq	80(%rsp), %rax
	movq	(%rax), %rdi
	movq	32(%rsp), %rsi                  # 8-byte Reload
	movq	%r12, %rdx
	movq	%r12, 88(%rsp)                  # 8-byte Spill
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	64(%rsp), %rax
	movq	(%rax), %rdi
	movq	48(%rsp), %rsi                  # 8-byte Reload
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	120(%rsp), %rbp
	movq	%rbp, %rdi
	callq	hipEventCreate
	leaq	56(%rsp), %rdi
	callq	hipEventCreate
	movq	(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	leaq	80(%rsp), %rax
	movq	(%rax), %rdi
	leaq	64(%rsp), %rax
	movq	(%rax), %rdx
	movq	104(%rsp), %rbp                 # 8-byte Reload
	leal	-1(%rbp), %ecx
	leaq	72(%rsp), %rax
	movq	(%rax), %r9
	movq	%r12, %rsi
	movl	%ecx, 24(%rsp)                  # 4-byte Spill
	movl	%r15d, %r8d
	callq	_Z15ASM_process_topPcmPiiiS0_
	leaq	56(%rsp), %rax
	movq	(%rax), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	leaq	56(%rsp), %rax
	movq	(%rax), %rdi
	movq	%rax, %r12
	callq	hipEventSynchronize
	leaq	120(%rsp), %rax
	movq	(%rax), %rsi
	movq	(%r12), %rdx
	leaq	12(%rsp), %rdi
	callq	hipEventElapsedTime
	leaq	72(%rsp), %rax
	movq	(%rax), %rsi
	movq	112(%rsp), %r12                 # 8-byte Reload
	movq	%r12, %rdi
	movq	40(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	cmpl	88(%rsp), %ebp                  # 4-byte Folded Reload
	jg	.LBB2_19
# %bb.14:                               # %.preheader.lr.ph
	movq	16(%rsp), %rax                  # 8-byte Reload
                                        # kill: def $eax killed $eax killed $rax def $rax
	subl	%ebp, %eax
	incl	%eax
	movl	%r15d, %ecx
	xorl	%edx, %edx
	xorl	%esi, %esi
	xorl	%r13d, %r13d
.LBB2_15:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_17 Depth 2
	testl	%r15d, %r15d
	jle	.LBB2_18
# %bb.16:                               # %.lr.ph151
                                        #   in Loop: Header=BB2_15 Depth=1
	movl	%edx, %edi
	leaq	(%r12,%rdi,4), %rdi
	xorl	%r8d, %r8d
.LBB2_17:                               #   Parent Loop BB2_15 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorl	%r9d, %r9d
	cmpl	%r14d, (%rdi,%r8,4)
	setle	%r9b
	addl	%r9d, %r13d
	incq	%r8
	cmpq	%r8, %rcx
	jne	.LBB2_17
.LBB2_18:                               # %._crit_edge152
                                        #   in Loop: Header=BB2_15 Depth=1
	incq	%rsi
	addl	%r15d, %edx
	cmpq	%rax, %rsi
	jne	.LBB2_15
.LBB2_19:                               # %._crit_edge157
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.Lstr.11, %edi
	callq	puts@PLT
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$.Lstr.10, %edi
	callq	puts@PLT
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	movl	$.Lstr.11, %edi
	callq	puts@PLT
	movl	$.L.str.6, %edi
	movl	%r15d, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.10, %edi
	callq	puts@PLT
	movl	$.L.str.7, %edi
	movl	24(%rsp), %esi                  # 4-byte Reload
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.10, %edi
	callq	puts@PLT
	movl	$.L.str.8, %edi
	movq	16(%rsp), %r15                  # 8-byte Reload
	movl	%r15d, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.10, %edi
	callq	puts@PLT
	movl	$.L.str.9, %edi
	movl	%r14d, %esi
	movl	%r13d, %edx
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.10, %edi
	callq	puts@PLT
	cvtss2sd	12(%rsp), %xmm0
	movl	$.L.str.10, %edi
	movb	$1, %al
	callq	printf
	movl	$.Lstr.10, %edi
	callq	puts@PLT
	shll	$3, %r15d
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r15d, %xmm0
	movss	12(%rsp), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	mulss	.LCPI2_0(%rip), %xmm1
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.11, %edi
	movb	$1, %al
	callq	printf
	movl	$.Lstr.11, %edi
	callq	puts@PLT
	movq	%rbx, %rdi
	callq	free
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%r12, %rdi
	callq	free
	movq	48(%rsp), %rdi                  # 8-byte Reload
	callq	free
	xorl	%eax, %eax
	addq	$648, %rsp                      # imm = 0x288
	.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_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.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	$_Z10ASM_kernelPciPiiiS0_, %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	_Z10ASM_kernelPciPiiiS0_,@object # @_Z10ASM_kernelPciPiiiS0_
	.section	.rodata,"a",@progbits
	.globl	_Z10ASM_kernelPciPiiiS0_
	.p2align	3, 0x0
_Z10ASM_kernelPciPiiiS0_:
	.quad	_Z25__device_stub__ASM_kernelPciPiiiS0_
	.size	_Z10ASM_kernelPciPiiiS0_, 8

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

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"#--No of Patterns            |\t\t %10d \t  #\n"
	.size	.L.str.6, 44

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"#--Pattern Length            |\t\t %10d \t  #\n"
	.size	.L.str.7, 44

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"#--Input Size (bytes)        |\t\t %10d \t  #\n"
	.size	.L.str.8, 44

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"#--Total matched with k = %d  |\t\t %10d \t  #\n"
	.size	.L.str.9, 45

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"#--Total elapsed time (ms)   |\t\t %10f \t  #\n"
	.size	.L.str.10, 44

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"#--Throughput Result (Gbps)  |\t\t %10f \t  #\n"
	.size	.L.str.11, 44

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z10ASM_kernelPciPiiiS0_"
	.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	"\n\n"
	.size	.Lstr, 3

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"#--Multi Fix-Length Patterns Approximate String Matching--#"
	.size	.Lstr.2, 60

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"#----------------Naive Approach in GPU--------------------#"
	.size	.Lstr.4, 60

	.type	.Lstr.10,@object                # @str.10
.Lstr.10:
	.asciz	"#---------------------------------------------------------#"
	.size	.Lstr.10, 60

	.type	.Lstr.11,@object                # @str.11
.Lstr.11:
	.asciz	"###########################################################"
	.size	.Lstr.11, 60

	.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 _Z25__device_stub__ASM_kernelPciPiiiS0_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z10ASM_kernelPciPiiiS0_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z10ASM_kernelPciPiiiS0_ ; -- Begin function _Z10ASM_kernelPciPiiiS0_
	.globl	_Z10ASM_kernelPciPiiiS0_
	.p2align	8
	.type	_Z10ASM_kernelPciPiiiS0_,@function
_Z10ASM_kernelPciPiiiS0_:               ; @_Z10ASM_kernelPciPiiiS0_
; %bb.0:
	s_clause 0x2
	s_load_b32 s4, s[0:1], 0x28
	s_load_b32 s5, s[0:1], 0x8
	s_load_b64 s[2:3], s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s4, s4, s15
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s4, s4, s14
	v_lshl_add_u32 v0, s4, 7, v0
	s_sub_i32 s4, s5, s2
	s_cmp_gt_i32 s3, 0
	s_mov_b32 s5, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_ge_i32_e32 vcc_lo, s4, v0
	s_cselect_b32 s4, -1, 0
	s_and_b32 s4, vcc_lo, s4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s6, s4
	s_cbranch_execz .LBB0_6
; %bb.1:                                ; %.preheader.lr.ph
	s_clause 0x2
	s_load_b64 s[6:7], s[0:1], 0x0
	s_load_b64 s[8:9], s[0:1], 0x10
	s_load_b64 s[10:11], s[0:1], 0x20
	v_mul_lo_u32 v1, v0, s3
	s_add_i32 s1, s2, 1
	v_mov_b32_e32 v2, 0
	s_cmp_gt_i32 s2, 0
	s_mov_b32 s4, s5
	s_cselect_b32 s14, -1, 0
	s_mov_b32 s15, s5
.LBB0_2:                                ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
	v_mov_b32_e32 v3, 0
	s_and_not1_b32 vcc_lo, exec_lo, s14
	s_cbranch_vccnz .LBB0_5
; %bb.3:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_lshl_b64 s[12:13], s[4:5], 2
	v_dual_mov_b32 v3, 0 :: v_dual_mov_b32 v4, v0
	s_waitcnt lgkmcnt(0)
	s_add_u32 s12, s8, s12
	s_addc_u32 s13, s9, s13
	s_mov_b32 s16, s2
.LBB0_4:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_ashrrev_i32_e32 v6, 31, v4
	v_add_co_u32 v5, vcc_lo, s6, v4
	s_add_i32 s16, s16, -1
	v_add_nc_u32_e32 v4, 1, v4
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v6, vcc_lo, s7, v6, vcc_lo
	global_load_b32 v7, v2, s[12:13]
	global_load_i8 v5, v[5:6], off
	s_waitcnt vmcnt(0)
	v_cmp_ne_u32_e32 vcc_lo, 10, v5
	v_cmp_ne_u32_e64 s0, v7, v5
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 vcc_lo, vcc_lo, s0
	s_add_u32 s12, s12, 4
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	s_addc_u32 s13, s13, 0
	s_cmp_eq_u32 s16, 0
	s_cbranch_scc0 .LBB0_4
.LBB0_5:                                ; %Flow58
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_add_nc_u32_e32 v4, s15, v1
	s_add_i32 s15, s15, 1
	s_add_i32 s4, s4, s1
	s_cmp_eq_u32 s15, s3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v4, vcc_lo, s10, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s11, v5, vcc_lo
	global_store_b32 v[4:5], v3, off
	s_cbranch_scc0 .LBB0_2
.LBB0_6:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10ASM_kernelPciPiiiS0_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 14
		.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 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 8
		.amdhsa_next_free_sgpr 17
		.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	_Z10ASM_kernelPciPiiiS0_, .Lfunc_end0-_Z10ASM_kernelPciPiiiS0_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 356
; NumSgprs: 19
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 19
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; 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
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .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:           _Z10ASM_kernelPciPiiiS0_
    .private_segment_fixed_size: 0
    .sgpr_count:     19
    .sgpr_spill_count: 0
    .symbol:         _Z10ASM_kernelPciPiiiS0_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
