// File: /workspace/github_cpp_makefile_star2_O3/akdess[P]BAFExtract/src/ansi_string.cpp
// Function: t_string::fast_search_string_per_prefix(char*, std::vector<char*, std::allocator<char*>>*, int, int)
int t_string::fast_search_string_per_prefix(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_per_prefix(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 &&
			!t_string::sort_strings_per_prefix(string_list->at(i_mid), query))
		{
			i_mid--;
		}

		return(i_mid);
	}
	else if(t_string::sort_strings_per_prefix(query, string_list->at(i_mid)))
	{
		return(t_string::fast_search_string_per_prefix(query, string_list, i, i_mid));
	}
	else if(!t_string::sort_strings_per_prefix(query, string_list->at(i_mid)))
	{
		return(t_string::fast_search_string_per_prefix(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 0x585c
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 0x586e
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x589c
testb %al, %al
jne 0x57e8
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x520a
testb %al, %al
jne 0x57c3
movl %r14d, %r15d
jmp 0x57c6
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 0x585c
cmpl %r12d, %r14d
jne 0x578b
jmp 0x585c
movq 0x8(%rsp), %r12
cmpl %r12d, %r14d
jge 0x5828
movq 0x18(%rsp), %rax
shrq $0x3, %rax
movslq %eax, %r14
cmpq %r13, %r12
jbe 0x587f
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rdi
movq %rbx, %rsi
callq 0x520a
testb %al, %al
je 0x5825
incq %r13
cmpq %r13, %r14
jne 0x57fe
movl %r12d, %r14d
jmp 0x5828
movl %r13d, %r14d
xorl %eax, %eax
cmpl %r12d, %r14d
sete %al
movl %r14d, %r15d
subl %eax, %r15d
testl %r15d, %r15d
jle 0x585c
movl %r15d, %esi
cmpq %rsi, %r12
jbe 0x5893
movq 0x10(%rsp), %rax
movq (%rax,%rsi,8), %rdi
movq %rbx, %rsi
callq 0x520a
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 0x50ef(%rip), %rdi      # 0xa964
movq %r13, %rsi
movq 0x8(%rsp), %rdx
jmp 0x588c
leaq 0x50de(%rip), %rdi      # 0xa964
movq %r12, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2250
leaq 0x50ca(%rip), %rdi      # 0xa964
jmp 0x5889