// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xa8ed(%rip), %rsi      # 0xd004
callq 0x21b0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x2745
movq -0x10(%rbp), %rsi
leaq 0xa8d5(%rip), %rdi      # 0xd007
movb $0x0, %al
callq 0x20a0
movl $0x1, -0x4(%rbp)
jmp 0x2a07
jmp 0x2747
movb $0x0, -0x1b(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x1a(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x2040
cmpq $0x1, %rax
jae 0x276b
jmp 0x29d7
movzbl -0x1a(%rbp), %eax
cmpl $0x1, %eax
je 0x2776
jmp 0x2747
movzbl -0x1a(%rbp), %ecx
movzbl -0x1b(%rbp), %eax
addl %ecx, %eax
movb %al, -0x1b(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x19(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x2040
cmpq $0x1, %rax
jae 0x27a3
jmp 0x29d7
movzbl -0x19(%rbp), %ecx
movzbl -0x1b(%rbp), %eax
addl %ecx, %eax
movb %al, -0x1b(%rbp)
movzbl -0x19(%rbp), %eax
shll $0x8, %eax
movzbl -0x1a(%rbp), %ecx
orl %ecx, %eax
movw %ax, -0x22(%rbp)
movzwl -0x22(%rbp), %eax
cmpl $0x1, %eax
je 0x27cf
jmp 0x2747
movq -0x18(%rbp), %rcx
leaq -0x1a(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x2040
cmpq $0x1, %rax
jae 0x27ef
jmp 0x29e9
movzbl -0x1a(%rbp), %ecx
movzbl -0x1b(%rbp), %eax
addl %ecx, %eax
movb %al, -0x1b(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x19(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x2040
cmpq $0x1, %rax
jae 0x281c
jmp 0x29e9
movzbl -0x19(%rbp), %ecx
movzbl -0x1b(%rbp), %eax
addl %ecx, %eax
movb %al, -0x1b(%rbp)
movzbl -0x19(%rbp), %eax
shll $0x8, %eax
movzbl -0x1a(%rbp), %ecx
orl %ecx, %eax
movw %ax, -0x1e(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x1a(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x2040
cmpq $0x1, %rax
jae 0x285a
jmp 0x29e9
movzbl -0x1a(%rbp), %ecx
movzbl -0x1b(%rbp), %eax
addl %ecx, %eax
movb %al, -0x1b(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x19(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x2040
cmpq $0x1, %rax
jae 0x2887
jmp 0x29e9
movzbl -0x19(%rbp), %ecx
movzbl -0x1b(%rbp), %eax
addl %ecx, %eax
movb %al, -0x1b(%rbp)
movzbl -0x19(%rbp), %eax
shll $0x8, %eax
movzbl -0x1a(%rbp), %ecx
orl %ecx, %eax
movw %ax, -0x20(%rbp)
movzwl -0x20(%rbp), %eax
cmpl $0x1, %eax
jne 0x28b3
jmp 0x29d7
movzwl -0x1e(%rbp), %eax
cmpl $0x0, %eax
jne 0x28c1
jmp 0x2747
movzwl -0x1e(%rbp), %eax
subl $0x6, %eax
movw %ax, -0x1e(%rbp)
movw -0x1e(%rbp), %ax
movw %ax, %cx
addw $-0x1, %cx
movw %cx, -0x1e(%rbp)
cmpw $0x0, %ax
je 0x29a0
movq -0x18(%rbp), %rcx
leaq -0x1a(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x2040
cmpq $0x1, %rax
jae 0x2905
jmp 0x29e9
movzbl -0x1a(%rbp), %ecx
movzbl -0x1b(%rbp), %eax
addl %ecx, %eax
movb %al, -0x1b(%rbp)
movzwl -0x20(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2959
movzwl -0x20(%rbp), %eax
sarl %eax
movslq %eax, %rcx
leaq 0xdeb2(%rip), %rax      # 0x107e0
movzwl (%rax,%rcx,2), %eax
andl $0xff, %eax
movzbl -0x1a(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movw %ax, %dx
movzwl -0x20(%rbp), %eax
sarl %eax
movslq %eax, %rcx
leaq 0xde8d(%rip), %rax      # 0x107e0
movw %dx, (%rax,%rcx,2)
jmp 0x298f
movzwl -0x20(%rbp), %eax
sarl %eax
movslq %eax, %rcx
leaq 0xde77(%rip), %rax      # 0x107e0
movzwl (%rax,%rcx,2), %eax
andl $0xff00, %eax           # imm = 0xFF00
movzbl -0x1a(%rbp), %ecx
orl %ecx, %eax
movw %ax, %dx
movzwl -0x20(%rbp), %eax
sarl %eax
movslq %eax, %rcx
leaq 0xde55(%rip), %rax      # 0x107e0
movw %dx, (%rax,%rcx,2)
movw -0x20(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x20(%rbp)
jmp 0x28cc
movq -0x18(%rbp), %rcx
leaq -0x1a(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x2040
cmpq $0x1, %rax
jae 0x29bd
jmp 0x29e9
movzbl -0x1a(%rbp), %ecx
movzbl -0x1b(%rbp), %eax
addl %ecx, %eax
movb %al, -0x1b(%rbp)
cmpb $0x0, -0x1b(%rbp)
je 0x29d2
jmp 0x29e9
jmp 0x2747
movq -0x18(%rbp), %rdi
callq 0x2080
movl $0x0, -0x4(%rbp)
jmp 0x2a07
leaq 0xa626(%rip), %rdi      # 0xd016
movb $0x0, %al
callq 0x20a0
movq -0x18(%rbp), %rdi
callq 0x2080
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq