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

; Function Attrs: nounwind uwtable
define dso_local void @b2DynamicTree_Create(ptr dead_on_unwind noalias writable sret(%struct.b2DynamicTree) align 8 %0) #0 {
  %2 = alloca i32, align 4
  %3 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 1
  store i32 -1, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 3
  store i32 16, ptr %4, align 8, !tbaa !11
  %5 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 2
  store i32 0, ptr %5, align 4, !tbaa !12
  %6 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 3
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = sext i32 %7 to i64
  %9 = mul i64 %8, 40
  %10 = trunc i64 %9 to i32
  %11 = call ptr @b2Alloc(i32 noundef %10)
  %12 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 0
  store ptr %11, ptr %12, align 8, !tbaa !13
  %13 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 3
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = sext i32 %16 to i64
  %18 = mul i64 %17, 40
  call void @llvm.memset.p0.i64(ptr align 8 %14, i8 0, i64 %18, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !14
  br label %19

19:                                               ; preds = %35, %1
  %20 = load i32, ptr %2, align 4, !tbaa !14
  %21 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 3
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = sub nsw i32 %22, 1
  %24 = icmp slt i32 %20, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %38

26:                                               ; preds = %19
  %27 = load i32, ptr %2, align 4, !tbaa !14
  %28 = add nsw i32 %27, 1
  %29 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = load i32, ptr %2, align 4, !tbaa !14
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds %struct.b2TreeNode, ptr %30, i64 %32
  %34 = getelementptr inbounds %struct.b2TreeNode, ptr %33, i32 0, i32 3
  store i32 %28, ptr %34, align 8, !tbaa !15
  br label %35

35:                                               ; preds = %26
  %36 = load i32, ptr %2, align 4, !tbaa !14
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %2, align 4, !tbaa !14
  br label %19, !llvm.loop !16

38:                                               ; preds = %25
  %39 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 3
  %42 = load i32, ptr %41, align 8, !tbaa !11
  %43 = sub nsw i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.b2TreeNode, ptr %40, i64 %44
  %46 = getelementptr inbounds %struct.b2TreeNode, ptr %45, i32 0, i32 3
  store i32 -1, ptr %46, align 8, !tbaa !15
  %47 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 4
  store i32 0, ptr %47, align 4, !tbaa !18
  %48 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 5
  store i32 0, ptr %48, align 8, !tbaa !19
  %49 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 6
  store ptr null, ptr %49, align 8, !tbaa !20
  %50 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 7
  store ptr null, ptr %50, align 8, !tbaa !21
  %51 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 8
  store ptr null, ptr %51, align 8, !tbaa !22
  %52 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 9
  store ptr null, ptr %52, align 8, !tbaa !23
  %53 = getelementptr inbounds %struct.b2DynamicTree, ptr %0, i32 0, i32 10
  store i32 0, ptr %53, align 8, !tbaa !24
  ret void
}

declare ptr @b2Alloc(i32 noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 8}
!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 = !{!6, !10, i64 16}
!12 = !{!6, !10, i64 12}
!13 = !{!6, !7, i64 0}
!14 = !{!10, !10, i64 0}
!15 = !{!8, !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !10, i64 20}
!19 = !{!6, !10, i64 24}
!20 = !{!6, !7, i64 32}
!21 = !{!6, !7, i64 40}
!22 = !{!6, !7, i64 48}
!23 = !{!6, !7, i64 56}
!24 = !{!6, !10, i64 64}


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

; Function Attrs: nounwind uwtable
define dso_local void @b2DynamicTree_Create(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.b2DynamicTree) align 8 %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = tail call ptr @b2Alloc(i32 noundef 640) #3
  store ptr %3, ptr %0, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(640) %3, i8 0, i64 640, i1 false)
  %4 = getelementptr inbounds i8, ptr %3, i64 32
  store i32 1, ptr %4, align 8, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %3, i64 72
  store i32 2, ptr %5, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %3, i64 112
  store i32 3, ptr %6, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %3, i64 152
  store i32 4, ptr %7, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %3, i64 192
  store i32 5, ptr %8, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %3, i64 232
  store i32 6, ptr %9, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %3, i64 272
  store i32 7, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %3, i64 312
  store i32 8, ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %3, i64 352
  store i32 9, ptr %12, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %3, i64 392
  store i32 10, ptr %13, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %3, i64 432
  store i32 11, ptr %14, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %3, i64 472
  store i32 12, ptr %15, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %3, i64 512
  store i32 13, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %3, i64 552
  store i32 14, ptr %17, align 8, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %3, i64 592
  store i32 15, ptr %18, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %3, i64 632
  store i32 -1, ptr %19, align 8, !tbaa !11
  store <4 x i32> <i32 -1, i32 0, i32 16, i32 0>, ptr %2, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 0, ptr %20, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(36) %21, i8 0, i64 36, i1 false)
  ret void
}

declare ptr @b2Alloc(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!10, !10, i64 0}
!13 = !{!6, !10, i64 24}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass