; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/5799.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.Edge = type { i32, i32 }

@edge = external dso_local global [200020 x %struct.Edge], align 16
@head = external dso_local global [100010 x i32], align 16
@idx = external dso_local global i32, align 4
@L = external dso_local global [100010 x i32], align 16
@R = external dso_local global [100010 x i32], align 16
@dep = external dso_local global [100010 x i32], align 16
@fa = external dso_local global [100010 x i32], align 16
@is = external dso_local global [100010 x i32], align 16
@st = external dso_local global [100010 x i32], align 16
@stn = external dso_local global i32, align 4
@pos = external dso_local global [100010 x i32], align 16
@b_cnt = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3dfsii(i32 noundef %0, i32 noundef %1) #0 {
  %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
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr @idx, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr @idx, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100010 x i32], ptr @L, i64 0, i64 %12
  store i32 %10, ptr %13, align 4, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr @idx, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100010 x i32], ptr @is, i64 0, i64 %16
  store i32 %14, ptr %17, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100010 x i32], ptr @dep, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100010 x i32], ptr @dep, i64 0, i64 %24
  store i32 %22, ptr %25, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100010 x i32], ptr @fa, i64 0, i64 %28
  store i32 %26, ptr %29, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  store i32 %33, ptr %6, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %77, %2
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = icmp ne i32 %35, -1
  br i1 %36, label %38, label %37

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

38:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [200020 x %struct.Edge], ptr @edge, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.Edge, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !9
  store i32 %43, ptr %8, align 4, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = icmp eq i32 %44, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %38
  store i32 4, ptr %7, align 4
  br label %74

48:                                               ; preds = %38
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = call noundef i32 @_Z3dfsii(i32 noundef %49, i32 noundef %50)
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = add nsw i32 %52, %51
  store i32 %53, ptr %5, align 4, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = icmp sgt i32 %54, 200
  br i1 %55, label %56, label %73

56:                                               ; preds = %48
  br label %57

57:                                               ; preds = %61, %56
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = add nsw i32 %58, -1
  store i32 %59, ptr %5, align 4, !tbaa !5
  %60 = icmp ne i32 %58, 0
  br i1 %60, label %61, label %70

61:                                               ; preds = %57
  %62 = load i32, ptr @b_cnt, align 4, !tbaa !5
  %63 = load i32, ptr @stn, align 4, !tbaa !5
  %64 = add nsw i32 %63, -1
  store i32 %64, ptr @stn, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [100010 x i32], ptr @st, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [100010 x i32], ptr @pos, i64 0, i64 %68
  store i32 %62, ptr %69, align 4, !tbaa !5
  br label %57, !llvm.loop !11

70:                                               ; preds = %57
  %71 = load i32, ptr @b_cnt, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr @b_cnt, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %70, %48
  store i32 0, ptr %7, align 4
  br label %74

74:                                               ; preds = %73, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %75 = load i32, ptr %7, align 4
  switch i32 %75, label %95 [
    i32 0, label %76
    i32 4, label %77
  ]

76:                                               ; preds = %74
  br label %77

77:                                               ; preds = %76, %74
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [200020 x %struct.Edge], ptr @edge, i64 0, i64 %79
  %81 = getelementptr inbounds %struct.Edge, ptr %80, i32 0, i32 1
  %82 = load i32, ptr %81, align 4, !tbaa !13
  store i32 %82, ptr %6, align 4, !tbaa !5
  br label %34, !llvm.loop !14

83:                                               ; preds = %37
  %84 = load i32, ptr %3, align 4, !tbaa !5
  %85 = load i32, ptr @stn, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr @stn, align 4, !tbaa !5
  %87 = sext i32 %85 to i64
  %88 = getelementptr inbounds [100010 x i32], ptr @st, i64 0, i64 %87
  store i32 %84, ptr %88, align 4, !tbaa !5
  %89 = load i32, ptr @idx, align 4, !tbaa !5
  %90 = load i32, ptr %3, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [100010 x i32], ptr @R, i64 0, i64 %91
  store i32 %89, ptr %92, align 4, !tbaa !5
  %93 = load i32, ptr %5, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %94

95:                                               ; preds = %74
  unreachable
}

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

; 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 = { 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, !6, i64 0}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!10, !6, i64 4}
!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"

%struct.Edge = type { i32, i32 }

@edge = external dso_local local_unnamed_addr global [200020 x %struct.Edge], align 16
@head = external dso_local local_unnamed_addr global [100010 x i32], align 16
@idx = external dso_local local_unnamed_addr global i32, align 4
@L = external dso_local local_unnamed_addr global [100010 x i32], align 16
@R = external dso_local local_unnamed_addr global [100010 x i32], align 16
@dep = external dso_local local_unnamed_addr global [100010 x i32], align 16
@fa = external dso_local local_unnamed_addr global [100010 x i32], align 16
@is = external dso_local local_unnamed_addr global [100010 x i32], align 16
@st = external dso_local local_unnamed_addr global [100010 x i32], align 16
@stn = external dso_local local_unnamed_addr global i32, align 4
@pos = external dso_local local_unnamed_addr global [100010 x i32], align 16
@b_cnt = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 -2147483647, -2147483648) i32 @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @idx, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @idx, align 4, !tbaa !5
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [100010 x i32], ptr @L, i64 0, i64 %5
  store i32 %4, ptr %6, align 4, !tbaa !5
  %7 = sext i32 %4 to i64
  %8 = getelementptr inbounds [100010 x i32], ptr @is, i64 0, i64 %7
  store i32 %0, ptr %8, align 4, !tbaa !5
  %9 = sext i32 %1 to i64
  %10 = getelementptr inbounds [100010 x i32], ptr @dep, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  %13 = getelementptr inbounds [100010 x i32], ptr @dep, i64 0, i64 %5
  store i32 %12, ptr %13, align 4, !tbaa !5
  %14 = getelementptr inbounds [100010 x i32], ptr @fa, i64 0, i64 %5
  store i32 %1, ptr %14, align 4, !tbaa !5
  %15 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %5
  %.02026 = load i32, ptr %15, align 4, !tbaa !5
  %.not27 = icmp eq i32 %.02026, -1
  br i1 %.not27, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %60
  %.pre = load i32, ptr @idx, align 4, !tbaa !5
  %16 = add nsw i32 %.3, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %17 = phi i32 [ %4, %2 ], [ %.pre, %._crit_edge.loopexit ]
  %.0.lcssa = phi i32 [ 1, %2 ], [ %16, %._crit_edge.loopexit ]
  %18 = load i32, ptr @stn, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @stn, align 4, !tbaa !5
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds [100010 x i32], ptr @st, i64 0, i64 %20
  store i32 %0, ptr %21, align 4, !tbaa !5
  %22 = getelementptr inbounds [100010 x i32], ptr @R, i64 0, i64 %5
  store i32 %17, ptr %22, align 4, !tbaa !5
  ret i32 %.0.lcssa

.lr.ph:                                           ; preds = %2, %60
  %.02029 = phi i32 [ %.020, %60 ], [ %.02026, %2 ]
  %.028 = phi i32 [ %.3, %60 ], [ 0, %2 ]
  %23 = sext i32 %.02029 to i64
  %24 = getelementptr inbounds [200020 x %struct.Edge], ptr @edge, i64 0, i64 %23
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %26 = icmp eq i32 %25, %1
  br i1 %26, label %60, label %27

27:                                               ; preds = %.lr.ph
  %28 = tail call noundef i32 @_Z3dfsii(i32 noundef %25, i32 noundef %0)
  %29 = add nsw i32 %28, %.028
  %30 = icmp sgt i32 %29, 200
  br i1 %30, label %.preheader, label %60

.preheader:                                       ; preds = %27
  %31 = load i32, ptr @b_cnt, align 4, !tbaa !5
  %stn.promoted = load i32, ptr @stn, align 4, !tbaa !5
  %32 = sext i32 %stn.promoted to i64
  %33 = add nsw i32 %28, -1
  %34 = add i32 %33, %.028
  %xtraiter = and i32 %29, 3
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.preheader

.prol.preheader:                                  ; preds = %.preheader, %.prol.preheader
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.prol.preheader ], [ %32, %.preheader ]
  %.125.prol = phi i32 [ %35, %.prol.preheader ], [ %29, %.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %.prol.preheader ], [ 0, %.preheader ]
  %35 = add nsw i32 %.125.prol, -1
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, -1
  %36 = getelementptr inbounds [100010 x i32], ptr @st, i64 0, i64 %indvars.iv.next.prol
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [100010 x i32], ptr @pos, i64 0, i64 %38
  store i32 %31, ptr %39, align 4, !tbaa !5
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.prol.loopexit, label %.prol.preheader, !llvm.loop !11

.prol.loopexit:                                   ; preds = %.prol.preheader, %.preheader
  %indvars.iv.next.lcssa.unr = phi i64 [ poison, %.preheader ], [ %indvars.iv.next.prol, %.prol.preheader ]
  %indvars.iv.unr = phi i64 [ %32, %.preheader ], [ %indvars.iv.next.prol, %.prol.preheader ]
  %.125.unr = phi i32 [ %29, %.preheader ], [ %35, %.prol.preheader ]
  %40 = icmp ult i32 %34, 3
  br i1 %40, label %.unr-lcssa, label %.preheader.new

.preheader.new:                                   ; preds = %.prol.loopexit, %.preheader.new
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.preheader.new ], [ %indvars.iv.unr, %.prol.loopexit ]
  %.125 = phi i32 [ %53, %.preheader.new ], [ %.125.unr, %.prol.loopexit ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %41 = getelementptr inbounds [100010 x i32], ptr @st, i64 0, i64 %indvars.iv.next
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100010 x i32], ptr @pos, i64 0, i64 %43
  store i32 %31, ptr %44, align 4, !tbaa !5
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, -2
  %45 = getelementptr inbounds [100010 x i32], ptr @st, i64 0, i64 %indvars.iv.next.1
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100010 x i32], ptr @pos, i64 0, i64 %47
  store i32 %31, ptr %48, align 4, !tbaa !5
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, -3
  %49 = getelementptr inbounds [100010 x i32], ptr @st, i64 0, i64 %indvars.iv.next.2
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100010 x i32], ptr @pos, i64 0, i64 %51
  store i32 %31, ptr %52, align 4, !tbaa !5
  %53 = add nsw i32 %.125, -4
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, -4
  %54 = getelementptr inbounds [100010 x i32], ptr @st, i64 0, i64 %indvars.iv.next.3
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100010 x i32], ptr @pos, i64 0, i64 %56
  store i32 %31, ptr %57, align 4, !tbaa !5
  %.not24.3 = icmp eq i32 %53, 0
  br i1 %.not24.3, label %.unr-lcssa, label %.preheader.new, !llvm.loop !13

.unr-lcssa:                                       ; preds = %.preheader.new, %.prol.loopexit
  %indvars.iv.next.lcssa = phi i64 [ %indvars.iv.next.lcssa.unr, %.prol.loopexit ], [ %indvars.iv.next.3, %.preheader.new ]
  %58 = trunc nsw i64 %indvars.iv.next.lcssa to i32
  store i32 %58, ptr @stn, align 4, !tbaa !5
  %59 = add nsw i32 %31, 1
  store i32 %59, ptr @b_cnt, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %27, %.unr-lcssa, %.lr.ph
  %.3 = phi i32 [ %.028, %.lr.ph ], [ -1, %.unr-lcssa ], [ %29, %27 ]
  %61 = getelementptr inbounds i8, ptr %24, i64 4
  %.020 = load i32, ptr %61, align 4, !tbaa !5
  %.not = icmp eq i32 %.020, -1
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !15
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass