; LLVM IR from pms67/HadesFCS :: Firmware/F4Quad/Middlewares/Third_Party/FreeRTOS/Source (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, [16 x i8], i64, i64, i32, i8, i8 }
%struct.xLIST_ITEM = type { i32, ptr, ptr, ptr, ptr }

@pxCurrentTCB = external dso_local global ptr, align 8
@pxReadyTasksLists = external hidden global [7 x %struct.xLIST], align 16
@uxTopReadyPriority = external hidden global i64, align 8
@uxCurrentNumberOfTasks = external hidden global i64, align 8
@xSchedulerRunning = external hidden global i64, align 8
@uxSchedulerSuspended = external hidden global i64, align 8
@xSuspendedTaskList = 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 void @vPortEnterCritical() #2

declare i64 @uxListRemove(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden void @prvResetNextTaskUnblockTime() #3

declare void @vPortExitCritical() #2

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

6:                                                ; preds = %1
  %7 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  br label %10

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %8, %6
  %11 = phi ptr [ %7, %6 ], [ %9, %8 ]
  store ptr %11, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %12, i32 0, i32 1
  %14 = call i64 @uxListRemove(ptr noundef %13)
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %33

16:                                               ; preds = %10
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %17, i32 0, i32 3
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.xLIST, ptr %20, i32 0, i32 0
  %22 = load volatile i64, ptr %21, align 8, !tbaa !14
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %24, label %32

24:                                               ; preds = %16
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %25, i32 0, i32 3
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = shl i64 1, %27
  %29 = xor i64 %28, -1
  %30 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !17
  %31 = and i64 %30, %29
  store volatile i64 %31, ptr @uxTopReadyPriority, align 8, !tbaa !17
  br label %32

32:                                               ; preds = %24, %16
  br label %34

33:                                               ; preds = %10
  br label %34

34:                                               ; preds = %33, %32
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %35, i32 0, i32 2
  %37 = getelementptr inbounds %struct.xLIST_ITEM, ptr %36, i32 0, i32 4
  %38 = load ptr, ptr %37, align 8, !tbaa !18
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %44

40:                                               ; preds = %34
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %41, i32 0, i32 2
  %43 = call i64 @uxListRemove(ptr noundef %42)
  br label %45

44:                                               ; preds = %34
  br label %45

45:                                               ; preds = %44, %40
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %46, i32 0, i32 1
  call void @vListInsertEnd(ptr noundef @xSuspendedTaskList, ptr noundef %47)
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %48, i32 0, i32 9
  %50 = load volatile i8, ptr %49, align 4, !tbaa !19
  %51 = zext i8 %50 to i32
  %52 = icmp eq i32 %51, 1
  br i1 %52, label %53, label %56

53:                                               ; preds = %45
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %54, i32 0, i32 9
  store volatile i8 0, ptr %55, align 4, !tbaa !19
  br label %56

56:                                               ; preds = %53, %45
  call void @vPortExitCritical()
  %57 = load volatile i64, ptr @xSchedulerRunning, align 8, !tbaa !17
  %58 = icmp ne i64 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %56
  call void @vPortEnterCritical()
  call void @prvResetNextTaskUnblockTime()
  call void @vPortExitCritical()
  br label %61

60:                                               ; preds = %56
  br label %61

61:                                               ; preds = %60, %59
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %64 = icmp eq ptr %62, %63
  br i1 %64, label %65, label %84

65:                                               ; preds = %61
  %66 = load volatile i64, ptr @xSchedulerRunning, align 8, !tbaa !17
  %67 = icmp ne i64 %66, 0
  br i1 %67, label %68, label %76

68:                                               ; preds = %65
  %69 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !17
  %70 = icmp eq i64 %69, 0
  %71 = zext i1 %70 to i32
  %72 = icmp eq i32 %71, 0
  br i1 %72, label %73, label %75

73:                                               ; preds = %68
  call void @vPortRaiseBASEPRI()
  br label %74

74:                                               ; preds = %74, %73
  br label %74

75:                                               ; preds = %68
  store volatile i32 268435456, ptr inttoptr (i64 3758157060 to ptr), align 4, !tbaa !20
  call void asm sideeffect "dsb", "~{memory},~{dirflag},~{fpsr},~{flags}"() #4, !srcloc !21
  call void asm sideeffect "isb", "~{dirflag},~{fpsr},~{flags}"() #4, !srcloc !22
  br label %83

76:                                               ; preds = %65
  %77 = load volatile i64, ptr @xSuspendedTaskList, align 8, !tbaa !14
  %78 = load volatile i64, ptr @uxCurrentNumberOfTasks, align 8, !tbaa !17
  %79 = icmp eq i64 %77, %78
  br i1 %79, label %80, label %81

80:                                               ; preds = %76
  store volatile ptr null, ptr @pxCurrentTCB, align 8, !tbaa !5
  br label %82

81:                                               ; preds = %76
  call void @vTaskSwitchContext()
  br label %82

82:                                               ; preds = %81, %80
  br label %83

83:                                               ; preds = %82, %75
  br label %85

84:                                               ; preds = %61
  br label %85

85:                                               ; preds = %84, %83
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @vTaskSwitchContext() #3

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, !13, i64 88}
!10 = !{!"tskTaskControlBlock", !6, i64 0, !11, i64 8, !11, i64 48, !13, i64 88, !6, i64 96, !7, i64 104, !13, i64 120, !13, i64 128, !12, i64 136, !7, i64 140, !7, i64 141}
!11 = !{!"xLIST_ITEM", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"xLIST", !13, i64 0, !6, i64 8, !16, i64 16}
!16 = !{!"xMINI_LIST_ITEM", !12, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!13, !13, i64 0}
!18 = !{!10, !6, i64 80}
!19 = !{!10, !7, i64 140}
!20 = !{!12, !12, i64 0}
!21 = !{i64 2148243634}
!22 = !{i64 2148243684}


; 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
@pxReadyTasksLists = external hidden global [7 x %struct.xLIST], align 16
@uxTopReadyPriority = external hidden global i64, align 8
@uxCurrentNumberOfTasks = external hidden global i64, align 8
@xSchedulerRunning = external hidden global i64, align 8
@uxSchedulerSuspended = external hidden global i64, align 8
@xSuspendedTaskList = external hidden global %struct.xLIST, align 8

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

declare void @vPortEnterCritical() local_unnamed_addr #1

declare i64 @uxListRemove(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden void @prvResetNextTaskUnblockTime() local_unnamed_addr #2

declare void @vPortExitCritical() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @vTaskSuspend(ptr noundef %0) local_unnamed_addr #2 {
  tail call void @vPortEnterCritical() #3
  %2 = icmp eq ptr %0, null
  br i1 %2, label %3, label %5

3:                                                ; preds = %1
  %4 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %1, %3
  %6 = phi ptr [ %4, %3 ], [ %0, %1 ]
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = tail call i64 @uxListRemove(ptr noundef nonnull %7) #3
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %10, label %21

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %6, i64 88
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %12
  %14 = load volatile i64, ptr %13, align 8, !tbaa !14
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %21

16:                                               ; preds = %10
  %17 = shl nuw i64 1, %12
  %18 = xor i64 %17, -1
  %19 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !17
  %20 = and i64 %19, %18
  store volatile i64 %20, ptr @uxTopReadyPriority, align 8, !tbaa !17
  br label %21

21:                                               ; preds = %5, %10, %16
  %22 = getelementptr inbounds i8, ptr %6, i64 80
  %23 = load ptr, ptr %22, align 8, !tbaa !18
  %.not = icmp eq ptr %23, null
  br i1 %.not, label %27, label %24

24:                                               ; preds = %21
  %25 = getelementptr inbounds i8, ptr %6, i64 48
  %26 = tail call i64 @uxListRemove(ptr noundef nonnull %25) #3
  br label %27

27:                                               ; preds = %21, %24
  tail call void @vListInsertEnd(ptr noundef nonnull @xSuspendedTaskList, ptr noundef nonnull %7) #3
  %28 = getelementptr inbounds i8, ptr %6, i64 140
  %29 = load volatile i8, ptr %28, align 4, !tbaa !19
  %30 = icmp eq i8 %29, 1
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  store volatile i8 0, ptr %28, align 4, !tbaa !19
  br label %32

32:                                               ; preds = %31, %27
  tail call void @vPortExitCritical() #3
  %33 = load volatile i64, ptr @xSchedulerRunning, align 8, !tbaa !17
  %.not11 = icmp eq i64 %33, 0
  br i1 %.not11, label %35, label %34

34:                                               ; preds = %32
  tail call void @vPortEnterCritical() #3
  tail call void @prvResetNextTaskUnblockTime()
  tail call void @vPortExitCritical() #3
  br label %35

35:                                               ; preds = %32, %34
  %36 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %37 = icmp eq ptr %6, %36
  br i1 %37, label %38, label %51

38:                                               ; preds = %35
  %39 = load volatile i64, ptr @xSchedulerRunning, align 8, !tbaa !17
  %.not12 = icmp eq i64 %39, 0
  br i1 %.not12, label %45, label %40

40:                                               ; preds = %38
  %41 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !17
  %.not13 = icmp eq i64 %41, 0
  br i1 %.not13, label %44, label %42

42:                                               ; preds = %40
  tail call void @vPortRaiseBASEPRI()
  br label %43

43:                                               ; preds = %43, %42
  br label %43

44:                                               ; preds = %40
  store volatile i32 268435456, ptr inttoptr (i64 3758157060 to ptr), align 4, !tbaa !20
  tail call void asm sideeffect "dsb", "~{memory},~{dirflag},~{fpsr},~{flags}"() #3, !srcloc !21
  tail call void asm sideeffect "isb", "~{dirflag},~{fpsr},~{flags}"() #3, !srcloc !22
  br label %51

45:                                               ; preds = %38
  %46 = load volatile i64, ptr @xSuspendedTaskList, align 8, !tbaa !14
  %47 = load volatile i64, ptr @uxCurrentNumberOfTasks, align 8, !tbaa !17
  %48 = icmp eq i64 %46, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %45
  store volatile ptr null, ptr @pxCurrentTCB, align 8, !tbaa !5
  br label %51

50:                                               ; preds = %45
  tail call void @vTaskSwitchContext()
  br label %51

51:                                               ; preds = %35, %44, %50, %49
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @vTaskSwitchContext() local_unnamed_addr #2

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !13, i64 88}
!10 = !{!"tskTaskControlBlock", !6, i64 0, !11, i64 8, !11, i64 48, !13, i64 88, !6, i64 96, !7, i64 104, !13, i64 120, !13, i64 128, !12, i64 136, !7, i64 140, !7, i64 141}
!11 = !{!"xLIST_ITEM", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"xLIST", !13, i64 0, !6, i64 8, !16, i64 16}
!16 = !{!"xMINI_LIST_ITEM", !12, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!13, !13, i64 0}
!18 = !{!10, !6, i64 80}
!19 = !{!10, !7, i64 140}
!20 = !{!12, !12, i64 0}
!21 = !{i64 2148243634}
!22 = !{i64 2148243684}


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