#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 *);
void ex2() {
  int x, y, primo = 1, d = 2;
  do {
    primo = 1, d = 2;
    printf("Informe um numero: ");
    scanf("%d", &x);
    for (d = 2; d <= x / 2; d++) {
      if (x % d == 0) {
        primo = 0;
        break;
      }
    }
    if (primo != 0 || x <= 2)
      printf("O numero %d e primo\n", x);
    else
      printf("O numero %d nao e primo\n", x);
  } while (x < 1);
}


x86 assembly (clang, -O0):
<ex2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jg     11b6 <ex2+0x96>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11a3 <ex2+0x83>
movl   $0x0,-0xc(%rbp)
jmp    11b6 <ex2+0x96>
jmp    11a8 <ex2+0x88>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1169 <ex2+0x49>
cmpl   $0x0,-0xc(%rbp)
jne    11ca <ex2+0xaa>
cmpl   $0x2,-0x4(%rbp)
jg     11e0 <ex2+0xc0>
mov    -0x4(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f1 <ex2+0xd1>
mov    -0x4(%rbp),%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f6 <ex2+0xd6>
cmpl   $0x1,-0x4(%rbp)
jl     1136 <ex2+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex2>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xecc(%rip),%r14
lea    0xed9(%rip),%r15
lea    0xc(%rsp),%r12
lea    0xed0(%rip),%rbx
lea    0xede(%rip),%r13
jmp    1168 <ex2+0x48>
cmp    $0x3,%esi
mov    %r13,%rdi
cmovl  %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jg     11c0 <ex2+0xa0>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
cmp    $0x4,%esi
jl     115a <ex2+0x3a>
mov    %esi,%ecx
shr    %ecx
neg    %ecx
mov    $0x2,%edi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %esi,%eax
cltd
idiv   %edi
test   %edx,%edx
je     1150 <ex2+0x30>
lea    (%rcx,%rdi,1),%eax
add    $0x1,%eax
mov    %edi,%edx
add    $0x1,%edx
mov    %edx,%edi
cmp    $0x1,%eax
jne    11a0 <ex2+0x80>
mov    %rbx,%rdi
jmp    115a <ex2+0x3a>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Informe um numero: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"O numero %d e primo\0A\00"
@.str.3 = [25 x i8] c"O numero %d nao e primo\0A\00"
define void @ex2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 1, i32* %3
store i32 2, i32* %4
br label %5
5: ; preds = %36, %0
store i32 1, i32* %3
store i32 2, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 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* %1)
store i32 2, i32* %4
br label %8
8: ; preds = %20, %5
%9 = load i32, i32* %4
%10 = load i32, i32* %1
%11 = sdiv i32 %10, 2
%12 = icmp sle i32 %9, %11
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = load i32, i32* %1
%15 = load i32, i32* %4
%16 = srem i32 %14, %15
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 0, i32* %3
br label %23
19: ; preds = %13
br label %20
20: ; preds = %19
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %8
23: ; preds = %18, %8
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* %1
%28 = icmp sle i32 %27, 2
br i1 %28, label %29, label %32
29: ; preds = %26, %23
%30 = load i32, i32* %1
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %35
32: ; preds = %26
%33 = load i32, i32* %1
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32, %29
br label %36
36: ; preds = %35
%37 = load i32, i32* %1
%38 = icmp slt i32 %37, 1
br i1 %38, label %5, label %39
39: ; preds = %36
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"Informe um numero: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"O numero %d e primo\0A\00"
@.str.3 = [25 x i8] c"O numero %d nao e primo\0A\00"
define void @ex2() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %20, %0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 4
br i1 %7, label %20, label %8
8: ; preds = %3
%9 = lshr i32 %6, 1
br label %13
10: ; preds = %13
%11 = add nuw nsw i32 %14, 1
%12 = icmp eq i32 %14, %9
br i1 %12, label %20, label %13
13: ; preds = %8, %10
%14 = phi i32 [ %11, %10 ], [ 2, %8 ]
%15 = srem i32 %6, %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %10
17: ; preds = %13
%18 = icmp slt i32 %6, 3
%19 = select i1 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0)
br label %20
20: ; preds = %10, %17, %3
%21 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %3 ], [ %19, %17 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %10 ]
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %21, i32 %6)
%23 = load i32, i32* %1
%24 = icmp slt i32 %23, 1
br i1 %24, label %3, label %25
25: ; preds = %20
ret void
}