#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 turn(double a, double base) {
  while (a - base < -M_PI)
    a += 2 * M_PI;
  while (a - base >= M_PI)
    a -= 2 * M_PI;
  return (a);
}


x86 assembly (clang, -O0):
<turn>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
mov    0x2ec9(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
ucomisd %xmm1,%xmm0
jbe    1166 <turn+0x66>
mov    0x2e9d(%rip),%rax
movsd  (%rax),%xmm0
movsd  -0x8(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    110e <turn+0xe>
jmp    116b <turn+0x6b>
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
mov    0x2e6c(%rip),%rax
ucomisd (%rax),%xmm0
jb     11a8 <turn+0xa8>
mov    0x2e5b(%rip),%rax
movsd  (%rax),%xmm1
movsd  -0x8(%rbp),%xmm0
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    116b <turn+0x6b>
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<turn>:
mov    0x2ee1(%rip),%rax
movsd  (%rax),%xmm2
movapd 0xeed(%rip),%xmm3
xorpd  %xmm2,%xmm3
movapd %xmm0,%xmm4
subsd  %xmm1,%xmm4
ucomisd %xmm4,%xmm3
jbe    1142 <turn+0x42>
movapd %xmm2,%xmm5
addsd  %xmm2,%xmm5
nopl   (%rax)
addsd  %xmm5,%xmm0
movapd %xmm0,%xmm4
subsd  %xmm1,%xmm4
ucomisd %xmm4,%xmm3
ja     1130 <turn+0x30>
ucomisd %xmm2,%xmm4
jb     1162 <turn+0x62>
movapd %xmm2,%xmm3
addsd  %xmm2,%xmm3
subsd  %xmm3,%xmm0
movapd %xmm0,%xmm4
subsd  %xmm1,%xmm4
ucomisd %xmm2,%xmm4
jae    1150 <turn+0x50>
ret

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

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @turn(double %0, double %1) {
%3 = load double, double* @M_PI
%4 = fneg double %3
%5 = fsub double %0, %1
%6 = fcmp olt double %5, %4
br i1 %6, label %11, label %7
7: ; preds = %11, %2
%8 = phi double [ %5, %2 ], [ %14, %11 ]
%9 = phi double [ %0, %2 ], [ %13, %11 ]
%10 = fcmp ult double %8, %3
br i1 %10, label %21, label %16
11: ; preds = %2, %11
%12 = phi double [ %13, %11 ], [ %0, %2 ]
%13 = tail call double @llvm.fmuladd.f64(double %3, double 2.000000e+00, double %12)
%14 = fsub double %13, %1
%15 = fcmp olt double %14, %4
br i1 %15, label %11, label %7
16: ; preds = %7, %16
%17 = phi double [ %18, %16 ], [ %9, %7 ]
%18 = tail call double @llvm.fmuladd.f64(double %3, double -2.000000e+00, double %17)
%19 = fsub double %18, %1
%20 = fcmp ult double %19, %3
br i1 %20, label %21, label %16
21: ; preds = %16, %7
%22 = phi double [ %9, %7 ], [ %18, %16 ]
ret double %22
}