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

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

@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
@pos = external dso_local global i32, align 4
@sz = external dso_local global i32, 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 uwtable
declare dso_local noundef i32 @_Z4dfs0ii(i32 noundef, i32 noundef) #1

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %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 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
  store i32 1073741824, ptr @sz, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = call noundef i32 @_Z4dfs1iii(i32 noundef %10, i32 noundef -1, i32 noundef %11)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %13 = load i32, ptr @pos, align 4, !tbaa !5
  store i32 %13, ptr %7, align 4, !tbaa !5
  %14 = load i32, ptr %7, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [110000 x i32], ptr @vis, i64 0, i64 %15
  store i32 1, ptr %16, align 4, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [110000 x i32], ptr @pa, i64 0, i64 %19
  store i32 %17, ptr %20, align 4, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z4dfs2iii(i32 noundef %21, i32 noundef -1, i32 noundef %22)
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %3
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z4dfs3iii(i32 noundef %26, i32 noundef -1, i32 noundef %27)
  br label %28

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

33:                                               ; preds = %53, %28
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %58

37:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [220000 x i32], ptr @to, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  store i32 %41, ptr %9, align 4, !tbaa !5
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [110000 x i32], ptr @vis, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %52, label %47

47:                                               ; preds = %37
  %48 = load i32, ptr %9, align 4, !tbaa !5
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = call noundef i32 @_Z4dfs0ii(i32 noundef %49, i32 noundef -1)
  %51 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z5buildiii(i32 noundef %48, i32 noundef %50, i32 noundef %51)
  br label %52

52:                                               ; preds = %47, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [220000 x i32], ptr @nxt, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  store i32 %57, ptr %8, align 4, !tbaa !5
  br label %33, !llvm.loop !9

58:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

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

@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
@pos = external dso_local local_unnamed_addr global i32, align 4
@sz = external dso_local local_unnamed_addr global i32, align 4

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  store i32 1073741824, ptr @sz, align 4, !tbaa !5
  %4 = tail call noundef i32 @_Z4dfs1iii(i32 noundef %0, i32 noundef -1, i32 noundef %1)
  %5 = load i32, ptr @pos, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [110000 x i32], ptr @vis, i64 0, i64 %6
  store i32 1, ptr %7, align 4, !tbaa !5
  %8 = getelementptr inbounds [110000 x i32], ptr @pa, i64 0, i64 %6
  store i32 %2, ptr %8, align 4, !tbaa !5
  tail call void @_Z4dfs2iii(i32 noundef %5, i32 noundef -1, i32 noundef %5)
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %10, label %9

9:                                                ; preds = %3
  tail call void @_Z4dfs3iii(i32 noundef %5, i32 noundef -1, i32 noundef %5)
  br label %10

10:                                               ; preds = %9, %3
  %11 = getelementptr inbounds [220000 x i32], ptr @head, i64 0, i64 %6
  %.020 = load i32, ptr %11, align 4, !tbaa !5
  %.not1821 = icmp eq i32 %.020, 0
  br i1 %.not1821, label %._crit_edge, label %.lr.ph

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

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

18:                                               ; preds = %.lr.ph
  %19 = tail call noundef i32 @_Z4dfs0ii(i32 noundef %14, i32 noundef -1)
  tail call void @_Z5buildiii(i32 noundef %14, i32 noundef %19, i32 noundef %5)
  br label %20

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

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

!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