#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, eprimo;
  int const fim = 0;
  printf("Entre com um numero: ");
  scanf("%d", &num);
  while (num != fim) {
    eprimo = 1;
    divisor = 2;
    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");
    printf("Entre com um numero: ");
    scanf("%d", &num);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
lea    0xecd(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
je     1207 <main+0xe7>
movl   $0x1,-0x10(%rbp)
movl   $0x2,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x15(%rbp)
jg     118a <main+0x6a>
cmpl   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    119a <main+0x7a>
jmp    11bf <main+0x9f>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11b1 <main+0x91>
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116a <main+0x4a>
cmpl   $0x0,-0x10(%rbp)
je     11da <main+0xba>
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
jmp    11e6 <main+0xc6>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
lea    0xe13(%rip),%rdi
call   1030 <printf@plt>
lea    0xe1d(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
jmp    1152 <main+0x32>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebc(%rip),%rdi
call   1040 <printf@plt>
lea    0xec6(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
je     11e7 <main+0xb7>
lea    0xebf(%rip),%rbx
lea    0xea5(%rip),%r13
lea    0xe85(%rip),%r14
lea    0xe94(%rip),%r15
lea    0xc(%rsp),%r12
jmp    11b9 <main+0x89>
nopl   0x0(%rax)
test   %edx,%edx
mov    %r13,%rdi
cmovne %rbx,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
je     11e7 <main+0xb7>
mov    %rbx,%rdi
cmp    $0x3,%ecx
jl     1199 <main+0x69>
mov    $0x3,%esi
cs nopw 0x0(%rax,%rax,1)
lea    -0x1(%rsi),%edi
mov    %ecx,%eax
cltd
idiv   %edi
test   %edx,%edx
je     1190 <main+0x60>
lea    0x1(%rsi),%eax
cmp    %ecx,%esi
mov    %eax,%esi
jl     11d0 <main+0xa0>
jmp    1190 <main+0x60>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
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
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%6 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %8
8: ; preds = %38, %0
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %41
11: ; preds = %8
store i32 1, i32* %4
store i32 2, i32* %3
br label %12
12: ; preds = %28, %11
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = sub nsw i32 %14, 1
%16 = icmp sle i32 %13, %15
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br label %20
20: ; preds = %17, %12
%21 = phi i1 [ false, %12 ], [ %19, %17 ]
br i1 %21, label %22, label %31
22: ; preds = %20
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = srem i32 %23, %24
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 0, i32* %4
br label %28
28: ; preds = %27, %22
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %12
31: ; preds = %20
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %38
36: ; preds = %31
%37 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %34
%39 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%40 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %8
41: ; preds = %8
%42 = load i32, i32* %1
ret i32 %42
}

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 eq i32 %5, 0
br i1 %6, label %26, label %7
7: ; preds = %0, %19
%8 = phi i32 [ %24, %19 ], [ %5, %0 ]
%9 = icmp sgt i32 %8, 2
br i1 %9, label %10, label %19
10: ; preds = %7, %10
%11 = phi i32 [ %14, %10 ], [ 2, %7 ]
%12 = srem i32 %8, %11
%13 = icmp ne i32 %12, 0
%14 = add nuw nsw i32 %11, 1
%15 = icmp slt i32 %14, %8
%16 = and i1 %13, %15
br i1 %16, label %10, label %17
17: ; preds = %10
%18 = select i1 %13, 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 %19
19: ; preds = %17, %7
%20 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.4, i64 0, i64 0), %7 ], [ %18, %17 ]
%21 = call i32 @puts(i8* dereferenceable(1) %20)
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%24 = load i32, i32* %1
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %7
26: ; preds = %19, %0
ret i32 0
}