; LLVM IR from jrouwe/JoltPhysics :: Jolt/Core/LinearCurve.ll (ZNK3JPH11LinearCurve8GetValueEf)

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

%class.anon.6 = type { i8 }
%"class.JPH::LinearCurve" = type { %"class.JPH::Array" }
%"class.JPH::Array" = type { i64, i64, ptr }
%"class.JPH::LinearCurve::Point" = type { float, float }

; 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 float @_ZNK3JPH11LinearCurve8GetValueEf(ptr noundef nonnull align 8 dereferenceable(24) %0, float noundef %1) #1 align 2 {
  %3 = alloca float, align 4
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  %7 = alloca %class.anon.6, align 1
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  %11 = getelementptr inbounds %"class.JPH::LinearCurve", ptr %10, i32 0, i32 0
  %12 = call noundef zeroext i1 @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24) %11)
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store float 0.000000e+00, ptr %3, align 4
  br label %69

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %15 = getelementptr inbounds %"class.JPH::LinearCurve", ptr %10, i32 0, i32 0
  %16 = call noundef ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %15)
  %17 = getelementptr inbounds %"class.JPH::LinearCurve", ptr %10, i32 0, i32 0
  %18 = call noundef ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %17)
  %19 = call noundef ptr @"_ZSt11lower_boundIPKN3JPH11LinearCurve5PointEfZNKS1_8GetValueEfE3$_0ET_S6_S6_RKT0_T1_"(ptr noundef %16, ptr noundef %18, ptr noundef nonnull align 4 dereferenceable(4) %5)
  store ptr %19, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.JPH::LinearCurve", ptr %10, i32 0, i32 0
  %22 = call noundef ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %21)
  %23 = icmp eq ptr %20, %22
  br i1 %23, label %24, label %29

24:                                               ; preds = %14
  %25 = getelementptr inbounds %"class.JPH::LinearCurve", ptr %10, i32 0, i32 0
  %26 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5frontEv(ptr noundef nonnull align 8 dereferenceable(24) %25)
  %27 = getelementptr inbounds %"class.JPH::LinearCurve::Point", ptr %26, i32 0, i32 1
  %28 = load float, ptr %27, align 4, !tbaa !11
  store float %28, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %68

29:                                               ; preds = %14
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.JPH::LinearCurve", ptr %10, i32 0, i32 0
  %32 = call noundef ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %31)
  %33 = icmp eq ptr %30, %32
  br i1 %33, label %34, label %39

34:                                               ; preds = %29
  %35 = getelementptr inbounds %"class.JPH::LinearCurve", ptr %10, i32 0, i32 0
  %36 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %35)
  %37 = getelementptr inbounds %"class.JPH::LinearCurve::Point", ptr %36, i32 0, i32 1
  %38 = load float, ptr %37, align 4, !tbaa !11
  store float %38, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %68

39:                                               ; preds = %29
  br label %40

40:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %"class.JPH::LinearCurve::Point", ptr %41, i64 -1
  store ptr %42, ptr %9, align 8, !tbaa !5
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.JPH::LinearCurve::Point", ptr %43, i32 0, i32 1
  %45 = load float, ptr %44, align 4, !tbaa !11
  %46 = load float, ptr %5, align 4, !tbaa !9
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %"class.JPH::LinearCurve::Point", ptr %47, i32 0, i32 0
  %49 = load float, ptr %48, align 4, !tbaa !13
  %50 = fsub float %46, %49
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %"class.JPH::LinearCurve::Point", ptr %51, i32 0, i32 1
  %53 = load float, ptr %52, align 4, !tbaa !11
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %"class.JPH::LinearCurve::Point", ptr %54, i32 0, i32 1
  %56 = load float, ptr %55, align 4, !tbaa !11
  %57 = fsub float %53, %56
  %58 = fmul float %50, %57
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %"class.JPH::LinearCurve::Point", ptr %59, i32 0, i32 0
  %61 = load float, ptr %60, align 4, !tbaa !13
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %"class.JPH::LinearCurve::Point", ptr %62, i32 0, i32 0
  %64 = load float, ptr %63, align 4, !tbaa !13
  %65 = fsub float %61, %64
  %66 = fdiv float %58, %65
  %67 = fadd float %45, %66
  store float %67, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %68

68:                                               ; preds = %40, %34, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %69

69:                                               ; preds = %68, %13
  %70 = load float, ptr %3, align 4
  ret float %70
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef ptr @"_ZSt11lower_boundIPKN3JPH11LinearCurve5PointEfZNKS1_8GetValueEfE3$_0ET_S6_S6_RKT0_T1_"(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5frontEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE4backEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 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 = { 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 = { inlinehint 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 #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTSN3JPH11LinearCurve5PointE", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 0}


; 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 float @_ZNK3JPH11LinearCurve8GetValueEf(ptr noundef nonnull align 8 dereferenceable(24) %0, float noundef %1) local_unnamed_addr #0 align 2 {
  %3 = alloca float, align 4
  store float %1, ptr %3, align 4, !tbaa !5
  %4 = tail call noundef zeroext i1 @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  br i1 %4, label %36, label %5

5:                                                ; preds = %2
  %6 = tail call noundef ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %7 = tail call noundef ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %8 = call noundef ptr @"_ZSt11lower_boundIPKN3JPH11LinearCurve5PointEfZNKS1_8GetValueEfE3$_0ET_S6_S6_RKT0_T1_"(ptr noundef %6, ptr noundef %7, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %9 = call noundef ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %10 = icmp eq ptr %8, %9
  br i1 %10, label %11, label %15

11:                                               ; preds = %5
  %12 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5frontEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %13 = getelementptr inbounds i8, ptr %12, i64 4
  %14 = load float, ptr %13, align 4, !tbaa !9
  br label %36

15:                                               ; preds = %5
  %16 = call noundef ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %17 = icmp eq ptr %8, %16
  br i1 %17, label %18, label %22

18:                                               ; preds = %15
  %19 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %20 = getelementptr inbounds i8, ptr %19, i64 4
  %21 = load float, ptr %20, align 4, !tbaa !9
  br label %36

22:                                               ; preds = %15
  %23 = getelementptr inbounds i8, ptr %8, i64 -8
  %24 = load float, ptr %3, align 4, !tbaa !5
  %25 = load <2 x float>, ptr %23, align 4, !tbaa !5
  %26 = extractelement <2 x float> %25, i64 0
  %27 = fsub float %24, %26
  %28 = load <2 x float>, ptr %8, align 4, !tbaa !5
  %29 = fsub <2 x float> %28, %25
  %30 = extractelement <2 x float> %29, i64 1
  %31 = fmul float %27, %30
  %32 = extractelement <2 x float> %29, i64 0
  %33 = fdiv float %31, %32
  %34 = extractelement <2 x float> %25, i64 1
  %35 = fadd float %34, %33
  br label %36

36:                                               ; preds = %11, %18, %22, %2
  %.1 = phi float [ 0.000000e+00, %2 ], [ %14, %11 ], [ %21, %18 ], [ %35, %22 ]
  ret float %.1
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef ptr @"_ZSt11lower_boundIPKN3JPH11LinearCurve5PointEfZNKS1_8GetValueEfE3$_0ET_S6_S6_RKT0_T1_"(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE5frontEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNK3JPH5ArrayINS_11LinearCurve5PointENS_12STLAllocatorIS2_EEE4backEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 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 = { 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 = { inlinehint 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" }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 4}
!10 = !{!"_ZTSN3JPH11LinearCurve5PointE", !6, i64 0, !6, i64 4}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass