; LLVM IR from lzyrapx/Competitive-Programming :: ACdream/1003（DFS）.ll (Z3dfsiii)

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

@n = external dso_local global i32, align 4
@Min = external dso_local global i32, align 4
@pill = external dso_local global [23 x i32], align 16
@vis = external dso_local global [23 x i32], align 16
@q = external dso_local global %"class.std::vector", align 8
@flag = external dso_local global i8, align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %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 %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr @Min, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  br label %105

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %14 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %14, ptr %7, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %100, %13
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = icmp sle i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 2, ptr %8, align 4
  br label %103

20:                                               ; preds = %15
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [23 x i32], ptr @vis, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %99

26:                                               ; preds = %20
  %27 = load i8, ptr @flag, align 1, !tbaa !9, !range !11, !noundef !12
  %28 = trunc i8 %27 to i1
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  store i32 1, ptr %8, align 4
  br label %103

30:                                               ; preds = %26
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = icmp sgt i32 %31, 1
  br i1 %32, label %33, label %52

33:                                               ; preds = %30
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [23 x i32], ptr @pill, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [23 x i32], ptr @pill, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = icmp eq i32 %37, %42
  br i1 %43, label %44, label %52

44:                                               ; preds = %33
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = sub nsw i32 %45, 1
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [23 x i32], ptr @vis, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %44
  br label %100

52:                                               ; preds = %44, %33, %30
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [23 x i32], ptr @pill, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = icmp sgt i32 %56, %57
  br i1 %58, label %59, label %60

59:                                               ; preds = %52
  store i32 1, ptr %8, align 4
  br label %103

60:                                               ; preds = %52
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [23 x i32], ptr @vis, i64 0, i64 %62
  store i32 1, ptr %63, align 4, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [23 x i32], ptr @pill, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = icmp eq i32 %67, %68
  br i1 %69, label %70, label %85

70:                                               ; preds = %60
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @q) #3
  %74 = sub i64 %73, 1
  %75 = icmp eq i64 %72, %74
  br i1 %75, label %76, label %77

76:                                               ; preds = %70
  store i8 1, ptr @flag, align 1, !tbaa !9
  store i32 1, ptr %8, align 4
  br label %103

77:                                               ; preds = %70
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  %80 = sext i32 %79 to i64
  %81 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @q, i64 noundef %80) #3
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = load i32, ptr %6, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  call void @_Z3dfsiii(i32 noundef 1, i32 noundef %82, i32 noundef %84)
  br label %95

85:                                               ; preds = %60
  %86 = load i32, ptr %7, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  %88 = load i32, ptr %5, align 4, !tbaa !5
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [23 x i32], ptr @pill, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = sub nsw i32 %88, %92
  %94 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsiii(i32 noundef %87, i32 noundef %93, i32 noundef %94)
  br label %95

95:                                               ; preds = %85, %77
  %96 = load i32, ptr %7, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [23 x i32], ptr @vis, i64 0, i64 %97
  store i32 0, ptr %98, align 4, !tbaa !5
  br label %99

99:                                               ; preds = %95, %20
  br label %100

100:                                              ; preds = %99, %51
  %101 = load i32, ptr %7, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %7, align 4, !tbaa !5
  br label %15, !llvm.loop !13

103:                                              ; preds = %76, %59, %29, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %104 = load i32, ptr %8, align 4
  switch i32 %104, label %106 [
    i32 2, label %105
    i32 1, label %105
  ]

105:                                              ; preds = %103, %103, %12
  ret void

106:                                              ; preds = %103
  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 i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%"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 }

@n = external dso_local local_unnamed_addr global i32, align 4
@Min = external dso_local local_unnamed_addr global i32, align 4
@pill = external dso_local local_unnamed_addr global [23 x i32], align 16
@vis = external dso_local local_unnamed_addr global [23 x i32], align 16
@q = external dso_local global %"class.std::vector", align 8
@flag = external dso_local local_unnamed_addr global i8, align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @Min, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, %1
  %6 = load i32, ptr @n, align 4
  %.not24 = icmp slt i32 %6, %0
  %or.cond = select i1 %5, i1 true, i1 %.not24
  br i1 %or.cond, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %7 = sext i32 %2 to i64
  %8 = add nsw i32 %2, 1
  %9 = sext i32 %8 to i64
  %10 = sext i32 %0 to i64
  br label %11

11:                                               ; preds = %.lr.ph, %48
  %12 = phi i32 [ %6, %.lr.ph ], [ %49, %48 ]
  %indvars.iv = phi i64 [ %10, %.lr.ph ], [ %indvars.iv.next, %48 ]
  %13 = getelementptr inbounds [23 x i32], ptr @vis, i64 0, i64 %indvars.iv
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %48

16:                                               ; preds = %11
  %17 = load i8, ptr @flag, align 1, !tbaa !9, !range !11, !noundef !12
  %18 = trunc nuw i8 %17 to i1
  br i1 %18, label %.loopexit, label %19

19:                                               ; preds = %16
  %20 = icmp sgt i64 %indvars.iv, 1
  %21 = getelementptr inbounds [23 x i32], ptr @pill, i64 0, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !5
  br i1 %20, label %23, label %._crit_edge

23:                                               ; preds = %19
  %24 = add nsw i64 %indvars.iv, -1
  %25 = getelementptr inbounds [23 x i32], ptr @pill, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp eq i32 %22, %26
  br i1 %27, label %28, label %._crit_edge

28:                                               ; preds = %23
  %29 = getelementptr inbounds [23 x i32], ptr @vis, i64 0, i64 %24
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %48, label %._crit_edge

._crit_edge:                                      ; preds = %19, %28, %23
  %32 = icmp sgt i32 %22, %1
  br i1 %32, label %.loopexit, label %33

33:                                               ; preds = %._crit_edge
  store i32 1, ptr %13, align 4, !tbaa !5
  %34 = icmp eq i32 %22, %1
  br i1 %34, label %35, label %43

35:                                               ; preds = %33
  %36 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @q) #1
  %37 = add i64 %36, -1
  %38 = icmp eq i64 %37, %7
  br i1 %38, label %39, label %40

39:                                               ; preds = %35
  store i8 1, ptr @flag, align 1, !tbaa !9
  br label %.loopexit

40:                                               ; preds = %35
  %41 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @q, i64 noundef %9) #1
  %42 = load i32, ptr %41, align 4, !tbaa !5
  tail call void @_Z3dfsiii(i32 noundef 1, i32 noundef %42, i32 noundef %8)
  br label %47

43:                                               ; preds = %33
  %44 = sub nsw i32 %1, %22
  %45 = trunc i64 %indvars.iv to i32
  %46 = add i32 %45, 1
  tail call void @_Z3dfsiii(i32 noundef %46, i32 noundef %44, i32 noundef %2)
  br label %47

47:                                               ; preds = %43, %40
  store i32 0, ptr %13, align 4, !tbaa !5
  %.pre30 = load i32, ptr @n, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %11, %47, %28
  %49 = phi i32 [ %12, %11 ], [ %.pre30, %47 ], [ %12, %28 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %50 = sext i32 %49 to i64
  %.not.not = icmp slt i64 %indvars.iv, %50
  br i1 %.not.not, label %11, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %._crit_edge, %16, %48, %39, %3
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) 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" }
attributes #1 = { 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 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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