; LLVM IR from DionysiosB/CodeForces :: 0300-0399/343C-ReadTime.ll (Z5checkSt6vectorIxSaIxEES1_x)

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

14:                                               ; preds = %117, %3
  %15 = load i64, ptr %9, align 8, !tbaa !9
  %16 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %20) #2
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %23) #2
  %25 = load i64, ptr %24, align 8, !tbaa !9
  %26 = icmp slt i64 %22, %25
  br i1 %26, label %27, label %57

27:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %29) #2
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = sub nsw i64 %28, %31
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %33) #2
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = mul nsw i64 2, %35
  %37 = add nsw i64 %32, %36
  store i64 %37, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %39) #2
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = add nsw i64 %38, %41
  %43 = load i64, ptr %8, align 8, !tbaa !9
  %44 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %43) #2
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = add nsw i64 %42, %45
  %47 = sdiv i64 %46, 2
  store i64 %47, ptr %13, align 8, !tbaa !9
  %48 = load i64, ptr %12, align 8, !tbaa !9
  %49 = load i64, ptr %13, align 8, !tbaa !9
  %50 = icmp sgt i64 %48, %49
  br i1 %50, label %51, label %53

51:                                               ; preds = %27
  %52 = load i64, ptr %12, align 8, !tbaa !9
  br label %55

53:                                               ; preds = %27
  %54 = load i64, ptr %13, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %53, %51
  %56 = phi i64 [ %52, %51 ], [ %54, %53 ]
  store i64 %56, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %63

57:                                               ; preds = %19
  %58 = load i64, ptr %7, align 8, !tbaa !9
  %59 = load i64, ptr %9, align 8, !tbaa !9
  %60 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %59) #2
  %61 = load i64, ptr %60, align 8, !tbaa !9
  %62 = add nsw i64 %58, %61
  store i64 %62, ptr %11, align 8, !tbaa !9
  br label %63

63:                                               ; preds = %57, %55
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %64) #2
  %66 = load i64, ptr %65, align 8, !tbaa !9
  %67 = load i64, ptr %9, align 8, !tbaa !9
  %68 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %67) #2
  %69 = load i64, ptr %68, align 8, !tbaa !9
  %70 = icmp slt i64 %66, %69
  br i1 %70, label %71, label %82

71:                                               ; preds = %63
  %72 = load i64, ptr %7, align 8, !tbaa !9
  %73 = load i64, ptr %8, align 8, !tbaa !9
  %74 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %73) #2
  %75 = load i64, ptr %74, align 8, !tbaa !9
  %76 = add nsw i64 %72, %75
  %77 = load i64, ptr %9, align 8, !tbaa !9
  %78 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %77) #2
  %79 = load i64, ptr %78, align 8, !tbaa !9
  %80 = icmp slt i64 %76, %79
  br i1 %80, label %81, label %82

81:                                               ; preds = %71
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %114

82:                                               ; preds = %71, %63
  br label %83

83:                                               ; preds = %105, %82
  %84 = load i64, ptr %8, align 8, !tbaa !9
  %85 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #2
  %86 = icmp ult i64 %84, %85
  br i1 %86, label %87, label %103

87:                                               ; preds = %83
  %88 = load i64, ptr %8, align 8, !tbaa !9
  %89 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %88) #2
  %90 = load i64, ptr %89, align 8, !tbaa !9
  %91 = load i64, ptr %11, align 8, !tbaa !9
  %92 = icmp sle i64 %90, %91
  br i1 %92, label %101, label %93

93:                                               ; preds = %87
  %94 = load i64, ptr %8, align 8, !tbaa !9
  %95 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %94) #2
  %96 = load i64, ptr %95, align 8, !tbaa !9
  %97 = load i64, ptr %9, align 8, !tbaa !9
  %98 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %97) #2
  %99 = load i64, ptr %98, align 8, !tbaa !9
  %100 = icmp sle i64 %96, %99
  br label %101

101:                                              ; preds = %93, %87
  %102 = phi i1 [ true, %87 ], [ %100, %93 ]
  br label %103

103:                                              ; preds = %101, %83
  %104 = phi i1 [ false, %83 ], [ %102, %101 ]
  br i1 %104, label %105, label %108

105:                                              ; preds = %103
  %106 = load i64, ptr %8, align 8, !tbaa !9
  %107 = add nsw i64 %106, 1
  store i64 %107, ptr %8, align 8, !tbaa !9
  br label %83, !llvm.loop !11

108:                                              ; preds = %103
  %109 = load i64, ptr %8, align 8, !tbaa !9
  %110 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #2
  %111 = icmp eq i64 %109, %110
  br i1 %111, label %112, label %113

112:                                              ; preds = %108
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %114

113:                                              ; preds = %108
  store i32 0, ptr %10, align 4
  br label %114

114:                                              ; preds = %113, %112, %81
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %115 = load i32, ptr %10, align 4
  switch i32 %115, label %120 [
    i32 0, label %116
  ]

116:                                              ; preds = %114
  br label %117

117:                                              ; preds = %116
  %118 = load i64, ptr %9, align 8, !tbaa !9
  %119 = add nsw i64 %118, 1
  store i64 %119, ptr %9, align 8, !tbaa !9
  br label %14, !llvm.loop !13

120:                                              ; preds = %114, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %121 = load i32, ptr %10, align 4
  switch i32 %121, label %123 [
    i32 2, label %122
  ]

122:                                              ; preds = %120
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %123

123:                                              ; preds = %122, %120
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %124 = load i1, ptr %4, align 1
  ret i1 %124
}

; 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 @_ZNSt6vectorIxSaIxEEixEm(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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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 zeroext i1 @_Z5checkSt6vectorIxSaIxEES1_x(ptr noundef nonnull %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %.not4148.not = icmp eq i64 %4, 0
  br i1 %.not4148.not, label %.thread, label %.lr.ph53

5:                                                ; preds = %._crit_edge
  %6 = add nuw nsw i64 %.03949, 1
  %7 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %.not41 = icmp ult i64 %6, %7
  br i1 %.not41, label %.lr.ph53, label %.thread, !llvm.loop !5

.lr.ph53:                                         ; preds = %3, %5
  %.03350 = phi i64 [ %.134.lcssa, %5 ], [ 0, %3 ]
  %.03949 = phi i64 [ %6, %5 ], [ 0, %3 ]
  %8 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.03350) #2
  %9 = load i64, ptr %8, align 8, !tbaa !7
  %10 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.03949) #2
  %11 = load i64, ptr %10, align 8, !tbaa !7
  %12 = icmp slt i64 %9, %11
  %13 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.03949) #2
  %14 = load i64, ptr %13, align 8, !tbaa !7
  br i1 %12, label %15, label %29

15:                                               ; preds = %.lr.ph53
  %16 = sub i64 %2, %14
  %17 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.03350) #2
  %18 = load i64, ptr %17, align 8, !tbaa !7
  %19 = shl nsw i64 %18, 1
  %20 = add nsw i64 %16, %19
  %21 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.03949) #2
  %22 = load i64, ptr %21, align 8, !tbaa !7
  %23 = add nsw i64 %22, %2
  %24 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.03350) #2
  %25 = load i64, ptr %24, align 8, !tbaa !7
  %26 = add nsw i64 %23, %25
  %27 = sdiv i64 %26, 2
  %28 = tail call i64 @llvm.smax.i64(i64 %20, i64 %27)
  br label %31

29:                                               ; preds = %.lr.ph53
  %30 = add nsw i64 %14, %2
  br label %31

31:                                               ; preds = %29, %15
  %.036 = phi i64 [ %28, %15 ], [ %30, %29 ]
  %32 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.03350) #2
  %33 = load i64, ptr %32, align 8, !tbaa !7
  %34 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.03949) #2
  %35 = load i64, ptr %34, align 8, !tbaa !7
  %36 = icmp slt i64 %33, %35
  br i1 %36, label %37, label %44

37:                                               ; preds = %31
  %38 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.03350) #2
  %39 = load i64, ptr %38, align 8, !tbaa !7
  %40 = add nsw i64 %39, %2
  %41 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.03949) #2
  %42 = load i64, ptr %41, align 8, !tbaa !7
  %43 = icmp slt i64 %40, %42
  br i1 %43, label %.thread, label %44

44:                                               ; preds = %37, %31
  %45 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #2
  %46 = icmp ult i64 %.03350, %45
  br i1 %46, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %44, %.critedge3
  %.13445 = phi i64 [ %54, %.critedge3 ], [ %.03350, %44 ]
  %47 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.13445) #2
  %48 = load i64, ptr %47, align 8, !tbaa !7
  %.not = icmp sgt i64 %48, %.036
  br i1 %.not, label %49, label %.critedge3

49:                                               ; preds = %.lr.ph
  %50 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.13445) #2
  %51 = load i64, ptr %50, align 8, !tbaa !7
  %52 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.03949) #2
  %53 = load i64, ptr %52, align 8, !tbaa !7
  %.not40 = icmp sgt i64 %51, %53
  br i1 %.not40, label %._crit_edge, label %.critedge3

.critedge3:                                       ; preds = %.lr.ph, %49
  %54 = add nuw nsw i64 %.13445, 1
  %55 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #2
  %56 = icmp ult i64 %54, %55
  br i1 %56, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.critedge3, %49, %44
  %.134.lcssa = phi i64 [ %.03350, %44 ], [ %.13445, %49 ], [ %54, %.critedge3 ]
  %57 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #2
  %58 = icmp eq i64 %.134.lcssa, %57
  br i1 %58, label %.thread, label %5

.thread:                                          ; preds = %._crit_edge, %5, %37, %3
  %spec.select = phi i1 [ false, %3 ], [ false, %37 ], [ false, %5 ], [ true, %._crit_edge ]
  ret i1 %spec.select
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #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 speculatable willreturn memory(none) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass