#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 */
float fabsf(float);
float log10f(float);
float powf(double, float);
scalar_t__ truncf(float);
float _s2priv_round(float x, int *nsub) {
  float nice[] = {0.0, 2.0, 5.0, 10.0};
  if (x == 0.0) {
    if (nsub) {
      *nsub = 2;
    }
    return 0.0;
  }
  float xx = fabsf(x);
  float xlog = log10f(xx);
  int ilog = (int)(truncf(xlog));
  if (xlog < 0) {
    ilog--;
  }
  float pwr = powf(10.0, (float)ilog);
  float frac = xx / pwr;
  int i = 3;
  if (frac <= 5.0) {
    i = 2;
  }
  if (frac <= 2.0) {
    i = 1;
  }
  if (nsub) {
    *nsub = 5;
  }
  if (i == 1) {
    if (nsub) {
      *nsub = 2;
    }
  }
  return (x < 0 ? -fabsf(pwr * nice[i]) : fabsf(pwr * nice[i]));
}


x86 assembly (clang, -O0):
<_s2priv_round>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    0xec8(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec5(%rip),%rax
mov    %rax,-0x18(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1195 <_s2priv_round+0x65>
jp     1195 <_s2priv_round+0x65>
cmpq   $0x0,-0x10(%rbp)
je     1188 <_s2priv_round+0x58>
mov    -0x10(%rbp),%rax
movl   $0x2,(%rax)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12ed <_s2priv_round+0x1bd>
movss  -0x8(%rbp),%xmm0
movaps 0xe5f(%rip),%xmm1
pand   %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
call   1040 <log10f@plt>
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
call   1050 <truncf@plt>
mov    %eax,-0x2c(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x28(%rbp),%xmm0
jbe    11dc <_s2priv_round+0xac>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
cvtsi2ssl -0x2c(%rbp),%xmm1
movsd  0xe3f(%rip),%xmm0
call   1030 <powf@plt>
movss  %xmm0,-0x30(%rbp)
movss  -0x24(%rbp),%xmm0
divss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movl   $0x3,-0x38(%rbp)
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe06(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     122b <_s2priv_round+0xfb>
movl   $0x2,-0x38(%rbp)
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdf4(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     124d <_s2priv_round+0x11d>
movl   $0x1,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1262 <_s2priv_round+0x132>
mov    -0x10(%rbp),%rax
movl   $0x5,(%rax)
cmpl   $0x1,-0x38(%rbp)
jne    1286 <_s2priv_round+0x156>
cmpq   $0x0,-0x10(%rbp)
je     1281 <_s2priv_round+0x151>
mov    -0x10(%rbp),%rax
movl   $0x2,(%rax)
jmp    1286 <_s2priv_round+0x156>
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    12c4 <_s2priv_round+0x194>
movss  -0x30(%rbp),%xmm0
movslq -0x38(%rbp),%rax
mulss  -0x20(%rbp,%rax,4),%xmm0
movaps 0xd57(%rip),%xmm1
pand   %xmm1,%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x3c(%rbp)
jmp    12e3 <_s2priv_round+0x1b3>
movss  -0x30(%rbp),%xmm0
movslq -0x38(%rbp),%rax
mulss  -0x20(%rbp,%rax,4),%xmm0
movaps 0xd26(%rip),%xmm1
pand   %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x3c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_s2priv_round>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jne    1159 <_s2priv_round+0x29>
jp     1159 <_s2priv_round+0x29>
test   %rbx,%rbx
je     120a <_s2priv_round+0xda>
movl   $0x2,(%rbx)
jmp    120a <_s2priv_round+0xda>
movaps 0xea0(%rip),%xmm0
movaps %xmm1,0x20(%rsp)
andps  %xmm1,%xmm0
movaps %xmm0,0x10(%rsp)
call   1040 <log10f@plt>
movss  %xmm0,0xc(%rsp)
call   1050 <truncf@plt>
xor    %ecx,%ecx
xorps  %xmm0,%xmm0
ucomiss 0xc(%rsp),%xmm0
seta   %cl
sub    %ecx,%eax
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
movsd  0xe95(%rip),%xmm0
call   1030 <powf@plt>
movaps 0x10(%rsp),%xmm2
divss  %xmm0,%xmm2
movss  0xe87(%rip),%xmm1
xor    %ecx,%ecx
ucomiss %xmm2,%xmm1
setb   %cl
or     $0x2,%ecx
movss  0xe78(%rip),%xmm1
ucomiss %xmm2,%xmm1
mov    $0x1,%eax
cmovb  %ecx,%eax
test   %rbx,%rbx
je     11e4 <_s2priv_round+0xb4>
xor    %ecx,%ecx
cmp    $0x1,%eax
setne  %cl
lea    (%rcx,%rcx,2),%ecx
add    $0x2,%ecx
mov    %ecx,(%rbx)
xorps  %xmm1,%xmm1
ucomiss 0x20(%rsp),%xmm1
mov    %eax,%eax
lea    0xe2b(%rip),%rcx
mulss  (%rcx,%rax,4),%xmm0
andps  0xdff(%rip),%xmm0
jbe    120a <_s2priv_round+0xda>
xorps  0xe06(%rip),%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const._s2priv_round.nice = [4 x float] [float 0.000000e+00, float 2.000000e+00, float 5.000000e+00, float 1.000000e+01]
define float @_s2priv_round(float %0, i32* %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca i32*
%6 = alloca [4 x float]
%7 = alloca float
%8 = alloca float
%9 = alloca i32
%10 = alloca float
%11 = alloca float
%12 = alloca i32
store float %0, float* %4
store i32* %1, i32** %5
%13 = bitcast [4 x float]* %6 to i8*
%14 = load float, float* %4
%15 = fpext float %14 to double
%16 = fcmp oeq double %15, 0.000000e+00
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32*, i32** %5
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = load i32*, i32** %5
store i32 2, i32* %21
br label %22
22: ; preds = %20, %17
store float 0.000000e+00, float* %3
br label %88
23: ; preds = %2
%24 = load float, float* %4
%25 = call float @llvm.fabs.f32(float %24)
store float %25, float* %7
%26 = load float, float* %7
%27 = call float @log10f(float %26)
store float %27, float* %8
%28 = load float, float* %8
%29 = call i64 @truncf(float %28)
%30 = trunc i64 %29 to i32
store i32 %30, i32* %9
%31 = load float, float* %8
%32 = fcmp olt float %31, 0.000000e+00
br i1 %32, label %33, label %36
33: ; preds = %23
%34 = load i32, i32* %9
%35 = add nsw i32 %34, -1
store i32 %35, i32* %9
br label %36
36: ; preds = %33, %23
%37 = load i32, i32* %9
%38 = sitofp i32 %37 to float
%39 = call float @powf(double 1.000000e+01, float %38)
store float %39, float* %10
%40 = load float, float* %7
%41 = load float, float* %10
%42 = fdiv float %40, %41
store float %42, float* %11
store i32 3, i32* %12
%43 = load float, float* %11
%44 = fpext float %43 to double
%45 = fcmp ole double %44, 5.000000e+00
br i1 %45, label %46, label %47
46: ; preds = %36
store i32 2, i32* %12
br label %47
47: ; preds = %46, %36
%48 = load float, float* %11
%49 = fpext float %48 to double
%50 = fcmp ole double %49, 2.000000e+00
br i1 %50, label %51, label %52
51: ; preds = %47
store i32 1, i32* %12
br label %52
52: ; preds = %51, %47
%53 = load i32*, i32** %5
%54 = icmp ne i32* %53, null
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = load i32*, i32** %5
store i32 5, i32* %56
br label %57
57: ; preds = %55, %52
%58 = load i32, i32* %12
%59 = icmp eq i32 %58, 1
br i1 %59, label %60, label %66
60: ; preds = %57
%61 = load i32*, i32** %5
%62 = icmp ne i32* %61, null
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = load i32*, i32** %5
store i32 2, i32* %64
br label %65
65: ; preds = %63, %60
br label %66
66: ; preds = %65, %57
%67 = load float, float* %4
%68 = fcmp olt float %67, 0.000000e+00
br i1 %68, label %69, label %78
69: ; preds = %66
%70 = load float, float* %10
%71 = load i32, i32* %12
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [4 x float], [4 x float]* %6, i64 0, i64 %72
%74 = load float, float* %73
%75 = fmul float %70, %74
%76 = call float @llvm.fabs.f32(float %75)
%77 = fneg float %76
br label %86
78: ; preds = %66
%79 = load float, float* %10
%80 = load i32, i32* %12
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [4 x float], [4 x float]* %6, i64 0, i64 %81
%83 = load float, float* %82
%84 = fmul float %79, %83
%85 = call float @llvm.fabs.f32(float %84)
br label %86
86: ; preds = %78, %69
%87 = phi float [ %77, %69 ], [ %85, %78 ]
store float %87, float* %3
br label %88
88: ; preds = %86, %22
%89 = load float, float* %3
ret float %89
}

LLVM IR (-O2):
@__const._s2priv_round.nice = [4 x float] [float 0.000000e+00, float 2.000000e+00, float 5.000000e+00, float 1.000000e+01]
define float @_s2priv_round(float %0, i32* writeonly %1) {
%3 = fcmp oeq float %0, 0.000000e+00
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = icmp eq i32* %1, null
br i1 %5, label %35, label %6
6: ; preds = %4
store i32 2, i32* %1
br label %35
7: ; preds = %2
%8 = tail call float @llvm.fabs.f32(float %0)
%9 = tail call float @log10f(float %8)
%10 = tail call i64 @truncf(float %9)
%11 = trunc i64 %10 to i32
%12 = fcmp olt float %9, 0.000000e+00
%13 = sext i1 %12 to i32
%14 = add nsw i32 %11, %13
%15 = sitofp i32 %14 to float
%16 = tail call float @powf(double 1.000000e+01, float %15)
%17 = fdiv float %8, %16
%18 = fcmp ugt float %17, 5.000000e+00
%19 = select i1 %18, i32 3, i32 2
%20 = fcmp ugt float %17, 2.000000e+00
%21 = select i1 %20, i32 %19, i32 1
%22 = icmp eq i32* %1, null
br i1 %22, label %26, label %23
23: ; preds = %7
%24 = icmp eq i32 %21, 1
%25 = select i1 %24, i32 2, i32 5
store i32 %25, i32* %1
br label %26
26: ; preds = %7, %23
%27 = fcmp olt float %0, 0.000000e+00
%28 = zext i32 %21 to i64
%29 = getelementptr inbounds [4 x float], [4 x float]* @__const._s2priv_round.nice, i64 0, i64 %28
%30 = load float, float* %29
%31 = fmul float %16, %30
%32 = tail call float @llvm.fabs.f32(float %31)
br i1 %27, label %33, label %35
33: ; preds = %26
%34 = fneg float %32
br label %35
35: ; preds = %26, %33, %4, %6
%36 = phi float [ 0.000000e+00, %6 ], [ 0.000000e+00, %4 ], [ %34, %33 ], [ %32, %26 ]
ret float %36
}