; LLVM IR from seikhchilli/codeforces-solution :: 580B.ll (Z13binary_searchRSt6vectorISt4pairIxxESaIS1_EEiix)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z13binary_searchRSt6vectorISt4pairIxxESaIS1_EEiix(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, i64 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !11
  br label %12

12:                                               ; preds = %63, %4
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %16, label %64

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = add nsw i32 %17, %18
  %20 = sdiv i32 %19, 2
  store i32 %20, ptr %10, align 4, !tbaa !9
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIxxESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %21, i64 noundef %23) #2
  %25 = getelementptr inbounds %"struct.std::pair", ptr %24, i32 0, i32 0
  %26 = load i64, ptr %25, align 8, !tbaa !13
  %27 = load i64, ptr %9, align 8, !tbaa !11
  %28 = icmp slt i64 %26, %27
  br i1 %28, label %29, label %39

29:                                               ; preds = %16
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = icmp eq i32 %30, %31
  br i1 %32, label %33, label %36

33:                                               ; preds = %29
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %61

36:                                               ; preds = %29
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %7, align 4, !tbaa !9
  br label %60

39:                                               ; preds = %16
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = icmp eq i32 %40, %41
  br i1 %42, label %43, label %45

43:                                               ; preds = %39
  %44 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %44, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %61

45:                                               ; preds = %39
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = sub nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIxxESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %46, i64 noundef %49) #2
  %51 = getelementptr inbounds %"struct.std::pair", ptr %50, i32 0, i32 0
  %52 = load i64, ptr %51, align 8, !tbaa !13
  %53 = load i64, ptr %9, align 8, !tbaa !11
  %54 = icmp slt i64 %52, %53
  br i1 %54, label %55, label %57

55:                                               ; preds = %45
  %56 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %56, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %61

57:                                               ; preds = %45
  %58 = load i32, ptr %10, align 4, !tbaa !9
  %59 = sub nsw i32 %58, 1
  store i32 %59, ptr %8, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %57, %36
  store i32 0, ptr %11, align 4
  br label %61

61:                                               ; preds = %60, %55, %43, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %62 = load i32, ptr %11, align 4
  switch i32 %62, label %67 [
    i32 0, label %63
    i32 1, label %65
  ]

63:                                               ; preds = %61
  br label %12, !llvm.loop !15

64:                                               ; preds = %12
  unreachable

65:                                               ; preds = %61
  %66 = load i32, ptr %5, align 4
  ret i32 %66

67:                                               ; preds = %61
  unreachable
}

; 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 nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIxxESaIS1_EEixEm(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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTSSt4pairIxxE", !12, i64 0, !12, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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 i32 @_Z13binary_searchRSt6vectorISt4pairIxxESaIS1_EEiix(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  br label %.outer

.outer:                                           ; preds = %21, %4
  %.023.ph = phi i32 [ %22, %21 ], [ %2, %4 ]
  %.021.ph = phi i32 [ %.021, %21 ], [ %1, %4 ]
  br label %5

5:                                                ; preds = %.outer, %17
  %.021 = phi i32 [ %18, %17 ], [ %.021.ph, %.outer ]
  %6 = icmp sle i32 %.021, %.023.ph
  tail call void @llvm.assume(i1 %6)
  %7 = add nsw i32 %.021, %.023.ph
  %8 = sdiv i32 %7, 2
  %9 = sext i32 %8 to i64
  %10 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIxxESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %9) #2
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = icmp slt i64 %11, %3
  br i1 %12, label %13, label %19

13:                                               ; preds = %5
  %14 = icmp eq i32 %8, %.023.ph
  br i1 %14, label %15, label %17

15:                                               ; preds = %13
  %16 = add nsw i32 %.023.ph, 1
  br label %.loopexit

17:                                               ; preds = %13
  %18 = add nsw i32 %8, 1
  br label %5

19:                                               ; preds = %5
  %20 = icmp eq i32 %8, %.021
  br i1 %20, label %.loopexit, label %21

21:                                               ; preds = %19
  %22 = add nsw i32 %8, -1
  %23 = sext i32 %22 to i64
  %24 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIxxESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %23) #2
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = icmp slt i64 %25, %3
  br i1 %26, label %.loopexit, label %.outer

.loopexit:                                        ; preds = %19, %21, %15
  %.1.ph = phi i32 [ %16, %15 ], [ %.021, %19 ], [ %8, %21 ]
  ret i32 %.1.ph
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIxxESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #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(inaccessiblemem: write) }
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, !7, i64 0}
!6 = !{!"_ZTSSt4pairIxxE", !7, i64 0, !7, i64 8}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass