; LLVM IR from kmilo17pet/QuarkTS-cpp :: check/main.ll (Z17idleTask_CallbackRN3qOS9taskEventE)

; 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.qOS::co::coContext" = type { i32, %"class.qOS::timer" }
%"class.qOS::timer" = type { ptr, i64, i64 }

@_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx = external hidden global %"class.qOS::co::coContext", align 8
@_ZGVZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx = external hidden global i64, align 8
@__dso_handle = external hidden global i8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z17idleTask_CallbackRN3qOS9taskEventE(ptr noundef nonnull align 8 dereferenceable(48) %0) #0 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call noundef zeroext i1 @_ZNK3qOS9taskEvent9firstCallEv(ptr noundef nonnull align 8 dereferenceable(48) %5) #2
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  br label %8

8:                                                ; preds = %7, %1
  call void @_ZN3qOS2co7reenterEv() #2
  %9 = load atomic i8, ptr @_ZGVZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx acquire, align 8
  %10 = icmp eq i8 %9, 0
  br i1 %10, label %11, label %17, !prof !9

11:                                               ; preds = %8
  %12 = call i32 @__cxa_guard_acquire(ptr @_ZGVZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx) #2
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %11
  invoke void @_ZN3qOS2co9coContextC2Ev(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx)
          to label %15 unwind label %22

15:                                               ; preds = %14
  %16 = call i32 @__cxa_atexit(ptr @_ZN3qOS2co9coContextD2Ev, ptr @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx, ptr @__dso_handle) #2
  call void @__cxa_guard_release(ptr @_ZGVZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx) #2
  br label %17

17:                                               ; preds = %15, %11, %8
  call void @_ZN3qOS2co9coContext10saveHandleEv() #2
  br label %18

18:                                               ; preds = %46, %17
  %19 = call noundef zeroext i1 @_ZNK3qOS2co9coContextneEi(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx, i32 noundef -1)
  br i1 %19, label %20, label %48

20:                                               ; preds = %18
  br i1 false, label %21, label %27

21:                                               ; preds = %20
  br label %26

22:                                               ; preds = %14
  %23 = landingpad { ptr, i32 }
          cleanup
  %24 = extractvalue { ptr, i32 } %23, 0
  store ptr %24, ptr %3, align 8
  %25 = extractvalue { ptr, i32 } %23, 1
  store i32 %25, ptr %4, align 4
  call void @__cxa_guard_abort(ptr @_ZGVZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx) #2
  br label %49

26:                                               ; preds = %21
  br label %46

27:                                               ; preds = %20
  br i1 false, label %28, label %30

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %41, %40, %38, %28
  br label %48

30:                                               ; preds = %27
  %31 = call noundef i32 @_ZNK3qOS2co9coContextclEv(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx)
  switch i32 %31, label %43 [
    i32 0, label %32
    i32 13, label %36
  ]

32:                                               ; preds = %30
  call void @_ZN3qOS2co5delayEm(i64 noundef 500) #2
  call void @_ZN3qOS2co9coContextclEm(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx, i64 noundef 500)
  %33 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS2co9coContextaSEi(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx, i32 noundef 13)
  br label %34

34:                                               ; preds = %32
  br i1 false, label %35, label %40

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35, %30
  %37 = call noundef zeroext i1 @_ZNK3qOS2co9coContext7timeoutEv(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx)
  br i1 %37, label %39, label %38

38:                                               ; preds = %36
  br label %29

39:                                               ; preds = %36
  br label %41

40:                                               ; preds = %34
  br label %29

41:                                               ; preds = %39
  call void @_ZN3qOS2co7restartEv() #2
  %42 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS2co9coContextaSEi(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx, i32 noundef 0)
  br label %29

43:                                               ; preds = %30
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45, %26
  %47 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS2co9coContextaSEi(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx, i32 noundef -1)
  br label %18, !llvm.loop !10

48:                                               ; preds = %29, %18
  ret void

49:                                               ; preds = %22
  %50 = load ptr, ptr %3, align 8
  %51 = load i32, ptr %4, align 4
  %52 = insertvalue { ptr, i32 } poison, ptr %50, 0
  %53 = insertvalue { ptr, i32 } %52, i32 %51, 1
  resume { ptr, i32 } %53
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3qOS9taskEvent9firstCallEv(ptr noundef nonnull align 8 dereferenceable(48)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2co7reenterEv() #1

; Function Attrs: nounwind
declare i32 @__cxa_guard_acquire(ptr) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS2co9coContextC2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2co9coContextD2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1 align 2

; Function Attrs: nounwind
declare i32 @__cxa_atexit(ptr, ptr, ptr) #2

; Function Attrs: nounwind
declare void @__cxa_guard_abort(ptr) #2

; Function Attrs: nounwind
declare void @__cxa_guard_release(ptr) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2co9coContext10saveHandleEv() #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3qOS2co9coContextneEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3qOS2co9coContextclEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2co5delayEm(i64 noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2co9coContextclEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS2co9coContextaSEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3qOS2co9coContext7timeoutEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2co7restartEv() #1

attributes #0 = { 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 #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 = { 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 = !{!"branch_weights", i32 1, i32 1048575}
!10 = distinct !{!10, !11}
!11 = !{!"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"

%"class.qOS::co::coContext" = type { i32, %"class.qOS::timer" }
%"class.qOS::timer" = type { ptr, i64, i64 }

@_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx = external hidden global %"class.qOS::co::coContext", align 8
@_ZGVZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx = external hidden global i64, align 8
@__dso_handle = external hidden global i8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z17idleTask_CallbackRN3qOS9taskEventE(ptr noundef nonnull align 8 dereferenceable(48) %0) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %2 = tail call noundef zeroext i1 @_ZNK3qOS9taskEvent9firstCallEv(ptr noundef nonnull align 8 dereferenceable(48) %0) #3
  tail call void @_ZN3qOS2co7reenterEv() #3
  %3 = load atomic i8, ptr @_ZGVZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx acquire, align 8
  %4 = icmp eq i8 %3, 0
  br i1 %4, label %5, label %10, !prof !5

5:                                                ; preds = %1
  %6 = tail call i32 @__cxa_guard_acquire(ptr nonnull @_ZGVZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx) #3
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %10, label %7

7:                                                ; preds = %5
  invoke void @_ZN3qOS2co9coContextC2Ev(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx)
          to label %8 unwind label %12

8:                                                ; preds = %7
  %9 = tail call i32 @__cxa_atexit(ptr nonnull @_ZN3qOS2co9coContextD2Ev, ptr nonnull @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx, ptr nonnull @__dso_handle) #3
  tail call void @__cxa_guard_release(ptr nonnull @_ZGVZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx) #3
  br label %10

10:                                               ; preds = %8, %5, %1
  tail call void @_ZN3qOS2co9coContext10saveHandleEv() #3
  %11 = tail call noundef zeroext i1 @_ZNK3qOS2co9coContextneEi(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx, i32 noundef -1)
  br i1 %11, label %.lr.ph, label %.loopexit

12:                                               ; preds = %7
  %13 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_guard_abort(ptr nonnull @_ZGVZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx) #3
  resume { ptr, i32 } %13

.lr.ph:                                           ; preds = %10, %19
  %14 = tail call noundef i32 @_ZNK3qOS2co9coContextclEv(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx)
  switch i32 %14, label %19 [
    i32 0, label %15
    i32 13, label %16
  ]

15:                                               ; preds = %.lr.ph
  tail call void @_ZN3qOS2co5delayEm(i64 noundef 500) #3
  tail call void @_ZN3qOS2co9coContextclEm(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx, i64 noundef 500)
  br label %.loopexit.sink.split

16:                                               ; preds = %.lr.ph
  %17 = tail call noundef zeroext i1 @_ZNK3qOS2co9coContext7timeoutEv(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx)
  br i1 %17, label %18, label %.loopexit

18:                                               ; preds = %16
  tail call void @_ZN3qOS2co7restartEv() #3
  br label %.loopexit.sink.split

19:                                               ; preds = %.lr.ph
  %20 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS2co9coContextaSEi(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx, i32 noundef -1)
  %21 = tail call noundef zeroext i1 @_ZNK3qOS2co9coContextneEi(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx, i32 noundef -1)
  br i1 %21, label %.lr.ph, label %.loopexit, !llvm.loop !6

.loopexit.sink.split:                             ; preds = %18, %15
  %.sink = phi i32 [ 13, %15 ], [ 0, %18 ]
  %22 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS2co9coContextaSEi(ptr noundef nonnull align 8 dereferenceable(32) @_ZZ17idleTask_CallbackRN3qOS9taskEventEE6co_ctx, i32 noundef %.sink)
  br label %.loopexit

.loopexit:                                        ; preds = %19, %.loopexit.sink.split, %10, %16
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3qOS9taskEvent9firstCallEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2co7reenterEv() local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare i32 @__cxa_guard_acquire(ptr) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS2co9coContextC2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2co9coContextD2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1 align 2

; Function Attrs: nofree nounwind
declare i32 @__cxa_atexit(ptr, ptr, ptr) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare void @__cxa_guard_abort(ptr) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare void @__cxa_guard_release(ptr) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2co9coContext10saveHandleEv() local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3qOS2co9coContextneEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3qOS2co9coContextclEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2co5delayEm(i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2co9coContextclEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS2co9coContextaSEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3qOS2co9coContext7timeoutEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS2co7restartEv() local_unnamed_addr #1

attributes #0 = { 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 #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 = { nofree nounwind }
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 = !{!"branch_weights", i32 1, i32 1048575}
!6 = distinct !{!6, !7}
!7 = !{!"llvm.loop.mustprogress"}


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