void layer_mix_forward(const int N, const int *table, const double *params,
                       const double *input, double *output) {
  for (int i = 0; i < N; i++) {
    output[i] = (input[table[0]] * params[0] + input[table[1]] * params[1] +
                 input[table[2]] * params[2]);
    table += 3;
    params += 3;
  }
}


x86 assembly (clang, -O0):
<layer_mix_forward>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b9 <layer_mix_forward+0xb9>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq 0x4(%rcx),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq 0x8(%rcx),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
add    $0xc,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    111e <layer_mix_forward+0x1e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<layer_mix_forward>:
test   %edi,%edi
jle    1158 <layer_mix_forward+0x58>
mov    %edi,%eax
shl    $0x2,%rax
lea    (%rax,%rax,2),%r9
xor    %edi,%edi
movslq (%rsi,%rdi,1),%rax
movsd  (%rcx,%rax,8),%xmm0
movslq 0x4(%rsi,%rdi,1),%rax
movsd  (%rcx,%rax,8),%xmm1
mulsd  0x8(%rdx,%rdi,2),%xmm1
mulsd  (%rdx,%rdi,2),%xmm0
addsd  %xmm1,%xmm0
movslq 0x8(%rsi,%rdi,1),%rax
movsd  (%rcx,%rax,8),%xmm1
mulsd  0x10(%rdx,%rdi,2),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r8)
add    $0x8,%r8
add    $0xc,%rdi
cmp    %rdi,%r9
jne    1110 <layer_mix_forward+0x10>
ret

LLVM IR (-O0):
define void @layer_mix_forward(i32 %0, i32* %1, double* %2, double* %3, double* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
store i32 %0, i32* %6
store i32* %1, i32** %7
store double* %2, double** %8
store double* %3, double** %9
store double* %4, double** %10
store i32 0, i32* %11
br label %12
12: ; preds = %58, %5
%13 = load i32, i32* %11
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %61
16: ; preds = %12
%17 = load double*, double** %9
%18 = load i32*, i32** %7
%19 = getelementptr inbounds i32, i32* %18, i64 0
%20 = load i32, i32* %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %17, i64 %21
%23 = load double, double* %22
%24 = load double*, double** %8
%25 = getelementptr inbounds double, double* %24, i64 0
%26 = load double, double* %25
%27 = load double*, double** %9
%28 = load i32*, i32** %7
%29 = getelementptr inbounds i32, i32* %28, i64 1
%30 = load i32, i32* %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %27, i64 %31
%33 = load double, double* %32
%34 = load double*, double** %8
%35 = getelementptr inbounds double, double* %34, i64 1
%36 = load double, double* %35
%37 = fmul double %33, %36
%38 = call double @llvm.fmuladd.f64(double %23, double %26, double %37)
%39 = load double*, double** %9
%40 = load i32*, i32** %7
%41 = getelementptr inbounds i32, i32* %40, i64 2
%42 = load i32, i32* %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %39, i64 %43
%45 = load double, double* %44
%46 = load double*, double** %8
%47 = getelementptr inbounds double, double* %46, i64 2
%48 = load double, double* %47
%49 = call double @llvm.fmuladd.f64(double %45, double %48, double %38)
%50 = load double*, double** %10
%51 = load i32, i32* %11
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
store double %49, double* %53
%54 = load i32*, i32** %7
%55 = getelementptr inbounds i32, i32* %54, i64 3
store i32* %55, i32** %7
%56 = load double*, double** %8
%57 = getelementptr inbounds double, double* %56, i64 3
store double* %57, double** %8
br label %58
58: ; preds = %16
%59 = load i32, i32* %11
%60 = add nsw i32 %59, 1
store i32 %60, i32* %11
br label %12
61: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @layer_mix_forward(i32 %0, i32* nocapture %1, double* nocapture %2, double* nocapture %3, double* nocapture writeonly %4) {
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = zext i32 %0 to i64
br label %10
9: ; preds = %10, %5
ret void
10: ; preds = %7, %10
%11 = phi i64 [ 0, %7 ], [ %39, %10 ]
%12 = phi i32* [ %1, %7 ], [ %37, %10 ]
%13 = phi double* [ %2, %7 ], [ %38, %10 ]
%14 = load i32, i32* %12
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %3, i64 %15
%17 = load double, double* %16
%18 = load double, double* %13
%19 = getelementptr inbounds i32, i32* %12, i64 1
%20 = load i32, i32* %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %3, i64 %21
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %13, i64 1
%25 = load double, double* %24
%26 = fmul double %23, %25
%27 = tail call double @llvm.fmuladd.f64(double %17, double %18, double %26)
%28 = getelementptr inbounds i32, i32* %12, i64 2
%29 = load i32, i32* %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %3, i64 %30
%32 = load double, double* %31
%33 = getelementptr inbounds double, double* %13, i64 2
%34 = load double, double* %33
%35 = tail call double @llvm.fmuladd.f64(double %32, double %34, double %27)
%36 = getelementptr inbounds double, double* %4, i64 %11
store double %35, double* %36
%37 = getelementptr inbounds i32, i32* %12, i64 3
%38 = getelementptr inbounds double, double* %13, i64 3
%39 = add nuw nsw i64 %11, 1
%40 = icmp eq i64 %39, %8
br i1 %40, label %9, label %10
}