; LLVM IR from nonstriater/Learn-Algorithms :: 4 Tree/2-二叉查找树/BiSearchTree/bisearchtree.ll (delete_node)

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

; 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: nounwind uwtable
define dso_local i32 @_delete_node(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.BiSearchTree, ptr %9, i32 0, i32 2
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %20, label %13

13:                                               ; preds = %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.BiSearchTree, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = icmp ne ptr %16, null
  br i1 %17, label %20, label %18

18:                                               ; preds = %13
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %19) #3
  br label %122

20:                                               ; preds = %13, %2
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.BiSearchTree, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = icmp ne ptr %23, null
  br i1 %24, label %51, label %25

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.BiSearchTree, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  store ptr %28, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.BiSearchTree, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  %32 = getelementptr inbounds %struct.BiSearchTree, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !13
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.BiSearchTree, ptr %34, i32 0, i32 0
  store i32 %33, ptr %35, align 8, !tbaa !13
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.BiSearchTree, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !12
  %39 = getelementptr inbounds %struct.BiSearchTree, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !12
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.BiSearchTree, ptr %41, i32 0, i32 1
  store ptr %40, ptr %42, align 8, !tbaa !12
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.BiSearchTree, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !12
  %46 = getelementptr inbounds %struct.BiSearchTree, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.BiSearchTree, ptr %48, i32 0, i32 2
  store ptr %47, ptr %49, align 8, !tbaa !9
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %50) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %121

51:                                               ; preds = %20
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.BiSearchTree, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !12
  %55 = icmp ne ptr %54, null
  br i1 %55, label %82, label %56

56:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.BiSearchTree, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  store ptr %59, ptr %6, align 8, !tbaa !5
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.BiSearchTree, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.BiSearchTree, ptr %62, i32 0, i32 0
  %64 = load i32, ptr %63, align 8, !tbaa !13
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.BiSearchTree, ptr %65, i32 0, i32 0
  store i32 %64, ptr %66, align 8, !tbaa !13
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.BiSearchTree, ptr %67, i32 0, i32 2
  %69 = load ptr, ptr %68, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.BiSearchTree, ptr %69, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !12
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.BiSearchTree, ptr %72, i32 0, i32 1
  store ptr %71, ptr %73, align 8, !tbaa !12
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.BiSearchTree, ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.BiSearchTree, ptr %76, i32 0, i32 2
  %78 = load ptr, ptr %77, align 8, !tbaa !9
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.BiSearchTree, ptr %79, i32 0, i32 2
  store ptr %78, ptr %80, align 8, !tbaa !9
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %81) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %120

82:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %83, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.BiSearchTree, ptr %84, i32 0, i32 1
  %86 = load ptr, ptr %85, align 8, !tbaa !12
  store ptr %86, ptr %8, align 8, !tbaa !5
  br label %87

87:                                               ; preds = %92, %82
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.BiSearchTree, ptr %88, i32 0, i32 2
  %90 = load ptr, ptr %89, align 8, !tbaa !9
  %91 = icmp ne ptr %90, null
  br i1 %91, label %92, label %97

92:                                               ; preds = %87
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %93, ptr %7, align 8, !tbaa !5
  %94 = load ptr, ptr %8, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.BiSearchTree, ptr %94, i32 0, i32 2
  %96 = load ptr, ptr %95, align 8, !tbaa !9
  store ptr %96, ptr %8, align 8, !tbaa !5
  br label %87, !llvm.loop !14

97:                                               ; preds = %87
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.BiSearchTree, ptr %98, i32 0, i32 0
  %100 = load i32, ptr %99, align 8, !tbaa !13
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.BiSearchTree, ptr %101, i32 0, i32 0
  store i32 %100, ptr %102, align 8, !tbaa !13
  %103 = load ptr, ptr %8, align 8, !tbaa !5
  %104 = load ptr, ptr %3, align 8, !tbaa !5
  %105 = icmp ne ptr %103, %104
  br i1 %105, label %106, label %112

106:                                              ; preds = %97
  %107 = load ptr, ptr %8, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.BiSearchTree, ptr %107, i32 0, i32 1
  %109 = load ptr, ptr %108, align 8, !tbaa !12
  %110 = load ptr, ptr %7, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.BiSearchTree, ptr %110, i32 0, i32 2
  store ptr %109, ptr %111, align 8, !tbaa !9
  br label %118

112:                                              ; preds = %97
  %113 = load ptr, ptr %8, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.BiSearchTree, ptr %113, i32 0, i32 1
  %115 = load ptr, ptr %114, align 8, !tbaa !12
  %116 = load ptr, ptr %3, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.BiSearchTree, ptr %116, i32 0, i32 1
  store ptr %115, ptr %117, align 8, !tbaa !12
  br label %118

118:                                              ; preds = %112, %106
  %119 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %119) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %120

120:                                              ; preds = %118, %56
  br label %121

121:                                              ; preds = %120, %25
  br label %122

122:                                              ; preds = %121, %18
  ret i32 0
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind "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/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"BiSearchTree", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @_delete_node(ptr noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %.not39 = icmp eq ptr %6, null
  br i1 %.not, label %7, label %14

7:                                                ; preds = %2
  br i1 %.not39, label %26, label %8

8:                                                ; preds = %7
  %9 = load i32, ptr %6, align 8, !tbaa !12
  store i32 %9, ptr %0, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %6, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %11, ptr %5, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %13, ptr %3, align 8, !tbaa !5
  br label %26

14:                                               ; preds = %2
  br i1 %.not39, label %15, label %.preheader

15:                                               ; preds = %14
  %16 = load i32, ptr %4, align 8, !tbaa !12
  store i32 %16, ptr %0, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %4, i64 8
  %18 = load <2 x ptr>, ptr %17, align 8, !tbaa !13
  store <2 x ptr> %18, ptr %5, align 8, !tbaa !13
  br label %26

.preheader:                                       ; preds = %14, %.preheader
  %.035 = phi ptr [ %.0, %.preheader ], [ %0, %14 ]
  %.0 = phi ptr [ %20, %.preheader ], [ %6, %14 ]
  %19 = getelementptr inbounds i8, ptr %.0, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %.not42 = icmp eq ptr %20, null
  br i1 %.not42, label %21, label %.preheader, !llvm.loop !14

21:                                               ; preds = %.preheader
  %22 = load i32, ptr %.0, align 8, !tbaa !12
  store i32 %22, ptr %0, align 8, !tbaa !12
  %.not43 = icmp eq ptr %.0, %0
  %23 = getelementptr inbounds i8, ptr %.0, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %.035, i64 16
  %.sink = select i1 %.not43, ptr %5, ptr %25
  store ptr %24, ptr %.sink, align 8, !tbaa !13
  br label %26

26:                                               ; preds = %7, %8, %21, %15
  %.sink44 = phi ptr [ %6, %8 ], [ %.0, %21 ], [ %4, %15 ], [ %0, %7 ]
  tail call void @free(ptr noundef nonnull %.sink44) #2
  ret i32 0
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { 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 willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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, !10, i64 16}
!6 = !{!"BiSearchTree", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !7, i64 0}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass