#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 exp(double);
double floor(double);
double log(double);
double find_step(double first, double last, int num_ticks) {
  int mini_step[3] = {1, 2, 5};
  int cur_mini_step = 0;
  double step = (last - first) / num_ticks;
  double log10 = log(10);
  step = exp(floor(log(step) / log10) * log10);
  while (cur_mini_step < 3 &&
         (last - first) / (step * mini_step[cur_mini_step]) > num_ticks)
    cur_mini_step++;
  if (cur_mini_step > 0)
    step *= mini_step[cur_mini_step - 1];
  return step;
}


x86 assembly (clang, -O0):
<find_step>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    0xebc(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeba(%rip),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe80(%rip),%xmm0
call   1040 <log@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <log@plt>
divsd  -0x38(%rbp),%xmm0
call   1050 <floor@plt>
mulsd  -0x38(%rbp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x30(%rbp)
xor    %eax,%eax
cmpl   $0x3,-0x24(%rbp)
mov    %al,-0x39(%rbp)
jge    11ec <find_step+0xbc>
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movslq -0x24(%rbp),%rax
cvtsi2sdl -0x20(%rbp,%rax,4),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11fc <find_step+0xcc>
jmp    120a <find_step+0xda>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ad <find_step+0x7d>
cmpl   $0x0,-0x24(%rbp)
jle    122c <find_step+0xfc>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cltq
cvtsi2sdl -0x20(%rbp,%rax,4),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_step>:
sub    $0x18,%rsp
subsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
cvtsi2sd %edi,%xmm2
movsd  %xmm2,0x8(%rsp)
movapd %xmm1,%xmm0
divsd  %xmm2,%xmm0
call   1040 <log@plt>
divsd  0xea3(%rip),%xmm0
call   1050 <floor@plt>
mulsd  0xe96(%rip),%xmm0
call   1030 <exp@plt>
movsd  0x8(%rsp),%xmm4
movsd  0x10(%rsp),%xmm3
movapd %xmm3,%xmm1
divsd  %xmm0,%xmm1
ucomisd %xmm4,%xmm1
jbe    11dd <find_step+0xad>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm3,%xmm2
divsd  %xmm1,%xmm2
mov    $0x1,%ecx
ucomisd %xmm4,%xmm2
jbe    11c4 <find_step+0x94>
movsd  0xe5c(%rip),%xmm1
mulsd  %xmm0,%xmm1
divsd  %xmm1,%xmm3
mov    $0x2,%ecx
mov    $0x3,%eax
ucomisd %xmm4,%xmm3
ja     11c7 <find_step+0x97>
mov    %rcx,%rax
add    $0xffffffff,%eax
lea    0xe3f(%rip),%rcx
xorps  %xmm1,%xmm1
cvtsi2sdl (%rcx,%rax,4),%xmm1
mulsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@__const.find_step.mini_step = [3 x i32] [i32 1, i32 2, i32 5]
define double @find_step(double %0, double %1, i32 %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca [3 x i32]
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store double %0, double* %4
store double %1, double* %5
store i32 %2, i32* %6
%11 = bitcast [3 x i32]* %7 to i8*
store i32 0, i32* %8
%12 = load double, double* %5
%13 = load double, double* %4
%14 = fsub double %12, %13
%15 = load i32, i32* %6
%16 = sitofp i32 %15 to double
%17 = fdiv double %14, %16
store double %17, double* %9
%18 = call double @log(double 1.000000e+01)
store double %18, double* %10
%19 = load double, double* %9
%20 = call double @log(double %19)
%21 = load double, double* %10
%22 = fdiv double %20, %21
%23 = call double @llvm.floor.f64(double %22)
%24 = load double, double* %10
%25 = fmul double %23, %24
%26 = call double @exp(double %25)
store double %26, double* %9
br label %27
27: ; preds = %47, %3
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 3
br i1 %29, label %30, label %45
30: ; preds = %27
%31 = load double, double* %5
%32 = load double, double* %4
%33 = fsub double %31, %32
%34 = load double, double* %9
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = sitofp i32 %38 to double
%40 = fmul double %34, %39
%41 = fdiv double %33, %40
%42 = load i32, i32* %6
%43 = sitofp i32 %42 to double
%44 = fcmp ogt double %41, %43
br label %45
45: ; preds = %30, %27
%46 = phi i1 [ false, %27 ], [ %44, %30 ]
br i1 %46, label %47, label %50
47: ; preds = %45
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %27
50: ; preds = %45
%51 = load i32, i32* %8
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %62
53: ; preds = %50
%54 = load i32, i32* %8
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = sitofp i32 %58 to double
%60 = load double, double* %9
%61 = fmul double %60, %59
store double %61, double* %9
br label %62
62: ; preds = %53, %50
%63 = load double, double* %9
ret double %63
}

LLVM IR (-O2):
@__const.find_step.mini_step = [3 x i32] [i32 1, i32 2, i32 5]
define double @find_step(double %0, double %1, i32 %2) {
%4 = fsub double %1, %0
%5 = sitofp i32 %2 to double
%6 = fdiv double %4, %5
%7 = tail call double @log(double %6)
%8 = fdiv double %7, 0x40026BB1BBB55516
%9 = tail call double @llvm.floor.f64(double %8)
%10 = fmul double %9, 0x40026BB1BBB55516
%11 = tail call double @exp(double %10)
%12 = fdiv double %4, %11
%13 = fcmp ogt double %12, %5
br i1 %13, label %14, label %32
14: ; preds = %3
%15 = fmul double %11, 2.000000e+00
%16 = fdiv double %4, %15
%17 = fcmp ogt double %16, %5
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = fmul double %11, 5.000000e+00
%20 = fdiv double %4, %19
%21 = fcmp ogt double %20, %5
br i1 %21, label %24, label %22
22: ; preds = %18, %14
%23 = phi i64 [ 1, %14 ], [ 2, %18 ]
br label %24
24: ; preds = %22, %18
%25 = phi i64 [ 3, %18 ], [ %23, %22 ]
%26 = add nuw nsw i64 %25, 4294967295
%27 = and i64 %26, 4294967295
%28 = getelementptr inbounds [3 x i32], [3 x i32]* @__const.find_step.mini_step, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = sitofp i32 %29 to double
%31 = fmul double %11, %30
br label %32
32: ; preds = %3, %24
%33 = phi double [ %31, %24 ], [ %11, %3 ]
ret double %33
}