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

@xTasksWaitingTermination = external hidden global %struct.xLIST, section "privileged_data", align 8
@pxDelayedTaskList = external hidden global ptr, section "privileged_data", align 8
@pxOverflowDelayedTaskList = external hidden global ptr, section "privileged_data", align 8
@xSuspendedTaskList = external hidden global %struct.xLIST, section "privileged_data", align 8
@pxReadyTasksLists = external hidden global [5 x %struct.xLIST], section "privileged_data", align 16

; 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
define dso_local ptr @xTaskGetHandle(ptr noundef %0) #1 section "privileged_functions" {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 5, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call i64 @strlen(ptr noundef %5) #4
  %7 = icmp ult i64 %6, 10
  %8 = zext i1 %7 to i32
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %12

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

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

12:                                               ; preds = %1
  call void @vTaskSuspendAll()
  br label %13

13:                                               ; preds = %24, %12
  %14 = load i64, ptr %3, align 8, !tbaa !9
  %15 = add i64 %14, -1
  store i64 %15, ptr %3, align 8, !tbaa !9
  %16 = load i64, ptr %3, align 8, !tbaa !9
  %17 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %16
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = call ptr @prvSearchForNameWithinSingleList(ptr noundef %17, ptr noundef %18)
  store ptr %19, ptr %4, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %13
  br label %27

23:                                               ; preds = %13
  br label %24

24:                                               ; preds = %23
  %25 = load i64, ptr %3, align 8, !tbaa !9
  %26 = icmp ugt i64 %25, 0
  br i1 %26, label %13, label %27, !llvm.loop !12

27:                                               ; preds = %24, %22
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %34

30:                                               ; preds = %27
  %31 = load volatile ptr, ptr @pxDelayedTaskList, align 8, !tbaa !5
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = call ptr @prvSearchForNameWithinSingleList(ptr noundef %31, ptr noundef %32)
  store ptr %33, ptr %4, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %30, %27
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = icmp eq ptr %35, null
  br i1 %36, label %37, label %41

37:                                               ; preds = %34
  %38 = load volatile ptr, ptr @pxOverflowDelayedTaskList, align 8, !tbaa !5
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = call ptr @prvSearchForNameWithinSingleList(ptr noundef %38, ptr noundef %39)
  store ptr %40, ptr %4, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %37, %34
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = icmp eq ptr %42, null
  br i1 %43, label %44, label %47

44:                                               ; preds = %41
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = call ptr @prvSearchForNameWithinSingleList(ptr noundef @xSuspendedTaskList, ptr noundef %45)
  store ptr %46, ptr %4, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %44, %41
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %53

50:                                               ; preds = %47
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = call ptr @prvSearchForNameWithinSingleList(ptr noundef @xTasksWaitingTermination, ptr noundef %51)
  store ptr %52, ptr %4, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %50, %47
  %54 = call i64 @xTaskResumeAll()
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %55
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @prvSearchForNameWithinSingleList(ptr noundef, 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 willreturn memory(read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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 = !{i64 2148449320}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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

@xTasksWaitingTermination = external hidden global %struct.xLIST, section "privileged_data", align 8
@pxDelayedTaskList = external hidden global ptr, section "privileged_data", align 8
@pxOverflowDelayedTaskList = external hidden global ptr, section "privileged_data", align 8
@xSuspendedTaskList = external hidden global %struct.xLIST, section "privileged_data", align 8
@pxReadyTasksLists = external hidden global [5 x %struct.xLIST], section "privileged_data", align 16

; 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
define dso_local ptr @xTaskGetHandle(ptr noundef %0) local_unnamed_addr #0 section "privileged_functions" {
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #2
  %3 = icmp ugt i64 %2, 9
  br i1 %3, label %4, label %6

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

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

6:                                                ; preds = %1
  tail call void @vTaskSuspendAll()
  br label %7

7:                                                ; preds = %7, %6
  %.015 = phi i64 [ 5, %6 ], [ %8, %7 ]
  %8 = add nsw i64 %.015, -1
  %9 = getelementptr inbounds [5 x %struct.xLIST], ptr @pxReadyTasksLists, i64 0, i64 %8
  %10 = tail call ptr @prvSearchForNameWithinSingleList(ptr noundef nonnull %9, ptr noundef %0)
  %11 = icmp eq ptr %10, null
  %12 = icmp ne i64 %8, 0
  %or.cond = and i1 %11, %12
  br i1 %or.cond, label %7, label %13, !llvm.loop !6

13:                                               ; preds = %7
  br i1 %11, label %14, label %.thread21

14:                                               ; preds = %13
  %15 = load volatile ptr, ptr @pxDelayedTaskList, align 8, !tbaa !8
  %16 = tail call ptr @prvSearchForNameWithinSingleList(ptr noundef %15, ptr noundef %0)
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %.thread21

18:                                               ; preds = %14
  %19 = load volatile ptr, ptr @pxOverflowDelayedTaskList, align 8, !tbaa !8
  %20 = tail call ptr @prvSearchForNameWithinSingleList(ptr noundef %19, ptr noundef %0)
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %.thread21

22:                                               ; preds = %18
  %23 = tail call ptr @prvSearchForNameWithinSingleList(ptr noundef nonnull @xSuspendedTaskList, ptr noundef %0)
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %.thread21

25:                                               ; preds = %22
  %26 = tail call ptr @prvSearchForNameWithinSingleList(ptr noundef nonnull @xTasksWaitingTermination, ptr noundef %0)
  br label %.thread21

.thread21:                                        ; preds = %13, %14, %18, %25, %22
  %.3 = phi ptr [ %26, %25 ], [ %23, %22 ], [ %20, %18 ], [ %16, %14 ], [ %10, %13 ]
  %27 = tail call i64 @xTaskResumeAll()
  ret ptr %.3
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden ptr @prvSearchForNameWithinSingleList(ptr noundef, 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" }
attributes #1 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }
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 = !{i64 2148449320}
!6 = distinct !{!6, !7}
!7 = !{!"llvm.loop.mustprogress"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass