#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(int);
int is_prime_number(int n) {
  int limit = sqrt(n) + 1;
  for (int i = 2; i <= limit; i++) {
    if (n % i == 0)
      return 0;
  }
  return (n > 1) ? 1 : 0;
}


x86 assembly (clang, -O0):
<is_prime_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <sqrt@plt>
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     116b <is_prime_number+0x5b>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    1158 <is_prime_number+0x48>
movl   $0x0,-0x4(%rbp)
jmp    117e <is_prime_number+0x6e>
jmp    115d <is_prime_number+0x4d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1130 <is_prime_number+0x20>
mov    -0x8(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x1,%edx
cmovg  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_prime_number>:
push   %rbx
mov    %edi,%ebx
call   1030 <sqrt@plt>
test   %eax,%eax
jle    114b <is_prime_number+0x3b>
mov    %eax,%ecx
neg    %ecx
mov    $0x2,%esi
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%eax
cltd
idiv   %esi
test   %edx,%edx
je     1155 <is_prime_number+0x45>
lea    (%rcx,%rsi,1),%eax
add    $0x1,%eax
mov    %esi,%edx
add    $0x1,%edx
mov    %edx,%esi
cmp    $0x2,%eax
jne    1130 <is_prime_number+0x20>
xor    %eax,%eax
cmp    $0x2,%ebx
setge  %al
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

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