void multMatrixColumnsByVector(double **leftmat, double *rightvec, int dim,
                               double **result) {
  int row, col;
  for (row = 0; row < dim; row++) {
    for (col = 0; col < dim; col++) {
      result[row][col] = leftmat[row][col] * rightvec[col];
    }
  }
}


x86 assembly (clang, -O0):
<multMatrixColumnsByVector>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1191 <multMatrixColumnsByVector+0x91>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117e <multMatrixColumnsByVector+0x7e>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    112d <multMatrixColumnsByVector+0x2d>
jmp    1183 <multMatrixColumnsByVector+0x83>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    111a <multMatrixColumnsByVector+0x1a>
pop    %rbp
ret

x86 assembly (clang, -O2):
<multMatrixColumnsByVector>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %edx,%edx
jle    131b <multMatrixColumnsByVector+0x21b>
mov    %edx,%r13d
lea    (%rsi,%r13,8),%r8
mov    %r13d,%r9d
and    $0xfffffffc,%r9d
lea    -0x4(%r9),%rax
mov    %rax,-0x8(%rsp)
mov    %rax,%rbp
shr    $0x2,%rbp
add    $0x1,%rbp
mov    %rbp,%rax
mov    %rbp,-0x10(%rsp)
and    $0xfffffffffffffffe,%rbp
mov    %rbp,-0x18(%rsp)
mov    %r13d,%r10d
and    $0x3,%r10d
xor    %r12d,%r12d
jmp    116d <multMatrixColumnsByVector+0x6d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    %r13,%r12
je     131b <multMatrixColumnsByVector+0x21b>
mov    (%rdi,%r12,8),%rbx
mov    (%rcx,%r12,8),%rax
cmp    $0x4,%edx
jae    1220 <multMatrixColumnsByVector+0x120>
xor    %ebp,%ebp
mov    %rbp,%r14
not    %r14
add    %r13,%r14
test   %r10,%r10
je     11b9 <multMatrixColumnsByVector+0xb9>
mov    %r10,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rbx,%rbp,8),%xmm0
mulsd  (%rsi,%rbp,8),%xmm0
movsd  %xmm0,(%rax,%rbp,8)
add    $0x1,%rbp
add    $0xffffffffffffffff,%r15
jne    11a0 <multMatrixColumnsByVector+0xa0>
cmp    $0x3,%r14
jb     1160 <multMatrixColumnsByVector+0x60>
nop
movsd  (%rbx,%rbp,8),%xmm0
mulsd  (%rsi,%rbp,8),%xmm0
movsd  %xmm0,(%rax,%rbp,8)
movsd  0x8(%rbx,%rbp,8),%xmm0
mulsd  0x8(%rsi,%rbp,8),%xmm0
movsd  %xmm0,0x8(%rax,%rbp,8)
movsd  0x10(%rbx,%rbp,8),%xmm0
mulsd  0x10(%rsi,%rbp,8),%xmm0
movsd  %xmm0,0x10(%rax,%rbp,8)
movsd  0x18(%rbx,%rbp,8),%xmm0
mulsd  0x18(%rsi,%rbp,8),%xmm0
movsd  %xmm0,0x18(%rax,%rbp,8)
add    $0x4,%rbp
cmp    %rbp,%r13
jne    11c0 <multMatrixColumnsByVector+0xc0>
jmp    1160 <multMatrixColumnsByVector+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%rax,%r13,8),%r15
lea    (%rbx,%r13,8),%rbp
cmp    %rbp,%rax
setb   %bpl
cmp    %r15,%rbx
setb   %r11b
cmp    %r8,%rax
setb   %r14b
cmp    %rsi,%r15
seta   %r15b
test   %r11b,%bpl
jne    117e <multMatrixColumnsByVector+0x7e>
mov    $0x0,%ebp
and    %r15b,%r14b
jne    1180 <multMatrixColumnsByVector+0x80>
cmpq   $0x0,-0x8(%rsp)
je     1310 <multMatrixColumnsByVector+0x210>
mov    -0x18(%rsp),%r14
xor    %ebp,%ebp
xchg   %ax,%ax
movupd (%rbx,%rbp,8),%xmm0
movupd 0x10(%rbx,%rbp,8),%xmm1
movupd (%rsi,%rbp,8),%xmm2
mulpd  %xmm0,%xmm2
movupd 0x10(%rsi,%rbp,8),%xmm0
mulpd  %xmm1,%xmm0
movupd %xmm2,(%rax,%rbp,8)
movupd %xmm0,0x10(%rax,%rbp,8)
movupd 0x20(%rbx,%rbp,8),%xmm0
movupd 0x30(%rbx,%rbp,8),%xmm1
movupd 0x20(%rsi,%rbp,8),%xmm2
mulpd  %xmm0,%xmm2
movupd 0x30(%rsi,%rbp,8),%xmm0
mulpd  %xmm1,%xmm0
movupd %xmm2,0x20(%rax,%rbp,8)
movupd %xmm0,0x30(%rax,%rbp,8)
add    $0x8,%rbp
add    $0xfffffffffffffffe,%r14
jne    1270 <multMatrixColumnsByVector+0x170>
testb  $0x1,-0x10(%rsp)
je     12ff <multMatrixColumnsByVector+0x1ff>
movupd (%rbx,%rbp,8),%xmm0
movupd 0x10(%rbx,%rbp,8),%xmm1
movupd (%rsi,%rbp,8),%xmm2
mulpd  %xmm0,%xmm2
movupd 0x10(%rsi,%rbp,8),%xmm0
mulpd  %xmm1,%xmm0
movupd %xmm2,(%rax,%rbp,8)
movupd %xmm0,0x10(%rax,%rbp,8)
mov    %r9,%rbp
cmp    %r13,%r9
je     1160 <multMatrixColumnsByVector+0x60>
jmp    1180 <multMatrixColumnsByVector+0x80>
xor    %ebp,%ebp
testb  $0x1,-0x10(%rsp)
jne    12d6 <multMatrixColumnsByVector+0x1d6>
jmp    12ff <multMatrixColumnsByVector+0x1ff>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @multMatrixColumnsByVector(double** %0, double* %1, i32 %2, double** %3) {
%5 = alloca double**
%6 = alloca double*
%7 = alloca i32
%8 = alloca double**
%9 = alloca i32
%10 = alloca i32
store double** %0, double*** %5
store double* %1, double** %6
store i32 %2, i32* %7
store double** %3, double*** %8
store i32 0, i32* %9
br label %11
11: ; preds = %48, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %7
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %51
15: ; preds = %11
store i32 0, i32* %10
br label %16
16: ; preds = %44, %15
%17 = load i32, i32* %10
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %47
20: ; preds = %16
%21 = load double**, double*** %5
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double*, double** %21, i64 %23
%25 = load double*, double** %24
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = load double*, double** %6
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = fmul double %29, %34
%36 = load double**, double*** %8
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double*, double** %36, i64 %38
%40 = load double*, double** %39
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
store double %35, double* %43
br label %44
44: ; preds = %20
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %16
47: ; preds = %16
br label %48
48: ; preds = %47
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %11
51: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @multMatrixColumnsByVector(double** nocapture %0, double* nocapture %1, i32 %2, double** nocapture %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %157
6: ; preds = %4
%7 = zext i32 %2 to i64
%8 = getelementptr double, double* %1, i64 %7
%9 = and i64 %7, 4294967292
%10 = add nsw i64 %9, -4
%11 = lshr exact i64 %10, 2
%12 = add nuw nsw i64 %11, 1
%13 = icmp ult i32 %2, 4
%14 = and i64 %7, 4294967292
%15 = and i64 %12, 1
%16 = icmp eq i64 %10, 0
%17 = and i64 %12, 9223372036854775806
%18 = icmp eq i64 %15, 0
%19 = icmp eq i64 %14, %7
%20 = and i64 %7, 3
%21 = icmp eq i64 %20, 0
br label %22
22: ; preds = %154, %6
%23 = phi i64 [ 0, %6 ], [ %155, %154 ]
%24 = getelementptr inbounds double*, double** %0, i64 %23
%25 = load double*, double** %24
%26 = getelementptr inbounds double*, double** %3, i64 %23
%27 = load double*, double** %26
br i1 %13, label %104, label %28
28: ; preds = %22
%29 = getelementptr double, double* %27, i64 %7
%30 = getelementptr double, double* %25, i64 %7
%31 = icmp ult double* %27, %30
%32 = icmp ult double* %25, %29
%33 = and i1 %31, %32
%34 = icmp ult double* %27, %8
%35 = icmp ugt double* %29, %1
%36 = and i1 %34, %35
%37 = or i1 %33, %36
br i1 %37, label %104, label %38
38: ; preds = %28
br i1 %16, label %82, label %39
39: ; preds = %38, %39
%40 = phi i64 [ %79, %39 ], [ 0, %38 ]
%41 = phi i64 [ %80, %39 ], [ 0, %38 ]
%42 = getelementptr inbounds double, double* %25, i64 %40
%43 = bitcast double* %42 to <2 x double>*
%44 = load <2 x double>, <2 x double>* %43
%45 = getelementptr inbounds double, double* %42, i64 2
%46 = bitcast double* %45 to <2 x double>*
%47 = load <2 x double>, <2 x double>* %46
%48 = getelementptr inbounds double, double* %1, i64 %40
%49 = bitcast double* %48 to <2 x double>*
%50 = load <2 x double>, <2 x double>* %49
%51 = getelementptr inbounds double, double* %48, i64 2
%52 = bitcast double* %51 to <2 x double>*
%53 = load <2 x double>, <2 x double>* %52
%54 = fmul <2 x double> %44, %50
%55 = fmul <2 x double> %47, %53
%56 = getelementptr inbounds double, double* %27, i64 %40
%57 = bitcast double* %56 to <2 x double>*
store <2 x double> %54, <2 x double>* %57
%58 = getelementptr inbounds double, double* %56, i64 2
%59 = bitcast double* %58 to <2 x double>*
store <2 x double> %55, <2 x double>* %59
%60 = or i64 %40, 4
%61 = getelementptr inbounds double, double* %25, i64 %60
%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 = getelementptr inbounds double, double* %1, i64 %60
%68 = bitcast double* %67 to <2 x double>*
%69 = load <2 x double>, <2 x double>* %68
%70 = getelementptr inbounds double, double* %67, i64 2
%71 = bitcast double* %70 to <2 x double>*
%72 = load <2 x double>, <2 x double>* %71
%73 = fmul <2 x double> %63, %69
%74 = fmul <2 x double> %66, %72
%75 = getelementptr inbounds double, double* %27, i64 %60
%76 = bitcast double* %75 to <2 x double>*
store <2 x double> %73, <2 x double>* %76
%77 = getelementptr inbounds double, double* %75, i64 2
%78 = bitcast double* %77 to <2 x double>*
store <2 x double> %74, <2 x double>* %78
%79 = add nuw i64 %40, 8
%80 = add i64 %41, 2
%81 = icmp eq i64 %80, %17
br i1 %81, label %82, label %39
82: ; preds = %39, %38
%83 = phi i64 [ 0, %38 ], [ %79, %39 ]
br i1 %18, label %103, label %84
84: ; preds = %82
%85 = getelementptr inbounds double, double* %25, i64 %83
%86 = bitcast double* %85 to <2 x double>*
%87 = load <2 x double>, <2 x double>* %86
%88 = getelementptr inbounds double, double* %85, i64 2
%89 = bitcast double* %88 to <2 x double>*
%90 = load <2 x double>, <2 x double>* %89
%91 = getelementptr inbounds double, double* %1, i64 %83
%92 = bitcast double* %91 to <2 x double>*
%93 = load <2 x double>, <2 x double>* %92
%94 = getelementptr inbounds double, double* %91, i64 2
%95 = bitcast double* %94 to <2 x double>*
%96 = load <2 x double>, <2 x double>* %95
%97 = fmul <2 x double> %87, %93
%98 = fmul <2 x double> %90, %96
%99 = getelementptr inbounds double, double* %27, i64 %83
%100 = bitcast double* %99 to <2 x double>*
store <2 x double> %97, <2 x double>* %100
%101 = getelementptr inbounds double, double* %99, i64 2
%102 = bitcast double* %101 to <2 x double>*
store <2 x double> %98, <2 x double>* %102
br label %103
103: ; preds = %82, %84
br i1 %19, label %154, label %104
104: ; preds = %28, %22, %103
%105 = phi i64 [ 0, %28 ], [ 0, %22 ], [ %14, %103 ]
%106 = xor i64 %105, -1
%107 = add nsw i64 %106, %7
br i1 %21, label %120, label %108
108: ; preds = %104, %108
%109 = phi i64 [ %117, %108 ], [ %105, %104 ]
%110 = phi i64 [ %118, %108 ], [ 0, %104 ]
%111 = getelementptr inbounds double, double* %25, i64 %109
%112 = load double, double* %111
%113 = getelementptr inbounds double, double* %1, i64 %109
%114 = load double, double* %113
%115 = fmul double %112, %114
%116 = getelementptr inbounds double, double* %27, i64 %109
store double %115, double* %116
%117 = add nuw nsw i64 %109, 1
%118 = add i64 %110, 1
%119 = icmp eq i64 %118, %20
br i1 %119, label %120, label %108
120: ; preds = %108, %104
%121 = phi i64 [ %105, %104 ], [ %117, %108 ]
%122 = icmp ult i64 %107, 3
br i1 %122, label %154, label %123
123: ; preds = %120, %123
%124 = phi i64 [ %152, %123 ], [ %121, %120 ]
%125 = getelementptr inbounds double, double* %25, i64 %124
%126 = load double, double* %125
%127 = getelementptr inbounds double, double* %1, i64 %124
%128 = load double, double* %127
%129 = fmul double %126, %128
%130 = getelementptr inbounds double, double* %27, i64 %124
store double %129, double* %130
%131 = add nuw nsw i64 %124, 1
%132 = getelementptr inbounds double, double* %25, i64 %131
%133 = load double, double* %132
%134 = getelementptr inbounds double, double* %1, i64 %131
%135 = load double, double* %134
%136 = fmul double %133, %135
%137 = getelementptr inbounds double, double* %27, i64 %131
store double %136, double* %137
%138 = add nuw nsw i64 %124, 2
%139 = getelementptr inbounds double, double* %25, i64 %138
%140 = load double, double* %139
%141 = getelementptr inbounds double, double* %1, i64 %138
%142 = load double, double* %141
%143 = fmul double %140, %142
%144 = getelementptr inbounds double, double* %27, i64 %138
store double %143, double* %144
%145 = add nuw nsw i64 %124, 3
%146 = getelementptr inbounds double, double* %25, i64 %145
%147 = load double, double* %146
%148 = getelementptr inbounds double, double* %1, i64 %145
%149 = load double, double* %148
%150 = fmul double %147, %149
%151 = getelementptr inbounds double, double* %27, i64 %145
store double %150, double* %151
%152 = add nuw nsw i64 %124, 4
%153 = icmp eq i64 %152, %7
br i1 %153, label %154, label %123
154: ; preds = %120, %123, %103
%155 = add nuw nsw i64 %23, 1
%156 = icmp eq i64 %155, %7
br i1 %156, label %157, label %22
157: ; preds = %154, %4
ret void
}