; LLVM IR from marcinlos/iga-ads :: src/ads/bspline/bspline.ll (ZN3ads7bspline9find_spanEdRKNS0_5basisE)

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3ads7bspline9find_spanEdRKNS0_5basisE(double noundef %0, ptr noundef nonnull align 8 dereferenceable(56) %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca double, 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
  store double %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !9
  %11 = call noundef i32 @_ZNK3ads7bspline5basis9begin_idxEv(ptr noundef nonnull align 8 dereferenceable(56) %10)
  store i32 %11, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  %13 = call noundef i32 @_ZNK3ads7bspline5basis7end_idxEv(ptr noundef nonnull align 8 dereferenceable(56) %12)
  store i32 %13, ptr %7, align 4, !tbaa !11
  %14 = load double, ptr %4, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = load i32, ptr %7, align 4, !tbaa !11
  %17 = call noundef double @_ZNK3ads7bspline5basisixEi(ptr noundef nonnull align 8 dereferenceable(56) %15, i32 noundef %16)
  %18 = fcmp oge double %14, %17
  br i1 %18, label %19, label %22

19:                                               ; preds = %2
  %20 = load i32, ptr %7, align 4, !tbaa !11
  %21 = sub nsw i32 %20, 1
  store i32 %21, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %68

22:                                               ; preds = %2
  %23 = load double, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !11
  %26 = call noundef double @_ZNK3ads7bspline5basisixEi(ptr noundef nonnull align 8 dereferenceable(56) %24, i32 noundef %25)
  %27 = fcmp ole double %23, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %22
  %29 = load i32, ptr %6, align 4, !tbaa !11
  store i32 %29, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %68

30:                                               ; preds = %22
  br label %31

31:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %32 = load i32, ptr %6, align 4, !tbaa !11
  %33 = load i32, ptr %7, align 4, !tbaa !11
  %34 = add nsw i32 %32, %33
  %35 = sdiv i32 %34, 2
  store i32 %35, ptr %9, align 4, !tbaa !11
  br label %36

36:                                               ; preds = %61, %31
  %37 = load double, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !9
  %39 = load i32, ptr %9, align 4, !tbaa !11
  %40 = call noundef double @_ZNK3ads7bspline5basisixEi(ptr noundef nonnull align 8 dereferenceable(56) %38, i32 noundef %39)
  %41 = fcmp olt double %37, %40
  br i1 %41, label %49, label %42

42:                                               ; preds = %36
  %43 = load double, ptr %4, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  %45 = load i32, ptr %9, align 4, !tbaa !11
  %46 = add nsw i32 %45, 1
  %47 = call noundef double @_ZNK3ads7bspline5basisixEi(ptr noundef nonnull align 8 dereferenceable(56) %44, i32 noundef %46)
  %48 = fcmp oge double %43, %47
  br label %49

49:                                               ; preds = %42, %36
  %50 = phi i1 [ true, %36 ], [ %48, %42 ]
  br i1 %50, label %51, label %66

51:                                               ; preds = %49
  %52 = load double, ptr %4, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !9
  %54 = load i32, ptr %9, align 4, !tbaa !11
  %55 = call noundef double @_ZNK3ads7bspline5basisixEi(ptr noundef nonnull align 8 dereferenceable(56) %53, i32 noundef %54)
  %56 = fcmp olt double %52, %55
  br i1 %56, label %57, label %59

57:                                               ; preds = %51
  %58 = load i32, ptr %9, align 4, !tbaa !11
  store i32 %58, ptr %7, align 4, !tbaa !11
  br label %61

59:                                               ; preds = %51
  %60 = load i32, ptr %9, align 4, !tbaa !11
  store i32 %60, ptr %6, align 4, !tbaa !11
  br label %61

61:                                               ; preds = %59, %57
  %62 = load i32, ptr %6, align 4, !tbaa !11
  %63 = load i32, ptr %7, align 4, !tbaa !11
  %64 = add nsw i32 %62, %63
  %65 = sdiv i32 %64, 2
  store i32 %65, ptr %9, align 4, !tbaa !11
  br label %36, !llvm.loop !13

66:                                               ; preds = %49
  %67 = load i32, ptr %9, align 4, !tbaa !11
  store i32 %67, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %68

68:                                               ; preds = %66, %28, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %69 = load i32, ptr %3, align 4
  ret i32 %69
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3ads7bspline5basis9begin_idxEv(ptr noundef nonnull align 8 dereferenceable(56)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK3ads7bspline5basis7end_idxEv(ptr noundef nonnull align 8 dereferenceable(56)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK3ads7bspline5basisixEi(ptr noundef nonnull align 8 dereferenceable(56), i32 noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 noundef i32 @_ZN3ads7bspline9find_spanEdRKNS0_5basisE(double noundef %0, ptr noundef nonnull align 8 dereferenceable(56) %1) local_unnamed_addr #0 {
  %3 = tail call noundef i32 @_ZNK3ads7bspline5basis9begin_idxEv(ptr noundef nonnull align 8 dereferenceable(56) %1)
  %4 = tail call noundef i32 @_ZNK3ads7bspline5basis7end_idxEv(ptr noundef nonnull align 8 dereferenceable(56) %1)
  %5 = tail call noundef double @_ZNK3ads7bspline5basisixEi(ptr noundef nonnull align 8 dereferenceable(56) %1, i32 noundef %4)
  %6 = fcmp ugt double %5, %0
  br i1 %6, label %9, label %7

7:                                                ; preds = %2
  %8 = add nsw i32 %4, -1
  br label %.loopexit

9:                                                ; preds = %2
  %10 = tail call noundef double @_ZNK3ads7bspline5basisixEi(ptr noundef nonnull align 8 dereferenceable(56) %1, i32 noundef %3)
  %11 = fcmp ult double %10, %0
  br i1 %11, label %12, label %.loopexit

12:                                               ; preds = %9
  %13 = add nsw i32 %4, %3
  br label %14

14:                                               ; preds = %.critedge, %12
  %.027 = phi i32 [ %3, %12 ], [ %.027..0, %.critedge ]
  %.026 = phi i32 [ %4, %12 ], [ %.0..026, %.critedge ]
  %.0.in = phi i32 [ %13, %12 ], [ %23, %.critedge ]
  %.0 = sdiv i32 %.0.in, 2
  %15 = tail call noundef double @_ZNK3ads7bspline5basisixEi(ptr noundef nonnull align 8 dereferenceable(56) %1, i32 noundef %.0)
  %16 = fcmp ogt double %15, %0
  br i1 %16, label %.critedge, label %17

17:                                               ; preds = %14
  %18 = add nsw i32 %.0, 1
  %19 = tail call noundef double @_ZNK3ads7bspline5basisixEi(ptr noundef nonnull align 8 dereferenceable(56) %1, i32 noundef %18)
  %20 = fcmp ugt double %19, %0
  br i1 %20, label %.loopexit, label %.critedge

.critedge:                                        ; preds = %14, %17
  %21 = tail call noundef double @_ZNK3ads7bspline5basisixEi(ptr noundef nonnull align 8 dereferenceable(56) %1, i32 noundef %.0)
  %22 = fcmp ogt double %21, %0
  %.027..0 = select i1 %22, i32 %.027, i32 %.0
  %.0..026 = select i1 %22, i32 %.0, i32 %.026
  %23 = add nsw i32 %.027..0, %.0..026
  br label %14, !llvm.loop !5

.loopexit:                                        ; preds = %17, %9, %7
  %.029 = phi i32 [ %8, %7 ], [ %3, %9 ], [ %.0, %17 ]
  ret i32 %.029
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3ads7bspline5basis9begin_idxEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK3ads7bspline5basis7end_idxEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK3ads7bspline5basisixEi(ptr noundef nonnull align 8 dereferenceable(56), i32 noundef) local_unnamed_addr #1 align 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 = { 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass