// File: /workspace/github_c_makefile_star2_O0/cyb70289[P]tt/src/apn/integer/prime.c
// Function: isprime_miller_rabin_1
static bool isprime_miller_rabin_1(const _tt_word *n, int msbn,
		_tt_word *r, int msbr, const _tt_word *m, int msbm, int k,
		const _tt_word *u, int msbu, const _tt_word *w, int msbw,
		_tt_word *t)
{
	int msbx, msbt;
	const int tsz = (msbn + 2) * 2 * _tt_word_sz;
	const int xsz = (msbn + 2) * _tt_word_sz;
	_tt_word *x = t + tsz / _tt_word_sz;
	_tt_word *buf = x + xsz / _tt_word_sz;	/* (msbn+2)*3 words */
	const int rsz = xsz;

	/* x = r */
	msbx = msbr;
	memcpy(x, r, msbr*_tt_word_sz);

	/* x = r^m % n */
	for (int i = msbm-1; i >= 0; i--) {
		_tt_word tmp = m[i];

		int bits = _tt_word_bits;
		if (i == msbm-1) {
			bits = _tt_int_word_bits(tmp) - 1;
			tmp <<= (_tt_word_bits - bits);
		}

		while (bits--) {
			/* x = x^2 % n */
			memset(t, 0, tsz);
			msbt = _tt_int_mul_buf(t, x, msbx, x, msbx);
			_tt_int_mont_reduce(t, &msbx, t, msbt, u, msbu,
					n, msbn, buf);
			memcpy(x, t, msbx*_tt_word_sz);

			if (tmp & (_tt_word_top_bit >> 1)) {
				/* x = (x * r) % n */
				memset(t, 0, tsz);
				msbt = _tt_int_mul_buf(t, x, msbx, r, msbr);
				_tt_int_mont_reduce(t, &msbx, t, msbt, u, msbu,
						n, msbn, buf);
				memcpy(x, t, msbx*_tt_word_sz);
			}
			memset(x+msbx, 0, xsz-msbx*_tt_word_sz);

			tmp <<= 1;
		}
	}

	/* r = n-1 -> n-lambda%n */
	memcpy(r, n, msbn*_tt_word_sz);
	memset(r+msbn, 0, rsz-msbn*_tt_word_sz);
	msbr = _tt_int_sub_buf(r, msbn, w, msbw);

	/* prime: x == 1 -> x == lambda%n */
	if (_tt_int_cmp_buf(x, msbx, w, msbw) == 0)
		return true;
	/* prime: x == n-1 -> x == n-lambda%n */
	if (_tt_int_cmp_buf(x, msbx, r, msbr) == 0)
		return true;

	while (--k) {
		/* x = x^2 % n */
		memset(t, 0, tsz);
		msbt = _tt_int_mul_buf(t, x, msbx, x, msbx);
		_tt_int_mont_reduce(t, &msbx, t, msbt, u, msbu, n, msbn, buf);
		memcpy(x, t, msbx*_tt_word_sz);
		memset(x+msbx, 0, xsz-msbx*_tt_word_sz);

		/* composite: x == 1 -> x == lambda%n */
		if (_tt_int_cmp_buf(x, msbx, w, msbw) == 0)
			return false;
		/* prime: x == n-1 -> x == n-lambda%n */
		if (_tt_int_cmp_buf(x, msbx, r, msbr) == 0)
			return true;
	}

	/* composite */
	return false;
}

// Assembly:
subq $0x98, %rsp
movq 0xc8(%rsp), %rax
movl 0xc0(%rsp), %eax
movq 0xb8(%rsp), %rax
movl 0xb0(%rsp), %eax
movq 0xa8(%rsp), %rax
movl 0xa0(%rsp), %eax
movq %rdi, 0x88(%rsp)
movl %esi, 0x84(%rsp)
movq %rdx, 0x78(%rsp)
movl %ecx, 0x74(%rsp)
movq %r8, 0x68(%rsp)
movl %r9d, 0x64(%rsp)
movl 0x84(%rsp), %eax
addl $0x2, %eax
shll %eax
shll $0x3, %eax
movl %eax, 0x58(%rsp)
movl 0x84(%rsp), %eax
addl $0x2, %eax
shll $0x3, %eax
movl %eax, 0x54(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x18(%rsp)
movl 0x58(%rsp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x18(%rsp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0x54(%rsp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x20(%rsp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x40(%rsp)
movl 0x54(%rsp), %eax
movl %eax, 0x3c(%rsp)
movl 0x74(%rsp), %eax
movl %eax, 0x60(%rsp)
movq 0x48(%rsp), %rdi
movq 0x78(%rsp), %rsi
movl 0x74(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movl 0x64(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x38(%rsp)
cmpl $0x0, 0x38(%rsp)
jl 0xdb9e
movq 0x68(%rsp), %rax
movslq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x30(%rsp)
movl $0x3f, 0x2c(%rsp)
movl 0x38(%rsp), %eax
movl 0x64(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0xd9d7
movq 0x30(%rsp), %rdi
callq 0x6aa0
subl $0x1, %eax
movl %eax, 0x2c(%rsp)
movl $0x3f, %ecx
subl 0x2c(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, %ecx
shlq %cl, %rax
movq %rax, 0x30(%rsp)
jmp 0xd9d9
movl 0x2c(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0x2c(%rsp)
cmpl $0x0, %eax
je 0xdb8c
movq 0xc8(%rsp), %rdi
movslq 0x58(%rsp), %rdx
xorl %esi, %esi
callq 0x10e0
movq 0xc8(%rsp), %rdi
movq 0x48(%rsp), %rsi
movl 0x60(%rsp), %edx
movq 0x48(%rsp), %rcx
movl 0x60(%rsp), %r8d
callq 0x8be0
movl %eax, 0x5c(%rsp)
movq 0xc8(%rsp), %rdi
movq 0xc8(%rsp), %rdx
movl 0x5c(%rsp), %ecx
movq 0xa8(%rsp), %r8
movl 0xb0(%rsp), %r9d
movq 0x88(%rsp), %r11
movl 0x84(%rsp), %r10d
movq 0x40(%rsp), %rax
leaq 0x60(%rsp), %rsi
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0xcbf0
movq 0x48(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movl 0x60(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
andq 0x30(%rsp), %rax
cmpq $0x0, %rax
je 0xdb52
movq 0xc8(%rsp), %rdi
movslq 0x58(%rsp), %rdx
xorl %esi, %esi
callq 0x10e0
movq 0xc8(%rsp), %rdi
movq 0x48(%rsp), %rsi
movl 0x60(%rsp), %edx
movq 0x78(%rsp), %rcx
movl 0x74(%rsp), %r8d
callq 0x8be0
movl %eax, 0x5c(%rsp)
movq 0xc8(%rsp), %rdi
movq 0xc8(%rsp), %rdx
movl 0x5c(%rsp), %ecx
movq 0xa8(%rsp), %r8
movl 0xb0(%rsp), %r9d
movq 0x88(%rsp), %r11
movl 0x84(%rsp), %r10d
movq 0x40(%rsp), %rax
leaq 0x60(%rsp), %rsi
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0xcbf0
movq 0x48(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movl 0x60(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x48(%rsp), %rdi
movslq 0x60(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x54(%rsp), %eax
movl 0x60(%rsp), %ecx
shll $0x3, %ecx
subl %ecx, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movq 0x30(%rsp), %rax
shlq %rax
movq %rax, 0x30(%rsp)
jmp 0xd9d9
jmp 0xdb8e
movl 0x38(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0xd979
movq 0x78(%rsp), %rdi
movq 0x88(%rsp), %rsi
movl 0x84(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x78(%rsp), %rdi
movslq 0x84(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x3c(%rsp), %eax
movl 0x84(%rsp), %ecx
shll $0x3, %ecx
subl %ecx, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movq 0x78(%rsp), %rdi
movl 0x84(%rsp), %esi
movq 0xb8(%rsp), %rdx
movl 0xc0(%rsp), %ecx
callq 0x8940
movl %eax, 0x74(%rsp)
movq 0x48(%rsp), %rdi
movl 0x60(%rsp), %esi
movq 0xb8(%rsp), %rdx
movl 0xc0(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
jne 0xdc3e
movb $0x1, 0x97(%rsp)
jmp 0xddaf
movq 0x48(%rsp), %rdi
movl 0x60(%rsp), %esi
movq 0x78(%rsp), %rdx
movl 0x74(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
jne 0xdc67
movb $0x1, 0x97(%rsp)
jmp 0xddaf
jmp 0xdc69
movl 0xa0(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xa0(%rsp)
cmpl $0x0, %eax
je 0xdda7
movq 0xc8(%rsp), %rdi
movslq 0x58(%rsp), %rdx
xorl %esi, %esi
callq 0x10e0
movq 0xc8(%rsp), %rdi
movq 0x48(%rsp), %rsi
movl 0x60(%rsp), %edx
movq 0x48(%rsp), %rcx
movl 0x60(%rsp), %r8d
callq 0x8be0
movl %eax, 0x5c(%rsp)
movq 0xc8(%rsp), %rdi
movq 0xc8(%rsp), %rdx
movl 0x5c(%rsp), %ecx
movq 0xa8(%rsp), %r8
movl 0xb0(%rsp), %r9d
movq 0x88(%rsp), %r11
movl 0x84(%rsp), %r10d
movq 0x40(%rsp), %rax
leaq 0x60(%rsp), %rsi
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0xcbf0
movq 0x48(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movl 0x60(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x48(%rsp), %rdi
movslq 0x60(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x54(%rsp), %eax
movl 0x60(%rsp), %ecx
shll $0x3, %ecx
subl %ecx, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movq 0x48(%rsp), %rdi
movl 0x60(%rsp), %esi
movq 0xb8(%rsp), %rdx
movl 0xc0(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
jne 0xdd7c
movb $0x0, 0x97(%rsp)
jmp 0xddaf
movq 0x48(%rsp), %rdi
movl 0x60(%rsp), %esi
movq 0x78(%rsp), %rdx
movl 0x74(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
jne 0xdda2
movb $0x1, 0x97(%rsp)
jmp 0xddaf
jmp 0xdc69
movb $0x0, 0x97(%rsp)
movb 0x97(%rsp), %al
andb $0x1, %al
addq $0x98, %rsp
retq