// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/sam_mods.c
// Function: bam_next_basemod
int bam_next_basemod(const bam1_t *b, hts_base_mod_state *state,
                     hts_base_mod *mods, int n_mods, int *pos) {
    // Look through state->MMcount arrays to see when the next lowest is
    // per base type;
    int next[16], freq[16] = {0}, i;
    memset(next, 0x7f, 16*sizeof(*next));
    const int unchecked = state->flags & HTS_MOD_REPORT_UNCHECKED;
    if (b->core.flag & BAM_FREVERSE) {
        for (i = 0; i < state->nmods; i++) {
            if (unchecked && !state->implicit[i])
                next[seqi_rc[state->canonical[i]]] = 1;
            else if (next[seqi_rc[state->canonical[i]]] > state->MMcount[i])
                next[seqi_rc[state->canonical[i]]] = state->MMcount[i];
        }
    } else {
        for (i = 0; i < state->nmods; i++) {
            if (unchecked && !state->implicit[i])
                next[state->canonical[i]] = 0;
            else if (next[state->canonical[i]] > state->MMcount[i])
                next[state->canonical[i]] = state->MMcount[i];
       }
    }

    // Now step through the sequence counting off base types.
    for (i = state->seq_pos; i < b->core.l_qseq; i++) {
        unsigned char bc = bam_seqi(bam_get_seq(b), i);
        if (next[bc] <= freq[bc] || next[15] <= freq[15])
            break;
        freq[bc]++;
        if (bc != 15) // N
            freq[15]++;
    }
    *pos = state->seq_pos = i;

    if (b->core.flag & BAM_FREVERSE) {
        for (i = 0; i < state->nmods; i++)
            state->MMcount[i] -= freq[seqi_rc[state->canonical[i]]];
    } else {
        for (i = 0; i < state->nmods; i++)
            state->MMcount[i] -= freq[state->canonical[i]];
    }

    if (b->core.l_qseq && state->seq_pos >= b->core.l_qseq &&
        !(b->core.flag & BAM_FREVERSE)) {
        // Spots +ve orientation run-overs.
        // The -ve orientation is spotted in bam_parse_basemod2
        int i;
        for (i = 0; i < state->nmods; i++) {
            // Check if any remaining items in MM after hitting the end
            // of the sequence.
            if (state->MMcount[i] < 0x7f000000 ||
                (*state->MM[i]!=0 && *state->MM[i]!=';')) {
                hts_log_warning("MM tag refers to bases beyond sequence length");
                return -1;
            }
        }
        return 0;
    }

    int r = bam_mods_at_next_pos(b, state, mods, n_mods);
    return r > 0 ? r : 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x4250
leaq -0x70(%rbp), %rdi
movl $0x7f, %esi
movl $0x40, %edx
callq 0x4250
movq -0x18(%rbp), %rax
movl 0x2d08(%rax), %eax
andl $0x1, %eax
movl %eax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x4a958
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x2d04(%rcx), %eax
jge 0x4a953
cmpl $0x0, -0xb8(%rbp)
je 0x4a8d1
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rcx
cmpl $0x0, 0x2900(%rax,%rcx,4)
jne 0x4a8d1
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movslq 0x400(%rax,%rcx,4), %rcx
leaq 0xc2fad(%rip), %rax     # 0x10d870
movslq (%rax,%rcx,4), %rax
movl $0x1, -0x70(%rbp,%rax,4)
jmp 0x4a93d
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movslq 0x400(%rax,%rcx,4), %rcx
leaq 0xc2f85(%rip), %rax     # 0x10d870
movslq (%rax,%rcx,4), %rax
movl -0x70(%rbp,%rax,4), %eax
movq -0x18(%rbp), %rcx
movslq -0xb4(%rbp), %rdx
cmpl 0x900(%rcx,%rdx,4), %eax
jle 0x4a93b
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movl 0x900(%rax,%rcx,4), %ecx
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rdx
movslq 0x400(%rax,%rdx,4), %rdx
leaq 0xc2f3d(%rip), %rax     # 0x10d870
movslq (%rax,%rdx,4), %rax
movl %ecx, -0x70(%rbp,%rax,4)
jmp 0x4a93d
jmp 0x4a93f
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x4a875
jmp 0x4aa21
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x2d04(%rcx), %eax
jge 0x4aa1f
cmpl $0x0, -0xb8(%rbp)
je 0x4a9b3
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rcx
cmpl $0x0, 0x2900(%rax,%rcx,4)
jne 0x4a9b3
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movslq 0x400(%rax,%rcx,4), %rax
movl $0x0, -0x70(%rbp,%rax,4)
jmp 0x4aa09
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movslq 0x400(%rax,%rcx,4), %rax
movl -0x70(%rbp,%rax,4), %eax
movq -0x18(%rbp), %rcx
movslq -0xb4(%rbp), %rdx
cmpl 0x900(%rcx,%rdx,4), %eax
jle 0x4aa07
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movl 0x900(%rax,%rcx,4), %ecx
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rdx
movslq 0x400(%rax,%rdx,4), %rax
movl %ecx, -0x70(%rbp,%rax,4)
jmp 0x4aa09
jmp 0x4aa0b
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x4a962
jmp 0x4aa21
movq -0x18(%rbp), %rax
movl 0x2d00(%rax), %eax
movl %eax, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x4aafa
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
movl -0xb4(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0xb4(%rbp), %ecx
xorl $-0x1, %ecx
andl $0x1, %ecx
shll $0x2, %ecx
sarl %cl, %eax
andl $0xf, %eax
movb %al, -0xb9(%rbp)
movzbl -0xb9(%rbp), %eax
movl -0x70(%rbp,%rax,4), %eax
movzbl -0xb9(%rbp), %ecx
cmpl -0xb0(%rbp,%rcx,4), %eax
jle 0x4aab5
movl -0x34(%rbp), %eax
cmpl -0x74(%rbp), %eax
jg 0x4aab7
jmp 0x4aafa
movzbl -0xb9(%rbp), %eax
movl -0xb0(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0xb0(%rbp,%rax,4)
movzbl -0xb9(%rbp), %eax
cmpl $0xf, %eax
je 0x4aae4
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x4aae6
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x4aa31
movl -0xb4(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x2d00(%rax)
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x4ab8f
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x2d04(%rcx), %eax
jge 0x4ab8d
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movslq 0x400(%rax,%rcx,4), %rcx
leaq 0xc2d1a(%rip), %rax     # 0x10d870
movslq (%rax,%rcx,4), %rax
movl -0xb0(%rbp,%rax,4), %esi
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movl 0x900(%rax,%rcx,4), %edx
subl %esi, %edx
movl %edx, 0x900(%rax,%rcx,4)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x4ab2a
jmp 0x4abf3
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x2d04(%rcx), %eax
jge 0x4abf1
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movslq 0x400(%rax,%rcx,4), %rax
movl -0xb0(%rbp,%rax,4), %esi
movq -0x18(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movl 0x900(%rax,%rcx,4), %edx
subl %esi, %edx
movl %edx, 0x900(%rax,%rcx,4)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x4ab99
jmp 0x4abf3
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x4acdc
movq -0x18(%rbp), %rax
movl 0x2d00(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jl 0x4acdc
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x4acdc
movl $0x0, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x2d04(%rcx), %eax
jge 0x4acd3
movq -0x18(%rbp), %rax
movslq -0xc0(%rbp), %rcx
cmpl $0x7f000000, 0x900(%rax,%rcx,4) # imm = 0x7F000000
jl 0x4ac9a
movq -0x18(%rbp), %rax
movslq -0xc0(%rbp), %rcx
movq 0xd00(%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x4acbd
movq -0x18(%rbp), %rax
movslq -0xc0(%rbp), %rcx
movq 0xd00(%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x3b, %eax
je 0x4acbd
movl $0x3, %edi
leaq 0xa837a(%rip), %rsi     # 0xf3020
leaq 0xa8287(%rip), %rdx     # 0xf2f34
movb $0x0, %al
callq 0x1b030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4ad20
jmp 0x4acbf
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x4ac36
movl $0x0, -0x4(%rbp)
jmp 0x4ad20
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
callq 0x4a180
movl %eax, -0xc4(%rbp)
cmpl $0x0, -0xc4(%rbp)
jle 0x4ad0d
movl -0xc4(%rbp), %eax
movl %eax, -0xc8(%rbp)
jmp 0x4ad17
xorl %eax, %eax
movl %eax, -0xc8(%rbp)
jmp 0x4ad17
movl -0xc8(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)