#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*/ printf(char *, double, double, double, ...);
double reflect(double x, double a, double b) {
  int rounds = 0, maxround = 10000;
  double x0 = x, small = 1e-12;
  if (b - a < small)
    printf("\nimproper range x0=%.6g (%.6g, %.6g)\n", x0, a, b);
  small = 0;
  for (;; rounds++) {
    if (x > a && x < b)
      return x;
    if (x <= a)
      x = a + a - x + small;
    else if (x >= b)
      x = b - (x - b) - small;
  }
  if (rounds > maxround)
    printf("\nx=%.6g (%.6g, %.6g), reflected %d rounds.\n", x0, a, b, maxround);
  return (x);
}


x86 assembly (clang, -O0):
<reflect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x2710,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeb9(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1182 <reflect+0x72>
movsd  -0x28(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
lea    0xe8d(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11b9 <reflect+0xa9>
movsd  -0x8(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b9 <reflect+0xa9>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11eb <reflect+0xdb>
movsd  -0x10(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121d <reflect+0x10d>
movsd  -0x8(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1218 <reflect+0x108>
movsd  -0x18(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
subsd  %xmm1,%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121d <reflect+0x10d>
jmp    1222 <reflect+0x112>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118a <reflect+0x7a>

x86 assembly (clang, -O2):
<reflect>:
sub    $0x18,%rsp
movapd %xmm2,%xmm3
subsd  %xmm1,%xmm3
movsd  0xedc(%rip),%xmm4
ucomisd %xmm3,%xmm4
jbe    115a <reflect+0x4a>
lea    0xed7(%rip),%rdi
mov    $0x3,%al
movsd  %xmm2,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
movsd  %xmm1,(%rsp)
call   1030 <printf@plt>
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm2
ucomisd %xmm1,%xmm0
jbe    116b <reflect+0x5b>
ucomisd %xmm0,%xmm2
jbe    116b <reflect+0x5b>
add    $0x18,%rsp
ret
movapd %xmm1,%xmm4
addsd  %xmm1,%xmm4
xorpd  %xmm5,%xmm5
nopw   0x0(%rax,%rax,1)
ucomisd %xmm0,%xmm1
jae    11a0 <reflect+0x90>
ucomisd %xmm2,%xmm0
jae    11b0 <reflect+0xa0>
ucomisd %xmm1,%xmm0
jbe    1180 <reflect+0x70>
ucomisd %xmm0,%xmm2
jbe    1180 <reflect+0x70>
jmp    1166 <reflect+0x56>
nopw   0x0(%rax,%rax,1)
movapd %xmm4,%xmm3
subsd  %xmm0,%xmm3
addsd  %xmm5,%xmm3
jmp    11bc <reflect+0xac>
xchg   %ax,%ax
subsd  %xmm2,%xmm0
movapd %xmm2,%xmm3
subsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
ucomisd %xmm1,%xmm0
ja     1192 <reflect+0x82>
jmp    1180 <reflect+0x70>

LLVM IR (-O0):
@.str = [38 x i8] c"\0Aimproper range x0=%.6g (%.6g, %.6g)\0A\00"
define double @reflect(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
store i32 0, i32* %7
store i32 10000, i32* %8
%11 = load double, double* %4
store double %11, double* %9
store double 0x3D719799812DEA11, double* %10
%12 = load double, double* %6
%13 = load double, double* %5
%14 = fsub double %12, %13
%15 = load double, double* %10
%16 = fcmp olt double %14, %15
br i1 %16, label %17, label %22
17: ; preds = %3
%18 = load double, double* %9
%19 = load double, double* %5
%20 = load double, double* %6
%21 = call i32 (i8*, double, double, double, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), double %18, double %19, double %20)
br label %22
22: ; preds = %17, %3
store double 0.000000e+00, double* %10
br label %23
23: ; preds = %59, %22
%24 = load double, double* %4
%25 = load double, double* %5
%26 = fcmp ogt double %24, %25
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load double, double* %4
%29 = load double, double* %6
%30 = fcmp olt double %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load double, double* %4
ret double %32
33: ; preds = %27, %23
%34 = load double, double* %4
%35 = load double, double* %5
%36 = fcmp ole double %34, %35
br i1 %36, label %37, label %45
37: ; preds = %33
%38 = load double, double* %5
%39 = load double, double* %5
%40 = fadd double %38, %39
%41 = load double, double* %4
%42 = fsub double %40, %41
%43 = load double, double* %10
%44 = fadd double %42, %43
store double %44, double* %4
br label %58
45: ; preds = %33
%46 = load double, double* %4
%47 = load double, double* %6
%48 = fcmp oge double %46, %47
br i1 %48, label %49, label %57
49: ; preds = %45
%50 = load double, double* %6
%51 = load double, double* %4
%52 = load double, double* %6
%53 = fsub double %51, %52
%54 = fsub double %50, %53
%55 = load double, double* %10
%56 = fsub double %54, %55
store double %56, double* %4
br label %57
57: ; preds = %49, %45
br label %58
58: ; preds = %57, %37
br label %59
59: ; preds = %58
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 1
store i32 %61, i32* %7
br label %23
}

LLVM IR (-O2):
@.str = [38 x i8] c"\0Aimproper range x0=%.6g (%.6g, %.6g)\0A\00"
define double @reflect(double %0, double %1, double %2) {
%4 = fsub double %2, %1
%5 = fcmp olt double %4, 0x3D719799812DEA11
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 (i8*, double, double, double, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), double %0, double %1, double %2)
br label %8
8: ; preds = %6, %3
%9 = fcmp ogt double %0, %1
%10 = fcmp olt double %0, %2
%11 = and i1 %9, %10
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = fadd double %1, %1
br label %16
14: ; preds = %27, %8
%15 = phi double [ %0, %8 ], [ %28, %27 ]
ret double %15
16: ; preds = %12, %27
%17 = phi double [ %0, %12 ], [ %28, %27 ]
%18 = fcmp ugt double %17, %1
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = fsub double %13, %17
%21 = fadd double %20, 0.000000e+00
br label %27
22: ; preds = %16
%23 = fcmp ult double %17, %2
br i1 %23, label %27, label %24
24: ; preds = %22
%25 = fsub double %17, %2
%26 = fsub double %2, %25
br label %27
27: ; preds = %19, %24, %22
%28 = phi double [ %21, %19 ], [ %26, %24 ], [ %17, %22 ]
%29 = fcmp ogt double %28, %1
%30 = fcmp olt double %28, %2
%31 = and i1 %29, %30
br i1 %31, label %14, label %16
}