; 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.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 }
%struct.b2Vec2 = 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 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

declare ptr @b2GetWorld(i32 noundef) #2

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

20:                                               ; preds = %3
  %21 = load ptr, ptr %8, align 8, !tbaa !15
  %22 = getelementptr inbounds %struct.b2Body, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !19
  %24 = icmp sge i32 %23, 3
  br i1 %24, label %25, label %29

25:                                               ; preds = %20
  %26 = load ptr, ptr %7, align 8, !tbaa !15
  %27 = load ptr, ptr %8, align 8, !tbaa !15
  %28 = call zeroext i1 @b2WakeBody(ptr noundef %26, ptr noundef %27)
  br label %29

29:                                               ; preds = %25, %20, %3
  %30 = load ptr, ptr %8, align 8, !tbaa !15
  %31 = getelementptr inbounds %struct.b2Body, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !19
  %33 = icmp eq i32 %32, 2
  br i1 %33, label %34, label %43

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %35 = load ptr, ptr %7, align 8, !tbaa !15
  %36 = load ptr, ptr %8, align 8, !tbaa !15
  %37 = call ptr @b2GetBodySim(ptr noundef %35, ptr noundef %36)
  store ptr %37, ptr %9, align 8, !tbaa !15
  %38 = load float, ptr %5, align 4, !tbaa !5
  %39 = load ptr, ptr %9, align 8, !tbaa !15
  %40 = getelementptr inbounds %struct.b2BodySim, ptr %39, i32 0, i32 6
  %41 = load float, ptr %40, align 4, !tbaa !21
  %42 = fadd float %41, %38
  store float %42, ptr %40, align 4, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %43

43:                                               ; preds = %34, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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

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

declare ptr @b2GetWorld(i32 noundef) local_unnamed_addr #1

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

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

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

14:                                               ; preds = %12, %8, %3
  %15 = getelementptr inbounds i8, ptr %7, i64 40
  %16 = load i32, ptr %15, align 8, !tbaa !5
  %17 = icmp eq i32 %16, 2
  br i1 %17, label %18, label %23

18:                                               ; preds = %14
  %19 = tail call ptr @b2GetBodySim(ptr noundef %6, ptr noundef nonnull %7)
  %20 = getelementptr inbounds i8, ptr %19, i64 56
  %21 = load float, ptr %20, align 4, !tbaa !14
  %22 = fadd float %21, %1
  store float %22, ptr %20, align 4, !tbaa !14
  br label %23

23:                                               ; preds = %18, %14
  ret void
}

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 = { "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, !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