; LLVM IR from erincatto/box2d :: src (dynamic_tree)

; 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.b2DynamicTree = type { ptr, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, i32 }
%struct.b2TreeNode = type { %struct.b2AABB, i64, %union.anon, %union.anon.0, i16, i16 }
%struct.b2AABB = type { %struct.b2Vec2, %struct.b2Vec2 }
%struct.b2Vec2 = type { float, float }
%union.anon = type { i64 }
%union.anon.0 = type { i32 }
%struct.anon = type { i32, i32 }

@.str.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [24 x i8], align 1

; 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 i32 @b2InternalAssertFcn(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: cold noreturn nounwind memory(inaccessiblemem: write)
declare void @llvm.trap() #2

; Function Attrs: nounwind uwtable
define dso_local void @b2DynamicTree_SetCategoryBits(ptr noundef %0, i32 noundef %1, i64 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.b2DynamicTree, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  store ptr %14, ptr %7, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %3
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds %struct.b2TreeNode, ptr %16, i64 %18
  %20 = getelementptr inbounds %struct.b2TreeNode, ptr %19, i32 0, i32 2
  %21 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !15
  %23 = icmp eq i32 %22, -1
  br i1 %23, label %28, label %24

24:                                               ; preds = %15
  %25 = call i32 @b2InternalAssertFcn(ptr noundef @.str.12, ptr noundef @.str.1, i32 noundef 872)
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  call void @llvm.trap()
  br label %28

28:                                               ; preds = %27, %24, %15
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds %struct.b2TreeNode, ptr %32, i64 %34
  %36 = getelementptr inbounds %struct.b2TreeNode, ptr %35, i32 0, i32 2
  %37 = getelementptr inbounds %struct.anon, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !15
  %39 = icmp eq i32 %38, -1
  br i1 %39, label %44, label %40

40:                                               ; preds = %31
  %41 = call i32 @b2InternalAssertFcn(ptr noundef @.str.13, ptr noundef @.str.1, i32 noundef 873)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %40
  call void @llvm.trap()
  br label %44

44:                                               ; preds = %43, %40, %31
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %struct.b2TreeNode, ptr %48, i64 %50
  %52 = getelementptr inbounds %struct.b2TreeNode, ptr %51, i32 0, i32 5
  %53 = load i16, ptr %52, align 2, !tbaa !16
  %54 = zext i16 %53 to i32
  %55 = and i32 %54, 4
  %56 = icmp eq i32 %55, 4
  br i1 %56, label %61, label %57

57:                                               ; preds = %47
  %58 = call i32 @b2InternalAssertFcn(ptr noundef @.str.14, ptr noundef @.str.1, i32 noundef 874)
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %61

60:                                               ; preds = %57
  call void @llvm.trap()
  br label %61

61:                                               ; preds = %60, %57, %47
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  %64 = load i64, ptr %6, align 8, !tbaa !11
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds %struct.b2TreeNode, ptr %65, i64 %67
  %69 = getelementptr inbounds %struct.b2TreeNode, ptr %68, i32 0, i32 1
  store i64 %64, ptr %69, align 8, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = load i32, ptr %5, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds %struct.b2TreeNode, ptr %70, i64 %72
  %74 = getelementptr inbounds %struct.b2TreeNode, ptr %73, i32 0, i32 3
  %75 = load i32, ptr %74, align 8, !tbaa !15
  store i32 %75, ptr %8, align 4, !tbaa !9
  br label %76

76:                                               ; preds = %111, %63
  %77 = load i32, ptr %8, align 4, !tbaa !9
  %78 = icmp ne i32 %77, -1
  br i1 %78, label %79, label %130

79:                                               ; preds = %76
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load i32, ptr %8, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds %struct.b2TreeNode, ptr %80, i64 %82
  store ptr %83, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.b2TreeNode, ptr %84, i32 0, i32 2
  %86 = getelementptr inbounds %struct.anon, ptr %85, i32 0, i32 0
  %87 = load i32, ptr %86, align 8, !tbaa !15
  store i32 %87, ptr %10, align 4, !tbaa !9
  br label %88

88:                                               ; preds = %79
  %89 = load i32, ptr %10, align 4, !tbaa !9
  %90 = icmp ne i32 %89, -1
  br i1 %90, label %95, label %91

91:                                               ; preds = %88
  %92 = call i32 @b2InternalAssertFcn(ptr noundef @.str.15, ptr noundef @.str.1, i32 noundef 884)
  %93 = icmp ne i32 %92, 0
  br i1 %93, label %94, label %95

94:                                               ; preds = %91
  call void @llvm.trap()
  br label %95

95:                                               ; preds = %94, %91, %88
  br label %96

96:                                               ; preds = %95
  br label %97

97:                                               ; preds = %96
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.b2TreeNode, ptr %98, i32 0, i32 2
  %100 = getelementptr inbounds %struct.anon, ptr %99, i32 0, i32 1
  %101 = load i32, ptr %100, align 4, !tbaa !15
  store i32 %101, ptr %11, align 4, !tbaa !9
  br label %102

102:                                              ; preds = %97
  %103 = load i32, ptr %11, align 4, !tbaa !9
  %104 = icmp ne i32 %103, -1
  br i1 %104, label %109, label %105

105:                                              ; preds = %102
  %106 = call i32 @b2InternalAssertFcn(ptr noundef @.str.16, ptr noundef @.str.1, i32 noundef 886)
  %107 = icmp ne i32 %106, 0
  br i1 %107, label %108, label %109

108:                                              ; preds = %105
  call void @llvm.trap()
  br label %109

109:                                              ; preds = %108, %105, %102
  br label %110

110:                                              ; preds = %109
  br label %111

111:                                              ; preds = %110
  %112 = load ptr, ptr %7, align 8, !tbaa !5
  %113 = load i32, ptr %10, align 4, !tbaa !9
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds %struct.b2TreeNode, ptr %112, i64 %114
  %116 = getelementptr inbounds %struct.b2TreeNode, ptr %115, i32 0, i32 1
  %117 = load i64, ptr %116, align 8, !tbaa !22
  %118 = load ptr, ptr %7, align 8, !tbaa !5
  %119 = load i32, ptr %11, align 4, !tbaa !9
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds %struct.b2TreeNode, ptr %118, i64 %120
  %122 = getelementptr inbounds %struct.b2TreeNode, ptr %121, i32 0, i32 1
  %123 = load i64, ptr %122, align 8, !tbaa !22
  %124 = or i64 %117, %123
  %125 = load ptr, ptr %9, align 8, !tbaa !5
  %126 = getelementptr inbounds %struct.b2TreeNode, ptr %125, i32 0, i32 1
  store i64 %124, ptr %126, align 8, !tbaa !22
  %127 = load ptr, ptr %9, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.b2TreeNode, ptr %127, i32 0, i32 3
  %129 = load i32, ptr %128, align 8, !tbaa !15
  store i32 %129, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %76, !llvm.loop !23

130:                                              ; preds = %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

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 = { cold noreturn nounwind memory(inaccessiblemem: write) }
attributes #3 = { 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 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"b2DynamicTree", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !21, i64 38}
!17 = !{!"b2TreeNode", !18, i64 0, !12, i64 16, !7, i64 24, !7, i64 32, !21, i64 36, !21, i64 38}
!18 = !{!"b2AABB", !19, i64 0, !19, i64 8}
!19 = !{!"b2Vec2", !20, i64 0, !20, i64 4}
!20 = !{!"float", !7, i64 0}
!21 = !{!"short", !7, i64 0}
!22 = !{!17, !12, i64 16}
!23 = distinct !{!23, !24}
!24 = !{!"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.b2TreeNode = type { %struct.b2AABB, i64, %union.anon, %union.anon.0, i16, i16 }
%struct.b2AABB = type { %struct.b2Vec2, %struct.b2Vec2 }
%struct.b2Vec2 = type { float, float }
%union.anon = type { i64 }
%union.anon.0 = type { i32 }

@.str.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [24 x i8], align 1

declare i32 @b2InternalAssertFcn(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: cold noreturn nounwind memory(inaccessiblemem: write)
declare void @llvm.trap() #1

; Function Attrs: nounwind uwtable
define dso_local void @b2DynamicTree_SetCategoryBits(ptr nocapture noundef readonly %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = sext i32 %1 to i64
  %6 = getelementptr inbounds %struct.b2TreeNode, ptr %4, i64 %5
  %7 = getelementptr inbounds i8, ptr %6, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = icmp eq i32 %8, -1
  br i1 %9, label %13, label %10

10:                                               ; preds = %3
  %11 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.12, ptr noundef nonnull @.str.1, i32 noundef 872) #3
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %13, label %12

12:                                               ; preds = %10
  tail call void @llvm.trap()
  unreachable

13:                                               ; preds = %3, %10
  %14 = getelementptr inbounds i8, ptr %6, i64 28
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %20, label %17

17:                                               ; preds = %13
  %18 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.1, i32 noundef 873) #3
  %.not24 = icmp eq i32 %18, 0
  br i1 %.not24, label %20, label %19

19:                                               ; preds = %17
  tail call void @llvm.trap()
  unreachable

20:                                               ; preds = %13, %17
  %21 = getelementptr inbounds i8, ptr %6, i64 38
  %22 = load i16, ptr %21, align 2, !tbaa !12
  %23 = and i16 %22, 4
  %.not25 = icmp eq i16 %23, 0
  br i1 %.not25, label %24, label %27

24:                                               ; preds = %20
  %25 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.14, ptr noundef nonnull @.str.1, i32 noundef 874) #3
  %.not26 = icmp eq i32 %25, 0
  br i1 %.not26, label %27, label %26

26:                                               ; preds = %24
  tail call void @llvm.trap()
  unreachable

27:                                               ; preds = %24, %20
  %28 = getelementptr inbounds i8, ptr %6, i64 16
  store i64 %2, ptr %28, align 8, !tbaa !19
  %.0.in32 = getelementptr inbounds %struct.b2TreeNode, ptr %4, i64 %5, i32 3
  %.033 = load i32, ptr %.0.in32, align 8, !tbaa !11
  %.not2734 = icmp eq i32 %.033, -1
  br i1 %.not2734, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %27, %42
  %.035 = phi i32 [ %.0, %42 ], [ %.033, %27 ]
  %29 = sext i32 %.035 to i64
  %30 = getelementptr inbounds %struct.b2TreeNode, ptr %4, i64 %29
  %31 = getelementptr inbounds i8, ptr %30, i64 24
  %32 = load i32, ptr %31, align 8, !tbaa !11
  %.not28 = icmp eq i32 %32, -1
  br i1 %.not28, label %33, label %36

33:                                               ; preds = %.lr.ph
  %34 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.15, ptr noundef nonnull @.str.1, i32 noundef 884) #3
  %.not29 = icmp eq i32 %34, 0
  br i1 %.not29, label %36, label %35

35:                                               ; preds = %33
  tail call void @llvm.trap()
  unreachable

36:                                               ; preds = %33, %.lr.ph
  %37 = getelementptr inbounds i8, ptr %30, i64 28
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %.not30 = icmp eq i32 %38, -1
  br i1 %.not30, label %39, label %42

39:                                               ; preds = %36
  %40 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.16, ptr noundef nonnull @.str.1, i32 noundef 886) #3
  %.not31 = icmp eq i32 %40, 0
  br i1 %.not31, label %42, label %41

41:                                               ; preds = %39
  tail call void @llvm.trap()
  unreachable

42:                                               ; preds = %39, %36
  %43 = sext i32 %32 to i64
  %44 = getelementptr inbounds %struct.b2TreeNode, ptr %4, i64 %43, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !19
  %46 = sext i32 %38 to i64
  %47 = getelementptr inbounds %struct.b2TreeNode, ptr %4, i64 %46, i32 1
  %48 = load i64, ptr %47, align 8, !tbaa !19
  %49 = or i64 %48, %45
  %50 = getelementptr inbounds i8, ptr %30, i64 16
  store i64 %49, ptr %50, align 8, !tbaa !19
  %.0.in = getelementptr inbounds %struct.b2TreeNode, ptr %4, i64 %29, i32 3
  %.0 = load i32, ptr %.0.in, align 8, !tbaa !11
  %.not27 = icmp eq i32 %.0, -1
  br i1 %.not27, label %._crit_edge, label %.lr.ph, !llvm.loop !20

._crit_edge:                                      ; preds = %42, %27
  ret void
}

attributes #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 = { cold noreturn nounwind memory(inaccessiblemem: write) }
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, !7, i64 0}
!6 = !{!"b2DynamicTree", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !10, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!13, !18, i64 38}
!13 = !{!"b2TreeNode", !14, i64 0, !17, i64 16, !8, i64 24, !8, i64 32, !18, i64 36, !18, i64 38}
!14 = !{!"b2AABB", !15, i64 0, !15, i64 8}
!15 = !{!"b2Vec2", !16, i64 0, !16, i64 4}
!16 = !{!"float", !8, i64 0}
!17 = !{!"long", !8, i64 0}
!18 = !{!"short", !8, i64 0}
!19 = !{!13, !17, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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