; LLVM IR from tangjz/acm-icpc :: lydsy/1165.ll (Z4dfs3i)

; 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.Edge = type { i32, i32 }

@nn = external dso_local global i32, align 4
@pre = external dso_local global [1000001 x i32], align 16
@lnk = external dso_local global [1000001 x i32], align 16
@que = external dso_local global [1000001 x i32], align 16
@scc = external dso_local global [1000001 x i32], align 16
@e = external dso_local global [4000005 x %struct.Edge], align 16
@vis = external dso_local global [1000001 x i8], 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
define dso_local noundef zeroext i1 @_Z4dfs3i(i32 noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %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
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %12
  store i8 1, ptr %13, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [1000001 x i32], ptr @pre, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %17, ptr %5, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %50, %1
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = icmp ne i32 %19, -1
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  store i32 2, ptr %6, align 4
  br label %56

22:                                               ; preds = %18
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [4000005 x %struct.Edge], ptr @e, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.Edge, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !9, !range !13, !noundef !14
  %31 = trunc i8 %30 to i1
  br i1 %31, label %40, label %32

32:                                               ; preds = %22
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [4000005 x %struct.Edge], ptr @e, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.Edge, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = call noundef zeroext i1 @_Z4dfs3i(i32 noundef %37)
  br i1 %38, label %40, label %39

39:                                               ; preds = %32
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %56

40:                                               ; preds = %32, %22
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [4000005 x %struct.Edge], ptr @e, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.Edge, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !11
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1000001 x i32], ptr @que, i64 0, i64 %46
  %48 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %47)
  %49 = load i32, ptr %48, align 4, !tbaa !5
  store i32 %49, ptr %4, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %40
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [4000005 x %struct.Edge], ptr @e, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.Edge, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !15
  store i32 %55, ptr %5, align 4, !tbaa !5
  br label %18, !llvm.loop !16

56:                                               ; preds = %39, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %57 = load i32, ptr %6, align 4
  switch i32 %57, label %121 [
    i32 2, label %58
  ]

58:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1000001 x i32], ptr @lnk, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  store i32 %62, ptr %7, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %106, %58
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = icmp ne i32 %64, -1
  br i1 %65, label %67, label %66

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

67:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [4000005 x %struct.Edge], ptr @e, i64 0, i64 %69
  %71 = getelementptr inbounds %struct.Edge, ptr %70, i32 0, i32 1
  %72 = load i32, ptr %71, align 4, !tbaa !11
  store i32 %72, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = load i32, ptr @nn, align 4, !tbaa !5
  %75 = icmp sle i32 %73, %74
  br i1 %75, label %76, label %80

76:                                               ; preds = %67
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = load i32, ptr @nn, align 4, !tbaa !5
  %79 = add nsw i32 %77, %78
  br label %84

80:                                               ; preds = %67
  %81 = load i32, ptr %8, align 4, !tbaa !5
  %82 = load i32, ptr @nn, align 4, !tbaa !5
  %83 = sub nsw i32 %81, %82
  br label %84

84:                                               ; preds = %80, %76
  %85 = phi i32 [ %79, %76 ], [ %83, %80 ]
  store i32 %85, ptr %9, align 4, !tbaa !5
  %86 = load i32, ptr %9, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [1000001 x i32], ptr @scc, i64 0, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %90
  %92 = load i8, ptr %91, align 1, !tbaa !9, !range !13, !noundef !14
  %93 = trunc i8 %92 to i1
  br i1 %93, label %94, label %105

94:                                               ; preds = %84
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %95 = load i32, ptr %9, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [1000001 x i32], ptr @scc, i64 0, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [1000001 x i32], ptr @que, i64 0, i64 %99
  %101 = load i32, ptr %100, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %10, align 4, !tbaa !5
  %103 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %104 = load i32, ptr %103, align 4, !tbaa !5
  store i32 %104, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %105

105:                                              ; preds = %94, %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %7, align 4, !tbaa !5
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [4000005 x %struct.Edge], ptr @e, i64 0, i64 %108
  %110 = getelementptr inbounds %struct.Edge, ptr %109, i32 0, i32 0
  %111 = load i32, ptr %110, align 8, !tbaa !15
  store i32 %111, ptr %7, align 4, !tbaa !5
  br label %63, !llvm.loop !18

112:                                              ; preds = %66
  %113 = load i32, ptr %4, align 4, !tbaa !5
  %114 = icmp sgt i32 %113, 1
  br i1 %114, label %115, label %116

115:                                              ; preds = %112
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %121

116:                                              ; preds = %112
  %117 = load i32, ptr %4, align 4, !tbaa !5
  %118 = load i32, ptr %3, align 4, !tbaa !5
  %119 = sext i32 %118 to i64
  %120 = getelementptr inbounds [1000001 x i32], ptr @que, i64 0, i64 %119
  store i32 %117, ptr %120, align 4, !tbaa !5
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %121

121:                                              ; preds = %116, %115, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %122 = load i1, ptr %2, align 1
  ret i1 %122
}

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

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 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !6, i64 4}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!12, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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.Edge = type { i32, i32 }

@nn = external dso_local local_unnamed_addr global i32, align 4
@pre = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@lnk = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@que = external dso_local global [1000001 x i32], align 16
@scc = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@e = external dso_local local_unnamed_addr global [4000005 x %struct.Edge], align 16
@vis = external dso_local local_unnamed_addr global [1000001 x i8], align 16

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

; Function Attrs: mustprogress 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 zeroext i1 @_Z4dfs3i(i32 noundef %0) local_unnamed_addr #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %4
  store i8 1, ptr %5, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  store i32 0, ptr %2, align 4, !tbaa !9
  %6 = getelementptr inbounds [1000001 x i32], ptr @pre, i64 0, i64 %4
  %.01827 = load i32, ptr %6, align 4, !tbaa !9
  %.not28 = icmp eq i32 %.01827, -1
  br i1 %.not28, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %17
  %.01829 = phi i32 [ %.018, %17 ], [ %.01827, %1 ]
  %7 = sext i32 %.01829 to i64
  %8 = getelementptr inbounds [4000005 x %struct.Edge], ptr @e, i64 0, i64 %7
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !5, !range !13, !noundef !14
  %14 = trunc nuw i8 %13 to i1
  br i1 %14, label %17, label %15

15:                                               ; preds = %.lr.ph
  %16 = call noundef zeroext i1 @_Z4dfs3i(i32 noundef %10)
  br i1 %16, label %._crit_edge34, label %.loopexit

._crit_edge34:                                    ; preds = %15
  %.pre = load i32, ptr %9, align 4, !tbaa !11
  %.pre37 = sext i32 %.pre to i64
  br label %17

17:                                               ; preds = %._crit_edge34, %.lr.ph
  %.pre-phi = phi i64 [ %.pre37, %._crit_edge34 ], [ %11, %.lr.ph ]
  %18 = getelementptr inbounds [1000001 x i32], ptr @que, i64 0, i64 %.pre-phi
  %19 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %18)
  %20 = load i32, ptr %19, align 4, !tbaa !9
  store i32 %20, ptr %2, align 4, !tbaa !9
  %.018 = load i32, ptr %8, align 8, !tbaa !9
  %.not = icmp eq i32 %.018, -1
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !15

.critedge:                                        ; preds = %17, %1
  %21 = phi i32 [ 0, %1 ], [ %20, %17 ]
  %22 = getelementptr inbounds [1000001 x i32], ptr @lnk, i64 0, i64 %4
  %.01930 = load i32, ptr %22, align 4, !tbaa !9
  %.not2531 = icmp eq i32 %.01930, -1
  br i1 %.not2531, label %._crit_edge, label %.lr.ph33.preheader

.lr.ph33.preheader:                               ; preds = %.critedge
  %.pre36 = load i32, ptr @nn, align 4, !tbaa !9
  br label %.lr.ph33

._crit_edge:                                      ; preds = %46, %.critedge
  %23 = phi i32 [ %21, %.critedge ], [ %47, %46 ]
  %24 = icmp sgt i32 %23, 1
  br i1 %24, label %.loopexit, label %49

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %46
  %25 = phi i32 [ %47, %46 ], [ %21, %.lr.ph33.preheader ]
  %26 = phi i32 [ %48, %46 ], [ %.pre36, %.lr.ph33.preheader ]
  %.01932 = phi i32 [ %.019, %46 ], [ %.01930, %.lr.ph33.preheader ]
  %27 = sext i32 %.01932 to i64
  %28 = getelementptr inbounds [4000005 x %struct.Edge], ptr @e, i64 0, i64 %27
  %29 = getelementptr inbounds i8, ptr %28, i64 4
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %.not26 = icmp sgt i32 %30, %26
  %31 = sub i32 0, %26
  %.p = select i1 %.not26, i32 %31, i32 %26
  %32 = add i32 %.p, %30
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1000001 x i32], ptr @scc, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !5, !range !13, !noundef !14
  %39 = trunc nuw i8 %38 to i1
  br i1 %39, label %40, label %46

40:                                               ; preds = %.lr.ph33
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %41 = getelementptr inbounds [1000001 x i32], ptr @que, i64 0, i64 %36
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %3, align 4, !tbaa !9
  %44 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %45 = load i32, ptr %44, align 4, !tbaa !9
  store i32 %45, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  %.pre35 = load i32, ptr @nn, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %40, %.lr.ph33
  %47 = phi i32 [ %45, %40 ], [ %25, %.lr.ph33 ]
  %48 = phi i32 [ %.pre35, %40 ], [ %26, %.lr.ph33 ]
  %.019 = load i32, ptr %28, align 8, !tbaa !9
  %.not25 = icmp eq i32 %.019, -1
  br i1 %.not25, label %._crit_edge, label %.lr.ph33, !llvm.loop !17

49:                                               ; preds = %._crit_edge
  %50 = getelementptr inbounds [1000001 x i32], ptr @que, i64 0, i64 %4
  store i32 %23, ptr %50, align 4, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %15, %._crit_edge, %49
  %.1 = phi i1 [ true, %49 ], [ false, %._crit_edge ], [ false, %15 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  ret i1 %.1
}

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

attributes #0 = { mustprogress 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 = { 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 #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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTS4Edge", !10, i64 0, !10, i64 4}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass