// File: /workspace/github_c_makefile_star2_O1/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 %r8, %r14
movq %rcx, %r8
movl %edi, %ebp
movl %esi, 0xc(%rsp)
movl (%r9), %eax
leal 0x1(%rax), %ecx
movl %ecx, (%r9)
cmpl $0x2, %eax
jl 0x32ea4
movsbl %bpl, %ecx
leaq 0x68720(%rip), %rsi     # 0x9b5b3
leaq 0x6872c(%rip), %rdx     # 0x9b5c6
movl $0x1, %edi
jmp 0x32f44
movq %r9, %rbx
movq %rdx, %r12
movl 0x40(%r14), %r15d
movl $0x0, 0x10(%rsp)
movsbl %bpl, %r13d
movl $0x1, %eax
cmpl $0x59, %r13d
jg 0x32ede
leal -0x41(%r13), %ecx
cmpl $0x8, %ecx
ja 0x32f17
leaq 0x674e3(%rip), %rdx     # 0x9a3b8
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leal -0x63(%r13), %ecx
cmpl $0x6, %ecx
ja 0x32efe
leaq 0x674ee(%rip), %rdx     # 0x9a3dc
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0x4, %eax
jmp 0x32f26
cmpl $0x5a, %r13d
je 0x32f11
cmpl $0x73, %r13d
jne 0x32f1d
movl $0x2, %eax
jmp 0x32f26
movzbl %bpl, %eax
jmp 0x32f26
cmpl $0x53, %r13d
je 0x32f0a
xorl %eax, %eax
jmp 0x32f26
movl $0x8, %eax
leal -0x5(%rax), %ecx
cmpl $-0x5, %ecx
ja 0x32f5f
leaq 0x6867e(%rip), %rsi     # 0x9b5b3
leaq 0x686a7(%rip), %rdx     # 0x9b5e3
movl $0x1, %edi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x14378
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %r15d, %rcx
testl %esi, %esi
jne 0x32f6e
movl $0x7, 0xc(%rsp)
movl 0xc(%rsp), %edx
movl %eax, %esi
imulq %rdx, %rsi
addq $0x6, %rsi
addq %rcx, %rsi
setae %al
testq $-0x80000000, %rsi      # imm = 0x80000000
sete %cl
testb %al, %cl
jne 0x32f9d
callq 0x4050
movl $0xc, (%rax)
jmp 0x32fbc
movl 0x44(%r14), %eax
cmpq %rax, %rsi
movq %r8, 0x18(%rsp)
jbe 0x32fdb
movq %r14, %rdi
callq 0x23476
movq 0x18(%rsp), %r8
testl %eax, %eax
je 0x32fdb
leaq 0x685f0(%rip), %rsi     # 0x9b5b3
leaq 0x676bb(%rip), %rdx     # 0x9a685
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
jmp 0x32f4b
movl $0x0, 0x14(%rsp)
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 %bpl, (%rax,%rcx)
movslq 0x40(%r14), %rbp
leal 0x4(%rbp), %eax
movl %eax, 0x40(%r14)
cmpl $0x62, %r13d
jle 0x33051
cmpl $0x68, %r13d
jg 0x3308d
cmpl $0x63, %r13d
je 0x330d8
movq %r12, %rax
cmpl $0x66, %r13d
jne 0x33138
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movq %r14, %rdi
movq %r12, %rsi
callq 0x33fe0
jmp 0x3312a
cmpl $0x43, %r13d
je 0x330bc
cmpl $0x49, %r13d
je 0x33110
movq %r12, %rax
cmpl $0x53, %r13d
jne 0x33138
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
callq 0x33a00
jmp 0x3312a
cmpl $0x69, %r13d
je 0x330f4
movq %r12, %rax
cmpl $0x73, %r13d
jne 0x33138
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
callq 0x33800
jmp 0x3312a
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
callq 0x33620
jmp 0x3312a
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
callq 0x33420
jmp 0x3312a
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
callq 0x33be0
jmp 0x3312a
leaq 0x14(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
callq 0x33e00
testq %rax, %rax
je 0x32f4b
movq 0x18(%rsp), %r8
movzbl (%rax), %ecx
testl %ecx, %ecx
je 0x33148
cmpl $0x9, %ecx
jne 0x332e9
movl 0x14(%rsp), %ecx
movq 0x38(%r14), %rdx
movl %ecx, (%rdx,%rbp)
cmpl $0x0, 0x10(%rsp)
je 0x332fc
movl $0x0, 0x10(%rsp)
movl %r15d, 0x40(%r14)
cmpq %r12, %rax
movq %r12, 0x20(%rsp)
jbe 0x33306
movq %r12, %r8
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
movabsq $0xccccccccccccccc, %rdi # imm = 0xCCCCCCCCCCCCCCC
xorl %edx, %edx
xorl %r12d, %r12d
movzbl 0x1(%r8), %r9d
cmpl $0x2b, %r9d
je 0x331e1
cmpl $0x2d, %r9d
jne 0x331e7
leaq 0x14(%r8), %r10
movl $0x2, %r11d
xorl %r9d, %r9d
movzbl (%r8,%r11), %r15d
leal -0x3a(%r15), %ebp
cmpb $-0xa, %bpl
setb %bpl
jb 0x33234
leaq (%r9,%r9,4), %r9
leaq (%r15,%r9,2), %r9
addq $-0x30, %r9
incq %r11
cmpl $0x14, %r11d
jne 0x331b2
xorl %ebp, %ebp
movq %r10, %r8
jmp 0x33237
addq $0x2, %r8
jmp 0x331ea
incq %r8
movq %r8, %r11
addq $0x12, %r8
xorl %r10d, %r10d
xorl %r9d, %r9d
movzbl (%r11,%r10), %r15d
leal -0x3a(%r15), %ebp
cmpb $-0xa, %bpl
setb %bpl
jb 0x33226
leaq (%r9,%r9,4), %r9
leaq (%r15,%r9,2), %r9
addq $-0x30, %r9
incq %r10
cmpl $0x12, %r10d
jne 0x331f7
movb $0x1, %r10b
xorl %ebp, %ebp
jmp 0x3322f
addq %r10, %r11
movb $0x1, %r10b
movq %r11, %r8
movq %rsi, %r11
jmp 0x3323e
addq %r11, %r8
leaq 0x1(%rsi), %r11
xorl %r10d, %r10d
testb %bpl, %bpl
jne 0x332ad
movb (%r8), %bpl
cmpb $0x30, %bpl
jb 0x332ad
movzbl %bpl, %ebp
addl $-0x30, %ebp
cmpl $0x9, %ebp
ja 0x332ad
leaq (%rsi,%r11), %r15
addq $0x9, %r15
movl %ebp, %r13d
cmpq %rdi, %r9
jb 0x3326f
jne 0x33290
cmpq %r13, %r15
jb 0x33290
leaq (%r9,%r9,4), %r9
leaq (,%r9,2), %r9
addq %r13, %r9
movzbl 0x1(%r8), %ebp
incq %r8
addl $-0x30, %ebp
cmpl $0xa, %ebp
jb 0x33260
jmp 0x332ad
movzbl 0x1(%r8), %r9d
incq %r8
addl $-0x30, %r9d
cmpl $0xa, %r9d
jb 0x33290
movl $0x1, 0x10(%rsp)
movq %r11, %r9
movq %r9, %r11
negq %r11
testb %r10b, %r10b
cmovneq %r9, %r11
cmpq %r11, %r12
cmovleq %r11, %r12
decq %r8
movb 0x1(%r8), %r9b
incq %r8
cmpb $0xa, %r9b
jl 0x332d7
cmpb $0x2c, %r9b
jne 0x332c4
cmpq %r11, %rdx
cmovgeq %r11, %rdx
cmpq %rax, %r8
jb 0x33194
jmp 0x3330b
leaq 0x682c3(%rip), %rsi     # 0x9b5b3
leaq 0x68303(%rip), %rdx     # 0x9b5fa
jmp 0x32f3c
movq %rax, (%r8)
xorl %eax, %eax
jmp 0x32f50
xorl %r12d, %r12d
xorl %edx, %edx
cmpl $0x0, 0x10(%rsp)
je 0x33325
leaq 0x6829a(%rip), %rsi     # 0x9b5b3
leaq 0x682e9(%rip), %rdx     # 0x9b609
jmp 0x32fca
testq %rdx, %rdx
js 0x33343
cmpq $0xfe, %r12
movq 0x18(%rsp), %rcx
jg 0x3336e
movl 0xc(%rsp), %esi
movl $0x43, %edi
jmp 0x333a9
cmpq $-0x80, %rdx
setge %al
cmpq $0x80, %r12
setl %sil
andb %al, %sil
cmpb $0x1, %sil
movq 0x18(%rsp), %rcx
jne 0x33382
movl 0xc(%rsp), %esi
movl $0x63, %edi
jmp 0x333a9
cmpq $0xffff, %r12           # imm = 0xFFFF
jg 0x333be
movl 0xc(%rsp), %esi
movl $0x53, %edi
jmp 0x333a9
cmpq $-0x8000, %rdx          # imm = 0x8000
setge %al
cmpq $0x8000, %r12           # imm = 0x8000
setl %sil
andb %al, %sil
cmpb $0x1, %sil
jne 0x333d7
movl 0xc(%rsp), %esi
movl $0x73, %edi
movq 0x20(%rsp), %rdx
movq %r14, %r8
movq %rbx, %r9
callq 0x32e60
jmp 0x32f50
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %r12
jg 0x33312
movl 0xc(%rsp), %esi
movl $0x49, %edi
jmp 0x33400
cmpq $-0x80000000, %rdx      # imm = 0x80000000
setge %al
movl $0x80000000, %edx       # imm = 0x80000000
cmpq %rdx, %r12
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x33312
movl 0xc(%rsp), %esi
movl $0x69, %edi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
jmp 0x333ae
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)