; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/可持久化Treap.ll (ZN12shared_treap4RankEPNS_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_treap4RankEPNS_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 %8, label %9

8:                                                ; preds = %2
  store i32 1, ptr %3, align 4
  br label %34

9:                                                ; preds = %2
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.shared_treap::node", ptr %11, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp sle i32 %10, %13
  br i1 %14, label %15, label %21

15:                                               ; preds = %9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %"struct.shared_treap::node", ptr %16, i32 0, i32 0
  %18 = call noundef ptr @_ZNK12shared_treap7pointercvPNS_4nodeEEv(ptr noundef nonnull align 8 dereferenceable(8) %17)
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = call noundef i32 @_ZN12shared_treap4RankEPNS_4nodeEi(ptr noundef %18, i32 noundef %19)
  store i32 %20, ptr %3, align 4
  br label %34

21:                                               ; preds = %9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.shared_treap::node", ptr %22, i32 0, i32 1
  %24 = call noundef ptr @_ZNK12shared_treap7pointercvPNS_4nodeEEv(ptr noundef nonnull align 8 dereferenceable(8) %23)
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = call noundef i32 @_ZN12shared_treap4RankEPNS_4nodeEi(ptr noundef %24, i32 noundef %25)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.shared_treap::node", ptr %27, i32 0, i32 0
  %29 = call noundef ptr @_ZN12shared_treap7pointerptEv(ptr noundef nonnull align 8 dereferenceable(8) %28)
  %30 = getelementptr inbounds %"struct.shared_treap::node", ptr %29, i32 0, i32 3
  %31 = load i32, ptr %30, align 4, !tbaa !14
  %32 = add nsw i32 %26, %31
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %3, align 4
  br label %34

34:                                               ; preds = %21, %15, %8
  %35 = load i32, ptr %3, align 4
  ret i32 %35
}

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 16}
!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 20}


; 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_treap4RankEPNS_4nodeEi(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, @_ZN12shared_treap5nodesE
  br i1 %3, label %common.ret18, label %.lr.ph

.lr.ph:                                           ; preds = %2, %tailrecurse
  %.tr12 = phi ptr [ %6, %tailrecurse ], [ %0, %2 ]
  %4 = getelementptr inbounds i8, ptr %.tr12, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp slt i32 %5, %1
  br i1 %.not, label %8, label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph
  %6 = tail call noundef ptr @_ZNK12shared_treap7pointercvPNS_4nodeEEv(ptr noundef nonnull align 8 dereferenceable(8) %.tr12)
  %7 = icmp eq ptr %6, @_ZN12shared_treap5nodesE
  br i1 %7, label %common.ret18, label %.lr.ph

common.ret18:                                     ; preds = %2, %tailrecurse, %8
  %common.ret18.op = phi i32 [ %16, %8 ], [ 1, %tailrecurse ], [ 1, %2 ]
  ret i32 %common.ret18.op

8:                                                ; preds = %.lr.ph
  %9 = getelementptr inbounds i8, ptr %.tr12, i64 8
  %10 = tail call noundef ptr @_ZNK12shared_treap7pointercvPNS_4nodeEEv(ptr noundef nonnull align 8 dereferenceable(8) %9)
  %11 = tail call noundef i32 @_ZN12shared_treap4RankEPNS_4nodeEi(ptr noundef %10, i32 noundef %1)
  %12 = tail call noundef ptr @_ZN12shared_treap7pointerptEv(ptr noundef nonnull align 8 dereferenceable(8) %.tr12)
  %13 = getelementptr inbounds i8, ptr %12, i64 20
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %15 = add i32 %11, 1
  %16 = add i32 %15, %14
  br label %common.ret18
}

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 16}
!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 20}


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