; LLVM IR from yinqiwen/ardb :: src/common/coro/coro_channel.ll (ZN4ardb11CoroChannel8WaitCoroEv)

; 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::CoroChannel" = type { %"class.ardb::ChannelUpstreamHandler", %"class.ardb::Runnable", ptr, ptr, ptr, ptr, i8, ptr, i8, i32 }
%"class.ardb::ChannelUpstreamHandler" = type { %"class.ardb::AbstractChannelHandler" }
%"class.ardb::AbstractChannelHandler" = type { %"class.ardb::ChannelHandler" }
%"class.ardb::ChannelHandler" = type { ptr }
%"class.ardb::Runnable" = type { ptr }

@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__FUNCTION__._ZN4ardb11CoroChannel8WaitCoroEv = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1

declare noundef nonnull align 8 dereferenceable(184) ptr @_ZN4ardb9Scheduler16CurrentSchedulerEv() #0

; 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: mustprogress uwtable
define dso_local noundef i32 @_ZN4ardb11CoroChannel8WaitCoroEv(ptr noundef nonnull align 8 dereferenceable(72) %0) #2 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %"class.ardb::CoroChannel", ptr %5, i32 0, i32 5
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp ne ptr null, %7
  br i1 %8, label %9, label %17

9:                                                ; preds = %1
  br label %10

10:                                               ; preds = %9
  %11 = call noundef ptr @_ZN4ardb10ArdbLogger13GetLogCheckerEv()
  %12 = call noundef zeroext i1 %11(i32 noundef 2)
  br i1 %12, label %13, label %15

13:                                               ; preds = %10
  %14 = call noundef ptr @_ZN4ardb10ArdbLogger13GetLogHandlerEv()
  call void (i32, ptr, ptr, i32, ptr, ...) %14(i32 noundef 2, ptr noundef @.str.1, ptr noundef @__FUNCTION__._ZN4ardb11CoroChannel8WaitCoroEv, i32 noundef 59, ptr noundef @.str.2)
  br label %15

15:                                               ; preds = %13, %10
  br label %16

16:                                               ; preds = %15
  store i32 -1, ptr %2, align 4
  br label %25

17:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %18 = call noundef nonnull align 8 dereferenceable(184) ptr @_ZN4ardb9Scheduler16CurrentSchedulerEv()
  store ptr %18, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.ardb::CoroChannel", ptr %5, i32 0, i32 4
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = getelementptr inbounds %"class.ardb::CoroChannel", ptr %5, i32 0, i32 5
  store ptr %20, ptr %21, align 8, !tbaa !9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %"class.ardb::CoroChannel", ptr %5, i32 0, i32 4
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  call void @_ZN4ardb9Scheduler4WaitEPNS_9CoroutineE(ptr noundef nonnull align 8 dereferenceable(184) %22, ptr noundef %24)
  store i32 0, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %25

25:                                               ; preds = %17, %16
  %26 = load i32, ptr %2, align 4
  ret i32 %26
}

declare noundef ptr @_ZN4ardb10ArdbLogger13GetLogCheckerEv() #0

declare noundef ptr @_ZN4ardb10ArdbLogger13GetLogHandlerEv() #0

declare void @_ZN4ardb9Scheduler4WaitEPNS_9CoroutineE(ptr noundef nonnull align 8 dereferenceable(184), ptr noundef) #0

attributes #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 = { 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 #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, !6, i64 40}
!10 = !{!"_ZTSN4ardb11CoroChannelE", !11, i64 0, !14, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !15, i64 48, !6, i64 56, !15, i64 64, !16, i64 68}
!11 = !{!"_ZTSN4ardb22ChannelUpstreamHandlerINS_6BufferEEE", !12, i64 0}
!12 = !{!"_ZTSN4ardb22AbstractChannelHandlerINS_6BufferEEE", !13, i64 0}
!13 = !{!"_ZTSN4ardb14ChannelHandlerE"}
!14 = !{!"_ZTSN4ardb8RunnableE"}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!10, !6, i64 32}


; 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.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__FUNCTION__._ZN4ardb11CoroChannel8WaitCoroEv = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1

declare noundef nonnull align 8 dereferenceable(184) ptr @_ZN4ardb9Scheduler16CurrentSchedulerEv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -1, 1) i32 @_ZN4ardb11CoroChannel8WaitCoroEv(ptr nocapture noundef nonnull align 8 dereferenceable(72) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %9, label %4

4:                                                ; preds = %1
  %5 = tail call noundef ptr @_ZN4ardb10ArdbLogger13GetLogCheckerEv()
  %6 = tail call noundef zeroext i1 %5(i32 noundef 2)
  br i1 %6, label %7, label %13

7:                                                ; preds = %4
  %8 = tail call noundef ptr @_ZN4ardb10ArdbLogger13GetLogHandlerEv()
  tail call void (i32, ptr, ptr, i32, ptr, ...) %8(i32 noundef 2, ptr noundef nonnull @.str.1, ptr noundef nonnull @__FUNCTION__._ZN4ardb11CoroChannel8WaitCoroEv, i32 noundef 59, ptr noundef nonnull @.str.2)
  br label %13

9:                                                ; preds = %1
  %10 = tail call noundef nonnull align 8 dereferenceable(184) ptr @_ZN4ardb9Scheduler16CurrentSchedulerEv()
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  store ptr %12, ptr %2, align 8, !tbaa !5
  tail call void @_ZN4ardb9Scheduler4WaitEPNS_9CoroutineE(ptr noundef nonnull align 8 dereferenceable(184) %10, ptr noundef %12)
  br label %13

13:                                               ; preds = %7, %4, %9
  %.0 = phi i32 [ 0, %9 ], [ -1, %4 ], [ -1, %7 ]
  ret i32 %.0
}

declare noundef ptr @_ZN4ardb10ArdbLogger13GetLogCheckerEv() local_unnamed_addr #0

declare noundef ptr @_ZN4ardb10ArdbLogger13GetLogHandlerEv() local_unnamed_addr #0

declare void @_ZN4ardb9Scheduler4WaitEPNS_9CoroutineE(ptr noundef nonnull align 8 dereferenceable(184), ptr noundef) local_unnamed_addr #0

attributes #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 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, !11, i64 40}
!6 = !{!"_ZTSN4ardb11CoroChannelE", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !14, i64 48, !11, i64 56, !14, i64 64, !15, i64 68}
!7 = !{!"_ZTSN4ardb22ChannelUpstreamHandlerINS_6BufferEEE", !8, i64 0}
!8 = !{!"_ZTSN4ardb22AbstractChannelHandlerINS_6BufferEEE", !9, i64 0}
!9 = !{!"_ZTSN4ardb14ChannelHandlerE"}
!10 = !{!"_ZTSN4ardb8RunnableE"}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"bool", !12, i64 0}
!15 = !{!"int", !12, i64 0}
!16 = !{!6, !11, i64 32}


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