// File: /workspace/github_c_makefile_star2_O0/cyb70289[P]tt/src/apn/integer/mod.c
// Function: tt_int_mont_reduce
int _tt_int_mont_reduce(_tt_word *r, int *msbr, const _tt_word *c, int msbc,
		const _tt_word *u, int msbu, const _tt_word *n, int msbn,
		_tt_word *t)
{
	tt_assert_fa(msbc <= msbn*2);

	/* q = u*c % lambda (TODO: drop 1/4 calculation) */
	_tt_word *q = t;
	memset(q, 0, msbn*2*_tt_word_sz);
	int msbq = _tt_int_mul_buf(q, u, msbu, c, _tt_min(msbc, msbn));
	if (msbq > msbn)
		msbq = _tt_int_get_msb(q, msbn);
	/* Q = c + q*n */
	_tt_word *Q = q + msbq;
	memset(Q, 0, msbn*2*_tt_word_sz);
	int msbQ = _tt_int_mul_buf(Q, q, msbq, n, msbn);
	msbQ = _tt_int_add_buf(Q, msbQ, c, msbc);
	/* r = Q / lambda */
	memset(r, 0, (msbn+1)*_tt_word_sz);
	*msbr = 1;
	if (msbQ > msbn) {
		*msbr = msbQ - msbn;
		memcpy(r, Q+msbn, (*msbr)*_tt_word_sz);
	}
	if (_tt_int_cmp_buf(r, *msbr, n, msbn) >= 0)
		*msbr = _tt_int_sub_buf(r, *msbr, n, msbn);

	tt_assert_fa(_tt_int_cmp_buf(r, *msbr, n, msbn) < 0);

	return 0;
}

// Assembly:
subq $0x88, %rsp
movq 0xa0(%rsp), %rax
movl 0x98(%rsp), %eax
movq 0x90(%rsp), %rax
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdx, 0x70(%rsp)
movl %ecx, 0x6c(%rsp)
movq %r8, 0x60(%rsp)
movl %r9d, 0x5c(%rsp)
movl 0x6c(%rsp), %eax
movl 0x98(%rsp), %ecx
shll %ecx
cmpl %ecx, %eax
setle %al
xorb $-0x1, %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0xcc7c
xorl %edi, %edi
leaq 0x11cce(%rip), %rsi     # 0x1e92a
leaq 0x547b(%rip), %rdx      # 0x120de
leaq 0x11cd4(%rip), %rcx     # 0x1e93e
movl $0x26, %r8d
movb $0x0, %al
callq 0xe010
callq 0x1060
jmp 0xcc7e
movq 0xa0(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rdi
movl 0x98(%rsp), %eax
shll %eax
shll $0x3, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x18(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x28(%rsp)
movl 0x6c(%rsp), %eax
movl %eax, 0x48(%rsp)
movl 0x98(%rsp), %eax
movl %eax, 0x44(%rsp)
movl 0x48(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0xccf3
movl 0x48(%rsp), %eax
movl %eax, 0xc(%rsp)
jmp 0xccfb
movl 0x44(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rcx
movl 0x24(%rsp), %edx
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdi
movl 0xc(%rsp), %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %r8d
callq 0x8be0
movl %eax, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x98(%rsp), %eax
jle 0xcd46
movq 0x50(%rsp), %rdi
movl 0x98(%rsp), %esi
callq 0x8b90
movl %eax, 0x4c(%rsp)
movq 0x50(%rsp), %rax
movslq 0x4c(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movl 0x98(%rsp), %eax
shll %eax
shll $0x3, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movq 0x38(%rsp), %rdi
movq 0x50(%rsp), %rsi
movl 0x4c(%rsp), %edx
movq 0x90(%rsp), %rcx
movl 0x98(%rsp), %r8d
callq 0x8be0
movl %eax, 0x34(%rsp)
movq 0x38(%rsp), %rdi
movl 0x34(%rsp), %esi
movq 0x70(%rsp), %rdx
movl 0x6c(%rsp), %ecx
callq 0x87d0
movl %eax, 0x34(%rsp)
movq 0x80(%rsp), %rdi
movl 0x98(%rsp), %eax
addl $0x1, %eax
shll $0x3, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movq 0x78(%rsp), %rax
movl $0x1, (%rax)
movl 0x34(%rsp), %eax
cmpl 0x98(%rsp), %eax
jle 0xce30
movl 0x34(%rsp), %ecx
subl 0x98(%rsp), %ecx
movq 0x78(%rsp), %rax
movl %ecx, (%rax)
movq 0x80(%rsp), %rdi
movq 0x38(%rsp), %rsi
movslq 0x98(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movq 0x78(%rsp), %rax
movl (%rax), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rax
movl (%rax), %esi
movq 0x90(%rsp), %rdx
movl 0x98(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
jl 0xce84
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rax
movl (%rax), %esi
movq 0x90(%rsp), %rdx
movl 0x98(%rsp), %ecx
callq 0x8940
movl %eax, %ecx
movq 0x78(%rsp), %rax
movl %ecx, (%rax)
jmp 0xce86
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rax
movl (%rax), %esi
movq 0x90(%rsp), %rdx
movl 0x98(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
setl %al
xorb $-0x1, %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0xceeb
xorl %edi, %edi
leaq 0x11a5f(%rip), %rsi     # 0x1e92a
leaq 0x520c(%rip), %rdx      # 0x120de
leaq 0x11a65(%rip), %rcx     # 0x1e93e
movl $0x3d, %r8d
movb $0x0, %al
callq 0xe010
callq 0x1060
jmp 0xceed
xorl %eax, %eax
addq $0x88, %rsp
retq
nopw (%rax,%rax)