// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
movq %rcx, %r15
movl %edx, %ebx
movq %rdi, %r14
movl $0x880, %edi            # imm = 0x880
callq 0x4680
testq %rax, %rax
je 0x7046b
movl $0x6, (%rax)
leaq -0x2e(%rip), %rcx       # 0x703eb
movq %rcx, 0x20(%rax)
leal -0x1(%rbx), %ecx
cmpl $0x6, %ecx
ja 0x70434
movl %ecx, %ecx
leaq 0x2d91a(%rip), %rdx     # 0x9dd48
movq (%rdx,%rcx,8), %rcx
jmp 0x7043b
leaq -0x9b(%rip), %rcx       # 0x703a0
movq %rcx, 0x30(%rax)
leaq -0x364(%rip), %rcx      # 0x700e2
movq %rcx, 0x38(%rax)
andq $0x0, 0x48(%rax)
testq %r15, %r15
je 0x7049c
movq (%r15), %rdx
movq 0x8(%r15), %rsi
movq %rsi, %rcx
subq %rdx, %rcx
jge 0x70472
movq %rax, %rdi
callq 0x45c0
xorl %eax, %eax
jmp 0x70557
cmpl $0x1, %ebx
je 0x7052a
cmpl $0x6, %ebx
jne 0x70541
cmpq $-0x80000000, %rdx      # imm = 0x80000000
jl 0x70463
cmpq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
jle 0x70541
jmp 0x70463
movq $-0x80000000, %rsi      # imm = 0x80000000
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
cmpq $0x400, %rcx            # imm = 0x400
je 0x704cf
cmpq %rcx, %rdx
movq %rcx, %rdi
cmovlq %rdx, %rdi
cmpl $0x0, (%r14,%rcx,4)
cmovneq %rdi, %rdx
cmovneq %rcx, %rsi
incq %rcx
jmp 0x704aa
movq 0x1000(%r14), %rdi
testq %rdi, %rdi
je 0x7045b
movl (%rdi), %r8d
xorl %r9d, %r9d
xorl %r10d, %r10d
cmpq %r10, %r8
je 0x7045b
movq 0x10(%rdi), %rcx
movl %r10d, %r11d
shrl $0x4, %r11d
movl (%rcx,%r11,4), %r11d
movl %r9d, %ecx
andb $0x1e, %cl
shrl %cl, %r11d
testb $0x3, %r11b
jne 0x70521
movq 0x18(%rdi), %rcx
movslq (%rcx,%r10,8), %rcx
cmpq %rcx, %rdx
cmovgeq %rcx, %rdx
cmpq %rcx, %rsi
cmovleq %rcx, %rsi
incq %r10
addl $0x2, %r9d
jmp 0x704e4
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
cmpq %rdi, %rsi
jg 0x70463
cmpq %rdi, %rcx
jg 0x70463
negl %edx
movl %edx, 0x60(%rax)
xorl %edx, %edx
testq %rcx, %rcx
je 0x70554
incl %edx
sarq %rcx
jmp 0x70548
movl %edx, 0x64(%rax)
popq %rbx
popq %r14
popq %r15
retq