// File: /workspace/github_c_makefile_star2_O1/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 0x9c2d
movq %rdi, %rbx
movabsq $0x100000000, %r15      # imm = 0x100000000
callq 0x10b0
movq %rax, 0x8(%rsp)
incl %eax
movslq %eax, %r14
leaq 0x10864(%rip), %r12     # 0x1a250
movq (%r12), %r12
testq %r12, %r12
je 0x9a0b
movq 0x10(%r12), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1070
testl %eax, %eax
jne 0x99ec
jmp 0x9a0e
xorl %r12d, %r12d
testq %r12, %r12
jne 0x9c18
movq 0x10852(%rip), %rax     # 0x1a270
testq %rax, %rax
je 0x9a8b
leaq 0x10(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdx
movq 0x8(%rsp), %rcx
callq *%rax
testl %eax, %eax
je 0x9a8b
leaq 0x10(%rsp), %r14
movb $0x0, 0xfff(%r14)
leaq 0x10801(%rip), %r12     # 0x1a250
movq (%r12), %r12
testq %r12, %r12
je 0x9a70
movq 0x10(%r12), %rsi
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
callq 0x1070
testl %eax, %eax
jne 0x9a4f
jmp 0x9a73
xorl %r12d, %r12d
testq %r12, %r12
jne 0x9c18
leaq 0x10(%rsp), %rdi
callq 0x2de4
testq %rax, %rax
jne 0x9a98
movq %rbx, %rdi
callq 0x2de4
testq %rax, %rax
je 0x9ab2
movq %rax, %r12
movq 0x107ae(%rip), %rax     # 0x1a250
movq %rax, (%r12)
movq %r12, 0x107a3(%rip)     # 0x1a250
jmp 0x9c18
cmpb $0x0, 0x107b3(%rip)     # 0x1a26c
jne 0x9b52
movb $0x1, 0x107a6(%rip)     # 0x1a26c
leaq 0xa023(%rip), %rdi      # 0x13af0
callq 0x1030
testq %rax, %rax
je 0x9b52
cmpq $0x0, 0x10781(%rip)     # 0x1a260
je 0x9af6
leaq 0x9fe1(%rip), %rsi      # 0x13ac9
movl $0x7, %edi
xorl %eax, %eax
callq 0xa36c
jmp 0x9b52
movq %rax, %r14
movq %rax, %rdi
callq 0x10b0
movl %eax, 0x10761(%rip)     # 0x1a268
shlq $0x20, %rax
addq %rax, %r15
sarq $0x20, %r15
movq %r15, %rdi
callq 0x1180
movq %rax, 0x1073f(%rip)     # 0x1a260
testq %rax, %rax
je 0x9b33
movq %rax, %rdi
movq %r14, %rsi
callq 0x1080
jmp 0x9b52
leaq 0x96ba(%rip), %rsi      # 0x131f4
leaq 0x9f2c(%rip), %rdx      # 0x13a6d
movl $0x7, %edi
movl $0x4a, %ecx
xorl %eax, %eax
callq 0xa36c
movq 0x10707(%rip), %r15     # 0x1a260
testq %r15, %r15
je 0x9bff
movl 0x10700(%rip), %ebp     # 0x1a268
leaq 0x10(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r15, %rdx
movl %ebp, %ecx
movq %rbx, %r8
movq 0x8(%rsp), %r9
callq 0x9c32
testl %eax, %eax
je 0x9bff
movl %eax, %r14d
leaq 0x10(%rsp), %r13
leaq 0x106b9(%rip), %r12     # 0x1a250
movq (%r12), %r12
testq %r12, %r12
je 0x9bb8
movq 0x10(%r12), %rsi
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
callq 0x1070
testl %eax, %eax
jne 0x9b97
jmp 0x9bbb
xorl %r12d, %r12d
testq %r12, %r12
jne 0x9c18
movq %r13, %rdi
callq 0x2de4
testq %rax, %rax
jne 0x9a98
movslq %r14d, %rax
addq %rax, %r15
incq %r15
notl %eax
addl %eax, %ebp
movq %r13, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r15, %rdx
movl %ebp, %ecx
movq %rbx, %r8
movq 0x8(%rsp), %r9
callq 0x9c32
movl %eax, %r14d
testl %eax, %eax
jne 0x9b90
leaq 0x9e77(%rip), %rsi      # 0x13a7d
xorl %r12d, %r12d
movl $0x6, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xa36c
movq %r12, %rax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1060