; LLVM IR from amritansh22/Data-Structures-and-Algorithms-in-cpp :: 494-Target_sum-Leetcode-DP.ll (Z16Count_Subset_SumRSt6vectorIiSaIiEEii)

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

@t = external dso_local global [1001 x [1001 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z16Count_Subset_SumRSt6vectorIiSaIiEEii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %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
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %23, %3
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 1001
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %11
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [1001 x i32], ptr @t, i64 0, i64 %17
  store i32 0, ptr %18, align 4, !tbaa !9
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %20
  %22 = getelementptr inbounds [1001 x i32], ptr %21, i64 0, i64 0
  store i32 1, ptr %22, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %15
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %7, align 4, !tbaa !9
  br label %11, !llvm.loop !11

26:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %100, %26
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  %31 = icmp slt i32 %28, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %27
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %103

33:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %96, %33
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  %38 = icmp slt i32 %35, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %34
  store i32 8, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %99

40:                                               ; preds = %34
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = sub nsw i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %41, i64 noundef %44) #2
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = icmp sle i32 %46, %47
  br i1 %48, label %49, label %80

49:                                               ; preds = %40
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = sub nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %52
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1001 x i32], ptr %53, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = sub nsw i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %60
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = sub nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %63, i64 noundef %66) #2
  %68 = load i32, ptr %67, align 4, !tbaa !9
  %69 = sub nsw i32 %62, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [1001 x i32], ptr %61, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !9
  %73 = add nsw i32 %57, %72
  %74 = load i32, ptr %8, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %75
  %77 = load i32, ptr %10, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [1001 x i32], ptr %76, i64 0, i64 %78
  store i32 %73, ptr %79, align 4, !tbaa !9
  br label %95

80:                                               ; preds = %40
  %81 = load i32, ptr %8, align 4, !tbaa !9
  %82 = sub nsw i32 %81, 1
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %83
  %85 = load i32, ptr %10, align 4, !tbaa !9
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [1001 x i32], ptr %84, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !9
  %89 = load i32, ptr %8, align 4, !tbaa !9
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %90
  %92 = load i32, ptr %10, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [1001 x i32], ptr %91, i64 0, i64 %93
  store i32 %88, ptr %94, align 4, !tbaa !9
  br label %95

95:                                               ; preds = %80, %49
  br label %96

96:                                               ; preds = %95
  %97 = load i32, ptr %10, align 4, !tbaa !9
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %10, align 4, !tbaa !9
  br label %34, !llvm.loop !13

99:                                               ; preds = %39
  br label %100

100:                                              ; preds = %99
  %101 = load i32, ptr %8, align 4, !tbaa !9
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %8, align 4, !tbaa !9
  br label %27, !llvm.loop !14

103:                                              ; preds = %32
  %104 = load i32, ptr %6, align 4, !tbaa !9
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %105
  %107 = load i32, ptr %5, align 4, !tbaa !9
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [1001 x i32], ptr %106, i64 0, i64 %108
  %110 = load i32, ptr %109, align 4, !tbaa !9
  ret i32 %110
}

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

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

; 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

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}


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

@t = external dso_local local_unnamed_addr global [1001 x [1001 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z16Count_Subset_SumRSt6vectorIiSaIiEEii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  br label %6

.preheader30:                                     ; preds = %6
  %.not34 = icmp slt i32 %2, 1
  %.not2832 = icmp slt i32 %1, 1
  %or.cond = or i1 %.not34, %.not2832
  br i1 %or.cond, label %._crit_edge36, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader30
  %4 = add nuw i32 %1, 1
  %5 = add nuw i32 %2, 1
  %wide.trip.count46 = zext i32 %5 to i64
  %wide.trip.count = zext i32 %4 to i64
  br label %.preheader

6:                                                ; preds = %9, %3
  %indvars.iv = phi i64 [ 0, %3 ], [ %indvars.iv.next.3, %9 ]
  %7 = getelementptr inbounds [1001 x i32], ptr @t, i64 0, i64 %indvars.iv
  store i32 0, ptr %7, align 16, !tbaa !5
  %8 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %indvars.iv
  store i32 1, ptr %8, align 16, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv, 1000
  br i1 %exitcond.not, label %.preheader30, label %9, !llvm.loop !9

9:                                                ; preds = %6
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %10 = getelementptr inbounds [1001 x i32], ptr @t, i64 0, i64 %indvars.iv.next
  store i32 0, ptr %10, align 4, !tbaa !5
  %11 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %indvars.iv.next
  store i32 1, ptr %11, align 4, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %12 = getelementptr inbounds [1001 x i32], ptr @t, i64 0, i64 %indvars.iv.next.1
  store i32 0, ptr %12, align 8, !tbaa !5
  %13 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %indvars.iv.next.1
  store i32 1, ptr %13, align 8, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %14 = getelementptr inbounds [1001 x i32], ptr @t, i64 0, i64 %indvars.iv.next.2
  store i32 0, ptr %14, align 4, !tbaa !5
  %15 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %indvars.iv.next.2
  store i32 1, ptr %15, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  br label %6

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %indvars.iv43 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next44, %._crit_edge ]
  %16 = add nsw i64 %indvars.iv43, -1
  br label %21

._crit_edge36:                                    ; preds = %._crit_edge, %.preheader30
  %17 = sext i32 %2 to i64
  %18 = sext i32 %1 to i64
  %19 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %17, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  ret i32 %20

._crit_edge:                                      ; preds = %36
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %exitcond47.not = icmp eq i64 %indvars.iv.next44, %wide.trip.count46
  br i1 %exitcond47.not, label %._crit_edge36, label %.preheader, !llvm.loop !11

21:                                               ; preds = %.preheader, %36
  %indvars.iv39 = phi i64 [ 1, %.preheader ], [ %indvars.iv.next40, %36 ]
  %22 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %16) #1
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %.not29 = icmp slt i64 %indvars.iv39, %24
  %25 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %16, i64 %indvars.iv39
  %26 = load i32, ptr %25, align 4, !tbaa !5
  br i1 %.not29, label %36, label %27

27:                                               ; preds = %21
  %28 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %16) #1
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = trunc nuw nsw i64 %indvars.iv39 to i32
  %31 = sub nsw i32 %30, %29
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %16, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %34, %26
  br label %36

36:                                               ; preds = %21, %27
  %.sink = phi i32 [ %35, %27 ], [ %26, %21 ]
  %37 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %indvars.iv43, i64 %indvars.iv39
  store i32 %.sink, ptr %37, align 4
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %exitcond42.not = icmp eq i64 %indvars.iv.next40, %wide.trip.count
  br i1 %exitcond42.not, label %._crit_edge, label %21, !llvm.loop !12
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass