; LLVM IR from ctlst-tech/catpilot :: os/freertos/core/src (tasks)

; 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"

%struct.xLIST = type { i64, ptr, %struct.xMINI_LIST_ITEM }
%struct.xMINI_LIST_ITEM = type { i32, ptr, ptr }
%struct.tskTaskControlBlock = type { ptr, %struct.xLIST_ITEM, %struct.xLIST_ITEM, i64, ptr, [24 x i8], ptr, i64, i64, ptr, [5 x ptr], [3 x i32], [3 x i8], i8, i8, i32 }
%struct.xLIST_ITEM = type { i32, ptr, ptr, ptr, ptr }

@pxCurrentTCB = external dso_local global ptr, align 8
@uxSchedulerSuspended = external hidden global i64, align 8
@pxReadyTasksLists = external hidden global [32 x %struct.xLIST], align 16
@uxTopReadyPriority = external hidden global i64, align 8
@xYieldPending = external hidden global i64, align 8
@xPendingReadyList = external hidden global %struct.xLIST, align 8

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @vPortRaiseBASEPRI() #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i64 @uxListRemove(ptr noundef) #2

declare void @vListInsertEnd(ptr noundef, ptr noundef) #2

declare void @vPortValidateInterruptPriority() #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @ulPortRaiseBASEPRI() #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @vPortSetBASEPRI(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @vTaskGenericNotifyGiveFromISR(ptr noundef %0, i64 noundef %1, ptr noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %14

12:                                               ; preds = %3
  call void @vPortRaiseBASEPRI()
  br label %13

13:                                               ; preds = %13, %12
  br label %13

14:                                               ; preds = %3
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = icmp ult i64 %15, 3
  %17 = zext i1 %16 to i32
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %14
  call void @vPortRaiseBASEPRI()
  br label %20

20:                                               ; preds = %20, %19
  br label %20

21:                                               ; preds = %14
  call void @vPortValidateInterruptPriority()
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %22, ptr %7, align 8, !tbaa !5
  %23 = call i32 @ulPortRaiseBASEPRI()
  %24 = zext i32 %23 to i64
  store i64 %24, ptr %9, align 8, !tbaa !9
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %25, i32 0, i32 12
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = getelementptr inbounds [3 x i8], ptr %26, i64 0, i64 %27
  %29 = load volatile i8, ptr %28, align 1, !tbaa !11
  store i8 %29, ptr %8, align 1, !tbaa !11
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %30, i32 0, i32 12
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = getelementptr inbounds [3 x i8], ptr %31, i64 0, i64 %32
  store volatile i8 2, ptr %33, align 1, !tbaa !11
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %34, i32 0, i32 11
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = getelementptr inbounds [3 x i32], ptr %35, i64 0, i64 %36
  %38 = load volatile i32, ptr %37, align 4, !tbaa !12
  %39 = add i32 %38, 1
  store volatile i32 %39, ptr %37, align 4, !tbaa !12
  %40 = load i8, ptr %8, align 1, !tbaa !11
  %41 = zext i8 %40 to i32
  %42 = icmp eq i32 %41, 1
  br i1 %42, label %43, label %95

43:                                               ; preds = %21
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %44, i32 0, i32 2
  %46 = getelementptr inbounds %struct.xLIST_ITEM, ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !14
  %48 = icmp eq ptr %47, null
  %49 = zext i1 %48 to i32
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %53

51:                                               ; preds = %43
  call void @vPortRaiseBASEPRI()
  br label %52

52:                                               ; preds = %52, %51
  br label %52

53:                                               ; preds = %43
  %54 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !9
  %55 = icmp eq i64 %54, 0
  br i1 %55, label %56, label %76

56:                                               ; preds = %53
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %57, i32 0, i32 1
  %59 = call i64 @uxListRemove(ptr noundef %58)
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %60, i32 0, i32 3
  %62 = load i64, ptr %61, align 8, !tbaa !17
  %63 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %64 = icmp ugt i64 %62, %63
  br i1 %64, label %65, label %69

65:                                               ; preds = %56
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %66, i32 0, i32 3
  %68 = load i64, ptr %67, align 8, !tbaa !17
  store volatile i64 %68, ptr @uxTopReadyPriority, align 8, !tbaa !9
  br label %69

69:                                               ; preds = %65, %56
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %70, i32 0, i32 3
  %72 = load i64, ptr %71, align 8, !tbaa !17
  %73 = getelementptr inbounds [32 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %72
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %74, i32 0, i32 1
  call void @vListInsertEnd(ptr noundef %73, ptr noundef %75)
  br label %79

76:                                               ; preds = %53
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %77, i32 0, i32 2
  call void @vListInsertEnd(ptr noundef @xPendingReadyList, ptr noundef %78)
  br label %79

79:                                               ; preds = %76, %69
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %80, i32 0, i32 3
  %82 = load i64, ptr %81, align 8, !tbaa !17
  %83 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %83, i32 0, i32 3
  %85 = load i64, ptr %84, align 8, !tbaa !17
  %86 = icmp ugt i64 %82, %85
  br i1 %86, label %87, label %93

87:                                               ; preds = %79
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = icmp ne ptr %88, null
  br i1 %89, label %90, label %92

90:                                               ; preds = %87
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 1, ptr %91, align 8, !tbaa !9
  br label %92

92:                                               ; preds = %90, %87
  store volatile i64 1, ptr @xYieldPending, align 8, !tbaa !9
  br label %94

93:                                               ; preds = %79
  br label %94

94:                                               ; preds = %93, %92
  br label %95

95:                                               ; preds = %94, %21
  %96 = load i64, ptr %9, align 8, !tbaa !9
  %97 = trunc i64 %96 to i32
  call void @vPortSetBASEPRI(i32 noundef %97)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 = { "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 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 80}
!15 = !{!"tskTaskControlBlock", !6, i64 0, !16, i64 8, !16, i64 48, !10, i64 88, !6, i64 96, !7, i64 104, !6, i64 128, !10, i64 136, !10, i64 144, !6, i64 152, !7, i64 160, !7, i64 200, !7, i64 212, !7, i64 215, !7, i64 216, !13, i64 220}
!16 = !{!"xLIST_ITEM", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!17 = !{!15, !10, i64 88}


; 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.xLIST = type { i64, ptr, %struct.xMINI_LIST_ITEM }
%struct.xMINI_LIST_ITEM = type { i32, ptr, ptr }

@pxCurrentTCB = external dso_local global ptr, align 8
@uxSchedulerSuspended = external hidden global i64, align 8
@pxReadyTasksLists = external hidden global [32 x %struct.xLIST], align 16
@uxTopReadyPriority = external hidden global i64, align 8
@xYieldPending = external hidden global i64, align 8
@xPendingReadyList = external hidden global %struct.xLIST, align 8

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @vPortRaiseBASEPRI() local_unnamed_addr #0

declare i64 @uxListRemove(ptr noundef) local_unnamed_addr #1

declare void @vListInsertEnd(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @vPortValidateInterruptPriority() local_unnamed_addr #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @ulPortRaiseBASEPRI() local_unnamed_addr #0

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @vPortSetBASEPRI(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @vTaskGenericNotifyGiveFromISR(ptr noundef %0, i64 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #2 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %5, label %7

5:                                                ; preds = %3
  tail call void @vPortRaiseBASEPRI()
  br label %6

6:                                                ; preds = %6, %5
  br label %6

7:                                                ; preds = %3
  %8 = icmp ugt i64 %1, 2
  br i1 %8, label %9, label %11

9:                                                ; preds = %7
  tail call void @vPortRaiseBASEPRI()
  br label %10

10:                                               ; preds = %10, %9
  br label %10

11:                                               ; preds = %7
  tail call void @vPortValidateInterruptPriority() #3
  %12 = tail call i32 @ulPortRaiseBASEPRI()
  %13 = getelementptr inbounds i8, ptr %0, i64 212
  %14 = getelementptr inbounds [3 x i8], ptr %13, i64 0, i64 %1
  %15 = load volatile i8, ptr %14, align 1, !tbaa !5
  store volatile i8 2, ptr %14, align 1, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 200
  %17 = getelementptr inbounds [3 x i32], ptr %16, i64 0, i64 %1
  %18 = load volatile i32, ptr %17, align 4, !tbaa !8
  %19 = add i32 %18, 1
  store volatile i32 %19, ptr %17, align 4, !tbaa !8
  %20 = icmp eq i8 %15, 1
  br i1 %20, label %21, label %51

21:                                               ; preds = %11
  %22 = getelementptr inbounds i8, ptr %0, i64 48
  %23 = getelementptr inbounds i8, ptr %0, i64 80
  %24 = load ptr, ptr %23, align 8, !tbaa !10
  %.not = icmp eq ptr %24, null
  br i1 %.not, label %27, label %25

25:                                               ; preds = %21
  tail call void @vPortRaiseBASEPRI()
  br label %26

26:                                               ; preds = %26, %25
  br label %26

27:                                               ; preds = %21
  %28 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !15
  %29 = icmp eq i64 %28, 0
  br i1 %29, label %30, label %40

30:                                               ; preds = %27
  %31 = getelementptr inbounds i8, ptr %0, i64 8
  %32 = tail call i64 @uxListRemove(ptr noundef nonnull %31) #3
  %33 = getelementptr inbounds i8, ptr %0, i64 88
  %34 = load i64, ptr %33, align 8, !tbaa !16
  %35 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !15
  %36 = icmp ugt i64 %34, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %30
  store volatile i64 %34, ptr @uxTopReadyPriority, align 8, !tbaa !15
  br label %38

38:                                               ; preds = %37, %30
  %39 = getelementptr inbounds [32 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %34
  tail call void @vListInsertEnd(ptr noundef nonnull %39, ptr noundef nonnull %31) #3
  br label %41

40:                                               ; preds = %27
  tail call void @vListInsertEnd(ptr noundef nonnull @xPendingReadyList, ptr noundef nonnull %22) #3
  br label %41

41:                                               ; preds = %40, %38
  %42 = getelementptr inbounds i8, ptr %0, i64 88
  %43 = load i64, ptr %42, align 8, !tbaa !16
  %44 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !17
  %45 = getelementptr inbounds i8, ptr %44, i64 88
  %46 = load i64, ptr %45, align 8, !tbaa !16
  %47 = icmp ugt i64 %43, %46
  br i1 %47, label %48, label %51

48:                                               ; preds = %41
  %.not21 = icmp eq ptr %2, null
  br i1 %.not21, label %50, label %49

49:                                               ; preds = %48
  store i64 1, ptr %2, align 8, !tbaa !15
  br label %50

50:                                               ; preds = %49, %48
  store volatile i64 1, ptr @xYieldPending, align 8, !tbaa !15
  br label %51

51:                                               ; preds = %50, %41, %11
  tail call void @vPortSetBASEPRI(i32 noundef %12)
  ret void
}

attributes #0 = { alwaysinline 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 = { "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 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !12, i64 80}
!11 = !{!"tskTaskControlBlock", !12, i64 0, !13, i64 8, !13, i64 48, !14, i64 88, !12, i64 96, !6, i64 104, !12, i64 128, !14, i64 136, !14, i64 144, !12, i64 152, !6, i64 160, !6, i64 200, !6, i64 212, !6, i64 215, !6, i64 216, !9, i64 220}
!12 = !{!"any pointer", !6, i64 0}
!13 = !{!"xLIST_ITEM", !9, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!14 = !{!"long", !6, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!11, !14, i64 88}
!17 = !{!12, !12, i64 0}


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