; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p2746.ll (Z6tarjani)

; 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 [1000010 x %struct.edge], align 16
@head = external dso_local global [110 x i32], align 16
@scc_cnt = external dso_local global i32, align 4
@scc_id = external dso_local global [110 x i32], align 16
@timestamp = external dso_local global i32, align 4
@dfn = external dso_local global [110 x i32], align 16
@low = external dso_local global [110 x i32], align 16
@stk = external dso_local global [110 x i32], align 16
@top = external dso_local global i32, align 4
@in_stk = external dso_local global [110 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6tarjani(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %6 = load i32, ptr @timestamp, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @timestamp, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [110 x i32], ptr @low, i64 0, i64 %9
  store i32 %7, ptr %10, align 4, !tbaa !5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [110 x i32], ptr @dfn, i64 0, i64 %12
  store i32 %7, ptr %13, align 4, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = load i32, ptr @top, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @top, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [110 x i32], ptr @stk, i64 0, i64 %17
  store i32 %14, ptr %18, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [110 x i8], ptr @in_stk, i64 0, i64 %20
  store i8 1, ptr %21, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [110 x i32], ptr @head, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  store i32 %25, ptr %3, align 4, !tbaa !5
  br label %26

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

29:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %80

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1000010 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 !11
  store i32 %35, ptr %4, align 4, !tbaa !5
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [110 x i32], ptr @dfn, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %54, label %41

41:                                               ; preds = %30
  %42 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z6tarjani(i32 noundef %42)
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [110 x i32], ptr @low, i64 0, i64 %44
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [110 x i32], ptr @low, i64 0, i64 %47
  %49 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %45, ptr noundef nonnull align 4 dereferenceable(4) %48)
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [110 x i32], ptr @low, i64 0, i64 %52
  store i32 %50, ptr %53, align 4, !tbaa !5
  br label %73

54:                                               ; preds = %30
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [110 x i8], ptr @in_stk, i64 0, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !9, !range !13, !noundef !14
  %59 = trunc i8 %58 to i1
  br i1 %59, label %60, label %72

60:                                               ; preds = %54
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [110 x i32], ptr @low, i64 0, i64 %62
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [110 x i32], ptr @dfn, i64 0, i64 %65
  %67 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %63, ptr noundef nonnull align 4 dereferenceable(4) %66)
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [110 x i32], ptr @low, i64 0, i64 %70
  store i32 %68, ptr %71, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %60, %54
  br label %73

73:                                               ; preds = %72, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [1000010 x %struct.edge], ptr @e, i64 0, i64 %76
  %78 = getelementptr inbounds %struct.edge, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 4, !tbaa !15
  store i32 %79, ptr %3, align 4, !tbaa !5
  br label %26, !llvm.loop !16

80:                                               ; preds = %29
  %81 = load i32, ptr %2, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [110 x i32], ptr @dfn, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = load i32, ptr %2, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [110 x i32], ptr @low, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = icmp eq i32 %84, %88
  br i1 %89, label %90, label %111

90:                                               ; preds = %80
  %91 = load i32, ptr @scc_cnt, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr @scc_cnt, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  br label %93

93:                                               ; preds = %106, %90
  %94 = load i32, ptr @top, align 4, !tbaa !5
  %95 = add nsw i32 %94, -1
  store i32 %95, ptr @top, align 4, !tbaa !5
  %96 = sext i32 %94 to i64
  %97 = getelementptr inbounds [110 x i32], ptr @stk, i64 0, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !5
  store i32 %98, ptr %5, align 4, !tbaa !5
  %99 = load i32, ptr %5, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [110 x i8], ptr @in_stk, i64 0, i64 %100
  store i8 0, ptr %101, align 1, !tbaa !9
  %102 = load i32, ptr @scc_cnt, align 4, !tbaa !5
  %103 = load i32, ptr %5, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [110 x i32], ptr @scc_id, i64 0, i64 %104
  store i32 %102, ptr %105, align 4, !tbaa !5
  br label %106

106:                                              ; preds = %93
  %107 = load i32, ptr %5, align 4, !tbaa !5
  %108 = load i32, ptr %2, align 4, !tbaa !5
  %109 = icmp ne i32 %107, %108
  br i1 %109, label %93, label %110, !llvm.loop !18

110:                                              ; preds = %106
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %111

111:                                              ; preds = %110, %80
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

; 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 = { inlinehint mustprogress 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 #3 = { 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 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!12, !6, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !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 }

@e = external dso_local local_unnamed_addr global [1000010 x %struct.edge], align 16
@head = external dso_local local_unnamed_addr global [110 x i32], align 16
@scc_cnt = external dso_local local_unnamed_addr global i32, align 4
@scc_id = external dso_local local_unnamed_addr global [110 x i32], align 16
@timestamp = external dso_local local_unnamed_addr global i32, align 4
@dfn = external dso_local global [110 x i32], align 16
@low = external dso_local global [110 x i32], align 16
@stk = external dso_local local_unnamed_addr global [110 x i32], align 16
@top = external dso_local local_unnamed_addr global i32, align 4
@in_stk = external dso_local local_unnamed_addr global [110 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6tarjani(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @timestamp, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr @timestamp, align 4, !tbaa !5
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [110 x i32], ptr @low, i64 0, i64 %4
  store i32 %3, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds [110 x i32], ptr @dfn, i64 0, i64 %4
  store i32 %3, ptr %6, align 4, !tbaa !5
  %7 = load i32, ptr @top, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @top, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [110 x i32], ptr @stk, i64 0, i64 %9
  store i32 %0, ptr %10, align 4, !tbaa !5
  %11 = getelementptr inbounds [110 x i8], ptr @in_stk, i64 0, i64 %4
  store i8 1, ptr %11, align 1, !tbaa !9
  %12 = getelementptr inbounds [110 x i32], ptr @head, i64 0, i64 %4
  %.025 = load i32, ptr %12, align 4, !tbaa !5
  %.not26 = icmp eq i32 %.025, 0
  br i1 %.not26, label %._crit_edge.thread, label %.lr.ph

._crit_edge:                                      ; preds = %29
  %.pre = load i32, ptr %6, align 4, !tbaa !5
  %13 = icmp eq i32 %.pre, %30
  br i1 %13, label %._crit_edge.thread, label %42

.lr.ph:                                           ; preds = %1, %29
  %14 = phi i32 [ %30, %29 ], [ %3, %1 ]
  %.027 = phi i32 [ %.0, %29 ], [ %.025, %1 ]
  %15 = sext i32 %.027 to i64
  %16 = getelementptr inbounds [1000010 x %struct.edge], ptr @e, i64 0, i64 %15
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [110 x i32], ptr @dfn, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %.not24 = icmp eq i32 %20, 0
  br i1 %.not24, label %21, label %23

21:                                               ; preds = %.lr.ph
  tail call void @_Z6tarjani(i32 noundef %17)
  %22 = getelementptr inbounds [110 x i32], ptr @low, i64 0, i64 %18
  br label %.sink.split

23:                                               ; preds = %.lr.ph
  %24 = getelementptr inbounds [110 x i8], ptr @in_stk, i64 0, i64 %18
  %25 = load i8, ptr %24, align 1, !tbaa !9, !range !13, !noundef !14
  %26 = trunc nuw i8 %25 to i1
  br i1 %26, label %.sink.split, label %29

.sink.split:                                      ; preds = %23, %21
  %.sink = phi ptr [ %22, %21 ], [ %19, %23 ]
  %27 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %.sink)
  %28 = load i32, ptr %27, align 4, !tbaa !5
  store i32 %28, ptr %5, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %.sink.split, %23
  %30 = phi i32 [ %14, %23 ], [ %28, %.sink.split ]
  %31 = getelementptr inbounds i8, ptr %16, i64 4
  %.0 = load i32, ptr %31, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge.thread:                               ; preds = %1, %._crit_edge
  %32 = load i32, ptr @scc_cnt, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @scc_cnt, align 4, !tbaa !5
  %top.promoted = load i32, ptr @top, align 4, !tbaa !5
  %34 = sext i32 %top.promoted to i64
  br label %35

35:                                               ; preds = %35, %._crit_edge.thread
  %indvars.iv = phi i64 [ %indvars.iv.next, %35 ], [ %34, %._crit_edge.thread ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %36 = getelementptr inbounds [110 x i32], ptr @stk, i64 0, i64 %indvars.iv
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [110 x i8], ptr @in_stk, i64 0, i64 %38
  store i8 0, ptr %39, align 1, !tbaa !9
  %40 = getelementptr inbounds [110 x i32], ptr @scc_id, i64 0, i64 %38
  store i32 %33, ptr %40, align 4, !tbaa !5
  %.not23 = icmp eq i32 %37, %0
  br i1 %.not23, label %.loopexit, label %35, !llvm.loop !17

.loopexit:                                        ; preds = %35
  %41 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %41, ptr @top, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %.loopexit, %._crit_edge
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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++ 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 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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