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

; 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.epoll_event = type <{ i32, %union.epoll_data }>
%union.epoll_data = type { ptr }
%struct.stPollItem_t = type <{ %struct.stTimeoutItem_t, ptr, ptr, %struct.epoll_event, [4 x i8] }>
%struct.stTimeoutItem_t = type { ptr, ptr, ptr, i64, ptr, ptr, ptr, i8 }
%struct.pollfd = type { i32, i16, i16 }
%struct.stPoll_t = type <{ %struct.stTimeoutItem_t, ptr, i64, ptr, i32, i32, i32, [4 x i8] }>

; 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 @_Z16OnPollPreparePfnP15stTimeoutItem_tR11epoll_eventP19stTimeoutItemLink_t(ptr noundef %0, ptr noundef nonnull align 1 dereferenceable(12) %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %9, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.epoll_event, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 1, !tbaa !9
  %13 = call noundef signext i16 @_ZL15EpollEvent2Pollj(i32 noundef %12)
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.stPollItem_t, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = getelementptr inbounds %struct.pollfd, ptr %16, i32 0, i32 2
  store i16 %13, ptr %17, align 2, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.stPollItem_t, ptr %18, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !20
  store ptr %20, ptr %8, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.stPoll_t, ptr %21, i32 0, i32 6
  %23 = load i32, ptr %22, align 8, !tbaa !21
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %22, align 8, !tbaa !21
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.stPoll_t, ptr %25, i32 0, i32 4
  %27 = load i32, ptr %26, align 8, !tbaa !24
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %35, label %29

29:                                               ; preds = %3
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.stPoll_t, ptr %30, i32 0, i32 4
  store i32 1, ptr %31, align 8, !tbaa !24
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_Z14RemoveFromLinkI15stTimeoutItem_t19stTimeoutItemLink_tEvPT_(ptr noundef %32)
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_Z7AddTailI8stPoll_t19stTimeoutItemLink_tEvPT0_PT_(ptr noundef %33, ptr noundef %34)
  br label %35

35:                                               ; preds = %29, %3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef signext i16 @_ZL15EpollEvent2Pollj(i32 noundef) #2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z7AddTailI8stPoll_t19stTimeoutItemLink_tEvPT0_PT_(ptr noundef, ptr noundef) #3

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 = { 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 #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, !11, i64 0}
!10 = !{!"_ZTS11epoll_event", !11, i64 0, !7, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 64}
!13 = !{!"_ZTS12stPollItem_t", !14, i64 0, !6, i64 64, !6, i64 72, !10, i64 80}
!14 = !{!"_ZTS15stTimeoutItem_t", !6, i64 0, !6, i64 8, !6, i64 16, !15, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !16, i64 56}
!15 = !{!"long long", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!18, !19, i64 6}
!18 = !{!"_ZTS6pollfd", !11, i64 0, !19, i64 4, !19, i64 6}
!19 = !{!"short", !7, i64 0}
!20 = !{!13, !6, i64 72}
!21 = !{!22, !11, i64 96}
!22 = !{!"_ZTS8stPoll_t", !14, i64 0, !6, i64 64, !23, i64 72, !6, i64 80, !11, i64 88, !11, i64 92, !11, i64 96}
!23 = !{!"long", !7, i64 0}
!24 = !{!22, !11, i64 88}


; 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: mustprogress nounwind uwtable
define dso_local void @_Z16OnPollPreparePfnP15stTimeoutItem_tR11epoll_eventP19stTimeoutItemLink_t(ptr nocapture noundef readonly %0, ptr nocapture noundef nonnull readonly align 1 dereferenceable(12) %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %1, align 1, !tbaa !5
  %5 = tail call noundef signext i16 @_ZL15EpollEvent2Pollj(i32 noundef %4)
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = load ptr, ptr %6, align 8, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %7, i64 6
  store i16 %5, ptr %8, align 2, !tbaa !16
  %9 = getelementptr inbounds i8, ptr %0, i64 72
  %10 = load ptr, ptr %9, align 8, !tbaa !19
  %11 = getelementptr inbounds i8, ptr %10, i64 96
  %12 = load i32, ptr %11, align 8, !tbaa !20
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr %11, align 8, !tbaa !20
  %14 = getelementptr inbounds i8, ptr %10, i64 88
  %15 = load i32, ptr %14, align 8, !tbaa !23
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %16, label %17

16:                                               ; preds = %3
  store i32 1, ptr %14, align 8, !tbaa !23
  tail call void @_Z14RemoveFromLinkI15stTimeoutItem_t19stTimeoutItemLink_tEvPT_(ptr noundef nonnull %10)
  tail call void @_Z7AddTailI8stPoll_t19stTimeoutItemLink_tEvPT0_PT_(ptr noundef %2, ptr noundef nonnull %10)
  br label %17

17:                                               ; preds = %16, %3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef signext i16 @_ZL15EpollEvent2Pollj(i32 noundef) local_unnamed_addr #0

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

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

attributes #0 = { 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 = { 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" }

!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, !7, i64 0}
!6 = !{!"_ZTS11epoll_event", !7, i64 0, !8, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !13, i64 64}
!11 = !{!"_ZTS12stPollItem_t", !12, i64 0, !13, i64 64, !13, i64 72, !6, i64 80}
!12 = !{!"_ZTS15stTimeoutItem_t", !13, i64 0, !13, i64 8, !13, i64 16, !14, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !15, i64 56}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"long long", !8, i64 0}
!15 = !{!"bool", !8, i64 0}
!16 = !{!17, !18, i64 6}
!17 = !{!"_ZTS6pollfd", !7, i64 0, !18, i64 4, !18, i64 6}
!18 = !{!"short", !8, i64 0}
!19 = !{!11, !13, i64 72}
!20 = !{!21, !7, i64 96}
!21 = !{!"_ZTS8stPoll_t", !12, i64 0, !13, i64 64, !22, i64 72, !13, i64 80, !7, i64 88, !7, i64 92, !7, i64 96}
!22 = !{!"long", !8, i64 0}
!23 = !{!21, !7, i64 88}


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