// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_stats.c
// Function: cram_stats_encoding
enum cram_encoding cram_stats_encoding(cram_fd *fd, cram_stats *st) {
    int nvals, i, ntot = 0, max_val = 0, min_val = INT_MAX;
    int *vals = NULL, *freqs = NULL, vals_alloc = 0;

    //cram_stats_dump(st);

    /* Count number of unique symbols */
    for (nvals = i = 0; i < MAX_STAT_VAL; i++) {
	if (!st->freqs[i])
	    continue;
	if (nvals >= vals_alloc) {
	    vals_alloc = vals_alloc ? vals_alloc*2 : 1024;
	    vals  = realloc(vals,  vals_alloc * sizeof(int));
	    freqs = realloc(freqs, vals_alloc * sizeof(int));
	    if (!vals || !freqs) {
		if (vals)  free(vals);
		if (freqs) free(freqs);
		return E_HUFFMAN; // Cannot do much else atm
	    }
	}
	vals[nvals] = i;
	freqs[nvals] = st->freqs[i];
	ntot += freqs[nvals];
	if (max_val < i) max_val = i;
	if (min_val > i) min_val = i;
	nvals++;
    }
    if (st->h) {
	khint_t k;
	int i;

	for (k = kh_begin(st->h); k != kh_end(st->h); k++) {
	    if (!kh_exist(st->h, k))
		continue;

	    if (nvals >= vals_alloc) {
		vals_alloc = vals_alloc ? vals_alloc*2 : 1024;
		vals  = realloc(vals,  vals_alloc * sizeof(int));
		freqs = realloc(freqs, vals_alloc * sizeof(int));
		if (!vals || !freqs)
		    return E_HUFFMAN; // Cannot do much else atm
	    }
	    i = kh_key(st->h, k);
	    vals[nvals]=i;
	    freqs[nvals] = kh_val(st->h, k);
	    ntot += freqs[nvals];
	    if (max_val < i) max_val = i;
	    if (min_val > i) min_val = i;
	    nvals++;
	}
    }

    st->nvals = nvals;
    assert(ntot == st->nsamp);

    free(vals);
    free(freqs);

    /*
     * Simple policy that everything is external unless it can be
     * encoded using zero bits as a unary item huffman table.
     */
    return nvals <= 1 ? E_HUFFMAN : E_EXTERNAL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
xorl %ebx, %ebx
xorl %r15d, %r15d
xorl %r8d, %r8d
xorl %edi, %edi
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rsi, 0x10(%rsp)
cmpq $0x400, %rbx            # imm = 0x400
je 0x2f0f6
cmpl $0x0, (%rsi,%rbx,4)
je 0x2f0ee
cmpl %ebp, %r15d
jl 0x2f0db
movl %r8d, %r14d
testl %ebp, %ebp
leal (%rbp,%rbp), %eax
movl %eax, %ebp
movl $0x400, %eax            # imm = 0x400
cmovel %eax, %ebp
movq %r12, (%rsp)
movslq %ebp, %r12
shlq $0x2, %r12
movq %r12, %rsi
callq 0x48c0
movq %rax, %r13
movq (%rsp), %rdi
movq %r12, %rsi
callq 0x48c0
movq %r13, %rdi
movq %rax, %r12
testq %r13, %r13
je 0x2f1f2
testq %r12, %r12
je 0x2f1f2
movq 0x10(%rsp), %rsi
movl %r14d, %r8d
movslq %r15d, %rax
movl %ebx, (%rdi,%rax,4)
movl (%rsi,%rbx,4), %ecx
movl %ecx, (%r12,%rax,4)
addl %ecx, %r8d
incl %r15d
incq %rbx
jmp 0x2f072
movq 0x1000(%rsi), %rax
testq %rax, %rax
je 0x2f1c3
xorl %r10d, %r10d
xorl %ebx, %ebx
cmpl (%rax), %ebx
je 0x2f1c3
movq 0x10(%rax), %rcx
movl %ebx, %edx
shrl $0x4, %edx
movl (%rcx,%rdx,4), %edx
movl %r10d, %ecx
andb $0x1e, %cl
shrl %cl, %edx
testb $0x3, %dl
jne 0x2f1b8
cmpl %ebp, %r15d
jl 0x2f197
movl %r10d, 0xc(%rsp)
movl %r8d, %r14d
testl %ebp, %ebp
leal (%rbp,%rbp), %eax
movl %eax, %ebp
movl $0x400, %eax            # imm = 0x400
cmovel %eax, %ebp
movq %r12, (%rsp)
movslq %ebp, %r12
shlq $0x2, %r12
movq %r12, %rsi
callq 0x48c0
movq %rax, %r13
movq (%rsp), %rdi
movq %r12, %rsi
callq 0x48c0
testq %r13, %r13
je 0x2f1ff
movq %rax, %r12
testq %rax, %rax
je 0x2f1ff
movq %r13, %rdi
movl %r14d, %r8d
movq 0x10(%rsp), %rsi
movq 0x1000(%rsi), %rax
movl 0xc(%rsp), %r10d
movq 0x18(%rax), %rcx
movl %ebx, %edx
movl (%rcx,%rdx,4), %ecx
movslq %r15d, %r9
movl %ecx, (%rdi,%r9,4)
movq 0x20(%rax), %rcx
movl (%rcx,%rdx,4), %ecx
movl %ecx, (%r12,%r9,4)
addl %ecx, %r8d
incl %r15d
incl %ebx
addl $0x2, %r10d
jmp 0x2f10b
movl %r15d, 0x100c(%rsi)
cmpl 0x1008(%rsi), %r8d
jne 0x2f211
callq 0x4600
movq %r12, %rdi
callq 0x4600
xorl %eax, %eax
cmpl $0x2, %r15d
setl %al
leal 0x1(,%rax,2), %eax
jmp 0x2f202
callq 0x4600
movq %r12, %rdi
callq 0x4600
pushq $0x3
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1705f(%rip), %rdi     # 0x46277
leaq 0x16fe5(%rip), %rsi     # 0x46204
leaq 0x17063(%rip), %rcx     # 0x46289
movl $0xb4, %edx
callq 0x4360