; LLVM IR from kenjin/Awesome-LC-C-Cracker :: leetcode-c-sol/0172_Factorial-Trailing-Zeroes (0172_Factorial-Trailing-Zeroes)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
define dso_local i32 @trailingZeroes(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store double 1.000000e+00, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %13, %1
  %8 = load double, ptr %3, align 8, !tbaa !9
  %9 = fmul double %8, 5.000000e+00
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sitofp i32 %10 to double
  %12 = fcmp ole double %9, %11
  br i1 %12, label %13, label %18

13:                                               ; preds = %7
  %14 = load double, ptr %3, align 8, !tbaa !9
  %15 = fmul double %14, 5.000000e+00
  store double %15, ptr %3, align 8, !tbaa !9
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %4, align 4, !tbaa !5
  br label %7, !llvm.loop !11

18:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %35, %18
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %38

24:                                               ; preds = %19
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sitofp i32 %25 to double
  %27 = load double, ptr %3, align 8, !tbaa !9
  %28 = fdiv double %26, %27
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sitofp i32 %29 to double
  %31 = fadd double %30, %28
  %32 = fptosi double %31 to i32
  store i32 %32, ptr %5, align 4, !tbaa !5
  %33 = load double, ptr %3, align 8, !tbaa !9
  %34 = fdiv double %33, 5.000000e+00
  store double %34, ptr %3, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %24
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %6, align 4, !tbaa !5
  br label %19, !llvm.loop !13

38:                                               ; preds = %23
  %39 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i32 %39
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local i32 @trailingZeroes(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sitofp i32 %0 to double
  br label %3

3:                                                ; preds = %3, %1
  %.013 = phi double [ 1.000000e+00, %1 ], [ %4, %3 ]
  %.012 = phi i32 [ 0, %1 ], [ %6, %3 ]
  %4 = fmul double %.013, 5.000000e+00
  %5 = fcmp ugt double %4, %2
  %6 = add nuw nsw i32 %.012, 1
  br i1 %5, label %.preheader, label %3, !llvm.loop !5

.preheader:                                       ; preds = %3
  %.not = icmp eq i32 %.012, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %xtraiter = and i32 %.012, 3
  %7 = icmp ult i32 %.012, 4
  br i1 %7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %.012, 2147483644
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %31, %.lr.ph ]
  %.01117.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %31, %.lr.ph ]
  %.116.unr = phi double [ %.013, %.lr.ph.preheader ], [ %32, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.01117.epil = phi i32 [ %11, %.lr.ph.epil ], [ %.01117.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.116.epil = phi double [ %12, %.lr.ph.epil ], [ %.116.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %8 = fdiv double %2, %.116.epil
  %9 = sitofp i32 %.01117.epil to double
  %10 = fadd double %8, %9
  %11 = fptosi double %10 to i32
  %12 = fdiv double %.116.epil, 5.000000e+00
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !7

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %.preheader
  %.011.lcssa = phi i32 [ 0, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %11, %.lr.ph.epil ]
  ret i32 %.011.lcssa

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01117 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %31, %.lr.ph ]
  %.116 = phi double [ %.013, %.lr.ph.preheader.new ], [ %32, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %13 = fdiv double %2, %.116
  %14 = sitofp i32 %.01117 to double
  %15 = fadd double %13, %14
  %16 = fptosi double %15 to i32
  %17 = fdiv double %.116, 5.000000e+00
  %18 = fdiv double %2, %17
  %19 = sitofp i32 %16 to double
  %20 = fadd double %18, %19
  %21 = fptosi double %20 to i32
  %22 = fdiv double %17, 5.000000e+00
  %23 = fdiv double %2, %22
  %24 = sitofp i32 %21 to double
  %25 = fadd double %23, %24
  %26 = fptosi double %25 to i32
  %27 = fdiv double %22, 5.000000e+00
  %28 = fdiv double %2, %27
  %29 = sitofp i32 %26 to double
  %30 = fadd double %28, %29
  %31 = fptosi double %30 to i32
  %32 = fdiv double %27, 5.000000e+00
  %niter.next.3 = add i32 %niter, 4
  %niter.ncmp.3 = icmp eq i32 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9
}

attributes #0 = { nofree norecurse nosync nounwind memory(none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !8}
!8 = !{!"llvm.loop.unroll.disable"}
!9 = distinct !{!9, !6}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass