// File: /workspace/github_c_makefile_star2_O3/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 0x9fff
movq %rdi, %rbx
movabsq $0x100000000, %r15      # imm = 0x100000000
callq 0x10b0
movq %rax, %r14
incl %eax
movslq %eax, %r12
leaq 0x104a1(%rip), %r13     # 0x1a258
movq (%r13), %r13
testq %r13, %r13
je 0x9dd8
movq 0x8(%r13), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x1070
testl %eax, %eax
jne 0x9db7
jmp 0x9f7f
movq 0x10491(%rip), %rax     # 0x1a270
testq %rax, %rax
je 0x9e41
leaq 0x10(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdx
movl %r14d, %ecx
callq *%rax
testl %eax, %eax
je 0x9e41
leaq 0x10(%rsp), %r12
movb $0x0, 0xfff(%r12)
leaq 0x10449(%rip), %r13     # 0x1a258
movq (%r13), %r13
testq %r13, %r13
je 0x9e32
movq 0x8(%r13), %rsi
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
callq 0x1070
testl %eax, %eax
jne 0x9e0f
jmp 0x9f7f
leaq 0x10(%rsp), %rdi
callq 0x3505
testq %rax, %rax
jne 0x9e4e
movq %rbx, %rdi
callq 0x3505
testq %rax, %rax
je 0x9e68
movq %rax, %r13
movq 0x10400(%rip), %rax     # 0x1a258
movq %rax, (%r13)
movq %r13, 0x103f5(%rip)     # 0x1a258
jmp 0x9f7f
cmpb $0x0, 0x103fd(%rip)     # 0x1a26c
jne 0x9eaa
movb $0x1, 0x103f4(%rip)     # 0x1a26c
leaq 0x9d41(%rip), %rdi      # 0x13bc0
callq 0x1030
testq %rax, %rax
je 0x9eaa
cmpq $0x0, 0x103cf(%rip)     # 0x1a260
je 0x9f94
leaq 0x9cfb(%rip), %rsi      # 0x13b99
movl $0x7, %edi
xorl %eax, %eax
callq 0xa278
movq 0x103af(%rip), %r15     # 0x1a260
testq %r15, %r15
je 0x9f66
movl 0x103a7(%rip), %r13d    # 0x1a268
leaq 0x10(%rsp), %rdi
movl $0xfff, %esi            # imm = 0xFFF
movq %r15, %rdx
movl %r13d, %ecx
movq %rbx, %r8
movl %r14d, %r9d
callq 0x9b34
testl %eax, %eax
je 0x9f66
movl %eax, %r12d
leaq 0x1036a(%rip), %rax     # 0x1a258
leaq 0x10(%rsp), %rbp
movq %r13, 0x8(%rsp)
movq %rax, %r13
movq (%r13), %r13
testq %r13, %r13
je 0x9f1b
movq 0x8(%r13), %rsi
movl $0x1000, %edx           # imm = 0x1000
movq %rbp, %rdi
callq 0x1070
testl %eax, %eax
jne 0x9efb
jmp 0x9f7f
movq %rbp, %rdi
callq 0x3505
testq %rax, %rax
jne 0x9e4e
movslq %r12d, %rax
addq %rax, %r15
incq %r15
notl %eax
movq 0x8(%rsp), %r13
addl %eax, %r13d
movq %rbp, %rdi
movl $0xfff, %esi            # imm = 0xFFF
movq %r15, %rdx
movl %r13d, %ecx
movq %rbx, %r8
movl %r14d, %r9d
callq 0x9b34
movl %eax, %r12d
testl %eax, %eax
leaq 0x102f4(%rip), %rax     # 0x1a258
jne 0x9ef3
leaq 0x9c0f(%rip), %rsi      # 0x13b7c
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, 0x102bf(%rip)    # 0x1a268
shlq $0x20, %rax
addq %rax, %r15
sarq $0x20, %r15
movq %r15, %rdi
callq 0x1190
movq %rax, 0x1029d(%rip)     # 0x1a260
testq %rax, %rax
je 0x9fdb
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
callq 0x1080
jmp 0x9ec1
leaq 0x925a(%rip), %rsi      # 0x1323c
leaq 0x9b54(%rip), %rdx      # 0x13b3d
movl $0x7, %edi
movl $0x4a, %ecx
xorl %eax, %eax
callq 0xa278
jmp 0x9eaa
callq 0x1060