; LLVM IR from jrouwe/JoltPhysics :: Samples/Tests/General (ModifyMassTest)

; 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.ModifyMassTest = type <{ %class.Test, %"class.JPH::ContactListener", float, [2 x %"class.JPH::BodyID"], [4 x i8] }>
%class.Test = type { ptr, ptr, ptr, ptr, ptr, ptr, i8, %"class.std::unordered_map" }
%"class.std::unordered_map" = type { %"class.std::_Hashtable" }
%"class.std::_Hashtable" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"struct.std::__detail::_Hash_node_base" = type { ptr }
%"struct.std::__detail::_Prime_rehash_policy" = type { float, i64 }
%"class.JPH::ContactListener" = type { ptr }
%"class.JPH::BodyID" = type { i32 }
%"class.Test::PreUpdateParams" = type { float, [12 x i8], %struct.CameraState }
%struct.CameraState = type <{ %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", float, [12 x i8] }>
%"class.JPH::Vec3" = type { %union.anon }
%union.anon = type { <4 x 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: mustprogress uwtable
declare dso_local void @_ZN14ModifyMassTest11ResetBodiesEi(ptr noundef nonnull align 8 dereferenceable(132), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14ModifyMassTest12UpdateLabelsEv(ptr noundef nonnull align 8 dereferenceable(132)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14ModifyMassTest16PrePhysicsUpdateERKN4Test15PreUpdateParamsE(ptr noundef nonnull align 8 dereferenceable(132) %0, ptr noundef nonnull align 16 dereferenceable(80) %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store float 2.000000e+00, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %9 = getelementptr inbounds %class.ModifyMassTest, ptr %8, i32 0, i32 2
  %10 = load float, ptr %9, align 8, !tbaa !11
  %11 = fdiv float %10, 2.000000e+00
  %12 = fptosi float %11 to i32
  store i32 %12, ptr %6, align 4, !tbaa !21
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %"class.Test::PreUpdateParams", ptr %13, i32 0, i32 0
  %15 = load float, ptr %14, align 16, !tbaa !23
  %16 = getelementptr inbounds %class.ModifyMassTest, ptr %8, i32 0, i32 2
  %17 = load float, ptr %16, align 8, !tbaa !11
  %18 = fadd float %17, %15
  store float %18, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %19 = getelementptr inbounds %class.ModifyMassTest, ptr %8, i32 0, i32 2
  %20 = load float, ptr %19, align 8, !tbaa !11
  %21 = fdiv float %20, 2.000000e+00
  %22 = fptosi float %21 to i32
  store i32 %22, ptr %7, align 4, !tbaa !21
  %23 = load i32, ptr %6, align 4, !tbaa !21
  %24 = load i32, ptr %7, align 4, !tbaa !21
  %25 = icmp ne i32 %23, %24
  br i1 %25, label %26, label %28

26:                                               ; preds = %2
  %27 = load i32, ptr %7, align 4, !tbaa !21
  call void @_ZN14ModifyMassTest11ResetBodiesEi(ptr noundef nonnull align 8 dereferenceable(132) %8, i32 noundef %27)
  br label %28

28:                                               ; preds = %26, %2
  call void @_ZN14ModifyMassTest12UpdateLabelsEv(ptr noundef nonnull align 8 dereferenceable(132) %8)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

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 = { 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 120}
!12 = !{!"_ZTS14ModifyMassTest", !13, i64 0, !20, i64 112, !10, i64 120, !7, i64 124}
!13 = !{!"_ZTS4Test", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !14, i64 48, !15, i64 56}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"_ZTSSt13unordered_mapIN3JPH6BodyIDENSt7__cxx1112basic_stringIcSt11char_traitsIcENS0_12STLAllocatorIcEEEESt4hashIS1_ESt8equal_toIS1_ESaISt4pairIKS1_S8_EEE", !16, i64 0}
!16 = !{!"_ZTSSt10_HashtableIN3JPH6BodyIDESt4pairIKS1_NSt7__cxx1112basic_stringIcSt11char_traitsIcENS0_12STLAllocatorIcEEEEESaISB_ENSt8__detail10_Select1stESt8equal_toIS1_ESt4hashIS1_ENSD_18_Mod_range_hashingENSD_20_Default_ranged_hashENSD_20_Prime_rehash_policyENSD_17_Hashtable_traitsILb1ELb0ELb1EEEE", !6, i64 0, !17, i64 8, !18, i64 16, !17, i64 24, !19, i64 32, !6, i64 48}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSNSt8__detail15_Hash_node_baseE", !6, i64 0}
!19 = !{!"_ZTSNSt8__detail20_Prime_rehash_policyE", !10, i64 0, !17, i64 8}
!20 = !{!"_ZTSN3JPH15ContactListenerE"}
!21 = !{!22, !22, i64 0}
!22 = !{!"int", !7, i64 0}
!23 = !{!24, !10, i64 0}
!24 = !{!"_ZTSN4Test15PreUpdateParamsE", !10, i64 0, !25, i64 16}
!25 = !{!"_ZTS11CameraState", !26, i64 0, !26, i64 16, !26, i64 32, !10, i64 48}
!26 = !{!"_ZTSN3JPH4Vec3E", !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"

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14ModifyMassTest11ResetBodiesEi(ptr noundef nonnull align 8 dereferenceable(132), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN14ModifyMassTest12UpdateLabelsEv(ptr noundef nonnull align 8 dereferenceable(132)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14ModifyMassTest16PrePhysicsUpdateERKN4Test15PreUpdateParamsE(ptr noundef nonnull align 8 dereferenceable(132) %0, ptr nocapture noundef nonnull readonly align 16 dereferenceable(80) %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 120
  %4 = load float, ptr %3, align 8, !tbaa !5
  %5 = load float, ptr %1, align 16, !tbaa !19
  %6 = fadd float %4, %5
  store float %6, ptr %3, align 8, !tbaa !5
  %7 = insertelement <2 x float> poison, float %4, i64 0
  %8 = insertelement <2 x float> %7, float %6, i64 1
  %9 = fmul <2 x float> %8, <float 5.000000e-01, float 5.000000e-01>
  %10 = fptosi <2 x float> %9 to <2 x i32>
  %11 = extractelement <2 x i32> %10, i64 0
  %12 = extractelement <2 x i32> %10, i64 1
  %.not = icmp eq i32 %11, %12
  br i1 %.not, label %14, label %13

13:                                               ; preds = %2
  tail call void @_ZN14ModifyMassTest11ResetBodiesEi(ptr noundef nonnull align 8 dereferenceable(132) %0, i32 noundef %12)
  br label %14

14:                                               ; preds = %13, %2
  tail call void @_ZN14ModifyMassTest12UpdateLabelsEv(ptr noundef nonnull align 8 dereferenceable(132) %0)
  ret void
}

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

!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, !17, i64 120}
!6 = !{!"_ZTS14ModifyMassTest", !7, i64 0, !18, i64 112, !17, i64 120, !9, i64 124}
!7 = !{!"_ZTS4Test", !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !11, i64 48, !12, i64 56}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"bool", !9, i64 0}
!12 = !{!"_ZTSSt13unordered_mapIN3JPH6BodyIDENSt7__cxx1112basic_stringIcSt11char_traitsIcENS0_12STLAllocatorIcEEEESt4hashIS1_ESt8equal_toIS1_ESaISt4pairIKS1_S8_EEE", !13, i64 0}
!13 = !{!"_ZTSSt10_HashtableIN3JPH6BodyIDESt4pairIKS1_NSt7__cxx1112basic_stringIcSt11char_traitsIcENS0_12STLAllocatorIcEEEEESaISB_ENSt8__detail10_Select1stESt8equal_toIS1_ESt4hashIS1_ENSD_18_Mod_range_hashingENSD_20_Default_ranged_hashENSD_20_Prime_rehash_policyENSD_17_Hashtable_traitsILb1ELb0ELb1EEEE", !8, i64 0, !14, i64 8, !15, i64 16, !14, i64 24, !16, i64 32, !8, i64 48}
!14 = !{!"long", !9, i64 0}
!15 = !{!"_ZTSNSt8__detail15_Hash_node_baseE", !8, i64 0}
!16 = !{!"_ZTSNSt8__detail20_Prime_rehash_policyE", !17, i64 0, !14, i64 8}
!17 = !{!"float", !9, i64 0}
!18 = !{!"_ZTSN3JPH15ContactListenerE"}
!19 = !{!20, !17, i64 0}
!20 = !{!"_ZTSN4Test15PreUpdateParamsE", !17, i64 0, !21, i64 16}
!21 = !{!"_ZTS11CameraState", !22, i64 0, !22, i64 16, !22, i64 32, !17, i64 48}
!22 = !{!"_ZTSN3JPH4Vec3E", !9, i64 0}


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