void compose_luminance(double **detail, double **base, double **luminance,
                       int width, int height) {
  int x, y;
  for (y = 0; y < height; y++)
    for (x = 0; x < width; x++)
      luminance[y][x] = base[y][x] + detail[y][x];
}


x86 assembly (clang, -O0):
<compose_luminance>:
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,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    119d <compose_luminance+0x9d>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    118a <compose_luminance+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1131 <compose_luminance+0x31>
jmp    118f <compose_luminance+0x8f>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    111e <compose_luminance+0x1e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<compose_luminance>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %r8d,%r8d
jle    1382 <compose_luminance+0x282>
mov    %r8d,%r8d
mov    %ecx,%r13d
mov    %r13d,%eax
and    $0xfffffffc,%eax
mov    %rax,-0x8(%rsp)
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x10(%rsp)
mov    %rax,%rbp
shr    $0x2,%rbp
add    $0x1,%rbp
mov    %rbp,%rax
mov    %rbp,-0x18(%rsp)
and    $0xfffffffffffffffe,%rbp
mov    %rbp,-0x20(%rsp)
mov    %r13d,%r11d
and    $0x3,%r11d
xor    %r12d,%r12d
mov    %ecx,-0x24(%rsp)
jmp    116d <compose_luminance+0x6d>
nopl   0x0(%rax)
add    $0x1,%r12
cmp    %r8,%r12
je     1382 <compose_luminance+0x282>
test   %ecx,%ecx
jle    1160 <compose_luminance+0x60>
mov    (%rsi,%r12,8),%r10
mov    (%rdi,%r12,8),%rax
mov    (%rdx,%r12,8),%rbp
cmp    $0x4,%ecx
jae    1190 <compose_luminance+0x90>
xor    %r9d,%r9d
jmp    12c0 <compose_luminance+0x1c0>
nopw   0x0(%rax,%rax,1)
mov    %r8,%rcx
lea    0x0(,%r13,8),%rbx
add    %rbp,%rbx
lea    (%r10,%r13,8),%r9
lea    (%rax,%r13,8),%r14
cmp    %r9,%rbp
setb   %r9b
cmp    %rbx,%r10
setb   %r8b
cmp    %r14,%rbp
setb   %r14b
cmp    %rbx,%rax
setb   %r15b
test   %r8b,%r9b
jne    12aa <compose_luminance+0x1aa>
mov    $0x0,%r9d
and    %r15b,%r14b
mov    %rcx,%r8
mov    -0x24(%rsp),%ecx
jne    12c0 <compose_luminance+0x1c0>
cmpq   $0x0,-0x10(%rsp)
je     1370 <compose_luminance+0x270>
mov    -0x20(%rsp),%r9
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movupd (%r10,%rbx,8),%xmm0
movupd 0x10(%r10,%rbx,8),%xmm1
movupd (%rax,%rbx,8),%xmm2
addpd  %xmm0,%xmm2
movupd 0x10(%rax,%rbx,8),%xmm0
addpd  %xmm1,%xmm0
movupd %xmm2,0x0(%rbp,%rbx,8)
movupd %xmm0,0x10(%rbp,%rbx,8)
movupd 0x20(%r10,%rbx,8),%xmm0
movupd 0x30(%r10,%rbx,8),%xmm1
movupd 0x20(%rax,%rbx,8),%xmm2
addpd  %xmm0,%xmm2
movupd 0x30(%rax,%rbx,8),%xmm0
addpd  %xmm1,%xmm0
movupd %xmm2,0x20(%rbp,%rbx,8)
movupd %xmm0,0x30(%rbp,%rbx,8)
add    $0x8,%rbx
add    $0xfffffffffffffffe,%r9
jne    1200 <compose_luminance+0x100>
testb  $0x1,-0x18(%rsp)
je     1297 <compose_luminance+0x197>
movupd (%r10,%rbx,8),%xmm0
movupd 0x10(%r10,%rbx,8),%xmm1
movupd (%rax,%rbx,8),%xmm2
addpd  %xmm0,%xmm2
movupd 0x10(%rax,%rbx,8),%xmm0
addpd  %xmm1,%xmm0
movupd %xmm2,0x0(%rbp,%rbx,8)
movupd %xmm0,0x10(%rbp,%rbx,8)
mov    -0x8(%rsp),%rbx
mov    %rbx,%r9
cmp    %r13,%rbx
je     1160 <compose_luminance+0x60>
jmp    12c0 <compose_luminance+0x1c0>
xor    %r9d,%r9d
mov    %rcx,%r8
mov    -0x24(%rsp),%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r9,%rbx
not    %rbx
add    %r13,%rbx
test   %r11,%r11
je     12fd <compose_luminance+0x1fd>
mov    %r11,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%r10,%r9,8),%xmm0
addsd  (%rax,%r9,8),%xmm0
movsd  %xmm0,0x0(%rbp,%r9,8)
add    $0x1,%r9
add    $0xffffffffffffffff,%r15
jne    12e0 <compose_luminance+0x1e0>
cmp    $0x3,%rbx
jb     1160 <compose_luminance+0x60>
nopw   0x0(%rax,%rax,1)
movsd  (%r10,%r9,8),%xmm0
addsd  (%rax,%r9,8),%xmm0
movsd  %xmm0,0x0(%rbp,%r9,8)
movsd  0x8(%r10,%r9,8),%xmm0
addsd  0x8(%rax,%r9,8),%xmm0
movsd  %xmm0,0x8(%rbp,%r9,8)
movsd  0x10(%r10,%r9,8),%xmm0
addsd  0x10(%rax,%r9,8),%xmm0
movsd  %xmm0,0x10(%rbp,%r9,8)
movsd  0x18(%r10,%r9,8),%xmm0
addsd  0x18(%rax,%r9,8),%xmm0
movsd  %xmm0,0x18(%rbp,%r9,8)
add    $0x4,%r9
cmp    %r9,%r13
jne    1310 <compose_luminance+0x210>
jmp    1160 <compose_luminance+0x60>
xor    %ebx,%ebx
testb  $0x1,-0x18(%rsp)
jne    126b <compose_luminance+0x16b>
jmp    1297 <compose_luminance+0x197>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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