LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O3/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 0x4ec0
addl $0xfffc0140, %ecx       # imm = 0xFFFC0140
cmpl $0xe, %ecx
ja 0x4ec2
leaq 0x2680(%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 0x4ee1
jmp 0x4ebe
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 0x4ebe
movq %rsi, %rdi
callq 0x50a9
jmp 0x4ebe
movzwl 0xc(%rdi), %eax
movw %ax, 0x2(%rsi)
testw %ax, %ax
js 0x4eb9
movw $0x0, (%rsi)
jmp 0x4ebe
movb 0xc(%rdi), %al
andb $0x3f, %al
movb %al, 0x6(%rsi)
movq %rsi, %rdi
callq 0x51e8
jmp 0x4ebe
movzwl 0xc(%rdi), %eax
movw %ax, 0x4(%rsi)
movq %rsi, %rdi
callq 0x504d
jmp 0x4ebe
movzwl 0xc(%rdi), %eax
movw %ax, (%rsi)
jmp 0x4ebe
movb 0xc(%rdi), %al
andb $0x3f, %al
movb %al, 0x6(%rsi)
movq %rsi, %rdi
callq 0x5124
jmp 0x4ebe
movw $0xffff, (%rsi)         # imm = 0xFFFF
xorl %eax, %eax
popq %rcx
retq
leaq 0x2502(%rip), %rdi      # 0x73cb
leaq 0x2688(%rip), %rsi      # 0x7558
leaq 0x2687(%rip), %rcx      # 0x755e
movl $0x12a, %edx            # imm = 0x12A
callq 0x20d0
// File: /workspace/github_c_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movzwl (%rdi), %ebp
movl %ebp, %eax
shll $0x10, %eax
movzwl 0x2(%rdi), %esi
orl %eax, %esi
movzwl 0x4(%rdi), %r9d
shll $0x10, %r9d
movzbl 0x7(%rdi), %ecx
movl %ecx, %eax
andb $0x7e, %al
movl %ebp, %edi
shrl $0xf, %edi
movb $0x10, 0x6(%rbx)
xorl %edx, %edx
movb $0xf, %r11b
movl %esi, %r14d
movl %r9d, %r8d
movl %r9d, %esi
shrl %esi
andl $0x80000000, %r9d       # imm = 0x80000000
orl %esi, %r9d
andl $0x7fff, %edx           # imm = 0x7FFF
movl %r9d, %r10d
negl %r10d
xorl %r15d, %r15d
movl %r14d, %esi
xorl %r8d, %esi
setns %r15b
movl %r9d, %esi
cmovnsl %r10d, %esi
leal (%r15,%rdx,2), %edx
addl %r14d, %esi
cmpb $0xf, %r11b
sete %r15b
testl %esi, %esi
setne %r12b
movl %esi, %r14d
shrl $0x1f, %r14d
cmpl %edi, %r14d
sete %r13b
andb %r15b, %r13b
testb %r12b, %r13b
jne 0x4fb4
movb %r11b, 0x6(%rbx)
addb $-0x1, %r11b
jb 0x4f1c
testl %esi, %esi
je 0x4fab
cmpl %edi, %r14d
sete %r11b
movl %r9d, %r14d
negl %r14d
cmovsl %r9d, %r14d
addl %esi, %r14d
setne %r14b
andb %r11b, %r14b
cmpb $0x1, %r14b
jne 0x4fbf
leal 0x1(,%rdx,2), %edx
jmp 0x4fd8
movl $0x1, %r8d
xorl %r14d, %r14d
jmp 0x4ffc
xorl %r11d, %r11d
movl %esi, %r14d
xorl %r8d, %r14d
cmovnsl %r10d, %r9d
setns %r11b
addl %r9d, %esi
addl %r11d, %edx
addl %edx, %edx
shrl $0x1f, %r8d
movzwl %dx, %r9d
shrl $0xf, %r9d
xorl %r10d, %r10d
cmpl %r9d, %r8d
setne %r10b
xorl %r8d, %r8d
cmpl %r10d, %edi
sete %r14b
setne %r8b
movw %si, (%rbx)
movw %dx, 0x2(%rbx)
movl %ecx, %edx
andb $0x7e, %dl
orb $-0x80, %al
btl $0x6, %ecx
sbbl $0x0, %r8d
movzbl %al, %eax
movzbl %dl, %ecx
cmovnel %eax, %ecx
movb %cl, 0x7(%rbx)
movq %rbx, %rdi
callq 0x5420
testb %r14b, %r14b
jne 0x503e
movb 0x7(%rbx), %al
andb $-0x41, %al
shrl $0x9, %ebp
andb $0x40, %bpl
orb %al, %bpl
movb %bpl, 0x7(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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
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 0x5080
testw %r8w, %r8w
jne 0x507e
addl %ecx, %eax
jmp 0x5080
subl %ecx, %eax
addl %ecx, %ecx
movzwl %dx, %edx
shrl %edx
incb %sil
jne 0x5065
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 0x5420
// File: /workspace/github_c_makefile_star2_O3/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 0x5118
movl %ecx, %edx
shrl $0xf, %edx
shrl $0xe, %ecx
andl $0x1, %ecx
cmpl %ecx, %edx
jne 0x5118
movb $0x1, %dl
cmpb $0x20, %dl
je 0x5118
leal (%rax,%rax), %ecx
movb %dl, 0x6(%rdi)
cmpl $0xc0000000, %ecx       # imm = 0xC0000000
je 0x511a
movl %ecx, %esi
shrl $0x1f, %esi
shrl $0x1d, %eax
andl $0x1, %eax
incb %dl
cmpl %eax, %esi
movl %ecx, %eax
je 0x50f0
jmp 0x511a
movl %eax, %ecx
rorl $0x10, %ecx
movl %ecx, (%rdi)
jmp 0x5420
// File: /workspace/github_c_makefile_star2_O3/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), %edx
movl %edx, %ecx
shll $0x10, %ecx
movzwl 0x2(%rdi), %eax
orl %ecx, %eax
movb 0x6(%rdi), %r9b
movb 0x7(%rdi), %cl
andb $-0x41, %cl
shrl $0x9, %edx
andb $0x40, %dl
orb %cl, %dl
movl %r9d, %esi
andb $0x3f, %sil
je 0x51b9
pushq %rbx
xorl %ecx, %ecx
movl $0x1, %r8d
movl %edx, %r10d
andb $-0x42, %r10b
testb $0x20, %r9b
jne 0x5197
movl %eax, %r9d
shrl $0x1f, %r9d
leal (%rax,%rax), %ebx
movl %ebx, %r11d
shrl $0x1f, %r11d
movzbl %dl, %edx
btl $0x6, %edx
sbbl $0x0, %r11d
cmovnel %r8d, %ecx
shrl $0x18, %eax
andb $0x40, %al
orb %r9b, %al
orb %r10b, %al
movb $-0x1, %r11b
movl %eax, %edx
movl %ebx, %eax
jmp 0x51a7
movl %eax, %edx
andb $0x1, %dl
orb %dl, %r10b
shrl %eax
movb $0x1, %r11b
movl %r10d, %edx
movl %esi, %r9d
addb %r11b, %r9b
movl %r9d, %esi
andb $0x3f, %sil
jne 0x5156
popq %rbx
jmp 0x51bb
xorl %ecx, %ecx
movb $0x0, 0x6(%rdi)
movzbl %dl, %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 0x5420
// File: /workspace/github_c_makefile_star2_O3/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), %r9b
movb 0x7(%rdi), %dl
andb $-0x41, %dl
shrl $0x9, %ecx
andb $0x40, %cl
orb %dl, %cl
movl %r9d, %esi
xorl %edx, %edx
andb $0x3f, %sil
je 0x5292
movl $0x1, %r8d
movl %ecx, %r10d
andb $0x40, %r10b
testb $0x20, %r9b
jne 0x5266
addl %eax, %eax
andb $-0x2, %cl
movl %eax, %r9d
shrl $0x1f, %r9d
orb %cl, %r9b
movl %eax, %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
andl $0x7ffffffe, %eax       # imm = 0x7FFFFFFE
testb %r10b, %r10b
cmovnel %ecx, %eax
movzbl %r9b, %ecx
movl %ecx, %r10d
shrl $0x6, %r10d
xorl %ecx, %r10d
testb $0x1, %r10b
cmovnel %r8d, %edx
movb $-0x1, %r10b
movl %r9d, %ecx
jmp 0x5283
andb $-0x2, %cl
movl %eax, %r9d
andb $0x1, %r9b
orb %r9b, %cl
shrl %eax
movzbl %r10b, %r9d
shll $0x19, %r9d
orl %r9d, %eax
movb $0x1, %r10b
movl %esi, %r9d
addb %r10b, %r9b
movl %r9d, %esi
andb $0x3f, %sil
jne 0x5219
movb $0x0, 0x6(%rdi)
movzbl %cl, %ecx
btl $0x6, %ecx
sbbl $0x0, %edx
setne %dl
andb $0x7f, %cl
shlb $0x7, %dl
orb %cl, %dl
movb %dl, 0x7(%rdi)
movl %eax, %ecx
shrl $0x10, %ecx
movw %cx, (%rdi)
movw %ax, 0x2(%rdi)
jmp 0x5420
// File: /workspace/github_c_makefile_star2_O3/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 0x52f1
movq %rsi, %rbp
xorl %ebx, %ebx
addl $0xfffc0140, %eax       # imm = 0xFFFC0140
leaq 0x21f4(%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 0x5124
jmp 0x52f1
movzwl 0xc(%rdi), %eax
movb %ah, 0x3(%rbp)
testw %ax, %ax
js 0x5387
movw $0x0, (%rbp)
jmp 0x52f1
movzbl 0xc(%rdi), %edi
callq 0x2444
movw %ax, 0x4(%rbp)
movq %rbp, %rdi
callq 0x504d
jmp 0x52f1
movb 0xd(%rdi), %al
movb %al, 0x1(%rbp)
jmp 0x52f1
movb 0xc(%rdi), %al
andb $0x3f, %al
movb %al, 0x6(%rbp)
movq %rbp, %rdi
callq 0x51e8
jmp 0x52f1
movzbl 0xc(%rdi), %edi
callq 0x2444
movw %ax, 0x4(%rbp)
movq %rbp, %rdi
callq 0x4ee1
jmp 0x52f1
movq %rbp, %rdi
callq 0x50a9
jmp 0x52f1
movzbl 0xc(%rdi), %edi
callq 0x2444
movw %ax, 0x2(%rbp)
testw %ax, %ax
jns 0x5318
movw $0xffff, (%rbp)         # imm = 0xFFFF
jmp 0x52f1
movzbl 0xc(%rdi), %edi
callq 0x2444
movw %ax, (%rbp)
jmp 0x52f1
// File: /workspace/github_c_makefile_star2_O3/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 0x53dc
addl $0xfffc0140, %ecx       # imm = 0xFFFC0140
cmpl $0xe, %ecx
ja 0x53f7
leaq 0x2151(%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 0x53d6
movzwl 0x2(%rsi), %eax
jmp 0x53d6
movzbl 0x6(%rsi), %eax
andl $0x3f, %eax
jmp 0x53d6
movzwl 0x6(%rsi), %eax
jmp 0x53d6
pushq %rax
leaq 0x1fcc(%rip), %rdi      # 0x73cb
leaq 0x2152(%rip), %rsi      # 0x7558
leaq 0x216e(%rip), %rcx      # 0x757b
movl $0x18c, %edx            # imm = 0x18C
callq 0x20d0
// File: /workspace/github_c_makefile_star2_O3/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)
movzwl (%rdi), %eax
testw %ax, %ax
jne 0x5441
movzwl 0x2(%rbx), %edi
callq 0x243e
testw %ax, %ax
je 0x5455
movzwl (%rbx), %eax
cmpw $-0x1, %ax
jne 0x5459
movzwl 0x2(%rbx), %edi
callq 0x243e
testw %ax, %ax
je 0x5459
orb $0x2, 0x7(%rbx)
cmpw $0x0, 0x2(%rbx)
movzwl (%rbx), %eax
jne 0x547a
movzbl 0x7(%rbx), %ecx
movl %ecx, %edx
orb $0x4, %dl
testl %eax, %eax
movzbl %dl, %edx
cmovnel %ecx, %edx
orb $0x8, %dl
movb %dl, 0x7(%rbx)
testl %eax, %eax
je 0x5489
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x548e
movb $0x20, %al
jmp 0x548b
movb $0x10, %al
orb %al, 0x7(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x54b5
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_O3/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 0x54df
movl 0xc(%rdi), %ecx
movl %ecx, %eax
shrl $0x6, %eax
andl $0x1, %eax
movl %eax, (%rsi)
xorl %eax, %eax
testb %cl, %cl
js 0x54df
movq $0x0, 0x4(%rsi)
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x5509
movl 0xc(%rdi), %ecx
movl %ecx, %eax
shrl $0x6, %eax
andl $0x1, %eax
movl %eax, (%rsi)
xorl %eax, %eax
testb %cl, %cl
js 0x5509
movq $0x0, 0x4(%rsi)
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x55e8
andl $0x6, %ecx
leaq 0x200d(%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 0x55e6
movw $0x0, 0xc(%rdi)
jmp 0x55e6
movzbl 0x14(%rsi), %eax
movw %ax, 0xc(%rdi)
movb $0x0, 0x14(%rsi)
movl $0x0, 0x10(%rsi)
jmp 0x55e6
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_O3/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 0x5613
andl $0x7, %ecx
xorl %eax, %eax
leaq 0x1faa(%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 0x5669
cmpl $0x0, 0x10(%rsi)
je 0x5613
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 0x566e
cmpl $0x0, 0x1c(%rsi)
je 0x5613
orb $0x1, 0x28(%rsi)
retq
andb $-0x3, 0x28(%rsi)
retq
andb $-0x2, 0x28(%rsi)
retq
// File: /workspace/github_c_makefile_star2_O3/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 0xe646(%rip), %eax      # 0x13ccc
incl %eax
movl %eax, 0xe63e(%rip)      # 0x13ccc
cmpl $0x4e20, %eax           # imm = 0x4E20
jne 0x5707
cmpl $0x0, 0x20(%rbx)
jne 0x56cc
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 0x56cc
orb $0x1, 0x28(%rbx)
leaq 0x2c(%rbx), %rdi
leaq 0xe(%rsp), %rsi
callq 0x67d5
testl %eax, %eax
je 0x56fd
xorl %eax, %eax
movl %eax, 0xc(%rbx)
movb 0xe(%rsp), %cl
movb %cl, 0x14(%rbx)
movl %eax, 0x8(%rbx)
movl $0x1, 0x10(%rbx)
cmpl %eax, 0x4(%rbx)
je 0x56fd
orb $0x2, 0x28(%rbx)
movl $0x0, 0xe5c5(%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_O3/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 0x5801
andl $0xe, %ecx
leaq 0x1e3a(%rip), %rax      # 0x75f0
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
addq $0x8, %rsi
jmp 0x57f8
addq $0xe, %rsi
jmp 0x57f8
movslq 0x1c(%rsi), %rax
shlq $0x4, %rax
addq %rax, %rsi
addq $0x28, %rsi
jmp 0x57f8
addq $0xc, %rsi
jmp 0x57f8
addq $0xa, %rsi
jmp 0x57f8
addq $0x12, %rsi
jmp 0x57f8
addq $0x14, %rsi
jmp 0x57f8
addq $0x10, %rsi
movzwl (%rsi), %eax
movw %ax, 0xc(%rdi)
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x5947
andl $0xf, %eax
xorl %ebx, %ebx
leaq 0x1dfa(%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 0x5939
movl $0x0, 0x18(%rsi)
testb $0x6, %cl
je 0x592f
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 0x5939
orl $0x880, %ecx            # imm = 0x880
movw %cx, 0x8(%rsi)
movl $0x1, 0x18(%rsi)
jmp 0x5939
movzwl 0xc(%rsi), %eax
movzwl 0xc(%rdi), %ecx
xorw %ax, %cx
andl %edx, %ecx
xorl %ecx, %eax
movw %ax, 0xc(%rsi)
jmp 0x5947
movzwl 0xa(%rsi), %eax
movzwl 0xc(%rdi), %ecx
xorw %ax, %cx
andl %edx, %ecx
xorl %ecx, %eax
movw %ax, 0xa(%rsi)
jmp 0x5947
movzwl 0x12(%rsi), %eax
movzwl 0xc(%rdi), %ecx
xorw %ax, %cx
andl %edx, %ecx
xorl %ecx, %eax
movw %ax, 0x12(%rsi)
jmp 0x5947
movzwl 0xe(%rsi), %eax
movzwl 0xc(%rdi), %ecx
xorw %ax, %cx
andl %edx, %ecx
xorl %ecx, %eax
movw %ax, 0xe(%rsi)
jmp 0x5947
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 0x5b70
jmp 0x5947
orl $0x80, %ecx
movw %cx, 0x8(%rsi)
btl $0x8, %eax
jae 0x5947
movq %rsi, %rdi
callq 0x5b3a
movl %ebx, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x59da
incq %r15
addq $0x10, %r14
cmpq $0x8, %r15
jne 0x5970
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 0x59d4
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_O3/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 0x5aa1
testl %edx, %edx
je 0x5b18
movq %rsi, %rbp
testb $-0x80, 0x8(%rsi)
jne 0x5b18
movzwl 0xe(%rbp), %eax
shrl $0xb, %eax
movl 0x10(%rbp), %esi
shll $0x5, %esi
andl $0x60, %esi
orl %eax, %esi
movq %rbp, %rdi
callq 0x5c67
cmpw $0x0, 0xa(%rbp)
je 0x5b18
movzwl 0x8(%rbx), %eax
movzwl 0xe(%rbp), %ecx
andl $0x7ff, %ecx            # imm = 0x7FF
cmpw %cx, %ax
jne 0x5b18
movl 0x8(%rbp), %ecx
shrl %ecx
andl $0x3, %ecx
leaq 0x1c22(%rip), %rdx      # 0x766c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq %rbp, %rdi
callq 0x5d22
movq (%rbp), %rdi
movl %eax, 0x8(%rdi)
callq 0x2392
testl %eax, %eax
je 0x5a78
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 0x5ae0
movw $0x0, 0x8(%rbx)
jmp 0x5b26
movzwl 0xa8(%rbp,%rax,2), %eax
movw %ax, 0x12(%rbp)
movq (%rbp), %rcx
movw %ax, 0xc(%rcx)
movq %rbp, %rdi
callq 0x5d22
movq (%rbp), %rdi
movl %eax, 0x8(%rdi)
callq 0x23c4
testl %eax, %eax
je 0x5ae8
orw $0x480, 0x8(%rbp)       # imm = 0x480
movl $0x18, %eax
movl $0x1, (%rbp,%rax)
incw 0xa(%rbp)
jne 0x5afb
orb $-0x80, 0x8(%rbp)
movl $0x1, 0x18(%rbp)
jmp 0x5b18
incw 0xe(%rbp)
jne 0x5b18
movl 0x10(%rbp), %esi
incl %esi
movw %si, 0x10(%rbp)
shrl $0x2, %esi
andl $0xf, %esi
movq %rbp, %rdi
callq 0x5b70
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_O3/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 0x5b66
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5c67
movl $0x0, 0x1c(%rbx)
xorl %eax, %eax
movl %eax, 0x12(%rbx)
movl %eax, 0x18(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x5ba8
pushq %rbp
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5c67
movl %ebp, %eax
andl $0x7, %eax
movl %eax, 0x1c(%rbx)
testb $0x8, %bpl
je 0x5ba2
orw $0x880, 0x8(%rbx)       # imm = 0x880
movl $0x1, 0x18(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x5bda
callq 0x2090
movq $0x0, (%r14)
movw $0x0, 0x8(%r14)
leaq 0x1aa2(%rip), %rsi      # 0x7683
movq %rbx, %rdi
callq 0x21b0
movq %rax, (%r14)
testq %rax, %rax
jne 0x5c08
leaq 0x1a8e(%rip), %rsi      # 0x7686
movq %rbx, %rdi
callq 0x21b0
movq %rax, (%r14)
testq %rax, %rax
je 0x5c17
movw $0x0, 0x8(%r14)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq 0x43da(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x1a61(%rip), %rsi      # 0x7689
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2120
jmp 0x5c08
// File: /workspace/github_c_makefile_star2_O3/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 0x5c58
callq 0x2090
movq $0x0, (%rbx)
movw $0x0, 0x8(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x5cfd
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 0x5cb4
movq (%r15), %rcx
testq %rcx, %rcx
je 0x5d03
leaq 0xa8(%r14), %rdi
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x2200
movl %ebx, 0xa4(%r14)
testl %ebx, %ebx
js 0x5cfd
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 0x1993(%rip), %rdi      # 0x769d
leaq 0x196b(%rip), %rsi      # 0x767c
leaq 0x198f(%rip), %rcx      # 0x76a7
movl $0x40, %edx
callq 0x20d0
// File: /workspace/github_c_makefile_star2_O3/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 0x5d4d
movl %ecx, %edx
addw $0x2, %dx
movw %dx, 0xc(%rdi)
jne 0x5d4d
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_O3/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 0x5dc8
andl $0xe, %ecx
leaq 0x194a(%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 0x5dc2
movzwl 0xe(%rsi), %eax
jmp 0x5dc2
movzwl 0x16(%rsi), %eax
jmp 0x5dc2
movzwl 0xc(%rsi), %eax
jmp 0x5dc2
movzwl 0xa(%rsi), %eax
jmp 0x5dc2
movzwl 0x12(%rsi), %eax
jmp 0x5dc2
movzwl 0x14(%rsi), %eax
jmp 0x5dc2
movzwl 0x10(%rsi), %eax
movw %ax, 0xc(%rdi)
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x5e00
andl $0xf, %ecx
xorl %eax, %eax
leaq 0x1909(%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 0x5e58
testb $0x1, %cl
jne 0x5e00
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_O3/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 0x188d(%rip), %rdx      # 0x7740
movslq (%rdx,%rcx,4), %r8
addq %rdx, %r8
jmpq *%r8
andl $0xdf7f, %eax           # imm = 0xDF7F
movw %ax, 0xc(%rsi)
cmpq $0x0, (%rdi)
jne 0x5ef9
movzwl 0xa(%rsi), %edx
movl %edx, %r8d
orl $0x80, %r8d
movw %r8w, 0xa(%rsi)
testl $0xb64c, %edx           # imm = 0xB64C
je 0x5ef9
orl $0x80, %eax
movw %ax, 0xc(%rsi)
movl $0x0, 0x10(%rdi)
xorl %ecx, %ecx
movzwl 0x12(%rsi), %edx
movl %edx, %r8d
notl %r8d
testb $0xc, %r8b
jne 0x5f35
movzwl 0xa(%rsi), %r8d
movl %r8d, %r9d
orl $0x20, %r9d
movw %r9w, 0xa(%rsi)
testl $0xb64c, %r8d           # imm = 0xB64C
je 0x5f35
orl $0x80, %eax
movw %ax, 0xc(%rsi)
movl $0x0, 0x10(%rdi)
xorl %ecx, %ecx
movl %edx, %r8d
andl $0x1fc0, %r8d           # imm = 0x1FC0
cmpl $0x1921, %r8d           # imm = 0x1921
jb 0x5f5e
orb $0x40, 0xa(%rsi)
orl $0x80, %eax
movw %ax, 0xc(%rsi)
movl $0x0, 0x10(%rdi)
xorl %ecx, %ecx
testb $0x20, 0xc(%rdi)
je 0x5f7b
orl $0x2, %ecx
cmpl $0x3, %ecx
jne 0x5f7b
orb $0x20, 0xb(%rsi)
orl $0x80, %eax
movw %ax, 0xc(%rsi)
jmp 0x5fd1
shrl $0x5, %edx
movzbl %dl, %eax
jmp 0x5fe3
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 0x5fa1
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_O3/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 0x60b2
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 0x5e8b
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 0x6147
incq %r15
addq $0x30, %r14
cmpq $0x8, %r15
jne 0x60b9
movzwl 0xa(%rbx), %eax
movzwl 0xc(%rbx), %ecx
testl $0xb64c, %eax           # imm = 0xB64C
je 0x60f3
orl $0x4000, %ecx           # imm = 0x4000
jmp 0x60fe
testw %ax, %ax
je 0x613f
andl $0xbfff, %ecx           # imm = 0xBFFF
orl $0x8000, %ecx           # imm = 0x8000
movw %cx, 0xc(%rbx)
movzwl %cx, %edx
xorl %eax, %eax
testb $0x40, %dl
je 0x6139
movl %edx, %esi
andl $0x4000, %esi           # imm = 0x4000
movl $0x5, %eax
orl 0x1c(%rbx), %esi
jne 0x6139
movl $0x0, %eax
testw %cx, %cx
jns 0x6139
shll $0x17, %edx
sarl $0x1f, %edx
andl $0x5, %edx
movl %edx, %eax
popq %rbx
popq %r14
popq %r15
retq
andl $0x3fff, %ecx           # imm = 0x3FFF
jmp 0x6104
// File: /workspace/github_c_makefile_star2_O3/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 0x64c9
callq 0x653a
leaq 0x11b3(%rip), %rsi      # 0x7683
movq %rbx, %rdi
callq 0x21b0
movq %rax, (%r14)
testq %rax, %rax
jne 0x64f7
leaq 0x119f(%rip), %rsi      # 0x7686
movq %rbx, %rdi
callq 0x21b0
movq %rax, (%r14)
testq %rax, %rax
je 0x651d
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 0x3ad4(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x115b(%rip), %rsi      # 0x7689
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2120
jmp 0x64f7
// File: /workspace/github_c_makefile_star2_O3/aap[P]pdp11/rk11.c
// Function: detach_rk05
void
detach_rk05(RK11 *rk, int n)
{
	if(rk->drives[n].fp){
		fclose(rk->drives[n].fp);
		rk->drives[n].fp = nil;
	}
	reset_rk05(&rk->drives[n]);
}

// Assembly:
pushq %rbx
movslq %esi, %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq (%rdi,%rax), %rbx
addq $0x28, %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x6562
callq 0x2090
movq $0x0, (%rbx)
movw $0x800, 0xc(%rbx)       # imm = 0x800
movq $0x0, 0x10(%rbx)
movl $0x0, 0x20(%rbx)
movw $0x0, 0x2c(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/aap[P]pdp11/rk11.c
// Function: busaddr
static int
busaddr(RK11 *rk)
{
	int addr = rk->rkba | (rk->rkcs&060)<<12;
	if((rk->rkcs & IBA)==0){
		rk->rkba += 2;
		if(rk->rkba == 0)
			SETMASK(rk->rkcs, rk->rkcs+020, 060);
	}
	return addr;
}

// Assembly:
movzwl 0x10(%rdi), %ecx
movzwl 0xc(%rdi), %eax
btl $0xb, %eax
jb 0x65aa
movl %ecx, %edx
addw $0x2, %dx
movw %dx, 0x10(%rdi)
jne 0x65aa
movl %eax, %edx
andl $-0x31, %edx
leal 0x10(%rax), %esi
andl $0x30, %esi
orl %edx, %esi
movw %si, 0xc(%rdi)
andl $0x30, %eax
shll $0xc, %eax
orl %ecx, %eax
retq
// File: /workspace/github_c_makefile_star2_O3/aap[P]pdp11/rk11.c
// Function: count
static void
count(RK05 *drive, RK11 *rk)
{
	word rkda;

	if(rk->rkwc == 0)
		return;

	rkda = rk->rkda+1;
	if((rkda & 017) == 12)
		rkda = (rkda&~017)+020;
	if((rkda&0160000) != (rk->rkda&0160000))
		rkerr(drive, rk, OVR);
	SETMASK(rk->rkda, rkda, 017777);

	// seek
	drive->newcyl = (rkda>>5) & 0377;
}

// Assembly:
cmpw $0x0, 0xe(%rsi)
je 0x6629
movzwl 0x12(%rsi), %eax
leal 0x1(%rax), %ecx
movl %ecx, %edx
andl $0xf, %edx
movl %ecx, %r8d
andl $-0x10, %r8d
addl $0x10, %r8d
cmpw $0xc, %dx
cmovnel %ecx, %r8d
movzwl %r8w, %ecx
movl $0xe000, %edx           # imm = 0xE000
andl %edx, %r8d
andl %edx, %eax
cmpl %eax, %r8d
je 0x6612
movzwl 0xa(%rsi), %edx
movl %edx, %r8d
orl $0x4000, %r8d           # imm = 0x4000
movw %r8w, 0xa(%rsi)
testl $0xb64c, %edx           # imm = 0xB64C
je 0x6612
orb $-0x80, 0xc(%rsi)
movl $0x0, 0x10(%rdi)
movl %ecx, %edx
andl $0x1fff, %edx           # imm = 0x1FFF
orl %edx, %eax
movw %ax, 0x12(%rsi)
shrl $0x5, %ecx
movzbl %cl, %eax
movl %eax, 0x20(%rdi)
retq
nop
// File: /workspace/github_c_makefile_star2_O3/aap[P]pdp11/unix.c
// Function: handleclock
int
handleclock(Clock *clk)
{
	struct timespec diff;
	clock_gettime(CLOCK_REALTIME, &clk->newtime);
	diff.tv_sec = clk->newtime.tv_sec - clk->oldtime.tv_sec;
	diff.tv_nsec = clk->newtime.tv_nsec - clk->oldtime.tv_nsec;
	if(diff.tv_nsec < 0){
		diff.tv_nsec += 1000000000;
		diff.tv_sec -= 1;
	}
	if(diff.tv_nsec >= clk->period){
		clk->oldtime.tv_nsec += clk->period;
		if(clk->oldtime.tv_nsec >= 1000000000){
			clk->oldtime.tv_nsec -= 1000000000;
			clk->oldtime.tv_sec += 1;
		}
		return 1;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x10(%rdi), %rsi
xorl %ebp, %ebp
xorl %edi, %edi
callq 0x2070
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rcx
subq %rax, %rcx
leaq 0x3b9aca00(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
movq 0x20(%rbx), %rcx
cmpq %rcx, %rdx
jl 0x679a
addq %rax, %rcx
movq %rcx, 0x8(%rbx)
movl $0x1, %ebp
cmpq $0x3b9aca00, %rcx       # imm = 0x3B9ACA00
jl 0x679a
addq $-0x3b9aca00, %rcx      # imm = 0xC4653600
movq %rcx, 0x8(%rbx)
incq (%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/aap[P]pdp11/unix.c
// Function: timestamp
int
timestamp(char *buffer, size_t n)
{
	struct tm *tm;
	time_t t;

	t = time(NULL);
	if (t == (time_t)-1)
		return -1;
	tm = localtime(&t);
	if (tm == NULL)
		return -1;
	if(strftime(buffer, n, "%Y%m%d%H%M%S", tm) == 0)
		return -1;
	return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
xorl %edi, %edi
callq 0x2140
movq %rax, 0x8(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq $-0x1, %rax
je 0x685c
leaq 0x8(%rsp), %rdi
callq 0x2030
testq %rax, %rax
je 0x685c
leaq 0xf38(%rip), %rdx       # 0x777e
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rcx
callq 0x2190
xorl %ebp, %ebp
cmpq $0x1, %rax
sbbl %ebp, %ebp
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O3/aap[P]pdp11/util.c
// Function: readn
int
readn(int fd, void *data, int n)
{
	int m;

	while(n > 0){
		m = read(fd, data, n);
		if(m <= 0)
			return -1;
		data += m;
		n -= m;
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
xorl %ebx, %ebx
testl %edx, %edx
jle 0x6910
movl %edx, %ebp
movq %rsi, %r14
movl %edi, %r15d
movl %ebp, %edx
movl %r15d, %edi
movq %r14, %rsi
callq 0x2100
testl %eax, %eax
jle 0x690b
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq %rcx, %r14
subl %eax, %ebp
jg 0x68e9
jmp 0x6910
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq