// File: /workspace/github_c_makefile_star2_O3/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
movl -0x4(%rdi), %eax
cmpl $0x2, %eax
jl 0x80de
movl %eax, %ecx
cmpl $0x0, -0x4(%rdi,%rcx,4)
jne 0x80de
leal -0x1(%rax), %ecx
movl %ecx, -0x4(%rdi)
cmpl $0x2, %eax
movl %ecx, %eax
jg 0x80c8
movl -0x4(%rbx), %r13d
cmpl $0x2, %r13d
jl 0x8106
movl %r13d, %eax
movl %eax, %ecx
cmpl $0x0, -0x4(%rbx,%rcx,4)
jne 0x811d
leal -0x1(%rax), %r13d
movl %r13d, -0x4(%rbx)
cmpl $0x2, %eax
movl %r13d, %eax
jg 0x80eb
jmp 0x810c
cmpl $0x1, %r13d
jne 0x8120
cmpl $0x0, (%rbx)
jne 0x8120
leaq 0x22096(%rip), %rdi     # 0x2a1ae
callq 0x780b
movl %eax, %r13d
movl -0x4(%rdi), %r14d
movl %r14d, %r15d
subl %r13d, %r15d
js 0x835e
callq 0x7e97
movq %rax, -0x40(%rbp)
leal 0x1(%r15), %r12d
leal 0x8(,%r15,4), %edi
callq 0x7853
incl 0x3b00c(%rip)           # 0x4315c
movl %r12d, (%rax)
movq %rax, -0x58(%rbp)
addq $0x4, %rax
movq %rax, -0x30(%rbp)
leal 0x1(%r13), %eax
movl %eax, -0x38(%rbp)
leal 0x8(,%r13,4), %edi
callq 0x7853
movq -0x40(%rbp), %r8
movq %rax, %r12
movl 0x3afdc(%rip), %eax     # 0x4315c
movq %rax, -0x50(%rbp)
incl %eax
movl %eax, 0x3afd0(%rip)     # 0x4315c
movl -0x38(%rbp), %eax
movl %eax, (%r12)
movslq %r13d, %rax
movq %rax, -0x38(%rbp)
movl -0x4(%rbx,%rax,4), %eax
movq %rax, -0x70(%rbp)
incq %rax
movq %rax, -0x60(%rbp)
movl %r15d, %r10d
movq %r13, -0x68(%rbp)
movl %r13d, %r9d
movq -0x30(%rbp), %r13
leaq (%r8,%r10,4), %r11
movq %r8, %rdi
addq $-0x4, %rdi
movl $0x0, (%r13,%r10,4)
movq -0x38(%rbp), %rax
leaq (%r10,%rax), %rdx
movslq %r14d, %rax
cmpq %rax, %rdx
jg 0x8310
xorl %esi, %esi
movq %rdx, -0x48(%rbp)
movslq %r14d, %r15
movl -0x4(%r8,%r15,4), %eax
cmpq %r15, %rdx
jge 0x81fe
shlq $0x20, %rax
movl -0x8(%r8,%r15,4), %ecx
orq %rcx, %rax
cmpq -0x70(%rbp), %rax
jb 0x8310
xorl %ecx, %ecx
xorl %edx, %edx
divq -0x60(%rbp)
cmpl $0x2, %eax
movl $0x1, %edx
cmovbl %edx, %eax
cmpl $0x0, -0x68(%rbp)
jle 0x8248
movl %eax, %edx
xorl %r13d, %r13d
xorl %ecx, %ecx
movl (%rbx,%r13,4), %r8d
imulq %rdx, %r8
addq %r8, %rcx
movl %ecx, 0x4(%r12,%r13,4)
shrq $0x20, %rcx
incq %r13
cmpq %r13, %r9
jne 0x8228
movq -0x40(%rbp), %r8
movq -0x38(%rbp), %rdx
movl %ecx, 0x4(%r12,%rdx,4)
cmpq %r15, %r10
jge 0x828e
xorl %ecx, %ecx
xorl %r13d, %r13d
movl (%r11,%rcx,4), %edx
movl 0x4(%r12,%rcx,4), %r8d
subq %r8, %rdx
addq %r13, %rdx
movl %edx, (%r11,%rcx,4)
movq %rdx, %r13
sarq $0x20, %r13
leaq (%r10,%rcx), %r8
incq %r8
incq %rcx
cmpq %r15, %r8
jl 0x825b
shrq $0x20, %rdx
movq -0x40(%rbp), %r8
jne 0x82d7
addl %eax, %esi
movq -0x30(%rbp), %r13
movl %esi, (%r13,%r10,4)
movl (%rdi), %eax
cmpl $0x2, %eax
jl 0x82bd
movq -0x48(%rbp), %rdx
movl %eax, %ecx
cmpl $0x0, (%rdi,%rcx,4)
jne 0x82c6
leal -0x1(%rax), %r14d
movl %r14d, (%rdi)
cmpl $0x2, %eax
movl %r14d, %eax
jg 0x82a4
jmp 0x82c9
movl %eax, %r14d
movq -0x48(%rbp), %rdx
jmp 0x82c9
movl %eax, %r14d
movslq %r14d, %rax
cmpq %rax, %rdx
jle 0x81e5
jmp 0x8310
cmpq %r15, %r10
jge 0x830c
xorl %eax, %eax
xorl %ecx, %ecx
movq -0x30(%rbp), %r13
movl (%r11,%rax,4), %edx
addq %rcx, %rdx
movl 0x4(%r12,%rax,4), %ecx
addq %rdx, %rcx
movl %ecx, (%r11,%rax,4)
shrq $0x20, %rcx
leaq (%r10,%rax), %rdx
incq %rdx
incq %rax
cmpq %r15, %rdx
jl 0x82e4
jmp 0x8310
movq -0x30(%rbp), %r13
leaq -0x1(%r10), %rax
addq $-0x4, %r11
testq %r10, %r10
movq %rax, %r10
jg 0x81c2
movq -0x58(%rbp), %rdx
movl (%rdx), %eax
cmpl $0x2, %eax
jl 0x8343
movl %eax, %ecx
cmpl $0x0, (%rdx,%rcx,4)
jne 0x8343
leal -0x1(%rax), %ecx
movl %ecx, (%rdx)
cmpl $0x2, %eax
movl %ecx, %eax
jg 0x832f
callq 0x7040
movq %r12, %rdi
callq 0x7040
movq -0x50(%rbp), %rax
decl %eax
movl %eax, 0x3ae00(%rip)     # 0x4315c
jmp 0x8381
movl $0x8, %edi
callq 0x7260
testq %rax, %rax
je 0x8393
movq %rax, %r13
incl 0x3ade6(%rip)           # 0x4315c
movq $0x1, (%rax)
addq $0x4, %r13
movq %r13, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x7330