// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movzwl (%rax), %eax
shll $0x10, %eax
movq -0x8(%rbp), %rcx
movzwl 0x2(%rcx), %ecx
orl %ecx, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movzwl 0x4(%rax), %eax
shll $0x10, %eax
movl %eax, -0x10(%rbp)
movw $0x0, -0x12(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x7(%rax), %ecx
andl $-0x2, %ecx
movb %cl, 0x7(%rax)
movl -0xc(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movb $0x10, 0x6(%rax)
movl -0x10(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
movl -0xc(%rbp), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
cmpl %ecx, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
shrl %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
andl $0x40000000, %eax       # imm = 0x40000000
cmpl $0x0, %eax
je 0x650c
movl -0x10(%rbp), %eax
orl $0x80000000, %eax       # imm = 0x80000000
movl %eax, -0x10(%rbp)
movzwl -0x12(%rbp), %eax
shll %eax
movw %ax, -0x12(%rbp)
movl -0x18(%rbp), %ecx
movzwl -0x12(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x12(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x653a
movl -0x10(%rbp), %eax
xorl $-0x1, %eax
addl $0x1, %eax
addl -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0x6543
movl -0x10(%rbp), %eax
addl -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x6(%rax), %eax
cmpl $0x10, %eax
jne 0x6578
cmpl $0x0, -0xc(%rbp)
je 0x6578
movl -0xc(%rbp), %eax
shrl $0x1f, %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cmpl -0x1c(%rbp), %eax
jne 0x6578
jmp 0x6670
movq -0x8(%rbp), %rax
movb 0x6(%rax), %cl
addb $-0x1, %cl
movb %cl, 0x6(%rax)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x6(%rax)
jne 0x64ce
cmpl $0x0, -0xc(%rbp)
je 0x65d0
movl -0xc(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x10(%rbp), %edi
callq 0x7040
movl %eax, %ecx
movl -0x24(%rbp), %eax
addl %ecx, %eax
cmpl $0x0, %eax
je 0x65f0
movl -0xc(%rbp), %eax
shrl $0x1f, %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cmpl -0x1c(%rbp), %eax
jne 0x65f0
movl $0x1, -0x18(%rbp)
movzwl -0x12(%rbp), %eax
shll %eax
movw %ax, -0x12(%rbp)
movl -0x18(%rbp), %ecx
movzwl -0x12(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x12(%rbp)
jmp 0x664c
movl -0xc(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
movl -0x10(%rbp), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
cmpl %ecx, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x6625
movl -0x10(%rbp), %eax
xorl $-0x1, %eax
addl $0x1, %eax
addl -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0x662e
movl -0x10(%rbp), %eax
addl -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0x18(%rbp), %ecx
movzwl -0x12(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x12(%rbp)
movl $0x0, -0x18(%rbp)
movzwl -0x12(%rbp), %eax
shll %eax
movw %ax, -0x12(%rbp)
movl -0x10(%rbp), %eax
shrl $0x1f, %eax
andl $0x1, %eax
movzwl -0x12(%rbp), %ecx
sarl $0xf, %ecx
andl $0x1, %ecx
cmpl %ecx, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
cmpl -0x1c(%rbp), %eax
je 0x6677
jmp 0x6670
movl $0x1, -0x20(%rbp)
movl -0xc(%rbp), %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, (%rax)
movw -0x12(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl 0x7(%rcx), %ecx
sarl $0x6, %ecx
andl $0x1, %ecx
cmpl %ecx, %eax
setne %al
andb $0x1, %al
movzbl %al, %edx
movl $0x80, %esi
callq 0x7070
movq -0x8(%rbp), %rdi
callq 0x6f40
cmpl $0x0, -0x20(%rbp)
je 0x66d9
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %edx
movl $0x40, %esi
callq 0x7070
addq $0x30, %rsp
popq %rbp
retq
nop