// File: /workspace/github_c_makefile_star2_O3/aap[P]pdp11/kd11a.c
// Function: fetch_dst
static int
fetch_dst(KD11A *cpu, int m, int b, int pse)
{
	int dm, df;
	int ai;

	df = m&7;
	dm = m>>3;
	if(df == SP && USER) df = USP;	// KT11-SP
	ai = 1 + (!b || (df&6)==6 || dm&1);
	switch(dm){
	case 0:
		assert(0);	// we don't do that here
		break;
	case 1:
		// DST00
		setBA(cpu, R[df], df, pse, !b);
		setMM(cpu, 1);
		goto DST14;
	case 2:
		// DST01
		setBA(cpu, R[df], df, pse, !b);
		setMM(cpu, 1);
		D = R[df] + ai;
		goto DST03;
	case 3:
		// DST04
		setBA(cpu, R[df], df, 0, 1);
		setMM(cpu, 0);
		D = R[df] + 2;
		R[df] = D;
		if(dati(cpu)) return 1;
		goto DST12;
	case 4:
		// DST02
		D = setBA(cpu, R[df]-ai, df, pse, !b);
		setMM(cpu, 1);
		goto DST03;
		break;
	case 5:
		// DST05
		D = setBA(cpu, R[df]-2, df, 0, 1);
		setMM(cpu, 0);
		R[df] = D;
		if(dati(cpu)) return 1;
		goto DST12;
	case 6:
		// DST06/07
		 setBA(cpu, R[PC], PC, 0, 1);	// only if not still set from fetch
		setMM(cpu, 0);
		D = R[PC] + 2;
		R[PC] = D;
		if(dati(cpu)) return 1;
		// DST09
		B = R[DEST] = UNIBUS_DATA;
		// DST10
		setBA(cpu, R[df]+B, df, pse, !b);
		setMM(cpu, 1);
		goto DST14;
	case 7:
		// DST06/07
		 setBA(cpu, R[PC], PC, 0, 1);	// only if not still set from fetch
		setMM(cpu, 0);
		D = R[PC] + 2;
		R[PC] = D;
		if(dati(cpu)) return 1;
		// DST09
		B = R[DEST] = UNIBUS_DATA;
		// DST11
		setBA(cpu, R[df]+B, df, 0, 1);
		setMM(cpu, 0);
		if(dati(cpu)) return 1;
		// DST12
		B = R[DEST] = UNIBUS_DATA;
		// DST13
		setBA(cpu, R[DEST], DEST, pse, !b);
		setMM(cpu, 1);
		goto DST14;
//

		DST03:
		R[df] = D;
		if(datix(cpu, pse)) return 1;
		goto DST15;

		DST12:
		B = R[DEST] = UNIBUS_DATA;
		// DST13:
		setBA(cpu, R[DEST], DEST, pse, !b);
		setMM(cpu, 1);
		DST14:
		if(datix(cpu, pse)) return 1;
		DST15:
		B = R[DEST] = UNIBUS_DATA;
	}
	if(b && BA&1){
		// DST16
		D = B&0177400 | (B>>8)&0377;
		// DST17
		B = R[DEST] = D;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r14d
movl %edx, %ebp
movq %rdi, %rbx
movl %esi, %r12d
andl $0x7, %r12d
movl %esi, %ecx
shrl $0x3, %ecx
cmpl $0x6, %r12d
jne 0x64fc
movb 0x86(%rbx), %al
andb $0x2, %al
shrb %al
movzbl %al, %eax
leal 0x6(,%rax,8), %r12d
movl %r12d, %edi
notl %edi
xorl %eax, %eax
btl $0x3, %esi
movl $0x0, %edx
adcw $0x1, %dx
testb $0x6, %dil
movl $0x2, %esi
cmovel %esi, %edx
testl %ebp, %ebp
cmovel %esi, %edx
movl %ecx, %ecx
leaq 0x2c72(%rip), %rsi      # 0x919c
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
xorl %eax, %eax
testl %ebp, %ebp
sete %al
testl %r14d, %r14d
setne %cl
cmpl $0x6, %r12d
sete %dl
movl 0x38(%rbx), %esi
testb $0x8, %sil
sete %dil
andb %cl, %dl
andb %dil, %dl
movl %esi, %ecx
andl $-0x61, %ecx
movzbl %dl, %edx
shll $0x5, %edx
shll $0x6, %eax
orl %ecx, %eax
orl %edx, %eax
movl %r12d, %ecx
movzwl (%rbx,%rcx,2), %ecx
movl %eax, 0x38(%rbx)
movw %cx, 0x24(%rbx)
testb $0x8, %sil
jne 0x6725
movzwl 0x86(%rbx), %eax
movw %ax, 0x84(%rbx)
movzwl 0x138(%rbx), %eax
movl $0x1, %ecx
testb $0x1, %al
jne 0x6730
shrl $0x8, %eax
andl $0x1, %eax
movl %eax, %ecx
jmp 0x6730
movl %r12d, %eax
movzwl (%rbx,%rax,2), %ecx
addl $-0x2, %ecx
movl 0x38(%rbx), %edi
movl %edi, %edx
andl $-0x61, %edx
orl $0x40, %edx
movl %edx, 0x38(%rbx)
movw %cx, 0x24(%rbx)
movw %cx, 0x22(%rbx)
xorl %edx, %edx
movl $0x0, %esi
testb $0x8, %dil
jne 0x65ee
movzwl 0x86(%rbx), %edx
movzwl 0x138(%rbx), %esi
andl $0x1, %esi
movw %dx, 0x84(%rbx)
movl %esi, 0x13c(%rbx)
jmp 0x66d5
xorl %esi, %esi
testl %ebp, %ebp
sete %sil
movl %r12d, %eax
movzwl (%rbx,%rax,2), %ecx
subl %edx, %ecx
testl %r14d, %r14d
setne %dl
cmpl $0x6, %r12d
sete %dil
movl 0x38(%rbx), %r8d
testb $0x8, %r8b
sete %r9b
andb %dl, %dil
andb %r9b, %dil
movl %r8d, %edx
andl $-0x61, %edx
movzbl %dil, %edi
shll $0x5, %edi
shll $0x6, %esi
orl %edx, %esi
orl %edi, %esi
movl %esi, 0x38(%rbx)
movw %cx, 0x24(%rbx)
movw %cx, 0x22(%rbx)
testb $0x8, %r8b
jne 0x694d
movzwl 0x86(%rbx), %edx
movw %dx, 0x84(%rbx)
movzwl 0x138(%rbx), %edx
movl $0x1, %esi
testb $0x1, %dl
jne 0x6958
shrl $0x8, %edx
andl $0x1, %edx
movl %edx, %esi
jmp 0x6958
movl %r12d, %eax
movzwl (%rbx,%rax,2), %ecx
movl 0x38(%rbx), %edi
movl %edi, %edx
andl $-0x61, %edx
orl $0x40, %edx
movl %edx, 0x38(%rbx)
movw %cx, 0x24(%rbx)
xorl %edx, %edx
movl $0x0, %esi
testb $0x8, %dil
jne 0x66c1
movzwl 0x86(%rbx), %edx
movzwl 0x138(%rbx), %esi
andl $0x1, %esi
movw %dx, 0x84(%rbx)
movl %esi, 0x13c(%rbx)
addl $0x2, %ecx
movw %cx, 0x22(%rbx)
movw %cx, (%rbx,%rax,2)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7188
movl $0x1, %r15d
testl %eax, %eax
jne 0x6990
xorl %eax, %eax
testl %ebp, %ebp
sete %al
movq 0x28(%rbx), %rcx
movzwl 0xc(%rcx), %ecx
movw %cx, 0x14(%rbx)
movw %cx, 0x20(%rbx)
movl 0x38(%rbx), %edx
movl %edx, %esi
andl $-0x61, %esi
shll $0x6, %eax
orl %esi, %eax
movl %eax, 0x38(%rbx)
movw %cx, 0x24(%rbx)
testb $0x8, %dl
je 0x6581
movw $0x0, 0x84(%rbx)
xorl %ecx, %ecx
movl %ecx, 0x13c(%rbx)
jmp 0x697b
xorl %esi, %esi
testl %ebp, %ebp
sete %sil
testl %r14d, %r14d
setne %al
cmpl $0x6, %r12d
sete %cl
movl 0x38(%rbx), %edi
testb $0x8, %dil
sete %r8b
andb %al, %cl
andb %r8b, %cl
movl %edi, %eax
andl $-0x61, %eax
movzbl %cl, %ecx
shll $0x5, %ecx
shll $0x6, %esi
orl %eax, %esi
orl %ecx, %esi
movl %r12d, %eax
movzwl (%rbx,%rax,2), %ecx
movl %esi, 0x38(%rbx)
movw %cx, 0x24(%rbx)
testb $0x8, %dil
jne 0x6960
movzwl 0x86(%rbx), %esi
movw %si, 0x84(%rbx)
movzwl 0x138(%rbx), %esi
movl $0x1, %edi
testb $0x1, %sil
jne 0x696b
shrl $0x8, %esi
andl $0x1, %esi
movl %esi, %edi
jmp 0x696b
movzwl 0xe(%rbx), %eax
movl 0x38(%rbx), %esi
movl %esi, %ecx
andl $-0x61, %ecx
orl $0x40, %ecx
movl %ecx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
xorl %ecx, %ecx
movl $0x0, %edx
testb $0x8, %sil
jne 0x67ef
movzwl 0x86(%rbx), %ecx
movzwl 0x138(%rbx), %edx
andl $0x1, %edx
movw %cx, 0x84(%rbx)
movl %edx, 0x13c(%rbx)
addl $0x2, %eax
movw %ax, 0x22(%rbx)
movw %ax, 0xe(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7188
movl $0x1, %r15d
testl %eax, %eax
jne 0x6990
xorl %eax, %eax
testl %ebp, %ebp
sete %al
movq 0x28(%rbx), %rcx
movzwl 0xc(%rcx), %ecx
movw %cx, 0x14(%rbx)
movw %cx, 0x20(%rbx)
movl %r12d, %edx
addw (%rbx,%rdx,2), %cx
testl %r14d, %r14d
setne %dl
cmpl $0x6, %r12d
sete %sil
movl 0x38(%rbx), %edi
testb $0x8, %dil
sete %r8b
andb %dl, %sil
andb %r8b, %sil
movl %edi, %edx
andl $-0x61, %edx
movzbl %sil, %esi
shll $0x5, %esi
shll $0x6, %eax
orl %edx, %eax
orl %esi, %eax
movl %eax, 0x38(%rbx)
movw %cx, 0x24(%rbx)
testb $0x8, %dil
je 0x6581
jmp 0x6725
movzwl 0xe(%rbx), %ecx
movl 0x38(%rbx), %esi
movl %esi, %edx
andl $-0x61, %edx
orl $0x40, %edx
movl %edx, 0x38(%rbx)
movw %cx, 0x24(%rbx)
movl $0x0, %edx
testb $0x8, %sil
jne 0x68b7
movzwl 0x86(%rbx), %edx
movzwl 0x138(%rbx), %eax
andl $0x1, %eax
movw %dx, 0x84(%rbx)
movl %eax, 0x13c(%rbx)
addl $0x2, %ecx
movw %cx, 0x22(%rbx)
movw %cx, 0xe(%rbx)
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7188
movl $0x1, %r15d
testl %eax, %eax
jne 0x6990
movq 0x28(%rbx), %rax
movzwl 0xc(%rax), %eax
movw %ax, 0x14(%rbx)
movw %ax, 0x20(%rbx)
movl %r12d, %ecx
addw (%rbx,%rcx,2), %ax
movl 0x38(%rbx), %ecx
movl %ecx, %edx
andl $-0x61, %edx
orl $0x40, %edx
movl %edx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
movl $0x0, %eax
testb $0x8, %cl
jne 0x6930
movzwl 0x86(%rbx), %eax
movzwl 0x138(%rbx), %r13d
andl $0x1, %r13d
movw %ax, 0x84(%rbx)
movl %r13d, 0x13c(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7188
jmp 0x66e9
movw $0x0, 0x84(%rbx)
xorl %esi, %esi
movl %esi, 0x13c(%rbx)
jmp 0x6977
movw $0x0, 0x84(%rbx)
xorl %edi, %edi
movl %edi, 0x13c(%rbx)
addl %edx, %ecx
movw %cx, 0x22(%rbx)
movw %cx, (%rbx,%rax,2)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x7188
movl $0x1, %r15d
testl %eax, %eax
je 0x69a2
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
movq 0x28(%rbx), %rax
movzwl 0xc(%rax), %eax
movw %ax, 0x14(%rbx)
movw %ax, 0x20(%rbx)
testl %ebp, %ebp
je 0x6990
testb $0x1, 0x24(%rbx)
je 0x6990
movl %eax, %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
movzwl %ax, %eax
shrl $0x8, %eax
orl %ecx, %eax
movw %ax, 0x22(%rbx)
movw %ax, 0x14(%rbx)
movw %ax, 0x20(%rbx)
jmp 0x6990
leaq 0x2b0c(%rip), %rdi      # 0x94f0
leaq 0x2b07(%rip), %rsi      # 0x94f2
leaq 0x2d71(%rip), %rcx      # 0x9763
movl $0x303, %edx            # imm = 0x303
callq 0x20d0