// File: /workspace/github_c_makefile_star2_O2/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
callq 0x12ac2
movq %rax, -0x38(%rbp)
movq 0x9aa0(%rip), %rax      # 0x1c5c0
movq 0xa0e1(%rip), %rcx      # 0x1cc08
movq (%rax,%rcx,8), %rcx
movq (%rax,%rcx,8), %rdi
shlq $0x3, %rdi
addq 0x9aae(%rip), %rdi      # 0x1c5e8
callq 0x105ab
movq %rax, %r14
leaq 0x2871(%rip), %rdi      # 0x153ba
callq 0x3030
testq %rax, %rax
leaq 0x166a(%rip), %r12      # 0x141c2
cmovneq %rax, %r12
leaq 0x164b(%rip), %rsi      # 0x141ae
movq %r14, -0x30(%rbp)
movq %r14, %rdi
callq 0x31d0
movq %rax, %r13
leaq -0x130(%rbp), %r14
testq %r13, %r13
je 0x12d07
movb (%r13), %bl
movq %r13, %rdi
callq 0x30a0
movq %rax, %r15
cmpb $0x7e, %bl
jne 0x12bc9
movq %r12, %rdi
callq 0x30a0
addq %r15, %rax
cmpq $0xef, %rax
jae 0x12cfb
incq %r13
movq %r14, %rdi
leaq 0x2821(%rip), %rsi      # 0x153db
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x31f0
jmp 0x12be1
cmpq $0xef, %r15
jae 0x12cfb
movq %r14, %rdi
movq %r13, %rsi
callq 0x3060
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x30a0
movq %rax, %r15
movq %r14, %rdi
callq 0x30a0
addq %r15, %rax
addq $-0xf9, %rax
cmpq $-0x100, %rax
leaq -0x230(%rbp), %r13
jbe 0x12cfb
movq %r13, %rdi
leaq 0x27c2(%rip), %rsi      # 0x153e0
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x31f0
cmpb $0x2d, (%rbx)
jne 0x12c36
cmpb $0x0, 0x1(%rbx)
je 0x12c46
movq %r13, %rdi
callq 0x12786
testl %eax, %eax
je 0x12cc9
movq %rbx, %rdi
callq 0x30a0
movq %rax, %r15
movq %r14, %rdi
callq 0x30a0
addq %r15, %rax
addq $-0xfd, %rax
cmpq $-0x100, %rax
jbe 0x12cfb
cmpb $0x2d, (%rbx)
movq %rbx, %rcx
jne 0x12c88
cmpb $0x0, 0x1(%rbx)
movq %rbx, %rcx
leaq 0x2730(%rip), %rax      # 0x153b4
cmoveq %rax, %rcx
movq %r13, %rdi
leaq 0x275a(%rip), %rsi      # 0x153ec
movq %r14, %rdx
xorl %eax, %eax
callq 0x31f0
movq %r13, %rdi
callq 0x100cf
testl %eax, %eax
je 0x12cbe
xorl %edi, %edi
leaq 0x14fd(%rip), %rsi      # 0x141ae
callq 0x31d0
movq %rax, %r13
jmp 0x12b79
movq -0x30(%rbp), %rdi
callq 0x3040
jmp 0x12ce9
movq -0x30(%rbp), %rdi
callq 0x3040
callq 0x12a8a
movq 0x98e2(%rip), %rcx      # 0x1c5c0
movq 0x9f23(%rip), %rdx      # 0x1cc08
movq %rax, (%rcx,%rdx,8)
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x26bd(%rip), %rdi      # 0x153bf
callq 0x39b6
leaq 0x26e6(%rip), %rsi      # 0x153f4
leaq -0x330(%rbp), %r14
movq %r14, %rdi
movq -0x38(%rbp), %rcx
movq %rcx, %rdx
xorl %eax, %eax
callq 0x31f0
movq %r14, %rdi
callq 0x39b6