// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1040, %rsp           # imm = 0x1040
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xea0b
callq 0x1050
movq -0x10(%rbp), %rdi
callq 0x10a0
movl %eax, -0x102c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x102c(%rbp), %esi
addl $0x1, %esi
callq 0xec10
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xea44
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xec03
cmpq $0x0, 0x17804(%rip)     # 0x26250
je 0xeabf
movq 0x177fb(%rip), %rax     # 0x26250
leaq -0x1020(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl -0x102c(%rbp), %ecx
movl $0x1000, %esi           # imm = 0x1000
callq *%rax
cmpl $0x0, %eax
je 0xeabd
movb $0x0, -0x21(%rbp)
leaq -0x1020(%rbp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0xec10
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xea9f
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xec03
leaq -0x1020(%rbp), %rdi
callq 0x4920
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xeabb
jmp 0xebe2
jmp 0xeabd
jmp 0xeabf
movq -0x10(%rbp), %rdi
callq 0x4920
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xead8
jmp 0xebe2
callq 0xe720
cmpq $0x0, 0x1775b(%rip)     # 0x26240
je 0xebc1
movq 0x1774e(%rip), %rax     # 0x26240
movq %rax, -0x1028(%rbp)
movl 0x17749(%rip), %eax     # 0x26248
movl %eax, -0x1030(%rbp)
leaq -0x1020(%rbp), %rdi
movq -0x1028(%rbp), %rdx
movl -0x1030(%rbp), %ecx
movq -0x10(%rbp), %r8
movl -0x102c(%rbp), %r9d
movl $0x1000, %esi           # imm = 0x1000
callq 0xec80
movl %eax, -0x1034(%rbp)
cmpl $0x0, %eax
je 0xebbf
leaq -0x1020(%rbp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0xec10
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xeb66
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xec03
leaq -0x1020(%rbp), %rdi
callq 0x4920
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xeb7f
jmp 0xebe2
movl -0x1034(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1034(%rbp)
movq -0x1028(%rbp), %rax
movslq -0x1034(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x1028(%rbp)
movl -0x1034(%rbp), %ecx
movl -0x1030(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x1030(%rbp)
jmp 0xeb05
jmp 0xebc1
movq -0x10(%rbp), %rdx
movl $0x6, %edi
leaq 0x1003e(%rip), %rsi     # 0x1ec0f
movb $0x0, %al
callq 0xf610
movq $0x0, -0x8(%rbp)
jmp 0xec03
movq 0x17647(%rip), %rcx     # 0x26230
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq %rax, 0x17635(%rip)     # 0x26230
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1040, %rsp           # imm = 0x1040
popq %rbp
retq