; LLVM IR from maliput/maliput :: src/maliput/math/quaternion.ll (ZN7maliput4math10QuaternionC2EdRKNS0_7Vector3E)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7maliput4math10QuaternionC2EdRKNS0_7Vector3E(ptr noundef nonnull align 8 dereferenceable(32) %0, double noundef %1, ptr noundef nonnull align 8 dereferenceable(24) %2) unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  %10 = getelementptr inbounds %"class.maliput::math::Quaternion", ptr %9, i32 0, i32 0
  store double 0.000000e+00, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds %"class.maliput::math::Quaternion", ptr %9, i32 0, i32 1
  store double 0.000000e+00, ptr %11, align 8, !tbaa !13
  %12 = getelementptr inbounds %"class.maliput::math::Quaternion", ptr %9, i32 0, i32 2
  store double 0.000000e+00, ptr %12, align 8, !tbaa !14
  %13 = getelementptr inbounds %"class.maliput::math::Quaternion", ptr %9, i32 0, i32 3
  store double 0.000000e+00, ptr %13, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = call noundef double @_ZNK7maliput4math10VectorBaseILm3ENS0_7Vector3EE4normEv(ptr noundef nonnull align 8 dereferenceable(24) %14)
  store double %15, ptr %7, align 8, !tbaa !9
  %16 = load double, ptr %7, align 8, !tbaa !9
  %17 = fcmp olt double %16, 1.000000e-15
  br i1 %17, label %18, label %23

18:                                               ; preds = %3
  %19 = getelementptr inbounds %"class.maliput::math::Quaternion", ptr %9, i32 0, i32 0
  store double 1.000000e+00, ptr %19, align 8, !tbaa !11
  %20 = getelementptr inbounds %"class.maliput::math::Quaternion", ptr %9, i32 0, i32 1
  store double 0.000000e+00, ptr %20, align 8, !tbaa !13
  %21 = getelementptr inbounds %"class.maliput::math::Quaternion", ptr %9, i32 0, i32 2
  store double 0.000000e+00, ptr %21, align 8, !tbaa !14
  %22 = getelementptr inbounds %"class.maliput::math::Quaternion", ptr %9, i32 0, i32 3
  store double 0.000000e+00, ptr %22, align 8, !tbaa !15
  br label %48

23:                                               ; preds = %3
  %24 = load double, ptr %5, align 8, !tbaa !9
  %25 = fmul double %24, 5.000000e-01
  store double %25, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %26 = load double, ptr %5, align 8, !tbaa !9
  %27 = call double @sin(double noundef %26) #5
  %28 = load double, ptr %7, align 8, !tbaa !9
  %29 = fdiv double %27, %28
  store double %29, ptr %8, align 8, !tbaa !9
  %30 = load double, ptr %5, align 8, !tbaa !9
  %31 = call double @cos(double noundef %30) #5
  %32 = getelementptr inbounds %"class.maliput::math::Quaternion", ptr %9, i32 0, i32 0
  store double %31, ptr %32, align 8, !tbaa !11
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = call noundef double @_ZNK7maliput4math7Vector31xEv(ptr noundef nonnull align 8 dereferenceable(24) %33)
  %35 = load double, ptr %8, align 8, !tbaa !9
  %36 = fmul double %34, %35
  %37 = getelementptr inbounds %"class.maliput::math::Quaternion", ptr %9, i32 0, i32 1
  store double %36, ptr %37, align 8, !tbaa !13
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = call noundef double @_ZNK7maliput4math7Vector31yEv(ptr noundef nonnull align 8 dereferenceable(24) %38)
  %40 = load double, ptr %8, align 8, !tbaa !9
  %41 = fmul double %39, %40
  %42 = getelementptr inbounds %"class.maliput::math::Quaternion", ptr %9, i32 0, i32 2
  store double %41, ptr %42, align 8, !tbaa !14
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = call noundef double @_ZNK7maliput4math7Vector31zEv(ptr noundef nonnull align 8 dereferenceable(24) %43)
  %45 = load double, ptr %8, align 8, !tbaa !9
  %46 = fmul double %44, %45
  %47 = getelementptr inbounds %"class.maliput::math::Quaternion", ptr %9, i32 0, i32 3
  store double %46, ptr %47, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %48

48:                                               ; preds = %23, %18
  call void @_ZN7maliput4math10Quaternion9normalizeEv(ptr noundef nonnull align 8 dereferenceable(32) %9)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret void
}

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

declare noundef double @_ZNK7maliput4math10VectorBaseILm3ENS0_7Vector3EE4normEv(ptr noundef nonnull align 8 dereferenceable(24)) #2

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

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

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

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7maliput4math10Quaternion9normalizeEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

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 willreturn memory(argmem: readwrite) }
attributes #2 = { "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 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 #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}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN7maliput4math10QuaternionE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 16}
!15 = !{!12, !10, i64 24}


; 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 uwtable
define dso_local void @_ZN7maliput4math10QuaternionC2EdRKNS0_7Vector3E(ptr noundef nonnull align 8 dereferenceable(32) %0, double noundef %1, ptr noundef nonnull align 8 dereferenceable(24) %2) unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %0, i8 0, i64 32, i1 false)
  %5 = tail call noundef double @_ZNK7maliput4math10VectorBaseILm3ENS0_7Vector3EE4normEv(ptr noundef nonnull align 8 dereferenceable(24) %2)
  %6 = fcmp olt double %5, 1.000000e-15
  br i1 %6, label %7, label %8

7:                                                ; preds = %3
  store double 1.000000e+00, ptr %0, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %4, i8 0, i64 16, i1 false)
  br label %20

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = fmul double %1, 5.000000e-01
  %11 = tail call double @sin(double noundef %10) #5
  %12 = fdiv double %11, %5
  %13 = tail call double @cos(double noundef %10) #5
  store double %13, ptr %0, align 8, !tbaa !5
  %14 = tail call noundef double @_ZNK7maliput4math7Vector31xEv(ptr noundef nonnull align 8 dereferenceable(24) %2)
  %15 = fmul double %12, %14
  store double %15, ptr %4, align 8, !tbaa !10
  %16 = tail call noundef double @_ZNK7maliput4math7Vector31yEv(ptr noundef nonnull align 8 dereferenceable(24) %2)
  %17 = fmul double %12, %16
  store double %17, ptr %9, align 8, !tbaa !11
  %18 = tail call noundef double @_ZNK7maliput4math7Vector31zEv(ptr noundef nonnull align 8 dereferenceable(24) %2)
  %19 = fmul double %12, %18
  br label %20

20:                                               ; preds = %8, %7
  %storemerge = phi double [ %19, %8 ], [ 0.000000e+00, %7 ]
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  store double %storemerge, ptr %21, align 8, !tbaa !12
  tail call void @_ZN7maliput4math10Quaternion9normalizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  ret void
}

declare noundef double @_ZNK7maliput4math10VectorBaseILm3ENS0_7Vector3EE4normEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1

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

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

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7maliput4math10Quaternion9normalizeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 = { "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 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"_ZTSN7maliput4math10QuaternionE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 16}
!12 = !{!6, !7, i64 24}


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