; LLVM IR from Dev-XYS/Algorithms :: Longest-Common-Substring.ll (Z11init_heightv)

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

@l = external dso_local global i32, align 4
@s = external dso_local global [300000 x i8], align 16
@rank = external dso_local global [600000 x i32], align 16
@sa = external dso_local global [300000 x i32], align 16
@height = external dso_local global [300000 x i32], align 16

; 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
define dso_local void @_Z11init_heightv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %58, %0
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @l, align 4, !tbaa !5
  %6 = icmp slt i32 %4, %5
  br i1 %6, label %8, label %7

7:                                                ; preds = %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %61

8:                                                ; preds = %3
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %8
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = add nsw i32 %12, -1
  store i32 %13, ptr %1, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %11, %8
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [600000 x i32], ptr @rank, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = load i32, ptr @l, align 4, !tbaa !5
  %20 = icmp eq i32 %18, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %14
  br label %58

22:                                               ; preds = %14
  br label %23

23:                                               ; preds = %47, %22
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = add nsw i32 %24, %25
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [300000 x i8], ptr @s, i64 0, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = sext i8 %29 to i32
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [600000 x i32], ptr @rank, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [300000 x i32], ptr @sa, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = load i32, ptr %1, align 4, !tbaa !5
  %40 = add nsw i32 %38, %39
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [300000 x i8], ptr @s, i64 0, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !9
  %44 = sext i8 %43 to i32
  %45 = icmp eq i32 %30, %44
  br i1 %45, label %46, label %50

46:                                               ; preds = %23
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %1, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %1, align 4, !tbaa !5
  br label %23, !llvm.loop !10

50:                                               ; preds = %23
  %51 = load i32, ptr %1, align 4, !tbaa !5
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [600000 x i32], ptr @rank, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [300000 x i32], ptr @height, i64 0, i64 %56
  store i32 %51, ptr %57, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %50, %21
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %2, align 4, !tbaa !5
  br label %3, !llvm.loop !12

61:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  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 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

@l = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local local_unnamed_addr global [300000 x i8], align 16
@rank = external dso_local local_unnamed_addr global [600000 x i32], align 16
@sa = external dso_local local_unnamed_addr global [300000 x i32], align 16
@height = external dso_local local_unnamed_addr global [300000 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z11init_heightv() local_unnamed_addr #0 {
  %1 = load i32, ptr @l, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %26, %0
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %26
  %indvars.iv16 = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next17, %26 ]
  %.01213 = phi i32 [ 0, %.lr.ph.preheader ], [ %.3, %26 ]
  %3 = icmp sgt i32 %.01213, 0
  %4 = sext i1 %3 to i32
  %spec.select = add i32 %.01213, %4
  %5 = getelementptr inbounds [600000 x i32], ptr @rank, i64 0, i64 %indvars.iv16
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, %1
  br i1 %7, label %26, label %.preheader

.preheader:                                       ; preds = %.lr.ph
  %8 = add nsw i32 %6, 1
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [300000 x i32], ptr @sa, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sext i32 %spec.select to i64
  %13 = sext i32 %11 to i64
  br label %14

14:                                               ; preds = %14, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next, %14 ], [ %12, %.preheader ]
  %15 = add nsw i64 %indvars.iv, %indvars.iv16
  %16 = getelementptr inbounds [300000 x i8], ptr @s, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = add nsw i64 %indvars.iv, %13
  %19 = getelementptr inbounds [300000 x i8], ptr @s, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = icmp eq i8 %17, %20
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  br i1 %21, label %14, label %22, !llvm.loop !10

22:                                               ; preds = %14
  %23 = trunc nsw i64 %indvars.iv to i32
  %24 = sext i32 %6 to i64
  %25 = getelementptr inbounds [300000 x i32], ptr @height, i64 0, i64 %24
  store i32 %23, ptr %25, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %.lr.ph, %22
  %.3 = phi i32 [ %spec.select, %.lr.ph ], [ %23, %22 ]
  %indvars.iv.next17 = add nuw nsw i64 %indvars.iv16, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next17, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12
}

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


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