// File: /workspace/github_c_makefile_star2_O3/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 0x9b2f
movq %rdi, %rbx
movabsq $0x100000000, %r15      # imm = 0x100000000
callq 0x10b0
movq %rax, %r14
incl %eax
movslq %eax, %r12
leaq 0x10969(%rip), %r13     # 0x1a250
movq (%r13), %r13
testq %r13, %r13
je 0x9908
movq 0x10(%r13), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x1070
testl %eax, %eax
jne 0x98e7
jmp 0x9aaf
movq 0x10961(%rip), %rax     # 0x1a270
testq %rax, %rax
je 0x9971
leaq 0x10(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdx
movl %r14d, %ecx
callq *%rax
testl %eax, %eax
je 0x9971
leaq 0x10(%rsp), %r12
movb $0x0, 0xfff(%r12)
leaq 0x10911(%rip), %r13     # 0x1a250
movq (%r13), %r13
testq %r13, %r13
je 0x9962
movq 0x10(%r13), %rsi
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
callq 0x1070
testl %eax, %eax
jne 0x993f
jmp 0x9aaf
leaq 0x10(%rsp), %rdi
callq 0x2d44
testq %rax, %rax
jne 0x997e
movq %rbx, %rdi
callq 0x2d44
testq %rax, %rax
je 0x9998
movq %rax, %r13
movq 0x108c8(%rip), %rax     # 0x1a250
movq %rax, (%r13)
movq %r13, 0x108bd(%rip)     # 0x1a250
jmp 0x9aaf
cmpb $0x0, 0x108cd(%rip)     # 0x1a26c
jne 0x99da
movb $0x1, 0x108c4(%rip)     # 0x1a26c
leaq 0xa211(%rip), %rdi      # 0x13bc0
callq 0x1030
testq %rax, %rax
je 0x99da
cmpq $0x0, 0x1089f(%rip)     # 0x1a260
je 0x9ac4
leaq 0xa1cb(%rip), %rsi      # 0x13b99
movl $0x7, %edi
xorl %eax, %eax
callq 0xa278
movq 0x1087f(%rip), %r15     # 0x1a260
testq %r15, %r15
je 0x9a96
movl 0x10877(%rip), %r13d    # 0x1a268
leaq 0x10(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r15, %rdx
movl %r13d, %ecx
movq %rbx, %r8
movl %r14d, %r9d
callq 0x9b34
testl %eax, %eax
je 0x9a96
movl %eax, %r12d
leaq 0x10832(%rip), %rax     # 0x1a250
leaq 0x10(%rsp), %rbp
movq %r13, 0x8(%rsp)
movq %rax, %r13
movq (%r13), %r13
testq %r13, %r13
je 0x9a4b
movq 0x10(%r13), %rsi
movl $0x1000, %edx           # imm = 0x1000
movq %rbp, %rdi
callq 0x1070
testl %eax, %eax
jne 0x9a2b
jmp 0x9aaf
movq %rbp, %rdi
callq 0x2d44
testq %rax, %rax
jne 0x997e
movslq %r12d, %rax
addq %rax, %r15
incq %r15
notl %eax
movq 0x8(%rsp), %r13
addl %eax, %r13d
movq %rbp, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r15, %rdx
movl %r13d, %ecx
movq %rbx, %r8
movl %r14d, %r9d
callq 0x9b34
movl %eax, %r12d
testl %eax, %eax
leaq 0x107bc(%rip), %rax     # 0x1a250
jne 0x9a23
leaq 0xa0b0(%rip), %rsi      # 0x13b4d
xorl %r13d, %r13d
movl $0x6, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xa278
movq %r13, %rax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r12
movq %rax, %rdi
callq 0x10b0
movq %rax, %r13
movl %r13d, 0x1078f(%rip)    # 0x1a268
shlq $0x20, %rax
addq %rax, %r15
sarq $0x20, %r15
movq %r15, %rdi
callq 0x1190
movq %rax, 0x1076d(%rip)     # 0x1a260
testq %rax, %rax
je 0x9b0b
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
callq 0x1080
jmp 0x99f1
leaq 0x972a(%rip), %rsi      # 0x1323c
leaq 0xa024(%rip), %rdx      # 0x13b3d
movl $0x7, %edi
movl $0x4a, %ecx
xorl %eax, %eax
callq 0xa278
jmp 0x99da
callq 0x1060