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


x86 assembly (clang, -O0):
<fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1131 <fun+0x21>
movl   $0x0,-0x4(%rbp)
jmp    1185 <fun+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 <fun+0x6e>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    116b <fun+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    1185 <fun+0x75>
jmp    1170 <fun+0x60>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1143 <fun+0x33>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
cmp    $0x1,%edi
je     1150 <fun+0x40>
mov    %edi,%ebp
call   1030 <sqrt@plt>
cmp    $0x2,%eax
jl     114b <fun+0x3b>
mov    %eax,%ecx
neg    %ecx
mov    $0x2,%esi
nop
mov    %ebp,%eax
cltd
idiv   %esi
test   %edx,%edx
je     1150 <fun+0x40>
lea    (%rcx,%rsi,1),%eax
add    $0x1,%eax
mov    %esi,%edx
add    $0x1,%edx
mov    %edx,%esi
cmp    $0x1,%eax
jne    1130 <fun+0x20>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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