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

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

%class.b2ParticleGroup = type { ptr, i32, i32, i32, float, ptr, ptr, i32, float, float, %struct.b2Vec2, %struct.b2Vec2, float, %struct.b2Transform, ptr }
%struct.b2Vec2 = type { float, float }
%struct.b2Transform = type { %struct.b2Vec2, %struct.b2Rot }
%struct.b2Rot = type { float, float }
%class.b2ParticleSystem = type { i8, i32, i32, i8, i32, i8, i8, i32, float, float, float, float, i32, i32, %class.b2SlabAllocator, %"struct.b2ParticleSystem::UserOverridableBuffer", %"struct.b2ParticleSystem::UserOverridableBuffer.0", %"struct.b2ParticleSystem::UserOverridableBuffer.2", %"struct.b2ParticleSystem::UserOverridableBuffer.2", ptr, ptr, ptr, ptr, ptr, ptr, %"struct.b2ParticleSystem::UserOverridableBuffer.4", ptr, %"struct.b2ParticleSystem::UserOverridableBuffer.6", i32, [4 x i8], %"struct.b2ParticleSystem::UserOverridableBuffer.8", %"struct.b2ParticleSystem::UserOverridableBuffer.8", %"struct.b2ParticleSystem::UserOverridableBuffer.8", %class.b2GrowableBuffer, %class.b2GrowableBuffer.10, %class.b2GrowableBuffer.11, %class.b2GrowableBuffer.12, %class.b2GrowableBuffer.13, %class.b2GrowableBuffer.14, %"struct.b2ParticleSystem::UserOverridableBuffer.8", %"struct.b2ParticleSystem::UserOverridableBuffer.8", i64, i8, i32, ptr, %struct.b2ParticleSystemDef, ptr, ptr, ptr }
%class.b2SlabAllocator = type { %class.b2TrackedBlockAllocator, i32, %class.b2TypedFreeList }
%class.b2TrackedBlockAllocator = type { %class.b2TypedIntrusiveListNode }
%class.b2TypedIntrusiveListNode = type { %class.b2IntrusiveListNode }
%class.b2IntrusiveListNode = type { ptr, ptr }
%class.b2TypedFreeList = type { %class.b2FreeList }
%class.b2FreeList = type { %class.b2IntrusiveListNode, %class.b2IntrusiveListNode }
%"struct.b2ParticleSystem::UserOverridableBuffer" = type <{ ptr, i32, [4 x i8] }>
%"struct.b2ParticleSystem::UserOverridableBuffer.0" = type <{ ptr, i32, [4 x i8] }>
%"struct.b2ParticleSystem::UserOverridableBuffer.2" = type <{ ptr, i32, [4 x i8] }>
%"struct.b2ParticleSystem::UserOverridableBuffer.4" = type <{ ptr, i32, [4 x i8] }>
%"struct.b2ParticleSystem::UserOverridableBuffer.6" = type <{ ptr, i32, [4 x i8] }>
%class.b2GrowableBuffer = type { ptr, i32, i32, ptr }
%class.b2GrowableBuffer.10 = type { ptr, i32, i32, ptr }
%class.b2GrowableBuffer.11 = type { ptr, i32, i32, ptr }
%class.b2GrowableBuffer.12 = type { ptr, i32, i32, ptr }
%class.b2GrowableBuffer.13 = type { ptr, i32, i32, ptr }
%class.b2GrowableBuffer.14 = type { ptr, i32, i32, ptr }
%"struct.b2ParticleSystem::UserOverridableBuffer.8" = type <{ ptr, i32, [4 x i8] }>
%struct.b2ParticleSystemDef = type { i8, float, float, float, i32, float, float, float, float, float, float, float, float, float, float, float, float, i32, float, i8, 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 @_ZN16b2ParticleSystem13SetGroupFlagsEP15b2ParticleGroupj(ptr noundef nonnull align 8 dereferenceable(632) %0, ptr noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = 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
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %class.b2ParticleGroup, ptr %9, i32 0, i32 3
  store ptr %10, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = xor i32 %12, %13
  %15 = and i32 %14, 1
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %3
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = or i32 %18, 16
  store i32 %19, ptr %6, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %17, %3
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = xor i32 %23, -1
  %25 = and i32 %22, %24
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %20
  %28 = getelementptr inbounds %class.b2ParticleSystem, ptr %8, i32 0, i32 5
  store i8 1, ptr %28, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %27, %20
  %30 = getelementptr inbounds %class.b2ParticleSystem, ptr %8, i32 0, i32 4
  %31 = load i32, ptr %30, align 8, !tbaa !35
  %32 = xor i32 %31, -1
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = and i32 %32, %33
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %50

36:                                               ; preds = %29
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = and i32 %37, 1
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %45

40:                                               ; preds = %36
  %41 = getelementptr inbounds %class.b2ParticleSystem, ptr %8, i32 0, i32 24
  %42 = load ptr, ptr %41, align 8, !tbaa !36
  %43 = call noundef ptr @_ZN16b2ParticleSystem13RequestBufferIfEEPT_S2_(ptr noundef nonnull align 8 dereferenceable(632) %8, ptr noundef %42)
  %44 = getelementptr inbounds %class.b2ParticleSystem, ptr %8, i32 0, i32 24
  store ptr %43, ptr %44, align 8, !tbaa !36
  br label %45

45:                                               ; preds = %40, %36
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = getelementptr inbounds %class.b2ParticleSystem, ptr %8, i32 0, i32 4
  %48 = load i32, ptr %47, align 8, !tbaa !35
  %49 = or i32 %48, %46
  store i32 %49, ptr %47, align 8, !tbaa !35
  br label %50

50:                                               ; preds = %45, %29
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %51, ptr %52, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN16b2ParticleSystem13RequestBufferIfEEPT_S2_(ptr noundef nonnull align 8 dereferenceable(632), ptr noundef) #1 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 = { 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, !13, i64 20}
!12 = !{!"_ZTS16b2ParticleSystem", !13, i64 0, !10, i64 4, !10, i64 8, !13, i64 12, !10, i64 16, !13, i64 20, !13, i64 21, !10, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !14, i64 40, !10, i64 44, !10, i64 48, !15, i64 56, !21, i64 112, !22, i64 128, !23, i64 144, !23, i64 160, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !24, i64 224, !6, i64 240, !25, i64 248, !10, i64 264, !26, i64 272, !26, i64 288, !26, i64 304, !27, i64 320, !28, i64 344, !29, i64 368, !30, i64 392, !31, i64 416, !32, i64 440, !26, i64 464, !26, i64 480, !33, i64 496, !13, i64 504, !10, i64 508, !6, i64 512, !34, i64 520, !6, i64 608, !6, i64 616, !6, i64 624}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!"_ZTS15b2SlabAllocatorI16b2ParticleHandleE", !16, i64 0, !10, i64 16, !19, i64 24}
!16 = !{!"_ZTS23b2TrackedBlockAllocator", !17, i64 0}
!17 = !{!"_ZTS24b2TypedIntrusiveListNodeI14b2TrackedBlockE", !18, i64 0}
!18 = !{!"_ZTS19b2IntrusiveListNode", !6, i64 0, !6, i64 8}
!19 = !{!"_ZTS15b2TypedFreeListI16b2ParticleHandleE", !20, i64 0}
!20 = !{!"_ZTS10b2FreeList", !18, i64 0, !18, i64 16}
!21 = !{!"_ZTSN16b2ParticleSystem21UserOverridableBufferIP16b2ParticleHandleEE", !6, i64 0, !10, i64 8}
!22 = !{!"_ZTSN16b2ParticleSystem21UserOverridableBufferIjEE", !6, i64 0, !10, i64 8}
!23 = !{!"_ZTSN16b2ParticleSystem21UserOverridableBufferI6b2Vec2EE", !6, i64 0, !10, i64 8}
!24 = !{!"_ZTSN16b2ParticleSystem21UserOverridableBufferI15b2ParticleColorEE", !6, i64 0, !10, i64 8}
!25 = !{!"_ZTSN16b2ParticleSystem21UserOverridableBufferIPvEE", !6, i64 0, !10, i64 8}
!26 = !{!"_ZTSN16b2ParticleSystem21UserOverridableBufferIiEE", !6, i64 0, !10, i64 8}
!27 = !{!"_ZTS16b2GrowableBufferIiE", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16}
!28 = !{!"_ZTS16b2GrowableBufferIN16b2ParticleSystem5ProxyEE", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16}
!29 = !{!"_ZTS16b2GrowableBufferI17b2ParticleContactE", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16}
!30 = !{!"_ZTS16b2GrowableBufferI21b2ParticleBodyContactE", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16}
!31 = !{!"_ZTS16b2GrowableBufferI14b2ParticlePairE", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16}
!32 = !{!"_ZTS16b2GrowableBufferI15b2ParticleTriadE", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16}
!33 = !{!"long long", !7, i64 0}
!34 = !{!"_ZTS19b2ParticleSystemDef", !13, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !10, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !14, i64 40, !14, i64 44, !14, i64 48, !14, i64 52, !14, i64 56, !14, i64 60, !14, i64 64, !10, i64 68, !14, i64 72, !13, i64 76, !14, i64 80}
!35 = !{!12, !10, i64 16}
!36 = !{!12, !6, i64 216}


; 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 uwtable
define dso_local void @_ZN16b2ParticleSystem13SetGroupFlagsEP15b2ParticleGroupj(ptr noundef nonnull align 8 dereferenceable(632) %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = xor i32 %5, %2
  %7 = shl i32 %6, 4
  %8 = and i32 %7, 16
  %spec.select = or i32 %8, %2
  %9 = xor i32 %spec.select, -1
  %10 = and i32 %5, %9
  %.not11 = icmp eq i32 %10, 0
  br i1 %.not11, label %13, label %11

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 20
  store i8 1, ptr %12, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %11, %3
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load i32, ptr %14, align 8, !tbaa !34
  %16 = xor i32 %15, -1
  %17 = and i32 %spec.select, %16
  %.not12 = icmp eq i32 %17, 0
  br i1 %.not12, label %27, label %18

18:                                               ; preds = %13
  %19 = and i32 %2, 1
  %.not13 = icmp eq i32 %19, 0
  br i1 %.not13, label %24, label %20

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %0, i64 216
  %22 = load ptr, ptr %21, align 8, !tbaa !35
  %23 = tail call noundef ptr @_ZN16b2ParticleSystem13RequestBufferIfEEPT_S2_(ptr noundef nonnull align 8 dereferenceable(632) %0, ptr noundef %22)
  store ptr %23, ptr %21, align 8, !tbaa !35
  %.pre = load i32, ptr %14, align 8, !tbaa !34
  br label %24

24:                                               ; preds = %20, %18
  %25 = phi i32 [ %.pre, %20 ], [ %15, %18 ]
  %26 = or i32 %25, %spec.select
  store i32 %26, ptr %14, align 8, !tbaa !34
  br label %27

27:                                               ; preds = %24, %13
  store i32 %spec.select, ptr %4, align 4, !tbaa !5
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN16b2ParticleSystem13RequestBufferIfEEPT_S2_(ptr noundef nonnull align 8 dereferenceable(632), ptr noundef) local_unnamed_addr #0 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 20}
!10 = !{!"_ZTS16b2ParticleSystem", !11, i64 0, !6, i64 4, !6, i64 8, !11, i64 12, !6, i64 16, !11, i64 20, !11, i64 21, !6, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !6, i64 44, !6, i64 48, !13, i64 56, !20, i64 112, !21, i64 128, !22, i64 144, !22, i64 160, !17, i64 176, !17, i64 184, !17, i64 192, !17, i64 200, !17, i64 208, !17, i64 216, !23, i64 224, !17, i64 240, !24, i64 248, !6, i64 264, !25, i64 272, !25, i64 288, !25, i64 304, !26, i64 320, !27, i64 344, !28, i64 368, !29, i64 392, !30, i64 416, !31, i64 440, !25, i64 464, !25, i64 480, !32, i64 496, !11, i64 504, !6, i64 508, !17, i64 512, !33, i64 520, !17, i64 608, !17, i64 616, !17, i64 624}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!"_ZTS15b2SlabAllocatorI16b2ParticleHandleE", !14, i64 0, !6, i64 16, !18, i64 24}
!14 = !{!"_ZTS23b2TrackedBlockAllocator", !15, i64 0}
!15 = !{!"_ZTS24b2TypedIntrusiveListNodeI14b2TrackedBlockE", !16, i64 0}
!16 = !{!"_ZTS19b2IntrusiveListNode", !17, i64 0, !17, i64 8}
!17 = !{!"any pointer", !7, i64 0}
!18 = !{!"_ZTS15b2TypedFreeListI16b2ParticleHandleE", !19, i64 0}
!19 = !{!"_ZTS10b2FreeList", !16, i64 0, !16, i64 16}
!20 = !{!"_ZTSN16b2ParticleSystem21UserOverridableBufferIP16b2ParticleHandleEE", !17, i64 0, !6, i64 8}
!21 = !{!"_ZTSN16b2ParticleSystem21UserOverridableBufferIjEE", !17, i64 0, !6, i64 8}
!22 = !{!"_ZTSN16b2ParticleSystem21UserOverridableBufferI6b2Vec2EE", !17, i64 0, !6, i64 8}
!23 = !{!"_ZTSN16b2ParticleSystem21UserOverridableBufferI15b2ParticleColorEE", !17, i64 0, !6, i64 8}
!24 = !{!"_ZTSN16b2ParticleSystem21UserOverridableBufferIPvEE", !17, i64 0, !6, i64 8}
!25 = !{!"_ZTSN16b2ParticleSystem21UserOverridableBufferIiEE", !17, i64 0, !6, i64 8}
!26 = !{!"_ZTS16b2GrowableBufferIiE", !17, i64 0, !6, i64 8, !6, i64 12, !17, i64 16}
!27 = !{!"_ZTS16b2GrowableBufferIN16b2ParticleSystem5ProxyEE", !17, i64 0, !6, i64 8, !6, i64 12, !17, i64 16}
!28 = !{!"_ZTS16b2GrowableBufferI17b2ParticleContactE", !17, i64 0, !6, i64 8, !6, i64 12, !17, i64 16}
!29 = !{!"_ZTS16b2GrowableBufferI21b2ParticleBodyContactE", !17, i64 0, !6, i64 8, !6, i64 12, !17, i64 16}
!30 = !{!"_ZTS16b2GrowableBufferI14b2ParticlePairE", !17, i64 0, !6, i64 8, !6, i64 12, !17, i64 16}
!31 = !{!"_ZTS16b2GrowableBufferI15b2ParticleTriadE", !17, i64 0, !6, i64 8, !6, i64 12, !17, i64 16}
!32 = !{!"long long", !7, i64 0}
!33 = !{!"_ZTS19b2ParticleSystemDef", !11, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !6, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !6, i64 68, !12, i64 72, !11, i64 76, !12, i64 80}
!34 = !{!10, !6, i64 16}
!35 = !{!10, !17, i64 216}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass