// File: /workspace/github_c_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl 0x2d00(%rsi), %eax
xorl %r13d, %r13d
cmpl 0x18(%rdi), %eax
jge 0x35a98
movl %ecx, %r10d
movq %rdx, %r8
movq %rsi, %r15
movq %rdi, %r12
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 0x356a5
movzbl %dl, %eax
leaq 0x6647e(%rip), %rcx     # 0x9bb20
movb (%rcx,%rax,4), %dl
cmpl $0x0, 0x2d04(%r15)
jle 0x35a98
movzbl %dl, %ebp
leaq 0xd00(%r15), %r9
movslq %r10d, %rax
movq %rax, 0x50(%rsp)
leaq 0x1d00(%r15), %rax
movq %rax, 0x48(%rsp)
leaq 0x2500(%r15), %rax
movq %rax, 0x40(%rsp)
leaq 0x800(%r15), %rax
movq %rax, 0x38(%rsp)
leaq 0xc(%r8), %rax
movq %rax, 0x30(%rsp)
xorl %r13d, %r13d
xorl %ebx, %ebx
movl %r10d, 0x4(%rsp)
movq %r8, 0x10(%rsp)
movq %r12, 0x28(%rsp)
movslq %ebx, %r14
movl 0x400(%r15,%r14,4), %eax
cmpl %ebp, %eax
setne %cl
cmpl $0xf, %eax
setne %dl
movl $0x4, %eax
testb %dl, %cl
jne 0x357c0
movl 0x900(%r15,%r14,4), %ecx
leal -0x1(%rcx), %edx
movl %edx, 0x900(%r15,%r14,4)
testl %ecx, %ecx
jle 0x35755
cmpl $0x0, 0x2900(%r15,%r14,4)
jne 0x357c0
testb $0x1, 0x2d08(%r15)
je 0x357c0
movq (%r9,%r14,8), %r11
cmpl %r10d, %r13d
jge 0x357b9
movslq %r13d, %rdx
shlq $0x4, %rdx
movl (%r15,%r14,4), %esi
movl %esi, (%r8,%rdx)
movslq 0x400(%r15,%r14,4), %rsi
leaq 0x63234(%rip), %rdi     # 0x989b0
movsbl (%rdi,%rsi), %esi
movl %esi, 0x4(%r8,%rdx)
movsbl 0x800(%r15,%r14), %esi
movl %esi, 0x8(%r8,%rdx)
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
testl %ecx, %ecx
jg 0x357b3
movq 0x1d00(%r15,%r14,8), %rsi
testq %rsi, %rsi
je 0x357ae
movzbl (%rsi), %esi
jmp 0x357b3
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
addq %r8, %rdx
movl %esi, 0xc(%rdx)
incl %r13d
testl %ecx, %ecx
jle 0x357dc
testb $0x3, %al
jne 0x35a92
incl %ebx
cmpl 0x2d04(%r15), %ebx
jl 0x35706
jmp 0x35a98
movq 0x1d00(%r15,%r14,8), %rax
testq %rax, %rax
je 0x35813
testb $0x10, 0x10(%r12)
jne 0x357fb
movl 0x2500(%r15,%r14,4), %ecx
jmp 0x35805
xorl %ecx, %ecx
subl 0x2500(%r15,%r14,4), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x1d00(%r15,%r14,8)
testb $0x10, 0x10(%r12)
movq %r11, 0x18(%rsp)
jne 0x35865
leaq (%r9,%r14,8), %rsi
movq (%rsi), %rdi
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpb $0x2c, (%rdi)
jne 0x35858
incq %rdi
movl $0xa, %edx
movq %r9, %r12
callq 0x46d0
movq 0x18(%rsp), %r11
movl 0x4(%rsp), %r10d
movq %r12, %r9
movq 0x10(%rsp), %r8
movq 0x28(%rsp), %r12
movl %eax, 0x900(%r15,%r14,4)
jmp 0x35957
movq 0x1500(%r15,%r14,8), %rax
leaq -0x1(%rax), %rsi
movq 0xd00(%r15,%r14,8), %r12
cmpq %r12, %rsi
jae 0x358bb
movl $0x1, %edi
movq %rsi, 0x20(%rsp)
leaq 0x66220(%rip), %rsi     # 0x9baaf
leaq 0x6622e(%rip), %rdx     # 0x9bac4
xorl %eax, %eax
movq %r9, 0x8(%rsp)
callq 0x14378
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %r11
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %r8
jmp 0x3593f
sete %cl
movq %rsi, %rdx
je 0x3592a
cmpb $0x2c, -0x1(%rax)
movq %rsi, %rdi
je 0x358e7
addq $-0x2, %rax
cmpq %r12, %rax
sete %cl
je 0x35927
leaq -0x1(%rax), %rdi
cmpb $0x2c, (%rax)
movq %rdi, %rax
jne 0x358d0
incq %rdi
movq %rdi, 0x1500(%r15,%r14,8)
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
testb %cl, %cl
jne 0x35937
incq %rdi
movq %rsi, 0x20(%rsp)
xorl %esi, %esi
movl $0xa, %edx
movq %r9, 0x8(%rsp)
callq 0x46d0
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %r11
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %r8
jmp 0x35937
movq %r12, %rdx
movq %rdx, 0x1500(%r15,%r14,8)
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, 0x900(%r15,%r14,4)
movl $0x1, %eax
cmpq %r12, %rsi
movl 0x4(%rsp), %r10d
movq 0x28(%rsp), %r12
jb 0x357c0
leaq 0x1(%r14), %rcx
xorl %eax, %eax
cmpl 0x2d04(%r15), %ecx
jge 0x357c0
movslq %r13d, %r13
cmpq %r11, 0x8(%r9,%r14,8)
jne 0x357c0
movq %r9, 0x8(%rsp)
movq 0x48(%rsp), %rdx
leaq (%rdx,%rcx,8), %rdx
movq 0x40(%rsp), %rsi
leaq (%rsi,%rcx,4), %rsi
movq 0x38(%rsp), %rdi
addq %rcx, %rdi
movq %r13, %r9
shlq $0x4, %r9
addq 0x30(%rsp), %r9
xorl %r10d, %r10d
movq %r10, %r8
addq %r13, %r10
cmpq 0x50(%rsp), %r10
jge 0x359f8
movl -0x2500(%rsi,%r8,4), %r10d
movl %r10d, -0xc(%r9)
movslq -0x2100(%rsi,%r8,4), %r10
leaq 0x62fe2(%rip), %r11     # 0x989b0
movsbl (%r11,%r10), %r10d
movl %r10d, -0x8(%r9)
movsbl (%rdi,%r8), %r10d
movl %r10d, -0x4(%r9)
movq (%rdx,%r8,8), %r10
testq %r10, %r10
je 0x359ef
movzbl (%r10), %r10d
jmp 0x359f5
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movl %r10d, (%r9)
movl 0x900(%r15,%r14,4), %r10d
movl %r10d, -0x1c00(%rsi,%r8,4)
movq 0xd00(%r15,%r14,8), %r10
movq %r10, -0x1000(%rdx,%r8,8)
movq (%rdx,%r8,8), %r10
testq %r10, %r10
je 0x35a40
testb $0x10, 0x10(%r12)
jne 0x35a2f
movl (%rsi,%r8,4), %r11d
jmp 0x35a36
xorl %r11d, %r11d
subl (%rsi,%r8,4), %r11d
movslq %r11d, %r11
addq %r11, %r10
movq %r10, (%rdx,%r8,8)
leaq (%rcx,%r8), %r10
incq %r10
movslq 0x2d04(%r15), %r11
cmpq %r11, %r10
jge 0x35a73
leaq 0x1(%r8), %r10
addq $0x10, %r9
movq 0x18(%rsp), %r11
cmpq %r11, -0xff8(%rdx,%r8,8)
je 0x359a6
addl %r10d, %ebx
jmp 0x35a78
addl %r8d, %ebx
incl %ebx
addq %r8, %r13
incq %r13
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r9
movl 0x4(%rsp), %r10d
jmp 0x357c0
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl %r13d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq