#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(int n, double a[], double x) {
  int i;
  double p = a[0];
  for (i = 1; i <= n; i++) {
    p += a[i] * pow(x, i);
  }
  return p;
}


x86 assembly (clang, -O0):
<poly>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     118b <poly+0x7b>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1138 <poly+0x28>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poly>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
movsd  (%rsi),%xmm1
test   %edi,%edi
jle    1269 <poly+0x159>
mov    %rsi,%r14
mov    %edi,%r12d
lea    -0x1(%r12),%rax
mov    %r12d,%r15d
and    $0x3,%r15d
cmp    $0x3,%rax
movsd  %xmm0,0x18(%rsp)
jae    1151 <poly+0x41>
mov    $0x1,%ebx
jmp    1227 <poly+0x117>
and    $0xfffffffc,%r12d
mov    $0x1,%ebx
xor    %r13d,%r13d
nopl   (%rax)
movsd  %xmm1,0x10(%rsp)
movsd  (%r14,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
mov    %ebx,%edi
call   1030 <pow@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0x1(%rbx),%edi
movsd  0x8(%r14,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1030 <pow@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0x2(%rbx),%edi
movsd  0x10(%r14,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1030 <pow@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0x3(%rbx),%edi
movsd  0x18(%r14,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1030 <pow@plt>
movapd %xmm0,%xmm1
mulsd  0x8(%rsp),%xmm1
addsd  0x10(%rsp),%xmm1
add    $0x4,%rbx
add    $0x4,%r13
cmp    %r12,%r13
jne    1160 <poly+0x50>
test   %r15,%r15
je     1269 <poly+0x159>
nopl   0x0(%rax)
movsd  %xmm1,0x10(%rsp)
movsd  (%r14,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
mov    %ebx,%edi
call   1030 <pow@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm1
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
jne    1230 <poly+0x120>
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define double @poly(i32 %0, double* nocapture %1, double %2) {
%4 = load double, double* %1
%5 = icmp slt i32 %0, 1
br i1 %5, label %62, label %6
6: ; preds = %3
%7 = add nuw i32 %0, 1
%8 = zext i32 %7 to i64
%9 = add nsw i64 %8, -1
%10 = add nsw i64 %8, -2
%11 = and i64 %9, 3
%12 = icmp ult i64 %10, 3
br i1 %12, label %45, label %13
13: ; preds = %6
%14 = and i64 %9, -4
br label %15
15: ; preds = %15, %13
%16 = phi i64 [ 1, %13 ], [ %42, %15 ]
%17 = phi double [ %4, %13 ], [ %41, %15 ]
%18 = phi i64 [ 0, %13 ], [ %43, %15 ]
%19 = getelementptr inbounds double, double* %1, i64 %16
%20 = load double, double* %19
%21 = trunc i64 %16 to i32
%22 = tail call double @pow(double %2, i32 %21)
%23 = tail call double @llvm.fmuladd.f64(double %20, double %22, double %17)
%24 = add nuw nsw i64 %16, 1
%25 = getelementptr inbounds double, double* %1, i64 %24
%26 = load double, double* %25
%27 = trunc i64 %24 to i32
%28 = tail call double @pow(double %2, i32 %27)
%29 = tail call double @llvm.fmuladd.f64(double %26, double %28, double %23)
%30 = add nuw nsw i64 %16, 2
%31 = getelementptr inbounds double, double* %1, i64 %30
%32 = load double, double* %31
%33 = trunc i64 %30 to i32
%34 = tail call double @pow(double %2, i32 %33)
%35 = tail call double @llvm.fmuladd.f64(double %32, double %34, double %29)
%36 = add nuw nsw i64 %16, 3
%37 = getelementptr inbounds double, double* %1, i64 %36
%38 = load double, double* %37
%39 = trunc i64 %36 to i32
%40 = tail call double @pow(double %2, i32 %39)
%41 = tail call double @llvm.fmuladd.f64(double %38, double %40, double %35)
%42 = add nuw nsw i64 %16, 4
%43 = add i64 %18, 4
%44 = icmp eq i64 %43, %14
br i1 %44, label %45, label %15
45: ; preds = %15, %6
%46 = phi double [ undef, %6 ], [ %41, %15 ]
%47 = phi i64 [ 1, %6 ], [ %42, %15 ]
%48 = phi double [ %4, %6 ], [ %41, %15 ]
%49 = icmp eq i64 %11, 0
br i1 %49, label %62, label %50
50: ; preds = %45, %50
%51 = phi i64 [ %59, %50 ], [ %47, %45 ]
%52 = phi double [ %58, %50 ], [ %48, %45 ]
%53 = phi i64 [ %60, %50 ], [ 0, %45 ]
%54 = getelementptr inbounds double, double* %1, i64 %51
%55 = load double, double* %54
%56 = trunc i64 %51 to i32
%57 = tail call double @pow(double %2, i32 %56)
%58 = tail call double @llvm.fmuladd.f64(double %55, double %57, double %52)
%59 = add nuw nsw i64 %51, 1
%60 = add i64 %53, 1
%61 = icmp eq i64 %60, %11
br i1 %61, label %62, label %50
62: ; preds = %45, %50, %3
%63 = phi double [ %4, %3 ], [ %46, %45 ], [ %58, %50 ]
ret double %63
}