#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*/ avalia(double *, int, double);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  double x, *pol;
  int g;
  printf("Informe o grau do polinômio: ");
  scanf("%d", &g);
  pol = (double *)malloc((g + 1) * sizeof(double));
  printf("Informe os coeficientes:\n");
  for (int i = 0; i < g; i++) {
    scanf("%lf", &pol[i]);
  }
  printf("Informe o 'x' para ser avaliado: ");
  scanf("%lf", &x);
  printf("O resultado de P(%.2lf) = %.2lf\n", x, avalia(pol, g, x));
  free(pol);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeab(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e2 <main+0x92>
mov    -0x18(%rbp),%rsi
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11ab <main+0x5b>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe45(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
movsd  -0x10(%rbp),%xmm0
call   1030 <avalia@plt>
movsd  -0x28(%rbp),%xmm0
mov    %eax,%esi
lea    0xe37(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe9f(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x4(%rsp),%eax
lea    0x8(,%rax,8),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xec3(%rip),%rdi
call   1050 <puts@plt>
cmpl   $0x0,0x4(%rsp)
jle    11df <main+0x7f>
lea    0xe69(%rip),%r15
mov    %r14,%r12
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
add    $0x8,%r12
cmp    %rax,%rbx
jl     11c0 <main+0x60>
lea    0xe40(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2e(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1030 <avalia@plt>
lea    0xe29(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %r14,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Informe o grau do polin\C3\B4mio: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [26 x i8] c"Informe os coeficientes:\0A\00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [34 x i8] c"Informe o 'x' para ser avaliado: \00"
@.str.5 = [33 x i8] c"O resultado de P(%.2lf) = %.2lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 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* %4)
%8 = load i32, i32* %4
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 8
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to double*
store double* %14, double** %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %16
16: ; preds = %26, %0
%17 = load i32, i32* %5
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load double*, double** %3
%22 = load i32, i32* %5
%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)
br label %26
26: ; preds = %20
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %16
29: ; preds = %16
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %2)
%32 = load double, double* %2
%33 = load double*, double** %3
%34 = load i32, i32* %4
%35 = load double, double* %2
%36 = call i32 @avalia(double* %33, i32 %34, double %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), double %32, i32 %36)
%38 = load double*, double** %3
%39 = call i32 @free(double* %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"Informe o grau do polin\C3\B4mio: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [34 x i8] c"Informe o 'x' para ser avaliado: \00"
@.str.5 = [33 x i8] c"O resultado de P(%.2lf) = %.2lf\0A\00"
@str = [25 x i8] c"Informe os coeficientes:\00"
define i32 @main() {
%1 = alloca double
%2 = alloca i32
%3 = bitcast double* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 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* %2)
%7 = load i32, i32* %2
%8 = shl i32 %7, 3
%9 = add i32 %8, 8
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to double*
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %23, %0
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %1)
%18 = load double, double* %1
%19 = load i32, i32* %2
%20 = call i32 @avalia(double* %11, i32 %19, double %18)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), double %18, i32 %20)
%22 = call i32 @free(double* %11)
ret i32 0
23: ; preds = %0, %23
%24 = phi i64 [ %27, %23 ], [ 0, %0 ]
%25 = getelementptr inbounds double, double* %11, i64 %24
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %25)
%27 = add nuw nsw i64 %24, 1
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %23, label %15
}