// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/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;
    cram_huffman_code *codes = c->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->e_huffman.nvals+16);
    char *tp = tmp;

    if (!tmp)
	return -1;

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

    tp += itf8_put(tp, c->e_huffman.nvals);
    for (i = 0; i < c->e_huffman.nvals; i++) {
	tp += itf8_put(tp, codes[i].symbol);
    }

    tp += itf8_put(tp, c->e_huffman.nvals);
    for (i = 0; i < c->e_huffman.nvals; i++) {
	tp += itf8_put(tp, codes[i].len);
    }

    len += itf8_put_blk(b, c->codec);
    len += itf8_put_blk(b, tp-tmp);
    BLOCK_APPEND(b, tmp, tp-tmp);
    len += tp-tmp;

    free(tmp);

    return len;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r15
movq 0x30(%rdi), %r13
movslq 0x38(%rdi), %rax
movq %rax, %rbp
leaq (%rax,%rax,2), %rax
leaq 0x10(,%rax,2), %rdi
callq 0x4700
testq %rax, %rax
je 0x4b189
movq %rax, %rcx
testq %r12, %r12
movq %rax, (%rsp)
je 0x4b194
movq %r12, %rdi
callq 0x4230
movq %rax, %r14
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rcx
movq 0x30(%rbx), %rdx
leaq (%rdx,%r14), %rsi
cmpq %rsi, %rcx
ja 0x4b16a
movl $0x400, %ebp            # imm = 0x400
movq %rcx, %xmm0
punpckldq 0x5879(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x5881(%rip), %xmm0     # 0x50990
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x693d(%rip), %xmm1     # 0x51a60
cvttsd2si %xmm1, %rdx
movq %rdx, %rdi
sarq $0x3f, %rdi
subsd 0x57d1(%rip), %xmm1     # 0x50908
cvttsd2si %xmm1, %rsi
andq %rdi, %rsi
orq %rdx, %rsi
testq %rcx, %rcx
cmoveq %rbp, %rsi
movq %rsi, 0x28(%rbx)
movq %rax, %rdi
callq 0x48d0
movq %rax, 0x20(%rbx)
movq 0x28(%rbx), %rcx
movq 0x30(%rbx), %rdx
leaq (%rdx,%r14), %rsi
cmpq %rsi, %rcx
jbe 0x4b0fa
addq %rdx, %rax
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x4420
addq %r14, 0x30(%rbx)
movl 0x38(%r15), %edx
movq (%rsp), %rcx
jmp 0x4b19a
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x4b575
xorl %r14d, %r14d
movq %rbp, %rdx
cmpl $0x7f, %edx
movq %rdx, %rsi
ja 0x4b1b5
movb %dl, (%rcx)
movl $0x1, %ebp
addq %rcx, %rbp
testl %edx, %edx
jg 0x4b21e
jmp 0x4b2e1
movl %edx, %eax
cmpl $0x3fff, %edx           # imm = 0x3FFF
ja 0x4b1d2
shrl $0x8, %eax
orb $-0x80, %al
movb %al, (%rcx)
movl $0x2, %ebp
movl $0x1, %eax
jmp 0x4b218
cmpl $0x1fffff, %edx         # imm = 0x1FFFFF
ja 0x4b1f0
shrl $0x10, %eax
orb $-0x40, %al
movb %al, (%rcx)
movb %dh, 0x1(%rcx)
movl $0x3, %ebp
movl $0x2, %eax
jmp 0x4b218
cmpl $0xfffffff, %edx        # imm = 0xFFFFFFF
ja 0x4b35a
shrl $0x18, %eax
orb $-0x20, %al
movb %al, (%rcx)
movl %edx, %eax
shrl $0x10, %eax
movb %al, 0x1(%rcx)
movb %dh, 0x2(%rcx)
movl $0x4, %ebp
movl $0x3, %eax
movb %dl, (%rcx,%rax)
addq %rcx, %rbp
movq %rsi, %rax
movl %eax, %eax
movq %r13, %rcx
movl (%rcx), %edx
cmpl $0x7f, %edx
ja 0x4b23a
movb %dl, (%rbp)
movl $0x1, %edx
jmp 0x4b2d1
cmpl $0x3fff, %edx           # imm = 0x3FFF
ja 0x4b257
shrl $0x8, %edx
orb $-0x80, %dl
movb %dl, (%rbp)
movb (%rcx), %dl
movb %dl, 0x1(%rbp)
movl $0x2, %edx
jmp 0x4b2d1
cmpl $0x1fffff, %edx         # imm = 0x1FFFFF
ja 0x4b27a
shrl $0x10, %edx
orb $-0x40, %dl
movb %dl, (%rbp)
movb 0x1(%rcx), %dl
movb %dl, 0x1(%rbp)
movb (%rcx), %dl
movb %dl, 0x2(%rbp)
movl $0x3, %edx
jmp 0x4b2d1
cmpl $0xfffffff, %edx        # imm = 0xFFFFFFF
ja 0x4b2a3
shrl $0x18, %edx
orb $-0x20, %dl
movb %dl, (%rbp)
movb 0x2(%rcx), %dl
movb %dl, 0x1(%rbp)
movb 0x1(%rcx), %dl
movb %dl, 0x2(%rbp)
movb (%rcx), %dl
movb %dl, 0x3(%rbp)
movl $0x4, %edx
jmp 0x4b2d1
shrl $0x1c, %edx
orb $-0x10, %dl
movb %dl, (%rbp)
movl (%rcx), %edx
shrl $0x14, %edx
movb %dl, 0x1(%rbp)
movl (%rcx), %edx
shrl $0xc, %edx
movb %dl, 0x2(%rbp)
movl (%rcx), %edx
shrl $0x4, %edx
movb %dl, 0x3(%rbp)
movb (%rcx), %dl
andb $0xf, %dl
movb %dl, 0x4(%rbp)
movl $0x5, %edx
addq %rdx, %rbp
addq $0x10, %rcx
decq %rax
jne 0x4b226
movq %rsi, %rcx
cmpl $0x7f, %ecx
ja 0x4b2f6
movb %cl, (%rbp)
movl $0x1, %eax
jmp 0x4b3b5
movl %ecx, %eax
cmpl $0x3fff, %ecx           # imm = 0x3FFF
ja 0x4b315
shrl $0x8, %eax
orb $-0x80, %al
movb %al, (%rbp)
movb %cl, 0x1(%rbp)
movl $0x2, %eax
jmp 0x4b3b5
cmpl $0x1fffff, %ecx         # imm = 0x1FFFFF
ja 0x4b335
shrl $0x10, %eax
orb $-0x40, %al
movb %al, (%rbp)
movb %ch, 0x1(%rbp)
movb %cl, 0x2(%rbp)
movl $0x3, %eax
jmp 0x4b3b5
cmpl $0xfffffff, %ecx        # imm = 0xFFFFFFF
ja 0x4b38a
shrl $0x18, %eax
orb $-0x20, %al
movb %al, (%rbp)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x1(%rbp)
movb %ch, 0x2(%rbp)
movb %cl, 0x3(%rbp)
movl $0x4, %eax
jmp 0x4b3b5
shrl $0x1c, %eax
orb $-0x10, %al
movb %al, (%rcx)
movl %edx, %eax
shrl $0x14, %eax
movb %al, 0x1(%rcx)
movl %edx, %eax
shrl $0xc, %eax
movb %al, 0x2(%rcx)
movl %edx, %eax
shrl $0x4, %eax
movb %al, 0x3(%rcx)
movl %edx, %eax
andb $0xf, %al
movb %al, 0x4(%rcx)
movl $0x5, %ebp
jmp 0x4b1a9
shrl $0x1c, %eax
orb $-0x10, %al
movb %al, (%rbp)
movl %ecx, %eax
shrl $0x14, %eax
movb %al, 0x1(%rbp)
movl %ecx, %eax
shrl $0xc, %eax
movb %al, 0x2(%rbp)
movl %ecx, %eax
shrl $0x4, %eax
movb %al, 0x3(%rbp)
andb $0xf, %cl
movb %cl, 0x4(%rbp)
movl $0x5, %eax
addq %rax, %rbp
cmpl $0x0, 0x38(%r15)
jle 0x4b4a1
addq $0xc, %r13
xorl %eax, %eax
movl (%r13), %ecx
cmpl $0x7f, %ecx
ja 0x4b3df
movb %cl, (%rbp)
movl $0x1, %ecx
jmp 0x4b48a
cmpl $0x3fff, %ecx           # imm = 0x3FFF
ja 0x4b401
shrl $0x8, %ecx
orb $-0x80, %cl
movb %cl, (%rbp)
movb (%r13), %cl
movb %cl, 0x1(%rbp)
movl $0x2, %ecx
jmp 0x4b48a
cmpl $0x1fffff, %ecx         # imm = 0x1FFFFF
ja 0x4b427
shrl $0x10, %ecx
orb $-0x40, %cl
movb %cl, (%rbp)
movb 0x1(%r13), %cl
movb %cl, 0x1(%rbp)
movb (%r13), %cl
movb %cl, 0x2(%rbp)
movl $0x3, %ecx
jmp 0x4b48a
cmpl $0xfffffff, %ecx        # imm = 0xFFFFFFF
ja 0x4b454
shrl $0x18, %ecx
orb $-0x20, %cl
movb %cl, (%rbp)
movb 0x2(%r13), %cl
movb %cl, 0x1(%rbp)
movb 0x1(%r13), %cl
movb %cl, 0x2(%rbp)
movb (%r13), %cl
movb %cl, 0x3(%rbp)
movl $0x4, %ecx
jmp 0x4b48a
shrl $0x1c, %ecx
orb $-0x10, %cl
movb %cl, (%rbp)
movl (%r13), %ecx
shrl $0x14, %ecx
movb %cl, 0x1(%rbp)
movl (%r13), %ecx
shrl $0xc, %ecx
movb %cl, 0x2(%rbp)
movl (%r13), %ecx
shrl $0x4, %ecx
movb %cl, 0x3(%rbp)
movb (%r13), %cl
andb $0xf, %cl
movb %cl, 0x4(%rbp)
movl $0x5, %ecx
addq %rcx, %rbp
incq %rax
movslq 0x38(%r15), %rcx
addq $0x10, %r13
cmpq %rcx, %rax
jl 0x4b3c9
movl (%r15), %esi
movq %rbx, %rdi
callq 0x3150c
movl %eax, %r15d
subq (%rsp), %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3150c
movl %eax, %r12d
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rcx
movq 0x30(%rbx), %rdx
leaq (%rdx,%rbp), %rsi
cmpq %rsi, %rcx
ja 0x4b54b
movl $0x400, %r13d           # imm = 0x400
movq %rcx, %xmm0
punpckldq 0x5498(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x54a0(%rip), %xmm0     # 0x50990
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x655c(%rip), %xmm1     # 0x51a60
cvttsd2si %xmm1, %rdx
movq %rdx, %rdi
sarq $0x3f, %rdi
subsd 0x53f0(%rip), %xmm1     # 0x50908
cvttsd2si %xmm1, %rsi
andq %rdi, %rsi
orq %rdx, %rsi
testq %rcx, %rcx
cmoveq %r13, %rsi
movq %rsi, 0x28(%rbx)
movq %rax, %rdi
callq 0x48d0
movq %rax, 0x20(%rbx)
movq 0x28(%rbx), %rcx
movq 0x30(%rbx), %rdx
leaq (%rdx,%rbp), %rsi
cmpq %rsi, %rcx
jbe 0x4b4db
addq %rdx, %rax
movq %rax, %rdi
movq (%rsp), %r13
movq %r13, %rsi
movq %rbp, %rdx
callq 0x4420
addq %rbp, 0x30(%rbx)
addl %ebp, %r14d
addl %r12d, %r15d
addl %r14d, %r15d
movq %r13, %rdi
callq 0x4610
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq