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

@t = external dso_local global [200010 x i32], align 16
@e = external dso_local global [400020 x %struct.edge], align 16
@head = external dso_local global [200010 x i32], align 16
@dp = external dso_local global [200010 x [2 x i32]], align 16
@depth = external dso_local global [200010 x i32], align 16
@y = external dso_local global i32, align 4

; 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 i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [200010 x i32], ptr @depth, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [200010 x i32], ptr @depth, i64 0, i64 %14
  store i32 %12, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [200010 x i32], ptr @head, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  store i32 %19, ptr %5, align 4, !tbaa !5
  br label %20

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

23:                                               ; preds = %20
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %70

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

33:                                               ; preds = %24
  store i32 4, ptr %6, align 4
  br label %61

34:                                               ; preds = %24
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %35, i32 noundef %36)
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [200010 x [2 x i32]], ptr @dp, i64 0, i64 %38
  %40 = getelementptr inbounds [2 x i32], ptr %39, i64 0, i64 1
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %60

43:                                               ; preds = %34
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [200010 x [2 x i32]], ptr @dp, i64 0, i64 %45
  %47 = getelementptr inbounds [2 x i32], ptr %46, i64 0, i64 1
  store i32 1, ptr %47, align 4, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [200010 x [2 x i32]], ptr @dp, i64 0, i64 %49
  %51 = getelementptr inbounds [2 x i32], ptr %50, i64 0, i64 0
  %52 = load i32, ptr %51, align 8, !tbaa !5
  %53 = add nsw i32 %52, 2
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [200010 x [2 x i32]], ptr @dp, i64 0, i64 %55
  %57 = getelementptr inbounds [2 x i32], ptr %56, i64 0, i64 0
  %58 = load i32, ptr %57, align 8, !tbaa !5
  %59 = add nsw i32 %58, %53
  store i32 %59, ptr %57, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %43, %34
  store i32 0, ptr %6, align 4
  br label %61

61:                                               ; preds = %60, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %62 = load i32, ptr %6, align 4
  switch i32 %62, label %86 [
    i32 0, label %63
    i32 4, label %64
  ]

63:                                               ; preds = %61
  br label %64

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

70:                                               ; preds = %23
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [200010 x i32], ptr @t, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %80, label %76

76:                                               ; preds = %70
  %77 = load i32, ptr %3, align 4, !tbaa !5
  %78 = load i32, ptr @y, align 4, !tbaa !5
  %79 = icmp eq i32 %77, %78
  br i1 %79, label %80, label %85

80:                                               ; preds = %76, %70
  %81 = load i32, ptr %3, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [200010 x [2 x i32]], ptr @dp, i64 0, i64 %82
  %84 = getelementptr inbounds [2 x i32], ptr %83, i64 0, i64 1
  store i32 1, ptr %84, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %80, %76
  ret void

86:                                               ; preds = %61
  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 }

@t = external dso_local local_unnamed_addr global [200010 x i32], align 16
@e = external dso_local local_unnamed_addr global [400020 x %struct.edge], align 16
@head = external dso_local local_unnamed_addr global [200010 x i32], align 16
@dp = external dso_local local_unnamed_addr global [200010 x [2 x i32]], align 16
@depth = external dso_local local_unnamed_addr global [200010 x i32], align 16
@y = 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 void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %1 to i64
  %4 = getelementptr inbounds [200010 x i32], ptr @depth, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = add nsw i32 %5, 1
  %7 = sext i32 %0 to i64
  %8 = getelementptr inbounds [200010 x i32], ptr @depth, i64 0, i64 %7
  store i32 %6, ptr %8, align 4, !tbaa !5
  %9 = getelementptr inbounds [200010 x i32], ptr @head, i64 0, i64 %7
  %.021 = load i32, ptr %9, align 4, !tbaa !5
  %.not22 = icmp eq i32 %.021, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %10 = getelementptr inbounds [200010 x [2 x i32]], ptr @dp, i64 0, i64 %7
  %11 = getelementptr inbounds i8, ptr %10, i64 4
  br label %16

._crit_edge:                                      ; preds = %31, %2
  %12 = getelementptr inbounds [200010 x i32], ptr @t, i64 0, i64 %7
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not18 = icmp ne i32 %13, 0
  %14 = load i32, ptr @y, align 4
  %15 = icmp eq i32 %14, %0
  %or.cond = select i1 %.not18, i1 true, i1 %15
  br i1 %or.cond, label %33, label %35

16:                                               ; preds = %.lr.ph, %31
  %.023 = phi i32 [ %.021, %.lr.ph ], [ %.0, %31 ]
  %17 = sext i32 %.023 to i64
  %18 = getelementptr inbounds [400020 x %struct.edge], ptr @e, i64 0, i64 %17
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = icmp eq i32 %19, %1
  br i1 %20, label %31, label %21

21:                                               ; preds = %16
  tail call void @_Z3dfsii(i32 noundef %19, i32 noundef %0)
  %22 = sext i32 %19 to i64
  %23 = getelementptr inbounds [200010 x [2 x i32]], ptr @dp, i64 0, i64 %22
  %24 = getelementptr inbounds i8, ptr %23, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %.not19 = icmp eq i32 %25, 0
  br i1 %.not19, label %31, label %26

26:                                               ; preds = %21
  store i32 1, ptr %11, align 4, !tbaa !5
  %27 = load i32, ptr %23, align 8, !tbaa !5
  %28 = add nsw i32 %27, 2
  %29 = load i32, ptr %10, align 8, !tbaa !5
  %30 = add nsw i32 %28, %29
  store i32 %30, ptr %10, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %21, %26, %16
  %32 = getelementptr inbounds i8, ptr %18, i64 4
  %.0 = load i32, ptr %32, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %._crit_edge, label %16, !llvm.loop !11

33:                                               ; preds = %._crit_edge
  %34 = getelementptr inbounds [200010 x [2 x i32]], ptr @dp, i64 0, i64 %7, i64 1
  store i32 1, ptr %34, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %._crit_edge, %33
  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: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass