// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xe8, %rsp
movq %rdi, 0xd8(%rsp)
movl %esi, 0xd4(%rsp)
movq %rdx, 0xc8(%rsp)
movq 0xd8(%rsp), %rdi
xorl %esi, %esi
callq 0x27e0
cmpl $0x0, %eax
jne 0x55c2
movl $0x0, 0xe4(%rsp)
jmp 0x5832
movq 0xd8(%rsp), %rdi
movl $0x1, %esi
callq 0x2420
cmpl $0x0, %eax
jg 0x55e9
movl $0x0, 0xe4(%rsp)
jmp 0x5832
movq 0xd8(%rsp), %rdi
movl $0x3, %esi
callq 0x2420
cmpl $0x0, %eax
jg 0x5610
movl $0x1, 0xe4(%rsp)
jmp 0x5832
leaq 0xb0(%rsp), %rdi
callq 0x20a0
leaq 0x90(%rsp), %rdi
callq 0x20a0
leaq 0x70(%rsp), %rdi
callq 0x20a0
leaq 0x50(%rsp), %rdi
callq 0x20a0
leaq 0x30(%rsp), %rdi
callq 0x20a0
leaq 0x10(%rsp), %rdi
callq 0x20a0
leaq 0x50(%rsp), %rdi
movl $0x2, %esi
callq 0x3a60
leaq 0x30(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movl $0x1, %edx
callq 0x3ef0
leaq 0x10(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movl $0x3, %edx
callq 0x3ef0
leaq 0x30(%rsp), %rdi
callq 0x4660
movl %eax, 0x8(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movl 0x8(%rsp), %edx
callq 0x4570
leaq 0xb0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0xc8(%rsp), %rdx
callq 0x5330
leaq 0xb0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
movl $0x2, %edx
callq 0x3ec0
leaq 0x70(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x90(%rsp), %rdx
movq 0xd8(%rsp), %rcx
callq 0x53f0
leaq 0x70(%rsp), %rdi
movl $0x1, %esi
callq 0x2420
cmpl $0x0, %eax
jne 0x5722
jmp 0x57cb
leaq 0x70(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x23d0
cmpl $0x0, %eax
jne 0x573b
jmp 0x57cb
movl $0x1, 0xc(%rsp)
movl 0xc(%rsp), %eax
cmpl 0x8(%rsp), %eax
jge 0x57b2
leaq 0x70(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x50(%rsp), %rdx
movq 0xd8(%rsp), %rcx
callq 0x53f0
leaq 0x70(%rsp), %rdi
movl $0x1, %esi
callq 0x2420
cmpl $0x0, %eax
jne 0x578d
movl $0x0, 0xe4(%rsp)
jmp 0x5832
leaq 0x70(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x23d0
cmpl $0x0, %eax
jne 0x57a3
jmp 0x57b2
jmp 0x57a5
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x5743
movl 0xc(%rsp), %eax
cmpl 0x8(%rsp), %eax
jne 0x57c9
movl $0x0, 0xe4(%rsp)
jmp 0x5832
jmp 0x57cb
movl 0xd4(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xd4(%rsp)
cmpl $0x0, %eax
jne 0x56b3
leaq 0xb0(%rsp), %rdi
callq 0x21b0
leaq 0x90(%rsp), %rdi
callq 0x21b0
leaq 0x70(%rsp), %rdi
callq 0x21b0
leaq 0x50(%rsp), %rdi
callq 0x21b0
leaq 0x30(%rsp), %rdi
callq 0x21b0
leaq 0x10(%rsp), %rdi
callq 0x21b0
movl $0x1, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
addq $0xe8, %rsp
retq
nopw %cs:(%rax,%rax)