; LLVM IR from KSkun/OI-Templates :: string (suffix_array)

; 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.SuffixArray = type { [1000005 x i8], i32, i32, [1000005 x i32], [1000005 x i32], [1000005 x i32], [1000005 x i32], [1000005 x i32], [1000005 x i32] }

@sa = external dso_local global %struct.SuffixArray, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef getelementptr inbounds (i8, ptr @sa, i64 1))
  %4 = call i64 @strlen(ptr noundef getelementptr inbounds (i8, ptr @sa, i64 1)) #5
  %5 = trunc i64 %4 to i32
  store i32 %5, ptr getelementptr inbounds (%struct.SuffixArray, ptr @sa, i32 0, i32 1), align 4, !tbaa !5
  store i32 256, ptr getelementptr inbounds (%struct.SuffixArray, ptr @sa, i32 0, i32 2), align 4, !tbaa !10
  call void @_ZN11SuffixArray5calsaEv(ptr noundef nonnull align 4 dereferenceable(25000136) @sa)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 1, ptr %2, align 4, !tbaa !11
  br label %6

6:                                                ; preds = %17, %0
  %7 = load i32, ptr %2, align 4, !tbaa !11
  %8 = load i32, ptr getelementptr inbounds (%struct.SuffixArray, ptr @sa, i32 0, i32 1), align 4, !tbaa !5
  %9 = icmp sle i32 %7, %8
  br i1 %9, label %11, label %10

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

11:                                               ; preds = %6
  %12 = load i32, ptr %2, align 4, !tbaa !11
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [1000005 x i32], ptr getelementptr inbounds (%struct.SuffixArray, ptr @sa, i32 0, i32 3), i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %15)
  br label %17

17:                                               ; preds = %11
  %18 = load i32, ptr %2, align 4, !tbaa !11
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %2, align 4, !tbaa !11
  br label %6, !llvm.loop !12

20:                                               ; preds = %10
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN11SuffixArray5calsaEv(ptr noundef nonnull align 4 dereferenceable(25000136)) #3 align 2

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

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

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

attributes #0 = { mustprogress norecurse 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 = { "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 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 #3 = { inlinehint 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 #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind willreturn memory(read) }
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, !9, i64 1000008}
!6 = !{!"_ZTS11SuffixArray", !7, i64 0, !9, i64 1000008, !9, i64 1000012, !7, i64 1000016, !7, i64 5000036, !7, i64 9000056, !7, i64 13000076, !7, i64 17000096, !7, i64 21000116}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !9, i64 1000012}
!11 = !{!9, !9, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

%struct.SuffixArray = type { [1000005 x i8], i32, i32, [1000005 x i32], [1000005 x i32], [1000005 x i32], [1000005 x i32], [1000005 x i32], [1000005 x i32] }

@sa = external dso_local global %struct.SuffixArray, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @sa, i64 1))
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @sa, i64 1)) #4
  %3 = trunc i64 %2 to i32
  store i32 %3, ptr getelementptr inbounds (i8, ptr @sa, i64 1000008), align 4, !tbaa !5
  store i32 256, ptr getelementptr inbounds (i8, ptr @sa, i64 1000012), align 4, !tbaa !10
  tail call void @_ZN11SuffixArray5calsaEv(ptr noundef nonnull align 4 dereferenceable(25000136) @sa)
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @sa, i64 1000008), align 4, !tbaa !5
  %.not3 = icmp slt i32 %4, 1
  br i1 %.not3, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  ret i32 0

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %5 = getelementptr inbounds [1000005 x i32], ptr getelementptr inbounds (i8, ptr @sa, i64 1000016), i64 0, i64 %indvars.iv
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %6)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = load i32, ptr getelementptr inbounds (i8, ptr @sa, i64 1000008), align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %.not.not = icmp slt i64 %indvars.iv, %9
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !12
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN11SuffixArray5calsaEv(ptr noundef nonnull align 4 dereferenceable(25000136)) local_unnamed_addr #3 align 2

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

attributes #0 = { mustprogress norecurse 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 = { 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" }
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 = { inlinehint 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 #4 = { nounwind willreturn memory(read) }

!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, !9, i64 1000008}
!6 = !{!"_ZTS11SuffixArray", !7, i64 0, !9, i64 1000008, !9, i64 1000012, !7, i64 1000016, !7, i64 5000036, !7, i64 9000056, !7, i64 13000076, !7, i64 17000096, !7, i64 21000116}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !9, i64 1000012}
!11 = !{!9, !9, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass