; 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

; 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 @vTaskPlaceOnEventListRestricted(ptr noundef %0, i32 noundef %1, i64 noundef %2) #1 section "privileged_functions" {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !11
  %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 !13
  br label %11

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

12:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.xLIST, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  store ptr %15, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %17, i32 0, i32 3
  %19 = getelementptr inbounds %struct.xLIST_ITEM, ptr %18, i32 0, i32 1
  store ptr %16, ptr %19, align 8, !tbaa !17
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.xLIST_ITEM, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !21
  %23 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %23, i32 0, i32 3
  %25 = getelementptr inbounds %struct.xLIST_ITEM, ptr %24, i32 0, i32 2
  store ptr %22, ptr %25, align 8, !tbaa !22
  %26 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.xLIST_ITEM, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !21
  %31 = getelementptr inbounds %struct.xLIST_ITEM, ptr %30, i32 0, i32 1
  store ptr %27, ptr %31, align 8, !tbaa !23
  %32 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.xLIST_ITEM, ptr %34, i32 0, i32 2
  store ptr %33, ptr %35, align 8, !tbaa !21
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %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 4
  store ptr %36, ptr %39, align 8, !tbaa !24
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.xLIST, ptr %40, i32 0, i32 0
  %42 = load volatile i64, ptr %41, align 8, !tbaa !25
  %43 = add i64 %42, 1
  store volatile i64 %43, ptr %41, align 8, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  %44 = load i64, ptr %6, align 8, !tbaa !11
  %45 = icmp ne i64 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %12
  store i32 -1, ptr %5, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %46, %12
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = load i64, ptr %6, align 8, !tbaa !11
  call void @prvAddCurrentTaskToDelayedList(i32 noundef %48, i64 noundef %49)
  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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{i64 2148465419}
!14 = !{!15, !6, i64 8}
!15 = !{!"xLIST", !12, i64 0, !6, i64 8, !16, i64 16}
!16 = !{!"xMINI_LIST_ITEM", !10, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!18, !6, i64 96}
!18 = !{!"tskTaskControlBlock", !6, i64 0, !19, i64 8, !20, i64 48, !20, i64 88, !12, i64 128, !6, i64 136, !7, i64 144, !12, i64 160, !12, i64 168, !12, i64 176, !12, i64 184, !7, i64 192, !7, i64 196, !7, i64 197, !7, i64 198}
!19 = !{!"MPU_SETTINGS", !10, i64 0, !7, i64 4}
!20 = !{!"xLIST_ITEM", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!21 = !{!20, !6, i64 16}
!22 = !{!18, !6, i64 104}
!23 = !{!20, !6, i64 8}
!24 = !{!18, !6, i64 120}
!25 = !{!15, !12, 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

; 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 @vTaskPlaceOnEventListRestricted(ptr noundef %0, i32 noundef %1, i64 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 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !6
  %10 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %10, i64 96
  store ptr %9, ptr %11, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %9, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !19
  %14 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %14, i64 104
  store ptr %13, ptr %15, align 8, !tbaa !20
  %16 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %16, i64 88
  %18 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr %17, ptr %18, align 8, !tbaa !21
  %19 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %19, i64 88
  store ptr %20, ptr %12, align 8, !tbaa !19
  %21 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %21, i64 120
  store ptr %0, ptr %22, align 8, !tbaa !22
  %23 = load volatile i64, ptr %0, align 8, !tbaa !23
  %24 = add i64 %23, 1
  store volatile i64 %24, ptr %0, align 8, !tbaa !23
  %.not = icmp eq i64 %2, 0
  %spec.select = select i1 %.not, i32 %1, i32 -1
  tail call void @prvAddCurrentTaskToDelayedList(i32 noundef %spec.select, i64 noundef %2)
  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 2148465419}
!6 = !{!7, !11, i64 8}
!7 = !{!"xLIST", !8, i64 0, !11, i64 8, !12, i64 16}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"xMINI_LIST_ITEM", !13, i64 0, !11, i64 8, !11, i64 16}
!13 = !{!"int", !9, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !11, i64 96}
!16 = !{!"tskTaskControlBlock", !11, i64 0, !17, i64 8, !18, i64 48, !18, i64 88, !8, i64 128, !11, i64 136, !9, i64 144, !8, i64 160, !8, i64 168, !8, i64 176, !8, i64 184, !9, i64 192, !9, i64 196, !9, i64 197, !9, i64 198}
!17 = !{!"MPU_SETTINGS", !13, i64 0, !9, i64 4}
!18 = !{!"xLIST_ITEM", !13, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!19 = !{!18, !11, i64 16}
!20 = !{!16, !11, i64 104}
!21 = !{!18, !11, i64 8}
!22 = !{!16, !11, i64 120}
!23 = !{!7, !8, i64 0}


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