// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rsi, %rbx
movl -0x4(%rdi), %eax
cmpl $0x2, %eax
jl 0x807b
movl %eax, %ecx
cmpl $0x0, -0x4(%rdi,%rcx,4)
jne 0x807b
leal -0x1(%rax), %ecx
movl %ecx, -0x4(%rdi)
cmpl $0x2, %eax
movl %ecx, %eax
jg 0x8065
movl -0x4(%rbx), %eax
cmpl $0x2, %eax
jl 0x8099
movl %eax, %ecx
cmpl $0x0, -0x4(%rbx,%rcx,4)
jne 0x8099
leal -0x1(%rax), %ecx
movl %ecx, -0x4(%rbx)
cmpl $0x2, %eax
movl %ecx, %eax
jg 0x8083
cmpl $0x1, -0x4(%rbx)
jne 0x80a8
cmpl $0x0, (%rbx)
je 0x82f9
movl -0x4(%rdi), %r12d
movslq -0x4(%rbx), %rax
movl %r12d, %r13d
subl %eax, %r13d
js 0x82ca
movl %eax, %r14d
movq %rax, -0x40(%rbp)
callq 0x7e34
movq %rax, %r15
movq %r13, %rax
movq %r13, -0x30(%rbp)
incl %r13d
leal 0x8(,%rax,4), %edi
callq 0x7810
incl 0x36075(%rip)           # 0x3e15c
movl %r13d, (%rax)
movq %rax, -0x50(%rbp)
movq %rax, %r13
addq $0x4, %r13
leal 0x1(%r14), %eax
movl %eax, -0x38(%rbp)
leal 0x8(,%r14,4), %edi
callq 0x7810
movq %r13, %rsi
movq %rax, %r13
movl 0x36047(%rip), %eax     # 0x3e15c
movq %rax, -0x48(%rbp)
incl %eax
movl %eax, 0x3603b(%rip)     # 0x3e15c
movq -0x40(%rbp), %rax
movl -0x38(%rbp), %ecx
movl %ecx, (%r13)
movl -0x4(%rbx,%rax,4), %ecx
movq %rcx, -0x38(%rbp)
incq %rcx
movq %rcx, -0x58(%rbp)
movl -0x30(%rbp), %r8d
leaq (%r15,%r8,4), %rdi
movq %rsi, -0x30(%rbp)
movl $0x0, (%rsi,%r8,4)
leaq (%r8,%rax), %r10
movslq %r12d, %rax
cmpq %rax, %r10
jg 0x8267
movslq %r12d, %r11
movl -0x4(%r15,%r11,4), %eax
cmpq %r11, %r10
jge 0x8178
shlq $0x20, %rax
movl -0x8(%r15,%r11,4), %edx
orq %rdx, %rax
cmpq -0x38(%rbp), %rax
jb 0x8267
xorl %r9d, %r9d
xorl %edx, %edx
divq -0x58(%rbp)
cmpl $0x2, %eax
movl $0x1, %ecx
cmovbl %ecx, %eax
testl %r14d, %r14d
jle 0x81bd
movl %eax, %edx
xorl %esi, %esi
xorl %r9d, %r9d
movl (%rbx,%rsi,4), %ecx
imulq %rdx, %rcx
addq %rcx, %r9
movl %r9d, 0x4(%r13,%rsi,4)
shrq $0x20, %r9
incq %rsi
cmpq %rsi, %r14
jne 0x81a2
movq -0x40(%rbp), %rcx
movl %r9d, 0x4(%r13,%rcx,4)
cmpq %r11, %r8
jge 0x81fe
xorl %edx, %edx
xorl %esi, %esi
movl (%rdi,%rdx,4), %r9d
movl 0x4(%r13,%rdx,4), %ecx
subq %rcx, %r9
addq %rsi, %r9
movl %r9d, (%rdi,%rdx,4)
movq %r9, %rsi
sarq $0x20, %rsi
leaq (%r8,%rdx), %rcx
incq %rcx
incq %rdx
cmpq %r11, %rcx
jl 0x81cf
shrq $0x20, %r9
jne 0x8236
movq -0x30(%rbp), %rsi
addl %eax, (%rsi,%r8,4)
movl -0x4(%r15), %eax
cmpl $0x2, %eax
jl 0x8227
movl %eax, %ecx
cmpl $0x0, -0x4(%r15,%rcx,4)
jne 0x8227
leal -0x1(%rax), %ecx
movl %ecx, -0x4(%r15)
cmpl $0x2, %eax
movl %ecx, %eax
jg 0x820f
movslq -0x4(%r15), %r12
cmpq %r12, %r10
jle 0x815f
jmp 0x8267
cmpq %r11, %r8
jge 0x8263
xorl %eax, %eax
xorl %edx, %edx
movl (%rdi,%rax,4), %ecx
addq %rdx, %rcx
movl 0x4(%r13,%rax,4), %edx
addq %rcx, %rdx
movl %edx, (%rdi,%rax,4)
shrq $0x20, %rdx
leaq (%r8,%rax), %rcx
incq %rcx
incq %rax
cmpq %r11, %rcx
jl 0x823f
movq -0x30(%rbp), %rsi
leaq -0x1(%r8), %rax
addq $-0x4, %rdi
testq %r8, %r8
movq %rax, %r8
movq -0x40(%rbp), %rax
jg 0x8147
movq -0x50(%rbp), %rdx
movl (%rdx), %eax
cmpl $0x2, %eax
jl 0x829e
movl %eax, %ecx
cmpl $0x0, (%rdx,%rcx,4)
jne 0x829e
leal -0x1(%rax), %ecx
movl %ecx, (%rdx)
cmpl $0x2, %eax
movl %ecx, %eax
jg 0x828a
addq $-0x4, %r15
movq %r15, %rdi
callq 0x7040
movq -0x48(%rbp), %rbx
movl %ebx, 0x35ea8(%rip)     # 0x3e15c
movq %r13, %rdi
callq 0x7040
decl %ebx
movl %ebx, 0x35e98(%rip)     # 0x3e15c
movq -0x30(%rbp), %rax
jmp 0x82ea
movl $0x8, %edi
callq 0x7260
testq %rax, %rax
je 0x8305
incl 0x35e7d(%rip)           # 0x3e15c
movq $0x1, (%rax)
addq $0x4, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1de8e(%rip), %rdi     # 0x2618e
callq 0x77c8
movl $0x1, %edi
callq 0x7330