; LLVM IR from AlgoGenesis/C :: Searching Algorithms/Ukkonen's Algorithm (Program)

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

@root = external dso_local global ptr, align 8
@activeNode = external dso_local global ptr, align 8
@rootEnd = external dso_local global ptr, align 8
@size = external dso_local global i32, align 4
@text = external dso_local global [1000 x i8], align 16

; Function Attrs: nounwind uwtable
declare dso_local ptr @newNode(i32 noundef, ptr 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @setSuffixIndexByDFS(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @buildSuffixTree() #0 {
  %1 = alloca i32, align 4
  %2 = call i64 @strlen(ptr noundef @text) #4
  %3 = trunc i64 %2 to i32
  store i32 %3, ptr @size, align 4, !tbaa !5
  %4 = call noalias ptr @malloc(i64 noundef 4) #5
  store ptr %4, ptr @rootEnd, align 8, !tbaa !9
  %5 = load ptr, ptr @rootEnd, align 8, !tbaa !9
  store i32 -1, ptr %5, align 4, !tbaa !5
  %6 = load ptr, ptr @rootEnd, align 8, !tbaa !9
  %7 = call ptr @newNode(i32 noundef -1, ptr noundef %6)
  store ptr %7, ptr @root, align 8, !tbaa !9
  %8 = load ptr, ptr @root, align 8, !tbaa !9
  store ptr %8, ptr @activeNode, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #6
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %16, %0
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = load i32, ptr @size, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #6
  br label %19

14:                                               ; preds = %9
  %15 = load i32, ptr %1, align 4, !tbaa !5
  call void @extendSuffixTree(i32 noundef %15)
  br label %16

16:                                               ; preds = %14
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %1, align 4, !tbaa !5
  br label %9, !llvm.loop !11

19:                                               ; preds = %13
  %20 = load ptr, ptr @root, align 8, !tbaa !9
  call void @setSuffixIndexByDFS(ptr noundef %20, i32 noundef 0)
  ret void
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

attributes #0 = { 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 allocsize(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 willreturn memory(read) "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 willreturn memory(read) }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@root = external dso_local local_unnamed_addr global ptr, align 8
@activeNode = external dso_local local_unnamed_addr global ptr, align 8
@rootEnd = external dso_local local_unnamed_addr global ptr, align 8
@size = external dso_local local_unnamed_addr global i32, align 4
@text = external dso_local global [1000 x i8], align 16

; Function Attrs: nounwind uwtable
declare dso_local ptr @newNode(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @setSuffixIndexByDFS(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @buildSuffixTree() local_unnamed_addr #0 {
  %1 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @text) #3
  %2 = trunc i64 %1 to i32
  store i32 %2, ptr @size, align 4, !tbaa !5
  %3 = tail call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #4
  store ptr %3, ptr @rootEnd, align 8, !tbaa !9
  store i32 -1, ptr %3, align 4, !tbaa !5
  %4 = tail call ptr @newNode(i32 noundef -1, ptr noundef nonnull %3)
  store ptr %4, ptr @root, align 8, !tbaa !9
  store ptr %4, ptr @activeNode, align 8, !tbaa !9
  %5 = load i32, ptr @size, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load ptr, ptr @root, align 8, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %7 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ %4, %0 ]
  tail call void @setSuffixIndexByDFS(ptr noundef %7, i32 noundef 0)
  ret void

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.03 = phi i32 [ %8, %.lr.ph ], [ 0, %0 ]
  tail call void @extendSuffixTree(i32 noundef %.03)
  %8 = add nuw nsw i32 %.03, 1
  %9 = load i32, ptr @size, align 4, !tbaa !5
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !11
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }
attributes #4 = { nounwind allocsize(0) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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