; LLVM IR from SelfishOlex/MiniAudioO3DE :: MiniAudio/Code/Source/Clients/MiniAudioImplementation.ll (Z18ma_vec3f_normalize8ma_vec3f)

; 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.ma_vec3f = type { 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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { <2 x float>, float } @_Z16ma_vec3f_init_3ffff(float noundef, float noundef, float noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z12ma_vec3f_len8ma_vec3f(<2 x float>, float) #3

; Function Attrs: mustprogress uwtable
define dso_local { <2 x float>, float } @_Z18ma_vec3f_normalize8ma_vec3f(<2 x float> %0, float %1) #3 {
  %3 = alloca %struct.ma_vec3f, align 4
  %4 = alloca %struct.ma_vec3f, align 4
  %5 = alloca { <2 x float>, float }, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca %struct.ma_vec3f, align 4
  %9 = alloca { <2 x float>, float }, align 4
  %10 = alloca { <2 x float>, float }, align 8
  %11 = alloca i32, align 4
  %12 = alloca { <2 x float>, float }, align 8
  %13 = getelementptr inbounds { <2 x float>, float }, ptr %5, i32 0, i32 0
  store <2 x float> %0, ptr %13, align 4
  %14 = getelementptr inbounds { <2 x float>, float }, ptr %5, i32 0, i32 1
  store float %1, ptr %14, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 %5, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %4, i64 12, i1 false), !tbaa.struct !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %8, i64 12, i1 false)
  %15 = getelementptr inbounds { <2 x float>, float }, ptr %9, i32 0, i32 0
  %16 = load <2 x float>, ptr %15, align 4
  %17 = getelementptr inbounds { <2 x float>, float }, ptr %9, i32 0, i32 1
  %18 = load float, ptr %17, align 4
  %19 = call noundef float @_Z12ma_vec3f_len8ma_vec3f(<2 x float> %16, float %18)
  store float %19, ptr %7, align 4, !tbaa !6
  %20 = load float, ptr %7, align 4, !tbaa !6
  %21 = fcmp oeq float %20, 0.000000e+00
  br i1 %21, label %22, label %24

22:                                               ; preds = %2
  %23 = call { <2 x float>, float } @_Z16ma_vec3f_init_3ffff(float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00)
  store { <2 x float>, float } %23, ptr %10, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 8 %10, i64 12, i1 false)
  store i32 1, ptr %11, align 4
  br label %39

24:                                               ; preds = %2
  %25 = load float, ptr %7, align 4, !tbaa !6
  %26 = fdiv float 1.000000e+00, %25
  store float %26, ptr %6, align 4, !tbaa !6
  %27 = load float, ptr %6, align 4, !tbaa !6
  %28 = getelementptr inbounds %struct.ma_vec3f, ptr %4, i32 0, i32 0
  %29 = load float, ptr %28, align 4, !tbaa !10
  %30 = fmul float %29, %27
  store float %30, ptr %28, align 4, !tbaa !10
  %31 = load float, ptr %6, align 4, !tbaa !6
  %32 = getelementptr inbounds %struct.ma_vec3f, ptr %4, i32 0, i32 1
  %33 = load float, ptr %32, align 4, !tbaa !12
  %34 = fmul float %33, %31
  store float %34, ptr %32, align 4, !tbaa !12
  %35 = load float, ptr %6, align 4, !tbaa !6
  %36 = getelementptr inbounds %struct.ma_vec3f, ptr %4, i32 0, i32 2
  %37 = load float, ptr %36, align 4, !tbaa !13
  %38 = fmul float %37, %35
  store float %38, ptr %36, align 4, !tbaa !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %4, i64 12, i1 false), !tbaa.struct !5
  store i32 1, ptr %11, align 4
  br label %39

39:                                               ; preds = %24, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 4 %3, i64 12, i1 false)
  %40 = load { <2 x float>, float }, ptr %12, align 8
  ret { <2 x float>, float } %40
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { <2 x float>, float } @_Z16ma_vec3f_init_3ffff(float noundef, float noundef, float noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z12ma_vec3f_len8ma_vec3f(<2 x float>, float) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local { <2 x float>, float } @_Z18ma_vec3f_normalize8ma_vec3f(<2 x float> %0, float %1) local_unnamed_addr #1 {
  %3 = tail call noundef float @_Z12ma_vec3f_len8ma_vec3f(<2 x float> %0, float %1)
  %4 = fcmp oeq float %3, 0.000000e+00
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = tail call { <2 x float>, float } @_Z16ma_vec3f_init_3ffff(float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00)
  %.fca.0.extract = extractvalue { <2 x float>, float } %6, 0
  %.fca.1.extract = extractvalue { <2 x float>, float } %6, 1
  br label %13

7:                                                ; preds = %2
  %8 = fdiv float 1.000000e+00, %3
  %9 = insertelement <2 x float> poison, float %8, i64 0
  %10 = shufflevector <2 x float> %9, <2 x float> poison, <2 x i32> zeroinitializer
  %11 = fmul <2 x float> %10, %0
  %12 = fmul float %8, %1
  br label %13

13:                                               ; preds = %7, %5
  %.sroa.017.0 = phi <2 x float> [ %.fca.0.extract, %5 ], [ %11, %7 ]
  %.sroa.3.0 = phi float [ %.fca.1.extract, %5 ], [ %12, %7 ]
  %.fca.0.insert = insertvalue { <2 x float>, float } poison, <2 x float> %.sroa.017.0, 0
  %.fca.1.insert = insertvalue { <2 x float>, float } %.fca.0.insert, float %.sroa.3.0, 1
  ret { <2 x float>, float } %.fca.1.insert
}

attributes #0 = { 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"="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" }

!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: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,TailCallElimPass