; LLVM IR from ippeb/ACM-ICPC :: data_structure/binary_search_tree/binary_search_tree.ll (Z6removeiP4node)

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

%class.node = type { i32, ptr, ptr }

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z12get_smallestP4node(ptr noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z15unlink_smallestP4node(ptr noundef) #0

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

11:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  br label %106

12:                                               ; preds = %2
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  %15 = getelementptr inbounds %class.node, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = icmp eq i32 %13, %16
  br i1 %17, label %18, label %82

18:                                               ; preds = %12
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds %class.node, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %33

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

28:                                               ; preds = %23
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = icmp eq ptr %29, null
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  call void @_ZdlPvm(ptr noundef %29, i64 noundef 24) #3
  br label %32

32:                                               ; preds = %31, %28
  store ptr null, ptr %3, align 8
  br label %106

33:                                               ; preds = %23, %18
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = getelementptr inbounds %class.node, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %47

38:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %39 = load ptr, ptr %5, align 8, !tbaa !9
  %40 = getelementptr inbounds %class.node, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  store ptr %41, ptr %6, align 8, !tbaa !9
  %42 = load ptr, ptr %5, align 8, !tbaa !9
  %43 = icmp eq ptr %42, null
  br i1 %43, label %45, label %44

44:                                               ; preds = %38
  call void @_ZdlPvm(ptr noundef %42, i64 noundef 24) #3
  br label %45

45:                                               ; preds = %44, %38
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %46, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %106

47:                                               ; preds = %33
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  %49 = getelementptr inbounds %class.node, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = icmp eq ptr %50, null
  br i1 %51, label %52, label %61

52:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %53 = load ptr, ptr %5, align 8, !tbaa !9
  %54 = getelementptr inbounds %class.node, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !14
  store ptr %55, ptr %7, align 8, !tbaa !9
  %56 = load ptr, ptr %5, align 8, !tbaa !9
  %57 = icmp eq ptr %56, null
  br i1 %57, label %59, label %58

58:                                               ; preds = %52
  call void @_ZdlPvm(ptr noundef %56, i64 noundef 24) #3
  br label %59

59:                                               ; preds = %58, %52
  %60 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %60, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %106

61:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %62 = load ptr, ptr %5, align 8, !tbaa !9
  %63 = getelementptr inbounds %class.node, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !13
  %65 = call noundef ptr @_Z12get_smallestP4node(ptr noundef %64)
  store ptr %65, ptr %8, align 8, !tbaa !9
  %66 = load ptr, ptr %5, align 8, !tbaa !9
  %67 = getelementptr inbounds %class.node, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !13
  %69 = call noundef ptr @_Z15unlink_smallestP4node(ptr noundef %68)
  %70 = load ptr, ptr %5, align 8, !tbaa !9
  %71 = getelementptr inbounds %class.node, ptr %70, i32 0, i32 1
  store ptr %69, ptr %71, align 8, !tbaa !13
  %72 = load ptr, ptr %8, align 8, !tbaa !9
  %73 = getelementptr inbounds %class.node, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 8, !tbaa !11
  %75 = load ptr, ptr %5, align 8, !tbaa !9
  %76 = getelementptr inbounds %class.node, ptr %75, i32 0, i32 0
  store i32 %74, ptr %76, align 8, !tbaa !11
  %77 = load ptr, ptr %8, align 8, !tbaa !9
  %78 = icmp eq ptr %77, null
  br i1 %78, label %80, label %79

79:                                               ; preds = %61
  call void @_ZdlPvm(ptr noundef %77, i64 noundef 24) #3
  br label %80

80:                                               ; preds = %79, %61
  %81 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %81, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %106

82:                                               ; preds = %12
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = load ptr, ptr %5, align 8, !tbaa !9
  %85 = getelementptr inbounds %class.node, ptr %84, i32 0, i32 0
  %86 = load i32, ptr %85, align 8, !tbaa !11
  %87 = icmp slt i32 %83, %86
  br i1 %87, label %88, label %96

88:                                               ; preds = %82
  %89 = load i32, ptr %4, align 4, !tbaa !5
  %90 = load ptr, ptr %5, align 8, !tbaa !9
  %91 = getelementptr inbounds %class.node, ptr %90, i32 0, i32 2
  %92 = load ptr, ptr %91, align 8, !tbaa !14
  %93 = call noundef ptr @_Z6removeiP4node(i32 noundef %89, ptr noundef %92)
  %94 = load ptr, ptr %5, align 8, !tbaa !9
  %95 = getelementptr inbounds %class.node, ptr %94, i32 0, i32 2
  store ptr %93, ptr %95, align 8, !tbaa !14
  br label %104

96:                                               ; preds = %82
  %97 = load i32, ptr %4, align 4, !tbaa !5
  %98 = load ptr, ptr %5, align 8, !tbaa !9
  %99 = getelementptr inbounds %class.node, ptr %98, i32 0, i32 1
  %100 = load ptr, ptr %99, align 8, !tbaa !13
  %101 = call noundef ptr @_Z6removeiP4node(i32 noundef %97, ptr noundef %100)
  %102 = load ptr, ptr %5, align 8, !tbaa !9
  %103 = getelementptr inbounds %class.node, ptr %102, i32 0, i32 1
  store ptr %101, ptr %103, align 8, !tbaa !13
  br label %104

104:                                              ; preds = %96, %88
  %105 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %105, ptr %3, align 8
  br label %106

106:                                              ; preds = %104, %80, %59, %45, %32, %11
  %107 = load ptr, ptr %3, align 8
  ret ptr %107
}

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #1

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

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

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 = { nobuiltin 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { builtin nounwind }
attributes #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4node", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 16}


; 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: mustprogress uwtable
declare dso_local noundef ptr @_Z12get_smallestP4node(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z15unlink_smallestP4node(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z6removeiP4node(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %1, null
  br i1 %3, label %common.ret36, label %4

4:                                                ; preds = %2
  %5 = load i32, ptr %1, align 8, !tbaa !5
  %6 = icmp eq i32 %5, %0
  br i1 %6, label %7, label %21

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

13:                                               ; preds = %7
  tail call void @_ZdlPvm(ptr noundef nonnull %1, i64 noundef 24) #2
  br label %common.ret36

.thread:                                          ; preds = %7
  %14 = icmp eq ptr %12, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %.thread
  tail call void @_ZdlPvm(ptr noundef nonnull %1, i64 noundef 24) #2
  br label %common.ret36

16:                                               ; preds = %.thread
  %17 = tail call noundef ptr @_Z12get_smallestP4node(ptr noundef nonnull %9)
  %18 = load ptr, ptr %8, align 8, !tbaa !11
  %19 = tail call noundef ptr @_Z15unlink_smallestP4node(ptr noundef %18)
  store ptr %19, ptr %8, align 8, !tbaa !11
  %20 = load i32, ptr %17, align 8, !tbaa !5
  store i32 %20, ptr %1, align 8, !tbaa !5
  tail call void @_ZdlPvm(ptr noundef %17, i64 noundef 24) #2
  br label %common.ret36

21:                                               ; preds = %4
  %22 = icmp sgt i32 %5, %0
  br i1 %22, label %23, label %27

common.ret36:                                     ; preds = %2, %16, %15, %13, %27, %23
  %common.ret36.op = phi ptr [ %1, %23 ], [ %1, %27 ], [ %9, %15 ], [ %1, %16 ], [ null, %2 ], [ %12, %13 ]
  ret ptr %common.ret36.op

23:                                               ; preds = %21
  %24 = getelementptr inbounds i8, ptr %1, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = tail call noundef ptr @_Z6removeiP4node(i32 noundef %0, ptr noundef %25)
  store ptr %26, ptr %24, align 8, !tbaa !12
  br label %common.ret36

27:                                               ; preds = %21
  %28 = getelementptr inbounds i8, ptr %1, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = tail call noundef ptr @_Z6removeiP4node(i32 noundef %0, ptr noundef %29)
  store ptr %30, ptr %28, align 8, !tbaa !11
  br label %common.ret36
}

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #1

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass