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


x86 assembly (clang, -O0):
<nicenum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <log10@plt>
mov    %eax,%edi
call   1050 <floor@plt>
mov    %eax,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%edi
movsd  0xe97(%rip),%xmm0
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1266 <nicenum+0x136>
movsd  0xe8f(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11c5 <nicenum+0x95>
mov    -0x18(%rbp),%edi
movsd  0xe59(%rip),%xmm0
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xe51(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133e <nicenum+0x20e>
movsd  0xe5b(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1201 <nicenum+0xd1>
mov    -0x18(%rbp),%edi
movsd  0xe1d(%rip),%xmm0
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xe1d(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133e <nicenum+0x20e>
movsd  0xe27(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    123d <nicenum+0x10d>
mov    -0x18(%rbp),%edi
movsd  0xde1(%rip),%xmm0
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xde9(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133e <nicenum+0x20e>
mov    -0x18(%rbp),%edi
movsd  0xdb8(%rip),%xmm0
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xda8(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133e <nicenum+0x20e>
movsd  0xd9a(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     12a2 <nicenum+0x172>
mov    -0x18(%rbp),%edi
movsd  0xd7c(%rip),%xmm0
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xd74(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133e <nicenum+0x20e>
movsd  0xd66(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     12de <nicenum+0x1ae>
mov    -0x18(%rbp),%edi
movsd  0xd40(%rip),%xmm0
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xd40(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133e <nicenum+0x20e>
movsd  0xd32(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     131a <nicenum+0x1ea>
mov    -0x18(%rbp),%edi
movsd  0xd04(%rip),%xmm0
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xd0c(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133e <nicenum+0x20e>
mov    -0x18(%rbp),%edi
movsd  0xcdb(%rip),%xmm0
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xccb(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<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
movsd  0xeb0(%rip),%xmm0
mov    %eax,%edi
call   1030 <pow@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
test   %ebp,%ebp
je     11b5 <nicenum+0x85>
movsd  0xe9c(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     11fe <nicenum+0xce>
movsd  0xe92(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     1213 <nicenum+0xe3>
movsd  0xe70(%rip),%xmm0
mov    %ebx,%edi
movsd  %xmm1,(%rsp)
call   1030 <pow@plt>
movsd  0xe74(%rip),%xmm1
ucomisd (%rsp),%xmm1
jbe    11f4 <nicenum+0xc4>
mulsd  0xe6d(%rip),%xmm0
jmp    1226 <nicenum+0xf6>
movsd  0xe6b(%rip),%xmm0
ucomisd %xmm1,%xmm0
jae    11fe <nicenum+0xce>
movsd  0xe65(%rip),%xmm0
ucomisd %xmm1,%xmm0
jae    1213 <nicenum+0xe3>
movsd  0xe27(%rip),%xmm0
mov    %ebx,%edi
movsd  %xmm1,(%rsp)
call   1030 <pow@plt>
movsd  0xe33(%rip),%xmm1
ucomisd (%rsp),%xmm1
jae    11ab <nicenum+0x7b>
mulsd  0xe04(%rip),%xmm0
jmp    1226 <nicenum+0xf6>
movsd  0xdfa(%rip),%xmm0
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <pow@plt>
movsd  0xde5(%rip),%xmm0
mov    %ebx,%edi
call   1030 <pow@plt>
addsd  %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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 = tail call double @pow(double 1.000000e+01, i32 %4)
%6 = fdiv double %0, %5
%7 = icmp eq i32 %1, 0
br i1 %7, label %24, label %8
8: ; preds = %2
%9 = fcmp olt double %6, 1.500000e+00
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call double @pow(double 1.000000e+01, i32 %4)
br label %40
12: ; preds = %8
%13 = fcmp olt double %6, 3.000000e+00
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = tail call double @pow(double 1.000000e+01, i32 %4)
%16 = fmul double %15, 2.000000e+00
br label %40
17: ; preds = %12
%18 = fcmp olt double %6, 7.000000e+00
%19 = tail call double @pow(double 1.000000e+01, i32 %4)
br i1 %18, label %20, label %22
20: ; preds = %17
%21 = fmul double %19, 5.000000e+00
br label %40
22: ; preds = %17
%23 = fmul double %19, 1.000000e+01
br label %40
24: ; preds = %2
%25 = fcmp ugt double %6, 1.000000e+00
br i1 %25, label %28, label %26
26: ; preds = %24
%27 = tail call double @pow(double 1.000000e+01, i32 %4)
br label %40
28: ; preds = %24
%29 = fcmp ugt double %6, 2.000000e+00
br i1 %29, label %33, label %30
30: ; preds = %28
%31 = tail call double @pow(double 1.000000e+01, i32 %4)
%32 = fmul double %31, 2.000000e+00
br label %40
33: ; preds = %28
%34 = fcmp ugt double %6, 5.000000e+00
%35 = tail call double @pow(double 1.000000e+01, i32 %4)
br i1 %34, label %38, label %36
36: ; preds = %33
%37 = fmul double %35, 5.000000e+00
br label %40
38: ; preds = %33
%39 = fmul double %35, 1.000000e+01
br label %40
40: ; preds = %38, %36, %30, %26, %22, %20, %14, %10
%41 = phi double [ %11, %10 ], [ %16, %14 ], [ %21, %20 ], [ %23, %22 ], [ %27, %26 ], [ %32, %30 ], [ %37, %36 ], [ %39, %38 ]
ret double %41
}