; LLVM IR from raphaelsenn/elastic-collision :: src/vector2.ll (ZN7Vector23subES_d)

; 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.Vector2 = type { double, double }

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress uwtable
define dso_local { double, double } @_ZN7Vector23subES_d(ptr noundef nonnull align 8 dereferenceable(16) %0, double %1, double %2, double noundef %3) #1 align 2 {
  %5 = alloca %class.Vector2, align 8
  %6 = alloca %class.Vector2, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 0
  store double %1, ptr %9, align 8
  %10 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 1
  store double %2, ptr %10, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store double %3, ptr %8, align 8, !tbaa !9
  %11 = load ptr, ptr %7, align 8
  %12 = getelementptr inbounds %class.Vector2, ptr %6, i32 0, i32 0
  %13 = load double, ptr %12, align 8, !tbaa !11
  %14 = load double, ptr %8, align 8, !tbaa !9
  %15 = getelementptr inbounds %class.Vector2, ptr %11, i32 0, i32 0
  %16 = load double, ptr %15, align 8, !tbaa !11
  %17 = fneg double %13
  %18 = call double @llvm.fmuladd.f64(double %17, double %14, double %16)
  store double %18, ptr %15, align 8, !tbaa !11
  %19 = getelementptr inbounds %class.Vector2, ptr %6, i32 0, i32 1
  %20 = load double, ptr %19, align 8, !tbaa !13
  %21 = load double, ptr %8, align 8, !tbaa !9
  %22 = getelementptr inbounds %class.Vector2, ptr %11, i32 0, i32 1
  %23 = load double, ptr %22, align 8, !tbaa !13
  %24 = fneg double %20
  %25 = call double @llvm.fmuladd.f64(double %24, double %21, double %23)
  store double %25, ptr %22, align 8, !tbaa !13
  %26 = getelementptr inbounds %class.Vector2, ptr %11, i32 0, i32 0
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds %class.Vector2, ptr %11, i32 0, i32 1
  %29 = load double, ptr %28, align 8, !tbaa !13
  call void @_ZN7Vector2C1Edd(ptr noundef nonnull align 8 dereferenceable(16) %5, double noundef %27, double noundef %29)
  %30 = load { double, double }, ptr %5, align 8
  ret { double, double } %30
}

declare void @_ZN7Vector2C1Edd(ptr, double, double)

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

!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 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS7Vector2", !10, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}


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

%class.Vector2 = type { double, double }

; Function Attrs: mustprogress uwtable
define dso_local { double, double } @_ZN7Vector23subES_d(ptr nocapture noundef nonnull align 8 dereferenceable(16) %0, double %1, double %2, double noundef %3) local_unnamed_addr #0 align 2 {
  %5 = alloca %class.Vector2, align 8
  %6 = insertelement <2 x double> poison, double %1, i64 0
  %7 = insertelement <2 x double> %6, double %2, i64 1
  %8 = fneg <2 x double> %7
  %9 = load <2 x double>, ptr %0, align 8, !tbaa !5
  %10 = insertelement <2 x double> poison, double %3, i64 0
  %11 = shufflevector <2 x double> %10, <2 x double> poison, <2 x i32> zeroinitializer
  %12 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %8, <2 x double> %11, <2 x double> %9)
  store <2 x double> %12, ptr %0, align 8, !tbaa !5
  %13 = extractelement <2 x double> %12, i64 0
  %14 = extractelement <2 x double> %12, i64 1
  call void @_ZN7Vector2C1Edd(ptr noundef nonnull align 8 dereferenceable(16) %5, double noundef %13, double noundef %14)
  %.fca.0.load = load double, ptr %5, align 8
  %.fca.0.insert = insertvalue { double, double } poison, double %.fca.0.load, 0
  %.fca.1.gep = getelementptr inbounds i8, ptr %5, i64 8
  %.fca.1.load = load double, ptr %.fca.1.gep, align 8
  %.fca.1.insert = insertvalue { double, double } %.fca.0.insert, double %.fca.1.load, 1
  ret { double, double } %.fca.1.insert
}

declare void @_ZN7Vector2C1Edd(ptr, double, double) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #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 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, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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