#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 *);
main() {
  int i, n, primo = 1;
  printf("Entre com um numero: ");
  scanf("%d", &n);
  for (i = 2; i < n; i++) {
    if ((n % i) == 0)
      primo = 0;
  }
  if (primo)
    printf("\nNumero %d eh primo\n", n);
  else
    printf("\nNumero %d nao eh primo\n", n);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1191 <main+0x71>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    117e <main+0x5e>
movl   $0x0,-0x10(%rbp)
jmp    1183 <main+0x63>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115b <main+0x3b>
cmpl   $0x0,-0x10(%rbp)
je     11b1 <main+0x91>
mov    -0xc(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c2 <main+0xa2>
mov    -0xc(%rbp),%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee0(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%r9d
cmp    $0x3,%r9d
jl     1159 <main+0x39>
jne    1162 <main+0x42>
mov    $0x2,%ecx
mov    $0x1,%edi
jmp    11a7 <main+0x87>
lea    0xeb9(%rip),%rdi
jmp    11cc <main+0xac>
lea    -0x2(%r9),%r8d
and    $0xfffffffe,%r8d
mov    $0x2,%ecx
mov    $0x1,%edi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ecx,%esi
mov    %r9d,%eax
cltd
idiv   %ecx
mov    %edx,%ecx
lea    0x1(%rsi),%r10d
mov    %r9d,%eax
cltd
idiv   %r10d
test   %ecx,%ecx
cmove  %ecx,%edi
test   %edx,%edx
cmove  %edx,%edi
lea    0x2(%rsi),%ecx
cmp    %r8d,%esi
jne    1180 <main+0x60>
test   $0x1,%r9b
je     11b8 <main+0x98>
mov    %r9d,%eax
cltd
idiv   %ecx
test   %edx,%edx
cmove  %edx,%edi
test   %edi,%edi
lea    0xe6d(%rip),%rax
lea    0xe51(%rip),%rdi
cmove  %rax,%rdi
mov    %r9d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Entre com um numero: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"\0ANumero %d eh primo\0A\00"
@.str.3 = [25 x i8] c"\0ANumero %d nao eh primo\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 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* %3)
store i32 2, i32* %2
br label %7
7: ; preds = %18, %0
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = load i32, i32* %3
%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 0, i32* %4
br label %17
17: ; preds = %16, %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 %7
21: ; preds = %7
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %30
27: ; preds = %21
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %24
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [22 x i8] c"Entre com um numero: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"\0ANumero %d eh primo\0A\00"
@.str.3 = [25 x i8] c"\0ANumero %d nao eh primo\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 ([22 x i8], [22 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 sgt i32 %5, 2
br i1 %6, label %7, label %40
7: ; preds = %0
%8 = and i32 %5, 1
%9 = icmp eq i32 %5, 3
br i1 %9, label %27, label %10
10: ; preds = %7
%11 = add i32 %5, -2
%12 = and i32 %11, -2
br label %13
13: ; preds = %13, %10
%14 = phi i32 [ 1, %10 ], [ %23, %13 ]
%15 = phi i32 [ 2, %10 ], [ %24, %13 ]
%16 = phi i32 [ 0, %10 ], [ %25, %13 ]
%17 = srem i32 %5, %15
%18 = icmp eq i32 %17, 0
%19 = or i32 %15, 1
%20 = srem i32 %5, %19
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i1 true, i1 %18
%23 = select i1 %22, i32 0, i32 %14
%24 = add nuw nsw i32 %15, 2
%25 = add i32 %16, 2
%26 = icmp eq i32 %25, %12
br i1 %26, label %27, label %13
27: ; preds = %13, %7
%28 = phi i32 [ undef, %7 ], [ %23, %13 ]
%29 = phi i32 [ 1, %7 ], [ %23, %13 ]
%30 = phi i32 [ 2, %7 ], [ %24, %13 ]
%31 = icmp eq i32 %8, 0
br i1 %31, label %36, label %32
32: ; preds = %27
%33 = srem i32 %5, %30
%34 = icmp eq i32 %33, 0
%35 = select i1 %34, i32 0, i32 %29
br label %36
36: ; preds = %27, %32
%37 = phi i32 [ %28, %27 ], [ %35, %32 ]
%38 = icmp eq i32 %37, 0
%39 = select i1 %38, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0)
br label %40
40: ; preds = %36, %0
%41 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %0 ], [ %39, %36 ]
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %41, i32 %5)
ret i32 0
}