#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 *);
int main() {
  int k;
  int i = 0;
  int somma = 0;
  int n;
  int media;
  printf("\nQuanti numeri si vogliono inserire:");
  scanf("%d", &k);
  while (i < k) {
    printf("\nInserire un numero:");
    scanf("%d", &n);
    i++;
    somma = somma + n;
  }
  media = somma / k;
  printf("\nLa media e' %d", media);
  getchar();
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ac <main+0x7c>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    116b <main+0x3b>
mov    -0x10(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebd(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%ecx
test   %ecx,%ecx
jle    11a4 <main+0x74>
lea    0xeb9(%rip),%r14
lea    0xed4(%rip),%r15
lea    0xc(%rsp),%r12
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
add    $0x1,%ebp
add    0xc(%rsp),%ebx
mov    0x8(%rsp),%ecx
cmp    %ecx,%ebp
jl     1180 <main+0x50>
mov    %ebx,%eax
cltd
idiv   %ecx
lea    0xe8a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"\0AQuanti numeri si vogliono inserire:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"\0AInserire un numero:\00"
@.str.3 = [16 x i8] c"\0ALa media e' %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %13, %0
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = add nsw i32 %18, %19
store i32 %20, i32* %4
br label %9
21: ; preds = %9
%22 = load i32, i32* %4
%23 = load i32, i32* %2
%24 = sdiv i32 %22, %23
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = call i32 (...) @getchar()
%28 = call i32 (...) @getchar()
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [37 x i8] c"\0AQuanti numeri si vogliono inserire:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"\0AInserire un numero:\00"
@.str.3 = [16 x i8] c"\0ALa media e' %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 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)
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %0, %9
%10 = phi i32 [ %14, %9 ], [ 0, %0 ]
%11 = phi i32 [ %16, %9 ], [ 0, %0 ]
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%14 = add nuw nsw i32 %10, 1
%15 = load i32, i32* %2
%16 = add nsw i32 %15, %11
%17 = load i32, i32* %1
%18 = icmp slt i32 %14, %17
br i1 %18, label %9, label %19
19: ; preds = %9, %0
%20 = phi i32 [ 0, %0 ], [ %16, %9 ]
%21 = phi i32 [ %7, %0 ], [ %17, %9 ]
%22 = sdiv i32 %20, %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = call i32 (...) @getchar()
%25 = call i32 (...) @getchar()
ret i32 0
}