; LLVM IR from maliput/maliput :: src/maliput/math/roll_pitch_yaw.ll (ZNK7maliput4math12RollPitchYaw12ToQuaternionEv)

; 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.maliput::math::Quaternion" = type { double, double, double, double }
%"class.maliput::math::RollPitchYaw" = type { %"class.maliput::math::Vector3" }
%"class.maliput::math::Vector3" = type { %"class.maliput::math::VectorBase" }
%"class.maliput::math::VectorBase" = type { %"struct.std::array" }
%"struct.std::array" = type { [3 x double] }

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK7maliput4math7Vector31xEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK7maliput4math7Vector31yEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK7maliput4math7Vector31zEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: nounwind
declare double @cos(double noundef) #3

; Function Attrs: nounwind
declare double @sin(double noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK7maliput4math12RollPitchYaw12ToQuaternionEv(ptr dead_on_unwind noalias writable sret(%"class.maliput::math::Quaternion") align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %1) #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %22 = getelementptr inbounds %"class.maliput::math::RollPitchYaw", ptr %21, i32 0, i32 0
  %23 = call noundef double @_ZNK7maliput4math7Vector31xEv(ptr noundef nonnull align 8 dereferenceable(24) %22)
  %24 = fdiv double %23, 2.000000e+00
  store double %24, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %25 = getelementptr inbounds %"class.maliput::math::RollPitchYaw", ptr %21, i32 0, i32 0
  %26 = call noundef double @_ZNK7maliput4math7Vector31yEv(ptr noundef nonnull align 8 dereferenceable(24) %25)
  %27 = fdiv double %26, 2.000000e+00
  store double %27, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %28 = getelementptr inbounds %"class.maliput::math::RollPitchYaw", ptr %21, i32 0, i32 0
  %29 = call noundef double @_ZNK7maliput4math7Vector31zEv(ptr noundef nonnull align 8 dereferenceable(24) %28)
  %30 = fdiv double %29, 2.000000e+00
  store double %30, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %31 = load double, ptr %4, align 8, !tbaa !9
  %32 = call double @cos(double noundef %31) #5
  store double %32, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %33 = load double, ptr %4, align 8, !tbaa !9
  %34 = call double @sin(double noundef %33) #5
  store double %34, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %35 = load double, ptr %5, align 8, !tbaa !9
  %36 = call double @cos(double noundef %35) #5
  store double %36, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %37 = load double, ptr %5, align 8, !tbaa !9
  %38 = call double @sin(double noundef %37) #5
  store double %38, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %39 = load double, ptr %6, align 8, !tbaa !9
  %40 = call double @cos(double noundef %39) #5
  store double %40, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %41 = load double, ptr %6, align 8, !tbaa !9
  %42 = call double @sin(double noundef %41) #5
  store double %42, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %43 = load double, ptr %9, align 8, !tbaa !9
  %44 = load double, ptr %11, align 8, !tbaa !9
  %45 = fmul double %43, %44
  store double %45, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %46 = load double, ptr %10, align 8, !tbaa !9
  %47 = load double, ptr %11, align 8, !tbaa !9
  %48 = fmul double %46, %47
  store double %48, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %49 = load double, ptr %10, align 8, !tbaa !9
  %50 = load double, ptr %12, align 8, !tbaa !9
  %51 = fmul double %49, %50
  store double %51, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %52 = load double, ptr %9, align 8, !tbaa !9
  %53 = load double, ptr %12, align 8, !tbaa !9
  %54 = fmul double %52, %53
  store double %54, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  %55 = load double, ptr %7, align 8, !tbaa !9
  %56 = load double, ptr %13, align 8, !tbaa !9
  %57 = load double, ptr %8, align 8, !tbaa !9
  %58 = load double, ptr %15, align 8, !tbaa !9
  %59 = fmul double %57, %58
  %60 = call double @llvm.fmuladd.f64(double %55, double %56, double %59)
  store double %60, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  %61 = load double, ptr %8, align 8, !tbaa !9
  %62 = load double, ptr %13, align 8, !tbaa !9
  %63 = load double, ptr %7, align 8, !tbaa !9
  %64 = load double, ptr %15, align 8, !tbaa !9
  %65 = fmul double %63, %64
  %66 = fneg double %65
  %67 = call double @llvm.fmuladd.f64(double %61, double %62, double %66)
  store double %67, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  %68 = load double, ptr %7, align 8, !tbaa !9
  %69 = load double, ptr %14, align 8, !tbaa !9
  %70 = load double, ptr %8, align 8, !tbaa !9
  %71 = load double, ptr %16, align 8, !tbaa !9
  %72 = fmul double %70, %71
  %73 = call double @llvm.fmuladd.f64(double %68, double %69, double %72)
  store double %73, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #5
  %74 = load double, ptr %7, align 8, !tbaa !9
  %75 = load double, ptr %16, align 8, !tbaa !9
  %76 = load double, ptr %8, align 8, !tbaa !9
  %77 = load double, ptr %14, align 8, !tbaa !9
  %78 = fmul double %76, %77
  %79 = fneg double %78
  %80 = call double @llvm.fmuladd.f64(double %74, double %75, double %79)
  store double %80, ptr %20, align 8, !tbaa !9
  %81 = load double, ptr %17, align 8, !tbaa !9
  %82 = load double, ptr %18, align 8, !tbaa !9
  %83 = load double, ptr %19, align 8, !tbaa !9
  %84 = load double, ptr %20, align 8, !tbaa !9
  call void @_ZN7maliput4math10QuaternionC2Edddd(ptr noundef nonnull align 8 dereferenceable(32) %0, double noundef %81, double noundef %82, double noundef %83, double noundef %84)
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7maliput4math10QuaternionC2Edddd(ptr noundef nonnull align 8 dereferenceable(32), double noundef, double noundef, double noundef, double noundef) unnamed_addr #2 align 2

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

%"class.maliput::math::Quaternion" = type { double, double, double, double }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK7maliput4math7Vector31xEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK7maliput4math7Vector31yEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK7maliput4math7Vector31zEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZNK7maliput4math12RollPitchYaw12ToQuaternionEv(ptr dead_on_unwind noalias writable sret(%"class.maliput::math::Quaternion") align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef double @_ZNK7maliput4math7Vector31xEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %4 = fmul double %3, 5.000000e-01
  %5 = tail call noundef double @_ZNK7maliput4math7Vector31yEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %6 = fmul double %5, 5.000000e-01
  %7 = tail call noundef double @_ZNK7maliput4math7Vector31zEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %8 = fmul double %7, 5.000000e-01
  %9 = tail call double @cos(double noundef %4) #3
  %10 = tail call double @sin(double noundef %4) #3
  %11 = tail call double @cos(double noundef %6) #3
  %12 = tail call double @sin(double noundef %6) #3
  %13 = tail call double @cos(double noundef %8) #3
  %14 = tail call double @sin(double noundef %8) #3
  %15 = fmul double %11, %13
  %16 = fmul double %12, %13
  %17 = fmul double %12, %14
  %18 = fmul double %11, %14
  %19 = fmul double %10, %17
  %20 = tail call double @llvm.fmuladd.f64(double %9, double %15, double %19)
  %21 = fneg double %9
  %22 = fmul double %17, %21
  %23 = tail call double @llvm.fmuladd.f64(double %10, double %15, double %22)
  %24 = fmul double %10, %18
  %25 = tail call double @llvm.fmuladd.f64(double %9, double %16, double %24)
  %26 = fneg double %10
  %27 = fmul double %16, %26
  %28 = tail call double @llvm.fmuladd.f64(double %9, double %18, double %27)
  tail call void @_ZN7maliput4math10QuaternionC2Edddd(ptr noundef nonnull align 8 dereferenceable(32) %0, double noundef %20, double noundef %23, double noundef %25, double noundef %28)
  ret void
}

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

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


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