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

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

; 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 void @_Z5transP4node(ptr noundef) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5splayP4nodei(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %30, %2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = call noundef zeroext i1 @_ZN4node6isrootEi(ptr noundef nonnull align 8 dereferenceable(122) %7, i32 noundef %8)
  %10 = xor i1 %9, true
  br i1 %10, label %11, label %32

11:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.node, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  store ptr %14, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = call noundef zeroext i1 @_ZN4node6isrootEi(ptr noundef nonnull align 8 dereferenceable(122) %15, i32 noundef %16)
  br i1 %17, label %30, label %18

18:                                               ; preds = %11
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call noundef i32 @_ZN4node4kindEv(ptr noundef nonnull align 8 dereferenceable(122) %19)
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call noundef i32 @_ZN4node4kindEv(ptr noundef nonnull align 8 dereferenceable(122) %21)
  %23 = icmp eq i32 %20, %22
  br i1 %23, label %24, label %26

24:                                               ; preds = %18
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  br label %28

26:                                               ; preds = %18
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %26, %24
  %29 = phi ptr [ %25, %24 ], [ %27, %26 ]
  call void @_Z5transP4node(ptr noundef %29)
  br label %30

30:                                               ; preds = %28, %11
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_Z5transP4node(ptr noundef %31)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %6, !llvm.loop !16

32:                                               ; preds = %6
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN4node2upEv(ptr noundef nonnull align 8 dereferenceable(122) %33)
  ret void
}

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

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 = { 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 = !{!12, !6, i64 32}
!12 = !{!"_ZTS4node", !7, i64 0, !6, i64 32, !13, i64 40, !13, i64 56, !13, i64 72, !13, i64 88, !14, i64 104, !14, i64 112, !15, i64 120, !15, i64 121}
!13 = !{!"_ZTS4info", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!14 = !{!"_ZTS4mark", !10, i64 0, !10, i64 4}
!15 = !{!"bool", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5splayP4nodei(ptr noundef nonnull %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef zeroext i1 @_ZN4node6isrootEi(ptr noundef nonnull align 8 dereferenceable(122) %0, i32 noundef %1)
  br i1 %3, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  br label %5

5:                                                ; preds = %.lr.ph, %13
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = tail call noundef zeroext i1 @_ZN4node6isrootEi(ptr noundef nonnull align 8 dereferenceable(122) %6, i32 noundef %1)
  br i1 %7, label %13, label %8

8:                                                ; preds = %5
  %9 = tail call noundef i32 @_ZN4node4kindEv(ptr noundef nonnull align 8 dereferenceable(122) %6)
  %10 = tail call noundef i32 @_ZN4node4kindEv(ptr noundef nonnull align 8 dereferenceable(122) %0)
  %11 = icmp eq i32 %9, %10
  %12 = select i1 %11, ptr %6, ptr %0
  tail call void @_Z5transP4node(ptr noundef nonnull %12)
  br label %13

13:                                               ; preds = %8, %5
  tail call void @_Z5transP4node(ptr noundef nonnull %0)
  %14 = tail call noundef zeroext i1 @_ZN4node6isrootEi(ptr noundef nonnull align 8 dereferenceable(122) %0, i32 noundef %1)
  br i1 %14, label %._crit_edge, label %5, !llvm.loop !14

._crit_edge:                                      ; preds = %13, %2
  tail call void @_ZN4node2upEv(ptr noundef nonnull align 8 dereferenceable(122) %0)
  ret void
}

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


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass