; LLVM IR from Bousk/Net :: NetworkLib/Samples/Games/TicTacToe/Game.ll (ZNK9TicTacToe4Grid10isGridFullEv)

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

%"class.TicTacToe::Grid" = type <{ %"struct.std::array", i32, i8, [3 x i8] }>
%"struct.std::array" = type { [3 x %"struct.std::array.0"] }
%"struct.std::array.0" = type { [3 x i32] }

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZNK9TicTacToe4Grid10isGridFullEv(ptr noundef nonnull align 4 dereferenceable(41) %0) #1 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %35, %1
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp ult i32 %9, 3
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  store i32 2, ptr %5, align 4
  br label %38

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

13:                                               ; preds = %29, %12
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp ult i32 %14, 3
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 5, ptr %5, align 4
  br label %32

17:                                               ; preds = %13
  %18 = getelementptr inbounds %"class.TicTacToe::Grid", ptr %7, i32 0, i32 0
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNKSt5arrayIS_IN9TicTacToe4CaseELm3EELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(36) %18, i64 noundef %20) #2
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIN9TicTacToe4CaseELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(12) %21, i64 noundef %23) #2
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %17
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %32

28:                                               ; preds = %17
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = add i32 %30, 1
  store i32 %31, ptr %6, align 4, !tbaa !9
  br label %13, !llvm.loop !13

32:                                               ; preds = %27, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %33 = load i32, ptr %5, align 4
  switch i32 %33, label %38 [
    i32 5, label %34
  ]

34:                                               ; preds = %32
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = add i32 %36, 1
  store i32 %37, ptr %4, align 4, !tbaa !9
  br label %8, !llvm.loop !15

38:                                               ; preds = %32, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %39 = load i32, ptr %5, align 4
  switch i32 %39, label %43 [
    i32 2, label %40
    i32 1, label %41
  ]

40:                                               ; preds = %38
  store i1 true, ptr %2, align 1
  br label %41

41:                                               ; preds = %40, %38
  %42 = load i1, ptr %2, align 1
  ret i1 %42

43:                                               ; preds = %38
  unreachable
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZNKSt5arrayIS_IN9TicTacToe4CaseELm3EELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(36), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIN9TicTacToe4CaseELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(12), i64 noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTSN9TicTacToe4CaseE", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 nounwind uwtable
define dso_local noundef zeroext i1 @_ZNK9TicTacToe4Grid10isGridFullEv(ptr noundef nonnull align 4 dereferenceable(41) %0) local_unnamed_addr #0 align 2 {
.preheader:
  %1 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNKSt5arrayIS_IN9TicTacToe4CaseELm3EELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(36) %0, i64 noundef 0) #1
  %2 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIN9TicTacToe4CaseELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(12) %1, i64 noundef 0) #1
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %.loopexit.loopexit, label %5

5:                                                ; preds = %.preheader
  %6 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNKSt5arrayIS_IN9TicTacToe4CaseELm3EELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(36) %0, i64 noundef 0) #1
  %7 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIN9TicTacToe4CaseELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(12) %6, i64 noundef 1) #1
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %.loopexit.loopexit, label %10

10:                                               ; preds = %5
  %11 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNKSt5arrayIS_IN9TicTacToe4CaseELm3EELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(36) %0, i64 noundef 0) #1
  %12 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIN9TicTacToe4CaseELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(12) %11, i64 noundef 2) #1
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %.loopexit.loopexit, label %.preheader.1

.preheader.1:                                     ; preds = %10
  %15 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNKSt5arrayIS_IN9TicTacToe4CaseELm3EELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(36) %0, i64 noundef 1) #1
  %16 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIN9TicTacToe4CaseELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(12) %15, i64 noundef 0) #1
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %.loopexit.loopexit, label %19

19:                                               ; preds = %.preheader.1
  %20 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNKSt5arrayIS_IN9TicTacToe4CaseELm3EELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(36) %0, i64 noundef 1) #1
  %21 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIN9TicTacToe4CaseELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(12) %20, i64 noundef 1) #1
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %.loopexit.loopexit, label %24

24:                                               ; preds = %19
  %25 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNKSt5arrayIS_IN9TicTacToe4CaseELm3EELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(36) %0, i64 noundef 1) #1
  %26 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIN9TicTacToe4CaseELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(12) %25, i64 noundef 2) #1
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %.loopexit.loopexit, label %.preheader.2

.preheader.2:                                     ; preds = %24
  %29 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNKSt5arrayIS_IN9TicTacToe4CaseELm3EELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(36) %0, i64 noundef 2) #1
  %30 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIN9TicTacToe4CaseELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(12) %29, i64 noundef 0) #1
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %.loopexit.loopexit, label %33

33:                                               ; preds = %.preheader.2
  %34 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNKSt5arrayIS_IN9TicTacToe4CaseELm3EELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(36) %0, i64 noundef 2) #1
  %35 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIN9TicTacToe4CaseELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(12) %34, i64 noundef 1) #1
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %.loopexit.loopexit, label %38

38:                                               ; preds = %33
  %39 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNKSt5arrayIS_IN9TicTacToe4CaseELm3EELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(36) %0, i64 noundef 2) #1
  %40 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIN9TicTacToe4CaseELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(12) %39, i64 noundef 2) #1
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %.loopexit.loopexit, label %.loopexit

.loopexit.loopexit:                               ; preds = %38, %33, %.preheader.2, %24, %19, %.preheader.1, %10, %5, %.preheader
  br label %.loopexit

.loopexit:                                        ; preds = %38, %.loopexit.loopexit
  %43 = phi i1 [ false, %.loopexit.loopexit ], [ true, %38 ]
  ret i1 %43
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZNKSt5arrayIS_IN9TicTacToe4CaseELm3EELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(36), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt5arrayIN9TicTacToe4CaseELm3EEixEm(ptr noundef nonnull align 4 dereferenceable(12), i64 noundef) local_unnamed_addr #0 align 2

attributes #0 = { 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 #1 = { 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 = !{!"_ZTSN9TicTacToe4CaseE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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