#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 */
int M_PI;
float sin(float);
float second_harmonic(float freq, float amp, float t) {
  float theta1 = 2 * M_PI * freq * t;
  float theta2 = 2 * theta1;
  return (amp / 2) * sin(theta1) + (amp / 2) * sin(theta2);
}


x86 assembly (clang, -O0):
<second_harmonic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
mov    0x2eba(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2ss %eax,%xmm0
mulss  -0x4(%rbp),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  0xeb2(%rip),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
movss  0xe9b(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
call   1030 <sin@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x8(%rbp),%xmm0
movss  0xe76(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x14(%rbp),%xmm0
call   1030 <sin@plt>
movss  -0x20(%rbp),%xmm1
movss  -0x1c(%rbp),%xmm2
movaps %xmm0,%xmm3
movss  -0x18(%rbp),%xmm0
mulss  %xmm3,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<second_harmonic>:
sub    $0x18,%rsp
mov    0x2ecd(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
cvtsi2ss %eax,%xmm3
mulss  %xmm3,%xmm0
mulss  %xmm2,%xmm0
movaps %xmm0,%xmm2
addss  %xmm0,%xmm2
movss  %xmm2,0xc(%rsp)
mulss  0xec0(%rip),%xmm1
movss  %xmm1,0x14(%rsp)
call   1030 <sin@plt>
movss  %xmm0,0x10(%rsp)
movss  0xc(%rsp),%xmm0
call   1030 <sin@plt>
movss  0x14(%rsp),%xmm1
mulss  %xmm1,%xmm0
movss  0x10(%rsp),%xmm2
mulss  %xmm1,%xmm2
addss  %xmm2,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@M_PI = global i32 0
define float @second_harmonic(float %0, float %1, float %2) {
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
store float %0, float* %4
store float %1, float* %5
store float %2, float* %6
%9 = load i32, i32* @M_PI
%10 = mul nsw i32 2, %9
%11 = sitofp i32 %10 to float
%12 = load float, float* %4
%13 = fmul float %11, %12
%14 = load float, float* %6
%15 = fmul float %13, %14
store float %15, float* %7
%16 = load float, float* %7
%17 = fmul float 2.000000e+00, %16
store float %17, float* %8
%18 = load float, float* %5
%19 = fdiv float %18, 2.000000e+00
%20 = load float, float* %7
%21 = call float @sin(float %20)
%22 = load float, float* %5
%23 = fdiv float %22, 2.000000e+00
%24 = load float, float* %8
%25 = call float @sin(float %24)
%26 = fmul float %23, %25
%27 = call float @llvm.fmuladd.f32(float %19, float %21, float %26)
ret float %27
}

LLVM IR (-O2):
@M_PI = global i32 0
define float @second_harmonic(float %0, float %1, float %2) {
%4 = load i32, i32* @M_PI
%5 = shl nsw i32 %4, 1
%6 = sitofp i32 %5 to float
%7 = fmul float %6, %0
%8 = fmul float %7, %2
%9 = fmul float %8, 2.000000e+00
%10 = fmul float %1, 5.000000e-01
%11 = tail call float @sin(float %8)
%12 = tail call float @sin(float %9)
%13 = fmul float %10, %12
%14 = tail call float @llvm.fmuladd.f32(float %10, float %11, float %13)
ret float %14
}