; LLVM IR from mbrenman/TetrisPlayground :: game/Tetris.ll (ZN6Tetris14maxBoardHeightEv)

; 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.Tetris = type { [10 x [20 x i32]], i32, i8, i8, ptr, ptr }

; 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 nounwind uwtable
define dso_local noundef i32 @_ZN6Tetris14maxBoardHeightEv(ptr noundef nonnull align 8 dereferenceable(824) %0) #1 align 2 {
  %2 = alloca i32, align 4
  %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 = %36, %1
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 20
  br i1 %10, label %12, label %11

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

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 = %30, %12
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 10
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %13
  %18 = getelementptr inbounds %class.Tetris, ptr %7, i32 0, i32 0
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [10 x [20 x i32]], ptr %18, i64 0, i64 %20
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [20 x i32], ptr %21, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %17
  %28 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %28, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %33

29:                                               ; preds = %17
  br label %30

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

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

35:                                               ; preds = %33
  br label %36

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

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

41:                                               ; preds = %39
  store i32 0, ptr %2, align 4
  br label %42

42:                                               ; preds = %41, %39
  %43 = load i32, ptr %2, align 4
  ret i32 %43

44:                                               ; preds = %39
  unreachable
}

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 = 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 nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef i32 @_ZN6Tetris14maxBoardHeightEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(824) %0) local_unnamed_addr #0 align 2 {
  br label %.preheader

.preheader:                                       ; preds = %1, %31
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %31 ]
  %2 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 0, i64 %indvars.iv
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %.loopexit.split.loop.exit25

4:                                                ; preds = %.preheader
  %5 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 1, i64 %indvars.iv
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not.1 = icmp eq i32 %6, 0
  br i1 %.not.1, label %7, label %.loopexit.split.loop.exit27

7:                                                ; preds = %4
  %8 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 2, i64 %indvars.iv
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not.2 = icmp eq i32 %9, 0
  br i1 %.not.2, label %10, label %.loopexit.split.loop.exit29

10:                                               ; preds = %7
  %11 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 3, i64 %indvars.iv
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %.not.3 = icmp eq i32 %12, 0
  br i1 %.not.3, label %13, label %.loopexit.split.loop.exit31

13:                                               ; preds = %10
  %14 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 4, i64 %indvars.iv
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %.not.4 = icmp eq i32 %15, 0
  br i1 %.not.4, label %16, label %.loopexit.split.loop.exit33

16:                                               ; preds = %13
  %17 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 5, i64 %indvars.iv
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %.not.5 = icmp eq i32 %18, 0
  br i1 %.not.5, label %19, label %.loopexit.split.loop.exit35

19:                                               ; preds = %16
  %20 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 6, i64 %indvars.iv
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not.6 = icmp eq i32 %21, 0
  br i1 %.not.6, label %22, label %.loopexit.split.loop.exit37

22:                                               ; preds = %19
  %23 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 7, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %.not.7 = icmp eq i32 %24, 0
  br i1 %.not.7, label %25, label %.loopexit.split.loop.exit39

25:                                               ; preds = %22
  %26 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 8, i64 %indvars.iv
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not.8 = icmp eq i32 %27, 0
  br i1 %.not.8, label %28, label %.loopexit.split.loop.exit41

28:                                               ; preds = %25
  %29 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 9, i64 %indvars.iv
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %.not.9 = icmp eq i32 %30, 0
  br i1 %.not.9, label %31, label %.loopexit.split.loop.exit43

31:                                               ; preds = %28
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond = icmp eq i64 %indvars.iv.next, 20
  br i1 %exitcond, label %.loopexit, label %.preheader, !llvm.loop !9

.loopexit.split.loop.exit25:                      ; preds = %.preheader
  %32 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit.split.loop.exit27:                      ; preds = %4
  %33 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit.split.loop.exit29:                      ; preds = %7
  %34 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit.split.loop.exit31:                      ; preds = %10
  %35 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit.split.loop.exit33:                      ; preds = %13
  %36 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit.split.loop.exit35:                      ; preds = %16
  %37 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit.split.loop.exit37:                      ; preds = %19
  %38 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit.split.loop.exit39:                      ; preds = %22
  %39 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit.split.loop.exit41:                      ; preds = %25
  %40 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit.split.loop.exit43:                      ; preds = %28
  %41 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit:                                        ; preds = %31, %.loopexit.split.loop.exit43, %.loopexit.split.loop.exit41, %.loopexit.split.loop.exit39, %.loopexit.split.loop.exit37, %.loopexit.split.loop.exit35, %.loopexit.split.loop.exit33, %.loopexit.split.loop.exit31, %.loopexit.split.loop.exit29, %.loopexit.split.loop.exit27, %.loopexit.split.loop.exit25
  %spec.select = phi i32 [ %32, %.loopexit.split.loop.exit25 ], [ %33, %.loopexit.split.loop.exit27 ], [ %34, %.loopexit.split.loop.exit29 ], [ %35, %.loopexit.split.loop.exit31 ], [ %36, %.loopexit.split.loop.exit33 ], [ %37, %.loopexit.split.loop.exit35 ], [ %38, %.loopexit.split.loop.exit37 ], [ %39, %.loopexit.split.loop.exit39 ], [ %40, %.loopexit.split.loop.exit41 ], [ %41, %.loopexit.split.loop.exit43 ], [ 0, %31 ]
  ret i32 %spec.select
}

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


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