// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movq %rdx, %r12
movl %esi, 0xc(%rsp)
movl (%r9), %eax
leal 0x1(%rax), %edx
movl %edx, (%r9)
cmpl $0x2, %eax
jl 0x31d26
movsbl %dil, %ecx
leaq 0x668ac(%rip), %rsi     # 0x985ba
leaq 0x668b8(%rip), %rdx     # 0x985cd
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
jmp 0x31e09
movq %r8, %r14
movl 0x40(%r8), %ebp
movl $0x0, 0x10(%rsp)
movsbl %dil, %r13d
leal -0x41(%r13), %eax
cmpl $0x32, %eax
ja 0x31e1d
movq %r9, %rbx
movabsq $0x400000005, %rdx      # imm = 0x400000005
btq %rax, %rdx
jb 0x31d70
movabsq $0x12000000100, %rdx    # imm = 0x12000000100
btq %rax, %rdx
jae 0x31d77
movl $0x4, %eax
jmp 0x31d90
movl $0x1, %eax
jmp 0x31d90
movabsq $0x4000000040000, %rdx  # imm = 0x4000000040000
btq %rax, %rdx
jae 0x31e1d
movl $0x2, %eax
movslq %ebp, %rdi
testl %esi, %esi
jne 0x31da4
movl $0x7, 0xc(%rsp)
movl $0x7, %esi
movl %esi, %edx
imulq %rdx, %rax
addq $0x6, %rax
addq %rdi, %rax
setae %dl
testq $-0x80000000, %rax      # imm = 0x80000000
sete %sil
testb %dl, %sil
jne 0x31dd0
callq 0x4050
movl $0xc, (%rax)
jmp 0x31def
movl 0x44(%r14), %esi
movl %ebp, %edx
cmpq %rsi, %rax
movq %rcx, 0x18(%rsp)
jbe 0x31e3c
movq %r14, %rdi
movq %rax, %rsi
callq 0x22a64
testl %eax, %eax
je 0x31e30
leaq 0x667c4(%rip), %rsi     # 0x985ba
leaq 0x65898(%rip), %rdx     # 0x97695
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x66796(%rip), %rsi     # 0x985ba
leaq 0x667bf(%rip), %rdx     # 0x985ea
jmp 0x3216a
movl 0x40(%r14), %edx
movslq %edx, %rdi
movq 0x18(%rsp), %rcx
movl $0x0, 0x14(%rsp)
movq 0x38(%r14), %rax
incl %edx
movl %edx, 0x40(%r14)
movb $0x42, (%rax,%rdi)
movq 0x38(%r14), %rax
movslq 0x40(%r14), %rsi
leal 0x1(%rsi), %edx
movl %edx, 0x40(%r14)
movb %r13b, (%rax,%rsi)
movslq 0x40(%r14), %r15
leal 0x4(%r15), %eax
movl %eax, 0x40(%r14)
cmpl $0x62, %r13d
jle 0x31eae
cmpl $0x68, %r13d
jg 0x31eea
cmpl $0x63, %r13d
je 0x31f35
movq %r12, %rax
cmpl $0x66, %r13d
jne 0x31f95
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movq %r14, %rdi
movq %r12, %rsi
callq 0x32da0
jmp 0x31f87
cmpl $0x43, %r13d
je 0x31f19
cmpl $0x49, %r13d
je 0x31f6d
movq %r12, %rax
cmpl $0x53, %r13d
jne 0x31f95
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
callq 0x32800
jmp 0x31f87
cmpl $0x69, %r13d
je 0x31f51
movq %r12, %rax
cmpl $0x73, %r13d
jne 0x31f95
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
callq 0x32600
jmp 0x31f87
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
callq 0x32460
jmp 0x31f87
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
callq 0x32280
jmp 0x31f87
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
callq 0x329c0
jmp 0x31f87
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
callq 0x32be0
testq %rax, %rax
je 0x31e09
movq 0x18(%rsp), %rcx
movzbl (%rax), %edx
testl %edx, %edx
je 0x31fa5
cmpl $0x9, %edx
jne 0x3215c
movl 0x14(%rsp), %esi
movq 0x38(%r14), %rdx
movl %esi, (%rdx,%r15)
cmpl $0x0, 0x10(%rsp)
je 0x32177
movl $0x0, 0x10(%rsp)
movl %ebp, 0x40(%r14)
cmpq %r12, %rax
movq %r12, %r11
jbe 0x32199
movabsq $0x7fffffffffffffff, %rdx # imm = 0x7FFFFFFFFFFFFFFF
xorl %edi, %edi
movabsq $0xccccccccccccccc, %rsi # imm = 0xCCCCCCCCCCCCCCC
xorl %r9d, %r9d
xorl %r12d, %r12d
movq %r11, 0x20(%rsp)
movq %r9, %r8
movzbl 0x1(%r11), %r9d
cmpl $0x2b, %r9d
je 0x3204a
cmpl $0x2d, %r9d
jne 0x32050
leaq 0x14(%r11), %r10
movl $0x2, %r15d
xorl %r9d, %r9d
movzbl (%r11,%r15), %r13d
leal -0x30(%r13), %ebp
cmpb $0xa, %bpl
jae 0x3210c
leaq (%r9,%r9,4), %r9
leaq -0x30(,%r9,2), %r9
addq %r13, %r9
incq %r15
cmpl $0x14, %r15d
jne 0x32016
leaq 0x1(%rdx), %r15
xorl %r11d, %r11d
jmp 0x3208e
addq $0x2, %r11
jmp 0x32053
incq %r11
leaq 0x12(%r11), %r10
xorl %r15d, %r15d
xorl %r9d, %r9d
movzbl (%r11,%r15), %r13d
leal -0x30(%r13), %ebp
cmpb $0x9, %bpl
ja 0x3210f
leaq (%r9,%r9,4), %r9
leaq -0x30(,%r9,2), %r9
addq %r13, %r9
incq %r15
cmpl $0x12, %r15d
jne 0x3205d
movb $0x1, %r11b
movq %rdx, %r15
movzbl (%r10), %ebp
cmpl $0x30, %ebp
jb 0x320d8
addl $-0x30, %ebp
cmpl $0x9, %ebp
ja 0x320d8
leaq (%rdx,%r15), %r13
addq $0x9, %r13
cmpq %rsi, %r9
jae 0x320b0
movl %ebp, %ebp
jmp 0x320b9
jne 0x320e2
movl %ebp, %ebp
cmpq %rbp, %r13
jb 0x320e2
leaq (%r9,%r9,4), %r9
leaq (,%r9,2), %r9
addq %rbp, %r9
movzbl 0x1(%r10), %ebp
incq %r10
addl $-0x30, %ebp
cmpl $0xa, %ebp
jb 0x320a7
testb %r11b, %r11b
jne 0x32115
negq %r9
jmp 0x32115
movzbl 0x1(%r10), %edi
incq %r10
addl $-0x30, %edi
cmpl $0xa, %edi
jb 0x320e2
movl $0x1, 0x10(%rsp)
movl $0x1, %edi
testb %r11b, %r11b
jne 0x32107
negq %r15
movq %r15, %r9
jmp 0x32115
negq %r9
addq %r15, %r11
movq %r11, %r10
cmpq %r9, %r12
cmovleq %r9, %r12
decq %r10
movq %r10, %r11
movb 0x1(%r11), %r10b
incq %r11
cmpb $0xa, %r10b
jl 0x32135
cmpb $0x2c, %r10b
jne 0x32122
cmpq %r9, %r8
cmovlq %r8, %r9
cmpq %rax, %r11
jb 0x31ff5
testl %edi, %edi
je 0x32181
leaq 0x6646a(%rip), %rsi     # 0x985ba
leaq 0x664b9(%rip), %rdx     # 0x98610
jmp 0x31dfd
leaq 0x66457(%rip), %rsi     # 0x985ba
leaq 0x66497(%rip), %rdx     # 0x98601
movl $0x1, %edi
movl %r13d, %ecx
jmp 0x31d1a
movq %rax, (%rcx)
xorl %eax, %eax
jmp 0x31e0e
testq %r9, %r9
js 0x321b5
cmpq $0xfe, %r12
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r11
jg 0x321d8
movl 0xc(%rsp), %esi
movl $0x43, %edi
movq %r11, %rdx
movq %r14, %r8
movq %rbx, %r9
callq 0x31ce0
jmp 0x31e0e
cmpq $-0x80, %r9
setae %al
cmpq $0x80, %r12
setl %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x321f1
movl 0xc(%rsp), %esi
movl $0x63, %edi
jmp 0x32255
cmpq $0xffff, %r12           # imm = 0xFFFF
ja 0x32217
movl 0xc(%rsp), %esi
movl $0x53, %edi
movq 0x20(%rsp), %rdx
jmp 0x321a5
cmpq $-0x8000, %r9           # imm = 0x8000
setae %al
cmpq $0x8000, %r12           # imm = 0x8000
setl %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x3222c
movl 0xc(%rsp), %esi
movl $0x73, %edi
jmp 0x32255
shrq $0x20, %r12
jne 0x32149
movl 0xc(%rsp), %esi
movl $0x49, %edi
jmp 0x32255
cmpq $-0x80000000, %r9       # imm = 0x80000000
setae %al
movl $0x80000000, %edx       # imm = 0x80000000
cmpq %rdx, %r12
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x32149
movl 0xc(%rsp), %esi
movl $0x69, %edi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
jmp 0x321a5
nopw %cs:(%rax,%rax)
nopw %cs:(%rax,%rax)