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

@_ZL6bodies = external hidden global [64 x ptr], align 16
@_ZL18physicsBodiesCount = external hidden global i32, align 4
@.str.6 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [66 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 i32 @GetPhysicsShapeVerticesCount(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !5
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %8, label %32

8:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %4, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !9
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %29

15:                                               ; preds = %8
  %16 = load ptr, ptr %4, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.PhysicsBodyData, ptr %16, i32 0, i32 18
  %18 = getelementptr inbounds %struct.PhysicsShape, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !11
  switch i32 %19, label %27 [
    i32 0, label %20
    i32 1, label %21
  ]

20:                                               ; preds = %15
  store i32 24, ptr %3, align 4, !tbaa !5
  br label %28

21:                                               ; preds = %15
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.PhysicsBodyData, ptr %22, i32 0, i32 18
  %24 = getelementptr inbounds %struct.PhysicsShape, ptr %23, i32 0, i32 2
  %25 = getelementptr inbounds %struct.PhysicsVertexData, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !20
  store i32 %26, ptr %3, align 4, !tbaa !5
  br label %28

27:                                               ; preds = %15
  br label %28

28:                                               ; preds = %27, %21, %20
  br label %31

29:                                               ; preds = %8
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  br label %31

31:                                               ; preds = %29, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %34

32:                                               ; preds = %1
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  br label %34

34:                                               ; preds = %32, %31
  %35 = load i32, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %35
}

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 = !{!12, !17, i64 80}
!12 = !{!"_ZTS15PhysicsBodyData", !6, i64 0, !13, i64 4, !14, i64 8, !14, i64 16, !14, i64 24, !15, i64 32, !15, i64 36, !15, i64 40, !15, i64 44, !15, i64 48, !15, i64 52, !15, i64 56, !15, i64 60, !15, i64 64, !15, i64 68, !13, i64 72, !13, i64 73, !13, i64 74, !16, i64 80}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTS7Vector2", !15, i64 0, !15, i64 4}
!15 = !{!"float", !7, i64 0}
!16 = !{!"_ZTS12PhysicsShape", !17, i64 0, !10, i64 8, !18, i64 16, !15, i64 404, !19, i64 408}
!17 = !{!"_ZTS16PhysicsShapeType", !7, i64 0}
!18 = !{!"_ZTS17PhysicsVertexData", !6, i64 0, !7, i64 4, !7, i64 196}
!19 = !{!"_ZTS9Matrix2x2", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12}
!20 = !{!12, !6, i64 96}


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

@_ZL6bodies = external hidden local_unnamed_addr global [64 x ptr], align 16
@_ZL18physicsBodiesCount = external hidden local_unnamed_addr global i32, align 4
@.str.6 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [66 x i8], align 1

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

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local i32 @GetPhysicsShapeVerticesCount(i32 noundef %0) local_unnamed_addr #1 {
  %2 = load i32, ptr @_ZL18physicsBodiesCount, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, %0
  br i1 %3, label %4, label %17

4:                                                ; preds = %1
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [64 x ptr], ptr @_ZL6bodies, i64 0, i64 %5
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %15, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %7, i64 80
  %10 = load i32, ptr %9, align 8, !tbaa !11
  switch i32 %10, label %19 [
    i32 0, label %11
    i32 1, label %12
  ]

11:                                               ; preds = %8
  br label %19

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %7, i64 96
  %14 = load i32, ptr %13, align 8, !tbaa !20
  br label %19

15:                                               ; preds = %4
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  br label %19

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

19:                                               ; preds = %15, %8, %12, %11, %17
  %.1 = phi i32 [ 0, %17 ], [ 0, %8 ], [ %14, %12 ], [ 24, %11 ], [ 0, %15 ]
  ret i32 %.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 nofree 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" }

!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 = !{!12, !17, i64 80}
!12 = !{!"_ZTS15PhysicsBodyData", !6, i64 0, !13, i64 4, !14, i64 8, !14, i64 16, !14, i64 24, !15, i64 32, !15, i64 36, !15, i64 40, !15, i64 44, !15, i64 48, !15, i64 52, !15, i64 56, !15, i64 60, !15, i64 64, !15, i64 68, !13, i64 72, !13, i64 73, !13, i64 74, !16, i64 80}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTS7Vector2", !15, i64 0, !15, i64 4}
!15 = !{!"float", !7, i64 0}
!16 = !{!"_ZTS12PhysicsShape", !17, i64 0, !10, i64 8, !18, i64 16, !15, i64 404, !19, i64 408}
!17 = !{!"_ZTS16PhysicsShapeType", !7, i64 0}
!18 = !{!"_ZTS17PhysicsVertexData", !6, i64 0, !7, i64 4, !7, i64 196}
!19 = !{!"_ZTS9Matrix2x2", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12}
!20 = !{!12, !6, i64 96}


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