double f(x, fd)
double *x, *fd;
{
  double f1, f2, f3, df1, df2, df3;
  f1 = x[0] * x[0] + x[1] * x[1] + x[2] * x[2] - 40;
  f2 = x[0] * x[0] + 7 * x[0] * x[1] + 3 * x[2] + 14;
  f3 = 5 * x[0] * x[2] + x[1] * x[2] - 24;
  df1 = 2.0 * x[0];
  df2 = 2.0 * x[0];
  df3 = 5.0 * x[2];
  fd[0] = 2.0 * (df1 * f1 + df2 * f2 + df3 * f3);
  df1 = 2 * x[1];
  df2 = 7.0 * x[0];
  df3 = x[2];
  fd[1] = 2.0 * (df1 * f1 + df2 * f2 + df3 * f3);
  df1 = 2.0 * x[2];
  df2 = 3.0;
  df3 = 5.0 * x[0] + x[1];
  fd[2] = 2.0 * (df1 * f1 + df2 * f2 + df3 * f3);
  return (f1 * f1 + f2 * f2 + f3 * f3);
}


x86 assembly (clang, -O0):
<f>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xed8(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0xe9b(%rip),%xmm0
mulsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  0xe6d(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe75(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0xe40(%rip),%xmm0
mulsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
mulsd  0x10(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe29(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  0xdf4(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  0xddf(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0xdd2(%rip),%xmm0
mulsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xd8a(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0xd72(%rip),%xmm0
mulsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  0xd74(%rip),%xmm0
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xd0f(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0xcf6(%rip),%xmm0
mulsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xcf4(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  0xcce(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xc83(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x18(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<f>:
movsd  (%rdi),%xmm5
movsd  0x8(%rdi),%xmm4
movapd %xmm4,%xmm0
mulsd  %xmm4,%xmm0
movapd %xmm5,%xmm2
mulsd  %xmm5,%xmm2
addsd  %xmm2,%xmm0
movsd  0x10(%rdi),%xmm7
movapd %xmm7,%xmm1
mulsd  %xmm7,%xmm1
addsd  %xmm0,%xmm1
addsd  0xeca(%rip),%xmm1
movsd  0xeca(%rip),%xmm6
movapd %xmm5,%xmm0
mulsd  %xmm6,%xmm0
mulsd  %xmm4,%xmm0
addsd  %xmm2,%xmm0
movsd  0xeb9(%rip),%xmm8
movapd %xmm7,%xmm2
mulsd  %xmm8,%xmm2
addsd  %xmm0,%xmm2
addsd  0xeac(%rip),%xmm2
movsd  0xeac(%rip),%xmm3
movapd %xmm5,%xmm0
mulsd  %xmm3,%xmm0
mulsd  %xmm7,%xmm4
mulsd  %xmm7,%xmm0
addsd  %xmm4,%xmm0
addsd  0xe98(%rip),%xmm0
addsd  %xmm5,%xmm5
mulsd  %xmm3,%xmm7
movapd %xmm5,%xmm4
mulsd  %xmm2,%xmm4
mulsd  %xmm1,%xmm5
addsd  %xmm4,%xmm5
mulsd  %xmm0,%xmm7
addsd  %xmm5,%xmm7
addsd  %xmm7,%xmm7
movsd  %xmm7,(%rsi)
movsd  0x8(%rdi),%xmm4
addsd  %xmm4,%xmm4
mulsd  (%rdi),%xmm6
mulsd  %xmm2,%xmm6
mulsd  %xmm1,%xmm4
addsd  %xmm6,%xmm4
movsd  0x10(%rdi),%xmm5
mulsd  %xmm0,%xmm5
addsd  %xmm4,%xmm5
addsd  %xmm5,%xmm5
movsd  %xmm5,0x8(%rsi)
movsd  0x10(%rdi),%xmm4
addsd  %xmm4,%xmm4
mulsd  (%rdi),%xmm3
addsd  0x8(%rdi),%xmm3
mulsd  %xmm2,%xmm8
mulsd  %xmm1,%xmm4
addsd  %xmm8,%xmm4
mulsd  %xmm0,%xmm3
addsd  %xmm4,%xmm3
addsd  %xmm3,%xmm3
movsd  %xmm3,0x10(%rsi)
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @f(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double* %0, double** %3
store double* %1, double** %4
%11 = load double*, double** %3
%12 = getelementptr inbounds double, double* %11, i64 0
%13 = load double, double* %12
%14 = load double*, double** %3
%15 = getelementptr inbounds double, double* %14, i64 0
%16 = load double, double* %15
%17 = load double*, double** %3
%18 = getelementptr inbounds double, double* %17, i64 1
%19 = load double, double* %18
%20 = load double*, double** %3
%21 = getelementptr inbounds double, double* %20, i64 1
%22 = load double, double* %21
%23 = fmul double %19, %22
%24 = call double @llvm.fmuladd.f64(double %13, double %16, double %23)
%25 = load double*, double** %3
%26 = getelementptr inbounds double, double* %25, i64 2
%27 = load double, double* %26
%28 = load double*, double** %3
%29 = getelementptr inbounds double, double* %28, i64 2
%30 = load double, double* %29
%31 = call double @llvm.fmuladd.f64(double %27, double %30, double %24)
%32 = fsub double %31, 4.000000e+01
store double %32, double* %5
%33 = load double*, double** %3
%34 = getelementptr inbounds double, double* %33, i64 0
%35 = load double, double* %34
%36 = load double*, double** %3
%37 = getelementptr inbounds double, double* %36, i64 0
%38 = load double, double* %37
%39 = load double*, double** %3
%40 = getelementptr inbounds double, double* %39, i64 0
%41 = load double, double* %40
%42 = fmul double 7.000000e+00, %41
%43 = load double*, double** %3
%44 = getelementptr inbounds double, double* %43, i64 1
%45 = load double, double* %44
%46 = fmul double %42, %45
%47 = call double @llvm.fmuladd.f64(double %35, double %38, double %46)
%48 = load double*, double** %3
%49 = getelementptr inbounds double, double* %48, i64 2
%50 = load double, double* %49
%51 = call double @llvm.fmuladd.f64(double 3.000000e+00, double %50, double %47)
%52 = fadd double %51, 1.400000e+01
store double %52, double* %6
%53 = load double*, double** %3
%54 = getelementptr inbounds double, double* %53, i64 0
%55 = load double, double* %54
%56 = fmul double 5.000000e+00, %55
%57 = load double*, double** %3
%58 = getelementptr inbounds double, double* %57, i64 2
%59 = load double, double* %58
%60 = load double*, double** %3
%61 = getelementptr inbounds double, double* %60, i64 1
%62 = load double, double* %61
%63 = load double*, double** %3
%64 = getelementptr inbounds double, double* %63, i64 2
%65 = load double, double* %64
%66 = fmul double %62, %65
%67 = call double @llvm.fmuladd.f64(double %56, double %59, double %66)
%68 = fsub double %67, 2.400000e+01
store double %68, double* %7
%69 = load double*, double** %3
%70 = getelementptr inbounds double, double* %69, i64 0
%71 = load double, double* %70
%72 = fmul double 2.000000e+00, %71
store double %72, double* %8
%73 = load double*, double** %3
%74 = getelementptr inbounds double, double* %73, i64 0
%75 = load double, double* %74
%76 = fmul double 2.000000e+00, %75
store double %76, double* %9
%77 = load double*, double** %3
%78 = getelementptr inbounds double, double* %77, i64 2
%79 = load double, double* %78
%80 = fmul double 5.000000e+00, %79
store double %80, double* %10
%81 = load double, double* %8
%82 = load double, double* %5
%83 = load double, double* %9
%84 = load double, double* %6
%85 = fmul double %83, %84
%86 = call double @llvm.fmuladd.f64(double %81, double %82, double %85)
%87 = load double, double* %10
%88 = load double, double* %7
%89 = call double @llvm.fmuladd.f64(double %87, double %88, double %86)
%90 = fmul double 2.000000e+00, %89
%91 = load double*, double** %4
%92 = getelementptr inbounds double, double* %91, i64 0
store double %90, double* %92
%93 = load double*, double** %3
%94 = getelementptr inbounds double, double* %93, i64 1
%95 = load double, double* %94
%96 = fmul double 2.000000e+00, %95
store double %96, double* %8
%97 = load double*, double** %3
%98 = getelementptr inbounds double, double* %97, i64 0
%99 = load double, double* %98
%100 = fmul double 7.000000e+00, %99
store double %100, double* %9
%101 = load double*, double** %3
%102 = getelementptr inbounds double, double* %101, i64 2
%103 = load double, double* %102
store double %103, double* %10
%104 = load double, double* %8
%105 = load double, double* %5
%106 = load double, double* %9
%107 = load double, double* %6
%108 = fmul double %106, %107
%109 = call double @llvm.fmuladd.f64(double %104, double %105, double %108)
%110 = load double, double* %10
%111 = load double, double* %7
%112 = call double @llvm.fmuladd.f64(double %110, double %111, double %109)
%113 = fmul double 2.000000e+00, %112
%114 = load double*, double** %4
%115 = getelementptr inbounds double, double* %114, i64 1
store double %113, double* %115
%116 = load double*, double** %3
%117 = getelementptr inbounds double, double* %116, i64 2
%118 = load double, double* %117
%119 = fmul double 2.000000e+00, %118
store double %119, double* %8
store double 3.000000e+00, double* %9
%120 = load double*, double** %3
%121 = getelementptr inbounds double, double* %120, i64 0
%122 = load double, double* %121
%123 = load double*, double** %3
%124 = getelementptr inbounds double, double* %123, i64 1
%125 = load double, double* %124
%126 = call double @llvm.fmuladd.f64(double 5.000000e+00, double %122, double %125)
store double %126, double* %10
%127 = load double, double* %8
%128 = load double, double* %5
%129 = load double, double* %9
%130 = load double, double* %6
%131 = fmul double %129, %130
%132 = call double @llvm.fmuladd.f64(double %127, double %128, double %131)
%133 = load double, double* %10
%134 = load double, double* %7
%135 = call double @llvm.fmuladd.f64(double %133, double %134, double %132)
%136 = fmul double 2.000000e+00, %135
%137 = load double*, double** %4
%138 = getelementptr inbounds double, double* %137, i64 2
store double %136, double* %138
%139 = load double, double* %5
%140 = load double, double* %5
%141 = load double, double* %6
%142 = load double, double* %6
%143 = fmul double %141, %142
%144 = call double @llvm.fmuladd.f64(double %139, double %140, double %143)
%145 = load double, double* %7
%146 = load double, double* %7
%147 = call double @llvm.fmuladd.f64(double %145, double %146, double %144)
ret double %147
}

LLVM IR (-O2):
define double @f(double* nocapture %0, double* nocapture writeonly %1) {
%3 = load double, double* %0
%4 = getelementptr inbounds double, double* %0, i64 1
%5 = load double, double* %4
%6 = fmul double %5, %5
%7 = tail call double @llvm.fmuladd.f64(double %3, double %3, double %6)
%8 = getelementptr inbounds double, double* %0, i64 2
%9 = load double, double* %8
%10 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %7)
%11 = fadd double %10, -4.000000e+01
%12 = fmul double %3, 7.000000e+00
%13 = fmul double %12, %5
%14 = tail call double @llvm.fmuladd.f64(double %3, double %3, double %13)
%15 = tail call double @llvm.fmuladd.f64(double %9, double 3.000000e+00, double %14)
%16 = fadd double %15, 1.400000e+01
%17 = fmul double %3, 5.000000e+00
%18 = fmul double %5, %9
%19 = tail call double @llvm.fmuladd.f64(double %17, double %9, double %18)
%20 = fadd double %19, -2.400000e+01
%21 = fmul double %3, 2.000000e+00
%22 = fmul double %9, 5.000000e+00
%23 = fmul double %21, %16
%24 = tail call double @llvm.fmuladd.f64(double %21, double %11, double %23)
%25 = tail call double @llvm.fmuladd.f64(double %22, double %20, double %24)
%26 = fmul double %25, 2.000000e+00
store double %26, double* %1
%27 = load double, double* %4
%28 = fmul double %27, 2.000000e+00
%29 = load double, double* %0
%30 = fmul double %29, 7.000000e+00
%31 = load double, double* %8
%32 = fmul double %16, %30
%33 = tail call double @llvm.fmuladd.f64(double %28, double %11, double %32)
%34 = tail call double @llvm.fmuladd.f64(double %31, double %20, double %33)
%35 = fmul double %34, 2.000000e+00
%36 = getelementptr inbounds double, double* %1, i64 1
store double %35, double* %36
%37 = load double, double* %8
%38 = fmul double %37, 2.000000e+00
%39 = load double, double* %0
%40 = load double, double* %4
%41 = tail call double @llvm.fmuladd.f64(double %39, double 5.000000e+00, double %40)
%42 = fmul double %16, 3.000000e+00
%43 = tail call double @llvm.fmuladd.f64(double %38, double %11, double %42)
%44 = tail call double @llvm.fmuladd.f64(double %41, double %20, double %43)
%45 = fmul double %44, 2.000000e+00
%46 = getelementptr inbounds double, double* %1, i64 2
store double %45, double* %46
%47 = fmul double %16, %16
%48 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %47)
%49 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %48)
ret double %49
}