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

; 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.frSpatialHash_ = type { ptr, float, float, %struct.anon, ptr }
%struct.anon = type { ptr, i64, i64 }
%struct.frSpatialHashEntry_ = type { %struct.frVector2i_, %struct.anon.0 }
%struct.frVector2i_ = type { i32, i32 }
%struct.anon.0 = type { ptr, i64, i64 }
%struct.stbds_array_header = type { i64, i64, ptr, i64 }

; 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 uwtable
define dso_local void @frReleaseSpatialHash(ptr noundef %0) #1 {
  %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 %92

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 = %58, %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.frSpatialHash_, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %24

15:                                               ; preds = %8
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.frSpatialHash_, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.frSpatialHashEntry_, ptr %18, i64 -1
  %20 = getelementptr inbounds %struct.stbds_array_header, ptr %19, i64 -1
  %21 = getelementptr inbounds %struct.stbds_array_header, ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !16
  %23 = sub nsw i64 %22, 1
  br label %25

24:                                               ; preds = %8
  br label %25

25:                                               ; preds = %24, %15
  %26 = phi i64 [ %23, %15 ], [ 0, %24 ]
  %27 = icmp slt i64 %10, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %61

29:                                               ; preds = %25
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.frSpatialHash_, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = load i32, ptr %3, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct.frSpatialHashEntry_, ptr %33, i64 %35
  %37 = getelementptr inbounds %struct.frSpatialHashEntry_, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds %struct.anon.0, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !18
  call void @free(ptr noundef %39) #4
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.frSpatialHash_, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = load i32, ptr %3, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.frSpatialHashEntry_, ptr %42, i64 %44
  %46 = getelementptr inbounds %struct.frSpatialHashEntry_, ptr %45, i32 0, i32 1
  %47 = getelementptr inbounds %struct.anon.0, ptr %46, i32 0, i32 1
  store i64 0, ptr %47, align 8, !tbaa !21
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.frSpatialHash_, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = load i32, ptr %3, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %struct.frSpatialHashEntry_, ptr %50, i64 %52
  %54 = getelementptr inbounds %struct.frSpatialHashEntry_, ptr %53, i32 0, i32 1
  %55 = getelementptr inbounds %struct.anon.0, ptr %54, i32 0, i32 2
  store i64 0, ptr %55, align 8, !tbaa !22
  br label %56

56:                                               ; preds = %30
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %3, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %3, align 4, !tbaa !9
  br label %8, !llvm.loop !23

61:                                               ; preds = %28
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.frSpatialHash_, ptr %62, i32 0, i32 4
  %64 = load ptr, ptr %63, align 8, !tbaa !25
  call void @free(ptr noundef %64) #4
  br label %65

65:                                               ; preds = %61
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.frSpatialHash_, ptr %66, i32 0, i32 3
  %68 = getelementptr inbounds %struct.anon, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !26
  call void @free(ptr noundef %69) #4
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.frSpatialHash_, ptr %70, i32 0, i32 3
  %72 = getelementptr inbounds %struct.anon, ptr %71, i32 0, i32 1
  store i64 0, ptr %72, align 8, !tbaa !27
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.frSpatialHash_, ptr %73, i32 0, i32 3
  %75 = getelementptr inbounds %struct.anon, ptr %74, i32 0, i32 2
  store i64 0, ptr %75, align 8, !tbaa !28
  br label %76

76:                                               ; preds = %65
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.frSpatialHash_, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !11
  %80 = icmp ne ptr %79, null
  br i1 %80, label %81, label %86

81:                                               ; preds = %76
  %82 = load ptr, ptr %2, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.frSpatialHash_, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !11
  %85 = getelementptr inbounds %struct.frSpatialHashEntry_, ptr %84, i64 -1
  call void @stbds_hmfree_func(ptr noundef %85, i64 noundef 32)
  br label %87

86:                                               ; preds = %76
  br label %87

87:                                               ; preds = %86, %81
  %88 = phi i32 [ 0, %81 ], [ 0, %86 ]
  %89 = load ptr, ptr %2, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.frSpatialHash_, ptr %89, i32 0, i32 0
  store ptr null, ptr %90, align 8, !tbaa !11
  %91 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %91) #4
  br label %92

92:                                               ; preds = %87, %6
  ret void
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

declare void @stbds_hmfree_func(ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !6, i64 0}
!12 = !{!"frSpatialHash_", !6, i64 0, !13, i64 8, !13, i64 12, !14, i64 16, !6, i64 40}
!13 = !{!"float", !7, i64 0}
!14 = !{!"", !6, i64 0, !15, i64 8, !15, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !15, i64 0}
!17 = !{!"", !15, i64 0, !15, i64 8, !6, i64 16, !15, i64 24}
!18 = !{!19, !6, i64 8}
!19 = !{!"frSpatialHashEntry_", !20, i64 0, !14, i64 8}
!20 = !{!"frVector2i_", !10, i64 0, !10, i64 4}
!21 = !{!19, !15, i64 16}
!22 = !{!19, !15, i64 24}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!12, !6, i64 40}
!26 = !{!12, !6, i64 16}
!27 = !{!12, !15, i64 24}
!28 = !{!12, !15, i64 32}


; 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.frSpatialHashEntry_ = type { %struct.frVector2i_, %struct.anon.0 }
%struct.frVector2i_ = type { i32, i32 }
%struct.anon.0 = type { ptr, i64, i64 }

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

.preheader:                                       ; preds = %1
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %.not23 = icmp eq ptr %3, null
  br i1 %.not23, label %.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %4 = getelementptr inbounds i8, ptr %3, i64 -64
  %5 = load i64, ptr %4, align 8, !tbaa !13
  %6 = icmp sgt i64 %5, 1
  br i1 %6, label %.lr.ph, label %.thread

.thread:                                          ; preds = %.lr.ph, %.lr.ph.preheader, %.preheader
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !15
  tail call void @free(ptr noundef %8) #4
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !16
  tail call void @free(ptr noundef %10) #4
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %11, i8 0, i64 16, i1 false)
  %12 = load ptr, ptr %0, align 8, !tbaa !5
  %.not22 = icmp eq ptr %12, null
  br i1 %.not22, label %24, label %22

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %13 = phi ptr [ %16, %.lr.ph ], [ %3, %.lr.ph.preheader ]
  %indvars.iv27 = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %14 = getelementptr inbounds %struct.frSpatialHashEntry_, ptr %13, i64 %indvars.iv27, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  tail call void @free(ptr noundef %15) #4
  %16 = load ptr, ptr %0, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.frSpatialHashEntry_, ptr %16, i64 %indvars.iv27, i32 1, i32 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv27, 1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %17, i8 0, i64 16, i1 false)
  %18 = getelementptr inbounds i8, ptr %16, i64 -64
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = add nsw i64 %19, -1
  %21 = icmp sgt i64 %20, %indvars.iv.next
  br i1 %21, label %.lr.ph, label %.thread, !llvm.loop !21

22:                                               ; preds = %.thread
  %23 = getelementptr inbounds i8, ptr %12, i64 -32
  tail call void @stbds_hmfree_func(ptr noundef nonnull %23, i64 noundef 32) #4
  br label %24

24:                                               ; preds = %.thread, %22
  tail call void @free(ptr noundef nonnull %0) #4
  br label %25

25:                                               ; preds = %1, %24
  ret void
}

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

declare void @stbds_hmfree_func(ptr noundef, i64 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 = { 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 = { 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 #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, !7, i64 0}
!6 = !{!"frSpatialHash_", !7, i64 0, !10, i64 8, !10, i64 12, !11, i64 16, !7, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"", !7, i64 0, !12, i64 8, !12, i64 16}
!12 = !{!"long", !8, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"", !12, i64 0, !12, i64 8, !7, i64 16, !12, i64 24}
!15 = !{!6, !7, i64 40}
!16 = !{!6, !7, i64 16}
!17 = !{!18, !7, i64 8}
!18 = !{!"frSpatialHashEntry_", !19, i64 0, !11, i64 8}
!19 = !{!"frVector2i_", !20, i64 0, !20, i64 4}
!20 = !{!"int", !8, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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