; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x22-深度优先搜索/165. 小猫爬山.ll (Z3dfsii)

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

@c = external dso_local global [20 x i32], align 16
@cab = external dso_local global [20 x i32], align 16
@n = external dso_local global i32, align 4
@w = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4

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

9:                                                ; preds = %2
  br label %79

10:                                               ; preds = %2
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  %14 = icmp eq i32 %11, %13
  br i1 %14, label %15, label %18

15:                                               ; preds = %10
  %16 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @ans, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %17 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %17, ptr @ans, align 4, !tbaa !5
  br label %79

18:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %59, %18
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = icmp sle i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %62

24:                                               ; preds = %19
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [20 x i32], ptr @cab, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %28, %32
  %34 = load i32, ptr @w, align 4, !tbaa !5
  %35 = icmp sle i32 %33, %34
  br i1 %35, label %36, label %58

36:                                               ; preds = %24
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [20 x i32], ptr @cab, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = add nsw i32 %44, %40
  store i32 %45, ptr %43, align 4, !tbaa !5
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  %48 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %47, i32 noundef %48)
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [20 x i32], ptr @cab, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sub nsw i32 %56, %52
  store i32 %57, ptr %55, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %36, %24
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %5, align 4, !tbaa !5
  br label %19, !llvm.loop !9

62:                                               ; preds = %23
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [20 x i32], ptr @cab, i64 0, i64 %69
  store i32 %66, ptr %70, align 4, !tbaa !5
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  call void @_Z3dfsii(i32 noundef %72, i32 noundef %74)
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [20 x i32], ptr @cab, i64 0, i64 %77
  store i32 0, ptr %78, align 4, !tbaa !5
  br label %79

79:                                               ; preds = %62, %15, %9
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

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

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

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" }
attributes #1 = { inlinehint 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"}


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

@c = external dso_local local_unnamed_addr global [20 x i32], align 16
@cab = external dso_local local_unnamed_addr global [20 x i32], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@w = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  store i32 %1, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr @ans, align 4, !tbaa !5
  %.not = icmp sgt i32 %4, %1
  br i1 %.not, label %5, label %common.ret28

5:                                                ; preds = %2
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  %8 = icmp eq i32 %7, %0
  br i1 %8, label %10, label %.preheader

.preheader:                                       ; preds = %5
  %.not1517 = icmp slt i32 %1, 1
  %.phi.trans.insert = sext i32 %0 to i64
  %.phi.trans.insert22 = getelementptr inbounds [20 x i32], ptr @c, i64 0, i64 %.phi.trans.insert
  %.pre24 = add nsw i32 %1, 1
  br i1 %.not1517, label %.preheader.._crit_edge_crit_edge, label %.lr.ph

.preheader.._crit_edge_crit_edge:                 ; preds = %.preheader
  %.pre23 = load i32, ptr %.phi.trans.insert22, align 4, !tbaa !5
  %.pre26 = add nsw i32 %0, 1
  br label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %9 = add nsw i32 %0, 1
  %wide.trip.count = zext nneg i32 %.pre24 to i64
  %.pre = load i32, ptr %.phi.trans.insert22, align 4, !tbaa !5
  %.pre21 = load i32, ptr @w, align 4, !tbaa !5
  br label %16

10:                                               ; preds = %5
  %11 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @ans, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %12 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %12, ptr @ans, align 4, !tbaa !5
  br label %common.ret28

common.ret28:                                     ; preds = %2, %10, %._crit_edge
  ret void

._crit_edge:                                      ; preds = %26, %.preheader.._crit_edge_crit_edge
  %.pre-phi27 = phi i32 [ %.pre26, %.preheader.._crit_edge_crit_edge ], [ %9, %26 ]
  %13 = phi i32 [ %.pre23, %.preheader.._crit_edge_crit_edge ], [ %28, %26 ]
  %14 = sext i32 %.pre24 to i64
  %15 = getelementptr inbounds [20 x i32], ptr @cab, i64 0, i64 %14
  store i32 %13, ptr %15, align 4, !tbaa !5
  tail call void @_Z3dfsii(i32 noundef %.pre-phi27, i32 noundef %.pre24)
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %common.ret28

16:                                               ; preds = %.lr.ph, %26
  %17 = phi i32 [ %.pre21, %.lr.ph ], [ %27, %26 ]
  %18 = phi i32 [ %.pre, %.lr.ph ], [ %28, %26 ]
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %26 ]
  %19 = getelementptr inbounds [20 x i32], ptr @cab, i64 0, i64 %indvars.iv
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = add nsw i32 %18, %20
  %.not16 = icmp sgt i32 %21, %17
  br i1 %.not16, label %26, label %22

22:                                               ; preds = %16
  store i32 %21, ptr %19, align 4, !tbaa !5
  tail call void @_Z3dfsii(i32 noundef %9, i32 noundef %1)
  %23 = load i32, ptr %.phi.trans.insert22, align 4, !tbaa !5
  %24 = load i32, ptr %19, align 4, !tbaa !5
  %25 = sub nsw i32 %24, %23
  store i32 %25, ptr %19, align 4, !tbaa !5
  %.pre20 = load i32, ptr @w, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %16, %22
  %27 = phi i32 [ %17, %16 ], [ %.pre20, %22 ]
  %28 = phi i32 [ %18, %16 ], [ %23, %22 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %16, !llvm.loop !9
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

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

!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: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass