// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
leaq 0x57dd(%rip), %rsi      # 0x10b98
callq 0x21c0
testq %rax, %rax
je 0xb3e8
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0xb384
testq %rax, %rax
je 0xb3f4
movq %rax, %r14
jmp 0xb4f7
leaq 0x57ac(%rip), %r14      # 0x10b9b
jmp 0xb4f7
leaq 0x5766(%rip), %rsi      # 0x10b61
leaq 0x10(%rsp), %rdi
pushq $0x5
popq %rdx
callq 0x2190
testl %eax, %eax
je 0xb418
leaq 0x579c(%rip), %r14      # 0x10baf
jmp 0xb4ef
movabsq $0x3231383039313032, %rax # imm = 0x3231383039313032
cmpq %rax, 0x15(%rsp)
je 0xb435
leaq 0x5793(%rip), %r14      # 0x10bc3
jmp 0xb4ef
cmpb $0x34, 0x1d(%rsp)
jne 0xb4df
cmpl $0x31323334, 0x1e(%rsp) # imm = 0x31323334
jne 0xb4e8
movq 0xbefb(%rip), %rdi      # 0x17350
movl $0x40000, %edx          # imm = 0x40000
xorl %esi, %esi
callq 0x20b0
leaq 0xc(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0xb384
testq %rax, %rax
jne 0xb3e0
leaq 0x8(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0xb384
testq %rax, %rax
jne 0xb3e0
cmpl $0x40000, 0xc(%rsp)     # imm = 0x40000
jne 0xb507
cmpl $0x40000, 0x8(%rsp)     # imm = 0x40000
jne 0xb510
leaq 0xbd2c(%rip), %r12      # 0x171e0
pushq $0x4
popq %rbp
pushq $0x1
popq %r15
movq (%r12), %rdi
testq %rdi, %rdi
je 0xb519
movl %ebp, %esi
movl %r15d, %edx
movq %rbx, %rcx
callq 0xb384
movq %rax, %r14
addq $0x8, %r12
testq %rax, %rax
je 0xb4bb
jmp 0xb4f7
leaq 0x56f1(%rip), %r14      # 0x10bd7
jmp 0xb4ef
leaq 0x56f8(%rip), %r14      # 0x10be7
movq %rbx, %rdi
callq 0x2070
movq %r14, %rax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x56ea(%rip), %r14      # 0x10bf8
jmp 0xb4ef
leaq 0x56f6(%rip), %r14      # 0x10c0d
jmp 0xb4ef
movq 0xbe20(%rip), %rdi      # 0x17340
pushq $0x1
popq %rsi
movl $0x100000, %edx         # imm = 0x100000
movq %rbx, %rcx
callq 0x2060
leaq 0x56ed(%rip), %r14      # 0x10c24
cmpq $0x100000, %rax         # imm = 0x100000
jne 0xb4ef
movq 0xbe02(%rip), %rdi      # 0x17348
pushq $0x1
popq %rsi
movl $0x100000, %edx         # imm = 0x100000
movq %rbx, %rcx
callq 0x2060
cmpq $0x100000, %rax         # imm = 0x100000
jne 0xb4ef
movq 0xbdeb(%rip), %rdi      # 0x17350
pushq $0x1
popq %rsi
movl $0x40000, %edx          # imm = 0x40000
movq %rbx, %rcx
callq 0x2060
cmpq $0x40000, %rax          # imm = 0x40000
jne 0xb4ef
movq 0xbdd0(%rip), %rdi      # 0x17358
pushq $0x1
popq %rsi
movl $0x100000, %edx         # imm = 0x100000
movq %rbx, %rcx
callq 0x2060
cmpq $0x100000, %rax         # imm = 0x100000
jne 0xb4ef
movq %rbx, %rdi
callq 0x20c0
xorl %r14d, %r14d
cmpl $-0x1, %eax
leaq 0x566b(%rip), %rax      # 0x10c24
cmovneq %rax, %r14
jmp 0xb4ef