#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 */
scalar_t__ sqrt(int);
int fact(int n) {
  int k, i;
  if (n == 1)
    return 2;
  k = (int)sqrt(n);
  for (i = 2; i <= k; i++)
    if (n % i == 0)
      return 1;
  return 0;
}


x86 assembly (clang, -O0):
<fact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1131 <fact+0x21>
movl   $0x2,-0x4(%rbp)
jmp    1185 <fact+0x75>
mov    -0x8(%rbp),%edi
call   1030 <sqrt@plt>
mov    %eax,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     117e <fact+0x6e>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    116b <fact+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    1185 <fact+0x75>
jmp    1170 <fact+0x60>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1143 <fact+0x33>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fact>:
push   %rbx
mov    $0x2,%ecx
cmp    $0x1,%edi
je     1162 <fact+0x52>
mov    %edi,%ebx
call   1030 <sqrt@plt>
mov    %rax,%rsi
xor    %ecx,%ecx
cmp    $0x2,%esi
jl     1162 <fact+0x52>
neg    %esi
mov    $0x2,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%eax
cltd
idiv   %edi
test   %edx,%edx
je     115d <fact+0x4d>
lea    (%rsi,%rdi,1),%eax
add    $0x1,%eax
mov    %edi,%edx
add    $0x1,%edx
mov    %edx,%edi
cmp    $0x1,%eax
jne    1140 <fact+0x30>
jmp    1162 <fact+0x52>
mov    $0x1,%ecx
mov    %ecx,%eax
pop    %rbx
ret

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

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