; LLVM IR from upupming/algorithm :: acwing/寒假每日一题（提高组）/week1/1402. 星空之夜.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"

%"struct.std::pair" = type { i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@top = external dso_local global i32, align 4
@g = external dso_local global [110 x [110 x i8]], align 16
@q = external dso_local global [12100 x %"struct.std::pair"], align 16

; 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 %"struct.std::pair", align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %5, ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %9 = load i32, ptr @top, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr @top, align 4, !tbaa !5
  %11 = sext i32 %9 to i64
  %12 = getelementptr inbounds [12100 x %"struct.std::pair"], ptr @q, i64 0, i64 %11
  %13 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %12, ptr noundef nonnull align 4 dereferenceable(8) %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [110 x [110 x i8]], ptr @g, i64 0, i64 %15
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [110 x i8], ptr %16, i64 0, i64 %18
  store i8 48, ptr %19, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sub nsw i32 %20, 1
  store i32 %21, ptr %6, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %78, %2
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  %26 = icmp sle i32 %23, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %81

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sub nsw i32 %29, 1
  store i32 %30, ptr %8, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %74, %28
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  %35 = icmp sle i32 %32, %34
  br i1 %35, label %37, label %36

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

37:                                               ; preds = %31
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = icmp eq i32 %38, %39
  br i1 %40, label %41, label %46

41:                                               ; preds = %37
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = icmp eq i32 %42, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  br label %74

46:                                               ; preds = %41, %37
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = icmp sge i32 %47, 0
  br i1 %48, label %49, label %73

49:                                               ; preds = %46
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = load i32, ptr @n, align 4, !tbaa !5
  %52 = icmp slt i32 %50, %51
  br i1 %52, label %53, label %73

53:                                               ; preds = %49
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = icmp sge i32 %54, 0
  br i1 %55, label %56, label %73

56:                                               ; preds = %53
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = load i32, ptr @m, align 4, !tbaa !5
  %59 = icmp slt i32 %57, %58
  br i1 %59, label %60, label %73

60:                                               ; preds = %56
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [110 x [110 x i8]], ptr @g, i64 0, i64 %62
  %64 = load i32, ptr %8, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [110 x i8], ptr %63, i64 0, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !9
  %68 = sext i8 %67 to i32
  %69 = icmp eq i32 %68, 49
  br i1 %69, label %70, label %73

70:                                               ; preds = %60
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %71, i32 noundef %72)
  br label %73

73:                                               ; preds = %70, %60, %56, %53, %49, %46
  br label %74

74:                                               ; preds = %73, %45
  %75 = load i32, ptr %8, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %8, align 4, !tbaa !5
  br label %31, !llvm.loop !10

77:                                               ; preds = %36
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %6, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %6, align 4, !tbaa !5
  br label %22, !llvm.loop !12

81:                                               ; preds = %27
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #2 align 2

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

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


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

%"struct.std::pair" = type { i32, i32 }

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@top = external dso_local local_unnamed_addr global i32, align 4
@g = external dso_local local_unnamed_addr global [110 x [110 x i8]], align 16
@q = external dso_local global [12100 x %"struct.std::pair"], align 16

; 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
  %4 = alloca i32, align 4
  %5 = alloca %"struct.std::pair", align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #2
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %5, ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %6 = load i32, ptr @top, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @top, align 4, !tbaa !5
  %8 = sext i32 %6 to i64
  %9 = getelementptr inbounds [12100 x %"struct.std::pair"], ptr @q, i64 0, i64 %8
  %10 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %9, ptr noundef nonnull align 4 dereferenceable(8) %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #2
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %.fr35 = freeze i32 %11
  %12 = sext i32 %.fr35 to i64
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [110 x [110 x i8]], ptr @g, i64 0, i64 %12, i64 %14
  store i8 48, ptr %15, align 1, !tbaa !9
  %16 = add i32 %.fr35, -1
  %17 = add nsw i32 %.fr35, 1
  %.not26 = icmp sgt i32 %16, %17
  br i1 %.not26, label %._crit_edge32, label %.lr.ph

._crit_edge32:                                    ; preds = %._crit_edge, %2
  ret void

.lr.ph:                                           ; preds = %2, %._crit_edge
  %18 = phi i32 [ %46, %._crit_edge ], [ %.fr35, %2 ]
  %19 = phi i32 [ %47, %._crit_edge ], [ %.fr35, %2 ]
  %20 = phi i32 [ %48, %._crit_edge ], [ %13, %2 ]
  %21 = phi i32 [ %49, %._crit_edge ], [ %13, %2 ]
  %22 = phi i32 [ %50, %._crit_edge ], [ %13, %2 ]
  %.01827 = phi i32 [ %51, %._crit_edge ], [ %16, %2 ]
  %.old2 = icmp sgt i32 %.01827, -1
  %23 = zext nneg i32 %.01827 to i64
  br i1 %.old2, label %.lr.ph.split.us.preheader, label %.lr.ph.split

.lr.ph.split.us.preheader:                        ; preds = %.lr.ph
  %24 = add nsw i32 %22, -1
  br label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph.split.us.preheader, %42
  %25 = phi i32 [ %43, %42 ], [ %20, %.lr.ph.split.us.preheader ]
  %26 = phi i32 [ %43, %42 ], [ %22, %.lr.ph.split.us.preheader ]
  %.023.us = phi i32 [ %44, %42 ], [ %24, %.lr.ph.split.us.preheader ]
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = icmp ne i32 %.01827, %27
  %29 = icmp ne i32 %.023.us, %26
  %or.cond33 = or i1 %28, %29
  br i1 %or.cond33, label %30, label %42

30:                                               ; preds = %.lr.ph.split.us
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = icmp slt i32 %.01827, %31
  %33 = icmp sgt i32 %.023.us, -1
  %or.cond.us = and i1 %33, %32
  %34 = load i32, ptr @m, align 4
  %35 = icmp slt i32 %.023.us, %34
  %or.cond21.us = select i1 %or.cond.us, i1 %35, i1 false
  br i1 %or.cond21.us, label %36, label %42

36:                                               ; preds = %30
  %37 = zext nneg i32 %.023.us to i64
  %38 = getelementptr inbounds [110 x [110 x i8]], ptr @g, i64 0, i64 %23, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !9
  %40 = icmp eq i8 %39, 49
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  call void @_Z3dfsii(i32 noundef %.01827, i32 noundef %.023.us)
  %.pre = load i32, ptr %4, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %.lr.ph.split.us, %41, %36, %30
  %43 = phi i32 [ %25, %.lr.ph.split.us ], [ %.pre, %41 ], [ %25, %36 ], [ %25, %30 ]
  %44 = add nsw i32 %.023.us, 1
  %.not19.us = icmp sgt i32 %.023.us, %43
  br i1 %.not19.us, label %._crit_edge.loopexit, label %.lr.ph.split.us, !llvm.loop !10

.lr.ph.split:                                     ; preds = %.lr.ph
  %45 = icmp eq i32 %.01827, %19
  %spec.select = select i1 %45, i32 %18, i32 %19
  %spec.select43 = select i1 %45, i32 %21, i32 %22
  br label %._crit_edge

._crit_edge.loopexit:                             ; preds = %42
  %.pre40 = load i32, ptr %3, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.split, %._crit_edge.loopexit
  %46 = phi i32 [ %.pre40, %._crit_edge.loopexit ], [ %18, %.lr.ph.split ]
  %47 = phi i32 [ %.pre40, %._crit_edge.loopexit ], [ %spec.select, %.lr.ph.split ]
  %48 = phi i32 [ %43, %._crit_edge.loopexit ], [ %20, %.lr.ph.split ]
  %49 = phi i32 [ %43, %._crit_edge.loopexit ], [ %21, %.lr.ph.split ]
  %50 = phi i32 [ %43, %._crit_edge.loopexit ], [ %spec.select43, %.lr.ph.split ]
  %51 = add i32 %.01827, 1
  %52 = add nsw i32 %47, 1
  %.not = icmp sgt i32 %51, %52
  br i1 %.not, label %._crit_edge32, label %.lr.ph, !llvm.loop !12
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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