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

@.str.1 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@__PRETTY_FUNCTION__._ZN9quickbook6detail17tree_builder_base7extractEPNS0_14tree_node_baseE = external hidden unnamed_addr constant [80 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN9quickbook6detail17tree_builder_base7extractEPNS0_14tree_node_baseE(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1) #1 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 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %6, i32 0, i32 3
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %41, label %10

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %23

15:                                               ; preds = %10
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %21, i32 0, i32 1
  store ptr %18, ptr %22, align 8, !tbaa !13
  br label %40

23:                                               ; preds = %10
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.quickbook::detail::tree_base", ptr %5, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = icmp eq ptr %24, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  br label %31

29:                                               ; preds = %23
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 150, ptr noundef @__PRETTY_FUNCTION__._ZN9quickbook6detail17tree_builder_base7extractEPNS0_14tree_node_baseE) #2
  unreachable

30:                                               ; No predecessors!
  br label %31

31:                                               ; preds = %30, %28
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !12
  %35 = getelementptr inbounds %"struct.quickbook::detail::tree_base", ptr %5, i32 0, i32 0
  store ptr %34, ptr %35, align 8, !tbaa !14
  %36 = getelementptr inbounds %"struct.quickbook::detail::tree_builder_base", ptr %5, i32 0, i32 2
  store ptr null, ptr %36, align 8, !tbaa !16
  %37 = getelementptr inbounds %"struct.quickbook::detail::tree_base", ptr %5, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = getelementptr inbounds %"struct.quickbook::detail::tree_builder_base", ptr %5, i32 0, i32 1
  store ptr %38, ptr %39, align 8, !tbaa !18
  br label %40

40:                                               ; preds = %31, %15
  br label %49

41:                                               ; preds = %2
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !12
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %45, i32 0, i32 3
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %47, i32 0, i32 2
  store ptr %44, ptr %48, align 8, !tbaa !12
  br label %49

49:                                               ; preds = %41, %40
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %50, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !12
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %62

54:                                               ; preds = %49
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %55, i32 0, i32 3
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !12
  %61 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %60, i32 0, i32 3
  store ptr %57, ptr %61, align 8, !tbaa !9
  br label %62

62:                                               ; preds = %54, %49
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %63, i32 0, i32 0
  store ptr null, ptr %64, align 8, !tbaa !11
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %65, i32 0, i32 2
  store ptr null, ptr %66, align 8, !tbaa !12
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %67, i32 0, i32 3
  store ptr null, ptr %68, align 8, !tbaa !9
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  ret ptr %69
}

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


; 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.1 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@__PRETTY_FUNCTION__._ZN9quickbook6detail17tree_builder_base7extractEPNS0_14tree_node_baseE = external hidden unnamed_addr constant [80 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN9quickbook6detail17tree_builder_base7extractEPNS0_14tree_node_baseE(ptr nocapture noundef nonnull align 8 dereferenceable(24) %0, ptr noundef returned %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %5, label %20

5:                                                ; preds = %2
  %6 = load ptr, ptr %1, align 8, !tbaa !10
  %.not19 = icmp eq ptr %6, null
  br i1 %.not19, label %11, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %6, i64 8
  store ptr %9, ptr %10, align 8, !tbaa !12
  br label %24

11:                                               ; preds = %5
  %12 = load ptr, ptr %0, align 8, !tbaa !13
  %13 = icmp eq ptr %12, %1
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 150, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN9quickbook6detail17tree_builder_base7extractEPNS0_14tree_node_baseE) #3
  unreachable

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %1, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  store ptr %17, ptr %0, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr null, ptr %18, align 8, !tbaa !15
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %17, ptr %19, align 8, !tbaa !17
  br label %24

20:                                               ; preds = %2
  %21 = getelementptr inbounds i8, ptr %1, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr %22, ptr %23, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %7, %15, %20
  %25 = phi ptr [ %9, %7 ], [ %17, %15 ], [ %22, %20 ]
  %.not20 = icmp eq ptr %25, null
  br i1 %.not20, label %28, label %26

26:                                               ; preds = %24
  %27 = getelementptr inbounds i8, ptr %25, i64 24
  store ptr %4, ptr %27, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %26, %24
  %29 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr null, ptr %1, align 8, !tbaa !10
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %29, i8 0, i64 16, i1 false)
  ret ptr %1
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { noreturn 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { noreturn 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 24}
!6 = !{!"_ZTSN9quickbook6detail14tree_node_baseE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!6, !7, i64 16}
!12 = !{!6, !7, i64 8}
!13 = !{!14, !7, i64 0}
!14 = !{!"_ZTSN9quickbook6detail9tree_baseE", !7, i64 0}
!15 = !{!16, !7, i64 16}
!16 = !{!"_ZTSN9quickbook6detail17tree_builder_baseE", !14, i64 0, !7, i64 8, !7, i64 16}
!17 = !{!16, !7, i64 8}


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