// File: /workspace/github_c_makefile_star2_O1/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 %ebx, %ebx
testl %esi, %esi
jle 0x3f13
movq %rdi, %r14
movq (%rdi), %rax
testb $0x1, (%rax)
je 0x3f13
movq %rdx, %r12
leaq 0x70(%rsp), %rdx
movl $0x1, (%rdx)
movq (%r14), %rdi
movl $0x1, %ecx
callq 0x1b00
testl %eax, %eax
jle 0x3f13
leaq 0x70(%rsp), %rdx
movl $0x3, (%rdx)
movq (%r14), %rdi
movl 0xc(%r14), %esi
movl $0x1, %ecx
callq 0x1b00
movl $0x1, %ebx
testl %eax, %eax
jle 0x3f13
xorl %eax, %eax
leaq 0x70(%rsp), %rcx
movl %eax, 0x10(%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rcx)
leaq 0x50(%rsp), %rcx
movaps %xmm0, (%rcx)
movl %eax, 0x10(%rcx)
leaq 0x10(%rsp), %r13
movaps %xmm0, (%r13)
movl %eax, 0x10(%r13)
leaq 0xb0(%rsp), %r15
movaps %xmm0, (%r15)
movl %eax, 0x10(%r15)
leaq 0x30(%rsp), %rbx
movaps %xmm0, (%rbx)
movl %eax, 0x10(%rbx)
leaq 0x90(%rsp), %rcx
movaps %xmm0, (%rcx)
movl %eax, 0x10(%rcx)
movq %r15, %rdi
movl $0x1, %esi
callq 0x1a71
movq (%r15), %rax
movl $0x2, (%rax)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x8(%r15)
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x2a93
leaq 0x90(%rsp), %rdi
movq %r14, %rsi
movl $0x3, %edx
movl $0x1, %ecx
callq 0x2a93
movq %rbx, %rdi
callq 0x2f3d
movl %eax, %r15d
movl 0xc(%rbx), %esi
leaq 0x50(%rsp), %rdi
callq 0x1a71
leaq 0x50(%rsp), %rax
movq (%rax), %rdi
movl 0x10(%rax), %esi
movq (%rbx), %rdx
movl 0xc(%rbx), %ecx
movl %r15d, %r8d
callq 0x2cf0
leaq 0x50(%rsp), %rcx
movl %eax, 0xc(%rcx)
movl 0x8(%rbx), %eax
movl %eax, 0x8(%rcx)
movq %r12, 0xa8(%rsp)
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
leaq 0x90(%rsp), %rsi
movq %r12, %rdx
callq 0x3935
movq %rbx, %rdi
movq %rbx, %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x2a93
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x50(%rsp), %rdx
movq %r14, %rcx
callq 0x3a39
movl $0x1, 0xc(%rsp)
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0xc(%rsp), %rdx
movl $0x1, %ecx
callq 0x1b00
testl %eax, %eax
je 0x3e67
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 0x1b6d
testl %eax, %eax
je 0x3e67
movl $0x1, %r12d
cmpl $0x2, %r15d
jl 0x3e56
leaq 0xb0(%rsp), %rbx
movq %r13, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x3a39
movl $0x1, 0xc(%rsp)
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
leaq 0xc(%rsp), %rdx
movl $0x1, %ecx
callq 0x1b00
testl %eax, %eax
je 0x3f11
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 0x1b6d
testl %eax, %eax
je 0x3e56
incl %r12d
cmpl %r12d, %r15d
jne 0x3ded
movl %r15d, %r12d
cmpl %r15d, %r12d
movq 0xa8(%rsp), %r12
je 0x3f11
decl %ebp
jne 0x3d4b
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 0xb0(%rsp), %rdi
callq 0x1030
movl %ebx, 0xc0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xb0(%rsp)
movq 0x30(%rsp), %rdi
callq 0x1030
movl %ebx, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x90(%rsp), %rdi
callq 0x1030
movl %ebx, 0xa0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movl $0x1, %ebx
jmp 0x3f13
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq