#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 */
double sqrt(long double);
int is_prime(long double num) {
  int i;
  double sqrt_num;
  if (num == 2) {
    return 1;
  }
  i = 2;
  sqrt_num = sqrt(num);
  while (i <= sqrt_num) {
    if ((int)num % i == 0) {
      return 0;
    }
    i++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<is_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
fldt   0x10(%rbp)
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
flds   0xed9(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    114a <is_prime+0x3a>
jp     114a <is_prime+0x3a>
jmp    113e <is_prime+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    11c4 <is_prime+0xb4>
movl   $0x2,-0x24(%rbp)
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11bd <is_prime+0xad>
fldt   -0x20(%rbp)
fnstcw -0x36(%rbp)
movzwl -0x36(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x38(%rbp)
fldcw  -0x38(%rbp)
fistpl -0x34(%rbp)
fldcw  -0x36(%rbp)
mov    -0x34(%rbp),%eax
cltd
idivl  -0x24(%rbp)
cmp    $0x0,%edx
jne    11af <is_prime+0x9f>
movl   $0x0,-0x4(%rbp)
jmp    11c4 <is_prime+0xb4>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1163 <is_prime+0x53>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_prime>:
push   %rbx
sub    $0x30,%rsp
fldt   0x40(%rsp)
mov    $0x1,%ebx
flds   0xedc(%rip)
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
jne    1132 <is_prime+0x22>
jp     1132 <is_prime+0x22>
fstp   %st(0)
jmp    119d <is_prime+0x8d>
fld    %st(0)
fstpt  (%rsp)
fstpt  0x24(%rsp)
call   1030 <sqrt@plt>
fnstcw 0x1c(%rsp)
movzwl 0x1c(%rsp),%eax
or     $0xc00,%eax
mov    %ax,0x1e(%rsp)
fldcw  0x1e(%rsp)
fldt   0x24(%rsp)
fistpl 0x20(%rsp)
fldcw  0x1c(%rsp)
ucomisd 0xe9d(%rip),%xmm0
jb     119d <is_prime+0x8d>
mov    0x20(%rsp),%ecx
mov    $0x2,%esi
cs nopw 0x0(%rax,%rax,1)
mov    %ecx,%eax
cltd
idiv   %esi
test   %edx,%edx
je     119b <is_prime+0x8b>
add    $0x1,%esi
xorps  %xmm1,%xmm1
cvtsi2sd %esi,%xmm1
ucomisd %xmm1,%xmm0
jae    1180 <is_prime+0x70>
jmp    119d <is_prime+0x8d>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @is_prime(x86_fp80 %0) {
%2 = alloca i32
%3 = alloca x86_fp80
%4 = alloca i32
%5 = alloca double
store x86_fp80 %0, x86_fp80* %3
%6 = load x86_fp80, x86_fp80* %3
%7 = fcmp oeq x86_fp80 %6, 0xK40008000000000000000
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 1, i32* %2
br label %28
9: ; preds = %1
store i32 2, i32* %4
%10 = load x86_fp80, x86_fp80* %3
%11 = call double @sqrt(x86_fp80 %10)
store double %11, double* %5
br label %12
12: ; preds = %24, %9
%13 = load i32, i32* %4
%14 = sitofp i32 %13 to double
%15 = load double, double* %5
%16 = fcmp ole double %14, %15
br i1 %16, label %17, label %27
17: ; preds = %12
%18 = load x86_fp80, x86_fp80* %3
%19 = fptosi x86_fp80 %18 to i32
%20 = load i32, i32* %4
%21 = srem i32 %19, %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 0, i32* %2
br label %28
24: ; preds = %17
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %12
27: ; preds = %12
store i32 1, i32* %2
br label %28
28: ; preds = %27, %23, %8
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
define i32 @is_prime(x86_fp80 %0) {
%2 = fcmp oeq x86_fp80 %0, 0xK40008000000000000000
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = tail call double @sqrt(x86_fp80 %0)
%5 = fptosi x86_fp80 %0 to i32
%6 = fcmp ult double %4, 2.000000e+00
br i1 %6, label %15, label %10
7: ; preds = %10
%8 = sitofp i32 %14 to double
%9 = fcmp ult double %4, %8
br i1 %9, label %15, label %10
10: ; preds = %3, %7
%11 = phi i32 [ %14, %7 ], [ 2, %3 ]
%12 = srem i32 %5, %11
%13 = icmp eq i32 %12, 0
%14 = add nuw nsw i32 %11, 1
br i1 %13, label %15, label %7
15: ; preds = %10, %7, %3, %1
%16 = phi i32 [ 1, %1 ], [ 1, %3 ], [ 0, %10 ], [ 1, %7 ]
ret i32 %16
}