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

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

@XsMath_tinyValue = external constant double, align 8
@XsMath_two = 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @XsVector_assign(ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @XsVector_destruct(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local double @XsVector_cartesianLength(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @XsVector_multiplyScalar(ptr noundef, double noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @XsVector_angularVelocityFromQuaternion(ptr noundef %0, double noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %9 = load ptr, ptr %6, 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 = %3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  call void @XsVector_destruct(ptr noundef %13)
  store i32 1, ptr %8, align 4
  br label %41

14:                                               ; preds = %3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.XsQuaternion, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds [4 x double], ptr %17, i64 0, i64 1
  call void @XsVector_assign(ptr noundef %15, i64 noundef 3, ptr noundef %18)
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call double @XsVector_cartesianLength(ptr noundef %19)
  store double %20, ptr %7, align 8, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load double, ptr %7, align 8, !tbaa !9
  %23 = load double, ptr @XsMath_tinyValue, align 8, !tbaa !9
  %24 = fcmp ogt double %22, %23
  br i1 %24, label %25, label %34

25:                                               ; preds = %14
  %26 = load double, ptr @XsMath_two, align 8, !tbaa !9
  %27 = load double, ptr %7, align 8, !tbaa !9
  %28 = call double @asin(double noundef %27) #4
  %29 = fmul double %26, %28
  %30 = load double, ptr %7, align 8, !tbaa !9
  %31 = load double, ptr %5, align 8, !tbaa !9
  %32 = fmul double %30, %31
  %33 = fdiv double %29, %32
  br label %38

34:                                               ; preds = %14
  %35 = load double, ptr @XsMath_two, align 8, !tbaa !9
  %36 = load double, ptr %5, align 8, !tbaa !9
  %37 = fdiv double %35, %36
  br label %38

38:                                               ; preds = %34, %25
  %39 = phi double [ %33, %25 ], [ %37, %34 ]
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  call void @XsVector_multiplyScalar(ptr noundef %21, double noundef %39, ptr noundef %40)
  store i32 0, ptr %8, align 4
  br label %41

41:                                               ; preds = %38, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %42 = load i32, ptr %8, align 4
  switch i32 %42, label %44 [
    i32 0, label %43
    i32 1, label %43
  ]

43:                                               ; preds = %41, %41
  ret void

44:                                               ; preds = %41
  unreachable
}

declare i32 @XsQuaternion_empty(ptr noundef) #2

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

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

@XsMath_tinyValue = external local_unnamed_addr constant double, align 8
@XsMath_two = external local_unnamed_addr constant double, align 8

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

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

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

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

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

5:                                                ; preds = %3
  tail call void @XsVector_destruct(ptr noundef %0)
  br label %21

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %2, i64 8
  tail call void @XsVector_assign(ptr noundef %0, i64 noundef 3, ptr noundef nonnull %7)
  %8 = tail call double @XsVector_cartesianLength(ptr noundef %0)
  %9 = load double, ptr @XsMath_tinyValue, align 8, !tbaa !5
  %10 = fcmp ogt double %8, %9
  %11 = load double, ptr @XsMath_two, align 8, !tbaa !5
  br i1 %10, label %12, label %17

12:                                               ; preds = %6
  %13 = tail call double @asin(double noundef %8) #3
  %14 = fmul double %11, %13
  %15 = fmul double %8, %1
  %16 = fdiv double %14, %15
  br label %19

17:                                               ; preds = %6
  %18 = fdiv double %11, %1
  br label %19

19:                                               ; preds = %17, %12
  %20 = phi double [ %16, %12 ], [ %18, %17 ]
  tail call void @XsVector_multiplyScalar(ptr noundef %0, double noundef %20, ptr noundef %0)
  br label %21

21:                                               ; preds = %19, %5
  ret void
}

declare i32 @XsQuaternion_empty(ptr noundef) local_unnamed_addr #1

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

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 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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