; LLVM IR from frol/completely-unscientific-benchmarks :: c++/main-tuned-raw-with-pool.ll (ZN4Tree5mergeEPNS_4NodeES1_RS1_)

; 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.Tree::Node" = type { i32, i32, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Tree5mergeEPNS_4NodeES1_RS1_(ptr noundef %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(8) %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %12, label %9

9:                                                ; preds = %3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %10, ptr %11, align 8, !tbaa !5
  br label %48

12:                                               ; preds = %3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %18, label %15

15:                                               ; preds = %12
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %16, ptr %17, align 8, !tbaa !5
  br label %48

18:                                               ; preds = %12
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.Tree::Node", ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.Tree::Node", ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = icmp slt i32 %21, %24
  br i1 %25, label %26, label %37

26:                                               ; preds = %18
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %27, ptr %28, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.Tree::Node", ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.Tree::Node", ptr %35, i32 0, i32 3
  call void @_ZN4Tree5mergeEPNS_4NodeES1_RS1_(ptr noundef %32, ptr noundef %33, ptr noundef nonnull align 8 dereferenceable(8) %36)
  br label %48

37:                                               ; preds = %18
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %38, ptr %39, align 8, !tbaa !5
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.Tree::Node", ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.Tree::Node", ptr %46, i32 0, i32 2
  call void @_ZN4Tree5mergeEPNS_4NodeES1_RS1_(ptr noundef %40, ptr noundef %44, ptr noundef nonnull align 8 dereferenceable(8) %47)
  br label %48

48:                                               ; preds = %37, %26, %15, %9
  ret void
}

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

!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, !11, i64 4}
!10 = !{!"_ZTSN4Tree4NodeE", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN4Tree5mergeEPNS_4NodeES1_RS1_(ptr noundef %0, ptr noundef %1, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %2) local_unnamed_addr #0 align 2 {
  %.not49 = icmp eq ptr %0, null
  br i1 %.not49, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

.lr.ph.split:                                     ; preds = %3, %tailrecurse.outer
  %.tr21.ph52 = phi ptr [ %10, %tailrecurse.outer ], [ %2, %3 ]
  %.tr20.ph51 = phi ptr [ %.tr202743, %tailrecurse.outer ], [ %1, %3 ]
  %.tr.ph50 = phi ptr [ %11, %tailrecurse.outer ], [ %0, %3 ]
  %.not1941 = icmp eq ptr %.tr20.ph51, null
  br i1 %.not1941, label %.split.us, label %.lr.ph44

.lr.ph44:                                         ; preds = %.lr.ph.split
  %4 = getelementptr inbounds i8, ptr %.tr.ph50, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  br label %6

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %3
  %.tr20.lcssa = phi ptr [ %1, %3 ], [ %.tr202743, %tailrecurse.outer ]
  %.tr21.lcssa = phi ptr [ %2, %3 ], [ %10, %tailrecurse.outer ]
  store ptr %.tr20.lcssa, ptr %.tr21.lcssa, align 8, !tbaa !11
  br label %14

.split.us:                                        ; preds = %.lr.ph.split, %tailrecurse
  %.us-phi32 = phi ptr [ %12, %tailrecurse ], [ %.tr21.ph52, %.lr.ph.split ]
  store ptr %.tr.ph50, ptr %.us-phi32, align 8, !tbaa !11
  br label %14

6:                                                ; preds = %.lr.ph44, %tailrecurse
  %.tr202743 = phi ptr [ %.tr20.ph51, %.lr.ph44 ], [ %13, %tailrecurse ]
  %.tr212842 = phi ptr [ %.tr21.ph52, %.lr.ph44 ], [ %12, %tailrecurse ]
  %7 = getelementptr inbounds i8, ptr %.tr202743, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = icmp slt i32 %5, %8
  br i1 %9, label %tailrecurse.outer, label %tailrecurse

tailrecurse.outer:                                ; preds = %6
  store ptr %.tr.ph50, ptr %.tr212842, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %.tr.ph50, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

tailrecurse:                                      ; preds = %6
  store ptr %.tr202743, ptr %.tr212842, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %.tr202743, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %.not19 = icmp eq ptr %13, null
  br i1 %.not19, label %.split.us, label %6

14:                                               ; preds = %.split.us, %tailrecurse.outer._crit_edge
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(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, !7, i64 4}
!6 = !{!"_ZTSN4Tree4NodeE", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass