#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 atan2(float const, float const);
float cos(double);
float sin(double);
extern double psi_of_mag(double phi, double theta, double mx, double my,
                         double mz) {
  const float cphi = cos(phi);
  const float sphi = sin(phi);
  const float ctheta = cos(theta);
  const float stheta = sin(theta);
  const float mn = ctheta * mx + sphi * stheta * my + cphi * stheta * mz;
  const float me = 0 * mx + cphi * my + -sphi * mz;
  return -atan2(me, mn);
}


x86 assembly (clang, -O0):
<psi_of_mag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,-0x2c(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <sin@plt>
movss  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,-0x34(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <sin@plt>
movss  %xmm0,-0x38(%rbp)
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm2
movss  -0x30(%rbp),%xmm0
mulss  -0x38(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
mulss  -0x38(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x3c(%rbp)
movsd  -0x18(%rbp),%xmm1
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  -0x20(%rbp),%xmm0
xorps  %xmm2,%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movss  -0x30(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x40(%rbp),%xmm0
movss  -0x3c(%rbp),%xmm1
call   1030 <atan2@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psi_of_mag>:
sub    $0x38,%rsp
movsd  %xmm4,0x30(%rsp)
movsd  %xmm3,0x20(%rsp)
movsd  %xmm2,0x28(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1050 <cos@plt>
movss  %xmm0,0x14(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movss  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
call   1040 <sin@plt>
movss  0x10(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
movss  0x8(%rsp),%xmm6
movaps %xmm6,%xmm2
mulss  %xmm0,%xmm2
cvtss2sd %xmm2,%xmm2
movsd  0x20(%rsp),%xmm5
mulsd  %xmm5,%xmm2
movsd  0x28(%rsp),%xmm4
mulsd  %xmm4,%xmm1
addsd  %xmm2,%xmm1
movss  0x14(%rsp),%xmm2
mulss  %xmm2,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0x30(%rsp),%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
mulsd  %xmm5,%xmm0
xorps  %xmm2,%xmm2
mulsd  %xmm4,%xmm2
addsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtss2sd %xmm6,%xmm0
mulsd  %xmm3,%xmm0
subsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsd2ss %xmm2,%xmm0
call   1030 <atan2@plt>
xorps  0xde8(%rip),%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define double @psi_of_mag(double %0, double %1, double %2, double %3, double %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca float
%15 = alloca float
%16 = alloca float
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store double %4, double* %10
%17 = load double, double* %6
%18 = call float @cos(double %17)
store float %18, float* %11
%19 = load double, double* %6
%20 = call float @sin(double %19)
store float %20, float* %12
%21 = load double, double* %7
%22 = call float @cos(double %21)
store float %22, float* %13
%23 = load double, double* %7
%24 = call float @sin(double %23)
store float %24, float* %14
%25 = load float, float* %13
%26 = fpext float %25 to double
%27 = load double, double* %8
%28 = load float, float* %12
%29 = load float, float* %14
%30 = fmul float %28, %29
%31 = fpext float %30 to double
%32 = load double, double* %9
%33 = fmul double %31, %32
%34 = call double @llvm.fmuladd.f64(double %26, double %27, double %33)
%35 = load float, float* %11
%36 = load float, float* %14
%37 = fmul float %35, %36
%38 = fpext float %37 to double
%39 = load double, double* %10
%40 = call double @llvm.fmuladd.f64(double %38, double %39, double %34)
%41 = fptrunc double %40 to float
store float %41, float* %15
%42 = load double, double* %8
%43 = load float, float* %11
%44 = fpext float %43 to double
%45 = load double, double* %9
%46 = fmul double %44, %45
%47 = call double @llvm.fmuladd.f64(double 0.000000e+00, double %42, double %46)
%48 = load float, float* %12
%49 = fneg float %48
%50 = fpext float %49 to double
%51 = load double, double* %10
%52 = call double @llvm.fmuladd.f64(double %50, double %51, double %47)
%53 = fptrunc double %52 to float
store float %53, float* %16
%54 = load float, float* %16
%55 = load float, float* %15
%56 = call double @atan2(float %54, float %55)
%57 = fneg double %56
ret double %57
}

LLVM IR (-O2):
define double @psi_of_mag(double %0, double %1, double %2, double %3, double %4) {
%6 = tail call float @cos(double %0)
%7 = tail call float @sin(double %0)
%8 = tail call float @cos(double %1)
%9 = tail call float @sin(double %1)
%10 = fpext float %8 to double
%11 = fmul float %7, %9
%12 = fpext float %11 to double
%13 = fmul double %12, %3
%14 = tail call double @llvm.fmuladd.f64(double %10, double %2, double %13)
%15 = fmul float %6, %9
%16 = fpext float %15 to double
%17 = tail call double @llvm.fmuladd.f64(double %16, double %4, double %14)
%18 = fptrunc double %17 to float
%19 = fpext float %6 to double
%20 = fmul double %19, %3
%21 = tail call double @llvm.fmuladd.f64(double %2, double 0.000000e+00, double %20)
%22 = fneg float %7
%23 = fpext float %22 to double
%24 = tail call double @llvm.fmuladd.f64(double %23, double %4, double %21)
%25 = fptrunc double %24 to float
%26 = tail call double @atan2(float %25, float %18)
%27 = fneg double %26
ret double %27
}