#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 */
int /*<<< orphan*/ gmp_randinit_default(int /*<<< orphan*/);
int /*<<< orphan*/ gmp_randseed_ui(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ millerRabinStep(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(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 /*<<< orphan*/ time(int /*<<< orphan*/ *);
int millerRabin(mpz_t n) {
  gmp_randstate_t rand_state;
  gmp_randinit_default(rand_state);
  gmp_randseed_ui(rand_state, time(NULL));
  mpz_t a;
  int i = 0;
  mpz_init(a);
  for (i = 0; i < 20; i++) {
    do {
      mpz_urandomm(a, rand_state, n);
    } while (mpz_sgn(a) == 0);
    if (millerRabinStep(a, n) == 0) {
      mpz_clear(a);
      return 0;
    }
  }
  mpz_clear(a);
  return 1;
}


x86 assembly (clang, -O0):
<millerRabin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <gmp_randinit_default@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
call   1060 <gmp_randseed_ui@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <mpz_init@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jge    122d <millerRabin+0xad>
jmp    11d1 <millerRabin+0x51>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
call   10a0 <mpz_urandomm@plt>
mov    -0x10(%rbp),%edi
call   1080 <mpz_sgn@plt>
cmp    $0x0,%rax
je     11d1 <millerRabin+0x51>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1090 <millerRabinStep@plt>
cmp    $0x0,%rax
jne    121a <millerRabin+0x9a>
mov    -0x10(%rbp),%edi
call   1050 <mpz_clear@plt>
movl   $0x0,-0x4(%rbp)
jmp    123c <millerRabin+0xbc>
jmp    121f <millerRabin+0x9f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c2 <millerRabin+0x42>
mov    -0x10(%rbp),%edi
call   1050 <mpz_clear@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<millerRabin>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
call   1070 <gmp_randinit_default@plt>
xor    %r14d,%r14d
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%esi
call   1060 <gmp_randseed_ui@plt>
call   1030 <mpz_init@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edx
call   10a0 <mpz_urandomm@plt>
call   1080 <mpz_sgn@plt>
test   %rax,%rax
je     11b0 <millerRabin+0x30>
mov    %ebx,%esi
call   1090 <millerRabinStep@plt>
test   %rax,%rax
je     11de <millerRabin+0x5e>
add    $0x1,%r14d
cmp    $0x14,%r14d
jne    11b0 <millerRabin+0x30>
mov    $0x1,%ebx
jmp    11e0 <millerRabin+0x60>
xor    %ebx,%ebx
call   1050 <mpz_clear@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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