#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 atan2f(float, float);
float cosf(float);
float sinf(float);
float MagnetoHeadingCompute(float fMagnetoX, float fMagnetoY, float fMagnetoZ,
                            float fRoll, float fPitch) {
  float fSinRoll, fCosRoll, fSinPitch, fCosPitch, fX, fY, fHeading;
  fSinRoll = sinf(fRoll);
  fCosRoll = cosf(fRoll);
  fSinPitch = sinf(fPitch);
  fCosPitch = cosf(fPitch);
  fX = ((fMagnetoX * fCosPitch) + (fMagnetoY * fSinRoll * fSinPitch) +
        (fMagnetoZ * fCosRoll * fSinPitch));
  fY = (fMagnetoY * fCosRoll) - (fMagnetoZ * fSinRoll);
  fHeading = atan2f(-fY, fX);
  if (fHeading < 0) {
    fHeading += 2 * 3.141592;
  }
  return (fHeading);
}


x86 assembly (clang, -O0):
<MagnetoHeadingCompute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  %xmm4,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
call   1030 <sinf@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
call   1040 <cosf@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x14(%rbp),%xmm0
call   1030 <sinf@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x14(%rbp),%xmm0
call   1040 <cosf@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x4(%rbp),%xmm1
movss  -0x24(%rbp),%xmm2
movss  -0x8(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  -0xc(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  -0x20(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm2
movss  -0xc(%rbp),%xmm1
mulss  -0x18(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  -0x28(%rbp),%xmm1
call   1050 <atan2f@plt>
movss  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x30(%rbp),%xmm0
jbe    1244 <MagnetoHeadingCompute+0x114>
movss  -0x30(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdc9(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MagnetoHeadingCompute>:
sub    $0x38,%rsp
movss  %xmm4,0xc(%rsp)
movss  %xmm3,0x8(%rsp)
movss  %xmm2,0x1c(%rsp)
movaps %xmm1,0x20(%rsp)
movss  %xmm0,0x18(%rsp)
movaps %xmm3,%xmm0
call   1030 <sinf@plt>
movss  %xmm0,0x14(%rsp)
movss  0x8(%rsp),%xmm0
call   1040 <cosf@plt>
movss  %xmm0,0x8(%rsp)
movss  0xc(%rsp),%xmm0
call   1030 <sinf@plt>
movss  %xmm0,0x10(%rsp)
movss  0xc(%rsp),%xmm0
call   1040 <cosf@plt>
movss  0x14(%rsp),%xmm4
movaps %xmm4,%xmm1
movaps 0x20(%rsp),%xmm2
mulss  %xmm2,%xmm1
movss  0x10(%rsp),%xmm5
mulss  %xmm5,%xmm1
movss  0x18(%rsp),%xmm3
mulss  %xmm0,%xmm3
addss  %xmm1,%xmm3
movss  0x8(%rsp),%xmm1
mulss  %xmm1,%xmm2
movss  0x1c(%rsp),%xmm0
mulss  %xmm0,%xmm1
mulss  %xmm5,%xmm1
addss  %xmm3,%xmm1
movaps %xmm4,%xmm3
mulss  %xmm0,%xmm3
subss  %xmm3,%xmm2
xorps  0xe1c(%rip),%xmm2
movaps %xmm2,%xmm0
call   1050 <atan2f@plt>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
addsd  0xe15(%rip),%xmm1
xorps  %xmm2,%xmm2
cvtsd2ss %xmm1,%xmm2
xorps  %xmm3,%xmm3
movaps %xmm0,%xmm1
cmpltss %xmm3,%xmm1
movaps %xmm1,%xmm3
andnps %xmm0,%xmm3
andps  %xmm2,%xmm1
orps   %xmm3,%xmm1
movaps %xmm1,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define float @MagnetoHeadingCompute(float %0, float %1, float %2, float %3, float %4) {
%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
%15 = alloca float
%16 = alloca float
%17 = alloca float
store float %0, float* %6
store float %1, float* %7
store float %2, float* %8
store float %3, float* %9
store float %4, float* %10
%18 = load float, float* %9
%19 = call float @sinf(float %18)
store float %19, float* %11
%20 = load float, float* %9
%21 = call float @cosf(float %20)
store float %21, float* %12
%22 = load float, float* %10
%23 = call float @sinf(float %22)
store float %23, float* %13
%24 = load float, float* %10
%25 = call float @cosf(float %24)
store float %25, float* %14
%26 = load float, float* %6
%27 = load float, float* %14
%28 = load float, float* %7
%29 = load float, float* %11
%30 = fmul float %28, %29
%31 = load float, float* %13
%32 = fmul float %30, %31
%33 = call float @llvm.fmuladd.f32(float %26, float %27, float %32)
%34 = load float, float* %8
%35 = load float, float* %12
%36 = fmul float %34, %35
%37 = load float, float* %13
%38 = call float @llvm.fmuladd.f32(float %36, float %37, float %33)
store float %38, float* %15
%39 = load float, float* %7
%40 = load float, float* %12
%41 = load float, float* %8
%42 = load float, float* %11
%43 = fmul float %41, %42
%44 = fneg float %43
%45 = call float @llvm.fmuladd.f32(float %39, float %40, float %44)
store float %45, float* %16
%46 = load float, float* %16
%47 = fneg float %46
%48 = load float, float* %15
%49 = call float @atan2f(float %47, float %48)
store float %49, float* %17
%50 = load float, float* %17
%51 = fcmp olt float %50, 0.000000e+00
br i1 %51, label %52, label %57
52: ; preds = %5
%53 = load float, float* %17
%54 = fpext float %53 to double
%55 = fadd double %54, 0x401921FAFC8B007A
%56 = fptrunc double %55 to float
store float %56, float* %17
br label %57
57: ; preds = %52, %5
%58 = load float, float* %17
ret float %58
}

LLVM IR (-O2):
define float @MagnetoHeadingCompute(float %0, float %1, float %2, float %3, float %4) {
%6 = tail call float @sinf(float %3)
%7 = tail call float @cosf(float %3)
%8 = tail call float @sinf(float %4)
%9 = tail call float @cosf(float %4)
%10 = fmul float %6, %1
%11 = fmul float %10, %8
%12 = tail call float @llvm.fmuladd.f32(float %0, float %9, float %11)
%13 = fmul float %7, %2
%14 = tail call float @llvm.fmuladd.f32(float %13, float %8, float %12)
%15 = fneg float %6
%16 = fmul float %15, %2
%17 = tail call float @llvm.fmuladd.f32(float %1, float %7, float %16)
%18 = fneg float %17
%19 = tail call float @atan2f(float %18, float %14)
%20 = fcmp olt float %19, 0.000000e+00
%21 = fpext float %19 to double
%22 = fadd double %21, 0x401921FAFC8B007A
%23 = fptrunc double %22 to float
%24 = select i1 %20, float %23, float %19
ret float %24
}