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

; 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.b2ArenaEntry = type { ptr, ptr, i32, i8 }
%struct.b2ArenaAllocator = type { ptr, i32, i32, i32, i32, %struct.b2ArenaEntryArray }
%struct.b2ArenaEntryArray = type { ptr, i32, i32 }

@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [19 x i8], align 1

declare void @b2Free(ptr noundef, i32 noundef) #0

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

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

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

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

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

12:                                               ; preds = %2
  %13 = load i32, ptr %5, align 4, !tbaa !13
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %19, label %15

15:                                               ; preds = %12
  %16 = call i32 @b2InternalAssertFcn(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 71)
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  call void @llvm.trap()
  br label %19

19:                                               ; preds = %18, %15, %12
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.b2ArenaAllocator, ptr %22, i32 0, i32 5
  %24 = getelementptr inbounds %struct.b2ArenaEntryArray, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = load i32, ptr %5, align 4, !tbaa !13
  %27 = sub nsw i32 %26, 1
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds %struct.b2ArenaEntry, ptr %25, i64 %28
  store ptr %29, ptr %6, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %21
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.b2ArenaEntry, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = icmp eq ptr %31, %34
  br i1 %35, label %40, label %36

36:                                               ; preds = %30
  %37 = call i32 @b2InternalAssertFcn(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 73)
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

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

40:                                               ; preds = %39, %36, %30
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.b2ArenaEntry, ptr %43, i32 0, i32 3
  %45 = load i8, ptr %44, align 4, !tbaa !18, !range !19, !noundef !20
  %46 = trunc i8 %45 to i1
  br i1 %46, label %47, label %52

47:                                               ; preds = %42
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.b2ArenaEntry, ptr %49, i32 0, i32 2
  %51 = load i32, ptr %50, align 8, !tbaa !21
  call void @b2Free(ptr noundef %48, i32 noundef %51)
  br label %60

52:                                               ; preds = %42
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.b2ArenaEntry, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 8, !tbaa !21
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.b2ArenaAllocator, ptr %56, i32 0, i32 2
  %58 = load i32, ptr %57, align 4, !tbaa !22
  %59 = sub nsw i32 %58, %55
  store i32 %59, ptr %57, align 4, !tbaa !22
  br label %60

60:                                               ; preds = %52, %47
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.b2ArenaEntry, ptr %61, i32 0, i32 2
  %63 = load i32, ptr %62, align 8, !tbaa !21
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.b2ArenaAllocator, ptr %64, i32 0, i32 3
  %66 = load i32, ptr %65, align 8, !tbaa !23
  %67 = sub nsw i32 %66, %63
  store i32 %67, ptr %65, align 8, !tbaa !23
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.b2ArenaAllocator, ptr %68, i32 0, i32 5
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #5
  call void @b2ArenaEntryArray_Pop(ptr dead_on_unwind writable sret(%struct.b2ArenaEntry) align 8 %7, ptr noundef %69)
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @b2ArenaEntryArray_Pop(ptr dead_on_unwind noalias writable sret(%struct.b2ArenaEntry) align 8, ptr noundef) #4

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !11, i64 32}
!10 = !{!"b2ArenaAllocator", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !12, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !6, i64 0, !11, i64 8, !11, i64 12}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 24}
!15 = !{!16, !6, i64 0}
!16 = !{!"b2ArenaEntry", !6, i64 0, !6, i64 8, !11, i64 16, !17, i64 20}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{!16, !17, i64 20}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!16, !11, i64 16}
!22 = !{!10, !11, i64 12}
!23 = !{!10, !11, i64 16}


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

@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [19 x i8], align 1

declare void @b2Free(ptr noundef, i32 noundef) local_unnamed_addr #0

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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @b2FreeArenaItem(ptr noundef %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.b2ArenaEntry, align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %11, label %8

8:                                                ; preds = %2
  %9 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 71) #5
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %11, label %10

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

11:                                               ; preds = %8, %2
  %12 = load ptr, ptr %4, align 8, !tbaa !12
  %13 = sext i32 %6 to i64
  %14 = getelementptr %struct.b2ArenaEntry, ptr %12, i64 %13
  %15 = getelementptr i8, ptr %14, i64 -24
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = icmp eq ptr %16, %1
  br i1 %17, label %21, label %18

18:                                               ; preds = %11
  %19 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 73) #5
  %.not13 = icmp eq i32 %19, 0
  br i1 %.not13, label %21, label %20

20:                                               ; preds = %18
  tail call void @llvm.trap()
  unreachable

21:                                               ; preds = %18, %11
  %22 = getelementptr i8, ptr %14, i64 -4
  %23 = load i8, ptr %22, align 4, !tbaa !16, !range !17, !noundef !18
  %24 = trunc nuw i8 %23 to i1
  %25 = getelementptr i8, ptr %14, i64 -8
  %26 = load i32, ptr %25, align 8, !tbaa !19
  br i1 %24, label %27, label %28

27:                                               ; preds = %21
  tail call void @b2Free(ptr noundef %1, i32 noundef %26) #5
  %.pre = load i32, ptr %25, align 8, !tbaa !19
  br label %32

28:                                               ; preds = %21
  %29 = getelementptr inbounds i8, ptr %0, i64 12
  %30 = load i32, ptr %29, align 4, !tbaa !20
  %31 = sub nsw i32 %30, %26
  store i32 %31, ptr %29, align 4, !tbaa !20
  br label %32

32:                                               ; preds = %28, %27
  %33 = phi i32 [ %26, %28 ], [ %.pre, %27 ]
  %34 = getelementptr inbounds i8, ptr %0, i64 16
  %35 = load i32, ptr %34, align 8, !tbaa !21
  %36 = sub nsw i32 %35, %33
  store i32 %36, ptr %34, align 8, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @b2ArenaEntryArray_Pop(ptr dead_on_unwind nonnull writable sret(%struct.b2ArenaEntry) align 8 %3, ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @b2ArenaEntryArray_Pop(ptr dead_on_unwind noalias writable sret(%struct.b2ArenaEntry) align 8, ptr noundef) local_unnamed_addr #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !10, i64 32}
!6 = !{!"b2ArenaAllocator", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !11, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12}
!12 = !{!6, !7, i64 24}
!13 = !{!14, !7, i64 0}
!14 = !{!"b2ArenaEntry", !7, i64 0, !7, i64 8, !10, i64 16, !15, i64 20}
!15 = !{!"_Bool", !8, i64 0}
!16 = !{!14, !15, i64 20}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!14, !10, i64 16}
!20 = !{!6, !10, i64 12}
!21 = !{!6, !10, i64 16}


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