#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef float uint32_t;

/* Variables and functions */
int /*<<< orphan*/ Lab2UnitCube(float *, float *, float *);
int /*<<< orphan*/ RGB2Lab(float *, float *, float *, float, float, float);
void build_tonecurve(int width_jpeg, int height_jpeg, float *buf_jpeg,
                     int offx_raw, int offy_raw, int width_raw, float *buf_raw,
                     float *curve, uint32_t *hist) {
  float *cL = curve;
  float *ca = cL + 0x10000;
  float *cb = ca + 0x10000;
  uint32_t *hL = hist;
  uint32_t *ha = hL + 0x10000;
  uint32_t *hb = ha + 0x10000;
  for (int j = 0; j < height_jpeg; j++) {
    for (int i = 0; i < width_jpeg; i++) {
      const int ri = offx_raw + i;
      const int rj = offy_raw + j;
      float r = buf_jpeg[3 * (width_jpeg * j + i) + 0];
      float g = buf_jpeg[3 * (width_jpeg * j + i) + 1];
      float b = buf_jpeg[3 * (width_jpeg * j + i) + 2];
      float L_jpeg;
      float a_jpeg;
      float b_jpeg;
      RGB2Lab(&L_jpeg, &a_jpeg, &b_jpeg, r, g, b);
      Lab2UnitCube(&L_jpeg, &a_jpeg, &b_jpeg);
      r = buf_raw[3 * (width_raw * rj + ri) + 0];
      g = buf_raw[3 * (width_raw * rj + ri) + 1];
      b = buf_raw[3 * (width_raw * rj + ri) + 2];
      float L_raw;
      float a_raw;
      float b_raw;
      RGB2Lab(&L_raw, &a_raw, &b_raw, r, g, b);
      Lab2UnitCube(&L_raw, &a_raw, &b_raw);
      size_t Li = (size_t)(L_raw * (float)(0x10000 - 1) + 0.5f);
      size_t ai = (size_t)(a_raw * (float)(0x10000 - 1) + 0.5f);
      size_t bi = (size_t)(b_raw * (float)(0x10000 - 1) + 0.5f);
      cL[Li] = (cL[Li] * hL[Li] + L_jpeg) / (hL[Li] + 1.0f);
      ca[ai] = (ca[ai] * ha[ai] + a_jpeg) / (ha[ai] + 1.0f);
      cb[bi] = (cb[bi] * hb[bi] + b_jpeg) / (hb[bi] + 1.0f);
      hL[Li]++;
      ha[ai]++;
      hb[bi]++;
    }
  }
}


x86 assembly (clang, -O0):
<build_tonecurve>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
mov    0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x40000,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x40000,%rax
mov    %rax,-0x38(%rbp)
mov    0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x40000,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    $0x40000,%rax
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1581 <build_tonecurve+0x461>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    156e <build_tonecurve+0x44e>
mov    -0x14(%rbp),%eax
mov    -0x58(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x54(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%edx
mov    -0x54(%rbp),%ecx
imul   %ecx,%edx
mov    -0x58(%rbp),%ecx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%edx
mov    -0x54(%rbp),%ecx
imul   %ecx,%edx
mov    -0x58(%rbp),%ecx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
movslq %ecx,%rcx
movss  0x4(%rax,%rcx,4),%xmm0
movss  %xmm0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%edx
mov    -0x54(%rbp),%ecx
imul   %ecx,%edx
mov    -0x58(%rbp),%ecx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
movslq %ecx,%rcx
movss  0x8(%rax,%rcx,4),%xmm0
movss  %xmm0,-0x6c(%rbp)
movss  -0x64(%rbp),%xmm0
movss  -0x68(%rbp),%xmm1
movss  -0x6c(%rbp),%xmm2
lea    -0x70(%rbp),%rdi
mov    %rdi,-0xd0(%rbp)
lea    -0x74(%rbp),%rsi
mov    %rsi,-0xc8(%rbp)
lea    -0x78(%rbp),%rdx
mov    %rdx,-0xc0(%rbp)
call   1030 <RGB2Lab@plt>
mov    -0xd0(%rbp),%rdi
mov    -0xc8(%rbp),%rsi
mov    -0xc0(%rbp),%rdx
call   1040 <Lab2UnitCube@plt>
mov    0x10(%rbp),%rax
mov    -0x1c(%rbp),%edx
mov    -0x60(%rbp),%ecx
imul   %ecx,%edx
mov    -0x5c(%rbp),%ecx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x64(%rbp)
mov    0x10(%rbp),%rax
mov    -0x1c(%rbp),%edx
mov    -0x60(%rbp),%ecx
imul   %ecx,%edx
mov    -0x5c(%rbp),%ecx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
movslq %ecx,%rcx
movss  0x4(%rax,%rcx,4),%xmm0
movss  %xmm0,-0x68(%rbp)
mov    0x10(%rbp),%rax
mov    -0x1c(%rbp),%edx
mov    -0x60(%rbp),%ecx
imul   %ecx,%edx
mov    -0x5c(%rbp),%ecx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
movslq %ecx,%rcx
movss  0x8(%rax,%rcx,4),%xmm0
movss  %xmm0,-0x6c(%rbp)
movss  -0x64(%rbp),%xmm0
movss  -0x68(%rbp),%xmm1
movss  -0x6c(%rbp),%xmm2
lea    -0x7c(%rbp),%rdi
mov    %rdi,-0xb8(%rbp)
lea    -0x80(%rbp),%rsi
mov    %rsi,-0xb0(%rbp)
lea    -0x84(%rbp),%rdx
mov    %rdx,-0xa8(%rbp)
call   1030 <RGB2Lab@plt>
mov    -0xb8(%rbp),%rdi
mov    -0xb0(%rbp),%rsi
mov    -0xa8(%rbp),%rdx
call   1040 <Lab2UnitCube@plt>
movss  -0x7c(%rbp),%xmm0
movss  0xcaa(%rip),%xmm3
mulss  %xmm3,%xmm0
movss  0xca2(%rip),%xmm2
addss  %xmm2,%xmm0
movaps %xmm0,%xmm1
cvttss2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movss  0xc8b(%rip),%xmm1
subss  %xmm1,%xmm0
cvttss2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x90(%rbp)
movss  -0x80(%rbp),%xmm0
mulss  %xmm3,%xmm0
addss  %xmm2,%xmm0
movaps %xmm0,%xmm4
cvttss2si %xmm4,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
subss  %xmm1,%xmm0
cvttss2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x98(%rbp)
movss  -0x84(%rbp),%xmm0
ff
mulss  %xmm3,%xmm0
addss  %xmm2,%xmm0
movaps %xmm0,%xmm2
cvttss2si %xmm2,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
subss  %xmm1,%xmm0
cvttss2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0xa0(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x90(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x40(%rbp),%rax
mov    -0x90(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm2
movss  -0x70(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x40(%rbp),%rax
mov    -0x90(%rbp),%rcx
movss  0xbc2(%rip),%xmm1
addss  (%rax,%rcx,4),%xmm1
divss  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
mov    -0x90(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
mov    -0x98(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x48(%rbp),%rax
mov    -0x98(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm2
movss  -0x74(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x48(%rbp),%rax
mov    -0x98(%rbp),%rcx
movss  0xb69(%rip),%xmm1
addss  (%rax,%rcx,4),%xmm1
divss  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
mov    -0x98(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x38(%rbp),%rax
mov    -0xa0(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x50(%rbp),%rax
mov    -0xa0(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm2
movss  -0x78(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x50(%rbp),%rax
mov    -0xa0(%rbp),%rcx
movss  0xb10(%rip),%xmm1
addss  (%rax,%rcx,4),%xmm1
divss  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
mov    -0xa0(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x40(%rbp),%rax
mov    -0x90(%rbp),%rcx
movss  0xae4(%rip),%xmm0
addss  (%rax,%rcx,4),%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x48(%rbp),%rax
mov    -0x98(%rbp),%rcx
movss  0xac7(%rip),%xmm0
addss  (%rax,%rcx,4),%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x50(%rbp),%rax
mov    -0xa0(%rbp),%rcx
movss  0xaaa(%rip),%xmm0
addss  (%rax,%rcx,4),%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11ae <build_tonecurve+0x8e>
jmp    1573 <build_tonecurve+0x453>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    119b <build_tonecurve+0x7b>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_tonecurve>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edi,0x4(%rsp)
test   %esi,%esi
jle    13e0 <build_tonecurve+0x2c0>
mov    %rdx,%r11
movslq 0x4(%rsp),%rax
mov    %esi,%edx
mov    %rdx,0x30(%rsp)
mov    %eax,%edx
add    $0x8,%r11
shl    $0x2,%rax
lea    (%rax,%rax,2),%rax
mov    %rax,0x28(%rsp)
imul   %r9d,%r8d
add    %r8d,%ecx
lea    (%rcx,%rcx,2),%eax
mov    %eax,0x8(%rsp)
lea    (%r9,%r9,2),%eax
mov    %eax,0x18(%rsp)
shl    $0x2,%rdx
lea    (%rdx,%rdx,2),%rsi
xor    %ecx,%ecx
mov    %rsi,0x40(%rsp)
jmp    11b1 <build_tonecurve+0x91>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x38(%rsp),%rcx
add    $0x1,%rcx
add    0x28(%rsp),%r11
mov    0x18(%rsp),%eax
add    %eax,0x8(%rsp)
cmp    0x30(%rsp),%rcx
je     13e0 <build_tonecurve+0x2c0>
mov    %rcx,0x38(%rsp)
cmpl   $0x0,0x4(%rsp)
lea    0x1c(%rsp),%r13
jle    1190 <build_tonecurve+0x70>
mov    0x8(%rsp),%eax
mov    %eax,%r14d
xor    %r15d,%r15d
nopl   0x0(%rax)
movss  -0x8(%r11,%r15,1),%xmm0
movss  -0x4(%r11,%r15,1),%xmm1
movss  (%r11,%r15,1),%xmm2
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r11,%rbx
call   1030 <RGB2Lab@plt>
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1040 <Lab2UnitCube@plt>
movslq %r14d,%r14
mov    0x80(%rsp),%rcx
movss  (%rcx,%r14,4),%xmm0
lea    0x1(%r14),%eax
cltq
movss  (%rcx,%rax,4),%xmm1
lea    0x2(%r14),%eax
cltq
movss  (%rcx,%rax,4),%xmm2
lea    0x24(%rsp),%rbp
mov    %rbp,%rdi
lea    0x20(%rsp),%r12
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <RGB2Lab@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <Lab2UnitCube@plt>
movss  0xda4(%rip),%xmm4
movss  0xd98(%rip),%xmm3
movss  0xd8c(%rip),%xmm2
mov    %rbx,%r11
mov    0x90(%rsp),%rbx
mov    0x88(%rsp),%r9
movss  0x24(%rsp),%xmm0
mulss  %xmm2,%xmm0
addss  %xmm3,%xmm0
cvttss2si %xmm0,%rsi
mov    %rsi,%rdx
sar    $0x3f,%rdx
subss  %xmm4,%xmm0
cvttss2si %xmm0,%rax
movss  0x20(%rsp),%xmm0
mulss  %xmm2,%xmm0
addss  %xmm3,%xmm0
cvttss2si %xmm0,%r8
movss  0x1c(%rsp),%xmm1
mulss  %xmm2,%xmm1
movss  0xd3d(%rip),%xmm2
addss  %xmm3,%xmm1
subss  %xmm4,%xmm0
cvttss2si %xmm1,%rdi
cvttss2si %xmm0,%rcx
and    %rdx,%rax
subss  %xmm4,%xmm1
cvttss2si %xmm1,%rdx
or     %rsi,%rax
mov    %r8,%rsi
movss  (%rbx,%rax,4),%xmm0
movss  (%r9,%rax,4),%xmm1
sar    $0x3f,%rsi
mov    %rdi,%rbp
mulss  %xmm0,%xmm1
addss  0x14(%rsp),%xmm1
and    %rsi,%rcx
sar    $0x3f,%rbp
addss  %xmm2,%xmm0
divss  %xmm0,%xmm1
or     %r8,%rcx
movss  %xmm1,(%r9,%rax,4)
movss  0x40000(%rbx,%rcx,4),%xmm0
movss  0x40000(%r9,%rcx,4),%xmm1
and    %rbp,%rdx
mulss  %xmm0,%xmm1
addss  0x10(%rsp),%xmm1
or     %rdi,%rdx
addss  %xmm2,%xmm0
divss  %xmm0,%xmm1
movss  %xmm1,0x40000(%r9,%rcx,4)
movss  0x80000(%rbx,%rdx,4),%xmm0
movss  0x80000(%r9,%rdx,4),%xmm1
mulss  %xmm0,%xmm1
addss  0xc(%rsp),%xmm1
addss  %xmm2,%xmm0
divss  %xmm0,%xmm1
movss  %xmm1,0x80000(%r9,%rdx,4)
movss  (%rbx,%rax,4),%xmm0
addss  %xmm2,%xmm0
movss  %xmm0,(%rbx,%rax,4)
movss  0x40000(%rbx,%rcx,4),%xmm0
addss  %xmm2,%xmm0
movss  %xmm0,0x40000(%rbx,%rcx,4)
mov    0x40(%rsp),%rsi
movss  0x80000(%rbx,%rdx,4),%xmm0
addss  %xmm2,%xmm0
movss  %xmm0,0x80000(%rbx,%rdx,4)
add    $0xc,%r15
add    $0x3,%r14d
cmp    %r15,%rsi
jne    11d0 <build_tonecurve+0xb0>
jmp    1190 <build_tonecurve+0x70>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @build_tonecurve(i32 %0, i32 %1, float* %2, i32 %3, i32 %4, i32 %5, float* %6, float* %7, float* %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca float*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca float*
%17 = alloca float*
%18 = alloca float*
%19 = alloca float*
%20 = alloca float*
%21 = alloca float*
%22 = alloca float*
%23 = alloca float*
%24 = alloca float*
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca float
%30 = alloca float
%31 = alloca float
%32 = alloca float
%33 = alloca float
%34 = alloca float
%35 = alloca float
%36 = alloca float
%37 = alloca float
%38 = alloca i64
%39 = alloca i64
%40 = alloca i64
store i32 %0, i32* %10
store i32 %1, i32* %11
store float* %2, float** %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store i32 %5, i32* %15
store float* %6, float** %16
store float* %7, float** %17
store float* %8, float** %18
%41 = load float*, float** %17
store float* %41, float** %19
%42 = load float*, float** %19
%43 = getelementptr inbounds float, float* %42, i64 65536
store float* %43, float** %20
%44 = load float*, float** %20
%45 = getelementptr inbounds float, float* %44, i64 65536
store float* %45, float** %21
%46 = load float*, float** %18
store float* %46, float** %22
%47 = load float*, float** %22
%48 = getelementptr inbounds float, float* %47, i64 65536
store float* %48, float** %23
%49 = load float*, float** %23
%50 = getelementptr inbounds float, float* %49, i64 65536
store float* %50, float** %24
store i32 0, i32* %25
br label %51
51: ; preds = %228, %9
%52 = load i32, i32* %25
%53 = load i32, i32* %11
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %231
55: ; preds = %51
store i32 0, i32* %26
br label %56
56: ; preds = %224, %55
%57 = load i32, i32* %26
%58 = load i32, i32* %10
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %227
60: ; preds = %56
%61 = load i32, i32* %13
%62 = load i32, i32* %26
%63 = add nsw i32 %61, %62
store i32 %63, i32* %27
%64 = load i32, i32* %14
%65 = load i32, i32* %25
%66 = add nsw i32 %64, %65
store i32 %66, i32* %28
%67 = load float*, float** %12
%68 = load i32, i32* %10
%69 = load i32, i32* %25
%70 = mul nsw i32 %68, %69
%71 = load i32, i32* %26
%72 = add nsw i32 %70, %71
%73 = mul nsw i32 3, %72
%74 = add nsw i32 %73, 0
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds float, float* %67, i64 %75
%77 = load float, float* %76
store float %77, float* %29
%78 = load float*, float** %12
%79 = load i32, i32* %10
%80 = load i32, i32* %25
%81 = mul nsw i32 %79, %80
%82 = load i32, i32* %26
%83 = add nsw i32 %81, %82
%84 = mul nsw i32 3, %83
%85 = add nsw i32 %84, 1
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds float, float* %78, i64 %86
%88 = load float, float* %87
store float %88, float* %30
%89 = load float*, float** %12
%90 = load i32, i32* %10
%91 = load i32, i32* %25
%92 = mul nsw i32 %90, %91
%93 = load i32, i32* %26
%94 = add nsw i32 %92, %93
%95 = mul nsw i32 3, %94
%96 = add nsw i32 %95, 2
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds float, float* %89, i64 %97
%99 = load float, float* %98
store float %99, float* %31
%100 = load float, float* %29
%101 = load float, float* %30
%102 = load float, float* %31
%103 = call i32 @RGB2Lab(float* %32, float* %33, float* %34, float %100, float %101, float %102)
%104 = call i32 @Lab2UnitCube(float* %32, float* %33, float* %34)
%105 = load float*, float** %16
%106 = load i32, i32* %15
%107 = load i32, i32* %28
%108 = mul nsw i32 %106, %107
%109 = load i32, i32* %27
%110 = add nsw i32 %108, %109
%111 = mul nsw i32 3, %110
%112 = add nsw i32 %111, 0
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds float, float* %105, i64 %113
%115 = load float, float* %114
store float %115, float* %29
%116 = load float*, float** %16
%117 = load i32, i32* %15
%118 = load i32, i32* %28
%119 = mul nsw i32 %117, %118
%120 = load i32, i32* %27
%121 = add nsw i32 %119, %120
%122 = mul nsw i32 3, %121
%123 = add nsw i32 %122, 1
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds float, float* %116, i64 %124
%126 = load float, float* %125
store float %126, float* %30
%127 = load float*, float** %16
%128 = load i32, i32* %15
%129 = load i32, i32* %28
%130 = mul nsw i32 %128, %129
%131 = load i32, i32* %27
%132 = add nsw i32 %130, %131
%133 = mul nsw i32 3, %132
%134 = add nsw i32 %133, 2
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds float, float* %127, i64 %135
%137 = load float, float* %136
store float %137, float* %31
%138 = load float, float* %29
%139 = load float, float* %30
%140 = load float, float* %31
%141 = call i32 @RGB2Lab(float* %35, float* %36, float* %37, float %138, float %139, float %140)
%142 = call i32 @Lab2UnitCube(float* %35, float* %36, float* %37)
%143 = load float, float* %35
%144 = call float @llvm.fmuladd.f32(float %143, float 6.553500e+04, float 5.000000e-01)
%145 = fptoui float %144 to i64
store i64 %145, i64* %38
%146 = load float, float* %36
%147 = call float @llvm.fmuladd.f32(float %146, float 6.553500e+04, float 5.000000e-01)
%148 = fptoui float %147 to i64
store i64 %148, i64* %39
%149 = load float, float* %37
%150 = call float @llvm.fmuladd.f32(float %149, float 6.553500e+04, float 5.000000e-01)
%151 = fptoui float %150 to i64
store i64 %151, i64* %40
%152 = load float*, float** %19
%153 = load i64, i64* %38
%154 = getelementptr inbounds float, float* %152, i64 %153
%155 = load float, float* %154
%156 = load float*, float** %22
%157 = load i64, i64* %38
%158 = getelementptr inbounds float, float* %156, i64 %157
%159 = load float, float* %158
%160 = load float, float* %32
%161 = call float @llvm.fmuladd.f32(float %155, float %159, float %160)
%162 = load float*, float** %22
%163 = load i64, i64* %38
%164 = getelementptr inbounds float, float* %162, i64 %163
%165 = load float, float* %164
%166 = fadd float %165, 1.000000e+00
%167 = fdiv float %161, %166
%168 = load float*, float** %19
%169 = load i64, i64* %38
%170 = getelementptr inbounds float, float* %168, i64 %169
store float %167, float* %170
%171 = load float*, float** %20
%172 = load i64, i64* %39
%173 = getelementptr inbounds float, float* %171, i64 %172
%174 = load float, float* %173
%175 = load float*, float** %23
%176 = load i64, i64* %39
%177 = getelementptr inbounds float, float* %175, i64 %176
%178 = load float, float* %177
%179 = load float, float* %33
%180 = call float @llvm.fmuladd.f32(float %174, float %178, float %179)
%181 = load float*, float** %23
%182 = load i64, i64* %39
%183 = getelementptr inbounds float, float* %181, i64 %182
%184 = load float, float* %183
%185 = fadd float %184, 1.000000e+00
%186 = fdiv float %180, %185
%187 = load float*, float** %20
%188 = load i64, i64* %39
%189 = getelementptr inbounds float, float* %187, i64 %188
store float %186, float* %189
%190 = load float*, float** %21
%191 = load i64, i64* %40
%192 = getelementptr inbounds float, float* %190, i64 %191
%193 = load float, float* %192
%194 = load float*, float** %24
%195 = load i64, i64* %40
%196 = getelementptr inbounds float, float* %194, i64 %195
%197 = load float, float* %196
%198 = load float, float* %34
%199 = call float @llvm.fmuladd.f32(float %193, float %197, float %198)
%200 = load float*, float** %24
%201 = load i64, i64* %40
%202 = getelementptr inbounds float, float* %200, i64 %201
%203 = load float, float* %202
%204 = fadd float %203, 1.000000e+00
%205 = fdiv float %199, %204
%206 = load float*, float** %21
%207 = load i64, i64* %40
%208 = getelementptr inbounds float, float* %206, i64 %207
store float %205, float* %208
%209 = load float*, float** %22
%210 = load i64, i64* %38
%211 = getelementptr inbounds float, float* %209, i64 %210
%212 = load float, float* %211
%213 = fadd float %212, 1.000000e+00
store float %213, float* %211
%214 = load float*, float** %23
%215 = load i64, i64* %39
%216 = getelementptr inbounds float, float* %214, i64 %215
%217 = load float, float* %216
%218 = fadd float %217, 1.000000e+00
store float %218, float* %216
%219 = load float*, float** %24
%220 = load i64, i64* %40
%221 = getelementptr inbounds float, float* %219, i64 %220
%222 = load float, float* %221
%223 = fadd float %222, 1.000000e+00
store float %223, float* %221
br label %224
224: ; preds = %60
%225 = load i32, i32* %26
%226 = add nsw i32 %225, 1
store i32 %226, i32* %26
br label %56
227: ; preds = %56
br label %228
228: ; preds = %227
%229 = load i32, i32* %25
%230 = add nsw i32 %229, 1
store i32 %230, i32* %25
br label %51
231: ; preds = %51
ret void
}

LLVM IR (-O2):
define void @build_tonecurve(i32 %0, i32 %1, float* nocapture %2, i32 %3, i32 %4, i32 %5, float* nocapture %6, float* nocapture %7, float* nocapture %8) {
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca float
%15 = alloca float
%16 = getelementptr inbounds float, float* %7, i64 65536
%17 = getelementptr inbounds float, float* %7, i64 131072
%18 = getelementptr inbounds float, float* %8, i64 65536
%19 = getelementptr inbounds float, float* %8, i64 131072
%20 = icmp sgt i32 %1, 0
br i1 %20, label %21, label %40
21: ; preds = %9
%22 = icmp sgt i32 %0, 0
%23 = bitcast float* %10 to i8*
%24 = bitcast float* %11 to i8*
%25 = bitcast float* %12 to i8*
%26 = bitcast float* %13 to i8*
%27 = bitcast float* %14 to i8*
%28 = bitcast float* %15 to i8*
%29 = sext i32 %0 to i64
%30 = zext i32 %1 to i64
%31 = zext i32 %0 to i64
br label %32
32: ; preds = %21, %41
%33 = phi i64 [ 0, %21 ], [ %42, %41 ]
br i1 %22, label %34, label %41
34: ; preds = %32
%35 = mul nsw i64 %33, %29
%36 = trunc i64 %33 to i32
%37 = add i32 %36, %4
%38 = mul i32 %37, %5
%39 = add i32 %38, %3
br label %44
40: ; preds = %41, %9
ret void
41: ; preds = %44, %32
%42 = add nuw nsw i64 %33, 1
%43 = icmp eq i64 %42, %30
br i1 %43, label %40, label %32
44: ; preds = %34, %44
%45 = phi i64 [ 0, %34 ], [ %113, %44 ]
%46 = add nsw i64 %45, %35
%47 = mul nsw i64 %46, 3
%48 = getelementptr inbounds float, float* %2, i64 %47
%49 = load float, float* %48
%50 = add nsw i64 %47, 1
%51 = getelementptr inbounds float, float* %2, i64 %50
%52 = load float, float* %51
%53 = add nsw i64 %47, 2
%54 = getelementptr inbounds float, float* %2, i64 %53
%55 = load float, float* %54
%56 = call i32 @RGB2Lab(float* %10, float* %11, float* %12, float %49, float %52, float %55)
%57 = call i32 @Lab2UnitCube(float* %10, float* %11, float* %12)
%58 = trunc i64 %45 to i32
%59 = add i32 %39, %58
%60 = mul nsw i32 %59, 3
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds float, float* %6, i64 %61
%63 = load float, float* %62
%64 = add nsw i32 %60, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds float, float* %6, i64 %65
%67 = load float, float* %66
%68 = add nsw i32 %60, 2
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds float, float* %6, i64 %69
%71 = load float, float* %70
%72 = call i32 @RGB2Lab(float* %13, float* %14, float* %15, float %63, float %67, float %71)
%73 = call i32 @Lab2UnitCube(float* %13, float* %14, float* %15)
%74 = load float, float* %13
%75 = call float @llvm.fmuladd.f32(float %74, float 6.553500e+04, float 5.000000e-01)
%76 = fptoui float %75 to i64
%77 = load float, float* %14
%78 = call float @llvm.fmuladd.f32(float %77, float 6.553500e+04, float 5.000000e-01)
%79 = fptoui float %78 to i64
%80 = load float, float* %15
%81 = call float @llvm.fmuladd.f32(float %80, float 6.553500e+04, float 5.000000e-01)
%82 = fptoui float %81 to i64
%83 = getelementptr inbounds float, float* %7, i64 %76
%84 = load float, float* %83
%85 = getelementptr inbounds float, float* %8, i64 %76
%86 = load float, float* %85
%87 = load float, float* %10
%88 = call float @llvm.fmuladd.f32(float %84, float %86, float %87)
%89 = fadd float %86, 1.000000e+00
%90 = fdiv float %88, %89
store float %90, float* %83
%91 = getelementptr inbounds float, float* %16, i64 %79
%92 = load float, float* %91
%93 = getelementptr inbounds float, float* %18, i64 %79
%94 = load float, float* %93
%95 = load float, float* %11
%96 = call float @llvm.fmuladd.f32(float %92, float %94, float %95)
%97 = fadd float %94, 1.000000e+00
%98 = fdiv float %96, %97
store float %98, float* %91
%99 = getelementptr inbounds float, float* %17, i64 %82
%100 = load float, float* %99
%101 = getelementptr inbounds float, float* %19, i64 %82
%102 = load float, float* %101
%103 = load float, float* %12
%104 = call float @llvm.fmuladd.f32(float %100, float %102, float %103)
%105 = fadd float %102, 1.000000e+00
%106 = fdiv float %104, %105
store float %106, float* %99
%107 = load float, float* %85
%108 = fadd float %107, 1.000000e+00
store float %108, float* %85
%109 = load float, float* %93
%110 = fadd float %109, 1.000000e+00
store float %110, float* %93
%111 = load float, float* %101
%112 = fadd float %111, 1.000000e+00
store float %112, float* %101
%113 = add nuw nsw i64 %45, 1
%114 = icmp eq i64 %113, %31
br i1 %114, label %41, label %44
}