; LLVM IR from Tunghohin/Competitive_Coding :: Uva/uva1364.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"

%struct.edge = type { i32, i32 }

@e = external dso_local global [2000010 x %struct.edge], align 16
@head = external dso_local global [1010 x i32], align 16
@color = external dso_local global [1010 x i32], align 16
@in_bcc = external dso_local global [1010 x i8], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsii(i32 noundef %0, i32 noundef %1) #1 {
  %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 [1010 x i32], ptr @color, 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 [1010 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 = %59, %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 %65

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 [2000010 x %struct.edge], ptr @e, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.edge, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !9
  store i32 %26, ptr %8, align 4, !tbaa !5
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1010 x i8], ptr @in_bcc, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !11, !range !13, !noundef !14
  %31 = trunc i8 %30 to i1
  br i1 %31, label %33, label %32

32:                                               ; preds = %21
  store i32 4, ptr %7, align 4
  br label %56

33:                                               ; preds = %21
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [1010 x i32], ptr @color, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %46, label %39

39:                                               ; preds = %33
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = sub nsw i32 3, %41
  %43 = call noundef zeroext i1 @_Z3dfsii(i32 noundef %40, i32 noundef %42)
  br i1 %43, label %45, label %44

44:                                               ; preds = %39
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %56

45:                                               ; preds = %39
  br label %55

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

53:                                               ; preds = %46
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %56

54:                                               ; preds = %46
  br label %55

55:                                               ; preds = %54, %45
  store i32 0, ptr %7, align 4
  br label %56

56:                                               ; preds = %55, %53, %44, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %57 = load i32, ptr %7, align 4
  switch i32 %57, label %65 [
    i32 0, label %58
    i32 4, label %59
  ]

58:                                               ; preds = %56
  br label %59

59:                                               ; preds = %58, %56
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [2000010 x %struct.edge], ptr @e, i64 0, i64 %61
  %63 = getelementptr inbounds %struct.edge, ptr %62, i32 0, i32 1
  %64 = load i32, ptr %63, align 4, !tbaa !15
  store i32 %64, ptr %6, align 4, !tbaa !5
  br label %17, !llvm.loop !16

65:                                               ; preds = %56, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %66 = load i32, ptr %7, align 4
  switch i32 %66, label %70 [
    i32 2, label %67
    i32 1, label %68
  ]

67:                                               ; preds = %65
  store i1 true, ptr %3, align 1
  br label %68

68:                                               ; preds = %67, %65
  %69 = load i1, ptr %3, align 1
  ret i1 %69

70:                                               ; preds = %65
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!10, !6, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"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.edge = type { i32, i32 }

@e = external dso_local local_unnamed_addr global [2000010 x %struct.edge], align 16
@head = external dso_local local_unnamed_addr global [1010 x i32], align 16
@color = external dso_local local_unnamed_addr global [1010 x i32], align 16
@in_bcc = external dso_local local_unnamed_addr global [1010 x i8], 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 [1010 x i32], ptr @color, i64 0, i64 %3
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds [1010 x i32], ptr @head, i64 0, i64 %3
  %.01620 = load i32, ptr %5, align 4, !tbaa !5
  %.not21 = icmp eq i32 %.01620, 0
  br i1 %.not21, label %.thread, label %.lr.ph

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

7:                                                ; preds = %.lr.ph, %22
  %.01622 = phi i32 [ %.01620, %.lr.ph ], [ %.016, %22 ]
  %8 = sext i32 %.01622 to i64
  %9 = getelementptr inbounds [2000010 x %struct.edge], ptr @e, i64 0, i64 %8
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1010 x i8], ptr @in_bcc, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !11, !range !13, !noundef !14
  %14 = trunc nuw i8 %13 to i1
  br i1 %14, label %15, label %22

15:                                               ; preds = %7
  %16 = getelementptr inbounds [1010 x i32], ptr @color, i64 0, i64 %11
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %.not18 = icmp eq i32 %17, 0
  br i1 %.not18, label %18, label %20

18:                                               ; preds = %15
  %19 = tail call noundef zeroext i1 @_Z3dfsii(i32 noundef %10, i32 noundef %6)
  br i1 %19, label %22, label %.thread

20:                                               ; preds = %15
  %21 = icmp eq i32 %17, %1
  br i1 %21, label %.thread, label %22

22:                                               ; preds = %18, %20, %7
  %23 = getelementptr inbounds i8, ptr %9, i64 4
  %.016 = load i32, ptr %23, align 4, !tbaa !5
  %.not = icmp eq i32 %.016, 0
  br i1 %.not, label %.thread, label %7, !llvm.loop !15

.thread:                                          ; preds = %22, %18, %20, %2
  %.not.lcssa = phi i1 [ true, %2 ], [ false, %20 ], [ false, %18 ], [ true, %22 ]
  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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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