int matrix_scale_cols_by_vector_component(double *output, double *input,
                                          int rows_mat, int cols_mat,
                                          double *vector, int cols_vec) {
  int i, j;
  for (j = 0; j < cols_mat; j++) {
    for (i = 0; i < rows_mat; i++) {
      output[i + j * rows_mat] = input[i + j * rows_mat] * vector[j];
    }
  }
}


x86 assembly (clang, -O0):
<matrix_scale_cols_by_vector_component>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    119e <matrix_scale_cols_by_vector_component+0x9e>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    118b <matrix_scale_cols_by_vector_component+0x8b>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    -0x34(%rbp),%edx
imul   -0x1c(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    -0x34(%rbp),%edx
imul   -0x1c(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1134 <matrix_scale_cols_by_vector_component+0x34>
jmp    1190 <matrix_scale_cols_by_vector_component+0x90>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1121 <matrix_scale_cols_by_vector_component+0x21>
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_scale_cols_by_vector_component>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,-0x48(%rsp)
test   %ecx,%ecx
jle    13b7 <matrix_scale_cols_by_vector_component+0x2b7>
mov    %edx,%r9d
mov    %rdi,%rsi
movslq %edx,%rax
mov    %ecx,%edi
mov    %eax,%r13d
mov    %r13d,%ecx
and    $0xfffffffc,%ecx
mov    %rcx,-0x20(%rsp)
add    $0xfffffffffffffffc,%rcx
mov    %rcx,-0x28(%rsp)
mov    %rcx,%rdx
shr    $0x2,%rdx
add    $0x1,%rdx
mov    %rdx,%rcx
mov    %rdx,-0x30(%rsp)
and    $0xfffffffffffffffe,%rdx
mov    %rdx,-0x38(%rsp)
mov    %r13,%rcx
neg    %rcx
mov    %rcx,-0x18(%rsp)
lea    0x30(%rsi),%rbx
mov    %rax,-0x8(%rsp)
lea    0x0(,%rax,8),%rdx
mov    -0x48(%rsp),%rax
lea    0x30(%rax),%rbp
lea    0x8(%rax),%r14
lea    0x8(%rsi),%r11
xor    %r15d,%r15d
mov    %r9d,-0x4c(%rsp)
mov    %rdi,-0x40(%rsp)
jmp    11b9 <matrix_scale_cols_by_vector_component+0xb9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
add    %rdx,%rbx
add    %rdx,%rbp
add    %rdx,%r14
add    %rdx,%r11
cmp    %rdi,%r15
je     13b7 <matrix_scale_cols_by_vector_component+0x2b7>
test   %r9d,%r9d
jle    11a0 <matrix_scale_cols_by_vector_component+0xa0>
mov    %r15,%r10
imul   -0x8(%rsp),%r10
cmp    $0x4,%r9d
jae    11e0 <matrix_scale_cols_by_vector_component+0xe0>
xor    %eax,%eax
jmp    1330 <matrix_scale_cols_by_vector_component+0x230>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r10,%r13,1),%rax
lea    (%rsi,%r10,8),%rcx
mov    %rsi,%rdi
lea    (%rsi,%rax,8),%r12
mov    -0x48(%rsp),%rsi
lea    (%rsi,%r10,8),%r9
lea    (%rsi,%rax,8),%rax
lea    (%r8,%r15,8),%rsi
mov    %rsi,-0x10(%rsp)
lea    (%r8,%r15,8),%rsi
add    $0x8,%rsi
cmp    %rax,%rcx
setb   %al
cmp    %r12,%r9
setb   %r9b
cmp    %rsi,%rcx
setb   %cl
cmp    %r12,-0x10(%rsp)
setb   %r12b
test   %r9b,%al
jne    1314 <matrix_scale_cols_by_vector_component+0x214>
mov    $0x0,%eax
and    %r12b,%cl
mov    -0x4c(%rsp),%r9d
mov    %rdi,%rsi
mov    -0x40(%rsp),%rdi
jne    1330 <matrix_scale_cols_by_vector_component+0x230>
cmpq   $0x0,-0x28(%rsp)
je     13a4 <matrix_scale_cols_by_vector_component+0x2a4>
movsd  (%r8,%r15,8),%xmm0
unpcklpd %xmm0,%xmm0
mov    -0x38(%rsp),%rax
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
movupd -0x30(%rbp,%r12,8),%xmm1
movupd -0x20(%rbp,%r12,8),%xmm2
mulpd  %xmm0,%xmm1
mulpd  %xmm0,%xmm2
movupd %xmm1,-0x30(%rbx,%r12,8)
movupd %xmm2,-0x20(%rbx,%r12,8)
movupd -0x10(%rbp,%r12,8),%xmm1
movupd 0x0(%rbp,%r12,8),%xmm2
mulpd  %xmm0,%xmm1
mulpd  %xmm0,%xmm2
movupd %xmm1,-0x10(%rbx,%r12,8)
movupd %xmm2,(%rbx,%r12,8)
add    $0x8,%r12
add    $0xfffffffffffffffe,%rax
jne    1270 <matrix_scale_cols_by_vector_component+0x170>
testb  $0x1,-0x30(%rsp)
je     12fc <matrix_scale_cols_by_vector_component+0x1fc>
add    %r10,%r12
mov    -0x48(%rsp),%rax
movupd (%rax,%r12,8),%xmm0
movupd 0x10(%rax,%r12,8),%xmm1
movsd  (%r8,%r15,8),%xmm2
unpcklpd %xmm2,%xmm2
mulpd  %xmm2,%xmm0
mulpd  %xmm1,%xmm2
movupd %xmm0,(%rsi,%r12,8)
movupd %xmm2,0x10(%rsi,%r12,8)
mov    -0x20(%rsp),%rcx
mov    %rcx,%rax
cmp    %r13,%rcx
mov    -0x40(%rsp),%rdi
je     11a0 <matrix_scale_cols_by_vector_component+0xa0>
jmp    1330 <matrix_scale_cols_by_vector_component+0x230>
xor    %eax,%eax
mov    -0x4c(%rsp),%r9d
mov    %rdi,%rsi
mov    -0x40(%rsp),%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rcx
test   $0x1,%r13b
je     135a <matrix_scale_cols_by_vector_component+0x25a>
add    %rax,%r10
mov    -0x48(%rsp),%rcx
movsd  (%rcx,%r10,8),%xmm0
mulsd  (%r8,%r15,8),%xmm0
movsd  %xmm0,(%rsi,%r10,8)
mov    %rax,%rcx
or     $0x1,%rcx
not    %rax
cmp    -0x18(%rsp),%rax
je     11a0 <matrix_scale_cols_by_vector_component+0xa0>
nopl   0x0(%rax,%rax,1)
movsd  -0x8(%r14,%rcx,8),%xmm0
mulsd  (%r8,%r15,8),%xmm0
movsd  %xmm0,-0x8(%r11,%rcx,8)
movsd  (%r14,%rcx,8),%xmm0
mulsd  (%r8,%r15,8),%xmm0
movsd  %xmm0,(%r11,%rcx,8)
add    $0x2,%rcx
cmp    %rcx,%r13
jne    1370 <matrix_scale_cols_by_vector_component+0x270>
jmp    11a0 <matrix_scale_cols_by_vector_component+0xa0>
xor    %r12d,%r12d
testb  $0x1,-0x30(%rsp)
jne    12c8 <matrix_scale_cols_by_vector_component+0x1c8>
jmp    12fc <matrix_scale_cols_by_vector_component+0x1fc>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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