; LLVM IR from pmla/polyhedral-template-matching :: ptm_quat.ll (ZN3ptm29quaternion_to_rotation_matrixEPdS0_)

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3ptm29quaternion_to_rotation_matrixEPdS0_(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds double, ptr %9, i64 0
  %11 = load double, ptr %10, align 8, !tbaa !9
  store double %11, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds double, ptr %12, i64 1
  %14 = load double, ptr %13, align 8, !tbaa !9
  store double %14, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds double, ptr %15, i64 2
  %17 = load double, ptr %16, align 8, !tbaa !9
  store double %17, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds double, ptr %18, i64 3
  %20 = load double, ptr %19, align 8, !tbaa !9
  store double %20, ptr %8, align 8, !tbaa !9
  %21 = load double, ptr %5, align 8, !tbaa !9
  %22 = load double, ptr %5, align 8, !tbaa !9
  %23 = load double, ptr %6, align 8, !tbaa !9
  %24 = load double, ptr %6, align 8, !tbaa !9
  %25 = fmul double %23, %24
  %26 = call double @llvm.fmuladd.f64(double %21, double %22, double %25)
  %27 = load double, ptr %7, align 8, !tbaa !9
  %28 = load double, ptr %7, align 8, !tbaa !9
  %29 = fneg double %27
  %30 = call double @llvm.fmuladd.f64(double %29, double %28, double %26)
  %31 = load double, ptr %8, align 8, !tbaa !9
  %32 = load double, ptr %8, align 8, !tbaa !9
  %33 = fneg double %31
  %34 = call double @llvm.fmuladd.f64(double %33, double %32, double %30)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds double, ptr %35, i64 0
  store double %34, ptr %36, align 8, !tbaa !9
  %37 = load double, ptr %6, align 8, !tbaa !9
  %38 = fmul double 2.000000e+00, %37
  %39 = load double, ptr %7, align 8, !tbaa !9
  %40 = load double, ptr %5, align 8, !tbaa !9
  %41 = fmul double 2.000000e+00, %40
  %42 = load double, ptr %8, align 8, !tbaa !9
  %43 = fmul double %41, %42
  %44 = fneg double %43
  %45 = call double @llvm.fmuladd.f64(double %38, double %39, double %44)
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds double, ptr %46, i64 1
  store double %45, ptr %47, align 8, !tbaa !9
  %48 = load double, ptr %6, align 8, !tbaa !9
  %49 = fmul double 2.000000e+00, %48
  %50 = load double, ptr %8, align 8, !tbaa !9
  %51 = load double, ptr %5, align 8, !tbaa !9
  %52 = fmul double 2.000000e+00, %51
  %53 = load double, ptr %7, align 8, !tbaa !9
  %54 = fmul double %52, %53
  %55 = call double @llvm.fmuladd.f64(double %49, double %50, double %54)
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds double, ptr %56, i64 2
  store double %55, ptr %57, align 8, !tbaa !9
  %58 = load double, ptr %6, align 8, !tbaa !9
  %59 = fmul double 2.000000e+00, %58
  %60 = load double, ptr %7, align 8, !tbaa !9
  %61 = load double, ptr %5, align 8, !tbaa !9
  %62 = fmul double 2.000000e+00, %61
  %63 = load double, ptr %8, align 8, !tbaa !9
  %64 = fmul double %62, %63
  %65 = call double @llvm.fmuladd.f64(double %59, double %60, double %64)
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds double, ptr %66, i64 3
  store double %65, ptr %67, align 8, !tbaa !9
  %68 = load double, ptr %5, align 8, !tbaa !9
  %69 = load double, ptr %5, align 8, !tbaa !9
  %70 = load double, ptr %6, align 8, !tbaa !9
  %71 = load double, ptr %6, align 8, !tbaa !9
  %72 = fmul double %70, %71
  %73 = fneg double %72
  %74 = call double @llvm.fmuladd.f64(double %68, double %69, double %73)
  %75 = load double, ptr %7, align 8, !tbaa !9
  %76 = load double, ptr %7, align 8, !tbaa !9
  %77 = call double @llvm.fmuladd.f64(double %75, double %76, double %74)
  %78 = load double, ptr %8, align 8, !tbaa !9
  %79 = load double, ptr %8, align 8, !tbaa !9
  %80 = fneg double %78
  %81 = call double @llvm.fmuladd.f64(double %80, double %79, double %77)
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds double, ptr %82, i64 4
  store double %81, ptr %83, align 8, !tbaa !9
  %84 = load double, ptr %7, align 8, !tbaa !9
  %85 = fmul double 2.000000e+00, %84
  %86 = load double, ptr %8, align 8, !tbaa !9
  %87 = load double, ptr %5, align 8, !tbaa !9
  %88 = fmul double 2.000000e+00, %87
  %89 = load double, ptr %6, align 8, !tbaa !9
  %90 = fmul double %88, %89
  %91 = fneg double %90
  %92 = call double @llvm.fmuladd.f64(double %85, double %86, double %91)
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds double, ptr %93, i64 5
  store double %92, ptr %94, align 8, !tbaa !9
  %95 = load double, ptr %6, align 8, !tbaa !9
  %96 = fmul double 2.000000e+00, %95
  %97 = load double, ptr %8, align 8, !tbaa !9
  %98 = load double, ptr %5, align 8, !tbaa !9
  %99 = fmul double 2.000000e+00, %98
  %100 = load double, ptr %7, align 8, !tbaa !9
  %101 = fmul double %99, %100
  %102 = fneg double %101
  %103 = call double @llvm.fmuladd.f64(double %96, double %97, double %102)
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  %105 = getelementptr inbounds double, ptr %104, i64 6
  store double %103, ptr %105, align 8, !tbaa !9
  %106 = load double, ptr %7, align 8, !tbaa !9
  %107 = fmul double 2.000000e+00, %106
  %108 = load double, ptr %8, align 8, !tbaa !9
  %109 = load double, ptr %5, align 8, !tbaa !9
  %110 = fmul double 2.000000e+00, %109
  %111 = load double, ptr %6, align 8, !tbaa !9
  %112 = fmul double %110, %111
  %113 = call double @llvm.fmuladd.f64(double %107, double %108, double %112)
  %114 = load ptr, ptr %4, align 8, !tbaa !5
  %115 = getelementptr inbounds double, ptr %114, i64 7
  store double %113, ptr %115, align 8, !tbaa !9
  %116 = load double, ptr %5, align 8, !tbaa !9
  %117 = load double, ptr %5, align 8, !tbaa !9
  %118 = load double, ptr %6, align 8, !tbaa !9
  %119 = load double, ptr %6, align 8, !tbaa !9
  %120 = fmul double %118, %119
  %121 = fneg double %120
  %122 = call double @llvm.fmuladd.f64(double %116, double %117, double %121)
  %123 = load double, ptr %7, align 8, !tbaa !9
  %124 = load double, ptr %7, align 8, !tbaa !9
  %125 = fneg double %123
  %126 = call double @llvm.fmuladd.f64(double %125, double %124, double %122)
  %127 = load double, ptr %8, align 8, !tbaa !9
  %128 = load double, ptr %8, align 8, !tbaa !9
  %129 = call double @llvm.fmuladd.f64(double %127, double %128, double %126)
  %130 = load ptr, ptr %4, align 8, !tbaa !5
  %131 = getelementptr inbounds double, ptr %130, i64 8
  store double %129, ptr %131, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

; 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(argmem: readwrite) uwtable
define dso_local void @_ZN3ptm29quaternion_to_rotation_matrixEPdS0_(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #1 {
  %3 = load double, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load double, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = fmul double %5, %5
  %8 = tail call double @llvm.fmuladd.f64(double %3, double %3, double %7)
  %9 = fmul double %3, 2.000000e+00
  %10 = load <2 x double>, ptr %6, align 8, !tbaa !5
  %11 = shufflevector <2 x double> %10, <2 x double> poison, <2 x i32> <i32 1, i32 0>
  %12 = extractelement <2 x double> %10, i64 0
  %13 = fneg double %12
  %14 = tail call double @llvm.fmuladd.f64(double %13, double %12, double %8)
  %15 = extractelement <2 x double> %10, i64 1
  %16 = fneg double %15
  %17 = getelementptr inbounds i8, ptr %1, i64 16
  %18 = insertelement <2 x double> poison, double %9, i64 0
  %19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
  %20 = fmul <2 x double> %19, %10
  %21 = extractelement <2 x double> %20, i64 1
  %22 = fneg double %21
  %23 = insertelement <2 x double> poison, double %22, i64 0
  %24 = insertelement <2 x double> %23, double %14, i64 1
  %25 = fneg double %7
  %26 = tail call double @llvm.fmuladd.f64(double %3, double %3, double %25)
  %27 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %26)
  %28 = getelementptr inbounds i8, ptr %1, i64 32
  %29 = fmul double %9, %5
  %30 = fneg double %29
  %31 = shufflevector <2 x double> %10, <2 x double> poison, <2 x i32> <i32 1, i32 1>
  %32 = insertelement <2 x double> poison, double %27, i64 0
  %33 = insertelement <2 x double> %32, double %30, i64 1
  %34 = extractelement <2 x double> %20, i64 0
  %35 = fneg double %34
  %36 = getelementptr inbounds i8, ptr %1, i64 48
  %37 = insertelement <2 x double> %11, double %5, i64 0
  %38 = fmul <2 x double> %37, <double 2.000000e+00, double 2.000000e+00>
  %39 = insertelement <2 x double> %38, double %16, i64 1
  %40 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %39, <2 x double> %10, <2 x double> %24)
  %41 = shufflevector <2 x double> %40, <2 x double> poison, <2 x i32> <i32 1, i32 0>
  store <2 x double> %41, ptr %1, align 8, !tbaa !5
  %42 = shufflevector <2 x double> %38, <2 x double> poison, <2 x i32> zeroinitializer
  %43 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %42, <2 x double> %11, <2 x double> %20)
  store <2 x double> %43, ptr %17, align 8, !tbaa !5
  %44 = insertelement <2 x double> %38, double %16, i64 0
  %45 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %44, <2 x double> %31, <2 x double> %33)
  store <2 x double> %45, ptr %28, align 8, !tbaa !5
  %46 = insertelement <2 x double> poison, double %35, i64 0
  %47 = insertelement <2 x double> %46, double %29, i64 1
  %48 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %38, <2 x double> %31, <2 x double> %47)
  store <2 x double> %48, ptr %36, align 8, !tbaa !5
  %49 = tail call double @llvm.fmuladd.f64(double %13, double %12, double %26)
  %50 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %49)
  %51 = getelementptr inbounds i8, ptr %1, i64 64
  store double %50, ptr %51, align 8, !tbaa !5
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 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,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass