// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x3a68a
cmpq $0x0, -0x20(%rbp)
jne 0x3a6b1
movl $0x1, %edi
leaq 0xb7a59(%rip), %rsi     # 0xf20ef
leaq 0xb7a23(%rip), %rdx     # 0xf20c0
movb $0x0, %al
callq 0x1b030
movq $-0x1, -0x8(%rbp)
jmp 0x3a87f
cmpq $0x0, -0x18(%rbp)
je 0x3a6c3
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
jne 0x3a6d6
xorl %eax, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3a6e2
movq -0x10(%rbp), %rdi
callq 0x3b980
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, %eax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3a71f
movq -0x20(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jne 0x3a71f
cmpq $0x0, -0x18(%rbp)
je 0x3a712
movq -0x10(%rbp), %rcx
addq $0x1, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x3a87f
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
movl 0x14(%rcx), %ecx
subq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jle 0x3a775
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rsi
shlq $0x2, %rsi
callq 0x3a350
cmpl $0x0, %eax
jge 0x3a775
movl $0x1, %edi
leaq 0xb7995(%rip), %rsi     # 0xf20ef
leaq 0xb7976(%rip), %rdx     # 0xf20d7
movb $0x0, %al
callq 0x1b030
movq $-0x1, -0x8(%rbp)
jmp 0x3a87f
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x20(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x38(%rcx), %rcx
movq -0x20(%rbp), %rdx
movslq 0x40(%rdx), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
je 0x3a806
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x20(%rbp), %rcx
movl 0x14(%rcx), %ecx
shll $0x2, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x48(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x20(%rbp), %rax
movslq 0x40(%rax), %rax
addq %rax, %rdx
movq -0x48(%rbp), %rax
subq %rax, %rdx
callq 0x4810
cmpq $0x0, -0x28(%rbp)
je 0x3a834
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x28(%rbp), %rax
movl %eax, %edx
callq 0x3ba50
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
jne 0x3a832
movq $-0x1, -0x8(%rbp)
jmp 0x3a87f
jmp 0x3a83b
movl $0x1, -0x2c(%rbp)
movq -0x38(%rbp), %rdx
shlq $0x2, %rdx
movq -0x20(%rbp), %rax
movslq 0x40(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x40(%rax)
movq -0x28(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x14(%rax)
cmpq $0x0, -0x18(%rbp)
je 0x3a877
movq -0x10(%rbp), %rcx
movslq -0x2c(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)