; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/可持久化Treap.ll (ZN12shared_treap3kthEPNS_4nodeEi)

; 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.shared_treap::node" = type <{ %"struct.shared_treap::pointer", %"struct.shared_treap::pointer", i32, i32, i32, [4 x i8] }>
%"struct.shared_treap::pointer" = type { ptr }

@_ZN12shared_treap5nodesE = external dso_local global [510000 x %"struct.shared_treap::node"], align 16

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK12shared_treap7pointercvPNS_4nodeEEv(ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN12shared_treap7pointerptEv(ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN12shared_treap3kthEPNS_4nodeEi(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp eq ptr %6, @_ZN12shared_treap5nodesE
  br i1 %7, label %17, label %8

8:                                                ; preds = %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp sle i32 %9, 0
  br i1 %10, label %17, label %11

11:                                               ; preds = %8
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.shared_treap::node", ptr %13, i32 0, i32 3
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp sgt i32 %12, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %11, %8, %2
  store i32 0, ptr %3, align 4
  br label %58

18:                                               ; preds = %11
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.shared_treap::node", ptr %20, i32 0, i32 0
  %22 = call noundef ptr @_ZN12shared_treap7pointerptEv(ptr noundef nonnull align 8 dereferenceable(8) %21)
  %23 = getelementptr inbounds %"struct.shared_treap::node", ptr %22, i32 0, i32 3
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = add nsw i32 %24, 1
  %26 = icmp eq i32 %19, %25
  br i1 %26, label %27, label %31

27:                                               ; preds = %18
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.shared_treap::node", ptr %28, i32 0, i32 2
  %30 = load i32, ptr %29, align 8, !tbaa !14
  store i32 %30, ptr %3, align 4
  br label %58

31:                                               ; preds = %18
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.shared_treap::node", ptr %33, i32 0, i32 0
  %35 = call noundef ptr @_ZN12shared_treap7pointerptEv(ptr noundef nonnull align 8 dereferenceable(8) %34)
  %36 = getelementptr inbounds %"struct.shared_treap::node", ptr %35, i32 0, i32 3
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = icmp sle i32 %32, %37
  br i1 %38, label %39, label %45

39:                                               ; preds = %31
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.shared_treap::node", ptr %40, i32 0, i32 0
  %42 = call noundef ptr @_ZNK12shared_treap7pointercvPNS_4nodeEEv(ptr noundef nonnull align 8 dereferenceable(8) %41)
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = call noundef i32 @_ZN12shared_treap3kthEPNS_4nodeEi(ptr noundef %42, i32 noundef %43)
  store i32 %44, ptr %3, align 4
  br label %58

45:                                               ; preds = %31
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.shared_treap::node", ptr %46, i32 0, i32 1
  %48 = call noundef ptr @_ZNK12shared_treap7pointercvPNS_4nodeEEv(ptr noundef nonnull align 8 dereferenceable(8) %47)
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.shared_treap::node", ptr %50, i32 0, i32 0
  %52 = call noundef ptr @_ZN12shared_treap7pointerptEv(ptr noundef nonnull align 8 dereferenceable(8) %51)
  %53 = getelementptr inbounds %"struct.shared_treap::node", ptr %52, i32 0, i32 3
  %54 = load i32, ptr %53, align 4, !tbaa !11
  %55 = sub nsw i32 %49, %54
  %56 = sub nsw i32 %55, 1
  %57 = call noundef i32 @_ZN12shared_treap3kthEPNS_4nodeEi(ptr noundef %48, i32 noundef %56)
  store i32 %57, ptr %3, align 4
  br label %58

58:                                               ; preds = %45, %39, %27, %17
  %59 = load i32, ptr %3, align 4
  ret i32 %59
}

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

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 20}
!12 = !{!"_ZTSN12shared_treap4nodeE", !13, i64 0, !13, i64 8, !10, i64 16, !10, i64 20, !10, i64 24}
!13 = !{!"_ZTSN12shared_treap7pointerE", !6, i64 0}
!14 = !{!12, !10, i64 16}


; 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.shared_treap::node" = type <{ %"struct.shared_treap::pointer", %"struct.shared_treap::pointer", i32, i32, i32, [4 x i8] }>
%"struct.shared_treap::pointer" = type { ptr }

@_ZN12shared_treap5nodesE = external dso_local global [510000 x %"struct.shared_treap::node"], align 16

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK12shared_treap7pointercvPNS_4nodeEEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN12shared_treap7pointerptEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN12shared_treap3kthEPNS_4nodeEi(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = icmp slt i32 %1, 1
  %4 = icmp eq ptr %0, @_ZN12shared_treap5nodesE
  %or.cond2027 = or i1 %4, %3
  br i1 %or.cond2027, label %.loopexit, label %.lr.ph.split.preheader

.lr.ph.split.preheader:                           ; preds = %2, %tailrecurse.outer
  %.tr17.ph29 = phi i32 [ %26, %tailrecurse.outer ], [ %1, %2 ]
  %.tr.ph28 = phi ptr [ %21, %tailrecurse.outer ], [ %0, %2 ]
  br label %.lr.ph.split

.lr.ph.split:                                     ; preds = %.lr.ph.split.preheader, %tailrecurse
  %.tr21 = phi ptr [ %18, %tailrecurse ], [ %.tr.ph28, %.lr.ph.split.preheader ]
  %5 = getelementptr inbounds i8, ptr %.tr21, i64 20
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp slt i32 %6, %.tr17.ph29
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %.lr.ph.split
  %9 = tail call noundef ptr @_ZN12shared_treap7pointerptEv(ptr noundef nonnull align 8 dereferenceable(8) %.tr21)
  %10 = getelementptr inbounds i8, ptr %9, i64 20
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  %13 = icmp eq i32 %12, %.tr17.ph29
  br i1 %13, label %.split.us, label %14

.split.us:                                        ; preds = %8
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.tr21, i64 16
  %.pre = load i32, ptr %.phi.trans.insert, align 8, !tbaa !12
  br label %.loopexit

14:                                               ; preds = %8
  %15 = tail call noundef ptr @_ZN12shared_treap7pointerptEv(ptr noundef nonnull align 8 dereferenceable(8) %.tr21)
  %16 = getelementptr inbounds i8, ptr %15, i64 20
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %.not = icmp slt i32 %17, %.tr17.ph29
  br i1 %.not, label %tailrecurse.outer, label %tailrecurse

tailrecurse:                                      ; preds = %14
  %18 = tail call noundef ptr @_ZNK12shared_treap7pointercvPNS_4nodeEEv(ptr noundef nonnull align 8 dereferenceable(8) %.tr21)
  %19 = icmp eq ptr %18, @_ZN12shared_treap5nodesE
  br i1 %19, label %.loopexit, label %.lr.ph.split

tailrecurse.outer:                                ; preds = %14
  %20 = getelementptr inbounds i8, ptr %.tr21, i64 8
  %21 = tail call noundef ptr @_ZNK12shared_treap7pointercvPNS_4nodeEEv(ptr noundef nonnull align 8 dereferenceable(8) %20)
  %22 = tail call noundef ptr @_ZN12shared_treap7pointerptEv(ptr noundef nonnull align 8 dereferenceable(8) %.tr21)
  %23 = getelementptr inbounds i8, ptr %22, i64 20
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = xor i32 %24, -1
  %26 = add i32 %.tr17.ph29, %25
  %27 = icmp slt i32 %26, 1
  %28 = icmp eq ptr %21, @_ZN12shared_treap5nodesE
  %or.cond20 = or i1 %28, %27
  br i1 %or.cond20, label %.loopexit, label %.lr.ph.split.preheader

.loopexit:                                        ; preds = %tailrecurse.outer, %.lr.ph.split, %tailrecurse, %2, %.split.us
  %.0 = phi i32 [ %.pre, %.split.us ], [ 0, %2 ], [ 0, %tailrecurse ], [ 0, %.lr.ph.split ], [ 0, %tailrecurse.outer ]
  ret i32 %.0
}

attributes #0 = { 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 #1 = { 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, !11, i64 20}
!6 = !{!"_ZTSN12shared_treap4nodeE", !7, i64 0, !7, i64 8, !11, i64 16, !11, i64 20, !11, i64 24}
!7 = !{!"_ZTSN12shared_treap7pointerE", !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!6, !11, i64 16}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass