// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rdi, %rbx
callq 0x30a0
movq %rax, %r15
incl %r15d
movq $-0x21, %rdi
movl %r15d, %esi
callq 0x417e
movq %rax, %r14
movq 0x9f3e(%rip), %rax      # 0x1e5c0
movq (%rax,%r14,8), %rdi
shlq $0x3, %rdi
addq 0x9f57(%rip), %rdi      # 0x1e5e8
movslq %r15d, %rdx
movq %rbx, %rsi
callq 0x3050
leaq 0x2b84(%rip), %rsi      # 0x17227
movq %rbx, %rdi
callq 0x31c0
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x149a9
movq %rax, %rbx
leaq -0x52(%rbp), %rdi
movl $0x1e, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x3080
cmpq $0x1, %rax
jne 0x1499a
cmpw $0x4c6d, -0x52(%rbp)    # imm = 0x4C6D
je 0x146f8
leaq 0x2b3e(%rip), %rdi      # 0x1722a
movq %r14, %rsi
callq 0x33eb
xorl %edx, %edx
jmp 0x146fd
movl $0x1, %edx
movabsq $0x2d32312d34313032, %rax # imm = 0x2D32312D34313032
xorq -0x50(%rbp), %rax
movzwl -0x48(%rbp), %ecx
xorq $0x3932, %rcx           # imm = 0x3932
orq %rax, %rcx
je 0x1472c
leaq 0x2b31(%rip), %rdi      # 0x17253
movq %r14, %rsi
callq 0x33eb
xorl %edx, %edx
cmpb $0x38, -0x46(%rbp)
je 0x14743
leaq 0x2b3e(%rip), %rdi      # 0x17277
movq %r14, %rsi
callq 0x33eb
xorl %edx, %edx
cmpb $0x34, -0x45(%rbp)
je 0x1475a
leaq 0x2b4d(%rip), %rdi      # 0x1729d
movq %r14, %rsi
callq 0x33eb
xorl %edx, %edx
cmpq $0x31323334, -0x44(%rbp) # imm = 0x31323334
je 0x14775
leaq 0x2b5c(%rip), %rdi      # 0x172c7
movq %r14, %rsi
callq 0x33eb
xorl %edx, %edx
movslq 0xa494(%rip), %rax      # 0x1ec10
cmpq %rax, -0x3c(%rbp)
je 0x14793
leaq 0x2b67(%rip), %rdi      # 0x172f0
movq %r14, %rsi
callq 0x33eb
xorl %edx, %edx
movl %edx, -0x2c(%rbp)
movq 0x9e43(%rip), %rdi      # 0x1e5e0
movslq 0x9e30(%rip), %rdx      # 0x1e5d4
xorl %esi, %esi
callq 0x30d0
leaq -0x34(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3080
cmpq $0x1, %rax
jne 0x1499a
leaq -0x30(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3080
cmpq $0x1, %rax
jne 0x1499a
movslq -0x34(%rbp), %r12
movl 0x9ddf(%rip), %eax      # 0x1e5d4
cmpl %eax, %r12d
jle 0x14838
movq 0x9e6f(%rip), %rcx      # 0x1e670
testq %rcx, %rcx
je 0x14817
movslq 0x9dcb(%rip), %rdx      # 0x1e5d8
cltq
addq %rdx, %rax
cmpq %rax, %rcx
jl 0x1481e
callq 0x3b02
jmp 0x147ef
leaq 0x2afc(%rip), %rdi      # 0x17321
movq $-0x8, %rsi
callq 0x33eb
movl $0x0, -0x2c(%rbp)
movslq -0x30(%rbp), %r13
movl 0x9dae(%rip), %eax      # 0x1e5f0
cmpl %eax, %r13d
movq %r12, -0x60(%rbp)
jle 0x14894
movq 0x9e1e(%rip), %rcx      # 0x1e670
testq %rcx, %rcx
je 0x14868
movslq 0x9d96(%rip), %rdx      # 0x1e5f4
cltq
addq %rdx, %rax
cmpq %rax, %rcx
jl 0x1487a
callq 0x3c2f
movl 0x9d7d(%rip), %eax      # 0x1e5f0
cmpl %eax, %r13d
jg 0x1484b
jmp 0x14894
leaq 0x2ac0(%rip), %rdi      # 0x17341
movq $-0x8, %rsi
callq 0x33eb
movl $0x0, -0x2c(%rbp)
movq 0x96f5(%rip), %rdi      # 0x1df90
testq %rdi, %rdi
je 0x148d0
leaq 0x96f1(%rip), %r12      # 0x1df98
movl $0x8, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3080
cmpq $0x1, %rax
jne 0x1499a
movq (%r12), %rdi
addq $0x8, %r12
testq %rdi, %rdi
jne 0x148a7
cmpl $0x0, -0x2c(%rbp)
movq -0x60(%rbp), %r15
je 0x1497a
movq 0x988b(%rip), %rdi      # 0x1e170
leaq (,%r15,8), %r14
movl $0x1, %esi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x3080
cmpq %r14, %rax
jne 0x14967
movq 0x9cb7(%rip), %rdi      # 0x1e5c0
movl $0x1, %esi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x3080
cmpq %r14, %rax
jne 0x14967
movq 0x9cbb(%rip), %rdi      # 0x1e5e0
movl $0x1, %esi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x3080
cmpq %r15, %rax
jne 0x14967
movq 0x9ca7(%rip), %rdi      # 0x1e5e8
shlq $0x3, %r13
movl $0x1, %esi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x3080
cmpq %r13, %rax
jne 0x14967
movq %rbx, %rdi
callq 0x30e0
cmpl $-0x1, %eax
je 0x1497a
leaq 0x29f3(%rip), %rdi      # 0x17361
movq $-0x8, %rsi
callq 0x33eb
movq %rbx, %rdi
callq 0x3090
xorl %r15d, %r15d
cmpl $0x0, 0x9c28(%rip)      # 0x1e5b4
je 0x149a9
leaq 0x29ed(%rip), %rdi      # 0x17382
callq 0x3ab5
leaq 0x2870(%rip), %rdi      # 0x17211
movq %r14, %rsi
callq 0x33eb
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq