// File: /workspace/github_c_makefile_star2_O0/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
subq $0x360, %rsp            # imm = 0x360
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1e7b0
movq %rax, -0x320(%rbp)
movq 0x9db2(%rip), %rdi      # 0x285f8
movq 0x9d83(%rip), %rax      # 0x285d0
movq 0x9d7c(%rip), %rcx      # 0x285d0
movq 0xa3bd(%rip), %rdx      # 0x28c18
movq (%rcx,%rdx,8), %rcx
movq (%rax,%rcx,8), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0x1a350
movq %rax, -0x10(%rbp)
leaq 0x2c39(%rip), %rdi      # 0x214b3
callq 0x3030
movq %rax, -0x318(%rbp)
cmpq $0x0, -0x318(%rbp)
jne 0x1e89e
leaq 0x19f3(%rip), %rax      # 0x2028a
movq %rax, -0x318(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x19cd(%rip), %rsi      # 0x20276
callq 0x31d0
movq %rax, -0x118(%rbp)
cmpq $0x0, -0x118(%rbp)
je 0x1eb22
movq -0x118(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7e, %eax
jne 0x1e93b
movq -0x118(%rbp), %rdi
callq 0x30a0
movq %rax, -0x330(%rbp)
movq -0x318(%rbp), %rdi
callq 0x30a0
movq %rax, %rcx
movq -0x330(%rbp), %rax
addq %rcx, %rax
cmpq $0xef, %rax
jb 0x1e912
leaq 0x2bab(%rip), %rdi      # 0x214b8
callq 0x3c70
leaq -0x210(%rbp), %rdi
movq -0x318(%rbp), %rdx
movq -0x118(%rbp), %rcx
addq $0x1, %rcx
leaq 0x2ba2(%rip), %rsi      # 0x214d4
movb $0x0, %al
callq 0x3200
jmp 0x1e96e
movq -0x118(%rbp), %rdi
callq 0x30a0
cmpq $0xef, %rax
jb 0x1e95b
leaq 0x2b62(%rip), %rdi      # 0x214b8
callq 0x3c70
leaq -0x210(%rbp), %rdi
movq -0x118(%rbp), %rsi
callq 0x3060
movq -0x320(%rbp), %rdi
callq 0x30a0
movq %rax, -0x338(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x30a0
movq %rax, %rcx
movq -0x338(%rbp), %rax
addq %rcx, %rax
addq $0x6, %rax
cmpq $0xff, %rax
jb 0x1e9b2
leaq 0x2b0b(%rip), %rdi      # 0x214b8
callq 0x3c70
leaq -0x310(%rbp), %rdi
leaq -0x210(%rbp), %rdx
movq -0x320(%rbp), %rcx
leaq 0x2b0b(%rip), %rsi      # 0x214d9
movb $0x0, %al
callq 0x3200
movq -0x320(%rbp), %rdi
leaq 0x1899(%rip), %rsi      # 0x2027c
callq 0x3120
cmpl $0x0, %eax
je 0x1ea31
leaq -0x310(%rbp), %rdi
callq 0x1e360
cmpl $0x0, %eax
jne 0x1ea31
movq -0x10(%rbp), %rdi
callq 0x3040
callq 0x1e760
movq %rax, -0x328(%rbp)
movq -0x328(%rbp), %rdx
movq 0x9baf(%rip), %rax      # 0x285d0
movq 0xa1f0(%rip), %rcx      # 0x28c18
movq %rdx, (%rax,%rcx,8)
jmp 0x1eb51
movq -0x320(%rbp), %rdi
callq 0x30a0
movq %rax, -0x340(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x30a0
movq %rax, %rcx
movq -0x340(%rbp), %rax
addq %rcx, %rax
addq $0x2, %rax
cmpq $0xff, %rax
jb 0x1ea75
leaq 0x2a48(%rip), %rdi      # 0x214b8
callq 0x3c70
leaq -0x310(%rbp), %rax
movq %rax, -0x350(%rbp)
leaq -0x210(%rbp), %rax
movq %rax, -0x348(%rbp)
movq -0x320(%rbp), %rdi
leaq 0x17dd(%rip), %rsi      # 0x2027c
callq 0x3120
cmpl $0x0, %eax
jne 0x1eab9
leaq 0x29fd(%rip), %rax      # 0x214ad
movq %rax, -0x358(%rbp)
jmp 0x1eac7
movq -0x320(%rbp), %rax
movq %rax, -0x358(%rbp)
movq -0x348(%rbp), %rdx
movq -0x350(%rbp), %rdi
movq -0x358(%rbp), %rcx
leaq 0x2a02(%rip), %rsi      # 0x214e5
movb $0x0, %al
callq 0x3200
leaq -0x310(%rbp), %rdi
callq 0x19bd0
cmpl $0x0, %eax
jne 0x1eb06
movq -0x10(%rbp), %rdi
callq 0x3040
jmp 0x1eb51
xorl %eax, %eax
movl %eax, %edi
leaq 0x1765(%rip), %rsi      # 0x20276
callq 0x31d0
movq %rax, -0x118(%rbp)
jmp 0x1e8b5
leaq -0x110(%rbp), %rdi
movq -0x320(%rbp), %rdx
movq -0x320(%rbp), %rcx
leaq 0x29af(%rip), %rsi      # 0x214ed
movb $0x0, %al
callq 0x3200
leaq -0x110(%rbp), %rdi
callq 0x3c70
addq $0x360, %rsp            # imm = 0x360
popq %rbp
retq
nopw (%rax,%rax)