; LLVM IR from ashishzero/karma :: src/broad_phase.ll (Z29hgrid_collision_check_objectsP5HGridP10Rigid_Bodyj)

; 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.HGrid = type { ptr, i32, float, i32 }
%struct.Grid = type { %union.Vec2, float, i32, ptr }
%union.Vec2 = type { %struct.anon.1 }
%struct.anon.1 = type { float, float }
%struct.Rigid_Body = type { i16, i16, float, float, float, float, %union.Vec2, %union.Vec2, %struct.Transform, i32, ptr, %struct.Mm_Rect, %struct.Entity_Id, ptr, i32, i32 }
%struct.Transform = type { %union.Vec2, %union.Mat2 }
%union.Mat2 = type { [2 x %union.Vec2] }
%struct.Mm_Rect = type { %union.Vec2, %union.Vec2 }
%struct.Entity_Id = type { 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: mustprogress uwtable
define dso_local void @_Z29hgrid_collision_check_objectsP5HGridP10Rigid_Bodyj(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca [64 x i32], align 16
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.HGrid, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  store ptr %17, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.HGrid, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 8, !tbaa !14
  store i32 %20, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds %struct.Grid, ptr %21, i64 %23
  store ptr %24, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Grid, ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  store ptr %27, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 256, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = load i32, ptr %12, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [64 x i32], ptr %11, i64 0, i64 %30
  store i32 %28, ptr %31, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %121, %3
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = icmp sge i32 %33, 0
  br i1 %34, label %35, label %122

35:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %36 = load i32, ptr %12, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [64 x i32], ptr %11, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !9
  store i32 %39, ptr %13, align 4, !tbaa !9
  %40 = load i32, ptr %13, align 4, !tbaa !9
  %41 = mul i32 %40, 4
  %42 = add i32 %41, 1
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = icmp ult i32 %42, %43
  br i1 %44, label %45, label %76

45:                                               ; preds = %35
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = mul i32 %46, 4
  %48 = add i32 %47, 4
  %49 = load i32, ptr %12, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [64 x i32], ptr %11, i64 0, i64 %50
  store i32 %48, ptr %51, align 4, !tbaa !9
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %12, align 4, !tbaa !9
  %54 = load i32, ptr %13, align 4, !tbaa !9
  %55 = mul i32 %54, 4
  %56 = add i32 %55, 3
  %57 = load i32, ptr %12, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [64 x i32], ptr %11, i64 0, i64 %58
  store i32 %56, ptr %59, align 4, !tbaa !9
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %12, align 4, !tbaa !9
  %62 = load i32, ptr %13, align 4, !tbaa !9
  %63 = mul i32 %62, 4
  %64 = add i32 %63, 2
  %65 = load i32, ptr %12, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [64 x i32], ptr %11, i64 0, i64 %66
  store i32 %64, ptr %67, align 4, !tbaa !9
  %68 = load i32, ptr %12, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %12, align 4, !tbaa !9
  %70 = load i32, ptr %13, align 4, !tbaa !9
  %71 = mul i32 %70, 4
  %72 = add i32 %71, 1
  %73 = load i32, ptr %12, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [64 x i32], ptr %11, i64 0, i64 %74
  store i32 %72, ptr %75, align 4, !tbaa !9
  br label %79

76:                                               ; preds = %35
  %77 = load i32, ptr %12, align 4, !tbaa !9
  %78 = add nsw i32 %77, -1
  store i32 %78, ptr %12, align 4, !tbaa !9
  br label %79

79:                                               ; preds = %76, %45
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load i32, ptr %13, align 4, !tbaa !9
  %82 = zext i32 %81 to i64
  %83 = getelementptr inbounds %struct.Grid, ptr %80, i64 %82
  store ptr %83, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.Grid, ptr %84, i32 0, i32 3
  %86 = load ptr, ptr %85, align 8, !tbaa !15
  store ptr %86, ptr %14, align 8, !tbaa !5
  br label %87

87:                                               ; preds = %117, %94, %79
  %88 = load ptr, ptr %14, align 8, !tbaa !5
  %89 = icmp ne ptr %88, null
  br i1 %89, label %90, label %121

90:                                               ; preds = %87
  %91 = load ptr, ptr %14, align 8, !tbaa !5
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = icmp eq ptr %91, %92
  br i1 %93, label %94, label %98

94:                                               ; preds = %90
  %95 = load ptr, ptr %14, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.Rigid_Body, ptr %95, i32 0, i32 13
  %97 = load ptr, ptr %96, align 8, !tbaa !17
  store ptr %97, ptr %14, align 8, !tbaa !5
  br label %87, !llvm.loop !25

98:                                               ; preds = %90
  %99 = load ptr, ptr %14, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.Rigid_Body, ptr %99, i32 0, i32 11
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.Rigid_Body, ptr %101, i32 0, i32 11
  %103 = call noundef zeroext i1 @_Z21test_mmrect_vs_mmrectRK7Mm_RectS1_(ptr noundef nonnull align 4 dereferenceable(16) %100, ptr noundef nonnull align 4 dereferenceable(16) %102)
  br i1 %103, label %104, label %117

104:                                              ; preds = %98
  %105 = load ptr, ptr %14, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.Rigid_Body, ptr %105, i32 0, i32 1
  %107 = load i16, ptr %106, align 2, !tbaa !27
  %108 = zext i16 %107 to i32
  %109 = or i32 %108, 2
  %110 = trunc i32 %109 to i16
  store i16 %110, ptr %106, align 2, !tbaa !27
  %111 = load ptr, ptr %5, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.Rigid_Body, ptr %111, i32 0, i32 1
  %113 = load i16, ptr %112, align 2, !tbaa !27
  %114 = zext i16 %113 to i32
  %115 = or i32 %114, 2
  %116 = trunc i32 %115 to i16
  store i16 %116, ptr %112, align 2, !tbaa !27
  br label %117

117:                                              ; preds = %104, %98
  %118 = load ptr, ptr %14, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.Rigid_Body, ptr %118, i32 0, i32 13
  %120 = load ptr, ptr %119, align 8, !tbaa !17
  store ptr %120, ptr %14, align 8, !tbaa !5
  br label %87, !llvm.loop !25

121:                                              ; preds = %87
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %32, !llvm.loop !28

122:                                              ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 256, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

declare noundef zeroext i1 @_Z21test_mmrect_vs_mmrectRK7Mm_RectS1_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS5HGrid", !6, i64 0, !10, i64 8, !13, i64 12, !10, i64 16}
!13 = !{!"float", !7, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!16, !6, i64 16}
!16 = !{!"_ZTS4Grid", !7, i64 0, !13, i64 8, !10, i64 12, !6, i64 16}
!17 = !{!18, !6, i64 96}
!18 = !{!"_ZTS10Rigid_Body", !19, i64 0, !20, i64 2, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !7, i64 20, !7, i64 28, !21, i64 36, !10, i64 60, !6, i64 64, !22, i64 72, !23, i64 88, !6, i64 96, !10, i64 104, !10, i64 108}
!19 = !{!"_ZTS15Rigid_Body_Type", !7, i64 0}
!20 = !{!"short", !7, i64 0}
!21 = !{!"_ZTS9Transform", !7, i64 0, !7, i64 8}
!22 = !{!"_ZTS7Mm_Rect", !7, i64 0, !7, i64 8}
!23 = !{!"_ZTS9Entity_Id", !24, i64 0}
!24 = !{!"long", !7, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!18, !20, i64 2}
!28 = distinct !{!28, !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.Grid = type { %union.Vec2, float, i32, ptr }
%union.Vec2 = type { %struct.anon.1 }
%struct.anon.1 = type { float, float }

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z29hgrid_collision_check_objectsP5HGridP10Rigid_Bodyj(ptr nocapture noundef readonly %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca [64 x i32], align 16
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %4) #3
  store i32 %2, ptr %4, align 16, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %1, i64 72
  %9 = getelementptr inbounds i8, ptr %1, i64 2
  br label %11

.loopexit:                                        ; preds = %.backedge, %33
  %10 = icmp sgt i32 %.1, -1
  br i1 %10, label %11, label %46, !llvm.loop !14

11:                                               ; preds = %3, %.loopexit
  %.03440 = phi i32 [ 0, %3 ], [ %.1, %.loopexit ]
  %12 = zext nneg i32 %.03440 to i64
  %13 = getelementptr inbounds [64 x i32], ptr %4, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = shl i32 %14, 2
  %16 = or disjoint i32 %15, 1
  %17 = icmp ult i32 %16, %7
  br i1 %17, label %18, label %31

18:                                               ; preds = %11
  %19 = add i32 %15, 4
  store i32 %19, ptr %13, align 4, !tbaa !13
  %20 = add nuw nsw i32 %.03440, 1
  %21 = or disjoint i32 %15, 3
  %22 = zext nneg i32 %20 to i64
  %23 = getelementptr inbounds [64 x i32], ptr %4, i64 0, i64 %22
  store i32 %21, ptr %23, align 4, !tbaa !13
  %24 = add nuw nsw i32 %.03440, 2
  %25 = or disjoint i32 %15, 2
  %26 = zext nneg i32 %24 to i64
  %27 = getelementptr inbounds [64 x i32], ptr %4, i64 0, i64 %26
  store i32 %25, ptr %27, align 4, !tbaa !13
  %28 = add nuw nsw i32 %.03440, 3
  %29 = zext nneg i32 %28 to i64
  %30 = getelementptr inbounds [64 x i32], ptr %4, i64 0, i64 %29
  store i32 %16, ptr %30, align 4, !tbaa !13
  br label %33

31:                                               ; preds = %11
  %32 = add nsw i32 %.03440, -1
  br label %33

33:                                               ; preds = %31, %18
  %.1 = phi i32 [ %28, %18 ], [ %32, %31 ]
  %34 = zext i32 %14 to i64
  %35 = getelementptr inbounds %struct.Grid, ptr %5, i64 %34, i32 3
  %.037 = load ptr, ptr %35, align 8, !tbaa !16
  %.not38 = icmp eq ptr %.037, null
  br i1 %.not38, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %33, %.backedge
  %.039 = phi ptr [ %.0, %.backedge ], [ %.037, %33 ]
  %36 = icmp eq ptr %.039, %1
  br i1 %36, label %.backedge, label %37

.backedge:                                        ; preds = %37, %40, %.lr.ph
  %.0.in.be = getelementptr inbounds i8, ptr %.039, i64 96
  %.0 = load ptr, ptr %.0.in.be, align 8, !tbaa !16
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !17

37:                                               ; preds = %.lr.ph
  %38 = getelementptr inbounds i8, ptr %.039, i64 72
  %39 = tail call noundef zeroext i1 @_Z21test_mmrect_vs_mmrectRK7Mm_RectS1_(ptr noundef nonnull align 4 dereferenceable(16) %38, ptr noundef nonnull align 4 dereferenceable(16) %8)
  br i1 %39, label %40, label %.backedge

40:                                               ; preds = %37
  %41 = getelementptr inbounds i8, ptr %.039, i64 2
  %42 = load i16, ptr %41, align 2, !tbaa !18
  %43 = or i16 %42, 2
  store i16 %43, ptr %41, align 2, !tbaa !18
  %44 = load i16, ptr %9, align 2, !tbaa !18
  %45 = or i16 %44, 2
  store i16 %45, ptr %9, align 2, !tbaa !18
  br label %.backedge

46:                                               ; preds = %.loopexit
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %4) #3
  ret void
}

declare noundef zeroext i1 @_Z21test_mmrect_vs_mmrectRK7Mm_RectS1_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 = !{!"_ZTS5HGrid", !7, i64 0, !10, i64 8, !11, i64 12, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !15}
!18 = !{!19, !21, i64 2}
!19 = !{!"_ZTS10Rigid_Body", !20, i64 0, !21, i64 2, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !8, i64 20, !8, i64 28, !22, i64 36, !10, i64 60, !7, i64 64, !23, i64 72, !24, i64 88, !7, i64 96, !10, i64 104, !10, i64 108}
!20 = !{!"_ZTS15Rigid_Body_Type", !8, i64 0}
!21 = !{!"short", !8, i64 0}
!22 = !{!"_ZTS9Transform", !8, i64 0, !8, i64 8}
!23 = !{!"_ZTS7Mm_Rect", !8, i64 0, !8, i64 8}
!24 = !{!"_ZTS9Entity_Id", !25, i64 0}
!25 = !{!"long", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass