double nfx(double x[], int j) {
  switch (j) {
  case 0:
    return (x[0] - 1.0) * (x[0] - 10.0) + (x[1] + 2.0) * (x[1] + 2.0) + 2.0;
  case 1:
    return 2.0 * (x[0] - 1.0);
  case 2:
    return 2.0 * (x[1] + 2.0);
  }
}


x86 assembly (clang, -O0):
<nfx>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
test   %eax,%eax
je     1140 <nfx+0x40>
jmp    111e <nfx+0x1e>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
je     11ac <nfx+0xac>
jmp    112f <nfx+0x2f>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
je     11d6 <nfx+0xd6>
jmp    11f8 <nfx+0xf8>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xeb8(%rip),%xmm1
subsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
movsd  0xeac(%rip),%xmm1
subsd  %xmm1,%xmm2
mov    -0x10(%rbp),%rax
movsd  0xe8c(%rip),%xmm1
addsd  0x8(%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  0xe7b(%rip),%xmm3
addsd  0x8(%rax),%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe62(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f8 <nfx+0xf8>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
movsd  0xe4c(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xe38(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f8 <nfx+0xf8>
mov    -0x10(%rbp),%rax
movsd  0xe1e(%rip),%xmm1
addsd  0x8(%rax),%xmm1
movsd  0xe11(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<nfx>:
cmp    $0x2,%esi
je     1148 <nfx+0x48>
cmp    $0x1,%esi
je     1157 <nfx+0x57>
test   %esi,%esi
jne    1167 <nfx+0x67>
movsd  (%rdi),%xmm1
movsd  0xeee(%rip),%xmm0
addsd  %xmm1,%xmm0
addsd  0xeea(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xece(%rip),%xmm2
movsd  0x8(%rdi),%xmm0
addsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
ret
movsd  0x8(%rdi),%xmm0
addsd  0xeab(%rip),%xmm0
jmp    1163 <nfx+0x63>
movsd  (%rdi),%xmm0
addsd  0xea5(%rip),%xmm0
addsd  %xmm0,%xmm0
ret

LLVM IR (-O0):
define double @nfx(double* %0, i32 %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
switch i32 %6, label %39 [
i32 0, label %7
i32 1, label %27
i32 2, label %33
]
7: ; preds = %2
%8 = load double*, double** %4
%9 = getelementptr inbounds double, double* %8, i64 0
%10 = load double, double* %9
%11 = fsub double %10, 1.000000e+00
%12 = load double*, double** %4
%13 = getelementptr inbounds double, double* %12, i64 0
%14 = load double, double* %13
%15 = fsub double %14, 1.000000e+01
%16 = load double*, double** %4
%17 = getelementptr inbounds double, double* %16, i64 1
%18 = load double, double* %17
%19 = fadd double %18, 2.000000e+00
%20 = load double*, double** %4
%21 = getelementptr inbounds double, double* %20, i64 1
%22 = load double, double* %21
%23 = fadd double %22, 2.000000e+00
%24 = fmul double %19, %23
%25 = call double @llvm.fmuladd.f64(double %11, double %15, double %24)
%26 = fadd double %25, 2.000000e+00
store double %26, double* %3
br label %39
27: ; preds = %2
%28 = load double*, double** %4
%29 = getelementptr inbounds double, double* %28, i64 0
%30 = load double, double* %29
%31 = fsub double %30, 1.000000e+00
%32 = fmul double 2.000000e+00, %31
store double %32, double* %3
br label %39
33: ; preds = %2
%34 = load double*, double** %4
%35 = getelementptr inbounds double, double* %34, i64 1
%36 = load double, double* %35
%37 = fadd double %36, 2.000000e+00
%38 = fmul double 2.000000e+00, %37
store double %38, double* %3
br label %39
39: ; preds = %7, %27, %33, %2
%40 = load double, double* %3
ret double %40
}

LLVM IR (-O2):
define double @nfx(double* nocapture %0, i32 %1) {
switch i32 %1, label %22 [
i32 0, label %3
i32 1, label %13
i32 2, label %17
]
3: ; preds = %2
%4 = load double, double* %0
%5 = fadd double %4, -1.000000e+00
%6 = fadd double %4, -1.000000e+01
%7 = getelementptr inbounds double, double* %0, i64 1
%8 = load double, double* %7
%9 = fadd double %8, 2.000000e+00
%10 = fmul double %9, %9
%11 = tail call double @llvm.fmuladd.f64(double %5, double %6, double %10)
%12 = fadd double %11, 2.000000e+00
br label %22
13: ; preds = %2
%14 = load double, double* %0
%15 = fadd double %14, -1.000000e+00
%16 = fmul double %15, 2.000000e+00
br label %22
17: ; preds = %2
%18 = getelementptr inbounds double, double* %0, i64 1
%19 = load double, double* %18
%20 = fadd double %19, 2.000000e+00
%21 = fmul double %20, 2.000000e+00
br label %22
22: ; preds = %3, %13, %17, %2
%23 = phi double [ undef, %2 ], [ %21, %17 ], [ %16, %13 ], [ %12, %3 ]
ret double %23
}