// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: mdiv
uint32_t *
mdiv(uint32_t *u, uint32_t *v)
{
	int i, k, nu, nv;
	uint32_t *q, qhat, *w;
	uint64_t a, b, t;
	mnorm(u);
	mnorm(v);
	if (MLENGTH(v) == 1 && v[0] == 0)
		stopf("divide by zero"); // v = 0
	nu = MLENGTH(u);
	nv = MLENGTH(v);
	k = nu - nv;
	if (k < 0) {
		q = mnew(1);
		q[0] = 0;
		return q; // u < v, return zero
	}
	u = mcopy(u);
	q = mnew(k + 1);
	w = mnew(nv + 1);
	b = v[nv - 1];
	do {
		q[k] = 0;
		while (nu >= nv + k) {
			// estimate 32-bit partial quotient
			a = u[nu - 1];
			if (nu > nv + k)
				a = a << 32 | u[nu - 2];
			if (a < b)
				break;
			qhat = (uint32_t) (a / (b + 1));
			if (qhat == 0)
				qhat = 1;
			// w = qhat * v
			t = 0;
			for (i = 0; i < nv; i++) {
				t += (uint64_t) qhat * v[i];
				w[i] = (uint32_t) t;
				t >>= 32;
			}
			w[nv] = (uint32_t) t;
			// u = u - w
			t = 0;
			for (i = k; i < nu; i++) {
				t += (uint64_t) u[i] - w[i - k];
				u[i] = (uint32_t) t;
				t = (int64_t) t >> 32; // cast to extend sign
			}
			if (t) {
				// u is negative, restore u
				t = 0;
				for (i = k; i < nu; i++) {
					t += (uint64_t) u[i] + w[i - k];
					u[i] = (uint32_t) t;
					t >>= 32;
				}
				break;
			}
			q[k] += qhat;
			mnorm(u);
			nu = MLENGTH(u);
		}
	} while (--k >= 0);
	mnorm(q);
	mfree(u);
	mfree(w);
	return q;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r14
callq 0x7d16
movq %rbx, %rdi
callq 0x7d16
movslq -0x4(%rbx), %rax
cmpq $0x1, %rax
jne 0x7e57
cmpl $0x0, (%rbx)
je 0x8019
movl -0x4(%r14), %r12d
movl %r12d, %r13d
subl %eax, %r13d
js 0x7fff
movq %r14, %rdi
movq %rax, -0x30(%rbp)
callq 0x7c9c
movq %rax, %r15
leal 0x1(%r13), %edi
callq 0x7d34
movq %rax, %r14
movq -0x30(%rbp), %rax
leal 0x1(%rax), %edi
callq 0x7d34
movl %r12d, %r8d
movq %r14, %rdi
movq -0x30(%rbp), %rcx
movq %rax, %r12
movl -0x4(%rbx,%rcx,4), %eax
xorl %r14d, %r14d
testl %ecx, %ecx
cmovgl %ecx, %r14d
movq %rax, -0x58(%rbp)
incq %rax
movq %rax, -0x50(%rbp)
movl %r13d, %r9d
leaq (%r15,%r9,4), %rax
movq %rax, -0x48(%rbp)
movq %rdi, -0x40(%rbp)
andl $0x0, (%rdi,%r9,4)
movq -0x30(%rbp), %rax
addq %r9, %rax
movq %rax, -0x68(%rbp)
xorl %r13d, %r13d
movq %r9, -0x60(%rbp)
movslq %r8d, %rcx
cmpq %rcx, -0x68(%rbp)
jg 0x7fcf
movl -0x4(%r15,%rcx,4), %eax
jge 0x7ef9
shlq $0x20, %rax
movl -0x8(%r15,%rcx,4), %edx
orq %rdx, %rax
cmpq -0x58(%rbp), %rax
jb 0x7fcf
movl %r8d, -0x34(%rbp)
xorl %edx, %edx
divq -0x50(%rbp)
cmpl $0x2, %eax
pushq $0x1
popq %rdx
cmovbl %edx, %eax
xorl %edx, %edx
xorl %esi, %esi
cmpq %rdx, %r14
je 0x7f3a
movl (%rbx,%rdx,4), %r8d
imulq %rax, %r8
addq %rsi, %r8
movl %r8d, (%r12,%rdx,4)
shrq $0x20, %r8
incq %rdx
movq %r8, %rsi
jmp 0x7f1a
movq -0x30(%rbp), %rdx
movl %esi, (%r12,%rdx,4)
movq %r12, %rdx
movq %r9, %r10
movq %r9, %rsi
xorl %r11d, %r11d
cmpq %rcx, %rsi
jge 0x7f74
movl (%r15,%rsi,4), %r8d
movl (%rdx), %r9d
subq %r9, %r8
addq %r11, %r8
movl %r8d, (%r15,%rsi,4)
sarq $0x20, %r8
incq %rsi
addq $0x4, %rdx
movq %r8, %r11
jmp 0x7f4e
testq %r11, %r11
jne 0x7f99
addl %eax, %r13d
movl %r13d, (%rdi,%r10,4)
movq %r15, %rdi
callq 0x7d16
movq -0x60(%rbp), %r9
movq -0x40(%rbp), %rdi
movl -0x4(%r15), %r8d
jmp 0x7ed9
xorl %eax, %eax
xorl %edx, %edx
movl -0x34(%rbp), %r8d
movq %r10, %r9
leaq (%r9,%rax), %rsi
cmpq %rcx, %rsi
jge 0x7fcf
movq -0x48(%rbp), %r10
movl (%r10,%rax,4), %esi
addq %rsi, %rdx
movl (%r12,%rax,4), %esi
addq %rdx, %rsi
movl %esi, (%r10,%rax,4)
shrq $0x20, %rsi
incq %rax
movq %rsi, %rdx
jmp 0x7fa4
leaq -0x1(%r9), %rax
addq $-0x4, -0x48(%rbp)
testq %r9, %r9
movq %rax, %r9
jg 0x7ec2
callq 0x7d16
movq %r15, %rdi
callq 0x7ad9
movq %r12, %rdi
callq 0x7ad9
movq -0x40(%rbp), %rax
jmp 0x800a
pushq $0x1
popq %rdi
callq 0x7d34
andl $0x0, (%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b1c6(%rip), %rdi     # 0x231e6
callq 0x7756