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


x86 assembly (clang, -O0):
<isPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x3,-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
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1171 <isPrime+0x61>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    115e <isPrime+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    1178 <isPrime+0x68>
jmp    1163 <isPrime+0x53>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1122 <isPrime+0x12>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isPrime>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
cvtsi2sd %edi,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x3,%ecx
jl     1165 <isPrime+0x55>
mov    $0x2,%ebx
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    %r14d,%eax
cltd
idiv   %ebx
mov    %edx,%ebp
test   %edx,%edx
je     115e <isPrime+0x4e>
movsd  0x8(%rsp),%xmm0
call   1030 <sqrt@plt>
cmp    %eax,%ebx
jl     1140 <isPrime+0x30>
xor    %eax,%eax
test   %ebp,%ebp
setne  %al
add    $0x10,%rsp
pop    %rbx
pop    %r14
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
store i32 3, i32* %4
br label %5
5: ; preds = %19, %1
%6 = load i32, i32* %4
%7 = load i32, i32* %3
%8 = sitofp i32 %7 to double
%9 = call i32 @sqrt(double %8)
%10 = add nsw i32 %9, 1
%11 = icmp slt i32 %6, %10
br i1 %11, label %12, label %22
12: ; preds = %5
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = srem i32 %13, %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 0, i32* %2
br label %23
18: ; preds = %12
br label %19
19: ; preds = %18
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %5
22: ; preds = %5
store i32 1, i32* %2
br label %23
23: ; preds = %22, %17
%24 = load i32, i32* %2
ret i32 %24
}

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