// File: /workspace/github_c_makefile_star2_O0/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
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8270
movq -0x18(%rbp), %rdi
callq 0x8270
movq -0x18(%rbp), %rax
cmpl $0x1, -0x4(%rax)
jne 0x84b1
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x84b1
leaq 0x3ccb2(%rip), %rdi     # 0x4515e
callq 0x78d0
movq -0x10(%rbp), %rax
movl -0x4(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movl -0x4(%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
subl -0x28(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x84f9
movl $0x1, %edi
callq 0x82c0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x8763
movq -0x10(%rbp), %rdi
callq 0x8170
movq %rax, -0x10(%rbp)
movl -0x20(%rbp), %edi
addl $0x1, %edi
callq 0x82c0
movq %rax, -0x30(%rbp)
movl -0x28(%rbp), %edi
addl $0x1, %edi
callq 0x82c0
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
movl -0x28(%rbp), %ecx
addl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jl 0x872c
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x48(%rbp)
movl -0x24(%rbp), %eax
movl -0x28(%rbp), %ecx
addl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jle 0x8598
movq -0x48(%rbp), %rax
shlq $0x20, %rax
movq -0x10(%rbp), %rcx
movl -0x24(%rbp), %edx
subl $0x2, %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
orq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x85a7
jmp 0x872c
movq -0x48(%rbp), %rax
movq -0x50(%rbp), %rcx
addq $0x1, %rcx
xorl %edx, %edx
divq %rcx
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x85c8
movl $0x1, -0x34(%rbp)
movq $0x0, -0x58(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x8621
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
imulq %rcx, %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl %eax, %edx
movq -0x40(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x58(%rbp), %rax
shrq $0x20, %rax
movq %rax, -0x58(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x85d7
movq -0x58(%rbp), %rax
movl %eax, %edx
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq $0x0, -0x58(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x8696
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x40(%rbp), %rcx
movl -0x1c(%rbp), %edx
subl -0x20(%rbp), %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
subq %rcx, %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x58(%rbp), %rax
sarq $0x20, %rax
movq %rax, -0x58(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x8640
cmpq $0x0, -0x58(%rbp)
je 0x8703
movq $0x0, -0x58(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x8701
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x40(%rbp), %rcx
movl -0x1c(%rbp), %edx
subl -0x20(%rbp), %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
addq %rcx, %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x58(%rbp), %rax
shrq $0x20, %rax
movq %rax, -0x58(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x86ab
jmp 0x872c
movl -0x34(%rbp), %edx
movq -0x30(%rbp), %rax
movslq -0x20(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rdi
callq 0x8270
movq -0x10(%rbp), %rax
movl -0x4(%rax), %eax
movl %eax, -0x24(%rbp)
jmp 0x8547
jmp 0x872e
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, %eax
jge 0x8538
movq -0x30(%rbp), %rdi
callq 0x8270
movq -0x10(%rbp), %rdi
callq 0x7e70
movq -0x40(%rbp), %rdi
callq 0x7e70
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)