#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 num, div, flag;
  div = 2;
  flag = 1;
  printf("\nIngrese un numero: ");
  scanf("%d", &num);
  while (div <= num - 1 && flag == 1) {
    if (num % div == 0)
      flag = 0;
    div = div + 1;
  }
  if (flag == 1)
    printf("\nEl numero es primo\n\n");
  else
    printf("\nEl numero no es primo\n\n");
  return 0;
}


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    0xec5(%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   $0x1,-0x10(%rbp)
sete   %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   $0x1,-0x10(%rbp)
jne    11c9 <main+0xa9>
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
jmp    11d5 <main+0xb5>
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
call   1040 <printf@plt>
lea    0xed1(%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    0xeb2(%rip),%rax
lea    0xe93(%rip),%rdi
cmovne %rax,%rdi
jmp    1192 <main+0x62>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"\0AIngrese un numero: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"\0AEl numero es primo\0A\0A\00"
@.str.3 = [25 x i8] c"\0AEl numero no es primo\0A\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 ([21 x i8], [21 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 eq i32 %13, 1
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 eq i32 %27, 1
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %33
31: ; preds = %26
%32 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %29
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"\0AIngrese un numero: \00"
@.str.1 = [3 x i8] c"%d\00"
@str = [24 x i8] c"\0AEl numero no es primo\0A\00"
@str.4 = [21 x i8] c"\0AEl numero es primo\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 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 ([21 x i8], [21 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0)
br label %16
16: ; preds = %14, %0
%17 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.4, i64 0, i64 0), %0 ], [ %15, %14 ]
%18 = call i32 @puts(i8* dereferenceable(1) %17)
ret i32 0
}