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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
declare hidden void @prvInitialiseNewTask(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #2 section "privileged_functions"

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

; 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 i64 @xTaskCreate(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2, ptr noundef %3, i64 noundef %4, ptr noundef %5) #2 section "privileged_functions" {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i16, align 2
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i16 %2, ptr %9, align 2, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !11
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %16 = load i16, ptr %9, align 2, !tbaa !9
  %17 = zext i16 %16 to i64
  %18 = mul i64 %17, 4
  %19 = call ptr @pvPortMalloc(i64 noundef %18)
  store ptr %19, ptr %15, align 8, !tbaa !5
  %20 = load ptr, ptr %15, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %33

22:                                               ; preds = %6
  %23 = call ptr @pvPortMalloc(i64 noundef 200)
  store ptr %23, ptr %13, align 8, !tbaa !5
  %24 = load ptr, ptr %13, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %30

26:                                               ; preds = %22
  %27 = load ptr, ptr %15, align 8, !tbaa !5
  %28 = load ptr, ptr %13, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %28, i32 0, i32 5
  store ptr %27, ptr %29, align 8, !tbaa !13
  br label %32

30:                                               ; preds = %22
  %31 = load ptr, ptr %15, align 8, !tbaa !5
  call void @vPortFree(ptr noundef %31)
  br label %32

32:                                               ; preds = %30, %26
  br label %34

33:                                               ; preds = %6
  store ptr null, ptr %13, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %33, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  %35 = load ptr, ptr %13, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %49

37:                                               ; preds = %34
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %38, i32 0, i32 13
  store i8 0, ptr %39, align 1, !tbaa !18
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load i16, ptr %9, align 2, !tbaa !9
  %43 = zext i16 %42 to i32
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = load i64, ptr %11, align 8, !tbaa !11
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = load ptr, ptr %13, align 8, !tbaa !5
  call void @prvInitialiseNewTask(ptr noundef %40, ptr noundef %41, i32 noundef %43, ptr noundef %44, i64 noundef %45, ptr noundef %46, ptr noundef %47, ptr noundef null)
  %48 = load ptr, ptr %13, align 8, !tbaa !5
  call void @prvAddNewTaskToReadyList(ptr noundef %48)
  store i64 1, ptr %14, align 8, !tbaa !11
  br label %50

49:                                               ; preds = %34
  store i64 -1, ptr %14, align 8, !tbaa !11
  br label %50

50:                                               ; preds = %49, %37
  %51 = load i64, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  ret i64 %51
}

declare void @vPortFree(ptr noundef) #1 section "privileged_functions"

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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 136}
!14 = !{!"tskTaskControlBlock", !6, i64 0, !15, i64 8, !17, i64 48, !17, 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}
!15 = !{!"MPU_SETTINGS", !16, i64 0, !7, i64 4}
!16 = !{!"int", !7, i64 0}
!17 = !{!"xLIST_ITEM", !16, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!18 = !{!14, !7, i64 197}


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

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

; Function Attrs: nounwind uwtable
declare hidden void @prvInitialiseNewTask(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1 section "privileged_functions"

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -1, 2) i64 @xTaskCreate(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2, ptr noundef %3, i64 noundef %4, ptr noundef %5) local_unnamed_addr #1 section "privileged_functions" {
  %7 = zext i16 %2 to i64
  %8 = shl nuw nsw i64 %7, 2
  %9 = tail call ptr @pvPortMalloc(i64 noundef %8) #2
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %.thread, label %10

10:                                               ; preds = %6
  %11 = tail call ptr @pvPortMalloc(i64 noundef 200) #2
  %.not19 = icmp eq ptr %11, null
  br i1 %.not19, label %12, label %13

12:                                               ; preds = %10
  tail call void @vPortFree(ptr noundef nonnull %9) #2
  br label %.thread

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %11, i64 136
  store ptr %9, ptr %14, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %11, i64 197
  store i8 0, ptr %15, align 1, !tbaa !14
  %16 = zext i16 %2 to i32
  tail call void @prvInitialiseNewTask(ptr noundef %0, ptr noundef %1, i32 noundef %16, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef nonnull %11, ptr noundef null)
  tail call void @prvAddNewTaskToReadyList(ptr noundef nonnull %11)
  br label %.thread

.thread:                                          ; preds = %6, %12, %13
  %.016 = phi i64 [ 1, %13 ], [ -1, %12 ], [ -1, %6 ]
  ret i64 %.016
}

declare void @vPortFree(ptr noundef) local_unnamed_addr #0 section "privileged_functions"

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, !7, i64 136}
!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 = !{!6, !8, i64 197}


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