; LLVM IR from eyangch/competitive-programming :: Codeforces/1251/d.ll (Z5worksxxx)

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

%"struct.std::pair" = type { i64, i64 }

@lr = external dso_local global [200000 x %"struct.std::pair"], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z3cmpSt4pairIxxES0_(i64, i64, i64, i64) #0

; 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 uwtable
define dso_local noundef zeroext i1 @_Z5worksxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i1, align 1
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !5
  %12 = load i64, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %"struct.std::pair", ptr @lr, i64 %12
  call void @_ZSt4sortIPSt4pairIxxEPFbS1_S1_EEvT_S5_T0_(ptr noundef @lr, ptr noundef %13, ptr noundef @_Z3cmpSt4pairIxxES0_)
  br label %14

14:                                               ; preds = %33, %3
  %15 = load i64, ptr %8, align 8, !tbaa !5
  %16 = load i64, ptr %5, align 8, !tbaa !5
  %17 = icmp slt i64 %15, %16
  br i1 %17, label %18, label %36

18:                                               ; preds = %14
  %19 = load i64, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds [200000 x %"struct.std::pair"], ptr @lr, i64 0, i64 %19
  %21 = getelementptr inbounds %"struct.std::pair", ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = load i64, ptr %7, align 8, !tbaa !5
  %24 = icmp sge i64 %22, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %18
  br label %36

26:                                               ; preds = %18
  %27 = load i64, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds [200000 x %"struct.std::pair"], ptr @lr, i64 0, i64 %27
  %29 = getelementptr inbounds %"struct.std::pair", ptr %28, i32 0, i32 0
  %30 = load i64, ptr %29, align 16, !tbaa !11
  %31 = load i64, ptr %6, align 8, !tbaa !5
  %32 = sub nsw i64 %31, %30
  store i64 %32, ptr %6, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %26
  %34 = load i64, ptr %8, align 8, !tbaa !5
  %35 = add nsw i64 %34, 1
  store i64 %35, ptr %8, align 8, !tbaa !5
  br label %14, !llvm.loop !12

36:                                               ; preds = %25, %14
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = load i64, ptr %8, align 8, !tbaa !5
  %39 = sub nsw i64 %37, %38
  %40 = load i64, ptr %5, align 8, !tbaa !5
  %41 = add nsw i64 %40, 1
  %42 = sdiv i64 %41, 2
  %43 = icmp slt i64 %39, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %36
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %94

45:                                               ; preds = %36
  %46 = load i64, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.std::pair", ptr @lr, i64 %46
  %48 = load i64, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.std::pair", ptr @lr, i64 %48
  call void @_ZSt4sortIPSt4pairIxxEEvT_S3_(ptr noundef %47, ptr noundef %49)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %50 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %50, ptr %10, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %67, %45
  %52 = load i64, ptr %5, align 8, !tbaa !5
  %53 = load i64, ptr %10, align 8, !tbaa !5
  %54 = sub nsw i64 %52, %53
  %55 = load i64, ptr %5, align 8, !tbaa !5
  %56 = add nsw i64 %55, 1
  %57 = sdiv i64 %56, 2
  %58 = icmp sgt i64 %54, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %51
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %70

60:                                               ; preds = %51
  %61 = load i64, ptr %10, align 8, !tbaa !5
  %62 = getelementptr inbounds [200000 x %"struct.std::pair"], ptr @lr, i64 0, i64 %61
  %63 = getelementptr inbounds %"struct.std::pair", ptr %62, i32 0, i32 0
  %64 = load i64, ptr %63, align 16, !tbaa !11
  %65 = load i64, ptr %6, align 8, !tbaa !5
  %66 = sub nsw i64 %65, %64
  store i64 %66, ptr %6, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %60
  %68 = load i64, ptr %10, align 8, !tbaa !5
  %69 = add nsw i64 %68, 1
  store i64 %69, ptr %10, align 8, !tbaa !5
  br label %51, !llvm.loop !14

70:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %71 = load i64, ptr %5, align 8, !tbaa !5
  %72 = add nsw i64 %71, 1
  %73 = sdiv i64 %72, 2
  %74 = sub nsw i64 %73, 1
  store i64 %74, ptr %11, align 8, !tbaa !5
  br label %75

75:                                               ; preds = %88, %70
  %76 = load i64, ptr %11, align 8, !tbaa !5
  %77 = load i64, ptr %5, align 8, !tbaa !5
  %78 = icmp slt i64 %76, %77
  br i1 %78, label %80, label %79

79:                                               ; preds = %75
  store i32 8, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %91

80:                                               ; preds = %75
  %81 = load i64, ptr %11, align 8, !tbaa !5
  %82 = getelementptr inbounds [200000 x %"struct.std::pair"], ptr @lr, i64 0, i64 %81
  %83 = getelementptr inbounds %"struct.std::pair", ptr %82, i32 0, i32 0
  %84 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %83)
  %85 = load i64, ptr %84, align 8, !tbaa !5
  %86 = load i64, ptr %6, align 8, !tbaa !5
  %87 = sub nsw i64 %86, %85
  store i64 %87, ptr %6, align 8, !tbaa !5
  br label %88

88:                                               ; preds = %80
  %89 = load i64, ptr %11, align 8, !tbaa !5
  %90 = add nsw i64 %89, 1
  store i64 %90, ptr %11, align 8, !tbaa !5
  br label %75, !llvm.loop !15

91:                                               ; preds = %79
  %92 = load i64, ptr %6, align 8, !tbaa !5
  %93 = icmp sge i64 %92, 0
  store i1 %93, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %94

94:                                               ; preds = %91, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %95 = load i1, ptr %4, align 1
  ret i1 %95
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPSt4pairIxxEPFbS1_S1_EEvT_S5_T0_(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPSt4pairIxxEEvT_S3_(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 #3 = { inlinehint 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 #4 = { 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 = !{!10, !6, i64 8}
!10 = !{!"_ZTSSt4pairIxxE", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


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

%"struct.std::pair" = type { i64, i64 }

@lr = external dso_local global [200000 x %"struct.std::pair"], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z3cmpSt4pairIxxES0_(i64, i64, i64, i64) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5worksxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = alloca i64, align 8
  store i64 %2, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds %"struct.std::pair", ptr @lr, i64 %0
  tail call void @_ZSt4sortIPSt4pairIxxEPFbS1_S1_EEvT_S5_T0_(ptr noundef nonnull @lr, ptr noundef nonnull %5, ptr noundef nonnull @_Z3cmpSt4pairIxxES0_)
  %6 = icmp sgt i64 %0, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %10
  %.02732 = phi i64 [ %13, %10 ], [ 0, %3 ]
  %.02831 = phi i64 [ %12, %10 ], [ %1, %3 ]
  %7 = getelementptr inbounds [200000 x %"struct.std::pair"], ptr @lr, i64 0, i64 %.02732
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %.not = icmp slt i64 %9, %2
  br i1 %.not, label %10, label %._crit_edge

10:                                               ; preds = %.lr.ph
  %11 = load i64, ptr %7, align 16, !tbaa !11
  %12 = sub nsw i64 %.02831, %11
  %13 = add nuw nsw i64 %.02732, 1
  %exitcond.not = icmp eq i64 %13, %0
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %10, %.lr.ph, %3
  %.028.lcssa = phi i64 [ %1, %3 ], [ %.02831, %.lr.ph ], [ %12, %10 ]
  %.027.lcssa = phi i64 [ 0, %3 ], [ %.02732, %.lr.ph ], [ %0, %10 ]
  %14 = sub nsw i64 %0, %.027.lcssa
  %15 = add nsw i64 %0, 1
  %16 = sdiv i64 %15, 2
  %17 = icmp slt i64 %14, %16
  br i1 %17, label %56, label %18

18:                                               ; preds = %._crit_edge
  %19 = getelementptr inbounds %"struct.std::pair", ptr @lr, i64 %.027.lcssa
  tail call void @_ZSt4sortIPSt4pairIxxEEvT_S3_(ptr noundef nonnull %19, ptr noundef nonnull %5)
  %20 = icmp sgt i64 %14, %16
  br i1 %20, label %.lr.ph40.preheader, label %._crit_edge41

.lr.ph40.preheader:                               ; preds = %18
  %21 = add i64 %.027.lcssa, %16
  %22 = sub i64 %0, %21
  %min.iters.check = icmp ult i64 %22, 4
  br i1 %min.iters.check, label %.lr.ph40.preheader55, label %vector.ph

.lr.ph40.preheader55:                             ; preds = %middle.block, %.lr.ph40.preheader
  %.02638.ph = phi i64 [ %.027.lcssa, %.lr.ph40.preheader ], [ %ind.end, %middle.block ]
  %.137.ph = phi i64 [ %.028.lcssa, %.lr.ph40.preheader ], [ %42, %middle.block ]
  br label %.lr.ph40

vector.ph:                                        ; preds = %.lr.ph40.preheader
  %n.vec = and i64 %22, -4
  %ind.end = add i64 %.027.lcssa, %n.vec
  %23 = insertelement <2 x i64> <i64 poison, i64 0>, i64 %.028.lcssa, i64 0
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ %23, %vector.ph ], [ %39, %vector.body ]
  %vec.phi54 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %40, %vector.body ]
  %offset.idx = add i64 %.027.lcssa, %index
  %24 = add i64 %offset.idx, 1
  %25 = add i64 %offset.idx, 2
  %26 = add i64 %offset.idx, 3
  %27 = getelementptr inbounds [200000 x %"struct.std::pair"], ptr @lr, i64 0, i64 %offset.idx
  %28 = getelementptr inbounds [200000 x %"struct.std::pair"], ptr @lr, i64 0, i64 %24
  %29 = getelementptr inbounds [200000 x %"struct.std::pair"], ptr @lr, i64 0, i64 %25
  %30 = getelementptr inbounds [200000 x %"struct.std::pair"], ptr @lr, i64 0, i64 %26
  %31 = load i64, ptr %27, align 16, !tbaa !11
  %32 = load i64, ptr %28, align 16, !tbaa !11
  %33 = insertelement <2 x i64> poison, i64 %31, i64 0
  %34 = insertelement <2 x i64> %33, i64 %32, i64 1
  %35 = load i64, ptr %29, align 16, !tbaa !11
  %36 = load i64, ptr %30, align 16, !tbaa !11
  %37 = insertelement <2 x i64> poison, i64 %35, i64 0
  %38 = insertelement <2 x i64> %37, i64 %36, i64 1
  %39 = sub <2 x i64> %vec.phi, %34
  %40 = sub <2 x i64> %vec.phi54, %38
  %index.next = add nuw i64 %index, 4
  %41 = icmp eq i64 %index.next, %n.vec
  br i1 %41, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %40, %39
  %42 = tail call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %22, %n.vec
  br i1 %cmp.n, label %._crit_edge41, label %.lr.ph40.preheader55

._crit_edge41:                                    ; preds = %.lr.ph40, %middle.block, %18
  %.1.lcssa = phi i64 [ %.028.lcssa, %18 ], [ %42, %middle.block ], [ %46, %.lr.ph40 ]
  %.not49 = icmp sgt i64 %16, %0
  br i1 %.not49, label %._crit_edge47, label %.lr.ph46.preheader

.lr.ph46.preheader:                               ; preds = %._crit_edge41
  %43 = add nsw i64 %16, -1
  br label %.lr.ph46

.lr.ph40:                                         ; preds = %.lr.ph40.preheader55, %.lr.ph40
  %.02638 = phi i64 [ %47, %.lr.ph40 ], [ %.02638.ph, %.lr.ph40.preheader55 ]
  %.137 = phi i64 [ %46, %.lr.ph40 ], [ %.137.ph, %.lr.ph40.preheader55 ]
  %44 = getelementptr inbounds [200000 x %"struct.std::pair"], ptr @lr, i64 0, i64 %.02638
  %45 = load i64, ptr %44, align 16, !tbaa !11
  %46 = sub nsw i64 %.137, %45
  %47 = add nuw nsw i64 %.02638, 1
  %48 = sub nsw i64 %0, %47
  %49 = icmp sgt i64 %48, %16
  br i1 %49, label %.lr.ph40, label %._crit_edge41, !llvm.loop !17

._crit_edge47:                                    ; preds = %.lr.ph46, %._crit_edge41
  %.2.lcssa = phi i64 [ %.1.lcssa, %._crit_edge41 ], [ %54, %.lr.ph46 ]
  %50 = icmp sgt i64 %.2.lcssa, -1
  br label %56

.lr.ph46:                                         ; preds = %.lr.ph46.preheader, %.lr.ph46
  %.044 = phi i64 [ %55, %.lr.ph46 ], [ %43, %.lr.ph46.preheader ]
  %.243 = phi i64 [ %54, %.lr.ph46 ], [ %.1.lcssa, %.lr.ph46.preheader ]
  %51 = getelementptr inbounds [200000 x %"struct.std::pair"], ptr @lr, i64 0, i64 %.044
  %52 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %51)
  %53 = load i64, ptr %52, align 8, !tbaa !5
  %54 = sub nsw i64 %.243, %53
  %55 = add i64 %.044, 1
  %exitcond51.not = icmp eq i64 %55, %0
  br i1 %exitcond51.not, label %._crit_edge47, label %.lr.ph46, !llvm.loop !18

56:                                               ; preds = %._crit_edge, %._crit_edge47
  %.029 = phi i1 [ %50, %._crit_edge47 ], [ false, %._crit_edge ]
  ret i1 %.029
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPSt4pairIxxEPFbS1_S1_EEvT_S5_T0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPSt4pairIxxEEvT_S3_(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #3

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 = { inlinehint 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!10, !6, i64 8}
!10 = !{!"_ZTSSt4pairIxxE", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13, !15, !16}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !13, !16, !15}
!18 = distinct !{!18, !13}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass