// File: /workspace/github_c_makefile_star2_O2/aap[P]pdp11/1120.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;
		/* odd number of bytes is probably allowed but we can't do it */
		if(n&1)
			goto botch;
		n >>= 1;
		a >>= 1;
		while(n--){
			if(fread(&lo, 1, 1, f) < 1) goto botch;
			s += lo;
			if(fread(&hi, 1, 1, f) < 1) goto botch;
			s += hi;
			w = WD(hi, lo);
			memory[a++] = w;
		}
		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 0x4b25(%rip), %rsi      # 0x7004
callq 0x21b0
testq %rax, %rax
je 0x26c6
movq %rax, %rbx
pushq $0x1
popq %r15
leaq 0x6(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x26dc
cmpb $0x1, 0x6(%rsp)
jne 0x24f4
leaq 0x7(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x26dc
movb 0x7(%rsp), %r12b
testb %r12b, %r12b
jne 0x24f4
leaq 0x6(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x26b0
movzbl 0x6(%rsp), %eax
movq %rax, 0x8(%rsp)
leaq 0x7(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x26b0
movzbl 0x7(%rsp), %eax
movq %rax, 0x10(%rsp)
leaq 0x6(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x26b0
movzbl 0x6(%rsp), %r14d
leaq 0x7(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x26b0
movzbl 0x7(%rsp), %ebp
movl %ebp, %r13d
shll $0x8, %r13d
orl %r14d, %r13d
cmpl $0x1, %r13d
je 0x26dc
movq 0x10(%rsp), %rax
shll $0x8, %eax
addl 0x8(%rsp), %eax
testl %eax, %eax
je 0x24f4
testb $0x1, 0x8(%rsp)
jne 0x26b0
incb %r12b
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rdx
leal (%rdx,%rcx), %eax
addb %r12b, %al
addb %r14b, %bpl
addb %al, %bpl
andl $-0x2, %r13d
movzwl %dx, %eax
shll $0x8, %eax
addl %ecx, %eax
addl $-0x6, %eax
movzwl %ax, %eax
shrl %eax
movq %rax, 0x8(%rsp)
xorl %r12d, %r12d
leaq 0x6(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
cmpw %r12w, 0x8(%rsp)
je 0x26a0
testq %rax, %rax
je 0x26b0
movzbl 0x6(%rsp), %r14d
leaq 0x7(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x26b0
movzwl %r14w, %eax
addb %al, %bpl
movzbl 0x7(%rsp), %ecx
addl %ecx, %ebp
shll $0x8, %ecx
orl %eax, %ecx
leaq (,%r12,2), %rax
addq %r13, %rax
leaq 0x7d19(%rip), %rdx      # 0xa3b0
movw %cx, (%rdx,%rax)
incq %r12
jmp 0x2634
testq %rax, %rax
je 0x26b0
addb 0x6(%rsp), %bpl
je 0x24f4
leaq 0x49a8(%rip), %rdi      # 0x705f
callq 0x2040
movq %rbx, %rdi
callq 0x2090
jmp 0x26d7
leaq 0x493a(%rip), %rdi      # 0x7007
movq %r14, %rsi
xorl %eax, %eax
callq 0x20a0
pushq $0x1
popq %rax
jmp 0x26e6
movq %rbx, %rdi
callq 0x2090
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq