// File: /workspace/github_c_makefile_star2_O3/aap[P]pdp11/kd11a.c
// Function: addr_dst
static int
addr_dst(KD11A *cpu, int m, int b)
{
	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:
		// MOV00
		D = setBA(cpu, R[df], df, 1, !b);	// BUG: D missing in microcode flow
		goto MOV07;
	case 2:
		// MOV01
		setBA(cpu, R[df], df, 1, !b);
		D = R[df] + ai;
		goto MOV07;
	case 3:
		// MOV03
		setBA(cpu, R[df], df, 0, 1);
		setMM(cpu, 0);
		D = R[df] + 2;
		R[df] = D;
		if(dati(cpu)) return 1;
		goto MOV11;
	case 4:
		// MOV02
		D = setBA(cpu, R[df]-ai, df, 1, !b);
		MOV07:
		R[df] = D;
		break;
	case 5:
		// MOV04
		D = setBA(cpu, R[df]-2, df, 0, 1);
		R[df] = D;
		setMM(cpu, 0);
		if(dati(cpu)) return 1;
		goto MOV11;
	case 6:
		// MOV05/06
		 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;
		// MOV08
		B = R[DEST] = UNIBUS_DATA;
		// MOV09
		setBA(cpu, R[df]+B, df, 1, !b);
		break;
	case 7:
		// MOV05/06
		 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;
		// MOV08
		B = R[DEST] = UNIBUS_DATA;
		// MOV10
		setBA(cpu, R[df]+B, df, 0, 1);	// oda BUG???
		setMM(cpu, 0);
		if(dati(cpu)) return 1;
		MOV11:
		B = R[DEST] = UNIBUS_DATA;
		// MOV12
		setBA(cpu, R[DEST], DEST, 0, !b);
		break;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebp
movq %rdi, %rbx
movl %esi, %r15d
andl $0x7, %r15d
movl %esi, %edx
shrl $0x3, %edx
cmpl $0x6, %r15d
jne 0x5ee6
movb 0x86(%rbx), %al
andb $0x2, %al
shrb %al
movzbl %al, %eax
leal 0x6(,%rax,8), %r15d
movl %r15d, %edi
notl %edi
xorl %eax, %eax
btl $0x3, %esi
movl $0x0, %ecx
adcw $0x1, %cx
testb $0x6, %dil
movl $0x2, %esi
cmovel %esi, %ecx
testl %ebp, %ebp
cmovel %esi, %ecx
movl %edx, %edx
leaq 0x3268(%rip), %rsi      # 0x917c
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
xorl %edx, %edx
testl %ebp, %ebp
sete %dl
movl %r15d, %eax
movzwl (%rbx,%rax,2), %ecx
xorl $0x6, %r15d
movl 0x38(%rbx), %esi
movl %esi, %edi
andl $0x8, %edi
xorl %r8d, %r8d
orl %r15d, %edi
sete %r8b
andl $-0x61, %esi
shll $0x5, %r8d
shll $0x6, %edx
orl %esi, %edx
orl %r8d, %edx
movl %edx, 0x38(%rbx)
movw %cx, 0x24(%rbx)
jmp 0x60be
movl %r15d, %eax
movzwl (%rbx,%rax,2), %ecx
addl $-0x2, %ecx
movl 0x38(%rbx), %edx
movl %edx, %esi
andl $-0x61, %esi
orl $0x40, %esi
movl %esi, 0x38(%rbx)
movw %cx, 0x24(%rbx)
movw %cx, 0x22(%rbx)
movw %cx, (%rbx,%rax,2)
xorl %eax, %eax
movl $0x0, %ecx
testb $0x8, %dl
jne 0x5f9d
movzwl 0x86(%rbx), %eax
movzwl 0x138(%rbx), %ecx
andl $0x1, %ecx
movw %ax, 0x84(%rbx)
movl %ecx, 0x13c(%rbx)
jmp 0x6041
xorl %edx, %edx
testl %ebp, %ebp
sete %dl
movl %r15d, %eax
movzwl (%rbx,%rax,2), %esi
subl %ecx, %esi
xorl $0x6, %r15d
movl 0x38(%rbx), %ecx
movl %ecx, %edi
andl $0x8, %edi
xorl %r8d, %r8d
orl %r15d, %edi
sete %r8b
andl $-0x61, %ecx
shll $0x5, %r8d
shll $0x6, %edx
orl %ecx, %edx
orl %r8d, %edx
movl %edx, 0x38(%rbx)
movw %si, 0x24(%rbx)
movl %esi, %ecx
jmp 0x60be
movl %r15d, %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 0x6029
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, %r14d
testl %eax, %eax
jne 0x6175
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
jmp 0x616b
xorl %edx, %edx
testl %ebp, %ebp
sete %dl
movl %r15d, %eax
movzwl (%rbx,%rax,2), %esi
xorl $0x6, %r15d
movl 0x38(%rbx), %edi
movl %edi, %r8d
andl $0x8, %r8d
xorl %r9d, %r9d
orl %r15d, %r8d
sete %r9b
andl $-0x61, %edi
shll $0x5, %r9d
shll $0x6, %edx
orl %edi, %edx
orl %r9d, %edx
movl %edx, 0x38(%rbx)
movw %si, 0x24(%rbx)
addl %esi, %ecx
movw %cx, 0x22(%rbx)
movw %cx, (%rbx,%rax,2)
jmp 0x6172
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 0x60ff
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, %r14d
testl %eax, %eax
jne 0x6175
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 %r15d, %edx
addw (%rbx,%rdx,2), %cx
xorl $0x6, %r15d
movl 0x38(%rbx), %edx
movl %edx, %esi
andl $0x8, %esi
xorl %edi, %edi
orl %r15d, %esi
sete %dil
andl $-0x61, %edx
shll $0x5, %edi
shll $0x6, %eax
orl %edx, %eax
orl %edi, %eax
movl %eax, 0x38(%rbx)
movw %cx, 0x24(%rbx)
xorl %r14d, %r14d
movl %r14d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
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 0x61b3
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 %r12d, %r12d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7188
movl $0x1, %r14d
testl %eax, %eax
jne 0x6175
movq 0x28(%rbx), %rax
movzwl 0xc(%rax), %eax
movw %ax, 0x14(%rbx)
movw %ax, 0x20(%rbx)
movl %r15d, %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 0x6228
movzwl 0x86(%rbx), %eax
movzwl 0x138(%rbx), %r12d
andl $0x1, %r12d
movw %ax, 0x84(%rbx)
movl %r12d, 0x13c(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7188
jmp 0x6051
leaq 0x32a4(%rip), %rdi      # 0x94f0
leaq 0x329f(%rip), %rsi      # 0x94f2
leaq 0x34c8(%rip), %rcx      # 0x9722
movl $0x207, %edx            # imm = 0x207
callq 0x20d0