#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
scalar_t__ sqrt(int);
int isPrime(int n) {
  int high = (int)sqrt(n);
  int i;
  if (n <= 2) {
    printf("%d is a prime number\n", n);
    return 1;
  }
  if (n % 2 == 0)
    return 0;
  for (i = 3; i <= high; i += 2) {
    if (n % i == 0)
      return 0;
  }
  printf("%d is a prime number\n", n);
  return 1;
}


x86 assembly (clang, -O0):
<isPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <sqrt@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0x8(%rbp)
jg     115b <isPrime+0x3b>
mov    -0x8(%rbp),%esi
lea    0xeb6(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d3 <isPrime+0xb3>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117b <isPrime+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <isPrime+0xb3>
movl   $0x3,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11bd <isPrime+0x9d>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11aa <isPrime+0x8a>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <isPrime+0xb3>
jmp    11af <isPrime+0x8f>
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    1182 <isPrime+0x62>
mov    -0x8(%rbp),%esi
lea    0xe39(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isPrime>:
push   %rbx
mov    %edi,%ebx
call   1040 <sqrt@plt>
cmp    $0x3,%ebx
jl     1160 <isPrime+0x40>
xor    %ecx,%ecx
test   $0x1,%bl
je     1173 <isPrime+0x53>
mov    %rax,%rsi
cmp    $0x3,%esi
jl     1160 <isPrime+0x40>
mov    $0x3,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
cltd
idiv   %edi
test   %edx,%edx
je     1173 <isPrime+0x53>
add    $0x2,%edi
cmp    %esi,%edi
jle    1150 <isPrime+0x30>
lea    0xe99(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0x1,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"%d is a prime number\0A\00"
define i32 @isPrime(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = call i64 @sqrt(i32 %6)
%8 = trunc i64 %7 to i32
store i32 %8, i32* %4
%9 = load i32, i32* %3
%10 = icmp sle i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* %3
%13 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 1, i32* %2
br label %37
14: ; preds = %1
%15 = load i32, i32* %3
%16 = srem i32 %15, 2
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 0, i32* %2
br label %37
19: ; preds = %14
store i32 3, i32* %5
br label %20
20: ; preds = %31, %19
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %34
24: ; preds = %20
%25 = load i32, i32* %3
%26 = load i32, i32* %5
%27 = srem i32 %25, %26
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 0, i32* %2
br label %37
30: ; preds = %24
br label %31
31: ; preds = %30
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 2
store i32 %33, i32* %5
br label %20
34: ; preds = %20
%35 = load i32, i32* %3
%36 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %35)
store i32 1, i32* %2
br label %37
37: ; preds = %34, %29, %18, %11
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@.str = [22 x i8] c"%d is a prime number\0A\00"
define i32 @isPrime(i32 %0) {
%2 = tail call i64 @sqrt(i32 %0)
%3 = trunc i64 %2 to i32
%4 = icmp slt i32 %0, 3
br i1 %4, label %17, label %5
5: ; preds = %1
%6 = and i32 %0, 1
%7 = icmp eq i32 %6, 0
br i1 %7, label %19, label %8
8: ; preds = %5
%9 = icmp slt i32 %3, 3
br i1 %9, label %17, label %12
10: ; preds = %12
%11 = icmp sgt i32 %16, %3
br i1 %11, label %17, label %12
12: ; preds = %8, %10
%13 = phi i32 [ %16, %10 ], [ 3, %8 ]
%14 = srem i32 %0, %13
%15 = icmp eq i32 %14, 0
%16 = add nuw nsw i32 %13, 2
br i1 %15, label %19, label %10
17: ; preds = %10, %8, %1
%18 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %19
19: ; preds = %12, %17, %5
%20 = phi i32 [ 0, %5 ], [ 1, %17 ], [ 0, %12 ]
ret i32 %20
}