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

; 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.systematic_testing_thread_t = type { i64, i32, i8 }
%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.mpmcq_t = type { ptr, %union.aba_protected_mpmcq_node_t, [32 x i8] }
%union.aba_protected_mpmcq_node_t = type { i128 }
%struct.messageq_t = type { ptr, ptr }

@waiting_to_start_count = external hidden global i32, align 4
@total_threads = external hidden global i32, align 4
@threads_to_track = external hidden global ptr, align 8
@active_thread = external hidden global ptr, align 8

; 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 @ponyint_thread_suspend(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @ponyint_systematic_testing_start(ptr noundef %0, i64 noundef %1, i32 noundef %2, i64 noundef %3, i32 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !11
  store i64 %3, ptr %9, align 8, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !11
  %13 = load i64, ptr %9, align 8, !tbaa !9
  %14 = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %14, i64 0
  %16 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %15, i32 0, i32 0
  store i64 %13, ptr %16, align 8, !tbaa !13
  %17 = load i32, ptr %10, align 4, !tbaa !11
  %18 = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %18, i64 0
  %20 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %19, i32 0, i32 1
  store i32 %17, ptr %20, align 8, !tbaa !16
  %21 = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %21, i64 0
  %23 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %22, i32 0, i32 2
  store i8 0, ptr %23, align 4, !tbaa !17
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %25, i64 1
  %27 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %26, i32 0, i32 0
  store i64 %24, ptr %27, align 8, !tbaa !13
  %28 = load i32, ptr %8, align 4, !tbaa !11
  %29 = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %29, i64 1
  %31 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %30, i32 0, i32 1
  store i32 %28, ptr %31, align 8, !tbaa !16
  %32 = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %32, i64 1
  %34 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %33, i32 0, i32 2
  store i8 0, ptr %34, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 2, ptr %11, align 4, !tbaa !11
  br label %35

35:                                               ; preds = %70, %5
  %36 = load i32, ptr %11, align 4, !tbaa !11
  %37 = load i32, ptr @total_threads, align 4, !tbaa !11
  %38 = icmp ult i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %73

40:                                               ; preds = %35
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i32, ptr %11, align 4, !tbaa !11
  %43 = sub i32 %42, 2
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds %struct.scheduler_t, ptr %41, i64 %44
  %46 = getelementptr inbounds %struct.scheduler_t, ptr %45, i32 0, i32 0
  %47 = load i64, ptr %46, align 64, !tbaa !18
  %48 = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  %49 = load i32, ptr %11, align 4, !tbaa !11
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %48, i64 %50
  %52 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %51, i32 0, i32 0
  store i64 %47, ptr %52, align 8, !tbaa !13
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i32, ptr %11, align 4, !tbaa !11
  %55 = sub i32 %54, 2
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds %struct.scheduler_t, ptr %53, i64 %56
  %58 = getelementptr inbounds %struct.scheduler_t, ptr %57, i32 0, i32 7
  %59 = load i32, ptr %58, align 4, !tbaa !27
  %60 = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  %61 = load i32, ptr %11, align 4, !tbaa !11
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %60, i64 %62
  %64 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %63, i32 0, i32 1
  store i32 %59, ptr %64, align 8, !tbaa !16
  %65 = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  %66 = load i32, ptr %11, align 4, !tbaa !11
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %65, i64 %67
  %69 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %68, i32 0, i32 2
  store i8 0, ptr %69, align 4, !tbaa !17
  br label %70

70:                                               ; preds = %40
  %71 = load i32, ptr %11, align 4, !tbaa !11
  %72 = add i32 %71, 1
  store i32 %72, ptr %11, align 4, !tbaa !11
  br label %35, !llvm.loop !28

73:                                               ; preds = %39
  br label %74

74:                                               ; preds = %80, %73
  %75 = load i32, ptr @total_threads, align 4, !tbaa !11
  %76 = sub i32 %75, 1
  %77 = load atomic i32, ptr @waiting_to_start_count monotonic, align 4
  store i32 %77, ptr %12, align 4
  %78 = load i32, ptr %12, align 4, !tbaa !11
  %79 = icmp ne i32 %76, %78
  br i1 %79, label %80, label %81

80:                                               ; preds = %74
  call void @ponyint_cpu_core_pause(i64 noundef 1, i64 noundef 10000002, i1 noundef zeroext true)
  br label %74, !llvm.loop !30

81:                                               ; preds = %74
  %82 = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %82, i64 2
  store ptr %83, ptr @active_thread, align 8, !tbaa !5
  %84 = load ptr, ptr @active_thread, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %84, i32 0, i32 0
  %86 = load i64, ptr %85, align 8, !tbaa !13
  %87 = load ptr, ptr @active_thread, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %87, i32 0, i32 1
  %89 = load i32, ptr %88, align 8, !tbaa !16
  %90 = call i32 @ponyint_thread_wake(i64 noundef %86, i32 noundef %89)
  %91 = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %91, i64 0
  %93 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %92, i32 0, i32 1
  %94 = load i32, ptr %93, align 8, !tbaa !16
  call void @ponyint_thread_suspend(i32 noundef %94)
  ret void
}

declare void @ponyint_cpu_core_pause(i64 noundef, i64 noundef, i1 noundef zeroext) #1

declare i32 @ponyint_thread_wake(i64 noundef, i32 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"systematic_testing_thread_t", !10, i64 0, !12, i64 8, !15, i64 12}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!14, !12, i64 8}
!17 = !{!14, !15, i64 12}
!18 = !{!19, !10, i64 0}
!19 = !{!"scheduler_t", !10, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !15, i64 20, !15, i64 21, !12, i64 24, !12, i64 28, !6, i64 64, !20, i64 72, !12, i64 216, !12, i64 220, !12, i64 224, !24, i64 232, !25, i64 320, !26, i64 384}
!20 = !{!"pony_ctx_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !21, i64 40, !6, i64 72, !10, i64 80, !23, i64 88, !6, i64 120, !6, i64 128, !6, i64 136}
!21 = !{!"actormap_t", !22, i64 0}
!22 = !{!"hashmap_t", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24}
!23 = !{!"ponyint_serialise_t", !22, i64 0}
!24 = !{!"mutemap_t", !22, i64 0}
!25 = !{!"mpmcq_t", !7, i64 0, !7, i64 16}
!26 = !{!"messageq_t", !7, i64 0, !6, i64 8}
!27 = !{!19, !12, i64 28}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = distinct !{!30, !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.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.mpmcq_t = type { ptr, %union.aba_protected_mpmcq_node_t, [32 x i8] }
%union.aba_protected_mpmcq_node_t = type { i128 }
%struct.messageq_t = type { ptr, ptr }
%struct.systematic_testing_thread_t = type { i64, i32, i8 }

@waiting_to_start_count = external hidden local_unnamed_addr global i32, align 4
@total_threads = external hidden local_unnamed_addr global i32, align 4
@threads_to_track = external hidden local_unnamed_addr global ptr, align 8
@active_thread = external hidden local_unnamed_addr global ptr, align 8

declare void @ponyint_thread_suspend(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @ponyint_systematic_testing_start(ptr nocapture noundef readonly %0, i64 noundef %1, i32 noundef %2, i64 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  store i64 %3, ptr %6, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 %4, ptr %7, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %6, i64 12
  store i8 0, ptr %8, align 4, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %6, i64 16
  store i64 %1, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %6, i64 24
  store i32 %2, ptr %10, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %6, i64 28
  store i8 0, ptr %11, align 4, !tbaa !15
  %12 = load i32, ptr @total_threads, align 4, !tbaa !16
  %13 = icmp ugt i32 %12, 2
  br i1 %13, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %5
  %14 = phi i32 [ %12, %5 ], [ %25, %.lr.ph ]
  %15 = add i32 %14, -1
  %16 = load atomic i32, ptr @waiting_to_start_count monotonic, align 4
  %.not14 = icmp eq i32 %15, %16
  br i1 %.not14, label %._crit_edge, label %.lr.ph15

.lr.ph:                                           ; preds = %5, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 2, %5 ]
  %17 = getelementptr %struct.scheduler_t, ptr %0, i64 %indvars.iv
  %18 = getelementptr i8, ptr %17, i64 -896
  %19 = load i64, ptr %18, align 64, !tbaa !17
  %20 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %6, i64 %indvars.iv
  store i64 %19, ptr %20, align 8, !tbaa !9
  %21 = getelementptr i8, ptr %17, i64 -868
  %22 = load i32, ptr %21, align 4, !tbaa !26
  %23 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %6, i64 %indvars.iv, i32 1
  store i32 %22, ptr %23, align 8, !tbaa !14
  %24 = getelementptr inbounds %struct.systematic_testing_thread_t, ptr %6, i64 %indvars.iv, i32 2
  store i8 0, ptr %24, align 4, !tbaa !15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i32, ptr @total_threads, align 4, !tbaa !16
  %26 = zext i32 %25 to i64
  %27 = icmp ult i64 %indvars.iv.next, %26
  br i1 %27, label %.lr.ph, label %.preheader, !llvm.loop !27

.lr.ph15:                                         ; preds = %.preheader, %.lr.ph15
  tail call void @ponyint_cpu_core_pause(i64 noundef 1, i64 noundef 10000002, i1 noundef zeroext true) #2
  %28 = load i32, ptr @total_threads, align 4, !tbaa !16
  %29 = add i32 %28, -1
  %30 = load atomic i32, ptr @waiting_to_start_count monotonic, align 4
  %.not = icmp eq i32 %29, %30
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph15, !llvm.loop !29

._crit_edge.loopexit:                             ; preds = %.lr.ph15
  %.pre = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %31 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ %6, %.preheader ]
  %32 = getelementptr inbounds i8, ptr %31, i64 32
  store ptr %32, ptr @active_thread, align 8, !tbaa !5
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %31, i64 40
  %35 = load i32, ptr %34, align 8, !tbaa !14
  %36 = tail call i32 @ponyint_thread_wake(i64 noundef %33, i32 noundef %35) #2
  %37 = load ptr, ptr @threads_to_track, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 8
  %39 = load i32, ptr %38, align 8, !tbaa !14
  tail call void @ponyint_thread_suspend(i32 noundef %39) #2
  ret void
}

declare void @ponyint_cpu_core_pause(i64 noundef, i64 noundef, i1 noundef zeroext) local_unnamed_addr #0

declare i32 @ponyint_thread_wake(i64 noundef, i32 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"systematic_testing_thread_t", !11, i64 0, !12, i64 8, !13, i64 12}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!10, !12, i64 8}
!15 = !{!10, !13, i64 12}
!16 = !{!12, !12, i64 0}
!17 = !{!18, !11, i64 0}
!18 = !{!"scheduler_t", !11, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !13, i64 20, !13, i64 21, !12, i64 24, !12, i64 28, !6, i64 64, !19, i64 72, !12, i64 216, !12, i64 220, !12, i64 224, !23, i64 232, !24, i64 320, !25, i64 384}
!19 = !{!"pony_ctx_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !20, i64 40, !6, i64 72, !11, i64 80, !22, i64 88, !6, i64 120, !6, i64 128, !6, i64 136}
!20 = !{!"actormap_t", !21, i64 0}
!21 = !{!"hashmap_t", !11, i64 0, !11, i64 8, !6, i64 16, !6, 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, !6, i64 8}
!26 = !{!18, !12, i64 28}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = distinct !{!29, !28}


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