// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %rsi, %rbx
movl -0x4(%rdi), %eax
cmpl $0x2, %eax
jl 0x83cf
movl %eax, %ecx
cmpl $0x0, -0x4(%rdi,%rcx,4)
jne 0x83cf
leal -0x1(%rax), %ecx
movl %ecx, -0x4(%rdi)
cmpl $0x2, %eax
movl %ecx, %eax
jg 0x83b9
movl -0x4(%rbx), %eax
cmpl $0x2, %eax
jl 0x83ef
movl %eax, %ecx
cmpl $0x0, -0x4(%rbx,%rcx,4)
jne 0x83fd
leal -0x1(%rax), %ecx
movl %ecx, -0x4(%rbx)
cmpl $0x2, %eax
movl %ecx, %eax
jg 0x83d7
jmp 0x83f4
cmpl $0x1, %eax
jne 0x83fd
cmpl $0x0, (%rbx)
je 0x859b
callq 0x7e97
movq %rax, %r14
movl -0x4(%rax), %r13d
movslq -0x4(%rbx), %r15
movl %r13d, %r12d
subl %r15d, %r12d
js 0x8589
leal 0x1(%r15), %eax
movl %eax, -0x30(%rbp)
leal 0x8(,%r15,4), %edi
callq 0x7853
movq %rax, %rdi
movl 0x3ad26(%rip), %eax     # 0x4315c
movq %rax, -0x38(%rbp)
incl %eax
movl %eax, 0x3ad1a(%rip)     # 0x4315c
movl -0x30(%rbp), %eax
movl %eax, (%rdi)
movl -0x4(%rbx,%r15,4), %eax
movq %rax, -0x30(%rbp)
incq %rax
movq %rax, -0x40(%rbp)
movl %r12d, %r9d
movl %r15d, %r8d
leaq (%r14,%r9,4), %r10
leaq (%r9,%r15), %r12
movslq %r13d, %rax
cmpq %rax, %r12
jg 0x8566
movslq %r13d, %r11
movl -0x4(%r14,%r11,4), %eax
cmpq %r11, %r12
jge 0x848a
shlq $0x20, %rax
movl -0x8(%r14,%r11,4), %edx
orq %rdx, %rax
cmpq -0x30(%rbp), %rax
jb 0x8566
testl %r15d, %r15d
jle 0x84ca
xorl %edx, %edx
divq -0x40(%rbp)
cmpl $0x2, %eax
movl $0x1, %ecx
cmovbl %ecx, %eax
xorl %esi, %esi
xorl %edx, %edx
movl (%rbx,%rsi,4), %ecx
imulq %rax, %rcx
addq %rcx, %rdx
movl %edx, 0x4(%rdi,%rsi,4)
shrq $0x20, %rdx
incq %rsi
cmpq %rsi, %r8
jne 0x84ae
jmp 0x84cc
xorl %edx, %edx
movl %edx, 0x4(%rdi,%r15,4)
cmpq %r11, %r9
jge 0x8508
xorl %eax, %eax
xorl %esi, %esi
movl (%r10,%rax,4), %edx
movl 0x4(%rdi,%rax,4), %ecx
subq %rcx, %rdx
addq %rsi, %rdx
movl %edx, (%r10,%rax,4)
movq %rdx, %rsi
sarq $0x20, %rsi
leaq (%r9,%rax), %rcx
incq %rcx
incq %rax
cmpq %r11, %rcx
jl 0x84da
shrq $0x20, %rdx
jne 0x8538
movl -0x4(%r14), %eax
cmpl $0x2, %eax
jl 0x8530
movl %eax, %ecx
cmpl $0x0, -0x4(%r14,%rcx,4)
jne 0x8530
leal -0x1(%rax), %r13d
movl %r13d, -0x4(%r14)
cmpl $0x2, %eax
movl %r13d, %eax
jg 0x8511
jmp 0x8465
movl %eax, %r13d
jmp 0x8465
cmpq %r11, %r9
jge 0x8566
xorl %eax, %eax
xorl %edx, %edx
movl (%r10,%rax,4), %ecx
addq %rdx, %rcx
movl 0x4(%rdi,%rax,4), %edx
addq %rcx, %rdx
movl %edx, (%r10,%rax,4)
shrq $0x20, %rdx
leaq (%r9,%rax), %rcx
incq %rcx
incq %rax
cmpq %r11, %rcx
jl 0x8541
leaq -0x1(%r9), %rax
addq $-0x4, %r10
testq %r9, %r9
movq %rax, %r9
jg 0x8461
callq 0x7040
movq -0x38(%rbp), %rax
movl %eax, 0x3abd3(%rip)     # 0x4315c
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x21c0c(%rip), %rdi     # 0x2a1ae
callq 0x780b