void work_ref(double a[128][128], double b[128][128], double c[128][128],
              int n) {
  int i, j;
  double tmp;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      tmp = a[i][j] + b[i][j];
      c[i][j] = tmp;
    }
  }
}


x86 assembly (clang, -O0):
<work_ref>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ac <work_ref+0xac>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1199 <work_ref+0x99>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
shl    $0xa,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
shl    $0xa,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
shl    $0xa,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112d <work_ref+0x2d>
jmp    119e <work_ref+0x9e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    111a <work_ref+0x1a>
pop    %rbp
ret

x86 assembly (clang, -O2):
<work_ref>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,-0x48(%rsp)
mov    %rdi,-0x50(%rsp)
test   %ecx,%ecx
jle    13be <work_ref+0x2be>
mov    %ecx,%r15d
mov    %r15d,%eax
and    $0xfffffffc,%eax
mov    %rax,-0x18(%rsp)
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x20(%rsp)
mov    %rax,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
mov    %rsi,%rax
mov    %rsi,-0x28(%rsp)
and    $0xfffffffffffffffe,%rsi
mov    %rsi,-0x30(%rsp)
mov    %r15,%rax
neg    %rax
mov    %rax,-0x8(%rsp)
mov    -0x50(%rsp),%rdi
lea    0x30(%rdi),%r12
mov    -0x48(%rsp),%rsi
lea    0x30(%rsi),%r13
lea    0x30(%rdx),%rbx
lea    0x8(%rdx),%rax
xor    %r8d,%r8d
mov    %ecx,-0x54(%rsp)
mov    %rdx,-0x38(%rsp)
jmp    11c6 <work_ref+0xc6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r8
add    $0x400,%r12
add    $0x400,%r13
add    $0x400,%rbx
add    $0x400,%rax
add    $0x400,%rsi
add    $0x400,%rdi
cmp    %r15,%r8
je     13be <work_ref+0x2be>
mov    %r8,%r10
shl    $0xa,%r10
lea    (%rdx,%r10,1),%r9
cmp    $0x4,%ecx
jae    1250 <work_ref+0x150>
xor    %r11d,%r11d
mov    %r11,%rbp
test   $0x1,%r15b
je     1209 <work_ref+0x109>
mov    -0x50(%rsp),%rbp
add    %r10,%rbp
movsd  0x0(%rbp,%r11,8),%xmm0
add    -0x48(%rsp),%r10
addsd  (%r10,%r11,8),%xmm0
movsd  %xmm0,(%r9,%r11,8)
mov    %r11,%rbp
or     $0x1,%rbp
not    %r11
cmp    -0x8(%rsp),%r11
je     1190 <work_ref+0x90>
nopw   0x0(%rax,%rax,1)
movsd  (%rdi,%rbp,8),%xmm0
addsd  (%rsi,%rbp,8),%xmm0
movsd  %xmm0,-0x8(%rax,%rbp,8)
movsd  0x8(%rdi,%rbp,8),%xmm0
addsd  0x8(%rsi,%rbp,8),%xmm0
movsd  %xmm0,(%rax,%rbp,8)
add    $0x2,%rbp
cmp    %rbp,%r15
jne    1220 <work_ref+0x120>
jmp    1190 <work_ref+0x90>
nop
lea    (%r9,%r15,8),%rdx
mov    -0x48(%rsp),%rcx
lea    (%rcx,%r10,1),%rbp
lea    0x0(,%r15,8),%r14
add    %rbp,%r14
mov    -0x50(%rsp),%rcx
lea    (%rcx,%r10,1),%r11
lea    (%r11,%r15,8),%rcx
cmp    %rcx,%r9
setb   -0x55(%rsp)
mov    %r11,-0x10(%rsp)
cmp    %rdx,%r11
setb   %r11b
mov    %r9,-0x40(%rsp)
cmp    %r14,%r9
setb   %cl
cmp    %rdx,%rbp
setb   %r9b
test   %r11b,-0x55(%rsp)
jne    134e <work_ref+0x24e>
mov    $0x0,%r11d
and    %r9b,%cl
mov    -0x54(%rsp),%ecx
mov    -0x38(%rsp),%rdx
mov    -0x40(%rsp),%r9
jne    11d9 <work_ref+0xd9>
cmpq   $0x0,-0x20(%rsp)
je     1364 <work_ref+0x264>
mov    -0x30(%rsp),%r9
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
movupd -0x30(%r12,%r14,8),%xmm0
movupd -0x20(%r12,%r14,8),%xmm1
movupd -0x30(%r13,%r14,8),%xmm2
addpd  %xmm0,%xmm2
movupd -0x20(%r13,%r14,8),%xmm0
addpd  %xmm1,%xmm0
movupd %xmm2,-0x30(%rbx,%r14,8)
movupd %xmm0,-0x20(%rbx,%r14,8)
movupd -0x10(%r12,%r14,8),%xmm0
movupd (%r12,%r14,8),%xmm1
movupd -0x10(%r13,%r14,8),%xmm2
addpd  %xmm0,%xmm2
movupd 0x0(%r13,%r14,8),%xmm0
addpd  %xmm1,%xmm0
movupd %xmm2,-0x10(%rbx,%r14,8)
movupd %xmm0,(%rbx,%r14,8)
add    $0x8,%r14
add    $0xfffffffffffffffe,%r9
jne    12e0 <work_ref+0x1e0>
jmp    1367 <work_ref+0x267>
xor    %r11d,%r11d
mov    -0x54(%rsp),%ecx
mov    -0x38(%rsp),%rdx
mov    -0x40(%rsp),%r9
jmp    11d9 <work_ref+0xd9>
xor    %r14d,%r14d
testb  $0x1,-0x28(%rsp)
mov    -0x40(%rsp),%r9
je     13a8 <work_ref+0x2a8>
mov    -0x10(%rsp),%r11
movupd (%r11,%r14,8),%xmm0
movupd 0x10(%r11,%r14,8),%xmm1
movupd 0x0(%rbp,%r14,8),%xmm2
addpd  %xmm0,%xmm2
movupd 0x10(%rbp,%r14,8),%xmm0
addpd  %xmm1,%xmm0
movupd %xmm2,(%r9,%r14,8)
movupd %xmm0,0x10(%r9,%r14,8)
mov    -0x18(%rsp),%rbp
mov    %rbp,%r11
cmp    %r15,%rbp
je     1190 <work_ref+0x90>
jmp    11d9 <work_ref+0xd9>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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