double poly(x, p)
double x;
double *p;
{
  static int i;
  static double r, s;
  s = 1.0;
  r = 0.0;
  for (i = 0; i < p[0]; i++) {
    r += p[i + 1] * s;
    s *= x;
  }
  return (r);
}


x86 assembly (clang, -O0):
<poly>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movsd  0xeeb(%rip),%xmm0
movsd  %xmm0,0x2f1b(%rip)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2f08(%rip)
movl   $0x0,0x2ef6(%rip)
cvtsi2sdl 0x2eee(%rip),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    11aa <poly+0xaa>
mov    -0x10(%rbp),%rax
mov    0x2ed2(%rip),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0x2ecf(%rip),%xmm2
movsd  0x2ebf(%rip),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2eaf(%rip)
movsd  -0x8(%rbp),%xmm0
mulsd  0x2eaa(%rip),%xmm0
movsd  %xmm0,0x2ea2(%rip)
mov    0x2e8c(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e83(%rip)
jmp    1132 <poly+0x32>
movsd  0x2e7e(%rip),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<poly>:
movsd  (%rdi),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jbe    1142 <poly+0x42>
xorpd  %xmm1,%xmm1
movsd  0xee6(%rip),%xmm3
mov    $0x1,%eax
nop
movsd  (%rdi,%rax,8),%xmm4
mulsd  %xmm3,%xmm4
addsd  %xmm4,%xmm1
xorps  %xmm4,%xmm4
cvtsi2sd %eax,%xmm4
mulsd  %xmm0,%xmm3
add    $0x1,%rax
ucomisd %xmm4,%xmm2
ja     1120 <poly+0x20>
movapd %xmm1,%xmm0
ret

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

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