; LLVM IR from erincatto/box2d :: src (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.b2BodyId = type { i32, i16, i16 }
%struct.b2Vec2 = type { float, float }
%struct.b2Body = type { [32 x i8], ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, float, float, float, float, i32, i32, i32, i16, i8, i8, i8, i8 }
%struct.b2BodySim = type { %struct.b2Transform, %struct.b2Vec2, %struct.b2Rot, %struct.b2Vec2, %struct.b2Vec2, %struct.b2Vec2, float, float, float, float, float, float, float, float, i32, i8, i8, i8, i8, i8 }
%struct.b2Transform = type { %struct.b2Vec2, %struct.b2Rot }
%struct.b2Rot = type { float, float }

; Function Attrs: nounwind uwtable
declare dso_local ptr @b2GetBodyFullId(ptr noundef, i64) #0

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @b2GetBodySim(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @b2WakeBody(ptr noundef, ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @b2Sub(<2 x float>, <2 x float>) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @b2Add(<2 x float>, <2 x float>) #3

declare ptr @b2GetWorld(i32 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @b2Body_ApplyForce(i64 %0, <2 x float> %1, <2 x float> %2, i1 noundef zeroext %3) #5 {
  %5 = alloca %struct.b2BodyId, align 4
  %6 = alloca %struct.b2Vec2, align 4
  %7 = alloca %struct.b2Vec2, align 4
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %struct.b2Vec2, align 4
  %13 = alloca %struct.b2Vec2, align 4
  store i64 %0, ptr %5, align 4
  store <2 x float> %1, ptr %6, align 4
  store <2 x float> %2, ptr %7, align 4
  %14 = zext i1 %3 to i8
  store i8 %14, ptr %8, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %15 = getelementptr inbounds %struct.b2BodyId, ptr %5, i32 0, i32 1
  %16 = load i16, ptr %15, align 4, !tbaa !9
  %17 = zext i16 %16 to i32
  %18 = call ptr @b2GetWorld(i32 noundef %17)
  store ptr %18, ptr %9, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %19 = load ptr, ptr %9, align 8, !tbaa !13
  %20 = load i64, ptr %5, align 4
  %21 = call ptr @b2GetBodyFullId(ptr noundef %19, i64 %20)
  store ptr %21, ptr %10, align 8, !tbaa !13
  %22 = load i8, ptr %8, align 1, !tbaa !5, !range !15, !noundef !16
  %23 = trunc i8 %22 to i1
  br i1 %23, label %24, label %33

24:                                               ; preds = %4
  %25 = load ptr, ptr %10, align 8, !tbaa !13
  %26 = getelementptr inbounds %struct.b2Body, ptr %25, i32 0, i32 2
  %27 = load i32, ptr %26, align 8, !tbaa !17
  %28 = icmp sge i32 %27, 3
  br i1 %28, label %29, label %33

29:                                               ; preds = %24
  %30 = load ptr, ptr %9, align 8, !tbaa !13
  %31 = load ptr, ptr %10, align 8, !tbaa !13
  %32 = call zeroext i1 @b2WakeBody(ptr noundef %30, ptr noundef %31)
  br label %33

33:                                               ; preds = %29, %24, %4
  %34 = load ptr, ptr %10, align 8, !tbaa !13
  %35 = getelementptr inbounds %struct.b2Body, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 8, !tbaa !17
  %37 = icmp eq i32 %36, 2
  br i1 %37, label %38, label %61

38:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %39 = load ptr, ptr %9, align 8, !tbaa !13
  %40 = load ptr, ptr %10, align 8, !tbaa !13
  %41 = call ptr @b2GetBodySim(ptr noundef %39, ptr noundef %40)
  store ptr %41, ptr %11, align 8, !tbaa !13
  %42 = load ptr, ptr %11, align 8, !tbaa !13
  %43 = getelementptr inbounds %struct.b2BodySim, ptr %42, i32 0, i32 5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %44 = load ptr, ptr %11, align 8, !tbaa !13
  %45 = getelementptr inbounds %struct.b2BodySim, ptr %44, i32 0, i32 5
  %46 = load <2 x float>, ptr %45, align 4
  %47 = load <2 x float>, ptr %6, align 4
  %48 = call <2 x float> @b2Add(<2 x float> %46, <2 x float> %47)
  store <2 x float> %48, ptr %12, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %43, ptr align 4 %12, i64 8, i1 false), !tbaa.struct !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  %49 = load ptr, ptr %11, align 8, !tbaa !13
  %50 = getelementptr inbounds %struct.b2BodySim, ptr %49, i32 0, i32 1
  %51 = load <2 x float>, ptr %7, align 4
  %52 = load <2 x float>, ptr %50, align 4
  %53 = call <2 x float> @b2Sub(<2 x float> %51, <2 x float> %52)
  store <2 x float> %53, ptr %13, align 4
  %54 = load <2 x float>, ptr %13, align 4
  %55 = load <2 x float>, ptr %6, align 4
  %56 = call float @b2Cross(<2 x float> %54, <2 x float> %55)
  %57 = load ptr, ptr %11, align 8, !tbaa !13
  %58 = getelementptr inbounds %struct.b2BodySim, ptr %57, i32 0, i32 6
  %59 = load float, ptr %58, align 4, !tbaa !22
  %60 = fadd float %59, %56
  store float %60, ptr %58, align 4, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  br label %61

61:                                               ; preds = %38, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @b2Cross(<2 x float>, <2 x float>) #3

attributes #0 = { 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 = { inlinehint 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 = { "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 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 #6 = { 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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 4}
!10 = !{!"b2BodyId", !11, i64 0, !12, i64 4, !12, i64 6}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !11, i64 40}
!18 = !{!"b2Body", !7, i64 0, !14, i64 32, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !19, i64 88, !19, i64 92, !19, i64 96, !19, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !12, i64 116, !6, i64 118, !6, i64 119, !6, i64 120, !6, i64 121}
!19 = !{!"float", !7, i64 0}
!20 = !{i64 0, i64 4, !21, i64 4, i64 4, !21}
!21 = !{!19, !19, i64 0}
!22 = !{!23, !19, i64 56}
!23 = !{!"b2BodySim", !24, i64 0, !25, i64 16, !26, i64 24, !25, i64 32, !25, i64 40, !25, i64 48, !19, i64 56, !19, i64 60, !19, i64 64, !19, i64 68, !19, i64 72, !19, i64 76, !19, i64 80, !19, i64 84, !11, i64 88, !6, i64 92, !6, i64 93, !6, i64 94, !6, i64 95, !6, i64 96}
!24 = !{!"b2Transform", !25, i64 0, !26, i64 8}
!25 = !{!"b2Vec2", !19, i64 0, !19, i64 4}
!26 = !{!"b2Rot", !19, i64 0, !19, i64 4}


; 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: nounwind uwtable
declare dso_local ptr @b2GetBodyFullId(ptr noundef, i64) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @b2GetBodySim(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @b2WakeBody(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @b2Sub(<2 x float>, <2 x float>) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @b2Add(<2 x float>, <2 x float>) local_unnamed_addr #1

declare ptr @b2GetWorld(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @b2Body_ApplyForce(i64 %0, <2 x float> %1, <2 x float> %2, i1 noundef zeroext %3) local_unnamed_addr #3 {
  %.sroa.2.0.extract.shift = lshr i64 %0, 32
  %5 = trunc nuw i64 %.sroa.2.0.extract.shift to i32
  %6 = and i32 %5, 65535
  %7 = tail call ptr @b2GetWorld(i32 noundef %6) #4
  %8 = tail call ptr @b2GetBodyFullId(ptr noundef %7, i64 %0)
  br i1 %3, label %9, label %15

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %8, i64 40
  %11 = load i32, ptr %10, align 8, !tbaa !5
  %12 = icmp sgt i32 %11, 2
  br i1 %12, label %13, label %15

13:                                               ; preds = %9
  %14 = tail call zeroext i1 @b2WakeBody(ptr noundef %7, ptr noundef nonnull %8)
  br label %15

15:                                               ; preds = %13, %9, %4
  %16 = getelementptr inbounds i8, ptr %8, i64 40
  %17 = load i32, ptr %16, align 8, !tbaa !5
  %18 = icmp eq i32 %17, 2
  br i1 %18, label %19, label %31

19:                                               ; preds = %15
  %20 = tail call ptr @b2GetBodySim(ptr noundef %7, ptr noundef nonnull %8)
  %21 = getelementptr inbounds i8, ptr %20, i64 48
  %22 = load <2 x float>, ptr %21, align 4
  %23 = tail call <2 x float> @b2Add(<2 x float> %22, <2 x float> %1)
  store <2 x float> %23, ptr %21, align 4
  %24 = getelementptr inbounds i8, ptr %20, i64 16
  %25 = load <2 x float>, ptr %24, align 4
  %26 = tail call <2 x float> @b2Sub(<2 x float> %2, <2 x float> %25)
  %27 = tail call float @b2Cross(<2 x float> %26, <2 x float> %1)
  %28 = getelementptr inbounds i8, ptr %20, i64 56
  %29 = load float, ptr %28, align 4, !tbaa !14
  %30 = fadd float %27, %29
  store float %30, ptr %28, align 4, !tbaa !14
  br label %31

31:                                               ; preds = %19, %15
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @b2Cross(<2 x float>, <2 x float>) local_unnamed_addr #1

attributes #0 = { 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 = { inlinehint 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 = { "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 = { 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 }

!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 40}
!6 = !{!"b2Body", !7, i64 0, !9, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !10, i64 104, !10, i64 108, !10, i64 112, !12, i64 116, !13, i64 118, !13, i64 119, !13, i64 120, !13, i64 121}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"float", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!15, !11, i64 56}
!15 = !{!"b2BodySim", !16, i64 0, !17, i64 16, !18, i64 24, !17, i64 32, !17, i64 40, !17, i64 48, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !10, i64 88, !13, i64 92, !13, i64 93, !13, i64 94, !13, i64 95, !13, i64 96}
!16 = !{!"b2Transform", !17, i64 0, !18, i64 8}
!17 = !{!"b2Vec2", !11, i64 0, !11, i64 4}
!18 = !{!"b2Rot", !11, i64 0, !11, i64 4}


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