void vec_mat_sum(double *vec, double vec_c, double **mat, double mat_c,
                 double **dest, int m, int n) {
  int i;
  int j;
  for (i = 0; i < m; i++)
    for (j = 0; j < n; j++)
      dest[i][j] = vec[j] * vec_c + mat[i][j] * mat_c;
}


x86 assembly (clang, -O0):
<vec_mat_sum>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    %r8d,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11b1 <vec_mat_sum+0xb1>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    119e <vec_mat_sum+0x9e>
mov    -0x8(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x10(%rbp),%xmm2
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    113b <vec_mat_sum+0x3b>
jmp    11a3 <vec_mat_sum+0xa3>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1128 <vec_mat_sum+0x28>
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec_mat_sum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %ecx,%ecx
jle    137b <vec_mat_sum+0x27b>
mov    %ecx,%r13d
mov    %r8d,%r10d
lea    (%rdi,%r10,8),%rax
mov    %rax,-0x8(%rsp)
mov    %r10d,%eax
and    $0xfffffffc,%eax
mov    %rax,-0x10(%rsp)
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x18(%rsp)
mov    %rax,%rcx
shr    $0x2,%rcx
add    $0x1,%rcx
movapd %xmm1,%xmm2
unpcklpd %xmm1,%xmm2
movapd %xmm0,%xmm3
unpcklpd %xmm0,%xmm3
mov    %rcx,%rax
mov    %rcx,-0x20(%rsp)
and    $0xfffffffffffffffe,%rcx
mov    %rcx,-0x28(%rsp)
mov    %r10,%r12
neg    %r12
xor    %r9d,%r9d
jmp    117d <vec_mat_sum+0x7d>
nopl   0x0(%rax)
add    $0x1,%r9
cmp    %r13,%r9
je     137b <vec_mat_sum+0x27b>
test   %r8d,%r8d
jle    1170 <vec_mat_sum+0x70>
mov    (%rsi,%r9,8),%rax
mov    (%rdx,%r9,8),%rbp
cmp    $0x4,%r8d
jb     12e0 <vec_mat_sum+0x1e0>
lea    0x0(,%r10,8),%rcx
add    %rbp,%rcx
lea    (%rax,%r10,8),%rbx
cmp    -0x8(%rsp),%rbp
setb   %r14b
cmp    %rdi,%rcx
seta   %r15b
cmp    %rbx,%rbp
setb   %bl
cmp    %rcx,%rax
setb   %r11b
test   %r15b,%r14b
jne    12e0 <vec_mat_sum+0x1e0>
mov    $0x0,%ecx
and    %r11b,%bl
jne    12e2 <vec_mat_sum+0x1e2>
cmpq   $0x0,-0x18(%rsp)
je     1368 <vec_mat_sum+0x268>
mov    -0x28(%rsp),%r11
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
movupd (%rdi,%r14,8),%xmm4
movupd 0x10(%rdi,%r14,8),%xmm5
movupd (%rax,%r14,8),%xmm6
movupd 0x10(%rax,%r14,8),%xmm7
mulpd  %xmm2,%xmm6
mulpd  %xmm2,%xmm7
mulpd  %xmm3,%xmm4
addpd  %xmm6,%xmm4
mulpd  %xmm3,%xmm5
addpd  %xmm7,%xmm5
movupd %xmm4,0x0(%rbp,%r14,8)
movupd %xmm5,0x10(%rbp,%r14,8)
movupd 0x20(%rdi,%r14,8),%xmm4
movupd 0x30(%rdi,%r14,8),%xmm5
movupd 0x20(%rax,%r14,8),%xmm6
movupd 0x30(%rax,%r14,8),%xmm7
mulpd  %xmm2,%xmm6
mulpd  %xmm2,%xmm7
mulpd  %xmm3,%xmm4
addpd  %xmm6,%xmm4
mulpd  %xmm3,%xmm5
addpd  %xmm7,%xmm5
movupd %xmm4,0x20(%rbp,%r14,8)
movupd %xmm5,0x30(%rbp,%r14,8)
add    $0x8,%r14
add    $0xfffffffffffffffe,%r11
jne    11f0 <vec_mat_sum+0xf0>
testb  $0x1,-0x20(%rsp)
je     12c7 <vec_mat_sum+0x1c7>
movupd (%rdi,%r14,8),%xmm4
movupd 0x10(%rdi,%r14,8),%xmm5
movupd (%rax,%r14,8),%xmm6
movupd 0x10(%rax,%r14,8),%xmm7
mulpd  %xmm2,%xmm6
mulpd  %xmm2,%xmm7
mulpd  %xmm3,%xmm4
addpd  %xmm6,%xmm4
mulpd  %xmm3,%xmm5
addpd  %xmm7,%xmm5
movupd %xmm4,0x0(%rbp,%r14,8)
movupd %xmm5,0x10(%rbp,%r14,8)
mov    -0x10(%rsp),%rbx
mov    %rbx,%rcx
cmp    %r10,%rbx
je     1170 <vec_mat_sum+0x70>
jmp    12e2 <vec_mat_sum+0x1e2>
nopw   0x0(%rax,%rax,1)
xor    %ecx,%ecx
mov    %rcx,%rbx
test   $0x1,%r10b
je     130e <vec_mat_sum+0x20e>
movsd  (%rax,%rcx,8),%xmm4
mulsd  %xmm1,%xmm4
movsd  (%rdi,%rcx,8),%xmm5
mulsd  %xmm0,%xmm5
addsd  %xmm4,%xmm5
movsd  %xmm5,0x0(%rbp,%rcx,8)
mov    %rcx,%rbx
or     $0x1,%rbx
not    %rcx
cmp    %r12,%rcx
je     1170 <vec_mat_sum+0x70>
nopw   0x0(%rax,%rax,1)
movsd  (%rax,%rbx,8),%xmm4
mulsd  %xmm1,%xmm4
movsd  (%rdi,%rbx,8),%xmm5
mulsd  %xmm0,%xmm5
addsd  %xmm4,%xmm5
movsd  %xmm5,0x0(%rbp,%rbx,8)
movsd  0x8(%rax,%rbx,8),%xmm4
mulsd  %xmm1,%xmm4
movsd  0x8(%rdi,%rbx,8),%xmm5
mulsd  %xmm0,%xmm5
addsd  %xmm4,%xmm5
movsd  %xmm5,0x8(%rbp,%rbx,8)
add    $0x2,%rbx
cmp    %rbx,%r10
jne    1320 <vec_mat_sum+0x220>
jmp    1170 <vec_mat_sum+0x70>
xor    %r14d,%r14d
testb  $0x1,-0x20(%rsp)
jne    1287 <vec_mat_sum+0x187>
jmp    12c7 <vec_mat_sum+0x1c7>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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