LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/ka11.c
// Function: addrop
static int
addrop(KA11 *cpu, int m, int b)
{
	int r;
	int ai;
	r = m&7;
	m >>= 3;
	ai = 1 + (!b || (r&6)==6 || m&1);
	if(m == 0){
//		assert(0);
		return 0;
	}
	switch(m&6){
	case 0:		// REG
		cpu->b = cpu->ba = cpu->r[r];
		return 0;	// this already is mode 1
	case 2:		// INC
		cpu->ba = cpu->r[r];
		cpu->b = cpu->r[r] = cpu->r[r] + ai;
		break;
	case 4:		// DEC
		cpu->b = cpu->ba = cpu->r[r]-ai;
		if(r == 6 && (cpu->ba&~0377) == 0) cpu->traps |= TRAP_STACK;
		cpu->r[r] = cpu->ba;
		break;
	case 6:		// INDEX
		cpu->ba = cpu->r[7];
		cpu->r[7] += 2;
		if(dati(cpu, 0)) return 1;
		cpu->b = cpu->ba = cpu->bus->data + cpu->r[r];
		break;
	}
	if(m&1){
		if(dati(cpu, 0)) return 1;
		cpu->b = cpu->ba = cpu->bus->data;
	}
	return 0;

}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ecx
notl %ecx
xorl %eax, %eax
btl $0x3, %esi
adcw $0x1, %ax
testb $0x6, %cl
movl $0x2, %ecx
cmovel %ecx, %eax
testl %edx, %edx
cmovel %ecx, %eax
cmpl $0x8, %esi
jb 0x4cf9
movl %esi, %ebp
movq %rdi, %rbx
movl %esi, %r14d
andl $0x7, %r14d
movl %esi, %ecx
shrl $0x3, %ecx
andl $0x6, %ecx
leaq 0x24ff(%rip), %rdx      # 0x7134
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl %r14d, %eax
leaq (%rbx,%rax,2), %rax
jmp 0x4cee
movzwl 0xe(%rbx), %eax
movw %ax, 0x22(%rbx)
addl $0x2, %eax
movw %ax, 0xe(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2d35
movl %eax, %ecx
movl $0x1, %eax
testl %ecx, %ecx
jne 0x4cfb
movq 0x28(%rbx), %rax
movl %r14d, %ecx
movzwl (%rbx,%rcx,2), %ecx
addw 0xc(%rax), %cx
movw %cx, 0x22(%rbx)
movw %cx, 0x20(%rbx)
jmp 0x4ccb
movl %r14d, %ecx
movzwl (%rbx,%rcx,2), %edx
movw %dx, 0x22(%rbx)
addl %edx, %eax
movw %ax, (%rbx,%rcx,2)
movw %ax, 0x20(%rbx)
jmp 0x4ccb
movl %r14d, %ecx
movzwl (%rbx,%rcx,2), %edx
subl %eax, %edx
movw %dx, 0x22(%rbx)
movw %dx, 0x20(%rbx)
cmpl $0x6, %r14d
jne 0x4cc7
movzwl %dx, %eax
cmpl $0xff, %eax
ja 0x4cc7
orb $0x1, 0x34(%rbx)
movw %dx, (%rbx,%rcx,2)
testb $0x8, %bpl
je 0x4cf9
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2d35
movl %eax, %ecx
movl $0x1, %eax
testl %ecx, %ecx
jne 0x4cfb
movq 0x28(%rbx), %rax
addq $0xc, %rax
movzwl (%rax), %eax
movw %ax, 0x22(%rbx)
movw %ax, 0x20(%rbx)
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/ka11.c
// Function: run
void
run(KA11 *cpu)
{
	int count;

	count = 0;
	cpu->state = STATE_RUNNING;
	while(cpu->state != STATE_HALTED){
		svc(cpu, cpu->bus);

#ifdef AUTODIAG
	extern int diagpassed;
	if(diagpassed)
		return;
#endif

		if(cpu->state == STATE_RUNNING ||
		   cpu->state == STATE_WAITING && cpu->traps){
			cpu->state = STATE_RUNNING;
			step(cpu);
		}

		if (count++ == 1000) {
			sleep_ms(cpu->throttle);
			count = 0;
		}
	}

	printstate(cpu);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl $0x1, 0x3c(%rdi)
leaq 0x48(%rdi), %r15
xorl %ebp, %ebp
leaq 0x276e(%rip), %r12      # 0x7490
movq 0x28(%rbx), %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%r15)
movups %xmm0, 0x20(%r15)
movups %xmm0, 0x10(%r15)
movups %xmm0, (%r15)
andb $-0x6d, 0x34(%rbx)
movq (%r14), %r13
testq %r13, %r13
je 0x4d8d
movq 0x8(%r13), %rsi
movq %r14, %rdi
callq *0x28(%r13)
movl %eax, %ecx
andl $-0x4, %ecx
cmpl $0x4, %ecx
jne 0x4d87
addl $-0x4, %eax
movq %rax, %rcx
shlq $0x4, %rcx
cmpq $0x0, (%r15,%rcx)
jne 0x4d87
addq %r15, %rcx
movq 0x30(%r13), %rdx
movq %rdx, (%rcx)
movq 0x8(%r13), %rdx
movq %rdx, 0x8(%rcx)
movl (%r12,%rax,4), %eax
orl %eax, 0x34(%rbx)
movq (%r13), %r13
jmp 0x4d43
movl 0x3c(%rbx), %eax
cmpl $0x1, %eax
je 0x4da0
cmpl $0x2, %eax
jne 0x4daf
cmpl $0x0, 0x34(%rbx)
je 0x4daf
movl $0x1, 0x3c(%rbx)
movq %rbx, %rdi
callq 0x2ec2
cmpl $0x3e8, %ebp            # imm = 0x3E8
je 0x4dbb
incl %ebp
jmp 0x4dc5
movl 0x40(%rbx), %edi
callq 0x69f9
xorl %ebp, %ebp
cmpl $0x0, 0x3c(%rbx)
jne 0x4d22
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c48
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/eae.c
// Function: dato_ke11
int
dato_ke11(Bus *bus, void *dev)
{
	KE11 *ke = dev;
	if(bus->addr >= 0777300 && bus->addr < 0777320){
//		printf("EAE DATO %o %o\n", bus->addr, bus->data);
		switch(bus->addr){
		case KE_DIV:
			ke->x = bus->data;
			divide(ke);
			break;
		case KE_AC:
			ke->ac = bus->data;
			break;
		case KE_MQ:
			ke->mq = bus->data;
			/* sign extend into AC */
			if(ke->mq&0100000)
				ke->ac = 0177777;
			else
				ke->ac = 0;
			break;
		case KE_MULT:
			ke->x = bus->data;
			mult(ke);
			break;
		case KE_SCSR:
			ke->sc = bus->data & 077;
			SETMASK(ke->sr, bus->data>>8, 0301);
			break;
		case KE_NORM:
			norm(ke);
			break;
		case KE_LSH:
			ke->sc = bus->data & 077;
			lsh(ke);
			break;
		case KE_ASH:
			ke->sc = bus->data & 077;
			ash(ke);
			break;
		default: assert(0);	/* can't happen */
		}
		return 0;
	}
	return 1;
}

// Assembly:
pushq %rax
movl 0x8(%rdi), %ecx
movl %ecx, %edx
andl $-0x10, %edx
movl $0x1, %eax
cmpl $0x3fec0, %edx          # imm = 0x3FEC0
jne 0x4eb8
addl $0xfffc0140, %ecx       # imm = 0xFFFC0140
cmpl $0xe, %ecx
ja 0x4eba
leaq 0x2688(%rip), %rax      # 0x74a0
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movzwl 0xc(%rdi), %eax
movw %ax, 0x4(%rsi)
movq %rsi, %rdi
callq 0x4ed9
jmp 0x4eb6
movzwl 0xc(%rdi), %eax
movl %eax, %ecx
andb $0x3f, %cl
movb %cl, 0x6(%rsi)
movb 0x7(%rsi), %cl
andb $0x3e, %cl
shrl $0x8, %eax
andb $-0x3f, %al
orb %cl, %al
movb %al, 0x7(%rsi)
jmp 0x4eb6
movq %rsi, %rdi
callq 0x509e
jmp 0x4eb6
movzwl 0xc(%rdi), %eax
movw %ax, 0x2(%rsi)
testw %ax, %ax
js 0x4eb1
movw $0x0, (%rsi)
jmp 0x4eb6
movb 0xc(%rdi), %al
andb $0x3f, %al
movb %al, 0x6(%rsi)
movq %rsi, %rdi
callq 0x51e7
jmp 0x4eb6
movzwl 0xc(%rdi), %eax
movw %ax, 0x4(%rsi)
movq %rsi, %rdi
callq 0x503e
jmp 0x4eb6
movzwl 0xc(%rdi), %eax
movw %ax, (%rsi)
jmp 0x4eb6
movb 0xc(%rdi), %al
andb $0x3f, %al
movb %al, 0x6(%rsi)
movq %rsi, %rdi
callq 0x511c
jmp 0x4eb6
movw $0xffff, (%rsi)         # imm = 0xFFFF
xorl %eax, %eax
popq %rcx
retq
leaq 0x250a(%rip), %rdi      # 0x73cb
leaq 0x2690(%rip), %rsi      # 0x7558
leaq 0x268f(%rip), %rcx      # 0x755e
movl $0x12a, %edx            # imm = 0x12A
callq 0x20d0
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/eae.c
// Function: divide
static void
divide(KE11 *ke)
{
	uint32 dd, dr;
	uint16 q;
	int c;
	int s;
	int ov;

	dd = ke->ac<<16 | ke->mq;
	dr = ke->x<<16;
	q = 0;
	ov = 0;
	ke->sr &= ~SR_C;
	s = !!(dd&B31);
	ke->sc = 16;
	do{
		c = (dr&B31) == (dd&B31);
		dr >>= 1;
		if(dr&B30)
			dr |= B31;
		q <<= 1;
		q |= c;
		if(c)
			dd += ~dr + 1;
		else
			dd += dr;
		if(ke->sc == 16 && dd != 0 && !!(dd>>31 & 1) == s)
			goto ov;
		ke->sc--;
	}while(ke->sc);

	if(dd == 0 ||
/* is this correct? */
	   dd + abs32(dr) != 0 && !!(dd>>31 & 1) == s){
		c = 1;
		q <<= 1;
		q |= c;
	}else{
		c = (dd&B31) == (dr&B31);
		if(c)
			dd += ~dr + 1;
		else
			dd += dr;
		q += c;
		c = 0;
		q <<= 1;
	}

	/* DOCU manual says DD in one place and DR in another...
	 * which is correct? have to check */
	if((dr>>31 & 1) != (q>>15 & 1) != s)
ov:
		ov = 1;

	ke->ac = dd;
	ke->mq = q;
	setflag(ke, SR_OV, ov != (ke->sr>>6 & 1));
	setflags(ke);
	if(ov)
		setflag(ke, SR_NEG, s);
	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movzwl (%rdi), %ebp
movl %ebp, %eax
shll $0x10, %eax
movzwl 0x2(%rdi), %edx
orl %eax, %edx
movzwl 0x4(%rdi), %r9d
shll $0x10, %r9d
movzbl 0x7(%rdi), %ecx
movl %ecx, %eax
andb $-0x2, %al
movb %al, 0x7(%rdi)
movl %ebp, %edi
shrl $0xf, %edi
movb $0x10, 0x6(%rbx)
xorl %esi, %esi
movb $0xf, %r10b
movl %edx, %r11d
movl %r9d, %r8d
movl %r9d, %edx
shrl %edx
andl $0x80000000, %r9d       # imm = 0x80000000
orl %edx, %r9d
andl $0x7fff, %esi           # imm = 0x7FFF
movl %r9d, %edx
negl %edx
xorl %r14d, %r14d
movl %r11d, %r15d
xorl %r8d, %r15d
setns %r14b
cmovsl %r9d, %edx
leal (%r14,%rsi,2), %esi
addl %r11d, %edx
cmpb $0xf, %r10b
sete %r14b
testl %edx, %edx
setne %r15b
movl %edx, %r11d
shrl $0x1f, %r11d
cmpl %edi, %r11d
sete %r12b
andb %r14b, %r12b
testb %r15b, %r12b
jne 0x4fab
movb %r10b, 0x6(%rbx)
addb $-0x1, %r10b
jb 0x4f14
testl %edx, %edx
je 0x4fa2
cmpl %edi, %r11d
sete %r11b
movl %r9d, %r10d
negl %r10d
movl %r9d, %r14d
cmovnsl %r10d, %r14d
addl %edx, %r14d
setne %r14b
andb %r11b, %r14b
cmpb $0x1, %r14b
jne 0x4fb6
leal 0x1(,%rsi,2), %esi
jmp 0x4fcf
movl $0x1, %r8d
xorl %r14d, %r14d
jmp 0x4ff3
xorl %r11d, %r11d
movl %edx, %r14d
xorl %r8d, %r14d
cmovnsl %r10d, %r9d
setns %r11b
addl %r9d, %edx
addl %r11d, %esi
addl %esi, %esi
shrl $0x1f, %r8d
movzwl %si, %r9d
shrl $0xf, %r9d
xorl %r10d, %r10d
cmpl %r9d, %r8d
setne %r10b
xorl %r8d, %r8d
cmpl %r10d, %edi
sete %r14b
setne %r8b
movw %dx, (%rbx)
movw %si, 0x2(%rbx)
orb $-0x80, %al
movl %ecx, %edx
andb $0x7e, %dl
btl $0x6, %ecx
sbbl $0x0, %r8d
movzbl %al, %eax
movzbl %dl, %ecx
cmovnel %eax, %ecx
movb %cl, 0x7(%rbx)
movq %rbx, %rdi
callq 0x541e
testb %r14b, %r14b
jne 0x5035
movb 0x7(%rbx), %al
andb $-0x41, %al
shrl $0x9, %ebp
andb $0x40, %bpl
orb %al, %bpl
movb %bpl, 0x7(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/eae.c
// Function: mult
static void
mult(KE11 *ke)
{
	uint32 sum, md;
	int c;

	sum = 0;
	md = ke->ac<<16 | ke->mq;
	c = 0;
	ke->sc = 16;
	do{
		if((ke->x & 1) != c){
			if(ke->x&1)
				sum += ~md + 1;
			else
				sum += md;
		}
		md <<= 1;
		c = ke->x&1;
		ke->x >>= 1;
		ke->sc--;
	}while(ke->sc);
	ke->ac = sum>>16;
	ke->mq = sum;
	ke->sr &= ~SR_C;
	setflags(ke);
}

// Assembly:
movzwl (%rdi), %eax
shll $0x10, %eax
movzwl 0x2(%rdi), %ecx
orl %eax, %ecx
movb $0x10, 0x6(%rdi)
movzwl 0x4(%rdi), %edx
xorl %eax, %eax
movb $-0x10, %sil
xorl %r8d, %r8d
movl %r8d, %r9d
movl %edx, %r8d
andl $0x1, %r8d
cmpl %r8d, %r9d
je 0x5075
testw %r8w, %r8w
jne 0x5073
addl %ecx, %eax
jmp 0x5075
subl %ecx, %eax
addl %ecx, %ecx
movzwl %dx, %edx
shrl %edx
incb %sil
jne 0x505a
movw %dx, 0x4(%rdi)
movb $0x0, 0x6(%rdi)
movl %eax, %ecx
shrl $0x10, %ecx
movw %cx, (%rdi)
movw %ax, 0x2(%rdi)
andb $-0x2, 0x7(%rdi)
jmp 0x541e
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/eae.c
// Function: norm
static void
norm(KE11 *ke)
{
	uint32 sh;

	sh = ke->ac<<16 | ke->mq;
	ke->sc = 0;
	ke->sr &= ~(SR_OV|SR_C);
	setflag(ke, SR_NEG, sh & B31);
	if(ke->sr & SR_NEG)
		ke->sr |= SR_OV;
loop:
	if((sh>>31 & 1) != (sh>>30 & 1))
		goto done;
	if(sh == (3U<<30))
		goto done;
	if(ke->sc == 31)
		goto done;
	sh <<= 1;
	ke->sc++;
	goto loop;
done:
	ke->ac = sh>>16;
	ke->mq = sh;
	setflags(ke);
}

// Assembly:
movzwl (%rdi), %ecx
movl %ecx, %edx
shll $0x10, %edx
movzwl 0x2(%rdi), %eax
orl %edx, %eax
movb $0x0, 0x6(%rdi)
movb 0x7(%rdi), %sil
andb $0x3e, %sil
leal -0x40(%rsi), %r8d
testl %edx, %edx
movzbl %sil, %edx
movzbl %r8b, %esi
cmovnsl %edx, %esi
movb %sil, 0x7(%rdi)
cmpl $0xc0000000, %eax       # imm = 0xC0000000
je 0x5110
movl %ecx, %edx
shrl $0xf, %edx
shrl $0xe, %ecx
andl $0x1, %ecx
cmpl %ecx, %edx
jne 0x5110
movb 0x6(%rdi), %dl
incb %dl
cmpb $0x20, %dl
je 0x5110
leal (%rax,%rax), %ecx
movb %dl, 0x6(%rdi)
cmpl $0xc0000000, %ecx       # imm = 0xC0000000
je 0x5112
movl %ecx, %esi
shrl $0x1f, %esi
shrl $0x1d, %eax
andl $0x1, %eax
incb %dl
cmpl %eax, %esi
movl %ecx, %eax
je 0x50e8
jmp 0x5112
movl %eax, %ecx
rorl $0x10, %ecx
movl %ecx, (%rdi)
jmp 0x541e
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/eae.c
// Function: lsh
static void
lsh(KE11 *ke)
{
	uint32 sh;
	int ov;

	sh = ke->ac<<16 | ke->mq;
	setflag(ke, SR_NEG, sh&B31);
	ov = 0;
loop:
	ke->sc &= 077;
	if(ke->sc == 0)
		goto done;
	if(ke->sc&040){
		/* negative, shift right */
		setflag(ke, SR_C, sh&1);
		sh >>= 1;
		ke->sr &= ~SR_NEG;
		ke->sc++;
	}else{
		/* positive, shift left */
		setflag(ke, SR_C, sh&B31);
		sh <<= 1;
		if((ke->sr>>6 & 1) != (sh>>31 & 1))
			ov = 1;	/* sign changed */
		setflag(ke, SR_NEG, sh&B31);
		ke->sc--;
	}
	goto loop;
done:
	setflag(ke, SR_OV, ov != (ke->sr>>6 & 1));
	ke->ac = sh>>16;
	ke->mq = sh;
	setflags(ke);
}

// Assembly:
movzwl (%rdi), %ecx
movl %ecx, %edx
shll $0x10, %edx
movzwl 0x2(%rdi), %eax
orl %edx, %eax
movb 0x6(%rdi), %r8b
movb 0x7(%rdi), %dl
andb $-0x41, %dl
shrl $0x9, %ecx
andb $0x40, %cl
orb %dl, %cl
movb %cl, 0x7(%rdi)
movl %r8d, %edx
xorl %ecx, %ecx
andb $0x3f, %dl
je 0x51ba
movl $0x1, %esi
testb $0x20, %r8b
jne 0x515e
testl %eax, %eax
js 0x5177
andb $-0x2, 0x7(%rdi)
jmp 0x517b
testb $0x1, %al
jne 0x5168
andb $-0x2, 0x7(%rdi)
jmp 0x516c
orb $0x1, 0x7(%rdi)
shrl %eax
andb $-0x41, 0x7(%rdi)
movb $0x1, %r9b
jmp 0x51ac
orb $0x1, 0x7(%rdi)
leal (%rax,%rax), %r8d
movzbl 0x7(%rdi), %r9d
movl %r8d, %r10d
shrl $0x1f, %r10d
btl $0x6, %r9d
sbbl $0x0, %r10d
cmovnel %esi, %ecx
andb $-0x41, %r9b
shrl $0x18, %eax
andb $0x40, %al
orb %r9b, %al
movb %al, 0x7(%rdi)
movb $-0x1, %r9b
movl %r8d, %eax
movl %edx, %r8d
addb %r9b, %r8b
movl %r8d, %edx
andb $0x3f, %dl
jne 0x514e
movb %dl, 0x6(%rdi)
movzbl 0x7(%rdi), %edx
btl $0x6, %edx
sbbl $0x0, %ecx
setne %cl
andb $0x7f, %dl
shlb $0x7, %cl
orb %dl, %cl
movb %cl, 0x7(%rdi)
movl %eax, %ecx
shrl $0x10, %ecx
movw %cx, (%rdi)
movw %ax, 0x2(%rdi)
jmp 0x541e
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/eae.c
// Function: ash
static void
ash(KE11 *ke)
{
	uint32 sh;
	int ov;

	sh = ke->ac<<16 | ke->mq;
	setflag(ke, SR_NEG, sh&B31);
	ov = 0;
loop:
	ke->sc &= 077;
	if(ke->sc == 0)
		goto done;
	if(ke->sc&040){
		/* negative, shift right */
		setflag(ke, SR_C, sh&1);
		sh >>= 1;
		if(ke->sr & SR_NEG)
			sh |= B31;
		ke->sc++;
	}else{
		/* positive, shift left */
		sh <<= 1;
		setflag(ke, SR_C, sh&B31);
		if(ke->sr & SR_NEG)
			sh |= B31;
		else
			sh &= ~B31;
		if((ke->sr & SR_C) != (ke->sr>>6 & 1))
			ov = 1;	/* sign changed */
		ke->sc--;
	}
	goto loop;
done:
	setflag(ke, SR_OV, ov != (ke->sr>>6 & 1));
	ke->ac = sh>>16;
	ke->mq = sh;
	setflags(ke);
}

// Assembly:
movzwl (%rdi), %ecx
movl %ecx, %edx
shll $0x10, %edx
movzwl 0x2(%rdi), %eax
orl %edx, %eax
movb 0x6(%rdi), %r8b
movb 0x7(%rdi), %dl
andb $-0x41, %dl
shrl $0x9, %ecx
andb $0x40, %cl
orb %dl, %cl
movb %cl, 0x7(%rdi)
movl %r8d, %edx
xorl %ecx, %ecx
andb $0x3f, %dl
je 0x5290
movl $0x1, %esi
testb $0x20, %r8b
jne 0x5229
addl %eax, %eax
js 0x524e
andb $-0x2, 0x7(%rdi)
jmp 0x5252
testb $0x1, %al
jne 0x5233
andb $-0x2, 0x7(%rdi)
jmp 0x5237
orb $0x1, 0x7(%rdi)
shrl %eax
movzbl 0x7(%rdi), %r8d
andl $0x40, %r8d
shll $0x19, %r8d
orl %r8d, %eax
movb $0x1, %r9b
jmp 0x5282
orb $0x1, 0x7(%rdi)
movzbl 0x7(%rdi), %r8d
movl %eax, %r9d
orl $0x80000000, %r9d       # imm = 0x80000000
andl $0x7ffffffe, %eax       # imm = 0x7FFFFFFE
testb $0x40, %r8b
cmovnel %r9d, %eax
movl %r8d, %r9d
shrl $0x6, %r9d
xorl %r8d, %r9d
testb $0x1, %r9b
cmovnel %esi, %ecx
movb $-0x1, %r9b
movl %edx, %r8d
addb %r9b, %r8b
movl %r8d, %edx
andb $0x3f, %dl
jne 0x5219
movb %dl, 0x6(%rdi)
movzbl 0x7(%rdi), %edx
btl $0x6, %edx
sbbl $0x0, %ecx
setne %cl
andb $0x7f, %dl
shlb $0x7, %cl
orb %dl, %cl
movb %cl, 0x7(%rdi)
movl %eax, %ecx
shrl $0x10, %ecx
movw %cx, (%rdi)
movw %ax, 0x2(%rdi)
jmp 0x541e
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/eae.c
// Function: datob_ke11
int
datob_ke11(Bus *bus, void *dev)
{
	KE11 *ke = dev;
	if(bus->addr >= 0777300 && bus->addr < 0777320){
//		printf("EAE DATOB %o %o\n", bus->addr, bus->data);
		switch(bus->addr){
		case KE_DIV:
			ke->x = sxt(bus->data);
			divide(ke);
			break;
		case KE_AC:
			ke->ac = sxt(bus->data);
			break;
		case KE_AC+1:
			SETMASK(ke->ac, bus->data, 0177400);
			break;
		case KE_MQ:
			ke->mq = sxt(bus->data);
			/* sign extend into AC */
			if(ke->mq&0100000)
				ke->ac = 0177777;
			else
				ke->ac = 0;
			break;
		case KE_MQ+1:
			SETMASK(ke->mq, bus->data, 0177400);
			/* sign extend into AC */
			if(ke->mq&0100000)
				ke->ac = 0177777;
			else
				ke->ac = 0;
			break;
		case KE_MULT:
			ke->x = sxt(bus->data);
			mult(ke);
			break;
		case KE_SCSR:
			break;
		case KE_NORM:
			norm(ke);
			break;
		case KE_LSH:
			ke->sc = bus->data & 077;
			lsh(ke);
			break;
		case KE_ASH:
			ke->sc = bus->data & 077;
			ash(ke);
			break;
		case KE_DIV+1:
		case KE_MULT+1:
		case KE_SCSR+1:
		case KE_NORM+1:
		case KE_LSH+1:
		case KE_ASH+1:
			break;

		default: assert(0);	/* can't happen */
		}
		return 0;
	}
	return 1;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl 0x8(%rdi), %eax
movl %eax, %ecx
andl $-0x10, %ecx
movl $0x1, %ebx
cmpl $0x3fec0, %ecx          # imm = 0x3FEC0
jne 0x52ef
movq %rsi, %rbp
xorl %ebx, %ebx
addl $0xfffc0140, %eax       # imm = 0xFFFC0140
leaq 0x21f6(%rip), %rcx      # 0x74dc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
movb 0xc(%rdi), %al
andb $0x3f, %al
movb %al, 0x6(%rbp)
movq %rbp, %rdi
callq 0x511c
jmp 0x52ef
movzwl 0xc(%rdi), %eax
movb %ah, 0x3(%rbp)
testw %ax, %ax
js 0x5385
movw $0x0, (%rbp)
jmp 0x52ef
movzbl 0xc(%rdi), %edi
callq 0x2544
movw %ax, 0x4(%rbp)
movq %rbp, %rdi
callq 0x503e
jmp 0x52ef
movb 0xd(%rdi), %al
movb %al, 0x1(%rbp)
jmp 0x52ef
movb 0xc(%rdi), %al
andb $0x3f, %al
movb %al, 0x6(%rbp)
movq %rbp, %rdi
callq 0x51e7
jmp 0x52ef
movzbl 0xc(%rdi), %edi
callq 0x2544
movw %ax, 0x4(%rbp)
movq %rbp, %rdi
callq 0x4ed9
jmp 0x52ef
movq %rbp, %rdi
callq 0x509e
jmp 0x52ef
movzbl 0xc(%rdi), %edi
callq 0x2544
movw %ax, 0x2(%rbp)
testw %ax, %ax
jns 0x5316
movw $0xffff, (%rbp)         # imm = 0xFFFF
jmp 0x52ef
movzbl 0xc(%rdi), %edi
callq 0x2544
movw %ax, (%rbp)
jmp 0x52ef
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/eae.c
// Function: dati_ke11
int
dati_ke11(Bus *bus, void *dev)
{
	KE11 *ke = dev;
	if(bus->addr >= 0777300 && bus->addr < 0777320){
//		printf("EAE DATI %o\n", bus->addr);
		switch(bus->addr){
		case KE_DIV:
		case KE_MULT:
		case KE_LSH:
		case KE_ASH:
			bus->data = 0;
			break;
		case KE_AC:
			bus->data = ke->ac;
			break;
		case KE_MQ:
			bus->data = ke->mq;
			break;
		case KE_SCSR:
			bus->data = WD(ke->sr, ke->sc);
			break;
		case KE_NORM:
			bus->data = ke->sc & 077;
			break;

		default: assert(0);	/* can't happen */
		}
		return 0;
	}
	return 1;
}

// Assembly:
movl 0x8(%rdi), %ecx
movl %ecx, %edx
andl $-0x10, %edx
movl $0x1, %eax
cmpl $0x3fec0, %edx          # imm = 0x3FEC0
jne 0x53da
addl $0xfffc0140, %ecx       # imm = 0xFFFC0140
cmpl $0xe, %ecx
ja 0x53f5
leaq 0x2153(%rip), %rax      # 0x751c
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %eax, %eax
movw %ax, 0xc(%rdi)
xorl %eax, %eax
retq
movzwl (%rsi), %eax
jmp 0x53d4
movzwl 0x2(%rsi), %eax
jmp 0x53d4
movzbl 0x6(%rsi), %eax
andl $0x3f, %eax
jmp 0x53d4
movzwl 0x6(%rsi), %eax
jmp 0x53d4
pushq %rax
leaq 0x1fce(%rip), %rdi      # 0x73cb
leaq 0x2154(%rip), %rsi      # 0x7558
leaq 0x2170(%rip), %rcx      # 0x757b
movl $0x18c, %edx            # imm = 0x18C
callq 0x20d0
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/eae.c
// Function: setflags
static void
setflags(KE11 *ke)
{
	ke->sr &= ~(SR_AC_EQ_MQ15|SR_AC_MQ_0|SR_MQ_0|SR_AC_0|SR_AC_1);
	if(ke->ac == 0 && sgn(ke->mq)==0 ||
	   ke->ac == 0177777 && sgn(ke->mq))
		ke->sr |= SR_AC_EQ_MQ15;
	if(ke->mq == 0 && ke->ac == 0)
		ke->sr |= SR_AC_MQ_0;
	if(ke->mq == 0)
		ke->sr |= SR_MQ_0;
	if(ke->ac == 0)
		ke->sr |= SR_AC_0;
	if(ke->ac == 0177777)
		ke->sr |= SR_AC_1;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
andb $-0x3f, 0x7(%rdi)
cmpw $0x0, (%rdi)
jne 0x543a
movzwl 0x2(%rbx), %edi
callq 0x253e
testw %ax, %ax
je 0x544e
cmpw $-0x1, (%rbx)
jne 0x5452
movzwl 0x2(%rbx), %edi
callq 0x253e
testw %ax, %ax
je 0x5452
orb $0x2, 0x7(%rbx)
movzwl 0x2(%rbx), %eax
testw %ax, %ax
jne 0x546e
cmpw $0x0, (%rbx)
jne 0x5465
orb $0x4, 0x7(%rbx)
testw %ax, %ax
jne 0x546e
orb $0x8, 0x7(%rbx)
movzwl (%rbx), %eax
testl %eax, %eax
je 0x5480
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x5485
movb $0x20, %al
jmp 0x5482
movb $0x10, %al
orb %al, 0x7(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/kw11.c
// Function: dati_kw11
int
dati_kw11(Bus *bus, void *dev)
{
	KW11 *kw = dev;
	if(bus->addr == 0777546){
		bus->data = kw->lc_int_enab<<6 |
			kw->lc_clock<<7;
		return 0;
	}
	return 1;
}

// Assembly:
movl $0x1, %eax
cmpl $0x3ff66, 0x8(%rdi)     # imm = 0x3FF66
jne 0x54a9
movl (%rsi), %eax
movl 0x4(%rsi), %ecx
shll $0x6, %eax
shll $0x7, %ecx
orl %eax, %ecx
movw %cx, 0xc(%rdi)
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/kw11.c
// Function: dato_kw11
int
dato_kw11(Bus *bus, void *dev)
{
	KW11 *kw = dev;
	if(bus->addr == 0777546){
		kw->lc_int_enab = bus->data>>6 & 1;
		if((bus->data & 0200) == 0){
			kw->lc_clock = 0;
			kw->lc_int = 0;
		}
		return 0;
	}
	return 1;
}

// Assembly:
movl $0x1, %eax
cmpl $0x3ff66, 0x8(%rdi)     # imm = 0x3FF66
jne 0x54d3
movl 0xc(%rdi), %ecx
movl %ecx, %eax
shrl $0x6, %eax
andl $0x1, %eax
movl %eax, (%rsi)
xorl %eax, %eax
testb %cl, %cl
js 0x54d3
movq $0x0, 0x4(%rsi)
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/kw11.c
// Function: datob_kw11
int
datob_kw11(Bus *bus, void *dev)
{
	if(bus->addr == 0777546){
		/* ignore odd bytes */
		if(bus->addr & 1)
			return 0;
		return dato_kw11(bus, dev);
	}
	return 1;
}

// Assembly:
movl $0x1, %eax
cmpl $0x3ff66, 0x8(%rdi)     # imm = 0x3FF66
jne 0x54fd
movl 0xc(%rdi), %ecx
movl %ecx, %eax
shrl $0x6, %eax
andl $0x1, %eax
movl %eax, (%rsi)
xorl %eax, %eax
testb %cl, %cl
js 0x54fd
movq $0x0, 0x4(%rsi)
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/kw11.c
// Function: svc_kw11
int
svc_kw11(Bus *bus, void *dev)
{
	KW11 *kw = dev;
	if(handleclock(&kw->clock)){
		kw->lc_clock = 1;
		kw->lc_int = 1;
	}
	return kw->lc_int && kw->lc_int_enab ? 6 : 0;
}

// Assembly:
pushq %rbx
movq %rsi, %rbx
leaq 0x10(%rsi), %rdi
callq 0x66de
testl %eax, %eax
je 0x551d
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x4(%rbx)
cmpl $0x0, 0x8(%rbx)
je 0x5531
movl (%rbx), %ecx
testl %ecx, %ecx
movl $0x6, %eax
cmovel %ecx, %eax
jmp 0x5533
xorl %eax, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/kl11.c
// Function: dati_kl11
int
dati_kl11(Bus *bus, void *dev)
{
	KL11 *kl = dev;
	if(bus->addr >= 0777560 && bus->addr < 0777570){
		switch(bus->addr&6){
		/* Receive */
		case 0:
			bus->data = kl->rdr_int_enab<<6 |
				kl->rdr_done<<7 |
				kl->rdr_busy<<11;
			break;
		case 2:
			bus->data = kl->rdr_buf;
			kl->rdr_buf = 0;
			kl->rdr_done = 0;
			break;
		/* Transmit */
		case 4:
			bus->data = kl->maint<<2 |
				kl->pun_int_enab<<6 |
				kl->pun_ready<<7;
			break;
		case 6:
			/* write only */
			bus->data = 0;
			break;
		default: assert(0);	/* can't happen */
		}
		return 0;
	}
	return 1;
}

// Assembly:
movl 0x8(%rdi), %ecx
movl %ecx, %edx
andl $-0x8, %edx
movl $0x1, %eax
cmpl $0x3ff70, %edx          # imm = 0x3FF70
jne 0x55dc
andl $0x6, %ecx
leaq 0x2019(%rip), %rax      # 0x7598
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl 0x4(%rsi), %eax
movl 0x8(%rsi), %ecx
shll $0x6, %eax
movl 0x10(%rsi), %edx
shll $0x7, %edx
orl %eax, %edx
shll $0xb, %ecx
orl %edx, %ecx
movw %cx, 0xc(%rdi)
jmp 0x55da
movw $0x0, 0xc(%rdi)
jmp 0x55da
movzbl 0x14(%rsi), %eax
movw %ax, 0xc(%rdi)
movb $0x0, 0x14(%rsi)
movl $0x0, 0x10(%rsi)
jmp 0x55da
movl (%rsi), %eax
movl 0x18(%rsi), %ecx
shll $0x2, %eax
shll $0x6, %ecx
orl %eax, %ecx
movl 0x1c(%rsi), %eax
shll $0x7, %eax
orl %ecx, %eax
movw %ax, 0xc(%rdi)
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/kl11.c
// Function: dato_kl11
int
dato_kl11(Bus *bus, void *dev)
{
	KL11 *kl = dev;
	if(bus->addr >= 0777560 && bus->addr < 0777570){
		switch(bus->addr&7){
		/* Receive */
		case 0:
			// TODO: RDR ENAB
			kl->rdr_enab = bus->data & 1;
			kl->rdr_int_enab = bus->data>>6 & 1;
			if(!kl->rdr_int_enab)
				kl->intr_flags &= ~2;
			else if(kl->rdr_done)
				kl->intr_flags |= 2;
			break;
		case 2:
			/* read only */
			break;
		/* Transmit */
		case 4:
			// TODO: MAINT
			kl->maint = bus->data>>2 & 1;
			kl->pun_int_enab = bus->data>>6 & 1;
			if(!kl->pun_int_enab)
				kl->intr_flags &= ~1;
			else if(kl->pun_ready)
				kl->intr_flags |= 1;
			break;
		case 6:
			kl->pun_buf = bus->data;
			kl->pun_halt = 0;
			kl->pun_ready = 0;
			break;

		/* respond but don't do anything */
		case 1:
		case 3:
		case 5:
		case 7:
			break;
		default: assert(0);	/* can't happen */
		}
		return 0;
	}
	return 1;
}

// Assembly:
movl 0x8(%rdi), %ecx
movl %ecx, %edx
andl $-0x8, %edx
movl $0x1, %eax
cmpl $0x3ff70, %edx          # imm = 0x3FF70
jne 0x5607
andl $0x7, %ecx
xorl %eax, %eax
leaq 0x1fb6(%rip), %rdx      # 0x75b4
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
retq
movb 0xc(%rdi), %cl
movb %cl, 0x24(%rsi)
movq $0x0, 0x1c(%rsi)
retq
movzwl 0xc(%rdi), %ecx
movl %ecx, %edx
andl $0x1, %edx
movl %edx, 0xc(%rsi)
shrl $0x6, %ecx
andl $0x1, %ecx
movl %ecx, 0x4(%rsi)
je 0x565d
cmpl $0x0, 0x10(%rsi)
je 0x5607
orb $0x2, 0x28(%rsi)
retq
movzwl 0xc(%rdi), %ecx
movl %ecx, %edx
shrl $0x2, %edx
andl $0x1, %edx
movl %edx, (%rsi)
shrl $0x6, %ecx
andl $0x1, %ecx
movl %ecx, 0x18(%rsi)
je 0x5662
cmpl $0x0, 0x1c(%rsi)
je 0x5607
orb $0x1, 0x28(%rsi)
retq
andb $-0x3, 0x28(%rsi)
retq
andb $-0x2, 0x28(%rsi)
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/kl11.c
// Function: svc_kl11
int
svc_kl11(Bus *bus, void *dev)
{
	char c;
	KL11 *kl = dev;

	NNN++;
//	if(NNN == 20){
	if(NNN == 20000){
	/* transmit */
	if(!kl->pun_halt){
		uint8 c = kl->pun_buf & 0177;
		write(kl->tty.fd, &c, 1);
#ifdef AUTODIAG
	extern int diagpassed;
	if(c == '\a')
		diagpassed = 1;
#endif
		kl->pun_halt = 1;
		kl->pun_ready = 1;
		if(kl->pun_int_enab)
			kl->intr_flags |= 1;
	}

	/* receive */
	if(ttyinput(&kl->tty, &c)){
		kl->rdr_busy = 1;
		kl->rdr_enab = 0;
		kl->rdr_buf = c;
		kl->rdr_busy = 0;
		kl->rdr_done = 1;
		if(kl->rdr_int_enab)
			kl->intr_flags |= 2;
	}
	NNN = 0;
	}

	return kl->intr_flags ? 4 : 0;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movl 0xe652(%rip), %eax      # 0x13ccc
incl %eax
movl %eax, 0xe64a(%rip)      # 0x13ccc
cmpl $0x4e20, %eax           # imm = 0x4E20
jne 0x5703
cmpl $0x0, 0x20(%rbx)
jne 0x56c0
movb 0x24(%rbx), %al
andb $0x7f, %al
leaq 0xf(%rsp), %rsi
movb %al, (%rsi)
movl 0x2c(%rbx), %edi
movl $0x1, %edx
callq 0x2080
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x1c(%rbx)
cmpl $0x0, 0x18(%rbx)
je 0x56c0
orb $0x1, 0x28(%rbx)
leaq 0x2c(%rbx), %rdi
leaq 0xe(%rsp), %rsi
callq 0x6771
testl %eax, %eax
je 0x56f9
movq $0x1, 0x8(%rbx)
movb 0xe(%rsp), %al
movb %al, 0x14(%rbx)
movl $0x0, 0x8(%rbx)
movl $0x1, 0x10(%rbx)
cmpl $0x0, 0x4(%rbx)
je 0x56f9
orb $0x2, 0x28(%rbx)
movl $0x0, 0xe5c9(%rip)      # 0x13ccc
xorl %eax, %eax
cmpl $0x0, 0x28(%rbx)
setne %al
shll $0x2, %eax
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rf11.c
// Function: dati_rf11
int
dati_rf11(Bus *bus, void *dev)
{
	RF11 *rf = dev;
	rf->bus = bus;
	if(bus->addr >= 0777460 && bus->addr < 0777500){
		switch(bus->addr&016){
		case 000: bus->data = rf->dcs; break;
		case 002: bus->data = rf->wc; break;
		case 004: bus->data = rf->cma; break;
		case 006: bus->data = rf->dar; break;
		case 010: bus->data = rf->dae; break;
		case 012: bus->data = rf->dbr; break;
		case 014: bus->data = rf->ma; break;
		case 016: bus->data = rf->drives[rf->d].ads; break;
		default: assert(0);	/* can't happen */
		}
		return 0;
	}
	return 1;
}

// Assembly:
movq %rdi, (%rsi)
movl 0x8(%rdi), %ecx
movl %ecx, %edx
andl $-0x10, %edx
movl $0x1, %eax
cmpl $0x3ff30, %edx          # imm = 0x3FF30
jne 0x57fd
andl $0xe, %ecx
leaq 0x1e3e(%rip), %rax      # 0x75f0
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
addq $0x8, %rsi
jmp 0x57f4
addq $0xe, %rsi
jmp 0x57f4
movslq 0x1c(%rsi), %rax
shlq $0x4, %rax
addq %rax, %rsi
addq $0x28, %rsi
jmp 0x57f4
addq $0xc, %rsi
jmp 0x57f4
addq $0xa, %rsi
jmp 0x57f4
addq $0x12, %rsi
jmp 0x57f4
addq $0x14, %rsi
jmp 0x57f4
addq $0x10, %rsi
movzwl (%rsi), %eax
movw %ax, 0xc(%rdi)
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rf11.c
// Function: datox_rf11
static int
datox_rf11(Bus *bus, RF11 *rf, word mask)
{
	rf->bus = bus;
	RS11 *drive = &rf->drives[rf->d];
	if(bus->addr >= 0777460 && bus->addr < 0777500){
		switch(bus->addr&017){
		case 000:	// DCS
		case 001:
			SETMASK(rf->dcs, bus->data, mask&0176);
			if(bus->data & GO){
				// start function
				rf->done = 0;
				switch((rf->dcs>>1)&3){
				case FR_NOP:
					rf->dcs |= RDY;
					// ??? interrupt?
					break;
				case FR_READ:
				case FR_WRITE:
				case FR_WRITE_CHECK:
					rf->dcs &= ~RDY;
					if(drive->fp == nil)
						rferr(rf, NED);
					break;
				}
			}
			if(bus->data & DCLR)
				reset_rf11(rf);
			break;
		case 002:	// WC
		case 003:
			SETMASK(rf->wc, bus->data, mask);
			break;
		case 004:	// CMA
		case 005:
			SETMASK(rf->cma, bus->data, mask);
			break;
		case 006:	// DAR
		case 007:
			SETMASK(rf->dar, bus->data, mask);
			break;
		case 010:	// DAE
		case 011:
			SETMASK(rf->dae, bus->data, mask&0637);
			rf->dae &= ~DA14;
			seldisk(rf, (rf->dae>>2)&7);
			break;
		case 012:	// DBR
		case 013:
			SETMASK(rf->dbr, bus->data, mask);
			break;
		case 014:	// MA
		case 015:
			// not implemented
			break;
		case 016:	// ADS
		case 017:
			// read only
			break;
		default: assert(0);	/* can't happen */
		}
		return 0;
	}
	return 1;
}

// Assembly:
pushq %rbx
movq %rdi, (%rsi)
movl 0x8(%rdi), %eax
movl %eax, %ecx
andl $-0x10, %ecx
movl $0x1, %ebx
cmpl $0x3ff30, %ecx          # imm = 0x3FF30
jne 0x5943
andl $0xf, %eax
xorl %ebx, %ebx
leaq 0x1dfe(%rip), %rcx      # 0x762c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movslq 0x1c(%rsi), %r8
movzwl 0x8(%rsi), %r9d
movzwl 0xc(%rdi), %eax
movl %eax, %ecx
xorl %r9d, %ecx
andl %edx, %ecx
andl $0x7e, %ecx
xorl %r9d, %ecx
movw %cx, 0x8(%rsi)
testb $0x1, %al
je 0x5935
movl $0x0, 0x18(%rsi)
testb $0x6, %cl
je 0x592b
shlq $0x4, %r8
leaq (%rsi,%r8), %rdx
addq $0x20, %rdx
movl %ecx, %edi
andl $0xff7f, %edi           # imm = 0xFF7F
movw %di, 0x8(%rsi)
cmpq $0x0, (%rdx)
jne 0x5935
orl $0x880, %ecx            # imm = 0x880
movw %cx, 0x8(%rsi)
movl $0x1, 0x18(%rsi)
jmp 0x5935
movzwl 0xc(%rsi), %eax
movzwl 0xc(%rdi), %ecx
xorw %ax, %cx
andl %edx, %ecx
xorl %ecx, %eax
movw %ax, 0xc(%rsi)
jmp 0x5943
movzwl 0xa(%rsi), %eax
movzwl 0xc(%rdi), %ecx
xorw %ax, %cx
andl %edx, %ecx
xorl %ecx, %eax
movw %ax, 0xa(%rsi)
jmp 0x5943
movzwl 0x12(%rsi), %eax
movzwl 0xc(%rdi), %ecx
xorw %ax, %cx
andl %edx, %ecx
xorl %ecx, %eax
movw %ax, 0x12(%rsi)
jmp 0x5943
movzwl 0xe(%rsi), %eax
movzwl 0xc(%rdi), %ecx
xorw %ax, %cx
andl %edx, %ecx
xorl %ecx, %eax
movw %ax, 0xe(%rsi)
jmp 0x5943
andl $0x19f, %edx            # imm = 0x19F
movzwl 0xc(%rdi), %eax
andw %dx, %ax
xorl $0xffdf, %edx           # imm = 0xFFDF
andw 0x10(%rsi), %dx
orl %eax, %edx
movw %dx, 0x10(%rsi)
shrl $0x2, %edx
andl $0x7, %edx
movq %rsi, %rdi
movl %edx, %esi
callq 0x5b6c
jmp 0x5943
orl $0x80, %ecx
movw %cx, 0x8(%rsi)
btl $0x8, %eax
jae 0x5943
movq %rsi, %rdi
callq 0x5b36
movl %ebx, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rf11.c
// Function: svc_rf11
int
svc_rf11(Bus *bus, void *dev)
{
	int i;
	RF11 *rf = dev;

	for(i = 0; i < 8; i++)
		svc_rs11(&rf->drives[i], rf, rf->d == i);

	if(rf->dcs&(FRZ|WCE|DPE|NED|WLO|MXF))
		rf->dcs |= ERR;
	else
		rf->dcs &= ~ERR;

	return (rf->dcs&IE) &&
// TODO: probably just have one interrupt bit?
	       (rf->done || (rf->dcs&ERR)) ?
		5 : 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
leaq 0x20(%rsi), %r14
xorl %r15d, %r15d
movl 0x1c(%rbx), %eax
xorl %edx, %edx
cmpq %rax, %r15
sete %dl
movq %r14, %rdi
movq %rbx, %rsi
callq 0x59d6
incq %r15
addq $0x10, %r14
cmpq $0x8, %r15
jne 0x596c
movzwl 0x8(%rbx), %ecx
movl %ecx, %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl %ecx, %edx
orl $0xffff8000, %edx       # imm = 0xFFFF8000
testl $0x7e00, %ecx           # imm = 0x7E00
cmovel %eax, %edx
movw %dx, 0x8(%rbx)
xorl %eax, %eax
testb $0x40, %dl
je 0x59d0
xorl %eax, %eax
testl $0x7e00, %ecx           # imm = 0x7E00
setne %al
cmpl $0x0, 0x18(%rbx)
leal (%rax,%rax,4), %ecx
movl $0x5, %eax
cmovel %ecx, %eax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rf11.c
// Function: svc_rs11
void
svc_rs11(RS11 *drive, RF11 *rf, int selected)
{
	if(drive->fp == nil){
		drive->ads = 0;
		return;
	}

	// read/write data
	if(selected && (rf->dcs&RDY)==0){
		// track address we want
		seltrack(rf, (rf->dar>>11) | (rf->dae&3)<<5);

		// word we're interested in
		if(rf->wc && drive->ads == (rf->dar&03777)){
			// read/write word here
			switch((rf->dcs>>1)&3){
			case FR_READ:
				rf->dbr = WD(rf->buf[drive->ads*2+1], rf->buf[drive->ads*2]);

				// write to bus
				rf->bus->data = rf->dbr;
				rf->bus->addr = busaddr(rf);
				if(dato_bus(rf->bus))
					rferr(rf, NEM);
				break;
			case FR_WRITE:
			case FR_WRITE_CHECK:
				// read from bus
				rf->bus->addr = busaddr(rf);
				if(dati_bus(rf->bus))
					rferr(rf, NEM);
				rf->dbr = rf->bus->data;

				rf->buf[drive->ads*2] = rf->dbr;
				rf->buf[drive->ads*2+1] = rf->dbr>>8;
				rf->dirty = 1;
				break;
			}

			rf->wc++;
			if(rf->wc == 0){
				rf->dcs |= RDY;
				rf->done = 1;
			}else{
				// count
				rf->dar++;
				if(rf->dar == 0){
					// carry into dae
					rf->dae++;
					// this can carry into disk address
					seldisk(rf, (rf->dae>>2)&017);
				}
			}
		}
	}

	// rotate - one word every 16us
	// address of next word on track
	drive->ads = (drive->ads+1)&03777;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpq $0x0, (%rdi)
je 0x5a9d
testl %edx, %edx
je 0x5b14
movq %rsi, %rbp
testb $-0x80, 0x8(%rsi)
jne 0x5b14
movzwl 0xe(%rbp), %eax
shrl $0xb, %eax
movl 0x10(%rbp), %esi
shll $0x5, %esi
andl $0x60, %esi
orl %eax, %esi
movq %rbp, %rdi
callq 0x5c64
cmpw $0x0, 0xa(%rbp)
je 0x5b14
movzwl 0x8(%rbx), %eax
movzwl 0xe(%rbp), %ecx
andl $0x7ff, %ecx            # imm = 0x7FF
cmpw %cx, %ax
jne 0x5b14
movl 0x8(%rbp), %ecx
shrl %ecx
andl $0x3, %ecx
leaq 0x1c26(%rip), %rdx      # 0x766c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq %rbp, %rdi
callq 0x5d1f
movq (%rbp), %rdi
movl %eax, 0x8(%rdi)
callq 0x2492
testl %eax, %eax
je 0x5a74
orw $0x480, 0x8(%rbp)       # imm = 0x480
movl $0x1, 0x18(%rbp)
movq (%rbp), %rax
movzwl 0xc(%rax), %eax
movw %ax, 0x12(%rbp)
movzwl 0x8(%rbx), %ecx
movb %al, 0xa8(%rbp,%rcx,2)
movzwl 0x8(%rbx), %ecx
movb %ah, 0xa9(%rbp,%rcx,2)
movl $0xa0, %eax
jmp 0x5adc
movw $0x0, 0x8(%rbx)
jmp 0x5b22
movzwl 0xa8(%rbp,%rax,2), %eax
movw %ax, 0x12(%rbp)
movq (%rbp), %rcx
movw %ax, 0xc(%rcx)
movq %rbp, %rdi
callq 0x5d1f
movq (%rbp), %rdi
movl %eax, 0x8(%rdi)
callq 0x24c4
testl %eax, %eax
je 0x5ae4
orw $0x480, 0x8(%rbp)       # imm = 0x480
movl $0x18, %eax
movl $0x1, (%rbp,%rax)
incw 0xa(%rbp)
jne 0x5af7
orb $-0x80, 0x8(%rbp)
movl $0x1, 0x18(%rbp)
jmp 0x5b14
incw 0xe(%rbp)
jne 0x5b14
movl 0x10(%rbp), %esi
incl %esi
movw %si, 0x10(%rbp)
shrl $0x2, %esi
andl $0xf, %esi
movq %rbp, %rdi
callq 0x5b6c
movl 0x8(%rbx), %eax
incl %eax
andl $0x7ff, %eax            # imm = 0x7FF
movw %ax, 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rf11.c
// Function: reset_rf11
void
reset_rf11(void *dev)
{
	RF11 *rf = dev;
	rf->dcs = RDY;
	rf->wc = 0;
	rf->cma = 0;
	rf->dar = 0;
	rf->dae = 0;
	seldisk(rf, 0);
	rf->dbr = 0;
	rf->ma = 0;

	rf->done = 0;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movw $0x80, 0x8(%rdi)
movq $0x0, 0xa(%rdi)
cmpl $0x0, 0x1c(%rdi)
je 0x5b62
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5c64
movl $0x0, 0x1c(%rbx)
xorl %eax, %eax
movl %eax, 0x12(%rbx)
movl %eax, 0x18(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rf11.c
// Function: seldisk
static void
seldisk(RF11 *rf, int disk)
{
	if(rf->d == disk)
		return;
	seltrack(rf, -1);
	rf->d = disk&7;
	if(disk&010)
		rferr(rf, NED);
}

// Assembly:
cmpl %esi, 0x1c(%rdi)
je 0x5ba4
pushq %rbp
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5c64
movl %ebp, %eax
andl $0x7, %eax
movl %eax, 0x1c(%rbx)
testb $0x8, %bpl
je 0x5b9e
orw $0x880, 0x8(%rbx)       # imm = 0x880
movl $0x1, 0x18(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rf11.c
// Function: attach_rs11
void
attach_rs11(RF11 *rf, int n, char *path)
{
	if(rf->drives[n].fp)
		detach_rs11(rf, n);
	rf->drives[n].fp = fopen(path, "r+");
	if(rf->drives[n].fp == nil)
		rf->drives[n].fp = fopen(path, "w+");
	if(rf->drives[n].fp == nil)
		fprintf(stderr, "couldn't open '%s'\n", path);
	reset_rs11(&rf->drives[n]);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movslq %esi, %rax
shlq $0x4, %rax
leaq (%rdi,%rax), %r14
addq $0x20, %r14
movq (%r14), %rdi
testq %rdi, %rdi
je 0x5bd6
callq 0x2090
movq $0x0, (%r14)
movw $0x0, 0x8(%r14)
leaq 0x1aa6(%rip), %rsi      # 0x7683
movq %rbx, %rdi
callq 0x21b0
movq %rax, (%r14)
testq %rax, %rax
jne 0x5bff
leaq 0x1a92(%rip), %rsi      # 0x7686
movq %rbx, %rdi
callq 0x21b0
movq %rax, (%r14)
cmpq $0x0, (%r14)
je 0x5c14
movw $0x0, 0x8(%r14)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq 0x43dd(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x1a64(%rip), %rsi      # 0x7689
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2120
jmp 0x5c05
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rf11.c
// Function: detach_rs11
void
detach_rs11(RF11 *rf, int n)
{
	if(rf->drives[n].fp){
		fclose(rf->drives[n].fp);
		rf->drives[n].fp = nil;
	}
	reset_rs11(&rf->drives[n]);
}

// Assembly:
pushq %rbx
movslq %esi, %rax
shlq $0x4, %rax
leaq (%rdi,%rax), %rbx
addq $0x20, %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x5c55
callq 0x2090
movq $0x0, (%rbx)
movw $0x0, 0x8(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rf11.c
// Function: seltrack
static void
seltrack(RF11 *rf, int track)
{
	if(rf->track == track)
		return;

	RS11 *drive = &rf->drives[rf->d];
	if(rf->dirty){
		assert(drive->fp);
		fwrite(rf->buf, 1, 2048*2, drive->fp);
	}
	rf->track = track;

	if(rf->track >= 0){
		int pos = rf->track<<12;
		fseek(drive->fp, pos, 0);
		fread(rf->buf, 1, 2048*2, drive->fp);
		// rewind so we can write back easily
		fseek(drive->fp, pos, 0);
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
cmpl %esi, 0xa4(%rdi)
je 0x5cfa
movl %esi, %ebx
movq %rdi, %r14
movslq 0x1c(%rdi), %rax
shlq $0x4, %rax
leaq (%rdi,%rax), %r15
addq $0x20, %r15
cmpl $0x0, 0xa0(%rdi)
je 0x5cb1
movq (%r15), %rcx
testq %rcx, %rcx
je 0x5d00
leaq 0xa8(%r14), %rdi
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x2200
movl %ebx, 0xa4(%r14)
testl %ebx, %ebx
js 0x5cfa
shll $0xc, %ebx
movq (%r15), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x2170
addq $0xa8, %r14
movq (%r15), %rcx
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
callq 0x2050
movq (%r15), %rdi
movq %rbx, %rsi
xorl %edx, %edx
popq %rbx
popq %r14
popq %r15
jmp 0x2170
popq %rbx
popq %r14
popq %r15
retq
leaq 0x1996(%rip), %rdi      # 0x769d
leaq 0x196e(%rip), %rsi      # 0x767c
leaq 0x1992(%rip), %rcx      # 0x76a7
movl $0x40, %edx
callq 0x20d0
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rf11.c
// Function: busaddr
static int
busaddr(RF11 *rf)
{
	int addr = rf->cma | (rf->dcs&060)<<12;
	if((rf->dae & CMA_INH)==0){
		rf->cma += 2;
		if(rf->cma == 0)
			SETMASK(rf->dcs, rf->dcs+020, 060);
	}
	return addr;
}

// Assembly:
movzwl 0xc(%rdi), %ecx
movzwl 0x8(%rdi), %eax
testb $0x1, 0x11(%rdi)
jne 0x5d4a
movl %ecx, %edx
addw $0x2, %dx
movw %dx, 0xc(%rdi)
jne 0x5d4a
movl %eax, %edx
andl $-0x31, %edx
leal 0x10(%rax), %esi
andl $0x30, %esi
orl %edx, %esi
movw %si, 0x8(%rdi)
andl $0x30, %eax
shll $0xc, %eax
orl %ecx, %eax
retq
nop
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rk11.c
// Function: dati_rk11
int
dati_rk11(Bus *bus, void *dev)
{
	RK11 *rk = dev;
	rk->bus = bus;
	if(bus->addr >= 0777400 && bus->addr < 0777420){
		switch(bus->addr&016){
		case 000: bus->data = rk->rkds | rk->drives[rk->d].rkds; break;
		case 002: bus->data = rk->rker; break;
		case 004: bus->data = rk->rkcs; break;
		case 006: bus->data = rk->rkwc; break;
		case 010: bus->data = rk->rkba; break;
		case 012: bus->data = rk->rkda; break;
		case 014: bus->data = rk->rkmr; break;
		case 016: bus->data = rk->rkdb; break;
		default: assert(0);	/* can't happen */
		}
		return 0;
	}
	return 1;
}

// Assembly:
movq %rdi, (%rsi)
movl 0x8(%rdi), %ecx
movl %ecx, %edx
andl $-0x10, %edx
movl $0x1, %eax
cmpl $0x3ff00, %edx          # imm = 0x3FF00
jne 0x5dc4
andl $0xe, %ecx
leaq 0x194e(%rip), %rax      # 0x76c4
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movslq 0x20(%rsi), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movzwl 0x34(%rsi,%rax), %eax
orw 0x8(%rsi), %ax
jmp 0x5dbe
movzwl 0xe(%rsi), %eax
jmp 0x5dbe
movzwl 0x16(%rsi), %eax
jmp 0x5dbe
movzwl 0xc(%rsi), %eax
jmp 0x5dbe
movzwl 0xa(%rsi), %eax
jmp 0x5dbe
movzwl 0x12(%rsi), %eax
jmp 0x5dbe
movzwl 0x14(%rsi), %eax
jmp 0x5dbe
movzwl 0x10(%rsi), %eax
movw %ax, 0xc(%rdi)
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rk11.c
// Function: datox_rk11
static int
datox_rk11(Bus *bus, RK11 *rk, word mask)
{
	rk->bus = bus;
	if(bus->addr >= 0777400 && bus->addr < 0777420){
		switch(bus->addr&017){
		case 000:	// RKDS
		case 001:
		case 002:	// RKER
		case 003:
			break;	// read only

		case 004:	// RKCS
		case 005:
			SETMASK(rk->rkcs, bus->data, mask&0017577);
			break;
		case 006:	// RKWC
		case 007:
			SETMASK(rk->rkwc, bus->data, mask);
			break;
		case 010:	// RKBA
		case 011:
			SETMASK(rk->rkba, bus->data, mask);
			break;
		case 012:	// RKDA
		case 013:
			if(rk->rkcs & RDY){
				SETMASK(rk->rkda, bus->data, mask);
				rk->d = (rk->rkda>>13) & 7;
			}else if((rk->rkcs & GO)==0)
				rk->done = 1;
			break;
		case 014:	// RKMR
		case 015:
			// not implemented
			break;
		case 016:	// RKDB
		case 017:
			// read only
			break;
		default: assert(0);	/* can't happen */
		}
		return 0;
	}
	return 1;
}

// Assembly:
movq %rdi, (%rsi)
movl 0x8(%rdi), %ecx
movl %ecx, %r8d
andl $-0x10, %r8d
movl $0x1, %eax
cmpl $0x3ff00, %r8d          # imm = 0x3FF00
jne 0x5dfc
andl $0xf, %ecx
xorl %eax, %eax
leaq 0x190d(%rip), %r8       # 0x7700
movslq (%r8,%rcx,4), %rcx
addq %r8, %rcx
jmpq *%rcx
retq
movzwl 0xc(%rsi), %ecx
movzwl 0xc(%rdi), %edi
xorw %cx, %di
andl %edx, %edi
andl $0x1f7f, %edi           # imm = 0x1F7F
xorl %edi, %ecx
movw %cx, 0xc(%rsi)
retq
movzwl 0xc(%rsi), %ecx
testb %cl, %cl
js 0x5e54
testb $0x1, %cl
jne 0x5dfc
movl $0x1, 0x1c(%rsi)
retq
movzwl 0xe(%rsi), %ecx
movzwl 0xc(%rdi), %edi
xorw %cx, %di
andl %edx, %edi
xorl %edi, %ecx
movw %cx, 0xe(%rsi)
retq
movzwl 0x10(%rsi), %ecx
movzwl 0xc(%rdi), %edi
xorw %cx, %di
andl %edx, %edi
xorl %edi, %ecx
movw %cx, 0x10(%rsi)
retq
movzwl 0x12(%rsi), %ecx
movzwl 0xc(%rdi), %edi
xorw %cx, %di
andl %edx, %edi
xorl %edi, %ecx
movzwl %cx, %ecx
movw %cx, 0x12(%rsi)
shrl $0xd, %ecx
movl %ecx, 0x20(%rsi)
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rk11.c
// Function: start_rk11
void
start_rk11(RK05 *drive, RK11 *rk)
{
	drive->func = (rk->rkcs>>1) & 7;
	rk->rkcs &= ~SCP;
	rk->done = 0;


	switch(drive->func){
	case FR_CTL_RESET:
		reset_rk11(rk);
		break;
	case FR_WRITE:
	case FR_READ:
	case FR_WRITE_CHECK:
	case FR_READ_CHECK:
		rk->rkcs &= ~RDY;
		if(drive->fp == nil)
			rkerr(drive, rk, NXD);
		if((rk->rkda&017) >= 12)
			rkerr(drive, rk, NXS);
		if(((rk->rkda>>5)&0377) >= 0312)
			rkerr(drive, rk, NXC);
		if(drive->rkds & WPS &&
		   (drive->func == FR_WRITE || drive->func == FR_WRITE_CHECK))
			rkerr(drive, rk, WLO);
		else
			drive->newcyl = (rk->rkda>>5)&0377;
		break;
	case FR_SEEK:
		drive->newcyl = (rk->rkda>>5)&0377;
		break;
	case FR_DRIVE_RESET:
		reset_rk05(&rk->drives[rk->d]);
		break;
	case FR_WRITE_LOCK:
		drive->rkds |= WPS;
		drive->func = 0;
		break;
	}
}

// Assembly:
movzwl 0xc(%rsi), %eax
movl %eax, %ecx
shrl %ecx
andl $0x7, %ecx
movl %ecx, 0x10(%rdi)
movl %eax, %edx
andl $0xdfff, %edx           # imm = 0xDFFF
movw %dx, 0xc(%rsi)
movl $0x0, 0x1c(%rsi)
leaq 0x1891(%rip), %rdx      # 0x7740
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
andl $0xdf7f, %eax           # imm = 0xDF7F
movw %ax, 0xc(%rsi)
cmpq $0x0, (%rdi)
jne 0x5eef
movzwl 0xa(%rsi), %ecx
movl %ecx, %edx
orl $0x80, %edx
movw %dx, 0xa(%rsi)
testl $0xb64c, %ecx           # imm = 0xB64C
je 0x5eef
orl $0x80, %eax
movw %ax, 0xc(%rsi)
movl $0x0, 0x10(%rdi)
movzwl 0x12(%rsi), %eax
movl %eax, %ecx
notl %ecx
testb $0xc, %cl
jne 0x5f1c
movzwl 0xa(%rsi), %ecx
movl %ecx, %edx
orl $0x20, %edx
movw %dx, 0xa(%rsi)
testl $0xb64c, %ecx           # imm = 0xB64C
je 0x5f1c
orb $-0x80, 0xc(%rsi)
movl $0x0, 0x10(%rdi)
movl %eax, %ecx
andl $0x1fc0, %ecx           # imm = 0x1FC0
cmpl $0x1921, %ecx           # imm = 0x1921
jb 0x5f3b
orb $0x40, 0xa(%rsi)
orb $-0x80, 0xc(%rsi)
movl $0x0, 0x10(%rdi)
testb $0x20, 0xc(%rdi)
je 0x5fb0
movl 0x10(%rdi), %ecx
orl $0x2, %ecx
cmpl $0x3, %ecx
jne 0x5fb0
orb $0x20, 0xb(%rsi)
orb $-0x80, 0xc(%rsi)
jmp 0x5fa4
movl $0x0, 0x8(%rsi)
movw $0x80, 0xc(%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0xe(%rsi)
movq $0x0, 0x1c(%rsi)
xorl %eax, %eax
movw $0x800, 0x34(%rsi,%rax) # imm = 0x800
movq $0x0, 0x38(%rsi,%rax)
movl $0x0, 0x48(%rsi,%rax)
movw $0x0, 0x54(%rsi,%rax)
addq $0x30, %rax
cmpq $0x180, %rax            # imm = 0x180
jne 0x5f74
retq
orb $0x20, 0xc(%rdi)
movl $0x0, 0x10(%rdi)
retq
movzwl 0x12(%rsi), %eax
shrl $0x5, %eax
movzbl %al, %eax
movl %eax, 0x20(%rdi)
retq
movslq 0x20(%rsi), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movw $0x800, 0x34(%rsi,%rax) # imm = 0x800
movq $0x0, 0x38(%rsi,%rax)
movl $0x0, 0x48(%rsi,%rax)
movw $0x0, 0x54(%rsi,%rax)
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rk11.c
// Function: svc_rk11
int
svc_rk11(Bus *bus, void *dev)
{
	int i;
	RK11 *rk = dev;

	if((rk->rkcs & RDY) && (rk->rkcs & GO)){
		rk->rkcs &= ~GO;
		start_rk11(&rk->drives[rk->d], rk);
	}
	for(i = 0; i < 8; i++)
		svc_rk05(&rk->drives[i], rk, rk->d == i);

	if(rk->rker & 177740)
		rk->rkcs |= HE;
	else
		rk->rkcs &= ~HE;
	if(rk->rker)
		rk->rkcs |= ERR;
	else
		rk->rkcs &= ~ERR;

	return (rk->rkcs&IDE) &&
// TODO: probably just have one interrupt bit?
	       (rk->done || (rk->rkcs&HE) || (rk->rkcs&ERR) && (rk->rkcs&SSE)) ?
		5 : 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movl 0xc(%rsi), %eax
movl %eax, %ecx
notl %ecx
testb $-0x7f, %cl
jne 0x6085
andl $0xfffe, %eax           # imm = 0xFFFE
movw %ax, 0xc(%rbx)
movslq 0x20(%rbx), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0x28, %rdi
movq %rbx, %rsi
callq 0x5e87
leaq 0x28(%rbx), %r14
xorl %r15d, %r15d
movl 0x20(%rbx), %eax
xorl %edx, %edx
cmpq %rax, %r15
sete %dl
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6115
incq %r15
addq $0x30, %r14
cmpq $0x8, %r15
jne 0x608c
movzwl 0xa(%rbx), %ecx
xorl %edx, %edx
testw %cx, %cx
setne %dl
xorl %eax, %eax
testl $0xb64c, %ecx           # imm = 0xB64C
setne %al
movzwl 0xc(%rbx), %esi
andl $0x3fff, %esi           # imm = 0x3FFF
shll $0xe, %eax
orl %esi, %eax
shll $0xf, %edx
orl %eax, %edx
movw %dx, 0xc(%rbx)
xorl %eax, %eax
testb $0x40, %dl
je 0x610f
movzwl %dx, %edx
movl %edx, %esi
andl $0x4000, %esi           # imm = 0x4000
xorl %eax, %eax
orl 0x1c(%rbx), %esi
setne %al
leal (%rax,%rax,4), %eax
testw %cx, %cx
je 0x610f
testl %esi, %esi
jne 0x610f
shll $0x17, %edx
sarl $0x1f, %edx
andl $0x5, %edx
movl %edx, %eax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/rk11.c
// Function: attach_rk05
void
attach_rk05(RK11 *rk, int n, char *path)
{
	if(rk->drives[n].fp)
		detach_rk05(rk, n);
	rk->drives[n].fp = fopen(path, "r+");
	if(rk->drives[n].fp == nil)
		rk->drives[n].fp = fopen(path, "w+");
	if(rk->drives[n].fp == nil)
		fprintf(stderr, "couldn't open '%s'\n", path);
	reset_rk05(&rk->drives[n]);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movslq %esi, %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq (%rdi,%rax), %r14
addq $0x28, %r14
cmpq $0x0, (%r14)
je 0x6464
callq 0x64d6
leaq 0x1218(%rip), %rsi      # 0x7683
movq %rbx, %rdi
callq 0x21b0
movq %rax, (%r14)
testq %rax, %rax
jne 0x648d
leaq 0x1204(%rip), %rsi      # 0x7686
movq %rbx, %rdi
callq 0x21b0
movq %rax, (%r14)
cmpq $0x0, (%r14)
je 0x64b9
movw $0x800, 0xc(%r14)       # imm = 0x800
movq $0x0, 0x10(%r14)
movl $0x0, 0x20(%r14)
movw $0x0, 0x2c(%r14)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq 0x3b38(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x11bf(%rip), %rsi      # 0x7689
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2120
jmp 0x6493