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

@.str = external hidden unnamed_addr constant [71 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [93 x i8], align 1
@__PRETTY_FUNCTION__._ZN9quickbook6detail14tree_node_base10add_beforeEPNS0_9tree_baseE = external hidden unnamed_addr constant [64 x i8], align 1

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

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

17:                                               ; preds = %10
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.quickbook::detail::tree_base", ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %20, i32 0, i32 3
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = icmp ne ptr %22, null
  br i1 %23, label %32, label %24

24:                                               ; preds = %17
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.quickbook::detail::tree_base", ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = icmp ne ptr %29, null
  %31 = xor i1 %30, true
  br label %32

32:                                               ; preds = %24, %17, %10, %2
  %33 = phi i1 [ false, %17 ], [ false, %10 ], [ false, %2 ], [ %31, %24 ]
  br i1 %33, label %34, label %35

34:                                               ; preds = %32
  br label %37

35:                                               ; preds = %32
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 20, ptr noundef @__PRETTY_FUNCTION__._ZN9quickbook6detail14tree_node_base10add_beforeEPNS0_9tree_baseE) #2
  unreachable

36:                                               ; No predecessors!
  br label %37

37:                                               ; preds = %36, %34
  %38 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %5, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.quickbook::detail::tree_base", ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %42, i32 0, i32 0
  store ptr %39, ptr %43, align 8, !tbaa !11
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %"struct.quickbook::detail::tree_base", ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !9
  %47 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %46, i32 0, i32 2
  store ptr %5, ptr %47, align 8, !tbaa !14
  %48 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %5, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %64

51:                                               ; preds = %37
  %52 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %5, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.quickbook::detail::tree_base", ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !9
  %57 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %56, i32 0, i32 3
  store ptr %53, ptr %57, align 8, !tbaa !13
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %"struct.quickbook::detail::tree_base", ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  %61 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %5, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !13
  %63 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %62, i32 0, i32 2
  store ptr %60, ptr %63, align 8, !tbaa !14
  br label %71

64:                                               ; preds = %37
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %"struct.quickbook::detail::tree_base", ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !9
  %68 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %5, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !11
  %70 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %69, i32 0, i32 1
  store ptr %67, ptr %70, align 8, !tbaa !15
  br label %71

71:                                               ; preds = %64, %51
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %"struct.quickbook::detail::tree_base", ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !9
  %75 = getelementptr inbounds %"struct.quickbook::detail::tree_node_base", ptr %5, i32 0, i32 3
  store ptr %74, ptr %75, align 8, !tbaa !13
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %"struct.quickbook::detail::tree_base", ptr %76, i32 0, i32 0
  store ptr null, ptr %77, align 8, !tbaa !9
  ret void
}

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

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 = { 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 #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 0}
!10 = !{!"_ZTSN9quickbook6detail9tree_baseE", !6, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSN9quickbook6detail14tree_node_baseE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!12, !6, i64 24}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !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 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [93 x i8], align 1
@__PRETTY_FUNCTION__._ZN9quickbook6detail14tree_node_base10add_beforeEPNS0_9tree_baseE = external hidden unnamed_addr constant [64 x i8], align 1

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

4:                                                ; preds = %2
  %5 = load ptr, ptr %3, align 8, !tbaa !10
  %.not13 = icmp eq ptr %5, null
  br i1 %.not13, label %6, label %.critedge

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %3, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %.not14 = icmp eq ptr %8, null
  br i1 %.not14, label %9, label %.critedge

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %3, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %.not15 = icmp eq ptr %11, null
  br i1 %.not15, label %12, label %.critedge

.critedge:                                        ; preds = %6, %4, %2, %9
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 20, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN9quickbook6detail14tree_node_base10add_beforeEPNS0_9tree_baseE) #2
  unreachable

12:                                               ; preds = %9
  %13 = load ptr, ptr %0, align 8, !tbaa !10
  store ptr %13, ptr %3, align 8, !tbaa !10
  store ptr %0, ptr %10, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %.not16 = icmp eq ptr %15, null
  br i1 %.not16, label %19, label %16

16:                                               ; preds = %12
  store ptr %15, ptr %7, align 8, !tbaa !12
  %17 = load ptr, ptr %14, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  br label %21

19:                                               ; preds = %12
  %20 = getelementptr inbounds i8, ptr %13, i64 8
  br label %21

21:                                               ; preds = %19, %16
  %.sink = phi ptr [ %20, %19 ], [ %18, %16 ]
  store ptr %3, ptr %.sink, align 8, !tbaa !14
  store ptr %3, ptr %14, align 8, !tbaa !12
  store ptr null, ptr %1, align 8, !tbaa !5
  ret void
}

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

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


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