#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*/ floor(int);
int log(double);
double pow(double, int /*<<< orphan*/);
double calc_step_size(double range, size_t graph_height) {
  const unsigned int factors[] = {1, 2, 5};
  unsigned int i;
  double min_step = range / (graph_height / 14.0);
  double mag = pow(10.0, floor(log(min_step) / log(10.0)));
  for (i = 0; i < 3; ++i)
    if (mag * factors[i] >= min_step)
      return mag * factors[i];
  return mag * 10;
}


x86 assembly (clang, -O0):
<calc_step_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    0xef1(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xedf(%rip),%rax
mov    %rax,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xeaf(%rip),%xmm2
movq   -0x18(%rbp),%xmm1
punpckldq %xmm2,%xmm1
movapd 0xeae(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
movsd  0xe7f(%rip),%xmm2
divsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <log@plt>
mov    %eax,-0x44(%rbp)
movsd  0xe55(%rip),%xmm0
call   1030 <log@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <floor@plt>
mov    %eax,%edi
movsd  0xe37(%rip),%xmm0
call   1040 <pow@plt>
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x2c(%rbp)
jae    1236 <calc_step_size+0x106>
movsd  -0x40(%rbp),%xmm0
mov    -0x2c(%rbp),%eax
mov    -0x28(%rbp,%rax,4),%eax
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     1223 <calc_step_size+0xf3>
movsd  -0x40(%rbp),%xmm0
mov    -0x2c(%rbp),%eax
mov    -0x28(%rbp,%rax,4),%eax
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1248 <calc_step_size+0x118>
jmp    1228 <calc_step_size+0xf8>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11da <calc_step_size+0xaa>
movsd  0xdc2(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_step_size>:
push   %rbx
sub    $0x10,%rsp
movq   %rdi,%xmm1
punpckldq 0xebe(%rip),%xmm1
subpd  0xec6(%rip),%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  0xec2(%rip),%xmm2
divsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <log@plt>
mov    %eax,%ebx
movsd  0xeb1(%rip),%xmm0
call   1030 <log@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <floor@plt>
movsd  0xe96(%rip),%xmm0
mov    %eax,%edi
call   1040 <pow@plt>
movsd  0x8(%rsp),%xmm2
ucomisd %xmm2,%xmm0
movapd %xmm0,%xmm1
jae    11d5 <calc_step_size+0xa5>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
ucomisd %xmm2,%xmm1
jae    11d5 <calc_step_size+0xa5>
movsd  0xe71(%rip),%xmm1
mulsd  %xmm0,%xmm1
ucomisd %xmm2,%xmm1
jae    11d5 <calc_step_size+0xa5>
mulsd  0xe57(%rip),%xmm0
movapd %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.calc_step_size.factors = [3 x i32] [i32 1, i32 2, i32 5]
define double @calc_step_size(double %0, i64 %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i64
%6 = alloca [3 x i32]
%7 = alloca i32
%8 = alloca double
%9 = alloca double
store double %0, double* %4
store i64 %1, i64* %5
%10 = bitcast [3 x i32]* %6 to i8*
%11 = load double, double* %4
%12 = load i64, i64* %5
%13 = uitofp i64 %12 to double
%14 = fdiv double %13, 1.400000e+01
%15 = fdiv double %11, %14
store double %15, double* %8
%16 = load double, double* %8
%17 = call i32 @log(double %16)
%18 = call i32 @log(double 1.000000e+01)
%19 = sdiv i32 %17, %18
%20 = call i32 @floor(i32 %19)
%21 = call double @pow(double 1.000000e+01, i32 %20)
store double %21, double* %9
store i32 0, i32* %7
br label %22
22: ; preds = %44, %2
%23 = load i32, i32* %7
%24 = icmp ult i32 %23, 3
br i1 %24, label %25, label %47
25: ; preds = %22
%26 = load double, double* %9
%27 = load i32, i32* %7
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = uitofp i32 %30 to double
%32 = fmul double %26, %31
%33 = load double, double* %8
%34 = fcmp oge double %32, %33
br i1 %34, label %35, label %43
35: ; preds = %25
%36 = load double, double* %9
%37 = load i32, i32* %7
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = uitofp i32 %40 to double
%42 = fmul double %36, %41
store double %42, double* %3
br label %50
43: ; preds = %25
br label %44
44: ; preds = %43
%45 = load i32, i32* %7
%46 = add i32 %45, 1
store i32 %46, i32* %7
br label %22
47: ; preds = %22
%48 = load double, double* %9
%49 = fmul double %48, 1.000000e+01
store double %49, double* %3
br label %50
50: ; preds = %47, %35
%51 = load double, double* %3
ret double %51
}

LLVM IR (-O2):
define double @calc_step_size(double %0, i64 %1) {
%3 = uitofp i64 %1 to double
%4 = fdiv double %3, 1.400000e+01
%5 = fdiv double %0, %4
%6 = tail call i32 @log(double %5)
%7 = tail call i32 @log(double 1.000000e+01)
%8 = sdiv i32 %6, %7
%9 = tail call i32 @floor(i32 %8)
%10 = tail call double @pow(double 1.000000e+01, i32 %9)
%11 = fcmp ult double %10, %5
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = fmul double %10, 2.000000e+00
%14 = fcmp ult double %13, %5
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = fmul double %10, 5.000000e+00
%17 = fcmp ult double %16, %5
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = fmul double %10, 1.000000e+01
br label %20
20: ; preds = %2, %12, %15, %18
%21 = phi double [ %19, %18 ], [ %10, %2 ], [ %13, %12 ], [ %16, %15 ]
ret double %21
}