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

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

@pa = external dso_local global [110000 x i32], align 16
@root = 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 @_Z6updateii(i32 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [110000 x i32], ptr @root, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !5
  call void @_ZN7TreeSet6insertEiii(ptr noundef nonnull align 4 dereferenceable(198000012) @tree, i32 noundef %10, i32 noundef 0, i32 noundef %11)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %12 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %12, ptr %5, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %42, %2
  %14 = load i32, ptr %5, 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 = icmp ne i32 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %47

20:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [110000 x i32], ptr @pa, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = call noundef i32 @_Z4distii(i32 noundef %24, i32 noundef %25)
  store i32 %26, ptr %6, align 4, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [110000 x i32], ptr @pa, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [110000 x i32], ptr @root, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  call void @_ZN7TreeSet6insertEiii(ptr noundef nonnull align 4 dereferenceable(198000012) @tree, i32 noundef %33, i32 noundef %34, i32 noundef %35)
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [110000 x i32], ptr @root2, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = load i32, ptr %4, align 4, !tbaa !5
  call void @_ZN7TreeSet6insertEiii(ptr noundef nonnull align 4 dereferenceable(198000012) @tree, i32 noundef %39, i32 noundef %40, i32 noundef %41)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %42

42:                                               ; preds = %20
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [110000 x i32], ptr @pa, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  store i32 %46, ptr %5, align 4, !tbaa !5
  br label %13, !llvm.loop !9

47:                                               ; preds = %19
  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 }

@pa = 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
@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 @_Z6updateii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [110000 x i32], ptr @root, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  tail call void @_ZN7TreeSet6insertEiii(ptr noundef nonnull align 4 dereferenceable(198000012) @tree, i32 noundef %5, i32 noundef 0, i32 noundef %1)
  %6 = getelementptr inbounds [110000 x i32], ptr @pa, i64 0, i64 %3
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not14 = icmp eq i32 %7, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %2
  ret void

.lr.ph:                                           ; preds = %2, %.lr.ph
  %8 = phi i32 [ %21, %.lr.ph ], [ %7, %2 ]
  %9 = phi ptr [ %20, %.lr.ph ], [ %6, %2 ]
  %10 = phi i64 [ %19, %.lr.ph ], [ %3, %2 ]
  %11 = tail call noundef i32 @_Z4distii(i32 noundef %8, i32 noundef %0)
  %12 = load i32, ptr %9, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [110000 x i32], ptr @root, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  tail call void @_ZN7TreeSet6insertEiii(ptr noundef nonnull align 4 dereferenceable(198000012) @tree, i32 noundef %15, i32 noundef %11, i32 noundef %1)
  %16 = getelementptr inbounds [110000 x i32], ptr @root2, i64 0, i64 %10
  %17 = load i32, ptr %16, align 4, !tbaa !5
  tail call void @_ZN7TreeSet6insertEiii(ptr noundef nonnull align 4 dereferenceable(198000012) @tree, i32 noundef %17, i32 noundef %11, i32 noundef %1)
  %18 = load i32, ptr %9, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [110000 x i32], ptr @pa, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not = icmp eq i32 %21, 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,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass