// File: /workspace/github_c_makefile_star2_O3/983[P]bigint/bigint.c
// Function: bigint_is_probable_prime
int bigint_is_probable_prime(
    const bigint *n,
    int n_tests,
    bigint_rand_func rand_func
){
    bigint a[1], d[1], x[1], two[1], n_minus_one[1], n_minus_three[1];
    int i, shift;

    /* divisible by 2, not prime */
    if (bigint_get_bit(n, 0) == 0) return 0;

    /* 1 is not prime */
    if (bigint_cmp_abs_word(n, 1) <= 0) return 0;
    /* 3 is prime */
    if (bigint_cmp_abs_word(n, 3) <= 0) return 1;

    bigint_init(a);
    bigint_init(d);
    bigint_init(x);
    bigint_init(two);
    bigint_init(n_minus_one);
    bigint_init(n_minus_three);

    bigint_from_word(two, 2);

    bigint_sub_word(n_minus_one, n, 1);
    bigint_sub_word(n_minus_three, n, 3);

    shift = bigint_count_trailing_zeros(n_minus_one);
    bigint_shift_right(d, n_minus_one, shift);

    do {
        bigint_rand_inclusive(a, n_minus_three, rand_func);
        bigint_add_word(a, a, 2);
        bigint_pow_mod(x, a, d, n);

        if (bigint_cmp_abs_word(x, 1) == 0) continue;
        if (bigint_cmp(x, n_minus_one) == 0) continue;

        for (i = 1; i < shift; i++){
            bigint_pow_mod(x, x, two, n);
            if (bigint_cmp_abs_word(x, 1) == 0) return 0;
            if (bigint_cmp(x, n_minus_one) == 0) break;
        }

        if (i == shift) return 0;
    } while (--n_tests);

    bigint_free(a);
    bigint_free(d);
    bigint_free(x);
    bigint_free(two);
    bigint_free(n_minus_one);
    bigint_free(n_minus_three);
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %esi, %ebp
movl 0xc(%rdi), %esi
xorl %r15d, %r15d
testl %esi, %esi
jle 0x3ed4
movq %rdi, %r14
movq (%rdi), %rdi
testb $0x1, (%rdi)
je 0x3ed4
movq %rdx, 0x48(%rsp)
leaq 0x70(%rsp), %rdx
movl $0x1, (%rdx)
movl $0x1, %ecx
callq 0x1ae4
testl %eax, %eax
jle 0x3ed4
leaq 0x70(%rsp), %rdx
movl $0x3, (%rdx)
movq (%r14), %rdi
movl 0xc(%r14), %esi
movl $0x1, %ecx
callq 0x1ae4
movl $0x1, %r15d
testl %eax, %eax
jle 0x3ed4
xorl %eax, %eax
leaq 0x70(%rsp), %r15
movl %eax, 0x10(%r15)
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
leaq 0x50(%rsp), %rcx
movaps %xmm0, (%rcx)
movl %eax, 0x10(%rcx)
leaq 0x10(%rsp), %r13
movaps %xmm0, (%r13)
movl %eax, 0x10(%r13)
leaq 0x90(%rsp), %r12
movaps %xmm0, (%r12)
movl %eax, 0x10(%r12)
leaq 0x30(%rsp), %rbx
movaps %xmm0, (%rbx)
movl %eax, 0x10(%rbx)
leaq 0xb0(%rsp), %rcx
movaps %xmm0, (%rcx)
movl %eax, 0x10(%rcx)
movq %r12, %rdi
movl $0x1, %esi
callq 0x1a55
movq (%r12), %rax
movl $0x2, (%rax)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x8(%r12)
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x2aa8
leaq 0xb0(%rsp), %rdi
movq %r14, %rsi
movl $0x3, %edx
movl $0x1, %ecx
callq 0x2aa8
movq %rbx, %rdi
callq 0x2f6b
movl %eax, %r12d
movl 0xc(%rbx), %esi
leaq 0x50(%rsp), %rdi
callq 0x1a55
leaq 0x50(%rsp), %rax
movq (%rax), %rdi
movl 0x10(%rax), %esi
movq (%rbx), %rdx
movl 0xc(%rbx), %ecx
movl %r12d, %r8d
callq 0x2d05
leaq 0x50(%rsp), %rcx
movl %eax, 0xc(%rcx)
movl 0x8(%rbx), %eax
movl %eax, 0x8(%rcx)
movq 0x48(%rsp), %rbx
movq %r15, %rdi
leaq 0xb0(%rsp), %rsi
movq %rbx, %rdx
callq 0x3905
movq %r15, %rdi
movq %r15, %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x2aa8
movq %r13, %rdi
movq %r15, %rsi
leaq 0x50(%rsp), %rdx
movq %r14, %rcx
callq 0x3a09
movl $0x1, 0xc(%rsp)
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0xc(%rsp), %rdx
movl $0x1, %ecx
callq 0x1ae4
testl %eax, %eax
je 0x3e38
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
movl 0x18(%rsp), %edx
movq 0x30(%rsp), %rcx
movl 0x3c(%rsp), %r8d
movl 0x38(%rsp), %r9d
callq 0x1b51
testl %eax, %eax
je 0x3e38
movl $0x1, %ebx
cmpl $0x2, %r12d
jl 0x3e2a
movq %r13, %rdi
movq %r13, %rsi
leaq 0x90(%rsp), %rdx
movq %r14, %rcx
callq 0x3a09
movl $0x1, 0xc(%rsp)
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0xc(%rsp), %rdx
movl $0x1, %ecx
callq 0x1ae4
xorl %r15d, %r15d
testl %eax, %eax
je 0x3ed4
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
movl 0x18(%rsp), %edx
movq 0x30(%rsp), %rcx
movl 0x3c(%rsp), %r8d
movl 0x38(%rsp), %r9d
callq 0x1b51
testl %eax, %eax
je 0x3e25
incl %ebx
cmpl %ebx, %r12d
jne 0x3db3
jmp 0x3ed4
leaq 0x70(%rsp), %r15
cmpl %r12d, %ebx
movq 0x48(%rsp), %rbx
je 0x3ed1
decl %ebp
jne 0x3d1f
movq 0x70(%rsp), %rdi
callq 0x1030
xorl %ebx, %ebx
movl %ebx, 0x80(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movq 0x50(%rsp), %rdi
callq 0x1030
movl %ebx, 0x60(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq 0x10(%rsp), %rdi
callq 0x1030
movl %ebx, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x90(%rsp), %rdi
callq 0x1030
movl %ebx, 0xa0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movq 0x30(%rsp), %rdi
callq 0x1030
movl %ebx, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x1030
movl $0x1, %r15d
jmp 0x3ed4
xorl %r15d, %r15d
movl %r15d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq