; LLVM IR from csviragh/robotsim :: src/utilities (math_utils)

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

@VectorialProduct.Temp1 = external hidden global [3 x double], align 16
@VectorialProduct.Temp2 = external hidden global [3 x double], align 16

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

; Function Attrs: nounwind uwtable
define dso_local void @VectorialProduct(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 @VectorialProduct.Temp1, ptr align 8 %7, i64 24, i1 false)
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 @VectorialProduct.Temp2, ptr align 8 %8, i64 24, i1 false)
  %9 = load double, ptr getelementptr inbounds ([3 x double], ptr @VectorialProduct.Temp1, i64 0, i64 1), align 8, !tbaa !9
  %10 = load double, ptr getelementptr inbounds ([3 x double], ptr @VectorialProduct.Temp2, i64 0, i64 2), align 16, !tbaa !9
  %11 = load double, ptr getelementptr inbounds ([3 x double], ptr @VectorialProduct.Temp1, i64 0, i64 2), align 16, !tbaa !9
  %12 = load double, ptr getelementptr inbounds ([3 x double], ptr @VectorialProduct.Temp2, i64 0, i64 1), align 8, !tbaa !9
  %13 = fmul double %11, %12
  %14 = fneg double %13
  %15 = call double @llvm.fmuladd.f64(double %9, double %10, double %14)
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds double, ptr %16, i64 0
  store double %15, ptr %17, align 8, !tbaa !9
  %18 = load double, ptr getelementptr inbounds ([3 x double], ptr @VectorialProduct.Temp1, i64 0, i64 2), align 16, !tbaa !9
  %19 = load double, ptr @VectorialProduct.Temp2, align 16, !tbaa !9
  %20 = load double, ptr @VectorialProduct.Temp1, align 16, !tbaa !9
  %21 = load double, ptr getelementptr inbounds ([3 x double], ptr @VectorialProduct.Temp2, i64 0, i64 2), align 16, !tbaa !9
  %22 = fmul double %20, %21
  %23 = fneg double %22
  %24 = call double @llvm.fmuladd.f64(double %18, double %19, double %23)
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds double, ptr %25, i64 1
  store double %24, ptr %26, align 8, !tbaa !9
  %27 = load double, ptr @VectorialProduct.Temp1, align 16, !tbaa !9
  %28 = load double, ptr getelementptr inbounds ([3 x double], ptr @VectorialProduct.Temp2, i64 0, i64 1), align 8, !tbaa !9
  %29 = load double, ptr getelementptr inbounds ([3 x double], ptr @VectorialProduct.Temp1, i64 0, i64 1), align 8, !tbaa !9
  %30 = load double, ptr @VectorialProduct.Temp2, align 16, !tbaa !9
  %31 = fmul double %29, %30
  %32 = fneg double %31
  %33 = call double @llvm.fmuladd.f64(double %27, double %28, double %32)
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds double, ptr %34, i64 2
  store double %33, ptr %35, align 8, !tbaa !9
  ret void
}

; 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) #2

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

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, 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"

@VectorialProduct.Temp1 = external hidden local_unnamed_addr global [3 x double], align 16
@VectorialProduct.Temp2 = external hidden local_unnamed_addr global [3 x double], align 16

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @VectorialProduct(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) @VectorialProduct.Temp1, ptr noundef nonnull align 8 dereferenceable(24) %1, i64 24, i1 false)
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) @VectorialProduct.Temp2, ptr noundef nonnull align 8 dereferenceable(24) %2, i64 24, i1 false)
  %4 = load double, ptr getelementptr inbounds (i8, ptr @VectorialProduct.Temp1, i64 8), align 8, !tbaa !5
  %5 = load double, ptr getelementptr inbounds (i8, ptr @VectorialProduct.Temp2, i64 16), align 16, !tbaa !5
  %6 = load double, ptr getelementptr inbounds (i8, ptr @VectorialProduct.Temp1, i64 16), align 16, !tbaa !5
  %7 = load double, ptr getelementptr inbounds (i8, ptr @VectorialProduct.Temp2, i64 8), align 8, !tbaa !5
  %8 = fneg double %6
  %9 = fmul double %7, %8
  %10 = tail call double @llvm.fmuladd.f64(double %4, double %5, double %9)
  store double %10, ptr %0, align 8, !tbaa !5
  %11 = load double, ptr getelementptr inbounds (i8, ptr @VectorialProduct.Temp1, i64 16), align 16, !tbaa !5
  %12 = load double, ptr @VectorialProduct.Temp2, align 16, !tbaa !5
  %13 = load double, ptr @VectorialProduct.Temp1, align 16, !tbaa !5
  %14 = load double, ptr getelementptr inbounds (i8, ptr @VectorialProduct.Temp2, i64 16), align 16, !tbaa !5
  %15 = fneg double %13
  %16 = fmul double %14, %15
  %17 = tail call double @llvm.fmuladd.f64(double %11, double %12, double %16)
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  store double %17, ptr %18, align 8, !tbaa !5
  %19 = load double, ptr getelementptr inbounds (i8, ptr @VectorialProduct.Temp2, i64 8), align 8, !tbaa !5
  %20 = load double, ptr getelementptr inbounds (i8, ptr @VectorialProduct.Temp1, i64 8), align 8, !tbaa !5
  %21 = fneg double %20
  %22 = fmul double %12, %21
  %23 = tail call double @llvm.fmuladd.f64(double %13, double %19, double %22)
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  store double %23, ptr %24, align 8, !tbaa !5
  ret void
}

; Function Attrs: mustprogress 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) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) 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 nounwind willreturn memory(argmem: readwrite) }

!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/C++ TBAA"}


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