#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 atof(char *);
int /*<<< orphan*/ polynomial_regression(double *, double *, double *, int,
                                         int);
double pow(double, int);
int /*<<< orphan*/ printf(char *, ...);
void test_regression(int argc, char *argv[]) {
  if (argc < 2) {
    printf("usage: %s <b0> [b1] [b2] ...\n", argv[0]);
    return;
  }
  int i, j, d = argc - 1, n = 100;
  double b[argc - 1];
  for (i = 0; i < d; i++)
    b[i] = atof(argv[i + 1]);
  double x[n], y[n];
  for (i = 0; i < n; i++) {
    x[i] = i;
    y[i] = b[0];
    for (j = 1; j < d; j++)
      y[i] += b[j] * pow(x[i], j);
  }
  polynomial_regression(b, x, y, n, d);
  printf("b = [ ");
  for (i = 0; i < d; i++)
    printf("%f ", b[i]);
  printf("]\n");
}


x86 assembly (clang, -O0):
<test_regression>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    1173 <test_regression+0x33>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    135f <test_regression+0x21f>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x64,-0x20(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f1 <test_regression+0xb1>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <atof@plt>
mov    -0x48(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b4 <test_regression+0x74>
mov    -0x20(%rbp),%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12e8 <test_regression+0x1a8>
mov    -0x50(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    -0x58(%rbp),%rdx
cvtsi2sdl -0x14(%rbp),%xmm0
movslq -0x14(%rbp),%rsi
movsd  %xmm0,(%rdx,%rsi,8)
movsd  (%rcx),%xmm0
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12d5 <test_regression+0x195>
mov    -0x58(%rbp),%rax
mov    -0x48(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%edi
call   1060 <pow@plt>
mov    -0x50(%rbp),%rax
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1272 <test_regression+0x132>
jmp    12da <test_regression+0x19a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1238 <test_regression+0xf8>
mov    -0x50(%rbp),%rdx
mov    -0x58(%rbp),%rsi
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1050 <polynomial_regression@plt>
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    134a <test_regression+0x20a>
mov    -0x48(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xcf0(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1315 <test_regression+0x1d5>
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_regression>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jg     1188 <test_regression+0x38>
mov    (%r14),%rsi
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>
mov    %rsp,-0x60(%rbp)
mov    %rdi,-0x40(%rbp)
lea    -0x1(%rdi),%r12d
mov    %rsp,%r13
lea    0xf(,%r12,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbx),%r15
mov    0x8(%r14,%rbx,8),%rdi
call   1040 <atof@plt>
movsd  %xmm0,0x0(%r13,%rbx,8)
mov    %r15,%rbx
cmp    %r15,%r12
jne    11b0 <test_regression+0x60>
movsd  0x0(%r13),%xmm0
mov    %rsp,%rsi
add    $0xfffffffffffffce0,%rsi
mov    %rsi,%rsp
mov    %rsp,%rbx
add    $0xfffffffffffffce0,%rbx
mov    %rbx,%rsp
lea    -0x1(%r12),%rcx
mov    %rcx,%rax
mov    %rcx,-0x70(%rbp)
and    $0xfffffffffffffffe,%rcx
mov    %rcx,-0x78(%rbp)
xor    %r14d,%r14d
mov    -0x40(%rbp),%rax
mov    %rsi,-0x50(%rbp)
movsd  %xmm0,-0x48(%rbp)
mov    %r12,-0x68(%rbp)
jmp    122e <test_regression+0xde>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    $0x64,%r14
je     133c <test_regression+0x1ec>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
movsd  %xmm1,(%rsi,%r14,8)
movsd  %xmm0,(%rbx,%r14,8)
cmp    $0x3,%eax
jl     1220 <test_regression+0xd0>
mov    $0x1,%r15d
movapd %xmm0,%xmm2
cmp    $0x2,%r12d
je     12f3 <test_regression+0x1a3>
mov    $0x1,%r15d
movapd %xmm0,%xmm2
movsd  %xmm1,-0x58(%rbp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm2,-0x38(%rbp)
movsd  0x0(%r13,%r15,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movapd %xmm1,%xmm0
mov    %r15d,%edi
call   1070 <pow@plt>
mulsd  -0x30(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  %xmm0,(%rbx,%r14,8)
movsd  0x8(%r13,%r15,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0x1(%r15),%r12
movsd  -0x58(%rbp),%xmm0
mov    %r12d,%edi
call   1070 <pow@plt>
movsd  -0x58(%rbp),%xmm1
movapd %xmm0,%xmm2
mulsd  -0x30(%rbp),%xmm2
addsd  -0x38(%rbp),%xmm2
movsd  %xmm2,(%rbx,%r14,8)
add    $0x2,%r15
cmp    -0x78(%rbp),%r12
jne    1270 <test_regression+0x120>
mov    -0x68(%rbp),%r12
mov    -0x40(%rbp),%rax
mov    -0x50(%rbp),%rsi
movsd  -0x48(%rbp),%xmm0
testb  $0x1,-0x70(%rbp)
je     1220 <test_regression+0xd0>
movsd  0x0(%r13,%r15,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movapd %xmm1,%xmm0
mov    %r15d,%edi
movsd  %xmm2,-0x38(%rbp)
call   1070 <pow@plt>
mov    -0x50(%rbp),%rsi
mov    -0x40(%rbp),%rax
mulsd  -0x30(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,(%rbx,%r14,8)
movsd  -0x48(%rbp),%xmm0
jmp    1220 <test_regression+0xd0>
mov    %rax,%r14
mov    %r13,%rdi
mov    %rbx,%rdx
mov    $0x64,%ecx
mov    %r12d,%r8d
call   1060 <polynomial_regression@plt>
lea    0xcc5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%r14d
jl     138a <test_regression+0x23a>
xor    %ebx,%ebx
lea    0xcb6(%rip),%r14
nop
movsd  0x0(%r13,%rbx,8),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1370 <test_regression+0x220>
lea    0xc98(%rip),%rdi
call   1030 <puts@plt>
mov    -0x60(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"usage: %s <b0> [b1] [b2] ...\0A\00"
@.str.1 = [7 x i8] c"b = [ \00"
@.str.2 = [4 x i8] c"%f \00"
@.str.3 = [3 x i8] c"]\0A\00"
define void @test_regression(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %4
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %116
20: ; preds = %2
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 1
store i32 %22, i32* %7
store i32 100, i32* %8
%23 = load i32, i32* %3
%24 = sub nsw i32 %23, 1
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %9
%27 = alloca double, i64 %25
store i64 %25, i64* %10
store i32 0, i32* %5
br label %28
28: ; preds = %43, %20
%29 = load i32, i32* %5
%30 = load i32, i32* %7
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %46
32: ; preds = %28
%33 = load i8**, i8*** %4
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %33, i64 %36
%38 = load i8*, i8** %37
%39 = call double @atof(i8* %38)
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %27, i64 %41
store double %39, double* %42
br label %43
43: ; preds = %32
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %28
46: ; preds = %28
%47 = load i32, i32* %8
%48 = zext i32 %47 to i64
%49 = alloca double, i64 %48
store i64 %48, i64* %11
%50 = load i32, i32* %8
%51 = zext i32 %50 to i64
%52 = alloca double, i64 %51
store i64 %51, i64* %12
store i32 0, i32* %5
br label %53
53: ; preds = %92, %46
%54 = load i32, i32* %5
%55 = load i32, i32* %8
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %95
57: ; preds = %53
%58 = load i32, i32* %5
%59 = sitofp i32 %58 to double
%60 = load i32, i32* %5
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %49, i64 %61
store double %59, double* %62
%63 = getelementptr inbounds double, double* %27, i64 0
%64 = load double, double* %63
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %52, i64 %66
store double %64, double* %67
store i32 1, i32* %6
br label %68
68: ; preds = %88, %57
%69 = load i32, i32* %6
%70 = load i32, i32* %7
%71 = icmp slt i32 %69, %70
br i1 %71, label %72, label %91
72: ; preds = %68
%73 = load i32, i32* %6
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds double, double* %27, i64 %74
%76 = load double, double* %75
%77 = load i32, i32* %5
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %49, i64 %78
%80 = load double, double* %79
%81 = load i32, i32* %6
%82 = call double @pow(double %80, i32 %81)
%83 = load i32, i32* %5
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %52, i64 %84
%86 = load double, double* %85
%87 = call double @llvm.fmuladd.f64(double %76, double %82, double %86)
store double %87, double* %85
br label %88
88: ; preds = %72
%89 = load i32, i32* %6
%90 = add nsw i32 %89, 1
store i32 %90, i32* %6
br label %68
91: ; preds = %68
br label %92
92: ; preds = %91
%93 = load i32, i32* %5
%94 = add nsw i32 %93, 1
store i32 %94, i32* %5
br label %53
95: ; preds = %53
%96 = load i32, i32* %8
%97 = load i32, i32* %7
%98 = call i32 @polynomial_regression(double* %27, double* %49, double* %52, i32 %96, i32 %97)
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %100
100: ; preds = %110, %95
%101 = load i32, i32* %5
%102 = load i32, i32* %7
%103 = icmp slt i32 %101, %102
br i1 %103, label %104, label %113
104: ; preds = %100
%105 = load i32, i32* %5
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds double, double* %27, i64 %106
%108 = load double, double* %107
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %108)
br label %110
110: ; preds = %104
%111 = load i32, i32* %5
%112 = add nsw i32 %111, 1
store i32 %112, i32* %5
br label %100
113: ; preds = %100
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%115 = load i8*, i8** %9
br label %116
116: ; preds = %113, %15
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"usage: %s <b0> [b1] [b2] ...\0A\00"
@.str.1 = [7 x i8] c"b = [ \00"
@.str.2 = [4 x i8] c"%f \00"
@str = [2 x i8] c"]\00"
define void @test_regression(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %82
7: ; preds = %2
%8 = add nsw i32 %0, -1
%9 = zext i32 %8 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca double, i64 %9
br label %12
12: ; preds = %7, %12
%13 = phi i64 [ 0, %7 ], [ %14, %12 ]
%14 = add nuw nsw i64 %13, 1
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = tail call double @atof(i8* %16)
%18 = getelementptr inbounds double, double* %11, i64 %13
store double %17, double* %18
%19 = icmp eq i64 %14, %9
br i1 %19, label %20, label %12
20: ; preds = %12
%21 = load double, double* %11
%22 = alloca [100 x double]
%23 = alloca [100 x double]
%24 = getelementptr inbounds [100 x double], [100 x double]* %23, i64 0, i64 0
%25 = icmp sgt i32 %0, 2
%26 = add nsw i64 %9, -1
%27 = and i64 %26, 1
%28 = icmp eq i32 %8, 2
%29 = and i64 %26, -2
%30 = icmp eq i64 %27, 0
br label %31
31: ; preds = %20, %65
%32 = phi i64 [ 0, %20 ], [ %66, %65 ]
%33 = trunc i64 %32 to i32
%34 = sitofp i32 %33 to double
%35 = getelementptr inbounds [100 x double], [100 x double]* %22, i64 0, i64 %32
store double %34, double* %35
%36 = getelementptr inbounds [100 x double], [100 x double]* %23, i64 0, i64 %32
store double %21, double* %36
br i1 %25, label %37, label %65
37: ; preds = %31
br i1 %28, label %56, label %38
38: ; preds = %37, %38
%39 = phi double [ %52, %38 ], [ %21, %37 ]
%40 = phi i64 [ %53, %38 ], [ 1, %37 ]
%41 = phi i64 [ %54, %38 ], [ 0, %37 ]
%42 = getelementptr inbounds double, double* %11, i64 %40
%43 = load double, double* %42
%44 = trunc i64 %40 to i32
%45 = tail call double @pow(double %34, i32 %44)
%46 = tail call double @llvm.fmuladd.f64(double %43, double %45, double %39)
store double %46, double* %36
%47 = add nuw nsw i64 %40, 1
%48 = getelementptr inbounds double, double* %11, i64 %47
%49 = load double, double* %48
%50 = trunc i64 %47 to i32
%51 = tail call double @pow(double %34, i32 %50)
%52 = tail call double @llvm.fmuladd.f64(double %49, double %51, double %46)
store double %52, double* %36
%53 = add nuw nsw i64 %40, 2
%54 = add i64 %41, 2
%55 = icmp eq i64 %54, %29
br i1 %55, label %56, label %38
56: ; preds = %38, %37
%57 = phi double [ %21, %37 ], [ %52, %38 ]
%58 = phi i64 [ 1, %37 ], [ %53, %38 ]
br i1 %30, label %65, label %59
59: ; preds = %56
%60 = getelementptr inbounds double, double* %11, i64 %58
%61 = load double, double* %60
%62 = trunc i64 %58 to i32
%63 = tail call double @pow(double %34, i32 %62)
%64 = tail call double @llvm.fmuladd.f64(double %61, double %63, double %57)
store double %64, double* %36
br label %65
65: ; preds = %59, %56, %31
%66 = add nuw nsw i64 %32, 1
%67 = icmp eq i64 %66, 100
br i1 %67, label %68, label %31
68: ; preds = %65
%69 = getelementptr inbounds [100 x double], [100 x double]* %22, i64 0, i64 0
%70 = call i32 @polynomial_regression(double* %11, double* %69, double* %24, i32 100, i32 %8)
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%72 = icmp sgt i32 %0, 1
br i1 %72, label %73, label %80
73: ; preds = %68, %73
%74 = phi i64 [ %78, %73 ], [ 0, %68 ]
%75 = getelementptr inbounds double, double* %11, i64 %74
%76 = load double, double* %75
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %76)
%78 = add nuw nsw i64 %74, 1
%79 = icmp eq i64 %78, %9
br i1 %79, label %80, label %73
80: ; preds = %73, %68
%81 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %82
82: ; preds = %80, %4
ret void
}