// File: /workspace/github_c_makefile_star2_O3/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 %r11d, %r11d
cmpl 0x18(%rdi), %eax
jge 0x34697
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, %r8d
movq %rdx, %r9
movq %rsi, %r15
movq %rdi, %r10
movl 0x14(%rdi), %ecx
shll $0x2, %ecx
addq 0x38(%rdi), %rcx
movzwl 0x12(%rdi), %edx
addq %rcx, %rdx
movl %eax, %ecx
sarl %ecx
movslq %ecx, %rcx
movzbl (%rcx,%rdx), %edx
leal (,%rax,4), %ecx
notb %cl
andb $0x4, %cl
shrl %cl, %edx
andb $0xf, %dl
incl %eax
movl %eax, 0x2d00(%rsi)
testb $0x10, 0x10(%rdi)
je 0x34304
movzbl %dl, %eax
leaq 0x6482f(%rip), %rcx     # 0x98b30
movb (%rcx,%rax,4), %dl
cmpl $0x0, 0x2d04(%r15)
jle 0x34689
movzbl %dl, %ebx
leaq 0xd00(%r15), %rdi
movslq %r8d, %rax
movq %rax, 0x50(%rsp)
leaq 0x1d00(%r15), %rax
movq %rax, 0x40(%rsp)
leaq 0x800(%r15), %rax
movq %rax, 0x38(%rsp)
leaq 0xc(%r9), %rax
movq %rax, 0x30(%rsp)
xorl %r11d, %r11d
xorl %ebp, %ebp
movl %r8d, 0x4(%rsp)
movq %r9, 0x20(%rsp)
movq %r10, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movslq %ebp, %r14
movl 0x400(%r15,%r14,4), %eax
cmpl %ebx, %eax
setne %cl
cmpl $0xf, %eax
setne %al
testb %al, %cl
jne 0x3452b
movl 0x900(%r15,%r14,4), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x900(%r15,%r14,4)
testl %eax, %eax
jle 0x343b0
cmpl $0x0, 0x2900(%r15,%r14,4)
jne 0x3452b
testb $0x1, 0x2d08(%r15)
je 0x3452b
movq (%rdi,%r14,8), %r12
cmpl %r8d, %r11d
jge 0x34414
movslq %r11d, %rcx
shlq $0x4, %rcx
movl (%r15,%r14,4), %edx
movl %edx, (%r9,%rcx)
movslq 0x400(%r15,%r14,4), %rdx
leaq 0x61689(%rip), %rsi     # 0x95a60
movsbl (%rsi,%rdx), %edx
movl %edx, 0x4(%r9,%rcx)
movsbl 0x800(%r15,%r14), %edx
movl %edx, 0x8(%r9,%rcx)
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
testl %eax, %eax
jg 0x3440e
movq 0x1d00(%r15,%r14,8), %rdx
testq %rdx, %rdx
je 0x34409
movzbl (%rdx), %edx
jmp 0x3440e
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
addq %r9, %rcx
movl %edx, 0xc(%rcx)
leal 0x1(%r11), %r13d
testl %eax, %eax
jg 0x34528
movq 0x1d00(%r15,%r14,8), %rcx
movzwl 0x10(%r10), %eax
testq %rcx, %rcx
je 0x34451
movl 0x2500(%r15,%r14,4), %edx
movl %edx, %esi
negl %esi
testb $0x10, %al
cmovel %edx, %esi
movslq %esi, %rdx
addq %rdx, %rcx
movq %rcx, 0x1d00(%r15,%r14,8)
leaq (%rdi,%r14,8), %rcx
movq %rcx, 0x28(%rsp)
testb $0x10, %al
jne 0x344a2
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpb $0x2c, (%r12)
jne 0x3450c
leaq 0x1(%r12), %rdi
movq 0x28(%rsp), %rsi
movl $0xa, %edx
movq %r11, 0x8(%rsp)
callq 0x46d0
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r11
movq 0x18(%rsp), %r10
movq 0x20(%rsp), %r9
movl 0x4(%rsp), %r8d
jmp 0x3450c
movq 0x1500(%r15,%r14,8), %rdi
decq %rdi
cmpq %r12, %rdi
jb 0x34669
je 0x344c8
cmpb $0x2c, (%rdi)
je 0x344d7
decq %rdi
cmpq %r12, %rdi
jne 0x344b8
movq %r12, %rdi
movq %rdi, 0x1500(%r15,%r14,8)
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jmp 0x34507
movq %rdi, 0x1500(%r15,%r14,8)
incq %rdi
xorl %esi, %esi
movl $0xa, %edx
movq %r11, 0x8(%rsp)
callq 0x46d0
movq 0x8(%rsp), %r11
movq 0x18(%rsp), %r10
movq 0x20(%rsp), %r9
movl 0x4(%rsp), %r8d
movq 0x10(%rsp), %rdi
movl %eax, 0x900(%r15,%r14,4)
leaq 0x1(%r14), %rcx
cmpl 0x2d04(%r15), %ecx
jge 0x34528
cmpq %r12, 0x8(%rdi,%r14,8)
je 0x3453f
movl %r13d, %r11d
incl %ebp
cmpl 0x2d04(%r15), %ebp
jl 0x3435e
jmp 0x34689
movq %r11, 0x8(%rsp)
movslq %r13d, %rdx
movq 0x40(%rsp), %rsi
leaq (%rsi,%rcx,8), %rsi
leaq (%r15,%rcx,4), %rdi
movq 0x38(%rsp), %r8
addq %rcx, %r8
movq %r8, 0x48(%rsp)
movq %rdx, %r9
shlq $0x4, %r9
addq 0x30(%rsp), %r9
xorl %r11d, %r11d
movq %r11, %r10
addq %rdx, %r11
cmpq 0x50(%rsp), %r11
jge 0x345ba
movl (%rdi,%r10,4), %eax
movl %eax, -0xc(%r9)
movslq 0x400(%rdi,%r10,4), %rax
leaq 0x614cc(%rip), %r8      # 0x95a60
movsbl (%r8,%rax), %eax
movl %eax, -0x8(%r9)
movq 0x48(%rsp), %rax
movsbl (%rax,%r10), %eax
movl %eax, -0x4(%r9)
movq (%rsi,%r10,8), %r11
testq %r11, %r11
je 0x345c0
movzbl (%r11), %eax
jmp 0x345c5
movq (%rsi,%r10,8), %r11
jmp 0x345d0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, (%r9)
movl 0x900(%r15,%r14,4), %eax
movl %eax, 0x900(%rdi,%r10,4)
movq 0x28(%rsp), %r8
movq (%r8), %r13
movq %r13, -0x1000(%rsi,%r10,8)
testq %r11, %r11
je 0x34617
movq 0x18(%rsp), %r8
movzwl 0x10(%r8), %ebp
movl 0x2500(%rdi,%r10,4), %r8d
movl %r8d, %r13d
negl %r13d
testb $0x10, %bpl
cmovel %r8d, %r13d
movslq %r13d, %r8
addq %r8, %r11
movq %r11, (%rsi,%r10,8)
leaq (%rcx,%r10), %r8
incq %r8
movslq 0x2d04(%r15), %r11
cmpq %r11, %r8
jge 0x34640
leaq 0x1(%r10), %r11
addq $0x10, %r9
cmpq %r12, -0xff8(%rsi,%r10,8)
je 0x34570
leal (%rcx,%r10), %ebp
movq 0x8(%rsp), %r11
addl %r10d, %r11d
addl $0x2, %r11d
movl 0x4(%rsp), %r8d
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x10(%rsp), %rdi
jmp 0x3452b
leaq 0x6444f(%rip), %rsi     # 0x98abf
leaq 0x6445d(%rip), %rdx     # 0x98ad4
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movl %r11d, %eax
retq