; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/dp/maxSquareMatrixWithOnes.ll (Z21maxSizeSquareWithOnesPPiiiiiS_S0_)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z21maxSizeSquareWithOnesPPiiiiiS_S0_(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef %6) #0 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !9
  store i32 %2, ptr %11, align 4, !tbaa !9
  store i32 %3, ptr %12, align 4, !tbaa !9
  store i32 %4, ptr %13, align 4, !tbaa !9
  store ptr %5, ptr %14, align 8, !tbaa !5
  store ptr %6, ptr %15, align 8, !tbaa !5
  %20 = load i32, ptr %12, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %25, label %22

22:                                               ; preds = %7
  %23 = load i32, ptr %13, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %52

25:                                               ; preds = %22, %7
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds ptr, ptr %26, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = load i32, ptr %13, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %30, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = load ptr, ptr %15, align 8, !tbaa !5
  %36 = load i32, ptr %12, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds ptr, ptr %35, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = load i32, ptr %13, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %39, i64 %41
  store i32 %34, ptr %42, align 4, !tbaa !9
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = load i32, ptr %12, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds ptr, ptr %43, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = load i32, ptr %13, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %47, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !9
  store i32 %51, ptr %8, align 4
  br label %152

52:                                               ; preds = %22
  %53 = load i32, ptr %12, align 4, !tbaa !9
  %54 = icmp slt i32 %53, 0
  br i1 %54, label %58, label %55

55:                                               ; preds = %52
  %56 = load i32, ptr %13, align 4, !tbaa !9
  %57 = icmp slt i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %55, %52
  store i32 2147483647, ptr %8, align 4
  br label %152

59:                                               ; preds = %55
  %60 = load ptr, ptr %15, align 8, !tbaa !5
  %61 = load i32, ptr %12, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds ptr, ptr %60, i64 %62
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = load i32, ptr %13, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr %64, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !9
  %69 = icmp sgt i32 %68, -1
  br i1 %69, label %70, label %80

70:                                               ; preds = %59
  %71 = load ptr, ptr %15, align 8, !tbaa !5
  %72 = load i32, ptr %12, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds ptr, ptr %71, i64 %73
  %75 = load ptr, ptr %74, align 8, !tbaa !5
  %76 = load i32, ptr %13, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i32, ptr %75, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !9
  store i32 %79, ptr %8, align 4
  br label %152

80:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = load i32, ptr %10, align 4, !tbaa !9
  %83 = load i32, ptr %11, align 4, !tbaa !9
  %84 = load i32, ptr %12, align 4, !tbaa !9
  %85 = sub nsw i32 %84, 1
  %86 = load i32, ptr %13, align 4, !tbaa !9
  %87 = load ptr, ptr %14, align 8, !tbaa !5
  %88 = load ptr, ptr %15, align 8, !tbaa !5
  %89 = call noundef i32 @_Z21maxSizeSquareWithOnesPPiiiiiS_S0_(ptr noundef %81, i32 noundef %82, i32 noundef %83, i32 noundef %85, i32 noundef %86, ptr noundef %87, ptr noundef %88)
  store i32 %89, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  %91 = load i32, ptr %10, align 4, !tbaa !9
  %92 = load i32, ptr %11, align 4, !tbaa !9
  %93 = load i32, ptr %12, align 4, !tbaa !9
  %94 = sub nsw i32 %93, 1
  %95 = load i32, ptr %13, align 4, !tbaa !9
  %96 = sub nsw i32 %95, 1
  %97 = load ptr, ptr %14, align 8, !tbaa !5
  %98 = load ptr, ptr %15, align 8, !tbaa !5
  %99 = call noundef i32 @_Z21maxSizeSquareWithOnesPPiiiiiS_S0_(ptr noundef %90, i32 noundef %91, i32 noundef %92, i32 noundef %94, i32 noundef %96, ptr noundef %97, ptr noundef %98)
  store i32 %99, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %100 = load ptr, ptr %9, align 8, !tbaa !5
  %101 = load i32, ptr %10, align 4, !tbaa !9
  %102 = load i32, ptr %11, align 4, !tbaa !9
  %103 = load i32, ptr %12, align 4, !tbaa !9
  %104 = load i32, ptr %13, align 4, !tbaa !9
  %105 = sub nsw i32 %104, 1
  %106 = load ptr, ptr %14, align 8, !tbaa !5
  %107 = load ptr, ptr %15, align 8, !tbaa !5
  %108 = call noundef i32 @_Z21maxSizeSquareWithOnesPPiiiiiS_S0_(ptr noundef %100, i32 noundef %101, i32 noundef %102, i32 noundef %103, i32 noundef %105, ptr noundef %106, ptr noundef %107)
  store i32 %108, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  %109 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %17, ptr noundef nonnull align 4 dereferenceable(4) %18)
  %110 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %16, ptr noundef nonnull align 4 dereferenceable(4) %109)
  %111 = load i32, ptr %110, align 4, !tbaa !9
  store i32 %111, ptr %19, align 4, !tbaa !9
  %112 = load ptr, ptr %9, align 8, !tbaa !5
  %113 = load i32, ptr %12, align 4, !tbaa !9
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds ptr, ptr %112, i64 %114
  %116 = load ptr, ptr %115, align 8, !tbaa !5
  %117 = load i32, ptr %13, align 4, !tbaa !9
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds i32, ptr %116, i64 %118
  %120 = load i32, ptr %119, align 4, !tbaa !9
  %121 = icmp eq i32 %120, 1
  br i1 %121, label %122, label %125

122:                                              ; preds = %80
  %123 = load i32, ptr %19, align 4, !tbaa !9
  %124 = add nsw i32 %123, 1
  store i32 %124, ptr %19, align 4, !tbaa !9
  br label %125

125:                                              ; preds = %122, %80
  %126 = load ptr, ptr %9, align 8, !tbaa !5
  %127 = load i32, ptr %12, align 4, !tbaa !9
  %128 = sext i32 %127 to i64
  %129 = getelementptr inbounds ptr, ptr %126, i64 %128
  %130 = load ptr, ptr %129, align 8, !tbaa !5
  %131 = load i32, ptr %13, align 4, !tbaa !9
  %132 = sext i32 %131 to i64
  %133 = getelementptr inbounds i32, ptr %130, i64 %132
  %134 = load i32, ptr %133, align 4, !tbaa !9
  %135 = icmp eq i32 %134, 0
  br i1 %135, label %136, label %137

136:                                              ; preds = %125
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %137

137:                                              ; preds = %136, %125
  %138 = load ptr, ptr %14, align 8, !tbaa !5
  %139 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %138, ptr noundef nonnull align 4 dereferenceable(4) %19)
  %140 = load i32, ptr %139, align 4, !tbaa !9
  %141 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 %140, ptr %141, align 4, !tbaa !9
  %142 = load i32, ptr %19, align 4, !tbaa !9
  %143 = load ptr, ptr %15, align 8, !tbaa !5
  %144 = load i32, ptr %12, align 4, !tbaa !9
  %145 = sext i32 %144 to i64
  %146 = getelementptr inbounds ptr, ptr %143, i64 %145
  %147 = load ptr, ptr %146, align 8, !tbaa !5
  %148 = load i32, ptr %13, align 4, !tbaa !9
  %149 = sext i32 %148 to i64
  %150 = getelementptr inbounds i32, ptr %147, i64 %149
  store i32 %142, ptr %150, align 4, !tbaa !9
  %151 = load i32, ptr %19, align 4, !tbaa !9
  store i32 %151, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %152

152:                                              ; preds = %137, %70, %58, %25
  %153 = load i32, ptr %8, align 4
  ret i32 %153
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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}


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z21maxSizeSquareWithOnesPPiiiiiS_S0_(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef %6) local_unnamed_addr #0 {
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = icmp eq i32 %3, 0
  %13 = icmp eq i32 %4, 0
  %or.cond = or i1 %12, %13
  br i1 %or.cond, label %14, label %24

14:                                               ; preds = %7
  %15 = sext i32 %3 to i64
  %16 = getelementptr inbounds ptr, ptr %0, i64 %15
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = sext i32 %4 to i64
  %19 = getelementptr inbounds i32, ptr %17, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = getelementptr inbounds ptr, ptr %6, i64 %15
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds i32, ptr %22, i64 %18
  store i32 %20, ptr %23, align 4, !tbaa !9
  br label %55

24:                                               ; preds = %7
  %25 = or i32 %4, %3
  %or.cond3.not = icmp sgt i32 %25, -1
  br i1 %or.cond3.not, label %26, label %55

26:                                               ; preds = %24
  %27 = zext nneg i32 %3 to i64
  %28 = getelementptr inbounds ptr, ptr %6, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = zext nneg i32 %4 to i64
  %31 = getelementptr inbounds i32, ptr %29, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = icmp sgt i32 %32, -1
  br i1 %33, label %55, label %34

34:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #3
  %35 = add nsw i32 %3, -1
  %36 = tail call noundef i32 @_Z21maxSizeSquareWithOnesPPiiiiiS_S0_(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %35, i32 noundef %4, ptr noundef %5, ptr noundef nonnull %6)
  store i32 %36, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #3
  %37 = add nsw i32 %4, -1
  %38 = tail call noundef i32 @_Z21maxSizeSquareWithOnesPPiiiiiS_S0_(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %35, i32 noundef %37, ptr noundef %5, ptr noundef nonnull %6)
  store i32 %38, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %10) #3
  %39 = tail call noundef i32 @_Z21maxSizeSquareWithOnesPPiiiiiS_S0_(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %37, ptr noundef %5, ptr noundef nonnull %6)
  store i32 %39, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %11) #3
  %40 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %40)
  %42 = load i32, ptr %41, align 4, !tbaa !9
  store i32 %42, ptr %11, align 4, !tbaa !9
  %43 = getelementptr inbounds ptr, ptr %0, i64 %27
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = getelementptr inbounds i32, ptr %44, i64 %30
  %46 = load i32, ptr %45, align 4, !tbaa !9
  switch i32 %46, label %49 [
    i32 1, label %.thread
    i32 0, label %48
  ]

.thread:                                          ; preds = %34
  %47 = add nsw i32 %42, 1
  store i32 %47, ptr %11, align 4, !tbaa !9
  br label %49

48:                                               ; preds = %34
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %34, %.thread, %48
  %50 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %51 = load i32, ptr %50, align 4, !tbaa !9
  store i32 %51, ptr %5, align 4, !tbaa !9
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = load ptr, ptr %28, align 8, !tbaa !5
  %54 = getelementptr inbounds i32, ptr %53, i64 %30
  store i32 %52, ptr %54, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #3
  br label %55

55:                                               ; preds = %26, %24, %49, %14
  %.0 = phi i32 [ %20, %14 ], [ %52, %49 ], [ 2147483647, %24 ], [ %32, %26 ]
  ret i32 %.0
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass