// File: /workspace/github_c_makefile_star2_O0/cyb70289[P]tt/tests/number.c
// Function: test_mont
void test_mont(int nl)
{
	struct tt_int *n = rand_int(nl);
	n->buf[0] |= 1;

	int l = _tt_rand() % nl;
	if (l == 0)
		l = 1;
	struct tt_int *a = rand_int(l);
	l = _tt_rand() % nl;
	if (l == 0)
		l = 1;
	struct tt_int *b = rand_int(l);

	/* lambda = (2^31)^(n->msb), (2^63)^(n->msb) */
	struct tt_int *lambda = tt_int_alloc();
	_tt_int_realloc(lambda, n->msb+1);
	lambda->buf[n->msb] = 1;
	lambda->msb = n->msb+1;

	/* u = -1/n % lambda */
	struct tt_int *u = tt_int_alloc();
	tt_int_mod_inv(u, n, lambda);
	if (u->sign == 0)
		tt_int_sub(u, lambda, u);

	/* c = (a * b * lambda) % n */
	struct tt_int *c = tt_int_alloc();
	tt_int_mul(c, a, b);
	tt_int_mul(c, c, lambda);
	tt_int_div(NULL, c, c, n);

	/* a = (a * lambda) % n, b = (b * lambda) % n */
	tt_int_mul(a, a, lambda);
	tt_int_div(NULL, a, a, n);
	tt_int_mul(b, b, lambda);
	tt_int_div(NULL, b, b, n);

	/* d = montgomery(a * b) */
	struct tt_int *d = tt_int_alloc();
	tt_int_mul(d, a, b);
	_tt_int_realloc(d, n->msb*2+1);

	_tt_word *t = malloc((n->msb+1)*3*_tt_word_sz);
	_tt_int_mont_reduce(d->buf, &d->msb, d->buf, d->msb,
			u->buf, u->msb, n->buf, n->msb, t);

	/* c == d? */
	if (_tt_int_cmp_buf(c->buf, c->msb, d->buf, d->msb))
		tt_error("Montgomery failed!");

	free(t);
	tt_int_free(a);
	tt_int_free(b);
	tt_int_free(n);
	tt_int_free(lambda);
	tt_int_free(u);
	tt_int_free(c);
	tt_int_free(d);
}

// Assembly:
subq $0x68, %rsp
movl %edi, 0x64(%rsp)
movl 0x64(%rsp), %edi
callq 0x16f0
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rcx
orq $0x1, %rcx
movq %rcx, (%rax)
callq 0xeb40
xorl %edx, %edx
divl 0x64(%rsp)
movl %edx, 0x54(%rsp)
cmpl $0x0, 0x54(%rsp)
jne 0x1a07
movl $0x1, 0x54(%rsp)
movl 0x54(%rsp), %edi
callq 0x16f0
movq %rax, 0x48(%rsp)
callq 0xeb40
xorl %edx, %edx
divl 0x64(%rsp)
movl %edx, 0x54(%rsp)
cmpl $0x0, 0x54(%rsp)
jne 0x1a33
movl $0x1, 0x54(%rsp)
movl 0x54(%rsp), %edi
callq 0x16f0
movq %rax, 0x40(%rsp)
callq 0x6800
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movq 0x58(%rsp), %rax
movl 0x8(%rax), %esi
addl $0x1, %esi
callq 0x68d0
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x58(%rsp), %rcx
movslq 0x8(%rcx), %rcx
movq $0x1, (%rax,%rcx,8)
movq 0x58(%rsp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x8(%rax)
callq 0x6800
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0xcb90
movq 0x30(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x1ac9
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0xa890
callq 0x6800
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0xa8c0
movq 0x28(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0xa8c0
movq 0x28(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x58(%rsp), %rcx
xorl %eax, %eax
movl %eax, %edi
callq 0xaa80
movq 0x48(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0xa8c0
movq 0x48(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0x58(%rsp), %rcx
xorl %eax, %eax
movl %eax, %edi
callq 0xaa80
movq 0x40(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0xa8c0
movq 0x40(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x58(%rsp), %rcx
xorl %eax, %eax
movl %eax, %edi
callq 0xaa80
callq 0x6800
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0xa8c0
movq 0x20(%rsp), %rdi
movq 0x58(%rsp), %rax
movl 0x8(%rax), %esi
shll %esi
addl $0x1, %esi
callq 0x68d0
movq 0x58(%rsp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
imull $0x3, %eax, %eax
shll $0x3, %eax
movslq %eax, %rdi
callq 0x1160
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x20(%rsp), %rsi
addq $0x8, %rsi
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rdx
movq 0x20(%rsp), %rax
movl 0x8(%rax), %ecx
movq 0x30(%rsp), %rax
movq 0x10(%rax), %r8
movq 0x30(%rsp), %rax
movl 0x8(%rax), %r9d
movq 0x58(%rsp), %rax
movq 0x10(%rax), %r11
movq 0x58(%rsp), %rax
movl 0x8(%rax), %r10d
movq 0x18(%rsp), %rax
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0xcbf0
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x28(%rsp), %rax
movl 0x8(%rax), %esi
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rdx
movq 0x20(%rsp), %rax
movl 0x8(%rax), %ecx
callq 0x8ad0
cmpl $0x0, %eax
je 0x1c60
xorl %edi, %edi
leaq 0x10465(%rip), %rsi     # 0x120b7
leaq 0x10468(%rip), %rdx     # 0x120c1
movb $0x0, %al
callq 0xe010
movq 0x18(%rsp), %rdi
callq 0x1030
movq 0x48(%rsp), %rdi
callq 0x68b0
movq 0x40(%rsp), %rdi
callq 0x68b0
movq 0x58(%rsp), %rdi
callq 0x68b0
movq 0x38(%rsp), %rdi
callq 0x68b0
movq 0x30(%rsp), %rdi
callq 0x68b0
movq 0x28(%rsp), %rdi
callq 0x68b0
movq 0x20(%rsp), %rdi
callq 0x68b0
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)