; LLVM IR from MakeContributions/DSA :: algorithms/CPlusPlus/Trees (in-order-predecessor-and-successor)

; 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.TreeNode = type <{ ptr, ptr, i32, [4 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z11predecessorP8TreeNodeRKiS0_(ptr noundef %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.TreeNode, ptr %8, i32 0, i32 2
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %14, label %21

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TreeNode, ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call noundef ptr @_Z11predecessorP8TreeNodeRKiS0_(ptr noundef %17, ptr noundef nonnull align 4 dereferenceable(4) %18, ptr noundef %19)
  store ptr %20, ptr %4, align 8
  br label %38

21:                                               ; preds = %3
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.TreeNode, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i32, ptr %25, align 4, !tbaa !12
  %27 = icmp sgt i32 %24, %26
  br i1 %27, label %28, label %35

28:                                               ; preds = %21
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.TreeNode, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = call noundef ptr @_Z11predecessorP8TreeNodeRKiS0_(ptr noundef %31, ptr noundef nonnull align 4 dereferenceable(4) %32, ptr noundef %33)
  store ptr %34, ptr %4, align 8
  br label %38

35:                                               ; preds = %21
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %37, ptr %4, align 8
  br label %38

38:                                               ; preds = %36, %28, %14
  %39 = load ptr, ptr %4, align 8
  ret ptr %39
}

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 16}
!10 = !{!"_ZTS8TreeNode", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !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(read, inaccessiblemem: none) uwtable
define dso_local noundef ptr @_Z11predecessorP8TreeNodeRKiS0_(ptr noundef readonly %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(4) %1, ptr noundef readnone %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %1, align 4, !tbaa !5
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %tailrecurse._crit_edge, %3
  %.tr.ph = phi ptr [ %9, %tailrecurse._crit_edge ], [ %0, %3 ]
  %.tr15.ph = phi ptr [ %.tr.lcssa, %tailrecurse._crit_edge ], [ %2, %3 ]
  %5 = getelementptr inbounds i8, ptr %.tr.ph, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp slt i32 %6, %4
  br i1 %7, label %tailrecurse._crit_edge, label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %tailrecurse.outer
  %.tr.lcssa = phi ptr [ %.tr.ph, %tailrecurse.outer ], [ %12, %tailrecurse ]
  %8 = getelementptr inbounds i8, ptr %.tr.lcssa, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  br label %tailrecurse.outer

.lr.ph:                                           ; preds = %tailrecurse.outer, %tailrecurse
  %10 = phi i32 [ %14, %tailrecurse ], [ %6, %tailrecurse.outer ]
  %.tr17 = phi ptr [ %12, %tailrecurse ], [ %.tr.ph, %tailrecurse.outer ]
  %11 = icmp sgt i32 %10, %4
  br i1 %11, label %tailrecurse, label %16

tailrecurse:                                      ; preds = %.lr.ph
  %12 = load ptr, ptr %.tr17, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = icmp slt i32 %14, %4
  br i1 %15, label %tailrecurse._crit_edge, label %.lr.ph

16:                                               ; preds = %.lr.ph
  ret ptr %.tr15.ph
}

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


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