#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 floor(double);
scalar_t__ log10(long);
double count_digit(long a) {
  double sum;
  long i;
  if (a == 0)
    return 1;
  else {
    sum = 0;
    for (i = 1; i <= a; i++)
      sum += log10(i);
    return floor(sum) + 1;
  }
}


x86 assembly (clang, -O0):
<count_digit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1149 <count_digit+0x29>
movsd  0xec1(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ab <count_digit+0x8b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jg     1190 <count_digit+0x70>
mov    -0x20(%rbp),%rdi
call   1030 <log10@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1159 <count_digit+0x39>
movsd  -0x18(%rbp),%xmm0
call   1040 <floor@plt>
movsd  0xe5e(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_digit>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     117c <count_digit+0x5c>
jle    1186 <count_digit+0x66>
mov    %rdi,%r14
neg    %r14
xorpd  %xmm0,%xmm0
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <log10@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
lea    (%r14,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
jne    1140 <count_digit+0x20>
jmp    118a <count_digit+0x6a>
movsd  0xe7c(%rip),%xmm0
jmp    1197 <count_digit+0x77>
xorpd  %xmm0,%xmm0
call   1040 <floor@plt>
addsd  0xe69(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @count_digit(i64 %0) {
%2 = alloca double
%3 = alloca i64
%4 = alloca double
%5 = alloca i64
store i64 %0, i64* %3
%6 = load i64, i64* %3
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store double 1.000000e+00, double* %2
br label %27
9: ; preds = %1
store double 0.000000e+00, double* %4
store i64 1, i64* %5
br label %10
10: ; preds = %20, %9
%11 = load i64, i64* %5
%12 = load i64, i64* %3
%13 = icmp sle i64 %11, %12
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = load i64, i64* %5
%16 = call i64 @log10(i64 %15)
%17 = sitofp i64 %16 to double
%18 = load double, double* %4
%19 = fadd double %18, %17
store double %19, double* %4
br label %20
20: ; preds = %14
%21 = load i64, i64* %5
%22 = add nsw i64 %21, 1
store i64 %22, i64* %5
br label %10
23: ; preds = %10
%24 = load double, double* %4
%25 = call double @llvm.floor.f64(double %24)
%26 = fadd double %25, 1.000000e+00
store double %26, double* %2
br label %27
27: ; preds = %23, %8
%28 = load double, double* %2
ret double %28
}

LLVM IR (-O2):
define double @count_digit(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = icmp slt i64 %0, 1
br i1 %4, label %13, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %11, %5 ], [ 1, %3 ]
%7 = phi double [ %10, %5 ], [ 0.000000e+00, %3 ]
%8 = tail call i64 @log10(i64 %6)
%9 = sitofp i64 %8 to double
%10 = fadd double %7, %9
%11 = add nuw i64 %6, 1
%12 = icmp eq i64 %6, %0
br i1 %12, label %13, label %5
13: ; preds = %5, %3
%14 = phi double [ 0.000000e+00, %3 ], [ %10, %5 ]
%15 = tail call double @llvm.floor.f64(double %14)
%16 = fadd double %15, 1.000000e+00
br label %17
17: ; preds = %1, %13
%18 = phi double [ %16, %13 ], [ 1.000000e+00, %1 ]
ret double %18
}