; LLVM IR from UtkarshPathrabe/Competitive-Coding :: Model Algorithms/Graphs/Strongly Connected Components.ll (Z4DFS1v)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Nodes, std::allocator<Nodes>>::_Vector_impl" }
%"struct.std::_Vector_base<Nodes, std::allocator<Nodes>>::_Vector_impl" = type { %"struct.std::_Vector_base<Nodes, std::allocator<Nodes>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Nodes, std::allocator<Nodes>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.Nodes = type { i8, i32, i32 }

@Node1 = external dso_local global %"class.std::vector", align 8
@n = external dso_local global i32, align 4
@timer = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI5NodesSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

; 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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11DFSUtility1i(i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4DFS1v() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI5NodesSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @Node1, i64 noundef 0) #3
  %4 = getelementptr inbounds %struct.Nodes, ptr %3, i32 0, i32 0
  store i8 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 1, ptr %1, align 4, !tbaa !11
  br label %5

5:                                                ; preds = %19, %0
  %6 = load i32, ptr %1, align 4, !tbaa !11
  %7 = load i32, ptr @n, align 4, !tbaa !11
  %8 = icmp sle i32 %6, %7
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %5
  %11 = load i32, ptr %1, align 4, !tbaa !11
  %12 = sext i32 %11 to i64
  %13 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI5NodesSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @Node1, i64 noundef %12) #3
  %14 = getelementptr inbounds %struct.Nodes, ptr %13, i32 0, i32 0
  store i8 0, ptr %14, align 4, !tbaa !5
  %15 = load i32, ptr %1, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI5NodesSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @Node1, i64 noundef %16) #3
  %18 = getelementptr inbounds %struct.Nodes, ptr %17, i32 0, i32 1
  store i32 -2147483648, ptr %18, align 4, !tbaa !12
  br label %19

19:                                               ; preds = %10
  %20 = load i32, ptr %1, align 4, !tbaa !11
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %1, align 4, !tbaa !11
  br label %5, !llvm.loop !13

22:                                               ; preds = %9
  store i32 0, ptr @timer, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !11
  br label %23

23:                                               ; preds = %38, %22
  %24 = load i32, ptr %2, align 4, !tbaa !11
  %25 = load i32, ptr @n, align 4, !tbaa !11
  %26 = icmp sle i32 %24, %25
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %23
  %29 = load i32, ptr %2, align 4, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI5NodesSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @Node1, i64 noundef %30) #3
  %32 = getelementptr inbounds %struct.Nodes, ptr %31, i32 0, i32 0
  %33 = load i8, ptr %32, align 4, !tbaa !5, !range !15, !noundef !16
  %34 = trunc i8 %33 to i1
  br i1 %34, label %37, label %35

35:                                               ; preds = %28
  %36 = load i32, ptr %2, align 4, !tbaa !11
  call void @_Z11DFSUtility1i(i32 noundef %36)
  br label %37

37:                                               ; preds = %35, %28
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %2, align 4, !tbaa !11
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %2, align 4, !tbaa !11
  br label %23, !llvm.loop !17

41:                                               ; preds = %27
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !7, i64 0}
!6 = !{!"_ZTS5Nodes", !7, i64 0, !10, i64 4, !10, i64 8}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !14}


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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Nodes, std::allocator<Nodes>>::_Vector_impl" }
%"struct.std::_Vector_base<Nodes, std::allocator<Nodes>>::_Vector_impl" = type { %"struct.std::_Vector_base<Nodes, std::allocator<Nodes>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Nodes, std::allocator<Nodes>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@Node1 = external dso_local global %"class.std::vector", align 8
@n = external dso_local local_unnamed_addr global i32, align 4
@timer = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI5NodesSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11DFSUtility1i(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4DFS1v() local_unnamed_addr #1 {
  %1 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI5NodesSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @Node1, i64 noundef 0) #2
  store i8 1, ptr %1, align 4, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !11
  %.not10 = icmp slt i32 %2, 1
  br i1 %.not10, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %0
  store i32 0, ptr @timer, align 4, !tbaa !11
  br label %._crit_edge16

._crit_edge:                                      ; preds = %.lr.ph
  %3 = icmp slt i32 %7, 1
  store i32 0, ptr @timer, align 4, !tbaa !11
  br i1 %3, label %._crit_edge16, label %.lr.ph15

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %4 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI5NodesSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @Node1, i64 noundef %indvars.iv) #2
  store i8 0, ptr %4, align 4, !tbaa !5
  %5 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI5NodesSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @Node1, i64 noundef %indvars.iv) #2
  %6 = getelementptr inbounds i8, ptr %5, i64 4
  store i32 -2147483648, ptr %6, align 4, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = load i32, ptr @n, align 4, !tbaa !11
  %8 = sext i32 %7 to i64
  %.not.not = icmp slt i64 %indvars.iv, %8
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge16:                                    ; preds = %14, %._crit_edge.thread, %._crit_edge
  ret void

.lr.ph15:                                         ; preds = %._crit_edge, %14
  %indvars.iv18 = phi i64 [ %indvars.iv.next19, %14 ], [ 1, %._crit_edge ]
  %9 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorI5NodesSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @Node1, i64 noundef %indvars.iv18) #2
  %10 = load i8, ptr %9, align 4, !tbaa !5, !range !15, !noundef !16
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %14, label %12

12:                                               ; preds = %.lr.ph15
  %13 = trunc nuw nsw i64 %indvars.iv18 to i32
  tail call void @_Z11DFSUtility1i(i32 noundef %13)
  br label %14

14:                                               ; preds = %.lr.ph15, %12
  %indvars.iv.next19 = add nuw nsw i64 %indvars.iv18, 1
  %15 = load i32, ptr @n, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %.not9.not = icmp slt i64 %indvars.iv18, %16
  br i1 %.not9.not, label %.lr.ph15, label %._crit_edge16, !llvm.loop !17
}

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 = { 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, !7, i64 0}
!6 = !{!"_ZTS5Nodes", !7, i64 0, !10, i64 4, !10, i64 8}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !14}


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