; LLVM IR from upupming/algorithm :: leetcode/contest-246/1904. The Number of Full Rounds You Have Played.ll (Z3cnt4TimeS_)

; 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"

%struct.Time = type { i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmp4TimeS_(i64, i64) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3cnt4TimeS_(i64 %0, i64 %1) #1 {
  %3 = alloca %struct.Time, align 4
  %4 = alloca %struct.Time, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.Time, align 4
  %10 = alloca %struct.Time, align 4
  %11 = alloca %struct.Time, align 4
  %12 = alloca %struct.Time, align 4
  %13 = alloca %struct.Time, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i64 %0, ptr %3, align 4
  store i64 %1, ptr %4, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %16 = getelementptr inbounds %struct.Time, ptr %3, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %17, ptr %6, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %47, %2
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = getelementptr inbounds %struct.Time, ptr %4, i32 0, i32 0
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = icmp sle i32 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %50

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

25:                                               ; preds = %43, %24
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = icmp sle i32 %26, 45
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %46

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !5
  call void @_ZN4TimeC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %9, i32 noundef %30, i32 noundef %31)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %9, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %3, i64 8, i1 false), !tbaa.struct !11
  %32 = load i64, ptr %10, align 4
  %33 = load i64, ptr %11, align 4
  %34 = call noundef zeroext i1 @_Z3cmp4TimeS_(i64 %32, i64 %33)
  br i1 %34, label %42, label %35

35:                                               ; preds = %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %9, i64 8, i1 false), !tbaa.struct !11
  %36 = load i64, ptr %12, align 4
  %37 = load i64, ptr %13, align 4
  %38 = call noundef zeroext i1 @_Z3cmp4TimeS_(i64 %36, i64 %37)
  br i1 %38, label %42, label %39

39:                                               ; preds = %35
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %5, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %39, %35, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = add nsw i32 %44, 15
  store i32 %45, ptr %8, align 4, !tbaa !5
  br label %25, !llvm.loop !12

46:                                               ; preds = %28
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %6, align 4, !tbaa !5
  br label %18, !llvm.loop !14

50:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 1
  store i32 %52, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  store i32 0, ptr %15, align 4, !tbaa !5
  %53 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %14, ptr noundef nonnull align 4 dereferenceable(4) %15)
  %54 = load i32, ptr %53, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %54
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4TimeC2Eii(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef, i32 noundef) unnamed_addr #0 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #4

attributes #0 = { mustprogress 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 = { mustprogress 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint mustprogress 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 #5 = { 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++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4Time", !6, i64 0, !6, i64 4}
!11 = !{i64 0, i64 4, !5, i64 4, i64 4, !5}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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"

%struct.Time = type { i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmp4TimeS_(i64, i64) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3cnt4TimeS_(i64 %0, i64 %1) local_unnamed_addr #0 {
  %3 = alloca %struct.Time, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %.sroa.012.0.extract.trunc = trunc i64 %0 to i32
  %.sroa.011.0.extract.trunc = trunc i64 %1 to i32
  %.not18 = icmp sgt i32 %.sroa.012.0.extract.trunc, %.sroa.011.0.extract.trunc
  br i1 %.not18, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %2, %28
  %.020 = phi i32 [ %.2.3, %28 ], [ 0, %2 ]
  %.01419 = phi i32 [ %29, %28 ], [ %.sroa.012.0.extract.trunc, %2 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @_ZN4TimeC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef %.01419, i32 noundef 0)
  %.sroa.03.0.copyload = load i64, ptr %3, align 8
  %6 = call noundef zeroext i1 @_Z3cmp4TimeS_(i64 %.sroa.03.0.copyload, i64 %0)
  br i1 %6, label %13, label %10

._crit_edge.loopexit:                             ; preds = %28
  %7 = add nsw i32 %.2.3, -1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.0.lcssa = phi i32 [ -1, %2 ], [ %7, %._crit_edge.loopexit ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  store i32 %.0.lcssa, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  %8 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %9 = load i32, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  ret i32 %9

10:                                               ; preds = %.preheader
  %.sroa.0.0.copyload = load i64, ptr %3, align 8
  %11 = call noundef zeroext i1 @_Z3cmp4TimeS_(i64 %1, i64 %.sroa.0.0.copyload)
  %not. = xor i1 %11, true
  %12 = zext i1 %not. to i32
  %spec.select = add nsw i32 %.020, %12
  br label %13

13:                                               ; preds = %10, %.preheader
  %.2 = phi i32 [ %.020, %.preheader ], [ %spec.select, %10 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @_ZN4TimeC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef %.01419, i32 noundef 15)
  %.sroa.03.0.copyload.1 = load i64, ptr %3, align 8
  %14 = call noundef zeroext i1 @_Z3cmp4TimeS_(i64 %.sroa.03.0.copyload.1, i64 %0)
  br i1 %14, label %18, label %15

15:                                               ; preds = %13
  %.sroa.0.0.copyload.1 = load i64, ptr %3, align 8
  %16 = call noundef zeroext i1 @_Z3cmp4TimeS_(i64 %1, i64 %.sroa.0.0.copyload.1)
  %not..1 = xor i1 %16, true
  %17 = zext i1 %not..1 to i32
  %spec.select.1 = add nsw i32 %.2, %17
  br label %18

18:                                               ; preds = %15, %13
  %.2.1 = phi i32 [ %.2, %13 ], [ %spec.select.1, %15 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @_ZN4TimeC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef %.01419, i32 noundef 30)
  %.sroa.03.0.copyload.2 = load i64, ptr %3, align 8
  %19 = call noundef zeroext i1 @_Z3cmp4TimeS_(i64 %.sroa.03.0.copyload.2, i64 %0)
  br i1 %19, label %23, label %20

20:                                               ; preds = %18
  %.sroa.0.0.copyload.2 = load i64, ptr %3, align 8
  %21 = call noundef zeroext i1 @_Z3cmp4TimeS_(i64 %1, i64 %.sroa.0.0.copyload.2)
  %not..2 = xor i1 %21, true
  %22 = zext i1 %not..2 to i32
  %spec.select.2 = add nsw i32 %.2.1, %22
  br label %23

23:                                               ; preds = %20, %18
  %.2.2 = phi i32 [ %.2.1, %18 ], [ %spec.select.2, %20 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @_ZN4TimeC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef %.01419, i32 noundef 45)
  %.sroa.03.0.copyload.3 = load i64, ptr %3, align 8
  %24 = call noundef zeroext i1 @_Z3cmp4TimeS_(i64 %.sroa.03.0.copyload.3, i64 %0)
  br i1 %24, label %28, label %25

25:                                               ; preds = %23
  %.sroa.0.0.copyload.3 = load i64, ptr %3, align 8
  %26 = call noundef zeroext i1 @_Z3cmp4TimeS_(i64 %1, i64 %.sroa.0.0.copyload.3)
  %not..3 = xor i1 %26, true
  %27 = zext i1 %not..3 to i32
  %spec.select.3 = add nsw i32 %.2.2, %27
  br label %28

28:                                               ; preds = %25, %23
  %.2.3 = phi i32 [ %.2.2, %23 ], [ %spec.select.3, %25 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  %29 = add i32 %.01419, 1
  %exitcond.not = icmp eq i32 %.01419, %.sroa.011.0.extract.trunc
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.preheader, !llvm.loop !9
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4TimeC2Eii(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef, i32 noundef) unnamed_addr #0 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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 #3 = { 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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