; LLVM IR from ponylang/ponyc :: src/libponyrt/sched (scheduler)

; 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.mpmcq_t = type { ptr, %union.aba_protected_mpmcq_node_t, [32 x i8] }
%union.aba_protected_mpmcq_node_t = type { i128 }
%struct.scheduler_t = type { i64, i32, i32, i32, i8, i8, i32, i32, [32 x i8], ptr, %struct.pony_ctx_t, i32, i32, i32, %struct.mutemap_t, [56 x i8], %struct.mpmcq_t, %struct.messageq_t, [48 x i8] }
%struct.pony_ctx_t = type { ptr, ptr, ptr, ptr, ptr, %struct.actormap_t, ptr, i64, %struct.ponyint_serialise_t, ptr, ptr, ptr }
%struct.actormap_t = type { %struct.hashmap_t }
%struct.hashmap_t = type { i64, i64, ptr, ptr }
%struct.ponyint_serialise_t = type { %struct.hashmap_t }
%struct.mutemap_t = type { %struct.hashmap_t }
%struct.messageq_t = type { ptr, ptr }

@use_yield = external hidden global i8, align 1
@scheduler_suspend_threshold = external hidden global i64, align 8
@scheduler_count = external hidden global i32, align 4
@min_scheduler_count = external hidden global i32, align 4
@active_scheduler_count = external hidden global i32, align 4
@active_scheduler_count_check = external hidden global i32, align 4
@temporarily_disable_scheduler_scaling = external hidden global i8, align 1
@scheduler = external hidden global ptr, align 8
@.str = external hidden unnamed_addr constant [27 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__func__.ponyint_sched_init = external hidden unnamed_addr constant [19 x i8], align 1
@inject = external hidden global %struct.mpmcq_t, align 64
@this_scheduler = external hidden thread_local global ptr, align 8
@pinned_actor_scheduler = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @ponyint_sched_init(i32 noundef %0, i1 noundef zeroext %1, i1 noundef zeroext %2, i1 noundef zeroext %3, i1 noundef zeroext %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i1 noundef zeroext %8) #0 {
  %10 = alloca i32, align 4
  %11 = alloca i8, align 1
  %12 = alloca i8, align 1
  %13 = alloca i8, align 1
  %14 = alloca i8, align 1
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i8, align 1
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i8, align 1
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca i32, align 4
  store i32 %0, ptr %10, align 4, !tbaa !5
  %25 = zext i1 %1 to i8
  store i8 %25, ptr %11, align 1, !tbaa !9
  %26 = zext i1 %2 to i8
  store i8 %26, ptr %12, align 1, !tbaa !9
  %27 = zext i1 %3 to i8
  store i8 %27, ptr %13, align 1, !tbaa !9
  %28 = zext i1 %4 to i8
  store i8 %28, ptr %14, align 1, !tbaa !9
  store i32 %5, ptr %15, align 4, !tbaa !5
  store i32 %6, ptr %16, align 4, !tbaa !5
  store i32 %7, ptr %17, align 4, !tbaa !5
  %29 = zext i1 %8 to i8
  store i8 %29, ptr %18, align 1, !tbaa !9
  call void @pony_register_thread()
  %30 = load i32, ptr %17, align 4, !tbaa !5
  %31 = load i8, ptr %11, align 1, !tbaa !9, !range !11, !noundef !12
  %32 = trunc i8 %31 to i1
  %33 = xor i1 %32, true
  %34 = zext i1 %33 to i8
  store i8 %34, ptr @use_yield, align 1, !tbaa !9
  %35 = load i32, ptr %16, align 4, !tbaa !5
  %36 = icmp ult i32 %35, 1
  br i1 %36, label %37, label %38

37:                                               ; preds = %9
  store i32 1, ptr %16, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %37, %9
  %39 = load i32, ptr %10, align 4, !tbaa !5
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %38
  %42 = call i32 (...) @ponyint_cpu_count()
  store i32 %42, ptr %10, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %41, %38
  %44 = load i32, ptr %15, align 4, !tbaa !5
  %45 = load i32, ptr %10, align 4, !tbaa !5
  %46 = icmp ugt i32 %44, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %43
  %48 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %48, ptr %15, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %47, %43
  %50 = load i32, ptr %16, align 4, !tbaa !5
  %51 = mul i32 %50, 1000000
  %52 = zext i32 %51 to i64
  store i64 %52, ptr @scheduler_suspend_threshold, align 8, !tbaa !13
  %53 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %53, ptr @scheduler_count, align 4, !tbaa !5
  %54 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %54, ptr @min_scheduler_count, align 4, !tbaa !5
  %55 = load i32, ptr @scheduler_count, align 4, !tbaa !5
  store i32 %55, ptr %19, align 4, !tbaa !5
  %56 = load i32, ptr %19, align 4
  store atomic i32 %56, ptr @active_scheduler_count monotonic, align 4
  %57 = load i32, ptr @scheduler_count, align 4, !tbaa !5
  store i32 %57, ptr %20, align 4, !tbaa !5
  %58 = load i32, ptr %20, align 4
  store atomic i32 %58, ptr @active_scheduler_count_check monotonic, align 4
  store i8 0, ptr %21, align 1, !tbaa !9
  %59 = load i8, ptr %21, align 1
  store atomic i8 %59, ptr @temporarily_disable_scheduler_scaling monotonic, align 1
  %60 = load i32, ptr @scheduler_count, align 4, !tbaa !5
  %61 = zext i32 %60 to i64
  %62 = mul i64 %61, 448
  %63 = call noalias ptr @ponyint_pool_alloc_size(i64 noundef %62)
  store ptr %63, ptr @scheduler, align 8, !tbaa !15
  %64 = load ptr, ptr @scheduler, align 8, !tbaa !15
  %65 = load i32, ptr @scheduler_count, align 4, !tbaa !5
  %66 = zext i32 %65 to i64
  %67 = mul i64 %66, 448
  call void @llvm.memset.p0.i64(ptr align 64 %64, i8 0, i64 %67, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #5
  store i32 -1, ptr %22, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #5
  %68 = load i32, ptr @scheduler_count, align 4, !tbaa !5
  %69 = load ptr, ptr @scheduler, align 8, !tbaa !15
  %70 = load i8, ptr %12, align 1, !tbaa !9, !range !11, !noundef !12
  %71 = trunc i8 %70 to i1
  %72 = load i8, ptr %13, align 1, !tbaa !9, !range !11, !noundef !12
  %73 = trunc i8 %72 to i1
  %74 = load i8, ptr %14, align 1, !tbaa !9, !range !11, !noundef !12
  %75 = trunc i8 %74 to i1
  %76 = load i8, ptr %18, align 1, !tbaa !9, !range !11, !noundef !12
  %77 = trunc i8 %76 to i1
  %78 = call i32 @ponyint_cpu_assign(i32 noundef %68, ptr noundef %69, i1 noundef zeroext %71, i1 noundef zeroext %73, i1 noundef zeroext %75, i1 noundef zeroext %77, ptr noundef %22)
  store i32 %78, ptr %23, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #5
  store i32 0, ptr %24, align 4, !tbaa !5
  br label %79

79:                                               ; preds = %146, %49
  %80 = load i32, ptr %24, align 4, !tbaa !5
  %81 = load i32, ptr @scheduler_count, align 4, !tbaa !5
  %82 = icmp ult i32 %80, %81
  br i1 %82, label %84, label %83

83:                                               ; preds = %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #5
  br label %149

84:                                               ; preds = %79
  %85 = load ptr, ptr @scheduler, align 8, !tbaa !15
  %86 = load i32, ptr %24, align 4, !tbaa !5
  %87 = zext i32 %86 to i64
  %88 = getelementptr inbounds %struct.scheduler_t, ptr %85, i64 %87
  %89 = getelementptr inbounds %struct.scheduler_t, ptr %88, i32 0, i32 7
  store i32 12, ptr %89, align 4, !tbaa !17
  %90 = load ptr, ptr @scheduler, align 8, !tbaa !15
  %91 = load i32, ptr %24, align 4, !tbaa !5
  %92 = zext i32 %91 to i64
  %93 = getelementptr inbounds %struct.scheduler_t, ptr %90, i64 %92
  %94 = load ptr, ptr @scheduler, align 8, !tbaa !15
  %95 = load i32, ptr %24, align 4, !tbaa !5
  %96 = zext i32 %95 to i64
  %97 = getelementptr inbounds %struct.scheduler_t, ptr %94, i64 %96
  %98 = getelementptr inbounds %struct.scheduler_t, ptr %97, i32 0, i32 10
  %99 = getelementptr inbounds %struct.pony_ctx_t, ptr %98, i32 0, i32 0
  store ptr %93, ptr %99, align 8, !tbaa !26
  %100 = load ptr, ptr @scheduler, align 8, !tbaa !15
  %101 = load i32, ptr %24, align 4, !tbaa !5
  %102 = zext i32 %101 to i64
  %103 = getelementptr inbounds %struct.scheduler_t, ptr %100, i64 %102
  %104 = load ptr, ptr @scheduler, align 8, !tbaa !15
  %105 = load i32, ptr %24, align 4, !tbaa !5
  %106 = zext i32 %105 to i64
  %107 = getelementptr inbounds %struct.scheduler_t, ptr %104, i64 %106
  %108 = getelementptr inbounds %struct.scheduler_t, ptr %107, i32 0, i32 9
  store ptr %103, ptr %108, align 64, !tbaa !27
  %109 = load i32, ptr %24, align 4, !tbaa !5
  %110 = load ptr, ptr @scheduler, align 8, !tbaa !15
  %111 = load i32, ptr %24, align 4, !tbaa !5
  %112 = zext i32 %111 to i64
  %113 = getelementptr inbounds %struct.scheduler_t, ptr %110, i64 %112
  %114 = getelementptr inbounds %struct.scheduler_t, ptr %113, i32 0, i32 1
  store i32 %109, ptr %114, align 8, !tbaa !28
  %115 = load ptr, ptr @scheduler, align 8, !tbaa !15
  %116 = load i32, ptr %24, align 4, !tbaa !5
  %117 = zext i32 %116 to i64
  %118 = getelementptr inbounds %struct.scheduler_t, ptr %115, i64 %117
  %119 = getelementptr inbounds %struct.scheduler_t, ptr %118, i32 0, i32 6
  store i32 0, ptr %119, align 8, !tbaa !29
  %120 = load i32, ptr @scheduler_count, align 4, !tbaa !5
  %121 = load ptr, ptr @scheduler, align 8, !tbaa !15
  %122 = load i32, ptr %24, align 4, !tbaa !5
  %123 = zext i32 %122 to i64
  %124 = getelementptr inbounds %struct.scheduler_t, ptr %121, i64 %123
  %125 = getelementptr inbounds %struct.scheduler_t, ptr %124, i32 0, i32 13
  store i32 %120, ptr %125, align 32, !tbaa !30
  %126 = load ptr, ptr @scheduler, align 8, !tbaa !15
  %127 = load i32, ptr %24, align 4, !tbaa !5
  %128 = zext i32 %127 to i64
  %129 = getelementptr inbounds %struct.scheduler_t, ptr %126, i64 %128
  %130 = getelementptr inbounds %struct.scheduler_t, ptr %129, i32 0, i32 13
  %131 = load i32, ptr %130, align 32, !tbaa !30
  %132 = icmp ugt i32 %131, 0
  br i1 %132, label %133, label %134

133:                                              ; preds = %84
  br label %135

134:                                              ; preds = %84
  call void @ponyint_assert_fail(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 1716, ptr noundef @__func__.ponyint_sched_init)
  br label %135

135:                                              ; preds = %134, %133
  %136 = load ptr, ptr @scheduler, align 8, !tbaa !15
  %137 = load i32, ptr %24, align 4, !tbaa !5
  %138 = zext i32 %137 to i64
  %139 = getelementptr inbounds %struct.scheduler_t, ptr %136, i64 %138
  %140 = getelementptr inbounds %struct.scheduler_t, ptr %139, i32 0, i32 17
  call void @ponyint_messageq_init(ptr noundef %140)
  %141 = load ptr, ptr @scheduler, align 8, !tbaa !15
  %142 = load i32, ptr %24, align 4, !tbaa !5
  %143 = zext i32 %142 to i64
  %144 = getelementptr inbounds %struct.scheduler_t, ptr %141, i64 %143
  %145 = getelementptr inbounds %struct.scheduler_t, ptr %144, i32 0, i32 16
  call void @ponyint_mpmcq_init(ptr noundef %145)
  br label %146

146:                                              ; preds = %135
  %147 = load i32, ptr %24, align 4, !tbaa !5
  %148 = add i32 %147, 1
  store i32 %148, ptr %24, align 4, !tbaa !5
  br label %79, !llvm.loop !31

149:                                              ; preds = %83
  call void @ponyint_mpmcq_init(ptr noundef @inject)
  %150 = load i32, ptr %23, align 4, !tbaa !5
  call void @ponyint_asio_init(i32 noundef %150)
  %151 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @this_scheduler)
  %152 = load ptr, ptr %151, align 8, !tbaa !15
  %153 = getelementptr inbounds %struct.scheduler_t, ptr %152, i32 0, i32 7
  store i32 12, ptr %153, align 4, !tbaa !17
  %154 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @this_scheduler)
  %155 = load ptr, ptr %154, align 8, !tbaa !15
  %156 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @this_scheduler)
  %157 = load ptr, ptr %156, align 8, !tbaa !15
  %158 = getelementptr inbounds %struct.scheduler_t, ptr %157, i32 0, i32 10
  %159 = getelementptr inbounds %struct.pony_ctx_t, ptr %158, i32 0, i32 0
  store ptr %155, ptr %159, align 8, !tbaa !26
  %160 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @this_scheduler)
  %161 = load ptr, ptr %160, align 8, !tbaa !15
  %162 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @this_scheduler)
  %163 = load ptr, ptr %162, align 8, !tbaa !15
  %164 = getelementptr inbounds %struct.scheduler_t, ptr %163, i32 0, i32 9
  store ptr %161, ptr %164, align 64, !tbaa !27
  %165 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @this_scheduler)
  %166 = load ptr, ptr %165, align 8, !tbaa !15
  %167 = getelementptr inbounds %struct.scheduler_t, ptr %166, i32 0, i32 1
  store i32 -999, ptr %167, align 8, !tbaa !28
  %168 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @this_scheduler)
  %169 = load ptr, ptr %168, align 8, !tbaa !15
  %170 = getelementptr inbounds %struct.scheduler_t, ptr %169, i32 0, i32 6
  store i32 0, ptr %170, align 8, !tbaa !29
  %171 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @this_scheduler)
  %172 = load ptr, ptr %171, align 8, !tbaa !15
  %173 = getelementptr inbounds %struct.scheduler_t, ptr %172, i32 0, i32 17
  call void @ponyint_messageq_init(ptr noundef %173)
  %174 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @this_scheduler)
  %175 = load ptr, ptr %174, align 8, !tbaa !15
  %176 = getelementptr inbounds %struct.scheduler_t, ptr %175, i32 0, i32 16
  call void @ponyint_mpmcq_init(ptr noundef %176)
  %177 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @this_scheduler)
  %178 = load ptr, ptr %177, align 8, !tbaa !15
  store ptr %178, ptr @pinned_actor_scheduler, align 8, !tbaa !15
  %179 = call ptr @pony_ctx()
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #5
  ret ptr %179
}

declare i32 @ponyint_cpu_count(...) #1

declare noalias ptr @ponyint_pool_alloc_size(i64 noundef) #1

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

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

declare i32 @ponyint_cpu_assign(i32 noundef, ptr noundef, i1 noundef zeroext, i1 noundef zeroext, i1 noundef zeroext, i1 noundef zeroext, ptr noundef) #1

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

declare void @ponyint_messageq_init(ptr noundef) #1

declare void @ponyint_mpmcq_init(ptr noundef) #1

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

declare void @ponyint_asio_init(i32 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #4

; Function Attrs: nounwind uwtable
declare dso_local void @pony_register_thread() #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @pony_ctx() #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"int", !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, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"any pointer", !7, i64 0}
!17 = !{!18, !6, i64 28}
!18 = !{!"scheduler_t", !14, i64 0, !6, i64 8, !6, i64 12, !6, i64 16, !10, i64 20, !10, i64 21, !6, i64 24, !6, i64 28, !16, i64 64, !19, i64 72, !6, i64 216, !6, i64 220, !6, i64 224, !23, i64 232, !24, i64 320, !25, i64 384}
!19 = !{!"pony_ctx_t", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !16, i64 32, !20, i64 40, !16, i64 72, !14, i64 80, !22, i64 88, !16, i64 120, !16, i64 128, !16, i64 136}
!20 = !{!"actormap_t", !21, i64 0}
!21 = !{!"hashmap_t", !14, i64 0, !14, i64 8, !16, i64 16, !16, i64 24}
!22 = !{!"ponyint_serialise_t", !21, i64 0}
!23 = !{!"mutemap_t", !21, i64 0}
!24 = !{!"mpmcq_t", !7, i64 0, !7, i64 16}
!25 = !{!"messageq_t", !7, i64 0, !16, i64 8}
!26 = !{!18, !16, i64 72}
!27 = !{!18, !16, i64 64}
!28 = !{!18, !6, i64 8}
!29 = !{!18, !6, i64 24}
!30 = !{!18, !6, i64 224}
!31 = distinct !{!31, !32}
!32 = !{!"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.mpmcq_t = type { ptr, %union.aba_protected_mpmcq_node_t, [32 x i8] }
%union.aba_protected_mpmcq_node_t = type { i128 }
%struct.scheduler_t = type { i64, i32, i32, i32, i8, i8, i32, i32, [32 x i8], ptr, %struct.pony_ctx_t, i32, i32, i32, %struct.mutemap_t, [56 x i8], %struct.mpmcq_t, %struct.messageq_t, [48 x i8] }
%struct.pony_ctx_t = type { ptr, ptr, ptr, ptr, ptr, %struct.actormap_t, ptr, i64, %struct.ponyint_serialise_t, ptr, ptr, ptr }
%struct.actormap_t = type { %struct.hashmap_t }
%struct.hashmap_t = type { i64, i64, ptr, ptr }
%struct.ponyint_serialise_t = type { %struct.hashmap_t }
%struct.mutemap_t = type { %struct.hashmap_t }
%struct.messageq_t = type { ptr, ptr }

@use_yield = external hidden local_unnamed_addr global i8, align 1
@scheduler_suspend_threshold = external hidden local_unnamed_addr global i64, align 8
@scheduler_count = external hidden local_unnamed_addr global i32, align 4
@min_scheduler_count = external hidden local_unnamed_addr global i32, align 4
@active_scheduler_count = external hidden local_unnamed_addr global i32, align 4
@active_scheduler_count_check = external hidden local_unnamed_addr global i32, align 4
@temporarily_disable_scheduler_scaling = external hidden local_unnamed_addr global i8, align 1
@scheduler = external hidden local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [27 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@__func__.ponyint_sched_init = external hidden unnamed_addr constant [19 x i8], align 1
@inject = external hidden global %struct.mpmcq_t, align 64
@this_scheduler = external hidden thread_local local_unnamed_addr global ptr, align 8
@pinned_actor_scheduler = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @ponyint_sched_init(i32 noundef %0, i1 noundef zeroext %1, i1 noundef zeroext %2, i1 noundef zeroext %3, i1 noundef zeroext %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i1 noundef zeroext %8) local_unnamed_addr #0 {
  %10 = alloca i32, align 4
  tail call void @pony_register_thread()
  %11 = xor i1 %1, true
  %12 = zext i1 %11 to i8
  store i8 %12, ptr @use_yield, align 1, !tbaa !5
  %spec.store.select = tail call i32 @llvm.umax.i32(i32 %6, i32 1)
  %13 = icmp eq i32 %0, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %9
  %15 = tail call i32 (...) @ponyint_cpu_count() #6
  br label %16

16:                                               ; preds = %14, %9
  %.032 = phi i32 [ %15, %14 ], [ %0, %9 ]
  %spec.select = tail call i32 @llvm.umin.i32(i32 %.032, i32 %5)
  %17 = mul i32 %spec.store.select, 1000000
  %18 = zext i32 %17 to i64
  store i64 %18, ptr @scheduler_suspend_threshold, align 8, !tbaa !9
  store i32 %.032, ptr @scheduler_count, align 4, !tbaa !11
  store i32 %spec.select, ptr @min_scheduler_count, align 4, !tbaa !11
  store atomic i32 %.032, ptr @active_scheduler_count monotonic, align 4
  store atomic i32 %.032, ptr @active_scheduler_count_check monotonic, align 4
  store atomic i8 0, ptr @temporarily_disable_scheduler_scaling monotonic, align 1
  %19 = zext i32 %.032 to i64
  %20 = mul nuw nsw i64 %19, 448
  %21 = tail call noalias ptr @ponyint_pool_alloc_size(i64 noundef %20) #6
  store ptr %21, ptr @scheduler, align 8, !tbaa !13
  %22 = load i32, ptr @scheduler_count, align 4, !tbaa !11
  %23 = zext i32 %22 to i64
  %24 = mul nuw nsw i64 %23, 448
  tail call void @llvm.memset.p0.i64(ptr align 64 %21, i8 0, i64 %24, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %10) #6
  store i32 -1, ptr %10, align 4, !tbaa !11
  %25 = call i32 @ponyint_cpu_assign(i32 noundef %22, ptr noundef %21, i1 noundef zeroext %2, i1 noundef zeroext %3, i1 noundef zeroext %4, i1 noundef zeroext %8, ptr noundef nonnull %10) #6
  %26 = load i32, ptr @scheduler_count, align 4, !tbaa !11
  %.not37 = icmp eq i32 %26, 0
  br i1 %.not37, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %53, %16
  call void @ponyint_mpmcq_init(ptr noundef nonnull @inject) #6
  call void @ponyint_asio_init(i32 noundef %25) #6
  %27 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @this_scheduler)
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %28, i64 28
  store i32 12, ptr %29, align 4, !tbaa !15
  %30 = getelementptr inbounds i8, ptr %28, i64 72
  store ptr %28, ptr %30, align 8, !tbaa !24
  %31 = getelementptr inbounds i8, ptr %28, i64 64
  store ptr %28, ptr %31, align 64, !tbaa !25
  %32 = getelementptr inbounds i8, ptr %28, i64 8
  store i32 -999, ptr %32, align 8, !tbaa !26
  %33 = getelementptr inbounds i8, ptr %28, i64 24
  store i32 0, ptr %33, align 8, !tbaa !27
  %34 = getelementptr inbounds i8, ptr %28, i64 384
  call void @ponyint_messageq_init(ptr noundef nonnull %34) #6
  %35 = load ptr, ptr %27, align 8, !tbaa !13
  %36 = getelementptr inbounds i8, ptr %35, i64 320
  call void @ponyint_mpmcq_init(ptr noundef nonnull %36) #6
  %37 = load ptr, ptr %27, align 8, !tbaa !13
  store ptr %37, ptr @pinned_actor_scheduler, align 8, !tbaa !13
  %38 = call ptr @pony_ctx()
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %10) #6
  ret ptr %38

.lr.ph:                                           ; preds = %16, %53
  %indvars.iv = phi i64 [ %indvars.iv.next, %53 ], [ 0, %16 ]
  %39 = load ptr, ptr @scheduler, align 8, !tbaa !13
  %40 = getelementptr inbounds %struct.scheduler_t, ptr %39, i64 %indvars.iv, i32 7
  store i32 12, ptr %40, align 4, !tbaa !15
  %41 = getelementptr inbounds %struct.scheduler_t, ptr %39, i64 %indvars.iv
  %42 = getelementptr inbounds i8, ptr %41, i64 72
  store ptr %41, ptr %42, align 8, !tbaa !24
  %43 = load ptr, ptr @scheduler, align 8, !tbaa !13
  %44 = getelementptr inbounds %struct.scheduler_t, ptr %43, i64 %indvars.iv
  %45 = getelementptr inbounds i8, ptr %44, i64 64
  store ptr %44, ptr %45, align 64, !tbaa !25
  %46 = load ptr, ptr @scheduler, align 8, !tbaa !13
  %47 = getelementptr inbounds %struct.scheduler_t, ptr %46, i64 %indvars.iv, i32 1
  %48 = trunc nuw i64 %indvars.iv to i32
  store i32 %48, ptr %47, align 8, !tbaa !26
  %49 = getelementptr inbounds %struct.scheduler_t, ptr %46, i64 %indvars.iv, i32 6
  store i32 0, ptr %49, align 8, !tbaa !27
  %50 = load i32, ptr @scheduler_count, align 4, !tbaa !11
  %51 = getelementptr inbounds %struct.scheduler_t, ptr %46, i64 %indvars.iv, i32 13
  store i32 %50, ptr %51, align 32, !tbaa !28
  %.not = icmp eq i32 %50, 0
  br i1 %.not, label %52, label %53

52:                                               ; preds = %.lr.ph
  call void @ponyint_assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 1716, ptr noundef nonnull @__func__.ponyint_sched_init) #6
  %.pre = load ptr, ptr @scheduler, align 8, !tbaa !13
  br label %53

53:                                               ; preds = %.lr.ph, %52
  %54 = phi ptr [ %46, %.lr.ph ], [ %.pre, %52 ]
  %55 = getelementptr inbounds %struct.scheduler_t, ptr %54, i64 %indvars.iv, i32 17
  call void @ponyint_messageq_init(ptr noundef nonnull %55) #6
  %56 = load ptr, ptr @scheduler, align 8, !tbaa !13
  %57 = getelementptr inbounds %struct.scheduler_t, ptr %56, i64 %indvars.iv, i32 16
  call void @ponyint_mpmcq_init(ptr noundef nonnull %57) #6
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %58 = load i32, ptr @scheduler_count, align 4, !tbaa !11
  %59 = zext i32 %58 to i64
  %60 = icmp ult i64 %indvars.iv.next, %59
  br i1 %60, label %.lr.ph, label %._crit_edge, !llvm.loop !29
}

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

declare noalias ptr @ponyint_pool_alloc_size(i64 noundef) local_unnamed_addr #1

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

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

declare i32 @ponyint_cpu_assign(i32 noundef, ptr noundef, i1 noundef zeroext, i1 noundef zeroext, i1 noundef zeroext, i1 noundef zeroext, ptr noundef) local_unnamed_addr #1

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

declare void @ponyint_messageq_init(ptr noundef) local_unnamed_addr #1

declare void @ponyint_mpmcq_init(ptr noundef) local_unnamed_addr #1

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

declare void @ponyint_asio_init(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #4

; Function Attrs: nounwind uwtable
declare dso_local void @pony_register_thread() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @pony_ctx() local_unnamed_addr #0

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #5

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!16, !12, i64 28}
!16 = !{!"scheduler_t", !10, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !6, i64 20, !6, i64 21, !12, i64 24, !12, i64 28, !14, i64 64, !17, i64 72, !12, i64 216, !12, i64 220, !12, i64 224, !21, i64 232, !22, i64 320, !23, i64 384}
!17 = !{!"pony_ctx_t", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !18, i64 40, !14, i64 72, !10, i64 80, !20, i64 88, !14, i64 120, !14, i64 128, !14, i64 136}
!18 = !{!"actormap_t", !19, i64 0}
!19 = !{!"hashmap_t", !10, i64 0, !10, i64 8, !14, i64 16, !14, i64 24}
!20 = !{!"ponyint_serialise_t", !19, i64 0}
!21 = !{!"mutemap_t", !19, i64 0}
!22 = !{!"mpmcq_t", !7, i64 0, !7, i64 16}
!23 = !{!"messageq_t", !7, i64 0, !14, i64 8}
!24 = !{!16, !14, i64 72}
!25 = !{!16, !14, i64 64}
!26 = !{!16, !12, i64 8}
!27 = !{!16, !12, i64 24}
!28 = !{!16, !12, i64 224}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass