; LLVM IR from abhisheknaiidu/dsa :: GFG/book-allocation.ll (Z5checkRSt6vectorIxSaIxEExxx)

; 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: 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 noundef zeroext i1 @_Z5checkRSt6vectorIxSaIxEExxx(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) #1 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 1, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store i64 0, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %48, %4
  %15 = load i64, ptr %12, align 8, !tbaa !9
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = icmp slt i64 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 2, ptr %13, align 4
  br label %51

19:                                               ; preds = %14
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i64, ptr %12, align 8, !tbaa !9
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %20, i64 noundef %21) #2
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = load i64, ptr %11, align 8, !tbaa !9
  %25 = add nsw i64 %23, %24
  %26 = load i64, ptr %9, align 8, !tbaa !9
  %27 = icmp sge i64 %25, %26
  br i1 %27, label %28, label %40

28:                                               ; preds = %19
  %29 = load i64, ptr %10, align 8, !tbaa !9
  %30 = add nsw i64 %29, 1
  store i64 %30, ptr %10, align 8, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i64, ptr %12, align 8, !tbaa !9
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %31, i64 noundef %32) #2
  %34 = load i64, ptr %33, align 8, !tbaa !9
  store i64 %34, ptr %11, align 8, !tbaa !9
  %35 = load i64, ptr %10, align 8, !tbaa !9
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = icmp sgt i64 %35, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %28
  store i1 false, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %51

39:                                               ; preds = %28
  br label %47

40:                                               ; preds = %19
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i64, ptr %12, align 8, !tbaa !9
  %43 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %41, i64 noundef %42) #2
  %44 = load i64, ptr %43, align 8, !tbaa !9
  %45 = load i64, ptr %11, align 8, !tbaa !9
  %46 = add nsw i64 %45, %44
  store i64 %46, ptr %11, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %40, %39
  br label %48

48:                                               ; preds = %47
  %49 = load i64, ptr %12, align 8, !tbaa !9
  %50 = add nsw i64 %49, 1
  store i64 %50, ptr %12, align 8, !tbaa !9
  br label %14, !llvm.loop !11

51:                                               ; preds = %38, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %52 = load i32, ptr %13, align 4
  switch i32 %52, label %54 [
    i32 2, label %53
  ]

53:                                               ; preds = %51
  store i1 true, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %54

54:                                               ; preds = %53, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %55 = load i1, ptr %5, align 1
  ret i1 %55
}

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

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


; 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 zeroext i1 @_Z5checkRSt6vectorIxSaIxEExxx(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %.not2425 = icmp slt i64 %1, 1
  br i1 %.not2425, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %16
  %.not2429 = phi i1 [ %.not24, %16 ], [ false, %4 ]
  %.01628 = phi i64 [ %17, %16 ], [ 0, %4 ]
  %.01727 = phi i64 [ %.1, %16 ], [ 0, %4 ]
  %.01826 = phi i64 [ %.119, %16 ], [ 1, %4 ]
  %5 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.01628) #1
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = add nsw i64 %6, %.01727
  %.not = icmp slt i64 %7, %3
  br i1 %.not, label %12, label %8

8:                                                ; preds = %.lr.ph
  %9 = add nsw i64 %.01826, 1
  %10 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.01628) #1
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %.not23 = icmp slt i64 %.01826, %2
  br i1 %.not23, label %16, label %.critedge

12:                                               ; preds = %.lr.ph
  %13 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.01628) #1
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = add nsw i64 %14, %.01727
  br label %16

16:                                               ; preds = %12, %8
  %.119 = phi i64 [ %9, %8 ], [ %.01826, %12 ]
  %.1 = phi i64 [ %11, %8 ], [ %15, %12 ]
  %17 = add nuw nsw i64 %.01628, 1
  %.not24 = icmp sge i64 %17, %1
  %exitcond = icmp eq i64 %17, %1
  br i1 %exitcond, label %.critedge, label %.lr.ph, !llvm.loop !9

.critedge:                                        ; preds = %8, %16, %4
  %.not24.lcssa = phi i1 [ true, %4 ], [ %.not24, %16 ], [ %.not2429, %8 ]
  ret i1 %.not24.lcssa
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass