#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, int);
int trailing_zero_factorial(int A) {
  int count_5 = 0;
  int i = 0;
  for (i = 5; A / i > 0; i *= 5) {
    printf("i:[%d], A/i:[%d]\n", i, A / i);
    count_5 += A / i;
  }
  return count_5;
}


x86 assembly (clang, -O0):
<trailing_zero_factorial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x5,-0xc(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%eax
jle    1171 <trailing_zero_factorial+0x61>
mov    -0xc(%rbp),%esi
mov    -0x4(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,%edx
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
cltd
idivl  -0xc(%rbp)
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
imul   $0x5,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1130 <trailing_zero_factorial+0x20>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trailing_zero_factorial>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r15d,%r15d
cmp    $0x5,%edi
jl     116f <trailing_zero_factorial+0x5f>
mov    %edi,%r14d
mov    %edi,%eax
mov    $0xcccccccd,%ebx
imul   %rax,%rbx
shr    $0x22,%rbx
xor    %r15d,%r15d
mov    $0x5,%ebp
lea    0xebf(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
add    %ebx,%r15d
lea    0x0(%rbp,%rbp,4),%ebp
mov    %r14d,%eax
cltd
idiv   %ebp
mov    %eax,%ebx
test   %eax,%eax
jg     1150 <trailing_zero_factorial+0x40>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"i:[%d], A/i:[%d]\0A\00"
define i32 @trailing_zero_factorial(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 5, i32* %4
br label %5
5: ; preds = %21, %1
%6 = load i32, i32* %2
%7 = load i32, i32* %4
%8 = sdiv i32 %6, %7
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %5
%11 = load i32, i32* %4
%12 = load i32, i32* %2
%13 = load i32, i32* %4
%14 = sdiv i32 %12, %13
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %14)
%16 = load i32, i32* %2
%17 = load i32, i32* %4
%18 = sdiv i32 %16, %17
%19 = load i32, i32* %3
%20 = add nsw i32 %19, %18
store i32 %20, i32* %3
br label %21
21: ; preds = %10
%22 = load i32, i32* %4
%23 = mul nsw i32 %22, 5
store i32 %23, i32* %4
br label %5
24: ; preds = %5
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [18 x i8] c"i:[%d], A/i:[%d]\0A\00"
define i32 @trailing_zero_factorial(i32 %0) {
%2 = icmp sgt i32 %0, 4
br i1 %2, label %3, label %14
3: ; preds = %1
%4 = udiv i32 %0, 5
br label %5
5: ; preds = %3, %5
%6 = phi i32 [ %12, %5 ], [ %4, %3 ]
%7 = phi i32 [ %11, %5 ], [ 5, %3 ]
%8 = phi i32 [ %10, %5 ], [ 0, %3 ]
%9 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %6)
%10 = add nsw i32 %6, %8
%11 = mul nsw i32 %7, 5
%12 = sdiv i32 %0, %11
%13 = icmp sgt i32 %12, 0
br i1 %13, label %5, label %14
14: ; preds = %5, %1
%15 = phi i32 [ 0, %1 ], [ %10, %5 ]
ret i32 %15
}