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

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

%union.Vec2 = type { %struct.anon.1 }
%struct.anon.1 = type { float, float }
%struct.Grid = type { %union.Vec2, float, i32, ptr }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z15initialize_gridP4Gridjjf4Vec2(ptr noundef %0, i32 noundef %1, i32 noundef %2, float noundef %3, <2 x float> %4) #2 {
  %6 = alloca %union.Vec2, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca float, align 4
  %11 = alloca ptr, align 8
  %12 = alloca %union.Vec2, align 4
  %13 = alloca %union.Vec2, align 4
  %14 = alloca %union.Vec2, align 4
  %15 = alloca %union.Vec2, align 4
  %16 = alloca %union.Vec2, align 4
  %17 = alloca %union.Vec2, align 4
  %18 = alloca %union.Vec2, align 4
  %19 = alloca %union.Vec2, align 4
  %20 = alloca %union.Vec2, align 4
  %21 = alloca %union.Vec2, align 4
  %22 = getelementptr inbounds %union.Vec2, ptr %6, i32 0, i32 0
  store <2 x float> %4, ptr %22, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store float %3, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds %struct.Grid, ptr %23, i64 %25
  store ptr %26, ptr %11, align 8, !tbaa !5
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Grid, ptr %27, i32 0, i32 2
  store i32 0, ptr %28, align 4, !tbaa !13
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Grid, ptr %29, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %30, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !15
  %31 = load float, ptr %10, align 4, !tbaa !11
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Grid, ptr %32, i32 0, i32 1
  store float %31, ptr %33, align 8, !tbaa !17
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Grid, ptr %34, i32 0, i32 3
  store ptr null, ptr %35, align 8, !tbaa !18
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = mul i32 %36, 4
  %38 = add i32 %37, 1
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = icmp ult i32 %38, %39
  br i1 %40, label %41, label %106

41:                                               ; preds = %5
  %42 = load float, ptr %10, align 4, !tbaa !11
  %43 = fpext float %42 to double
  %44 = fmul double %43, 5.000000e-01
  %45 = fptrunc double %44 to float
  store float %45, ptr %10, align 4, !tbaa !11
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = mul i32 %47, 4
  %49 = add i32 %48, 1
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = load float, ptr %10, align 4, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !15
  %52 = load float, ptr %10, align 4, !tbaa !11
  %53 = call <2 x float> @_Z4vec2ff(float noundef 0.000000e+00, float noundef %52)
  %54 = getelementptr inbounds %union.Vec2, ptr %14, i32 0, i32 0
  store <2 x float> %53, ptr %54, align 4
  %55 = getelementptr inbounds %union.Vec2, ptr %13, i32 0, i32 0
  %56 = load <2 x float>, ptr %55, align 4
  %57 = getelementptr inbounds %union.Vec2, ptr %14, i32 0, i32 0
  %58 = load <2 x float>, ptr %57, align 4
  %59 = call <2 x float> @_Zpl4Vec2S_(<2 x float> %56, <2 x float> %58)
  %60 = getelementptr inbounds %union.Vec2, ptr %12, i32 0, i32 0
  store <2 x float> %59, ptr %60, align 4
  %61 = getelementptr inbounds %union.Vec2, ptr %12, i32 0, i32 0
  %62 = load <2 x float>, ptr %61, align 4
  call void @_Z15initialize_gridP4Gridjjf4Vec2(ptr noundef %46, i32 noundef %49, i32 noundef %50, float noundef %51, <2 x float> %62)
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = mul i32 %64, 4
  %66 = add i32 %65, 2
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = load float, ptr %10, align 4, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !15
  %69 = load float, ptr %10, align 4, !tbaa !11
  %70 = load float, ptr %10, align 4, !tbaa !11
  %71 = call <2 x float> @_Z4vec2ff(float noundef %69, float noundef %70)
  %72 = getelementptr inbounds %union.Vec2, ptr %17, i32 0, i32 0
  store <2 x float> %71, ptr %72, align 4
  %73 = getelementptr inbounds %union.Vec2, ptr %16, i32 0, i32 0
  %74 = load <2 x float>, ptr %73, align 4
  %75 = getelementptr inbounds %union.Vec2, ptr %17, i32 0, i32 0
  %76 = load <2 x float>, ptr %75, align 4
  %77 = call <2 x float> @_Zpl4Vec2S_(<2 x float> %74, <2 x float> %76)
  %78 = getelementptr inbounds %union.Vec2, ptr %15, i32 0, i32 0
  store <2 x float> %77, ptr %78, align 4
  %79 = getelementptr inbounds %union.Vec2, ptr %15, i32 0, i32 0
  %80 = load <2 x float>, ptr %79, align 4
  call void @_Z15initialize_gridP4Gridjjf4Vec2(ptr noundef %63, i32 noundef %66, i32 noundef %67, float noundef %68, <2 x float> %80)
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = load i32, ptr %8, align 4, !tbaa !9
  %83 = mul i32 %82, 4
  %84 = add i32 %83, 3
  %85 = load i32, ptr %9, align 4, !tbaa !9
  %86 = load float, ptr %10, align 4, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %18, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !15
  %87 = getelementptr inbounds %union.Vec2, ptr %18, i32 0, i32 0
  %88 = load <2 x float>, ptr %87, align 4
  call void @_Z15initialize_gridP4Gridjjf4Vec2(ptr noundef %81, i32 noundef %84, i32 noundef %85, float noundef %86, <2 x float> %88)
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = load i32, ptr %8, align 4, !tbaa !9
  %91 = mul i32 %90, 4
  %92 = add i32 %91, 4
  %93 = load i32, ptr %9, align 4, !tbaa !9
  %94 = load float, ptr %10, align 4, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %20, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !15
  %95 = load float, ptr %10, align 4, !tbaa !11
  %96 = call <2 x float> @_Z4vec2ff(float noundef %95, float noundef 0.000000e+00)
  %97 = getelementptr inbounds %union.Vec2, ptr %21, i32 0, i32 0
  store <2 x float> %96, ptr %97, align 4
  %98 = getelementptr inbounds %union.Vec2, ptr %20, i32 0, i32 0
  %99 = load <2 x float>, ptr %98, align 4
  %100 = getelementptr inbounds %union.Vec2, ptr %21, i32 0, i32 0
  %101 = load <2 x float>, ptr %100, align 4
  %102 = call <2 x float> @_Zpl4Vec2S_(<2 x float> %99, <2 x float> %101)
  %103 = getelementptr inbounds %union.Vec2, ptr %19, i32 0, i32 0
  store <2 x float> %102, ptr %103, align 4
  %104 = getelementptr inbounds %union.Vec2, ptr %19, i32 0, i32 0
  %105 = load <2 x float>, ptr %104, align 4
  call void @_Z15initialize_gridP4Gridjjf4Vec2(ptr noundef %89, i32 noundef %92, i32 noundef %93, float noundef %94, <2 x float> %105)
  br label %106

106:                                              ; preds = %41, %5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_Zpl4Vec2S_(<2 x float>, <2 x float>) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local <2 x float> @_Z4vec2ff(float noundef, float noundef) #4

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { inlinehint mustprogress uwtable "min-legal-vector-width"="64" "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 mustprogress nounwind uwtable "min-legal-vector-width"="64" "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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !10, i64 12}
!14 = !{!"_ZTS4Grid", !7, i64 0, !12, i64 8, !10, i64 12, !6, i64 16}
!15 = !{i64 0, i64 8, !16}
!16 = !{!7, !7, i64 0}
!17 = !{!14, !12, i64 8}
!18 = !{!14, !6, 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.Grid = type { %union.Vec2, float, i32, ptr }
%union.Vec2 = type { %struct.anon.1 }
%struct.anon.1 = type { float, float }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z15initialize_gridP4Gridjjf4Vec2(ptr noundef %0, i32 noundef %1, i32 noundef %2, float noundef %3, <2 x float> %4) local_unnamed_addr #0 {
  %6 = zext i32 %1 to i64
  %7 = getelementptr inbounds %struct.Grid, ptr %0, i64 %6
  %8 = getelementptr inbounds i8, ptr %7, i64 12
  store i32 0, ptr %8, align 4, !tbaa !5
  store <2 x float> %4, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %7, i64 8
  store float %3, ptr %9, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %7, i64 16
  store ptr null, ptr %10, align 8, !tbaa !14
  %11 = shl i32 %1, 2
  %12 = or disjoint i32 %11, 1
  %13 = icmp ult i32 %12, %2
  br i1 %13, label %tailrecurse, label %tailrecurse._crit_edge

tailrecurse:                                      ; preds = %5, %tailrecurse
  %14 = phi i32 [ %32, %tailrecurse ], [ %12, %5 ]
  %15 = phi i32 [ %31, %tailrecurse ], [ %11, %5 ]
  %.tr4648 = phi <2 x float> [ %25, %tailrecurse ], [ %4, %5 ]
  %.tr4547 = phi float [ %16, %tailrecurse ], [ %3, %5 ]
  %16 = fmul float %.tr4547, 5.000000e-01
  %17 = tail call <2 x float> @_Z4vec2ff(float noundef 0.000000e+00, float noundef %16)
  %18 = tail call <2 x float> @_Zpl4Vec2S_(<2 x float> %.tr4648, <2 x float> %17)
  tail call void @_Z15initialize_gridP4Gridjjf4Vec2(ptr noundef nonnull %0, i32 noundef %14, i32 noundef %2, float noundef %16, <2 x float> %18)
  %19 = or disjoint i32 %15, 2
  %20 = tail call <2 x float> @_Z4vec2ff(float noundef %16, float noundef %16)
  %21 = tail call <2 x float> @_Zpl4Vec2S_(<2 x float> %.tr4648, <2 x float> %20)
  tail call void @_Z15initialize_gridP4Gridjjf4Vec2(ptr noundef nonnull %0, i32 noundef %19, i32 noundef %2, float noundef %16, <2 x float> %21)
  %22 = or disjoint i32 %15, 3
  tail call void @_Z15initialize_gridP4Gridjjf4Vec2(ptr noundef nonnull %0, i32 noundef %22, i32 noundef %2, float noundef %16, <2 x float> %.tr4648)
  %23 = add i32 %15, 4
  %24 = tail call <2 x float> @_Z4vec2ff(float noundef %16, float noundef 0.000000e+00)
  %25 = tail call <2 x float> @_Zpl4Vec2S_(<2 x float> %.tr4648, <2 x float> %24)
  %26 = zext i32 %23 to i64
  %27 = getelementptr inbounds %struct.Grid, ptr %0, i64 %26
  %28 = getelementptr inbounds i8, ptr %27, i64 12
  store i32 0, ptr %28, align 4, !tbaa !5
  store <2 x float> %25, ptr %27, align 8, !tbaa !12
  %29 = getelementptr inbounds i8, ptr %27, i64 8
  store float %16, ptr %29, align 8, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %27, i64 16
  store ptr null, ptr %30, align 8, !tbaa !14
  %31 = shl i32 %23, 2
  %32 = or disjoint i32 %31, 1
  %33 = icmp ult i32 %32, %2
  br i1 %33, label %tailrecurse, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_Zpl4Vec2S_(<2 x float>, <2 x float>) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local <2 x float> @_Z4vec2ff(float noundef, float noundef) local_unnamed_addr #2

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { inlinehint mustprogress uwtable "min-legal-vector-width"="64" "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 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="64" "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" }

!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 12}
!6 = !{!"_ZTS4Grid", !7, i64 0, !9, i64 8, !10, i64 12, !11, i64 16}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"float", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !9, i64 8}
!14 = !{!6, !11, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass