#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 */
scalar_t__ num_five_divisors(int);
int get_num_trailing_zeros_in_factorial_v2(int num) {
  int num_trailing_zeros, multiple_five_index;
  if (num <= 0) {
    return (0);
  }
  num_trailing_zeros = 0;
  multiple_five_index = 5;
  while (multiple_five_index <= num) {
    num_trailing_zeros += num_five_divisors(multiple_five_index);
    multiple_five_index += 5;
  }
  return (num_trailing_zeros);
}


x86 assembly (clang, -O0):
<get_num_trailing_zeros_in_factorial_v2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1131 <get_num_trailing_zeros_in_factorial_v2+0x21>
movl   $0x0,-0x4(%rbp)
jmp    1174 <get_num_trailing_zeros_in_factorial_v2+0x64>
movl   $0x0,-0xc(%rbp)
movl   $0x5,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     116e <get_num_trailing_zeros_in_factorial_v2+0x5e>
mov    -0x10(%rbp),%edi
call   1030 <num_five_divisors@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x10(%rbp)
jmp    113f <get_num_trailing_zeros_in_factorial_v2+0x2f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_num_trailing_zeros_in_factorial_v2>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
cmp    $0x5,%edi
jl     1141 <get_num_trailing_zeros_in_factorial_v2+0x31>
mov    %edi,%r14d
xor    %ebp,%ebp
mov    $0x5,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
call   1030 <num_five_divisors@plt>
add    %eax,%ebp
add    $0x5,%ebx
cmp    %r14d,%ebx
jle    1130 <get_num_trailing_zeros_in_factorial_v2+0x20>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_num_trailing_zeros_in_factorial_v2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp sle i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %25
9: ; preds = %1
store i32 0, i32* %4
store i32 5, i32* %5
br label %10
10: ; preds = %14, %9
%11 = load i32, i32* %5
%12 = load i32, i32* %3
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = load i32, i32* %5
%16 = call i64 @num_five_divisors(i32 %15)
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = add nsw i64 %18, %16
%20 = trunc i64 %19 to i32
store i32 %20, i32* %4
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 5
store i32 %22, i32* %5
br label %10
23: ; preds = %10
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %25
25: ; preds = %23, %8
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @get_num_trailing_zeros_in_factorial_v2(i32 %0) {
%2 = icmp slt i32 %0, 5
br i1 %2, label %11, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %9, %3 ], [ 5, %1 ]
%5 = phi i32 [ %8, %3 ], [ 0, %1 ]
%6 = tail call i64 @num_five_divisors(i32 %4)
%7 = trunc i64 %6 to i32
%8 = add i32 %5, %7
%9 = add nuw nsw i32 %4, 5
%10 = icmp sgt i32 %9, %0
br i1 %10, label %11, label %3
11: ; preds = %3, %1
%12 = phi i32 [ 0, %1 ], [ %8, %3 ]
ret i32 %12
}