void rInnerproduct(double *result, double a[40 + 1][40 + 1],
                   double b[40 + 1][40 + 1], int row, int column) {
  int i;
  *result = 0.0f;
  for (i = 1; i <= 40; i++)
    *result = *result + a[row][i] * b[i][column];
}


x86 assembly (clang, -O0):
<rInnerproduct>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x24(%rbp)
cmpl   $0x28,-0x24(%rbp)
jg     118f <rInnerproduct+0x8f>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x148,%rcx,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x148,%rcx,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1129 <rInnerproduct+0x29>
pop    %rbp
ret

x86 assembly (clang, -O2):
<rInnerproduct>:
movq   $0x0,(%rdi)
movslq %ecx,%rax
movslq %r8d,%rcx
imul   $0x148,%rax,%rax
add    %rsi,%rax
lea    (%rdx,%rcx,8),%rcx
add    $0x148,%rcx
xorpd  %xmm0,%xmm0
mov    $0x2,%edx
nopl   0x0(%rax,%rax,1)
movsd  -0x8(%rax,%rdx,8),%xmm1
mulsd  (%rcx),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi)
movsd  (%rax,%rdx,8),%xmm0
mulsd  0x148(%rcx),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rdi)
add    $0x2,%rdx
add    $0x290,%rcx
cmp    $0x2a,%rdx
jne    1130 <rInnerproduct+0x30>
ret

LLVM IR (-O0):
define void @rInnerproduct(double* %0, [41 x double]* %1, [41 x double]* %2, i32 %3, i32 %4) {
%6 = alloca double*
%7 = alloca [41 x double]*
%8 = alloca [41 x double]*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store double* %0, double** %6
store [41 x double]* %1, [41 x double]** %7
store [41 x double]* %2, [41 x double]** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load double*, double** %6
store double 0.000000e+00, double* %12
store i32 1, i32* %11
br label %13
13: ; preds = %37, %5
%14 = load i32, i32* %11
%15 = icmp sle i32 %14, 40
br i1 %15, label %16, label %40
16: ; preds = %13
%17 = load double*, double** %6
%18 = load double, double* %17
%19 = load [41 x double]*, [41 x double]** %7
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [41 x double], [41 x double]* %19, i64 %21
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [41 x double], [41 x double]* %22, i64 0, i64 %24
%26 = load double, double* %25
%27 = load [41 x double]*, [41 x double]** %8
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [41 x double], [41 x double]* %27, i64 %29
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [41 x double], [41 x double]* %30, i64 0, i64 %32
%34 = load double, double* %33
%35 = call double @llvm.fmuladd.f64(double %26, double %34, double %18)
%36 = load double*, double** %6
store double %35, double* %36
br label %37
37: ; preds = %16
%38 = load i32, i32* %11
%39 = add nsw i32 %38, 1
store i32 %39, i32* %11
br label %13
40: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @rInnerproduct(double* nocapture %0, [41 x double]* nocapture %1, [41 x double]* nocapture %2, i32 %3, i32 %4) {
store double 0.000000e+00, double* %0
%6 = sext i32 %3 to i64
%7 = sext i32 %4 to i64
br label %8
8: ; preds = %8, %5
%9 = phi double [ 0.000000e+00, %5 ], [ %21, %8 ]
%10 = phi i64 [ 1, %5 ], [ %22, %8 ]
%11 = getelementptr inbounds [41 x double], [41 x double]* %1, i64 %6, i64 %10
%12 = load double, double* %11
%13 = getelementptr inbounds [41 x double], [41 x double]* %2, i64 %10, i64 %7
%14 = load double, double* %13
%15 = tail call double @llvm.fmuladd.f64(double %12, double %14, double %9)
store double %15, double* %0
%16 = add nuw nsw i64 %10, 1
%17 = getelementptr inbounds [41 x double], [41 x double]* %1, i64 %6, i64 %16
%18 = load double, double* %17
%19 = getelementptr inbounds [41 x double], [41 x double]* %2, i64 %16, i64 %7
%20 = load double, double* %19
%21 = tail call double @llvm.fmuladd.f64(double %18, double %20, double %15)
store double %21, double* %0
%22 = add nuw nsw i64 %10, 2
%23 = icmp eq i64 %22, 41
br i1 %23, label %24, label %8
24: ; preds = %8
ret void
}