; LLVM IR from TheAlgorithms/C-Plus-Plus :: data_structures/tree_234.ll (ZN15data_structures8tree_2347Tree2348TraverseEPNS0_4NodeE)

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

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_ZN15data_structures8tree_2344Node8GetCountEv(ptr noundef nonnull align 8 dereferenceable(57)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN15data_structures8tree_2344Node8GetChildEa(ptr noundef nonnull align 8 dereferenceable(57), i8 noundef signext) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

9:                                                ; preds = %2
  br label %34

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  store i8 0, ptr %5, align 1, !tbaa !9
  store i8 0, ptr %5, align 1, !tbaa !9
  br label %11

11:                                               ; preds = %27, %10
  %12 = load i8, ptr %5, align 1, !tbaa !9
  %13 = sext i8 %12 to i32
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call noundef signext i8 @_ZN15data_structures8tree_2344Node8GetCountEv(ptr noundef nonnull align 8 dereferenceable(57) %14)
  %16 = sext i8 %15 to i32
  %17 = icmp slt i32 %13, %16
  br i1 %17, label %18, label %30

18:                                               ; preds = %11
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i8, ptr %5, align 1, !tbaa !9
  %21 = call noundef ptr @_ZN15data_structures8tree_2344Node8GetChildEa(ptr noundef nonnull align 8 dereferenceable(57) %19, i8 noundef signext %20)
  call void @_ZN15data_structures8tree_2347Tree2348TraverseEPNS0_4NodeE(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef %21)
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load i8, ptr %5, align 1, !tbaa !9
  %24 = call noundef i64 @_ZN15data_structures8tree_2344Node7GetItemEa(ptr noundef nonnull align 8 dereferenceable(57) %22, i8 noundef signext %23)
  %25 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %24)
  %26 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %25, ptr noundef @.str)
  br label %27

27:                                               ; preds = %18
  %28 = load i8, ptr %5, align 1, !tbaa !9
  %29 = add i8 %28, 1
  store i8 %29, ptr %5, align 1, !tbaa !9
  br label %11, !llvm.loop !10

30:                                               ; preds = %11
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i8, ptr %5, align 1, !tbaa !9
  %33 = call noundef ptr @_ZN15data_structures8tree_2344Node8GetChildEa(ptr noundef nonnull align 8 dereferenceable(57) %31, i8 noundef signext %32)
  call void @_ZN15data_structures8tree_2347Tree2348TraverseEPNS0_4NodeE(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef %33)
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  br label %34

34:                                               ; preds = %30, %9
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN15data_structures8tree_2344Node7GetItemEa(ptr noundef nonnull align 8 dereferenceable(57), i8 noundef signext) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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" }
attributes #3 = { inlinehint 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" }
attributes #4 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_ZN15data_structures8tree_2344Node8GetCountEv(ptr noundef nonnull align 8 dereferenceable(57)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN15data_structures8tree_2344Node8GetChildEa(ptr noundef nonnull align 8 dereferenceable(57), i8 noundef signext) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN15data_structures8tree_2347Tree2348TraverseEPNS0_4NodeE(ptr nocapture noundef nonnull readnone align 8 dereferenceable(8) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %.not13 = icmp eq ptr %1, null
  br i1 %.not13, label %tailrecurse._crit_edge, label %.preheader

.preheader:                                       ; preds = %2, %tailrecurse
  %.tr1114 = phi ptr [ %12, %tailrecurse ], [ %1, %2 ]
  %3 = tail call noundef signext i8 @_ZN15data_structures8tree_2344Node8GetCountEv(ptr noundef nonnull align 8 dereferenceable(57) %.tr1114)
  %4 = icmp sgt i8 %3, 0
  br i1 %4, label %.lr.ph, label %tailrecurse

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.012 = phi i8 [ %9, %.lr.ph ], [ 0, %.preheader ]
  %5 = tail call noundef ptr @_ZN15data_structures8tree_2344Node8GetChildEa(ptr noundef nonnull align 8 dereferenceable(57) %.tr1114, i8 noundef signext %.012)
  tail call void @_ZN15data_structures8tree_2347Tree2348TraverseEPNS0_4NodeE(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %5)
  %6 = tail call noundef i64 @_ZN15data_structures8tree_2344Node7GetItemEa(ptr noundef nonnull align 8 dereferenceable(57) %.tr1114, i8 noundef signext %.012)
  %7 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %6)
  %8 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull @.str)
  %9 = add nuw nsw i8 %.012, 1
  %10 = tail call noundef signext i8 @_ZN15data_structures8tree_2344Node8GetCountEv(ptr noundef nonnull align 8 dereferenceable(57) %.tr1114)
  %11 = icmp slt i8 %9, %10
  br i1 %11, label %.lr.ph, label %tailrecurse, !llvm.loop !5

tailrecurse:                                      ; preds = %.lr.ph, %.preheader
  %.0.lcssa = phi i8 [ 0, %.preheader ], [ %9, %.lr.ph ]
  %12 = tail call noundef ptr @_ZN15data_structures8tree_2344Node8GetChildEa(ptr noundef nonnull align 8 dereferenceable(57) %.tr1114, i8 noundef signext %.0.lcssa)
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %tailrecurse._crit_edge, label %.preheader

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %2
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEl(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN15data_structures8tree_2344Node7GetItemEa(ptr noundef nonnull align 8 dereferenceable(57), i8 noundef signext) local_unnamed_addr #0 align 2

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 = { 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" }
attributes #2 = { inlinehint 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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