; 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
@pxReadyTasksLists = external hidden global [5 x %struct.xLIST], section "privileged_data", align 16
@uxTopReadyPriority = 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

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

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

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %10, i32 0, i32 4
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %13, i32 0, i32 4
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = icmp ult i64 %12, %15
  br i1 %16, label %17, label %118

17:                                               ; preds = %9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %18, i32 0, i32 3
  %20 = getelementptr inbounds %struct.xLIST_ITEM, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !16
  %22 = zext i32 %21 to i64
  %23 = and i64 %22, 2147483648
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %25, label %34

25:                                               ; preds = %17
  %26 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %26, i32 0, i32 4
  %28 = load i64, ptr %27, align 8, !tbaa !11
  %29 = trunc i64 %28 to i32
  %30 = sub i32 5, %29
  %31 = load ptr, ptr %3, 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 0
  store i32 %30, ptr %33, align 8, !tbaa !16
  br label %35

34:                                               ; preds = %17
  br label %35

35:                                               ; preds = %34, %25
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %36, i32 0, i32 2
  %38 = getelementptr inbounds %struct.xLIST_ITEM, ptr %37, i32 0, i32 4
  %39 = load ptr, ptr %38, align 8, !tbaa !17
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %40, i32 0, i32 4
  %42 = load i64, ptr %41, align 8, !tbaa !11
  %43 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %42
  %44 = icmp eq ptr %39, %43
  %45 = zext i1 %44 to i64
  %46 = select i1 %44, i64 1, i64 0
  %47 = icmp ne i64 %46, 0
  br i1 %47, label %48, label %111

48:                                               ; preds = %35
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %49, i32 0, i32 2
  %51 = call i64 @uxListRemove(ptr noundef %50)
  %52 = icmp eq i64 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %48
  br label %55

54:                                               ; preds = %48
  br label %55

55:                                               ; preds = %54, %53
  %56 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %56, i32 0, i32 4
  %58 = load i64, ptr %57, align 8, !tbaa !11
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %59, i32 0, i32 4
  store i64 %58, ptr %60, align 8, !tbaa !11
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %61, i32 0, i32 4
  %63 = load i64, ptr %62, align 8, !tbaa !11
  %64 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !9
  %65 = icmp ugt i64 %63, %64
  br i1 %65, label %66, label %70

66:                                               ; preds = %55
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %67, i32 0, i32 4
  %69 = load i64, ptr %68, align 8, !tbaa !11
  store volatile i64 %69, ptr @uxTopReadyPriority, align 8, !tbaa !9
  br label %70

70:                                               ; preds = %66, %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %71, i32 0, i32 4
  %73 = load i64, ptr %72, align 8, !tbaa !11
  %74 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %73
  %75 = getelementptr inbounds %struct.xLIST, ptr %74, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !18
  store ptr %76, ptr %5, align 8, !tbaa !5
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %78, i32 0, i32 2
  %80 = getelementptr inbounds %struct.xLIST_ITEM, ptr %79, i32 0, i32 1
  store ptr %77, ptr %80, align 8, !tbaa !21
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.xLIST_ITEM, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !22
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %84, i32 0, i32 2
  %86 = getelementptr inbounds %struct.xLIST_ITEM, ptr %85, i32 0, i32 2
  store ptr %83, ptr %86, align 8, !tbaa !23
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %87, i32 0, i32 2
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.xLIST_ITEM, ptr %89, i32 0, i32 2
  %91 = load ptr, ptr %90, align 8, !tbaa !22
  %92 = getelementptr inbounds %struct.xLIST_ITEM, ptr %91, i32 0, i32 1
  store ptr %88, ptr %92, align 8, !tbaa !24
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %93, i32 0, i32 2
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.xLIST_ITEM, ptr %95, i32 0, i32 2
  store ptr %94, ptr %96, align 8, !tbaa !22
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %97, i32 0, i32 4
  %99 = load i64, ptr %98, align 8, !tbaa !11
  %100 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %99
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %101, i32 0, i32 2
  %103 = getelementptr inbounds %struct.xLIST_ITEM, ptr %102, i32 0, i32 4
  store ptr %100, ptr %103, align 8, !tbaa !17
  %104 = load ptr, ptr %3, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %104, i32 0, i32 4
  %106 = load i64, ptr %105, align 8, !tbaa !11
  %107 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %106
  %108 = getelementptr inbounds %struct.xLIST, ptr %107, i32 0, i32 0
  %109 = load volatile i64, ptr %108, align 8, !tbaa !25
  %110 = add i64 %109, 1
  store volatile i64 %110, ptr %108, align 8, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %117

111:                                              ; preds = %35
  %112 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %112, i32 0, i32 4
  %114 = load i64, ptr %113, align 8, !tbaa !11
  %115 = load ptr, ptr %3, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %115, i32 0, i32 4
  store i64 %114, ptr %116, align 8, !tbaa !11
  br label %117

117:                                              ; preds = %111, %70
  store i64 1, ptr %4, align 8, !tbaa !9
  br label %129

118:                                              ; preds = %9
  %119 = load ptr, ptr %3, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %119, i32 0, i32 9
  %121 = load i64, ptr %120, align 8, !tbaa !26
  %122 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !5
  %123 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %122, i32 0, i32 4
  %124 = load i64, ptr %123, align 8, !tbaa !11
  %125 = icmp ult i64 %121, %124
  br i1 %125, label %126, label %127

126:                                              ; preds = %118
  store i64 1, ptr %4, align 8, !tbaa !9
  br label %128

127:                                              ; preds = %118
  br label %128

128:                                              ; preds = %127, %126
  br label %129

129:                                              ; preds = %128, %117
  br label %131

130:                                              ; preds = %1
  br label %131

131:                                              ; preds = %130, %129
  %132 = load i64, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i64 %132
}

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 = !{!12, !10, i64 128}
!12 = !{!"tskTaskControlBlock", !6, i64 0, !13, i64 8, !15, i64 48, !15, 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}
!13 = !{!"MPU_SETTINGS", !14, i64 0, !7, i64 4}
!14 = !{!"int", !7, i64 0}
!15 = !{!"xLIST_ITEM", !14, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!16 = !{!12, !14, i64 88}
!17 = !{!12, !6, i64 80}
!18 = !{!19, !6, i64 8}
!19 = !{!"xLIST", !10, i64 0, !6, i64 8, !20, i64 16}
!20 = !{!"xMINI_LIST_ITEM", !14, i64 0, !6, i64 8, !6, i64 16}
!21 = !{!12, !6, i64 56}
!22 = !{!15, !6, i64 16}
!23 = !{!12, !6, i64 64}
!24 = !{!15, !6, i64 8}
!25 = !{!19, !10, i64 0}
!26 = !{!12, !10, i64 176}


; 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
@pxReadyTasksLists = external hidden global [5 x %struct.xLIST], section "privileged_data", align 16
@uxTopReadyPriority = external hidden global i64, section "privileged_data", align 8

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 2) i64 @xTaskPriorityInherit(ptr noundef %0) local_unnamed_addr #1 section "privileged_functions" {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %55, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 128
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !14
  %6 = getelementptr inbounds i8, ptr %5, i64 128
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = icmp ult i64 %4, %7
  br i1 %8, label %9, label %48

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 88
  %11 = load i32, ptr %10, align 8, !tbaa !15
  %12 = icmp sgt i32 %11, -1
  br i1 %12, label %13, label %19

13:                                               ; preds = %9
  %14 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %14, i64 128
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = trunc i64 %16 to i32
  %18 = sub i32 5, %17
  store i32 %18, ptr %10, align 8, !tbaa !15
  br label %19

19:                                               ; preds = %9, %13
  %20 = getelementptr inbounds i8, ptr %0, i64 48
  %21 = getelementptr inbounds i8, ptr %0, i64 80
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %4
  %24 = icmp eq ptr %22, %23
  br i1 %24, label %25, label %44

25:                                               ; preds = %19
  %26 = tail call i64 @uxListRemove(ptr noundef nonnull %20) #2
  %27 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %27, i64 128
  %29 = load i64, ptr %28, align 8, !tbaa !5
  store i64 %29, ptr %3, align 8, !tbaa !5
  %30 = load volatile i64, ptr @uxTopReadyPriority, align 8, !tbaa !17
  %31 = icmp ugt i64 %29, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %25
  store volatile i64 %29, ptr @uxTopReadyPriority, align 8, !tbaa !17
  br label %33

33:                                               ; preds = %32, %25
  %34 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %29, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %35, ptr %36, align 8, !tbaa !21
  %37 = getelementptr inbounds i8, ptr %35, i64 16
  %38 = load ptr, ptr %37, align 8, !tbaa !22
  %39 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %38, ptr %39, align 8, !tbaa !23
  %40 = getelementptr inbounds i8, ptr %38, i64 8
  store ptr %20, ptr %40, align 8, !tbaa !24
  store ptr %20, ptr %37, align 8, !tbaa !22
  %41 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %29
  store ptr %41, ptr %21, align 8, !tbaa !16
  %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
  br label %55

44:                                               ; preds = %19
  %45 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !14
  %46 = getelementptr inbounds i8, ptr %45, i64 128
  %47 = load i64, ptr %46, align 8, !tbaa !5
  store i64 %47, ptr %3, align 8, !tbaa !5
  br label %55

48:                                               ; preds = %2
  %49 = getelementptr inbounds i8, ptr %0, i64 176
  %50 = load i64, ptr %49, align 8, !tbaa !26
  %51 = load volatile ptr, ptr @pxCurrentTCB, align 8, !tbaa !14
  %52 = getelementptr inbounds i8, ptr %51, i64 128
  %53 = load i64, ptr %52, align 8, !tbaa !5
  %54 = icmp ult i64 %50, %53
  %spec.select = zext i1 %54 to i64
  br label %55

55:                                               ; preds = %48, %33, %44, %1
  %.0 = phi i64 [ 0, %1 ], [ 1, %44 ], [ 1, %33 ], [ %spec.select, %48 ]
  ret i64 %.0
}

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


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