; LLVM IR from achilles288/robot-monitor-graphics :: src/base/math/vec4.ll (ZNK3rmg4Vec49normalizeEv)

; 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.rmg::Vec4" = type { %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { float, float, float, float }

; Function Attrs: mustprogress uwtable
define dso_local { <2 x float>, <2 x float> } @_ZNK3rmg4Vec49normalizeEv(ptr noundef nonnull align 4 dereferenceable(16) %0) #0 align 2 {
  %2 = alloca %"struct.rmg::Vec4", align 4
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %6 = getelementptr inbounds %"struct.rmg::Vec4", ptr %5, i32 0, i32 0
  %7 = getelementptr inbounds %struct.anon, ptr %6, i32 0, i32 0
  %8 = load float, ptr %7, align 4, !tbaa !9
  %9 = getelementptr inbounds %"struct.rmg::Vec4", ptr %5, i32 0, i32 0
  %10 = getelementptr inbounds %struct.anon, ptr %9, i32 0, i32 0
  %11 = load float, ptr %10, align 4, !tbaa !9
  %12 = getelementptr inbounds %"struct.rmg::Vec4", ptr %5, i32 0, i32 0
  %13 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 1
  %14 = load float, ptr %13, align 4, !tbaa !9
  %15 = getelementptr inbounds %"struct.rmg::Vec4", ptr %5, i32 0, i32 0
  %16 = getelementptr inbounds %struct.anon, ptr %15, i32 0, i32 1
  %17 = load float, ptr %16, align 4, !tbaa !9
  %18 = fmul float %14, %17
  %19 = call float @llvm.fmuladd.f32(float %8, float %11, float %18)
  %20 = getelementptr inbounds %"struct.rmg::Vec4", ptr %5, i32 0, i32 0
  %21 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 2
  %22 = load float, ptr %21, align 4, !tbaa !9
  %23 = getelementptr inbounds %"struct.rmg::Vec4", ptr %5, i32 0, i32 0
  %24 = getelementptr inbounds %struct.anon, ptr %23, i32 0, i32 2
  %25 = load float, ptr %24, align 4, !tbaa !9
  %26 = call float @llvm.fmuladd.f32(float %22, float %25, float %19)
  %27 = getelementptr inbounds %"struct.rmg::Vec4", ptr %5, i32 0, i32 0
  %28 = getelementptr inbounds %struct.anon, ptr %27, i32 0, i32 3
  %29 = load float, ptr %28, align 4, !tbaa !9
  %30 = getelementptr inbounds %"struct.rmg::Vec4", ptr %5, i32 0, i32 0
  %31 = getelementptr inbounds %struct.anon, ptr %30, i32 0, i32 3
  %32 = load float, ptr %31, align 4, !tbaa !9
  %33 = call float @llvm.fmuladd.f32(float %29, float %32, float %26)
  %34 = fpext float %33 to double
  %35 = call double @sqrt(double noundef %34) #5
  %36 = fptrunc double %35 to float
  store float %36, ptr %4, align 4, !tbaa !10
  call void @_ZN3rmg4Vec4C2Ev(ptr noundef nonnull align 4 dereferenceable(16) %2)
  %37 = getelementptr inbounds %"struct.rmg::Vec4", ptr %5, i32 0, i32 0
  %38 = getelementptr inbounds %struct.anon, ptr %37, i32 0, i32 0
  %39 = load float, ptr %38, align 4, !tbaa !9
  %40 = load float, ptr %4, align 4, !tbaa !10
  %41 = fdiv float %39, %40
  %42 = getelementptr inbounds %"struct.rmg::Vec4", ptr %2, i32 0, i32 0
  %43 = getelementptr inbounds %struct.anon, ptr %42, i32 0, i32 0
  store float %41, ptr %43, align 4, !tbaa !9
  %44 = getelementptr inbounds %"struct.rmg::Vec4", ptr %5, i32 0, i32 0
  %45 = getelementptr inbounds %struct.anon, ptr %44, i32 0, i32 1
  %46 = load float, ptr %45, align 4, !tbaa !9
  %47 = load float, ptr %4, align 4, !tbaa !10
  %48 = fdiv float %46, %47
  %49 = getelementptr inbounds %"struct.rmg::Vec4", ptr %2, i32 0, i32 0
  %50 = getelementptr inbounds %struct.anon, ptr %49, i32 0, i32 1
  store float %48, ptr %50, align 4, !tbaa !9
  %51 = getelementptr inbounds %"struct.rmg::Vec4", ptr %5, i32 0, i32 0
  %52 = getelementptr inbounds %struct.anon, ptr %51, i32 0, i32 2
  %53 = load float, ptr %52, align 4, !tbaa !9
  %54 = load float, ptr %4, align 4, !tbaa !10
  %55 = fdiv float %53, %54
  %56 = getelementptr inbounds %"struct.rmg::Vec4", ptr %2, i32 0, i32 0
  %57 = getelementptr inbounds %struct.anon, ptr %56, i32 0, i32 2
  store float %55, ptr %57, align 4, !tbaa !9
  %58 = getelementptr inbounds %"struct.rmg::Vec4", ptr %5, i32 0, i32 0
  %59 = getelementptr inbounds %struct.anon, ptr %58, i32 0, i32 3
  %60 = load float, ptr %59, align 4, !tbaa !9
  %61 = load float, ptr %4, align 4, !tbaa !10
  %62 = fdiv float %60, %61
  %63 = getelementptr inbounds %"struct.rmg::Vec4", ptr %2, i32 0, i32 0
  %64 = getelementptr inbounds %struct.anon, ptr %63, i32 0, i32 3
  store float %62, ptr %64, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %65 = getelementptr inbounds %"struct.rmg::Vec4", ptr %2, i32 0, i32 0
  %66 = getelementptr inbounds %union.anon, ptr %65, i32 0, i32 0
  %67 = load { <2 x float>, <2 x float> }, ptr %66, align 4
  ret { <2 x float>, <2 x float> } %67
}

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #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}


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

%"struct.rmg::Vec4" = type { %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { float, float, float, float }

; Function Attrs: mustprogress nounwind uwtable
define dso_local { <2 x float>, <2 x float> } @_ZNK3rmg4Vec49normalizeEv(ptr nocapture noundef nonnull readonly align 4 dereferenceable(16) %0) local_unnamed_addr #0 align 2 {
  %2 = alloca %"struct.rmg::Vec4", align 16
  %3 = load float, ptr %0, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load float, ptr %4, align 4, !tbaa !5
  %6 = fmul float %5, %5
  %7 = tail call float @llvm.fmuladd.f32(float %3, float %3, float %6)
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load float, ptr %8, align 4, !tbaa !5
  %10 = tail call float @llvm.fmuladd.f32(float %9, float %9, float %7)
  %11 = getelementptr inbounds i8, ptr %0, i64 12
  %12 = load float, ptr %11, align 4, !tbaa !5
  %13 = tail call float @llvm.fmuladd.f32(float %12, float %12, float %10)
  %sqrt = tail call float @llvm.sqrt.f32(float %13)
  call void @_ZN3rmg4Vec4C2Ev(ptr noundef nonnull align 4 dereferenceable(16) %2)
  %14 = getelementptr inbounds i8, ptr %2, i64 8
  %15 = load <4 x float>, ptr %0, align 4, !tbaa !5
  %16 = insertelement <4 x float> poison, float %sqrt, i64 0
  %17 = shufflevector <4 x float> %16, <4 x float> poison, <4 x i32> zeroinitializer
  %18 = fdiv <4 x float> %15, %17
  store <4 x float> %18, ptr %2, align 16, !tbaa !5
  %.fca.0.load = load <2 x float>, ptr %2, align 16
  %.fca.0.insert = insertvalue { <2 x float>, <2 x float> } poison, <2 x float> %.fca.0.load, 0
  %.fca.1.load = load <2 x float>, ptr %14, align 8
  %.fca.1.insert = insertvalue { <2 x float>, <2 x float> } %.fca.0.insert, <2 x float> %.fca.1.load, 1
  ret { <2 x float>, <2 x float> } %.fca.1.insert
}

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

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

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

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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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"}


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