; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: Algorithms/Searching/Sources (JumpSearch)

; 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"

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @jumpSearch(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %23

20:                                               ; preds = %5
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str, ptr noundef @.str.1, ptr noundef @.str.2) #4
  call void @exit(i32 noundef -83386157) #5
  unreachable

23:                                               ; preds = %5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %29

26:                                               ; preds = %23
  %27 = load ptr, ptr @stderr, align 8, !tbaa !5
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str.3, ptr noundef @.str.4, ptr noundef @.str.2) #4
  call void @exit(i32 noundef -83384987) #5
  unreachable

29:                                               ; preds = %23
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.3, ptr noundef @.str.5, ptr noundef @.str.2) #4
  call void @exit(i32 noundef -83384987) #5
  unreachable

35:                                               ; preds = %29
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef @.str.3, ptr noundef @.str.6, ptr noundef @.str.2) #4
  call void @exit(i32 noundef -83384987) #5
  unreachable

41:                                               ; preds = %35
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = icmp sle i32 %42, 0
  br i1 %43, label %44, label %47

44:                                               ; preds = %41
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.3, ptr noundef @.str.7, ptr noundef @.str.2) #4
  call void @exit(i32 noundef -83384987) #5
  unreachable

47:                                               ; preds = %41
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = sitofp i32 %52 to double
  %54 = call double @sqrt(double noundef %53) #4
  %55 = fptosi double %54 to i32
  store i32 %55, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %56, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %57, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = mul nsw i32 %59, %60
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %58, i64 %62
  store ptr %63, ptr %15, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %131, %51
  %65 = load ptr, ptr %14, align 8, !tbaa !5
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = mul nsw i32 %67, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i8, ptr %66, i64 %70
  %72 = icmp ult ptr %65, %71
  br i1 %72, label %73, label %139

73:                                               ; preds = %64
  %74 = load ptr, ptr %15, align 8, !tbaa !5
  %75 = load ptr, ptr %13, align 8, !tbaa !5
  %76 = load i32, ptr %9, align 4, !tbaa !9
  %77 = load i32, ptr %10, align 4, !tbaa !9
  %78 = mul nsw i32 %76, %77
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i8, ptr %75, i64 %79
  %81 = icmp ugt ptr %74, %80
  br i1 %81, label %82, label %89

82:                                               ; preds = %73
  %83 = load ptr, ptr %13, align 8, !tbaa !5
  %84 = load i32, ptr %9, align 4, !tbaa !9
  %85 = load i32, ptr %10, align 4, !tbaa !9
  %86 = mul nsw i32 %84, %85
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i8, ptr %83, i64 %87
  store ptr %88, ptr %15, align 8, !tbaa !5
  br label %89

89:                                               ; preds = %82, %73
  %90 = load ptr, ptr %11, align 8, !tbaa !5
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = load ptr, ptr %15, align 8, !tbaa !5
  %93 = load i32, ptr %10, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = sub i64 0, %94
  %96 = getelementptr inbounds i8, ptr %92, i64 %95
  %97 = call i32 %90(ptr noundef %91, ptr noundef %96)
  %98 = icmp sle i32 %97, 0
  br i1 %98, label %99, label %131

99:                                               ; preds = %89
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %100 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %100, ptr %16, align 8, !tbaa !5
  br label %101

101:                                              ; preds = %123, %99
  %102 = load ptr, ptr %16, align 8, !tbaa !5
  %103 = load ptr, ptr %15, align 8, !tbaa !5
  %104 = icmp ult ptr %102, %103
  br i1 %104, label %106, label %105

105:                                              ; preds = %101
  store i32 4, ptr %17, align 4
  br label %128

106:                                              ; preds = %101
  %107 = load ptr, ptr %11, align 8, !tbaa !5
  %108 = load ptr, ptr %8, align 8, !tbaa !5
  %109 = load ptr, ptr %16, align 8, !tbaa !5
  %110 = call i32 %107(ptr noundef %108, ptr noundef %109)
  %111 = icmp eq i32 %110, 0
  br i1 %111, label %112, label %122

112:                                              ; preds = %106
  %113 = load ptr, ptr %16, align 8, !tbaa !5
  %114 = load ptr, ptr %13, align 8, !tbaa !5
  %115 = ptrtoint ptr %113 to i64
  %116 = ptrtoint ptr %114 to i64
  %117 = sub i64 %115, %116
  %118 = load i32, ptr %10, align 4, !tbaa !9
  %119 = sext i32 %118 to i64
  %120 = sdiv i64 %117, %119
  %121 = trunc i64 %120 to i32
  store i32 %121, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %128

122:                                              ; preds = %106
  br label %123

123:                                              ; preds = %122
  %124 = load i32, ptr %10, align 4, !tbaa !9
  %125 = load ptr, ptr %16, align 8, !tbaa !5
  %126 = sext i32 %124 to i64
  %127 = getelementptr inbounds i8, ptr %125, i64 %126
  store ptr %127, ptr %16, align 8, !tbaa !5
  br label %101, !llvm.loop !11

128:                                              ; preds = %112, %105
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  %129 = load i32, ptr %17, align 4
  switch i32 %129, label %140 [
    i32 4, label %130
  ]

130:                                              ; preds = %128
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %140

131:                                              ; preds = %89
  %132 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %132, ptr %14, align 8, !tbaa !5
  %133 = load i32, ptr %12, align 4, !tbaa !9
  %134 = load i32, ptr %10, align 4, !tbaa !9
  %135 = mul nsw i32 %133, %134
  %136 = load ptr, ptr %15, align 8, !tbaa !5
  %137 = sext i32 %135 to i64
  %138 = getelementptr inbounds i8, ptr %136, i64 %137
  store ptr %138, ptr %15, align 8, !tbaa !5
  br label %64, !llvm.loop !13

139:                                              ; preds = %64
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %140

140:                                              ; preds = %139, %130, %128
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %141 = load i32, ptr %6, align 4
  ret i32 %141
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #1

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

attributes #0 = { 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 "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 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }
attributes #5 = { noreturn 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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @jumpSearch(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef readonly %4) local_unnamed_addr #0 {
  %6 = icmp eq ptr %0, null
  br i1 %6, label %7, label %10

7:                                                ; preds = %5
  %8 = load ptr, ptr @stderr, align 8, !tbaa !5
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2) #4
  tail call void @exit(i32 noundef -83386157) #5
  unreachable

10:                                               ; preds = %5
  %11 = icmp eq ptr %1, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %10
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.2) #4
  tail call void @exit(i32 noundef -83384987) #5
  unreachable

15:                                               ; preds = %10
  %16 = icmp eq ptr %4, null
  br i1 %16, label %17, label %20

17:                                               ; preds = %15
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.2) #4
  tail call void @exit(i32 noundef -83384987) #5
  unreachable

20:                                               ; preds = %15
  %21 = icmp slt i32 %2, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %20
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.2) #4
  tail call void @exit(i32 noundef -83384987) #5
  unreachable

25:                                               ; preds = %20
  %26 = icmp slt i32 %3, 1
  br i1 %26, label %27, label %30

27:                                               ; preds = %25
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.2) #4
  tail call void @exit(i32 noundef -83384987) #5
  unreachable

30:                                               ; preds = %25
  %31 = uitofp nneg i32 %2 to double
  %sqrt = tail call double @llvm.sqrt.f64(double %31)
  %32 = fptosi double %sqrt to i32
  %33 = mul nsw i32 %32, %3
  %34 = sext i32 %33 to i64
  %35 = mul nuw nsw i32 %3, %2
  %36 = zext nneg i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %0, i64 %36
  %38 = zext nneg i32 %3 to i64
  %39 = sub nsw i64 0, %38
  br label %40

40:                                               ; preds = %42, %30
  %.044 = phi ptr [ %0, %30 ], [ %spec.select, %42 ]
  %41 = icmp ult ptr %.044, %37
  br i1 %41, label %42, label %.loopexit

42:                                               ; preds = %40
  %.043 = getelementptr inbounds i8, ptr %.044, i64 %34
  %43 = icmp ugt ptr %.043, %37
  %spec.select = select i1 %43, ptr %37, ptr %.043
  %44 = getelementptr inbounds i8, ptr %spec.select, i64 %39
  %45 = tail call i32 %4(ptr noundef nonnull %1, ptr noundef nonnull %44) #6
  %46 = icmp slt i32 %45, 1
  br i1 %46, label %.preheader, label %40, !llvm.loop !9

.preheader:                                       ; preds = %42
  %.not57 = icmp ult ptr %.044, %spec.select
  br i1 %.not57, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %55
  %.04258 = phi ptr [ %56, %55 ], [ %.044, %.preheader ]
  %47 = tail call i32 %4(ptr noundef nonnull %1, ptr noundef %.04258) #6
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %55

49:                                               ; preds = %.lr.ph
  %50 = ptrtoint ptr %.04258 to i64
  %51 = ptrtoint ptr %0 to i64
  %52 = sub i64 %50, %51
  %53 = sdiv i64 %52, %38
  %54 = trunc i64 %53 to i32
  br label %.loopexit

55:                                               ; preds = %.lr.ph
  %56 = getelementptr inbounds i8, ptr %.04258, i64 %38
  %.not = icmp ult ptr %56, %spec.select
  br i1 %.not, label %.lr.ph, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %40, %55, %.preheader, %49
  %.146 = phi i32 [ %54, %49 ], [ -1, %.preheader ], [ -1, %55 ], [ -1, %40 ]
  ret i32 %.146
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.sqrt.f64(double) #3

attributes #0 = { 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 = { nofree nounwind "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 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { cold nounwind }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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