; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/freertos (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.MPU_SETTINGS, %struct.xLIST_ITEM, %struct.xLIST_ITEM, i64, ptr, [10 x i8], i64, i64, i64, i64, [1 x i32], [1 x i8], i8, i8 }
%struct.MPU_SETTINGS = type { i32, [4 x %struct.MPURegionSettings] }
%struct.MPURegionSettings = type { i32, i32 }
%struct.xLIST_ITEM = type { i32, ptr, ptr, ptr, ptr }

@pxCurrentTCB = external dso_local global ptr, section "privileged_data", align 8
@pxReadyTasksLists = external hidden global [5 x %struct.xLIST], section "privileged_data", align 16
@uxTopReadyPriority = external hidden global i64, section "privileged_data", 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 section "privileged_functions"

; Function Attrs: nounwind uwtable
define dso_local i64 @xTaskPriorityDisinherit(ptr noundef %0) #2 section "privileged_functions" {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %6, 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
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %116

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

15:                                               ; preds = %9
  call void asm sideeffect " cpsid i ", "~{memory},~{dirflag},~{fpsr},~{flags}"() #3, !srcloc !11
  br label %16

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

17:                                               ; preds = %9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %18, i32 0, i32 10
  %20 = load i64, ptr %19, align 8, !tbaa !12
  %21 = icmp eq i64 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %17
  call void asm sideeffect " cpsid i ", "~{memory},~{dirflag},~{fpsr},~{flags}"() #3, !srcloc !17
  br label %23

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

24:                                               ; preds = %17
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %25, i32 0, i32 10
  %27 = load i64, ptr %26, align 8, !tbaa !12
  %28 = add i64 %27, -1
  store i64 %28, ptr %26, align 8, !tbaa !12
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %29, i32 0, i32 4
  %31 = load i64, ptr %30, align 8, !tbaa !18
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %32, i32 0, i32 9
  %34 = load i64, ptr %33, align 8, !tbaa !19
  %35 = icmp ne i64 %31, %34
  br i1 %35, label %36, label %114

36:                                               ; preds = %24
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %37, i32 0, i32 10
  %39 = load i64, ptr %38, align 8, !tbaa !12
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %41, label %112

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

46:                                               ; preds = %41
  br label %48

47:                                               ; preds = %41
  br label %48

48:                                               ; preds = %47, %46
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %49, i32 0, i32 9
  %51 = load i64, ptr %50, align 8, !tbaa !19
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %52, i32 0, i32 4
  store i64 %51, ptr %53, align 8, !tbaa !18
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %54, i32 0, i32 4
  %56 = load i64, ptr %55, align 8, !tbaa !18
  %57 = trunc i64 %56 to i32
  %58 = sub i32 5, %57
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %59, i32 0, i32 3
  %61 = getelementptr inbounds %struct.xLIST_ITEM, ptr %60, i32 0, i32 0
  store i32 %58, ptr %61, align 8, !tbaa !20
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %62, i32 0, i32 4
  %64 = load i64, ptr %63, align 8, !tbaa !18
  %65 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %66 = icmp ugt i64 %64, %65
  br i1 %66, label %67, label %71

67:                                               ; preds = %48
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %68, i32 0, i32 4
  %70 = load i64, ptr %69, align 8, !tbaa !18
  store volatile i64 %70, ptr @uxTopReadyPriority, align 8, !tbaa !9
  br label %71

71:                                               ; preds = %67, %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %72, i32 0, i32 4
  %74 = load i64, ptr %73, align 8, !tbaa !18
  %75 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %74
  %76 = getelementptr inbounds %struct.xLIST, ptr %75, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8, !tbaa !21
  store ptr %77, ptr %5, align 8, !tbaa !5
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %79, i32 0, i32 2
  %81 = getelementptr inbounds %struct.xLIST_ITEM, ptr %80, i32 0, i32 1
  store ptr %78, ptr %81, align 8, !tbaa !24
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.xLIST_ITEM, ptr %82, i32 0, i32 2
  %84 = load ptr, ptr %83, align 8, !tbaa !25
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %85, i32 0, i32 2
  %87 = getelementptr inbounds %struct.xLIST_ITEM, ptr %86, i32 0, i32 2
  store ptr %84, ptr %87, align 8, !tbaa !26
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %88, i32 0, i32 2
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.xLIST_ITEM, ptr %90, i32 0, i32 2
  %92 = load ptr, ptr %91, align 8, !tbaa !25
  %93 = getelementptr inbounds %struct.xLIST_ITEM, ptr %92, i32 0, i32 1
  store ptr %89, ptr %93, align 8, !tbaa !27
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %94, i32 0, i32 2
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.xLIST_ITEM, ptr %96, i32 0, i32 2
  store ptr %95, ptr %97, align 8, !tbaa !25
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %98, i32 0, i32 4
  %100 = load i64, ptr %99, align 8, !tbaa !18
  %101 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %100
  %102 = load ptr, ptr %3, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %102, i32 0, i32 2
  %104 = getelementptr inbounds %struct.xLIST_ITEM, ptr %103, i32 0, i32 4
  store ptr %101, ptr %104, align 8, !tbaa !28
  %105 = load ptr, ptr %3, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %105, i32 0, i32 4
  %107 = load i64, ptr %106, align 8, !tbaa !18
  %108 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %107
  %109 = getelementptr inbounds %struct.xLIST, ptr %108, i32 0, i32 0
  %110 = load volatile i64, ptr %109, align 8, !tbaa !29
  %111 = add i64 %110, 1
  store volatile i64 %111, ptr %109, align 8, !tbaa !29
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  store i64 1, ptr %4, align 8, !tbaa !9
  br label %113

112:                                              ; preds = %36
  br label %113

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

114:                                              ; preds = %24
  br label %115

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

116:                                              ; preds = %1
  br label %117

117:                                              ; preds = %116, %115
  %118 = 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 %118
}

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 = !{i64 2148489679}
!12 = !{!13, !10, i64 184}
!13 = !{!"tskTaskControlBlock", !6, i64 0, !14, i64 8, !16, i64 48, !16, i64 88, !10, i64 128, !6, i64 136, !7, i64 144, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !7, i64 192, !7, i64 196, !7, i64 197, !7, i64 198}
!14 = !{!"MPU_SETTINGS", !15, i64 0, !7, i64 4}
!15 = !{!"int", !7, i64 0}
!16 = !{!"xLIST_ITEM", !15, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!17 = !{i64 2148489827}
!18 = !{!13, !10, i64 128}
!19 = !{!13, !10, i64 176}
!20 = !{!13, !15, i64 88}
!21 = !{!22, !6, i64 8}
!22 = !{!"xLIST", !10, i64 0, !6, i64 8, !23, i64 16}
!23 = !{!"xMINI_LIST_ITEM", !15, i64 0, !6, i64 8, !6, i64 16}
!24 = !{!13, !6, i64 56}
!25 = !{!16, !6, i64 16}
!26 = !{!13, !6, i64 64}
!27 = !{!16, !6, i64 8}
!28 = !{!13, !6, i64 80}
!29 = !{!22, !10, i64 0}


; 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, section "privileged_data", align 8
@pxReadyTasksLists = external hidden global [5 x %struct.xLIST], section "privileged_data", align 16
@uxTopReadyPriority = external hidden global i64, section "privileged_data", align 8

declare i64 @uxListRemove(ptr noundef) local_unnamed_addr #0 section "privileged_functions"

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 2) i64 @xTaskPriorityDisinherit(ptr noundef %0) local_unnamed_addr #1 section "privileged_functions" {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %41, label %2

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

4:                                                ; preds = %2
  tail call void asm sideeffect " cpsid i ", "~{memory},~{dirflag},~{fpsr},~{flags}"() #2, !srcloc !9
  br label %5

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

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

10:                                               ; preds = %6
  tail call void asm sideeffect " cpsid i ", "~{memory},~{dirflag},~{fpsr},~{flags}"() #2, !srcloc !16
  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 !10
  %14 = getelementptr inbounds i8, ptr %0, i64 128
  %15 = load i64, ptr %14, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %0, i64 176
  %17 = load i64, ptr %16, align 8, !tbaa !18
  %.not30 = icmp ne i64 %15, %17
  %18 = icmp eq i64 %13, 0
  %or.cond = and i1 %18, %.not30
  br i1 %or.cond, label %19, label %41

19:                                               ; preds = %12
  %20 = getelementptr inbounds i8, ptr %0, i64 48
  %21 = tail call i64 @uxListRemove(ptr noundef nonnull %20) #2
  %22 = load i64, ptr %16, align 8, !tbaa !18
  store i64 %22, ptr %14, align 8, !tbaa !17
  %23 = trunc i64 %22 to i32
  %24 = sub i32 5, %23
  %25 = getelementptr inbounds i8, ptr %0, i64 88
  store i32 %24, ptr %25, align 8, !tbaa !19
  %26 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !20
  %27 = icmp ugt i64 %22, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %19
  store volatile i64 %22, ptr @uxTopReadyPriority, align 8, !tbaa !20
  br label %29

29:                                               ; preds = %28, %19
  %30 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %22, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !21
  %32 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %31, ptr %32, align 8, !tbaa !24
  %33 = getelementptr inbounds i8, ptr %31, i64 16
  %34 = load ptr, ptr %33, align 8, !tbaa !25
  %35 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %34, ptr %35, align 8, !tbaa !26
  %36 = getelementptr inbounds i8, ptr %34, i64 8
  store ptr %20, ptr %36, align 8, !tbaa !27
  store ptr %20, ptr %33, align 8, !tbaa !25
  %37 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %22
  %38 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr %37, ptr %38, align 8, !tbaa !28
  %39 = load volatile i64, ptr %37, align 8, !tbaa !29
  %40 = add i64 %39, 1
  store volatile i64 %40, ptr %37, align 8, !tbaa !29
  br label %41

41:                                               ; 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 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i64 2148489679}
!10 = !{!11, !15, i64 184}
!11 = !{!"tskTaskControlBlock", !6, i64 0, !12, i64 8, !14, i64 48, !14, i64 88, !15, i64 128, !6, i64 136, !7, i64 144, !15, i64 160, !15, i64 168, !15, i64 176, !15, i64 184, !7, i64 192, !7, i64 196, !7, i64 197, !7, i64 198}
!12 = !{!"MPU_SETTINGS", !13, i64 0, !7, i64 4}
!13 = !{!"int", !7, i64 0}
!14 = !{!"xLIST_ITEM", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = !{i64 2148489827}
!17 = !{!11, !15, i64 128}
!18 = !{!11, !15, i64 176}
!19 = !{!11, !13, i64 88}
!20 = !{!15, !15, i64 0}
!21 = !{!22, !6, i64 8}
!22 = !{!"xLIST", !15, i64 0, !6, i64 8, !23, i64 16}
!23 = !{!"xMINI_LIST_ITEM", !13, i64 0, !6, i64 8, !6, i64 16}
!24 = !{!11, !6, i64 56}
!25 = !{!14, !6, i64 16}
!26 = !{!11, !6, i64 64}
!27 = !{!14, !6, i64 8}
!28 = !{!11, !6, i64 80}
!29 = !{!22, !15, i64 0}


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