#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*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int n, i;
  float media, total = 0;
  printf("Numero de elementos: ");
  scanf("%d", &n);
  int *vetor = (int *)malloc(n * sizeof(int));
  for (i = 0; i < n; i++) {
    printf("Valor da posiçao vetor[i]: ");
    scanf("%d", &vetor[i]);
    total += vetor[i];
  }
  media = total / (float)n;
  printf("Media = %.2f", media);
  free(vetor);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e9 <main+0xa9>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe57(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
cvtsi2ssl (%rax,%rcx,4),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118f <main+0x4f>
movss  -0x14(%rbp),%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe2a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    0x8(%rsp),%eax
xorps  %xmm1,%xmm1
test   %eax,%eax
jle    11de <main+0x9e>
lea    0xe8c(%rip),%r15
lea    0xe82(%rip),%r12
mov    %r14,%rbx
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
movss  %xmm1,0xc(%rsp)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
movss  0xc(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2ssl (%rbx),%xmm0
addss  %xmm0,%xmm1
add    $0x1,%r13
movslq 0x8(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     11a0 <main+0x60>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe3f(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Numero de elementos: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"Valor da posi\C3\A7ao vetor[i]: \00"
@.str.3 = [13 x i8] c"Media = %.2f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = alloca float
%6 = alloca i32*
store i32 0, i32* %1
store float 0.000000e+00, float* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 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)
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %6
store i32 0, i32* %3
br label %15
15: ; preds = %34, %0
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %37
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32*, i32** %6
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %24)
%26 = load i32*, i32** %6
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = sitofp i32 %30 to float
%32 = load float, float* %5
%33 = fadd float %32, %31
store float %33, float* %5
br label %34
34: ; preds = %19
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %15
37: ; preds = %15
%38 = load float, float* %5
%39 = load i32, i32* %2
%40 = sitofp i32 %39 to float
%41 = fdiv float %38, %40
store float %41, float* %4
%42 = load float, float* %4
%43 = fpext float %42 to double
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), double %43)
%45 = load i32*, i32** %6
%46 = call i32 @free(i32* %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Numero de elementos: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"Valor da posi\C3\A7ao vetor[i]: \00"
@.str.3 = [13 x i8] c"Media = %.2f\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = shl i32 %5, 2
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %0, %11
%12 = phi i64 [ %20, %11 ], [ 0, %0 ]
%13 = phi float [ %19, %11 ], [ 0.000000e+00, %0 ]
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds i32, i32* %8, i64 %12
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%17 = load i32, i32* %15
%18 = sitofp i32 %17 to float
%19 = fadd float %13, %18
%20 = add nuw nsw i64 %12, 1
%21 = load i32, i32* %1
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %11, label %24
24: ; preds = %11, %0
%25 = phi float [ 0.000000e+00, %0 ], [ %19, %11 ]
%26 = phi i32 [ %9, %0 ], [ %21, %11 ]
%27 = sitofp i32 %26 to float
%28 = fdiv float %25, %27
%29 = fpext float %28 to double
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), double %29)
%31 = call i32 @free(i32* %8)
ret i32 0
}