#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 _pow(double, int);
double poly(double x, int n, double c[]) {
  double y = 0;
  while (n >= 0) {
    y += c[n] * _pow(x, n);
    n--;
  }
  return y;
}


x86 assembly (clang, -O0):
<poly>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     117d <poly+0x6d>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0xc(%rbp),%edi
call   1030 <_pow@plt>
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    112c <poly+0x1c>
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poly>:
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
js     1166 <poly+0x56>
mov    %rsi,%r14
mov    %edi,%ebx
xorpd  %xmm1,%xmm1
movsd  %xmm0,(%rsp)
nopl   0x0(%rax)
movsd  %xmm1,0x10(%rsp)
movsd  (%r14,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
mov    %ebx,%edi
call   1030 <_pow@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm1
add    $0xffffffffffffffff,%rbx
jb     1130 <poly+0x20>
jmp    116a <poly+0x5a>
xorpd  %xmm1,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define double @poly(double %0, i32 %1, double* nocapture %2) {
%4 = icmp sgt i32 %1, -1
br i1 %4, label %5, label %17
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ %6, %5 ], [ %15, %7 ]
%9 = phi double [ 0.000000e+00, %5 ], [ %14, %7 ]
%10 = getelementptr inbounds double, double* %2, i64 %8
%11 = load double, double* %10
%12 = trunc i64 %8 to i32
%13 = tail call double @_pow(double %0, i32 %12)
%14 = tail call double @llvm.fmuladd.f64(double %11, double %13, double %9)
%15 = add nsw i64 %8, -1
%16 = icmp eq i64 %8, 0
br i1 %16, label %17, label %7
17: ; preds = %7, %3
%18 = phi double [ 0.000000e+00, %3 ], [ %14, %7 ]
ret double %18
}