; 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.xTASK_STATUS = type { ptr, ptr, i64, i32, i64, i64, i32, ptr, i16 }
%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 dso_local void @vTaskSuspendAll() #1 section "privileged_functions"

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

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

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

12:                                               ; preds = %4
  %13 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  br label %16

14:                                               ; preds = %4
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %14, %12
  %17 = phi ptr [ %13, %12 ], [ %15, %14 ]
  store ptr %17, ptr %9, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.xTASK_STATUS, ptr %19, i32 0, i32 0
  store ptr %18, ptr %20, align 8, !tbaa !13
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %21, i32 0, i32 6
  %23 = getelementptr inbounds [10 x i8], ptr %22, i64 0, i64 0
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.xTASK_STATUS, ptr %24, i32 0, i32 1
  store ptr %23, ptr %25, align 8, !tbaa !16
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %26, i32 0, i32 4
  %28 = load i64, ptr %27, align 8, !tbaa !17
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.xTASK_STATUS, ptr %29, i32 0, i32 4
  store i64 %28, ptr %30, align 8, !tbaa !21
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %31, i32 0, i32 5
  %33 = load ptr, ptr %32, align 8, !tbaa !22
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.xTASK_STATUS, ptr %34, i32 0, i32 7
  store ptr %33, ptr %35, align 8, !tbaa !23
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %36, i32 0, i32 7
  %38 = load i64, ptr %37, align 8, !tbaa !24
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.xTASK_STATUS, ptr %39, i32 0, i32 2
  store i64 %38, ptr %40, align 8, !tbaa !25
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %41, i32 0, i32 9
  %43 = load i64, ptr %42, align 8, !tbaa !26
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.xTASK_STATUS, ptr %44, i32 0, i32 5
  store i64 %43, ptr %45, align 8, !tbaa !27
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.xTASK_STATUS, ptr %46, i32 0, i32 6
  store i32 0, ptr %47, align 8, !tbaa !28
  %48 = load i32, ptr %8, align 4, !tbaa !11
  %49 = icmp ne i32 %48, 5
  br i1 %49, label %50, label %76

50:                                               ; preds = %16
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %53 = icmp eq ptr %51, %52
  br i1 %53, label %54, label %57

54:                                               ; preds = %50
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.xTASK_STATUS, ptr %55, i32 0, i32 3
  store i32 0, ptr %56, align 8, !tbaa !29
  br label %75

57:                                               ; preds = %50
  %58 = load i32, ptr %8, align 4, !tbaa !11
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.xTASK_STATUS, ptr %59, i32 0, i32 3
  store i32 %58, ptr %60, align 8, !tbaa !29
  %61 = load i32, ptr %8, align 4, !tbaa !11
  %62 = icmp eq i32 %61, 3
  br i1 %62, label %63, label %74

63:                                               ; preds = %57
  call void @vTaskSuspendAll()
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %64, i32 0, i32 3
  %66 = getelementptr inbounds %struct.xLIST_ITEM, ptr %65, i32 0, i32 4
  %67 = load ptr, ptr %66, align 8, !tbaa !30
  %68 = icmp ne ptr %67, null
  br i1 %68, label %69, label %72

69:                                               ; preds = %63
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.xTASK_STATUS, ptr %70, i32 0, i32 3
  store i32 2, ptr %71, align 8, !tbaa !29
  br label %72

72:                                               ; preds = %69, %63
  %73 = call i64 @xTaskResumeAll()
  br label %74

74:                                               ; preds = %72, %57
  br label %75

75:                                               ; preds = %74, %54
  br label %81

76:                                               ; preds = %16
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = call i32 @eTaskGetState(ptr noundef %77)
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.xTASK_STATUS, ptr %79, i32 0, i32 3
  store i32 %78, ptr %80, align 8, !tbaa !29
  br label %81

81:                                               ; preds = %76, %75
  %82 = load i64, ptr %7, align 8, !tbaa !9
  %83 = icmp ne i64 %82, 0
  br i1 %83, label %84, label %91

84:                                               ; preds = %81
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %85, i32 0, i32 5
  %87 = load ptr, ptr %86, align 8, !tbaa !22
  %88 = call zeroext i16 @prvTaskCheckFreeStackSpace(ptr noundef %87)
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.xTASK_STATUS, ptr %89, i32 0, i32 8
  store i16 %88, ptr %90, align 8, !tbaa !31
  br label %94

91:                                               ; preds = %81
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.xTASK_STATUS, ptr %92, i32 0, i32 8
  store i16 0, ptr %93, align 8, !tbaa !31
  br label %94

94:                                               ; preds = %91, %84
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @prvTaskCheckFreeStackSpace(ptr noundef) #1 section "privileged_functions"

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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"xTASK_STATUS", !6, i64 0, !6, i64 8, !10, i64 16, !12, i64 24, !10, i64 32, !10, i64 40, !12, i64 48, !6, i64 56, !15, i64 64}
!15 = !{!"short", !7, i64 0}
!16 = !{!14, !6, i64 8}
!17 = !{!18, !10, i64 128}
!18 = !{!"tskTaskControlBlock", !6, i64 0, !19, i64 8, !20, i64 48, !20, 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}
!19 = !{!"MPU_SETTINGS", !12, i64 0, !7, i64 4}
!20 = !{!"xLIST_ITEM", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!21 = !{!14, !10, i64 32}
!22 = !{!18, !6, i64 136}
!23 = !{!14, !6, i64 56}
!24 = !{!18, !10, i64 160}
!25 = !{!14, !10, i64 16}
!26 = !{!18, !10, i64 176}
!27 = !{!14, !10, i64 40}
!28 = !{!14, !12, i64 48}
!29 = !{!14, !12, i64 24}
!30 = !{!18, !6, i64 120}
!31 = !{!14, !15, i64 64}


; 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 dso_local void @vTaskSuspendAll() local_unnamed_addr #0 section "privileged_functions"

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

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

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

6:                                                ; preds = %4
  %7 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %4, %6
  %9 = phi ptr [ %7, %6 ], [ %0, %4 ]
  store ptr %9, ptr %1, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %9, i64 144
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %10, ptr %11, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %9, i64 128
  %13 = load i64, ptr %12, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %1, i64 32
  store i64 %13, ptr %14, align 8, !tbaa !19
  %15 = getelementptr inbounds i8, ptr %9, i64 136
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  %17 = getelementptr inbounds i8, ptr %1, i64 56
  store ptr %16, ptr %17, align 8, !tbaa !21
  %18 = getelementptr inbounds i8, ptr %9, i64 160
  %19 = load i64, ptr %18, align 8, !tbaa !22
  %20 = getelementptr inbounds i8, ptr %1, i64 16
  store i64 %19, ptr %20, align 8, !tbaa !23
  %21 = getelementptr inbounds i8, ptr %9, i64 176
  %22 = load i64, ptr %21, align 8, !tbaa !24
  %23 = getelementptr inbounds i8, ptr %1, i64 40
  store i64 %22, ptr %23, align 8, !tbaa !25
  %24 = getelementptr inbounds i8, ptr %1, i64 48
  store i32 0, ptr %24, align 8, !tbaa !26
  %.not = icmp eq i32 %3, 5
  br i1 %.not, label %38, label %25

25:                                               ; preds = %8
  %26 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %27 = icmp eq ptr %9, %26
  %28 = getelementptr inbounds i8, ptr %1, i64 24
  br i1 %27, label %29, label %30

29:                                               ; preds = %25
  store i32 0, ptr %28, align 8, !tbaa !27
  br label %41

30:                                               ; preds = %25
  store i32 %3, ptr %28, align 8, !tbaa !27
  %31 = icmp eq i32 %3, 3
  br i1 %31, label %32, label %41

32:                                               ; preds = %30
  tail call void @vTaskSuspendAll()
  %33 = getelementptr inbounds i8, ptr %9, i64 120
  %34 = load ptr, ptr %33, align 8, !tbaa !28
  %.not30 = icmp eq ptr %34, null
  br i1 %.not30, label %36, label %35

35:                                               ; preds = %32
  store i32 2, ptr %28, align 8, !tbaa !27
  br label %36

36:                                               ; preds = %35, %32
  %37 = tail call i64 @xTaskResumeAll()
  br label %41

38:                                               ; preds = %8
  %39 = tail call i32 @eTaskGetState(ptr noundef nonnull %9)
  %40 = getelementptr inbounds i8, ptr %1, i64 24
  store i32 %39, ptr %40, align 8, !tbaa !27
  br label %41

41:                                               ; preds = %29, %36, %30, %38
  %.not31 = icmp eq i64 %2, 0
  br i1 %.not31, label %45, label %42

42:                                               ; preds = %41
  %43 = load ptr, ptr %15, align 8, !tbaa !20
  %44 = tail call zeroext i16 @prvTaskCheckFreeStackSpace(ptr noundef %43)
  br label %45

45:                                               ; preds = %41, %42
  %.sink = phi i16 [ %44, %42 ], [ 0, %41 ]
  %46 = getelementptr inbounds i8, ptr %1, i64 64
  store i16 %.sink, ptr %46, align 8
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @prvTaskCheckFreeStackSpace(ptr noundef) local_unnamed_addr #0 section "privileged_functions"

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" }

!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, !6, i64 0}
!10 = !{!"xTASK_STATUS", !6, i64 0, !6, i64 8, !11, i64 16, !12, i64 24, !11, i64 32, !11, i64 40, !12, i64 48, !6, i64 56, !13, i64 64}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !6, i64 8}
!15 = !{!16, !11, i64 128}
!16 = !{!"tskTaskControlBlock", !6, i64 0, !17, i64 8, !18, i64 48, !18, 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}
!17 = !{!"MPU_SETTINGS", !12, i64 0, !7, i64 4}
!18 = !{!"xLIST_ITEM", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!19 = !{!10, !11, i64 32}
!20 = !{!16, !6, i64 136}
!21 = !{!10, !6, i64 56}
!22 = !{!16, !11, i64 160}
!23 = !{!10, !11, i64 16}
!24 = !{!16, !11, i64 176}
!25 = !{!10, !11, i64 40}
!26 = !{!10, !12, i64 48}
!27 = !{!10, !12, i64 24}
!28 = !{!16, !6, i64 120}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass