#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 */
double get_i();
int /*<<< orphan*/ put_d(double);
int /*<<< orphan*/ put_s(char *);
void main() {
  int i, n;
  double s;
  s = 0.0;
  put_s("n=");
  n = get_i();
  for (i = 0; i < n; i = i + 1) {
    s = s + get_i();
  }
  put_s("media=");
  put_d(s / n);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
lea    0xeb9(%rip),%rdi
call   1040 <put_s@plt>
mov    $0x0,%al
call   1050 <get_i@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119d <main+0x6d>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <get_i@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1161 <main+0x31>
lea    0xe5f(%rip),%rdi
call   1040 <put_s@plt>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1030 <put_d@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
call   1040 <put_s@plt>
xor    %eax,%eax
call   1050 <get_i@plt>
cvttsd2si %xmm0,%ebx
xorpd  %xmm0,%xmm0
test   %ebx,%ebx
jle    117c <main+0x4c>
movsd  %xmm0,(%rsp)
mov    %ebx,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <get_i@plt>
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
add    $0xffffffff,%ebp
jne    1160 <main+0x30>
jmp    1181 <main+0x51>
movsd  %xmm0,(%rsp)
lea    0xe7b(%rip),%rdi
call   1040 <put_s@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
movsd  (%rsp),%xmm0
divsd  %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <put_d@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"n=\00"
@.str.1 = [7 x i8] c"media=\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
store double 0.000000e+00, double* %3
%4 = call i32 @put_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = call double (...) @get_i()
%6 = fptosi double %5 to i32
store i32 %6, i32* %2
store i32 0, i32* %1
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %1
%9 = load i32, i32* %2
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = load double, double* %3
%13 = call double (...) @get_i()
%14 = fadd double %12, %13
store double %14, double* %3
br label %15
15: ; preds = %11
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
store i32 %17, i32* %1
br label %7
18: ; preds = %7
%19 = call i32 @put_s(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%20 = load double, double* %3
%21 = load i32, i32* %2
%22 = sitofp i32 %21 to double
%23 = fdiv double %20, %22
%24 = call i32 @put_d(double %23)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"n=\00"
@.str.1 = [7 x i8] c"media=\00"
define void @main() {
%1 = tail call i32 @put_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%2 = tail call double (...) @get_i()
%3 = fptosi double %2 to i32
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %0, %5
%6 = phi double [ %9, %5 ], [ 0.000000e+00, %0 ]
%7 = phi i32 [ %10, %5 ], [ 0, %0 ]
%8 = tail call double (...) @get_i()
%9 = fadd double %6, %8
%10 = add nuw nsw i32 %7, 1
%11 = icmp eq i32 %10, %3
br i1 %11, label %12, label %5
12: ; preds = %5, %0
%13 = phi double [ 0.000000e+00, %0 ], [ %9, %5 ]
%14 = tail call i32 @put_s(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = sitofp i32 %3 to double
%16 = fdiv double %13, %15
%17 = tail call i32 @put_d(double %16)
ret void
}