/* 2013
 * Maciej Szeptuch
 * II UWr
 * ----------
 * bez shared, pozbywanie sie jak najwiecej pamieci + loop unrolling
 * czasy okolo 10x szybciej niz na CPU.

        word       |              gpu               |              cpu               | distance
 ------------------|--------------------------------|--------------------------------|----------
  kot              | kot              [  13.373088] | kot              [ 120.616997] | 0
  czesc            | czescy           [  17.563328] | czescy           [ 182.584000] | 1
  onomatopeja      | onomatopeja      [  31.341473] | onomatopeja      [ 367.598022] | 0


 */
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <string.h>
#include <errno.h>

#define WORD_MAXLEN     16
#define STEP_0_THREADS  128
#define STEP_R_THREADS  128
#define __CUDA__
#define __CPU__

__device__ __host__ inline unsigned char MIN(const unsigned char a, const unsigned char b) { return a<b?a:b; }
__host__ unsigned char LevenshteinDistanceH(const unsigned char *const A, const unsigned char *const B);
__device__ unsigned char LevenshteinDistanceD(const unsigned char *const A, const unsigned char *const B);

unsigned char *loadDictionary(const char *const file, unsigned int &words, unsigned int &size);
void printHead(void);

#ifdef __CUDA__
__global__ void LevenshteinCUDA_STEP_0(const unsigned char *const dictionary, const unsigned int words, const unsigned char *const pattern, unsigned int *result);

__global__ void LevenshteinCUDA_STEP_R(const unsigned int *from, unsigned int *to, const unsigned int words);
#endif // __CUDA__

#ifdef __CPU__
unsigned int LevenshteinCPU(const unsigned char *const dictionary, const unsigned int words, const unsigned char *const pattern);
#endif // __CPU__

int main(const int argc, const char *const* argv)
{
    if(argc < 3)
    {
        fprintf(stderr, "usage: %s dictionary words...\nError: not enough arguments\n", argv[0]);
        return 1;
    }

    unsigned int dictionarySize = 0,
                 dictionaryWords = 0;
    unsigned char *dictionary = loadDictionary(argv[1], dictionaryWords, dictionarySize);

    if(!dictionary)
    {
        fprintf(stderr, "usage: %s dictionary words...\nError: loading dictionary: %s\n", argv[0], strerror(errno));
        return 2;
    }

#ifdef __CUDA__
    // GPU INIT
    unsigned char *cudaDictionary = NULL,
                  *cudaPattern = NULL;

    unsigned int *cudaResult = NULL;
    cudaMalloc(&cudaDictionary, dictionarySize * sizeof(unsigned char));
    cudaMemcpy(cudaDictionary, dictionary, dictionarySize * sizeof(unsigned char), cudaMemcpyHostToDevice);

    cudaMalloc(&cudaPattern, WORD_MAXLEN * sizeof(unsigned char));

    cudaMalloc(&cudaResult, dictionarySize * 2 * sizeof(unsigned int));
#endif // __CUDA__

    printHead();
    for(unsigned int a = 2; a < argc; ++ a)
    {
        unsigned int result[2] = {1 << 30, 1 << 30};
        unsigned char pattern[WORD_MAXLEN + 2] = {};
        memcpy(pattern, argv[a], strlen(argv[a]) * sizeof(unsigned char));

        printf(" %-16s | ", pattern);
#ifdef __CUDA__
        {
            // GPU TEST
            cudaEvent_t start, end;
            cudaEventCreate(&start);
            cudaEventCreate(&end);
            cudaEventRecord(start, NULL);

            cudaMemcpy(cudaPattern, pattern, WORD_MAXLEN * sizeof(unsigned char), cudaMemcpyHostToDevice);

            LevenshteinCUDA_STEP_0<<<(dictionaryWords + STEP_0_THREADS - 1) / STEP_0_THREADS, STEP_0_THREADS>>> (cudaDictionary, dictionaryWords, cudaPattern, cudaResult);
            for(unsigned int size = STEP_R_THREADS; size < dictionaryWords; size <<= 1)
                LevenshteinCUDA_STEP_R<<<(dictionaryWords + size - 1) / size, STEP_R_THREADS>>> (cudaResult, cudaResult, dictionaryWords);

            cudaMemcpy(result, cudaResult, 2 * sizeof(unsigned int), cudaMemcpyDeviceToHost);

            cudaEventRecord(end, NULL);
            cudaEventSynchronize(end);
            float gputotal = 0;
            cudaEventElapsedTime(&gputotal, start, end);

            printf("%-16s [%11.6f] | ", &dictionary[result[0] * WORD_MAXLEN], gputotal, result[1]);
        }
#endif // __CUDA__
#ifdef __CPU__
        {
            // CPU TEST
            timeval start, end;
            gettimeofday(&start, NULL);

            result[0] = LevenshteinCPU(dictionary, dictionaryWords, pattern);

            gettimeofday(&end, NULL);
            float cputotal = (end.tv_sec - start.tv_sec) * 1000.0f + (end.tv_usec - start.tv_usec) / 1000.0f;
            printf("%-16s [%11.6f] | ", dictionary + result[0] * WORD_MAXLEN, cputotal);
        }
#endif // __CPU__

        printf("%u\n", LevenshteinDistanceH(pattern, dictionary + result[0] * WORD_MAXLEN));
    }

#ifdef __CUDA__
    cudaFree(cudaDictionary);
#endif // __CUDA__
    free(dictionary);
    return 0;
}

unsigned char *loadDictionary(const char *const file, unsigned int &words, unsigned int &size)
{
    FILE *handle = fopen(file, "rb");
    if(!handle)
        return NULL;

    unsigned char *dictionary = NULL,
                  *current = NULL;
    char buffer[64] = {};
    words = 0;
    while(fgets(buffer, 64, handle))
        ++ words;

    fseek(handle, 0, SEEK_SET);
    size = words * WORD_MAXLEN;
    current = dictionary = new unsigned char[size];
    memset(dictionary, 0, size * sizeof(unsigned char));
    while(fgets((char *) current, WORD_MAXLEN + 8, handle))
    {
        current[strlen((const char *) current) - 1] = 0; // remove \n
        current[strlen((const char *) current) - 1] = 0; // remove \r
        current += WORD_MAXLEN;
    }

    fclose(handle);
    return dictionary;
}

#ifdef __CPU__
unsigned int LevenshteinCPU(const unsigned char *const dictionary, const unsigned int words, const unsigned char *const pattern)
{
    const unsigned char *word = dictionary;
    unsigned int best = 1 << 30,
                 r = 0;
    for(unsigned int w = 0; w < words; ++ w, word += WORD_MAXLEN)
    {
        unsigned int dist = LevenshteinDistanceH(pattern, word);
        if(dist < best)
        {
            best = dist;
            r = w;
        }
    }

    return r;
}
#endif // __CPU__

__host__ unsigned char LevenshteinDistanceH(const unsigned char *const A, const unsigned char *const B)
{
    unsigned char sb = strlen((const char *) B);
    unsigned char *AA = (unsigned char *) A,
                  *BB = (unsigned char *) B;

    unsigned char temp[2][WORD_MAXLEN + 1];
    unsigned char t = 1;
    for(unsigned char a = 0; a <= sb; ++ a)
        temp[0][a] = a;

    AA = (unsigned char *) A;
    for(unsigned char a = 1; *AA > 0; ++ a, t ^= 1, ++ AA)
    {
        temp[t][0] = a;
        BB = (unsigned char *) B;
        for(unsigned char b = 1; b <= sb; ++ b, ++ BB)
            temp[t][b] = MIN(temp[t ^ 1][  b  ] + 1,
                    MIN(temp[  t  ][b - 1] + 1,
                        temp[t ^ 1][b - 1] + (*AA != *BB)));
    }

    return temp[t ^ 1][sb];
}

__device__ unsigned char LevenshteinDistanceD(const unsigned char *const A, const unsigned char *const B)
{
    unsigned char sb = 0;
    unsigned char *AA = (unsigned char *) A,
                  *BB = (unsigned char *) B;

    while(*BB ++ > 0)
        ++ sb;

    unsigned char temp[2][WORD_MAXLEN + 1];
    unsigned char t = 1;
#pragma unroll
    for(unsigned char a = 0; a <= WORD_MAXLEN; ++ a)
        temp[0][a] = a;

    for(unsigned char a = 1; *AA > 0; ++ a, t ^= 1, ++ AA)
    {
        temp[t][0] = a;
        BB = (unsigned char *) B;
#pragma unroll
        for(unsigned char b = 1; b <= WORD_MAXLEN; ++ b, ++ BB)
            temp[t][b] = MIN(temp[t ^ 1][  b  ] + 1,
                    MIN(temp[  t  ][b - 1] + 1,
                        temp[t ^ 1][b - 1] + (*AA != *BB)));
    }

    return temp[t ^ 1][sb];
}

void printHead(void)
{
    printf("       word       | ");
#ifdef __CUDA__
    printf("             gpu               | ");
#endif // __CUDA__

#ifdef __CPU__
    printf("             cpu               | ");
#endif // __CPU__

    printf("distance\n");

    printf("------------------|-");
#ifdef __CUDA__
    printf("-------------------------------|-");
#endif // __CUDA__

#ifdef __CPU__
    printf("-------------------------------|-");
#endif // __CPU__

    printf("---------\n");
}

#ifdef __CUDA__
__global__ void LevenshteinCUDA_STEP_0(const unsigned char *dictionary, const unsigned int words, const unsigned char *pattern, unsigned int *result)
{
    int word = blockIdx.x * STEP_0_THREADS + threadIdx.x;
    if(word >= words)
        return;

    result[word * 2] = word;
    result[word * 2 + 1] = LevenshteinDistanceD(pattern, dictionary + word * WORD_MAXLEN);
}

__global__ void LevenshteinCUDA_STEP_R(const unsigned int *from, unsigned int *to, const unsigned int words)
{
    __shared__ unsigned int local_data[STEP_R_THREADS * 2];
    unsigned int tid = threadIdx.x;
    unsigned int i = blockIdx.x * blockDim.x + tid;
    local_data[tid * 2] = from[i * 2];
    local_data[tid * 2 + 1] = from[i * 2 + 1];

    __syncthreads();
    for(unsigned int s = 1; s < blockDim.x && tid + s < words; s <<= 1)
    {
        if(tid % (2 * s) == 0 && local_data[tid * 2 + 1] > local_data[(tid + s) * 2 + 1])
        {
            local_data[tid * 2] = local_data[(tid + s) * 2];
            local_data[tid * 2 + 1] = local_data[(tid + s) * 2 + 1];
        }

        __syncthreads();
    }

    if(tid == 0)
    {
        to[blockIdx.x * 2] = local_data[0];
        to[blockIdx.x * 2 + 1] = local_data[1];
    }
}
#endif // __CUDA__


	.file	"tmpxft_001ff366_00000000-6_Levenshtein.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2036:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2036:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"rb"
	.text
	.globl	_Z14loadDictionaryPKcRjS1_
	.type	_Z14loadDictionaryPKcRjS1_, @function
_Z14loadDictionaryPKcRjS1_:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rdx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rsi, %rbx
	leaq	.LC0(%rip), %rsi
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	movq	%rax, %rbp
	testq	%rax, %rax
	je	.L2
	leaq	8(%rsp), %rdi
	movl	$16, %ecx
	xorl	%eax, %eax
	rep stosl
	leaq	8(%rsp), %r13
.L4:
	movl	%eax, (%rbx)
	movq	%rbp, %rcx
	movl	$64, %edx
	movl	$64, %esi
	movq	%r13, %rdi
	call	__fgets_chk@PLT
	testq	%rax, %rax
	je	.L14
	movl	(%rbx), %eax
	incl	%eax
	jmp	.L4
.L14:
	xorl	%edx, %edx
	xorl	%esi, %esi
	movq	%rbp, %rdi
	call	fseek@PLT
	movl	(%rbx), %ebx
	sall	$4, %ebx
	movl	%ebx, (%r12)
	movq	%rbx, %rdi
	call	_Znam@PLT
	movl	(%r12), %edx
	movq	%rbx, %rcx
	xorl	%esi, %esi
	movq	%rax, %r14
	movq	%rax, %rdi
	movq	%rbx, %r12
	call	__memset_chk@PLT
	movq	%r14, %r13
.L6:
	movq	%rbp, %rcx
	movl	$24, %edx
	movq	%r12, %rsi
	movq	%r13, %rdi
	call	__fgets_chk@PLT
	testq	%rax, %rax
	je	.L15
	movq	%r13, %rdi
	call	strlen@PLT
	movq	%r13, %rdi
	movb	$0, -1(%r13,%rax)
	call	strlen@PLT
	cmpq	%r12, %rbx
	movq	%r12, %rdx
	cmovnb	%rbx, %rdx
	movb	$0, -1(%r13,%rax)
	movq	%rdx, %rax
	subq	%r12, %rax
	addq	$16, %rax
	cmpq	%rdx, %rax
	cmovb	%rdx, %rax
	subq	%rdx, %r12
	addq	$16, %r13
	leaq	-16(%r12,%rax), %r12
	jmp	.L6
.L15:
	movq	%rbp, %rdi
	movq	%r14, %rbp
	call	fclose@PLT
.L2:
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	addq	$80, %rsp
	.cfi_def_cfa_offset 48
	movq	%rbp, %rax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z14loadDictionaryPKcRjS1_, .-_Z14loadDictionaryPKcRjS1_
	.globl	_Z20LevenshteinDistanceHPKhS0_
	.type	_Z20LevenshteinDistanceHPKhS0_, @function
_Z20LevenshteinDistanceHPKhS0_:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rdi, %rbp
	movq	%rsi, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rsi, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	strlen@PLT
	movq	%rax, %rsi
	movl	%eax, %r10d
	xorl	%eax, %eax
.L17:
	movzbl	%al, %edx
	movb	%al, 6(%rsp,%rdx)
	incl	%eax
	cmpb	%al, %r10b
	jnb	.L17
	xorl	%r8d, %r8d
	movb	$1, %al
	leaq	6(%rsp), %r11
.L18:
	movb	0(%rbp,%r8), %r9b
	leal	1(%r8), %ecx
	testb	%r9b, %r9b
	je	.L25
	movzbl	%al, %edx
	xorl	%edi, %edi
	imulq	$17, %rdx, %rdx
	movb	%cl, 6(%rsp,%rdx)
	movq	%rax, %rcx
	xorl	$1, %eax
	movzbl	%al, %r12d
	negq	%rcx
	imulq	$17, %r12, %r12
	andl	$17, %ecx
	addq	%r11, %rcx
	leaq	48(%r12), %rdx
	leaq	(%rsp,%rdx), %r12
.L19:
	incq	%rdi
	incq	%rcx
	cmpb	%dil, %r10b
	jb	.L26
	leal	-1(%rdi), %r13d
	cmpb	%r9b, -1(%rbx,%rdi)
	movslq	%r13d, %r13
	setne	%dl
	addb	-42(%r13,%r12), %dl
	movslq	%edi, %r13
	movb	-42(%r13,%r12), %r13b
	incl	%r13d
	cmpb	%r13b, %dl
	cmova	%r13d, %edx
	movb	-1(%rcx), %r13b
	incl	%r13d
	cmpb	%r13b, %dl
	cmova	%r13d, %edx
	movb	%dl, (%rcx)
	jmp	.L19
.L26:
	incq	%r8
	jmp	.L18
.L25:
	xorl	$1, %eax
	movzbl	%sil, %esi
	movzbl	%al, %eax
	imulq	$17, %rax, %rax
	addq	$48, %rax
	addq	%rsp, %rax
	movb	-42(%rsi,%rax), %al
	movq	40(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	addq	$56, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z20LevenshteinDistanceHPKhS0_, .-_Z20LevenshteinDistanceHPKhS0_
	.globl	_Z14LevenshteinCPUPKhjS0_
	.type	_Z14LevenshteinCPUPKhjS0_, @function
_Z14LevenshteinCPUPKhjS0_:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$1073741824, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 64
.L28:
	cmpq	%r12, %rbp
	je	.L32
	movq	%rbx, %rsi
	movq	%r13, %rdi
	call	_Z20LevenshteinDistanceHPKhS0_
	movzbl	%al, %eax
	cmpl	%r15d, %eax
	jnb	.L29
	movl	%ebp, %r14d
	movl	%eax, %r15d
.L29:
	addq	$16, %rbx
	incq	%rbp
	jmp	.L28
.L32:
	popq	%rdx
	.cfi_def_cfa_offset 56
	movl	%r14d, %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
.LFE2030:
	.size	_Z14LevenshteinCPUPKhjS0_, .-_Z14LevenshteinCPUPKhjS0_
	.globl	_Z20LevenshteinDistanceDPKhS0_
	.type	_Z20LevenshteinDistanceDPKhS0_, @function
_Z20LevenshteinDistanceDPKhS0_:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2032:
	.size	_Z20LevenshteinDistanceDPKhS0_, .-_Z20LevenshteinDistanceDPKhS0_
	.section	.rodata.str1.1
.LC1:
	.string	"       word       | "
.LC2:
	.string	"             gpu               | "
.LC3:
	.string	"             cpu               | "
.LC4:
	.string	"distance\n"
.LC5:
	.string	"------------------|-"
.LC6:
	.string	"-------------------------------|-"
.LC7:
	.string	"---------\n"
	.text
	.globl	_Z9printHeadv
	.type	_Z9printHeadv, @function
_Z9printHeadv:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC6(%rip), %rbx
	call	__printf_chk@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC4(%rip), %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
	movq	%rbx, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	movl	$2, %edi
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2033:
	.size	_Z9printHeadv, .-_Z9printHeadv
	.globl	_Z49__device_stub__Z22LevenshteinCUDA_STEP_0PKhjS0_PjPKhjS0_Pj
	.type	_Z49__device_stub__Z22LevenshteinCUDA_STEP_0PKhjS0_PjPKhjS0_Pj, @function
_Z49__device_stub__Z22LevenshteinCUDA_STEP_0PKhjS0_PjPKhjS0_Pj:
.LFB2058:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movl	%esi, 20(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L37
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L37:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L39
	call	__stack_chk_fail@PLT
.L39:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z49__device_stub__Z22LevenshteinCUDA_STEP_0PKhjS0_PjPKhjS0_Pj, .-_Z49__device_stub__Z22LevenshteinCUDA_STEP_0PKhjS0_PjPKhjS0_Pj
	.globl	_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj
	.type	_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj, @function
_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z49__device_stub__Z22LevenshteinCUDA_STEP_0PKhjS0_PjPKhjS0_Pj
	.cfi_endproc
.LFE2059:
	.size	_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj, .-_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj
	.globl	_Z46__device_stub__Z22LevenshteinCUDA_STEP_RPKjPjjPKjPjj
	.type	_Z46__device_stub__Z22LevenshteinCUDA_STEP_RPKjPjjPKjPjj, @function
_Z46__device_stub__Z22LevenshteinCUDA_STEP_RPKjPjjPKjPjj:
.LFB2060:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L42
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z22LevenshteinCUDA_STEP_RPKjPjj(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L42:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L44
	call	__stack_chk_fail@PLT
.L44:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2060:
	.size	_Z46__device_stub__Z22LevenshteinCUDA_STEP_RPKjPjjPKjPjj, .-_Z46__device_stub__Z22LevenshteinCUDA_STEP_RPKjPjjPKjPjj
	.globl	_Z22LevenshteinCUDA_STEP_RPKjPjj
	.type	_Z22LevenshteinCUDA_STEP_RPKjPjj, @function
_Z22LevenshteinCUDA_STEP_RPKjPjj:
.LFB2061:
	.cfi_startproc
	endbr64
	jmp	_Z46__device_stub__Z22LevenshteinCUDA_STEP_RPKjPjjPKjPjj
	.cfi_endproc
.LFE2061:
	.size	_Z22LevenshteinCUDA_STEP_RPKjPjj, .-_Z22LevenshteinCUDA_STEP_RPKjPjj
	.section	.rodata.str1.1
.LC8:
	.string	"usage: %s dictionary words...\nError: not enough arguments\n"
.LC9:
	.string	"usage: %s dictionary words...\nError: loading dictionary: %s\n"
.LC10:
	.string	" %-16s | "
.LC12:
	.string	"%-16s [%11.6f] | "
.LC14:
	.string	"%u\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
	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
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	movl	%edi, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	jg	.L48
	movq	(%rsi), %rcx
	movq	stderr(%rip), %rdi
	leaq	.LC8(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	$1, %eax
	jmp	.L47
.L48:
	xorl	%edx, %edx
	movq	8(%r12), %rdi
	leaq	28(%rsp), %rsi
	movl	%edx, 24(%rsp)
	movl	%edx, 28(%rsp)
	leaq	24(%rsp), %rdx
	call	_Z14loadDictionaryPKcRjS1_
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L50
	call	__errno_location@PLT
	movl	(%rax), %edi
	call	strerror@PLT
	movq	(%r12), %rcx
	movl	$2, %esi
	movq	stderr(%rip), %rdi
	movq	%rax, %r8
	leaq	.LC9(%rip), %rdx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$2, %eax
	jmp	.L47
.L50:
	movl	24(%rsp), %r14d
	xorl	%eax, %eax
	leaq	32(%rsp), %rdi
	movabsq	$4294967424, %r15
	movq	%rax, 32(%rsp)
	movq	%r14, %rsi
	movq	%rax, 40(%rsp)
	movq	%rax, 48(%rsp)
	call	cudaMalloc@PLT
	movq	32(%rsp), %rdi
	movq	%r14, %rdx
	movq	%rbx, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	leaq	40(%rsp), %rdi
	movl	$16, %esi
	call	cudaMalloc@PLT
	leal	(%r14,%r14), %esi
	leaq	48(%rsp), %rdi
	movl	$2, %r14d
	salq	$2, %rsi
	call	cudaMalloc@PLT
	call	_Z9printHeadv
.L55:
	movq	(%r12,%r14,8), %rbp
	xorps	%xmm0, %xmm0
	movabsq	$4611686019501129728, %rax
	movw	$0, 134(%rsp)
	movups	%xmm0, 118(%rsp)
	movq	%rbp, %rdi
	movq	%rax, 108(%rsp)
	call	strlen@PLT
	movl	$18, %ecx
	movq	%rbp, %rsi
	movq	%rax, %rdx
	leaq	118(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	__memcpy_chk@PLT
	movq	(%rsp), %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC10(%rip), %rsi
	call	__printf_chk@PLT
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	64(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	(%rsp), %rsi
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movl	$16, %edx
	call	cudaMemcpy@PLT
	movl	28(%rsp), %ebp
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r15, %rdx
	movl	$1, %ecx
	movq	%r15, 88(%rsp)
	leal	127(%rbp), %eax
	movl	$1, 96(%rsp)
	shrl	$7, %eax
	movl	%eax, 72(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 76(%rsp)
	movq	72(%rsp), %rdi
	movl	80(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L51
	movq	48(%rsp), %rcx
	movq	40(%rsp), %rdx
	movl	%ebp, %esi
	movq	32(%rsp), %rdi
	call	_Z49__device_stub__Z22LevenshteinCUDA_STEP_0PKhjS0_PjPKhjS0_Pj
.L51:
	movl	$128, %r13d
.L52:
	cmpl	%ebp, %r13d
	jnb	.L59
	xorl	%edx, %edx
	leal	-1(%rbp,%r13), %eax
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	divl	%r13d
	movq	%r15, 88(%rsp)
	movl	$1, 96(%rsp)
	movq	%r15, %rdx
	movl	$1, %ecx
	movl	%eax, 72(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 76(%rsp)
	movq	72(%rsp), %rdi
	movl	80(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L53
	movq	48(%rsp), %rdi
	movl	%ebp, %edx
	movq	%rdi, %rsi
	call	_Z46__device_stub__Z22LevenshteinCUDA_STEP_RPKjPjjPKjPjj
.L53:
	addl	%r13d, %r13d
	jmp	.L52
.L59:
	movq	48(%rsp), %rsi
	movl	$2, %ecx
	movl	$8, %edx
	incq	%r14
	leaq	108(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	64(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	leaq	88(%rsp), %rax
	movq	64(%rsp), %rdx
	movq	56(%rsp), %rsi
	movq	%rax, %rdi
	movq	%rax, %r13
	movl	$0x00000000, 88(%rsp)
	call	cudaEventElapsedTime@PLT
	movl	108(%rsp), %edx
	movl	112(%rsp), %ecx
	movb	$1, %al
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	cvtss2sd	88(%rsp), %xmm0
	sall	$4, %edx
	addq	%rbx, %rdx
	call	__printf_chk@PLT
	leaq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	movq	(%rsp), %rdx
	movl	%ebp, %esi
	movq	%rbx, %rdi
	call	_Z14LevenshteinCPUPKhjS0_
	xorl	%esi, %esi
	movq	%r13, %rdi
	movl	%eax, 108(%rsp)
	call	gettimeofday@PLT
	movq	88(%rsp), %rax
	movl	108(%rsp), %edx
	leaq	.LC12(%rip), %rsi
	subq	72(%rsp), %rax
	movss	.LC13(%rip), %xmm2
	movl	$2, %edi
	cvtsi2ssq	%rax, %xmm0
	movq	96(%rsp), %rax
	subq	80(%rsp), %rax
	sall	$4, %edx
	cvtsi2ssq	%rax, %xmm1
	addq	%rbx, %rdx
	movb	$1, %al
	mulss	%xmm2, %xmm0
	divss	%xmm2, %xmm1
	addss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	108(%rsp), %esi
	movq	(%rsp), %rdi
	sall	$4, %esi
	addq	%rbx, %rsi
	call	_Z20LevenshteinDistanceHPKhS0_
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	movzbl	%al, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	12(%rsp), %eax
	cmpl	%eax, %r14d
	jb	.L55
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbx, %rdi
	call	free@PLT
	xorl	%eax, %eax
.L47:
	movq	136(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L56
	call	__stack_chk_fail@PLT
.L56:
	addq	$152, %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
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC16:
	.string	"_Z22LevenshteinCUDA_STEP_RPKjPjj"
.LC17:
	.string	"_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2063:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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	.LC16(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z22LevenshteinCUDA_STEP_RPKjPjj(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC17(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	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	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2063:
	.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
.LC13:
	.long	1148846080
	.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:

/* 2013
 * Maciej Szeptuch
 * II UWr
 * ----------
 * bez shared, pozbywanie sie jak najwiecej pamieci + loop unrolling
 * czasy okolo 10x szybciej niz na CPU.

        word       |              gpu               |              cpu               | distance
 ------------------|--------------------------------|--------------------------------|----------
  kot              | kot              [  13.373088] | kot              [ 120.616997] | 0
  czesc            | czescy           [  17.563328] | czescy           [ 182.584000] | 1
  onomatopeja      | onomatopeja      [  31.341473] | onomatopeja      [ 367.598022] | 0


 */

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

#define WORD_MAXLEN     16
#define STEP_0_THREADS  128
#define STEP_R_THREADS  128
#define __CUDA__
#define __CPU__

__device__ __host__ inline unsigned char MIN(const unsigned char a, const unsigned char b) { return a<b?a:b; }
__host__ unsigned char LevenshteinDistanceH(const unsigned char *const A, const unsigned char *const B);
__device__ unsigned char LevenshteinDistanceD(const unsigned char *const A, const unsigned char *const B);

unsigned char *loadDictionary(const char *const file, unsigned int &words, unsigned int &size);
void printHead(void);

#ifdef __CUDA__
__global__ void LevenshteinCUDA_STEP_0(const unsigned char *const dictionary, const unsigned int words, const unsigned char *const pattern, unsigned int *result);

__global__ void LevenshteinCUDA_STEP_R(const unsigned int *from, unsigned int *to, const unsigned int words);
#endif // __CUDA__

#ifdef __CPU__
unsigned int LevenshteinCPU(const unsigned char *const dictionary, const unsigned int words, const unsigned char *const pattern);
#endif // __CPU__

int main(const int argc, const char *const* argv)
{
    if(argc < 3)
    {
        fprintf(stderr, "usage: %s dictionary words...\nError: not enough arguments\n", argv[0]);
        return 1;
    }

    unsigned int dictionarySize = 0,
                 dictionaryWords = 0;
    unsigned char *dictionary = loadDictionary(argv[1], dictionaryWords, dictionarySize);

    if(!dictionary)
    {
        fprintf(stderr, "usage: %s dictionary words...\nError: loading dictionary: %s\n", argv[0], strerror(errno));
        return 2;
    }

#ifdef __CUDA__
    // GPU INIT
    unsigned char *cudaDictionary = NULL,
                  *cudaPattern = NULL;

    unsigned int *cudaResult = NULL;
    hipMalloc(&cudaDictionary, dictionarySize * sizeof(unsigned char));
    hipMemcpy(cudaDictionary, dictionary, dictionarySize * sizeof(unsigned char), hipMemcpyHostToDevice);

    hipMalloc(&cudaPattern, WORD_MAXLEN * sizeof(unsigned char));

    hipMalloc(&cudaResult, dictionarySize * 2 * sizeof(unsigned int));
#endif // __CUDA__

    printHead();
    for(unsigned int a = 2; a < argc; ++ a)
    {
        unsigned int result[2] = {1 << 30, 1 << 30};
        unsigned char pattern[WORD_MAXLEN + 2] = {};
        memcpy(pattern, argv[a], strlen(argv[a]) * sizeof(unsigned char));

        printf(" %-16s | ", pattern);
#ifdef __CUDA__
        {
            // GPU TEST
            hipEvent_t start, end;
            hipEventCreate(&start);
            hipEventCreate(&end);
            hipEventRecord(start, NULL);

            hipMemcpy(cudaPattern, pattern, WORD_MAXLEN * sizeof(unsigned char), hipMemcpyHostToDevice);

            LevenshteinCUDA_STEP_0<<<(dictionaryWords + STEP_0_THREADS - 1) / STEP_0_THREADS, STEP_0_THREADS>>> (cudaDictionary, dictionaryWords, cudaPattern, cudaResult);
            for(unsigned int size = STEP_R_THREADS; size < dictionaryWords; size <<= 1)
                LevenshteinCUDA_STEP_R<<<(dictionaryWords + size - 1) / size, STEP_R_THREADS>>> (cudaResult, cudaResult, dictionaryWords);

            hipMemcpy(result, cudaResult, 2 * sizeof(unsigned int), hipMemcpyDeviceToHost);

            hipEventRecord(end, NULL);
            hipEventSynchronize(end);
            float gputotal = 0;
            hipEventElapsedTime(&gputotal, start, end);

            printf("%-16s [%11.6f] | ", &dictionary[result[0] * WORD_MAXLEN], gputotal, result[1]);
        }
#endif // __CUDA__
#ifdef __CPU__
        {
            // CPU TEST
            timeval start, end;
            gettimeofday(&start, NULL);

            result[0] = LevenshteinCPU(dictionary, dictionaryWords, pattern);

            gettimeofday(&end, NULL);
            float cputotal = (end.tv_sec - start.tv_sec) * 1000.0f + (end.tv_usec - start.tv_usec) / 1000.0f;
            printf("%-16s [%11.6f] | ", dictionary + result[0] * WORD_MAXLEN, cputotal);
        }
#endif // __CPU__

        printf("%u\n", LevenshteinDistanceH(pattern, dictionary + result[0] * WORD_MAXLEN));
    }

#ifdef __CUDA__
    hipFree(cudaDictionary);
#endif // __CUDA__
    free(dictionary);
    return 0;
}

unsigned char *loadDictionary(const char *const file, unsigned int &words, unsigned int &size)
{
    FILE *handle = fopen(file, "rb");
    if(!handle)
        return NULL;

    unsigned char *dictionary = NULL,
                  *current = NULL;
    char buffer[64] = {};
    words = 0;
    while(fgets(buffer, 64, handle))
        ++ words;

    fseek(handle, 0, SEEK_SET);
    size = words * WORD_MAXLEN;
    current = dictionary = new unsigned char[size];
    memset(dictionary, 0, size * sizeof(unsigned char));
    while(fgets((char *) current, WORD_MAXLEN + 8, handle))
    {
        current[strlen((const char *) current) - 1] = 0; // remove \n
        current[strlen((const char *) current) - 1] = 0; // remove \r
        current += WORD_MAXLEN;
    }

    fclose(handle);
    return dictionary;
}

#ifdef __CPU__
unsigned int LevenshteinCPU(const unsigned char *const dictionary, const unsigned int words, const unsigned char *const pattern)
{
    const unsigned char *word = dictionary;
    unsigned int best = 1 << 30,
                 r = 0;
    for(unsigned int w = 0; w < words; ++ w, word += WORD_MAXLEN)
    {
        unsigned int dist = LevenshteinDistanceH(pattern, word);
        if(dist < best)
        {
            best = dist;
            r = w;
        }
    }

    return r;
}
#endif // __CPU__

__host__ unsigned char LevenshteinDistanceH(const unsigned char *const A, const unsigned char *const B)
{
    unsigned char sb = strlen((const char *) B);
    unsigned char *AA = (unsigned char *) A,
                  *BB = (unsigned char *) B;

    unsigned char temp[2][WORD_MAXLEN + 1];
    unsigned char t = 1;
    for(unsigned char a = 0; a <= sb; ++ a)
        temp[0][a] = a;

    AA = (unsigned char *) A;
    for(unsigned char a = 1; *AA > 0; ++ a, t ^= 1, ++ AA)
    {
        temp[t][0] = a;
        BB = (unsigned char *) B;
        for(unsigned char b = 1; b <= sb; ++ b, ++ BB)
            temp[t][b] = MIN(temp[t ^ 1][  b  ] + 1,
                    MIN(temp[  t  ][b - 1] + 1,
                        temp[t ^ 1][b - 1] + (*AA != *BB)));
    }

    return temp[t ^ 1][sb];
}

__device__ unsigned char LevenshteinDistanceD(const unsigned char *const A, const unsigned char *const B)
{
    unsigned char sb = 0;
    unsigned char *AA = (unsigned char *) A,
                  *BB = (unsigned char *) B;

    while(*BB ++ > 0)
        ++ sb;

    unsigned char temp[2][WORD_MAXLEN + 1];
    unsigned char t = 1;
#pragma unroll
    for(unsigned char a = 0; a <= WORD_MAXLEN; ++ a)
        temp[0][a] = a;

    for(unsigned char a = 1; *AA > 0; ++ a, t ^= 1, ++ AA)
    {
        temp[t][0] = a;
        BB = (unsigned char *) B;
#pragma unroll
        for(unsigned char b = 1; b <= WORD_MAXLEN; ++ b, ++ BB)
            temp[t][b] = MIN(temp[t ^ 1][  b  ] + 1,
                    MIN(temp[  t  ][b - 1] + 1,
                        temp[t ^ 1][b - 1] + (*AA != *BB)));
    }

    return temp[t ^ 1][sb];
}

void printHead(void)
{
    printf("       word       | ");
#ifdef __CUDA__
    printf("             gpu               | ");
#endif // __CUDA__

#ifdef __CPU__
    printf("             cpu               | ");
#endif // __CPU__

    printf("distance\n");

    printf("------------------|-");
#ifdef __CUDA__
    printf("-------------------------------|-");
#endif // __CUDA__

#ifdef __CPU__
    printf("-------------------------------|-");
#endif // __CPU__

    printf("---------\n");
}

#ifdef __CUDA__
__global__ void LevenshteinCUDA_STEP_0(const unsigned char *dictionary, const unsigned int words, const unsigned char *pattern, unsigned int *result)
{
    int word = blockIdx.x * STEP_0_THREADS + threadIdx.x;
    if(word >= words)
        return;

    result[word * 2] = word;
    result[word * 2 + 1] = LevenshteinDistanceD(pattern, dictionary + word * WORD_MAXLEN);
}

__global__ void LevenshteinCUDA_STEP_R(const unsigned int *from, unsigned int *to, const unsigned int words)
{
    __shared__ unsigned int local_data[STEP_R_THREADS * 2];
    unsigned int tid = threadIdx.x;
    unsigned int i = blockIdx.x * blockDim.x + tid;
    local_data[tid * 2] = from[i * 2];
    local_data[tid * 2 + 1] = from[i * 2 + 1];

    __syncthreads();
    for(unsigned int s = 1; s < blockDim.x && tid + s < words; s <<= 1)
    {
        if(tid % (2 * s) == 0 && local_data[tid * 2 + 1] > local_data[(tid + s) * 2 + 1])
        {
            local_data[tid * 2] = local_data[(tid + s) * 2];
            local_data[tid * 2 + 1] = local_data[(tid + s) * 2 + 1];
        }

        __syncthreads();
    }

    if(tid == 0)
    {
        to[blockIdx.x * 2] = local_data[0];
        to[blockIdx.x * 2 + 1] = local_data[1];
    }
}
#endif // __CUDA__


	.text
	.file	"Levenshtein.hip"
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI0_0:
	.long	0x447a0000                      # float 1000
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI0_1:
	.zero	16
	.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	$168, %rsp
	.cfi_def_cfa_offset 224
	.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, %r12
	cmpl	$2, %edi
	jle	.LBB0_1
# %bb.2:
	movl	%edi, %ebp
	xorl	%eax, %eax
	leaq	36(%rsp), %rdx
	movl	%eax, (%rdx)
	leaq	32(%rsp), %rsi
	movl	%eax, (%rsi)
	movq	8(%r12), %rdi
	callq	_Z14loadDictionaryPKcRjS1_
	testq	%rax, %rax
	je	.LBB0_3
# %bb.4:                                # %.lr.ph48
	movq	%rax, %rbx
	xorl	%eax, %eax
	leaq	88(%rsp), %r15
	movq	%rax, (%r15)
	leaq	80(%rsp), %r14
	movq	%rax, (%r14)
	leaq	24(%rsp), %rcx
	movq	%rax, (%rcx)
	movl	36(%rsp), %r13d
	movq	%r15, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%r15), %rdi
	movq	%rbx, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$16, %esi
	movq	%r14, %rdi
	callq	hipMalloc
	leal	(,%r13,2), %esi
	movabsq	$4294967296, %r13               # imm = 0x100000000
	shlq	$2, %rsi
	leaq	24(%rsp), %rdi
	callq	hipMalloc
	callq	_Z9printHeadv
	movl	32(%rsp), %r15d
	leal	127(%r15), %eax
	shrl	$7, %eax
	btsq	$32, %rax
	movq	%rax, 112(%rsp)                 # 8-byte Spill
	leal	-1(%r15), %eax
	movq	%rax, 136(%rsp)                 # 8-byte Spill
	movl	%ebp, %eax
	movq	%rax, 104(%rsp)                 # 8-byte Spill
	movl	$2, %eax
	leaq	144(%rsp), %rbp
	leaq	128(%r13), %rcx
	movq	%rcx, 96(%rsp)                  # 8-byte Spill
	movq	%r12, 120(%rsp)                 # 8-byte Spill
	movq	%rbx, 56(%rsp)                  # 8-byte Spill
.LBB0_5:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_9 Depth 2
                                        #     Child Loop BB0_14 Depth 2
	movabsq	$4611686019501129728, %rcx      # imm = 0x4000000040000000
	movq	%rcx, 12(%rsp)
	xorps	%xmm0, %xmm0
	movaps	%xmm0, 144(%rsp)
	movw	$0, 160(%rsp)
	movq	%rax, 128(%rsp)                 # 8-byte Spill
	movq	(%r12,%rax,8), %r14
	movq	%r14, %rdi
	callq	strlen
	movq	%rbp, %rdi
	movq	%r14, %rsi
	movq	%rax, %rdx
	callq	memcpy@PLT
	movl	$.L.str.2, %edi
	movq	%rbp, %rsi
	xorl	%eax, %eax
	callq	printf
	leaq	64(%rsp), %rdi
	callq	hipEventCreate
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	80(%rsp), %rdi
	movl	$16, %edx
	movq	%rbp, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	112(%rsp), %rdi                 # 8-byte Reload
	movl	$1, %esi
	movq	96(%rsp), %rbp                  # 8-byte Reload
	movq	%rbp, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_7
# %bb.6:                                #   in Loop: Header=BB0_5 Depth=1
	movq	88(%rsp), %rdi
	movq	80(%rsp), %rdx
	movq	24(%rsp), %rcx
	movl	%r15d, %esi
	callq	_Z37__device_stub__LevenshteinCUDA_STEP_0PKhjS0_Pj
.LBB0_7:                                #   in Loop: Header=BB0_5 Depth=1
	cmpl	$129, %r15d
	jb	.LBB0_12
# %bb.8:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB0_5 Depth=1
	movl	$128, %r14d
.LBB0_9:                                # %.lr.ph
                                        #   Parent Loop BB0_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	136(%rsp), %rax                 # 8-byte Reload
	addl	%r14d, %eax
	xorl	%edx, %edx
	divl	%r14d
                                        # kill: def $eax killed $eax def $rax
	orq	%r13, %rax
	movq	%rax, %rdi
	movl	$1, %esi
	movq	%rbp, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_11
# %bb.10:                               #   in Loop: Header=BB0_9 Depth=2
	movq	24(%rsp), %rdi
	movq	%rdi, %rsi
	movl	%r15d, %edx
	callq	_Z37__device_stub__LevenshteinCUDA_STEP_RPKjPjj
.LBB0_11:                               #   in Loop: Header=BB0_9 Depth=2
	addl	%r14d, %r14d
	cmpl	%r15d, %r14d
	jb	.LBB0_9
.LBB0_12:                               # %._crit_edge
                                        #   in Loop: Header=BB0_5 Depth=1
	movq	24(%rsp), %rsi
	movl	$8, %edx
	leaq	12(%rsp), %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	40(%rsp), %rdi
	xorl	%r12d, %r12d
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	40(%rsp), %rdi
	callq	hipEventSynchronize
	movl	$0, 20(%rsp)
	movq	64(%rsp), %rsi
	movq	40(%rsp), %rdx
	leaq	20(%rsp), %rdi
	callq	hipEventElapsedTime
	movl	12(%rsp), %esi
	movl	16(%rsp), %edx
	shll	$4, %esi
	addq	%rbx, %rsi
	xorps	%xmm0, %xmm0
	cvtss2sd	20(%rsp), %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	leaq	64(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	testl	%r15d, %r15d
	leaq	144(%rsp), %rbp
	je	.LBB0_15
# %bb.13:                               # %.lr.ph.i.preheader
                                        #   in Loop: Header=BB0_5 Depth=1
	movl	$1073741824, %r13d              # imm = 0x40000000
	xorl	%ebx, %ebx
	movq	56(%rsp), %r14                  # 8-byte Reload
	xorl	%r12d, %r12d
.LBB0_14:                               # %.lr.ph.i
                                        #   Parent Loop BB0_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%rbp, %rdi
	movq	%r14, %rsi
	callq	_Z20LevenshteinDistanceHPKhS0_
	movzbl	%al, %eax
	cmpl	%eax, %r13d
	cmovael	%eax, %r13d
	cmoval	%ebx, %r12d
	incl	%ebx
	addq	$16, %r14
	cmpl	%ebx, %r15d
	jne	.LBB0_14
.LBB0_15:                               # %_Z14LevenshteinCPUPKhjS0_.exit
                                        #   in Loop: Header=BB0_5 Depth=1
	movl	%r12d, 12(%rsp)
	leaq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	40(%rsp), %rax
	subq	64(%rsp), %rax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	movq	48(%rsp), %rax
	subq	72(%rsp), %rax
	cvtsi2ss	%rax, %xmm1
	movss	.LCPI0_0(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	mulss	%xmm2, %xmm0
	divss	%xmm2, %xmm1
	addss	%xmm0, %xmm1
	movl	12(%rsp), %esi
	shll	$4, %esi
	movq	56(%rsp), %rbx                  # 8-byte Reload
	addq	%rbx, %rsi
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	movl	12(%rsp), %esi
	shll	$4, %esi
	addq	%rbx, %rsi
	movq	%rbp, %rdi
	callq	_Z20LevenshteinDistanceHPKhS0_
	movzbl	%al, %esi
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	movq	128(%rsp), %rax                 # 8-byte Reload
	incq	%rax
	cmpq	104(%rsp), %rax                 # 8-byte Folded Reload
	movq	120(%rsp), %r12                 # 8-byte Reload
	movabsq	$4294967296, %r13               # imm = 0x100000000
	jne	.LBB0_5
# %bb.16:                               # %._crit_edge49
	movq	88(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	free
	xorl	%eax, %eax
.LBB0_17:
	addq	$168, %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
.LBB0_1:
	.cfi_def_cfa_offset 224
	movq	stderr(%rip), %rdi
	movq	(%r12), %rdx
	movl	$.L.str, %esi
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %eax
	jmp	.LBB0_17
.LBB0_3:
	movq	stderr(%rip), %rbx
	movq	(%r12), %r14
	callq	__errno_location
	movl	(%rax), %edi
	callq	strerror
	movl	$.L.str.1, %esi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	movl	$2, %eax
	jmp	.LBB0_17
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z14loadDictionaryPKcRjS1_      # -- Begin function _Z14loadDictionaryPKcRjS1_
	.type	_Z14loadDictionaryPKcRjS1_,@function
_Z14loadDictionaryPKcRjS1_:             # @_Z14loadDictionaryPKcRjS1_
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdx, %r14
	movq	%rsi, %r15
	movl	$.L.str.5, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_1
# %bb.2:
	movq	%rax, %rbx
	xorps	%xmm0, %xmm0
	movq	%rsp, %rdi
	movaps	%xmm0, 48(%rdi)
	movaps	%xmm0, 32(%rdi)
	movaps	%xmm0, 16(%rdi)
	movaps	%xmm0, (%rdi)
	movl	$0, (%r15)
	movl	$64, %esi
	movq	%rax, %rdx
	callq	fgets
	testq	%rax, %rax
	je	.LBB1_5
# %bb.3:                                # %.lr.ph.preheader
	movq	%rsp, %r12
.LBB1_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	incl	(%r15)
	movq	%r12, %rdi
	movl	$64, %esi
	movq	%rbx, %rdx
	callq	fgets
	testq	%rax, %rax
	jne	.LBB1_4
.LBB1_5:                                # %._crit_edge
	movq	%rbx, %rdi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	fseek
	movl	(%r15), %r15d
	shll	$4, %r15d
	movl	%r15d, (%r14)
	movq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r14
	movq	%rax, %rdi
	xorl	%esi, %esi
	movq	%r15, %rdx
	callq	memset@PLT
	movq	%r14, %rdi
	movl	$24, %esi
	movq	%rbx, %rdx
	callq	fgets
	testq	%rax, %rax
	je	.LBB1_8
# %bb.6:                                # %.lr.ph29.preheader
	xorl	%ebp, %ebp
	movq	%r14, %r15
.LBB1_7:                                # %.lr.ph29
                                        # =>This Inner Loop Header: Depth=1
	movq	%r15, %rdi
	callq	strlen
	movb	%bpl, -1(%rax,%r15)
	movq	%r15, %rdi
	callq	strlen
	movb	%bpl, -1(%rax,%r15)
	addq	$16, %r15
	movq	%r15, %rdi
	movl	$24, %esi
	movq	%rbx, %rdx
	callq	fgets
	testq	%rax, %rax
	jne	.LBB1_7
.LBB1_8:                                # %._crit_edge30
	movq	%rbx, %rdi
	callq	fclose
	jmp	.LBB1_9
.LBB1_1:
	xorl	%r14d, %r14d
.LBB1_9:
	movq	%r14, %rax
	addq	$64, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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_end1:
	.size	_Z14loadDictionaryPKcRjS1_, .Lfunc_end1-_Z14loadDictionaryPKcRjS1_
	.cfi_endproc
                                        # -- End function
	.globl	_Z9printHeadv                   # -- Begin function _Z9printHeadv
	.type	_Z9printHeadv,@function
_Z9printHeadv:                          # @_Z9printHeadv
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.L.str.10, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.1, %edi
	popq	%rax
	.cfi_def_cfa_offset 8
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end2:
	.size	_Z9printHeadv, .Lfunc_end2-_Z9printHeadv
	.cfi_endproc
                                        # -- End function
	.globl	_Z37__device_stub__LevenshteinCUDA_STEP_0PKhjS0_Pj # -- Begin function _Z37__device_stub__LevenshteinCUDA_STEP_0PKhjS0_Pj
	.type	_Z37__device_stub__LevenshteinCUDA_STEP_0PKhjS0_Pj,@function
_Z37__device_stub__LevenshteinCUDA_STEP_0PKhjS0_Pj: # @_Z37__device_stub__LevenshteinCUDA_STEP_0PKhjS0_Pj
	.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	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	4(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	24(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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_end3:
	.size	_Z37__device_stub__LevenshteinCUDA_STEP_0PKhjS0_Pj, .Lfunc_end3-_Z37__device_stub__LevenshteinCUDA_STEP_0PKhjS0_Pj
	.cfi_endproc
                                        # -- End function
	.globl	_Z37__device_stub__LevenshteinCUDA_STEP_RPKjPjj # -- Begin function _Z37__device_stub__LevenshteinCUDA_STEP_RPKjPjj
	.type	_Z37__device_stub__LevenshteinCUDA_STEP_RPKjPjj,@function
_Z37__device_stub__LevenshteinCUDA_STEP_RPKjPjj: # @_Z37__device_stub__LevenshteinCUDA_STEP_RPKjPjj
	.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	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%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	$_Z22LevenshteinCUDA_STEP_RPKjPjj, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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_end4:
	.size	_Z37__device_stub__LevenshteinCUDA_STEP_RPKjPjj, .Lfunc_end4-_Z37__device_stub__LevenshteinCUDA_STEP_RPKjPjj
	.cfi_endproc
                                        # -- End function
	.globl	_Z14LevenshteinCPUPKhjS0_       # -- Begin function _Z14LevenshteinCPUPKhjS0_
	.type	_Z14LevenshteinCPUPKhjS0_,@function
_Z14LevenshteinCPUPKhjS0_:              # @_Z14LevenshteinCPUPKhjS0_
	.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
	testl	%esi, %esi
	je	.LBB5_1
# %bb.3:                                # %.lr.ph.preheader
	movq	%rdx, %rbx
	movl	%esi, %ebp
	movq	%rdi, %r14
	movl	$1073741824, %r12d              # imm = 0x40000000
	xorl	%r13d, %r13d
	xorl	%r15d, %r15d
.LBB5_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	_Z20LevenshteinDistanceHPKhS0_
	movzbl	%al, %eax
	cmpl	%eax, %r12d
	cmovael	%eax, %r12d
	cmoval	%r13d, %r15d
	incl	%r13d
	addq	$16, %r14
	cmpl	%r13d, %ebp
	jne	.LBB5_4
	jmp	.LBB5_2
.LBB5_1:
	xorl	%r15d, %r15d
.LBB5_2:                                # %._crit_edge
	movl	%r15d, %eax
	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
.Lfunc_end5:
	.size	_Z14LevenshteinCPUPKhjS0_, .Lfunc_end5-_Z14LevenshteinCPUPKhjS0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z20LevenshteinDistanceHPKhS0_  # -- Begin function _Z20LevenshteinDistanceHPKhS0_
	.type	_Z20LevenshteinDistanceHPKhS0_,@function
_Z20LevenshteinDistanceHPKhS0_:         # @_Z20LevenshteinDistanceHPKhS0_
	.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	%rbx
	.cfi_def_cfa_offset 40
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movq	%rsi, %rdi
	callq	strlen
	xorl	%ecx, %ecx
.LBB6_1:                                # =>This Inner Loop Header: Depth=1
	movb	%cl, (%rsp,%rcx)
	incq	%rcx
	cmpb	%al, %cl
	jbe	.LBB6_1
# %bb.2:                                # %.preheader
	movb	(%r14), %dl
	testb	%dl, %dl
	je	.LBB6_3
# %bb.5:                                # %.lr.ph48
	movb	$1, %sil
	movb	$1, %dil
.LBB6_6:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_8 Depth 2
	movzbl	%dil, %ecx
	movl	%ecx, %r8d
	shll	$4, %r8d
	addq	%rcx, %r8
	movl	%ecx, %edi
	xorb	$1, %dil
	movb	%sil, (%rsp,%r8)
	testb	%al, %al
	je	.LBB6_9
# %bb.7:                                # %.lr.ph
                                        #   in Loop: Header=BB6_6 Depth=1
	movzbl	%dil, %r9d
	movl	%ecx, %r8d
	shll	$4, %r8d
	addq	%rcx, %r8
	addq	%rsp, %r8
	movb	(%r8), %r11b
	movl	%r9d, %r10d
	shll	$4, %r10d
	addq	%r9, %r10
	leaq	(%rsp,%r10), %r9
	movl	$1, %r10d
.LBB6_8:                                #   Parent Loop BB6_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movb	(%r9,%r10), %bpl
	incb	%bpl
	incb	%r11b
	cmpb	-1(%rbx,%r10), %dl
	setne	%r15b
	addb	-1(%r9,%r10), %r15b
	movzbl	%r11b, %r11d
	movzbl	%r15b, %r15d
	cmpb	%r15b, %r11b
	cmovbl	%r11d, %r15d
	movzbl	%bpl, %r11d
	cmpb	%r15b, %r11b
	cmovbl	%r11d, %r15d
	movb	%r15b, (%r8,%r10)
	incq	%r10
	movl	%r15d, %r11d
	cmpb	%al, %r10b
	jbe	.LBB6_8
.LBB6_9:                                # %._crit_edge
                                        #   in Loop: Header=BB6_6 Depth=1
	incb	%sil
	movb	1(%r14), %dl
	incq	%r14
	testb	%dl, %dl
	jne	.LBB6_6
	jmp	.LBB6_4
.LBB6_3:
	xorl	%ecx, %ecx
.LBB6_4:                                # %._crit_edge49
	movzbl	%al, %eax
	movl	%ecx, %edx
	shll	$4, %edx
	addq	%rcx, %rdx
	leaq	(%rsp,%rdx), %rcx
	movb	(%rax,%rcx), %al
	addq	$40, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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_end6:
	.size	_Z20LevenshteinDistanceHPKhS0_, .Lfunc_end6-_Z20LevenshteinDistanceHPKhS0_
	.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:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z22LevenshteinCUDA_STEP_RPKjPjj, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"usage: %s dictionary words...\nError: not enough arguments\n"
	.size	.L.str, 59

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"usage: %s dictionary words...\nError: loading dictionary: %s\n"
	.size	.L.str.1, 61

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	" %-16s | "
	.size	.L.str.2, 10

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

	.type	_Z22LevenshteinCUDA_STEP_RPKjPjj,@object # @_Z22LevenshteinCUDA_STEP_RPKjPjj
	.globl	_Z22LevenshteinCUDA_STEP_RPKjPjj
	.p2align	3, 0x0
_Z22LevenshteinCUDA_STEP_RPKjPjj:
	.quad	_Z37__device_stub__LevenshteinCUDA_STEP_RPKjPjj
	.size	_Z22LevenshteinCUDA_STEP_RPKjPjj, 8

	.type	.L.str.3,@object                # @.str.3
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.3:
	.asciz	"%-16s [%11.6f] | "
	.size	.L.str.3, 18

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%u\n"
	.size	.L.str.4, 4

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

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"       word       | "
	.size	.L.str.6, 21

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"             gpu               | "
	.size	.L.str.7, 34

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"             cpu               | "
	.size	.L.str.8, 34

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"------------------|-"
	.size	.L.str.10, 21

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"-------------------------------|-"
	.size	.L.str.11, 34

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj"
	.size	.L__unnamed_1, 36

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z22LevenshteinCUDA_STEP_RPKjPjj"
	.size	.L__unnamed_2, 33

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

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

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

	.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 _Z37__device_stub__LevenshteinCUDA_STEP_0PKhjS0_Pj
	.addrsig_sym _Z37__device_stub__LevenshteinCUDA_STEP_RPKjPjj
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z22LevenshteinCUDA_STEP_0PKhjS0_Pj
	.addrsig_sym _Z22LevenshteinCUDA_STEP_RPKjPjj
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj ; -- Begin function _Z22LevenshteinCUDA_STEP_0PKhjS0_Pj
	.globl	_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj
	.p2align	8
	.type	_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj,@function
_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj:    ; @_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj
; %bb.0:
	s_load_b32 s4, s[2:3], 0x8
	v_and_b32_e32 v8, 0x3ff, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshl_add_u32 v5, s15, 7, v8
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_u32_e32 vcc_lo, s4, v5
	s_and_saveexec_b32 s4, vcc_lo
	s_cbranch_execz .LBB0_9
; %bb.1:
	s_clause 0x1
	s_load_b128 s[4:7], s[2:3], 0x10
	s_load_b64 s[2:3], s[2:3], 0x0
	v_lshlrev_b32_e32 v1, 1, v5
	v_lshlrev_b32_e32 v6, 4, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v1, vcc_lo, s6, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s7, v2, vcc_lo
	s_mov_b32 s7, 0
	s_mov_b32 s6, exec_lo
	global_store_b32 v[1:2], v5, off
	v_mov_b32_e32 v5, 0
	v_ashrrev_i32_e32 v9, 31, v6
	v_add_co_u32 v3, vcc_lo, s2, v6
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s3, v9, vcc_lo
	global_load_u8 v7, v[3:4], off
	s_waitcnt vmcnt(0)
	v_cmpx_ne_u16_e32 0, v7
	s_cbranch_execz .LBB0_5
; %bb.2:                                ; %.lr.ph.i.preheader
	v_add_co_u32 v5, vcc_lo, v6, s2
	v_add_co_ci_u32_e32 v6, vcc_lo, s3, v9, vcc_lo
	v_mov_b32_e32 v9, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v5, vcc_lo, v5, 1
	v_add_co_ci_u32_e32 v6, vcc_lo, 0, v6, vcc_lo
.LBB0_3:                                ; %.lr.ph.i
                                        ; =>This Inner Loop Header: Depth=1
	global_load_u8 v10, v[5:6], off
	v_and_b32_e32 v9, 0xff, v9
	v_add_co_u32 v5, vcc_lo, v5, 1
	v_add_co_ci_u32_e32 v6, vcc_lo, 0, v6, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_add_nc_u16 v9, v9, 1
	s_waitcnt vmcnt(0)
	v_cmp_eq_u16_e64 s2, 0, v10
	s_or_b32 s7, s2, s7
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s7
	s_cbranch_execnz .LBB0_3
; %bb.4:                                ; %._crit_edge.loopexit.i
	s_or_b32 exec_lo, exec_lo, s7
	v_and_b32_e32 v5, 0xff, v9
.LBB0_5:                                ; %Flow33
	s_or_b32 exec_lo, exec_lo, s6
	s_load_b64 s[0:1], s[0:1], 0x4
	v_bfe_u32 v9, v0, 10, 10
	v_mov_b32_e32 v6, 0
	v_bfe_u32 v0, v0, 20, 10
	v_mov_b32_e32 v10, 0xb0a0908
	v_dual_mov_b32 v11, 0xf0e0d0c :: v_dual_mov_b32 v12, 16
	s_mov_b32 s2, 0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s0, s0, 16
	v_mul_u32_u24_e32 v9, s1, v9
	s_mul_i32 s0, s0, s1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v8, s0, v8
	v_add3_u32 v0, v8, v9, v0
	v_mov_b32_e32 v9, 0x7060504
	global_load_u8 v22, v6, s[4:5]
	v_mov_b32_e32 v8, 0x3020100
	v_mul_lo_u32 v0, v0, 34
	ds_store_b128 v0, v[8:11]
	ds_store_b8 v0, v12 offset:16
	s_waitcnt vmcnt(0)
	v_cmp_eq_u16_e32 vcc_lo, 0, v22
	s_cbranch_vccnz .LBB0_8
; %bb.6:                                ; %.lr.ph47.preheader.i
	s_clause 0x3
	global_load_u16 v11, v[3:4], off offset:13
	global_load_b64 v[8:9], v[3:4], off offset:1
	global_load_i8 v23, v[3:4], off offset:15
	global_load_b32 v12, v[3:4], off offset:9
	v_mov_b32_e32 v3, 1
	s_add_u32 s0, s4, 1
	s_addc_u32 s1, s5, 0
	s_mov_b32 s3, 1
	s_waitcnt vmcnt(3)
	v_and_b32_e32 v13, 0xffff, v11
	s_waitcnt vmcnt(2)
	v_lshrrev_b64 v[19:20], 24, v[8:9]
	v_lshrrev_b32_e32 v14, 8, v8
	v_lshrrev_b32_e32 v15, 16, v8
	v_and_b32_e32 v8, 0xff, v8
	s_waitcnt vmcnt(0)
	v_lshrrev_b64 v[20:21], 24, v[12:13]
	v_lshrrev_b32_e32 v16, 8, v9
	v_lshrrev_b32_e32 v17, 16, v9
	v_lshrrev_b32_e32 v18, 8, v12
	v_lshrrev_b32_e32 v24, 16, v12
	v_lshrrev_b32_e32 v4, 24, v9
	v_and_b32_e32 v9, 0xff, v9
	v_and_b32_e32 v10, 0xff, v12
	v_and_b32_e32 v11, 0xff, v11
	v_lshrrev_b32_e32 v12, 8, v13
	v_and_b32_e32 v13, 0xff, v14
	v_and_b32_e32 v14, 0xff, v15
	v_and_b32_e32 v15, 0xff, v16
	v_and_b32_e32 v16, 0xff, v17
	v_and_b32_e32 v17, 0xff, v18
	v_and_b32_e32 v18, 0xff, v24
	v_and_b32_e32 v19, 0xff, v19
	v_and_b32_e32 v20, 0xff, v20
	v_and_b32_e32 v21, 0xff, v23
.LBB0_7:                                ; %.lr.ph47.i
                                        ; =>This Inner Loop Header: Depth=1
	s_and_b32 s2, s3, 0xff
	v_and_b32_e32 v26, 0xff, v3
	s_xor_b32 s3, s2, 1
	v_mad_u64_u32 v[23:24], null, s2, 17, v[0:1]
	v_mad_u64_u32 v[24:25], null, s3, 17, v[0:1]
	v_and_b32_e32 v27, 0xff, v22
	global_load_u8 v22, v6, s[0:1]
	s_add_u32 s0, s0, 1
	s_addc_u32 s1, s1, 0
	ds_store_b8 v23, v3
	v_add_nc_u16 v3, v26, 1
	ds_load_u8 v26, v24 offset:1
	ds_load_u8 v34, v24
	v_cmp_ne_u16_e32 vcc_lo, v27, v7
	v_and_b32_e32 v35, 0xff, v3
	v_cndmask_b32_e64 v25, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v8
	v_cndmask_b32_e64 v28, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v13
	v_cndmask_b32_e64 v29, 0, 1, vcc_lo
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v25, v34, v25
	v_cmp_ne_u16_e32 vcc_lo, v27, v14
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_and_b32_e32 v26, 0xff, v26
	v_and_b32_e32 v25, 0xff, v25
	v_cndmask_b32_e64 v30, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v19
	s_delay_alu instid0(VALU_DEP_3)
	v_min3_u16 v25, v26, v35, v25
	v_cndmask_b32_e64 v31, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v9
	ds_store_b8 v23, v25 offset:1
	ds_load_u8 v26, v24 offset:2
	ds_load_u8 v34, v24 offset:1
	v_add_nc_u16 v25, v25, 1
	v_cndmask_b32_e64 v32, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v15
	s_delay_alu instid0(VALU_DEP_3)
	v_and_b32_e32 v25, 0xff, v25
	v_cndmask_b32_e64 v33, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v16
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v34, v28
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_and_b32_e32 v26, 0xff, v26
	v_and_b32_e32 v28, 0xff, v28
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_min3_u16 v25, v26, v25, v28
	ds_store_b8 v23, v25 offset:2
	ds_load_u8 v26, v24 offset:3
	ds_load_u8 v28, v24 offset:2
	v_add_nc_u16 v25, v25, 1
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v28, v29
	v_cndmask_b32_e64 v29, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v4
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v28, 0xff, v28
	v_min3_u16 v25, v26, v25, v28
	ds_store_b8 v23, v25 offset:3
	ds_load_u8 v26, v24 offset:4
	ds_load_u8 v28, v24 offset:3
	v_add_nc_u16 v25, v25, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v28, v30
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v28, 0xff, v28
	v_min3_u16 v25, v26, v25, v28
	ds_store_b8 v23, v25 offset:4
	ds_load_u8 v26, v24 offset:5
	ds_load_u8 v28, v24 offset:4
	v_add_nc_u16 v25, v25, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v28, v31
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v28, 0xff, v28
	v_min3_u16 v25, v26, v25, v28
	ds_store_b8 v23, v25 offset:5
	ds_load_u8 v26, v24 offset:6
	ds_load_u8 v28, v24 offset:5
	v_add_nc_u16 v25, v25, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v28, v32
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v28, 0xff, v28
	v_min3_u16 v25, v26, v25, v28
	ds_store_b8 v23, v25 offset:6
	ds_load_u8 v26, v24 offset:7
	ds_load_u8 v28, v24 offset:6
	v_add_nc_u16 v25, v25, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v28, v33
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v28, 0xff, v28
	v_min3_u16 v25, v26, v25, v28
	ds_store_b8 v23, v25 offset:7
	ds_load_u8 v26, v24 offset:8
	ds_load_u8 v28, v24 offset:7
	v_add_nc_u16 v25, v25, 1
	s_delay_alu instid0(VALU_DEP_1)
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v28, v29
	v_cndmask_b32_e64 v29, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v10
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v28, 0xff, v28
	v_min3_u16 v25, v26, v25, v28
	ds_store_b8 v23, v25 offset:8
	ds_load_u8 v26, v24 offset:9
	ds_load_u8 v28, v24 offset:8
	v_add_nc_u16 v25, v25, 1
	s_delay_alu instid0(VALU_DEP_1)
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v28, v29
	v_cndmask_b32_e64 v29, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v17
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v28, 0xff, v28
	v_min3_u16 v25, v26, v25, v28
	ds_store_b8 v23, v25 offset:9
	ds_load_u8 v26, v24 offset:10
	ds_load_u8 v28, v24 offset:9
	v_add_nc_u16 v25, v25, 1
	s_delay_alu instid0(VALU_DEP_1)
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v28, v29
	v_cndmask_b32_e64 v29, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v18
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v28, 0xff, v28
	v_min3_u16 v25, v26, v25, v28
	ds_store_b8 v23, v25 offset:10
	ds_load_u8 v26, v24 offset:11
	ds_load_u8 v28, v24 offset:10
	v_add_nc_u16 v25, v25, 1
	s_delay_alu instid0(VALU_DEP_1)
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v28, v29
	v_cndmask_b32_e64 v29, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v20
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v28, 0xff, v28
	v_min3_u16 v25, v26, v25, v28
	ds_store_b8 v23, v25 offset:11
	ds_load_u8 v26, v24 offset:12
	ds_load_u8 v28, v24 offset:11
	v_add_nc_u16 v25, v25, 1
	s_delay_alu instid0(VALU_DEP_1)
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v28, v29
	v_cndmask_b32_e64 v29, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v11
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v28, 0xff, v28
	v_min3_u16 v25, v26, v25, v28
	ds_store_b8 v23, v25 offset:12
	ds_load_u8 v26, v24 offset:13
	ds_load_u8 v28, v24 offset:12
	v_add_nc_u16 v25, v25, 1
	s_delay_alu instid0(VALU_DEP_1)
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v28, v29
	v_cndmask_b32_e64 v29, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v12
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v28, 0xff, v28
	v_min3_u16 v25, v26, v25, v28
	ds_store_b8 v23, v25 offset:13
	ds_load_u8 v26, v24 offset:14
	ds_load_u8 v28, v24 offset:13
	v_add_nc_u16 v25, v25, 1
	s_delay_alu instid0(VALU_DEP_1)
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v28, v29
	v_cndmask_b32_e64 v29, 0, 1, vcc_lo
	v_cmp_ne_u16_e32 vcc_lo, v27, v21
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_and_b32_e32 v28, 0xff, v28
	v_cndmask_b32_e64 v27, 0, 1, vcc_lo
	s_waitcnt vmcnt(0)
	v_cmp_ne_u16_e32 vcc_lo, 0, v22
	v_min3_u16 v25, v26, v25, v28
	s_and_b32 vcc_lo, exec_lo, vcc_lo
	ds_store_b8 v23, v25 offset:14
	ds_load_u8 v26, v24 offset:15
	ds_load_u8 v28, v24 offset:14
	v_add_nc_u16 v25, v25, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v28, v28, v29
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v28, 0xff, v28
	v_min3_u16 v25, v26, v25, v28
	ds_store_b8 v23, v25 offset:15
	ds_load_u8 v26, v24 offset:16
	ds_load_u8 v24, v24 offset:15
	v_add_nc_u16 v25, v25, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_and_b32_e32 v25, 0xff, v25
	s_waitcnt lgkmcnt(1)
	v_add_nc_u16 v26, v26, 1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u16 v24, v24, v27
	v_and_b32_e32 v26, 0xff, v26
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v24, 0xff, v24
	v_min3_u16 v24, v26, v25, v24
	ds_store_b8 v23, v24 offset:16
	s_cbranch_vccnz .LBB0_7
.LBB0_8:                                ; %_Z20LevenshteinDistanceDPKhS0_.exit
	s_mul_i32 s0, s2, 17
	s_delay_alu instid0(SALU_CYCLE_1)
	v_add3_u32 v0, v0, s0, v5
	ds_load_u8 v0, v0
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[1:2], v0, off offset:4
.LBB0_9:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z22LevenshteinCUDA_STEP_0PKhjS0_Pj
		.amdhsa_group_segment_fixed_size 34816
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 32
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 1
		.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 2
		.amdhsa_next_free_vgpr 36
		.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	_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj, .Lfunc_end0-_Z22LevenshteinCUDA_STEP_0PKhjS0_Pj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 2516
; NumSgprs: 18
; NumVgprs: 36
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 34816 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 4
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 36
; 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: 2
	.text
	.protected	_Z22LevenshteinCUDA_STEP_RPKjPjj ; -- Begin function _Z22LevenshteinCUDA_STEP_RPKjPjj
	.globl	_Z22LevenshteinCUDA_STEP_RPKjPjj
	.p2align	8
	.type	_Z22LevenshteinCUDA_STEP_RPKjPjj,@function
_Z22LevenshteinCUDA_STEP_RPKjPjj:       ; @_Z22LevenshteinCUDA_STEP_RPKjPjj
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b128 s[4:7], s[0:1], 0x0
	v_dual_mov_b32 v2, 0 :: v_dual_lshlrev_b32 v3, 3, v0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	s_mul_i32 s3, s15, s2
	s_cmp_lt_u32 s2, 2
	v_add_lshl_u32 v1, s3, v0, 1
	s_mov_b32 s3, 1
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v1, vcc_lo, s4, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s5, v2, vcc_lo
	global_load_b64 v[1:2], v[1:2], off
	s_waitcnt vmcnt(0)
	ds_store_b64 v3, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB1_9
; %bb.1:                                ; %.lr.ph.preheader
	s_load_b32 s1, s[0:1], 0x10
	s_mov_b32 s0, 0
                                        ; implicit-def: $sgpr4
.LBB1_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	v_add_nc_u32_e32 v1, s3, v0
	s_or_b32 s4, s4, exec_lo
	s_mov_b32 s5, exec_lo
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_u32_e64 s1, v1
	s_cbranch_execz .LBB1_7
; %bb.3:                                ;   in Loop: Header=BB1_2 Depth=1
	s_lshl_b32 s3, s3, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s8, s3, -1
	v_and_b32_e32 v2, s8, v0
	s_mov_b32 s8, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_eq_u32_e32 0, v2
	s_cbranch_execz .LBB1_6
; %bb.4:                                ;   in Loop: Header=BB1_2 Depth=1
	v_lshlrev_b32_e32 v1, 3, v1
	ds_load_b32 v4, v3 offset:4
	ds_load_b32 v2, v1 offset:4
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_u32_e32 vcc_lo, v4, v2
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB1_6
; %bb.5:                                ;   in Loop: Header=BB1_2 Depth=1
	ds_load_b32 v1, v1
	s_waitcnt lgkmcnt(0)
	ds_store_b64 v3, v[1:2]
.LBB1_6:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s8
	s_cmp_ge_u32 s3, s2
	s_waitcnt lgkmcnt(0)
	s_cselect_b32 s8, -1, 0
	s_and_not1_b32 s4, s4, exec_lo
	s_and_b32 s8, s8, exec_lo
	s_barrier
	s_or_b32 s4, s4, s8
	buffer_gl0_inv
.LBB1_7:                                ; %Flow38
                                        ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s5
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s5, exec_lo, s4
	s_or_b32 s0, s5, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s0
	s_cbranch_execnz .LBB1_2
; %bb.8:                                ; %Flow39
	s_or_b32 exec_lo, exec_lo, s0
.LBB1_9:                                ; %.critedge
	s_mov_b32 s1, 0
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB1_11
; %bb.10:
	v_mov_b32_e32 v2, 0
	s_lshl_b32 s0, s15, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b64 s[0:1], s[0:1], 2
	s_add_u32 s0, s6, s0
	ds_load_b64 v[0:1], v2
	s_addc_u32 s1, s7, s1
	s_waitcnt lgkmcnt(0)
	global_store_b64 v2, v[0:1], s[0:1]
.LBB1_11:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z22LevenshteinCUDA_STEP_RPKjPjj
		.amdhsa_group_segment_fixed_size 1024
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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 5
		.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_end1:
	.size	_Z22LevenshteinCUDA_STEP_RPKjPjj, .Lfunc_end1-_Z22LevenshteinCUDA_STEP_RPKjPjj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 404
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 1024 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 34816
    .kernarg_segment_align: 8
    .kernarg_segment_size: 32
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z22LevenshteinCUDA_STEP_0PKhjS0_Pj
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z22LevenshteinCUDA_STEP_0PKhjS0_Pj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     36
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 1024
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z22LevenshteinCUDA_STEP_RPKjPjj
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z22LevenshteinCUDA_STEP_RPKjPjj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
