; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/可持久化Treap.ll (ZN5treap3kthEPNS_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.treap::node" = type { ptr, ptr, i32, i32 }

@_ZN5treap3nilE = external dso_local global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5treap3kthEPNS_4nodeEi(ptr noundef %0, i32 noundef %1) #0 {
  %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 = load ptr, ptr @_ZN5treap3nilE, align 8, !tbaa !5
  %8 = icmp eq ptr %6, %7
  br i1 %8, label %18, label %9

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

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

18:                                               ; preds = %12, %9, %2
  store i32 0, ptr %3, align 4
  br label %59

19:                                               ; preds = %12
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.treap::node", ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = getelementptr inbounds %"struct.treap::node", ptr %23, i32 0, i32 3
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = add nsw i32 %25, 1
  %27 = icmp eq i32 %20, %26
  br i1 %27, label %28, label %32

28:                                               ; preds = %19
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.treap::node", ptr %29, i32 0, i32 2
  %31 = load i32, ptr %30, align 8, !tbaa !14
  store i32 %31, ptr %3, align 4
  br label %59

32:                                               ; preds = %19
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.treap::node", ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = getelementptr inbounds %"struct.treap::node", ptr %36, i32 0, i32 3
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %39 = icmp sle i32 %33, %38
  br i1 %39, label %40, label %46

40:                                               ; preds = %32
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.treap::node", ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !13
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = call noundef i32 @_ZN5treap3kthEPNS_4nodeEi(ptr noundef %43, i32 noundef %44)
  store i32 %45, ptr %3, align 4
  br label %59

46:                                               ; preds = %32
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.treap::node", ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %"struct.treap::node", ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = getelementptr inbounds %"struct.treap::node", ptr %53, i32 0, i32 3
  %55 = load i32, ptr %54, align 4, !tbaa !11
  %56 = sub nsw i32 %50, %55
  %57 = sub nsw i32 %56, 1
  %58 = call noundef i32 @_ZN5treap3kthEPNS_4nodeEi(ptr noundef %49, i32 noundef %57)
  store i32 %58, ptr %3, align 4
  br label %59

59:                                               ; preds = %46, %40, %28, %18
  %60 = load i32, ptr %3, align 4
  ret i32 %60
}

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 = !{!"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 = !{!"_ZTSN5treap4nodeE", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !10, i64 16}
!15 = !{!12, !6, i64 8}


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

@_ZN5treap3nilE = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_ZN5treap3kthEPNS_4nodeEi(ptr noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @_ZN5treap3nilE, align 8, !tbaa !5
  %4 = icmp slt i32 %1, 1
  br i1 %4, label %.loopexit.split, label %tailrecurse.preheader

tailrecurse.preheader:                            ; preds = %2, %tailrecurse.outer
  %.tr18.ph.fr35 = phi i32 [ %23, %tailrecurse.outer ], [ %1, %2 ]
  %.tr.ph34 = phi ptr [ %21, %tailrecurse.outer ], [ %0, %2 ]
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.preheader, %19
  %.tr = phi ptr [ %11, %19 ], [ %.tr.ph34, %tailrecurse.preheader ]
  %5 = icmp eq ptr %3, %.tr
  br i1 %5, label %.loopexit.split, label %6

6:                                                ; preds = %tailrecurse
  %7 = getelementptr inbounds i8, ptr %.tr, i64 20
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp slt i32 %8, %.tr18.ph.fr35
  br i1 %9, label %.loopexit.split, label %10

10:                                               ; preds = %6
  %11 = load ptr, ptr %.tr, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %11, i64 20
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %.fr36 = freeze i32 %13
  %14 = add nsw i32 %.fr36, 1
  %15 = icmp eq i32 %14, %.tr18.ph.fr35
  br i1 %15, label %16, label %19

16:                                               ; preds = %10
  %17 = getelementptr inbounds i8, ptr %.tr, i64 16
  %18 = load i32, ptr %17, align 8, !tbaa !13
  br label %.loopexit.split

19:                                               ; preds = %10
  %.not = icmp slt i32 %.fr36, %.tr18.ph.fr35
  br i1 %.not, label %tailrecurse.outer, label %tailrecurse

tailrecurse.outer:                                ; preds = %19
  %20 = getelementptr inbounds i8, ptr %.tr, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = xor i32 %.fr36, -1
  %23 = add i32 %.tr18.ph.fr35, %22
  %24 = icmp slt i32 %23, 1
  br i1 %24, label %.loopexit.split, label %tailrecurse.preheader

.loopexit.split:                                  ; preds = %tailrecurse.outer, %6, %tailrecurse, %2, %16
  %.0 = phi i32 [ %18, %16 ], [ 0, %2 ], [ 0, %tailrecurse ], [ 0, %6 ], [ 0, %tailrecurse.outer ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 20}
!10 = !{!"_ZTSN5treap4nodeE", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !11, i64 16}
!14 = !{!10, !6, i64 8}


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