// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/sam.c
// Function: sam_parse_B_vals_r
HTS_ALIGN32
static int sam_parse_B_vals_r(char type, uint32_t nalloc, char *in,
                              char **end, bam1_t *b,
                              int *ctr) {
    // Protect against infinite recursion when dealing with invalid input.
    // An example string is "XX:B:C,-".  The lack of a number means min=0,
    // but it overflowed due to "-" and so we repeat ad-infinitum.
    //
    // Loop detection is the safest solution incase there are other
    // strange corner cases with malformed inputs.
    if (++(*ctr) > 2) {
        hts_log_error("Malformed data in B:%c array", type);
        return -1;
    }

    int orig_l = b->l_data;
    char *q = in;
    int32_t size;
    size_t bytes;
    int overflow = 0;

    size = aux_type2size(type);
    if (size <= 0 || size > 4) {
        hts_log_error("Unrecognized type B:%c", type);
        return -1;
    }

    // Ensure space for type + values.
    // The first pass through here we don't know the number of entries and
    // nalloc == 0.  We start with a small working set and then parse the
    // data, growing as needed.
    //
    // If we have a second pass through we do know the number of entries
    // and nalloc is already known.  We have no need to expand the bam data.
    if (!nalloc)
         nalloc=7;

    // Ensure allocated memory is big enough (for current nalloc estimate)
    bytes = (size_t) nalloc * (size_t) size;
    if (bytes / size != nalloc
        || possibly_expand_bam_data(b, bytes + 2 + sizeof(uint32_t))) {
        hts_log_error("Out of memory");
        return -1;
    }

    uint32_t nused = 0;

    b->data[b->l_data++] = 'B';
    b->data[b->l_data++] = type;
    // 32-bit B-array length is inserted later once we know it.
    int b_len_idx = b->l_data;
    b->l_data += sizeof(uint32_t);

    if (type == 'c') {
        if (!(q = sam_parse_Bc_vals(b, q, &nused, &nalloc, &overflow)))
            return -1;
    } else if (type == 'C') {
        if (!(q = sam_parse_BC_vals(b, q, &nused, &nalloc, &overflow)))
            return -1;
    } else if (type == 's') {
        if (!(q = sam_parse_Bs_vals(b, q, &nused, &nalloc, &overflow)))
            return -1;
    } else if (type == 'S') {
        if (!(q = sam_parse_BS_vals(b, q, &nused, &nalloc, &overflow)))
            return -1;
    } else if (type == 'i') {
        if (!(q = sam_parse_Bi_vals(b, q, &nused, &nalloc, &overflow)))
            return -1;
    } else if (type == 'I') {
        if (!(q = sam_parse_BI_vals(b, q, &nused, &nalloc, &overflow)))
            return -1;
    } else if (type == 'f') {
        if (!(q = sam_parse_Bf_vals(b, q, &nused, &nalloc, &overflow)))
            return -1;
    }
    if (*q != '\t' && *q != '\0') {
        // Unknown B array type or junk in the numbers
        hts_log_error("Malformed B:%c", type);
        return -1;
    }
    i32_to_le(nused, b->data + b_len_idx);

    if (!overflow) {
        *end = q;
        return 0;
    } else {
        int64_t max = 0, min = 0, val;
        // Given type was incorrect.  Try to rescue the situation.
        char *r = q;
        q = in;
        overflow = 0;
        b->l_data = orig_l;
        // Find out what range of values is present
        while (q < r) {
            val = hts_str2int(q + 1, &q, 64, &overflow);
            if (max < val) max = val;
            if (min > val) min = val;
            skip_to_comma_(q);
        }
        // Retry with appropriate type
        if (!overflow) {
            if (min < 0) {
                if (min >= INT8_MIN && max <= INT8_MAX) {
                    return sam_parse_B_vals_r('c', nalloc, in, end, b, ctr);
                } else if (min >= INT16_MIN && max <= INT16_MAX) {
                    return sam_parse_B_vals_r('s', nalloc, in, end, b, ctr);
                } else if (min >= INT32_MIN && max <= INT32_MAX) {
                    return sam_parse_B_vals_r('i', nalloc, in, end, b, ctr);
                }
            } else {
                if (max < UINT8_MAX) {
                    return sam_parse_B_vals_r('C', nalloc, in, end, b, ctr);
                } else if (max <= UINT16_MAX) {
                    return sam_parse_B_vals_r('S', nalloc, in, end, b, ctr);
                } else if (max <= UINT32_MAX) {
                    return sam_parse_B_vals_r('I', nalloc, in, end, b, ctr);
                }
            }
        }
        // If here then at least one of the values is too big to store
        hts_log_error("Numeric value in B array out of allowed range");
        return -1;
    }
#undef skip_to_comma_
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r12
movl %edi, %r13d
movl %esi, (%rsp)
movl (%r9), %eax
leal 0x1(%rax), %ecx
movl %ecx, (%r9)
movsbl %r13b, %ebp
cmpl $0x2, %eax
jl 0x28b79
leaq 0x519a5(%rip), %rsi     # 0x7a515
leaq 0x519b1(%rip), %rdx     # 0x7a528
jmp 0x28bb8
movq %r9, %rbx
movq %r8, %r14
movl %esi, %r15d
movl 0x40(%r8), %eax
movl %eax, 0x34(%rsp)
movq %rdx, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
andl $0x0, 0x4(%rsp)
movzbl %r13b, %edi
callq 0x260de
leal -0x5(%rax), %ecx
cmpl $-0x5, %ecx
ja 0x28bd6
leaq 0x51964(%rip), %rsi     # 0x7a515
leaq 0x5198d(%rip), %rdx     # 0x7a545
pushq $0x1
popq %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x110c6
pushq $-0x1
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r15d, %r15d
jne 0x28be6
movl $0x7, (%rsp)
pushq $0x7
popq %r15
movl %r15d, %ecx
movl %eax, %esi
imulq %rcx, %rsi
addq $0x6, %rsi
movq %r14, %rdi
callq 0x2200f
testl %eax, %eax
je 0x28c19
leaq 0x5190f(%rip), %rsi     # 0x7a515
leaq 0x509d8(%rip), %rdx     # 0x795e5
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
jmp 0x28bc4
movq 0x38(%r14), %rax
movslq 0x40(%r14), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x40(%r14)
movb $0x42, (%rax,%rcx)
movq 0x38(%r14), %rax
movslq 0x40(%r14), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x40(%r14)
movb %r13b, (%rax,%rcx)
movslq 0x40(%r14), %r15
leal 0x4(%r15), %eax
movl %eax, 0x40(%r14)
cmpl $0x43, %ebp
movq %r12, 0x28(%rsp)
je 0x28e55
cmpl $0x49, %ebp
movq 0x18(%rsp), %r13
je 0x28f73
cmpl $0x53, %ebp
je 0x28ee3
cmpl $0x73, %ebp
je 0x28d09
cmpl $0x66, %ebp
je 0x28de8
cmpl $0x69, %ebp
je 0x28d7a
xorl %r12d, %r12d
cmpl $0x63, %ebp
jne 0x28ffe
movq %r15, 0x10(%rsp)
leaq 0x8(%rsp), %rax
movq 0x18(%rsp), %r13
movq %r13, (%rax)
xorl %r12d, %r12d
leaq 0x4(%rsp), %r15
movb (%r13), %al
cmpb $0x2c, %al
jne 0x28e4b
cmpl (%rsp), %r12d
jb 0x28cda
movq %r14, %rdi
movq %rsp, %rsi
pushq $0x1
popq %rdx
callq 0x291a2
testq %rax, %rax
js 0x28bc4
incq %r13
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
pushq $0x8
popq %rdx
movq %r15, %rcx
callq 0x22273
movq 0x38(%r14), %rcx
movslq 0x40(%r14), %rdx
movb %al, (%rcx,%rdx)
incl 0x40(%r14)
movq 0x8(%rsp), %r13
incl %r12d
jmp 0x28cb1
movq %r15, 0x10(%rsp)
leaq 0x8(%rsp), %rax
movq %r13, (%rax)
xorl %r12d, %r12d
leaq 0x4(%rsp), %r15
movb (%r13), %al
cmpb $0x2c, %al
jne 0x28e4b
cmpl (%rsp), %r12d
jb 0x28d47
movq %r14, %rdi
movq %rsp, %rsi
pushq $0x2
popq %rdx
callq 0x291a2
testq %rax, %rax
js 0x28bc4
incq %r13
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
pushq $0x10
popq %rdx
movq %r15, %rcx
callq 0x22273
movq 0x38(%r14), %rcx
movslq 0x40(%r14), %rdx
movw %ax, (%rcx,%rdx)
leal 0x2(%rdx), %eax
movl %eax, 0x40(%r14)
movq 0x8(%rsp), %r13
incl %r12d
jmp 0x28d1e
movq %r15, 0x10(%rsp)
leaq 0x8(%rsp), %rax
movq %r13, (%rax)
xorl %r12d, %r12d
leaq 0x4(%rsp), %r15
movb (%r13), %al
cmpb $0x2c, %al
jne 0x28e4b
cmpl (%rsp), %r12d
jb 0x28db8
movq %r14, %rdi
movq %rsp, %rsi
pushq $0x4
popq %rdx
callq 0x291a2
testq %rax, %rax
js 0x28bc4
incq %r13
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
pushq $0x20
popq %rdx
movq %r15, %rcx
callq 0x22273
movq 0x38(%r14), %rcx
movslq 0x40(%r14), %rdx
movl %eax, (%rcx,%rdx)
addl $0x4, 0x40(%r14)
movq 0x8(%rsp), %r13
incl %r12d
jmp 0x28d8f
movq %r15, 0x10(%rsp)
leaq 0x8(%rsp), %r15
movq %r13, (%r15)
xorl %r12d, %r12d
movb (%r13), %al
cmpb $0x2c, %al
jne 0x28e4b
cmpl (%rsp), %r12d
jb 0x28e1d
movq %r14, %rdi
movq %rsp, %rsi
pushq $0x4
popq %rdx
callq 0x291a2
testq %rax, %rax
js 0x28bc4
incq %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x4350
cvtsd2ss %xmm0, %xmm0
movq 0x38(%r14), %rax
movslq 0x40(%r14), %rcx
movss %xmm0, (%rax,%rcx)
addl $0x4, 0x40(%r14)
movq 0x8(%rsp), %r13
incl %r12d
jmp 0x28df8
movq 0x10(%rsp), %r15
jmp 0x29002
leaq 0x8(%rsp), %rax
movq 0x18(%rsp), %r13
movq %r13, (%rax)
xorl %r12d, %r12d
cmpb $0x2c, (%r13)
jne 0x28ff9
cmpl (%rsp), %r12d
jb 0x28e8d
movq %r14, %rdi
movq %rsp, %rsi
pushq $0x1
popq %rdx
callq 0x291a2
testq %rax, %rax
js 0x28bc4
incl %r12d
cmpb $0x2d, 0x1(%r13)
jne 0x28eb5
movl $0x1, 0x4(%rsp)
movb 0x1(%r13), %al
incq %r13
cmpb $0xa, %al
jl 0x28eae
cmpb $0x2c, %al
jne 0x28e9f
movq %r13, 0x8(%rsp)
jmp 0x28e65
incq %r13
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
pushq $0x8
popq %rdx
leaq 0x4(%rsp), %rcx
callq 0x2204d
movq 0x38(%r14), %rcx
movslq 0x40(%r14), %rdx
movb %al, (%rcx,%rdx)
incl 0x40(%r14)
movq 0x8(%rsp), %r13
jmp 0x28e65
leaq 0x8(%rsp), %rax
movq %r13, (%rax)
xorl %r12d, %r12d
cmpb $0x2c, (%r13)
jne 0x28ff9
cmpl (%rsp), %r12d
jb 0x28f16
movq %r14, %rdi
movq %rsp, %rsi
pushq $0x2
popq %rdx
callq 0x291a2
testq %rax, %rax
js 0x28bc4
incl %r12d
cmpb $0x2d, 0x1(%r13)
jne 0x28f3e
movl $0x1, 0x4(%rsp)
movb 0x1(%r13), %al
incq %r13
cmpb $0xa, %al
jl 0x28f37
cmpb $0x2c, %al
jne 0x28f28
movq %r13, 0x8(%rsp)
jmp 0x28eee
incq %r13
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
pushq $0x10
popq %rdx
leaq 0x4(%rsp), %rcx
callq 0x2204d
movq 0x38(%r14), %rcx
movslq 0x40(%r14), %rdx
movw %ax, (%rcx,%rdx)
leal 0x2(%rdx), %eax
movl %eax, 0x40(%r14)
movq 0x8(%rsp), %r13
jmp 0x28eee
leaq 0x8(%rsp), %rax
movq %r13, (%rax)
xorl %r12d, %r12d
cmpb $0x2c, (%r13)
jne 0x28ff9
cmpl (%rsp), %r12d
jb 0x28fa2
movq %r14, %rdi
movq %rsp, %rsi
pushq $0x4
popq %rdx
callq 0x291a2
testq %rax, %rax
js 0x28bc4
incl %r12d
cmpb $0x2d, 0x1(%r13)
jne 0x28fca
movl $0x1, 0x4(%rsp)
movb 0x1(%r13), %al
incq %r13
cmpb $0xa, %al
jl 0x28fc3
cmpb $0x2c, %al
jne 0x28fb4
movq %r13, 0x8(%rsp)
jmp 0x28f7e
incq %r13
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
pushq $0x20
popq %rdx
leaq 0x4(%rsp), %rcx
callq 0x2204d
movq 0x38(%r14), %rcx
movslq 0x40(%r14), %rdx
movl %eax, (%rcx,%rdx)
addl $0x4, 0x40(%r14)
movq 0x8(%rsp), %r13
jmp 0x28f7e
movq %r13, 0x20(%rsp)
movb (%r13), %al
testb %al, %al
je 0x29012
movzbl %al, %eax
cmpl $0x9, %eax
jne 0x290af
movq 0x38(%r14), %rax
movl %r12d, (%rax,%r15)
cmpl $0x0, 0x4(%rsp)
je 0x290c2
movq %rbx, 0x10(%rsp)
leaq 0x20(%rsp), %rax
movq 0x18(%rsp), %rdi
movq %rdi, (%rax)
leaq 0x4(%rsp), %r15
andl $0x0, (%r15)
movl 0x34(%rsp), %eax
movl %eax, 0x40(%r14)
xorl %ebx, %ebx
pushq $0x40
popq %r12
xorl %ebp, %ebp
cmpq %r13, %rdi
jae 0x29095
incq %rdi
leaq 0x20(%rsp), %rsi
movl %r12d, %edx
movq %r15, %rcx
callq 0x22273
cmpq %rax, %rbx
cmovleq %rax, %rbx
movq 0x20(%rsp), %rdi
decq %rdi
movb 0x1(%rdi), %cl
incq %rdi
cmpb $0xa, %cl
jl 0x29087
cmpb $0x2c, %cl
jne 0x29077
cmpq %rax, %rbp
cmovgeq %rax, %rbp
movq %rdi, 0x20(%rsp)
jmp 0x29050
cmpl $0x0, 0x4(%rsp)
je 0x290d1
leaq 0x51472(%rip), %rsi     # 0x7a515
leaq 0x514c1(%rip), %rdx     # 0x7a56b
jmp 0x28c0d
leaq 0x5145f(%rip), %rsi     # 0x7a515
leaq 0x5149f(%rip), %rdx     # 0x7a55c
jmp 0x28bb8
movq 0x28(%rsp), %rax
movq %r13, (%rax)
xorl %eax, %eax
jmp 0x28bc7
testq %rbp, %rbp
js 0x290f0
cmpq $0xfe, %rbx
movq 0x28(%rsp), %rcx
movq 0x18(%rsp), %rdx
jg 0x29119
movl (%rsp), %esi
pushq $0x43
jmp 0x2914c
cmpq $-0x80, %rbp
setae %al
cmpq $0x80, %rbx
setl %cl
andb %al, %cl
cmpb $0x1, %cl
movq 0x28(%rsp), %rcx
movq 0x18(%rsp), %rdx
jne 0x29129
movl (%rsp), %esi
pushq $0x63
jmp 0x2914c
cmpq $0xffff, %rbx           # imm = 0xFFFF
ja 0x2915f
movl (%rsp), %esi
pushq $0x53
jmp 0x2914c
cmpq $-0x8000, %rbp          # imm = 0x8000
setae %al
cmpq $0x8000, %rbx           # imm = 0x8000
setl %sil
andb %al, %sil
cmpb $0x1, %sil
jne 0x29170
movl (%rsp), %esi
pushq $0x73
popq %rdi
movq %r14, %r8
movq 0x10(%rsp), %r9
callq 0x28b40
jmp 0x28bc7
shrq $0x20, %rbx
jne 0x2909c
movl (%rsp), %esi
pushq $0x49
jmp 0x29195
cmpq $-0x80000000, %rbp      # imm = 0x80000000
setae %al
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rbx
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2909c
movl (%rsp), %esi
pushq $0x69
popq %rdi
movq 0x18(%rsp), %rdx
movq 0x28(%rsp), %rcx
jmp 0x2914d