; LLVM IR from upupming/algorithm :: acwing/寒假每日一题（提高组）/week2/257. 关押罪犯.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"

@head = external dso_local global [20010 x i32], align 16
@ver = external dso_local global [200010 x i32], align 16
@edge = external dso_local global [200010 x i32], align 16
@Next = external dso_local global [200010 x i32], align 16
@color = external dso_local global [20010 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i1, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [20010 x i32], ptr @color, i64 0, i64 %14
  store i32 %12, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [20010 x i32], ptr @head, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  store i32 %19, ptr %8, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %67, %3
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 2, ptr %9, align 4
  br label %72

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [200010 x i32], ptr @ver, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  store i32 %28, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200010 x i32], ptr @edge, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  store i32 %32, ptr %11, align 4, !tbaa !5
  %33 = load i32, ptr %11, align 4, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = icmp sle i32 %33, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %24
  store i32 4, ptr %9, align 4
  br label %64

37:                                               ; preds = %24
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [20010 x i32], ptr @color, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %55

43:                                               ; preds = %37
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [20010 x i32], ptr @color, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [20010 x i32], ptr @color, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = icmp eq i32 %47, %51
  br i1 %52, label %53, label %54

53:                                               ; preds = %43
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %64

54:                                               ; preds = %43
  br label %63

55:                                               ; preds = %37
  %56 = load i32, ptr %10, align 4, !tbaa !5
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = sub nsw i32 3, %57
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = call noundef zeroext i1 @_Z3dfsiii(i32 noundef %56, i32 noundef %58, i32 noundef %59)
  br i1 %60, label %62, label %61

61:                                               ; preds = %55
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %64

62:                                               ; preds = %55
  br label %63

63:                                               ; preds = %62, %54
  store i32 0, ptr %9, align 4
  br label %64

64:                                               ; preds = %63, %61, %53, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %65 = load i32, ptr %9, align 4
  switch i32 %65, label %72 [
    i32 0, label %66
    i32 4, label %67
  ]

66:                                               ; preds = %64
  br label %67

67:                                               ; preds = %66, %64
  %68 = load i32, ptr %8, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [200010 x i32], ptr @Next, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  store i32 %71, ptr %8, align 4, !tbaa !5
  br label %20, !llvm.loop !9

72:                                               ; preds = %64, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %73 = load i32, ptr %9, align 4
  switch i32 %73, label %77 [
    i32 2, label %74
    i32 1, label %75
  ]

74:                                               ; preds = %72
  store i1 true, ptr %4, align 1
  br label %75

75:                                               ; preds = %74, %72
  %76 = load i1, ptr %4, align 1
  ret i1 %76

77:                                               ; preds = %72
  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 [20010 x i32], align 16
@ver = external dso_local local_unnamed_addr global [200010 x i32], align 16
@edge = 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
@color = external dso_local local_unnamed_addr global [20010 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [20010 x i32], ptr @color, i64 0, i64 %4
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds [20010 x i32], ptr @head, i64 0, i64 %4
  %.01725 = load i32, ptr %6, align 4, !tbaa !5
  %.not26 = icmp eq i32 %.01725, 0
  br i1 %.not26, label %.thread, label %.lr.ph

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

8:                                                ; preds = %.lr.ph, %23
  %.01727 = phi i32 [ %.01725, %.lr.ph ], [ %.017, %23 ]
  %9 = sext i32 %.01727 to i64
  %10 = getelementptr inbounds [200010 x i32], ptr @ver, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = getelementptr inbounds [200010 x i32], ptr @edge, i64 0, i64 %9
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not22 = icmp sgt i32 %13, %2
  br i1 %.not22, label %14, label %23

14:                                               ; preds = %8
  %15 = sext i32 %11 to i64
  %16 = getelementptr inbounds [20010 x i32], ptr @color, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %.not23 = icmp eq i32 %17, 0
  br i1 %.not23, label %21, label %18

18:                                               ; preds = %14
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = icmp eq i32 %17, %19
  br i1 %20, label %.thread, label %23

21:                                               ; preds = %14
  %22 = tail call noundef zeroext i1 @_Z3dfsiii(i32 noundef %11, i32 noundef %7, i32 noundef %2)
  br i1 %22, label %23, label %.thread

23:                                               ; preds = %18, %21, %8
  %24 = getelementptr inbounds [200010 x i32], ptr @Next, i64 0, i64 %9
  %.017 = load i32, ptr %24, align 4, !tbaa !5
  %.not = icmp eq i32 %.017, 0
  br i1 %.not, label %.thread, label %8, !llvm.loop !9

.thread:                                          ; preds = %23, %18, %21, %3
  %.not.lcssa = phi i1 [ true, %3 ], [ false, %21 ], [ false, %18 ], [ true, %23 ]
  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