#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 copysign(float, float);
float fabs(float);
int floor(int /*<<< orphan*/);
int /*<<< orphan*/ log10(float);
int /*<<< orphan*/ modf(float, float *);
float powf(int, float);
float float_round(float fVal, unsigned long int uSigfigs) {
  float fWholeDigits = floor(log10(fabs(fVal))) + 1;
  float fSigNif = fabs(fVal) / powf(10, fWholeDigits - uSigfigs);
  float fIntPart = 0;
  modf(fabs(fSigNif) + 0.5, &fIntPart);
  return copysign(fIntPart * powf(10, fWholeDigits - uSigfigs), fVal);
}


x86 assembly (clang, -O0):
<float_round>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
call   1050 <fabs@plt>
call   1070 <log10@plt>
mov    %eax,%edi
call   1080 <floor@plt>
add    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x4(%rbp),%xmm0
call   1050 <fabs@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x24(%rbp)
test   %rax,%rax
movss  %xmm0,-0x20(%rbp)
js     11e9 <float_round+0x89>
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x28(%rbp),%xmm0
movss  -0x20(%rbp),%xmm1
subss  %xmm1,%xmm0
mov    $0xa,%edi
call   1030 <powf@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movss  -0x18(%rbp),%xmm0
call   1050 <fabs@plt>
cvtss2sd %xmm0,%xmm0
movsd  0xdd1(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
lea    -0x1c(%rbp),%rdi
call   1040 <modf@plt>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x34(%rbp)
test   %rax,%rax
movss  %xmm0,-0x30(%rbp)
js     1291 <float_round+0x131>
movss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x38(%rbp),%xmm0
movss  -0x30(%rbp),%xmm1
subss  %xmm1,%xmm0
mov    $0xa,%edi
call   1030 <powf@plt>
movaps %xmm0,%xmm1
movss  -0x3c(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  -0x4(%rbp),%xmm1
call   1060 <copysign@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<float_round>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movaps %xmm0,0x20(%rsp)
andps  0xe9c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
call   1060 <log10@plt>
mov    %eax,%edi
call   1070 <floor@plt>
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
test   %rbx,%rbx
js     118b <float_round+0x3b>
cvtsi2ss %rbx,%xmm1
jmp    11a0 <float_round+0x50>
mov    %rbx,%rax
shr    %rax
and    $0x1,%ebx
or     %rax,%rbx
cvtsi2ss %rbx,%xmm1
addss  %xmm1,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,0xc(%rsp)
mov    $0xa,%edi
call   1030 <powf@plt>
movaps 0x10(%rsp),%xmm1
divss  %xmm0,%xmm1
movl   $0x0,0x8(%rsp)
andps  0xe34(%rip),%xmm1
addss  0xe3c(%rip),%xmm1
lea    0x8(%rsp),%rdi
movaps %xmm1,%xmm0
call   1040 <modf@plt>
movss  0x8(%rsp),%xmm0
movss  %xmm0,0x10(%rsp)
mov    $0xa,%edi
movss  0xc(%rsp),%xmm0
call   1030 <powf@plt>
mulss  0x10(%rsp),%xmm0
movaps 0x20(%rsp),%xmm1
add    $0x30,%rsp
pop    %rbx
jmp    1050 <copysign@plt>

LLVM IR (-O0):
define float @float_round(float %0, i64 %1) {
%3 = alloca float
%4 = alloca i64
%5 = alloca float
%6 = alloca float
%7 = alloca float
store float %0, float* %3
store i64 %1, i64* %4
%8 = load float, float* %3
%9 = call float @fabs(float %8)
%10 = call i32 @log10(float %9)
%11 = call i32 @floor(i32 %10)
%12 = add nsw i32 %11, 1
%13 = sitofp i32 %12 to float
store float %13, float* %5
%14 = load float, float* %3
%15 = call float @fabs(float %14)
%16 = load float, float* %5
%17 = load i64, i64* %4
%18 = uitofp i64 %17 to float
%19 = fsub float %16, %18
%20 = call float @powf(i32 10, float %19)
%21 = fdiv float %15, %20
store float %21, float* %6
store float 0.000000e+00, float* %7
%22 = load float, float* %6
%23 = call float @fabs(float %22)
%24 = fpext float %23 to double
%25 = fadd double %24, 5.000000e-01
%26 = fptrunc double %25 to float
%27 = call i32 @modf(float %26, float* %7)
%28 = load float, float* %7
%29 = load float, float* %5
%30 = load i64, i64* %4
%31 = uitofp i64 %30 to float
%32 = fsub float %29, %31
%33 = call float @powf(i32 10, float %32)
%34 = fmul float %28, %33
%35 = load float, float* %3
%36 = call float @copysign(float %34, float %35)
ret float %36
}

LLVM IR (-O2):
define float @float_round(float %0, i64 %1) {
%3 = alloca float
%4 = tail call float @llvm.fabs.f32(float %0)
%5 = tail call i32 @log10(float %4)
%6 = tail call i32 @floor(i32 %5)
%7 = add nsw i32 %6, 1
%8 = sitofp i32 %7 to float
%9 = uitofp i64 %1 to float
%10 = fsub float %8, %9
%11 = tail call float @powf(i32 10, float %10)
%12 = fdiv float %4, %11
%13 = bitcast float* %3 to i8*
store float 0.000000e+00, float* %3
%14 = tail call float @llvm.fabs.f32(float %12)
%15 = fadd float %14, 5.000000e-01
%16 = call i32 @modf(float %15, float* %3)
%17 = load float, float* %3
%18 = tail call float @powf(i32 10, float %10)
%19 = fmul float %17, %18
%20 = tail call float @copysign(float %19, float %0)
ret float %20
}