; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/TopTree.ll (Z7addvirtP4nodeS0_)

; 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.node = type <{ [4 x ptr], ptr, %struct.info, %struct.info, %struct.info, %struct.info, %struct.mark, %struct.mark, i8, i8, [6 x i8] }>
%struct.info = type { i32, i32, i32, i32 }
%struct.mark = type { i32, i32 }

@null = external dso_local global ptr, align 8

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

; 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: mustprogress uwtable
declare dso_local void @_ZN4node4downEv(ptr noundef nonnull align 8 dereferenceable(122)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4node4linkEiPS_(ptr noundef nonnull align 8 dereferenceable(122), i32 noundef, ptr noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7addvirtP4nodeS0_(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr @null, align 8, !tbaa !5
  %10 = icmp eq ptr %8, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  br label %64

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN4node4downEv(ptr noundef nonnull align 8 dereferenceable(122) %13)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 2, ptr %5, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %32, %12
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp slt i32 %15, 4
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 2, ptr %6, align 4
  br label %35

18:                                               ; preds = %14
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.node, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [4 x ptr], ptr %20, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = load ptr, ptr @null, align 8, !tbaa !5
  %26 = icmp eq ptr %24, %25
  br i1 %26, label %27, label %31

27:                                               ; preds = %18
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !9
  call void @_ZN4node3setEPS_i(ptr noundef nonnull align 8 dereferenceable(122) %28, ptr noundef %29, i32 noundef %30)
  store i32 1, ptr %6, align 4
  br label %35

31:                                               ; preds = %18
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %5, align 4, !tbaa !9
  br label %14, !llvm.loop !11

35:                                               ; preds = %27, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %36 = load i32, ptr %6, align 4
  switch i32 %36, label %65 [
    i32 2, label %37
    i32 1, label %64
  ]

37:                                               ; preds = %35
  br label %38

38:                                               ; preds = %46, %37
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.node, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds [4 x ptr], ptr %40, i64 0, i64 2
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.node, ptr %42, i32 0, i32 9
  %44 = load i8, ptr %43, align 1, !tbaa !13, !range !18, !noundef !19
  %45 = trunc i8 %44 to i1
  br i1 %45, label %46, label %51

46:                                               ; preds = %38
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.node, ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds [4 x ptr], ptr %48, i64 0, i64 2
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  store ptr %50, ptr %4, align 8, !tbaa !5
  br label %38, !llvm.loop !20

51:                                               ; preds = %38
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_Z5splayP4nodei(ptr noundef %52, i32 noundef 2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %53 = call noundef ptr @_Z7newnodei(i32 noundef 2147483647)
  store ptr %53, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.node, ptr %55, i32 0, i32 0
  %57 = getelementptr inbounds [4 x ptr], ptr %56, i64 0, i64 2
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  call void @_ZN4node4linkEiPS_(ptr noundef nonnull align 8 dereferenceable(122) %54, i32 noundef 2, ptr noundef %58)
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN4node4linkEiPS_(ptr noundef nonnull align 8 dereferenceable(122) %59, i32 noundef 3, ptr noundef %60)
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN4node3setEPS_i(ptr noundef nonnull align 8 dereferenceable(122) %61, ptr noundef %62, i32 noundef 2)
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_Z5splayP4nodei(ptr noundef %63, i32 noundef 2)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %64

64:                                               ; preds = %51, %35, %11
  ret void

65:                                               ; preds = %35
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4node3setEPS_i(ptr noundef nonnull align 8 dereferenceable(122), ptr noundef, i32 noundef) #0 align 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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !17, i64 121}
!14 = !{!"_ZTS4node", !7, i64 0, !6, i64 32, !15, i64 40, !15, i64 56, !15, i64 72, !15, i64 88, !16, i64 104, !16, i64 112, !17, i64 120, !17, i64 121}
!15 = !{!"_ZTS4info", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!16 = !{!"_ZTS4mark", !10, i64 0, !10, i64 4}
!17 = !{!"bool", !7, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = distinct !{!20, !12}


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

@null = external dso_local local_unnamed_addr global ptr, align 8

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4node4downEv(ptr noundef nonnull align 8 dereferenceable(122)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4node4linkEiPS_(ptr noundef nonnull align 8 dereferenceable(122), i32 noundef, ptr noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7addvirtP4nodeS0_(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @null, align 8, !tbaa !5
  %4 = icmp eq ptr %3, %0
  br i1 %4, label %23, label %5

5:                                                ; preds = %2
  tail call void @_ZN4node4downEv(ptr noundef nonnull align 8 dereferenceable(122) %1)
  %6 = load ptr, ptr @null, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = icmp eq ptr %8, %6
  br i1 %9, label %.thread, label %10

.thread:                                          ; preds = %10, %5
  %.02026.lcssa.wide = phi i32 [ 2, %5 ], [ 3, %10 ]
  tail call void @_ZN4node3setEPS_i(ptr noundef nonnull align 8 dereferenceable(122) %1, ptr noundef %0, i32 noundef %.02026.lcssa.wide)
  br label %23

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %1, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = icmp eq ptr %12, %6
  br i1 %13, label %.thread, label %.preheader

.preheader:                                       ; preds = %10, %.preheader
  %.0 = phi ptr [ %15, %.preheader ], [ %1, %10 ]
  %14 = getelementptr inbounds i8, ptr %.0, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 121
  %17 = load i8, ptr %16, align 1, !tbaa !9, !range !15, !noundef !16
  %18 = trunc nuw i8 %17 to i1
  br i1 %18, label %.preheader, label %19, !llvm.loop !17

19:                                               ; preds = %.preheader
  %20 = getelementptr inbounds i8, ptr %.0, i64 16
  tail call void @_Z5splayP4nodei(ptr noundef nonnull %.0, i32 noundef 2)
  %21 = tail call noundef ptr @_Z7newnodei(i32 noundef 2147483647)
  %22 = load ptr, ptr %20, align 8, !tbaa !5
  tail call void @_ZN4node4linkEiPS_(ptr noundef nonnull align 8 dereferenceable(122) %21, i32 noundef 2, ptr noundef %22)
  tail call void @_ZN4node4linkEiPS_(ptr noundef nonnull align 8 dereferenceable(122) %21, i32 noundef 3, ptr noundef %0)
  tail call void @_ZN4node3setEPS_i(ptr noundef nonnull align 8 dereferenceable(122) %.0, ptr noundef nonnull %21, i32 noundef 2)
  tail call void @_Z5splayP4nodei(ptr noundef nonnull %21, i32 noundef 2)
  br label %23

23:                                               ; preds = %.thread, %2, %19
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4node3setEPS_i(ptr noundef nonnull align 8 dereferenceable(122), ptr noundef, i32 noundef) local_unnamed_addr #0 align 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 = { 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" }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !14, i64 121}
!10 = !{!"_ZTS4node", !7, i64 0, !6, i64 32, !11, i64 40, !11, i64 56, !11, i64 72, !11, i64 88, !13, i64 104, !13, i64 112, !14, i64 120, !14, i64 121}
!11 = !{!"_ZTS4info", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTS4mark", !12, i64 0, !12, i64 4}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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