// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/sam.c
// Function: bam_parse_cigar
ssize_t bam_parse_cigar(const char *in, char **end, bam1_t *b) {
    size_t n_cigar = 0;
    int diff;

    if (!in || !b) {
        hts_log_error("NULL pointer arguments");
        return -1;
    }
    if (end) *end = (char *)in;

    n_cigar = (*in == '*') ? 0 : read_ncigar(in);
    if (!n_cigar && b->core.n_cigar == 0) {
        if (end) *end = (char *)in+1;
        return 0;
    }

    ssize_t cig_diff = n_cigar - b->core.n_cigar;
    if (cig_diff > 0 &&
        possibly_expand_bam_data(b, cig_diff * sizeof(uint32_t)) < 0) {
        hts_log_error("Memory allocation error");
        return -1;
    }

    uint32_t *cig = bam_get_cigar(b);
    if ((uint8_t *)cig != b->data + b->l_data) {
        // Modifying an BAM existing BAM record
        uint8_t  *seq = bam_get_seq(b);
        memmove(cig + n_cigar, seq, (b->data + b->l_data) - seq);
    }

    if (n_cigar) {
        if (!(diff = parse_cigar(in, cig, n_cigar)))
            return -1;
    } else {
        diff = 1; // handle "*"
    }

    b->l_data += cig_diff * sizeof(uint32_t);
    b->core.n_cigar = n_cigar;
    if (end) *end = (char *)in + diff;

    return n_cigar;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
setne %al
testq %rdx, %rdx
setne %cl
testb %cl, %al
je 0x280f1
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
testq %rsi, %rsi
je 0x280d2
movq %r14, (%rbx)
cmpb $0x2a, (%r14)
je 0x28101
movq %r14, %rdi
callq 0x28e27
testl %eax, %eax
je 0x28101
movl %eax, %r8d
movl %eax, %ebp
movl 0x14(%r15), %eax
xorl %edi, %edi
jmp 0x28111
leaq 0x6fadf(%rip), %rsi     # 0x97bd7
leaq 0x6faa9(%rip), %rdx     # 0x97ba8
jmp 0x28158
movl 0x14(%r15), %eax
testl %eax, %eax
je 0x2817d
xorl %ebp, %ebp
movb $0x1, %dil
xorl %r8d, %r8d
movl %eax, %eax
movq %rbp, %r12
subq %rax, %r12
jle 0x281ad
leaq (,%r12,4), %rax
movslq 0x40(%r15), %rsi
addq %rax, %rsi
setae %al
testq $-0x80000000, %rsi      # imm = 0x80000000
sete %cl
testb %al, %cl
jne 0x2818c
callq 0x4050
movl $0xc, (%rax)
leaq 0x6fa86(%rip), %rsi     # 0x97bd7
leaq 0x6fa67(%rip), %rdx     # 0x97bbf
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
movq $-0x1, %rbp
movq %rbp, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rbx, %rbx
je 0x28188
incq %r14
movq %r14, (%rbx)
xorl %ebp, %ebp
jmp 0x2816b
movl 0x44(%r15), %eax
cmpq %rax, %rsi
jbe 0x281ad
movl %edi, (%rsp)
movq %r15, %rdi
movl %r8d, %r13d
callq 0x22a64
movl (%rsp), %edi
movl %r13d, %r8d
testl %eax, %eax
js 0x2814a
movq 0x38(%r15), %rdx
movzwl 0x12(%r15), %ecx
leaq (%rdx,%rcx), %r13
movslq 0x40(%r15), %rax
cmpq %rax, %rcx
je 0x281f3
addq %rax, %rdx
movl 0x14(%r15), %esi
shll $0x2, %esi
addq %r13, %rsi
movl %edi, (%rsp)
leaq (,%rbp,4), %rdi
addq %r13, %rdi
subq %rsi, %rdx
movl %r8d, 0x4(%rsp)
callq 0x4830
movl (%rsp), %edi
movl 0x4(%rsp), %r8d
movl $0x1, %eax
testb %dil, %dil
jne 0x28219
movq %r14, %rdi
movq %r13, %rsi
movl %r8d, %edx
movl %r8d, %r13d
callq 0x28e92
movl %r13d, %r8d
testl %eax, %eax
je 0x28164
shll $0x2, %r12d
addl %r12d, 0x40(%r15)
movl %r8d, 0x14(%r15)
testq %rbx, %rbx
je 0x2816b
cltq
addq %rax, %r14
movq %r14, (%rbx)
jmp 0x2816b