#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*/ assert(int /*<<< orphan*/);
double blend_weight(double x, int deriv) {
  double x2 = x * x;
  if (x2 >= 1.0)
    return deriv == 0 && x > 0.0 ? 1.0 : 0.0;
  switch (deriv) {
  case 0:
    return ((3.0 * x2 - 10.0) * x2 + 15.0) * x / 16.0 + 0.5;
  case 1:
    return ((x2 - 2.0) * x2 + 1.0) * (15.0 / 16.0);
  case 2:
    return (x2 - 1.0) * x * (15.0 / 4.0);
  }
  assert(0);
}


x86 assembly (clang, -O0):
<blend_weight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xec4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11a0 <blend_weight+0x90>
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x21(%rbp)
jne    1167 <blend_weight+0x57>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
movsd  0xe8e(%rip),%xmm0
xorps  %xmm1,%xmm1
movsd  %xmm1,-0x38(%rbp)
test   $0x1,%al
movsd  %xmm0,-0x30(%rbp)
jne    1191 <blend_weight+0x81>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    129d <blend_weight+0x18d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
test   %eax,%eax
je     11d5 <blend_weight+0xc5>
jmp    11b3 <blend_weight+0xa3>
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
je     122e <blend_weight+0x11e>
jmp    11c4 <blend_weight+0xb4>
mov    -0x3c(%rbp),%eax
sub    $0x2,%eax
je     126a <blend_weight+0x15a>
jmp    1296 <blend_weight+0x186>
movsd  -0x20(%rbp),%xmm0
movsd  0xe56(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe52(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe2d(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xe14(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe00(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    129d <blend_weight+0x18d>
movsd  -0x20(%rbp),%xmm0
movsd  0xddd(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdb0(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xdb4(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    129d <blend_weight+0x18d>
movsd  -0x20(%rbp),%xmm0
movsd  0xd89(%rip),%xmm1
subsd  %xmm1,%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xd80(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    129d <blend_weight+0x18d>
xor    %edi,%edi
call   1030 <assert@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blend_weight>:
push   %rax
movapd %xmm0,%xmm1
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
ucomisd 0xedb(%rip),%xmm2
jae    116f <blend_weight+0x5f>
cmp    $0x2,%edi
je     1190 <blend_weight+0x80>
cmp    $0x1,%edi
je     11aa <blend_weight+0x9a>
test   %edi,%edi
jne    11cc <blend_weight+0xbc>
movsd  0xee7(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xee3(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xedf(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  0xedb(%rip),%xmm0
addsd  0xedb(%rip),%xmm0
pop    %rax
ret
xorpd  %xmm0,%xmm0
test   %edi,%edi
je     117d <blend_weight+0x6d>
xorpd  %xmm2,%xmm2
jmp    1185 <blend_weight+0x75>
movsd  0xe7b(%rip),%xmm2
cmpltsd %xmm1,%xmm0
andpd  %xmm2,%xmm0
pop    %rax
ret
addsd  0xe70(%rip),%xmm2
mulsd  %xmm1,%xmm2
mulsd  0xe6c(%rip),%xmm2
movapd %xmm2,%xmm0
pop    %rax
ret
movsd  0xe66(%rip),%xmm0
addsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm0
addsd  0xe3e(%rip),%xmm0
mulsd  0xe56(%rip),%xmm0
pop    %rax
ret
xor    %edi,%edi
call   1030 <assert@plt>
pop    %rax
ret

LLVM IR (-O0):
define double @blend_weight(double %0, i32 %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca double
store double %0, double* %4
store i32 %1, i32* %5
%7 = load double, double* %4
%8 = load double, double* %4
%9 = fmul double %7, %8
store double %9, double* %6
%10 = load double, double* %6
%11 = fcmp oge double %10, 1.000000e+00
br i1 %11, label %12, label %22
12: ; preds = %2
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load double, double* %4
%17 = fcmp ogt double %16, 0.000000e+00
br label %18
18: ; preds = %15, %12
%19 = phi i1 [ false, %12 ], [ %17, %15 ]
%20 = zext i1 %19 to i64
%21 = select i1 %19, double 1.000000e+00, double 0.000000e+00
store double %21, double* %3
br label %47
22: ; preds = %2
%23 = load i32, i32* %5
switch i32 %23, label %45 [
i32 0, label %24
i32 1, label %33
i32 2, label %39
]
24: ; preds = %22
%25 = load double, double* %6
%26 = call double @llvm.fmuladd.f64(double 3.000000e+00, double %25, double -1.000000e+01)
%27 = load double, double* %6
%28 = call double @llvm.fmuladd.f64(double %26, double %27, double 1.500000e+01)
%29 = load double, double* %4
%30 = fmul double %28, %29
%31 = fdiv double %30, 1.600000e+01
%32 = fadd double %31, 5.000000e-01
store double %32, double* %3
br label %47
33: ; preds = %22
%34 = load double, double* %6
%35 = fsub double %34, 2.000000e+00
%36 = load double, double* %6
%37 = call double @llvm.fmuladd.f64(double %35, double %36, double 1.000000e+00)
%38 = fmul double %37, 9.375000e-01
store double %38, double* %3
br label %47
39: ; preds = %22
%40 = load double, double* %6
%41 = fsub double %40, 1.000000e+00
%42 = load double, double* %4
%43 = fmul double %41, %42
%44 = fmul double %43, 3.750000e+00
store double %44, double* %3
br label %47
45: ; preds = %22
%46 = call i32 @assert(i32 0)
br label %47
47: ; preds = %45, %39, %33, %24, %18
%48 = load double, double* %3
ret double %48
}

LLVM IR (-O2):
define double @blend_weight(double %0, i32 %1) {
%3 = fmul double %0, %0
%4 = fcmp ult double %3, 1.000000e+00
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = icmp eq i32 %1, 0
%7 = fcmp ogt double %0, 0.000000e+00
%8 = and i1 %7, %6
%9 = select i1 %8, double 1.000000e+00, double 0.000000e+00
br label %27
10: ; preds = %2
switch i32 %1, label %25 [
i32 0, label %11
i32 1, label %17
i32 2, label %21
]
11: ; preds = %10
%12 = tail call double @llvm.fmuladd.f64(double %3, double 3.000000e+00, double -1.000000e+01)
%13 = tail call double @llvm.fmuladd.f64(double %12, double %3, double 1.500000e+01)
%14 = fmul double %13, %0
%15 = fmul double %14, 6.250000e-02
%16 = fadd double %15, 5.000000e-01
br label %27
17: ; preds = %10
%18 = fadd double %3, -2.000000e+00
%19 = tail call double @llvm.fmuladd.f64(double %18, double %3, double 1.000000e+00)
%20 = fmul double %19, 9.375000e-01
br label %27
21: ; preds = %10
%22 = fadd double %3, -1.000000e+00
%23 = fmul double %22, %0
%24 = fmul double %23, 3.750000e+00
br label %27
25: ; preds = %10
%26 = tail call i32 @assert(i32 0)
br label %27
27: ; preds = %25, %21, %17, %11, %5
%28 = phi double [ %9, %5 ], [ undef, %25 ], [ %24, %21 ], [ %20, %17 ], [ %16, %11 ]
ret double %28
}