#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 fn(double, double *, int);
int /*<<< orphan*/ printf(char *, double, double);
void horner() {
  double a[] = {1, 2, 3, 4, 5};
  double x;
  for (x = 1; x <= 5; x++) {
    printf("fn(%f)=%f\n", x, fn(x, a, 4));
  }
}


x86 assembly (clang, -O0):
<horner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
movsd  0xeb0(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xec3(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeae(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe99(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe84(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe6f(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe6a(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     11f1 <horner+0xc1>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
call   1030 <fn@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
movsd  0xe1e(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1196 <horner+0x66>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<horner>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps 0xed2(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xed7(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x4014000000000000,%rax
mov    %rax,0x20(%rsp)
movsd  0xecb(%rip),%xmm0
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <fn@plt>
movaps %xmm0,%xmm1
lea    0xed9(%rip),%rbx
mov    %rbx,%rdi
movsd  0xea6(%rip),%xmm0
call   1040 <printf@plt>
movsd  0xea1(%rip),%xmm0
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <fn@plt>
movaps %xmm0,%xmm1
mov    %rbx,%rdi
movsd  0xe86(%rip),%xmm0
call   1040 <printf@plt>
movsd  0xe81(%rip),%xmm0
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <fn@plt>
movaps %xmm0,%xmm1
mov    %rbx,%rdi
movsd  0xe66(%rip),%xmm0
call   1040 <printf@plt>
movsd  0xe61(%rip),%xmm0
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <fn@plt>
movaps %xmm0,%xmm1
mov    %rbx,%rdi
movsd  0xe46(%rip),%xmm0
call   1040 <printf@plt>
movsd  0xe41(%rip),%xmm0
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <fn@plt>
movaps %xmm0,%xmm1
mov    %rbx,%rdi
movsd  0xe26(%rip),%xmm0
call   1040 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"fn(%f)=%f\0A\00"
define void @horner() {
%1 = alloca [5 x double]
%2 = alloca double
%3 = bitcast [5 x double]* %1 to i8*
%4 = bitcast i8* %3 to [5 x double]*
%5 = getelementptr inbounds [5 x double], [5 x double]* %4, i32 0, i32 0
store double 1.000000e+00, double* %5
%6 = getelementptr inbounds [5 x double], [5 x double]* %4, i32 0, i32 1
store double 2.000000e+00, double* %6
%7 = getelementptr inbounds [5 x double], [5 x double]* %4, i32 0, i32 2
store double 3.000000e+00, double* %7
%8 = getelementptr inbounds [5 x double], [5 x double]* %4, i32 0, i32 3
store double 4.000000e+00, double* %8
%9 = getelementptr inbounds [5 x double], [5 x double]* %4, i32 0, i32 4
store double 5.000000e+00, double* %9
store double 1.000000e+00, double* %2
br label %10
10: ; preds = %19, %0
%11 = load double, double* %2
%12 = fcmp ole double %11, 5.000000e+00
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load double, double* %2
%15 = load double, double* %2
%16 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 0
%17 = call double @fn(double %15, double* %16, i32 4)
%18 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double %14, double %17)
br label %19
19: ; preds = %13
%20 = load double, double* %2
%21 = fadd double %20, 1.000000e+00
store double %21, double* %2
br label %10
22: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"fn(%f)=%f\0A\00"
define void @horner() {
%1 = alloca [5 x double]
%2 = bitcast [5 x double]* %1 to i8*
%3 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 0
%4 = bitcast [5 x double]* %1 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 2.000000e+00>, <2 x double>* %4
%5 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 2
%6 = bitcast double* %5 to <2 x double>*
store <2 x double> <double 3.000000e+00, double 4.000000e+00>, <2 x double>* %6
%7 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 4
store double 5.000000e+00, double* %7
%8 = call double @fn(double 1.000000e+00, double* %3, i32 4)
%9 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double 1.000000e+00, double %8)
%10 = call double @fn(double 2.000000e+00, double* %3, i32 4)
%11 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double 2.000000e+00, double %10)
%12 = call double @fn(double 3.000000e+00, double* %3, i32 4)
%13 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double 3.000000e+00, double %12)
%14 = call double @fn(double 4.000000e+00, double* %3, i32 4)
%15 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double 4.000000e+00, double %14)
%16 = call double @fn(double 5.000000e+00, double* %3, i32 4)
%17 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double 5.000000e+00, double %16)
ret void
}