#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 n;
  int primo;
  int div;
  printf("Inserisci un numero qualsiasi: ");
  scanf("%d", &n);
  printf("\n");
  primo = 0;
  div = 2;
  while (div < n) {
    if (n % div == 0) {
      div = n;
      primo = 1;
    }
    div++;
  }
  if (primo == 0) {
    printf("Il numero inserito e' primo");
  } else {
    printf("Il numero inserito non e' primo");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
lea    0xede(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119c <main+0x7c>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    118e <main+0x6e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1165 <main+0x45>
cmpl   $0x0,-0xc(%rbp)
jne    11b7 <main+0x97>
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
jmp    11c3 <main+0xa3>
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
call   1040 <printf@plt>
lea    0xedc(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%r8d
cmp    $0x3,%r8d
jl     1194 <main+0x64>
xor    %edi,%edi
mov    $0x2,%ecx
jmp    117c <main+0x4c>
nopl   0x0(%rax)
add    $0x1,%esi
mov    %esi,%ecx
mov    %eax,%edi
cmp    %r8d,%esi
jge    119d <main+0x6d>
mov    %r8d,%eax
cltd
idiv   %ecx
mov    $0x1,%eax
mov    %r8d,%esi
test   %edx,%edx
je     1170 <main+0x40>
mov    %edi,%eax
mov    %ecx,%esi
jmp    1170 <main+0x40>
lea    0xe88(%rip),%rdi
jmp    11b1 <main+0x81>
test   %eax,%eax
lea    0xe7d(%rip),%rax
lea    0xe92(%rip),%rdi
cmove  %rax,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Inserisci un numero qualsiasi: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [28 x i8] c"Il numero inserito e' primo\00"
@.str.4 = [32 x i8] c"Il numero inserito non e' primo\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 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)
%7 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
store i32 2, i32* %4
br label %8
8: ; preds = %19, %0
%9 = load i32, i32* %4
%10 = load i32, i32* %2
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load i32, i32* %2
%14 = load i32, i32* %4
%15 = srem i32 %13, %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = load i32, i32* %2
store i32 %18, i32* %4
store i32 1, i32* %3
br label %19
19: ; preds = %17, %12
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %8
22: ; preds = %8
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %29
27: ; preds = %22
%28 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %27, %25
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [32 x i8] c"Inserisci un numero qualsiasi: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [28 x i8] c"Il numero inserito e' primo\00"
@.str.4 = [32 x i8] c"Il numero inserito non 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 ([32 x i8], [32 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 = call i32 @putchar(i32 10)
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 2
br i1 %7, label %8, label %20
8: ; preds = %0, %8
%9 = phi i32 [ %15, %8 ], [ 2, %0 ]
%10 = phi i32 [ %13, %8 ], [ 0, %0 ]
%11 = srem i32 %6, %9
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 1, i32 %10
%14 = select i1 %12, i32 %6, i32 %9
%15 = add nsw i32 %14, 1
%16 = icmp slt i32 %15, %6
br i1 %16, label %8, label %17
17: ; preds = %8
%18 = icmp eq i32 %13, 0
%19 = select i1 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0)
br label %20
20: ; preds = %17, %0
%21 = phi i8* [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), %0 ], [ %19, %17 ]
%22 = call i32 @printf(i8* dereferenceable(1) %21)
ret i32 0
}