; 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
@xYieldPending = 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

; Function Attrs: nounwind uwtable
declare dso_local void @vTaskSuspendAll() #2 section "privileged_functions"

; Function Attrs: nounwind uwtable
declare dso_local i64 @xTaskResumeAll() #2 section "privileged_functions"

; Function Attrs: nounwind uwtable
declare dso_local i32 @eTaskGetState(ptr noundef) #2 section "privileged_functions"

; Function Attrs: nounwind uwtable
define dso_local i64 @xTaskAbortDelay(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
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %11

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

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

11:                                               ; preds = %1
  call void @vTaskSuspendAll()
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call i32 @eTaskGetState(ptr noundef %12)
  %14 = icmp eq i32 %13, 2
  br i1 %14, label %15, label %92

15:                                               ; preds = %11
  store i64 1, ptr %4, align 8, !tbaa !10
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %16, i32 0, i32 2
  %18 = call i64 @uxListRemove(ptr noundef %17)
  call void @vPortEnterCritical()
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %19, i32 0, i32 3
  %21 = getelementptr inbounds %struct.xLIST_ITEM, ptr %20, i32 0, i32 4
  %22 = load ptr, ptr %21, align 8, !tbaa !12
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %30

24:                                               ; preds = %15
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %25, i32 0, i32 3
  %27 = call i64 @uxListRemove(ptr noundef %26)
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %28, i32 0, i32 14
  store i8 1, ptr %29, align 2, !tbaa !17
  br label %31

30:                                               ; preds = %15
  br label %31

31:                                               ; preds = %30, %24
  call void @vPortExitCritical()
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %32, i32 0, i32 4
  %34 = load i64, ptr %33, align 8, !tbaa !18
  %35 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !10
  %36 = icmp ugt i64 %34, %35
  br i1 %36, label %37, label %41

37:                                               ; preds = %31
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %38, i32 0, i32 4
  %40 = load i64, ptr %39, align 8, !tbaa !18
  store volatile i64 %40, ptr @uxTopReadyPriority, align 8, !tbaa !10
  br label %41

41:                                               ; preds = %37, %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %42, i32 0, i32 4
  %44 = load i64, ptr %43, align 8, !tbaa !18
  %45 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.xLIST, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !19
  store ptr %47, ptr %5, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %49, i32 0, i32 2
  %51 = getelementptr inbounds %struct.xLIST_ITEM, ptr %50, i32 0, i32 1
  store ptr %48, ptr %51, align 8, !tbaa !22
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.xLIST_ITEM, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !23
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %55, i32 0, i32 2
  %57 = getelementptr inbounds %struct.xLIST_ITEM, ptr %56, i32 0, i32 2
  store ptr %54, ptr %57, align 8, !tbaa !24
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.xLIST_ITEM, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !23
  %63 = getelementptr inbounds %struct.xLIST_ITEM, ptr %62, i32 0, i32 1
  store ptr %59, ptr %63, align 8, !tbaa !25
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.xLIST_ITEM, ptr %66, i32 0, i32 2
  store ptr %65, ptr %67, align 8, !tbaa !23
  %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
  %71 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %70
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %72, i32 0, i32 2
  %74 = getelementptr inbounds %struct.xLIST_ITEM, ptr %73, i32 0, i32 4
  store ptr %71, ptr %74, align 8, !tbaa !26
  %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 !18
  %78 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %77
  %79 = getelementptr inbounds %struct.xLIST, ptr %78, i32 0, i32 0
  %80 = load volatile i64, ptr %79, align 8, !tbaa !27
  %81 = add i64 %80, 1
  store volatile i64 %81, ptr %79, align 8, !tbaa !27
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %82, i32 0, i32 4
  %84 = load i64, ptr %83, align 8, !tbaa !18
  %85 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %85, i32 0, i32 4
  %87 = load i64, ptr %86, align 8, !tbaa !18
  %88 = icmp ugt i64 %84, %87
  br i1 %88, label %89, label %90

89:                                               ; preds = %41
  store volatile i64 1, ptr @xYieldPending, align 8, !tbaa !10
  br label %91

90:                                               ; preds = %41
  br label %91

91:                                               ; preds = %90, %89
  br label %93

92:                                               ; preds = %11
  store i64 0, ptr %4, align 8, !tbaa !10
  br label %93

93:                                               ; preds = %92, %91
  %94 = call i64 @xTaskResumeAll()
  %95 = load i64, ptr %4, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i64 %95
}

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 2148449919}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 120}
!13 = !{!"tskTaskControlBlock", !6, i64 0, !14, i64 8, !16, i64 48, !16, i64 88, !11, i64 128, !6, i64 136, !7, i64 144, !11, i64 160, !11, i64 168, !11, i64 176, !11, 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 = !{!13, !7, i64 198}
!18 = !{!13, !11, i64 128}
!19 = !{!20, !6, i64 8}
!20 = !{!"xLIST", !11, i64 0, !6, i64 8, !21, i64 16}
!21 = !{!"xMINI_LIST_ITEM", !15, i64 0, !6, i64 8, !6, i64 16}
!22 = !{!13, !6, i64 56}
!23 = !{!16, !6, i64 16}
!24 = !{!13, !6, i64 64}
!25 = !{!16, !6, i64 8}
!26 = !{!13, !6, i64 80}
!27 = !{!20, !11, 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
@xYieldPending = 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

; Function Attrs: nounwind uwtable
declare dso_local void @vTaskSuspendAll() local_unnamed_addr #1 section "privileged_functions"

; Function Attrs: nounwind uwtable
declare dso_local i64 @xTaskResumeAll() local_unnamed_addr #1 section "privileged_functions"

; Function Attrs: nounwind uwtable
declare dso_local i32 @eTaskGetState(ptr noundef) local_unnamed_addr #1 section "privileged_functions"

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 2) i64 @xTaskAbortDelay(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
  tail call void @vTaskSuspendAll()
  %6 = tail call i32 @eTaskGetState(ptr noundef nonnull %0)
  %7 = icmp eq i32 %6, 2
  br i1 %7, label %8, label %40

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  %10 = tail call i64 @uxListRemove(ptr noundef nonnull %9) #2
  tail call void @vPortEnterCritical() #2
  %11 = getelementptr inbounds i8, ptr %0, i64 120
  %12 = load ptr, ptr %11, align 8, !tbaa !6
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %17, label %13

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 88
  %15 = tail call i64 @uxListRemove(ptr noundef nonnull %14) #2
  %16 = getelementptr inbounds i8, ptr %0, i64 198
  store i8 1, ptr %16, align 2, !tbaa !15
  br label %17

17:                                               ; preds = %8, %13
  tail call void @vPortExitCritical() #2
  %18 = getelementptr inbounds i8, ptr %0, i64 128
  %19 = load i64, ptr %18, align 8, !tbaa !16
  %20 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !17
  %21 = icmp ugt i64 %19, %20
  br i1 %21, label %22, label %23

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

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

39:                                               ; preds = %23
  store volatile i64 1, ptr @xYieldPending, align 8, !tbaa !17
  br label %40

40:                                               ; preds = %5, %39, %23
  %.0 = phi i64 [ 1, %39 ], [ 1, %23 ], [ 0, %5 ]
  %41 = tail call i64 @xTaskResumeAll()
  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 = !{i64 2148449919}
!6 = !{!7, !8, i64 120}
!7 = !{!"tskTaskControlBlock", !8, i64 0, !11, i64 8, !13, i64 48, !13, i64 88, !14, i64 128, !8, i64 136, !9, i64 144, !14, i64 160, !14, i64 168, !14, i64 176, !14, i64 184, !9, i64 192, !9, i64 196, !9, i64 197, !9, i64 198}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"MPU_SETTINGS", !12, i64 0, !9, i64 4}
!12 = !{!"int", !9, i64 0}
!13 = !{!"xLIST_ITEM", !12, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32}
!14 = !{!"long", !9, i64 0}
!15 = !{!7, !9, i64 198}
!16 = !{!7, !14, i64 128}
!17 = !{!14, !14, i64 0}
!18 = !{!19, !8, i64 8}
!19 = !{!"xLIST", !14, i64 0, !8, i64 8, !20, i64 16}
!20 = !{!"xMINI_LIST_ITEM", !12, i64 0, !8, i64 8, !8, i64 16}
!21 = !{!7, !8, i64 56}
!22 = !{!13, !8, i64 16}
!23 = !{!7, !8, i64 64}
!24 = !{!13, !8, i64 8}
!25 = !{!7, !8, i64 80}
!26 = !{!19, !14, i64 0}
!27 = !{!8, !8, i64 0}


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