void constant_multiplication(double **a, int m, int n, double c) {
  int i, j;
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      a[i][j] *= c;
    }
  }
}


x86 assembly (clang, -O0):
<constant_multiplication>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1179 <constant_multiplication+0x79>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1166 <constant_multiplication+0x66>
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112d <constant_multiplication+0x2d>
jmp    116b <constant_multiplication+0x6b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    111a <constant_multiplication+0x1a>
pop    %rbp
ret

x86 assembly (clang, -O2):
<constant_multiplication>:
push   %r15
push   %r14
push   %rbx
test   %esi,%esi
jle    1226 <constant_multiplication+0x126>
mov    %esi,%r14d
mov    %edx,%ecx
mov    %ecx,%r11d
and    $0xfffffffc,%r11d
lea    -0x4(%r11),%r8
mov    %r8,%r9
shr    $0x2,%r9
add    $0x1,%r9
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
mov    %r9,%r10
and    $0xfffffffffffffffe,%r10
xor    %r15d,%r15d
jmp    114d <constant_multiplication+0x4d>
nopl   0x0(%rax)
add    $0x1,%r15
cmp    %r14,%r15
je     1226 <constant_multiplication+0x126>
test   %edx,%edx
jle    1140 <constant_multiplication+0x40>
mov    (%rdi,%r15,8),%rbx
cmp    $0x4,%edx
jae    1170 <constant_multiplication+0x70>
xor    %eax,%eax
jmp    1200 <constant_multiplication+0x100>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %r8,%r8
je     121c <constant_multiplication+0x11c>
mov    %r10,%rsi
xor    %eax,%eax
xchg   %ax,%ax
movupd (%rbx,%rax,8),%xmm2
movupd 0x10(%rbx,%rax,8),%xmm3
movupd 0x20(%rbx,%rax,8),%xmm4
movupd 0x30(%rbx,%rax,8),%xmm5
mulpd  %xmm1,%xmm2
mulpd  %xmm1,%xmm3
movupd %xmm2,(%rbx,%rax,8)
movupd %xmm3,0x10(%rbx,%rax,8)
mulpd  %xmm1,%xmm4
mulpd  %xmm1,%xmm5
movupd %xmm4,0x20(%rbx,%rax,8)
movupd %xmm5,0x30(%rbx,%rax,8)
add    $0x8,%rax
add    $0xfffffffffffffffe,%rsi
jne    1180 <constant_multiplication+0x80>
test   $0x1,%r9b
je     11ec <constant_multiplication+0xec>
movupd (%rbx,%rax,8),%xmm2
movupd 0x10(%rbx,%rax,8),%xmm3
mulpd  %xmm1,%xmm2
mulpd  %xmm1,%xmm3
movupd %xmm2,(%rbx,%rax,8)
movupd %xmm3,0x10(%rbx,%rax,8)
mov    %r11,%rax
cmp    %rcx,%r11
je     1140 <constant_multiplication+0x40>
nopl   0x0(%rax,%rax,1)
movsd  (%rbx,%rax,8),%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,(%rbx,%rax,8)
add    $0x1,%rax
cmp    %rax,%rcx
jne    1200 <constant_multiplication+0x100>
jmp    1140 <constant_multiplication+0x40>
xor    %eax,%eax
test   $0x1,%r9b
jne    11ce <constant_multiplication+0xce>
jmp    11ec <constant_multiplication+0xec>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @constant_multiplication(double** nocapture %0, i32 %1, i32 %2, double %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %84
6: ; preds = %4
%7 = icmp sgt i32 %2, 0
%8 = zext i32 %1 to i64
%9 = zext i32 %2 to i64
%10 = and i64 %9, 4294967292
%11 = add nsw i64 %10, -4
%12 = lshr exact i64 %11, 2
%13 = add nuw nsw i64 %12, 1
%14 = icmp ult i32 %2, 4
%15 = and i64 %9, 4294967292
%16 = insertelement <2 x double> poison, double %3, i64 0
%17 = shufflevector <2 x double> %16, <2 x double> poison, <2 x i32> zeroinitializer
%18 = insertelement <2 x double> poison, double %3, i64 0
%19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
%20 = and i64 %13, 1
%21 = icmp eq i64 %11, 0
%22 = and i64 %13, 9223372036854775806
%23 = icmp eq i64 %20, 0
%24 = icmp eq i64 %15, %9
br label %25
25: ; preds = %6, %81
%26 = phi i64 [ 0, %6 ], [ %82, %81 ]
br i1 %7, label %27, label %81
27: ; preds = %25
%28 = getelementptr inbounds double*, double** %0, i64 %26
%29 = load double*, double** %28
br i1 %14, label %72, label %30
30: ; preds = %27
br i1 %21, label %58, label %31
31: ; preds = %30, %31
%32 = phi i64 [ %55, %31 ], [ 0, %30 ]
%33 = phi i64 [ %56, %31 ], [ 0, %30 ]
%34 = getelementptr inbounds double, double* %29, i64 %32
%35 = bitcast double* %34 to <2 x double>*
%36 = load <2 x double>, <2 x double>* %35
%37 = getelementptr inbounds double, double* %34, i64 2
%38 = bitcast double* %37 to <2 x double>*
%39 = load <2 x double>, <2 x double>* %38
%40 = fmul <2 x double> %36, %17
%41 = fmul <2 x double> %39, %19
%42 = bitcast double* %34 to <2 x double>*
store <2 x double> %40, <2 x double>* %42
%43 = bitcast double* %37 to <2 x double>*
store <2 x double> %41, <2 x double>* %43
%44 = or i64 %32, 4
%45 = getelementptr inbounds double, double* %29, i64 %44
%46 = bitcast double* %45 to <2 x double>*
%47 = load <2 x double>, <2 x double>* %46
%48 = getelementptr inbounds double, double* %45, i64 2
%49 = bitcast double* %48 to <2 x double>*
%50 = load <2 x double>, <2 x double>* %49
%51 = fmul <2 x double> %47, %17
%52 = fmul <2 x double> %50, %19
%53 = bitcast double* %45 to <2 x double>*
store <2 x double> %51, <2 x double>* %53
%54 = bitcast double* %48 to <2 x double>*
store <2 x double> %52, <2 x double>* %54
%55 = add nuw i64 %32, 8
%56 = add i64 %33, 2
%57 = icmp eq i64 %56, %22
br i1 %57, label %58, label %31
58: ; preds = %31, %30
%59 = phi i64 [ 0, %30 ], [ %55, %31 ]
br i1 %23, label %71, label %60
60: ; preds = %58
%61 = getelementptr inbounds double, double* %29, i64 %59
%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 = fmul <2 x double> %63, %17
%68 = fmul <2 x double> %66, %19
%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
br label %71
71: ; preds = %58, %60
br i1 %24, label %81, label %72
72: ; preds = %27, %71
%73 = phi i64 [ 0, %27 ], [ %15, %71 ]
br label %74
74: ; preds = %72, %74
%75 = phi i64 [ %79, %74 ], [ %73, %72 ]
%76 = getelementptr inbounds double, double* %29, i64 %75
%77 = load double, double* %76
%78 = fmul double %77, %3
store double %78, double* %76
%79 = add nuw nsw i64 %75, 1
%80 = icmp eq i64 %79, %9
br i1 %80, label %81, label %74
81: ; preds = %74, %71, %25
%82 = add nuw nsw i64 %26, 1
%83 = icmp eq i64 %82, %8
br i1 %83, label %84, label %25
84: ; preds = %81, %4
ret void
}