#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 *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  double *valores;
  int cantidad;
  printf("Ingresa la cantidad de numeros a promediar: ");
  scanf("%d", &cantidad);
  valores = malloc((cantidad + 1) * sizeof(double));
  for (int i = 0; i < cantidad; i++) {
    printf("Ingresa el valor %d: ", i + 1);
    scanf("%lf", valores + i);
    *(valores + cantidad + 1) += *(valores + i);
  }
  printf("El promedio es: %.2lf\n", *(valores + cantidad + 1) / cantidad);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed9(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e9 <main+0xb9>
mov    -0x18(%rbp),%esi
add    $0x1,%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
addsd  0x8(%rax,%rcx,8),%xmm0
movsd  %xmm0,0x8(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117d <main+0x4d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  0x8(%rax,%rcx,8),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xe43(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xedd(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movslq 0x4(%rsp),%rbp
lea    0x8(,%rbp,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %rbp,%rbp
jle    11d1 <main+0xa1>
lea    0xeb4(%rip),%r14
lea    0xec3(%rip),%r15
mov    %r12,%r13
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movsd  0x0(%r13),%xmm0
movslq 0x4(%rsp),%rbp
addsd  0x8(%r12,%rbp,8),%xmm0
movsd  %xmm0,0x8(%r12,%rbp,8)
add    $0x8,%r13
cmp    %rbp,%rbx
jl     1190 <main+0x60>
jmp    11d8 <main+0xa8>
movsd  0x8(%r12,%rbp,8),%xmm0
cvtsi2sd %ebp,%xmm1
divsd  %xmm1,%xmm0
lea    0xe63(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"Ingresa la cantidad de numeros a promediar: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"Ingresa el valor %d: \00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [23 x i8] c"El promedio es: %.2lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = add nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i32
%12 = call double* @malloc(i32 %11)
store double* %12, double** %2
store i32 0, i32* %4
br label %13
13: ; preds = %38, %0
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %41
17: ; preds = %13
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load double*, double** %2
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %24)
%26 = load double*, double** %2
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double*, double** %2
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = getelementptr inbounds double, double* %34, i64 1
%36 = load double, double* %35
%37 = fadd double %36, %30
store double %37, double* %35
br label %38
38: ; preds = %17
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %13
41: ; preds = %13
%42 = load double*, double** %2
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = getelementptr inbounds double, double* %45, i64 1
%47 = load double, double* %46
%48 = load i32, i32* %3
%49 = sitofp i32 %48 to double
%50 = fdiv double %47, %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), double %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [45 x i8] c"Ingresa la cantidad de numeros a promediar: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"Ingresa el valor %d: \00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [23 x i8] c"El promedio es: %.2lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @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, 3
%7 = add i32 %6, 8
%8 = call double* @malloc(i32 %7)
%9 = icmp sgt i32 %5, 0
br i1 %9, label %15, label %10
10: ; preds = %0
%11 = sext i32 %5 to i64
%12 = getelementptr inbounds double, double* %8, i64 %11
%13 = getelementptr inbounds double, double* %12, i64 1
%14 = load double, double* %13
br label %17
15: ; preds = %0
%16 = getelementptr inbounds double, double* %8, i64 1
br label %23
17: ; preds = %23, %10
%18 = phi double [ %14, %10 ], [ %35, %23 ]
%19 = phi i32 [ %5, %10 ], [ %31, %23 ]
%20 = sitofp i32 %19 to double
%21 = fdiv double %18, %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), double %21)
ret i32 0
23: ; preds = %15, %23
%24 = phi i64 [ 0, %15 ], [ %25, %23 ]
%25 = add nuw nsw i64 %24, 1
%26 = trunc i64 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds double, double* %8, i64 %24
%29 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %28)
%30 = load double, double* %28
%31 = load i32, i32* %1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %16, i64 %32
%34 = load double, double* %33
%35 = fadd double %30, %34
store double %35, double* %33
%36 = icmp slt i64 %25, %32
br i1 %36, label %23, label %17
}