; LLVM IR from tangjz/acm-icpc :: 51nod/1336.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 }

@N = external dso_local global i32, align 4
@S = external dso_local global i32, align 4
@T = external dso_local global i32, align 4
@lnk = external dso_local global [210 x i32], align 16
@level = external dso_local global [210 x i32], align 16
@que = external dso_local global [210 x i32], align 16
@L = external dso_local global i32, align 4
@R = external dso_local global i32, align 4
@e = external dso_local global [176400 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 0, ptr @R, align 4, !tbaa !5
  store i32 0, ptr @L, align 4, !tbaa !5
  %3 = load i32, ptr @N, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = mul i64 %4, 4
  call void @llvm.memset.p0.i64(ptr align 16 @level, i8 0, i64 %5, i1 false)
  %6 = load i32, ptr @S, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [210 x i32], ptr @level, i64 0, i64 %7
  store i32 1, ptr %8, align 4, !tbaa !5
  %9 = load i32, ptr @S, align 4, !tbaa !5
  %10 = load i32, ptr @R, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @R, align 4, !tbaa !5
  %12 = sext i32 %10 to i64
  %13 = getelementptr inbounds [210 x i32], ptr @que, i64 0, i64 %12
  store i32 %9, ptr %13, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %78, %0
  %15 = load i32, ptr @L, align 4, !tbaa !5
  %16 = load i32, ptr @R, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %18, label %79

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %19 = load i32, ptr @L, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @L, align 4, !tbaa !5
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds [210 x i32], ptr @que, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  store i32 %23, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [210 x i32], ptr @lnk, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  store i32 %27, ptr %2, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %72, %18
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = icmp ne i32 %29, -1
  br i1 %30, label %32, label %31

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

32:                                               ; preds = %28
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [176400 x %struct.Edge], ptr @e, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.Edge, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %71

39:                                               ; preds = %32
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [176400 x %struct.Edge], ptr @e, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.Edge, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !11
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [210 x i32], ptr @level, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %71, label %49

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

71:                                               ; preds = %49, %39, %32
  br label %72

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

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

79:                                               ; preds = %14
  %80 = load i32, ptr @T, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [210 x i32], ptr @level, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = icmp ne i32 %83, 0
  ret i1 %84
}

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

@N = external dso_local local_unnamed_addr global i32, align 4
@S = external dso_local local_unnamed_addr global i32, align 4
@T = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [210 x i32], align 16
@level = external dso_local local_unnamed_addr global [210 x i32], align 16
@que = external dso_local local_unnamed_addr global [210 x i32], align 16
@L = external dso_local local_unnamed_addr global i32, align 4
@R = external dso_local local_unnamed_addr global i32, align 4
@e = external dso_local local_unnamed_addr global [176400 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:
  %0 = load i32, ptr @N, align 4, !tbaa !5
  %1 = sext i32 %0 to i64
  %2 = shl nsw i64 %1, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @level, i8 0, i64 %2, i1 false)
  %3 = load i32, ptr @S, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [210 x i32], ptr @level, i64 0, i64 %4
  store i32 1, ptr %5, align 4, !tbaa !5
  store i32 1, ptr @R, align 4, !tbaa !5
  store i32 %3, ptr @que, align 16, !tbaa !5
  br label %.lr.ph20

.loopexit:                                        ; preds = %31, %.lr.ph20
  %R.promoted17 = phi i32 [ %R.promoted1819, %.lr.ph20 ], [ %R.promoted15, %31 ]
  %6 = sext i32 %R.promoted17 to i64
  %7 = icmp slt i64 %indvars.iv.next, %6
  br i1 %7, label %.lr.ph20, label %33, !llvm.loop !9

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

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

13:                                               ; preds = %.lr.ph, %31
  %R.promoted16 = phi i32 [ %R.promoted1819, %.lr.ph ], [ %R.promoted15, %31 ]
  %.013 = phi i32 [ %.011, %.lr.ph ], [ %.0, %31 ]
  %14 = phi i32 [ %R.promoted1819, %.lr.ph ], [ %32, %31 ]
  %15 = sext i32 %.013 to i64
  %16 = getelementptr inbounds [176400 x %struct.Edge], ptr @e, i64 0, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %.not9 = icmp eq i32 %18, 0
  br i1 %.not9, label %31, label %19

19:                                               ; preds = %13
  %20 = getelementptr inbounds i8, ptr %16, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !13
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [210 x i32], ptr @level, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %.not10 = icmp eq i32 %24, 0
  br i1 %.not10, label %25, label %31

25:                                               ; preds = %19
  %26 = load i32, ptr %12, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %23, align 4, !tbaa !5
  %28 = add nsw i32 %14, 1
  store i32 %28, ptr @R, align 4, !tbaa !5
  %29 = sext i32 %14 to i64
  %30 = getelementptr inbounds [210 x i32], ptr @que, i64 0, i64 %29
  store i32 %21, ptr %30, align 4, !tbaa !5
  br label %31

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

33:                                               ; preds = %.loopexit
  %34 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %34, ptr @L, align 4, !tbaa !5
  %35 = load i32, ptr @T, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [210 x i32], ptr @level, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp ne i32 %38, 0
  ret i1 %39
}

; 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,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass