; LLVM IR from upupming/algorithm :: acwing/算法基础课/第三讲 搜索与图论/染色法判定二分图/860. 染色法判定二分图.ll (Z3dfsii)

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

@head = external dso_local global [100010 x i32], align 16
@ver = external dso_local global [200010 x i32], align 16
@Next = external dso_local global [200010 x i32], align 16
@v = external dso_local global [100010 x i32], align 16

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

17:                                               ; preds = %51, %2
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 2, ptr %7, align 4
  br label %56

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [200010 x i32], ptr @ver, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  store i32 %25, ptr %8, align 4, !tbaa !5
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100010 x i32], ptr @v, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %38, label %31

31:                                               ; preds = %21
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sub nsw i32 3, %33
  %35 = call noundef zeroext i1 @_Z3dfsii(i32 noundef %32, i32 noundef %34)
  br i1 %35, label %37, label %36

36:                                               ; preds = %31
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %48

37:                                               ; preds = %31
  br label %47

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

45:                                               ; preds = %38
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %48

46:                                               ; preds = %38
  br label %47

47:                                               ; preds = %46, %37
  store i32 0, ptr %7, align 4
  br label %48

48:                                               ; preds = %47, %45, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %49 = load i32, ptr %7, align 4
  switch i32 %49, label %56 [
    i32 0, label %50
  ]

50:                                               ; preds = %48
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [200010 x i32], ptr @Next, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  store i32 %55, ptr %6, align 4, !tbaa !5
  br label %17, !llvm.loop !9

56:                                               ; preds = %48, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %57 = load i32, ptr %7, align 4
  switch i32 %57, label %61 [
    i32 2, label %58
    i32 1, label %59
  ]

58:                                               ; preds = %56
  store i1 true, ptr %3, align 1
  br label %59

59:                                               ; preds = %58, %56
  %60 = load i1, ptr %3, align 1
  ret i1 %60

61:                                               ; preds = %56
  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"

@head = external dso_local local_unnamed_addr global [100010 x i32], align 16
@ver = external dso_local local_unnamed_addr global [200010 x i32], align 16
@Next = external dso_local local_unnamed_addr global [200010 x i32], align 16
@v = 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 noundef zeroext i1 @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [100010 x i32], ptr @v, i64 0, i64 %3
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %3
  %.01518 = load i32, ptr %5, align 4, !tbaa !5
  %.not19 = icmp eq i32 %.01518, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %6 = sub nsw i32 3, %1
  br label %7

7:                                                ; preds = %.lr.ph, %.critedge
  %.01520 = phi i32 [ %.01518, %.lr.ph ], [ %.015, %.critedge ]
  %8 = sext i32 %.01520 to i64
  %9 = getelementptr inbounds [200010 x i32], ptr @ver, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [100010 x i32], ptr @v, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not17 = icmp eq i32 %13, 0
  br i1 %.not17, label %14, label %16

14:                                               ; preds = %7
  %15 = tail call noundef zeroext i1 @_Z3dfsii(i32 noundef %10, i32 noundef %6)
  br i1 %15, label %.critedge, label %._crit_edge

16:                                               ; preds = %7
  %17 = icmp eq i32 %13, %1
  br i1 %17, label %._crit_edge, label %.critedge

.critedge:                                        ; preds = %16, %14
  %18 = getelementptr inbounds [200010 x i32], ptr @Next, i64 0, i64 %8
  %.015 = load i32, ptr %18, align 4, !tbaa !5
  %.not = icmp eq i32 %.015, 0
  br i1 %.not, label %._crit_edge, label %7, !llvm.loop !9

._crit_edge:                                      ; preds = %.critedge, %16, %14, %2
  %.not.lcssa = phi i1 [ true, %2 ], [ false, %14 ], [ false, %16 ], [ true, %.critedge ]
  ret i1 %.not.lcssa
}

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


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