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


x86 assembly (clang, -O0):
<checkPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     1131 <checkPrime+0x21>
movl   $0x0,-0x4(%rbp)
jmp    1185 <checkPrime+0x75>
mov    -0x8(%rbp),%edi
call   1030 <sqrt@plt>
mov    %eax,-0x10(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    117e <checkPrime+0x6e>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    116b <checkPrime+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    1185 <checkPrime+0x75>
jmp    1170 <checkPrime+0x60>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <checkPrime+0x33>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkPrime>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
cmp    $0x2,%edi
jl     1145 <checkPrime+0x35>
mov    %edi,%ebp
call   1030 <sqrt@plt>
cmp    $0x3,%eax
jl     1140 <checkPrime+0x30>
mov    %eax,%ecx
mov    $0x2,%esi
nopl   (%rax)
mov    %ebp,%eax
cltd
idiv   %esi
test   %edx,%edx
je     1145 <checkPrime+0x35>
add    $0x1,%esi
cmp    %esi,%ecx
jne    1130 <checkPrime+0x20>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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