#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 mpi_pi(double val) {
  {
    while (val > M_PI)
      val -= 2. * M_PI;
    while (val < -M_PI)
      val += 2. * M_PI;
  };
  return val;
}


x86 assembly (clang, -O0):
<mpi_pi>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    0x2ed3(%rip),%rax
ucomisd (%rax),%xmm0
jbe    1141 <mpi_pi+0x41>
mov    0x2ec2(%rip),%rax
movsd  (%rax),%xmm1
movsd  -0x8(%rbp),%xmm0
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1109 <mpi_pi+0x9>
jmp    1146 <mpi_pi+0x46>
movsd  -0x8(%rbp),%xmm1
mov    0x2e96(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
ucomisd %xmm1,%xmm0
jbe    1199 <mpi_pi+0x99>
mov    0x2e6a(%rip),%rax
movsd  (%rax),%xmm0
movsd  -0x8(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1146 <mpi_pi+0x46>
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpi_pi>:
mov    0x2ee1(%rip),%rax
movsd  (%rax),%xmm1
ucomisd %xmm1,%xmm0
jbe    112a <mpi_pi+0x2a>
movapd %xmm1,%xmm2
addsd  %xmm1,%xmm2
nopl   0x0(%rax)
subsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
ja     1120 <mpi_pi+0x20>
movapd 0xece(%rip),%xmm2
xorpd  %xmm1,%xmm2
ucomisd %xmm0,%xmm2
jbe    114a <mpi_pi+0x4a>
addsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
ucomisd %xmm0,%xmm2
ja     1140 <mpi_pi+0x40>
ret

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

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