#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 */
int M_PI;
int fabs(double);
double derotate_180_rad_double(double a) {
  int i;
  i = fabs(a) / M_PI;
  if (a > 0)
    a -= M_PI * i;
  else
    a += M_PI * i;
  if (a < 0)
    a += M_PI;
  return a;
}


x86 assembly (clang, -O0):
<derotate_180_rad_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <fabs@plt>
mov    0x2eba(%rip),%rcx
cltd
idivl  (%rcx)
mov    %eax,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    116a <derotate_180_rad_double+0x5a>
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
imul   -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  -0x8(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1185 <derotate_180_rad_double+0x75>
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
imul   -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11a8 <derotate_180_rad_double+0x98>
mov    0x2e4e(%rip),%rax
cvtsi2sdl (%rax),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<derotate_180_rad_double>:
push   %rax
movsd  %xmm0,(%rsp)
call   1030 <fabs@plt>
mov    %eax,%ecx
mov    0x2ec4(%rip),%rax
mov    (%rax),%esi
mov    %ecx,%eax
cltd
idiv   %esi
sub    %edx,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movapd 0xec4(%rip),%xmm1
xorpd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
xorpd  %xmm3,%xmm3
movsd  (%rsp),%xmm5
cmpltsd %xmm5,%xmm3
movapd %xmm3,%xmm4
andnpd %xmm0,%xmm4
andpd  %xmm1,%xmm3
orpd   %xmm4,%xmm3
addsd  %xmm5,%xmm3
xorps  %xmm1,%xmm1
cvtsi2sd %esi,%xmm1
movapd %xmm3,%xmm0
cmpltsd %xmm2,%xmm0
andpd  %xmm0,%xmm1
movsd  0xe8e(%rip),%xmm2
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
addsd  %xmm3,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@M_PI = global i32 0
define double @derotate_180_rad_double(double %0) {
%2 = alloca double
%3 = alloca i32
store double %0, double* %2
%4 = load double, double* %2
%5 = call i32 @fabs(double %4)
%6 = load i32, i32* @M_PI
%7 = sdiv i32 %5, %6
store i32 %7, i32* %3
%8 = load double, double* %2
%9 = fcmp ogt double %8, 0.000000e+00
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = load i32, i32* @M_PI
%12 = load i32, i32* %3
%13 = mul nsw i32 %11, %12
%14 = sitofp i32 %13 to double
%15 = load double, double* %2
%16 = fsub double %15, %14
store double %16, double* %2
br label %24
17: ; preds = %1
%18 = load i32, i32* @M_PI
%19 = load i32, i32* %3
%20 = mul nsw i32 %18, %19
%21 = sitofp i32 %20 to double
%22 = load double, double* %2
%23 = fadd double %22, %21
store double %23, double* %2
br label %24
24: ; preds = %17, %10
%25 = load double, double* %2
%26 = fcmp olt double %25, 0.000000e+00
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i32, i32* @M_PI
%29 = sitofp i32 %28 to double
%30 = load double, double* %2
%31 = fadd double %30, %29
store double %31, double* %2
br label %32
32: ; preds = %27, %24
%33 = load double, double* %2
ret double %33
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @derotate_180_rad_double(double %0) {
%2 = tail call i32 @fabs(double %0)
%3 = load i32, i32* @M_PI
%4 = fcmp ogt double %0, 0.000000e+00
%5 = srem i32 %2, %3
%6 = sub i32 %2, %5
%7 = sitofp i32 %6 to double
%8 = fneg double %7
%9 = select i1 %4, double %8, double %7
%10 = fadd double %9, %0
%11 = fcmp olt double %10, 0.000000e+00
%12 = sitofp i32 %3 to double
%13 = select i1 %11, double %12, double -0.000000e+00
%14 = fadd double %10, %13
ret double %14
}