void grad(int n, const double *x, double *g) {
  g[0] = 2.0 * (x[0] - 1.0) - 4.0e2 * x[0] * (x[1] - ((x[0]) * (x[0])));
  g[1] = 2.0e2 * (x[1] - ((x[0]) * (x[0])));
}


x86 assembly (clang, -O0):
<grad>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xef1(%rip),%xmm1
subsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  0xed9(%rip),%xmm1
mulsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm3
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm4
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm4,%xmm2
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe2a(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<grad>:
movsd  (%rsi),%xmm0
movsd  0x8(%rsi),%xmm1
movsd  0xeef(%rip),%xmm2
addsd  %xmm0,%xmm2
movapd %xmm0,%xmm3
mulsd  %xmm0,%xmm3
mulsd  0xee3(%rip),%xmm0
subsd  %xmm3,%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%rdx)
movsd  (%rsi),%xmm0
movsd  0x8(%rsi),%xmm1
mulsd  %xmm0,%xmm0
subsd  %xmm0,%xmm1
mulsd  0xebe(%rip),%xmm1
movsd  %xmm1,0x8(%rdx)
ret

LLVM IR (-O0):
define void @grad(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
%7 = load double*, double** %5
%8 = getelementptr inbounds double, double* %7, i64 0
%9 = load double, double* %8
%10 = fsub double %9, 1.000000e+00
%11 = load double*, double** %5
%12 = getelementptr inbounds double, double* %11, i64 0
%13 = load double, double* %12
%14 = fmul double 4.000000e+02, %13
%15 = load double*, double** %5
%16 = getelementptr inbounds double, double* %15, i64 1
%17 = load double, double* %16
%18 = load double*, double** %5
%19 = getelementptr inbounds double, double* %18, i64 0
%20 = load double, double* %19
%21 = load double*, double** %5
%22 = getelementptr inbounds double, double* %21, i64 0
%23 = load double, double* %22
%24 = fneg double %20
%25 = call double @llvm.fmuladd.f64(double %24, double %23, double %17)
%26 = fmul double %14, %25
%27 = fneg double %26
%28 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %10, double %27)
%29 = load double*, double** %6
%30 = getelementptr inbounds double, double* %29, i64 0
store double %28, double* %30
%31 = load double*, double** %5
%32 = getelementptr inbounds double, double* %31, i64 1
%33 = load double, double* %32
%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 0
%39 = load double, double* %38
%40 = fneg double %36
%41 = call double @llvm.fmuladd.f64(double %40, double %39, double %33)
%42 = fmul double 2.000000e+02, %41
%43 = load double*, double** %6
%44 = getelementptr inbounds double, double* %43, i64 1
store double %42, double* %44
ret void
}

LLVM IR (-O2):
define void @grad(i32 %0, double* nocapture %1, double* nocapture writeonly %2) {
%4 = load double, double* %1
%5 = fadd double %4, -1.000000e+00
%6 = getelementptr inbounds double, double* %1, i64 1
%7 = load double, double* %6
%8 = fneg double %4
%9 = tail call double @llvm.fmuladd.f64(double %8, double %4, double %7)
%10 = fmul double %4, -4.000000e+02
%11 = fmul double %10, %9
%12 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double %11)
store double %12, double* %2
%13 = load double, double* %6
%14 = load double, double* %1
%15 = fneg double %14
%16 = tail call double @llvm.fmuladd.f64(double %15, double %14, double %13)
%17 = fmul double %16, 2.000000e+02
%18 = getelementptr inbounds double, double* %2, i64 1
store double %17, double* %18
ret void
}