#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 */
int /*<<< orphan*/ BlackBody_to_XYZ(double, double *);
double MAX(int /*<<< orphan*/, double);
int /*<<< orphan*/ MIN(double, double);
int /*<<< orphan*/ XYZ_to_xyY(double *, double *);
int /*<<< orphan*/ xyY_to_XYZ(double *, double *);
void Kelvin_Daylight_to_XYZ(double temperature, double *XYZ_out) {
  double XYZ[3];
  double xyY[3];
  BlackBody_to_XYZ(temperature, XYZ);
  XYZ_to_xyY(XYZ, xyY);
  double y = 2.870 * xyY[0] - 3.000 * xyY[0] * xyY[0] - 0.275;
  double blend_fac = ((temperature - 3800.0) / 500.0);
  blend_fac = MAX(MIN(blend_fac, 1.0), 0.0);
  xyY[1] = xyY[1] * (1.0 - blend_fac) + y * blend_fac;
  xyY_to_XYZ(xyY, XYZ);
  for (int i = 0; i < 3; ++i)
    XYZ_out[i] = XYZ[i];
}


x86 assembly (clang, -O0):
<Kelvin_Daylight_to_XYZ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
lea    -0x30(%rbp),%rdi
call   1070 <BlackBody_to_XYZ@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1060 <XYZ_to_xyY@plt>
movsd  -0x50(%rbp),%xmm0
movsd  0xe9f(%rip),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xe6e(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe56(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe38(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe24(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  0xe06(%rip),%xmm1
call   1030 <MIN@plt>
mov    %eax,%edi
xorps  %xmm0,%xmm0
call   1040 <MAX@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xde5(%rip),%xmm2
subsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
lea    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <xyY_to_XYZ@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0x3,-0x64(%rbp)
jge    127a <Kelvin_Daylight_to_XYZ+0x12a>
movslq -0x64(%rbp),%rax
movsd  -0x30(%rbp,%rax,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    124b <Kelvin_Daylight_to_XYZ+0xfb>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Kelvin_Daylight_to_XYZ>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%rbx
movsd  %xmm0,0x8(%rsp)
lea    0x30(%rsp),%r14
mov    %r14,%rdi
call   1070 <BlackBody_to_XYZ@plt>
lea    0x10(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <XYZ_to_xyY@plt>
movsd  0x10(%rsp),%xmm1
movsd  0xe73(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  0xe6b(%rip),%xmm1
addsd  %xmm0,%xmm1
addsd  0xe67(%rip),%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0xe5c(%rip),%xmm0
divsd  0xe5c(%rip),%xmm0
movsd  0xe5c(%rip),%xmm1
call   1030 <MIN@plt>
xorpd  %xmm0,%xmm0
mov    %eax,%edi
call   1040 <MAX@plt>
movsd  0xe44(%rip),%xmm2
subsd  %xmm0,%xmm2
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
mulsd  0x18(%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x18(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <xyY_to_XYZ@plt>
movaps 0x30(%rsp),%xmm0
movups %xmm0,(%rbx)
mov    0x40(%rsp),%rax
mov    %rax,0x10(%rbx)
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @Kelvin_Daylight_to_XYZ(double %0, double* %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca [3 x double]
%6 = alloca [3 x double]
%7 = alloca double
%8 = alloca double
%9 = alloca i32
store double %0, double* %3
store double* %1, double** %4
%10 = load double, double* %3
%11 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%12 = call i32 @BlackBody_to_XYZ(double %10, double* %11)
%13 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%14 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%15 = call i32 @XYZ_to_xyY(double* %13, double* %14)
%16 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%17 = load double, double* %16
%18 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%19 = load double, double* %18
%20 = fmul double 3.000000e+00, %19
%21 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%22 = load double, double* %21
%23 = fmul double %20, %22
%24 = fneg double %23
%25 = call double @llvm.fmuladd.f64(double 2.870000e+00, double %17, double %24)
%26 = fsub double %25, 2.750000e-01
store double %26, double* %7
%27 = load double, double* %3
%28 = fsub double %27, 3.800000e+03
%29 = fdiv double %28, 5.000000e+02
store double %29, double* %8
%30 = load double, double* %8
%31 = call i32 @MIN(double %30, double 1.000000e+00)
%32 = call double @MAX(i32 %31, double 0.000000e+00)
store double %32, double* %8
%33 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 1
%34 = load double, double* %33
%35 = load double, double* %8
%36 = fsub double 1.000000e+00, %35
%37 = load double, double* %7
%38 = load double, double* %8
%39 = fmul double %37, %38
%40 = call double @llvm.fmuladd.f64(double %34, double %36, double %39)
%41 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 1
store double %40, double* %41
%42 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%43 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%44 = call i32 @xyY_to_XYZ(double* %42, double* %43)
store i32 0, i32* %9
br label %45
45: ; preds = %57, %2
%46 = load i32, i32* %9
%47 = icmp slt i32 %46, 3
br i1 %47, label %48, label %60
48: ; preds = %45
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 %50
%52 = load double, double* %51
%53 = load double*, double** %4
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
store double %52, double* %56
br label %57
57: ; preds = %48
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %45
60: ; preds = %45
ret void
}

LLVM IR (-O2):
define void @Kelvin_Daylight_to_XYZ(double %0, double* nocapture writeonly %1) {
%3 = bitcast double* %1 to i8*
%4 = alloca [3 x double]
%5 = bitcast [3 x double]* %4 to i8*
%6 = alloca [3 x double]
%7 = bitcast [3 x double]* %6 to i8*
%8 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%9 = call i32 @BlackBody_to_XYZ(double %0, double* %8)
%10 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%11 = call i32 @XYZ_to_xyY(double* %8, double* %10)
%12 = load double, double* %10
%13 = fmul double %12, -3.000000e+00
%14 = fmul double %12, %13
%15 = call double @llvm.fmuladd.f64(double %12, double 2.870000e+00, double %14)
%16 = fadd double %15, -2.750000e-01
%17 = fadd double %0, -3.800000e+03
%18 = fdiv double %17, 5.000000e+02
%19 = call i32 @MIN(double %18, double 1.000000e+00)
%20 = call double @MAX(i32 %19, double 0.000000e+00)
%21 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 1
%22 = load double, double* %21
%23 = fsub double 1.000000e+00, %20
%24 = fmul double %20, %16
%25 = call double @llvm.fmuladd.f64(double %22, double %23, double %24)
store double %25, double* %21
%26 = call i32 @xyY_to_XYZ(double* %10, double* %8)
ret void
}