#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 */
scalar_t__ fermat(int /*<<< orphan*/);
int /*<<< orphan*/ gmp_scanf(char *, int /*<<< orphan*/);
scalar_t__ millerrabin(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  mpz_t n;
  mpz_init(n);
  printf("Miller-Rabin/Fermat Primality Testing\n");
  printf("Enter a number: ");
  gmp_scanf("%Zd", n);
  printf("Miller-Rabin says: %s\n",
         millerrabin(n) ? "probably a prime..." : "not a prime.");
  printf("Fermat says: %s\n",
         fermat(n) ? "probably a prime..." : "not a prime.");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <mpz_init@plt>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xeab(%rip),%rdi
call   1050 <gmp_scanf@plt>
mov    -0x8(%rbp),%edi
call   1030 <millerrabin@plt>
mov    %rax,%rcx
lea    0xec3(%rip),%rsi
lea    0xea8(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1070 <fermat@plt>
mov    %rax,%rcx
lea    0xe94(%rip),%rsi
lea    0xe79(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
call   1070 <mpz_init@plt>
lea    0xeee(%rip),%rdi
call   1030 <puts@plt>
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe87(%rip),%rdi
call   1060 <gmp_scanf@plt>
call   1040 <millerrabin@plt>
test   %rax,%rax
lea    0xea2(%rip),%r14
lea    0xe87(%rip),%rbx
mov    %rbx,%rsi
cmove  %r14,%rsi
lea    0xe62(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
call   1080 <fermat@plt>
test   %rax,%rax
cmove  %r14,%rbx
lea    0xe80(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Miller-Rabin/Fermat Primality Testing\0A\00"
@.str.1 = [17 x i8] c"Enter a number: \00"
@.str.2 = [4 x i8] c"%Zd\00"
@.str.3 = [23 x i8] c"Miller-Rabin says: %s\0A\00"
@.str.4 = [20 x i8] c"probably a prime...\00"
@.str.5 = [13 x i8] c"not a prime.\00"
@.str.6 = [17 x i8] c"Fermat says: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* %2
%4 = call i32 @mpz_init(i32 %3)
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = call i32 @gmp_scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %2
%10 = call i64 @millerrabin(i32 %9)
%11 = icmp ne i64 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = load i32, i32* %2
%16 = call i64 @fermat(i32 %15)
%17 = icmp ne i64 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %19)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"Enter a number: \00"
@.str.2 = [4 x i8] c"%Zd\00"
@.str.3 = [23 x i8] c"Miller-Rabin says: %s\0A\00"
@.str.4 = [20 x i8] c"probably a prime...\00"
@.str.5 = [13 x i8] c"not a prime.\00"
@.str.6 = [17 x i8] c"Fermat says: %s\0A\00"
@str = [38 x i8] c"Miller-Rabin/Fermat Primality Testing\00"
define i32 @main() {
%1 = tail call i32 @mpz_init(i32 undef)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @gmp_scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 undef)
%5 = tail call i64 @millerrabin(i32 undef)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%9 = tail call i64 @fermat(i32 undef)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %11)
ret i32 0
}