// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl $0x1, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
callq 0x30a0
movq -0x68(%rbp), %rdi
movl %eax, %esi
callq 0xa160
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x2f67(%rip), %rsi      # 0x21305
callq 0x31c0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1e3ba
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1e755
movq -0x60(%rbp), %rdi
movq -0x18(%rbp), %r8
leaq -0x4a(%rbp), %rsi
movl $0x1e, %edx
movl $0x1, %ecx
callq 0x1e2f0
cmpl $0x0, %eax
je 0x1e3e6
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1e755
leaq -0x4a(%rbp), %rax
movw (%rax), %ax
subw $0x4c6d, %ax            # imm = 0x4C6D
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x1e413
movq -0x60(%rbp), %rsi
leaq 0x2f01(%rip), %rdi      # 0x21308
callq 0x34b0
movl $0x0, -0x50(%rbp)
leaq -0x4a(%rbp), %rdi
addq $0x2, %rdi
leaq 0x2e8b(%rip), %rsi      # 0x212ad
movl $0xa, %edx
callq 0x3100
cmpl $0x0, %eax
je 0x1e448
movq -0x60(%rbp), %rsi
leaq 0x2ef5(%rip), %rdi      # 0x21331
callq 0x34b0
movl $0x0, -0x50(%rbp)
movsbl -0x3e(%rbp), %eax
subl $0x30, %eax
cltq
cmpq $0x8, %rax
je 0x1e46e
movq -0x60(%rbp), %rsi
leaq 0x2ef3(%rip), %rdi      # 0x21355
callq 0x34b0
movl $0x0, -0x50(%rbp)
movsbl -0x3d(%rbp), %eax
subl $0x30, %eax
cmpl $0x4, %eax
je 0x1e491
movq -0x60(%rbp), %rsi
leaq 0x2ef6(%rip), %rdi      # 0x2137b
callq 0x34b0
movl $0x0, -0x50(%rbp)
movq -0x3c(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x31323334, -0x20(%rbp) # imm = 0x31323334
je 0x1e4ba
movq -0x60(%rbp), %rsi
leaq 0x2ef7(%rip), %rdi      # 0x213a5
callq 0x34b0
movl $0x0, -0x50(%rbp)
movq -0x34(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movslq 0xa753(%rip), %rcx      # 0x28c20
cmpq %rcx, %rax
je 0x1e4e9
movq -0x60(%rbp), %rsi
leaq 0x2ef1(%rip), %rdi      # 0x213ce
callq 0x34b0
movl $0x0, -0x50(%rbp)
movq 0xa100(%rip), %rdi      # 0x285f0
movslq 0xa0ed(%rip), %rdx      # 0x285e4
xorl %esi, %esi
callq 0x30e0
movq -0x60(%rbp), %rdi
movq -0x18(%rbp), %r8
leaq -0x54(%rbp), %rsi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x1e2f0
cmpl $0x0, %eax
je 0x1e52a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1e755
movq -0x60(%rbp), %rdi
movq -0x18(%rbp), %r8
leaq -0x58(%rbp), %rsi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x1e2f0
cmpl $0x0, %eax
je 0x1e556
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1e755
jmp 0x1e558
movl -0x54(%rbp), %eax
cmpl 0xa083(%rip), %eax      # 0x285e4
jle 0x1e5a7
cmpq $0x0, 0xa115(%rip)      # 0x28680
je 0x1e5a0
movl 0xa071(%rip), %eax      # 0x285e4
addl 0xa06f(%rip), %eax      # 0x285e8
cltq
cmpq 0xa0fe(%rip), %rax      # 0x28680
jle 0x1e5a0
leaq 0x2e74(%rip), %rdi      # 0x213ff
movq $-0x8, %rsi
callq 0x34b0
movl $0x0, -0x50(%rbp)
jmp 0x1e5a7
callq 0x3cd0
jmp 0x1e558
jmp 0x1e5a9
movl -0x58(%rbp), %eax
cmpl 0xa04e(%rip), %eax      # 0x28600
jle 0x1e5f8
cmpq $0x0, 0xa0c4(%rip)      # 0x28680
je 0x1e5f1
movl 0xa03c(%rip), %eax      # 0x28600
addl 0xa03a(%rip), %eax      # 0x28604
cltq
cmpq 0xa0ad(%rip), %rax      # 0x28680
jle 0x1e5f1
leaq 0x2e43(%rip), %rdi      # 0x2141f
movq $-0x8, %rsi
callq 0x34b0
movl $0x0, -0x50(%rbp)
jmp 0x1e5f8
callq 0x3e10
jmp 0x1e5a9
leaq 0x99a1(%rip), %rax      # 0x27fa0
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x1e658
movq -0x60(%rbp), %rdi
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x18(%rbp), %r8
movl $0x8, %edx
movl $0x1, %ecx
callq 0x1e2f0
cmpl $0x0, %eax
je 0x1e64d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1e755
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1e60a
cmpl $0x0, -0x50(%rbp)
je 0x1e72e
movq 0x9b17(%rip), %rdi      # 0x28180
movslq -0x54(%rbp), %rdx
shlq $0x3, %rdx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x3080
movslq -0x54(%rbp), %rcx
shlq $0x3, %rcx
cmpq %rcx, %rax
jne 0x1e714
movq 0x9f39(%rip), %rdi      # 0x285d0
movslq -0x54(%rbp), %rdx
shlq $0x3, %rdx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x3080
movslq -0x54(%rbp), %rcx
shlq $0x3, %rcx
cmpq %rcx, %rax
jne 0x1e714
movq 0x9f2f(%rip), %rdi      # 0x285f0
movslq -0x54(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x3080
movslq -0x54(%rbp), %rcx
cmpq %rcx, %rax
jne 0x1e714
movq 0x9f15(%rip), %rdi      # 0x285f8
movslq -0x58(%rbp), %rdx
shlq $0x3, %rdx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x3080
movslq -0x58(%rbp), %rcx
shlq $0x3, %rcx
cmpq %rcx, %rax
jne 0x1e714
movq -0x18(%rbp), %rdi
callq 0x30f0
cmpl $-0x1, %eax
je 0x1e72e
leaq 0x2d24(%rip), %rdi      # 0x2143f
movq $-0x8, %rsi
callq 0x34b0
movl $0x1, -0x50(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3090
movl 0x9e87(%rip), %eax      # 0x285c4
cmpl $0x0, %eax
je 0x1e74e
leaq 0x2d17(%rip), %rdi      # 0x21460
callq 0x3c70
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop