#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*/ getch();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int numero, divisores, contador;
  printf("Vamos ver se o numero e primo!\nDigite um numero para que possamos "
         "verifica-lo:\n");
  scanf("%d", &numero);
  divisores = 0;
  contador = 1;
  while (contador <= numero) {
    if (numero % contador == 0) {
      printf("Divisor: %d\n", contador);
      divisores++;
    }
    contador++;
  }
  if (divisores == 2) {
    printf("O numero e PRIMO!\n");
  } else {
    printf("O numero NAO e PRIMO!\n");
  }
  getch();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11af <main+0x7f>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11a1 <main+0x71>
mov    -0x10(%rbp),%esi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116b <main+0x3b>
cmpl   $0x2,-0xc(%rbp)
jne    11cc <main+0x9c>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11da <main+0xaa>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getch@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
lea    0xea5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
jle    11b3 <main+0x73>
lea    0xe8f(%rip),%r14
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1184 <main+0x44>
nopw   0x0(%rax,%rax,1)
cmp    %ecx,%ebp
jge    11a5 <main+0x65>
add    $0x1,%ebp
mov    %ecx,%eax
cltd
idiv   %ebp
test   %edx,%edx
jne    1180 <main+0x40>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
mov    0xc(%rsp),%ecx
jmp    1180 <main+0x40>
cmp    $0x2,%ebx
jne    11b3 <main+0x73>
lea    0xec4(%rip),%rdi
jmp    11ba <main+0x7a>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <getch@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [80 x i8] c"Vamos ver se o numero e primo!\0ADigite um numero para que possamos verifica-lo:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"Divisor: %d\0A\00"
@.str.3 = [19 x i8] c"O numero e PRIMO!\0A\00"
@.str.4 = [23 x i8] c"O numero NAO e 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 (i8*, ...) @printf(i8* getelementptr inbounds ([80 x i8], [80 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 0, i32* %3
store i32 1, i32* %4
br label %7
7: ; preds = %21, %0
%8 = load i32, i32* %4
%9 = load i32, i32* %2
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %24
11: ; preds = %7
%12 = load i32, i32* %2
%13 = load i32, i32* %4
%14 = srem i32 %12, %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %21
21: ; preds = %16, %11
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %7
24: ; preds = %7
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %31
29: ; preds = %24
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %29, %27
%32 = call i32 (...) @getch()
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"Divisor: %d\0A\00"
@str = [79 x i8] c"Vamos ver se o numero e primo!\0ADigite um numero para que possamos verifica-lo:\00"
@str.5 = [22 x i8] c"O numero NAO e PRIMO!\00"
@str.6 = [18 x i8] c"O numero e PRIMO!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 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, 1
br i1 %6, label %24, label %7
7: ; preds = %0, %17
%8 = phi i32 [ %18, %17 ], [ %5, %0 ]
%9 = phi i32 [ %20, %17 ], [ 1, %0 ]
%10 = phi i32 [ %19, %17 ], [ 0, %0 ]
%11 = srem i32 %8, %9
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%15 = add nsw i32 %10, 1
%16 = load i32, i32* %1
br label %17
17: ; preds = %13, %7
%18 = phi i32 [ %16, %13 ], [ %8, %7 ]
%19 = phi i32 [ %15, %13 ], [ %10, %7 ]
%20 = add nuw nsw i32 %9, 1
%21 = icmp slt i32 %9, %18
br i1 %21, label %7, label %22
22: ; preds = %17
%23 = icmp eq i32 %19, 2
br i1 %23, label %25, label %24
24: ; preds = %0, %22
br label %25
25: ; preds = %22, %24
%26 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.5, i64 0, i64 0), %24 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0), %22 ]
%27 = call i32 @puts(i8* dereferenceable(1) %26)
%28 = call i32 (...) @getch()
ret i32 0
}