// File: gersteinlab[P]MUSIC/src/ms_annot_region_tools.cpp
// Function: locate_posn_per_sorted_obj_list(int, std::vector<void*, std::allocator<void*>>*, int, int, int (*)(void*))
int locate_posn_per_sorted_obj_list(int posn, vector<void*>* obj_list, int i, int j, int (*prop_accession)(void*))
{
	int i_mid = (i + j) / 2;

	if(i_mid == i ||
		i_mid == j)
	{
		return(i);
	}

	if(prop_accession(obj_list->at(i_mid)) == posn)
	{
		// Move back while the entry is larger than or equal to the requestd position.
		while(i_mid > 0 &&
			prop_accession(obj_list->at(i_mid)) >= posn)
		{
			i_mid--;
		}

		return(i_mid);
	}
	else if(prop_accession(obj_list->at(i_mid)) > posn)
	{
		return(locate_posn_per_sorted_obj_list(posn, obj_list, i, i_mid, prop_accession));
	}
	else if(prop_accession(obj_list->at(i_mid)) < posn)
	{
		return(locate_posn_per_sorted_obj_list(posn, obj_list, i_mid, j, prop_accession));
	}
	else
	{
		fprintf(stderr, "Current indices are (%d, %d), searching for %d @ %s(%d)\n", prop_accession(obj_list->at(i)), prop_accession(obj_list->at(j)),
			posn, __FILE__, __LINE__);
		exit(0);
	}	
}

// Assembly:
subq $0x78, %rsp
movl %edi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movl %edx, 0x64(%rsp)
movl %ecx, 0x60(%rsp)
movq %r8, 0x58(%rsp)
movl 0x64(%rsp), %eax
addl 0x60(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0x64(%rsp), %eax
je 0x31b22
movl 0x54(%rsp), %eax
cmpl 0x60(%rsp), %eax
jne 0x31b2f
movl 0x64(%rsp), %eax
movl %eax, 0x74(%rsp)
jmp 0x31cf1
movq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x68(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0x31db0
movq %rax, %rcx
movq 0x48(%rsp), %rax
movq (%rcx), %rdi
callq *%rax
cmpl 0x70(%rsp), %eax
jne 0x31bbf
jmp 0x31b5d
xorl %eax, %eax
cmpl $0x0, 0x54(%rsp)
movb %al, 0x47(%rsp)
jle 0x31b9b
movq 0x58(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x68(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0x31db0
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq (%rcx), %rdi
callq *%rax
cmpl 0x70(%rsp), %eax
setge %al
movb %al, 0x47(%rsp)
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x31ba5
jmp 0x31bb2
movl 0x54(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x31b5d
movl 0x54(%rsp), %eax
movl %eax, 0x74(%rsp)
jmp 0x31cf1
movq 0x58(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x68(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0x31db0
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq (%rcx), %rdi
callq *%rax
cmpl 0x70(%rsp), %eax
jle 0x31c0f
movl 0x70(%rsp), %edi
movq 0x68(%rsp), %rsi
movl 0x64(%rsp), %edx
movl 0x54(%rsp), %ecx
movq 0x58(%rsp), %r8
callq 0x31ae0
movl %eax, 0x74(%rsp)
jmp 0x31cf1
movq 0x58(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x68(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0x31db0
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq (%rcx), %rdi
callq *%rax
cmpl 0x70(%rsp), %eax
jge 0x31c5f
movl 0x70(%rsp), %edi
movq 0x68(%rsp), %rsi
movl 0x54(%rsp), %edx
movl 0x60(%rsp), %ecx
movq 0x58(%rsp), %r8
callq 0x31ae0
movl %eax, 0x74(%rsp)
jmp 0x31cf1
movq 0x3337a(%rip), %rax     # 0x64fe0
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x68(%rsp), %rdi
movslq 0x64(%rsp), %rsi
callq 0x31db0
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq (%rcx), %rdi
callq *%rax
movl %eax, 0x24(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x68(%rsp), %rdi
movslq 0x60(%rsp), %rsi
callq 0x31db0
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq (%rcx), %rdi
callq *%rax
movq 0x18(%rsp), %rdi
movl 0x24(%rsp), %edx
movl %eax, %ecx
movl 0x70(%rsp), %r8d
leaq 0x2459b(%rip), %rsi     # 0x56270
leaq 0x240c7(%rip), %r9      # 0x55da3
movl $0xc4d, (%rsp)          # imm = 0xC4D
movb $0x0, %al
callq 0x2250
xorl %edi, %edi
callq 0x21f0
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopw (%rax,%rax)