// 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 2: {
        uint16_t map[256], x, y;
        for (x = 0; x < 16; x++)
            for (y = 0; y < 16; y++)
                map[x*16+y] = p[x]*256+p[y];

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

        uint16_t *o16 = (uint16_t *)out;
        for (i = 0; i+4 < olen/2; i+=4) {
            int k;
            for (k = 0; k < 4; k++)
                o16[i+k] = map[data[i+k]];
        }
        j = i; i *= 2;

        for (; i < olen; i+=2) {
            uint16_t w1 = map[data[j++]];
            *(uint16_t *)&out[i] = w1;
        }

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

    default:
        return NULL;
    }

    return out;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
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 0x8e083
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x43b0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x8e2bd
movl -0x2c(%rbp), %eax
subl $0x2, %eax
jne 0x8e2ab
jmp 0x8e091
movw $0x0, -0x262(%rbp)
movzwl -0x262(%rbp), %eax
cmpl $0x10, %eax
jge 0x8e12f
movw $0x0, -0x264(%rbp)
movzwl -0x264(%rbp), %eax
cmpl $0x10, %eax
jge 0x8e116
movq -0x38(%rbp), %rax
movzwl -0x262(%rbp), %ecx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x38(%rbp), %rcx
movzwl -0x264(%rbp), %edx
movzbl (%rcx,%rdx), %ecx
addl %ecx, %eax
movw %ax, %cx
movzwl -0x262(%rbp), %eax
shll $0x4, %eax
movzwl -0x264(%rbp), %edx
addl %edx, %eax
cltq
movw %cx, -0x260(%rbp,%rax,2)
movw -0x264(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x264(%rbp)
jmp 0x8e0b3
jmp 0x8e118
movw -0x262(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x262(%rbp)
jmp 0x8e09a
movq -0x28(%rbp), %rax
addq $0x1, %rax
shrq %rax
cmpq -0x18(%rbp), %rax
jbe 0x8e14d
movq $0x0, -0x8(%rbp)
jmp 0x8e2bd
movq -0x28(%rbp), %rax
andq $-0x2, %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x270(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x280(%rbp)
movq -0x58(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x280(%rbp), %rax
cmpq %rcx, %rax
jge 0x8e206
movl $0x0, -0x274(%rbp)
cmpl $0x4, -0x274(%rbp)
jge 0x8e1f3
movq -0x10(%rbp), %rax
movq -0x48(%rbp), %rcx
movslq -0x274(%rbp), %rdx
addq %rdx, %rcx
movzbl (%rax,%rcx), %eax
movw -0x260(%rbp,%rax,2), %dx
movq -0x270(%rbp), %rax
movq -0x48(%rbp), %rcx
movslq -0x274(%rbp), %rsi
addq %rsi, %rcx
movw %dx, (%rax,%rcx,2)
movl -0x274(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x274(%rbp)
jmp 0x8e1a2
jmp 0x8e1f5
movq -0x48(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x48(%rbp)
jmp 0x8e16c
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
shlq %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x8e26a
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x50(%rbp)
movzbl (%rax,%rcx), %eax
movw -0x260(%rbp,%rax,2), %ax
movw %ax, -0x276(%rbp)
movw -0x276(%rbp), %dx
movq -0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movw %dx, (%rax,%rcx)
movq -0x48(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
jmp 0x8e219
movq -0x28(%rbp), %rax
cmpq -0x58(%rbp), %rax
je 0x8e2a9
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 0x8e2b5
movq $0x0, -0x8(%rbp)
jmp 0x8e2bd
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
nopw (%rax,%rax)