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

; 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
@pa = external dso_local global [110000 x i32], align 16
@value = external dso_local global [110000 x i32], align 16
@root2 = 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
declare dso_local void @_ZN7TreeSet6insertEiii(ptr noundef nonnull align 4 dereferenceable(198000012), i32 noundef, i32 noundef, i32 noundef) #2 align 2

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

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

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

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

39:                                               ; preds = %31
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [110000 x i32], ptr @vis, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %49, label %45

45:                                               ; preds = %39
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z4dfs3iii(i32 noundef %46, i32 noundef %47, i32 noundef %48)
  br label %49

49:                                               ; preds = %45, %39, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %50

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

55:                                               ; preds = %30
  ret void
}

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
@pa = 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
@root2 = 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
declare dso_local void @_ZN7TreeSet6insertEiii(ptr noundef nonnull align 4 dereferenceable(198000012), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4dfs3iii(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 @root2, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = getelementptr inbounds [110000 x i32], ptr @pa, i64 0, i64 %4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = tail call noundef i32 @_Z4distii(i32 noundef %0, i32 noundef %8)
  %10 = sext i32 %0 to i64
  %11 = getelementptr inbounds [110000 x i32], ptr @value, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  tail call void @_ZN7TreeSet6insertEiii(ptr noundef nonnull align 4 dereferenceable(198000012) @tree, i32 noundef %6, i32 noundef %9, i32 noundef %12)
  %13 = getelementptr inbounds [220000 x i32], ptr @head, i64 0, i64 %10
  %.017 = load i32, ptr %13, align 4, !tbaa !5
  %.not18 = icmp eq i32 %.017, 0
  br i1 %.not18, label %._crit_edge, label %.lr.ph

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

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

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

21:                                               ; preds = %17
  tail call void @_Z4dfs3iii(i32 noundef %16, i32 noundef %0, i32 noundef %2)
  br label %22

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

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