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

	ASSERT(file_name)

	file_name_len = strlen(file_name);

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

	/*   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;

		conversion = find_conversion(path, PATH_NAME_MAX);
		if(conversion)
			return conversion;
		conversion = conversion_compile_from_file(path);
		if(conversion)
			goto return_conversion;
	}

	/*   try file_name directly   */
	conversion = conversion_compile_from_file(file_name);
	if(conversion)
		goto return_conversion;

	/*   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 - 1, paths, paths_len, file_name, file_name_len))
		{
			conversion = find_conversion(path, PATH_NAME_MAX);
			if(conversion)
				return conversion;
			conversion = conversion_compile_from_file(path);
			if(conversion)
				goto return_conversion;

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

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

	return_conversion:
	conversion->nxt = conversion_list;
	conversion_list = conversion;
	return conversion;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
testq %rdi, %rdi
je 0x8f91
movq %rdi, %r12
callq 0x10b0
movq %rax, %r14
leal 0x1(%rax), %esi
movq %r12, %rdi
callq 0x8f96
testq %rax, %rax
je 0x8e6a
movq %rax, %r15
jmp 0x8f7c
movq 0x1040f(%rip), %rax     # 0x19280
testq %rax, %rax
je 0x8eb6
leaq 0x10(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r12, %rdx
movl %r14d, %ecx
callq *%rax
testl %eax, %eax
je 0x8eb6
leaq 0x10(%rsp), %rdi
movb $0x0, 0xfff(%rdi)
movl $0x1000, %esi           # imm = 0x1000
callq 0x8f96
testq %rax, %rax
jne 0x8e62
leaq 0x10(%rsp), %rdi
callq 0x32ec
testq %rax, %rax
jne 0x8ec3
movq %r12, %rdi
callq 0x32ec
testq %rax, %rax
je 0x8edc
movq %rax, %r15
movq 0x1039b(%rip), %rax     # 0x19268
movq %rax, (%r15)
movq %r15, 0x10391(%rip)     # 0x19268
jmp 0x8f7c
callq 0x8808
movq 0x10388(%rip), %rax     # 0x19270
testq %rax, %rax
je 0x8f65
movq %rax, %rdx
movl 0x10382(%rip), %ecx     # 0x19278
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movl $0xfff, %esi            # imm = 0xFFF
movq %rdx, %rbx
movl %ecx, 0xc(%rsp)
movq %r12, %r8
movl %r14d, %r9d
callq 0x8c0c
testl %eax, %eax
je 0x8f65
movl %eax, %r13d
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x8f96
testq %rax, %rax
jne 0x8e62
movq %r15, %rdi
movq %r14, %rbp
movq %r15, %r14
callq 0x32ec
testq %rax, %rax
jne 0x8ec3
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 0x8efb
leaq 0x8b80(%rip), %rsi      # 0x11aec
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