// File: /workspace/github_c_makefile_star2_O3/blakemcbride[P]LISP9/ls9.c
// Function: loadimg
char *loadimg(char *path) {
	FILE		*f;
	cell		n, **v;
	int		i;
	struct imghdr	m;
	int		image_nodes, image_vcells;
	char		*s;

	f = fopen(path, "rb");
	if (NULL == f)
		return "could not open file";
	if ((s = xfread(&m, sizeof(m), 1, f)) != NULL)
		return s;
	if (memcmp(m.magic, "LISP9", sizeof(m.magic))) {
		fclose(f);
		return "imghdr match failed";
	}
	if (memcmp(m.version, VERSION, sizeof(m.version))) {
		fclose(f);
		return "wrong image version";
	}
	if (m.cell_size[0]-'0' != sizeof(cell)) {
		fclose(f);
		return "wrong cell size";
	}
	memcpy(&n, m.byte_order, sizeof(cell));
	if (n != 0x31323334L) {
		fclose(f);
		return "wrong byte order";
	}
	memset(Tag, 0, NNODES);
	if ((s = xfread(&image_nodes, sizeof(int), 1, f)) != NULL)
		return s;
	if ((s = xfread(&image_vcells, sizeof(int), 1, f)) != NULL)
		return s;
	if (image_nodes != NNODES) {
		fclose(f);
		return "wrong node pool size";
	}
	if (image_vcells != NVCELLS) {
		fclose(f);
		return "wrong vector pool size";
	}
	v = Imagevars;
	i = 0;
	while (v && v[i]) {
		if ((s = xfread(v[i], sizeof(cell), 1, f)) != NULL)
			return s;
		i++;
	}
	if (	(fread(Car, 1, sizeof(cell) * NNODES, f)
		  != sizeof(cell) * NNODES ||
		 fread(Cdr, 1, sizeof(cell) * NNODES, f)
		  != sizeof(cell) * NNODES ||
		 fread(Tag, 1, NNODES, f) != NNODES ||
		 fread(Vectors, 1, sizeof(cell) * NVCELLS, f)
		  != sizeof(cell) * NVCELLS ||
		 fgetc(f) != EOF))
	{
		fclose(f);
		return "wrong file size";
	}
	fclose(f);
	return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x30, %rsp
leaq 0x6949(%rip), %rsi      # 0x13bd8
callq 0x21c0
testq %rax, %rax
je 0xd2e5
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
movl $0x20, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x2060
leaq 0x6908(%rip), %r14      # 0x13bc2
cmpq $0x1, %rax
jne 0xd495
movl $0x5053494c, %eax       # imm = 0x5053494C
xorl 0x10(%rsp), %eax
movzbl 0x14(%rsp), %ecx
xorl $0x39, %ecx
orl %eax, %ecx
je 0xd2f1
leaq 0x690f(%rip), %r14      # 0x13bef
jmp 0xd48d
leaq 0x68ef(%rip), %r14      # 0x13bdb
jmp 0xd495
movabsq $0x3231383039313032, %rax # imm = 0x3231383039313032
cmpq %rax, 0x15(%rsp)
je 0xd30e
leaq 0x68fa(%rip), %r14      # 0x13c03
jmp 0xd48d
cmpb $0x34, 0x1d(%rsp)
jne 0xd47d
cmpl $0x31323334, 0x1e(%rsp) # imm = 0x31323334
jne 0xd486
movq 0xc022(%rip), %rdi      # 0x19350
movl $0x40000, %edx          # imm = 0x40000
xorl %esi, %esi
callq 0x20b0
leaq 0xc(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2060
cmpq $0x1, %rax
jne 0xd495
leaq 0x8(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2060
cmpq $0x1, %rax
jne 0xd495
cmpl $0x40000, 0xc(%rsp)     # imm = 0x40000
jne 0xd4a2
cmpl $0x40000, 0x8(%rsp)     # imm = 0x40000
jne 0xd4ab
movq 0xbe41(%rip), %rdi      # 0x191e0
testq %rdi, %rdi
je 0xd3d3
leaq 0xbe3d(%rip), %r15      # 0x191e8
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2060
cmpq $0x1, %rax
jne 0xd495
movq (%r15), %rdi
addq $0x8, %r15
testq %rdi, %rdi
jne 0xd3ab
movq 0xbf66(%rip), %rdi      # 0x19340
movl $0x1, %esi
movl $0x100000, %edx         # imm = 0x100000
movq %rbx, %rcx
callq 0x2060
leaq 0x6871(%rip), %r14      # 0x13c64
cmpq $0x100000, %rax         # imm = 0x100000
jne 0xd48d
movq 0xbf42(%rip), %rdi      # 0x19348
movl $0x1, %esi
movl $0x100000, %edx         # imm = 0x100000
movq %rbx, %rcx
callq 0x2060
cmpq $0x100000, %rax         # imm = 0x100000
jne 0xd48d
movq 0xbf29(%rip), %rdi      # 0x19350
movl $0x1, %esi
movl $0x40000, %edx          # imm = 0x40000
movq %rbx, %rcx
callq 0x2060
cmpq $0x40000, %rax          # imm = 0x40000
jne 0xd48d
movq 0xbf10(%rip), %rdi      # 0x19358
movl $0x1, %esi
movl $0x100000, %edx         # imm = 0x100000
movq %rbx, %rcx
callq 0x2060
cmpq $0x100000, %rax         # imm = 0x100000
jne 0xd48d
movq %rbx, %rdi
callq 0x20c0
xorl %r14d, %r14d
cmpl $-0x1, %eax
leaq 0x67ed(%rip), %rax      # 0x13c64
cmovneq %rax, %r14
jmp 0xd48d
leaq 0x6793(%rip), %r14      # 0x13c17
jmp 0xd48d
leaq 0x679a(%rip), %r14      # 0x13c27
movq %rbx, %rdi
callq 0x2070
movq %r14, %rax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %r15
retq
leaq 0x678f(%rip), %r14      # 0x13c38
jmp 0xd48d
leaq 0x679b(%rip), %r14      # 0x13c4d
jmp 0xd48d