// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/sam.c
// Function: bam_plp_insertion_mod
int bam_plp_insertion_mod(const bam_pileup1_t *p,
                          hts_base_mod_state *m,
                          kstring_t *ins, int *del_len) {
    int j, k, indel, nb = 0;
    uint32_t *cigar;

    if (p->indel <= 0) {
        if (ks_resize(ins, 1) < 0)
            return -1;
        ins->l = 0;
        ins->s[0] = '\0';
        return 0;
    }

    if (del_len)
        *del_len = 0;

    // Measure indel length including pads
    indel = 0;
    k = p->cigar_ind+1;
    cigar = bam_get_cigar(p->b);
    while (k < p->b->core.n_cigar) {
        switch (cigar[k] & BAM_CIGAR_MASK) {
        case BAM_CPAD:
        case BAM_CINS:
            indel += (cigar[k] >> BAM_CIGAR_SHIFT);
            break;
        default:
            k = p->b->core.n_cigar;
            break;
        }
        k++;
    }
    nb = ins->l = indel;

    // Produce sequence
    if (ks_resize(ins, indel+1) < 0)
        return -1;
    indel = 0;
    k = p->cigar_ind+1;
    j = 1;
    while (k < p->b->core.n_cigar) {
        int l, c;
        switch (cigar[k] & BAM_CIGAR_MASK) {
        case BAM_CPAD:
            for (l = 0; l < (cigar[k]>>BAM_CIGAR_SHIFT); l++)
                ins->s[indel++] = '*';
            break;
        case BAM_CINS:
            for (l = 0; l < (cigar[k]>>BAM_CIGAR_SHIFT); l++, j++) {
                c = p->qpos + j - p->is_del < p->b->core.l_qseq
                    ? seq_nt16_str[bam_seqi(bam_get_seq(p->b),
                                            p->qpos + j - p->is_del)]
                    : 'N';
                ins->s[indel++] = c;
                int nm;
                hts_base_mod mod[256];
                if (m && (nm = bam_mods_at_qpos(p->b, p->qpos + j - p->is_del,
                                                m, mod, 256)) > 0) {
                    int o_indel = indel;
                    if (ks_resize(ins, ins->l + nm*16+3) < 0)
                        return -1;
                    ins->s[indel++] = '[';
                    int j;
                    for (j = 0; j < nm; j++) {
                        char qual[20];
                        if (mod[j].qual >= 0)
                            snprintf(qual, sizeof(qual), "%d", mod[j].qual);
                        else
                            *qual=0;
                        if (mod[j].modified_base < 0)
                            // ChEBI
                            indel += snprintf(&ins->s[indel], ins->m - indel,
                                              "%c(%d)%s",
                                              "+-"[mod[j].strand],
                                              -mod[j].modified_base,
                                              qual);
                        else
                            indel += snprintf(&ins->s[indel], ins->m - indel,
                                              "%c%c%s",
                                              "+-"[mod[j].strand],
                                              mod[j].modified_base,
                                              qual);
                    }
                    ins->s[indel++] = ']';
                    ins->l += indel - o_indel; // grow by amount we used
                }
            }
            break;
        case BAM_CDEL:
            // eg cigar 1M2I1D gives mpileup output in T+2AA-1C style
            if (del_len)
                *del_len = cigar[k]>>BAM_CIGAR_SHIFT;
            // fall through
        default:
            k = p->b->core.n_cigar;
            break;
        }
        k++;
    }
    ins->s[indel] = '\0';
    ins->l = indel; // string length

    return nb;      // base length
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1068, %rsp           # imm = 0x1068
movq %rdx, %r14
movq %rsi, 0x18(%rsp)
movq %rdi, 0x8(%rsp)
cmpl $0x0, 0xc(%rdi)
pushq $-0x1
popq %rbx
jle 0x26fdf
movq %rcx, %r12
testq %rcx, %rcx
je 0x26d36
andl $0x0, (%r12)
movq 0x8(%rsp), %rcx
movl 0x20(%rcx), %eax
movq (%rcx), %rcx
movzwl 0x12(%rcx), %ebp
addq 0x38(%rcx), %rbp
movl 0x14(%rcx), %ecx
xorl %r15d, %r15d
movl %eax, %edi
movl %edi, %eax
incl %eax
cmpl %ecx, %eax
jae 0x26d79
movslq %eax, %rdx
movl (%rbp,%rdx,4), %edx
movl %edx, %esi
andl $0xf, %esi
cmpl $0x6, %esi
je 0x26d71
movl %ecx, %edi
cmpl $0x1, %esi
jne 0x26d51
shrl $0x4, %edx
addl %edx, %r15d
jmp 0x26d4f
movslq %r15d, %rax
movq %rax, (%r14)
incl %eax
movslq %eax, %rsi
movq %r14, %rdi
callq 0x24d14
testl %eax, %eax
js 0x2700c
movl %r15d, 0x10(%rsp)
movq 0x8(%rsp), %rax
movl 0x20(%rax), %r13d
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
xorl %r15d, %r15d
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movl %r13d, %esi
movl %esi, %r13d
incl %r13d
movl 0x14(%rdx), %esi
movslq %r15d, %rcx
cmpl %esi, %r13d
jae 0x26ffd
movslq %r13d, %rax
movq %rax, 0x28(%rsp)
movl (%rbp,%rax,4), %eax
movl %eax, %edi
andl $0xf, %edi
cmpl $0x2, %edi
je 0x26df3
cmpl $0x6, %edi
je 0x26e04
cmpl $0x1, %edi
jne 0x26dbc
jmp 0x26e2a
testq %r12, %r12
je 0x26dbc
shrl $0x4, %eax
movl %eax, (%r12)
movl 0x14(%rdx), %esi
jmp 0x26dbc
xorl %edx, %edx
shrl $0x4, %eax
cmpl %eax, %edx
jae 0x26fd7
movq 0x10(%r14), %rax
addq %rcx, %rax
movb $0x2a, (%rdx,%rax)
movq 0x28(%rsp), %rax
movl (%rbp,%rax,4), %eax
incq %rdx
jmp 0x26e06
xorl %ecx, %ecx
movq %r12, 0x30(%rsp)
movq %rbp, 0x38(%rsp)
shrl $0x4, %eax
cmpl %eax, %ecx
jae 0x26db1
movl %ecx, 0x14(%rsp)
movq 0x8(%rsp), %rdx
movl 0x8(%rdx), %ecx
addl 0x4(%rsp), %ecx
movl 0x14(%rdx), %eax
andl $0x1, %eax
subl %eax, %ecx
movq (%rdx), %rax
movb $0x4e, %dl
cmpl 0x18(%rax), %ecx
jge 0x26e96
movl 0x14(%rax), %edx
shll $0x2, %edx
addq 0x38(%rax), %rdx
movzwl 0x12(%rax), %eax
addq %rdx, %rax
movl %ecx, %edx
sarl %edx
movslq %edx, %rdx
movzbl (%rdx,%rax), %eax
shll $0x2, %ecx
notb %cl
andb $0x4, %cl
shrl %cl, %eax
andl $0xf, %eax
leaq 0x50b7d(%rip), %rcx     # 0x77a10
movb (%rcx,%rax), %dl
movq %r15, 0x20(%rsp)
movslq %r15d, %rax
leaq 0x1(%rax), %r15
movq 0x10(%r14), %rcx
movb %dl, (%rcx,%rax)
testq %rbx, %rbx
je 0x26fba
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
addl 0x4(%rsp), %esi
movl 0x14(%rax), %eax
andl $0x1, %eax
subl %eax, %esi
movq %rbx, %rdx
leaq 0x60(%rsp), %rcx
movl $0x100, %r8d            # imm = 0x100
callq 0x2ada0
testl %eax, %eax
jle 0x26fba
movl %eax, %ebp
movl %eax, %esi
shll $0x4, %esi
orl $0x3, %esi
addq (%r14), %rsi
movq %r14, %rdi
callq 0x24d14
testl %eax, %eax
js 0x27020
movq 0x10(%r14), %rax
movq 0x20(%rsp), %rcx
leal 0x2(%rcx), %r12d
movb $0x5b, (%rax,%r15)
movl %ebp, %ebp
shlq $0x4, %rbp
xorl %r15d, %r15d
movslq %r12d, %rbx
cmpq %r15, %rbp
je 0x26f9a
movl 0x6c(%rsp,%r15), %ecx
testl %ecx, %ecx
js 0x26f45
leaq 0x40(%rsp), %rdi
pushq $0x14
popq %rsi
leaq 0x50763(%rip), %rdx     # 0x7769f
xorl %eax, %eax
callq 0x4800
jmp 0x26f4a
movb $0x0, 0x40(%rsp)
movl 0x60(%rsp,%r15), %r8d
movq 0x10(%r14), %rdi
addq %rbx, %rdi
movq 0x8(%r14), %rsi
subq %rbx, %rsi
movslq 0x68(%rsp,%r15), %rax
leaq 0x52ec8(%rip), %rcx     # 0x79e31
movsbl (%rax,%rcx), %ecx
testl %r8d, %r8d
js 0x26f7b
leaq 0x52ebb(%rip), %rdx     # 0x79e34
jmp 0x26f85
negl %r8d
leaq 0x52ea3(%rip), %rdx     # 0x79e28
leaq 0x40(%rsp), %r9
xorl %eax, %eax
callq 0x4800
addl %eax, %r12d
addq $0x10, %r15
jmp 0x26f1c
movq 0x10(%r14), %rax
leal 0x1(%rbx), %r15d
movb $0x5d, (%rax,%rbx)
subl 0x20(%rsp), %ebx
movslq %ebx, %rax
addq %rax, (%r14)
movq 0x30(%rsp), %r12
movq 0x18(%rsp), %rbx
movl 0x14(%rsp), %ecx
incl %ecx
incl 0x4(%rsp)
movq 0x38(%rsp), %rbp
movq 0x28(%rsp), %rax
movl (%rbp,%rax,4), %eax
jmp 0x26e36
addl %edx, %r15d
jmp 0x26db1
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x24d14
testl %eax, %eax
js 0x2700c
andq $0x0, (%r14)
movq 0x10(%r14), %rax
movb $0x0, (%rax)
xorl %ebx, %ebx
jmp 0x2700c
movq 0x10(%r14), %rax
movb $0x0, (%rax,%rcx)
movq %rcx, (%r14)
movl 0x10(%rsp), %ebx
movl %ebx, %eax
addq $0x1068, %rsp           # imm = 0x1068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x1
popq %rbx
jmp 0x2700c