; LLVM IR from whoiswelliton/Computer_Engineering_UTFPR-PB :: Embedded_Systems/TIVA Connected TM4C1294XL Projects/00 - freeRTOS10_on_TIVA (xTaskResumeAll)

; 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.xLIST_ITEM = type { i32, ptr, ptr, ptr, ptr }
%struct.tskTaskControlBlock = type { ptr, %struct.xLIST_ITEM, %struct.xLIST_ITEM, i64, ptr, [32 x i8], i64, i64, [1 x i32], [1 x i8] }

@pxCurrentTCB = external dso_local global ptr, align 8
@pxReadyTasksLists = external hidden global [15 x %struct.xLIST], align 16
@uxTopReadyPriority = external hidden global i64, align 8
@uxCurrentNumberOfTasks = external hidden global i64, align 8
@uxSchedulerSuspended = external hidden global i64, align 8
@xPendingReadyList = external hidden global %struct.xLIST, align 8
@xYieldPending = external hidden global i64, align 8
@xPendedTicks = external hidden global i32, align 4

; 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 void @vPortEnterCritical() #1

declare i64 @uxListRemove(ptr noundef) #1

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

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

declare void @vPortExitCritical() #1

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

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

6:                                                ; preds = %0
  call void @vPortRaiseBASEPRI()
  br label %7

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

8:                                                ; preds = %0
  call void @vPortEnterCritical()
  %9 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !9
  %10 = add i64 %9, -1
  store volatile i64 %10, ptr @uxSchedulerSuspended, align 8, !tbaa !9
  %11 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !9
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %84

13:                                               ; preds = %8
  %14 = load volatile i64, ptr @uxCurrentNumberOfTasks, align 8, !tbaa !9
  %15 = icmp ugt i64 %14, 0
  br i1 %15, label %16, label %83

16:                                               ; preds = %13
  br label %17

17:                                               ; preds = %54, %16
  %18 = load volatile i64, ptr @xPendingReadyList, align 8, !tbaa !11
  %19 = icmp eq i64 %18, 0
  %20 = zext i1 %19 to i64
  %21 = select i1 %19, i64 1, i64 0
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %55

23:                                               ; preds = %17
  %24 = load ptr, ptr getelementptr inbounds (%struct.xMINI_LIST_ITEM, ptr getelementptr inbounds (%struct.xLIST, ptr @xPendingReadyList, i32 0, i32 2), i32 0, i32 1), align 8, !tbaa !15
  %25 = getelementptr inbounds %struct.xLIST_ITEM, ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  store ptr %26, ptr %1, align 8, !tbaa !5
  %27 = load ptr, ptr %1, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %27, i32 0, i32 2
  %29 = call i64 @uxListRemove(ptr noundef %28)
  %30 = load ptr, ptr %1, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %30, i32 0, i32 1
  %32 = call i64 @uxListRemove(ptr noundef %31)
  %33 = load ptr, ptr %1, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %33, i32 0, i32 3
  %35 = load i64, ptr %34, align 8, !tbaa !18
  %36 = shl i64 1, %35
  %37 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %38 = or i64 %37, %36
  store volatile i64 %38, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %39 = load ptr, ptr %1, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %39, i32 0, i32 3
  %41 = load i64, ptr %40, align 8, !tbaa !18
  %42 = getelementptr inbounds [15 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %41
  %43 = load ptr, ptr %1, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %43, i32 0, i32 1
  call void @vListInsertEnd(ptr noundef %42, ptr noundef %44)
  %45 = load ptr, ptr %1, 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 ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %48, i32 0, i32 3
  %50 = load i64, ptr %49, align 8, !tbaa !18
  %51 = icmp uge i64 %47, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %23
  store volatile i64 1, ptr @xYieldPending, align 8, !tbaa !9
  br label %54

53:                                               ; preds = %23
  br label %54

54:                                               ; preds = %53, %52
  br label %17, !llvm.loop !20

55:                                               ; preds = %17
  %56 = load ptr, ptr %1, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %59

58:                                               ; preds = %55
  call void @prvResetNextTaskUnblockTime()
  br label %59

59:                                               ; preds = %58, %55
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %60 = load volatile i32, ptr @xPendedTicks, align 4, !tbaa !22
  store i32 %60, ptr %3, align 4, !tbaa !22
  %61 = load i32, ptr %3, align 4, !tbaa !22
  %62 = icmp ugt i32 %61, 0
  br i1 %62, label %63, label %76

63:                                               ; preds = %59
  br label %64

64:                                               ; preds = %72, %63
  %65 = call i64 @xTaskIncrementTick()
  %66 = icmp ne i64 %65, 0
  br i1 %66, label %67, label %68

67:                                               ; preds = %64
  store volatile i64 1, ptr @xYieldPending, align 8, !tbaa !9
  br label %69

68:                                               ; preds = %64
  br label %69

69:                                               ; preds = %68, %67
  %70 = load i32, ptr %3, align 4, !tbaa !22
  %71 = add i32 %70, -1
  store i32 %71, ptr %3, align 4, !tbaa !22
  br label %72

72:                                               ; preds = %69
  %73 = load i32, ptr %3, align 4, !tbaa !22
  %74 = icmp ugt i32 %73, 0
  br i1 %74, label %64, label %75, !llvm.loop !23

75:                                               ; preds = %72
  store volatile i32 0, ptr @xPendedTicks, align 4, !tbaa !22
  br label %77

76:                                               ; preds = %59
  br label %77

77:                                               ; preds = %76, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  %78 = load volatile i64, ptr @xYieldPending, align 8, !tbaa !9
  %79 = icmp ne i64 %78, 0
  br i1 %79, label %80, label %81

80:                                               ; preds = %77
  store i64 1, ptr %2, align 8, !tbaa !9
  store volatile i32 268435456, ptr inttoptr (i64 3758157060 to ptr), align 4, !tbaa !22
  call void asm sideeffect "dsb", "~{memory},~{dirflag},~{fpsr},~{flags}"() #4, !srcloc !24
  call void asm sideeffect "isb", "~{dirflag},~{fpsr},~{flags}"() #4, !srcloc !25
  br label %82

81:                                               ; preds = %77
  br label %82

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

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

84:                                               ; preds = %8
  br label %85

85:                                               ; preds = %84, %83
  call void @vPortExitCritical()
  %86 = load i64, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret i64 %86
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @xTaskIncrementTick() #2

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 = { 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 #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 0}
!12 = !{!"xLIST", !10, i64 0, !6, i64 8, !13, i64 16}
!13 = !{!"xMINI_LIST_ITEM", !14, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !6, i64 24}
!16 = !{!17, !6, i64 24}
!17 = !{!"xLIST_ITEM", !14, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!18 = !{!19, !10, i64 88}
!19 = !{!"tskTaskControlBlock", !6, i64 0, !17, i64 8, !17, i64 48, !10, i64 88, !6, i64 96, !7, i64 104, !10, i64 136, !10, i64 144, !7, i64 152, !7, i64 156}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!14, !14, i64 0}
!23 = distinct !{!23, !21}
!24 = !{i64 2148440711}
!25 = !{i64 2148440780}


; 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 [15 x %struct.xLIST], align 16
@uxTopReadyPriority = external hidden global i64, align 8
@uxCurrentNumberOfTasks = external hidden global i64, align 8
@uxSchedulerSuspended = external hidden global i64, align 8
@xPendingReadyList = external hidden global %struct.xLIST, align 8
@xYieldPending = external hidden global i64, align 8
@xPendedTicks = external hidden global i32, align 4

declare void @vPortEnterCritical() local_unnamed_addr #0

declare i64 @uxListRemove(ptr noundef) local_unnamed_addr #0

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

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

declare void @vPortExitCritical() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 2) i64 @xTaskResumeAll() local_unnamed_addr #1 {
  %1 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !5
  %2 = icmp eq i64 %1, 0
  br i1 %2, label %3, label %5

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

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

5:                                                ; preds = %0
  tail call void @vPortEnterCritical() #3
  %6 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !5
  %7 = add i64 %6, -1
  store volatile i64 %7, ptr @uxSchedulerSuspended, align 8, !tbaa !5
  %8 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !5
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %10, label %42

10:                                               ; preds = %5
  %11 = load volatile i64, ptr @uxCurrentNumberOfTasks, align 8, !tbaa !5
  %.not = icmp eq i64 %11, 0
  br i1 %.not, label %42, label %.preheader21

.preheader21:                                     ; preds = %10
  %12 = load volatile i64, ptr @xPendingReadyList, align 8, !tbaa !9
  %.not1422 = icmp eq i64 %12, 0
  br i1 %.not1422, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader21, %31
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @xPendingReadyList, i64 24), align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %13, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %15, i64 48
  %17 = tail call i64 @uxListRemove(ptr noundef nonnull %16) #3
  %18 = getelementptr inbounds i8, ptr %15, i64 8
  %19 = tail call i64 @uxListRemove(ptr noundef nonnull %18) #3
  %20 = getelementptr inbounds i8, ptr %15, i64 88
  %21 = load i64, ptr %20, align 8, !tbaa !17
  %22 = shl nuw i64 1, %21
  %23 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !5
  %24 = or i64 %23, %22
  store volatile i64 %24, ptr @uxTopReadyPriority, align 8, !tbaa !5
  %25 = getelementptr inbounds [15 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %21
  tail call void @vListInsertEnd(ptr noundef nonnull %25, ptr noundef nonnull %18) #3
  %26 = load i64, ptr %20, align 8, !tbaa !17
  %27 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !19
  %28 = getelementptr inbounds i8, ptr %27, i64 88
  %29 = load i64, ptr %28, align 8, !tbaa !17
  %.not20 = icmp ult i64 %26, %29
  br i1 %.not20, label %31, label %30

30:                                               ; preds = %.lr.ph
  store volatile i64 1, ptr @xYieldPending, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %.lr.ph, %30
  %32 = load volatile i64, ptr @xPendingReadyList, align 8, !tbaa !9
  %.not14 = icmp eq i64 %32, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph, !llvm.loop !20

._crit_edge:                                      ; preds = %31
  tail call void @prvResetNextTaskUnblockTime()
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.preheader21, %._crit_edge
  %33 = load volatile i32, ptr @xPendedTicks, align 4, !tbaa !22
  %.not16 = icmp eq i32 %33, 0
  br i1 %.not16, label %39, label %.preheader

.preheader:                                       ; preds = %._crit_edge.thread, %36
  %.0 = phi i32 [ %37, %36 ], [ %33, %._crit_edge.thread ]
  %34 = tail call i64 @xTaskIncrementTick()
  %.not17 = icmp eq i64 %34, 0
  br i1 %.not17, label %36, label %35

35:                                               ; preds = %.preheader
  store volatile i64 1, ptr @xYieldPending, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %.preheader, %35
  %37 = add i32 %.0, -1
  %.not18 = icmp eq i32 %37, 0
  br i1 %.not18, label %38, label %.preheader, !llvm.loop !23

38:                                               ; preds = %36
  store volatile i32 0, ptr @xPendedTicks, align 4, !tbaa !22
  br label %39

39:                                               ; preds = %._crit_edge.thread, %38
  %40 = load volatile i64, ptr @xYieldPending, align 8, !tbaa !5
  %.not19 = icmp eq i64 %40, 0
  br i1 %.not19, label %42, label %41

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

42:                                               ; preds = %5, %10, %39, %41
  %.010 = phi i64 [ 1, %41 ], [ 0, %39 ], [ 0, %10 ], [ 0, %5 ]
  tail call void @vPortExitCritical() #3
  ret i64 %.010
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @xTaskIncrementTick() local_unnamed_addr #1

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 = { 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 #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 0}
!10 = !{!"xLIST", !6, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"xMINI_LIST_ITEM", !13, i64 0, !11, i64 8, !11, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !11, i64 24}
!15 = !{!16, !11, i64 24}
!16 = !{!"xLIST_ITEM", !13, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!17 = !{!18, !6, i64 88}
!18 = !{!"tskTaskControlBlock", !11, i64 0, !16, i64 8, !16, i64 48, !6, i64 88, !11, i64 96, !7, i64 104, !6, i64 136, !6, i64 144, !7, i64 152, !7, i64 156}
!19 = !{!11, !11, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!13, !13, i64 0}
!23 = distinct !{!23, !21}
!24 = !{i64 2148440711}
!25 = !{i64 2148440780}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass