// File: /workspace/github_c_makefile_star2_O3/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 0x416e
movq %rax, %r14
movq 0xa1ed(%rip), %rax      # 0x1e5c0
movq (%rax,%r14,8), %rdi
shlq $0x3, %rdi
addq 0xa206(%rip), %rdi      # 0x1e5e8
movslq %r15d, %rdx
movq %rbx, %rsi
callq 0x3050
leaq 0x2e18(%rip), %rsi      # 0x1720c
movq %rbx, %rdi
callq 0x31c0
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x146fa
movq %rax, %rbx
leaq -0x52(%rbp), %rdi
movl $0x1e, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x3080
cmpq $0x1, %rax
jne 0x146eb
cmpw $0x4c6d, -0x52(%rbp)    # imm = 0x4C6D
je 0x14449
leaq 0x2dd2(%rip), %rdi      # 0x1720f
movq %r14, %rsi
callq 0x33eb
xorl %edx, %edx
jmp 0x1444e
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 0x1447d
leaq 0x2dc5(%rip), %rdi      # 0x17238
movq %r14, %rsi
callq 0x33eb
xorl %edx, %edx
cmpb $0x38, -0x46(%rbp)
je 0x14494
leaq 0x2dd2(%rip), %rdi      # 0x1725c
movq %r14, %rsi
callq 0x33eb
xorl %edx, %edx
cmpb $0x34, -0x45(%rbp)
je 0x144ab
leaq 0x2de1(%rip), %rdi      # 0x17282
movq %r14, %rsi
callq 0x33eb
xorl %edx, %edx
cmpq $0x31323334, -0x44(%rbp) # imm = 0x31323334
je 0x144c6
leaq 0x2df0(%rip), %rdi      # 0x172ac
movq %r14, %rsi
callq 0x33eb
xorl %edx, %edx
movslq 0xa743(%rip), %rax      # 0x1ec10
cmpq %rax, -0x3c(%rbp)
je 0x144e4
leaq 0x2dfb(%rip), %rdi      # 0x172d5
movq %r14, %rsi
callq 0x33eb
xorl %edx, %edx
movl %edx, -0x2c(%rbp)
movq 0xa0f2(%rip), %rdi      # 0x1e5e0
movslq 0xa0df(%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 0x146eb
leaq -0x30(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3080
cmpq $0x1, %rax
jne 0x146eb
movslq -0x34(%rbp), %r12
movl 0xa08e(%rip), %eax      # 0x1e5d4
cmpl %eax, %r12d
jle 0x14589
movq 0xa11e(%rip), %rcx      # 0x1e670
testq %rcx, %rcx
je 0x14568
movslq 0xa07a(%rip), %rdx      # 0x1e5d8
cltq
addq %rdx, %rax
cmpq %rax, %rcx
jl 0x1456f
callq 0x3b01
jmp 0x14540
leaq 0x2d90(%rip), %rdi      # 0x17306
movq $-0x8, %rsi
callq 0x33eb
movl $0x0, -0x2c(%rbp)
movslq -0x30(%rbp), %r13
movl 0xa05d(%rip), %eax      # 0x1e5f0
cmpl %eax, %r13d
movq %r12, -0x60(%rbp)
jle 0x145e5
movq 0xa0cd(%rip), %rcx      # 0x1e670
testq %rcx, %rcx
je 0x145b9
movslq 0xa045(%rip), %rdx      # 0x1e5f4
cltq
addq %rdx, %rax
cmpq %rax, %rcx
jl 0x145cb
callq 0x3c25
movl 0xa02c(%rip), %eax      # 0x1e5f0
cmpl %eax, %r13d
jg 0x1459c
jmp 0x145e5
leaq 0x2d54(%rip), %rdi      # 0x17326
movq $-0x8, %rsi
callq 0x33eb
movl $0x0, -0x2c(%rbp)
movq 0x99a4(%rip), %rdi      # 0x1df90
testq %rdi, %rdi
je 0x14621
leaq 0x99a0(%rip), %r12      # 0x1df98
movl $0x8, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3080
cmpq $0x1, %rax
jne 0x146eb
movq (%r12), %rdi
addq $0x8, %r12
testq %rdi, %rdi
jne 0x145f8
cmpl $0x0, -0x2c(%rbp)
movq -0x60(%rbp), %r15
je 0x146cb
movq 0x9b3a(%rip), %rdi      # 0x1e170
leaq (,%r15,8), %r14
movl $0x1, %esi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x3080
cmpq %r14, %rax
jne 0x146b8
movq 0x9f66(%rip), %rdi      # 0x1e5c0
movl $0x1, %esi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x3080
cmpq %r14, %rax
jne 0x146b8
movq 0x9f6a(%rip), %rdi      # 0x1e5e0
movl $0x1, %esi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x3080
cmpq %r15, %rax
jne 0x146b8
movq 0x9f56(%rip), %rdi      # 0x1e5e8
shlq $0x3, %r13
movl $0x1, %esi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x3080
cmpq %r13, %rax
jne 0x146b8
movq %rbx, %rdi
callq 0x30e0
cmpl $-0x1, %eax
je 0x146cb
leaq 0x2c87(%rip), %rdi      # 0x17346
movq $-0x8, %rsi
callq 0x33eb
movq %rbx, %rdi
callq 0x3090
xorl %r15d, %r15d
cmpl $0x0, 0x9ed7(%rip)      # 0x1e5b4
je 0x146fa
leaq 0x2c81(%rip), %rdi      # 0x17367
callq 0x3ab4
leaq 0x2b04(%rip), %rdi      # 0x171f6
movq %r14, %rsi
callq 0x33eb
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq