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

@type = external dso_local global [200010 x i32], align 16
@e = external dso_local global [400010 x %struct.edge], align 16
@head = external dso_local global [200010 x i32], 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 i8, align 1
  %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 1, ptr %5) #2
  store i8 0, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [200010 x i32], ptr @head, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %12, ptr %6, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %40, %2
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [400010 x %struct.edge], ptr @e, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.edge, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !11
  store i32 %22, ptr %8, align 4, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %17
  store i32 4, ptr %7, align 4
  br label %37

27:                                               ; preds = %17
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %28, i32 noundef %29)
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [200010 x i32], ptr @type, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp eq i32 %33, 1
  br i1 %34, label %35, label %36

35:                                               ; preds = %27
  store i8 1, ptr %5, align 1, !tbaa !9
  br label %36

36:                                               ; preds = %35, %27
  store i32 0, ptr %7, align 4
  br label %37

37:                                               ; preds = %36, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %38 = load i32, ptr %7, align 4
  switch i32 %38, label %63 [
    i32 0, label %39
    i32 4, label %40
  ]

39:                                               ; preds = %37
  br label %40

40:                                               ; preds = %39, %37
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [400010 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 !13
  store i32 %45, ptr %6, align 4, !tbaa !5
  br label %13, !llvm.loop !14

46:                                               ; preds = %16
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = icmp ne i32 %47, %48
  br i1 %49, label %50, label %62

50:                                               ; preds = %46
  %51 = load i8, ptr %5, align 1, !tbaa !9, !range !16, !noundef !17
  %52 = trunc i8 %51 to i1
  br i1 %52, label %53, label %57

53:                                               ; preds = %50
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [200010 x i32], ptr @type, i64 0, i64 %55
  store i32 2, ptr %56, align 4, !tbaa !5
  br label %61

57:                                               ; preds = %50
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [200010 x i32], ptr @type, i64 0, i64 %59
  store i32 1, ptr %60, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %57, %53
  br label %62

62:                                               ; preds = %61, %46
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  ret void

63:                                               ; preds = %37
  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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{i8 0, i8 2}
!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 }

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

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [200010 x i32], ptr @head, i64 0, i64 %3
  %.01417 = load i32, ptr %4, align 4, !tbaa !5
  %.not18 = icmp eq i32 %.01417, 0
  br i1 %.not18, label %._crit_edge.thread, label %.lr.ph

._crit_edge:                                      ; preds = %14
  %.not16 = icmp eq i32 %0, %1
  br i1 %.not16, label %18, label %16

._crit_edge.thread:                               ; preds = %2
  %.not1622 = icmp eq i32 %0, %1
  br i1 %.not1622, label %18, label %.thread

.lr.ph:                                           ; preds = %2, %14
  %.01420 = phi i32 [ %.014, %14 ], [ %.01417, %2 ]
  %.019 = phi i1 [ %.2, %14 ], [ false, %2 ]
  %5 = sext i32 %.01420 to i64
  %6 = getelementptr inbounds [400010 x %struct.edge], ptr @e, i64 0, i64 %5
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp eq i32 %7, %1
  br i1 %8, label %14, label %9

9:                                                ; preds = %.lr.ph
  tail call void @_Z3dfsii(i32 noundef %7, i32 noundef %0)
  %10 = sext i32 %7 to i64
  %11 = getelementptr inbounds [200010 x i32], ptr @type, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp eq i32 %12, 1
  %spec.select = select i1 %13, i1 true, i1 %.019
  br label %14

14:                                               ; preds = %.lr.ph, %9
  %.2 = phi i1 [ %spec.select, %9 ], [ %.019, %.lr.ph ]
  %15 = getelementptr inbounds i8, ptr %6, i64 4
  %.014 = load i32, ptr %15, align 4, !tbaa !5
  %.not = icmp eq i32 %.014, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

16:                                               ; preds = %._crit_edge
  br i1 %.2, label %.sink.split, label %.thread

.thread:                                          ; preds = %._crit_edge.thread, %16
  br label %.sink.split

.sink.split:                                      ; preds = %16, %.thread
  %.sink = phi i32 [ 1, %.thread ], [ 2, %16 ]
  %17 = getelementptr inbounds [200010 x i32], ptr @type, i64 0, i64 %3
  store i32 %.sink, ptr %17, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %.sink.split, %._crit_edge.thread, %._crit_edge
  ret void
}

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.mustprogress"}


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