; LLVM IR from Tunghohin/Competitive_Coding :: Hdu/hdu4612.ll (Z6tarjanii)

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

@e = external dso_local global [6000020 x %struct.edge], align 16
@head = external dso_local global [200010 x i32], align 16
@dfn = external dso_local global [200010 x i32], align 16
@low = external dso_local global [200010 x i32], align 16
@timestamp = external dso_local global i32, align 4
@stk = external dso_local global [200010 x i32], align 16
@top = external dso_local global i32, align 4
@in_stk = external dso_local global [200010 x i8], align 16
@bcc_id = external dso_local global [200010 x i32], align 16
@bcc_cnt = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z8inv_edgei(i32 noundef) #0

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

29:                                               ; preds = %85, %2
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [6000020 x %struct.edge], ptr @e, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.edge, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !11
  store i32 %38, ptr %7, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = icmp eq i32 %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %33
  store i32 4, ptr %6, align 4
  br label %82

43:                                               ; preds = %33
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [200010 x i32], ptr @dfn, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %63, label %49

49:                                               ; preds = %43
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z6tarjanii(i32 noundef %50, i32 noundef %51)
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [200010 x i32], ptr @low, i64 0, i64 %53
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [200010 x i32], ptr @low, i64 0, i64 %56
  %58 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %54, ptr noundef nonnull align 4 dereferenceable(4) %57)
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [200010 x i32], ptr @low, i64 0, i64 %61
  store i32 %59, ptr %62, align 4, !tbaa !5
  br label %81

63:                                               ; preds = %43
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = call noundef i32 @_Z8inv_edgei(i32 noundef %65)
  %67 = icmp ne i32 %64, %66
  br i1 %67, label %68, label %80

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

80:                                               ; preds = %68, %63
  br label %81

81:                                               ; preds = %80, %49
  store i32 0, ptr %6, align 4
  br label %82

82:                                               ; preds = %81, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %83 = load i32, ptr %6, align 4
  switch i32 %83, label %123 [
    i32 0, label %84
    i32 4, label %85
  ]

84:                                               ; preds = %82
  br label %85

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

91:                                               ; preds = %32
  %92 = load i32, ptr %3, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [200010 x i32], ptr @dfn, i64 0, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !5
  %96 = load i32, ptr %3, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [200010 x i32], ptr @low, i64 0, i64 %97
  %99 = load i32, ptr %98, align 4, !tbaa !5
  %100 = icmp eq i32 %95, %99
  br i1 %100, label %101, label %122

101:                                              ; preds = %91
  %102 = load i32, ptr @bcc_cnt, align 4, !tbaa !5
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr @bcc_cnt, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  br label %104

104:                                              ; preds = %117, %101
  %105 = load i32, ptr @top, align 4, !tbaa !5
  %106 = add nsw i32 %105, -1
  store i32 %106, ptr @top, align 4, !tbaa !5
  %107 = sext i32 %105 to i64
  %108 = getelementptr inbounds [200010 x i32], ptr @stk, i64 0, i64 %107
  %109 = load i32, ptr %108, align 4, !tbaa !5
  store i32 %109, ptr %8, align 4, !tbaa !5
  %110 = load i32, ptr @bcc_cnt, align 4, !tbaa !5
  %111 = load i32, ptr %8, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [200010 x i32], ptr @bcc_id, i64 0, i64 %112
  store i32 %110, ptr %113, align 4, !tbaa !5
  %114 = load i32, ptr %8, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [200010 x i8], ptr @in_stk, i64 0, i64 %115
  store i8 0, ptr %116, align 1, !tbaa !9
  br label %117

117:                                              ; preds = %104
  %118 = load i32, ptr %8, align 4, !tbaa !5
  %119 = load i32, ptr %3, align 4, !tbaa !5
  %120 = icmp ne i32 %118, %119
  br i1 %120, label %104, label %121, !llvm.loop !16

121:                                              ; preds = %117
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %122

122:                                              ; preds = %121, %91
  ret void

123:                                              ; preds = %82
  unreachable
}

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

; 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)) #3

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

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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 4}
!12 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@e = external dso_local local_unnamed_addr global [6000020 x %struct.edge], align 16
@head = external dso_local local_unnamed_addr global [200010 x i32], align 16
@dfn = external dso_local global [200010 x i32], align 16
@low = external dso_local global [200010 x i32], align 16
@timestamp = external dso_local local_unnamed_addr global i32, align 4
@stk = external dso_local local_unnamed_addr global [200010 x i32], align 16
@top = external dso_local local_unnamed_addr global i32, align 4
@in_stk = external dso_local local_unnamed_addr global [200010 x i8], align 16
@bcc_id = external dso_local local_unnamed_addr global [200010 x i32], align 16
@bcc_cnt = external dso_local local_unnamed_addr global i32, align 4

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

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

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

.lr.ph:                                           ; preds = %2, %30
  %.033 = phi i32 [ %.0, %30 ], [ %.031, %2 ]
  %15 = sext i32 %.033 to i64
  %16 = getelementptr inbounds [6000020 x %struct.edge], ptr @e, i64 0, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = icmp eq i32 %.033, %1
  br i1 %19, label %30, label %20

20:                                               ; preds = %.lr.ph
  %21 = sext i32 %18 to i64
  %22 = getelementptr inbounds [200010 x i32], ptr @dfn, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %.not29 = icmp eq i32 %23, 0
  br i1 %.not29, label %24, label %26

24:                                               ; preds = %20
  tail call void @_Z6tarjanii(i32 noundef %18, i32 noundef %.033)
  %25 = getelementptr inbounds [200010 x i32], ptr @low, i64 0, i64 %21
  br label %.sink.split

26:                                               ; preds = %20
  %27 = tail call noundef i32 @_Z8inv_edgei(i32 noundef %1)
  %.not30 = icmp eq i32 %.033, %27
  br i1 %.not30, label %30, label %.sink.split

.sink.split:                                      ; preds = %26, %24
  %.sink = phi ptr [ %25, %24 ], [ %22, %26 ]
  %28 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %.sink)
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %6, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %.sink.split, %26, %.lr.ph
  %31 = getelementptr inbounds i8, ptr %16, i64 8
  %.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 !13

._crit_edge.thread:                               ; preds = %2, %._crit_edge
  %32 = load i32, ptr @bcc_cnt, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @bcc_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 [200010 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 [200010 x i32], ptr @bcc_id, i64 0, i64 %38
  store i32 %33, ptr %39, align 4, !tbaa !5
  %40 = getelementptr inbounds [200010 x i8], ptr @in_stk, i64 0, i64 %38
  store i8 0, ptr %40, align 1, !tbaa !9
  %.not28 = icmp eq i32 %37, %0
  br i1 %.not28, label %.loopexit, label %35, !llvm.loop !15

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


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