; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/可持久化Treap.ll (ZN5treap5mergeEPNS_4nodeES1_)

; 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.treap::node" = type { ptr, ptr, i32, i32 }

@_ZN5treap3nilE = external dso_local global ptr, align 8

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

; Function Attrs: nounwind
declare i32 @rand() #1

; 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 ptr @_ZN5treap4copyEPNS_4nodeE(ptr noundef) #2

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

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %12, ptr %3, align 8
  br label %57

13:                                               ; preds = %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr @_ZN5treap3nilE, align 8, !tbaa !5
  %16 = icmp eq ptr %14, %15
  br i1 %16, label %17, label %19

17:                                               ; preds = %13
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %18, ptr %3, align 8
  br label %57

19:                                               ; preds = %13
  %20 = call i32 @rand() #4
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.treap::node", ptr %21, i32 0, i32 3
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.treap::node", ptr %24, i32 0, i32 3
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = add nsw i32 %23, %26
  %28 = srem i32 %20, %27
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.treap::node", ptr %29, i32 0, i32 3
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = icmp slt i32 %28, %31
  br i1 %32, label %33, label %45

33:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = call noundef ptr @_ZN5treap4copyEPNS_4nodeE(ptr noundef %34)
  store ptr %35, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.treap::node", ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !12
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = call noundef ptr @_ZN5treap5mergeEPNS_4nodeES1_(ptr noundef %38, ptr noundef %39)
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.treap::node", ptr %41, i32 0, i32 1
  store ptr %40, ptr %42, align 8, !tbaa !12
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN5treap4node2upEv(ptr noundef nonnull align 8 dereferenceable(24) %43)
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %44, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %57

45:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = call noundef ptr @_ZN5treap4copyEPNS_4nodeE(ptr noundef %46)
  store ptr %47, ptr %7, align 8, !tbaa !5
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %"struct.treap::node", ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !13
  %52 = call noundef ptr @_ZN5treap5mergeEPNS_4nodeES1_(ptr noundef %48, ptr noundef %51)
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %"struct.treap::node", ptr %53, i32 0, i32 0
  store ptr %52, ptr %54, align 8, !tbaa !13
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN5treap4node2upEv(ptr noundef nonnull align 8 dereferenceable(24) %55)
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %56, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %57

57:                                               ; preds = %45, %33, %17, %11
  %58 = load ptr, ptr %3, align 8
  ret ptr %58
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5treap4node2upEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { 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 #4 = { 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, !11, i64 20}
!10 = !{!"_ZTSN5treap4nodeE", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 0}


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

@_ZN5treap3nilE = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN5treap5mergeEPNS_4nodeES1_(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr @_ZN5treap3nilE, align 8, !tbaa !5
  %4 = icmp eq ptr %3, %0
  br i1 %4, label %common.ret, label %5

5:                                                ; preds = %2
  %6 = icmp eq ptr %3, %1
  br i1 %6, label %common.ret, label %7

7:                                                ; preds = %5
  %8 = tail call i32 @rand() #2
  %9 = getelementptr inbounds i8, ptr %0, i64 20
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %1, i64 20
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = add nsw i32 %12, %10
  %14 = srem i32 %8, %13
  %15 = icmp slt i32 %14, %10
  br i1 %15, label %16, label %22

common.ret.sink.split:                            ; preds = %16, %22
  %.sink = phi ptr [ %23, %22 ], [ %17, %16 ]
  tail call void @_ZN5treap4node2upEv(ptr noundef nonnull align 8 dereferenceable(24) %.sink)
  br label %common.ret

common.ret:                                       ; preds = %common.ret.sink.split, %2, %5
  %common.ret.op = phi ptr [ %1, %2 ], [ %0, %5 ], [ %.sink, %common.ret.sink.split ]
  ret ptr %common.ret.op

16:                                               ; preds = %7
  %17 = tail call noundef ptr @_ZN5treap4copyEPNS_4nodeE(ptr noundef nonnull %0)
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = tail call noundef ptr @_ZN5treap5mergeEPNS_4nodeES1_(ptr noundef %19, ptr noundef nonnull %1)
  %21 = getelementptr inbounds i8, ptr %17, i64 8
  store ptr %20, ptr %21, align 8, !tbaa !12
  br label %common.ret.sink.split

22:                                               ; preds = %7
  %23 = tail call noundef ptr @_ZN5treap4copyEPNS_4nodeE(ptr noundef nonnull %1)
  %24 = load ptr, ptr %1, align 8, !tbaa !13
  %25 = tail call noundef ptr @_ZN5treap5mergeEPNS_4nodeES1_(ptr noundef nonnull %0, ptr noundef %24)
  store ptr %25, ptr %23, align 8, !tbaa !13
  br label %common.ret.sink.split
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5treap4node2upEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

attributes #0 = { nounwind "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" }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 20}
!10 = !{!"_ZTSN5treap4nodeE", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass