#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 fabs(double);
double E_ToZeroTwoPi(double input) {
  int mod;
  double res = 0.0;
  if (fabs(input) == (2.0 * M_PI))
    return 0.0;
  if (input < 0.0) {
    mod = (int)(input / (2.0 * M_PI));
    res = input - mod * (2.0 * M_PI);
    res = (2.0 * M_PI) + res;
  } else if (input > 0.0) {
    mod = (int)(input / (2.0 * M_PI));
    res = input - mod * (2.0 * M_PI);
  }
  return res;
}


x86 assembly (clang, -O0):
<E_ToZeroTwoPi>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xef3(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xed7(%rip),%xmm1
mov    0x2eb8(%rip),%rax
mulsd  (%rax),%xmm1
ucomisd %xmm1,%xmm0
jne    1151 <E_ToZeroTwoPi+0x51>
jp     1151 <E_ToZeroTwoPi+0x51>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    126a <E_ToZeroTwoPi+0x16a>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11e5 <E_ToZeroTwoPi+0xe5>
movsd  -0x10(%rbp),%xmm0
movsd  0xe94(%rip),%xmm1
mov    0x2e75(%rip),%rax
mulsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe6c(%rip),%xmm2
mov    0x2e4d(%rip),%rax
mulsd  (%rax),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    0x2e1e(%rip),%rax
movsd  (%rax),%xmm0
movsd  -0x20(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1260 <E_ToZeroTwoPi+0x160>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    125b <E_ToZeroTwoPi+0x15b>
movsd  -0x10(%rbp),%xmm0
movsd  0xdfc(%rip),%xmm1
mov    0x2ddd(%rip),%rax
mulsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xdd4(%rip),%xmm2
mov    0x2db5(%rip),%rax
mulsd  (%rax),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1260 <E_ToZeroTwoPi+0x160>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<E_ToZeroTwoPi>:
movapd 0xef8(%rip),%xmm2
andpd  %xmm0,%xmm2
mov    0x2ed5(%rip),%rax
movsd  (%rax),%xmm1
addsd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jne    1128 <E_ToZeroTwoPi+0x28>
jp     1128 <E_ToZeroTwoPi+0x28>
xorpd  %xmm0,%xmm0
ret
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
jbe    114f <E_ToZeroTwoPi+0x4f>
movapd %xmm0,%xmm2
divsd  %xmm1,%xmm2
cvttpd2dq %xmm2,%xmm2
cvtdq2pd %xmm2,%xmm2
mulsd  %xmm1,%xmm2
subsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
ret
ucomisd %xmm2,%xmm0
jbe    1123 <E_ToZeroTwoPi+0x23>
movapd %xmm0,%xmm2
divsd  %xmm1,%xmm2
cvttpd2dq %xmm2,%xmm2
cvtdq2pd %xmm2,%xmm2
mulsd  %xmm1,%xmm2
subsd  %xmm2,%xmm0
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @E_ToZeroTwoPi(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca double
store double %0, double* %3
store double 0.000000e+00, double* %5
%6 = load double, double* %3
%7 = call double @llvm.fabs.f64(double %6)
%8 = load double, double* @M_PI
%9 = fmul double 2.000000e+00, %8
%10 = fcmp oeq double %7, %9
br i1 %10, label %11, label %12
11: ; preds = %1
store double 0.000000e+00, double* %2
br label %50
12: ; preds = %1
%13 = load double, double* %3
%14 = fcmp olt double %13, 0.000000e+00
br i1 %14, label %15, label %31
15: ; preds = %12
%16 = load double, double* %3
%17 = load double, double* @M_PI
%18 = fmul double 2.000000e+00, %17
%19 = fdiv double %16, %18
%20 = fptosi double %19 to i32
store i32 %20, i32* %4
%21 = load double, double* %3
%22 = load i32, i32* %4
%23 = sitofp i32 %22 to double
%24 = load double, double* @M_PI
%25 = fmul double 2.000000e+00, %24
%26 = fneg double %23
%27 = call double @llvm.fmuladd.f64(double %26, double %25, double %21)
store double %27, double* %5
%28 = load double, double* @M_PI
%29 = load double, double* %5
%30 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %28, double %29)
store double %30, double* %5
br label %48
31: ; preds = %12
%32 = load double, double* %3
%33 = fcmp ogt double %32, 0.000000e+00
br i1 %33, label %34, label %47
34: ; preds = %31
%35 = load double, double* %3
%36 = load double, double* @M_PI
%37 = fmul double 2.000000e+00, %36
%38 = fdiv double %35, %37
%39 = fptosi double %38 to i32
store i32 %39, i32* %4
%40 = load double, double* %3
%41 = load i32, i32* %4
%42 = sitofp i32 %41 to double
%43 = load double, double* @M_PI
%44 = fmul double 2.000000e+00, %43
%45 = fneg double %42
%46 = call double @llvm.fmuladd.f64(double %45, double %44, double %40)
store double %46, double* %5
br label %47
47: ; preds = %34, %31
br label %48
48: ; preds = %47, %15
%49 = load double, double* %5
store double %49, double* %2
br label %50
50: ; preds = %48, %11
%51 = load double, double* %2
ret double %51
}

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