#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);
int IsPrime(unsigned long test_num) {
  int is_prime;
  if (test_num != 1) {
    is_prime = 1;
    float k_max = sqrtf(test_num);
    for (unsigned long k = 2; k <= k_max; k++) {
      if (test_num % k == 0) {
        is_prime = 0;
        break;
      }
    }
  } else {
    is_prime = 0;
  }
  return is_prime;
}


x86 assembly (clang, -O0):
<IsPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x1,-0x8(%rbp)
je     11d1 <IsPrime+0xc1>
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     1181 <IsPrime+0x71>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm1
movss  -0x10(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     11cc <IsPrime+0xbc>
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
jne    11b6 <IsPrime+0xa6>
movl   $0x0,-0xc(%rbp)
jmp    11cc <IsPrime+0xbc>
jmp    11bb <IsPrime+0xab>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1144 <IsPrime+0x34>
jmp    11d8 <IsPrime+0xc8>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IsPrime>:
push   %rbx
xor    %ecx,%ecx
cmp    $0x1,%rdi
je     119d <IsPrime+0x8d>
mov    %rdi,%rbx
call   1030 <sqrtf@plt>
mov    $0x1,%ecx
ucomiss 0xecf(%rip),%xmm0
jb     119d <IsPrime+0x8d>
mov    $0x2,%esi
jmp    1175 <IsPrime+0x65>
nopw   0x0(%rax,%rax,1)
xorps  %xmm1,%xmm1
cvtsi2ss %rsi,%xmm1
ucomiss %xmm1,%xmm0
jae    1175 <IsPrime+0x65>
jmp    119d <IsPrime+0x8d>
nop
add    $0x1,%rsi
jns    1140 <IsPrime+0x30>
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     119d <IsPrime+0x8d>
mov    %rbx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1190 <IsPrime+0x80>
mov    %rbx,%rax
xor    %edx,%edx
div    %rsi
test   %rdx,%rdx
jne    1150 <IsPrime+0x40>
jmp    119b <IsPrime+0x8b>
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
test   %rdx,%rdx
jne    1150 <IsPrime+0x40>
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
%6 = load i64, i64* %2
%7 = icmp ne i64 %6, 1
br i1 %7, label %8, label %27
8: ; preds = %1
store i32 1, i32* %3
%9 = load i64, i64* %2
%10 = call float @sqrtf(i64 %9)
store float %10, float* %4
store i64 2, i64* %5
br label %11
11: ; preds = %23, %8
%12 = load i64, i64* %5
%13 = uitofp i64 %12 to float
%14 = load float, float* %4
%15 = fcmp ole float %13, %14
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = load i64, i64* %2
%18 = load i64, i64* %5
%19 = urem i64 %17, %18
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 0, i32* %3
br label %26
22: ; preds = %16
br label %23
23: ; preds = %22
%24 = load i64, i64* %5
%25 = add i64 %24, 1
store i64 %25, i64* %5
br label %11
26: ; preds = %21, %11
br label %28
27: ; preds = %1
store i32 0, i32* %3
br label %28
28: ; preds = %27, %26
%29 = load i32, i32* %3
ret i32 %29
}

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