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

; 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::Channel" = type { %"class.ardb::Runnable", %"struct.ardb::ChannelOptions", i8, i8, i32, %"class.ardb::ChannelPipeline", ptr, i32, i32, %"class.ardb::Buffer", %"class.ardb::Buffer", i32, ptr, ptr, ptr, ptr, i8, i8, i8, ptr, ptr, ptr }
%"class.ardb::Runnable" = type { ptr }
%"struct.ardb::ChannelOptions" = type <{ i32, i32, i8, [3 x i8], i32, i8, [3 x i8], i32, i32, i32, i8, i8, [2 x i8] }>
%"class.ardb::ChannelPipeline" = type { ptr, ptr, ptr, %"class.btree::btree_map" }
%"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<std::__cxx11::basic_string<char>, ardb::ChannelHandlerContext *, std::less<std::__cxx11::basic_string<char>>, std::allocator<std::pair<const std::__cxx11::basic_string<char>, ardb::ChannelHandlerContext *>>, 256>>::empty_base_handle" }
%"struct.btree::btree<btree::btree_map_params<std::__cxx11::basic_string<char>, ardb::ChannelHandlerContext *, std::less<std::__cxx11::basic_string<char>>, std::allocator<std::pair<const std::__cxx11::basic_string<char>, ardb::ChannelHandlerContext *>>, 256>>::empty_base_handle" = type { ptr }
%"class.ardb::Buffer" = type <{ ptr, i64, i64, i64, i8, [7 x i8] }>

@.str = external hidden unnamed_addr constant [78 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [36 x i8], align 1
@__FUNCTION__._ZN4ardb7Channel8AttachFDEv = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4ardb7Channel15IOEventCallbackEP11aeEventLoopiPvi(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #0 align 2

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(288) ptr @_ZN4ardb7Channel10GetServiceEv(ptr noundef nonnull align 8 dereferenceable(256)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4ardb14ChannelService15GetRawEventLoopEv(ptr noundef nonnull align 8 dereferenceable(288)) #2 align 2

declare i32 @aeCreateFileEvent(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) #3

declare i32 @close(i32 noundef) #3

declare noundef ptr @_ZN4ardb10ArdbLogger13GetLogCheckerEv() #3

declare noundef ptr @_ZN4ardb10ArdbLogger13GetLogHandlerEv() #3

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4ardb7Channel8AttachFDEv(ptr noundef nonnull align 8 dereferenceable(256) %0) unnamed_addr #0 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds ptr, ptr %8, i64 16
  %10 = load ptr, ptr %9, align 8
  %11 = call noundef i32 %10(ptr noundef nonnull align 8 dereferenceable(256) %7)
  store i32 %11, ptr %4, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !11
  %12 = getelementptr inbounds %"class.ardb::Channel", ptr %7, i32 0, i32 10
  %13 = call noundef zeroext i1 @_ZNK4ardb6Buffer8ReadableEv(ptr noundef nonnull align 8 dereferenceable(33) %12)
  br i1 %13, label %14, label %17

14:                                               ; preds = %1
  %15 = load i32, ptr %5, align 4, !tbaa !11
  %16 = or i32 %15, 2
  store i32 %16, ptr %5, align 4, !tbaa !11
  br label %17

17:                                               ; preds = %14, %1
  %18 = load i32, ptr %4, align 4, !tbaa !11
  %19 = icmp ne i32 %18, -1
  br i1 %19, label %20, label %45

20:                                               ; preds = %17
  %21 = call noundef nonnull align 8 dereferenceable(288) ptr @_ZN4ardb7Channel10GetServiceEv(ptr noundef nonnull align 8 dereferenceable(256) %7)
  %22 = call noundef ptr @_ZN4ardb14ChannelService15GetRawEventLoopEv(ptr noundef nonnull align 8 dereferenceable(288) %21)
  %23 = load i32, ptr %4, align 4, !tbaa !11
  %24 = load i32, ptr %5, align 4, !tbaa !11
  %25 = call i32 @aeCreateFileEvent(ptr noundef %22, i32 noundef %23, i32 noundef %24, ptr noundef @_ZN4ardb7Channel15IOEventCallbackEP11aeEventLoopiPvi, ptr noundef %7)
  %26 = icmp eq i32 %25, -1
  br i1 %26, label %27, label %45

27:                                               ; preds = %20
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = getelementptr inbounds ptr, ptr %28, i64 16
  %30 = load ptr, ptr %29, align 8
  %31 = call noundef i32 %30(ptr noundef nonnull align 8 dereferenceable(256) %7)
  %32 = call i32 @close(i32 noundef %31)
  br label %33

33:                                               ; preds = %27
  %34 = call noundef ptr @_ZN4ardb10ArdbLogger13GetLogCheckerEv()
  %35 = call noundef zeroext i1 %34(i32 noundef 2)
  br i1 %35, label %36, label %42

36:                                               ; preds = %33
  %37 = call noundef ptr @_ZN4ardb10ArdbLogger13GetLogHandlerEv()
  %38 = load ptr, ptr %7, align 8, !tbaa !9
  %39 = getelementptr inbounds ptr, ptr %38, i64 16
  %40 = load ptr, ptr %39, align 8
  %41 = call noundef i32 %40(ptr noundef nonnull align 8 dereferenceable(256) %7)
  call void (i32, ptr, ptr, i32, ptr, ...) %37(i32 noundef 2, ptr noundef @.str, ptr noundef @__FUNCTION__._ZN4ardb7Channel8AttachFDEv, i32 noundef 138, ptr noundef @.str.2, i32 noundef %41)
  br label %42

42:                                               ; preds = %36, %33
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %47

45:                                               ; preds = %20, %17
  %46 = getelementptr inbounds %"class.ardb::Channel", ptr %7, i32 0, i32 16
  store i8 0, ptr %46, align 8, !tbaa !13
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %47

47:                                               ; preds = %45, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %48 = load i1, ptr %2, align 1
  ret i1 %48
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4ardb6Buffer8ReadableEv(ptr noundef nonnull align 8 dereferenceable(33)) #2 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = { "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, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !17, i64 224}
!14 = !{!"_ZTSN4ardb7ChannelE", !15, i64 0, !16, i64 8, !17, i64 44, !17, i64 45, !12, i64 48, !18, i64 56, !6, i64 88, !12, i64 96, !12, i64 100, !25, i64 104, !25, i64 144, !12, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !17, i64 224, !17, i64 225, !17, i64 226, !6, i64 232, !6, i64 240, !6, i64 248}
!15 = !{!"_ZTSN4ardb8RunnableE"}
!16 = !{!"_ZTSN4ardb14ChannelOptionsE", !12, i64 0, !12, i64 4, !17, i64 8, !12, i64 12, !17, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !17, i64 32, !17, i64 33}
!17 = !{!"bool", !7, i64 0}
!18 = !{!"_ZTSN4ardb15ChannelPipelineE", !6, i64 0, !6, i64 8, !6, i64 16, !19, i64 24}
!19 = !{!"_ZTSN5btree9btree_mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPN4ardb21ChannelHandlerContextESt4lessIS6_ESaISt4pairIKS6_S9_EELi256EEE", !20, i64 0}
!20 = !{!"_ZTSN5btree19btree_map_containerINS_5btreeINS_16btree_map_paramsINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPN4ardb21ChannelHandlerContextESt4lessIS8_ESaISt4pairIKS8_SB_EELi256EEEEEEE", !21, i64 0}
!21 = !{!"_ZTSN5btree22btree_unique_containerINS_5btreeINS_16btree_map_paramsINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPN4ardb21ChannelHandlerContextESt4lessIS8_ESaISt4pairIKS8_SB_EELi256EEEEEEE", !22, i64 0}
!22 = !{!"_ZTSN5btree15btree_containerINS_5btreeINS_16btree_map_paramsINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPN4ardb21ChannelHandlerContextESt4lessIS8_ESaISt4pairIKS8_SB_EELi256EEEEEEE", !23, i64 0}
!23 = !{!"_ZTSN5btree5btreeINS_16btree_map_paramsINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPN4ardb21ChannelHandlerContextESt4lessIS7_ESaISt4pairIKS7_SA_EELi256EEEEE", !24, i64 0}
!24 = !{!"_ZTSN5btree5btreeINS_16btree_map_paramsINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPN4ardb21ChannelHandlerContextESt4lessIS7_ESaISt4pairIKS7_SA_EELi256EEEE17empty_base_handleIS6_PNS_10btree_nodeISH_EEEE", !6, i64 0}
!25 = !{!"_ZTSN4ardb6BufferE", !6, i64 0, !26, i64 8, !26, i64 16, !26, i64 24, !17, i64 32}
!26 = !{!"long", !7, 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"

@.str = external hidden unnamed_addr constant [78 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [36 x i8], align 1
@__FUNCTION__._ZN4ardb7Channel8AttachFDEv = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4ardb7Channel15IOEventCallbackEP11aeEventLoopiPvi(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(288) ptr @_ZN4ardb7Channel10GetServiceEv(ptr noundef nonnull align 8 dereferenceable(256)) local_unnamed_addr #1 align 2

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

declare i32 @aeCreateFileEvent(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @close(i32 noundef) local_unnamed_addr #2

declare noundef ptr @_ZN4ardb10ArdbLogger13GetLogCheckerEv() local_unnamed_addr #2

declare noundef ptr @_ZN4ardb10ArdbLogger13GetLogHandlerEv() local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4ardb7Channel8AttachFDEv(ptr noundef nonnull align 8 dereferenceable(256) %0) unnamed_addr #0 align 2 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 128
  %4 = load ptr, ptr %3, align 8
  %5 = tail call noundef i32 %4(ptr noundef nonnull align 8 dereferenceable(256) %0)
  %6 = getelementptr inbounds i8, ptr %0, i64 144
  %7 = tail call noundef zeroext i1 @_ZNK4ardb6Buffer8ReadableEv(ptr noundef nonnull align 8 dereferenceable(33) %6)
  %.not = icmp eq i32 %5, -1
  br i1 %.not, label %27, label %8

8:                                                ; preds = %1
  %spec.select = select i1 %7, i32 3, i32 1
  %9 = tail call noundef nonnull align 8 dereferenceable(288) ptr @_ZN4ardb7Channel10GetServiceEv(ptr noundef nonnull align 8 dereferenceable(256) %0)
  %10 = tail call noundef ptr @_ZN4ardb14ChannelService15GetRawEventLoopEv(ptr noundef nonnull align 8 dereferenceable(288) %9)
  %11 = tail call i32 @aeCreateFileEvent(ptr noundef %10, i32 noundef %5, i32 noundef %spec.select, ptr noundef nonnull @_ZN4ardb7Channel15IOEventCallbackEP11aeEventLoopiPvi, ptr noundef nonnull %0)
  %12 = icmp eq i32 %11, -1
  br i1 %12, label %13, label %27

13:                                               ; preds = %8
  %14 = load ptr, ptr %0, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 128
  %16 = load ptr, ptr %15, align 8
  %17 = tail call noundef i32 %16(ptr noundef nonnull align 8 dereferenceable(256) %0)
  %18 = tail call i32 @close(i32 noundef %17)
  %19 = tail call noundef ptr @_ZN4ardb10ArdbLogger13GetLogCheckerEv()
  %20 = tail call noundef zeroext i1 %19(i32 noundef 2)
  br i1 %20, label %21, label %29

21:                                               ; preds = %13
  %22 = tail call noundef ptr @_ZN4ardb10ArdbLogger13GetLogHandlerEv()
  %23 = load ptr, ptr %0, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 128
  %25 = load ptr, ptr %24, align 8
  %26 = tail call noundef i32 %25(ptr noundef nonnull align 8 dereferenceable(256) %0)
  tail call void (i32, ptr, ptr, i32, ptr, ...) %22(i32 noundef 2, ptr noundef nonnull @.str, ptr noundef nonnull @__FUNCTION__._ZN4ardb7Channel8AttachFDEv, i32 noundef 138, ptr noundef nonnull @.str.2, i32 noundef %26)
  br label %29

27:                                               ; preds = %8, %1
  %28 = getelementptr inbounds i8, ptr %0, i64 224
  store i8 0, ptr %28, align 8, !tbaa !8
  br label %29

29:                                               ; preds = %13, %21, %27
  %.05 = phi i1 [ true, %27 ], [ false, %21 ], [ false, %13 ]
  ret i1 %.05
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4ardb6Buffer8ReadableEv(ptr noundef nonnull align 8 dereferenceable(33)) 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 = { inlinehint 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 = { "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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !14, i64 224}
!9 = !{!"_ZTSN4ardb7ChannelE", !10, i64 0, !11, i64 8, !14, i64 44, !14, i64 45, !12, i64 48, !15, i64 56, !16, i64 88, !12, i64 96, !12, i64 100, !23, i64 104, !23, i64 144, !12, i64 184, !16, i64 192, !16, i64 200, !16, i64 208, !16, i64 216, !14, i64 224, !14, i64 225, !14, i64 226, !16, i64 232, !16, i64 240, !16, i64 248}
!10 = !{!"_ZTSN4ardb8RunnableE"}
!11 = !{!"_ZTSN4ardb14ChannelOptionsE", !12, i64 0, !12, i64 4, !14, i64 8, !12, i64 12, !14, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !14, i64 32, !14, i64 33}
!12 = !{!"int", !13, i64 0}
!13 = !{!"omnipotent char", !7, i64 0}
!14 = !{!"bool", !13, i64 0}
!15 = !{!"_ZTSN4ardb15ChannelPipelineE", !16, i64 0, !16, i64 8, !16, i64 16, !17, i64 24}
!16 = !{!"any pointer", !13, i64 0}
!17 = !{!"_ZTSN5btree9btree_mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPN4ardb21ChannelHandlerContextESt4lessIS6_ESaISt4pairIKS6_S9_EELi256EEE", !18, i64 0}
!18 = !{!"_ZTSN5btree19btree_map_containerINS_5btreeINS_16btree_map_paramsINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPN4ardb21ChannelHandlerContextESt4lessIS8_ESaISt4pairIKS8_SB_EELi256EEEEEEE", !19, i64 0}
!19 = !{!"_ZTSN5btree22btree_unique_containerINS_5btreeINS_16btree_map_paramsINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPN4ardb21ChannelHandlerContextESt4lessIS8_ESaISt4pairIKS8_SB_EELi256EEEEEEE", !20, i64 0}
!20 = !{!"_ZTSN5btree15btree_containerINS_5btreeINS_16btree_map_paramsINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPN4ardb21ChannelHandlerContextESt4lessIS8_ESaISt4pairIKS8_SB_EELi256EEEEEEE", !21, i64 0}
!21 = !{!"_ZTSN5btree5btreeINS_16btree_map_paramsINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPN4ardb21ChannelHandlerContextESt4lessIS7_ESaISt4pairIKS7_SA_EELi256EEEEE", !22, i64 0}
!22 = !{!"_ZTSN5btree5btreeINS_16btree_map_paramsINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPN4ardb21ChannelHandlerContextESt4lessIS7_ESaISt4pairIKS7_SA_EELi256EEEE17empty_base_handleIS6_PNS_10btree_nodeISH_EEEE", !16, i64 0}
!23 = !{!"_ZTSN4ardb6BufferE", !16, i64 0, !24, i64 8, !24, i64 16, !24, i64 24, !14, i64 32}
!24 = !{!"long", !13, i64 0}


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