; LLVM IR from VTIvanov20/eight-ball-pool :: src (main)

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

@_ZL10usedMemory = external hidden global i32, align 4
@_ZL6bodies = external hidden global [64 x ptr], align 16
@_ZL18physicsBodiesCount = external hidden global i32, align 4
@_ZL21physicsManifoldsCount = external hidden global i32, align 4
@_ZL8contacts = external hidden global [4096 x ptr], align 16
@.str.14 = external hidden unnamed_addr constant [96 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [101 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [45 x i8], align 1

declare i32 @printf(ptr noundef, ...) #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
declare dso_local void @DestroyPhysicsBody(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @ClosePhysics() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = load i32, ptr @_ZL21physicsManifoldsCount, align 4, !tbaa !5
  %4 = icmp ugt i32 %3, 0
  br i1 %4, label %5, label %21

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

8:                                                ; preds = %17, %5
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = icmp sge i32 %9, 0
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %8
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [4096 x ptr], ptr @_ZL8contacts, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  call void @_ZL22DestroyPhysicsManifoldP19PhysicsManifoldData(ptr noundef %16)
  br label %17

17:                                               ; preds = %12
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = add nsw i32 %18, -1
  store i32 %19, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !11

20:                                               ; preds = %11
  br label %21

21:                                               ; preds = %20, %0
  %22 = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !5
  %23 = icmp ugt i32 %22, 0
  br i1 %23, label %24, label %40

24:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %25 = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !5
  %26 = sub i32 %25, 1
  store i32 %26, ptr %2, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %36, %24
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = icmp sge i32 %28, 0
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %39

31:                                               ; preds = %27
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %33
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  call void @DestroyPhysicsBody(ptr noundef %35)
  br label %36

36:                                               ; preds = %31
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr %2, align 4, !tbaa !5
  br label %27, !llvm.loop !13

39:                                               ; preds = %30
  br label %40

40:                                               ; preds = %39, %21
  %41 = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !5
  %42 = icmp ugt i32 %41, 0
  br i1 %42, label %46, label %43

43:                                               ; preds = %40
  %44 = load i32, ptr @_ZL10usedMemory, align 4, !tbaa !5
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %50

46:                                               ; preds = %43, %40
  %47 = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !5
  %48 = load i32, ptr @_ZL10usedMemory, align 4, !tbaa !5
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.14, i32 noundef %47, i32 noundef %48)
  br label %63

50:                                               ; preds = %43
  %51 = load i32, ptr @_ZL21physicsManifoldsCount, align 4, !tbaa !5
  %52 = icmp ugt i32 %51, 0
  br i1 %52, label %56, label %53

53:                                               ; preds = %50
  %54 = load i32, ptr @_ZL10usedMemory, align 4, !tbaa !5
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %60

56:                                               ; preds = %53, %50
  %57 = load i32, ptr @_ZL21physicsManifoldsCount, align 4, !tbaa !5
  %58 = load i32, ptr @_ZL10usedMemory, align 4, !tbaa !5
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, i32 noundef %57, i32 noundef %58)
  br label %62

60:                                               ; preds = %53
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.16)
  br label %62

62:                                               ; preds = %60, %56
  br label %63

63:                                               ; preds = %62, %46
  ret void
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL22DestroyPhysicsManifoldP19PhysicsManifoldData(ptr noundef) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@_ZL10usedMemory = external hidden local_unnamed_addr global i32, align 4
@_ZL6bodies = external hidden local_unnamed_addr global [64 x ptr], align 16
@_ZL18physicsBodiesCount = external hidden local_unnamed_addr global i32, align 4
@_ZL21physicsManifoldsCount = external hidden local_unnamed_addr global i32, align 4
@_ZL8contacts = external hidden local_unnamed_addr global [4096 x ptr], align 16
@.str.14 = external hidden unnamed_addr constant [96 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [101 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @DestroyPhysicsBody(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @ClosePhysics() local_unnamed_addr #1 {
  %1 = load i32, ptr @_ZL21physicsManifoldsCount, align 4, !tbaa !5
  %.0918 = add i32 %1, -1
  %2 = icmp sgt i32 %.0918, -1
  br i1 %2, label %.lr.ph.preheader, label %.loopexit17

.lr.ph.preheader:                                 ; preds = %0
  %3 = zext nneg i32 %.0918 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %3, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %4 = getelementptr inbounds [4096 x ptr], ptr @_ZL8contacts, i64 0, i64 %indvars.iv
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  tail call void @_ZL22DestroyPhysicsManifoldP19PhysicsManifoldData(ptr noundef %5)
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not = icmp eq i64 %indvars.iv, 0
  br i1 %.not, label %.loopexit17, label %.lr.ph, !llvm.loop !11

.loopexit17:                                      ; preds = %.lr.ph, %0
  %6 = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !5
  %.020 = add i32 %6, -1
  %7 = icmp sgt i32 %.020, -1
  br i1 %7, label %.lr.ph22.preheader, label %.loopexit

.lr.ph22.preheader:                               ; preds = %.loopexit17
  %8 = zext nneg i32 %.020 to i64
  br label %.lr.ph22

.lr.ph22:                                         ; preds = %.lr.ph22.preheader, %.lr.ph22
  %indvars.iv26 = phi i64 [ %8, %.lr.ph22.preheader ], [ %indvars.iv.next27, %.lr.ph22 ]
  %9 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %indvars.iv26
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  tail call void @DestroyPhysicsBody(ptr noundef %10)
  %indvars.iv.next27 = add nsw i64 %indvars.iv26, -1
  %.not29 = icmp eq i64 %indvars.iv26, 0
  br i1 %.not29, label %.loopexit.loopexit, label %.lr.ph22, !llvm.loop !13

.loopexit.loopexit:                               ; preds = %.lr.ph22
  %.pre = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.loopexit17
  %11 = phi i32 [ %.pre, %.loopexit.loopexit ], [ %6, %.loopexit17 ]
  %12 = icmp ne i32 %11, 0
  %13 = load i32, ptr @_ZL10usedMemory, align 4
  %14 = icmp ne i32 %13, 0
  %or.cond = select i1 %12, i1 true, i1 %14
  br i1 %or.cond, label %15, label %17

15:                                               ; preds = %.loopexit
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14, i32 noundef %11, i32 noundef %13)
  br label %23

17:                                               ; preds = %.loopexit
  %18 = load i32, ptr @_ZL21physicsManifoldsCount, align 4, !tbaa !5
  %.not15 = icmp eq i32 %18, 0
  br i1 %.not15, label %21, label %19

19:                                               ; preds = %17
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.15, i32 noundef %18, i32 noundef 0)
  br label %23

21:                                               ; preds = %17
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16)
  br label %23

23:                                               ; preds = %19, %21, %15
  ret void
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL22DestroyPhysicsManifoldP19PhysicsManifoldData(ptr noundef) local_unnamed_addr #1

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

!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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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