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

; 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 [19 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 @exponentialSearch(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %22

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

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

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

28:                                               ; preds = %22
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %34

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

34:                                               ; preds = %28
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = icmp slt i32 %35, 0
  br i1 %36, label %37, label %40

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

40:                                               ; preds = %34
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = icmp sle i32 %41, 0
  br i1 %42, label %43, label %46

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

46:                                               ; preds = %40
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %51, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %52, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %53, ptr %13, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %95, %50
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  %58 = call i32 %55(ptr noundef %56, ptr noundef %57)
  %59 = icmp sgt i32 %58, 0
  br i1 %59, label %60, label %96

60:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %61 = load ptr, ptr %13, align 8, !tbaa !5
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = ptrtoint ptr %61 to i64
  %64 = ptrtoint ptr %62 to i64
  %65 = sub i64 %63, %64
  %66 = add nsw i64 %65, 1
  %67 = trunc i64 %66 to i32
  store i32 %67, ptr %14, align 4, !tbaa !9
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %68, ptr %12, align 8, !tbaa !5
  %69 = load i32, ptr %14, align 4, !tbaa !9
  %70 = mul nsw i32 %69, 2
  %71 = load i32, ptr %9, align 4, !tbaa !9
  %72 = mul nsw i32 %70, %71
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = sext i32 %72 to i64
  %75 = getelementptr inbounds i8, ptr %73, i64 %74
  store ptr %75, ptr %13, align 8, !tbaa !5
  %76 = load ptr, ptr %13, align 8, !tbaa !5
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = load i32, ptr %9, align 4, !tbaa !9
  %80 = mul nsw i32 %78, %79
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds i8, ptr %77, i64 %81
  %83 = icmp uge ptr %76, %82
  br i1 %83, label %84, label %92

84:                                               ; preds = %60
  %85 = load ptr, ptr %11, align 8, !tbaa !5
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = sub nsw i32 %86, 1
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = mul nsw i32 %87, %88
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i8, ptr %85, i64 %90
  store ptr %91, ptr %13, align 8, !tbaa !5
  store i32 3, ptr %15, align 4
  br label %93

92:                                               ; preds = %60
  store i32 0, ptr %15, align 4
  br label %93

93:                                               ; preds = %92, %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  %94 = load i32, ptr %15, align 4
  switch i32 %94, label %127 [
    i32 0, label %95
    i32 3, label %96
  ]

95:                                               ; preds = %93
  br label %54, !llvm.loop !11

96:                                               ; preds = %93, %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  %97 = load ptr, ptr %12, align 8, !tbaa !5
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = load ptr, ptr %13, align 8, !tbaa !5
  %100 = load ptr, ptr %12, align 8, !tbaa !5
  %101 = ptrtoint ptr %99 to i64
  %102 = ptrtoint ptr %100 to i64
  %103 = sub i64 %101, %102
  %104 = add nsw i64 %103, 1
  %105 = trunc i64 %104 to i32
  %106 = load i32, ptr %9, align 4, !tbaa !9
  %107 = load ptr, ptr %10, align 8, !tbaa !5
  %108 = call i32 @binarySearchI(ptr noundef %97, ptr noundef %98, i32 noundef %105, i32 noundef %106, ptr noundef %107)
  store i32 %108, ptr %16, align 4, !tbaa !9
  %109 = load i32, ptr %16, align 4, !tbaa !9
  %110 = icmp eq i32 %109, -1
  br i1 %110, label %111, label %112

111:                                              ; preds = %96
  br label %124

112:                                              ; preds = %96
  %113 = load i32, ptr %16, align 4, !tbaa !9
  %114 = sext i32 %113 to i64
  %115 = load ptr, ptr %12, align 8, !tbaa !5
  %116 = load ptr, ptr %11, align 8, !tbaa !5
  %117 = ptrtoint ptr %115 to i64
  %118 = ptrtoint ptr %116 to i64
  %119 = sub i64 %117, %118
  %120 = load i32, ptr %9, align 4, !tbaa !9
  %121 = sext i32 %120 to i64
  %122 = sdiv i64 %119, %121
  %123 = add nsw i64 %114, %122
  br label %124

124:                                              ; preds = %112, %111
  %125 = phi i64 [ -1, %111 ], [ %123, %112 ]
  %126 = trunc i64 %125 to i32
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  ret i32 %126

127:                                              ; preds = %93
  unreachable
}

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

declare i32 @binarySearchI(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) #4

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 = { "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 #5 = { nounwind }
attributes #6 = { 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"}


; 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 [19 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 @exponentialSearch(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %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 %30, label %.preheader

.preheader:                                       ; preds = %25
  %27 = mul nuw nsw i32 %3, %2
  %28 = zext nneg i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %0, i64 %28
  br label %33

30:                                               ; preds = %25
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, 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

33:                                               ; preds = %.preheader, %36
  %.036 = phi ptr [ %45, %36 ], [ %0, %.preheader ]
  %.0 = phi ptr [ %.036, %36 ], [ %0, %.preheader ]
  %34 = tail call i32 %4(ptr noundef nonnull %1, ptr noundef %.036) #6
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %36, label %.split.loop.exit45.loopexit

36:                                               ; preds = %33
  %37 = ptrtoint ptr %.036 to i64
  %38 = ptrtoint ptr %.0 to i64
  %39 = sub i64 %37, %38
  %40 = trunc i64 %39 to i32
  %41 = shl i32 %40, 1
  %42 = add i32 %41, 2
  %43 = mul nsw i32 %42, %3
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %.036, i64 %44
  %.not = icmp ult ptr %45, %29
  br i1 %.not, label %33, label %.split.loop.exit

.split.loop.exit:                                 ; preds = %36
  %46 = add nsw i32 %2, -1
  %47 = mul nsw i32 %46, %3
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %0, i64 %48
  br label %.split.loop.exit45

.split.loop.exit45.loopexit:                      ; preds = %33
  %.pre = ptrtoint ptr %.0 to i64
  br label %.split.loop.exit45

.split.loop.exit45:                               ; preds = %.split.loop.exit45.loopexit, %.split.loop.exit
  %.pre-phi = phi i64 [ %.pre, %.split.loop.exit45.loopexit ], [ %37, %.split.loop.exit ]
  %.2 = phi ptr [ %.036, %.split.loop.exit45.loopexit ], [ %49, %.split.loop.exit ]
  %.1 = phi ptr [ %.0, %.split.loop.exit45.loopexit ], [ %.036, %.split.loop.exit ]
  %50 = ptrtoint ptr %.2 to i64
  %51 = sub i64 %50, %.pre-phi
  %52 = trunc i64 %51 to i32
  %53 = add i32 %52, 1
  %54 = tail call i32 @binarySearchI(ptr noundef %.1, ptr noundef nonnull %1, i32 noundef %53, i32 noundef %3, ptr noundef nonnull %4) #6
  %55 = icmp eq i32 %54, -1
  br i1 %55, label %63, label %56

56:                                               ; preds = %.split.loop.exit45
  %57 = ptrtoint ptr %0 to i64
  %58 = sub i64 %.pre-phi, %57
  %59 = zext nneg i32 %3 to i64
  %60 = sdiv i64 %58, %59
  %61 = trunc i64 %60 to i32
  %62 = add i32 %54, %61
  br label %63

63:                                               ; preds = %.split.loop.exit45, %56
  %64 = phi i32 [ %62, %56 ], [ -1, %.split.loop.exit45 ]
  ret i32 %64
}

; 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

declare i32 @binarySearchI(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #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 = { "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 = { 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"}


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