; LLVM IR from tangjz/acm-icpc :: hdu/4673.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 [3003 x i32], align 16
@lev = external dso_local global [3003 x i32], align 16
@e = external dso_local global [66003 x %struct.Edge], align 16
@_ZZ3bfsvE3que = external hidden global [3003 x i32], 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
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @N, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = mul i64 %6, 4
  call void @llvm.memset.p0.i64(ptr align 16 @lev, i8 -1, i64 %7, i1 false)
  %8 = load i32, ptr @S, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [3003 x i32], ptr @lev, i64 0, i64 %9
  store i32 0, ptr %10, align 4, !tbaa !5
  %11 = load i32, ptr @S, align 4, !tbaa !5
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %12 to i64
  %15 = getelementptr inbounds [3003 x i32], ptr @_ZZ3bfsvE3que, i64 0, i64 %14
  store i32 %11, ptr %15, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %80, %0
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %81

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

30:                                               ; preds = %74, %20
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = icmp ne i32 %31, -1
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %80

34:                                               ; preds = %30
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [66003 x %struct.Edge], ptr @e, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.Edge, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [3003 x i32], ptr @lev, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = icmp eq i32 %42, -1
  br i1 %43, label %44, label %73

44:                                               ; preds = %34
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [66003 x %struct.Edge], ptr @e, i64 0, i64 %46
  %48 = getelementptr inbounds %struct.Edge, ptr %47, i32 0, i32 2
  %49 = load i32, ptr %48, align 4, !tbaa !11
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %73

51:                                               ; preds = %44
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [3003 x i32], ptr @lev, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [66003 x %struct.Edge], ptr @e, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.Edge, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [3003 x i32], ptr @lev, i64 0, i64 %62
  store i32 %56, ptr %63, align 4, !tbaa !5
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [66003 x %struct.Edge], ptr @e, i64 0, i64 %65
  %67 = getelementptr inbounds %struct.Edge, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %67, align 4, !tbaa !9
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %2, align 4, !tbaa !5
  %71 = sext i32 %69 to i64
  %72 = getelementptr inbounds [3003 x i32], ptr @_ZZ3bfsvE3que, i64 0, i64 %71
  store i32 %68, ptr %72, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %51, %44, %34
  br label %74

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

80:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %16, !llvm.loop !15

81:                                               ; preds = %16
  %82 = load i32, ptr @T, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [3003 x i32], ptr @lev, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = icmp ne i32 %85, -1
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret i1 %86
}

; 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 4}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 8}
!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 [3003 x i32], align 16
@lev = external dso_local local_unnamed_addr global [3003 x i32], align 16
@e = external dso_local local_unnamed_addr global [66003 x %struct.Edge], align 16
@_ZZ3bfsvE3que = external hidden local_unnamed_addr global [3003 x i32], 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 {
  %1 = load i32, ptr @N, align 4, !tbaa !5
  %2 = sext i32 %1 to i64
  %3 = shl nsw i64 %2, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @lev, i8 -1, i64 %3, i1 false)
  %4 = load i32, ptr @S, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [3003 x i32], ptr @lev, i64 0, i64 %5
  store i32 0, ptr %6, align 4, !tbaa !5
  store i32 %4, ptr @_ZZ3bfsvE3que, align 16, !tbaa !5
  br label %9

.loopexit:                                        ; preds = %33, %9
  %.1.lcssa = phi i32 [ %.01420, %9 ], [ %.2, %33 ]
  %7 = sext i32 %.1.lcssa to i64
  %8 = icmp slt i64 %indvars.iv.next, %7
  br i1 %8, label %9, label %34, !llvm.loop !9

9:                                                ; preds = %0, %.loopexit
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %.loopexit ]
  %.01420 = phi i32 [ 1, %0 ], [ %.1.lcssa, %.loopexit ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = getelementptr inbounds [3003 x i32], ptr @_ZZ3bfsvE3que, i64 0, i64 %indvars.iv
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [3003 x i32], ptr @lnk, i64 0, i64 %12
  %.016 = load i32, ptr %13, align 4, !tbaa !5
  %.not17 = icmp eq i32 %.016, -1
  br i1 %.not17, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %14 = getelementptr inbounds [3003 x i32], ptr @lev, i64 0, i64 %12
  br label %15

15:                                               ; preds = %.lr.ph, %33
  %.019 = phi i32 [ %.016, %.lr.ph ], [ %.0, %33 ]
  %.118 = phi i32 [ %.01420, %.lr.ph ], [ %.2, %33 ]
  %16 = sext i32 %.019 to i64
  %17 = getelementptr inbounds [66003 x %struct.Edge], ptr @e, i64 0, i64 %16
  %18 = getelementptr inbounds i8, ptr %17, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [3003 x i32], ptr @lev, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp eq i32 %22, -1
  br i1 %23, label %24, label %33

24:                                               ; preds = %15
  %25 = getelementptr inbounds i8, ptr %17, i64 8
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %.not15 = icmp eq i32 %26, 0
  br i1 %.not15, label %33, label %27

27:                                               ; preds = %24
  %28 = load i32, ptr %14, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %21, align 4, !tbaa !5
  %30 = add nsw i32 %.118, 1
  %31 = sext i32 %.118 to i64
  %32 = getelementptr inbounds [3003 x i32], ptr @_ZZ3bfsvE3que, i64 0, i64 %31
  store i32 %19, ptr %32, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %15, %24, %27
  %.2 = phi i32 [ %30, %27 ], [ %.118, %24 ], [ %.118, %15 ]
  %.0 = load i32, ptr %17, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, -1
  br i1 %.not, label %.loopexit, label %15, !llvm.loop !14

34:                                               ; preds = %.loopexit
  %35 = load i32, ptr @T, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [3003 x i32], ptr @lev, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp ne i32 %38, -1
  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 4}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !10}


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