; LLVM IR from ayush-tulsyan/ACM-ICPC-Handbook :: code/SuffixTree.ll (Z19setSuffixIndexByDFSP14SuffixTreeNodei)

; 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
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; 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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z10edgeLengthP14SuffixTreeNode(ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5printii(i32 noundef, i32 noundef) #2

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_Z19setSuffixIndexByDFSP14SuffixTreeNodei(ptr noundef %0, i32 noundef %1) #2 {
  %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 %82

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.SuffixTreeNode, ptr %11, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp ne i32 %13, -1
  br i1 %14, label %15, label %23

15:                                               ; preds = %10
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SuffixTreeNode, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.SuffixTreeNode, ptr %19, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = load i32, ptr %21, align 4, !tbaa !9
  call void @_Z5printii(i32 noundef %18, i32 noundef %22)
  br label %23

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

24:                                               ; preds = %65, %23
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 256
  br i1 %26, label %27, label %68

27:                                               ; preds = %24
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.SuffixTreeNode, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [256 x ptr], ptr %29, i64 0, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %64

35:                                               ; preds = %27
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = icmp eq i32 %36, 1
  br i1 %37, label %38, label %48

38:                                               ; preds = %35
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.SuffixTreeNode, ptr %39, i32 0, i32 2
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = icmp ne i32 %41, -1
  br i1 %42, label %43, label %48

43:                                               ; preds = %38
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.SuffixTreeNode, ptr %44, i32 0, i32 4
  %46 = load i32, ptr %45, align 8, !tbaa !14
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %46)
  br label %48

48:                                               ; preds = %43, %38, %35
  store i32 0, ptr %5, align 4, !tbaa !9
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.SuffixTreeNode, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [256 x ptr], ptr %50, i64 0, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = load i32, ptr %4, align 4, !tbaa !9
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.SuffixTreeNode, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [256 x ptr], ptr %57, i64 0, i64 %59
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = call noundef i32 @_Z10edgeLengthP14SuffixTreeNode(ptr noundef %61)
  %63 = add nsw i32 %55, %62
  call void @_Z19setSuffixIndexByDFSP14SuffixTreeNodei(ptr noundef %54, i32 noundef %63)
  br label %64

64:                                               ; preds = %48, %27
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %6, align 4, !tbaa !9
  br label %24, !llvm.loop !15

68:                                               ; preds = %24
  %69 = load i32, ptr %5, align 4, !tbaa !9
  %70 = icmp eq i32 %69, 1
  br i1 %70, label %71, label %81

71:                                               ; preds = %68
  %72 = load i32, ptr @size, align 4, !tbaa !9
  %73 = load i32, ptr %4, align 4, !tbaa !9
  %74 = sub nsw i32 %72, %73
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.SuffixTreeNode, ptr %75, i32 0, i32 4
  store i32 %74, ptr %76, align 8, !tbaa !14
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.SuffixTreeNode, ptr %77, i32 0, i32 4
  %79 = load i32, ptr %78, align 8, !tbaa !14
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %79)
  br label %81

81:                                               ; preds = %71, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %82

82:                                               ; preds = %81, %9
  ret void
}

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 = { 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 #3 = { "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 }

!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 2056}
!12 = !{!"_ZTS14SuffixTreeNode", !7, i64 0, !6, i64 2048, !10, i64 2056, !6, i64 2064, !10, i64 2072}
!13 = !{!12, !6, i64 2064}
!14 = !{!12, !10, i64 2072}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@size = external dso_local local_unnamed_addr global i32, align 4
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5printii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z19setSuffixIndexByDFSP14SuffixTreeNodei(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %.thread31, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 2056
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i32 %6, -1
  br i1 %.not, label %11, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 2064
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = load i32, ptr %9, align 4, !tbaa !12
  tail call void @_Z5printii(i32 noundef %6, i32 noundef %10)
  br label %11

11:                                               ; preds = %7, %4
  %12 = getelementptr inbounds i8, ptr %0, i64 2072
  br label %.outer

.outer:                                           ; preds = %.thread, %11
  %indvars.iv.ph = phi i64 [ %indvars.iv.next28, %.thread ], [ 0, %11 ]
  %13 = phi i1 [ false, %.thread ], [ true, %11 ]
  br label %14

14:                                               ; preds = %.outer, %24
  %indvars.iv = phi i64 [ %indvars.iv.next, %24 ], [ %indvars.iv.ph, %.outer ]
  %15 = getelementptr inbounds [256 x ptr], ptr %0, i64 0, i64 %indvars.iv
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %.not22 = icmp eq ptr %16, null
  br i1 %.not22, label %24, label %17

17:                                               ; preds = %14
  %18 = getelementptr inbounds [256 x ptr], ptr %0, i64 0, i64 %indvars.iv
  br i1 %13, label %19, label %.thread

19:                                               ; preds = %17
  %20 = load i32, ptr %5, align 8, !tbaa !5
  %.not23 = icmp eq i32 %20, -1
  br i1 %.not23, label %.thread, label %21

21:                                               ; preds = %19
  %22 = load i32, ptr %12, align 8, !tbaa !14
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %22)
  %.pre = load ptr, ptr %18, align 8, !tbaa !13
  br label %.thread

24:                                               ; preds = %14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 256
  br i1 %exitcond.not, label %28, label %14, !llvm.loop !15

.thread:                                          ; preds = %17, %19, %21
  %25 = phi ptr [ %.pre, %21 ], [ %16, %19 ], [ %16, %17 ]
  %26 = tail call noundef i32 @_Z10edgeLengthP14SuffixTreeNode(ptr noundef %25)
  %27 = add nsw i32 %26, %1
  tail call void @_Z19setSuffixIndexByDFSP14SuffixTreeNodei(ptr noundef %25, i32 noundef %27)
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not29 = icmp eq i64 %indvars.iv.next28, 256
  br i1 %exitcond.not29, label %.thread31, label %.outer, !llvm.loop !15

28:                                               ; preds = %24
  br i1 %13, label %29, label %.thread31

29:                                               ; preds = %28
  %30 = load i32, ptr @size, align 4, !tbaa !12
  %31 = sub nsw i32 %30, %1
  store i32 %31, ptr %12, align 8, !tbaa !14
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %31)
  br label %.thread31

.thread31:                                        ; preds = %.thread, %28, %29, %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 = { 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 #2 = { nofree nounwind "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, !10, i64 2056}
!6 = !{!"_ZTS14SuffixTreeNode", !7, i64 0, !9, i64 2048, !10, i64 2056, !9, i64 2064, !10, i64 2072}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!6, !9, i64 2064}
!12 = !{!10, !10, i64 0}
!13 = !{!9, !9, i64 0}
!14 = !{!6, !10, i64 2072}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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