; LLVM IR from amritansh22/Data-Structures-and-Algorithms-in-cpp :: Equal_Sum_Partition.ll (Z10Subset_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 zeroext i1 @_Z10Subset_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 = %105, %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 %108

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 = %101, %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 %104

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

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 = icmp ne i32 %57, 0
  br i1 %58, label %76, label %59

59:                                               ; preds = %49
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = sub nsw i32 %60, 1
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %62
  %64 = load i32, ptr %10, align 4, !tbaa !9
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = sub nsw i32 %66, 1
  %68 = sext i32 %67 to i64
  %69 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %65, i64 noundef %68) #2
  %70 = load i32, ptr %69, align 4, !tbaa !9
  %71 = sub nsw i32 %64, %70
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [1001 x i32], ptr %63, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !9
  %75 = icmp ne i32 %74, 0
  br label %76

76:                                               ; preds = %59, %49
  %77 = phi i1 [ true, %49 ], [ %75, %59 ]
  %78 = zext i1 %77 to i32
  %79 = load i32, ptr %8, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %80
  %82 = load i32, ptr %10, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [1001 x i32], ptr %81, i64 0, i64 %83
  store i32 %78, ptr %84, align 4, !tbaa !9
  br label %100

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

100:                                              ; preds = %85, %76
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %10, align 4, !tbaa !9
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %10, align 4, !tbaa !9
  br label %34, !llvm.loop !13

104:                                              ; preds = %39
  br label %105

105:                                              ; preds = %104
  %106 = load i32, ptr %8, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %8, align 4, !tbaa !9
  br label %27, !llvm.loop !14

108:                                              ; preds = %32
  %109 = load i32, ptr %6, align 4, !tbaa !9
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %110
  %112 = load i32, ptr %5, align 4, !tbaa !9
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [1001 x i32], ptr %111, i64 0, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !9
  %116 = icmp ne i32 %115, 0
  ret i1 %116
}

; 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 zeroext i1 @_Z10Subset_SumRSt6vectorIiSaIiEEii(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  br label %6

.preheader31:                                     ; preds = %6
  %.not36 = icmp slt i32 %2, 1
  %.not2833 = icmp slt i32 %1, 1
  %or.cond = or i1 %.not36, %.not2833
  br i1 %or.cond, label %._crit_edge38, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader31
  %4 = add nuw i32 %1, 1
  %5 = add nuw i32 %2, 1
  %wide.trip.count48 = 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 %.preheader31, 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.iv45 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next46, %._crit_edge ]
  %16 = add nsw i64 %indvars.iv45, -1
  br label %22

._crit_edge38:                                    ; preds = %._crit_edge, %.preheader31
  %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
  %21 = icmp ne i32 %20, 0
  ret i1 %21

._crit_edge:                                      ; preds = %41
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %exitcond49.not = icmp eq i64 %indvars.iv.next46, %wide.trip.count48
  br i1 %exitcond49.not, label %._crit_edge38, label %.preheader, !llvm.loop !11

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

28:                                               ; preds = %22
  %.not30 = icmp eq i32 %27, 0
  br i1 %.not30, label %29, label %38

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

38:                                               ; preds = %29, %28
  %39 = phi i1 [ true, %28 ], [ %37, %29 ]
  %40 = zext i1 %39 to i32
  br label %41

41:                                               ; preds = %22, %38
  %.sink = phi i32 [ %40, %38 ], [ %27, %22 ]
  %42 = getelementptr inbounds [1001 x [1001 x i32]], ptr @t, i64 0, i64 %indvars.iv45, i64 %indvars.iv41
  store i32 %.sink, ptr %42, align 4, !tbaa !5
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %exitcond44.not = icmp eq i64 %indvars.iv.next42, %wide.trip.count
  br i1 %exitcond44.not, label %._crit_edge, label %22, !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,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass