; LLVM IR from yinqiwen/ardb :: src/common/coro/scheduler.ll (ZN4ardb9Scheduler6WakeupEPNS_9CoroutineE)

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

%"class.ardb::Scheduler" = type { %"class.std::stack", %"class.std::stack", %"class.btree::btree_map", %"class.btree::btree_map", ptr }
%"class.std::stack" = type { %"class.std::deque" }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<ardb::Coroutine *, std::allocator<ardb::Coroutine *>>::_Deque_impl" }
%"struct.std::_Deque_base<ardb::Coroutine *, std::allocator<ardb::Coroutine *>>::_Deque_impl" = type { %"struct.std::_Deque_base<ardb::Coroutine *, std::allocator<ardb::Coroutine *>>::_Deque_impl_data" }
%"struct.std::_Deque_base<ardb::Coroutine *, std::allocator<ardb::Coroutine *>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, ptr }
%"class.btree::btree_map" = type { %"class.btree::btree_map_container" }
%"class.btree::btree_map_container" = type { %"class.btree::btree_unique_container" }
%"class.btree::btree_unique_container" = type { %"class.btree::btree_container" }
%"class.btree::btree_container" = type { %"class.btree::btree" }
%"class.btree::btree" = type { %"struct.btree::btree<btree::btree_map_params<unsigned long, ardb::Coroutine *, std::less<unsigned long>, std::allocator<std::pair<const unsigned long, ardb::Coroutine *>>, 256>>::empty_base_handle" }
%"struct.btree::btree<btree::btree_map_params<unsigned long, ardb::Coroutine *, std::less<unsigned long>, std::allocator<std::pair<const unsigned long, ardb::Coroutine *>>, 256>>::empty_base_handle" = type { ptr }
%"struct.ardb::Coroutine" = type { i64, ptr, %struct.coro_context, %struct.coro_stack }
%struct.coro_context = type { ptr }
%struct.coro_stack = type { ptr, i64 }

declare i32 @__gxx_personality_v0(...)

; 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 @_ZN4ardb9Scheduler5CleanEv(ptr noundef nonnull align 8 dereferenceable(184)) #1 align 2

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4ardb9Scheduler6WakeupEPNS_9CoroutineE(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef %1) #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  call void @_ZN4ardb9Scheduler5CleanEv(ptr noundef nonnull align 8 dereferenceable(184) %9)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %10 = call noundef ptr @_ZN4ardb9Scheduler19GetCurrentCoroutineEv(ptr noundef nonnull align 8 dereferenceable(184) %9)
  store ptr %10, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr null, %11
  br i1 %12, label %13, label %20

13:                                               ; preds = %2
  %14 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 40) #7
  invoke void @_ZN4ardb9CoroutineC1EPFvPvES1_j(ptr noundef nonnull align 8 dereferenceable(40) %14, ptr noundef null, ptr noundef null, i32 noundef 0)
          to label %15 unwind label %16

15:                                               ; preds = %13
  store ptr %14, ptr %5, align 8, !tbaa !5
  br label %20

16:                                               ; preds = %13
  %17 = landingpad { ptr, i32 }
          cleanup
  %18 = extractvalue { ptr, i32 } %17, 0
  store ptr %18, ptr %6, align 8
  %19 = extractvalue { ptr, i32 } %17, 1
  store i32 %19, ptr %7, align 4
  call void @_ZdlPvm(ptr noundef %14, i64 noundef 40) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br label %36

20:                                               ; preds = %15, %2
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = icmp eq ptr %21, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %20
  store i32 1, ptr %8, align 4
  br label %33

25:                                               ; preds = %20
  %26 = getelementptr inbounds %"class.ardb::Scheduler", ptr %9, i32 0, i32 0
  call void @_ZNSt5stackIPN4ardb9CoroutineESt5dequeIS2_SaIS2_EEE4pushERKS2_(ptr noundef nonnull align 8 dereferenceable(80) %26, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN4ardb9Scheduler19SetCurrentCoroutineEPNS_9CoroutineE(ptr noundef nonnull align 8 dereferenceable(184) %9, ptr noundef %27)
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.ardb::Coroutine", ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.ardb::Coroutine", ptr %30, i32 0, i32 2
  call void @coro_transfer(ptr noundef %29, ptr noundef %31)
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN4ardb9Scheduler19SetCurrentCoroutineEPNS_9CoroutineE(ptr noundef nonnull align 8 dereferenceable(184) %9, ptr noundef %32)
  store i32 0, ptr %8, align 4
  br label %33

33:                                               ; preds = %25, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  %34 = load i32, ptr %8, align 4
  switch i32 %34, label %41 [
    i32 0, label %35
    i32 1, label %35
  ]

35:                                               ; preds = %33, %33
  ret void

36:                                               ; preds = %16
  %37 = load ptr, ptr %6, align 8
  %38 = load i32, ptr %7, align 4
  %39 = insertvalue { ptr, i32 } poison, ptr %37, 0
  %40 = insertvalue { ptr, i32 } %39, i32 %38, 1
  resume { ptr, i32 } %40

41:                                               ; preds = %33
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4ardb9Scheduler19GetCurrentCoroutineEv(ptr noundef nonnull align 8 dereferenceable(184)) #3 align 2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #4

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb9Scheduler19SetCurrentCoroutineEPNS_9CoroutineE(ptr noundef nonnull align 8 dereferenceable(184), ptr noundef) #3 align 2

declare void @coro_transfer(ptr noundef, ptr noundef) #5

declare void @_ZN4ardb9CoroutineC1EPFvPvES1_j(ptr, ptr, ptr, i32)

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 = { nobuiltin 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 #3 = { 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 #4 = { nobuiltin allocsize(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 #5 = { "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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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"}


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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress 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 @_ZN4ardb9Scheduler5CleanEv(ptr noundef nonnull align 8 dereferenceable(184)) local_unnamed_addr #1 align 2

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4ardb9Scheduler6WakeupEPNS_9CoroutineE(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef %1) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  tail call void @_ZN4ardb9Scheduler5CleanEv(ptr noundef nonnull align 8 dereferenceable(184) %0)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #6
  %4 = tail call noundef ptr @_ZN4ardb9Scheduler19GetCurrentCoroutineEv(ptr noundef nonnull align 8 dereferenceable(184) %0)
  store ptr %4, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %11

6:                                                ; preds = %2
  %7 = tail call noalias noundef nonnull dereferenceable(40) ptr @_Znwm(i64 noundef 40) #7
  invoke void @_ZN4ardb9CoroutineC1EPFvPvES1_j(ptr noundef nonnull align 8 dereferenceable(40) %7, ptr noundef null, ptr noundef null, i32 noundef 0)
          to label %8 unwind label %9

8:                                                ; preds = %6
  store ptr %7, ptr %3, align 8, !tbaa !5
  br label %11

9:                                                ; preds = %6
  %10 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %7, i64 noundef 40) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #6
  resume { ptr, i32 } %10

11:                                               ; preds = %8, %2
  %12 = phi ptr [ %7, %8 ], [ %4, %2 ]
  %13 = icmp eq ptr %12, %1
  br i1 %13, label %19, label %14

14:                                               ; preds = %11
  call void @_ZNSt5stackIPN4ardb9CoroutineESt5dequeIS2_SaIS2_EEE4pushERKS2_(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef nonnull align 8 dereferenceable(8) %3)
  call void @_ZN4ardb9Scheduler19SetCurrentCoroutineEPNS_9CoroutineE(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef %1)
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  %17 = getelementptr inbounds i8, ptr %1, i64 16
  call void @coro_transfer(ptr noundef nonnull %16, ptr noundef nonnull %17)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN4ardb9Scheduler19SetCurrentCoroutineEPNS_9CoroutineE(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef %18)
  br label %19

19:                                               ; preds = %11, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #6
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4ardb9Scheduler19GetCurrentCoroutineEv(ptr noundef nonnull align 8 dereferenceable(184)) local_unnamed_addr #3 align 2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5stackIPN4ardb9CoroutineESt5dequeIS2_SaIS2_EEE4pushERKS2_(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb9Scheduler19SetCurrentCoroutineEPNS_9CoroutineE(ptr noundef nonnull align 8 dereferenceable(184), ptr noundef) local_unnamed_addr #3 align 2

declare void @coro_transfer(ptr noundef, ptr noundef) local_unnamed_addr #5

declare void @_ZN4ardb9CoroutineC1EPFvPvES1_j(ptr, ptr, ptr, i32) local_unnamed_addr

attributes #0 = { mustprogress 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 = { nobuiltin 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 #3 = { 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 #4 = { nobuiltin allocsize(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 #5 = { "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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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"}


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