; LLVM IR from UtkarshPathrabe/Competitive-Coding :: Model Algorithms/Graphs (Eulerian Path and Circuit in Undirected Graph)

; 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.Graph = type { i32, ptr }
%"class.std::__cxx11::list" = type { %"class.std::__cxx11::_List_base" }
%"class.std::__cxx11::_List_base" = type { %"struct.std::__cxx11::_List_base<int, std::allocator<int>>::_List_impl" }
%"struct.std::__cxx11::_List_base<int, std::allocator<int>>::_List_impl" = type { %"struct.std::__detail::_List_node_header" }
%"struct.std::__detail::_List_node_header" = type { %"struct.std::__detail::_List_node_base", i64 }
%"struct.std::__detail::_List_node_base" = type { ptr, ptr }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Graph7DFSUtilEiPb(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, ptr 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
define dso_local noundef zeroext i1 @_ZN5Graph11isConnectedEv(ptr noundef nonnull align 8 dereferenceable(16) %0) #0 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %10 = getelementptr inbounds %class.Graph, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = call noalias noundef nonnull ptr @_Znam(i64 noundef %12) #5
  store ptr %13, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %14

14:                                               ; preds = %25, %1
  %15 = load i32, ptr %5, align 4, !tbaa !12
  %16 = getelementptr inbounds %class.Graph, ptr %9, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !9
  %18 = icmp slt i32 %15, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %28

20:                                               ; preds = %14
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !12
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  store i8 0, ptr %24, align 1, !tbaa !13
  br label %25

25:                                               ; preds = %20
  %26 = load i32, ptr %5, align 4, !tbaa !12
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %5, align 4, !tbaa !12
  br label %14, !llvm.loop !15

28:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !12
  br label %29

29:                                               ; preds = %44, %28
  %30 = load i32, ptr %6, align 4, !tbaa !12
  %31 = getelementptr inbounds %class.Graph, ptr %9, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !9
  %33 = icmp slt i32 %30, %32
  br i1 %33, label %34, label %47

34:                                               ; preds = %29
  %35 = getelementptr inbounds %class.Graph, ptr %9, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = load i32, ptr %6, align 4, !tbaa !12
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds %"class.std::__cxx11::list", ptr %36, i64 %38
  %40 = call noundef i64 @_ZNKSt7__cxx114listIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %39) #4
  %41 = icmp ugt i64 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %34
  br label %47

43:                                               ; preds = %34
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %6, align 4, !tbaa !12
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %6, align 4, !tbaa !12
  br label %29, !llvm.loop !18

47:                                               ; preds = %42, %29
  %48 = load i32, ptr %6, align 4, !tbaa !12
  %49 = getelementptr inbounds %class.Graph, ptr %9, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !9
  %51 = icmp eq i32 %48, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %47
  store i1 true, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %85

53:                                               ; preds = %47
  %54 = load i32, ptr %6, align 4, !tbaa !12
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN5Graph7DFSUtilEiPb(ptr noundef nonnull align 8 dereferenceable(16) %9, i32 noundef %54, ptr noundef %55)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !12
  br label %56

56:                                               ; preds = %79, %53
  %57 = load i32, ptr %8, align 4, !tbaa !12
  %58 = getelementptr inbounds %class.Graph, ptr %9, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !9
  %60 = icmp slt i32 %57, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %56
  store i32 8, ptr %7, align 4
  br label %82

62:                                               ; preds = %56
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !12
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %63, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !13, !range !19, !noundef !20
  %68 = trunc i8 %67 to i1
  br i1 %68, label %78, label %69

69:                                               ; preds = %62
  %70 = getelementptr inbounds %class.Graph, ptr %9, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !17
  %72 = load i32, ptr %8, align 4, !tbaa !12
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds %"class.std::__cxx11::list", ptr %71, i64 %73
  %75 = call noundef i64 @_ZNKSt7__cxx114listIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %74) #4
  %76 = icmp ugt i64 %75, 0
  br i1 %76, label %77, label %78

77:                                               ; preds = %69
  store i1 false, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %82

78:                                               ; preds = %69, %62
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %8, align 4, !tbaa !12
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %8, align 4, !tbaa !12
  br label %56, !llvm.loop !21

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

84:                                               ; preds = %82
  store i1 true, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %85

85:                                               ; preds = %84, %82, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %86 = load i1, ptr %2, align 1
  ret i1 %86
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt7__cxx114listIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nobuiltin allocsize(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 = { 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 }
attributes #5 = { builtin allocsize(0) }

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


; 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::__cxx11::list" = type { %"class.std::__cxx11::_List_base" }
%"class.std::__cxx11::_List_base" = type { %"struct.std::__cxx11::_List_base<int, std::allocator<int>>::_List_impl" }
%"struct.std::__cxx11::_List_base<int, std::allocator<int>>::_List_impl" = type { %"struct.std::__detail::_List_node_header" }
%"struct.std::__detail::_List_node_header" = type { %"struct.std::__detail::_List_node_base", i64 }
%"struct.std::__detail::_List_node_base" = type { ptr, ptr }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Graph7DFSUtilEiPb(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5Graph11isConnectedEv(ptr noundef nonnull align 8 dereferenceable(16) %0) local_unnamed_addr #0 align 2 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %3) #4
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph25.preheader, label %.preheader

.preheader:                                       ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  br label %._crit_edge

.lr.ph25.preheader:                               ; preds = %1
  %7 = zext nneg i32 %2 to i64
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %4, i8 0, i64 %7, i1 false), !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  br label %.lr.ph25

.lr.ph25:                                         ; preds = %.lr.ph25.preheader, %12
  %indvars.iv = phi i64 [ 0, %.lr.ph25.preheader ], [ %indvars.iv.next, %12 ]
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds %"class.std::__cxx11::list", ptr %9, i64 %indvars.iv
  %11 = tail call noundef i64 @_ZNKSt7__cxx114listIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %10) #5
  %.not = icmp eq i64 %11, 0
  %.pre.pre = load i32, ptr %0, align 8, !tbaa !5
  br i1 %.not, label %12, label %._crit_edge.loopexit

12:                                               ; preds = %.lr.ph25
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = sext i32 %.pre.pre to i64
  %14 = icmp slt i64 %indvars.iv.next, %13
  br i1 %14, label %.lr.ph25, label %._crit_edge.loopexit, !llvm.loop !14

._crit_edge.loopexit:                             ; preds = %.lr.ph25, %12
  %.018.lcssa.ph.in = phi i64 [ %indvars.iv.next, %12 ], [ %indvars.iv, %.lr.ph25 ]
  %.018.lcssa.ph = trunc i64 %.018.lcssa.ph.in to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %.preheader, %._crit_edge.loopexit
  %15 = phi ptr [ %6, %.preheader ], [ %8, %._crit_edge.loopexit ]
  %16 = phi i32 [ %2, %.preheader ], [ %.pre.pre, %._crit_edge.loopexit ]
  %.018.lcssa = phi i32 [ 0, %.preheader ], [ %.018.lcssa.ph, %._crit_edge.loopexit ]
  %17 = icmp eq i32 %.018.lcssa, %16
  br i1 %17, label %.loopexit, label %18

18:                                               ; preds = %._crit_edge
  tail call void @_ZN5Graph7DFSUtilEiPb(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.018.lcssa, ptr noundef nonnull %4)
  %19 = load i32, ptr %0, align 8, !tbaa !5
  %.not2228 = icmp slt i32 %19, 1
  br i1 %.not2228, label %.loopexit, label %.lr.ph31

.lr.ph31:                                         ; preds = %18, %28
  %20 = phi i32 [ %29, %28 ], [ %19, %18 ]
  %indvars.iv37 = phi i64 [ %indvars.iv.next38, %28 ], [ 0, %18 ]
  %21 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv37
  %22 = load i8, ptr %21, align 1, !tbaa !11, !range !16, !noundef !17
  %23 = trunc nuw i8 %22 to i1
  br i1 %23, label %28, label %24

24:                                               ; preds = %.lr.ph31
  %25 = load ptr, ptr %15, align 8, !tbaa !13
  %26 = getelementptr inbounds %"class.std::__cxx11::list", ptr %25, i64 %indvars.iv37
  %27 = tail call noundef i64 @_ZNKSt7__cxx114listIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %26) #5
  %.not21 = icmp eq i64 %27, 0
  br i1 %.not21, label %._crit_edge41, label %.loopexit

._crit_edge41:                                    ; preds = %24
  %.pre42 = load i32, ptr %0, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %._crit_edge41, %.lr.ph31
  %29 = phi i32 [ %.pre42, %._crit_edge41 ], [ %20, %.lr.ph31 ]
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %30 = sext i32 %29 to i64
  %.not22.not = icmp slt i64 %indvars.iv.next38, %30
  br i1 %.not22.not, label %.lr.ph31, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %24, %28, %18, %._crit_edge
  %.1 = phi i1 [ true, %._crit_edge ], [ true, %18 ], [ false, %24 ], [ true, %28 ]
  ret i1 %.1
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt7__cxx114listIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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


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