; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/prioqueue.ll (ZNK3qOS9prioQueue12isTaskInsideERKNS_4taskE)

; 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::prioQueue" = type { ptr, i32, ptr, ptr, i64 }
%"struct.qOS::pq::queueStack_t" = type { ptr, ptr }

; Function Attrs: nounwind
declare void @_ZN3qOS8critical5enterEv() #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: nounwind
declare void @_ZN3qOS8critical4exitEv() #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZNK3qOS9prioQueue12isTaskInsideERKNS_4taskE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(150) %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  store i8 0, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %10 = getelementptr inbounds %"class.qOS::prioQueue", ptr %9, i32 0, i32 1
  %11 = load volatile i32, ptr %10, align 8, !tbaa !11
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr %6, align 4, !tbaa !15
  %13 = load i32, ptr %6, align 4, !tbaa !15
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %15, label %38

15:                                               ; preds = %2
  call void @_ZN3qOS8critical5enterEv() #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !15
  br label %16

16:                                               ; preds = %33, %15
  %17 = load i32, ptr %7, align 4, !tbaa !15
  %18 = load i32, ptr %6, align 4, !tbaa !15
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %8, align 4
  br label %36

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %"class.qOS::prioQueue", ptr %9, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = load i32, ptr %7, align 4, !tbaa !15
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %24, i64 %26
  %28 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  %30 = icmp eq ptr %22, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %21
  store i8 1, ptr %5, align 1, !tbaa !9
  store i32 2, ptr %8, align 4
  br label %36

32:                                               ; preds = %21
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %7, align 4, !tbaa !15
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !15
  br label %16, !llvm.loop !19

36:                                               ; preds = %31, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %37

37:                                               ; preds = %36
  call void @_ZN3qOS8critical4exitEv() #3
  br label %38

38:                                               ; preds = %37, %2
  %39 = load i8, ptr %5, align 1, !tbaa !9, !range !21, !noundef !22
  %40 = trunc i8 %39 to i1
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  ret i1 %40
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"bool", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTSN3qOS9prioQueueE", !13, i64 8, !6, i64 16, !6, i64 24, !14, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !6, i64 24}
!17 = !{!18, !6, i64 0}
!18 = !{!"_ZTSN3qOS2pq12queueStack_tE", !6, i64 0, !6, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!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"

%"struct.qOS::pq::queueStack_t" = type { ptr, ptr }

; Function Attrs: nounwind
declare void @_ZN3qOS8critical5enterEv() local_unnamed_addr #0

; Function Attrs: nounwind
declare void @_ZN3qOS8critical4exitEv() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZNK3qOS9prioQueue12isTaskInsideERKNS_4taskE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull readnone align 8 dereferenceable(150) %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load volatile i32, ptr %3, align 8, !tbaa !5
  %5 = icmp sgt i32 %4, -1
  br i1 %5, label %6, label %17

6:                                                ; preds = %2
  tail call void @_ZN3qOS8critical5enterEv() #2
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = zext nneg i32 %4 to i64
  %10 = add nuw i32 %4, 1
  %wide.trip.count = zext i32 %10 to i64
  %11 = load ptr, ptr %8, align 8, !tbaa !13
  %12 = icmp eq ptr %11, %1
  br i1 %12, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %13
  %indvars.iv11 = phi i64 [ %indvars.iv.next, %13 ], [ 0, %6 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv11, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %13, !llvm.loop !15

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %8, i64 %indvars.iv.next
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = icmp eq ptr %15, %1
  br i1 %16, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %13, %.lr.ph
  %.not.le = icmp ult i64 %indvars.iv11, %9
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %6
  %.not.lcssa = phi i1 [ true, %6 ], [ %.not.le, %._crit_edge.loopexit ]
  tail call void @_ZN3qOS8critical4exitEv() #2
  br label %17

17:                                               ; preds = %._crit_edge, %2
  %.1 = phi i1 [ %.not.lcssa, %._crit_edge ], [ false, %2 ]
  ret i1 %.1
}

attributes #0 = { 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 #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 }

!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, !7, i64 8}
!6 = !{!"_ZTSN3qOS9prioQueueE", !7, i64 8, !10, i64 16, !10, i64 24, !11, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !10, i64 24}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTSN3qOS2pq12queueStack_tE", !10, i64 0, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass