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

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

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %13, i32 0, i32 7
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %12
  call void @vPortRaiseBASEPRI()
  br label %18

18:                                               ; preds = %18, %17
  br label %18

19:                                               ; preds = %12
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %20, i32 0, i32 6
  %22 = load i64, ptr %21, align 8, !tbaa !15
  %23 = load i64, ptr %4, align 8, !tbaa !9
  %24 = icmp ult i64 %22, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %19
  %26 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %26, ptr %7, align 8, !tbaa !9
  br label %31

27:                                               ; preds = %19
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %28, i32 0, i32 6
  %30 = load i64, ptr %29, align 8, !tbaa !15
  store i64 %30, ptr %7, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %27, %25
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %32, i32 0, i32 3
  %34 = load i64, ptr %33, align 8, !tbaa !16
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = icmp ne i64 %34, %35
  br i1 %36, label %37, label %123

37:                                               ; preds = %31
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %38, i32 0, i32 7
  %40 = load i64, ptr %39, align 8, !tbaa !11
  %41 = icmp eq i64 %40, 1
  br i1 %41, label %42, label %121

42:                                               ; preds = %37
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %45 = icmp ne ptr %43, %44
  %46 = zext i1 %45 to i32
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %50

48:                                               ; preds = %42
  call void @vPortRaiseBASEPRI()
  br label %49

49:                                               ; preds = %49, %48
  br label %49

50:                                               ; preds = %42
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %51, i32 0, i32 3
  %53 = load i64, ptr %52, align 8, !tbaa !16
  store i64 %53, ptr %6, align 8, !tbaa !9
  %54 = load i64, ptr %7, align 8, !tbaa !9
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %55, i32 0, i32 3
  store i64 %54, ptr %56, align 8, !tbaa !16
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %57, i32 0, i32 2
  %59 = getelementptr inbounds %struct.xLIST_ITEM, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 8, !tbaa !17
  %61 = zext i32 %60 to i64
  %62 = and i64 %61, 2147483648
  %63 = icmp eq i64 %62, 0
  br i1 %63, label %64, label %71

64:                                               ; preds = %50
  %65 = load i64, ptr %7, align 8, !tbaa !9
  %66 = trunc i64 %65 to i32
  %67 = sub i32 7, %66
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %68, i32 0, i32 2
  %70 = getelementptr inbounds %struct.xLIST_ITEM, ptr %69, i32 0, i32 0
  store i32 %67, ptr %70, align 8, !tbaa !17
  br label %72

71:                                               ; preds = %50
  br label %72

72:                                               ; preds = %71, %64
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %73, i32 0, i32 1
  %75 = getelementptr inbounds %struct.xLIST_ITEM, ptr %74, i32 0, i32 4
  %76 = load ptr, ptr %75, align 8, !tbaa !18
  %77 = load i64, ptr %6, align 8, !tbaa !9
  %78 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %77
  %79 = icmp eq ptr %76, %78
  %80 = zext i1 %79 to i32
  %81 = sext i32 %80 to i64
  %82 = icmp ne i64 %81, 0
  br i1 %82, label %83, label %119

83:                                               ; preds = %72
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %84, i32 0, i32 1
  %86 = call i64 @uxListRemove(ptr noundef %85)
  %87 = icmp eq i64 %86, 0
  br i1 %87, label %88, label %105

88:                                               ; preds = %83
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %89, i32 0, i32 3
  %91 = load i64, ptr %90, align 8, !tbaa !16
  %92 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %91
  %93 = getelementptr inbounds %struct.xLIST, ptr %92, i32 0, i32 0
  %94 = load volatile i64, ptr %93, align 8, !tbaa !19
  %95 = icmp eq i64 %94, 0
  br i1 %95, label %96, label %104

96:                                               ; preds = %88
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %97, i32 0, i32 3
  %99 = load i64, ptr %98, align 8, !tbaa !16
  %100 = shl i64 1, %99
  %101 = xor i64 %100, -1
  %102 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %103 = and i64 %102, %101
  store volatile i64 %103, ptr @uxTopReadyPriority, align 8, !tbaa !9
  br label %104

104:                                              ; preds = %96, %88
  br label %106

105:                                              ; preds = %83
  br label %106

106:                                              ; preds = %105, %104
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %107, i32 0, i32 3
  %109 = load i64, ptr %108, align 8, !tbaa !16
  %110 = shl i64 1, %109
  %111 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %112 = or i64 %111, %110
  store volatile i64 %112, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %113 = load ptr, ptr %5, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %113, i32 0, i32 3
  %115 = load i64, ptr %114, align 8, !tbaa !16
  %116 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %115
  %117 = load ptr, ptr %5, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %117, i32 0, i32 1
  call void @vListInsertEnd(ptr noundef %116, ptr noundef %118)
  br label %120

119:                                              ; preds = %72
  br label %120

120:                                              ; preds = %119, %106
  br label %122

121:                                              ; preds = %37
  br label %122

122:                                              ; preds = %121, %120
  br label %124

123:                                              ; preds = %31
  br label %124

124:                                              ; preds = %123, %122
  br label %126

125:                                              ; preds = %2
  br label %126

126:                                              ; preds = %125, %124
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #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 = !{!12, !10, i64 128}
!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, !10, i64 120}
!16 = !{!12, !10, i64 88}
!17 = !{!12, !14, i64 48}
!18 = !{!12, !6, i64 40}
!19 = !{!20, !10, i64 0}
!20 = !{!"xLIST", !10, i64 0, !6, i64 8, !21, i64 16}
!21 = !{!"xMINI_LIST_ITEM", !14, i64 0, !6, i64 8, !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.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

; 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

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

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 128
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %3
  tail call void @vPortRaiseBASEPRI()
  br label %8

8:                                                ; preds = %8, %7
  br label %8

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 120
  %11 = load i64, ptr %10, align 8, !tbaa !13
  %. = tail call i64 @llvm.umax.i64(i64 %11, i64 %1)
  %12 = getelementptr inbounds i8, ptr %0, i64 88
  %13 = load i64, ptr %12, align 8, !tbaa !14
  %.not27 = icmp ne i64 %13, %.
  %14 = icmp eq i64 %5, 1
  %or.cond = and i1 %14, %.not27
  br i1 %or.cond, label %15, label %49

15:                                               ; preds = %9
  %16 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !15
  %.not28 = icmp eq ptr %16, %0
  br i1 %.not28, label %17, label %19

17:                                               ; preds = %15
  tail call void @vPortRaiseBASEPRI()
  br label %18

18:                                               ; preds = %18, %17
  br label %18

19:                                               ; preds = %15
  store i64 %., ptr %12, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %0, i64 48
  %21 = load i32, ptr %20, align 8, !tbaa !16
  %22 = icmp sgt i32 %21, -1
  br i1 %22, label %23, label %26

23:                                               ; preds = %19
  %24 = trunc i64 %. to i32
  %25 = sub i32 7, %24
  store i32 %25, ptr %20, align 8, !tbaa !16
  br label %26

26:                                               ; preds = %19, %23
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  %28 = getelementptr inbounds i8, ptr %0, i64 40
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  %30 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %13
  %31 = icmp eq ptr %29, %30
  br i1 %31, label %32, label %49

32:                                               ; preds = %26
  %33 = tail call i64 @uxListRemove(ptr noundef nonnull %27) #4
  %34 = icmp eq i64 %33, 0
  %.pre = load i64, ptr %12, align 8, !tbaa !14
  br i1 %34, label %35, label %44

35:                                               ; preds = %32
  %36 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %.pre
  %37 = load volatile i64, ptr %36, align 8, !tbaa !18
  %38 = icmp eq i64 %37, 0
  br i1 %38, label %39, label %44

39:                                               ; preds = %35
  %40 = shl nuw i64 1, %.pre
  %41 = xor i64 %40, -1
  %42 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !21
  %43 = and i64 %42, %41
  store volatile i64 %43, ptr @uxTopReadyPriority, align 8, !tbaa !21
  br label %44

44:                                               ; preds = %32, %35, %39
  %45 = shl nuw i64 1, %.pre
  %46 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !21
  %47 = or i64 %46, %45
  store volatile i64 %47, ptr @uxTopReadyPriority, align 8, !tbaa !21
  %48 = getelementptr inbounds [7 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %.pre
  tail call void @vListInsertEnd(ptr noundef nonnull %48, ptr noundef nonnull %27) #4
  br label %49

49:                                               ; preds = %2, %44, %26, %9
  ret void
}

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

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 = { 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, !12, i64 128}
!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 = !{!6, !12, i64 120}
!14 = !{!6, !12, i64 88}
!15 = !{!7, !7, i64 0}
!16 = !{!6, !11, i64 48}
!17 = !{!6, !7, i64 40}
!18 = !{!19, !12, i64 0}
!19 = !{!"xLIST", !12, i64 0, !7, i64 8, !20, i64 16}
!20 = !{!"xMINI_LIST_ITEM", !11, i64 0, !7, i64 8, !7, i64 16}
!21 = !{!12, !12, i64 0}


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