; LLVM IR from thuhcsi/Crystal.TTVS :: Xface/XFace/src/XMath/Quaternion.ll (ZNK5XMath10Quaternion11ToAxisAngleEv)

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

%"class.XMath::AxisAngle" = type { %"class.XMath::Vector3", float }
%"class.XMath::Vector3" = type { float, float, float }
%"class.XMath::Quaternion" = type { float, float, float, float }

; 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4sqrtf(float noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5XMath7Vector3D2Ev(ptr noundef nonnull align 4 dereferenceable(12)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK5XMath10Quaternion11ToAxisAngleEv(ptr dead_on_unwind noalias writable sret(%"class.XMath::AxisAngle") align 4 %0, ptr noundef nonnull align 4 dereferenceable(16) %1) #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca %"class.XMath::Vector3", align 4
  %8 = alloca float, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %12 = getelementptr inbounds %"class.XMath::Quaternion", ptr %11, i32 0, i32 3
  %13 = load float, ptr %12, align 4, !tbaa !9
  %14 = getelementptr inbounds %"class.XMath::Quaternion", ptr %11, i32 0, i32 3
  %15 = load float, ptr %14, align 4, !tbaa !9
  %16 = fmul float %13, %15
  store float %16, ptr %5, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %17 = load float, ptr %5, align 4, !tbaa !12
  %18 = fcmp olt float %17, 1.000000e+00
  br i1 %18, label %19, label %24

19:                                               ; preds = %2
  %20 = load float, ptr %5, align 4, !tbaa !12
  %21 = fsub float 1.000000e+00, %20
  %22 = call noundef float @_ZSt4sqrtf(float noundef %21)
  %23 = fdiv float 1.000000e+00, %22
  br label %25

24:                                               ; preds = %2
  br label %25

25:                                               ; preds = %24, %19
  %26 = phi float [ %23, %19 ], [ 1.000000e+00, %24 ]
  store float %26, ptr %6, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 12, ptr %7) #4
  %27 = getelementptr inbounds %"class.XMath::Quaternion", ptr %11, i32 0, i32 0
  %28 = load float, ptr %27, align 4, !tbaa !13
  %29 = load float, ptr %6, align 4, !tbaa !12
  %30 = fmul float %28, %29
  %31 = getelementptr inbounds %"class.XMath::Quaternion", ptr %11, i32 0, i32 1
  %32 = load float, ptr %31, align 4, !tbaa !14
  %33 = load float, ptr %6, align 4, !tbaa !12
  %34 = fmul float %32, %33
  %35 = getelementptr inbounds %"class.XMath::Quaternion", ptr %11, i32 0, i32 2
  %36 = load float, ptr %35, align 4, !tbaa !15
  %37 = load float, ptr %6, align 4, !tbaa !12
  %38 = fmul float %36, %37
  call void @_ZN5XMath7Vector3C2Efff(ptr noundef nonnull align 4 dereferenceable(12) %7, float noundef %30, float noundef %34, float noundef %38)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %39 = getelementptr inbounds %"class.XMath::Quaternion", ptr %11, i32 0, i32 3
  %40 = load float, ptr %39, align 4, !tbaa !9
  %41 = invoke noundef float @_ZSt4acosf(float noundef %40)
          to label %42 unwind label %50

42:                                               ; preds = %25
  %43 = fmul float %41, 2.000000e+00
  store float %43, ptr %8, align 4, !tbaa !12
  %44 = getelementptr inbounds %"class.XMath::Quaternion", ptr %11, i32 0, i32 3
  %45 = load float, ptr %44, align 4, !tbaa !9
  %46 = invoke noundef float @_ZSt4acosf(float noundef %45)
          to label %47 unwind label %50

47:                                               ; preds = %42
  %48 = fmul float %46, 2.000000e+00
  invoke void @_ZN5XMath9AxisAngleC2ERKNS_7Vector3Ef(ptr noundef nonnull align 4 dereferenceable(16) %0, ptr noundef nonnull align 4 dereferenceable(12) %7, float noundef %48)
          to label %49 unwind label %50

49:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @_ZN5XMath7Vector3D2Ev(ptr noundef nonnull align 4 dereferenceable(12) %7) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void

50:                                               ; preds = %47, %42, %25
  %51 = landingpad { ptr, i32 }
          cleanup
  %52 = extractvalue { ptr, i32 } %51, 0
  store ptr %52, ptr %9, align 8
  %53 = extractvalue { ptr, i32 } %51, 1
  store i32 %53, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @_ZN5XMath7Vector3D2Ev(ptr noundef nonnull align 4 dereferenceable(12) %7) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %54

54:                                               ; preds = %50
  %55 = load ptr, ptr %9, align 8
  %56 = load i32, ptr %10, align 4
  %57 = insertvalue { ptr, i32 } poison, ptr %55, 0
  %58 = insertvalue { ptr, i32 } %57, i32 %56, 1
  resume { ptr, i32 } %58
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5XMath7Vector3C2Efff(ptr noundef nonnull align 4 dereferenceable(12), float noundef, float noundef, float noundef) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4acosf(float noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5XMath9AxisAngleC2ERKNS_7Vector3Ef(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(12), float noundef) unnamed_addr #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 = { mustprogress 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 = { mustprogress 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 #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++ TBAA"}
!9 = !{!10, !11, i64 12}
!10 = !{!"_ZTSN5XMath10QuaternionE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!11 = !{!"float", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!10, !11, i64 4}
!15 = !{!10, !11, i64 8}


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

%"class.XMath::AxisAngle" = type { %"class.XMath::Vector3", float }
%"class.XMath::Vector3" = type { float, float, float }

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

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4sqrtf(float noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5XMath7Vector3D2Ev(ptr noundef nonnull align 4 dereferenceable(12)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK5XMath10Quaternion11ToAxisAngleEv(ptr dead_on_unwind noalias writable sret(%"class.XMath::AxisAngle") align 4 %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(16) %1) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.XMath::Vector3", align 4
  %4 = getelementptr inbounds i8, ptr %1, i64 12
  %5 = load float, ptr %4, align 4, !tbaa !5
  %6 = fmul float %5, %5
  %7 = fcmp olt float %6, 1.000000e+00
  br i1 %7, label %8, label %12

8:                                                ; preds = %2
  %9 = fsub float 1.000000e+00, %6
  %10 = tail call noundef float @_ZSt4sqrtf(float noundef %9)
  %11 = fdiv float 1.000000e+00, %10
  br label %12

12:                                               ; preds = %2, %8
  %13 = phi float [ %11, %8 ], [ 1.000000e+00, %2 ]
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #4
  %14 = load float, ptr %1, align 4, !tbaa !10
  %15 = fmul float %13, %14
  %16 = getelementptr inbounds i8, ptr %1, i64 4
  %17 = load float, ptr %16, align 4, !tbaa !11
  %18 = fmul float %13, %17
  %19 = getelementptr inbounds i8, ptr %1, i64 8
  %20 = load float, ptr %19, align 4, !tbaa !12
  %21 = fmul float %13, %20
  call void @_ZN5XMath7Vector3C2Efff(ptr noundef nonnull align 4 dereferenceable(12) %3, float noundef %15, float noundef %18, float noundef %21)
  %22 = load float, ptr %4, align 4, !tbaa !5
  %23 = call noundef float @_ZSt4acosf(float noundef %22)
  %24 = load float, ptr %4, align 4, !tbaa !5
  %25 = call noundef float @_ZSt4acosf(float noundef %24)
  %26 = fmul float %25, 2.000000e+00
  invoke void @_ZN5XMath9AxisAngleC2ERKNS_7Vector3Ef(ptr noundef nonnull align 4 dereferenceable(16) %0, ptr noundef nonnull align 4 dereferenceable(12) %3, float noundef %26)
          to label %27 unwind label %28

27:                                               ; preds = %12
  call void @_ZN5XMath7Vector3D2Ev(ptr noundef nonnull align 4 dereferenceable(12) %3) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #4
  ret void

28:                                               ; preds = %12
  %29 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN5XMath7Vector3D2Ev(ptr noundef nonnull align 4 dereferenceable(12) %3) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #4
  resume { ptr, i32 } %29
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5XMath7Vector3C2Efff(ptr noundef nonnull align 4 dereferenceable(12), float noundef, float noundef, float noundef) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4acosf(float noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5XMath9AxisAngleC2ERKNS_7Vector3Ef(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(12), float noundef) unnamed_addr #3 align 2

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


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