DISCRETE_STEP(dst_xtime_buffer) {
  int in0 = (int)DISCRETE_INPUT(0);
  int out = in0;
  int out_is_energy = 1;
  double x_time = DISCRETE_INPUT(0) - in0;
  double out_low = DISCRETE_INPUT(1);
  double out_high = DISCRETE_INPUT(2);
  if (out_low == 0 && out_high == 0)
    out_is_energy = 0;
  if (DISCRETE_INPUT(3) != 0)
    out ^= 1;
  if (out_is_energy) {
    if (x_time > 0) {
      double diff = out_high - out_low;
      diff = out ? diff * x_time : diff * (1.0 - x_time);
      set_output(0, out_low + diff);
    } else
      set_output(0, out ? out_high : out_low);
  } else
    set_output(0, out + x_time);
}


x86 assembly (clang, -O0):
<DISCRETE_STEP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
xor    %edi,%edi
mov    $0x0,%al
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
xor    %edi,%edi
mov    $0x0,%al
call   1030 <DISCRETE_INPUT@plt>
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x1,%edi
mov    $0x0,%al
call   1030 <DISCRETE_INPUT@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x2,%edi
mov    $0x0,%al
call   1030 <DISCRETE_INPUT@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ba <DISCRETE_STEP+0x9a>
jp     11ba <DISCRETE_STEP+0x9a>
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ba <DISCRETE_STEP+0x9a>
jp     11ba <DISCRETE_STEP+0x9a>
movl   $0x0,-0x14(%rbp)
mov    $0x3,%edi
mov    $0x0,%al
call   1030 <DISCRETE_INPUT@plt>
cmp    $0x0,%eax
je     11d8 <DISCRETE_STEP+0xb8>
mov    -0x10(%rbp),%eax
xor    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1294 <DISCRETE_STEP+0x174>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    125e <DISCRETE_STEP+0x13e>
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1221 <DISCRETE_STEP+0x101>
movsd  -0x38(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    123c <DISCRETE_STEP+0x11c>
movsd  -0x38(%rbp),%xmm0
movsd  0xdd2(%rip),%xmm1
subsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
xor    %edi,%edi
mov    $0x1,%al
call   1040 <set_output@plt>
jmp    128f <DISCRETE_STEP+0x16f>
cmpl   $0x0,-0x10(%rbp)
je     1277 <DISCRETE_STEP+0x157>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    1281 <DISCRETE_STEP+0x161>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
xor    %edi,%edi
mov    $0x1,%al
call   1040 <set_output@plt>
jmp    12a7 <DISCRETE_STEP+0x187>
cvtsi2sdl -0x10(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
xor    %edi,%edi
mov    $0x1,%al
call   1040 <set_output@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DISCRETE_STEP>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
xor    %eax,%eax
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,%r15d
xor    %edi,%edi
xor    %eax,%eax
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,%ebx
sub    %r15d,%ebx
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,(%rsp)
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,%r14d
mov    $0x2,%edi
xor    %eax,%eax
call   1030 <DISCRETE_INPUT@plt>
mov    %eax,%ebp
mov    $0x3,%edi
xor    %eax,%eax
call   1030 <DISCRETE_INPUT@plt>
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
xor    %r15d,%ecx
mov    %r14d,%eax
or     %ebp,%eax
jne    119a <DISCRETE_STEP+0x7a>
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    11db <DISCRETE_STEP+0xbb>
movsd  (%rsp),%xmm3
cvtsi2sd %r14d,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
test   %ebx,%ebx
jle    11bd <DISCRETE_STEP+0x9d>
subsd  %xmm1,%xmm0
test   %ecx,%ecx
je     11c7 <DISCRETE_STEP+0xa7>
movapd %xmm3,%xmm2
jmp    11d3 <DISCRETE_STEP+0xb3>
test   %ecx,%ecx
je     1194 <DISCRETE_STEP+0x74>
movapd %xmm0,%xmm1
jmp    1194 <DISCRETE_STEP+0x74>
movsd  0xe31(%rip),%xmm2
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
xor    %edi,%edi
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <set_output@plt>

LLVM IR (-O0):
define i32 @DISCRETE_STEP(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i32 %0, i32* %3
%11 = call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 0)
store i32 %11, i32* %4
%12 = load i32, i32* %4
store i32 %12, i32* %5
store i32 1, i32* %6
%13 = call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 0)
%14 = load i32, i32* %4
%15 = sub nsw i32 %13, %14
%16 = sitofp i32 %15 to double
store double %16, double* %7
%17 = call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 1)
%18 = sitofp i32 %17 to double
store double %18, double* %8
%19 = call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 2)
%20 = sitofp i32 %19 to double
store double %20, double* %9
%21 = load double, double* %8
%22 = fcmp oeq double %21, 0.000000e+00
br i1 %22, label %23, label %27
23: ; preds = %1
%24 = load double, double* %9
%25 = fcmp oeq double %24, 0.000000e+00
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 0, i32* %6
br label %27
27: ; preds = %26, %23, %1
%28 = call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 3)
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* %5
%32 = xor i32 %31, 1
store i32 %32, i32* %5
br label %33
33: ; preds = %30, %27
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %71
36: ; preds = %33
%37 = load double, double* %7
%38 = fcmp ogt double %37, 0.000000e+00
br i1 %38, label %39, label %60
39: ; preds = %36
%40 = load double, double* %9
%41 = load double, double* %8
%42 = fsub double %40, %41
store double %42, double* %10
%43 = load i32, i32* %5
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %39
%46 = load double, double* %10
%47 = load double, double* %7
%48 = fmul double %46, %47
br label %54
49: ; preds = %39
%50 = load double, double* %10
%51 = load double, double* %7
%52 = fsub double 1.000000e+00, %51
%53 = fmul double %50, %52
br label %54
54: ; preds = %49, %45
%55 = phi double [ %48, %45 ], [ %53, %49 ]
store double %55, double* %10
%56 = load double, double* %8
%57 = load double, double* %10
%58 = fadd double %56, %57
%59 = call i32 (i32, double, ...) bitcast (i32 (...)* @set_output to i32 (i32, double, ...)*)(i32 0, double %58)
br label %70
60: ; preds = %36
%61 = load i32, i32* %5
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = load double, double* %9
br label %67
65: ; preds = %60
%66 = load double, double* %8
br label %67
67: ; preds = %65, %63
%68 = phi double [ %64, %63 ], [ %66, %65 ]
%69 = call i32 (i32, double, ...) bitcast (i32 (...)* @set_output to i32 (i32, double, ...)*)(i32 0, double %68)
br label %70
70: ; preds = %67, %54
br label %77
71: ; preds = %33
%72 = load i32, i32* %5
%73 = sitofp i32 %72 to double
%74 = load double, double* %7
%75 = fadd double %73, %74
%76 = call i32 (i32, double, ...) bitcast (i32 (...)* @set_output to i32 (i32, double, ...)*)(i32 0, double %75)
br label %77
77: ; preds = %71, %70
%78 = load i32, i32* %2
ret i32 %78
}

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 0)
%4 = sub nsw i32 %3, %2
%5 = sitofp i32 %4 to double
%6 = tail call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 1)
%7 = sitofp i32 %6 to double
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 2)
%9 = sitofp i32 %8 to double
%10 = icmp eq i32 %6, 0
%11 = icmp eq i32 %8, 0
%12 = select i1 %10, i1 %11, i1 false
%13 = tail call i32 (i32, ...) bitcast (i32 (...)* @DISCRETE_INPUT to i32 (i32, ...)*)(i32 3)
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i32
%16 = xor i32 %2, %15
br i1 %12, label %29, label %17
17: ; preds = %1
%18 = icmp sgt i32 %4, 0
br i1 %18, label %19, label %26
19: ; preds = %17
%20 = fsub double %9, %7
%21 = icmp eq i32 %16, 0
%22 = fsub double 1.000000e+00, %5
%23 = select i1 %21, double %22, double %5
%24 = fmul double %20, %23
%25 = fadd double %24, %7
br label %32
26: ; preds = %17
%27 = icmp eq i32 %16, 0
%28 = select i1 %27, double %7, double %9
br label %32
29: ; preds = %1
%30 = sitofp i32 %16 to double
%31 = fadd double %5, %30
br label %32
32: ; preds = %19, %26, %29
%33 = phi double [ %25, %19 ], [ %28, %26 ], [ %31, %29 ]
%34 = tail call i32 (i32, double, ...) bitcast (i32 (...)* @set_output to i32 (i32, double, ...)*)(i32 0, double %33)
ret i32 undef
}