// File: 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:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movl %edx, 0x2c(%rsp)
movl %ecx, 0x28(%rsp)
movl 0x2c(%rsp), %eax
addl 0x28(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x2c(%rsp), %eax
je 0x8c8e
movl 0x24(%rsp), %eax
cmpl 0x28(%rsp), %eax
jne 0x8c9b
movl 0x2c(%rsp), %eax
movl %eax, 0x44(%rsp)
jmp 0x8e3d
movq 0x30(%rsp), %rdi
movslq 0x24(%rsp), %rsi
callq 0x4f70
movq (%rax), %rdi
movq 0x38(%rsp), %rsi
callq 0x8e50
testb $0x1, %al
jne 0x8cc0
jmp 0x8d82
jmp 0x8cc2
movl 0x24(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x30(%rsp), %rdi
callq 0x4f10
movl 0x1c(%rsp), %ecx
movl %eax, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, 0x23(%rsp)
jge 0x8d04
movq 0x30(%rsp), %rdi
movslq 0x24(%rsp), %rsi
callq 0x4f70
movq (%rax), %rdi
movq 0x38(%rsp), %rsi
callq 0x86d0
movb %al, 0x23(%rsp)
movb 0x23(%rsp), %al
testb $0x1, %al
jne 0x8d0e
jmp 0x8d1b
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x8cc2
movl 0x24(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x30(%rsp), %rdi
callq 0x4f10
movq %rax, %rcx
movl 0x18(%rsp), %eax
cmpl %ecx, %eax
jne 0x8d43
movl 0x24(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
jle 0x8d75
movq 0x30(%rsp), %rdi
movslq 0x24(%rsp), %rsi
callq 0x4f70
movq (%rax), %rdi
movq 0x38(%rsp), %rsi
callq 0x86d0
testb $0x1, %al
jne 0x8d75
movl 0x24(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0x44(%rsp)
jmp 0x8e3d
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x30(%rsp), %rdi
movslq 0x24(%rsp), %rsi
callq 0x4f70
movq 0x10(%rsp), %rdi
movq (%rax), %rsi
callq 0x86d0
testb $0x1, %al
jne 0x8dae
jmp 0x8dcb
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movl 0x2c(%rsp), %edx
movl 0x24(%rsp), %ecx
callq 0x8c50
movl %eax, 0x44(%rsp)
jmp 0x8e3d
movq 0x38(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rdi
movslq 0x24(%rsp), %rsi
callq 0x4f70
movq 0x8(%rsp), %rdi
movq (%rax), %rsi
callq 0x86d0
testb $0x1, %al
jne 0x8e12
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movl 0x24(%rsp), %edx
movl 0x28(%rsp), %ecx
callq 0x8c50
movl %eax, 0x44(%rsp)
jmp 0x8e3d
movq 0x121c7(%rip), %rax     # 0x1afe0
movq (%rax), %rdi
leaq 0xbdd5(%rip), %rsi      # 0x14bf8
leaq 0xbdee(%rip), %rdx      # 0x14c18
movl $0x106, %ecx            # imm = 0x106
movb $0x0, %al
callq 0x2240
xorl %edi, %edi
callq 0x21d0
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)