// File: /workspace/github_c_makefile_star2_O2/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
cmpl $0x0, 0xc(%rdi)
jle 0x36c7
movq %rdi, %r14
movq (%rdi), %rax
testb $0x1, (%rax)
je 0x36c7
movq %rdx, %r15
movl %esi, %ebp
pushq $0x1
popq %rbx
movq %r14, %rdi
movl %ebx, %esi
callq 0x1b1c
testl %eax, %eax
jle 0x36c7
pushq $0x3
popq %rsi
movq %r14, %rdi
callq 0x1b1c
testl %eax, %eax
jle 0x36c9
xorps %xmm0, %xmm0
leaq 0x90(%rsp), %rax
movaps %xmm0, (%rax)
andl $0x0, 0x10(%rax)
leaq 0x30(%rsp), %rax
movaps %xmm0, (%rax)
andl $0x0, 0x10(%rax)
leaq 0xb0(%rsp), %r13
andl $0x0, 0x10(%r13)
leaq 0x70(%rsp), %rdi
andl $0x0, 0x10(%rdi)
movaps %xmm0, (%r13)
movaps %xmm0, (%rdi)
leaq 0x10(%rsp), %rbx
movaps %xmm0, (%rbx)
andl $0x0, 0x10(%rbx)
leaq 0x50(%rsp), %r12
movaps %xmm0, (%r12)
andl $0x0, 0x10(%r12)
pushq $0x2
popq %rsi
callq 0x2609
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2810
pushq $0x3
popq %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x2810
movq %rbx, %rdi
callq 0x2b94
movl %eax, %r12d
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
movl %eax, %edx
callq 0x2b28
cmpl $0x2, %r12d
pushq $0x1
popq %rax
cmovgel %r12d, %eax
movl %eax, 0x4(%rsp)
movq %r15, 0x8(%rsp)
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
movq %r15, %rdx
callq 0x32dd
movq %rbx, %rdi
movq %rbx, %rsi
pushq $0x2
popq %rdx
callq 0x2809
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x30(%rsp), %rdx
movq %r14, %rcx
callq 0x3365
movq %r13, %rdi
pushq $0x1
popq %rsi
callq 0x1b1c
testl %eax, %eax
je 0x3678
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
callq 0x1afc
testl %eax, %eax
je 0x3678
pushq $0x1
popq %r15
leaq 0x70(%rsp), %rbx
cmpl %r12d, %r15d
jge 0x3669
movq %r13, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x3365
movq %r13, %rdi
pushq $0x1
popq %rsi
callq 0x1b1c
testl %eax, %eax
je 0x36c7
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
callq 0x1afc
testl %eax, %eax
je 0x366e
incl %r15d
jmp 0x362e
movl 0x4(%rsp), %r15d
cmpl %r12d, %r15d
movq 0x8(%rsp), %r15
je 0x36c7
decl %ebp
jne 0x35cc
leaq 0x90(%rsp), %rdi
callq 0x1a26
leaq 0x30(%rsp), %rdi
callq 0x1a26
leaq 0xb0(%rsp), %rdi
callq 0x1a26
leaq 0x70(%rsp), %rdi
callq 0x1a26
leaq 0x10(%rsp), %rdi
callq 0x1a26
leaq 0x50(%rsp), %rdi
callq 0x1a26
pushq $0x1
popq %rbx
jmp 0x36c9
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq