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

@b2_lengthUnitsPerMeter = external global float, align 4
@.str.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [48 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: 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) #3

; Function Attrs: nounwind uwtable
declare hidden void @b2InsertLeaf(ptr noundef, i32 noundef, i1 noundef zeroext) #4

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @b2IsLeaf(ptr noundef) #5

; Function Attrs: nounwind uwtable
declare hidden void @b2RemoveLeaf(ptr noundef, i32 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @b2DynamicTree_MoveProxy(ptr noundef %0, i32 noundef %1, <2 x float> %2, <2 x float> %3) #4 {
  %5 = alloca %struct.b2AABB, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %5, i32 0, i32 0
  store <2 x float> %2, ptr %9, align 4
  %10 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %5, i32 0, i32 1
  store <2 x float> %3, ptr %10, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %4
  %12 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %5, i32 0, i32 0
  %13 = load <2 x float>, ptr %12, align 4
  %14 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %5, i32 0, i32 1
  %15 = load <2 x float>, ptr %14, align 4
  %16 = call zeroext i1 @b2IsValidAABB(<2 x float> %13, <2 x float> %15)
  br i1 %16, label %21, label %17

17:                                               ; preds = %11
  %18 = call i32 @b2InternalAssertFcn(ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 813)
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  call void @llvm.trap()
  br label %21

21:                                               ; preds = %20, %17, %11
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = getelementptr inbounds %struct.b2AABB, ptr %5, i32 0, i32 1
  %25 = getelementptr inbounds %struct.b2Vec2, ptr %24, i32 0, i32 0
  %26 = load float, ptr %25, align 4, !tbaa !11
  %27 = getelementptr inbounds %struct.b2AABB, ptr %5, i32 0, i32 0
  %28 = getelementptr inbounds %struct.b2Vec2, ptr %27, i32 0, i32 0
  %29 = load float, ptr %28, align 4, !tbaa !15
  %30 = fsub float %26, %29
  %31 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !16
  %32 = fmul float 1.000000e+05, %31
  %33 = fcmp olt float %30, %32
  br i1 %33, label %38, label %34

34:                                               ; preds = %23
  %35 = call i32 @b2InternalAssertFcn(ptr noundef @.str.9, ptr noundef @.str.1, i32 noundef 814)
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  call void @llvm.trap()
  br label %38

38:                                               ; preds = %37, %34, %23
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  %41 = getelementptr inbounds %struct.b2AABB, ptr %5, i32 0, i32 1
  %42 = getelementptr inbounds %struct.b2Vec2, ptr %41, i32 0, i32 1
  %43 = load float, ptr %42, align 4, !tbaa !17
  %44 = getelementptr inbounds %struct.b2AABB, ptr %5, i32 0, i32 0
  %45 = getelementptr inbounds %struct.b2Vec2, ptr %44, i32 0, i32 1
  %46 = load float, ptr %45, align 4, !tbaa !18
  %47 = fsub float %43, %46
  %48 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !16
  %49 = fmul float 1.000000e+05, %48
  %50 = fcmp olt float %47, %49
  br i1 %50, label %55, label %51

51:                                               ; preds = %40
  %52 = call i32 @b2InternalAssertFcn(ptr noundef @.str.10, ptr noundef @.str.1, i32 noundef 815)
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %51
  call void @llvm.trap()
  br label %55

55:                                               ; preds = %54, %51, %40
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = icmp sle i32 0, %58
  br i1 %59, label %60, label %66

60:                                               ; preds = %57
  %61 = load i32, ptr %7, align 4, !tbaa !9
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.b2DynamicTree, ptr %62, i32 0, i32 3
  %64 = load i32, ptr %63, align 8, !tbaa !19
  %65 = icmp slt i32 %61, %64
  br i1 %65, label %70, label %66

66:                                               ; preds = %60, %57
  %67 = call i32 @b2InternalAssertFcn(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 816)
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %66
  call void @llvm.trap()
  br label %70

70:                                               ; preds = %69, %66, %60
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.b2DynamicTree, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !21
  %76 = load i32, ptr %7, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds %struct.b2TreeNode, ptr %75, i64 %77
  %79 = call zeroext i1 @b2IsLeaf(ptr noundef %78)
  br i1 %79, label %84, label %80

80:                                               ; preds = %72
  %81 = call i32 @b2InternalAssertFcn(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 817)
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %84

83:                                               ; preds = %80
  call void @llvm.trap()
  br label %84

84:                                               ; preds = %83, %80, %72
  br label %85

85:                                               ; preds = %84
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = load i32, ptr %7, align 4, !tbaa !9
  call void @b2RemoveLeaf(ptr noundef %86, i32 noundef %87)
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.b2DynamicTree, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !21
  %91 = load i32, ptr %7, align 4, !tbaa !9
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds %struct.b2TreeNode, ptr %90, i64 %92
  %94 = getelementptr inbounds %struct.b2TreeNode, ptr %93, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %94, ptr align 4 %5, i64 16, i1 false), !tbaa.struct !22
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #6
  store i8 0, ptr %8, align 1, !tbaa !23
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = load i32, ptr %7, align 4, !tbaa !9
  %97 = load i8, ptr %8, align 1, !tbaa !23, !range !25, !noundef !26
  %98 = trunc i8 %97 to i1
  call void @b2InsertLeaf(ptr noundef %95, i32 noundef %96, i1 noundef zeroext %98)
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #6
  ret void
}

declare zeroext i1 @b2IsValidAABB(<2 x float>, <2 x float>) #1

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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 #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 = !{!"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, !14, i64 8}
!12 = !{!"b2AABB", !13, i64 0, !13, i64 8}
!13 = !{!"b2Vec2", !14, i64 0, !14, i64 4}
!14 = !{!"float", !7, i64 0}
!15 = !{!12, !14, i64 0}
!16 = !{!14, !14, i64 0}
!17 = !{!12, !14, i64 12}
!18 = !{!12, !14, i64 4}
!19 = !{!20, !10, i64 16}
!20 = !{!"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}
!21 = !{!20, !6, i64 0}
!22 = !{i64 0, i64 4, !16, i64 4, i64 4, !16, i64 8, i64 4, !16, i64 12, i64 4, !16}
!23 = !{!24, !24, i64 0}
!24 = !{!"_Bool", !7, i64 0}
!25 = !{i8 0, i8 2}
!26 = !{}


; 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 }

@b2_lengthUnitsPerMeter = external local_unnamed_addr global float, align 4
@.str.1 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [48 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
declare hidden void @b2InsertLeaf(ptr noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @b2IsLeaf(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @b2RemoveLeaf(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @b2DynamicTree_MoveProxy(ptr noundef %0, i32 noundef %1, <2 x float> %2, <2 x float> %3) local_unnamed_addr #2 {
  %5 = tail call zeroext i1 @b2IsValidAABB(<2 x float> %2, <2 x float> %3) #4
  br i1 %5, label %9, label %6

6:                                                ; preds = %4
  %7 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i32 noundef 813) #4
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %9, label %8

8:                                                ; preds = %6
  tail call void @llvm.trap()
  unreachable

9:                                                ; preds = %6, %4
  %10 = fsub <2 x float> %3, %2
  %11 = extractelement <2 x float> %10, i64 0
  %12 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !5
  %13 = fmul float %12, 1.000000e+05
  %14 = fcmp olt float %11, %13
  br i1 %14, label %18, label %15

15:                                               ; preds = %9
  %16 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.1, i32 noundef 814) #4
  %.not13 = icmp eq i32 %16, 0
  br i1 %.not13, label %._crit_edge, label %17

._crit_edge:                                      ; preds = %15
  %.pre = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !5
  %.pre17 = fmul float %.pre, 1.000000e+05
  br label %18

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

18:                                               ; preds = %._crit_edge, %9
  %.pre-phi = phi float [ %.pre17, %._crit_edge ], [ %13, %9 ]
  %19 = fsub <2 x float> %3, %2
  %20 = extractelement <2 x float> %19, i64 1
  %21 = fcmp olt float %20, %.pre-phi
  br i1 %21, label %25, label %22

22:                                               ; preds = %18
  %23 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.1, i32 noundef 815) #4
  %.not14 = icmp eq i32 %23, 0
  br i1 %.not14, label %25, label %24

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

25:                                               ; preds = %22, %18
  %26 = icmp sgt i32 %1, -1
  br i1 %26, label %27, label %31

27:                                               ; preds = %25
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = icmp sgt i32 %29, %1
  br i1 %30, label %34, label %31

31:                                               ; preds = %27, %25
  %32 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 816) #4
  %.not15 = icmp eq i32 %32, 0
  br i1 %.not15, label %34, label %33

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

34:                                               ; preds = %31, %27
  %35 = load ptr, ptr %0, align 8, !tbaa !13
  %36 = sext i32 %1 to i64
  %37 = getelementptr inbounds %struct.b2TreeNode, ptr %35, i64 %36
  %38 = tail call zeroext i1 @b2IsLeaf(ptr noundef %37)
  br i1 %38, label %42, label %39

39:                                               ; preds = %34
  %40 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 817) #4
  %.not16 = icmp eq i32 %40, 0
  br i1 %.not16, label %42, label %41

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

42:                                               ; preds = %34, %39
  tail call void @b2RemoveLeaf(ptr noundef nonnull %0, i32 noundef %1)
  %43 = load ptr, ptr %0, align 8, !tbaa !13
  %44 = getelementptr inbounds %struct.b2TreeNode, ptr %43, i64 %36
  store <2 x float> %2, ptr %44, align 8
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %44, i64 8
  store <2 x float> %3, ptr %.sroa.5.0..sroa_idx, align 8
  tail call void @b2InsertLeaf(ptr noundef nonnull %0, i32 noundef %1, i1 noundef zeroext false)
  ret void
}

declare zeroext i1 @b2IsValidAABB(<2 x float>, <2 x float>) local_unnamed_addr #0

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"="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 #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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 16}
!10 = !{!"b2DynamicTree", !11, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !12, i64 64}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass