#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 */
float sqrtf(unsigned long);
bool IsPrime(unsigned long test_num) {
  bool is_prime = true;
  float k_max = sqrtf(test_num);
  for (unsigned long k = 2; k <= k_max; k++) {
    if (test_num % k == 0) {
      is_prime = false;
      break;
    }
  }
  return is_prime;
}


x86 assembly (clang, -O0):
<IsPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <sqrtf@plt>
movss  %xmm0,-0x10(%rbp)
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x20(%rbp)
test   %rax,%rax
movss  %xmm0,-0x1c(%rbp)
js     1176 <IsPrime+0x66>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm1
movss  -0x10(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     11c1 <IsPrime+0xb1>
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
jne    11ab <IsPrime+0x9b>
movl   $0x0,-0xc(%rbp)
jmp    11c1 <IsPrime+0xb1>
jmp    11b0 <IsPrime+0xa0>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1139 <IsPrime+0x29>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IsPrime>:
push   %rbx
mov    %rdi,%rbx
call   1030 <sqrtf@plt>
mov    $0x1,%ecx
ucomiss 0xedb(%rip),%xmm0
jb     118d <IsPrime+0x7d>
mov    $0x2,%esi
jmp    1165 <IsPrime+0x55>
xchg   %ax,%ax
xorps  %xmm1,%xmm1
cvtsi2ss %rsi,%xmm1
ucomiss %xmm1,%xmm0
jae    1165 <IsPrime+0x55>
jmp    118d <IsPrime+0x7d>
nop
add    $0x1,%rsi
jns    1130 <IsPrime+0x20>
mov    %rsi,%rax
shr    %rax
mov    %esi,%edx
and    $0x1,%edx
or     %rax,%rdx
xorps  %xmm1,%xmm1
cvtsi2ss %rdx,%xmm1
addss  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     118d <IsPrime+0x7d>
mov    %rbx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1180 <IsPrime+0x70>
mov    %rbx,%rax
xor    %edx,%edx
div    %rsi
test   %rdx,%rdx
jne    1140 <IsPrime+0x30>
jmp    118b <IsPrime+0x7b>
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
test   %rdx,%rdx
jne    1140 <IsPrime+0x30>
xor    %ecx,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @IsPrime(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca float
%5 = alloca i64
store i64 %0, i64* %2
store i32 1, i32* %3
%6 = load i64, i64* %2
%7 = call float @sqrtf(i64 %6)
store float %7, float* %4
store i64 2, i64* %5
br label %8
8: ; preds = %20, %1
%9 = load i64, i64* %5
%10 = uitofp i64 %9 to float
%11 = load float, float* %4
%12 = fcmp ole float %10, %11
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = load i64, i64* %2
%15 = load i64, i64* %5
%16 = urem i64 %14, %15
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 0, i32* %3
br label %23
19: ; preds = %13
br label %20
20: ; preds = %19
%21 = load i64, i64* %5
%22 = add i64 %21, 1
store i64 %22, i64* %5
br label %8
23: ; preds = %18, %8
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @IsPrime(i64 %0) {
%2 = tail call float @sqrtf(i64 %0)
%3 = fcmp ult float %2, 2.000000e+00
br i1 %3, label %12, label %7
4: ; preds = %7
%5 = uitofp i64 %11 to float
%6 = fcmp ult float %2, %5
br i1 %6, label %12, label %7
7: ; preds = %1, %4
%8 = phi i64 [ %11, %4 ], [ 2, %1 ]
%9 = urem i64 %0, %8
%10 = icmp eq i64 %9, 0
%11 = add i64 %8, 1
br i1 %10, label %12, label %4
12: ; preds = %4, %7, %1
%13 = phi i32 [ 1, %1 ], [ 0, %7 ], [ 1, %4 ]
ret i32 %13
}