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

; 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: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i64 @_ZL9GetTickMSv() #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z10AddTimeoutP11stTimeout_tP15stTimeoutItem_ty(ptr noundef, ptr noundef, i64 noundef) #4

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11co_yield_ctv() #4

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z17co_cond_timedwaitP10stCoCond_ti(ptr noundef %0, i32 noundef %1) #4 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %10 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 88) #7
  store ptr %10, ptr %6, align 8, !tbaa !5
  %11 = call noundef ptr @_Z15GetCurrThreadCov()
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.stCoCondItem_t, ptr %12, i32 0, i32 3
  %14 = getelementptr inbounds %struct.stTimeoutItem_t, ptr %13, i32 0, i32 6
  store ptr %11, ptr %14, align 8, !tbaa !11
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.stCoCondItem_t, ptr %15, i32 0, i32 3
  %17 = getelementptr inbounds %struct.stTimeoutItem_t, ptr %16, i32 0, i32 5
  store ptr @_ZL20OnSignalProcessEventP15stTimeoutItem_t, ptr %17, align 8, !tbaa !16
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %20, label %47

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %21 = call noundef i64 @_ZL9GetTickMSv()
  store i64 %21, ptr %7, align 8, !tbaa !17
  %22 = load i64, ptr %7, align 8, !tbaa !17
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = add i64 %22, %24
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.stCoCondItem_t, ptr %26, i32 0, i32 3
  %28 = getelementptr inbounds %struct.stTimeoutItem_t, ptr %27, i32 0, i32 3
  store i64 %25, ptr %28, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %29 = call noundef ptr @_Z22co_get_curr_thread_envv()
  %30 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !19
  %32 = getelementptr inbounds %struct.stCoEpoll_t, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !21
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.stCoCondItem_t, ptr %34, i32 0, i32 3
  %36 = load i64, ptr %7, align 8, !tbaa !17
  %37 = call noundef i32 @_Z10AddTimeoutP11stTimeout_tP15stTimeoutItem_ty(ptr noundef %33, ptr noundef %35, i64 noundef %36)
  store i32 %37, ptr %8, align 4, !tbaa !9
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %20
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %41) #6
  %42 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %42, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %44

43:                                               ; preds = %20
  store i32 0, ptr %9, align 4
  br label %44

44:                                               ; preds = %43, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  %45 = load i32, ptr %9, align 4
  switch i32 %45, label %52 [
    i32 0, label %46
  ]

46:                                               ; preds = %44
  br label %47

47:                                               ; preds = %46, %2
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_Z7AddTailI14stCoCondItem_t10stCoCond_tEvPT0_PT_(ptr noundef %48, ptr noundef %49)
  call void @_Z11co_yield_ctv()
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_Z14RemoveFromLinkI14stCoCondItem_t10stCoCond_tEvPT_(ptr noundef %50)
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %51) #6
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %52

52:                                               ; preds = %47, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %53 = load i32, ptr %3, align 4
  ret i32 %53
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL20OnSignalProcessEventP15stTimeoutItem_t(ptr noundef) #4

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(0,1) "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 "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 = { 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0,1) }

!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, !6, i64 72}
!12 = !{!"_ZTS14stCoCondItem_t", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24}
!13 = !{!"_ZTS15stTimeoutItem_t", !6, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !15, i64 56}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!12, !6, i64 64}
!17 = !{!14, !14, i64 0}
!18 = !{!12, !14, i64 48}
!19 = !{!20, !6, i64 1032}
!20 = !{!"_ZTS16stCoRoutineEnv_t", !7, i64 0, !10, i64 1024, !6, i64 1032, !6, i64 1040, !6, i64 1048}
!21 = !{!22, !6, i64 8}
!22 = !{!"_ZTS11stCoEpoll_t", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !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"

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i64 @_ZL9GetTickMSv() local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z10AddTimeoutP11stTimeout_tP15stTimeoutItem_ty(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11co_yield_ctv() local_unnamed_addr #3

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z17co_cond_timedwaitP10stCoCond_ti(ptr noundef %0, i32 noundef %1) local_unnamed_addr #3 {
  %3 = tail call noalias dereferenceable_or_null(88) ptr @calloc(i64 noundef 1, i64 noundef 88) #5
  %4 = tail call noundef ptr @_Z15GetCurrThreadCov()
  %5 = getelementptr inbounds i8, ptr %3, i64 72
  store ptr %4, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 64
  store ptr @_ZL20OnSignalProcessEventP15stTimeoutItem_t, ptr %6, align 8, !tbaa !13
  %7 = icmp sgt i32 %1, 0
  br i1 %7, label %8, label %.critedge

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %3, i64 24
  %10 = tail call noundef i64 @_ZL9GetTickMSv()
  %11 = zext nneg i32 %1 to i64
  %12 = add i64 %10, %11
  %13 = getelementptr inbounds i8, ptr %3, i64 48
  store i64 %12, ptr %13, align 8, !tbaa !14
  %14 = tail call noundef ptr @_Z22co_get_curr_thread_envv()
  %15 = getelementptr inbounds i8, ptr %14, i64 1032
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !18
  %19 = tail call noundef i32 @_Z10AddTimeoutP11stTimeout_tP15stTimeoutItem_ty(ptr noundef %18, ptr noundef nonnull %9, i64 noundef %10)
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %.critedge, label %20

.critedge:                                        ; preds = %8, %2
  tail call void @_Z7AddTailI14stCoCondItem_t10stCoCond_tEvPT0_PT_(ptr noundef %0, ptr noundef nonnull %3)
  tail call void @_Z11co_yield_ctv()
  tail call void @_Z14RemoveFromLinkI14stCoCondItem_t10stCoCond_tEvPT_(ptr noundef nonnull %3)
  br label %20

20:                                               ; preds = %8, %.critedge
  %.1 = phi i32 [ 0, %.critedge ], [ %19, %8 ]
  tail call void @free(ptr noundef nonnull %3) #6
  ret i32 %.1
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL20OnSignalProcessEventP15stTimeoutItem_t(ptr noundef) #3

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

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 #5 = { nounwind allocsize(0,1) }
attributes #6 = { 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, !7, i64 72}
!6 = !{!"_ZTS14stCoCondItem_t", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS15stTimeoutItem_t", !7, i64 0, !7, i64 8, !7, i64 16, !11, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !12, i64 56}
!11 = !{!"long long", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!6, !7, i64 64}
!14 = !{!6, !11, i64 48}
!15 = !{!16, !7, i64 1032}
!16 = !{!"_ZTS16stCoRoutineEnv_t", !8, i64 0, !17, i64 1024, !7, i64 1032, !7, i64 1040, !7, i64 1048}
!17 = !{!"int", !8, i64 0}
!18 = !{!19, !7, i64 8}
!19 = !{!"_ZTS11stCoEpoll_t", !17, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}


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