// File: /workspace/github_c_makefile_star2_O2/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, %r15d
movl %edx, %ebp
movq %rdi, %rbx
movl %esi, %r12d
andl $0x7, %r12d
movl %esi, %eax
shrl $0x3, %eax
cmpl $0x6, %r12d
jne 0x5fbe
movb 0x86(%rbx), %cl
andb $0x2, %cl
shrb %cl
movzbl %cl, %ecx
leal 0x6(,%rcx,8), %r12d
movl %r12d, %ecx
notl %ecx
xorl %r13d, %r13d
btl $0x3, %esi
adcw $0x1, %r13w
testb $0x6, %cl
pushq $0x2
popq %rcx
cmovel %ecx, %r13d
testl %ebp, %ebp
cmovel %ecx, %r13d
movl %eax, %eax
leaq 0x21c4(%rip), %rcx      # 0x81ac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
pushq $0x1
popq %r14
jmpq *%rax
xorl %r8d, %r8d
testl %ebp, %ebp
sete %r8b
movl %r12d, %eax
movzwl (%rbx,%rax,2), %esi
jmp 0x6193
movl %r14d, %r13d
movl %r15d, %r14d
movl %r12d, %r15d
movzwl (%rbx,%r15,2), %eax
addl $-0x2, %eax
movl 0x38(%rbx), %ecx
andl $-0x61, %ecx
orl $0x40, %ecx
movl %ecx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
movw %ax, 0x22(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x59d2
movzwl 0x22(%rbx), %eax
movw %ax, (%rbx,%r15,2)
jmp 0x60c3
xorl %r8d, %r8d
testl %ebp, %ebp
sete %r8b
movl %r15d, %r14d
movl %r12d, %r15d
movzwl (%rbx,%r15,2), %eax
subl %r13d, %eax
movzwl %ax, %r13d
movq %rbx, %rdi
movl %r13d, %esi
movl %r12d, %edx
movl %r14d, %ecx
callq 0x5992
movw %r13w, 0x22(%rbx)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x59d2
movzwl 0x22(%rbx), %r13d
jmp 0x6112
movl %r14d, %r13d
movl %r15d, %r14d
movl %r12d, %r15d
movzwl (%rbx,%r15,2), %eax
movl 0x38(%rbx), %ecx
andl $-0x61, %ecx
orl $0x40, %ecx
movl %ecx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x59d2
movzwl (%rbx,%r15,2), %eax
addl $0x2, %eax
movw %ax, 0x22(%rbx)
movw %ax, (%rbx,%r15,2)
movq %rbx, %rdi
callq 0x5a53
testl %eax, %eax
je 0x625d
movl %r13d, %r14d
jmp 0x62df
xorl %r8d, %r8d
testl %ebp, %ebp
sete %r8b
movl %r15d, %r14d
movl %r12d, %r15d
movzwl (%rbx,%r15,2), %esi
movq %rbx, %rdi
movl %r12d, %edx
movl %r14d, %ecx
callq 0x5992
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x59d2
addw (%rbx,%r15,2), %r13w
movw %r13w, 0x22(%rbx)
movw %r13w, (%rbx,%r15,2)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x6972
testl %eax, %eax
pushq $0x1
popq %r14
jne 0x62df
jmp 0x62a6
movzwl 0xe(%rbx), %eax
movl 0x38(%rbx), %ecx
andl $-0x61, %ecx
orl $0x40, %ecx
movl %ecx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x59d2
movzwl 0xe(%rbx), %eax
addl $0x2, %eax
movw %ax, 0x22(%rbx)
movw %ax, 0xe(%rbx)
movq %rbx, %rdi
callq 0x5a53
testl %eax, %eax
jne 0x62df
xorl %r8d, %r8d
testl %ebp, %ebp
sete %r8b
movq 0x28(%rbx), %rax
movzwl 0xc(%rax), %eax
movw %ax, 0x14(%rbx)
movw %ax, 0x20(%rbx)
movl %r12d, %ecx
addw (%rbx,%rcx,2), %ax
movzwl %ax, %esi
movq %rbx, %rdi
movl %r12d, %edx
movl %r15d, %ecx
callq 0x5992
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x59d2
jmp 0x6297
movzwl 0xe(%rbx), %eax
movl 0x38(%rbx), %ecx
andl $-0x61, %ecx
orl $0x40, %ecx
movl %ecx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x59d2
movzwl 0xe(%rbx), %eax
addl $0x2, %eax
movw %ax, 0x22(%rbx)
movw %ax, 0xe(%rbx)
movq %rbx, %rdi
callq 0x5a53
testl %eax, %eax
jne 0x62df
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
andl $-0x61, %ecx
orl $0x40, %ecx
movl %ecx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x59d2
movq %rbx, %rdi
callq 0x5a53
testl %eax, %eax
jne 0x62df
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
andl $-0x61, %edx
shll $0x6, %eax
orl %edx, %eax
movl %eax, 0x38(%rbx)
movw %cx, 0x24(%rbx)
jmp 0x61a1
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
andl $-0x61, %edx
shll $0x6, %eax
orl %edx, %eax
movl %eax, 0x38(%rbx)
movw %cx, 0x24(%rbx)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x59d2
movl %r14d, %r15d
movl %r13d, %r14d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x6972
testl %eax, %eax
jne 0x62df
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movzwl 0xc(%rax), %eax
movw %ax, 0x14(%rbx)
movw %ax, 0x20(%rbx)
testl %ebp, %ebp
je 0x62df
testb $0x1, 0x24(%rbx)
je 0x62df
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)
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x222c(%rip), %rdi      # 0x8524
leaq 0x2227(%rip), %rsi      # 0x8526
leaq 0x2491(%rip), %rcx      # 0x8797
movl $0x303, %edx            # imm = 0x303
callq 0x20d0