// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x880, %edi            # imm = 0x880
callq 0x4650
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0xe47f7
movq $0x0, -0x8(%rbp)
jmp 0xe4a5f
movq -0x38(%rbp), %rax
movl $0x6, (%rax)
movq -0x38(%rbp), %rax
leaq -0x8c(%rip), %rcx       # 0xe4780
movq %rcx, 0x20(%rax)
cmpl $0x1, -0x18(%rbp)
je 0xe481c
cmpl $0x6, -0x18(%rbp)
jne 0xe482d
movq -0x38(%rbp), %rax
leaq -0x1a7(%rip), %rcx      # 0xe4680
movq %rcx, 0x30(%rax)
jmp 0xe485b
cmpl $0x2, -0x18(%rbp)
je 0xe4839
cmpl $0x7, -0x18(%rbp)
jne 0xe484a
movq -0x38(%rbp), %rax
leaq -0x4d4(%rip), %rcx      # 0xe4370
movq %rcx, 0x30(%rax)
jmp 0xe4859
movq -0x38(%rbp), %rax
leaq -0x155(%rip), %rcx      # 0xe4700
movq %rcx, 0x30(%rax)
jmp 0xe485b
movq -0x38(%rbp), %rax
leaq -0x666(%rip), %rcx      # 0xe4200
movq %rcx, 0x38(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x48(%rax)
cmpq $0x0, -0x20(%rbp)
je 0xe4899
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0xe49a5
movq $0x7fffffff, -0x40(%rbp) # imm = 0x7FFFFFFF
movq $-0x80000000, -0x48(%rbp) # imm = 0x80000000
movl $0x0, -0x5c(%rbp)
cmpl $0x400, -0x5c(%rbp)     # imm = 0x400
jge 0xe48f1
movq -0x10(%rbp), %rax
movslq -0x5c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0xe48c9
jmp 0xe48e6
movq -0x40(%rbp), %rax
movslq -0x5c(%rbp), %rcx
cmpq %rcx, %rax
jle 0xe48de
movslq -0x5c(%rbp), %rax
movq %rax, -0x40(%rbp)
movslq -0x5c(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xe48b0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x1000(%rax)
je 0xe49a3
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x1000(%rcx), %rcx
cmpl (%rcx), %eax
je 0xe49a1
movq -0x10(%rbp), %rax
movq 0x1000(%rax), %rax
movq 0x10(%rax), %rax
movl -0x60(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0x60(%rbp), %ecx
andl $0xf, %ecx
shll %ecx
shrl %cl, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0xe494e
jmp 0xe4993
movq -0x10(%rbp), %rax
movq 0x1000(%rax), %rax
movq 0x18(%rax), %rax
movl -0x60(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x5c(%rbp)
movq -0x40(%rbp), %rax
movslq -0x5c(%rbp), %rcx
cmpq %rcx, %rax
jle 0xe497c
movslq -0x5c(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
movslq -0x5c(%rbp), %rcx
cmpq %rcx, %rax
jge 0xe4991
movslq -0x5c(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0xe4993
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0xe490a
jmp 0xe49a3
jmp 0xe49a5
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jge 0xe49b4
jmp 0xe4a4e
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x58(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x64(%rbp)
subl $0x1, %eax
je 0xe49f2
jmp 0xe49d0
movl -0x64(%rbp), %eax
subl $0x6, %eax
jne 0xe4a0c
jmp 0xe49da
cmpq $-0x80000000, -0x40(%rbp) # imm = 0x80000000
jl 0xe49ee
cmpq $0x7fffffff, -0x58(%rbp) # imm = 0x7FFFFFFF
jle 0xe49f0
jmp 0xe4a4e
jmp 0xe4a0e
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x48(%rbp)
jg 0xe4a08
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x58(%rbp)
jle 0xe4a0a
jmp 0xe4a4e
jmp 0xe4a0e
jmp 0xe4a0e
xorl %eax, %eax
subq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x60(%rax)
cmpq $0x0, -0x58(%rbp)
je 0xe4a3a
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x58(%rbp), %rax
sarq %rax
movq %rax, -0x58(%rbp)
jmp 0xe4a1d
movl -0x4c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x64(%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xe4a5f
movq -0x38(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)