; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/图论/最小生成树.ll (Z7kruskalv)

; 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.anon = type { i8 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@from = external dso_local global [210000 x i32], align 16
@to = external dso_local global [210000 x i32], align 16
@weight = external dso_local global [210000 x i32], align 16
@p = external dso_local global [210000 x i32], align 16
@r = external dso_local global [210000 x i32], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7kruskalv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca %class.anon, align 1
  %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
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %12

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

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

17:                                               ; preds = %12
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [210000 x i32], ptr @p, i64 0, i64 %20
  store i32 %18, ptr %21, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %17
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !9

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

26:                                               ; preds = %36, %25
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr @m, align 4, !tbaa !5
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %31, label %30

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

31:                                               ; preds = %26
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [210000 x i32], ptr @r, i64 0, i64 %34
  store i32 %32, ptr %35, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %31
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %3, align 4, !tbaa !5
  br label %26, !llvm.loop !11

39:                                               ; preds = %30
  %40 = load i32, ptr @m, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr @r, i64 %41
  %43 = getelementptr inbounds i32, ptr %42, i64 1
  call void @"_ZSt4sortIPiZ7kruskalvE3$_0EvT_S2_T0_"(ptr noundef getelementptr inbounds (i32, ptr @r, i64 1), ptr noundef %43)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %81, %39
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = load i32, ptr @m, align 4, !tbaa !5
  %47 = icmp sle i32 %45, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %84

49:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [210000 x i32], ptr @r, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  store i32 %53, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [210000 x i32], ptr @from, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = call noundef i32 @_Z4findi(i32 noundef %57)
  store i32 %58, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [210000 x i32], ptr @to, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = call noundef i32 @_Z4findi(i32 noundef %62)
  store i32 %63, ptr %10, align 4, !tbaa !5
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = icmp ne i32 %64, %65
  br i1 %66, label %67, label %80

67:                                               ; preds = %49
  %68 = load i32, ptr %10, align 4, !tbaa !5
  %69 = load i32, ptr %9, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [210000 x i32], ptr @p, i64 0, i64 %70
  store i32 %68, ptr %71, align 4, !tbaa !5
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [210000 x i32], ptr @weight, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = add nsw i32 %76, %75
  store i32 %77, ptr %5, align 4, !tbaa !5
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %6, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %67, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %7, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %7, align 4, !tbaa !5
  br label %44, !llvm.loop !12

84:                                               ; preds = %48
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = load i32, ptr @n, align 4, !tbaa !5
  %87 = sub nsw i32 %86, 1
  %88 = icmp ne i32 %85, %87
  br i1 %88, label %89, label %90

89:                                               ; preds = %84
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %11, align 4
  br label %92

90:                                               ; preds = %84
  %91 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %91, ptr %1, align 4
  store i32 1, ptr %11, align 4
  br label %92

92:                                               ; preds = %90, %89
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %93 = load i32, ptr %1, align 4
  ret i32 %93
}

; 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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @"_ZSt4sortIPiZ7kruskalvE3$_0EvT_S2_T0_"(ptr noundef, ptr noundef) #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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; 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
@m = external dso_local local_unnamed_addr global i32, align 4
@from = external dso_local local_unnamed_addr global [210000 x i32], align 16
@to = external dso_local local_unnamed_addr global [210000 x i32], align 16
@weight = external dso_local local_unnamed_addr global [210000 x i32], align 16
@p = external dso_local local_unnamed_addr global [210000 x i32], align 16
@r = external dso_local global [210000 x i32], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7kruskalv() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %.not36 = icmp slt i32 %1, 1
  br i1 %.not36, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %2 = add nuw i32 %1, 1
  %wide.trip.count = zext i32 %2 to i64
  %3 = zext nneg i32 %1 to i64
  %min.iters.check = icmp ult i32 %1, 8
  br i1 %min.iters.check, label %.lr.ph.preheader78, label %vector.ph

.lr.ph.preheader78:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %3, 2147483640
  %ind.end = or disjoint i64 %n.vec, 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %offset.idx = or disjoint i64 %index, 1
  %4 = getelementptr inbounds [210000 x i32], ptr @p, i64 0, i64 %offset.idx
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  store <4 x i32> %vec.ind, ptr %4, align 4, !tbaa !5
  store <4 x i32> %step.add, ptr %5, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %6 = icmp eq i64 %index.next, %n.vec
  br i1 %6, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %3
  br i1 %cmp.n, label %.preheader, label %.lr.ph.preheader78

.preheader:                                       ; preds = %.lr.ph, %middle.block, %0
  %7 = load i32, ptr @m, align 4, !tbaa !5
  %.not3238 = icmp slt i32 %7, 1
  br i1 %.not3238, label %._crit_edge, label %.lr.ph40.preheader

.lr.ph40.preheader:                               ; preds = %.preheader
  %8 = add nuw i32 %7, 1
  %wide.trip.count54 = zext i32 %8 to i64
  %9 = zext nneg i32 %7 to i64
  %min.iters.check62 = icmp ult i32 %7, 8
  br i1 %min.iters.check62, label %.lr.ph40.preheader77, label %vector.ph63

.lr.ph40.preheader77:                             ; preds = %middle.block60, %.lr.ph40.preheader
  %indvars.iv51.ph = phi i64 [ 1, %.lr.ph40.preheader ], [ %ind.end66, %middle.block60 ]
  br label %.lr.ph40

vector.ph63:                                      ; preds = %.lr.ph40.preheader
  %n.vec65 = and i64 %9, 2147483640
  %ind.end66 = or disjoint i64 %n.vec65, 1
  br label %vector.body68

vector.body68:                                    ; preds = %vector.body68, %vector.ph63
  %index69 = phi i64 [ 0, %vector.ph63 ], [ %index.next75, %vector.body68 ]
  %vec.ind70 = phi <4 x i32> [ <i32 1, i32 2, i32 3, i32 4>, %vector.ph63 ], [ %vec.ind.next73, %vector.body68 ]
  %step.add71 = add <4 x i32> %vec.ind70, <i32 4, i32 4, i32 4, i32 4>
  %offset.idx74 = or disjoint i64 %index69, 1
  %10 = getelementptr inbounds [210000 x i32], ptr @r, i64 0, i64 %offset.idx74
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  store <4 x i32> %vec.ind70, ptr %10, align 4, !tbaa !5
  store <4 x i32> %step.add71, ptr %11, align 4, !tbaa !5
  %index.next75 = add nuw i64 %index69, 8
  %vec.ind.next73 = add <4 x i32> %vec.ind70, <i32 8, i32 8, i32 8, i32 8>
  %12 = icmp eq i64 %index.next75, %n.vec65
  br i1 %12, label %middle.block60, label %vector.body68, !llvm.loop !13

middle.block60:                                   ; preds = %vector.body68
  %cmp.n76 = icmp eq i64 %n.vec65, %9
  br i1 %cmp.n76, label %._crit_edge, label %.lr.ph40.preheader77

.lr.ph:                                           ; preds = %.lr.ph.preheader78, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader78 ]
  %13 = getelementptr inbounds [210000 x i32], ptr @p, i64 0, i64 %indvars.iv
  %14 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %14, ptr %13, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph40, %middle.block60, %.preheader
  %15 = sext i32 %7 to i64
  %16 = getelementptr inbounds i32, ptr @r, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 4
  tail call void @"_ZSt4sortIPiZ7kruskalvE3$_0EvT_S2_T0_"(ptr noundef nonnull getelementptr inbounds (i8, ptr @r, i64 4), ptr noundef nonnull %17)
  %18 = load i32, ptr @m, align 4, !tbaa !5
  %.not3341 = icmp slt i32 %18, 1
  br i1 %.not3341, label %._crit_edge47, label %.lr.ph46

.lr.ph40:                                         ; preds = %.lr.ph40.preheader77, %.lr.ph40
  %indvars.iv51 = phi i64 [ %indvars.iv.next52, %.lr.ph40 ], [ %indvars.iv51.ph, %.lr.ph40.preheader77 ]
  %19 = getelementptr inbounds [210000 x i32], ptr @r, i64 0, i64 %indvars.iv51
  %20 = trunc nuw nsw i64 %indvars.iv51 to i32
  store i32 %20, ptr %19, align 4, !tbaa !5
  %indvars.iv.next52 = add nuw nsw i64 %indvars.iv51, 1
  %exitcond55.not = icmp eq i64 %indvars.iv.next52, %wide.trip.count54
  br i1 %exitcond55.not, label %._crit_edge, label %.lr.ph40, !llvm.loop !15

._crit_edge47:                                    ; preds = %39, %._crit_edge
  %.027.lcssa = phi i32 [ 0, %._crit_edge ], [ %.128, %39 ]
  %.026.lcssa = phi i32 [ 0, %._crit_edge ], [ %.1, %39 ]
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = add nsw i32 %21, -1
  %.not34 = icmp eq i32 %.026.lcssa, %22
  %.027. = select i1 %.not34, i32 %.027.lcssa, i32 -1
  ret i32 %.027.

.lr.ph46:                                         ; preds = %._crit_edge, %39
  %indvars.iv56 = phi i64 [ %indvars.iv.next57, %39 ], [ 1, %._crit_edge ]
  %.02643 = phi i32 [ %.1, %39 ], [ 0, %._crit_edge ]
  %.02742 = phi i32 [ %.128, %39 ], [ 0, %._crit_edge ]
  %23 = getelementptr inbounds [210000 x i32], ptr @r, i64 0, i64 %indvars.iv56
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [210000 x i32], ptr @from, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = tail call noundef i32 @_Z4findi(i32 noundef %27)
  %29 = getelementptr inbounds [210000 x i32], ptr @to, i64 0, i64 %25
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = tail call noundef i32 @_Z4findi(i32 noundef %30)
  %.not35 = icmp eq i32 %28, %31
  br i1 %.not35, label %39, label %32

32:                                               ; preds = %.lr.ph46
  %33 = sext i32 %28 to i64
  %34 = getelementptr inbounds [210000 x i32], ptr @p, i64 0, i64 %33
  store i32 %31, ptr %34, align 4, !tbaa !5
  %35 = getelementptr inbounds [210000 x i32], ptr @weight, i64 0, i64 %25
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = add nsw i32 %36, %.02742
  %38 = add nsw i32 %.02643, 1
  br label %39

39:                                               ; preds = %32, %.lr.ph46
  %.128 = phi i32 [ %37, %32 ], [ %.02742, %.lr.ph46 ]
  %.1 = phi i32 [ %38, %32 ], [ %.02643, %.lr.ph46 ]
  %indvars.iv.next57 = add nuw nsw i64 %indvars.iv56, 1
  %40 = load i32, ptr @m, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %.not33.not = icmp slt i64 %indvars.iv56, %41
  br i1 %.not33.not, label %.lr.ph46, label %._crit_edge47, !llvm.loop !16
}

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @"_ZSt4sortIPiZ7kruskalvE3$_0EvT_S2_T0_"(ptr noundef, ptr noundef) local_unnamed_addr #1

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 = { inlinehint 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" }

!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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !11, !12}
!14 = distinct !{!14, !10, !12, !11}
!15 = distinct !{!15, !10, !12, !11}
!16 = distinct !{!16, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass