; LLVM IR from mbrenman/TetrisPlayground :: agents/HeuristicAgent.ll (ZN14HeuristicAgent19fillReachableBlanksEiiPA20_i)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14HeuristicAgent19fillReachableBlanksEiiPA20_i(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = icmp sge i32 %10, 0
  br i1 %11, label %12, label %56

12:                                               ; preds = %4
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 10
  br i1 %14, label %15, label %56

15:                                               ; preds = %12
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = icmp sge i32 %16, 0
  br i1 %17, label %18, label %56

18:                                               ; preds = %15
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 20
  br i1 %20, label %21, label %56

21:                                               ; preds = %18
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [20 x i32], ptr %22, i64 %24
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [20 x i32], ptr %25, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %55

31:                                               ; preds = %21
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [20 x i32], ptr %32, i64 %34
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [20 x i32], ptr %35, i64 0, i64 %37
  store i32 -1, ptr %38, align 4, !tbaa !9
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN14HeuristicAgent19fillReachableBlanksEiiPA20_i(ptr noundef nonnull align 8 dereferenceable(56) %9, i32 noundef %40, i32 noundef %41, ptr noundef %42)
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = sub nsw i32 %43, 1
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN14HeuristicAgent19fillReachableBlanksEiiPA20_i(ptr noundef nonnull align 8 dereferenceable(56) %9, i32 noundef %44, i32 noundef %45, ptr noundef %46)
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN14HeuristicAgent19fillReachableBlanksEiiPA20_i(ptr noundef nonnull align 8 dereferenceable(56) %9, i32 noundef %47, i32 noundef %49, ptr noundef %50)
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = sub nsw i32 %52, 1
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN14HeuristicAgent19fillReachableBlanksEiiPA20_i(ptr noundef nonnull align 8 dereferenceable(56) %9, i32 noundef %51, i32 noundef %53, ptr noundef %54)
  br label %55

55:                                               ; preds = %31, %21
  br label %56

56:                                               ; preds = %55, %18, %15, %12, %4
  ret void
}

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


; 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 nofree nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN14HeuristicAgent19fillReachableBlanksEiiPA20_i(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 align 2 {
  %5 = zext nneg i32 %1 to i64
  %or.cond = icmp ult i32 %1, 10
  %6 = icmp ult i32 %2, 20
  %or.cond531 = and i1 %or.cond, %6
  br i1 %or.cond531, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %7 = add nuw nsw i32 %1, 1
  %8 = add nsw i32 %1, -1
  br label %9

9:                                                ; preds = %.lr.ph, %tailrecurse
  %.tr2932 = phi i32 [ %2, %.lr.ph ], [ %15, %tailrecurse ]
  %10 = zext nneg i32 %.tr2932 to i64
  %11 = getelementptr inbounds [20 x i32], ptr %3, i64 %5, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %tailrecurse, label %._crit_edge

tailrecurse:                                      ; preds = %9
  store i32 -1, ptr %11, align 4, !tbaa !5
  tail call void @_ZN14HeuristicAgent19fillReachableBlanksEiiPA20_i(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %7, i32 noundef %.tr2932, ptr noundef nonnull %3)
  tail call void @_ZN14HeuristicAgent19fillReachableBlanksEiiPA20_i(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %8, i32 noundef %.tr2932, ptr noundef nonnull %3)
  %14 = add nuw nsw i32 %.tr2932, 1
  tail call void @_ZN14HeuristicAgent19fillReachableBlanksEiiPA20_i(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, i32 noundef %14, ptr noundef nonnull %3)
  %15 = add nsw i32 %.tr2932, -1
  %16 = icmp ult i32 %15, 20
  br i1 %16, label %9, label %._crit_edge

._crit_edge:                                      ; preds = %tailrecurse, %9, %4
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind memory(argmem: readwrite) 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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass