#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() {
  int n, i, primo;
  printf("n = ");
  scanf("%d", &n);
  i = n - 1;
  primo = 1;
  while (i > 1) {
    if (!(n % i)) {
      primo = 0;
      break;
    }
    --i;
  }
  if (primo)
    printf("É primo!\n");
  else
    printf("Não é primo!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    118f <main+0x6f>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1181 <main+0x61>
movl   $0x0,-0x10(%rbp)
jmp    118f <main+0x6f>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    115b <main+0x3b>
cmpl   $0x0,-0x10(%rbp)
je     11aa <main+0x8a>
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
jmp    11b6 <main+0x96>
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
call   1040 <printf@plt>
lea    0xec1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
lea    0xebe(%rip),%rdi
lea    0xea8(%rip),%r8
mov    %esi,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x3,%ecx
jl     1184 <main+0x54>
add    $0xffffffff,%ecx
mov    %esi,%eax
cltd
idiv   %ecx
test   %edx,%edx
jne    1170 <main+0x40>
mov    %r8,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"n = \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"\C3\89 primo!\0A\00"
@.str.3 = [16 x i8] c"N\C3\A3o \C3\A9 primo!\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 @printf(i8* getelementptr inbounds ([5 x i8], [5 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)
%7 = load i32, i32* %2
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %3
store i32 1, i32* %4
br label %9
9: ; preds = %18, %0
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = srem i32 %13, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %12
store i32 0, i32* %4
br label %21
18: ; preds = %12
%19 = load i32, i32* %3
%20 = add nsw i32 %19, -1
store i32 %20, i32* %3
br label %9
21: ; preds = %17, %9
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %28
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %24
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"n = \00"
@.str.1 = [3 x i8] c"%d\00"
@str = [15 x i8] c"N\C3\A3o \C3\A9 primo!\00"
@str.4 = [10 x i8] c"\C3\89 primo!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 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
br label %6
6: ; preds = %10, %0
%7 = phi i32 [ %5, %0 ], [ %8, %10 ]
%8 = add nsw i32 %7, -1
%9 = icmp sgt i32 %7, 2
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = srem i32 %5, %8
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %6
13: ; preds = %10, %6
%14 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.4, i64 0, i64 0), %6 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0), %10 ]
%15 = call i32 @puts(i8* dereferenceable(1) %14)
ret i32 0
}