; LLVM IR from yangfengzzz/DigitalVox3 :: vox.render/runtime/controls (spherical)

; 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.vox::control::Spherical" = type { float, float, float }
%"struct.vox::math::Float3" = type { float, float, float }

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZN3vox4math5ClampIfEET_S2_S2_S2_(float noundef, float noundef, float noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3vox7control9Spherical11setFromVec3ERKNS_4math6Float3E(ptr noundef nonnull align 4 dereferenceable(12) %0, ptr noundef nonnull align 4 dereferenceable(12) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = call noundef float @_ZN3vox4math6LengthERKNS0_6Float3E(ptr noundef nonnull align 4 dereferenceable(12) %6)
  %8 = getelementptr inbounds %"class.vox::control::Spherical", ptr %5, i32 0, i32 0
  store float %7, ptr %8, align 4, !tbaa !9
  %9 = getelementptr inbounds %"class.vox::control::Spherical", ptr %5, i32 0, i32 0
  %10 = load float, ptr %9, align 4, !tbaa !9
  %11 = fcmp oeq float %10, 0.000000e+00
  br i1 %11, label %12, label %15

12:                                               ; preds = %2
  %13 = getelementptr inbounds %"class.vox::control::Spherical", ptr %5, i32 0, i32 2
  store float 0.000000e+00, ptr %13, align 4, !tbaa !12
  %14 = getelementptr inbounds %"class.vox::control::Spherical", ptr %5, i32 0, i32 1
  store float 0.000000e+00, ptr %14, align 4, !tbaa !13
  br label %33

15:                                               ; preds = %2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %"struct.vox::math::Float3", ptr %16, i32 0, i32 0
  %18 = load float, ptr %17, align 4, !tbaa !14
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.vox::math::Float3", ptr %19, i32 0, i32 2
  %21 = load float, ptr %20, align 4, !tbaa !16
  %22 = call noundef float @_ZSt5atan2ff(float noundef %18, float noundef %21)
  %23 = getelementptr inbounds %"class.vox::control::Spherical", ptr %5, i32 0, i32 2
  store float %22, ptr %23, align 4, !tbaa !12
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.vox::math::Float3", ptr %24, i32 0, i32 1
  %26 = load float, ptr %25, align 4, !tbaa !17
  %27 = getelementptr inbounds %"class.vox::control::Spherical", ptr %5, i32 0, i32 0
  %28 = load float, ptr %27, align 4, !tbaa !9
  %29 = fdiv float %26, %28
  %30 = call noundef float @_ZN3vox4math5ClampIfEET_S2_S2_S2_(float noundef %29, float noundef -1.000000e+00, float noundef 1.000000e+00)
  %31 = call noundef float @_ZSt4acosf(float noundef %30)
  %32 = getelementptr inbounds %"class.vox::control::Spherical", ptr %5, i32 0, i32 1
  store float %31, ptr %32, align 4, !tbaa !13
  br label %33

33:                                               ; preds = %15, %12
  ret void
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef float @_ZN3vox4math6LengthERKNS0_6Float3E(ptr noundef nonnull align 4 dereferenceable(12)) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5atan2ff(float noundef, float noundef) #3

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

attributes #0 = { alwaysinline 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 #1 = { 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 #2 = { alwaysinline 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 #3 = { 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" }

!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 0}
!10 = !{!"_ZTSN3vox7control9SphericalE", !11, i64 0, !11, i64 4, !11, i64 8}
!11 = !{!"float", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 4}
!14 = !{!15, !11, i64 0}
!15 = !{!"_ZTSN3vox4math6Float3E", !11, i64 0, !11, i64 4, !11, i64 8}
!16 = !{!15, !11, i64 8}
!17 = !{!15, !11, i64 4}


; 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: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZN3vox4math5ClampIfEET_S2_S2_S2_(float noundef, float noundef, float noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3vox7control9Spherical11setFromVec3ERKNS_4math6Float3E(ptr nocapture noundef nonnull align 4 dereferenceable(12) %0, ptr noundef nonnull align 4 dereferenceable(12) %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef float @_ZN3vox4math6LengthERKNS0_6Float3E(ptr noundef nonnull align 4 dereferenceable(12) %1)
  store float %3, ptr %0, align 4, !tbaa !5
  %4 = fcmp oeq float %3, 0.000000e+00
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  store float 0.000000e+00, ptr %6, align 4, !tbaa !10
  br label %19

7:                                                ; preds = %2
  %8 = load float, ptr %1, align 4, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load float, ptr %9, align 4, !tbaa !13
  %11 = tail call noundef float @_ZSt5atan2ff(float noundef %8, float noundef %10)
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  store float %11, ptr %12, align 4, !tbaa !10
  %13 = getelementptr inbounds i8, ptr %1, i64 4
  %14 = load float, ptr %13, align 4, !tbaa !14
  %15 = load float, ptr %0, align 4, !tbaa !5
  %16 = fdiv float %14, %15
  %17 = tail call noundef float @_ZN3vox4math5ClampIfEET_S2_S2_S2_(float noundef %16, float noundef -1.000000e+00, float noundef 1.000000e+00)
  %18 = tail call noundef float @_ZSt4acosf(float noundef %17)
  br label %19

19:                                               ; preds = %7, %5
  %.sink = phi float [ 0.000000e+00, %5 ], [ %18, %7 ]
  %20 = getelementptr inbounds i8, ptr %0, i64 4
  store float %.sink, ptr %20, align 4
  ret void
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef float @_ZN3vox4math6LengthERKNS0_6Float3E(ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5atan2ff(float noundef, float noundef) local_unnamed_addr #3

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

attributes #0 = { alwaysinline 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 #1 = { 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 #2 = { alwaysinline 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 #3 = { 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" }

!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 0}
!6 = !{!"_ZTSN3vox7control9SphericalE", !7, i64 0, !7, i64 4, !7, i64 8}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !7, i64 0}
!12 = !{!"_ZTSN3vox4math6Float3E", !7, i64 0, !7, i64 4, !7, i64 8}
!13 = !{!12, !7, i64 8}
!14 = !{!12, !7, i64 4}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass