#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ mpz_t;
typedef int /*<<< orphan*/ gmp_randstate_t;

/* Variables and functions */
scalar_t__ miller_rabin_pass(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
scalar_t__ mpz_sgn(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_urandomm(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/);
int miller_rabin(mpz_t n, gmp_randstate_t rand_state) {
  mpz_t a;
  int repeat;
  mpz_init(a);
  for (repeat = 0; repeat < 20; repeat++) {
    do {
      mpz_urandomm(a, rand_state, n);
    } while (mpz_sgn(a) == 0);
    if (miller_rabin_pass(a, n) == 0) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<miller_rabin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <mpz_init@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jge    11c0 <miller_rabin+0x80>
jmp    116c <miller_rabin+0x2c>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1060 <mpz_urandomm@plt>
mov    -0x10(%rbp),%edi
call   1050 <mpz_sgn@plt>
cmp    $0x0,%rax
je     116c <miller_rabin+0x2c>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <miller_rabin_pass@plt>
cmp    $0x0,%rax
jne    11ad <miller_rabin+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    11c7 <miller_rabin+0x87>
jmp    11b2 <miller_rabin+0x72>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115d <miller_rabin+0x1d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<miller_rabin>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
call   1030 <mpz_init@plt>
xor    %r14d,%r14d
mov    %ebx,%esi
mov    %ebp,%edx
call   1060 <mpz_urandomm@plt>
call   1050 <mpz_sgn@plt>
test   %rax,%rax
je     1150 <miller_rabin+0x10>
mov    %ebp,%esi
call   1040 <miller_rabin_pass@plt>
test   %rax,%rax
je     1180 <miller_rabin+0x40>
add    $0x1,%r14d
cmp    $0x14,%r14d
jne    1150 <miller_rabin+0x10>
mov    $0x1,%eax
jmp    1182 <miller_rabin+0x42>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @miller_rabin(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %6
%9 = call i32 @mpz_init(i32 %8)
store i32 0, i32* %7
br label %10
10: ; preds = %30, %2
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 20
br i1 %12, label %13, label %33
13: ; preds = %10
br label %14
14: ; preds = %19, %13
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = call i32 @mpz_urandomm(i32 %15, i32 %16, i32 %17)
br label %19
19: ; preds = %14
%20 = load i32, i32* %6
%21 = call i64 @mpz_sgn(i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %14, label %23
23: ; preds = %19
%24 = load i32, i32* %6
%25 = load i32, i32* %4
%26 = call i64 @miller_rabin_pass(i32 %24, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 0, i32* %3
br label %34
29: ; preds = %23
br label %30
30: ; preds = %29
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %10
33: ; preds = %10
store i32 1, i32* %3
br label %34
34: ; preds = %33, %28
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @miller_rabin(i32 %0, i32 %1) {
%3 = tail call i32 @mpz_init(i32 undef)
br label %7
4: ; preds = %13
%5 = add nuw nsw i32 %8, 1
%6 = icmp eq i32 %5, 20
br i1 %6, label %16, label %7
7: ; preds = %2, %4
%8 = phi i32 [ 0, %2 ], [ %5, %4 ]
br label %9
9: ; preds = %7, %9
%10 = tail call i32 @mpz_urandomm(i32 undef, i32 %1, i32 %0)
%11 = tail call i64 @mpz_sgn(i32 undef)
%12 = icmp eq i64 %11, 0
br i1 %12, label %9, label %13
13: ; preds = %9
%14 = tail call i64 @miller_rabin_pass(i32 undef, i32 %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %4
16: ; preds = %4, %13
%17 = phi i32 [ 0, %13 ], [ 1, %4 ]
ret i32 %17
}