// File: /workspace/github_c_makefile_star2_O2/MikeGray-APH[P]LibLouisAPH/source/lookup.c
// Function: lookup_table
struct table* lookup_table(const char *file_name)
{
	struct table *table;
	char path[PATH_NAME_MAX], *paths;
	int file_name_len, paths_len, len;

	ASSERT(file_name)

	file_name_len = strlen(file_name);

	/*   has table already been loaded   */
	table = find_table(file_name, file_name_len + 1);
	if(table)
		return table;

	/*   try lookup hook   */
	if(lookup_hook)
	if(lookup_hook(path, PATH_NAME_MAX, file_name, file_name_len))
	{
		/*   make sure path is NULL terminated   */
		path[PATH_NAME_MAX - 1] = 0;

		table = find_table(path, PATH_NAME_MAX);
		if(table)
			return table;
		table = table_compile_from_file(path);
		if(table)
			goto return_table;
	}

	/*   try file_name directly   */
	table = table_compile_from_file(file_name);
	if(table)
		goto return_table;

	/*   assume file_name is a base name   */
	check_env();
	if(table_paths)
	{
		paths = table_paths;
		paths_len = table_paths_len;
		while(len = create_path_file_name(path, PATH_NAME_MAX, paths, paths_len, file_name, file_name_len))
		{
			table = find_table(path, PATH_NAME_MAX);
			if(table)
				return table;
			table = table_compile_from_file(path);
			if(table)
				goto return_table;

			len++;
			paths = &paths[len];
			paths_len -= len;
		}
	}

	log_message(LOG_ERROR, "unable to open table %s", file_name);
	return NULL;

	return_table:
	table->nxt = table_list;
	table_list = table;
	return table;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
testq %rdi, %rdi
je 0x8bd1
movq %rdi, %r12
callq 0x10b0
movq %rax, %r14
leal 0x1(%rax), %esi
movq %r12, %rdi
callq 0x8bd6
testq %rax, %rax
je 0x8aaa
movq %rax, %r15
jmp 0x8bbc
movq 0x107cf(%rip), %rax     # 0x19280
testq %rax, %rax
je 0x8af6
leaq 0x10(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r12, %rdx
movl %r14d, %ecx
callq *%rax
testl %eax, %eax
je 0x8af6
leaq 0x10(%rsp), %rdi
movb $0x0, 0xfff(%rdi)
movl $0x1000, %esi           # imm = 0x1000
callq 0x8bd6
testq %rax, %rax
jne 0x8aa2
leaq 0x10(%rsp), %rdi
callq 0x2c04
testq %rax, %rax
jne 0x8b03
movq %r12, %rdi
callq 0x2c04
testq %rax, %rax
je 0x8b1c
movq %rax, %r15
movq 0x10753(%rip), %rax     # 0x19260
movq %rax, (%r15)
movq %r15, 0x10749(%rip)     # 0x19260
jmp 0x8bbc
callq 0x8808
movq 0x10748(%rip), %rax     # 0x19270
testq %rax, %rax
je 0x8ba5
movq %rax, %rdx
movl 0x10742(%rip), %ecx     # 0x19278
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %rdx, %rbx
movl %ecx, 0xc(%rsp)
movq %r12, %r8
movl %r14d, %r9d
callq 0x8c0c
testl %eax, %eax
je 0x8ba5
movl %eax, %r13d
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x8bd6
testq %rax, %rax
jne 0x8aa2
movq %r15, %rdi
movq %r14, %rbp
movq %r15, %r14
callq 0x2c04
testq %rax, %rax
jne 0x8b03
movslq %r13d, %rax
leaq (%rax,%rbx), %rdx
incq %rdx
notl %r13d
movl 0xc(%rsp), %ecx
addl %r13d, %ecx
movq %r14, %r15
movq %rbp, %r14
jmp 0x8b3b
leaq 0x8f11(%rip), %rsi      # 0x11abd
xorl %r15d, %r15d
pushq $0x6
popq %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x9174
movq %r15, %rax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1060