void calc_inverse_kl(double *a, double *kl, double **vec, int n, int dim) {
  int d;
  int i;
  for (d = 0; d < n; d++)
    a[d] = 0.0;
  for (i = 0; i < dim; i++)
    for (d = 0; d < n; d++)
      a[d] += kl[i] * (*((double *)vec + i * n + d));
}


x86 assembly (clang, -O0):
<calc_inverse_kl>:
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)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1148 <calc_inverse_kl+0x48>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    111e <calc_inverse_kl+0x1e>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11d4 <calc_inverse_kl+0xd4>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c1 <calc_inverse_kl+0xc1>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1162 <calc_inverse_kl+0x62>
jmp    11c6 <calc_inverse_kl+0xc6>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    114f <calc_inverse_kl+0x4f>
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_inverse_kl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8d,%r12d
mov    %ecx,%r15d
mov    %rdx,(%rsp)
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %ecx,%r13d
test   %ecx,%ecx
jle    1147 <calc_inverse_kl+0x37>
lea    0x0(,%r13,8),%rdx
mov    %rbp,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
test   %r12d,%r12d
jle    1331 <calc_inverse_kl+0x221>
movslq %r15d,%rcx
mov    %r12d,%r11d
lea    0x0(,%r13,8),%rax
add    %rbp,%rax
mov    %rax,0x20(%rsp)
mov    %r13d,%eax
and    $0xfffffffc,%eax
mov    %rax,0x18(%rsp)
mov    %r13,%rax
neg    %rax
mov    %rax,0x28(%rsp)
mov    (%rsp),%rax
lea    0x10(%rax),%rsi
mov    %rcx,0x30(%rsp)
lea    0x0(,%rcx,8),%r8
lea    0x0(,%r13,8),%r12
and    $0xffffffffffffffe0,%r12
add    $0x8,%rax
xor    %ecx,%ecx
mov    %r11,0x10(%rsp)
mov    %r8,0x8(%rsp)
jmp    11c3 <calc_inverse_kl+0xb3>
nop
add    $0x1,%rcx
add    %r8,%rsi
add    %r8,%rax
cmp    %r11,%rcx
je     1331 <calc_inverse_kl+0x221>
test   %r15d,%r15d
jle    11b0 <calc_inverse_kl+0xa0>
mov    %rcx,%rdx
imul   0x30(%rsp),%rdx
mov    (%rsp),%rdi
lea    (%rdi,%rdx,8),%r14
cmp    $0x4,%r15d
jae    11f0 <calc_inverse_kl+0xe0>
xor    %r10d,%r10d
jmp    12b0 <calc_inverse_kl+0x1a0>
nopw   0x0(%rax,%rax,1)
add    %r13,%rdx
lea    (%rbx,%rcx,8),%r9
lea    (%rbx,%rcx,8),%r10
add    $0x8,%r10
mov    (%rsp),%rdi
lea    (%rdi,%rdx,8),%rdx
cmp    %rbp,%r10
seta   %r10b
mov    0x20(%rsp),%r8
cmp    %r8,%r9
setb   %dil
cmp    %rbp,%rdx
seta   %dl
cmp    %r8,%r14
setb   %r9b
test   %dil,%r10b
jne    129f <calc_inverse_kl+0x18f>
mov    $0x0,%r10d
and    %r9b,%dl
mov    0x10(%rsp),%r11
mov    0x8(%rsp),%r8
jne    12b0 <calc_inverse_kl+0x1a0>
movsd  (%rbx,%rcx,8),%xmm0
unpcklpd %xmm0,%xmm0
xor    %edx,%edx
nopl   0x0(%rax)
movupd -0x10(%rsi,%rdx,1),%xmm1
movupd (%rsi,%rdx,1),%xmm2
movupd 0x0(%rbp,%rdx,1),%xmm3
movupd 0x10(%rbp,%rdx,1),%xmm4
mulpd  %xmm0,%xmm1
addpd  %xmm3,%xmm1
mulpd  %xmm0,%xmm2
addpd  %xmm4,%xmm2
movupd %xmm1,0x0(%rbp,%rdx,1)
movupd %xmm2,0x10(%rbp,%rdx,1)
add    $0x20,%rdx
cmp    %rdx,%r12
jne    1250 <calc_inverse_kl+0x140>
mov    0x18(%rsp),%rdx
mov    %rdx,%r10
cmp    %r13,%rdx
je     11b0 <calc_inverse_kl+0xa0>
jmp    12b0 <calc_inverse_kl+0x1a0>
xor    %r10d,%r10d
mov    0x10(%rsp),%r11
mov    0x8(%rsp),%r8
nopl   0x0(%rax)
mov    %r10,%r9
test   $0x1,%r13b
je     12d9 <calc_inverse_kl+0x1c9>
movsd  (%rbx,%rcx,8),%xmm0
mulsd  (%r14,%r10,8),%xmm0
addsd  0x0(%rbp,%r10,8),%xmm0
movsd  %xmm0,0x0(%rbp,%r10,8)
mov    %r10,%r9
or     $0x1,%r9
not    %r10
cmp    0x28(%rsp),%r10
je     11b0 <calc_inverse_kl+0xa0>
nopw   0x0(%rax,%rax,1)
movsd  (%rbx,%rcx,8),%xmm0
mulsd  -0x8(%rax,%r9,8),%xmm0
addsd  0x0(%rbp,%r9,8),%xmm0
movsd  %xmm0,0x0(%rbp,%r9,8)
movsd  (%rbx,%rcx,8),%xmm0
mulsd  (%rax,%r9,8),%xmm0
addsd  0x8(%rbp,%r9,8),%xmm0
movsd  %xmm0,0x8(%rbp,%r9,8)
add    $0x2,%r9
cmp    %r9,%r13
jne    12f0 <calc_inverse_kl+0x1e0>
jmp    11b0 <calc_inverse_kl+0xa0>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @calc_inverse_kl(double* nocapture %0, double* nocapture %1, double** nocapture %2, i32 %3, i32 %4) {
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %11
7: ; preds = %5
%8 = bitcast double* %0 to i8*
%9 = zext i32 %3 to i64
%10 = shl nuw nsw i64 %9, 3
br label %11
11: ; preds = %7, %5
%12 = icmp sgt i32 %4, 0
br i1 %12, label %13, label %111
13: ; preds = %11
%14 = sext i32 %3 to i64
%15 = zext i32 %4 to i64
%16 = zext i32 %3 to i64
%17 = getelementptr double, double* %0, i64 %16
%18 = icmp ult i32 %3, 4
%19 = bitcast double* %17 to double**
%20 = and i64 %16, 4294967292
%21 = icmp eq i64 %20, %16
%22 = and i64 %16, 1
%23 = icmp eq i64 %22, 0
%24 = sub nsw i64 0, %16
br label %25
25: ; preds = %13, %108
%26 = phi i64 [ 0, %13 ], [ %109, %108 ]
%27 = getelementptr double, double* %1, i64 %26
%28 = add nuw i64 %26, 1
%29 = getelementptr double, double* %1, i64 %28
%30 = mul i64 %26, %14
%31 = getelementptr double*, double** %2, i64 %30
%32 = add i64 %30, %16
%33 = getelementptr double*, double** %2, i64 %32
br i1 %6, label %34, label %108
34: ; preds = %25
%35 = getelementptr inbounds double, double* %1, i64 %26
%36 = mul nsw i64 %26, %14
%37 = getelementptr inbounds double*, double** %2, i64 %36
br i1 %18, label %74, label %38
38: ; preds = %34
%39 = icmp ugt double* %29, %0
%40 = icmp ult double* %27, %17
%41 = and i1 %39, %40
%42 = bitcast double** %33 to double*
%43 = icmp ugt double* %42, %0
%44 = icmp ult double** %31, %19
%45 = and i1 %43, %44
%46 = or i1 %41, %45
br i1 %46, label %74, label %47
47: ; preds = %38
%48 = load double, double* %35
%49 = insertelement <2 x double> poison, double %48, i64 0
%50 = shufflevector <2 x double> %49, <2 x double> poison, <2 x i32> zeroinitializer
%51 = insertelement <2 x double> poison, double %48, i64 0
%52 = shufflevector <2 x double> %51, <2 x double> poison, <2 x i32> zeroinitializer
br label %53
53: ; preds = %53, %47
%54 = phi i64 [ 0, %47 ], [ %71, %53 ]
%55 = getelementptr inbounds double*, double** %37, i64 %54
%56 = bitcast double** %55 to <2 x double>*
%57 = load <2 x double>, <2 x double>* %56
%58 = getelementptr inbounds double*, double** %55, i64 2
%59 = bitcast double** %58 to <2 x double>*
%60 = load <2 x double>, <2 x double>* %59
%61 = getelementptr inbounds double, double* %0, i64 %54
%62 = bitcast double* %61 to <2 x double>*
%63 = load <2 x double>, <2 x double>* %62
%64 = getelementptr inbounds double, double* %61, i64 2
%65 = bitcast double* %64 to <2 x double>*
%66 = load <2 x double>, <2 x double>* %65
%67 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %50, <2 x double> %57, <2 x double> %63)
%68 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %52, <2 x double> %60, <2 x double> %66)
%69 = bitcast double* %61 to <2 x double>*
store <2 x double> %67, <2 x double>* %69
%70 = bitcast double* %64 to <2 x double>*
store <2 x double> %68, <2 x double>* %70
%71 = add nuw i64 %54, 4
%72 = icmp eq i64 %71, %20
br i1 %72, label %73, label %53
73: ; preds = %53
br i1 %21, label %108, label %74
74: ; preds = %38, %34, %73
%75 = phi i64 [ 0, %38 ], [ 0, %34 ], [ %20, %73 ]
%76 = xor i64 %75, -1
br i1 %23, label %86, label %77
77: ; preds = %74
%78 = load double, double* %35
%79 = getelementptr inbounds double*, double** %37, i64 %75
%80 = bitcast double** %79 to double*
%81 = load double, double* %80
%82 = getelementptr inbounds double, double* %0, i64 %75
%83 = load double, double* %82
%84 = tail call double @llvm.fmuladd.f64(double %78, double %81, double %83)
store double %84, double* %82
%85 = or i64 %75, 1
br label %86
86: ; preds = %77, %74
%87 = phi i64 [ %75, %74 ], [ %85, %77 ]
%88 = icmp eq i64 %76, %24
br i1 %88, label %108, label %89
89: ; preds = %86, %89
%90 = phi i64 [ %106, %89 ], [ %87, %86 ]
%91 = load double, double* %35
%92 = getelementptr inbounds double*, double** %37, i64 %90
%93 = bitcast double** %92 to double*
%94 = load double, double* %93
%95 = getelementptr inbounds double, double* %0, i64 %90
%96 = load double, double* %95
%97 = tail call double @llvm.fmuladd.f64(double %91, double %94, double %96)
store double %97, double* %95
%98 = add nuw nsw i64 %90, 1
%99 = load double, double* %35
%100 = getelementptr inbounds double*, double** %37, i64 %98
%101 = bitcast double** %100 to double*
%102 = load double, double* %101
%103 = getelementptr inbounds double, double* %0, i64 %98
%104 = load double, double* %103
%105 = tail call double @llvm.fmuladd.f64(double %99, double %102, double %104)
store double %105, double* %103
%106 = add nuw nsw i64 %90, 2
%107 = icmp eq i64 %106, %16
br i1 %107, label %108, label %89
108: ; preds = %86, %89, %73, %25
%109 = add nuw nsw i64 %26, 1
%110 = icmp eq i64 %109, %15
br i1 %110, label %111, label %25
111: ; preds = %108, %11
ret void
}