#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 */
long long ceil(int /*<<< orphan*/);
int /*<<< orphan*/ sqrt(long long);
int prime(long long x) {
  long long i;
  long long sqrtx = ceil(sqrt(x));
  for (i = 2; i < sqrtx; i++) {
    if (x % i == 0)
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<prime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %rax,-0x20(%rbp)
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    118c <prime+0x6c>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0x0,%rdx
jne    1176 <prime+0x56>
movl   $0x0,-0x4(%rbp)
jmp    1193 <prime+0x73>
jmp    117b <prime+0x5b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1148 <prime+0x28>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prime>:
push   %rbx
mov    %rdi,%rbx
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
mov    $0x1,%ecx
cmp    $0x3,%rax
jl     1188 <prime+0x68>
mov    %rax,%rsi
mov    $0x2,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rax
or     %rdi,%rax
shr    $0x20,%rax
je     1170 <prime+0x50>
mov    %rbx,%rax
cqto
idiv   %rdi
test   %rdx,%rdx
jne    117b <prime+0x5b>
jmp    1186 <prime+0x66>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %edi
test   %rdx,%rdx
je     1186 <prime+0x66>
add    $0x1,%rdi
cmp    %rdi,%rsi
jne    1150 <prime+0x30>
jmp    1188 <prime+0x68>
xor    %ecx,%ecx
mov    %ecx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @prime(i64 %0) {
%2 = tail call i32 @sqrt(i64 %0)
%3 = tail call i64 @ceil(i32 %2)
%4 = icmp sgt i64 %3, 2
br i1 %4, label %7, label %12
5: ; preds = %7
%6 = icmp eq i64 %11, %3
br i1 %6, label %12, label %7
7: ; preds = %1, %5
%8 = phi i64 [ %11, %5 ], [ 2, %1 ]
%9 = srem i64 %0, %8
%10 = icmp eq i64 %9, 0
%11 = add nuw nsw i64 %8, 1
br i1 %10, label %12, label %5
12: ; preds = %7, %5, %1
%13 = phi i32 [ 1, %1 ], [ 1, %5 ], [ 0, %7 ]
ret i32 %13
}