; LLVM IR from upupming/algorithm :: acwing/算法基础课/第三讲 搜索与图论/Dijkstra/849. Dijkstra求最短路 I.ll (Z8dijkstrav)

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

@n = external dso_local global i32, align 4
@a = external dso_local global [510 x [510 x i32]], align 16
@d = external dso_local global [510 x i32], align 16
@v = external dso_local global [510 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8dijkstrav() #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
  %6 = alloca i32, align 4
  call void @llvm.memset.p0.i64(ptr align 16 @d, i8 63, i64 2040, i1 false)
  store i32 0, ptr getelementptr inbounds ([510 x i32], ptr @d, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %77, %0
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  br label %80

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %40, %12
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %43

18:                                               ; preds = %13
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [510 x i8], ptr @v, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !9, !range !11, !noundef !12
  %23 = trunc i8 %22 to i1
  br i1 %23, label %39, label %24

24:                                               ; preds = %18
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %37, label %27

27:                                               ; preds = %24
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [510 x i32], ptr @d, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [510 x i32], ptr @d, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp slt i32 %31, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %27, %24
  %38 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %38, ptr %3, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %37, %27, %18
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %4, align 4, !tbaa !5
  br label %13, !llvm.loop !13

43:                                               ; preds = %17
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [510 x i8], ptr @v, i64 0, i64 %45
  store i8 1, ptr %46, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %73, %43
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = load i32, ptr @n, align 4, !tbaa !5
  %50 = icmp sle i32 %48, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %47
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %76

52:                                               ; preds = %47
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [510 x i32], ptr @d, i64 0, i64 %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [510 x i32], ptr @d, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [510 x [510 x i32]], ptr @a, i64 0, i64 %61
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [510 x i32], ptr %62, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = add nsw i32 %59, %66
  store i32 %67, ptr %6, align 4, !tbaa !5
  %68 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %55, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [510 x i32], ptr @d, i64 0, i64 %71
  store i32 %69, ptr %72, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %73

73:                                               ; preds = %52
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %5, align 4, !tbaa !5
  br label %47, !llvm.loop !15

76:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %1, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %1, align 4, !tbaa !5
  br label %7, !llvm.loop !16

80:                                               ; preds = %11
  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: 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

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 = { inlinehint 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}
!16 = distinct !{!16, !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"

@n = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [510 x [510 x i32]], align 16
@d = external dso_local global [510 x i32], align 16
@v = external dso_local local_unnamed_addr global [510 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8dijkstrav() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2040) @d, i8 63, i64 2040, i1 false)
  store i32 0, ptr getelementptr inbounds (i8, ptr @d, i64 4), align 4, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 1
  br i1 %3, label %.preheader, label %._crit_edge30

.preheader:                                       ; preds = %0, %._crit_edge28
  %4 = phi i32 [ %53, %._crit_edge28 ], [ %2, %0 ]
  %.01929 = phi i32 [ %54, %._crit_edge28 ], [ 1, %0 ]
  %.not21 = icmp slt i32 %4, 1
  br i1 %.not21, label %._crit_edge.thread, label %.lr.ph.preheader

._crit_edge.thread:                               ; preds = %.preheader
  store i8 1, ptr @v, align 16, !tbaa !9
  br label %._crit_edge28

.lr.ph.preheader:                                 ; preds = %.preheader
  %5 = zext nneg i32 %4 to i64
  %xtraiter = and i64 %5, 1
  %6 = icmp eq i32 %4, 1
  br i1 %6, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %5, 2147483646
  br label %.lr.ph

._crit_edge30:                                    ; preds = %._crit_edge28, %0
  ret void

._crit_edge.unr-lcssa:                            ; preds = %52, %.lr.ph.preheader
  %.1.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %.1.1, %52 ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.1, %52 ]
  %.01822.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %.1.1, %52 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa
  %7 = getelementptr inbounds [510 x i8], ptr @v, i64 0, i64 %indvars.iv.unr
  %8 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %._crit_edge, label %10

10:                                               ; preds = %.lr.ph.epil
  %11 = icmp eq i32 %.01822.unr, 0
  br i1 %11, label %19, label %12

12:                                               ; preds = %10
  %13 = getelementptr inbounds [510 x i32], ptr @d, i64 0, i64 %indvars.iv.unr
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = sext i32 %.01822.unr to i64
  %16 = getelementptr inbounds [510 x i32], ptr @d, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp slt i32 %14, %17
  br i1 %18, label %19, label %._crit_edge

19:                                               ; preds = %12, %10
  %20 = trunc nuw nsw i64 %indvars.iv.unr to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %12, %19, %._crit_edge.unr-lcssa
  %.1.lcssa = phi i32 [ %.1.lcssa.ph, %._crit_edge.unr-lcssa ], [ %.01822.unr, %.lr.ph.epil ], [ %20, %19 ], [ %.01822.unr, %12 ]
  %21 = sext i32 %.1.lcssa to i64
  %22 = getelementptr inbounds [510 x i8], ptr @v, i64 0, i64 %21
  store i8 1, ptr %22, align 1, !tbaa !9
  br i1 %.not21, label %._crit_edge28, label %.lr.ph27

.lr.ph27:                                         ; preds = %._crit_edge
  %23 = getelementptr inbounds [510 x i32], ptr @d, i64 0, i64 %21
  br label %56

.lr.ph:                                           ; preds = %52, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %52 ]
  %.01822 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %.1.1, %52 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %52 ]
  %24 = getelementptr inbounds [510 x i8], ptr @v, i64 0, i64 %indvars.iv
  %25 = load i8, ptr %24, align 1, !tbaa !9, !range !11, !noundef !12
  %26 = trunc nuw i8 %25 to i1
  br i1 %26, label %.lr.ph.1, label %27

27:                                               ; preds = %.lr.ph
  %28 = icmp eq i32 %.01822, 0
  br i1 %28, label %36, label %29

29:                                               ; preds = %27
  %30 = getelementptr inbounds [510 x i32], ptr @d, i64 0, i64 %indvars.iv
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %.01822 to i64
  %33 = getelementptr inbounds [510 x i32], ptr @d, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = icmp slt i32 %31, %34
  br i1 %35, label %36, label %.lr.ph.1

36:                                               ; preds = %29, %27
  %37 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %29, %36
  %.1 = phi i32 [ %.01822, %.lr.ph ], [ %37, %36 ], [ %.01822, %29 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %38 = getelementptr inbounds [510 x i8], ptr @v, i64 0, i64 %indvars.iv.next
  %39 = load i8, ptr %38, align 1, !tbaa !9, !range !11, !noundef !12
  %40 = trunc nuw i8 %39 to i1
  br i1 %40, label %52, label %41

41:                                               ; preds = %.lr.ph.1
  %42 = icmp eq i32 %.1, 0
  br i1 %42, label %50, label %43

43:                                               ; preds = %41
  %44 = getelementptr inbounds [510 x i32], ptr @d, i64 0, i64 %indvars.iv.next
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = sext i32 %.1 to i64
  %47 = getelementptr inbounds [510 x i32], ptr @d, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = icmp slt i32 %45, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %43, %41
  %51 = trunc nuw nsw i64 %indvars.iv.next to i32
  br label %52

52:                                               ; preds = %50, %43, %.lr.ph.1
  %.1.1 = phi i32 [ %.1, %.lr.ph.1 ], [ %51, %50 ], [ %.1, %43 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !13

._crit_edge28:                                    ; preds = %56, %._crit_edge.thread, %._crit_edge
  %53 = phi i32 [ %4, %._crit_edge ], [ %4, %._crit_edge.thread ], [ %64, %56 ]
  %54 = add nuw nsw i32 %.01929, 1
  %55 = icmp slt i32 %54, %53
  br i1 %55, label %.preheader, label %._crit_edge30, !llvm.loop !15

56:                                               ; preds = %.lr.ph27, %56
  %indvars.iv32 = phi i64 [ 1, %.lr.ph27 ], [ %indvars.iv.next33, %56 ]
  %57 = getelementptr inbounds [510 x i32], ptr @d, i64 0, i64 %indvars.iv32
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %58 = load i32, ptr %23, align 4, !tbaa !5
  %59 = getelementptr inbounds [510 x [510 x i32]], ptr @a, i64 0, i64 %21, i64 %indvars.iv32
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = add nsw i32 %60, %58
  store i32 %61, ptr %1, align 4, !tbaa !5
  %62 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %57, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %63 = load i32, ptr %62, align 4, !tbaa !5
  store i32 %63, ptr %57, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %64 = load i32, ptr @n, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %.not20.not = icmp slt i64 %indvars.iv32, %65
  br i1 %.not20.not, label %56, label %._crit_edge28, !llvm.loop !16
}

; 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 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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}
!16 = distinct !{!16, !14}


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