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

; 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.XsQuaternion = type { %union.anon.1 }
%union.anon.1 = type { %struct.anon.2 }
%struct.anon.2 = type { double, double, double, double }
%struct.XsEuler = type { %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { double, double, double }

@XsMath_two = external constant double, align 8
@XsMath_one = external constant double, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @XsEuler_destruct(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @XsEuler_fromQuaternion(ptr noundef %0, ptr noundef %1) #0 {
  %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 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) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call i32 @XsQuaternion_empty(ptr noundef %9)
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %14

12:                                               ; preds = %2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  call void @XsEuler_destruct(ptr noundef %13)
  store i32 1, ptr %8, align 4
  br label %131

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

131:                                              ; preds = %14, %12
  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
  %132 = load i32, ptr %8, align 4
  switch i32 %132, label %134 [
    i32 0, label %133
    i32 1, label %133
  ]

133:                                              ; preds = %131, %131
  ret void

134:                                              ; preds = %131
  unreachable
}

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

declare i32 @XsQuaternion_empty(ptr noundef) #2

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

declare double @XsMath_rad2deg(double noundef) #2

; Function Attrs: nounwind
declare double @atan2(double noundef, double noundef) #4

declare double @XsMath_asinClamped(double noundef) #2

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

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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"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_two = external local_unnamed_addr constant double, align 8
@XsMath_one = external local_unnamed_addr constant double, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @XsEuler_destruct(ptr noundef) local_unnamed_addr #0

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

4:                                                ; preds = %2
  tail call void @XsEuler_destruct(ptr noundef %0)
  br label %48

5:                                                ; preds = %2
  %6 = load double, ptr %1, align 8, !tbaa !5
  %7 = fmul double %6, %6
  %8 = load double, ptr @XsMath_two, align 8, !tbaa !8
  %9 = getelementptr inbounds i8, ptr %1, i64 24
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %7)
  %12 = load double, ptr @XsMath_one, align 8, !tbaa !8
  %13 = fneg double %12
  %14 = tail call double @llvm.fmuladd.f64(double %8, double %11, double %13)
  %15 = getelementptr inbounds i8, ptr %1, i64 8
  %16 = load double, ptr %15, align 8, !tbaa !5
  %17 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %7)
  %18 = tail call double @llvm.fmuladd.f64(double %8, double %17, double %13)
  %19 = getelementptr inbounds i8, ptr %1, i64 16
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = fmul double %6, %16
  %22 = tail call double @llvm.fmuladd.f64(double %20, double %10, double %21)
  %23 = fmul double %8, %22
  %24 = tail call double @atan2(double noundef %23, double noundef %14) #4
  %25 = tail call double @XsMath_rad2deg(double noundef %24) #4
  store double %25, ptr %0, align 8, !tbaa !5
  %26 = load double, ptr %15, align 8, !tbaa !5
  %27 = load double, ptr %9, align 8, !tbaa !5
  %28 = load double, ptr %1, align 8, !tbaa !5
  %29 = load double, ptr %19, align 8, !tbaa !5
  %30 = fneg double %28
  %31 = fmul double %29, %30
  %32 = tail call double @llvm.fmuladd.f64(double %26, double %27, double %31)
  %33 = fmul double %8, %32
  %34 = tail call double @XsMath_asinClamped(double noundef %33) #4
  %35 = tail call double @XsMath_rad2deg(double noundef %34) #4
  %36 = fneg double %35
  %37 = getelementptr inbounds i8, ptr %0, i64 8
  store double %36, ptr %37, align 8, !tbaa !5
  %38 = load double, ptr %15, align 8, !tbaa !5
  %39 = load double, ptr %19, align 8, !tbaa !5
  %40 = load double, ptr %1, align 8, !tbaa !5
  %41 = load double, ptr %9, align 8, !tbaa !5
  %42 = fmul double %40, %41
  %43 = tail call double @llvm.fmuladd.f64(double %38, double %39, double %42)
  %44 = fmul double %8, %43
  %45 = tail call double @atan2(double noundef %44, double noundef %18) #4
  %46 = tail call double @XsMath_rad2deg(double noundef %45) #4
  %47 = getelementptr inbounds i8, ptr %0, i64 16
  store double %46, ptr %47, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %5, %4
  ret void
}

declare i32 @XsQuaternion_empty(ptr noundef) local_unnamed_addr #1

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

declare double @XsMath_rad2deg(double noundef) local_unnamed_addr #1

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

declare double @XsMath_asinClamped(double noundef) local_unnamed_addr #1

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 nosync nounwind speculatable willreturn memory(none) }
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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"double", !6, i64 0}


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