void layer_mix2_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];
    table += 2;
    params += 2;
  }
}


x86 assembly (clang, -O0):
<layer_mix2_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    11b6 <layer_mix2_backward+0xb6>
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    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    111e <layer_mix2_backward+0x1e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<layer_mix2_backward>:
test   %edi,%edi
jle    114f <layer_mix2_backward+0x4f>
mov    %edi,%r9d
shl    $0x3,%r9
xor    %edi,%edi
nopl   (%rax)
movsd  (%rdx,%rdi,2),%xmm0
movslq (%rsi,%rdi,1),%rax
mulsd  (%rcx,%rdi,1),%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,%rdi,1),%xmm0
addsd  (%r8,%rax,8),%xmm0
movsd  %xmm0,(%r8,%rax,8)
add    $0x8,%rdi
cmp    %rdi,%r9
jne    1110 <layer_mix2_backward+0x10>
ret

LLVM IR (-O0):
define void @layer_mix2_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 = %53, %5
%13 = load i32, i32* %11
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %56
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 i32*, i32** %7
%50 = getelementptr inbounds i32, i32* %49, i64 2
store i32* %50, i32** %7
%51 = load double*, double** %8
%52 = getelementptr inbounds double, double* %51, i64 2
store double* %52, double** %8
br label %53
53: ; preds = %16
%54 = load i32, i32* %11
%55 = add nsw i32 %54, 1
store i32 %55, i32* %11
br label %12
56: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @layer_mix2_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 ], [ %33, %10 ]
%12 = phi i32* [ %1, %7 ], [ %31, %10 ]
%13 = phi double* [ %2, %7 ], [ %32, %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 i32, i32* %12, i64 2
%32 = getelementptr inbounds double, double* %13, i64 2
%33 = add nuw nsw i64 %11, 1
%34 = icmp eq i64 %33, %8
br i1 %34, label %9, label %10
}