#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 floor(int /*<<< orphan*/);
int /*<<< orphan*/ log10(double);
double pow(int, int);
double JGPL_Plot_internal_nicenum(double x, int round) {
  int expv;
  double f;
  double nf;
  expv = floor(log10(x));
  f = x / pow(10., expv);
  if (round) {
    if (f < 1.5)
      nf = 1.;
    else if (f < 3.)
      nf = 2.;
    else if (f < 7.)
      nf = 5.;
    else
      nf = 10.;
  } else {
    if (f <= 1.)
      nf = 1.;
    else if (f <= 2.)
      nf = 2.;
    else if (f <= 5.)
      nf = 5.;
    else
      nf = 10.;
  }
  return nf * pow(10., expv);
}


x86 assembly (clang, -O0):
<JGPL_Plot_internal_nicenum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <log10@plt>
mov    %eax,%edi
call   1050 <floor@plt>
mov    %eax,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%esi
mov    $0xa,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1211 <JGPL_Plot_internal_nicenum+0xe1>
movsd  0xe92(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11ab <JGPL_Plot_internal_nicenum+0x7b>
movsd  0xe5f(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    120c <JGPL_Plot_internal_nicenum+0xdc>
movsd  0xe75(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11d0 <JGPL_Plot_internal_nicenum+0xa0>
movsd  0xe42(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1207 <JGPL_Plot_internal_nicenum+0xd7>
movsd  0xe58(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11f5 <JGPL_Plot_internal_nicenum+0xc5>
movsd  0xe25(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1202 <JGPL_Plot_internal_nicenum+0xd2>
movsd  0xe1b(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1207 <JGPL_Plot_internal_nicenum+0xd7>
jmp    120c <JGPL_Plot_internal_nicenum+0xdc>
jmp    129c <JGPL_Plot_internal_nicenum+0x16c>
movsd  0xde7(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1236 <JGPL_Plot_internal_nicenum+0x106>
movsd  0xdd4(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1297 <JGPL_Plot_internal_nicenum+0x167>
movsd  0xdca(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     125b <JGPL_Plot_internal_nicenum+0x12b>
movsd  0xdb7(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1292 <JGPL_Plot_internal_nicenum+0x162>
movsd  0xdad(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1280 <JGPL_Plot_internal_nicenum+0x150>
movsd  0xd9a(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    128d <JGPL_Plot_internal_nicenum+0x15d>
movsd  0xd90(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1292 <JGPL_Plot_internal_nicenum+0x162>
jmp    1297 <JGPL_Plot_internal_nicenum+0x167>
jmp    129c <JGPL_Plot_internal_nicenum+0x16c>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%esi
mov    $0xa,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<JGPL_Plot_internal_nicenum>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
movsd  %xmm0,(%rsp)
call   1040 <log10@plt>
mov    %eax,%edi
call   1050 <floor@plt>
mov    %eax,%ebx
mov    $0xa,%edi
mov    %eax,%esi
call   1030 <pow@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
test   %ebp,%ebp
je     1179 <JGPL_Plot_internal_nicenum+0x49>
movsd  0xe9f(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11af <JGPL_Plot_internal_nicenum+0x7f>
movsd  0xe89(%rip),%xmm0
jmp    11e4 <JGPL_Plot_internal_nicenum+0xb4>
movsd  0xe7f(%rip),%xmm0
ucomisd %xmm1,%xmm0
jae    11e4 <JGPL_Plot_internal_nicenum+0xb4>
movsd  0xe81(%rip),%xmm0
ucomisd %xmm1,%xmm0
jae    11e4 <JGPL_Plot_internal_nicenum+0xb4>
movsd  0xe8b(%rip),%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
setb   %al
lea    0xe93(%rip),%rcx
jmp    11df <JGPL_Plot_internal_nicenum+0xaf>
movsd  0xe61(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c7 <JGPL_Plot_internal_nicenum+0x97>
movsd  0xe4b(%rip),%xmm0
jmp    11e4 <JGPL_Plot_internal_nicenum+0xb4>
movsd  0xe51(%rip),%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
seta   %al
lea    0xe51(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
movsd  %xmm0,(%rsp)
mov    $0xa,%edi
mov    %ebx,%esi
call   1030 <pow@plt>
mulsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @JGPL_Plot_internal_nicenum(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca double
store double %0, double* %3
store i32 %1, i32* %4
%8 = load double, double* %3
%9 = call i32 @log10(double %8)
%10 = call i32 @floor(i32 %9)
store i32 %10, i32* %5
%11 = load double, double* %3
%12 = load i32, i32* %5
%13 = call double @pow(i32 10, i32 %12)
%14 = fdiv double %11, %13
store double %14, double* %6
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %33
17: ; preds = %2
%18 = load double, double* %6
%19 = fcmp olt double %18, 1.500000e+00
br i1 %19, label %20, label %21
20: ; preds = %17
store double 1.000000e+00, double* %7
br label %32
21: ; preds = %17
%22 = load double, double* %6
%23 = fcmp olt double %22, 3.000000e+00
br i1 %23, label %24, label %25
24: ; preds = %21
store double 2.000000e+00, double* %7
br label %31
25: ; preds = %21
%26 = load double, double* %6
%27 = fcmp olt double %26, 7.000000e+00
br i1 %27, label %28, label %29
28: ; preds = %25
store double 5.000000e+00, double* %7
br label %30
29: ; preds = %25
store double 1.000000e+01, double* %7
br label %30
30: ; preds = %29, %28
br label %31
31: ; preds = %30, %24
br label %32
32: ; preds = %31, %20
br label %49
33: ; preds = %2
%34 = load double, double* %6
%35 = fcmp ole double %34, 1.000000e+00
br i1 %35, label %36, label %37
36: ; preds = %33
store double 1.000000e+00, double* %7
br label %48
37: ; preds = %33
%38 = load double, double* %6
%39 = fcmp ole double %38, 2.000000e+00
br i1 %39, label %40, label %41
40: ; preds = %37
store double 2.000000e+00, double* %7
br label %47
41: ; preds = %37
%42 = load double, double* %6
%43 = fcmp ole double %42, 5.000000e+00
br i1 %43, label %44, label %45
44: ; preds = %41
store double 5.000000e+00, double* %7
br label %46
45: ; preds = %41
store double 1.000000e+01, double* %7
br label %46
46: ; preds = %45, %44
br label %47
47: ; preds = %46, %40
br label %48
48: ; preds = %47, %36
br label %49
49: ; preds = %48, %32
%50 = load double, double* %7
%51 = load i32, i32* %5
%52 = call double @pow(i32 10, i32 %51)
%53 = fmul double %50, %52
ret double %53
}

LLVM IR (-O2):
define double @JGPL_Plot_internal_nicenum(double %0, i32 %1) {
%3 = tail call i32 @log10(double %0)
%4 = tail call i32 @floor(i32 %3)
%5 = tail call double @pow(i32 10, i32 %4)
%6 = fdiv double %0, %5
%7 = icmp eq i32 %1, 0
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = fcmp olt double %6, 1.500000e+00
br i1 %9, label %22, label %10
10: ; preds = %8
%11 = fcmp olt double %6, 3.000000e+00
br i1 %11, label %22, label %12
12: ; preds = %10
%13 = fcmp olt double %6, 7.000000e+00
%14 = select i1 %13, double 5.000000e+00, double 1.000000e+01
br label %22
15: ; preds = %2
%16 = fcmp ugt double %6, 1.000000e+00
br i1 %16, label %17, label %22
17: ; preds = %15
%18 = fcmp ugt double %6, 2.000000e+00
br i1 %18, label %19, label %22
19: ; preds = %17
%20 = fcmp ugt double %6, 5.000000e+00
%21 = select i1 %20, double 1.000000e+01, double 5.000000e+00
br label %22
22: ; preds = %19, %17, %15, %12, %10, %8
%23 = phi double [ 1.000000e+00, %8 ], [ 2.000000e+00, %10 ], [ %14, %12 ], [ 1.000000e+00, %15 ], [ 2.000000e+00, %17 ], [ %21, %19 ]
%24 = tail call double @pow(i32 10, i32 %4)
%25 = fmul double %23, %24
ret double %25
}