// File: /workspace/github_c_makefile_star2_O3/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 0x147dc
movq %rdi, %r14
cmpb $0x0, (%rdi)
jne 0x147e3
leaq 0x2bd1(%rip), %r14      # 0x173b4
movq %r14, %rdi
movl $0x2f, %esi
callq 0x30c0
leaq 0x1(%rax), %rbx
testq %rax, %rax
cmoveq %r14, %rbx
movq 0x9dbe(%rip), %rax      # 0x1e5c0
movq 0xa3ff(%rip), %rcx      # 0x1ec08
movq (%rax,%rcx,8), %rcx
movq (%rax,%rcx,8), %rdi
shlq $0x3, %rdi
addq 0x9dcc(%rip), %rdi      # 0x1e5e8
callq 0x11e48
movq %rax, %r14
leaq 0x2b8f(%rip), %rdi      # 0x173ba
callq 0x3030
testq %rax, %rax
leaq 0x1988(%rip), %rcx      # 0x161c2
cmovneq %rax, %rcx
movq %rcx, -0x38(%rbp)
leaq 0x1965(%rip), %rsi      # 0x161ae
movq %r14, -0x30(%rbp)
movq %r14, %rdi
callq 0x31d0
testq %rax, %rax
je 0x149a8
movq %rax, %r14
leaq -0x230(%rbp), %r13
movb (%r14), %r12b
movq %r14, %rdi
callq 0x30a0
movq %rax, %r15
cmpb $0x7e, %r12b
jne 0x148b3
movq -0x38(%rbp), %r12
movq %r12, %rdi
callq 0x30a0
addq %r15, %rax
cmpq $0xef, %rax
jae 0x14a0b
incq %r14
movq %r13, %rdi
leaq 0x2b37(%rip), %rsi      # 0x173db
movq %r12, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x31f0
jmp 0x148cb
cmpq $0xef, %r15
jae 0x14a0b
movq %r13, %rdi
movq %r14, %rsi
callq 0x3060
leaq -0x140(%rbp), %r15
movq %rbx, %rdi
callq 0x30a0
movq %rax, %r14
movq %r13, %rdi
callq 0x30a0
addq %r14, %rax
addq $-0xf9, %rax
cmpq $-0x100, %rax
jbe 0x14a0b
movq %r15, %rdi
leaq 0x2adc(%rip), %rsi      # 0x173e0
movq %r13, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x31f0
cmpb $0x2d, (%rbx)
jne 0x1491c
cmpb $0x0, 0x1(%rbx)
je 0x1492c
movq %r15, %rdi
callq 0x1439b
testl %eax, %eax
je 0x149d9
movq %rbx, %rdi
callq 0x30a0
movq %rax, %r14
movq %r13, %rdi
callq 0x30a0
addq %r14, %rax
addq $-0xfd, %rax
cmpq $-0x100, %rax
jbe 0x14a0b
cmpb $0x2d, (%rbx)
movq %rbx, %rcx
jne 0x1496e
cmpb $0x0, 0x1(%rbx)
movq %rbx, %rcx
leaq 0x2a4a(%rip), %rax      # 0x173b4
cmoveq %rax, %rcx
movq %r15, %rdi
leaq 0x2a74(%rip), %rsi      # 0x173ec
movq %r13, %rdx
xorl %eax, %eax
callq 0x31f0
movq %r15, %rdi
callq 0x11853
testl %eax, %eax
je 0x149ce
xorl %edi, %edi
leaq 0x1817(%rip), %rsi      # 0x161ae
callq 0x31d0
movq %rax, %r14
testq %rax, %rax
jne 0x14868
leaq 0x2a45(%rip), %rsi      # 0x173f4
leaq -0x330(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x31f0
movq %r14, %rdi
callq 0x3ab4
movq -0x30(%rbp), %rdi
callq 0x3040
jmp 0x149f9
movq -0x30(%rbp), %rdi
callq 0x3040
callq 0x1470c
movq 0x9bd2(%rip), %rcx      # 0x1e5c0
movq 0xa213(%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 0x29ad(%rip), %rdi      # 0x173bf
callq 0x3ab4