// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/cram/cram_codecs.c
// Function: cram_beta_encode_init
cram_codec *cram_beta_encode_init(cram_stats *st,
				  enum cram_external_type option,
				  void *dat,
				  int version) {
    cram_codec *c;
    int min_val, max_val, len = 0;

    c = malloc(sizeof(*c));
    if (!c)
	return NULL;
    c->codec  = E_BETA;
    c->free   = cram_beta_encode_free;
    if (option == E_INT)
	c->encode = cram_beta_encode_int;
    else
	c->encode = cram_beta_encode_char;
    c->store  = cram_beta_encode_store;

    if (dat) {
	min_val = ((int *)dat)[0];
	max_val = ((int *)dat)[1];
    } else {
	min_val = INT_MAX;
	max_val = INT_MIN;
	int i;
	for (i = 0; i < MAX_STAT_VAL; i++) {
	    if (!st->freqs[i])
		continue;
	    if (min_val > i)
		min_val = i;
	    max_val = i;
	}
	if (st->h) {
	    khint_t k;

	    for (k = kh_begin(st->h); k != kh_end(st->h); k++) {
		if (!kh_exist(st->h, k))
		    continue;
	    
		i = kh_key(st->h, k);
		if (min_val > i)
		    min_val = i;
		if (max_val < i)
		    max_val = i;
	    }
	}
    }

    assert(max_val >= min_val);
    c->e_beta.offset = -min_val;
    max_val -= min_val;
    while (max_val) {
	len++;
	max_val >>= 1;
    }
    c->e_beta.nbits = len;

    return c;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x240, %edi            # imm = 0x240
callq 0x69c0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xcf2ff
movq $0x0, -0x8(%rbp)
jmp 0xcf4c5
movq -0x30(%rbp), %rax
movl $0x6, (%rax)
movq -0x30(%rbp), %rax
leaq -0x84(%rip), %rcx       # 0xcf290
movq %rcx, 0x10(%rax)
cmpl $0x1, -0x14(%rbp)
jne 0xcf32f
movq -0x30(%rbp), %rax
leaq -0x409(%rip), %rcx      # 0xcef20
movq %rcx, 0x20(%rax)
jmp 0xcf33e
movq -0x30(%rbp), %rax
leaq -0x12a(%rip), %rcx      # 0xcf210
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
leaq -0x6e9(%rip), %rcx      # 0xcec60
movq %rcx, 0x28(%rax)
cmpq $0x0, -0x20(%rbp)
je 0xcf36c
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0xcf45a
movl $0x7fffffff, -0x34(%rbp) # imm = 0x7FFFFFFF
movl $0x80000000, -0x38(%rbp) # imm = 0x80000000
movl $0x0, -0x40(%rbp)
cmpl $0x400, -0x40(%rbp)     # imm = 0x400
jge 0xcf3b9
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0xcf39a
jmp 0xcf3ae
movl -0x34(%rbp), %eax
cmpl -0x40(%rbp), %eax
jle 0xcf3a8
movl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xcf381
movq -0x10(%rbp), %rax
cmpq $0x0, 0x1000(%rax)
je 0xcf458
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x1000(%rcx), %rcx
cmpl (%rcx), %eax
je 0xcf456
movq -0x10(%rbp), %rax
movq 0x1000(%rax), %rax
movq 0x10(%rax), %rax
movl -0x44(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0x44(%rbp), %ecx
andl $0xf, %ecx
shll %ecx
shrl %cl, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0xcf412
jmp 0xcf448
movq -0x10(%rbp), %rax
movq 0x1000(%rax), %rax
movq 0x18(%rax), %rax
movl -0x44(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x40(%rbp), %eax
jle 0xcf438
movl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0xcf446
movl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0xcf448
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xcf3d2
jmp 0xcf458
jmp 0xcf45a
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jl 0xcf464
jmp 0xcf483
leaq 0x16681(%rip), %rdi     # 0xe5aec
leaq 0x1668d(%rip), %rsi     # 0xe5aff
movl $0x293, %edx            # imm = 0x293
leaq 0x16694(%rip), %rcx     # 0xe5b12
callq 0x6450
xorl %ecx, %ecx
subl -0x34(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x30(%rax)
movl -0x34(%rbp), %ecx
movl -0x38(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0xcf4b3
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
sarl %eax
movl %eax, -0x38(%rbp)
jmp 0xcf49a
movl -0x3c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nop