int trailingZeroes(int n) {
  return n / 5 + n / 25 + n / 125 + n / 625 + n / 3125 + n / 15625 + n / 78125 +
         n / 390625 + n / 1953125 + n / 9765625 + n / 48828125 + n / 244140625 +
         n / 1220703125;
}


x86 assembly (clang, -O0):
<trailingZeroes>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x19,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x7d,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x271,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xc35,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3d09,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x1312d,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x5f5e1,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x1dcd65,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x9502f9,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2e90edd,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xe8d4a51,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x48c27395,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
add    %ecx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<trailingZeroes>:
movslq %edi,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
imul   $0x51eb851f,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x23,%rdx
add    %esi,%edx
add    %ecx,%edx
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x23,%rcx
add    %esi,%ecx
add    %edx,%ecx
imul   $0x68db8bad,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x28,%rdx
add    %esi,%edx
add    %ecx,%edx
imul   $0x14f8b589,%rax,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x28,%rcx
add    %esi,%ecx
add    %edx,%ecx
imul   $0x431bde83,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x2c,%rdx
add    %esi,%edx
add    %ecx,%edx
imul   $0x6b5fca6b,%rax,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x2f,%rcx
add    %esi,%ecx
add    %edx,%ecx
imul   $0x55e63b89,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x31,%rdx
add    %esi,%edx
add    %ecx,%edx
imul   $0x44b82fa1,%rax,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x33,%rcx
add    %esi,%ecx
add    %edx,%ecx
imul   $0xdbe6fed,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x33,%rdx
add    %esi,%edx
add    %ecx,%edx
imul   $0x2bfaffc3,%rax,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x37,%rcx
add    %esi,%ecx
add    %edx,%ecx
imul   $0x465e6605,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x3a,%rdx
add    %esi,%edx
add    %ecx,%edx
imul   $0x384b84d1,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x3c,%rax
add    %ecx,%eax
add    %edx,%eax
ret

LLVM IR (-O0):
define i32 @trailingZeroes(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = sdiv i32 %3, 5
%5 = load i32, i32* %2
%6 = sdiv i32 %5, 25
%7 = add nsw i32 %4, %6
%8 = load i32, i32* %2
%9 = sdiv i32 %8, 125
%10 = add nsw i32 %7, %9
%11 = load i32, i32* %2
%12 = sdiv i32 %11, 625
%13 = add nsw i32 %10, %12
%14 = load i32, i32* %2
%15 = sdiv i32 %14, 3125
%16 = add nsw i32 %13, %15
%17 = load i32, i32* %2
%18 = sdiv i32 %17, 15625
%19 = add nsw i32 %16, %18
%20 = load i32, i32* %2
%21 = sdiv i32 %20, 78125
%22 = add nsw i32 %19, %21
%23 = load i32, i32* %2
%24 = sdiv i32 %23, 390625
%25 = add nsw i32 %22, %24
%26 = load i32, i32* %2
%27 = sdiv i32 %26, 1953125
%28 = add nsw i32 %25, %27
%29 = load i32, i32* %2
%30 = sdiv i32 %29, 9765625
%31 = add nsw i32 %28, %30
%32 = load i32, i32* %2
%33 = sdiv i32 %32, 48828125
%34 = add nsw i32 %31, %33
%35 = load i32, i32* %2
%36 = sdiv i32 %35, 244140625
%37 = add nsw i32 %34, %36
%38 = load i32, i32* %2
%39 = sdiv i32 %38, 1220703125
%40 = add nsw i32 %37, %39
ret i32 %40
}

LLVM IR (-O2):
define i32 @trailingZeroes(i32 %0) {
%2 = sdiv i32 %0, 5
%3 = sdiv i32 %0, 25
%4 = add nsw i32 %2, %3
%5 = sdiv i32 %0, 125
%6 = add nsw i32 %4, %5
%7 = sdiv i32 %0, 625
%8 = add nsw i32 %6, %7
%9 = sdiv i32 %0, 3125
%10 = add nsw i32 %8, %9
%11 = sdiv i32 %0, 15625
%12 = add nsw i32 %10, %11
%13 = sdiv i32 %0, 78125
%14 = add nsw i32 %12, %13
%15 = sdiv i32 %0, 390625
%16 = add nsw i32 %14, %15
%17 = sdiv i32 %0, 1953125
%18 = add nsw i32 %16, %17
%19 = sdiv i32 %0, 9765625
%20 = add nsw i32 %18, %19
%21 = sdiv i32 %0, 48828125
%22 = add nsw i32 %20, %21
%23 = sdiv i32 %0, 244140625
%24 = add nsw i32 %22, %23
%25 = sdiv i32 %0, 1220703125
%26 = add nsw i32 %24, %25
ret i32 %26
}