; LLVM IR from DionysiosB/CodeForces :: CodeforcesEDU/BinarySearch5C-KthSum.ll (Z5checkRKSt6vectorIxSaIxEES3_xx)

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

16:                                               ; preds = %55, %4
  %17 = load i64, ptr %11, align 8, !tbaa !11
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %18) #2
  %20 = icmp ult i64 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 2, ptr %12, align 4
  br label %58

22:                                               ; preds = %16
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i64, ptr %11, align 8, !tbaa !11
  %25 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %23, i64 noundef %24) #2
  %26 = load i64, ptr %25, align 8, !tbaa !9
  %27 = load i64, ptr %8, align 8, !tbaa !9
  %28 = icmp sge i64 %26, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %22
  store i32 2, ptr %12, align 4
  br label %58

30:                                               ; preds = %22
  br label %31

31:                                               ; preds = %48, %30
  %32 = load i64, ptr %9, align 8, !tbaa !9
  %33 = icmp sgt i64 %32, 0
  br i1 %33, label %34, label %46

34:                                               ; preds = %31
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i64, ptr %11, align 8, !tbaa !11
  %37 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %35, i64 noundef %36) #2
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load i64, ptr %9, align 8, !tbaa !9
  %41 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %39, i64 noundef %40) #2
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = add nsw i64 %38, %42
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = icmp sgt i64 %43, %44
  br label %46

46:                                               ; preds = %34, %31
  %47 = phi i1 [ false, %31 ], [ %45, %34 ]
  br i1 %47, label %48, label %51

48:                                               ; preds = %46
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = add nsw i64 %49, -1
  store i64 %50, ptr %9, align 8, !tbaa !9
  br label %31, !llvm.loop !13

51:                                               ; preds = %46
  %52 = load i64, ptr %9, align 8, !tbaa !9
  %53 = load i64, ptr %10, align 8, !tbaa !9
  %54 = add nsw i64 %53, %52
  store i64 %54, ptr %10, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %51
  %56 = load i64, ptr %11, align 8, !tbaa !11
  %57 = add nsw i64 %56, 1
  store i64 %57, ptr %11, align 8, !tbaa !11
  br label %16, !llvm.loop !15

58:                                               ; preds = %29, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %59

59:                                               ; preds = %58
  %60 = load i64, ptr %10, align 8, !tbaa !9
  %61 = load i64, ptr %7, align 8, !tbaa !9
  %62 = icmp sge i64 %60, %61
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i1 %62
}

; 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 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(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 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 @_Z5checkRKSt6vectorIxSaIxEES3_xx(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #1
  %6 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %7 = icmp ugt i64 %6, 1
  br i1 %7, label %.lr.ph25.preheader, label %._crit_edge

.lr.ph25.preheader:                               ; preds = %4
  %8 = add i64 %5, -1
  br label %.lr.ph25

.lr.ph25:                                         ; preds = %.lr.ph25.preheader, %.critedge
  %.024 = phi i64 [ %22, %.critedge ], [ 1, %.lr.ph25.preheader ]
  %.01723 = phi i64 [ %21, %.critedge ], [ 0, %.lr.ph25.preheader ]
  %.01822 = phi i64 [ %.1.lcssa, %.critedge ], [ %8, %.lr.ph25.preheader ]
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.024) #1
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %.not = icmp slt i64 %10, %3
  br i1 %.not, label %.preheader, label %._crit_edge

.preheader:                                       ; preds = %.lr.ph25
  %11 = icmp sgt i64 %.01822, 0
  br i1 %11, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.preheader, %18
  %.119 = phi i64 [ %19, %18 ], [ %.01822, %.preheader ]
  %12 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.024) #1
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.119) #1
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = add nsw i64 %15, %13
  %17 = icmp sgt i64 %16, %3
  br i1 %17, label %18, label %.critedge

18:                                               ; preds = %.lr.ph
  %19 = add nsw i64 %.119, -1
  %20 = icmp sgt i64 %.119, 1
  br i1 %20, label %.lr.ph, label %.critedge, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph, %18, %.preheader
  %.1.lcssa = phi i64 [ %.01822, %.preheader ], [ 0, %18 ], [ %.119, %.lr.ph ]
  %21 = add nsw i64 %.1.lcssa, %.01723
  %22 = add nuw nsw i64 %.024, 1
  %23 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %24 = icmp ult i64 %22, %23
  br i1 %24, label %.lr.ph25, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.critedge, %.lr.ph25, %4
  %.017.lcssa = phi i64 [ 0, %4 ], [ %.01723, %.lr.ph25 ], [ %21, %.critedge ]
  %25 = icmp sge i64 %.017.lcssa, %2
  ret i1 %25
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(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(8) ptr @_ZNKSt6vectorIxSaIxEEixEm(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"}
!11 = distinct !{!11, !10}


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