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


x86 assembly (clang, -O0):
<isPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jg     117d <isPrime+0x6d>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    1167 <isPrime+0x57>
movb   $0x1,-0x1(%rbp)
jmp    1181 <isPrime+0x71>
jmp    116c <isPrime+0x5c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1124 <isPrime+0x14>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isPrime>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <sqrt@plt>
test   %eax,%eax
jle    116f <isPrime+0x5f>
mov    $0x1,%ebx
jmp    114e <isPrime+0x3e>
nopw   0x0(%rax,%rax,1)
mov    %r14d,%eax
xor    %edx,%edx
div    %ebx
test   %rdx,%rdx
je     116b <isPrime+0x5b>
mov    %r14,%rdi
call   1030 <sqrt@plt>
add    $0x1,%eax
cltq
cmp    %rax,%rbx
jge    116f <isPrime+0x5f>
add    $0x1,%rbx
mov    %r14,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     1130 <isPrime+0x20>
mov    %r14,%rax
cqto
idiv   %rbx
test   %rdx,%rdx
jne    113c <isPrime+0x2c>
mov    $0x1,%al
jmp    1171 <isPrime+0x61>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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