; LLVM IR from mtsamis/box2d-optimized :: src/particle (b2_particle_system)

; 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.(anonymous namespace)::LightweightPair.17" = type { ptr, i32 }
%struct.b2ParticleBodyContact = type { i32, ptr, ptr, float, %struct.b2Vec2, float }
%struct.b2Vec2 = type { 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: mustprogress uwtable
define dso_local void @_ZN18FixtureParticleSet10InitializeEPK21b2ParticleBodyContactiPKj(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8
  call void @_ZN12_GLOBAL__N_117FixedSetAllocator5ClearEv(ptr noundef nonnull align 8 dereferenceable(32) %15)
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = call noundef i32 @_ZN12_GLOBAL__N_122TypedFixedSetAllocatorINS_15LightweightPairIP9b2FixtureiEEE8AllocateEi(ptr noundef nonnull align 8 dereferenceable(32) %15, i32 noundef %16)
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %76

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %20 = call noundef ptr @_ZN12_GLOBAL__N_122TypedFixedSetAllocatorINS_15LightweightPairIP9b2FixtureiEEE9GetBufferEv(ptr noundef nonnull align 8 dereferenceable(32) %15)
  store ptr %20, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %66, %19
  %22 = load i32, ptr %11, align 4, !tbaa !9
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %69

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %"struct.(anonymous namespace)::LightweightPair.17", ptr %27, i64 %29
  store ptr %30, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.b2ParticleBodyContact, ptr %31, i64 %33
  store ptr %34, ptr %14, align 8, !tbaa !5
  %35 = load ptr, ptr %14, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.b2ParticleBodyContact, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !11
  %38 = icmp eq i32 %37, -1
  br i1 %38, label %49, label %39

39:                                               ; preds = %26
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %14, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.b2ParticleBodyContact, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !11
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %40, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = and i32 %46, 16384
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %50, label %49

49:                                               ; preds = %39, %26
  store i32 4, ptr %12, align 4
  br label %63

50:                                               ; preds = %39
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.b2ParticleBodyContact, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  %54 = load ptr, ptr %13, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.(anonymous namespace)::LightweightPair.17", ptr %54, i32 0, i32 0
  store ptr %53, ptr %55, align 8, !tbaa !16
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.b2ParticleBodyContact, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !11
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = getelementptr inbounds %"struct.(anonymous namespace)::LightweightPair.17", ptr %59, i32 0, i32 1
  store i32 %58, ptr %60, align 8, !tbaa !18
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %12, align 4
  br label %63

63:                                               ; preds = %50, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  %64 = load i32, ptr %12, align 4
  switch i32 %64, label %77 [
    i32 0, label %65
    i32 4, label %66
  ]

65:                                               ; preds = %63
  br label %66

66:                                               ; preds = %65, %63
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %11, align 4, !tbaa !9
  br label %21, !llvm.loop !19

69:                                               ; preds = %25
  %70 = load i32, ptr %10, align 4, !tbaa !9
  call void @_ZN12_GLOBAL__N_117FixedSetAllocator8SetCountEi(ptr noundef nonnull align 8 dereferenceable(32) %15, i32 noundef %70)
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = load i32, ptr %10, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds %"struct.(anonymous namespace)::LightweightPair.17", ptr %72, i64 %74
  call void @_ZSt4sortIPN12_GLOBAL__N_115LightweightPairIP9b2FixtureiEEPFbRKS4_S7_EEvT_SA_T0_(ptr noundef %71, ptr noundef %75, ptr noundef @_ZN12_GLOBAL__N_115LightweightPairIP9b2FixtureiE7CompareERKS3_S5_)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %76

76:                                               ; preds = %69, %4
  ret void

77:                                               ; preds = %63
  unreachable
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN12_GLOBAL__N_117FixedSetAllocator5ClearEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZN12_GLOBAL__N_122TypedFixedSetAllocatorINS_15LightweightPairIP9b2FixtureiEEE8AllocateEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN12_GLOBAL__N_122TypedFixedSetAllocatorINS_15LightweightPairIP9b2FixtureiEEE9GetBufferEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN12_GLOBAL__N_117FixedSetAllocator8SetCountEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @_ZSt4sortIPN12_GLOBAL__N_115LightweightPairIP9b2FixtureiEEPFbRKS4_S7_EEvT_SA_T0_(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN12_GLOBAL__N_115LightweightPairIP9b2FixtureiE7CompareERKS3_S5_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #2 align 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 = { mustprogress 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 = { inlinehint 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS21b2ParticleBodyContact", !10, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !14, i64 28, !13, i64 36}
!13 = !{!"float", !7, i64 0}
!14 = !{!"_ZTS6b2Vec2", !13, i64 0, !13, i64 4}
!15 = !{!12, !6, i64 16}
!16 = !{!17, !6, i64 0}
!17 = !{!"_ZTSN12_GLOBAL__N_115LightweightPairIP9b2FixtureiEE", !6, i64 0, !10, i64 8}
!18 = !{!17, !10, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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.(anonymous namespace)::LightweightPair.17" = type { ptr, i32 }
%struct.b2ParticleBodyContact = type { i32, ptr, ptr, float, %struct.b2Vec2, float }
%struct.b2Vec2 = type { float, float }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN18FixtureParticleSet10InitializeEPK21b2ParticleBodyContactiPKj(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 align 2 {
  tail call void @_ZN12_GLOBAL__N_117FixedSetAllocator5ClearEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %5 = tail call noundef i32 @_ZN12_GLOBAL__N_122TypedFixedSetAllocatorINS_15LightweightPairIP9b2FixtureiEEE8AllocateEi(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %2)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %26, label %6

6:                                                ; preds = %4
  %7 = tail call noundef ptr @_ZN12_GLOBAL__N_122TypedFixedSetAllocatorINS_15LightweightPairIP9b2FixtureiEEE9GetBufferEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %8 = icmp sgt i32 %2, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %6
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %25, %6
  %.0.lcssa = phi i32 [ 0, %6 ], [ %.1, %25 ]
  tail call void @_ZN12_GLOBAL__N_117FixedSetAllocator8SetCountEi(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %.0.lcssa)
  %9 = sext i32 %.0.lcssa to i64
  %10 = getelementptr inbounds %"struct.(anonymous namespace)::LightweightPair.17", ptr %7, i64 %9
  tail call void @_ZSt4sortIPN12_GLOBAL__N_115LightweightPairIP9b2FixtureiEEPFbRKS4_S7_EEvT_SA_T0_(ptr noundef %7, ptr noundef %10, ptr noundef nonnull @_ZN12_GLOBAL__N_115LightweightPairIP9b2FixtureiE7CompareERKS3_S5_)
  br label %26

.lr.ph:                                           ; preds = %.lr.ph.preheader, %25
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %25 ]
  %.024 = phi i32 [ 0, %.lr.ph.preheader ], [ %.1, %25 ]
  %11 = getelementptr inbounds %"struct.(anonymous namespace)::LightweightPair.17", ptr %7, i64 %indvars.iv
  %12 = getelementptr inbounds %struct.b2ParticleBodyContact, ptr %1, i64 %indvars.iv
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = icmp eq i32 %13, -1
  br i1 %14, label %25, label %15

15:                                               ; preds = %.lr.ph
  %16 = sext i32 %13 to i64
  %17 = getelementptr inbounds i32, ptr %3, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %19 = and i32 %18, 16384
  %.not22 = icmp eq i32 %19, 0
  br i1 %.not22, label %25, label %20

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %12, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  store ptr %22, ptr %11, align 8, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %11, i64 8
  store i32 %13, ptr %23, align 8, !tbaa !17
  %24 = add nsw i32 %.024, 1
  br label %25

25:                                               ; preds = %.lr.ph, %15, %20
  %.1 = phi i32 [ %24, %20 ], [ %.024, %15 ], [ %.024, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

26:                                               ; preds = %._crit_edge, %4
  ret void
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN12_GLOBAL__N_117FixedSetAllocator5ClearEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZN12_GLOBAL__N_122TypedFixedSetAllocatorINS_15LightweightPairIP9b2FixtureiEEE8AllocateEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN12_GLOBAL__N_122TypedFixedSetAllocatorINS_15LightweightPairIP9b2FixtureiEEE9GetBufferEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN12_GLOBAL__N_117FixedSetAllocator8SetCountEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @_ZSt4sortIPN12_GLOBAL__N_115LightweightPairIP9b2FixtureiEEPFbRKS4_S7_EEvT_SA_T0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN12_GLOBAL__N_115LightweightPairIP9b2FixtureiE7CompareERKS3_S5_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

attributes #0 = { 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 #1 = { mustprogress 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 = { inlinehint 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" }

!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 = !{!"_ZTS21b2ParticleBodyContact", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !12, i64 28, !11, i64 36}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!"_ZTS6b2Vec2", !11, i64 0, !11, i64 4}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !10, i64 16}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTSN12_GLOBAL__N_115LightweightPairIP9b2FixtureiEE", !10, i64 0, !7, i64 8}
!17 = !{!16, !7, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass