#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 num, divisor = 2;
  int eprimo = 1;
  printf("Entre com um numero: ");
  scanf("%d", &num);
  while ((divisor <= (num - 1)) && eprimo) {
    if ((num % divisor) == 0)
      eprimo = 0;
    divisor++;
  }
  if (eprimo)
    printf("Numero e primo\n");
  else
    printf("Numero nao e primo\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
lea    0xebc(%rip),%rdi
call   1030 <printf@plt>
lea    0xec6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x11(%rbp)
jg     1179 <main+0x59>
cmpl   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1189 <main+0x69>
jmp    11ae <main+0x8e>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11a0 <main+0x80>
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1159 <main+0x39>
cmpl   $0x0,-0x10(%rbp)
je     11c9 <main+0xa9>
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
jmp    11d5 <main+0xb5>
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
call   1040 <printf@plt>
lea    0xed2(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%ecx
cmp    $0x3,%ecx
jl     118b <main+0x5b>
mov    $0x3,%esi
nopl   0x0(%rax)
lea    -0x1(%rsi),%edi
mov    %ecx,%eax
cltd
idiv   %edi
test   %edx,%edx
je     1175 <main+0x45>
lea    0x1(%rsi),%eax
cmp    %ecx,%esi
mov    %eax,%esi
jl     1160 <main+0x30>
test   %edx,%edx
lea    0xeae(%rip),%rax
lea    0xe94(%rip),%rdi
cmovne %rax,%rdi
jmp    1192 <main+0x62>
lea    0xe9a(%rip),%rdi
call   1030 <puts@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 = [16 x i8] c"Numero e primo\0A\00"
@.str.3 = [20 x i8] c"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
store i32 2, i32* %3
store i32 1, i32* %4
%5 = call i32 @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* %2)
br label %7
7: ; preds = %23, %0
%8 = load i32, i32* %3
%9 = load i32, i32* %2
%10 = sub nsw i32 %9, 1
%11 = icmp sle i32 %8, %10
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br label %15
15: ; preds = %12, %7
%16 = phi i1 [ false, %7 ], [ %14, %12 ]
br i1 %16, label %17, label %26
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 %23
23: ; preds = %22, %17
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %7
26: ; preds = %15
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %33
31: ; preds = %26
%32 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %29
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [22 x i8] c"Entre com um numero: \00"
@.str.1 = [3 x i8] c"%d\00"
@str = [19 x i8] c"Numero nao e primo\00"
@str.4 = [15 x i8] c"Numero e primo\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @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 %16
7: ; preds = %0, %7
%8 = phi i32 [ %11, %7 ], [ 2, %0 ]
%9 = srem i32 %5, %8
%10 = icmp ne i32 %9, 0
%11 = add nuw nsw i32 %8, 1
%12 = icmp slt i32 %11, %5
%13 = and i1 %10, %12
br i1 %13, label %7, label %14
14: ; preds = %7
%15 = select i1 %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0)
br label %16
16: ; preds = %14, %0
%17 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.4, i64 0, i64 0), %0 ], [ %15, %14 ]
%18 = call i32 @puts(i8* dereferenceable(1) %17)
ret i32 0
}