; LLVM IR from SOHNE/Dura2D :: src/kinetics/d2Body.ll (ZN6d2Body19ApplyImpulseAtPointERK6d2Vec2S2_)

; 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.d2Vec2 = type { float, float }
%class.d2Body = type <{ i16, [2 x i8], i32, %struct.d2Transform, %struct.d2Vec2, %struct.d2Vec2, float, float, float, %struct.d2Vec2, float, float, float, float, float, float, float, ptr, ptr, ptr, ptr, ptr, float, [4 x i8] }>
%struct.d2Transform = type { %struct.d2Vec2, %struct.d2Rot }
%struct.d2Rot = type { 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare noundef nonnull align 4 dereferenceable(8) ptr @_ZN6d2Vec2pLERKS_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #1

declare <2 x float> @_ZNK6d2Vec2mlEf(ptr noundef nonnull align 4 dereferenceable(8), float noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6d2Body19ApplyImpulseAtPointERK6d2Vec2S2_(ptr noundef nonnull align 8 dereferenceable(132) %0, ptr noundef nonnull align 4 dereferenceable(8) %1, ptr noundef nonnull align 4 dereferenceable(8) %2) #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.d2Vec2, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds %class.d2Body, ptr %8, i32 0, i32 2
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  br label %28

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %class.d2Body, ptr %8, i32 0, i32 12
  %16 = load float, ptr %15, align 4, !tbaa !17
  %17 = call <2 x float> @_ZNK6d2Vec2mlEf(ptr noundef nonnull align 4 dereferenceable(8) %14, float noundef %16)
  store <2 x float> %17, ptr %7, align 4
  %18 = getelementptr inbounds %class.d2Body, ptr %8, i32 0, i32 4
  %19 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZN6d2Vec2pLERKS_(ptr noundef nonnull align 4 dereferenceable(8) %18, ptr noundef nonnull align 4 dereferenceable(8) %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call noundef float @_ZNK6d2Vec25CrossERKS_(ptr noundef nonnull align 4 dereferenceable(8) %20, ptr noundef nonnull align 4 dereferenceable(8) %21)
  %23 = getelementptr inbounds %class.d2Body, ptr %8, i32 0, i32 14
  %24 = load float, ptr %23, align 4, !tbaa !18
  %25 = getelementptr inbounds %class.d2Body, ptr %8, i32 0, i32 7
  %26 = load float, ptr %25, align 4, !tbaa !19
  %27 = call float @llvm.fmuladd.f32(float %22, float %24, float %26)
  store float %27, ptr %25, align 4, !tbaa !19
  br label %28

28:                                               ; preds = %13, %12
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { mustprogress 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 = { 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 = !{!10, !12, i64 4}
!10 = !{!"_ZTS6d2Body", !11, i64 0, !12, i64 4, !13, i64 8, !14, i64 24, !14, i64 32, !15, i64 40, !15, i64 44, !15, i64 48, !14, i64 52, !15, i64 60, !15, i64 64, !15, i64 68, !15, i64 72, !15, i64 76, !15, i64 80, !15, i64 84, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !15, i64 128}
!11 = !{!"short", !7, i64 0}
!12 = !{!"_ZTS10d2BodyType", !7, i64 0}
!13 = !{!"_ZTS11d2Transform", !14, i64 0, !16, i64 8}
!14 = !{!"_ZTS6d2Vec2", !15, i64 0, !15, i64 4}
!15 = !{!"float", !7, i64 0}
!16 = !{!"_ZTS5d2Rot", !15, i64 0, !15, i64 4}
!17 = !{!10, !15, i64 68}
!18 = !{!10, !15, i64 76}
!19 = !{!10, !15, i64 44}


; 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.d2Vec2 = type { float, 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

declare noundef nonnull align 4 dereferenceable(8) ptr @_ZN6d2Vec2pLERKS_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1

declare <2 x float> @_ZNK6d2Vec2mlEf(ptr noundef nonnull align 4 dereferenceable(8), float noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6d2Body19ApplyImpulseAtPointERK6d2Vec2S2_(ptr noundef nonnull align 8 dereferenceable(132) %0, ptr noundef nonnull align 4 dereferenceable(8) %1, ptr noundef nonnull align 4 dereferenceable(8) %2) local_unnamed_addr #3 align 2 {
  %4 = alloca %struct.d2Vec2, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %20, label %8

8:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  %9 = getelementptr inbounds i8, ptr %0, i64 68
  %10 = load float, ptr %9, align 4, !tbaa !16
  %11 = tail call <2 x float> @_ZNK6d2Vec2mlEf(ptr noundef nonnull align 4 dereferenceable(8) %1, float noundef %10)
  store <2 x float> %11, ptr %4, align 8
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZN6d2Vec2pLERKS_(ptr noundef nonnull align 4 dereferenceable(8) %12, ptr noundef nonnull align 4 dereferenceable(8) %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  %14 = call noundef float @_ZNK6d2Vec25CrossERKS_(ptr noundef nonnull align 4 dereferenceable(8) %2, ptr noundef nonnull align 4 dereferenceable(8) %1)
  %15 = getelementptr inbounds i8, ptr %0, i64 76
  %16 = load float, ptr %15, align 4, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %0, i64 44
  %18 = load float, ptr %17, align 4, !tbaa !18
  %19 = call float @llvm.fmuladd.f32(float %14, float %16, float %18)
  store float %19, ptr %17, align 4, !tbaa !18
  br label %20

20:                                               ; preds = %3, %8
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { mustprogress 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 = { 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, !10, i64 4}
!6 = !{!"_ZTS6d2Body", !7, i64 0, !10, i64 4, !11, i64 8, !12, i64 24, !12, i64 32, !13, i64 40, !13, i64 44, !13, i64 48, !12, i64 52, !13, i64 60, !13, i64 64, !13, i64 68, !13, i64 72, !13, i64 76, !13, i64 80, !13, i64 84, !15, i64 88, !15, i64 96, !15, i64 104, !15, i64 112, !15, i64 120, !13, i64 128}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS10d2BodyType", !8, i64 0}
!11 = !{!"_ZTS11d2Transform", !12, i64 0, !14, i64 8}
!12 = !{!"_ZTS6d2Vec2", !13, i64 0, !13, i64 4}
!13 = !{!"float", !8, i64 0}
!14 = !{!"_ZTS5d2Rot", !13, i64 0, !13, i64 4}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!6, !13, i64 68}
!17 = !{!6, !13, i64 76}
!18 = !{!6, !13, i64 44}


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