// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/sam_mods.c
// Function: bam_mods_at_next_pos
int bam_mods_at_next_pos(const bam1_t *b, hts_base_mod_state *state,
                         hts_base_mod *mods, int n_mods) {

    if (state->seq_pos >= b->core.l_qseq)
        return 0;

    int i, j, n = 0;
    unsigned char base = bam_seqi(bam_get_seq(b), state->seq_pos);
    state->seq_pos++;
    if (b->core.flag & BAM_FREVERSE)
        base = seqi_rc[base];

    for (i = 0; i < state->nmods; i++) {
        int unchecked = 0;
        if (state->canonical[i] != base && state->canonical[i] != 15/*N*/)
            continue;

        if (state->MMcount[i]-- > 0) {
            if (!state->implicit[i] &&
                (state->flags & HTS_MOD_REPORT_UNCHECKED))
                unchecked = 1;
            else
                continue;
        }

        char *MMptr = state->MM[i];
        if (n < n_mods) {
            mods[n].modified_base = state->type[i];
            mods[n].canonical_base = seq_nt16_str[state->canonical[i]];
            mods[n].strand = state->strand[i];
            mods[n].qual = unchecked
                ? HTS_MOD_UNCHECKED
                : (state->ML[i] ? *state->ML[i] : HTS_MOD_UNKNOWN);
        }
        n++;

        if (unchecked)
            continue;

        if (state->ML[i])
            state->ML[i] += (b->core.flag & BAM_FREVERSE)
                ? -state->MLstride[i]
                : +state->MLstride[i];

        if (b->core.flag & BAM_FREVERSE) {
            // process MM list backwards
            char *cp;

            if (state->MMend[i]-1 < state->MM[i]) {
                // Should be impossible to hit if coding is correct
                hts_log_error("Assert failed while processing base modification states");
                return -1;
            }
            for (cp = state->MMend[i]-1; cp != state->MM[i]; cp--)
                if (*cp == ',')
                    break;
            state->MMend[i] = cp;
            if (cp != state->MM[i])
                state->MMcount[i] = strtol(cp+1, NULL, 10);
            else
                state->MMcount[i] = INT_MAX;
        } else {
            if (*state->MM[i] == ',')
                state->MMcount[i] = strtol(state->MM[i]+1, &state->MM[i], 10);
            else
                state->MMcount[i] = INT_MAX;
        }

        // Multiple mods at the same coords.
        for (j=i+1; j < state->nmods && state->MM[j] == MMptr; j++) {
            if (n < n_mods) {
                mods[n].modified_base = state->type[j];
                mods[n].canonical_base = seq_nt16_str[state->canonical[j]];
                mods[n].strand = state->strand[j];
                mods[n].qual = state->ML[j] ? *state->ML[j] : -1;
            }
            n++;
            state->MMcount[j] = state->MMcount[i];
            state->MM[j]      = state->MM[i];
            if (state->ML[j])
                state->ML[j] += (b->core.flag & BAM_FREVERSE)
                    ? -state->MLstride[j]
                    : +state->MLstride[j];
        }
        i = j-1;
    }

    return n;
}

// Assembly:
movl 0x2d00(%rsi), %eax
xorl %r10d, %r10d
cmpl 0x18(%rdi), %eax
jge 0x2ab29
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, %r8d
movq %rsi, %r15
movq %rdi, %r14
movl 0x14(%rdi), %ecx
shll $0x2, %ecx
addq 0x38(%rdi), %rcx
movzwl 0x12(%rdi), %esi
addq %rcx, %rsi
movl %eax, %ecx
sarl %ecx
movslq %ecx, %rcx
movzbl (%rcx,%rsi), %esi
leal (,%rax,4), %ecx
notb %cl
andb $0x4, %cl
shrl %cl, %esi
andb $0xf, %sil
incl %eax
movl %eax, 0x2d00(%r15)
testb $0x10, 0x10(%rdi)
je 0x2a812
movzbl %sil, %eax
leaq 0x50282(%rip), %rcx     # 0x7aa90
movb (%rcx,%rax,4), %sil
movzbl %sil, %r9d
leaq 0xd00(%r15), %r11
movslq %r8d, %rax
movq %rax, 0x50(%rsp)
leaq 0xc(%rdx), %rax
movq %rax, 0x30(%rsp)
leaq 0x1d08(%r15), %rax
movq %rax, 0x28(%rsp)
leaq 0x4(%r15), %rax
movq %rax, 0x20(%rsp)
leaq 0x801(%r15), %rax
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
xorl %r10d, %r10d
movl %r8d, 0x8(%rsp)
movq %rdx, 0x40(%rsp)
movl %r9d, 0x4(%rsp)
movq %r11, 0x38(%rsp)
cmpl 0x2d04(%r15), %ebx
jge 0x2ab1b
movslq %ebx, %r12
movl 0x400(%r15,%r12,4), %eax
cmpl %r9d, %eax
setne %cl
cmpl $0xf, %eax
setne %al
testb %al, %cl
jne 0x2aaf8
movl 0x900(%r15,%r12,4), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x900(%r15,%r12,4)
testl %eax, %eax
jle 0x2a8c8
cmpl $0x0, 0x2900(%r15,%r12,4)
jne 0x2aaf8
testb $0x1, 0x2d08(%r15)
je 0x2aaf8
movq (%r11,%r12,8), %rbp
cmpl %r8d, %r10d
jge 0x2a923
movslq %r10d, %rcx
shlq $0x4, %rcx
movl (%r15,%r12,4), %esi
movl %esi, (%rdx,%rcx)
movslq 0x400(%r15,%r12,4), %rsi
leaq 0x4d122(%rip), %rdi     # 0x77a10
movsbl (%rdi,%rsi), %esi
movl %esi, 0x4(%rdx,%rcx)
movsbl 0x800(%r15,%r12), %esi
movl %esi, 0x8(%rdx,%rcx)
pushq $-0x2
popq %rdi
testl %eax, %eax
jg 0x2a91d
movq 0x1d00(%r15,%r12,8), %rsi
pushq $-0x1
popq %rdi
testq %rsi, %rsi
je 0x2a91d
movzbl (%rsi), %edi
addq %rdx, %rcx
movl %edi, 0xc(%rcx)
incl %r10d
testl %eax, %eax
jg 0x2aaf8
movq 0x1d00(%r15,%r12,8), %rcx
movzwl 0x10(%r14), %eax
testq %rcx, %rcx
je 0x2a95f
movl 0x2500(%r15,%r12,4), %edx
movl %edx, %esi
negl %esi
testb $0x10, %al
cmovel %edx, %esi
movslq %esi, %rdx
addq %rdx, %rcx
movq %rcx, 0x1d00(%r15,%r12,8)
leaq (%r11,%r12,8), %rcx
movq %rcx, 0x10(%rsp)
testb $0x10, %al
jne 0x2a982
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpb $0x2c, (%rbp)
jne 0x2a9cf
leaq 0x1(%rbp), %rdi
movq 0x10(%rsp), %rsi
jmp 0x2a9c1
movq 0x1500(%r15,%r12,8), %rdi
decq %rdi
cmpq %rbp, %rdi
jb 0x2aaff
cmpq %rbp, %rdi
je 0x2a9a5
cmpb $0x2c, (%rdi)
je 0x2a9b4
decq %rdi
jmp 0x2a996
movq %rbp, 0x1500(%r15,%r12,8)
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jmp 0x2a9cf
movq %rdi, 0x1500(%r15,%r12,8)
incq %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
movl %r10d, %r13d
callq 0x46d0
movl %r13d, %r10d
movl %eax, 0x900(%r15,%r12,4)
movl %r10d, 0xc(%rsp)
movslq %r10d, %rcx
movq %rcx, %rdx
shlq $0x4, %rdx
addq 0x30(%rsp), %rdx
movq 0x28(%rsp), %rsi
leaq (%rsi,%r12,8), %rdi
movq 0x20(%rsp), %rsi
leaq (%rsi,%r12,4), %r8
movq 0x18(%rsp), %rsi
addq %r12, %rsi
movq %rsi, 0x48(%rsp)
xorl %esi, %esi
leaq (%r12,%rsi), %r10
incq %r10
movslq 0x2d04(%r15), %r11
cmpq %r11, %r10
jge 0x2aada
cmpq %rbp, -0x1000(%rdi,%rsi,8)
jne 0x2aada
leaq (%rcx,%rsi), %r10
cmpq 0x50(%rsp), %r10
jge 0x2aa82
movl (%r8,%rsi,4), %eax
movl %eax, -0xc(%rdx)
movslq 0x400(%r8,%rsi,4), %rax
leaq 0x4cfbe(%rip), %r9      # 0x77a10
movsbl (%r9,%rax), %eax
movl %eax, -0x8(%rdx)
movq 0x48(%rsp), %rax
movsbl (%rax,%rsi), %eax
movl %eax, -0x4(%rdx)
movq (%rdi,%rsi,8), %r10
pushq $-0x1
popq %rax
testq %r10, %r10
je 0x2aa76
movzbl (%r10), %eax
movl %eax, (%rdx)
movl 0x900(%r15,%r12,4), %eax
jmp 0x2aa86
movq (%rdi,%rsi,8), %r10
movl %eax, 0x900(%r8,%rsi,4)
movq 0x10(%rsp), %r9
movq (%r9), %r11
movq %r11, -0x1000(%rdi,%rsi,8)
testq %r10, %r10
je 0x2aace
movzwl 0x10(%r14), %r11d
movl 0x2500(%r8,%rsi,4), %r9d
movq %r14, %r13
movl %r9d, %r14d
negl %r14d
testb $0x10, %r11b
cmovel %r9d, %r14d
movslq %r14d, %r9
movq %r13, %r14
addq %r9, %r10
movq %r10, (%rdi,%rsi,8)
incq %rsi
addq $0x10, %rdx
jmp 0x2aa0c
addl %esi, %ebx
movl 0xc(%rsp), %r10d
addl %esi, %r10d
movl 0x8(%rsp), %r8d
movq 0x40(%rsp), %rdx
movl 0x4(%rsp), %r9d
movq 0x38(%rsp), %r11
incl %ebx
jmp 0x2a868
leaq 0x4ff19(%rip), %rsi     # 0x7aa1f
leaq 0x4ff27(%rip), %rdx     # 0x7aa34
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
pushq $-0x1
popq %r10
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movl %r10d, %eax
retq