#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 */
struct poly {
  int dummy;
};

/* Variables and functions */
int polyDegree(struct poly *);
double polyGetCoefficient(struct poly *, int);
double pow(double, int);
double polyEval(struct poly *p, double x) {
  double sum = 0;
  for (int i = 0; i <= polyDegree(p); i++)
    sum += polyGetCoefficient(p, i) * pow(x, i);
  return sum;
}


x86 assembly (clang, -O0):
<polyEval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <polyDegree@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jg     11b2 <polyEval+0x82>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <polyGetCoefficient@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
call   1050 <pow@plt>
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1150 <polyEval+0x20>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<polyEval>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
call   1040 <polyDegree@plt>
xorpd  %xmm0,%xmm0
test   %eax,%eax
js     11a2 <polyEval+0x72>
movsd  %xmm0,(%rsp)
mov    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <polyGetCoefficient@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
mov    %ebp,%edi
call   1050 <pow@plt>
mulsd  0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    %rbx,%rdi
call   1040 <polyDegree@plt>
cmp    %eax,%ebp
jl     1160 <polyEval+0x30>
jmp    11a7 <polyEval+0x77>
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.poly = type { i32 }
define double @polyEval(%struct.poly* %0, double %1) {
%3 = alloca %struct.poly*
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store %struct.poly* %0, %struct.poly** %3
store double %1, double* %4
store double 0.000000e+00, double* %5
store i32 0, i32* %6
br label %7
7: ; preds = %21, %2
%8 = load i32, i32* %6
%9 = load %struct.poly*, %struct.poly** %3
%10 = call i32 @polyDegree(%struct.poly* %9)
%11 = icmp sle i32 %8, %10
br i1 %11, label %12, label %24
12: ; preds = %7
%13 = load %struct.poly*, %struct.poly** %3
%14 = load i32, i32* %6
%15 = call double @polyGetCoefficient(%struct.poly* %13, i32 %14)
%16 = load double, double* %4
%17 = load i32, i32* %6
%18 = call double @pow(double %16, i32 %17)
%19 = load double, double* %5
%20 = call double @llvm.fmuladd.f64(double %15, double %18, double %19)
store double %20, double* %5
br label %21
21: ; preds = %12
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %7
24: ; preds = %7
%25 = load double, double* %5
ret double %25
}

LLVM IR (-O2):
%struct.poly = type { i32 }
define double @polyEval(%struct.poly* %0, double %1) {
%3 = tail call i32 @polyDegree(%struct.poly* %0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %7, %2
%6 = phi double [ 0.000000e+00, %2 ], [ %12, %7 ]
ret double %6
7: ; preds = %2, %7
%8 = phi i32 [ %13, %7 ], [ 0, %2 ]
%9 = phi double [ %12, %7 ], [ 0.000000e+00, %2 ]
%10 = tail call double @polyGetCoefficient(%struct.poly* %0, i32 %8)
%11 = tail call double @pow(double %1, i32 %8)
%12 = tail call double @llvm.fmuladd.f64(double %10, double %11, double %9)
%13 = add nuw nsw i32 %8, 1
%14 = tail call i32 @polyDegree(%struct.poly* %0)
%15 = icmp slt i32 %8, %14
br i1 %15, label %7, label %5
}