; LLVM IR from devparthgarg/Data-Structures-and-Algorithms :: 18. Graphs/05 Depth First Search (05a Depth First Search)

; 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<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsPSt6vectorIiSaIiEEii(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 5, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = zext i32 %8 to i64
  %10 = call ptr @llvm.stacksave.p0()
  store ptr %10, ptr %3, align 8
  %11 = alloca %"class.std::vector", i64 %9, align 16
  store i64 %9, ptr %4, align 8
  %12 = icmp eq i64 %9, 0
  br i1 %12, label %19, label %13

13:                                               ; preds = %0
  %14 = getelementptr inbounds %"class.std::vector", ptr %11, i64 %9
  br label %15

15:                                               ; preds = %15, %13
  %16 = phi ptr [ %11, %13 ], [ %17, %15 ]
  call void @_ZNSt6vectorIiSaIiEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %16) #5
  %17 = getelementptr inbounds %"class.std::vector", ptr %16, i64 1
  %18 = icmp eq ptr %17, %14
  br i1 %18, label %19, label %15

19:                                               ; preds = %15, %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  invoke void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef %11, i32 noundef 0, i32 noundef 1)
          to label %20 unwind label %31

20:                                               ; preds = %19
  invoke void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef %11, i32 noundef 0, i32 noundef 2)
          to label %21 unwind label %31

21:                                               ; preds = %20
  invoke void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef %11, i32 noundef 2, i32 noundef 3)
          to label %22 unwind label %31

22:                                               ; preds = %21
  invoke void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef %11, i32 noundef 1, i32 noundef 3)
          to label %23 unwind label %31

23:                                               ; preds = %22
  invoke void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef %11, i32 noundef 1, i32 noundef 4)
          to label %24 unwind label %31

24:                                               ; preds = %23
  invoke void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef %11, i32 noundef 3, i32 noundef 4)
          to label %25 unwind label %31

25:                                               ; preds = %24
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !5
  invoke void @_Z3dfsPSt6vectorIiSaIiEEii(ptr noundef %11, i32 noundef %26, i32 noundef %27)
          to label %28 unwind label %31

28:                                               ; preds = %25
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  %29 = getelementptr inbounds %"class.std::vector", ptr %11, i64 %9
  %30 = icmp eq ptr %11, %29
  br i1 %30, label %41, label %37

31:                                               ; preds = %25, %24, %23, %22, %21, %20, %19
  %32 = landingpad { ptr, i32 }
          cleanup
  %33 = extractvalue { ptr, i32 } %32, 0
  store ptr %33, ptr %6, align 8
  %34 = extractvalue { ptr, i32 } %32, 1
  store i32 %34, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  %35 = getelementptr inbounds %"class.std::vector", ptr %11, i64 %9
  %36 = icmp eq ptr %11, %35
  br i1 %36, label %48, label %44

37:                                               ; preds = %37, %28
  %38 = phi ptr [ %29, %28 ], [ %39, %37 ]
  %39 = getelementptr inbounds %"class.std::vector", ptr %38, i64 -1
  call void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %39) #5
  %40 = icmp eq ptr %39, %11
  br i1 %40, label %41, label %37

41:                                               ; preds = %37, %28
  %42 = load ptr, ptr %3, align 8
  call void @llvm.stackrestore.p0(ptr %42)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %43 = load i32, ptr %1, align 4
  ret i32 %43

44:                                               ; preds = %44, %31
  %45 = phi ptr [ %35, %31 ], [ %46, %44 ]
  %46 = getelementptr inbounds %"class.std::vector", ptr %45, i64 -1
  call void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %46) #5
  %47 = icmp eq ptr %46, %11
  br i1 %47, label %48, label %44

48:                                               ; preds = %44, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %6, align 8
  %51 = load i32, ptr %7, align 4
  %52 = insertvalue { ptr, i32 } poison, ptr %50, 0
  %53 = insertvalue { ptr, i32 } %52, i32 %51, 1
  resume { ptr, i32 } %53
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #4 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #4 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }
attributes #3 = { mustprogress norecurse 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 = { 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 #5 = { 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"}


; 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<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsPSt6vectorIiSaIiEEii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %1 = alloca [5 x %"class.std::vector"], align 16
  call void @_ZNSt6vectorIiSaIiEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %1) #3
  %.ptr.1 = getelementptr inbounds i8, ptr %1, i64 24
  call void @_ZNSt6vectorIiSaIiEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %.ptr.1) #3
  %.ptr.2 = getelementptr inbounds i8, ptr %1, i64 48
  call void @_ZNSt6vectorIiSaIiEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %.ptr.2) #3
  %.ptr.3 = getelementptr inbounds i8, ptr %1, i64 72
  call void @_ZNSt6vectorIiSaIiEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %.ptr.3) #3
  %.ptr.4 = getelementptr inbounds i8, ptr %1, i64 96
  call void @_ZNSt6vectorIiSaIiEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %.ptr.4) #3
  invoke void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef nonnull %1, i32 noundef 0, i32 noundef 1)
          to label %2 unwind label %13

2:                                                ; preds = %0
  invoke void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef nonnull %1, i32 noundef 0, i32 noundef 2)
          to label %3 unwind label %13

3:                                                ; preds = %2
  invoke void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef nonnull %1, i32 noundef 2, i32 noundef 3)
          to label %4 unwind label %13

4:                                                ; preds = %3
  invoke void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef nonnull %1, i32 noundef 1, i32 noundef 3)
          to label %5 unwind label %13

5:                                                ; preds = %4
  invoke void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef nonnull %1, i32 noundef 1, i32 noundef 4)
          to label %6 unwind label %13

6:                                                ; preds = %5
  invoke void @_Z7addEdgePSt6vectorIiSaIiEEii(ptr noundef nonnull %1, i32 noundef 3, i32 noundef 4)
          to label %7 unwind label %13

7:                                                ; preds = %6
  invoke void @_Z3dfsPSt6vectorIiSaIiEEii(ptr noundef nonnull %1, i32 noundef 5, i32 noundef 0)
          to label %8 unwind label %13

8:                                                ; preds = %7
  %9 = getelementptr inbounds i8, ptr %1, i64 96
  call void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %9) #3
  %10 = getelementptr inbounds i8, ptr %1, i64 72
  call void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %10) #3
  %11 = getelementptr inbounds i8, ptr %1, i64 48
  call void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %11) #3
  %12 = getelementptr inbounds i8, ptr %1, i64 24
  call void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %12) #3
  call void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %1) #3
  ret i32 0

13:                                               ; preds = %7, %6, %5, %4, %3, %2, %0
  %14 = landingpad { ptr, i32 }
          cleanup
  %15 = getelementptr inbounds i8, ptr %1, i64 96
  call void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %15) #3
  %16 = getelementptr inbounds i8, ptr %1, i64 72
  call void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %16) #3
  %17 = getelementptr inbounds i8, ptr %1, i64 48
  call void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %17) #3
  %18 = getelementptr inbounds i8, ptr %1, i64 24
  call void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %18) #3
  call void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %1) #3
  resume { ptr, i32 } %14
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEEC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

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 = { mustprogress norecurse 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 = { 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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass