// File: /workspace/github_c_makefile_star2_O1/azhai[P]mlite/mlite.c
// Function: load_library
void load_library(char *argv0) {
	char	*path, buf[256], *p;
	char	libdir[240], libfile[256];
	char	*home, *image;
	cell	new;

	image = libname(argv0);
	path = copy_string(string(box_value(S_library_path)));
	home = getenv("HOME");
	if (home == NULL)
		home = ".";
	p = strtok(path, ":");
	while (p != NULL) {
		if (p[0] == '~') {
			if (strlen(p) + strlen(home) >= sizeof(libdir)-1)
				fatal("load_library: path too long");
			sprintf(libdir, "%s%s", home, &p[1]);
		}
		else {
			if (strlen(p) >= sizeof(libdir)-1)
				fatal("load_library: path too long");
			strcpy(libdir, p);
		}
		if (strlen(image) + strlen(libdir) + strlen(".image")
			>= sizeof(libfile)-1
		)
			fatal("load_library: path too long");
		sprintf(libfile, "%s/%s.image", libdir, image);
		if (strcmp(image, "-") && load_image(libfile) == 0) {
			free(path);
			/* *library-path* is overwritten by load_image() */
			set(box_value(S_library_path), get_library_path());
			return;
		}
		if (strlen(image) + strlen(libdir) + strlen(".m")
			>= sizeof(libfile)-1
		)
			fatal("load_library: path too long");
		sprintf(libfile, "%s/%s.m", libdir,
			!strcmp(image, "-")? "mlite": image);
		if (load(libfile) == 0) {
			free(path);
			return;
		}
		p = strtok(NULL, ":");
	}
	sprintf(buf, "found neither \"%s.image\" nor \"%s.m\"", image, image);
	fatal(buf);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
testq %rdi, %rdi
je 0x14a8b
movq %rdi, %r14
cmpb $0x0, (%rdi)
jne 0x14a92
leaq 0x293d(%rip), %r14      # 0x173cf
movq %r14, %rdi
movl $0x2f, %esi
callq 0x30c0
leaq 0x1(%rax), %rbx
testq %rax, %rax
cmoveq %r14, %rbx
movq 0x9b0f(%rip), %rax      # 0x1e5c0
movq 0xa150(%rip), %rcx      # 0x1ec08
movq (%rax,%rcx,8), %rcx
movq (%rax,%rcx,8), %rdi
shlq $0x3, %rdi
addq 0x9b1d(%rip), %rdi      # 0x1e5e8
callq 0x1211d
movq %rax, %r14
leaq 0x28fb(%rip), %rdi      # 0x173d5
callq 0x3030
testq %rax, %rax
leaq 0x16f1(%rip), %rcx      # 0x161da
cmovneq %rax, %rcx
movq %rcx, -0x38(%rbp)
leaq 0x16ce(%rip), %rsi      # 0x161c6
movq %r14, -0x30(%rbp)
movq %r14, %rdi
callq 0x31d0
testq %rax, %rax
je 0x14c63
movq %rax, %r14
leaq -0x230(%rbp), %r13
movb (%r14), %r12b
movq %r14, %rdi
callq 0x30a0
movq %rax, %r15
cmpb $0x7e, %r12b
jne 0x14b62
movq -0x38(%rbp), %r12
movq %r12, %rdi
callq 0x30a0
addq %r15, %rax
cmpq $0xef, %rax
jae 0x14cc6
incq %r14
movq %r13, %rdi
leaq 0x28a3(%rip), %rsi      # 0x173f6
movq %r12, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x31f0
jmp 0x14b7a
cmpq $0xef, %r15
jae 0x14cc6
movq %r13, %rdi
movq %r14, %rsi
callq 0x3060
leaq -0x140(%rbp), %r15
leaq 0x1644(%rip), %r12      # 0x161cc
movq %rbx, %rdi
callq 0x30a0
movq %rax, %r14
movq %r13, %rdi
callq 0x30a0
addq %r14, %rax
addq $-0xf9, %rax
cmpq $-0x100, %rax
jbe 0x14cc6
movq %r15, %rdi
leaq 0x2841(%rip), %rsi      # 0x173fb
movq %r13, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x31f0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3110
testl %eax, %eax
je 0x14be6
movq %r15, %rdi
callq 0x1464a
testl %eax, %eax
je 0x14c94
movq %rbx, %rdi
callq 0x30a0
movq %rax, %r14
movq %r13, %rdi
callq 0x30a0
addq %r14, %rax
addq $-0xfd, %rax
cmpq $-0x100, %rax
jbe 0x14cc6
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3110
testl %eax, %eax
movq %rbx, %rcx
leaq 0x27aa(%rip), %rax      # 0x173cf
cmoveq %rax, %rcx
movq %r15, %rdi
leaq 0x27d4(%rip), %rsi      # 0x17407
movq %r13, %rdx
xorl %eax, %eax
callq 0x31f0
movq %r15, %rdi
callq 0x11b3b
testl %eax, %eax
je 0x14c89
xorl %edi, %edi
leaq 0x1574(%rip), %rsi      # 0x161c6
callq 0x31d0
movq %rax, %r14
testq %rax, %rax
jne 0x14b17
leaq 0x27a5(%rip), %rsi      # 0x1740f
leaq -0x330(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x31f0
movq %r14, %rdi
callq 0x3ab5
movq -0x30(%rbp), %rdi
callq 0x3040
jmp 0x14cb4
movq -0x30(%rbp), %rdi
callq 0x3040
callq 0x149bb
movq 0x9917(%rip), %rcx      # 0x1e5c0
movq 0x9f58(%rip), %rdx      # 0x1ec08
movq %rax, (%rcx,%rdx,8)
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x270d(%rip), %rdi      # 0x173da
callq 0x3ab5