// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq %rdi, %r14
leaq 0x5b23(%rip), %rsi      # 0x8004
callq 0x21b0
testq %rax, %rax
je 0x2687
movq %rax, %rbx
pushq $0x1
popq %r15
leaq 0x1(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x269d
cmpb $0x1, 0x1(%rsp)
jne 0x24f6
leaq 0x2(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x269d
movb 0x2(%rsp), %al
movb %al, 0x3(%rsp)
testb %al, %al
jne 0x24f6
leaq 0x1(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x2671
movzbl 0x1(%rsp), %r13d
leaq 0x2(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x2671
movzbl 0x2(%rsp), %eax
movl %eax, 0x4(%rsp)
leaq 0x1(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x2671
movzbl 0x1(%rsp), %ebp
leaq 0x2(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
testq %rax, %rax
je 0x2671
movl %ebp, %ecx
movzwl %cx, %eax
movzbl 0x2(%rsp), %r12d
movl %r12d, %ebp
shll $0x8, %ebp
orl %eax, %ebp
cmpw $0x1, %bp
je 0x269d
movl 0x4(%rsp), %r14d
shll $0x8, %r14d
orl %r13d, %r14d
testl %r14d, %r14d
je 0x24f6
movb 0x3(%rsp), %al
incb %al
addb 0x4(%rsp), %r13b
addb %al, %r13b
addb %cl, %r12b
addb %r13b, %r12b
addl $-0x6, %r14d
leaq 0x1(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2050
subw $0x1, %r14w
jb 0x2661
testq %rax, %rax
je 0x2671
movzbl 0x1(%rsp), %eax
movzwl %bp, %ecx
testb $0x1, %cl
jne 0x2649
movl %ecx, %ecx
leaq 0x918c(%rip), %rdx      # 0xb7d0
movb %al, (%rcx,%rdx)
jmp 0x2657
andl $-0x2, %ecx
leaq 0x917d(%rip), %rdx      # 0xb7d0
movb %al, 0x1(%rcx,%rdx)
addb %r12b, %al
incl %ebp
movl %eax, %r12d
jmp 0x260f
testq %rax, %rax
je 0x2671
addb 0x1(%rsp), %r12b
je 0x24f6
leaq 0x59ea(%rip), %rdi      # 0x8062
callq 0x2040
movq %rbx, %rdi
callq 0x2090
jmp 0x2698
leaq 0x5979(%rip), %rdi      # 0x8007
movq %r14, %rsi
xorl %eax, %eax
callq 0x20a0
pushq $0x1
popq %rax
jmp 0x26a7
movq %rbx, %rdi
callq 0x2090
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq