#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
void add_grad(size_t i, size_t j, double s, double *cor, double *delta,
              double *gradient) {
  gradient[i * 3] += s * delta[0];
  gradient[j * 3] -= s * delta[0];
  gradient[i * 3 + 1] += s * delta[1];
  gradient[j * 3 + 1] -= s * delta[1];
  gradient[i * 3 + 2] += s * delta[2];
  gradient[j * 3 + 2] -= s * delta[2];
}


x86 assembly (clang, -O0):
<add_grad>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x30(%rbp),%rax
imul   $0x3,-0x8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x30(%rbp),%rax
imul   $0x3,-0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movq   %xmm0,%rdx
movabs $0x8000000000000000,%rsi
xor    %rsi,%rdx
movq   %rdx,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  0x8(%rax),%xmm2
mov    -0x30(%rbp),%rax
imul   $0x3,-0x8(%rbp),%rcx
movsd  0x8(%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rax,%rcx,8)
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  0x8(%rax),%xmm2
mov    -0x30(%rbp),%rax
imul   $0x3,-0x10(%rbp),%rcx
movsd  0x8(%rax,%rcx,8),%xmm1
movq   %xmm0,%rdx
movabs $0x8000000000000000,%rsi
xor    %rsi,%rdx
movq   %rdx,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rax,%rcx,8)
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  0x10(%rax),%xmm2
mov    -0x30(%rbp),%rax
imul   $0x3,-0x8(%rbp),%rcx
movsd  0x10(%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rax,%rcx,8)
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  0x10(%rax),%xmm2
mov    -0x30(%rbp),%rax
imul   $0x3,-0x10(%rbp),%rcx
movsd  0x10(%rax,%rcx,8),%xmm1
movq   %xmm0,%rdx
movabs $0x8000000000000000,%rsi
xor    %rsi,%rdx
movq   %rdx,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rax,%rcx,8)
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_grad>:
lea    (%rdi,%rdi,2),%rax
movsd  (%rcx),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%r8,%rax,8),%xmm1
movsd  %xmm1,(%r8,%rax,8)
lea    (%rsi,%rsi,2),%rdx
movsd  (%r8,%rdx,8),%xmm1
movsd  (%rcx),%xmm2
mulsd  %xmm0,%xmm2
subsd  %xmm2,%xmm1
movsd  %xmm1,(%r8,%rdx,8)
movsd  0x8(%rcx),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x8(%r8,%rax,8),%xmm1
movsd  %xmm1,0x8(%r8,%rax,8)
movsd  0x8(%r8,%rdx,8),%xmm1
movsd  0x8(%rcx),%xmm2
mulsd  %xmm0,%xmm2
subsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%r8,%rdx,8)
movsd  0x10(%rcx),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x10(%r8,%rax,8),%xmm1
movsd  %xmm1,0x10(%r8,%rax,8)
movsd  0x10(%r8,%rdx,8),%xmm1
mulsd  0x10(%rcx),%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%r8,%rdx,8)
ret

LLVM IR (-O0):
define void @add_grad(i64 %0, i64 %1, double %2, double* %3, double* %4, double* %5) {
%7 = alloca i64
%8 = alloca i64
%9 = alloca double
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
store i64 %0, i64* %7
store i64 %1, i64* %8
store double %2, double* %9
store double* %3, double** %10
store double* %4, double** %11
store double* %5, double** %12
%13 = load double, double* %9
%14 = load double*, double** %11
%15 = getelementptr inbounds double, double* %14, i64 0
%16 = load double, double* %15
%17 = load double*, double** %12
%18 = load i64, i64* %7
%19 = mul i64 %18, 3
%20 = getelementptr inbounds double, double* %17, i64 %19
%21 = load double, double* %20
%22 = call double @llvm.fmuladd.f64(double %13, double %16, double %21)
store double %22, double* %20
%23 = load double, double* %9
%24 = load double*, double** %11
%25 = getelementptr inbounds double, double* %24, i64 0
%26 = load double, double* %25
%27 = load double*, double** %12
%28 = load i64, i64* %8
%29 = mul i64 %28, 3
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = fneg double %23
%33 = call double @llvm.fmuladd.f64(double %32, double %26, double %31)
store double %33, double* %30
%34 = load double, double* %9
%35 = load double*, double** %11
%36 = getelementptr inbounds double, double* %35, i64 1
%37 = load double, double* %36
%38 = load double*, double** %12
%39 = load i64, i64* %7
%40 = mul i64 %39, 3
%41 = add i64 %40, 1
%42 = getelementptr inbounds double, double* %38, i64 %41
%43 = load double, double* %42
%44 = call double @llvm.fmuladd.f64(double %34, double %37, double %43)
store double %44, double* %42
%45 = load double, double* %9
%46 = load double*, double** %11
%47 = getelementptr inbounds double, double* %46, i64 1
%48 = load double, double* %47
%49 = load double*, double** %12
%50 = load i64, i64* %8
%51 = mul i64 %50, 3
%52 = add i64 %51, 1
%53 = getelementptr inbounds double, double* %49, i64 %52
%54 = load double, double* %53
%55 = fneg double %45
%56 = call double @llvm.fmuladd.f64(double %55, double %48, double %54)
store double %56, double* %53
%57 = load double, double* %9
%58 = load double*, double** %11
%59 = getelementptr inbounds double, double* %58, i64 2
%60 = load double, double* %59
%61 = load double*, double** %12
%62 = load i64, i64* %7
%63 = mul i64 %62, 3
%64 = add i64 %63, 2
%65 = getelementptr inbounds double, double* %61, i64 %64
%66 = load double, double* %65
%67 = call double @llvm.fmuladd.f64(double %57, double %60, double %66)
store double %67, double* %65
%68 = load double, double* %9
%69 = load double*, double** %11
%70 = getelementptr inbounds double, double* %69, i64 2
%71 = load double, double* %70
%72 = load double*, double** %12
%73 = load i64, i64* %8
%74 = mul i64 %73, 3
%75 = add i64 %74, 2
%76 = getelementptr inbounds double, double* %72, i64 %75
%77 = load double, double* %76
%78 = fneg double %68
%79 = call double @llvm.fmuladd.f64(double %78, double %71, double %77)
store double %79, double* %76
ret void
}

LLVM IR (-O2):
define void @add_grad(i64 %0, i64 %1, double %2, double* nocapture readnone %3, double* nocapture %4, double* nocapture %5) {
%7 = load double, double* %4
%8 = mul i64 %0, 3
%9 = getelementptr inbounds double, double* %5, i64 %8
%10 = load double, double* %9
%11 = tail call double @llvm.fmuladd.f64(double %2, double %7, double %10)
store double %11, double* %9
%12 = load double, double* %4
%13 = mul i64 %1, 3
%14 = getelementptr inbounds double, double* %5, i64 %13
%15 = load double, double* %14
%16 = fneg double %2
%17 = tail call double @llvm.fmuladd.f64(double %16, double %12, double %15)
store double %17, double* %14
%18 = getelementptr inbounds double, double* %4, i64 1
%19 = load double, double* %18
%20 = add i64 %8, 1
%21 = getelementptr inbounds double, double* %5, i64 %20
%22 = load double, double* %21
%23 = tail call double @llvm.fmuladd.f64(double %2, double %19, double %22)
store double %23, double* %21
%24 = load double, double* %18
%25 = add i64 %13, 1
%26 = getelementptr inbounds double, double* %5, i64 %25
%27 = load double, double* %26
%28 = tail call double @llvm.fmuladd.f64(double %16, double %24, double %27)
store double %28, double* %26
%29 = getelementptr inbounds double, double* %4, i64 2
%30 = load double, double* %29
%31 = add i64 %8, 2
%32 = getelementptr inbounds double, double* %5, i64 %31
%33 = load double, double* %32
%34 = tail call double @llvm.fmuladd.f64(double %2, double %30, double %33)
store double %34, double* %32
%35 = load double, double* %29
%36 = add i64 %13, 2
%37 = getelementptr inbounds double, double* %5, i64 %36
%38 = load double, double* %37
%39 = tail call double @llvm.fmuladd.f64(double %16, double %35, double %38)
store double %39, double* %37
ret void
}