#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 /*<<< orphan*/ fabs(float);
double floorf(float);
scalar_t__ log10(int /*<<< orphan*/);
double pow(int, short);
int /*<<< orphan*/ printf(char *, double, double);
void round(float v, float err) {
  short int exp = (short)log10(fabs(err));
  while (!(err / pow(10, exp) >= 1 && err / pow(10, exp) < 10)) {
    if (err / pow(10, exp) <= 1)
      exp--;
    else
      exp++;
  }
  if (err / pow(10, exp) < 3)
    exp--;
  printf("%f\t%f\t", floorf(v / pow(10., exp) + 0.5) * pow(10., exp),
         floorf(err / pow(10., exp) + 0.5) * pow(10., exp));
}


x86 assembly (clang, -O0):
<round>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
call   1050 <fabs@plt>
mov    %eax,%edi
call   1070 <log10@plt>
mov    %ax,-0xa(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0xa,%edi
movswl -0xa(%rbp),%esi
call   1060 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
xor    %eax,%eax
movsd  0xe57(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0xb(%rbp)
jb     11ed <round+0x9d>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0xa,%edi
movswl -0xa(%rbp),%esi
call   1060 <pow@plt>
movsd  -0x20(%rbp),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe25(%rip),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0xb(%rbp)
mov    -0xb(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    11ff <round+0xaf>
jmp    1258 <round+0x108>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0xa,%edi
movswl -0xa(%rbp),%esi
call   1060 <pow@plt>
movsd  -0x28(%rbp),%xmm1
divsd  %xmm0,%xmm1
movsd  0xdd4(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1247 <round+0xf7>
mov    -0xa(%rbp),%ax
add    $0xffff,%ax
mov    %ax,-0xa(%rbp)
jmp    1253 <round+0x103>
mov    -0xa(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0xa(%rbp)
jmp    1177 <round+0x27>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0xa,%edi
movswl -0xa(%rbp),%esi
call   1060 <pow@plt>
movsd  -0x30(%rbp),%xmm1
divsd  %xmm0,%xmm1
movsd  0xd8b(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    129b <round+0x14b>
mov    -0xa(%rbp),%ax
add    $0xffff,%ax
mov    %ax,-0xa(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    $0xa,%edi
movswl -0xa(%rbp),%esi
call   1060 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  0xd4d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1040 <floorf@plt>
movsd  %xmm0,-0x50(%rbp)
mov    $0xa,%edi
movswl -0xa(%rbp),%esi
call   1060 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    $0xa,%edi
movswl -0xa(%rbp),%esi
call   1060 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  0xcec(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1040 <floorf@plt>
movsd  %xmm0,-0x40(%rbp)
mov    $0xa,%edi
movswl -0xa(%rbp),%esi
call   1060 <pow@plt>
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm2,%xmm1
lea    0xcbc(%rip),%rdi
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<round>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm1,(%rsp)
movss  %xmm0,0x8(%rsp)
movapd %xmm1,%xmm0
call   1050 <fabs@plt>
mov    %eax,%edi
call   1070 <log10@plt>
movss  (%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,(%rsp)
jmp    11ac <round+0x5c>
mov    $0xa,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
xor    %eax,%eax
movsd  0xe61(%rip),%xmm0
ucomisd %xmm1,%xmm0
setb   %al
lea    (%rbx,%rax,2),%eax
add    $0xffffffff,%eax
movswl %ax,%ebx
mov    $0xa,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
ucomisd 0xe34(%rip),%xmm1
jb     1180 <round+0x30>
mov    $0xa,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe1d(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1180 <round+0x30>
mov    $0xa,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe02(%rip),%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
seta   %al
sub    %eax,%ebx
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movswl %bx,%ebx
mov    $0xa,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
addsd  0xdce(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
call   1040 <floorf@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xa,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0xa,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
addsd  0xd87(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
call   1040 <floorf@plt>
movsd  %xmm0,(%rsp)
mov    $0xa,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
lea    0xd62(%rip),%rdi
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%f\09%f\09\00"
define void @round(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca i16
store float %0, float* %3
store float %1, float* %4
%6 = load float, float* %4
%7 = call i32 @fabs(float %6)
%8 = call i64 @log10(i32 %7)
%9 = trunc i64 %8 to i16
store i16 %9, i16* %5
br label %10
10: ; preds = %40, %2
%11 = load float, float* %4
%12 = fpext float %11 to double
%13 = load i16, i16* %5
%14 = call double @pow(i32 10, i16 signext %13)
%15 = fdiv double %12, %14
%16 = fcmp oge double %15, 1.000000e+00
br i1 %16, label %17, label %24
17: ; preds = %10
%18 = load float, float* %4
%19 = fpext float %18 to double
%20 = load i16, i16* %5
%21 = call double @pow(i32 10, i16 signext %20)
%22 = fdiv double %19, %21
%23 = fcmp olt double %22, 1.000000e+01
br label %24
24: ; preds = %17, %10
%25 = phi i1 [ false, %10 ], [ %23, %17 ]
%26 = xor i1 %25, true
br i1 %26, label %27, label %41
27: ; preds = %24
%28 = load float, float* %4
%29 = fpext float %28 to double
%30 = load i16, i16* %5
%31 = call double @pow(i32 10, i16 signext %30)
%32 = fdiv double %29, %31
%33 = fcmp ole double %32, 1.000000e+00
br i1 %33, label %34, label %37
34: ; preds = %27
%35 = load i16, i16* %5
%36 = add i16 %35, -1
store i16 %36, i16* %5
br label %40
37: ; preds = %27
%38 = load i16, i16* %5
%39 = add i16 %38, 1
store i16 %39, i16* %5
br label %40
40: ; preds = %37, %34
br label %10
41: ; preds = %24
%42 = load float, float* %4
%43 = fpext float %42 to double
%44 = load i16, i16* %5
%45 = call double @pow(i32 10, i16 signext %44)
%46 = fdiv double %43, %45
%47 = fcmp olt double %46, 3.000000e+00
br i1 %47, label %48, label %51
48: ; preds = %41
%49 = load i16, i16* %5
%50 = add i16 %49, -1
store i16 %50, i16* %5
br label %51
51: ; preds = %48, %41
%52 = load float, float* %3
%53 = fpext float %52 to double
%54 = load i16, i16* %5
%55 = call double @pow(i32 10, i16 signext %54)
%56 = fdiv double %53, %55
%57 = fadd double %56, 5.000000e-01
%58 = fptrunc double %57 to float
%59 = call double @floorf(float %58)
%60 = load i16, i16* %5
%61 = call double @pow(i32 10, i16 signext %60)
%62 = fmul double %59, %61
%63 = load float, float* %4
%64 = fpext float %63 to double
%65 = load i16, i16* %5
%66 = call double @pow(i32 10, i16 signext %65)
%67 = fdiv double %64, %66
%68 = fadd double %67, 5.000000e-01
%69 = fptrunc double %68 to float
%70 = call double @floorf(float %69)
%71 = load i16, i16* %5
%72 = call double @pow(i32 10, i16 signext %71)
%73 = fmul double %70, %72
%74 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %62, double %73)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%f\09%f\09\00"
define void @round(float %0, float %1) {
%3 = tail call i32 @fabs(float %1)
%4 = tail call i64 @log10(i32 %3)
%5 = trunc i64 %4 to i16
%6 = fpext float %1 to double
br label %7
7: ; preds = %16, %2
%8 = phi i16 [ %5, %2 ], [ %21, %16 ]
%9 = tail call double @pow(i32 10, i16 signext %8)
%10 = fdiv double %6, %9
%11 = fcmp ult double %10, 1.000000e+00
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = tail call double @pow(i32 10, i16 signext %8)
%14 = fdiv double %6, %13
%15 = fcmp olt double %14, 1.000000e+01
br i1 %15, label %22, label %16
16: ; preds = %7, %12
%17 = tail call double @pow(i32 10, i16 signext %8)
%18 = fdiv double %6, %17
%19 = fcmp ugt double %18, 1.000000e+00
%20 = select i1 %19, i16 1, i16 -1
%21 = add i16 %20, %8
br label %7
22: ; preds = %12
%23 = tail call double @pow(i32 10, i16 signext %8)
%24 = fdiv double %6, %23
%25 = fcmp olt double %24, 3.000000e+00
%26 = sext i1 %25 to i16
%27 = add i16 %8, %26
%28 = fpext float %0 to double
%29 = tail call double @pow(i32 10, i16 signext %27)
%30 = fdiv double %28, %29
%31 = fadd double %30, 5.000000e-01
%32 = fptrunc double %31 to float
%33 = tail call double @floorf(float %32)
%34 = tail call double @pow(i32 10, i16 signext %27)
%35 = fmul double %33, %34
%36 = tail call double @pow(i32 10, i16 signext %27)
%37 = fdiv double %6, %36
%38 = fadd double %37, 5.000000e-01
%39 = fptrunc double %38 to float
%40 = tail call double @floorf(float %39)
%41 = tail call double @pow(i32 10, i16 signext %27)
%42 = fmul double %40, %41
%43 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %35, double %42)
ret void
}