#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 double_modulus(double, double);
double math_angle_to_game_angle(double angle) {
  double a;
  a = (2.0 * M_PI - angle) + M_PI / 2.0;
  if (a < 0)
    a += 2.0 * M_PI;
  if (a >= 2.0 * M_PI)
    a -= 2.0 * M_PI;
  return double_modulus(a, 2.0 * M_PI);
}


x86 assembly (clang, -O0):
<math_angle_to_game_angle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    0x2ec4(%rip),%rax
movsd  (%rax),%xmm0
movsd  -0x8(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    0x2e95(%rip),%rax
movsd  (%rax),%xmm1
movsd  0xea1(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1197 <math_angle_to_game_angle+0x87>
mov    0x2e67(%rip),%rax
movsd  (%rax),%xmm0
movsd  -0x10(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
mov    0x2e3d(%rip),%rax
mulsd  (%rax),%xmm1
ucomisd %xmm1,%xmm0
jb     11d6 <math_angle_to_game_angle+0xc6>
mov    0x2e28(%rip),%rax
movsd  (%rax),%xmm1
movsd  -0x10(%rbp),%xmm0
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe1d(%rip),%xmm1
mov    0x2dfe(%rip),%rax
mulsd  (%rax),%xmm1
call   1030 <double_modulus@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<math_angle_to_game_angle>:
mov    0x2ed1(%rip),%rax
movsd  (%rax),%xmm2
movapd %xmm2,%xmm1
addsd  %xmm2,%xmm1
movapd %xmm1,%xmm3
subsd  %xmm0,%xmm3
mulsd  0xecd(%rip),%xmm2
addsd  %xmm3,%xmm2
movapd %xmm1,%xmm0
addsd  %xmm2,%xmm0
xorpd  %xmm3,%xmm3
movapd %xmm2,%xmm4
cmpltsd %xmm3,%xmm4
andpd  %xmm4,%xmm0
andnpd %xmm2,%xmm4
orpd   %xmm0,%xmm4
movapd %xmm4,%xmm2
subsd  %xmm1,%xmm2
movapd %xmm1,%xmm0
cmpnlesd %xmm4,%xmm0
movapd %xmm0,%xmm3
andpd  %xmm4,%xmm3
andnpd %xmm2,%xmm0
orpd   %xmm3,%xmm0
jmp    1030 <double_modulus@plt>

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @math_angle_to_game_angle(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %2
%4 = load double, double* @M_PI
%5 = load double, double* %2
%6 = fneg double %5
%7 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %4, double %6)
%8 = load double, double* @M_PI
%9 = fdiv double %8, 2.000000e+00
%10 = fadd double %7, %9
store double %10, double* %3
%11 = load double, double* %3
%12 = fcmp olt double %11, 0.000000e+00
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load double, double* @M_PI
%15 = load double, double* %3
%16 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %14, double %15)
store double %16, double* %3
br label %17
17: ; preds = %13, %1
%18 = load double, double* %3
%19 = load double, double* @M_PI
%20 = fmul double 2.000000e+00, %19
%21 = fcmp oge double %18, %20
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load double, double* @M_PI
%24 = load double, double* %3
%25 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %23, double %24)
store double %25, double* %3
br label %26
26: ; preds = %22, %17
%27 = load double, double* %3
%28 = load double, double* @M_PI
%29 = fmul double 2.000000e+00, %28
%30 = call double @double_modulus(double %27, double %29)
ret double %30
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @math_angle_to_game_angle(double %0) {
%2 = load double, double* @M_PI
%3 = fneg double %0
%4 = tail call double @llvm.fmuladd.f64(double %2, double 2.000000e+00, double %3)
%5 = fmul double %2, 5.000000e-01
%6 = fadd double %4, %5
%7 = fcmp olt double %6, 0.000000e+00
%8 = tail call double @llvm.fmuladd.f64(double %2, double 2.000000e+00, double %6)
%9 = select i1 %7, double %8, double %6
%10 = fmul double %2, 2.000000e+00
%11 = fcmp ult double %9, %10
%12 = tail call double @llvm.fmuladd.f64(double %2, double -2.000000e+00, double %9)
%13 = select i1 %11, double %9, double %12
%14 = tail call double @double_modulus(double %13, double %10)
ret double %14
}