; LLVM IR from VTIvanov20/eight-ball-pool :: src/game_manager.ll (ZN11GameManager17ReinitializeSceneEv)

; 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.GameManager::GameState" = type { i8, i8, i8, float, i32, i32 }

@_ZN11GameManager5stateE = external dso_local global %"struct.GameManager::GameState", align 4

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

declare i32 @GetPhysicsBodiesCount() #1

declare ptr @GetPhysicsBody(i32 noundef) #1

; 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 @_ZN11GameManager17ReinitializeSceneEv() #2 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  call void @_ZN15DrawableManager19DestroyAllDrawablesEv()
  br label %4

4:                                                ; preds = %19, %0
  %5 = call i32 @GetPhysicsBodiesCount()
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %7, label %20

7:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #6
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %16, %7
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = call i32 @GetPhysicsBodiesCount()
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #6
  br label %19

13:                                               ; preds = %8
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = call ptr @GetPhysicsBody(i32 noundef %14)
  call void @DestroyPhysicsBody(ptr noundef %15)
  br label %16

16:                                               ; preds = %13
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !9

19:                                               ; preds = %12
  br label %4, !llvm.loop !11

20:                                               ; preds = %4
  %21 = load i32, ptr getelementptr inbounds (%"struct.GameManager::GameState", ptr @_ZN11GameManager5stateE, i32 0, i32 4), align 4, !tbaa !12
  switch i32 %21, label %43 [
    i32 0, label %22
    i32 1, label %29
    i32 2, label %36
  ]

22:                                               ; preds = %20
  %23 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 40) #7
  call void @llvm.memset.p0.i64(ptr align 16 %23, i8 0, i64 40, i1 false)
  invoke void @_ZN8MainMenuC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %23)
          to label %24 unwind label %25

24:                                               ; preds = %22
  br label %44

25:                                               ; preds = %22
  %26 = landingpad { ptr, i32 }
          cleanup
  %27 = extractvalue { ptr, i32 } %26, 0
  store ptr %27, ptr %2, align 8
  %28 = extractvalue { ptr, i32 } %26, 1
  store i32 %28, ptr %3, align 4
  call void @_ZdlPvm(ptr noundef %23, i64 noundef 40) #8
  br label %45

29:                                               ; preds = %20
  %30 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 40) #7
  call void @llvm.memset.p0.i64(ptr align 16 %30, i8 0, i64 40, i1 false)
  invoke void @_ZN12SettingsMenuC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %30)
          to label %31 unwind label %32

31:                                               ; preds = %29
  br label %44

32:                                               ; preds = %29
  %33 = landingpad { ptr, i32 }
          cleanup
  %34 = extractvalue { ptr, i32 } %33, 0
  store ptr %34, ptr %2, align 8
  %35 = extractvalue { ptr, i32 } %33, 1
  store i32 %35, ptr %3, align 4
  call void @_ZdlPvm(ptr noundef %30, i64 noundef 40) #8
  br label %45

36:                                               ; preds = %20
  %37 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 96) #7
  invoke void @_ZN9GameSceneC2Ev(ptr noundef nonnull align 8 dereferenceable(96) %37)
          to label %38 unwind label %39

38:                                               ; preds = %36
  br label %44

39:                                               ; preds = %36
  %40 = landingpad { ptr, i32 }
          cleanup
  %41 = extractvalue { ptr, i32 } %40, 0
  store ptr %41, ptr %2, align 8
  %42 = extractvalue { ptr, i32 } %40, 1
  store i32 %42, ptr %3, align 4
  call void @_ZdlPvm(ptr noundef %37, i64 noundef 96) #8
  br label %45

43:                                               ; preds = %20
  br label %44

44:                                               ; preds = %43, %38, %31, %24
  call void @_ZN15DrawableManager9CreateAllEv()
  ret void

45:                                               ; preds = %39, %32, %25
  %46 = load ptr, ptr %2, align 8
  %47 = load i32, ptr %3, align 4
  %48 = insertvalue { ptr, i32 } poison, ptr %46, 0
  %49 = insertvalue { ptr, i32 } %48, i32 %47, 1
  resume { ptr, i32 } %49
}

declare void @_ZN15DrawableManager19DestroyAllDrawablesEv() #1

declare void @DestroyPhysicsBody(ptr noundef) #1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8MainMenuC2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #5

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12SettingsMenuC2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9GameSceneC2Ev(ptr noundef nonnull align 8 dereferenceable(96)) unnamed_addr #2 align 2

declare void @_ZN15DrawableManager9CreateAllEv() #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { nobuiltin allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nobuiltin nounwind "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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !16, i64 8}
!13 = !{!"_ZTSN11GameManager9GameStateE", !14, i64 0, !14, i64 1, !14, i64 2, !15, i64 4, !16, i64 8, !17, i64 12}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!"_ZTSN11GameManager5SceneE", !7, i64 0}
!17 = !{!"_ZTSN11GameManager4TurnE", !7, i64 0}


; 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.GameManager::GameState" = type { i8, i8, i8, float, i32, i32 }

@_ZN11GameManager5stateE = external dso_local local_unnamed_addr global %"struct.GameManager::GameState", align 4

declare i32 @GetPhysicsBodiesCount() local_unnamed_addr #0

declare ptr @GetPhysicsBody(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11GameManager17ReinitializeSceneEv() local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN15DrawableManager19DestroyAllDrawablesEv()
  %1 = tail call i32 @GetPhysicsBodiesCount()
  %.not8 = icmp eq i32 %1, 0
  br i1 %.not8, label %._crit_edge, label %.preheader

.loopexit:                                        ; preds = %.lr.ph, %.preheader
  %2 = tail call i32 @GetPhysicsBodiesCount()
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !5

.preheader:                                       ; preds = %0, %.loopexit
  %3 = tail call i32 @GetPhysicsBodiesCount()
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.057 = phi i32 [ %6, %.lr.ph ], [ 0, %.preheader ]
  %5 = tail call ptr @GetPhysicsBody(i32 noundef %.057)
  tail call void @DestroyPhysicsBody(ptr noundef %5)
  %6 = add nuw nsw i32 %.057, 1
  %7 = tail call i32 @GetPhysicsBodiesCount()
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %.lr.ph, label %.loopexit, !llvm.loop !7

._crit_edge:                                      ; preds = %.loopexit, %0
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @_ZN11GameManager5stateE, i64 8), align 4, !tbaa !8
  switch i32 %9, label %22 [
    i32 0, label %10
    i32 1, label %14
    i32 2, label %18
  ]

10:                                               ; preds = %._crit_edge
  %11 = tail call noalias noundef nonnull dereferenceable(40) ptr @_Znwm(i64 noundef 40) #5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %11, i8 0, i64 40, i1 false)
  invoke void @_ZN8MainMenuC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %11)
          to label %22 unwind label %12

12:                                               ; preds = %10
  %13 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %11, i64 noundef 40) #6
  br label %23

14:                                               ; preds = %._crit_edge
  %15 = tail call noalias noundef nonnull dereferenceable(40) ptr @_Znwm(i64 noundef 40) #5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %15, i8 0, i64 40, i1 false)
  invoke void @_ZN12SettingsMenuC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %15)
          to label %22 unwind label %16

16:                                               ; preds = %14
  %17 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %15, i64 noundef 40) #6
  br label %23

18:                                               ; preds = %._crit_edge
  %19 = tail call noalias noundef nonnull dereferenceable(96) ptr @_Znwm(i64 noundef 96) #5
  invoke void @_ZN9GameSceneC2Ev(ptr noundef nonnull align 8 dereferenceable(96) %19)
          to label %22 unwind label %20

20:                                               ; preds = %18
  %21 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %19, i64 noundef 96) #6
  br label %23

22:                                               ; preds = %._crit_edge, %18, %14, %10
  tail call void @_ZN15DrawableManager9CreateAllEv()
  ret void

23:                                               ; preds = %20, %16, %12
  %.pn = phi { ptr, i32 } [ %21, %20 ], [ %17, %16 ], [ %13, %12 ]
  resume { ptr, i32 } %.pn
}

declare void @_ZN15DrawableManager19DestroyAllDrawablesEv() local_unnamed_addr #0

declare void @DestroyPhysicsBody(ptr noundef) local_unnamed_addr #0

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8MainMenuC2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12SettingsMenuC2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9GameSceneC2Ev(ptr noundef nonnull align 8 dereferenceable(96)) unnamed_addr #1 align 2

declare void @_ZN15DrawableManager9CreateAllEv() local_unnamed_addr #0

attributes #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 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 = { nobuiltin allocsize(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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nobuiltin nounwind "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 = { builtin allocsize(0) }
attributes #6 = { builtin 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = !{!9, !14, i64 8}
!9 = !{!"_ZTSN11GameManager9GameStateE", !10, i64 0, !10, i64 1, !10, i64 2, !13, i64 4, !14, i64 8, !15, i64 12}
!10 = !{!"bool", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"float", !11, i64 0}
!14 = !{!"_ZTSN11GameManager5SceneE", !11, i64 0}
!15 = !{!"_ZTSN11GameManager4TurnE", !11, i64 0}


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