; LLVM IR from TheAlgorithms/C-Plus-Plus :: search (interpolation_search)

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

15:                                               ; preds = %96, %2
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = icmp ule i64 %16, %17
  br i1 %18, label %19, label %33

19:                                               ; preds = %15
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %21, i64 noundef %22) #2
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = icmp uge i64 %20, %24
  br i1 %25, label %26, label %33

26:                                               ; preds = %19
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %28, i64 noundef %29) #2
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = icmp ule i64 %27, %31
  br label %33

33:                                               ; preds = %26, %19, %15
  %34 = phi i1 [ false, %19 ], [ false, %15 ], [ %32, %26 ]
  br i1 %34, label %35, label %97

35:                                               ; preds = %33
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = load i64, ptr %8, align 8, !tbaa !9
  %38 = icmp eq i64 %36, %37
  br i1 %38, label %39, label %49

39:                                               ; preds = %35
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %40, i64 noundef %41) #2
  %43 = load i64, ptr %42, align 8, !tbaa !9
  %44 = load i64, ptr %5, align 8, !tbaa !9
  %45 = icmp eq i64 %43, %44
  br i1 %45, label %46, label %48

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

48:                                               ; preds = %39
  store i64 -1, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %98

49:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %50 = load i64, ptr %7, align 8, !tbaa !9
  %51 = load i64, ptr %8, align 8, !tbaa !9
  %52 = load i64, ptr %7, align 8, !tbaa !9
  %53 = sub i64 %51, %52
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load i64, ptr %8, align 8, !tbaa !9
  %56 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %54, i64 noundef %55) #2
  %57 = load i64, ptr %56, align 8, !tbaa !9
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = load i64, ptr %7, align 8, !tbaa !9
  %60 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %58, i64 noundef %59) #2
  %61 = load i64, ptr %60, align 8, !tbaa !9
  %62 = sub i64 %57, %61
  %63 = udiv i64 %53, %62
  %64 = load i64, ptr %5, align 8, !tbaa !9
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = load i64, ptr %7, align 8, !tbaa !9
  %67 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %65, i64 noundef %66) #2
  %68 = load i64, ptr %67, align 8, !tbaa !9
  %69 = sub i64 %64, %68
  %70 = mul i64 %63, %69
  %71 = add i64 %50, %70
  store i64 %71, ptr %10, align 8, !tbaa !9
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = load i64, ptr %10, align 8, !tbaa !9
  %74 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %72, i64 noundef %73) #2
  %75 = load i64, ptr %74, align 8, !tbaa !9
  %76 = load i64, ptr %5, align 8, !tbaa !9
  %77 = icmp eq i64 %75, %76
  br i1 %77, label %78, label %80

78:                                               ; preds = %49
  %79 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %79, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %94

80:                                               ; preds = %49
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = load i64, ptr %10, align 8, !tbaa !9
  %83 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %81, i64 noundef %82) #2
  %84 = load i64, ptr %83, align 8, !tbaa !9
  %85 = load i64, ptr %5, align 8, !tbaa !9
  %86 = icmp ult i64 %84, %85
  br i1 %86, label %87, label %90

87:                                               ; preds = %80
  %88 = load i64, ptr %10, align 8, !tbaa !9
  %89 = add i64 %88, 1
  store i64 %89, ptr %7, align 8, !tbaa !9
  br label %93

90:                                               ; preds = %80
  %91 = load i64, ptr %10, align 8, !tbaa !9
  %92 = sub i64 %91, 1
  store i64 %92, ptr %8, align 8, !tbaa !9
  br label %93

93:                                               ; preds = %90, %87
  store i32 0, ptr %9, align 4
  br label %94

94:                                               ; preds = %93, %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %95 = load i32, ptr %9, align 4
  switch i32 %95, label %98 [
    i32 0, label %96
  ]

96:                                               ; preds = %94
  br label %15, !llvm.loop !11

97:                                               ; preds = %33
  store i64 -1, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %98

98:                                               ; preds = %97, %94, %48, %46
  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
  %99 = load i64, ptr %3, align 8
  ret i64 %99
}

; 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 @_ZNKSt6vectorImSaImEE4sizeEv(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 @_ZNKSt6vectorImSaImEEixEm(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", !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 i64 @_ZN6search20interpolation_search19interpolationSearchERKSt6vectorImSaImEEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef i64 @_ZNKSt6vectorImSaImEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %4 = add i64 %3, -1
  br label %5

5:                                                ; preds = %2, %32
  %.03752 = phi i64 [ %4, %2 ], [ %.138, %32 ]
  %.04051 = phi i64 [ 0, %2 ], [ %.141, %32 ]
  %6 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.04051) #1
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %.not44 = icmp ugt i64 %7, %1
  br i1 %.not44, label %.critedge, label %8

8:                                                ; preds = %5
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.03752) #1
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %.not45 = icmp ult i64 %10, %1
  br i1 %.not45, label %.critedge, label %11

11:                                               ; preds = %8
  %12 = icmp eq i64 %.04051, %.03752
  br i1 %12, label %13, label %17

13:                                               ; preds = %11
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.03752) #1
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = icmp eq i64 %15, %1
  %.040. = select i1 %16, i64 %.03752, i64 -1
  br label %.critedge

17:                                               ; preds = %11
  %18 = sub i64 %.03752, %.04051
  %19 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.03752) #1
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.04051) #1
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = sub i64 %20, %22
  %24 = udiv i64 %18, %23
  %25 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.04051) #1
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = sub i64 %1, %26
  %28 = mul i64 %27, %24
  %29 = add i64 %28, %.04051
  %30 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %29) #1
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %.not46 = icmp eq i64 %31, %1
  br i1 %.not46, label %.critedge, label %32

32:                                               ; preds = %17
  %33 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorImSaImEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %29) #1
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = icmp ult i64 %34, %1
  %36 = add i64 %29, 1
  %37 = add i64 %29, -1
  %.141 = select i1 %35, i64 %36, i64 %.04051
  %.138 = select i1 %35, i64 %.03752, i64 %37
  %.not = icmp ugt i64 %.141, %.138
  br i1 %.not, label %.critedge, label %5

.critedge:                                        ; preds = %17, %8, %32, %5, %13
  %.2 = phi i64 [ %.040., %13 ], [ %29, %17 ], [ -1, %8 ], [ -1, %32 ], [ -1, %5 ]
  ret i64 %.2
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorImSaImEE4sizeEv(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 @_ZNKSt6vectorImSaImEEixEm(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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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