// File: /workspace/github_cpp_makefile_star2_O3/gersteinlab[P]MUSIC/src/ms_ansi_string.cpp
// Function: t_string::fast_search_string(char*, std::vector<char*, std::allocator<char*>>*, int, int)
int t_string::fast_search_string(char* query, vector<char*>* string_list, int i, int j)
{
	// Sort the string list.
	int i_mid = (i + j) / 2;

	if(i_mid == i ||
		i_mid == j)
	{
		return(i);
	}
	
	if(t_string::compare_strings(string_list->at(i_mid), query))
	{
		while(i_mid < (int)string_list->size() &&
			t_string::sort_strings(string_list->at(i_mid), query))
		{
			i_mid++;
		}

		// If the above loop hit the end, move back once.
		if(i_mid == (int)string_list->size())
		{
			i_mid--;
		}

		// If the above loop moved beyond the query move back once, which is the exact element just before query.
		if(i_mid > 0 &&
			!sort_strings(string_list->at(i_mid), query))
		{
			i_mid--;
		}

		return(i_mid);
	}
	else if(sort_strings(query, string_list->at(i_mid)))
	{
		return(t_string::fast_search_string(query, string_list, i, i_mid));
	}
	else if(!sort_strings(query, string_list->at(i_mid)))
	{
		return(t_string::fast_search_string(query, string_list, i_mid, j));
	}
	else
	{
		fprintf(stderr, "Fast searching failed @ %s(%d)\n", __FILE__, __LINE__);
		exit(0);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %r12d
movl %edx, %r15d
movq %rdi, 0x20(%rsp)
leal (%r12,%r15), %eax
movl %eax, %r14d
shrl $0x1f, %r14d
addl %eax, %r14d
sarl %r14d
cmpl %edx, %r14d
sete %al
cmpl %ecx, %r14d
sete %dl
orb %al, %dl
jne 0x26d30
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
movq %rax, 0x10(%rsp)
subq %rax, %rdx
movq %rdx, 0x18(%rsp)
movq %rdx, %rax
sarq $0x3, %rax
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rbx
movslq %r14d, %r13
cmpq %r13, %rax
jbe 0x26d42
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x26d70
testb %al, %al
jne 0x26cbc
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x267e2
testb %al, %al
jne 0x26c97
movl %r14d, %r15d
jmp 0x26c9a
movl %r14d, %r12d
leal (%r12,%r15), %eax
movl %eax, %r14d
shrl $0x1f, %r14d
addl %eax, %r14d
sarl %r14d
cmpl %r15d, %r14d
movq 0x8(%rsp), %rax
je 0x26d30
cmpl %r12d, %r14d
jne 0x26c5f
jmp 0x26d30
movq 0x8(%rsp), %r12
cmpl %r12d, %r14d
jge 0x26cfc
movq 0x18(%rsp), %rax
shrq $0x3, %rax
movslq %eax, %r14
cmpq %r13, %r12
jbe 0x26d53
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rdi
movq %rbx, %rsi
callq 0x267e2
testb %al, %al
je 0x26cf9
incq %r13
cmpq %r13, %r14
jne 0x26cd2
movl %r12d, %r14d
jmp 0x26cfc
movl %r13d, %r14d
xorl %eax, %eax
cmpl %r12d, %r14d
sete %al
movl %r14d, %r15d
subl %eax, %r15d
testl %r15d, %r15d
jle 0x26d30
movl %r15d, %esi
cmpq %rsi, %r12
jbe 0x26d67
movq 0x10(%rsp), %rax
movq (%rax,%rsi,8), %rdi
movq %rbx, %rsi
callq 0x267e2
xorb $0x1, %al
movzbl %al, %eax
subl %eax, %r15d
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5b87(%rip), %rdi      # 0x2c8d0
movq %r13, %rsi
movq 0x8(%rsp), %rdx
jmp 0x26d60
leaq 0x5b76(%rip), %rdi      # 0x2c8d0
movq %r12, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2270
leaq 0x5b62(%rip), %rdi      # 0x2c8d0
jmp 0x26d5d