// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
imull $0x6, 0x68(%rax), %eax
addl $0x10, %eax
movslq %eax, %rdi
callq 0x4650
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
imull $0x6, 0x68(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xea1dd
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xea536
cmpq $0x0, -0x20(%rbp)
je 0xea21a
movq -0x20(%rbp), %rdi
callq 0x41b0
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0xe2300
cmpl $0x0, %eax
jge 0xea20c
jmp 0xea52f
movq -0x60(%rbp), %rcx
movslq -0x2c(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x38(%rax), %rax
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x10(%rbp), %rcx
movl 0x68(%rcx), %edx
callq *%rax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x270(%rax)
jne 0xea2af
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x68(%rcx), %eax
jge 0xea2aa
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x48(%rax), %rax
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x40(%rbp), %rcx
movslq -0x28(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
callq *%rax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xea25b
jmp 0xea404
movq -0x10(%rbp), %rax
cmpl $0x7, 0x270(%rax)
jne 0xea317
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x68(%rcx), %eax
jge 0xea312
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x50(%rax), %rax
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x40(%rbp), %rcx
movslq -0x28(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
callq *%rax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xea2c3
jmp 0xea402
movq -0x10(%rbp), %rax
cmpl $0x1, 0x270(%rax)
je 0xea331
movq -0x10(%rbp), %rax
cmpl $0x3, 0x270(%rax)
jne 0xea38b
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x68(%rcx), %eax
jge 0xea389
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x38(%rax), %rax
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x40(%rbp), %rcx
movslq -0x28(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movl %ecx, %edx
callq *%rax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xea338
jmp 0xea400
movq -0x10(%rbp), %rax
cmpl $0x6, 0x270(%rax)
jne 0xea3f2
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x68(%rcx), %eax
jge 0xea3f0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x40(%rax), %rax
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x40(%rbp), %rcx
movslq -0x28(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movl %ecx, %edx
callq *%rax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xea39f
jmp 0xea3fe
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xea536
jmp 0xea400
jmp 0xea402
jmp 0xea404
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x38(%rax), %rax
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x10(%rbp), %rcx
movl 0x68(%rcx), %edx
callq *%rax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x68(%rcx), %eax
jge 0xea487
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x38(%rax), %rax
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x40(%rbp), %rcx
movslq -0x28(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %edx
callq *%rax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xea438
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x58(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl (%rcx), %esi
callq *%rax
movl %eax, -0x34(%rbp)
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x34(%rbp), %eax
orl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x58(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rdx
subq %rdx, %rcx
movl %ecx, %esi
callq *%rax
movl %eax, -0x34(%rbp)
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x34(%rbp), %eax
orl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rax
subq %rax, %rdx
callq 0xe2300
cmpl $0x0, %eax
jge 0xea501
jmp 0xea52f
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rax
subq %rax, %rcx
movslq -0x2c(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x2c(%rbp)
movq -0x48(%rbp), %rdi
callq 0x45a0
cmpl $0x0, -0x30(%rbp)
jle 0xea52d
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xea536
jmp 0xea52f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop