; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x46-二叉查找树与平衡树初步/253. 普通平衡树.ll (Z6RemoveRii)

; 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 = type { i32, i32, i32, i32, i32, i32 }

@a = external dso_local global [100010 x %struct.Treap], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6Updatei(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3zigRi(ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3zagRi(ptr noundef nonnull align 4 dereferenceable(4)) #0

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

8:                                                ; preds = %2
  br label %130

9:                                                ; preds = %2
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.Treap, ptr %14, i32 0, i32 2
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = icmp eq i32 %10, %16
  br i1 %17, label %18, label %104

18:                                               ; preds = %9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.Treap, ptr %22, i32 0, i32 4
  %24 = load i32, ptr %23, align 8, !tbaa !13
  %25 = icmp sgt i32 %24, 1
  br i1 %25, label %26, label %36

26:                                               ; preds = %18
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.Treap, ptr %30, i32 0, i32 4
  %32 = load i32, ptr %31, align 8, !tbaa !13
  %33 = add nsw i32 %32, -1
  store i32 %33, ptr %31, align 8, !tbaa !13
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i32, ptr %34, align 4, !tbaa !9
  call void @_Z6Updatei(i32 noundef %35)
  br label %130

36:                                               ; preds = %18
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.Treap, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !14
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %52, label %44

44:                                               ; preds = %36
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.Treap, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !15
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %101

52:                                               ; preds = %44, %36
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.Treap, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 4, !tbaa !15
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %82, label %60

60:                                               ; preds = %52
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.Treap, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 8, !tbaa !14
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %67
  %69 = getelementptr inbounds %struct.Treap, ptr %68, i32 0, i32 3
  %70 = load i32, ptr %69, align 4, !tbaa !16
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = load i32, ptr %71, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %73
  %75 = getelementptr inbounds %struct.Treap, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 4, !tbaa !15
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %77
  %79 = getelementptr inbounds %struct.Treap, ptr %78, i32 0, i32 3
  %80 = load i32, ptr %79, align 4, !tbaa !16
  %81 = icmp sgt i32 %70, %80
  br i1 %81, label %82, label %90

82:                                               ; preds = %60, %52
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_Z3zigRi(ptr noundef nonnull align 4 dereferenceable(4) %83)
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = load i32, ptr %84, align 4, !tbaa !9
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %86
  %88 = getelementptr inbounds %struct.Treap, ptr %87, i32 0, i32 1
  %89 = load i32, ptr %4, align 4, !tbaa !9
  call void @_Z6RemoveRii(ptr noundef nonnull align 4 dereferenceable(4) %88, i32 noundef %89)
  br label %98

90:                                               ; preds = %60
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_Z3zagRi(ptr noundef nonnull align 4 dereferenceable(4) %91)
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = load i32, ptr %92, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %94
  %96 = getelementptr inbounds %struct.Treap, ptr %95, i32 0, i32 0
  %97 = load i32, ptr %4, align 4, !tbaa !9
  call void @_Z6RemoveRii(ptr noundef nonnull align 4 dereferenceable(4) %96, i32 noundef %97)
  br label %98

98:                                               ; preds = %90, %82
  %99 = load ptr, ptr %3, align 8, !tbaa !5
  %100 = load i32, ptr %99, align 4, !tbaa !9
  call void @_Z6Updatei(i32 noundef %100)
  br label %103

101:                                              ; preds = %44
  %102 = load ptr, ptr %3, align 8, !tbaa !5
  store i32 0, ptr %102, align 4, !tbaa !9
  br label %103

103:                                              ; preds = %101, %98
  br label %130

104:                                              ; preds = %9
  %105 = load i32, ptr %4, align 4, !tbaa !9
  %106 = load ptr, ptr %3, align 8, !tbaa !5
  %107 = load i32, ptr %106, align 4, !tbaa !9
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %108
  %110 = getelementptr inbounds %struct.Treap, ptr %109, i32 0, i32 2
  %111 = load i32, ptr %110, align 8, !tbaa !11
  %112 = icmp slt i32 %105, %111
  br i1 %112, label %113, label %120

113:                                              ; preds = %104
  %114 = load ptr, ptr %3, align 8, !tbaa !5
  %115 = load i32, ptr %114, align 4, !tbaa !9
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %116
  %118 = getelementptr inbounds %struct.Treap, ptr %117, i32 0, i32 0
  %119 = load i32, ptr %4, align 4, !tbaa !9
  call void @_Z6RemoveRii(ptr noundef nonnull align 4 dereferenceable(4) %118, i32 noundef %119)
  br label %127

120:                                              ; preds = %104
  %121 = load ptr, ptr %3, align 8, !tbaa !5
  %122 = load i32, ptr %121, align 4, !tbaa !9
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %123
  %125 = getelementptr inbounds %struct.Treap, ptr %124, i32 0, i32 1
  %126 = load i32, ptr %4, align 4, !tbaa !9
  call void @_Z6RemoveRii(ptr noundef nonnull align 4 dereferenceable(4) %125, i32 noundef %126)
  br label %127

127:                                              ; preds = %120, %113
  %128 = load ptr, ptr %3, align 8, !tbaa !5
  %129 = load i32, ptr %128, align 4, !tbaa !9
  call void @_Z6Updatei(i32 noundef %129)
  br label %130

130:                                              ; preds = %127, %103, %26, %8
  ret void
}

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


; 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.Treap = type { i32, i32, i32, i32, i32, i32 }

@a = external dso_local global [100010 x %struct.Treap], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6Updatei(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3zigRi(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3zagRi(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6RemoveRii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %0, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %common.ret, label %5

5:                                                ; preds = %2
  %6 = sext i32 %3 to i64
  %7 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %6
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = icmp eq i32 %9, %1
  br i1 %10, label %11, label %42

11:                                               ; preds = %5
  %12 = getelementptr inbounds i8, ptr %7, i64 16
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp sgt i32 %13, 1
  br i1 %14, label %15, label %18

15:                                               ; preds = %11
  %16 = add nsw i32 %13, -1
  store i32 %16, ptr %12, align 8, !tbaa !11
  %17 = load i32, ptr %0, align 4, !tbaa !5
  tail call void @_Z6Updatei(i32 noundef %17)
  br label %common.ret

18:                                               ; preds = %11
  %19 = load i32, ptr %7, align 8, !tbaa !12
  %.not = icmp eq i32 %19, 0
  %20 = getelementptr inbounds i8, ptr %7, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !13
  %.not29 = icmp eq i32 %21, 0
  br i1 %.not, label %22, label %23

22:                                               ; preds = %18
  br i1 %.not29, label %41, label %.thread

23:                                               ; preds = %18
  br i1 %.not29, label %31, label %.thread

.thread:                                          ; preds = %22, %23
  %24 = sext i32 %19 to i64
  %25 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %24, i32 3
  %26 = load i32, ptr %25, align 4, !tbaa !14
  %27 = sext i32 %21 to i64
  %28 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %27, i32 3
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = icmp sgt i32 %26, %29
  br i1 %30, label %31, label %35

31:                                               ; preds = %.thread, %23
  tail call void @_Z3zigRi(ptr noundef nonnull align 4 dereferenceable(4) %0)
  %32 = load i32, ptr %0, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %33, i32 1
  br label %39

35:                                               ; preds = %.thread
  tail call void @_Z3zagRi(ptr noundef nonnull align 4 dereferenceable(4) %0)
  %36 = load i32, ptr %0, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100010 x %struct.Treap], ptr @a, i64 0, i64 %37
  br label %39

common.ret:                                       ; preds = %15, %2, %41, %42, %39
  ret void

39:                                               ; preds = %35, %31
  %.sink = phi ptr [ %38, %35 ], [ %34, %31 ]
  tail call void @_Z6RemoveRii(ptr noundef nonnull align 4 dereferenceable(4) %.sink, i32 noundef %1)
  %40 = load i32, ptr %0, align 4, !tbaa !5
  tail call void @_Z6Updatei(i32 noundef %40)
  br label %common.ret

41:                                               ; preds = %22
  store i32 0, ptr %0, align 4, !tbaa !5
  br label %common.ret

42:                                               ; preds = %5
  %43 = icmp sgt i32 %9, %1
  %.sink30.idx = select i1 %43, i64 0, i64 4
  %.sink30 = getelementptr inbounds i8, ptr %7, i64 %.sink30.idx
  tail call void @_Z6RemoveRii(ptr noundef nonnull align 4 dereferenceable(4) %.sink30, i32 noundef %1)
  %44 = load i32, ptr %0, align 4, !tbaa !5
  tail call void @_Z6Updatei(i32 noundef %44)
  br label %common.ret
}

attributes #0 = { 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS5Treap", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20}
!11 = !{!10, !6, i64 16}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !6, i64 4}
!14 = !{!10, !6, i64 12}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass