; LLVM IR from jrouwe/JoltPhysics :: Jolt/Physics/Body/MassProperties.ll (ZN3JPH14MassProperties11ScaleToMassEf)

; 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.JPH::Vec4" = type { %union.anon }
%union.anon = type { <4 x float> }
%"class.JPH::MassProperties" = type { float, %"class.JPH::Mat44" }
%"class.JPH::Mat44" = type { [4 x %"class.JPH::Vec4"] }

; 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: mustprogress uwtable
define dso_local void @_ZN3JPH14MassProperties11ScaleToMassEf(ptr noundef nonnull align 16 dereferenceable(80) %0, float noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca i32, align 4
  %7 = alloca %"class.JPH::Vec4", align 16
  %8 = alloca %"class.JPH::Vec4", align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  %10 = getelementptr inbounds %"class.JPH::MassProperties", ptr %9, i32 0, i32 0
  %11 = load float, ptr %10, align 16, !tbaa !11
  %12 = fcmp ogt float %11, 0.000000e+00
  br i1 %12, label %13, label %52

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %14 = load float, ptr %4, align 4, !tbaa !9
  %15 = getelementptr inbounds %"class.JPH::MassProperties", ptr %9, i32 0, i32 0
  %16 = load float, ptr %15, align 16, !tbaa !11
  %17 = fdiv float %14, %16
  store float %17, ptr %5, align 4, !tbaa !9
  %18 = load float, ptr %4, align 4, !tbaa !9
  %19 = getelementptr inbounds %"class.JPH::MassProperties", ptr %9, i32 0, i32 0
  store float %18, ptr %19, align 16, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !14
  br label %20

20:                                               ; preds = %48, %13
  %21 = load i32, ptr %6, align 4, !tbaa !14
  %22 = icmp slt i32 %21, 3
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %51

24:                                               ; preds = %20
  %25 = getelementptr inbounds %"class.JPH::MassProperties", ptr %9, i32 0, i32 1
  %26 = load i32, ptr %6, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  %27 = getelementptr inbounds %"class.JPH::MassProperties", ptr %9, i32 0, i32 1
  %28 = load i32, ptr %6, align 4, !tbaa !14
  %29 = call { double, double } @_ZNK3JPH5Mat4410GetColumn4Ej(ptr noundef nonnull align 16 dereferenceable(64) %27, i32 noundef %28)
  %30 = getelementptr inbounds %"class.JPH::Vec4", ptr %8, i32 0, i32 0
  %31 = getelementptr inbounds %union.anon, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds { double, double }, ptr %31, i32 0, i32 0
  %33 = extractvalue { double, double } %29, 0
  store double %33, ptr %32, align 16
  %34 = getelementptr inbounds { double, double }, ptr %31, i32 0, i32 1
  %35 = extractvalue { double, double } %29, 1
  store double %35, ptr %34, align 8
  %36 = load float, ptr %5, align 4, !tbaa !9
  %37 = call { double, double } @_ZNK3JPH4Vec4mlEf(ptr noundef nonnull align 16 dereferenceable(16) %8, float noundef %36)
  %38 = getelementptr inbounds %"class.JPH::Vec4", ptr %7, i32 0, i32 0
  %39 = getelementptr inbounds %union.anon, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds { double, double }, ptr %39, i32 0, i32 0
  %41 = extractvalue { double, double } %37, 0
  store double %41, ptr %40, align 16
  %42 = getelementptr inbounds { double, double }, ptr %39, i32 0, i32 1
  %43 = extractvalue { double, double } %37, 1
  store double %43, ptr %42, align 8
  %44 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 0
  %45 = load double, ptr %44, align 16
  %46 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 1
  %47 = load double, ptr %46, align 8
  call void @_ZN3JPH5Mat4410SetColumn4EjNS_4Vec4E(ptr noundef nonnull align 16 dereferenceable(64) %25, i32 noundef %26, double %45, double %47)
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  br label %48

48:                                               ; preds = %24
  %49 = load i32, ptr %6, align 4, !tbaa !14
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %6, align 4, !tbaa !14
  br label %20, !llvm.loop !16

51:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %55

52:                                               ; preds = %2
  %53 = load float, ptr %4, align 4, !tbaa !9
  %54 = getelementptr inbounds %"class.JPH::MassProperties", ptr %9, i32 0, i32 0
  store float %53, ptr %54, align 16, !tbaa !11
  br label %55

55:                                               ; preds = %52, %51
  ret void
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN3JPH5Mat4410SetColumn4EjNS_4Vec4E(ptr noundef nonnull align 16 dereferenceable(64), i32 noundef, double, double) #2 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZNK3JPH5Mat4410GetColumn4Ej(ptr noundef nonnull align 16 dereferenceable(64), i32 noundef) #2 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZNK3JPH4Vec4mlEf(ptr noundef nonnull align 16 dereferenceable(16), float noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="128" "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, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN3JPH14MassPropertiesE", !10, i64 0, !13, i64 16}
!13 = !{!"_ZTSN3JPH5Mat44E", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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.JPH::Vec4" = type { %union.anon }
%union.anon = type { <4 x 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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH14MassProperties11ScaleToMassEf(ptr noundef nonnull align 16 dereferenceable(80) %0, float noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca %"class.JPH::Vec4", align 16
  %4 = load float, ptr %0, align 16, !tbaa !5
  %5 = fcmp ogt float %4, 0.000000e+00
  br i1 %5, label %.loopexit.loopexit, label %27

.loopexit.loopexit:                               ; preds = %2
  %6 = fdiv float %1, %4
  store float %1, ptr %0, align 16, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  %9 = tail call { double, double } @_ZNK3JPH5Mat4410GetColumn4Ej(ptr noundef nonnull align 16 dereferenceable(64) %7, i32 noundef 0)
  %10 = extractvalue { double, double } %9, 0
  store double %10, ptr %3, align 16
  %11 = extractvalue { double, double } %9, 1
  store double %11, ptr %8, align 8
  %12 = call { double, double } @_ZNK3JPH4Vec4mlEf(ptr noundef nonnull align 16 dereferenceable(16) %3, float noundef %6)
  %13 = extractvalue { double, double } %12, 0
  %14 = extractvalue { double, double } %12, 1
  call void @_ZN3JPH5Mat4410SetColumn4EjNS_4Vec4E(ptr noundef nonnull align 16 dereferenceable(64) %7, i32 noundef 0, double %13, double %14)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  %15 = call { double, double } @_ZNK3JPH5Mat4410GetColumn4Ej(ptr noundef nonnull align 16 dereferenceable(64) %7, i32 noundef 1)
  %16 = extractvalue { double, double } %15, 0
  store double %16, ptr %3, align 16
  %17 = extractvalue { double, double } %15, 1
  store double %17, ptr %8, align 8
  %18 = call { double, double } @_ZNK3JPH4Vec4mlEf(ptr noundef nonnull align 16 dereferenceable(16) %3, float noundef %6)
  %19 = extractvalue { double, double } %18, 0
  %20 = extractvalue { double, double } %18, 1
  call void @_ZN3JPH5Mat4410SetColumn4EjNS_4Vec4E(ptr noundef nonnull align 16 dereferenceable(64) %7, i32 noundef 1, double %19, double %20)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  %21 = call { double, double } @_ZNK3JPH5Mat4410GetColumn4Ej(ptr noundef nonnull align 16 dereferenceable(64) %7, i32 noundef 2)
  %22 = extractvalue { double, double } %21, 0
  store double %22, ptr %3, align 16
  %23 = extractvalue { double, double } %21, 1
  store double %23, ptr %8, align 8
  %24 = call { double, double } @_ZNK3JPH4Vec4mlEf(ptr noundef nonnull align 16 dereferenceable(16) %3, float noundef %6)
  %25 = extractvalue { double, double } %24, 0
  %26 = extractvalue { double, double } %24, 1
  call void @_ZN3JPH5Mat4410SetColumn4EjNS_4Vec4E(ptr noundef nonnull align 16 dereferenceable(64) %7, i32 noundef 2, double %25, double %26)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  br label %.loopexit

27:                                               ; preds = %2
  store float %1, ptr %0, align 16, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %27
  ret void
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN3JPH5Mat4410SetColumn4EjNS_4Vec4E(ptr noundef nonnull align 16 dereferenceable(64), i32 noundef, double, double) local_unnamed_addr #2 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZNK3JPH5Mat4410GetColumn4Ej(ptr noundef nonnull align 16 dereferenceable(64), i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZNK3JPH4Vec4mlEf(ptr noundef nonnull align 16 dereferenceable(16), float noundef) local_unnamed_addr #3 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="128" "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 0}
!6 = !{!"_ZTSN3JPH14MassPropertiesE", !7, i64 0, !10, i64 16}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN3JPH5Mat44E", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass