#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 ceil(double);
double floor(double);
double log10(double);
double pow(double, double);
void sensible_limits(double xlo, double xhi, double *res_lo, double *res_hi,
                     double *res_delta) {
  double scale, rel_hi, rel_delta;
  if (xlo > xhi) {
    double temp = xlo;
    xlo = xhi;
    xhi = temp;
  }
  if (xhi - xlo < 1e-50) {
    double xmid = (xlo + xhi) / 2.0;
    xlo = xmid - 1e-50;
    xhi = xmid + 1e-50;
  }
  scale = pow(10.0, ceil(-log10(xhi - xlo)));
  rel_hi = scale * (xhi - xlo);
  rel_delta = (rel_hi < 1.5)   ? 0.2
              : (rel_hi < 2.5) ? 0.5
              : (rel_hi < 5.0) ? 1.0
                               : 2.0;
  *res_delta = rel_delta / scale;
  *res_lo = *res_delta * floor(xlo / *res_delta);
  *res_hi = *res_delta * ceil(xhi / *res_delta);
}


x86 assembly (clang, -O0):
<sensible_limits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    118c <sensible_limits+0x4c>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
subsd  -0x8(%rbp),%xmm1
movsd  0xe62(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11eb <sensible_limits+0xab>
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xe4e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  0xe30(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xe1f(%rip),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
call   1050 <log10@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <ceil@plt>
movaps %xmm0,%xmm1
movsd  0xdf7(%rip),%xmm0
call   1040 <pow@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
subsd  -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xdc5(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    1268 <sensible_limits+0x128>
movsd  0xde2(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    12cd <sensible_limits+0x18d>
movsd  0xdb0(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    128d <sensible_limits+0x14d>
movsd  0xdb5(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    12c3 <sensible_limits+0x183>
movsd  -0x38(%rbp),%xmm0
movsd  0xd8e(%rip),%xmm3
movsd  0xd66(%rip),%xmm2
movsd  0xd86(%rip),%xmm1
cmpltsd %xmm1,%xmm0
movaps %xmm0,%xmm1
andpd  %xmm3,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x28(%rbp),%rax
divsd  (%rax),%xmm0
call   1060 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x28(%rbp),%rax
divsd  (%rax),%xmm0
call   1030 <ceil@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sensible_limits>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
movapd %xmm0,%xmm5
maxsd  %xmm1,%xmm5
minsd  %xmm0,%xmm1
movapd %xmm5,%xmm4
subsd  %xmm1,%xmm4
movsd  0xe92(%rip),%xmm2
ucomisd %xmm4,%xmm2
movapd %xmm1,%xmm0
addsd  %xmm5,%xmm0
mulsd  0xe86(%rip),%xmm0
movapd %xmm0,%xmm3
addsd  %xmm2,%xmm3
cmpltsd %xmm2,%xmm4
andpd  %xmm4,%xmm3
andnpd %xmm5,%xmm4
orpd   %xmm3,%xmm4
jbe    11a9 <sensible_limits+0x69>
addsd  0xe6b(%rip),%xmm0
movapd %xmm0,%xmm1
movapd %xmm4,0x20(%rsp)
movapd %xmm4,%xmm0
movsd  %xmm1,0x8(%rsp)
subsd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
call   1050 <log10@plt>
xorpd  0xe70(%rip),%xmm0
call   1030 <ceil@plt>
movapd %xmm0,%xmm1
movsd  0xe37(%rip),%xmm0
call   1040 <pow@plt>
movapd 0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  0xe30(%rip),%xmm1
ucomisd %xmm2,%xmm1
jbe    1208 <sensible_limits+0xc8>
movsd  0xe1a(%rip),%xmm2
jmp    123d <sensible_limits+0xfd>
movsd  0xe20(%rip),%xmm1
ucomisd %xmm2,%xmm1
jbe    1220 <sensible_limits+0xe0>
movsd  0xdea(%rip),%xmm2
jmp    123d <sensible_limits+0xfd>
movsd  0xe10(%rip),%xmm1
xor    %eax,%eax
ucomisd %xmm2,%xmm1
seta   %al
lea    0xe18(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm2
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  %xmm2,(%rbx)
divsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
call   1060 <floor@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r15)
movsd  (%rbx),%xmm1
movsd  %xmm1,0x8(%rsp)
movapd 0x20(%rsp),%xmm0
divsd  %xmm1,%xmm0
call   1030 <ceil@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r14)
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @sensible_limits(double %0, double %1, double* %2, double* %3, double* %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double %0, double* %6
store double %1, double* %7
store double* %2, double** %8
store double* %3, double** %9
store double* %4, double** %10
%16 = load double, double* %6
%17 = load double, double* %7
%18 = fcmp ogt double %16, %17
br i1 %18, label %19, label %23
19: ; preds = %5
%20 = load double, double* %6
store double %20, double* %14
%21 = load double, double* %7
store double %21, double* %6
%22 = load double, double* %14
store double %22, double* %7
br label %23
23: ; preds = %19, %5
%24 = load double, double* %7
%25 = load double, double* %6
%26 = fsub double %24, %25
%27 = fcmp olt double %26, 1.000000e-50
br i1 %27, label %28, label %37
28: ; preds = %23
%29 = load double, double* %6
%30 = load double, double* %7
%31 = fadd double %29, %30
%32 = fdiv double %31, 2.000000e+00
store double %32, double* %15
%33 = load double, double* %15
%34 = fsub double %33, 1.000000e-50
store double %34, double* %6
%35 = load double, double* %15
%36 = fadd double %35, 1.000000e-50
store double %36, double* %7
br label %37
37: ; preds = %28, %23
%38 = load double, double* %7
%39 = load double, double* %6
%40 = fsub double %38, %39
%41 = call double @log10(double %40)
%42 = fneg double %41
%43 = call double @llvm.ceil.f64(double %42)
%44 = call double @pow(double 1.000000e+01, double %43)
store double %44, double* %11
%45 = load double, double* %11
%46 = load double, double* %7
%47 = load double, double* %6
%48 = fsub double %46, %47
%49 = fmul double %45, %48
store double %49, double* %12
%50 = load double, double* %12
%51 = fcmp olt double %50, 1.500000e+00
br i1 %51, label %52, label %53
52: ; preds = %37
br label %64
53: ; preds = %37
%54 = load double, double* %12
%55 = fcmp olt double %54, 2.500000e+00
br i1 %55, label %56, label %57
56: ; preds = %53
br label %62
57: ; preds = %53
%58 = load double, double* %12
%59 = fcmp olt double %58, 5.000000e+00
%60 = zext i1 %59 to i64
%61 = select i1 %59, double 1.000000e+00, double 2.000000e+00
br label %62
62: ; preds = %57, %56
%63 = phi double [ 5.000000e-01, %56 ], [ %61, %57 ]
br label %64
64: ; preds = %62, %52
%65 = phi double [ 2.000000e-01, %52 ], [ %63, %62 ]
store double %65, double* %13
%66 = load double, double* %13
%67 = load double, double* %11
%68 = fdiv double %66, %67
%69 = load double*, double** %10
store double %68, double* %69
%70 = load double*, double** %10
%71 = load double, double* %70
%72 = load double, double* %6
%73 = load double*, double** %10
%74 = load double, double* %73
%75 = fdiv double %72, %74
%76 = call double @llvm.floor.f64(double %75)
%77 = fmul double %71, %76
%78 = load double*, double** %8
store double %77, double* %78
%79 = load double*, double** %10
%80 = load double, double* %79
%81 = load double, double* %7
%82 = load double*, double** %10
%83 = load double, double* %82
%84 = fdiv double %81, %83
%85 = call double @llvm.ceil.f64(double %84)
%86 = fmul double %80, %85
%87 = load double*, double** %9
store double %86, double* %87
ret void
}

LLVM IR (-O2):
define void @sensible_limits(double %0, double %1, double* nocapture writeonly %2, double* nocapture writeonly %3, double* nocapture %4) {
%6 = fcmp ogt double %0, %1
%7 = select i1 %6, double %0, double %1
%8 = select i1 %6, double %1, double %0
%9 = fsub double %7, %8
%10 = fcmp olt double %9, 1.000000e-50
%11 = fadd double %8, %7
%12 = fmul double %11, 5.000000e-01
%13 = fadd double %12, -1.000000e-50
%14 = fadd double %12, 1.000000e-50
%15 = select i1 %10, double %14, double %7
%16 = select i1 %10, double %13, double %8
%17 = fsub double %15, %16
%18 = tail call double @log10(double %17)
%19 = fneg double %18
%20 = tail call double @llvm.ceil.f64(double %19)
%21 = tail call double @pow(double 1.000000e+01, double %20)
%22 = fmul double %17, %21
%23 = fcmp olt double %22, 1.500000e+00
br i1 %23, label %29, label %24
24: ; preds = %5
%25 = fcmp olt double %22, 2.500000e+00
br i1 %25, label %29, label %26
26: ; preds = %24
%27 = fcmp olt double %22, 5.000000e+00
%28 = select i1 %27, double 1.000000e+00, double 2.000000e+00
br label %29
29: ; preds = %26, %24, %5
%30 = phi double [ 2.000000e-01, %5 ], [ %28, %26 ], [ 5.000000e-01, %24 ]
%31 = fdiv double %30, %21
store double %31, double* %4
%32 = fdiv double %16, %31
%33 = tail call double @llvm.floor.f64(double %32)
%34 = fmul double %31, %33
store double %34, double* %2
%35 = load double, double* %4
%36 = fdiv double %15, %35
%37 = tail call double @llvm.ceil.f64(double %36)
%38 = fmul double %35, %37
store double %38, double* %3
ret void
}