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


x86 assembly (clang, -O0):
<prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1145 <prime+0x35>
cmpl   $0x2,-0x8(%rbp)
je     1145 <prime+0x35>
movl   $0x0,-0x4(%rbp)
jmp    119d <prime+0x8d>
movl   $0x3,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jg     1196 <prime+0x86>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1183 <prime+0x73>
movl   $0x0,-0x4(%rbp)
jmp    119d <prime+0x8d>
jmp    1188 <prime+0x78>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    114c <prime+0x3c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prime>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
xor    %r14d,%r14d
cmp    $0x2,%edi
je     1125 <prime+0x15>
mov    %ebp,%eax
and    $0x1,%eax
je     115d <prime+0x4d>
mov    %ebp,%edi
call   1030 <sqrt@plt>
cmp    $0x3,%eax
jl     1157 <prime+0x47>
mov    $0x3,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%eax
cltd
idiv   %ebx
test   %edx,%edx
je     115d <prime+0x4d>
add    $0x2,%ebx
mov    %ebp,%edi
call   1030 <sqrt@plt>
cmp    %eax,%ebx
jle    1140 <prime+0x30>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @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 = srem i32 %6, 2
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 0, i32* %2
br label %30
13: ; preds = %9, %1
store i32 3, i32* %4
br label %14
14: ; preds = %26, %13
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = call i32 @sqrt(i32 %16)
%18 = icmp sle i32 %15, %17
br i1 %18, label %19, label %29
19: ; preds = %14
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = srem 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 nsw i32 %27, 2
store i32 %28, i32* %4
br label %14
29: ; preds = %14
store i32 1, i32* %2
br label %30
30: ; preds = %29, %24, %12
%31 = load i32, i32* %2
ret i32 %31
}

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