#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 /*<<< orphan*/ _expect_approx(int /*<<< orphan*/, int /*<<< orphan*/,
                                  char *);
int /*<<< orphan*/ _expect_true(int, char *);
double az_mod2pi(double);
double az_mod2pi_nonneg(double);
double az_mod2pi_nonpos(double);
int /*<<< orphan*/ cos(double const);
int /*<<< orphan*/ sin(double const);
void test_mod2pi(void) {
  for (double t = -20.0; t < 20.0; t += 0.1) {
    const double t2 = az_mod2pi(t);
    _expect_true(t2 >= -3.1415926535897931, "t2 >= -AZ_PI");
    _expect_true(t2 <= 3.1415926535897931, "t2 <= AZ_PI");
    _expect_approx(sin(t), sin(t2),
                   "sin(t)"
                   " == "
                   "sin(t2)");
    _expect_approx(cos(t), cos(t2),
                   "cos(t)"
                   " == "
                   "cos(t2)");
  }
  for (double t = -20.0; t < 20.0; t += 0.1) {
    const double t2 = az_mod2pi_nonneg(t);
    _expect_true(t2 >= 0.0, "t2 >= 0.0");
    _expect_true(t2 <= 6.2831853071795862, "t2 <= AZ_TWO_PI");
    _expect_approx(sin(t), sin(t2),
                   "sin(t)"
                   " == "
                   "sin(t2)");
    _expect_approx(cos(t), cos(t2),
                   "cos(t)"
                   " == "
                   "cos(t2)");
  }
  for (double t = -20.0; t < 20.0; t += 0.1) {
    const double t2 = az_mod2pi_nonpos(t);
    _expect_true(t2 >= -6.2831853071795862, "t2 >= -AZ_TWO_PI");
    _expect_true(t2 <= 0.0, "t2 <= 0.0");
    _expect_approx(sin(t), sin(t2),
                   "sin(t)"
                   " == "
                   "sin(t2)");
    _expect_approx(cos(t), cos(t2),
                   "cos(t)"
                   " == "
                   "cos(t2)");
  }
}


x86 assembly (clang, -O0):
<test_mod2pi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  0xe80(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xe7b(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1254 <test_mod2pi+0xe4>
movsd  -0x8(%rbp),%xmm0
call   1080 <az_mod2pi@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe7c(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xe71(%rip),%rsi
call   1040 <_expect_true@plt>
movsd  0xe54(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xe5d(%rip),%rsi
call   1040 <_expect_true@plt>
movsd  -0x8(%rbp),%xmm0
call   1050 <sin@plt>
mov    %eax,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <sin@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%esi
lea    0xe41(%rip),%rdx
call   1060 <_expect_approx@plt>
movsd  -0x8(%rbp),%xmm0
call   1070 <cos@plt>
mov    %eax,-0x34(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1070 <cos@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%esi
lea    0xe2b(%rip),%rdx
call   1060 <_expect_approx@plt>
movsd  0xdd3(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1185 <test_mod2pi+0x15>
movsd  0xda4(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xd9f(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    132b <test_mod2pi+0x1bb>
movsd  -0x18(%rbp),%xmm0
call   1030 <az_mod2pi_nonneg@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xdd7(%rip),%rsi
call   1040 <_expect_true@plt>
movsd  0xd75(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xdc0(%rip),%rsi
call   1040 <_expect_true@plt>
movsd  -0x18(%rbp),%xmm0
call   1050 <sin@plt>
mov    %eax,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <sin@plt>
mov    -0x40(%rbp),%edi
mov    %eax,%esi
lea    0xd6a(%rip),%rdx
call   1060 <_expect_approx@plt>
movsd  -0x18(%rbp),%xmm0
call   1070 <cos@plt>
mov    %eax,-0x3c(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1070 <cos@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%esi
lea    0xd54(%rip),%rdx
call   1060 <_expect_approx@plt>
movsd  0xcfc(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1261 <test_mod2pi+0xf1>
movsd  0xccd(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xcc8(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1402 <test_mod2pi+0x292>
movsd  -0x28(%rbp),%xmm0
call   1090 <az_mod2pi_nonpos@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xca9(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xd15(%rip),%rsi
call   1040 <_expect_true@plt>
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xd0a(%rip),%rsi
call   1040 <_expect_true@plt>
movsd  -0x28(%rbp),%xmm0
call   1050 <sin@plt>
mov    %eax,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <sin@plt>
mov    -0x48(%rbp),%edi
mov    %eax,%esi
lea    0xc93(%rip),%rdx
call   1060 <_expect_approx@plt>
movsd  -0x28(%rbp),%xmm0
call   1070 <cos@plt>
mov    %eax,-0x44(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1070 <cos@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%esi
lea    0xc7d(%rip),%rdx
call   1060 <_expect_approx@plt>
movsd  0xc25(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1338 <test_mod2pi+0x1c8>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_mod2pi>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movsd  0xe7c(%rip),%xmm0
lea    0xeb5(%rip),%r14
lea    0xebb(%rip),%r15
lea    0xec0(%rip),%r12
lea    0xecb(%rip),%rbx
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
call   1080 <az_mod2pi@plt>
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
ucomisd 0xe49(%rip),%xmm0
setae  %dil
mov    %r14,%rsi
call   1040 <_expect_true@plt>
xor    %edi,%edi
movsd  0xe3b(%rip),%xmm0
ucomisd 0x8(%rsp),%xmm0
setae  %dil
mov    %r15,%rsi
call   1040 <_expect_true@plt>
movsd  (%rsp),%xmm0
call   1050 <sin@plt>
mov    %eax,%ebp
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %r12,%rdx
call   1060 <_expect_approx@plt>
movsd  (%rsp),%xmm0
call   1070 <cos@plt>
mov    %eax,%ebp
movsd  0x8(%rsp),%xmm0
call   1070 <cos@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %rbx,%rdx
call   1060 <_expect_approx@plt>
movsd  0xde3(%rip),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0xdd5(%rip),%xmm0
ucomisd (%rsp),%xmm0
movsd  (%rsp),%xmm0
ja     11a0 <test_mod2pi+0x30>
movsd  0xd9d(%rip),%xmm0
lea    0xe13(%rip),%r14
lea    0xe16(%rip),%r15
lea    0xde1(%rip),%r12
lea    0xdec(%rip),%rbx
nop
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
call   1030 <az_mod2pi_nonneg@plt>
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
ucomisd 0xd99(%rip),%xmm0
setae  %dil
mov    %r14,%rsi
call   1040 <_expect_true@plt>
xor    %edi,%edi
movsd  0xd73(%rip),%xmm0
ucomisd 0x8(%rsp),%xmm0
setae  %dil
mov    %r15,%rsi
call   1040 <_expect_true@plt>
movsd  (%rsp),%xmm0
call   1050 <sin@plt>
mov    %eax,%ebp
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %r12,%rdx
call   1060 <_expect_approx@plt>
movsd  (%rsp),%xmm0
call   1070 <cos@plt>
mov    %eax,%ebp
movsd  0x8(%rsp),%xmm0
call   1070 <cos@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %rbx,%rdx
call   1060 <_expect_approx@plt>
movsd  (%rsp),%xmm0
addsd  0xcfe(%rip),%xmm0
movsd  %xmm0,(%rsp)
movsd  0xcf9(%rip),%xmm0
ucomisd (%rsp),%xmm0
movsd  (%rsp),%xmm0
ja     1280 <test_mod2pi+0x110>
movsd  0xcc1(%rip),%xmm0
lea    0xd51(%rip),%r14
lea    0xd5b(%rip),%r15
lea    0xd05(%rip),%r12
lea    0xd10(%rip),%rbx
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
call   1090 <az_mod2pi_nonpos@plt>
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
ucomisd 0xcb1(%rip),%xmm0
setae  %dil
mov    %r14,%rsi
call   1040 <_expect_true@plt>
xor    %edi,%edi
xorpd  %xmm0,%xmm0
ucomisd 0x8(%rsp),%xmm0
setae  %dil
mov    %r15,%rsi
call   1040 <_expect_true@plt>
movsd  (%rsp),%xmm0
call   1050 <sin@plt>
mov    %eax,%ebp
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %r12,%rdx
call   1060 <_expect_approx@plt>
movsd  (%rsp),%xmm0
call   1070 <cos@plt>
mov    %eax,%ebp
movsd  0x8(%rsp),%xmm0
call   1070 <cos@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %rbx,%rdx
call   1060 <_expect_approx@plt>
movsd  (%rsp),%xmm0
addsd  0xc22(%rip),%xmm0
movsd  %xmm0,(%rsp)
movsd  0xc1d(%rip),%xmm0
ucomisd (%rsp),%xmm0
movsd  (%rsp),%xmm0
ja     1360 <test_mod2pi+0x1f0>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"t2 >= -AZ_PI\00"
@.str.1 = [12 x i8] c"t2 <= AZ_PI\00"
@.str.2 = [18 x i8] c"sin(t) == sin(t2)\00"
@.str.3 = [18 x i8] c"cos(t) == cos(t2)\00"
@.str.4 = [10 x i8] c"t2 >= 0.0\00"
@.str.5 = [16 x i8] c"t2 <= AZ_TWO_PI\00"
@.str.6 = [17 x i8] c"t2 >= -AZ_TWO_PI\00"
@.str.7 = [10 x i8] c"t2 <= 0.0\00"
define void @test_mod2pi() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double -2.000000e+01, double* %1
br label %7
7: ; preds = %31, %0
%8 = load double, double* %1
%9 = fcmp olt double %8, 2.000000e+01
br i1 %9, label %10, label %34
10: ; preds = %7
%11 = load double, double* %1
%12 = call double @az_mod2pi(double %11)
store double %12, double* %2
%13 = load double, double* %2
%14 = fcmp oge double %13, 0xC00921FB54442D18
%15 = zext i1 %14 to i32
%16 = call i32 @_expect_true(i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = load double, double* %2
%18 = fcmp ole double %17, 0x400921FB54442D18
%19 = zext i1 %18 to i32
%20 = call i32 @_expect_true(i32 %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%21 = load double, double* %1
%22 = call i32 @sin(double %21)
%23 = load double, double* %2
%24 = call i32 @sin(double %23)
%25 = call i32 @_expect_approx(i32 %22, i32 %24, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%26 = load double, double* %1
%27 = call i32 @cos(double %26)
%28 = load double, double* %2
%29 = call i32 @cos(double %28)
%30 = call i32 @_expect_approx(i32 %27, i32 %29, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %10
%32 = load double, double* %1
%33 = fadd double %32, 1.000000e-01
store double %33, double* %1
br label %7
34: ; preds = %7
store double -2.000000e+01, double* %3
br label %35
35: ; preds = %59, %34
%36 = load double, double* %3
%37 = fcmp olt double %36, 2.000000e+01
br i1 %37, label %38, label %62
38: ; preds = %35
%39 = load double, double* %3
%40 = call double @az_mod2pi_nonneg(double %39)
store double %40, double* %4
%41 = load double, double* %4
%42 = fcmp oge double %41, 0.000000e+00
%43 = zext i1 %42 to i32
%44 = call i32 @_expect_true(i32 %43, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%45 = load double, double* %4
%46 = fcmp ole double %45, 0x401921FB54442D18
%47 = zext i1 %46 to i32
%48 = call i32 @_expect_true(i32 %47, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%49 = load double, double* %3
%50 = call i32 @sin(double %49)
%51 = load double, double* %4
%52 = call i32 @sin(double %51)
%53 = call i32 @_expect_approx(i32 %50, i32 %52, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%54 = load double, double* %3
%55 = call i32 @cos(double %54)
%56 = load double, double* %4
%57 = call i32 @cos(double %56)
%58 = call i32 @_expect_approx(i32 %55, i32 %57, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %38
%60 = load double, double* %3
%61 = fadd double %60, 1.000000e-01
store double %61, double* %3
br label %35
62: ; preds = %35
store double -2.000000e+01, double* %5
br label %63
63: ; preds = %87, %62
%64 = load double, double* %5
%65 = fcmp olt double %64, 2.000000e+01
br i1 %65, label %66, label %90
66: ; preds = %63
%67 = load double, double* %5
%68 = call double @az_mod2pi_nonpos(double %67)
store double %68, double* %6
%69 = load double, double* %6
%70 = fcmp oge double %69, 0xC01921FB54442D18
%71 = zext i1 %70 to i32
%72 = call i32 @_expect_true(i32 %71, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%73 = load double, double* %6
%74 = fcmp ole double %73, 0.000000e+00
%75 = zext i1 %74 to i32
%76 = call i32 @_expect_true(i32 %75, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%77 = load double, double* %5
%78 = call i32 @sin(double %77)
%79 = load double, double* %6
%80 = call i32 @sin(double %79)
%81 = call i32 @_expect_approx(i32 %78, i32 %80, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%82 = load double, double* %5
%83 = call i32 @cos(double %82)
%84 = load double, double* %6
%85 = call i32 @cos(double %84)
%86 = call i32 @_expect_approx(i32 %83, i32 %85, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %87
87: ; preds = %66
%88 = load double, double* %5
%89 = fadd double %88, 1.000000e-01
store double %89, double* %5
br label %63
90: ; preds = %63
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"t2 >= -AZ_PI\00"
@.str.1 = [12 x i8] c"t2 <= AZ_PI\00"
@.str.2 = [18 x i8] c"sin(t) == sin(t2)\00"
@.str.3 = [18 x i8] c"cos(t) == cos(t2)\00"
@.str.4 = [10 x i8] c"t2 >= 0.0\00"
@.str.5 = [16 x i8] c"t2 <= AZ_TWO_PI\00"
@.str.6 = [17 x i8] c"t2 >= -AZ_TWO_PI\00"
@.str.7 = [10 x i8] c"t2 <= 0.0\00"
define void @test_mod2pi() {
br label %1
1: ; preds = %0, %1
%2 = phi double [ -2.000000e+01, %0 ], [ %16, %1 ]
%3 = tail call double @az_mod2pi(double %2)
%4 = fcmp oge double %3, 0xC00921FB54442D18
%5 = zext i1 %4 to i32
%6 = tail call i32 @_expect_true(i32 %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = fcmp ole double %3, 0x400921FB54442D18
%8 = zext i1 %7 to i32
%9 = tail call i32 @_expect_true(i32 %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @sin(double %2)
%11 = tail call i32 @sin(double %3)
%12 = tail call i32 @_expect_approx(i32 %10, i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @cos(double %2)
%14 = tail call i32 @cos(double %3)
%15 = tail call i32 @_expect_approx(i32 %13, i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%16 = fadd double %2, 1.000000e-01
%17 = fcmp olt double %16, 2.000000e+01
br i1 %17, label %1, label %18
18: ; preds = %1, %18
%19 = phi double [ %33, %18 ], [ -2.000000e+01, %1 ]
%20 = tail call double @az_mod2pi_nonneg(double %19)
%21 = fcmp oge double %20, 0.000000e+00
%22 = zext i1 %21 to i32
%23 = tail call i32 @_expect_true(i32 %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%24 = fcmp ole double %20, 0x401921FB54442D18
%25 = zext i1 %24 to i32
%26 = tail call i32 @_expect_true(i32 %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%27 = tail call i32 @sin(double %19)
%28 = tail call i32 @sin(double %20)
%29 = tail call i32 @_expect_approx(i32 %27, i32 %28, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%30 = tail call i32 @cos(double %19)
%31 = tail call i32 @cos(double %20)
%32 = tail call i32 @_expect_approx(i32 %30, i32 %31, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%33 = fadd double %19, 1.000000e-01
%34 = fcmp olt double %33, 2.000000e+01
br i1 %34, label %18, label %36
35: ; preds = %36
ret void
36: ; preds = %18, %36
%37 = phi double [ %51, %36 ], [ -2.000000e+01, %18 ]
%38 = tail call double @az_mod2pi_nonpos(double %37)
%39 = fcmp oge double %38, 0xC01921FB54442D18
%40 = zext i1 %39 to i32
%41 = tail call i32 @_expect_true(i32 %40, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%42 = fcmp ole double %38, 0.000000e+00
%43 = zext i1 %42 to i32
%44 = tail call i32 @_expect_true(i32 %43, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%45 = tail call i32 @sin(double %37)
%46 = tail call i32 @sin(double %38)
%47 = tail call i32 @_expect_approx(i32 %45, i32 %46, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%48 = tail call i32 @cos(double %37)
%49 = tail call i32 @cos(double %38)
%50 = tail call i32 @_expect_approx(i32 %48, i32 %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%51 = fadd double %37, 1.000000e-01
%52 = fcmp olt double %51, 2.000000e+01
br i1 %52, label %36, label %35
}