; LLVM IR from DionysiosB/CodeForces :: 0400-0499/474B-Worms-OLD.ll (Z12binarySearchSt6vectorIlSaIlEEl)

; 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 i64 @_Z12binarySearchSt6vectorIlSaIlEEl(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %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
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #2
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = icmp slt i64 %10, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i64 0, ptr %3, align 8
  br label %71

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %16 = call noundef i64 @_ZNKSt6vectorIlSaIlEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %17 = sub i64 %16, 1
  store i64 %17, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = load i64, ptr %7, align 8, !tbaa !9
  %20 = add nsw i64 %18, %19
  %21 = sdiv i64 %20, 2
  store i64 %21, ptr %8, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %65, %15
  br label %23

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

29:                                               ; preds = %23
  %30 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %30, ptr %7, align 8, !tbaa !9
  br label %49

31:                                               ; preds = %23
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %33) #2
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = icmp sgt i64 %32, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %31
  %38 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %38, ptr %6, align 8, !tbaa !9
  br label %48

39:                                               ; preds = %31
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %41) #2
  %43 = load i64, ptr %42, align 8, !tbaa !9
  %44 = icmp eq i64 %40, %43
  br i1 %44, label %45, label %47

45:                                               ; preds = %39
  %46 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %46, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %70

47:                                               ; preds = %39
  br label %48

48:                                               ; preds = %47, %37
  br label %49

49:                                               ; preds = %48, %29
  %50 = load i64, ptr %7, align 8, !tbaa !9
  %51 = load i64, ptr %6, align 8, !tbaa !9
  %52 = add nsw i64 %51, 1
  %53 = icmp sle i64 %50, %52
  br i1 %53, label %54, label %65

54:                                               ; preds = %49
  %55 = load i64, ptr %5, align 8, !tbaa !9
  %56 = load i64, ptr %6, align 8, !tbaa !9
  %57 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %56) #2
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = icmp eq i64 %55, %58
  br i1 %59, label %60, label %62

60:                                               ; preds = %54
  %61 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %61, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %70

62:                                               ; preds = %54
  %63 = load i64, ptr %6, align 8, !tbaa !9
  %64 = add nsw i64 %63, 1
  store i64 %64, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %70

65:                                               ; preds = %49
  %66 = load i64, ptr %6, align 8, !tbaa !9
  %67 = load i64, ptr %7, align 8, !tbaa !9
  %68 = add nsw i64 %66, %67
  %69 = sdiv i64 %68, 2
  store i64 %69, ptr %8, align 8, !tbaa !9
  br label %22, !llvm.loop !11

70:                                               ; preds = %62, %60, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %71

71:                                               ; preds = %70, %14
  %72 = load i64, ptr %3, align 8
  ret i64 %72
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(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.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIlSaIlEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #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", !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 range(i64 -4611686018427387904, 4611686018427387905) i64 @_Z12binarySearchSt6vectorIlSaIlEEl(ptr noundef nonnull %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #1
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp sgt i64 %4, %1
  br i1 %5, label %.loopexit, label %6

6:                                                ; preds = %2
  %7 = tail call noundef i64 @_ZNKSt6vectorIlSaIlEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %8 = add i64 %7, -1
  br label %9

9:                                                ; preds = %21, %6
  %.022 = phi i64 [ 0, %6 ], [ %.123, %21 ]
  %.021 = phi i64 [ %8, %6 ], [ %.1, %21 ]
  %.0.in = phi i64 [ %8, %6 ], [ %23, %21 ]
  %.0 = sdiv i64 %.0.in, 2
  %10 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.0) #1
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = icmp sgt i64 %11, %1
  br i1 %12, label %21, label %13

13:                                               ; preds = %9
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.0) #1
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = icmp slt i64 %15, %1
  br i1 %16, label %21, label %17

17:                                               ; preds = %13
  %18 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.0) #1
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = icmp eq i64 %19, %1
  br i1 %20, label %.loopexit, label %21

21:                                               ; preds = %13, %9, %17
  %.123 = phi i64 [ %.022, %17 ], [ %.022, %9 ], [ %.0, %13 ]
  %.1 = phi i64 [ %.021, %17 ], [ %.0, %9 ], [ %.021, %13 ]
  %22 = add nsw i64 %.123, 1
  %.not = icmp sgt i64 %.1, %22
  %23 = add nsw i64 %.1, %.123
  br i1 %.not, label %9, label %24, !llvm.loop !9

24:                                               ; preds = %21
  %25 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.123) #1
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = icmp eq i64 %26, %1
  %.123. = select i1 %27, i64 %.123, i64 %22
  br label %.loopexit

.loopexit:                                        ; preds = %17, %24, %2
  %.125 = phi i64 [ 0, %2 ], [ %.123., %24 ], [ %.0, %17 ]
  ret i64 %.125
}

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

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


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