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

; 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 i64 @xTaskPriorityDisinherit(ptr noundef %0) #3 {
  %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) #4
  %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) #4
  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 %84

8:                                                ; preds = %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %11 = icmp eq ptr %9, %10
  %12 = zext i1 %11 to i32
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %8
  call void @vPortRaiseBASEPRI()
  br label %15

15:                                               ; preds = %15, %14
  br label %15

16:                                               ; preds = %8
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %17, i32 0, i32 7
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %16
  call void @vPortRaiseBASEPRI()
  br label %22

22:                                               ; preds = %22, %21
  br label %22

23:                                               ; preds = %16
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %24, i32 0, i32 7
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = add i64 %26, -1
  store i64 %27, ptr %25, align 8, !tbaa !11
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %28, i32 0, i32 3
  %30 = load i64, ptr %29, align 8, !tbaa !15
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %31, i32 0, i32 6
  %33 = load i64, ptr %32, align 8, !tbaa !16
  %34 = icmp ne i64 %30, %33
  br i1 %34, label %35, label %82

35:                                               ; preds = %23
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %36, i32 0, i32 7
  %38 = load i64, ptr %37, align 8, !tbaa !11
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %40, label %80

40:                                               ; preds = %35
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %41, i32 0, i32 1
  %43 = call i64 @uxListRemove(ptr noundef %42)
  %44 = icmp eq i64 %43, 0
  br i1 %44, label %45, label %53

45:                                               ; preds = %40
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %46, i32 0, i32 3
  %48 = load i64, ptr %47, align 8, !tbaa !15
  %49 = shl i64 1, %48
  %50 = xor i64 %49, -1
  %51 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %52 = and i64 %51, %50
  store volatile i64 %52, ptr @uxTopReadyPriority, align 8, !tbaa !9
  br label %54

53:                                               ; preds = %40
  br label %54

54:                                               ; preds = %53, %45
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %55, i32 0, i32 6
  %57 = load i64, ptr %56, align 8, !tbaa !16
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %58, i32 0, i32 3
  store i64 %57, ptr %59, align 8, !tbaa !15
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %60, i32 0, i32 3
  %62 = load i64, ptr %61, align 8, !tbaa !15
  %63 = trunc i64 %62 to i32
  %64 = sub i32 15, %63
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %65, i32 0, i32 2
  %67 = getelementptr inbounds %struct.xLIST_ITEM, ptr %66, i32 0, i32 0
  store i32 %64, ptr %67, align 8, !tbaa !17
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %68, i32 0, i32 3
  %70 = load i64, ptr %69, align 8, !tbaa !15
  %71 = shl i64 1, %70
  %72 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %73 = or i64 %72, %71
  store volatile i64 %73, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %74, i32 0, i32 3
  %76 = load i64, ptr %75, align 8, !tbaa !15
  %77 = getelementptr inbounds [15 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %76
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %78, i32 0, i32 1
  call void @vListInsertEnd(ptr noundef %77, ptr noundef %79)
  store i64 1, ptr %4, align 8, !tbaa !9
  br label %81

80:                                               ; preds = %35
  br label %81

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

82:                                               ; preds = %23
  br label %83

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

84:                                               ; preds = %1
  br label %85

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

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 88}
!16 = !{!12, !10, i64 136}
!17 = !{!12, !14, i64 48}


; 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 range(i64 0, 2) i64 @xTaskPriorityDisinherit(ptr noundef %0) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %38, label %2

2:                                                ; preds = %1
  %3 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %.not19 = icmp eq ptr %3, %0
  br i1 %.not19, label %6, label %4

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

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

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 144
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %10, label %12

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

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

12:                                               ; preds = %6
  %13 = add i64 %8, -1
  store i64 %13, ptr %7, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %0, i64 88
  %15 = load i64, ptr %14, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %0, i64 136
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %.not20 = icmp ne i64 %15, %17
  %18 = icmp eq i64 %13, 0
  %or.cond = and i1 %18, %.not20
  br i1 %or.cond, label %19, label %38

19:                                               ; preds = %12
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = tail call i64 @uxListRemove(ptr noundef nonnull %20) #3
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %29

23:                                               ; preds = %19
  %24 = load i64, ptr %14, align 8, !tbaa !14
  %25 = shl nuw i64 1, %24
  %26 = xor i64 %25, -1
  %27 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !16
  %28 = and i64 %27, %26
  store volatile i64 %28, ptr @uxTopReadyPriority, align 8, !tbaa !16
  br label %29

29:                                               ; preds = %19, %23
  %30 = load i64, ptr %16, align 8, !tbaa !15
  store i64 %30, ptr %14, align 8, !tbaa !14
  %31 = trunc i64 %30 to i32
  %32 = sub i32 15, %31
  %33 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %32, ptr %33, align 8, !tbaa !17
  %34 = shl nuw i64 1, %30
  %35 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !16
  %36 = or i64 %35, %34
  store volatile i64 %36, ptr @uxTopReadyPriority, align 8, !tbaa !16
  %37 = getelementptr inbounds [15 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %30
  tail call void @vListInsertEnd(ptr noundef nonnull %37, ptr noundef nonnull %20) #3
  br label %38

38:                                               ; preds = %1, %29, %12
  %.0 = phi i64 [ 1, %29 ], [ 0, %12 ], [ 0, %1 ]
  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 = { 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 = { 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, !13, i64 144}
!10 = !{!"tskTaskControlBlock", !6, i64 0, !11, i64 8, !11, i64 48, !13, i64 88, !6, i64 96, !7, i64 104, !13, i64 136, !13, i64 144, !7, i64 152, !7, i64 156}
!11 = !{!"xLIST_ITEM", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !13, i64 88}
!15 = !{!10, !13, i64 136}
!16 = !{!13, !13, i64 0}
!17 = !{!10, !12, i64 48}


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