; LLVM IR from MakeContributions/DSA :: algorithms/CPlusPlus/Searching/jump-search.ll (Z21recursive_jump_searchPiiiiii)

; 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 uwtable
define dso_local noundef i32 @_Z21recursive_jump_searchPiiiiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %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 %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !9
  %14 = load i32, ptr %10, align 4, !tbaa !9
  %15 = load i32, ptr %11, align 4, !tbaa !9
  %16 = icmp sgt i32 %14, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %6
  store i32 -1, ptr %7, align 4
  br label %59

18:                                               ; preds = %6
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr %19, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = load i32, ptr %12, align 4, !tbaa !9
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %26, label %31

26:                                               ; preds = %18
  %27 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %27, ptr %9, align 4, !tbaa !9
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = load i32, ptr %13, align 4, !tbaa !9
  %30 = add nsw i32 %28, %29
  store i32 %30, ptr %10, align 4, !tbaa !9
  br label %50

31:                                               ; preds = %18
  br label %32

32:                                               ; preds = %46, %31
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = icmp sle i32 %33, %34
  br i1 %35, label %36, label %49

36:                                               ; preds = %32
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr %37, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = load i32, ptr %12, align 4, !tbaa !9
  %43 = icmp eq i32 %41, %42
  br i1 %43, label %44, label %46

44:                                               ; preds = %36
  %45 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %45, ptr %7, align 4
  br label %59

46:                                               ; preds = %36
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %9, align 4, !tbaa !9
  br label %32, !llvm.loop !11

49:                                               ; preds = %32
  store i32 -1, ptr %7, align 4
  br label %59

50:                                               ; preds = %26
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = load i32, ptr %11, align 4, !tbaa !9
  %56 = load i32, ptr %12, align 4, !tbaa !9
  %57 = load i32, ptr %13, align 4, !tbaa !9
  %58 = call noundef i32 @_Z21recursive_jump_searchPiiiiii(ptr noundef %52, i32 noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %56, i32 noundef %57)
  store i32 %58, ptr %7, align 4
  br label %59

59:                                               ; preds = %51, %49, %44, %17
  %60 = load i32, ptr %7, align 4
  ret i32 %60
}

attributes #0 = { mustprogress 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 = !{!"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 nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef i32 @_Z21recursive_jump_searchPiiiiii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = icmp sgt i32 %2, %3
  br i1 %7, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %6
  %8 = sext i32 %2 to i64
  %9 = sext i32 %5 to i64
  %10 = sext i32 %3 to i64
  %11 = getelementptr inbounds i32, ptr %0, i64 %8
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp slt i32 %12, %4
  br i1 %13, label %tailrecurse, label %.preheader

.lr.ph:                                           ; preds = %tailrecurse
  %14 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp slt i32 %15, %4
  br i1 %16, label %tailrecurse, label %.lr.ph..preheader_crit_edge

.lr.ph..preheader_crit_edge:                      ; preds = %.lr.ph
  %17 = trunc nsw i64 %indvars.iv56 to i32
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph..preheader_crit_edge, %.lr.ph.preheader
  %indvars.iv.lcssa = phi i64 [ %indvars.iv.next, %.lr.ph..preheader_crit_edge ], [ %8, %.lr.ph.preheader ]
  %.tr2533.lcssa = phi i32 [ %17, %.lr.ph..preheader_crit_edge ], [ %1, %.lr.ph.preheader ]
  %18 = trunc nsw i64 %indvars.iv.lcssa to i32
  %.not35 = icmp sgt i32 %.tr2533.lcssa, %18
  br i1 %.not35, label %.loopexit, label %.lr.ph37.preheader

.lr.ph37.preheader:                               ; preds = %.preheader
  %19 = sext i32 %.tr2533.lcssa to i64
  %sext = shl i64 %indvars.iv.lcssa, 32
  %20 = ashr exact i64 %sext, 32
  br label %.lr.ph37

tailrecurse:                                      ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv56 = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %8, %.lr.ph.preheader ]
  %indvars.iv.next = add nsw i64 %indvars.iv56, %9
  %21 = icmp sgt i64 %indvars.iv.next, %10
  br i1 %21, label %.loopexit, label %.lr.ph

.lr.ph37:                                         ; preds = %.lr.ph37.preheader, %25
  %indvars.iv44 = phi i64 [ %19, %.lr.ph37.preheader ], [ %indvars.iv.next45, %25 ]
  %22 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv44
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp eq i32 %23, %4
  br i1 %24, label %.loopexit.loopexit.split.loop.exit50, label %25

25:                                               ; preds = %.lr.ph37
  %indvars.iv.next45 = add nsw i64 %indvars.iv44, 1
  %.not.not = icmp slt i64 %indvars.iv44, %20
  br i1 %.not.not, label %.lr.ph37, label %.loopexit, !llvm.loop !9

.loopexit.loopexit.split.loop.exit50:             ; preds = %.lr.ph37
  %26 = trunc nsw i64 %indvars.iv44 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %tailrecurse, %25, %.loopexit.loopexit.split.loop.exit50, %6, %.preheader
  %.0 = phi i32 [ -1, %.preheader ], [ -1, %6 ], [ %26, %.loopexit.loopexit.split.loop.exit50 ], [ -1, %25 ], [ -1, %tailrecurse ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass