// File: /workspace/github_cpp_makefile_star2_O1/gersteinlab[P]MUSIC/src/ms_annot_region_tools.cpp
// Function: locate_posn_per_sorted_obj_list(void*, std::vector<void*, std::allocator<void*>>*, int, int, int (*)(void*, void*))
int locate_posn_per_sorted_obj_list(void* prop_ptr, vector<void*>* obj_list, int i, int j, int (*comparor)(void*, void*))
{
	int i_mid = (i + j) / 2;

	if(i_mid == i ||
		i_mid == j)
	{
		return(i);
	}

	// If the property of interest is matching the mid point's property, go to the left till posn point to a smaller property.
	if(comparor(obj_list->at(i_mid), prop_ptr) == 1)
	{
		while(i_mid > 0 &&
			comparor(obj_list->at(i_mid), prop_ptr) == 1)
		{
			i_mid--;
		}

		return(i_mid);
	}
	else if(comparor(obj_list->at(i_mid), prop_ptr) > 1)
	{
		// The mid region is higher than the property of interest. Move the mid point to left to get closer to the property of interest.
		return(locate_posn_per_sorted_obj_list(prop_ptr, obj_list, i, i_mid, comparor));
	}
	else if(comparor(obj_list->at(i_mid), prop_ptr) < 1)
	{
		// The mid region is lower than the property of interest. Move the mid point to right to get closer to the property of interest.
		return(locate_posn_per_sorted_obj_list(prop_ptr, obj_list, i_mid, j, comparor));
	}
	else
	{
		fprintf(stderr, "Current indices are (%d, %d) @ %s(%d)\n", comparor(obj_list->at(i), prop_ptr), comparor(obj_list->at(j), prop_ptr),
			__FILE__, __LINE__);
		exit(0);
	}	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, 0x10(%rsp)
movl %ecx, %r13d
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
movl %r12d, %ebp
movl %r13d, %r12d
movl %r12d, %r13d
leal (%r13,%rbp), %r14d
movl %r14d, %r12d
shrl $0x1f, %r12d
addl %r14d, %r12d
sarl %r12d
cmpl %ebp, %r12d
je 0x1c63e
cmpl %r13d, %r12d
je 0x1c63e
movslq %r12d, %rbx
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
jbe 0x1c64f
movq (%rax,%rbx,8), %rdi
movq 0x8(%rsp), %rsi
callq *0x10(%rsp)
cmpl $0x1, %eax
je 0x1c5fb
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
jbe 0x1c64f
movq (%rax,%rbx,8), %rdi
movq 0x8(%rsp), %rsi
callq *0x10(%rsp)
cmpl $0x1, %eax
jg 0x1c4e8
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
jbe 0x1c64f
movq (%rax,%rbx,8), %rdi
movq 0x8(%rsp), %rsi
callq *0x10(%rsp)
testl %eax, %eax
jle 0x1c4e2
movq 0x1da45(%rip), %rax     # 0x39fe0
movq (%rax), %rbx
movslq %ebp, %rsi
movq %r15, %rdi
callq 0x1c842
movq (%rax), %rdi
movq 0x8(%rsp), %r12
movq %r12, %rsi
movq 0x10(%rsp), %r14
callq *%r14
movl %eax, %ebp
movslq %r13d, %rsi
movq %r15, %rdi
callq 0x1c842
movq (%rax), %rdi
movq %r12, %rsi
callq *%r14
leaq 0x128c8(%rip), %rsi     # 0x2eea1
leaq 0x12403(%rip), %r8      # 0x2e9e3
movq %rbx, %rdi
movl %ebp, %edx
movl %eax, %ecx
movl $0xc26, %r9d            # imm = 0xC26
xorl %eax, %eax
callq 0x2250
xorl %edi, %edi
callq 0x21e0
cmpl $0x2, %r14d
jl 0x1c63b
movl %r12d, %esi
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x1c660
movq (%rax,%rsi,8), %rdi
movq 0x8(%rsp), %rsi
callq *0x10(%rsp)
cmpl $0x1, %eax
jne 0x1c63b
leal -0x1(%r12), %eax
cmpl $0x1, %r12d
movl %eax, %r12d
jg 0x1c601
xorl %ebp, %ebp
jmp 0x1c63e
movl %r12d, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11280(%rip), %rdi     # 0x2d8d6
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2270
leaq 0x1126f(%rip), %rdi     # 0x2d8d6
jmp 0x1c659