#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 fmod(double, double);
double trunc(double);
double wrap(double v, double min, double max) {
  double delta;
  if (min <= v && v < max) {
    return v;
  }
  delta = max - min;
  if (v < min) {
    v += delta * (trunc((min - v) / delta) + 1.0);
  }
  return min + fmod((v - min), delta);
}


x86 assembly (clang, -O0):
<wrap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     116e <wrap+0x4e>
movsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    116e <wrap+0x4e>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1204 <wrap+0xe4>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d5 <wrap+0xb5>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
call   1040 <trunc@plt>
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
movsd  0xe41(%rip),%xmm1
addsd  %xmm1,%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1030 <fmod@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wrap>:
movapd %xmm0,%xmm3
ucomisd %xmm1,%xmm0
jb     1135 <wrap+0x15>
ucomisd %xmm3,%xmm2
jbe    1135 <wrap+0x15>
movapd %xmm3,%xmm0
ret
sub    $0x18,%rsp
subsd  %xmm1,%xmm2
ucomisd %xmm3,%xmm1
movsd  %xmm1,(%rsp)
jbe    1186 <wrap+0x66>
movapd %xmm1,%xmm0
subsd  %xmm3,%xmm0
divsd  %xmm2,%xmm0
movsd  %xmm3,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
call   1040 <trunc@plt>
movsd  0x8(%rsp),%xmm2
movsd  (%rsp),%xmm1
movsd  0x10(%rsp),%xmm3
addsd  0xe82(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm0,%xmm3
subsd  %xmm1,%xmm3
movapd %xmm3,%xmm0
movapd %xmm2,%xmm1
call   1030 <fmod@plt>
movapd %xmm0,%xmm3
addsd  (%rsp),%xmm3
add    $0x18,%rsp
movapd %xmm3,%xmm0
ret

LLVM IR (-O0):
define double @wrap(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%9 = load double, double* %6
%10 = load double, double* %5
%11 = fcmp ole double %9, %10
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load double, double* %5
%14 = load double, double* %7
%15 = fcmp olt double %13, %14
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load double, double* %5
store double %17, double* %4
br label %44
18: ; preds = %12, %3
%19 = load double, double* %7
%20 = load double, double* %6
%21 = fsub double %19, %20
store double %21, double* %8
%22 = load double, double* %5
%23 = load double, double* %6
%24 = fcmp olt double %22, %23
br i1 %24, label %25, label %36
25: ; preds = %18
%26 = load double, double* %8
%27 = load double, double* %6
%28 = load double, double* %5
%29 = fsub double %27, %28
%30 = load double, double* %8
%31 = fdiv double %29, %30
%32 = call double @llvm.trunc.f64(double %31)
%33 = fadd double %32, 1.000000e+00
%34 = load double, double* %5
%35 = call double @llvm.fmuladd.f64(double %26, double %33, double %34)
store double %35, double* %5
br label %36
36: ; preds = %25, %18
%37 = load double, double* %6
%38 = load double, double* %5
%39 = load double, double* %6
%40 = fsub double %38, %39
%41 = load double, double* %8
%42 = call double @fmod(double %40, double %41)
%43 = fadd double %37, %42
store double %43, double* %4
br label %44
44: ; preds = %36, %16
%45 = load double, double* %4
ret double %45
}

LLVM IR (-O2):
define double @wrap(double %0, double %1, double %2) {
%4 = fcmp ole double %1, %0
%5 = fcmp olt double %0, %2
%6 = and i1 %4, %5
br i1 %6, label %21, label %7
7: ; preds = %3
%8 = fsub double %2, %1
%9 = fcmp olt double %0, %1
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = fsub double %1, %0
%12 = fdiv double %11, %8
%13 = tail call double @llvm.trunc.f64(double %12)
%14 = fadd double %13, 1.000000e+00
%15 = tail call double @llvm.fmuladd.f64(double %8, double %14, double %0)
br label %16
16: ; preds = %10, %7
%17 = phi double [ %15, %10 ], [ %0, %7 ]
%18 = fsub double %17, %1
%19 = tail call double @fmod(double %18, double %8)
%20 = fadd double %19, %1
br label %21
21: ; preds = %3, %16
%22 = phi double [ %20, %16 ], [ %0, %3 ]
ret double %22
}