#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 const log(double const);
double calcBrighness(const double lux, const double min, const double max) {
  double result = min;
  if (lux == 0) {
    return result;
  }
  result = (max - min) * (log(lux) / log(10000)) + min;
  if (result < min) {
    result = min;
  }
  return result;
}


x86 assembly (clang, -O0):
<calcBrighness>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1158 <calcBrighness+0x48>
jp     1158 <calcBrighness+0x48>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ce <calcBrighness+0xbe>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <log@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xe82(%rip),%xmm0
call   1030 <log@plt>
movsd  -0x38(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c4 <calcBrighness+0xb4>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcBrighness>:
movapd %xmm1,%xmm3
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1125 <calcBrighness+0x15>
jp     1125 <calcBrighness+0x15>
movapd %xmm3,%xmm0
ret
sub    $0x18,%rsp
subsd  %xmm3,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  %xmm3,0x10(%rsp)
call   1030 <log@plt>
movsd  0x10(%rsp),%xmm3
divsd  0xeb4(%rip),%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  %xmm3,%xmm0
maxsd  %xmm0,%xmm3
add    $0x18,%rsp
movapd %xmm3,%xmm0
ret

LLVM IR (-O0):
define double @calcBrighness(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%9 = load double, double* %6
store double %9, double* %8
%10 = load double, double* %5
%11 = fcmp oeq double %10, 0.000000e+00
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = load double, double* %8
store double %13, double* %4
br label %31
14: ; preds = %3
%15 = load double, double* %7
%16 = load double, double* %6
%17 = fsub double %15, %16
%18 = load double, double* %5
%19 = call double @log(double %18)
%20 = call double @log(double 1.000000e+04)
%21 = fdiv double %19, %20
%22 = load double, double* %6
%23 = call double @llvm.fmuladd.f64(double %17, double %21, double %22)
store double %23, double* %8
%24 = load double, double* %8
%25 = load double, double* %6
%26 = fcmp olt double %24, %25
br i1 %26, label %27, label %29
27: ; preds = %14
%28 = load double, double* %6
store double %28, double* %8
br label %29
29: ; preds = %27, %14
%30 = load double, double* %8
store double %30, double* %4
br label %31
31: ; preds = %29, %12
%32 = load double, double* %4
ret double %32
}

LLVM IR (-O2):
define double @calcBrighness(double %0, double %1, double %2) {
%4 = fcmp oeq double %0, 0.000000e+00
br i1 %4, label %12, label %5
5: ; preds = %3
%6 = fsub double %2, %1
%7 = tail call double @log(double %0)
%8 = fdiv double %7, 0x40226BB1BBB55516
%9 = tail call double @llvm.fmuladd.f64(double %6, double %8, double %1)
%10 = fcmp olt double %9, %1
%11 = select i1 %10, double %1, double %9
br label %12
12: ; preds = %3, %5
%13 = phi double [ %11, %5 ], [ %1, %3 ]
ret double %13
}