#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*/ modf(double, double *);
double reduce(double value, double rangeMin, double rangeMax) {
  double range, rangeFrac, fullRanges, retval;
  range = rangeMax - rangeMin;
  rangeFrac = (rangeMax - value) / range;
  modf(rangeFrac, &fullRanges);
  retval = value + fullRanges * range;
  if (retval > rangeMax)
    retval -= range;
  return (retval);
}


x86 assembly (clang, -O0):
<reduce>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    -0x30(%rbp),%rdi
call   1030 <modf@plt>
movsd  -0x8(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1197 <reduce+0x87>
movsd  -0x20(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reduce>:
sub    $0x38,%rsp
movapd %xmm2,0x20(%rsp)
movapd %xmm0,%xmm4
movsd  %xmm0,(%rsp)
movapd %xmm2,%xmm3
subsd  %xmm1,%xmm3
movapd %xmm3,0x10(%rsp)
movapd %xmm2,%xmm0
subsd  %xmm4,%xmm0
divsd  %xmm3,%xmm0
lea    0x8(%rsp),%rdi
call   1030 <modf@plt>
movsd  0x8(%rsp),%xmm0
movapd 0x10(%rsp),%xmm2
mulsd  %xmm2,%xmm0
addsd  (%rsp),%xmm0
movapd 0x20(%rsp),%xmm1
cmpltsd %xmm0,%xmm1
andpd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define double @reduce(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
%11 = load double, double* %6
%12 = load double, double* %5
%13 = fsub double %11, %12
store double %13, double* %7
%14 = load double, double* %6
%15 = load double, double* %4
%16 = fsub double %14, %15
%17 = load double, double* %7
%18 = fdiv double %16, %17
store double %18, double* %8
%19 = load double, double* %8
%20 = call i32 @modf(double %19, double* %9)
%21 = load double, double* %4
%22 = load double, double* %9
%23 = load double, double* %7
%24 = call double @llvm.fmuladd.f64(double %22, double %23, double %21)
store double %24, double* %10
%25 = load double, double* %10
%26 = load double, double* %6
%27 = fcmp ogt double %25, %26
br i1 %27, label %28, label %32
28: ; preds = %3
%29 = load double, double* %7
%30 = load double, double* %10
%31 = fsub double %30, %29
store double %31, double* %10
br label %32
32: ; preds = %28, %3
%33 = load double, double* %10
ret double %33
}

LLVM IR (-O2):
define double @reduce(double %0, double %1, double %2) {
%4 = alloca double
%5 = bitcast double* %4 to i8*
%6 = fsub double %2, %1
%7 = fsub double %2, %0
%8 = fdiv double %7, %6
%9 = call i32 @modf(double %8, double* %4)
%10 = load double, double* %4
%11 = tail call double @llvm.fmuladd.f64(double %10, double %6, double %0)
%12 = fcmp ogt double %11, %2
%13 = select i1 %12, double %6, double 0.000000e+00
%14 = fsub double %11, %13
ret double %14
}