#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;

/* Variables and functions */
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ mpz_cmp_si(int /*<<< orphan*/, int);
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mod(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mod_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, int);
bool isPrime(mpz_t n) {
  mpz_t i, c, r;
  mpz_init(i);
  mpz_init(c);
  mpz_init(r);
  if (mpz_cmp_si(n, 2) < 0)
    return false;
  if (mpz_cmp_si(n, 2) == 0)
    return true;
  mpz_mod_ui(r, n, 2);
  if (mpz_cmp_ui(r, 0) == 0)
    return false;
  for (mpz_set_ui(i, 2); mpz_cmp(i, n) < 0; mpz_add_ui(i, i, 1)) {
    mpz_mod(r, n, i);
    if (mpz_cmp_ui(r, 0) == 0)
      return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<isPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x10(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x14(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1080 <mpz_cmp_si@plt>
cmp    $0x0,%rax
jge    11c6 <isPrime+0x46>
movl   $0x0,-0x4(%rbp)
jmp    128a <isPrime+0x10a>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1080 <mpz_cmp_si@plt>
cmp    $0x0,%rax
jne    11e9 <isPrime+0x69>
movl   $0x1,-0x4(%rbp)
jmp    128a <isPrime+0x10a>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x2,%edx
call   1040 <mpz_mod_ui@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1060 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    1219 <isPrime+0x99>
movl   $0x0,-0x4(%rbp)
jmp    128a <isPrime+0x10a>
mov    -0xc(%rbp),%edi
mov    $0x2,%esi
call   1090 <mpz_set_ui@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1070 <mpz_cmp@plt>
cmp    $0x0,%rax
jge    1283 <isPrime+0x103>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   10a0 <mpz_mod@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1060 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    1269 <isPrime+0xe9>
movl   $0x0,-0x4(%rbp)
jmp    128a <isPrime+0x10a>
jmp    126e <isPrime+0xee>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   1030 <mpz_add_ui@plt>
jmp    1226 <isPrime+0xa6>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isPrime>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
call   1050 <mpz_init@plt>
call   1050 <mpz_init@plt>
call   1050 <mpz_init@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1080 <mpz_cmp_si@plt>
test   %rax,%rax
js     1222 <isPrime+0xa2>
mov    %ebx,%edi
mov    $0x2,%esi
call   1080 <mpz_cmp_si@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1224 <isPrime+0xa4>
mov    %ebx,%esi
mov    $0x2,%edx
call   1040 <mpz_mod_ui@plt>
xor    %ebp,%ebp
xor    %esi,%esi
call   1060 <mpz_cmp_ui@plt>
test   %rax,%rax
je     1224 <isPrime+0xa4>
mov    $0x2,%esi
call   1090 <mpz_set_ui@plt>
mov    %ebx,%esi
call   1070 <mpz_cmp@plt>
mov    $0x1,%ebp
test   %rax,%rax
jns    1224 <isPrime+0xa4>
mov    %ebx,%esi
call   10a0 <mpz_mod@plt>
xor    %ebp,%ebp
xor    %esi,%esi
call   1060 <mpz_cmp_ui@plt>
test   %rax,%rax
je     1224 <isPrime+0xa4>
mov    $0x1,%ebp
mov    $0x1,%edx
call   1030 <mpz_add_ui@plt>
mov    %ebx,%esi
call   1070 <mpz_cmp@plt>
test   %rax,%rax
js     11f0 <isPrime+0x70>
jmp    1224 <isPrime+0xa4>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @isPrime(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 @mpz_init(i32 %7)
%9 = load i32, i32* %5
%10 = call i32 @mpz_init(i32 %9)
%11 = load i32, i32* %6
%12 = call i32 @mpz_init(i32 %11)
%13 = load i32, i32* %3
%14 = call i64 @mpz_cmp_si(i32 %13, i32 2)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 0, i32* %2
br label %53
17: ; preds = %1
%18 = load i32, i32* %3
%19 = call i64 @mpz_cmp_si(i32 %18, i32 2)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 1, i32* %2
br label %53
22: ; preds = %17
%23 = load i32, i32* %6
%24 = load i32, i32* %3
%25 = call i32 @mpz_mod_ui(i32 %23, i32 %24, i32 2)
%26 = load i32, i32* %6
%27 = call i64 @mpz_cmp_ui(i32 %26, i32 0)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %22
store i32 0, i32* %2
br label %53
30: ; preds = %22
%31 = load i32, i32* %4
%32 = call i32 @mpz_set_ui(i32 %31, i32 2)
br label %33
33: ; preds = %48, %30
%34 = load i32, i32* %4
%35 = load i32, i32* %3
%36 = call i64 @mpz_cmp(i32 %34, i32 %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %52
38: ; preds = %33
%39 = load i32, i32* %6
%40 = load i32, i32* %3
%41 = load i32, i32* %4
%42 = call i32 @mpz_mod(i32 %39, i32 %40, i32 %41)
%43 = load i32, i32* %6
%44 = call i64 @mpz_cmp_ui(i32 %43, i32 0)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %38
store i32 0, i32* %2
br label %53
47: ; preds = %38
br label %48
48: ; preds = %47
%49 = load i32, i32* %4
%50 = load i32, i32* %4
%51 = call i32 @mpz_add_ui(i32 %49, i32 %50, i32 1)
br label %33
52: ; preds = %33
store i32 1, i32* %2
br label %53
53: ; preds = %52, %46, %29, %21, %16
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
define i32 @isPrime(i32 %0) {
%2 = tail call i32 @mpz_init(i32 undef)
%3 = tail call i32 @mpz_init(i32 undef)
%4 = tail call i32 @mpz_init(i32 undef)
%5 = tail call i64 @mpz_cmp_si(i32 %0, i32 2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %26, label %7
7: ; preds = %1
%8 = tail call i64 @mpz_cmp_si(i32 %0, i32 2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %26, label %10
10: ; preds = %7
%11 = tail call i32 @mpz_mod_ui(i32 undef, i32 %0, i32 2)
%12 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %10
%15 = tail call i32 @mpz_set_ui(i32 undef, i32 2)
%16 = tail call i64 @mpz_cmp(i32 undef, i32 %0)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %14, %22
%19 = tail call i32 @mpz_mod(i32 undef, i32 %0, i32 undef)
%20 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 1)
%24 = tail call i64 @mpz_cmp(i32 undef, i32 %0)
%25 = icmp slt i64 %24, 0
br i1 %25, label %18, label %26
26: ; preds = %18, %22, %14, %10, %7, %1
%27 = phi i32 [ 0, %1 ], [ 1, %7 ], [ 0, %10 ], [ 1, %14 ], [ 0, %18 ], [ 1, %22 ]
ret i32 %27
}