; 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.b2ShapeId = 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.b2World = type { %struct.b2ArenaAllocator, %struct.b2BroadPhase, %struct.b2ConstraintGraph, %struct.b2IdPool, %struct.b2BodyArray, %struct.b2IdPool, %struct.b2SolverSetArray, %struct.b2IdPool, %struct.b2JointArray, %struct.b2IdPool, %struct.b2ContactArray, %struct.b2IdPool, %struct.b2IslandArray, %struct.b2IdPool, %struct.b2IdPool, %struct.b2ShapeArray, %struct.b2ChainShapeArray, %struct.b2SensorArray, %struct.b2TaskContextArray, %struct.b2SensorTaskContextArray, %struct.b2BodyMoveEventArray, %struct.b2SensorBeginTouchEventArray, %struct.b2ContactBeginTouchEventArray, [2 x %struct.b2SensorEndTouchEventArray], [2 x %struct.b2ContactEndTouchEventArray], i32, %struct.b2ContactHitEventArray, %struct.b2BitSet, %struct.b2BitSet, %struct.b2BitSet, %struct.b2BitSet, i64, i32, %struct.b2Vec2, float, float, float, float, float, float, float, float, ptr, ptr, i16, %struct.b2Profile, ptr, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr, float, i32, i32, i16, i8, i8, i8, i8, i8, i8 }
%struct.b2ArenaAllocator = type { ptr, i32, i32, i32, i32, %struct.b2ArenaEntryArray }
%struct.b2ArenaEntryArray = type { ptr, i32, i32 }
%struct.b2BroadPhase = type { [3 x %struct.b2DynamicTree], i32, %struct.b2HashSet, %struct.b2IntArray, ptr, ptr, i32, %struct.b2AtomicInt, %struct.b2HashSet }
%struct.b2DynamicTree = type { ptr, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, i32 }
%struct.b2IntArray = type { ptr, i32, i32 }
%struct.b2AtomicInt = type { i32 }
%struct.b2HashSet = type { ptr, i32, i32 }
%struct.b2ConstraintGraph = type { [12 x %struct.b2GraphColor] }
%struct.b2GraphColor = type { %struct.b2BitSet, %struct.b2ContactSimArray, %struct.b2JointSimArray, %union.anon }
%struct.b2ContactSimArray = type { ptr, i32, i32 }
%struct.b2JointSimArray = type { ptr, i32, i32 }
%union.anon = type { ptr }
%struct.b2BodyArray = type { ptr, i32, i32 }
%struct.b2SolverSetArray = type { ptr, i32, i32 }
%struct.b2JointArray = type { ptr, i32, i32 }
%struct.b2ContactArray = type { ptr, i32, i32 }
%struct.b2IslandArray = type { ptr, i32, i32 }
%struct.b2IdPool = type { %struct.b2IntArray, i32 }
%struct.b2ShapeArray = type { ptr, i32, i32 }
%struct.b2ChainShapeArray = type { ptr, i32, i32 }
%struct.b2SensorArray = type { ptr, i32, i32 }
%struct.b2TaskContextArray = type { ptr, i32, i32 }
%struct.b2SensorTaskContextArray = type { ptr, i32, i32 }
%struct.b2BodyMoveEventArray = type { ptr, i32, i32 }
%struct.b2SensorBeginTouchEventArray = type { ptr, i32, i32 }
%struct.b2ContactBeginTouchEventArray = type { ptr, i32, i32 }
%struct.b2SensorEndTouchEventArray = type { ptr, i32, i32 }
%struct.b2ContactEndTouchEventArray = type { ptr, i32, i32 }
%struct.b2ContactHitEventArray = type { ptr, i32, i32 }
%struct.b2BitSet = type { ptr, i32, i32 }
%struct.b2Vec2 = type { float, float }
%struct.b2Profile = type { float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float }
%struct.b2Shape = type { i32, i32, i32, i32, i32, i32, float, float, float, float, float, i32, %struct.b2AABB, %struct.b2AABB, %struct.b2Vec2, i32, %struct.b2Filter, ptr, i32, %union.anon.0, i16, i8, i8, i8, i8, i8 }
%struct.b2AABB = type { %struct.b2Vec2, %struct.b2Vec2 }
%struct.b2Filter = type { i64, i64, i32 }
%union.anon.0 = type { %struct.b2Polygon }
%struct.b2Polygon = type { [8 x %struct.b2Vec2], [8 x %struct.b2Vec2], %struct.b2Vec2, float, i32 }

; 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: inlinehint nounwind uwtable
declare hidden ptr @b2ShapeArray_Get(ptr noundef, i32 noundef) #3

declare ptr @b2GetWorld(i32 noundef) #4

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

23:                                               ; preds = %32, %3
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = icmp ne i32 %24, -1
  br i1 %25, label %26, label %30

26:                                               ; preds = %23
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br label %30

30:                                               ; preds = %26, %23
  %31 = phi i1 [ false, %23 ], [ %29, %26 ]
  br i1 %31, label %32, label %58

32:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.b2World, ptr %33, i32 0, i32 15
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = call ptr @b2ShapeArray_Get(ptr noundef %34, i32 noundef %35)
  store ptr %36, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %37 = getelementptr inbounds %struct.b2ShapeId, ptr %12, i32 0, i32 0
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.b2Shape, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 8, !tbaa !18
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %37, align 4, !tbaa !24
  %42 = getelementptr inbounds %struct.b2ShapeId, ptr %12, i32 0, i32 1
  %43 = getelementptr inbounds %struct.b2BodyId, ptr %4, i32 0, i32 1
  %44 = load i16, ptr %43, align 4, !tbaa !11
  store i16 %44, ptr %42, align 4, !tbaa !26
  %45 = getelementptr inbounds %struct.b2ShapeId, ptr %12, i32 0, i32 2
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.b2Shape, ptr %46, i32 0, i32 20
  %48 = load i16, ptr %47, align 4, !tbaa !27
  store i16 %48, ptr %45, align 2, !tbaa !28
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds %struct.b2ShapeId, ptr %49, i64 %51
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %52, ptr align 4 %12, i64 8, i1 false), !tbaa.struct !29
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %10, align 4, !tbaa !9
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.b2Shape, ptr %55, i32 0, i32 3
  %57 = load i32, ptr %56, align 4, !tbaa !31
  store i32 %57, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %23, !llvm.loop !32

58:                                               ; preds = %30
  %59 = load i32, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret i32 %59
}

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

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 4}
!12 = !{!"b2BodyId", !10, i64 0, !13, i64 4, !13, i64 6}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !10, i64 56}
!15 = !{!"b2Body", !7, i64 0, !6, 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, !16, i64 88, !16, i64 92, !16, i64 96, !16, i64 100, !10, i64 104, !10, i64 108, !10, i64 112, !13, i64 116, !17, i64 118, !17, i64 119, !17, i64 120, !17, i64 121}
!16 = !{!"float", !7, i64 0}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{!19, !10, i64 0}
!19 = !{!"b2Shape", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !16, i64 24, !16, i64 28, !16, i64 32, !16, i64 36, !16, i64 40, !10, i64 44, !20, i64 48, !20, i64 64, !21, i64 80, !10, i64 88, !22, i64 96, !6, i64 120, !10, i64 128, !7, i64 132, !13, i64 276, !17, i64 278, !17, i64 279, !17, i64 280, !17, i64 281, !17, i64 282}
!20 = !{!"b2AABB", !21, i64 0, !21, i64 8}
!21 = !{!"b2Vec2", !16, i64 0, !16, i64 4}
!22 = !{!"b2Filter", !23, i64 0, !23, i64 8, !10, i64 16}
!23 = !{!"long", !7, i64 0}
!24 = !{!25, !10, i64 0}
!25 = !{!"b2ShapeId", !10, i64 0, !13, i64 4, !13, i64 6}
!26 = !{!25, !13, i64 4}
!27 = !{!19, !13, i64 276}
!28 = !{!25, !13, i64 6}
!29 = !{i64 0, i64 4, !9, i64 4, i64 2, !30, i64 6, i64 2, !30}
!30 = !{!13, !13, i64 0}
!31 = !{!19, !10, i64 12}
!32 = distinct !{!32, !33}
!33 = !{!"llvm.loop.mustprogress"}


; 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.b2ShapeId = type { i32, i16, i16 }

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @b2ShapeArray_Get(ptr noundef, i32 noundef) local_unnamed_addr #1

declare ptr @b2GetWorld(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @b2Body_GetShapes(i64 %0, ptr nocapture noundef writeonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %.sroa.2.0.extract.shift = lshr i64 %0, 32
  %.sroa.2.0.extract.trunc = trunc i64 %.sroa.2.0.extract.shift to i16
  %4 = trunc nuw i64 %.sroa.2.0.extract.shift to i32
  %5 = and i32 %4, 65535
  %6 = tail call ptr @b2GetWorld(i32 noundef %5) #3
  %7 = tail call ptr @b2GetBodyFullId(ptr noundef %6, i64 %0)
  %8 = getelementptr inbounds i8, ptr %7, i64 56
  %.017 = load i32, ptr %8, align 4, !tbaa !5
  %9 = icmp ne i32 %.017, -1
  %10 = icmp sgt i32 %2, 0
  %11 = and i1 %9, %10
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %12 = getelementptr inbounds i8, ptr %6, i64 1256
  %13 = zext nneg i32 %2 to i64
  br label %14

14:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %.019 = phi i32 [ %.017, %.lr.ph ], [ %.0, %14 ]
  %15 = tail call ptr @b2ShapeArray_Get(ptr noundef nonnull %12, i32 noundef %.019)
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = add nsw i32 %16, 1
  %18 = getelementptr inbounds i8, ptr %15, i64 276
  %19 = load i16, ptr %18, align 4, !tbaa !19
  %20 = getelementptr inbounds %struct.b2ShapeId, ptr %1, i64 %indvars.iv
  store i32 %17, ptr %20, align 4, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %20, i64 4
  store i16 %.sroa.2.0.extract.trunc, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !20
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %20, i64 6
  store i16 %19, ptr %.sroa.5.0..sroa_idx, align 2, !tbaa !20
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = getelementptr inbounds i8, ptr %15, i64 12
  %.0 = load i32, ptr %21, align 4, !tbaa !5
  %22 = icmp ne i32 %.0, -1
  %23 = icmp ult i64 %indvars.iv.next, %13
  %24 = select i1 %22, i1 %23, i1 false
  br i1 %24, label %14, label %._crit_edge.loopexit, !llvm.loop !21

._crit_edge.loopexit:                             ; preds = %14
  %25 = trunc nuw nsw i64 %indvars.iv.next to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %3
  %.016.lcssa = phi i32 [ 0, %3 ], [ %25, %._crit_edge.loopexit ]
  ret i32 %.016.lcssa
}

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"="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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"b2Shape", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !6, i64 44, !12, i64 48, !12, i64 64, !13, i64 80, !6, i64 88, !14, i64 96, !16, i64 120, !6, i64 128, !7, i64 132, !17, i64 276, !18, i64 278, !18, i64 279, !18, i64 280, !18, i64 281, !18, i64 282}
!11 = !{!"float", !7, i64 0}
!12 = !{!"b2AABB", !13, i64 0, !13, i64 8}
!13 = !{!"b2Vec2", !11, i64 0, !11, i64 4}
!14 = !{!"b2Filter", !15, i64 0, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!"any pointer", !7, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{!10, !17, i64 276}
!20 = !{!17, !17, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass