#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <sys/resource.h>

//TODO: add support for when there's more sets than there are blocks
__global__ void gCompress(uint8_t* fours, uint8_t* threes, size_t pitchfour, size_t pitchthree, size_t setcount) {
	long a = blockIdx.x;

	uint8_t* row4;
	uint8_t* row3; 

	do {
		row4 = fours + a * pitchfour;
		row3 = threes + a * pitchthree;
		
		row3[threadIdx.x] = 0;
		row3[threadIdx.x] = (row4[threadIdx.x]) << (2 + (threadIdx.x * 2));
		row3[threadIdx.x] += (row4[threadIdx.x + 1]) >> (4 - (threadIdx.x * 2));

		a += 65535;
	} while(a < setcount);

}

__global__ void gUncompress(uint8_t* fours, uint8_t* threes, size_t pitchfour, size_t pitchthree, size_t setcount) {
	long a = blockIdx.x;

	uint8_t* row4;
	uint8_t* row3; 

	do {
		row4 = fours + a * pitchfour;
		row3 = threes + a * pitchthree;
		
		row4[threadIdx.x] = 0;
		int i, ander = 0;
		for (i = 0; i < threadIdx.x; i++)
			ander += (48 >> (i*2));
		if (threadIdx.x != 0)
			row4[threadIdx.x] = ((row3[threadIdx.x - 1]) << (4 - (2 * (threadIdx.x - 1)))) & ander;
		if (threadIdx.x != 3)
			row4[threadIdx.x] += ((row3[threadIdx.x]) >> (2 + (threadIdx.x * 2)));

		a += 65535;
	} while (a < setcount);

}

uint8_t getCharVal(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else if (c >= 'a' && c <= 'z')
		return 10 + (c - 'a');
	else if (c >= 'A' && c <= 'Z')
		return 36 + (c - 'A');
	else 
		return 62;
}

char getOriginalVal(uint8_t t) {
	if (t <= 9) 
		return '0' + t;
	else if (t >= 10 && t <= 35)
		return 'a' + t - 10;
	else if (t >= 36 && t <= 61)
		return 'A' + t - 36;
	else
		return '\n';
}

bool fileExists (char* name)
{
   FILE* tmp   = fopen (name, "rb");
   bool exists = (tmp != NULL);
   if (tmp != NULL) fclose (tmp);
   return exists;
}

void compress(char* argv[]);
void uncompress(char* argv[]);
size_t setCount;
size_t overflow;
int main(int argc, char* argv[]) {


	if (argc != 3 || (strcmp(argv[1], "-c") != 0 && strcmp(argv[1], "-u") != 0)) {
		fprintf(stderr, "Usage:\n%s -c filename ....... to compress\n%s -u filename ....... to uncompress\n", argv[0], argv[0]);
		exit(0);
	}
	else if (!fileExists(argv[2])) {
		fprintf(stderr, "File %s does not exist.\n", argv[2]);
		exit(0);
	}

    const rlim_t kStackSize = 64L * 1024L * 1024L;   // min stack size = 64 Mb
    struct rlimit rl;
    int result;
    result = getrlimit(RLIMIT_STACK, &rl);
    if (result == 0)
    {
        if (rl.rlim_cur < kStackSize)
        {
            rl.rlim_cur = kStackSize;
            result = setrlimit(RLIMIT_STACK, &rl);
            if (result != 0)
            {
                fprintf(stderr, "setrlimit returned result = %d\n", result);
                exit(0);
            }
        }
    }

	setCount = 0;
	if (strcmp(argv[1], "-c") == 0)
		compress(argv);
	else {
		uncompress(argv);
	}


	exit(0);
}


void compress(char* argv[]) {
	size_t i;

	char* filename = argv[2];
	char* outfilename = (char*)malloc(sizeof(char) * 64);
	sprintf(outfilename, "%s.bcg", filename);
	FILE* infile = fopen(filename, "r");
	FILE* outfile = fopen(outfilename, "w+");

	long filesize = 0;
	fseek(infile, 0, SEEK_END);
	filesize = ftell(infile);
	fseek(infile, 0, SEEK_SET);

	overflow = filesize % 4;
	setCount = filesize / 4;
	if (overflow > 0)
		setCount++;

	uint8_t threebytes[setCount][3];
	uint8_t fourbytes[setCount][4];

	i = 0;
	while (!feof(infile)) {
		fourbytes[i / 4][i % 4] = getCharVal(fgetc(infile));
		i++;
	}
	fclose(infile);

	size_t pitch3, pitch4;
	uint8_t* garr3;
	uint8_t* garr4;

	cudaMallocPitch((void**)&garr3, &pitch3, (size_t)(3 * sizeof(uint8_t)), setCount);
	cudaMallocPitch((void**)&garr4, &pitch4, (size_t)(4 * sizeof(uint8_t)), setCount);

	cudaMemcpy2D((void*)garr4, pitch4, fourbytes, 4 * sizeof(uint8_t), 4 * sizeof(uint8_t), setCount, cudaMemcpyHostToDevice);
	
	if (setCount <= 65535)
		gCompress<<<setCount, 3>>>(garr4, garr3, pitch4, pitch3, setCount);
	else
		gCompress<<<65535, 3>>>(garr4, garr3, pitch4, pitch3, setCount);

	cudaMemcpy2D(threebytes, 3 * sizeof(uint8_t), garr3, pitch3, 3 * sizeof(uint8_t), setCount, cudaMemcpyDeviceToHost);
	cudaFree(garr3);
	cudaFree(garr4);

	for (i = 0; i < setCount; i++) {
		fprintf(outfile, "%c%c%c", threebytes[i][0], threebytes[i][1], threebytes[i][2]);
	}
	fprintf(outfile, "%i", overflow);

	fclose(outfile);
	free(outfilename);	
}

void uncompress(char* argv[]) {
	size_t i;

	//acquire and handle file overhead
	char* filename = argv[2];
	char* outfilename = (char*)malloc(sizeof(char) * 64);
	sprintf(outfilename, "%s.out", filename);
	FILE* infile = fopen(filename, "r");
	FILE* outfile = fopen(outfilename, "w+");

	//determine file size and number of sets
	long filesize = 0;
	fseek(infile, 0, SEEK_END);
	filesize = ftell(infile) - 1; //don't count end delimiter
	fseek(infile, 0, SEEK_SET);

	setCount = filesize / 3;

	uint8_t threebytes[setCount][3];
	uint8_t fourbytes[setCount][4];

	//get file data
	i = 0;
	while (i < filesize) {
		threebytes[i / 3][i % 3] = (uint8_t)(fgetc(infile));
		i++;
	}
	uint8_t delim = fgetc(infile) - '0';
	fclose(infile);	

	//begin gpu section
	size_t pitch3, pitch4;
	uint8_t* garr3;
	uint8_t* garr4;

	cudaMallocPitch((void**)&garr3, &pitch3, (size_t)(3 * sizeof(uint8_t)), setCount);
	cudaMallocPitch((void**)&garr4, &pitch4, (size_t)(4 * sizeof(uint8_t)), setCount);

	cudaMemcpy2D((void*)garr3, pitch3, threebytes, 3 * sizeof(uint8_t), 3 * sizeof(uint8_t), setCount, cudaMemcpyHostToDevice);

	if (setCount <= 65535)
		gUncompress<<<setCount, 4>>>(garr4, garr3, pitch4, pitch3, setCount);
	else
		gUncompress<<<65535, 4>>>(garr4, garr3, pitch4, pitch3, setCount);	

	cudaMemcpy2D(fourbytes, 4 * sizeof(uint8_t), garr4, pitch4, 4 * sizeof(uint8_t), setCount, cudaMemcpyDeviceToHost);
	cudaFree(garr3);
	cudaFree(garr4);

	for (i = 0; i < setCount; i++) {
		if (delim == 0 || i != setCount - 1) 
			fprintf(outfile, "%c%c%c%c", 
				getOriginalVal(fourbytes[i][0]), 
				getOriginalVal(fourbytes[i][1]), 
				getOriginalVal(fourbytes[i][2]), 
				getOriginalVal(fourbytes[i][3]));
		else {
			int k;
			for (k = 0; k < delim; k++)
				fprintf(outfile, "%c", getOriginalVal(fourbytes[i][k]));
		}
	}

	fclose(outfile);
	free(outfilename);
}



	.file	"tmpxft_002ee7dd_00000000-6_basicCompressGpu.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z10getCharValc
	.type	_Z10getCharValc, @function
_Z10getCharValc:
.LFB2027:
	.cfi_startproc
	endbr64
	leal	-48(%rdi), %eax
	cmpb	$9, %al
	jbe	.L2
	leal	-97(%rdi), %eax
	cmpb	$25, %al
	ja	.L4
	leal	-87(%rdi), %eax
	ret
.L4:
	leal	-65(%rdi), %edx
	movb	$62, %al
	cmpb	$25, %dl
	ja	.L2
	leal	-29(%rdi), %eax
.L2:
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z10getCharValc, .-_Z10getCharValc
	.globl	_Z14getOriginalValh
	.type	_Z14getOriginalValh, @function
_Z14getOriginalValh:
.LFB2028:
	.cfi_startproc
	endbr64
	cmpb	$9, %dil
	ja	.L8
	leal	48(%rdi), %eax
	ret
.L8:
	leal	-10(%rdi), %eax
	cmpb	$25, %al
	ja	.L10
	leal	87(%rdi), %eax
	ret
.L10:
	leal	-36(%rdi), %edx
	movb	$10, %al
	cmpb	$25, %dl
	ja	.L7
	leal	29(%rdi), %eax
.L7:
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z14getOriginalValh, .-_Z14getOriginalValh
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"rb"
	.text
	.globl	_Z10fileExistsPc
	.type	_Z10fileExistsPc, @function
_Z10fileExistsPc:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	.LC0(%rip), %rsi
	call	fopen@PLT
	testq	%rax, %rax
	setne	%bl
	je	.L12
	movq	%rax, %rdi
	call	fclose@PLT
.L12:
	movl	%ebx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z10fileExistsPc, .-_Z10fileExistsPc
	.globl	_Z33__device_stub__Z9gCompressPhS_mmmPhS_mmm
	.type	_Z33__device_stub__Z9gCompressPhS_mmmPhS_mmm, @function
_Z33__device_stub__Z9gCompressPhS_mmmPhS_mmm:
.LFB2057:
	.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
	movq	%r8, 8(%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	8(%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	.L18
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z9gCompressPhS_mmm(%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
.L18:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z33__device_stub__Z9gCompressPhS_mmmPhS_mmm, .-_Z33__device_stub__Z9gCompressPhS_mmmPhS_mmm
	.globl	_Z9gCompressPhS_mmm
	.type	_Z9gCompressPhS_mmm, @function
_Z9gCompressPhS_mmm:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z33__device_stub__Z9gCompressPhS_mmmPhS_mmm
	.cfi_endproc
.LFE2058:
	.size	_Z9gCompressPhS_mmm, .-_Z9gCompressPhS_mmm
	.section	.rodata.str1.1
.LC1:
	.string	"%s.bcg"
.LC2:
	.string	"r"
.LC3:
	.string	"w+"
.LC4:
	.string	"%c%c%c"
.LC5:
	.string	"%i"
	.text
	.globl	_Z8compressPPc
	.type	_Z8compressPPc, @function
_Z8compressPPc:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$88, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	16(%rdi), %rbx
	movl	$64, %edi
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	call	malloc@PLT
	leaq	.LC1(%rip), %rcx
	movq	%rbx, %r8
	movl	$64, %edx
	movq	%rax, %rdi
	movq	%rax, %r12
	movl	$2, %esi
	xorl	%eax, %eax
	call	__sprintf_chk@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rbx, %rdi
	call	fopen@PLT
	leaq	.LC3(%rip), %rsi
	movq	%r12, %rdi
	movq	%rax, -120(%rbp)
	call	fopen@PLT
	movq	-120(%rbp), %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	movq	%rax, %r13
	call	fseek@PLT
	movq	-120(%rbp), %rdi
	call	ftell@PLT
	movq	-120(%rbp), %rdi
	xorl	%edx, %edx
	xorl	%esi, %esi
	movq	%rax, %r14
	call	fseek@PLT
	movq	%r14, %rax
	movl	$4, %ecx
	movq	%rsp, %rsi
	cqto
	idivq	%rcx
	cmpq	$1, %rdx
	movq	%rdx, overflow(%rip)
	sbbq	$-1, %rax
	leaq	(%rax,%rax,2), %rdx
	movq	%rax, setCount(%rip)
	addq	$15, %rdx
	movq	%rdx, %rcx
	andq	$-4096, %rdx
	andq	$-16, %rcx
	subq	%rdx, %rsi
.L25:
	cmpq	%rsi, %rsp
	je	.L26
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L25
.L26:
	andl	$4095, %ecx
	subq	%rcx, %rsp
	testq	%rcx, %rcx
	je	.L27
	orq	$0, -8(%rsp,%rcx)
.L27:
	leaq	15(,%rax,4), %rdx
	movq	%rsp, %rcx
	movq	%rsp, %rbx
	movq	%rdx, %rax
	andq	$-4096, %rdx
	andq	$-16, %rax
	subq	%rdx, %rcx
.L28:
	cmpq	%rcx, %rsp
	je	.L29
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L28
.L29:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L30
	orq	$0, -8(%rsp,%rax)
.L30:
	movq	%rsp, %r15
	xorl	%r14d, %r14d
.L31:
	movq	-120(%rbp), %rdi
	call	feof@PLT
	movq	-120(%rbp), %rdi
	testl	%eax, %eax
	jne	.L51
	call	fgetc@PLT
	movsbl	%al, %edi
	call	_Z10getCharValc
	movq	%r14, %rdx
	movl	%eax, %ecx
	movq	%r14, %rax
	andl	$3, %edx
	incq	%r14
	andq	$-4, %rax
	addq	%r15, %rax
	movb	%cl, (%rax,%rdx)
	jmp	.L31
.L51:
	call	fclose@PLT
	movq	setCount(%rip), %rcx
	leaq	-112(%rbp), %rsi
	leaq	-96(%rbp), %rdi
	movl	$3, %edx
	call	cudaMallocPitch@PLT
	movq	setCount(%rip), %rcx
	leaq	-104(%rbp), %rsi
	leaq	-88(%rbp), %rdi
	movl	$4, %edx
	call	cudaMallocPitch@PLT
	movl	$4, %r8d
	movq	%r15, %rdx
	movl	$4, %ecx
	pushq	%rsi
	movq	-88(%rbp), %rdi
	movq	setCount(%rip), %r9
	movq	-104(%rbp), %rsi
	pushq	$1
	call	cudaMemcpy2D@PLT
	movq	setCount(%rip), %rax
	popq	%rdi
	movabsq	$4294967299, %rdx
	popq	%r8
	movq	%rdx, -68(%rbp)
	cmpq	$65535, %rax
	movl	$1, -60(%rbp)
	ja	.L33
	movl	%eax, -80(%rbp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$4294967297, %rax
	movq	%rax, -76(%rbp)
	movq	-80(%rbp), %rdi
	movl	-72(%rbp), %esi
	jmp	.L50
.L33:
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movl	$1, %esi
	movabsq	$4295032831, %rdi
	movl	$1, -72(%rbp)
	movq	%rdi, -80(%rbp)
.L50:
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L35
	movq	setCount(%rip), %r8
	movq	-112(%rbp), %rcx
	movq	-104(%rbp), %rdx
	movq	-96(%rbp), %rsi
	movq	-88(%rbp), %rdi
	call	_Z33__device_stub__Z9gCompressPhS_mmmPhS_mmm
.L35:
	pushq	%rax
	movq	setCount(%rip), %r9
	movl	$3, %esi
	movq	%rbx, %rdi
	pushq	$2
	movq	-112(%rbp), %rcx
	movl	$3, %r8d
	xorl	%r14d, %r14d
	movq	-96(%rbp), %rdx
	leaq	.LC4(%rip), %r15
	call	cudaMemcpy2D@PLT
	movq	-96(%rbp), %rdi
	popq	%rdx
	popq	%rcx
	call	cudaFree@PLT
	movq	-88(%rbp), %rdi
	call	cudaFree@PLT
.L37:
	cmpq	setCount(%rip), %r14
	jnb	.L52
	movzbl	(%rbx), %ecx
	movzbl	2(%rbx), %r9d
	movq	%r15, %rdx
	movl	$2, %esi
	movzbl	1(%rbx), %r8d
	movq	%r13, %rdi
	xorl	%eax, %eax
	incq	%r14
	addq	$3, %rbx
	call	__fprintf_chk@PLT
	jmp	.L37
.L52:
	movq	overflow(%rip), %rcx
	leaq	.LC5(%rip), %rdx
	movq	%r13, %rdi
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	%r13, %rdi
	call	fclose@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L39
	call	__stack_chk_fail@PLT
.L39:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z8compressPPc, .-_Z8compressPPc
	.globl	_Z36__device_stub__Z11gUncompressPhS_mmmPhS_mmm
	.type	_Z36__device_stub__Z11gUncompressPhS_mmmPhS_mmm, @function
_Z36__device_stub__Z11gUncompressPhS_mmmPhS_mmm:
.LFB2059:
	.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
	movq	%r8, 8(%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	8(%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	.L53
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z11gUncompressPhS_mmm(%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
.L53:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L55
	call	__stack_chk_fail@PLT
.L55:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2059:
	.size	_Z36__device_stub__Z11gUncompressPhS_mmmPhS_mmm, .-_Z36__device_stub__Z11gUncompressPhS_mmmPhS_mmm
	.globl	_Z11gUncompressPhS_mmm
	.type	_Z11gUncompressPhS_mmm, @function
_Z11gUncompressPhS_mmm:
.LFB2060:
	.cfi_startproc
	endbr64
	jmp	_Z36__device_stub__Z11gUncompressPhS_mmmPhS_mmm
	.cfi_endproc
.LFE2060:
	.size	_Z11gUncompressPhS_mmm, .-_Z11gUncompressPhS_mmm
	.section	.rodata.str1.1
.LC6:
	.string	"%s.out"
.LC7:
	.string	"%c%c%c%c"
.LC8:
	.string	"%c"
	.text
	.globl	_Z10uncompressPPc
	.type	_Z10uncompressPPc, @function
_Z10uncompressPPc:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$104, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	16(%rdi), %rbx
	movl	$64, %edi
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	call	malloc@PLT
	movq	%rbx, %r8
	movl	$64, %edx
	leaq	.LC6(%rip), %rcx
	movq	%rax, %rdi
	movq	%rax, -120(%rbp)
	movl	$2, %esi
	xorl	%eax, %eax
	call	__sprintf_chk@PLT
	movq	%rbx, %rdi
	leaq	.LC2(%rip), %rsi
	call	fopen@PLT
	movq	-120(%rbp), %rdi
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rbx
	call	fopen@PLT
	movl	$2, %edx
	xorl	%esi, %esi
	movq	%rbx, %rdi
	movq	%rax, -128(%rbp)
	call	fseek@PLT
	movq	%rbx, %rdi
	call	ftell@PLT
	xorl	%edx, %edx
	xorl	%esi, %esi
	movq	%rbx, %rdi
	leaq	-1(%rax), %r12
	call	fseek@PLT
	movq	%r12, %rax
	movl	$3, %ecx
	movq	%rsp, %rsi
	cqto
	idivq	%rcx
	leaq	(%rax,%rax,2), %rdx
	movq	%rax, setCount(%rip)
	addq	$15, %rdx
	movq	%rdx, %rcx
	andq	$-4096, %rdx
	andq	$-16, %rcx
	subq	%rdx, %rsi
.L59:
	cmpq	%rsi, %rsp
	je	.L60
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L59
.L60:
	andl	$4095, %ecx
	subq	%rcx, %rsp
	testq	%rcx, %rcx
	je	.L61
	orq	$0, -8(%rsp,%rcx)
.L61:
	leaq	15(,%rax,4), %rdx
	movq	%rsp, %rcx
	movq	%rsp, %r14
	movq	%rdx, %rax
	andq	$-4096, %rdx
	andq	$-16, %rax
	subq	%rdx, %rcx
.L62:
	cmpq	%rcx, %rsp
	je	.L63
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L62
.L63:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L64
	orq	$0, -8(%rsp,%rax)
.L64:
	movq	%rsp, -136(%rbp)
	xorl	%r15d, %r15d
	movl	$3, %r13d
.L65:
	movq	%rbx, %rdi
	cmpq	%r12, %r15
	jnb	.L90
	call	fgetc@PLT
	xorl	%edx, %edx
	movl	%eax, %esi
	movq	%r15, %rax
	incq	%r15
	divq	%r13
	leaq	(%rax,%rax,2), %rax
	addq	%r14, %rax
	movb	%sil, (%rax,%rdx)
	jmp	.L65
.L90:
	call	fgetc@PLT
	movq	%rbx, %rdi
	leal	-48(%rax), %r13d
	call	fclose@PLT
	movq	setCount(%rip), %rcx
	leaq	-112(%rbp), %rsi
	leaq	-96(%rbp), %rdi
	movl	$3, %edx
	call	cudaMallocPitch@PLT
	movq	setCount(%rip), %rcx
	leaq	-104(%rbp), %rsi
	leaq	-88(%rbp), %rdi
	movl	$4, %edx
	call	cudaMallocPitch@PLT
	movq	%r14, %rdx
	movl	$3, %r8d
	movl	$3, %ecx
	pushq	%r9
	movq	setCount(%rip), %r9
	movq	-112(%rbp), %rsi
	movq	-96(%rbp), %rdi
	pushq	$1
	call	cudaMemcpy2D@PLT
	movq	setCount(%rip), %rax
	popq	%r10
	movabsq	$4294967300, %rdx
	popq	%r11
	movq	%rdx, -68(%rbp)
	cmpq	$65535, %rax
	movl	$1, -60(%rbp)
	ja	.L67
	movl	%eax, -80(%rbp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$4294967297, %rax
	movq	%rax, -76(%rbp)
	movq	-80(%rbp), %rdi
	movl	-72(%rbp), %esi
	jmp	.L89
.L67:
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movl	$1, %esi
	movabsq	$4295032831, %rdi
	movl	$1, -72(%rbp)
	movq	%rdi, -80(%rbp)
.L89:
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L69
	movq	setCount(%rip), %r8
	movq	-112(%rbp), %rcx
	movq	-104(%rbp), %rdx
	movq	-96(%rbp), %rsi
	movq	-88(%rbp), %rdi
	call	_Z36__device_stub__Z11gUncompressPhS_mmmPhS_mmm
.L69:
	pushq	%rsi
	movq	setCount(%rip), %r9
	movl	$4, %esi
	xorl	%r12d, %r12d
	movq	-104(%rbp), %rcx
	movq	-88(%rbp), %rdx
	pushq	$2
	movl	$4, %r8d
	movq	-136(%rbp), %rdi
	call	cudaMemcpy2D@PLT
	popq	%rdi
	movq	-96(%rbp), %rdi
	popq	%r8
	call	cudaFree@PLT
	movq	-88(%rbp), %rdi
	call	cudaFree@PLT
	movq	-136(%rbp), %rbx
.L71:
	movq	setCount(%rip), %rax
	cmpq	%rax, %r12
	jnb	.L91
	testb	%r13b, %r13b
	je	.L72
	decq	%rax
	cmpq	%r12, %rax
	jne	.L72
	movzbl	%r13b, %r14d
	xorl	%r15d, %r15d
	jmp	.L73
.L72:
	movzbl	3(%rbx), %edi
	call	_Z14getOriginalValh
	movzbl	2(%rbx), %edi
	movsbl	%al, %esi
	call	_Z14getOriginalValh
	movzbl	1(%rbx), %edi
	movsbl	%al, %r9d
	call	_Z14getOriginalValh
	movzbl	(%rbx), %edi
	movsbl	%al, %r8d
	call	_Z14getOriginalValh
	leaq	.LC7(%rip), %rdx
	movsbl	%al, %ecx
	pushq	%rax
	movq	-128(%rbp), %rdi
	xorl	%eax, %eax
	pushq	%rsi
	movl	$2, %esi
	call	__fprintf_chk@PLT
	popq	%rdx
	popq	%rcx
	jmp	.L74
.L73:
	movzbl	(%rbx,%r15), %edi
	movl	$2, %esi
	incq	%r15
	call	_Z14getOriginalValh
	movq	-128(%rbp), %rdi
	leaq	.LC8(%rip), %rdx
	movsbl	%al, %ecx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	cmpl	%r15d, %r14d
	jg	.L73
.L74:
	incq	%r12
	addq	$4, %rbx
	jmp	.L71
.L91:
	movq	-128(%rbp), %rdi
	call	fclose@PLT
	movq	-120(%rbp), %rdi
	call	free@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L76
	call	__stack_chk_fail@PLT
.L76:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z10uncompressPPc, .-_Z10uncompressPPc
	.section	.rodata.str1.1
.LC9:
	.string	"-c"
.LC10:
	.string	"-u"
.LC11:
	.string	"Usage:\n%s -c filename ....... to compress\n%s -u filename ....... to uncompress\n"
.LC12:
	.string	"File %s does not exist.\n"
.LC13:
	.string	"setrlimit returned result = %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rsi, %rbx
	subq	$32, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	cmpl	$3, %edi
	jne	.L93
	movq	8(%rsi), %r12
	leaq	.LC9(%rip), %rbp
	movq	%rbp, %rsi
	movq	%r12, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L94
	leaq	.LC10(%rip), %rsi
	movq	%r12, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L94
.L93:
	movq	(%rbx), %rcx
	movq	stderr(%rip), %rdi
	leaq	.LC11(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	movq	%rcx, %r8
	call	__fprintf_chk@PLT
	jmp	.L110
.L94:
	movq	16(%rbx), %rdi
	call	_Z10fileExistsPc
	testb	%al, %al
	jne	.L95
	movq	16(%rbx), %rcx
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC12(%rip), %rdx
	call	__fprintf_chk@PLT
.L110:
	xorl	%edi, %edi
	call	exit@PLT
.L95:
	leaq	8(%rsp), %r12
	movl	$3, %edi
	movq	%r12, %rsi
	call	getrlimit@PLT
	testl	%eax, %eax
	jne	.L96
	cmpq	$67108863, 8(%rsp)
	ja	.L96
	movq	%r12, %rsi
	movl	$3, %edi
	movq	$67108864, 8(%rsp)
	call	setrlimit@PLT
	movl	%eax, %ecx
	testl	%eax, %eax
	je	.L96
	movq	stderr(%rip), %rdi
	leaq	.LC13(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L110
.L96:
	movq	8(%rbx), %rdi
	xorl	%eax, %eax
	movq	%rbp, %rsi
	movq	%rax, setCount(%rip)
	call	strcmp@PLT
	movq	%rbx, %rdi
	testl	%eax, %eax
	jne	.L97
	call	_Z8compressPPc
	jmp	.L110
.L97:
	call	_Z10uncompressPPc
	jmp	.L110
	.cfi_endproc
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC14:
	.string	"_Z11gUncompressPhS_mmm"
.LC15:
	.string	"_Z9gCompressPhS_mmm"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2062:
	.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	.LC14(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z11gUncompressPhS_mmm(%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	.LC15(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z9gCompressPhS_mmm(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2062:
	.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	overflow
	.bss
	.align 8
	.type	overflow, @object
	.size	overflow, 8
overflow:
	.zero	8
	.globl	setCount
	.align 8
	.type	setCount, @object
	.size	setCount, 8
setCount:
	.zero	8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <sys/resource.h>

//TODO: add support for when there's more sets than there are blocks
__global__ void gCompress(uint8_t* fours, uint8_t* threes, size_t pitchfour, size_t pitchthree, size_t setcount) {
	long a = blockIdx.x;

	uint8_t* row4;
	uint8_t* row3; 

	do {
		row4 = fours + a * pitchfour;
		row3 = threes + a * pitchthree;
		
		row3[threadIdx.x] = 0;
		row3[threadIdx.x] = (row4[threadIdx.x]) << (2 + (threadIdx.x * 2));
		row3[threadIdx.x] += (row4[threadIdx.x + 1]) >> (4 - (threadIdx.x * 2));

		a += 65535;
	} while(a < setcount);

}

__global__ void gUncompress(uint8_t* fours, uint8_t* threes, size_t pitchfour, size_t pitchthree, size_t setcount) {
	long a = blockIdx.x;

	uint8_t* row4;
	uint8_t* row3; 

	do {
		row4 = fours + a * pitchfour;
		row3 = threes + a * pitchthree;
		
		row4[threadIdx.x] = 0;
		int i, ander = 0;
		for (i = 0; i < threadIdx.x; i++)
			ander += (48 >> (i*2));
		if (threadIdx.x != 0)
			row4[threadIdx.x] = ((row3[threadIdx.x - 1]) << (4 - (2 * (threadIdx.x - 1)))) & ander;
		if (threadIdx.x != 3)
			row4[threadIdx.x] += ((row3[threadIdx.x]) >> (2 + (threadIdx.x * 2)));

		a += 65535;
	} while (a < setcount);

}

uint8_t getCharVal(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else if (c >= 'a' && c <= 'z')
		return 10 + (c - 'a');
	else if (c >= 'A' && c <= 'Z')
		return 36 + (c - 'A');
	else 
		return 62;
}

char getOriginalVal(uint8_t t) {
	if (t <= 9) 
		return '0' + t;
	else if (t >= 10 && t <= 35)
		return 'a' + t - 10;
	else if (t >= 36 && t <= 61)
		return 'A' + t - 36;
	else
		return '\n';
}

bool fileExists (char* name)
{
   FILE* tmp   = fopen (name, "rb");
   bool exists = (tmp != NULL);
   if (tmp != NULL) fclose (tmp);
   return exists;
}

void compress(char* argv[]);
void uncompress(char* argv[]);
size_t setCount;
size_t overflow;
int main(int argc, char* argv[]) {


	if (argc != 3 || (strcmp(argv[1], "-c") != 0 && strcmp(argv[1], "-u") != 0)) {
		fprintf(stderr, "Usage:\n%s -c filename ....... to compress\n%s -u filename ....... to uncompress\n", argv[0], argv[0]);
		exit(0);
	}
	else if (!fileExists(argv[2])) {
		fprintf(stderr, "File %s does not exist.\n", argv[2]);
		exit(0);
	}

    const rlim_t kStackSize = 64L * 1024L * 1024L;   // min stack size = 64 Mb
    struct rlimit rl;
    int result;
    result = getrlimit(RLIMIT_STACK, &rl);
    if (result == 0)
    {
        if (rl.rlim_cur < kStackSize)
        {
            rl.rlim_cur = kStackSize;
            result = setrlimit(RLIMIT_STACK, &rl);
            if (result != 0)
            {
                fprintf(stderr, "setrlimit returned result = %d\n", result);
                exit(0);
            }
        }
    }

	setCount = 0;
	if (strcmp(argv[1], "-c") == 0)
		compress(argv);
	else {
		uncompress(argv);
	}


	exit(0);
}


void compress(char* argv[]) {
	size_t i;

	char* filename = argv[2];
	char* outfilename = (char*)malloc(sizeof(char) * 64);
	sprintf(outfilename, "%s.bcg", filename);
	FILE* infile = fopen(filename, "r");
	FILE* outfile = fopen(outfilename, "w+");

	long filesize = 0;
	fseek(infile, 0, SEEK_END);
	filesize = ftell(infile);
	fseek(infile, 0, SEEK_SET);

	overflow = filesize % 4;
	setCount = filesize / 4;
	if (overflow > 0)
		setCount++;

	uint8_t threebytes[setCount][3];
	uint8_t fourbytes[setCount][4];

	i = 0;
	while (!feof(infile)) {
		fourbytes[i / 4][i % 4] = getCharVal(fgetc(infile));
		i++;
	}
	fclose(infile);

	size_t pitch3, pitch4;
	uint8_t* garr3;
	uint8_t* garr4;

	hipMallocPitch((void**)&garr3, &pitch3, (size_t)(3 * sizeof(uint8_t)), setCount);
	hipMallocPitch((void**)&garr4, &pitch4, (size_t)(4 * sizeof(uint8_t)), setCount);

	hipMemcpy2D((void*)garr4, pitch4, fourbytes, 4 * sizeof(uint8_t), 4 * sizeof(uint8_t), setCount, hipMemcpyHostToDevice);
	
	if (setCount <= 65535)
		gCompress<<<setCount, 3>>>(garr4, garr3, pitch4, pitch3, setCount);
	else
		gCompress<<<65535, 3>>>(garr4, garr3, pitch4, pitch3, setCount);

	hipMemcpy2D(threebytes, 3 * sizeof(uint8_t), garr3, pitch3, 3 * sizeof(uint8_t), setCount, hipMemcpyDeviceToHost);
	hipFree(garr3);
	hipFree(garr4);

	for (i = 0; i < setCount; i++) {
		fprintf(outfile, "%c%c%c", threebytes[i][0], threebytes[i][1], threebytes[i][2]);
	}
	fprintf(outfile, "%i", overflow);

	fclose(outfile);
	free(outfilename);	
}

void uncompress(char* argv[]) {
	size_t i;

	//acquire and handle file overhead
	char* filename = argv[2];
	char* outfilename = (char*)malloc(sizeof(char) * 64);
	sprintf(outfilename, "%s.out", filename);
	FILE* infile = fopen(filename, "r");
	FILE* outfile = fopen(outfilename, "w+");

	//determine file size and number of sets
	long filesize = 0;
	fseek(infile, 0, SEEK_END);
	filesize = ftell(infile) - 1; //don't count end delimiter
	fseek(infile, 0, SEEK_SET);

	setCount = filesize / 3;

	uint8_t threebytes[setCount][3];
	uint8_t fourbytes[setCount][4];

	//get file data
	i = 0;
	while (i < filesize) {
		threebytes[i / 3][i % 3] = (uint8_t)(fgetc(infile));
		i++;
	}
	uint8_t delim = fgetc(infile) - '0';
	fclose(infile);	

	//begin gpu section
	size_t pitch3, pitch4;
	uint8_t* garr3;
	uint8_t* garr4;

	hipMallocPitch((void**)&garr3, &pitch3, (size_t)(3 * sizeof(uint8_t)), setCount);
	hipMallocPitch((void**)&garr4, &pitch4, (size_t)(4 * sizeof(uint8_t)), setCount);

	hipMemcpy2D((void*)garr3, pitch3, threebytes, 3 * sizeof(uint8_t), 3 * sizeof(uint8_t), setCount, hipMemcpyHostToDevice);

	if (setCount <= 65535)
		gUncompress<<<setCount, 4>>>(garr4, garr3, pitch4, pitch3, setCount);
	else
		gUncompress<<<65535, 4>>>(garr4, garr3, pitch4, pitch3, setCount);	

	hipMemcpy2D(fourbytes, 4 * sizeof(uint8_t), garr4, pitch4, 4 * sizeof(uint8_t), setCount, hipMemcpyDeviceToHost);
	hipFree(garr3);
	hipFree(garr4);

	for (i = 0; i < setCount; i++) {
		if (delim == 0 || i != setCount - 1) 
			fprintf(outfile, "%c%c%c%c", 
				getOriginalVal(fourbytes[i][0]), 
				getOriginalVal(fourbytes[i][1]), 
				getOriginalVal(fourbytes[i][2]), 
				getOriginalVal(fourbytes[i][3]));
		else {
			int k;
			for (k = 0; k < delim; k++)
				fprintf(outfile, "%c", getOriginalVal(fourbytes[i][k]));
		}
	}

	fclose(outfile);
	free(outfilename);
}



	.text
	.file	"basicCompressGpu.hip"
	.globl	_Z24__device_stub__gCompressPhS_mmm # -- Begin function _Z24__device_stub__gCompressPhS_mmm
	.type	_Z24__device_stub__gCompressPhS_mmm,@function
_Z24__device_stub__gCompressPhS_mmm:    # @_Z24__device_stub__gCompressPhS_mmm
	.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	24(%rsp), %rcx
	movq	%r8, (%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	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	$_Z9gCompressPhS_mmm, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z24__device_stub__gCompressPhS_mmm, .Lfunc_end0-_Z24__device_stub__gCompressPhS_mmm
	.cfi_endproc
                                        # -- End function
	.globl	_Z26__device_stub__gUncompressPhS_mmm # -- Begin function _Z26__device_stub__gUncompressPhS_mmm
	.type	_Z26__device_stub__gUncompressPhS_mmm,@function
_Z26__device_stub__gUncompressPhS_mmm:  # @_Z26__device_stub__gUncompressPhS_mmm
	.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	24(%rsp), %rcx
	movq	%r8, (%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	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	$_Z11gUncompressPhS_mmm, %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	_Z26__device_stub__gUncompressPhS_mmm, .Lfunc_end1-_Z26__device_stub__gUncompressPhS_mmm
	.cfi_endproc
                                        # -- End function
	.globl	_Z10getCharValc                 # -- Begin function _Z10getCharValc
	.type	_Z10getCharValc,@function
_Z10getCharValc:                        # @_Z10getCharValc
	.cfi_startproc
# %bb.0:
                                        # kill: def $edi killed $edi def $rdi
	leal	-48(%rdi), %eax
	cmpb	$10, %al
	jb	.LBB2_4
# %bb.1:
	leal	-97(%rdi), %eax
	cmpb	$25, %al
	ja	.LBB2_3
# %bb.2:
	addb	$-87, %dil
	movl	%edi, %eax
.LBB2_4:
                                        # kill: def $al killed $al killed $eax
	retq
.LBB2_3:
	leal	-65(%rdi), %eax
	addb	$-29, %dil
	cmpb	$26, %al
	movzbl	%dil, %ecx
	movl	$62, %eax
	cmovbl	%ecx, %eax
                                        # kill: def $al killed $al killed $eax
	retq
.Lfunc_end2:
	.size	_Z10getCharValc, .Lfunc_end2-_Z10getCharValc
	.cfi_endproc
                                        # -- End function
	.globl	_Z14getOriginalValh             # -- Begin function _Z14getOriginalValh
	.type	_Z14getOriginalValh,@function
_Z14getOriginalValh:                    # @_Z14getOriginalValh
	.cfi_startproc
# %bb.0:
	movl	%edi, %eax
	cmpb	$9, %al
	ja	.LBB3_3
# %bb.1:
	orb	$48, %al
                                        # kill: def $al killed $al killed $rax
	retq
.LBB3_3:
	cmpb	$35, %al
	ja	.LBB3_5
# %bb.4:
	addb	$87, %al
                                        # kill: def $al killed $al killed $rax
	retq
.LBB3_5:
	leal	29(%rax), %ecx
	cmpb	$62, %al
	movzbl	%cl, %ecx
	movl	$10, %eax
	cmovbl	%ecx, %eax
                                        # kill: def $al killed $al killed $rax
	retq
.Lfunc_end3:
	.size	_Z14getOriginalValh, .Lfunc_end3-_Z14getOriginalValh
	.cfi_endproc
                                        # -- End function
	.globl	_Z10fileExistsPc                # -- Begin function _Z10fileExistsPc
	.type	_Z10fileExistsPc,@function
_Z10fileExistsPc:                       # @_Z10fileExistsPc
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.LBB4_2
# %bb.1:
	movq	%rbx, %rdi
	callq	fclose
.LBB4_2:
	testq	%rbx, %rbx
	setne	%al
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z10fileExistsPc, .Lfunc_end4-_Z10fileExistsPc
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rsi, %rbx
	cmpl	$3, %edi
	jne	.LBB5_3
# %bb.1:
	movq	8(%rbx), %r14
	movl	$.L.str.1, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB5_4
# %bb.2:
	movl	$.L.str.2, %esi
	movq	%r14, %rdi
	callq	strcmp
	testl	%eax, %eax
	jne	.LBB5_3
.LBB5_4:
	movq	16(%rbx), %rdi
	callq	_Z10fileExistsPc
	testb	%al, %al
	je	.LBB5_5
# %bb.6:
	leaq	8(%rsp), %rsi
	movl	$3, %edi
	callq	getrlimit
	testl	%eax, %eax
	jne	.LBB5_10
# %bb.7:
	cmpq	$67108863, 8(%rsp)              # imm = 0x3FFFFFF
	ja	.LBB5_10
# %bb.8:
	leaq	8(%rsp), %rsi
	movq	$67108864, (%rsi)               # imm = 0x4000000
	movl	$3, %edi
	callq	setrlimit
	testl	%eax, %eax
	jne	.LBB5_9
.LBB5_10:
	movq	$0, setCount(%rip)
	movq	8(%rbx), %rdi
	movl	$.L.str.1, %esi
	callq	strcmp
	movq	%rbx, %rdi
	testl	%eax, %eax
	jne	.LBB5_12
# %bb.11:
	callq	_Z8compressPPc
	jmp	.LBB5_13
.LBB5_3:
	movq	stderr(%rip), %rdi
	movq	(%rbx), %rcx
	movl	$.L.str.3, %esi
	movq	%rcx, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB5_13
.LBB5_5:
	movq	stderr(%rip), %rdi
	movq	16(%rbx), %rdx
	movl	$.L.str.4, %esi
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB5_13
.LBB5_12:
	callq	_Z10uncompressPPc
	jmp	.LBB5_13
.LBB5_9:
	movq	stderr(%rip), %rdi
	movl	$.L.str.5, %esi
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	fprintf
.LBB5_13:
	xorl	%edi, %edi
	callq	exit
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z8compressPPc                  # -- Begin function _Z8compressPPc
	.type	_Z8compressPPc,@function
_Z8compressPPc:                         # @_Z8compressPPc
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$40, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	16(%rdi), %r14
	movl	$64, %edi
	callq	malloc
	movq	%rax, %rbx
	movl	$.L.str.6, %esi
	movq	%rax, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	sprintf
	movl	$.L.str.7, %esi
	movq	%r14, %rdi
	callq	fopen
	movq	%rax, %r12
	movl	$.L.str.8, %esi
	movq	%rbx, -72(%rbp)                 # 8-byte Spill
	movq	%rbx, %rdi
	callq	fopen
	movq	%rax, %r14
	movq	%r12, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	fseek
	movq	%r12, %rdi
	callq	ftell
	movq	%rax, %r15
	movq	%r12, %rdi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	fseek
	leaq	3(%r15), %rax
	testq	%r15, %r15
	cmovnsq	%r15, %rax
	movq	%rax, %rcx
	sarq	$2, %rcx
	andq	$-4, %rax
	xorl	%edx, %edx
	subq	%rax, %r15
	movq	%r15, overflow(%rip)
	setne	%dl
	addq	%rcx, %rdx
	movq	%rdx, setCount(%rip)
	leaq	(%rdx,%rdx,2), %rax
	addq	$15, %rax
	andq	$-16, %rax
	movq	%rsp, %r15
	subq	%rax, %r15
	movq	%r15, %rsp
	leaq	15(,%rdx,4), %rax
	andq	$-16, %rax
	movq	%rsp, %r13
	subq	%rax, %r13
	movq	%r13, %rsp
	movq	%r12, %rdi
	callq	feof
	testl	%eax, %eax
	jne	.LBB6_7
# %bb.1:                                # %.lr.ph.preheader
	xorl	%ebx, %ebx
.LBB6_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%r12, %rdi
	callq	fgetc
                                        # kill: def $eax killed $eax def $rax
	leal	-48(%rax), %ecx
	cmpb	$10, %cl
	jb	.LBB6_6
# %bb.3:                                #   in Loop: Header=BB6_2 Depth=1
	leal	-97(%rax), %ecx
	cmpb	$25, %cl
	ja	.LBB6_5
# %bb.4:                                #   in Loop: Header=BB6_2 Depth=1
	addb	$-87, %al
	movl	%eax, %ecx
	jmp	.LBB6_6
.LBB6_5:                                #   in Loop: Header=BB6_2 Depth=1
	leal	-65(%rax), %ecx
	addb	$-29, %al
	cmpb	$26, %cl
	movzbl	%al, %ecx
	movl	$62, %eax
	cmovael	%eax, %ecx
.LBB6_6:                                # %_Z10getCharValc.exit
                                        #   in Loop: Header=BB6_2 Depth=1
	movl	%ebx, %eax
	andl	$3, %eax
	movq	%rbx, %rdx
	andq	$-4, %rdx
	addq	%r13, %rdx
	movb	%cl, (%rax,%rdx)
	incq	%rbx
	movq	%r12, %rdi
	callq	feof
	testl	%eax, %eax
	je	.LBB6_2
.LBB6_7:                                # %._crit_edge
	movq	%r12, %rdi
	callq	fclose
	movq	setCount(%rip), %rcx
	leaq	-48(%rbp), %rdi
	leaq	-64(%rbp), %rsi
	movl	$3, %edx
	callq	hipMallocPitch
	movq	setCount(%rip), %rcx
	leaq	-56(%rbp), %r12
	leaq	-80(%rbp), %rbx
	movl	$4, %edx
	movq	%r12, %rdi
	movq	%rbx, %rsi
	callq	hipMallocPitch
	movq	(%r12), %rdi
	movq	(%rbx), %rsi
	movq	setCount(%rip), %r9
	subq	$8, %rsp
	movl	$4, %ecx
	movl	$4, %r8d
	movq	%r13, %rdx
	pushq	$1
	callq	hipMemcpy2D
	addq	$16, %rsp
	movq	setCount(%rip), %rax
	movabsq	$4294967299, %rdx               # imm = 0x100000003
	cmpq	$65535, %rax                    # imm = 0xFFFF
	ja	.LBB6_9
# %bb.8:
	leaq	(%rax,%rdx), %rdi
	addq	$-3, %rdi
	jmp	.LBB6_10
.LBB6_9:
	leaq	65532(%rdx), %rdi
.LBB6_10:
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	movq	-72(%rbp), %r12                 # 8-byte Reload
	jne	.LBB6_12
# %bb.11:
	movq	-56(%rbp), %rdi
	movq	-48(%rbp), %rsi
	movq	-80(%rbp), %rdx
	movq	-64(%rbp), %rcx
	movq	setCount(%rip), %r8
	callq	_Z24__device_stub__gCompressPhS_mmm
.LBB6_12:
	movq	-48(%rbp), %rdx
	movq	-64(%rbp), %rcx
	movq	setCount(%rip), %r9
	subq	$8, %rsp
	movl	$3, %esi
	movl	$3, %r8d
	movq	%r15, %rdi
	pushq	$2
	callq	hipMemcpy2D
	addq	$16, %rsp
	movq	-48(%rbp), %rdi
	callq	hipFree
	movq	-56(%rbp), %rdi
	callq	hipFree
	cmpq	$0, setCount(%rip)
	je	.LBB6_15
# %bb.13:                               # %.lr.ph48.preheader
	addq	$2, %r15
	xorl	%ebx, %ebx
.LBB6_14:                               # %.lr.ph48
                                        # =>This Inner Loop Header: Depth=1
	movzbl	-2(%r15), %edx
	movzbl	-1(%r15), %ecx
	movzbl	(%r15), %r8d
	movl	$.L.str.9, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%rbx
	addq	$3, %r15
	cmpq	setCount(%rip), %rbx
	jb	.LBB6_14
.LBB6_15:                               # %._crit_edge49
	movq	overflow(%rip), %rdx
	movl	$.L.str.10, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movq	%r14, %rdi
	callq	fclose
	movq	%r12, %rdi
	callq	free
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.Lfunc_end6:
	.size	_Z8compressPPc, .Lfunc_end6-_Z8compressPPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z10uncompressPPc               # -- Begin function _Z10uncompressPPc
	.type	_Z10uncompressPPc,@function
_Z10uncompressPPc:                      # @_Z10uncompressPPc
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	16(%rdi), %rbx
	movl	$64, %edi
	callq	malloc
	movq	%rax, %r14
	movl	$.L.str.11, %esi
	movq	%rax, %rdi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	sprintf
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	callq	fopen
	movq	%rax, %r13
	movl	$.L.str.8, %esi
	movq	%r14, -88(%rbp)                 # 8-byte Spill
	movq	%r14, %rdi
	callq	fopen
	movq	%rax, %r14
	movq	%r13, %rdi
	xorl	%esi, %esi
	movl	$2, %edx
	callq	fseek
	movq	%r13, %rdi
	callq	ftell
	movq	%rax, %r12
	decq	%r12
	movq	%r13, %rdi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	fseek
	movabsq	$6148914691236517206, %rcx      # imm = 0x5555555555555556
	movq	%r12, %rax
	imulq	%rcx
	movq	%rdx, %rax
	shrq	$63, %rax
	addq	%rdx, %rax
	movq	%rax, setCount(%rip)
	leaq	(%rax,%rax,2), %rcx
	addq	$15, %rcx
	andq	$-16, %rcx
	movq	%rsp, %rbx
	subq	%rcx, %rbx
	movq	%rbx, %rsp
	leaq	15(,%rax,4), %rax
	andq	$-16, %rax
	movq	%rsp, %rcx
	subq	%rax, %rcx
	movq	%rcx, -56(%rbp)                 # 8-byte Spill
	movq	%rcx, %rsp
	testq	%r12, %r12
	je	.LBB7_3
# %bb.1:                                # %.lr.ph.preheader
	xorl	%r15d, %r15d
.LBB7_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%r13, %rdi
	callq	fgetc
	movb	%al, (%rbx,%r15)
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB7_2
.LBB7_3:                                # %._crit_edge
	movq	%r13, %rdi
	callq	fgetc
	movl	%eax, %r15d
	movq	%r13, %rdi
	callq	fclose
	movq	setCount(%rip), %rcx
	leaq	-64(%rbp), %r13
	leaq	-80(%rbp), %r12
	movl	$3, %edx
	movq	%r13, %rdi
	movq	%r12, %rsi
	callq	hipMallocPitch
	movq	setCount(%rip), %rcx
	leaq	-48(%rbp), %rdi
	leaq	-72(%rbp), %rsi
	movl	$4, %edx
	callq	hipMallocPitch
	movq	(%r13), %rdi
	movq	(%r12), %rsi
	movq	setCount(%rip), %r9
	subq	$8, %rsp
	movl	$3, %ecx
	movl	$3, %r8d
	movq	%rbx, %rdx
	pushq	$1
	callq	hipMemcpy2D
	addq	$16, %rsp
	movq	setCount(%rip), %rax
	movabsq	$4294967300, %rdx               # imm = 0x100000004
	cmpq	$65535, %rax                    # imm = 0xFFFF
	ja	.LBB7_5
# %bb.4:
	leaq	(%rax,%rdx), %rdi
	addq	$-4, %rdi
	jmp	.LBB7_6
.LBB7_5:
	leaq	65531(%rdx), %rdi
.LBB7_6:
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	movq	-56(%rbp), %r12                 # 8-byte Reload
	jne	.LBB7_8
# %bb.7:
	movq	-48(%rbp), %rdi
	movq	-64(%rbp), %rsi
	movq	-72(%rbp), %rdx
	movq	-80(%rbp), %rcx
	movq	setCount(%rip), %r8
	callq	_Z26__device_stub__gUncompressPhS_mmm
.LBB7_8:
	movq	-48(%rbp), %rdx
	movq	-72(%rbp), %rcx
	movq	setCount(%rip), %r9
	subq	$8, %rsp
	movl	$4, %esi
	movl	$4, %r8d
	movq	%r12, %rdi
	pushq	$2
	callq	hipMemcpy2D
	addq	$16, %rsp
	movq	-64(%rbp), %rdi
	callq	hipFree
	movq	-48(%rbp), %rdi
	callq	hipFree
	movq	setCount(%rip), %rax
	testq	%rax, %rax
	je	.LBB7_41
# %bb.9:                                # %.lr.ph71
	addl	$208, %r15d
	movzbl	%r15b, %ebx
	movq	%r12, %r13
	xorl	%r15d, %r15d
.LBB7_10:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB7_13 Depth 2
	testq	%rbx, %rbx
	je	.LBB7_15
# %bb.11:                               #   in Loop: Header=BB7_10 Depth=1
	decq	%rax
	cmpq	%rax, %r15
	jne	.LBB7_15
# %bb.12:                               # %.preheader.preheader
                                        #   in Loop: Header=BB7_10 Depth=1
	xorl	%r12d, %r12d
.LBB7_13:                               # %.preheader
                                        #   Parent Loop BB7_10 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movb	(%r13,%r12), %al
	cmpb	$9, %al
	ja	.LBB7_36
# %bb.14:                               #   in Loop: Header=BB7_13 Depth=2
	orb	$48, %al
	jmp	.LBB7_39
.LBB7_36:                               #   in Loop: Header=BB7_13 Depth=2
	cmpb	$35, %al
	ja	.LBB7_38
# %bb.37:                               #   in Loop: Header=BB7_13 Depth=2
	addb	$87, %al
	jmp	.LBB7_39
.LBB7_38:                               #   in Loop: Header=BB7_13 Depth=2
	leal	29(%rax), %ecx
	cmpb	$62, %al
	movzbl	%cl, %eax
	movl	$10, %ecx
	cmovael	%ecx, %eax
.LBB7_39:                               # %_Z14getOriginalValh.exit57
                                        #   in Loop: Header=BB7_13 Depth=2
	movzbl	%al, %edi
	movq	%r14, %rsi
	callq	fputc@PLT
	incq	%r12
	cmpq	%r12, %rbx
	jne	.LBB7_13
	jmp	.LBB7_40
.LBB7_15:                               #   in Loop: Header=BB7_10 Depth=1
	movb	(%r12,%r15,4), %al
	cmpb	$9, %al
	ja	.LBB7_17
# %bb.16:                               #   in Loop: Header=BB7_10 Depth=1
	orb	$48, %al
	jmp	.LBB7_20
.LBB7_17:                               #   in Loop: Header=BB7_10 Depth=1
	cmpb	$35, %al
	ja	.LBB7_19
# %bb.18:                               #   in Loop: Header=BB7_10 Depth=1
	addb	$87, %al
	jmp	.LBB7_20
.LBB7_19:                               #   in Loop: Header=BB7_10 Depth=1
	leal	29(%rax), %ecx
	cmpb	$62, %al
	movzbl	%cl, %eax
	movl	$10, %ecx
	cmovael	%ecx, %eax
.LBB7_20:                               # %_Z14getOriginalValh.exit
                                        #   in Loop: Header=BB7_10 Depth=1
	movb	1(%r12,%r15,4), %cl
	cmpb	$9, %cl
	ja	.LBB7_22
# %bb.21:                               #   in Loop: Header=BB7_10 Depth=1
	orb	$48, %cl
	jmp	.LBB7_25
.LBB7_22:                               #   in Loop: Header=BB7_10 Depth=1
	cmpb	$35, %cl
	ja	.LBB7_24
# %bb.23:                               #   in Loop: Header=BB7_10 Depth=1
	addb	$87, %cl
	jmp	.LBB7_25
.LBB7_24:                               #   in Loop: Header=BB7_10 Depth=1
	leal	29(%rcx), %edx
	cmpb	$62, %cl
	movzbl	%dl, %ecx
	movl	$10, %edx
	cmovael	%edx, %ecx
.LBB7_25:                               # %_Z14getOriginalValh.exit48
                                        #   in Loop: Header=BB7_10 Depth=1
	movb	2(%r12,%r15,4), %sil
	cmpb	$9, %sil
	ja	.LBB7_27
# %bb.26:                               #   in Loop: Header=BB7_10 Depth=1
	orb	$48, %sil
	jmp	.LBB7_30
.LBB7_27:                               #   in Loop: Header=BB7_10 Depth=1
	cmpb	$35, %sil
	ja	.LBB7_29
# %bb.28:                               #   in Loop: Header=BB7_10 Depth=1
	addb	$87, %sil
	jmp	.LBB7_30
.LBB7_29:                               #   in Loop: Header=BB7_10 Depth=1
	leal	29(%rsi), %edx
	cmpb	$62, %sil
	movzbl	%dl, %esi
	movl	$10, %edx
	cmovael	%edx, %esi
.LBB7_30:                               # %_Z14getOriginalValh.exit51
                                        #   in Loop: Header=BB7_10 Depth=1
	movb	3(%r12,%r15,4), %dil
	cmpb	$9, %dil
	ja	.LBB7_32
# %bb.31:                               #   in Loop: Header=BB7_10 Depth=1
	orb	$48, %dil
	jmp	.LBB7_35
.LBB7_32:                               #   in Loop: Header=BB7_10 Depth=1
	cmpb	$35, %dil
	ja	.LBB7_34
# %bb.33:                               #   in Loop: Header=BB7_10 Depth=1
	addb	$87, %dil
	jmp	.LBB7_35
.LBB7_34:                               #   in Loop: Header=BB7_10 Depth=1
	leal	29(%rdi), %edx
	cmpb	$62, %dil
	movzbl	%dl, %edi
	movl	$10, %edx
	cmovael	%edx, %edi
.LBB7_35:                               # %_Z14getOriginalValh.exit54
                                        #   in Loop: Header=BB7_10 Depth=1
	movzbl	%al, %edx
	movzbl	%cl, %ecx
	movzbl	%sil, %r8d
	movzbl	%dil, %r9d
	movl	$.L.str.12, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
.LBB7_40:                               # %.loopexit
                                        #   in Loop: Header=BB7_10 Depth=1
	incq	%r15
	movq	setCount(%rip), %rax
	addq	$4, %r13
	cmpq	%rax, %r15
	movq	-56(%rbp), %r12                 # 8-byte Reload
	jb	.LBB7_10
.LBB7_41:                               # %._crit_edge72
	movq	%r14, %rdi
	callq	fclose
	movq	-88(%rbp), %rdi                 # 8-byte Reload
	callq	free
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.Lfunc_end7:
	.size	_Z10uncompressPPc, .Lfunc_end7-_Z10uncompressPPc
	.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	.LBB8_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB8_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9gCompressPhS_mmm, %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	$_Z11gUncompressPhS_mmm, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end8:
	.size	__hip_module_ctor, .Lfunc_end8-__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	.LBB9_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
.LBB9_2:
	retq
.Lfunc_end9:
	.size	__hip_module_dtor, .Lfunc_end9-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z9gCompressPhS_mmm,@object     # @_Z9gCompressPhS_mmm
	.section	.rodata,"a",@progbits
	.globl	_Z9gCompressPhS_mmm
	.p2align	3, 0x0
_Z9gCompressPhS_mmm:
	.quad	_Z24__device_stub__gCompressPhS_mmm
	.size	_Z9gCompressPhS_mmm, 8

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

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

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

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

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

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"-u"
	.size	.L.str.2, 3

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Usage:\n%s -c filename ....... to compress\n%s -u filename ....... to uncompress\n"
	.size	.L.str.3, 80

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"File %s does not exist.\n"
	.size	.L.str.4, 25

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"setrlimit returned result = %d\n"
	.size	.L.str.5, 32

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"%s.bcg"
	.size	.L.str.6, 7

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"r"
	.size	.L.str.7, 2

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

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"%c%c%c"
	.size	.L.str.9, 7

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"%i"
	.size	.L.str.10, 3

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"%s.out"
	.size	.L.str.11, 7

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"%c%c%c%c"
	.size	.L.str.12, 9

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z9gCompressPhS_mmm"
	.size	.L__unnamed_1, 20

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z11gUncompressPhS_mmm"
	.size	.L__unnamed_2, 23

	.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 _Z24__device_stub__gCompressPhS_mmm
	.addrsig_sym _Z26__device_stub__gUncompressPhS_mmm
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z9gCompressPhS_mmm
	.addrsig_sym _Z11gUncompressPhS_mmm
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9gCompressPhS_mmm     ; -- Begin function _Z9gCompressPhS_mmm
	.globl	_Z9gCompressPhS_mmm
	.p2align	8
	.type	_Z9gCompressPhS_mmm,@function
_Z9gCompressPhS_mmm:                    ; @_Z9gCompressPhS_mmm
; %bb.0:
	s_clause 0x1
	s_load_b256 s[4:11], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x20
	s_mov_b32 s2, s15
	v_dual_mov_b32 v4, 0 :: v_dual_lshlrev_b32 v1, 1, v0
	s_mov_b32 s3, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v5, 2, v1
	v_sub_nc_u32_e32 v6, 4, v1
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s12, s11, s15
	s_mul_hi_u32 s13, s10, s15
	s_mul_i32 s14, s10, s15
	s_mul_i32 s11, s11, 0xffff
	s_mul_hi_u32 s15, s10, 0xffff
	s_mul_i32 s16, s9, s2
	s_mul_hi_u32 s17, s8, s2
	s_add_i32 s13, s13, s12
	s_mul_i32 s18, s8, s2
	s_add_u32 s12, s6, s14
	s_addc_u32 s7, s7, s13
	s_add_i32 s6, s15, s11
	s_add_i32 s17, s17, s16
	s_add_u32 s4, s4, s18
	s_addc_u32 s5, s5, s17
	v_add_co_u32 v2, s4, s4, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v3, null, s5, 0, s4
	v_add_co_u32 v0, s4, s12, v0
	v_add_co_u32 v2, vcc_lo, v2, 1
	v_add_co_ci_u32_e64 v1, null, s7, 0, s4
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	s_mul_i32 s5, s9, 0xffff
	s_mul_hi_u32 s7, s8, 0xffff
	s_mul_i32 s4, s10, 0xffff
	s_add_i32 s5, s7, s5
	s_mul_i32 s7, s8, 0xffff
.LBB0_1:                                ; =>This Inner Loop Header: Depth=1
	global_store_b8 v[0:1], v4, off
	global_load_u8 v7, v[2:3], off offset:-1
	s_add_u32 s2, s2, 0xffff
	s_addc_u32 s3, s3, 0
	s_delay_alu instid0(SALU_CYCLE_1)
	v_cmp_lt_u64_e64 s8, s[2:3], s[0:1]
	s_waitcnt vmcnt(0)
	v_lshlrev_b32_e32 v7, v5, v7
	global_store_b8 v[0:1], v7, off
	global_load_u8 v8, v[2:3], off
	v_add_co_u32 v2, vcc_lo, v2, s7
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	s_waitcnt vmcnt(0)
	v_lshrrev_b32_e32 v8, v6, v8
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u16 v7, v8, v7
	global_store_b8 v[0:1], v7, off
	v_add_co_u32 v0, vcc_lo, v0, s4
	v_add_co_ci_u32_e32 v1, vcc_lo, s6, v1, vcc_lo
	s_and_b32 vcc_lo, exec_lo, s8
	s_cbranch_vccnz .LBB0_1
; %bb.2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9gCompressPhS_mmm
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 40
		.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 19
		.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	_Z9gCompressPhS_mmm, .Lfunc_end0-_Z9gCompressPhS_mmm
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 344
; NumSgprs: 21
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 21
; NumVGPRsForWavesPerEU: 9
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z11gUncompressPhS_mmm  ; -- Begin function _Z11gUncompressPhS_mmm
	.globl	_Z11gUncompressPhS_mmm
	.p2align	8
	.type	_Z11gUncompressPhS_mmm,@function
_Z11gUncompressPhS_mmm:                 ; @_Z11gUncompressPhS_mmm
; %bb.0:
	s_clause 0x1
	s_load_b256 s[4:11], s[0:1], 0x0
	s_load_b64 s[12:13], s[0:1], 0x20
	v_dual_mov_b32 v6, 0 :: v_dual_lshlrev_b32 v5, 1, v0
	v_cmp_ne_u32_e64 s0, 0, v0
	v_add_nc_u32_e32 v7, -1, v0
	v_cmp_ne_u32_e64 s1, 3, v0
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v8, 6, v5
	v_add_nc_u32_e32 v9, 2, v5
	s_mov_b32 s2, s15
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v1, s3, s4, v0
	v_add_co_ci_u32_e64 v2, null, s5, 0, s3
	s_mov_b32 s3, 0
.LBB1_1:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB1_3 Depth 2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[3:4], null, s2, s8, v[1:2]
	s_mul_i32 s4, s3, s8
	s_mul_i32 s5, s2, s9
	v_mov_b32_e32 v10, 0
	v_add3_u32 v4, s5, s4, v4
	global_store_b8 v[3:4], v6, off
	s_and_saveexec_b32 s4, s0
	s_cbranch_execz .LBB1_5
; %bb.2:                                ; %.lr.ph.preheader
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_mov_b32 s5, 0
	s_mov_b32 s14, 0
	s_mov_b32 s15, 0
.LBB1_3:                                ; %.lr.ph
                                        ;   Parent Loop BB1_1 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_lshr_b32 s16, 48, s14
	s_add_i32 s14, s14, 2
	s_add_i32 s15, s16, s15
	v_cmp_eq_u32_e32 vcc_lo, s14, v5
	v_mov_b32_e32 v10, s15
	s_or_b32 s5, vcc_lo, s5
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s5
	s_cbranch_execnz .LBB1_3
; %bb.4:                                ; %Flow40
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s5
.LBB1_5:                                ; %Flow41
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 exec_lo, exec_lo, s4
	s_mul_i32 s4, s2, s11
	s_mul_hi_u32 s5, s2, s10
	s_mul_i32 s14, s3, s10
	s_add_i32 s4, s5, s4
	v_mov_b32_e32 v11, 0
	s_add_i32 s5, s4, s14
	s_mul_i32 s4, s2, s10
	s_mov_b32 s15, -1
	s_add_u32 s4, s6, s4
	s_addc_u32 s5, s7, s5
	s_and_saveexec_b32 s14, s0
	s_cbranch_execz .LBB1_7
; %bb.6:                                ;   in Loop: Header=BB1_1 Depth=1
	v_add_co_u32 v11, s15, s4, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v12, null, s5, 0, s15
	s_or_not1_b32 s15, s1, exec_lo
	global_load_u8 v11, v[11:12], off
	s_waitcnt vmcnt(0)
	v_lshlrev_b32_e32 v11, v8, v11
	v_and_b32_e32 v11, v11, v10
	global_store_b8 v[3:4], v11, off
.LBB1_7:                                ; %Flow
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s14
	s_and_saveexec_b32 s14, s15
	s_cbranch_execz .LBB1_9
; %bb.8:                                ;   in Loop: Header=BB1_1 Depth=1
	v_add_co_u32 v12, s4, s4, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v13, null, s5, 0, s4
	global_load_u8 v10, v[12:13], off
	s_waitcnt vmcnt(0)
	v_lshrrev_b32_e32 v10, v9, v10
	v_add_nc_u16 v10, v11, v10
	global_store_b8 v[3:4], v10, off
.LBB1_9:                                ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s14
	s_add_u32 s2, s2, 0xffff
	s_addc_u32 s3, s3, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_u64_e64 s4, s[2:3], s[12:13]
	s_and_b32 vcc_lo, exec_lo, s4
	s_cbranch_vccnz .LBB1_1
; %bb.10:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11gUncompressPhS_mmm
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 40
		.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 14
		.amdhsa_next_free_sgpr 17
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z11gUncompressPhS_mmm, .Lfunc_end1-_Z11gUncompressPhS_mmm
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 408
; NumSgprs: 19
; NumVgprs: 14
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 19
; NumVGPRsForWavesPerEU: 14
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           8
        .value_kind:     by_value
      - .offset:         24
        .size:           8
        .value_kind:     by_value
      - .offset:         32
        .size:           8
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 40
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9gCompressPhS_mmm
    .private_segment_fixed_size: 0
    .sgpr_count:     21
    .sgpr_spill_count: 0
    .symbol:         _Z9gCompressPhS_mmm.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
      - .offset:         16
        .size:           8
        .value_kind:     by_value
      - .offset:         24
        .size:           8
        .value_kind:     by_value
      - .offset:         32
        .size:           8
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 40
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z11gUncompressPhS_mmm
    .private_segment_fixed_size: 0
    .sgpr_count:     19
    .sgpr_spill_count: 0
    .symbol:         _Z11gUncompressPhS_mmm.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     14
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
