#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(float *);
float *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
float valor(float *, int);
int main() {
  int quant;
  printf("Digite a quantidade: ");
  scanf("%d", &quant);
  float *vTotal = malloc(quant * sizeof(float));
  for (int i = 0; i < quant; i++) {
    printf("Digite o valor %d: ", i + 1);
    scanf("%f", &vTotal[i]);
  }
  float teste = valor(vTotal, quant);
  printf("\n %.2f", teste);
  free(vTotal);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea2(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e4 <main+0x94>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1199 <main+0x49>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <valor@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe2b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%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    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x4(%rsp),%ebp
lea    0x0(,%rbp,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    11db <main+0x8b>
lea    0xe7f(%rip),%r15
lea    0xe8c(%rip),%r12
mov    %r14,%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movslq 0x4(%rsp),%rbp
add    $0x4,%r13
cmp    %rbp,%rbx
jl     11b0 <main+0x60>
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <valor@plt>
cvtss2sd %xmm0,%xmm0
lea    0xe40(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Digite a quantidade: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Digite o valor %d: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [7 x i8] c"\0A %.2f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float*
%4 = alloca i32
%5 = alloca float
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 4
%11 = trunc i64 %10 to i32
%12 = call float* @malloc(i32 %11)
store float* %12, float** %3
store i32 0, i32* %4
br label %13
13: ; preds = %26, %0
%14 = load i32, i32* %4
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %29
17: ; preds = %13
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load float*, float** %3
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds float, float* %21, i64 %23
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %24)
br label %26
26: ; preds = %17
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %13
29: ; preds = %13
%30 = load float*, float** %3
%31 = load i32, i32* %2
%32 = call float @valor(float* %30, i32 %31)
store float %32, float* %5
%33 = load float, float* %5
%34 = fpext float %33 to double
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %34)
%36 = load float*, float** %3
%37 = call i32 @free(float* %36)
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [22 x i8] c"Digite a quantidade: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Digite o valor %d: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [7 x i8] c"\0A %.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 (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, 2
%7 = call float* @malloc(i32 %6)
%8 = icmp sgt i32 %5, 0
br i1 %8, label %15, label %9
9: ; preds = %15, %0
%10 = phi i32 [ %5, %0 ], [ %22, %15 ]
%11 = call float @valor(float* %7, i32 %10)
%12 = fpext float %11 to double
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %12)
%14 = call i32 @free(float* %7)
ret i32 0
15: ; preds = %0, %15
%16 = phi i64 [ %17, %15 ], [ 0, %0 ]
%17 = add nuw nsw i64 %16, 1
%18 = trunc i64 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds float, float* %7, i64 %16
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %20)
%22 = load i32, i32* %1
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %17, %23
br i1 %24, label %15, label %9
}