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

; 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.stTimeout_t = type { ptr, i32, i64, i64 }
%struct.stTimeoutItem_t = type { ptr, ptr, ptr, i64, ptr, ptr, ptr, i8 }
%struct.stTimeoutItemLink_t = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [64 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z10co_log_errPKcz(ptr noundef, ...) #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 @_Z10AddTimeoutP11stTimeout_tP15stTimeoutItem_ty(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.stTimeout_t, ptr %9, i32 0, i32 2
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %19

13:                                               ; preds = %3
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.stTimeout_t, ptr %15, i32 0, i32 2
  store i64 %14, ptr %16, align 8, !tbaa !11
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.stTimeout_t, ptr %17, i32 0, i32 3
  store i64 0, ptr %18, align 8, !tbaa !14
  br label %19

19:                                               ; preds = %13, %3
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.stTimeout_t, ptr %21, i32 0, i32 2
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = icmp ult i64 %20, %23
  br i1 %24, label %25, label %30

25:                                               ; preds = %19
  %26 = load i64, ptr %7, align 8, !tbaa !9
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.stTimeout_t, ptr %27, i32 0, i32 2
  %29 = load i64, ptr %28, align 8, !tbaa !11
  call void (ptr, ...) @_Z10co_log_errPKcz(ptr noundef @.str, i32 noundef 388, i64 noundef %26, i64 noundef %29)
  store i32 390, ptr %4, align 4
  br label %81

30:                                               ; preds = %19
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.stTimeoutItem_t, ptr %31, i32 0, i32 3
  %33 = load i64, ptr %32, align 8, !tbaa !15
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %35 = icmp ult i64 %33, %34
  br i1 %35, label %36, label %44

36:                                               ; preds = %30
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.stTimeoutItem_t, ptr %37, i32 0, i32 3
  %39 = load i64, ptr %38, align 8, !tbaa !15
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.stTimeout_t, ptr %41, i32 0, i32 2
  %43 = load i64, ptr %42, align 8, !tbaa !11
  call void (ptr, ...) @_Z10co_log_errPKcz(ptr noundef @.str.1, i32 noundef 395, i64 noundef %39, i64 noundef %40, i64 noundef %43)
  store i32 397, ptr %4, align 4
  br label %81

44:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.stTimeoutItem_t, ptr %45, i32 0, i32 3
  %47 = load i64, ptr %46, align 8, !tbaa !15
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.stTimeout_t, ptr %48, i32 0, i32 2
  %50 = load i64, ptr %49, align 8, !tbaa !11
  %51 = sub i64 %47, %50
  store i64 %51, ptr %8, align 8, !tbaa !9
  %52 = load i64, ptr %8, align 8, !tbaa !9
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.stTimeout_t, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 8, !tbaa !18
  %56 = sext i32 %55 to i64
  %57 = icmp uge i64 %52, %56
  br i1 %57, label %58, label %65

58:                                               ; preds = %44
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.stTimeout_t, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 8, !tbaa !18
  %62 = sub nsw i32 %61, 1
  %63 = sext i32 %62 to i64
  store i64 %63, ptr %8, align 8, !tbaa !9
  %64 = load i64, ptr %8, align 8, !tbaa !9
  call void (ptr, ...) @_Z10co_log_errPKcz(ptr noundef @.str.2, i32 noundef 405, i64 noundef %64)
  br label %65

65:                                               ; preds = %58, %44
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.stTimeout_t, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !19
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.stTimeout_t, ptr %69, i32 0, i32 3
  %71 = load i64, ptr %70, align 8, !tbaa !14
  %72 = load i64, ptr %8, align 8, !tbaa !9
  %73 = add i64 %71, %72
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.stTimeout_t, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 8, !tbaa !18
  %77 = sext i32 %76 to i64
  %78 = urem i64 %73, %77
  %79 = getelementptr inbounds %struct.stTimeoutItemLink_t, ptr %68, i64 %78
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_Z7AddTailI15stTimeoutItem_t19stTimeoutItemLink_tEvPT0_PT_(ptr noundef %79, ptr noundef %80)
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %81

81:                                               ; preds = %65, %36, %25
  %82 = load i32, ptr %4, align 4
  ret i32 %82
}

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

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 = { 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 = { 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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTS11stTimeout_t", !6, i64 0, !13, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 24}
!15 = !{!16, !10, i64 24}
!16 = !{!"_ZTS15stTimeoutItem_t", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !17, i64 56}
!17 = !{!"bool", !7, i64 0}
!18 = !{!12, !13, i64 8}
!19 = !{!12, !6, 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"

%struct.stTimeoutItemLink_t = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [64 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [35 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 398) i32 @_Z10AddTimeoutP11stTimeout_tP15stTimeoutItem_ty(ptr nocapture noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %.thread, label %8

.thread:                                          ; preds = %3
  store i64 %2, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 0, ptr %7, align 8, !tbaa !12
  br label %11

8:                                                ; preds = %3
  %9 = icmp ugt i64 %5, %2
  br i1 %9, label %10, label %11

10:                                               ; preds = %8
  tail call void (ptr, ...) @_Z10co_log_errPKcz(ptr noundef nonnull @.str, i32 noundef 388, i64 noundef %2, i64 noundef %5)
  br label %32

11:                                               ; preds = %.thread, %8
  %12 = phi i64 [ %2, %.thread ], [ %5, %8 ]
  %13 = getelementptr inbounds i8, ptr %1, i64 24
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = icmp ult i64 %14, %2
  br i1 %15, label %16, label %17

16:                                               ; preds = %11
  tail call void (ptr, ...) @_Z10co_log_errPKcz(ptr noundef nonnull @.str.1, i32 noundef 395, i64 noundef %14, i64 noundef %2, i64 noundef %12)
  br label %32

17:                                               ; preds = %11
  %18 = sub i64 %14, %12
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !16
  %21 = sext i32 %20 to i64
  %.not = icmp ult i64 %18, %21
  br i1 %.not, label %25, label %22

22:                                               ; preds = %17
  %23 = add nsw i32 %20, -1
  %24 = sext i32 %23 to i64
  tail call void (ptr, ...) @_Z10co_log_errPKcz(ptr noundef nonnull @.str.2, i32 noundef 405, i64 noundef %24)
  %.pre = load i32, ptr %19, align 8, !tbaa !16
  %.pre31 = sext i32 %.pre to i64
  br label %25

25:                                               ; preds = %22, %17
  %.pre-phi = phi i64 [ %.pre31, %22 ], [ %21, %17 ]
  %.0 = phi i64 [ %24, %22 ], [ %18, %17 ]
  %26 = load ptr, ptr %0, align 8, !tbaa !17
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  %28 = load i64, ptr %27, align 8, !tbaa !12
  %29 = add i64 %28, %.0
  %30 = urem i64 %29, %.pre-phi
  %31 = getelementptr inbounds %struct.stTimeoutItemLink_t, ptr %26, i64 %30
  tail call void @_Z7AddTailI15stTimeoutItem_t19stTimeoutItemLink_tEvPT0_PT_(ptr noundef %31, ptr noundef nonnull %1)
  br label %32

32:                                               ; preds = %25, %16, %10
  %.024 = phi i32 [ 390, %10 ], [ 397, %16 ], [ 0, %25 ]
  ret i32 %.024
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z7AddTailI15stTimeoutItem_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, !11, i64 16}
!6 = !{!"_ZTS11stTimeout_t", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!6, !11, i64 24}
!13 = !{!14, !11, i64 24}
!14 = !{!"_ZTS15stTimeoutItem_t", !7, i64 0, !7, i64 8, !7, i64 16, !11, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !15, i64 56}
!15 = !{!"bool", !8, i64 0}
!16 = !{!6, !10, i64 8}
!17 = !{!6, !7, i64 0}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass