#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 mu_pow10(int);
float mu_precision(float v, int ndigits) {
  if (v == 0.0) {
    return 0.0;
  } else if (v < 0.0) {
    return -mu_precision(-v, ndigits);
  }
  float p10 = mu_pow10(ndigits);
  float v1 = v * p10;
  float v2 = (int)(v1 + 0.5);
  float v3 = v2 / p10;
  return v3;
}


x86 assembly (clang, -O0):
<mu_precision>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1159 <mu_precision+0x39>
jp     1159 <mu_precision+0x39>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11fc <mu_precision+0xdc>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11a0 <mu_precision+0x80>
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0xc(%rbp),%edi
call   1040 <mu_precision@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11fc <mu_precision+0xdc>
jmp    11a5 <mu_precision+0x85>
mov    -0xc(%rbp),%edi
call   1030 <mu_pow10@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe2e(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mu_precision>:
sub    $0x18,%rsp
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jne    1136 <mu_precision+0x16>
jp     1136 <mu_precision+0x16>
add    $0x18,%rsp
ret
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
jbe    1159 <mu_precision+0x39>
xorps  0xecb(%rip),%xmm1
movaps %xmm1,%xmm0
call   1040 <mu_precision@plt>
xorps  0xebc(%rip),%xmm0
add    $0x18,%rsp
ret
movaps %xmm1,(%rsp)
call   1030 <mu_pow10@plt>
movaps %xmm0,%xmm1
movaps (%rsp),%xmm0
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xe87(%rip),%xmm0
cvttpd2dq %xmm0,%xmm0
cvtdq2ps %xmm0,%xmm0
divss  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define float @mu_precision(float %0, i32 %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca i32
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
store float %0, float* %4
store i32 %1, i32* %5
%10 = load float, float* %4
%11 = fpext float %10 to double
%12 = fcmp oeq double %11, 0.000000e+00
br i1 %12, label %13, label %14
13: ; preds = %2
store float 0.000000e+00, float* %3
br label %40
14: ; preds = %2
%15 = load float, float* %4
%16 = fpext float %15 to double
%17 = fcmp olt double %16, 0.000000e+00
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load float, float* %4
%20 = fneg float %19
%21 = load i32, i32* %5
%22 = call float @mu_precision(float %20, i32 %21)
%23 = fneg float %22
store float %23, float* %3
br label %40
24: ; preds = %14
br label %25
25: ; preds = %24
%26 = load i32, i32* %5
%27 = call float @mu_pow10(i32 %26)
store float %27, float* %6
%28 = load float, float* %4
%29 = load float, float* %6
%30 = fmul float %28, %29
store float %30, float* %7
%31 = load float, float* %7
%32 = fpext float %31 to double
%33 = fadd double %32, 5.000000e-01
%34 = fptosi double %33 to i32
%35 = sitofp i32 %34 to float
store float %35, float* %8
%36 = load float, float* %8
%37 = load float, float* %6
%38 = fdiv float %36, %37
store float %38, float* %9
%39 = load float, float* %9
store float %39, float* %3
br label %40
40: ; preds = %25, %18, %13
%41 = load float, float* %3
ret float %41
}

LLVM IR (-O2):
define float @mu_precision(float %0, i32 %1) {
%3 = fcmp oeq float %0, 0.000000e+00
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = fcmp olt float %0, 0.000000e+00
br i1 %5, label %8, label %12
6: ; preds = %12, %2, %8
%7 = phi float [ %11, %8 ], [ %19, %12 ], [ 0.000000e+00, %2 ]
ret float %7
8: ; preds = %4
%9 = fneg float %0
%10 = tail call float @mu_precision(float %9, i32 %1)
%11 = fneg float %10
br label %6
12: ; preds = %4
%13 = tail call float @mu_pow10(i32 %1)
%14 = fmul float %13, %0
%15 = fpext float %14 to double
%16 = fadd double %15, 5.000000e-01
%17 = fptosi double %16 to i32
%18 = sitofp i32 %17 to float
%19 = fdiv float %18, %13
br label %6
}