#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 */
double M_PI;
double pow(int /*<<< orphan*/, int);
int /*<<< orphan*/ sin(double);
double _pulse(double t, double position, double width, double amplitude) {
  double a;
  t -= position - width;
  if (t <= 0 || t >= width * 2) {
    return (0);
  }
  a = t / (width * 2) * M_PI;
  return (pow(sin(a), 2) * amplitude);
}


x86 assembly (clang, -O0):
<_pulse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jae    117e <_pulse+0x5e>
movsd  -0x10(%rbp),%xmm0
movsd  0xe91(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jb     118b <_pulse+0x6b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d1 <_pulse+0xb1>
movsd  -0x10(%rbp),%xmm0
movsd  0xe68(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    0x2e40(%rip),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <sin@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1040 <pow@plt>
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_pulse>:
subsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    116f <_pulse+0x4f>
addsd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jae    116f <_pulse+0x4f>
push   %rax
divsd  %xmm2,%xmm0
mov    0x2ea0(%rip),%rax
mulsd  (%rax),%xmm0
movsd  %xmm3,(%rsp)
call   1030 <sin@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1040 <pow@plt>
movapd %xmm0,%xmm1
mulsd  (%rsp),%xmm1
add    $0x8,%rsp
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @_pulse(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
%11 = load double, double* %7
%12 = load double, double* %8
%13 = fsub double %11, %12
%14 = load double, double* %6
%15 = fsub double %14, %13
store double %15, double* %6
%16 = load double, double* %6
%17 = fcmp ole double %16, 0.000000e+00
br i1 %17, label %23, label %18
18: ; preds = %4
%19 = load double, double* %6
%20 = load double, double* %8
%21 = fmul double %20, 2.000000e+00
%22 = fcmp oge double %19, %21
br i1 %22, label %23, label %24
23: ; preds = %18, %4
store double 0.000000e+00, double* %5
br label %36
24: ; preds = %18
%25 = load double, double* %6
%26 = load double, double* %8
%27 = fmul double %26, 2.000000e+00
%28 = fdiv double %25, %27
%29 = load double, double* @M_PI
%30 = fmul double %28, %29
store double %30, double* %10
%31 = load double, double* %10
%32 = call i32 @sin(double %31)
%33 = call double @pow(i32 %32, i32 2)
%34 = load double, double* %9
%35 = fmul double %33, %34
store double %35, double* %5
br label %36
36: ; preds = %24, %23
%37 = load double, double* %5
ret double %37
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @_pulse(double %0, double %1, double %2, double %3) {
%5 = fsub double %1, %2
%6 = fsub double %0, %5
%7 = fcmp ugt double %6, 0.000000e+00
br i1 %7, label %8, label %18
8: ; preds = %4
%9 = fmul double %2, 2.000000e+00
%10 = fcmp ult double %6, %9
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = fdiv double %6, %9
%13 = load double, double* @M_PI
%14 = fmul double %12, %13
%15 = tail call i32 @sin(double %14)
%16 = tail call double @pow(i32 %15, i32 2)
%17 = fmul double %16, %3
br label %18
18: ; preds = %4, %8, %11
%19 = phi double [ %17, %11 ], [ 0.000000e+00, %8 ], [ 0.000000e+00, %4 ]
ret double %19
}