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

; 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: alwaysinline nounwind uwtable
declare hidden void @vPortRaiseBASEPRI() #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 %116

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

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

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 15, %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 [15 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %77
  %79 = icmp eq ptr %76, %78
  %80 = zext i1 %79 to i64
  %81 = select i1 %79, i64 1, i64 0
  %82 = icmp ne i64 %81, 0
  br i1 %82, label %83, label %110

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

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 = shl i64 1, %91
  %93 = xor i64 %92, -1
  %94 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %95 = and i64 %94, %93
  store volatile i64 %95, ptr @uxTopReadyPriority, align 8, !tbaa !9
  br label %97

96:                                               ; preds = %83
  br label %97

97:                                               ; preds = %96, %88
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %98, i32 0, i32 3
  %100 = load i64, ptr %99, align 8, !tbaa !16
  %101 = shl i64 1, %100
  %102 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %103 = or i64 %102, %101
  store volatile i64 %103, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %104 = load ptr, ptr %5, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %104, i32 0, i32 3
  %106 = load i64, ptr %105, align 8, !tbaa !16
  %107 = getelementptr inbounds [15 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %106
  %108 = load ptr, ptr %5, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %108, i32 0, i32 1
  call void @vListInsertEnd(ptr noundef %107, ptr noundef %109)
  br label %111

110:                                              ; preds = %72
  br label %111

111:                                              ; preds = %110, %97
  br label %113

112:                                              ; preds = %37
  br label %113

113:                                              ; preds = %112, %111
  br label %115

114:                                              ; preds = %31
  br label %115

115:                                              ; preds = %114, %113
  br label %117

116:                                              ; preds = %2
  br label %117

117:                                              ; preds = %116, %115
  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 = { "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 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 144}
!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, !10, i64 136}
!16 = !{!12, !10, i64 88}
!17 = !{!12, !14, i64 48}
!18 = !{!12, !6, i64 40}


; 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: alwaysinline nounwind uwtable
declare hidden void @vPortRaiseBASEPRI() 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 %43, label %3

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 144
  %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 136
  %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
  %.not26 = icmp ne i64 %13, %.
  %14 = icmp eq i64 %5, 1
  %or.cond = and i1 %14, %.not26
  br i1 %or.cond, label %15, label %43

15:                                               ; preds = %9
  %16 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !15
  %.not27 = icmp eq ptr %16, %0
  br i1 %.not27, 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 15, %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 [15 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %13
  %31 = icmp eq ptr %29, %30
  br i1 %31, label %32, label %43

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
  %35 = shl nuw i64 1, %.pre
  br i1 %34, label %36, label %._crit_edge

36:                                               ; preds = %32
  %37 = xor i64 %35, -1
  %38 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !18
  %39 = and i64 %38, %37
  store volatile i64 %39, ptr @uxTopReadyPriority, align 8, !tbaa !18
  br label %._crit_edge

._crit_edge:                                      ; preds = %32, %36
  %40 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !18
  %41 = or i64 %40, %35
  store volatile i64 %41, ptr @uxTopReadyPriority, align 8, !tbaa !18
  %42 = getelementptr inbounds [15 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %.pre
  tail call void @vListInsertEnd(ptr noundef nonnull %42, ptr noundef nonnull %27) #4
  br label %43

43:                                               ; preds = %2, %._crit_edge, %26, %9
  ret void
}

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

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 = { 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 = { 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 144}
!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 = !{!6, !12, i64 136}
!14 = !{!6, !12, i64 88}
!15 = !{!7, !7, i64 0}
!16 = !{!6, !11, i64 48}
!17 = !{!6, !7, i64 40}
!18 = !{!12, !12, i64 0}


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