; LLVM IR from SOHNE/Dura2D :: src/collision/d2AABBTree.ll (ZN10d2AABBTree10RemoveNodeEP6d2Node)

; 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.d2Node = type { ptr, [2 x ptr], i8, %struct.d2AABB, ptr }
%struct.d2AABB = type { %struct.d2Vec2, %struct.d2Vec2, ptr, ptr }
%struct.d2Vec2 = type { float, float }
%class.d2AABBTree = type { %class.d2Broadphase, ptr, %"class.std::__cxx11::list", float, %"class.std::vector" }
%class.d2Broadphase = type { ptr }
%"class.std::__cxx11::list" = type { %"class.std::__cxx11::_List_base" }
%"class.std::__cxx11::_List_base" = type { %"struct.std::__cxx11::_List_base<std::pair<d2Body *, d2Body *>, std::allocator<std::pair<d2Body *, d2Body *>>>::_List_impl" }
%"struct.std::__cxx11::_List_base<std::pair<d2Body *, d2Body *>, std::allocator<std::pair<d2Body *, d2Body *>>>::_List_impl" = type { %"struct.std::__detail::_List_node_header" }
%"struct.std::__detail::_List_node_header" = type { %"struct.std::__detail::_List_node_base", i64 }
%"struct.std::__detail::_List_node_base" = type { ptr, ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<d2Node *, std::allocator<d2Node *>>::_Vector_impl" }
%"struct.std::_Vector_base<d2Node *, std::allocator<d2Node *>>::_Vector_impl" = type { %"struct.std::_Vector_base<d2Node *, std::allocator<d2Node *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<d2Node *, std::allocator<d2Node *>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 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: mustprogress uwtable
define dso_local void @_ZN10d2AABBTree10RemoveNodeEP6d2Node(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef %1) #2 align 2 {
  %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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.d2Node, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %11, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %66

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call noundef ptr @_ZNK6d2Node10GetSiblingEv(ptr noundef nonnull align 8 dereferenceable(72) %15)
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.d2Node, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %50

21:                                               ; preds = %14
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.d2Node, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.d2Node, ptr %25, i32 0, i32 0
  store ptr %24, ptr %26, align 8, !tbaa !9
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.d2Node, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.d2Node, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds [2 x ptr], ptr %32, i64 0, i64 0
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = icmp eq ptr %28, %34
  br i1 %35, label %36, label %42

36:                                               ; preds = %21
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.d2Node, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.d2Node, ptr %39, i32 0, i32 1
  %41 = getelementptr inbounds [2 x ptr], ptr %40, i64 0, i64 0
  br label %48

42:                                               ; preds = %21
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.d2Node, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.d2Node, ptr %45, i32 0, i32 1
  %47 = getelementptr inbounds [2 x ptr], ptr %46, i64 0, i64 1
  br label %48

48:                                               ; preds = %42, %36
  %49 = phi ptr [ %41, %36 ], [ %47, %42 ]
  store ptr %27, ptr %49, align 8, !tbaa !5
  br label %57

50:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = call noundef ptr @_ZNK6d2Node10GetSiblingEv(ptr noundef nonnull align 8 dereferenceable(72) %51)
  store ptr %52, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %class.d2AABBTree, ptr %8, i32 0, i32 1
  store ptr %53, ptr %54, align 8, !tbaa !15
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.d2Node, ptr %55, i32 0, i32 0
  store ptr null, ptr %56, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %57

57:                                               ; preds = %50, %48
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = icmp eq ptr %58, null
  br i1 %59, label %61, label %60

60:                                               ; preds = %57
  call void @_ZdlPvm(ptr noundef %58, i64 noundef 72) #5
  br label %61

61:                                               ; preds = %60, %57
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = icmp eq ptr %62, null
  br i1 %63, label %65, label %64

64:                                               ; preds = %61
  call void @_ZdlPvm(ptr noundef %62, i64 noundef 72) #5
  br label %65

65:                                               ; preds = %64, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %72

66:                                               ; preds = %2
  %67 = getelementptr inbounds %class.d2AABBTree, ptr %8, i32 0, i32 1
  store ptr null, ptr %67, align 8, !tbaa !15
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = icmp eq ptr %68, null
  br i1 %69, label %71, label %70

70:                                               ; preds = %66
  call void @_ZdlPvm(ptr noundef %68, i64 noundef 72) #5
  br label %71

71:                                               ; preds = %70, %66
  br label %72

72:                                               ; preds = %71, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK6d2Node10GetSiblingEv(ptr noundef nonnull align 8 dereferenceable(72)) #3 align 2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { inlinehint 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 #4 = { nounwind }
attributes #5 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS6d2Node", !6, i64 0, !7, i64 8, !11, i64 24, !12, i64 32, !6, i64 64}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"_ZTS6d2AABB", !13, i64 0, !13, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!"_ZTS6d2Vec2", !14, i64 0, !14, i64 4}
!14 = !{!"float", !7, i64 0}
!15 = !{!16, !6, i64 8}
!16 = !{!"_ZTS10d2AABBTree", !17, i64 0, !6, i64 8, !18, i64 16, !14, i64 40, !24, i64 48}
!17 = !{!"_ZTS12d2Broadphase"}
!18 = !{!"_ZTSNSt7__cxx114listISt4pairIP6d2BodyS3_ESaIS4_EEE", !19, i64 0}
!19 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairIP6d2BodyS3_ESaIS4_EEE", !20, i64 0}
!20 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairIP6d2BodyS3_ESaIS4_EE10_List_implE", !21, i64 0}
!21 = !{!"_ZTSNSt8__detail17_List_node_headerE", !22, i64 0, !23, i64 16}
!22 = !{!"_ZTSNSt8__detail15_List_node_baseE", !6, i64 0, !6, i64 8}
!23 = !{!"long", !7, i64 0}
!24 = !{!"_ZTSSt6vectorIP6d2NodeSaIS1_EE", !25, i64 0}
!25 = !{!"_ZTSSt12_Vector_baseIP6d2NodeSaIS1_EE", !26, i64 0}
!26 = !{!"_ZTSNSt12_Vector_baseIP6d2NodeSaIS1_EE12_Vector_implE", !27, i64 0}
!27 = !{!"_ZTSNSt12_Vector_baseIP6d2NodeSaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, 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: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN10d2AABBTree10RemoveNodeEP6d2Node(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(72) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %18, label %4

4:                                                ; preds = %2
  %5 = tail call noundef ptr @_ZNK6d2Node10GetSiblingEv(ptr noundef nonnull align 8 dereferenceable(72) %1)
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %.not19 = icmp eq ptr %6, null
  br i1 %.not19, label %14, label %7

7:                                                ; preds = %4
  store ptr %6, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = icmp eq ptr %3, %10
  %12 = getelementptr inbounds i8, ptr %8, i64 16
  %13 = select i1 %11, ptr %9, ptr %12
  store ptr %5, ptr %13, align 8, !tbaa !14
  br label %17

14:                                               ; preds = %4
  %15 = tail call noundef ptr @_ZNK6d2Node10GetSiblingEv(ptr noundef nonnull align 8 dereferenceable(72) %1)
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %15, ptr %16, align 8, !tbaa !15
  store ptr null, ptr %15, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %7, %14
  tail call void @_ZdlPvm(ptr noundef nonnull %1, i64 noundef 72) #3
  br label %20

18:                                               ; preds = %2
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %19, align 8, !tbaa !15
  br label %20

20:                                               ; preds = %18, %17
  %.sink = phi ptr [ %1, %18 ], [ %3, %17 ]
  tail call void @_ZdlPvm(ptr noundef nonnull %.sink, i64 noundef 72) #3
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK6d2Node10GetSiblingEv(ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #2 align 2

attributes #0 = { 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 #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" }
attributes #2 = { inlinehint 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 = { 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 = !{!"_ZTS6d2Node", !7, i64 0, !8, i64 8, !10, i64 24, !11, i64 32, !7, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"_ZTS6d2AABB", !12, i64 0, !12, i64 8, !7, i64 16, !7, i64 24}
!12 = !{!"_ZTS6d2Vec2", !13, i64 0, !13, i64 4}
!13 = !{!"float", !8, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !7, i64 8}
!16 = !{!"_ZTS10d2AABBTree", !17, i64 0, !7, i64 8, !18, i64 16, !13, i64 40, !24, i64 48}
!17 = !{!"_ZTS12d2Broadphase"}
!18 = !{!"_ZTSNSt7__cxx114listISt4pairIP6d2BodyS3_ESaIS4_EEE", !19, i64 0}
!19 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairIP6d2BodyS3_ESaIS4_EEE", !20, i64 0}
!20 = !{!"_ZTSNSt7__cxx1110_List_baseISt4pairIP6d2BodyS3_ESaIS4_EE10_List_implE", !21, i64 0}
!21 = !{!"_ZTSNSt8__detail17_List_node_headerE", !22, i64 0, !23, i64 16}
!22 = !{!"_ZTSNSt8__detail15_List_node_baseE", !7, i64 0, !7, i64 8}
!23 = !{!"long", !8, i64 0}
!24 = !{!"_ZTSSt6vectorIP6d2NodeSaIS1_EE", !25, i64 0}
!25 = !{!"_ZTSSt12_Vector_baseIP6d2NodeSaIS1_EE", !26, i64 0}
!26 = !{!"_ZTSNSt12_Vector_baseIP6d2NodeSaIS1_EE12_Vector_implE", !27, i64 0}
!27 = !{!"_ZTSNSt12_Vector_baseIP6d2NodeSaIS1_EE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}


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