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

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

declare void @vPortExitCritical() #1

declare void @vPortYield() #1

; Function Attrs: nounwind uwtable
define dso_local void @vTaskResume(ptr noundef %0) #2 section "privileged_functions" {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, 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
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %10

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

9:                                                ; preds = %9, %8
  br label %9

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %13 = icmp ne ptr %11, %12
  br i1 %13, label %14, label %87

14:                                               ; preds = %10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %87

17:                                               ; preds = %14
  call void @vPortEnterCritical()
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = call i64 @prvTaskIsTaskSuspended(ptr noundef %18)
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %85

21:                                               ; preds = %17
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %22, i32 0, i32 2
  %24 = call i64 @uxListRemove(ptr noundef %23)
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %25, i32 0, i32 4
  %27 = load i64, ptr %26, align 8, !tbaa !10
  %28 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !16
  %29 = icmp ugt i64 %27, %28
  br i1 %29, label %30, label %34

30:                                               ; preds = %21
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %31, i32 0, i32 4
  %33 = load i64, ptr %32, align 8, !tbaa !10
  store volatile i64 %33, ptr @uxTopReadyPriority, align 8, !tbaa !16
  br label %34

34:                                               ; preds = %30, %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %35, i32 0, i32 4
  %37 = load i64, ptr %36, align 8, !tbaa !10
  %38 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %37
  %39 = getelementptr inbounds %struct.xLIST, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  store ptr %40, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %42, i32 0, i32 2
  %44 = getelementptr inbounds %struct.xLIST_ITEM, ptr %43, i32 0, i32 1
  store ptr %41, ptr %44, align 8, !tbaa !20
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.xLIST_ITEM, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !21
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %48, i32 0, i32 2
  %50 = getelementptr inbounds %struct.xLIST_ITEM, ptr %49, i32 0, i32 2
  store ptr %47, ptr %50, align 8, !tbaa !22
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.xLIST_ITEM, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !21
  %56 = getelementptr inbounds %struct.xLIST_ITEM, ptr %55, i32 0, i32 1
  store ptr %52, ptr %56, align 8, !tbaa !23
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.xLIST_ITEM, ptr %59, i32 0, i32 2
  store ptr %58, ptr %60, align 8, !tbaa !21
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %61, i32 0, i32 4
  %63 = load i64, ptr %62, align 8, !tbaa !10
  %64 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %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 4
  store ptr %64, ptr %67, align 8, !tbaa !24
  %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 !10
  %71 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %70
  %72 = getelementptr inbounds %struct.xLIST, ptr %71, i32 0, i32 0
  %73 = load volatile i64, ptr %72, align 8, !tbaa !25
  %74 = add i64 %73, 1
  store volatile i64 %74, ptr %72, align 8, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %75, i32 0, i32 4
  %77 = load i64, ptr %76, align 8, !tbaa !10
  %78 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %78, i32 0, i32 4
  %80 = load i64, ptr %79, align 8, !tbaa !10
  %81 = icmp uge i64 %77, %80
  br i1 %81, label %82, label %83

82:                                               ; preds = %34
  call void @vPortYield()
  br label %84

83:                                               ; preds = %34
  br label %84

84:                                               ; preds = %83, %82
  br label %86

85:                                               ; preds = %17
  br label %86

86:                                               ; preds = %85, %84
  call void @vPortExitCritical()
  br label %88

87:                                               ; preds = %14, %10
  br label %88

88:                                               ; preds = %87, %86
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i64 @prvTaskIsTaskSuspended(ptr noundef) #2 section "privileged_functions"

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 = !{i64 2148434243}
!10 = !{!11, !15, i64 128}
!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 = !{!15, !15, i64 0}
!17 = !{!18, !6, i64 8}
!18 = !{!"xLIST", !15, i64 0, !6, i64 8, !19, i64 16}
!19 = !{!"xMINI_LIST_ITEM", !13, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!11, !6, i64 56}
!21 = !{!14, !6, i64 16}
!22 = !{!11, !6, i64 64}
!23 = !{!14, !6, i64 8}
!24 = !{!11, !6, i64 80}
!25 = !{!18, !15, 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 void @vPortEnterCritical() local_unnamed_addr #0

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

declare void @vPortExitCritical() local_unnamed_addr #0

declare void @vPortYield() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @vTaskResume(ptr noundef %0) local_unnamed_addr #1 section "privileged_functions" {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %3, label %5

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

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

5:                                                ; preds = %1
  %6 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !6
  %.not = icmp eq ptr %6, %0
  br i1 %.not, label %34, label %7

7:                                                ; preds = %5
  tail call void @vPortEnterCritical() #2
  %8 = tail call i64 @prvTaskIsTaskSuspended(ptr noundef nonnull %0)
  %.not22 = icmp eq i64 %8, 0
  br i1 %.not22, label %33, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  %11 = tail call i64 @uxListRemove(ptr noundef nonnull %10) #2
  %12 = getelementptr inbounds i8, ptr %0, i64 128
  %13 = load i64, ptr %12, align 8, !tbaa !10
  %14 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !16
  %15 = icmp ugt i64 %13, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %9
  store volatile i64 %13, ptr @uxTopReadyPriority, align 8, !tbaa !16
  br label %17

17:                                               ; preds = %16, %9
  %18 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %13, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  %20 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %19, ptr %20, align 8, !tbaa !20
  %21 = getelementptr inbounds i8, ptr %19, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !21
  %23 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %22, ptr %23, align 8, !tbaa !22
  %24 = getelementptr inbounds i8, ptr %22, i64 8
  store ptr %10, ptr %24, align 8, !tbaa !23
  store ptr %10, ptr %21, align 8, !tbaa !21
  %25 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %13
  %26 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr %25, ptr %26, align 8, !tbaa !24
  %27 = load volatile i64, ptr %25, align 8, !tbaa !25
  %28 = add i64 %27, 1
  store volatile i64 %28, ptr %25, align 8, !tbaa !25
  %29 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !6
  %30 = getelementptr inbounds i8, ptr %29, i64 128
  %31 = load i64, ptr %30, align 8, !tbaa !10
  %.not23 = icmp ult i64 %13, %31
  br i1 %.not23, label %33, label %32

32:                                               ; preds = %17
  tail call void @vPortYield() #2
  br label %33

33:                                               ; preds = %7, %32, %17
  tail call void @vPortExitCritical() #2
  br label %34

34:                                               ; preds = %5, %33
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i64 @prvTaskIsTaskSuspended(ptr noundef) local_unnamed_addr #1 section "privileged_functions"

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


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