// File: /workspace/github_c_makefile_star2_O1/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 0x49c7(%rip), %rsi      # 0x7004
callq 0x21b0
testq %rax, %rax
je 0x2850
movq %rax, %rbx
leaq 0x2(%rsp), %rdi
movl $0x1, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x2844
cmpb $0x1, 0x2(%rsp)
jne 0x269f
movl $0x1, %esi
movl $0x1, %edx
leaq 0x3(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x2844
movb 0x3(%rsp), %r12b
testb %r12b, %r12b
je 0x26b0
movl $0x1, %esi
movl $0x1, %edx
leaq 0x2(%rsp), %rdi
jmp 0x265d
movl $0x1, %esi
movl $0x1, %edx
leaq 0x2(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x282e
movzbl 0x2(%rsp), %r14d
movl $0x1, %esi
movl $0x1, %edx
leaq 0x3(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x282e
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 0x282e
movzbl 0x2(%rsp), %r15d
movl $0x1, %esi
movl $0x1, %edx
leaq 0x3(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x282e
movzbl 0x3(%rsp), %r13d
movl %r13d, %ebp
shll $0x8, %ebp
orl %r15d, %ebp
cmpl $0x1, %ebp
je 0x2844
movl 0x4(%rsp), %eax
shll $0x8, %eax
orl %r14d, %eax
testl %eax, %eax
je 0x269f
testb $0x1, %r14b
jne 0x282e
incb %r12b
addb 0x4(%rsp), %r14b
addb %r12b, %r14b
addb %r15b, %r13b
addb %r14b, %r13b
addw $-0x6, %ax
je 0x2807
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 0x282e
movzbl 0x2(%rsp), %r15d
movl $0x1, %esi
movl $0x1, %edx
leaq 0x3(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x282e
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 0x7bb5(%rip), %rsi      # 0xa3b0
movw %cx, (%rsi,%rax,2)
movl %edx, %ebp
testw %r14w, %r14w
jne 0x2799
movl $0x1, %esi
movl $0x1, %edx
leaq 0x2(%rsp), %rdi
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x282e
addb 0x2(%rsp), %r13b
je 0x269f
leaq 0x482a(%rip), %rdi      # 0x705f
callq 0x2040
movq %rbx, %rdi
callq 0x2090
jmp 0x2861
movq %rbx, %rdi
callq 0x2090
xorl %eax, %eax
jmp 0x2866
leaq 0x47b0(%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