#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 */
float pow(double, int);
float log10(float x) {
  int i = 0;
  if (x < 0)
    return -1;
  else {
    float 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    $0x10,%rsp
movss  %xmm0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    1143 <log10+0x33>
movss  0xecf(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11b1 <log10+0xa1>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
ucomiss -0x8(%rbp),%xmm0
jne    1165 <log10+0x55>
jp     1165 <log10+0x55>
jmp    119d <log10+0x8d>
mov    -0xc(%rbp),%eax
cvttss2si -0x8(%rbp),%ecx
cmp    %ecx,%eax
jl     117a <log10+0x6a>
jmp    119d <log10+0x8d>
mov    -0xc(%rbp),%edi
movsd  0xe7b(%rip),%xmm0
call   1030 <pow@plt>
movss  %xmm0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114b <log10+0x3b>
jmp    11a2 <log10+0x92>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log10>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
jbe    112d <log10+0x1d>
movss  0xed5(%rip),%xmm0
jmp    1180 <log10+0x70>
ucomiss %xmm0,%xmm1
mov    $0xffffffff,%ebx
jne    1139 <log10+0x29>
jnp    1179 <log10+0x69>
cvttss2si %xmm1,%r14d
test   %r14d,%r14d
jle    1179 <log10+0x69>
mov    $0xffffffff,%ebp
movss  %xmm1,0xc(%rsp)
xchg   %ax,%ax
lea    0x1(%rbp),%ebx
movsd  0xead(%rip),%xmm0
mov    %ebx,%edi
call   1030 <pow@plt>
movss  0xc(%rsp),%xmm1
ucomiss %xmm1,%xmm0
jne    116f <log10+0x5f>
jnp    1179 <log10+0x69>
add    $0x2,%ebp
cmp    %r14d,%ebp
mov    %ebx,%ebp
jl     1150 <log10+0x40>
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define float @log10(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca i32
%5 = alloca float
store float %0, float* %3
store i32 0, i32* %4
%6 = load float, float* %3
%7 = fcmp olt float %6, 0.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %1
store float -1.000000e+00, float* %2
br label %30
9: ; preds = %1
store float 0.000000e+00, float* %5
br label %10
10: ; preds = %20, %9
%11 = load float, float* %5
%12 = load float, float* %3
%13 = fcmp une float %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i32, i32* %4
%16 = load float, float* %3
%17 = fptosi float %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 float @pow(double 1.000000e+01, i32 %21)
store float %22, float* %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 float
store float %29, float* %2
br label %30
30: ; preds = %26, %8
%31 = load float, float* %2
ret float %31
}

LLVM IR (-O2):
define float @log10(float %0) {
%2 = fcmp olt float %0, 0.000000e+00
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = fptosi float %0 to i32
%5 = fcmp une float %0, 0.000000e+00
%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 float @pow(double 1.000000e+01, i32 %9)
%11 = add nuw nsw i32 %9, 1
%12 = fcmp une float %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 float
br label %18
18: ; preds = %1, %15
%19 = phi float [ %17, %15 ], [ -1.000000e+00, %1 ]
ret float %19
}