void add_mat(double **org_mat, double **update_mat, int m, int n,
             double coeff) {
  int i;
  int j;
  for (i = 0; i < m; i++)
    for (j = 0; j < n; j++)
      org_mat[i][j] += coeff * update_mat[i][j];
}


x86 assembly (clang, -O0):
<add_mat>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119a <add_mat+0x9a>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1187 <add_mat+0x87>
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1131 <add_mat+0x31>
jmp    118c <add_mat+0x8c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    111e <add_mat+0x1e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_mat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %edx,%edx
jle    12c1 <add_mat+0x1c1>
mov    %edx,%r15d
mov    %ecx,%r13d
mov    %r13d,%r8d
and    $0xfffffffc,%r8d
lea    -0x4(%r8),%r9
mov    %r9,%r10
shr    $0x2,%r10
add    $0x1,%r10
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
mov    %r10,%r11
and    $0xfffffffffffffffe,%r11
mov    %r13,%r14
neg    %r14
xor    %r12d,%r12d
jmp    115d <add_mat+0x5d>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    %r15,%r12
je     12c1 <add_mat+0x1c1>
test   %ecx,%ecx
jle    1150 <add_mat+0x50>
mov    (%rsi,%r12,8),%rax
mov    (%rdi,%r12,8),%rbx
cmp    $0x4,%ecx
jb     1180 <add_mat+0x80>
lea    (%rax,%r13,8),%rdx
cmp    %rdx,%rbx
jae    11e7 <add_mat+0xe7>
lea    (%rbx,%r13,8),%rdx
cmp    %rdx,%rax
jae    11e7 <add_mat+0xe7>
xor    %ebp,%ebp
mov    %rbp,%rdx
test   $0x1,%r13b
je     11a5 <add_mat+0xa5>
movsd  (%rax,%rbp,8),%xmm2
mulsd  %xmm0,%xmm2
addsd  (%rbx,%rbp,8),%xmm2
movsd  %xmm2,(%rbx,%rbp,8)
mov    %rbp,%rdx
or     $0x1,%rdx
not    %rbp
cmp    %r14,%rbp
je     1150 <add_mat+0x50>
nopl   (%rax)
movsd  (%rax,%rdx,8),%xmm2
mulsd  %xmm0,%xmm2
addsd  (%rbx,%rdx,8),%xmm2
movsd  %xmm2,(%rbx,%rdx,8)
movsd  0x8(%rax,%rdx,8),%xmm2
mulsd  %xmm0,%xmm2
addsd  0x8(%rbx,%rdx,8),%xmm2
movsd  %xmm2,0x8(%rbx,%rdx,8)
add    $0x2,%rdx
cmp    %rdx,%r13
jne    11b0 <add_mat+0xb0>
jmp    1150 <add_mat+0x50>
test   %r9,%r9
je     12b7 <add_mat+0x1b7>
mov    %r11,%rbp
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nop
movupd (%rax,%rdx,8),%xmm2
movupd 0x10(%rax,%rdx,8),%xmm3
mulpd  %xmm1,%xmm2
movupd (%rbx,%rdx,8),%xmm4
addpd  %xmm2,%xmm4
movupd 0x10(%rbx,%rdx,8),%xmm2
movupd 0x20(%rbx,%rdx,8),%xmm5
movupd 0x30(%rbx,%rdx,8),%xmm6
mulpd  %xmm1,%xmm3
addpd  %xmm2,%xmm3
movupd %xmm4,(%rbx,%rdx,8)
movupd %xmm3,0x10(%rbx,%rdx,8)
movupd 0x20(%rax,%rdx,8),%xmm2
movupd 0x30(%rax,%rdx,8),%xmm3
mulpd  %xmm1,%xmm2
addpd  %xmm5,%xmm2
mulpd  %xmm1,%xmm3
addpd  %xmm6,%xmm3
movupd %xmm2,0x20(%rbx,%rdx,8)
movupd %xmm3,0x30(%rbx,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rbp
jne    1200 <add_mat+0x100>
test   $0x1,%r10b
je     12a6 <add_mat+0x1a6>
movupd (%rax,%rdx,8),%xmm2
movupd 0x10(%rax,%rdx,8),%xmm3
movupd (%rbx,%rdx,8),%xmm4
movupd 0x10(%rbx,%rdx,8),%xmm5
mulpd  %xmm1,%xmm2
addpd  %xmm4,%xmm2
mulpd  %xmm1,%xmm3
addpd  %xmm5,%xmm3
movupd %xmm2,(%rbx,%rdx,8)
movupd %xmm3,0x10(%rbx,%rdx,8)
mov    %r8,%rbp
cmp    %r13,%r8
je     1150 <add_mat+0x50>
jmp    1182 <add_mat+0x82>
xor    %edx,%edx
test   $0x1,%r10b
jne    1275 <add_mat+0x175>
jmp    12a6 <add_mat+0x1a6>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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