#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, long long *);
int main() {
  int div = 5, zeroes = 0;
  long long int n;
  printf("Problem 1: Given a number n, the program will print the number of "
         "rightmost 0's of n!.\n");
  printf("Please enter input n: ");
  scanf("%lld", &n);
  while (div <= n) {
    zeroes = zeroes + (n / div);
    div = div * 5;
  }
  printf("The output is: %lld! has %d rightmost 0's.\n", n, zeroes);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf0f(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
movslq -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jg     11a5 <main+0x85>
movslq -0xc(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
imul   $0x5,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1169 <main+0x49>
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xf0c(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebf(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%rsi
cmp    $0x5,%rsi
jge    1185 <main+0x55>
lea    0xea8(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    $0x5,%ecx
mov    $0x5,%edi
mov    %rsi,%r8
shr    $0x20,%r8
jmp    11b4 <main+0x84>
nopl   0x0(%rax,%rax,1)
mov    %rsi,%rax
cqto
idiv   %rdi
add    %eax,%ebx
lea    (%rcx,%rcx,4),%edi
mov    %edi,%ecx
cmp    %rdi,%rsi
jl     116d <main+0x3d>
test   %r8,%r8
jne    11a0 <main+0x70>
mov    %esi,%eax
xor    %edx,%edx
div    %edi
jmp    11a8 <main+0x78>

LLVM IR (-O0):
@.str = [88 x i8] c"Problem 1: Given a number n, the program will print the number of rightmost 0's of n!.\0A\00"
@.str.1 = [23 x i8] c"Please enter input n: \00"
@.str.2 = [5 x i8] c"%lld\00"
@.str.3 = [44 x i8] c"The output is: %lld! has %d rightmost 0's.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
store i32 5, i32* %2
store i32 0, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %4)
br label %8
8: ; preds = %13, %0
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = load i64, i64* %4
%12 = icmp sle i64 %10, %11
br i1 %12, label %13, label %24
13: ; preds = %8
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = load i64, i64* %4
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = sdiv i64 %16, %18
%20 = add nsw i64 %15, %19
%21 = trunc i64 %20 to i32
store i32 %21, i32* %3
%22 = load i32, i32* %2
%23 = mul nsw i32 %22, 5
store i32 %23, i32* %2
br label %8
24: ; preds = %8
%25 = load i64, i64* %4
%26 = load i32, i32* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i64 %25, i32 %26)
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"Please enter input n: \00"
@.str.2 = [5 x i8] c"%lld\00"
@.str.3 = [44 x i8] c"The output is: %lld! has %d rightmost 0's.\0A\00"
@str = [87 x i8] c"Problem 1: Given a number n, the program will print the number of rightmost 0's of n!.\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([87 x i8], [87 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%6 = load i64, i64* %1
%7 = icmp slt i64 %6, 5
br i1 %7, label %18, label %8
8: ; preds = %0, %8
%9 = phi i64 [ %16, %8 ], [ 5, %0 ]
%10 = phi i32 [ %14, %8 ], [ 0, %0 ]
%11 = phi i32 [ %15, %8 ], [ 5, %0 ]
%12 = sdiv i64 %6, %9
%13 = trunc i64 %12 to i32
%14 = add i32 %10, %13
%15 = mul nsw i32 %11, 5
%16 = zext i32 %15 to i64
%17 = icmp slt i64 %6, %16
br i1 %17, label %18, label %8
18: ; preds = %8, %0
%19 = phi i32 [ 0, %0 ], [ %14, %8 ]
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i64 %6, i32 %19)
ret i32 0
}