; 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_PARAMETERS = type { ptr, ptr, i16, ptr, i64, ptr, [3 x %struct.xMEMORY_REGION] }
%struct.xMEMORY_REGION = type { ptr, i32, i32 }
%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: nounwind uwtable
define dso_local i64 @xTaskCreateRestricted(ptr noundef %0, ptr noundef %1) #0 section "privileged_functions" {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 -1, ptr %6, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.xTASK_PARAMETERS, ptr %7, i32 0, i32 5
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %13

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

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

13:                                               ; preds = %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.xTASK_PARAMETERS, ptr %14, i32 0, i32 5
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %53

18:                                               ; preds = %13
  %19 = call ptr @pvPortMalloc(i64 noundef 200)
  store ptr %19, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %52

22:                                               ; preds = %18
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.xTASK_PARAMETERS, ptr %23, i32 0, i32 5
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %26, i32 0, i32 5
  store ptr %25, ptr %27, align 8, !tbaa !15
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.tskTaskControlBlock, ptr %28, i32 0, i32 13
  store i8 1, ptr %29, align 1, !tbaa !20
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.xTASK_PARAMETERS, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !21
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.xTASK_PARAMETERS, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !22
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.xTASK_PARAMETERS, ptr %36, i32 0, i32 2
  %38 = load i16, ptr %37, align 8, !tbaa !23
  %39 = zext i16 %38 to i32
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.xTASK_PARAMETERS, ptr %40, i32 0, i32 3
  %42 = load ptr, ptr %41, align 8, !tbaa !24
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.xTASK_PARAMETERS, ptr %43, i32 0, i32 4
  %45 = load i64, ptr %44, align 8, !tbaa !25
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.xTASK_PARAMETERS, ptr %48, i32 0, i32 6
  %50 = getelementptr inbounds [3 x %struct.xMEMORY_REGION], ptr %49, i64 0, i64 0
  call void @prvInitialiseNewTask(ptr noundef %32, ptr noundef %35, i32 noundef %39, ptr noundef %42, i64 noundef %45, ptr noundef %46, ptr noundef %47, ptr noundef %50)
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  call void @prvAddNewTaskToReadyList(ptr noundef %51)
  store i64 1, ptr %6, align 8, !tbaa !9
  br label %52

52:                                               ; preds = %22, %18
  br label %53

53:                                               ; preds = %52, %13
  %54 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i64 %54
}

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

declare ptr @pvPortMalloc(i64 noundef) #2 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) #0 section "privileged_functions"

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 40}
!12 = !{!"xTASK_PARAMETERS", !6, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !7, i64 48}
!13 = !{!"short", !7, i64 0}
!14 = !{i64 2148422623}
!15 = !{!16, !6, i64 136}
!16 = !{!"tskTaskControlBlock", !6, i64 0, !17, i64 8, !19, i64 48, !19, 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}
!17 = !{!"MPU_SETTINGS", !18, i64 0, !7, i64 4}
!18 = !{!"int", !7, i64 0}
!19 = !{!"xLIST_ITEM", !18, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!20 = !{!16, !7, i64 197}
!21 = !{!12, !6, i64 0}
!22 = !{!12, !6, i64 8}
!23 = !{!12, !13, i64 16}
!24 = !{!12, !6, i64 24}
!25 = !{!12, !10, i64 32}


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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -1, 2) i64 @xTaskCreateRestricted(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 section "privileged_functions" {
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %8

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

7:                                                ; preds = %7, %6
  br label %7

8:                                                ; preds = %2
  %9 = tail call ptr @pvPortMalloc(i64 noundef 200) #2
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %25, label %10

10:                                               ; preds = %8
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %9, i64 136
  store ptr %11, ptr %12, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %9, i64 197
  store i8 1, ptr %13, align 1, !tbaa !18
  %14 = load ptr, ptr %0, align 8, !tbaa !19
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = load i16, ptr %17, align 8, !tbaa !21
  %19 = zext i16 %18 to i32
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !22
  %22 = getelementptr inbounds i8, ptr %0, i64 32
  %23 = load i64, ptr %22, align 8, !tbaa !23
  %24 = getelementptr inbounds i8, ptr %0, i64 48
  tail call void @prvInitialiseNewTask(ptr noundef %14, ptr noundef %16, i32 noundef %19, ptr noundef %21, i64 noundef %23, ptr noundef %1, ptr noundef nonnull %9, ptr noundef nonnull %24)
  tail call void @prvAddNewTaskToReadyList(ptr noundef nonnull %9)
  br label %25

25:                                               ; preds = %8, %10
  %.0 = phi i64 [ 1, %10 ], [ -1, %8 ]
  ret i64 %.0
}

declare ptr @pvPortMalloc(i64 noundef) local_unnamed_addr #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) local_unnamed_addr #0 section "privileged_functions"

; Function Attrs: nounwind uwtable
declare hidden void @prvAddNewTaskToReadyList(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 = { "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 40}
!6 = !{!"xTASK_PARAMETERS", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !11, i64 32, !7, i64 40, !8, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{i64 2148422623}
!13 = !{!14, !7, i64 136}
!14 = !{!"tskTaskControlBlock", !7, i64 0, !15, i64 8, !17, i64 48, !17, i64 88, !11, i64 128, !7, i64 136, !8, i64 144, !11, i64 160, !11, i64 168, !11, i64 176, !11, i64 184, !8, i64 192, !8, i64 196, !8, i64 197, !8, i64 198}
!15 = !{!"MPU_SETTINGS", !16, i64 0, !8, i64 4}
!16 = !{!"int", !8, i64 0}
!17 = !{!"xLIST_ITEM", !16, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!18 = !{!14, !8, i64 197}
!19 = !{!6, !7, i64 0}
!20 = !{!6, !7, i64 8}
!21 = !{!6, !10, i64 16}
!22 = !{!6, !7, i64 24}
!23 = !{!6, !11, i64 32}


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