; LLVM IR from erayzesen/QuarkPhysics :: QuarkPhysics/qvector.ll (ZN7QVector22AngleBetweenTwoVectorsES_S_)

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

%struct.QVector = type { float, float }

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN7QVector22AngleBetweenTwoVectorsES_S_(<2 x float> %0, <2 x float> %1) #0 align 2 {
  %3 = alloca %struct.QVector, align 4
  %4 = alloca %struct.QVector, align 4
  %5 = alloca float, align 4
  %6 = alloca %struct.QVector, align 4
  %7 = alloca float, align 4
  %8 = alloca %struct.QVector, align 4
  %9 = alloca float, align 4
  %10 = alloca %struct.QVector, align 4
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  store <2 x float> %0, ptr %3, align 4
  store <2 x float> %1, ptr %4, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #8
  %15 = call noundef float @_ZNK7QVector6LengthEv(ptr noundef nonnull align 4 dereferenceable(8) %3)
  %16 = call noundef float @_ZNK7QVector6LengthEv(ptr noundef nonnull align 4 dereferenceable(8) %4)
  %17 = fadd float %15, %16
  store float %17, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #8
  %18 = call <2 x float> @_ZNK7QVector13PerpendicularEv(ptr noundef nonnull align 4 dereferenceable(8) %4)
  store <2 x float> %18, ptr %6, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !9
  %19 = load <2 x float>, ptr %8, align 4
  %20 = call noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8) %3, <2 x float> %19)
  store float %20, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !9
  %21 = load <2 x float>, ptr %10, align 4
  %22 = call noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8) %3, <2 x float> %21)
  store float %22, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #8
  store float 0.000000e+00, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #8
  store float 0.000000e+00, ptr %12, align 4, !tbaa !5
  %23 = load float, ptr %5, align 4, !tbaa !5
  %24 = fcmp une float %23, 0.000000e+00
  br i1 %24, label %25, label %32

25:                                               ; preds = %2
  %26 = load float, ptr %7, align 4, !tbaa !5
  %27 = load float, ptr %5, align 4, !tbaa !5
  %28 = fdiv float %26, %27
  store float %28, ptr %11, align 4, !tbaa !5
  %29 = load float, ptr %9, align 4, !tbaa !5
  %30 = load float, ptr %5, align 4, !tbaa !5
  %31 = fdiv float %29, %30
  store float %31, ptr %12, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %25, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #8
  %33 = load float, ptr %12, align 4, !tbaa !5
  %34 = fcmp olt float %33, -1.000000e+00
  br i1 %34, label %35, label %38

35:                                               ; preds = %32
  %36 = call double @asin(double noundef -1.000000e+00) #8
  %37 = fptrunc double %36 to float
  store float %37, ptr %13, align 4, !tbaa !5
  br label %48

38:                                               ; preds = %32
  %39 = load float, ptr %12, align 4, !tbaa !5
  %40 = fcmp ogt float %39, 1.000000e+00
  br i1 %40, label %41, label %44

41:                                               ; preds = %38
  %42 = call double @asin(double noundef 1.000000e+00) #8
  %43 = fptrunc double %42 to float
  store float %43, ptr %13, align 4, !tbaa !5
  br label %47

44:                                               ; preds = %38
  %45 = load float, ptr %12, align 4, !tbaa !5
  %46 = call noundef float @_ZSt4asinf(float noundef %45)
  store float %46, ptr %13, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %44, %41
  br label %48

48:                                               ; preds = %47, %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #8
  %49 = load float, ptr %13, align 4, !tbaa !5
  %50 = load float, ptr %11, align 4, !tbaa !5
  %51 = call noundef float @_ZSt5atan2ff(float noundef %49, float noundef %50)
  %52 = fneg float %51
  store float %52, ptr %14, align 4, !tbaa !5
  %53 = load float, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #8
  ret float %53
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZNK7QVector13PerpendicularEv(ptr noundef nonnull align 4 dereferenceable(8)) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8), <2 x float>) #4 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

; Function Attrs: nounwind
declare double @asin(double noundef) #6

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4asinf(float noundef) #7

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5atan2ff(float noundef, float noundef) #7

; 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"="64" "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 = { 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 #3 = { inlinehint mustprogress uwtable "min-legal-vector-width"="64" "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 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="64" "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 #7 = { 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 #8 = { 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 0, i64 4, !5, i64 4, i64 4, !5}


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

%struct.QVector = type { float, float }

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN7QVector22AngleBetweenTwoVectorsES_S_(<2 x float> %0, <2 x float> %1) local_unnamed_addr #0 align 2 {
  %3 = alloca %struct.QVector, align 8
  %4 = alloca %struct.QVector, align 8
  store <2 x float> %0, ptr %3, align 8
  store <2 x float> %1, ptr %4, align 8
  %5 = call noundef float @_ZNK7QVector6LengthEv(ptr noundef nonnull align 4 dereferenceable(8) %3)
  %6 = call noundef float @_ZNK7QVector6LengthEv(ptr noundef nonnull align 4 dereferenceable(8) %4)
  %7 = fadd float %5, %6
  %8 = call <2 x float> @_ZNK7QVector13PerpendicularEv(ptr noundef nonnull align 4 dereferenceable(8) %4)
  %.sroa.07.0.copyload = load <2 x float>, ptr %4, align 8
  %9 = call noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8) %3, <2 x float> %.sroa.07.0.copyload)
  %10 = call noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8) %3, <2 x float> %8)
  %11 = fcmp une float %7, 0.000000e+00
  %12 = fdiv float %10, %7
  %.014 = select i1 %11, float %12, float 0.000000e+00
  %13 = fcmp olt float %.014, -1.000000e+00
  br i1 %13, label %18, label %14

14:                                               ; preds = %2
  %15 = fcmp ogt float %.014, 1.000000e+00
  br i1 %15, label %18, label %16

16:                                               ; preds = %14
  %17 = call noundef float @_ZSt4asinf(float noundef %.014)
  br label %18

18:                                               ; preds = %14, %2, %16
  %.013 = phi float [ %17, %16 ], [ 0xBFF921FB60000000, %2 ], [ 0x3FF921FB60000000, %14 ]
  %19 = fdiv float %9, %7
  %.0 = select i1 %11, float %19, float 0.000000e+00
  %20 = call noundef float @_ZSt5atan2ff(float noundef %.013, float noundef %.0)
  %21 = fneg float %20
  ret float %21
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZNK7QVector13PerpendicularEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8), <2 x float>) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4asinf(float noundef) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5atan2ff(float noundef, float noundef) local_unnamed_addr #4

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 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"="64" "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 nounwind uwtable "min-legal-vector-width"="64" "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 = { 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" }

!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)"}


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