; LLVM IR from zumrudu-anka/Algorithms :: C++/Searching Algorithms/Jump Search/JumpSearch.ll (Z10JumpSearchPiii)

; 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 ptr @_Z10JumpSearchPiii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %14)
  %16 = fptosi double %15 to i32
  store i32 %16, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %17 = call noalias noundef nonnull ptr @_Znam(i64 noundef 8) #5
  store ptr %17, ptr %9, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = getelementptr inbounds i32, ptr %18, i64 0
  store i32 0, ptr %19, align 4, !tbaa !9
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = getelementptr inbounds i32, ptr %20, i64 1
  store i32 -1, ptr %21, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %22 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %22, ptr %10, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %104, %3
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 2, ptr %11, align 4
  br label %108

28:                                               ; preds = %23
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i32, ptr %29, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = icmp sgt i32 %33, %34
  br i1 %35, label %36, label %67

36:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = sub nsw i32 %37, %38
  store i32 %39, ptr %12, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %61, %36
  %41 = load i32, ptr %12, align 4, !tbaa !9
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  store i32 5, ptr %11, align 4
  br label %64

45:                                               ; preds = %40
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr %46, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = icmp eq i32 %50, %51
  br i1 %52, label %53, label %60

53:                                               ; preds = %45
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds i32, ptr %54, i64 0
  store i32 1, ptr %55, align 4, !tbaa !9
  %56 = load i32, ptr %12, align 4, !tbaa !9
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds i32, ptr %57, i64 1
  store i32 %56, ptr %58, align 4, !tbaa !9
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %59, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %64

60:                                               ; preds = %45
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %12, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %12, align 4, !tbaa !9
  br label %40, !llvm.loop !11

64:                                               ; preds = %53, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %65 = load i32, ptr %11, align 4
  switch i32 %65, label %108 [
    i32 5, label %66
  ]

66:                                               ; preds = %64
  br label %103

67:                                               ; preds = %28
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = add nsw i32 %68, %69
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = icmp sge i32 %70, %71
  br i1 %72, label %73, label %102

73:                                               ; preds = %67
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %74 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %74, ptr %13, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %96, %73
  %76 = load i32, ptr %13, align 4, !tbaa !9
  %77 = load i32, ptr %6, align 4, !tbaa !9
  %78 = icmp slt i32 %76, %77
  br i1 %78, label %80, label %79

79:                                               ; preds = %75
  store i32 8, ptr %11, align 4
  br label %99

80:                                               ; preds = %75
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i32, ptr %13, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i32, ptr %81, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !9
  %86 = load i32, ptr %7, align 4, !tbaa !9
  %87 = icmp eq i32 %85, %86
  br i1 %87, label %88, label %95

88:                                               ; preds = %80
  %89 = load ptr, ptr %9, align 8, !tbaa !5
  %90 = getelementptr inbounds i32, ptr %89, i64 0
  store i32 1, ptr %90, align 4, !tbaa !9
  %91 = load i32, ptr %13, align 4, !tbaa !9
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = getelementptr inbounds i32, ptr %92, i64 1
  store i32 %91, ptr %93, align 4, !tbaa !9
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %94, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %99

95:                                               ; preds = %80
  br label %96

96:                                               ; preds = %95
  %97 = load i32, ptr %13, align 4, !tbaa !9
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %13, align 4, !tbaa !9
  br label %75, !llvm.loop !13

99:                                               ; preds = %88, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  %100 = load i32, ptr %11, align 4
  switch i32 %100, label %108 [
    i32 8, label %101
  ]

101:                                              ; preds = %99
  br label %102

102:                                              ; preds = %101, %67
  br label %103

103:                                              ; preds = %102, %66
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %8, align 4, !tbaa !9
  %106 = load i32, ptr %10, align 4, !tbaa !9
  %107 = add nsw i32 %106, %105
  store i32 %107, ptr %10, align 4, !tbaa !9
  br label %23, !llvm.loop !14

108:                                              ; preds = %99, %64, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %109 = load i32, ptr %11, align 4
  switch i32 %109, label %112 [
    i32 2, label %110
  ]

110:                                              ; preds = %108
  %111 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %111, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %112

112:                                              ; preds = %110, %108
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %113 = load ptr, ptr %4, align 8
  ret ptr %113
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #3

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { nobuiltin allocsize(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 #4 = { nounwind }
attributes #5 = { builtin allocsize(0) }

!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"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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 uwtable
define dso_local noalias noundef nonnull ptr @_Z10JumpSearchPiii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %1)
  %5 = fptosi double %4 to i32
  %6 = tail call noalias noundef nonnull dereferenceable(8) ptr @_Znam(i64 noundef 8) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 -1, ptr %7, align 4, !tbaa !5
  %.not5467 = icmp slt i32 %5, %1
  br i1 %.not5467, label %.lr.ph70.preheader, label %.loopexit59

.lr.ph70.preheader:                               ; preds = %3
  %8 = sext i32 %5 to i64
  %9 = sext i32 %1 to i64
  %invariant.op = sub nsw i64 %9, %8
  %.not5364 = icmp sgt i32 %5, 0
  br label %.lr.ph70

.lr.ph70:                                         ; preds = %.lr.ph70.preheader, %.loopexit
  %indvars.iv77 = phi i32 [ 0, %.lr.ph70.preheader ], [ %indvars.iv.next78, %.loopexit ]
  %indvars.iv = phi i64 [ %8, %.lr.ph70.preheader ], [ %indvars.iv.next, %.loopexit ]
  %10 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, %2
  br i1 %12, label %13, label %19

13:                                               ; preds = %.lr.ph70
  br i1 %.not5364, label %.lr.ph66.preheader, label %.loopexit

.lr.ph66.preheader:                               ; preds = %13
  %14 = sext i32 %indvars.iv77 to i64
  br label %.lr.ph66

.lr.ph66:                                         ; preds = %.lr.ph66.preheader, %18
  %indvars.iv79 = phi i64 [ %indvars.iv.next80, %18 ], [ %14, %.lr.ph66.preheader ]
  %15 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv79
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = icmp eq i32 %16, %2
  br i1 %17, label %.loopexit59.sink.split, label %18

18:                                               ; preds = %.lr.ph66
  %indvars.iv.next80 = add nsw i64 %indvars.iv79, 1
  %.not53 = icmp slt i64 %indvars.iv.next80, %indvars.iv
  br i1 %.not53, label %.lr.ph66, label %.loopexit, !llvm.loop !9

19:                                               ; preds = %.lr.ph70
  %.not.not = icmp slt i64 %indvars.iv, %invariant.op
  br i1 %.not.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %19, %23
  %indvars.iv74 = phi i64 [ %indvars.iv.next75, %23 ], [ %indvars.iv, %19 ]
  %20 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv74
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp eq i32 %21, %2
  br i1 %22, label %.loopexit59.sink.split, label %23

23:                                               ; preds = %.lr.ph
  %indvars.iv.next75 = add nsw i64 %indvars.iv74, 1
  %.not52 = icmp slt i64 %indvars.iv.next75, %9
  br i1 %.not52, label %.lr.ph, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %23, %18, %13, %19
  %indvars.iv.next = add nsw i64 %indvars.iv, %8
  %.not54 = icmp slt i64 %indvars.iv.next, %9
  %indvars.iv.next78 = add i32 %indvars.iv77, %5
  br i1 %.not54, label %.lr.ph70, label %.loopexit59, !llvm.loop !12

.loopexit59.sink.split:                           ; preds = %.lr.ph, %.lr.ph66
  %indvars.iv74.lcssa.sink = phi i64 [ %indvars.iv79, %.lr.ph66 ], [ %indvars.iv74, %.lr.ph ]
  %24 = trunc nsw i64 %indvars.iv74.lcssa.sink to i32
  store i32 1, ptr %6, align 4, !tbaa !5
  store i32 %24, ptr %7, align 4, !tbaa !5
  br label %.loopexit59

.loopexit59:                                      ; preds = %.loopexit, %.loopexit59.sink.split, %3
  ret ptr %6
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #2

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" }
attributes #1 = { inlinehint 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 = { nobuiltin allocsize(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 #3 = { builtin allocsize(0) }

!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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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