// File: karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_huffman_encode_char
int cram_huffman_encode_char(cram_slice *slice, cram_codec *c,
			     char *in, int in_size) {
    int i, code, len, r = 0;
    unsigned char *syms = (unsigned char *)in;

    while (in_size--) {
	int sym = *syms++;
	if (sym >= -1 && sym < MAX_HUFF) {
	    i = c->e_huffman.val2code[sym+1];
	    assert(c->e_huffman.codes[i].symbol == sym);
	    code = c->e_huffman.codes[i].code;
	    len  = c->e_huffman.codes[i].len;
	} else {
	    /* Slow - use a lookup table for when sym < MAX_HUFF? */
	    for (i = 0; i < c->e_huffman.nvals; i++) {
		if (c->e_huffman.codes[i].symbol == sym)
		    break;
	    }
	    if (i == c->e_huffman.nvals)
		return -1;
    
	    code = c->e_huffman.codes[i].code;
	    len  = c->e_huffman.codes[i].len;
	}

	r |= store_bits_MSB(c->out, code, len);
    }

    return r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x24(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x24(%rbp)
cmpl $0x0, %eax
je 0x7156d
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movzbl (%rax), %eax
movl %eax, -0x44(%rbp)
cmpl $-0x1, -0x44(%rbp)
jl 0x714cc
cmpl $0x80, -0x44(%rbp)
jge 0x714cc
movq -0x18(%rbp), %rax
movl -0x44(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl 0x3c(%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x44(%rbp), %eax
jne 0x71476
jmp 0x71495
leaq 0xd6d7(%rip), %rdi      # 0x7eb54
leaq 0xd607(%rip), %rsi      # 0x7ea8b
movl $0x429, %edx            # imm = 0x429
leaq 0xd6e8(%rip), %rcx      # 0x7eb78
callq 0x4360
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x7154f
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jge 0x71508
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x44(%rbp), %eax
jne 0x714fb
jmp 0x71508
jmp 0x714fd
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x714d3
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jne 0x7151d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x71573
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x2c(%rbp), %esi
movl -0x30(%rbp), %edx
callq 0x6fc40
orl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x71406
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)