// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/cram/cram_index.c
// Function: cram_index_query
cram_index *cram_index_query(cram_fd *fd, int refid, int pos, 
			     cram_index *from) {
    int i, j, k;
    cram_index *e;

    if (refid+1 < 0 || refid+1 >= fd->index_sz)
	return NULL;

    if (!from)
	from = &fd->index[refid+1];

    // Ref with nothing aligned against it.
    if (!from->e)
	return NULL;

    // This sequence is covered by the index, so binary search to find
    // the optimal starting block.
    i = 0, j = fd->index[refid+1].nslice-1;
    for (k = j/2; k != i; k = (j-i)/2 + i) {
	if (from->e[k].refid > refid) {
	    j = k;
	    continue;
	}

	if (from->e[k].refid < refid) {
	    i = k;
	    continue;
	}

	if (from->e[k].start >= pos) {
	    j = k;
	    continue;
	}

	if (from->e[k].start < pos) {
	    i = k;
	    continue;
	}
    }
    // i==j or i==j-1. Check if j is better.
    if (j >= 0 && from->e[j].start < pos && from->e[j].refid == refid)
	i = j;

    /* The above found *a* bin overlapping, but not necessarily the first */
    while (i > 0 && from->e[i-1].end >= pos)
	i--;

    /* We may be one bin before the optimum, so check */
    while (i+1 < from->nslice &&
	   (from->e[i].refid < refid ||
	    from->e[i].end < pos))
	i++;

    e = &from->e[i];

    return e;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
cmpl $0x0, %eax
jl 0x7ac7f
movl -0x14(%rbp), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
cmpl 0x8834(%rcx), %eax
jl 0x7ac8c
movq $0x0, -0x8(%rbp)
jmp 0x7aec9
cmpq $0x0, -0x20(%rbp)
jne 0x7acb2
movq -0x10(%rbp), %rax
movq 0x8838(%rax), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x7acca
movq $0x0, -0x8(%rbp)
jmp 0x7aec9
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x8838(%rax), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
je 0x7adb5
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
cmpl -0x14(%rbp), %eax
jle 0x7ad31
movl -0x2c(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x7ad9c
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
cmpl -0x14(%rbp), %eax
jge 0x7ad54
movl -0x2c(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x7ad9c
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
cmpl -0x18(%rbp), %eax
jl 0x7ad77
movl -0x2c(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x7ad9c
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
cmpl -0x18(%rbp), %eax
jge 0x7ad9a
movl -0x2c(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x7ad9c
jmp 0x7ad9c
movl -0x28(%rbp), %eax
subl -0x24(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x7ad02
cmpl $0x0, -0x28(%rbp)
jl 0x7adf7
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x28(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
cmpl -0x18(%rbp), %eax
jge 0x7adf7
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x28(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x7adf7
movl -0x28(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x7adf9
xorl %eax, %eax
cmpl $0x0, -0x24(%rbp)
movb %al, -0x39(%rbp)
jle 0x7ae28
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
cmpl -0x18(%rbp), %eax
setge %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x7ae31
jmp 0x7ae3c
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x7adf9
jmp 0x7ae3e
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rdx
xorl %eax, %eax
cmpl (%rdx), %ecx
movb %al, -0x3a(%rbp)
jge 0x7ae96
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movb $0x1, %al
cmpl -0x14(%rbp), %ecx
movb %al, -0x3b(%rbp)
jl 0x7ae90
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
cmpl -0x18(%rbp), %eax
setl %al
movb %al, -0x3b(%rbp)
movb -0x3b(%rbp), %al
movb %al, -0x3a(%rbp)
movb -0x3a(%rbp), %al
testb $0x1, %al
jne 0x7ae9f
jmp 0x7aeaa
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x7ae3e
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq
nop