// File: /workspace/github_cpp_makefile_star2_O1/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
leaq (%rax,%rax,2), %rax
leaq 0x10(,%rax,2), %rdi
callq 0x4700
testq %rax, %rax
je 0x4c228
testq %r12, %r12
movq %rax, (%rsp)
je 0x4c233
movq %r12, %rdi
callq 0x4230
movq %rax, %r14
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rdi
leaq (%rdi,%r14), %rcx
cmpq %rcx, %rax
ja 0x4c20f
movl $0x400, %ebp            # imm = 0x400
movq %rax, %xmm0
punpckldq 0x6785(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x678d(%rip), %xmm0     # 0x52940
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x7841(%rip), %xmm1     # 0x53a08
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x6731(%rip), %xmm1     # 0x52908
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 0x48d0
movq %rax, 0x20(%rbx)
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rdi
leaq (%rdi,%r14), %rcx
cmpq %rcx, %rax
jbe 0x4c19e
addq 0x20(%rbx), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x4420
addq %r14, 0x30(%rbx)
movq (%rsp), %rax
jmp 0x4c236
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x4c639
xorl %r14d, %r14d
movl 0x38(%r15), %edx
cmpq $0x7f, %rdx
ja 0x4c24c
movb %dl, (%rax)
movl $0x1, %ebp
jmp 0x4c2d7
movl %edx, %ecx
cmpl $0x3fff, %edx           # imm = 0x3FFF
ja 0x4c268
shrl $0x8, %ecx
orb $-0x80, %cl
movb %cl, (%rax)
movb %dl, 0x1(%rax)
movl $0x2, %ebp
jmp 0x4c2d7
cmpl $0x1fffff, %edx         # imm = 0x1FFFFF
ja 0x4c285
shrl $0x10, %ecx
orb $-0x40, %cl
movb %cl, (%rax)
movb %dh, 0x1(%rax)
movb %dl, 0x2(%rax)
movl $0x3, %ebp
jmp 0x4c2d7
cmpl $0xfffffff, %edx        # imm = 0xFFFFFFF
ja 0x4c2aa
shrl $0x18, %ecx
orb $-0x20, %cl
movb %cl, (%rax)
movl %edx, %ecx
shrl $0x10, %ecx
movb %cl, 0x1(%rax)
movb %dh, 0x2(%rax)
movb %dl, 0x3(%rax)
movl $0x4, %ebp
jmp 0x4c2d7
shrl $0x1c, %ecx
orb $-0x10, %cl
movb %cl, (%rax)
movl %edx, %ecx
shrl $0x14, %ecx
movb %cl, 0x1(%rax)
movl %edx, %ecx
shrl $0xc, %ecx
movb %cl, 0x2(%rax)
movl %edx, %ecx
shrl $0x4, %ecx
movb %cl, 0x3(%rax)
movl %edx, %ecx
andb $0xf, %cl
movb %cl, 0x4(%rax)
movl $0x5, %ebp
addq %rax, %rbp
testl %edx, %edx
jle 0x4c3e0
movq %rdx, %rax
movq %rdx, %rcx
shlq $0x4, %rcx
xorl %edx, %edx
movl (%r13,%rdx), %esi
cmpl $0x7f, %esi
ja 0x4c306
movb %sil, (%rbp)
movl $0x1, %esi
jmp 0x4c3ce
cmpl $0x3fff, %esi           # imm = 0x3FFF
ja 0x4c32c
shrl $0x8, %esi
orb $-0x80, %sil
movb %sil, (%rbp)
movb (%r13,%rdx), %sil
movb %sil, 0x1(%rbp)
movl $0x2, %esi
jmp 0x4c3ce
cmpl $0x1fffff, %esi         # imm = 0x1FFFFF
ja 0x4c358
shrl $0x10, %esi
orb $-0x40, %sil
movb %sil, (%rbp)
movb 0x1(%r13,%rdx), %sil
movb %sil, 0x1(%rbp)
movb (%r13,%rdx), %sil
movb %sil, 0x2(%rbp)
movl $0x3, %esi
jmp 0x4c3ce
cmpl $0xfffffff, %esi        # imm = 0xFFFFFFF
ja 0x4c38d
shrl $0x18, %esi
orb $-0x20, %sil
movb %sil, (%rbp)
movb 0x2(%r13,%rdx), %sil
movb %sil, 0x1(%rbp)
movb 0x1(%r13,%rdx), %sil
movb %sil, 0x2(%rbp)
movb (%r13,%rdx), %sil
movb %sil, 0x3(%rbp)
movl $0x4, %esi
jmp 0x4c3ce
shrl $0x1c, %esi
orb $-0x10, %sil
movb %sil, (%rbp)
movl (%r13,%rdx), %esi
shrl $0x14, %esi
movb %sil, 0x1(%rbp)
movl (%r13,%rdx), %esi
shrl $0xc, %esi
movb %sil, 0x2(%rbp)
movl (%r13,%rdx), %esi
shrl $0x4, %esi
movb %sil, 0x3(%rbp)
movb (%r13,%rdx), %sil
andb $0xf, %sil
movb %sil, 0x4(%rbp)
movl $0x5, %esi
addq %rsi, %rbp
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x4c2ee
jmp 0x4c3e3
movq %rdx, %rax
cmpl $0x7f, %eax
ja 0x4c3f5
movb %al, (%rbp)
movl $0x1, %eax
jmp 0x4c47e
movl %eax, %ecx
cmpl $0x3fff, %eax           # imm = 0x3FFF
ja 0x4c411
shrl $0x8, %ecx
orb $-0x80, %cl
movb %cl, (%rbp)
movb %al, 0x1(%rbp)
movl $0x2, %eax
jmp 0x4c47e
cmpl $0x1fffff, %eax         # imm = 0x1FFFFF
ja 0x4c42e
shrl $0x10, %ecx
orb $-0x40, %cl
movb %cl, (%rbp)
movb %ah, 0x1(%rbp)
movb %al, 0x2(%rbp)
movl $0x3, %eax
jmp 0x4c47e
cmpl $0xfffffff, %eax        # imm = 0xFFFFFFF
ja 0x4c453
shrl $0x18, %ecx
orb $-0x20, %cl
movb %cl, (%rbp)
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x1(%rbp)
movb %ah, 0x2(%rbp)
movb %al, 0x3(%rbp)
movl $0x4, %eax
jmp 0x4c47e
shrl $0x1c, %ecx
orb $-0x10, %cl
movb %cl, (%rbp)
movl %eax, %ecx
shrl $0x14, %ecx
movb %cl, 0x1(%rbp)
movl %eax, %ecx
shrl $0xc, %ecx
movb %cl, 0x2(%rbp)
movl %eax, %ecx
shrl $0x4, %ecx
movb %cl, 0x3(%rbp)
andb $0xf, %al
movb %al, 0x4(%rbp)
movl $0x5, %eax
addq %rax, %rbp
cmpl $0x0, 0x38(%r15)
jle 0x4c56a
addq $0xc, %r13
xorl %eax, %eax
movl (%r13), %ecx
cmpl $0x7f, %ecx
ja 0x4c4a8
movb %cl, (%rbp)
movl $0x1, %ecx
jmp 0x4c553
cmpl $0x3fff, %ecx           # imm = 0x3FFF
ja 0x4c4ca
shrl $0x8, %ecx
orb $-0x80, %cl
movb %cl, (%rbp)
movb (%r13), %cl
movb %cl, 0x1(%rbp)
movl $0x2, %ecx
jmp 0x4c553
cmpl $0x1fffff, %ecx         # imm = 0x1FFFFF
ja 0x4c4f0
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 0x4c553
cmpl $0xfffffff, %ecx        # imm = 0xFFFFFFF
ja 0x4c51d
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 0x4c553
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 0x4c492
movl (%r15), %esi
movq %rbx, %rdi
callq 0x32062
movl %eax, %r15d
subq (%rsp), %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x32062
movl %eax, %r12d
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rdi
leaq (%rdi,%rbp), %rcx
cmpq %rcx, %rax
ja 0x4c611
movl $0x400, %r13d           # imm = 0x400
movq %rax, %xmm0
punpckldq 0x6383(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x638b(%rip), %xmm0     # 0x52940
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x743f(%rip), %xmm1     # 0x53a08
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x632f(%rip), %xmm1     # 0x52908
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 0x48d0
movq %rax, 0x20(%rbx)
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rdi
leaq (%rdi,%rbp), %rcx
cmpq %rcx, %rax
jbe 0x4c5a0
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 0x4610
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq