void subtractMatrix(double first[][3], double second[][3], double result[][3],
                    int rows, int cols) {
  int i, j;
  for (i = 0; i < rows; ++i) {
    for (j = 0; j < cols; ++j) {
      result[i][j] = first[i][j] - second[i][j];
    }
  }
}


x86 assembly (clang, -O0):
<subtractMatrix>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11a6 <subtractMatrix+0xa6>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1193 <subtractMatrix+0x93>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1131 <subtractMatrix+0x31>
jmp    1198 <subtractMatrix+0x98>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    111e <subtractMatrix+0x1e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<subtractMatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %ecx,%ecx
jle    13b6 <subtractMatrix+0x2b6>
mov    %ecx,%eax
mov    %rax,-0x8(%rsp)
mov    %r8d,%r13d
mov    %r13d,%eax
and    $0xfffffffc,%eax
mov    %rax,-0x18(%rsp)
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x20(%rsp)
mov    %rax,%rcx
shr    $0x2,%rcx
add    $0x1,%rcx
mov    %rcx,%rax
mov    %rcx,-0x28(%rsp)
and    $0xfffffffffffffffe,%rcx
mov    %rcx,-0x30(%rsp)
mov    %r13,%rax
neg    %rax
mov    %rax,-0x10(%rsp)
lea    0x30(%rdi),%r9
lea    0x30(%rsi),%rax
lea    0x30(%rdx),%rcx
lea    0x8(%rdx),%rbp
xor    %r14d,%r14d
mov    %rdi,%r11
mov    %rsi,%r12
mov    %r8d,-0x5c(%rsp)
mov    %rdi,-0x48(%rsp)
mov    %rsi,-0x50(%rsp)
mov    %rdx,-0x58(%rsp)
jmp    11b7 <subtractMatrix+0xb7>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r14
add    $0x18,%r9
add    $0x18,%rax
add    $0x18,%rcx
add    $0x18,%rbp
add    $0x18,%r12
add    $0x18,%r11
cmp    -0x8(%rsp),%r14
je     13b6 <subtractMatrix+0x2b6>
test   %r8d,%r8d
jle    1190 <subtractMatrix+0x90>
lea    0x0(,%r14,8),%rbx
lea    (%rbx,%rbx,2),%r15
lea    (%rdx,%r15,1),%rbx
lea    (%rdi,%r15,1),%r10
add    %rsi,%r15
cmp    $0x4,%r8d
mov    %rbx,-0x38(%rsp)
mov    %r10,-0x40(%rsp)
jae    11f0 <subtractMatrix+0xf0>
xor    %r10d,%r10d
jmp    1330 <subtractMatrix+0x230>
nopl   0x0(%rax,%rax,1)
lea    (%rbx,%r13,8),%rdx
mov    %r10,%rsi
lea    (%r10,%r13,8),%r10
lea    (%r15,%r13,8),%rdi
cmp    %r10,%rbx
setb   %r10b
cmp    %rdx,%rsi
setb   %r8b
cmp    %rdi,%rbx
setb   %bl
cmp    %rdx,%r15
setb   %dl
test   %r8b,%r10b
jne    1316 <subtractMatrix+0x216>
mov    $0x0,%r10d
and    %dl,%bl
mov    -0x5c(%rsp),%r8d
mov    -0x58(%rsp),%rdx
mov    -0x50(%rsp),%rsi
mov    -0x48(%rsp),%rdi
jne    1330 <subtractMatrix+0x230>
cmpq   $0x0,-0x20(%rsp)
je     13a4 <subtractMatrix+0x2a4>
mov    -0x30(%rsp),%r10
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movupd -0x30(%r9,%rbx,8),%xmm0
movupd -0x20(%r9,%rbx,8),%xmm1
movupd -0x30(%rax,%rbx,8),%xmm2
subpd  %xmm2,%xmm0
movupd -0x20(%rax,%rbx,8),%xmm2
subpd  %xmm2,%xmm1
movupd %xmm0,-0x30(%rcx,%rbx,8)
movupd %xmm1,-0x20(%rcx,%rbx,8)
movupd -0x10(%r9,%rbx,8),%xmm0
movupd (%r9,%rbx,8),%xmm1
movupd -0x10(%rax,%rbx,8),%xmm2
subpd  %xmm2,%xmm0
movupd (%rax,%rbx,8),%xmm2
subpd  %xmm2,%xmm1
movupd %xmm0,-0x10(%rcx,%rbx,8)
movupd %xmm1,(%rcx,%rbx,8)
add    $0x8,%rbx
add    $0xfffffffffffffffe,%r10
jne    1260 <subtractMatrix+0x160>
testb  $0x1,-0x28(%rsp)
je     1303 <subtractMatrix+0x203>
mov    -0x40(%rsp),%r10
movupd (%r10,%rbx,8),%xmm0
movupd 0x10(%r10,%rbx,8),%xmm1
movupd (%r15,%rbx,8),%xmm2
subpd  %xmm2,%xmm0
movupd 0x10(%r15,%rbx,8),%xmm2
subpd  %xmm2,%xmm1
mov    -0x38(%rsp),%r10
movupd %xmm0,(%r10,%rbx,8)
movupd %xmm1,0x10(%r10,%rbx,8)
mov    -0x18(%rsp),%rbx
mov    %rbx,%r10
cmp    %r13,%rbx
je     1190 <subtractMatrix+0x90>
jmp    1330 <subtractMatrix+0x230>
xor    %r10d,%r10d
mov    -0x5c(%rsp),%r8d
mov    -0x58(%rsp),%rdx
mov    -0x50(%rsp),%rsi
mov    -0x48(%rsp),%rdi
nopl   (%rax)
mov    %r10,%rbx
test   $0x1,%r13b
je     135c <subtractMatrix+0x25c>
mov    -0x40(%rsp),%rbx
movsd  (%rbx,%r10,8),%xmm0
subsd  (%r15,%r10,8),%xmm0
mov    -0x38(%rsp),%rbx
movsd  %xmm0,(%rbx,%r10,8)
mov    %r10,%rbx
or     $0x1,%rbx
not    %r10
cmp    -0x10(%rsp),%r10
je     1190 <subtractMatrix+0x90>
nopw   0x0(%rax,%rax,1)
movsd  (%r11,%rbx,8),%xmm0
subsd  (%r12,%rbx,8),%xmm0
movsd  %xmm0,-0x8(%rbp,%rbx,8)
movsd  0x8(%r11,%rbx,8),%xmm0
subsd  0x8(%r12,%rbx,8),%xmm0
movsd  %xmm0,0x0(%rbp,%rbx,8)
add    $0x2,%rbx
cmp    %rbx,%r13
jne    1370 <subtractMatrix+0x270>
jmp    1190 <subtractMatrix+0x90>
xor    %ebx,%ebx
testb  $0x1,-0x28(%rsp)
jne    12ca <subtractMatrix+0x1ca>
jmp    1303 <subtractMatrix+0x203>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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