; LLVM IR from jdeokkim/ferox :: src (world)

; 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.frWorld_ = type { %struct.anon, %struct.anon.0, ptr, ptr, float, float, %struct.frCollisionHandler_, %struct.frVector2_ }
%struct.anon = type { ptr, i64, i64 }
%struct.anon.0 = type { ptr, i64, i32, i32 }
%struct.frCollisionHandler_ = type { ptr, ptr }
%struct.frVector2_ = type { float, float }
%struct.frContactCacheEntry_ = type { %struct.frBodyPair_, %struct.frCollision_ }
%struct.frBodyPair_ = type { ptr, ptr }
%struct.frCollision_ = type { i32, %struct.frVector2_, [2 x %struct.frContact_], float, float }
%struct.frContact_ = type { i32, float, float, %struct.frVector2_, %struct.anon.1 }
%struct.anon.1 = type { float, float, float, float }

; 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: nounwind
declare void @free(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @stbds_hmfree_func(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @frReleaseWorld(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %7

6:                                                ; preds = %1
  br label %66

7:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %26, %7
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = sext i32 %9 to i64
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.frWorld_, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = icmp ult i64 %10, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %29

17:                                               ; preds = %8
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.frWorld_, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds %struct.anon, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !19
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds ptr, ptr %21, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  call void @frReleaseBody(ptr noundef %25)
  br label %26

26:                                               ; preds = %17
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %3, align 4, !tbaa !9
  br label %8, !llvm.loop !20

29:                                               ; preds = %16
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.frWorld_, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !22
  call void @frReleaseSpatialHash(ptr noundef %32)
  br label %33

33:                                               ; preds = %29
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.frWorld_, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds %struct.anon, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !19
  call void @free(ptr noundef %37) #4
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.frWorld_, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds %struct.anon, ptr %39, i32 0, i32 1
  store i64 0, ptr %40, align 8, !tbaa !11
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.frWorld_, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds %struct.anon, ptr %42, i32 0, i32 2
  store i64 0, ptr %43, align 8, !tbaa !23
  br label %44

44:                                               ; preds = %33
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.frWorld_, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds %struct.anon.0, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !24
  call void @free(ptr noundef %49) #4
  br label %50

50:                                               ; preds = %45
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.frWorld_, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !25
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %60

55:                                               ; preds = %50
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.frWorld_, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !25
  %59 = getelementptr inbounds %struct.frContactCacheEntry_, ptr %58, i64 -1
  call void @stbds_hmfree_func(ptr noundef %59, i64 noundef 112)
  br label %61

60:                                               ; preds = %50
  br label %61

61:                                               ; preds = %60, %55
  %62 = phi i32 [ 0, %55 ], [ 0, %60 ]
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.frWorld_, ptr %63, i32 0, i32 3
  store ptr null, ptr %64, align 8, !tbaa !25
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %65) #4
  br label %66

66:                                               ; preds = %61, %6
  ret void
}

declare void @frReleaseBody(ptr noundef) #3

declare void @frReleaseSpatialHash(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { "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, !14, i64 8}
!12 = !{!"frWorld_", !13, i64 0, !15, i64 24, !6, i64 48, !6, i64 56, !16, i64 64, !16, i64 68, !17, i64 72, !18, i64 88}
!13 = !{!"", !6, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"long", !7, i64 0}
!15 = !{!"", !6, i64 0, !14, i64 8, !10, i64 16, !10, i64 20}
!16 = !{!"float", !7, i64 0}
!17 = !{!"frCollisionHandler_", !6, i64 0, !6, i64 8}
!18 = !{!"frVector2_", !16, i64 0, !16, i64 4}
!19 = !{!12, !6, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!12, !6, i64 48}
!23 = !{!12, !14, i64 16}
!24 = !{!12, !6, i64 24}
!25 = !{!12, !6, i64 56}


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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @stbds_hmfree_func(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @frReleaseWorld(ptr noundef %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %20, label %.preheader

.preheader:                                       ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not18 = icmp eq i64 %4, 0
  br i1 %.not18, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load ptr, ptr %5, align 8, !tbaa !17
  tail call void @frReleaseSpatialHash(ptr noundef %6) #4
  %7 = load ptr, ptr %0, align 8, !tbaa !18
  tail call void @free(ptr noundef %7) #4
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %3, i8 0, i64 16, i1 false)
  %9 = load ptr, ptr %8, align 8, !tbaa !19
  tail call void @free(ptr noundef %9) #4
  %10 = getelementptr inbounds i8, ptr %0, i64 56
  %11 = load ptr, ptr %10, align 8, !tbaa !20
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %19, label %17

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %12 = load ptr, ptr %0, align 8, !tbaa !18
  %13 = getelementptr inbounds ptr, ptr %12, i64 %indvars.iv
  %14 = load ptr, ptr %13, align 8, !tbaa !21
  tail call void @frReleaseBody(ptr noundef %14) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = icmp ugt i64 %15, %indvars.iv.next
  br i1 %16, label %.lr.ph, label %._crit_edge, !llvm.loop !22

17:                                               ; preds = %._crit_edge
  %18 = getelementptr inbounds i8, ptr %11, i64 -112
  tail call void @stbds_hmfree_func(ptr noundef nonnull %18, i64 noundef 112)
  br label %19

19:                                               ; preds = %._crit_edge, %17
  tail call void @free(ptr noundef nonnull %0) #4
  br label %20

20:                                               ; preds = %1, %19
  ret void
}

declare void @frReleaseBody(ptr noundef) local_unnamed_addr #2

declare void @frReleaseSpatialHash(ptr noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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" }
attributes #2 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !11, i64 8}
!6 = !{!"frWorld_", !7, i64 0, !12, i64 24, !8, i64 48, !8, i64 56, !14, i64 64, !14, i64 68, !15, i64 72, !16, i64 88}
!7 = !{!"", !8, i64 0, !11, i64 8, !11, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"", !8, i64 0, !11, i64 8, !13, i64 16, !13, i64 20}
!13 = !{!"int", !9, i64 0}
!14 = !{!"float", !9, i64 0}
!15 = !{!"frCollisionHandler_", !8, i64 0, !8, i64 8}
!16 = !{!"frVector2_", !14, i64 0, !14, i64 4}
!17 = !{!6, !8, i64 48}
!18 = !{!6, !8, i64 0}
!19 = !{!6, !8, i64 24}
!20 = !{!6, !8, i64 56}
!21 = !{!8, !8, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass