#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*/ floor(double);
double min(double, int /*<<< orphan*/);
double b_flat(double y, double A, double B, double C) {
  double tmp1 = min(0.0, floor(y - B)) * A * (B - y) / B;
  double tmp2 = min(0.0, floor(C - y)) * (1.0 - A) * (y - C) / (1.0 - C);
  double result = A + tmp1 - tmp2;
  if (result > 1)
    result = 1;
  if (result < 0)
    result = 0;
  return result;
}


x86 assembly (clang, -O0):
<b_flat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
call   1040 <floor@plt>
mov    %eax,%edi
xorps  %xmm0,%xmm0
call   1030 <min@plt>
mulsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
call   1040 <floor@plt>
mov    %eax,%edi
xorps  %xmm0,%xmm0
call   1030 <min@plt>
movsd  0xe6d(%rip),%xmm1
subsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x8(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe4e(%rip),%xmm1
subsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe1f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11f8 <b_flat+0xd8>
movsd  0xe0d(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    120e <b_flat+0xee>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b_flat>:
sub    $0x58,%rsp
movaps %xmm3,0x10(%rsp)
movapd %xmm2,0x40(%rsp)
movaps %xmm1,0x30(%rsp)
movapd %xmm0,(%rsp)
subsd  %xmm2,%xmm0
call   1040 <floor@plt>
xorpd  %xmm0,%xmm0
mov    %eax,%edi
call   1030 <min@plt>
movapd %xmm0,0x20(%rsp)
movapd 0x10(%rsp),%xmm0
subsd  (%rsp),%xmm0
call   1040 <floor@plt>
xorpd  %xmm0,%xmm0
mov    %eax,%edi
call   1030 <min@plt>
movsd  0xe8a(%rip),%xmm1
movapd %xmm1,%xmm2
movapd 0x30(%rsp),%xmm3
subsd  %xmm3,%xmm2
movapd 0x20(%rsp),%xmm4
unpcklpd %xmm2,%xmm4
movapd %xmm3,%xmm2
unpcklpd %xmm0,%xmm2
mulpd  %xmm4,%xmm2
movapd 0x40(%rsp),%xmm4
movapd %xmm4,%xmm0
movapd (%rsp),%xmm6
unpcklpd %xmm6,%xmm0
movapd 0x10(%rsp),%xmm5
unpcklpd %xmm5,%xmm6
subpd  %xmm6,%xmm0
mulpd  %xmm2,%xmm0
movapd %xmm1,%xmm2
subsd  %xmm5,%xmm2
unpcklpd %xmm2,%xmm4
divpd  %xmm4,%xmm0
addsd  %xmm0,%xmm3
unpckhpd %xmm0,%xmm0
subsd  %xmm0,%xmm3
minsd  %xmm3,%xmm1
xorpd  %xmm0,%xmm0
maxsd  %xmm1,%xmm0
add    $0x58,%rsp
ret

LLVM IR (-O0):
define double @b_flat(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%12 = load double, double* %5
%13 = load double, double* %7
%14 = fsub double %12, %13
%15 = call i32 @floor(double %14)
%16 = call double @min(double 0.000000e+00, i32 %15)
%17 = load double, double* %6
%18 = fmul double %16, %17
%19 = load double, double* %7
%20 = load double, double* %5
%21 = fsub double %19, %20
%22 = fmul double %18, %21
%23 = load double, double* %7
%24 = fdiv double %22, %23
store double %24, double* %9
%25 = load double, double* %8
%26 = load double, double* %5
%27 = fsub double %25, %26
%28 = call i32 @floor(double %27)
%29 = call double @min(double 0.000000e+00, i32 %28)
%30 = load double, double* %6
%31 = fsub double 1.000000e+00, %30
%32 = fmul double %29, %31
%33 = load double, double* %5
%34 = load double, double* %8
%35 = fsub double %33, %34
%36 = fmul double %32, %35
%37 = load double, double* %8
%38 = fsub double 1.000000e+00, %37
%39 = fdiv double %36, %38
store double %39, double* %10
%40 = load double, double* %6
%41 = load double, double* %9
%42 = fadd double %40, %41
%43 = load double, double* %10
%44 = fsub double %42, %43
store double %44, double* %11
%45 = load double, double* %11
%46 = fcmp ogt double %45, 1.000000e+00
br i1 %46, label %47, label %48
47: ; preds = %4
store double 1.000000e+00, double* %11
br label %48
48: ; preds = %47, %4
%49 = load double, double* %11
%50 = fcmp olt double %49, 0.000000e+00
br i1 %50, label %51, label %52
51: ; preds = %48
store double 0.000000e+00, double* %11
br label %52
52: ; preds = %51, %48
%53 = load double, double* %11
ret double %53
}

LLVM IR (-O2):
define double @b_flat(double %0, double %1, double %2, double %3) {
%5 = fsub double %0, %2
%6 = tail call i32 @floor(double %5)
%7 = tail call double @min(double 0.000000e+00, i32 %6)
%8 = fsub double %3, %0
%9 = tail call i32 @floor(double %8)
%10 = tail call double @min(double 0.000000e+00, i32 %9)
%11 = fsub double 1.000000e+00, %1
%12 = insertelement <2 x double> poison, double %7, i64 0
%13 = insertelement <2 x double> %12, double %11, i64 1
%14 = insertelement <2 x double> poison, double %1, i64 0
%15 = insertelement <2 x double> %14, double %10, i64 1
%16 = fmul <2 x double> %13, %15
%17 = insertelement <2 x double> poison, double %2, i64 0
%18 = insertelement <2 x double> %17, double %0, i64 1
%19 = insertelement <2 x double> poison, double %0, i64 0
%20 = insertelement <2 x double> %19, double %3, i64 1
%21 = fsub <2 x double> %18, %20
%22 = fmul <2 x double> %21, %16
%23 = fsub double 1.000000e+00, %3
%24 = insertelement <2 x double> %17, double %23, i64 1
%25 = fdiv <2 x double> %22, %24
%26 = extractelement <2 x double> %25, i64 0
%27 = fadd double %26, %1
%28 = extractelement <2 x double> %25, i64 1
%29 = fsub double %27, %28
%30 = fcmp ogt double %29, 1.000000e+00
%31 = select i1 %30, double 1.000000e+00, double %29
%32 = fcmp olt double %31, 0.000000e+00
%33 = select i1 %32, double 0.000000e+00, double %31
ret double %33
}