; 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
@uxSchedulerSuspended = external hidden global i64, 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
@xPendingReadyList = external hidden global %struct.xLIST, 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"

declare void @vListInsertEnd(ptr noundef, ptr noundef) #1 section "privileged_functions"

declare i32 @ulSetInterruptMask() #1

declare void @vClearInterruptMask(i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @xTaskResumeFromISR(ptr noundef %0) #2 section "privileged_functions" {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %7, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %12

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

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

12:                                               ; preds = %1
  %13 = call i32 @ulSetInterruptMask()
  %14 = zext i32 %13 to i64
  store i64 %14, ptr %5, align 8, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call i64 @prvTaskIsTaskSuspended(ptr noundef %15)
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %89

18:                                               ; preds = %12
  %19 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !9
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %85

21:                                               ; preds = %18
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %22, i32 0, i32 4
  %24 = load i64, ptr %23, align 8, !tbaa !12
  %25 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %25, i32 0, i32 4
  %27 = load i64, ptr %26, align 8, !tbaa !12
  %28 = icmp uge i64 %24, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %21
  store i64 1, ptr %3, align 8, !tbaa !9
  store volatile i64 1, ptr @xYieldPending, align 8, !tbaa !9
  br label %31

30:                                               ; preds = %21
  br label %31

31:                                               ; preds = %30, %29
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %32, i32 0, i32 2
  %34 = call i64 @uxListRemove(ptr noundef %33)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %35, i32 0, i32 4
  %37 = load i64, ptr %36, align 8, !tbaa !12
  %38 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %39 = icmp ugt i64 %37, %38
  br i1 %39, label %40, label %44

40:                                               ; preds = %31
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %41, i32 0, i32 4
  %43 = load i64, ptr %42, align 8, !tbaa !12
  store volatile i64 %43, ptr @uxTopReadyPriority, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %40, %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %45, i32 0, i32 4
  %47 = load i64, ptr %46, align 8, !tbaa !12
  %48 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.xLIST, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !17
  store ptr %50, ptr %6, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %52, i32 0, i32 2
  %54 = getelementptr inbounds %struct.xLIST_ITEM, ptr %53, i32 0, i32 1
  store ptr %51, ptr %54, align 8, !tbaa !20
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.xLIST_ITEM, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !21
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %58, i32 0, i32 2
  %60 = getelementptr inbounds %struct.xLIST_ITEM, ptr %59, i32 0, i32 2
  store ptr %57, ptr %60, align 8, !tbaa !22
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.xLIST_ITEM, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !21
  %66 = getelementptr inbounds %struct.xLIST_ITEM, ptr %65, i32 0, i32 1
  store ptr %62, ptr %66, align 8, !tbaa !23
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %67, i32 0, i32 2
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.xLIST_ITEM, ptr %69, i32 0, i32 2
  store ptr %68, ptr %70, align 8, !tbaa !21
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %71, i32 0, i32 4
  %73 = load i64, ptr %72, align 8, !tbaa !12
  %74 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %73
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %75, i32 0, i32 2
  %77 = getelementptr inbounds %struct.xLIST_ITEM, ptr %76, i32 0, i32 4
  store ptr %74, ptr %77, align 8, !tbaa !24
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %78, i32 0, i32 4
  %80 = load i64, ptr %79, align 8, !tbaa !12
  %81 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %80
  %82 = getelementptr inbounds %struct.xLIST, ptr %81, i32 0, i32 0
  %83 = load volatile i64, ptr %82, align 8, !tbaa !25
  %84 = add i64 %83, 1
  store volatile i64 %84, ptr %82, align 8, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %88

85:                                               ; preds = %18
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %86, i32 0, i32 3
  call void @vListInsertEnd(ptr noundef @xPendingReadyList, ptr noundef %87)
  br label %88

88:                                               ; preds = %85, %44
  br label %90

89:                                               ; preds = %12
  br label %90

90:                                               ; preds = %89, %88
  %91 = load i64, ptr %5, align 8, !tbaa !9
  %92 = trunc i64 %91 to i32
  call void @vClearInterruptMask(i32 noundef %92)
  %93 = load i64, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i64 %93
}

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 2148437205}
!12 = !{!13, !10, i64 128}
!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 = !{!18, !6, i64 8}
!18 = !{!"xLIST", !10, i64 0, !6, i64 8, !19, i64 16}
!19 = !{!"xMINI_LIST_ITEM", !15, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!13, !6, i64 56}
!21 = !{!16, !6, i64 16}
!22 = !{!13, !6, i64 64}
!23 = !{!16, !6, i64 8}
!24 = !{!13, !6, i64 80}
!25 = !{!18, !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
@uxSchedulerSuspended = external hidden global i64, 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
@xPendingReadyList = external hidden global %struct.xLIST, section "privileged_data", align 8

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

declare void @vListInsertEnd(ptr noundef, ptr noundef) local_unnamed_addr #0 section "privileged_functions"

declare i32 @ulSetInterruptMask() local_unnamed_addr #0

declare void @vClearInterruptMask(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 2) i64 @xTaskResumeFromISR(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 = tail call i32 @ulSetInterruptMask() #2
  %7 = tail call i64 @prvTaskIsTaskSuspended(ptr noundef nonnull %0)
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %39, label %8

8:                                                ; preds = %5
  %9 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !6
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %37

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 128
  %13 = load i64, ptr %12, align 8, !tbaa !10
  %14 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %14, i64 128
  %16 = load i64, ptr %15, align 8, !tbaa !10
  %.not22 = icmp ult i64 %13, %16
  br i1 %.not22, label %18, label %17

17:                                               ; preds = %11
  store volatile i64 1, ptr @xYieldPending, align 8, !tbaa !6
  br label %18

18:                                               ; preds = %11, %17
  %.0 = phi i64 [ 1, %17 ], [ 0, %11 ]
  %19 = getelementptr inbounds i8, ptr %0, i64 48
  %20 = tail call i64 @uxListRemove(ptr noundef nonnull %19) #2
  %21 = load i64, ptr %12, align 8, !tbaa !10
  %22 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !6
  %23 = icmp ugt i64 %21, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %18
  store volatile i64 %21, ptr @uxTopReadyPriority, align 8, !tbaa !6
  br label %25

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

37:                                               ; preds = %8
  %38 = getelementptr inbounds i8, ptr %0, i64 88
  tail call void @vListInsertEnd(ptr noundef nonnull @xPendingReadyList, ptr noundef nonnull %38) #2
  br label %39

39:                                               ; preds = %5, %25, %37
  %.1 = phi i64 [ %.0, %25 ], [ 0, %37 ], [ 0, %5 ]
  tail call void @vClearInterruptMask(i32 noundef %6) #2
  ret i64 %.1
}

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


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