; LLVM IR from Tunghohin/Competitive_Coding :: Daimayuan/226.ll (Z5dfs_1ii)

; 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.std::pair" = type { i32, i32 }
%struct.edge = type { i32, i32 }

@mx_down = external dso_local global [100010 x %"struct.std::pair"], align 16
@smx_down = external dso_local global [100010 x %"struct.std::pair"], align 16
@e = external dso_local global [200020 x %struct.edge], align 16
@head = external dso_local global [100010 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5dfs_1ii(i32 noundef %0, i32 noundef %1) #0 {
  %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
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %11, ptr %5, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %98, %2
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [200020 x %struct.edge], ptr @e, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.edge, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !9
  store i32 %21, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = icmp eq i32 %22, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %16
  store i32 4, ptr %6, align 4
  br label %95

26:                                               ; preds = %16
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z5dfs_1ii(i32 noundef %27, i32 noundef %28)
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @mx_down, i64 0, i64 %30
  %32 = getelementptr inbounds %"struct.std::pair", ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = add nsw i32 %33, 1
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @mx_down, i64 0, i64 %36
  %38 = getelementptr inbounds %"struct.std::pair", ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !11
  %40 = icmp sgt i32 %34, %39
  br i1 %40, label %41, label %64

41:                                               ; preds = %26
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @mx_down, i64 0, i64 %43
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @smx_down, i64 0, i64 %46
  %48 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8) %47, ptr noundef nonnull align 4 dereferenceable(8) %44)
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @mx_down, i64 0, i64 %50
  %52 = getelementptr inbounds %"struct.std::pair", ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !11
  %54 = add nsw i32 %53, 1
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @mx_down, i64 0, i64 %56
  %58 = getelementptr inbounds %"struct.std::pair", ptr %57, i32 0, i32 0
  store i32 %54, ptr %58, align 8, !tbaa !11
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @mx_down, i64 0, i64 %61
  %63 = getelementptr inbounds %"struct.std::pair", ptr %62, i32 0, i32 1
  store i32 %59, ptr %63, align 4, !tbaa !13
  br label %94

64:                                               ; preds = %26
  %65 = load i32, ptr %7, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @mx_down, i64 0, i64 %66
  %68 = getelementptr inbounds %"struct.std::pair", ptr %67, i32 0, i32 0
  %69 = load i32, ptr %68, align 8, !tbaa !11
  %70 = add nsw i32 %69, 1
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @smx_down, i64 0, i64 %72
  %74 = getelementptr inbounds %"struct.std::pair", ptr %73, i32 0, i32 0
  %75 = load i32, ptr %74, align 8, !tbaa !11
  %76 = icmp sgt i32 %70, %75
  br i1 %76, label %77, label %93

77:                                               ; preds = %64
  %78 = load i32, ptr %7, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @mx_down, i64 0, i64 %79
  %81 = getelementptr inbounds %"struct.std::pair", ptr %80, i32 0, i32 0
  %82 = load i32, ptr %81, align 8, !tbaa !11
  %83 = add nsw i32 %82, 1
  %84 = load i32, ptr %3, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @smx_down, i64 0, i64 %85
  %87 = getelementptr inbounds %"struct.std::pair", ptr %86, i32 0, i32 0
  store i32 %83, ptr %87, align 8, !tbaa !11
  %88 = load i32, ptr %7, align 4, !tbaa !5
  %89 = load i32, ptr %3, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @smx_down, i64 0, i64 %90
  %92 = getelementptr inbounds %"struct.std::pair", ptr %91, i32 0, i32 1
  store i32 %88, ptr %92, align 4, !tbaa !13
  br label %93

93:                                               ; preds = %77, %64
  br label %94

94:                                               ; preds = %93, %41
  store i32 0, ptr %6, align 4
  br label %95

95:                                               ; preds = %94, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %96 = load i32, ptr %6, align 4
  switch i32 %96, label %105 [
    i32 0, label %97
    i32 4, label %98
  ]

97:                                               ; preds = %95
  br label %98

98:                                               ; preds = %97, %95
  %99 = load i32, ptr %5, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [200020 x %struct.edge], ptr @e, i64 0, i64 %100
  %102 = getelementptr inbounds %struct.edge, ptr %101, i32 0, i32 1
  %103 = load i32, ptr %102, align 4, !tbaa !14
  store i32 %103, ptr %5, align 4, !tbaa !5
  br label %12, !llvm.loop !15

104:                                              ; preds = %15
  ret void

105:                                              ; preds = %95
  unreachable
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #2 align 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 = { 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, !6, i64 0}
!12 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 4}
!14 = !{!10, !6, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"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.std::pair" = type { i32, i32 }
%struct.edge = type { i32, i32 }

@mx_down = external dso_local global [100010 x %"struct.std::pair"], align 16
@smx_down = external dso_local global [100010 x %"struct.std::pair"], align 16
@e = external dso_local local_unnamed_addr global [200020 x %struct.edge], align 16
@head = external dso_local local_unnamed_addr global [100010 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5dfs_1ii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %3
  %.026 = load i32, ptr %4, align 4, !tbaa !5
  %.not27 = icmp eq i32 %.026, 0
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %5 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @mx_down, i64 0, i64 %3
  %6 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @smx_down, i64 0, i64 %3
  br label %7

._crit_edge:                                      ; preds = %26, %2
  ret void

7:                                                ; preds = %.lr.ph, %26
  %.028 = phi i32 [ %.026, %.lr.ph ], [ %.0, %26 ]
  %8 = sext i32 %.028 to i64
  %9 = getelementptr inbounds [200020 x %struct.edge], ptr @e, i64 0, i64 %8
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp eq i32 %10, %1
  br i1 %11, label %26, label %12

12:                                               ; preds = %7
  tail call void @_Z5dfs_1ii(i32 noundef %10, i32 noundef %0)
  %13 = sext i32 %10 to i64
  %14 = getelementptr inbounds [100010 x %"struct.std::pair"], ptr @mx_down, i64 0, i64 %13
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = add nsw i32 %15, 1
  %17 = load i32, ptr %5, align 8, !tbaa !11
  %.not24 = icmp slt i32 %15, %17
  br i1 %.not24, label %22, label %18

18:                                               ; preds = %12
  %19 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(8) %5)
  %20 = load i32, ptr %14, align 8, !tbaa !11
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %5, align 8, !tbaa !11
  br label %.sink.split

22:                                               ; preds = %12
  %23 = load i32, ptr %6, align 8, !tbaa !11
  %.not25 = icmp slt i32 %15, %23
  br i1 %.not25, label %26, label %24

24:                                               ; preds = %22
  store i32 %16, ptr %6, align 8, !tbaa !11
  br label %.sink.split

.sink.split:                                      ; preds = %24, %18
  %25 = phi ptr [ @mx_down, %18 ], [ @smx_down, %24 ]
  %.sink = getelementptr inbounds [100010 x %"struct.std::pair"], ptr %25, i64 0, i64 %3, i32 1
  store i32 %10, ptr %.sink, align 4, !tbaa !13
  br label %26

26:                                               ; preds = %.sink.split, %22, %7
  %27 = getelementptr inbounds i8, ptr %9, i64 4
  %.0 = load i32, ptr %27, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %._crit_edge, label %7, !llvm.loop !14
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #0 align 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" }

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


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