; 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.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 }
%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

; 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

; Function Attrs: nounwind uwtable
declare hidden void @prvAddCurrentTaskToDelayedList(i32 noundef, i64 noundef) #1 section "privileged_functions"

; Function Attrs: nounwind uwtable
define dso_local void @vTaskPlaceOnUnorderedEventList(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 section "privileged_functions" {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %12

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

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

12:                                               ; preds = %3
  %13 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !12
  %14 = icmp ne i64 %13, 0
  %15 = zext i1 %14 to i32
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %19

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

18:                                               ; preds = %18, %17
  br label %18

19:                                               ; preds = %12
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  %22 = or i64 %21, 2147483648
  %23 = trunc i64 %22 to i32
  %24 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %24, i32 0, i32 3
  %26 = getelementptr inbounds %struct.xLIST_ITEM, ptr %25, i32 0, i32 0
  store i32 %23, ptr %26, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.xLIST, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !19
  store ptr %29, ptr %7, align 8, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %31, i32 0, i32 3
  %33 = getelementptr inbounds %struct.xLIST_ITEM, ptr %32, i32 0, i32 1
  store ptr %30, ptr %33, align 8, !tbaa !22
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.xLIST_ITEM, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !23
  %37 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %37, i32 0, i32 3
  %39 = getelementptr inbounds %struct.xLIST_ITEM, ptr %38, i32 0, i32 2
  store ptr %36, ptr %39, align 8, !tbaa !24
  %40 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %40, i32 0, i32 3
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.xLIST_ITEM, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !23
  %45 = getelementptr inbounds %struct.xLIST_ITEM, ptr %44, i32 0, i32 1
  store ptr %41, ptr %45, align 8, !tbaa !25
  %46 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.xLIST_ITEM, ptr %48, i32 0, i32 2
  store ptr %47, ptr %49, align 8, !tbaa !23
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %51, i32 0, i32 3
  %53 = getelementptr inbounds %struct.xLIST_ITEM, ptr %52, i32 0, i32 4
  store ptr %50, ptr %53, align 8, !tbaa !26
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.xLIST, ptr %54, i32 0, i32 0
  %56 = load volatile i64, ptr %55, align 8, !tbaa !27
  %57 = add i64 %56, 1
  store volatile i64 %57, ptr %55, align 8, !tbaa !27
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  %58 = load i32, ptr %6, align 4, !tbaa !9
  call void @prvAddCurrentTaskToDelayedList(i32 noundef %58, i64 noundef 1)
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i64 2148463183}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{i64 2148463336}
!15 = !{!16, !10, i64 88}
!16 = !{!"tskTaskControlBlock", !6, i64 0, !17, i64 8, !18, i64 48, !18, i64 88, !13, i64 128, !6, i64 136, !7, i64 144, !13, i64 160, !13, i64 168, !13, i64 176, !13, i64 184, !7, i64 192, !7, i64 196, !7, i64 197, !7, i64 198}
!17 = !{!"MPU_SETTINGS", !10, i64 0, !7, i64 4}
!18 = !{!"xLIST_ITEM", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!19 = !{!20, !6, i64 8}
!20 = !{!"xLIST", !13, i64 0, !6, i64 8, !21, i64 16}
!21 = !{!"xMINI_LIST_ITEM", !10, i64 0, !6, i64 8, !6, i64 16}
!22 = !{!16, !6, i64 96}
!23 = !{!18, !6, i64 16}
!24 = !{!16, !6, i64 104}
!25 = !{!18, !6, i64 8}
!26 = !{!16, !6, i64 120}
!27 = !{!20, !13, 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"

@pxCurrentTCB = external dso_local global ptr, section "privileged_data", align 8
@uxSchedulerSuspended = external hidden global i64, section "privileged_data", align 8

; Function Attrs: nounwind uwtable
declare hidden void @prvAddCurrentTaskToDelayedList(i32 noundef, i64 noundef) local_unnamed_addr #0 section "privileged_functions"

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

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

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

7:                                                ; preds = %3
  %8 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !6
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %9, label %11

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

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

11:                                               ; preds = %7
  %12 = or i32 %1, -2147483648
  %13 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %13, i64 88
  store i32 %12, ptr %14, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %17 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %17, i64 96
  store ptr %16, ptr %18, align 8, !tbaa !21
  %19 = getelementptr inbounds i8, ptr %16, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !22
  %21 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %21, i64 104
  store ptr %20, ptr %22, align 8, !tbaa !23
  %23 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !11
  %24 = getelementptr inbounds i8, ptr %23, i64 88
  %25 = getelementptr inbounds i8, ptr %20, i64 8
  store ptr %24, ptr %25, align 8, !tbaa !24
  %26 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %26, i64 88
  store ptr %27, ptr %19, align 8, !tbaa !22
  %28 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %28, i64 120
  store ptr %0, ptr %29, align 8, !tbaa !25
  %30 = load volatile i64, ptr %0, align 8, !tbaa !26
  %31 = add i64 %30, 1
  store volatile i64 %31, ptr %0, align 8, !tbaa !26
  tail call void @prvAddCurrentTaskToDelayedList(i32 noundef %2, i64 noundef 1)
  ret void
}

attributes #0 = { 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 #1 = { 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 2148463183}
!6 = !{!7, !7, i64 0}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{i64 2148463336}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !16, i64 88}
!14 = !{!"tskTaskControlBlock", !12, i64 0, !15, i64 8, !17, i64 48, !17, 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}
!15 = !{!"MPU_SETTINGS", !16, i64 0, !8, i64 4}
!16 = !{!"int", !8, i64 0}
!17 = !{!"xLIST_ITEM", !16, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!18 = !{!19, !12, i64 8}
!19 = !{!"xLIST", !7, i64 0, !12, i64 8, !20, i64 16}
!20 = !{!"xMINI_LIST_ITEM", !16, i64 0, !12, i64 8, !12, i64 16}
!21 = !{!14, !12, i64 96}
!22 = !{!17, !12, i64 16}
!23 = !{!14, !12, i64 104}
!24 = !{!17, !12, i64 8}
!25 = !{!14, !12, i64 120}
!26 = !{!19, !7, i64 0}


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