// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/htscodecs/htscodecs/pack.c
// Function: hts_unpack
uint8_t *hts_unpack(uint8_t *data, int64_t len, uint8_t *out, uint64_t out_len, int nsym, uint8_t *p) {
    //uint8_t *out;
    uint8_t c = 0;
    int64_t i, j = 0, olen;

    if (nsym == 1) {
        // raw data; FIXME: shortcut the need for malloc & memcpy here
        memcpy(out, data, len);
        return out;
    }

    switch(nsym) {
    case 8: {
        union {
            uint64_t w;
            uint8_t c[8];
        } map[256];
        int x;
        for (x = 0; x < 256; x++) {
            map[x].c[0] = p[x>>0&1];
            map[x].c[1] = p[x>>1&1];
            map[x].c[2] = p[x>>2&1];
            map[x].c[3] = p[x>>3&1];
            map[x].c[4] = p[x>>4&1];
            map[x].c[5] = p[x>>5&1];
            map[x].c[6] = p[x>>6&1];
            map[x].c[7] = p[x>>7&1];
        }
        if ((out_len+7)/8 > len)
            return NULL;
        olen = out_len & ~7;

        for (i = 0; i < olen; i+=8)
            memcpy(&out[i], &map[data[j++]].w, 8);

        if (out_len != olen) {
            c = data[j++];
            while (i < out_len) {
                out[i++] = p[c & 1];
                c >>= 1;
            }
        }
        break;
    }

    case 4: {
        union {
            uint32_t w;
            uint8_t c[4];
        } map[256];

        int x, y, z, _, P=0;
        for (x = 0; x < 4; x++)
            for (y = 0; y < 4; y++)
                for (z = 0; z < 4; z++)
                    for (_ = 0; _ < 4; _++, P++) {
                        map[P].c[0] = p[_];
                        map[P].c[1] = p[z];
                        map[P].c[2] = p[y];
                        map[P].c[3] = p[x];
                    }

        if ((out_len+3)/4 > len)
            return NULL;
        olen = out_len & ~3;

        for (i = 0; i < olen-12; i+=16) {
            uint32_t w[] = {
                map[data[j+0]].w,
                map[data[j+1]].w,
                map[data[j+2]].w,
                map[data[j+3]].w
            };
            j += 4;
            memcpy(&out[i], &w, 16);
        }

        for (; i < olen; i+=4)
            memcpy(&out[i], &map[data[j++]].w, 4);

        if (out_len != olen) {
            c = data[j++];
            while (i < out_len) {
                out[i++] = p[c & 3];
                c >>= 2;
            }
        }
        break;
    }

    case 2: {
        union {
            uint16_t w;
            uint8_t c[2];
        } map[256];

        int x, y;
        for (x = 0; x < 16; x++) {
            for (y = 0; y < 16; y++) {
                map[x*16+y].c[0] = p[y];
                map[x*16+y].c[1] = p[x];
            }
        }

        if ((out_len+1)/2 > len)
            return NULL;
        olen = out_len & ~1;

        for (i = j = 0; i+2 < olen; i+=4) {
            uint16_t w[] = {
                map[data[j+0]].w,
                map[data[j+1]].w
            };
            memcpy(&out[i], &w, 4);

            j += 2;
        }

        for (; i < olen; i+=2)
            memcpy(&out[i], &map[data[j++]].w, 2);

        if (out_len != olen) {
            c = data[j++];
            out[i+0] = p[c&15];
        }
        break;
    }

    case 0:
        memset(out, p[0], out_len);
        break;

    default:
        return NULL;
    }

    return out;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xec0, %rsp            # imm = 0xEC0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movb $0x0, -0x39(%rbp)
movq $0x0, -0x50(%rbp)
cmpl $0x1, -0x2c(%rbp)
jne 0x8d903
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x43b0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x8e01f
movl -0x2c(%rbp), %eax
movq %rax, -0xeb8(%rbp)
subq $0x8, %rax
ja 0x8e00d
movq -0xeb8(%rbp), %rax
leaq 0x68ac3(%rip), %rcx     # 0xf63e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, -0x864(%rbp)
cmpl $0x100, -0x864(%rbp)    # imm = 0x100
jge 0x8da7b
movq -0x38(%rbp), %rax
movl -0x864(%rbp), %ecx
sarl $0x0, %ecx
andl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movslq -0x864(%rbp), %rax
movb %cl, -0x860(%rbp,%rax,8)
movq -0x38(%rbp), %rax
movl -0x864(%rbp), %ecx
sarl %ecx
andl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movslq -0x864(%rbp), %rax
movb %cl, -0x85f(%rbp,%rax,8)
movq -0x38(%rbp), %rax
movl -0x864(%rbp), %ecx
sarl $0x2, %ecx
andl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movslq -0x864(%rbp), %rax
movb %cl, -0x85e(%rbp,%rax,8)
movq -0x38(%rbp), %rax
movl -0x864(%rbp), %ecx
sarl $0x3, %ecx
andl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movslq -0x864(%rbp), %rax
movb %cl, -0x85d(%rbp,%rax,8)
movq -0x38(%rbp), %rax
movl -0x864(%rbp), %ecx
sarl $0x4, %ecx
andl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movslq -0x864(%rbp), %rax
movb %cl, -0x85c(%rbp,%rax,8)
movq -0x38(%rbp), %rax
movl -0x864(%rbp), %ecx
sarl $0x5, %ecx
andl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movslq -0x864(%rbp), %rax
movb %cl, -0x85b(%rbp,%rax,8)
movq -0x38(%rbp), %rax
movl -0x864(%rbp), %ecx
sarl $0x6, %ecx
andl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movslq -0x864(%rbp), %rax
movb %cl, -0x85a(%rbp,%rax,8)
movq -0x38(%rbp), %rax
movl -0x864(%rbp), %ecx
sarl $0x7, %ecx
andl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movslq -0x864(%rbp), %rax
movb %cl, -0x859(%rbp,%rax,8)
movl -0x864(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x864(%rbp)
jmp 0x8d938
movq -0x28(%rbp), %rax
addq $0x7, %rax
shrq $0x3, %rax
cmpq -0x18(%rbp), %rax
jbe 0x8da9a
movq $0x0, -0x8(%rbp)
jmp 0x8e01f
movq -0x28(%rbp), %rax
andq $-0x8, %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x8daf1
movq -0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rdx
movq -0x50(%rbp), %rsi
movq %rsi, %rdi
addq $0x1, %rdi
movq %rdi, -0x50(%rbp)
movzbl (%rdx,%rsi), %edx
movq -0x860(%rbp,%rdx,8), %rdx
movq %rdx, (%rax,%rcx)
movq -0x48(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x48(%rbp)
jmp 0x8daae
movq -0x28(%rbp), %rax
cmpq -0x58(%rbp), %rax
je 0x8db52
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x50(%rbp)
movb (%rax,%rcx), %al
movb %al, -0x39(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x8db50
movq -0x38(%rbp), %rax
movzbl -0x39(%rbp), %ecx
andl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x48(%rbp)
movb %dl, (%rax,%rcx)
movzbl -0x39(%rbp), %eax
sarl %eax
movb %al, -0x39(%rbp)
jmp 0x8db14
jmp 0x8db52
jmp 0x8e017
movl $0x0, -0xc84(%rbp)
movl $0x0, -0xc74(%rbp)
cmpl $0x4, -0xc74(%rbp)
jge 0x8dc92
movl $0x0, -0xc78(%rbp)
cmpl $0x4, -0xc78(%rbp)
jge 0x8dc7c
movl $0x0, -0xc7c(%rbp)
cmpl $0x4, -0xc7c(%rbp)
jge 0x8dc66
movl $0x0, -0xc80(%rbp)
cmpl $0x4, -0xc80(%rbp)
jge 0x8dc50
movq -0x38(%rbp), %rax
movslq -0xc80(%rbp), %rcx
movb (%rax,%rcx), %cl
movslq -0xc84(%rbp), %rax
movb %cl, -0xc70(%rbp,%rax,4)
movq -0x38(%rbp), %rax
movslq -0xc7c(%rbp), %rcx
movb (%rax,%rcx), %cl
movslq -0xc84(%rbp), %rax
movb %cl, -0xc6f(%rbp,%rax,4)
movq -0x38(%rbp), %rax
movslq -0xc78(%rbp), %rcx
movb (%rax,%rcx), %cl
movslq -0xc84(%rbp), %rax
movb %cl, -0xc6e(%rbp,%rax,4)
movq -0x38(%rbp), %rax
movslq -0xc74(%rbp), %rcx
movb (%rax,%rcx), %cl
movslq -0xc84(%rbp), %rax
movb %cl, -0xc6d(%rbp,%rax,4)
movl -0xc80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc80(%rbp)
movl -0xc84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc84(%rbp)
jmp 0x8dbb0
jmp 0x8dc52
movl -0xc7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc7c(%rbp)
jmp 0x8db99
jmp 0x8dc68
movl -0xc78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc78(%rbp)
jmp 0x8db82
jmp 0x8dc7e
movl -0xc74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc74(%rbp)
jmp 0x8db6b
movq -0x28(%rbp), %rax
addq $0x3, %rax
shrq $0x2, %rax
cmpq -0x18(%rbp), %rax
jbe 0x8dcb1
movq $0x0, -0x8(%rbp)
jmp 0x8e01f
movq -0x28(%rbp), %rax
andq $-0x4, %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
subq $0xc, %rcx
cmpq %rcx, %rax
jge 0x8dd7d
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl -0xc70(%rbp,%rax,4), %eax
movl %eax, -0xca0(%rbp)
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %eax
movl -0xc70(%rbp,%rax,4), %eax
movl %eax, -0xc9c(%rbp)
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movzbl 0x2(%rax,%rcx), %eax
movl -0xc70(%rbp,%rax,4), %eax
movl %eax, -0xc98(%rbp)
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movzbl 0x3(%rax,%rcx), %eax
movl -0xc70(%rbp,%rax,4), %eax
movl %eax, -0xc94(%rbp)
movq -0x50(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movq -0xca0(%rbp), %rdx
movq %rdx, (%rax,%rcx)
movq -0xc98(%rbp), %rdx
movq %rdx, 0x8(%rax,%rcx)
movq -0x48(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x48(%rbp)
jmp 0x8dcc5
jmp 0x8dd7f
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x8ddc0
movq -0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rdx
movq -0x50(%rbp), %rsi
movq %rsi, %rdi
addq $0x1, %rdi
movq %rdi, -0x50(%rbp)
movzbl (%rdx,%rsi), %edx
movl -0xc70(%rbp,%rdx,4), %edx
movl %edx, (%rax,%rcx)
movq -0x48(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x48(%rbp)
jmp 0x8dd7f
movq -0x28(%rbp), %rax
cmpq -0x58(%rbp), %rax
je 0x8de22
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x50(%rbp)
movb (%rax,%rcx), %al
movb %al, -0x39(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x8de20
movq -0x38(%rbp), %rax
movzbl -0x39(%rbp), %ecx
andl $0x3, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x48(%rbp)
movb %dl, (%rax,%rcx)
movzbl -0x39(%rbp), %eax
sarl $0x2, %eax
movb %al, -0x39(%rbp)
jmp 0x8dde3
jmp 0x8de22
jmp 0x8e017
movl $0x0, -0xea4(%rbp)
cmpl $0x10, -0xea4(%rbp)
jge 0x8dec4
movl $0x0, -0xea8(%rbp)
cmpl $0x10, -0xea8(%rbp)
jge 0x8deae
movq -0x38(%rbp), %rax
movslq -0xea8(%rbp), %rcx
movb (%rax,%rcx), %cl
movl -0xea4(%rbp), %eax
shll $0x4, %eax
addl -0xea8(%rbp), %eax
cltq
movb %cl, -0xea0(%rbp,%rax,2)
movq -0x38(%rbp), %rax
movslq -0xea4(%rbp), %rcx
movb (%rax,%rcx), %cl
movl -0xea4(%rbp), %eax
shll $0x4, %eax
addl -0xea8(%rbp), %eax
cltq
movb %cl, -0xe9f(%rbp,%rax,2)
movl -0xea8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xea8(%rbp)
jmp 0x8de48
jmp 0x8deb0
movl -0xea4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xea4(%rbp)
jmp 0x8de31
movq -0x28(%rbp), %rax
addq $0x1, %rax
shrq %rax
cmpq -0x18(%rbp), %rax
jbe 0x8dee2
movq $0x0, -0x8(%rbp)
jmp 0x8e01f
movq -0x28(%rbp), %rax
andq $-0x2, %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq $0x2, %rax
cmpq -0x58(%rbp), %rax
jge 0x8df6e
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movw -0xea0(%rbp,%rax,2), %ax
movw %ax, -0xeac(%rbp)
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %eax
movw -0xea0(%rbp,%rax,2), %ax
movw %ax, -0xeaa(%rbp)
movq -0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movl -0xeac(%rbp), %edx
movl %edx, (%rax,%rcx)
movq -0x50(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x48(%rbp)
jmp 0x8defe
jmp 0x8df70
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x8dfb3
movq -0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rdx
movq -0x50(%rbp), %rsi
movq %rsi, %rdi
addq $0x1, %rdi
movq %rdi, -0x50(%rbp)
movzbl (%rdx,%rsi), %edx
movw -0xea0(%rbp,%rdx,2), %dx
movw %dx, (%rax,%rcx)
movq -0x48(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
jmp 0x8df70
movq -0x28(%rbp), %rax
cmpq -0x58(%rbp), %rax
je 0x8dff2
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x50(%rbp)
movb (%rax,%rcx), %al
movb %al, -0x39(%rbp)
movq -0x38(%rbp), %rax
movzbl -0x39(%rbp), %ecx
andl $0xf, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x8e017
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
movq -0x28(%rbp), %rdx
movzbl %al, %esi
callq 0x4250
jmp 0x8e017
movq $0x0, -0x8(%rbp)
jmp 0x8e01f
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xec0, %rsp            # imm = 0xEC0
popq %rbp
retq
nopl (%rax)