#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 power(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n;
  printf("Please enter n to know how many trailing zero there are in n!: ");
  scanf("%d", &n);
  int trailingZeroesSum = 0, i = 1, result = n / 5;
  while (result > 0) {
    result = n / power(5, i);
    trailingZeroesSum += result;
    i++;
  }
  printf("Trailing zeros - > %d\n", trailingZeroesSum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeec(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11b8 <main+0x88>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%esi
mov    $0x5,%edi
call   1030 <power@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1179 <main+0x49>
mov    -0xc(%rbp),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xef1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%ebp
cmp    $0x5,%ebp
jl     11b2 <main+0x82>
mov    $0x5,%edi
mov    $0x1,%esi
call   1030 <power@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%ebx
test   %eax,%eax
jle    11b2 <main+0x82>
mov    $0x2,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0xc(%rsp),%r14d
mov    $0x5,%edi
mov    %ebp,%esi
call   1030 <power@plt>
mov    %eax,%ecx
mov    %r14d,%eax
cltd
idiv   %ecx
add    %eax,%ebx
add    $0x1,%ebp
test   %eax,%eax
jg     1190 <main+0x60>
lea    0xe8a(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [64 x i8] c"Please enter n to know how many trailing zero there are in n!: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Trailing zeros - > %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
store i32 1, i32* %4
%8 = load i32, i32* %2
%9 = sdiv i32 %8, 5
store i32 %9, i32* %5
br label %10
10: ; preds = %13, %0
%11 = load i32, i32* %5
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = load i32, i32* %2
%15 = load i32, i32* %4
%16 = call i32 @power(i32 5, i32 %15)
%17 = sdiv i32 %14, %16
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = load i32, i32* %3
%20 = add nsw i32 %19, %18
store i32 %20, i32* %3
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %10
23: ; preds = %10
%24 = load i32, i32* %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [64 x i8] c"Please enter n to know how many trailing zero there are in n!: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Trailing zeros - > %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 4
br i1 %6, label %7, label %20
7: ; preds = %0
%8 = call i32 @power(i32 5, i32 1)
%9 = sdiv i32 %5, %8
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %7, %11
%12 = phi i32 [ %18, %11 ], [ %9, %7 ]
%13 = phi i32 [ %14, %11 ], [ 1, %7 ]
%14 = add nuw nsw i32 %13, 1
%15 = load i32, i32* %1
%16 = call i32 @power(i32 5, i32 %14)
%17 = sdiv i32 %15, %16
%18 = add nsw i32 %17, %12
%19 = icmp sgt i32 %17, 0
br i1 %19, label %11, label %20
20: ; preds = %11, %7, %0
%21 = phi i32 [ 0, %0 ], [ %9, %7 ], [ %18, %11 ]
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %21)
ret i32 0
}