; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/kernel.ll (ZN3qOS4core19handleInputWatchersEv)

; 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::listIterator" = type { ptr, ptr, ptr, ptr }
%"class.qOS::core" = type { %"class.qOS::taskEvent", %"class.qOS::task", ptr, ptr, [10 x %"struct.qOS::pq::queueStack_t"], %"class.qOS::prioQueue", i32, %"struct.qOS::notificationSpreader_t", i64, [5 x %"class.qOS::list"], ptr, ptr, %"class.qOS::list" }
%"class.qOS::taskEvent" = type { ptr, i8, i8, i8, i8, i64, ptr, ptr, ptr }
%"class.qOS::task" = type <{ %"class.qOS::node", ptr, ptr, ptr, ptr, ptr, i64, [11 x i8], [5 x i8], %"class.qOS::timer", i32, [4 x i8], i64, i32, i32, i32, i8, i8, [2 x i8] }>
%"class.qOS::node" = type { ptr, ptr, ptr, ptr }
%"class.qOS::timer" = type { ptr, i64, i64 }
%"struct.qOS::pq::queueStack_t" = type { ptr, ptr }
%"class.qOS::prioQueue" = type { ptr, i32, ptr, ptr, i64 }
%"struct.qOS::notificationSpreader_t" = type { i8, ptr }
%"class.qOS::list" = type { %"class.qOS::node", ptr, ptr, i64 }

; 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
declare void @_ZN3qOS4list5beginEv(ptr dead_on_unwind writable sret(%"class.qOS::listIterator") align 8, ptr noundef nonnull align 8 dereferenceable(56)) #1

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZNK3qOS12listIterator8untilEndEv(ptr noundef nonnull align 8 dereferenceable(32)) #1

; Function Attrs: nounwind
declare noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS12listIteratorppEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS4core19handleInputWatchersEv(ptr noundef nonnull align 8 dereferenceable(800) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca %"class.qOS::listIterator", align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr %3) #4
  %6 = getelementptr inbounds %"class.qOS::core", ptr %5, i32 0, i32 12
  call void @_ZN3qOS4list5beginEv(ptr dead_on_unwind writable sret(%"class.qOS::listIterator") align 8 %3, ptr noundef nonnull align 8 dereferenceable(56) %6) #4
  br label %7

7:                                                ; preds = %14, %1
  %8 = call noundef zeroext i1 @_ZNK3qOS12listIterator8untilEndEv(ptr noundef nonnull align 8 dereferenceable(32) %3) #4
  br i1 %8, label %10, label %9

9:                                                ; preds = %7
  call void @_ZN3qOS12listIteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %3) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #4
  br label %16

10:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %11 = call noundef ptr @_ZN3qOS12listIterator3getIPNS_5input7watcherEEET_v(ptr noundef nonnull align 8 dereferenceable(32) %3) #4
  store ptr %11, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call noundef zeroext i1 @_ZN3qOS5input7watcher5watchEv(ptr noundef nonnull align 8 dereferenceable(200) %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %14

14:                                               ; preds = %10
  %15 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS12listIteratorppEi(ptr noundef nonnull align 8 dereferenceable(32) %3, i32 noundef 0) #4
  br label %7, !llvm.loop !9

16:                                               ; preds = %9
  ret void
}

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

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN3qOS5input7watcher5watchEv(ptr noundef nonnull align 8 dereferenceable(200)) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"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::listIterator" = type { ptr, ptr, ptr, ptr }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare void @_ZN3qOS4list5beginEv(ptr dead_on_unwind writable sret(%"class.qOS::listIterator") align 8, ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #1

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZNK3qOS12listIterator8untilEndEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1

; Function Attrs: nounwind
declare noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS12listIteratorppEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS4core19handleInputWatchersEv(ptr noundef nonnull align 8 dereferenceable(800) %0) local_unnamed_addr #2 align 2 {
  %2 = alloca %"class.qOS::listIterator", align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #4
  %3 = getelementptr inbounds i8, ptr %0, i64 744
  call void @_ZN3qOS4list5beginEv(ptr dead_on_unwind nonnull writable sret(%"class.qOS::listIterator") align 8 %2, ptr noundef nonnull align 8 dereferenceable(56) %3) #4
  %4 = call noundef zeroext i1 @_ZNK3qOS12listIterator8untilEndEv(ptr noundef nonnull align 8 dereferenceable(32) %2) #4
  br i1 %4, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %1
  call void @_ZN3qOS12listIteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %2) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #4
  ret void

.lr.ph:                                           ; preds = %1, %.lr.ph
  %5 = call noundef ptr @_ZN3qOS12listIterator3getIPNS_5input7watcherEEET_v(ptr noundef nonnull align 8 dereferenceable(32) %2) #4
  %6 = call noundef zeroext i1 @_ZN3qOS5input7watcher5watchEv(ptr noundef nonnull align 8 dereferenceable(200) %5) #4
  %7 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS12listIteratorppEi(ptr noundef nonnull align 8 dereferenceable(32) %2, i32 noundef 0) #4
  %8 = call noundef zeroext i1 @_ZNK3qOS12listIterator8untilEndEv(ptr noundef nonnull align 8 dereferenceable(32) %2) #4
  br i1 %8, label %.lr.ph, label %._crit_edge, !llvm.loop !5
}

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

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN3qOS5input7watcher5watchEv(ptr noundef nonnull align 8 dereferenceable(200)) local_unnamed_addr #1

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


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