// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/cram/cram_codecs.c
// Function: cram_huffman_encode_store
int cram_huffman_encode_store(cram_codec *c, cram_block *b, char *prefix,
                              int version) {
    int i, len = 0, r = 0, n;
    cram_huffman_code *codes = c->u.e_huffman.codes;
    /*
     * Up to code length 127 means 2.5e+26 bytes of data required (worst
     * case huffman tree needs symbols with freqs matching the Fibonacci
     * series). So guaranteed 1 byte per code.
     *
     * Symbols themselves could be 5 bytes (eg -1 is 5 bytes in itf8).
     *
     * Therefore 6*ncodes + 5 + 5 + 1 + 5 is max memory
     */
    char *tmp = malloc(6*c->u.e_huffman.nvals+16);
    char *tp = tmp, *tpend = tmp+6*c->u.e_huffman.nvals+16;

    if (!tmp)
        return -1;

    if (prefix) {
        size_t l = strlen(prefix);
        BLOCK_APPEND(b, prefix, l);
        len += l;
    }

    tp += c->vv->varint_put32(tp, tpend, c->u.e_huffman.nvals);
    if (c->u.e_huffman.option == E_LONG) {
        for (i = 0; i < c->u.e_huffman.nvals; i++) {
            tp += c->vv->varint_put64(tp, tpend, codes[i].symbol);
        }
    } else if (c->u.e_huffman.option == E_SLONG) {
        for (i = 0; i < c->u.e_huffman.nvals; i++) {
            tp += c->vv->varint_put64s(tp, tpend, codes[i].symbol);
        }
    } else if (c->u.e_huffman.option == E_INT || c->u.e_huffman.option == E_BYTE) {
        for (i = 0; i < c->u.e_huffman.nvals; i++) {
            tp += c->vv->varint_put32(tp, tpend, codes[i].symbol);
        }
    } else if (c->u.e_huffman.option == E_SINT) {
        for (i = 0; i < c->u.e_huffman.nvals; i++) {
            tp += c->vv->varint_put32s(tp, tpend, codes[i].symbol);
        }
    } else {
        return -1;
    }

    tp += c->vv->varint_put32(tp, tpend, c->u.e_huffman.nvals);
    for (i = 0; i < c->u.e_huffman.nvals; i++)
        tp += c->vv->varint_put32(tp, tpend, codes[i].len);

    len += (n = c->vv->varint_put32_blk(b, c->codec)); r |= n;
    len += (n = c->vv->varint_put32_blk(b, tp-tmp));   r |= n;
    BLOCK_APPEND(b, tmp, tp-tmp);
    len += tp-tmp;

    free(tmp);

    if (r > 0)
        return len;

 block_err:
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %rbx
movq %rsi, 0x20(%rsp)
movq %rdi, %r13
movq 0x60(%rdi), %rbp
movslq 0x68(%rdi), %r12
leaq (%r12,%r12), %r14
leaq (%r14,%r14,2), %rdi
addq $0x10, %rdi
callq 0x4680
movq %rax, %r15
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r15, %r15
je 0x913b3
testq %rbx, %rbx
movq %r15, 0x18(%rsp)
je 0x91142
movq %rbx, %rdi
callq 0x41d0
movq 0x20(%rsp), %r15
movq 0x30(%r15), %r12
addq %rax, %r12
movq 0x28(%r15), %rdx
cmpq %r12, %rdx
movq %rax, 0x10(%rsp)
ja 0x9110f
leaq 0x320(%rdx), %rcx
shrq $0x2, %rcx
leaq (%rcx,%rdx), %rax
addq $0x320, %rax            # imm = 0x320
cmpq %r12, %rax
cmovaq %rax, %r12
movq 0x20(%r15), %rdi
movq %r12, %rsi
callq 0x4840
testq %rax, %rax
je 0x913ae
movq %r12, 0x28(%r15)
movq %rax, 0x20(%r15)
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x91137
movq 0x20(%rsp), %r15
movq 0x20(%r15), %rdi
addq 0x30(%r15), %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
callq 0x43c0
movq 0x10(%rsp), %rax
addq %rax, 0x30(%r15)
movl 0x68(%r13), %r12d
movq 0x18(%rsp), %r15
jmp 0x9114b
movq $0x0, 0x10(%rsp)
leaq (%r14,%r14,2), %rax
cltq
leaq (%r15,%rax), %r14
addq $0x10, %r14
movq 0x10(%r13), %rax
movq %r15, %rdi
movq %r14, %rsi
movl %r12d, %edx
callq *0x38(%rax)
movl 0x270(%r13), %ecx
decl %ecx
cmpl $0x6, %ecx
ja 0x913ae
movslq %eax, %rbx
addq %r15, %rbx
leaq 0x116c4(%rip), %rax     # 0xa284c
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl 0x68(%r13), %edx
testl %edx, %edx
jle 0x9129f
movq %r14, 0x8(%rsp)
xorl %r14d, %r14d
movq %rbp, %r15
movq %rbx, %r12
movq 0x10(%r13), %rax
movl (%r15), %edx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq *0x38(%rax)
movslq %eax, %rbx
addq %r12, %rbx
incq %r14
movslq 0x68(%r13), %rdx
addq $0x18, %r15
cmpq %rdx, %r14
jl 0x911a8
jmp 0x9129a
movl 0x68(%r13), %edx
testl %edx, %edx
jle 0x9129f
movq %r14, 0x8(%rsp)
xorl %r14d, %r14d
movq %rbp, %r15
movq %rbx, %r12
movq 0x10(%r13), %rax
movq (%r15), %rdx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq *0x48(%rax)
movslq %eax, %rbx
addq %r12, %rbx
incq %r14
movslq 0x68(%r13), %rdx
addq $0x18, %r15
cmpq %rdx, %r14
jl 0x911ef
jmp 0x9129a
movl 0x68(%r13), %edx
testl %edx, %edx
jle 0x9129f
movq %r14, 0x8(%rsp)
xorl %r14d, %r14d
movq %rbp, %r15
movq %rbx, %r12
movq 0x10(%r13), %rax
movl (%r15), %edx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq *0x40(%rax)
movslq %eax, %rbx
addq %r12, %rbx
incq %r14
movslq 0x68(%r13), %rdx
addq $0x18, %r15
cmpq %rdx, %r14
jl 0x9122f
jmp 0x9129a
movl 0x68(%r13), %edx
testl %edx, %edx
jle 0x9129f
movq %r14, 0x8(%rsp)
xorl %r14d, %r14d
movq %rbp, %r15
movq %rbx, %r12
movq 0x10(%r13), %rax
movq (%r15), %rdx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq *0x50(%rax)
movslq %eax, %rbx
addq %r12, %rbx
incq %r14
movslq 0x68(%r13), %rdx
addq $0x18, %r15
cmpq %rdx, %r14
jl 0x9126f
movq 0x8(%rsp), %r14
movq 0x10(%r13), %rax
movq %rbx, %rdi
movq %r14, %r15
movq %r14, %rsi
callq *0x38(%rax)
movslq %eax, %r12
addq %rbx, %r12
cmpl $0x0, 0x68(%r13)
movq 0x20(%rsp), %r14
jle 0x912ec
addq $0x10, %rbp
xorl %ebx, %ebx
movq 0x10(%r13), %rax
movl (%rbp), %edx
movq %r12, %rdi
movq %r15, %rsi
callq *0x38(%rax)
cltq
addq %rax, %r12
incq %rbx
movslq 0x68(%r13), %rax
addq $0x18, %rbp
cmpq %rax, %rbx
jl 0x912c7
movq 0x10(%r13), %rax
movl (%r13), %esi
movq %r14, %rdi
callq *0x58(%rax)
movl %eax, 0x8(%rsp)
movq 0x10(%r13), %rax
movq %r12, %r13
movq 0x18(%rsp), %r15
subq %r15, %r13
movq %r14, %rdi
movl %r13d, %esi
callq *0x58(%rax)
movl %eax, %ebp
movq 0x30(%r14), %rbx
addq %r13, %rbx
movq 0x28(%r14), %rax
cmpq %rbx, %rax
ja 0x91361
leaq 0x320(%rax), %rcx
shrq $0x2, %rcx
addq %rcx, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %rbx, %rax
cmovaq %rax, %rbx
movq 0x20(%r14), %rdi
movq %rbx, %rsi
callq 0x4840
testq %rax, %rax
je 0x913ae
movq %rbx, 0x28(%r14)
movq %rax, 0x20(%r14)
movq 0x18(%rsp), %r15
cmpq %r15, %r12
movq %r15, %rdi
je 0x91387
movq 0x20(%r14), %rdi
addq 0x30(%r14), %rdi
movq 0x18(%rsp), %rsi
movq %r13, %rdx
callq 0x43c0
movq 0x18(%rsp), %rdi
addq %r13, 0x30(%r14)
movl %ebp, %ebx
movl 0x8(%rsp), %r14d
orl %r14d, %ebx
callq 0x45c0
testl %ebx, %ebx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jle 0x913b3
movq 0x10(%rsp), %rax
addl %r13d, %eax
addl %r14d, %eax
addl %ebp, %eax
jmp 0x913b3
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq