; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: 2D Arrays/sum_of_all_submatrices.ll (Z19sum_all_submatricesSt6vectorIS_IiSaIiEESaIS1_EE)

; 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 nounwind uwtable
define dso_local noundef i32 @_Z19sum_all_submatricesSt6vectorIS_IiSaIiEESaIS1_EE(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %13 = call noundef i64 @_ZNKSt6vectorIS_IiSaIiEESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %15 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #2
  %16 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %15) #2
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, 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 %18

18:                                               ; preds = %87, %1
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %90

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %83, %23
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %86

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %30 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %30, ptr %9, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %79, %29
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %82

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %37 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %37, ptr %10, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %75, %36
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 11, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %78

43:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %44 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %44, ptr %11, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %71, %43
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = icmp sle i32 %46, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %45
  store i32 14, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %74

50:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %51 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %51, ptr %12, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %67, %50
  %53 = load i32, ptr %12, align 4, !tbaa !9
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = icmp sle i32 %53, %54
  br i1 %55, label %57, label %56

56:                                               ; preds = %52
  store i32 17, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %70

57:                                               ; preds = %52
  %58 = load i32, ptr %11, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %59) #2
  %61 = load i32, ptr %12, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %60, i64 noundef %62) #2
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = add nsw i32 %65, %64
  store i32 %66, ptr %5, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %57
  %68 = load i32, ptr %12, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %12, align 4, !tbaa !9
  br label %52, !llvm.loop !11

70:                                               ; preds = %56
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %11, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %11, align 4, !tbaa !9
  br label %45, !llvm.loop !13

74:                                               ; preds = %49
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %10, align 4, !tbaa !9
  br label %38, !llvm.loop !14

78:                                               ; preds = %42
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %9, align 4, !tbaa !9
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %9, align 4, !tbaa !9
  br label %31, !llvm.loop !15

82:                                               ; preds = %35
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %8, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %8, align 4, !tbaa !9
  br label %24, !llvm.loop !16

86:                                               ; preds = %28
  br label %87

87:                                               ; preds = %86
  %88 = load i32, ptr %6, align 4, !tbaa !9
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %6, align 4, !tbaa !9
  br label %18, !llvm.loop !17

90:                                               ; preds = %22
  %91 = load i32, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %91
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIS_IiSaIiEESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}


; 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 @_Z19sum_all_submatricesSt6vectorIS_IiSaIiEESaIS1_EE(ptr noundef nonnull %0) local_unnamed_addr #0 {
  %2 = tail call noundef i64 @_ZNKSt6vectorIS_IiSaIiEESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %3 = trunc i64 %2 to i32
  %4 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #1
  %5 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %4) #1
  %6 = icmp sgt i32 %3, 0
  %7 = trunc i64 %5 to i32
  %8 = icmp sgt i32 %7, 0
  %or.cond = and i1 %6, %8
  br i1 %or.cond, label %.preheader38.us.preheader, label %._crit_edge79

.preheader38.us.preheader:                        ; preds = %1
  %9 = add nuw nsw i64 %5, 1
  %10 = add nuw nsw i64 %2, 1
  %wide.trip.count129 = and i64 %2, 2147483647
  %wide.trip.count124 = and i64 %5, 2147483647
  %wide.trip.count = and i64 %10, 4294967295
  %wide.trip.count113 = and i64 %9, 4294967295
  br label %.preheader37.us.us.preheader

.preheader37.us.us.preheader:                     ; preds = %._crit_edge.us, %.preheader38.us.preheader
  %indvars.iv115 = phi i64 [ 1, %.preheader38.us.preheader ], [ %indvars.iv.next116, %._crit_edge.us ]
  %indvars.iv97 = phi i64 [ 0, %.preheader38.us.preheader ], [ %indvars.iv.next98, %._crit_edge.us ]
  %.03176.us = phi i32 [ 0, %.preheader38.us.preheader ], [ %.us-phi52.us.us.us, %._crit_edge.us ]
  %indvars128 = trunc i64 %indvars.iv97 to i32
  br label %.preheader36.us.us.us.preheader

._crit_edge.us:                                   ; preds = %._crit_edge56.us.us
  %indvars.iv.next98 = add nuw nsw i64 %indvars.iv97, 1
  %indvars.iv.next116 = add nuw nsw i64 %indvars.iv115, 1
  %exitcond130.not = icmp eq i64 %indvars.iv.next98, %wide.trip.count129
  br i1 %exitcond130.not, label %._crit_edge79, label %.preheader37.us.us.preheader, !llvm.loop !5

.preheader36.us.us.us.preheader:                  ; preds = %._crit_edge56.us.us, %.preheader37.us.us.preheader
  %indvars.iv108 = phi i64 [ 1, %.preheader37.us.us.preheader ], [ %indvars.iv.next109, %._crit_edge56.us.us ]
  %indvars.iv = phi i64 [ 0, %.preheader37.us.us.preheader ], [ %indvars.iv.next, %._crit_edge56.us.us ]
  %.168.us.us = phi i32 [ %.03176.us, %.preheader37.us.us.preheader ], [ %.us-phi52.us.us.us, %._crit_edge56.us.us ]
  %indvars123 = trunc i64 %indvars.iv to i32
  br label %.preheader36.us.us.us

._crit_edge56.us.us:                              ; preds = %._crit_edge50.us.us.us
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %indvars.iv.next109 = add nuw nsw i64 %indvars.iv108, 1
  %exitcond125.not = icmp eq i64 %indvars.iv.next, %wide.trip.count124
  br i1 %exitcond125.not, label %._crit_edge.us, label %.preheader36.us.us.us.preheader, !llvm.loop !7

.preheader36.us.us.us:                            ; preds = %.preheader36.us.us.us.preheader, %._crit_edge50.us.us.us
  %indvars.iv117 = phi i64 [ %indvars.iv115, %.preheader36.us.us.us.preheader ], [ %indvars.iv.next118, %._crit_edge50.us.us.us ]
  %.02854.us.us.us = phi i32 [ %indvars128, %.preheader36.us.us.us.preheader ], [ %17, %._crit_edge50.us.us.us ]
  %.253.us.us.us = phi i32 [ %.168.us.us, %.preheader36.us.us.us.preheader ], [ %.us-phi52.us.us.us, %._crit_edge50.us.us.us ]
  %.not42.us.us.us = icmp ult i32 %.02854.us.us.us, %indvars128
  br i1 %.not42.us.us.us, label %._crit_edge50.us.us.us, label %.preheader35.us60.us.us

11:                                               ; preds = %.preheader.us58.us.us, %11
  %indvars.iv90 = phi i64 [ %indvars.iv, %.preheader.us58.us.us ], [ %indvars.iv.next91, %11 ]
  %.540.us.us.us = phi i32 [ %.443.us.us.us, %.preheader.us58.us.us ], [ %15, %11 ]
  %12 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv99) #1
  %13 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %12, i64 noundef %indvars.iv90) #1
  %14 = load i32, ptr %13, align 4, !tbaa !8
  %15 = add nsw i32 %14, %.540.us.us.us
  %indvars.iv.next91 = add nuw nsw i64 %indvars.iv90, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next91, %indvars.iv110
  br i1 %exitcond.not, label %._crit_edge.us.us.us, label %11, !llvm.loop !12

.preheader.us58.us.us:                            ; preds = %.preheader35.us60.us.us, %._crit_edge.us.us.us
  %indvars.iv99 = phi i64 [ %indvars.iv.next100, %._crit_edge.us.us.us ], [ %indvars.iv97, %.preheader35.us60.us.us ]
  %.443.us.us.us = phi i32 [ %15, %._crit_edge.us.us.us ], [ %.347.us.us.us, %.preheader35.us60.us.us ]
  br label %11

.preheader35.us60.us.us:                          ; preds = %.preheader36.us.us.us, %._crit_edge45.us.us.us
  %indvars.iv110 = phi i64 [ %indvars.iv.next111, %._crit_edge45.us.us.us ], [ %indvars.iv108, %.preheader36.us.us.us ]
  %.02748.us61.us.us = phi i32 [ %16, %._crit_edge45.us.us.us ], [ %indvars123, %.preheader36.us.us.us ]
  %.347.us.us.us = phi i32 [ %.us-phi.us.us.us, %._crit_edge45.us.us.us ], [ %.253.us.us.us, %.preheader36.us.us.us ]
  %.not3439.us.us.us = icmp ult i32 %.02748.us61.us.us, %indvars123
  br i1 %.not3439.us.us.us, label %._crit_edge45.us.us.us, label %.preheader.us58.us.us

._crit_edge.us.us.us:                             ; preds = %11
  %indvars.iv.next100 = add nuw nsw i64 %indvars.iv99, 1
  %exitcond107.not = icmp eq i64 %indvars.iv.next100, %indvars.iv117
  br i1 %exitcond107.not, label %._crit_edge45.us.us.us, label %.preheader.us58.us.us, !llvm.loop !13

._crit_edge45.us.us.us:                           ; preds = %._crit_edge.us.us.us, %.preheader35.us60.us.us
  %.us-phi.us.us.us = phi i32 [ %.347.us.us.us, %.preheader35.us60.us.us ], [ %15, %._crit_edge.us.us.us ]
  %16 = add nuw nsw i32 %.02748.us61.us.us, 1
  %indvars.iv.next111 = add nuw nsw i64 %indvars.iv110, 1
  %exitcond114.not = icmp eq i64 %indvars.iv.next111, %wide.trip.count113
  br i1 %exitcond114.not, label %._crit_edge50.us.us.us, label %.preheader35.us60.us.us, !llvm.loop !14

._crit_edge50.us.us.us:                           ; preds = %._crit_edge45.us.us.us, %.preheader36.us.us.us
  %.us-phi52.us.us.us = phi i32 [ %.253.us.us.us, %.preheader36.us.us.us ], [ %.us-phi.us.us.us, %._crit_edge45.us.us.us ]
  %17 = add nuw nsw i32 %.02854.us.us.us, 1
  %indvars.iv.next118 = add nuw nsw i64 %indvars.iv117, 1
  %exitcond120.not = icmp eq i64 %indvars.iv.next118, %wide.trip.count
  br i1 %exitcond120.not, label %._crit_edge56.us.us, label %.preheader36.us.us.us, !llvm.loop !15

._crit_edge79:                                    ; preds = %._crit_edge.us, %1
  %.031.lcssa = phi i32 [ 0, %1 ], [ %.us-phi52.us.us.us, %._crit_edge.us ]
  ret i32 %.031.lcssa
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIS_IiSaIiEESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IiSaIiEESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = distinct !{!12, !6}
!13 = distinct !{!13, !6}
!14 = distinct !{!14, !6}
!15 = distinct !{!15, !6}


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