; LLVM IR from asllop/AppOS :: core/task (task_internal)

; 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.TaskStruct = type { i32, ptr, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, i64, i64 }

@isScheduling = external hidden global i8, align 1
@taskCounter = external hidden global i32, align 4
@taskArray = external hidden global [10 x %struct.TaskStruct], align 16

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

3:                                                ; preds = %31, %0
  %4 = load i32, ptr %2, align 4, !tbaa !9
  %5 = icmp slt i32 %4, 10
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %34

7:                                                ; preds = %3
  %8 = load i32, ptr %2, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [10 x %struct.TaskStruct], ptr @taskArray, i64 0, i64 %9
  store ptr %10, ptr %1, align 8, !tbaa !11
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = add nsw i32 %11, 1
  %13 = load ptr, ptr %1, align 8, !tbaa !11
  %14 = getelementptr inbounds %struct.TaskStruct, ptr %13, i32 0, i32 0
  store i32 %12, ptr %14, align 8, !tbaa !13
  %15 = load ptr, ptr %1, align 8, !tbaa !11
  %16 = getelementptr inbounds %struct.TaskStruct, ptr %15, i32 0, i32 1
  store ptr null, ptr %16, align 8, !tbaa !17
  %17 = load ptr, ptr %1, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.TaskStruct, ptr %17, i32 0, i32 2
  store i32 0, ptr %18, align 8, !tbaa !18
  %19 = load ptr, ptr %1, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.TaskStruct, ptr %19, i32 0, i32 3
  store i32 0, ptr %20, align 4, !tbaa !19
  %21 = load ptr, ptr %1, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct.TaskStruct, ptr %21, i32 0, i32 4
  store i32 0, ptr %22, align 8, !tbaa !20
  %23 = load ptr, ptr %1, align 8, !tbaa !11
  %24 = getelementptr inbounds %struct.TaskStruct, ptr %23, i32 0, i32 5
  store i32 0, ptr %24, align 4, !tbaa !21
  %25 = load ptr, ptr %1, align 8, !tbaa !11
  %26 = getelementptr inbounds %struct.TaskStruct, ptr %25, i32 0, i32 6
  store ptr null, ptr %26, align 8, !tbaa !22
  %27 = load ptr, ptr %1, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.TaskStruct, ptr %27, i32 0, i32 7
  store ptr null, ptr %28, align 8, !tbaa !23
  %29 = load ptr, ptr %1, align 8, !tbaa !11
  %30 = getelementptr inbounds %struct.TaskStruct, ptr %29, i32 0, i32 8
  store ptr null, ptr %30, align 8, !tbaa !24
  br label %31

31:                                               ; preds = %7
  %32 = load i32, ptr %2, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %2, align 4, !tbaa !9
  br label %3, !llvm.loop !25

34:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 8, 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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"TaskStruct", !10, i64 0, !12, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !15, i64 72, !16, i64 80}
!15 = !{!"long", !7, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = !{!14, !12, i64 8}
!18 = !{!14, !10, i64 16}
!19 = !{!14, !10, i64 20}
!20 = !{!14, !10, i64 24}
!21 = !{!14, !10, i64 28}
!22 = !{!14, !12, i64 32}
!23 = !{!14, !12, i64 40}
!24 = !{!14, !12, i64 48}
!25 = distinct !{!25, !26}
!26 = !{!"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.TaskStruct = type { i32, ptr, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, i64, i64 }

@isScheduling = external hidden local_unnamed_addr global i8, align 1
@taskCounter = external hidden local_unnamed_addr global i32, align 4
@taskArray = external hidden local_unnamed_addr global [10 x %struct.TaskStruct], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @init_task_buffer() local_unnamed_addr #0 {
  store i8 0, ptr @isScheduling, align 1, !tbaa !5
  store i32 0, ptr @taskCounter, align 4, !tbaa !9
  store i32 1, ptr @taskArray, align 16, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) getelementptr inbounds (i8, ptr @taskArray, i64 8), i8 0, i64 48, i1 false)
  store i32 2, ptr getelementptr inbounds (i8, ptr @taskArray, i64 88), align 8, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(48) getelementptr inbounds (i8, ptr @taskArray, i64 96), i8 0, i64 48, i1 false)
  store i32 3, ptr getelementptr inbounds (i8, ptr @taskArray, i64 176), align 16, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) getelementptr inbounds (i8, ptr @taskArray, i64 184), i8 0, i64 48, i1 false)
  store i32 4, ptr getelementptr inbounds (i8, ptr @taskArray, i64 264), align 8, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(48) getelementptr inbounds (i8, ptr @taskArray, i64 272), i8 0, i64 48, i1 false)
  store i32 5, ptr getelementptr inbounds (i8, ptr @taskArray, i64 352), align 16, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) getelementptr inbounds (i8, ptr @taskArray, i64 360), i8 0, i64 48, i1 false)
  store i32 6, ptr getelementptr inbounds (i8, ptr @taskArray, i64 440), align 8, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(48) getelementptr inbounds (i8, ptr @taskArray, i64 448), i8 0, i64 48, i1 false)
  store i32 7, ptr getelementptr inbounds (i8, ptr @taskArray, i64 528), align 16, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) getelementptr inbounds (i8, ptr @taskArray, i64 536), i8 0, i64 48, i1 false)
  store i32 8, ptr getelementptr inbounds (i8, ptr @taskArray, i64 616), align 8, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(48) getelementptr inbounds (i8, ptr @taskArray, i64 624), i8 0, i64 48, i1 false)
  store i32 9, ptr getelementptr inbounds (i8, ptr @taskArray, i64 704), align 16, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) getelementptr inbounds (i8, ptr @taskArray, i64 712), i8 0, i64 48, i1 false)
  store i32 10, ptr getelementptr inbounds (i8, ptr @taskArray, i64 792), align 8, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(48) getelementptr inbounds (i8, ptr @taskArray, i64 800), i8 0, i64 48, i1 false)
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"TaskStruct", !10, i64 0, !13, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !14, i64 72, !15, i64 80}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"long long", !7, i64 0}


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