#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 */
double fabs(double);
int expo_ten_inf(double nb) {
  int iter;
  double cur_nb;
  nb = fabs(nb);
  iter = 0;
  if (nb < 1.0) {
    cur_nb = 1.0;
    while (cur_nb - nb > 1e-9) {
      iter--;
      cur_nb *= 0.1;
    }
  } else if (nb > 1.0) {
    cur_nb = 10.0;
    while (nb - cur_nb >= 0.0) {
      iter++;
      cur_nb *= 10.0;
    }
  }
  return iter;
}


x86 assembly (clang, -O0):
<expo_ten_inf>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movaps 0xf0b(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movsd  0xed3(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1186 <expo_ten_inf+0x86>
movsd  0xec0(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  0xeb9(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1181 <expo_ten_inf+0x81>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
movsd  0xea6(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1145 <expo_ten_inf+0x45>
jmp    11eb <expo_ten_inf+0xeb>
movsd  -0x8(%rbp),%xmm0
movsd  0xe6d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e6 <expo_ten_inf+0xe6>
movsd  0xe63(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e1 <expo_ten_inf+0xe1>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movsd  0xe36(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11aa <expo_ten_inf+0xaa>
jmp    11e6 <expo_ten_inf+0xe6>
jmp    11eb <expo_ten_inf+0xeb>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<expo_ten_inf>:
andpd  0xef8(%rip),%xmm0
movsd  0xf00(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1157 <expo_ten_inf+0x57>
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
xor    %eax,%eax
ucomisd 0xf00(%rip),%xmm2
jbe    11a5 <expo_ten_inf+0xa5>
xor    %eax,%eax
movsd  0xefc(%rip),%xmm2
movsd  0xeec(%rip),%xmm3
nopl   0x0(%rax)
add    $0xffffffff,%eax
mulsd  %xmm2,%xmm1
movapd %xmm1,%xmm4
subsd  %xmm0,%xmm4
ucomisd %xmm3,%xmm4
ja     1140 <expo_ten_inf+0x40>
jmp    11a5 <expo_ten_inf+0xa5>
xor    %eax,%eax
ucomisd 0xeaf(%rip),%xmm0
jbe    11a5 <expo_ten_inf+0xa5>
movsd  0xead(%rip),%xmm2
addsd  %xmm0,%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jb     11a5 <expo_ten_inf+0xa5>
xor    %eax,%eax
movsd  0xe9d(%rip),%xmm2
movapd %xmm2,%xmm3
nopw   0x0(%rax,%rax,1)
add    $0x1,%eax
mulsd  %xmm2,%xmm3
movapd %xmm0,%xmm4
subsd  %xmm3,%xmm4
ucomisd %xmm1,%xmm4
jae    1190 <expo_ten_inf+0x90>
ret

LLVM IR (-O0):
define i32 @expo_ten_inf(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca double
store double %0, double* %2
%5 = load double, double* %2
%6 = call double @llvm.fabs.f64(double %5)
store double %6, double* %2
store i32 0, i32* %3
%7 = load double, double* %2
%8 = fcmp olt double %7, 1.000000e+00
br i1 %8, label %9, label %21
9: ; preds = %1
store double 1.000000e+00, double* %4
br label %10
10: ; preds = %15, %9
%11 = load double, double* %4
%12 = load double, double* %2
%13 = fsub double %11, %12
%14 = fcmp ogt double %13, 1.000000e-09
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32, i32* %3
%17 = add nsw i32 %16, -1
store i32 %17, i32* %3
%18 = load double, double* %4
%19 = fmul double %18, 1.000000e-01
store double %19, double* %4
br label %10
20: ; preds = %10
br label %37
21: ; preds = %1
%22 = load double, double* %2
%23 = fcmp ogt double %22, 1.000000e+00
br i1 %23, label %24, label %36
24: ; preds = %21
store double 1.000000e+01, double* %4
br label %25
25: ; preds = %30, %24
%26 = load double, double* %2
%27 = load double, double* %4
%28 = fsub double %26, %27
%29 = fcmp oge double %28, 0.000000e+00
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
%33 = load double, double* %4
%34 = fmul double %33, 1.000000e+01
store double %34, double* %4
br label %25
35: ; preds = %25
br label %36
36: ; preds = %35, %21
br label %37
37: ; preds = %36, %20
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @expo_ten_inf(double %0) {
%2 = tail call double @llvm.fabs.f64(double %0)
%3 = fcmp olt double %2, 1.000000e+00
br i1 %3, label %4, label %14
4: ; preds = %1
%5 = fsub double 1.000000e+00, %2
%6 = fcmp ogt double %5, 1.000000e-09
br i1 %6, label %7, label %26
7: ; preds = %4, %7
%8 = phi double [ %11, %7 ], [ 1.000000e+00, %4 ]
%9 = phi i32 [ %10, %7 ], [ 0, %4 ]
%10 = add nsw i32 %9, -1
%11 = fmul double %8, 1.000000e-01
%12 = fsub double %11, %2
%13 = fcmp ogt double %12, 1.000000e-09
br i1 %13, label %7, label %26
14: ; preds = %1
%15 = fcmp ule double %2, 1.000000e+00
%16 = fadd double %2, -1.000000e+01
%17 = fcmp ult double %16, 0.000000e+00
%18 = or i1 %15, %17
br i1 %18, label %26, label %19
19: ; preds = %14, %19
%20 = phi double [ %23, %19 ], [ 1.000000e+01, %14 ]
%21 = phi i32 [ %22, %19 ], [ 0, %14 ]
%22 = add nuw nsw i32 %21, 1
%23 = fmul double %20, 1.000000e+01
%24 = fsub double %2, %23
%25 = fcmp ult double %24, 0.000000e+00
br i1 %25, label %26, label %19
26: ; preds = %19, %7, %4, %14
%27 = phi i32 [ 0, %14 ], [ 0, %4 ], [ %10, %7 ], [ %22, %19 ]
ret i32 %27
}