#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 floor(double);
__attribute__((gnu_)) double carmen_normalize_theta(double theta) {
  double multiplier;
  if (theta >= -3.14159265358979323846 && theta < 3.14159265358979323846)
    return theta;
  multiplier = floor(theta / (2 * 3.14159265358979323846));
  theta = theta - multiplier * 2 * 3.14159265358979323846;
  if (theta >= 3.14159265358979323846)
    theta -= 2 * 3.14159265358979323846;
  if (theta < -3.14159265358979323846)
    theta += 2 * 3.14159265358979323846;
  return theta;
}


x86 assembly (clang, -O0):
<carmen_normalize_theta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xed6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1156 <carmen_normalize_theta+0x46>
movsd  0xecc(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1156 <carmen_normalize_theta+0x46>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120b <carmen_normalize_theta+0xfb>
movsd  -0x10(%rbp),%xmm0
movsd  0xeb5(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  0xe92(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe66(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe4c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11dc <carmen_normalize_theta+0xcc>
movsd  -0x10(%rbp),%xmm0
movsd  0xe45(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe1c(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1201 <carmen_normalize_theta+0xf1>
movsd  0xe21(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<carmen_normalize_theta>:
sub    $0x18,%rsp
movapd %xmm0,%xmm2
ucomisd 0xee0(%rip),%xmm0
jb     1130 <carmen_normalize_theta+0x20>
movsd  0xede(%rip),%xmm0
ucomisd %xmm2,%xmm0
ja     11a5 <carmen_normalize_theta+0x95>
movsd  0xed8(%rip),%xmm1
movapd %xmm2,%xmm0
divsd  %xmm1,%xmm0
movapd %xmm2,(%rsp)
call   1030 <floor@plt>
mulsd  0xec6(%rip),%xmm0
movsd  0xeae(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  (%rsp),%xmm0
movsd  0xeb5(%rip),%xmm2
addsd  %xmm0,%xmm2
cmpnlesd %xmm0,%xmm1
andpd  %xmm1,%xmm0
andnpd %xmm2,%xmm1
orpd   %xmm0,%xmm1
movapd %xmm1,%xmm2
cmpltsd 0xe73(%rip),%xmm2
movsd  0xe7b(%rip),%xmm0
addsd  %xmm1,%xmm0
andpd  %xmm2,%xmm0
andnpd %xmm1,%xmm2
orpd   %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @carmen_normalize_theta(double %0) {
%2 = fcmp oge double %0, 0xC00921FB54442D18
%3 = fcmp olt double %0, 0x400921FB54442D18
%4 = and i1 %2, %3
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = fdiv double %0, 0x401921FB54442D18
%7 = tail call double @llvm.floor.f64(double %6)
%8 = fmul double %7, -2.000000e+00
%9 = tail call double @llvm.fmuladd.f64(double %8, double 0x400921FB54442D18, double %0)
%10 = fcmp ult double %9, 0x400921FB54442D18
%11 = fadd double %9, 0xC01921FB54442D18
%12 = select i1 %10, double %9, double %11
%13 = fcmp olt double %12, 0xC00921FB54442D18
%14 = fadd double %12, 0x401921FB54442D18
%15 = select i1 %13, double %14, double %12
br label %16
16: ; preds = %1, %5
%17 = phi double [ %15, %5 ], [ %0, %1 ]
ret double %17
}