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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN14HeuristicAgent9aggHeightEP6Tetris(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [10 x [20 x i32]], align 16
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 800, ptr %5) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds [10 x [20 x i32]], ptr %5, i64 0, i64 0
  call void @_ZN6Tetris9copyBoardEPA20_i(ptr noundef nonnull align 8 dereferenceable(824) %11, ptr noundef %12)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %41, %2
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 10
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %44

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

18:                                               ; preds = %37, %17
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 20
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %40

22:                                               ; preds = %18
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [10 x [20 x i32]], ptr %5, i64 0, i64 %24
  %26 = load i32, ptr %9, 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 ne i32 %29, 0
  br i1 %30, label %31, label %36

31:                                               ; preds = %22
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = sub nsw i32 20, %32
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = add nsw i32 %34, %33
  store i32 %35, ptr %6, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %31, %22
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %9, align 4, !tbaa !9
  br label %18, !llvm.loop !11

40:                                               ; preds = %21
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %7, align 4, !tbaa !9
  br label %13, !llvm.loop !13

44:                                               ; preds = %16
  %45 = load i32, ptr %6, align 4, !tbaa !9
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 800, ptr %5) #3
  ret i32 %45
}

declare void @_ZN6Tetris9copyBoardEPA20_i(ptr noundef nonnull align 8 dereferenceable(824), ptr noundef) #2

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


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN14HeuristicAgent9aggHeightEP6Tetris(ptr nocapture noundef nonnull readnone align 8 dereferenceable(56) %0, ptr noundef nonnull %1) local_unnamed_addr #1 align 2 {
  %3 = alloca [10 x [20 x i32]], align 16
  call void @llvm.lifetime.start.p0(i64 800, ptr nonnull %3) #3
  call void @_ZN6Tetris9copyBoardEPA20_i(ptr noundef nonnull align 8 dereferenceable(824) %1, ptr noundef nonnull %3)
  br label %.preheader

.preheader:                                       ; preds = %2, %.preheader
  %indvars.iv = phi i64 [ 0, %2 ], [ %indvars.iv.next, %.preheader ]
  %.01114 = phi i32 [ 0, %2 ], [ %.2.19, %.preheader ]
  %4 = getelementptr inbounds [10 x [20 x i32]], ptr %3, i64 0, i64 %indvars.iv, i64 0
  %5 = load i32, ptr %4, align 16, !tbaa !5
  %.not = icmp eq i32 %5, 0
  %reass.sub = add i32 %.01114, 20
  %.2 = select i1 %.not, i32 %.01114, i32 %reass.sub
  %6 = getelementptr inbounds [10 x [20 x i32]], ptr %3, i64 0, i64 %indvars.iv, i64 1
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not.1 = icmp eq i32 %7, 0
  %8 = add i32 %.2, 19
  %.2.1 = select i1 %.not.1, i32 %.2, i32 %8
  %9 = getelementptr inbounds [10 x [20 x i32]], ptr %3, i64 0, i64 %indvars.iv, i64 2
  %10 = load i32, ptr %9, align 8, !tbaa !5
  %.not.2 = icmp eq i32 %10, 0
  %11 = add i32 %.2.1, 18
  %.2.2 = select i1 %.not.2, i32 %.2.1, i32 %11
  %12 = getelementptr inbounds [10 x [20 x i32]], ptr %3, i64 0, i64 %indvars.iv, i64 3
  %13 = add i32 %.2.2, 17
  %14 = load <16 x i32>, ptr %12, align 4, !tbaa !5
  %15 = icmp eq <16 x i32> %14, zeroinitializer
  %16 = extractelement <16 x i1> %15, i64 0
  %.2.3 = select i1 %16, i32 %.2.2, i32 %13
  %17 = add i32 %.2.3, 16
  %18 = extractelement <16 x i1> %15, i64 1
  %.2.4 = select i1 %18, i32 %.2.3, i32 %17
  %19 = add i32 %.2.4, 15
  %20 = extractelement <16 x i1> %15, i64 2
  %.2.5 = select i1 %20, i32 %.2.4, i32 %19
  %21 = add i32 %.2.5, 14
  %22 = extractelement <16 x i1> %15, i64 3
  %.2.6 = select i1 %22, i32 %.2.5, i32 %21
  %23 = add i32 %.2.6, 13
  %24 = extractelement <16 x i1> %15, i64 4
  %.2.7 = select i1 %24, i32 %.2.6, i32 %23
  %25 = add i32 %.2.7, 12
  %26 = extractelement <16 x i1> %15, i64 5
  %.2.8 = select i1 %26, i32 %.2.7, i32 %25
  %27 = add i32 %.2.8, 11
  %28 = extractelement <16 x i1> %15, i64 6
  %.2.9 = select i1 %28, i32 %.2.8, i32 %27
  %29 = add i32 %.2.9, 10
  %30 = extractelement <16 x i1> %15, i64 7
  %.2.10 = select i1 %30, i32 %.2.9, i32 %29
  %31 = add i32 %.2.10, 9
  %32 = extractelement <16 x i1> %15, i64 8
  %.2.11 = select i1 %32, i32 %.2.10, i32 %31
  %33 = add i32 %.2.11, 8
  %34 = extractelement <16 x i1> %15, i64 9
  %.2.12 = select i1 %34, i32 %.2.11, i32 %33
  %35 = add i32 %.2.12, 7
  %36 = extractelement <16 x i1> %15, i64 10
  %.2.13 = select i1 %36, i32 %.2.12, i32 %35
  %37 = add i32 %.2.13, 6
  %38 = extractelement <16 x i1> %15, i64 11
  %.2.14 = select i1 %38, i32 %.2.13, i32 %37
  %39 = add i32 %.2.14, 5
  %40 = extractelement <16 x i1> %15, i64 12
  %.2.15 = select i1 %40, i32 %.2.14, i32 %39
  %41 = add i32 %.2.15, 4
  %42 = extractelement <16 x i1> %15, i64 13
  %.2.16 = select i1 %42, i32 %.2.15, i32 %41
  %43 = add i32 %.2.16, 3
  %44 = extractelement <16 x i1> %15, i64 14
  %.2.17 = select i1 %44, i32 %.2.16, i32 %43
  %45 = add i32 %.2.17, 2
  %46 = extractelement <16 x i1> %15, i64 15
  %.2.18 = select i1 %46, i32 %.2.17, i32 %45
  %47 = getelementptr inbounds [10 x [20 x i32]], ptr %3, i64 0, i64 %indvars.iv, i64 19
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %.not.19 = icmp ne i32 %48, 0
  %49 = zext i1 %.not.19 to i32
  %.2.19 = add i32 %.2.18, %49
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 10
  br i1 %exitcond.not, label %50, label %.preheader, !llvm.loop !9

50:                                               ; preds = %.preheader
  call void @llvm.lifetime.end.p0(i64 800, ptr nonnull %3) #3
  ret i32 %.2.19
}

declare void @_ZN6Tetris9copyBoardEPA20_i(ptr noundef nonnull align 8 dereferenceable(824), ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass