void quarticgrad(double *x, int N, double *g, void *params) {
  double t1, t2, t3, t4;
  t1 = (x[0] + 10 * x[1]);
  t2 = (x[2] - x[3]);
  t3 = (x[1] - 2 * x[2]);
  t4 = (x[0] - x[3]);
  g[0] = 2 * t1 + 40 * t4 * t4 * t4;
  g[1] = 20 * t1 + 4 * t3 * t3 * t3;
  g[2] = 10 * t2 - 8 * t3 * t3 * t3;
  g[3] = -10 * t2 - 40 * t4 * t4 * t4;
}


x86 assembly (clang, -O0):
<quarticgrad>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  0xee4(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm1
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
subsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe76(%rip),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
movsd  0xe6a(%rip),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
movsd  0xe4b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x30(%rbp),%xmm0
movsd  0xe25(%rip),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xdef(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x30(%rbp),%xmm0
movsd  0xdc9(%rip),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xd93(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x18(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<quarticgrad>:
movsd  (%rdi),%xmm2
movsd  0x8(%rdi),%xmm1
movsd  0xeef(%rip),%xmm3
mulsd  %xmm1,%xmm3
addsd  %xmm2,%xmm3
movsd  0x10(%rdi),%xmm4
movsd  0x18(%rdi),%xmm5
movapd %xmm4,%xmm0
subsd  %xmm5,%xmm0
addsd  %xmm4,%xmm4
subsd  %xmm4,%xmm1
subsd  %xmm5,%xmm2
unpcklpd %xmm1,%xmm2
movapd 0xecd(%rip),%xmm4
mulpd  %xmm2,%xmm4
mulpd  %xmm2,%xmm4
mulpd  %xmm2,%xmm4
unpcklpd %xmm3,%xmm3
mulpd  0xec5(%rip),%xmm3
addpd  %xmm4,%xmm3
movupd %xmm3,(%rdx)
movsd  0xe9d(%rip),%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
xorpd  0xeb1(%rip),%xmm4
unpcklpd %xmm4,%xmm2
unpcklpd %xmm0,%xmm0
mulpd  0xeb1(%rip),%xmm0
addpd  %xmm2,%xmm0
movupd %xmm0,0x10(%rdx)
ret

LLVM IR (-O0):
define void @quarticgrad(double* %0, i32 %1, double* %2, i8* %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca double*
%8 = alloca i8*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store double* %0, double** %5
store i32 %1, i32* %6
store double* %2, double** %7
store i8* %3, i8** %8
%13 = load double*, double** %5
%14 = getelementptr inbounds double, double* %13, i64 0
%15 = load double, double* %14
%16 = load double*, double** %5
%17 = getelementptr inbounds double, double* %16, i64 1
%18 = load double, double* %17
%19 = call double @llvm.fmuladd.f64(double 1.000000e+01, double %18, double %15)
store double %19, double* %9
%20 = load double*, double** %5
%21 = getelementptr inbounds double, double* %20, i64 2
%22 = load double, double* %21
%23 = load double*, double** %5
%24 = getelementptr inbounds double, double* %23, i64 3
%25 = load double, double* %24
%26 = fsub double %22, %25
store double %26, double* %10
%27 = load double*, double** %5
%28 = getelementptr inbounds double, double* %27, i64 1
%29 = load double, double* %28
%30 = load double*, double** %5
%31 = getelementptr inbounds double, double* %30, i64 2
%32 = load double, double* %31
%33 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %32, double %29)
store double %33, double* %11
%34 = load double*, double** %5
%35 = getelementptr inbounds double, double* %34, i64 0
%36 = load double, double* %35
%37 = load double*, double** %5
%38 = getelementptr inbounds double, double* %37, i64 3
%39 = load double, double* %38
%40 = fsub double %36, %39
store double %40, double* %12
%41 = load double, double* %9
%42 = load double, double* %12
%43 = fmul double 4.000000e+01, %42
%44 = load double, double* %12
%45 = fmul double %43, %44
%46 = load double, double* %12
%47 = fmul double %45, %46
%48 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %41, double %47)
%49 = load double*, double** %7
%50 = getelementptr inbounds double, double* %49, i64 0
store double %48, double* %50
%51 = load double, double* %9
%52 = load double, double* %11
%53 = fmul double 4.000000e+00, %52
%54 = load double, double* %11
%55 = fmul double %53, %54
%56 = load double, double* %11
%57 = fmul double %55, %56
%58 = call double @llvm.fmuladd.f64(double 2.000000e+01, double %51, double %57)
%59 = load double*, double** %7
%60 = getelementptr inbounds double, double* %59, i64 1
store double %58, double* %60
%61 = load double, double* %10
%62 = load double, double* %11
%63 = fmul double 8.000000e+00, %62
%64 = load double, double* %11
%65 = fmul double %63, %64
%66 = load double, double* %11
%67 = fmul double %65, %66
%68 = fneg double %67
%69 = call double @llvm.fmuladd.f64(double 1.000000e+01, double %61, double %68)
%70 = load double*, double** %7
%71 = getelementptr inbounds double, double* %70, i64 2
store double %69, double* %71
%72 = load double, double* %10
%73 = load double, double* %12
%74 = fmul double 4.000000e+01, %73
%75 = load double, double* %12
%76 = fmul double %74, %75
%77 = load double, double* %12
%78 = fmul double %76, %77
%79 = fneg double %78
%80 = call double @llvm.fmuladd.f64(double -1.000000e+01, double %72, double %79)
%81 = load double*, double** %7
%82 = getelementptr inbounds double, double* %81, i64 3
store double %80, double* %82
ret void
}

LLVM IR (-O2):
define void @quarticgrad(double* nocapture %0, i32 %1, double* nocapture writeonly %2, i8* nocapture readnone %3) {
%5 = load double, double* %0
%6 = getelementptr inbounds double, double* %0, i64 1
%7 = load double, double* %6
%8 = tail call double @llvm.fmuladd.f64(double %7, double 1.000000e+01, double %5)
%9 = getelementptr inbounds double, double* %0, i64 2
%10 = load double, double* %9
%11 = getelementptr inbounds double, double* %0, i64 3
%12 = load double, double* %11
%13 = fsub double %10, %12
%14 = tail call double @llvm.fmuladd.f64(double %10, double -2.000000e+00, double %7)
%15 = fsub double %5, %12
%16 = insertelement <2 x double> poison, double %15, i64 0
%17 = insertelement <2 x double> %16, double %14, i64 1
%18 = fmul <2 x double> %17, <double 4.000000e+01, double 4.000000e+00>
%19 = fmul <2 x double> %17, %18
%20 = fmul <2 x double> %17, %19
%21 = insertelement <2 x double> poison, double %8, i64 0
%22 = shufflevector <2 x double> %21, <2 x double> poison, <2 x i32> zeroinitializer
%23 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %22, <2 x double> <double 2.000000e+00, double 2.000000e+01>, <2 x double> %20)
%24 = bitcast double* %2 to <2 x double>*
store <2 x double> %23, <2 x double>* %24
%25 = fmul double %14, -8.000000e+00
%26 = fmul double %14, %25
%27 = fmul double %14, %26
%28 = getelementptr inbounds double, double* %2, i64 2
%29 = extractelement <2 x double> %20, i64 0
%30 = fneg double %29
%31 = insertelement <2 x double> poison, double %13, i64 0
%32 = shufflevector <2 x double> %31, <2 x double> poison, <2 x i32> zeroinitializer
%33 = insertelement <2 x double> poison, double %27, i64 0
%34 = insertelement <2 x double> %33, double %30, i64 1
%35 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %32, <2 x double> <double 1.000000e+01, double -1.000000e+01>, <2 x double> %34)
%36 = bitcast double* %28 to <2 x double>*
store <2 x double> %35, <2 x double>* %36
ret void
}