; 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
@currentTask = external hidden global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [39 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

declare void @core_fatal(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @schedule(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load i8, ptr @isScheduling, align 1, !tbaa !9, !range !11, !noundef !12
  %6 = trunc i8 %5 to i1
  br i1 %6, label %9, label %7

7:                                                ; preds = %1
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %8, ptr %2, align 8
  br label %92

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr @currentTask, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.TaskStruct, ptr %11, i32 0, i32 9
  store ptr %10, ptr %12, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %13 = load ptr, ptr @currentTask, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.TaskStruct, ptr %13, i32 0, i32 7
  %15 = load ptr, ptr %14, align 8, !tbaa !18
  store ptr %15, ptr %4, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %86, %9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %85

19:                                               ; preds = %16
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.TaskStruct, ptr %20, i32 0, i32 4
  %22 = load i32, ptr %21, align 8, !tbaa !19
  %23 = icmp eq i32 %22, 3
  br i1 %23, label %24, label %59

24:                                               ; preds = %19
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.TaskStruct, ptr %25, i32 0, i32 10
  %27 = load ptr, ptr %26, align 8, !tbaa !20
  call void @internal_free(ptr noundef %27)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TaskStruct, ptr %28, i32 0, i32 4
  store i32 0, ptr %29, align 8, !tbaa !19
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.TaskStruct, ptr %30, i32 0, i32 10
  store ptr null, ptr %31, align 8, !tbaa !20
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.TaskStruct, ptr %32, i32 0, i32 8
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = icmp ne ptr %34, %35
  br i1 %36, label %37, label %58

37:                                               ; preds = %24
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.TaskStruct, ptr %38, i32 0, i32 7
  %40 = load ptr, ptr %39, align 8, !tbaa !18
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = icmp ne ptr %40, %41
  br i1 %42, label %43, label %58

43:                                               ; preds = %37
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.TaskStruct, ptr %44, i32 0, i32 7
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.TaskStruct, ptr %47, i32 0, i32 8
  %49 = load ptr, ptr %48, align 8, !tbaa !21
  %50 = getelementptr inbounds %struct.TaskStruct, ptr %49, i32 0, i32 7
  store ptr %46, ptr %50, align 8, !tbaa !18
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.TaskStruct, ptr %51, i32 0, i32 8
  %53 = load ptr, ptr %52, align 8, !tbaa !21
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.TaskStruct, ptr %54, i32 0, i32 7
  %56 = load ptr, ptr %55, align 8, !tbaa !18
  %57 = getelementptr inbounds %struct.TaskStruct, ptr %56, i32 0, i32 8
  store ptr %53, ptr %57, align 8, !tbaa !21
  br label %58

58:                                               ; preds = %43, %37, %24
  br label %84

59:                                               ; preds = %19
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.TaskStruct, ptr %60, i32 0, i32 3
  %62 = load i32, ptr %61, align 4, !tbaa !22
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %75

64:                                               ; preds = %59
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.TaskStruct, ptr %65, i32 0, i32 4
  %67 = load i32, ptr %66, align 8, !tbaa !19
  %68 = icmp eq i32 %67, 1
  br i1 %68, label %69, label %75

69:                                               ; preds = %64
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.TaskStruct, ptr %70, i32 0, i32 2
  %72 = load i32, ptr %71, align 8, !tbaa !23
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.TaskStruct, ptr %73, i32 0, i32 3
  store i32 %72, ptr %74, align 4, !tbaa !22
  br label %87

75:                                               ; preds = %64, %59
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.TaskStruct, ptr %76, i32 0, i32 3
  %78 = load i32, ptr %77, align 4, !tbaa !22
  %79 = add i32 %78, -1
  store i32 %79, ptr %77, align 4, !tbaa !22
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.TaskStruct, ptr %80, i32 0, i32 7
  %82 = load ptr, ptr %81, align 8, !tbaa !18
  store ptr %82, ptr %4, align 8, !tbaa !5
  br label %83

83:                                               ; preds = %75
  br label %84

84:                                               ; preds = %83, %58
  br label %86

85:                                               ; preds = %16
  call void @core_fatal(ptr noundef @.str.2)
  br label %86

86:                                               ; preds = %85, %84
  br label %16

87:                                               ; preds = %69
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %88, ptr @currentTask, align 8, !tbaa !5
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.TaskStruct, ptr %89, i32 0, i32 9
  %91 = load ptr, ptr %90, align 8, !tbaa !13
  store ptr %91, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %92

92:                                               ; preds = %87, %7
  %93 = load ptr, ptr %2, align 8
  ret ptr %93
}

declare void @internal_free(ptr noundef) #1

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


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

@isScheduling = external hidden local_unnamed_addr global i8, align 1
@currentTask = external hidden local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [39 x i8], align 1

declare void @core_fatal(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @schedule(ptr noundef %0) local_unnamed_addr #1 {
  %2 = load i8, ptr @isScheduling, align 1, !tbaa !5, !range !9, !noundef !10
  %3 = trunc nuw i8 %2 to i1
  br i1 %3, label %4, label %41

4:                                                ; preds = %1
  %5 = load ptr, ptr @currentTask, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %5, i64 56
  store ptr %0, ptr %6, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %5, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !18
  br label %.outer

.outer:                                           ; preds = %.outer.backedge, %4
  %.0.ph = phi ptr [ %8, %4 ], [ %.0.ph.be, %.outer.backedge ]
  %.not = icmp eq ptr %.0.ph, null
  %9 = getelementptr inbounds i8, ptr %.0.ph, i64 24
  %10 = getelementptr inbounds i8, ptr %.0.ph, i64 64
  %11 = getelementptr inbounds i8, ptr %.0.ph, i64 48
  %12 = getelementptr inbounds i8, ptr %.0.ph, i64 40
  br label %13

13:                                               ; preds = %.backedge, %.outer
  br i1 %.not, label %40, label %14

14:                                               ; preds = %13
  %15 = load i32, ptr %9, align 8, !tbaa !19
  %16 = icmp eq i32 %15, 3
  br i1 %16, label %17, label %26

17:                                               ; preds = %14
  %18 = load ptr, ptr %10, align 8, !tbaa !20
  tail call void @internal_free(ptr noundef %18) #2
  store i32 0, ptr %9, align 8, !tbaa !19
  store ptr null, ptr %10, align 8, !tbaa !20
  %19 = load ptr, ptr %11, align 8, !tbaa !21
  %.not28 = icmp eq ptr %19, %.0.ph
  br i1 %.not28, label %.backedge, label %20

20:                                               ; preds = %17
  %21 = load ptr, ptr %12, align 8, !tbaa !18
  %.not29 = icmp eq ptr %21, %.0.ph
  br i1 %.not29, label %.backedge, label %22

22:                                               ; preds = %20
  %23 = getelementptr inbounds i8, ptr %19, i64 40
  store ptr %21, ptr %23, align 8, !tbaa !18
  %24 = load ptr, ptr %12, align 8, !tbaa !18
  %25 = getelementptr inbounds i8, ptr %24, i64 48
  store ptr %19, ptr %25, align 8, !tbaa !21
  br label %.backedge

.backedge:                                        ; preds = %22, %20, %17
  br label %13

26:                                               ; preds = %14
  %27 = getelementptr inbounds i8, ptr %.0.ph, i64 20
  %28 = load i32, ptr %27, align 4, !tbaa !22
  %29 = icmp eq i32 %28, 0
  %30 = icmp eq i32 %15, 1
  %or.cond = and i1 %30, %29
  br i1 %or.cond, label %31, label %36

31:                                               ; preds = %26
  %32 = getelementptr inbounds i8, ptr %.0.ph, i64 16
  %33 = load i32, ptr %32, align 8, !tbaa !23
  store i32 %33, ptr %27, align 4, !tbaa !22
  store ptr %.0.ph, ptr @currentTask, align 8, !tbaa !11
  %34 = getelementptr inbounds i8, ptr %.0.ph, i64 56
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  br label %41

36:                                               ; preds = %26
  %37 = add i32 %28, -1
  store i32 %37, ptr %27, align 4, !tbaa !22
  %38 = getelementptr inbounds i8, ptr %.0.ph, i64 40
  %39 = load ptr, ptr %38, align 8, !tbaa !18
  br label %.outer.backedge

.outer.backedge:                                  ; preds = %36, %40
  %.0.ph.be = phi ptr [ null, %40 ], [ %39, %36 ]
  br label %.outer

40:                                               ; preds = %13
  tail call void @core_fatal(ptr noundef nonnull @.str.2) #2
  br label %.outer.backedge

41:                                               ; preds = %1, %31
  %.024 = phi ptr [ %35, %31 ], [ %0, %1 ]
  ret ptr %.024
}

declare void @internal_free(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 56}
!14 = !{!"TaskStruct", !15, i64 0, !12, i64 8, !15, i64 16, !15, i64 20, !15, i64 24, !15, i64 28, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !16, i64 72, !17, i64 80}
!15 = !{!"int", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = !{!14, !12, i64 40}
!19 = !{!14, !15, i64 24}
!20 = !{!14, !12, i64 64}
!21 = !{!14, !12, i64 48}
!22 = !{!14, !15, i64 20}
!23 = !{!14, !15, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass