#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <sys/time.h>
#include <cuda.h>
#include <cuda_runtime.h>

#define SYMBOL_NUM 256
#define MAX_CODE_LEN (SYMBOL_NUM - 1)

#define GRID_X (1u << 12)
#define GRID_Y 1
#define BLOCK_X (1u << 10)
#define BLOCK_Y 1

#define RAW_BUFF_SIZE (GRID_X * GRID_Y * BLOCK_X * BLOCK_Y)

#define DEF_IDX \
    size_t idx = blockDim.x * blockIdx.x + threadIdx.x;

#define CUDA_SAFE_CALL(func)                                               \
    do {                                                                   \
        cudaError_t err = (func);                                          \
        if (err != cudaSuccess) {                                          \
            fprintf(stderr, "[Error] %s (error code: %d) at %s line %d\n", \
                cudaGetErrorString(err), err, __FILE__, __LINE__);         \
            exit(err);                                                     \
        }                                                                  \
    } while (0)

void prefixSumHost(
    char* raw_data, size_t* code_len, size_t* len_ps, size_t raw_len);
__global__ void prefixSum(
    char* raw_data, size_t* code_len, size_t* len_ps, size_t raw_len);
__global__ void genByteStream(
    char* raw_data, bool* code, size_t* code_len, size_t* len_ps, bool* bytes,
    size_t raw_len);
__global__ void compressByteStream(bool* bytes, uint8_t* bits, size_t bits_len);

int main(int argc, char** argv)
{
    if (argc != 3) {
        fprintf(stderr, "Usage: %s raw_data huffman_table\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    // Read raw data
    char* raw_data_h = (char*)calloc(RAW_BUFF_SIZE, 1);
    size_t raw_len = 0;

    {
        printf("Reading raw data ... ");
        FILE* raw_file = fopen(argv[1], "r");
        size_t r;
        while ((r = fread(
                    raw_data_h + raw_len, 1, RAW_BUFF_SIZE - raw_len, raw_file))
               != 0) {
            raw_len += r;
        }
        fclose(raw_file);
        printf("done. Read %zu bytes.\n", raw_len);
    }

    char* raw_data;
    CUDA_SAFE_CALL(cudaMalloc((void**)&raw_data, raw_len));
    CUDA_SAFE_CALL(cudaMemcpy(
        raw_data, raw_data_h, raw_len, cudaMemcpyHostToDevice));

    // Read Huffman table
    bool* code_h = (bool*)calloc(MAX_CODE_LEN * SYMBOL_NUM, sizeof(bool));
    size_t* code_len_h = (size_t*)calloc(SYMBOL_NUM, sizeof(size_t));

    {
        printf("Reading Huffman table ... ");
        FILE* hufftable_file = fopen(argv[2], "r");
        int c;
        while (fscanf(hufftable_file, "%d", &c) != EOF) {
            size_t len;
            int _ = fscanf(hufftable_file, "%zu", &len);
            code_len_h[c] = len;
            for (size_t j = 0; j < len; j++) {
                int b;
                int _ = fscanf(hufftable_file, "%d", &b);
                code_h[c * MAX_CODE_LEN + j] = b;
            }
        }

        fclose(hufftable_file);
        printf("done.\n");
    }

    bool* code;
    CUDA_SAFE_CALL(cudaMalloc(
        (void**)&code, MAX_CODE_LEN * SYMBOL_NUM * sizeof(bool)));
    CUDA_SAFE_CALL(cudaMemcpy(
        code, code_h, MAX_CODE_LEN * SYMBOL_NUM * sizeof(bool),
        cudaMemcpyHostToDevice));
    size_t* code_len;
    CUDA_SAFE_CALL(cudaMalloc((void**)&code_len, SYMBOL_NUM * sizeof(size_t)));
    CUDA_SAFE_CALL(cudaMemcpy(
        code_len, code_len_h, SYMBOL_NUM * sizeof(size_t),
        cudaMemcpyHostToDevice));

    // free(code_h);

    // Run on CUDA
    dim3 grid(GRID_X, GRID_Y);
    dim3 block(BLOCK_X, BLOCK_Y, 1);

    struct timeval time_start, time_end;
    gettimeofday(&time_start, NULL);

    // Prefix sum of code length
    size_t* len_ps_h = (size_t*)calloc(raw_len, sizeof(size_t));

    prefixSumHost(raw_data_h, code_len_h, len_ps_h, raw_len);
    // prefixSum<<<grid, block>>>(raw_data, code_len, len_ps, raw_len);
    CUDA_SAFE_CALL(cudaThreadSynchronize());

    size_t* len_ps;
    CUDA_SAFE_CALL(cudaMalloc((void**)&len_ps, raw_len * sizeof(size_t)));
    CUDA_SAFE_CALL(cudaMemcpy(
        len_ps, len_ps_h, raw_len * sizeof(size_t), cudaMemcpyHostToDevice));

    /* {
        size_t* len_ps_h = (size_t*)malloc(sizeof(size_t) * raw_len);
        CUDA_SAFE_CALL(cudaMemcpy(
            len_ps_h, len_ps, sizeof(size_t) * raw_len, cudaMemcpyDeviceToHost));
        for (size_t i = 0; i < raw_len; i++)
            printf("%zu\n", len_ps_h[i]);
    } */

    size_t len_ps_end;
    CUDA_SAFE_CALL(cudaMemcpy(
        &len_ps_end, &len_ps[raw_len - 1], sizeof(size_t),
        cudaMemcpyDeviceToHost));
    size_t bytes_len = len_ps_end + code_len_h[raw_data_h[raw_len - 1]];
    printf("bytes len: %zu\n", bytes_len);

    // free(code_len_h);
    // free(raw_data_h);

    if (bytes_len > RAW_BUFF_SIZE) {
        fprintf(stderr, "Bytes stream overflowed\n");
        exit(EXIT_FAILURE);
    }

    bool* bytes;
    CUDA_SAFE_CALL(cudaMalloc((void**)&bytes, sizeof(bool) * bytes_len));
    genByteStream<<<grid, block>>>(
        raw_data, code, code_len, len_ps, bytes, raw_len);
    CUDA_SAFE_CALL(cudaThreadSynchronize());

    // CUDA_SAFE_CALL(cudaFree(len_ps));
    // CUDA_SAFE_CALL(cudaFree(code_len));
    // CUDA_SAFE_CALL(cudaFree(code));
    // CUDA_SAFE_CALL(cudaFree(raw_data));

    uint8_t* bits;
    size_t bits_len = bytes_len / 8 + 1;
    printf("bits len: %zu\n", bits_len);
    CUDA_SAFE_CALL(cudaMalloc((void**)&bits, bits_len));
    compressByteStream<<<grid, block>>>(bytes, bits, bits_len);
    CUDA_SAFE_CALL(cudaThreadSynchronize());

    // CUDA_SAFE_CALL(cudaFree(bits));
    // CUDA_SAFE_CALL(cudaFree(bytes));

    gettimeofday(&time_end, NULL);
    double sec = (double)(time_end.tv_sec - time_start.tv_sec)
                 + (double)(time_end.tv_usec - time_start.tv_usec) / 1e6;
    printf("bytes: %zu sec: %lf bytes/sec: %lf\n",
        raw_len, sec, raw_len / sec);

    return 0;
}

void prefixSumHost(
    char* raw_data, size_t* code_len, size_t* len_ps, size_t raw_len)
{
    len_ps[0] = 0;
    for (size_t i = 1; i < raw_len; i++) {
        len_ps[i] = len_ps[i - 1] + code_len[raw_data[i - 1]];
    }
}

__global__ void prefixSum(
    char* raw_data, size_t* code_len, size_t* len_ps, size_t raw_len)
{
    DEF_IDX;

    if (2 * idx + 1 < raw_len) {
        len_ps[2 * idx] = code_len[raw_data[2 * idx]];
        len_ps[2 * idx + 1] = code_len[raw_data[2 * idx + 1]];
    }

    __syncthreads();

    // build sum in place up the tree
    size_t offset = 1;
    for (size_t d = raw_len >> 1; d > 0; d >>= 1) {
        __syncthreads();
        if (idx < d) {
            size_t ai = offset * (2 * idx + 1) - 1;
            size_t bi = offset * (2 * idx + 2) - 1;
            len_ps[bi] += len_ps[ai];
        }
        offset *= 2;
    }

    // clear the last element
    if (idx == 0)
        len_ps[raw_len - 1] = 0;

    // traverse down tree & build scan
    for (size_t d = 1; d < raw_len; d *= 2) {
        offset >>= 1;
        __syncthreads();
        if (idx < d) {
            size_t ai = offset * (2 * idx + 1) - 1;
            size_t bi = offset * (2 * idx + 2) - 1;
            size_t t = len_ps[ai];
            len_ps[ai] = len_ps[bi];
            len_ps[bi] += t;
        }
    }
}

__global__ void genByteStream(
    char* raw_data, bool* code, size_t* code_len, size_t* len_ps, bool* bytes,
    size_t raw_len)
{
    DEF_IDX;

    if (idx < raw_len) {
        size_t start_pos = len_ps[idx];
        char symbol = raw_data[idx];
        for (size_t i = 0, len = code_len[symbol]; i < len; i++) {
            bytes[start_pos + i] = code[symbol * MAX_CODE_LEN + i];
        }
    }
}

__global__ void compressByteStream(bool* bytes, uint8_t* bits, size_t bits_len)
{
    DEF_IDX;

    if (idx < bits_len) {
        for (size_t i = 0; i < 8; i++) {
            bits[idx] |= (uint8_t)bytes[8 * idx + i] << (7 - i);
        }
    }
}

	.file	"tmpxft_0021676d_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z13prefixSumHostPcPmS0_m
	.type	_Z13prefixSumHostPcPmS0_m, @function
_Z13prefixSumHostPcPmS0_m:
.LFB2028:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	movq	%rax, (%rdx)
	movl	$1, %eax
.L3:
	cmpq	%rcx, %rax
	jnb	.L6
	movsbq	-1(%rdi,%rax), %r9
	movq	-8(%rdx,%rax,8), %r8
	addq	(%rsi,%r9,8), %r8
	movq	%r8, (%rdx,%rax,8)
	incq	%rax
	jmp	.L3
.L6:
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z13prefixSumHostPcPmS0_m, .-_Z13prefixSumHostPcPmS0_m
	.globl	_Z34__device_stub__Z9prefixSumPcPmS0_mPcPmS0_m
	.type	_Z34__device_stub__Z9prefixSumPcPmS0_mPcPmS0_m, @function
_Z34__device_stub__Z9prefixSumPcPmS0_mPcPmS0_m:
.LFB2053:
	.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
	movq	%rcx, (%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L7
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z9prefixSumPcPmS0_m(%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
.L7:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z34__device_stub__Z9prefixSumPcPmS0_mPcPmS0_m, .-_Z34__device_stub__Z9prefixSumPcPmS0_mPcPmS0_m
	.globl	_Z9prefixSumPcPmS0_m
	.type	_Z9prefixSumPcPmS0_m, @function
_Z9prefixSumPcPmS0_m:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z34__device_stub__Z9prefixSumPcPmS0_mPcPmS0_m
	.cfi_endproc
.LFE2054:
	.size	_Z9prefixSumPcPmS0_m, .-_Z9prefixSumPcPmS0_m
	.globl	_Z44__device_stub__Z13genByteStreamPcPbPmS1_S0_mPcPbPmS1_S0_m
	.type	_Z44__device_stub__Z13genByteStreamPcPbPmS1_S0_mPcPbPmS1_S0_m, @function
_Z44__device_stub__Z13genByteStreamPcPbPmS1_S0_mPcPbPmS1_S0_m:
.LFB2055:
	.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
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	64(%rsp), %rcx
	movq	%r8, 8(%rsp)
	movq	%r9, (%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	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 152(%rsp)
	movq	%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	.L12
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z13genByteStreamPcPbPmS1_S0_m(%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
.L12:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z44__device_stub__Z13genByteStreamPcPbPmS1_S0_mPcPbPmS1_S0_m, .-_Z44__device_stub__Z13genByteStreamPcPbPmS1_S0_mPcPbPmS1_S0_m
	.globl	_Z13genByteStreamPcPbPmS1_S0_m
	.type	_Z13genByteStreamPcPbPmS1_S0_m, @function
_Z13genByteStreamPcPbPmS1_S0_m:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z44__device_stub__Z13genByteStreamPcPbPmS1_S0_mPcPbPmS1_S0_m
	.cfi_endproc
.LFE2056:
	.size	_Z13genByteStreamPcPbPmS1_S0_m, .-_Z13genByteStreamPcPbPmS1_S0_m
	.globl	_Z41__device_stub__Z18compressByteStreamPbPhmPbPhm
	.type	_Z41__device_stub__Z18compressByteStreamPbPhmPbPhm, @function
_Z41__device_stub__Z18compressByteStreamPbPhmPbPhm:
.LFB2057:
	.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
	movq	%rdx, 8(%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	8(%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	.L17
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z18compressByteStreamPbPhm(%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
.L17:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z41__device_stub__Z18compressByteStreamPbPhmPbPhm, .-_Z41__device_stub__Z18compressByteStreamPbPhmPbPhm
	.globl	_Z18compressByteStreamPbPhm
	.type	_Z18compressByteStreamPbPhm, @function
_Z18compressByteStreamPbPhm:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z41__device_stub__Z18compressByteStreamPbPhmPbPhm
	.cfi_endproc
.LFE2058:
	.size	_Z18compressByteStreamPbPhm, .-_Z18compressByteStreamPbPhm
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Usage: %s raw_data huffman_table\n"
.LC1:
	.string	"Reading raw data ... "
.LC2:
	.string	"r"
.LC3:
	.string	"done. Read %zu bytes.\n"
.LC4:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/ordovicia/huffman-coding-cuda/master/main.cu"
.LC5:
	.string	"[Error] %s (error code: %d) at %s line %d\n"
.LC6:
	.string	"Reading Huffman table ... "
.LC7:
	.string	"%zu"
.LC8:
	.string	"%d"
.LC9:
	.string	"done.\n"
.LC10:
	.string	"bytes len: %zu\n"
.LC11:
	.string	"Bytes stream overflowed\n"
.LC12:
	.string	"bits len: %zu\n"
.LC14:
	.string	"bytes: %zu sec: %lf bytes/sec: %lf\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	cmpl	$3, %edi
	je	.L23
	movq	(%rsi), %rcx
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L51
.L23:
	movl	$1, %esi
	movl	$4194304, %edi
	leaq	.LC2(%rip), %r15
	xorl	%ebx, %ebx
	call	calloc@PLT
	movl	$2, %edi
	movl	$4194304, %ebp
	leaq	.LC1(%rip), %rsi
	movq	%rax, %r12
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	8(%r14), %rdi
	movq	%r15, %rsi
	call	fopen@PLT
	movq	%rax, %r13
.L24:
	movl	$4194304, %esi
	movq	%rbp, %rcx
	leaq	(%r12,%rbx), %rdi
	movq	%r13, %r8
	subq	%rbx, %rcx
	cmpq	%rsi, %rbx
	movl	$1, %edx
	cmovnb	%rbx, %rsi
	subq	%rbx, %rsi
	call	__fread_chk@PLT
	testq	%rax, %rax
	je	.L56
	addq	%rax, %rbx
	jmp	.L24
.L56:
	movq	%r13, %rdi
	call	fclose@PLT
	movq	%rbx, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC3(%rip), %rsi
	call	__printf_chk@PLT
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.L26
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	pushq	%r15
	.cfi_remember_state
	.cfi_def_cfa_offset 216
	movq	%rax, %rcx
	pushq	$65
	.cfi_def_cfa_offset 224
	jmp	.L52
.L26:
	.cfi_restore_state
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%r12, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.L27
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	pushq	%r14
	.cfi_def_cfa_offset 216
	pushq	$66
	.cfi_def_cfa_offset 224
	movq	%rax, %rcx
.L52:
	movq	stderr(%rip), %rdi
	leaq	.LC4(%rip), %r9
	movl	%ebp, %r8d
	xorl	%eax, %eax
	leaq	.LC5(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	%ebp, %edi
.L53:
	call	exit@PLT
.L27:
	.cfi_def_cfa_offset 208
	movl	$1, %esi
	movl	$65280, %edi
	call	calloc@PLT
	movl	$8, %esi
	movl	$256, %edi
	movq	%rax, %r13
	call	calloc@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rbp
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	16(%r14), %rdi
	movq	%r15, %rsi
	call	fopen@PLT
	movq	%rax, (%rsp)
.L28:
	movq	(%rsp), %rdi
	xorl	%eax, %eax
	leaq	92(%rsp), %rdx
	leaq	.LC8(%rip), %rsi
	call	__isoc23_fscanf@PLT
	incl	%eax
	leaq	120(%rsp), %rax
	movq	%rax, 8(%rsp)
	je	.L57
	movq	8(%rsp), %rdx
	movq	(%rsp), %rdi
	xorl	%eax, %eax
	xorl	%r14d, %r14d
	leaq	.LC7(%rip), %rsi
	leaq	104(%rsp), %r15
	call	__isoc23_fscanf@PLT
	movslq	92(%rsp), %rax
	movq	120(%rsp), %rdx
	movq	%rdx, 0(%rbp,%rax,8)
.L29:
	cmpq	120(%rsp), %r14
	jnb	.L28
	movq	(%rsp), %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	leaq	.LC8(%rip), %rsi
	call	__isoc23_fscanf@PLT
	imull	$255, 92(%rsp), %eax
	leaq	0(%r13,%r14), %rdx
	cmpl	$0, 104(%rsp)
	cltq
	setne	(%rdx,%rax)
	incq	%r14
	jmp	.L29
.L57:
	movq	(%rsp), %rdi
	call	fclose@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	32(%rsp), %rdi
	movl	$65280, %esi
	call	cudaMalloc@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	je	.L32
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	pushq	%r13
	.cfi_remember_state
	.cfi_def_cfa_offset 216
	movl	%r14d, %r8d
	movl	$2, %esi
	pushq	$93
	.cfi_def_cfa_offset 224
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	xorl	%eax, %eax
	leaq	.LC4(%rip), %r9
	leaq	.LC5(%rip), %rdx
	call	__fprintf_chk@PLT
	movl	%r14d, %edi
	jmp	.L53
.L32:
	.cfi_restore_state
	movq	32(%rsp), %rdi
	movq	%r13, %rsi
	movl	$1, %ecx
	movl	$65280, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %r13d
	testl	%eax, %eax
	je	.L33
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	pushq	%r12
	.cfi_remember_state
	.cfi_def_cfa_offset 216
	movq	%rax, %rcx
	pushq	$95
	.cfi_def_cfa_offset 224
	jmp	.L55
.L33:
	.cfi_restore_state
	leaq	40(%rsp), %rdi
	movl	$2048, %esi
	call	cudaMalloc@PLT
	movl	%eax, %r13d
	testl	%eax, %eax
	je	.L34
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	pushq	%rbp
	.cfi_remember_state
	.cfi_def_cfa_offset 216
	movq	%rax, %rcx
	pushq	$99
	.cfi_def_cfa_offset 224
	jmp	.L55
.L34:
	.cfi_restore_state
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movl	$2048, %edx
	movq	%rbp, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %r13d
	testl	%eax, %eax
	je	.L35
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	pushq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 216
	movq	%rax, %rcx
	pushq	$100
	.cfi_def_cfa_offset 224
	jmp	.L55
.L35:
	.cfi_restore_state
	movl	$1048577, %eax
	leaq	104(%rsp), %rdi
	xorl	%esi, %esi
	movl	$1, 88(%rsp)
	salq	$12, %rax
	movl	$1, 100(%rsp)
	movq	%rax, 80(%rsp)
	subq	$3072, %rax
	movq	%rax, 92(%rsp)
	call	gettimeofday@PLT
	movl	$8, %esi
	movq	%rbx, %rdi
	call	calloc@PLT
	movq	%rbx, %rcx
	movq	%rbp, %rsi
	movq	%r12, %rdi
	movq	%rax, %rdx
	movq	%rax, %r14
	call	_Z13prefixSumHostPcPmS0_m
	call	cudaThreadSynchronize@PLT
	movl	%eax, %r13d
	testl	%eax, %eax
	je	.L36
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %rcx
	pushq	%r11
	.cfi_remember_state
	.cfi_def_cfa_offset 216
	pushq	$118
	.cfi_def_cfa_offset 224
	jmp	.L55
.L36:
	.cfi_restore_state
	leaq	0(,%rbx,8), %r15
	leaq	48(%rsp), %rdi
	movq	%r15, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %r13d
	testl	%eax, %eax
	je	.L37
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %rcx
	pushq	%r10
	.cfi_remember_state
	.cfi_def_cfa_offset 216
	pushq	$121
	.cfi_def_cfa_offset 224
	jmp	.L55
.L37:
	.cfi_restore_state
	movq	48(%rsp), %rdi
	movl	$1, %ecx
	movq	%r15, %rdx
	movq	%r14, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %r13d
	testl	%eax, %eax
	je	.L38
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %rcx
	pushq	%r9
	.cfi_remember_state
	.cfi_def_cfa_offset 216
	pushq	$122
	.cfi_def_cfa_offset 224
	jmp	.L55
.L38:
	.cfi_restore_state
	movq	48(%rsp), %rax
	leaq	56(%rsp), %rdi
	movl	$2, %ecx
	movl	$8, %edx
	leaq	-8(%rax,%r15), %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %r13d
	testl	%eax, %eax
	je	.L39
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	pushq	%r8
	.cfi_def_cfa_offset 216
	movq	%rax, %rcx
	pushq	$134
	.cfi_def_cfa_offset 224
.L55:
	movq	stderr(%rip), %rdi
	leaq	.LC4(%rip), %r9
	movl	%r13d, %r8d
	xorl	%eax, %eax
	leaq	.LC5(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	%r13d, %edi
	jmp	.L53
.L39:
	.cfi_def_cfa_offset 208
	movsbq	-1(%r12,%rbx), %rdx
	movq	56(%rsp), %rax
	movl	$2, %edi
	leaq	.LC10(%rip), %rsi
	addq	0(%rbp,%rdx,8), %rax
	movq	%rax, %rbp
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	cmpq	$4194304, %rbp
	jbe	.L40
	movq	stderr(%rip), %rdi
	leaq	.LC11(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L51:
	movl	$1, %edi
	call	exit@PLT
.L40:
	leaq	64(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %r12d
	testl	%eax, %eax
	je	.L41
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %rcx
	pushq	%rdi
	.cfi_remember_state
	.cfi_def_cfa_offset 216
	pushq	$149
	.cfi_def_cfa_offset 224
	jmp	.L54
.L41:
	.cfi_restore_state
	movl	100(%rsp), %ecx
	movq	92(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	80(%rsp), %rdi
	movl	88(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L42
	movq	64(%rsp), %r8
	movq	48(%rsp), %rcx
	movq	%rbx, %r9
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z44__device_stub__Z13genByteStreamPcPbPmS1_S0_mPcPbPmS1_S0_m
.L42:
	call	cudaThreadSynchronize@PLT
	movl	%eax, %r12d
	testl	%eax, %eax
	je	.L43
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %rcx
	pushq	%rsi
	.cfi_remember_state
	.cfi_def_cfa_offset 216
	pushq	$152
	.cfi_def_cfa_offset 224
	jmp	.L54
.L43:
	.cfi_restore_state
	shrq	$3, %rbp
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%rbp
	movq	%rbp, %rdx
	call	__printf_chk@PLT
	leaq	72(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %r12d
	testl	%eax, %eax
	je	.L44
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	pushq	%rdx
	.cfi_def_cfa_offset 216
	movq	%rax, %rcx
	pushq	$162
	.cfi_def_cfa_offset 224
.L54:
	movq	stderr(%rip), %rdi
	leaq	.LC4(%rip), %r9
	movl	%r12d, %r8d
	xorl	%eax, %eax
	leaq	.LC5(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	%r12d, %edi
	jmp	.L53
.L44:
	.cfi_def_cfa_offset 208
	movl	100(%rsp), %ecx
	movq	92(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	80(%rsp), %rdi
	movl	88(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L45
	movq	72(%rsp), %rsi
	movq	64(%rsp), %rdi
	movq	%rbp, %rdx
	call	_Z41__device_stub__Z18compressByteStreamPbPhmPbPhm
.L45:
	call	cudaThreadSynchronize@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.L46
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %rcx
	pushq	%rax
	.cfi_remember_state
	.cfi_def_cfa_offset 216
	pushq	$164
	.cfi_def_cfa_offset 224
	jmp	.L52
.L46:
	.cfi_restore_state
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	movq	128(%rsp), %rax
	subq	112(%rsp), %rax
	cvtsi2sdq	%rax, %xmm0
	movq	120(%rsp), %rax
	subq	104(%rsp), %rax
	divsd	.LC13(%rip), %xmm0
	cvtsi2sdq	%rax, %xmm1
	addsd	%xmm1, %xmm0
	testq	%rbx, %rbx
	js	.L47
	cvtsi2sdq	%rbx, %xmm1
	jmp	.L48
.L47:
	movq	%rbx, %rax
	movq	%rbx, %rdx
	shrq	%rax
	andl	$1, %edx
	orq	%rdx, %rax
	cvtsi2sdq	%rax, %xmm1
	addsd	%xmm1, %xmm1
.L48:
	divsd	%xmm0, %xmm1
	movq	%rbx, %rdx
	leaq	.LC14(%rip), %rsi
	movb	$2, %al
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L49
	call	__stack_chk_fail@PLT
.L49:
	addq	$152, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC15:
	.string	"_Z18compressByteStreamPbPhm"
.LC16:
	.string	"_Z13genByteStreamPcPbPmS1_S0_m"
.LC17:
	.string	"_Z9prefixSumPcPmS0_m"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.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	.LC15(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z18compressByteStreamPbPhm(%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	.LC16(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z13genByteStreamPcPbPmS1_S0_m(%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	.LC17(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z9prefixSumPcPmS0_m(%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
.LFE2060:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC13:
	.long	0
	.long	1093567616
	.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 <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <sys/time.h>
#include <hip/hip_runtime.h>


#define SYMBOL_NUM 256
#define MAX_CODE_LEN (SYMBOL_NUM - 1)

#define GRID_X (1u << 12)
#define GRID_Y 1
#define BLOCK_X (1u << 10)
#define BLOCK_Y 1

#define RAW_BUFF_SIZE (GRID_X * GRID_Y * BLOCK_X * BLOCK_Y)

#define DEF_IDX \
    size_t idx = blockDim.x * blockIdx.x + threadIdx.x;

#define CUDA_SAFE_CALL(func)                                               \
    do {                                                                   \
        hipError_t err = (func);                                          \
        if (err != hipSuccess) {                                          \
            fprintf(stderr, "[Error] %s (error code: %d) at %s line %d\n", \
                hipGetErrorString(err), err, __FILE__, __LINE__);         \
            exit(err);                                                     \
        }                                                                  \
    } while (0)

void prefixSumHost(
    char* raw_data, size_t* code_len, size_t* len_ps, size_t raw_len);
__global__ void prefixSum(
    char* raw_data, size_t* code_len, size_t* len_ps, size_t raw_len);
__global__ void genByteStream(
    char* raw_data, bool* code, size_t* code_len, size_t* len_ps, bool* bytes,
    size_t raw_len);
__global__ void compressByteStream(bool* bytes, uint8_t* bits, size_t bits_len);

int main(int argc, char** argv)
{
    if (argc != 3) {
        fprintf(stderr, "Usage: %s raw_data huffman_table\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    // Read raw data
    char* raw_data_h = (char*)calloc(RAW_BUFF_SIZE, 1);
    size_t raw_len = 0;

    {
        printf("Reading raw data ... ");
        FILE* raw_file = fopen(argv[1], "r");
        size_t r;
        while ((r = fread(
                    raw_data_h + raw_len, 1, RAW_BUFF_SIZE - raw_len, raw_file))
               != 0) {
            raw_len += r;
        }
        fclose(raw_file);
        printf("done. Read %zu bytes.\n", raw_len);
    }

    char* raw_data;
    CUDA_SAFE_CALL(hipMalloc((void**)&raw_data, raw_len));
    CUDA_SAFE_CALL(hipMemcpy(
        raw_data, raw_data_h, raw_len, hipMemcpyHostToDevice));

    // Read Huffman table
    bool* code_h = (bool*)calloc(MAX_CODE_LEN * SYMBOL_NUM, sizeof(bool));
    size_t* code_len_h = (size_t*)calloc(SYMBOL_NUM, sizeof(size_t));

    {
        printf("Reading Huffman table ... ");
        FILE* hufftable_file = fopen(argv[2], "r");
        int c;
        while (fscanf(hufftable_file, "%d", &c) != EOF) {
            size_t len;
            int _ = fscanf(hufftable_file, "%zu", &len);
            code_len_h[c] = len;
            for (size_t j = 0; j < len; j++) {
                int b;
                int _ = fscanf(hufftable_file, "%d", &b);
                code_h[c * MAX_CODE_LEN + j] = b;
            }
        }

        fclose(hufftable_file);
        printf("done.\n");
    }

    bool* code;
    CUDA_SAFE_CALL(hipMalloc(
        (void**)&code, MAX_CODE_LEN * SYMBOL_NUM * sizeof(bool)));
    CUDA_SAFE_CALL(hipMemcpy(
        code, code_h, MAX_CODE_LEN * SYMBOL_NUM * sizeof(bool),
        hipMemcpyHostToDevice));
    size_t* code_len;
    CUDA_SAFE_CALL(hipMalloc((void**)&code_len, SYMBOL_NUM * sizeof(size_t)));
    CUDA_SAFE_CALL(hipMemcpy(
        code_len, code_len_h, SYMBOL_NUM * sizeof(size_t),
        hipMemcpyHostToDevice));

    // free(code_h);

    // Run on CUDA
    dim3 grid(GRID_X, GRID_Y);
    dim3 block(BLOCK_X, BLOCK_Y, 1);

    struct timeval time_start, time_end;
    gettimeofday(&time_start, NULL);

    // Prefix sum of code length
    size_t* len_ps_h = (size_t*)calloc(raw_len, sizeof(size_t));

    prefixSumHost(raw_data_h, code_len_h, len_ps_h, raw_len);
    // prefixSum<<<grid, block>>>(raw_data, code_len, len_ps, raw_len);
    CUDA_SAFE_CALL(hipDeviceSynchronize());

    size_t* len_ps;
    CUDA_SAFE_CALL(hipMalloc((void**)&len_ps, raw_len * sizeof(size_t)));
    CUDA_SAFE_CALL(hipMemcpy(
        len_ps, len_ps_h, raw_len * sizeof(size_t), hipMemcpyHostToDevice));

    /* {
        size_t* len_ps_h = (size_t*)malloc(sizeof(size_t) * raw_len);
        CUDA_SAFE_CALL(cudaMemcpy(
            len_ps_h, len_ps, sizeof(size_t) * raw_len, cudaMemcpyDeviceToHost));
        for (size_t i = 0; i < raw_len; i++)
            printf("%zu\n", len_ps_h[i]);
    } */

    size_t len_ps_end;
    CUDA_SAFE_CALL(hipMemcpy(
        &len_ps_end, &len_ps[raw_len - 1], sizeof(size_t),
        hipMemcpyDeviceToHost));
    size_t bytes_len = len_ps_end + code_len_h[raw_data_h[raw_len - 1]];
    printf("bytes len: %zu\n", bytes_len);

    // free(code_len_h);
    // free(raw_data_h);

    if (bytes_len > RAW_BUFF_SIZE) {
        fprintf(stderr, "Bytes stream overflowed\n");
        exit(EXIT_FAILURE);
    }

    bool* bytes;
    CUDA_SAFE_CALL(hipMalloc((void**)&bytes, sizeof(bool) * bytes_len));
    genByteStream<<<grid, block>>>(
        raw_data, code, code_len, len_ps, bytes, raw_len);
    CUDA_SAFE_CALL(hipDeviceSynchronize());

    // CUDA_SAFE_CALL(cudaFree(len_ps));
    // CUDA_SAFE_CALL(cudaFree(code_len));
    // CUDA_SAFE_CALL(cudaFree(code));
    // CUDA_SAFE_CALL(cudaFree(raw_data));

    uint8_t* bits;
    size_t bits_len = bytes_len / 8 + 1;
    printf("bits len: %zu\n", bits_len);
    CUDA_SAFE_CALL(hipMalloc((void**)&bits, bits_len));
    compressByteStream<<<grid, block>>>(bytes, bits, bits_len);
    CUDA_SAFE_CALL(hipDeviceSynchronize());

    // CUDA_SAFE_CALL(cudaFree(bits));
    // CUDA_SAFE_CALL(cudaFree(bytes));

    gettimeofday(&time_end, NULL);
    double sec = (double)(time_end.tv_sec - time_start.tv_sec)
                 + (double)(time_end.tv_usec - time_start.tv_usec) / 1e6;
    printf("bytes: %zu sec: %lf bytes/sec: %lf\n",
        raw_len, sec, raw_len / sec);

    return 0;
}

void prefixSumHost(
    char* raw_data, size_t* code_len, size_t* len_ps, size_t raw_len)
{
    len_ps[0] = 0;
    for (size_t i = 1; i < raw_len; i++) {
        len_ps[i] = len_ps[i - 1] + code_len[raw_data[i - 1]];
    }
}

__global__ void prefixSum(
    char* raw_data, size_t* code_len, size_t* len_ps, size_t raw_len)
{
    DEF_IDX;

    if (2 * idx + 1 < raw_len) {
        len_ps[2 * idx] = code_len[raw_data[2 * idx]];
        len_ps[2 * idx + 1] = code_len[raw_data[2 * idx + 1]];
    }

    __syncthreads();

    // build sum in place up the tree
    size_t offset = 1;
    for (size_t d = raw_len >> 1; d > 0; d >>= 1) {
        __syncthreads();
        if (idx < d) {
            size_t ai = offset * (2 * idx + 1) - 1;
            size_t bi = offset * (2 * idx + 2) - 1;
            len_ps[bi] += len_ps[ai];
        }
        offset *= 2;
    }

    // clear the last element
    if (idx == 0)
        len_ps[raw_len - 1] = 0;

    // traverse down tree & build scan
    for (size_t d = 1; d < raw_len; d *= 2) {
        offset >>= 1;
        __syncthreads();
        if (idx < d) {
            size_t ai = offset * (2 * idx + 1) - 1;
            size_t bi = offset * (2 * idx + 2) - 1;
            size_t t = len_ps[ai];
            len_ps[ai] = len_ps[bi];
            len_ps[bi] += t;
        }
    }
}

__global__ void genByteStream(
    char* raw_data, bool* code, size_t* code_len, size_t* len_ps, bool* bytes,
    size_t raw_len)
{
    DEF_IDX;

    if (idx < raw_len) {
        size_t start_pos = len_ps[idx];
        char symbol = raw_data[idx];
        for (size_t i = 0, len = code_len[symbol]; i < len; i++) {
            bytes[start_pos + i] = code[symbol * MAX_CODE_LEN + i];
        }
    }
}

__global__ void compressByteStream(bool* bytes, uint8_t* bits, size_t bits_len)
{
    DEF_IDX;

    if (idx < bits_len) {
        for (size_t i = 0; i < 8; i++) {
            bits[idx] |= (uint8_t)bytes[8 * idx + i] << (7 - i);
        }
    }
}

	.text
	.file	"main.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI0_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI0_1:
	.long	1127219200                      # 0x43300000
	.long	1160773632                      # 0x45300000
	.long	0                               # 0x0
	.long	0                               # 0x0
.LCPI0_2:
	.quad	0x4330000000000000              # double 4503599627370496
	.quad	0x4530000000000000              # double 1.9342813113834067E+25
	.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	$104, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %r13
	cmpl	$3, %edi
	jne	.LBB0_32
# %bb.1:
	movl	$4194304, %edi                  # imm = 0x400000
	movl	$1, %esi
	callq	calloc
	movq	%rax, %r12
	xorl	%r14d, %r14d
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	movq	8(%r13), %rdi
	movl	$.L.str.2, %esi
	callq	fopen
	movq	%rax, %r15
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
	movq	%r14, %rbx
	leaq	(%r12,%r14), %rdi
	movl	$4194304, %edx                  # imm = 0x400000
	subq	%r14, %rdx
	movl	$1, %esi
	movq	%r15, %rcx
	callq	fread
	addq	%rax, %r14
	testq	%rax, %rax
	jne	.LBB0_2
# %bb.3:
	movq	%r12, 16(%rsp)                  # 8-byte Spill
	movq	%r15, %rdi
	callq	fclose
	movl	$.L.str.3, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	leaq	64(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB0_33
# %bb.4:
	movq	64(%rsp), %rdi
	movq	16(%rsp), %rsi                  # 8-byte Reload
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB0_34
# %bb.5:
	movl	$65280, %edi                    # imm = 0xFF00
	movl	$1, %esi
	callq	calloc
	movq	%rax, %r12
	movl	$256, %edi                      # imm = 0x100
	movl	$8, %esi
	callq	calloc
	movq	%rax, %r15
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movq	16(%r13), %rdi
	movl	$.L.str.2, %esi
	callq	fopen
	movq	%rax, %r13
	leaq	72(%rsp), %rdx
	movl	$.L.str.7, %esi
	movq	%rax, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$-1, %eax
	je	.LBB0_11
# %bb.6:                                # %.lr.ph163.preheader
	leaq	8(%rsp), %rbp
.LBB0_7:                                # %.lr.ph163
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_9 Depth 2
	movl	$.L.str.8, %esi
	movq	%r13, %rdi
	leaq	40(%rsp), %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movq	40(%rsp), %rax
	movslq	72(%rsp), %rcx
	movq	%rax, (%r15,%rcx,8)
	testq	%rax, %rax
	je	.LBB0_10
# %bb.8:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB0_7 Depth=1
	xorl	%r14d, %r14d
.LBB0_9:                                # %.lr.ph
                                        #   Parent Loop BB0_7 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$.L.str.7, %esi
	movq	%r13, %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movslq	72(%rsp), %rax
	movq	%rax, %rcx
	shlq	$8, %rcx
	subq	%rax, %rcx
	addq	%r12, %rcx
	cmpl	$0, 8(%rsp)
	setne	(%r14,%rcx)
	incq	%r14
	cmpq	40(%rsp), %r14
	jb	.LBB0_9
.LBB0_10:                               # %._crit_edge
                                        #   in Loop: Header=BB0_7 Depth=1
	movl	$.L.str.7, %esi
	movq	%r13, %rdi
	leaq	72(%rsp), %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$-1, %eax
	jne	.LBB0_7
.LBB0_11:                               # %._crit_edge164
	movq	%r13, %rdi
	callq	fclose
	movl	$.Lstr, %edi
	callq	puts@PLT
	leaq	8(%rsp), %rdi
	movl	$65280, %esi                    # imm = 0xFF00
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB0_35
# %bb.12:
	movq	8(%rsp), %rdi
	movl	$65280, %edx                    # imm = 0xFF00
	movq	%r12, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB0_36
# %bb.13:
	leaq	56(%rsp), %rdi
	movl	$2048, %esi                     # imm = 0x800
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB0_37
# %bb.14:
	movq	56(%rsp), %rdi
	movl	$2048, %edx                     # imm = 0x800
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB0_38
# %bb.15:
	leaq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movl	$8, %esi
	movq	%rbx, %rdi
	callq	calloc
	movq	%rax, %r12
	cmpq	$2, %rbx
	movq	16(%rsp), %rdi                  # 8-byte Reload
	jb	.LBB0_18
# %bb.16:                               # %.lr.ph.preheader.i
	leaq	-1(%rbx), %rax
	xorl	%ecx, %ecx
	xorl	%edx, %edx
.LBB0_17:                               # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	movsbq	(%rdi,%rcx), %rsi
	addq	(%r15,%rsi,8), %rdx
	movq	%rdx, 8(%r12,%rcx,8)
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB0_17
.LBB0_18:                               # %_Z13prefixSumHostPcPmS0_m.exit
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB0_39
# %bb.19:
	leaq	(,%rbx,8), %r13
	leaq	24(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB0_40
# %bb.20:
	movq	24(%rsp), %rdi
	movq	%r12, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB0_41
# %bb.21:
	leaq	-8(,%rbx,8), %rsi
	addq	24(%rsp), %rsi
	leaq	96(%rsp), %rdi
	movl	$8, %edx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB0_42
# %bb.22:
	leaq	-1(%rbx), %rax
	movq	16(%rsp), %rcx                  # 8-byte Reload
	movsbq	(%rcx,%rax), %rax
	movq	(%r15,%rax,8), %r14
	addq	96(%rsp), %r14
	movl	$.L.str.10, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	printf
	cmpq	$4194305, %r14                  # imm = 0x400001
	jae	.LBB0_43
# %bb.23:
	leaq	32(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB0_45
# %bb.24:
	movabsq	$4294968320, %r15               # imm = 0x100000400
	leaq	3072(%r15), %r12
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_26
# %bb.25:
	movq	64(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	56(%rsp), %rdx
	movq	24(%rsp), %rcx
	movq	32(%rsp), %r8
	movq	%rbx, %r9
	callq	_Z28__device_stub__genByteStreamPcPbPmS1_S0_m
.LBB0_26:
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB0_46
# %bb.27:
	shrq	$3, %r14
	incq	%r14
	movl	$.L.str.12, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	printf
	leaq	88(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB0_47
# %bb.28:
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_30
# %bb.29:
	movq	32(%rsp), %rdi
	movq	88(%rsp), %rsi
	movq	%r14, %rdx
	callq	_Z33__device_stub__compressByteStreamPbPhm
.LBB0_30:
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB0_48
# %bb.31:
	leaq	72(%rsp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%r14), %rax
	movq	8(%r14), %rcx
	subq	40(%rsp), %rax
	cvtsi2sd	%rax, %xmm1
	subq	48(%rsp), %rcx
	cvtsi2sd	%rcx, %xmm0
	divsd	.LCPI0_0(%rip), %xmm0
	addsd	%xmm1, %xmm0
	movq	%rbx, %xmm2
	punpckldq	.LCPI0_1(%rip), %xmm2   # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
	subpd	.LCPI0_2(%rip), %xmm2
	movapd	%xmm2, %xmm1
	unpckhpd	%xmm2, %xmm1                    # xmm1 = xmm1[1],xmm2[1]
	addsd	%xmm2, %xmm1
	divsd	%xmm0, %xmm1
	movl	$.L.str.13, %edi
	movq	%rbx, %rsi
	movb	$2, %al
	callq	printf
	xorl	%eax, %eax
	addq	$104, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB0_32:
	.cfi_def_cfa_offset 160
	movq	stderr(%rip), %rdi
	movq	(%r13), %rdx
	movl	$.L.str, %esi
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB0_44
.LBB0_33:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$65, %r9d
	jmp	.LBB0_49
.LBB0_34:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$67, %r9d
	jmp	.LBB0_49
.LBB0_35:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$94, %r9d
	jmp	.LBB0_49
.LBB0_36:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$97, %r9d
	jmp	.LBB0_49
.LBB0_37:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$99, %r9d
	jmp	.LBB0_49
.LBB0_38:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$102, %r9d
	jmp	.LBB0_49
.LBB0_39:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$118, %r9d
	jmp	.LBB0_49
.LBB0_40:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$121, %r9d
	jmp	.LBB0_49
.LBB0_41:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$123, %r9d
	jmp	.LBB0_49
.LBB0_42:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$136, %r9d
	jmp	.LBB0_49
.LBB0_43:
	movq	stderr(%rip), %rcx
	movl	$.L.str.11, %edi
	movl	$24, %esi
	movl	$1, %edx
	callq	fwrite@PLT
.LBB0_44:
	movl	$1, %edi
	callq	exit
.LBB0_45:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$149, %r9d
	jmp	.LBB0_49
.LBB0_46:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$152, %r9d
	jmp	.LBB0_49
.LBB0_47:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$162, %r9d
	jmp	.LBB0_49
.LBB0_48:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	%ebp, %ecx
	movl	$164, %r9d
.LBB0_49:
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebp, %edi
	callq	exit
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z13prefixSumHostPcPmS0_m       # -- Begin function _Z13prefixSumHostPcPmS0_m
	.type	_Z13prefixSumHostPcPmS0_m,@function
_Z13prefixSumHostPcPmS0_m:              # @_Z13prefixSumHostPcPmS0_m
	.cfi_startproc
# %bb.0:
	movq	$0, (%rdx)
	cmpq	$2, %rcx
	jb	.LBB1_3
# %bb.1:                                # %.lr.ph.preheader
	decq	%rcx
	xorl	%eax, %eax
	xorl	%r8d, %r8d
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movsbq	(%rdi,%rax), %r9
	addq	(%rsi,%r9,8), %r8
	movq	%r8, 8(%rdx,%rax,8)
	incq	%rax
	cmpq	%rax, %rcx
	jne	.LBB1_2
.LBB1_3:                                # %._crit_edge
	retq
.Lfunc_end1:
	.size	_Z13prefixSumHostPcPmS0_m, .Lfunc_end1-_Z13prefixSumHostPcPmS0_m
	.cfi_endproc
                                        # -- End function
	.globl	_Z28__device_stub__genByteStreamPcPbPmS1_S0_m # -- Begin function _Z28__device_stub__genByteStreamPcPbPmS1_S0_m
	.type	_Z28__device_stub__genByteStreamPcPbPmS1_S0_m,@function
_Z28__device_stub__genByteStreamPcPbPmS1_S0_m: # @_Z28__device_stub__genByteStreamPcPbPmS1_S0_m
	.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	16(%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	8(%rsp), %r12
	movq	%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	$_Z13genByteStreamPcPbPmS1_S0_m, %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_end2:
	.size	_Z28__device_stub__genByteStreamPcPbPmS1_S0_m, .Lfunc_end2-_Z28__device_stub__genByteStreamPcPbPmS1_S0_m
	.cfi_endproc
                                        # -- End function
	.globl	_Z33__device_stub__compressByteStreamPbPhm # -- Begin function _Z33__device_stub__compressByteStreamPbPhm
	.type	_Z33__device_stub__compressByteStreamPbPhm,@function
_Z33__device_stub__compressByteStreamPbPhm: # @_Z33__device_stub__compressByteStreamPbPhm
	.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	24(%rsp), %rsi
	movq	%rdx, (%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	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	$_Z18compressByteStreamPbPhm, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z33__device_stub__compressByteStreamPbPhm, .Lfunc_end3-_Z33__device_stub__compressByteStreamPbPhm
	.cfi_endproc
                                        # -- End function
	.globl	_Z24__device_stub__prefixSumPcPmS0_m # -- Begin function _Z24__device_stub__prefixSumPcPmS0_m
	.type	_Z24__device_stub__prefixSumPcPmS0_m,@function
_Z24__device_stub__prefixSumPcPmS0_m:   # @_Z24__device_stub__prefixSumPcPmS0_m
	.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	16(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z9prefixSumPcPmS0_m, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z24__device_stub__prefixSumPcPmS0_m, .Lfunc_end4-_Z24__device_stub__prefixSumPcPmS0_m
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9prefixSumPcPmS0_m, %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	$_Z13genByteStreamPcPbPmS1_S0_m, %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	$_Z18compressByteStreamPbPhm, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %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_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB6_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Usage: %s raw_data huffman_table\n"
	.size	.L.str, 34

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Reading raw data ... "
	.size	.L.str.1, 22

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

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"done. Read %zu bytes.\n"
	.size	.L.str.3, 23

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"[Error] %s (error code: %d) at %s line %d\n"
	.size	.L.str.4, 43

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/ordovicia/huffman-coding-cuda/master/main.hip"
	.size	.L.str.5, 108

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Reading Huffman table ... "
	.size	.L.str.6, 27

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

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

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"bytes len: %zu\n"
	.size	.L.str.10, 16

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Bytes stream overflowed\n"
	.size	.L.str.11, 25

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

	.type	.L.str.12,@object               # @.str.12
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.12:
	.asciz	"bits len: %zu\n"
	.size	.L.str.12, 15

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

	.type	.L.str.13,@object               # @.str.13
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.13:
	.asciz	"bytes: %zu sec: %lf bytes/sec: %lf\n"
	.size	.L.str.13, 36

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

	.type	.L__unnamed_1,@object           # @0
	.section	.rodata.str1.1,"aMS",@progbits,1
.L__unnamed_1:
	.asciz	"_Z9prefixSumPcPmS0_m"
	.size	.L__unnamed_1, 21

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z13genByteStreamPcPbPmS1_S0_m"
	.size	.L__unnamed_2, 31

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z18compressByteStreamPbPhm"
	.size	.L__unnamed_3, 28

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

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

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

	.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 _Z28__device_stub__genByteStreamPcPbPmS1_S0_m
	.addrsig_sym _Z33__device_stub__compressByteStreamPbPhm
	.addrsig_sym _Z24__device_stub__prefixSumPcPmS0_m
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z13genByteStreamPcPbPmS1_S0_m
	.addrsig_sym _Z18compressByteStreamPbPhm
	.addrsig_sym _Z9prefixSumPcPmS0_m
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9prefixSumPcPmS0_m    ; -- Begin function _Z9prefixSumPcPmS0_m
	.globl	_Z9prefixSumPcPmS0_m
	.p2align	8
	.type	_Z9prefixSumPcPmS0_m,@function
_Z9prefixSumPcPmS0_m:                   ; @_Z9prefixSumPcPmS0_m
; %bb.0:
	s_clause 0x1
	s_load_b32 s8, s[0:1], 0x2c
	s_load_b256 s[0:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s8, s8, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s8, v[0:1]
	v_mov_b32_e32 v2, 0
	s_mov_b32 s8, exec_lo
	v_lshlrev_b64 v[5:6], 1, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_or_b32_e32 v3, 1, v5
	v_mov_b32_e32 v4, v6
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_u64_e64 s[6:7], v[3:4]
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_add_co_u32 v7, vcc_lo, s0, v5
	v_add_co_ci_u32_e32 v8, vcc_lo, s1, v6, vcc_lo
	v_lshlrev_b64 v[5:6], 3, v[5:6]
	global_load_i8 v0, v[7:8], off
	s_waitcnt vmcnt(0)
	v_bfe_i32 v9, v0, 0, 16
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v10, 31, v9
	v_lshlrev_b64 v[9:10], 3, v[9:10]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v9, vcc_lo, s2, v9
	v_add_co_ci_u32_e32 v10, vcc_lo, s3, v10, vcc_lo
	v_add_co_u32 v5, vcc_lo, s4, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s5, v6, vcc_lo
	global_load_b64 v[9:10], v[9:10], off
	s_waitcnt vmcnt(0)
	global_store_b64 v[5:6], v[9:10], off
	global_load_i8 v0, v[7:8], off offset:1
	s_waitcnt vmcnt(0)
	v_bfe_i32 v7, v0, 0, 16
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v8, 31, v7
	v_lshlrev_b64 v[7:8], 3, v[7:8]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v7, vcc_lo, s2, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s3, v8, vcc_lo
	global_load_b64 v[7:8], v[7:8], off
	s_waitcnt vmcnt(0)
	global_store_b64 v[5:6], v[7:8], off offset:8
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s8
	v_cmp_lt_u64_e64 s0, s[6:7], 2
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_and_b32 vcc_lo, exec_lo, s0
	s_mov_b64 s[0:1], 1
	s_cbranch_vccnz .LBB0_8
; %bb.3:                                ; %.lr.ph
	s_mov_b64 s[2:3], s[6:7]
.LBB0_4:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshr_b64 s[8:9], s[2:3], 1
	s_mov_b32 s10, exec_lo
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_u64_e64 s[8:9], v[1:2]
	s_cbranch_execz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_4 Depth=1
	v_mul_lo_u32 v0, s1, v3
	v_mul_lo_u32 v7, s0, v4
	v_mad_u64_u32 v[5:6], null, s0, v3, 0
	s_lshl_b64 s[12:13], s[0:1], 3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add3_u32 v6, v6, v7, v0
	v_lshlrev_b64 v[5:6], 3, v[5:6]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v5, vcc_lo, s4, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s5, v6, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v7, vcc_lo, v5, s12
	v_add_co_ci_u32_e32 v8, vcc_lo, s13, v6, vcc_lo
	s_clause 0x1
	global_load_b64 v[5:6], v[5:6], off offset:-8
	global_load_b64 v[9:10], v[7:8], off offset:-8
	s_waitcnt vmcnt(0)
	v_add_co_u32 v5, vcc_lo, v9, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, v10, v6, vcc_lo
	global_store_b64 v[7:8], v[5:6], off offset:-8
.LBB0_6:                                ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
	v_cmp_lt_u64_e64 s2, s[2:3], 4
	s_lshl_b64 s[0:1], s[0:1], 1
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 vcc_lo, exec_lo, s2
	s_cbranch_vccnz .LBB0_8
; %bb.7:                                ;   in Loop: Header=BB0_4 Depth=1
	s_mov_b64 s[2:3], s[8:9]
	s_branch .LBB0_4
.LBB0_8:                                ; %Flow81
	s_mov_b32 s2, exec_lo
	v_cmpx_eq_u32_e32 0, v1
	s_cbranch_execz .LBB0_10
; %bb.9:
	v_mov_b32_e32 v5, 0
	s_lshl_b64 s[8:9], s[6:7], 3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	s_add_u32 s8, s4, s8
	s_addc_u32 s9, s5, s9
	v_mov_b32_e32 v6, v5
	global_store_b64 v5, v[5:6], s[8:9] offset:-8
.LBB0_10:
	s_or_b32 exec_lo, exec_lo, s2
	v_cmp_lt_u64_e64 s2, s[6:7], 2
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 vcc_lo, exec_lo, s2
	s_cbranch_vccnz .LBB0_15
; %bb.11:                               ; %.lr.ph66
	s_mov_b64 s[2:3], 1
.LBB0_12:                               ; =>This Inner Loop Header: Depth=1
	s_lshr_b64 s[0:1], s[0:1], 1
	s_mov_b32 s8, exec_lo
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_u64_e64 s[2:3], v[1:2]
	s_cbranch_execz .LBB0_14
; %bb.13:                               ;   in Loop: Header=BB0_12 Depth=1
	v_mul_lo_u32 v0, s1, v3
	v_mul_lo_u32 v7, s0, v4
	v_mad_u64_u32 v[5:6], null, s0, v3, 0
	s_lshl_b64 s[10:11], s[0:1], 3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add3_u32 v6, v6, v7, v0
	v_lshlrev_b64 v[5:6], 3, v[5:6]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v5, vcc_lo, s4, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s5, v6, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v7, vcc_lo, v5, s10
	v_add_co_ci_u32_e32 v8, vcc_lo, s11, v6, vcc_lo
	s_clause 0x1
	global_load_b64 v[9:10], v[5:6], off offset:-8
	global_load_b64 v[11:12], v[7:8], off offset:-8
	s_waitcnt vmcnt(0)
	v_add_co_u32 v9, vcc_lo, v11, v9
	v_add_co_ci_u32_e32 v10, vcc_lo, v12, v10, vcc_lo
	s_clause 0x1
	global_store_b64 v[5:6], v[11:12], off offset:-8
	global_store_b64 v[7:8], v[9:10], off offset:-8
.LBB0_14:                               ;   in Loop: Header=BB0_12 Depth=1
	s_or_b32 exec_lo, exec_lo, s8
	s_lshl_b64 s[2:3], s[2:3], 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_u64_e64 s8, s[2:3], s[6:7]
	s_and_b32 vcc_lo, exec_lo, s8
	s_cbranch_vccz .LBB0_12
.LBB0_15:                               ; %._crit_edge67
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9prefixSumPcPmS0_m
		.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 13
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z9prefixSumPcPmS0_m, .Lfunc_end0-_Z9prefixSumPcPmS0_m
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 792
; NumSgprs: 18
; NumVgprs: 13
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 13
; 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	_Z13genByteStreamPcPbPmS1_S0_m ; -- Begin function _Z13genByteStreamPcPbPmS1_S0_m
	.globl	_Z13genByteStreamPcPbPmS1_S0_m
	.p2align	8
	.type	_Z13genByteStreamPcPbPmS1_S0_m,@function
_Z13genByteStreamPcPbPmS1_S0_m:         ; @_Z13genByteStreamPcPbPmS1_S0_m
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x3c
	s_load_b128 s[8:11], s[0:1], 0x20
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, s15, s2, v[0:1]
	v_mov_b32_e32 v3, 0
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_u64_e64 s[10:11], v[2:3]
	s_cbranch_execz .LBB1_4
; %bb.1:
	s_load_b256 s[0:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, s0, s0, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v1, null, s1, 0, s0
	s_mov_b32 s1, 0
	global_load_i8 v0, v[0:1], off
	s_waitcnt vmcnt(0)
	v_bfe_i32 v4, v0, 0, 16
	v_ashrrev_i32_e32 v5, 31, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 3, v[4:5]
	v_add_co_u32 v0, vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	global_load_b64 v[0:1], v[0:1], off
	s_waitcnt vmcnt(0)
	v_cmp_ne_u64_e32 vcc_lo, 0, v[0:1]
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB1_4
; %bb.2:                                ; %.lr.ph
	v_lshlrev_b64 v[2:3], 3, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s6, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
	global_load_b64 v[5:6], v[2:3], off
	v_mul_i32_i24_e32 v2, 0xff, v4
	v_mul_hi_i32_i24_e32 v3, 0xff, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s2, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s3, v3, vcc_lo
	s_waitcnt vmcnt(0)
	v_add_co_u32 v4, vcc_lo, s8, v5
	v_add_co_ci_u32_e32 v5, vcc_lo, s9, v6, vcc_lo
.LBB1_3:                                ; =>This Inner Loop Header: Depth=1
	global_load_u8 v6, v[2:3], off
	v_add_co_u32 v0, vcc_lo, v0, -1
	v_add_co_ci_u32_e32 v1, vcc_lo, -1, v1, vcc_lo
	v_add_co_u32 v2, vcc_lo, v2, 1
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_cmp_eq_u64_e32 vcc_lo, 0, v[0:1]
	s_or_b32 s1, vcc_lo, s1
	s_waitcnt vmcnt(0)
	global_store_b8 v[4:5], v6, off
	v_add_co_u32 v4, s0, v4, 1
	v_add_co_ci_u32_e64 v5, s0, 0, v5, s0
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB1_3
.LBB1_4:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z13genByteStreamPcPbPmS1_S0_m
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 304
		.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 7
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z13genByteStreamPcPbPmS1_S0_m, .Lfunc_end1-_Z13genByteStreamPcPbPmS1_S0_m
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 348
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; 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	_Z18compressByteStreamPbPhm ; -- Begin function _Z18compressByteStreamPbPhm
	.globl	_Z18compressByteStreamPbPhm
	.p2align	8
	.type	_Z18compressByteStreamPbPhm,@function
_Z18compressByteStreamPbPhm:            ; @_Z18compressByteStreamPbPhm
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x24
	s_load_b64 s[2:3], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, s15, s4, v[0:1]
	v_mov_b32_e32 v3, 0
	v_cmp_gt_u64_e32 vcc_lo, s[2:3], v[2:3]
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB2_3
; %bb.1:                                ; %.preheader
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, s2, s2, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v1, null, s3, 0, s2
	v_lshlrev_b64 v[2:3], 3, v[2:3]
	global_load_u8 v4, v[0:1], off
	v_add_co_u32 v2, vcc_lo, s0, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v3, vcc_lo
	s_mov_b64 s[0:1], 0
.LBB2_2:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
	v_add_co_u32 v5, vcc_lo, v2, s0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v6, vcc_lo, s1, v3, vcc_lo
	s_xor_b32 s2, s0, 7
	s_add_u32 s0, s0, 1
	s_addc_u32 s1, s1, 0
	global_load_u8 v5, v[5:6], off
	s_cmp_lg_u64 s[0:1], 8
	s_waitcnt vmcnt(0)
	v_lshlrev_b32_e32 v5, s2, v5
	s_delay_alu instid0(VALU_DEP_1)
	v_or_b32_e32 v4, v4, v5
	global_store_b8 v[0:1], v4, off
	s_cbranch_scc1 .LBB2_2
.LBB2_3:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z18compressByteStreamPbPhm
		.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 7
		.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	_Z18compressByteStreamPbPhm, .Lfunc_end2-_Z18compressByteStreamPbPhm
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 208
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; 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
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           8
        .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:           _Z9prefixSumPcPmS0_m
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9prefixSumPcPmS0_m.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     13
    .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
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .offset:         40
        .size:           8
        .value_kind:     by_value
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         52
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         56
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         60
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         62
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         64
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         66
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         68
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         70
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         112
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 304
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z13genByteStreamPcPbPmS1_S0_m
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z13genByteStreamPcPbPmS1_S0_m.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .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:           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:           _Z18compressByteStreamPbPhm
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z18compressByteStreamPbPhm.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
