; LLVM IR from JessonYue/LeetCodeLearning :: Array/linchuanxin/homework/homework_0714_0718/homework3 (bst)

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

@root = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local i32 @keyComp(i32 noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @treeDelete(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr @root, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  br label %8

8:                                                ; preds = %88, %1
  %9 = load ptr, ptr %4, align 8, !tbaa !9
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %89

12:                                               ; preds = %8
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !9
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.node, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = call i32 @keyComp(i32 noundef %13, i32 noundef %17)
  store i32 %18, ptr %6, align 4, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  store ptr %20, ptr %5, align 8, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %23, label %76

23:                                               ; preds = %12
  %24 = load ptr, ptr %5, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.node, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %35

28:                                               ; preds = %23
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.node, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %35

33:                                               ; preds = %28
  %34 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr null, ptr %34, align 8, !tbaa !9
  br label %74

35:                                               ; preds = %28, %23
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.node, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !13
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %45

40:                                               ; preds = %35
  %41 = load ptr, ptr %5, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.node, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %43, ptr %44, align 8, !tbaa !9
  br label %73

45:                                               ; preds = %35
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.node, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %55

50:                                               ; preds = %45
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.node, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %53, ptr %54, align 8, !tbaa !9
  br label %72

55:                                               ; preds = %45
  %56 = load ptr, ptr %5, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.node, ptr %56, i32 0, i32 2
  %58 = call ptr @treeDeleteMin(ptr noundef %57)
  %59 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %58, ptr %59, align 8, !tbaa !9
  %60 = load ptr, ptr %5, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.node, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !14
  %63 = load ptr, ptr %4, align 8, !tbaa !9
  %64 = load ptr, ptr %63, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.node, ptr %64, i32 0, i32 1
  store ptr %62, ptr %65, align 8, !tbaa !14
  %66 = load ptr, ptr %5, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.node, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !13
  %69 = load ptr, ptr %4, align 8, !tbaa !9
  %70 = load ptr, ptr %69, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.node, ptr %70, i32 0, i32 2
  store ptr %68, ptr %71, align 8, !tbaa !13
  br label %72

72:                                               ; preds = %55, %50
  br label %73

73:                                               ; preds = %72, %40
  br label %74

74:                                               ; preds = %73, %33
  %75 = load ptr, ptr %5, align 8, !tbaa !9
  call void @free(ptr noundef %75) #3
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %90

76:                                               ; preds = %12
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = icmp eq i32 %77, 2
  br i1 %78, label %79, label %83

79:                                               ; preds = %76
  %80 = load ptr, ptr %4, align 8, !tbaa !9
  %81 = load ptr, ptr %80, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct.node, ptr %81, i32 0, i32 2
  store ptr %82, ptr %4, align 8, !tbaa !9
  br label %87

83:                                               ; preds = %76
  %84 = load ptr, ptr %4, align 8, !tbaa !9
  %85 = load ptr, ptr %84, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.node, ptr %85, i32 0, i32 1
  store ptr %86, ptr %4, align 8, !tbaa !9
  br label %87

87:                                               ; preds = %83, %79
  br label %88

88:                                               ; preds = %87
  br label %8, !llvm.loop !15

89:                                               ; preds = %8
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %90

90:                                               ; preds = %89, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %91 = load i32, ptr %2, align 4
  ret i32 %91
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @treeDeleteMin(ptr noundef) #0

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"node", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@root = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local i32 @keyComp(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @treeDelete(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @root, align 8, !tbaa !5
  %.not29 = icmp eq ptr %2, null
  br i1 %.not29, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %1, %26
  %3 = phi ptr [ %28, %26 ], [ %2, %1 ]
  %.02430 = phi ptr [ %27, %26 ], [ @root, %1 ]
  %4 = load i32, ptr %3, align 8, !tbaa !9
  %5 = tail call i32 @keyComp(i32 noundef %0, i32 noundef %4)
  %6 = load ptr, ptr %.02430, align 8, !tbaa !5
  switch i32 %5, label %25 [
    i32 1, label %7
    i32 2, label %26
  ]

7:                                                ; preds = %.lr.ph
  %8 = getelementptr inbounds i8, ptr %6, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %7
  store ptr null, ptr %.02430, align 8, !tbaa !5
  br label %24

12:                                               ; preds = %7
  %13 = getelementptr inbounds i8, ptr %6, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  store ptr %9, ptr %.02430, align 8, !tbaa !5
  br label %24

17:                                               ; preds = %12
  %18 = tail call ptr @treeDeleteMin(ptr noundef nonnull %8)
  store ptr %18, ptr %.02430, align 8, !tbaa !5
  %19 = load ptr, ptr %13, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %18, i64 8
  store ptr %19, ptr %20, align 8, !tbaa !13
  %21 = load ptr, ptr %8, align 8, !tbaa !12
  %22 = load ptr, ptr %.02430, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  store ptr %21, ptr %23, align 8, !tbaa !12
  br label %24

24:                                               ; preds = %17, %16, %11
  tail call void @free(ptr noundef nonnull %6) #2
  br label %.loopexit

25:                                               ; preds = %.lr.ph
  br label %26

26:                                               ; preds = %.lr.ph, %25
  %.sink = phi i64 [ 8, %25 ], [ 16, %.lr.ph ]
  %27 = getelementptr inbounds i8, ptr %6, i64 %.sink
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %.not = icmp eq ptr %28, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !14

.loopexit:                                        ; preds = %26, %1, %24
  %.0 = phi i32 [ 1, %24 ], [ 0, %1 ], [ 0, %26 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @treeDeleteMin(ptr noundef) local_unnamed_addr #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"node", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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