; LLVM IR from BehaviorTree/BehaviorTree.CPP :: src/controls/sequence_with_memory_node.ll (ZN2BT18SequenceWithMemory4tickEv)

; 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.BT::ControlNode" = type { %"class.BT::TreeNode", %"class.std::vector" }
%"class.BT::TreeNode" = type { ptr, %"class.std::unique_ptr" }
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Head_base.1" }
%"struct.std::_Head_base.1" = type { ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<BT::TreeNode *, std::allocator<BT::TreeNode *>>::_Vector_impl" }
%"struct.std::_Vector_base<BT::TreeNode *, std::allocator<BT::TreeNode *>>::_Vector_impl" = type { %"struct.std::_Vector_base<BT::TreeNode *, std::allocator<BT::TreeNode *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<BT::TreeNode *, std::allocator<BT::TreeNode *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.BT::SequenceWithMemory" = type { %"class.BT::ControlNode", i64, i64 }

@.str.12 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [37 x i8], align 1
@_ZTIN2BT10LogicErrorE = external dso_local constant { ptr, ptr, ptr }, align 8

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

declare i32 @__gxx_personality_v0(...)

; 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
define dso_local noundef i32 @_ZN2BT18SequenceWithMemory4tickEv(ptr noundef nonnull align 8 dereferenceable(56) %0) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %13 = getelementptr inbounds %"class.BT::ControlNode", ptr %12, i32 0, i32 1
  %14 = call noundef i64 @_ZNKSt6vectorIPN2BT8TreeNodeESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %13) #5
  store i64 %14, ptr %4, align 8, !tbaa !9
  %15 = call noundef i32 @_ZNK2BT8TreeNode6statusEv(ptr noundef nonnull align 8 dereferenceable(16) %12)
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %1
  %18 = getelementptr inbounds %"class.BT::SequenceWithMemory", ptr %12, i32 0, i32 2
  store i64 0, ptr %18, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %17, %1
  call void @_ZN2BT8TreeNode9setStatusENS_10NodeStatusE(ptr noundef nonnull align 8 dereferenceable(16) %12, i32 noundef 1)
  br label %20

20:                                               ; preds = %90, %19
  %21 = getelementptr inbounds %"class.BT::SequenceWithMemory", ptr %12, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !25
  %23 = load i64, ptr %4, align 8, !tbaa !9
  %24 = icmp ult i64 %22, %23
  br i1 %24, label %25, label %91

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %26 = getelementptr inbounds %"class.BT::ControlNode", ptr %12, i32 0, i32 1
  %27 = getelementptr inbounds %"class.BT::SequenceWithMemory", ptr %12, i32 0, i32 1
  %28 = load i64, ptr %27, align 8, !tbaa !25
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN2BT8TreeNodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %26, i64 noundef %28) #5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  store ptr %30, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = call noundef i32 @_ZNK2BT8TreeNode6statusEv(ptr noundef nonnull align 8 dereferenceable(16) %31)
  store i32 %32, ptr %6, align 4, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %33, align 8, !tbaa !28
  %35 = getelementptr inbounds ptr, ptr %34, i64 2
  %36 = load ptr, ptr %35, align 8
  %37 = call noundef i32 %36(ptr noundef nonnull align 8 dereferenceable(16) %33)
  store i32 %37, ptr %7, align 4, !tbaa !26
  %38 = load i32, ptr %7, align 4, !tbaa !26
  switch i32 %38, label %87 [
    i32 1, label %39
    i32 3, label %41
    i32 2, label %56
    i32 4, label %71
    i32 0, label %78
  ]

39:                                               ; preds = %25
  %40 = load i32, ptr %7, align 4, !tbaa !26
  store i32 %40, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %88

41:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %42 = getelementptr inbounds %"class.BT::SequenceWithMemory", ptr %12, i32 0, i32 1
  %43 = load i64, ptr %42, align 8, !tbaa !25
  store i64 %43, ptr %9, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %51, %41
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = call noundef i64 @_ZNK2BT11ControlNode13childrenCountEv(ptr noundef nonnull align 8 dereferenceable(40) %12)
  %47 = icmp ult i64 %45, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %54

49:                                               ; preds = %44
  %50 = load i64, ptr %9, align 8, !tbaa !9
  call void @_ZN2BT11ControlNode9haltChildEm(ptr noundef nonnull align 8 dereferenceable(40) %12, i64 noundef %50)
  br label %51

51:                                               ; preds = %49
  %52 = load i64, ptr %9, align 8, !tbaa !9
  %53 = add i64 %52, 1
  store i64 %53, ptr %9, align 8, !tbaa !9
  br label %44, !llvm.loop !30

54:                                               ; preds = %48
  %55 = load i32, ptr %7, align 4, !tbaa !26
  store i32 %55, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %88

56:                                               ; preds = %25
  %57 = getelementptr inbounds %"class.BT::SequenceWithMemory", ptr %12, i32 0, i32 1
  %58 = load i64, ptr %57, align 8, !tbaa !25
  %59 = add i64 %58, 1
  store i64 %59, ptr %57, align 8, !tbaa !25
  %60 = call noundef zeroext i1 @_ZNK2BT8TreeNode14requiresWakeUpEv(ptr noundef nonnull align 8 dereferenceable(16) %12)
  br i1 %60, label %61, label %70

61:                                               ; preds = %56
  %62 = load i32, ptr %6, align 4, !tbaa !26
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %70

64:                                               ; preds = %61
  %65 = getelementptr inbounds %"class.BT::SequenceWithMemory", ptr %12, i32 0, i32 1
  %66 = load i64, ptr %65, align 8, !tbaa !25
  %67 = load i64, ptr %4, align 8, !tbaa !9
  %68 = icmp ult i64 %66, %67
  br i1 %68, label %69, label %70

69:                                               ; preds = %64
  call void @_ZN2BT8TreeNode16emitWakeUpSignalEv(ptr noundef nonnull align 8 dereferenceable(16) %12)
  store i32 1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %88

70:                                               ; preds = %64, %61, %56
  br label %87

71:                                               ; preds = %25
  %72 = getelementptr inbounds %"class.BT::SequenceWithMemory", ptr %12, i32 0, i32 1
  %73 = load i64, ptr %72, align 8, !tbaa !25
  %74 = add i64 %73, 1
  store i64 %74, ptr %72, align 8, !tbaa !25
  %75 = getelementptr inbounds %"class.BT::SequenceWithMemory", ptr %12, i32 0, i32 2
  %76 = load i64, ptr %75, align 8, !tbaa !11
  %77 = add i64 %76, 1
  store i64 %77, ptr %75, align 8, !tbaa !11
  br label %87

78:                                               ; preds = %25
  %79 = call ptr @__cxa_allocate_exception(i64 40) #5
  %80 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZNK2BT8TreeNode4nameB5cxx11Ev(ptr noundef nonnull align 8 dereferenceable(16) %12)
          to label %81 unwind label %83

81:                                               ; preds = %78
  invoke void @_ZN2BT10LogicErrorC2IJA2_cNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEA37_cEEEDpRKT_(ptr noundef nonnull align 8 dereferenceable(40) %79, ptr noundef nonnull align 1 dereferenceable(2) @.str.12, ptr noundef nonnull align 8 dereferenceable(32) %80, ptr noundef nonnull align 1 dereferenceable(37) @.str.13)
          to label %82 unwind label %83

82:                                               ; preds = %81
  call void @__cxa_throw(ptr %79, ptr @_ZTIN2BT10LogicErrorE, ptr @_ZN2BT21BehaviorTreeExceptionD2Ev) #6
  unreachable

83:                                               ; preds = %81, %78
  %84 = landingpad { ptr, i32 }
          cleanup
  %85 = extractvalue { ptr, i32 } %84, 0
  store ptr %85, ptr %10, align 8
  %86 = extractvalue { ptr, i32 } %84, 1
  store i32 %86, ptr %11, align 4
  call void @__cxa_free_exception(ptr %79) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %107

87:                                               ; preds = %71, %70, %25
  store i32 0, ptr %8, align 4
  br label %88

88:                                               ; preds = %87, %69, %54, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  %89 = load i32, ptr %8, align 4
  switch i32 %89, label %105 [
    i32 0, label %90
  ]

90:                                               ; preds = %88
  br label %20, !llvm.loop !32

91:                                               ; preds = %20
  %92 = getelementptr inbounds %"class.BT::SequenceWithMemory", ptr %12, i32 0, i32 1
  %93 = load i64, ptr %92, align 8, !tbaa !25
  %94 = load i64, ptr %4, align 8, !tbaa !9
  %95 = icmp eq i64 %93, %94
  br i1 %95, label %96, label %98

96:                                               ; preds = %91
  call void @_ZN2BT11ControlNode13resetChildrenEv(ptr noundef nonnull align 8 dereferenceable(40) %12)
  %97 = getelementptr inbounds %"class.BT::SequenceWithMemory", ptr %12, i32 0, i32 1
  store i64 0, ptr %97, align 8, !tbaa !25
  br label %98

98:                                               ; preds = %96, %91
  %99 = getelementptr inbounds %"class.BT::SequenceWithMemory", ptr %12, i32 0, i32 2
  %100 = load i64, ptr %99, align 8, !tbaa !11
  %101 = load i64, ptr %4, align 8, !tbaa !9
  %102 = icmp eq i64 %100, %101
  %103 = zext i1 %102 to i64
  %104 = select i1 %102, i32 4, i32 2
  store i32 %104, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %105

105:                                              ; preds = %98, %88
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %106 = load i32, ptr %2, align 4
  ret i32 %106

107:                                              ; preds = %83
  %108 = load ptr, ptr %10, align 8
  %109 = load i32, ptr %11, align 4
  %110 = insertvalue { ptr, i32 } poison, ptr %108, 0
  %111 = insertvalue { ptr, i32 } %110, i32 %109, 1
  resume { ptr, i32 } %111
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIPN2BT8TreeNodeESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

declare noundef i32 @_ZNK2BT8TreeNode6statusEv(ptr noundef nonnull align 8 dereferenceable(16)) #3

declare void @_ZN2BT8TreeNode9setStatusENS_10NodeStatusE(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN2BT8TreeNodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

declare noundef i64 @_ZNK2BT11ControlNode13childrenCountEv(ptr noundef nonnull align 8 dereferenceable(40)) #3

declare void @_ZN2BT11ControlNode9haltChildEm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef) #3

declare noundef zeroext i1 @_ZNK2BT8TreeNode14requiresWakeUpEv(ptr noundef nonnull align 8 dereferenceable(16)) #3

declare void @_ZN2BT8TreeNode16emitWakeUpSignalEv(ptr noundef nonnull align 8 dereferenceable(16)) #3

declare ptr @__cxa_allocate_exception(i64)

declare noundef nonnull align 8 dereferenceable(32) ptr @_ZNK2BT8TreeNode4nameB5cxx11Ev(ptr noundef nonnull align 8 dereferenceable(16)) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2BT10LogicErrorC2IJA2_cNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEA37_cEEEDpRKT_(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 1 dereferenceable(2), ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 1 dereferenceable(37)) unnamed_addr #1 align 2

declare void @__cxa_free_exception(ptr)

declare void @__cxa_throw(ptr, ptr, ptr)

declare void @_ZN2BT11ControlNode13resetChildrenEv(ptr noundef nonnull align 8 dereferenceable(40)) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN2BT21BehaviorTreeExceptionD2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #4 align 2

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 = { "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 = { 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 #5 = { nounwind }
attributes #6 = { noreturn }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 48}
!12 = !{!"_ZTSN2BT18SequenceWithMemoryE", !13, i64 0, !10, i64 40, !10, i64 48}
!13 = !{!"_ZTSN2BT11ControlNodeE", !14, i64 0, !21, i64 16}
!14 = !{!"_ZTSN2BT8TreeNodeE", !15, i64 8}
!15 = !{!"_ZTSSt10unique_ptrIN2BT8TreeNode5PImplESt14default_deleteIS2_EE", !16, i64 0}
!16 = !{!"_ZTSSt15__uniq_ptr_dataIN2BT8TreeNode5PImplESt14default_deleteIS2_ELb1ELb1EE", !17, i64 0}
!17 = !{!"_ZTSSt15__uniq_ptr_implIN2BT8TreeNode5PImplESt14default_deleteIS2_EE", !18, i64 0}
!18 = !{!"_ZTSSt5tupleIJPN2BT8TreeNode5PImplESt14default_deleteIS2_EEE", !19, i64 0}
!19 = !{!"_ZTSSt11_Tuple_implILm0EJPN2BT8TreeNode5PImplESt14default_deleteIS2_EEE", !20, i64 0}
!20 = !{!"_ZTSSt10_Head_baseILm0EPN2BT8TreeNode5PImplELb0EE", !6, i64 0}
!21 = !{!"_ZTSSt6vectorIPN2BT8TreeNodeESaIS2_EE", !22, i64 0}
!22 = !{!"_ZTSSt12_Vector_baseIPN2BT8TreeNodeESaIS2_EE", !23, i64 0}
!23 = !{!"_ZTSNSt12_Vector_baseIPN2BT8TreeNodeESaIS2_EE12_Vector_implE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseIPN2BT8TreeNodeESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!25 = !{!12, !10, i64 40}
!26 = !{!27, !27, i64 0}
!27 = !{!"_ZTSN2BT10NodeStatusE", !7, i64 0}
!28 = !{!29, !29, i64 0}
!29 = !{!"vtable pointer", !8, i64 0}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.mustprogress"}
!32 = distinct !{!32, !31}


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

@.str.12 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [37 x i8], align 1
@_ZTIN2BT10LogicErrorE = external dso_local constant { ptr, ptr, ptr }, align 8

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN2BT18SequenceWithMemory4tickEv(ptr noundef nonnull align 8 dereferenceable(56) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = tail call noundef i64 @_ZNKSt6vectorIPN2BT8TreeNodeESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %2) #4
  %4 = tail call noundef i32 @_ZNK2BT8TreeNode6statusEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %6, label %8

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %6, %1
  tail call void @_ZN2BT8TreeNode9setStatusENS_10NodeStatusE(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef 1)
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  %10 = load i64, ptr %9, align 8, !tbaa !23
  %11 = icmp ult i64 %10, %3
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %8, %46
  %12 = phi i64 [ %47, %46 ], [ %10, %8 ]
  %13 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN2BT8TreeNodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %2, i64 noundef %12) #4
  %14 = load ptr, ptr %13, align 8, !tbaa !24
  %15 = tail call noundef i32 @_ZNK2BT8TreeNode6statusEv(ptr noundef nonnull align 8 dereferenceable(16) %14)
  %16 = load ptr, ptr %14, align 8, !tbaa !25
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %18 = load ptr, ptr %17, align 8
  %19 = tail call noundef i32 %18(ptr noundef nonnull align 8 dereferenceable(16) %14)
  switch i32 %19, label %._crit_edge46 [
    i32 1, label %.thread
    i32 3, label %20
    i32 2, label %27
    i32 4, label %35
    i32 0, label %39
  ]

._crit_edge46:                                    ; preds = %.lr.ph
  %.pre = load i64, ptr %9, align 8, !tbaa !23
  br label %46

20:                                               ; preds = %.lr.ph
  %21 = load i64, ptr %9, align 8, !tbaa !23
  %22 = tail call noundef i64 @_ZNK2BT11ControlNode13childrenCountEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %.lr.ph43, label %.thread

.lr.ph43:                                         ; preds = %20, %.lr.ph43
  %.01941 = phi i64 [ %24, %.lr.ph43 ], [ %21, %20 ]
  tail call void @_ZN2BT11ControlNode9haltChildEm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %.01941)
  %24 = add nuw i64 %.01941, 1
  %25 = tail call noundef i64 @_ZNK2BT11ControlNode13childrenCountEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %.lr.ph43, label %.thread, !llvm.loop !27

27:                                               ; preds = %.lr.ph
  %28 = load i64, ptr %9, align 8, !tbaa !23
  %29 = add i64 %28, 1
  store i64 %29, ptr %9, align 8, !tbaa !23
  %30 = tail call noundef zeroext i1 @_ZNK2BT8TreeNode14requiresWakeUpEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %31 = icmp eq i32 %15, 0
  %or.cond = and i1 %31, %30
  %32 = load i64, ptr %9, align 8
  %33 = icmp ult i64 %32, %3
  %or.cond27 = select i1 %or.cond, i1 %33, i1 false
  br i1 %or.cond27, label %34, label %46

34:                                               ; preds = %27
  tail call void @_ZN2BT8TreeNode16emitWakeUpSignalEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  br label %.thread

35:                                               ; preds = %.lr.ph
  %36 = load <2 x i64>, ptr %9, align 8, !tbaa !29
  %37 = add <2 x i64> %36, <i64 1, i64 1>
  store <2 x i64> %37, ptr %9, align 8, !tbaa !29
  %38 = extractelement <2 x i64> %37, i64 0
  br label %46

39:                                               ; preds = %.lr.ph
  %40 = tail call ptr @__cxa_allocate_exception(i64 40) #4
  %41 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZNK2BT8TreeNode4nameB5cxx11Ev(ptr noundef nonnull align 8 dereferenceable(16) %0)
          to label %42 unwind label %44

42:                                               ; preds = %39
  invoke void @_ZN2BT10LogicErrorC2IJA2_cNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEA37_cEEEDpRKT_(ptr noundef nonnull align 8 dereferenceable(40) %40, ptr noundef nonnull align 1 dereferenceable(2) @.str.12, ptr noundef nonnull align 8 dereferenceable(32) %41, ptr noundef nonnull align 1 dereferenceable(37) @.str.13)
          to label %43 unwind label %44

43:                                               ; preds = %42
  tail call void @__cxa_throw(ptr nonnull %40, ptr nonnull @_ZTIN2BT10LogicErrorE, ptr nonnull @_ZN2BT21BehaviorTreeExceptionD2Ev) #5
  unreachable

44:                                               ; preds = %42, %39
  %45 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_free_exception(ptr %40) #4
  resume { ptr, i32 } %45

46:                                               ; preds = %._crit_edge46, %35, %27
  %47 = phi i64 [ %.pre, %._crit_edge46 ], [ %38, %35 ], [ %32, %27 ]
  %48 = icmp ult i64 %47, %3
  br i1 %48, label %.lr.ph, label %._crit_edge, !llvm.loop !30

._crit_edge:                                      ; preds = %46, %8
  %.lcssa = phi i64 [ %10, %8 ], [ %47, %46 ]
  %49 = icmp eq i64 %.lcssa, %3
  br i1 %49, label %50, label %51

50:                                               ; preds = %._crit_edge
  tail call void @_ZN2BT11ControlNode13resetChildrenEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  store i64 0, ptr %9, align 8, !tbaa !23
  br label %51

51:                                               ; preds = %50, %._crit_edge
  %52 = getelementptr inbounds i8, ptr %0, i64 48
  %53 = load i64, ptr %52, align 8, !tbaa !5
  %54 = icmp eq i64 %53, %3
  %55 = select i1 %54, i32 4, i32 2
  br label %.thread

.thread:                                          ; preds = %.lr.ph, %.lr.ph43, %20, %34, %51
  %.2 = phi i32 [ %55, %51 ], [ 1, %34 ], [ 3, %20 ], [ 3, %.lr.ph43 ], [ %19, %.lr.ph ]
  ret i32 %.2
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIPN2BT8TreeNodeESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

declare noundef i32 @_ZNK2BT8TreeNode6statusEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

declare void @_ZN2BT8TreeNode9setStatusENS_10NodeStatusE(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN2BT8TreeNodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

declare noundef i64 @_ZNK2BT11ControlNode13childrenCountEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #2

declare void @_ZN2BT11ControlNode9haltChildEm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef) local_unnamed_addr #2

declare noundef zeroext i1 @_ZNK2BT8TreeNode14requiresWakeUpEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

declare void @_ZN2BT8TreeNode16emitWakeUpSignalEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare noundef nonnull align 8 dereferenceable(32) ptr @_ZNK2BT8TreeNode4nameB5cxx11Ev(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN2BT10LogicErrorC2IJA2_cNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEA37_cEEEDpRKT_(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 1 dereferenceable(2), ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 1 dereferenceable(37)) unnamed_addr #0 align 2

declare void @__cxa_free_exception(ptr) local_unnamed_addr

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

declare void @_ZN2BT11ControlNode13resetChildrenEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN2BT21BehaviorTreeExceptionD2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #3 align 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 = { 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 = { "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 = { noreturn }

!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, !22, i64 48}
!6 = !{!"_ZTSN2BT18SequenceWithMemoryE", !7, i64 0, !22, i64 40, !22, i64 48}
!7 = !{!"_ZTSN2BT11ControlNodeE", !8, i64 0, !18, i64 16}
!8 = !{!"_ZTSN2BT8TreeNodeE", !9, i64 8}
!9 = !{!"_ZTSSt10unique_ptrIN2BT8TreeNode5PImplESt14default_deleteIS2_EE", !10, i64 0}
!10 = !{!"_ZTSSt15__uniq_ptr_dataIN2BT8TreeNode5PImplESt14default_deleteIS2_ELb1ELb1EE", !11, i64 0}
!11 = !{!"_ZTSSt15__uniq_ptr_implIN2BT8TreeNode5PImplESt14default_deleteIS2_EE", !12, i64 0}
!12 = !{!"_ZTSSt5tupleIJPN2BT8TreeNode5PImplESt14default_deleteIS2_EEE", !13, i64 0}
!13 = !{!"_ZTSSt11_Tuple_implILm0EJPN2BT8TreeNode5PImplESt14default_deleteIS2_EEE", !14, i64 0}
!14 = !{!"_ZTSSt10_Head_baseILm0EPN2BT8TreeNode5PImplELb0EE", !15, i64 0}
!15 = !{!"any pointer", !16, i64 0}
!16 = !{!"omnipotent char", !17, i64 0}
!17 = !{!"Simple C++ TBAA"}
!18 = !{!"_ZTSSt6vectorIPN2BT8TreeNodeESaIS2_EE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseIPN2BT8TreeNodeESaIS2_EE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIPN2BT8TreeNodeESaIS2_EE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIPN2BT8TreeNodeESaIS2_EE17_Vector_impl_dataE", !15, i64 0, !15, i64 8, !15, i64 16}
!22 = !{!"long", !16, i64 0}
!23 = !{!6, !22, i64 40}
!24 = !{!15, !15, i64 0}
!25 = !{!26, !26, i64 0}
!26 = !{!"vtable pointer", !17, i64 0}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = !{!22, !22, i64 0}
!30 = distinct !{!30, !28}


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