; LLVM IR from asllop/AppOS :: core/task (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.TaskStruct = type { i32, ptr, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, i64, i64 }

@.str = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @core_create(ptr noundef %0, i32 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !11
  %11 = call i32 @core_lock(i32 noundef 1)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %12 = call ptr (...) @empty_slot()
  store ptr %12, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %17, label %15

15:                                               ; preds = %3
  %16 = call i32 @core_unlock(i32 noundef 1)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %112

17:                                               ; preds = %3
  %18 = load i64, ptr %7, align 8, !tbaa !11
  %19 = icmp ult i64 %18, 256
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  store i64 256, ptr %7, align 8, !tbaa !11
  br label %21

21:                                               ; preds = %20, %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %22 = load i64, ptr %7, align 8, !tbaa !11
  %23 = call ptr @core_malloc(i64 noundef %22)
  store ptr %23, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = call i64 @core_size(ptr noundef %24)
  store i64 %25, ptr %7, align 8, !tbaa !11
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %30, label %28

28:                                               ; preds = %21
  %29 = call i32 @core_unlock(i32 noundef 1)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %111

30:                                               ; preds = %21
  %31 = call i32 (...) @inc_task_counter()
  %32 = icmp eq i32 %31, -512
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  call void @core_fatal(ptr noundef @.str)
  br label %34

34:                                               ; preds = %33, %30
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.TaskStruct, ptr %36, i32 0, i32 1
  store ptr %35, ptr %37, align 8, !tbaa !13
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.TaskStruct, ptr %39, i32 0, i32 2
  store i32 %38, ptr %40, align 8, !tbaa !16
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.TaskStruct, ptr %42, i32 0, i32 3
  store i32 %41, ptr %43, align 4, !tbaa !17
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.TaskStruct, ptr %44, i32 0, i32 4
  store i32 1, ptr %45, align 8, !tbaa !18
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.TaskStruct, ptr %46, i32 0, i32 5
  store i32 0, ptr %47, align 4, !tbaa !19
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.TaskStruct, ptr %48, i32 0, i32 6
  store ptr null, ptr %49, align 8, !tbaa !20
  %50 = load i64, ptr %7, align 8, !tbaa !11
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.TaskStruct, ptr %51, i32 0, i32 11
  store i64 %50, ptr %52, align 8, !tbaa !21
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.TaskStruct, ptr %54, i32 0, i32 10
  store ptr %53, ptr %55, align 8, !tbaa !22
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.TaskStruct, ptr %57, i32 0, i32 11
  %59 = load i64, ptr %58, align 8, !tbaa !21
  %60 = getelementptr inbounds i8, ptr %56, i64 %59
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.TaskStruct, ptr %61, i32 0, i32 9
  store ptr %60, ptr %62, align 8, !tbaa !23
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = call ptr @prev_used_slot(ptr noundef %63)
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.TaskStruct, ptr %65, i32 0, i32 8
  store ptr %64, ptr %66, align 8, !tbaa !24
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = call ptr @next_used_slot(ptr noundef %67)
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.TaskStruct, ptr %69, i32 0, i32 7
  store ptr %68, ptr %70, align 8, !tbaa !25
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.TaskStruct, ptr %71, i32 0, i32 8
  %73 = load ptr, ptr %72, align 8, !tbaa !24
  %74 = icmp ne ptr %73, null
  br i1 %74, label %79, label %75

75:                                               ; preds = %34
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.TaskStruct, ptr %77, i32 0, i32 8
  store ptr %76, ptr %78, align 8, !tbaa !24
  br label %85

79:                                               ; preds = %34
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.TaskStruct, ptr %81, i32 0, i32 8
  %83 = load ptr, ptr %82, align 8, !tbaa !24
  %84 = getelementptr inbounds %struct.TaskStruct, ptr %83, i32 0, i32 7
  store ptr %80, ptr %84, align 8, !tbaa !25
  br label %85

85:                                               ; preds = %79, %75
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.TaskStruct, ptr %86, i32 0, i32 7
  %88 = load ptr, ptr %87, align 8, !tbaa !25
  %89 = icmp ne ptr %88, null
  br i1 %89, label %94, label %90

90:                                               ; preds = %85
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.TaskStruct, ptr %92, i32 0, i32 7
  store ptr %91, ptr %93, align 8, !tbaa !25
  br label %100

94:                                               ; preds = %85
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.TaskStruct, ptr %96, i32 0, i32 7
  %98 = load ptr, ptr %97, align 8, !tbaa !25
  %99 = getelementptr inbounds %struct.TaskStruct, ptr %98, i32 0, i32 8
  store ptr %95, ptr %99, align 8, !tbaa !24
  br label %100

100:                                              ; preds = %94, %90
  %101 = call ptr (...) @get_current_task()
  %102 = icmp eq ptr %101, null
  br i1 %102, label %103, label %105

103:                                              ; preds = %100
  %104 = load ptr, ptr %8, align 8, !tbaa !5
  call void @set_current_task(ptr noundef %104)
  br label %105

105:                                              ; preds = %103, %100
  %106 = load ptr, ptr %8, align 8, !tbaa !5
  call void @context_init(ptr noundef %106)
  %107 = call i32 @core_unlock(i32 noundef 1)
  %108 = load ptr, ptr %8, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.TaskStruct, ptr %108, i32 0, i32 0
  %110 = load i32, ptr %109, align 8, !tbaa !26
  store i32 %110, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %111

111:                                              ; preds = %105, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %112

112:                                              ; preds = %111, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %113 = load i32, ptr %4, align 4
  ret i32 %113
}

declare i32 @core_lock(i32 noundef) #1

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

declare ptr @empty_slot(...) #1

declare i32 @core_unlock(i32 noundef) #1

declare ptr @core_malloc(i64 noundef) #1

declare i64 @core_size(ptr noundef) #1

declare i32 @inc_task_counter(...) #1

declare void @core_fatal(ptr noundef) #1

declare ptr @prev_used_slot(ptr noundef) #1

declare ptr @next_used_slot(ptr noundef) #1

declare ptr @get_current_task(...) #1

declare void @set_current_task(ptr noundef) #1

declare void @context_init(ptr noundef) #1

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"TaskStruct", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !12, i64 72, !15, i64 80}
!15 = !{!"long long", !7, i64 0}
!16 = !{!14, !10, i64 16}
!17 = !{!14, !10, i64 20}
!18 = !{!14, !10, i64 24}
!19 = !{!14, !10, i64 28}
!20 = !{!14, !6, i64 32}
!21 = !{!14, !12, i64 72}
!22 = !{!14, !6, i64 64}
!23 = !{!14, !6, i64 56}
!24 = !{!14, !6, i64 48}
!25 = !{!14, !6, i64 40}
!26 = !{!14, !10, i64 0}


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

@.str = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @core_create(ptr noundef %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @core_lock(i32 noundef 1) #3
  %5 = tail call ptr (...) @empty_slot() #3
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %6, label %8

6:                                                ; preds = %3
  %7 = tail call i32 @core_unlock(i32 noundef 1) #3
  br label %45

8:                                                ; preds = %3
  %spec.store.select = tail call i64 @llvm.umax.i64(i64 %2, i64 256)
  %9 = tail call ptr @core_malloc(i64 noundef %spec.store.select) #3
  %10 = tail call i64 @core_size(ptr noundef %9) #3
  %.not42 = icmp eq ptr %9, null
  br i1 %.not42, label %11, label %13

11:                                               ; preds = %8
  %12 = tail call i32 @core_unlock(i32 noundef 1) #3
  br label %45

13:                                               ; preds = %8
  %14 = tail call i32 (...) @inc_task_counter() #3
  %15 = icmp eq i32 %14, -512
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  tail call void @core_fatal(ptr noundef nonnull @.str) #3
  br label %17

17:                                               ; preds = %16, %13
  %18 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %0, ptr %18, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %5, i64 16
  store i32 %1, ptr %19, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %5, i64 20
  store i32 %1, ptr %20, align 4, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %5, i64 24
  store i32 1, ptr %21, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %5, i64 28
  store i32 0, ptr %22, align 4, !tbaa !16
  %23 = getelementptr inbounds i8, ptr %5, i64 32
  store ptr null, ptr %23, align 8, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %5, i64 72
  store i64 %10, ptr %24, align 8, !tbaa !18
  %25 = getelementptr inbounds i8, ptr %5, i64 64
  store ptr %9, ptr %25, align 8, !tbaa !19
  %26 = getelementptr inbounds i8, ptr %9, i64 %10
  %27 = getelementptr inbounds i8, ptr %5, i64 56
  store ptr %26, ptr %27, align 8, !tbaa !20
  %28 = tail call ptr @prev_used_slot(ptr noundef nonnull %5) #3
  %29 = getelementptr inbounds i8, ptr %5, i64 48
  store ptr %28, ptr %29, align 8, !tbaa !21
  %30 = tail call ptr @next_used_slot(ptr noundef nonnull %5) #3
  %31 = getelementptr inbounds i8, ptr %5, i64 40
  store ptr %30, ptr %31, align 8, !tbaa !22
  %32 = load ptr, ptr %29, align 8, !tbaa !21
  %.not43 = icmp eq ptr %32, null
  br i1 %.not43, label %33, label %34

33:                                               ; preds = %17
  store ptr %5, ptr %29, align 8, !tbaa !21
  br label %36

34:                                               ; preds = %17
  %35 = getelementptr inbounds i8, ptr %32, i64 40
  store ptr %5, ptr %35, align 8, !tbaa !22
  %.pr = load ptr, ptr %31, align 8, !tbaa !22
  br label %36

36:                                               ; preds = %34, %33
  %37 = phi ptr [ %.pr, %34 ], [ %30, %33 ]
  %.not44 = icmp eq ptr %37, null
  %38 = getelementptr inbounds i8, ptr %37, i64 48
  %.sink = select i1 %.not44, ptr %31, ptr %38
  store ptr %5, ptr %.sink, align 8, !tbaa !23
  %39 = tail call ptr (...) @get_current_task() #3
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  tail call void @set_current_task(ptr noundef nonnull %5) #3
  br label %42

42:                                               ; preds = %41, %36
  tail call void @context_init(ptr noundef nonnull %5) #3
  %43 = tail call i32 @core_unlock(i32 noundef 1) #3
  %44 = load i32, ptr %5, align 8, !tbaa !24
  br label %45

45:                                               ; preds = %11, %42, %6
  %.1 = phi i32 [ 0, %6 ], [ %44, %42 ], [ 0, %11 ]
  ret i32 %.1
}

declare i32 @core_lock(i32 noundef) local_unnamed_addr #1

declare ptr @empty_slot(...) local_unnamed_addr #1

declare i32 @core_unlock(i32 noundef) local_unnamed_addr #1

declare ptr @core_malloc(i64 noundef) local_unnamed_addr #1

declare i64 @core_size(ptr noundef) local_unnamed_addr #1

declare i32 @inc_task_counter(...) local_unnamed_addr #1

declare void @core_fatal(ptr noundef) local_unnamed_addr #1

declare ptr @prev_used_slot(ptr noundef) local_unnamed_addr #1

declare ptr @next_used_slot(ptr noundef) local_unnamed_addr #1

declare ptr @get_current_task(...) local_unnamed_addr #1

declare void @set_current_task(ptr noundef) local_unnamed_addr #1

declare void @context_init(ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, i64 8}
!6 = !{!"TaskStruct", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !11, i64 72, !12, i64 80}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!6, !7, i64 16}
!14 = !{!6, !7, i64 20}
!15 = !{!6, !7, i64 24}
!16 = !{!6, !7, i64 28}
!17 = !{!6, !10, i64 32}
!18 = !{!6, !11, i64 72}
!19 = !{!6, !10, i64 64}
!20 = !{!6, !10, i64 56}
!21 = !{!6, !10, i64 48}
!22 = !{!6, !10, i64 40}
!23 = !{!10, !10, i64 0}
!24 = !{!6, !7, i64 0}


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