#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 MINN(double, int);
double const sq(double);
double sqrt(double const);
double intensity_scaling(double scale, double scale_limit) {
  double ratio = 1., x;
  const double knee_width = 0.25, y_offset = sqrt(1. + knee_width) - 1.;
  if (scale < scale_limit)
    ratio = scale / scale_limit;
  x = scale / scale_limit;
  ratio = sqrt(sq(x - 1.) + knee_width) - x - 1. - y_offset;
  ratio *= -0.5;
  ratio = MINN(ratio, 1.);
  return ratio;
}


x86 assembly (clang, -O0):
<intensity_scaling>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  0xeb6(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeb9(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xea4(%rip),%xmm0
call   1040 <sqrt@plt>
movsd  0xe8f(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    119d <intensity_scaling+0x6d>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe47(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1030 <sq@plt>
movsd  0xe46(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
subsd  -0x20(%rbp),%xmm0
movsd  0xe20(%rip),%xmm1
subsd  %xmm1,%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe22(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    $0x1,%edi
call   1050 <MINN@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intensity_scaling>:
push   %rax
movapd %xmm0,%xmm2
divsd  %xmm1,%xmm2
movsd  0xebf(%rip),%xmm0
movsd  %xmm2,(%rsp)
addsd  %xmm2,%xmm0
call   1030 <sq@plt>
addsd  0xeb1(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1167 <intensity_scaling+0x37>
sqrtsd %xmm0,%xmm0
jmp    116c <intensity_scaling+0x3c>
call   1040 <sqrt@plt>
subsd  (%rsp),%xmm0
addsd  0xe87(%rip),%xmm0
addsd  0xe8f(%rip),%xmm0
mulsd  0xe8f(%rip),%xmm0
mov    $0x1,%edi
pop    %rax
jmp    1050 <MINN@plt>

LLVM IR (-O0):
define double @intensity_scaling(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %3
store double %1, double* %4
store double 1.000000e+00, double* %5
store double 2.500000e-01, double* %7
%9 = call double @sqrt(double 1.250000e+00)
%10 = fsub double %9, 1.000000e+00
store double %10, double* %8
%11 = load double, double* %3
%12 = load double, double* %4
%13 = fcmp olt double %11, %12
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load double, double* %3
%16 = load double, double* %4
%17 = fdiv double %15, %16
store double %17, double* %5
br label %18
18: ; preds = %14, %2
%19 = load double, double* %3
%20 = load double, double* %4
%21 = fdiv double %19, %20
store double %21, double* %6
%22 = load double, double* %6
%23 = fsub double %22, 1.000000e+00
%24 = call double @sq(double %23)
%25 = fadd double %24, 2.500000e-01
%26 = call double @sqrt(double %25)
%27 = load double, double* %6
%28 = fsub double %26, %27
%29 = fsub double %28, 1.000000e+00
%30 = load double, double* %8
%31 = fsub double %29, %30
store double %31, double* %5
%32 = load double, double* %5
%33 = fmul double %32, -5.000000e-01
store double %33, double* %5
%34 = load double, double* %5
%35 = call double @MINN(double %34, i32 1)
store double %35, double* %5
%36 = load double, double* %5
ret double %36
}

LLVM IR (-O2):
define double @intensity_scaling(double %0, double %1) {
%3 = fdiv double %0, %1
%4 = fadd double %3, -1.000000e+00
%5 = tail call double @sq(double %4)
%6 = fadd double %5, 2.500000e-01
%7 = tail call double @sqrt(double %6)
%8 = fsub double %7, %3
%9 = fadd double %8, -1.000000e+00
%10 = fadd double %9, 0xBFBE3779B97F4A80
%11 = fmul double %10, -5.000000e-01
%12 = tail call double @MINN(double %11, i32 1)
ret double %12
}