; LLVM IR from aras-p/ToyPathTracer :: Cpp/Source/enkiTS (TaskScheduler)

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

%"class.enki::TaskScheduler" = type <{ [3 x ptr], [3 x ptr], i32, [4 x i8], ptr, ptr, %"struct.std::atomic", %"struct.std::atomic", %"struct.std::atomic", i8, %"struct.std::atomic.0", %"struct.std::atomic.0", %"struct.std::atomic.0", i32, [4 x i8], ptr, ptr, i32, i8, [3 x i8], %"struct.enki::TaskSchedulerConfig", %"struct.std::atomic.0", [4 x i8] }>
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i8 }
%"struct.enki::TaskSchedulerConfig" = type { i32, i32, %"struct.enki::ProfilerCallbacks", %"struct.enki::CustomAllocator" }
%"struct.enki::ProfilerCallbacks" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%"struct.enki::CustomAllocator" = type { ptr, ptr, ptr }
%"struct.std::atomic.0" = type { %"struct.std::__atomic_base.1" }
%"struct.std::__atomic_base.1" = type { i32 }
%"struct.enki::ThreadDataStore" = type { ptr, %"struct.std::atomic.2", i32, [48 x i8] }
%"struct.std::atomic.2" = type { i32 }
%"class.enki::ICompletable" = type { ptr, i32, %"struct.std::atomic.0", %"struct.std::atomic.0", i32, %"struct.std::atomic.0", ptr }

@_ZL13gtl_threadNum = external hidden thread_local global i32, align 4
@.str.3 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@__PRETTY_FUNCTION__._ZN4enki13TaskScheduler11WaitforTaskEPKNS_12ICompletableENS_12TaskPriorityE = external hidden unnamed_addr constant [80 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4enki12ICompletable13GetIsCompleteEv(ptr noundef nonnull align 8 dereferenceable(40)) #0 align 2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNKSt6atomicIN4enki11ThreadStateEE4loadESt12memory_order(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6atomicIN4enki11ThreadStateEE5storeES1_St12memory_order(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef) #0 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN12_GLOBAL__N_112SafeCallbackEPFvjEj(ptr noundef, i32 noundef) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4enki13TaskScheduler15GetIsRunningIntEv(ptr noundef nonnull align 8 dereferenceable(220)) #5 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN12_GLOBAL__N_18SpinWaitEj(i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4enki13TaskScheduler10TryRunTaskEjjRj(ptr noundef nonnull align 8 dereferenceable(220), i32 noundef, i32 noundef, ptr noundef nonnull align 4 dereferenceable(4)) #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4enki13TaskScheduler21WaitForTaskCompletionEPKNS_12ICompletableEj(ptr noundef nonnull align 8 dereferenceable(220), ptr noundef, i32 noundef) #4 align 2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local void @_ZSt19atomic_thread_fenceSt12memory_order(i32 noundef) #6

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4enki13TaskScheduler11WaitforTaskEPKNS_12ICompletableENS_12TaskPriorityE(ptr noundef nonnull align 8 dereferenceable(220) %0, ptr noundef %1, i32 noundef %2) #4 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %15 = load ptr, ptr %4, align 8
  %16 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @_ZL13gtl_threadNum)
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp ne i32 %17, -1
  br i1 %18, label %19, label %20

19:                                               ; preds = %3
  br label %22

20:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.3, i32 noundef 973, ptr noundef @__PRETTY_FUNCTION__._ZN4enki13TaskScheduler11WaitforTaskEPKNS_12ICompletableENS_12TaskPriorityE) #7
  unreachable

21:                                               ; No predecessors!
  br label %22

22:                                               ; preds = %21, %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  %23 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @_ZL13gtl_threadNum)
  %24 = load i32, ptr %23, align 4, !tbaa !11
  store i32 %24, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  %25 = load i32, ptr %7, align 4, !tbaa !11
  %26 = add i32 %25, 1
  store i32 %26, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  %27 = getelementptr inbounds %"class.enki::TaskScheduler", ptr %15, i32 0, i32 4
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = load i32, ptr %7, align 4, !tbaa !11
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds %"struct.enki::ThreadDataStore", ptr %28, i64 %30
  %32 = getelementptr inbounds %"struct.enki::ThreadDataStore", ptr %31, i32 0, i32 1
  %33 = call noundef i32 @_ZNKSt6atomicIN4enki11ThreadStateEE4loadESt12memory_order(ptr noundef nonnull align 4 dereferenceable(4) %32, i32 noundef 0) #8
  store i32 %33, ptr %9, align 4, !tbaa !23
  %34 = getelementptr inbounds %"class.enki::TaskScheduler", ptr %15, i32 0, i32 4
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = load i32, ptr %7, align 4, !tbaa !11
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds %"struct.enki::ThreadDataStore", ptr %35, i64 %37
  %39 = getelementptr inbounds %"struct.enki::ThreadDataStore", ptr %38, i32 0, i32 1
  call void @_ZNSt6atomicIN4enki11ThreadStateEE5storeES1_St12memory_order(ptr noundef nonnull align 4 dereferenceable(4) %39, i32 noundef 2, i32 noundef 0) #8
  call void @_ZSt19atomic_thread_fenceSt12memory_order(i32 noundef 2) #8
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %97

42:                                               ; preds = %22
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = call noundef zeroext i1 @_ZNK4enki12ICompletable13GetIsCompleteEv(ptr noundef nonnull align 8 dereferenceable(40) %43)
  br i1 %44, label %97, label %45

45:                                               ; preds = %42
  %46 = getelementptr inbounds %"class.enki::TaskScheduler", ptr %15, i32 0, i32 20
  %47 = getelementptr inbounds %"struct.enki::TaskSchedulerConfig", ptr %46, i32 0, i32 2
  %48 = getelementptr inbounds %"struct.enki::ProfilerCallbacks", ptr %47, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !25
  %50 = load i32, ptr %7, align 4, !tbaa !11
  call void @_ZN12_GLOBAL__N_112SafeCallbackEPFvjEj(ptr noundef %49, i32 noundef %50)
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %"class.enki::ICompletable", ptr %51, i32 0, i32 1
  %53 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIN4enki12TaskPriorityEERKT_S4_S4_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %52)
  %54 = load i32, ptr %53, align 4, !tbaa !9
  store i32 %54, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #8
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %55

55:                                               ; preds = %90, %45
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = call noundef zeroext i1 @_ZNK4enki12ICompletable13GetIsCompleteEv(ptr noundef nonnull align 8 dereferenceable(40) %56)
  br i1 %57, label %60, label %58

58:                                               ; preds = %55
  %59 = call noundef zeroext i1 @_ZNK4enki13TaskScheduler15GetIsRunningIntEv(ptr noundef nonnull align 8 dereferenceable(220) %15)
  br label %60

60:                                               ; preds = %58, %55
  %61 = phi i1 [ false, %55 ], [ %59, %58 ]
  br i1 %61, label %62, label %91

62:                                               ; preds = %60
  %63 = load i32, ptr %10, align 4, !tbaa !11
  %64 = add i32 %63, 1
  store i32 %64, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #8
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %65

65:                                               ; preds = %76, %62
  %66 = load i32, ptr %11, align 4, !tbaa !11
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = icmp sle i32 %66, %67
  br i1 %68, label %70, label %69

69:                                               ; preds = %65
  store i32 4, ptr %12, align 4
  br label %79

70:                                               ; preds = %65
  %71 = load i32, ptr %7, align 4, !tbaa !11
  %72 = load i32, ptr %11, align 4, !tbaa !11
  %73 = call noundef zeroext i1 @_ZN4enki13TaskScheduler10TryRunTaskEjjRj(ptr noundef nonnull align 8 dereferenceable(220) %15, i32 noundef %71, i32 noundef %72, ptr noundef nonnull align 4 dereferenceable(4) %8)
  br i1 %73, label %74, label %75

74:                                               ; preds = %70
  store i32 0, ptr %10, align 4, !tbaa !11
  store i32 4, ptr %12, align 4
  br label %79

75:                                               ; preds = %70
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %11, align 4, !tbaa !11
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %11, align 4, !tbaa !11
  br label %65, !llvm.loop !26

79:                                               ; preds = %74, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #8
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %10, align 4, !tbaa !11
  %82 = icmp ugt i32 %81, 10
  br i1 %82, label %83, label %86

83:                                               ; preds = %80
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = load i32, ptr %7, align 4, !tbaa !11
  call void @_ZN4enki13TaskScheduler21WaitForTaskCompletionEPKNS_12ICompletableEj(ptr noundef nonnull align 8 dereferenceable(220) %15, ptr noundef %84, i32 noundef %85)
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %90

86:                                               ; preds = %80
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #8
  %87 = load i32, ptr %10, align 4, !tbaa !11
  %88 = mul i32 %87, 100
  store i32 %88, ptr %13, align 4, !tbaa !11
  %89 = load i32, ptr %13, align 4, !tbaa !11
  call void @_ZN12_GLOBAL__N_18SpinWaitEj(i32 noundef %89)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #8
  br label %90

90:                                               ; preds = %86, %83
  br label %55, !llvm.loop !28

91:                                               ; preds = %60
  %92 = getelementptr inbounds %"class.enki::TaskScheduler", ptr %15, i32 0, i32 20
  %93 = getelementptr inbounds %"struct.enki::TaskSchedulerConfig", ptr %92, i32 0, i32 2
  %94 = getelementptr inbounds %"struct.enki::ProfilerCallbacks", ptr %93, i32 0, i32 5
  %95 = load ptr, ptr %94, align 8, !tbaa !29
  %96 = load i32, ptr %7, align 4, !tbaa !11
  call void @_ZN12_GLOBAL__N_112SafeCallbackEPFvjEj(ptr noundef %95, i32 noundef %96)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #8
  br label %118

97:                                               ; preds = %42, %22
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = icmp eq ptr null, %98
  br i1 %99, label %100, label %117

100:                                              ; preds = %97
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #8
  store i32 0, ptr %14, align 4, !tbaa !11
  br label %101

101:                                              ; preds = %112, %100
  %102 = load i32, ptr %14, align 4, !tbaa !11
  %103 = load i32, ptr %6, align 4, !tbaa !9
  %104 = icmp sle i32 %102, %103
  br i1 %104, label %106, label %105

105:                                              ; preds = %101
  store i32 7, ptr %12, align 4
  br label %115

106:                                              ; preds = %101
  %107 = load i32, ptr %7, align 4, !tbaa !11
  %108 = load i32, ptr %14, align 4, !tbaa !11
  %109 = call noundef zeroext i1 @_ZN4enki13TaskScheduler10TryRunTaskEjjRj(ptr noundef nonnull align 8 dereferenceable(220) %15, i32 noundef %107, i32 noundef %108, ptr noundef nonnull align 4 dereferenceable(4) %8)
  br i1 %109, label %110, label %111

110:                                              ; preds = %106
  store i32 7, ptr %12, align 4
  br label %115

111:                                              ; preds = %106
  br label %112

112:                                              ; preds = %111
  %113 = load i32, ptr %14, align 4, !tbaa !11
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %14, align 4, !tbaa !11
  br label %101, !llvm.loop !30

115:                                              ; preds = %110, %105
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #8
  br label %116

116:                                              ; preds = %115
  br label %117

117:                                              ; preds = %116, %97
  br label %118

118:                                              ; preds = %117, %91
  %119 = getelementptr inbounds %"class.enki::TaskScheduler", ptr %15, i32 0, i32 4
  %120 = load ptr, ptr %119, align 8, !tbaa !13
  %121 = load i32, ptr %7, align 4, !tbaa !11
  %122 = zext i32 %121 to i64
  %123 = getelementptr inbounds %"struct.enki::ThreadDataStore", ptr %120, i64 %122
  %124 = getelementptr inbounds %"struct.enki::ThreadDataStore", ptr %123, i32 0, i32 1
  %125 = load i32, ptr %9, align 4, !tbaa !23
  call void @_ZNSt6atomicIN4enki11ThreadStateEE5storeES1_St12memory_order(ptr noundef nonnull align 4 dereferenceable(4) %124, i32 noundef %125, i32 noundef 3) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIN4enki12TaskPriorityEERKT_S4_S4_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #5

attributes #0 = { mustprogress 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 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { mustprogress 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 #5 = { inlinehint mustprogress 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 #6 = { alwaysinline mustprogress 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 #7 = { noreturn nounwind }
attributes #8 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTSN4enki12TaskPriorityE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 56}
!14 = !{!"_ZTSN4enki13TaskSchedulerE", !7, i64 0, !7, i64 24, !12, i64 48, !6, i64 56, !6, i64 64, !15, i64 72, !15, i64 73, !15, i64 74, !18, i64 76, !18, i64 80, !18, i64 84, !12, i64 88, !6, i64 96, !6, i64 104, !12, i64 112, !17, i64 116, !20, i64 120, !18, i64 216}
!15 = !{!"_ZTSSt6atomicIbE", !16, i64 0}
!16 = !{!"_ZTSSt13__atomic_baseIbE", !17, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{!"_ZTSSt6atomicIiE", !19, i64 0}
!19 = !{!"_ZTSSt13__atomic_baseIiE", !12, i64 0}
!20 = !{!"_ZTSN4enki19TaskSchedulerConfigE", !12, i64 0, !12, i64 4, !21, i64 8, !22, i64 72}
!21 = !{!"_ZTSN4enki17ProfilerCallbacksE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!22 = !{!"_ZTSN4enki15CustomAllocatorE", !6, i64 0, !6, i64 8, !6, i64 16}
!23 = !{!24, !24, i64 0}
!24 = !{!"_ZTSN4enki11ThreadStateE", !7, i64 0}
!25 = !{!14, !6, i64 160}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = distinct !{!28, !27}
!29 = !{!14, !6, i64 168}
!30 = distinct !{!30, !27}


; 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.enki::ThreadDataStore" = type { ptr, %"struct.std::atomic.2", i32, [48 x i8] }
%"struct.std::atomic.2" = type { i32 }

@_ZL13gtl_threadNum = external hidden thread_local local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@__PRETTY_FUNCTION__._ZN4enki13TaskScheduler11WaitforTaskEPKNS_12ICompletableENS_12TaskPriorityE = external hidden unnamed_addr constant [80 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4enki12ICompletable13GetIsCompleteEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNKSt6atomicIN4enki11ThreadStateEE4loadESt12memory_order(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6atomicIN4enki11ThreadStateEE5storeES1_St12memory_order(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN12_GLOBAL__N_112SafeCallbackEPFvjEj(ptr noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4enki13TaskScheduler15GetIsRunningIntEv(ptr noundef nonnull align 8 dereferenceable(220)) local_unnamed_addr #5 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN12_GLOBAL__N_18SpinWaitEj(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4enki13TaskScheduler10TryRunTaskEjjRj(ptr noundef nonnull align 8 dereferenceable(220), i32 noundef, i32 noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4enki13TaskScheduler21WaitForTaskCompletionEPKNS_12ICompletableEj(ptr noundef nonnull align 8 dereferenceable(220), ptr noundef, i32 noundef) local_unnamed_addr #4 align 2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local void @_ZSt19atomic_thread_fenceSt12memory_order(i32 noundef) local_unnamed_addr #6

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4enki13TaskScheduler11WaitforTaskEPKNS_12ICompletableENS_12TaskPriorityE(ptr noundef nonnull align 8 dereferenceable(220) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #4 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %2, ptr %4, align 4, !tbaa !5
  %6 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @_ZL13gtl_threadNum)
  %7 = load i32, ptr %6, align 4, !tbaa !9
  %.not = icmp eq i32 %7, -1
  br i1 %.not, label %8, label %9

8:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.3, i32 noundef 973, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4enki13TaskScheduler11WaitforTaskEPKNS_12ICompletableENS_12TaskPriorityE) #7
  unreachable

9:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #8
  %10 = add nuw i32 %7, 1
  store i32 %10, ptr %5, align 4, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %0, i64 56
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = zext i32 %7 to i64
  %14 = getelementptr inbounds %"struct.enki::ThreadDataStore", ptr %12, i64 %13, i32 1
  %15 = tail call noundef i32 @_ZNKSt6atomicIN4enki11ThreadStateEE4loadESt12memory_order(ptr noundef nonnull align 4 dereferenceable(4) %14, i32 noundef 0) #8
  %16 = load ptr, ptr %11, align 8, !tbaa !11
  %17 = getelementptr inbounds %"struct.enki::ThreadDataStore", ptr %16, i64 %13, i32 1
  tail call void @_ZNSt6atomicIN4enki11ThreadStateEE5storeES1_St12memory_order(ptr noundef nonnull align 4 dereferenceable(4) %17, i32 noundef 2, i32 noundef 0) #8
  tail call void @_ZSt19atomic_thread_fenceSt12memory_order(i32 noundef 2) #8
  %cond = icmp eq ptr %1, null
  br i1 %cond, label %.preheader, label %18

.preheader:                                       ; preds = %9
  %.not3241 = icmp slt i32 %2, 0
  br i1 %.not3241, label %.loopexit, label %.lr.ph43

18:                                               ; preds = %9
  %19 = tail call noundef zeroext i1 @_ZNK4enki12ICompletable13GetIsCompleteEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  br i1 %19, label %.loopexit, label %20

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %0, i64 160
  %22 = load ptr, ptr %21, align 8, !tbaa !22
  tail call void @_ZN12_GLOBAL__N_112SafeCallbackEPFvjEj(ptr noundef %22, i32 noundef %7)
  %23 = getelementptr inbounds i8, ptr %1, i64 8
  %24 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIN4enki12TaskPriorityEERKT_S4_S4_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %23)
  %25 = load i32, ptr %24, align 4, !tbaa !5
  store i32 %25, ptr %4, align 4, !tbaa !5
  %26 = call noundef zeroext i1 @_ZNK4enki12ICompletable13GetIsCompleteEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  br i1 %26, label %.critedge, label %.lr.ph39

.lr.ph39:                                         ; preds = %20, %38
  %.02637 = phi i32 [ %.2, %38 ], [ 0, %20 ]
  %27 = call noundef zeroext i1 @_ZNK4enki13TaskScheduler15GetIsRunningIntEv(ptr noundef nonnull align 8 dereferenceable(220) %0)
  br i1 %27, label %28, label %.critedge

28:                                               ; preds = %.lr.ph39
  %29 = add nuw nsw i32 %.02637, 1
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %.not3135 = icmp slt i32 %30, 0
  br i1 %.not3135, label %._crit_edge, label %.lr.ph

31:                                               ; preds = %.lr.ph
  %32 = add nuw nsw i32 %.02736, 1
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %.not31.not = icmp slt i32 %.02736, %33
  br i1 %.not31.not, label %.lr.ph, label %._crit_edge, !llvm.loop !23

.lr.ph:                                           ; preds = %28, %31
  %.02736 = phi i32 [ %32, %31 ], [ 0, %28 ]
  %34 = call noundef zeroext i1 @_ZN4enki13TaskScheduler10TryRunTaskEjjRj(ptr noundef nonnull align 8 dereferenceable(220) %0, i32 noundef %7, i32 noundef %.02736, ptr noundef nonnull align 4 dereferenceable(4) %5)
  br i1 %34, label %.thread, label %31

._crit_edge:                                      ; preds = %31, %28
  %35 = icmp ugt i32 %.02637, 9
  br i1 %35, label %36, label %.thread

36:                                               ; preds = %._crit_edge
  call void @_ZN4enki13TaskScheduler21WaitForTaskCompletionEPKNS_12ICompletableEj(ptr noundef nonnull align 8 dereferenceable(220) %0, ptr noundef nonnull %1, i32 noundef %7)
  br label %38

.thread:                                          ; preds = %.lr.ph, %._crit_edge
  %.134 = phi i32 [ %29, %._crit_edge ], [ 0, %.lr.ph ]
  %37 = mul nuw nsw i32 %.134, 100
  call void @_ZN12_GLOBAL__N_18SpinWaitEj(i32 noundef %37)
  br label %38

38:                                               ; preds = %.thread, %36
  %.2 = phi i32 [ 0, %36 ], [ %.134, %.thread ]
  %39 = call noundef zeroext i1 @_ZNK4enki12ICompletable13GetIsCompleteEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  br i1 %39, label %.critedge, label %.lr.ph39, !llvm.loop !25

.critedge:                                        ; preds = %.lr.ph39, %38, %20
  %40 = getelementptr inbounds i8, ptr %0, i64 168
  %41 = load ptr, ptr %40, align 8, !tbaa !26
  call void @_ZN12_GLOBAL__N_112SafeCallbackEPFvjEj(ptr noundef %41, i32 noundef %7)
  br label %.loopexit

.lr.ph43:                                         ; preds = %.preheader, %.lr.ph43
  %.042 = phi i32 [ %43, %.lr.ph43 ], [ 0, %.preheader ]
  %42 = call noundef zeroext i1 @_ZN4enki13TaskScheduler10TryRunTaskEjjRj(ptr noundef nonnull align 8 dereferenceable(220) %0, i32 noundef %7, i32 noundef %.042, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %43 = add nuw nsw i32 %.042, 1
  %.not32.not = icmp sge i32 %.042, %2
  %or.cond.not = or i1 %.not32.not, %42
  br i1 %or.cond.not, label %.loopexit, label %.lr.ph43, !llvm.loop !27

.loopexit:                                        ; preds = %.lr.ph43, %.preheader, %18, %.critedge
  %44 = load ptr, ptr %11, align 8, !tbaa !11
  %45 = getelementptr inbounds %"struct.enki::ThreadDataStore", ptr %44, i64 %13, i32 1
  call void @_ZNSt6atomicIN4enki11ThreadStateEE5storeES1_St12memory_order(ptr noundef nonnull align 4 dereferenceable(4) %45, i32 noundef %15, i32 noundef 3) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #8
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIN4enki12TaskPriorityEERKT_S4_S4_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #5

attributes #0 = { mustprogress 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 = { noreturn nounwind "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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { mustprogress 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 #5 = { inlinehint mustprogress 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 #6 = { alwaysinline mustprogress 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 #7 = { noreturn nounwind }
attributes #8 = { 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 = !{!"_ZTSN4enki12TaskPriorityE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 56}
!12 = !{!"_ZTSN4enki13TaskSchedulerE", !7, i64 0, !7, i64 24, !10, i64 48, !13, i64 56, !13, i64 64, !14, i64 72, !14, i64 73, !14, i64 74, !17, i64 76, !17, i64 80, !17, i64 84, !10, i64 88, !13, i64 96, !13, i64 104, !10, i64 112, !16, i64 116, !19, i64 120, !17, i64 216}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"_ZTSSt6atomicIbE", !15, i64 0}
!15 = !{!"_ZTSSt13__atomic_baseIbE", !16, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"_ZTSSt6atomicIiE", !18, i64 0}
!18 = !{!"_ZTSSt13__atomic_baseIiE", !10, i64 0}
!19 = !{!"_ZTSN4enki19TaskSchedulerConfigE", !10, i64 0, !10, i64 4, !20, i64 8, !21, i64 72}
!20 = !{!"_ZTSN4enki17ProfilerCallbacksE", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56}
!21 = !{!"_ZTSN4enki15CustomAllocatorE", !13, i64 0, !13, i64 8, !13, i64 16}
!22 = !{!12, !13, i64 160}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}
!26 = !{!12, !13, i64 168}
!27 = distinct !{!27, !24}


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