// File: /workspace/github_cpp_makefile_star2_O2/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
imulq $0x6, %rax, %rdi
addq $0x10, %rdi
callq 0x46f0
testq %rax, %rax
je 0x3d97e
testq %r12, %r12
movq %rax, (%rsp)
je 0x3d987
movq %r12, %rdi
callq 0x4210
movq %rax, %r14
movl $0x400, %ebp            # imm = 0x400
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rdi
leaq (%rdi,%r14), %rcx
cmpq %rcx, %rax
ja 0x3d961
movq %rax, %xmm0
punpckldq 0x6084(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x608c(%rip), %xmm0     # 0x439a0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x70b8(%rip), %xmm1     # 0x449e0
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x5fe0(%rip), %xmm1     # 0x43918
cvttsd2si %xmm1, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %rbp, %rsi
movq %rsi, 0x28(%rbx)
movq 0x20(%rbx), %rdi
callq 0x48c0
movq %rax, 0x20(%rbx)
jmp 0x3d8ee
addq 0x20(%rbx), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x4420
addq %r14, 0x30(%rbx)
movl 0x38(%r15), %edx
movq (%rsp), %rax
jmp 0x3d98d
pushq $-0x1
popq %r15
jmp 0x3ddb5
xorl %r14d, %r14d
movq %rbp, %rdx
pushq $0x2
popq %r11
pushq $0x3
popq %rcx
pushq $0x4
popq %r12
pushq $0x5
popq %rsi
cmpl $0x7f, %edx
ja 0x3d9aa
movb %dl, (%rax)
pushq $0x1
popq %rbp
jmp 0x3da3b
movl %edx, %edi
cmpl $0x3fff, %edx           # imm = 0x3FFF
ja 0x3d9c6
shrl $0x8, %edi
orb $-0x80, %dil
movb %dil, (%rax)
movb %dl, 0x1(%rax)
movq %r11, %rbp
jmp 0x3da3b
cmpl $0x1fffff, %edx         # imm = 0x1FFFFF
ja 0x3d9e3
shrl $0x10, %edi
orb $-0x40, %dil
movb %dil, (%rax)
movb %dh, 0x1(%rax)
movb %dl, 0x2(%rax)
movq %rcx, %rbp
jmp 0x3da3b
cmpl $0xfffffff, %edx        # imm = 0xFFFFFFF
ja 0x3da09
shrl $0x18, %edi
orb $-0x20, %dil
movb %dil, (%rax)
movl %edx, %edi
shrl $0x10, %edi
movb %dil, 0x1(%rax)
movb %dh, 0x2(%rax)
movb %dl, 0x3(%rax)
movq %r12, %rbp
jmp 0x3da3b
shrl $0x1c, %edi
orb $-0x10, %dil
movb %dil, (%rax)
movl %edx, %edi
shrl $0x14, %edi
movb %dil, 0x1(%rax)
movl %edx, %edi
shrl $0xc, %edi
movb %dil, 0x2(%rax)
movl %edx, %edi
shrl $0x4, %edi
movb %dil, 0x3(%rax)
movl %edx, %edi
andb $0xf, %dil
movb %dil, 0x4(%rax)
movq %rsi, %rbp
pushq $0x1
popq %rdi
addq %rax, %rbp
xorl %r8d, %r8d
testl %edx, %edx
movl $0x0, %r9d
cmovgl %edx, %r9d
shlq $0x4, %r9
cmpq %r8, %r9
je 0x3db4a
movl (%r13,%r8), %r10d
cmpl $0x7f, %r10d
ja 0x3da74
movb %r10b, (%rbp)
movq %rdi, %r10
jmp 0x3db3e
cmpl $0x3fff, %r10d          # imm = 0x3FFF
ja 0x3da9a
shrl $0x8, %r10d
orb $-0x80, %r10b
movb %r10b, (%rbp)
movb (%r13,%r8), %r10b
movb %r10b, 0x1(%rbp)
movq %r11, %r10
jmp 0x3db3e
cmpl $0x1fffff, %r10d        # imm = 0x1FFFFF
ja 0x3dac6
shrl $0x10, %r10d
orb $-0x40, %r10b
movb %r10b, (%rbp)
movb 0x1(%r13,%r8), %r10b
movb %r10b, 0x1(%rbp)
movb (%r13,%r8), %r10b
movb %r10b, 0x2(%rbp)
movq %rcx, %r10
jmp 0x3db3e
cmpl $0xfffffff, %r10d       # imm = 0xFFFFFFF
ja 0x3dafb
shrl $0x18, %r10d
orb $-0x20, %r10b
movb %r10b, (%rbp)
movb 0x2(%r13,%r8), %r10b
movb %r10b, 0x1(%rbp)
movb 0x1(%r13,%r8), %r10b
movb %r10b, 0x2(%rbp)
movb (%r13,%r8), %r10b
movb %r10b, 0x3(%rbp)
movq %r12, %r10
jmp 0x3db3e
shrl $0x1c, %r10d
orb $-0x10, %r10b
movb %r10b, (%rbp)
movl (%r13,%r8), %r10d
shrl $0x14, %r10d
movb %r10b, 0x1(%rbp)
movl (%r13,%r8), %r10d
shrl $0xc, %r10d
movb %r10b, 0x2(%rbp)
movl (%r13,%r8), %r10d
shrl $0x4, %r10d
movb %r10b, 0x3(%rbp)
movb (%r13,%r8), %r10b
andb $0xf, %r10b
movb %r10b, 0x4(%rbp)
movq %rsi, %r10
addq %r10, %rbp
addq $0x10, %r8
jmp 0x3da54
cmpl $0x7f, %edx
ja 0x3db5c
movq %rdx, %r9
movb %dl, (%rbp)
pushq $0x1
jmp 0x3dbe6
movl %edx, %eax
cmpl $0x3fff, %edx           # imm = 0x3FFF
ja 0x3db78
shrl $0x8, %eax
orb $-0x80, %al
movb %al, (%rbp)
movq %rdx, %r9
movb %dl, 0x1(%rbp)
pushq $0x2
jmp 0x3dbe6
cmpl $0x1fffff, %edx         # imm = 0x1FFFFF
ja 0x3db95
shrl $0x10, %eax
orb $-0x40, %al
movb %al, (%rbp)
movb %dh, 0x1(%rbp)
movq %rdx, %r9
movb %dl, 0x2(%rbp)
pushq $0x3
jmp 0x3dbe6
cmpl $0xfffffff, %edx        # imm = 0xFFFFFFF
ja 0x3dbba
shrl $0x18, %eax
orb $-0x20, %al
movb %al, (%rbp)
movl %edx, %eax
shrl $0x10, %eax
movb %al, 0x1(%rbp)
movb %dh, 0x2(%rbp)
movq %rdx, %r9
movb %dl, 0x3(%rbp)
pushq $0x4
jmp 0x3dbe6
shrl $0x1c, %eax
orb $-0x10, %al
movb %al, (%rbp)
movl %edx, %eax
shrl $0x14, %eax
movb %al, 0x1(%rbp)
movl %edx, %eax
shrl $0xc, %eax
movb %al, 0x2(%rbp)
movl %edx, %eax
shrl $0x4, %eax
movb %al, 0x3(%rbp)
movq %rdx, %r9
movl %edx, %eax
andb $0xf, %al
movb %al, 0x4(%rbp)
pushq $0x5
popq %rax
addq %rax, %rbp
addq $0xc, %r13
xorl %eax, %eax
pushq $0x1
popq %rcx
pushq $0x2
popq %rdx
pushq $0x3
popq %rsi
pushq $0x4
popq %rdi
pushq $0x5
popq %r8
movslq %r9d, %r9
cmpq %r9, %rax
jge 0x3dcf5
movl (%r13), %r9d
cmpl $0x7f, %r9d
ja 0x3dc22
movb %r9b, (%rbp)
movq %rcx, %r9
jmp 0x3dce2
cmpl $0x3fff, %r9d           # imm = 0x3FFF
ja 0x3dc47
shrl $0x8, %r9d
orb $-0x80, %r9b
movb %r9b, (%rbp)
movb (%r13), %r9b
movb %r9b, 0x1(%rbp)
movq %rdx, %r9
jmp 0x3dce2
cmpl $0x1fffff, %r9d         # imm = 0x1FFFFF
ja 0x3dc71
shrl $0x10, %r9d
orb $-0x40, %r9b
movb %r9b, (%rbp)
movb 0x1(%r13), %r9b
movb %r9b, 0x1(%rbp)
movb (%r13), %r9b
movb %r9b, 0x2(%rbp)
movq %rsi, %r9
jmp 0x3dce2
cmpl $0xfffffff, %r9d        # imm = 0xFFFFFFF
ja 0x3dca3
shrl $0x18, %r9d
orb $-0x20, %r9b
movb %r9b, (%rbp)
movb 0x2(%r13), %r9b
movb %r9b, 0x1(%rbp)
movb 0x1(%r13), %r9b
movb %r9b, 0x2(%rbp)
movb (%r13), %r9b
movb %r9b, 0x3(%rbp)
movq %rdi, %r9
jmp 0x3dce2
shrl $0x1c, %r9d
orb $-0x10, %r9b
movb %r9b, (%rbp)
movl (%r13), %r9d
shrl $0x14, %r9d
movb %r9b, 0x1(%rbp)
movl (%r13), %r9d
shrl $0xc, %r9d
movb %r9b, 0x2(%rbp)
movl (%r13), %r9d
shrl $0x4, %r9d
movb %r9b, 0x3(%rbp)
movb (%r13), %r9b
andb $0xf, %r9b
movb %r9b, 0x4(%rbp)
movq %r8, %r9
addq %r9, %rbp
incq %rax
movl 0x38(%r15), %r9d
addq $0x10, %r13
jmp 0x3dc00
movl (%r15), %esi
movq %rbx, %rdi
callq 0x27684
movl %eax, %r15d
subq (%rsp), %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x27684
movl %eax, %r12d
movl $0x400, %r13d           # imm = 0x400
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rdi
leaq (%rdi,%rbp), %rcx
cmpq %rcx, %rax
ja 0x3dd8d
movq %rax, %xmm0
punpckldq 0x5c58(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x5c60(%rip), %xmm0     # 0x439a0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x6c8c(%rip), %xmm1     # 0x449e0
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x5bb4(%rip), %xmm1     # 0x43918
cvttsd2si %xmm1, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %r13, %rsi
movq %rsi, 0x28(%rbx)
movq 0x20(%rbx), %rdi
callq 0x48c0
movq %rax, 0x20(%rbx)
jmp 0x3dd1a
addq 0x20(%rbx), %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 0x4600
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq