#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 floor(float);
float integral(float, float);
float filteredPulseTrain(float edge, float period, float x, float dx) {
  float invPeriod = 1.0 / period;
  float w = dx * invPeriod;
  float x0 = x * invPeriod - 0.5 * w;
  float x1 = x0 + w;
  float nedge = edge * invPeriod;
  float result;
  if (x0 == x1) {
    result = (x0 - floor(x0) < nedge) ? 0.0 : 1.0;
  } else {
    result = (integral(x1, nedge) - integral(x0, nedge)) / w;
  }
  return result;
}


x86 assembly (clang, -O0):
<filteredPulseTrain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xebb(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe78(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x1c(%rbp),%xmm0
ucomiss -0x20(%rbp),%xmm0
jne    1229 <filteredPulseTrain+0x109>
jp     1229 <filteredPulseTrain+0x109>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x1c(%rbp),%xmm0
call   1040 <floor@plt>
movss  -0x3c(%rbp),%xmm2
subss  %xmm0,%xmm2
movss  -0x24(%rbp),%xmm1
xorps  %xmm0,%xmm0
movsd  0xe0f(%rip),%xmm3
movsd  %xmm3,-0x38(%rbp)
ucomiss %xmm2,%xmm1
movsd  %xmm0,-0x30(%rbp)
ja     1216 <filteredPulseTrain+0xf6>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
jmp    1262 <filteredPulseTrain+0x142>
movss  -0x20(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
call   1030 <integral@plt>
movss  %xmm0,-0x40(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
call   1030 <integral@plt>
movaps %xmm0,%xmm1
movss  -0x40(%rbp),%xmm0
subss  %xmm1,%xmm0
divss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filteredPulseTrain>:
sub    $0x28,%rsp
movaps %xmm0,%xmm4
movss  0xed1(%rip),%xmm5
divss  %xmm1,%xmm5
mulss  %xmm5,%xmm3
mulss  %xmm5,%xmm2
xorps  %xmm0,%xmm0
cvtss2sd %xmm3,%xmm0
mulsd  0xebe(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
addsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
movaps %xmm3,%xmm0
addss  %xmm1,%xmm0
mulss  %xmm4,%xmm5
ucomiss %xmm1,%xmm0
movaps %xmm1,0x10(%rsp)
movss  %xmm5,0x4(%rsp)
jne    119e <filteredPulseTrain+0x7e>
jp     119e <filteredPulseTrain+0x7e>
movaps %xmm1,%xmm0
call   1040 <floorf@plt>
movaps 0x10(%rsp),%xmm1
subss  %xmm0,%xmm1
cmpltss 0x4(%rsp),%xmm1
movss  0xe67(%rip),%xmm0
andnps %xmm0,%xmm1
jmp    11d2 <filteredPulseTrain+0xb2>
movaps %xmm5,%xmm1
movss  %xmm3,0xc(%rsp)
call   1030 <integral@plt>
movss  %xmm0,0x8(%rsp)
movaps 0x10(%rsp),%xmm0
movss  0x4(%rsp),%xmm1
call   1030 <integral@plt>
movss  0x8(%rsp),%xmm1
subss  %xmm0,%xmm1
divss  0xc(%rsp),%xmm1
movaps %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define float @filteredPulseTrain(float %0, float %1, float %2, float %3) {
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca float
store float %0, float* %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%15 = load float, float* %6
%16 = fpext float %15 to double
%17 = fdiv double 1.000000e+00, %16
%18 = fptrunc double %17 to float
store float %18, float* %9
%19 = load float, float* %8
%20 = load float, float* %9
%21 = fmul float %19, %20
store float %21, float* %10
%22 = load float, float* %7
%23 = load float, float* %9
%24 = fmul float %22, %23
%25 = fpext float %24 to double
%26 = load float, float* %10
%27 = fpext float %26 to double
%28 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %27, double %25)
%29 = fptrunc double %28 to float
store float %29, float* %11
%30 = load float, float* %11
%31 = load float, float* %10
%32 = fadd float %30, %31
store float %32, float* %12
%33 = load float, float* %5
%34 = load float, float* %9
%35 = fmul float %33, %34
store float %35, float* %13
%36 = load float, float* %11
%37 = load float, float* %12
%38 = fcmp oeq float %36, %37
br i1 %38, label %39, label %49
39: ; preds = %4
%40 = load float, float* %11
%41 = load float, float* %11
%42 = call float @floor(float %41)
%43 = fsub float %40, %42
%44 = load float, float* %13
%45 = fcmp olt float %43, %44
%46 = zext i1 %45 to i64
%47 = select i1 %45, double 0.000000e+00, double 1.000000e+00
%48 = fptrunc double %47 to float
store float %48, float* %14
br label %59
49: ; preds = %4
%50 = load float, float* %12
%51 = load float, float* %13
%52 = call float @integral(float %50, float %51)
%53 = load float, float* %11
%54 = load float, float* %13
%55 = call float @integral(float %53, float %54)
%56 = fsub float %52, %55
%57 = load float, float* %10
%58 = fdiv float %56, %57
store float %58, float* %14
br label %59
59: ; preds = %49, %39
%60 = load float, float* %14
ret float %60
}

LLVM IR (-O2):
define float @filteredPulseTrain(float %0, float %1, float %2, float %3) {
%5 = fdiv float 1.000000e+00, %1
%6 = fmul float %5, %3
%7 = fmul float %5, %2
%8 = fpext float %7 to double
%9 = fpext float %6 to double
%10 = tail call double @llvm.fmuladd.f64(double %9, double -5.000000e-01, double %8)
%11 = fptrunc double %10 to float
%12 = fadd float %6, %11
%13 = fmul float %5, %0
%14 = fcmp oeq float %12, %11
br i1 %14, label %15, label %20
15: ; preds = %4
%16 = tail call float @llvm.floor.f32(float %11)
%17 = fsub float %11, %16
%18 = fcmp olt float %17, %13
%19 = select i1 %18, float 0.000000e+00, float 1.000000e+00
br label %25
20: ; preds = %4
%21 = tail call float @integral(float %12, float %13)
%22 = tail call float @integral(float %11, float %13)
%23 = fsub float %21, %22
%24 = fdiv float %23, %6
br label %25
25: ; preds = %20, %15
%26 = phi float [ %19, %15 ], [ %24, %20 ]
ret float %26
}