; LLVM IR from Dev-XYS/Algorithms :: Link-Cut-Tree(with-Reverse).ll (Z5splayii)

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

@fa = external dso_local global [10010 x i32], align 16
@_ZZ5splayiiE4path = external hidden global [10010 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6rotatei(i32 noundef) #0

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5whichi(i32 noundef) #2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9push_downi(i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5splayii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %11, %2
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = icmp ne i32 %8, %9
  br i1 %10, label %11, label %21

11:                                               ; preds = %7
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %5, align 4, !tbaa !5
  %15 = sext i32 %13 to i64
  %16 = getelementptr inbounds [10010 x i32], ptr @_ZZ5splayiiE4path, i64 0, i64 %15
  store i32 %12, ptr %16, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [10010 x i32], ptr @fa, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  store i32 %20, ptr %3, align 4, !tbaa !5
  br label %7, !llvm.loop !9

21:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sub nsw i32 %22, 1
  store i32 %23, ptr %6, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %33, %21
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = icmp sge i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %36

28:                                               ; preds = %24
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10010 x i32], ptr @_ZZ5splayiiE4path, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  call void @_Z9push_downi(i32 noundef %32)
  br label %33

33:                                               ; preds = %28
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = add nsw i32 %34, -1
  store i32 %35, ptr %6, align 4, !tbaa !5
  br label %24, !llvm.loop !11

36:                                               ; preds = %27
  %37 = load i32, ptr @_ZZ5splayiiE4path, align 16, !tbaa !5
  store i32 %37, ptr %3, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %72, %36
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [10010 x i32], ptr @fa, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = icmp ne i32 %42, %43
  br i1 %44, label %45, label %74

45:                                               ; preds = %38
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [10010 x i32], ptr @fa, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [10010 x i32], ptr @fa, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = icmp ne i32 %52, %53
  br i1 %54, label %55, label %72

55:                                               ; preds = %45
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = call noundef i32 @_Z5whichi(i32 noundef %56)
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [10010 x i32], ptr @fa, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = call noundef i32 @_Z5whichi(i32 noundef %61)
  %63 = icmp eq i32 %57, %62
  br i1 %63, label %64, label %69

64:                                               ; preds = %55
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [10010 x i32], ptr @fa, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  call void @_Z6rotatei(i32 noundef %68)
  br label %71

69:                                               ; preds = %55
  %70 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z6rotatei(i32 noundef %70)
  br label %71

71:                                               ; preds = %69, %64
  br label %72

72:                                               ; preds = %71, %45
  %73 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z6rotatei(i32 noundef %73)
  br label %38, !llvm.loop !12

74:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

attributes #0 = { 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 #1 = { 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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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

@fa = external dso_local local_unnamed_addr global [10010 x i32], align 16
@_ZZ5splayiiE4path = external hidden local_unnamed_addr global [10010 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6rotatei(i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5whichi(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9push_downi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5splayii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not24 = icmp eq i32 %0, %1
  br i1 %.not24, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %3 = trunc nuw i64 %indvars.iv.next to i32
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph28.preheader, label %._crit_edge

.lr.ph28.preheader:                               ; preds = %.preheader
  %5 = and i64 %indvars.iv.next, 2147483647
  br label %.lr.ph28

.lr.ph:                                           ; preds = %2, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %2 ]
  %.01925 = phi i32 [ %9, %.lr.ph ], [ %0, %2 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %6 = getelementptr inbounds [10010 x i32], ptr @_ZZ5splayiiE4path, i64 0, i64 %indvars.iv
  store i32 %.01925, ptr %6, align 4, !tbaa !5
  %7 = sext i32 %.01925 to i64
  %8 = getelementptr inbounds [10010 x i32], ptr @fa, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not = icmp eq i32 %9, %1
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph28, %2, %.preheader
  %10 = load i32, ptr @_ZZ5splayiiE4path, align 16, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [10010 x i32], ptr @fa, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not2229 = icmp eq i32 %13, %1
  br i1 %.not2229, label %._crit_edge32, label %.lr.ph31

.lr.ph28:                                         ; preds = %.lr.ph28.preheader, %.lr.ph28
  %indvars.iv34 = phi i64 [ %5, %.lr.ph28.preheader ], [ %indvars.iv.next35, %.lr.ph28 ]
  %indvars.iv.next35 = add nsw i64 %indvars.iv34, -1
  %14 = getelementptr inbounds [10010 x i32], ptr @_ZZ5splayiiE4path, i64 0, i64 %indvars.iv.next35
  %15 = load i32, ptr %14, align 4, !tbaa !5
  tail call void @_Z9push_downi(i32 noundef %15)
  %16 = icmp ugt i64 %indvars.iv34, 1
  br i1 %16, label %.lr.ph28, label %._crit_edge, !llvm.loop !11

.lr.ph31:                                         ; preds = %._crit_edge, %28
  %17 = phi i32 [ %29, %28 ], [ %13, %._crit_edge ]
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [10010 x i32], ptr @fa, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %.not23 = icmp eq i32 %20, %1
  br i1 %.not23, label %28, label %21

21:                                               ; preds = %.lr.ph31
  %22 = tail call noundef i32 @_Z5whichi(i32 noundef %10)
  %23 = load i32, ptr %12, align 4, !tbaa !5
  %24 = tail call noundef i32 @_Z5whichi(i32 noundef %23)
  %25 = icmp eq i32 %22, %24
  br i1 %25, label %26, label %.sink.split

26:                                               ; preds = %21
  %27 = load i32, ptr %12, align 4, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %21, %26
  %.sink = phi i32 [ %27, %26 ], [ %10, %21 ]
  tail call void @_Z6rotatei(i32 noundef %.sink)
  br label %28

28:                                               ; preds = %.sink.split, %.lr.ph31
  tail call void @_Z6rotatei(i32 noundef %10)
  %29 = load i32, ptr %12, align 4, !tbaa !5
  %.not22 = icmp eq i32 %29, %1
  br i1 %.not22, label %._crit_edge32, label %.lr.ph31, !llvm.loop !12

._crit_edge32:                                    ; preds = %28, %._crit_edge
  ret void
}

attributes #0 = { 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 #1 = { 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" }

!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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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