; 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
@xYieldPending = 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

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 @vTaskNotifyGiveFromISR(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %12

10:                                               ; preds = %2
  call void @vPortRaiseBASEPRI()
  br label %11

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

12:                                               ; preds = %2
  call void @vPortValidateInterruptPriority()
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %13, ptr %5, align 8, !tbaa !5
  %14 = call i32 @ulPortRaiseBASEPRI()
  %15 = zext i32 %14 to i64
  store i64 %15, ptr %7, align 8, !tbaa !9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %16, i32 0, i32 11
  %18 = load volatile i8, ptr %17, align 4, !tbaa !11
  store i8 %18, ptr %6, align 1, !tbaa !15
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %19, i32 0, i32 11
  store volatile i8 2, ptr %20, align 4, !tbaa !11
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %21, i32 0, i32 10
  %23 = load volatile i32, ptr %22, align 8, !tbaa !16
  %24 = add i32 %23, 1
  store volatile i32 %24, ptr %22, align 8, !tbaa !16
  %25 = load i8, ptr %6, align 1, !tbaa !15
  %26 = zext i8 %25 to i32
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %80

28:                                               ; preds = %12
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %29, i32 0, i32 2
  %31 = getelementptr inbounds %struct.xLIST_ITEM, ptr %30, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = icmp eq ptr %32, null
  %34 = zext i1 %33 to i32
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %28
  call void @vPortRaiseBASEPRI()
  br label %37

37:                                               ; preds = %37, %36
  br label %37

38:                                               ; preds = %28
  %39 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !9
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %41, label %61

41:                                               ; preds = %38
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %42, i32 0, i32 1
  %44 = call i64 @uxListRemove(ptr noundef %43)
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %45, i32 0, i32 3
  %47 = load i64, ptr %46, align 8, !tbaa !18
  %48 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %49 = icmp ugt i64 %47, %48
  br i1 %49, label %50, label %54

50:                                               ; preds = %41
  %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 !18
  store volatile i64 %53, ptr @uxTopReadyPriority, align 8, !tbaa !9
  br label %54

54:                                               ; preds = %50, %41
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %55, i32 0, i32 3
  %57 = load i64, ptr %56, align 8, !tbaa !18
  %58 = getelementptr inbounds [56 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %57
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %59, i32 0, i32 1
  call void @vListInsertEnd(ptr noundef %58, ptr noundef %60)
  br label %64

61:                                               ; preds = %38
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %62, i32 0, i32 2
  call void @vListInsertEnd(ptr noundef @xPendingReadyList, ptr noundef %63)
  br label %64

64:                                               ; preds = %61, %54
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %65, i32 0, i32 3
  %67 = load i64, ptr %66, align 8, !tbaa !18
  %68 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %68, i32 0, i32 3
  %70 = load i64, ptr %69, align 8, !tbaa !18
  %71 = icmp ugt i64 %67, %70
  br i1 %71, label %72, label %78

72:                                               ; preds = %64
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = icmp ne ptr %73, null
  br i1 %74, label %75, label %77

75:                                               ; preds = %72
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  store i64 1, ptr %76, align 8, !tbaa !9
  br label %77

77:                                               ; preds = %75, %72
  store volatile i64 1, ptr @xYieldPending, align 8, !tbaa !9
  br label %79

78:                                               ; preds = %64
  br label %79

79:                                               ; preds = %78, %77
  br label %80

80:                                               ; preds = %79, %12
  %81 = load i64, ptr %7, align 8, !tbaa !9
  %82 = trunc i64 %81 to i32
  call void @vPortSetBASEPRI(i32 noundef %82)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1, 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, !7, i64 156}
!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}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !14, i64 152}
!17 = !{!12, !6, i64 80}
!18 = !{!12, !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 [56 x %struct.xLIST], align 16
@uxTopReadyPriority = external hidden global i64, align 8
@xPendingReadyList = external hidden global %struct.xLIST, align 8
@xYieldPending = 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

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 @vTaskNotifyGiveFromISR(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #2 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  tail call void @vPortRaiseBASEPRI()
  br label %5

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

6:                                                ; preds = %2
  tail call void @vPortValidateInterruptPriority() #3
  %7 = tail call i32 @ulPortRaiseBASEPRI()
  %8 = getelementptr inbounds i8, ptr %0, i64 156
  %9 = load volatile i8, ptr %8, align 4, !tbaa !5
  store volatile i8 2, ptr %8, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 152
  %11 = load volatile i32, ptr %10, align 8, !tbaa !13
  %12 = add i32 %11, 1
  store volatile i32 %12, ptr %10, align 8, !tbaa !13
  %13 = icmp eq i8 %9, 1
  br i1 %13, label %14, label %44

14:                                               ; preds = %6
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  %16 = getelementptr inbounds i8, ptr %0, i64 80
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %.not = icmp eq ptr %17, null
  br i1 %.not, label %20, label %18

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

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

20:                                               ; preds = %14
  %21 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !15
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %33

23:                                               ; preds = %20
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  %25 = tail call i64 @uxListRemove(ptr noundef nonnull %24) #3
  %26 = getelementptr inbounds i8, ptr %0, i64 88
  %27 = load i64, ptr %26, align 8, !tbaa !16
  %28 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !15
  %29 = icmp ugt i64 %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %23
  store volatile i64 %27, ptr @uxTopReadyPriority, align 8, !tbaa !15
  br label %31

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

33:                                               ; preds = %20
  tail call void @vListInsertEnd(ptr noundef nonnull @xPendingReadyList, ptr noundef nonnull %15) #3
  br label %34

34:                                               ; preds = %33, %31
  %35 = getelementptr inbounds i8, ptr %0, i64 88
  %36 = load i64, ptr %35, align 8, !tbaa !16
  %37 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !17
  %38 = getelementptr inbounds i8, ptr %37, i64 88
  %39 = load i64, ptr %38, align 8, !tbaa !16
  %40 = icmp ugt i64 %36, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %34
  %.not17 = icmp eq ptr %1, null
  br i1 %.not17, label %43, label %42

42:                                               ; preds = %41
  store i64 1, ptr %1, align 8, !tbaa !15
  br label %43

43:                                               ; preds = %42, %41
  store volatile i64 1, ptr @xYieldPending, align 8, !tbaa !15
  br label %44

44:                                               ; preds = %43, %34, %6
  tail call void @vPortSetBASEPRI(i32 noundef %7)
  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, !8, i64 156}
!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, !12, i64 136, !12, i64 144, !11, i64 152, !8, i64 156, !8, i64 157}
!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, !11, i64 152}
!14 = !{!6, !7, i64 80}
!15 = !{!12, !12, i64 0}
!16 = !{!6, !12, i64 88}
!17 = !{!7, !7, i64 0}


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