; LLVM IR from MRPT/mrpt :: 3rdparty/xspublic/xstypes (xsquaternion)

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

%struct.XsEuler = type { %union.anon.0 }
%union.anon.0 = type { %struct.anon.1 }
%struct.anon.1 = type { double, double, double }
%struct.XsQuaternion = type { %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { double, double, double, double }

@XsMath_pt5 = external constant double, align 8

; 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: nounwind uwtable
define dso_local void @XsQuaternion_fromEulerAngles(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
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  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) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call i32 @XsEuler_empty(ptr noundef %12)
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %18

15:                                               ; preds = %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call ptr @XsQuaternion_identity()
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %16, ptr align 8 %17, i64 32, i1 false), !tbaa.struct !9
  store i32 1, ptr %11, align 4
  br label %121

18:                                               ; preds = %2
  %19 = load double, ptr @XsMath_pt5, align 8, !tbaa !11
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.XsEuler, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %struct.anon.1, ptr %21, i32 0, i32 0
  %23 = load double, ptr %22, align 8, !tbaa !10
  %24 = call double @XsMath_deg2rad(double noundef %23)
  %25 = fmul double %19, %24
  %26 = call double @cos(double noundef %25) #6
  store double %26, ptr %5, align 8, !tbaa !11
  %27 = load double, ptr @XsMath_pt5, align 8, !tbaa !11
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.XsEuler, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds %struct.anon.1, ptr %29, i32 0, i32 0
  %31 = load double, ptr %30, align 8, !tbaa !10
  %32 = call double @XsMath_deg2rad(double noundef %31)
  %33 = fmul double %27, %32
  %34 = call double @sin(double noundef %33) #6
  store double %34, ptr %6, align 8, !tbaa !11
  %35 = load double, ptr @XsMath_pt5, align 8, !tbaa !11
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.XsEuler, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds %struct.anon.1, ptr %37, i32 0, i32 1
  %39 = load double, ptr %38, align 8, !tbaa !10
  %40 = call double @XsMath_deg2rad(double noundef %39)
  %41 = fmul double %35, %40
  %42 = call double @cos(double noundef %41) #6
  store double %42, ptr %7, align 8, !tbaa !11
  %43 = load double, ptr @XsMath_pt5, align 8, !tbaa !11
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.XsEuler, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds %struct.anon.1, ptr %45, i32 0, i32 1
  %47 = load double, ptr %46, align 8, !tbaa !10
  %48 = call double @XsMath_deg2rad(double noundef %47)
  %49 = fmul double %43, %48
  %50 = call double @sin(double noundef %49) #6
  store double %50, ptr %8, align 8, !tbaa !11
  %51 = load double, ptr @XsMath_pt5, align 8, !tbaa !11
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.XsEuler, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds %struct.anon.1, ptr %53, i32 0, i32 2
  %55 = load double, ptr %54, align 8, !tbaa !10
  %56 = call double @XsMath_deg2rad(double noundef %55)
  %57 = fmul double %51, %56
  %58 = call double @cos(double noundef %57) #6
  store double %58, ptr %9, align 8, !tbaa !11
  %59 = load double, ptr @XsMath_pt5, align 8, !tbaa !11
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.XsEuler, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct.anon.1, ptr %61, i32 0, i32 2
  %63 = load double, ptr %62, align 8, !tbaa !10
  %64 = call double @XsMath_deg2rad(double noundef %63)
  %65 = fmul double %59, %64
  %66 = call double @sin(double noundef %65) #6
  store double %66, ptr %10, align 8, !tbaa !11
  %67 = load double, ptr %5, align 8, !tbaa !11
  %68 = load double, ptr %7, align 8, !tbaa !11
  %69 = fmul double %67, %68
  %70 = load double, ptr %9, align 8, !tbaa !11
  %71 = load double, ptr %6, align 8, !tbaa !11
  %72 = load double, ptr %8, align 8, !tbaa !11
  %73 = fmul double %71, %72
  %74 = load double, ptr %10, align 8, !tbaa !11
  %75 = fmul double %73, %74
  %76 = call double @llvm.fmuladd.f64(double %69, double %70, double %75)
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.XsQuaternion, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds %struct.anon, ptr %78, i32 0, i32 0
  store double %76, ptr %79, align 8, !tbaa !10
  %80 = load double, ptr %6, align 8, !tbaa !11
  %81 = load double, ptr %7, align 8, !tbaa !11
  %82 = fmul double %80, %81
  %83 = load double, ptr %9, align 8, !tbaa !11
  %84 = load double, ptr %5, align 8, !tbaa !11
  %85 = load double, ptr %8, align 8, !tbaa !11
  %86 = fmul double %84, %85
  %87 = load double, ptr %10, align 8, !tbaa !11
  %88 = fmul double %86, %87
  %89 = fneg double %88
  %90 = call double @llvm.fmuladd.f64(double %82, double %83, double %89)
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.XsQuaternion, ptr %91, i32 0, i32 0
  %93 = getelementptr inbounds %struct.anon, ptr %92, i32 0, i32 1
  store double %90, ptr %93, align 8, !tbaa !10
  %94 = load double, ptr %5, align 8, !tbaa !11
  %95 = load double, ptr %8, align 8, !tbaa !11
  %96 = fmul double %94, %95
  %97 = load double, ptr %9, align 8, !tbaa !11
  %98 = load double, ptr %6, align 8, !tbaa !11
  %99 = load double, ptr %7, align 8, !tbaa !11
  %100 = fmul double %98, %99
  %101 = load double, ptr %10, align 8, !tbaa !11
  %102 = fmul double %100, %101
  %103 = call double @llvm.fmuladd.f64(double %96, double %97, double %102)
  %104 = load ptr, ptr %3, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.XsQuaternion, ptr %104, i32 0, i32 0
  %106 = getelementptr inbounds %struct.anon, ptr %105, i32 0, i32 2
  store double %103, ptr %106, align 8, !tbaa !10
  %107 = load double, ptr %5, align 8, !tbaa !11
  %108 = load double, ptr %7, align 8, !tbaa !11
  %109 = fmul double %107, %108
  %110 = load double, ptr %10, align 8, !tbaa !11
  %111 = load double, ptr %6, align 8, !tbaa !11
  %112 = load double, ptr %8, align 8, !tbaa !11
  %113 = fmul double %111, %112
  %114 = load double, ptr %9, align 8, !tbaa !11
  %115 = fmul double %113, %114
  %116 = fneg double %115
  %117 = call double @llvm.fmuladd.f64(double %109, double %110, double %116)
  %118 = load ptr, ptr %3, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.XsQuaternion, ptr %118, i32 0, i32 0
  %120 = getelementptr inbounds %struct.anon, ptr %119, i32 0, i32 3
  store double %117, ptr %120, align 8, !tbaa !10
  store i32 0, ptr %11, align 4
  br label %121

121:                                              ; preds = %18, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  %122 = load i32, ptr %11, align 4
  switch i32 %122, label %124 [
    i32 0, label %123
    i32 1, label %123
  ]

123:                                              ; preds = %121, %121
  ret void

124:                                              ; preds = %121
  unreachable
}

declare i32 @XsEuler_empty(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @XsQuaternion_identity() #2

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

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

declare double @XsMath_deg2rad(double noundef) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = { "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: readwrite) }
attributes #5 = { 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 #6 = { 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/C++ TBAA"}
!9 = !{i64 0, i64 32, !10}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"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"

@XsMath_pt5 = external local_unnamed_addr constant double, align 8

; Function Attrs: nounwind uwtable
define dso_local void @XsQuaternion_fromEulerAngles(ptr nocapture noundef writeonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @XsEuler_empty(ptr noundef %1) #5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %6, label %4

4:                                                ; preds = %2
  %5 = tail call ptr @XsQuaternion_identity()
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %5, i64 32, i1 false), !tbaa.struct !5
  br label %59

6:                                                ; preds = %2
  %7 = load double, ptr @XsMath_pt5, align 8, !tbaa !9
  %8 = load double, ptr %1, align 8, !tbaa !6
  %9 = tail call double @XsMath_deg2rad(double noundef %8) #5
  %10 = fmul double %7, %9
  %11 = tail call double @cos(double noundef %10) #5
  %12 = load double, ptr %1, align 8, !tbaa !6
  %13 = tail call double @XsMath_deg2rad(double noundef %12) #5
  %14 = fmul double %7, %13
  %15 = tail call double @sin(double noundef %14) #5
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  %17 = load double, ptr %16, align 8, !tbaa !6
  %18 = tail call double @XsMath_deg2rad(double noundef %17) #5
  %19 = fmul double %7, %18
  %20 = tail call double @cos(double noundef %19) #5
  %21 = load double, ptr %16, align 8, !tbaa !6
  %22 = tail call double @XsMath_deg2rad(double noundef %21) #5
  %23 = fmul double %7, %22
  %24 = tail call double @sin(double noundef %23) #5
  %25 = getelementptr inbounds i8, ptr %1, i64 16
  %26 = load double, ptr %25, align 8, !tbaa !6
  %27 = tail call double @XsMath_deg2rad(double noundef %26) #5
  %28 = fmul double %7, %27
  %29 = tail call double @cos(double noundef %28) #5
  %30 = load double, ptr %25, align 8, !tbaa !6
  %31 = tail call double @XsMath_deg2rad(double noundef %30) #5
  %32 = fmul double %7, %31
  %33 = tail call double @sin(double noundef %32) #5
  %34 = fmul double %15, %24
  %35 = fmul double %11, %24
  %36 = fneg double %35
  %37 = insertelement <2 x double> poison, double %11, i64 0
  %38 = insertelement <2 x double> %37, double %15, i64 1
  %39 = insertelement <2 x double> poison, double %20, i64 0
  %40 = shufflevector <2 x double> %39, <2 x double> poison, <2 x i32> zeroinitializer
  %41 = fmul <2 x double> %38, %40
  %42 = insertelement <2 x double> poison, double %34, i64 0
  %43 = insertelement <2 x double> %42, double %36, i64 1
  %44 = insertelement <2 x double> poison, double %33, i64 0
  %45 = shufflevector <2 x double> %44, <2 x double> poison, <2 x i32> zeroinitializer
  %46 = fmul <2 x double> %43, %45
  %47 = insertelement <2 x double> poison, double %29, i64 0
  %48 = shufflevector <2 x double> %47, <2 x double> poison, <2 x i32> zeroinitializer
  %49 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %41, <2 x double> %48, <2 x double> %46)
  store <2 x double> %49, ptr %0, align 8, !tbaa !6
  %50 = getelementptr inbounds i8, ptr %0, i64 16
  %51 = fneg double %34
  %52 = shufflevector <2 x double> %41, <2 x double> poison, <2 x i32> <i32 1, i32 0>
  %53 = insertelement <2 x double> %52, double %29, i64 1
  %54 = insertelement <2 x double> %44, double %51, i64 1
  %55 = fmul <2 x double> %53, %54
  %56 = insertelement <2 x double> %52, double %35, i64 0
  %57 = shufflevector <2 x double> %53, <2 x double> %44, <2 x i32> <i32 1, i32 2>
  %58 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %56, <2 x double> %57, <2 x double> %55)
  store <2 x double> %58, ptr %50, align 8, !tbaa !6
  br label %59

59:                                               ; preds = %6, %4
  ret void
}

declare i32 @XsEuler_empty(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @XsQuaternion_identity() local_unnamed_addr #0

; 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

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

declare double @XsMath_deg2rad(double noundef) local_unnamed_addr #1

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

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

attributes #0 = { 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 #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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{i64 0, i64 32, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}


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