#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(double, double);
double nicenum(double x, int round) {
  int exp;
  double f;
  double nf;
  exp = floor(log10(x));
  f = x / pow(10.0, (double)(exp));
  if (round)
    if (f < 1.5)
      nf = 1.0;
    else if (f < 3.0)
      nf = 2.0;
    else if (f < 7.0)
      nf = 5.0;
    else
      nf = 10.0;
  else if (f <= 1.0)
    nf = 1.0;
  else if (f <= 2.0)
    nf = 2.0;
  else if (f <= 5.0)
    nf = 5.0;
  else
    nf = 10.0;
  return nf * pow(10.0, (double)(exp));
}


x86 assembly (clang, -O0):
<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)
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  0xe95(%rip),%xmm0
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1216 <nicenum+0xe6>
movsd  0xe8d(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11b0 <nicenum+0x80>
movsd  0xe62(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1211 <nicenum+0xe1>
movsd  0xe70(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11d5 <nicenum+0xa5>
movsd  0xe45(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    120c <nicenum+0xdc>
movsd  0xe53(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11fa <nicenum+0xca>
movsd  0xe28(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1207 <nicenum+0xd7>
movsd  0xdfe(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    120c <nicenum+0xdc>
jmp    1211 <nicenum+0xe1>
jmp    12a1 <nicenum+0x171>
movsd  0xdea(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     123b <nicenum+0x10b>
movsd  0xdd7(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    129c <nicenum+0x16c>
movsd  0xdcd(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1260 <nicenum+0x130>
movsd  0xdba(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1297 <nicenum+0x167>
movsd  0xdb0(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1285 <nicenum+0x155>
movsd  0xd9d(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1292 <nicenum+0x162>
movsd  0xd73(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1297 <nicenum+0x167>
jmp    129c <nicenum+0x16c>
jmp    12a1 <nicenum+0x171>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  0xd48(%rip),%xmm0
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nicenum>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movsd  %xmm0,0x8(%rsp)
call   1040 <log10@plt>
mov    %eax,%edi
call   1050 <floor@plt>
cvtsi2sd %eax,%xmm1
movsd  0xeab(%rip),%xmm0
movsd  %xmm1,(%rsp)
call   1030 <pow@plt>
movsd  0x8(%rsp),%xmm2
divsd  %xmm0,%xmm2
test   %ebx,%ebx
je     1185 <nicenum+0x55>
movsd  0xe9b(%rip),%xmm0
ucomisd %xmm2,%xmm0
jbe    11c5 <nicenum+0x95>
movsd  0xe85(%rip),%xmm0
jmp    11fa <nicenum+0xca>
movsd  0xe7b(%rip),%xmm0
ucomisd %xmm2,%xmm0
movsd  (%rsp),%xmm1
jae    11ff <nicenum+0xcf>
movsd  0xe78(%rip),%xmm0
ucomisd %xmm2,%xmm0
jae    11ff <nicenum+0xcf>
movsd  0xe82(%rip),%xmm0
xor    %eax,%eax
ucomisd %xmm2,%xmm0
setb   %al
lea    0xe8a(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
jmp    11ff <nicenum+0xcf>
movsd  0xe53(%rip),%xmm0
ucomisd %xmm2,%xmm0
jbe    11dd <nicenum+0xad>
movsd  0xe3d(%rip),%xmm0
jmp    11fa <nicenum+0xca>
movsd  0xe43(%rip),%xmm0
xor    %eax,%eax
ucomisd %xmm2,%xmm0
seta   %al
lea    0xe43(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
movsd  (%rsp),%xmm1
movsd  %xmm0,0x8(%rsp)
movsd  0xdf3(%rip),%xmm0
call   1030 <pow@plt>
mulsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

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

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