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

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

@qc = external dso_local global i32, align 4
@val = external dso_local global [1500300 x i32], align 16
@size = external dso_local global [1500300 x i32], align 16
@tree = external dso_local global [1500300 x [2 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5RankYi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp ne i32 %4, 0
  br i1 %5, label %7, label %6

6:                                                ; preds = %1
  store i32 0, ptr %2, align 4
  br label %38

7:                                                ; preds = %1
  %8 = load i32, ptr @qc, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [1500300 x i32], ptr @val, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp sle i32 %8, %12
  br i1 %13, label %14, label %21

14:                                               ; preds = %7
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1500300 x [2 x i32]], ptr @tree, i64 0, i64 %16
  %18 = getelementptr inbounds [2 x i32], ptr %17, i64 0, i64 0
  %19 = load i32, ptr %18, align 8, !tbaa !5
  %20 = call noundef i32 @_Z5RankYi(i32 noundef %19)
  store i32 %20, ptr %2, align 4
  br label %38

21:                                               ; preds = %7
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1500300 x [2 x i32]], ptr @tree, i64 0, i64 %23
  %25 = getelementptr inbounds [2 x i32], ptr %24, i64 0, i64 0
  %26 = load i32, ptr %25, align 8, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1500300 x i32], ptr @size, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1500300 x [2 x i32]], ptr @tree, i64 0, i64 %32
  %34 = getelementptr inbounds [2 x i32], ptr %33, i64 0, i64 1
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = call noundef i32 @_Z5RankYi(i32 noundef %35)
  %37 = add nsw i32 %30, %36
  store i32 %37, ptr %2, align 4
  br label %38

38:                                               ; preds = %21, %14, %6
  %39 = load i32, ptr %2, align 4
  ret i32 %39
}

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


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

@qc = external dso_local local_unnamed_addr global i32, align 4
@val = external dso_local local_unnamed_addr global [1500300 x i32], align 16
@size = external dso_local local_unnamed_addr global [1500300 x i32], align 16
@tree = external dso_local local_unnamed_addr global [1500300 x [2 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z5RankYi(i32 noundef %0) local_unnamed_addr #0 {
  %.not811 = icmp eq i32 %0, 0
  br i1 %.not811, label %tailrecurse.outer._crit_edge, label %.lr.ph.lr.ph

.lr.ph.lr.ph:                                     ; preds = %1
  %2 = load i32, ptr @qc, align 4, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.lr.ph, %tailrecurse.outer
  %.tr.ph13 = phi i32 [ %0, %.lr.ph.lr.ph ], [ %12, %tailrecurse.outer ]
  %accumulator.tr.ph12 = phi i32 [ 0, %.lr.ph.lr.ph ], [ %14, %tailrecurse.outer ]
  br label %3

3:                                                ; preds = %.lr.ph, %tailrecurse
  %.tr9 = phi i32 [ %.tr.ph13, %.lr.ph ], [ %8, %tailrecurse ]
  %4 = sext i32 %.tr9 to i64
  %5 = getelementptr inbounds [1500300 x i32], ptr @val, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not7 = icmp sgt i32 %2, %6
  %7 = getelementptr inbounds [1500300 x [2 x i32]], ptr @tree, i64 0, i64 %4
  %8 = load i32, ptr %7, align 8, !tbaa !5
  br i1 %.not7, label %tailrecurse.outer, label %tailrecurse

tailrecurse:                                      ; preds = %3
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %tailrecurse.outer._crit_edge, label %3

tailrecurse.outer:                                ; preds = %3
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [1500300 x i32], ptr @size, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %gep = getelementptr [1500300 x [2 x i32]], ptr getelementptr (i8, ptr @tree, i64 4), i64 0, i64 %4
  %12 = load i32, ptr %gep, align 4, !tbaa !5
  %13 = add i32 %accumulator.tr.ph12, 1
  %14 = add i32 %13, %11
  %.not8 = icmp eq i32 %12, 0
  br i1 %.not8, label %tailrecurse.outer._crit_edge, label %.lr.ph

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %1
  %accumulator.tr.ph.lcssa = phi i32 [ 0, %1 ], [ %accumulator.tr.ph12, %tailrecurse ], [ %14, %tailrecurse.outer ]
  ret i32 %accumulator.tr.ph.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: 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 = !{!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,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass