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


x86 assembly (clang, -O0):
<BPU_isPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1131 <BPU_isPrime+0x21>
movl   $0x1,-0x4(%rbp)
jmp    118b <BPU_isPrime+0x7b>
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jg     1184 <BPU_isPrime+0x74>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1171 <BPU_isPrime+0x61>
movl   $0x0,-0x4(%rbp)
jmp    118b <BPU_isPrime+0x7b>
jmp    1176 <BPU_isPrime+0x66>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1138 <BPU_isPrime+0x28>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BPU_isPrime>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebp
cmp    $0x2,%edi
je     1163 <BPU_isPrime+0x53>
mov    %edi,%ebx
cvtsi2sd %edi,%xmm0
movsd  %xmm0,(%rsp)
call   1030 <sqrt@plt>
cmp    $0x2,%eax
jl     1163 <BPU_isPrime+0x53>
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %ebx,%eax
cltd
idiv   %ebp
test   %edx,%edx
je     1161 <BPU_isPrime+0x51>
movsd  (%rsp),%xmm0
call   1030 <sqrt@plt>
cmp    %eax,%ebp
jl     1140 <BPU_isPrime+0x30>
mov    $0x1,%ebp
jmp    1163 <BPU_isPrime+0x53>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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