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

; 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::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: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3qOS4core6notifyENS_10notifyModeERNS_4taskEPv(ptr noundef nonnull align 8 dereferenceable(800) %0, i8 noundef zeroext %1, ptr noundef nonnull align 8 dereferenceable(150) %2, ptr noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  store i8 0, ptr %9, align 1, !tbaa !11
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = getelementptr inbounds %"class.qOS::core", ptr %10, i32 0, i32 1
  %13 = icmp ne ptr %11, %12
  br i1 %13, label %14, label %45

14:                                               ; preds = %4
  %15 = load i8, ptr %6, align 1, !tbaa !9
  %16 = icmp eq i8 0, %15
  br i1 %16, label %17, label %33

17:                                               ; preds = %14
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.qOS::task", ptr %18, i32 0, i32 14
  %20 = load volatile i32, ptr %19, align 4, !tbaa !13
  %21 = icmp ult i32 %20, -2
  br i1 %21, label %22, label %32

22:                                               ; preds = %17
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %"class.qOS::task", ptr %23, i32 0, i32 14
  %25 = load volatile i32, ptr %24, align 4, !tbaa !13
  %26 = add i32 %25, 1
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %"class.qOS::task", ptr %27, i32 0, i32 14
  store volatile i32 %26, ptr %28, align 4, !tbaa !13
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.qOS::task", ptr %30, i32 0, i32 2
  store ptr %29, ptr %31, align 8, !tbaa !20
  store i8 1, ptr %9, align 1, !tbaa !11
  br label %32

32:                                               ; preds = %22, %17
  br label %44

33:                                               ; preds = %14
  %34 = load i8, ptr %6, align 1, !tbaa !9
  %35 = icmp eq i8 1, %34
  br i1 %35, label %36, label %42

36:                                               ; preds = %33
  %37 = getelementptr inbounds %"class.qOS::core", ptr %10, i32 0, i32 5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = call noundef zeroext i1 @_ZN3qOS9prioQueue6insertERNS_4taskEPv(ptr noundef nonnull align 8 dereferenceable(40) %37, ptr noundef nonnull align 8 dereferenceable(150) %38, ptr noundef %39) #3
  %41 = zext i1 %40 to i8
  store i8 %41, ptr %9, align 1, !tbaa !11
  br label %43

42:                                               ; preds = %33
  br label %43

43:                                               ; preds = %42, %36
  br label %44

44:                                               ; preds = %43, %32
  br label %45

45:                                               ; preds = %44, %4
  %46 = load i8, ptr %9, align 1, !tbaa !11, !range !21, !noundef !22
  %47 = trunc i8 %46 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  ret i1 %47
}

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN3qOS9prioQueue6insertERNS_4taskEPv(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(150), ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!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 = !{!"_ZTSN3qOS10notifyModeE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !18, i64 140}
!14 = !{!"_ZTSN3qOS4taskE", !15, i64 0, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !16, i64 72, !7, i64 80, !17, i64 96, !18, i64 120, !16, i64 128, !18, i64 136, !18, i64 140, !18, i64 144, !7, i64 148, !19, i64 149}
!15 = !{!"_ZTSN3qOS4nodeE", !6, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!"long", !7, i64 0}
!17 = !{!"_ZTSN3qOS5timerE", !16, i64 8, !16, i64 16}
!18 = !{!"int", !7, i64 0}
!19 = !{!"_ZTSN3qOS7triggerE", !7, i64 0}
!20 = !{!14, !6, i64 40}
!21 = !{i8 0, i8 2}
!22 = !{}


; 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 noundef zeroext i1 @_ZN3qOS4core6notifyENS_10notifyModeERNS_4taskEPv(ptr noundef nonnull align 8 dereferenceable(800) %0, i8 noundef zeroext %1, ptr noundef nonnull align 8 dereferenceable(150) %2, ptr noundef %3) local_unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %.not = icmp eq ptr %5, %2
  br i1 %.not, label %18, label %6

6:                                                ; preds = %4
  switch i8 %1, label %18 [
    i8 0, label %7
    i8 1, label %15
  ]

7:                                                ; preds = %6
  %8 = getelementptr inbounds i8, ptr %2, i64 140
  %9 = load volatile i32, ptr %8, align 4, !tbaa !5
  %10 = icmp ult i32 %9, -2
  br i1 %10, label %11, label %18

11:                                               ; preds = %7
  %12 = load volatile i32, ptr %8, align 4, !tbaa !5
  %13 = add i32 %12, 1
  store volatile i32 %13, ptr %8, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %2, i64 40
  store ptr %3, ptr %14, align 8, !tbaa !15
  br label %18

15:                                               ; preds = %6
  %16 = getelementptr inbounds i8, ptr %0, i64 376
  %17 = tail call noundef zeroext i1 @_ZN3qOS9prioQueue6insertERNS_4taskEPv(ptr noundef nonnull align 8 dereferenceable(40) %16, ptr noundef nonnull align 8 dereferenceable(150) %2, ptr noundef %3) #2
  br label %18

18:                                               ; preds = %6, %11, %7, %15, %4
  %.0 = phi i1 [ true, %11 ], [ false, %7 ], [ %17, %15 ], [ false, %4 ], [ false, %6 ]
  ret i1 %.0
}

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZN3qOS9prioQueue6insertERNS_4taskEPv(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(150), 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 = { 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 = { 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, !13, i64 140}
!6 = !{!"_ZTSN3qOS4taskE", !7, i64 0, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !11, i64 72, !9, i64 80, !12, i64 96, !13, i64 120, !11, i64 128, !13, i64 136, !13, i64 140, !13, i64 144, !9, i64 148, !14, i64 149}
!7 = !{!"_ZTSN3qOS4nodeE", !8, i64 8, !8, i64 16, !8, i64 24}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"_ZTSN3qOS5timerE", !11, i64 8, !11, i64 16}
!13 = !{!"int", !9, i64 0}
!14 = !{!"_ZTSN3qOS7triggerE", !9, i64 0}
!15 = !{!6, !8, i64 40}


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