; LLVM IR from CMU-SAFARI/prim-benchmarks :: BS/baselines/cpu (bs_omp)

; 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: nounwind uwtable
define dso_local i64 @binarySearch(ptr noundef %0, i64 noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 -1, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %63, %4
  %15 = load i64, ptr %10, align 8, !tbaa !9
  %16 = load i32, ptr %8, align 4, !tbaa !11
  %17 = zext i32 %16 to i64
  %18 = icmp ult i64 %15, %17
  br i1 %18, label %19, label %66

19:                                               ; preds = %14
  store i64 0, ptr %12, align 8, !tbaa !9
  %20 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %20, ptr %11, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %61, %19
  %22 = load i64, ptr %12, align 8, !tbaa !9
  %23 = load i64, ptr %11, align 8, !tbaa !9
  %24 = icmp ule i64 %22, %23
  br i1 %24, label %25, label %62

25:                                               ; preds = %21
  %26 = load i64, ptr %12, align 8, !tbaa !9
  %27 = load i64, ptr %11, align 8, !tbaa !9
  %28 = load i64, ptr %12, align 8, !tbaa !9
  %29 = sub i64 %27, %28
  %30 = udiv i64 %29, 2
  %31 = add i64 %26, %30
  store i64 %31, ptr %13, align 8, !tbaa !9
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load i64, ptr %13, align 8, !tbaa !9
  %34 = getelementptr inbounds i64, ptr %32, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i64, ptr %10, align 8, !tbaa !9
  %38 = getelementptr inbounds i64, ptr %36, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = icmp eq i64 %35, %39
  br i1 %40, label %41, label %45

41:                                               ; preds = %25
  %42 = load i64, ptr %13, align 8, !tbaa !9
  %43 = load i64, ptr %9, align 8, !tbaa !9
  %44 = add i64 %43, %42
  store i64 %44, ptr %9, align 8, !tbaa !9
  br label %62

45:                                               ; preds = %25
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i64, ptr %13, align 8, !tbaa !9
  %48 = getelementptr inbounds i64, ptr %46, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !9
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i64, ptr %10, align 8, !tbaa !9
  %52 = getelementptr inbounds i64, ptr %50, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !9
  %54 = icmp ult i64 %49, %53
  br i1 %54, label %55, label %58

55:                                               ; preds = %45
  %56 = load i64, ptr %13, align 8, !tbaa !9
  %57 = add i64 %56, 1
  store i64 %57, ptr %12, align 8, !tbaa !9
  br label %61

58:                                               ; preds = %45
  %59 = load i64, ptr %13, align 8, !tbaa !9
  %60 = sub i64 %59, 1
  store i64 %60, ptr %11, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %58, %55
  br label %21, !llvm.loop !13

62:                                               ; preds = %41, %21
  br label %63

63:                                               ; preds = %62
  %64 = load i64, ptr %10, align 8, !tbaa !9
  %65 = add i64 %64, 1
  store i64 %65, ptr %10, align 8, !tbaa !9
  br label %14, !llvm.loop !15

66:                                               ; preds = %14
  %67 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i64 %67
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local i64 @binarySearch(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = zext i32 %3 to i64
  %.not32 = icmp eq i32 %3, 0
  br i1 %.not32, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %4, %.loopexit
  %.031 = phi i64 [ %.1, %.loopexit ], [ -1, %4 ]
  %.02530 = phi i64 [ %21, %.loopexit ], [ 0, %4 ]
  %6 = getelementptr inbounds i64, ptr %2, i64 %.02530
  %7 = load i64, ptr %6, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %.preheader, %17
  %.02129 = phi i64 [ 0, %.preheader ], [ %.122, %17 ]
  %.02328 = phi i64 [ %1, %.preheader ], [ %.124, %17 ]
  %9 = sub i64 %.02328, %.02129
  %10 = lshr i64 %9, 1
  %11 = add i64 %10, %.02129
  %12 = getelementptr inbounds i64, ptr %0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = icmp eq i64 %13, %7
  br i1 %14, label %15, label %17

15:                                               ; preds = %8
  %16 = add i64 %11, %.031
  br label %.loopexit

17:                                               ; preds = %8
  %18 = icmp ult i64 %13, %7
  %19 = add i64 %11, 1
  %20 = add i64 %11, -1
  %.124 = select i1 %18, i64 %.02328, i64 %20
  %.122 = select i1 %18, i64 %19, i64 %.02129
  %.not = icmp ugt i64 %.122, %.124
  br i1 %.not, label %.loopexit, label %8, !llvm.loop !9

.loopexit:                                        ; preds = %17, %15
  %.1 = phi i64 [ %16, %15 ], [ %.031, %17 ]
  %21 = add nuw nsw i64 %.02530, 1
  %exitcond.not = icmp eq i64 %21, %5
  br i1 %exitcond.not, label %._crit_edge, label %.preheader, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %4
  %.0.lcssa = phi i64 [ -1, %4 ], [ %.1, %.loopexit ]
  ret i64 %.0.lcssa
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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" }

!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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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