// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/1140.c
// Function: loadpt
int
loadpt(char *filename)
{
	FILE *f;
	byte hi, lo, s;
	word n, a, w;

	f = fopen(filename, "rb");
	if(f == nil){
		printf("can't open %s\n", filename);
		return 1;
	}

	for(;;){
		s = 0;
		if(fread(&lo, 1, 1, f) < 1) break;
		if(lo != 1)
			continue;
		s += lo;
		if(fread(&hi, 1, 1, f) < 1) break;
		s += hi;
		w = WD(hi, lo);
		if(w != 1)
			continue;
		if(fread(&lo, 1, 1, f) < 1) goto botch;
		s += lo;
		if(fread(&hi, 1, 1, f) < 1) goto botch;
		s += hi;
		n = WD(hi, lo);
		if(fread(&lo, 1, 1, f) < 1) goto botch;
		s += lo;
		if(fread(&hi, 1, 1, f) < 1) goto botch;
		s += hi;
		a = WD(hi, lo);
		if(a == 1)
			break;
		if(n == 0)
			continue;
		n -= 6;
		while(n--){
			if(fread(&lo, 1, 1, f) < 1) goto botch;
			s += lo;
			if(a & 1)
				memory[a>>1] = memory[a>>1]&0377 | lo<<8;
			else
				memory[a>>1] = memory[a>>1]&0177400 | lo;
			a++;
		}
		if(fread(&lo, 1, 1, f) < 1) goto botch;
		s += lo;
		if(s)
			goto botch;
	}
	fclose(f);
	return 0;
botch:
	printf("paper tape botch\n");
	fclose(f);
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
leaq 0x6992(%rip), %rsi      # 0x9004
callq 0x21b0
testq %rax, %rax
je 0x286f
movq %rax, %rbx
leaq 0xe(%rsp), %rdi
movl $0x1, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x2863
cmpb $0x1, 0xe(%rsp)
jne 0x26d4
movl $0x1, %esi
movl $0x1, %edx
leaq 0xf(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x2863
movb 0xf(%rsp), %r12b
testb %r12b, %r12b
je 0x26e5
movl $0x1, %esi
movl $0x1, %edx
leaq 0xe(%rsp), %rdi
jmp 0x2692
movl $0x1, %esi
movl $0x1, %edx
leaq 0xe(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x284d
movzbl 0xe(%rsp), %eax
movq %rax, 0x10(%rsp)
movl $0x1, %esi
movl $0x1, %edx
leaq 0xf(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x284d
movzbl 0xf(%rsp), %r15d
movl $0x1, %esi
movl $0x1, %edx
leaq 0xe(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x284d
movzbl 0xe(%rsp), %r14d
movl $0x1, %esi
movl $0x1, %edx
leaq 0xf(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x284d
movzwl %r14w, %eax
movzbl 0xf(%rsp), %ebp
movl %ebp, %r13d
shll $0x8, %r13d
orl %eax, %r13d
cmpw $0x1, %r13w
je 0x2863
movl %r15d, %eax
shll $0x8, %eax
addl 0x10(%rsp), %eax
testl %eax, %eax
je 0x26d4
incb %r12b
movq 0x10(%rsp), %rdx
leal (%r15,%rdx), %ecx
addb %r12b, %cl
addb %r14b, %bpl
addb %cl, %bpl
cmpl $0x6, %eax
je 0x2826
movzwl %r15w, %eax
shll $0x8, %eax
leal (%rax,%rdx), %r14d
addl $-0x6, %r14d
movl $0x1, %esi
movl $0x1, %edx
leaq 0xe(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x284d
movzbl 0xe(%rsp), %eax
movzwl %r13w, %ecx
testb $0x1, %cl
jne 0x280c
movl %ecx, %ecx
leaq 0x9fc9(%rip), %rdx      # 0xc7d0
movb %al, (%rcx,%rdx)
jmp 0x281a
andl $-0x2, %ecx
leaq 0x9fba(%rip), %rdx      # 0xc7d0
movb %al, 0x1(%rcx,%rdx)
addb %al, %bpl
incl %r13d
decw %r14w
jne 0x27d4
movl $0x1, %esi
movl $0x1, %edx
leaq 0xe(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x284d
addb 0xe(%rsp), %bpl
je 0x26d4
leaq 0x680e(%rip), %rdi      # 0x9062
callq 0x2040
movq %rbx, %rdi
callq 0x2090
jmp 0x2880
movq %rbx, %rdi
callq 0x2090
xorl %eax, %eax
jmp 0x2885
leaq 0x6791(%rip), %rdi      # 0x9007
movq %r14, %rsi
xorl %eax, %eax
callq 0x20a0
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq