#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*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int n, i, primo;
  do {
    printf("Inserire un intero: ");
    scanf("%d", &n);
  } while (n < 1);
  primo = 1;
  i = 2;
  while (i <= n / 2 && primo == 1) {
    if (n % i == 0)
      primo = 0;
    i++;
  }
  printf("\n%d", n);
  if (primo == 0)
    printf(" non ");
  printf(" è primo\n");
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec9(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x1,-0x4(%rbp)
jl     1138 <main+0x8>
movl   $0x1,-0xc(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0xd(%rbp)
jg     1195 <main+0x65>
cmpl   $0x1,-0xc(%rbp)
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    11a5 <main+0x75>
jmp    11ca <main+0x9a>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%edx
jne    11bc <main+0x8c>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116e <main+0x3e>
mov    -0x4(%rbp),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jne    11f3 <main+0xc3>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb0(%rip),%r14
lea    0xebf(%rip),%r15
lea    0xc(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    1160 <main+0x20>
cmp    $0x4,%esi
jb     11c4 <main+0x84>
mov    %esi,%ecx
shr    %ecx
mov    $0x2,%edi
nopl   0x0(%rax,%rax,1)
mov    %esi,%eax
cltd
idiv   %edi
mov    %edx,%ebx
cmp    %ecx,%edi
jae    11a2 <main+0x62>
add    $0x1,%edi
test   %ebx,%ebx
jne    1190 <main+0x50>
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jne    11d2 <main+0x92>
lea    0xe5e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d2 <main+0x92>
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [21 x i8] c"Inserire un intero: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"\0A%d\00"
@.str.3 = [6 x i8] c" non \00"
@str = [10 x i8] c" \C3\A8 primo\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 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, 1
br i1 %7, label %3, label %8
8: ; preds = %3
%9 = lshr i32 %6, 1
%10 = icmp ugt i32 %6, 3
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %6)
br label %24
13: ; preds = %8, %13
%14 = phi i32 [ %17, %13 ], [ 2, %8 ]
%15 = srem i32 %6, %14
%16 = icmp ne i32 %15, 0
%17 = add nuw nsw i32 %14, 1
%18 = icmp ult i32 %14, %9
%19 = and i1 %18, %16
br i1 %19, label %13, label %20
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %6)
br i1 %16, label %24, label %22
22: ; preds = %20
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %11, %22, %20
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%26 = call i32 (...) @getchar()
ret void
}