// File: /workspace/github_c_makefile_star2_O1/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 0xa0fe
movq %rdi, %rbx
movabsq $0x100000000, %r15      # imm = 0x100000000
callq 0x10b0
movq %rax, 0x8(%rsp)
incl %eax
movslq %eax, %r14
leaq 0x1039b(%rip), %r12     # 0x1a258
movq (%r12), %r12
testq %r12, %r12
je 0x9edc
movq 0x8(%r12), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1070
testl %eax, %eax
jne 0x9ebd
jmp 0x9edf
xorl %r12d, %r12d
testq %r12, %r12
jne 0xa0e9
movq 0x10381(%rip), %rax     # 0x1a270
testq %rax, %rax
je 0x9f5c
leaq 0x10(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdx
movq 0x8(%rsp), %rcx
callq *%rax
testl %eax, %eax
je 0x9f5c
leaq 0x10(%rsp), %r14
movb $0x0, 0xfff(%r14)
leaq 0x10338(%rip), %r12     # 0x1a258
movq (%r12), %r12
testq %r12, %r12
je 0x9f41
movq 0x8(%r12), %rsi
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
callq 0x1070
testl %eax, %eax
jne 0x9f20
jmp 0x9f44
xorl %r12d, %r12d
testq %r12, %r12
jne 0xa0e9
leaq 0x10(%rsp), %rdi
callq 0x3572
testq %rax, %rax
jne 0x9f69
movq %rbx, %rdi
callq 0x3572
testq %rax, %rax
je 0x9f83
movq %rax, %r12
movq 0x102e5(%rip), %rax     # 0x1a258
movq %rax, (%r12)
movq %r12, 0x102da(%rip)     # 0x1a258
jmp 0xa0e9
cmpb $0x0, 0x102e2(%rip)     # 0x1a26c
jne 0xa023
movb $0x1, 0x102d5(%rip)     # 0x1a26c
leaq 0x9b52(%rip), %rdi      # 0x13af0
callq 0x1030
testq %rax, %rax
je 0xa023
cmpq $0x0, 0x102b0(%rip)     # 0x1a260
je 0x9fc7
leaq 0x9b10(%rip), %rsi      # 0x13ac9
movl $0x7, %edi
xorl %eax, %eax
callq 0xa36c
jmp 0xa023
movq %rax, %r14
movq %rax, %rdi
callq 0x10b0
movl %eax, 0x10290(%rip)     # 0x1a268
shlq $0x20, %rax
addq %rax, %r15
sarq $0x20, %r15
movq %r15, %rdi
callq 0x1180
movq %rax, 0x1026e(%rip)     # 0x1a260
testq %rax, %rax
je 0xa004
movq %rax, %rdi
movq %r14, %rsi
callq 0x1080
jmp 0xa023
leaq 0x91e9(%rip), %rsi      # 0x131f4
leaq 0x9a5b(%rip), %rdx      # 0x13a6d
movl $0x7, %edi
movl $0x4a, %ecx
xorl %eax, %eax
callq 0xa36c
movq 0x10236(%rip), %r15     # 0x1a260
testq %r15, %r15
je 0xa0d0
movl 0x1022f(%rip), %ebp     # 0x1a268
leaq 0x10(%rsp), %rdi
movl $0xfff, %esi            # imm = 0xFFF
movq %r15, %rdx
movl %ebp, %ecx
movq %rbx, %r8
movq 0x8(%rsp), %r9
callq 0x9c32
testl %eax, %eax
je 0xa0d0
movl %eax, %r14d
leaq 0x10(%rsp), %r13
leaq 0x101f0(%rip), %r12     # 0x1a258
movq (%r12), %r12
testq %r12, %r12
je 0xa089
movq 0x8(%r12), %rsi
movl $0x1000, %edx           # imm = 0x1000
movq %r13, %rdi
callq 0x1070
testl %eax, %eax
jne 0xa068
jmp 0xa08c
xorl %r12d, %r12d
testq %r12, %r12
jne 0xa0e9
movq %r13, %rdi
callq 0x3572
testq %rax, %rax
jne 0x9f69
movslq %r14d, %rax
addq %rax, %r15
incq %r15
notl %eax
addl %eax, %ebp
movq %r13, %rdi
movl $0xfff, %esi            # imm = 0xFFF
movq %r15, %rdx
movl %ebp, %ecx
movq %rbx, %r8
movq 0x8(%rsp), %r9
callq 0x9c32
movl %eax, %r14d
testl %eax, %eax
jne 0xa061
leaq 0x99d5(%rip), %rsi      # 0x13aac
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