; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/link-cut-tree（指针）.ll (Z5splayP4node)

; 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 { ptr, [2 x ptr], i32, i32, i32, i32 }

@_ZZ5splayP4nodeE3sta = external hidden global [400000 x ptr], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z6isrootP4node(ptr noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6pushupP4node(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8pushdownP4node(ptr noundef) #0

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5splayP4node(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !9
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %7, ptr @_ZZ5splayP4nodeE3sta, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %8, ptr %4, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %22, %1
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call noundef zeroext i1 @_Z6isrootP4node(ptr noundef %10)
  %12 = xor i1 %11, true
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.node, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = load i32, ptr %3, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %3, align 4, !tbaa !9
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds [400000 x ptr], ptr @_ZZ5splayP4nodeE3sta, i64 0, i64 %20
  store ptr %17, ptr %21, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %14
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.node, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  store ptr %25, ptr %4, align 8, !tbaa !5
  br label %9, !llvm.loop !13

26:                                               ; preds = %13
  br label %27

27:                                               ; preds = %30, %26
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %36

30:                                               ; preds = %27
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = add nsw i32 %31, -1
  store i32 %32, ptr %3, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [400000 x ptr], ptr @_ZZ5splayP4nodeE3sta, i64 0, i64 %33
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  call void @_Z8pushdownP4node(ptr noundef %35)
  br label %27, !llvm.loop !15

36:                                               ; preds = %27
  br label %37

37:                                               ; preds = %86, %36
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = call noundef zeroext i1 @_Z6isrootP4node(ptr noundef %38)
  %40 = xor i1 %39, true
  br i1 %40, label %41, label %87

41:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.node, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  store ptr %44, ptr %5, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = call noundef zeroext i1 @_Z6isrootP4node(ptr noundef %45)
  br i1 %46, label %47, label %56

47:                                               ; preds = %41
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.node, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds [2 x ptr], ptr %51, i64 0, i64 0
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  %54 = icmp eq ptr %49, %53
  %55 = zext i1 %54 to i32
  call void @_Z6rotateP4nodei(ptr noundef %48, i32 noundef %55)
  br label %86

56:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  %61 = getelementptr inbounds %struct.node, ptr %60, i32 0, i32 1
  %62 = getelementptr inbounds [2 x ptr], ptr %61, i64 0, i64 0
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %64 = icmp eq ptr %57, %63
  %65 = zext i1 %64 to i32
  store i32 %65, ptr %6, align 4, !tbaa !9
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.node, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [2 x ptr], ptr %68, i64 0, i64 %70
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  %73 = icmp eq ptr %66, %72
  br i1 %73, label %74, label %80

74:                                               ; preds = %56
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = load i32, ptr %6, align 4, !tbaa !9
  %77 = icmp ne i32 %76, 0
  %78 = xor i1 %77, true
  %79 = zext i1 %78 to i32
  call void @_Z6rotateP4nodei(ptr noundef %75, i32 noundef %79)
  br label %83

80:                                               ; preds = %56
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i32, ptr %6, align 4, !tbaa !9
  call void @_Z6rotateP4nodei(ptr noundef %81, i32 noundef %82)
  br label %83

83:                                               ; preds = %80, %74
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = load i32, ptr %6, align 4, !tbaa !9
  call void @_Z6rotateP4nodei(ptr noundef %84, i32 noundef %85)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %86

86:                                               ; preds = %83, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %37, !llvm.loop !16

87:                                               ; preds = %37
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_Z6pushupP4node(ptr noundef %88)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4node", !6, i64 0, !7, i64 8, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@_ZZ5splayP4nodeE3sta = external hidden local_unnamed_addr global [400000 x ptr], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z6isrootP4node(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6pushupP4node(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8pushdownP4node(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5splayP4node(ptr noundef %0) local_unnamed_addr #1 {
  store ptr %0, ptr @_ZZ5splayP4nodeE3sta, align 16, !tbaa !5
  %2 = tail call noundef zeroext i1 @_Z6isrootP4node(ptr noundef %0)
  br i1 %2, label %.preheader27.preheader, label %.lr.ph

.preheader27.preheader:                           ; preds = %.preheader27.loopexit, %1
  %indvars.iv33.ph = phi i64 [ %3, %.preheader27.loopexit ], [ 1, %1 ]
  br label %.preheader27

.preheader27.loopexit:                            ; preds = %.lr.ph
  %sext = shl i64 %indvars.iv.next, 32
  %3 = ashr exact i64 %sext, 32
  br label %.preheader27.preheader

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %1 ]
  %.02528 = phi ptr [ %4, %.lr.ph ], [ %0, %1 ]
  %4 = load ptr, ptr %.02528, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %5 = getelementptr inbounds [400000 x ptr], ptr @_ZZ5splayP4nodeE3sta, i64 0, i64 %indvars.iv
  store ptr %4, ptr %5, align 8, !tbaa !5
  %6 = tail call noundef zeroext i1 @_Z6isrootP4node(ptr noundef %4)
  br i1 %6, label %.preheader27.loopexit, label %.lr.ph, !llvm.loop !12

.preheader:                                       ; preds = %.preheader27
  %7 = tail call noundef zeroext i1 @_Z6isrootP4node(ptr noundef %0)
  br i1 %7, label %._crit_edge, label %.lr.ph31

.preheader27:                                     ; preds = %.preheader27.preheader, %.preheader27
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %.preheader27 ], [ %indvars.iv33.ph, %.preheader27.preheader ]
  %indvars.iv.next34 = add nsw i64 %indvars.iv33, -1
  %8 = getelementptr inbounds [400000 x ptr], ptr @_ZZ5splayP4nodeE3sta, i64 0, i64 %indvars.iv.next34
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  tail call void @_Z8pushdownP4node(ptr noundef %9)
  %10 = icmp eq i64 %indvars.iv.next34, 0
  br i1 %10, label %.preheader, label %.preheader27, !llvm.loop !14

.lr.ph31:                                         ; preds = %.preheader, %33
  %11 = load ptr, ptr %0, align 8, !tbaa !9
  %12 = tail call noundef zeroext i1 @_Z6isrootP4node(ptr noundef %11)
  br i1 %12, label %13, label %18

13:                                               ; preds = %.lr.ph31
  %14 = getelementptr inbounds i8, ptr %11, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = icmp eq ptr %15, %0
  %17 = zext i1 %16 to i32
  br label %33

18:                                               ; preds = %.lr.ph31
  %19 = load ptr, ptr %11, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = icmp eq ptr %11, %21
  %23 = zext i1 %22 to i32
  %24 = getelementptr inbounds i8, ptr %11, i64 8
  %25 = zext i1 %22 to i64
  %26 = getelementptr inbounds [2 x ptr], ptr %24, i64 0, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = icmp eq ptr %27, %0
  br i1 %28, label %29, label %32

29:                                               ; preds = %18
  %30 = xor i1 %22, true
  %31 = zext i1 %30 to i32
  tail call void @_Z6rotateP4nodei(ptr noundef nonnull %0, i32 noundef %31)
  br label %33

32:                                               ; preds = %18
  tail call void @_Z6rotateP4nodei(ptr noundef nonnull %11, i32 noundef %23)
  br label %33

33:                                               ; preds = %29, %32, %13
  %.sink = phi i32 [ %17, %13 ], [ %23, %32 ], [ %23, %29 ]
  tail call void @_Z6rotateP4nodei(ptr noundef nonnull %0, i32 noundef %.sink)
  %34 = tail call noundef zeroext i1 @_Z6isrootP4node(ptr noundef nonnull %0)
  br i1 %34, label %._crit_edge, label %.lr.ph31, !llvm.loop !15

._crit_edge:                                      ; preds = %33, %.preheader
  tail call void @_Z6pushupP4node(ptr noundef %0)
  ret void
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4node", !6, i64 0, !7, i64 8, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


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