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

/* Variables and functions */
int MillerRabin(int, int *, int);
bool IsPrime(uint32_t n) {
  if ((!(n % 2)) || (n <= 1))
    return false;
  if (n < 2047) {
    uint32_t g[1] = {2};
    return MillerRabin(n, g, 1);
  }
  if (n < 1373653) {
    uint32_t g[2] = {2, 3};
    return MillerRabin(n, g, 2);
  }
  if (n < 9080191) {
    uint32_t g[2] = {31, 73};
    return MillerRabin(n, g, 2);
  }
  if (n < 25326001) {
    uint32_t g[3] = {2, 3, 5};
    return MillerRabin(n, g, 3);
  }
  if (n < 4759123141) {
    uint32_t g[3] = {2, 7, 61};
    return MillerRabin(n, g, 3);
  }
}


x86 assembly (clang, -O0):
<IsPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1139 <IsPrime+0x29>
cmpl   $0x1,-0x8(%rbp)
jg     1145 <IsPrime+0x35>
movl   $0x0,-0x4(%rbp)
jmp    124f <IsPrime+0x13f>
cmpl   $0x7ff,-0x8(%rbp)
jge    1174 <IsPrime+0x64>
mov    0xea8(%rip),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
call   1030 <MillerRabin@plt>
mov    %eax,-0x4(%rbp)
jmp    124f <IsPrime+0x13f>
cmpl   $0x14f5d5,-0x8(%rbp)
jge    11a5 <IsPrime+0x95>
mov    0xe7c(%rip),%rax
mov    %rax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x2,%edx
call   1030 <MillerRabin@plt>
mov    %eax,-0x4(%rbp)
jmp    124f <IsPrime+0x13f>
cmpl   $0x8a8d7f,-0x8(%rbp)
jge    11d6 <IsPrime+0xc6>
mov    0xe53(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x2,%edx
call   1030 <MillerRabin@plt>
mov    %eax,-0x4(%rbp)
jmp    124f <IsPrime+0x13f>
cmpl   $0x18271b1,-0x8(%rbp)
jge    1210 <IsPrime+0x100>
mov    0xe2a(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe28(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x3,%edx
call   1030 <MillerRabin@plt>
mov    %eax,-0x4(%rbp)
jmp    124f <IsPrime+0x13f>
movslq -0x8(%rbp),%rax
movabs $0x11baa74c5,%rcx
cmp    %rcx,%rax
jge    124f <IsPrime+0x13f>
mov    0xdf2(%rip),%rax
mov    %rax,-0x34(%rbp)
mov    0xdf0(%rip),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0x3,%edx
call   1030 <MillerRabin@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IsPrime>:
sub    $0x18,%rsp
xor    %eax,%eax
cmp    $0x2,%edi
jl     11bd <IsPrime+0xad>
mov    %edi,%ecx
and    $0x1,%ecx
je     11bd <IsPrime+0xad>
cmp    $0x7fe,%edi
ja     1146 <IsPrime+0x36>
movl   $0x2,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
jmp    11b8 <IsPrime+0xa8>
cmp    $0x14f5d4,%edi
ja     115a <IsPrime+0x4a>
movabs $0x300000002,%rax
jmp    116c <IsPrime+0x5c>
cmp    $0x8a8d7e,%edi
ja     117d <IsPrime+0x6d>
movabs $0x490000001f,%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x2,%edx
jmp    11b8 <IsPrime+0xa8>
cmp    $0x18271b0,%edi
ja     1198 <IsPrime+0x88>
mov    0xe7d(%rip),%eax
mov    %eax,0x10(%rsp)
mov    0xe6a(%rip),%rax
jmp    11a9 <IsPrime+0x99>
mov    0xe76(%rip),%eax
mov    %eax,0x10(%rsp)
mov    0xe63(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x3,%edx
call   1030 <MillerRabin@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@__const.IsPrime.g = [1 x i32] [i32 2]
@__const.IsPrime.g.1 = [2 x i32] [i32 2, i32 3]
@__const.IsPrime.g.2 = [2 x i32] [i32 31, i32 73]
@__const.IsPrime.g.3 = [3 x i32] [i32 2, i32 3, i32 5]
@__const.IsPrime.g.4 = [3 x i32] [i32 2, i32 7, i32 61]
define i32 @IsPrime(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1 x i32]
%5 = alloca [2 x i32]
%6 = alloca [2 x i32]
%7 = alloca [3 x i32]
%8 = alloca [3 x i32]
store i32 %0, i32* %3
%9 = load i32, i32* %3
%10 = srem i32 %9, 2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* %3
%14 = icmp sle i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %12, %1
store i32 0, i32* %2
br label %57
16: ; preds = %12
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 2047
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = bitcast [1 x i32]* %4 to i8*
%21 = load i32, i32* %3
%22 = getelementptr inbounds [1 x i32], [1 x i32]* %4, i64 0, i64 0
%23 = call i32 @MillerRabin(i32 %21, i32* %22, i32 1)
store i32 %23, i32* %2
br label %57
24: ; preds = %16
%25 = load i32, i32* %3
%26 = icmp slt i32 %25, 1373653
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = bitcast [2 x i32]* %5 to i8*
%29 = load i32, i32* %3
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%31 = call i32 @MillerRabin(i32 %29, i32* %30, i32 2)
store i32 %31, i32* %2
br label %57
32: ; preds = %24
%33 = load i32, i32* %3
%34 = icmp slt i32 %33, 9080191
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = bitcast [2 x i32]* %6 to i8*
%37 = load i32, i32* %3
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%39 = call i32 @MillerRabin(i32 %37, i32* %38, i32 2)
store i32 %39, i32* %2
br label %57
40: ; preds = %32
%41 = load i32, i32* %3
%42 = icmp slt i32 %41, 25326001
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = bitcast [3 x i32]* %7 to i8*
%45 = load i32, i32* %3
%46 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%47 = call i32 @MillerRabin(i32 %45, i32* %46, i32 3)
store i32 %47, i32* %2
br label %57
48: ; preds = %40
%49 = load i32, i32* %3
%50 = sext i32 %49 to i64
%51 = icmp slt i64 %50, 4759123141
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = bitcast [3 x i32]* %8 to i8*
%54 = load i32, i32* %3
%55 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
%56 = call i32 @MillerRabin(i32 %54, i32* %55, i32 3)
store i32 %56, i32* %2
br label %57
57: ; preds = %15, %19, %27, %35, %43, %52, %48
%58 = load i32, i32* %2
ret i32 %58
}

LLVM IR (-O2):
@__const.IsPrime.g.3 = [3 x i32] [i32 2, i32 3, i32 5]
@__const.IsPrime.g.4 = [3 x i32] [i32 2, i32 7, i32 61]
define i32 @IsPrime(i32 %0) {
%2 = alloca [1 x i32]
%3 = alloca i64
%4 = alloca i64
%5 = alloca [3 x i32]
%6 = alloca [3 x i32]
%7 = and i32 %0, 1
%8 = icmp eq i32 %7, 0
%9 = icmp slt i32 %0, 2
%10 = or i1 %9, %8
br i1 %10, label %39, label %11
11: ; preds = %1
%12 = icmp ult i32 %0, 2047
br i1 %12, label %13, label %17
13: ; preds = %11
%14 = bitcast [1 x i32]* %2 to i8*
%15 = getelementptr inbounds [1 x i32], [1 x i32]* %2, i64 0, i64 0
store i32 2, i32* %15
%16 = call i32 @MillerRabin(i32 %0, i32* %15, i32 1)
br label %39
17: ; preds = %11
%18 = icmp ult i32 %0, 1373653
br i1 %18, label %19, label %23
19: ; preds = %17
%20 = bitcast i64* %3 to i8*
store i64 12884901890, i64* %3
%21 = bitcast i64* %3 to i32*
%22 = call i32 @MillerRabin(i32 %0, i32* %21, i32 2)
br label %39
23: ; preds = %17
%24 = icmp ult i32 %0, 9080191
br i1 %24, label %25, label %29
25: ; preds = %23
%26 = bitcast i64* %4 to i8*
store i64 313532612639, i64* %4
%27 = bitcast i64* %4 to i32*
%28 = call i32 @MillerRabin(i32 %0, i32* %27, i32 2)
br label %39
29: ; preds = %23
%30 = icmp ult i32 %0, 25326001
br i1 %30, label %31, label %35
31: ; preds = %29
%32 = bitcast [3 x i32]* %5 to i8*
%33 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%34 = call i32 @MillerRabin(i32 %0, i32* %33, i32 3)
br label %39
35: ; preds = %29
%36 = bitcast [3 x i32]* %6 to i8*
%37 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
%38 = call i32 @MillerRabin(i32 %0, i32* %37, i32 3)
br label %39
39: ; preds = %1, %13, %19, %25, %31, %35
%40 = phi i32 [ %16, %13 ], [ %22, %19 ], [ %28, %25 ], [ %34, %31 ], [ %38, %35 ], [ 0, %1 ]
ret i32 %40
}