; LLVM IR from ShahjalalShohag/code-library :: Strings/Suffix Automaton Distinct Substring Queries in Range.ll (ZN3lct5splayEi)

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

@_ZN3lct3parE = external dso_local global [200018 x i32], align 16
@_ZN3lct1cE = external dso_local global [200018 x [2 x i32]], align 16
@_ZZN3lct5splayEiE2st = external hidden global [100009 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3lct4pushEi(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3lct7is_rootEi(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3lct6rotateEi(i32 noundef) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3lct5splayEi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr %3, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100009 x i32], ptr @_ZZN3lct5splayEiE2st, i64 0, i64 %10
  store i32 %7, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %12 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %12, ptr %4, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %27, %1
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = call noundef zeroext i1 @_ZN3lct7is_rootEi(i32 noundef %14)
  %16 = xor i1 %15, true
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %32

18:                                               ; preds = %13
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [200018 x i32], ptr @_ZN3lct3parE, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [100009 x i32], ptr @_ZZN3lct5splayEiE2st, i64 0, i64 %25
  store i32 %22, ptr %26, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %18
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [200018 x i32], ptr @_ZN3lct3parE, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  store i32 %31, ptr %4, align 4, !tbaa !5
  br label %13, !llvm.loop !9

32:                                               ; preds = %17
  br label %33

33:                                               ; preds = %36, %32
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %42

36:                                               ; preds = %33
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %37 to i64
  %40 = getelementptr inbounds [100009 x i32], ptr @_ZZN3lct5splayEiE2st, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  call void @_ZN3lct4pushEi(i32 noundef %41)
  br label %33, !llvm.loop !11

42:                                               ; preds = %33
  br label %43

43:                                               ; preds = %82, %42
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = call noundef zeroext i1 @_ZN3lct7is_rootEi(i32 noundef %44)
  %46 = xor i1 %45, true
  br i1 %46, label %47, label %84

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [200018 x i32], ptr @_ZN3lct3parE, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  store i32 %51, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [200018 x i32], ptr @_ZN3lct3parE, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  store i32 %55, ptr %6, align 4, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = call noundef zeroext i1 @_ZN3lct7is_rootEi(i32 noundef %56)
  br i1 %57, label %82, label %58

58:                                               ; preds = %47
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [200018 x [2 x i32]], ptr @_ZN3lct1cE, i64 0, i64 %60
  %62 = getelementptr inbounds [2 x i32], ptr %61, i64 0, i64 1
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = icmp eq i32 %63, %64
  %66 = zext i1 %65 to i32
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [200018 x [2 x i32]], ptr @_ZN3lct1cE, i64 0, i64 %68
  %70 = getelementptr inbounds [2 x i32], ptr %69, i64 0, i64 1
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = icmp eq i32 %71, %72
  %74 = zext i1 %73 to i32
  %75 = icmp eq i32 %66, %74
  br i1 %75, label %76, label %78

76:                                               ; preds = %58
  %77 = load i32, ptr %5, align 4, !tbaa !5
  br label %80

78:                                               ; preds = %58
  %79 = load i32, ptr %2, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %78, %76
  %81 = phi i32 [ %77, %76 ], [ %79, %78 ]
  call void @_ZN3lct6rotateEi(i32 noundef %81)
  br label %82

82:                                               ; preds = %80, %47
  %83 = load i32, ptr %2, align 4, !tbaa !5
  call void @_ZN3lct6rotateEi(i32 noundef %83)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %43, !llvm.loop !12

84:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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

@_ZN3lct3parE = external dso_local local_unnamed_addr global [200018 x i32], align 16
@_ZN3lct1cE = external dso_local local_unnamed_addr global [200018 x [2 x i32]], align 16
@_ZZN3lct5splayEiE2st = external hidden local_unnamed_addr global [100009 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3lct4pushEi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3lct7is_rootEi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3lct6rotateEi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3lct5splayEi(i32 noundef %0) local_unnamed_addr #0 {
  store i32 %0, ptr getelementptr inbounds (i8, ptr @_ZZN3lct5splayEiE2st, i64 4), align 4, !tbaa !5
  %2 = tail call noundef zeroext i1 @_ZN3lct7is_rootEi(i32 noundef %0)
  br i1 %2, label %.preheader21.preheader, label %.lr.ph

.preheader21.preheader:                           ; preds = %.preheader21.loopexit, %1
  %indvars.iv27.ph = phi i64 [ %3, %.preheader21.loopexit ], [ 1, %1 ]
  br label %.preheader21

.preheader21.loopexit:                            ; preds = %.lr.ph
  %3 = and i64 %indvars.iv.next, 4294967295
  br label %.preheader21.preheader

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %1 ]
  %.02022 = phi i32 [ %6, %.lr.ph ], [ %0, %1 ]
  %4 = sext i32 %.02022 to i64
  %5 = getelementptr inbounds [200018 x i32], ptr @_ZN3lct3parE, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = getelementptr inbounds [100009 x i32], ptr @_ZZN3lct5splayEiE2st, i64 0, i64 %indvars.iv.next
  store i32 %6, ptr %7, align 4, !tbaa !5
  %8 = tail call noundef zeroext i1 @_ZN3lct7is_rootEi(i32 noundef %6)
  br i1 %8, label %.preheader21.loopexit, label %.lr.ph, !llvm.loop !9

.preheader:                                       ; preds = %.preheader21
  %9 = tail call noundef zeroext i1 @_ZN3lct7is_rootEi(i32 noundef %0)
  br i1 %9, label %._crit_edge, label %.lr.ph25

.lr.ph25:                                         ; preds = %.preheader
  %10 = sext i32 %0 to i64
  %11 = getelementptr inbounds [200018 x i32], ptr @_ZN3lct3parE, i64 0, i64 %10
  br label %15

.preheader21:                                     ; preds = %.preheader21.preheader, %.preheader21
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %.preheader21 ], [ %indvars.iv27.ph, %.preheader21.preheader ]
  %indvars.iv.next28 = add nsw i64 %indvars.iv27, -1
  %12 = getelementptr inbounds [100009 x i32], ptr @_ZZN3lct5splayEiE2st, i64 0, i64 %indvars.iv27
  %13 = load i32, ptr %12, align 4, !tbaa !5
  tail call void @_ZN3lct4pushEi(i32 noundef %13)
  %14 = icmp eq i64 %indvars.iv.next28, 0
  br i1 %14, label %.preheader, label %.preheader21, !llvm.loop !11

15:                                               ; preds = %.lr.ph25, %31
  %16 = load i32, ptr %11, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [200018 x i32], ptr @_ZN3lct3parE, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = tail call noundef zeroext i1 @_ZN3lct7is_rootEi(i32 noundef %16)
  br i1 %20, label %31, label %21

21:                                               ; preds = %15
  %22 = getelementptr inbounds [200018 x [2 x i32]], ptr @_ZN3lct1cE, i64 0, i64 %17, i64 1
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp eq i32 %23, %0
  %25 = sext i32 %19 to i64
  %26 = getelementptr inbounds [200018 x [2 x i32]], ptr @_ZN3lct1cE, i64 0, i64 %25, i64 1
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp ne i32 %27, %16
  %29 = xor i1 %24, %28
  %30 = select i1 %29, i32 %16, i32 %0
  tail call void @_ZN3lct6rotateEi(i32 noundef %30)
  br label %31

31:                                               ; preds = %21, %15
  tail call void @_ZN3lct6rotateEi(i32 noundef %0)
  %32 = tail call noundef zeroext i1 @_ZN3lct7is_rootEi(i32 noundef %0)
  br i1 %32, label %._crit_edge, label %15, !llvm.loop !12

._crit_edge:                                      ; preds = %31, %.preheader
  ret void
}

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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