#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 */
long double pow(double, int);
long double log10(long double x) {
  int i = 0;
  if (x < 0)
    return -1;
  else {
    long double sn = 0;
    while (sn != x) {
      if (i >= (int)x)
        break;
      sn = pow(10.0, i);
      i++;
    }
  }
  return i - 1;
}


x86 assembly (clang, -O0):
<log10>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
fldt   0x10(%rbp)
fstpt  -0x20(%rbp)
movl   $0x0,-0x24(%rbp)
fldt   -0x20(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
jbe    1145 <log10+0x35>
jmp    1139 <log10+0x29>
fld1
fchs
fstpt  -0x10(%rbp)
jmp    11cc <log10+0xbc>
fldz
fstpt  -0x40(%rbp)
fldt   -0x40(%rbp)
fldt   -0x20(%rbp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    1167 <log10+0x57>
jp     1167 <log10+0x57>
jmp    11b8 <log10+0xa8>
mov    -0x24(%rbp),%eax
fldt   -0x20(%rbp)
fnstcw -0x4a(%rbp)
movzwl -0x4a(%rbp),%ecx
or     $0xc00,%ecx
mov    %cx,-0x4c(%rbp)
fldcw  -0x4c(%rbp)
fistpl -0x44(%rbp)
fldcw  -0x4a(%rbp)
mov    -0x44(%rbp),%ecx
cmp    %ecx,%eax
jl     1197 <log10+0x87>
jmp    11b8 <log10+0xa8>
mov    -0x24(%rbp),%edi
movsd  0xe5e(%rip),%xmm0
call   1030 <pow@plt>
fstpt  -0x40(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114a <log10+0x3a>
jmp    11bd <log10+0xad>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x48(%rbp)
fildl  -0x48(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log10>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
fldt   0x40(%rsp)
fld1
fchs
fldz
fucomip %st(2),%st
ja     11c2 <log10+0xb2>
fstp   %st(0)
fnstcw 0x8(%rsp)
movzwl 0x8(%rsp),%eax
or     $0xc00,%eax
mov    %ax,0xa(%rsp)
fldcw  0xa(%rsp)
fistl  0x10(%rsp)
fldcw  0x8(%rsp)
fldz
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
mov    $0xffffffff,%ebx
jne    115c <log10+0x4c>
jnp    11b0 <log10+0xa0>
mov    0x10(%rsp),%r14d
test   %r14d,%r14d
jle    11b4 <log10+0xa4>
mov    $0xffffffff,%ebp
fstpt  0x14(%rsp)
fldz
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
fstp   %st(0)
lea    0x1(%rbp),%ebx
movsd  0xe73(%rip),%xmm0
mov    %ebx,%edi
call   1030 <pow@plt>
fldt   0x14(%rsp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    11a2 <log10+0x92>
jnp    11b2 <log10+0xa2>
add    $0x2,%ebp
cmp    %r14d,%ebp
mov    %ebx,%ebp
fldz
jl     1180 <log10+0x70>
jmp    11b4 <log10+0xa4>
fstp   %st(0)
fldz
fstp   %st(0)
mov    %ebx,0xc(%rsp)
fildl  0xc(%rsp)
fldz
fxch   %st(1)
fstp   %st(1)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define x86_fp80 @log10(x86_fp80 %0) {
%2 = alloca x86_fp80
%3 = alloca x86_fp80
%4 = alloca i32
%5 = alloca x86_fp80
store x86_fp80 %0, x86_fp80* %3
store i32 0, i32* %4
%6 = load x86_fp80, x86_fp80* %3
%7 = fcmp olt x86_fp80 %6, 0xK00000000000000000000
br i1 %7, label %8, label %9
8: ; preds = %1
store x86_fp80 0xKBFFF8000000000000000, x86_fp80* %2
br label %30
9: ; preds = %1
store x86_fp80 0xK00000000000000000000, x86_fp80* %5
br label %10
10: ; preds = %20, %9
%11 = load x86_fp80, x86_fp80* %5
%12 = load x86_fp80, x86_fp80* %3
%13 = fcmp une x86_fp80 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i32, i32* %4
%16 = load x86_fp80, x86_fp80* %3
%17 = fptosi x86_fp80 %16 to i32
%18 = icmp sge i32 %15, %17
br i1 %18, label %19, label %20
19: ; preds = %14
br label %25
20: ; preds = %14
%21 = load i32, i32* %4
%22 = call x86_fp80 @pow(double 1.000000e+01, i32 %21)
store x86_fp80 %22, x86_fp80* %5
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %10
25: ; preds = %19, %10
br label %26
26: ; preds = %25
%27 = load i32, i32* %4
%28 = sub nsw i32 %27, 1
%29 = sitofp i32 %28 to x86_fp80
store x86_fp80 %29, x86_fp80* %2
br label %30
30: ; preds = %26, %8
%31 = load x86_fp80, x86_fp80* %2
ret x86_fp80 %31
}

LLVM IR (-O2):
define x86_fp80 @log10(x86_fp80 %0) {
%2 = fcmp olt x86_fp80 %0, 0xK00000000000000000000
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = fptosi x86_fp80 %0 to i32
%5 = fcmp une x86_fp80 %0, 0xK00000000000000000000
%6 = icmp sgt i32 %4, 0
%7 = select i1 %5, i1 %6, i1 false
br i1 %7, label %8, label %15
8: ; preds = %3, %8
%9 = phi i32 [ %11, %8 ], [ 0, %3 ]
%10 = tail call x86_fp80 @pow(double 1.000000e+01, i32 %9)
%11 = add nuw nsw i32 %9, 1
%12 = fcmp une x86_fp80 %10, %0
%13 = icmp slt i32 %11, %4
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %8, label %15
15: ; preds = %8, %3
%16 = phi i32 [ -1, %3 ], [ %9, %8 ]
%17 = sitofp i32 %16 to x86_fp80
br label %18
18: ; preds = %1, %15
%19 = phi x86_fp80 [ %17, %15 ], [ 0xKBFFF8000000000000000, %1 ]
ret x86_fp80 %19
}