#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() {
  float somma = 0, divisore = 0;
  int numero;
  double media;
  printf("Calcolatore media");
  do {
    printf("Inserisci numero: ");
    scanf("%d", &numero);
    somma = somma + numero;
    divisore = divisore + 1;
  } while (numero > 0);
  media = somma / divisore;
  printf("Media calcolata: %g", media);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movss  -0x8(%rbp),%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  0xe7a(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
cmpl   $0x0,-0x10(%rbp)
jg     114d <main+0x2d>
movss  -0x8(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe73(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xed4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
lea    0xed5(%rip),%r14
lea    0xee1(%rip),%r15
lea    0xc(%rsp),%rbx
xorps  %xmm1,%xmm1
movss  %xmm1,0x4(%rsp)
movss  %xmm0,0x8(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
movss  0x4(%rsp),%xmm1
mov    0xc(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
addss  %xmm0,%xmm1
movss  0x8(%rsp),%xmm0
addss  0xe6c(%rip),%xmm0
test   %eax,%eax
jg     1150 <main+0x30>
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe82(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Calcolatore media\00"
@.str.1 = [19 x i8] c"Inserisci numero: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [20 x i8] c"Media calcolata: %g\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca i32
%5 = alloca double
store i32 0, i32* %1
store float 0.000000e+00, float* %2
store float 0.000000e+00, float* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %16, %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%10 = load float, float* %2
%11 = load i32, i32* %4
%12 = sitofp i32 %11 to float
%13 = fadd float %10, %12
store float %13, float* %2
%14 = load float, float* %3
%15 = fadd float %14, 1.000000e+00
store float %15, float* %3
br label %16
16: ; preds = %7
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 0
br i1 %18, label %7, label %19
19: ; preds = %16
%20 = load float, float* %2
%21 = load float, float* %3
%22 = fdiv float %20, %21
%23 = fpext float %22 to double
store double %23, double* %5
%24 = load double, double* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), double %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Calcolatore media\00"
@.str.1 = [19 x i8] c"Inserisci numero: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [20 x i8] c"Media calcolata: %g\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %4, %0
%5 = phi float [ 0.000000e+00, %0 ], [ %12, %4 ]
%6 = phi float [ 0.000000e+00, %0 ], [ %11, %4 ]
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 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* %1)
%9 = load i32, i32* %1
%10 = sitofp i32 %9 to float
%11 = fadd float %6, %10
%12 = fadd float %5, 1.000000e+00
%13 = icmp sgt i32 %9, 0
br i1 %13, label %4, label %14
14: ; preds = %4
%15 = fdiv float %11, %12
%16 = fpext float %15 to double
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), double %16)
ret i32 0
}