// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x890d(%rip), %rsi      # 0xb004
callq 0x21b0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x2725
movq -0x10(%rbp), %rsi
leaq 0x88f5(%rip), %rdi      # 0xb007
movb $0x0, %al
callq 0x20a0
movl $0x1, -0x4(%rbp)
jmp 0x29e4
jmp 0x2727
movb $0x0, -0x1b(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x1a(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x2040
cmpq $0x1, %rax
jae 0x274b
jmp 0x29b4
movzbl -0x1a(%rbp), %eax
cmpl $0x1, %eax
je 0x2756
jmp 0x2727
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 0x2783
jmp 0x29b4
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 0x27af
jmp 0x2727
movq -0x18(%rbp), %rcx
leaq -0x1a(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x2040
cmpq $0x1, %rax
jae 0x27cf
jmp 0x29c6
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 0x27fc
jmp 0x29c6
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 0x283a
jmp 0x29c6
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 0x2867
jmp 0x29c6
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 0x2893
jmp 0x29b4
movzwl -0x1e(%rbp), %eax
cmpl $0x0, %eax
jne 0x28a1
jmp 0x2727
movzwl -0x1e(%rbp), %eax
subl $0x6, %eax
movw %ax, -0x1e(%rbp)
movzwl -0x1e(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x28bd
jmp 0x29c6
movzwl -0x1e(%rbp), %eax
sarl %eax
movw %ax, -0x1e(%rbp)
movzwl -0x20(%rbp), %eax
sarl %eax
movw %ax, -0x20(%rbp)
movw -0x1e(%rbp), %ax
movw %ax, %cx
addw $-0x1, %cx
movw %cx, -0x1e(%rbp)
cmpw $0x0, %ax
je 0x297d
movq -0x18(%rbp), %rcx
leaq -0x1a(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x2040
cmpq $0x1, %rax
jae 0x290a
jmp 0x29c6
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 0x2937
jmp 0x29c6
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)
movw -0x22(%rbp), %dx
movw -0x20(%rbp), %ax
movw %ax, %cx
addw $0x1, %cx
movw %cx, -0x20(%rbp)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0xba4c(%rip), %rax      # 0xe3c0
movw %dx, (%rax,%rcx,2)
jmp 0x28d1
movq -0x18(%rbp), %rcx
leaq -0x1a(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x2040
cmpq $0x1, %rax
jae 0x299a
jmp 0x29c6
movzbl -0x1a(%rbp), %ecx
movzbl -0x1b(%rbp), %eax
addl %ecx, %eax
movb %al, -0x1b(%rbp)
cmpb $0x0, -0x1b(%rbp)
je 0x29af
jmp 0x29c6
jmp 0x2727
movq -0x18(%rbp), %rdi
callq 0x2080
movl $0x0, -0x4(%rbp)
jmp 0x29e4
leaq 0x8649(%rip), %rdi      # 0xb016
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
nopl (%rax)