; LLVM IR from gstonge/spreading_CR :: src/BinaryTree.ll (ZN3net10BinaryTree12update_valueEjd)

; 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.net::BinaryTree" = type { ptr, ptr, %"class.std::vector", %"class.std::unordered_map" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<net::BinaryTreeNode *, std::allocator<net::BinaryTreeNode *>>::_Vector_impl" }
%"struct.std::_Vector_base<net::BinaryTreeNode *, std::allocator<net::BinaryTreeNode *>>::_Vector_impl" = type { %"struct.std::_Vector_base<net::BinaryTreeNode *, std::allocator<net::BinaryTreeNode *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<net::BinaryTreeNode *, std::allocator<net::BinaryTreeNode *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::unordered_map" = type { %"class.std::_Hashtable" }
%"class.std::_Hashtable" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"struct.std::__detail::_Hash_node_base" = type { ptr }
%"struct.std::__detail::_Prime_rehash_policy" = type { float, i64 }
%"struct.net::BinaryTreeNode" = type { double, ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3net10BinaryTree12update_valueEjd(ptr noundef nonnull align 8 dereferenceable(96) %0, i32 noundef %1, double noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !11
  %7 = load ptr, ptr %4, align 8
  %8 = getelementptr inbounds %"class.net::BinaryTree", ptr %7, i32 0, i32 2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = zext i32 %9 to i64
  %11 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN3net14BinaryTreeNodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %8, i64 noundef %10) #2
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds %"class.net::BinaryTree", ptr %7, i32 0, i32 1
  store ptr %12, ptr %13, align 8, !tbaa !13
  %14 = load double, ptr %6, align 8, !tbaa !11
  %15 = getelementptr inbounds %"class.net::BinaryTree", ptr %7, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds %"struct.net::BinaryTreeNode", ptr %16, i32 0, i32 0
  %18 = load double, ptr %17, align 8, !tbaa !25
  %19 = fadd double %18, %14
  store double %19, ptr %17, align 8, !tbaa !25
  br label %20

20:                                               ; preds = %23, %3
  %21 = call noundef zeroext i1 @_ZN3net10BinaryTree7is_rootEv(ptr noundef nonnull align 8 dereferenceable(96) %7)
  %22 = xor i1 %21, true
  br i1 %22, label %23, label %30

23:                                               ; preds = %20
  call void @_ZN3net10BinaryTree7move_upEv(ptr noundef nonnull align 8 dereferenceable(96) %7)
  %24 = load double, ptr %6, align 8, !tbaa !11
  %25 = getelementptr inbounds %"class.net::BinaryTree", ptr %7, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = getelementptr inbounds %"struct.net::BinaryTreeNode", ptr %26, i32 0, i32 0
  %28 = load double, ptr %27, align 8, !tbaa !25
  %29 = fadd double %28, %24
  store double %29, ptr %27, align 8, !tbaa !25
  br label %20, !llvm.loop !27

30:                                               ; preds = %20
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3net10BinaryTree7is_rootEv(ptr noundef nonnull align 8 dereferenceable(96)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3net10BinaryTree7move_upEv(ptr noundef nonnull align 8 dereferenceable(96)) #1 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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"_ZTSN3net10BinaryTreeE", !6, i64 0, !6, i64 8, !15, i64 16, !19, i64 40}
!15 = !{!"_ZTSSt6vectorIPN3net14BinaryTreeNodeESaIS2_EE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIPN3net14BinaryTreeNodeESaIS2_EE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIPN3net14BinaryTreeNodeESaIS2_EE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIPN3net14BinaryTreeNodeESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!"_ZTSSt13unordered_mapIPN3net14BinaryTreeNodeEjSt4hashIS2_ESt8equal_toIS2_ESaISt4pairIKS2_jEEE", !20, i64 0}
!20 = !{!"_ZTSSt10_HashtableIPN3net14BinaryTreeNodeESt4pairIKS2_jESaIS5_ENSt8__detail10_Select1stESt8equal_toIS2_ESt4hashIS2_ENS7_18_Mod_range_hashingENS7_20_Default_ranged_hashENS7_20_Prime_rehash_policyENS7_17_Hashtable_traitsILb0ELb0ELb1EEEE", !6, i64 0, !21, i64 8, !22, i64 16, !21, i64 24, !23, i64 32, !6, i64 48}
!21 = !{!"long", !7, i64 0}
!22 = !{!"_ZTSNSt8__detail15_Hash_node_baseE", !6, i64 0}
!23 = !{!"_ZTSNSt8__detail20_Prime_rehash_policyE", !24, i64 0, !21, i64 8}
!24 = !{!"float", !7, i64 0}
!25 = !{!26, !12, i64 0}
!26 = !{!"_ZTSN3net14BinaryTreeNodeE", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!27 = distinct !{!27, !28}
!28 = !{!"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: mustprogress nounwind uwtable
define dso_local void @_ZN3net10BinaryTree12update_valueEjd(ptr noundef nonnull align 8 dereferenceable(96) %0, i32 noundef %1, double noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = zext i32 %1 to i64
  %6 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN3net14BinaryTreeNodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %4, i64 noundef %5) #1
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %7, ptr %8, align 8, !tbaa !9
  %9 = load double, ptr %7, align 8, !tbaa !21
  %10 = fadd double %9, %2
  store double %10, ptr %7, align 8, !tbaa !21
  %11 = tail call noundef zeroext i1 @_ZN3net10BinaryTree7is_rootEv(ptr noundef nonnull align 8 dereferenceable(96) %0)
  br i1 %11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  tail call void @_ZN3net10BinaryTree7move_upEv(ptr noundef nonnull align 8 dereferenceable(96) %0)
  %12 = load ptr, ptr %8, align 8, !tbaa !9
  %13 = load double, ptr %12, align 8, !tbaa !21
  %14 = fadd double %13, %2
  store double %14, ptr %12, align 8, !tbaa !21
  %15 = tail call noundef zeroext i1 @_ZN3net10BinaryTree7is_rootEv(ptr noundef nonnull align 8 dereferenceable(96) %0)
  br i1 %15, label %._crit_edge, label %.lr.ph, !llvm.loop !24

._crit_edge:                                      ; preds = %.lr.ph, %3
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3net10BinaryTree7is_rootEv(ptr noundef nonnull align 8 dereferenceable(96)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3net10BinaryTree7move_upEv(ptr noundef nonnull align 8 dereferenceable(96)) local_unnamed_addr #0 align 2

attributes #0 = { 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 #1 = { 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 8}
!10 = !{!"_ZTSN3net10BinaryTreeE", !6, i64 0, !6, i64 8, !11, i64 16, !15, i64 40}
!11 = !{!"_ZTSSt6vectorIPN3net14BinaryTreeNodeESaIS2_EE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseIPN3net14BinaryTreeNodeESaIS2_EE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIPN3net14BinaryTreeNodeESaIS2_EE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIPN3net14BinaryTreeNodeESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!"_ZTSSt13unordered_mapIPN3net14BinaryTreeNodeEjSt4hashIS2_ESt8equal_toIS2_ESaISt4pairIKS2_jEEE", !16, i64 0}
!16 = !{!"_ZTSSt10_HashtableIPN3net14BinaryTreeNodeESt4pairIKS2_jESaIS5_ENSt8__detail10_Select1stESt8equal_toIS2_ESt4hashIS2_ENS7_18_Mod_range_hashingENS7_20_Default_ranged_hashENS7_20_Prime_rehash_policyENS7_17_Hashtable_traitsILb0ELb0ELb1EEEE", !6, i64 0, !17, i64 8, !18, i64 16, !17, i64 24, !19, i64 32, !6, i64 48}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSNSt8__detail15_Hash_node_baseE", !6, i64 0}
!19 = !{!"_ZTSNSt8__detail20_Prime_rehash_policyE", !20, i64 0, !17, i64 8}
!20 = !{!"float", !7, i64 0}
!21 = !{!22, !23, i64 0}
!22 = !{!"_ZTSN3net14BinaryTreeNodeE", !23, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!23 = !{!"double", !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass