// File: /workspace/github_c_makefile_star2_O0/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 (b->core.flag & BAM_FREVERSE) {
        if (state->seq_pos < 0)
            return -1;
    } else {
        if (state->seq_pos >= b->core.l_qseq)
            return -1;
    }

    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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x4a1c2
movq -0x18(%rbp), %rax
cmpl $0x0, 0x2d00(%rax)
jge 0x4a1c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4a7ed
jmp 0x4a1e3
movq -0x18(%rbp), %rax
movl 0x2d00(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jl 0x4a1e1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4a7ed
jmp 0x4a1e3
movl $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
shll $0x2, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movl 0x2d00(%rcx), %ecx
sarl %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movl 0x2d00(%rcx), %ecx
xorl $-0x1, %ecx
andl $0x1, %ecx
shll $0x2, %ecx
sarl %cl, %eax
andl $0xf, %eax
movb %al, -0x31(%rbp)
movq -0x18(%rbp), %rax
movl 0x2d00(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x2d00(%rax)
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x4a273
movzbl -0x31(%rbp), %eax
movl %eax, %ecx
leaq 0xc3603(%rip), %rax     # 0x10d870
movl (%rax,%rcx,4), %eax
movb %al, -0x31(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x2d04(%rcx), %eax
jge 0x4a7e7
movl $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl 0x400(%rax,%rcx,4), %eax
movzbl -0x31(%rbp), %ecx
cmpl %ecx, %eax
je 0x4a2c2
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
cmpl $0xf, 0x400(%rax,%rcx,4)
je 0x4a2c2
jmp 0x4a7d9
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movl 0x900(%rcx,%rdx,4), %eax
movl %eax, %esi
addl $-0x1, %esi
movl %esi, 0x900(%rcx,%rdx,4)
cmpl $0x0, %eax
jle 0x4a316
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
cmpl $0x0, 0x2900(%rax,%rcx,4)
jne 0x4a30f
movq -0x18(%rbp), %rax
movl 0x2d08(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4a30f
movl $0x1, -0x38(%rbp)
jmp 0x4a314
jmp 0x4a7d9
jmp 0x4a316
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq 0xd00(%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x4a401
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movslq 0x400(%rax,%rcx,4), %rcx
leaq 0xa58c7(%rip), %rax     # 0xefc30
movsbl (%rax,%rcx), %ecx
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movsbl 0x800(%rax,%rcx), %ecx
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
cmpl $0x0, -0x38(%rbp)
je 0x4a3b1
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
movl %eax, -0x4c(%rbp)
jmp 0x4a3ec
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
cmpq $0x0, 0x1d00(%rax,%rcx,8)
je 0x4a3dc
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq 0x1d00(%rax,%rcx,8), %rax
movzbl (%rax), %eax
movl %eax, -0x50(%rbp)
jmp 0x4a3e6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x50(%rbp)
jmp 0x4a3e6
movl -0x50(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %ecx
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x4a415
jmp 0x4a7d9
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
cmpq $0x0, 0x1d00(%rax,%rcx,8)
je 0x4a481
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x4a44e
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
xorl %eax, %eax
subl 0x2500(%rcx,%rdx,4), %eax
movl %eax, -0x54(%rbp)
jmp 0x4a460
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl 0x2500(%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %esi
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq 0x1d00(%rax,%rcx,8), %rdx
movslq %esi, %rsi
addq %rsi, %rdx
movq %rdx, 0x1d00(%rax,%rcx,8)
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x4a595
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq 0x1500(%rax,%rcx,8), %rax
addq $-0x1, %rax
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
cmpq 0xd00(%rcx,%rdx,8), %rax
jae 0x4a4e1
movl $0x1, %edi
leaq 0xa8b0c(%rip), %rsi     # 0xf2fd3
leaq 0xa8b1a(%rip), %rdx     # 0xf2fe8
movb $0x0, %al
callq 0x1b030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4a7ed
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq 0x1500(%rax,%rcx,8), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
cmpq 0xd00(%rcx,%rdx,8), %rax
je 0x4a52d
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2c, %eax
jne 0x4a51d
jmp 0x4a52d
jmp 0x4a51f
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x4a4f9
movq -0x48(%rbp), %rdx
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq %rdx, 0x1500(%rax,%rcx,8)
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
cmpq 0xd00(%rcx,%rdx,8), %rax
je 0x4a580
movq -0x48(%rbp), %rdi
addq $0x1, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x46a0
movl %eax, %edx
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl %edx, 0x900(%rax,%rcx,4)
jmp 0x4a593
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl $0x7fffffff, 0x900(%rax,%rcx,4) # imm = 0x7FFFFFFF
jmp 0x4a609
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq 0xd00(%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2c, %eax
jne 0x4a5f4
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq 0xd00(%rax,%rcx,8), %rdi
addq $0x1, %rdi
movq -0x18(%rbp), %rsi
addq $0xd00, %rsi            # imm = 0xD00
movslq -0x28(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movl $0xa, %edx
callq 0x46a0
movl %eax, %edx
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl %edx, 0x900(%rax,%rcx,4)
jmp 0x4a607
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl $0x7fffffff, 0x900(%rax,%rcx,4) # imm = 0x7FFFFFFF
jmp 0x4a609
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpl 0x2d04(%rdx), %ecx
movb %al, -0x55(%rbp)
jge 0x4a640
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq 0xd00(%rax,%rcx,8), %rax
cmpq -0x40(%rbp), %rax
sete %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %al
testb $0x1, %al
jne 0x4a64c
jmp 0x4a7d0
movl -0x30(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x4a70d
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movslq 0x400(%rax,%rcx,4), %rcx
leaq 0xa55a5(%rip), %rax     # 0xefc30
movsbl (%rax,%rcx), %ecx
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsbl 0x800(%rax,%rcx), %ecx
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cmpq $0x0, 0x1d00(%rax,%rcx,8)
je 0x4a6ee
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq 0x1d00(%rax,%rcx,8), %rax
movzbl (%rax), %eax
movl %eax, -0x5c(%rbp)
jmp 0x4a6f8
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x5c(%rbp)
jmp 0x4a6f8
movl -0x5c(%rbp), %ecx
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl 0x900(%rax,%rcx,4), %edx
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl %edx, 0x900(%rax,%rcx,4)
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq 0xd00(%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq %rdx, 0xd00(%rax,%rcx,8)
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cmpq $0x0, 0x1d00(%rax,%rcx,8)
je 0x4a7c0
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x4a78d
movq -0x18(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
xorl %eax, %eax
subl 0x2500(%rcx,%rdx,4), %eax
movl %eax, -0x60(%rbp)
jmp 0x4a79f
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl 0x2500(%rax,%rcx,4), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %esi
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq 0x1d00(%rax,%rcx,8), %rdx
movslq %esi, %rsi
addq %rsi, %rdx
movq %rdx, 0x1d00(%rax,%rcx,8)
jmp 0x4a7c2
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4a612
movl -0x2c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x4a27a
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)