; LLVM IR from lzyrapx/Competitive-Programming :: LibreOJ/106（Splay）（104基础上加区间）.ll (Z5RankXiii)

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

@left = external dso_local global i32, align 4
@right = external dso_local global i32, align 4
@root = external dso_local global [200040 x i32], align 16

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z5RankYi(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5RankXiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %10 = load i32, ptr @left, align 4, !tbaa !5
  %11 = load i32, ptr %6, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %13, label %24

13:                                               ; preds = %3
  %14 = load i32, ptr %7, align 4, !tbaa !5
  %15 = load i32, ptr @right, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %17, label %24

17:                                               ; preds = %13
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [200040 x i32], ptr @root, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = call noundef i32 @_Z5RankYi(i32 noundef %21)
  %23 = sub nsw i32 %22, 1
  store i32 %23, ptr %4, align 4
  br label %66

24:                                               ; preds = %13, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = add nsw i32 %25, %26
  %28 = ashr i32 %27, 1
  store i32 %28, ptr %8, align 4, !tbaa !5
  %29 = load i32, ptr @right, align 4, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %32, label %38

32:                                               ; preds = %24
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = shl i32 %33, 1
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = call noundef i32 @_Z5RankXiii(i32 noundef %34, i32 noundef %35, i32 noundef %36)
  store i32 %37, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %65

38:                                               ; preds = %24
  %39 = load i32, ptr @left, align 4, !tbaa !5
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = icmp sgt i32 %39, %40
  br i1 %41, label %42, label %50

42:                                               ; preds = %38
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = shl i32 %43, 1
  %45 = or i32 %44, 1
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = call noundef i32 @_Z5RankXiii(i32 noundef %45, i32 noundef %47, i32 noundef %48)
  store i32 %49, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %65

50:                                               ; preds = %38
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = shl i32 %52, 1
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = call noundef i32 @_Z5RankXiii(i32 noundef %53, i32 noundef %54, i32 noundef %55)
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = shl i32 %57, 1
  %59 = or i32 %58, 1
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = call noundef i32 @_Z5RankXiii(i32 noundef %59, i32 noundef %61, i32 noundef %62)
  %64 = add nsw i32 %56, %63
  store i32 %64, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %65

65:                                               ; preds = %51, %42, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %66

66:                                               ; preds = %65, %17
  %67 = load i32, ptr %4, align 4
  ret i32 %67
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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"}


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

@left = external dso_local local_unnamed_addr global i32, align 4
@right = external dso_local local_unnamed_addr global i32, align 4
@root = external dso_local local_unnamed_addr global [200040 x i32], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5RankXiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @left, align 4, !tbaa !5
  %5 = load i32, ptr @right, align 4
  %.not4556 = icmp sgt i32 %4, %1
  %.not22354657 = icmp slt i32 %5, %2
  %or.cond364758 = select i1 %.not4556, i1 true, i1 %.not22354657
  br i1 %or.cond364758, label %.lr.ph.lr.ph, label %tailrecurse.outer26._crit_edge

.lr.ph.lr.ph:                                     ; preds = %3, %tailrecurse.outer
  %.not4563 = phi i1 [ %.not45, %tailrecurse.outer ], [ %.not4556, %3 ]
  %6 = phi i32 [ %28, %tailrecurse.outer ], [ %5, %3 ]
  %7 = phi i32 [ %27, %tailrecurse.outer ], [ %4, %3 ]
  %.tr25.ph62 = phi i32 [ %.us-phi43, %tailrecurse.outer ], [ %2, %3 ]
  %.tr24.ph61 = phi i32 [ %25, %tailrecurse.outer ], [ %1, %3 ]
  %.tr.ph60 = phi i32 [ %24, %tailrecurse.outer ], [ %0, %3 ]
  %accumulator.tr.ph59 = phi i32 [ %26, %tailrecurse.outer ], [ 0, %3 ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.lr.ph, %tailrecurse.outer26
  %.not51 = phi i1 [ %.not4563, %.lr.ph.lr.ph ], [ %.not, %tailrecurse.outer26 ]
  %.tr25.ph2950 = phi i32 [ %.tr25.ph62, %.lr.ph.lr.ph ], [ %.us-phi43, %tailrecurse.outer26 ]
  %.tr24.ph2849 = phi i32 [ %.tr24.ph61, %.lr.ph.lr.ph ], [ %22, %tailrecurse.outer26 ]
  %.tr.ph2748 = phi i32 [ %.tr.ph60, %.lr.ph.lr.ph ], [ %21, %tailrecurse.outer26 ]
  %.not.fr = freeze i1 %.not51
  br i1 %.not.fr, label %tailrecurse.us, label %.lr.ph.split

tailrecurse.us:                                   ; preds = %.lr.ph, %tailrecurse.us
  %.tr2538.us = phi i32 [ %9, %tailrecurse.us ], [ %.tr25.ph2950, %.lr.ph ]
  %.tr37.us = phi i32 [ %10, %tailrecurse.us ], [ %.tr.ph2748, %.lr.ph ]
  %8 = add nsw i32 %.tr2538.us, %.tr24.ph2849
  %9 = ashr i32 %8, 1
  %.not23.us = icmp sgt i32 %6, %9
  %10 = shl i32 %.tr37.us, 1
  br i1 %.not23.us, label %.split.us, label %tailrecurse.us

tailrecurse.outer26._crit_edge:                   ; preds = %tailrecurse.outer, %tailrecurse.outer26, %tailrecurse, %3
  %accumulator.tr.ph.lcssa = phi i32 [ 0, %3 ], [ %accumulator.tr.ph59, %tailrecurse ], [ %accumulator.tr.ph59, %tailrecurse.outer26 ], [ %26, %tailrecurse.outer ]
  %.tr.lcssa = phi i32 [ %0, %3 ], [ %18, %tailrecurse ], [ %21, %tailrecurse.outer26 ], [ %24, %tailrecurse.outer ]
  %11 = sext i32 %.tr.lcssa to i64
  %12 = getelementptr inbounds [200040 x i32], ptr @root, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = tail call noundef i32 @_Z5RankYi(i32 noundef %13)
  %15 = add i32 %accumulator.tr.ph.lcssa, -1
  %accumulator.ret.tr = add i32 %15, %14
  ret i32 %accumulator.ret.tr

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr2538 = phi i32 [ %17, %tailrecurse ], [ %.tr25.ph2950, %.lr.ph ]
  %.tr37 = phi i32 [ %18, %tailrecurse ], [ %.tr.ph2748, %.lr.ph ]
  %16 = add nsw i32 %.tr2538, %.tr24.ph2849
  %17 = ashr i32 %16, 1
  %.not23 = icmp sgt i32 %6, %17
  br i1 %.not23, label %.split.us, label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph.split
  %18 = shl i32 %.tr37, 1
  %.not22 = icmp slt i32 %6, %17
  br i1 %.not22, label %.lr.ph.split, label %tailrecurse.outer26._crit_edge

.split.us:                                        ; preds = %.lr.ph.split, %tailrecurse.us
  %.us-phi = phi i32 [ %9, %tailrecurse.us ], [ %17, %.lr.ph.split ]
  %.us-phi42 = phi i32 [ %.tr37.us, %tailrecurse.us ], [ %.tr37, %.lr.ph.split ]
  %.us-phi43 = phi i32 [ %.tr2538.us, %tailrecurse.us ], [ %.tr2538, %.lr.ph.split ]
  %19 = icmp sgt i32 %7, %.us-phi
  %20 = shl i32 %.us-phi42, 1
  br i1 %19, label %tailrecurse.outer26, label %tailrecurse.outer

tailrecurse.outer26:                              ; preds = %.split.us
  %21 = or disjoint i32 %20, 1
  %22 = add nsw i32 %.us-phi, 1
  %.not = icmp sgt i32 %7, %22
  %.not2235 = icmp slt i32 %6, %.us-phi43
  %or.cond36 = select i1 %.not, i1 true, i1 %.not2235
  br i1 %or.cond36, label %.lr.ph, label %tailrecurse.outer26._crit_edge

tailrecurse.outer:                                ; preds = %.split.us
  %23 = tail call noundef i32 @_Z5RankXiii(i32 noundef %20, i32 noundef %.tr24.ph2849, i32 noundef %.us-phi)
  %24 = or disjoint i32 %20, 1
  %25 = add nsw i32 %.us-phi, 1
  %26 = add nsw i32 %23, %accumulator.tr.ph59
  %27 = load i32, ptr @left, align 4, !tbaa !5
  %28 = load i32, ptr @right, align 4
  %.not45 = icmp sgt i32 %27, %25
  %.not223546 = icmp slt i32 %28, %.us-phi43
  %or.cond3647 = select i1 %.not45, i1 true, i1 %.not223546
  br i1 %or.cond3647, label %.lr.ph.lr.ph, label %tailrecurse.outer26._crit_edge
}

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

!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"}


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