; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p3275.ll (Z4spfaRi)

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

@e = external dso_local global [300010 x %struct.edge], align 16
@head = external dso_local global [100010 x i32], align 16
@dist = external dso_local global [100010 x i32], align 16
@vis = external dso_local global [100010 x i8], align 16
@cnt = external dso_local global [100010 x i32], align 16
@q = external dso_local global [100010 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z4spfaRi(ptr noundef nonnull align 4 dereferenceable(4) %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 16 @dist, i8 -63, i64 400040, i1 false)
  store i32 0, ptr @dist, align 16, !tbaa !9
  store i32 0, ptr @q, align 16, !tbaa !9
  store i8 1, ptr @vis, align 16, !tbaa !11
  br label %10

10:                                               ; preds = %114, %1
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp ne i32 %11, %12
  br i1 %13, label %14, label %115

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr %5, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100010 x i32], ptr @q, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !9
  store i32 %19, ptr %6, align 4, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100010 x i8], ptr @vis, i64 0, i64 %21
  store i8 0, ptr %22, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !9
  store i32 %26, ptr %7, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %103, %14
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  store i32 4, ptr %8, align 4
  br label %109

31:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [300010 x %struct.edge], ptr @e, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.edge, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 4, !tbaa !13
  store i32 %36, ptr %9, align 4, !tbaa !9
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [100010 x i32], ptr @dist, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100010 x i32], ptr @dist, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [300010 x %struct.edge], ptr @e, i64 0, i64 %46
  %48 = getelementptr inbounds %struct.edge, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 4, !tbaa !15
  %50 = add nsw i32 %44, %49
  %51 = icmp slt i32 %40, %50
  br i1 %51, label %52, label %99

52:                                               ; preds = %31
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100010 x i32], ptr @dist, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [300010 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 !15
  %62 = add nsw i32 %56, %61
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [100010 x i32], ptr @dist, i64 0, i64 %64
  store i32 %62, ptr %65, align 4, !tbaa !9
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100010 x i32], ptr @cnt, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  %71 = load i32, ptr %9, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [100010 x i32], ptr @cnt, i64 0, i64 %72
  store i32 %70, ptr %73, align 4, !tbaa !9
  %74 = load i32, ptr %9, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [100010 x i32], ptr @cnt, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !9
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = load i32, ptr %78, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  %81 = icmp sge i32 %77, %80
  br i1 %81, label %82, label %83

82:                                               ; preds = %52
  store i1 false, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %100

83:                                               ; preds = %52
  %84 = load i32, ptr %9, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [100010 x i8], ptr @vis, i64 0, i64 %85
  %87 = load i8, ptr %86, align 1, !tbaa !11, !range !16, !noundef !17
  %88 = trunc i8 %87 to i1
  br i1 %88, label %98, label %89

89:                                               ; preds = %83
  %90 = load i32, ptr %9, align 4, !tbaa !9
  %91 = load i32, ptr %5, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %5, align 4, !tbaa !9
  %93 = sext i32 %91 to i64
  %94 = getelementptr inbounds [100010 x i32], ptr @q, i64 0, i64 %93
  store i32 %90, ptr %94, align 4, !tbaa !9
  %95 = load i32, ptr %9, align 4, !tbaa !9
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [100010 x i8], ptr @vis, i64 0, i64 %96
  store i8 1, ptr %97, align 1, !tbaa !11
  br label %98

98:                                               ; preds = %89, %83
  br label %99

99:                                               ; preds = %98, %31
  store i32 0, ptr %8, align 4
  br label %100

100:                                              ; preds = %99, %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %101 = load i32, ptr %8, align 4
  switch i32 %101, label %109 [
    i32 0, label %102
  ]

102:                                              ; preds = %100
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %7, align 4, !tbaa !9
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [300010 x %struct.edge], ptr @e, i64 0, i64 %105
  %107 = getelementptr inbounds %struct.edge, ptr %106, i32 0, i32 2
  %108 = load i32, ptr %107, align 4, !tbaa !18
  store i32 %108, ptr %7, align 4, !tbaa !9
  br label %27, !llvm.loop !19

109:                                              ; preds = %100, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %110 = load i32, ptr %8, align 4
  switch i32 %110, label %112 [
    i32 4, label %111
  ]

111:                                              ; preds = %109
  store i32 0, ptr %8, align 4
  br label %112

112:                                              ; preds = %111, %109
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %113 = load i32, ptr %8, align 4
  switch i32 %113, label %116 [
    i32 0, label %114
  ]

114:                                              ; preds = %112
  br label %10, !llvm.loop !21

115:                                              ; preds = %10
  store i1 true, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %116

116:                                              ; preds = %115, %112
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %117 = load i1, ptr %2, align 1
  ret i1 %117
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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


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

@e = external dso_local local_unnamed_addr global [300010 x %struct.edge], align 16
@head = external dso_local local_unnamed_addr global [100010 x i32], align 16
@dist = external dso_local local_unnamed_addr global [100010 x i32], align 16
@vis = external dso_local local_unnamed_addr global [100010 x i8], align 16
@cnt = external dso_local local_unnamed_addr global [100010 x i32], align 16
@q = external dso_local local_unnamed_addr global [100010 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z4spfaRi(ptr nocapture noundef nonnull readonly align 4 dereferenceable(4) %0) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(400040) @dist, i8 -63, i64 400040, i1 false)
  store i32 0, ptr @dist, align 16, !tbaa !5
  store i32 0, ptr @q, align 16, !tbaa !5
  store i8 1, ptr @vis, align 16, !tbaa !9
  br label %2

.loopexit:                                        ; preds = %37, %2
  %.131.lcssa = phi i32 [ %3, %2 ], [ %.333.ph, %37 ]
  %.not = icmp eq i32 %.131.lcssa, 0
  br i1 %.not, label %.thread41, label %2, !llvm.loop !11

2:                                                ; preds = %1, %.loopexit
  %.03051 = phi i32 [ 1, %1 ], [ %.131.lcssa, %.loopexit ]
  %3 = add nsw i32 %.03051, -1
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [100010 x i32], ptr @q, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [100010 x i8], ptr @vis, 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
  %.02947 = load i32, ptr %9, align 4, !tbaa !5
  %.not3648 = icmp eq i32 %.02947, 0
  br i1 %.not3648, label %.loopexit, label %.lr.ph

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

12:                                               ; preds = %.lr.ph, %37
  %.02950 = phi i32 [ %.02947, %.lr.ph ], [ %.029, %37 ]
  %.13149 = phi i32 [ %3, %.lr.ph ], [ %.333.ph, %37 ]
  %13 = sext i32 %.02950 to i64
  %14 = getelementptr inbounds [300010 x %struct.edge], ptr @e, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100010 x i32], ptr @dist, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = load i32, ptr %10, align 4, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %14, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !15
  %22 = add nsw i32 %21, %19
  %23 = icmp slt i32 %18, %22
  br i1 %23, label %24, label %37

24:                                               ; preds = %12
  store i32 %22, ptr %17, align 4, !tbaa !5
  %25 = load i32, ptr %11, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  %27 = getelementptr inbounds [100010 x i32], ptr @cnt, i64 0, i64 %16
  store i32 %26, ptr %27, align 4, !tbaa !5
  %28 = load i32, ptr %0, align 4, !tbaa !5
  %.not37 = icmp slt i32 %25, %28
  br i1 %.not37, label %29, label %.thread41

29:                                               ; preds = %24
  %30 = getelementptr inbounds [100010 x i8], ptr @vis, i64 0, i64 %16
  %31 = load i8, ptr %30, align 1, !tbaa !9, !range !16, !noundef !17
  %32 = trunc nuw i8 %31 to i1
  br i1 %32, label %37, label %33

33:                                               ; preds = %29
  %34 = add nsw i32 %.13149, 1
  %35 = sext i32 %.13149 to i64
  %36 = getelementptr inbounds [100010 x i32], ptr @q, i64 0, i64 %35
  store i32 %15, ptr %36, align 4, !tbaa !5
  store i8 1, ptr %30, align 1, !tbaa !9
  br label %37

37:                                               ; preds = %29, %33, %12
  %.333.ph = phi i32 [ %.13149, %12 ], [ %34, %33 ], [ %.13149, %29 ]
  %38 = getelementptr inbounds i8, ptr %14, i64 8
  %.029 = load i32, ptr %38, align 4, !tbaa !5
  %.not36 = icmp eq i32 %.029, 0
  br i1 %.not36, label %.loopexit, label %12, !llvm.loop !18

.thread41:                                        ; preds = %.loopexit, %24
  %.not46 = phi i1 [ false, %24 ], [ true, %.loopexit ]
  ret i1 %.not46
}

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


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