; LLVM IR from cjmcv/hpc :: coroutine/libco/libco/src/co_routine.ll (Z17co_cond_broadcastP10stCoCond_t)

; 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.stCoCondItem_t = type { ptr, ptr, ptr, %struct.stTimeoutItem_t }
%struct.stTimeoutItem_t = type { ptr, ptr, ptr, i64, ptr, ptr, ptr, i8 }
%struct.stCoRoutineEnv_t = type { [128 x ptr], i32, ptr, ptr, ptr }
%struct.stCoEpoll_t = type { i32, ptr, 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z7AddTailI15stTimeoutItem_t19stTimeoutItemLink_tEvPT0_PT_(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z22co_get_curr_thread_envv() #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z14RemoveFromLinkI15stTimeoutItem_t19stTimeoutItemLink_tEvPT_(ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z11co_cond_popP10stCoCond_t(ptr noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z17co_cond_broadcastP10stCoCond_t(ptr noundef %0) #3 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %24, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = call noundef ptr @_Z11co_cond_popP10stCoCond_t(ptr noundef %7)
  store ptr %8, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %6
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %22

12:                                               ; preds = %6
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.stCoCondItem_t, ptr %13, i32 0, i32 3
  call void @_Z14RemoveFromLinkI15stTimeoutItem_t19stTimeoutItemLink_tEvPT_(ptr noundef %14)
  %15 = call noundef ptr @_Z22co_get_curr_thread_envv()
  %16 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.stCoEpoll_t, ptr %17, i32 0, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.stCoCondItem_t, ptr %20, i32 0, i32 3
  call void @_Z7AddTailI15stTimeoutItem_t19stTimeoutItemLink_tEvPT0_PT_(ptr noundef %19, ptr noundef %21)
  store i32 0, ptr %5, align 4
  br label %22

22:                                               ; preds = %12, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %23 = load i32, ptr %5, align 4
  switch i32 %23, label %27 [
    i32 0, label %24
    i32 1, label %25
  ]

24:                                               ; preds = %22
  br label %6, !llvm.loop !14

25:                                               ; preds = %22
  %26 = load i32, ptr %2, align 4
  ret i32 %26

27:                                               ; preds = %22
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 1032}
!10 = !{!"_ZTS16stCoRoutineEnv_t", !7, i64 0, !11, i64 1024, !6, i64 1032, !6, i64 1040, !6, i64 1048}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 24}
!13 = !{!"_ZTS11stCoEpoll_t", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z7AddTailI15stTimeoutItem_t19stTimeoutItemLink_tEvPT0_PT_(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z11co_cond_popP10stCoCond_t(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z17co_cond_broadcastP10stCoCond_t(ptr noundef %0) local_unnamed_addr #2 {
  %2 = tail call noundef ptr @_Z11co_cond_popP10stCoCond_t(ptr noundef %0)
  %.not7 = icmp eq ptr %2, null
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %3 = phi ptr [ %10, %.lr.ph ], [ %2, %1 ]
  %4 = getelementptr inbounds i8, ptr %3, i64 24
  tail call void @_Z14RemoveFromLinkI15stTimeoutItem_t19stTimeoutItemLink_tEvPT_(ptr noundef nonnull %4)
  %5 = tail call noundef ptr @_Z22co_get_curr_thread_envv()
  %6 = getelementptr inbounds i8, ptr %5, i64 1032
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  tail call void @_Z7AddTailI15stTimeoutItem_t19stTimeoutItemLink_tEvPT0_PT_(ptr noundef %9, ptr noundef nonnull %4)
  %10 = tail call noundef ptr @_Z11co_cond_popP10stCoCond_t(ptr noundef %0)
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  ret i32 0
}

attributes #0 = { 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 #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 = { 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, !10, i64 1032}
!6 = !{!"_ZTS16stCoRoutineEnv_t", !7, i64 0, !9, i64 1024, !10, i64 1032, !10, i64 1040, !10, i64 1048}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"_ZTS11stCoEpoll_t", !9, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}


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