; LLVM IR from alenic/realGA :: src/algorithms.ll (ZN4RALG23searchIndexBinarySearchESt6vectorIfSaIfEEfii)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN4RALG23searchIndexBinarySearchESt6vectorIfSaIfEEfii(ptr noundef %0, float noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store float %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !11
  store i32 %3, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %14 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %14, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %15 = load i32, ptr %9, align 4, !tbaa !11
  store i32 %15, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %81, %4
  %17 = load i32, ptr %10, align 4, !tbaa !11
  %18 = load i32, ptr %11, align 4, !tbaa !11
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %82

20:                                               ; preds = %16
  %21 = load i32, ptr %11, align 4, !tbaa !11
  %22 = load i32, ptr %10, align 4, !tbaa !11
  %23 = add nsw i32 %21, %22
  %24 = sdiv i32 %23, 2
  store i32 %24, ptr %12, align 4, !tbaa !11
  %25 = load i32, ptr %10, align 4, !tbaa !11
  %26 = load i32, ptr %11, align 4, !tbaa !11
  %27 = icmp eq i32 %25, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %20
  %29 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %29, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %84

30:                                               ; preds = %20
  %31 = load i32, ptr %11, align 4, !tbaa !11
  %32 = load i32, ptr %10, align 4, !tbaa !11
  %33 = add nsw i32 %32, 1
  %34 = icmp eq i32 %31, %33
  br i1 %34, label %35, label %61

35:                                               ; preds = %30
  %36 = load float, ptr %7, align 4, !tbaa !9
  %37 = load i32, ptr %10, align 4, !tbaa !11
  %38 = sext i32 %37 to i64
  %39 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %38) #2
  %40 = load float, ptr %39, align 4, !tbaa !9
  %41 = fcmp ogt float %36, %40
  br i1 %41, label %42, label %51

42:                                               ; preds = %35
  %43 = load float, ptr %7, align 4, !tbaa !9
  %44 = load i32, ptr %11, align 4, !tbaa !11
  %45 = sext i32 %44 to i64
  %46 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %45) #2
  %47 = load float, ptr %46, align 4, !tbaa !9
  %48 = fcmp olt float %43, %47
  br i1 %48, label %49, label %51

49:                                               ; preds = %42
  %50 = load i32, ptr %10, align 4, !tbaa !11
  store i32 %50, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %84

51:                                               ; preds = %42, %35
  %52 = load float, ptr %7, align 4, !tbaa !9
  %53 = load i32, ptr %11, align 4, !tbaa !11
  %54 = sext i32 %53 to i64
  %55 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %54) #2
  %56 = load float, ptr %55, align 4, !tbaa !9
  %57 = fcmp ogt float %52, %56
  br i1 %57, label %58, label %60

58:                                               ; preds = %51
  %59 = load i32, ptr %11, align 4, !tbaa !11
  store i32 %59, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %84

60:                                               ; preds = %51
  br label %61

61:                                               ; preds = %60, %30
  %62 = load i32, ptr %12, align 4, !tbaa !11
  %63 = sext i32 %62 to i64
  %64 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %63) #2
  %65 = load float, ptr %64, align 4, !tbaa !9
  %66 = load float, ptr %7, align 4, !tbaa !9
  %67 = fcmp oeq float %65, %66
  br i1 %67, label %68, label %70

68:                                               ; preds = %61
  %69 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %69, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %84

70:                                               ; preds = %61
  %71 = load i32, ptr %12, align 4, !tbaa !11
  %72 = sext i32 %71 to i64
  %73 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %72) #2
  %74 = load float, ptr %73, align 4, !tbaa !9
  %75 = load float, ptr %7, align 4, !tbaa !9
  %76 = fcmp olt float %74, %75
  br i1 %76, label %77, label %79

77:                                               ; preds = %70
  %78 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %78, ptr %10, align 4, !tbaa !11
  br label %81

79:                                               ; preds = %70
  %80 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %80, ptr %11, align 4, !tbaa !11
  br label %81

81:                                               ; preds = %79, %77
  br label %16, !llvm.loop !13

82:                                               ; preds = %16
  %83 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %83, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %84

84:                                               ; preds = %82, %68, %58, %49, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %85 = load i32, ptr %5, align 4
  ret i32 %85
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN4RALG23searchIndexBinarySearchESt6vectorIfSaIfEEfii(ptr noundef %0, float noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp slt i32 %2, %3
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4, %28
  %.02735 = phi i32 [ %.027., %28 ], [ %3, %4 ]
  %.02833 = phi i32 [ %..028, %28 ], [ %2, %4 ]
  %6 = add nsw i32 %.02735, %.02833
  %7 = sdiv i32 %6, 2
  %8 = add nsw i32 %.02833, 1
  %9 = icmp eq i32 %.02735, %8
  br i1 %9, label %10, label %23

10:                                               ; preds = %.lr.ph
  %11 = sext i32 %.02833 to i64
  %12 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %11) #1
  %13 = load float, ptr %12, align 4, !tbaa !5
  %14 = fcmp olt float %13, %1
  %15 = sext i32 %.02735 to i64
  br i1 %14, label %16, label %._crit_edge42

16:                                               ; preds = %10
  %17 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %15) #1
  %18 = load float, ptr %17, align 4, !tbaa !5
  %19 = fcmp ogt float %18, %1
  br i1 %19, label %._crit_edge, label %._crit_edge42

._crit_edge42:                                    ; preds = %10, %16
  %20 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %15) #1
  %21 = load float, ptr %20, align 4, !tbaa !5
  %22 = fcmp olt float %21, %1
  br i1 %22, label %._crit_edge, label %23

23:                                               ; preds = %._crit_edge42, %.lr.ph
  %24 = sext i32 %7 to i64
  %25 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %24) #1
  %26 = load float, ptr %25, align 4, !tbaa !5
  %27 = fcmp oeq float %26, %1
  br i1 %27, label %._crit_edge, label %28

28:                                               ; preds = %23
  %29 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIfSaIfEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %24) #1
  %30 = load float, ptr %29, align 4, !tbaa !5
  %31 = fcmp olt float %30, %1
  %..028 = select i1 %31, i32 %7, i32 %.02833
  %.027. = select i1 %31, i32 %.02735, i32 %7
  %32 = icmp slt i32 %..028, %.027.
  br i1 %32, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %16, %._crit_edge42, %23, %28, %4
  %.030 = phi i32 [ 0, %4 ], [ %7, %28 ], [ %7, %23 ], [ %.02735, %._crit_edge42 ], [ %.02833, %16 ]
  ret i32 %.030
}

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 = !{!"float", !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,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass