#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 is_prime(int n) {
  if (n < 4)
    return 1;
  if (!(n % 2))
    return 0;
  for (int a = 3; a < (int)(sqrt(n)) + 1; a++)
    if (!(n % a))
      return 0;
  return 1;
}


x86 assembly (clang, -O0):
<is_prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1131 <is_prime+0x21>
movl   $0x1,-0x4(%rbp)
jmp    11b0 <is_prime+0xa0>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1151 <is_prime+0x41>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <is_prime+0xa0>
movl   $0x3,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
call   1030 <sqrt@plt>
mov    -0x10(%rbp),%eax
cvttsd2si %xmm0,%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11a9 <is_prime+0x99>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1196 <is_prime+0x86>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <is_prime+0xa0>
jmp    119b <is_prime+0x8b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1158 <is_prime+0x48>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_prime>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%eax
cmp    $0x4,%edi
jl     11d2 <is_prime+0xc2>
mov    %edi,%r14d
xor    %eax,%eax
test   $0x1,%r14b
je     11d2 <is_prime+0xc2>
cvtsi2sd %r14d,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
movsd  %xmm1,(%rsp)
jb     1152 <is_prime+0x42>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    1160 <is_prime+0x50>
movapd %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  (%rsp),%xmm1
cvttsd2si %xmm0,%ecx
mov    $0x1,%eax
cmp    $0x3,%ecx
jl     11d2 <is_prime+0xc2>
mov    $0x2,%ebx
sqrtsd %xmm1,%xmm2
xorpd  %xmm3,%xmm3
movsd  %xmm2,0x8(%rsp)
jmp    1198 <is_prime+0x88>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cvttsd2si %xmm0,%eax
cmp    %eax,%ebx
jge    11cb <is_prime+0xbb>
add    $0x1,%ebx
mov    %r14d,%eax
cltd
idiv   %ebx
mov    %edx,%ebp
test   %edx,%edx
je     11cb <is_prime+0xbb>
ucomisd %xmm3,%xmm1
movapd %xmm2,%xmm0
jae    1190 <is_prime+0x80>
movapd %xmm1,%xmm0
call   1030 <sqrt@plt>
xorpd  %xmm3,%xmm3
movsd  0x8(%rsp),%xmm2
movsd  (%rsp),%xmm1
jmp    1190 <is_prime+0x80>
xor    %eax,%eax
test   %ebp,%ebp
setne  %al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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