; LLVM IR from tangjz/acm-icpc :: codeforces/complete/510E.ll (Z3bfsv)

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

@s = external dso_local global i32, align 4
@t = external dso_local global i32, align 4
@pre = external dso_local global [202 x i32], align 16
@level = external dso_local global [202 x i32], align 16
@que = external dso_local global [202 x i32], align 16
@head = external dso_local global i32, align 4
@tail = external dso_local global i32, align 4
@e = external dso_local global [82012 x %struct.Edge], 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 nounwind uwtable
define dso_local noundef zeroext i1 @_Z3bfsv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 1, ptr @tail, align 4, !tbaa !5
  store i32 1, ptr @head, align 4, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 16 @level, i8 0, i64 808, i1 false)
  %3 = load i32, ptr @s, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [202 x i32], ptr @level, i64 0, i64 %4
  store i32 1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr @s, align 4, !tbaa !5
  %7 = load i32, ptr @tail, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @tail, align 4, !tbaa !5
  %9 = sext i32 %7 to i64
  %10 = getelementptr inbounds [202 x i32], ptr @que, i64 0, i64 %9
  store i32 %6, ptr %10, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %75, %0
  %12 = load i32, ptr @head, align 4, !tbaa !5
  %13 = load i32, ptr @tail, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %15, label %76

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %16 = load i32, ptr @head, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @head, align 4, !tbaa !5
  %18 = sext i32 %16 to i64
  %19 = getelementptr inbounds [202 x i32], ptr @que, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  store i32 %20, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [202 x i32], ptr @pre, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %69, %15
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = icmp ne i32 %26, -1
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %75

29:                                               ; preds = %25
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [82012 x %struct.Edge], ptr @e, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.Edge, ptr %32, i32 0, i32 2
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %68

36:                                               ; preds = %29
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [82012 x %struct.Edge], ptr @e, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.Edge, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [202 x i32], ptr @level, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %68, label %46

46:                                               ; preds = %36
  %47 = load i32, ptr %1, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [202 x i32], ptr @level, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [82012 x %struct.Edge], ptr @e, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.Edge, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !11
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [202 x i32], ptr @level, i64 0, i64 %57
  store i32 %51, ptr %58, align 4, !tbaa !5
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [82012 x %struct.Edge], ptr @e, i64 0, i64 %60
  %62 = getelementptr inbounds %struct.Edge, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 4, !tbaa !11
  %64 = load i32, ptr @tail, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr @tail, align 4, !tbaa !5
  %66 = sext i32 %64 to i64
  %67 = getelementptr inbounds [202 x i32], ptr @que, i64 0, i64 %66
  store i32 %63, ptr %67, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %46, %36, %29
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [82012 x %struct.Edge], ptr @e, i64 0, i64 %71
  %73 = getelementptr inbounds %struct.Edge, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 4, !tbaa !12
  store i32 %74, ptr %2, align 4, !tbaa !5
  br label %25, !llvm.loop !13

75:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %11, !llvm.loop !15

76:                                               ; preds = %11
  %77 = load i32, ptr @t, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [202 x i32], ptr @level, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = icmp ne i32 %80, 0
  ret i1 %81
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !6, i64 8}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@s = external dso_local local_unnamed_addr global i32, align 4
@t = external dso_local local_unnamed_addr global i32, align 4
@pre = external dso_local local_unnamed_addr global [202 x i32], align 16
@level = external dso_local local_unnamed_addr global [202 x i32], align 16
@que = external dso_local local_unnamed_addr global [202 x i32], align 16
@head = external dso_local local_unnamed_addr global i32, align 4
@tail = external dso_local local_unnamed_addr global i32, align 4
@e = external dso_local local_unnamed_addr global [82012 x %struct.Edge], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z3bfsv() local_unnamed_addr #0 {
.lr.ph20.preheader:
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(808) @level, i8 0, i64 808, i1 false)
  %0 = load i32, ptr @s, align 4, !tbaa !5
  %1 = sext i32 %0 to i64
  %2 = getelementptr inbounds [202 x i32], ptr @level, i64 0, i64 %1
  store i32 1, ptr %2, align 4, !tbaa !5
  store i32 2, ptr @tail, align 4, !tbaa !5
  store i32 %0, ptr getelementptr inbounds (i8, ptr @que, i64 4), align 4, !tbaa !5
  br label %.lr.ph20

.loopexit:                                        ; preds = %28, %.lr.ph20
  %tail.promoted17 = phi i32 [ %tail.promoted1819, %.lr.ph20 ], [ %tail.promoted15, %28 ]
  %3 = sext i32 %tail.promoted17 to i64
  %4 = icmp slt i64 %indvars.iv.next, %3
  br i1 %4, label %.lr.ph20, label %30, !llvm.loop !9

.lr.ph20:                                         ; preds = %.lr.ph20.preheader, %.loopexit
  %indvars.iv = phi i64 [ 1, %.lr.ph20.preheader ], [ %indvars.iv.next, %.loopexit ]
  %tail.promoted1819 = phi i32 [ 2, %.lr.ph20.preheader ], [ %tail.promoted17, %.loopexit ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %5 = getelementptr inbounds [202 x i32], ptr @que, i64 0, i64 %indvars.iv
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [202 x i32], ptr @pre, i64 0, i64 %7
  %.011 = load i32, ptr %8, align 4, !tbaa !5
  %.not12 = icmp eq i32 %.011, -1
  br i1 %.not12, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph20
  %9 = getelementptr inbounds [202 x i32], ptr @level, i64 0, i64 %7
  br label %10

10:                                               ; preds = %.lr.ph, %28
  %tail.promoted16 = phi i32 [ %tail.promoted1819, %.lr.ph ], [ %tail.promoted15, %28 ]
  %.013 = phi i32 [ %.011, %.lr.ph ], [ %.0, %28 ]
  %11 = phi i32 [ %tail.promoted1819, %.lr.ph ], [ %29, %28 ]
  %12 = sext i32 %.013 to i64
  %13 = getelementptr inbounds [82012 x %struct.Edge], ptr @e, i64 0, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %.not9 = icmp eq i32 %15, 0
  br i1 %.not9, label %28, label %16

16:                                               ; preds = %10
  %17 = getelementptr inbounds i8, ptr %13, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [202 x i32], ptr @level, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not10 = icmp eq i32 %21, 0
  br i1 %.not10, label %22, label %28

22:                                               ; preds = %16
  %23 = load i32, ptr %9, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %20, align 4, !tbaa !5
  %25 = add nsw i32 %11, 1
  store i32 %25, ptr @tail, align 4, !tbaa !5
  %26 = sext i32 %11 to i64
  %27 = getelementptr inbounds [202 x i32], ptr @que, i64 0, i64 %26
  store i32 %18, ptr %27, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %10, %16, %22
  %tail.promoted15 = phi i32 [ %tail.promoted16, %10 ], [ %tail.promoted16, %16 ], [ %25, %22 ]
  %29 = phi i32 [ %11, %10 ], [ %11, %16 ], [ %25, %22 ]
  %.0 = load i32, ptr %13, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, -1
  br i1 %.not, label %.loopexit, label %10, !llvm.loop !14

30:                                               ; preds = %.loopexit
  %31 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %31, ptr @head, align 4, !tbaa !5
  %32 = load i32, ptr @t, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [202 x i32], ptr @level, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp ne i32 %35, 0
  ret i1 %36
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse 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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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"}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!13 = !{!12, !6, i64 4}
!14 = distinct !{!14, !10}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass