#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <math.h> 
#include <cuda.h>
#include <algorithm>


#define BLOCK_SIZE 1024
__device__ unsigned int counter, counter_2;
//__device__ unsigned int flag;
__constant__ const unsigned int INTMAX = 2147483647;

// struct for dictionary
struct huffmanDictionary{
    unsigned char bitSequence[255];
    unsigned char bitSequenceLength;
};

// struct for node
struct huffmanNode{
    unsigned char letter;  // char to store
    unsigned int frequency;  // frequency of the char
    struct huffmanNode * left;  // left sub tree
    struct huffmanNode * right;  // right sub tree
};

struct huffmanDictionary huffmanDictionary[256];
struct huffmanNode * huffmanNode_head;
struct huffmanNode huffmanTreeNode[512];

#define DEBUG 1

__device__ int findIndex(unsigned int *freq, unsigned int size,unsigned int search){
    for(int i=0;i<size;i++){
        if(freq[i] == search){
            return i;
        }
    }
    return -1;
}
__global__ void findLeastFrequent(unsigned int *freq, unsigned int *min, int size, unsigned int threads, unsigned int* count, unsigned int *index){
    int id = blockIdx.x*blockDim.x + threadIdx.x;
    counter_2 = 0;
    __syncthreads();
    int ind;
    
    if(id<threads){
        
        while(1){
            min[counter_2] = INTMAX;
            
            atomicMin(&min[counter_2], freq[id]);
            // Need global barrier
            __syncthreads();
            
            ind = findIndex(freq, threads, min[counter_2]);
            index[counter_2] = ind;
            // Need global barrier
            __syncthreads();
            freq[ind] = INTMAX;
            
            if(id == 0) atomicInc(&counter_2, size);
            // Need global barrier
            __syncthreads();

            min[counter_2] = INTMAX;
            
            atomicMin(&min[counter_2], freq[id]);
            // Need global barrier
            __syncthreads();
            
            ind = findIndex(freq, threads, min[counter_2]);
            index[counter_2] = ind;
            // Need global barrier
            __syncthreads();
            freq[ind] = min[counter_2] + min[counter_2-1];
            
            if(id == 0) atomicInc(&counter_2, size);
            // Need global barrier
            __syncthreads();
            

            if(min[counter_2] == INTMAX || min[counter_2-1] == INTMAX){
                count[0] = counter_2;
                break;
            }
            
        }
    }
}

__global__ void searchSimilarIndex(unsigned int *index, unsigned int *resultIndex, unsigned int *cnt, int threads){
    int id = blockIdx.x*blockDim.x + threadIdx.x;
    
    __syncthreads();
    counter = 0;
    if(id != threads){
        if(index[id] == index[threads]){
            
            int temp = atomicInc(&counter, threads+1);
            resultIndex[temp] = id;
        }
        __syncthreads();
        cnt[0] = counter;
    }
}



void buildHuffmanTree(int count,unsigned char *uniqueChar, unsigned int *frequency,int newIndex, int childIndex){
    if(count == 0){
        
        huffmanTreeNode[newIndex].frequency = frequency[childIndex];
        huffmanTreeNode[newIndex].letter = uniqueChar[childIndex];
        huffmanTreeNode[newIndex].left = NULL;
        huffmanTreeNode[newIndex].right = NULL;
    }
    else{
        
        huffmanTreeNode[newIndex].frequency = huffmanTreeNode[childIndex].frequency + huffmanTreeNode[childIndex + 1].frequency;
        huffmanTreeNode[newIndex].left = & huffmanTreeNode[childIndex];
        huffmanTreeNode[newIndex].right = & huffmanTreeNode[childIndex + 1];
        huffmanNode_head = & (huffmanTreeNode[newIndex]);
    }
}

void buildHuffmanDictionary(struct huffmanNode * root, unsigned char * bitSequence, unsigned char bitSequenceLength){
    if(root -> left){
        bitSequence[bitSequenceLength] = 0;
        buildHuffmanDictionary(root -> left, bitSequence, bitSequenceLength + 1);
    }

    if(root -> right){
        bitSequence[bitSequenceLength] = 1;
        buildHuffmanDictionary(root -> right, bitSequence, bitSequenceLength + 1);
    }

    // copy the bit sequence and the length to the dictionary
    if(root -> right == NULL && root -> left == NULL){
        huffmanDictionary[root -> letter].bitSequenceLength = bitSequenceLength;
        memcpy(huffmanDictionary[root -> letter].bitSequence, bitSequence, bitSequenceLength * sizeof(unsigned char));
    }
}


int main(int argc, char ** argv){

    clock_t start, end;
    unsigned int cpuTime;
    unsigned int compressedFileLength, outputFileLengthCounter, outputFileLength, extra;
    unsigned int distinctCharacterCount;
    unsigned int frequency[256];

    unsigned char bitSequenceLength = 0, bitSequence[255];
    unsigned char * compressedData, * outputData;
    struct huffmanNode * huffmanNode_current;

    FILE *compressedFile, *outputFile;

    // read input file get length, frequency and data
    compressedFile = fopen(argv[1], "r");
    
    fread(& outputFileLength, sizeof(unsigned int), 1, compressedFile);
    //no. of extra bits added, calculate here
    fread(& extra, sizeof(unsigned int), 1, compressedFile);
    fread(frequency, 256 * sizeof(unsigned int), 1, compressedFile);

    // find length of the compressed file
    fseek(compressedFile, 0, SEEK_END);
    compressedFileLength = ftell(compressedFile) - 1032;
    
    fseek(compressedFile, 1032, SEEK_SET);

    // allocate the required memory, read the file
    compressedData = (unsigned char *)malloc((compressedFileLength) * sizeof(unsigned char));
    fread(compressedData, sizeof(unsigned char), compressedFileLength, compressedFile);

    // start the clock, tick tick
    start = clock();

    // for(int i=0;i<256;i++) printf("%c ",frequency[i]);
    // printf("\n");
    // initialize the huffman tree
    distinctCharacterCount = 0;
    for(int i = 0; i < 256; i++){
        if(frequency[i] > 0){
            distinctCharacterCount ++;
        }
    }

    int unique = 0;
    unsigned char *uniqueChar, *duniqueChar;
    uniqueChar = (unsigned char *)malloc(256*sizeof(unsigned char));
    cudaMalloc(&duniqueChar, 256*sizeof(unsigned char));
    for(int i = 0; i<256; i++){
        if(frequency[i] > 0){
            uniqueChar[unique++] = i;
            //printf("%d ",frequency[i]);
        }
    }
    //printf("\n");
    cudaMemcpy(duniqueChar, uniqueChar, 256*sizeof(unsigned char), cudaMemcpyHostToDevice);

    // *** FIND MINIMUM 2 FREQUENCY FOR ADDING NEW NODE ***
    unsigned int *tempFreq, *tempDFreq;
    unsigned int *min, *dmin;
    unsigned int *cntMin, *dcntMin;
    unsigned int *indMin, *dindMin;
    int ctr;

    tempFreq = (unsigned int *)malloc(unique*sizeof(unsigned int));
    
    min = (unsigned int *)malloc(outputFileLength*sizeof(unsigned int));
    cntMin = (unsigned int *)malloc(sizeof(unsigned int));
    indMin = (unsigned int *)malloc(outputFileLength*sizeof(unsigned int));
    ctr = 0;
    for(unsigned int i=0;i<256;i++){
        if(frequency[i]!=0){
            tempFreq[ctr++] = frequency[i];
        }
    }
    // for(unsigned int i=0;i<unique;i++) printf("%d:%c ",tempFreq[i],uniqueChar[i]);
    // printf("\n");
    
    cudaMalloc(&tempDFreq, unique*sizeof(unsigned int));
    
    cudaMalloc(&dmin, outputFileLength*sizeof(unsigned int));
    cudaMalloc(&dindMin, outputFileLength*sizeof(unsigned int));
    cudaMalloc(&dcntMin, sizeof(unsigned int));
    cudaMemcpy(tempDFreq, tempFreq, unique*sizeof(unsigned int), cudaMemcpyHostToDevice);

    float num = (float)(unique)/(float)BLOCK_SIZE;
    //num = (float)(5)/(float)BLOCK_SIZE;
    int mod = BLOCK_SIZE;
    if(unique < BLOCK_SIZE) mod = unique%BLOCK_SIZE;
    //if(5 < BLOCKSIZE) mod = 5%BLOCK_SIZE;
    int n = ceil(num);
    //printf("%d %d\n",n,mod);
    findLeastFrequent<<<n, mod>>>(tempDFreq, dmin, outputFileLength, unique, dcntMin, dindMin);
    
    cudaDeviceSynchronize();

    cudaMemcpy(min, dmin, outputFileLength*sizeof(unsigned int), cudaMemcpyDeviceToHost);
    cudaMemcpy(indMin, dindMin, outputFileLength*sizeof(unsigned int), cudaMemcpyDeviceToHost);
    cudaMemcpy(cntMin, dcntMin, sizeof(unsigned int), cudaMemcpyDeviceToHost);
    // printf("count : %d\n",cntMin[0]);
    // for(unsigned int i=0;i<cntMin[0];i++){
    //     printf("%d:%d:%d ",i,indMin[i],min[i]);
    // } 
    // printf("\n");
    // printf("Min:\n");
    // for(unsigned int i=0;i<cntMin[0];i++) printf("%d ",min[i]);
    // printf("\nIndMin:\n");
    // for(unsigned int i=0;i<cntMin[0];i++) printf("%d ",indMin[i]);
    
    // Get all children
    unsigned int *resultIndex, *dresultIndex;
    unsigned int *cnt, *dcnt;
    resultIndex = (unsigned int *)malloc(cntMin[0]*sizeof(unsigned int));
    cudaMalloc(&dresultIndex, cntMin[0]*sizeof(unsigned int));
    cnt = (unsigned int *)malloc(sizeof(unsigned int));
    cudaMalloc(&dcnt, sizeof(unsigned int));

    int indexChild;
    for(int i=0;i<cntMin[0]-1;i++){
        num = (float)(i+1)/(float)BLOCK_SIZE;
        mod = BLOCK_SIZE;
        if(i+1 < BLOCK_SIZE) mod = (i+1)%BLOCK_SIZE;
        n = ceil(num);
        
        searchSimilarIndex<<<n, mod>>>(dindMin, dresultIndex, dcnt, i);
        cudaDeviceSynchronize();

        cudaMemcpy(resultIndex, dresultIndex, cntMin[0]*sizeof(unsigned int), cudaMemcpyDeviceToHost);
        cudaMemcpy(cnt, dcnt, sizeof(unsigned int), cudaMemcpyDeviceToHost);
        
        if(cnt[0] == 0) indexChild = indMin[i];
        else indexChild = *std::max_element(resultIndex, resultIndex + cnt[0])-1;
        buildHuffmanTree(cnt[0], uniqueChar, tempFreq, i, indexChild);

    }
    // for(int j=0;j<cntMin[0]-1;j++){
    //         printf("Index %d:Frequency %u",j,huffmanTreeNode[j].frequency);
    //         if(huffmanTreeNode[j].letter != '\0') printf(":Letter %c\n",huffmanTreeNode[j].letter);
    //         if(huffmanTreeNode[j].left != NULL) printf(":Left %u:Right %u\n",(huffmanTreeNode[j].left)->frequency,(huffmanTreeNode[j].right)->frequency);
    //     }

    
    // build the huffman dictionary with the bit sequence and its length
    buildHuffmanDictionary(huffmanNode_head, bitSequence, bitSequenceLength);

    // write data to the file
    outputData = (unsigned char *)malloc(outputFileLength * sizeof(unsigned char));
    huffmanNode_current = huffmanNode_head;
    outputFileLengthCounter = 0;
    for(int i = 0; i < compressedFileLength-extra; i++){

            // value is 0 then left sub tree
            if(compressedData[i] == 0){
                huffmanNode_current = huffmanNode_current -> left;
                if(huffmanNode_current -> left == NULL){
                    outputData[outputFileLengthCounter] = huffmanNode_current -> letter;
                    huffmanNode_current = huffmanNode_head;
                    outputFileLengthCounter ++;
                }
            }
            // value is 1 the right sub tree
            else {
                huffmanNode_current = huffmanNode_current -> right;
                if(huffmanNode_current -> right == NULL){
                    outputData[outputFileLengthCounter] = huffmanNode_current -> letter;
                    huffmanNode_current = huffmanNode_head;
                    outputFileLengthCounter ++;
                }
            }
    }

    // end the clock, tick tick
    end = clock();

    // write the data to the output file
    outputFile = fopen(argv[2], "wb");
    
    fwrite(outputData, sizeof(unsigned char), outputFileLength, outputFile);
    fclose(outputFile);

    // printing debug info if debug is on
    if(DEBUG){
        printf("\nCompressed file length :: %d", compressedFileLength/8);
        //printf("\nOutput file length counter :: %d", outputFileLengthCounter);
        printf("\nOutput file length :: %d", outputFileLength);
        // printf("\nMerged Huffman Nodes :: %d", mergedHuffmanNodes);
        // printf("\nDistinct character count :: %d", distinctCharacterCount);
    }

    cpuTime = (end - start) * 1000 / CLOCKS_PER_SEC;
    printf("\nTime taken: %d:%d s\n", cpuTime / 1000, cpuTime % 1000);

	// clean up
	free(outputData);
	free(compressedData);

	return 0;
}

	.file	"tmpxft_00233cbf_00000000-6_decompress.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2313:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2313:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z9findIndexPjjj
	.type	_Z9findIndexPjjj, @function
_Z9findIndexPjjj:
.LFB2307:
	.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
.LFE2307:
	.size	_Z9findIndexPjjj, .-_Z9findIndexPjjj
	.globl	_Z16buildHuffmanTreeiPhPjii
	.type	_Z16buildHuffmanTreeiPhPjii, @function
_Z16buildHuffmanTreeiPhPjii:
.LFB2308:
	.cfi_startproc
	endbr64
	movl	%edi, %r9d
	movslq	%r8d, %rax
	movq	%rsi, %rdi
	movslq	%ecx, %rcx
	testl	%r9d, %r9d
	leaq	huffmanTreeNode(%rip), %rsi
	jne	.L5
	imulq	$24, %rcx, %rcx
	movl	(%rdx,%rax,4), %edx
	addq	%rsi, %rcx
	movl	%edx, 4(%rcx)
	movb	(%rdi,%rax), %al
	movb	%al, (%rcx)
	xorl	%eax, %eax
	movq	%rax, 8(%rcx)
	movq	%rax, 16(%rcx)
	ret
.L5:
	incl	%r8d
	imulq	$24, %rax, %rax
	movslq	%r8d, %r8
	imulq	$24, %rcx, %rcx
	imulq	$24, %r8, %r8
	leaq	(%rsi,%rax), %rdi
	leaq	24(%rsi,%rax), %rax
	addq	%rsi, %rcx
	movl	4(%rdi), %edx
	addl	4(%rsi,%r8), %edx
	movq	%rdi, 8(%rcx)
	movl	%edx, 4(%rcx)
	movq	%rax, 16(%rcx)
	movq	%rcx, huffmanNode_head(%rip)
	ret
	.cfi_endproc
.LFE2308:
	.size	_Z16buildHuffmanTreeiPhPjii, .-_Z16buildHuffmanTreeiPhPjii
	.globl	_Z22buildHuffmanDictionaryP11huffmanNodePhh
	.type	_Z22buildHuffmanDictionaryP11huffmanNodePhh, @function
_Z22buildHuffmanDictionaryP11huffmanNodePhh:
.LFB2309:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	cmpq	$0, 8(%rdi)
	movl	%edx, %ebx
	je	.L9
	movzbl	%dl, %eax
	leal	1(%rdx), %edx
	movb	$0, (%rsi,%rax)
	movq	8(%rdi), %rdi
	movzbl	%dl, %edx
	call	_Z22buildHuffmanDictionaryP11huffmanNodePhh
.L9:
	cmpq	$0, 16(%rbp)
	jne	.L10
.L13:
	cmpq	$0, 8(%rbp)
	jne	.L8
	movzbl	0(%rbp), %eax
	leaq	huffmanDictionary(%rip), %rdx
	movzbl	%bl, %ecx
	movq	%r12, %rsi
	salq	$8, %rax
	movb	%bl, 255(%rdx,%rax)
	movzbl	0(%rbp), %eax
	salq	$8, %rax
	addq	%rdx, %rax
	movq	%rax, %rdi
	rep movsb
	jmp	.L8
.L10:
	movzbl	%bl, %eax
	leal	1(%rbx), %edx
	movq	%r12, %rsi
	movb	$1, (%r12,%rax)
	movq	16(%rbp), %rdi
	movzbl	%dl, %edx
	call	_Z22buildHuffmanDictionaryP11huffmanNodePhh
	cmpq	$0, 16(%rbp)
	je	.L13
.L8:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2309:
	.size	_Z22buildHuffmanDictionaryP11huffmanNodePhh, .-_Z22buildHuffmanDictionaryP11huffmanNodePhh
	.globl	_Z45__device_stub__Z17findLeastFrequentPjS_ijS_S_PjS_ijS_S_
	.type	_Z45__device_stub__Z17findLeastFrequentPjS_ijS_S_PjS_ijS_S_, @function
_Z45__device_stub__Z17findLeastFrequentPjS_ijS_S_PjS_ijS_S_:
.LFB2335:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movl	%edx, 28(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 24(%rsp)
	leaq	64(%rsp), %rcx
	movq	%r8, 16(%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	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%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	.L16
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z17findLeastFrequentPjS_ijS_S_(%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
.L16:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2335:
	.size	_Z45__device_stub__Z17findLeastFrequentPjS_ijS_S_PjS_ijS_S_, .-_Z45__device_stub__Z17findLeastFrequentPjS_ijS_S_PjS_ijS_S_
	.globl	_Z17findLeastFrequentPjS_ijS_S_
	.type	_Z17findLeastFrequentPjS_ijS_S_, @function
_Z17findLeastFrequentPjS_ijS_S_:
.LFB2336:
	.cfi_startproc
	endbr64
	jmp	_Z45__device_stub__Z17findLeastFrequentPjS_ijS_S_PjS_ijS_S_
	.cfi_endproc
.LFE2336:
	.size	_Z17findLeastFrequentPjS_ijS_S_, .-_Z17findLeastFrequentPjS_ijS_S_
	.globl	_Z43__device_stub__Z18searchSimilarIndexPjS_S_iPjS_S_i
	.type	_Z43__device_stub__Z18searchSimilarIndexPjS_S_iPjS_S_i, @function
_Z43__device_stub__Z18searchSimilarIndexPjS_S_iPjS_S_i:
.LFB2337:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%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	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%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	.L21
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z18searchSimilarIndexPjS_S_i(%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
.L21:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2337:
	.size	_Z43__device_stub__Z18searchSimilarIndexPjS_S_iPjS_S_i, .-_Z43__device_stub__Z18searchSimilarIndexPjS_S_iPjS_S_i
	.globl	_Z18searchSimilarIndexPjS_S_i
	.type	_Z18searchSimilarIndexPjS_S_i, @function
_Z18searchSimilarIndexPjS_S_i:
.LFB2338:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z18searchSimilarIndexPjS_S_iPjS_S_i
	.cfi_endproc
.LFE2338:
	.size	_Z18searchSimilarIndexPjS_S_i, .-_Z18searchSimilarIndexPjS_S_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"r"
.LC2:
	.string	"wb"
.LC3:
	.string	"\nCompressed file length :: %d"
.LC4:
	.string	"\nOutput file length :: %d"
.LC5:
	.string	"\nTime taken: %d:%d s\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2310:
	.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
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$1448, %rsp
	.cfi_def_cfa_offset 1504
	movq	8(%rsi), %rdi
	leaq	.LC0(%rip), %rsi
	movq	%fs:40, %rax
	movq	%rax, 1432(%rsp)
	xorl	%eax, %eax
	leaq	152(%rsp), %r15
	call	fopen@PLT
	leaq	64(%rsp), %rdi
	movl	$1, %ecx
	movl	$4, %edx
	movq	%rax, %rbx
	movq	%rax, %r8
	movl	$4, %esi
	call	__fread_chk@PLT
	movq	%rbx, %r8
	leaq	68(%rsp), %rdi
	movl	$1, %ecx
	movl	$4, %edx
	movl	$4, %esi
	call	__fread_chk@PLT
	movq	%rbx, %r8
	movl	$1, %ecx
	movq	%r15, %rdi
	movl	$1024, %edx
	movl	$1024, %esi
	call	__fread_chk@PLT
	movl	$2, %edx
	xorl	%esi, %esi
	movq	%rbx, %rdi
	call	fseek@PLT
	movq	%rbx, %rdi
	call	ftell@PLT
	xorl	%edx, %edx
	movl	$1032, %esi
	movq	%rbx, %rdi
	subl	$1032, %eax
	movl	%eax, 12(%rsp)
	call	fseek@PLT
	movl	12(%rsp), %ebp
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rbx, %r8
	movq	%rbp, %rcx
	movl	$1, %edx
	movq	%rbp, %rsi
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	xorl	%ebx, %ebx
	call	__fread_chk@PLT
	call	clock@PLT
	movl	$256, %edi
	movq	%rax, 56(%rsp)
	call	malloc@PLT
	leaq	72(%rsp), %rdi
	movl	$256, %esi
	movq	%rax, 24(%rsp)
	call	cudaMalloc@PLT
	xorl	%eax, %eax
.L28:
	cmpl	$0, (%r15,%rax,4)
	je	.L27
	movq	24(%rsp), %rcx
	movslq	%ebx, %rdx
	incl	%ebx
	movb	%al, (%rcx,%rdx)
.L27:
	incq	%rax
	cmpq	$256, %rax
	jne	.L28
	movq	24(%rsp), %rsi
	movq	72(%rsp), %rdi
	movslq	%ebx, %r12
	movl	$256, %edx
	movl	$1, %ecx
	salq	$2, %r12
	call	cudaMemcpy@PLT
	movq	%r12, %rdi
	call	malloc@PLT
	movl	64(%rsp), %r13d
	movq	%rax, 32(%rsp)
	leaq	0(,%r13,4), %rax
	movq	%rax, %rdi
	movq	%rax, 40(%rsp)
	call	malloc@PLT
	movl	$4, %edi
	movq	%rax, %r13
	call	malloc@PLT
	movq	40(%rsp), %rdi
	movq	%rax, %rbp
	call	malloc@PLT
	xorl	%edx, %edx
	movq	%rax, 48(%rsp)
	xorl	%eax, %eax
.L30:
	movl	(%r15,%rax,4), %ecx
	testl	%ecx, %ecx
	je	.L29
	movq	32(%rsp), %rdi
	movslq	%edx, %rsi
	incl	%edx
	movl	%ecx, (%rdi,%rsi,4)
.L29:
	incq	%rax
	cmpq	$256, %rax
	jne	.L30
	movq	%r12, %rsi
	leaq	80(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	64(%rsp), %esi
	leaq	88(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	64(%rsp), %esi
	leaq	104(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	leaq	96(%rsp), %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	movq	32(%rsp), %rsi
	movq	80(%rsp), %rdi
	movq	%r12, %rdx
	movl	$1, %ecx
	movl	$1024, %r12d
	call	cudaMemcpy@PLT
	cvtsi2ssl	%ebx, %xmm0
	mulss	.LC1(%rip), %xmm0
	cmpl	$1023, %ebx
	jg	.L31
	movl	%ebx, %eax
	cltd
	idivl	%r12d
	movl	%edx, %r12d
.L31:
	call	ceilf@PLT
	movl	%r12d, 140(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	cvttss2sil	%xmm0, %edx
	movq	%rax, 144(%rsp)
	movl	148(%rsp), %ecx
	movq	%rax, 132(%rsp)
	movl	136(%rsp), %esi
	movl	%edx, 128(%rsp)
	movq	140(%rsp), %rdx
	movq	128(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L32
	movq	104(%rsp), %r9
	movq	96(%rsp), %r8
	movl	%ebx, %ecx
	movl	64(%rsp), %edx
	movq	88(%rsp), %rsi
	movq	80(%rsp), %rdi
	call	_Z45__device_stub__Z17findLeastFrequentPjS_ijS_S_PjS_ijS_S_
.L32:
	call	cudaDeviceSynchronize@PLT
	movl	64(%rsp), %edx
	movq	88(%rsp), %rsi
	movq	%r13, %rdi
	movabsq	$4294967297, %r13
	movl	$2, %ecx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	64(%rsp), %edx
	movq	104(%rsp), %rsi
	movl	$2, %ecx
	movq	48(%rsp), %rdi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	96(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdi
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movl	0(%rbp), %ebx
	salq	$2, %rbx
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rbx, %rsi
	leaq	112(%rsp), %rdi
	xorl	%ebx, %ebx
	movq	%rax, %r12
	call	cudaMalloc@PLT
	movl	$4, %edi
	call	malloc@PLT
	leaq	120(%rsp), %rdi
	movl	$4, %esi
	movq	%rax, %r15
	call	cudaMalloc@PLT
.L33:
	movl	0(%rbp), %eax
	movl	%ebx, 40(%rsp)
	decl	%eax
	cmpl	%eax, %ebx
	jnb	.L57
	leal	1(%rbx), %eax
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC1(%rip), %xmm0
	call	ceilf@PLT
	movl	$1023, %eax
	movq	%r13, 144(%rsp)
	movl	148(%rsp), %ecx
	cmpl	%eax, %ebx
	movq	%r13, 132(%rsp)
	movl	136(%rsp), %esi
	cmovle	%ebx, %eax
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	incl	%eax
	movl	%eax, 140(%rsp)
	cvttss2sil	%xmm0, %eax
	movq	140(%rsp), %rdx
	movl	%eax, 128(%rsp)
	movq	128(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L34
	movl	40(%rsp), %ecx
	movq	120(%rsp), %rdx
	movq	112(%rsp), %rsi
	movq	104(%rsp), %rdi
	call	_Z43__device_stub__Z18searchSimilarIndexPjS_S_iPjS_S_i
.L34:
	call	cudaDeviceSynchronize@PLT
	movl	0(%rbp), %edx
	movq	112(%rsp), %rsi
	movq	%r12, %rdi
	movl	$2, %ecx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	120(%rsp), %rsi
	movq	%r15, %rdi
	movl	$2, %ecx
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movl	(%r15), %edi
	testl	%edi, %edi
	jne	.L35
	movq	48(%rsp), %rax
	movl	(%rax,%rbx,4), %r8d
	jmp	.L36
.L35:
	movl	%edi, %eax
	movq	%r12, %rdx
	leaq	(%r12,%rax,4), %rcx
	movq	%r12, %rax
.L37:
	addq	$4, %rax
	movl	(%rdx), %r8d
	cmpq	%rax, %rcx
	je	.L58
	cmpl	(%rax), %r8d
	cmovb	%rax, %rdx
	jmp	.L37
.L58:
	decl	%r8d
.L36:
	movl	40(%rsp), %ecx
	movq	32(%rsp), %rdx
	incq	%rbx
	movq	24(%rsp), %rsi
	call	_Z16buildHuffmanTreeiPhPjii
	jmp	.L33
.L57:
	movq	huffmanNode_head(%rip), %rdi
	leaq	1177(%rsp), %rsi
	xorl	%edx, %edx
	call	_Z22buildHuffmanDictionaryP11huffmanNodePhh
	movl	64(%rsp), %edi
	call	malloc@PLT
	movq	huffmanNode_head(%rip), %rsi
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	movl	12(%rsp), %edi
	movq	%rax, %rbx
	subl	68(%rsp), %edi
	movq	%rsi, %rax
.L41:
	cmpl	%edi, %ecx
	jnb	.L59
	movq	16(%rsp), %r10
	cmpb	$0, (%r10,%rcx)
	jne	.L42
	movq	8(%rax), %rax
	cmpq	$0, 8(%rax)
	jmp	.L56
.L42:
	movq	16(%rax), %rax
	cmpq	$0, 16(%rax)
.L56:
	jne	.L43
	movb	(%rax), %r8b
	movl	%edx, %eax
	incl	%edx
	movb	%r8b, (%rbx,%rax)
	movq	%rsi, %rax
.L43:
	incq	%rcx
	jmp	.L41
.L59:
	call	clock@PLT
	movq	16(%r14), %rdi
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rbp
	call	fopen@PLT
	movl	64(%rsp), %edx
	movl	$1, %esi
	movq	%rbx, %rdi
	movq	%rax, %rcx
	movq	%rax, %r12
	call	fwrite@PLT
	movq	%r12, %rdi
	call	fclose@PLT
	movl	12(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC3(%rip), %rsi
	shrl	$3, %edx
	call	__printf_chk@PLT
	movl	64(%rsp), %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC4(%rip), %rsi
	call	__printf_chk@PLT
	movq	56(%rsp), %rcx
	movq	%rbp, %rax
	movl	$1000, %esi
	movl	$2, %edi
	subq	%rcx, %rax
	movl	$1000, %ecx
	cqto
	idivq	%rcx
	xorl	%edx, %edx
	divl	%esi
	leaq	.LC5(%rip), %rsi
	movl	%edx, %ecx
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	1432(%rsp), %rax
	subq	%fs:40, %rax
	je	.L45
	call	__stack_chk_fail@PLT
.L45:
	addq	$1448, %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
.LFE2310:
	.size	main, .-main
	.section	.rodata.str1.1
.LC6:
	.string	"_Z18searchSimilarIndexPjS_S_i"
.LC7:
	.string	"_Z17findLeastFrequentPjS_ijS_S_"
.LC8:
	.string	"counter"
.LC9:
	.string	"counter_2"
.LC10:
	.string	"INTMAX"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2340:
	.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	.LC6(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z18searchSimilarIndexPjS_S_i(%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	.LC7(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z17findLeastFrequentPjS_ijS_S_(%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
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC8(%rip), %rdx
	movl	$4, %r9d
	leaq	_ZL7counter(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC9(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL9counter_2(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC10(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movl	$4, %r9d
	movq	%rdx, %rcx
	leaq	_ZL6INTMAX(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%r8
	.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
.LFE2340:
	.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
	.globl	huffmanTreeNode
	.bss
	.align 32
	.type	huffmanTreeNode, @object
	.size	huffmanTreeNode, 12288
huffmanTreeNode:
	.zero	12288
	.globl	huffmanNode_head
	.align 8
	.type	huffmanNode_head, @object
	.size	huffmanNode_head, 8
huffmanNode_head:
	.zero	8
	.globl	huffmanDictionary
	.align 32
	.type	huffmanDictionary, @object
	.size	huffmanDictionary, 65536
huffmanDictionary:
	.zero	65536
	.section	.rodata
	.align 4
	.type	_ZL6INTMAX, @object
	.size	_ZL6INTMAX, 4
_ZL6INTMAX:
	.long	2147483647
	.local	_ZL9counter_2
	.comm	_ZL9counter_2,4,4
	.local	_ZL7counter
	.comm	_ZL7counter,4,4
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	981467136
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <math.h> 
#include <hip/hip_runtime.h>
#include <algorithm>


#define BLOCK_SIZE 1024
__device__ unsigned int counter, counter_2;
//__device__ unsigned int flag;
__constant__ const unsigned int INTMAX = 2147483647;

// struct for dictionary
struct huffmanDictionary{
    unsigned char bitSequence[255];
    unsigned char bitSequenceLength;
};

// struct for node
struct huffmanNode{
    unsigned char letter;  // char to store
    unsigned int frequency;  // frequency of the char
    struct huffmanNode * left;  // left sub tree
    struct huffmanNode * right;  // right sub tree
};

struct huffmanDictionary huffmanDictionary[256];
struct huffmanNode * huffmanNode_head;
struct huffmanNode huffmanTreeNode[512];

#define DEBUG 1

__device__ int findIndex(unsigned int *freq, unsigned int size,unsigned int search){
    for(int i=0;i<size;i++){
        if(freq[i] == search){
            return i;
        }
    }
    return -1;
}
__global__ void findLeastFrequent(unsigned int *freq, unsigned int *min, int size, unsigned int threads, unsigned int* count, unsigned int *index){
    int id = blockIdx.x*blockDim.x + threadIdx.x;
    counter_2 = 0;
    __syncthreads();
    int ind;
    
    if(id<threads){
        
        while(1){
            min[counter_2] = INTMAX;
            
            atomicMin(&min[counter_2], freq[id]);
            // Need global barrier
            __syncthreads();
            
            ind = findIndex(freq, threads, min[counter_2]);
            index[counter_2] = ind;
            // Need global barrier
            __syncthreads();
            freq[ind] = INTMAX;
            
            if(id == 0) atomicInc(&counter_2, size);
            // Need global barrier
            __syncthreads();

            min[counter_2] = INTMAX;
            
            atomicMin(&min[counter_2], freq[id]);
            // Need global barrier
            __syncthreads();
            
            ind = findIndex(freq, threads, min[counter_2]);
            index[counter_2] = ind;
            // Need global barrier
            __syncthreads();
            freq[ind] = min[counter_2] + min[counter_2-1];
            
            if(id == 0) atomicInc(&counter_2, size);
            // Need global barrier
            __syncthreads();
            

            if(min[counter_2] == INTMAX || min[counter_2-1] == INTMAX){
                count[0] = counter_2;
                break;
            }
            
        }
    }
}

__global__ void searchSimilarIndex(unsigned int *index, unsigned int *resultIndex, unsigned int *cnt, int threads){
    int id = blockIdx.x*blockDim.x + threadIdx.x;
    
    __syncthreads();
    counter = 0;
    if(id != threads){
        if(index[id] == index[threads]){
            
            int temp = atomicInc(&counter, threads+1);
            resultIndex[temp] = id;
        }
        __syncthreads();
        cnt[0] = counter;
    }
}



void buildHuffmanTree(int count,unsigned char *uniqueChar, unsigned int *frequency,int newIndex, int childIndex){
    if(count == 0){
        
        huffmanTreeNode[newIndex].frequency = frequency[childIndex];
        huffmanTreeNode[newIndex].letter = uniqueChar[childIndex];
        huffmanTreeNode[newIndex].left = NULL;
        huffmanTreeNode[newIndex].right = NULL;
    }
    else{
        
        huffmanTreeNode[newIndex].frequency = huffmanTreeNode[childIndex].frequency + huffmanTreeNode[childIndex + 1].frequency;
        huffmanTreeNode[newIndex].left = & huffmanTreeNode[childIndex];
        huffmanTreeNode[newIndex].right = & huffmanTreeNode[childIndex + 1];
        huffmanNode_head = & (huffmanTreeNode[newIndex]);
    }
}

void buildHuffmanDictionary(struct huffmanNode * root, unsigned char * bitSequence, unsigned char bitSequenceLength){
    if(root -> left){
        bitSequence[bitSequenceLength] = 0;
        buildHuffmanDictionary(root -> left, bitSequence, bitSequenceLength + 1);
    }

    if(root -> right){
        bitSequence[bitSequenceLength] = 1;
        buildHuffmanDictionary(root -> right, bitSequence, bitSequenceLength + 1);
    }

    // copy the bit sequence and the length to the dictionary
    if(root -> right == NULL && root -> left == NULL){
        huffmanDictionary[root -> letter].bitSequenceLength = bitSequenceLength;
        memcpy(huffmanDictionary[root -> letter].bitSequence, bitSequence, bitSequenceLength * sizeof(unsigned char));
    }
}


int main(int argc, char ** argv){

    clock_t start, end;
    unsigned int cpuTime;
    unsigned int compressedFileLength, outputFileLengthCounter, outputFileLength, extra;
    unsigned int distinctCharacterCount;
    unsigned int frequency[256];

    unsigned char bitSequenceLength = 0, bitSequence[255];
    unsigned char * compressedData, * outputData;
    struct huffmanNode * huffmanNode_current;

    FILE *compressedFile, *outputFile;

    // read input file get length, frequency and data
    compressedFile = fopen(argv[1], "r");
    
    fread(& outputFileLength, sizeof(unsigned int), 1, compressedFile);
    //no. of extra bits added, calculate here
    fread(& extra, sizeof(unsigned int), 1, compressedFile);
    fread(frequency, 256 * sizeof(unsigned int), 1, compressedFile);

    // find length of the compressed file
    fseek(compressedFile, 0, SEEK_END);
    compressedFileLength = ftell(compressedFile) - 1032;
    
    fseek(compressedFile, 1032, SEEK_SET);

    // allocate the required memory, read the file
    compressedData = (unsigned char *)malloc((compressedFileLength) * sizeof(unsigned char));
    fread(compressedData, sizeof(unsigned char), compressedFileLength, compressedFile);

    // start the clock, tick tick
    start = clock();

    // for(int i=0;i<256;i++) printf("%c ",frequency[i]);
    // printf("\n");
    // initialize the huffman tree
    distinctCharacterCount = 0;
    for(int i = 0; i < 256; i++){
        if(frequency[i] > 0){
            distinctCharacterCount ++;
        }
    }

    int unique = 0;
    unsigned char *uniqueChar, *duniqueChar;
    uniqueChar = (unsigned char *)malloc(256*sizeof(unsigned char));
    hipMalloc(&duniqueChar, 256*sizeof(unsigned char));
    for(int i = 0; i<256; i++){
        if(frequency[i] > 0){
            uniqueChar[unique++] = i;
            //printf("%d ",frequency[i]);
        }
    }
    //printf("\n");
    hipMemcpy(duniqueChar, uniqueChar, 256*sizeof(unsigned char), hipMemcpyHostToDevice);

    // *** FIND MINIMUM 2 FREQUENCY FOR ADDING NEW NODE ***
    unsigned int *tempFreq, *tempDFreq;
    unsigned int *min, *dmin;
    unsigned int *cntMin, *dcntMin;
    unsigned int *indMin, *dindMin;
    int ctr;

    tempFreq = (unsigned int *)malloc(unique*sizeof(unsigned int));
    
    min = (unsigned int *)malloc(outputFileLength*sizeof(unsigned int));
    cntMin = (unsigned int *)malloc(sizeof(unsigned int));
    indMin = (unsigned int *)malloc(outputFileLength*sizeof(unsigned int));
    ctr = 0;
    for(unsigned int i=0;i<256;i++){
        if(frequency[i]!=0){
            tempFreq[ctr++] = frequency[i];
        }
    }
    // for(unsigned int i=0;i<unique;i++) printf("%d:%c ",tempFreq[i],uniqueChar[i]);
    // printf("\n");
    
    hipMalloc(&tempDFreq, unique*sizeof(unsigned int));
    
    hipMalloc(&dmin, outputFileLength*sizeof(unsigned int));
    hipMalloc(&dindMin, outputFileLength*sizeof(unsigned int));
    hipMalloc(&dcntMin, sizeof(unsigned int));
    hipMemcpy(tempDFreq, tempFreq, unique*sizeof(unsigned int), hipMemcpyHostToDevice);

    float num = (float)(unique)/(float)BLOCK_SIZE;
    //num = (float)(5)/(float)BLOCK_SIZE;
    int mod = BLOCK_SIZE;
    if(unique < BLOCK_SIZE) mod = unique%BLOCK_SIZE;
    //if(5 < BLOCKSIZE) mod = 5%BLOCK_SIZE;
    int n = ceil(num);
    //printf("%d %d\n",n,mod);
    findLeastFrequent<<<n, mod>>>(tempDFreq, dmin, outputFileLength, unique, dcntMin, dindMin);
    
    hipDeviceSynchronize();

    hipMemcpy(min, dmin, outputFileLength*sizeof(unsigned int), hipMemcpyDeviceToHost);
    hipMemcpy(indMin, dindMin, outputFileLength*sizeof(unsigned int), hipMemcpyDeviceToHost);
    hipMemcpy(cntMin, dcntMin, sizeof(unsigned int), hipMemcpyDeviceToHost);
    // printf("count : %d\n",cntMin[0]);
    // for(unsigned int i=0;i<cntMin[0];i++){
    //     printf("%d:%d:%d ",i,indMin[i],min[i]);
    // } 
    // printf("\n");
    // printf("Min:\n");
    // for(unsigned int i=0;i<cntMin[0];i++) printf("%d ",min[i]);
    // printf("\nIndMin:\n");
    // for(unsigned int i=0;i<cntMin[0];i++) printf("%d ",indMin[i]);
    
    // Get all children
    unsigned int *resultIndex, *dresultIndex;
    unsigned int *cnt, *dcnt;
    resultIndex = (unsigned int *)malloc(cntMin[0]*sizeof(unsigned int));
    hipMalloc(&dresultIndex, cntMin[0]*sizeof(unsigned int));
    cnt = (unsigned int *)malloc(sizeof(unsigned int));
    hipMalloc(&dcnt, sizeof(unsigned int));

    int indexChild;
    for(int i=0;i<cntMin[0]-1;i++){
        num = (float)(i+1)/(float)BLOCK_SIZE;
        mod = BLOCK_SIZE;
        if(i+1 < BLOCK_SIZE) mod = (i+1)%BLOCK_SIZE;
        n = ceil(num);
        
        searchSimilarIndex<<<n, mod>>>(dindMin, dresultIndex, dcnt, i);
        hipDeviceSynchronize();

        hipMemcpy(resultIndex, dresultIndex, cntMin[0]*sizeof(unsigned int), hipMemcpyDeviceToHost);
        hipMemcpy(cnt, dcnt, sizeof(unsigned int), hipMemcpyDeviceToHost);
        
        if(cnt[0] == 0) indexChild = indMin[i];
        else indexChild = *std::max_element(resultIndex, resultIndex + cnt[0])-1;
        buildHuffmanTree(cnt[0], uniqueChar, tempFreq, i, indexChild);

    }
    // for(int j=0;j<cntMin[0]-1;j++){
    //         printf("Index %d:Frequency %u",j,huffmanTreeNode[j].frequency);
    //         if(huffmanTreeNode[j].letter != '\0') printf(":Letter %c\n",huffmanTreeNode[j].letter);
    //         if(huffmanTreeNode[j].left != NULL) printf(":Left %u:Right %u\n",(huffmanTreeNode[j].left)->frequency,(huffmanTreeNode[j].right)->frequency);
    //     }

    
    // build the huffman dictionary with the bit sequence and its length
    buildHuffmanDictionary(huffmanNode_head, bitSequence, bitSequenceLength);

    // write data to the file
    outputData = (unsigned char *)malloc(outputFileLength * sizeof(unsigned char));
    huffmanNode_current = huffmanNode_head;
    outputFileLengthCounter = 0;
    for(int i = 0; i < compressedFileLength-extra; i++){

            // value is 0 then left sub tree
            if(compressedData[i] == 0){
                huffmanNode_current = huffmanNode_current -> left;
                if(huffmanNode_current -> left == NULL){
                    outputData[outputFileLengthCounter] = huffmanNode_current -> letter;
                    huffmanNode_current = huffmanNode_head;
                    outputFileLengthCounter ++;
                }
            }
            // value is 1 the right sub tree
            else {
                huffmanNode_current = huffmanNode_current -> right;
                if(huffmanNode_current -> right == NULL){
                    outputData[outputFileLengthCounter] = huffmanNode_current -> letter;
                    huffmanNode_current = huffmanNode_head;
                    outputFileLengthCounter ++;
                }
            }
    }

    // end the clock, tick tick
    end = clock();

    // write the data to the output file
    outputFile = fopen(argv[2], "wb");
    
    fwrite(outputData, sizeof(unsigned char), outputFileLength, outputFile);
    fclose(outputFile);

    // printing debug info if debug is on
    if(DEBUG){
        printf("\nCompressed file length :: %d", compressedFileLength/8);
        //printf("\nOutput file length counter :: %d", outputFileLengthCounter);
        printf("\nOutput file length :: %d", outputFileLength);
        // printf("\nMerged Huffman Nodes :: %d", mergedHuffmanNodes);
        // printf("\nDistinct character count :: %d", distinctCharacterCount);
    }

    cpuTime = (end - start) * 1000 / CLOCKS_PER_SEC;
    printf("\nTime taken: %d:%d s\n", cpuTime / 1000, cpuTime % 1000);

	// clean up
	free(outputData);
	free(compressedData);

	return 0;
}

	.text
	.file	"decompress.hip"
	.globl	_Z32__device_stub__findLeastFrequentPjS_ijS_S_ # -- Begin function _Z32__device_stub__findLeastFrequentPjS_ijS_S_
	.type	_Z32__device_stub__findLeastFrequentPjS_ijS_S_,@function
_Z32__device_stub__findLeastFrequentPjS_ijS_S_: # @_Z32__device_stub__findLeastFrequentPjS_ijS_S_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	32(%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	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	$_Z17findLeastFrequentPjS_ijS_S_, %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	_Z32__device_stub__findLeastFrequentPjS_ijS_S_, .Lfunc_end0-_Z32__device_stub__findLeastFrequentPjS_ijS_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z33__device_stub__searchSimilarIndexPjS_S_i # -- Begin function _Z33__device_stub__searchSimilarIndexPjS_S_i
	.type	_Z33__device_stub__searchSimilarIndexPjS_S_i,@function
_Z33__device_stub__searchSimilarIndexPjS_S_i: # @_Z33__device_stub__searchSimilarIndexPjS_S_i
	.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), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%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	$_Z18searchSimilarIndexPjS_S_i, %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_end1:
	.size	_Z33__device_stub__searchSimilarIndexPjS_S_i, .Lfunc_end1-_Z33__device_stub__searchSimilarIndexPjS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z16buildHuffmanTreeiPhPjii     # -- Begin function _Z16buildHuffmanTreeiPhPjii
	.type	_Z16buildHuffmanTreeiPhPjii,@function
_Z16buildHuffmanTreeiPhPjii:            # @_Z16buildHuffmanTreeiPhPjii
	.cfi_startproc
# %bb.0:
	movslq	%r8d, %rax
	testl	%edi, %edi
	je	.LBB2_1
# %bb.2:
	shlq	$3, %rax
	leaq	(%rax,%rax,2), %rdx
	addq	$huffmanTreeNode+24, %rdx
	movl	4(%rdx), %esi
	addl	-20(%rdx), %esi
	leaq	(%rax,%rax,2), %rax
	addq	$huffmanTreeNode, %rax
	movslq	%ecx, %rcx
	shlq	$3, %rcx
	leaq	(%rcx,%rcx,2), %rcx
	addq	$huffmanTreeNode, %rcx
	movl	%esi, 4(%rcx)
	movq	%rax, 8(%rcx)
	movq	%rdx, 16(%rcx)
	movq	%rcx, huffmanNode_head(%rip)
	retq
.LBB2_1:
	movl	(%rdx,%rax,4), %edx
	movslq	%ecx, %rcx
	shlq	$3, %rcx
	movl	%edx, huffmanTreeNode+4(%rcx,%rcx,2)
	movb	(%rsi,%rax), %al
	movb	%al, huffmanTreeNode(%rcx,%rcx,2)
	xorps	%xmm0, %xmm0
	movups	%xmm0, huffmanTreeNode+8(%rcx,%rcx,2)
	retq
.Lfunc_end2:
	.size	_Z16buildHuffmanTreeiPhPjii, .Lfunc_end2-_Z16buildHuffmanTreeiPhPjii
	.cfi_endproc
                                        # -- End function
	.globl	_Z22buildHuffmanDictionaryP11huffmanNodePhh # -- Begin function _Z22buildHuffmanDictionaryP11huffmanNodePhh
	.type	_Z22buildHuffmanDictionaryP11huffmanNodePhh,@function
_Z22buildHuffmanDictionaryP11huffmanNodePhh: # @_Z22buildHuffmanDictionaryP11huffmanNodePhh
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movq	%rdi, %r15
	cmpq	$0, 8(%rdi)
	movzbl	%dl, %r14d
	je	.LBB3_2
# %bb.1:
	movb	$0, (%rbx,%r14)
	movq	8(%r15), %rdi
	leal	1(%r14), %eax
	movzbl	%al, %edx
	movq	%rbx, %rsi
	callq	_Z22buildHuffmanDictionaryP11huffmanNodePhh
.LBB3_2:
	cmpq	$0, 16(%r15)
	je	.LBB3_4
# %bb.3:
	movb	$1, (%rbx,%r14)
	movq	16(%r15), %rdi
	leal	1(%r14), %eax
	movzbl	%al, %edx
	movq	%rbx, %rsi
	callq	_Z22buildHuffmanDictionaryP11huffmanNodePhh
	cmpq	$0, 16(%r15)
	jne	.LBB3_5
.LBB3_4:                                # %.thread
	cmpq	$0, 8(%r15)
	je	.LBB3_6
.LBB3_5:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB3_6:
	.cfi_def_cfa_offset 32
	movzbl	(%r15), %eax
	shll	$8, %eax
	leaq	huffmanDictionary(%rax), %rdi
	movb	%r14b, 255(%rdi)
	movq	%rbx, %rsi
	movq	%r14, %rdx
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	memcpy@PLT                      # TAILCALL
.Lfunc_end3:
	.size	_Z22buildHuffmanDictionaryP11huffmanNodePhh, .Lfunc_end3-_Z22buildHuffmanDictionaryP11huffmanNodePhh
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI4_0:
	.long	0x3a800000                      # float 9.765625E-4
	.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	$1448, %rsp                     # imm = 0x5A8
	.cfi_def_cfa_offset 1504
	.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, 112(%rsp)                 # 8-byte Spill
	movq	8(%rsi), %rdi
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %rbx
	leaq	44(%rsp), %rdi
	movl	$4, %esi
	movl	$1, %edx
	movq	%rax, %rcx
	callq	fread
	leaq	40(%rsp), %rdi
	movl	$4, %esi
	movl	$1, %edx
	movq	%rbx, %rcx
	callq	fread
	leaq	416(%rsp), %rdi
	movl	$1024, %esi                     # imm = 0x400
	movl	$1, %edx
	movq	%rbx, %rcx
	callq	fread
	xorl	%r14d, %r14d
	movq	%rbx, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	fseek
	movq	%rbx, %rdi
	callq	ftell
	movq	%rax, %r13
	addl	$-1032, %r13d                   # imm = 0xFBF8
	movl	$1032, %esi                     # imm = 0x408
	movq	%rbx, %rdi
	xorl	%edx, %edx
	callq	fseek
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %r12
	movl	$1, %esi
	movq	%rax, %rdi
	movq	%r13, %rdx
	movq	%rbx, %rcx
	callq	fread
	callq	clock
	movq	%rax, 96(%rsp)                  # 8-byte Spill
	movl	$256, %edi                      # imm = 0x100
	callq	malloc
	movq	%rax, %rbp
	leaq	152(%rsp), %rdi
	movl	$256, %esi                      # imm = 0x100
	callq	hipMalloc
	xorl	%r15d, %r15d
.LBB4_1:                                # =>This Inner Loop Header: Depth=1
	cmpl	$0, 416(%rsp,%r14,4)
	je	.LBB4_3
# %bb.2:                                #   in Loop: Header=BB4_1 Depth=1
	movslq	%r15d, %rax
	incl	%r15d
	movb	%r14b, (%rbp,%rax)
.LBB4_3:                                #   in Loop: Header=BB4_1 Depth=1
	incq	%r14
	cmpq	$256, %r14                      # imm = 0x100
	jne	.LBB4_1
# %bb.4:
	movq	%r13, 104(%rsp)                 # 8-byte Spill
	movq	%r12, 120(%rsp)                 # 8-byte Spill
	movq	152(%rsp), %rdi
	movl	$256, %edx                      # imm = 0x100
	movq	%rbp, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movslq	%r15d, %rbx
	shlq	$2, %rbx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r12
	movl	44(%rsp), %eax
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	leaq	(,%rax,4), %r13
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	$4, %edi
	callq	malloc
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	xorl	%eax, %eax
	xorl	%ecx, %ecx
.LBB4_5:                                # =>This Inner Loop Header: Depth=1
	movl	416(%rsp,%rax,4), %edx
	testl	%edx, %edx
	je	.LBB4_7
# %bb.6:                                #   in Loop: Header=BB4_5 Depth=1
	movslq	%ecx, %rsi
	incl	%ecx
	movl	%edx, (%r12,%rsi,4)
.LBB4_7:                                #   in Loop: Header=BB4_5 Depth=1
	incq	%rax
	cmpq	$256, %rax                      # imm = 0x100
	jne	.LBB4_5
# %bb.8:
	leaq	144(%rsp), %r14
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	leaq	88(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	32(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	80(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	%r12, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	cvtsi2ss	%r15d, %xmm0
	mulss	.LCPI4_0(%rip), %xmm0
	leal	1023(%r15), %eax
	testl	%r15d, %r15d
	cmovnsl	%r15d, %eax
	andl	$-1024, %eax                    # imm = 0xFC00
	movl	%r15d, %ebx
	subl	%eax, %ebx
	movl	$1024, %eax                     # imm = 0x400
	cmpl	%eax, %r15d
	cmovgel	%eax, %ebx
	callq	ceilf@PLT
	cvttss2si	%xmm0, %edi
	btsq	$32, %rdi
	btsq	$32, %rbx
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_10
# %bb.9:
	movq	144(%rsp), %rdi
	movq	88(%rsp), %rsi
	movq	80(%rsp), %r8
	movq	32(%rsp), %r9
	movq	8(%rsp), %rdx                   # 8-byte Reload
                                        # kill: def $edx killed $edx killed $rdx
	movl	%r15d, %ecx
	callq	_Z32__device_stub__findLeastFrequentPjS_ijS_S_
.LBB4_10:
	callq	hipDeviceSynchronize
	movq	88(%rsp), %rsi
	movq	16(%rsp), %rdi                  # 8-byte Reload
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	32(%rsp), %rsi
	movq	48(%rsp), %rdi                  # 8-byte Reload
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	80(%rsp), %rsi
	movl	$4, %edx
	movq	24(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	(%r14), %ebx
	shlq	$2, %rbx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r13
	leaq	72(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movl	$4, %edi
	callq	malloc
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	leaq	64(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	cmpl	$1, (%r14)
	je	.LBB4_16
# %bb.11:                               # %.lr.ph
	movabsq	$4294967296, %rax               # imm = 0x100000000
	movq	%r13, %rcx
	addq	$4, %rcx
	movq	%rcx, 128(%rsp)                 # 8-byte Spill
	xorl	%ebx, %ebx
	addq	$1024, %rax                     # imm = 0x400
	movq	%rax, 136(%rsp)                 # 8-byte Spill
	movq	%r12, 56(%rsp)                  # 8-byte Spill
	movl	$1023, %r15d                    # imm = 0x3FF
.LBB4_12:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_22 Depth 2
	movq	%rbp, %r12
	leaq	1(%rbx), %r14
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r14d, %xmm0
	mulss	.LCPI4_0(%rip), %xmm0
	movq	%r14, %rbp
	andq	%r15, %rbp
	callq	ceilf@PLT
	cvttss2si	%xmm0, %edi
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %rdi
	orq	%rax, %rbp
	cmpq	%r15, %rbx
	cmovaeq	136(%rsp), %rbp                 # 8-byte Folded Reload
	movl	$1, %esi
	movq	%rbp, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_14
# %bb.13:                               #   in Loop: Header=BB4_12 Depth=1
	movq	32(%rsp), %rdi
	movq	72(%rsp), %rsi
	movq	64(%rsp), %rdx
	movl	%ebx, %ecx
	callq	_Z33__device_stub__searchSimilarIndexPjS_S_i
.LBB4_14:                               #   in Loop: Header=BB4_12 Depth=1
	callq	hipDeviceSynchronize
	movq	72(%rsp), %rsi
	movq	24(%rsp), %rax                  # 8-byte Reload
	movl	(%rax), %edx
	shlq	$2, %rdx
	movq	%r13, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	64(%rsp), %rsi
	movl	$4, %edx
	movq	16(%rsp), %rbp                  # 8-byte Reload
	movq	%rbp, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	(%rbp), %edi
	testq	%rdi, %rdi
	movq	%r12, %rbp
	je	.LBB4_15
# %bb.20:                               #   in Loop: Header=BB4_12 Depth=1
	movq	%r13, %rax
	cmpl	$1, %edi
	movq	56(%rsp), %r12                  # 8-byte Reload
	je	.LBB4_23
# %bb.21:                               # %.lr.ph.preheader.i.i
                                        #   in Loop: Header=BB4_12 Depth=1
	movl	(%r13), %ecx
	leaq	-4(,%rdi,4), %rdx
	movq	128(%rsp), %rsi                 # 8-byte Reload
	movq	%r13, %rax
.LBB4_22:                               # %.lr.ph.i.i
                                        #   Parent Loop BB4_12 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%rsi), %r8d
	cmpl	%r8d, %ecx
	cmovbel	%r8d, %ecx
	cmovbq	%rsi, %rax
	addq	$4, %rsi
	addq	$-4, %rdx
	jne	.LBB4_22
.LBB4_23:                               # %_ZSt11max_elementIPjET_S1_S1_.exit
                                        #   in Loop: Header=BB4_12 Depth=1
	movl	(%rax), %r8d
	decl	%r8d
	jmp	.LBB4_24
.LBB4_15:                               #   in Loop: Header=BB4_12 Depth=1
	movq	48(%rsp), %rax                  # 8-byte Reload
	movl	(%rax,%rbx,4), %r8d
	movq	56(%rsp), %r12                  # 8-byte Reload
.LBB4_24:                               #   in Loop: Header=BB4_12 Depth=1
                                        # kill: def $edi killed $edi killed $rdi
	movq	%rbp, %rsi
	movq	%r12, %rdx
	movl	%ebx, %ecx
	callq	_Z16buildHuffmanTreeiPhPjii
	movq	24(%rsp), %rax                  # 8-byte Reload
	movl	(%rax), %eax
	decl	%eax
	movq	%r14, %rbx
	cmpq	%rax, %r14
	jb	.LBB4_12
.LBB4_16:                               # %._crit_edge
	movq	huffmanNode_head(%rip), %rdi
	leaq	160(%rsp), %rsi
	xorl	%r14d, %r14d
	xorl	%edx, %edx
	callq	_Z22buildHuffmanDictionaryP11huffmanNodePhh
	movq	8(%rsp), %rdi                   # 8-byte Reload
	callq	malloc
	movq	%rax, %rbx
	movq	104(%rsp), %r13                 # 8-byte Reload
	movl	%r13d, %eax
	subl	40(%rsp), %eax
	movq	120(%rsp), %r12                 # 8-byte Reload
	jne	.LBB4_17
.LBB4_28:                               # %._crit_edge145
	callq	clock
	movq	%rax, %r14
	movq	112(%rsp), %rax                 # 8-byte Reload
	movq	16(%rax), %rdi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, %r15
	movl	$1, %esi
	movq	%rbx, %rdi
	movq	8(%rsp), %rbp                   # 8-byte Reload
	movq	%rbp, %rdx
	movq	%rax, %rcx
	callq	fwrite
	movq	%r15, %rdi
	callq	fclose
	shrl	$3, %r13d
	movl	$.L.str.2, %edi
	movl	%r13d, %esi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.3, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	subq	96(%rsp), %r14                  # 8-byte Folded Reload
	movabsq	$2361183241434822607, %rcx      # imm = 0x20C49BA5E353F7CF
	movq	%r14, %rax
	imulq	%rcx
	movq	%rdx, %rax
	shrq	$63, %rax
	sarq	$7, %rdx
	addq	%rax, %rdx
	movl	%edx, %eax
	imulq	$274877907, %rax, %rsi          # imm = 0x10624DD3
	shrq	$38, %rsi
	imull	$1000, %esi, %eax               # imm = 0x3E8
	subl	%eax, %edx
	movl	$.L.str.4, %edi
                                        # kill: def $esi killed $esi killed $rsi
                                        # kill: def $edx killed $edx killed $rdx
	xorl	%eax, %eax
	callq	printf
	movq	%rbx, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$1448, %rsp                     # imm = 0x5A8
	.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
.LBB4_17:                               # %.lr.ph144.preheader
	.cfi_def_cfa_offset 1504
	movq	huffmanNode_head(%rip), %rcx
	cmpl	$1, %eax
	adcl	$0, %eax
	xorl	%edx, %edx
	movq	%rcx, %rsi
.LBB4_18:                               # %.lr.ph144
                                        # =>This Inner Loop Header: Depth=1
	cmpb	$0, (%r12,%rdx)
	je	.LBB4_19
# %bb.25:                               #   in Loop: Header=BB4_18 Depth=1
	movq	16(%rsi), %rsi
	cmpq	$0, 16(%rsi)
	jne	.LBB4_27
.LBB4_26:                               # %.sink.split
                                        #   in Loop: Header=BB4_18 Depth=1
	movb	(%rsi), %sil
	movl	%r14d, %edi
	movb	%sil, (%rbx,%rdi)
	incl	%r14d
	movq	%rcx, %rsi
.LBB4_27:                               #   in Loop: Header=BB4_18 Depth=1
	incq	%rdx
	cmpq	%rdx, %rax
	jne	.LBB4_18
	jmp	.LBB4_28
.LBB4_19:                               #   in Loop: Header=BB4_18 Depth=1
	movq	8(%rsi), %rsi
	cmpq	$0, 8(%rsi)
	jne	.LBB4_27
	jmp	.LBB4_26
.Lfunc_end4:
	.size	main, .Lfunc_end4-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:
	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	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z17findLeastFrequentPjS_ijS_S_, %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	$_Z18searchSimilarIndexPjS_S_i, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$0, 8(%rsp)
	movl	$0, (%rsp)
	movl	$counter, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movl	$4, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	callq	__hipRegisterVar
	movl	$0, 8(%rsp)
	movl	$0, (%rsp)
	movl	$counter_2, %esi
	movl	$.L__unnamed_4, %edx
	movl	$.L__unnamed_4, %ecx
	movl	$4, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	callq	__hipRegisterVar
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	counter,@object                 # @counter
	.local	counter
	.comm	counter,4,4
	.type	counter_2,@object               # @counter_2
	.local	counter_2
	.comm	counter_2,4,4
	.type	huffmanDictionary,@object       # @huffmanDictionary
	.bss
	.globl	huffmanDictionary
	.p2align	4, 0x0
huffmanDictionary:
	.zero	65536
	.size	huffmanDictionary, 65536

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

	.type	huffmanTreeNode,@object         # @huffmanTreeNode
	.globl	huffmanTreeNode
	.p2align	4, 0x0
huffmanTreeNode:
	.zero	12288
	.size	huffmanTreeNode, 12288

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

	.type	_Z18searchSimilarIndexPjS_S_i,@object # @_Z18searchSimilarIndexPjS_S_i
	.globl	_Z18searchSimilarIndexPjS_S_i
	.p2align	3, 0x0
_Z18searchSimilarIndexPjS_S_i:
	.quad	_Z33__device_stub__searchSimilarIndexPjS_S_i
	.size	_Z18searchSimilarIndexPjS_S_i, 8

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

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"wb"
	.size	.L.str.1, 3

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"\nCompressed file length :: %d"
	.size	.L.str.2, 30

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"\nOutput file length :: %d"
	.size	.L.str.3, 26

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"\nTime taken: %d:%d s\n"
	.size	.L.str.4, 22

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z17findLeastFrequentPjS_ijS_S_"
	.size	.L__unnamed_1, 32

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z18searchSimilarIndexPjS_S_i"
	.size	.L__unnamed_2, 30

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"counter"
	.size	.L__unnamed_3, 8

	.type	.L__unnamed_4,@object           # @3
.L__unnamed_4:
	.asciz	"counter_2"
	.size	.L__unnamed_4, 10

	.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

	.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 _Z32__device_stub__findLeastFrequentPjS_ijS_S_
	.addrsig_sym _Z33__device_stub__searchSimilarIndexPjS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym counter
	.addrsig_sym counter_2
	.addrsig_sym huffmanTreeNode
	.addrsig_sym _Z17findLeastFrequentPjS_ijS_S_
	.addrsig_sym _Z18searchSimilarIndexPjS_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z17findLeastFrequentPjS_ijS_S_ ; -- Begin function _Z17findLeastFrequentPjS_ijS_S_
	.globl	_Z17findLeastFrequentPjS_ijS_S_
	.p2align	8
	.type	_Z17findLeastFrequentPjS_ijS_S_,@function
_Z17findLeastFrequentPjS_ijS_S_:        ; @_Z17findLeastFrequentPjS_ijS_S_
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x34
	s_load_b64 s[2:3], s[0:1], 0x10
	s_mov_b32 s6, exec_lo
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mad_u64_u32 v[4:5], null, s15, s4, v[0:1]
	v_mov_b32_e32 v1, 0
	s_getpc_b64 s[4:5]
	s_add_u32 s4, s4, counter_2@rel32@lo+4
	s_addc_u32 s5, s5, counter_2@rel32@hi+12
	global_store_b32 v1, v1, s[4:5]
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_u32_e64 s3, v4
	s_cbranch_execz .LBB0_29
; %bb.1:                                ; %.preheader
	global_load_b32 v0, v1, s[4:5]
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b128 s[4:7], s[0:1], 0x18
	v_ashrrev_i32_e32 v5, 31, v4
	v_cmp_eq_u32_e64 s0, 0, v4
	s_mov_b32 s13, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[2:3], 2, v[4:5]
	v_bfrev_b32_e32 v4, -2
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s8, v2
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v3, vcc_lo, s9, v3, vcc_lo
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_3 Depth 2
                                        ;     Child Loop BB0_7 Depth 2
                                        ;     Child Loop BB0_14 Depth 2
                                        ;     Child Loop BB0_18 Depth 2
	s_waitcnt vmcnt(0)
	v_lshlrev_b64 v[5:6], 2, v[0:1]
	s_getpc_b64 s[14:15]
	s_add_u32 s14, s14, counter_2@rel32@lo+4
	s_addc_u32 s15, s15, counter_2@rel32@hi+12
	s_mov_b32 s12, exec_lo
	s_mov_b32 s1, -1
	v_add_co_u32 v5, vcc_lo, s10, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s11, v6, vcc_lo
	global_store_b32 v[5:6], v4, off
	global_load_b32 v0, v1, s[14:15]
	global_load_b32 v5, v[2:3], off
.LBB0_3:                                ; %ComputeLoop
                                        ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_ctz_i32_b32 s14, s12
	s_waitcnt vmcnt(0)
	v_readlane_b32 s15, v5, s14
	s_lshl_b32 s14, 1, s14
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_and_not1_b32 s12, s12, s14
	s_min_u32 s1, s1, s15
	s_cmp_lg_u32 s12, 0
	s_cbranch_scc1 .LBB0_3
; %bb.4:                                ; %ComputeEnd
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_mbcnt_lo_u32_b32 v5, exec_lo, 0
	s_mov_b32 s12, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_eq_u32_e32 0, v5
	s_xor_b32 s12, exec_lo, s12
	s_cbranch_execz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_2 Depth=1
	v_lshlrev_b64 v[5:6], 2, v[0:1]
	v_mov_b32_e32 v0, s1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v5, vcc_lo, s10, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s11, v6, vcc_lo
	global_atomic_min_u32 v[5:6], v0, off
.LBB0_6:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s12
	s_getpc_b64 s[14:15]
	s_add_u32 s14, s14, counter_2@rel32@lo+4
	s_addc_u32 s15, s15, counter_2@rel32@hi+12
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	global_load_b32 v0, v1, s[14:15]
	s_mov_b32 s1, 0
	s_waitcnt vmcnt(0)
	v_readfirstlane_b32 s12, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b64 s[14:15], s[12:13], 2
	s_add_u32 s16, s10, s14
	s_addc_u32 s17, s11, s15
	global_load_b32 v0, v1, s[16:17]
	s_mov_b64 s[16:17], s[8:9]
.LBB0_7:                                ; %.lr.ph.i
                                        ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	global_load_b32 v5, v1, s[16:17]
	s_mov_b32 s12, -1
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, v5, v0
	s_cbranch_vccnz .LBB0_9
; %bb.8:                                ;   in Loop: Header=BB0_7 Depth=2
	s_add_i32 s1, s1, 1
	s_add_u32 s16, s16, 4
	s_addc_u32 s17, s17, 0
	s_cmp_eq_u32 s3, s1
	s_mov_b32 s18, -1
	s_cselect_b32 s12, -1, 0
	s_branch .LBB0_10
.LBB0_9:                                ;   in Loop: Header=BB0_7 Depth=2
	s_mov_b32 s18, s1
                                        ; implicit-def: $sgpr16_sgpr17
.LBB0_10:                               ; %Flow69
                                        ;   in Loop: Header=BB0_7 Depth=2
	s_and_not1_b32 vcc_lo, exec_lo, s12
	s_cbranch_vccnz .LBB0_7
; %bb.11:                               ; %_Z9findIndexPjjj.exit
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_mov_b32_e32 v0, s18
	s_add_u32 s14, s6, s14
	s_addc_u32 s15, s7, s15
	s_ashr_i32 s19, s18, 31
	global_store_b32 v1, v0, s[14:15]
	s_lshl_b64 s[14:15], s[18:19], 2
	s_waitcnt_vscnt null, 0x0
	s_add_u32 s14, s8, s14
	s_addc_u32 s15, s9, s15
	s_barrier
	buffer_gl0_inv
	global_store_b32 v1, v4, s[14:15]
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_13
; %bb.12:                               ;   in Loop: Header=BB0_2 Depth=1
	v_mov_b32_e32 v0, s2
	s_getpc_b64 s[14:15]
	s_add_u32 s14, s14, counter_2@rel32@lo+4
	s_addc_u32 s15, s15, counter_2@rel32@hi+12
	global_atomic_inc_u32 v1, v0, s[14:15]
.LBB0_13:                               ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_getpc_b64 s[14:15]
	s_add_u32 s14, s14, counter_2@rel32@lo+4
	s_addc_u32 s15, s15, counter_2@rel32@hi+12
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	global_load_b32 v0, v1, s[14:15]
	s_mov_b32 s1, exec_lo
	s_mov_b32 s12, -1
	s_waitcnt vmcnt(0)
	v_lshlrev_b64 v[5:6], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v5, vcc_lo, s10, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s11, v6, vcc_lo
	global_store_b32 v[5:6], v4, off
	global_load_b32 v0, v1, s[14:15]
	global_load_b32 v5, v[2:3], off
.LBB0_14:                               ; %ComputeLoop42
                                        ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_ctz_i32_b32 s14, s1
	s_waitcnt vmcnt(0)
	v_readlane_b32 s15, v5, s14
	s_lshl_b32 s14, 1, s14
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_and_not1_b32 s1, s1, s14
	s_min_u32 s12, s12, s15
	s_cmp_lg_u32 s1, 0
	s_cbranch_scc1 .LBB0_14
; %bb.15:                               ; %ComputeEnd43
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_mbcnt_lo_u32_b32 v5, exec_lo, 0
	s_mov_b32 s1, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_eq_u32_e32 0, v5
	s_xor_b32 s1, exec_lo, s1
	s_cbranch_execz .LBB0_17
; %bb.16:                               ;   in Loop: Header=BB0_2 Depth=1
	v_lshlrev_b64 v[5:6], 2, v[0:1]
	v_mov_b32_e32 v0, s12
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v5, vcc_lo, s10, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s11, v6, vcc_lo
	global_atomic_min_u32 v[5:6], v0, off
.LBB0_17:                               ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_getpc_b64 s[14:15]
	s_add_u32 s14, s14, counter_2@rel32@lo+4
	s_addc_u32 s15, s15, counter_2@rel32@hi+12
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	global_load_b32 v0, v1, s[14:15]
	s_mov_b32 s1, 0
	s_mov_b64 s[18:19], s[8:9]
	s_waitcnt vmcnt(0)
	v_readfirstlane_b32 s12, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b64 s[16:17], s[12:13], 2
	s_add_u32 s14, s10, s16
	s_addc_u32 s15, s11, s17
	global_load_b32 v0, v1, s[14:15]
.LBB0_18:                               ; %.lr.ph.i37
                                        ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	global_load_b32 v5, v1, s[18:19]
	s_mov_b32 s12, -1
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, v5, v0
	s_cbranch_vccnz .LBB0_20
; %bb.19:                               ;   in Loop: Header=BB0_18 Depth=2
	s_add_i32 s1, s1, 1
	s_add_u32 s18, s18, 4
	s_addc_u32 s19, s19, 0
	s_cmp_eq_u32 s3, s1
	s_mov_b32 s14, -1
	s_cselect_b32 s12, -1, 0
	s_branch .LBB0_21
.LBB0_20:                               ;   in Loop: Header=BB0_18 Depth=2
	s_mov_b32 s14, s1
                                        ; implicit-def: $sgpr18_sgpr19
.LBB0_21:                               ; %Flow
                                        ;   in Loop: Header=BB0_18 Depth=2
	s_and_not1_b32 vcc_lo, exec_lo, s12
	s_cbranch_vccnz .LBB0_18
; %bb.22:                               ; %_Z9findIndexPjjj.exit41
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_mov_b32_e32 v0, s14
	s_add_u32 s18, s6, s16
	s_addc_u32 s19, s7, s17
	s_getpc_b64 s[16:17]
	s_add_u32 s16, s16, counter_2@rel32@lo+4
	s_addc_u32 s17, s17, counter_2@rel32@hi+12
	s_ashr_i32 s15, s14, 31
	global_store_b32 v1, v0, s[18:19]
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	global_load_b32 v0, v1, s[16:17]
	s_lshl_b64 s[14:15], s[14:15], 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	s_add_u32 s14, s8, s14
	s_addc_u32 s15, s9, s15
	s_waitcnt vmcnt(0)
	v_lshlrev_b64 v[5:6], 2, v[0:1]
	v_add_nc_u32_e32 v0, -1, v0
	v_lshlrev_b64 v[7:8], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v5, vcc_lo, s10, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s11, v6, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v7, vcc_lo, s10, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s11, v8, vcc_lo
	s_clause 0x1
	global_load_b32 v0, v[5:6], off
	global_load_b32 v5, v[7:8], off
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v0, v5, v0
	global_store_b32 v1, v0, s[14:15]
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_24
; %bb.23:                               ;   in Loop: Header=BB0_2 Depth=1
	v_mov_b32_e32 v0, s2
	global_atomic_inc_u32 v1, v0, s[16:17]
.LBB0_24:                               ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	global_load_b32 v0, v1, s[16:17]
	s_waitcnt vmcnt(0)
	v_lshlrev_b64 v[5:6], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v5, vcc_lo, s10, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s11, v6, vcc_lo
	global_load_b32 v5, v[5:6], off
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, 0x7fffffff, v5
	s_cbranch_vccnz .LBB0_26
; %bb.25:                               ;   in Loop: Header=BB0_2 Depth=1
	v_dual_mov_b32 v6, v1 :: v_dual_add_nc_u32 v5, -1, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 2, v[5:6]
	v_add_co_u32 v5, vcc_lo, s10, v5
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v6, vcc_lo, s11, v6, vcc_lo
	global_load_b32 v5, v[5:6], off
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e64 s1, 0x7fffffff, v5
	s_branch .LBB0_27
.LBB0_26:                               ;   in Loop: Header=BB0_2 Depth=1
	s_mov_b32 s1, -1
.LBB0_27:                               ; %Flow70
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	s_and_not1_b32 vcc_lo, exec_lo, s1
	s_cbranch_vccnz .LBB0_2
; %bb.28:
	v_mov_b32_e32 v1, 0
	global_store_b32 v1, v0, s[4:5]
.LBB0_29:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z17findLeastFrequentPjS_ijS_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 9
		.amdhsa_next_free_sgpr 20
		.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	_Z17findLeastFrequentPjS_ijS_S_, .Lfunc_end0-_Z17findLeastFrequentPjS_ijS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1364
; NumSgprs: 22
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 22
; NumVGPRsForWavesPerEU: 9
; Occupancy: 16
; WaveLimiterHint : 1
; 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
	.protected	_Z18searchSimilarIndexPjS_S_i ; -- Begin function _Z18searchSimilarIndexPjS_S_i
	.globl	_Z18searchSimilarIndexPjS_S_i
	.p2align	8
	.type	_Z18searchSimilarIndexPjS_S_i,@function
_Z18searchSimilarIndexPjS_S_i:          ; @_Z18searchSimilarIndexPjS_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x2c
	s_load_b32 s2, s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_b32 s3, s3, 0xffff
	s_getpc_b64 s[4:5]
	s_add_u32 s4, s4, counter@rel32@lo+4
	s_addc_u32 s5, s5, counter@rel32@hi+12
	v_mad_u64_u32 v[1:2], null, s15, s3, v[0:1]
	v_mov_b32_e32 v0, 0
	s_mov_b32 s3, exec_lo
	global_store_b32 v0, v0, s[4:5]
	v_cmpx_ne_u32_e64 s2, v1
	s_cbranch_execz .LBB1_4
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	s_ashr_i32 s3, s2, 31
	s_load_b64 s[0:1], s[0:1], 0x10
	s_lshl_b64 s[8:9], s[2:3], 2
	s_mov_b32 s3, exec_lo
	v_lshlrev_b64 v[2:3], 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 v2, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	s_add_u32 s4, s4, s8
	s_addc_u32 s5, s5, s9
	s_clause 0x1
	global_load_b32 v2, v[2:3], off
	global_load_b32 v0, v0, s[4:5]
	s_waitcnt vmcnt(0)
	v_cmpx_eq_u32_e64 v2, v0
	s_cbranch_execz .LBB1_3
; %bb.2:
	s_add_i32 s2, s2, 1
	v_mov_b32_e32 v0, 0
	v_mov_b32_e32 v2, s2
	s_getpc_b64 s[4:5]
	s_add_u32 s4, s4, counter@rel32@lo+4
	s_addc_u32 s5, s5, counter@rel32@hi+12
	global_atomic_inc_u32 v2, v0, v2, s[4:5] glc
	s_waitcnt vmcnt(0)
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	v_add_co_u32 v2, vcc_lo, s6, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
	global_store_b32 v[2:3], v1, off
.LBB1_3:
	s_or_b32 exec_lo, exec_lo, s3
	v_mov_b32_e32 v0, 0
	s_getpc_b64 s[2:3]
	s_add_u32 s2, s2, counter@rel32@lo+4
	s_addc_u32 s3, s3, counter@rel32@hi+12
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	global_load_b32 v1, v0, s[2:3]
	s_waitcnt vmcnt(0)
	global_store_b32 v0, v1, s[0:1]
.LBB1_4:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z18searchSimilarIndexPjS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 4
		.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	_Z18searchSimilarIndexPjS_S_i, .Lfunc_end1-_Z18searchSimilarIndexPjS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 364
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 4
; 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
	.protected	counter                 ; @counter
	.type	counter,@object
	.section	.bss,"aw",@nobits
	.globl	counter
	.p2align	2, 0x0
counter:
	.long	0                               ; 0x0
	.size	counter, 4

	.protected	counter_2               ; @counter_2
	.type	counter_2,@object
	.globl	counter_2
	.p2align	2, 0x0
counter_2:
	.long	0                               ; 0x0
	.size	counter_2, 4

	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.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 counter
	.addrsig_sym counter_2
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z17findLeastFrequentPjS_ijS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     22
    .sgpr_spill_count: 0
    .symbol:         _Z17findLeastFrequentPjS_ijS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .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
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z18searchSimilarIndexPjS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z18searchSimilarIndexPjS_S_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
