; LLVM IR from zumrudu-anka/Algorithms :: C++/Searching Algorithms/InterpolationSearch (InterpolationSearch)

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

20:                                               ; preds = %104, %3
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %24, label %40

24:                                               ; preds = %20
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %26, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = icmp sle i32 %25, %30
  br i1 %31, label %32, label %40

32:                                               ; preds = %24
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %34, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = icmp sge i32 %33, %38
  br label %40

40:                                               ; preds = %32, %24, %20
  %41 = phi i1 [ false, %24 ], [ false, %20 ], [ %39, %32 ]
  br i1 %41, label %42, label %105

42:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = sitofp i32 %43 to double
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = sub nsw i32 %45, %46
  %48 = sitofp i32 %47 to double
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr %49, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = sub nsw i32 %53, %58
  %60 = sitofp i32 %59 to double
  %61 = fdiv double %48, %60
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i32, ptr %63, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !9
  %68 = sub nsw i32 %62, %67
  %69 = sitofp i32 %68 to double
  %70 = call double @llvm.fmuladd.f64(double %61, double %69, double %44)
  %71 = fptosi double %70 to i32
  store i32 %71, ptr %11, align 4, !tbaa !9
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load i32, ptr %11, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i32, ptr %72, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !9
  %77 = load i32, ptr %7, align 4, !tbaa !9
  %78 = icmp eq i32 %76, %77
  br i1 %78, label %79, label %86

79:                                               ; preds = %42
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  %81 = getelementptr inbounds i32, ptr %80, i64 0
  store i32 1, ptr %81, align 4, !tbaa !9
  %82 = load i32, ptr %11, align 4, !tbaa !9
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = getelementptr inbounds i32, ptr %83, i64 1
  store i32 %82, ptr %84, align 4, !tbaa !9
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %85, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %102

86:                                               ; preds = %42
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = load i32, ptr %11, align 4, !tbaa !9
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds i32, ptr %87, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !9
  %92 = load i32, ptr %7, align 4, !tbaa !9
  %93 = icmp sgt i32 %91, %92
  br i1 %93, label %94, label %97

94:                                               ; preds = %86
  %95 = load i32, ptr %11, align 4, !tbaa !9
  %96 = sub nsw i32 %95, 1
  store i32 %96, ptr %9, align 4, !tbaa !9
  br label %100

97:                                               ; preds = %86
  %98 = load i32, ptr %11, align 4, !tbaa !9
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %8, align 4, !tbaa !9
  br label %100

100:                                              ; preds = %97, %94
  br label %101

101:                                              ; preds = %100
  store i32 0, ptr %12, align 4
  br label %102

102:                                              ; preds = %101, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %103 = load i32, ptr %12, align 4
  switch i32 %103, label %107 [
    i32 0, label %104
  ]

104:                                              ; preds = %102
  br label %20, !llvm.loop !11

105:                                              ; preds = %40
  %106 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %106, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %107

107:                                              ; preds = %105, %102
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %108 = load ptr, ptr %4, align 8
  ret ptr %108
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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"}


; 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 @_Z19InterpolationSearchPiii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call noalias noundef nonnull dereferenceable(8) ptr @_Znam(i64 noundef 8) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 -1, ptr %5, align 4, !tbaa !5
  %.not52 = icmp slt i32 %1, 1
  br i1 %.not52, label %.critedge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %6 = add nsw i32 %1, -1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %28
  %.03654 = phi i32 [ %.137, %28 ], [ 0, %.lr.ph.preheader ]
  %.03953 = phi i32 [ %.140, %28 ], [ %6, %.lr.ph.preheader ]
  %7 = sext i32 %.03953 to i64
  %8 = getelementptr inbounds i32, ptr %0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not46 = icmp slt i32 %9, %2
  br i1 %.not46, label %.critedge, label %10

10:                                               ; preds = %.lr.ph
  %11 = sext i32 %.03654 to i64
  %12 = getelementptr inbounds i32, ptr %0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not47 = icmp sgt i32 %13, %2
  br i1 %.not47, label %.critedge, label %14

14:                                               ; preds = %10
  %15 = sitofp i32 %.03654 to double
  %16 = sub nsw i32 %.03953, %.03654
  %17 = sitofp i32 %16 to double
  %18 = sub nsw i32 %9, %13
  %19 = sitofp i32 %18 to double
  %20 = fdiv double %17, %19
  %21 = sub nsw i32 %2, %13
  %22 = sitofp i32 %21 to double
  %23 = tail call double @llvm.fmuladd.f64(double %20, double %22, double %15)
  %24 = fptosi double %23 to i32
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr %0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not48 = icmp eq i32 %27, %2
  br i1 %.not48, label %.thread, label %28

.thread:                                          ; preds = %14
  store i32 1, ptr %4, align 4, !tbaa !5
  store i32 %24, ptr %5, align 4, !tbaa !5
  br label %.critedge

28:                                               ; preds = %14
  %29 = icmp sgt i32 %27, %2
  %30 = add nsw i32 %24, -1
  %31 = add nsw i32 %24, 1
  %.140 = select i1 %29, i32 %30, i32 %.03953
  %.137 = select i1 %29, i32 %.03654, i32 %31
  %.not = icmp sgt i32 %.137, %.140
  br i1 %.not, label %.critedge, label %.lr.ph

.critedge:                                        ; preds = %.lr.ph, %28, %10, %3, %.thread
  ret ptr %4
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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"}


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