// File: karel-brinda[P]ococo/ext/htslib/sam.c
// Function: bam_plp_push
int bam_plp_push(bam_plp_t iter, const bam1_t *b)
{
    if (iter->error) return -1;
    if (b) {
        if (b->core.tid < 0) { overlap_remove(iter, b); return 0; }
        // Skip only unmapped reads here, any additional filtering must be done in iter->func
        if (b->core.flag & BAM_FUNMAP) { overlap_remove(iter, b); return 0; }
        if (iter->tid == b->core.tid && iter->pos == b->core.pos && iter->mp->cnt > iter->maxcnt)
        {
            overlap_remove(iter, b);
            return 0;
        }
        bam_copy1(&iter->tail->b, b);
        overlap_push(iter, iter->tail);
#ifndef BAM_NO_ID
        iter->tail->b.id = iter->id++;
#endif
        iter->tail->beg = b->core.pos;
        iter->tail->end = bam_endpos(b);
        iter->tail->s = g_cstate_null; iter->tail->s.end = iter->tail->end - 1; // initialize cstate_t
        if (b->core.tid < iter->max_tid) {
            fprintf(stderr, "[bam_pileup_core] the input is not sorted (chromosomes out of order)\n");
            iter->error = 1;
            return -1;
        }
        if ((b->core.tid == iter->max_tid) && (iter->tail->beg < iter->max_pos)) {
            fprintf(stderr, "[bam_pileup_core] the input is not sorted (reads out of order)\n");
            iter->error = 1;
            return -1;
        }
        iter->max_tid = b->core.tid; iter->max_pos = iter->tail->beg;
        if (iter->tail->end > iter->pos || iter->tail->b.core.tid > iter->tid) {
            iter->tail->next = mp_alloc(iter->mp);
            iter->tail = iter->tail->next;
        }
    } else iter->is_eof = 1;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x22266
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x224c9
cmpq $0x0, -0x18(%rbp)
je 0x224b7
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jge 0x22293
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x21b10
movl $0x0, -0x4(%rbp)
jmp 0x224c9
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0x4, %eax
cmpl $0x0, %eax
je 0x222c6
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x21b10
movl $0x0, -0x4(%rbp)
jmp 0x224c9
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x22310
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x22310
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x34(%rcx), %eax
jle 0x22310
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x21b10
movl $0x0, -0x4(%rbp)
jmp 0x224c9
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x1b650
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x224e0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %ecx, 0x38(%rax)
movq -0x18(%rbp), %rdi
callq 0x1b880
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %ecx, 0x3c(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x6825c(%rip), %rcx     # 0x8a5e4
movq %rcx, 0x40(%rax)
movq 0x68259(%rip), %rcx     # 0x8a5ec
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x3c(%rax), %ecx
subl $0x1, %ecx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %ecx, 0x4c(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x223ee
movq 0x67c0a(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
leaq 0x594c6(%rip), %rsi     # 0x7b896
movb $0x0, %al
callq 0x4830
movq -0x10(%rbp), %rax
movl $0x1, 0x30(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x224c9
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jne 0x22440
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x38(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jge 0x22440
movq 0x67bb8(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
leaq 0x594ba(%rip), %rsi     # 0x7b8dc
movb $0x0, %al
callq 0x4830
movq -0x10(%rbp), %rax
movl $0x1, 0x30(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x224c9
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x38(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x3c(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jg 0x22486
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jle 0x224b5
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x214b0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x50(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x50(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x224c2
movq -0x10(%rbp), %rax
movl $0x1, 0x28(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)