; 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

; 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

declare i64 @uxListRemove(ptr noundef) #1

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

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

8:                                                ; preds = %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %9, i32 0, i32 3
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %12, i32 0, i32 3
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = icmp ult i64 %11, %14
  br i1 %15, label %16, label %95

16:                                               ; preds = %8
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %17, i32 0, i32 2
  %19 = getelementptr inbounds %struct.xLIST_ITEM, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %21 = zext i32 %20 to i64
  %22 = and i64 %21, 2147483648
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %24, label %33

24:                                               ; preds = %16
  %25 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %25, i32 0, i32 3
  %27 = load i64, ptr %26, align 8, !tbaa !11
  %28 = trunc i64 %27 to i32
  %29 = sub i32 7, %28
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %30, i32 0, i32 2
  %32 = getelementptr inbounds %struct.xLIST_ITEM, ptr %31, i32 0, i32 0
  store i32 %29, ptr %32, align 8, !tbaa !15
  br label %34

33:                                               ; preds = %16
  br label %34

34:                                               ; preds = %33, %24
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %35, i32 0, i32 1
  %37 = getelementptr inbounds %struct.xLIST_ITEM, ptr %36, i32 0, i32 4
  %38 = load ptr, ptr %37, align 8, !tbaa !16
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %39, i32 0, i32 3
  %41 = load i64, ptr %40, align 8, !tbaa !11
  %42 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %41
  %43 = icmp eq ptr %38, %42
  %44 = zext i1 %43 to i32
  %45 = sext i32 %44 to i64
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %47, label %88

47:                                               ; preds = %34
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %48, i32 0, i32 1
  %50 = call i64 @uxListRemove(ptr noundef %49)
  %51 = icmp eq i64 %50, 0
  br i1 %51, label %52, label %69

52:                                               ; preds = %47
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %53, i32 0, i32 3
  %55 = load i64, ptr %54, align 8, !tbaa !11
  %56 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.xLIST, ptr %56, i32 0, i32 0
  %58 = load volatile i64, ptr %57, align 8, !tbaa !17
  %59 = icmp eq i64 %58, 0
  br i1 %59, label %60, label %68

60:                                               ; preds = %52
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %61, i32 0, i32 3
  %63 = load i64, ptr %62, align 8, !tbaa !11
  %64 = shl i64 1, %63
  %65 = xor i64 %64, -1
  %66 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %67 = and i64 %66, %65
  store volatile i64 %67, ptr @uxTopReadyPriority, align 8, !tbaa !9
  br label %68

68:                                               ; preds = %60, %52
  br label %70

69:                                               ; preds = %47
  br label %70

70:                                               ; preds = %69, %68
  %71 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %71, i32 0, i32 3
  %73 = load i64, ptr %72, align 8, !tbaa !11
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %74, i32 0, i32 3
  store i64 %73, ptr %75, align 8, !tbaa !11
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %76, i32 0, i32 3
  %78 = load i64, ptr %77, align 8, !tbaa !11
  %79 = shl i64 1, %78
  %80 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %81 = or i64 %80, %79
  store volatile i64 %81, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %82, i32 0, i32 3
  %84 = load i64, ptr %83, align 8, !tbaa !11
  %85 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %84
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %86, i32 0, i32 1
  call void @vListInsertEnd(ptr noundef %85, ptr noundef %87)
  br label %94

88:                                               ; preds = %34
  %89 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %89, i32 0, i32 3
  %91 = load i64, ptr %90, align 8, !tbaa !11
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %92, i32 0, i32 3
  store i64 %91, ptr %93, align 8, !tbaa !11
  br label %94

94:                                               ; preds = %88, %70
  store i64 1, ptr %4, align 8, !tbaa !9
  br label %106

95:                                               ; preds = %8
  %96 = load ptr, ptr %3, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %96, i32 0, i32 6
  %98 = load i64, ptr %97, align 8, !tbaa !20
  %99 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %99, i32 0, i32 3
  %101 = load i64, ptr %100, align 8, !tbaa !11
  %102 = icmp ult i64 %98, %101
  br i1 %102, label %103, label %104

103:                                              ; preds = %95
  store i64 1, ptr %4, align 8, !tbaa !9
  br label %105

104:                                              ; preds = %95
  br label %105

105:                                              ; preds = %104, %103
  br label %106

106:                                              ; preds = %105, %94
  br label %108

107:                                              ; preds = %1
  br label %108

108:                                              ; preds = %107, %106
  %109 = load i64, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i64 %109
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 88}
!12 = !{!"tskTaskControlBlock", !6, i64 0, !13, i64 8, !13, i64 48, !10, i64 88, !6, i64 96, !7, i64 104, !10, i64 120, !10, i64 128, !14, i64 136, !7, i64 140, !7, i64 141}
!13 = !{!"xLIST_ITEM", !14, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !14, i64 48}
!16 = !{!12, !6, i64 40}
!17 = !{!18, !10, i64 0}
!18 = !{!"xLIST", !10, i64 0, !6, i64 8, !19, i64 16}
!19 = !{!"xMINI_LIST_ITEM", !14, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!12, !10, i64 120}


; 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

declare i64 @uxListRemove(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 2) i64 @xTaskPriorityInherit(ptr noundef %0) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %57, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 88
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !13
  %6 = getelementptr inbounds i8, ptr %5, i64 88
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = icmp ult i64 %4, %7
  br i1 %8, label %9, label %50

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  %11 = load i32, ptr %10, align 8, !tbaa !14
  %12 = icmp sgt i32 %11, -1
  br i1 %12, label %13, label %19

13:                                               ; preds = %9
  %14 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %14, i64 88
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = trunc i64 %16 to i32
  %18 = sub i32 7, %17
  store i32 %18, ptr %10, align 8, !tbaa !14
  br label %19

19:                                               ; preds = %9, %13
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = getelementptr inbounds i8, ptr %0, i64 40
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %4
  %24 = icmp eq ptr %22, %23
  br i1 %24, label %25, label %46

25:                                               ; preds = %19
  %26 = tail call i64 @uxListRemove(ptr noundef nonnull %20) #2
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %28, label %38

28:                                               ; preds = %25
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %29
  %31 = load volatile i64, ptr %30, align 8, !tbaa !16
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %33, label %38

33:                                               ; preds = %28
  %34 = shl nuw i64 1, %29
  %35 = xor i64 %34, -1
  %36 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !19
  %37 = and i64 %36, %35
  store volatile i64 %37, ptr @uxTopReadyPriority, align 8, !tbaa !19
  br label %38

38:                                               ; preds = %25, %28, %33
  %39 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !13
  %40 = getelementptr inbounds i8, ptr %39, i64 88
  %41 = load i64, ptr %40, align 8, !tbaa !5
  store i64 %41, ptr %3, align 8, !tbaa !5
  %42 = shl nuw i64 1, %41
  %43 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !19
  %44 = or i64 %43, %42
  store volatile i64 %44, ptr @uxTopReadyPriority, align 8, !tbaa !19
  %45 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %41
  tail call void @vListInsertEnd(ptr noundef nonnull %45, ptr noundef nonnull %20) #2
  br label %57

46:                                               ; preds = %19
  %47 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !13
  %48 = getelementptr inbounds i8, ptr %47, i64 88
  %49 = load i64, ptr %48, align 8, !tbaa !5
  store i64 %49, ptr %3, align 8, !tbaa !5
  br label %57

50:                                               ; preds = %2
  %51 = getelementptr inbounds i8, ptr %0, i64 120
  %52 = load i64, ptr %51, align 8, !tbaa !20
  %53 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !13
  %54 = getelementptr inbounds i8, ptr %53, i64 88
  %55 = load i64, ptr %54, align 8, !tbaa !5
  %56 = icmp ult i64 %52, %55
  %spec.select = zext i1 %56 to i64
  br label %57

57:                                               ; preds = %50, %38, %46, %1
  %.0 = phi i64 [ 0, %1 ], [ 1, %46 ], [ 1, %38 ], [ %spec.select, %50 ]
  ret i64 %.0
}

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


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