; 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.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.b2Joint = type { ptr, i32, i32, i32, [2 x %struct.b2JointEdge], i32, i32, i32, i32, float, i32, i16, i8, i8 }
%struct.b2JointEdge = type { i32, i32, i32 }

; 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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @b2ShouldBodiesCollide(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.b2Body, ptr %15, i32 0, i32 20
  %17 = load i32, ptr %16, align 8, !tbaa !9
  %18 = icmp ne i32 %17, 2
  br i1 %18, label %19, label %25

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

24:                                               ; preds = %19
  store i1 false, ptr %4, align 1
  br label %92

25:                                               ; preds = %19, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.b2Body, ptr %26, i32 0, i32 10
  %28 = load i32, ptr %27, align 8, !tbaa !15
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.b2Body, ptr %29, i32 0, i32 10
  %31 = load i32, ptr %30, align 8, !tbaa !15
  %32 = icmp slt i32 %28, %31
  br i1 %32, label %33, label %40

33:                                               ; preds = %25
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.b2Body, ptr %34, i32 0, i32 9
  %36 = load i32, ptr %35, align 4, !tbaa !16
  store i32 %36, ptr %8, align 4, !tbaa !17
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.b2Body, ptr %37, i32 0, i32 19
  %39 = load i32, ptr %38, align 4, !tbaa !18
  store i32 %39, ptr %9, align 4, !tbaa !17
  br label %47

40:                                               ; preds = %25
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.b2Body, ptr %41, i32 0, i32 9
  %43 = load i32, ptr %42, align 4, !tbaa !16
  store i32 %43, ptr %8, align 4, !tbaa !17
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.b2Body, ptr %44, i32 0, i32 19
  %46 = load i32, ptr %45, align 4, !tbaa !18
  store i32 %46, ptr %9, align 4, !tbaa !17
  br label %47

47:                                               ; preds = %40, %33
  br label %48

48:                                               ; preds = %89, %47
  %49 = load i32, ptr %8, align 4, !tbaa !17
  %50 = icmp ne i32 %49, -1
  br i1 %50, label %51, label %90

51:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %52 = load i32, ptr %8, align 4, !tbaa !17
  %53 = ashr i32 %52, 1
  store i32 %53, ptr %10, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %54 = load i32, ptr %8, align 4, !tbaa !17
  %55 = and i32 %54, 1
  store i32 %55, ptr %11, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %56 = load i32, ptr %11, align 4, !tbaa !17
  %57 = xor i32 %56, 1
  store i32 %57, ptr %12, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.b2World, ptr %58, i32 0, i32 8
  %60 = load i32, ptr %10, align 4, !tbaa !17
  %61 = call ptr @b2JointArray_Get(ptr noundef %59, i32 noundef %60)
  store ptr %61, ptr %13, align 8, !tbaa !5
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.b2Joint, ptr %62, i32 0, i32 13
  %64 = load i8, ptr %63, align 1, !tbaa !19, !range !21, !noundef !22
  %65 = trunc i8 %64 to i1
  %66 = zext i1 %65 to i32
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %68, label %79

68:                                               ; preds = %51
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.b2Joint, ptr %69, i32 0, i32 4
  %71 = load i32, ptr %12, align 4, !tbaa !17
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [2 x %struct.b2JointEdge], ptr %70, i64 0, i64 %72
  %74 = getelementptr inbounds %struct.b2JointEdge, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %74, align 4, !tbaa !23
  %76 = load i32, ptr %9, align 4, !tbaa !17
  %77 = icmp eq i32 %75, %76
  br i1 %77, label %78, label %79

78:                                               ; preds = %68
  store i1 false, ptr %4, align 1
  store i32 1, ptr %14, align 4
  br label %87

79:                                               ; preds = %68, %51
  %80 = load ptr, ptr %13, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.b2Joint, ptr %80, i32 0, i32 4
  %82 = load i32, ptr %11, align 4, !tbaa !17
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [2 x %struct.b2JointEdge], ptr %81, i64 0, i64 %83
  %85 = getelementptr inbounds %struct.b2JointEdge, ptr %84, i32 0, i32 2
  %86 = load i32, ptr %85, align 4, !tbaa !25
  store i32 %86, ptr %8, align 4, !tbaa !17
  store i32 0, ptr %14, align 4
  br label %87

87:                                               ; preds = %79, %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %88 = load i32, ptr %14, align 4
  switch i32 %88, label %91 [
    i32 0, label %89
  ]

89:                                               ; preds = %87
  br label %48, !llvm.loop !26

90:                                               ; preds = %48
  store i1 true, ptr %4, align 1
  store i32 1, ptr %14, align 4
  br label %91

91:                                               ; preds = %90, %87
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %92

92:                                               ; preds = %91, %24
  %93 = load i1, ptr %4, align 1
  ret i1 %93
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 112}
!10 = !{!"b2Body", !7, i64 0, !6, 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, !12, i64 88, !12, i64 92, !12, i64 96, !12, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !13, i64 116, !14, i64 118, !14, i64 119, !14, i64 120, !14, i64 121}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!10, !11, i64 72}
!16 = !{!10, !11, i64 68}
!17 = !{!11, !11, i64 0}
!18 = !{!10, !11, i64 108}
!19 = !{!20, !14, i64 71}
!20 = !{!"b2Joint", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !7, i64 20, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !12, i64 60, !11, i64 64, !13, i64 68, !14, i64 70, !14, i64 71}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!24, !11, i64 0}
!24 = !{!"b2JointEdge", !11, i64 0, !11, i64 4, !11, i64 8}
!25 = !{!24, !11, i64 8}
!26 = distinct !{!26, !27}
!27 = !{!"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.b2JointEdge = type { i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @b2ShouldBodiesCollide(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %1, i64 112
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %5, 2
  br i1 %.not, label %9, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %2, i64 112
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %.not26 = icmp eq i32 %8, 2
  br i1 %.not26, label %9, label %.thread

9:                                                ; preds = %6, %3
  %10 = getelementptr inbounds i8, ptr %1, i64 72
  %11 = load i32, ptr %10, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %2, i64 72
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = icmp slt i32 %11, %13
  %. = select i1 %14, ptr %2, ptr %1
  %.29 = select i1 %14, ptr %1, ptr %2
  %.022.in = getelementptr inbounds i8, ptr %.29, i64 68
  %.025.in = getelementptr inbounds i8, ptr %., i64 108
  %.025 = load i32, ptr %.025.in, align 4, !tbaa !15
  %.12332 = load i32, ptr %.022.in, align 4, !tbaa !16
  %.not2833 = icmp eq i32 %.12332, -1
  br i1 %.not2833, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %15 = getelementptr inbounds i8, ptr %0, i64 1112
  br label %16

16:                                               ; preds = %.lr.ph, %30
  %.12334 = phi i32 [ %.12332, %.lr.ph ], [ %.123, %30 ]
  %17 = ashr i32 %.12334, 1
  %18 = and i32 %.12334, 1
  %19 = tail call ptr @b2JointArray_Get(ptr noundef nonnull %15, i32 noundef %17)
  %20 = getelementptr inbounds i8, ptr %19, i64 71
  %21 = load i8, ptr %20, align 1, !tbaa !17, !range !19, !noundef !20
  %22 = icmp eq i8 %21, 0
  br i1 %22, label %23, label %30

23:                                               ; preds = %16
  %24 = xor i32 %18, 1
  %25 = getelementptr inbounds i8, ptr %19, i64 20
  %26 = zext nneg i32 %24 to i64
  %27 = getelementptr inbounds [2 x %struct.b2JointEdge], ptr %25, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !21
  %29 = icmp eq i32 %28, %.025
  br i1 %29, label %.thread, label %30

30:                                               ; preds = %16, %23
  %31 = getelementptr inbounds i8, ptr %19, i64 20
  %32 = zext nneg i32 %18 to i64
  %33 = getelementptr inbounds [2 x %struct.b2JointEdge], ptr %31, i64 0, i64 %32, i32 2
  %.123 = load i32, ptr %33, align 4, !tbaa !16
  %.not28 = icmp eq i32 %.123, -1
  br i1 %.not28, label %.thread, label %16, !llvm.loop !23

.thread:                                          ; preds = %30, %23, %9, %6
  %.3 = phi i1 [ false, %6 ], [ true, %9 ], [ true, %30 ], [ false, %23 ]
  ret i1 %.3
}

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

!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 112}
!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 = !{!6, !10, i64 72}
!15 = !{!6, !10, i64 108}
!16 = !{!10, !10, i64 0}
!17 = !{!18, !13, i64 71}
!18 = !{!"b2Joint", !9, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 20, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !11, i64 60, !10, i64 64, !12, i64 68, !13, i64 70, !13, i64 71}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!22, !10, i64 0}
!22 = !{!"b2JointEdge", !10, i64 0, !10, i64 4, !10, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass