; LLVM IR from Dev-XYS/Algorithms :: Breadth-First-Search.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.vertex = type { i32, i8 }
%struct.edge = type { i32, i32 }

@V = external dso_local global [100000 x %struct.vertex], align 16
@E = external dso_local global [100000 x %struct.edge], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7enqueuei(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7dequeuev() #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z11queue_emptyv() #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3BFSv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  br label %3

3:                                                ; preds = %51, %0
  %4 = call noundef zeroext i1 @_Z11queue_emptyv()
  %5 = xor i1 %4, true
  br i1 %5, label %6, label %52

6:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  %7 = call noundef i32 @_Z7dequeuev()
  store i32 %7, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [100000 x %struct.vertex], ptr @V, i64 0, i64 %9
  %11 = getelementptr inbounds %struct.vertex, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !9
  store i32 %12, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %45, %6
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %51

17:                                               ; preds = %13
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100000 x %struct.edge], ptr @E, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.edge, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !12
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100000 x %struct.vertex], ptr @V, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.vertex, ptr %24, i32 0, i32 1
  %26 = load i8, ptr %25, align 4, !tbaa !14, !range !15, !noundef !16
  %27 = trunc i8 %26 to i1
  %28 = zext i1 %27 to i32
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %44

30:                                               ; preds = %17
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100000 x %struct.edge], ptr @E, i64 0, i64 %32
  %34 = getelementptr inbounds %struct.edge, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !12
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100000 x %struct.vertex], ptr @V, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.vertex, ptr %37, i32 0, i32 1
  store i8 1, ptr %38, align 4, !tbaa !14
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100000 x %struct.edge], ptr @E, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.edge, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !12
  call void @_Z7enqueuei(i32 noundef %43)
  br label %44

44:                                               ; preds = %30, %17
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100000 x %struct.edge], ptr @E, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.edge, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !17
  store i32 %50, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !18

51:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %3, !llvm.loop !20

52:                                               ; preds = %3
  ret void
}

; 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 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 #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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS6vertex", !6, i64 0, !11, i64 4}
!11 = !{!"bool", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4}
!14 = !{!10, !11, i64 4}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!13, !6, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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.vertex = type { i32, i8 }
%struct.edge = type { i32, i32 }

@V = external dso_local local_unnamed_addr global [100000 x %struct.vertex], align 16
@E = external dso_local local_unnamed_addr global [100000 x %struct.edge], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7enqueuei(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7dequeuev() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z11queue_emptyv() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3BFSv() local_unnamed_addr #0 {
  %1 = tail call noundef zeroext i1 @_Z11queue_emptyv()
  br i1 %1, label %._crit_edge, label %.lr.ph9

.loopexit:                                        ; preds = %14, %.lr.ph9
  %2 = tail call noundef zeroext i1 @_Z11queue_emptyv()
  br i1 %2, label %._crit_edge, label %.lr.ph9, !llvm.loop !5

.lr.ph9:                                          ; preds = %0, %.loopexit
  %3 = tail call noundef i32 @_Z7dequeuev()
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [100000 x %struct.vertex], ptr @V, i64 0, i64 %4
  %.06 = load i32, ptr %5, align 8, !tbaa !7
  %.not7 = icmp eq i32 %.06, 0
  br i1 %.not7, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph9, %14
  %.08 = phi i32 [ %.0, %14 ], [ %.06, %.lr.ph9 ]
  %6 = sext i32 %.08 to i64
  %7 = getelementptr inbounds [100000 x %struct.edge], ptr @E, i64 0, i64 %6
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [100000 x %struct.vertex], ptr @V, i64 0, i64 %9, i32 1
  %11 = load i8, ptr %10, align 4, !tbaa !13, !range !16, !noundef !17
  %12 = icmp eq i8 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %.lr.ph
  store i8 1, ptr %10, align 4, !tbaa !13
  tail call void @_Z7enqueuei(i32 noundef %8)
  br label %14

14:                                               ; preds = %.lr.ph, %13
  %15 = getelementptr inbounds i8, ptr %7, i64 4
  %.0 = load i32, ptr %15, align 4, !tbaa !7
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %.loopexit, %0
  ret void
}

attributes #0 = { 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !8, i64 0}
!12 = !{!"_ZTS4edge", !8, i64 0, !8, i64 4}
!13 = !{!14, !15, i64 4}
!14 = !{!"_ZTS6vertex", !8, i64 0, !15, i64 4}
!15 = !{!"bool", !9, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass