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

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3qOS9prioQueue11hasElementsEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN3qOS9prioQueue3getEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store ptr null, ptr %3, align 8, !tbaa !5
  %9 = call noundef zeroext i1 @_ZNK3qOS9prioQueue11hasElementsEv(ptr noundef nonnull align 8 dereferenceable(40) %8) #4
  br i1 %9, label %10, label %68

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !9
  call void @_ZN3qOS8critical5enterEv() #4
  %11 = getelementptr inbounds %"class.qOS::prioQueue", ptr %8, i32 0, i32 3
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %12, i64 0
  %14 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = call noundef zeroext i8 @_ZNK3qOS4task11getPriorityEv(ptr noundef nonnull align 8 dereferenceable(150) %15) #4
  store i8 %16, ptr %4, align 1, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 1, ptr %6, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %50, %10
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = getelementptr inbounds %"class.qOS::prioQueue", ptr %8, i32 0, i32 4
  %20 = load i64, ptr %19, align 8, !tbaa !17
  %21 = icmp ult i64 %18, %20
  br i1 %21, label %22, label %30

22:                                               ; preds = %17
  %23 = getelementptr inbounds %"class.qOS::prioQueue", ptr %8, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %24, i64 %25
  %27 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = icmp ne ptr null, %28
  br label %30

30:                                               ; preds = %22, %17
  %31 = phi i1 [ false, %17 ], [ %29, %22 ]
  br i1 %31, label %33, label %32

32:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %53

33:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  %34 = getelementptr inbounds %"class.qOS::prioQueue", ptr %8, i32 0, i32 3
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %35, i64 %36
  %38 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  %40 = call noundef zeroext i8 @_ZNK3qOS4task11getPriorityEv(ptr noundef nonnull align 8 dereferenceable(150) %39) #4
  store i8 %40, ptr %7, align 1, !tbaa !16
  %41 = load i8, ptr %7, align 1, !tbaa !16
  %42 = zext i8 %41 to i32
  %43 = load i8, ptr %4, align 1, !tbaa !16
  %44 = zext i8 %43 to i32
  %45 = icmp sgt i32 %42, %44
  br i1 %45, label %46, label %49

46:                                               ; preds = %33
  %47 = load i8, ptr %7, align 1, !tbaa !16
  store i8 %47, ptr %4, align 1, !tbaa !16
  %48 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %48, ptr %5, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %46, %33
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  br label %50

50:                                               ; preds = %49
  %51 = load i64, ptr %6, align 8, !tbaa !9
  %52 = add i64 %51, 1
  store i64 %52, ptr %6, align 8, !tbaa !9
  br label %17, !llvm.loop !18

53:                                               ; preds = %32
  %54 = getelementptr inbounds %"class.qOS::prioQueue", ptr %8, i32 0, i32 3
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  %56 = load i64, ptr %5, align 8, !tbaa !9
  %57 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %55, i64 %56
  %58 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !20
  %60 = getelementptr inbounds %"class.qOS::prioQueue", ptr %8, i32 0, i32 2
  store ptr %59, ptr %60, align 8, !tbaa !21
  %61 = getelementptr inbounds %"class.qOS::prioQueue", ptr %8, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  %63 = load i64, ptr %5, align 8, !tbaa !9
  %64 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %62, i64 %63
  %65 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  store ptr %66, ptr %3, align 8, !tbaa !5
  %67 = load i64, ptr %5, align 8, !tbaa !9
  call void @_ZN3qOS9prioQueue10clearIndexEm(ptr noundef nonnull align 8 dereferenceable(40) %8, i64 noundef %67) #4
  call void @_ZN3qOS8critical4exitEv() #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #4
  br label %68

68:                                               ; preds = %53, %1
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret ptr %69
}

; Function Attrs: nounwind
declare noundef zeroext i8 @_ZNK3qOS4task11getPriorityEv(ptr noundef nonnull align 8 dereferenceable(150)) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS9prioQueue10clearIndexEm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef) #3 align 2

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 = { 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 #3 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"_ZTSN3qOS9prioQueueE", !13, i64 8, !6, i64 16, !6, i64 24, !10, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTSN3qOS2pq12queueStack_tE", !6, i64 0, !6, i64 8}
!16 = !{!7, !7, i64 0}
!17 = !{!12, !10, i64 32}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!15, !6, i64 8}
!21 = !{!12, !6, i64 16}


; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3qOS9prioQueue11hasElementsEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN3qOS9prioQueue3getEv(ptr noundef nonnull align 8 dereferenceable(40) %0) local_unnamed_addr #2 align 2 {
  %2 = tail call noundef zeroext i1 @_ZNK3qOS9prioQueue11hasElementsEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #4
  br i1 %2, label %3, label %26

3:                                                ; preds = %1
  tail call void @_ZN3qOS8critical5enterEv() #4
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = tail call noundef zeroext i8 @_ZNK3qOS4task11getPriorityEv(ptr noundef nonnull align 8 dereferenceable(150) %6) #4
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = load i64, ptr %8, align 8, !tbaa !14
  %10 = icmp ugt i64 %9, 1
  br i1 %10, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %3, %20
  %.01220 = phi i64 [ %23, %20 ], [ 1, %3 ]
  %.01319 = phi i64 [ %spec.select17, %20 ], [ 0, %3 ]
  %.01418 = phi i8 [ %spec.select, %20 ], [ %7, %3 ]
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %11, i64 %.01220
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %.critedge, label %20

.critedge:                                        ; preds = %.lr.ph, %20, %3
  %.013.lcssa = phi i64 [ 0, %3 ], [ %spec.select17, %20 ], [ %.01319, %.lr.ph ]
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %14, i64 %.013.lcssa, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %16, ptr %17, align 8, !tbaa !16
  %18 = getelementptr inbounds %"struct.qOS::pq::queueStack_t", ptr %14, i64 %.013.lcssa
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  tail call void @_ZN3qOS9prioQueue10clearIndexEm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %.013.lcssa) #4
  tail call void @_ZN3qOS8critical4exitEv() #4
  br label %26

20:                                               ; preds = %.lr.ph
  %21 = tail call noundef zeroext i8 @_ZNK3qOS4task11getPriorityEv(ptr noundef nonnull align 8 dereferenceable(150) %13) #4
  %22 = icmp ugt i8 %21, %.01418
  %spec.select = tail call i8 @llvm.umax.i8(i8 %21, i8 %.01418)
  %spec.select17 = select i1 %22, i64 %.01220, i64 %.01319
  %23 = add nuw i64 %.01220, 1
  %24 = load i64, ptr %8, align 8, !tbaa !14
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %.lr.ph, label %.critedge, !llvm.loop !17

26:                                               ; preds = %.critedge, %1
  %.0 = phi ptr [ %19, %.critedge ], [ null, %1 ]
  ret ptr %.0
}

; Function Attrs: nounwind
declare noundef zeroext i8 @_ZNK3qOS4task11getPriorityEv(ptr noundef nonnull align 8 dereferenceable(150)) local_unnamed_addr #0

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.umax.i8(i8, i8) #3

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 = { 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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, i64 24}
!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 = !{!13, !10, i64 0}
!13 = !{!"_ZTSN3qOS2pq12queueStack_tE", !10, i64 0, !10, i64 8}
!14 = !{!6, !11, i64 32}
!15 = !{!13, !10, i64 8}
!16 = !{!6, !10, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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