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

%struct.SuffixTreeNode = type { [256 x ptr], ptr, i32, ptr, i32 }

@size = external dso_local global i32, align 4

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

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

; Function Attrs: nounwind uwtable
define dso_local void @setSuffixIndexByDFS(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  br label %65

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

11:                                               ; preds = %52, %10
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 256
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %55

15:                                               ; preds = %11
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SuffixTreeNode, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [256 x ptr], ptr %17, i64 0, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %51

23:                                               ; preds = %15
  store i32 0, ptr %5, align 4, !tbaa !9
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SuffixTreeNode, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [256 x ptr], ptr %25, i64 0, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !9
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.SuffixTreeNode, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [256 x ptr], ptr %32, i64 0, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SuffixTreeNode, ptr %36, i32 0, i32 3
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = add nsw i32 %30, %39
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.SuffixTreeNode, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [256 x ptr], ptr %42, i64 0, i64 %44
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.SuffixTreeNode, ptr %46, i32 0, i32 2
  %48 = load i32, ptr %47, align 8, !tbaa !13
  %49 = sub nsw i32 %40, %48
  %50 = add nsw i32 %49, 1
  call void @setSuffixIndexByDFS(ptr noundef %29, i32 noundef %50)
  br label %51

51:                                               ; preds = %23, %15
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %6, align 4, !tbaa !9
  br label %11, !llvm.loop !14

55:                                               ; preds = %14
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = icmp eq i32 %56, 1
  br i1 %57, label %58, label %64

58:                                               ; preds = %55
  %59 = load i32, ptr @size, align 4, !tbaa !9
  %60 = load i32, ptr %4, align 4, !tbaa !9
  %61 = sub nsw i32 %59, %60
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.SuffixTreeNode, ptr %62, i32 0, i32 4
  store i32 %61, ptr %63, align 8, !tbaa !16
  br label %64

64:                                               ; preds = %58, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %65

65:                                               ; preds = %64, %9
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 2064}
!12 = !{!"SuffixTreeNode", !7, i64 0, !6, i64 2048, !10, i64 2056, !6, i64 2064, !10, i64 2072}
!13 = !{!12, !10, i64 2056}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!12, !10, i64 2072}


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

@size = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nofree nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @setSuffixIndexByDFS(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %.thread24, label %.preheader

.preheader:                                       ; preds = %2
  %4 = add i32 %1, 1
  br label %.outer

.outer:                                           ; preds = %.thread, %.preheader
  %indvars.iv.ph = phi i64 [ %indvars.iv.next21, %.thread ], [ 0, %.preheader ]
  %5 = phi i1 [ false, %.thread ], [ true, %.preheader ]
  br label %7

6:                                                ; preds = %10
  br i1 %5, label %18, label %.thread24

7:                                                ; preds = %.outer, %10
  %indvars.iv = phi i64 [ %indvars.iv.next, %10 ], [ %indvars.iv.ph, %.outer ]
  %8 = getelementptr inbounds [256 x ptr], ptr %0, i64 0, i64 %indvars.iv
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %10, label %.thread

10:                                               ; preds = %7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 256
  br i1 %exitcond.not, label %6, label %7, !llvm.loop !9

.thread:                                          ; preds = %7
  %11 = getelementptr inbounds i8, ptr %9, i64 2064
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load i32, ptr %12, align 4, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %9, i64 2056
  %15 = load i32, ptr %14, align 8, !tbaa !15
  %16 = add i32 %4, %13
  %17 = sub i32 %16, %15
  tail call void @setSuffixIndexByDFS(ptr noundef nonnull %9, i32 noundef %17)
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not22 = icmp eq i64 %indvars.iv.next21, 256
  br i1 %exitcond.not22, label %.thread24, label %.outer, !llvm.loop !9

18:                                               ; preds = %6
  %19 = load i32, ptr @size, align 4, !tbaa !14
  %20 = sub nsw i32 %19, %1
  %21 = getelementptr inbounds i8, ptr %0, i64 2072
  store i32 %20, ptr %21, align 8, !tbaa !16
  br label %.thread24

.thread24:                                        ; preds = %.thread, %6, %18, %2
  ret void
}

attributes #0 = { nofree nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 2064}
!12 = !{!"SuffixTreeNode", !7, i64 0, !6, i64 2048, !13, i64 2056, !6, i64 2064, !13, i64 2072}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 2056}
!16 = !{!12, !13, i64 2072}


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