; LLVM IR from yinqiwen/ardb :: src/common/channel/channel_service.ll (ZN4ardb14ChannelService12OnSoftSignalEjj)

; 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.ardb::ChannelAsyncIOContext" = type { i32, ptr, ptr }
%"class.ardb::ChannelService" = type { %"class.ardb::Runnable", %"struct.ardb::SoftSignalHandler", %"class.btree::btree_map", i32, ptr, ptr, ptr, ptr, %"class.std::__cxx11::list", %"class.ardb::MPSCQueue", i8, i32, %"class.std::vector", %"class.std::vector.6", i64, %"class.ardb::SPSCQueue", ptr, i32, ptr }
%"class.ardb::Runnable" = type { ptr }
%"struct.ardb::SoftSignalHandler" = type { 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 int, ardb::Channel *, std::less<unsigned int>, std::allocator<std::pair<const unsigned int, ardb::Channel *>>, 256>>::empty_base_handle" }
%"struct.btree::btree<btree::btree_map_params<unsigned int, ardb::Channel *, std::less<unsigned int>, std::allocator<std::pair<const unsigned int, ardb::Channel *>>, 256>>::empty_base_handle" = type { ptr }
%"class.std::__cxx11::list" = type { %"class.std::__cxx11::_List_base" }
%"class.std::__cxx11::_List_base" = type { %"struct.std::__cxx11::_List_base<unsigned int, std::allocator<unsigned int>>::_List_impl" }
%"struct.std::__cxx11::_List_base<unsigned int, std::allocator<unsigned int>>::_List_impl" = type { %"struct.std::__detail::_List_node_header" }
%"struct.std::__detail::_List_node_header" = type { %"struct.std::__detail::_List_node_base", i64 }
%"struct.std::__detail::_List_node_base" = type { ptr, ptr }
%"class.ardb::MPSCQueue" = type { ptr, ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<ardb::ChannelService *, std::allocator<ardb::ChannelService *>>::_Vector_impl" }
%"struct.std::_Vector_base<ardb::ChannelService *, std::allocator<ardb::ChannelService *>>::_Vector_impl" = type { %"struct.std::_Vector_base<ardb::ChannelService *, std::allocator<ardb::ChannelService *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ardb::ChannelService *, std::allocator<ardb::ChannelService *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.6" = type { %"struct.std::_Vector_base.7" }
%"struct.std::_Vector_base.7" = type { %"struct.std::_Vector_base<ardb::Thread *, std::allocator<ardb::Thread *>>::_Vector_impl" }
%"struct.std::_Vector_base<ardb::Thread *, std::allocator<ardb::Thread *>>::_Vector_impl" = type { %"struct.std::_Vector_base<ardb::Thread *, std::allocator<ardb::Thread *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ardb::Thread *, std::allocator<ardb::Thread *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.ardb::SPSCQueue" = type { ptr, [64 x i8], ptr, ptr, ptr }

; 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
define dso_local void @_ZN4ardb14ChannelService12OnSoftSignalEjj(ptr noundef nonnull align 8 dereferenceable(288) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca %"struct.ardb::ChannelAsyncIOContext", align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  %11 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %11, label %47 [
    i32 1, label %12
    i32 2, label %13
    i32 3, label %27
    i32 4, label %28
  ]

12:                                               ; preds = %3
  call void @_ZN4ardb14ChannelService17VerifyRemoveQueueEv(ptr noundef nonnull align 8 dereferenceable(288) %10)
  br label %48

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr null, ptr %7, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %25, %13
  %15 = getelementptr inbounds %"class.ardb::ChannelService", ptr %10, i32 0, i32 15
  %16 = call noundef zeroext i1 @_ZN4ardb9SPSCQueueIPNS_8RunnableEE3PopERS2_(ptr noundef nonnull align 8 dereferenceable(96) %15, ptr noundef nonnull align 8 dereferenceable(8) %7)
  br i1 %16, label %17, label %26

17:                                               ; preds = %14
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr null, %18
  br i1 %19, label %20, label %25

20:                                               ; preds = %17
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = getelementptr inbounds ptr, ptr %22, i64 0
  %24 = load ptr, ptr %23, align 8
  call void %24(ptr noundef nonnull align 8 dereferenceable(8) %21)
  br label %25

25:                                               ; preds = %20, %17
  br label %14, !llvm.loop !13

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

27:                                               ; preds = %3
  br label %48

28:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #3
  call void @_ZN4ardb21ChannelAsyncIOContextC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %8)
  br label %29

29:                                               ; preds = %45, %28
  %30 = getelementptr inbounds %"class.ardb::ChannelService", ptr %10, i32 0, i32 9
  %31 = call noundef zeroext i1 @_ZN4ardb9MPSCQueueINS_21ChannelAsyncIOContextEE3PopERS1_(ptr noundef nonnull align 8 dereferenceable(16) %30, ptr noundef nonnull align 8 dereferenceable(24) %8)
  br i1 %31, label %32, label %46

32:                                               ; preds = %29
  %33 = getelementptr inbounds %"struct.ardb::ChannelAsyncIOContext", ptr %8, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = icmp ne ptr null, %34
  br i1 %35, label %36, label %45

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %37 = getelementptr inbounds %"struct.ardb::ChannelAsyncIOContext", ptr %8, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !17
  %39 = call noundef ptr @_ZN4ardb14ChannelService10GetChannelEj(ptr noundef nonnull align 8 dereferenceable(288) %10, i32 noundef %38)
  store ptr %39, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.ardb::ChannelAsyncIOContext", ptr %8, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.ardb::ChannelAsyncIOContext", ptr %8, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !18
  call void %41(ptr noundef %42, ptr noundef %44)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %45

45:                                               ; preds = %36, %32
  br label %29, !llvm.loop !19

46:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #3
  br label %48

47:                                               ; preds = %3
  br label %48

48:                                               ; preds = %47, %46, %27, %26, %12
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4ardb9SPSCQueueIPNS_8RunnableEE3PopERS2_(ptr noundef nonnull align 8 dereferenceable(96), ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN4ardb9MPSCQueueINS_21ChannelAsyncIOContextEE3PopERS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN4ardb14ChannelService10GetChannelEj(ptr noundef nonnull align 8 dereferenceable(288), i32 noundef) #1 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, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 8}
!16 = !{!"_ZTSN4ardb21ChannelAsyncIOContextE", !10, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!16, !10, i64 0}
!18 = !{!16, !6, i64 16}
!19 = distinct !{!19, !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"

%"struct.ardb::ChannelAsyncIOContext" = type { i32, ptr, ptr }

; 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
define dso_local void @_ZN4ardb14ChannelService12OnSoftSignalEjj(ptr noundef nonnull align 8 dereferenceable(288) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca %"struct.ardb::ChannelAsyncIOContext", align 8
  switch i32 %1, label %30 [
    i32 1, label %6
    i32 2, label %7
    i32 4, label %16
  ]

6:                                                ; preds = %3
  tail call void @_ZN4ardb14ChannelService17VerifyRemoveQueueEv(ptr noundef nonnull align 8 dereferenceable(288) %0)
  br label %30

7:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store ptr null, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 168
  %9 = call noundef zeroext i1 @_ZN4ardb9SPSCQueueIPNS_8RunnableEE3PopERS2_(ptr noundef nonnull align 8 dereferenceable(96) %8, ptr noundef nonnull align 8 dereferenceable(8) %4)
  br i1 %9, label %.lr.ph4, label %._crit_edge5

.lr.ph4:                                          ; preds = %7, %14
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %.not2 = icmp eq ptr %10, null
  br i1 %.not2, label %14, label %11

11:                                               ; preds = %.lr.ph4
  %12 = load ptr, ptr %10, align 8, !tbaa !9
  %13 = load ptr, ptr %12, align 8
  call void %13(ptr noundef nonnull align 8 dereferenceable(8) %10)
  br label %14

14:                                               ; preds = %11, %.lr.ph4
  %15 = call noundef zeroext i1 @_ZN4ardb9SPSCQueueIPNS_8RunnableEE3PopERS2_(ptr noundef nonnull align 8 dereferenceable(96) %8, ptr noundef nonnull align 8 dereferenceable(8) %4)
  br i1 %15, label %.lr.ph4, label %._crit_edge5, !llvm.loop !11

._crit_edge5:                                     ; preds = %14, %7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br label %30

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #3
  call void @_ZN4ardb21ChannelAsyncIOContextC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %5)
  %17 = getelementptr inbounds i8, ptr %0, i64 88
  %18 = call noundef zeroext i1 @_ZN4ardb9MPSCQueueINS_21ChannelAsyncIOContextEE3PopERS1_(ptr noundef nonnull align 8 dereferenceable(16) %17, ptr noundef nonnull align 8 dereferenceable(24) %5)
  br i1 %18, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %16
  %19 = getelementptr inbounds i8, ptr %5, i64 8
  %20 = getelementptr inbounds i8, ptr %5, i64 16
  br label %21

21:                                               ; preds = %.lr.ph, %28
  %22 = load ptr, ptr %19, align 8, !tbaa !13
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %28, label %23

23:                                               ; preds = %21
  %24 = load i32, ptr %5, align 8, !tbaa !16
  %25 = call noundef ptr @_ZN4ardb14ChannelService10GetChannelEj(ptr noundef nonnull align 8 dereferenceable(288) %0, i32 noundef %24)
  %26 = load ptr, ptr %19, align 8, !tbaa !13
  %27 = load ptr, ptr %20, align 8, !tbaa !17
  call void %26(ptr noundef %25, ptr noundef %27)
  br label %28

28:                                               ; preds = %23, %21
  %29 = call noundef zeroext i1 @_ZN4ardb9MPSCQueueINS_21ChannelAsyncIOContextEE3PopERS1_(ptr noundef nonnull align 8 dereferenceable(16) %17, ptr noundef nonnull align 8 dereferenceable(24) %5)
  br i1 %29, label %21, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %28, %16
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  br label %30

30:                                               ; preds = %3, %._crit_edge, %._crit_edge5, %6
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4ardb9SPSCQueueIPNS_8RunnableEE3PopERS2_(ptr noundef nonnull align 8 dereferenceable(96), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN4ardb9MPSCQueueINS_21ChannelAsyncIOContextEE3PopERS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN4ardb14ChannelService10GetChannelEj(ptr noundef nonnull align 8 dereferenceable(288), i32 noundef) local_unnamed_addr #1 align 2

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 = { 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 = !{!"vtable pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 8}
!14 = !{!"_ZTSN4ardb21ChannelAsyncIOContextE", !15, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!"int", !7, i64 0}
!16 = !{!14, !15, i64 0}
!17 = !{!14, !6, i64 16}
!18 = distinct !{!18, !12}


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