; LLVM IR from ashishzero/karma :: src/modules/core/lin_maths.ll (Z21quat_get_euler_angles4Quat)

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

%union.Vec3 = type { %struct.anon }
%struct.anon = type { float, float, float }
%union.Quat = type { [4 x float] }
%struct.anon.17 = type { float, float, float, float }

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #1

; Function Attrs: nounwind
declare float @atan2f(float noundef, float noundef) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local { <2 x float>, float } @_Z21quat_get_euler_angles4Quat(<2 x float> %0, <2 x float> %1) #4 {
  %3 = alloca %union.Vec3, align 4
  %4 = alloca %union.Quat, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca { <2 x float>, float }, align 8
  %11 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %4, i32 0, i32 0
  store <2 x float> %0, ptr %11, align 4
  %12 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %4, i32 0, i32 1
  store <2 x float> %1, ptr %12, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %13 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 3
  %14 = load float, ptr %13, align 4, !tbaa !5
  %15 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 0
  %16 = load float, ptr %15, align 4, !tbaa !5
  %17 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 1
  %18 = load float, ptr %17, align 4, !tbaa !5
  %19 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 2
  %20 = load float, ptr %19, align 4, !tbaa !5
  %21 = fmul float %18, %20
  %22 = call float @llvm.fmuladd.f32(float %14, float %16, float %21)
  %23 = fmul float 2.000000e+00, %22
  store float %23, ptr %5, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %24 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 0
  %25 = load float, ptr %24, align 4, !tbaa !5
  %26 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 0
  %27 = load float, ptr %26, align 4, !tbaa !5
  %28 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 1
  %29 = load float, ptr %28, align 4, !tbaa !5
  %30 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 1
  %31 = load float, ptr %30, align 4, !tbaa !5
  %32 = fmul float %29, %31
  %33 = call float @llvm.fmuladd.f32(float %25, float %27, float %32)
  %34 = call float @llvm.fmuladd.f32(float -2.000000e+00, float %33, float 1.000000e+00)
  store float %34, ptr %6, align 4, !tbaa !8
  %35 = load float, ptr %5, align 4, !tbaa !8
  %36 = load float, ptr %6, align 4, !tbaa !8
  %37 = call float @atan2f(float noundef %35, float noundef %36) #5
  %38 = getelementptr inbounds %struct.anon, ptr %3, i32 0, i32 2
  store float %37, ptr %38, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %39 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 3
  %40 = load float, ptr %39, align 4, !tbaa !5
  %41 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 1
  %42 = load float, ptr %41, align 4, !tbaa !5
  %43 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 2
  %44 = load float, ptr %43, align 4, !tbaa !5
  %45 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 0
  %46 = load float, ptr %45, align 4, !tbaa !5
  %47 = fmul float %44, %46
  %48 = fneg float %47
  %49 = call float @llvm.fmuladd.f32(float %40, float %42, float %48)
  %50 = fmul float 2.000000e+00, %49
  store float %50, ptr %7, align 4, !tbaa !8
  %51 = load float, ptr %7, align 4, !tbaa !8
  %52 = call float @llvm.fabs.f32(float %51)
  %53 = fcmp oge float %52, 1.000000e+00
  br i1 %53, label %54, label %58

54:                                               ; preds = %2
  %55 = load float, ptr %7, align 4, !tbaa !8
  %56 = call float @llvm.copysign.f32(float 0x3FF921FB60000000, float %55)
  %57 = getelementptr inbounds %struct.anon, ptr %3, i32 0, i32 0
  store float %56, ptr %57, align 4, !tbaa !5
  br label %62

58:                                               ; preds = %2
  %59 = load float, ptr %7, align 4, !tbaa !8
  %60 = call float @asinf(float noundef %59) #5
  %61 = getelementptr inbounds %struct.anon, ptr %3, i32 0, i32 0
  store float %60, ptr %61, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %58, %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %63 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 3
  %64 = load float, ptr %63, align 4, !tbaa !5
  %65 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 2
  %66 = load float, ptr %65, align 4, !tbaa !5
  %67 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 0
  %68 = load float, ptr %67, align 4, !tbaa !5
  %69 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 1
  %70 = load float, ptr %69, align 4, !tbaa !5
  %71 = fmul float %68, %70
  %72 = call float @llvm.fmuladd.f32(float %64, float %66, float %71)
  %73 = fmul float 2.000000e+00, %72
  store float %73, ptr %8, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %74 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 1
  %75 = load float, ptr %74, align 4, !tbaa !5
  %76 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 1
  %77 = load float, ptr %76, align 4, !tbaa !5
  %78 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 2
  %79 = load float, ptr %78, align 4, !tbaa !5
  %80 = getelementptr inbounds %struct.anon.17, ptr %4, i32 0, i32 2
  %81 = load float, ptr %80, align 4, !tbaa !5
  %82 = fmul float %79, %81
  %83 = call float @llvm.fmuladd.f32(float %75, float %77, float %82)
  %84 = call float @llvm.fmuladd.f32(float -2.000000e+00, float %83, float 1.000000e+00)
  store float %84, ptr %9, align 4, !tbaa !8
  %85 = load float, ptr %8, align 4, !tbaa !8
  %86 = load float, ptr %9, align 4, !tbaa !8
  %87 = call float @atan2f(float noundef %85, float noundef %86) #5
  %88 = getelementptr inbounds %struct.anon, ptr %3, i32 0, i32 1
  store float %87, ptr %88, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  %89 = getelementptr inbounds %union.Vec3, ptr %3, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 4 %89, i64 12, i1 false)
  %90 = load { <2 x float>, float }, ptr %10, align 8
  ret { <2 x float>, float } %90
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.copysign.f32(float, float) #1

; Function Attrs: nounwind
declare float @asinf(float noundef) #3

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @atan2f(float noundef, float noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write) uwtable
define dso_local { <2 x float>, float } @_Z21quat_get_euler_angles4Quat(<2 x float> %0, <2 x float> %1) local_unnamed_addr #2 {
  %.sroa.13.12.vec.extract = extractelement <2 x float> %1, i64 1
  %.sroa.07.0.vec.extract = extractelement <2 x float> %0, i64 0
  %.sroa.07.4.vec.extract = extractelement <2 x float> %0, i64 1
  %.sroa.13.8.vec.extract = extractelement <2 x float> %1, i64 0
  %3 = fmul float %.sroa.07.4.vec.extract, %.sroa.13.8.vec.extract
  %4 = tail call float @llvm.fmuladd.f32(float %.sroa.13.12.vec.extract, float %.sroa.07.0.vec.extract, float %3)
  %5 = fmul float %4, 2.000000e+00
  %6 = fmul float %.sroa.07.4.vec.extract, %.sroa.07.4.vec.extract
  %7 = tail call float @llvm.fmuladd.f32(float %.sroa.07.0.vec.extract, float %.sroa.07.0.vec.extract, float %6)
  %8 = tail call float @llvm.fmuladd.f32(float %7, float -2.000000e+00, float 1.000000e+00)
  %9 = tail call float @atan2f(float noundef %5, float noundef %8) #3
  %10 = fneg float %.sroa.13.8.vec.extract
  %11 = fmul float %.sroa.07.0.vec.extract, %10
  %12 = tail call float @llvm.fmuladd.f32(float %.sroa.13.12.vec.extract, float %.sroa.07.4.vec.extract, float %11)
  %13 = fmul float %12, 2.000000e+00
  %14 = tail call float @llvm.fabs.f32(float %13)
  %15 = fcmp ult float %14, 1.000000e+00
  br i1 %15, label %18, label %16

16:                                               ; preds = %2
  %17 = tail call float @llvm.copysign.f32(float 0x3FF921FB60000000, float %13)
  br label %20

18:                                               ; preds = %2
  %19 = tail call float @asinf(float noundef %13) #3
  br label %20

20:                                               ; preds = %18, %16
  %.sink = phi float [ %19, %18 ], [ %17, %16 ]
  %.sroa.040.0.vec.insert43 = insertelement <2 x float> poison, float %.sink, i64 0
  %21 = fmul float %.sroa.07.0.vec.extract, %.sroa.07.4.vec.extract
  %22 = tail call float @llvm.fmuladd.f32(float %.sroa.13.12.vec.extract, float %.sroa.13.8.vec.extract, float %21)
  %23 = fmul float %22, 2.000000e+00
  %24 = fmul <2 x float> %1, %1
  %25 = extractelement <2 x float> %24, i64 0
  %26 = tail call float @llvm.fmuladd.f32(float %.sroa.07.4.vec.extract, float %.sroa.07.4.vec.extract, float %25)
  %27 = tail call float @llvm.fmuladd.f32(float %26, float -2.000000e+00, float 1.000000e+00)
  %28 = tail call float @atan2f(float noundef %23, float noundef %27) #3
  %.sroa.040.4.vec.insert = insertelement <2 x float> %.sroa.040.0.vec.insert43, float %28, i64 1
  %.fca.0.insert = insertvalue { <2 x float>, float } poison, <2 x float> %.sroa.040.4.vec.insert, 0
  %.fca.1.insert = insertvalue { <2 x float>, float } %.fca.0.insert, float %9, 1
  ret { <2 x float>, float } %.fca.1.insert
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.copysign.f32(float, float) #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @asinf(float noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { mustprogress nofree nounwind willreturn memory(write) uwtable "min-legal-vector-width"="64" "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,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass