// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %rsp
movq %rdx, %r15
movq %rsi, 0x8(%rsp)
movq %rdi, %r13
movq 0x60(%rdi), %r14
movslq 0x68(%rdi), %rbx
imulq $0x6, %rbx, %rbp
leaq 0x10(%rbp), %rdi
callq 0x4680
pushq $-0x1
popq %r12
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x73623
testq %r15, %r15
je 0x73479
movq %r15, %rdi
callq 0x41d0
movq %rax, %rbx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x6f15a
testl %eax, %eax
js 0x73623
movq %rbx, (%rsp)
movl 0x68(%r13), %ebx
jmp 0x73481
movq $0x0, (%rsp)
movslq %ebp, %rax
movq 0x10(%rsp), %r15
leaq (%r15,%rax), %rbp
addq $0x10, %rbp
movq 0x10(%r13), %rax
movq %r15, %rdi
movq %rbp, %rsi
movl %ebx, %edx
callq *0x38(%rax)
movl 0x270(%r13), %ecx
decl %ecx
cmpl $0x6, %ecx
ja 0x73623
movslq %eax, %rbx
addq %r15, %rbx
leaq 0x10c7d(%rip), %rax     # 0x8413c
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %r15d, %r15d
movq %r14, %r12
movslq 0x68(%r13), %rdx
cmpq %rdx, %r15
jge 0x73584
movq 0x10(%r13), %rax
movl (%r12), %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq *0x38(%rax)
cltq
addq %rax, %rbx
incq %r15
addq $0x18, %r12
jmp 0x734ce
xorl %r15d, %r15d
movq %r14, %r12
movslq 0x68(%r13), %rdx
cmpq %rdx, %r15
jge 0x73584
movq 0x10(%r13), %rax
movq (%r12), %rdx
movq %rbx, %rdi
movq %rbp, %rsi
callq *0x48(%rax)
cltq
addq %rax, %rbx
incq %r15
addq $0x18, %r12
jmp 0x73500
xorl %r15d, %r15d
movq %r14, %r12
movslq 0x68(%r13), %rdx
cmpq %rdx, %r15
jge 0x73584
movq 0x10(%r13), %rax
movl (%r12), %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq *0x40(%rax)
cltq
addq %rax, %rbx
incq %r15
addq $0x18, %r12
jmp 0x7352e
xorl %r15d, %r15d
movq %r14, %r12
movslq 0x68(%r13), %rdx
cmpq %rdx, %r15
jge 0x73584
movq 0x10(%r13), %rax
movq (%r12), %rdx
movq %rbx, %rdi
movq %rbp, %rsi
callq *0x50(%rax)
cltq
addq %rax, %rbx
incq %r15
addq $0x18, %r12
jmp 0x7355c
movq 0x10(%r13), %rax
movq %rbx, %rdi
movq %rbp, %rsi
callq *0x38(%rax)
movslq %eax, %r15
addq %rbx, %r15
addq $0x10, %r14
xorl %ebx, %ebx
pushq $-0x1
popq %r12
movslq 0x68(%r13), %rcx
movq 0x10(%r13), %rax
cmpq %rcx, %rbx
jge 0x735c8
movl (%r14), %edx
movq %r15, %rdi
movq %rbp, %rsi
callq *0x38(%rax)
cltq
addq %rax, %r15
incq %rbx
addq $0x18, %r14
jmp 0x735a1
movl (%r13), %esi
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq *0x58(%rax)
movl %eax, %ebx
movq 0x10(%r13), %rax
movq 0x10(%rsp), %r13
subq %r13, %r15
movq %r14, %rdi
movl %r15d, %esi
callq *0x58(%rax)
movl %eax, %ebp
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x6f15a
testl %eax, %eax
js 0x73623
movl %ebp, %r14d
orl %ebx, %r14d
movq %r13, %rdi
callq 0x45c0
testl %r14d, %r14d
jle 0x73623
movq (%rsp), %rax
addl %r15d, %eax
addl %ebx, %eax
addl %ebp, %eax
movl %eax, %r12d
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq