; LLVM IR from xtaci/algorithms :: src/suffix_array_demo.ll (ZN3alg11SuffixArray10lcp_lengthEii)

; 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.alg::SuffixArray" = type { %"class.std::vector", %"class.std::vector.0", i32, i32, i32, ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::vector<int>, std::allocator<std::vector<int>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::vector<int>, std::allocator<std::vector<int>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::vector<int>, std::allocator<std::vector<int>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::vector<int>, std::allocator<std::vector<int>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; 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 nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #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 nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3alg11SuffixArray10lcp_lengthEii(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %10 = load ptr, ptr %5, align 8
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp eq i32 %11, %12
  br i1 %13, label %14, label %19

14:                                               ; preds = %3
  %15 = getelementptr inbounds %"class.alg::SuffixArray", ptr %10, i32 0, i32 2
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = sub nsw i32 %16, %17
  store i32 %18, ptr %4, align 4
  br label %76

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %20 = getelementptr inbounds %"class.alg::SuffixArray", ptr %10, i32 0, i32 4
  %21 = load i32, ptr %20, align 8, !tbaa !21
  %22 = sub nsw i32 %21, 1
  store i32 %22, ptr %9, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %71, %19
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = icmp sge i32 %24, 0
  br i1 %25, label %26, label %36

26:                                               ; preds = %23
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = getelementptr inbounds %"class.alg::SuffixArray", ptr %10, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = icmp slt i32 %27, %29
  br i1 %30, label %31, label %36

31:                                               ; preds = %26
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = getelementptr inbounds %"class.alg::SuffixArray", ptr %10, i32 0, i32 2
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = icmp slt i32 %32, %34
  br label %36

36:                                               ; preds = %31, %26, %23
  %37 = phi i1 [ false, %26 ], [ false, %23 ], [ %35, %31 ]
  br i1 %37, label %39, label %38

38:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %74

39:                                               ; preds = %36
  %40 = getelementptr inbounds %"class.alg::SuffixArray", ptr %10, i32 0, i32 0
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %40, i64 noundef %42) #2
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %43, i64 noundef %45) #2
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = getelementptr inbounds %"class.alg::SuffixArray", ptr %10, i32 0, i32 0
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %48, i64 noundef %50) #2
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %51, i64 noundef %53) #2
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = icmp eq i32 %47, %55
  br i1 %56, label %57, label %70

57:                                               ; preds = %39
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = shl i32 1, %58
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = add nsw i32 %60, %59
  store i32 %61, ptr %6, align 4, !tbaa !9
  %62 = load i32, ptr %9, align 4, !tbaa !9
  %63 = shl i32 1, %62
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = add nsw i32 %64, %63
  store i32 %65, ptr %7, align 4, !tbaa !9
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = shl i32 1, %66
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = add nsw i32 %68, %67
  store i32 %69, ptr %8, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %57, %39
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = add nsw i32 %72, -1
  store i32 %73, ptr %9, align 4, !tbaa !9
  br label %23, !llvm.loop !22

74:                                               ; preds = %38
  %75 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %75, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %76

76:                                               ; preds = %74, %14
  %77 = load i32, ptr %4, align 4
  ret i32 %77
}

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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 48}
!12 = !{!"_ZTSN3alg11SuffixArrayE", !13, i64 0, !17, i64 24, !10, i64 48, !10, i64 52, !10, i64 56, !6, i64 64}
!13 = !{!"_ZTSSt6vectorIS_IiSaIiEESaIS1_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseISt6vectorIiSaIiEESaIS2_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseISt6vectorIiSaIiEESaIS2_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseISt6vectorIiSaIiEESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"_ZTSSt6vectorIiSaIiEE", !18, i64 0}
!18 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = !{!12, !10, i64 56}
!22 = distinct !{!22, !23}
!23 = !{!"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 nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3alg11SuffixArray10lcp_lengthEii(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = icmp eq i32 %1, %2
  br i1 %4, label %5, label %9

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = sub nsw i32 %7, %1
  br label %.critedge

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 56
  %11 = load i32, ptr %10, align 8, !tbaa !19
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 48
  %14 = zext nneg i32 %11 to i64
  br label %15

15:                                               ; preds = %.lr.ph, %19
  %indvars.iv = phi i64 [ %14, %.lr.ph ], [ %indvars.iv.next, %19 ]
  %.01932 = phi i32 [ 0, %.lr.ph ], [ %.1, %19 ]
  %.02031 = phi i32 [ %2, %.lr.ph ], [ %.121, %19 ]
  %.02230 = phi i32 [ %1, %.lr.ph ], [ %.123, %19 ]
  %16 = load i32, ptr %13, align 8, !tbaa !5
  %17 = icmp slt i32 %.02230, %16
  %18 = icmp slt i32 %.02031, %16
  %or.cond = select i1 %17, i1 %18, i1 false
  br i1 %or.cond, label %19, label %.critedge

19:                                               ; preds = %15
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %20 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv.next) #1
  %21 = sext i32 %.02230 to i64
  %22 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %20, i64 noundef %21) #1
  %23 = load i32, ptr %22, align 4, !tbaa !20
  %24 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv.next) #1
  %25 = sext i32 %.02031 to i64
  %26 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %24, i64 noundef %25) #1
  %27 = load i32, ptr %26, align 4, !tbaa !20
  %28 = icmp eq i32 %23, %27
  %29 = trunc nuw nsw i64 %indvars.iv.next to i32
  %30 = shl nuw i32 1, %29
  %31 = select i1 %28, i32 %30, i32 0
  %.123 = add nsw i32 %31, %.02230
  %.121 = add nsw i32 %31, %.02031
  %.1 = add nsw i32 %31, %.01932
  %32 = icmp sgt i64 %indvars.iv, 1
  br i1 %32, label %15, label %.critedge, !llvm.loop !21

.critedge:                                        ; preds = %15, %19, %9, %5
  %.024 = phi i32 [ %8, %5 ], [ 0, %9 ], [ %.01932, %15 ], [ %.1, %19 ]
  ret i32 %.024
}

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 = { 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, !18, i64 48}
!6 = !{!"_ZTSN3alg11SuffixArrayE", !7, i64 0, !14, i64 24, !18, i64 48, !18, i64 52, !18, i64 56, !11, i64 64}
!7 = !{!"_ZTSSt6vectorIS_IiSaIiEESaIS1_EE", !8, i64 0}
!8 = !{!"_ZTSSt12_Vector_baseISt6vectorIiSaIiEESaIS2_EE", !9, i64 0}
!9 = !{!"_ZTSNSt12_Vector_baseISt6vectorIiSaIiEESaIS2_EE12_Vector_implE", !10, i64 0}
!10 = !{!"_ZTSNSt12_Vector_baseISt6vectorIiSaIiEESaIS2_EE17_Vector_impl_dataE", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"_ZTSSt6vectorIiSaIiEE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !11, i64 0, !11, i64 8, !11, i64 16}
!18 = !{!"int", !12, i64 0}
!19 = !{!6, !18, i64 56}
!20 = !{!18, !18, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass