#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 abs(int);
int pow(int, double);
int isprime(int n) {
  int i;
  n = abs(n);
  if (n < 2)
    return (0);
  if (n == 2)
    return (1);
  if (n % 2 == 0)
    return (0);
  for (i = 3; i <= pow(n, 0.5) + 1; i += 2)
    if (n % i == 0)
      return (0);
  return (1);
}


x86 assembly (clang, -O0):
<isprime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    114c <isprime+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <isprime+0xc5>
cmpl   $0x2,-0x8(%rbp)
jne    1162 <isprime+0x42>
movl   $0x1,-0x4(%rbp)
jmp    11e5 <isprime+0xc5>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1182 <isprime+0x62>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <isprime+0xc5>
movl   $0x3,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
movsd  0xe66(%rip),%xmm0
call   1040 <pow@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jg     11de <isprime+0xbe>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11cb <isprime+0xab>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <isprime+0xc5>
jmp    11d0 <isprime+0xb0>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    1189 <isprime+0x69>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isprime>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
neg    %ebx
cmovs  %edi,%ebx
xor    %ecx,%ecx
cmp    $0x2,%ebx
jb     1148 <isprime+0x38>
jne    112a <isprime+0x1a>
mov    $0x1,%ecx
jmp    1148 <isprime+0x38>
test   $0x1,%bl
je     1148 <isprime+0x38>
movsd  0xec9(%rip),%xmm0
mov    %ebx,%edi
call   1030 <pow@plt>
mov    $0x1,%ecx
cmp    $0x2,%eax
jge    1151 <isprime+0x41>
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
add    $0x2,%ebp
xor    %ecx,%ecx
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
test   %edx,%edx
je     1148 <isprime+0x38>
mov    %ebx,%edi
movsd  0xe87(%rip),%xmm0
call   1030 <pow@plt>
cmp    %eax,%ebp
jl     1160 <isprime+0x50>
jmp    1123 <isprime+0x13>

LLVM IR (-O0):
define i32 @isprime(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @abs(i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %37
10: ; preds = %1
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 1, i32* %2
br label %37
14: ; preds = %10
%15 = load i32, i32* %3
%16 = srem i32 %15, 2
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 0, i32* %2
br label %37
19: ; preds = %14
store i32 3, i32* %4
br label %20
20: ; preds = %33, %19
%21 = load i32, i32* %4
%22 = load i32, i32* %3
%23 = call i32 @pow(i32 %22, double 5.000000e-01)
%24 = add nsw i32 %23, 1
%25 = icmp sle i32 %21, %24
br i1 %25, label %26, label %36
26: ; preds = %20
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = srem i32 %27, %28
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 0, i32* %2
br label %37
32: ; preds = %26
br label %33
33: ; preds = %32
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 2
store i32 %35, i32* %4
br label %20
36: ; preds = %20
store i32 1, i32* %2
br label %37
37: ; preds = %36, %31, %18, %13, %9
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @isprime(i32 %0) {
%2 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%3 = icmp ult i32 %2, 2
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = icmp eq i32 %2, 2
br i1 %5, label %20, label %6
6: ; preds = %4
%7 = and i32 %2, 1
%8 = icmp eq i32 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %6
%10 = tail call i32 @pow(i32 %2, double 5.000000e-01)
%11 = icmp slt i32 %10, 2
br i1 %11, label %20, label %16
12: ; preds = %16
%13 = add nuw nsw i32 %17, 2
%14 = tail call i32 @pow(i32 %2, double 5.000000e-01)
%15 = icmp slt i32 %17, %14
br i1 %15, label %16, label %20
16: ; preds = %9, %12
%17 = phi i32 [ %13, %12 ], [ 3, %9 ]
%18 = urem i32 %2, %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %12
20: ; preds = %16, %12, %9, %6, %4, %1
%21 = phi i32 [ 0, %1 ], [ 1, %4 ], [ 0, %6 ], [ 1, %9 ], [ 0, %16 ], [ 1, %12 ]
ret i32 %21
}