// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_codecs.c
// Function: cram_beta_encode_init
cram_codec *cram_beta_encode_init(cram_stats *st,
                                  enum cram_encoding codec,
                                  enum cram_external_type option,
                                  void *dat,
                                  int version, varint_vec *vv) {
    cram_codec *c;
    hts_pos_t min_val, max_val;
    int len = 0;
    int64_t range;

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

    if (dat) {
        min_val = ((hts_pos_t *)dat)[0];
        max_val = ((hts_pos_t *)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;
            }
        }
    }

    if (max_val < min_val)
        goto err;

    range = (int64_t) max_val - min_val;
    switch (option) {
    case E_SINT:
        if (min_val < INT_MIN || range > INT_MAX)
            goto err;
        break;

    case E_INT:
        if (max_val > UINT_MAX || range > UINT_MAX)
            goto err;
        break;

    default:
        break;
    }

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

    return c;

 err:
    free(c);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rcx, %r15
movl %edx, %ebx
movq %rdi, %r14
movl $0x880, %edi            # imm = 0x880
callq 0x4680
testq %rax, %rax
je 0x90287
movl $0x6, (%rax)
leaq -0x35(%rip), %rcx       # 0x901fd
movq %rcx, 0x20(%rax)
leal -0x1(%rbx), %ecx
cmpl $0x6, %ecx
ja 0x9024d
movl %ecx, %ecx
leaq 0x28b01(%rip), %rdx     # 0xb8d48
movq (%rdx,%rcx,8), %rcx
jmp 0x90254
leaq -0xa3(%rip), %rcx       # 0x901b1
movq %rcx, 0x30(%rax)
leaq -0x3d0(%rip), %rcx      # 0x8fe8f
movq %rcx, 0x38(%rax)
movq $0x0, 0x48(%rax)
testq %r15, %r15
je 0x902b8
movq (%r15), %rdx
movq 0x8(%r15), %rsi
movq %rsi, %rcx
subq %rdx, %rcx
jge 0x9028e
movq %rax, %rdi
callq 0x45c0
xorl %eax, %eax
jmp 0x90388
cmpl $0x1, %ebx
je 0x90351
cmpl $0x6, %ebx
jne 0x90368
cmpq $-0x80000000, %rdx      # imm = 0x80000000
jl 0x9027f
cmpq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
jle 0x90368
jmp 0x9027f
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq $-0x80000000, %rsi      # imm = 0x80000000
xorl %ecx, %ecx
movq %rdx, %rdi
cmpq %rcx, %rdx
movq %rcx, %rdx
cmovlq %rdi, %rdx
cmpl $0x0, (%r14,%rcx,4)
cmoveq %rdi, %rdx
cmovneq %rcx, %rsi
incq %rcx
cmpq $0x400, %rcx            # imm = 0x400
jne 0x902c6
movq 0x1000(%r14), %rdi
testq %rdi, %rdi
je 0x90277
movl (%rdi), %r8d
testq %r8, %r8
je 0x90277
movq 0x10(%rdi), %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
movl %r11d, %ecx
shrl $0x4, %ecx
movl (%r9,%rcx,4), %ebp
movl %r10d, %ecx
andb $0x1e, %cl
shrl %cl, %ebp
testb $0x3, %bpl
jne 0x90340
movq 0x18(%rdi), %rcx
movslq (%rcx,%r11,8), %rcx
cmpq %rcx, %rdx
cmovgeq %rcx, %rdx
cmpq %rcx, %rsi
cmovleq %rcx, %rsi
incq %r11
addl $0x2, %r10d
cmpq %r11, %r8
jne 0x90312
jmp 0x90277
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
cmpq %rdi, %rsi
jg 0x9027f
cmpq %rdi, %rcx
jg 0x9027f
negl %edx
movl %edx, 0x60(%rax)
xorl %edx, %edx
testq %rcx, %rcx
je 0x90385
movq %rcx, %rsi
incl %edx
sarq %rsi
cmpq $0x1, %rcx
movq %rsi, %rcx
ja 0x90377
movl %edx, 0x64(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq