; LLVM IR from CodersForLife/Data-Structures-Algorithms :: Arrays/SearchRotatedSortedArray.ll (Z6searchRSt6vectorIiSaIiEEi)

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

16:                                               ; preds = %109, %2
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = icmp sle i32 %17, %18
  br i1 %19, label %20, label %110

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = sub nsw i32 %22, %23
  %25 = sdiv i32 %24, 2
  %26 = add nsw i32 %21, %25
  store i32 %26, ptr %9, align 4, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %27, i64 noundef %29) #2
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = icmp eq i32 %31, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %20
  %35 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %35, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %107

36:                                               ; preds = %20
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %37, i64 noundef %39) #2
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = icmp sgt i32 %41, %42
  br i1 %43, label %44, label %75

44:                                               ; preds = %36
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %45, i64 noundef %47) #2
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %50, i64 noundef %52) #2
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = icmp sle i32 %49, %54
  br i1 %55, label %56, label %59

56:                                               ; preds = %44
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = sub nsw i32 %57, 1
  store i32 %58, ptr %8, align 4, !tbaa !9
  br label %74

59:                                               ; preds = %44
  %60 = load i32, ptr %5, align 4, !tbaa !9
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %61, i64 noundef %63) #2
  %65 = load i32, ptr %64, align 4, !tbaa !9
  %66 = icmp sgt i32 %60, %65
  br i1 %66, label %67, label %70

67:                                               ; preds = %59
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = sub nsw i32 %68, 1
  store i32 %69, ptr %8, align 4, !tbaa !9
  br label %73

70:                                               ; preds = %59
  %71 = load i32, ptr %9, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %7, align 4, !tbaa !9
  br label %73

73:                                               ; preds = %70, %67
  br label %74

74:                                               ; preds = %73, %56
  br label %106

75:                                               ; preds = %36
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %76, i64 noundef %78) #2
  %80 = load i32, ptr %79, align 4, !tbaa !9
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %81, i64 noundef %83) #2
  %85 = load i32, ptr %84, align 4, !tbaa !9
  %86 = icmp sge i32 %80, %85
  br i1 %86, label %87, label %90

87:                                               ; preds = %75
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %7, align 4, !tbaa !9
  br label %105

90:                                               ; preds = %75
  %91 = load i32, ptr %5, align 4, !tbaa !9
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  %93 = load i32, ptr %8, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %92, i64 noundef %94) #2
  %96 = load i32, ptr %95, align 4, !tbaa !9
  %97 = icmp sgt i32 %91, %96
  br i1 %97, label %98, label %101

98:                                               ; preds = %90
  %99 = load i32, ptr %9, align 4, !tbaa !9
  %100 = sub nsw i32 %99, 1
  store i32 %100, ptr %8, align 4, !tbaa !9
  br label %104

101:                                              ; preds = %90
  %102 = load i32, ptr %9, align 4, !tbaa !9
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %7, align 4, !tbaa !9
  br label %104

104:                                              ; preds = %101, %98
  br label %105

105:                                              ; preds = %104, %87
  br label %106

106:                                              ; preds = %105, %74
  store i32 0, ptr %10, align 4
  br label %107

107:                                              ; preds = %106, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %108 = load i32, ptr %10, align 4
  switch i32 %108, label %111 [
    i32 0, label %109
  ]

109:                                              ; preds = %107
  br label %16, !llvm.loop !11

110:                                              ; preds = %16
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %111

111:                                              ; preds = %110, %107
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %112 = load i32, ptr %3, align 4
  ret i32 %112
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(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 = 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 i32 @_Z6searchRSt6vectorIiSaIiEEi(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %4 = trunc i64 %3 to i32
  %.not49 = icmp slt i32 %4, 1
  br i1 %.not49, label %.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %5 = add nsw i32 %4, -1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %47
  %.03651 = phi i32 [ %.238, %47 ], [ %5, %.lr.ph.preheader ]
  %.03950 = phi i32 [ %.241, %47 ], [ 0, %.lr.ph.preheader ]
  %6 = sub nsw i32 %.03651, %.03950
  %7 = sdiv i32 %6, 2
  %8 = add nsw i32 %7, %.03950
  %9 = sext i32 %8 to i64
  %10 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %9) #1
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %.not45 = icmp eq i32 %11, %1
  br i1 %.not45, label %.thread, label %12

12:                                               ; preds = %.lr.ph
  %13 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %9) #1
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp sgt i32 %14, %1
  %16 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %9) #1
  %17 = load i32, ptr %16, align 4, !tbaa !5
  br i1 %15, label %18, label %32

18:                                               ; preds = %12
  %19 = sext i32 %.03651 to i64
  %20 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %19) #1
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not44 = icmp sgt i32 %17, %21
  br i1 %.not44, label %24, label %22

22:                                               ; preds = %18
  %23 = add nsw i32 %8, -1
  br label %47

24:                                               ; preds = %18
  %25 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %19) #1
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp slt i32 %26, %1
  br i1 %27, label %28, label %30

28:                                               ; preds = %24
  %29 = add nsw i32 %8, -1
  br label %47

30:                                               ; preds = %24
  %31 = add nsw i32 %8, 1
  br label %47

32:                                               ; preds = %12
  %33 = sext i32 %.03950 to i64
  %34 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %33) #1
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %.not43 = icmp slt i32 %17, %35
  br i1 %.not43, label %38, label %36

36:                                               ; preds = %32
  %37 = add nsw i32 %8, 1
  br label %47

38:                                               ; preds = %32
  %39 = sext i32 %.03651 to i64
  %40 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %39) #1
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp slt i32 %41, %1
  br i1 %42, label %43, label %45

43:                                               ; preds = %38
  %44 = add nsw i32 %8, -1
  br label %47

45:                                               ; preds = %38
  %46 = add nsw i32 %8, 1
  br label %47

47:                                               ; preds = %28, %30, %22, %43, %45, %36
  %.241 = phi i32 [ %.03950, %22 ], [ %.03950, %28 ], [ %31, %30 ], [ %37, %36 ], [ %.03950, %43 ], [ %46, %45 ]
  %.238 = phi i32 [ %23, %22 ], [ %29, %28 ], [ %.03651, %30 ], [ %.03651, %36 ], [ %44, %43 ], [ %.03651, %45 ]
  %.not = icmp sgt i32 %.241, %.238
  br i1 %.not, label %.thread, label %.lr.ph

.thread:                                          ; preds = %47, %.lr.ph, %2
  %.2 = phi i32 [ -1, %2 ], [ %8, %.lr.ph ], [ -1, %47 ]
  ret i32 %.2
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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