; 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
@uxTaskNumber = external hidden global i64, section "privileged_data", align 8
@xTasksWaitingTermination = external hidden global %struct.xLIST, section "privileged_data", align 8
@uxDeletedTasksWaitingCleanUp = external hidden global i64, section "privileged_data", align 8
@uxCurrentNumberOfTasks = external hidden global i64, section "privileged_data", align 8
@xSchedulerRunning = external hidden global i64, 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
define dso_local void @vTaskDelete(ptr noundef %0) #1 section "privileged_functions" {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @vPortEnterCritical()
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %8

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

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %8, %6
  %11 = phi ptr [ %7, %6 ], [ %9, %8 ]
  store ptr %11, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %12, i32 0, i32 2
  %14 = call i64 @uxListRemove(ptr noundef %13)
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %10
  br label %18

17:                                               ; preds = %10
  br label %18

18:                                               ; preds = %17, %16
  %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 !9
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %28

24:                                               ; preds = %18
  %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)
  br label %29

28:                                               ; preds = %18
  br label %29

29:                                               ; preds = %28, %24
  %30 = load i64, ptr @uxTaskNumber, align 8, !tbaa !15
  %31 = add i64 %30, 1
  store i64 %31, ptr @uxTaskNumber, align 8, !tbaa !15
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %34 = icmp eq ptr %32, %33
  br i1 %34, label %35, label %40

35:                                               ; preds = %29
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %36, i32 0, i32 2
  call void @vListInsertEnd(ptr noundef @xTasksWaitingTermination, ptr noundef %37)
  %38 = load volatile i64, ptr @uxDeletedTasksWaitingCleanUp, align 8, !tbaa !15
  %39 = add i64 %38, 1
  store volatile i64 %39, ptr @uxDeletedTasksWaitingCleanUp, align 8, !tbaa !15
  br label %43

40:                                               ; preds = %29
  %41 = load volatile i64, ptr @uxCurrentNumberOfTasks, align 8, !tbaa !15
  %42 = add i64 %41, -1
  store volatile i64 %42, ptr @uxCurrentNumberOfTasks, align 8, !tbaa !15
  call void @prvResetNextTaskUnblockTime()
  br label %43

43:                                               ; preds = %40, %35
  call void @vPortExitCritical()
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %46 = icmp ne ptr %44, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %43
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  call void @prvDeleteTCB(ptr noundef %48)
  br label %49

49:                                               ; preds = %47, %43
  %50 = load volatile i64, ptr @xSchedulerRunning, align 8, !tbaa !15
  %51 = icmp ne i64 %50, 0
  br i1 %51, label %52, label %66

52:                                               ; preds = %49
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %55 = icmp eq ptr %53, %54
  br i1 %55, label %56, label %64

56:                                               ; preds = %52
  %57 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !15
  %58 = icmp eq i64 %57, 0
  %59 = zext i1 %58 to i32
  %60 = icmp eq i32 %59, 0
  br i1 %60, label %61, label %63

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

62:                                               ; preds = %62, %61
  br label %62

63:                                               ; preds = %56
  call void @vPortYield()
  br label %65

64:                                               ; preds = %52
  br label %65

65:                                               ; preds = %64, %63
  br label %66

66:                                               ; preds = %65, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare void @vPortEnterCritical() #2

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

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

; Function Attrs: nounwind uwtable
declare hidden void @prvResetNextTaskUnblockTime() #1 section "privileged_functions"

declare void @vPortExitCritical() #2

; Function Attrs: nounwind uwtable
declare hidden void @prvDeleteTCB(ptr noundef) #1 section "privileged_functions"

declare void @vPortYield() #2

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 = { "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, !6, i64 120}
!10 = !{!"tskTaskControlBlock", !6, i64 0, !11, i64 8, !13, i64 48, !13, i64 88, !14, i64 128, !6, i64 136, !7, i64 144, !14, i64 160, !14, i64 168, !14, i64 176, !14, i64 184, !7, i64 192, !7, i64 196, !7, i64 197, !7, i64 198}
!11 = !{!"MPU_SETTINGS", !12, i64 0, !7, i64 4}
!12 = !{!"int", !7, i64 0}
!13 = !{!"xLIST_ITEM", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!14 = !{!"long", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{i64 2148427528}


; 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
@uxTaskNumber = external hidden local_unnamed_addr global i64, section "privileged_data", align 8
@xTasksWaitingTermination = external hidden global %struct.xLIST, section "privileged_data", align 8
@uxDeletedTasksWaitingCleanUp = external hidden global i64, section "privileged_data", align 8
@uxCurrentNumberOfTasks = external hidden global i64, section "privileged_data", align 8
@xSchedulerRunning = external hidden global i64, section "privileged_data", align 8
@uxSchedulerSuspended = external hidden global i64, section "privileged_data", align 8

; Function Attrs: nounwind uwtable
define dso_local void @vTaskDelete(ptr noundef %0) local_unnamed_addr #0 section "privileged_functions" {
  tail call void @vPortEnterCritical() #2
  %2 = icmp eq ptr %0, null
  br i1 %2, label %3, label %5

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

5:                                                ; preds = %1, %3
  %6 = phi ptr [ %4, %3 ], [ %0, %1 ]
  %7 = getelementptr inbounds i8, ptr %6, i64 48
  %8 = tail call i64 @uxListRemove(ptr noundef nonnull %7) #2
  %9 = getelementptr inbounds i8, ptr %6, i64 120
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %14, label %11

11:                                               ; preds = %5
  %12 = getelementptr inbounds i8, ptr %6, i64 88
  %13 = tail call i64 @uxListRemove(ptr noundef nonnull %12) #2
  br label %14

14:                                               ; preds = %5, %11
  %15 = load i64, ptr @uxTaskNumber, align 8, !tbaa !15
  %16 = add i64 %15, 1
  store i64 %16, ptr @uxTaskNumber, align 8, !tbaa !15
  %17 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %18 = icmp eq ptr %6, %17
  br i1 %18, label %19, label %22

19:                                               ; preds = %14
  tail call void @vListInsertEnd(ptr noundef nonnull @xTasksWaitingTermination, ptr noundef nonnull %7) #2
  %20 = load volatile i64, ptr @uxDeletedTasksWaitingCleanUp, align 8, !tbaa !15
  %21 = add i64 %20, 1
  store volatile i64 %21, ptr @uxDeletedTasksWaitingCleanUp, align 8, !tbaa !15
  br label %25

22:                                               ; preds = %14
  %23 = load volatile i64, ptr @uxCurrentNumberOfTasks, align 8, !tbaa !15
  %24 = add i64 %23, -1
  store volatile i64 %24, ptr @uxCurrentNumberOfTasks, align 8, !tbaa !15
  tail call void @prvResetNextTaskUnblockTime()
  br label %25

25:                                               ; preds = %22, %19
  tail call void @vPortExitCritical() #2
  %26 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %.not11 = icmp eq ptr %6, %26
  br i1 %.not11, label %28, label %27

27:                                               ; preds = %25
  tail call void @prvDeleteTCB(ptr noundef nonnull %6)
  br label %28

28:                                               ; preds = %27, %25
  %29 = load volatile i64, ptr @xSchedulerRunning, align 8, !tbaa !15
  %.not12 = icmp eq i64 %29, 0
  br i1 %.not12, label %38, label %30

30:                                               ; preds = %28
  %31 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %32 = icmp eq ptr %6, %31
  br i1 %32, label %33, label %38

33:                                               ; preds = %30
  %34 = load volatile i64, ptr @uxSchedulerSuspended, align 8, !tbaa !15
  %.not13 = icmp eq i64 %34, 0
  br i1 %.not13, label %37, label %35

35:                                               ; preds = %33
  tail call void asm sideeffect " cpsid i ", "~{memory},~{dirflag},~{fpsr},~{flags}"() #2, !srcloc !16
  br label %36

36:                                               ; preds = %36, %35
  br label %36

37:                                               ; preds = %33
  tail call void @vPortYield() #2
  br label %38

38:                                               ; preds = %37, %30, %28
  ret void
}

declare void @vPortEnterCritical() local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare hidden void @prvResetNextTaskUnblockTime() local_unnamed_addr #0 section "privileged_functions"

declare void @vPortExitCritical() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @prvDeleteTCB(ptr noundef) local_unnamed_addr #0 section "privileged_functions"

declare void @vPortYield() local_unnamed_addr #1

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 = { "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, !6, i64 120}
!10 = !{!"tskTaskControlBlock", !6, i64 0, !11, i64 8, !13, i64 48, !13, i64 88, !14, i64 128, !6, i64 136, !7, i64 144, !14, i64 160, !14, i64 168, !14, i64 176, !14, i64 184, !7, i64 192, !7, i64 196, !7, i64 197, !7, i64 198}
!11 = !{!"MPU_SETTINGS", !12, i64 0, !7, i64 4}
!12 = !{!"int", !7, i64 0}
!13 = !{!"xLIST_ITEM", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!14 = !{!"long", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{i64 2148427528}


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