; LLVM IR from Eslam-Rizk/Elite-DriveGuard :: Application/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, i64, i64, i32, i8, i8 }
%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 [56 x %struct.xLIST], align 16
@uxTopReadyPriority = 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
declare hidden i64 @prvTaskIsTaskSuspended(ptr noundef) #3

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

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

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

11:                                               ; preds = %1
  call void @vPortValidateInterruptPriority()
  %12 = call i32 @ulPortRaiseBASEPRI()
  %13 = zext i32 %12 to i64
  store i64 %13, ptr %5, align 8, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call i64 @prvTaskIsTaskSuspended(ptr noundef %14)
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %17, label %54

17:                                               ; preds = %11
  %18 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !9
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %50

20:                                               ; preds = %17
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %21, i32 0, i32 3
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %24, i32 0, i32 3
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = icmp uge i64 %23, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %20
  store i64 1, ptr %3, align 8, !tbaa !9
  br label %30

29:                                               ; preds = %20
  br label %30

30:                                               ; preds = %29, %28
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %31, i32 0, i32 1
  %33 = call i64 @uxListRemove(ptr noundef %32)
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %34, i32 0, i32 3
  %36 = load i64, ptr %35, align 8, !tbaa !11
  %37 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %38 = icmp ugt i64 %36, %37
  br i1 %38, label %39, label %43

39:                                               ; preds = %30
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %40, i32 0, i32 3
  %42 = load i64, ptr %41, align 8, !tbaa !11
  store volatile i64 %42, ptr @uxTopReadyPriority, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %39, %30
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %44, i32 0, i32 3
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = getelementptr inbounds [56 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %46
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %48, i32 0, i32 1
  call void @vListInsertEnd(ptr noundef %47, ptr noundef %49)
  br label %53

50:                                               ; preds = %17
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %51, i32 0, i32 2
  call void @vListInsertEnd(ptr noundef @xPendingReadyList, ptr noundef %52)
  br label %53

53:                                               ; preds = %50, %43
  br label %55

54:                                               ; preds = %11
  br label %55

55:                                               ; preds = %54, %53
  %56 = load i64, ptr %5, align 8, !tbaa !9
  %57 = trunc i64 %56 to i32
  call void @vPortSetBASEPRI(i32 noundef %57)
  %58 = load i64, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret i64 %58
}

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 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, !10, i64 136, !10, i64 144, !14, i64 152, !7, i64 156, !7, i64 157}
!13 = !{!"xLIST_ITEM", !14, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!14 = !{!"int", !7, i64 0}


; 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 [56 x %struct.xLIST], align 16
@uxTopReadyPriority = 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
declare hidden i64 @prvTaskIsTaskSuspended(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 2) i64 @xTaskResumeFromISR(ptr noundef %0) local_unnamed_addr #2 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %3, label %5

3:                                                ; preds = %1
  tail call void @vPortRaiseBASEPRI()
  br label %4

4:                                                ; preds = %4, %3
  br label %4

5:                                                ; preds = %1
  tail call void @vPortValidateInterruptPriority() #3
  %6 = tail call i32 @ulPortRaiseBASEPRI()
  %7 = tail call i64 @prvTaskIsTaskSuspended(ptr noundef nonnull %0)
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %27, label %8

8:                                                ; preds = %5
  %9 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !5
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %25

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 88
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %14, i64 88
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %.not12 = icmp uge i64 %13, %16
  %spec.select = zext i1 %.not12 to i64
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = tail call i64 @uxListRemove(ptr noundef nonnull %17) #3
  %19 = load i64, ptr %12, align 8, !tbaa !9
  %20 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !5
  %21 = icmp ugt i64 %19, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %11
  store volatile i64 %19, ptr @uxTopReadyPriority, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %22, %11
  %24 = getelementptr inbounds [56 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %19
  tail call void @vListInsertEnd(ptr noundef nonnull %24, ptr noundef nonnull %17) #3
  br label %27

25:                                               ; preds = %8
  %26 = getelementptr inbounds i8, ptr %0, i64 48
  tail call void @vListInsertEnd(ptr noundef nonnull @xPendingReadyList, ptr noundef nonnull %26) #3
  br label %27

27:                                               ; preds = %5, %23, %25
  %.1 = phi i64 [ %spec.select, %23 ], [ 0, %25 ], [ 0, %5 ]
  tail call void @vPortSetBASEPRI(i32 noundef %6)
  ret i64 %.1
}

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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 88}
!10 = !{!"tskTaskControlBlock", !11, i64 0, !12, i64 8, !12, i64 48, !6, i64 88, !11, i64 96, !7, i64 104, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !13, i64 152, !7, i64 156, !7, i64 157}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"xLIST_ITEM", !13, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = !{!11, !11, i64 0}


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