; LLVM IR from jdeokkim/ferox :: src (rigid_body)

; 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.frVector2_ = type { float, float }
%struct.frBody_ = type { %struct.frMotionData_, %struct.frTransform_, ptr, i32, i32, %struct.frAABB_, ptr }
%struct.frMotionData_ = type { float, float, float, float, %struct.frVector2_, float, float, %struct.frVector2_, float }
%struct.frTransform_ = type { %struct.frVector2_, %struct.anon, float }
%struct.anon = type { float, float }
%struct.frAABB_ = type { float, 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 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: alwaysinline nounwind uwtable
declare <2 x float> @frVector2Add(<2 x float>, <2 x float>) #3

; Function Attrs: alwaysinline nounwind uwtable
declare <2 x float> @frVector2ScalarMultiply(<2 x float>, float noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @frIntegrateForBodyVelocity(ptr noundef %0, float noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca %struct.frVector2_, align 4
  %6 = alloca %struct.frVector2_, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %18, label %9

9:                                                ; preds = %2
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.frBody_, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds %struct.frMotionData_, ptr %11, i32 0, i32 1
  %13 = load float, ptr %12, align 4, !tbaa !11
  %14 = fcmp ole float %13, 0.000000e+00
  br i1 %14, label %18, label %15

15:                                               ; preds = %9
  %16 = load float, ptr %4, align 4, !tbaa !9
  %17 = fcmp ole float %16, 0.000000e+00
  br i1 %17, label %18, label %19

18:                                               ; preds = %15, %9, %2
  br label %55

19:                                               ; preds = %15
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.frBody_, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %struct.frMotionData_, ptr %21, i32 0, i32 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.frBody_, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.frMotionData_, ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.frBody_, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.frMotionData_, ptr %27, i32 0, i32 7
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.frBody_, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds %struct.frMotionData_, ptr %30, i32 0, i32 1
  %32 = load float, ptr %31, align 4, !tbaa !11
  %33 = load float, ptr %4, align 4, !tbaa !9
  %34 = fmul float %32, %33
  %35 = load <2 x float>, ptr %28, align 8
  %36 = call <2 x float> @frVector2ScalarMultiply(<2 x float> %35, float noundef %34)
  store <2 x float> %36, ptr %6, align 4
  %37 = load <2 x float>, ptr %25, align 8
  %38 = load <2 x float>, ptr %6, align 4
  %39 = call <2 x float> @frVector2Add(<2 x float> %37, <2 x float> %38)
  store <2 x float> %39, ptr %5, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %22, ptr align 4 %5, i64 8, i1 false), !tbaa.struct !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.frBody_, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds %struct.frMotionData_, ptr %41, i32 0, i32 8
  %43 = load float, ptr %42, align 8, !tbaa !20
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.frBody_, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds %struct.frMotionData_, ptr %45, i32 0, i32 3
  %47 = load float, ptr %46, align 4, !tbaa !21
  %48 = fmul float %43, %47
  %49 = load float, ptr %4, align 4, !tbaa !9
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.frBody_, ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds %struct.frMotionData_, ptr %51, i32 0, i32 5
  %53 = load float, ptr %52, align 8, !tbaa !22
  %54 = call float @llvm.fmuladd.f32(float %48, float %49, float %53)
  store float %54, ptr %52, align 8, !tbaa !22
  br label %55

55:                                               ; preds = %19, %18
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { alwaysinline nounwind 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 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"frBody_", !13, i64 0, !15, i64 44, !6, i64 64, !17, i64 72, !17, i64 76, !18, i64 80, !6, i64 96}
!13 = !{!"frMotionData_", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !14, i64 16, !10, i64 24, !10, i64 28, !14, i64 32, !10, i64 40}
!14 = !{!"frVector2_", !10, i64 0, !10, i64 4}
!15 = !{!"frTransform_", !14, i64 0, !16, i64 8, !10, i64 16}
!16 = !{!"", !10, i64 0, !10, i64 4}
!17 = !{!"int", !7, i64 0}
!18 = !{!"frAABB_", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!19 = !{i64 0, i64 4, !9, i64 4, i64 4, !9}
!20 = !{!12, !10, i64 40}
!21 = !{!12, !10, i64 12}
!22 = !{!12, !10, i64 24}


; 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: alwaysinline nounwind uwtable
declare <2 x float> @frVector2Add(<2 x float>, <2 x float>) local_unnamed_addr #1

; Function Attrs: alwaysinline nounwind uwtable
declare <2 x float> @frVector2ScalarMultiply(<2 x float>, float noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @frIntegrateForBodyVelocity(ptr noundef %0, float noundef %1) local_unnamed_addr #2 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %25, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load float, ptr %5, align 4, !tbaa !5
  %7 = fcmp ole float %6, 0.000000e+00
  %8 = fcmp ole float %1, 0.000000e+00
  %or.cond = or i1 %8, %7
  br i1 %or.cond, label %25, label %9

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  %12 = fmul float %6, %1
  %13 = load <2 x float>, ptr %11, align 8
  %14 = tail call <2 x float> @frVector2ScalarMultiply(<2 x float> %13, float noundef %12)
  %15 = load <2 x float>, ptr %10, align 8
  %16 = tail call <2 x float> @frVector2Add(<2 x float> %15, <2 x float> %14)
  store <2 x float> %16, ptr %10, align 8
  %17 = getelementptr inbounds i8, ptr %0, i64 40
  %18 = load float, ptr %17, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %0, i64 12
  %20 = load float, ptr %19, align 4, !tbaa !18
  %21 = fmul float %18, %20
  %22 = getelementptr inbounds i8, ptr %0, i64 24
  %23 = load float, ptr %22, align 8, !tbaa !19
  %24 = tail call float @llvm.fmuladd.f32(float %21, float %1, float %23)
  store float %24, ptr %22, align 8, !tbaa !19
  br label %25

25:                                               ; preds = %2, %4, %9
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { alwaysinline nounwind 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 #2 = { nounwind 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)"}
!5 = !{!6, !8, i64 4}
!6 = !{!"frBody_", !7, i64 0, !12, i64 44, !14, i64 64, !15, i64 72, !15, i64 76, !16, i64 80, !14, i64 96}
!7 = !{!"frMotionData_", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !11, i64 16, !8, i64 24, !8, i64 28, !11, i64 32, !8, i64 40}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"frVector2_", !8, i64 0, !8, i64 4}
!12 = !{!"frTransform_", !11, i64 0, !13, i64 8, !8, i64 16}
!13 = !{!"", !8, i64 0, !8, i64 4}
!14 = !{!"any pointer", !9, i64 0}
!15 = !{!"int", !9, i64 0}
!16 = !{!"frAABB_", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12}
!17 = !{!6, !8, i64 40}
!18 = !{!6, !8, i64 12}
!19 = !{!6, !8, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass