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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6rotateRP4nodei(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4node8maintainEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4node3cmpEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6removeRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = call noundef i32 @_ZNK4node3cmpEi(ptr noundef nonnull align 8 dereferenceable(32) %8, i32 noundef %9)
  store i32 %10, ptr %5, align 4, !tbaa !9
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp eq i32 %11, -1
  br i1 %12, label %13, label %72

13:                                               ; preds = %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.node, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds [2 x ptr], ptr %16, i64 0, i64 0
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = load ptr, ptr @nil, align 8, !tbaa !5
  %20 = icmp eq ptr %18, %19
  br i1 %20, label %21, label %28

21:                                               ; preds = %13
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.node, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds [2 x ptr], ptr %24, i64 0, i64 1
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %26, ptr %27, align 8, !tbaa !5
  br label %71

28:                                               ; preds = %13
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.node, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [2 x ptr], ptr %31, i64 0, i64 1
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = load ptr, ptr @nil, align 8, !tbaa !5
  %35 = icmp eq ptr %33, %34
  br i1 %35, label %36, label %43

36:                                               ; preds = %28
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.node, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds [2 x ptr], ptr %39, i64 0, i64 0
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %41, ptr %42, align 8, !tbaa !5
  br label %70

43:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.node, ptr %45, i32 0, i32 0
  %47 = getelementptr inbounds [2 x ptr], ptr %46, i64 0, i64 0
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.node, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 8, !tbaa !11
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds [2 x ptr], ptr %53, i64 0, i64 1
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.node, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 8, !tbaa !11
  %58 = icmp sgt i32 %50, %57
  %59 = zext i1 %58 to i64
  %60 = select i1 %58, i32 1, i32 0
  store i32 %60, ptr %6, align 4, !tbaa !9
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = load i32, ptr %6, align 4, !tbaa !9
  call void @_Z6rotateRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %61, i32 noundef %62)
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.node, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [2 x ptr], ptr %65, i64 0, i64 %67
  %69 = load i32, ptr %4, align 4, !tbaa !9
  call void @_Z6removeRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %68, i32 noundef %69)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %70

70:                                               ; preds = %43, %36
  br label %71

71:                                               ; preds = %70, %21
  br label %80

72:                                               ; preds = %2
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = load ptr, ptr %73, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.node, ptr %74, i32 0, i32 0
  %76 = load i32, ptr %5, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [2 x ptr], ptr %75, i64 0, i64 %77
  %79 = load i32, ptr %4, align 4, !tbaa !9
  call void @_Z6removeRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %78, i32 noundef %79)
  br label %80

80:                                               ; preds = %72, %71
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = load ptr, ptr %81, align 8, !tbaa !5
  %83 = load ptr, ptr @nil, align 8, !tbaa !5
  %84 = icmp ne ptr %82, %83
  br i1 %84, label %85, label %88

85:                                               ; preds = %80
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = load ptr, ptr %86, align 8, !tbaa !5
  call void @_ZN4node8maintainEv(ptr noundef nonnull align 8 dereferenceable(32) %87)
  br label %88

88:                                               ; preds = %85, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #3 = { nounwind }

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


; 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 uwtable
declare dso_local void @_Z6rotateRP4nodei(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4node8maintainEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4node3cmpEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6removeRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = tail call noundef i32 @_ZNK4node3cmpEi(ptr noundef nonnull align 8 dereferenceable(32) %3, i32 noundef %1)
  %5 = icmp eq i32 %4, -1
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  br i1 %5, label %7, label %27

7:                                                ; preds = %2
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr @nil, align 8, !tbaa !5
  %10 = icmp eq ptr %8, %9
  %11 = getelementptr inbounds i8, ptr %6, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  br i1 %10, label %13, label %14

13:                                               ; preds = %7
  store ptr %12, ptr %0, align 8, !tbaa !5
  br label %30

14:                                               ; preds = %7
  %15 = icmp eq ptr %12, %9
  br i1 %15, label %16, label %17

16:                                               ; preds = %14
  store ptr %8, ptr %0, align 8, !tbaa !5
  br label %30

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %8, i64 16
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %12, i64 16
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = icmp sgt i32 %19, %21
  %23 = zext i1 %22 to i32
  tail call void @_Z6rotateRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %23)
  %24 = load ptr, ptr %0, align 8, !tbaa !5
  %25 = zext i1 %22 to i64
  %26 = getelementptr inbounds [2 x ptr], ptr %24, i64 0, i64 %25
  tail call void @_Z6removeRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %26, i32 noundef %1)
  br label %30

27:                                               ; preds = %2
  %28 = sext i32 %4 to i64
  %29 = getelementptr inbounds [2 x ptr], ptr %6, i64 0, i64 %28
  tail call void @_Z6removeRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %29, i32 noundef %1)
  br label %30

30:                                               ; preds = %13, %17, %16, %27
  %31 = load ptr, ptr %0, align 8, !tbaa !5
  %32 = load ptr, ptr @nil, align 8, !tbaa !5
  %.not = icmp eq ptr %31, %32
  br i1 %.not, label %34, label %33

33:                                               ; preds = %30
  tail call void @_ZN4node8maintainEv(ptr noundef nonnull align 8 dereferenceable(32) %31)
  br label %34

34:                                               ; preds = %33, %30
  ret void
}

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass