// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl -0x14(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x24(%rbp)
movl -0x14(%rbp), %eax
sarl $0x3, %eax
movl %eax, -0x20(%rbp)
cmpl $0x6, -0x24(%rbp)
jne 0x81c7
movq -0x10(%rbp), %rax
movzwl 0x86(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x81c7
movl $0xe, -0x24(%rbp)
movb $0x1, %al
cmpl $0x0, -0x18(%rbp)
movb %al, -0x29(%rbp)
je 0x81f1
movl -0x24(%rbp), %ecx
andl $0x6, %ecx
movb $0x1, %al
cmpl $0x6, %ecx
movb %al, -0x29(%rbp)
je 0x81f1
movl -0x20(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x29(%rbp)
movb -0x29(%rbp), %al
movzbl %al, %eax
andl $0x1, %eax
incl %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
movq %rax, -0x38(%rbp)
subq $0x7, %rax
ja 0x86ed
movq -0x38(%rbp), %rax
leaq 0x4fed(%rip), %rcx      # 0xd208
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x5331(%rip), %rdi      # 0xd55c
leaq 0x532c(%rip), %rsi      # 0xd55e
movl $0x303, %edx            # imm = 0x303
leaq 0x5591(%rip), %rcx      # 0xd7cf
callq 0x20d0
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movw (%rax,%rcx,2), %ax
movl -0x24(%rbp), %edx
movl -0x1c(%rbp), %ecx
cmpl $0x0, -0x18(%rbp)
setne %sil
xorb $-0x1, %sil
andb $0x1, %sil
movzbl %sil, %r8d
movzwl %ax, %esi
callq 0x73f0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x7470
jmp 0x86b5
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movw (%rax,%rcx,2), %ax
movl -0x24(%rbp), %edx
movl -0x1c(%rbp), %ecx
cmpl $0x0, -0x18(%rbp)
setne %sil
xorb $-0x1, %sil
andb $0x1, %sil
movzbl %sil, %r8d
movzwl %ax, %esi
callq 0x73f0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x7470
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
addl -0x28(%rbp), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x22(%rax)
jmp 0x862b
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movw (%rax,%rcx,2), %ax
movl -0x24(%rbp), %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movzwl %ax, %esi
callq 0x73f0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x7470
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
addl $0x2, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x22(%rax)
movq -0x10(%rbp), %rax
movw 0x22(%rax), %dx
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movq -0x10(%rbp), %rdi
callq 0x75e0
cmpl $0x0, %eax
je 0x835d
movl $0x1, -0x4(%rbp)
jmp 0x874d
jmp 0x865e
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
subl -0x28(%rbp), %eax
movl -0x24(%rbp), %edx
movl -0x1c(%rbp), %ecx
cmpl $0x0, -0x18(%rbp)
setne %sil
xorb $-0x1, %sil
andb $0x1, %sil
movzbl %sil, %r8d
movzwl %ax, %esi
callq 0x73f0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x22(%rax)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x7470
jmp 0x862b
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
subl $0x2, %eax
movl -0x24(%rbp), %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movzwl %ax, %esi
callq 0x73f0
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x22(%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x7470
movq -0x10(%rbp), %rax
movw 0x22(%rax), %dx
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movq -0x10(%rbp), %rdi
callq 0x75e0
cmpl $0x0, %eax
je 0x841f
movl $0x1, -0x4(%rbp)
jmp 0x874d
jmp 0x865e
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl $0x7, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movzwl 0xe(%rax), %esi
callq 0x73f0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x7470
movq -0x10(%rbp), %rax
movzwl 0xe(%rax), %eax
addl $0x2, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x22(%rax)
movq -0x10(%rbp), %rax
movw 0x22(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0xe(%rax)
movq -0x10(%rbp), %rdi
callq 0x75e0
cmpl $0x0, %eax
je 0x848d
movl $0x1, -0x4(%rbp)
jmp 0x874d
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw 0xc(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x10(%rbp), %rax
movw %cx, 0x20(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
movq -0x10(%rbp), %rcx
movzwl 0x20(%rcx), %ecx
addl %ecx, %eax
movl -0x24(%rbp), %edx
movl -0x1c(%rbp), %ecx
cmpl $0x0, -0x18(%rbp)
setne %sil
xorb $-0x1, %sil
andb $0x1, %sil
movzbl %sil, %r8d
movzwl %ax, %esi
callq 0x73f0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x7470
jmp 0x86b5
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl $0x7, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movzwl 0xe(%rax), %esi
callq 0x73f0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x7470
movq -0x10(%rbp), %rax
movzwl 0xe(%rax), %eax
addl $0x2, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x22(%rax)
movq -0x10(%rbp), %rax
movw 0x22(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0xe(%rax)
movq -0x10(%rbp), %rdi
callq 0x75e0
cmpl $0x0, %eax
je 0x8561
movl $0x1, -0x4(%rbp)
jmp 0x874d
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw 0xc(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x10(%rbp), %rax
movw %cx, 0x20(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
movq -0x10(%rbp), %rcx
movzwl 0x20(%rcx), %ecx
addl %ecx, %eax
movl -0x24(%rbp), %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movzwl %ax, %esi
callq 0x73f0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x7470
movq -0x10(%rbp), %rdi
callq 0x75e0
cmpl $0x0, %eax
je 0x85cf
movl $0x1, -0x4(%rbp)
jmp 0x874d
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw 0xc(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x10(%rbp), %rax
movw %cx, 0x20(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movw 0x14(%rax), %ax
movl -0x1c(%rbp), %ecx
cmpl $0x0, -0x18(%rbp)
setne %dl
xorb $-0x1, %dl
andb $0x1, %dl
movzbl %dl, %r8d
movl $0xa, %edx
movzwl %ax, %esi
callq 0x73f0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x7470
jmp 0x86b5
movq -0x10(%rbp), %rax
movw 0x22(%rax), %dx
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x92f0
cmpl $0x0, %eax
je 0x865c
movl $0x1, -0x4(%rbp)
jmp 0x874d
jmp 0x86d1
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw 0xc(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x10(%rbp), %rax
movw %cx, 0x20(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movw 0x14(%rax), %ax
movl -0x1c(%rbp), %ecx
cmpl $0x0, -0x18(%rbp)
setne %dl
xorb $-0x1, %dl
andb $0x1, %dl
movzbl %dl, %r8d
movl $0xa, %edx
movzwl %ax, %esi
callq 0x73f0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x7470
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x92f0
cmpl $0x0, %eax
je 0x86cf
movl $0x1, -0x4(%rbp)
jmp 0x874d
jmp 0x86d1
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw 0xc(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x10(%rbp), %rax
movw %cx, 0x20(%rax)
cmpl $0x0, -0x18(%rbp)
je 0x8746
movq -0x10(%rbp), %rax
movzwl 0x24(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x8746
movq -0x10(%rbp), %rax
movzwl 0x20(%rax), %eax
andl $0xff00, %eax           # imm = 0xFF00
movq -0x10(%rbp), %rcx
movzwl 0x20(%rcx), %ecx
sarl $0x8, %ecx
andl $0xff, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x22(%rax)
movq -0x10(%rbp), %rax
movw 0x22(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x10(%rbp), %rax
movw %cx, 0x20(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)