#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 */

/* Variables and functions */
double log10(double);
double pow(int, double);
void ColorTemperatureCurve(unsigned char *ImageDataBlock, int imageHeight,
                           int imageWidth, double *RCoefficient,
                           double *BCoefficient, int ColumnWidth) {
  int i;
  int j;
  int BIndex;
  int GIndex;
  int RIndex;
  double x;
  double y;
  double slope;
  double b;
  double GRRatio = 0;
  double GBRatio = 0;
  double RTotal = 0;
  double GTotal = 0;
  double BTotal = 0;
  for (i = 0; i < imageHeight; i++)
    for (j = 0; j < ColumnWidth; j += 3) {
      BIndex = i * ColumnWidth + (j + 0);
      GIndex = i * ColumnWidth + (j + 1);
      RIndex = i * ColumnWidth + (j + 2);
      BTotal += ImageDataBlock[BIndex];
      GTotal += ImageDataBlock[GIndex];
      RTotal += ImageDataBlock[RIndex];
    }
  GBRatio = GTotal / BTotal;
  GRRatio = GTotal / RTotal;
  GBRatio = log10(GBRatio);
  GRRatio = log10(GRRatio);
  x = GRRatio;
  y = GBRatio;
  slope = 1 / 1.0163;
  b = y - slope * x;
  GRRatio = (-b + 0.4258) / (slope + 1.0163);
  GBRatio = -1.0163 * GRRatio + 0.4258;
  *RCoefficient = pow(10, GRRatio);
  *BCoefficient = pow(10, GBRatio);
}


x86 assembly (clang, -O0):
<ColorTemperatureCurve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x80(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1234 <ColorTemperatureCurve+0x114>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1221 <ColorTemperatureCurve+0x101>
mov    -0x28(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    -0x2c(%rbp),%ecx
add    $0x0,%ecx
add    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    -0x2c(%rbp),%ecx
add    $0x2,%ecx
add    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cvtsi2sd %eax,%xmm0
addsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cvtsi2sd %eax,%xmm0
addsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x38(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cvtsi2sd %eax,%xmm0
addsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x2c(%rbp)
jmp    1183 <ColorTemperatureCurve+0x63>
jmp    1226 <ColorTemperatureCurve+0x106>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1170 <ColorTemperatureCurve+0x50>
movsd  -0x78(%rbp),%xmm0
divsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x78(%rbp),%xmm0
divsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x68(%rbp),%xmm0
call   1040 <log10@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
call   1040 <log10@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xd8c(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xd20(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xd1c(%rip),%xmm1
addsd  -0x50(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  0xcf1(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xced(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
mov    $0xa,%edi
call   1030 <pow@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x68(%rbp),%xmm0
mov    $0xa,%edi
call   1030 <pow@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ColorTemperatureCurve>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x20(%rsp)
mov    %rcx,0x18(%rsp)
test   %esi,%esi
jle    11ee <ColorTemperatureCurve+0xce>
movabs $0x300000000,%rax
movslq %r9d,%rcx
mov    %esi,%r8d
mov    %rcx,%r10
shl    $0x20,%r10
xorpd  %xmm1,%xmm1
movabs $0x200000000,%r11
movabs $0x100000000,%r15
xor    %r13d,%r13d
mov    %rdi,%rbx
xorpd  %xmm3,%xmm3
xorpd  %xmm2,%xmm2
jmp    1192 <ColorTemperatureCurve+0x72>
nop
add    $0x1,%r13
add    %r10,%r11
add    %r10,%r15
add    %rcx,%rbx
cmp    %r8,%r13
je     11fa <ColorTemperatureCurve+0xda>
test   %r9d,%r9d
jle    1180 <ColorTemperatureCurve+0x60>
mov    %r15,%r12
mov    %r11,%rsi
xor    %ebp,%ebp
nop
movzbl (%rbx,%rbp,1),%r14d
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
addsd  %xmm0,%xmm1
mov    %r12,%rdx
sar    $0x20,%rdx
movzbl (%rdi,%rdx,1),%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
addsd  %xmm0,%xmm3
mov    %rsi,%rdx
sar    $0x20,%rdx
movzbl (%rdi,%rdx,1),%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
addsd  %xmm0,%xmm2
add    $0x3,%rbp
add    %rax,%rsi
add    %rax,%r12
cmp    %rcx,%rbp
jl     11a0 <ColorTemperatureCurve+0x80>
jmp    1180 <ColorTemperatureCurve+0x60>
xorpd  %xmm2,%xmm2
xorpd  %xmm3,%xmm3
xorpd  %xmm1,%xmm1
movapd %xmm3,%xmm0
divsd  %xmm1,%xmm0
divsd  %xmm2,%xmm3
movsd  %xmm3,0x10(%rsp)
call   1040 <log10@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <log10@plt>
mulsd  0xdd6(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  0xdd0(%rip),%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
divsd  0xdc8(%rip),%xmm1
movsd  0xdc8(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0xa,%edi
movapd %xmm1,%xmm0
call   1030 <pow@plt>
mov    0x18(%rsp),%rax
movsd  %xmm0,(%rax)
mov    $0xa,%edi
movsd  0x8(%rsp),%xmm0
call   1030 <pow@plt>
mov    0x20(%rsp),%rax
movsd  %xmm0,(%rax)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ColorTemperatureCurve(i8* %0, i32 %1, i32 %2, double* %3, double* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca double*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca double
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store double* %3, double** %10
store double* %4, double** %11
store i32 %5, i32* %12
store double 0.000000e+00, double* %22
store double 0.000000e+00, double* %23
store double 0.000000e+00, double* %24
store double 0.000000e+00, double* %25
store double 0.000000e+00, double* %26
store i32 0, i32* %13
br label %27
27: ; preds = %86, %6
%28 = load i32, i32* %13
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %89
31: ; preds = %27
store i32 0, i32* %14
br label %32
32: ; preds = %82, %31
%33 = load i32, i32* %14
%34 = load i32, i32* %12
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %85
36: ; preds = %32
%37 = load i32, i32* %13
%38 = load i32, i32* %12
%39 = mul nsw i32 %37, %38
%40 = load i32, i32* %14
%41 = add nsw i32 %40, 0
%42 = add nsw i32 %39, %41
store i32 %42, i32* %15
%43 = load i32, i32* %13
%44 = load i32, i32* %12
%45 = mul nsw i32 %43, %44
%46 = load i32, i32* %14
%47 = add nsw i32 %46, 1
%48 = add nsw i32 %45, %47
store i32 %48, i32* %16
%49 = load i32, i32* %13
%50 = load i32, i32* %12
%51 = mul nsw i32 %49, %50
%52 = load i32, i32* %14
%53 = add nsw i32 %52, 2
%54 = add nsw i32 %51, %53
store i32 %54, i32* %17
%55 = load i8*, i8** %7
%56 = load i32, i32* %15
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = sitofp i32 %60 to double
%62 = load double, double* %26
%63 = fadd double %62, %61
store double %63, double* %26
%64 = load i8*, i8** %7
%65 = load i32, i32* %16
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = sitofp i32 %69 to double
%71 = load double, double* %25
%72 = fadd double %71, %70
store double %72, double* %25
%73 = load i8*, i8** %7
%74 = load i32, i32* %17
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = sitofp i32 %78 to double
%80 = load double, double* %24
%81 = fadd double %80, %79
store double %81, double* %24
br label %82
82: ; preds = %36
%83 = load i32, i32* %14
%84 = add nsw i32 %83, 3
store i32 %84, i32* %14
br label %32
85: ; preds = %32
br label %86
86: ; preds = %85
%87 = load i32, i32* %13
%88 = add nsw i32 %87, 1
store i32 %88, i32* %13
br label %27
89: ; preds = %27
%90 = load double, double* %25
%91 = load double, double* %26
%92 = fdiv double %90, %91
store double %92, double* %23
%93 = load double, double* %25
%94 = load double, double* %24
%95 = fdiv double %93, %94
store double %95, double* %22
%96 = load double, double* %23
%97 = call double @log10(double %96)
store double %97, double* %23
%98 = load double, double* %22
%99 = call double @log10(double %98)
store double %99, double* %22
%100 = load double, double* %22
store double %100, double* %18
%101 = load double, double* %23
store double %101, double* %19
store double 0x3FEF7C9CAD9AFD8F, double* %20
%102 = load double, double* %19
%103 = load double, double* %20
%104 = load double, double* %18
%105 = fneg double %103
%106 = call double @llvm.fmuladd.f64(double %105, double %104, double %102)
store double %106, double* %21
%107 = load double, double* %21
%108 = fneg double %107
%109 = fadd double %108, 4.258000e-01
%110 = load double, double* %20
%111 = fadd double %110, 1.016300e+00
%112 = fdiv double %109, %111
store double %112, double* %22
%113 = load double, double* %22
%114 = call double @llvm.fmuladd.f64(double -1.016300e+00, double %113, double 4.258000e-01)
store double %114, double* %23
%115 = load double, double* %22
%116 = call double @pow(i32 10, double %115)
%117 = load double*, double** %10
store double %116, double* %117
%118 = load double, double* %23
%119 = call double @pow(i32 10, double %118)
%120 = load double*, double** %11
store double %119, double* %120
ret void
}

LLVM IR (-O2):
define void @ColorTemperatureCurve(i8* nocapture %0, i32 %1, i32 %2, double* nocapture writeonly %3, double* nocapture writeonly %4, i32 %5) {
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %51
8: ; preds = %6
%9 = icmp sgt i32 %5, 0
%10 = sext i32 %5 to i64
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %8, %45
%13 = phi i64 [ 0, %8 ], [ %49, %45 ]
%14 = phi double [ 0.000000e+00, %8 ], [ %48, %45 ]
%15 = phi double [ 0.000000e+00, %8 ], [ %47, %45 ]
%16 = phi double [ 0.000000e+00, %8 ], [ %46, %45 ]
br i1 %9, label %17, label %45
17: ; preds = %12
%18 = mul nsw i64 %13, %10
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %43, %19 ]
%21 = phi double [ %14, %17 ], [ %28, %19 ]
%22 = phi double [ %15, %17 ], [ %35, %19 ]
%23 = phi double [ %16, %17 ], [ %42, %19 ]
%24 = add nsw i64 %20, %18
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = load i8, i8* %25
%27 = uitofp i8 %26 to double
%28 = fadd double %21, %27
%29 = shl i64 %24, 32
%30 = add i64 %29, 4294967296
%31 = ashr exact i64 %30, 32
%32 = getelementptr inbounds i8, i8* %0, i64 %31
%33 = load i8, i8* %32
%34 = uitofp i8 %33 to double
%35 = fadd double %22, %34
%36 = shl i64 %24, 32
%37 = add i64 %36, 8589934592
%38 = ashr exact i64 %37, 32
%39 = getelementptr inbounds i8, i8* %0, i64 %38
%40 = load i8, i8* %39
%41 = uitofp i8 %40 to double
%42 = fadd double %23, %41
%43 = add nuw nsw i64 %20, 3
%44 = icmp slt i64 %43, %10
br i1 %44, label %19, label %45
45: ; preds = %19, %12
%46 = phi double [ %16, %12 ], [ %42, %19 ]
%47 = phi double [ %15, %12 ], [ %35, %19 ]
%48 = phi double [ %14, %12 ], [ %28, %19 ]
%49 = add nuw nsw i64 %13, 1
%50 = icmp eq i64 %49, %11
br i1 %50, label %51, label %12
51: ; preds = %45, %6
%52 = phi double [ 0.000000e+00, %6 ], [ %46, %45 ]
%53 = phi double [ 0.000000e+00, %6 ], [ %47, %45 ]
%54 = phi double [ 0.000000e+00, %6 ], [ %48, %45 ]
%55 = fdiv double %53, %54
%56 = fdiv double %53, %52
%57 = tail call double @log10(double %55)
%58 = tail call double @log10(double %56)
%59 = tail call double @llvm.fmuladd.f64(double %58, double 0xBFEF7C9CAD9AFD8F, double %57)
%60 = fsub double 4.258000e-01, %59
%61 = fdiv double %60, 0x40000089105E2561
%62 = tail call double @llvm.fmuladd.f64(double %61, double -1.016300e+00, double 4.258000e-01)
%63 = tail call double @pow(i32 10, double %61)
store double %63, double* %3
%64 = tail call double @pow(i32 10, double %62)
store double %64, double* %4
ret void
}