#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 /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  unsigned int flip(void);
  unsigned int TentativiDaControllare;
  unsigned int numeroCroce = 0;
  unsigned int numeroTesta = 0;
  srand(time(NULL));
  printf("%s", "Indica quante volte vuoi lanciare la moneta: ");
  scanf("%u", &TentativiDaControllare);
  if (TentativiDaControllare >= 1) {
    do {
      if (flip() == 0) {
        numeroCroce++;
      } else {
        numeroTesta++;
      }
      TentativiDaControllare--;
    } while (TentativiDaControllare > 0);
  } else {
    printf("%s", "E' stato inserito un valore non valido");
  }
  printf("Il numero volte in cui e' uscita testa e' pari a: %u\n", numeroTesta);
  printf("Il numero volte in cui e' uscita croce e' pari a: %u\n", numeroCroce);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
lea    0xe7c(%rip),%rdi
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe98(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jb     11ee <main+0x9e>
jmp    11b1 <main+0x61>
call   1050 <flip@plt>
cmp    $0x0,%eax
jne    11cd <main+0x7d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d6 <main+0x86>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
ja     11b1 <main+0x61>
jmp    1203 <main+0xb3>
lea    0xe0b(%rip),%rdi
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe73(%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   %rbx
push   %rax
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
lea    0xe96(%rip),%rdi
lea    0xe92(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb2(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
je     11be <main+0x6e>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1050 <flip@plt>
xor    %ecx,%ecx
xor    %edx,%edx
test   %eax,%eax
setne  %cl
sete   %dl
add    %edx,%ebx
add    %ecx,%ebp
addl   $0xffffffff,0x4(%rsp)
jne    11a0 <main+0x50>
jmp    11d7 <main+0x87>
lea    0xe3b(%rip),%rdi
lea    0xe68(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %ebp,%ebp
lea    0xe7d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea3(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [46 x i8] c"Indica quante volte vuoi lanciare la moneta: \00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [39 x i8] c"E' stato inserito un valore non valido\00"
@.str.4 = [54 x i8] c"Il numero volte in cui e' uscita testa e' pari a: %u\0A\00"
@.str.5 = [54 x i8] c"Il numero volte in cui e' uscita croce e' pari a: %u\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
store i32 0, i32* %4
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = icmp uge i32 %9, 1
br i1 %10, label %11, label %28
11: ; preds = %0
br label %12
12: ; preds = %24, %11
%13 = call i32 @flip()
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %3
%17 = add i32 %16, 1
store i32 %17, i32* %3
br label %21
18: ; preds = %12
%19 = load i32, i32* %4
%20 = add i32 %19, 1
store i32 %20, i32* %4
br label %21
21: ; preds = %18, %15
%22 = load i32, i32* %2
%23 = add i32 %22, -1
store i32 %23, i32* %2
br label %24
24: ; preds = %21
%25 = load i32, i32* %2
%26 = icmp ugt i32 %25, 0
br i1 %26, label %12, label %27
27: ; preds = %24
br label %30
28: ; preds = %0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %27
%31 = load i32, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i32 %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [46 x i8] c"Indica quante volte vuoi lanciare la moneta: \00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [39 x i8] c"E' stato inserito un valore non valido\00"
@.str.4 = [54 x i8] c"Il numero volte in cui e' uscita testa e' pari a: %u\0A\00"
@.str.5 = [54 x i8] c"Il numero volte in cui e' uscita croce e' pari a: %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %0, %9
%10 = phi i32 [ %15, %9 ], [ 0, %0 ]
%11 = phi i32 [ %18, %9 ], [ 0, %0 ]
%12 = call i32 @flip()
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = add i32 %10, %14
%16 = xor i1 %13, true
%17 = zext i1 %16 to i32
%18 = add i32 %11, %17
%19 = load i32, i32* %1
%20 = add i32 %19, -1
store i32 %20, i32* %1
%21 = icmp eq i32 %20, 0
br i1 %21, label %24, label %9
22: ; preds = %0
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %9, %22
%25 = phi i32 [ 0, %22 ], [ %15, %9 ]
%26 = phi i32 [ 0, %22 ], [ %18, %9 ]
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i32 %25)
ret i32 0
}