// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: mmod
uint32_t *
mmod(uint32_t *u, uint32_t *v)
{
	int i, k, nu, nv;
	uint32_t qhat, *w;
	uint64_t a, b, t;
	mnorm(u);
	mnorm(v);
	if (MLENGTH(v) == 1 && v[0] == 0)
		stopf("divide by zero"); // v = 0
	u = mcopy(u);
	nu = MLENGTH(u);
	nv = MLENGTH(v);
	k = nu - nv;
	if (k < 0)
		return u; // u < v
	w = mnew(nv + 1);
	b = v[nv - 1];
	do {
		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;
			}
			mnorm(u);
			nu = MLENGTH(u);
		}
	} while (--k >= 0);
	mfree(w);
	return u;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r14
callq 0x7d16
movq %rbx, %rdi
callq 0x7d16
cmpl $0x1, -0x4(%rbx)
jne 0x8058
cmpl $0x0, (%rbx)
je 0x81c0
movq %r14, %rdi
callq 0x7c9c
movq %rax, %r14
movl -0x4(%rax), %ecx
movslq -0x4(%rbx), %rax
movl %ecx, %r13d
subl %eax, %r13d
js 0x81ae
leal 0x1(%rax), %edi
movq %rax, -0x30(%rbp)
movl %ecx, %r15d
callq 0x7d34
movl %r15d, %r10d
movq -0x30(%rbp), %r9
movq %rax, %r15
movl -0x4(%rbx,%r9,4), %eax
xorl %r12d, %r12d
testl %r9d, %r9d
cmovgl %r9d, %r12d
movq %rax, -0x48(%rbp)
incq %rax
movq %rax, -0x40(%rbp)
movl %r13d, %r13d
leaq (%r14,%r13,4), %rax
movq %rax, -0x38(%rbp)
leaq (%r9,%r13), %rax
movq %rax, -0x50(%rbp)
movslq %r10d, %rcx
cmpq %rcx, -0x50(%rbp)
jg 0x8191
movl -0x4(%r14,%rcx,4), %eax
jge 0x80dc
shlq $0x20, %rax
movl -0x8(%r14,%rcx,4), %edx
orq %rdx, %rax
cmpq -0x48(%rbp), %rax
jb 0x8191
xorl %edx, %edx
divq -0x40(%rbp)
cmpl $0x2, %eax
pushq $0x1
popq %rdx
cmovbl %edx, %eax
xorl %edx, %edx
xorl %esi, %esi
cmpq %rdx, %r12
je 0x8118
movl (%rbx,%rdx,4), %edi
imulq %rax, %rdi
addq %rsi, %rdi
movl %edi, (%r15,%rdx,4)
shrq $0x20, %rdi
incq %rdx
movq %rdi, %rsi
jmp 0x80f9
movl %esi, (%r15,%r9,4)
movq %r15, %rax
movq %r13, %rdx
xorl %esi, %esi
cmpq %rcx, %rdx
jge 0x814a
movl (%r14,%rdx,4), %edi
movl (%rax), %r8d
subq %r8, %rdi
addq %rsi, %rdi
movl %edi, (%r14,%rdx,4)
sarq $0x20, %rdi
incq %rdx
addq $0x4, %rax
movq %rdi, %rsi
jmp 0x8124
testq %rsi, %rsi
jne 0x8164
movq %r14, %rdi
callq 0x7d16
movq -0x30(%rbp), %r9
movl -0x4(%r14), %r10d
jmp 0x80bc
xorl %eax, %eax
xorl %edx, %edx
leaq (%rax,%r13), %rsi
cmpq %rcx, %rsi
jge 0x8191
movq -0x38(%rbp), %rdi
movl (%rdi,%rax,4), %esi
addq %rsi, %rdx
movl (%r15,%rax,4), %esi
addq %rdx, %rsi
movl %esi, (%rdi,%rax,4)
shrq $0x20, %rsi
incq %rax
movq %rsi, %rdx
jmp 0x8168
leaq -0x1(%r13), %rax
addq $-0x4, -0x38(%rbp)
testq %r13, %r13
movq %rax, %r13
jg 0x80b4
movq %r15, %rdi
callq 0x7ad9
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b01f(%rip), %rdi     # 0x231e6
callq 0x7756