#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 *);
scalar_t__ malloc(int);
int /*<<< orphan*/ media(int, float *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int num;
  printf("\nBem vindo ao programa Calcula Media!\nEste programa calcula a "
         "media de uma amostra de dados.\n\n");
  printf("Qual eh o tamanho de sua amostra?\t");
  scanf("%i", &num);
  while (num < 1) {
    printf("Sua entrada eh invalida. Digite um valor estritamente maior que "
           "zero.\n");
    scanf("%i", &num);
  }
  float *ponteiro = (float *)malloc(num * sizeof(float));
  media(num, ponteiro);
  free(ponteiro);
  printf("\nObrigado por usar o programa!\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    0xeed(%rip),%rdi
call   1040 <printf@plt>
lea    0xf04(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jge    11b2 <main+0x62>
lea    0xeed(%rip),%rdi
call   1040 <printf@plt>
lea    0xede(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
jmp    1187 <main+0x37>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <media@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xeeb(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb6(%rip),%rdi
call   1040 <puts@plt>
lea    0xe84(%rip),%rdi
call   1050 <printf@plt>
lea    0xe9b(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%edi
test   %edi,%edi
jg     11cb <main+0x6b>
lea    0xf02(%rip),%r14
lea    0xe7b(%rip),%r15
lea    0xc(%rsp),%rbx
nopl   (%rax)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%edi
test   %edi,%edi
jle    11b0 <main+0x50>
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%edi
mov    %rax,%rsi
call   1080 <media@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe93(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [95 x i8] c"\0ABem vindo ao programa Calcula Media!\0AEste programa calcula a media de uma amostra de dados.\0A\0A\00"
@.str.1 = [35 x i8] c"Qual eh o tamanho de sua amostra?\09\00"
@.str.2 = [3 x i8] c"%i\00"
@.str.3 = [71 x i8] c"Sua entrada eh invalida. Digite um valor estritamente maior que zero.\0A\00"
@.str.4 = [32 x i8] c"\0AObrigado por usar o programa!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float*
store i32 0, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
br label %7
7: ; preds = %10, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
br label %7
13: ; preds = %7
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to float*
store float* %19, float** %3
%20 = load i32, i32* %2
%21 = load float*, float** %3
%22 = call i32 @media(i32 %20, float* %21)
%23 = load float*, float** %3
%24 = call i32 @free(float* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [35 x i8] c"Qual eh o tamanho de sua amostra?\09\00"
@.str.2 = [3 x i8] c"%i\00"
@str = [94 x i8] c"\0ABem vindo ao programa Calcula Media!\0AEste programa calcula a media de uma amostra de dados.\0A\00"
@str.5 = [31 x i8] c"\0AObrigado por usar o programa!\00"
@str.6 = [70 x i8] c"Sua entrada eh invalida. Digite um valor estritamente maior que zero.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([94 x i8], [94 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %13
8: ; preds = %0, %8
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.6, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 1
br i1 %12, label %8, label %13
13: ; preds = %8, %0
%14 = phi i32 [ %6, %0 ], [ %11, %8 ]
%15 = shl i32 %14, 2
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to float*
%18 = load i32, i32* %1
%19 = call i32 @media(i32 %18, float* %17)
%20 = call i32 @free(float* %17)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}