#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(void) {
  int num;
  int isPrime;
  int i;
  isPrime = 0;
  printf("IsPrime v1.0\n");
  printf("\nInserire un numero: ");
  scanf("%d", &num);
  if (num < 0) {
    num = (-num);
  }
  i = num / 2;
  if (num == 3 || num == 1) {
    isPrime = 1;
  } else {
    while (i > 1) {
      if (!(num % i)) {
        isPrime = 0;
        printf("\nIl numero %d", num);
        printf(" è divisibile per %d", i);
      } else {
        isPrime = 1;
      }
      i--;
    }
  }
  if (isPrime == 1) {
    printf("\n\nIl numero %d", num);
    printf(" è primo.\n");
  } else {
    printf("\n\nIl numero %d", num);
    printf(" non è primo.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeed(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    1174 <main+0x54>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1196 <main+0x76>
cmpl   $0x1,-0x8(%rbp)
jne    11a2 <main+0x82>
movl   $0x1,-0xc(%rbp)
jmp    1209 <main+0xe9>
jmp    11a7 <main+0x87>
cmpl   $0x1,-0x10(%rbp)
jle    1204 <main+0xe4>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11ef <main+0xcf>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f6 <main+0xd6>
movl   $0x1,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11a7 <main+0x87>
jmp    1209 <main+0xe9>
cmpl   $0x1,-0xc(%rbp)
jne    1237 <main+0x117>
mov    -0x8(%rbp),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1256 <main+0x136>
mov    -0x8(%rbp),%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xef8(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedb(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jns    1175 <main+0x45>
neg    %esi
mov    %esi,0xc(%rsp)
mov    %esi,%eax
and    $0xfffffffd,%eax
lea    0xecb(%rip),%r14
cmp    $0x1,%eax
je     11de <main+0xae>
cmp    $0x4,%esi
jb     11d3 <main+0xa3>
mov    %esi,%ebp
shr    %ebp
lea    0xe97(%rip),%r15
lea    0xe79(%rip),%r12
nopl   (%rax)
mov    %esi,%eax
cltd
idiv   %ebp
mov    %edx,%ebx
test   %edx,%edx
jne    11c1 <main+0x91>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x3,%ebp
jl     11cf <main+0x9f>
add    $0xffffffff,%ebp
mov    0xc(%rsp),%esi
jmp    11a0 <main+0x70>
test   %ebx,%ebx
jne    11da <main+0xaa>
lea    0xe6e(%rip),%r14
mov    0xc(%rsp),%esi
lea    0xe47(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"IsPrime v1.0\0A\00"
@.str.1 = [22 x i8] c"\0AInserire un numero: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [14 x i8] c"\0AIl numero %d\00"
@.str.4 = [22 x i8] c" \C3\A8 divisibile per %d\00"
@.str.5 = [15 x i8] c"\0A\0AIl numero %d\00"
@.str.6 = [12 x i8] c" \C3\A8 primo.\0A\00"
@.str.7 = [16 x i8] c" non \C3\A8 primo.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* %2
%12 = sub nsw i32 0, %11
store i32 %12, i32* %2
br label %13
13: ; preds = %10, %0
%14 = load i32, i32* %2
%15 = sdiv i32 %14, 2
store i32 %15, i32* %4
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, 3
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %22
21: ; preds = %18, %13
store i32 1, i32* %3
br label %41
22: ; preds = %18
br label %23
23: ; preds = %37, %22
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 1
br i1 %25, label %26, label %40
26: ; preds = %23
%27 = load i32, i32* %2
%28 = load i32, i32* %4
%29 = srem i32 %27, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %26
store i32 0, i32* %3
%32 = load i32, i32* %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %34)
br label %37
36: ; preds = %26
store i32 1, i32* %3
br label %37
37: ; preds = %36, %31
%38 = load i32, i32* %4
%39 = add nsw i32 %38, -1
store i32 %39, i32* %4
br label %23
40: ; preds = %23
br label %41
41: ; preds = %40, %21
%42 = load i32, i32* %3
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i32, i32* %2
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %52
48: ; preds = %41
%49 = load i32, i32* %2
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %52
52: ; preds = %48, %44
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"\0AInserire un numero: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [14 x i8] c"\0AIl numero %d\00"
@.str.4 = [22 x i8] c" \C3\A8 divisibile per %d\00"
@.str.5 = [15 x i8] c"\0A\0AIl numero %d\00"
@str = [13 x i8] c"IsPrime v1.0\00"
@str.8 = [15 x i8] c" non \C3\A8 primo.\00"
@str.9 = [11 x i8] c" \C3\A8 primo.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = sub nsw i32 0, %6
store i32 %9, i32* %1
br label %10
10: ; preds = %8, %0
%11 = phi i32 [ %9, %8 ], [ %6, %0 ]
%12 = and i32 %11, -3
%13 = icmp eq i32 %12, 1
br i1 %13, label %36, label %14
14: ; preds = %10
%15 = icmp ugt i32 %11, 3
br i1 %15, label %16, label %34
16: ; preds = %14
%17 = lshr i32 %11, 1
br label %18
18: ; preds = %28, %16
%19 = phi i32 [ %30, %28 ], [ %11, %16 ]
%20 = phi i32 [ %29, %28 ], [ %17, %16 ]
%21 = srem i32 %19, %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %20)
br label %26
26: ; preds = %18, %23
%27 = icmp sgt i32 %20, 2
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = add nsw i32 %20, -1
%30 = load i32, i32* %1
br label %18
31: ; preds = %26
br i1 %22, label %34, label %32
32: ; preds = %31
%33 = load i32, i32* %1
br label %36
34: ; preds = %14, %31
%35 = load i32, i32* %1
br label %36
36: ; preds = %10, %32, %34
%37 = phi i32 [ %35, %34 ], [ %33, %32 ], [ %11, %10 ]
%38 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0), %34 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @str.9, i64 0, i64 0), %32 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @str.9, i64 0, i64 0), %10 ]
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %37)
%40 = call i32 @puts(i8* dereferenceable(1) %38)
ret i32 0
}