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

; 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.18 = type { float, float, float, float }

@_ZL13WORLD_FORWARD = external hidden global %union.Vec3, align 4

; 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: nounwind
declare float @sqrtf(float noundef) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z19quat_get_angle_axis4QuatPfP4Vec3(<2 x float> %0, <2 x float> %1, ptr noundef %2, ptr noundef %3) #4 {
  %5 = alloca %union.Quat, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %5, i32 0, i32 0
  store <2 x float> %0, ptr %9, align 4
  %10 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %5, i32 0, i32 1
  store <2 x float> %1, ptr %10, align 4
  store ptr %2, ptr %6, align 8, !tbaa !5
  store ptr %3, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %11 = getelementptr inbounds %struct.anon.18, ptr %5, i32 0, i32 0
  %12 = load float, ptr %11, align 4, !tbaa !9
  %13 = getelementptr inbounds %struct.anon.18, ptr %5, i32 0, i32 0
  %14 = load float, ptr %13, align 4, !tbaa !9
  %15 = getelementptr inbounds %struct.anon.18, ptr %5, i32 0, i32 1
  %16 = load float, ptr %15, align 4, !tbaa !9
  %17 = getelementptr inbounds %struct.anon.18, ptr %5, i32 0, i32 1
  %18 = load float, ptr %17, align 4, !tbaa !9
  %19 = fmul float %16, %18
  %20 = call float @llvm.fmuladd.f32(float %12, float %14, float %19)
  %21 = getelementptr inbounds %struct.anon.18, ptr %5, i32 0, i32 2
  %22 = load float, ptr %21, align 4, !tbaa !9
  %23 = getelementptr inbounds %struct.anon.18, ptr %5, i32 0, i32 2
  %24 = load float, ptr %23, align 4, !tbaa !9
  %25 = call float @llvm.fmuladd.f32(float %22, float %24, float %20)
  %26 = call float @sqrtf(float noundef %25) #5
  store float %26, ptr %8, align 4, !tbaa !10
  %27 = load float, ptr %8, align 4, !tbaa !10
  %28 = fcmp une float %27, 0.000000e+00
  br i1 %28, label %29, label %56

29:                                               ; preds = %4
  %30 = load float, ptr %8, align 4, !tbaa !10
  %31 = getelementptr inbounds %struct.anon.18, ptr %5, i32 0, i32 3
  %32 = load float, ptr %31, align 4, !tbaa !9
  %33 = call float @atan2f(float noundef %30, float noundef %32) #5
  %34 = fmul float 2.000000e+00, %33
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  store float %34, ptr %35, align 4, !tbaa !10
  %36 = load float, ptr %8, align 4, !tbaa !10
  %37 = fdiv float 1.000000e+00, %36
  store float %37, ptr %8, align 4, !tbaa !10
  %38 = getelementptr inbounds %struct.anon.18, ptr %5, i32 0, i32 0
  %39 = load float, ptr %38, align 4, !tbaa !9
  %40 = load float, ptr %8, align 4, !tbaa !10
  %41 = fmul float %39, %40
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.anon, ptr %42, i32 0, i32 0
  store float %41, ptr %43, align 4, !tbaa !9
  %44 = getelementptr inbounds %struct.anon.18, ptr %5, i32 0, i32 1
  %45 = load float, ptr %44, align 4, !tbaa !9
  %46 = load float, ptr %8, align 4, !tbaa !10
  %47 = fmul float %45, %46
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.anon, ptr %48, i32 0, i32 1
  store float %47, ptr %49, align 4, !tbaa !9
  %50 = getelementptr inbounds %struct.anon.18, ptr %5, i32 0, i32 2
  %51 = load float, ptr %50, align 4, !tbaa !9
  %52 = load float, ptr %8, align 4, !tbaa !10
  %53 = fmul float %51, %52
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.anon, ptr %54, i32 0, i32 2
  store float %53, ptr %55, align 4, !tbaa !9
  br label %59

56:                                               ; preds = %4
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  store float 0.000000e+00, ptr %57, align 4, !tbaa !10
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %58, ptr align 4 @_ZL13WORLD_FORWARD, i64 12, i1 false), !tbaa.struct !12
  br label %59

59:                                               ; preds = %56, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  ret void
}

; Function Attrs: nounwind
declare float @atan2f(float noundef, 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"float", !7, i64 0}
!12 = !{i64 0, i64 12, !9}


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

%union.Vec3 = type { %struct.anon }
%struct.anon = type { float, float, float }

@_ZL13WORLD_FORWARD = external hidden local_unnamed_addr global %union.Vec3, align 4

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(readwrite, inaccessiblemem: write) uwtable
define dso_local void @_Z19quat_get_angle_axis4QuatPfP4Vec3(<2 x float> %0, <2 x float> %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #2 {
  %5 = extractelement <2 x float> %0, i64 0
  %6 = fmul <2 x float> %0, %0
  %7 = extractelement <2 x float> %6, i64 1
  %8 = tail call float @llvm.fmuladd.f32(float %5, float %5, float %7)
  %.sroa.7.8.vec.extract = extractelement <2 x float> %1, i64 0
  %9 = tail call float @llvm.fmuladd.f32(float %.sroa.7.8.vec.extract, float %.sroa.7.8.vec.extract, float %8)
  %sqrt = tail call float @llvm.sqrt.f32(float %9)
  %10 = fcmp une float %sqrt, 0.000000e+00
  br i1 %10, label %11, label %20

11:                                               ; preds = %4
  %.sroa.7.12.vec.extract = extractelement <2 x float> %1, i64 1
  %12 = tail call float @atan2f(float noundef %sqrt, float noundef %.sroa.7.12.vec.extract) #5
  %13 = fmul float %12, 2.000000e+00
  store float %13, ptr %2, align 4, !tbaa !5
  %14 = fdiv float 1.000000e+00, %sqrt
  %15 = insertelement <2 x float> poison, float %14, i64 0
  %16 = shufflevector <2 x float> %15, <2 x float> poison, <2 x i32> zeroinitializer
  %17 = fmul <2 x float> %16, %0
  store <2 x float> %17, ptr %3, align 4, !tbaa !9
  %18 = fmul float %.sroa.7.8.vec.extract, %14
  %19 = getelementptr inbounds i8, ptr %3, i64 8
  store float %18, ptr %19, align 4, !tbaa !9
  br label %21

20:                                               ; preds = %4
  store float 0.000000e+00, ptr %2, align 4, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %3, ptr noundef nonnull align 4 dereferenceable(12) @_ZL13WORLD_FORWARD, i64 12, i1 false), !tbaa.struct !10
  br label %21

21:                                               ; preds = %20, %11
  ret void
}

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

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

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


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass,VectorCombinePass