#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 *);
void main(void) {
  int N, i, flag = 0;
  printf("Enter number to check: ");
  scanf("%d", &N);
  for (i = 2; i <= N / 2; i++) {
    if (N % i == 0) {
      flag = 1;
      break;
    }
  }
  if (flag == 1)
    printf("Number is not prime\n");
  else
    printf("Number is prime\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jg     119f <main+0x7f>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    118c <main+0x6c>
movl   $0x1,-0xc(%rbp)
jmp    119f <main+0x7f>
jmp    1191 <main+0x71>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1152 <main+0x32>
cmpl   $0x1,-0xc(%rbp)
jne    11ba <main+0x9a>
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
jmp    11c6 <main+0xa6>
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
call   1040 <printf@plt>
lea    0xed4(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%r9d
lea    0xec1(%rip),%rdi
cmp    $0x4,%r9d
jl     119d <main+0x6d>
mov    %r9d,%esi
shr    %esi
neg    %esi
mov    $0x2,%ecx
lea    0xeb8(%rip),%r8
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r9d,%eax
cltd
idiv   %ecx
test   %edx,%edx
je     119a <main+0x6a>
lea    (%rsi,%rcx,1),%eax
add    $0x1,%eax
add    $0x1,%ecx
cmp    $0x1,%eax
jne    1180 <main+0x50>
jmp    119d <main+0x6d>
mov    %r8,%rdi
call   1030 <puts@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Enter number to check: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"Number is not prime\0A\00"
@.str.3 = [17 x i8] c"Number is prime\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
%4 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
store i32 2, i32* %2
br label %6
6: ; preds = %18, %0
%7 = load i32, i32* %2
%8 = load i32, i32* %1
%9 = sdiv i32 %8, 2
%10 = icmp sle i32 %7, %9
br i1 %10, label %11, label %21
11: ; preds = %6
%12 = load i32, i32* %1
%13 = load i32, i32* %2
%14 = srem i32 %12, %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 1, i32* %3
br label %21
17: ; preds = %11
br label %18
18: ; preds = %17
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %6
21: ; preds = %16, %6
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %28
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %24
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"Enter number to check: \00"
@.str.1 = [3 x i8] c"%d\00"
@str = [16 x i8] c"Number is prime\00"
@str.4 = [20 x i8] c"Number is not prime\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 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 = icmp slt i32 %5, 4
br i1 %6, label %16, label %7
7: ; preds = %0
%8 = lshr i32 %5, 1
br label %12
9: ; preds = %12
%10 = add nuw nsw i32 %13, 1
%11 = icmp eq i32 %13, %8
br i1 %11, label %16, label %12
12: ; preds = %7, %9
%13 = phi i32 [ %10, %9 ], [ 2, %7 ]
%14 = srem i32 %5, %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %9
16: ; preds = %9, %12, %0
%17 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0), %12 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0), %9 ]
%18 = call i32 @puts(i8* dereferenceable(1) %17)
ret void
}