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


x86 assembly (clang, -O0):
<isPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <sqrt@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <sqrt@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
cmp    $0x0,%eax
jne    115a <isPrime+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    11ba <isPrime+0x9a>
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jae    11b3 <isPrime+0x93>
mov    -0x8(%rbp),%eax
xor    %edx,%edx
divl   -0xc(%rbp)
cmp    $0x0,%edx
jne    11a0 <isPrime+0x80>
movl   $0x0,-0x4(%rbp)
jmp    11ba <isPrime+0x9a>
jmp    11a5 <isPrime+0x85>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1161 <isPrime+0x41>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isPrime>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
call   1040 <sqrt@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <sqrt@plt>
xor    %ecx,%ecx
cmp    %eax,%ebp
je     1186 <isPrime+0x66>
mov    %ebx,%edi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
cmp    $0x3,%eax
jb     1181 <isPrime+0x61>
mov    $0x2,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ecx,%ecx
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
test   %edx,%edx
je     1186 <isPrime+0x66>
add    $0x1,%ebp
mov    %ebx,%edi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
cmp    %eax,%ebp
jb     1160 <isPrime+0x40>
mov    $0x1,%ecx
mov    %ecx,%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
%5 = load i32, i32* %3
%6 = call i32 @sqrt(i32 %5)
%7 = load i32, i32* %3
%8 = call i32 @sqrt(i32 %7)
%9 = sub i32 %6, %8
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %30
12: ; preds = %1
store i32 2, i32* %4
br label %13
13: ; preds = %26, %12
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = call i32 @sqrt(i32 %15)
%17 = call i32 @ceil(i32 %16)
%18 = icmp ult i32 %14, %17
br i1 %18, label %19, label %29
19: ; preds = %13
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = urem i32 %20, %21
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 0, i32* %2
br label %30
25: ; preds = %19
br label %26
26: ; preds = %25
%27 = load i32, i32* %4
%28 = add i32 %27, 1
store i32 %28, i32* %4
br label %13
29: ; preds = %13
store i32 1, i32* %2
br label %30
30: ; preds = %29, %24, %11
%31 = load i32, i32* %2
ret i32 %31
}

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