#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;

__constant__ const unsigned int INTMAX = 2147483647;

// structure for dictionary
struct huffmanDictionary{
    unsigned char bitSequence[256][191];
    unsigned char bitSequenceLength[256];
};

// structure for node
struct huffmanNode{
    unsigned char letter;
    unsigned int frequency;
    struct huffmanNode * left, * right;
};

struct huffmanNode * huffmanTreeNode_head;
struct huffmanDictionary huffmanDict;
struct huffmanNode huffmanTreeNode[512];
unsigned char bitSequenceConstMemory[256][255];

__global__ void CalculateFrequency(unsigned char * device_inputFileData , unsigned int * device_frequency, unsigned int inputFileLength)
{
    unsigned int id = blockIdx.x * blockDim.x + threadIdx.x ;
    if(id < inputFileLength){
        atomicAdd(& device_frequency[device_inputFileData[id]] , 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;
    }
}

__global__ void compress(unsigned char * device_inputFileData,
    unsigned int * device_compressedDataOffset,
    struct huffmanDictionary * device_huffmanDictionary,
    unsigned char * device_byteCompressedData,
    unsigned int device_inputFileLength)
{
    __shared__ struct huffmanDictionary table;
    memcpy(& table, device_huffmanDictionary, sizeof(struct huffmanDictionary));
    unsigned int inputFileLength = device_inputFileLength;
    unsigned int pos = blockIdx.x * blockDim.x + threadIdx.x;


    for(int i = pos; i < inputFileLength; i += blockDim.x){
        for(int k = 0; k < table.bitSequenceLength[device_inputFileData[i]]; k++){
            device_byteCompressedData[device_compressedDataOffset[i] + k] = table.bitSequence[device_inputFileData[i]][k];
        }
    }

    __syncthreads();

    if(pos == inputFileLength-1){
        unsigned int lastLetterOffset = device_compressedDataOffset[pos] ;
        unsigned int lastLetterSeqLength = table.bitSequenceLength[device_inputFileData[pos]] ;
        unsigned int ActualOffset = lastLetterOffset + lastLetterSeqLength ;
        unsigned int formalOffset = device_compressedDataOffset[inputFileLength] ;
        if(ActualOffset < formalOffset){
            
            for(int i = ActualOffset; i < formalOffset; i++){
                device_byteCompressedData[i] = 0 ;
            }
        }
    }

}


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];
        huffmanTreeNode_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){
        huffmanDict.bitSequenceLength[root -> letter] = bitSequenceLength;
        
        memcpy(huffmanDict.bitSequence[root -> letter], bitSequence, bitSequenceLength * sizeof(unsigned char));
        
    }
}

void createDataOffsetArray(unsigned int * compressedDataOffset, unsigned char * inputFileData, unsigned int inputFileLength)
{
    compressedDataOffset[0] = 0;
    for(int i = 0; i < inputFileLength; i++){
    compressedDataOffset[i + 1] = huffmanDict.bitSequenceLength[inputFileData[i]] + compressedDataOffset[i];
    }
    // not a byte & remaining values
    if(compressedDataOffset[inputFileLength] % 8 != 0){
    compressedDataOffset[inputFileLength] = compressedDataOffset[inputFileLength] + (8 - (compressedDataOffset[inputFileLength] % 8));
    }
}

void launchCudaHuffmanCompress(unsigned char * inputFileData, unsigned int * compressedDataOffset, unsigned char *compressedData, unsigned int inputFileLength, int NumBlocks)
{
    struct huffmanDictionary * device_huffmanDictionary;
    unsigned char * device_inputFileData, * device_byteCompressedData;
    unsigned int * device_compressedDataOffset;
    

    createDataOffsetArray(compressedDataOffset, inputFileData, inputFileLength);
    
    cudaMalloc((void **) & device_inputFileData, inputFileLength * sizeof(unsigned char));
        
    cudaMalloc((void **) & device_compressedDataOffset, (inputFileLength + 1) * sizeof(unsigned int));
        
    cudaMalloc((void **) & device_huffmanDictionary, sizeof(huffmanDictionary));
        
    cudaMemcpy(device_inputFileData, inputFileData, inputFileLength * sizeof(unsigned char), cudaMemcpyHostToDevice);
        
    cudaMemcpy(device_compressedDataOffset, compressedDataOffset, (inputFileLength + 1) * sizeof(unsigned int), cudaMemcpyHostToDevice);
        
    cudaMemcpy(device_huffmanDictionary, & huffmanDict, sizeof(huffmanDict), cudaMemcpyHostToDevice);
    
    cudaMalloc((void **) & device_byteCompressedData, (compressedDataOffset[inputFileLength]) * sizeof(unsigned char));
	
    cudaMemset(device_byteCompressedData, 0, compressedDataOffset[inputFileLength] * sizeof(unsigned char));
	
    compress<<<NumBlocks, BLOCK_SIZE>>>(device_inputFileData, device_compressedDataOffset, device_huffmanDictionary, device_byteCompressedData, inputFileLength);
    
    // copy compressed data from GPU to CPU memory
    cudaMemcpy(compressedData, device_byteCompressedData, ((compressedDataOffset[inputFileLength])) * sizeof(unsigned char), cudaMemcpyDeviceToHost);
    
    // free allocated memory
    cudaFree(device_inputFileData);
    cudaFree(device_compressedDataOffset);
    cudaFree(device_huffmanDictionary);
    cudaFree(device_byteCompressedData);

}

int main(int argc, char ** argv){
    unsigned int distinctCharacterCount, inputFileLength;
    unsigned int frequency[256];
    unsigned char * inputFileData, bitSequenceLength = 0, bitSequence[255];
    unsigned int * compressedDataOffset, cpuTimeUsed;
    long unsigned int  memOffset;
    clock_t start, end;

    FILE * inputFile, * compressedFile;

    // check the arguments
    if(argc != 3){
        printf("Arguments should be input file and output file");
        return -1;
    }

    // read input file, get length and data
    inputFile = fopen(argv[1], "rb");
    fseek(inputFile, 0, SEEK_END);
    inputFileLength = ftell(inputFile);
    printf("Input File length : %d\n", inputFileLength);
    fseek(inputFile, 0, SEEK_SET);
    inputFileData = (unsigned char *) malloc(inputFileLength * sizeof(unsigned char));
    fread(inputFileData, sizeof(unsigned char), inputFileLength, inputFile);
    fclose(inputFile);

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

    // find frequency of each symbols
    for(int i = 0; i < 256; i++)
        frequency[i] = 0;

    unsigned int *device_frequency;
    cudaMalloc(& device_frequency, 256*sizeof(unsigned int));
    cudaMemcpy(device_frequency, frequency, 256*sizeof(unsigned int), cudaMemcpyHostToDevice);

    unsigned char * device_inputFileData;
    cudaMalloc(& device_inputFileData, inputFileLength*sizeof(unsigned char));
    cudaMemcpy(device_inputFileData, inputFileData, inputFileLength*sizeof(unsigned char), cudaMemcpyHostToDevice);

    int NumBlocks;
    if( inputFileLength > 1024){
        NumBlocks = ceil( (float)inputFileLength / BLOCK_SIZE );
    }
    else{
        NumBlocks = 1;
    }

    printf("Num of blocks %d\n",NumBlocks);

    CalculateFrequency<<< NumBlocks, BLOCK_SIZE >>>(device_inputFileData, device_frequency, inputFileLength);
    cudaMemcpy(frequency, device_frequency, 256*sizeof(unsigned int), cudaMemcpyDeviceToHost);

    cudaFree(device_inputFileData);
    cudaFree(device_frequency);

    // initialize the nodes
    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(inputFileLength*sizeof(unsigned int));
    cntMin = (unsigned int *)malloc(sizeof(unsigned int));
    indMin = (unsigned int *)malloc(inputFileLength*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, inputFileLength*sizeof(unsigned int));
    cudaMalloc(&dindMin, inputFileLength*sizeof(unsigned int));
    cudaMalloc(&dcntMin, sizeof(unsigned int));
    cudaMemcpy(tempDFreq, tempFreq, unique*sizeof(unsigned int), cudaMemcpyHostToDevice);

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

    cudaMemcpy(min, dmin, inputFileLength*sizeof(unsigned int), cudaMemcpyDeviceToHost);
    cudaMemcpy(indMin, dindMin, inputFileLength*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);
    //     }

    if(distinctCharacterCount == 1){
        huffmanTreeNode_head = & huffmanTreeNode[0];
    }

    // build the huffman dictionary
    buildHuffmanDictionary(huffmanTreeNode_head, bitSequence, bitSequenceLength);

    // printf("HOST DICTIONARY\n");
    // for(int i = 0; i < 256; i ++){
    //     if(frequency[i]>0){
    //         printf("%c\t",i);
    //         for(int k = 0; k < huffmanDict.bitSequenceLength[i]; k++){
    //             printf("%u",huffmanDict.bitSequence[i][k]);
    //         }
    //         printf("\n");
    //     }
    // }

    memOffset = 0;
    for(int i = 0; i < 256; i++)
        memOffset += frequency[i] * huffmanDict.bitSequenceLength[i];
    long unsigned int actualOffset = memOffset;
    //printf("actual offset %ld\n",actualOffset);
    memOffset = memOffset % 8 == 0 ? memOffset : memOffset + 8 - memOffset % 8;

    printf("Output file length : %ld\n",memOffset/8);

    unsigned int extra = memOffset - actualOffset ;

    // generate offset data array
    compressedDataOffset = (unsigned int * ) malloc((inputFileLength + 1) * sizeof(unsigned int));

    unsigned char *compressedData = (unsigned char * ) malloc(compressedDataOffset[inputFileLength] * sizeof(unsigned char));
    // launch kernel
    launchCudaHuffmanCompress(inputFileData, compressedDataOffset,compressedData, inputFileLength, NumBlocks);

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

    // writing the compressed file to the output
    compressedFile = fopen(argv[2], "wb");
    fwrite(& inputFileLength, sizeof(unsigned int), 1, compressedFile);
    fwrite(& extra, sizeof(unsigned int), 1, compressedFile);
    fwrite(frequency, sizeof(unsigned int), 256, compressedFile);
    fwrite(compressedData, sizeof(unsigned char), compressedDataOffset[inputFileLength], compressedFile);
    fclose(compressedFile);

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

    free(inputFileData);
    free(compressedDataOffset);

    return 0;
}

	.file	"tmpxft_00281f47_00000000-6_compress.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2315:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2315:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.type	_Z10cudaMallocIjE9cudaErrorPPT_m.isra.0, @function
_Z10cudaMallocIjE9cudaErrorPPT_m.isra.0:
.LFB2469:
	.cfi_startproc
	jmp	cudaMalloc@PLT
	.cfi_endproc
.LFE2469:
	.size	_Z10cudaMallocIjE9cudaErrorPPT_m.isra.0, .-_Z10cudaMallocIjE9cudaErrorPPT_m.isra.0
	.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	.L6
	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
.L6:
	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, huffmanTreeNode_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	.L10
	movzbl	%dl, %eax
	leal	1(%rdx), %edx
	movb	$0, (%rsi,%rax)
	movq	8(%rdi), %rdi
	movzbl	%dl, %edx
	call	_Z22buildHuffmanDictionaryP11huffmanNodePhh
.L10:
	cmpq	$0, 16(%rbp)
	jne	.L11
.L14:
	cmpq	$0, 8(%rbp)
	jne	.L9
	movzbl	0(%rbp), %eax
	leaq	huffmanDict(%rip), %rdx
	movzbl	%bl, %ecx
	movq	%r12, %rsi
	movb	%bl, 48896(%rdx,%rax)
	movzbl	0(%rbp), %eax
	imulq	$191, %rax, %rax
	addq	%rdx, %rax
	movq	%rax, %rdi
	rep movsb
	jmp	.L9
.L11:
	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	.L14
.L9:
	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	_Z21createDataOffsetArrayPjPhj
	.type	_Z21createDataOffsetArrayPjPhj, @function
_Z21createDataOffsetArrayPjPhj:
.LFB2310:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	leaq	huffmanDict(%rip), %r8
	movl	%eax, (%rdi)
	xorl	%eax, %eax
.L18:
	cmpl	%edx, %eax
	jnb	.L24
	movzbl	(%rsi,%rax), %ecx
	movzbl	48896(%r8,%rcx), %ecx
	addl	(%rdi,%rax,4), %ecx
	movl	%ecx, 4(%rdi,%rax,4)
	incq	%rax
	jmp	.L18
.L24:
	movl	%edx, %edx
	leaq	(%rdi,%rdx,4), %rdx
	movl	(%rdx), %eax
	testb	$7, %al
	je	.L17
	andl	$-8, %eax
	addl	$8, %eax
	movl	%eax, (%rdx)
.L17:
	ret
	.cfi_endproc
.LFE2310:
	.size	_Z21createDataOffsetArrayPjPhj, .-_Z21createDataOffsetArrayPjPhj
	.globl	_Z41__device_stub__Z18CalculateFrequencyPhPjjPhPjj
	.type	_Z41__device_stub__Z18CalculateFrequencyPhPjjPhPjj, @function
_Z41__device_stub__Z18CalculateFrequencyPhPjjPhPjj:
.LFB2337:
	.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	.L25
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z18CalculateFrequencyPhPjj(%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
.L25:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2337:
	.size	_Z41__device_stub__Z18CalculateFrequencyPhPjjPhPjj, .-_Z41__device_stub__Z18CalculateFrequencyPhPjjPhPjj
	.globl	_Z18CalculateFrequencyPhPjj
	.type	_Z18CalculateFrequencyPhPjj, @function
_Z18CalculateFrequencyPhPjj:
.LFB2338:
	.cfi_startproc
	endbr64
	jmp	_Z41__device_stub__Z18CalculateFrequencyPhPjjPhPjj
	.cfi_endproc
.LFE2338:
	.size	_Z18CalculateFrequencyPhPjj, .-_Z18CalculateFrequencyPhPjj
	.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_:
.LFB2339:
	.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	.L30
	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
.L30:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L32
	call	__stack_chk_fail@PLT
.L32:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2339:
	.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_:
.LFB2340:
	.cfi_startproc
	endbr64
	jmp	_Z45__device_stub__Z17findLeastFrequentPjS_ijS_S_PjS_ijS_S_
	.cfi_endproc
.LFE2340:
	.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:
.LFB2341:
	.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	.L35
	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
.L35:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L37
	call	__stack_chk_fail@PLT
.L37:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2341:
	.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:
.LFB2342:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z18searchSimilarIndexPjS_S_iPjS_S_i
	.cfi_endproc
.LFE2342:
	.size	_Z18searchSimilarIndexPjS_S_i, .-_Z18searchSimilarIndexPjS_S_i
	.globl	_Z52__device_stub__Z8compressPhPjP17huffmanDictionaryS_jPhPjP17huffmanDictionaryS_j
	.type	_Z52__device_stub__Z8compressPhPjP17huffmanDictionaryS_jPhPjP17huffmanDictionaryS_j, @function
_Z52__device_stub__Z8compressPhPjP17huffmanDictionaryS_jPhPjP17huffmanDictionaryS_j:
.LFB2343:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movl	%r8d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L40
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z8compressPhPjP17huffmanDictionaryS_j(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L40:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L42
	call	__stack_chk_fail@PLT
.L42:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2343:
	.size	_Z52__device_stub__Z8compressPhPjP17huffmanDictionaryS_jPhPjP17huffmanDictionaryS_j, .-_Z52__device_stub__Z8compressPhPjP17huffmanDictionaryS_jPhPjP17huffmanDictionaryS_j
	.globl	_Z8compressPhPjP17huffmanDictionaryS_j
	.type	_Z8compressPhPjP17huffmanDictionaryS_j, @function
_Z8compressPhPjP17huffmanDictionaryS_j:
.LFB2344:
	.cfi_startproc
	endbr64
	jmp	_Z52__device_stub__Z8compressPhPjP17huffmanDictionaryS_jPhPjP17huffmanDictionaryS_j
	.cfi_endproc
.LFE2344:
	.size	_Z8compressPhPjP17huffmanDictionaryS_j, .-_Z8compressPhPjP17huffmanDictionaryS_j
	.globl	_Z25launchCudaHuffmanCompressPhPjS_ji
	.type	_Z25launchCudaHuffmanCompressPhPjS_ji, @function
_Z25launchCudaHuffmanCompressPhPjS_ji:
.LFB2311:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%ecx, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdx, %r14
	movl	%r15d, %edx
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leal	1(%r15), %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	movq	%rdi, %rsi
	salq	$2, %r12
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rbp, %rdi
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movl	%r8d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	_Z21createDataOffsetArrayPjPhj
	leaq	24(%rsp), %rdi
	movq	%r15, %rsi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movq	%r12, %rsi
	call	cudaMalloc@PLT
	leaq	16(%rsp), %rdi
	movl	$49152, %esi
	call	cudaMalloc@PLT
	movq	24(%rsp), %rdi
	movq	%r15, %rdx
	movq	%r13, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rdi
	movq	%rbp, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	leaq	0(%rbp,%r15,4), %rbp
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movl	$49152, %edx
	leaq	huffmanDict(%rip), %rsi
	call	cudaMemcpy@PLT
	movl	0(%rbp), %esi
	leaq	32(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	0(%rbp), %edx
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movl	12(%rsp), %r8d
	movl	$4194305, %edx
	movabsq	$4294967297, %rax
	movq	%rax, 52(%rsp)
	movl	56(%rsp), %esi
	xorl	%r9d, %r9d
	salq	$10, %rdx
	movl	%r8d, 48(%rsp)
	movq	48(%rsp), %rdi
	xorl	%r8d, %r8d
	movl	$1, %ecx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L46
	movq	32(%rsp), %rcx
	movq	16(%rsp), %rdx
	movl	%r15d, %r8d
	movq	40(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z52__device_stub__Z8compressPhPjP17huffmanDictionaryS_jPhPjP17huffmanDictionaryS_j
.L46:
	movl	0(%rbp), %edx
	movq	32(%rsp), %rsi
	movl	$2, %ecx
	movq	%r14, %rdi
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L47
	call	__stack_chk_fail@PLT
.L47:
	addq	$88, %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
.LFE2311:
	.size	_Z25launchCudaHuffmanCompressPhPjS_ji, .-_Z25launchCudaHuffmanCompressPhPjS_ji
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Arguments should be input file and output file"
.LC1:
	.string	"rb"
.LC2:
	.string	"Input File length : %d\n"
.LC4:
	.string	"Num of blocks %d\n"
.LC5:
	.string	"%d "
.LC6:
	.string	"\n"
.LC7:
	.string	"%d %d\n"
.LC8:
	.string	"Output file length : %ld\n"
.LC9:
	.string	"wb"
.LC10:
	.string	"\n\nTime taken :: %d:%d s\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2312:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$1464, %rsp
	.cfi_def_cfa_offset 1520
	movq	%fs:40, %rax
	movq	%rax, 1448(%rsp)
	xorl	%eax, %eax
	cmpl	$3, %edi
	je	.L50
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	orl	$-1, %eax
	jmp	.L49
.L50:
	movq	8(%rsi), %rdi
	movq	%rsi, %r13
	leaq	.LC1(%rip), %rsi
	call	fopen@PLT
	movl	$2, %edx
	xorl	%esi, %esi
	movq	%rax, %rbx
	movq	%rax, %rdi
	call	fseek@PLT
	movq	%rbx, %rdi
	call	ftell@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	movl	%eax, %edx
	movl	%eax, 68(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%edx, %edx
	xorl	%esi, %esi
	movq	%rbx, %rdi
	call	fseek@PLT
	movl	68(%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)
	leaq	168(%rsp), %rbp
	call	__fread_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	call	clock@PLT
	movl	$256, %ecx
	movq	%rbp, %rdi
	movl	$1024, %esi
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	rep stosl
	leaq	72(%rsp), %rdi
	call	_Z10cudaMallocIjE9cudaErrorPPT_m.isra.0
	movq	72(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$1024, %edx
	call	cudaMemcpy@PLT
	movl	68(%rsp), %esi
	leaq	80(%rsp), %rdi
	call	_Z10cudaMallocIjE9cudaErrorPPT_m.isra.0
	movl	68(%rsp), %edx
	movq	16(%rsp), %rsi
	movl	$1, %ecx
	movq	80(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	68(%rsp), %eax
	movl	$1, 12(%rsp)
	cmpl	$1024, %eax
	jbe	.L52
	cvtsi2ssq	%rax, %xmm0
	mulss	.LC3(%rip), %xmm0
	call	ceilf@PLT
	cvttss2sil	%xmm0, %eax
	movl	%eax, 12(%rsp)
.L52:
	movl	12(%rsp), %edx
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	12(%rsp), %eax
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$4194305, %edx
	movl	$1, %ecx
	movl	$1, 164(%rsp)
	movl	%eax, 144(%rsp)
	salq	$10, %rdx
	movabsq	$4294967297, %rax
	movq	%rax, 148(%rsp)
	movq	144(%rsp), %rdi
	movl	152(%rsp), %esi
	movq	%rdx, 156(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L55
	movl	68(%rsp), %edx
	movq	72(%rsp), %rsi
	movq	80(%rsp), %rdi
	call	_Z41__device_stub__Z18CalculateFrequencyPhPjjPhPjj
.L55:
	movq	72(%rsp), %rsi
	movl	$1024, %edx
	movl	$2, %ecx
	movq	%rbp, %rdi
	call	cudaMemcpy@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%edx, %edx
	xorl	%eax, %eax
	movl	%edx, 40(%rsp)
.L57:
	cmpl	$0, 0(%rbp,%rax,4)
	je	.L56
	incl	40(%rsp)
.L56:
	incq	%rax
	cmpq	$256, %rax
	jne	.L57
	movl	$256, %edi
	xorl	%r15d, %r15d
	xorl	%ebx, %ebx
	call	malloc@PLT
	leaq	88(%rsp), %rdi
	movl	$256, %esi
	leaq	.LC5(%rip), %r12
	movq	%rax, 24(%rsp)
	call	_Z10cudaMallocIjE9cudaErrorPPT_m.isra.0
.L59:
	movl	0(%rbp,%r15,4), %edx
	testl	%edx, %edx
	je	.L58
	movq	24(%rsp), %rax
	leal	1(%rbx), %r14d
	movq	%r12, %rsi
	movl	$2, %edi
	movb	%r15b, (%rax,%rbx)
	xorl	%eax, %eax
	movslq	%r14d, %rbx
	call	__printf_chk@PLT
.L58:
	incq	%r15
	cmpq	$256, %r15
	jne	.L59
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	movslq	%ebx, %r12
	call	__printf_chk@PLT
	movq	24(%rsp), %rsi
	movq	88(%rsp), %rdi
	movl	$256, %edx
	movl	$1, %ecx
	salq	$2, %r12
	call	cudaMemcpy@PLT
	movq	%r12, %rdi
	call	malloc@PLT
	movl	68(%rsp), %r14d
	movq	%rax, 32(%rsp)
	salq	$2, %r14
	movq	%r14, %rdi
	call	malloc@PLT
	movl	$4, %edi
	movq	%rax, %r15
	call	malloc@PLT
	movq	%r14, %rdi
	movq	%rax, %rbp
	call	malloc@PLT
	xorl	%edx, %edx
	movq	%rax, 48(%rsp)
	xorl	%eax, %eax
.L61:
	movl	168(%rsp,%rax,4), %ecx
	testl	%ecx, %ecx
	je	.L60
	movq	32(%rsp), %rdi
	movslq	%edx, %rsi
	incl	%edx
	movl	%ecx, (%rdi,%rsi,4)
.L60:
	incq	%rax
	cmpq	$256, %rax
	jne	.L61
	movq	%r12, %rsi
	leaq	96(%rsp), %rdi
	call	_Z10cudaMallocIjE9cudaErrorPPT_m.isra.0
	movl	68(%rsp), %esi
	leaq	104(%rsp), %rdi
	salq	$2, %rsi
	call	_Z10cudaMallocIjE9cudaErrorPPT_m.isra.0
	movl	68(%rsp), %esi
	leaq	120(%rsp), %rdi
	salq	$2, %rsi
	call	_Z10cudaMallocIjE9cudaErrorPPT_m.isra.0
	leaq	112(%rsp), %rdi
	movl	$4, %esi
	call	_Z10cudaMallocIjE9cudaErrorPPT_m.isra.0
	movq	32(%rsp), %rsi
	movq	96(%rsp), %rdi
	movq	%r12, %rdx
	movl	$1, %ecx
	movl	$1024, %r12d
	call	cudaMemcpy@PLT
	cvtsi2ssl	%ebx, %xmm0
	mulss	.LC3(%rip), %xmm0
	cmpl	$1023, %ebx
	jg	.L62
	movl	%ebx, %eax
	cltd
	idivl	%r12d
	movl	%edx, %r12d
.L62:
	call	ceilf@PLT
	movl	%r12d, %ecx
	movl	$2, %edi
	xorl	%eax, %eax
	cvttss2sil	%xmm0, %r14d
	leaq	.LC7(%rip), %rsi
	movl	%r14d, %edx
	call	__printf_chk@PLT
	movl	%r12d, 156(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	%r14d, 144(%rsp)
	movq	%rax, 160(%rsp)
	movl	164(%rsp), %ecx
	movq	%rax, 148(%rsp)
	movq	156(%rsp), %rdx
	movq	144(%rsp), %rdi
	movl	152(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L63
	movq	120(%rsp), %r9
	movq	112(%rsp), %r8
	movl	%ebx, %ecx
	movl	68(%rsp), %edx
	movq	104(%rsp), %rsi
	movq	96(%rsp), %rdi
	call	_Z45__device_stub__Z17findLeastFrequentPjS_ijS_S_PjS_ijS_S_
.L63:
	call	cudaDeviceSynchronize@PLT
	movl	68(%rsp), %edx
	movq	104(%rsp), %rsi
	movq	%r15, %rdi
	movabsq	$4294967297, %r14
	movl	$2, %ecx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	68(%rsp), %edx
	movq	120(%rsp), %rsi
	movl	$2, %ecx
	movq	48(%rsp), %rdi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	112(%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	128(%rsp), %rdi
	xorl	%ebx, %ebx
	movq	%rax, %r12
	call	_Z10cudaMallocIjE9cudaErrorPPT_m.isra.0
	movl	$4, %edi
	call	malloc@PLT
	leaq	136(%rsp), %rdi
	movl	$4, %esi
	movq	%rax, %r15
	call	_Z10cudaMallocIjE9cudaErrorPPT_m.isra.0
.L64:
	movl	0(%rbp), %eax
	movl	%ebx, 44(%rsp)
	decl	%eax
	cmpl	%eax, %ebx
	jnb	.L92
	leal	1(%rbx), %eax
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC3(%rip), %xmm0
	call	ceilf@PLT
	movl	$1023, %eax
	movq	%r14, 160(%rsp)
	movl	164(%rsp), %ecx
	cmpl	%eax, %ebx
	movq	%r14, 148(%rsp)
	movl	152(%rsp), %esi
	cmovle	%ebx, %eax
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	incl	%eax
	movl	%eax, 156(%rsp)
	cvttss2sil	%xmm0, %eax
	movq	156(%rsp), %rdx
	movl	%eax, 144(%rsp)
	movq	144(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L65
	movl	44(%rsp), %ecx
	movq	136(%rsp), %rdx
	movq	128(%rsp), %rsi
	movq	120(%rsp), %rdi
	call	_Z43__device_stub__Z18searchSimilarIndexPjS_S_iPjS_S_i
.L65:
	call	cudaDeviceSynchronize@PLT
	movl	0(%rbp), %edx
	movl	$2, %ecx
	movq	%r12, %rdi
	movq	128(%rsp), %rsi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	136(%rsp), %rsi
	movq	%r15, %rdi
	movl	$2, %ecx
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movl	(%r15), %edi
	testl	%edi, %edi
	jne	.L66
	movq	48(%rsp), %rax
	movl	(%rax,%rbx,4), %r8d
	jmp	.L67
.L66:
	movl	%edi, %eax
	movq	%r12, %rdx
	leaq	(%r12,%rax,4), %rcx
	movq	%r12, %rax
.L68:
	addq	$4, %rax
	movl	(%rdx), %r8d
	cmpq	%rax, %rcx
	je	.L93
	cmpl	(%rax), %r8d
	cmovb	%rax, %rdx
	jmp	.L68
.L93:
	decl	%r8d
.L67:
	movl	44(%rsp), %ecx
	movq	32(%rsp), %rdx
	incq	%rbx
	movq	24(%rsp), %rsi
	call	_Z16buildHuffmanTreeiPhPjii
	jmp	.L64
.L92:
	cmpl	$1, 40(%rsp)
	jne	.L72
	leaq	huffmanTreeNode(%rip), %rax
	movq	%rax, huffmanTreeNode_head(%rip)
.L72:
	movq	huffmanTreeNode_head(%rip), %rdi
	leaq	1193(%rsp), %rsi
	xorl	%edx, %edx
	xorl	%ebp, %ebp
	leaq	168(%rsp), %r14
	call	_Z22buildHuffmanDictionaryP11huffmanNodePhh
	xorl	%eax, %eax
	leaq	48896+huffmanDict(%rip), %rcx
.L73:
	movzbl	(%rcx,%rax), %edx
	imull	(%r14,%rax,4), %edx
	incq	%rax
	addq	%rdx, %rbp
	cmpq	$256, %rax
	jne	.L73
	movq	%rbp, %rbx
	testl	$7, %ebp
	je	.L74
	andq	$-8, %rbx
	addq	$8, %rbx
.L74:
	movq	%rbx, %rdx
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	shrq	$3, %rdx
	subl	%ebp, %ebx
	call	__printf_chk@PLT
	movl	68(%rsp), %r12d
	movl	%ebx, 156(%rsp)
	leal	1(%r12), %edi
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %rbx
	movl	%r12d, %eax
	movl	(%rbx,%rax,4), %edi
	call	malloc@PLT
	movl	12(%rsp), %r8d
	movl	%r12d, %ecx
	movq	%rbx, %rsi
	movq	16(%rsp), %rdi
	movq	%rax, %rdx
	movq	%rax, %rbp
	call	_Z25launchCudaHuffmanCompressPhPjS_ji
	call	clock@PLT
	movq	16(%r13), %rdi
	leaq	.LC9(%rip), %rsi
	movq	%rax, %r12
	call	fopen@PLT
	leaq	68(%rsp), %rdi
	movl	$1, %edx
	movl	$4, %esi
	movq	%rax, %r13
	movq	%rax, %rcx
	call	fwrite@PLT
	leaq	156(%rsp), %rdi
	movq	%r13, %rcx
	movl	$1, %edx
	movl	$4, %esi
	call	fwrite@PLT
	movq	%r13, %rcx
	movl	$256, %edx
	movq	%r14, %rdi
	movl	$4, %esi
	call	fwrite@PLT
	movl	68(%rsp), %eax
	movq	%r13, %rcx
	movq	%rbp, %rdi
	movl	$1, %esi
	movl	(%rbx,%rax,4), %edx
	call	fwrite@PLT
	movq	%r13, %rdi
	call	fclose@PLT
	movq	56(%rsp), %rcx
	movq	%r12, %rax
	movl	$1000, %esi
	movl	$2, %edi
	subq	%rcx, %rax
	movl	$1000, %ecx
	cqto
	idivq	%rcx
	xorl	%edx, %edx
	divl	%esi
	leaq	.LC10(%rip), %rsi
	movl	%edx, %ecx
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	xorl	%eax, %eax
.L49:
	movq	1448(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L75
	call	__stack_chk_fail@PLT
.L75:
	addq	$1464, %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
.LFE2312:
	.size	main, .-main
	.section	.rodata.str1.1
.LC11:
	.string	"_Z8compressPhPjP17huffmanDictionaryS_j"
.LC12:
	.string	"_Z18searchSimilarIndexPjS_S_i"
.LC13:
	.string	"_Z17findLeastFrequentPjS_ijS_S_"
.LC14:
	.string	"_Z18CalculateFrequencyPhPjj"
.LC15:
	.string	"counter"
.LC16:
	.string	"counter_2"
.LC17:
	.string	"INTMAX"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2346:
	.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	.LC11(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z8compressPhPjP17huffmanDictionaryS_j(%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	.LC12(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z18searchSimilarIndexPjS_S_i(%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	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC13(%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	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC14(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z18CalculateFrequencyPhPjj(%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	.LC15(%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	.LC16(%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	.LC17(%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
.LFE2346:
	.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	bitSequenceConstMemory
	.bss
	.align 32
	.type	bitSequenceConstMemory, @object
	.size	bitSequenceConstMemory, 65280
bitSequenceConstMemory:
	.zero	65280
	.globl	huffmanTreeNode
	.align 32
	.type	huffmanTreeNode, @object
	.size	huffmanTreeNode, 12288
huffmanTreeNode:
	.zero	12288
	.globl	huffmanDict
	.align 32
	.type	huffmanDict, @object
	.size	huffmanDict, 49152
huffmanDict:
	.zero	49152
	.globl	huffmanTreeNode_head
	.align 8
	.type	huffmanTreeNode_head, @object
	.size	huffmanTreeNode_head, 8
huffmanTreeNode_head:
	.zero	8
	.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
.LC3:
	.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;

__constant__ const unsigned int INTMAX = 2147483647;

// structure for dictionary
struct huffmanDictionary{
    unsigned char bitSequence[256][191];
    unsigned char bitSequenceLength[256];
};

// structure for node
struct huffmanNode{
    unsigned char letter;
    unsigned int frequency;
    struct huffmanNode * left, * right;
};

struct huffmanNode * huffmanTreeNode_head;
struct huffmanDictionary huffmanDict;
struct huffmanNode huffmanTreeNode[512];
unsigned char bitSequenceConstMemory[256][255];

__global__ void CalculateFrequency(unsigned char * device_inputFileData , unsigned int * device_frequency, unsigned int inputFileLength)
{
    unsigned int id = blockIdx.x * blockDim.x + threadIdx.x ;
    if(id < inputFileLength){
        atomicAdd(& device_frequency[device_inputFileData[id]] , 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;
    }
}

__global__ void compress(unsigned char * device_inputFileData,
    unsigned int * device_compressedDataOffset,
    struct huffmanDictionary * device_huffmanDictionary,
    unsigned char * device_byteCompressedData,
    unsigned int device_inputFileLength)
{
    __shared__ struct huffmanDictionary table;
    memcpy(& table, device_huffmanDictionary, sizeof(struct huffmanDictionary));
    unsigned int inputFileLength = device_inputFileLength;
    unsigned int pos = blockIdx.x * blockDim.x + threadIdx.x;


    for(int i = pos; i < inputFileLength; i += blockDim.x){
        for(int k = 0; k < table.bitSequenceLength[device_inputFileData[i]]; k++){
            device_byteCompressedData[device_compressedDataOffset[i] + k] = table.bitSequence[device_inputFileData[i]][k];
        }
    }

    __syncthreads();

    if(pos == inputFileLength-1){
        unsigned int lastLetterOffset = device_compressedDataOffset[pos] ;
        unsigned int lastLetterSeqLength = table.bitSequenceLength[device_inputFileData[pos]] ;
        unsigned int ActualOffset = lastLetterOffset + lastLetterSeqLength ;
        unsigned int formalOffset = device_compressedDataOffset[inputFileLength] ;
        if(ActualOffset < formalOffset){
            
            for(int i = ActualOffset; i < formalOffset; i++){
                device_byteCompressedData[i] = 0 ;
            }
        }
    }

}


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];
        huffmanTreeNode_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){
        huffmanDict.bitSequenceLength[root -> letter] = bitSequenceLength;
        
        memcpy(huffmanDict.bitSequence[root -> letter], bitSequence, bitSequenceLength * sizeof(unsigned char));
        
    }
}

void createDataOffsetArray(unsigned int * compressedDataOffset, unsigned char * inputFileData, unsigned int inputFileLength)
{
    compressedDataOffset[0] = 0;
    for(int i = 0; i < inputFileLength; i++){
    compressedDataOffset[i + 1] = huffmanDict.bitSequenceLength[inputFileData[i]] + compressedDataOffset[i];
    }
    // not a byte & remaining values
    if(compressedDataOffset[inputFileLength] % 8 != 0){
    compressedDataOffset[inputFileLength] = compressedDataOffset[inputFileLength] + (8 - (compressedDataOffset[inputFileLength] % 8));
    }
}

void launchCudaHuffmanCompress(unsigned char * inputFileData, unsigned int * compressedDataOffset, unsigned char *compressedData, unsigned int inputFileLength, int NumBlocks)
{
    struct huffmanDictionary * device_huffmanDictionary;
    unsigned char * device_inputFileData, * device_byteCompressedData;
    unsigned int * device_compressedDataOffset;
    

    createDataOffsetArray(compressedDataOffset, inputFileData, inputFileLength);
    
    hipMalloc((void **) & device_inputFileData, inputFileLength * sizeof(unsigned char));
        
    hipMalloc((void **) & device_compressedDataOffset, (inputFileLength + 1) * sizeof(unsigned int));
        
    hipMalloc((void **) & device_huffmanDictionary, sizeof(huffmanDictionary));
        
    hipMemcpy(device_inputFileData, inputFileData, inputFileLength * sizeof(unsigned char), hipMemcpyHostToDevice);
        
    hipMemcpy(device_compressedDataOffset, compressedDataOffset, (inputFileLength + 1) * sizeof(unsigned int), hipMemcpyHostToDevice);
        
    hipMemcpy(device_huffmanDictionary, & huffmanDict, sizeof(huffmanDict), hipMemcpyHostToDevice);
    
    hipMalloc((void **) & device_byteCompressedData, (compressedDataOffset[inputFileLength]) * sizeof(unsigned char));
	
    hipMemset(device_byteCompressedData, 0, compressedDataOffset[inputFileLength] * sizeof(unsigned char));
	
    compress<<<NumBlocks, BLOCK_SIZE>>>(device_inputFileData, device_compressedDataOffset, device_huffmanDictionary, device_byteCompressedData, inputFileLength);
    
    // copy compressed data from GPU to CPU memory
    hipMemcpy(compressedData, device_byteCompressedData, ((compressedDataOffset[inputFileLength])) * sizeof(unsigned char), hipMemcpyDeviceToHost);
    
    // free allocated memory
    hipFree(device_inputFileData);
    hipFree(device_compressedDataOffset);
    hipFree(device_huffmanDictionary);
    hipFree(device_byteCompressedData);

}

int main(int argc, char ** argv){
    unsigned int distinctCharacterCount, inputFileLength;
    unsigned int frequency[256];
    unsigned char * inputFileData, bitSequenceLength = 0, bitSequence[255];
    unsigned int * compressedDataOffset, cpuTimeUsed;
    long unsigned int  memOffset;
    clock_t start, end;

    FILE * inputFile, * compressedFile;

    // check the arguments
    if(argc != 3){
        printf("Arguments should be input file and output file");
        return -1;
    }

    // read input file, get length and data
    inputFile = fopen(argv[1], "rb");
    fseek(inputFile, 0, SEEK_END);
    inputFileLength = ftell(inputFile);
    printf("Input File length : %d\n", inputFileLength);
    fseek(inputFile, 0, SEEK_SET);
    inputFileData = (unsigned char *) malloc(inputFileLength * sizeof(unsigned char));
    fread(inputFileData, sizeof(unsigned char), inputFileLength, inputFile);
    fclose(inputFile);

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

    // find frequency of each symbols
    for(int i = 0; i < 256; i++)
        frequency[i] = 0;

    unsigned int *device_frequency;
    hipMalloc(& device_frequency, 256*sizeof(unsigned int));
    hipMemcpy(device_frequency, frequency, 256*sizeof(unsigned int), hipMemcpyHostToDevice);

    unsigned char * device_inputFileData;
    hipMalloc(& device_inputFileData, inputFileLength*sizeof(unsigned char));
    hipMemcpy(device_inputFileData, inputFileData, inputFileLength*sizeof(unsigned char), hipMemcpyHostToDevice);

    int NumBlocks;
    if( inputFileLength > 1024){
        NumBlocks = ceil( (float)inputFileLength / BLOCK_SIZE );
    }
    else{
        NumBlocks = 1;
    }

    printf("Num of blocks %d\n",NumBlocks);

    CalculateFrequency<<< NumBlocks, BLOCK_SIZE >>>(device_inputFileData, device_frequency, inputFileLength);
    hipMemcpy(frequency, device_frequency, 256*sizeof(unsigned int), hipMemcpyDeviceToHost);

    hipFree(device_inputFileData);
    hipFree(device_frequency);

    // initialize the nodes
    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(inputFileLength*sizeof(unsigned int));
    cntMin = (unsigned int *)malloc(sizeof(unsigned int));
    indMin = (unsigned int *)malloc(inputFileLength*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, inputFileLength*sizeof(unsigned int));
    hipMalloc(&dindMin, inputFileLength*sizeof(unsigned int));
    hipMalloc(&dcntMin, sizeof(unsigned int));
    hipMemcpy(tempDFreq, tempFreq, unique*sizeof(unsigned int), hipMemcpyHostToDevice);

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

    hipMemcpy(min, dmin, inputFileLength*sizeof(unsigned int), hipMemcpyDeviceToHost);
    hipMemcpy(indMin, dindMin, inputFileLength*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);
    //     }

    if(distinctCharacterCount == 1){
        huffmanTreeNode_head = & huffmanTreeNode[0];
    }

    // build the huffman dictionary
    buildHuffmanDictionary(huffmanTreeNode_head, bitSequence, bitSequenceLength);

    // printf("HOST DICTIONARY\n");
    // for(int i = 0; i < 256; i ++){
    //     if(frequency[i]>0){
    //         printf("%c\t",i);
    //         for(int k = 0; k < huffmanDict.bitSequenceLength[i]; k++){
    //             printf("%u",huffmanDict.bitSequence[i][k]);
    //         }
    //         printf("\n");
    //     }
    // }

    memOffset = 0;
    for(int i = 0; i < 256; i++)
        memOffset += frequency[i] * huffmanDict.bitSequenceLength[i];
    long unsigned int actualOffset = memOffset;
    //printf("actual offset %ld\n",actualOffset);
    memOffset = memOffset % 8 == 0 ? memOffset : memOffset + 8 - memOffset % 8;

    printf("Output file length : %ld\n",memOffset/8);

    unsigned int extra = memOffset - actualOffset ;

    // generate offset data array
    compressedDataOffset = (unsigned int * ) malloc((inputFileLength + 1) * sizeof(unsigned int));

    unsigned char *compressedData = (unsigned char * ) malloc(compressedDataOffset[inputFileLength] * sizeof(unsigned char));
    // launch kernel
    launchCudaHuffmanCompress(inputFileData, compressedDataOffset,compressedData, inputFileLength, NumBlocks);

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

    // writing the compressed file to the output
    compressedFile = fopen(argv[2], "wb");
    fwrite(& inputFileLength, sizeof(unsigned int), 1, compressedFile);
    fwrite(& extra, sizeof(unsigned int), 1, compressedFile);
    fwrite(frequency, sizeof(unsigned int), 256, compressedFile);
    fwrite(compressedData, sizeof(unsigned char), compressedDataOffset[inputFileLength], compressedFile);
    fclose(compressedFile);

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

    free(inputFileData);
    free(compressedDataOffset);

    return 0;
}

	.text
	.file	"compress.hip"
	.globl	_Z33__device_stub__CalculateFrequencyPhPjj # -- Begin function _Z33__device_stub__CalculateFrequencyPhPjj
	.type	_Z33__device_stub__CalculateFrequencyPhPjj,@function
_Z33__device_stub__CalculateFrequencyPhPjj: # @_Z33__device_stub__CalculateFrequencyPhPjj
	.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	$_Z18CalculateFrequencyPhPjj, %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_end0:
	.size	_Z33__device_stub__CalculateFrequencyPhPjj, .Lfunc_end0-_Z33__device_stub__CalculateFrequencyPhPjj
	.cfi_endproc
                                        # -- End function
	.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_end1:
	.size	_Z32__device_stub__findLeastFrequentPjS_ijS_S_, .Lfunc_end1-_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_end2:
	.size	_Z33__device_stub__searchSimilarIndexPjS_S_i, .Lfunc_end2-_Z33__device_stub__searchSimilarIndexPjS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z23__device_stub__compressPhPjP17huffmanDictionaryS_j # -- Begin function _Z23__device_stub__compressPhPjP17huffmanDictionaryS_j
	.type	_Z23__device_stub__compressPhPjP17huffmanDictionaryS_j,@function
_Z23__device_stub__compressPhPjP17huffmanDictionaryS_j: # @_Z23__device_stub__compressPhPjP17huffmanDictionaryS_j
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	12(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z8compressPhPjP17huffmanDictionaryS_j, %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_end3:
	.size	_Z23__device_stub__compressPhPjP17huffmanDictionaryS_j, .Lfunc_end3-_Z23__device_stub__compressPhPjP17huffmanDictionaryS_j
	.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	.LBB4_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, huffmanTreeNode_head(%rip)
	retq
.LBB4_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_end4:
	.size	_Z16buildHuffmanTreeiPhPjii, .Lfunc_end4-_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	.LBB5_2
# %bb.1:
	movb	$0, (%rbx,%r14)
	movq	8(%r15), %rdi
	leal	1(%r14), %eax
	movzbl	%al, %edx
	movq	%rbx, %rsi
	callq	_Z22buildHuffmanDictionaryP11huffmanNodePhh
.LBB5_2:
	cmpq	$0, 16(%r15)
	je	.LBB5_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	.LBB5_5
.LBB5_4:                                # %.thread
	cmpq	$0, 8(%r15)
	je	.LBB5_6
.LBB5_5:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB5_6:
	.cfi_def_cfa_offset 32
	movzbl	(%r15), %eax
	movb	%r14b, huffmanDict+48896(%rax)
	movzbl	(%r15), %eax
	imulq	$191, %rax, %rax
	leaq	huffmanDict(%rax), %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_end5:
	.size	_Z22buildHuffmanDictionaryP11huffmanNodePhh, .Lfunc_end5-_Z22buildHuffmanDictionaryP11huffmanNodePhh
	.cfi_endproc
                                        # -- End function
	.globl	_Z21createDataOffsetArrayPjPhj  # -- Begin function _Z21createDataOffsetArrayPjPhj
	.type	_Z21createDataOffsetArrayPjPhj,@function
_Z21createDataOffsetArrayPjPhj:         # @_Z21createDataOffsetArrayPjPhj
	.cfi_startproc
# %bb.0:
	movl	$0, (%rdi)
	xorl	%ecx, %ecx
	testl	%edx, %edx
	je	.LBB6_1
# %bb.5:                                # %.lr.ph.preheader
	movl	%edx, %eax
	xorl	%edx, %edx
.LBB6_6:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movzbl	(%rsi,%rdx), %r8d
	movzbl	huffmanDict+48896(%r8), %r8d
	addl	%r8d, %ecx
	movl	%ecx, 4(%rdi,%rdx,4)
	incq	%rdx
	cmpq	%rdx, %rax
	jne	.LBB6_6
	jmp	.LBB6_2
.LBB6_1:
	xorl	%eax, %eax
.LBB6_2:                                # %._crit_edge
	movl	(%rdi,%rax,4), %ecx
	testb	$7, %cl
	je	.LBB6_4
# %bb.3:
	andl	$-8, %ecx
	addl	$8, %ecx
	movl	%ecx, (%rdi,%rax,4)
.LBB6_4:
	retq
.Lfunc_end6:
	.size	_Z21createDataOffsetArrayPjPhj, .Lfunc_end6-_Z21createDataOffsetArrayPjPhj
	.cfi_endproc
                                        # -- End function
	.globl	_Z25launchCudaHuffmanCompressPhPjS_ji # -- Begin function _Z25launchCudaHuffmanCompressPhPjS_ji
	.type	_Z25launchCudaHuffmanCompressPhPjS_ji,@function
_Z25launchCudaHuffmanCompressPhPjS_ji:  # @_Z25launchCudaHuffmanCompressPhPjS_ji
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%r8d, 20(%rsp)                  # 4-byte Spill
	movl	%ecx, %ebx
	movq	%rdx, 48(%rsp)                  # 8-byte Spill
	movq	%rsi, %r14
	movq	%rdi, %r13
	movl	$0, (%rsi)
	movl	%ecx, %r12d
	testl	%ecx, %ecx
	je	.LBB7_5
# %bb.1:                                # %.lr.ph.preheader.i
	xorl	%eax, %eax
	xorl	%ecx, %ecx
.LBB7_2:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	movzbl	(%r13,%rcx), %edx
	movzbl	huffmanDict+48896(%rdx), %edx
	addl	%edx, %eax
	movl	%eax, 4(%r14,%rcx,4)
	incq	%rcx
	cmpq	%rcx, %r12
	jne	.LBB7_2
# %bb.3:                                # %._crit_edge.i
	movl	(%r14,%r12,4), %eax
	testb	$7, %al
	je	.LBB7_5
# %bb.4:
	andl	$-8, %eax
	addl	$8, %eax
	movl	%eax, (%r14,%r12,4)
.LBB7_5:                                # %_Z21createDataOffsetArrayPjPhj.exit
	leaq	32(%rsp), %rbp
	movq	%rbp, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	%rbx, 40(%rsp)                  # 8-byte Spill
	incl	%ebx
	shlq	$2, %rbx
	leaq	24(%rsp), %r15
	movq	%r15, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$49152, %esi                    # imm = 0xC000
	callq	hipMalloc
	movq	(%rbp), %rdi
	movq	%r13, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r15), %rdi
	movq	%r14, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	8(%rsp), %rax
	movq	(%rax), %rdi
	movl	$huffmanDict, %esi
	movl	$49152, %edx                    # imm = 0xC000
	movl	$1, %ecx
	callq	hipMemcpy
	movl	(%r14,%r12,4), %esi
	movq	%rsp, %rbx
	movq	%rbx, %rdi
	callq	hipMalloc
	movq	(%rbx), %rdi
	movl	(%r14,%r12,4), %edx
	xorl	%esi, %esi
	callq	hipMemset
	movl	20(%rsp), %edi                  # 4-byte Reload
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$1024, %rdx                     # imm = 0x400
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB7_7
# %bb.6:
	movq	32(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	8(%rsp), %rdx
	movq	(%rsp), %rcx
	movq	40(%rsp), %r8                   # 8-byte Reload
                                        # kill: def $r8d killed $r8d killed $r8
	callq	_Z23__device_stub__compressPhPjP17huffmanDictionaryS_j
.LBB7_7:
	movq	(%rsp), %rsi
	movl	(%r14,%r12,4), %edx
	movq	48(%rsp), %rdi                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	addq	$56, %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_end7:
	.size	_Z25launchCudaHuffmanCompressPhPjS_ji, .Lfunc_end7-_Z25launchCudaHuffmanCompressPhPjS_ji
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI8_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	$1464, %rsp                     # imm = 0x5B8
	.cfi_def_cfa_offset 1520
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$3, %edi
	jne	.LBB8_1
# %bb.2:
	movq	%rsi, 120(%rsp)                 # 8-byte Spill
	movq	8(%rsi), %rdi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, %rbx
	movq	%rax, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	fseek
	movq	%rbx, %rdi
	callq	ftell
	movq	%rax, %r13
	movl	%r13d, 52(%rsp)
	movl	$.L.str.2, %edi
	movl	%r13d, %esi
	xorl	%eax, %eax
	callq	printf
	movq	%rbx, %rdi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	fseek
	movl	%r13d, %r12d
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r14
	movl	$1, %esi
	movq	%rax, %rdi
	movq	%r12, %rdx
	movq	%rbx, %rcx
	callq	fread
	movq	%rbx, %rdi
	callq	fclose
	callq	clock
	movq	%rax, 112(%rsp)                 # 8-byte Spill
	leaq	176(%rsp), %rbx
	movl	$1024, %edx                     # imm = 0x400
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	leaq	32(%rsp), %r15
	movl	$1024, %esi                     # imm = 0x400
	movq	%r15, %rdi
	callq	hipMalloc
	movq	(%r15), %rdi
	movl	$1, %ebp
	movl	$1024, %edx                     # imm = 0x400
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	104(%rsp), %rbx
	movq	%rbx, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	(%rbx), %rdi
	movq	%r14, 128(%rsp)                 # 8-byte Spill
	movq	%r14, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r13, (%rsp)                    # 8-byte Spill
	cmpl	$1025, %r13d                    # imm = 0x401
	jb	.LBB8_4
# %bb.3:
	cvtsi2ss	%r12, %xmm0
	mulss	.LCPI8_0(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %ebp
.LBB8_4:
	movabsq	$4294967296, %rbx               # imm = 0x100000000
	xorl	%r14d, %r14d
	movl	$.L.str.3, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	movl	%ebp, %edi
	btsq	$32, %rdi
	leaq	1024(%rbx), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB8_6
# %bb.5:
	movq	104(%rsp), %rdi
	movq	32(%rsp), %rsi
	movq	(%rsp), %rdx                    # 8-byte Reload
                                        # kill: def $edx killed $edx killed $rdx
	callq	_Z33__device_stub__CalculateFrequencyPhPjj
.LBB8_6:
	movl	%ebp, 44(%rsp)                  # 4-byte Spill
	movq	32(%rsp), %rsi
	leaq	176(%rsp), %rdi
	movl	$1024, %edx                     # imm = 0x400
	movl	$2, %ecx
	callq	hipMemcpy
	movq	104(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
.LBB8_7:                                # =>This Inner Loop Header: Depth=1
	cmpl	$1, 176(%rsp,%rax,4)
	sbbl	$-1, %r14d
	incq	%rax
	cmpq	$256, %rax                      # imm = 0x100
	jne	.LBB8_7
# %bb.8:
	movl	$256, %edi                      # imm = 0x100
	callq	malloc
	movq	%rax, %r13
	leaq	168(%rsp), %rdi
	movl	$256, %esi                      # imm = 0x100
	callq	hipMalloc
	xorl	%ebx, %ebx
	xorl	%ebp, %ebp
.LBB8_9:                                # =>This Inner Loop Header: Depth=1
	movl	176(%rsp,%rbx,4), %esi
	testl	%esi, %esi
	je	.LBB8_11
# %bb.10:                               #   in Loop: Header=BB8_9 Depth=1
	movslq	%ebp, %rax
	incl	%ebp
	movb	%bl, (%r13,%rax)
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
.LBB8_11:                               #   in Loop: Header=BB8_9 Depth=1
	incq	%rbx
	cmpq	$256, %rbx                      # imm = 0x100
	jne	.LBB8_9
# %bb.12:
	movl	$10, %edi
	callq	putchar@PLT
	movq	168(%rsp), %rdi
	movl	$256, %edx                      # imm = 0x100
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movslq	%ebp, %rbx
	shlq	$2, %rbx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r15
	leaq	(,%r12,4), %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movl	$4, %edi
	callq	malloc
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	xorl	%eax, %eax
	xorl	%ecx, %ecx
.LBB8_13:                               # =>This Inner Loop Header: Depth=1
	movl	176(%rsp,%rax,4), %edx
	testl	%edx, %edx
	je	.LBB8_15
# %bb.14:                               #   in Loop: Header=BB8_13 Depth=1
	movslq	%ecx, %rsi
	incl	%ecx
	movl	%edx, (%r15,%rsi,4)
.LBB8_15:                               #   in Loop: Header=BB8_13 Depth=1
	incq	%rax
	cmpq	$256, %rax                      # imm = 0x100
	jne	.LBB8_13
# %bb.16:
	leaq	96(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	leaq	88(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	80(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	leaq	96(%rsp), %rax
	movq	(%rax), %rdi
	movq	%r15, 160(%rsp)                 # 8-byte Spill
	movq	%r15, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	cvtsi2ss	%ebp, %xmm0
	mulss	.LCPI8_0(%rip), %xmm0
	leal	1023(%rbp), %eax
	testl	%ebp, %ebp
	cmovnsl	%ebp, %eax
	andl	$-1024, %eax                    # imm = 0xFC00
	movl	%ebp, %ebx
	subl	%eax, %ebx
	movl	$1024, %eax                     # imm = 0x400
	cmpl	%eax, %ebp
	cmovgel	%eax, %ebx
	callq	ceilf@PLT
	movq	%r12, %r15
	cvttss2si	%xmm0, %r12d
	movl	$.L.str.6, %edi
	movl	%r12d, %esi
	movl	%ebx, %edx
	xorl	%eax, %eax
	callq	printf
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %r12
	orq	%rax, %rbx
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB8_18
# %bb.17:
	movq	96(%rsp), %rdi
	movq	88(%rsp), %rsi
	movq	80(%rsp), %r8
	movq	24(%rsp), %r9
	movq	(%rsp), %rdx                    # 8-byte Reload
                                        # kill: def $edx killed $edx killed $rdx
	movl	%ebp, %ecx
	callq	_Z32__device_stub__findLeastFrequentPjS_ijS_S_
.LBB8_18:
	callq	hipDeviceSynchronize
	movq	88(%rsp), %rsi
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	24(%rsp), %rsi
	movq	56(%rsp), %rdi                  # 8-byte Reload
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	80(%rsp), %rsi
	movl	$4, %edx
	movq	16(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	(%r15), %ebx
	shlq	$2, %rbx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r12
	leaq	72(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movl	$4, %edi
	callq	malloc
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	leaq	64(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	cmpl	$1, (%r15)
	je	.LBB8_24
# %bb.19:                               # %.lr.ph
	movq	%r12, %rax
	addq	$4, %rax
	movq	%rax, 136(%rsp)                 # 8-byte Spill
	xorl	%ebx, %ebx
	movabsq	$4294967296, %rax               # imm = 0x100000000
	addq	$1024, %rax                     # imm = 0x400
	movq	%rax, 144(%rsp)                 # 8-byte Spill
	movq	%r13, 152(%rsp)                 # 8-byte Spill
	movl	$1023, %ebp                     # imm = 0x3FF
.LBB8_20:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB8_28 Depth 2
	leaq	1(%rbx), %r15
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r15d, %xmm0
	mulss	.LCPI8_0(%rip), %xmm0
	movq	%r15, %r13
	andq	%rbp, %r13
	callq	ceilf@PLT
	cvttss2si	%xmm0, %edi
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %rdi
	orq	%rax, %r13
	cmpq	%rbp, %rbx
	cmovaeq	144(%rsp), %r13                 # 8-byte Folded Reload
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB8_22
# %bb.21:                               #   in Loop: Header=BB8_20 Depth=1
	movq	24(%rsp), %rdi
	movq	72(%rsp), %rsi
	movq	64(%rsp), %rdx
	movl	%ebx, %ecx
	callq	_Z33__device_stub__searchSimilarIndexPjS_S_i
.LBB8_22:                               #   in Loop: Header=BB8_20 Depth=1
	callq	hipDeviceSynchronize
	movq	72(%rsp), %rsi
	movq	16(%rsp), %rax                  # 8-byte Reload
	movl	(%rax), %edx
	shlq	$2, %rdx
	movq	%r12, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	64(%rsp), %rsi
	movl	$4, %edx
	movq	8(%rsp), %r13                   # 8-byte Reload
	movq	%r13, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	(%r13), %edi
	testq	%rdi, %rdi
	movq	152(%rsp), %r13                 # 8-byte Reload
	je	.LBB8_23
# %bb.26:                               #   in Loop: Header=BB8_20 Depth=1
	movq	%r12, %rax
	cmpl	$1, %edi
	je	.LBB8_29
# %bb.27:                               # %.lr.ph.preheader.i.i
                                        #   in Loop: Header=BB8_20 Depth=1
	movl	(%r12), %ecx
	leaq	-4(,%rdi,4), %rdx
	movq	136(%rsp), %rsi                 # 8-byte Reload
	movq	%r12, %rax
.LBB8_28:                               # %.lr.ph.i.i
                                        #   Parent Loop BB8_20 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	.LBB8_28
.LBB8_29:                               # %_ZSt11max_elementIPjET_S1_S1_.exit
                                        #   in Loop: Header=BB8_20 Depth=1
	movl	(%rax), %r8d
	decl	%r8d
	jmp	.LBB8_30
.LBB8_23:                               #   in Loop: Header=BB8_20 Depth=1
	movq	56(%rsp), %rax                  # 8-byte Reload
	movl	(%rax,%rbx,4), %r8d
.LBB8_30:                               #   in Loop: Header=BB8_20 Depth=1
                                        # kill: def $edi killed $edi killed $rdi
	movq	%r13, %rsi
	movq	160(%rsp), %rdx                 # 8-byte Reload
	movl	%ebx, %ecx
	callq	_Z16buildHuffmanTreeiPhPjii
	movq	16(%rsp), %rax                  # 8-byte Reload
	movl	(%rax), %eax
	decl	%eax
	movq	%r15, %rbx
	cmpq	%rax, %r15
	jb	.LBB8_20
.LBB8_24:                               # %._crit_edge
	cmpl	$1, %r14d
	jne	.LBB8_25
# %bb.31:
	movq	$huffmanTreeNode, huffmanTreeNode_head(%rip)
	movl	$huffmanTreeNode, %edi
	jmp	.LBB8_32
.LBB8_1:
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$-1, %eax
	jmp	.LBB8_35
.LBB8_25:                               # %._crit_edge._crit_edge
	movq	huffmanTreeNode_head(%rip), %rdi
.LBB8_32:
	leaq	1200(%rsp), %rsi
	xorl	%ebx, %ebx
	xorl	%edx, %edx
	callq	_Z22buildHuffmanDictionaryP11huffmanNodePhh
	xorl	%r14d, %r14d
.LBB8_33:                               # =>This Inner Loop Header: Depth=1
	movzbl	huffmanDict+48896(%rbx), %eax
	imull	176(%rsp,%rbx,4), %eax
	addq	%rax, %r14
	incq	%rbx
	cmpq	$256, %rbx                      # imm = 0x100
	jne	.LBB8_33
# %bb.34:
	leaq	7(%r14), %rsi
	movl	%esi, %ebp
	andl	$-8, %ebp
	shrq	$3, %rsi
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	subl	%r14d, %ebp
	leaq	48(%rsp), %rax
	movl	%ebp, (%rax)
	movq	(%rsp), %r12                    # 8-byte Reload
	leaq	4(,%r12,4), %rax
	movabsq	$17179869180, %rdi              # imm = 0x3FFFFFFFC
	andq	%rax, %rdi
	callq	malloc
	movq	%rax, %r14
	xorl	%edi, %edi
	callq	malloc
	movq	%rax, %r15
	movq	128(%rsp), %rbx                 # 8-byte Reload
	movq	%rbx, %rdi
	movq	%r14, %rsi
	movq	%rax, %rdx
	movl	%r12d, %ecx
	movl	44(%rsp), %r8d                  # 4-byte Reload
	callq	_Z25launchCudaHuffmanCompressPhPjS_ji
	callq	clock
	movq	%rax, %r12
	movq	120(%rsp), %rax                 # 8-byte Reload
	movq	16(%rax), %rdi
	movl	$.L.str.8, %esi
	callq	fopen
	movq	%rax, %rbp
	leaq	52(%rsp), %r13
	movl	$4, %esi
	movl	$1, %edx
	movq	%r13, %rdi
	movq	%rax, %rcx
	callq	fwrite
	movl	$4, %esi
	movl	$1, %edx
	leaq	48(%rsp), %rdi
	movq	%rbp, %rcx
	callq	fwrite
	leaq	176(%rsp), %rdi
	movl	$4, %esi
	movl	$256, %edx                      # imm = 0x100
	movq	%rbp, %rcx
	callq	fwrite
	movl	(%r13), %eax
	movl	(%r14,%rax,4), %edx
	movl	$1, %esi
	movq	%r15, %rdi
	movq	%rbp, %rcx
	callq	fwrite
	movq	%rbp, %rdi
	callq	fclose
	subq	112(%rsp), %r12                 # 8-byte Folded Reload
	movabsq	$2361183241434822607, %rcx      # imm = 0x20C49BA5E353F7CF
	movq	%r12, %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.9, %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	%r14, %rdi
	callq	free
	xorl	%eax, %eax
.LBB8_35:
                                        # kill: def $eax killed $eax killed $rax
	addq	$1464, %rsp                     # imm = 0x5B8
	.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_end8:
	.size	main, .Lfunc_end8-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	.LBB9_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB9_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z18CalculateFrequencyPhPjj, %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	$_Z17findLeastFrequentPjS_ijS_S_, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %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_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z8compressPhPjP17huffmanDictionaryS_j, %esi
	movl	$.L__unnamed_4, %edx
	movl	$.L__unnamed_4, %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_5, %edx
	movl	$.L__unnamed_5, %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_6, %edx
	movl	$.L__unnamed_6, %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_end9:
	.size	__hip_module_ctor, .Lfunc_end9-__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	.LBB10_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
.LBB10_2:
	retq
.Lfunc_end10:
	.size	__hip_module_dtor, .Lfunc_end10-__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	huffmanTreeNode_head,@object    # @huffmanTreeNode_head
	.bss
	.globl	huffmanTreeNode_head
	.p2align	3, 0x0
huffmanTreeNode_head:
	.quad	0
	.size	huffmanTreeNode_head, 8

	.type	huffmanDict,@object             # @huffmanDict
	.globl	huffmanDict
huffmanDict:
	.zero	49152
	.size	huffmanDict, 49152

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

	.type	bitSequenceConstMemory,@object  # @bitSequenceConstMemory
	.globl	bitSequenceConstMemory
	.p2align	4, 0x0
bitSequenceConstMemory:
	.zero	65280
	.size	bitSequenceConstMemory, 65280

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

	.type	_Z17findLeastFrequentPjS_ijS_S_,@object # @_Z17findLeastFrequentPjS_ijS_S_
	.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	_Z8compressPhPjP17huffmanDictionaryS_j,@object # @_Z8compressPhPjP17huffmanDictionaryS_j
	.globl	_Z8compressPhPjP17huffmanDictionaryS_j
	.p2align	3, 0x0
_Z8compressPhPjP17huffmanDictionaryS_j:
	.quad	_Z23__device_stub__compressPhPjP17huffmanDictionaryS_j
	.size	_Z8compressPhPjP17huffmanDictionaryS_j, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Arguments should be input file and output file"
	.size	.L.str, 47

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

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Input File length : %d\n"
	.size	.L.str.2, 24

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Num of blocks %d\n"
	.size	.L.str.3, 18

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

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"%d %d\n"
	.size	.L.str.6, 7

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Output file length : %ld\n"
	.size	.L.str.7, 26

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

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z18CalculateFrequencyPhPjj"
	.size	.L__unnamed_1, 28

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z17findLeastFrequentPjS_ijS_S_"
	.size	.L__unnamed_2, 32

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z18searchSimilarIndexPjS_S_i"
	.size	.L__unnamed_3, 30

	.type	.L__unnamed_4,@object           # @3
.L__unnamed_4:
	.asciz	"_Z8compressPhPjP17huffmanDictionaryS_j"
	.size	.L__unnamed_4, 39

	.type	.L__unnamed_5,@object           # @4
.L__unnamed_5:
	.asciz	"counter"
	.size	.L__unnamed_5, 8

	.type	.L__unnamed_6,@object           # @5
.L__unnamed_6:
	.asciz	"counter_2"
	.size	.L__unnamed_6, 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 _Z33__device_stub__CalculateFrequencyPhPjj
	.addrsig_sym _Z32__device_stub__findLeastFrequentPjS_ijS_S_
	.addrsig_sym _Z33__device_stub__searchSimilarIndexPjS_S_i
	.addrsig_sym _Z23__device_stub__compressPhPjP17huffmanDictionaryS_j
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym counter
	.addrsig_sym counter_2
	.addrsig_sym huffmanDict
	.addrsig_sym huffmanTreeNode
	.addrsig_sym _Z18CalculateFrequencyPhPjj
	.addrsig_sym _Z17findLeastFrequentPjS_ijS_S_
	.addrsig_sym _Z18searchSimilarIndexPjS_S_i
	.addrsig_sym _Z8compressPhPjP17huffmanDictionaryS_j
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z18CalculateFrequencyPhPjj ; -- Begin function _Z18CalculateFrequencyPhPjj
	.globl	_Z18CalculateFrequencyPhPjj
	.p2align	8
	.type	_Z18CalculateFrequencyPhPjj,@function
_Z18CalculateFrequencyPhPjj:            ; @_Z18CalculateFrequencyPhPjj
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b32 s3, s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_u32_e64 s3, v1
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	global_load_u8 v0, v1, s[0:1]
	s_waitcnt vmcnt(0)
	v_dual_mov_b32 v1, 1 :: v_dual_lshlrev_b32 v0, 2, v0
	global_atomic_add_u32 v0, v1, s[2:3]
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z18CalculateFrequencyPhPjj
		.amdhsa_group_segment_fixed_size 0
		.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 3
		.amdhsa_next_free_sgpr 16
		.amdhsa_reserve_vcc 0
		.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	_Z18CalculateFrequencyPhPjj, .Lfunc_end0-_Z18CalculateFrequencyPhPjj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 112
; NumSgprs: 16
; NumVgprs: 3
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 16
; NumVGPRsForWavesPerEU: 3
; 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	_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 .LBB1_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
.LBB1_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB1_3 Depth 2
                                        ;     Child Loop BB1_7 Depth 2
                                        ;     Child Loop BB1_14 Depth 2
                                        ;     Child Loop BB1_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
.LBB1_3:                                ; %ComputeLoop
                                        ;   Parent Loop BB1_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 .LBB1_3
; %bb.4:                                ; %ComputeEnd
                                        ;   in Loop: Header=BB1_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 .LBB1_6
; %bb.5:                                ;   in Loop: Header=BB1_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
.LBB1_6:                                ;   in Loop: Header=BB1_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]
.LBB1_7:                                ; %.lr.ph.i
                                        ;   Parent Loop BB1_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 .LBB1_9
; %bb.8:                                ;   in Loop: Header=BB1_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 .LBB1_10
.LBB1_9:                                ;   in Loop: Header=BB1_7 Depth=2
	s_mov_b32 s18, s1
                                        ; implicit-def: $sgpr16_sgpr17
.LBB1_10:                               ; %Flow69
                                        ;   in Loop: Header=BB1_7 Depth=2
	s_and_not1_b32 vcc_lo, exec_lo, s12
	s_cbranch_vccnz .LBB1_7
; %bb.11:                               ; %_Z9findIndexPjjj.exit
                                        ;   in Loop: Header=BB1_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 .LBB1_13
; %bb.12:                               ;   in Loop: Header=BB1_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]
.LBB1_13:                               ;   in Loop: Header=BB1_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
.LBB1_14:                               ; %ComputeLoop42
                                        ;   Parent Loop BB1_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 .LBB1_14
; %bb.15:                               ; %ComputeEnd43
                                        ;   in Loop: Header=BB1_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 .LBB1_17
; %bb.16:                               ;   in Loop: Header=BB1_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
.LBB1_17:                               ;   in Loop: Header=BB1_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]
.LBB1_18:                               ; %.lr.ph.i37
                                        ;   Parent Loop BB1_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 .LBB1_20
; %bb.19:                               ;   in Loop: Header=BB1_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 .LBB1_21
.LBB1_20:                               ;   in Loop: Header=BB1_18 Depth=2
	s_mov_b32 s14, s1
                                        ; implicit-def: $sgpr18_sgpr19
.LBB1_21:                               ; %Flow
                                        ;   in Loop: Header=BB1_18 Depth=2
	s_and_not1_b32 vcc_lo, exec_lo, s12
	s_cbranch_vccnz .LBB1_18
; %bb.22:                               ; %_Z9findIndexPjjj.exit41
                                        ;   in Loop: Header=BB1_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 .LBB1_24
; %bb.23:                               ;   in Loop: Header=BB1_2 Depth=1
	v_mov_b32_e32 v0, s2
	global_atomic_inc_u32 v1, v0, s[16:17]
.LBB1_24:                               ;   in Loop: Header=BB1_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 .LBB1_26
; %bb.25:                               ;   in Loop: Header=BB1_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 .LBB1_27
.LBB1_26:                               ;   in Loop: Header=BB1_2 Depth=1
	s_mov_b32 s1, -1
.LBB1_27:                               ; %Flow70
                                        ;   in Loop: Header=BB1_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 .LBB1_2
; %bb.28:
	v_mov_b32_e32 v1, 0
	global_store_b32 v1, v0, s[4:5]
.LBB1_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_end1:
	.size	_Z17findLeastFrequentPjS_ijS_S_, .Lfunc_end1-_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 .LBB2_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 .LBB2_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
.LBB2_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]
.LBB2_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_end2:
	.size	_Z18searchSimilarIndexPjS_S_i, .Lfunc_end2-_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
	.protected	_Z8compressPhPjP17huffmanDictionaryS_j ; -- Begin function _Z8compressPhPjP17huffmanDictionaryS_j
	.globl	_Z8compressPhPjP17huffmanDictionaryS_j
	.p2align	8
	.type	_Z8compressPhPjP17huffmanDictionaryS_j,@function
_Z8compressPhPjP17huffmanDictionaryS_j: ; @_Z8compressPhPjP17huffmanDictionaryS_j
; %bb.0:
	s_load_b256 s[4:11], s[0:1], 0x0
	v_mov_b32_e32 v1, 0
	s_mov_b32 s12, 0
	s_mov_b64 s[2:3], 0
.LBB3_1:                                ; =>This Inner Loop Header: Depth=1
	s_waitcnt lgkmcnt(0)
	s_add_u32 s16, s8, s2
	s_addc_u32 s17, s9, s3
	v_mov_b32_e32 v3, s12
	global_load_b32 v2, v1, s[16:17]
	s_add_i32 s12, s12, 4
	s_add_u32 s2, s2, 4
	s_addc_u32 s3, s3, 0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_lg_u64 s[2:3], 0xc000
	s_waitcnt vmcnt(0)
	v_lshrrev_b32_e32 v4, 8, v2
	v_lshrrev_b32_e32 v5, 24, v2
	ds_store_b8 v3, v2
	ds_store_b8 v3, v4 offset:1
	ds_store_b8_d16_hi v3, v2 offset:2
	ds_store_b8 v3, v5 offset:3
	s_cbranch_scc1 .LBB3_1
; %bb.2:                                ; %_ZL6memcpyPvPKvm.exit
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b32 s0, s[0:1], 0x20
	s_waitcnt lgkmcnt(0)
	s_and_b32 s1, s2, 0xffff
	s_mov_b32 s2, exec_lo
	v_mad_u64_u32 v[1:2], null, s15, s1, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_u32_e64 s0, v1
	s_cbranch_execz .LBB3_8
; %bb.3:                                ; %.preheader44.preheader
	v_mov_b32_e32 v2, v1
	s_mov_b32 s3, 0
.LBB3_4:                                ; %.preheader44
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB3_6 Depth 2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v3, 31, v2
	v_add_co_u32 v4, vcc_lo, s4, v2
	s_mov_b32 s8, exec_lo
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v3, vcc_lo
	global_load_u8 v0, v[4:5], off
	s_waitcnt vmcnt(0)
	v_and_b32_e32 v6, 0xff, v0
	ds_load_u8 v6, v6 offset:48896
	s_waitcnt lgkmcnt(0)
	v_cmpx_ne_u16_e32 0, v6
	s_cbranch_execz .LBB3_7
; %bb.5:                                ; %.lr.ph
                                        ;   in Loop: Header=BB3_4 Depth=1
	v_lshlrev_b64 v[6:7], 2, v[2:3]
	s_mov_b32 s9, 0
	s_mov_b32 s12, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, s6, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, s7, v7, vcc_lo
.LBB3_6:                                ;   Parent Loop BB3_4 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	global_load_b32 v3, v[6:7], off
	v_and_b32_e32 v0, 0xff, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_mad_u32_u24 v0, 0xbf, v0, s12
	ds_load_u8 v0, v0
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v3, s12, v3
	s_add_i32 s12, s12, 1
	s_waitcnt lgkmcnt(0)
	global_store_b8 v3, v0, s[10:11]
	global_load_u8 v0, v[4:5], off
	s_waitcnt vmcnt(0)
	v_and_b32_e32 v3, 0xff, v0
	ds_load_u8 v3, v3 offset:48896
	s_waitcnt lgkmcnt(0)
	v_cmp_ge_u32_e32 vcc_lo, s12, v3
	s_or_b32 s9, vcc_lo, s9
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s9
	s_cbranch_execnz .LBB3_6
.LBB3_7:                                ; %Flow73
                                        ;   in Loop: Header=BB3_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s8
	v_add_nc_u32_e32 v2, s1, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_le_u32_e32 vcc_lo, s0, v2
	s_or_b32 s3, vcc_lo, s3
	s_and_not1_b32 exec_lo, exec_lo, s3
	s_cbranch_execnz .LBB3_4
.LBB3_8:                                ; %Flow75
	s_or_b32 exec_lo, exec_lo, s2
	s_add_i32 s1, s0, -1
	s_waitcnt_vscnt null, 0x0
	v_cmp_eq_u32_e32 vcc_lo, s1, v1
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s1, vcc_lo
	s_cbranch_execz .LBB3_12
; %bb.9:
	global_load_u8 v4, v1, s[4:5]
	v_mov_b32_e32 v2, 0
	s_mov_b32 s1, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_lshl_b64 s[2:3], s[0:1], 2
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_add_u32 s2, s6, s2
	s_addc_u32 s3, s7, s3
	global_load_b32 v3, v2, s[2:3]
	v_add_co_u32 v0, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	global_load_b32 v0, v[0:1], off
	s_waitcnt vmcnt(2)
	ds_load_u8 v1, v4 offset:48896
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_add_nc_u32_e32 v4, v0, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_lt_u32_e32 vcc_lo, v4, v3
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB3_12
; %bb.10:                               ; %.preheader.preheader
	v_ashrrev_i32_e32 v1, 31, v4
	v_add_co_u32 v0, vcc_lo, s10, v4
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s11, v1, vcc_lo
.LBB3_11:                               ; %.preheader
                                        ; =>This Inner Loop Header: Depth=1
	v_add_nc_u32_e32 v4, 1, v4
	global_store_b8 v[0:1], v2, off
	v_add_co_u32 v0, s0, v0, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	v_add_co_ci_u32_e64 v1, s0, 0, v1, s0
	v_cmp_ge_u32_e32 vcc_lo, v4, v3
	s_or_b32 s1, vcc_lo, s1
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB3_11
.LBB3_12:                               ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z8compressPhPjP17huffmanDictionaryS_j
		.amdhsa_group_segment_fixed_size 49152
		.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 8
		.amdhsa_next_free_sgpr 18
		.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_end3:
	.size	_Z8compressPhPjP17huffmanDictionaryS_j, .Lfunc_end3-_Z8compressPhPjP17huffmanDictionaryS_j
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 644
; NumSgprs: 20
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 49152 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 20
; NumVGPRsForWavesPerEU: 8
; 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
	.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:         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: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z18CalculateFrequencyPhPjj
    .private_segment_fixed_size: 0
    .sgpr_count:     16
    .sgpr_spill_count: 0
    .symbol:         _Z18CalculateFrequencyPhPjj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     3
    .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:         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
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         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: 49152
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z8compressPhPjP17huffmanDictionaryS_j
    .private_segment_fixed_size: 0
    .sgpr_count:     20
    .sgpr_spill_count: 0
    .symbol:         _Z8compressPhPjP17huffmanDictionaryS_j.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
