#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 sqrt(int);
int isPrime(int n) {
  int i = 0;
  if (n <= 1)
    return 0;
  else
    for (i = 2; i <= sqrt(n); i++) {
      if (n % i == 0)
        return 0;
    }
  return 1;
}


x86 assembly (clang, -O0):
<isPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     1138 <isPrime+0x28>
movl   $0x0,-0x4(%rbp)
jmp    1195 <isPrime+0x85>
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jg     1189 <isPrime+0x79>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1176 <isPrime+0x66>
movl   $0x0,-0x4(%rbp)
jmp    1195 <isPrime+0x85>
jmp    117b <isPrime+0x6b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113f <isPrime+0x2f>
jmp    118e <isPrime+0x7e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isPrime>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jge    111c <isPrime+0xc>
xor    %eax,%eax
jmp    115c <isPrime+0x4c>
mov    %edi,%ebx
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x2,%ecx
jl     115c <isPrime+0x4c>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebp
mov    %ebx,%eax
cltd
idiv   %ebp
test   %edx,%edx
je     1118 <isPrime+0x8>
mov    %ebx,%edi
call   1030 <sqrt@plt>
cmp    %eax,%ebp
jl     1140 <isPrime+0x30>
mov    $0x1,%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
store i32 %0, i32* %3
store i32 0, i32* %4
%5 = load i32, i32* %3
%6 = icmp sle i32 %5, 1
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 0, i32* %2
br label %26
8: ; preds = %1
store i32 2, i32* %4
br label %9
9: ; preds = %21, %8
%10 = load i32, i32* %4
%11 = load i32, i32* %3
%12 = call i32 @sqrt(i32 %11)
%13 = icmp sle i32 %10, %12
br i1 %13, label %14, label %24
14: ; preds = %9
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = srem i32 %15, %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 0, i32* %2
br label %26
20: ; preds = %14
br label %21
21: ; preds = %20
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %9
24: ; preds = %9
br label %25
25: ; preds = %24
store i32 1, i32* %2
br label %26
26: ; preds = %25, %19, %7
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
define i32 @isPrime(i32 %0) {
%2 = icmp slt i32 %0, 2
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = tail call i32 @sqrt(i32 %0)
%5 = icmp slt i32 %4, 2
br i1 %5, label %14, label %10
6: ; preds = %10
%7 = add nuw nsw i32 %11, 1
%8 = tail call i32 @sqrt(i32 %0)
%9 = icmp slt i32 %11, %8
br i1 %9, label %10, label %14
10: ; preds = %3, %6
%11 = phi i32 [ %7, %6 ], [ 2, %3 ]
%12 = srem i32 %0, %11
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %10, %6, %3, %1
%15 = phi i32 [ 0, %1 ], [ 1, %3 ], [ 0, %10 ], [ 1, %6 ]
ret i32 %15
}