// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/samtools-0.1.18/bam_index.c
// Function: bam_iter_read
int bam_iter_read(bamFile fp, bam_iter_t iter, bam1_t *b)
{
	int ret;
	if (iter && iter->finished) return -1;
	if (iter == 0 || iter->from_first) {
		ret = bam_read1(fp, b);
		if (ret < 0 && iter) iter->finished = 1;
		return ret;
	}
	if (iter->off == 0) return -1;
	for (;;) {
		if (iter->curr_off == 0 || iter->curr_off >= iter->off[iter->i].v) { // then jump to the next chunk
			if (iter->i == iter->n_off - 1) { ret = -1; break; } // no more chunks
			if (iter->i >= 0) assert(iter->curr_off == iter->off[iter->i].v); // otherwise bug
			if (iter->i < 0 || iter->off[iter->i].v != iter->off[iter->i+1].u) { // not adjacent chunks; then seek
				bam_seek(fp, iter->off[iter->i+1].u, SEEK_SET);
				iter->curr_off = bam_tell(fp);
			}
			++iter->i;
		}
		if ((ret = bam_read1(fp, b)) >= 0) {
			iter->curr_off = bam_tell(fp);
			if (b->core.tid != iter->tid || b->core.pos >= iter->end) { // no need to proceed
				ret = bam_validate1(NULL, b)? -1 : -5; // determine whether end of region or error
				break;
			}
			else if (is_overlap(iter->beg, iter->end, b)) return ret;
		} else break; // end of file or error
	}
	iter->finished = 1;
	return ret;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x473d03
movq 0x10(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0x473d03
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
jmp 0x473fa0
cmpq $0x0, 0x10(%rsp)
je 0x473d15
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
je 0x473d50
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x469710
movl %eax, 0x4(%rsp)
cmpl $0x0, 0x4(%rsp)
jge 0x473d43
cmpq $0x0, 0x10(%rsp)
je 0x473d43
movq 0x10(%rsp), %rax
movl $0x1, 0x18(%rax)
movl 0x4(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0x473fa0
movq 0x10(%rsp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x473d69
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
jmp 0x473fa0
jmp 0x473d6b
movq 0x10(%rsp), %rax
cmpq $0x0, 0x20(%rax)
je 0x473da3
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rsp), %rcx
movq 0x28(%rcx), %rcx
movq 0x10(%rsp), %rdx
movslq 0x14(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jb 0x473ecb
movq 0x10(%rsp), %rax
movl 0x14(%rax), %eax
movq 0x10(%rsp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x473dc7
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
jmp 0x473f8c
movq 0x10(%rsp), %rax
cmpl $0x0, 0x14(%rax)
jl 0x473e1d
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rsp), %rcx
movq 0x28(%rcx), %rcx
movq 0x10(%rsp), %rdx
movslq 0x14(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jne 0x473dfc
jmp 0x473e1b
leaq 0x10660b(%rip), %rdi    # 0x57a40e
leaq 0x10662b(%rip), %rsi    # 0x57a435
movl $0x2b0, %edx            # imm = 0x2B0
leaq 0x106648(%rip), %rcx    # 0x57a45e
callq 0x2fdc0
jmp 0x473e1d
movq 0x10(%rsp), %rax
cmpl $0x0, 0x14(%rax)
jl 0x473e68
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x10(%rsp), %rcx
movslq 0x14(%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq 0x10(%rsp), %rcx
movq 0x28(%rcx), %rcx
movq 0x10(%rsp), %rdx
movl 0x14(%rdx), %edx
addl $0x1, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
je 0x473ebd
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x10(%rsp), %rcx
movl 0x14(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
xorl %edx, %edx
callq 0x465b80
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rcx
shlq $0x10, %rcx
movq 0x18(%rsp), %rax
movl 0x3c(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cltq
orq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x10(%rsp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x469710
movl %eax, 0x4(%rsp)
cmpl $0x0, %eax
jl 0x473f85
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rcx
shlq $0x10, %rcx
movq 0x18(%rsp), %rax
movl 0x3c(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cltq
orq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x8(%rsp), %rax
movl (%rax), %eax
movq 0x10(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x473f32
movq 0x8(%rsp), %rax
movl 0x4(%rax), %eax
movq 0x10(%rsp), %rcx
cmpl 0xc(%rcx), %eax
jl 0x473f58
movq 0x8(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x46b310
movl %eax, %edx
movl $0xfffffffb, %eax       # imm = 0xFFFFFFFB
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, 0x4(%rsp)
jmp 0x473f8c
movq 0x10(%rsp), %rax
movl 0x8(%rax), %edi
movq 0x10(%rsp), %rax
movl 0xc(%rax), %esi
movq 0x8(%rsp), %rdx
callq 0x473fb0
cmpl $0x0, %eax
je 0x473f81
movl 0x4(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0x473fa0
jmp 0x473f83
jmp 0x473f87
jmp 0x473f8c
jmp 0x473d6b
movq 0x10(%rsp), %rax
movl $0x1, 0x18(%rax)
movl 0x4(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nopl (%rax)