// File: /workspace/github_c_makefile_star2_O1/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, 0x18(%rsp)
movq %rdi, %r12
movq 0x60(%rdi), %r15
movslq 0x68(%rdi), %r14
addq %r14, %r14
leaq (%r14,%r14,2), %rdi
addq $0x10, %rdi
callq 0x4680
movq %rax, %rbp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %rbp, %rbp
je 0x93cae
testq %rbx, %rbx
movq %rbp, 0x8(%rsp)
je 0x93a4a
movq %rbx, %rdi
callq 0x41d0
movq 0x18(%rsp), %r13
movq 0x30(%r13), %rbp
addq %rax, %rbp
movq 0x28(%r13), %rdx
cmpq %rbp, %rdx
ja 0x93a0e
movq %rax, 0x10(%rsp)
leaq 0x320(%rdx), %rcx
shrq $0x2, %rcx
leaq (%rcx,%rdx), %rax
addq $0x320, %rax            # imm = 0x320
cmpq %rbp, %rax
cmovaq %rax, %rbp
movq 0x20(%r13), %rdi
movq %rbp, %rsi
callq 0x4840
testq %rax, %rax
je 0x93ada
movq %rbp, 0x28(%r13)
movq %rax, 0x20(%r13)
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x93a35
movq 0x18(%rsp), %r13
movq 0x20(%r13), %rdi
addq 0x30(%r13), %rdi
movq %rbx, %rsi
movq %rax, %rbx
movq %rax, %rdx
callq 0x43c0
movq %rbx, %rax
addq %rbx, 0x30(%r13)
xorl %ecx, %ecx
movq 0x8(%rsp), %rbp
xorl %ebx, %ebx
testb %cl, %cl
cmovel %eax, %ebx
je 0x93a4c
jmp 0x93ca9
xorl %ebx, %ebx
leaq (%r14,%r14,2), %rax
cltq
leaq (%rax,%rbp), %r13
addq $0x10, %r13
movq 0x10(%r12), %rax
movl 0x68(%r12), %edx
movq %rbp, %rdi
movq %r13, %rsi
callq *0x38(%rax)
movl 0x270(%r12), %ecx
decl %ecx
cmpl $0x6, %ecx
ja 0x93ca9
movq %rbp, %rdx
movslq %eax, %rbp
addq %rdx, %rbp
leaq 0x1163c(%rip), %rax     # 0xa50cc
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
movl %ebx, 0x24(%rsp)
jmpq *%rcx
cmpl $0x0, 0x68(%r12)
jle 0x93b8f
xorl %ebx, %ebx
movq %r15, %r14
movq 0x10(%r12), %rax
movl (%r14), %edx
movq %rbp, %rdi
movq %r13, %rsi
callq *0x38(%rax)
cltq
addq %rax, %rbp
incq %rbx
movslq 0x68(%r12), %rax
addq $0x18, %r14
cmpq %rax, %rbx
jl 0x93aae
jmp 0x93b8f
movb $0x1, %cl
movq 0x8(%rsp), %rbp
movq 0x10(%rsp), %rax
jmp 0x93a3c
cmpl $0x0, 0x68(%r12)
jle 0x93b8f
xorl %ebx, %ebx
movq %r15, %r14
movq 0x10(%r12), %rax
movq (%r14), %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq *0x48(%rax)
cltq
addq %rax, %rbp
incq %rbx
movslq 0x68(%r12), %rax
addq $0x18, %r14
cmpq %rax, %rbx
jl 0x93afc
jmp 0x93b8f
cmpl $0x0, 0x68(%r12)
jle 0x93b8f
xorl %ebx, %ebx
movq %r15, %r14
movq 0x10(%r12), %rax
movl (%r14), %edx
movq %rbp, %rdi
movq %r13, %rsi
callq *0x40(%rax)
cltq
addq %rax, %rbp
incq %rbx
movslq 0x68(%r12), %rax
addq $0x18, %r14
cmpq %rax, %rbx
jl 0x93b32
jmp 0x93b8f
cmpl $0x0, 0x68(%r12)
jle 0x93b8f
xorl %ebx, %ebx
movq %r15, %r14
movq 0x10(%r12), %rax
movq (%r14), %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq *0x50(%rax)
cltq
addq %rax, %rbp
incq %rbx
movslq 0x68(%r12), %rax
addq $0x18, %r14
cmpq %rax, %rbx
jl 0x93b68
movq 0x10(%r12), %rax
movl 0x68(%r12), %edx
movq %rbp, %rdi
movq %r13, %rsi
callq *0x38(%rax)
movslq %eax, %rbx
addq %rbp, %rbx
cmpl $0x0, 0x68(%r12)
jle 0x93be5
addq $0x10, %r15
xorl %r14d, %r14d
movq 0x8(%rsp), %rbp
movq 0x10(%r12), %rax
movl (%r15), %edx
movq %rbx, %rdi
movq %r13, %rsi
callq *0x38(%rax)
cltq
addq %rax, %rbx
incq %r14
movslq 0x68(%r12), %rax
addq $0x18, %r15
cmpq %rax, %r14
jl 0x93bbc
jmp 0x93bea
movq 0x8(%rsp), %rbp
movq 0x10(%r12), %rax
movl (%r12), %esi
movq 0x18(%rsp), %r14
movq %r14, %rdi
callq *0x58(%rax)
movl %eax, 0x10(%rsp)
movq 0x10(%r12), %rax
movq %rbx, %r12
subq %rbp, %r12
movq %r14, %rdi
movl %r12d, %esi
callq *0x58(%rax)
movl %eax, %r13d
movq %rbp, %r15
movq 0x30(%r14), %rbp
addq %r12, %rbp
movq 0x28(%r14), %rax
cmpq %rbp, %rax
ja 0x93c65
leaq 0x320(%rax), %rcx
shrq $0x2, %rcx
addq %rcx, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %rbp, %rax
cmovaq %rax, %rbp
movq 0x20(%r14), %rdi
movq %rbp, %rsi
callq 0x4840
testq %rax, %rax
je 0x93ca9
movq %rbp, 0x28(%r14)
movq %rax, 0x20(%r14)
movq 0x8(%rsp), %r15
cmpq %r15, %rbx
je 0x93c81
movq 0x20(%r14), %rdi
addq 0x30(%r14), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x43c0
addq %r12, 0x30(%r14)
movl %r13d, %ebx
movl 0x10(%rsp), %ebp
orl %ebp, %ebx
movq %r15, %rdi
callq 0x45c0
testl %ebx, %ebx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jle 0x93cae
movl 0x24(%rsp), %eax
addl %r12d, %eax
addl %ebp, %eax
addl %r13d, %eax
jmp 0x93cae
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq