; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p1330.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 }

@e = external dso_local global [200010 x %struct.edge], align 16
@head = external dso_local global [10010 x i32], align 16
@color = external dso_local global [10010 x i32], align 16
@type_1 = external dso_local global i32, align 4
@type_2 = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i1, align 1
  %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 %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [10010 x i32], ptr @color, i64 0, i64 %11
  store i32 %9, ptr %12, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %18

15:                                               ; preds = %2
  %16 = load i32, ptr @type_1, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @type_1, align 4, !tbaa !5
  br label %21

18:                                               ; preds = %2
  %19 = load i32, ptr @type_2, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @type_2, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %18, %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10010 x i32], ptr @head, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  store i32 %25, ptr %6, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %61, %21
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 2, ptr %7, align 4
  br label %67

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %32
  %34 = getelementptr inbounds %struct.edge, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !9
  store i32 %35, ptr %8, align 4, !tbaa !5
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10010 x i32], ptr @color, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %48, label %41

41:                                               ; preds = %30
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sub nsw i32 3, %43
  %45 = call noundef zeroext i1 @_Z3dfsii(i32 noundef %42, i32 noundef %44)
  br i1 %45, label %47, label %46

46:                                               ; preds = %41
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %58

47:                                               ; preds = %41
  br label %57

48:                                               ; preds = %30
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [10010 x i32], ptr @color, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = icmp eq i32 %52, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %48
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %58

56:                                               ; preds = %48
  br label %57

57:                                               ; preds = %56, %47
  store i32 0, ptr %7, align 4
  br label %58

58:                                               ; preds = %57, %55, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %59 = load i32, ptr %7, align 4
  switch i32 %59, label %67 [
    i32 0, label %60
  ]

60:                                               ; preds = %58
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.edge, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 4, !tbaa !11
  store i32 %66, ptr %6, align 4, !tbaa !5
  br label %26, !llvm.loop !12

67:                                               ; preds = %58, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %68 = load i32, ptr %7, align 4
  switch i32 %68, label %72 [
    i32 2, label %69
    i32 1, label %70
  ]

69:                                               ; preds = %67
  store i1 true, ptr %3, align 1
  br label %70

70:                                               ; preds = %69, %67
  %71 = load i1, ptr %3, align 1
  ret i1 %71

72:                                               ; preds = %67
  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 = !{!10, !6, i64 4}
!12 = distinct !{!12, !13}
!13 = !{!"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"

%struct.edge = type { i32, i32 }

@e = external dso_local local_unnamed_addr global [200010 x %struct.edge], align 16
@head = external dso_local local_unnamed_addr global [10010 x i32], align 16
@color = external dso_local local_unnamed_addr global [10010 x i32], align 16
@type_1 = external dso_local local_unnamed_addr global i32, align 4
@type_2 = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [10010 x i32], ptr @color, i64 0, i64 %3
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = icmp eq i32 %1, 1
  %type_1.type_2 = select i1 %5, ptr @type_1, ptr @type_2
  %6 = load i32, ptr %type_1.type_2, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr %type_1.type_2, align 4, !tbaa !5
  %8 = getelementptr inbounds [10010 x i32], ptr @head, i64 0, i64 %3
  %.01619 = load i32, ptr %8, align 4, !tbaa !5
  %.not20 = icmp eq i32 %.01619, 0
  br i1 %.not20, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %9 = sub nsw i32 3, %1
  br label %10

10:                                               ; preds = %.lr.ph, %.critedge
  %.01621 = phi i32 [ %.01619, %.lr.ph ], [ %.016, %.critedge ]
  %11 = sext i32 %.01621 to i64
  %12 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %11
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [10010 x i32], ptr @color, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %.not18 = icmp eq i32 %16, 0
  br i1 %.not18, label %17, label %19

17:                                               ; preds = %10
  %18 = tail call noundef zeroext i1 @_Z3dfsii(i32 noundef %13, i32 noundef %9)
  br i1 %18, label %.critedge, label %._crit_edge

19:                                               ; preds = %10
  %20 = icmp eq i32 %16, %1
  br i1 %20, label %._crit_edge, label %.critedge

.critedge:                                        ; preds = %19, %17
  %21 = getelementptr inbounds i8, ptr %12, i64 4
  %.016 = load i32, ptr %21, align 4, !tbaa !5
  %.not = icmp eq i32 %.016, 0
  br i1 %.not, label %._crit_edge, label %10, !llvm.loop !11

._crit_edge:                                      ; preds = %.critedge, %19, %17, %2
  %.not.lcssa = phi i1 [ true, %2 ], [ false, %17 ], [ false, %19 ], [ true, %.critedge ]
  ret i1 %.not.lcssa
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: read, 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.mustprogress"}


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