#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 */
int log(double);
scalar_t__ pow(double, int);
int trailingZerosInFact(int n) {
  int max_exp_5 = (int)(log(n * 1.0) / log(5.0));
  int max_power = (int)(pow(5.0, max_exp_5));
  int num5 = 0;
  while (max_power > 1) {
    num5 += n / max_power;
    max_power /= 5;
  }
  return num5;
}


x86 assembly (clang, -O0):
<trailingZerosInFact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xed0(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <log@plt>
mov    %eax,-0x14(%rbp)
movsd  0xeb4(%rip),%xmm0
call   1030 <log@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
movsd  0xe99(%rip),%xmm0
call   1040 <pow@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    11a0 <trailingZerosInFact+0x80>
mov    -0x4(%rbp),%eax
cltd
idivl  -0xc(%rbp)
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    1176 <trailingZerosInFact+0x56>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trailingZerosInFact>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
cvtsi2sd %edi,%xmm0
call   1030 <log@plt>
mov    %eax,%ebp
movsd  0xec8(%rip),%xmm0
call   1030 <log@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
movsd  0xeb4(%rip),%xmm0
mov    %eax,%edi
call   1040 <pow@plt>
mov    %rax,%rsi
xor    %ecx,%ecx
cmp    $0x2,%esi
jl     1188 <trailingZerosInFact+0x68>
xor    %ecx,%ecx
mov    $0xcccccccd,%edi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%eax
cltd
idiv   %esi
add    %eax,%ecx
mov    %esi,%eax
imul   %rdi,%rax
shr    $0x22,%rax
cmp    $0x9,%esi
mov    %eax,%esi
ja     1170 <trailingZerosInFact+0x50>
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @trailingZerosInFact(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = sitofp i32 %6 to double
%8 = fmul double %7, 1.000000e+00
%9 = call i32 @log(double %8)
%10 = call i32 @log(double 5.000000e+00)
%11 = sdiv i32 %9, %10
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = call i64 @pow(double 5.000000e+00, i32 %12)
%14 = trunc i64 %13 to i32
store i32 %14, i32* %4
store i32 0, i32* %5
br label %15
15: ; preds = %18, %1
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i32, i32* %2
%20 = load i32, i32* %4
%21 = sdiv i32 %19, %20
%22 = load i32, i32* %5
%23 = add nsw i32 %22, %21
store i32 %23, i32* %5
%24 = load i32, i32* %4
%25 = sdiv i32 %24, 5
store i32 %25, i32* %4
br label %15
26: ; preds = %15
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
define i32 @trailingZerosInFact(i32 %0) {
%2 = sitofp i32 %0 to double
%3 = tail call i32 @log(double %2)
%4 = tail call i32 @log(double 5.000000e+00)
%5 = sdiv i32 %3, %4
%6 = tail call i64 @pow(double 5.000000e+00, i32 %5)
%7 = trunc i64 %6 to i32
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %16
9: ; preds = %1, %9
%10 = phi i32 [ %13, %9 ], [ 0, %1 ]
%11 = phi i32 [ %14, %9 ], [ %7, %1 ]
%12 = sdiv i32 %0, %11
%13 = add nsw i32 %12, %10
%14 = udiv i32 %11, 5
%15 = icmp ugt i32 %11, 9
br i1 %15, label %9, label %16
16: ; preds = %9, %1
%17 = phi i32 [ 0, %1 ], [ %13, %9 ]
ret i32 %17
}