// File: /workspace/github_c_makefile_star2_O1/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
movl -0x4(%rdi), %eax
cmpl $0x2, %eax
jl 0x8341
movl %eax, %ecx
cmpl $0x0, -0x4(%rdi,%rcx,4)
jne 0x8341
leal -0x1(%rax), %ecx
movl %ecx, -0x4(%rdi)
cmpl $0x2, %eax
movl %ecx, %eax
jg 0x832b
movl -0x4(%rbx), %eax
cmpl $0x2, %eax
jl 0x835f
movl %eax, %ecx
cmpl $0x0, -0x4(%rbx,%rcx,4)
jne 0x835f
leal -0x1(%rax), %ecx
movl %ecx, -0x4(%rbx)
cmpl $0x2, %eax
movl %ecx, %eax
jg 0x8349
cmpl $0x1, -0x4(%rbx)
jne 0x836e
cmpl $0x0, (%rbx)
je 0x8511
callq 0x7e34
movq %rax, %r14
movl -0x4(%rax), %r13d
movslq -0x4(%rbx), %r15
movl %r13d, %eax
subl %r15d, %eax
js 0x84ff
movl %r15d, %r12d
leal 0x1(%r12), %ecx
movl %ecx, -0x30(%rbp)
leal 0x8(,%r12,4), %edi
movl %eax, -0x34(%rbp)
callq 0x7810
movq %rax, %rdi
movl 0x35dae(%rip), %eax     # 0x3e15c
movq %rax, -0x40(%rbp)
incl %eax
movl %eax, 0x35da2(%rip)     # 0x3e15c
movl -0x30(%rbp), %eax
movl %eax, (%rdi)
movl -0x4(%rbx,%r15,4), %eax
movq %rax, -0x30(%rbp)
incq %rax
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %r9d
leaq (%r14,%r9,4), %r8
leaq (%r9,%r15), %r11
movslq %r13d, %rax
cmpq %rax, %r11
jg 0x84dc
movslq %r13d, %r10
movl -0x4(%r14,%r10,4), %eax
cmpq %r10, %r11
jge 0x8400
shlq $0x20, %rax
movl -0x8(%r14,%r10,4), %edx
orq %rdx, %rax
cmpq -0x30(%rbp), %rax
jb 0x84dc
testl %r12d, %r12d
jle 0x8440
xorl %edx, %edx
divq -0x48(%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, %r12
jne 0x8424
jmp 0x8442
xorl %edx, %edx
movl %edx, 0x4(%rdi,%r15,4)
cmpq %r10, %r9
jge 0x847e
xorl %eax, %eax
xorl %esi, %esi
movl (%r8,%rax,4), %edx
movl 0x4(%rdi,%rax,4), %ecx
subq %rcx, %rdx
addq %rsi, %rdx
movl %edx, (%r8,%rax,4)
movq %rdx, %rsi
sarq $0x20, %rsi
leaq (%r9,%rax), %rcx
incq %rcx
incq %rax
cmpq %r10, %rcx
jl 0x8450
shrq $0x20, %rdx
jne 0x84ae
movl -0x4(%r14), %eax
cmpl $0x2, %eax
jl 0x849f
movl %eax, %ecx
cmpl $0x0, -0x4(%r14,%rcx,4)
jne 0x849f
leal -0x1(%rax), %ecx
movl %ecx, -0x4(%r14)
cmpl $0x2, %eax
movl %ecx, %eax
jg 0x8487
movslq -0x4(%r14), %r13
cmpq %r13, %r11
jle 0x83e7
jmp 0x84dc
cmpq %r10, %r9
jge 0x84dc
xorl %eax, %eax
xorl %edx, %edx
movl (%r8,%rax,4), %ecx
addq %rdx, %rcx
movl 0x4(%rdi,%rax,4), %edx
addq %rcx, %rdx
movl %edx, (%r8,%rax,4)
shrq $0x20, %rdx
leaq (%r9,%rax), %rcx
incq %rcx
incq %rax
cmpq %r10, %rcx
jl 0x84b7
leaq -0x1(%r9), %rax
addq $-0x4, %r8
testq %r9, %r9
movq %rax, %r9
jg 0x83d7
callq 0x7040
movq -0x40(%rbp), %rax
movl %eax, 0x35c5d(%rip)     # 0x3e15c
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1dc76(%rip), %rdi     # 0x2618e
callq 0x77c8