double round_text_size(double size) {
  int loop = 100;
  double target = 10.0;
  if (size >= 10.0)
    return size;
  while (loop--) {
    if (size >= target)
      return target;
    target = target / 2.0;
  }
  return size;
}


x86 assembly (clang, -O0):
<round_text_size>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
movsd  0xee8(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xed6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1143 <round_text_size+0x43>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a0 <round_text_size+0xa0>
jmp    1148 <round_text_size+0x48>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1196 <round_text_size+0x96>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     117b <round_text_size+0x7b>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a0 <round_text_size+0xa0>
movsd  -0x20(%rbp),%xmm0
movsd  0xe80(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1148 <round_text_size+0x48>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<round_text_size>:
ucomisd 0xef8(%rip),%xmm0
jae    1157 <round_text_size+0x57>
movsd  0xeee(%rip),%xmm1
mov    $0xffffff9c,%eax
movsd  0xee9(%rip),%xmm2
nop
ucomisd %xmm1,%xmm0
jae    1158 <round_text_size+0x58>
mulsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jae    1158 <round_text_size+0x58>
mulsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jae    1158 <round_text_size+0x58>
mulsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jae    1158 <round_text_size+0x58>
mulsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jae    1158 <round_text_size+0x58>
mulsd  %xmm2,%xmm1
add    $0x5,%eax
jne    1120 <round_text_size+0x20>
ret
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @round_text_size(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca double
store double %0, double* %3
store i32 100, i32* %4
store double 1.000000e+01, double* %5
%6 = load double, double* %3
%7 = fcmp oge double %6, 1.000000e+01
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load double, double* %3
store double %9, double* %2
br label %26
10: ; preds = %1
br label %11
11: ; preds = %21, %10
%12 = load i32, i32* %4
%13 = add nsw i32 %12, -1
store i32 %13, i32* %4
%14 = icmp ne i32 %12, 0
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = load double, double* %3
%17 = load double, double* %5
%18 = fcmp oge double %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load double, double* %5
store double %20, double* %2
br label %26
21: ; preds = %15
%22 = load double, double* %5
%23 = fdiv double %22, 2.000000e+00
store double %23, double* %5
br label %11
24: ; preds = %11
%25 = load double, double* %3
store double %25, double* %2
br label %26
26: ; preds = %24, %19, %8
%27 = load double, double* %2
ret double %27
}

LLVM IR (-O2):
define double @round_text_size(double %0) {
%2 = fcmp ult double %0, 1.000000e+01
br i1 %2, label %3, label %23
3: ; preds = %1, %19
%4 = phi i32 [ %21, %19 ], [ 99, %1 ]
%5 = phi double [ %20, %19 ], [ 1.000000e+01, %1 ]
%6 = fcmp ugt double %5, %0
br i1 %6, label %7, label %23
7: ; preds = %3
%8 = fmul double %5, 5.000000e-01
%9 = fcmp ugt double %8, %0
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = fmul double %8, 5.000000e-01
%12 = fcmp ugt double %11, %0
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = fmul double %11, 5.000000e-01
%15 = fcmp ugt double %14, %0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = fmul double %14, 5.000000e-01
%18 = fcmp ugt double %17, %0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = fmul double %17, 5.000000e-01
%21 = add nsw i32 %4, -5
%22 = icmp eq i32 %4, 4
br i1 %22, label %23, label %3
23: ; preds = %3, %7, %10, %13, %16, %19, %1
%24 = phi double [ %0, %1 ], [ %5, %3 ], [ %8, %7 ], [ %11, %10 ], [ %14, %13 ], [ %17, %16 ], [ %0, %19 ]
ret double %24
}