#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 */
void polynomial_fit(double x, double *basis, size_t n, void *user) {
  basis[0] = 1;
  for (size_t j = 1; j < n; j++)
    basis[j] = basis[j - 1] * x;
}


x86 assembly (clang, -O0):
<polynomial_fit>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  0xedf(%rip),%xmm0
movsd  %xmm0,(%rax)
movq   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    116f <polynomial_fit+0x6f>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x8(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    112d <polynomial_fit+0x2d>
pop    %rbp
ret

x86 assembly (clang, -O2):
<polynomial_fit>:
movabs $0x3ff0000000000000,%rax
mov    %rax,(%rdi)
cmp    $0x2,%rsi
jb     11a2 <polynomial_fit+0xa2>
lea    -0x1(%rsi),%rdx
add    $0xfffffffffffffffe,%rsi
mov    %edx,%eax
and    $0x3,%eax
cmp    $0x3,%rsi
jae    113e <polynomial_fit+0x3e>
mov    $0x1,%ecx
movsd  0xec9(%rip),%xmm1
test   %rax,%rax
jne    118a <polynomial_fit+0x8a>
jmp    11a2 <polynomial_fit+0xa2>
and    $0xfffffffffffffffc,%rdx
movsd  0xeb6(%rip),%xmm1
xor    %ecx,%ecx
nopl   0x0(%rax)
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rdi,%rcx,8)
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rdi,%rcx,8)
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rdi,%rcx,8)
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rdi,%rcx,8)
add    $0x4,%rcx
cmp    %rcx,%rdx
jne    1150 <polynomial_fit+0x50>
add    $0x1,%rcx
test   %rax,%rax
je     11a2 <polynomial_fit+0xa2>
lea    (%rdi,%rcx,8),%rcx
xor    %edx,%edx
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rcx,%rdx,8)
add    $0x1,%rdx
cmp    %rdx,%rax
jne    1190 <polynomial_fit+0x90>
ret

LLVM IR (-O0):
define void @polynomial_fit(double %0, double* %1, i64 %2, i8* %3) {
%5 = alloca double
%6 = alloca double*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
store double %0, double* %5
store double* %1, double** %6
store i64 %2, i64* %7
store i8* %3, i8** %8
%10 = load double*, double** %6
%11 = getelementptr inbounds double, double* %10, i64 0
store double 1.000000e+00, double* %11
store i64 1, i64* %9
br label %12
12: ; preds = %27, %4
%13 = load i64, i64* %9
%14 = load i64, i64* %7
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = load double*, double** %6
%18 = load i64, i64* %9
%19 = sub i64 %18, 1
%20 = getelementptr inbounds double, double* %17, i64 %19
%21 = load double, double* %20
%22 = load double, double* %5
%23 = fmul double %21, %22
%24 = load double*, double** %6
%25 = load i64, i64* %9
%26 = getelementptr inbounds double, double* %24, i64 %25
store double %23, double* %26
br label %27
27: ; preds = %16
%28 = load i64, i64* %9
%29 = add i64 %28, 1
store i64 %29, i64* %9
br label %12
30: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @polynomial_fit(double %0, double* nocapture %1, i64 %2, i8* nocapture readnone %3) {
store double 1.000000e+00, double* %1
%5 = icmp ugt i64 %2, 1
br i1 %5, label %6, label %26
6: ; preds = %4
%7 = add i64 %2, -1
%8 = add i64 %2, -2
%9 = and i64 %7, 3
%10 = icmp ult i64 %8, 3
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = and i64 %7, -4
br label %27
13: ; preds = %27, %6
%14 = phi double [ 1.000000e+00, %6 ], [ %40, %27 ]
%15 = phi i64 [ 1, %6 ], [ %42, %27 ]
%16 = icmp eq i64 %9, 0
br i1 %16, label %26, label %17
17: ; preds = %13, %17
%18 = phi double [ %21, %17 ], [ %14, %13 ]
%19 = phi i64 [ %23, %17 ], [ %15, %13 ]
%20 = phi i64 [ %24, %17 ], [ 0, %13 ]
%21 = fmul double %18, %0
%22 = getelementptr inbounds double, double* %1, i64 %19
store double %21, double* %22
%23 = add nuw i64 %19, 1
%24 = add i64 %20, 1
%25 = icmp eq i64 %24, %9
br i1 %25, label %26, label %17
26: ; preds = %13, %17, %4
ret void
27: ; preds = %27, %11
%28 = phi double [ 1.000000e+00, %11 ], [ %40, %27 ]
%29 = phi i64 [ 1, %11 ], [ %42, %27 ]
%30 = phi i64 [ 0, %11 ], [ %43, %27 ]
%31 = fmul double %28, %0
%32 = getelementptr inbounds double, double* %1, i64 %29
store double %31, double* %32
%33 = add nuw nsw i64 %29, 1
%34 = fmul double %31, %0
%35 = getelementptr inbounds double, double* %1, i64 %33
store double %34, double* %35
%36 = add nuw nsw i64 %29, 2
%37 = fmul double %34, %0
%38 = getelementptr inbounds double, double* %1, i64 %36
store double %37, double* %38
%39 = add nuw i64 %29, 3
%40 = fmul double %37, %0
%41 = getelementptr inbounds double, double* %1, i64 %39
store double %40, double* %41
%42 = add nuw i64 %29, 4
%43 = add i64 %30, 4
%44 = icmp eq i64 %43, %12
br i1 %44, label %13, label %27
}