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

%struct.PhysicsBodyData = type { i32, i8, %struct.Vector2, %struct.Vector2, %struct.Vector2, float, float, float, float, float, float, float, float, float, float, i8, i8, i8, %struct.PhysicsShape }
%struct.Vector2 = type { float, float }
%struct.PhysicsShape = type { i32, ptr, %struct.PhysicsVertexData, float, %struct.Matrix2x2 }
%struct.PhysicsVertexData = type { i32, [24 x %struct.Vector2], [24 x %struct.Vector2] }
%struct.Matrix2x2 = type { float, float, float, float }

@_ZL10usedMemory = external hidden global i32, align 4
@_ZL6bodies = external hidden global [64 x ptr], align 16
@_ZL18physicsBodiesCount = external hidden global i32, align 4
@.str.10 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [56 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
define dso_local void @DestroyPhysicsBody(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %82

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.PhysicsBodyData, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !9
  store i32 %13, ptr %3, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 -1, ptr %4, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !19
  br label %14

14:                                               ; preds = %31, %10
  %15 = load i32, ptr %5, align 4, !tbaa !19
  %16 = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !19
  %17 = icmp ult i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 2, ptr %6, align 4
  br label %34

19:                                               ; preds = %14
  %20 = load i32, ptr %5, align 4, !tbaa !19
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.PhysicsBodyData, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %26 = load i32, ptr %3, align 4, !tbaa !19
  %27 = icmp eq i32 %25, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %19
  %29 = load i32, ptr %5, align 4, !tbaa !19
  store i32 %29, ptr %4, align 4, !tbaa !19
  store i32 2, ptr %6, align 4
  br label %34

30:                                               ; preds = %19
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %5, align 4, !tbaa !19
  %33 = add i32 %32, 1
  store i32 %33, ptr %5, align 4, !tbaa !19
  br label %14, !llvm.loop !20

34:                                               ; preds = %28, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %4, align 4, !tbaa !19
  %37 = icmp eq i32 %36, -1
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = load i32, ptr %3, align 4, !tbaa !19
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.10, i32 noundef %39)
  store i32 1, ptr %6, align 4
  br label %79

41:                                               ; preds = %35
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %42) #4
  %43 = load i32, ptr @_ZL10usedMemory, align 4, !tbaa !19
  %44 = zext i32 %43 to i64
  %45 = sub i64 %44, 504
  %46 = trunc i64 %45 to i32
  store i32 %46, ptr @_ZL10usedMemory, align 4, !tbaa !19
  %47 = load i32, ptr %4, align 4, !tbaa !19
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %48
  store ptr null, ptr %49, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %50 = load i32, ptr %4, align 4, !tbaa !19
  store i32 %50, ptr %7, align 4, !tbaa !19
  br label %51

51:                                               ; preds = %71, %41
  %52 = load i32, ptr %7, align 4, !tbaa !19
  %53 = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !19
  %54 = icmp ult i32 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %74

56:                                               ; preds = %51
  %57 = load i32, ptr %7, align 4, !tbaa !19
  %58 = add i32 %57, 1
  %59 = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !19
  %60 = icmp ult i32 %58, %59
  br i1 %60, label %61, label %70

61:                                               ; preds = %56
  %62 = load i32, ptr %7, align 4, !tbaa !19
  %63 = add i32 %62, 1
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = load i32, ptr %7, align 4, !tbaa !19
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %68
  store ptr %66, ptr %69, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %61, %56
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %7, align 4, !tbaa !19
  %73 = add i32 %72, 1
  store i32 %73, ptr %7, align 4, !tbaa !19
  br label %51, !llvm.loop !22

74:                                               ; preds = %55
  %75 = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !19
  %76 = add i32 %75, -1
  store i32 %76, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !19
  %77 = load i32, ptr %3, align 4, !tbaa !19
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.11, i32 noundef %77)
  store i32 0, ptr %6, align 4
  br label %79

79:                                               ; preds = %74, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  %80 = load i32, ptr %6, align 4
  switch i32 %80, label %85 [
    i32 0, label %81
    i32 1, label %84
  ]

81:                                               ; preds = %79
  br label %84

82:                                               ; preds = %1
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.12)
  br label %84

84:                                               ; preds = %82, %81, %79
  ret void

85:                                               ; preds = %79
  unreachable
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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 "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, !11, i64 0}
!10 = !{!"_ZTS15PhysicsBodyData", !11, i64 0, !12, i64 4, !13, i64 8, !13, i64 16, !13, i64 24, !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, !14, i64 68, !12, i64 72, !12, i64 73, !12, i64 74, !15, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!"_ZTS7Vector2", !14, i64 0, !14, i64 4}
!14 = !{!"float", !7, i64 0}
!15 = !{!"_ZTS12PhysicsShape", !16, i64 0, !6, i64 8, !17, i64 16, !14, i64 404, !18, i64 408}
!16 = !{!"_ZTS16PhysicsShapeType", !7, i64 0}
!17 = !{!"_ZTS17PhysicsVertexData", !11, i64 0, !7, i64 4, !7, i64 196}
!18 = !{!"_ZTS9Matrix2x2", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12}
!19 = !{!11, !11, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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
@.str.10 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [56 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @DestroyPhysicsBody(ptr noundef %0) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %41, label %2

2:                                                ; preds = %1
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !18
  %.not29 = icmp eq i32 %4, 0
  br i1 %.not29, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %10
  %.01724 = phi i32 [ %11, %10 ], [ 0, %2 ]
  %5 = zext i32 %.01724 to i64
  %6 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %5
  %7 = load ptr, ptr %6, align 8, !tbaa !19
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = icmp eq i32 %8, %3
  br i1 %9, label %13, label %10

10:                                               ; preds = %.lr.ph
  %11 = add nuw i32 %.01724, 1
  %exitcond.not = icmp eq i32 %11, %4
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !20

._crit_edge:                                      ; preds = %10, %2
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10, i32 noundef %3)
  br label %43

13:                                               ; preds = %.lr.ph
  tail call void @free(ptr noundef %0) #3
  %14 = load i32, ptr @_ZL10usedMemory, align 4, !tbaa !18
  %15 = add i32 %14, -504
  store i32 %15, ptr @_ZL10usedMemory, align 4, !tbaa !18
  %16 = sext i32 %.01724 to i64
  %17 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %16
  store ptr null, ptr %17, align 8, !tbaa !19
  %18 = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !18
  %19 = icmp ult i32 %.01724, %18
  br i1 %19, label %.lr.ph27.preheader, label %._crit_edge28

.lr.ph27.preheader:                               ; preds = %13
  %20 = zext i32 %18 to i64
  %21 = sub i32 %18, %.01724
  %.neg = add i32 %.01724, 1
  %xtraiter = and i32 %21, 1
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph27.prol.loopexit, label %.lr.ph27.prol

.lr.ph27.prol:                                    ; preds = %.lr.ph27.preheader
  %indvars.iv.next.prol = add nuw nsw i64 %5, 1
  %22 = icmp ult i64 %indvars.iv.next.prol, %20
  br i1 %22, label %23, label %.lr.ph27.prol.loopexit

23:                                               ; preds = %.lr.ph27.prol
  %24 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %indvars.iv.next.prol
  %25 = load ptr, ptr %24, align 8, !tbaa !19
  %26 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %5
  store ptr %25, ptr %26, align 8, !tbaa !19
  br label %.lr.ph27.prol.loopexit

.lr.ph27.prol.loopexit:                           ; preds = %.lr.ph27.prol, %23, %.lr.ph27.preheader
  %indvars.iv.unr = phi i64 [ %5, %.lr.ph27.preheader ], [ %indvars.iv.next.prol, %23 ], [ %indvars.iv.next.prol, %.lr.ph27.prol ]
  %27 = icmp eq i32 %18, %.neg
  br i1 %27, label %._crit_edge28, label %.lr.ph27

._crit_edge28:                                    ; preds = %.lr.ph27.prol.loopexit, %40, %13
  %28 = add i32 %18, -1
  store i32 %28, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !18
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11, i32 noundef %3)
  br label %43

.lr.ph27:                                         ; preds = %.lr.ph27.prol.loopexit, %40
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %40 ], [ %indvars.iv.unr, %.lr.ph27.prol.loopexit ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %30 = icmp ult i64 %indvars.iv.next, %20
  br i1 %30, label %31, label %.lr.ph27.1

31:                                               ; preds = %.lr.ph27
  %32 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %indvars.iv.next
  %33 = load ptr, ptr %32, align 8, !tbaa !19
  %34 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %indvars.iv
  store ptr %33, ptr %34, align 8, !tbaa !19
  br label %.lr.ph27.1

.lr.ph27.1:                                       ; preds = %.lr.ph27, %31
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %35 = icmp ult i64 %indvars.iv.next.1, %20
  br i1 %35, label %36, label %40

36:                                               ; preds = %.lr.ph27.1
  %37 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %indvars.iv.next.1
  %38 = load ptr, ptr %37, align 8, !tbaa !19
  %39 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %indvars.iv.next
  store ptr %38, ptr %39, align 8, !tbaa !19
  br label %40

40:                                               ; preds = %36, %.lr.ph27.1
  %lftr.wideiv.1 = trunc i64 %indvars.iv.next.1 to i32
  %exitcond34.not.1 = icmp eq i32 %18, %lftr.wideiv.1
  br i1 %exitcond34.not.1, label %._crit_edge28, label %.lr.ph27, !llvm.loop !22

41:                                               ; preds = %1
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12)
  br label %43

43:                                               ; preds = %._crit_edge, %._crit_edge28, %41
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

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 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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, !7, i64 0}
!6 = !{!"_ZTS15PhysicsBodyData", !7, i64 0, !10, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !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, !12, i64 68, !10, i64 72, !10, i64 73, !10, i64 74, !13, i64 80}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"_ZTS7Vector2", !12, i64 0, !12, i64 4}
!12 = !{!"float", !8, i64 0}
!13 = !{!"_ZTS12PhysicsShape", !14, i64 0, !15, i64 8, !16, i64 16, !12, i64 404, !17, i64 408}
!14 = !{!"_ZTS16PhysicsShapeType", !8, i64 0}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!"_ZTS17PhysicsVertexData", !7, i64 0, !8, i64 4, !8, i64 196}
!17 = !{!"_ZTS9Matrix2x2", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12}
!18 = !{!7, !7, i64 0}
!19 = !{!15, !15, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


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