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

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

; 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 %98

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 %86

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 15, %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 [15 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %41
  %43 = icmp eq ptr %38, %42
  %44 = zext i1 %43 to i64
  %45 = select i1 %43, i64 1, i64 0
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %47, label %79

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 %60

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 = shl i64 1, %55
  %57 = xor i64 %56, -1
  %58 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %59 = and i64 %58, %57
  store volatile i64 %59, ptr @uxTopReadyPriority, align 8, !tbaa !9
  br label %61

60:                                               ; preds = %47
  br label %61

61:                                               ; preds = %60, %52
  %62 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %62, i32 0, i32 3
  %64 = load i64, ptr %63, align 8, !tbaa !11
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %65, i32 0, i32 3
  store i64 %64, ptr %66, align 8, !tbaa !11
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %67, i32 0, i32 3
  %69 = load i64, ptr %68, align 8, !tbaa !11
  %70 = shl i64 1, %69
  %71 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %72 = or i64 %71, %70
  store volatile i64 %72, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %73, i32 0, i32 3
  %75 = load i64, ptr %74, align 8, !tbaa !11
  %76 = getelementptr inbounds [15 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %75
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %77, i32 0, i32 1
  call void @vListInsertEnd(ptr noundef %76, ptr noundef %78)
  br label %85

79:                                               ; preds = %34
  %80 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %80, i32 0, i32 3
  %82 = load i64, ptr %81, align 8, !tbaa !11
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %83, i32 0, i32 3
  store i64 %82, ptr %84, align 8, !tbaa !11
  br label %85

85:                                               ; preds = %79, %61
  store i64 1, ptr %4, align 8, !tbaa !9
  br label %97

86:                                               ; preds = %8
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %87, i32 0, i32 6
  %89 = load i64, ptr %88, align 8, !tbaa !17
  %90 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %90, i32 0, i32 3
  %92 = load i64, ptr %91, align 8, !tbaa !11
  %93 = icmp ult i64 %89, %92
  br i1 %93, label %94, label %95

94:                                               ; preds = %86
  store i64 1, ptr %4, align 8, !tbaa !9
  br label %96

95:                                               ; preds = %86
  br label %96

96:                                               ; preds = %95, %94
  br label %97

97:                                               ; preds = %96, %85
  br label %99

98:                                               ; preds = %1
  br label %99

99:                                               ; preds = %98, %97
  %100 = 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 %100
}

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 136, !10, i64 144, !7, i64 152, !7, i64 156}
!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 = !{!12, !10, i64 136}


; 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

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 %53, 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 %46

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 15, %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 [15 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %4
  %24 = icmp eq ptr %22, %23
  br i1 %24, label %25, label %42

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 %34

28:                                               ; preds = %25
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = shl nuw i64 1, %29
  %31 = xor i64 %30, -1
  %32 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !16
  %33 = and i64 %32, %31
  store volatile i64 %33, ptr @uxTopReadyPriority, align 8, !tbaa !16
  br label %34

34:                                               ; preds = %25, %28
  %35 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !13
  %36 = getelementptr inbounds i8, ptr %35, i64 88
  %37 = load i64, ptr %36, align 8, !tbaa !5
  store i64 %37, ptr %3, align 8, !tbaa !5
  %38 = shl nuw i64 1, %37
  %39 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !16
  %40 = or i64 %39, %38
  store volatile i64 %40, ptr @uxTopReadyPriority, align 8, !tbaa !16
  %41 = getelementptr inbounds [15 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %37
  tail call void @vListInsertEnd(ptr noundef nonnull %41, ptr noundef nonnull %20) #2
  br label %53

42:                                               ; preds = %19
  %43 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !13
  %44 = getelementptr inbounds i8, ptr %43, i64 88
  %45 = load i64, ptr %44, align 8, !tbaa !5
  store i64 %45, ptr %3, align 8, !tbaa !5
  br label %53

46:                                               ; preds = %2
  %47 = getelementptr inbounds i8, ptr %0, i64 136
  %48 = load i64, ptr %47, align 8, !tbaa !17
  %49 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !13
  %50 = getelementptr inbounds i8, ptr %49, i64 88
  %51 = load i64, ptr %50, align 8, !tbaa !5
  %52 = icmp ult i64 %48, %51
  %spec.select = zext i1 %52 to i64
  br label %53

53:                                               ; preds = %46, %34, %42, %1
  %.0 = phi i64 [ 0, %1 ], [ 1, %42 ], [ 1, %34 ], [ %spec.select, %46 ]
  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 136, !12, i64 144, !8, i64 152, !8, i64 156}
!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 = !{!12, !12, i64 0}
!17 = !{!6, !12, i64 136}


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