#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 floor(double);
double sub_hi(double, double);
double sub_lo(double, double);
int reduce_trig2pi(int hilo, double x, double *N, int *J, double *Z) {
  double M;
  M = floor(4 * x + 0.5);
  *J = M - 4 * floor(M / 4);
  if (hilo == 1)
    *Z = sub_hi(x, M / 4.0);
  else
    *Z = sub_lo(x, M / 4.0);
  *N = floor(M / 4.0);
  return ((-0.25 < *Z) && (*Z < 0.25));
}


x86 assembly (clang, -O0):
<reduce_trig2pi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xea7(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xea3(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1050 <floor@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe72(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <floor@plt>
movsd  -0x38(%rbp),%xmm0
shl    $0x2,%eax
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x1,-0x4(%rbp)
jne    11e3 <reduce_trig2pi+0xb3>
movsd  -0x10(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  0xe33(%rip),%xmm2
divsd  %xmm2,%xmm1
call   1040 <sub_hi@plt>
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1206 <reduce_trig2pi+0xd6>
movsd  -0x10(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  0xe0b(%rip),%xmm2
divsd  %xmm2,%xmm1
call   1030 <sub_lo@plt>
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
movsd  0xded(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <floor@plt>
cvtsi2sd %eax,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
xor    %eax,%eax
movsd  0xdd6(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x39(%rbp)
jbe    125d <reduce_trig2pi+0x12d>
mov    -0x28(%rbp),%rax
movsd  0xdc5(%rip),%xmm0
ucomisd (%rax),%xmm0
seta   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reduce_trig2pi>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r14
movapd %xmm0,%xmm1
mov    %edi,%ebp
movsd  0xeaf(%rip),%xmm0
movsd  %xmm1,0x8(%rsp)
mulsd  %xmm1,%xmm0
addsd  0xea5(%rip),%xmm0
call   1050 <floor@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0xe93(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
call   1050 <floor@plt>
shl    $0x2,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
mov    %eax,(%rbx)
cmp    $0x1,%ebp
jne    11bc <reduce_trig2pi+0x8c>
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1040 <sub_hi@plt>
jmp    11cc <reduce_trig2pi+0x9c>
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1030 <sub_lo@plt>
movsd  %xmm0,(%r15)
movsd  (%rsp),%xmm0
call   1050 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%r14)
movsd  (%r15),%xmm0
ucomisd 0xe24(%rip),%xmm0
seta   %al
movsd  0xe11(%rip),%xmm1
ucomisd %xmm0,%xmm1
seta   %cl
and    %al,%cl
movzbl %cl,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @reduce_trig2pi(i32 %0, double %1, double* %2, i32* %3, double* %4) {
%6 = alloca i32
%7 = alloca double
%8 = alloca double*
%9 = alloca i32*
%10 = alloca double*
%11 = alloca double
store i32 %0, i32* %6
store double %1, double* %7
store double* %2, double** %8
store i32* %3, i32** %9
store double* %4, double** %10
%12 = load double, double* %7
%13 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %12, double 5.000000e-01)
%14 = call i32 @floor(double %13)
%15 = sitofp i32 %14 to double
store double %15, double* %11
%16 = load double, double* %11
%17 = load double, double* %11
%18 = fdiv double %17, 4.000000e+00
%19 = call i32 @floor(double %18)
%20 = mul nsw i32 4, %19
%21 = sitofp i32 %20 to double
%22 = fsub double %16, %21
%23 = fptosi double %22 to i32
%24 = load i32*, i32** %9
store i32 %23, i32* %24
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %33
27: ; preds = %5
%28 = load double, double* %7
%29 = load double, double* %11
%30 = fdiv double %29, 4.000000e+00
%31 = call double @sub_hi(double %28, double %30)
%32 = load double*, double** %10
store double %31, double* %32
br label %39
33: ; preds = %5
%34 = load double, double* %7
%35 = load double, double* %11
%36 = fdiv double %35, 4.000000e+00
%37 = call double @sub_lo(double %34, double %36)
%38 = load double*, double** %10
store double %37, double* %38
br label %39
39: ; preds = %33, %27
%40 = load double, double* %11
%41 = fdiv double %40, 4.000000e+00
%42 = call i32 @floor(double %41)
%43 = sitofp i32 %42 to double
%44 = load double*, double** %8
store double %43, double* %44
%45 = load double*, double** %10
%46 = load double, double* %45
%47 = fcmp olt double -2.500000e-01, %46
br i1 %47, label %48, label %52
48: ; preds = %39
%49 = load double*, double** %10
%50 = load double, double* %49
%51 = fcmp olt double %50, 2.500000e-01
br label %52
52: ; preds = %48, %39
%53 = phi i1 [ false, %39 ], [ %51, %48 ]
%54 = zext i1 %53 to i32
ret i32 %54
}

LLVM IR (-O2):
define i32 @reduce_trig2pi(i32 %0, double %1, double* nocapture writeonly %2, i32* nocapture writeonly %3, double* nocapture %4) {
%6 = tail call double @llvm.fmuladd.f64(double %1, double 4.000000e+00, double 5.000000e-01)
%7 = tail call i32 @floor(double %6)
%8 = sitofp i32 %7 to double
%9 = fmul double %8, 2.500000e-01
%10 = tail call i32 @floor(double %9)
%11 = shl nsw i32 %10, 2
%12 = sitofp i32 %11 to double
%13 = fsub double %8, %12
%14 = fptosi double %13 to i32
store i32 %14, i32* %3
%15 = icmp eq i32 %0, 1
br i1 %15, label %16, label %18
16: ; preds = %5
%17 = tail call double @sub_hi(double %1, double %9)
br label %20
18: ; preds = %5
%19 = tail call double @sub_lo(double %1, double %9)
br label %20
20: ; preds = %18, %16
%21 = phi double [ %19, %18 ], [ %17, %16 ]
store double %21, double* %4
%22 = tail call i32 @floor(double %9)
%23 = sitofp i32 %22 to double
store double %23, double* %2
%24 = load double, double* %4
%25 = fcmp ogt double %24, -2.500000e-01
%26 = fcmp olt double %24, 2.500000e-01
%27 = and i1 %25, %26
%28 = zext i1 %27 to i32
ret i32 %28
}