; LLVM IR from lzyrapx/Competitive-Programming :: LibreOJ/6084（dfs）.ll (Z3dfsi)

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

@n = external dso_local global i32, align 4
@Next = external dso_local global [100010 x [2 x i32]], align 16
@vis = external dso_local global [100010 x i32], align 16
@check = external dso_local global [100010 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [100010 x i32], ptr @vis, i64 0, i64 %7
  store i32 1, ptr %8, align 4, !tbaa !5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp eq i32 %9, %10
  br i1 %11, label %12, label %16

12:                                               ; preds = %1
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100010 x i32], ptr @check, i64 0, i64 %14
  store i32 1, ptr %15, align 4, !tbaa !5
  br label %63

16:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %60, %16
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = icmp sle i32 %18, 1
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %63

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100010 x [2 x i32]], ptr @Next, i64 0, i64 %24
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [2 x i32], ptr %25, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %22, %29
  store i32 %30, ptr %5, align 4, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = icmp slt i32 %31, 1
  br i1 %32, label %37, label %33

33:                                               ; preds = %21
  %34 = load i32, ptr @n, align 4, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %33, %21
  store i32 4, ptr %4, align 4
  br label %57

38:                                               ; preds = %33
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100010 x i32], ptr @vis, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %38
  %45 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z3dfsi(i32 noundef %45)
  br label %46

46:                                               ; preds = %44, %38
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100010 x i32], ptr @check, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %56

52:                                               ; preds = %46
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100010 x i32], ptr @check, i64 0, i64 %54
  store i32 1, ptr %55, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %52, %46
  store i32 0, ptr %4, align 4
  br label %57

57:                                               ; preds = %56, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  %58 = load i32, ptr %4, align 4
  switch i32 %58, label %64 [
    i32 0, label %59
    i32 4, label %60
  ]

59:                                               ; preds = %57
  br label %60

60:                                               ; preds = %59, %57
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %3, align 4, !tbaa !5
  br label %17, !llvm.loop !9

63:                                               ; preds = %20, %12
  ret void

64:                                               ; preds = %57
  unreachable
}

; 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

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 = { 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 = distinct !{!9, !10}
!10 = !{!"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"

@n = external dso_local local_unnamed_addr global i32, align 4
@Next = external dso_local local_unnamed_addr global [100010 x [2 x i32]], align 16
@vis = external dso_local local_unnamed_addr global [100010 x i32], align 16
@check = external dso_local local_unnamed_addr global [100010 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [100010 x i32], ptr @vis, i64 0, i64 %2
  store i32 1, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr @n, align 4
  %5 = icmp eq i32 %4, %0
  %6 = getelementptr inbounds [100010 x i32], ptr @check, i64 0, i64 %2
  br i1 %5, label %.loopexit.sink.split, label %.preheader

.preheader:                                       ; preds = %1
  %7 = getelementptr inbounds [100010 x [2 x i32]], ptr @Next, i64 0, i64 %2, i64 0
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = add nsw i32 %8, %0
  %10 = icmp slt i32 %9, 1
  %11 = icmp slt i32 %4, %9
  %or.cond = or i1 %10, %11
  br i1 %or.cond, label %22, label %12

12:                                               ; preds = %.preheader
  %13 = zext nneg i32 %9 to i64
  %14 = getelementptr inbounds [100010 x i32], ptr @vis, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %12
  tail call void @_Z3dfsi(i32 noundef %9)
  br label %18

18:                                               ; preds = %17, %12
  %19 = getelementptr inbounds [100010 x i32], ptr @check, i64 0, i64 %13
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %22, label %21

21:                                               ; preds = %18
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %18, %21, %.preheader
  %23 = getelementptr inbounds [100010 x [2 x i32]], ptr @Next, i64 0, i64 %2, i64 1
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %24, %0
  %26 = icmp slt i32 %25, 1
  %27 = load i32, ptr @n, align 4
  %28 = icmp slt i32 %27, %25
  %or.cond.1 = select i1 %26, i1 true, i1 %28
  br i1 %or.cond.1, label %.loopexit, label %29

29:                                               ; preds = %22
  %30 = zext nneg i32 %25 to i64
  %31 = getelementptr inbounds [100010 x i32], ptr @vis, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  tail call void @_Z3dfsi(i32 noundef %25)
  br label %35

35:                                               ; preds = %34, %29
  %36 = getelementptr inbounds [100010 x i32], ptr @check, i64 0, i64 %30
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %.not.1 = icmp eq i32 %37, 0
  br i1 %.not.1, label %.loopexit, label %.loopexit.sink.split

.loopexit.sink.split:                             ; preds = %35, %1
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.sink.split, %22, %35
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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"}


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