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

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

@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [14 x i8], align 1
@__PRETTY_FUNCTION__._ZN6Tetris9clearLineEi = external hidden unnamed_addr constant [28 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [23 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

12:                                               ; preds = %2
  br label %15

13:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.16, ptr noundef @.str.1, i32 noundef 260, ptr noundef @__PRETTY_FUNCTION__._ZN6Tetris9clearLineEi) #3
  unreachable

14:                                               ; No predecessors!
  br label %15

15:                                               ; preds = %14, %12
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 20
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  br label %21

19:                                               ; preds = %15
  call void @__assert_fail(ptr noundef @.str.17, ptr noundef @.str.1, i32 noundef 261, ptr noundef @__PRETTY_FUNCTION__._ZN6Tetris9clearLineEi) #3
  unreachable

20:                                               ; No predecessors!
  br label %21

21:                                               ; preds = %20, %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %22 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %22, ptr %5, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %53, %21
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %56

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %49, %27
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = icmp slt i32 %29, 10
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %52

32:                                               ; preds = %28
  %33 = getelementptr inbounds %class.Tetris, ptr %9, i32 0, i32 0
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [10 x [20 x i32]], ptr %33, i64 0, i64 %35
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [20 x i32], ptr %36, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = getelementptr inbounds %class.Tetris, ptr %9, i32 0, i32 0
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [10 x [20 x i32]], ptr %42, i64 0, i64 %44
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [20 x i32], ptr %45, i64 0, i64 %47
  store i32 %41, ptr %48, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %32
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %7, align 4, !tbaa !9
  br label %28, !llvm.loop !11

52:                                               ; preds = %31
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr %5, align 4, !tbaa !9
  br label %23, !llvm.loop !13

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

57:                                               ; preds = %67, %56
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = icmp slt i32 %58, 10
  br i1 %59, label %61, label %60

60:                                               ; preds = %57
  store i32 8, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %70

61:                                               ; preds = %57
  %62 = getelementptr inbounds %class.Tetris, ptr %9, i32 0, i32 0
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [10 x [20 x i32]], ptr %62, i64 0, i64 %64
  %66 = getelementptr inbounds [20 x i32], ptr %65, i64 0, i64 0
  store i32 0, ptr %66, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %61
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %8, align 4, !tbaa !9
  br label %57, !llvm.loop !14

70:                                               ; preds = %60
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #2 = { 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 #3 = { noreturn nounwind }
attributes #4 = { 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}
!14 = distinct !{!14, !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"

@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [14 x i8], align 1
@__PRETTY_FUNCTION__._ZN6Tetris9clearLineEi = external hidden unnamed_addr constant [28 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6Tetris9clearLineEi(ptr nocapture noundef nonnull align 8 dereferenceable(824) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = icmp sgt i32 %1, -1
  br i1 %3, label %5, label %4

4:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.16, ptr noundef nonnull @.str.1, i32 noundef 260, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6Tetris9clearLineEi) #2
  unreachable

5:                                                ; preds = %2
  %6 = icmp ult i32 %1, 20
  br i1 %6, label %.preheader18, label %8

.preheader18:                                     ; preds = %5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %.preheader, label %.preheader17.preheader

.preheader17.preheader:                           ; preds = %.preheader18
  %7 = zext nneg i32 %1 to i64
  br label %.preheader17

8:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.17, ptr noundef nonnull @.str.1, i32 noundef 261, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6Tetris9clearLineEi) #2
  unreachable

.preheader17:                                     ; preds = %.preheader17.preheader, %.preheader17
  %indvars.iv = phi i64 [ %7, %.preheader17.preheader ], [ %indvars.iv.next, %.preheader17 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %9 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 0, i64 %indvars.iv.next
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 0, i64 %indvars.iv
  store i32 %10, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 1, i64 %indvars.iv.next
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 1, i64 %indvars.iv
  store i32 %13, ptr %14, align 4, !tbaa !5
  %15 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 2, i64 %indvars.iv.next
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 2, i64 %indvars.iv
  store i32 %16, ptr %17, align 4, !tbaa !5
  %18 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 3, i64 %indvars.iv.next
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 3, i64 %indvars.iv
  store i32 %19, ptr %20, align 4, !tbaa !5
  %21 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 4, i64 %indvars.iv.next
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 4, i64 %indvars.iv
  store i32 %22, ptr %23, align 4, !tbaa !5
  %24 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 5, i64 %indvars.iv.next
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 5, i64 %indvars.iv
  store i32 %25, ptr %26, align 4, !tbaa !5
  %27 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 6, i64 %indvars.iv.next
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 6, i64 %indvars.iv
  store i32 %28, ptr %29, align 4, !tbaa !5
  %30 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 7, i64 %indvars.iv.next
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 7, i64 %indvars.iv
  store i32 %31, ptr %32, align 4, !tbaa !5
  %33 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 8, i64 %indvars.iv.next
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 8, i64 %indvars.iv
  store i32 %34, ptr %35, align 4, !tbaa !5
  %36 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 9, i64 %indvars.iv.next
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = getelementptr inbounds [10 x [20 x i32]], ptr %0, i64 0, i64 9, i64 %indvars.iv
  store i32 %37, ptr %38, align 4, !tbaa !5
  %39 = icmp ugt i64 %indvars.iv, 1
  br i1 %39, label %.preheader17, label %.preheader, !llvm.loop !9

.preheader:                                       ; preds = %.preheader17, %.preheader18
  store i32 0, ptr %0, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %0, i64 80
  store i32 0, ptr %40, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %0, i64 160
  store i32 0, ptr %41, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %0, i64 240
  store i32 0, ptr %42, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %0, i64 320
  store i32 0, ptr %43, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %0, i64 400
  store i32 0, ptr %44, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %0, i64 480
  store i32 0, ptr %45, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %0, i64 560
  store i32 0, ptr %46, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %0, i64 640
  store i32 0, ptr %47, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %0, i64 720
  store i32 0, ptr %48, align 8, !tbaa !5
  ret void
}

attributes #0 = { noreturn 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 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 = { noreturn 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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass