; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x29-总结与练习/194. 涂满它！.ll (Z4filli)

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

@n = external dso_local global i32, align 4
@a = external dso_local global [10 x [10 x i32]], align 16
@v = external dso_local global [10 x [10 x i32]], align 16

; 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
declare dso_local void @_Z3dfsiii(i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4filli(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %48, %1
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %51

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

13:                                               ; preds = %44, %12
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %13
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [10 x [10 x i32]], ptr @a, i64 0, i64 %20
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10 x i32], ptr %21, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = icmp eq i32 %25, %26
  br i1 %27, label %28, label %43

28:                                               ; preds = %18
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10 x [10 x i32]], ptr @v, i64 0, i64 %30
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10 x i32], ptr %31, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp eq i32 %35, 2
  br i1 %36, label %37, label %43

37:                                               ; preds = %28
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %38, i32 noundef %39, i32 noundef %40)
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %3, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %37, %28, %18
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %6, align 4, !tbaa !5
  br label %13, !llvm.loop !9

47:                                               ; preds = %17
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %4, align 4, !tbaa !5
  br label %7, !llvm.loop !11

51:                                               ; preds = %11
  %52 = load i32, ptr %3, align 4, !tbaa !5
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %52
}

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 = { 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"}
!11 = distinct !{!11, !10}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [10 x [10 x i32]], align 16
@v = external dso_local local_unnamed_addr global [10 x [10 x i32]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4filli(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.preheader, label %._crit_edge21

.preheader:                                       ; preds = %1, %._crit_edge
  %4 = phi i32 [ %7, %._crit_edge ], [ %2, %1 ]
  %indvars.iv25 = phi i64 [ %indvars.iv.next26, %._crit_edge ], [ 0, %1 ]
  %.01519 = phi i32 [ %.1.lcssa, %._crit_edge ], [ 0, %1 ]
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %6 = trunc nuw nsw i64 %indvars.iv25 to i32
  br label %10

._crit_edge21:                                    ; preds = %._crit_edge, %1
  %.015.lcssa = phi i32 [ 0, %1 ], [ %.1.lcssa, %._crit_edge ]
  ret i32 %.015.lcssa

._crit_edge:                                      ; preds = %23, %.preheader
  %7 = phi i32 [ %4, %.preheader ], [ %24, %23 ]
  %.1.lcssa = phi i32 [ %.01519, %.preheader ], [ %.2, %23 ]
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %8 = sext i32 %7 to i64
  %9 = icmp slt i64 %indvars.iv.next26, %8
  br i1 %9, label %.preheader, label %._crit_edge21, !llvm.loop !9

10:                                               ; preds = %.lr.ph, %23
  %11 = phi i32 [ %4, %.lr.ph ], [ %24, %23 ]
  %12 = phi i32 [ %4, %.lr.ph ], [ %25, %23 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %23 ]
  %.117 = phi i32 [ %.01519, %.lr.ph ], [ %.2, %23 ]
  %13 = getelementptr inbounds [10 x [10 x i32]], ptr @a, i64 0, i64 %indvars.iv25, i64 %indvars.iv
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp eq i32 %14, %0
  br i1 %15, label %16, label %23

16:                                               ; preds = %10
  %17 = getelementptr inbounds [10 x [10 x i32]], ptr @v, i64 0, i64 %indvars.iv25, i64 %indvars.iv
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp eq i32 %18, 2
  br i1 %19, label %20, label %23

20:                                               ; preds = %16
  %21 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @_Z3dfsiii(i32 noundef %0, i32 noundef %6, i32 noundef %21)
  %22 = add nsw i32 %.117, 1
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %10, %16, %20
  %24 = phi i32 [ %.pre, %20 ], [ %11, %16 ], [ %11, %10 ]
  %25 = phi i32 [ %.pre, %20 ], [ %12, %16 ], [ %12, %10 ]
  %.2 = phi i32 [ %22, %20 ], [ %.117, %16 ], [ %.117, %10 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = sext i32 %25 to i64
  %27 = icmp slt i64 %indvars.iv.next, %26
  br i1 %27, label %10, label %._crit_edge, !llvm.loop !12
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.unswitch.partial.disable"}
!12 = distinct !{!12, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass