void subtract_array_array(double *out, double *a, double *b, int ncol,
                          int nlns) {
  int i, j;
  for (i = 0; i < ncol; i++)
    for (j = 0; j < nlns; j++)
      (out[(i) * (nlns) + (j)]) =
          (a[(i) * (nlns) + (j)]) - (b[(i) * (nlns) + (j)]);
}


x86 assembly (clang, -O0):
<subtract_array_array>:
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    11a0 <subtract_array_array+0xa0>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    118d <subtract_array_array+0x8d>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x20(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x20(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x20(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1131 <subtract_array_array+0x31>
jmp    1192 <subtract_array_array+0x92>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    111e <subtract_array_array+0x1e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<subtract_array_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,-0x58(%rsp)
mov    %rsi,-0x60(%rsp)
mov    %rdi,-0x68(%rsp)
test   %ecx,%ecx
jle    13f8 <subtract_array_array+0x2f8>
movslq %r8d,%rdx
mov    %ecx,%r9d
mov    %edx,%eax
mov    %eax,%ecx
and    $0xfffffffc,%ecx
mov    %rcx,-0x30(%rsp)
add    $0xfffffffffffffffc,%rcx
mov    %rcx,-0x38(%rsp)
mov    %rcx,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
mov    %rsi,%rcx
mov    %rsi,-0x40(%rsp)
and    $0xfffffffffffffffe,%rsi
mov    %rsi,-0x48(%rsp)
mov    %rax,%rcx
neg    %rcx
mov    %rcx,-0x28(%rsp)
mov    -0x68(%rsp),%rdi
lea    0x30(%rdi),%rbx
mov    %rdx,-0x8(%rsp)
lea    0x0(,%rdx,8),%rsi
mov    -0x58(%rsp),%rcx
lea    0x30(%rcx),%rbp
mov    -0x60(%rsp),%rdx
lea    0x30(%rdx),%r14
lea    0x8(%rdx),%r11
lea    0x8(%rcx),%r15
lea    0x8(%rdi),%r10
mov    %r9,%rdi
xor    %r12d,%r12d
mov    %r8d,-0x6c(%rsp)
mov    %r9,-0x50(%rsp)
jmp    11cf <subtract_array_array+0xcf>
nopl   0x0(%rax)
add    $0x1,%r12
add    %rsi,%rbx
add    %rsi,%rbp
add    %rsi,%r14
add    %rsi,%r11
add    %rsi,%r15
add    %rsi,%r10
cmp    %rdi,%r12
je     13f8 <subtract_array_array+0x2f8>
test   %r8d,%r8d
jle    11b0 <subtract_array_array+0xb0>
mov    %r12,%r9
imul   -0x8(%rsp),%r9
cmp    $0x4,%r8d
jae    11f0 <subtract_array_array+0xf0>
xor    %edx,%edx
jmp    1370 <subtract_array_array+0x270>
nopw   0x0(%rax,%rax,1)
lea    (%r9,%rax,1),%rcx
mov    -0x68(%rsp),%rdx
lea    (%rdx,%r9,8),%r13
lea    (%rdx,%rcx,8),%rdx
mov    %rdx,-0x20(%rsp)
mov    -0x60(%rsp),%rdx
lea    (%rdx,%r9,8),%rdi
mov    %rdi,-0x18(%rsp)
lea    (%rdx,%rcx,8),%rdi
mov    -0x58(%rsp),%rdx
lea    (%rdx,%r9,8),%r8
mov    %r8,-0x10(%rsp)
lea    (%rdx,%rcx,8),%rcx
cmp    %rdi,%r13
setb   %dl
mov    -0x20(%rsp),%rdi
cmp    %rdi,-0x18(%rsp)
setb   %r8b
cmp    %rcx,%r13
setb   %cl
cmp    %rdi,-0x10(%rsp)
setb   %r13b
test   %r8b,%dl
jne    1357 <subtract_array_array+0x257>
mov    $0x0,%edx
and    %r13b,%cl
mov    -0x6c(%rsp),%r8d
mov    -0x50(%rsp),%rdi
jne    1370 <subtract_array_array+0x270>
cmpq   $0x0,-0x38(%rsp)
je     13e5 <subtract_array_array+0x2e5>
mov    -0x48(%rsp),%rcx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movupd -0x30(%r14,%r13,8),%xmm0
movupd -0x20(%r14,%r13,8),%xmm1
movupd -0x30(%rbp,%r13,8),%xmm2
subpd  %xmm2,%xmm0
movupd -0x20(%rbp,%r13,8),%xmm2
subpd  %xmm2,%xmm1
movupd %xmm0,-0x30(%rbx,%r13,8)
movupd %xmm1,-0x20(%rbx,%r13,8)
movupd -0x10(%r14,%r13,8),%xmm0
movupd (%r14,%r13,8),%xmm1
movupd -0x10(%rbp,%r13,8),%xmm2
subpd  %xmm2,%xmm0
movupd 0x0(%rbp,%r13,8),%xmm2
subpd  %xmm2,%xmm1
movupd %xmm0,-0x10(%rbx,%r13,8)
movupd %xmm1,(%rbx,%r13,8)
add    $0x8,%r13
add    $0xfffffffffffffffe,%rcx
jne    1290 <subtract_array_array+0x190>
testb  $0x1,-0x40(%rsp)
je     1344 <subtract_array_array+0x244>
add    %r9,%r13
mov    -0x60(%rsp),%rcx
movupd (%rcx,%r13,8),%xmm0
movupd 0x10(%rcx,%r13,8),%xmm1
mov    -0x58(%rsp),%rcx
movupd (%rcx,%r13,8),%xmm2
subpd  %xmm2,%xmm0
movupd 0x10(%rcx,%r13,8),%xmm2
subpd  %xmm2,%xmm1
mov    -0x68(%rsp),%rcx
movupd %xmm0,(%rcx,%r13,8)
movupd %xmm1,0x10(%rcx,%r13,8)
mov    -0x30(%rsp),%rcx
mov    %rcx,%rdx
cmp    %rax,%rcx
je     11b0 <subtract_array_array+0xb0>
jmp    1370 <subtract_array_array+0x270>
xor    %edx,%edx
mov    -0x6c(%rsp),%r8d
mov    -0x50(%rsp),%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rdx,%rcx
test   $0x1,%al
je     13a2 <subtract_array_array+0x2a2>
add    %rdx,%r9
mov    -0x60(%rsp),%rcx
movsd  (%rcx,%r9,8),%xmm0
mov    -0x58(%rsp),%rcx
subsd  (%rcx,%r9,8),%xmm0
mov    -0x68(%rsp),%rcx
movsd  %xmm0,(%rcx,%r9,8)
mov    %rdx,%rcx
or     $0x1,%rcx
not    %rdx
cmp    -0x28(%rsp),%rdx
je     11b0 <subtract_array_array+0xb0>
movsd  -0x8(%r11,%rcx,8),%xmm0
subsd  -0x8(%r15,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%r10,%rcx,8)
movsd  (%r11,%rcx,8),%xmm0
subsd  (%r15,%rcx,8),%xmm0
movsd  %xmm0,(%r10,%rcx,8)
add    $0x2,%rcx
cmp    %rcx,%rax
jne    13b0 <subtract_array_array+0x2b0>
jmp    11b0 <subtract_array_array+0xb0>
xor    %r13d,%r13d
testb  $0x1,-0x40(%rsp)
jne    1303 <subtract_array_array+0x203>
jmp    1344 <subtract_array_array+0x244>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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