// File: /workspace/github_c_makefile_star2_O3/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
pushq %rax
movq %rdi, %r14
leaq 0x4ac8(%rip), %rsi      # 0x7004
callq 0x21b0
testq %rax, %rax
je 0x274f
movq %rax, %rbx
leaq 0x2(%rsp), %rdi
movl $0x1, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x2743
cmpb $0x1, 0x2(%rsp)
jne 0x259e
movl $0x1, %esi
movl $0x1, %edx
leaq 0x3(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x2743
movb 0x3(%rsp), %r12b
testb %r12b, %r12b
je 0x25af
movl $0x1, %esi
movl $0x1, %edx
leaq 0x2(%rsp), %rdi
jmp 0x255c
movl $0x1, %esi
movl $0x1, %edx
leaq 0x2(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x272d
movzbl 0x2(%rsp), %r14d
movl $0x1, %esi
movl $0x1, %edx
leaq 0x3(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x272d
movzbl 0x3(%rsp), %eax
movl %eax, 0x4(%rsp)
movl $0x1, %esi
movl $0x1, %edx
leaq 0x2(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x272d
movzbl 0x2(%rsp), %r15d
movl $0x1, %esi
movl $0x1, %edx
leaq 0x3(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x272d
movzbl 0x3(%rsp), %r13d
movl %r13d, %ebp
shll $0x8, %ebp
orl %r15d, %ebp
cmpl $0x1, %ebp
je 0x2743
movl 0x4(%rsp), %eax
shll $0x8, %eax
orl %r14d, %eax
testl %eax, %eax
je 0x259e
testb $0x1, %r14b
jne 0x272d
incb %r12b
addb 0x4(%rsp), %r14b
addb %r12b, %r14b
addb %r15b, %r13b
addb %r14b, %r13b
addw $-0x6, %ax
je 0x2706
shrl %ebp
movzwl %ax, %r14d
shrl %r14d
movl $0x1, %esi
movl $0x1, %edx
leaq 0x2(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x272d
movzbl 0x2(%rsp), %r15d
movl $0x1, %esi
movl $0x1, %edx
leaq 0x3(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x272d
decl %r14d
movzwl %r15w, %eax
addb %al, %r13b
movzbl 0x3(%rsp), %ecx
addl %ecx, %r13d
shll $0x8, %ecx
orl %eax, %ecx
movzwl %bp, %eax
leal 0x1(%rbp), %edx
leaq 0x7cb6(%rip), %rsi      # 0xa3b0
movw %cx, (%rsi,%rax,2)
movl %edx, %ebp
testw %r14w, %r14w
jne 0x2698
movl $0x1, %esi
movl $0x1, %edx
leaq 0x2(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x272d
addb 0x2(%rsp), %r13b
je 0x259e
leaq 0x492b(%rip), %rdi      # 0x705f
callq 0x2040
movq %rbx, %rdi
callq 0x2090
jmp 0x2760
movq %rbx, %rdi
callq 0x2090
xorl %eax, %eax
jmp 0x2765
leaq 0x48b1(%rip), %rdi      # 0x7007
movq %r14, %rsi
xorl %eax, %eax
callq 0x20a0
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq