// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/htscodecs/htscodecs/pack.c
// Function: hts_pack
uint8_t *hts_pack(uint8_t *data, int64_t len,
                  uint8_t *out_meta, int *out_meta_len, uint64_t *out_len) {
    int p[256] = {0}, n;
    uint64_t i, j;

    // count syms
    for (i = 0; i < len; i++)
        p[data[i]]=1;
    
    for (i = n = 0; i < 256; i++) {
        if (p[i]) {
            p[i] = n++; // p[i] is now the code number
            out_meta[n] = i;
        }
    }
    out_meta[0] = n; // 256 wraps to 0
    j = n+1;

    // 1 value per byte
    if (n > 16)
        return NULL;

    uint8_t *out = malloc(len+1);
    if (!out)
        return NULL;

    // Work out how many values per byte to encode.
    int val_per_byte;
    if (n > 4)
        val_per_byte = 2;
    else if (n > 2)
        val_per_byte = 4;
    else if (n > 1)
        val_per_byte = 8;
    else
        val_per_byte = 0; // infinite

    *out_meta_len = j;
    j = 0;

    switch (val_per_byte) {
    case 2:
        for (i = 0; i < (len & ~1); i+=2)
            out[j++] = (p[data[i]]<<0) | (p[data[i+1]]<<4);
        switch (len-i) {
        case 1: out[j++] = p[data[i]];
        }
        *out_len = j;
        return out;

    case 4: {
        for (i = 0; i < (len & ~3); i+=4)
            out[j++] = (p[data[i]]<<0) | (p[data[i+1]]<<2) | (p[data[i+2]]<<4) | (p[data[i+3]]<<6);
        out[j] = 0;
        int s = len-i, x = 0;
        switch (s) {
        case 3: out[j] |= p[data[i++]] << x; x+=2; // fall-through
        case 2: out[j] |= p[data[i++]] << x; x+=2; // fall-through
        case 1: out[j] |= p[data[i++]] << x; x+=2;
            j++;
        }
        *out_len = j;
        return out;
    }

    case 8: {
        for (i = 0; i < (len & ~7); i+=8)
            out[j++] = (p[data[i+0]]<<0) | (p[data[i+1]]<<1) | (p[data[i+2]]<<2) | (p[data[i+3]]<<3)
                     | (p[data[i+4]]<<4) | (p[data[i+5]]<<5) | (p[data[i+6]]<<6) | (p[data[i+7]]<<7);
        out[j] = 0;
        int s = len-i, x = 0;
        switch (s) {
        case 7: out[j] |= p[data[i++]] << x++; // fall-through
        case 6: out[j] |= p[data[i++]] << x++; // fall-through
        case 5: out[j] |= p[data[i++]] << x++; // fall-through
        case 4: out[j] |= p[data[i++]] << x++; // fall-through
        case 3: out[j] |= p[data[i++]] << x++; // fall-through
        case 2: out[j] |= p[data[i++]] << x++; // fall-through
        case 1: out[j] |= p[data[i++]] << x++;
            j++;
        }
        *out_len = j;
        return out;
    }

    case 0:
        *out_len = j;
        return out;
    }

    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x480, %rsp            # imm = 0x480
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
leaq -0x430(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x4250
movq $0x0, -0x440(%rbp)
movq -0x440(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x8cea8
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl $0x1, -0x430(%rbp,%rax,4)
movq -0x440(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x440(%rbp)
jmp 0x8ce6d
movl $0x0, -0x434(%rbp)
movq $0x0, -0x440(%rbp)
cmpq $0x100, -0x440(%rbp) # imm = 0x100
jae 0x8cf27
movq -0x440(%rbp), %rax
cmpl $0x0, -0x430(%rbp,%rax,4)
je 0x8cf11
movl -0x434(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x434(%rbp)
movq -0x440(%rbp), %rax
movl %ecx, -0x430(%rbp,%rax,4)
movq -0x440(%rbp), %rax
movb %al, %dl
movq -0x20(%rbp), %rax
movslq -0x434(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x8cf13
movq -0x440(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x440(%rbp)
jmp 0x8cebd
movl -0x434(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movl -0x434(%rbp), %eax
addl $0x1, %eax
cltq
movq %rax, -0x448(%rbp)
cmpl $0x10, -0x434(%rbp)
jle 0x8cf5d
movq $0x0, -0x8(%rbp)
jmp 0x8d765
movq -0x18(%rbp), %rdi
addq $0x1, %rdi
callq 0x4650
movq %rax, -0x450(%rbp)
cmpq $0x0, -0x450(%rbp)
jne 0x8cf88
movq $0x0, -0x8(%rbp)
jmp 0x8d765
cmpl $0x4, -0x434(%rbp)
jle 0x8cf9d
movl $0x2, -0x454(%rbp)
jmp 0x8cfd5
cmpl $0x2, -0x434(%rbp)
jle 0x8cfb2
movl $0x4, -0x454(%rbp)
jmp 0x8cfd3
cmpl $0x1, -0x434(%rbp)
jle 0x8cfc7
movl $0x8, -0x454(%rbp)
jmp 0x8cfd1
movl $0x0, -0x454(%rbp)
jmp 0x8cfd3
jmp 0x8cfd5
movl -0x448(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq $0x0, -0x448(%rbp)
movl -0x454(%rbp), %eax
movq %rax, -0x470(%rbp)
subq $0x8, %rax
ja 0x8d75d
movq -0x470(%rbp), %rax
leaq 0x69397(%rip), %rcx     # 0xf63a8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq $0x0, -0x440(%rbp)
movq -0x440(%rbp), %rax
movq -0x18(%rbp), %rcx
andq $-0x2, %rcx
cmpq %rcx, %rax
jae 0x8d0a3
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %eax
shll $0x0, %eax
movq -0x10(%rbp), %rcx
movq -0x440(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
movl -0x430(%rbp,%rcx,4), %ecx
shll $0x4, %ecx
orl %ecx, %eax
movb %al, %dl
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x448(%rbp)
movb %dl, (%rax,%rcx)
movq -0x440(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x440(%rbp)
jmp 0x8d025
movq -0x18(%rbp), %rax
movq -0x440(%rbp), %rcx
subq %rcx, %rax
subq $0x1, %rax
jne 0x8d0f0
jmp 0x8d0b9
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %eax
movb %al, %dl
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x448(%rbp)
movb %dl, (%rax,%rcx)
movq -0x448(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x450(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x8d765
movq $0x0, -0x440(%rbp)
movq -0x440(%rbp), %rax
movq -0x18(%rbp), %rcx
andq $-0x4, %rcx
cmpq %rcx, %rax
jae 0x8d1d6
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %eax
shll $0x0, %eax
movq -0x10(%rbp), %rcx
movq -0x440(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
movl -0x430(%rbp,%rcx,4), %ecx
shll $0x2, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movq -0x440(%rbp), %rdx
movzbl 0x2(%rcx,%rdx), %ecx
movl -0x430(%rbp,%rcx,4), %ecx
shll $0x4, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movq -0x440(%rbp), %rdx
movzbl 0x3(%rcx,%rdx), %ecx
movl -0x430(%rbp,%rcx,4), %ecx
shll $0x6, %ecx
orl %ecx, %eax
movb %al, %dl
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x448(%rbp)
movb %dl, (%rax,%rcx)
movq -0x440(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x440(%rbp)
jmp 0x8d119
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x18(%rbp), %eax
movl -0x440(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x458(%rbp)
movl $0x0, -0x45c(%rbp)
movl -0x458(%rbp), %eax
movl %eax, -0x474(%rbp)
subl $0x1, %eax
je 0x8d2dc
jmp 0x8d21a
movl -0x474(%rbp), %eax
subl $0x2, %eax
je 0x8d28a
jmp 0x8d227
movl -0x474(%rbp), %eax
subl $0x3, %eax
jne 0x8d340
jmp 0x8d238
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x440(%rbp)
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %esi
movl -0x45c(%rbp), %ecx
shll %cl, %esi
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movl -0x45c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x45c(%rbp)
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x440(%rbp)
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %esi
movl -0x45c(%rbp), %ecx
shll %cl, %esi
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movl -0x45c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x45c(%rbp)
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x440(%rbp)
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %esi
movl -0x45c(%rbp), %ecx
shll %cl, %esi
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movl -0x45c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x45c(%rbp)
movq -0x448(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x448(%rbp)
movq -0x448(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x450(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x8d765
movq $0x0, -0x440(%rbp)
movq -0x440(%rbp), %rax
movq -0x18(%rbp), %rcx
andq $-0x8, %rcx
cmpq %rcx, %rax
jae 0x8d495
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %eax
shll $0x0, %eax
movq -0x10(%rbp), %rcx
movq -0x440(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
movl -0x430(%rbp,%rcx,4), %ecx
shll %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movq -0x440(%rbp), %rdx
movzbl 0x2(%rcx,%rdx), %ecx
movl -0x430(%rbp,%rcx,4), %ecx
shll $0x2, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movq -0x440(%rbp), %rdx
movzbl 0x3(%rcx,%rdx), %ecx
movl -0x430(%rbp,%rcx,4), %ecx
shll $0x3, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movq -0x440(%rbp), %rdx
movzbl 0x4(%rcx,%rdx), %ecx
movl -0x430(%rbp,%rcx,4), %ecx
shll $0x4, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movq -0x440(%rbp), %rdx
movzbl 0x5(%rcx,%rdx), %ecx
movl -0x430(%rbp,%rcx,4), %ecx
shll $0x5, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movq -0x440(%rbp), %rdx
movzbl 0x6(%rcx,%rdx), %ecx
movl -0x430(%rbp,%rcx,4), %ecx
shll $0x6, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movq -0x440(%rbp), %rdx
movzbl 0x7(%rcx,%rdx), %ecx
movl -0x430(%rbp,%rcx,4), %ecx
shll $0x7, %ecx
orl %ecx, %eax
movb %al, %dl
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x448(%rbp)
movb %dl, (%rax,%rcx)
movq -0x440(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x440(%rbp)
jmp 0x8d369
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x18(%rbp), %eax
movl -0x440(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x460(%rbp)
movl $0x0, -0x464(%rbp)
movl -0x460(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x480(%rbp)
subl $0x6, %eax
ja 0x8d727
movq -0x480(%rbp), %rax
leaq 0x68ee2(%rip), %rcx     # 0xf63cc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x440(%rbp)
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %esi
movl -0x464(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
shll %cl, %esi
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x440(%rbp)
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %esi
movl -0x464(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
shll %cl, %esi
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x440(%rbp)
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %esi
movl -0x464(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
shll %cl, %esi
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x440(%rbp)
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %esi
movl -0x464(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
shll %cl, %esi
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x440(%rbp)
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %esi
movl -0x464(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
shll %cl, %esi
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x440(%rbp)
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %esi
movl -0x464(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
shll %cl, %esi
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq -0x440(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x440(%rbp)
movzbl (%rax,%rcx), %eax
movl -0x430(%rbp,%rax,4), %esi
movl -0x464(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
shll %cl, %esi
movq -0x450(%rbp), %rax
movq -0x448(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x448(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x448(%rbp)
movq -0x448(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x450(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x8d765
movq -0x448(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x450(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x8d765
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x480, %rsp            # imm = 0x480
popq %rbp
retq
nopw %cs:(%rax,%rax)