#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(scalar_t__);
double pow(int, int);
scalar_t__ round(double);
int _num_decimals(double val) {
  int c;
  double v;
  for (c = 0; c < 22; c++) {
    v = val * pow(10, c);
    if (fabs(v - round(v)) == 0.0)
      return c;
  }
  return -1;
}


x86 assembly (clang, -O0):
<_num_decimals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x16,-0x14(%rbp)
jge    11d3 <_num_decimals+0xa3>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%esi
mov    $0xa,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <round@plt>
movsd  -0x28(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1030 <fabs@plt>
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c0 <_num_decimals+0x90>
jp     11c0 <_num_decimals+0x90>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11da <_num_decimals+0xaa>
jmp    11c5 <_num_decimals+0x95>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <_num_decimals+0x14>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_num_decimals>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%ebp
mov    $0xa,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1050 <round@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
call   1030 <fabs@plt>
ucomisd 0xe6c(%rip),%xmm0
jne    1198 <_num_decimals+0x68>
jnp    11f2 <_num_decimals+0xc2>
mov    $0xa,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1050 <round@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
call   1030 <fabs@plt>
ucomisd 0xe27(%rip),%xmm0
jne    11dd <_num_decimals+0xad>
jnp    11f0 <_num_decimals+0xc0>
add    $0x2,%ebx
cmp    $0x17,%ebx
jne    1150 <_num_decimals+0x20>
mov    $0xffffffff,%ebp
jmp    11f2 <_num_decimals+0xc2>
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_num_decimals(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
%5 = alloca double
store double %0, double* %3
store i32 0, i32* %4
br label %6
6: ; preds = %25, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 22
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = load double, double* %3
%11 = load i32, i32* %4
%12 = call double @pow(i32 10, i32 %11)
%13 = fmul double %10, %12
store double %13, double* %5
%14 = load double, double* %5
%15 = load double, double* %5
%16 = call i64 @round(double %15)
%17 = sitofp i64 %16 to double
%18 = fsub double %14, %17
%19 = fptosi double %18 to i64
%20 = call double @fabs(i64 %19)
%21 = fcmp oeq double %20, 0.000000e+00
br i1 %21, label %22, label %24
22: ; preds = %9
%23 = load i32, i32* %4
store i32 %23, i32* %2
br label %29
24: ; preds = %9
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %6
28: ; preds = %6
store i32 -1, i32* %2
br label %29
29: ; preds = %28, %22
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @_num_decimals(double %0) {
br label %2
2: ; preds = %22, %1
%3 = phi i32 [ 0, %1 ], [ %23, %22 ]
%4 = tail call double @pow(i32 10, i32 %3)
%5 = fmul double %4, %0
%6 = tail call i64 @round(double %5)
%7 = sitofp i64 %6 to double
%8 = fsub double %5, %7
%9 = fptosi double %8 to i64
%10 = tail call double @fabs(i64 %9)
%11 = fcmp oeq double %10, 0.000000e+00
br i1 %11, label %25, label %12
12: ; preds = %2
%13 = or i32 %3, 1
%14 = tail call double @pow(i32 10, i32 %13)
%15 = fmul double %14, %0
%16 = tail call i64 @round(double %15)
%17 = sitofp i64 %16 to double
%18 = fsub double %15, %17
%19 = fptosi double %18 to i64
%20 = tail call double @fabs(i64 %19)
%21 = fcmp oeq double %20, 0.000000e+00
br i1 %21, label %25, label %22
22: ; preds = %12
%23 = add nuw nsw i32 %3, 2
%24 = icmp eq i32 %23, 22
br i1 %24, label %25, label %2
25: ; preds = %22, %12, %2
%26 = phi i32 [ %3, %2 ], [ %13, %12 ], [ -1, %22 ]
ret i32 %26
}