#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 ceil(double);
int /*<<< orphan*/ errAbort(char *, double, double);
int floor(double);
int /*<<< orphan*/ rangeIncludingZero(double, double, double *, double *);
void rangeRoundUp(double start, double end, double *retStart, double *retEnd) {
  double size = end - start;
  if (size < 0)
    errAbort("start (%g) after end (%g) in rangeRoundUp", start, end);
  if (size == 0.0) {
    rangeIncludingZero(start, end, &start, &end);
    size = end - start;
  }
  double exponent = 1;
  double scaledSize = size;
  double increment = 0;
  while (scaledSize < 100) {
    scaledSize *= 10;
    exponent /= 10;
  }
  while (scaledSize >= 100) {
    scaledSize /= 10;
    exponent *= 10;
  }
  if (scaledSize < 12)
    increment = 1;
  else if (scaledSize < 20)
    increment = 2;
  else if (scaledSize < 75)
    increment = 5;
  else
    increment = 10;
  increment *= exponent;
  int startInIncrements = floor(start / increment);
  int endInIncrements = ceil(end / increment);
  *retStart = startInIncrements * increment;
  *retEnd = endInIncrements * increment;
}


x86 assembly (clang, -O0):
<rangeRoundUp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    118d <rangeRoundUp+0x4d>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    0xeb8(%rip),%rdi
call   1040 <errAbort@plt>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11cb <rangeRoundUp+0x8b>
jp     11cb <rangeRoundUp+0x8b>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <rangeIncludingZero@plt>
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe2d(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe16(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    122a <rangeRoundUp+0xea>
movsd  0xe23(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe0c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11ea <rangeRoundUp+0xaa>
jmp    122f <rangeRoundUp+0xef>
movsd  -0x38(%rbp),%xmm0
movsd  0xdcc(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1273 <rangeRoundUp+0x133>
movsd  -0x38(%rbp),%xmm0
movsd  0xdd5(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xdc4(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    122f <rangeRoundUp+0xef>
movsd  0xd95(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    1298 <rangeRoundUp+0x158>
movsd  0xd72(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    12f9 <rangeRoundUp+0x1b9>
movsd  0xd78(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    12bd <rangeRoundUp+0x17d>
movsd  0xd85(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    12f4 <rangeRoundUp+0x1b4>
movsd  0xd5b(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    12e2 <rangeRoundUp+0x1a2>
movsd  0xd58(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    12ef <rangeRoundUp+0x1af>
movsd  0xd3e(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    12f4 <rangeRoundUp+0x1b4>
jmp    12f9 <rangeRoundUp+0x1b9>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
call   1060 <floor@plt>
mov    %eax,-0x44(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
call   1030 <ceil@plt>
mov    %eax,-0x48(%rbp)
cvtsi2sdl -0x44(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
cvtsi2sdl -0x48(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rangeRoundUp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  %xmm0,0x18(%rsp)
movsd  %xmm1,0x10(%rsp)
movapd %xmm1,%xmm4
subsd  %xmm0,%xmm4
xorpd  %xmm2,%xmm2
ucomisd %xmm4,%xmm2
jbe    11a6 <rangeRoundUp+0x66>
lea    0xed5(%rip),%rdi
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm1
movsd  %xmm0,0x28(%rsp)
movsd  %xmm4,0x20(%rsp)
call   1040 <errAbort@plt>
xorpd  %xmm2,%xmm2
movsd  0x8(%rsp),%xmm1
movsd  0x20(%rsp),%xmm4
movsd  0x28(%rsp),%xmm0
ucomisd %xmm2,%xmm4
jne    11cd <rangeRoundUp+0x8d>
jp     11cd <rangeRoundUp+0x8d>
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <rangeIncludingZero@plt>
movsd  0x10(%rsp),%xmm4
movsd  0x18(%rsp),%xmm0
subsd  %xmm0,%xmm4
movsd  0xe33(%rip),%xmm2
movsd  0xe23(%rip),%xmm3
ucomisd %xmm4,%xmm2
jbe    11fe <rangeRoundUp+0xbe>
movsd  0xe25(%rip),%xmm1
nopl   0x0(%rax,%rax,1)
mulsd  %xmm1,%xmm4
divsd  %xmm1,%xmm3
ucomisd %xmm4,%xmm2
ja     11f0 <rangeRoundUp+0xb0>
ucomisd 0xe02(%rip),%xmm4
jb     121e <rangeRoundUp+0xde>
movsd  0xe00(%rip),%xmm1
divsd  %xmm1,%xmm4
mulsd  %xmm1,%xmm3
ucomisd %xmm2,%xmm4
jae    1210 <rangeRoundUp+0xd0>
movsd  0xdf2(%rip),%xmm1
ucomisd %xmm4,%xmm1
jbe    1236 <rangeRoundUp+0xf6>
movsd  0xdcc(%rip),%xmm1
jmp    126b <rangeRoundUp+0x12b>
movsd  0xdea(%rip),%xmm1
ucomisd %xmm4,%xmm1
jbe    124e <rangeRoundUp+0x10e>
movsd  0xdd4(%rip),%xmm1
jmp    126b <rangeRoundUp+0x12b>
movsd  0xdda(%rip),%xmm1
xor    %eax,%eax
ucomisd %xmm4,%xmm1
seta   %al
lea    0xdd2(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm1
mulsd  %xmm1,%xmm3
movsd  %xmm3,0x8(%rsp)
divsd  %xmm3,%xmm0
call   1060 <floor@plt>
mov    %eax,%ebp
movsd  0x10(%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
call   1030 <ceil@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%r14)
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"start (%g) after end (%g) in rangeRoundUp\00"
define void @rangeRoundUp(double %0, double %1, double* %2, double* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
store double %0, double* %5
store double %1, double* %6
store double* %2, double** %7
store double* %3, double** %8
%15 = load double, double* %6
%16 = load double, double* %5
%17 = fsub double %15, %16
store double %17, double* %9
%18 = load double, double* %9
%19 = fcmp olt double %18, 0.000000e+00
br i1 %19, label %20, label %24
20: ; preds = %4
%21 = load double, double* %5
%22 = load double, double* %6
%23 = call i32 @errAbort(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), double %21, double %22)
br label %24
24: ; preds = %20, %4
%25 = load double, double* %9
%26 = fcmp oeq double %25, 0.000000e+00
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load double, double* %5
%29 = load double, double* %6
%30 = call i32 @rangeIncludingZero(double %28, double %29, double* %5, double* %6)
%31 = load double, double* %6
%32 = load double, double* %5
%33 = fsub double %31, %32
store double %33, double* %9
br label %34
34: ; preds = %27, %24
store double 1.000000e+00, double* %10
%35 = load double, double* %9
store double %35, double* %11
store double 0.000000e+00, double* %12
br label %36
36: ; preds = %39, %34
%37 = load double, double* %11
%38 = fcmp olt double %37, 1.000000e+02
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load double, double* %11
%41 = fmul double %40, 1.000000e+01
store double %41, double* %11
%42 = load double, double* %10
%43 = fdiv double %42, 1.000000e+01
store double %43, double* %10
br label %36
44: ; preds = %36
br label %45
45: ; preds = %48, %44
%46 = load double, double* %11
%47 = fcmp oge double %46, 1.000000e+02
br i1 %47, label %48, label %53
48: ; preds = %45
%49 = load double, double* %11
%50 = fdiv double %49, 1.000000e+01
store double %50, double* %11
%51 = load double, double* %10
%52 = fmul double %51, 1.000000e+01
store double %52, double* %10
br label %45
53: ; preds = %45
%54 = load double, double* %11
%55 = fcmp olt double %54, 1.200000e+01
br i1 %55, label %56, label %57
56: ; preds = %53
store double 1.000000e+00, double* %12
br label %68
57: ; preds = %53
%58 = load double, double* %11
%59 = fcmp olt double %58, 2.000000e+01
br i1 %59, label %60, label %61
60: ; preds = %57
store double 2.000000e+00, double* %12
br label %67
61: ; preds = %57
%62 = load double, double* %11
%63 = fcmp olt double %62, 7.500000e+01
br i1 %63, label %64, label %65
64: ; preds = %61
store double 5.000000e+00, double* %12
br label %66
65: ; preds = %61
store double 1.000000e+01, double* %12
br label %66
66: ; preds = %65, %64
br label %67
67: ; preds = %66, %60
br label %68
68: ; preds = %67, %56
%69 = load double, double* %10
%70 = load double, double* %12
%71 = fmul double %70, %69
store double %71, double* %12
%72 = load double, double* %5
%73 = load double, double* %12
%74 = fdiv double %72, %73
%75 = call i32 @floor(double %74)
store i32 %75, i32* %13
%76 = load double, double* %6
%77 = load double, double* %12
%78 = fdiv double %76, %77
%79 = call i32 @ceil(double %78)
store i32 %79, i32* %14
%80 = load i32, i32* %13
%81 = sitofp i32 %80 to double
%82 = load double, double* %12
%83 = fmul double %81, %82
%84 = load double*, double** %7
store double %83, double* %84
%85 = load i32, i32* %14
%86 = sitofp i32 %85 to double
%87 = load double, double* %12
%88 = fmul double %86, %87
%89 = load double*, double** %8
store double %88, double* %89
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"start (%g) after end (%g) in rangeRoundUp\00"
define void @rangeRoundUp(double %0, double %1, double* nocapture writeonly %2, double* nocapture writeonly %3) {
%5 = alloca double
%6 = alloca double
store double %0, double* %5
store double %1, double* %6
%7 = fsub double %1, %0
%8 = fcmp olt double %7, 0.000000e+00
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @errAbort(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), double %0, double %1)
br label %11
11: ; preds = %9, %4
%12 = fcmp oeq double %7, 0.000000e+00
br i1 %12, label %13, label %18
13: ; preds = %11
%14 = call i32 @rangeIncludingZero(double %0, double %1, double* %5, double* %6)
%15 = load double, double* %6
%16 = load double, double* %5
%17 = fsub double %15, %16
br label %18
18: ; preds = %13, %11
%19 = phi double [ %16, %13 ], [ %0, %11 ]
%20 = phi double [ %17, %13 ], [ %7, %11 ]
%21 = fcmp olt double %20, 1.000000e+02
br i1 %21, label %26, label %22
22: ; preds = %26, %18
%23 = phi double [ %20, %18 ], [ %29, %26 ]
%24 = phi double [ 1.000000e+00, %18 ], [ %30, %26 ]
%25 = fcmp ult double %23, 1.000000e+02
br i1 %25, label %38, label %32
26: ; preds = %18, %26
%27 = phi double [ %30, %26 ], [ 1.000000e+00, %18 ]
%28 = phi double [ %29, %26 ], [ %20, %18 ]
%29 = fmul double %28, 1.000000e+01
%30 = fdiv double %27, 1.000000e+01
%31 = fcmp olt double %29, 1.000000e+02
br i1 %31, label %26, label %22
32: ; preds = %22, %32
%33 = phi double [ %36, %32 ], [ %24, %22 ]
%34 = phi double [ %35, %32 ], [ %23, %22 ]
%35 = fdiv double %34, 1.000000e+01
%36 = fmul double %33, 1.000000e+01
%37 = fcmp ult double %35, 1.000000e+02
br i1 %37, label %38, label %32
38: ; preds = %32, %22
%39 = phi double [ %23, %22 ], [ %35, %32 ]
%40 = phi double [ %24, %22 ], [ %36, %32 ]
%41 = fcmp olt double %39, 1.200000e+01
br i1 %41, label %47, label %42
42: ; preds = %38
%43 = fcmp olt double %39, 2.000000e+01
br i1 %43, label %47, label %44
44: ; preds = %42
%45 = fcmp olt double %39, 7.500000e+01
%46 = select i1 %45, double 5.000000e+00, double 1.000000e+01
br label %47
47: ; preds = %44, %42, %38
%48 = phi double [ 1.000000e+00, %38 ], [ 2.000000e+00, %42 ], [ %46, %44 ]
%49 = fmul double %40, %48
%50 = fdiv double %19, %49
%51 = call i32 @floor(double %50)
%52 = load double, double* %6
%53 = fdiv double %52, %49
%54 = call i32 @ceil(double %53)
%55 = sitofp i32 %51 to double
%56 = fmul double %49, %55
store double %56, double* %2
%57 = sitofp i32 %54 to double
%58 = fmul double %49, %57
store double %58, double* %3
ret void
}