#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 sin(double);
double amplitude_modulation(long long cnt, double peak, double time_peak) {
  double res;
  double pi = 3.14159265;
  double cnt_peak = time_peak / 4.0 * 10000.0;
  if (cnt < cnt_peak * 2)
    res = peak * sin(pi / 2 * (cnt / cnt_peak));
  else
    res = 0;
  return res;
}


x86 assembly (clang, -O0):
<amplitude_modulation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  0xeea(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xed0(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xebc(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdq -0x8(%rbp),%xmm1
movsd  0xe9d(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b7 <amplitude_modulation+0xa7>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe77(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdq -0x8(%rbp),%xmm1
divsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11bf <amplitude_modulation+0xaf>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<amplitude_modulation>:
push   %rax
movaps %xmm0,%xmm4
mulsd  0xee4(%rip),%xmm1
mulsd  0xee4(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rdi,%xmm0
movapd %xmm1,%xmm3
addsd  %xmm1,%xmm3
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm3
jbe    115d <amplitude_modulation+0x4d>
divsd  %xmm1,%xmm0
mulsd  0xec6(%rip),%xmm0
movsd  %xmm4,(%rsp)
call   1030 <sin@plt>
movapd %xmm0,%xmm2
mulsd  (%rsp),%xmm2
movapd %xmm2,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @amplitude_modulation(i64 %0, double %1, double %2) {
%4 = alloca i64
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i64 %0, i64* %4
store double %1, double* %5
store double %2, double* %6
store double 0x400921FB53C8D4F1, double* %8
%10 = load double, double* %6
%11 = fdiv double %10, 4.000000e+00
%12 = fmul double %11, 1.000000e+04
store double %12, double* %9
%13 = load i64, i64* %4
%14 = sitofp i64 %13 to double
%15 = load double, double* %9
%16 = fmul double %15, 2.000000e+00
%17 = fcmp olt double %14, %16
br i1 %17, label %18, label %29
18: ; preds = %3
%19 = load double, double* %5
%20 = load double, double* %8
%21 = fdiv double %20, 2.000000e+00
%22 = load i64, i64* %4
%23 = sitofp i64 %22 to double
%24 = load double, double* %9
%25 = fdiv double %23, %24
%26 = fmul double %21, %25
%27 = call double @sin(double %26)
%28 = fmul double %19, %27
store double %28, double* %7
br label %30
29: ; preds = %3
store double 0.000000e+00, double* %7
br label %30
30: ; preds = %29, %18
%31 = load double, double* %7
ret double %31
}

LLVM IR (-O2):
define double @amplitude_modulation(i64 %0, double %1, double %2) {
%4 = fmul double %2, 2.500000e-01
%5 = fmul double %4, 1.000000e+04
%6 = sitofp i64 %0 to double
%7 = fmul double %5, 2.000000e+00
%8 = fcmp ogt double %7, %6
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = fdiv double %6, %5
%11 = fmul double %10, 0x3FF921FB53C8D4F1
%12 = tail call double @sin(double %11)
%13 = fmul double %12, %1
br label %14
14: ; preds = %3, %9
%15 = phi double [ %13, %9 ], [ 0.000000e+00, %3 ]
ret double %15
}