; LLVM IR from chrxh/alien :: source/Base/Math.ll (ZN4Math9normalizeER12RealVector2D)

; 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.RealVector2D = type { float, float }
%"class.std::initializer_list" = type { ptr, i64 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZN4Math6lengthERK12RealVector2D(ptr noundef nonnull align 4 dereferenceable(8)) #0 align 2

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

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

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

declare void @_ZN12RealVector2DC1ESt16initializer_listIfE(ptr noundef nonnull align 4 dereferenceable(8), ptr, i64) unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Math9normalizeER12RealVector2D(ptr noundef nonnull align 4 dereferenceable(8) %0) #4 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = alloca %struct.RealVector2D, align 4
  %5 = alloca %"class.std::initializer_list", align 8
  %6 = alloca [2 x float], align 4
  %7 = alloca %struct.RealVector2D, align 4
  %8 = alloca %"class.std::initializer_list", align 8
  %9 = alloca [2 x float], align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call noundef float @_ZN4Math6lengthERK12RealVector2D(ptr noundef nonnull align 4 dereferenceable(8) %10)
  store float %11, ptr %3, align 4, !tbaa !9
  %12 = load float, ptr %3, align 4, !tbaa !9
  %13 = fcmp ogt float %12, 0x3F1A36E2E0000000
  br i1 %13, label %14, label %33

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.RealVector2D, ptr %15, i32 0, i32 0
  %17 = load float, ptr %16, align 4, !tbaa !11
  %18 = load float, ptr %3, align 4, !tbaa !9
  %19 = fdiv float %17, %18
  store float %19, ptr %6, align 4, !tbaa !9
  %20 = getelementptr inbounds float, ptr %6, i64 1
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.RealVector2D, ptr %21, i32 0, i32 1
  %23 = load float, ptr %22, align 4, !tbaa !13
  %24 = load float, ptr %3, align 4, !tbaa !9
  %25 = fdiv float %23, %24
  store float %25, ptr %20, align 4, !tbaa !9
  %26 = getelementptr inbounds %"class.std::initializer_list", ptr %5, i32 0, i32 0
  store ptr %6, ptr %26, align 8, !tbaa !14
  %27 = getelementptr inbounds %"class.std::initializer_list", ptr %5, i32 0, i32 1
  store i64 2, ptr %27, align 8, !tbaa !17
  %28 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8
  %30 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 1
  %31 = load i64, ptr %30, align 8
  call void @_ZN12RealVector2DC1ESt16initializer_listIfE(ptr noundef nonnull align 4 dereferenceable(8) %4, ptr %29, i64 %31)
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %32, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %42

33:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store float 1.000000e+00, ptr %9, align 4, !tbaa !9
  %34 = getelementptr inbounds float, ptr %9, i64 1
  store float 0.000000e+00, ptr %34, align 4, !tbaa !9
  %35 = getelementptr inbounds %"class.std::initializer_list", ptr %8, i32 0, i32 0
  store ptr %9, ptr %35, align 8, !tbaa !14
  %36 = getelementptr inbounds %"class.std::initializer_list", ptr %8, i32 0, i32 1
  store i64 2, ptr %36, align 8, !tbaa !17
  %37 = getelementptr inbounds { ptr, i64 }, ptr %8, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8
  %39 = getelementptr inbounds { ptr, i64 }, ptr %8, i32 0, i32 1
  %40 = load i64, ptr %39, align 8
  call void @_ZN12RealVector2DC1ESt16initializer_listIfE(ptr noundef nonnull align 4 dereferenceable(8) %7, ptr %38, i64 %40)
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %41, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %42

42:                                               ; preds = %33, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 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 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS12RealVector2D", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 4}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTSSt16initializer_listIfE", !6, i64 0, !16, i64 8}
!16 = !{!"long", !7, i64 0}
!17 = !{!15, !16, i64 8}
!18 = !{i64 0, i64 4, !9, i64 4, i64 4, !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"

%struct.RealVector2D = type { float, float }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZN4Math6lengthERK12RealVector2D(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #0 align 2

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

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

declare void @_ZN12RealVector2DC1ESt16initializer_listIfE(ptr noundef nonnull align 4 dereferenceable(8), ptr, i64) unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Math9normalizeER12RealVector2D(ptr noundef nonnull align 4 dereferenceable(8) %0) local_unnamed_addr #3 align 2 {
  %2 = alloca %struct.RealVector2D, align 8
  %3 = alloca [2 x float], align 8
  %4 = alloca %struct.RealVector2D, align 8
  %5 = alloca [2 x float], align 8
  %6 = tail call noundef float @_ZN4Math6lengthERK12RealVector2D(ptr noundef nonnull align 4 dereferenceable(8) %0)
  %7 = fcmp ogt float %6, 0x3F1A36E2E0000000
  br i1 %7, label %8, label %14

8:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %9 = load <2 x float>, ptr %0, align 4, !tbaa !5
  %10 = insertelement <2 x float> poison, float %6, i64 0
  %11 = shufflevector <2 x float> %10, <2 x float> poison, <2 x i32> zeroinitializer
  %12 = fdiv <2 x float> %9, %11
  store <2 x float> %12, ptr %3, align 8, !tbaa !5
  call void @_ZN12RealVector2DC1ESt16initializer_listIfE(ptr noundef nonnull align 4 dereferenceable(8) %2, ptr nonnull %3, i64 2)
  %13 = load i64, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  br label %16

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store <2 x float> <float 1.000000e+00, float 0.000000e+00>, ptr %5, align 8, !tbaa !5
  call void @_ZN12RealVector2DC1ESt16initializer_listIfE(ptr noundef nonnull align 4 dereferenceable(8) %4, ptr nonnull %5, i64 2)
  %15 = load i64, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  br label %16

16:                                               ; preds = %14, %8
  %.sink = phi i64 [ %13, %8 ], [ %15, %14 ]
  store i64 %.sink, ptr %0, align 4
  ret void
}

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 willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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