; 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

; Function Attrs: nounwind uwtable
define dso_local void @os_task_init() #0 {
  %1 = alloca i8, align 1
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #2
  store i8 0, ptr @nTasks, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i8 0, ptr %1, align 1, !tbaa !5
  br label %4

4:                                                ; preds = %57, %0
  %5 = load i8, ptr %1, align 1, !tbaa !5
  %6 = zext i8 %5 to i32
  %7 = icmp slt i32 %6, 1
  br i1 %7, label %8, label %60

8:                                                ; preds = %4
  %9 = load i8, ptr %1, align 1, !tbaa !5
  %10 = zext i8 %9 to i64
  %11 = getelementptr inbounds [1 x %struct.tcb], ptr @task_list, i64 0, i64 %10
  store ptr %11, ptr %3, align 8, !tbaa !8
  %12 = load ptr, ptr %3, align 8, !tbaa !8
  %13 = getelementptr inbounds %struct.tcb, ptr %12, i32 0, i32 13
  store i8 -1, ptr %13, align 8, !tbaa !10
  %14 = load ptr, ptr %3, align 8, !tbaa !8
  %15 = getelementptr inbounds %struct.tcb, ptr %14, i32 0, i32 3
  store i16 255, ptr %15, align 8, !tbaa !15
  %16 = load ptr, ptr %3, align 8, !tbaa !8
  %17 = getelementptr inbounds %struct.tcb, ptr %16, i32 0, i32 8
  store i8 0, ptr %17, align 1, !tbaa !16
  %18 = load ptr, ptr %3, align 8, !tbaa !8
  %19 = getelementptr inbounds %struct.tcb, ptr %18, i32 0, i32 9
  store i8 0, ptr %19, align 4, !tbaa !17
  %20 = load ptr, ptr %3, align 8, !tbaa !8
  %21 = getelementptr inbounds %struct.tcb, ptr %20, i32 0, i32 10
  store i8 0, ptr %21, align 1, !tbaa !18
  %22 = load ptr, ptr %3, align 8, !tbaa !8
  %23 = getelementptr inbounds %struct.tcb, ptr %22, i32 0, i32 11
  store i8 0, ptr %23, align 2, !tbaa !19
  %24 = load ptr, ptr %3, align 8, !tbaa !8
  %25 = getelementptr inbounds %struct.tcb, ptr %24, i32 0, i32 6
  store i8 0, ptr %25, align 1, !tbaa !20
  %26 = load ptr, ptr %3, align 8, !tbaa !8
  %27 = getelementptr inbounds %struct.tcb, ptr %26, i32 0, i32 2
  store i32 0, ptr %27, align 4, !tbaa !21
  %28 = load ptr, ptr %3, align 8, !tbaa !8
  %29 = getelementptr inbounds %struct.tcb, ptr %28, i32 0, i32 7
  store i8 -1, ptr %29, align 2, !tbaa !22
  %30 = load ptr, ptr %3, align 8, !tbaa !8
  %31 = getelementptr inbounds %struct.tcb, ptr %30, i32 0, i32 1
  store i32 0, ptr %31, align 8, !tbaa !23
  %32 = load ptr, ptr %3, align 8, !tbaa !8
  %33 = getelementptr inbounds %struct.tcb, ptr %32, i32 0, i32 0
  store ptr null, ptr %33, align 8, !tbaa !24
  %34 = load ptr, ptr %3, align 8, !tbaa !8
  %35 = getelementptr inbounds %struct.tcb, ptr %34, i32 0, i32 5
  store i8 -1, ptr %35, align 8, !tbaa !25
  %36 = load ptr, ptr %3, align 8, !tbaa !8
  %37 = getelementptr inbounds %struct.tcb, ptr %36, i32 0, i32 4
  store i32 0, ptr %37, align 4, !tbaa !26
  %38 = load ptr, ptr %3, align 8, !tbaa !8
  %39 = getelementptr inbounds %struct.tcb, ptr %38, i32 0, i32 12
  store i8 0, ptr %39, align 1, !tbaa !27
  store i8 0, ptr %2, align 1, !tbaa !5
  br label %40

40:                                               ; preds = %51, %8
  %41 = load i8, ptr %2, align 1, !tbaa !5
  %42 = zext i8 %41 to i64
  %43 = icmp ult i64 %42, 1
  br i1 %43, label %44, label %54

44:                                               ; preds = %40
  %45 = load ptr, ptr %3, align 8, !tbaa !8
  %46 = getelementptr inbounds %struct.tcb, ptr %45, i32 0, i32 14
  %47 = getelementptr inbounds %struct.EventQueue_t, ptr %46, i32 0, i32 0
  %48 = load i8, ptr %2, align 1, !tbaa !5
  %49 = zext i8 %48 to i64
  %50 = getelementptr inbounds [1 x i8], ptr %47, i64 0, i64 %49
  store i8 -1, ptr %50, align 1, !tbaa !5
  br label %51

51:                                               ; preds = %44
  %52 = load i8, ptr %2, align 1, !tbaa !5
  %53 = add i8 %52, 1
  store i8 %53, ptr %2, align 1, !tbaa !5
  br label %40, !llvm.loop !28

54:                                               ; preds = %40
  %55 = load ptr, ptr %3, align 8, !tbaa !8
  %56 = getelementptr inbounds %struct.tcb, ptr %55, i32 0, i32 15
  store ptr null, ptr %56, align 8, !tbaa !30
  br label %57

57:                                               ; preds = %54
  %58 = load i8, ptr %1, align 1, !tbaa !5
  %59 = add i8 %58, 1
  store i8 %59, ptr %1, align 1, !tbaa !5
  br label %4, !llvm.loop !31

60:                                               ; preds = %4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %1) #2
  ret void
}

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

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


; 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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @os_task_init() local_unnamed_addr #0 {
.critedge:
  store i8 0, ptr @nTasks, align 1, !tbaa !5
  store i8 -1, ptr getelementptr inbounds (i8, ptr @task_list, i64 32), align 16, !tbaa !8
  store i16 255, ptr getelementptr inbounds (i8, ptr @task_list, i64 16), align 16, !tbaa !14
  store i8 0, ptr getelementptr inbounds (i8, ptr @task_list, i64 25), align 1, !tbaa !15
  store i32 0, ptr getelementptr inbounds (i8, ptr @task_list, i64 12), align 4, !tbaa !16
  store i32 0, ptr getelementptr inbounds (i8, ptr @task_list, i64 27), align 1
  store i8 -1, ptr getelementptr inbounds (i8, ptr @task_list, i64 26), align 2, !tbaa !17
  store i32 0, ptr getelementptr inbounds (i8, ptr @task_list, i64 8), align 8, !tbaa !18
  store ptr null, ptr @task_list, align 16, !tbaa !19
  store i8 -1, ptr getelementptr inbounds (i8, ptr @task_list, i64 24), align 8, !tbaa !20
  store i32 0, ptr getelementptr inbounds (i8, ptr @task_list, i64 20), align 4, !tbaa !21
  store i8 0, ptr getelementptr inbounds (i8, ptr @task_list, i64 31), align 1, !tbaa !22
  store i8 -1, ptr getelementptr inbounds (i8, ptr @task_list, i64 33), align 1, !tbaa !5
  store ptr null, ptr getelementptr inbounds (i8, ptr @task_list, i64 40), align 8, !tbaa !23
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) 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" }

!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 32}
!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 = !{!9, !12, i64 16}
!15 = !{!9, !6, i64 25}
!16 = !{!9, !11, i64 12}
!17 = !{!9, !6, i64 26}
!18 = !{!9, !11, i64 8}
!19 = !{!9, !10, i64 0}
!20 = !{!9, !6, i64 24}
!21 = !{!9, !11, i64 20}
!22 = !{!9, !6, i64 31}
!23 = !{!9, !10, i64 40}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass