#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 *, unsigned int *);
int main(void) {
  unsigned int controlloNumeroPrimo(unsigned int numeroDaControllare);
  unsigned int maxNumDaControllare;
  unsigned int numeroPrimo;
  unsigned int contatoreNumeri = 1;
  unsigned int quantiNumeriPrimi = 0;
  printf("%s", "Indica quanti numeri si desidera controllare: ");
  scanf("%u", &maxNumDaControllare);
  do {
    numeroPrimo = controlloNumeroPrimo(contatoreNumeri);
    if (numeroPrimo == 1) {
      printf("%u e' un numero primo!!\n", contatoreNumeri);
      quantiNumeriPrimi++;
    }
  } while (contatoreNumeri++ < maxNumDaControllare);
  printf("\nSono stati scoperti: %u numeri primi", quantiNumeriPrimi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeac(%rip),%rdi
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%edi
call   1030 <controlloNumeroPrimo@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11a1 <main+0x71>
mov    -0x10(%rbp),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a6 <main+0x76>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
cmp    -0x8(%rbp),%eax
jb     1172 <main+0x42>
mov    -0x14(%rbp),%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
lea    0xebd(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xede(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
lea    0xed0(%rip),%r14
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1176 <main+0x46>
nopl   0x0(%rax,%rax,1)
cmp    0xc(%rsp),%ebp
jae    1196 <main+0x66>
add    $0x1,%ebp
mov    %ebp,%edi
call   1030 <controlloNumeroPrimo@plt>
cmp    $0x1,%eax
jne    1170 <main+0x40>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
jmp    1170 <main+0x40>
lea    0xeb1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [47 x i8] c"Indica quanti numeri si desidera controllare: \00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [25 x i8] c"%u e' un numero primo!!\0A\00"
@.str.4 = [38 x i8] c"\0ASono stati scoperti: %u numeri primi\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
store i32 0, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 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)
br label %8
8: ; preds = %19, %0
%9 = load i32, i32* %4
%10 = call i32 @controlloNumeroPrimo(i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %5
%17 = add i32 %16, 1
store i32 %17, i32* %5
br label %18
18: ; preds = %13, %8
br label %19
19: ; preds = %18
%20 = load i32, i32* %4
%21 = add i32 %20, 1
store i32 %21, i32* %4
%22 = load i32, i32* %2
%23 = icmp ult i32 %20, %22
br i1 %23, label %8, label %24
24: ; preds = %19
%25 = load i32, i32* %5
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [47 x i8] c"Indica quanti numeri si desidera controllare: \00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [25 x i8] c"%u e' un numero primo!!\0A\00"
@.str.4 = [38 x i8] c"\0ASono stati scoperti: %u numeri primi\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
br label %5
5: ; preds = %13, %0
%6 = phi i32 [ 1, %0 ], [ %15, %13 ]
%7 = phi i32 [ 0, %0 ], [ %14, %13 ]
%8 = call i32 @controlloNumeroPrimo(i32 %6)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %6)
%12 = add i32 %7, 1
br label %13
13: ; preds = %5, %10
%14 = phi i32 [ %12, %10 ], [ %7, %5 ]
%15 = add i32 %6, 1
%16 = load i32, i32* %1
%17 = icmp ult i32 %6, %16
br i1 %17, label %5, label %18
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %14)
ret i32 0
}