; LLVM IR from stan-dev/math :: lib/boost_1.84.0/tools/quickbook/src (tree)

; 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.quickbook::detail::tree_builder_base" = type { %"struct.quickbook::detail::tree_base", ptr, ptr }
%"struct.quickbook::detail::tree_base" = type { ptr }
%"struct.quickbook::detail::tree_node_base" = type { ptr, ptr, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN9quickbook6detail17tree_builder_base11add_elementEPNS0_14tree_node_baseE(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %"struct.quickbook::detail::tree_builder_base", ptr %5, i32 0, i32 2
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %8, i32 0, i32 0
  store ptr %7, ptr %9, align 8, !tbaa !12
  %10 = getelementptr inbounds %"struct.quickbook::detail::tree_builder_base", ptr %5, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %12, i32 0, i32 3
  store ptr %11, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds %"struct.quickbook::detail::tree_builder_base", ptr %5, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %22

17:                                               ; preds = %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.quickbook::detail::tree_builder_base", ptr %5, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %20, i32 0, i32 2
  store ptr %18, ptr %21, align 8, !tbaa !16
  br label %35

22:                                               ; preds = %2
  %23 = getelementptr inbounds %"struct.quickbook::detail::tree_builder_base", ptr %5, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %31

26:                                               ; preds = %22
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.quickbook::detail::tree_builder_base", ptr %5, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %29, i32 0, i32 1
  store ptr %27, ptr %30, align 8, !tbaa !17
  br label %34

31:                                               ; preds = %22
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.quickbook::detail::tree_base", ptr %5, i32 0, i32 0
  store ptr %32, ptr %33, align 8, !tbaa !18
  br label %34

34:                                               ; preds = %31, %26
  br label %35

35:                                               ; preds = %34, %17
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.quickbook::detail::tree_builder_base", ptr %5, i32 0, i32 1
  store ptr %36, ptr %37, align 8, !tbaa !14
  ret void
}

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

!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 16}
!10 = !{!"_ZTSN9quickbook6detail17tree_builder_baseE", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"_ZTSN9quickbook6detail9tree_baseE", !6, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"_ZTSN9quickbook6detail14tree_node_baseE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!10, !6, i64 8}
!15 = !{!13, !6, i64 24}
!16 = !{!13, !6, i64 16}
!17 = !{!13, !6, i64 8}
!18 = !{!11, !6, i64 0}


; 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 nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN9quickbook6detail17tree_builder_base11add_elementEPNS0_14tree_node_baseE(ptr nocapture noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %4, ptr %1, align 8, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %1, i64 24
  store ptr %6, ptr %7, align 8, !tbaa !14
  %.not = icmp eq ptr %6, null
  %8 = getelementptr inbounds i8, ptr %6, i64 16
  %.not8 = icmp eq ptr %4, null
  %9 = getelementptr inbounds i8, ptr %4, i64 8
  %spec.select = select i1 %.not8, ptr %0, ptr %9
  %.sink = select i1 %.not, ptr %spec.select, ptr %8
  store ptr %1, ptr %.sink, align 8, !tbaa !15
  store ptr %1, ptr %5, align 8, !tbaa !13
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) 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" }

!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, !8, i64 16}
!6 = !{!"_ZTSN9quickbook6detail17tree_builder_baseE", !7, i64 0, !8, i64 8, !8, i64 16}
!7 = !{!"_ZTSN9quickbook6detail9tree_baseE", !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !8, i64 0}
!12 = !{!"_ZTSN9quickbook6detail14tree_node_baseE", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24}
!13 = !{!6, !8, i64 8}
!14 = !{!12, !8, i64 24}
!15 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass