; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/树算法/快速求树中与结点x距离不超过k的点权和.ll (Z4dfs2iii)

; 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.TreeSet = type { [16500000 x %"struct.TreeSet::node"], i32, i32, i32 }
%"struct.TreeSet::node" = type { i32, i32, i32 }

@head = external dso_local global [220000 x i32], align 16
@nxt = external dso_local global [220000 x i32], align 16
@to = external dso_local global [220000 x i32], align 16
@vis = external dso_local global [110000 x i32], align 16
@value = external dso_local global [110000 x i32], align 16
@root = external dso_local global [110000 x i32], align 16
@tree = external dso_local global %struct.TreeSet, align 4

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4distii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4dfs2iii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %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
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr %6, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [110000 x i32], ptr @root, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = call noundef i32 @_Z4distii(i32 noundef %13, i32 noundef %14)
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [110000 x i32], ptr @value, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  call void @_ZN7TreeSet6insertEiii(ptr noundef nonnull align 4 dereferenceable(198000012) @tree, i32 noundef %12, i32 noundef %15, i32 noundef %19)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [220000 x i32], ptr @head, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  store i32 %23, ptr %7, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %47, %3
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [220000 x i32], ptr @to, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  store i32 %32, ptr %8, align 4, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = icmp ne i32 %33, %34
  br i1 %35, label %36, label %46

36:                                               ; preds = %28
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [110000 x i32], ptr @vis, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %46, label %42

42:                                               ; preds = %36
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z4dfs2iii(i32 noundef %43, i32 noundef %44, i32 noundef %45)
  br label %46

46:                                               ; preds = %42, %36, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [220000 x i32], ptr @nxt, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  store i32 %51, ptr %7, align 4, !tbaa !5
  br label %24, !llvm.loop !9

52:                                               ; preds = %27
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7TreeSet6insertEiii(ptr noundef nonnull align 4 dereferenceable(198000012), i32 noundef, i32 noundef, i32 noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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"}


; 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.TreeSet = type { [16500000 x %"struct.TreeSet::node"], i32, i32, i32 }
%"struct.TreeSet::node" = type { i32, i32, i32 }

@head = external dso_local local_unnamed_addr global [220000 x i32], align 16
@nxt = external dso_local local_unnamed_addr global [220000 x i32], align 16
@to = external dso_local local_unnamed_addr global [220000 x i32], align 16
@vis = external dso_local local_unnamed_addr global [110000 x i32], align 16
@value = external dso_local local_unnamed_addr global [110000 x i32], align 16
@root = external dso_local local_unnamed_addr global [110000 x i32], align 16
@tree = external dso_local global %struct.TreeSet, align 4

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4dfs2iii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = sext i32 %2 to i64
  %5 = getelementptr inbounds [110000 x i32], ptr @root, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = tail call noundef i32 @_Z4distii(i32 noundef %0, i32 noundef %2)
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds [110000 x i32], ptr @value, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  tail call void @_ZN7TreeSet6insertEiii(ptr noundef nonnull align 4 dereferenceable(198000012) @tree, i32 noundef %6, i32 noundef %7, i32 noundef %10)
  %11 = getelementptr inbounds [220000 x i32], ptr @head, i64 0, i64 %8
  %.017 = load i32, ptr %11, align 4, !tbaa !5
  %.not18 = icmp eq i32 %.017, 0
  br i1 %.not18, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %20, %3
  ret void

.lr.ph:                                           ; preds = %3, %20
  %.019 = phi i32 [ %.0, %20 ], [ %.017, %3 ]
  %12 = sext i32 %.019 to i64
  %13 = getelementptr inbounds [220000 x i32], ptr @to, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %.not15 = icmp eq i32 %14, %1
  br i1 %.not15, label %20, label %15

15:                                               ; preds = %.lr.ph
  %16 = sext i32 %14 to i64
  %17 = getelementptr inbounds [110000 x i32], ptr @vis, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %.not16 = icmp eq i32 %18, 0
  br i1 %.not16, label %19, label %20

19:                                               ; preds = %15
  tail call void @_Z4dfs2iii(i32 noundef %14, i32 noundef %0, i32 noundef %2)
  br label %20

20:                                               ; preds = %19, %15, %.lr.ph
  %21 = getelementptr inbounds [220000 x i32], ptr @nxt, i64 0, i64 %12
  %.0 = load i32, ptr %21, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7TreeSet6insertEiii(ptr noundef nonnull align 4 dereferenceable(198000012), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

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 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}
!10 = !{!"llvm.loop.mustprogress"}


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