; LLVM IR from cocoOS/cocoOS :: src (os_task)

; 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.tcb = type { ptr, i32, i32, i16, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, %struct.EventQueue_t, ptr }
%struct.EventQueue_t = type { [1 x i8] }

@nTasks = external hidden global i8, align 1
@task_list = external hidden global [1 x %struct.tcb], align 16
@.str = external hidden unnamed_addr constant [61 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1

; 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 zeroext i8 @task_create(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, ptr noundef %3, i8 noundef zeroext %4, i16 noundef zeroext %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = alloca i16, align 2
  %13 = alloca i8, align 1
  %14 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i8 %2, ptr %9, align 1, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i8 %4, ptr %11, align 1, !tbaa !9
  store i16 %5, ptr %12, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %15 = call zeroext i8 @os_running()
  %16 = zext i8 %15 to i32
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %6
  call void @os_on_assert(ptr noundef @.str, i16 noundef zeroext 138, ptr noundef @.str.1)
  br label %19

19:                                               ; preds = %18, %6
  %20 = load i8, ptr @nTasks, align 1, !tbaa !9
  %21 = zext i8 %20 to i32
  %22 = icmp slt i32 %21, 1
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @os_on_assert(ptr noundef @.str, i16 noundef zeroext 139, ptr noundef @.str.2)
  br label %24

24:                                               ; preds = %23, %19
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  call void @os_on_assert(ptr noundef @.str, i16 noundef zeroext 140, ptr noundef @.str.3)
  br label %28

28:                                               ; preds = %27, %24
  %29 = load i8, ptr @nTasks, align 1, !tbaa !9
  store i8 %29, ptr %13, align 1, !tbaa !9
  br label %30

30:                                               ; preds = %47, %28
  %31 = load i8, ptr %13, align 1, !tbaa !9
  %32 = zext i8 %31 to i32
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %48

34:                                               ; preds = %30
  %35 = load i8, ptr %13, align 1, !tbaa !9
  %36 = add i8 %35, -1
  store i8 %36, ptr %13, align 1, !tbaa !9
  %37 = load i8, ptr %13, align 1, !tbaa !9
  %38 = zext i8 %37 to i64
  %39 = getelementptr inbounds [1 x %struct.tcb], ptr @task_list, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.tcb, ptr %39, i32 0, i32 6
  %41 = load i8, ptr %40, align 1, !tbaa !12
  %42 = zext i8 %41 to i32
  %43 = load i8, ptr %9, align 1, !tbaa !9
  %44 = zext i8 %43 to i32
  %45 = icmp ne i32 %42, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %34
  call void @os_on_assert(ptr noundef @.str, i16 noundef zeroext 147, ptr noundef @.str.4)
  br label %47

47:                                               ; preds = %46, %34
  br label %30, !llvm.loop !16

48:                                               ; preds = %30
  %49 = load i8, ptr @nTasks, align 1, !tbaa !9
  %50 = zext i8 %49 to i64
  %51 = getelementptr inbounds [1 x %struct.tcb], ptr @task_list, i64 0, i64 %50
  store ptr %51, ptr %14, align 8, !tbaa !5
  %52 = load i8, ptr @nTasks, align 1, !tbaa !9
  %53 = load ptr, ptr %14, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.tcb, ptr %53, i32 0, i32 5
  store i8 %52, ptr %54, align 8, !tbaa !18
  %55 = load i8, ptr %9, align 1, !tbaa !9
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.tcb, ptr %56, i32 0, i32 6
  store i8 %55, ptr %57, align 1, !tbaa !12
  %58 = load ptr, ptr %14, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.tcb, ptr %58, i32 0, i32 1
  store i32 5, ptr %59, align 8, !tbaa !19
  %60 = load ptr, ptr %14, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.tcb, ptr %60, i32 0, i32 2
  store i32 5, ptr %61, align 4, !tbaa !20
  %62 = load ptr, ptr %14, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.tcb, ptr %62, i32 0, i32 7
  store i8 0, ptr %63, align 2, !tbaa !21
  %64 = load ptr, ptr %14, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.tcb, ptr %64, i32 0, i32 3
  store i16 0, ptr %65, align 8, !tbaa !22
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load ptr, ptr %14, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.tcb, ptr %67, i32 0, i32 0
  store ptr %66, ptr %68, align 8, !tbaa !23
  %69 = load ptr, ptr %14, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.tcb, ptr %69, i32 0, i32 12
  store i8 0, ptr %70, align 1, !tbaa !24
  %71 = load ptr, ptr %14, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.tcb, ptr %71, i32 0, i32 4
  store i32 0, ptr %72, align 4, !tbaa !25
  %73 = load i8, ptr %11, align 1, !tbaa !9
  %74 = zext i8 %73 to i32
  %75 = icmp sgt i32 %74, 0
  br i1 %75, label %76, label %86

76:                                               ; preds = %48
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = load i8, ptr %11, align 1, !tbaa !9
  %79 = load i16, ptr %12, align 2, !tbaa !10
  %80 = load ptr, ptr %14, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.tcb, ptr %80, i32 0, i32 5
  %82 = load i8, ptr %81, align 8, !tbaa !18
  %83 = call zeroext i8 @os_msgQ_create(ptr noundef %77, i8 noundef zeroext %78, i16 noundef zeroext %79, i8 noundef zeroext %82)
  %84 = load ptr, ptr %14, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.tcb, ptr %84, i32 0, i32 8
  store i8 %83, ptr %85, align 1, !tbaa !26
  br label %89

86:                                               ; preds = %48
  %87 = load ptr, ptr %14, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.tcb, ptr %87, i32 0, i32 8
  store i8 -1, ptr %88, align 1, !tbaa !26
  br label %89

89:                                               ; preds = %86, %76
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = load ptr, ptr %14, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.tcb, ptr %91, i32 0, i32 15
  store ptr %90, ptr %92, align 8, !tbaa !27
  %93 = load i8, ptr @nTasks, align 1, !tbaa !9
  call void @os_task_clear_wait_queue(i8 noundef zeroext %93)
  %94 = load i8, ptr @nTasks, align 1, !tbaa !9
  %95 = add i8 %94, 1
  store i8 %95, ptr @nTasks, align 1, !tbaa !9
  %96 = load ptr, ptr %14, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.tcb, ptr %96, i32 0, i32 5
  %98 = load i8, ptr %97, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #3
  ret i8 %98
}

declare zeroext i8 @os_running() #2

declare void @os_on_assert(ptr noundef, i16 noundef zeroext, ptr noundef) #2

declare zeroext i8 @os_msgQ_create(ptr noundef, i8 noundef zeroext, i16 noundef zeroext, i8 noundef zeroext) #2

; Function Attrs: nounwind uwtable
declare dso_local void @os_task_clear_wait_queue(i8 noundef zeroext) #1

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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !7, i64 25}
!13 = !{!"tcb", !6, i64 0, !14, i64 8, !14, i64 12, !11, i64 16, !14, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !7, i64 28, !7, i64 29, !7, i64 30, !7, i64 31, !7, i64 32, !15, i64 33, !6, i64 40}
!14 = !{!"int", !7, i64 0}
!15 = !{!"", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!13, !7, i64 24}
!19 = !{!13, !14, i64 8}
!20 = !{!13, !14, i64 12}
!21 = !{!13, !7, i64 26}
!22 = !{!13, !11, i64 16}
!23 = !{!13, !6, i64 0}
!24 = !{!13, !7, i64 31}
!25 = !{!13, !14, i64 20}
!26 = !{!13, !7, i64 27}
!27 = !{!13, !6, i64 40}


; 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.tcb = type { ptr, i32, i32, i16, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, %struct.EventQueue_t, ptr }
%struct.EventQueue_t = type { [1 x i8] }

@nTasks = external hidden local_unnamed_addr global i8, align 1
@task_list = external hidden local_unnamed_addr global [1 x %struct.tcb], align 16
@.str = external hidden unnamed_addr constant [61 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @task_create(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, ptr noundef %3, i8 noundef zeroext %4, i16 noundef zeroext %5) local_unnamed_addr #0 {
  %7 = tail call zeroext i8 @os_running() #2
  %8 = icmp eq i8 %7, 0
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  tail call void @os_on_assert(ptr noundef nonnull @.str, i16 noundef zeroext 138, ptr noundef nonnull @.str.1) #2
  br label %10

10:                                               ; preds = %9, %6
  %11 = load i8, ptr @nTasks, align 1, !tbaa !5
  %12 = icmp eq i8 %11, 0
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  tail call void @os_on_assert(ptr noundef nonnull @.str, i16 noundef zeroext 139, ptr noundef nonnull @.str.2) #2
  br label %14

14:                                               ; preds = %13, %10
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %15, label %16

15:                                               ; preds = %14
  tail call void @os_on_assert(ptr noundef nonnull @.str, i16 noundef zeroext 140, ptr noundef nonnull @.str.3) #2
  br label %16

16:                                               ; preds = %15, %14
  %17 = load i8, ptr @nTasks, align 1, !tbaa !5
  %.not2528 = icmp eq i8 %17, 0
  br i1 %.not2528, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %16
  %18 = zext i8 %17 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %23
  %indvars.iv = phi i64 [ %18, %.lr.ph.preheader ], [ %19, %23 ]
  %19 = add nsw i64 %indvars.iv, -1
  %20 = getelementptr inbounds [1 x %struct.tcb], ptr @task_list, i64 0, i64 %19, i32 6
  %21 = load i8, ptr %20, align 1, !tbaa !8
  %.not27 = icmp eq i8 %21, %2
  br i1 %.not27, label %22, label %23

22:                                               ; preds = %.lr.ph
  tail call void @os_on_assert(ptr noundef nonnull @.str, i16 noundef zeroext 147, ptr noundef nonnull @.str.4) #2
  br label %23

23:                                               ; preds = %22, %.lr.ph
  %.not25.wide = icmp eq i64 %19, 0
  br i1 %.not25.wide, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !14

._crit_edge.loopexit:                             ; preds = %23
  %.pre = load i8, ptr @nTasks, align 1, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %16
  %24 = phi i8 [ %.pre, %._crit_edge.loopexit ], [ 0, %16 ]
  %25 = zext i8 %24 to i64
  %26 = getelementptr inbounds [1 x %struct.tcb], ptr @task_list, i64 0, i64 %25
  %27 = getelementptr inbounds i8, ptr %26, i64 24
  store i8 %24, ptr %27, align 8, !tbaa !16
  %28 = getelementptr inbounds i8, ptr %26, i64 25
  store i8 %2, ptr %28, align 1, !tbaa !8
  %29 = getelementptr inbounds i8, ptr %26, i64 8
  store i32 5, ptr %29, align 8, !tbaa !17
  %30 = getelementptr inbounds i8, ptr %26, i64 12
  store i32 5, ptr %30, align 4, !tbaa !18
  %31 = getelementptr inbounds i8, ptr %26, i64 26
  store i8 0, ptr %31, align 2, !tbaa !19
  %32 = getelementptr inbounds i8, ptr %26, i64 16
  store i16 0, ptr %32, align 16, !tbaa !20
  store ptr %0, ptr %26, align 16, !tbaa !21
  %33 = getelementptr inbounds i8, ptr %26, i64 31
  store i8 0, ptr %33, align 1, !tbaa !22
  %34 = getelementptr inbounds i8, ptr %26, i64 20
  store i32 0, ptr %34, align 4, !tbaa !23
  %.not26 = icmp eq i8 %4, 0
  br i1 %.not26, label %37, label %35

35:                                               ; preds = %._crit_edge
  %36 = tail call zeroext i8 @os_msgQ_create(ptr noundef %3, i8 noundef zeroext %4, i16 noundef zeroext %5, i8 noundef zeroext %24) #2
  %.pre31 = load i8, ptr @nTasks, align 1, !tbaa !5
  br label %37

37:                                               ; preds = %._crit_edge, %35
  %38 = phi i8 [ %.pre31, %35 ], [ %24, %._crit_edge ]
  %.sink = phi i8 [ %36, %35 ], [ -1, %._crit_edge ]
  %39 = getelementptr inbounds i8, ptr %26, i64 27
  store i8 %.sink, ptr %39, align 1
  %40 = getelementptr inbounds i8, ptr %26, i64 40
  store ptr %1, ptr %40, align 8, !tbaa !24
  tail call void @os_task_clear_wait_queue(i8 noundef zeroext %38)
  %41 = load i8, ptr @nTasks, align 1, !tbaa !5
  %42 = add i8 %41, 1
  store i8 %42, ptr @nTasks, align 1, !tbaa !5
  %43 = load i8, ptr %27, align 8, !tbaa !16
  ret i8 %43
}

declare zeroext i8 @os_running() local_unnamed_addr #1

declare void @os_on_assert(ptr noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #1

declare zeroext i8 @os_msgQ_create(ptr noundef, i8 noundef zeroext, i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @os_task_clear_wait_queue(i8 noundef zeroext) local_unnamed_addr #0

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !6, i64 25}
!9 = !{!"tcb", !10, i64 0, !11, i64 8, !11, i64 12, !12, i64 16, !11, i64 20, !6, i64 24, !6, i64 25, !6, i64 26, !6, i64 27, !6, i64 28, !6, i64 29, !6, i64 30, !6, i64 31, !6, i64 32, !13, i64 33, !10, i64 40}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"short", !6, i64 0}
!13 = !{!"", !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!9, !6, i64 24}
!17 = !{!9, !11, i64 8}
!18 = !{!9, !11, i64 12}
!19 = !{!9, !6, i64 26}
!20 = !{!9, !12, i64 16}
!21 = !{!9, !10, i64 0}
!22 = !{!9, !6, i64 31}
!23 = !{!9, !11, i64 20}
!24 = !{!9, !10, i64 40}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass,TailCallElimPass