DISCRETE_STEP(dst_clamp) {
  if (DISCRETE_INPUT(0) < DISCRETE_INPUT(1))
    set_output(0, DISCRETE_INPUT(1));
  else if (DISCRETE_INPUT(0) > DISCRETE_INPUT(2))
    set_output(0, DISCRETE_INPUT(2));
  else
    set_output(0, DISCRETE_INPUT(0));
}


x86 assembly (clang, -O0):
<DISCRETE_STEP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
xor    %edi,%edi
mov    $0x0,%al
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,-0xc(%rbp)
mov    $0x1,%edi
mov    $0x0,%al
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
cmp    %ecx,%eax
jge    116c <DISCRETE_STEP+0x4c>
mov    $0x1,%edi
mov    $0x0,%al
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,%esi
xor    %edi,%edi
mov    $0x0,%al
call   1040 <set_output@plt>
jmp    11c6 <DISCRETE_STEP+0xa6>
xor    %edi,%edi
mov    $0x0,%al
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,-0x10(%rbp)
mov    $0x2,%edi
mov    $0x0,%al
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jle    11ad <DISCRETE_STEP+0x8d>
mov    $0x2,%edi
mov    $0x0,%al
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,%esi
xor    %edi,%edi
mov    $0x0,%al
call   1040 <set_output@plt>
jmp    11c1 <DISCRETE_STEP+0xa1>
xor    %edi,%edi
mov    $0x0,%al
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,%esi
xor    %edi,%edi
mov    $0x0,%al
call   1040 <set_output@plt>
jmp    11c6 <DISCRETE_STEP+0xa6>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DISCRETE_STEP>:
push   %rbp
push   %rbx
push   %rax
xor    %edi,%edi
xor    %eax,%eax
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,%ebp
mov    $0x1,%ebx
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <DISCRETE_INPUT@plt>
cmp    %eax,%ebp
jl     1163 <DISCRETE_STEP+0x43>
xor    %edi,%edi
xor    %eax,%eax
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,%ebp
mov    $0x2,%edi
xor    %eax,%eax
call   1030 <DISCRETE_INPUT@plt>
xor    %ebx,%ebx
cmp    %eax,%ebp
setg   %bl
add    %ebx,%ebx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <DISCRETE_INPUT@plt>
xor    %edi,%edi
mov    %eax,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <set_output@plt>

LLVM IR (-O0):
define i32 @DISCRETE_STEP(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 0)
%5 = call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 1)
%6 = icmp slt i32 %4, %5
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 1)
%9 = call i32 (i32, i32, ...) bitcast (i32 (...)* @set_output to i32 (i32, i32, ...)*)(i32 0, i32 %8)
br label %21
10: ; preds = %1
%11 = call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 0)
%12 = call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 2)
%13 = icmp sgt i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 2)
%16 = call i32 (i32, i32, ...) bitcast (i32 (...)* @set_output to i32 (i32, i32, ...)*)(i32 0, i32 %15)
br label %20
17: ; preds = %10
%18 = call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 0)
%19 = call i32 (i32, i32, ...) bitcast (i32 (...)* @set_output to i32 (i32, i32, ...)*)(i32 0, i32 %18)
br label %20
20: ; preds = %17, %14
br label %21
21: ; preds = %20, %7
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
define i32 @DISCRETE_STEP(i32 %0) {
%2 = tail call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 0)
%3 = tail call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 1)
%4 = icmp slt i32 %2, %3
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = tail call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 0)
%7 = tail call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 2)
%8 = icmp sgt i32 %6, %7
%9 = select i1 %8, i32 2, i32 0
br label %10
10: ; preds = %5, %1
%11 = phi i32 [ 1, %1 ], [ %9, %5 ]
%12 = tail call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 %11)
%13 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @set_output to i32 (i32, i32, ...)*)(i32 0, i32 %12)
ret i32 undef
}