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

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

; 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 #3 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN3qOS4core11getTaskByIDEm(ptr noundef nonnull align 8 dereferenceable(800) %0, i64 noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i8, align 1
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca %"class.qOS::listIterator", align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %12 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store ptr null, ptr %5, align 8, !tbaa !5
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = icmp ugt i64 %13, 0
  br i1 %14, label %15, label %56

15:                                               ; preds = %2
  %16 = load i64, ptr %4, align 8, !tbaa !9
  %17 = icmp ult i64 %16, -1
  br i1 %17, label %18, label %56

18:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 5, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  store i8 0, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %52, %18
  %20 = load i8, ptr %7, align 1, !tbaa !11, !range !13, !noundef !14
  %21 = trunc i8 %20 to i1
  br i1 %21, label %25, label %22

22:                                               ; preds = %19
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = icmp ult i64 %23, 5
  br label %25

25:                                               ; preds = %22, %19
  %26 = phi i1 [ false, %19 ], [ %24, %22 ]
  br i1 %26, label %28, label %27

27:                                               ; preds = %25
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %55

28:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #4
  %29 = getelementptr inbounds %"class.qOS::core", ptr %12, i32 0, i32 9
  %30 = load i64, ptr %8, align 8, !tbaa !9
  %31 = getelementptr inbounds [5 x %"class.qOS::list"], ptr %29, i64 0, i64 %30
  call void @_ZN3qOS4list5beginEv(ptr dead_on_unwind writable sret(%"class.qOS::listIterator") align 8 %10, ptr noundef nonnull align 8 dereferenceable(56) %31) #4
  br label %32

32:                                               ; preds = %48, %28
  %33 = call noundef zeroext i1 @_ZNK3qOS12listIterator8untilEndEv(ptr noundef nonnull align 8 dereferenceable(32) %10) #4
  br i1 %33, label %35, label %34

34:                                               ; preds = %32
  store i32 5, ptr %9, align 4
  br label %50

35:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %36 = call noundef ptr @_ZN3qOS12listIterator3getIPNS_4taskEEET_v(ptr noundef nonnull align 8 dereferenceable(32) %10) #4
  store ptr %36, ptr %11, align 8, !tbaa !5
  %37 = load i64, ptr %4, align 8, !tbaa !9
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = getelementptr inbounds %"class.qOS::task", ptr %38, i32 0, i32 12
  %40 = load i64, ptr %39, align 8, !tbaa !15
  %41 = icmp eq i64 %37, %40
  br i1 %41, label %42, label %44

42:                                               ; preds = %35
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %43, ptr %5, align 8, !tbaa !5
  store i8 1, ptr %7, align 1, !tbaa !11
  store i32 5, ptr %9, align 4
  br label %45

44:                                               ; preds = %35
  store i32 0, ptr %9, align 4
  br label %45

45:                                               ; preds = %44, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %46 = load i32, ptr %9, align 4
  switch i32 %46, label %50 [
    i32 0, label %47
  ]

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47
  %49 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS12listIteratorppEi(ptr noundef nonnull align 8 dereferenceable(32) %10, i32 noundef 0) #4
  br label %32, !llvm.loop !21

50:                                               ; preds = %45, %34
  call void @_ZN3qOS12listIteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %10) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #4
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  %53 = load i64, ptr %8, align 8, !tbaa !9
  %54 = add i64 %53, 1
  store i64 %54, ptr %8, align 8, !tbaa !9
  br label %19, !llvm.loop !23

55:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %56

56:                                               ; preds = %55, %15, %2
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret ptr %57
}

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

%"class.qOS::listIterator" = type { ptr, ptr, ptr, ptr }
%"class.qOS::list" = type { %"class.qOS::node", ptr, ptr, i64 }
%"class.qOS::node" = 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3qOS12listIterator3getIPNS_4taskEEET_v(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #2 align 2

; 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 #3 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN3qOS4core11getTaskByIDEm(ptr noundef nonnull align 8 dereferenceable(800) %0, i64 noundef %1) local_unnamed_addr #3 align 2 {
  %3 = alloca %"class.qOS::listIterator", align 8
  %4 = add i64 %1, -1
  %or.cond = icmp ult i64 %4, -2
  br i1 %or.cond, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 448
  br label %6

6:                                                ; preds = %.preheader, %._crit_edge
  %.026 = phi ptr [ null, %.preheader ], [ %.3, %._crit_edge ]
  %.01325 = phi i64 [ 0, %.preheader ], [ %15, %._crit_edge ]
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  %7 = getelementptr inbounds [5 x %"class.qOS::list"], ptr %5, i64 0, i64 %.01325
  call void @_ZN3qOS4list5beginEv(ptr dead_on_unwind nonnull writable sret(%"class.qOS::listIterator") align 8 %3, ptr noundef nonnull align 8 dereferenceable(56) %7) #4
  %8 = call noundef zeroext i1 @_ZNK3qOS12listIterator8untilEndEv(ptr noundef nonnull align 8 dereferenceable(32) %3) #4
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6, %12
  %9 = call noundef ptr @_ZN3qOS12listIterator3getIPNS_4taskEEET_v(ptr noundef nonnull align 8 dereferenceable(32) %3) #4
  %10 = getelementptr inbounds i8, ptr %9, i64 128
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %.not = icmp eq i64 %11, %1
  br i1 %.not, label %._crit_edge, label %12

12:                                               ; preds = %.lr.ph
  %13 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN3qOS12listIteratorppEi(ptr noundef nonnull align 8 dereferenceable(32) %3, i32 noundef 0) #4
  %14 = call noundef zeroext i1 @_ZNK3qOS12listIterator8untilEndEv(ptr noundef nonnull align 8 dereferenceable(32) %3) #4
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %12, %6
  %.317 = phi i1 [ false, %6 ], [ %.not, %12 ], [ %.not, %.lr.ph ]
  %.3 = phi ptr [ %.026, %6 ], [ %9, %.lr.ph ], [ %.026, %12 ]
  call void @_ZN3qOS12listIteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %3) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  %15 = add nuw nsw i64 %.01325, 1
  %16 = icmp ugt i64 %.01325, 3
  %.not19 = or i1 %.317, %16
  br i1 %.not19, label %.loopexit, label %6, !llvm.loop !17

.loopexit:                                        ; preds = %._crit_edge, %2
  %.4 = phi ptr [ null, %2 ], [ %.3, %._crit_edge ]
  ret ptr %.4
}

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 = { 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, !11, i64 128}
!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 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; Effective O3 passes: AggressiveInstCombinePass,CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass