; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/task.ll (ZN3qOS4task16queueCheckEventsEv)

; 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::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 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3qOS4task7getFlagEj(ptr noundef nonnull align 8 dereferenceable(150), i32 noundef) #0 align 2

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

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %14 = call noundef zeroext i1 @_ZNK3qOS4task7getFlagEj(ptr noundef nonnull align 8 dereferenceable(150) %9, i32 noundef 8) #3
  %15 = zext i1 %14 to i8
  store i8 %15, ptr %4, align 1, !tbaa !17
  %16 = call noundef zeroext i1 @_ZNK3qOS4task7getFlagEj(ptr noundef nonnull align 8 dereferenceable(150) %9, i32 noundef 16) #3
  %17 = zext i1 %16 to i8
  store i8 %17, ptr %5, align 1, !tbaa !17
  %18 = call noundef zeroext i1 @_ZNK3qOS4task7getFlagEj(ptr noundef nonnull align 8 dereferenceable(150) %9, i32 noundef 4) #3
  %19 = zext i1 %18 to i8
  store i8 %19, ptr %6, align 1, !tbaa !17
  %20 = call noundef zeroext i1 @_ZNK3qOS4task7getFlagEj(ptr noundef nonnull align 8 dereferenceable(150) %9, i32 noundef 32) #3
  %21 = zext i1 %20 to i8
  store i8 %21, ptr %7, align 1, !tbaa !17
  %22 = getelementptr inbounds %"class.qOS::task", ptr %9, i32 0, i32 5
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = call noundef i64 @_ZNK3qOS5queue5countEv(ptr noundef nonnull align 8 dereferenceable(64) %23) #3
  store i64 %24, ptr %8, align 8, !tbaa !19
  %25 = load i8, ptr %4, align 1, !tbaa !17, !range !20, !noundef !21
  %26 = trunc i8 %25 to i1
  br i1 %26, label %27, label %32

27:                                               ; preds = %13
  %28 = getelementptr inbounds %"class.qOS::task", ptr %9, i32 0, i32 5
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = call noundef zeroext i1 @_ZNK3qOS5queue6isFullEv(ptr noundef nonnull align 8 dereferenceable(64) %29) #3
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  store i8 5, ptr %3, align 1, !tbaa !9
  br label %60

32:                                               ; preds = %27, %13
  %33 = load i8, ptr %5, align 1, !tbaa !17, !range !20, !noundef !21
  %34 = trunc i8 %33 to i1
  br i1 %34, label %35, label %41

35:                                               ; preds = %32
  %36 = load i64, ptr %8, align 8, !tbaa !19
  %37 = getelementptr inbounds %"class.qOS::task", ptr %9, i32 0, i32 6
  %38 = load i64, ptr %37, align 8, !tbaa !22
  %39 = icmp uge i64 %36, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %35
  store i8 6, ptr %3, align 1, !tbaa !9
  br label %59

41:                                               ; preds = %35, %32
  %42 = load i8, ptr %6, align 1, !tbaa !17, !range !20, !noundef !21
  %43 = trunc i8 %42 to i1
  br i1 %43, label %44, label %48

44:                                               ; preds = %41
  %45 = load i64, ptr %8, align 8, !tbaa !19
  %46 = icmp ugt i64 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  store i8 4, ptr %3, align 1, !tbaa !9
  br label %58

48:                                               ; preds = %44, %41
  %49 = load i8, ptr %7, align 1, !tbaa !17, !range !20, !noundef !21
  %50 = trunc i8 %49 to i1
  br i1 %50, label %51, label %56

51:                                               ; preds = %48
  %52 = getelementptr inbounds %"class.qOS::task", ptr %9, i32 0, i32 5
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = call noundef zeroext i1 @_ZNK3qOS5queue7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(64) %53) #3
  br i1 %54, label %55, label %56

55:                                               ; preds = %51
  store i8 7, ptr %3, align 1, !tbaa !9
  br label %57

56:                                               ; preds = %51, %48
  br label %57

57:                                               ; preds = %56, %55
  br label %58

58:                                               ; preds = %57, %47
  br label %59

59:                                               ; preds = %58, %40
  br label %60

60:                                               ; preds = %59, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  br label %61

61:                                               ; preds = %60, %1
  %62 = load i8, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  ret i8 %62
}

; Function Attrs: nounwind
declare noundef i64 @_ZNK3qOS5queue5countEv(ptr noundef nonnull align 8 dereferenceable(64)) #2

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZNK3qOS5queue6isFullEv(ptr noundef nonnull align 8 dereferenceable(64)) #2

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZNK3qOS5queue7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(64)) #2

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 = { 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 = !{!"_ZTSN3qOS7triggerE", !7, i64 0}
!11 = !{!12, !6, i64 64}
!12 = !{!"_ZTSN3qOS4taskE", !13, i64 0, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !14, i64 72, !7, i64 80, !15, i64 96, !16, i64 120, !14, i64 128, !16, i64 136, !16, i64 140, !16, i64 144, !7, i64 148, !10, i64 149}
!13 = !{!"_ZTSN3qOS4nodeE", !6, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTSN3qOS5timerE", !14, i64 8, !14, i64 16}
!16 = !{!"int", !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"bool", !7, i64 0}
!19 = !{!14, !14, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!12, !14, i64 72}


; 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
declare dso_local noundef zeroext i1 @_ZNK3qOS4task7getFlagEj(ptr noundef nonnull align 8 dereferenceable(150), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext range(i8 0, 8) i8 @_ZN3qOS4task16queueCheckEventsEv(ptr noundef nonnull align 8 dereferenceable(150) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 64
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %22, label %4

4:                                                ; preds = %1
  %5 = tail call noundef zeroext i1 @_ZNK3qOS4task7getFlagEj(ptr noundef nonnull align 8 dereferenceable(150) %0, i32 noundef 8) #2
  %6 = tail call noundef zeroext i1 @_ZNK3qOS4task7getFlagEj(ptr noundef nonnull align 8 dereferenceable(150) %0, i32 noundef 16) #2
  %7 = tail call noundef zeroext i1 @_ZNK3qOS4task7getFlagEj(ptr noundef nonnull align 8 dereferenceable(150) %0, i32 noundef 4) #2
  %8 = tail call noundef zeroext i1 @_ZNK3qOS4task7getFlagEj(ptr noundef nonnull align 8 dereferenceable(150) %0, i32 noundef 32) #2
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = tail call noundef i64 @_ZNK3qOS5queue5countEv(ptr noundef nonnull align 8 dereferenceable(64) %9) #2
  br i1 %5, label %11, label %14

11:                                               ; preds = %4
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = tail call noundef zeroext i1 @_ZNK3qOS5queue6isFullEv(ptr noundef nonnull align 8 dereferenceable(64) %12) #2
  br i1 %13, label %22, label %14

14:                                               ; preds = %11, %4
  %15 = getelementptr inbounds i8, ptr %0, i64 72
  %16 = load i64, ptr %15, align 8
  %.not8 = icmp uge i64 %10, %16
  %or.cond11.not = select i1 %6, i1 %.not8, i1 false
  br i1 %or.cond11.not, label %22, label %17

17:                                               ; preds = %14
  %18 = icmp ne i64 %10, 0
  %or.cond = and i1 %7, %18
  %.not12 = xor i1 %8, true
  %brmerge = or i1 %or.cond, %.not12
  %.mux = select i1 %or.cond, i8 4, i8 0
  br i1 %brmerge, label %22, label %19

19:                                               ; preds = %17
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = tail call noundef zeroext i1 @_ZNK3qOS5queue7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(64) %20) #2
  %spec.select = select i1 %21, i8 7, i8 0
  br label %22

22:                                               ; preds = %19, %11, %14, %17, %1
  %.1 = phi i8 [ 0, %1 ], [ 5, %11 ], [ 6, %14 ], [ %.mux, %17 ], [ %spec.select, %19 ]
  ret i8 %.1
}

; Function Attrs: nounwind
declare noundef i64 @_ZNK3qOS5queue5countEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #1

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

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZNK3qOS5queue7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(64)) 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, !8, i64 64}
!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}


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