; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/Treap.ll (Z3kthP4nodei)

; 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.node = type { [2 x ptr], i32, i32, i32 }

@nil = external dso_local global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3kthP4nodei(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 @nil, 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.node, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 8, !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 %64

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.node, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds [2 x ptr], ptr %22, i64 0, i64 0
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.node, ptr %24, i32 0, i32 3
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = add nsw i32 %26, 1
  %28 = icmp eq i32 %20, %27
  br i1 %28, label %29, label %33

29:                                               ; preds = %19
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.node, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !13
  store i32 %32, ptr %3, align 4
  br label %64

33:                                               ; preds = %19
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.node, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds [2 x ptr], ptr %36, i64 0, i64 0
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.node, ptr %38, i32 0, i32 3
  %40 = load i32, ptr %39, align 8, !tbaa !11
  %41 = icmp sle i32 %34, %40
  br i1 %41, label %42, label %49

42:                                               ; preds = %33
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.node, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds [2 x ptr], ptr %44, i64 0, i64 0
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = call noundef i32 @_Z3kthP4nodei(ptr noundef %46, i32 noundef %47)
  store i32 %48, ptr %3, align 4
  br label %64

49:                                               ; preds = %33
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.node, ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds [2 x ptr], ptr %51, i64 0, i64 1
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.node, ptr %55, i32 0, i32 0
  %57 = getelementptr inbounds [2 x ptr], ptr %56, i64 0, i64 0
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 3
  %60 = load i32, ptr %59, align 8, !tbaa !11
  %61 = sub nsw i32 %54, %60
  %62 = sub nsw i32 %61, 1
  %63 = call noundef i32 @_Z3kthP4nodei(ptr noundef %53, i32 noundef %62)
  store i32 %63, ptr %3, align 4
  br label %64

64:                                               ; preds = %49, %42, %29, %18
  %65 = load i32, ptr %3, align 4
  ret i32 %65
}

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 24}
!12 = !{!"_ZTS4node", !7, i64 0, !10, i64 16, !10, i64 20, !10, i64 24}
!13 = !{!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"

@nil = 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 @_Z3kthP4nodei(ptr noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @nil, 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 24
  %8 = load i32, ptr %7, align 8, !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 !5
  %12 = getelementptr inbounds i8, ptr %11, i64 24
  %13 = load i32, ptr %12, align 8, !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 20
  %18 = load i32, ptr %17, align 4, !tbaa !12
  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 !5
  %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 24}
!10 = !{!"_ZTS4node", !7, i64 0, !11, i64 16, !11, i64 20, !11, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 20}


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