; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p3388.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 [200010 x %struct.edge], align 16
@head = external dso_local global [20010 x i32], align 16
@root = external dso_local global i32, align 4
@dfn = external dso_local global [20010 x i32], align 16
@low = external dso_local global [20010 x i32], align 16
@timestamp = external dso_local global i32, align 4
@is_cnt = external dso_local global [20010 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 [20010 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 [20010 x i32], ptr @dfn, i64 0, i64 %12
  store i32 %7, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [20010 x i32], ptr @head, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %17, ptr %4, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %83, %1
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %89

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.edge, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !9
  store i32 %27, ptr %5, align 4, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [20010 x i32], ptr @dfn, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %70, label %33

33:                                               ; preds = %22
  %34 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z6tarjani(i32 noundef %34)
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [20010 x i32], ptr @low, i64 0, i64 %36
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [20010 x i32], ptr @low, i64 0, i64 %39
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %37, ptr noundef nonnull align 4 dereferenceable(4) %40)
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [20010 x i32], ptr @low, i64 0, i64 %44
  store i32 %42, ptr %45, align 4, !tbaa !5
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [20010 x i32], ptr @dfn, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [20010 x i32], ptr @low, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = icmp sle i32 %49, %53
  br i1 %54, label %55, label %69

55:                                               ; preds = %33
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %3, align 4, !tbaa !5
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = load i32, ptr @root, align 4, !tbaa !5
  %60 = icmp ne i32 %58, %59
  br i1 %60, label %64, label %61

61:                                               ; preds = %55
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = icmp sgt i32 %62, 1
  br i1 %63, label %64, label %68

64:                                               ; preds = %61, %55
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [20010 x i8], ptr @is_cnt, i64 0, i64 %66
  store i8 1, ptr %67, align 1, !tbaa !11
  br label %68

68:                                               ; preds = %64, %61
  br label %69

69:                                               ; preds = %68, %33
  br label %82

70:                                               ; preds = %22
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [20010 x i32], ptr @low, i64 0, i64 %72
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [20010 x i32], ptr @dfn, i64 0, i64 %75
  %77 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %73, ptr noundef nonnull align 4 dereferenceable(4) %76)
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = load i32, ptr %2, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [20010 x i32], ptr @low, i64 0, i64 %80
  store i32 %78, ptr %81, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %70, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %4, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %85
  %87 = getelementptr inbounds %struct.edge, ptr %86, i32 0, i32 1
  %88 = load i32, ptr %87, align 4, !tbaa !13
  store i32 %88, ptr %4, align 4, !tbaa !5
  br label %18, !llvm.loop !14

89:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  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, !6, i64 0}
!10 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!10, !6, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"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 }

@e = external dso_local local_unnamed_addr global [200010 x %struct.edge], align 16
@head = external dso_local local_unnamed_addr global [20010 x i32], align 16
@root = external dso_local local_unnamed_addr global i32, align 4
@dfn = external dso_local global [20010 x i32], align 16
@low = external dso_local global [20010 x i32], align 16
@timestamp = external dso_local local_unnamed_addr global i32, align 4
@is_cnt = external dso_local local_unnamed_addr global [20010 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 [20010 x i32], ptr @low, i64 0, i64 %4
  store i32 %3, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds [20010 x i32], ptr @dfn, i64 0, i64 %4
  store i32 %3, ptr %6, align 4, !tbaa !5
  %7 = getelementptr inbounds [20010 x i32], ptr @head, i64 0, i64 %4
  %.02125 = load i32, ptr %7, align 4, !tbaa !5
  %.not26 = icmp eq i32 %.02125, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %8 = getelementptr inbounds [20010 x i8], ptr @is_cnt, i64 0, i64 %4
  br label %9

._crit_edge:                                      ; preds = %31, %1
  ret void

9:                                                ; preds = %.lr.ph, %31
  %.02128 = phi i32 [ %.02125, %.lr.ph ], [ %.021, %31 ]
  %.027 = phi i32 [ 0, %.lr.ph ], [ %.1, %31 ]
  %10 = sext i32 %.02128 to i64
  %11 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %10
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [20010 x i32], ptr @dfn, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %.not23 = icmp eq i32 %15, 0
  br i1 %.not23, label %16, label %28

16:                                               ; preds = %9
  tail call void @_Z6tarjani(i32 noundef %12)
  %17 = getelementptr inbounds [20010 x i32], ptr @low, i64 0, i64 %13
  %18 = 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) %17)
  %19 = load i32, ptr %18, align 4, !tbaa !5
  store i32 %19, ptr %5, align 4, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = load i32, ptr %17, align 4, !tbaa !5
  %.not24 = icmp sgt i32 %20, %21
  br i1 %.not24, label %31, label %22

22:                                               ; preds = %16
  %23 = add nsw i32 %.027, 1
  %24 = load i32, ptr @root, align 4, !tbaa !5
  %25 = icmp ne i32 %24, %0
  %26 = icmp sgt i32 %.027, 0
  %or.cond = select i1 %25, i1 true, i1 %26
  br i1 %or.cond, label %27, label %31

27:                                               ; preds = %22
  store i8 1, ptr %8, align 1, !tbaa !11
  br label %31

28:                                               ; preds = %9
  %29 = 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) %14)
  %30 = load i32, ptr %29, align 4, !tbaa !5
  store i32 %30, ptr %5, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %16, %22, %27, %28
  %.1 = phi i32 [ %.027, %28 ], [ %23, %27 ], [ %23, %22 ], [ %.027, %16 ]
  %32 = getelementptr inbounds i8, ptr %11, i64 4
  %.021 = load i32, ptr %32, align 4, !tbaa !5
  %.not = icmp eq i32 %.021, 0
  br i1 %.not, label %._crit_edge, label %9, !llvm.loop !13
}

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


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