; LLVM IR from xtaci/algorithms :: src (suffix_tree_demo)

; 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.SuffixTree = type { %"class.std::__cxx11::basic_string", %"struct.SuffixTree::Node", %"class.SuffixTree::ActivePoint", i32, i32, i32, %"class.SuffixTree::LinkState" }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"struct.SuffixTree::Node" = type { ptr, %"class.std::map", %"class.std::map.3", %"class.std::map.9", ptr }
%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"class.std::map.3" = type { %"class.std::_Rb_tree.4" }
%"class.std::_Rb_tree.4" = type { %"struct.std::_Rb_tree<SuffixTree::Edge *, std::pair<SuffixTree::Edge *const, bool>, std::_Select1st<std::pair<SuffixTree::Edge *const, bool>>, std::less<SuffixTree::Edge *>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<SuffixTree::Edge *, std::pair<SuffixTree::Edge *const, bool>, std::_Select1st<std::pair<SuffixTree::Edge *const, bool>>, std::less<SuffixTree::Edge *>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"class.std::map.9" = type { %"class.std::_Rb_tree.10" }
%"class.std::_Rb_tree.10" = type { %"struct.std::_Rb_tree<char, std::pair<const char, SuffixTree::Edge *>, std::_Select1st<std::pair<const char, SuffixTree::Edge *>>, std::less<char>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<char, std::pair<const char, SuffixTree::Edge *>, std::_Select1st<std::pair<const char, SuffixTree::Edge *>>, std::less<char>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"class.SuffixTree::ActivePoint" = type { ptr, i8, i32 }
%"class.SuffixTree::LinkState" = type { i8, ptr, ptr }
%"struct.SuffixTree::Edge" = type { i32, i32, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10SuffixTree6searchENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(248) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %16 = getelementptr inbounds %class.SuffixTree, ptr %15, i32 0, i32 1
  store ptr %16, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  store i8 0, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 -1, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %17

17:                                               ; preds = %72, %2
  %18 = load i32, ptr %12, align 4, !tbaa !11
  %19 = zext i32 %18 to i64
  %20 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #3
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %17
  store i32 2, ptr %13, align 4
  br label %75

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #3
  %24 = load i32, ptr %12, align 4, !tbaa !11
  %25 = zext i32 %24 to i64
  %26 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %25)
  %27 = load i8, ptr %26, align 1, !tbaa !13
  store i8 %27, ptr %14, align 1, !tbaa !13
  %28 = load i8, ptr %7, align 1, !tbaa !9, !range !14, !noundef !15
  %29 = trunc i8 %28 to i1
  %30 = zext i1 %29 to i32
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %49

32:                                               ; preds = %23
  store i8 1, ptr %7, align 1, !tbaa !9
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i8, ptr %14, align 1, !tbaa !13
  %35 = call noundef ptr @_ZN10SuffixTree4Node9find_edgeEc(ptr noundef nonnull align 8 dereferenceable(160) %33, i8 noundef signext %34)
  store ptr %35, ptr %8, align 8, !tbaa !5
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %39

38:                                               ; preds = %32
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %13, align 4
  br label %69

39:                                               ; preds = %32
  %40 = load i32, ptr %12, align 4, !tbaa !11
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %46

42:                                               ; preds = %39
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.SuffixTree::Edge", ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !16
  store i32 %45, ptr %11, align 4, !tbaa !11
  br label %46

46:                                               ; preds = %42, %39
  store i32 0, ptr %9, align 4, !tbaa !11
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = call noundef i32 @_ZN10SuffixTree4Edge6lengthEv(ptr noundef nonnull align 8 dereferenceable(24) %47)
  store i32 %48, ptr %10, align 4, !tbaa !11
  br label %49

49:                                               ; preds = %46, %23
  %50 = load i8, ptr %14, align 1, !tbaa !13
  %51 = sext i8 %50 to i32
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !11
  %54 = call noundef signext i8 @_ZN10SuffixTree4EdgeixEj(ptr noundef nonnull align 8 dereferenceable(24) %52, i32 noundef %53)
  %55 = sext i8 %54 to i32
  %56 = icmp ne i32 %51, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %49
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %13, align 4
  br label %69

58:                                               ; preds = %49
  %59 = load i32, ptr %9, align 4, !tbaa !11
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %9, align 4, !tbaa !11
  %61 = load i32, ptr %9, align 4, !tbaa !11
  %62 = load i32, ptr %10, align 4, !tbaa !11
  %63 = icmp sge i32 %61, %62
  br i1 %63, label %64, label %68

64:                                               ; preds = %58
  store i8 0, ptr %7, align 1, !tbaa !9
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %"struct.SuffixTree::Edge", ptr %65, i32 0, i32 3
  %67 = load ptr, ptr %66, align 8, !tbaa !18
  store ptr %67, ptr %6, align 8, !tbaa !5
  store ptr null, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %68

68:                                               ; preds = %64, %58
  store i32 0, ptr %13, align 4
  br label %69

69:                                               ; preds = %68, %57, %38
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #3
  %70 = load i32, ptr %13, align 4
  switch i32 %70, label %75 [
    i32 0, label %71
  ]

71:                                               ; preds = %69
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %12, align 4, !tbaa !11
  %74 = add i32 %73, 1
  store i32 %74, ptr %12, align 4, !tbaa !11
  br label %17, !llvm.loop !19

75:                                               ; preds = %69, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %76 = load i32, ptr %13, align 4
  switch i32 %76, label %79 [
    i32 2, label %77
  ]

77:                                               ; preds = %75
  %78 = load i32, ptr %11, align 4, !tbaa !11
  store i32 %78, ptr %3, align 4
  store i32 1, ptr %13, align 4
  br label %79

79:                                               ; preds = %77, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %80 = load i32, ptr %3, align 4
  ret i32 %80
}

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN10SuffixTree4Node9find_edgeEc(ptr noundef nonnull align 8 dereferenceable(160), i8 noundef signext) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN10SuffixTree4Edge6lengthEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef signext i8 @_ZN10SuffixTree4EdgeixEj(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) #0 align 2

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!17, !12, i64 0}
!17 = !{!"_ZTSN10SuffixTree4EdgeE", !12, i64 0, !12, i64 4, !6, i64 8, !6, i64 16}
!18 = !{!17, !6, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"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"

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10SuffixTree6searchENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(248) %0, ptr noundef nonnull %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #2
  %.not5266.not = icmp eq i64 %3, 0
  br i1 %.not5266.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %26
  %5 = phi i64 [ %28, %26 ], [ 0, %.lr.ph.preheader ]
  %.02473 = phi i32 [ %27, %26 ], [ 0, %.lr.ph.preheader ]
  %.02572 = phi i32 [ %.227, %26 ], [ -1, %.lr.ph.preheader ]
  %.02971 = phi i32 [ %.130, %26 ], [ 0, %.lr.ph.preheader ]
  %.03270 = phi i32 [ %.335.ph, %26 ], [ 0, %.lr.ph.preheader ]
  %.03669 = phi ptr [ %.339.ph, %26 ], [ null, %.lr.ph.preheader ]
  %.04068 = phi i8 [ %.343.ph, %26 ], [ 0, %.lr.ph.preheader ]
  %.04467 = phi ptr [ %.246.ph, %26 ], [ %4, %.lr.ph.preheader ]
  %6 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %1, i64 noundef %5)
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = and i8 %.04068, 1
  %9 = icmp eq i8 %8, 0
  br i1 %9, label %10, label %19

10:                                               ; preds = %.lr.ph
  %11 = tail call noundef ptr @_ZN10SuffixTree4Node9find_edgeEc(ptr noundef nonnull align 8 dereferenceable(160) %.04467, i8 noundef signext %7)
  %12 = icmp eq ptr %11, null
  br i1 %12, label %._crit_edge, label %13

13:                                               ; preds = %10
  %14 = icmp eq i32 %.02473, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %13
  %16 = load i32, ptr %11, align 8, !tbaa !8
  br label %17

17:                                               ; preds = %15, %13
  %.126 = phi i32 [ %16, %15 ], [ %.02572, %13 ]
  %18 = tail call noundef i32 @_ZN10SuffixTree4Edge6lengthEv(ptr noundef nonnull align 8 dereferenceable(24) %11)
  br label %19

19:                                               ; preds = %17, %.lr.ph
  %.141 = phi i8 [ 1, %17 ], [ %.04068, %.lr.ph ]
  %.137 = phi ptr [ %11, %17 ], [ %.03669, %.lr.ph ]
  %.133 = phi i32 [ 0, %17 ], [ %.03270, %.lr.ph ]
  %.130 = phi i32 [ %18, %17 ], [ %.02971, %.lr.ph ]
  %.227 = phi i32 [ %.126, %17 ], [ %.02572, %.lr.ph ]
  %20 = tail call noundef signext i8 @_ZN10SuffixTree4EdgeixEj(ptr noundef nonnull align 8 dereferenceable(24) %.137, i32 noundef %.133)
  %.not = icmp eq i8 %7, %20
  br i1 %.not, label %21, label %._crit_edge

21:                                               ; preds = %19
  %22 = add nsw i32 %.133, 1
  %.not51 = icmp slt i32 %22, %.130
  br i1 %.not51, label %26, label %23

23:                                               ; preds = %21
  %24 = getelementptr inbounds i8, ptr %.137, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  br label %26

26:                                               ; preds = %23, %21
  %.246.ph = phi ptr [ %.04467, %21 ], [ %25, %23 ]
  %.343.ph = phi i8 [ %.141, %21 ], [ 0, %23 ]
  %.339.ph = phi ptr [ %.137, %21 ], [ null, %23 ]
  %.335.ph = phi i32 [ %22, %21 ], [ 0, %23 ]
  %27 = add i32 %.02473, 1
  %28 = zext i32 %27 to i64
  %29 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #2
  %.not52 = icmp ugt i64 %29, %28
  br i1 %.not52, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %26, %19, %10, %2
  %spec.select = phi i32 [ -1, %2 ], [ -1, %10 ], [ -1, %19 ], [ %.227, %26 ]
  ret i32 %spec.select
}

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN10SuffixTree4Edge6lengthEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

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

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" }
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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"_ZTSN10SuffixTree4EdgeE", !10, i64 0, !10, i64 4, !11, i64 8, !11, i64 16}
!10 = !{!"int", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!9, !11, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass