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


x86 assembly (clang, -O0):
<layer_mix_backward>:
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    11ea <layer_mix_backward+0xea>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq 0x4(%rcx),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq 0x8(%rcx),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
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_backward+0x1e>
pop    %rbp
ret

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

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

LLVM IR (-O2):
define void @layer_mix_backward(i32 %0, i32* nocapture %1, double* nocapture %2, double* nocapture %3, double* nocapture %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 ], [ %42, %10 ]
%12 = phi i32* [ %1, %7 ], [ %40, %10 ]
%13 = phi double* [ %2, %7 ], [ %41, %10 ]
%14 = load double, double* %13
%15 = getelementptr inbounds double, double* %3, i64 %11
%16 = load double, double* %15
%17 = load i32, i32* %12
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %4, i64 %18
%20 = load double, double* %19
%21 = tail call double @llvm.fmuladd.f64(double %14, double %16, double %20)
store double %21, double* %19
%22 = getelementptr inbounds double, double* %13, i64 1
%23 = load double, double* %22
%24 = load double, double* %15
%25 = getelementptr inbounds i32, i32* %12, i64 1
%26 = load i32, i32* %25
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %4, i64 %27
%29 = load double, double* %28
%30 = tail call double @llvm.fmuladd.f64(double %23, double %24, double %29)
store double %30, double* %28
%31 = getelementptr inbounds double, double* %13, i64 2
%32 = load double, double* %31
%33 = load double, double* %15
%34 = getelementptr inbounds i32, i32* %12, i64 2
%35 = load i32, i32* %34
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %4, i64 %36
%38 = load double, double* %37
%39 = tail call double @llvm.fmuladd.f64(double %32, double %33, double %38)
store double %39, double* %37
%40 = getelementptr inbounds i32, i32* %12, i64 3
%41 = getelementptr inbounds double, double* %13, i64 3
%42 = add nuw nsw i64 %11, 1
%43 = icmp eq i64 %42, %8
br i1 %43, label %9, label %10
}