#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 */
float clamp(float, float, float);
float step(float, float);
float linearstep(float edge0, float edge1, float x) {
  float result;
  if (edge0 != edge1) {
    float xclamped = clamp(x, edge0, edge1);
    result = (xclamped - edge0) / (edge1 - edge0);
  } else {
    result = step(edge0, x);
  }
  return result;
}


x86 assembly (clang, -O0):
<linearstep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  -0x4(%rbp),%xmm0
ucomiss -0x8(%rbp),%xmm0
jne    1151 <linearstep+0x31>
jp     1151 <linearstep+0x31>
jmp    118c <linearstep+0x6c>
movss  -0xc(%rbp),%xmm0
movss  -0x4(%rbp),%xmm1
movss  -0x8(%rbp),%xmm2
call   1030 <clamp@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
subss  -0x4(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
subss  -0x4(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    11a0 <linearstep+0x80>
movss  -0x4(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
call   1040 <step@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linearstep>:
movaps %xmm1,%xmm3
movaps %xmm0,%xmm1
ucomiss %xmm3,%xmm0
jne    112d <linearstep+0xd>
jnp    115d <linearstep+0x3d>
push   %rax
movaps %xmm2,%xmm0
movss  %xmm1,(%rsp)
movaps %xmm3,%xmm2
movss  %xmm3,0x4(%rsp)
call   1030 <clamp@plt>
movss  (%rsp),%xmm2
subss  %xmm2,%xmm0
movss  0x4(%rsp),%xmm1
subss  %xmm2,%xmm1
divss  %xmm1,%xmm0
pop    %rax
ret
movaps %xmm1,%xmm0
movaps %xmm2,%xmm1
jmp    1040 <step@plt>

LLVM IR (-O0):
define float @linearstep(float %0, float %1, float %2) {
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
store float %0, float* %4
store float %1, float* %5
store float %2, float* %6
%9 = load float, float* %4
%10 = load float, float* %5
%11 = fcmp une float %9, %10
br i1 %11, label %12, label %24
12: ; preds = %3
%13 = load float, float* %6
%14 = load float, float* %4
%15 = load float, float* %5
%16 = call float @clamp(float %13, float %14, float %15)
store float %16, float* %8
%17 = load float, float* %8
%18 = load float, float* %4
%19 = fsub float %17, %18
%20 = load float, float* %5
%21 = load float, float* %4
%22 = fsub float %20, %21
%23 = fdiv float %19, %22
store float %23, float* %7
br label %28
24: ; preds = %3
%25 = load float, float* %4
%26 = load float, float* %6
%27 = call float @step(float %25, float %26)
store float %27, float* %7
br label %28
28: ; preds = %24, %12
%29 = load float, float* %7
ret float %29
}

LLVM IR (-O2):
define float @linearstep(float %0, float %1, float %2) {
%4 = fcmp une float %0, %1
br i1 %4, label %5, label %10
5: ; preds = %3
%6 = tail call float @clamp(float %2, float %0, float %1)
%7 = fsub float %6, %0
%8 = fsub float %1, %0
%9 = fdiv float %7, %8
br label %12
10: ; preds = %3
%11 = tail call float @step(float %0, float %2)
br label %12
12: ; preds = %10, %5
%13 = phi float [ %9, %5 ], [ %11, %10 ]
ret float %13
}