; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p1525.ll (Z3dfsiii)

; 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, i32 }

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i1, align 1
  %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 %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %11 = load i32, ptr %6, align 4, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100010 x i32], ptr @color, i64 0, i64 %13
  store i32 %11, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  store i32 %18, ptr %8, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %64, %3
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  store i32 2, ptr %9, align 4
  br label %70

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.edge, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 4, !tbaa !9
  store i32 %28, ptr %10, align 4, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.edge, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %23
  store i32 4, ptr %9, align 4
  br label %61

37:                                               ; preds = %23
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100010 x i32], ptr @color, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %51, label %43

43:                                               ; preds = %37
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = sub nsw i32 3, %45
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = call noundef zeroext i1 @_Z3dfsiii(i32 noundef %44, i32 noundef %46, i32 noundef %47)
  br i1 %48, label %50, label %49

49:                                               ; preds = %43
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %61

50:                                               ; preds = %43
  br label %60

51:                                               ; preds = %37
  %52 = load i32, ptr %10, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100010 x i32], ptr @color, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = icmp eq i32 %55, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %51
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %61

59:                                               ; preds = %51
  br label %60

60:                                               ; preds = %59, %50
  store i32 0, ptr %9, align 4
  br label %61

61:                                               ; preds = %60, %58, %49, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %62 = load i32, ptr %9, align 4
  switch i32 %62, label %70 [
    i32 0, label %63
    i32 4, label %64
  ]

63:                                               ; preds = %61
  br label %64

64:                                               ; preds = %63, %61
  %65 = load i32, ptr %8, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %66
  %68 = getelementptr inbounds %struct.edge, ptr %67, i32 0, i32 2
  %69 = load i32, ptr %68, align 4, !tbaa !12
  store i32 %69, ptr %8, align 4, !tbaa !5
  br label %19, !llvm.loop !13

70:                                               ; preds = %61, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %71 = load i32, ptr %9, align 4
  switch i32 %71, label %75 [
    i32 2, label %72
    i32 1, label %73
  ]

72:                                               ; preds = %70
  store i1 true, ptr %4, align 1
  br label %73

73:                                               ; preds = %72, %70
  %74 = load i1, ptr %4, align 1
  ret i1 %74

75:                                               ; preds = %70
  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, !6, i64 8}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"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, i32 }

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

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [100010 x i32], ptr @color, i64 0, i64 %4
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %4
  %.01823 = load i32, ptr %6, align 4, !tbaa !5
  %.not24 = icmp eq i32 %.01823, 0
  br i1 %.not24, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %7 = sub nsw i32 3, %1
  br label %8

8:                                                ; preds = %.lr.ph, %23
  %.01825 = phi i32 [ %.01823, %.lr.ph ], [ %.018, %23 ]
  %9 = sext i32 %.01825 to i64
  %10 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %10, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = icmp slt i32 %13, %2
  br i1 %14, label %23, label %15

15:                                               ; preds = %8
  %16 = sext i32 %11 to i64
  %17 = getelementptr inbounds [100010 x i32], ptr @color, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %.not21 = icmp eq i32 %18, 0
  br i1 %.not21, label %19, label %21

19:                                               ; preds = %15
  %20 = tail call noundef zeroext i1 @_Z3dfsiii(i32 noundef %11, i32 noundef %7, i32 noundef %2)
  br i1 %20, label %23, label %.thread

21:                                               ; preds = %15
  %22 = icmp eq i32 %18, %1
  br i1 %22, label %.thread, label %23

23:                                               ; preds = %19, %21, %8
  %24 = getelementptr inbounds i8, ptr %10, i64 8
  %.018 = load i32, ptr %24, align 4, !tbaa !5
  %.not = icmp eq i32 %.018, 0
  br i1 %.not, label %.thread, label %8, !llvm.loop !12

.thread:                                          ; preds = %23, %19, %21, %3
  %.not.lcssa = phi i1 [ true, %3 ], [ false, %21 ], [ false, %19 ], [ true, %23 ]
  ret i1 %.not.lcssa
}

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


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