; 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.b2ParticleSystem::Proxy" = type { i32, i32 }

; 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN16b2ParticleSystem19ProxyBufferHasIndexEiPKNS_5ProxyEi(i32 noundef, ptr noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN16b2ParticleSystem21NumProxiesWithSameTagEPKNS_5ProxyES2_i(ptr noundef, ptr noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN16b2ParticleSystem22AreProxyBuffersTheSameERK16b2GrowableBufferINS_5ProxyEES4_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) #2 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call noundef i32 @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24) %11)
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call noundef i32 @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24) %13)
  %15 = icmp ne i32 %12, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  br label %81

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

18:                                               ; preds = %77, %17
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call noundef i32 @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24) %20)
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  store i32 2, ptr %7, align 4
  br label %78

24:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEEixEi(ptr noundef nonnull align 8 dereferenceable(24) %25, i32 noundef %26)
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEEixEi(ptr noundef nonnull align 8 dereferenceable(24) %28, i32 noundef %29)
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call noundef i32 @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24) %31)
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = sub nsw i32 %32, %33
  %35 = call noundef i32 @_ZN16b2ParticleSystem21NumProxiesWithSameTagEPKNS_5ProxyES2_i(ptr noundef %27, ptr noundef %30, i32 noundef %34)
  store i32 %35, ptr %8, align 4, !tbaa !9
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %24
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %75

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

40:                                               ; preds = %66, %39
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  store i32 4, ptr %7, align 4
  br label %69

45:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = add nsw i32 %47, %48
  %50 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEEixEi(ptr noundef nonnull align 8 dereferenceable(24) %46, i32 noundef %49)
  %51 = getelementptr inbounds %"struct.b2ParticleSystem::Proxy", ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i32, ptr %6, align 4, !tbaa !9
  %55 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEEixEi(ptr noundef nonnull align 8 dereferenceable(24) %53, i32 noundef %54)
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = call noundef zeroext i1 @_ZN16b2ParticleSystem19ProxyBufferHasIndexEiPKNS_5ProxyEi(i32 noundef %52, ptr noundef %55, i32 noundef %56)
  %58 = zext i1 %57 to i8
  store i8 %58, ptr %10, align 1, !tbaa !13
  %59 = load i8, ptr %10, align 1, !tbaa !13, !range !15, !noundef !16
  %60 = trunc i8 %59 to i1
  br i1 %60, label %62, label %61

61:                                               ; preds = %45
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %63

62:                                               ; preds = %45
  store i32 0, ptr %7, align 4
  br label %63

63:                                               ; preds = %62, %61
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  %64 = load i32, ptr %7, align 4
  switch i32 %64, label %69 [
    i32 0, label %65
  ]

65:                                               ; preds = %63
  br label %66

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

69:                                               ; preds = %63, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %70 = load i32, ptr %7, align 4
  switch i32 %70, label %75 [
    i32 4, label %71
  ]

71:                                               ; preds = %69
  %72 = load i32, ptr %8, align 4, !tbaa !9
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = add nsw i32 %73, %72
  store i32 %74, ptr %6, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  br label %75

75:                                               ; preds = %71, %69, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %76 = load i32, ptr %7, align 4
  switch i32 %76, label %78 [
    i32 0, label %77
  ]

77:                                               ; preds = %75
  br label %18, !llvm.loop !19

78:                                               ; preds = %75, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %79 = load i32, ptr %7, align 4
  switch i32 %79, label %83 [
    i32 2, label %80
    i32 1, label %81
  ]

80:                                               ; preds = %78
  store i1 true, ptr %3, align 1
  br label %81

81:                                               ; preds = %80, %78, %16
  %82 = load i1, ptr %3, align 1
  ret i1 %82

83:                                               ; preds = %78
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEEixEi(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !10, i64 0}
!12 = !{!"_ZTSN16b2ParticleSystem5ProxyE", !10, i64 0, !10, i64 4}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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 uwtable
declare dso_local noundef zeroext i1 @_ZN16b2ParticleSystem19ProxyBufferHasIndexEiPKNS_5ProxyEi(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN16b2ParticleSystem21NumProxiesWithSameTagEPKNS_5ProxyES2_i(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN16b2ParticleSystem22AreProxyBuffersTheSameERK16b2GrowableBufferINS_5ProxyEES4_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef i32 @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %4 = tail call noundef i32 @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %.not = icmp eq i32 %3, %4
  br i1 %.not, label %.preheader47, label %.thread

.preheader47:                                     ; preds = %2
  %5 = tail call noundef i32 @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %6 = icmp slt i32 %5, 1
  br i1 %6, label %.thread, label %.lr.ph52

.lr.ph52:                                         ; preds = %.preheader47, %._crit_edge
  %.03051 = phi i32 [ %20, %._crit_edge ], [ 0, %.preheader47 ]
  %7 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEEixEi(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %.03051)
  %8 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEEixEi(ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %.03051)
  %9 = tail call noundef i32 @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %10 = sub nsw i32 %9, %.03051
  %11 = tail call noundef i32 @_ZN16b2ParticleSystem21NumProxiesWithSameTagEPKNS_5ProxyES2_i(ptr noundef nonnull %7, ptr noundef nonnull %8, i32 noundef %10)
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %.preheader, label %.thread

.preheader:                                       ; preds = %.lr.ph52
  %.not3749 = icmp sgt i32 %11, 0
  br i1 %.not3749, label %.lr.ph, label %._crit_edge

13:                                               ; preds = %.lr.ph
  %14 = add nuw nsw i32 %.02950, 1
  %exitcond.not = icmp eq i32 %14, %11
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader, %13
  %.02950 = phi i32 [ %14, %13 ], [ 0, %.preheader ]
  %15 = add nsw i32 %.02950, %.03051
  %16 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEEixEi(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %15)
  %17 = load i32, ptr %16, align 4, !tbaa !7
  %18 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEEixEi(ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %.03051)
  %19 = tail call noundef zeroext i1 @_ZN16b2ParticleSystem19ProxyBufferHasIndexEiPKNS_5ProxyEi(i32 noundef %17, ptr noundef nonnull %18, i32 noundef %11)
  br i1 %19, label %13, label %.thread

._crit_edge:                                      ; preds = %13, %.preheader
  %20 = add nsw i32 %11, %.03051
  %21 = tail call noundef i32 @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %.not56 = icmp slt i32 %20, %21
  br i1 %.not56, label %.lr.ph52, label %.thread, !llvm.loop !12

.thread:                                          ; preds = %.lr.ph52, %._crit_edge, %.lr.ph, %.preheader47, %2
  %.6 = phi i1 [ false, %2 ], [ true, %.preheader47 ], [ false, %.lr.ph ], [ false, %.lr.ph52 ], [ %12, %._crit_edge ]
  ret i1 %.6
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEE8GetCountEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNK16b2GrowableBufferIN16b2ParticleSystem5ProxyEEixEi(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) local_unnamed_addr #0 align 2

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 0}
!8 = !{!"_ZTSN16b2ParticleSystem5ProxyE", !9, i64 0, !9, i64 4}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = distinct !{!12, !6}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass