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

; 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
declare dso_local <2 x float> @_ZN7QVector17AngleToUnitVectorEf(float noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7QVectorC2Eff(ptr noundef nonnull align 4 dereferenceable(8), float noundef, float noundef) unnamed_addr #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local <2 x float> @_ZNK7QVector7RotatedEf(ptr noundef nonnull align 4 dereferenceable(8) %0, float noundef %1) #0 align 2 {
  %3 = alloca %struct.QVector, align 4
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca %struct.QVector, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  %10 = load float, ptr %5, align 4, !tbaa !9
  %11 = fcmp oeq float %10, 0.000000e+00
  br i1 %11, label %12, label %17

12:                                               ; preds = %2
  %13 = getelementptr inbounds %struct.QVector, ptr %9, i32 0, i32 0
  %14 = load float, ptr %13, align 4, !tbaa !11
  %15 = getelementptr inbounds %struct.QVector, ptr %9, i32 0, i32 1
  %16 = load float, ptr %15, align 4, !tbaa !13
  call void @_ZN7QVectorC2Eff(ptr noundef nonnull align 4 dereferenceable(8) %3, float noundef %14, float noundef %16)
  br label %43

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %18 = load float, ptr %5, align 4, !tbaa !9
  %19 = call <2 x float> @_ZN7QVector17AngleToUnitVectorEf(float noundef %18)
  store <2 x float> %19, ptr %6, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %20 = getelementptr inbounds %struct.QVector, ptr %9, i32 0, i32 0
  %21 = load float, ptr %20, align 4, !tbaa !11
  %22 = getelementptr inbounds %struct.QVector, ptr %6, i32 0, i32 0
  %23 = load float, ptr %22, align 4, !tbaa !11
  %24 = getelementptr inbounds %struct.QVector, ptr %9, i32 0, i32 1
  %25 = load float, ptr %24, align 4, !tbaa !13
  %26 = getelementptr inbounds %struct.QVector, ptr %6, i32 0, i32 1
  %27 = load float, ptr %26, align 4, !tbaa !13
  %28 = fmul float %25, %27
  %29 = fneg float %28
  %30 = call float @llvm.fmuladd.f32(float %21, float %23, float %29)
  store float %30, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %31 = getelementptr inbounds %struct.QVector, ptr %9, i32 0, i32 0
  %32 = load float, ptr %31, align 4, !tbaa !11
  %33 = getelementptr inbounds %struct.QVector, ptr %6, i32 0, i32 1
  %34 = load float, ptr %33, align 4, !tbaa !13
  %35 = getelementptr inbounds %struct.QVector, ptr %9, i32 0, i32 1
  %36 = load float, ptr %35, align 4, !tbaa !13
  %37 = getelementptr inbounds %struct.QVector, ptr %6, i32 0, i32 0
  %38 = load float, ptr %37, align 4, !tbaa !11
  %39 = fmul float %36, %38
  %40 = call float @llvm.fmuladd.f32(float %32, float %34, float %39)
  store float %40, ptr %8, align 4, !tbaa !9
  %41 = load float, ptr %7, align 4, !tbaa !9
  %42 = load float, ptr %8, align 4, !tbaa !9
  call void @_ZN7QVectorC2Eff(ptr noundef nonnull align 4 dereferenceable(8) %3, float noundef %41, float noundef %42)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %43

43:                                               ; preds = %17, %12
  %44 = load <2 x float>, ptr %3, align 4
  ret <2 x float> %44
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 0}
!12 = !{!"_ZTS7QVector", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 4}


; 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
declare dso_local <2 x float> @_ZN7QVector17AngleToUnitVectorEf(float noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7QVectorC2Eff(ptr noundef nonnull align 4 dereferenceable(8), float noundef, float noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local <2 x float> @_ZNK7QVector7RotatedEf(ptr nocapture noundef nonnull readonly align 4 dereferenceable(8) %0, float noundef %1) local_unnamed_addr #0 align 2 {
  %3 = alloca %struct.QVector, align 8
  %4 = fcmp oeq float %1, 0.000000e+00
  br i1 %4, label %5, label %9

5:                                                ; preds = %2
  %6 = load float, ptr %0, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load float, ptr %7, align 4, !tbaa !10
  call void @_ZN7QVectorC2Eff(ptr noundef nonnull align 4 dereferenceable(8) %3, float noundef %6, float noundef %8)
  br label %19

9:                                                ; preds = %2
  %10 = tail call <2 x float> @_ZN7QVector17AngleToUnitVectorEf(float noundef %1)
  %11 = load float, ptr %0, align 4, !tbaa !5
  %.sroa.0.0.vec.extract = extractelement <2 x float> %10, i64 0
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  %13 = load float, ptr %12, align 4, !tbaa !10
  %.sroa.0.4.vec.extract = extractelement <2 x float> %10, i64 1
  %14 = fneg float %13
  %15 = fmul float %.sroa.0.4.vec.extract, %14
  %16 = tail call float @llvm.fmuladd.f32(float %11, float %.sroa.0.0.vec.extract, float %15)
  %17 = fmul float %.sroa.0.0.vec.extract, %13
  %18 = tail call float @llvm.fmuladd.f32(float %11, float %.sroa.0.4.vec.extract, float %17)
  call void @_ZN7QVectorC2Eff(ptr noundef nonnull align 4 dereferenceable(8) %3, float noundef %16, float noundef %18)
  br label %19

19:                                               ; preds = %9, %5
  %20 = load <2 x float>, ptr %3, align 8
  ret <2 x float> %20
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

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 = { 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass