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

; 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.Vector2 = type { float, float }
%struct.Color = type { i8, i8, i8, i8 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11GameManager13DrawCollidersEv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %struct.Vector2, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.Vector2, align 4
  %9 = alloca %struct.Vector2, align 4
  %10 = alloca %struct.Vector2, align 4
  %11 = alloca %struct.Color, align 1
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %59, %0
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = call i32 @GetPhysicsBodiesCount()
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  br label %62

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = call ptr @GetPhysicsBody(i32 noundef %18)
  store ptr %19, ptr %3, align 8, !tbaa !9
  %20 = load ptr, ptr %3, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %58

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = call i32 @GetPhysicsShapeVerticesCount(i32 noundef %23)
  store i32 %24, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %54, %22
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %57

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %31 = load ptr, ptr %3, align 8, !tbaa !9
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = call <2 x float> @GetPhysicsShapeVertex(ptr noundef %31, i32 noundef %32)
  store <2 x float> %33, ptr %6, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %38, label %41

38:                                               ; preds = %30
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  br label %42

41:                                               ; preds = %30
  br label %42

42:                                               ; preds = %41, %38
  %43 = phi i32 [ %40, %38 ], [ 0, %41 ]
  store i32 %43, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %44 = load ptr, ptr %3, align 8, !tbaa !9
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = call <2 x float> @GetPhysicsShapeVertex(ptr noundef %44, i32 noundef %45)
  store <2 x float> %46, ptr %8, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %8, i64 8, i1 false), !tbaa.struct !11
  %47 = getelementptr inbounds %struct.Color, ptr %11, i32 0, i32 0
  store i8 0, ptr %47, align 1, !tbaa !14
  %48 = getelementptr inbounds %struct.Color, ptr %11, i32 0, i32 1
  store i8 -28, ptr %48, align 1, !tbaa !16
  %49 = getelementptr inbounds %struct.Color, ptr %11, i32 0, i32 2
  store i8 48, ptr %49, align 1, !tbaa !17
  %50 = getelementptr inbounds %struct.Color, ptr %11, i32 0, i32 3
  store i8 -1, ptr %50, align 1, !tbaa !18
  %51 = load <2 x float>, ptr %9, align 4
  %52 = load <2 x float>, ptr %10, align 4
  %53 = load i32, ptr %11, align 1
  call void @DrawLineV(<2 x float> %51, <2 x float> %52, i32 %53)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %54

54:                                               ; preds = %42
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !5
  br label %25, !llvm.loop !19

57:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %58

58:                                               ; preds = %57, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %1, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %1, align 4, !tbaa !5
  br label %12, !llvm.loop !21

62:                                               ; preds = %16
  ret void
}

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

declare i32 @GetPhysicsBodiesCount() #2

declare ptr @GetPhysicsBody(i32 noundef) #2

declare i32 @GetPhysicsShapeVerticesCount(i32 noundef) #2

declare <2 x float> @GetPhysicsShapeVertex(ptr noundef, i32 noundef) #2

declare void @DrawLineV(<2 x float>, <2 x float>, i32) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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 = !{i64 0, i64 4, !12, i64 4, i64 4, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = !{!15, !7, i64 0}
!15 = !{!"_ZTS5Color", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!16 = !{!15, !7, i64 1}
!17 = !{!15, !7, i64 2}
!18 = !{!15, !7, i64 3}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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 @_ZN11GameManager13DrawCollidersEv() local_unnamed_addr #0 {
  %1 = tail call i32 @GetPhysicsBodiesCount()
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph23, label %._crit_edge

._crit_edge:                                      ; preds = %.loopexit, %0
  ret void

.lr.ph23:                                         ; preds = %0, %.loopexit
  %.022 = phi i32 [ %12, %.loopexit ], [ 0, %0 ]
  %3 = tail call ptr @GetPhysicsBody(i32 noundef %.022)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.loopexit, label %4

4:                                                ; preds = %.lr.ph23
  %5 = tail call i32 @GetPhysicsShapeVerticesCount(i32 noundef %.022)
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.01821 = phi i32 [ %8, %.lr.ph ], [ 0, %4 ]
  %7 = tail call <2 x float> @GetPhysicsShapeVertex(ptr noundef nonnull %3, i32 noundef %.01821)
  %8 = add nuw nsw i32 %.01821, 1
  %9 = icmp slt i32 %8, %5
  %10 = select i1 %9, i32 %8, i32 0
  %11 = tail call <2 x float> @GetPhysicsShapeVertex(ptr noundef nonnull %3, i32 noundef %10)
  tail call void @DrawLineV(<2 x float> %7, <2 x float> %11, i32 -13573120)
  %exitcond.not = icmp eq i32 %8, %5
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !5

.loopexit:                                        ; preds = %.lr.ph, %4, %.lr.ph23
  %12 = add nuw nsw i32 %.022, 1
  %13 = tail call i32 @GetPhysicsBodiesCount()
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %.lr.ph23, label %._crit_edge, !llvm.loop !7
}

declare i32 @GetPhysicsBodiesCount() local_unnamed_addr #1

declare ptr @GetPhysicsBody(i32 noundef) local_unnamed_addr #1

declare i32 @GetPhysicsShapeVerticesCount(i32 noundef) local_unnamed_addr #1

declare <2 x float> @GetPhysicsShapeVertex(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @DrawLineV(<2 x float>, <2 x float>, i32) local_unnamed_addr #1

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { "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 = distinct !{!7, !6}


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