; LLVM IR from upupming/algorithm :: acwing/算法基础课/第三讲 搜索与图论/SPFA/851. spfa求最短路.ll (Z4spfav)

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

%"class.std::queue" = type { %"class.std::deque" }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl" }
%"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl" = type { %"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl_data" }
%"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, ptr }

@head = external dso_local global [100010 x i32], align 16
@ver = external dso_local global [100010 x i32], align 16
@edge = external dso_local global [100010 x i32], align 16
@Next = external dso_local global [100010 x i32], align 16
@d = external dso_local global [100010 x i32], align 16
@v = external dso_local global [100010 x i8], align 16
@q = external dso_local global %"class.std::queue", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4spfav() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.memset.p0.i64(ptr align 16 @d, i8 63, i64 400040, i1 false)
  store i32 0, ptr getelementptr inbounds ([100010 x i32], ptr @d, i64 0, i64 1), align 4, !tbaa !5
  store i8 1, ptr getelementptr inbounds ([100010 x i8], ptr @v, i64 0, i64 1), align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 1, ptr %1, align 4, !tbaa !5
  call void @_ZNSt5queueIiSt5dequeIiSaIiEEE4pushEOi(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(4) %1)
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  br label %6

6:                                                ; preds = %69, %0
  %7 = call noundef i64 @_ZNKSt5queueIiSt5dequeIiSaIiEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  %8 = icmp ne i64 %7, 0
  br i1 %8, label %9, label %70

9:                                                ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %10 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5queueIiSt5dequeIiSaIiEEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  %11 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %11, ptr %2, align 4, !tbaa !5
  call void @_ZNSt5queueIiSt5dequeIiSaIiEEE3popEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100010 x i8], ptr @v, i64 0, i64 %13
  store i8 0, ptr %14, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  store i32 %18, ptr %3, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %64, %9
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %69

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [100010 x i32], ptr @ver, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  store i32 %27, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100010 x i32], ptr @edge, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  store i32 %31, ptr %5, align 4, !tbaa !5
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [100010 x i32], ptr @d, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100010 x i32], ptr @d, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = add nsw i32 %39, %40
  %42 = icmp sgt i32 %35, %41
  br i1 %42, label %43, label %63

43:                                               ; preds = %23
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100010 x i32], ptr @d, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = add nsw i32 %47, %48
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100010 x i32], ptr @d, i64 0, i64 %51
  store i32 %49, ptr %52, align 4, !tbaa !5
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100010 x i8], ptr @v, i64 0, i64 %54
  %56 = load i8, ptr %55, align 1, !tbaa !9, !range !11, !noundef !12
  %57 = trunc i8 %56 to i1
  br i1 %57, label %62, label %58

58:                                               ; preds = %43
  call void @_ZNSt5queueIiSt5dequeIiSaIiEEE4pushERKi(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100010 x i8], ptr @v, i64 0, i64 %60
  store i8 1, ptr %61, align 1, !tbaa !9
  br label %62

62:                                               ; preds = %58, %43
  br label %63

63:                                               ; preds = %62, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [100010 x i32], ptr @Next, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  store i32 %68, ptr %3, align 4, !tbaa !5
  br label %19, !llvm.loop !13

69:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %6, !llvm.loop !15

70:                                               ; preds = %6
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5queueIiSt5dequeIiSaIiEEE4pushEOi(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 4 dereferenceable(4)) #0 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt5queueIiSt5dequeIiSaIiEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(80)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5queueIiSt5dequeIiSaIiEEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt5queueIiSt5dequeIiSaIiEEE3popEv(ptr noundef nonnull align 8 dereferenceable(80)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5queueIiSt5dequeIiSaIiEEE4pushERKi(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 4 dereferenceable(4)) #0 align 2

attributes #0 = { 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 #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!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"

%"class.std::queue" = type { %"class.std::deque" }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl" }
%"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl" = type { %"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl_data" }
%"struct.std::_Deque_base<int, std::allocator<int>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, ptr }

@head = external dso_local local_unnamed_addr global [100010 x i32], align 16
@ver = external dso_local local_unnamed_addr global [100010 x i32], align 16
@edge = external dso_local local_unnamed_addr global [100010 x i32], align 16
@Next = external dso_local local_unnamed_addr global [100010 x i32], align 16
@d = external dso_local local_unnamed_addr global [100010 x i32], align 16
@v = external dso_local local_unnamed_addr global [100010 x i8], align 16
@q = external dso_local global %"class.std::queue", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4spfav() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(400040) @d, i8 63, i64 400040, i1 false)
  store i32 0, ptr getelementptr inbounds (i8, ptr @d, i64 4), align 4, !tbaa !5
  store i8 1, ptr getelementptr inbounds (i8, ptr @v, i64 1), align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  store i32 1, ptr %1, align 4, !tbaa !5
  call void @_ZNSt5queueIiSt5dequeIiSaIiEEE4pushEOi(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(4) %1)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %3 = call noundef i64 @_ZNKSt5queueIiSt5dequeIiSaIiEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  %.not15 = icmp eq i64 %3, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph16

.loopexit:                                        ; preds = %31, %.lr.ph16
  %4 = call noundef i64 @_ZNKSt5queueIiSt5dequeIiSaIiEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph16, !llvm.loop !11

.lr.ph16:                                         ; preds = %0, %.loopexit
  %5 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5queueIiSt5dequeIiSaIiEEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  %6 = load i32, ptr %5, align 4, !tbaa !5
  call void @_ZNSt5queueIiSt5dequeIiSaIiEEE3popEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [100010 x i8], ptr @v, i64 0, i64 %7
  store i8 0, ptr %8, align 1, !tbaa !9
  %9 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %7
  %.012 = load i32, ptr %9, align 4, !tbaa !5
  %.not1113 = icmp eq i32 %.012, 0
  br i1 %.not1113, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph16
  %10 = getelementptr inbounds [100010 x i32], ptr @d, i64 0, i64 %7
  br label %11

11:                                               ; preds = %.lr.ph, %31
  %.014 = phi i32 [ %.012, %.lr.ph ], [ %.0, %31 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %12 = sext i32 %.014 to i64
  %13 = getelementptr inbounds [100010 x i32], ptr @ver, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %14, ptr %2, align 4, !tbaa !5
  %15 = getelementptr inbounds [100010 x i32], ptr @edge, i64 0, i64 %12
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = sext i32 %14 to i64
  %18 = getelementptr inbounds [100010 x i32], ptr @d, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = load i32, ptr %10, align 4, !tbaa !5
  %21 = add nsw i32 %20, %16
  %22 = icmp sgt i32 %19, %21
  br i1 %22, label %23, label %31

23:                                               ; preds = %11
  store i32 %21, ptr %18, align 4, !tbaa !5
  %24 = getelementptr inbounds [100010 x i8], ptr @v, i64 0, i64 %17
  %25 = load i8, ptr %24, align 1, !tbaa !9, !range !13, !noundef !14
  %26 = trunc nuw i8 %25 to i1
  br i1 %26, label %31, label %27

27:                                               ; preds = %23
  call void @_ZNSt5queueIiSt5dequeIiSaIiEEE4pushERKi(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100010 x i8], ptr @v, i64 0, i64 %29
  store i8 1, ptr %30, align 1, !tbaa !9
  br label %31

31:                                               ; preds = %23, %27, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  %32 = getelementptr inbounds [100010 x i32], ptr @Next, i64 0, i64 %12
  %.0 = load i32, ptr %32, align 4, !tbaa !5
  %.not11 = icmp eq i32 %.0, 0
  br i1 %.not11, label %.loopexit, label %11, !llvm.loop !15

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5queueIiSt5dequeIiSaIiEEE4pushEOi(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt5queueIiSt5dequeIiSaIiEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5queueIiSt5dequeIiSaIiEEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt5queueIiSt5dequeIiSaIiEEE3popEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5queueIiSt5dequeIiSaIiEEE4pushERKi(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

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


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