; LLVM IR from reyadussalahin/problem-solving :: graph/scc/loj/F1210 (Solution)

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

@edges = external dso_local global [50000 x %struct.Edge], align 16
@list = external dso_local global [20000 x i32], align 16
@visited = external dso_local global [20000 x i32], align 16
@inPath = external dso_local global [20000 x i32], align 16
@startTime = external dso_local global [20000 x i32], align 16
@stack = external dso_local global [20000 x i32], align 16
@top = external dso_local global i32, align 4
@timer = external dso_local global i32, align 4
@nscc = external dso_local global i32, align 4
@component = external dso_local global [20000 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @min(i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @dfs(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [20000 x i32], ptr @visited, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %24

12:                                               ; preds = %1
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [20000 x i32], ptr @inPath, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %23

18:                                               ; preds = %12
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [20000 x i32], ptr @startTime, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  store i32 %22, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %94

23:                                               ; preds = %12
  store i32 1111111111, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %94

24:                                               ; preds = %1
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [20000 x i32], ptr @visited, i64 0, i64 %26
  store i32 1, ptr %27, align 4, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = load i32, ptr @top, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @top, align 4, !tbaa !5
  %31 = sext i32 %29 to i64
  %32 = getelementptr inbounds [20000 x i32], ptr @stack, i64 0, i64 %31
  store i32 %28, ptr %32, align 4, !tbaa !5
  %33 = load i32, ptr @timer, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr @timer, align 4, !tbaa !5
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [20000 x i32], ptr @startTime, i64 0, i64 %36
  store i32 %33, ptr %37, align 4, !tbaa !5
  store i32 %33, ptr %4, align 4, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [20000 x i32], ptr @list, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  store i32 %41, ptr %5, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %45, %24
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = icmp ne i32 %43, -1
  br i1 %44, label %45, label %59

45:                                               ; preds = %42
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [50000 x %struct.Edge], ptr @edges, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.Edge, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !9
  %52 = call i32 @dfs(i32 noundef %51)
  %53 = call i32 @min(i32 noundef %46, i32 noundef %52)
  store i32 %53, ptr %4, align 4, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [50000 x %struct.Edge], ptr @edges, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.Edge, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 4, !tbaa !11
  store i32 %58, ptr %5, align 4, !tbaa !5
  br label %42, !llvm.loop !12

59:                                               ; preds = %42
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [20000 x i32], ptr @startTime, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = icmp eq i32 %60, %64
  br i1 %65, label %66, label %92

66:                                               ; preds = %59
  br label %67

67:                                               ; preds = %82, %66
  %68 = load i32, ptr @top, align 4, !tbaa !5
  %69 = add nsw i32 %68, -1
  store i32 %69, ptr @top, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [20000 x i32], ptr @stack, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [20000 x i32], ptr @inPath, i64 0, i64 %73
  store i32 0, ptr %74, align 4, !tbaa !5
  %75 = load i32, ptr @nscc, align 4, !tbaa !5
  %76 = load i32, ptr @top, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [20000 x i32], ptr @stack, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [20000 x i32], ptr @component, i64 0, i64 %80
  store i32 %75, ptr %81, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %67
  %83 = load i32, ptr @top, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [20000 x i32], ptr @stack, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = load i32, ptr %3, align 4, !tbaa !5
  %88 = icmp ne i32 %86, %87
  br i1 %88, label %67, label %89, !llvm.loop !14

89:                                               ; preds = %82
  %90 = load i32, ptr @nscc, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr @nscc, align 4, !tbaa !5
  br label %92

92:                                               ; preds = %89, %59
  %93 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %93, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %94

94:                                               ; preds = %92, %23, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %95 = load i32, ptr %2, align 4
  ret i32 %95
}

; 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 = { nounwind 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/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@edges = external dso_local local_unnamed_addr global [50000 x %struct.Edge], align 16
@list = external dso_local local_unnamed_addr global [20000 x i32], align 16
@visited = external dso_local local_unnamed_addr global [20000 x i32], align 16
@inPath = external dso_local local_unnamed_addr global [20000 x i32], align 16
@startTime = external dso_local local_unnamed_addr global [20000 x i32], align 16
@stack = external dso_local local_unnamed_addr global [20000 x i32], align 16
@top = external dso_local local_unnamed_addr global i32, align 4
@timer = external dso_local local_unnamed_addr global i32, align 4
@nscc = external dso_local local_unnamed_addr global i32, align 4
@component = external dso_local local_unnamed_addr global [20000 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @min(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @dfs(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [20000 x i32], ptr @visited, i64 0, i64 %2
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %11, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds [20000 x i32], ptr @inPath, i64 0, i64 %2
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not20 = icmp eq i32 %7, 0
  br i1 %.not20, label %39, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds [20000 x i32], ptr @startTime, i64 0, i64 %2
  %10 = load i32, ptr %9, align 4, !tbaa !5
  br label %39

11:                                               ; preds = %1
  store i32 1, ptr %3, align 4, !tbaa !5
  %12 = load i32, ptr @top, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr @top, align 4, !tbaa !5
  %14 = sext i32 %12 to i64
  %15 = getelementptr inbounds [20000 x i32], ptr @stack, i64 0, i64 %14
  store i32 %0, ptr %15, align 4, !tbaa !5
  %16 = load i32, ptr @timer, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @timer, align 4, !tbaa !5
  %18 = getelementptr inbounds [20000 x i32], ptr @startTime, i64 0, i64 %2
  store i32 %16, ptr %18, align 4, !tbaa !5
  %19 = getelementptr inbounds [20000 x i32], ptr @list, i64 0, i64 %2
  %.021 = load i32, ptr %19, align 4, !tbaa !5
  %.not1822 = icmp eq i32 %.021, -1
  br i1 %.not1822, label %.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.024 = phi i32 [ %.0, %.lr.ph ], [ %.021, %11 ]
  %.01623 = phi i32 [ %24, %.lr.ph ], [ %16, %11 ]
  %20 = sext i32 %.024 to i64
  %21 = getelementptr inbounds [50000 x %struct.Edge], ptr @edges, i64 0, i64 %20
  %22 = load i32, ptr %21, align 8, !tbaa !9
  %23 = tail call i32 @dfs(i32 noundef %22)
  %24 = tail call i32 @min(i32 noundef %.01623, i32 noundef %23)
  %25 = getelementptr inbounds i8, ptr %21, i64 4
  %.0 = load i32, ptr %25, align 4, !tbaa !5
  %.not18 = icmp eq i32 %.0, -1
  br i1 %.not18, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph
  %.pre = load i32, ptr %18, align 4, !tbaa !5
  %26 = icmp eq i32 %24, %.pre
  br i1 %26, label %.preheader, label %39

.preheader:                                       ; preds = %11, %._crit_edge
  %27 = phi i32 [ %.pre, %._crit_edge ], [ %16, %11 ]
  %28 = load i32, ptr @nscc, align 4, !tbaa !5
  %top.promoted = load i32, ptr @top, align 4, !tbaa !5
  %29 = sext i32 %top.promoted to i64
  br label %30

30:                                               ; preds = %.preheader, %30
  %indvars.iv = phi i64 [ %29, %.preheader ], [ %indvars.iv.next, %30 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %31 = getelementptr inbounds [20000 x i32], ptr @stack, i64 0, i64 %indvars.iv.next
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [20000 x i32], ptr @inPath, i64 0, i64 %33
  store i32 0, ptr %34, align 4, !tbaa !5
  %35 = getelementptr inbounds [20000 x i32], ptr @component, i64 0, i64 %33
  store i32 %28, ptr %35, align 4, !tbaa !5
  %.not19 = icmp eq i32 %32, %0
  br i1 %.not19, label %36, label %30, !llvm.loop !13

36:                                               ; preds = %30
  %37 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %37, ptr @top, align 4, !tbaa !5
  %38 = add nsw i32 %28, 1
  store i32 %38, ptr @nscc, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %._crit_edge, %36, %5, %8
  %.017 = phi i32 [ %10, %8 ], [ 1111111111, %5 ], [ %27, %36 ], [ %24, %._crit_edge ]
  ret i32 %.017
}

attributes #0 = { nounwind 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/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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