// File: /workspace/github_c_makefile_star2_O2/azhai[P]mlite/mlite.c
// Function: load_image
int load_image(char *p) {
	FILE		*f;
	cell		n, **v;
	int		i;
	struct magic	m;
	int		ok = 1;
	int		image_nodes, image_vcells;
	cell		name;

	name = make_string(p, (int) strlen(p));
	f = fopen(p, "rb");
	if (f == NULL)
		return -1;
	if (xfread(name, &m, sizeof(m), 1, f)) return -1;
	if (memcmp(m.id, "mL", 2)) {
		error("error in image file (magic match failed)", name);
		ok = 0;
	}
	if (memcmp(m.version, VERSION, 10)) {
		error("error in image file (wrong version)", name);
		ok = 0;
	}
	if (m.cell_size[0]-'0' != sizeof(cell)) {
		error("error in image file (wrong cell size)", name);
		ok = 0;
	}
	if (m.mantissa_size[0]-'0' != MANTISSA_SEGMENTS) {
		error("error in image file (wrong mantissa size)", name);
		ok = 0;
	}
	memcpy(&n, m.byte_order, sizeof(cell));
	if (n != ENDIANNESS) {
		error("error in image file (wrong architecture)", name);
		ok = 0;
	}
	memcpy(&n, m.prim_slots, sizeof(cell));
	if (n != Last_prim) {
		error("error in image file (wrong number of primitives)",
			name);
		ok = 0;
	}
	memset(Tag, 0, Cons_pool_size);
	if (xfread(name, &image_nodes, sizeof(int), 1, f)) return -1;
	if (xfread(name, &image_vcells, sizeof(int), 1, f)) return -1;
	while (image_nodes > Cons_pool_size) {
		if (	Memory_limit_kn &&
			Cons_pool_size + Cons_segment_size > Memory_limit_kn
		) {
			error("image too big (too many conses)", NOEXPR);
			ok = 0;
			break;
		}
		new_cons_segment();
	}
	while (image_vcells > Vec_pool_size) {
		if (	Memory_limit_kn &&
			Vec_pool_size + Vec_segment_size > Memory_limit_kn
		) {
			error("image too big (too many vcells)", NOEXPR);
			ok = 0;
			break;
		}
		new_vec_segment();
	}
	v = Image_vars;
	i = 0;
	while (v[i]) {
		if (xfread(name, v[i], sizeof(cell), 1, f)) return -1;
		i++;
	}
	if (	ok &&
		(fread(Car, 1, image_nodes*sizeof(cell), f)
		  != image_nodes*sizeof(cell) ||
		 fread(Cdr, 1, image_nodes*sizeof(cell), f)
		  != image_nodes*sizeof(cell) ||
		 fread(Tag, 1, image_nodes, f) != image_nodes ||
		 fread(Vectors, 1, image_vcells*sizeof(cell), f)
		  != image_vcells*sizeof(cell) ||
		 fgetc(f) != EOF)
	) {
		error("error in image file (wrong size)", NOEXPR);
		ok = 1;
	}
	fclose(f);
	if (Error_flag)
		fatal("unusable image");
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
callq 0x30a0
movq %rbx, %rdi
movl %eax, %esi
callq 0x729e
movq %rax, %r15
leaq 0x2a59(%rip), %rsi      # 0x1520c
movq %rbx, %rdi
callq 0x31c0
pushq $-0x1
popq %r14
testq %rax, %rax
je 0x12a6c
movq %rax, %rbx
leaq -0x66(%rbp), %rsi
pushq $0x1e
popq %rdx
pushq $0x1
popq %r13
movq %r15, %rdi
movl %r13d, %ecx
movq %rax, %r8
callq 0x12744
testl %eax, %eax
jne 0x12a6c
cmpw $0x4c6d, -0x66(%rbp)    # imm = 0x4C6D
je 0x12806
leaq 0x2a14(%rip), %rdi      # 0x1520f
movq %r15, %rsi
callq 0x33e4
xorl %r13d, %r13d
leaq -0x64(%rbp), %rdi
leaq 0x29a3(%rip), %rsi      # 0x151b4
pushq $0xa
popq %rdx
callq 0x3180
testl %eax, %eax
je 0x1282f
leaq 0x2a14(%rip), %rdi      # 0x15238
movq %r15, %rsi
callq 0x33e4
xorl %r13d, %r13d
cmpb $0x38, -0x5a(%rbp)
je 0x12847
leaq 0x2a20(%rip), %rdi      # 0x1525c
movq %r15, %rsi
callq 0x33e4
xorl %r13d, %r13d
cmpb $0x34, -0x59(%rbp)
je 0x1285f
leaq 0x2a2e(%rip), %rdi      # 0x15282
movq %r15, %rsi
callq 0x33e4
xorl %r13d, %r13d
cmpq $0x31323334, -0x58(%rbp) # imm = 0x31323334
je 0x1287b
leaq 0x2a3c(%rip), %rdi      # 0x152ac
movq %r15, %rsi
callq 0x33e4
xorl %r13d, %r13d
movslq 0xa38e(%rip), %rax      # 0x1cc10
cmpq %rax, -0x50(%rbp)
je 0x1289a
leaq 0x2a46(%rip), %rdi      # 0x152d5
movq %r15, %rsi
callq 0x33e4
xorl %r13d, %r13d
movq 0x9d3f(%rip), %rdi      # 0x1c5e0
movslq 0x9d2c(%rip), %rdx      # 0x1c5d4
xorl %esi, %esi
callq 0x30d0
leaq -0x34(%rbp), %rsi
pushq $0x4
popq %rdx
pushq $0x1
popq %rcx
movq %r15, %rdi
movq %rbx, %r8
callq 0x12744
testl %eax, %eax
jne 0x12a6c
leaq -0x30(%rbp), %rsi
pushq $0x4
popq %rdx
pushq $0x1
popq %rcx
movq %r15, %rdi
movq %rbx, %r8
callq 0x12744
testl %eax, %eax
jne 0x12a6c
movslq -0x34(%rbp), %r12
movslq 0x9ce0(%rip), %rax      # 0x1c5d4
cmpl %eax, %r12d
jle 0x1291b
movq 0x9d70(%rip), %rcx      # 0x1c670
testq %rcx, %rcx
je 0x12914
movslq 0x9ccc(%rip), %rdx      # 0x1c5d8
addq %rax, %rdx
cmpq %rdx, %rcx
jl 0x12924
callq 0x3a00
jmp 0x128ed
testl %r13d, %r13d
sete -0x29(%rbp)
jmp 0x12937
leaq 0x29db(%rip), %rdi      # 0x15306
pushq $-0x8
popq %rsi
callq 0x33e4
movb $0x1, -0x29(%rbp)
movslq -0x30(%rbp), %r13
movq %r12, -0x48(%rbp)
movq %r13, -0x40(%rbp)
movslq 0x9ca6(%rip), %rax      # 0x1c5f0
cmpl %eax, %r13d
jle 0x12984
movq 0x9d1a(%rip), %rcx      # 0x1c670
testq %rcx, %rcx
je 0x1296a
movslq 0x9c92(%rip), %rdx      # 0x1c5f4
addq %rax, %rdx
cmpq %rdx, %rcx
jl 0x12971
callq 0x3b21
jmp 0x12943
leaq 0x29ae(%rip), %rdi      # 0x15326
pushq $-0x8
popq %rsi
callq 0x33e4
movb $0x1, -0x29(%rbp)
leaq 0x9605(%rip), %r12      # 0x1bf90
pushq $0x1
popq %r13
movq (%r12), %rsi
testq %rsi, %rsi
je 0x129b6
movq %r15, %rdi
pushq $0x8
popq %rdx
movl %r13d, %ecx
movq %rbx, %r8
callq 0x12744
addq $0x8, %r12
testl %eax, %eax
je 0x1298f
jmp 0x12a6c
cmpb $0x0, -0x29(%rbp)
movq -0x48(%rbp), %r15
jne 0x12a58
movq 0x97a5(%rip), %rdi      # 0x1c170
leaq (,%r15,8), %r14
pushq $0x1
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x3080
cmpq %r14, %rax
jne 0x12a49
movq 0x9bd3(%rip), %rdi      # 0x1c5c0
pushq $0x1
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x3080
cmpq %r14, %rax
jne 0x12a49
movq 0x9bd9(%rip), %rdi      # 0x1c5e0
pushq $0x1
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x3080
cmpq %r15, %rax
jne 0x12a49
movq 0x9bc7(%rip), %rdi      # 0x1c5e8
movq -0x40(%rbp), %r14
shlq $0x3, %r14
pushq $0x1
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x3080
cmpq %r14, %rax
jne 0x12a49
movq %rbx, %rdi
callq 0x30e0
cmpl $-0x1, %eax
je 0x12a58
leaq 0x28f6(%rip), %rdi      # 0x15346
pushq $-0x8
popq %rsi
callq 0x33e4
movq %rbx, %rdi
callq 0x3090
xorl %r14d, %r14d
cmpl $0x0, 0x9b4a(%rip)      # 0x1c5b4
jne 0x12a7e
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28e2(%rip), %rdi      # 0x15367
callq 0x39b6