#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int n;
  int i;
  int flag;
  printf("Enter value of N > ");
  scanf("%d", &n);
  flag = 1;
  for (i = 2; (i < (n / 2)) && (flag > 0);) {
    if ((n % i) == 0)
      flag = 0;
    else
      i++;
  }
  if (flag)
    printf("%d is prime\n", n);
  else
    printf("%d has %d as a factor\n", n, i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x10(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x11(%rbp)
jge    1182 <main+0x62>
cmpl   $0x0,-0x10(%rbp)
setg   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1192 <main+0x72>
jmp    11bc <main+0x9c>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11ae <main+0x8e>
movl   $0x0,-0x10(%rbp)
jmp    11b7 <main+0x97>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115b <main+0x3b>
cmpl   $0x0,-0x10(%rbp)
je     11dc <main+0xbc>
mov    -0x8(%rbp),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f0 <main+0xd0>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xede(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%esi
cmp    $0x6,%esi
jl     117e <main+0x5e>
mov    %esi,%ecx
shr    $0x1f,%ecx
add    %esi,%ecx
sar    %ecx
mov    $0x2,%edx
nopw   0x0(%rax,%rax,1)
mov    %edx,%edi
mov    %esi,%eax
cltd
idiv   %edi
mov    %edx,%eax
xor    %edx,%edx
test   %eax,%eax
setne  %dl
add    %edi,%edx
test   %eax,%eax
je     117a <main+0x5a>
cmp    %ecx,%edx
jl     1160 <main+0x40>
test   %eax,%eax
je     118e <main+0x6e>
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    119c <main+0x7c>
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter value of N > \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"%d is prime\0A\00"
@.str.3 = [23 x i8] c"%d has %d as a factor\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 1, i32* %4
store i32 2, i32* %3
br label %7
7: ; preds = %26, %0
%8 = load i32, i32* %3
%9 = load i32, i32* %2
%10 = sdiv i32 %9, 2
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 0
br label %15
15: ; preds = %12, %7
%16 = phi i1 [ false, %7 ], [ %14, %12 ]
br i1 %16, label %17, label %27
17: ; preds = %15
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = srem i32 %18, %19
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 0, i32* %4
br label %26
23: ; preds = %17
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %26
26: ; preds = %23, %22
br label %7
27: ; preds = %15
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %37
33: ; preds = %27
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %35)
br label %37
37: ; preds = %33, %30
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter value of N > \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"%d is prime\0A\00"
@.str.3 = [23 x i8] c"%d has %d as a factor\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = sdiv i32 %5, 2
%7 = icmp sgt i32 %5, 5
br i1 %7, label %8, label %18
8: ; preds = %0, %8
%9 = phi i32 [ %14, %8 ], [ 2, %0 ]
%10 = srem i32 %5, %9
%11 = icmp eq i32 %10, 0
%12 = xor i1 %11, true
%13 = zext i1 %12 to i32
%14 = add nuw nsw i32 %9, %13
%15 = icmp sge i32 %14, %6
%16 = or i1 %11, %15
br i1 %16, label %17, label %8
17: ; preds = %8
br i1 %11, label %20, label %18
18: ; preds = %0, %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %5)
br label %22
20: ; preds = %17
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %5, i32 %14)
br label %22
22: ; preds = %20, %18
ret i32 0
}