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


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

x86 assembly (clang, -O2):
<check_prime>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebx
cmp    $0x1,%edi
je     115f <check_prime+0x4f>
mov    %edi,%ebp
call   1030 <sqrt@plt>
cmp    $0x2,%eax
jl     115f <check_prime+0x4f>
mov    %eax,%ecx
neg    %ecx
mov    $0x2,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%eax
cltd
idiv   %esi
test   %edx,%edx
je     115d <check_prime+0x4d>
lea    (%rcx,%rsi,1),%eax
add    $0x1,%eax
mov    %esi,%edx
add    $0x1,%edx
mov    %edx,%esi
cmp    $0x1,%eax
jne    1140 <check_prime+0x30>
jmp    115f <check_prime+0x4f>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @check_prime(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 eq i32 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 1, i32* %2
br label %27
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 @sqrt(i32 %10)
store i32 %11, i32* %4
store i32 2, i32* %5
br label %12
12: ; preds = %23, %9
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = load i32, i32* %3
%18 = load i32, i32* %5
%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* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
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 @check_prime(i32 %0) {
%2 = icmp eq i32 %0, 1
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = tail call i32 @sqrt(i32 %0)
%5 = icmp slt i32 %4, 2
br i1 %5, label %13, label %9
6: ; preds = %9
%7 = add nuw i32 %10, 1
%8 = icmp eq i32 %10, %4
br i1 %8, label %13, label %9
9: ; preds = %3, %6
%10 = phi i32 [ %7, %6 ], [ 2, %3 ]
%11 = srem i32 %0, %10
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %6
13: ; preds = %9, %6, %3, %1
%14 = phi i32 [ 1, %1 ], [ 1, %3 ], [ 0, %9 ], [ 1, %6 ]
ret i32 %14
}