// File: /workspace/github_c_makefile_star2_O1/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 0x6973(%rip), %rsi      # 0x13ba8
callq 0x21c0
testq %rax, %rax
je 0xd292
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
movl $0x20, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x2060
xorl %r14d, %r14d
leaq 0x692f(%rip), %r15      # 0x13b92
cmpq $0x1, %rax
cmovneq %r15, %r14
jne 0xd450
movl $0x5053494c, %eax       # imm = 0x5053494C
xorl 0x10(%rsp), %eax
movzbl 0x14(%rsp), %ecx
xorl $0x39, %ecx
orl %eax, %ecx
je 0xd29e
leaq 0x6932(%rip), %r14      # 0x13bbf
jmp 0xd448
leaq 0x6912(%rip), %r14      # 0x13bab
jmp 0xd450
movabsq $0x3231383039313032, %rax # imm = 0x3231383039313032
cmpq %rax, 0x15(%rsp)
je 0xd2bb
leaq 0x691d(%rip), %r14      # 0x13bd3
jmp 0xd448
cmpb $0x34, 0x1d(%rsp)
jne 0xd438
cmpl $0x31323334, 0x1e(%rsp) # imm = 0x31323334
jne 0xd441
movq 0xc075(%rip), %rdi      # 0x19350
xorl %r14d, %r14d
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
cmovneq %r15, %r14
jne 0xd450
leaq 0x8(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2060
xorl %r14d, %r14d
cmpq $0x1, %rax
cmovneq %r15, %r14
jne 0xd450
cmpl $0x40000, 0xc(%rsp)     # imm = 0x40000
jne 0xd45d
cmpl $0x40000, 0x8(%rsp)     # imm = 0x40000
jne 0xd466
movq 0xbe86(%rip), %rdi      # 0x191e0
testq %rdi, %rdi
je 0xd38e
leaq 0xbe82(%rip), %r14      # 0x191e8
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2060
cmpq $0x1, %rax
jne 0xd46f
movq (%r14), %rdi
addq $0x8, %r14
testq %rdi, %rdi
jne 0xd366
movq 0xbfab(%rip), %rdi      # 0x19340
movl $0x1, %esi
movl $0x100000, %edx         # imm = 0x100000
movq %rbx, %rcx
callq 0x2060
leaq 0x6886(%rip), %r14      # 0x13c34
cmpq $0x100000, %rax         # imm = 0x100000
jne 0xd448
movq 0xbf87(%rip), %rdi      # 0x19348
movl $0x1, %esi
movl $0x100000, %edx         # imm = 0x100000
movq %rbx, %rcx
callq 0x2060
cmpq $0x100000, %rax         # imm = 0x100000
jne 0xd448
movq 0xbf6e(%rip), %rdi      # 0x19350
movl $0x1, %esi
movl $0x40000, %edx          # imm = 0x40000
movq %rbx, %rcx
callq 0x2060
cmpq $0x40000, %rax          # imm = 0x40000
jne 0xd448
movq 0xbf55(%rip), %rdi      # 0x19358
movl $0x1, %esi
movl $0x100000, %edx         # imm = 0x100000
movq %rbx, %rcx
callq 0x2060
cmpq $0x100000, %rax         # imm = 0x100000
jne 0xd448
movq %rbx, %rdi
callq 0x20c0
xorl %r14d, %r14d
cmpl $-0x1, %eax
leaq 0x6802(%rip), %rax      # 0x13c34
cmovneq %rax, %r14
jmp 0xd448
leaq 0x67a8(%rip), %r14      # 0x13be7
jmp 0xd448
leaq 0x67af(%rip), %r14      # 0x13bf7
movq %rbx, %rdi
callq 0x2070
movq %r14, %rax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %r15
retq
leaq 0x67a4(%rip), %r14      # 0x13c08
jmp 0xd448
leaq 0x67b0(%rip), %r14      # 0x13c1d
jmp 0xd448
movq %r15, %r14
jmp 0xd450