// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1040, %rsp           # imm = 0x1040
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xf06b
callq 0x1050
movq -0x10(%rbp), %rdi
callq 0x10a0
movl %eax, -0x102c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x102c(%rbp), %esi
addl $0x1, %esi
callq 0xf270
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xf0a4
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xf263
cmpq $0x0, 0x171a4(%rip)     # 0x26250
je 0xf11f
movq 0x1719b(%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 0xf11d
movb $0x0, -0x21(%rbp)
leaq -0x1020(%rbp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0xf270
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xf0ff
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xf263
leaq -0x1020(%rbp), %rdi
callq 0x53a0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xf11b
jmp 0xf242
jmp 0xf11d
jmp 0xf11f
movq -0x10(%rbp), %rdi
callq 0x53a0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xf138
jmp 0xf242
callq 0xe720
cmpq $0x0, 0x170fb(%rip)     # 0x26240
je 0xf221
movq 0x170ee(%rip), %rax     # 0x26240
movq %rax, -0x1028(%rbp)
movl 0x170e9(%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 $0xfff, %esi            # imm = 0xFFF
callq 0xec80
movl %eax, -0x1034(%rbp)
cmpl $0x0, %eax
je 0xf21f
leaq -0x1020(%rbp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0xf270
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xf1c6
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xf263
leaq -0x1020(%rbp), %rdi
callq 0x53a0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xf1df
jmp 0xf242
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 0xf165
jmp 0xf221
movq -0x10(%rbp), %rdx
movl $0x6, %edi
leaq 0xfa0d(%rip), %rsi      # 0x1ec3e
movb $0x0, %al
callq 0xf610
movq $0x0, -0x8(%rbp)
jmp 0xf263
movq 0x16fef(%rip), %rcx     # 0x26238
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq %rax, 0x16fdd(%rip)     # 0x26238
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1040, %rsp           # imm = 0x1040
popq %rbp
retq