#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 */
unsigned int sqrt(unsigned int);
char isPrime(unsigned n) {
  unsigned i = 2;
  if (n == 2)
    return 1;
  while (i <= sqrt(n)) {
    if (n % i == 0)
      return 0;
    i++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<isPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1135 <isPrime+0x25>
movb   $0x1,-0x1(%rbp)
jmp    1181 <isPrime+0x71>
jmp    113a <isPrime+0x2a>
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
ja     117d <isPrime+0x6d>
mov    -0x8(%rbp),%eax
xor    %edx,%edx
divl   -0xc(%rbp)
cmp    $0x0,%edx
jne    116f <isPrime+0x5f>
movb   $0x0,-0x1(%rbp)
jmp    1181 <isPrime+0x71>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113a <isPrime+0x2a>
movb   $0x1,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isPrime>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%r14b
cmp    $0x2,%edi
je     114d <isPrime+0x3d>
mov    %edi,%ebp
call   1030 <sqrt@plt>
cmp    $0x2,%eax
jb     114d <isPrime+0x3d>
mov    $0x2,%ebx
nopl   (%rax)
mov    %ebp,%eax
xor    %edx,%edx
div    %ebx
test   %edx,%edx
je     114a <isPrime+0x3a>
add    $0x1,%ebx
mov    %ebp,%edi
call   1030 <sqrt@plt>
cmp    %eax,%ebx
jbe    1130 <isPrime+0x20>
jmp    114d <isPrime+0x3d>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @isPrime(i32 %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 2, i32* %4
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 2
br i1 %6, label %7, label %8
7: ; preds = %1
store i8 1, i8* %2
br label %24
8: ; preds = %1
br label %9
9: ; preds = %20, %8
%10 = load i32, i32* %4
%11 = load i32, i32* %3
%12 = call i32 @sqrt(i32 %11)
%13 = icmp ule i32 %10, %12
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = urem i32 %15, %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i8 0, i8* %2
br label %24
20: ; preds = %14
%21 = load i32, i32* %4
%22 = add i32 %21, 1
store i32 %22, i32* %4
br label %9
23: ; preds = %9
store i8 1, i8* %2
br label %24
24: ; preds = %23, %19, %7
%25 = load i8, i8* %2
ret i8 %25
}

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