#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);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/, int);
scalar_t__ mpz_divisible_p(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ mpz_divisible_ui_p(int /*<<< orphan*/, int);
scalar_t__ mpz_even_p(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_sqrt(int /*<<< orphan*/, int /*<<< orphan*/);
int isprime(mpz_t n) {
  mpz_t i, n2;
  int d, ret;
  if (mpz_cmp_ui(n, 1) == 0)
    return (0);
  if (mpz_cmp_ui(n, 2) == 0 || mpz_cmp_ui(n, 3) == 0)
    return (1);
  if (mpz_even_p(n) || mpz_divisible_ui_p(n, 3))
    return (0);
  mpz_init(n2);
  mpz_sqrt(n2, n);
  d = 2;
  mpz_init_set_ui(i, 5);
  ret = 1;
  while (mpz_cmp(i, n2) <= 0) {
    if (mpz_divisible_p(n, i)) {
      ret = 0;
      break;
    }
    mpz_add_ui(i, i, d);
    d = (d == 2 ? 4 : 2);
  }
  mpz_clear(i);
  mpz_clear(n2);
  return (ret);
}


x86 assembly (clang, -O0):
<isprime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1070 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    11ce <isprime+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    12e0 <isprime+0x140>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1070 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
je     11fc <isprime+0x5c>
mov    -0x8(%rbp),%edi
mov    $0x3,%esi
call   1070 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jne    1208 <isprime+0x68>
movl   $0x1,-0x4(%rbp)
jmp    12e0 <isprime+0x140>
mov    -0x8(%rbp),%edi
call   1080 <mpz_even_p@plt>
cmp    $0x0,%rax
jne    1231 <isprime+0x91>
mov    -0x8(%rbp),%edi
mov    $0x3,%esi
call   1030 <mpz_divisible_ui_p@plt>
cmp    $0x0,%rax
je     123d <isprime+0x9d>
movl   $0x0,-0x4(%rbp)
jmp    12e0 <isprime+0x140>
mov    -0x10(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10a0 <mpz_sqrt@plt>
movl   $0x2,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x5,%esi
call   1090 <mpz_init_set_ui@plt>
movl   $0x1,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   10b0 <mpz_cmp@plt>
cmp    $0x0,%rax
jg     12ca <isprime+0x12a>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <mpz_divisible_p@plt>
cmp    $0x0,%rax
je     12a1 <isprime+0x101>
movl   $0x0,-0x18(%rbp)
jmp    12ca <isprime+0x12a>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <mpz_add_ui@plt>
mov    -0x14(%rbp),%edx
mov    $0x2,%eax
mov    $0x4,%ecx
cmp    $0x2,%edx
cmove  %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    126b <isprime+0xcb>
mov    -0xc(%rbp),%edi
call   10c0 <mpz_clear@plt>
mov    -0x10(%rbp),%edi
call   10c0 <mpz_clear@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isprime>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0x1,%ebp
mov    $0x1,%esi
call   1070 <mpz_cmp_ui@plt>
test   %rax,%rax
je     11e8 <isprime+0x48>
mov    %ebx,%edi
mov    $0x2,%esi
call   1070 <mpz_cmp_ui@plt>
test   %rax,%rax
je     11ea <isprime+0x4a>
mov    %ebx,%edi
mov    $0x3,%esi
call   1070 <mpz_cmp_ui@plt>
test   %rax,%rax
je     11ea <isprime+0x4a>
mov    %ebx,%edi
call   1080 <mpz_even_p@plt>
test   %rax,%rax
je     11f1 <isprime+0x51>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebx,%edi
mov    $0x3,%esi
call   1030 <mpz_divisible_ui_p@plt>
mov    $0x0,%ebp
test   %rax,%rax
jne    11ea <isprime+0x4a>
call   1060 <mpz_init@plt>
mov    %ebx,%esi
call   10a0 <mpz_sqrt@plt>
mov    $0x5,%esi
call   1090 <mpz_init_set_ui@plt>
call   10b0 <mpz_cmp@plt>
mov    $0x1,%ebp
test   %rax,%rax
jg     1273 <isprime+0xd3>
mov    $0x2,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
call   1040 <mpz_divisible_p@plt>
test   %rax,%rax
jne    1271 <isprime+0xd1>
mov    %r14d,%edx
call   1050 <mpz_add_ui@plt>
xor    %eax,%eax
cmp    $0x2,%r14d
sete   %al
lea    (%rax,%rax,1),%r14d
add    $0x2,%r14d
call   10b0 <mpz_cmp@plt>
test   %rax,%rax
jle    1240 <isprime+0xa0>
jmp    1273 <isprime+0xd3>
xor    %ebp,%ebp
call   10c0 <mpz_clear@plt>
call   10c0 <mpz_clear@plt>
jmp    11ea <isprime+0x4a>

LLVM IR (-O0):
define i32 @isprime(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = call i64 @mpz_cmp_ui(i32 %8, i32 1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %64
12: ; preds = %1
%13 = load i32, i32* %3
%14 = call i64 @mpz_cmp_ui(i32 %13, i32 2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i32, i32* %3
%18 = call i64 @mpz_cmp_ui(i32 %17, i32 3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16, %12
store i32 1, i32* %2
br label %64
21: ; preds = %16
%22 = load i32, i32* %3
%23 = call i64 @mpz_even_p(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i32, i32* %3
%27 = call i64 @mpz_divisible_ui_p(i32 %26, i32 3)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25, %21
store i32 0, i32* %2
br label %64
30: ; preds = %25
%31 = load i32, i32* %5
%32 = call i32 @mpz_init(i32 %31)
%33 = load i32, i32* %5
%34 = load i32, i32* %3
%35 = call i32 @mpz_sqrt(i32 %33, i32 %34)
store i32 2, i32* %6
%36 = load i32, i32* %4
%37 = call i32 @mpz_init_set_ui(i32 %36, i32 5)
store i32 1, i32* %7
br label %38
38: ; preds = %49, %30
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = call i64 @mpz_cmp(i32 %39, i32 %40)
%42 = icmp sle i64 %41, 0
br i1 %42, label %43, label %58
43: ; preds = %38
%44 = load i32, i32* %3
%45 = load i32, i32* %4
%46 = call i64 @mpz_divisible_p(i32 %44, i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %43
store i32 0, i32* %7
br label %58
49: ; preds = %43
%50 = load i32, i32* %4
%51 = load i32, i32* %4
%52 = load i32, i32* %6
%53 = call i32 @mpz_add_ui(i32 %50, i32 %51, i32 %52)
%54 = load i32, i32* %6
%55 = icmp eq i32 %54, 2
%56 = zext i1 %55 to i64
%57 = select i1 %55, i32 4, i32 2
store i32 %57, i32* %6
br label %38
58: ; preds = %48, %38
%59 = load i32, i32* %4
%60 = call i32 @mpz_clear(i32 %59)
%61 = load i32, i32* %5
%62 = call i32 @mpz_clear(i32 %61)
%63 = load i32, i32* %7
store i32 %63, i32* %2
br label %64
64: ; preds = %58, %29, %20, %11
%65 = load i32, i32* %2
ret i32 %65
}

LLVM IR (-O2):
define i32 @isprime(i32 %0) {
%2 = tail call i64 @mpz_cmp_ui(i32 %0, i32 1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %36, label %4
4: ; preds = %1
%5 = tail call i64 @mpz_cmp_ui(i32 %0, i32 2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %36, label %7
7: ; preds = %4
%8 = tail call i64 @mpz_cmp_ui(i32 %0, i32 3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %36, label %10
10: ; preds = %7
%11 = tail call i64 @mpz_even_p(i32 %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %36
13: ; preds = %10
%14 = tail call i64 @mpz_divisible_ui_p(i32 %0, i32 3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %36
16: ; preds = %13
%17 = tail call i32 @mpz_init(i32 undef)
%18 = tail call i32 @mpz_sqrt(i32 undef, i32 %0)
%19 = tail call i32 @mpz_init_set_ui(i32 undef, i32 5)
%20 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%21 = icmp slt i64 %20, 1
br i1 %21, label %22, label %32
22: ; preds = %16, %26
%23 = phi i32 [ %29, %26 ], [ 2, %16 ]
%24 = tail call i64 @mpz_divisible_p(i32 %0, i32 undef)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 %23)
%28 = icmp eq i32 %23, 2
%29 = select i1 %28, i32 4, i32 2
%30 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%31 = icmp slt i64 %30, 1
br i1 %31, label %22, label %32
32: ; preds = %26, %22, %16
%33 = phi i32 [ 1, %16 ], [ 0, %22 ], [ 1, %26 ]
%34 = tail call i32 @mpz_clear(i32 undef)
%35 = tail call i32 @mpz_clear(i32 undef)
br label %36
36: ; preds = %10, %13, %4, %7, %1, %32
%37 = phi i32 [ %33, %32 ], [ 0, %1 ], [ 1, %7 ], [ 1, %4 ], [ 0, %13 ], [ 0, %10 ]
ret i32 %37
}